libtc  20160415
Threshold Cryptography functions library
Classes | Typedefs | Enumerations | Functions
tc.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  bytes
 Structure that's stores a pointer that points to data_len bytes. More...
 

Typedefs

typedef struct bytes bytes_t
 
typedef struct public_key public_key_t
 
typedef struct key_metainfo key_metainfo_t
 
typedef struct key_share key_share_t
 
typedef struct signature_share signature_share_t
 
typedef enum tc_hash_type tc_hash_type_t
 

Enumerations

enum  tc_hash_type { TC_SHA256, TC_NONE }
 Hash functions to be used when preparing a document to be signed. More...
 

Functions

bytes_ttc_init_bytes (void *bs, size_t len)
 
bytes_ttc_init_bytes_copy (void *bs, size_t len)
 
key_share_t ** tc_generate_keys (key_metainfo_t **metainfo, size_t bit_size, uint16_t k, uint16_t l, bytes_t *e)
 
signature_share_ttc_node_sign (const key_share_t *share, const bytes_t *doc, const key_metainfo_t *info)
 
bytes_ttc_join_signatures (const signature_share_t **signatures, const bytes_t *document, const key_metainfo_t *info)
 
int tc_verify_signature (const signature_share_t *signature, const bytes_t *doc, const key_metainfo_t *info)
 
bytes_ttc_prepare_document (const bytes_t *doc, tc_hash_type_t hash_type, const key_metainfo_t *metainfo)
 
int tc_rsa_verify (bytes_t *signature, bytes_t *doc, key_metainfo_t *info, tc_hash_type_t hashtype)
 
int tc_key_meta_info_k (const key_metainfo_t *i)
 
int tc_key_meta_info_l (const key_metainfo_t *i)
 
const public_key_ttc_key_meta_info_public_key (const key_metainfo_t *i)
 
int tc_key_share_id (const key_share_t *k)
 
const bytes_ttc_public_key_n (const public_key_t *pk)
 
const bytes_ttc_public_key_e (const public_key_t *pk)
 
int tc_signature_share_id (const signature_share_t *s)
 
char * tc_bytes_b64 (const bytes_t *b)
 
bytes_ttc_b64_bytes (const char *s)
 
char * tc_serialize_key_share (const key_share_t *ks)
 
char * tc_serialize_signature_share (const signature_share_t *ss)
 
char * tc_serialize_key_metainfo (const key_metainfo_t *kmi)
 
key_share_ttc_deserialize_key_share (const char *b64)
 
signature_share_ttc_deserialize_signature_share (const char *b64)
 
key_metainfo_ttc_deserialize_key_metainfo (const char *b64)
 
void tc_clear_bytes (bytes_t *bytes)
 
void * tc_release_bytes (bytes_t *bytes, uint32_t *len)
 
void tc_clear_bytes_n (bytes_t *bytes,...)
 
void tc_clear_key_metainfo (key_metainfo_t *info)
 
void tc_clear_signature_share (signature_share_t *ss)
 
void tc_clear_key_share (key_share_t *share)
 
void tc_clear_key_shares (key_share_t **shares, key_metainfo_t *info)
 

Typedef Documentation

typedef struct bytes bytes_t

Definition at line 18 of file tc.h.

typedef struct key_metainfo key_metainfo_t

Definition at line 30 of file tc.h.

typedef struct key_share key_share_t

Definition at line 36 of file tc.h.

typedef struct public_key public_key_t

Definition at line 24 of file tc.h.

Definition at line 42 of file tc.h.

Definition at line 51 of file tc.h.

Enumeration Type Documentation

Hash functions to be used when preparing a document to be signed.

Enumerator
TC_SHA256 
TC_NONE 

Definition at line 47 of file tc.h.

Function Documentation

bytes_t* tc_b64_bytes ( const char *  s)
Parameters
[in]sa C string in the Base64 format.
Returns
a bytes_t structure with the binary data in s.

Definition at line 144 of file algorithms_base64.c.

char* tc_bytes_b64 ( const bytes_t b)
Parameters
[in]ba bytes_t structure.
Returns
a C string with the data of bytes serialized in the Base64 format.

Definition at line 140 of file algorithms_base64.c.

void tc_clear_bytes ( bytes_t bytes)

Clears the memory stored in bytes and its structure.

Definition at line 39 of file structs_init.c.

void tc_clear_bytes_n ( bytes_t bytes,
  ... 
)

Clears several bytes_t structures at once. The parameter list should end with a NULL sentinel.

Definition at line 61 of file structs_init.c.

void tc_clear_key_metainfo ( key_metainfo_t info)

Clears the memory of the structure

Definition at line 136 of file structs_init.c.

void tc_clear_key_share ( key_share_t share)

Clears the memory of the structure

Definition at line 167 of file structs_init.c.

void tc_clear_key_shares ( key_share_t **  shares,
key_metainfo_t info 
)

Clears the memory of all the key shares in the shares structure

Definition at line 172 of file structs_init.c.

void tc_clear_signature_share ( signature_share_t ss)

Clears the memory of the structure

Definition at line 191 of file structs_init.c.

key_metainfo_t* tc_deserialize_key_metainfo ( const char *  b64)

Deserializes a key share from a C string in the Base64 format

Definition at line 208 of file structs_serialization.c.

key_share_t* tc_deserialize_key_share ( const char *  b64)

Deserializes a key share from a C string in the Base64 format

Definition at line 159 of file structs_serialization.c.

signature_share_t* tc_deserialize_signature_share ( const char *  b64)

Deserializes a signature share from a C string in the Base64 format

Definition at line 183 of file structs_serialization.c.

key_share_t** tc_generate_keys ( key_metainfo_t **  out,
size_t  bit_size,
uint16_t  k,
uint16_t  l,
bytes_t public_e 
)

Function that generates an array with l key shares. The bit_size parameter is used to generates key shares with a security level equivalent to a RSA private of that size. The generated key shares have a threshold parameter of k. This means that k valid signatures are needed to sign.

Parameters
[out]metainfostores the corresponding key_metainfo to the key_share array.
[in]

Definition at line 42 of file algorithms_generate_keys.c.

bytes_t* tc_init_bytes ( void *  bs,
size_t  len 
)

Function that allocates and initialize a bytes_t structure that contains len bytes in the bs pointer. The bytes_t structure will own the data pointed by bs. Any bytes_t structure initialized by this function should be deinitialized by tc_clear_bytes.

Parameters
[in]bspointer to data
[in]lendata stored in len
Returns
a new bytes_t structure that stores bs with its len

Definition at line 18 of file structs_init.c.

bytes_t* tc_init_bytes_copy ( void *  bs,
size_t  len 
)

Function that allocates and initialize a bytes_t structure that contains a copy of the len bytes stored by the bs pointer. The data stored in the structure is a copy of the original data. Any bytes_t structure initialized by this function should be deinitialized by tc_clear_bytes.

Parameters
[in]bspointer to data
[in]lendata stored in len
Returns
a new bytes_t structure that stores a copy of bs with its len

Definition at line 26 of file structs_init.c.

bytes_t* tc_join_signatures ( const signature_share_t **  signatures,
const bytes_t document,
const key_metainfo_t info 
)

Function that takes several signature shares (at least the threshold number stored in info), and generates a standard RSA signature.

Parameters
[in]signaturesan array of the needed number of signature shares to be joined.
[in]

Definition at line 25 of file algorithms_join_signatures.c.

int tc_key_meta_info_k ( const key_metainfo_t i)
Parameters
[in]ithe metainfo of the key shares array.
Returns
the threshold number of the key shares array.

Definition at line 108 of file structs_init.c.

int tc_key_meta_info_l ( const key_metainfo_t i)
Parameters
[in]ithe metainfo of the key shares array.
Returns
the number of key shares in the originally generated key shares array.

Definition at line 112 of file structs_init.c.

const public_key_t* tc_key_meta_info_public_key ( const key_metainfo_t i)
Parameters
[in]ithe metainfo of the key shares array.
Returns
the public key structure of the key shares array

Definition at line 116 of file structs_init.c.

int tc_key_share_id ( const key_share_t k)
Parameters
[in]ka key share.
Returns
the id of the node that stores that key share

Definition at line 120 of file structs_init.c.

signature_share_t* tc_node_sign ( const key_share_t share,
const bytes_t doc,
const key_metainfo_t info 
)

Function that generates a signature share using a key share. A standard RSA signature is generated using several signature shares. The document to be signed should be prepared (hashed and padded) before using this function. In order to prepare the document we provide the tc_prepare_document function. But any other padder function may be used. For example, the Botan library provides a complete set of procedures that provide that functionality.

Parameters
[in]sharethe key share to be used in the signature operation.
[in]docthe document to be signed.
[in]themetainfo of the key shares array.
Returns
a signature share.

Definition at line 23 of file algorithms_node_sign.c.

bytes_t* tc_prepare_document ( const bytes_t doc,
tc_hash_type_t  hash_type,
const key_metainfo_t metainfo 
)

Function that hashes and adds the PKCS1 padding to the document to be signed. This function should be only used in testing environments. In production environments, any function that does the PSS padding should be used. Such functions are provided by general cryptography suites such as OpenSSL or Botan.

Parameters
[in]docthe document to be prepared.
[in]hash_typethe hash function to be used in the document.
[in]metainfothe metainfo of the key shares array, with the public key.
Returns
the prepared document.

Definition at line 91 of file algorithms_pkcs1_encoding.c.

const bytes_t* tc_public_key_e ( const public_key_t pk)
Parameters
[in]pka public key.
Returns
the public exponent of the RSA public key.

Definition at line 128 of file structs_init.c.

const bytes_t* tc_public_key_n ( const public_key_t pk)
Parameters
[in]pka public key.
Returns
the modulus of the RSA public key.

Definition at line 124 of file structs_init.c.

void* tc_release_bytes ( bytes_t bytes,
uint32_t *  len 
)

Clears just the bytes structure, and returns a pointer to bytes' data.

Parameters
[in]bytesthe bytes_t structure to be freed.
[out]lena pointer to store the length of the data stored in bytes.
Returns
a pointer to the data stored by bytes

Definition at line 44 of file structs_init.c.

int tc_rsa_verify ( bytes_t signature,
bytes_t doc,
key_metainfo_t info,
tc_hash_type_t  hashtype 
)

Function that verifies a standard RSA signature using the PKCS1 padding. Should be used only for testing purposed.

Parameters
[in]thesignature to be verified.
[in]thesigned document.
[in]themetainfo of the key shares array.
[in]thehash function used in the PKCS1 padding.
Returns
1 if the signature verifies the document, 0 otherwise.

Definition at line 14 of file algorithms_rsa_verify.c.

char* tc_serialize_key_metainfo ( const key_metainfo_t kmi)

Serializes a key shares array metainfo as a C string in the Base64 format

Definition at line 86 of file structs_serialization.c.

char* tc_serialize_key_share ( const key_share_t ks)

Serializes a key share as a C string in the Base64 format

Definition at line 21 of file structs_serialization.c.

char* tc_serialize_signature_share ( const signature_share_t ss)

Serializes a signature share as a C string in the Base64 format

Definition at line 51 of file structs_serialization.c.

int tc_signature_share_id ( const signature_share_t s)
Parameters
[in]sa signature share.
Returns
the id of the node that generated the signature share.

Definition at line 132 of file structs_init.c.

int tc_verify_signature ( const signature_share_t signature,
const bytes_t doc,
const key_metainfo_t info 
)

Function that verifies that a signature share was generated by any key shares that shares the same key metainfo. That means, any key shares that came from the same key_share array.

Parameters
signaturethe signature to be verified.
docthe document used to generate the signature share.
infothe metainfo of the key shares array used to sign.
Returns
1 if the signature share was generated by any key from the original key shares array. 0 otherwise.

Definition at line 9 of file algorithms_verify_signature.c.