forked from openpgpjs/openpgpjs
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add ML-DSA + Ed25519 (Node only)
Dilithium lib uses Buffer and doesn't work with browser
- Loading branch information
Showing
11 changed files
with
326 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import * as kem from './kem/index'; | ||
import * as signature from './signature'; | ||
|
||
export { | ||
kem | ||
kem, | ||
signature | ||
}; |
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,40 @@ | ||
// TODOOOOO is this file needed? vs inlining calls in signature.js? | ||
|
||
|
||
import * as eddsa from '../../elliptic/eddsa'; | ||
import enums from '../../../../enums'; | ||
|
||
export async function generate(algo) { | ||
switch (algo) { | ||
case enums.publicKey.pqc_mldsa_ed25519: { | ||
const { A, seed } = await eddsa.generate(enums.publicKey.ed25519); | ||
return { | ||
eccPublicKey: A, | ||
eccSecretKey: seed | ||
}; | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export async function sign(signatureAlgo, hashAlgo, eccSecretKey, eccPublicKey, dataDigest) { | ||
switch (signatureAlgo) { | ||
case enums.publicKey.pqc_mldsa_ed25519: { | ||
const { RS: eccSignature } = await eddsa.sign(enums.publicKey.ed25519, hashAlgo, null, eccPublicKey, eccSecretKey, dataDigest); | ||
|
||
return { eccSignature }; | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export async function verify(signatureAlgo, hashAlgo, eccPublicKey, dataDigest, eccSignature) { | ||
switch (signatureAlgo) { | ||
case enums.publicKey.pqc_mldsa_ed25519: | ||
return eddsa.verify(enums.publicKey.ed25519, hashAlgo, { RS: eccSignature }, null, eccPublicKey, dataDigest); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { generate, sign, verify } from './signature'; |
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,47 @@ | ||
import enums from '../../../../enums'; | ||
|
||
export async function generate(algo) { | ||
switch (algo) { | ||
case enums.publicKey.pqc_mldsa_ed25519: { | ||
const { DilithiumKeyPair, DilithiumLevel } = await import('@asanrom/dilithium'); | ||
|
||
const level = DilithiumLevel.get(3); | ||
const keyPair = DilithiumKeyPair.generate(level); | ||
|
||
const mldsaSecretKey = keyPair.getPrivateKey().getBytes(); | ||
const mldsaPublicKey = keyPair.getPublicKey().getBytes(); | ||
|
||
return { mldsaSecretKey, mldsaPublicKey }; | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export async function sign(algo, mldsaSecretKey, dataDigest) { | ||
switch (algo) { | ||
case enums.publicKey.pqc_mldsa_ed25519: { | ||
const { DilithiumPrivateKey, DilithiumLevel } = await import('@asanrom/dilithium'); | ||
const level = DilithiumLevel.get(3); | ||
const secretKey = DilithiumPrivateKey.fromBytes(mldsaSecretKey, level); | ||
const mldsaSignature = secretKey.sign(dataDigest).getBytes(); | ||
return { mldsaSignature }; | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} | ||
|
||
export async function verify(algo, mldsaPublicKey, dataDigest, mldsaSignature) { | ||
switch (algo) { | ||
case enums.publicKey.pqc_mldsa_ed25519: { | ||
const { DilithiumPublicKey, DilithiumSignature, DilithiumLevel } = await import('@asanrom/dilithium'); | ||
const level = DilithiumLevel.get(3); | ||
const publicKey = DilithiumPublicKey.fromBytes(mldsaPublicKey, level); | ||
const signature = DilithiumSignature.fromBytes(mldsaSignature, level); | ||
return publicKey.verifySignature(dataDigest, signature); | ||
} | ||
default: | ||
throw new Error('Unsupported signature algorithm'); | ||
} | ||
} |
Oops, something went wrong.