Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption with “constant” initialization vector considered harmful #3

Open
jcalfee opened this issue Oct 20, 2016 · 3 comments
Open

Comments

@jcalfee
Copy link

jcalfee commented Oct 20, 2016

Looks like your using a CBC (aes-128-cbc), so this should apply to you:

https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Initialization_vector_.28IV.29

An initialization vector has different security requirements than a key, so the IV usually does not need to be secret. However, in most cases, it is important that an initialization vector is never reused under the same key. For CBC and CFB, reusing an IV leaks some information about the first block of plaintext, and about any common prefix shared by the two messages.

Sounds like you can simply prefix your encrypted data with a unique nonce (like Date.now() + random_value). The random_value is a value in RAM used to keep the none unique in a cluster of nodes. Sha256 hash the nonce to get the IV value.

@jcalfee
Copy link
Author

jcalfee commented Oct 21, 2016

Reference:

let iv = opts.iv || new Buffer('cvdgfjf1837483jn')

@jcalfee
Copy link
Author

jcalfee commented Oct 26, 2016

If you're interested, I created a branch that is close to being a pull request. It is a breaking change and I'm not sure how you want to handle that.

https://github.com/steemit/koa-crypto-session/tree/koa-crypto-session-pull-request

@haoxins
Copy link
Member

haoxins commented Oct 27, 2016

SGTM, PR welcome

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

No branches or pull requests

2 participants