aboutsummaryrefslogtreecommitdiff
path: root/libcmix/cmix.c
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-11-18 12:47:35 +0100
committerDennis Brentjes <d.brentjes@gmail.com>2016-11-18 12:47:35 +0100
commit6d55dcba54ceaccc9d90ea7c2f1746524a6e81e3 (patch)
tree264bcf206535d41cdfec7c0a659c861ea0bd5f31 /libcmix/cmix.c
parentd9e011488b9d7af4683e6640216e78871a06a5ec (diff)
downloadcmix-6d55dcba54ceaccc9d90ea7c2f1746524a6e81e3.tar.gz
cmix-6d55dcba54ceaccc9d90ea7c2f1746524a6e81e3.tar.bz2
cmix-6d55dcba54ceaccc9d90ea7c2f1746524a6e81e3.zip
Made permutation a responsibility of cmix in the precomputation phase.
Diffstat (limited to 'libcmix/cmix.c')
-rw-r--r--libcmix/cmix.c61
1 files changed, 41 insertions, 20 deletions
diff --git a/libcmix/cmix.c b/libcmix/cmix.c
index f6eb2e8..68a638f 100644
--- a/libcmix/cmix.c
+++ b/libcmix/cmix.c
@@ -120,13 +120,31 @@ enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants) {
return alloc_mix(ctx);
}
+enum cmix_error generate_permutation(struct CMixContext* ctx) {
+ ctx->permutation = (unsigned int*) calloc(ctx->nr_participants, sizeof(unsigned int));
+ for(unsigned int i = 0; i < ctx->nr_participants; ++i) {
+ ctx->permutation[i] = i;
+ }
+
+ //Fisher-Yates shuffle
+ unsigned int temp = 0;
+ for(unsigned int i = ctx->nr_participants - 1; i > 0; --i) {
+ unsigned int rand = ctx->api.get_uniform_int(i+1);
+ temp = ctx->permutation[i];
+ ctx->permutation[i] = ctx->permutation[rand];
+ ctx->permutation[rand] = temp;
+ }
+
+ return no_error;
+}
+
enum cmix_error initialize_mix_randomness(struct CMixContext* ctx) {
for(size_t i = 0; i < ctx->nr_participants; ++i) {
ctx->r[i] = ctx->api.get_group_element(true);
ctx->s[i] = ctx->api.get_group_element(true);
- ctx->permutation[i] = i;
}
- return no_error;
+
+ return generate_permutation(ctx);
}
enum cmix_error generate_random_message(struct CMixContext* ctx, char* buffer) {
@@ -185,27 +203,30 @@ enum cmix_error encrypt_r_and_multiply(struct CMixContext const* ctx, char* rand
return no_error;
}
-enum cmix_error multiply_encrypted_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 permute_and_multiply_encrypted_s(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, char const** random_element, char const** message_element, size_t nr_elements) {
size_t el_size = get_group_element_array_size(ctx);
- GroupElement random_r = ctx->api.array_to_element(r_in_buffer, el_size, true);
- GroupElement message_r = ctx->api.array_to_element(m_in_buffer, el_size, true);
-
- GroupElement random_s;
- GroupElement message_s;
-
- ctx->api.encrypt(&random_s, &message_s, ctx->s[ctx->permutation[index]], ctx->network_key);
-
- GroupElement random_pirs = ctx->api.multiply(random_r, random_s, true);
- GroupElement message_pirs = ctx->api.multiply(message_r, message_s, true);
-
- element_to_buffer(ctx, r_out_buffer, random_pirs);
- element_to_buffer(ctx, m_out_buffer, message_pirs);
+ for(size_t i = 0; i < nr_elements; ++i) {
+ unsigned int new_pos = ctx->permutation[i];
+ GroupElement random_r = ctx->api.array_to_element(random_element[i], el_size, true);
+ GroupElement message_r = ctx->api.array_to_element(message_element[i], el_size, true);
- ctx->api.free_group_element(random_r);
- ctx->api.free_group_element(message_r);
- ctx->api.free_group_element(random_s);
- ctx->api.free_group_element(message_s);
+ GroupElement random_s;
+ GroupElement message_s;
+
+ ctx->api.encrypt(&random_s, &message_s, ctx->s[new_pos], ctx->network_key);
+
+ GroupElement random_pirs = ctx->api.multiply(random_r, random_s, true);
+ GroupElement message_pirs = ctx->api.multiply(message_r, message_s, true);
+
+ element_to_buffer(ctx, random_buffer[new_pos], random_pirs);
+ element_to_buffer(ctx, message_buffer[new_pos], message_pirs);
+
+ ctx->api.free_group_element(random_r);
+ ctx->api.free_group_element(message_r);
+ ctx->api.free_group_element(random_s);
+ ctx->api.free_group_element(message_s);
+ }
return no_error;
}