diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-07 12:53:59 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-07 12:53:59 +0100 |
| commit | 46f22621759d388f7cef4bf0d2ac03667a5d611e (patch) | |
| tree | b26cd49fe2552680eb16d9008695c8f56e757ded /libcmix/cmix.c | |
| parent | 7e21069bea9e8e6276591eee98f22cb07d67392d (diff) | |
| download | cmix-46f22621759d388f7cef4bf0d2ac03667a5d611e.tar.gz cmix-46f22621759d388f7cef4bf0d2ac03667a5d611e.tar.bz2 cmix-46f22621759d388f7cef4bf0d2ac03667a5d611e.zip | |
prepares the api for sending and mixing messages in the realtime phase.
Diffstat (limited to 'libcmix/cmix.c')
| -rw-r--r-- | libcmix/cmix.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/libcmix/cmix.c b/libcmix/cmix.c index 28f56db..582fe70 100644 --- a/libcmix/cmix.c +++ b/libcmix/cmix.c @@ -45,7 +45,8 @@ struct CMixContext initialize_cmix_context(struct Api api) { .r = NULL, .s = NULL, .permutation = NULL, - .pirs = NULL + .pirs = NULL, + .messages = NULL }; } @@ -54,17 +55,20 @@ void release_mix(struct CMixContext* ctx) { ctx->api.free_group_element(ctx->r[i]); ctx->api.free_group_element(ctx->s[i]); ctx->api.free_group_element(ctx->pirs[i]); + ctx->api.free_group_element(ctx->messages[i]); } free(ctx->r); free(ctx->s); free(ctx->permutation); free(ctx->pirs); + free(ctx->messages); } void deinitialize(struct CMixContext* ctx) { ctx->api.free_keypair(&ctx->keypair); release_mix(ctx); + ctx->api.deinitialize(); } void element_to_buffer(struct CMixContext const* ctx, char* out_buffer, GroupElement element) { @@ -106,7 +110,8 @@ enum cmix_error alloc_mix(struct CMixContext* ctx) { ctx->s = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); ctx->permutation = (unsigned int*) calloc(ctx->nr_participants, sizeof(unsigned int)); ctx->pirs = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); - if(!ctx->r || !ctx->s || !ctx->permutation || !ctx->pirs) { + ctx->pirs = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); + if(!ctx->r || !ctx->s || !ctx->permutation || !ctx->pirs || !ctx->messages) { return out_of_memory; } return no_error; @@ -127,6 +132,11 @@ enum cmix_error initialize_mix_randomness(struct CMixContext* ctx) { return no_error; } +enum cmix_error generate_random_message(struct CMixContext* ctx, size_t index) { + ctx->messages[index] = ctx->api.get_group_element(true); + return no_error; +} + size_t get_group_element_array_size(struct CMixContext const* ctx) { return ctx->api.get_group_element_array_size(); } @@ -200,12 +210,20 @@ enum cmix_error multiply_s(struct CMixContext const* ctx, char* r_out_buffer, ch return no_error; } -enum cmix_error key_exchange(struct CMixContext const* ctx, GroupElement* shared_key, char* public_key_buffer, char* exchange_value_buffer, char const* pubkey, char const* value) { +enum cmix_error key_exchange_init(struct CMixContext const* ctx, char* pubkey_buffer, char* value_buffer, GroupElement* priv_el) { + *priv_el = ctx->api.get_group_element(true); + GroupElement value = ctx->api.get_key_exchange_value(priv_el); + + get_public_key(ctx, pubkey_buffer); + element_to_buffer(ctx, value_buffer, value); + return no_error; +} + +enum cmix_error key_exchange_responder(struct CMixContext const* ctx, GroupElement* shared_key, char* public_key_buffer, char* exchange_value_buffer, char const* pubkey, char const* value) { GroupElement priv_el = ctx->api.get_group_element(true); GroupElement ex_val = ctx->api.get_key_exchange_value(priv_el); size_t el_len = get_group_element_array_size(ctx); - *shared_key = ctx->api.derive_shared_key(ctx->keypair, (unsigned char*)pubkey, el_len, (unsigned char*)value, el_len, priv_el, true); element_to_buffer(ctx, public_key_buffer, ctx->keypair.pub); @@ -217,15 +235,24 @@ enum cmix_error key_exchange(struct CMixContext const* ctx, GroupElement* shared return no_error; } -enum cmix_error post_process(struct CMixContext* ctx, char const* r_epirs, char const* m_epirs, size_t index) { - GroupElement x = ctx->api.array_to_element(r_epirs, get_group_element_array_size(ctx), true); +enum cmix_error key_exchange_initiator(struct CMixContext const* ctx, GroupElement* shared_key, char const* pubkey, char const* value, GroupElement priv_el) { + size_t el_len = get_group_element_array_size(ctx); + *shared_key = ctx->api.derive_shared_key(ctx->keypair, (unsigned char*)pubkey, el_len, (unsigned char*)value, el_len, priv_el, false); + return no_error; +} + +enum cmix_error post_process(struct CMixContext* ctx, char* r_out, char* m_out, char const* r_epirs, char const* m_epirs, size_t index) { + GroupElement x = ctx->api.array_to_element(r_epirs, get_group_element_array_size(ctx), true); GroupElement D = ctx->api.get_decryption_share(x, ctx->keypair.sec); + element_to_buffer(ctx, r_out, D); GroupElement msg = ctx->api.array_to_element(m_epirs, get_group_element_array_size(ctx), true); GroupElement pirs = ctx->api.multiply(D, msg, true); + element_to_buffer(ctx, m_out, pirs); + + ctx->pirs = pirs; // this is not always usable as only the last node will be able to use this effectively, but we store it anyways. - ctx->pirs[index] = pirs; ctx->api.free_group_element(x); ctx->api.free_group_element(D); ctx->api.free_group_element(msg); |
