-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmodulus.h
52 lines (40 loc) · 1.49 KB
/
modulus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
/**
@file modulus.h
*/
#pragma once
#include <stdbool.h>
#include <stdint.h> // uint64_t
#include "defines.h"
/**
Struct to store a modulus. 'const_ratio' can be precomputed and used later for faster modular
reduction in some cases.
@param value Value of the modulus (aka 'q')
@param const_ratio floor(2^64/q)
*/
typedef struct Modulus
{
ZZ value; // Value of the modulus (aka 'q')
// -- Note: SEAL const_ratio is size 3 to store the remainder,
// but we don't need the remainder so we can use a size 2 array
ZZ const_ratio[2]; // floor(2^64/q)
} Modulus;
/**
Sets up the modulus object for a particular modulus value. Useful for setting up a modulus if
const_ratio for modulus value has not been pre-computed by set_modulus' table.
@param[in] q Modulus value
@param[in] hw High word of const_ratio for 'q'
@param[in] lw Low word of const_ratio for 'q'
@param[out] mod Modulus object to set
*/
void set_modulus_custom(const ZZ q, ZZ hw, ZZ lw, Modulus *mod);
/**
Sets up the modulus object for a particular modulus value. Implements const_ratio set as a table
lookup. If table does not contain const_ratio for the requested modulus value, returns a failure. In
this case, set_modulus_custom should be used instead.
@param[in] q Modulus value
@param[out] mod Modulus object to set
@returns 1 on success, 0 on failure
*/
bool set_modulus(const ZZ q, Modulus *mod);