-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
181 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CoseKey } from "."; | ||
|
||
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa'; | ||
import { toArrayBuffer } from "../../cbor"; | ||
|
||
export const signer = (secretKey: CoseKey) => { | ||
const alg = secretKey.get(3); | ||
if (alg === -49) { | ||
return { | ||
sign: async (bytes: ArrayBuffer) => { | ||
return toArrayBuffer(ml_dsa65.sign(new Uint8Array(secretKey.get(-2) as ArrayBuffer), new Uint8Array(bytes))) | ||
} | ||
} | ||
} | ||
throw new Error('Unsupported 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,16 @@ | ||
import { CoseKey } from "."; | ||
|
||
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa'; | ||
import { toArrayBuffer } from "../../cbor"; | ||
|
||
export const signer = (publicKey: CoseKey) => { | ||
const alg = publicKey.get(3); | ||
if (alg === -49) { | ||
return { | ||
verify: async (bytes: ArrayBuffer) => { | ||
return toArrayBuffer(ml_dsa65.sign(new Uint8Array(secretKey.get(-2) as ArrayBuffer), new Uint8Array(bytes))) | ||
} | ||
} | ||
} | ||
throw new Error('Unsupported 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as cose from '../../src' | ||
|
||
it('ML-DSA-65', async () => { | ||
const secretKey = await cose.key.generate<cose.key.CoseKey>('ML-DSA-65') | ||
const publicKey = await cose.key.publicFromPrivate<cose.key.CoseKey>(secretKey) | ||
const signer = cose.detached.signer({ | ||
remote: cose.key.signer(secretKey) | ||
}) | ||
const message = '💣 test ✨ mesage 🔥' | ||
const payload = new TextEncoder().encode(message) | ||
const coseSign1 = await signer.sign({ | ||
protectedHeader: new Map([ | ||
[1, -49] // alg : ML-DSA-65 | ||
]), | ||
unprotectedHeader: new Map(), | ||
payload | ||
}) | ||
const verifier = cose.detached.verifier({ | ||
resolver: { | ||
resolve: async () => { | ||
return cose.key.convertCoseKeyToJsonWebKey(publicKey) | ||
} | ||
} | ||
}) | ||
// console.log(await cose.cbor.diagnose(coseSign1)) | ||
const verified = await verifier.verify({ coseSign1, payload: payload }) | ||
expect(new TextDecoder().decode(verified)).toBe(message) | ||
}) |
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,11 @@ | ||
|
||
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa'; | ||
|
||
it('ml_dsa65', () => { | ||
const seed = new TextEncoder().encode('not a safe seed') | ||
const aliceKeys = ml_dsa65.keygen(seed); | ||
const msg = new Uint8Array(1); | ||
const sig = ml_dsa65.sign(aliceKeys.secretKey, msg); | ||
const isValid = ml_dsa65.verify(aliceKeys.publicKey, msg, sig); | ||
expect(isValid).toBe(true) | ||
}) |