@@ -125,7 +125,10 @@ func (c *curve25519) Encaps(rand io.Reader, point []byte) (ephemeral, sharedSecr
125125 // "VB = convert point V to the octet string"
126126 // sharedPoint corresponds to `VB`.
127127 var sharedPoint x25519lib.Key
128- x25519lib .Shared (& sharedPoint , & ephemeralPrivate , & pubKey )
128+ ok := x25519lib .Shared (& sharedPoint , & ephemeralPrivate , & pubKey )
129+ if ! ok {
130+ return nil , nil , errors .KeyInvalidError ("ecc: the public key is a low order point" )
131+ }
129132
130133 return ephemeralPublic [:], sharedPoint [:], nil
131134}
@@ -146,7 +149,10 @@ func (c *curve25519) Decaps(vsG, secret []byte) (sharedSecret []byte, err error)
146149 // RFC6637 §8: "Note that the recipient obtains the shared secret by calculating
147150 // S = rV = rvG, where (r,R) is the recipient's key pair."
148151 // sharedPoint corresponds to `S`.
149- x25519lib .Shared (& sharedPoint , & decodedPrivate , & ephemeralPublic )
152+ ok := x25519lib .Shared (& sharedPoint , & decodedPrivate , & ephemeralPublic )
153+ if ! ok {
154+ return nil , errors .KeyInvalidError ("ecc: the public key is a low order point" )
155+ }
150156
151157 return sharedPoint [:], nil
152158}
0 commit comments