ricmoo / aes-js

A pure JavaScript implementation of the AES block cipher and all common modes of operation for node.js or web browsers.
MIT License
1.45k stars 272 forks source link

Is it possible to set the initialization vector in CTR mode? #85

Closed emacsen closed 5 years ago

emacsen commented 5 years ago

There are situations in which it is necessary to set the IV in AES CTR mode, but this doesn't seem to be an option I can pass in this library.

It does appear to be an option in the Node.js implementation of crypto:

crypto.createDecipheriv('aes-256-ctr', key, iv);

Is this something that could be added to this libtary? I'm specifically interested in it for use in browser applications and unsure if this is supported by whatever this library is calling for the browser.

ricmoo commented 5 years ago

This is absolutely an option. :)

In this example the 5 is the IV, but you could also pass in a 16 entry Array (or TypedArray) for your IV into the Counter object, which is what an IV is represented as in CTR mode.

This library is pure JavaScript, so the library is no different for either node or browsers.

Hope that helps, and let me know if you have any more questions. :)

emacsen commented 5 years ago

Ah sorry I thought the example was messing with the counter, rather than the IV itself!

t3db0t commented 3 years ago

Is it accurate to say that the "counter" parameter in this library's AES-CTR mode is the IV?