diff --git a/src/romulus-m.ts b/src/romulus-m.ts index 17e1422..31e7b10 100644 --- a/src/romulus-m.ts +++ b/src/romulus-m.ts @@ -271,6 +271,8 @@ export function cryptoAeadDecrypt (ciphertext: number[], associatedData: number[ ciphertext.length -= 16 let state = zeroedBuffer(16) + let counter = resetCounter() + if (ciphertext.length !== 0) { state = [...authenticationTag] const parsedCiphertext = parse(ciphertext, 16) @@ -278,8 +280,6 @@ export function cryptoAeadDecrypt (ciphertext: number[], associatedData: number[ const finalCiphertextBlockLength = parsedCiphertext[parsedCiphertextLength].length parsedCiphertext[parsedCiphertextLength] = pad(parsedCiphertext[parsedCiphertextLength], 16) - var counter = resetCounter() - for (let i = 1; i < parsedCiphertextLength + 1; i++) { state = skinnyEncrypt(state, tweakeyEncode(counter, 4, nonce, key)) let mBlock