slackhq/nebula · error

invalid integer

Error message

invalid integer

What it means

addASN1IntBytes in cert/p256/p256.go raises 'invalid integer' when asked to encode a big-endian integer whose bytes are all zero (empty after stripping leading zeros). DER integers must carry at least one significant byte, so the builder is put into an error state.

Source

Thrown at cert/p256/p256.go:118

}

func encodeSignature(r, s []byte) ([]byte, error) {
	var b cryptobyte.Builder
	b.AddASN1(asn1.SEQUENCE, func(b *cryptobyte.Builder) {
		addASN1IntBytes(b, r)
		addASN1IntBytes(b, s)
	})
	return b.Bytes()
}

// addASN1IntBytes encodes in ASN.1 a positive integer represented as
// a big-endian byte slice with zero or more leading zeroes.
func addASN1IntBytes(b *cryptobyte.Builder, bytes []byte) {
	for len(bytes) > 0 && bytes[0] == 0 {
		bytes = bytes[1:]
	}
	if len(bytes) == 0 {
		b.SetError(errors.New("invalid integer"))
		return
	}
	b.AddASN1(asn1.INTEGER, func(c *cryptobyte.Builder) {
		if bytes[0]&0x80 != 0 {
			c.AddUint8(0)
		}
		c.AddBytes(bytes)
	})
}

View on GitHub (pinned to dd8f660c0a)

Solutions

  1. Check the signing key is valid and non-zero before signing — a zero r or s indicates a broken scalar
  2. Reject or re-request signatures containing all-zero components at the decoding boundary
  3. Validate signature bytes (non-zero r and s) before attempting to re-encode them

Example fix

// before
sig, _ := encodeSignature(zeroR, s) // r all zeroes
// after
if isAllZero(r) || isAllZero(s) {
    return nil, fmt.Errorf("invalid signature component")
}
sig, err := encodeSignature(r, s)
Defensive patterns

Strategy: validation

Validate before calling

func isAllZero(b []byte) bool {
    for _, x := range b { if x != 0 { return false } }
    return true
}
// reject if isAllZero(r) || isAllZero(s)

Type guard

func hasNonZeroComponents(r, s []byte) bool {
    return !(isAllZero(r) || isAllZero(s))
}

Try / catch

sig, err := encodeSignature(r, s)
if err != nil && err.Error() == "invalid integer" {
    // zero component: signature or key is invalid
}

Prevention

When it happens

Trigger: Encoding a signature component (r or s) that is entirely zero — all-zero byte slices passed to encodeSignature via addASN1IntBytes.

Common situations: A signing operation that produced a zero component due to a bad or zero private key; corrupted/zeroed signature bytes parsed from storage or the wire; test fixtures containing empty scalar values.

Related errors


AI-assisted analysis of slackhq/nebula@dd8f660c0a (2026-09-03). Data as JSON: /api/errors/e9b7162209b1d02a. Report an issue: GitHub.