aboutsummaryrefslogtreecommitdiff
path: root/libcmix
diff options
context:
space:
mode:
Diffstat (limited to 'libcmix')
-rw-r--r--libcmix/cmix.c41
-rw-r--r--libcmix/cmix.h13
2 files changed, 45 insertions, 9 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);
diff --git a/libcmix/cmix.h b/libcmix/cmix.h
index 433c3bc..7442369 100644
--- a/libcmix/cmix.h
+++ b/libcmix/cmix.h
@@ -78,6 +78,7 @@ struct CMixContext {
GroupElement* s;
unsigned int* permutation;
GroupElement* pirs;
+ GroupElement* messages;
};
struct CMixContext initialize_cmix_context(struct Api api);
@@ -94,6 +95,8 @@ enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants);
enum cmix_error initialize_mix_randomness(struct CMixContext* ctx);
+enum cmix_error generate_random_message(struct CMixContext* ctx, size_t index);
+
size_t get_group_element_array_size(struct CMixContext const* ctx);
enum cmix_error set_network_key(struct CMixContext* ctx, char const* buffer, size_t len);
@@ -104,9 +107,15 @@ enum cmix_error encrypt_r_and_multiply(struct CMixContext const* ctx, char* rand
enum cmix_error multiply_s(struct CMixContext const* ctx, char* r_out_buffer, char* m_out_buffer, char const* r_in_buffer, char const* m_in_buffer, size_t index);
-enum cmix_error key_exchange(struct CMixContext const* ctx, GroupElement* shared_key, char* public_key_buffer, char* exhange_value_buffer, char const* pubkey, char const* value);
+enum cmix_error get_key_exchange_value(struct CMixContext const* ctx, char* buffer, GroupElement priv_element);
+
+enum cmix_error key_exchange_init(struct CMixContext const* ctx, char* pubkey_buffer, char* value_buffer, GroupElement* secret_value);
+
+enum cmix_error key_exchange_responder(struct CMixContext const* ctx, GroupElement* shared_key, char* public_key_buffer, char* exhange_value_buffer, char const* pubkey, char const* value);
+
+enum cmix_error key_exchange_initiator(struct CMixContext const* ctx, GroupElement* shared_key, char const* pubkey, char const* value, GroupElement priv_el);
-enum cmix_error post_process(struct CMixContext* ctx, char const* r_epirs, char const* m_epirs, size_t index);
+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);
#ifdef __cplusplus
} // extern "C"