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

PBKDF2 updates to conform to SP800-132 #8868

Closed
wants to merge 1 commit into from

Conversation

slontis
Copy link
Member

@slontis slontis commented May 3, 2019

Checklist
  • documentation is added or updated
  • tests are added or updated

crypto/kdf/scrypt.c Outdated Show resolved Hide resolved
doc/man7/EVP_KDF_PBKDF2.pod Outdated Show resolved Hide resolved
doc/man7/EVP_KDF_PBKDF2.pod Outdated Show resolved Hide resolved
test/evp_kdf_test.c Outdated Show resolved Hide resolved
test/evp_kdf_test.c Show resolved Hide resolved
doc/man7/EVP_KDF_PBKDF2.pod Outdated Show resolved Hide resolved
@slontis
Copy link
Member Author

slontis commented May 15, 2019

Updated commit message and rebased.

@mspncp
Copy link
Contributor

mspncp commented May 27, 2019

Would you mind using present tense in the commit message of 1827b7119195? See #8763 (comment) for an explanation.

PBKDF2: conform to SP800-132

The existing code used PKCS5 specifications.
SP800-132 adds the following additional constraints:
  - Check the range of the key length.
  - Minimum iteration count (1000 recommended).
  - Randomly-generated portion of the salt shall be at least 128 bits.
There are cases where the constraints will cause errors (in scrypt, and
some PKCS5 related test vectors) so a ctrl "pkcs5" is added to disable
these additional constraints.

@slontis
Copy link
Member Author

slontis commented May 28, 2019

Updated the commit message and rebased. (This present tense stuff hurts my brain.)

@mspncp
Copy link
Contributor

mspncp commented May 28, 2019

Updated the commit message and rebased. (This present tense stuff hurts my brain.)

Sorry that it hit you so often. I did not mean to stalk you ;-)

@mattcaswell
Copy link
Member

mattcaswell commented May 29, 2019

Looks like you've picked up @t8m's commit in this PR (I guess you rebased on top of github master in the window while 6acf605 was there, before it got force pushed away - see the discussion in #9015 (comment)). Can you rebase this?

@slontis
Copy link
Member Author

slontis commented May 29, 2019

Ahh that would explain the merge commit I had earlier in the day.. sigh.

Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

My suspicion is that this is going to break stuff. It will probably have an impact on "enc" command line usage - e.g. for files that have previously been encrypted with bad iteration counts it might no longer be possible to decrypt them. Probably the breaking aspects of this need wider discussion. At the very least we would need a CHANGES entry. Probably some changes to "enc".

A minimum iteration count of 1000 and length of the salt being at least
128 bits.

The default value is 0. Use 1 to disable the checks.
Copy link
Member

Choose a reason for hiding this comment

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

So, this sounds like having the default like this is a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

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

enc uses the PKCS5_PBKDF2_HMAC() method which sets this control to be 1, as does scrypt.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added note to CHANGES


/* Check that 112 bits <= keylen < (2^32 - 1) * mdlen */
if (((keylen * 8) < KDF_PBKDF2_MIN_KEY_LEN_BITS)
|| ((keylen / mdlen) >= KDF_PBKDF2_MAX_KEY_LEN_DIGEST_RATIO))
Copy link
Member

Choose a reason for hiding this comment

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

Should we be also checking the value of range_checks here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did ponder it - But I think not..
If it goes above that range the counter overflows which is very bad.

Copy link
Member

Choose a reason for hiding this comment

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

If it goes above that range the counter overflows which is very bad.

Perhaps a comment stating that would be helpful

Is that also true for the KDF_PBKDF2_MIN_KEY_LEN_BITS check?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure - I assume that is similar to the salt check so maybe that one goes in the check - in that case I might rename the range_checks variable :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment added and the lower bound check has been moved.

doc/man7/EVP_KDF_PBKDF2.pod Show resolved Hide resolved
crypto/kdf/pbkdf2.c Outdated Show resolved Hide resolved
@slontis slontis changed the title PBKDF2 changed to conform to SP800-132 PBKDF2 updates to conform to SP800-132 May 29, 2019
@slontis
Copy link
Member Author

slontis commented Jun 4, 2019

ping @mattcaswell

@mattcaswell
Copy link
Member

This looks ok, but since this is a breaking change I'd like a wider viewpoint from @openssl/omc.

@slontis
Copy link
Member Author

slontis commented Jun 5, 2019

Note that the minimum iteration count is only recommended (it is not a SHALL) so that particular test could be relaxed (but it is probably a better idea to still force it to at least the recommended value)

@levitte
Copy link
Member

levitte commented Jun 5, 2019

Whether this is a breaking change or not depends on your point of view. EVP_KDF is an unreleased API, so there's nothing that can be called a breaking change there. However, for KDFs implemented via EVP_PKEY, this is effectively a breaking change.

To resolve that issue, the use via EVP_PKEY could be relaxed so as not to pose a problem.

@kroeckx
Copy link
Member

kroeckx commented Jun 5, 2019

I think we should support reading old data from before this change.

@slontis
Copy link
Member Author

slontis commented Jun 6, 2019

To resolve that issue, the use via EVP_PKEY could be relaxed so as not to pose a problem.

Ok so that would be a fairly ugly check. The best solution would probably be to have it default to how it used to work, but in FIPS_MODE it does the extra checks by default. The flag can still be enabled or disabled in either provider.
Does that sound like a better solution?

@slontis
Copy link
Member Author

slontis commented Jun 6, 2019

Updated the default value to disable the checks by default in the default provider.

@mattcaswell
Copy link
Member

Updated the default value to disable the checks by default in the default provider.

Sounds like a reasonable approach.

@levitte
Copy link
Member

levitte commented Jun 8, 2019

I agree with @mattcaswell. Good thinking!

@slontis
Copy link
Member Author

slontis commented Jun 10, 2019

ping @mattcaswell or @levitte : Code was updated to set default check for FIPS_MODE only.

@mattcaswell mattcaswell added the approval: done This pull request has the required number of approvals label Jun 10, 2019
@slontis slontis added this to In progress in 3.0 New Core + FIPS via automation Jun 11, 2019
@slontis
Copy link
Member Author

slontis commented Jun 11, 2019

rebased to fix CHANGES conflict.

@slontis slontis added the branch: master Merge to master branch label Jun 11, 2019
Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Reconfirmed. Although CHANGES is conflicting again :-). I don't think there is a need to seek reapproval where a conflict is trivial. Just go ahead and commit this.

3.0 New Core + FIPS automation moved this from In progress to Reviewer approved Jun 11, 2019
The existing code used PKCS5 specifications.
SP800-132 adds the following additional constraints for:
  - the range of the key length.
  - the minimum iteration count (1000 recommended).
  - salt length (at least 128 bits).
These additional constraints may cause errors (in scrypt, and
some PKCS5 related test vectors). To disable the new
constraints use the new ctrl string "pkcs5".
For backwards compatability, the checks are only enabled by
default for fips mode.
levitte pushed a commit that referenced this pull request Jun 11, 2019
The existing code used PKCS5 specifications.
SP800-132 adds the following additional constraints for:
  - the range of the key length.
  - the minimum iteration count (1000 recommended).
  - salt length (at least 128 bits).
These additional constraints may cause errors (in scrypt, and
some PKCS5 related test vectors). To disable the new
constraints use the new ctrl string "pkcs5".
For backwards compatability, the checks are only enabled by
default for fips mode.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #8868)
@slontis slontis closed this Jun 11, 2019
3.0 New Core + FIPS automation moved this from Reviewer approved to Done Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals branch: master Merge to master branch
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants