Skip to content

Commit a3500eb

Browse files
committed
randomBuffer enabled instead of empty buffer for testing
demo changes crypto function name changes & additions
1 parent 92dfbb9 commit a3500eb

File tree

8 files changed

+41
-13
lines changed

8 files changed

+41
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"server": "nodemon ./serverApp/index.js --watch ./udsp/ --watch ./serverApp/ --watch ./utilities/",
101101
"simulate": "nodemon ./scripts/simulate.js --watch ./client/ --watch ./server/ --watch ./scripts/simulate.js --watch utilities/",
102102
"connectRequest": "nodemon ./scripts/client/connectRequest.js --watch ./udsp/ --watch ./scripts/client/connectRequest.js --watch ./utilities/ --delay 3",
103+
"connectRequestHybridKyber": "nodemon ./scripts/client/connectRequestHybridKyber.js --watch ./udsp/ --watch ./scripts/client/connectRequestHybridKyber.js --watch ./utilities/ --delay 3",
103104
"connect": "nodemon ./scripts/client/connect.js --watch ./udsp/ --watch ./scripts/client/connect.js --watch ./utilities/ --delay 3",
104105
"closeReconnect": "nodemon ./scripts/client/closeReconnect.js --watch ./udsp/ --watch ./scripts/client/closeReconnect.js --watch ./utilities/ --delay 3",
105106
"request": "nodemon ./scripts/client/request.js --watch ./udsp/ --watch ./scripts/client/request.js --watch ./utilities/ --delay 3",
File renamed without changes.

utilities/crypto.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ export function randomBuffer(size = 8) {
3939
randomize(target);
4040
return target;
4141
}
42+
const int32 = 32;
43+
export function random32ByteBuffer() {
44+
const target = bufferAlloc(int32);
45+
randomize(target);
46+
return target;
47+
}
48+
const int64 = 64;
49+
export function random64ByteBuffer() {
50+
const target = bufferAlloc(int64);
51+
randomize(target);
52+
return target;
53+
}
4254
export function randomConnectionId(size = 8) {
4355
return randomBuffer(size);
4456
}

utilities/cryptoMiddleware/dilithium44.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ml_dsa44 } from '@noble/post-quantum/ml-dsa';
12
/*
23
Algorithm 1, implementing key generation for ML-DSA, uses an RBG to generate the 256-bit random
34
value ξ . The seed ξ shall be freshly generated using an approved RBG, as prescribed in NIST SP 800-90A,
@@ -7,10 +8,9 @@
78
RBG with at least 128 bits of security but less than 192 bits of security is used, then the claimed security
89
strength of ML-DSA-44 is reduced from category 2 to category 1.)
910
*/
10-
import { bufferAlloc } from '../crypto.js';
11-
import { ml_dsa44 } from '@noble/post-quantum/ml-dsa';
11+
import { randomBuffer } from '../crypto.js';
1212
export function createSeed(size = 32) {
13-
const seed = bufferAlloc(size);
13+
const seed = randomBuffer(size);
1414
return seed;
1515
}
1616
export async function signatureKeypair(seed = createSeed()) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
createSeed,
3+
sign,
4+
signatureKeypair,
5+
verifySignature
6+
} from './dilithium44.js';
7+
export const dilithium44_ed25519 = {
8+
name: 'dilithium44_ed25519',
9+
alias: 'dilithium44_ed25519',
10+
id: 1,
11+
createSeed,
12+
signatureKeypair,
13+
sign,
14+
verifySignature
15+
};

utilities/cryptoMiddleware/dilithium65.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { ml_dsa65, ml_dsa87 } from '@noble/post-quantum/ml-dsa';
88
RBG with at least 128 bits of security but less than 192 bits of security is used, then the claimed security
99
strength of ML-DSA-44 is reduced from category 2 to category 1.)
1010
*/
11-
import { bufferAlloc } from '../crypto.js';
11+
import { randomBuffer } from '../crypto.js';
1212
export function createSeed(size = 32) {
13-
const seed = bufferAlloc(size);
13+
const seed = randomBuffer(size);
1414
return seed;
1515
}
1616
export async function signatureKeypair(seed = createSeed()) {
@@ -31,7 +31,7 @@ export async function verifySignature(signedMessage, publicKey, message) {
3131
export const dilithium65 = {
3232
name: 'dilithium65',
3333
alias: 'dilithium65',
34-
id: 1,
34+
id: 2,
3535
createSeed,
3636
signatureKeypair,
3737
sign,

utilities/cryptoMiddleware/dilithium87.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ml_dsa87 } from '@noble/post-quantum/ml-dsa';
12
/*
23
Algorithm 1, implementing key generation for ML-DSA, uses an RBG to generate the 256-bit random
34
value ξ . The seed ξ shall be freshly generated using an approved RBG, as prescribed in NIST SP 800-90A,
@@ -7,10 +8,9 @@
78
RBG with at least 128 bits of security but less than 192 bits of security is used, then the claimed security
89
strength of ML-DSA-44 is reduced from category 2 to category 1.)
910
*/
10-
import { bufferAlloc } from '../crypto.js';
11-
import { ml_dsa87 } from '@noble/post-quantum/ml-dsa';
11+
import { randomBuffer } from '../crypto.js';
1212
export function createSeed(size = 32) {
13-
const seed = bufferAlloc(size);
13+
const seed = randomBuffer(size);
1414
return seed;
1515
}
1616
export async function signatureKeypair(seed = createSeed()) {
@@ -31,7 +31,7 @@ export async function verifySignature(signedMessage, publicKey, message) {
3131
export const dilithium87 = {
3232
name: 'dilithium87',
3333
alias: 'dilithium87',
34-
id: 1,
34+
id: 3,
3535
createSeed,
3636
signatureKeypair,
3737
sign,

utilities/cryptoMiddleware/x25519XChaCha.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import {
2222
verifySignature,
2323
verifySignatureDetached,
2424
} from './ed25519.js';
25-
import { blake3 } from '@noble/hashes/blake3';
26-
import { hash } from './blake3.js';
25+
import { blake3 } from './blake3.js';
2726
const sodium = await import('sodium-native');
2827
const sodiumLib = sodium?.default || sodium;
2928
const {
@@ -33,6 +32,7 @@ const {
3332
const {
3433
randomConnectionId, randomBuffer, toBase64
3534
} = defaultCrypto;
35+
const hash = blake3.hash;
3636
export const x25519_xchacha20 = {
3737
name: 'x25519_xchacha20',
3838
alias: 'default',
@@ -65,5 +65,5 @@ export const x25519_xchacha20 = {
6565
serverInitializeSession: serverSetSessionAttach,
6666
serverSetSession: serverSetSessionAttach,
6767
preferred: true,
68-
hash: blake3,
68+
hash,
6969
};

0 commit comments

Comments
 (0)