mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Change the compiler's big integer library to use libTomMath
This now replaces Bill's crappy big int implementation
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef MP_RAND_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
mp_err mp_rand(mp_int *a, int digits)
|
||||
{
|
||||
int i;
|
||||
mp_err err;
|
||||
|
||||
mp_zero(a);
|
||||
|
||||
if (digits <= 0) {
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
if ((err = mp_grow(a, digits)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = s_mp_rand_source(a->dp, (size_t)digits * sizeof(mp_digit))) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* TODO: We ensure that the highest digit is nonzero. Should this be removed? */
|
||||
while ((a->dp[digits - 1] & MP_MASK) == 0u) {
|
||||
if ((err = s_mp_rand_source(a->dp + digits - 1, sizeof(mp_digit))) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
a->used = digits;
|
||||
for (i = 0; i < digits; ++i) {
|
||||
a->dp[i] &= MP_MASK;
|
||||
}
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user