Clamp private keys, add test vectors.

This commit is contained in:
akwizgran
2018-02-02 22:13:28 +00:00
parent 56a5b8df87
commit 8bdf04a289
2 changed files with 42 additions and 1 deletions

View File

@@ -21,6 +21,15 @@ class Curve25519KeyParser implements KeyParser {
public PrivateKey parsePrivateKey(byte[] encodedKey)
throws GeneralSecurityException {
if (encodedKey.length != 32) throw new GeneralSecurityException();
return new Curve25519PrivateKey(encodedKey);
return new Curve25519PrivateKey(clamp(encodedKey));
}
static byte[] clamp(byte[] b) {
byte[] clamped = new byte[32];
System.arraycopy(b, 0, clamped, 0, 32);
clamped[0] &= 248;
clamped[31] &= 127;
clamped[31] |= 64;
return clamped;
}
}