commit
784077d380
@ -29,7 +29,7 @@ mp_rand (mp_int * a, int digits)
|
|||||||
|
|
||||||
/* first place a random non-zero digit */
|
/* first place a random non-zero digit */
|
||||||
do {
|
do {
|
||||||
d = ((mp_digit) abs (rand ())) & MP_MASK;
|
d = ((mp_digit) abs (MP_GEN_RANDOM())) & MP_MASK;
|
||||||
} while (d == 0);
|
} while (d == 0);
|
||||||
|
|
||||||
if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
|
if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
|
||||||
@ -41,7 +41,7 @@ mp_rand (mp_int * a, int digits)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = mp_add_d (a, ((mp_digit) abs (rand ())), a)) != MP_OKAY) {
|
if ((res = mp_add_d (a, ((mp_digit) abs (MP_GEN_RANDOM())), a)) != MP_OKAY) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
tommath.h
11
tommath.h
@ -138,6 +138,17 @@ extern "C" {
|
|||||||
typedef mp_digit mp_min_u32;
|
typedef mp_digit mp_min_u32;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* platforms that can use a better rand function */
|
||||||
|
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
||||||
|
#define MP_USE_ALT_RAND 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* use arc4random on platforms that support it */
|
||||||
|
#ifdef MP_USE_ALT_RAND
|
||||||
|
#define MP_GEN_RANDOM() arc4random()
|
||||||
|
#else
|
||||||
|
#define MP_GEN_RANDOM() rand()
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MP_DIGIT_BIT DIGIT_BIT
|
#define MP_DIGIT_BIT DIGIT_BIT
|
||||||
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
|
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
|
||||||
|
Loading…
Reference in New Issue
Block a user