CiFEr
lwe_fs.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 XLAB d.o.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CIFER_LWE_FS_H
18 #define CIFER_LWE_FS_H
19 
20 #include <math.h>
21 #include <gmp.h>
22 
23 #include "cifer/data/vec.h"
24 #include "cifer/data/mat.h"
25 #include "cifer/internal/errors.h"
26 
36 typedef struct cfe_lwe_fs {
37  size_t l; // Length of data vectors for inner product
38 
39  size_t n; // Main security parameters of the scheme
40  size_t m; // Number of samples
41 
42  // Message space size
43  mpz_t bound_x;
44  // Inner product vector space size
45  mpz_t bound_y;
46  // Modulus for the resulting inner product.
47  // K depends on the parameters l, P and V and is computed by the scheme.
48  mpz_t K;
49  // Modulus for ciphertext and keys.
50  // Must be significantly larger than K.
51  mpz_t q;
52  // standard deviation for the noise terms in the encryption process
53  mpf_t sigma_q;
54  mpz_t k_sigma_q;
55  // standard deviation for first half of the matrix for sampling private key
56  mpf_t sigma1;
57  mpz_t k_sigma1;
58  // standard deviation for second half of the matrix for sampling private key
59  mpf_t sigma2;
60  mpz_t k_sigma2;
61 
62  // Matrix A of dimensions m*n is a public parameter
63  // of the scheme
64  cfe_mat A;
65 } cfe_lwe_fs;
66 
78 cfe_error cfe_lwe_fs_init(cfe_lwe_fs *s, size_t l, size_t n, mpz_t bound_x, mpz_t bound_y);
79 
88 
97 
106 
116 cfe_error cfe_lwe_fs_generate_pub_key(cfe_mat *PK, cfe_lwe_fs *s, cfe_mat *SK);
117 
126 
139 cfe_error cfe_lwe_fs_derive_fe_key(cfe_vec *z_y, cfe_lwe_fs *s, cfe_vec *y, cfe_mat *SK);
140 
149 
160 cfe_error cfe_lwe_fs_encrypt(cfe_vec *ct, cfe_lwe_fs *s, cfe_vec *x, cfe_mat *PK);
161 
175 cfe_error cfe_lwe_fs_decrypt(mpz_t res, cfe_lwe_fs *s, cfe_vec *ct, cfe_vec *z_y, cfe_vec *y);
176 
184 void cfe_lwe_fs_free(cfe_lwe_fs *s);
185 
186 #endif
cfe_lwe_fs_ciphertext_init
void cfe_lwe_fs_ciphertext_init(cfe_vec *ct, cfe_lwe_fs *s)
cfe_vec
Definition: vec.h:41
cfe_lwe_fs_encrypt
cfe_error cfe_lwe_fs_encrypt(cfe_vec *ct, cfe_lwe_fs *s, cfe_vec *x, cfe_mat *PK)
cfe_lwe_fs_generate_sec_key
void cfe_lwe_fs_generate_sec_key(cfe_mat *SK, cfe_lwe_fs *s)
mat.h
Matrix struct and operations.
errors.h
Error definitions.
cfe_lwe_fs
Definition: lwe_fs.h:36
cfe_lwe_fs_sec_key_init
void cfe_lwe_fs_sec_key_init(cfe_mat *SK, cfe_lwe_fs *s)
cfe_lwe_fs_init
cfe_error cfe_lwe_fs_init(cfe_lwe_fs *s, size_t l, size_t n, mpz_t bound_x, mpz_t bound_y)
cfe_lwe_fs_pub_key_init
void cfe_lwe_fs_pub_key_init(cfe_mat *PK, cfe_lwe_fs *s)
cfe_lwe_fs_generate_pub_key
cfe_error cfe_lwe_fs_generate_pub_key(cfe_mat *PK, cfe_lwe_fs *s, cfe_mat *SK)
cfe_lwe_fs_fe_key_init
void cfe_lwe_fs_fe_key_init(cfe_vec *z_y, cfe_lwe_fs *s)
cfe_lwe_fs
struct cfe_lwe_fs cfe_lwe_fs
cfe_lwe_fs_decrypt
cfe_error cfe_lwe_fs_decrypt(mpz_t res, cfe_lwe_fs *s, cfe_vec *ct, cfe_vec *z_y, cfe_vec *y)
vec.h
Vector struct and operations.
cfe_lwe_fs_derive_fe_key
cfe_error cfe_lwe_fs_derive_fe_key(cfe_vec *z_y, cfe_lwe_fs *s, cfe_vec *y, cfe_mat *SK)
cfe_mat
Definition: mat.h:44
cfe_lwe_fs_free
void cfe_lwe_fs_free(cfe_lwe_fs *s)