-
Notifications
You must be signed in to change notification settings - Fork 1
/
bswabe.h
122 lines (101 loc) · 3.72 KB
/
bswabe.h
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
/*
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;
/*
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 );
/*
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 );
/*
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 );
/*
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