First part: RSA CRT versus RSA std.
[crypto_lab3.git] / src / Rand.h
1 #ifndef RAND_H
2 #define RAND_H
3
4 #include <gmpxx.h>
5
6 /**
7 * All random functions uses "/dev/urandom".
8 */
9 class Rand
10 {
11 public:
12 /**
13 * Returns a random number with a maximum size of 'sizeBits'.
14 * If 'forceSize' is true the size is exactly 'sizeBits', so the highest bit will always be 1.
15 *
16 * For example, for 'sizeBits' = 12 and 'forceSize' = true, the returned number will be in the following range:
17 * [2^11, 2^12-1]
18 *
19 * For 'sizeBits' = 12 and 'forceSize' = false, the returned number will be in the following range:
20 * [0, 2^12-1]
21 */
22 static mpz_class randSize(int sizeBits, bool forceSize = true);
23
24 /**
25 * Return a random number n such as:
26 * 'from' <= n <= 'to'
27 */
28 static mpz_class randLimits(const mpz_class& from, const mpz_class& to);
29
30 static mpz_class randPrime(const int size_bits);
31
32 private:
33 /**
34 * Read a rand from "/dev/urandom" of size 'size' in byte to the given array 'to'.
35 */
36 static void readRand(char* to, int size);
37 };
38
39 #endif