paulmillr / noble-ciphers

Audited & minimal JS implementation of Salsa20, ChaCha and AES
https://paulmillr.com/noble
MIT License
214 stars 8 forks source link

RangeError when decrypting chacha20poly1305: start offset of Uint32Array should be a multiple of 4 #7

Closed hazae41 closed 1 year ago

hazae41 commented 1 year ago

I was trying to decrypt 2246 bytes (Uint8Array) with 12 bytes IV and got the error

chacha20poly1305(key, iv).decrypt(bytes)

RangeError: start offset of Uint32Array should be a multiple of 4

It also happens if I force .slice() to copy to a new buffer

chacha20poly1305(key, iv).decrypt(bytes.slice())

Using Stablelib it works fine

new ChaCha20Poly1305(key).open(iv, cipher)
paulmillr commented 1 year ago

for now either key or iv need to be their own array and now a subarray: chacha20poly1305(key.slice(), iv.slice()) should be a workaround

hazae41 commented 1 year ago

Thanks, it works

paulmillr commented 1 year ago

Fixed