@@ -127,13 +127,18 @@ func doChallenge(g, gx, h, hx, gP, hP, N *big.Int, secParam uint) (*big.Int, err
127127 return nil , ErrSecParam
128128 }
129129
130+ err := checkBounds (N , g , gx , h , hx , gP , hP )
131+ if err != nil {
132+ return nil , err
133+ }
134+
130135 modulusLenBytes := (N .BitLen () + 7 ) / 8
131136 nBytes := make ([]byte , modulusLenBytes )
132137 cByteLen := (secParam + 7 ) / 8
133138 cBytes := make ([]byte , cByteLen )
134139
135140 H := sha3 .NewShake256 ()
136- _ , err : = H .Write (g .FillBytes (nBytes ))
141+ _ , err = H .Write (g .FillBytes (nBytes ))
137142 if err != nil {
138143 return nil , err
139144 }
@@ -171,5 +176,21 @@ func doChallenge(g, gx, h, hx, gP, hP, N *big.Int, secParam uint) (*big.Int, err
171176 return new (big.Int ).SetBytes (cBytes ), nil
172177}
173178
174- // ErrSecParam is returned when the security parameter is less than 128.
175- var ErrSecParam = errors .New ("zk/qndleq: the security parameter must be greater than 128" )
179+ // checkBounds returns nil if 0 < x[i] < N for all 0 <= i < len(x);
180+ // otherwise, returns ErrBounds.
181+ func checkBounds (N * big.Int , x ... * big.Int ) error {
182+ for _ , xi := range x {
183+ if ! (0 < xi .Sign () && xi .Cmp (N ) < 0 ) {
184+ return ErrBounds
185+ }
186+ }
187+
188+ return nil
189+ }
190+
191+ var (
192+ // ErrSecParam is returned when the security parameter is less than 128.
193+ ErrSecParam = errors .New ("zk/qndleq: the security parameter must be greater than 128" )
194+ // ErrBounds is returned when a value is not in the range 0 to N.
195+ ErrBounds = errors .New ("zk/qndleq: input must be greater than 0 and less than N" )
196+ )
0 commit comments