Skip to content

auth: reuse the keyed HMAC context for HS256 session tokens - #1167

Open
dormancygrace wants to merge 1 commit into
mainfrom
codex/jwt-hmac-context
Open

dormancygrace wants to merge 1 commit into
mainfrom
codex/jwt-hmac-context

Conversation

@dormancygrace

Copy link
Copy Markdown
Owner

Reuse one keyed OpenSSL HMAC-SHA256 context per server thread. Each JWT still gets its own signature calculation, constant-time tag comparison, claim checks and session validation. The signing key is loaded once at server startup. A MAC failure discards the context and ends the request without issuing a token.

Verification

  • Passed the host authentication suite and cross-compiled the login and password-change routes.
  • On a NanoKVM Cube, four concurrent readers verified 32 tokens generated by the other build in each direction and rejected altered tags.

Eight alternating pairs on SG2002, same OpenSSL 3.5.10 for both executables. Median CPU time through the server's request authentication and account/session checks went from 169.6 to 116.3 µs for Bearer and from 187.0 to 133.2 µs for a cookie. Both improved in all eight pairs. These timings exclude socket I/O, TLS and the route handler.

This branch has not been deployed

No deployments
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.

1 participant