aboutsummaryrefslogtreecommitdiff
path: root/libcmix
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-11-21 15:22:48 +0100
committerDennis Brentjes <d.brentjes@gmail.com>2016-11-21 15:22:48 +0100
commit37315f877ef27d0f8585389f0c83cd00a31577c1 (patch)
treecaead8a996811c154859d97ae3c5c946ae8da4b6 /libcmix
parente4cf0d04c4afff98603df440d12a4a19b3717a34 (diff)
downloadcmix-37315f877ef27d0f8585389f0c83cd00a31577c1.tar.gz
cmix-37315f877ef27d0f8585389f0c83cd00a31577c1.tar.bz2
cmix-37315f877ef27d0f8585389f0c83cd00a31577c1.zip
Reworked server and client to do one mix and shutdown.
This is done as cleanly as possible to track down any memory leaks. unfortunately there is still one async operation running on the nodes. when there should be none. So the nodes are still forced to stop with a. io_service.stop().
Diffstat (limited to 'libcmix')
-rw-r--r--libcmix/cmix.c36
-rw-r--r--libcmix/cmix.h2
2 files changed, 26 insertions, 12 deletions
diff --git a/libcmix/cmix.c b/libcmix/cmix.c
index d21dab5..c60f441 100644
--- a/libcmix/cmix.c
+++ b/libcmix/cmix.c
@@ -24,6 +24,17 @@ struct CMixContext initialize_cmix_context(struct Api api) {
};
}
+enum cmix_error alloc_mix(struct CMixContext* ctx) {
+ ctx->r = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement));
+ 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) {
+ return out_of_memory;
+ }
+ return no_error;
+}
+
void release_mix(struct CMixContext* ctx) {
for(size_t i = 0; i < ctx->nr_participants; ++i) {
ctx->api.free_group_element(ctx->r[i]);
@@ -31,9 +42,18 @@ void release_mix(struct CMixContext* ctx) {
ctx->api.free_group_element(ctx->pirs[i]);
}
free(ctx->r);
+ ctx->r = NULL;
+
free(ctx->s);
+ ctx->s = NULL;
+
free(ctx->permutation);
+ ctx->permutation = NULL;
+
free(ctx->pirs);
+ ctx->pirs = NULL;
+
+ ctx->nr_participants = 0;
}
void deinitialize(struct CMixContext* ctx)
@@ -77,17 +97,6 @@ enum cmix_error add_public_share(struct CMixContext const* ctx, char* buffer, ch
ctx->api.free_group_element(el);
}
-enum cmix_error alloc_mix(struct CMixContext* ctx) {
- ctx->r = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement));
- 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) {
- return out_of_memory;
- }
- return no_error;
-}
-
enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants) {
release_mix(ctx);
ctx->nr_participants = nr_participants;
@@ -95,7 +104,10 @@ enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants) {
}
enum cmix_error generate_permutation(struct CMixContext* ctx) {
- ctx->permutation = (unsigned int*) calloc(ctx->nr_participants, sizeof(unsigned int));
+ if (ctx->nr_participants == 0) {
+ return no_error;
+ }
+
for(unsigned int i = 0; i < ctx->nr_participants; ++i) {
ctx->permutation[i] = i;
}
diff --git a/libcmix/cmix.h b/libcmix/cmix.h
index 057fd60..8e6f598 100644
--- a/libcmix/cmix.h
+++ b/libcmix/cmix.h
@@ -73,6 +73,8 @@ 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);
+void release_mix(struct CMixContext* ctx);
+
enum cmix_error initialize_mix_randomness(struct CMixContext* ctx);
enum cmix_error generate_random_message(struct CMixContext* ctx, char* buffer);