{"record":{"id":"6596a1cc66aea783","repo":"OpenNHP/opennhp","slug":"random-number-is-zero","errorCode":null,"errorMessage":"random number is zero","messagePattern":"random number is zero","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/kgc/utils.go","lineNumber":18,"sourceCode":"package kgc\n\nimport (\n\t\"crypto/rand\"\n\t\"fmt\"\n\t\"math/big\"\n\t\"os\"\n\t\"path/filepath\"\n)\n\nfunc GenerateRandomNumber(N *big.Int) (*big.Int, error) {\n\tr, err := rand.Int(rand.Reader, N)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif r.Cmp(big.NewInt(0)) == 0 {\n\t\treturn nil, fmt.Errorf(\"random number is zero\")\n\t}\n\n\treturn r, nil\n}\n\nfunc GetExeDirPath() (string, error) {\n\texeFilePath, err := os.Executable()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn filepath.Dir(exeFilePath), nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/kgc/utils.go#L1-L32","documentation":"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.","triggerScenarios":"Thrown at endpoints/kgc/utils.go:18 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Simply call GenerateRandomNumber again — drawing 0 has probability ~1/N and will not repeat","If observed more than once, audit the platform's crypto/rand/entropy supply"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}