Skip to content

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
chenkins pushed a commit to chenkins/cryptolib that referenced this pull request Mar 7, 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.

5 participants