CiFEr
ring_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_RING_LWE_H
18 #define CIFER_RING_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"
27 
37 typedef struct cfe_ring_lwe {
38  size_t l; // Length of data vectors for inner product
39 
40  size_t n; // main security parameters of the scheme
41 
42  mpz_t bound; // Data vector coordinates should be strictly smaller than bound
43 
44  mpz_t p; // Modulus for message space
45  mpz_t q; // Modulus for ciphertext and keys
46 
47  // vector a of dimension n representing the random polynomial for the scheme
48  cfe_vec a;
49 
50  // sampler
51  cfe_normal_cumulative sampler;
52 } cfe_ring_lwe;
53 
54 // TODO: this scheme needs automatic parameters generation and the input should
55 // depend only on n, l, bound_x, bound_y (i.e. also bound x and bound_y should be separated),
56 // this needs some theoretical effort.
57 
71 cfe_error cfe_ring_lwe_init(cfe_ring_lwe *s, size_t l, size_t n, mpz_t bound, mpz_t p, mpz_t q, mpf_t sigma);
72 
81 
90 
99 
110 
119 
132 cfe_error cfe_ring_lwe_derive_fe_key(cfe_vec *sk_y, cfe_ring_lwe *s, cfe_mat *SK, cfe_vec *y);
133 
142 
153 cfe_error cfe_ring_lwe_encrypt(cfe_mat *CT, cfe_ring_lwe *s, cfe_mat *x, cfe_mat *PK);
154 
163 
176 cfe_error cfe_ring_lwe_decrypt(cfe_vec *res, cfe_ring_lwe *s, cfe_mat *ct, cfe_vec *sk_y, cfe_vec *y);
177 
186 
187 #endif
cfe_ring_lwe
Definition: ring_lwe.h:37
cfe_ring_lwe_derive_fe_key
cfe_error cfe_ring_lwe_derive_fe_key(cfe_vec *sk_y, cfe_ring_lwe *s, cfe_mat *SK, cfe_vec *y)
cfe_vec
Definition: vec.h:41
cfe_ring_lwe_decrypted_init
void cfe_ring_lwe_decrypted_init(cfe_vec *res, cfe_ring_lwe *s)
cfe_ring_lwe_generate_pub_key
cfe_error cfe_ring_lwe_generate_pub_key(cfe_mat *PK, cfe_ring_lwe *s, cfe_mat *SK)
cfe_ring_lwe_free
void cfe_ring_lwe_free(cfe_ring_lwe *s)
mat.h
Matrix struct and operations.
errors.h
Error definitions.
cfe_ring_lwe_encrypt
cfe_error cfe_ring_lwe_encrypt(cfe_mat *CT, cfe_ring_lwe *s, cfe_mat *x, cfe_mat *PK)
cfe_ring_lwe_generate_sec_key
void cfe_ring_lwe_generate_sec_key(cfe_mat *SK, cfe_ring_lwe *s)
cfe_ring_lwe_init
cfe_error cfe_ring_lwe_init(cfe_ring_lwe *s, size_t l, size_t n, mpz_t bound, mpz_t p, mpz_t q, mpf_t sigma)
normal_cumulative.h
Normal cumulative sampler.
vec.h
Vector struct and operations.
cfe_ring_lwe_decrypt
cfe_error cfe_ring_lwe_decrypt(cfe_vec *res, cfe_ring_lwe *s, cfe_mat *ct, cfe_vec *sk_y, cfe_vec *y)
cfe_ring_lwe_pub_key_init
void cfe_ring_lwe_pub_key_init(cfe_mat *PK, cfe_ring_lwe *s)
cfe_ring_lwe
struct cfe_ring_lwe cfe_ring_lwe
cfe_ring_lwe_sec_key_init
void cfe_ring_lwe_sec_key_init(cfe_mat *SK, cfe_ring_lwe *s)
cfe_mat
Definition: mat.h:44
cfe_normal_cumulative
Definition: normal_cumulative.h:36
cfe_ring_lwe_fe_key_init
void cfe_ring_lwe_fe_key_init(cfe_vec *sk_y, cfe_ring_lwe *s)
cfe_ring_lwe_ciphertext_init
void cfe_ring_lwe_ciphertext_init(cfe_mat *CT, cfe_ring_lwe *s)