MCPcopy Create free account
hub / github.com/chanify/chanify / calcSharedKey

Function calcSharedKey

crypto/crypto.go:215–228  ·  view source on GitHub ↗
(sec *ecdsa.PrivateKey, pub *ecdsa.PublicKey)

Source from the content-addressed store, hash-verified

213}
214
215func 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
230type noMaybeReader struct {
231 reader io.Reader

Callers 3

EncryptMethod · 0.85
DecryptMethod · 0.85
TestKeyFailedFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestKeyFailedFunction · 0.68