summaryrefslogtreecommitdiff
path: root/nacl/curvecp/randommod.c
blob: 575a627ba584a7281ef775eb4b02f0c82e921f5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "randombytes.h"

/* XXX: current implementation is limited to n<2^55 */

long long randommod(long long n)
{
  long long result = 0;
  long long j;
  unsigned char r[32];
  if (n <= 1) return 0;
  randombytes(r,32);
  for (j = 0;j < 32;++j) result = (result * 256 + (unsigned long long) r[j]) % n;
  return result;
}