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

use 512 bit keys for HMAC-SHA256 #31

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

overheadhunter
Copy link
Contributor

When HKDF uses SHA-512, the native output size is 512 bit.

When HMAC uses SHA256, the internal block size is also 512 bit. If the key is shorter than the block size, it gets padded.

I.e. using a 256 bit key introduces unnecessary intermediate steps:

flowchart LR
  hkdf["HKDF-SHA512"] -->|"512 bit key"| truncate
  truncate -->|"256 bit key"| pad
  pad -->|"512 bit key"| hmac["HMAC-SHA256"]
Loading

So let's simplify this to:

flowchart LR
  hkdf["HKDF-SHA512"] -->|"512 bit key"| hmac["HMAC-SHA256"]
Loading

Not only does this remove unnecessary operations. Furthermore, truncating and then padding the key reduce the effective key size (assuming surrounding operations provide equally high security).

@overheadhunter overheadhunter merged commit 682b59f into develop Mar 5, 2025
@overheadhunter overheadhunter deleted the feature/512bit-hmac-keys branch March 5, 2025 11:39
overheadhunter added a commit to cryptomator/cryptolib that referenced this pull request Mar 6, 2025
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

Successfully merging this pull request may close these issues.

4 participants