Skip to content

Commit

Permalink
explain
Browse files Browse the repository at this point in the history
  • Loading branch information
mj850 committed Nov 27, 2024
1 parent 756335b commit e864733
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/zkproofs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/coinbase/kryptology/pkg/core/curves"
)

// Generates a non-zero random scalar. The chances of generating a zero scalar are very low.
func GenerateRandomScalar(curve *curves.Curve) (curves.Scalar, error) {
attempts := 0
scalar := curve.Scalar.Random(rand.Reader)
// Try 5 times to generate a non zero scalar. The chance that this fails with a normal random number generator is impossibly low.
for scalar.IsZero() && attempts < 5 {
curve.Scalar.Random(rand.Reader)
attempts += 1
Expand Down

0 comments on commit e864733

Please sign in to comment.