CiFEr
lwe.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_H
18 #define CIFER_LWE_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 {
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 rows (samples) for the LWE problem
41 
42  mpz_t bound_x; // Bound for input vector coordinates (for x)
43  mpz_t bound_y; // Bound for inner product vector coordinates (for y)
44 
45  mpz_t p; // Modulus for message space
46  mpz_t q; // Modulus for ciphertext and keys
47 
48  mpf_t sigma_q;
49  mpz_t k_sigma_q;
50 
51  // Matrix A of dimensions m*n is a public parameter
52  // of the scheme
53  cfe_mat A;
54 } cfe_lwe;
55 
71 cfe_error cfe_lwe_init(cfe_lwe *s, size_t l, mpz_t bound_x, mpz_t bound_y, size_t n);
72 
81 
90 
99 
109 cfe_error cfe_lwe_generate_pub_key(cfe_mat *PK, cfe_lwe *s, cfe_mat *SK);
110 
118 void cfe_lwe_fe_key_init(cfe_vec *sk_y, cfe_lwe *s);
119 
132 cfe_error cfe_lwe_derive_fe_key(cfe_vec *sk_y, cfe_lwe *s, cfe_mat *SK, cfe_vec *y);
133 
142 
153 cfe_error cfe_lwe_encrypt(cfe_vec *ct, cfe_lwe *s, cfe_vec *x, cfe_mat *PK);
154 
167 cfe_error cfe_lwe_decrypt(mpz_t res, cfe_lwe *s, cfe_vec *c, cfe_vec *sk_y, cfe_vec *y);
168 
176 void cfe_lwe_free(cfe_lwe *s);
177 
178 #endif
cfe_lwe_fe_key_init
void cfe_lwe_fe_key_init(cfe_vec *sk_y, cfe_lwe *s)
cfe_vec
Definition: vec.h:41
cfe_lwe_derive_fe_key
cfe_error cfe_lwe_derive_fe_key(cfe_vec *sk_y, cfe_lwe *s, cfe_mat *SK, cfe_vec *y)
cfe_lwe_generate_sec_key
void cfe_lwe_generate_sec_key(cfe_mat *SK, cfe_lwe *s)
cfe_lwe_ciphertext_init
void cfe_lwe_ciphertext_init(cfe_vec *ct, cfe_lwe *s)
mat.h
Matrix struct and operations.
errors.h
Error definitions.
cfe_lwe_init
cfe_error cfe_lwe_init(cfe_lwe *s, size_t l, mpz_t bound_x, mpz_t bound_y, size_t n)
cfe_lwe_free
void cfe_lwe_free(cfe_lwe *s)
cfe_lwe
struct cfe_lwe cfe_lwe
cfe_lwe_generate_pub_key
cfe_error cfe_lwe_generate_pub_key(cfe_mat *PK, cfe_lwe *s, cfe_mat *SK)
cfe_lwe_pub_key_init
void cfe_lwe_pub_key_init(cfe_mat *PK, cfe_lwe *s)
vec.h
Vector struct and operations.
cfe_lwe
Definition: lwe.h:36
cfe_lwe_encrypt
cfe_error cfe_lwe_encrypt(cfe_vec *ct, cfe_lwe *s, cfe_vec *x, cfe_mat *PK)
cfe_lwe_decrypt
cfe_error cfe_lwe_decrypt(mpz_t res, cfe_lwe *s, cfe_vec *c, cfe_vec *sk_y, cfe_vec *y)
cfe_lwe_sec_key_init
void cfe_lwe_sec_key_init(cfe_mat *SK, cfe_lwe *s)
cfe_mat
Definition: mat.h:44