Skip to content

Commit

Permalink
Only add SHA3 preferences to v6 keys
Browse files Browse the repository at this point in the history
To ensure compatibility with older mobile clients, which may not
support verifying SHA3 message signatures
  • Loading branch information
larabr committed Apr 16, 2024
1 parent d2a40e1 commit 0ac9e5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/key/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
// prefer fast asm.js implementations (SHA-256)
enums.hash.sha256,
enums.hash.sha512,
enums.hash.sha3_256,
enums.hash.sha3_512
...(secretKeyPacket.version === 6 ? [enums.hash.sha3_256, enums.hash.sha3_512] : [])
], config.preferredHashAlgorithm);
signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
enums.compression.uncompressed,
Expand Down
12 changes: 10 additions & 2 deletions test/general/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,11 @@ function versionSpecificTests() {
]);
}
const hash = openpgp.enums.hash;
expect(selfSignature.preferredHashAlgorithms).to.eql([hash.sha256, hash.sha512, hash.sha3_256, hash.sha3_512]);
expect(selfSignature.preferredHashAlgorithms).to.eql(
openpgp.config.v6Keys ?
[hash.sha256, hash.sha512, hash.sha3_256, hash.sha3_512] :
[hash.sha256, hash.sha512]
);
const compr = openpgp.enums.compression;
expect(selfSignature.preferredCompressionAlgorithms).to.eql([compr.uncompressed, compr.zlib, compr.zip]);

Expand Down Expand Up @@ -2316,7 +2320,11 @@ function versionSpecificTests() {
]);
}
const hash = openpgp.enums.hash;
expect(selfSignature.preferredHashAlgorithms).to.eql([hash.sha224, hash.sha256, hash.sha512, hash.sha3_256, hash.sha3_512]);
expect(selfSignature.preferredHashAlgorithms).to.eql(
openpgp.config.v6Keys ?
[hash.sha224, hash.sha256, hash.sha512, hash.sha3_256, hash.sha3_512] :
[hash.sha224, hash.sha256, hash.sha512]
);
const compr = openpgp.enums.compression;
expect(selfSignature.preferredCompressionAlgorithms).to.eql([compr.zlib, compr.uncompressed, compr.zip]);

Expand Down

0 comments on commit 0ac9e5f

Please sign in to comment.