| 189 | } |
| 190 | |
| 191 | func x963KDF(sharedKeySeed []byte, ephemeralPublicKey []byte, hfnc func() hash.Hash) []byte { |
| 192 | length := 32 |
| 193 | output := make([]byte, 0) |
| 194 | outlen := 0 |
| 195 | counter := uint32(1) |
| 196 | |
| 197 | for outlen < length { |
| 198 | h := hfnc() |
| 199 | h.Write(sharedKeySeed) // nolint: errcheck |
| 200 | |
| 201 | counterBuf := make([]byte, 4) |
| 202 | binary.BigEndian.PutUint32(counterBuf, counter) |
| 203 | h.Write(counterBuf) // nolint: errcheck |
| 204 | |
| 205 | h.Write(ephemeralPublicKey) // nolint: errcheck |
| 206 | |
| 207 | out := h.Sum(nil) |
| 208 | output = append(output, out...) |
| 209 | outlen += h.Size() |
| 210 | counter++ |
| 211 | } |
| 212 | return output |
| 213 | } |
| 214 | |
| 215 | func calcSharedKey(sec *ecdsa.PrivateKey, pub *ecdsa.PublicKey) ([]byte, error) { |
| 216 | if pub == nil { |