Skip to content
Closed
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: 5 additions & 3 deletions lib/cipher/symmetric/aes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ function aesInstrumented(
label: `Block 1 — Round ${r} — MixColumns`,
inputState: fromByteArray(stateBeforeMix, 'hex'),
outputState: fromByteArray(state, 'hex'),
note: 'Treated each state column as a degree-3 polynomial over GF(2^8) and multiplied it by c(x) = {03}x³ + {01}x² + {01}x + {02}, reduced modulo x⁴ + 1. All coefficient arithmetic is performed in GF(2^8).',
note: 'Treated each state column as a degree-3 polynomial over GF(2^8) and multiplied it by c(x) = {03}x³ + {01}x² + {01}x + {02}, reduced modulo x⁴ + 1. All coefficient arithmetic is performed in GF(2^8).',
})

// AddRoundKey
Expand Down Expand Up @@ -647,6 +647,7 @@ function aesInstrumented(
durationMs: performance.now() - start,
}
}

function xorBlocks(a: Uint8Array, b: Uint8Array): Uint8Array {
const result = new Uint8Array(16)
for (let i = 0; i < 16; i++) {
Expand Down Expand Up @@ -814,6 +815,7 @@ function aesStreamInstrumented(
durationMs: performance.now() - start,
}
}

// PKCS7 padding helper
function padPKCS7(bytes: Uint8Array, blockSize: number): Uint8Array {
const paddingVal = blockSize - (bytes.length % blockSize)
Expand Down Expand Up @@ -896,6 +898,7 @@ function aesFast(
durationMs: performance.now() - start,
}
}

function getKeyBytes(key: string): Uint8Array {
let keyBytes: Uint8Array

Expand Down Expand Up @@ -923,7 +926,6 @@ export function encrypt(

const keyBytes = getKeyBytes(key)


const mode = parseMode(options.mode)

// Stream modes (CTR/CFB/OFB) are unpadded; block modes (ECB/CBC) use PKCS7.
Expand Down Expand Up @@ -1012,4 +1014,4 @@ export const TEST_VECTORS: TestVector[] = [
expected: 'randomized',
description: 'AES-128 CBC mode (randomized IV prepended to ciphertext)',
},
]
]
Loading