Skip to content

Impossible to use HMAC-SHA-256/512 with non 32 bytes keys #165

@gdwrd

Description

@gdwrd

Hi, here is libsodium issue, we need to fix this too.

This causes incompatibility with other implementations. For HMAC-SHA-256, it is possible to work around by padding or hashing keys beforehand. But this is not possible for HMAC-SHA-512, because crypto_auth_hmacsha512 does not accept 64-byte keys (crypto_auth_hmacsha512_KEYBYTES is hardcoded to 32).

Short keys should be first padded and long keys should be first hashed with the underlying hash function.

RFC: https://tools.ietf.org/html/rfc2104#section-3
Test Vectors: https://tools.ietf.org/html/rfc4231#section-4.3

HMAC-SHA-512 should certainly allow 64-byte keys because "the minimal recommended length for K is L bytes" where L is the output length. -- https://tools.ietf.org/html/rfc2104#section-2

I will add PR with changes soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions