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

crypto,doc: update language regarding key stretching #19810

Closed
wants to merge 1 commit into from

Conversation

ryzokuken
Copy link
Contributor

Update the docs to provide clearer instructions regarding the exact scope
of the use (and re-use) of an IV, stating the instructions explicitly with
greater clarity.

Fixes: #19748

Checklist

/cc @bnoordhuis @tniessen

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. labels Apr 4, 2018
@@ -1365,6 +1365,8 @@ The `key` is the raw key used by the `algorithm` and `iv` is an
[Buffers][`Buffer`], `TypedArray`, or `DataView`s. If the cipher does not need
an initialization vector, `iv` may be `null`.

An initialization vector should be unpredictable; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages in plaintext. It may sound contradictory that something has to be unpredictable, but doesn’t have to be secret; it’s important to remember that an attacker must not be able to predict ahead of time what a given IV will be.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines need to be wrapped at 80 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't they? strange. I'll do that promptly, sorry.

Copy link
Contributor Author

@ryzokuken ryzokuken Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, wait. It's just one single huge line.

@@ -1437,6 +1439,8 @@ The `key` is the raw key used by the `algorithm` and `iv` is an
[Buffers][`Buffer`], `TypedArray`, or `DataView`s. If the cipher does not need
an initialization vector, `iv` may be `null`.

An initialization vector should be unpredictable; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages in plaintext. It may sound contradictory that something has to be unpredictable, but doesn’t have to be secret; it’s important to remember that an attacker must not be able to predict ahead of time what a given IV will be.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@@ -1365,6 +1365,8 @@ The `key` is the raw key used by the `algorithm` and `iv` is an
[Buffers][`Buffer`], `TypedArray`, or `DataView`s. If the cipher does not need
an initialization vector, `iv` may be `null`.

An initialization vector should be unpredictable; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages in plaintext. It may sound contradictory that something has to be unpredictable, but doesn’t have to be secret; it’s important to remember that an attacker must not be able to predict ahead of time what a given IV will be.
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An initialization vector -> Initialization vectors?
Or
they will be -> it will be, They do not have -> It does not have?

@ryzokuken
Copy link
Contributor Author

@tniessen @vsemozhetbyt fixed.

@vsemozhetbyt
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt added fast-track PRs that do not need to wait for 48 hours to land. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Apr 4, 2018
@@ -1365,6 +1365,13 @@ The `key` is the raw key used by the `algorithm` and `iv` is an
[Buffers][`Buffer`], `TypedArray`, or `DataView`s. If the cipher does not need
an initialization vector, `iv` may be `null`.

Initialization vectors should be unpredictable; ideally, they will be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really depends on the cipher block mode, some work fine even with predictable IVs. What is much more important is that IVs are unique and that their value cannot be influenced by an attacker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. How should I better communicate this, in your opinion?

I (among a lot of other people, I'm sure), prefer to keep the IV unpredictable (cryptographically random) anyway. Better be safe than be sorry, I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should be unpredictable and unique? That's not always true, but as you said, better safe than sorry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll add unique. I think that was exactly what @bnoordhuis wanted to communicate as well.

cryptographically random. They do not have to be secret: IVs are typically just
added to ciphertext messages in plaintext. It may sound contradictory that
something has to be unpredictable, but doesn’t have to be secret; it’s
importantto remember that an attacker must not be able to predict ahead of time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space in importantto. Actually, I am not sure what this sentence is supposed to say apart from what the previous said.

Copy link
Contributor Author

@ryzokuken ryzokuken Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may sound contradictory that something has to be unpredictable, but does not have to be secret; it is important to remember that an attacker must not be able to predict ahead of time what a given IV will be.

Emphasis on ahead of time here. While the IV does not have to be (and mostly isn't) secret, It needs to be unpredictable. It can be as obvious as it could be in hindsight, but it's important that the attack should not be able to predict it ahead of time.

I hope that makes my stance clearer? I'm willing to chop this down if you don't find it up to the mark?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion here, I am okay with or without the sentence. (Just remember that it is not entirely true for all block cipher modes.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal standard here is that in case of ambiguity (here: the exact block cipher being used), we should go with the most secure solution which would work well with all of the alternatives, and I think the current definition works for all of the ciphers we're supporting.

That said, my knowledge of both the crypto subsystem and the Node crypto ecosystem are substantially less than yours, and I'd trust your instincts on this.

Initialization vectors should be unpredictable; ideally, they will be
cryptographically random. They do not have to be secret: IVs are typically just
added to ciphertext messages in plaintext. It may sound contradictory that
something has to be unpredictable, but doesn’t have to be secret; it’s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn'tdoes not, it'sit is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on it.

@tniessen tniessen removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. fast-track PRs that do not need to wait for 48 hours to land. labels Apr 4, 2018
@ryzokuken ryzokuken force-pushed the docs/crypto-iv branch 2 times, most recently from b944ecc to e283a51 Compare April 4, 2018 22:05
@@ -1365,6 +1365,13 @@ The `key` is the raw key used by the `algorithm` and `iv` is an
[Buffers][`Buffer`], `TypedArray`, or `DataView`s. If the cipher does not need
an initialization vector, `iv` may be `null`.

Initialization vectors should be unpredictable; ideally, they will be
cryptographically random. They do not have to be secret: IVs are typically just
added to ciphertext messages in plaintext. It may sound contradictory that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe don't say 'plaintext' here, that has a specific meaning in crypto speak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I meant, it's sent "in the plain", or more precisely, unencrypted. I'll substitute "in plaintext" with "unencrypted". Is that better?

Initialization vectors should be unpredictable; ideally, they will be
cryptographically random. They do not have to be secret: IVs are typically just
added to ciphertext messages unencrypted. It may sound contradictory that
something has to be unpredictable and unique, but does not have to be secret;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move and unique to the beginning (the first sentence)? It really is the most important property of an IV, compared to that, predictability has very limited attack vectors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make too much sense not using the word unique in this sentence, does it? I'll definitely add it to the beginning as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't hurt to have it twice, but it should definitely be in the beginning 👍

Update the docs to provide clearer instructions regarding the exact scope
of the use (and re-use) of an IV, stating the instructions explicitly with
greater clarity.

Fixes: nodejs#19748
@tniessen tniessen added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 5, 2018
@tniessen
Copy link
Member

tniessen commented Apr 5, 2018

(Subsystem should probably just be doc.)

@ryzokuken
Copy link
Contributor Author

ryzokuken commented Apr 5, 2018 via email

@tniessen
Copy link
Member

tniessen commented Apr 5, 2018

@ryzokuken
Copy link
Contributor Author

@tniessen is this landable now?

@tniessen
Copy link
Member

tniessen commented Apr 6, 2018

@ryzokuken Yes, as soon as 48 hours have passed :)

@ryzokuken
Copy link
Contributor Author

ryzokuken commented Apr 6, 2018 via email

@tniessen
Copy link
Member

tniessen commented Apr 8, 2018

Landed in 0a67932.

@tniessen tniessen closed this Apr 8, 2018
tniessen pushed a commit that referenced this pull request Apr 8, 2018
Update the docs to provide clearer instructions regarding the exact
scope of the use (and re-use) of an IV, stating the instructions
explicitly with greater clarity.

PR-URL: #19810
Fixes: #19748
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
targos pushed a commit that referenced this pull request Apr 12, 2018
Update the docs to provide clearer instructions regarding the exact
scope of the use (and re-use) of an IV, stating the instructions
explicitly with greater clarity.

PR-URL: #19810
Fixes: #19748
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crypto,doc: update language around key stretching
6 participants