Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/symmetric-crypto/aes.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,8 +19,7 @@ export async function encryptSymmetrically(
): Promise<Uint8Array> {
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 });
Expand All @@ -41,10 +40,9 @@ export async function decryptSymmetrically(
aux: Uint8Array,
): Promise<Uint8Array> {
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 });
Expand Down
12 changes: 1 addition & 11 deletions src/symmetric-crypto/core.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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<Uint8Array> {
return getBytesFromData(AUX_BYTE_LEN, aux);
}

/**
* Symmetrically encrypts message
*
Expand Down
Loading