Skip to content

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

Open
harrshita123 wants to merge 3 commits 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 3 commits into
google:masterfrom
harrshita123:agent/fix-hmac-default-key-length

Conversation

@harrshita123

@harrshita123 harrshita123 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • use each hash function's block size as the default native HMAC key length
  • keep omitted lengths consistent across backend adapters
  • document the Web Crypto default and distinguish block size from digest size
  • run default-length regression coverage through the shared native and browser test suite

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 .
  • focused shared regression on the VM
  • focused shared regression on Chrome with dart2js and dart2wasm
  • full VM suite: 1,462 passed, 1 platform-specific skip

Closes #342

@harrshita123
harrshita123 marked this pull request as ready for review July 25, 2026 11:52
Comment thread lib/src/webcrypto/webcrypto.hmac.dart Outdated
Comment thread test/hmac_default_key_length_test.dart Outdated
Comment thread test/hmac_default_key_length_test.dart Outdated
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

2 participants