grafana/k6 · error
public exponent too small
Error message
public exponent too small
What it means
Thrown by crypto.subtle.generateKey for RSA algorithms when publicExponent is odd but smaller than 2. validatePublicExponent (internal/js/modules/k6/webcrypto/rsa.go:151) checks evenness first, then rejects e < 2 — an exponent of 1 (or a negative odd value) makes RSA signatures trivially forgeable and is refused before key generation.
Solutions
- Use the standard exponent 65537: new Uint8Array([0x01, 0x00, 0x01])
- Otherwise pick any odd value >= 3 (3 and 17 are the usual alternatives)
- Validate configured exponents against the same rule (odd, 2 <= e <= 2^31-1) before generateKey
Example fix
// before publicExponent: new Uint8Array([0x01]) // 1 — too small // after publicExponent: new Uint8Array([0x01, 0x00, 0x01]) // 65537
Defensive patterns
Strategy: validation
Validate before calling
const e = publicExponent.reduce((acc, b) => acc * 256 + b, 0);
if (e % 2 !== 0 && e < 2) {
throw new Error(`publicExponent ${e} is too small — use [0x01, 0x00, 0x01] (65537)`);
} Prevention
- Never ship an exponent default of 1 or 0 — initialize to [0x01, 0x00, 0x01]
- Validate decoded exponent bounds before generateKey
- Even and too-small exponents have distinct messages — read which one fired to locate the bad byte
When it happens
Trigger: Passing publicExponent: new Uint8Array([0x01]) or new Uint8Array([0x00, 0x01]) in the generateKey algorithm identifier. Even values like 0 hit the 'public exponent is even' sibling error instead.
Common situations: A default exponent constant initialized to 1 ('set later, never set'); trimming the exponent array to its last non-zero byte; test scripts that shrink the exponent 'to be fast'.
Related errors
- public exponent is even
- public exponent too large
- exponent (e) is required
- modulus (n) is required
- coordinate Y is required
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/8f38ef6dc1821ba6.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/rsa.go:151
if err != nil {
return nil, err
}
return &CryptoKeyPair{
PrivateKey: privateKey,
PublicKey: publicKey,
}, nil
}
// validatePublicExponent validates the public exponent.
// it's done same way how golang's rsa package does it + additional check for evenness.
func validatePublicExponent(e int) error {
if e%2 == 0 {
return errors.New("public exponent is even")
}
if e < 2 {
return errors.New("public exponent too small")
}
if e > 1<<31-1 {
return errors.New("public exponent too large")
}
return nil
}
func generateRSAKeyPair(
modulusLength int,
publicExponent int,
) (any, any, error) {
privateKey, err := rsa.GenerateKey(rand.Reader, modulusLength)
if err != nil {
return nil, nil, NewError(OperationError, "could not generate RSA key pair")
}
privateKey.E = publicExponentView on GitHub (pinned to 01ffac6f24)