File: randommod.c

package info (click to toggle)
tlswrapper 0~20241101-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,796 kB
  • sloc: ansic: 7,099; sh: 2,342; makefile: 234
file content (17 lines) | stat: -rw-r--r-- 452 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* taken from public-domain nacl-20110221, from curvecp/randommod.c */
#include "randombytes.h"
#include "randommod.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;
}