forked from openpgpjs/openpgpjs
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: PQC: Implement draft RFC for SLH-DSA (shake128s variant only)
Implements Draft 6 (https://datatracker.ietf.org/doc/draft-ietf-openpgp-pqc/06/). NB: signing is currently too slow to be usable (10+ seconds).
- Loading branch information
Showing
18 changed files
with
913 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
import * as kem from './kem/index'; | ||
import * as signature from './signature'; | ||
import * as mlkem from './ml_kem'; | ||
import * as mldsa from './ml_dsa'; | ||
import * as slhdsa from './slh_dsa'; | ||
import enums from '../../../enums'; | ||
|
||
export { | ||
kem, | ||
signature | ||
mlkem, | ||
mldsa, | ||
slhdsa | ||
}; | ||
|
||
const pqcAlgos = new Set([ | ||
enums.publicKey.pqc_mldsa_ed25519, | ||
enums.publicKey.pqc_mlkem_x25519, | ||
enums.publicKey.pqc_slhdsa_shake128s | ||
]); | ||
|
||
export function isPostQuantumAlgo(algo) { | ||
return pqcAlgos.has(algo); | ||
} | ||
|
||
export function getRequiredHashAlgo(signatureAlgo) { | ||
switch (signatureAlgo) { | ||
case enums.publicKey.pqc_mldsa_ed25519: | ||
return mldsa.getRequiredHashAlgo(signatureAlgo); | ||
case enums.publicKey.pqc_slhdsa_shake128s: | ||
return slhdsa.getRequiredHashAlgo(signatureAlgo); | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...c_key/post_quantum/signature/signature.js → ...ublic_key/post_quantum/ml_dsa/combiner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ublic_key/post_quantum/signature/index.js → ...o/public_key/post_quantum/ml_dsa/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { generate, sign, verify, validateParams, getRequiredHashAlgo } from './signature'; | ||
export { expandSecretSeed as mldsaExpandSecretSeed } from './ml_dsa'; | ||
export { generate, sign, verify, validateParams, getRequiredHashAlgo } from './combiner'; | ||
export { expandSecretSeed as mldsaExpandSecretSeed } from './ml_dsa_pure'; |
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ypto/public_key/post_quantum/kem/index.js → ...o/public_key/post_quantum/ml_kem/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { generate, encrypt, decrypt, validateParams } from './kem'; | ||
export { expandSecretSeed as mlkemExpandSecretSeed } from './ml_kem'; | ||
export { generate, encrypt, decrypt, validateParams } from './kem_combiner'; | ||
export { expandSecretSeed as mlkemExpandSecretSeed } from './ml_kem_pure'; |
2 changes: 1 addition & 1 deletion
2
...crypto/public_key/post_quantum/kem/kem.js → ...c_key/post_quantum/ml_kem/kem_combiner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,3 @@ | |
|
||
export { ml_kem768 } from '@noble/post-quantum/ml-kem'; | ||
export { ml_dsa65 } from '@noble/post-quantum/ml-dsa'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import enums from '../../../../enums'; | ||
import { getRandomBytes } from '../../../random'; | ||
|
||
|
||
export async function generate(algo) { | ||
switch (algo) { | ||
case enums.publicKey.pqc_slhdsa_shake128s: { | ||
const { slh_dsa_shake_128s } = await import('@noble/post-quantum/slh-dsa'); | ||
const { secretKey: slhdsaSecretKey, publicKey: slhdsaPublicKey } = slh_dsa_shake_128s.keygen(); | ||
|
||
return { slhdsaSecretKey, slhdsaPublicKey }; | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export async function sign(signatureAlgo, hashAlgo, slhdsaSecretKey, dataDigest) { | ||
if (hashAlgo !== getRequiredHashAlgo(signatureAlgo)) { | ||
// The signature hash algo MUST be set to the specified algorithm, see | ||
// https://www.ietf.org/archive/id/draft-ietf-openpgp-pqc-06.html#section-6.1.1 | ||
throw new Error('Unexpected hash algorithm for PQC signature'); | ||
} | ||
|
||
switch (signatureAlgo) { | ||
case enums.publicKey.pqc_slhdsa_shake128s: { | ||
const { slh_dsa_shake_128s } = await import('@noble/post-quantum/slh-dsa'); | ||
const slhdsaSignature = slh_dsa_shake_128s.sign(slhdsaSecretKey, dataDigest); | ||
return { slhdsaSignature }; | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export async function verify(signatureAlgo, hashAlgo, slhdsaPublicKey, dataDigest, { slhdsaSignature }) { | ||
if (hashAlgo !== getRequiredHashAlgo(signatureAlgo)) { | ||
// The signature hash algo MUST be set to the specified algorithm, see | ||
// https://www.ietf.org/archive/id/draft-ietf-openpgp-pqc-06.html#section-6.1.1 | ||
throw new Error('Unexpected hash algorithm for PQC signature'); | ||
} | ||
|
||
switch (signatureAlgo) { | ||
case enums.publicKey.pqc_slhdsa_shake128s: { | ||
const { slh_dsa_shake_128s } = await import('@noble/post-quantum/slh-dsa'); | ||
return slh_dsa_shake_128s.verify(slhdsaPublicKey, dataDigest, slhdsaSignature); | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export async function validateParams(algo, slhdsaPublicKey, slhdsaSecretKey) { | ||
switch (algo) { | ||
case enums.publicKey.pqc_slhdsa_shake128s: { | ||
// TODO check if more performant validation is possible via public key re-derivation | ||
const randomBytes = getRandomBytes(16); | ||
const { slhdsaSignature } = await sign(algo, slhdsaSecretKey, randomBytes); | ||
const trialSignatureVerified = await verify(algo, slhdsaPublicKey, randomBytes, slhdsaSignature); | ||
return trialSignatureVerified; | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export function getRequiredHashAlgo(signatureAlgo) { | ||
// See https://www.ietf.org/archive/id/draft-ietf-openpgp-pqc-06.html#section-6.1.1 | ||
switch (signatureAlgo) { | ||
case enums.publicKey.pqc_slhdsa_shake128s: | ||
return enums.hash.sha3_256; | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.