Skip to content

Commit 3d56ba1

Browse files
committed
Moving to SHAKE256
1 parent 577560f commit 3d56ba1

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

udsp/cryptoMiddleware/cipherSuite/Kyber768_xChaCha.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const {
2626
randomBuffer,
2727
toBase64,
2828
toHex,
29-
combineKeys,
29+
combineKeysSHAKE256,
3030
clearBuffer,
3131
clearBuffers
3232
} = defaultCrypto;
@@ -75,8 +75,8 @@ export const kyber768_xChaCha = {
7575
const sharedSecret = source.sharedSecret;
7676
const oldTransmitKey = source.transmitKey;
7777
const oldReceiveKey = source.receiveKey;
78-
source.transmitKey = combineKeys(oldTransmitKey, source.sharedSecret);
79-
source.receiveKey = combineKeys(oldReceiveKey, source.sharedSecret);
78+
source.transmitKey = combineKeysSHAKE256(oldTransmitKey, source.sharedSecret);
79+
source.receiveKey = combineKeysSHAKE256(oldReceiveKey, source.sharedSecret);
8080
clearBuffer(oldTransmitKey);
8181
clearBuffer(oldReceiveKey);
8282
clearBuffer(source.sharedSecret);
@@ -148,8 +148,8 @@ export const kyber768_xChaCha = {
148148
const sharedSecret = source.sharedSecret;
149149
const oldTransmitKey = source.transmitKey;
150150
const oldReceiveKey = source.receiveKey;
151-
source.transmitKey = combineKeys(oldTransmitKey, source.sharedSecret);
152-
source.receiveKey = combineKeys(oldReceiveKey, source.sharedSecret);
151+
source.transmitKey = combineKeysSHAKE256(oldTransmitKey, source.sharedSecret);
152+
source.receiveKey = combineKeysSHAKE256(oldReceiveKey, source.sharedSecret);
153153
clearBuffer(oldTransmitKey);
154154
clearBuffer(oldReceiveKey);
155155
clearBuffer(source.sharedSecret);

udsp/cryptoMiddleware/cipherSuite/x25519_Kyber768_xChaCha.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { kyber768_x25519 } from '../keyExchange/kyber768_x25519.js';
2929
import { shake256 } from '@noble/hashes/sha3';
3030
import { x25519_kyber768Half_xchacha20 } from './x25519_Kyber768Half_xChaCha.js';
3131
const hashFunction = shake256;
32+
// CHANGE THIS TO BE SAFE TO ITS OWN AT kyber768_x25519
3233
const { clientSetSession } = x25519_kyber768Half_xchacha20;
3334
const {
3435
serverSetSessionAttach,
@@ -38,7 +39,6 @@ const {
3839
randomBuffer,
3940
toBase64,
4041
toHex,
41-
combineKeys,
4242
} = defaultCrypto;
4343
const {
4444
clientInitializeSession,

udsp/cryptoMiddleware/cipherSuite/x25519_xChaCha.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const {
2828
clearBuffer,
2929
clearBuffers,
3030
getX25519Key,
31-
combineKeys,
3231
combineSessionKeys
3332
} = defaultCrypto;
3433
const { id: encryptionKeypairID } = x25519;

udsp/cryptoMiddleware/keyExchange/kyber768_x25519.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// CONVERT THIS TO SHAKE256 AFTER x25519_blake3 is done
2+
// Consider SHAKE256 as the hash function for x25519_shake256 variant
13
import * as defaultCrypto from '#crypto';
24
import {
35
clientSetSession,

utilities/crypto.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const sodiumLib = sodium?.default || sodium;
66
const { randombytes_buf } = sodiumLib;
77
import { clear, isBuffer } from '@universalweb/acid';
88
import { blake3 } from '@noble/hashes/blake3';
9-
export const defaultHashFunction = blake3;
9+
import { shake256 } from '@noble/hashes/sha3';
10+
export const basicHashFunction = blake3;
11+
export const defaultHashFunction = shake256;
1012
export const int32 = 32;
1113
export const int64 = 64;
1214
export function toBuffer(source) {
@@ -86,6 +88,11 @@ export function cleanKeypair(source) {
8688
return source;
8789
}
8890
export function combineKeys(...sources) {
91+
// console.log('Combine', key1, key2);
92+
const combinedKeys = basicHashFunction(Buffer.concat(sources));
93+
return combinedKeys;
94+
}
95+
export function combineKeysSHAKE256(...sources) {
8996
// console.log('Combine', key1, key2);
9097
const combinedKeys = defaultHashFunction(Buffer.concat(sources));
9198
return combinedKeys;
@@ -101,7 +108,7 @@ export function combineSessionKeys(oldTransmitKey, oldReceiveKey, source) {
101108
}
102109
export function combineKeysFreeMemory(...sources) {
103110
// console.log('Combine', key1, key2);
104-
const combinedKeys = defaultHashFunction(Buffer.concat(sources));
111+
const combinedKeys = basicHashFunction(Buffer.concat(sources));
105112
clearBuffers(...sources);
106113
return combinedKeys;
107114
}

0 commit comments

Comments
 (0)