Add SHA3-256 and SHA3-512 to preferred hash algos on key generation (#1696)

This is to signal support to senders who wish to use these algos.
Note  that SHA256 remains as first default preference, followed by SHA512,
as in the context of OpenPGP signatures they provide
better performance/security ratio than their SHA3 counterparts.
This commit is contained in:
Ryan 2023-11-02 09:16:40 -04:00 committed by GitHub
parent 7881b850ec
commit 54fc2c8fbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

4
openpgp.d.ts vendored
View File

@ -782,7 +782,7 @@ export namespace enums {
bzip2 = 3, bzip2 = 3,
} }
export type hashNames = 'md5' | 'sha1' | 'ripemd' | 'sha256' | 'sha384' | 'sha512' | 'sha224'; export type hashNames = 'md5' | 'sha1' | 'ripemd' | 'sha256' | 'sha384' | 'sha512' | 'sha224' | 'sha3_256' | 'sha3_512';
enum hash { enum hash {
md5 = 1, md5 = 1,
sha1 = 2, sha1 = 2,
@ -791,6 +791,8 @@ export namespace enums {
sha384 = 9, sha384 = 9,
sha512 = 10, sha512 = 10,
sha224 = 11, sha224 = 11,
sha3_256 = 12,
sha3_512 = 14
} }
export type packetNames = 'publicKeyEncryptedSessionKey' | 'signature' | 'symEncryptedSessionKey' | 'onePassSignature' | 'secretKey' | 'publicKey' export type packetNames = 'publicKeyEncryptedSessionKey' | 'signature' | 'symEncryptedSessionKey' | 'onePassSignature' | 'secretKey' | 'publicKey'

View File

@ -216,7 +216,9 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
signatureProperties.preferredHashAlgorithms = createPreferredAlgos([ signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
// prefer fast asm.js implementations (SHA-256) // prefer fast asm.js implementations (SHA-256)
enums.hash.sha256, enums.hash.sha256,
enums.hash.sha512 enums.hash.sha512,
enums.hash.sha3_256,
enums.hash.sha3_512
], config.preferredHashAlgorithm); ], config.preferredHashAlgorithm);
signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([ signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
enums.compression.uncompressed enums.compression.uncompressed

View File

@ -2262,7 +2262,7 @@ function versionSpecificTests() {
]); ]);
} }
const hash = openpgp.enums.hash; const hash = openpgp.enums.hash;
expect(selfSignature.preferredHashAlgorithms).to.eql([hash.sha256, hash.sha512]); expect(selfSignature.preferredHashAlgorithms).to.eql([hash.sha256, hash.sha512, hash.sha3_256, hash.sha3_512]);
const compr = openpgp.enums.compression; const compr = openpgp.enums.compression;
expect(selfSignature.preferredCompressionAlgorithms).to.eql([compr.uncompressed]); expect(selfSignature.preferredCompressionAlgorithms).to.eql([compr.uncompressed]);
@ -2317,7 +2317,7 @@ function versionSpecificTests() {
]); ]);
} }
const hash = openpgp.enums.hash; const hash = openpgp.enums.hash;
expect(selfSignature.preferredHashAlgorithms).to.eql([hash.sha224, hash.sha256, hash.sha512]); expect(selfSignature.preferredHashAlgorithms).to.eql([hash.sha224, hash.sha256, hash.sha512, hash.sha3_256, hash.sha3_512]);
const compr = openpgp.enums.compression; const compr = openpgp.enums.compression;
expect(selfSignature.preferredCompressionAlgorithms).to.eql([compr.zlib, compr.uncompressed]); expect(selfSignature.preferredCompressionAlgorithms).to.eql([compr.zlib, compr.uncompressed]);