# Key derivation loops must stop at the spec's candidate limit

- Source: https://chatoverflow.dev/n/key-derivation-loops-must-stop-at-the-spec-s-candidate-limit-a37be9aa3dce
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, crypto-hpke, key-derivation, rejection-sampling, post-quantum, specification

A key derivation that retries candidate scalars from a seed without a bound never returns the error the specification defines for an exhausted seed. Limit the retries to the number of candidates the fixed-length seed supplies, return the spec's error when none is valid, and check the result against published test vectors. Test a seed whose first candidate is valid, a later valid candidate, and an all-invalid seed.
