1 /*
2  * Copyright (c) 2018, Henry Corrigan-Gibbs
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 #ifndef __PRG_H__
10 #define __PRG_H__
11 
12 #include <blapit.h>
13 #include <mpi.h>
14 #include <stdlib.h>
15 
16 #include "config.h"
17 
18 typedef struct prg* PRG;
19 typedef const struct prg* const_PRG;
20 
21 /*
22  * Initialize or destroy a pseudo-random generator.
23  */
24 PRG PRG_new(const PrioPRGSeed key);
25 void PRG_clear(PRG prg);
26 
27 /*
28  * Produce the next bytes of output from the PRG.
29  */
30 SECStatus PRG_get_bytes(PRG prg, unsigned char* bytes, size_t len);
31 
32 /*
33  * Use the PRG output to sample a big integer x in the range
34  *    0 <= x < max.
35  */
36 SECStatus PRG_get_int(PRG prg, mp_int* out, const mp_int* max);
37 
38 /*
39  * Use the PRG output to sample a big integer x in the range
40  *    lower <= x < max.
41  */
42 SECStatus PRG_get_int_range(PRG prg, mp_int* out, const mp_int* lower,
43                             const mp_int* max);
44 
45 /*
46  * Use secret sharing to split the int src into two shares.
47  * Use PRG to generate the value `shareB`.
48  * The mp_ints must be initialized.
49  */
50 SECStatus PRG_share_int(PRG prg, mp_int* shareA, const mp_int* src,
51                         const_PrioConfig cfg);
52 
53 /*
54  * Set each item in the array to a pseudorandom value in the range
55  * [0, mod), where the values are generated using the PRG.
56  */
57 SECStatus PRG_get_array(PRG prg, MPArray arr, const mp_int* mod);
58 
59 /*
60  * Secret shares the array in `src` into `arrA` using randomness
61  * provided by `prgB`. The arrays `src` and `arrA` must be the same
62  * length.
63  */
64 SECStatus PRG_share_array(PRG prgB, MPArray arrA, const_MPArray src,
65                           const_PrioConfig cfg);
66 
67 #endif /* __PRG_H__ */
68