diff options
Diffstat (limited to 'nacl/curvecp/randommod.c')
-rw-r--r-- | nacl/curvecp/randommod.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/nacl/curvecp/randommod.c b/nacl/curvecp/randommod.c new file mode 100644 index 00000000..575a627b --- /dev/null +++ b/nacl/curvecp/randommod.c | |||
@@ -0,0 +1,14 @@ | |||
1 | #include "randombytes.h" | ||
2 | |||
3 | /* XXX: current implementation is limited to n<2^55 */ | ||
4 | |||
5 | long long randommod(long long n) | ||
6 | { | ||
7 | long long result = 0; | ||
8 | long long j; | ||
9 | unsigned char r[32]; | ||
10 | if (n <= 1) return 0; | ||
11 | randombytes(r,32); | ||
12 | for (j = 0;j < 32;++j) result = (result * 256 + (unsigned long long) r[j]) % n; | ||
13 | return result; | ||
14 | } | ||