libtc  20160415
Threshold Cryptography functions library
tc.h
Go to the documentation of this file.
1 #ifndef TC_H
2 #define TC_H
3 
4 #include <stddef.h> // for size_t
5 #include <stdint.h> // for uint8_t
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
14 struct bytes {
15  void *data;
16  uint32_t data_len;
17 };
18 typedef struct bytes bytes_t;
19 
24 typedef struct public_key public_key_t;
25 
31 
36 typedef struct key_share key_share_t;
37 
43 
50 };
52 
53 
54 /* Operations & Constructors */
55 
56 
67 bytes_t *tc_init_bytes(void *bs, size_t len);
68 
79 bytes_t *tc_init_bytes_copy(void *bs, size_t len);
80 
94 key_share_t **tc_generate_keys(key_metainfo_t **metainfo, size_t bit_size, uint16_t k, uint16_t l, bytes_t * e);
95 
108 signature_share_t *tc_node_sign(const key_share_t *share, const bytes_t *doc, const key_metainfo_t *info);
109 
120 bytes_t *tc_join_signatures(const signature_share_t **signatures, const bytes_t *document, const key_metainfo_t *info);
121 
132 int tc_verify_signature(const signature_share_t *signature, const bytes_t *doc, const key_metainfo_t *info);
133 
145 bytes_t *tc_prepare_document(const bytes_t *doc, tc_hash_type_t hash_type, const key_metainfo_t *metainfo);
146 
157 int tc_rsa_verify(bytes_t *signature, bytes_t *doc, key_metainfo_t *info, tc_hash_type_t hashtype);
158 
159 
160 /* Getters */
161 
167 int tc_key_meta_info_k(const key_metainfo_t *i);
168 
174 int tc_key_meta_info_l(const key_metainfo_t *i);
175 
182 
188 int tc_key_share_id(const key_share_t *k);
189 
195 const bytes_t *tc_public_key_n(const public_key_t *pk);
196 
202 const bytes_t *tc_public_key_e(const public_key_t *pk);
203 
210 
211 
212 /* Serializers */
213 
219 char *tc_bytes_b64(const bytes_t *b);
220 
226 bytes_t *tc_b64_bytes(const char *s);
227 
228 /* *** Serialization Format ***
229  * The colon means concatenation.
230  * KeyShare:
231  * Base64(version :: id :: n_len :: n :: si_len :: si)
232  * SignatureShare:
233  * Base64(version :: id :: xi_len :: xi :: c_len :: c :: z_len :: z)
234  * PublicKey:
235  * Bytes(n :: e :: m) -> pk_len :: pk
236  * KeyMetainfo:
237  * Base64(version :: pk_len :: pk :: k :: l :: vk_len :: vk :: v0_len :: v0 :: ... :: v(l-1)_len :: v(l-1))
238  */
239 
243 char *tc_serialize_key_share(const key_share_t *ks);
244 
249 
253 char *tc_serialize_key_metainfo(const key_metainfo_t *kmi);
254 
258 key_share_t *tc_deserialize_key_share(const char *b64);
259 
264 
269 
270 /* Destructors */
271 
276 
284 void* tc_release_bytes(bytes_t *bytes, uint32_t *len);
285 
289 void tc_clear_bytes_n(bytes_t *bytes, ...);
290 
295 
300 
304 void tc_clear_key_share(key_share_t *share);
305 
309 void tc_clear_key_shares(key_share_t **shares, key_metainfo_t *info);
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 
315 #endif
bytes_t * tc_join_signatures(const signature_share_t **signatures, const bytes_t *document, const key_metainfo_t *info)
char * tc_serialize_signature_share(const signature_share_t *ss)
bytes_t * tc_b64_bytes(const char *s)
void tc_clear_key_shares(key_share_t **shares, key_metainfo_t *info)
Definition: structs_init.c:172
char * tc_serialize_key_metainfo(const key_metainfo_t *kmi)
void tc_clear_key_share(key_share_t *share)
Definition: structs_init.c:167
signature_share_t * tc_deserialize_signature_share(const char *b64)
bytes_t * tc_init_bytes_copy(void *bs, size_t len)
Definition: structs_init.c:26
char * tc_serialize_key_share(const key_share_t *ks)
void tc_clear_key_metainfo(key_metainfo_t *info)
Definition: structs_init.c:136
Structure that&#39;s stores a pointer that points to data_len bytes.
Definition: tc.h:14
Structure that represents a signature share, to be joined generating a standard RSA signatures...
Definition: tc_internal.h:28
Structure that represents the data about a key share, including its public key.
Definition: tc_internal.h:13
Definition: tc.h:48
key_share_t ** tc_generate_keys(key_metainfo_t **metainfo, size_t bit_size, uint16_t k, uint16_t l, bytes_t *e)
int tc_key_meta_info_l(const key_metainfo_t *i)
Definition: structs_init.c:112
Definition: tc.h:49
const bytes_t * tc_public_key_e(const public_key_t *pk)
Definition: structs_init.c:128
void * tc_release_bytes(bytes_t *bytes, uint32_t *len)
Definition: structs_init.c:44
tc_hash_type
Hash functions to be used when preparing a document to be signed.
Definition: tc.h:47
void * data
Definition: tc.h:15
uint32_t data_len
Definition: tc.h:16
Structure that represents a standard RSA public key. Used to verify signatures.
Definition: tc_internal.h:8
void tc_clear_bytes_n(bytes_t *bytes,...)
Definition: structs_init.c:61
int tc_signature_share_id(const signature_share_t *s)
Definition: structs_init.c:132
int tc_verify_signature(const signature_share_t *signature, const bytes_t *doc, const key_metainfo_t *info)
void tc_clear_signature_share(signature_share_t *ss)
Definition: structs_init.c:191
bytes_t * tc_prepare_document(const bytes_t *doc, tc_hash_type_t hash_type, const key_metainfo_t *metainfo)
const public_key_t * tc_key_meta_info_public_key(const key_metainfo_t *i)
Definition: structs_init.c:116
key_metainfo_t * tc_deserialize_key_metainfo(const char *b64)
signature_share_t * tc_node_sign(const key_share_t *share, const bytes_t *doc, const key_metainfo_t *info)
key_share_t * tc_deserialize_key_share(const char *b64)
int tc_key_meta_info_k(const key_metainfo_t *i)
Definition: structs_init.c:108
enum tc_hash_type tc_hash_type_t
Definition: tc.h:51
Structure that represents one key share, to be used to generate a signature share.
Definition: tc_internal.h:22
void tc_clear_bytes(bytes_t *bytes)
Definition: structs_init.c:39
bytes_t * tc_init_bytes(void *bs, size_t len)
Definition: structs_init.c:18
int tc_key_share_id(const key_share_t *k)
Definition: structs_init.c:120
char * tc_bytes_b64(const bytes_t *b)
int tc_rsa_verify(bytes_t *signature, bytes_t *doc, key_metainfo_t *info, tc_hash_type_t hashtype)
const bytes_t * tc_public_key_n(const public_key_t *pk)
Definition: structs_init.c:124