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 __MPARRAY_H__
10 #define __MPARRAY_H__
11 
12 #include <mpi.h>
13 #include <mprio.h>
14 
15 struct mparray
16 {
17   int len;
18   mp_int* data;
19 };
20 
21 typedef struct mparray* MPArray;
22 typedef const struct mparray* const_MPArray;
23 
24 /*
25  * Initialize an array of `mp_int`s of the given length.
26  */
27 MPArray MPArray_new(int len);
28 void MPArray_clear(MPArray arr);
29 
30 /*
31  * Copies secret sharing of data from src into arrays
32  * arrA and arrB. The lengths of the three input arrays
33  * must be identical.
34  */
35 SECStatus MPArray_set_share(MPArray arrA, MPArray arrB, const_MPArray src,
36                             const_PrioConfig cfg);
37 
38 /*
39  * Initializes array with 0/1 values specified in boolean array `data_in`
40  */
41 MPArray MPArray_new_bool(int len, const bool* data_in);
42 
43 /*
44  * Expands or shrinks the MPArray to the desired size. If shrinking,
45  * will clear the values on the end of array.
46  */
47 SECStatus MPArray_resize(MPArray arr, int newlen);
48 
49 /*
50  * Initializes dst and creates a duplicate of the array in src.
51  */
52 MPArray MPArray_dup(const_MPArray src);
53 
54 /*
55  * Copies array from src to dst. Arrays must have the same length.
56  */
57 SECStatus MPArray_copy(MPArray dst, const_MPArray src);
58 
59 /* For each index i into the array, set:
60  *    dst[i] = dst[i] + to_add[i]   (modulo mod)
61  */
62 SECStatus MPArray_addmod(MPArray dst, const_MPArray to_add, const mp_int* mod);
63 
64 /*
65  * Return true iff the two arrays are equal in length
66  * and contents. This comparison is NOT constant time.
67  */
68 bool MPArray_areEqual(const_MPArray arr1, const_MPArray arr2);
69 
70 #endif /* __MPARRAY_H__ */
71