-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathckks_tests_common.h
148 lines (120 loc) · 6.39 KB
/
ckks_tests_common.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
/**
@file ckks_tests_common.h
*/
#pragma once
#include <complex.h>
#include "defines.h"
#include "parameters.h"
#include "test_common.h"
/**
Sets the values of 'v' according to the particular test number.
If testnum > 8, will set testnum to 8.
@param[in] testnum Test number in range [0,9]
@param[in] vlen Number of flpt elements in v
@param[out] v Array to set
*/
void set_encode_encrypt_test(size_t testnum, size_t vlen, flpt *v);
/**
(Pseudo) ckks decode. 'values_decoded' and 'pt' may share the same starting address for in-place
computation (see: ckks_decode_inpl)
Note: index_map is non-const in case SE_INDEX_MAP_LOAD is defined (or, if
SE_INDEX_MAP_LOAD_PERSIST_SYM_LOAD_ASYM is defined and asymmetric encryption is used).
Size req: 'temp' must contain space for n double complex values
'values_decoded' must contain space for n/2 flpt elements.
If index map needs to be loaded (see 'Note' above), index_map must constain space for n uint16_t
elements.
@param[in] pt Plaintext to decode
@param[in] values_len True number of entries in initial values message. Must be <= n/2
@param[in] index_map [Optional]. If passed in, can avoid 1 flash read
@param[in] parms Parameters set by ckks_setup
@param temp Scratch space
@param[out] values_decoded Decoded message
*/
void ckks_decode(const ZZ *pt, size_t values_len, uint16_t *index_map, const Parms *parms,
double complex *temp, flpt *values_decoded);
/**
(Pseudo) in-place ckks decode.
Note: index_map is non-const in case SE_INDEX_MAP_LOAD is defined (or, if
SE_INDEX_MAP_LOAD_PERSIST_SYM_LOAD_ASYM is defined and asymmetric encryption is used).
Size req: 'temp' must contain space for n double complex values
'values_decoded' must contain space for n/2 flpt elements
If index map needs to be loaded (see 'Note' above), index_map must constain space for n uint16_t
elements.
@param[in,out] pt In: Plaintext to decode; Out: Decoded message
@param[in] values_len True number of entries in initial values message. Must be <= n/2
@param[in] index_map [Optional]. If passed in, can avoid 1 flash read
@param[in] parms Parameters set by ckks_setup
@param temp Scratch space
*/
static inline void ckks_decode_inpl(ZZ *pt, size_t values_len, uint16_t *index_map,
const Parms *parms, double complex *temp)
{
ckks_decode(pt, values_len, index_map, parms, temp, (flpt *)pt);
}
/**
Checks that the pseudo-decoding of a ciphertext is correct.
Note: index_map is non-const in case SE_INDEX_MAP_LOAD is defined (or, if
SE_INDEX_MAP_LOAD_PERSIST_SYM_LOAD_ASYM is defined and asymmetric encryption is used).
Size req: 'temp' must contain space for n double complex values
If index map needs to be loaded (see 'Note' above), index_map must constain space for n uint16_t
elements.
@param[in,out] pt In: Plaintext to decode; Out: Decoded message
@param[in] values Cleartext input message
@param[in] values_len True number of entries in initial values message. Must be <= n/2
@param[in] index_map [Optional]. If passed in, can avoid 1 flash read
@param[in] parms Parameters instance
@param temp Scratch space
*/
void check_decode_inpl(ZZ *pt, const flpt *values, size_t values_len, uint16_t *index_map,
const Parms *parms, ZZ *temp);
/**
Pseudo-decrypts a ciphertext in place (for a particular prime component). Currently only works if
'small_s' is 0. 'c0' and 'pt' may share the same starting address for in-place computation (see:
ckks_decrypt_inpl).
Size req: 'pt' must have space for n elements
@param[in] c0 1st ciphertext component for this prime
@param[in] c1 2nd ciphertext component for this prime
@param[in] s Secret key. Must be in expanded form!
@param[in] small_s If true, secret key is in small form; Else, is in expanded form
@param[in] parms Parameters instance
@param[out] pt Decypted result (a ckks plaintext)
*/
void ckks_decrypt(const ZZ *c0, const ZZ *c1, const ZZ *s, bool small_s, const Parms *parms,
ZZ *pt);
/**
Pseudo-decrypts a ciphertext in place (for a particular prime component). Currently only works if
small_s is 0. Note that this function will also corrupt the memory pointed to by c1.
@param[in,out] c0 In: First ciphertext component for this prime;
Out: Decrypted result (a CKKS plaintext)
@param[in] c1 Second ciphertext component for this prime. Will be corrupted
@param[in] s Secret key. Must be in expanded form!
@param[in] small_s If true, secret key is in small form; Else, is in expanded form
@param[in] parms Parameters instance
*/
void ckks_decrypt_inpl(ZZ *c0, ZZ *c1, const ZZ *s, bool small_s, const Parms *parms);
/**
Checks that the pseudo-decoding and pseudo-decryption of a ciphertext is correct (for a particular
prime ciphertext component). Currently only works if 'small_s' is 0.
Correctness: 'small_s' must be true (and 's' must be in small form)
Note: index_map is non-const in case SE_INDEX_MAP_LOAD is defined (or, if
SE_INDEX_MAP_LOAD_PERSIST_SYM_LOAD_ASYM is defined and asymmetric encryption is used).
Size req: 'temp' must contain space for n double complex values
If index map needs to be loaded (see 'Note' above), index_map must constain space for n uint16_t
elements.
@param[in] c0 In: 1st component of ciphertext to check;
Out: Decrypted and decoded message
@param[in] c1 2nd component of ciphertext to check. Will be corrupted!
@param[in] values Cleartext input message
@param[in] values_len True number of entries in initial values message. Must be <= n/2
@param[in] s Secret key. Must be in expanded form!
@param[in] small_s If true, secret key is in small form; Else, is in expanded form
@param[in] pte_calc Plaintext + error (in NTT form) (output by ckks_encode for testing)
@param[in] index_map [Optional]. If passed in, can avoid 1 flash read
@param[in] parms Parameters instance
@param temp Scratch space
*/
void check_decode_decrypt_inpl(ZZ *c0, ZZ *c1, const flpt *values, size_t values_len, const ZZ *s,
bool small_s, const ZZ *pte_calc, uint16_t *index_map,
const Parms *parms, ZZ *temp);