1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 mp_err
mp_rand(mp_int
*a
, int digits
)
17 if ((err
= mp_grow(a
, digits
)) != MP_OKAY
) {
21 if ((err
= s_mp_rand_source(a
->dp
, (size_t)digits
* sizeof(mp_digit
))) != MP_OKAY
) {
25 /* TODO: We ensure that the highest digit is nonzero. Should this be removed? */
26 while ((a
->dp
[digits
- 1] & MP_MASK
) == 0u) {
27 if ((err
= s_mp_rand_source(a
->dp
+ digits
- 1, sizeof(mp_digit
))) != MP_OKAY
) {
33 for (i
= 0; i
< digits
; ++i
) {