Skip to content

fix: generate RFC-compliant TOTP codes - #410

Open
giri256 wants to merge 1 commit into
browserpass:masterfrom
giri256:fix/rfc-compliant-totp-secrets
Open

fix: generate RFC-compliant TOTP codes#410
giri256 wants to merge 1 commit into
browserpass:masterfrom
giri256:fix/rfc-compliant-totp-secrets

Conversation

@giri256

@giri256 giri256 commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #358

otplib 11 transforms TOTP secrets to the digest length before HMAC. For short seeds that repeats the decoded bytes, which produces a different key and therefore a different OTP than other RFC-compatible implementations.

This overrides the library's documented createHmacSecret hook so HMAC receives the decoded secret bytes unchanged and performs its normal RFC 2104 key handling.

I also added regression vectors for short SHA-1, SHA-256, and SHA-512 secrets, plus the standard 20-byte SHA-1 vector.

Verification:

  • yarn test
  • prettier --check package.json helpers/base.test.js
  • Browserify compilation of background.js

Signed-off-by: p1 <giridharpavan593@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Generates incorrect TOTP codes when using seed of less than 10 bytes

1 participant