From c5e1641d9fc962743fdfc9d66ca32716ed089bc8 Mon Sep 17 00:00:00 2001 From: tamarafinogina Date: Wed, 18 Mar 2026 15:52:02 +0100 Subject: [PATCH] remove aux hashing --- src/symmetric-crypto/aes.ts | 8 +++----- src/symmetric-crypto/core.ts | 12 +----------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/symmetric-crypto/aes.ts b/src/symmetric-crypto/aes.ts index df031d8..e4ef1cf 100644 --- a/src/symmetric-crypto/aes.ts +++ b/src/symmetric-crypto/aes.ts @@ -1,4 +1,4 @@ -import { createNISTbasedIV, makeAuxFixedLength, encryptMessage, decryptMessage } from './core'; +import { createNISTbasedIV, encryptMessage, decryptMessage } from './core'; import { concatBytes } from '@noble/hashes/utils.js'; import { IV_LEN_BYTES } from '../constants'; @@ -19,8 +19,7 @@ export async function encryptSymmetrically( ): Promise { try { const iv = createNISTbasedIV(freeField); - const additionalData = await makeAuxFixedLength(aux); - const ciphertext = await encryptMessage(message, encryptionKey, iv, additionalData); + const ciphertext = await encryptMessage(message, encryptionKey, iv, aux); return concatBytes(ciphertext, iv); } catch (error) { throw new Error('Failed to encrypt symmetrically', { cause: error }); @@ -41,10 +40,9 @@ export async function decryptSymmetrically( aux: Uint8Array, ): Promise { try { - const additionalData = await makeAuxFixedLength(aux); const ciphertext = encryptedMessage.slice(0, encryptedMessage.length - IV_LEN_BYTES); const iv = encryptedMessage.slice(encryptedMessage.length - IV_LEN_BYTES); - const result = await decryptMessage(ciphertext, iv, encryptionKey, additionalData); + const result = await decryptMessage(ciphertext, iv, encryptionKey, aux); return result; } catch (error) { throw new Error('Failed to decrypt symmetrically', { cause: error }); diff --git a/src/symmetric-crypto/core.ts b/src/symmetric-crypto/core.ts index e43b613..a95c506 100644 --- a/src/symmetric-crypto/core.ts +++ b/src/symmetric-crypto/core.ts @@ -1,7 +1,7 @@ import { gcm as aeadCipher } from '@noble/ciphers/webcrypto.js'; import { randomBytes } from '@noble/post-quantum/utils.js'; import { getBytesFromData } from '../hash'; -import { AUX_BYTE_LEN, IV_LEN_BYTES } from '../constants'; +import { IV_LEN_BYTES } from '../constants'; /** * Creates an initialization vector (IV) using RGB-based construction (8.2.2 NIST Special Publication 800-38D) @@ -31,16 +31,6 @@ export function createNISTbasedIV(freeField?: Uint8Array): Uint8Array { } } -/** - * Hashes aux string to make it fixed-length - * - * @param aux - The auxilay string of arbitrary length - * @returns The resulting fixed-length auxilary string. - */ -export async function makeAuxFixedLength(aux: Uint8Array): Promise { - return getBytesFromData(AUX_BYTE_LEN, aux); -} - /** * Symmetrically encrypts message *