-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcelia.h
More file actions
168 lines (149 loc) · 3.83 KB
/
Copy pathcelia.h
File metadata and controls
168 lines (149 loc) · 3.83 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*! \file celia.h
*
* \brief Routines for the Goyal-Pandey-Sahai-Waters ABE scheme.
* Include glib.h and pbc.h before including this file.
*
* Copyright 2011 Yao Zheng.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#if defined (__cplusplus)
extern "C" {
#endif
/*
one attribute structure in public key
*/
typedef struct
{
char* attr;
element_t T; /* G_1 */
}
kpabe_pub_comp_t;
/*
A public key.
*/
typedef struct
{
char* pairing_desc;
pairing_t p;
element_t g; /* G_1 */
element_t Y; /* G_T */
GArray* comps; /* kpabe_pub_comp_t */
}
kpabe_pub_t;
/*
one attribute structure in master key
*/
typedef struct
{
char* attr;
element_t t; /* Z_p */
}
kpabe_msk_comp_t;
/*
A master secret key.
*/
typedef struct
{
element_t y; /* Z_p */
GArray* comps; /* kpabe_msk_comp_t */
}
kpabe_msk_t;
typedef struct
{
int deg;
/* coefficients from [0] x^0 to [deg] x^deg */
element_t* coef; /* Z_p (of length deg + 1) */
}
kpabe_polynomial_t;
typedef struct
{
/* serialized */
int k; /* one if leaf, otherwise threshold */
char* attr; /* attribute string if leaf, otherwise null */
element_t D; /* G_1, only for leaves */
GPtrArray* children; /* pointers to kpabe_policy_t's, len == 0 for leaves */
/* only used during encryption */
kpabe_polynomial_t* q;
/* only used during decryption */
int satisfiable;
int min_leaves;
int attri;
GArray* satl;
}
kpabe_policy_t;
/*
A private key.
*/
typedef struct
{
kpabe_policy_t* p; /* kpabe_policy_t */
}
kpabe_prv_t;
/*
one attribute structure in ciphertext key
*/
typedef struct
{
char* attr;
element_t E; /* G_1 */
}
kpabe_cph_comp_t;
/*
A ciphertext.
*/
typedef struct
{
element_t Ep; /* G_T */
GArray* comps; /* kpabe_cph_comp_t */
}
kpabe_cph_t;
/*
core function
*/
void kpabe_setup( kpabe_pub_t** pub, kpabe_msk_t** msk, char** attributes );
kpabe_prv_t* kpabe_keygen( kpabe_pub_t* pub,kpabe_msk_t* msk,char* policy );
kpabe_cph_t* kpabe_enc( kpabe_pub_t* pub, element_t m, char** attributes );
int kpabe_dec( kpabe_pub_t* pub, kpabe_prv_t* prv, kpabe_cph_t* cph, element_t m );
/*
Exactly what it seems.
*/
GByteArray* kpabe_pub_serialize( kpabe_pub_t* pub );
GByteArray* kpabe_msk_serialize( kpabe_msk_t* msk );
GByteArray* kpabe_prv_serialize( kpabe_prv_t* prv );
GByteArray* kpabe_cph_serialize( kpabe_cph_t* cph );
/*
Also exactly what it seems. If free is true, the GByteArray passed
in will be free'd after it is read.
*/
kpabe_pub_t* kpabe_pub_unserialize( GByteArray* b, int free );
kpabe_msk_t* kpabe_msk_unserialize( kpabe_pub_t* pub, GByteArray* b, int free );
kpabe_prv_t* kpabe_prv_unserialize( kpabe_pub_t* pub, GByteArray* b, int free );
kpabe_cph_t* kpabe_cph_unserialize( kpabe_pub_t* pub, GByteArray* b, int free );
/*
Again, exactly what it seems.
*/
void kpabe_pub_free( kpabe_pub_t* pub );
void kpabe_msk_free( kpabe_msk_t* msk );
void kpabe_prv_free( kpabe_prv_t* prv );
void kpabe_cph_free( kpabe_cph_t* cph );
/*
Return a description of the last error that occured. Call this after
kpabe_enc or kpabe_dec returns 0. The returned string does not
need to be free'd.
*/
char* kpabe_error();
#if defined (__cplusplus)
} // extern "C"
#endif