Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

AES_CBC.decrypt is broken with default iv #142

Open
cvlmtg opened this issue Feb 12, 2018 · 0 comments
Open

AES_CBC.decrypt is broken with default iv #142

cvlmtg opened this issue Feb 12, 2018 · 0 comments

Comments

@cvlmtg
Copy link

cvlmtg commented Feb 12, 2018

Hi, I just tried to upgrade from 0.0.11 to 0.22.0 and my code doesn't work anymore because of this error:

TypeError: unexpected iv type

following the code it seems an error of asmycrypto. I call:

asmCrypto.AES_CBC.decrypt(data, key);

which calls AES_CBC_decrypt_bytes(data, key, padding, iv), which calls:

class AES_CBC extends AES {
     /**
      * @param {Uint8Array} key
      * @param {Uint8Array} [iv=null]
      * @param {boolean} [padding=true]
      * @param {Uint8Array} [heap]
      * @param {Uint8Array} [asm]
      */
     constructor(key, iv = null, padding = true, heap, asm) {
       super(key, iv, padding, heap, asm);

please note that since I did not specify iv (which the docs says is optional) it was undefined in AES_CBC_decrypt_bytes but now gets converted to null because of the default value specified in the constructor. the constructor call super() which then calls:

this.AES_reset(key, iv, padding);

which calls:

this.AES_set_iv(iv);

inside AES_set_iv we have:

       if (iv !== undefined) {
         if (!is_bytes(iv)) {
           throw new TypeError('unexpected iv type');
         }

since 'iv' has been set to null we have is_bytes(null) which is false. the error is in the AES_CBC class which sets iv to null instead of leaving it undefined.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant