Bug Description
BenchmarkEngine.generateKey(lengthInBytes) in lib/utils/benchmark.ts produces a hex string with lengthInBytes characters (nibbles), which is only lengthInBytes / 2 actual bytes. The function name and parameter clearly document the intent as byte count, but the implementation generates half as many bytes as requested.
Steps to Reproduce
- Call
BenchmarkEngine.generateKey(16) — intended to produce a 16-byte key for AES-128.
- Observe: the returned string has 16 hex characters = 8 bytes, not 16.
- Pass this key to an AES encrypt benchmark — it throws
INVALID_KEY_LENGTH because AES requires exactly 16, 24, or 32 bytes.
Expected Behavior
BenchmarkEngine.generateKey(16) should return a string representing exactly 16 bytes (i.e. 32 hex characters).
Actual Behavior
The function loops lengthInBytes times, appending one hex character per iteration:
// lib/utils/benchmark.ts line 27
for (let i = 0; i < lengthInBytes; i++) { // loops 16 times
result += hex.charAt(...) // appends 1 nibble each time
}
// result = 16 chars = 8 bytes ← wrong
This means every cipher that relies on the benchmark engine for key generation receives a key that is half the intended size, causing silent failures or thrown errors during benchmark runs.
Screenshots
N/A — reproducible via unit test:
const key = BenchmarkEngine.generateKey(16)
console.log(key.length) // prints 16 — should be 32 for 16 bytes
Environment
- OS: Any
- Browser: Any
- Version: Latest (
main branch)
Additional Context
Affected file: lib/utils/benchmark.ts lines 24–31
Fix: loop lengthInBytes * 2 times so that each byte is represented by two hex characters:
static generateKey(lengthInBytes: number): string {
const hex = '0123456789abcdef'
let result = ''
- for (let i = 0; i < lengthInBytes; i++) {
+ for (let i = 0; i < lengthInBytes * 2; i++) {
result += hex.charAt(Math.floor(Math.random() * hex.length))
}
return result
}
Bug Description
BenchmarkEngine.generateKey(lengthInBytes)inlib/utils/benchmark.tsproduces a hex string withlengthInBytescharacters (nibbles), which is onlylengthInBytes / 2actual bytes. The function name and parameter clearly document the intent as byte count, but the implementation generates half as many bytes as requested.Steps to Reproduce
BenchmarkEngine.generateKey(16)— intended to produce a 16-byte key for AES-128.INVALID_KEY_LENGTHbecause AES requires exactly 16, 24, or 32 bytes.Expected Behavior
BenchmarkEngine.generateKey(16)should return a string representing exactly 16 bytes (i.e. 32 hex characters).Actual Behavior
The function loops
lengthInBytestimes, appending one hex character per iteration:This means every cipher that relies on the benchmark engine for key generation receives a key that is half the intended size, causing silent failures or thrown errors during benchmark runs.
Screenshots
N/A — reproducible via unit test:
Environment
mainbranch)Additional Context
Affected file:
lib/utils/benchmark.tslines 24–31Fix: loop
lengthInBytes * 2times so that each byte is represented by two hex characters:static generateKey(lengthInBytes: number): string { const hex = '0123456789abcdef' let result = '' - for (let i = 0; i < lengthInBytes; i++) { + for (let i = 0; i < lengthInBytes * 2; i++) { result += hex.charAt(Math.floor(Math.random() * hex.length)) } return result }