mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-09 07:23:56 +08:00
Update rand_range functions
`rand_range` will stop and return 0 if the `range` is too small. Caller can call it again or stop. `rand_range` return -1 only if RNG failure.
This commit is contained in:
@@ -80,12 +80,21 @@ void sm2_z256_set_zero(uint64_t a[4])
|
||||
|
||||
int sm2_z256_rand_range(uint64_t r[4], const uint64_t range[4])
|
||||
{
|
||||
unsigned int max_tries = 100;
|
||||
|
||||
do {
|
||||
if (!max_tries) {
|
||||
// caller call this function again if return zero
|
||||
return 0;
|
||||
}
|
||||
if (rand_bytes((uint8_t *)r, 32) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
max_tries--;
|
||||
|
||||
} while (sm2_z256_cmp(r, range) >= 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user