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

Recommended HMAC key length for ecdsa-sd-2023? #58

Closed
filip26 opened this issue Feb 25, 2024 · 4 comments
Closed

Recommended HMAC key length for ecdsa-sd-2023? #58

filip26 opened this issue Feb 25, 2024 · 4 comments
Assignees
Labels
CR1 normative This item is a normative change. pr exists

Comments

@filip26
Copy link

filip26 commented Feb 25, 2024

Hi,
I've not found any mention about a recommended HMAC key length. Test vector Example 49 says 32 bytes. Is it the only allowed length?

@Wind4Greg
Copy link
Collaborator

Agree @filip26 need to give either a recommendation or requirement here. Was just looking over my test vector code the other day and was wondering about this same issue.

@Wind4Greg Wind4Greg self-assigned this Feb 27, 2024
@Wind4Greg
Copy link
Collaborator

Did some digging @filip26 . The specification cites RFC6234: US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF) but this is an open source implementation without advice on key lengths. FIPS PUB 198-1: The Keyed-Hash Message Authentication Code (HMAC) gives a nice description of the algorithm that can take any key size (in bytes), but doesn't give any advice. Finally there is RFC2104 HMAC: Keyed-Hashing for Message Authenticatio which does offer the following advice on HMAC key sizes:

The key for HMAC can be of any length (keys longer than B bytes are
first hashed using H). However, less than L bytes is strongly
discouraged as it would decrease the security strength of the
function. Keys longer than L bytes are acceptable but the extra
length would not significantly increase the function strength. (A
longer key may be advisable if the randomness of the key is
considered weak.)

We are using SHA-256 so L = 32 bytes (256 bits) and B = 64 bytes (512). Hence I would be inclined to cite RFC2104 and recommend a key size of 32 bytes.

@filip26
Copy link
Author

filip26 commented Feb 27, 2024

I've been looking for this, and I agree there is not much info around. MS (.NET) recommends 64 bytes but then they say if the key length is greater than 64 hash it to get 32.
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.hmacsha256.-ctor?view=net-8.0

there is also a post on crypto.stackexchange.com
https://crypto.stackexchange.com/questions/31473/what-size-should-the-hmac-key-be-with-sha-256

+1 to recommend hmac key size of 32 bytes

@msporny
Copy link
Member

msporny commented Apr 28, 2024

PR #60 has been merged to address this issue; closing.

@msporny msporny closed this as completed Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CR1 normative This item is a normative change. pr exists
Projects
None yet
Development

No branches or pull requests

3 participants