- 8CE351DC40192AE3425D230BE59B8B487B9A206D2AE0747F87B09E00CCDF14898876877C68A6EA9E2C382B90220401B1EC4925F59906E77895C4A499827751F1
+ DAB95B2F666390284B7BA75171F6836E16847E0B910755599C439F5792E1CDF83CA43C198D03A19491FAF213313D34635C373BFC13A97ED432C1CA4FAAEFDF18
eucrypt/smg_rsa/include/smg_rsa.h
(8 . 6)(8 . 12)
15 #include "mpi.h"
16 #include "knobs.h"
17
18 /* A way to determine endianness at runtime.
19 * Required for diddling a float's mantissa for instance.
20 */
21 static const int onect = 1;
22 #define is_bigendian() ( (*(char*)&onect) == 0 )
23
24 /*
25 * These are constants as per TMSR RSA specification, NOT knobs!
26 * TMSR key length is 4096 bits (512 octets); this means 2 primes of 2048 bits (256 octets) each.
(82 . 6)(88 . 73)
28 */
29 int get_random_octets_from(int noctets, unsigned char *out, int from);
30
31 /* Returns (in parameter *n) a *potentially biased* random float between 0 and 1
32 * Uses bits from ENTROPY_SOURCE but it rounds when converting to float
33 * NB: This function rounds impredictably.
34 Use it ONLY if LSB normalization is insignificant to you!
35 * This function uses rng_uint64 below.
36 *
37 * @param n - a float value (LSB rounded) between 0 and 1, obtained using
38 * a 64-bit random integer (64 bits from ENTROPY_SOURCE)
39 * @return - a positive value on success and a negative value in case of error
40 * main possible cause for error: failure to open ENTROPY_SOURCE.
41 * NB: a non-responsive/malconfigured source can result in blocking
42 */
43 int rng_dirty_float(float *n);
44
45
46 /* Returns (in parameter *n) a randomly generated float between 1 and 2 using:
47 * - the IEEE 754/1985 format for single float representation
48 * - ENTROPY_SOURCE to obtain bits that are *directly* used as mantissa
49 * NB: this value is between 1 and 2 due to the normalised format that includes
50 * an implicit 1 ( i.e. value is (-1)^sign * 2^(e-127) * (1.mantissa) )
51 *
52 * From IEEE 754/1985, a description of the single float format:
53 * msb means most significant bit
54 * lsb means least significant bit
55 * 1 8 23 ... widths
56 * +-+-------+-----------------------+
57 * |s| e | f |
58 * +-+-------+-----------------------+
59 * msb lsb msb lsb ... order
60
61 * A 32-bit single format number X is divided as shown in the figure above. The
62 * value v of X is inferred from its constituent fields thus:
63 * 1. If e = 255 and f != 0 , then v is NaN regardless of s
64 * 2. If e = 255 and f = 0 , then v = (-1)^s INFINITY
65 * 3. If 0 < e < 255 , then v = (-1)^s * 2^(e-127) * ( 1.f )
66 * 4. If e = 0 and f != 0 , then v = (-1)^s * 2^(-126) * ( 0.f ) (denormalized
67 * numbers)
68 * 5. If e = 0 and f = 0 , then v = ( -1 )^s * 0 (zero)
69 *
70 * @param n - the address of an IEEE 754/1985 float: its mantissa will be set to
71 * random bits obtained from ENTROPY_SOURCE; its sign will be set
72 * to 0; its exponent will be set to 127 (the bias value so
73 * that the actual exponent is 0).
74 * @return - a positive value on success and a negative value in case of error
75 * main possible cause for error: failure to open ENTROPY_SOURCE.
76 * NB: a non-responsive/malconfigured source can result in blocking
77 */
78 int rng_float_754_1985(float *n);
79
80 /* Returns (in parameter *n) a random unsigned integer value on 32 bits.
81 * Uses random bits from ENTROPY_SOURCE that are directly interpreted as int
82 *
83 * @param n - it will contain the random integer obtained by interpreting 32
84 * bits from ENTROPY_SOURCE as an unsigned int value on 32 bits.
85 * @return - a positive value on success and a negative value in case of error
86 */
87 int rng_uint32( uint32_t *n );
88
89 /* Returns (in parameter *n) a random unsigned integer value on 64 bits.
90 * Uses random bits from ENTROPY_SOURCE that are directly interpreted as int
91 *
92 * @param n - it will contain the random integer obtained by interpreting 64
93 * bits from ENTROPY_SOURCE as an unsigned int value on 64 bits.
94 * @return - a positive value on success and a negative value in case of error
95 */
96 int rng_uint64( uint64_t *n );
97
98 /*********primegen.c*********/
99
100 /*