Skip to content

Improve speed of PBKDF2 by caching the digest state of the passphrase #277

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

Merged
merged 1 commit into from
Sep 30, 2019

Conversation

jack-fortanix
Copy link
Contributor

mbedtls_md_hmac_starts computes a hash block consisting of H(passphrase xor ipad), but this operations is performed again and again during the PBKDF2 computation even though it always produces the same result. Instead call mbedtls_md_hmac_starts once at the start of computation and use mbedtls_md_hmac_restart to reuse the same key again.

In my measurements (x86-64 machine, gcc, using SHA-256, 1 million iterations) this is about 10% faster than the current code, which matters quite a lot eg on a server which regularly validates user logins against a hash database.

@gilles-peskine-arm
Copy link
Collaborator

Thank you for your contribution! We'll review it as soon as we can.

The CI failures are a known issue which is unrelated to this PR.

@gilles-peskine-arm gilles-peskine-arm added the needs: review The pull request is ready for review. This generally means that it has no known issues. label Sep 24, 2019
@k-stachowiak k-stachowiak self-requested a review September 25, 2019 08:31
@gilles-peskine-arm
Copy link
Collaborator

CI is ok except for some TLS tests that failed due to an unrelated issue in mbedtls (since fixed).

@gilles-peskine-arm gilles-peskine-arm merged commit 9a562d4 into ARMmbed:development Sep 30, 2019
gilles-peskine-arm added a commit to Mbed-TLS/mbedtls that referenced this pull request Oct 8, 2019
Update crypto submodule:

* ARMmbed/mbed-crypto#277: Improve speed of PBKDF2 by caching the digest state of the passphras
* ARMmbed/mbed-crypto#269: Add PSA API versioning
* ARMmbed/mbed-crypto#278: Fix on target test issues
* ARMmbed/mbed-crypto#286: Fix defgroup syntax for API version section
* ARMmbed/mbed-crypto#75: ASN.1 tests without x509
gilles-peskine-arm added a commit to gilles-peskine-arm/mbed-crypto that referenced this pull request Nov 15, 2019
* ARMmbed#277: Improve speed of PBKDF2 by caching the digest state of the passphrase
* ARMmbed#269: Add PSA API versioning
* ARMmbed#278: Fix on target test issues
* ARMmbed#286: Fix defgroup syntax for API version section
* ARMmbed#75: ASN.1 tests without x509
Patater pushed a commit that referenced this pull request Jan 15, 2020
Check array index range in GCM multiplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: review The pull request is ready for review. This generally means that it has no known issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants