(sec *ecdsa.PrivateKey, pub *ecdsa.PublicKey)
| 213 | } |
| 214 | |
| 215 | func calcSharedKey(sec *ecdsa.PrivateKey, pub *ecdsa.PublicKey) ([]byte, error) { |
| 216 | if pub == nil { |
| 217 | return nil, ErrInvalidKey |
| 218 | } |
| 219 | res, _ := sec.Curve.ScalarMult(pub.X, pub.Y, sec.D.Bytes()) |
| 220 | byteLen := sec.Params().BitSize / 8 |
| 221 | key := res.Bytes() |
| 222 | if byteLen > len(key) { |
| 223 | fixKey := make([]byte, byteLen) |
| 224 | copy(fixKey[byteLen-len(key):], key) |
| 225 | key = fixKey |
| 226 | } |
| 227 | return key, nil |
| 228 | } |
| 229 | |
| 230 | type noMaybeReader struct { |
| 231 | reader io.Reader |
no outgoing calls