OpenNHP/opennhp · error

random number is zero

Error message

random number is zero

What it means

Guard in the shared helper GenerateRandomNumber: crypto/rand.Int returned successfully but produced the value 0, which is unusable as a secret scalar or nonce (it would yield degenerate keys and invalid signatures). The helper rejects it so callers (master key, partial key, and signature-nonce generation) never proceed with a zero scalar.

Solutions

  1. Simply call GenerateRandomNumber again — drawing 0 has probability ~1/N and will not repeat
  2. If observed more than once, audit the platform's crypto/rand/entropy supply
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at endpoints/kgc/utils.go:18 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/6596a1cc66aea783. Report an issue: GitHub.

Appendix: source

Thrown at endpoints/kgc/utils.go:18

package kgc

import (
	"crypto/rand"
	"fmt"
	"math/big"
	"os"
	"path/filepath"
)

func GenerateRandomNumber(N *big.Int) (*big.Int, error) {
	r, err := rand.Int(rand.Reader, N)
	if err != nil {
		return nil, err
	}

	if r.Cmp(big.NewInt(0)) == 0 {
		return nil, fmt.Errorf("random number is zero")
	}

	return r, nil
}

func GetExeDirPath() (string, error) {
	exeFilePath, err := os.Executable()
	if err != nil {
		return "", err
	}

	return filepath.Dir(exeFilePath), nil
}

View on GitHub (pinned to 6e04ca5ff0)