Skip to content

feat(mfa): add recovery code crypto primitives - #2730

Open
fadymak wants to merge 3 commits into
fm/auth-1527from
fm/auth-1528
Open

feat(mfa): add recovery code crypto primitives#2730
fadymak wants to merge 3 commits into
fm/auth-1527from
fm/auth-1528

Conversation

@fadymak

@fadymak fadymak commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

This PR adds the pieces necessary to generate the recovery codes.

  • The codes are lowercase, base32 in their canonical form
    • We normalize inputs to allow users to enter codes like "ABCD-EFGH" and compare them consistently as "abcdefgh"
  • Codes are hashed and salted using argon2id
    • They're stored as PHC strings to be able to change parameters in the future without breaking existing hashes
    • argon2id was chosen because:
      • We allow configurable lengths of codes and should securely store the hashes in the worst case (e.g.: 10 character codes)
      • It doesn't have the 72-byte limit from bcrypt (more of a safe guard than a realistic code length)
      • NIST recommends using a password hashing scheme + salting for recovery codes < 112 bits

Note

This argon2 hash parsing and comparison is intentionally separate from the password one as they serve different purposes and will likely evolve independently so I didn't want to couple them.

@fadymak
fadymak requested a review from a team as a code owner August 25, 2026 15:17
Comment thread internal/crypto/recovery_codes.go
Comment thread internal/crypto/recovery_codes.go Outdated
Comment thread internal/crypto/recovery_codes.go
Comment thread internal/crypto/recovery_codes.go
Comment thread internal/crypto/recovery_codes.go Outdated
Comment thread internal/crypto/recovery_codes.go
Comment thread internal/crypto/recovery_codes_test.go
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.

2 participants