Skip to content

Commit da5c190

Browse files
authored
Merge pull request #299 from ProtonMail/fix/ecdh-low-order-curve-points
ECDHv4: Error on low-order x25519 public key curve points
2 parents b6bdd12 + b11bd23 commit da5c190

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

openpgp/internal/ecc/curve25519.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)