Skip to content

🔒️ Add SASL::ScramCache for salted SCRAM keys#645

Open
nevans wants to merge 4 commits intomasterfrom
scram-cache
Open

🔒️ Add SASL::ScramCache for salted SCRAM keys#645
nevans wants to merge 4 commits intomasterfrom
scram-cache

Conversation

@nevans
Copy link
Copy Markdown
Collaborator

@nevans nevans commented Apr 19, 2026

Adds SASL::ScramCache, a SASL::ScramAuthenticator#cache attr, and a cache keyword parameter to SASL::ScramAuthenticator#initialize.

This avoids expensive re-hashing that was done during a single authentication exchange. It can also be re-used across multiple authentication exchanges.

When the cache kwarg contains the client and server keys (or the salted password), password is optional. But authentication will fail if salt or iterations change and password hasn't been provided.

nevans added 2 commits April 17, 2026 11:26
`SASL::ScramAlgorithm` and `SASL::ScramAuthenticator` use
`salted_password` _at least_ twice: once to compute `client_key` and
once to compute `server_key`.  It is actually used more than that, since
`client_key` and `server_key` are also used multiple times each.
Computing `salted_password` is _intentionally_ computationally
expensive, so it should be cached.

Although `client_key` and `server_key` are far less computationally
expensive, they _are_ used multiple times, so they are memoized too.

Ultimately, we _could_ memoize most of the methods in `ScramAlgorithm`,
but I've decided to keep it simple by only memoizing these three.
nevans added 2 commits April 19, 2026 07:21
Adds `SASL::ScramCache`, a `SASL::ScramAuthenticator#cache` attr, and a
`cache` keyword parameter to `SASL::ScramAuthenticator#initialize`.

This avoids expensive re-hashing that was done during a single
authentication exchange, but can also be re-used across multiple
authentication exchanges.
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