package main import ( "crypto/rand" "encoding/hex" "fmt" "math/big" ) var order, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16) func valid(b []byte) bool { return len(b) == 32 && new(big.Int).SetBytes(b).Sign() > 0 && new(big.Int).SetBytes(b).Cmp(order) < 0 } func generate() ([]byte, error) { n, e := rand.Int(rand.Reader, new(big.Int).Sub(order, big.NewInt(1))) if e != nil { return nil, e } return n.Add(n, big.NewInt(1)).FillBytes(make([]byte, 32)), nil } func main() { b, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000001") fmt.Println(valid(b)) }