Skip to content

fix(hmac): use block size for default key length - #343

Open
harrshita123 wants to merge 1 commit into
google:masterfrom
harrshita123:agent/fix-hmac-default-key-length
Open

fix(hmac): use block size for default key length#343
harrshita123 wants to merge 1 commit into
google:masterfrom
harrshita123:agent/fix-hmac-default-key-length

Conversation

@harrshita123

Copy link
Copy Markdown
Contributor

Summary

  • use each hash function's block size as the default native HMAC key length
  • remove stale backend adapter defaults so omitted lengths remain consistent
  • document the default lengths and add regression coverage for every supported hash

Root cause

The FFI backend used EVP_MD_size when length was omitted. That function returns the digest size, while Web Crypto defines the default HMAC key length as the hash function's block size. This made native-generated keys shorter than browser-generated keys.

Explicitly supplied key lengths continue to take precedence.

Validation

  • dart format --output none --set-exit-if-changed .
  • dart analyze --fatal-warnings .
  • dart test test/hmac_default_key_length_test.dart -p vm
  • dart test test/hmac_default_key_length_test.dart -p chrome -c dart2js,dart2wasm
  • dart test --exclude-tags browser-interop -p vm

Closes #342

@harrshita123
harrshita123 marked this pull request as ready for review July 25, 2026 11:52
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.

bug: native HMAC generation uses digest size instead of hash block size by default

1 participant