Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes same array in memory was used for
generateRandom
in web crypto
I'm not entirely sure why `generateRandom` was reusing the same Uint32Array array stored in `blockRandomArray` variable between calls. It may be the relic of the past, or a bug that was only discovered recently, since we stopped copying this array for some operations. This was causing race condition errors in crypto browser tests, specifically with `multiple_send_*` tests. They generated cipher key using `Crypto.generateRandomKey()` and thus shared the same array in memory which was used for iv generation on each message encryption. This way, cipher key was actually changed in memory after each `CBCCipher.encrypt` call, and if two messages were encrypted back to back, then next call to `CBCCipher.decrypt` would fail due to incorrect cipher key. This regression was introduced in e14f1bf, when we switched from using WordArray and `BufferUtils.toWordArray`, which was copying the array, to ArrayBuffer and `BufferUtils.toArrayBuffer`, which is returning the same array in memory. Resolves #1557
- Loading branch information