CiFEr
sgp.h
Go to the documentation of this file.
1 /* *
2  * Copyright (C) 2018 XLAB d.o.o.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of either:
6  *
7  * * the GNU Lesser General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * or
12  *
13  * * the GNU General Public License as published by the Free Software
14  * Foundation; either version 2 of the License, or (at your option) any
15  * later version.
16  *
17  * or both in parallel, as here.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef CIFER_SGP_H
29 #define CIFER_SGP_H
30 
31 #include "cifer/data/vec.h"
32 #include "cifer/internal/errors.h"
33 #include "cifer/data/vec_curve.h"
34 
47 typedef struct cfe_sgp {
48  size_t l;
49  mpz_t bound;
50  mpz_t mod;
51  BIG_256_56 mod_big;
52 } cfe_sgp;
53 
57 typedef struct cfe_sgp_sec_key {
58  cfe_vec s;
59  cfe_vec t;
61 
65 typedef struct cfe_sgp_cipher {
66  ECP_BN254 g1MulGamma;
67  cfe_vec_G1 *a;
68  cfe_vec_G2 *b;
69  size_t l;
71 
81 cfe_error cfe_sgp_init(cfe_sgp *s, size_t l, mpz_t bound);
82 
90 void cfe_sgp_free(cfe_sgp *s);
91 
100 
109 
119 
132 cfe_error cfe_sgp_derive_fe_key(ECP2_BN254 *key, cfe_sgp *sgp, cfe_sgp_sec_key *msk, cfe_mat *f);
133 
141 void cfe_sgp_cipher_init(cfe_sgp_cipher *cipher, cfe_sgp *s);
142 
150 void cfe_sgp_cipher_free(cfe_sgp_cipher *cipher);
151 
163 cfe_error cfe_sgp_encrypt(cfe_sgp_cipher *cipher, cfe_sgp *s, cfe_vec *x, cfe_vec *y, cfe_sgp_sec_key *msk);
164 
178 cfe_error cfe_sgp_decrypt(mpz_t res, cfe_sgp *s, cfe_sgp_cipher *cipher, ECP2_BN254 *key, cfe_mat *f);
179 
180 #endif
cfe_vec_G1
Definition: vec_curve.h:34
cfe_sgp_sec_key_init
void cfe_sgp_sec_key_init(cfe_sgp_sec_key *msk, cfe_sgp *sgp)
cfe_sgp_generate_sec_key
void cfe_sgp_generate_sec_key(cfe_sgp_sec_key *msk, cfe_sgp *s)
cfe_vec
Definition: vec.h:41
cfe_sgp_sec_key_free
void cfe_sgp_sec_key_free(cfe_sgp_sec_key *msk)
cfe_sgp_encrypt
cfe_error cfe_sgp_encrypt(cfe_sgp_cipher *cipher, cfe_sgp *s, cfe_vec *x, cfe_vec *y, cfe_sgp_sec_key *msk)
cfe_sgp
struct cfe_sgp cfe_sgp
cfe_sgp_decrypt
cfe_error cfe_sgp_decrypt(mpz_t res, cfe_sgp *s, cfe_sgp_cipher *cipher, ECP2_BN254 *key, cfe_mat *f)
cfe_sgp_cipher_init
void cfe_sgp_cipher_init(cfe_sgp_cipher *cipher, cfe_sgp *s)
cfe_sgp_cipher
struct cfe_sgp_cipher cfe_sgp_cipher
cfe_sgp_cipher
Definition: sgp.h:65
errors.h
Error definitions.
vec_curve.h
Vectors of elements of an elliptic curve struct and operations on it.
cfe_sgp_init
cfe_error cfe_sgp_init(cfe_sgp *s, size_t l, mpz_t bound)
cfe_sgp_derive_fe_key
cfe_error cfe_sgp_derive_fe_key(ECP2_BN254 *key, cfe_sgp *sgp, cfe_sgp_sec_key *msk, cfe_mat *f)
cfe_sgp_sec_key
Definition: sgp.h:57
cfe_sgp
Definition: sgp.h:47
cfe_sgp_sec_key
struct cfe_sgp_sec_key cfe_sgp_sec_key
vec.h
Vector struct and operations.
cfe_vec_G2
Definition: vec_curve.h:42
cfe_sgp_free
void cfe_sgp_free(cfe_sgp *s)
cfe_sgp_cipher_free
void cfe_sgp_cipher_free(cfe_sgp_cipher *cipher)
cfe_mat
Definition: mat.h:44