summaryrefslogtreecommitdiffstats
path: root/moon-abe/libbswabe-0.9/bswabe.h
blob: 5213154d6d62be649c0692db97e98ce80edb7284 (plain)
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
169
170
171
172
173
174
175
176
177
/*
  Include glib.h and pbc.h before including this file. Note that this
  file should be included at most once.
*/

#if defined (__cplusplus)
extern "C" {
#endif

/*
  A public key.
*/
typedef struct bswabe_pub_s bswabe_pub_t;

/*
  A master secret key.
*/
typedef struct bswabe_msk_s bswabe_msk_t;

/*
  A private key.
*/
typedef struct bswabe_prv_s bswabe_prv_t;

/*
  A ciphertext. Note that this library only handles encrypting a
  single group element, so if you want to encrypt something bigger,
  you will have to use that group element as a symmetric key for
  hybrid encryption (which you do yourself).
*/
typedef struct bswabe_cph_s bswabe_cph_t;


/*
A searchable encryption word. Contains two elements: [g^r,t]
g in G_1 and t = e(H_1(W),h^r) in G_t
*/
typedef struct peks_sew_s peks_sew_t;


/*
A trapdoor for a word. T_W = H_1(W)^a in G_1
*/
typedef struct peks_trap_s peks_trap_t;

/*
  An index.
*/
typedef struct peks_ind_s peks_ind_t;


/*
  Generate a public key and corresponding master secret key, and
  assign the *pub and *msk pointers to them. The space used may be
  later freed by calling bswabe_pub_free(*pub) and
  bswabe_msk_free(*msk).
*/
void bswabe_setup( bswabe_pub_t** pub, bswabe_msk_t** msk );

/*
  Generate a private key with the given set of attributes. The final
  argument should be a null terminated array of pointers to strings,
  one for each attribute.
*/
bswabe_prv_t* bswabe_keygen( bswabe_pub_t* pub,
                             bswabe_msk_t* msk,
                             char** attributes );

/*
  Pick a random group element and encrypt it under the specified
  access policy. The resulting ciphertext is returned and the
  element_t given as an argument (which need not be initialized) is
  set to the random group element.

  After using this function, it is normal to extract the random data
  in m using the pbc functions element_length_in_bytes and
  element_to_bytes and use it as a key for hybrid encryption.

  The policy is specified as a simple string which encodes a postorder
  traversal of threshold tree defining the access policy. As an
  example,

    "foo bar fim 2of3 baf 1of2"

  specifies a policy with two threshold gates and four leaves. It is
  not possible to specify an attribute with whitespace in it (although
  "_" is allowed).

  Numerical attributes and any other fancy stuff are not supported.

  Returns null if an error occured, in which case a description can be
  retrieved by calling bswabe_error().
*/
bswabe_cph_t* bswabe_enc( bswabe_pub_t* pub, element_t m, char* policy );

/*
  Decrypt the specified ciphertext using the given private key,
  filling in the provided element m (which need not be initialized)
  with the result.

  Returns true if decryption succeeded, false if this key does not
  satisfy the policy of the ciphertext (in which case m is unaltered).
*/
int bswabe_dec( bswabe_pub_t* pub, bswabe_prv_t* prv,
                bswabe_cph_t* cph, element_t m );

/* Returns the policy of a ciphertext*/
char* bswabe_policyList( bswabe_cph_t* cph);

/* Returns the list of attributes of a privaate key*/
char** bswabe_attrList( bswabe_prv_t* prv);


/*
Generates a searchable encrypted word
*/
peks_sew_t peks_enc( bswabe_pub_t* pub, char* w );

/*
Generates a trapdoor corresponding to the word w
*/
peks_trap_t* peks_trap( bswabe_pub_t* pub, bswabe_msk_t* msk, char* w );

/*
Test if the encrypted word correspond to the word represented by the trapdoor
*/
int peks_test( bswabe_pub_t* pub, peks_sew_t sew, peks_trap_t* trap );

/* Generates an encrypted index using the public key and a clear index.
   Each keyword of the clear index should be on a different line  */
peks_ind_t* peks_enc_ind( bswabe_pub_t* pub, char* ind_file );

/* Tests if the encrypted index match with the trapdoor  */
int peks_test_ind( bswabe_pub_t* pub, peks_ind_t* ind, peks_trap_t* trap );

/*
  Exactly what it seems.
*/
GByteArray* bswabe_pub_serialize( bswabe_pub_t* pub );
GByteArray* bswabe_msk_serialize( bswabe_msk_t* msk );
GByteArray* bswabe_prv_serialize( bswabe_prv_t* prv );
GByteArray* bswabe_cph_serialize( bswabe_cph_t* cph );
GByteArray* peks_sew_serialize( peks_sew_t* sew );
GByteArray* peks_ind_serialize( peks_ind_t* ind );
GByteArray* peks_trap_serialize( peks_trap_t* trap );

/*
  Also exactly what it seems. If free is true, the GByteArray passed
  in will be free'd after it is read.
*/
bswabe_pub_t* bswabe_pub_unserialize( GByteArray* b, int free );
bswabe_msk_t* bswabe_msk_unserialize( bswabe_pub_t* pub, GByteArray* b, int free );
bswabe_prv_t* bswabe_prv_unserialize( bswabe_pub_t* pub, GByteArray* b, int free );
bswabe_cph_t* bswabe_cph_unserialize( bswabe_pub_t* pub, GByteArray* b, int free );
peks_sew_t* peks_sew_unserialize( bswabe_pub_t* pub, GByteArray* b, int free );
peks_ind_t* peks_ind_unserialize( bswabe_pub_t* pub, GByteArray* b, int free );
peks_trap_t* peks_trap_unserialize( bswabe_pub_t* pub, GByteArray* b, int free );


/*
  Again, exactly what it seems.
*/
void bswabe_pub_free( bswabe_pub_t* pub );
void bswabe_msk_free( bswabe_msk_t* msk );
void bswabe_prv_free( bswabe_prv_t* prv );
void bswabe_cph_free( bswabe_cph_t* cph );

/*
  Return a description of the last error that occured. Call this after
  bswabe_enc or bswabe_dec returns 0. The returned string does not
  need to be free'd.
*/
char* bswabe_error();

#if defined (__cplusplus)
} // extern "C"
#endif