Skip to content

Commit

Permalink
Merge pull request #357 from skids/rand
Browse files Browse the repository at this point in the history
Workaround tommath issue #56, affects random bigint numbers > 32bits
  • Loading branch information
FROGGS committed Oct 16, 2016
2 parents 80aa6f7 + d60390f commit 3f1ef57
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/math/bigintops.c
Expand Up @@ -893,8 +893,18 @@ void MVM_bigint_rand(MVMThreadContext *tc, MVMObject *a, MVMObject *b) {
mp_int *rnd = MVM_malloc(sizeof(mp_int));
mp_int *max = force_bigint(bb, tmp);

/* Workaround tommath issue #56 */
mp_int workaround;
mp_init (&workaround);
mp_rand(&workaround, USED(max) + 1);
mp_mul_2d(&workaround, 29, &workaround);

mp_init(rnd);
mp_rand(rnd, USED(max) + 1);

mp_xor(rnd, &workaround, rnd);
mp_clear(&workaround);

mp_mod(rnd, max, rnd);
store_bigint_result(ba, rnd);
clear_temp_bigints(tmp, 1);
Expand Down

0 comments on commit 3f1ef57

Please sign in to comment.