mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-06 00:58:51 +00:00
Mask curve25519 keys during generation (before serializing them)
This was broken in #922 (merged as part of #956). This would cause GPG to be unable to parse unencrypted secret keys, thinking they were encrypted. rfc4880bis-08 hints at this requirement, saying: o MPI of an integer representing the secret key, which is a scalar of the public EC point. Since scalar multiplication happens after masking the private key, this implies that we should serialize the private key after masking, as well.
This commit is contained in:
@@ -191,6 +191,8 @@ Curve.prototype.genKeyPair = async function () {
|
||||
return nodeGenKeyPair(this.name);
|
||||
case 'curve25519': {
|
||||
const privateKey = await random.getRandomBytes(32);
|
||||
privateKey[0] = (privateKey[0] & 127) | 64;
|
||||
privateKey[31] &= 248;
|
||||
const secretKey = privateKey.slice().reverse();
|
||||
keyPair = nacl.box.keyPair.fromSecretKey(secretKey);
|
||||
const publicKey = util.concatUint8Array([new Uint8Array([0x40]), keyPair.publicKey]);
|
||||
|
||||
Reference in New Issue
Block a user