Skip to content

Commit

Permalink
UPDATED: Change range of random numbers -- see discussion (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcher committed Jul 29, 2017
1 parent f28caa2 commit 4aa47a1
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/shamir.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ void seed_random(void) {
srand(seed);
}

int nonzero_random(int modulo) {
int range = modulo - 1;
/*-- use arc4random if available */
#if defined (HAVE_ARC4RANDOM)
return arc4random_uniform(range) + 1;
#else
return rand() % range + 1;
#endif
}

/*
from http://stackoverflow.com/questions/18730071/c-programming-to-calculate-using-modular-exponentiation
Expand Down Expand Up @@ -135,8 +126,12 @@ int * split_number(int number, int n, int t) {

for (i = 1; i < t; ++i)
{
/* prevent degraded polynomials by using non-zero random coefficients */
coef[i] = nonzero_random(prime - 1);
/* Generate random coefficients -- use arc4random if available */
#ifdef HAVE_ARC4RANDOM
coef[i] = arc4random_uniform(prime);
#else
coef[i] = rand() % (prime);
#endif
}

for (x = 0; x < n; ++x)
Expand Down

0 comments on commit 4aa47a1

Please sign in to comment.