diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-18 12:40:47 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-18 12:44:11 +0100 |
| commit | 81b38e86e4e073aa3aa590cbea39852972242a41 (patch) | |
| tree | 929074d99422f094ee9d02a99ab244578d57b4ca | |
| parent | 6ae607cc84b671810fca9c24b1c131ca12d922e7 (diff) | |
| download | cmix-81b38e86e4e073aa3aa590cbea39852972242a41.tar.gz cmix-81b38e86e4e073aa3aa590cbea39852972242a41.tar.bz2 cmix-81b38e86e4e073aa3aa590cbea39852972242a41.zip | |
Adds api call to convert public key to an (string) id
| -rw-r--r-- | client/cmixclient.cpp | 8 | ||||
| -rw-r--r-- | libcmix-crypto/api.h | 6 | ||||
| -rw-r--r-- | libcmix-crypto/elgamal/elgamal.c | 1 | ||||
| -rw-r--r-- | libcmix-crypto/elgamal/elgamal.h | 2 | ||||
| -rw-r--r-- | libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c | 13 | ||||
| -rw-r--r-- | libcmix/cmix.c | 19 | ||||
| -rw-r--r-- | libcmix/cmix.h | 2 |
7 files changed, 50 insertions, 1 deletions
diff --git a/client/cmixclient.cpp b/client/cmixclient.cpp index e3b33b6..636398f 100644 --- a/client/cmixclient.cpp +++ b/client/cmixclient.cpp @@ -40,7 +40,13 @@ void CMixClient::initialize_connections() { for(size_t i = 0; i < nr_nodes; ++i) { auto handler = [this, i]() { cmix_proto::ImAClient imaclient; - imaclient.set_id("A"); + + char* id; + get_pub_key_hash(&cmix_ctx, &id); + + imaclient.set_id(id); + free(id); + BOOST_LOG_TRIVIAL(trace) << "sending imaclient to node: " << i; network_connections.at(i).async_send(imaclient); network_connections.at(i).async_receive([i, this](cmix_proto::CMixMessage message) { diff --git a/libcmix-crypto/api.h b/libcmix-crypto/api.h index 98c81a1..d52ab95 100644 --- a/libcmix-crypto/api.h +++ b/libcmix-crypto/api.h @@ -61,6 +61,11 @@ typedef void(*BufferDeleter)(void*); typedef GroupElement(*ArrayToElement)(char const*, size_t size, bool); /*! + * + */ +typedef void(*PubKeyHashGetter)(char** buffer, size_t* len, GroupElement const pub); + +/*! * \brief PublicShareAdder typedef */ typedef void(*PublicShareAdder)(GroupElement*, char const*, size_t, GroupElement); @@ -115,6 +120,7 @@ struct Api { ElementToArray element_to_array; ///< Get the array representation of a public key BufferDeleter free_buffer; ///< frees library allocated buffers. ArrayToElement array_to_element; ///< The the GroupElement representation of this array; + PubKeyHashGetter get_pub_key_hash; ///< Get the hash of the public key. GroupElementGetter get_group_element; ///< get group element GroupElementArraySizeGetter get_group_element_array_size; ///< Return the size required to store a groupelement in an array; GroupElementDeleter free_group_element; ///< frees a base type of the cryptolibrary. diff --git a/libcmix-crypto/elgamal/elgamal.c b/libcmix-crypto/elgamal/elgamal.c index 1525618..7eea0f3 100644 --- a/libcmix-crypto/elgamal/elgamal.c +++ b/libcmix-crypto/elgamal/elgamal.c @@ -10,6 +10,7 @@ struct Api get_elgamal_implementation() .element_to_array = elgamal_element_to_array, .free_buffer = elgamal_free_buffer, .array_to_element = elgamal_array_to_element, + .get_pub_key_hash = elgamal_get_pub_key_hash, .get_group_element = elgamal_get_group_element, .get_group_element_array_size = elgamal_get_group_element_array_size, .free_group_element = elgamal_delete_group_element, diff --git a/libcmix-crypto/elgamal/elgamal.h b/libcmix-crypto/elgamal/elgamal.h index 1fcb044..1054e3e 100644 --- a/libcmix-crypto/elgamal/elgamal.h +++ b/libcmix-crypto/elgamal/elgamal.h @@ -22,6 +22,8 @@ extern BufferDeleter elgamal_free_buffer; extern ArrayToElement elgamal_array_to_element; +extern PubKeyHashGetter elgamal_get_pub_key_hash; + extern GroupElementGetter elgamal_get_group_element; extern GroupElementDeleter elgamal_delete_group_element; diff --git a/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c b/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c index 2f48a9e..6a03fb1 100644 --- a/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c +++ b/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c @@ -129,6 +129,18 @@ void* gcrypt_elgamal_array_to_element(char const* buffer, size_t len, bool secur return mpi; } +void gcrypt_elgamal_get_pub_key_hash(char** buffer, size_t* len, GroupElement const pub) { + gcry_sexp_t pubkey; + gcry_error_t error; + size_t err_off; + + error = gcry_sexp_build(&pubkey, &err_off, "(public-key (elg (p %M) (g %M) (y %M)))", p, g, (gcry_mpi_t) pub); + check(error); + + *buffer = (char*) gcry_pk_get_keygrip(pubkey, NULL); + *len = 20; +} + void* gcrypt_elgamal_get_group_element(bool secure) { size_t parse_error_offset; gcry_error_t error; @@ -284,6 +296,7 @@ KeyPairDeleter elgamal_delete_keypair = &gcrypt_elgamal_delete_keypair; ElementToArray elgamal_element_to_array = &gcrypt_elgamal_element_to_array; BufferDeleter elgamal_free_buffer = &gcrypt_elgamal_free_buffer; ArrayToElement elgamal_array_to_element = &gcrypt_elgamal_array_to_element; +PubKeyHashGetter elgamal_get_pub_key_hash = &gcrypt_elgamal_get_pub_key_hash; GroupElementGetter elgamal_get_group_element = &gcrypt_elgamal_get_group_element; GroupElementDeleter elgamal_delete_group_element = &gcrypt_elgamal_delete_group_element; KeyExchangeValueGetter elgamal_get_key_exchange_value = &gcrypt_elgamal_get_key_exchange_value; diff --git a/libcmix/cmix.c b/libcmix/cmix.c index 9db4dbb..f6eb2e8 100644 --- a/libcmix/cmix.c +++ b/libcmix/cmix.c @@ -3,6 +3,7 @@ #include <string.h> #include <stdlib.h> +#include <stdio.h> enum cmix_error permutation(struct CMixBuffer b) { return no_error; @@ -336,3 +337,21 @@ enum cmix_error remove_r_and_s(struct CMixContext const* ctx, char* out_buffer, ctx->api.free_group_element(inv_pirs); ctx->api.free_group_element(mult); } + +enum cmix_error get_pub_key_hash(struct CMixContext const* ctx, char** buffer) +{ + char* buffer2; + size_t len; + ctx->api.get_pub_key_hash(&buffer2, &len, ctx->keypair.pub); + + size_t hex_len = len*2+1; + *buffer = (char*) calloc(hex_len, sizeof(char)); + + for(size_t i = 0; i < len; i++) { + sprintf(&(*buffer)[i*2],"%hhX",buffer2[i]); + } + + ctx->api.free_buffer(buffer2); + + return no_error; +} diff --git a/libcmix/cmix.h b/libcmix/cmix.h index ba0b826..89a6ad3 100644 --- a/libcmix/cmix.h +++ b/libcmix/cmix.h @@ -94,6 +94,8 @@ enum cmix_error get_public_key(struct CMixContext const* ctx, char* buffer); enum cmix_error add_public_share(struct CMixContext const* ctx, char* buffer, char const* share); +enum cmix_error get_pub_key_hash(struct CMixContext const* ctx, char** buffer); + enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants); enum cmix_error initialize_mix_randomness(struct CMixContext* ctx); |
