aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac2
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/zklaim/Makefile.am47
-rw-r--r--src/zklaim/main.c237
-rw-r--r--src/zklaim/zklaim.c79
5 files changed, 117 insertions, 249 deletions
diff --git a/configure.ac b/configure.ac
index fb9012f33..0162f39f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -447,7 +447,7 @@ AC_CHECK_LIB(ogg, ogg_stream_flush_fill,
447 447
448# check for zklaims 448# check for zklaims
449zklaim=0 449zklaim=0
450AC_CHECK_HEADER([zklaim.h],zklaim=1) 450AC_CHECK_HEADER([zklaim/zklaim.h],zklaim=1)
451AM_CONDITIONAL(HAVE_ZKLAIM, [test "$zklaim" = 1]) 451AM_CONDITIONAL(HAVE_ZKLAIM, [test "$zklaim" = 1])
452if test "x$zklaim" = x1 452if test "x$zklaim" = x1
453then 453then
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d710eaba8..7846872ec 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -508,6 +508,7 @@ src/vpn/gnunet-service-vpn.c
508src/vpn/gnunet-vpn.c 508src/vpn/gnunet-vpn.c
509src/vpn/vpn_api.c 509src/vpn/vpn_api.c
510src/zklaim/main.c 510src/zklaim/main.c
511src/zklaim/zklaim.c
511src/zonemaster/gnunet-service-zonemaster.c 512src/zonemaster/gnunet-service-zonemaster.c
512src/fs/fs_api.h 513src/fs/fs_api.h
513src/include/gnunet_common.h 514src/include/gnunet_common.h
diff --git a/src/zklaim/Makefile.am b/src/zklaim/Makefile.am
index b2876d274..c7ca595b8 100644
--- a/src/zklaim/Makefile.am
+++ b/src/zklaim/Makefile.am
@@ -1,22 +1,47 @@
1# This Makefile.am is in the public domain 1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include 2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3 3
4if MINGW 4plugindir = $(libdir)/gnunet
5 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols 5
6endif 6libexecdir= $(pkglibdir)/libexec/
7
8pkgcfgdir= $(pkgdatadir)/config.d/
7 9
8if USE_COVERAGE 10if USE_COVERAGE
9 AM_CFLAGS = --coverage -O0 11 AM_CFLAGS = --coverage -O0
10 XLIB = -lgcov 12 XLIB = -lgcov
11endif 13endif
12 14
13bin_PROGRAMS = \
14 gnunet-zklaim
15 15
16gnunet_zklaim_SOURCES = \ 16libgnunetzklaim_la_SOURCES = zklaim.c
17 main.c 17libgnunetzklaim_la_LIBADD = \
18gnunet_zklaim_LDFLAGS = -rdynamic 18 $(GCLIBADD)\
19gnunet_zklaim_LDADD = \ 19 $(LIBGCRYPT_LIBS) \
20 -lzklaim \ 20 -lzklaim \
21 -lgcrypt 21 -lgcrypt \
22 -lgmp \
23 -lgmpxx \
24 -lcrypto \
25 -lprocps \
26 -lstdc++ \
27 -lm
28libgnunetzklaim_la_LDFLAGS = \
29 $(GN_LIB_LDFLAGS) \
30 -version-info 1:0:0
31
32lib_LTLIBRARIES = libgnunetzklaim.la
33
34if ENABLE_TEST_RUN
35AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
36TESTS = $(check_PROGRAMS)
37endif
38
39#check_PROGRAMS = test_cpabe
22 40
41#test_cpabe_SOURCES = \
42# test_cpabe.c
43#test_cpabe_LDADD = \
44# libgnunetabe.la \
45# $(top_builddir)/src/util/libgnunetutil.la
46#check_PROGRAMS += \
47# test_cpabe
diff --git a/src/zklaim/main.c b/src/zklaim/main.c
deleted file mode 100644
index 3fe823ba1..000000000
--- a/src/zklaim/main.c
+++ /dev/null
@@ -1,237 +0,0 @@
1/**
2 * Test File for zklaim c implementation
3 */
4
5#include "zklaim.h"
6#include "zklaim_ecc.h"
7#include "zklaim_hash.h"
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include <gcrypt.h>
12
13// to boost up valgrind
14int worker() {
15 gcry_sexp_t priv, pub;
16 zklaim_gen_pk(&priv);
17 zklaim_get_pub(priv, &pub);
18 unsigned char *pubbuf;
19 size_t publen;
20 zklaim_pub2buf(pub, &pubbuf, &publen);
21
22 printf("===========================================================================\n");
23 printf("===========================================================================\n");
24 printf("============================== ISSUER =====================================\n");
25 printf("===========================================================================\n");
26 printf("===========================================================================\n");
27 //zklaim_ctx* ctx = zklaim_context_init();
28 //zklaim_proving_key* pk = zklaim_proving_key_get(ctx);
29 /*
30 * - 1 -
31 * initialize data structures
32 */
33 printf("[ISSUER] initializing context\n");
34 zklaim_ctx *ctx = zklaim_context_new();
35
36 if (sizeof(ctx->pub_key) != publen) {
37 printf("size mismatch!");
38 return 1;
39 }
40
41 // TODO: there should be a zklaim method for this
42 memcpy(ctx->pub_key, pubbuf, sizeof(ctx->pub_key));
43 free(pubbuf);
44
45 //print_sexp(pub);
46
47 /*
48 * - 2 -
49 * setup the first payload
50 */
51 printf("[ISSUER] Setting up payloads..\n");
52 zklaim_payload pl, pl2;
53 memset(&pl, 0, sizeof(zklaim_payload));
54 pl.data0_ref = 18;
55 pl.data0_op = (enum zklaim_op) (zklaim_greater | zklaim_eq);
56 pl.data1_ref = 1;
57 pl.data1_op = zklaim_eq;
58 pl.data2_ref = 2;
59 pl.data2_op = zklaim_eq;
60 pl.data3_ref = 3;
61 pl.data3_op = zklaim_eq;
62 pl.data4_ref = 600;
63 pl.data4_op = zklaim_less;
64 pl.priv = 0;
65
66 memset(&pl2, 0, sizeof(zklaim_payload));
67 pl2.data0_ref = 0;
68 pl2.data0_op = zklaim_noop;
69 pl2.data1_ref = 0;
70 pl2.data1_op = zklaim_noop;
71 pl2.data2_ref = 0;
72 pl2.data2_op = zklaim_noop;
73 pl2.data3_ref = 0;
74 pl2.data3_op = zklaim_noop;
75 pl2.data4_ref = 9223372036854775807;
76 pl2.data4_op = zklaim_less_or_eq;
77 pl2.priv = 0;
78
79 // fill in the values
80 zklaim_set_attr(&pl, 23, 0);
81 zklaim_set_attr(&pl, 1, 1);
82 zklaim_set_attr(&pl, 2, 2);
83 zklaim_set_attr(&pl, 3, 3);
84 zklaim_set_attr(&pl, 599, 4);
85
86 zklaim_set_attr(&pl2, 0, 0);
87 zklaim_set_attr(&pl2, 0, 1);
88 zklaim_set_attr(&pl2, 0, 2);
89 zklaim_set_attr(&pl2, 0, 3);
90 zklaim_set_attr(&pl2, 9223372036854775807, 4);
91
92 /*
93 * - 3 -
94 * add payload to context
95 */
96 printf("[ISSUER] adding payloads to context\n");
97 zklaim_add_pl(ctx, pl);
98 //zklaim_add_pl(ctx, pl2);
99 //zklaim_add_pl(ctx, pl2);
100 zklaim_hash_ctx(ctx);
101
102 printf("[ISSUER] performing trusted setup in order to generate keys\n");
103 printf("-> trusted setup result: %s\n", (zklaim_trusted_setup(ctx) ? "failed" : "passed"));
104
105 //unsigned char* buf;
106 //size_t vksize = zklaim_verification_key_serialize(ctx, &buf);
107 //printf("serialized vk size: %zuB\n", vksize);
108
109 // write key to disk
110 //FILE* f = fopen("/tmp/vk1", "w");
111 //fwrite(buf, vksize, 1, f);
112 //fclose(f);
113
114 //zklaim_verification_key_deserialize(ctx2, buf, vksize);
115
116 //free(buf);
117
118 //size_t pksize = zklaim_proving_key_serialize(ctx, &buf);
119 //printf("serialized pk size: %.2fMB\n", ((float) pksize)/1000/1000);
120
121 //zklaim_proving_key_deserialize(ctx, buf, pksize);
122
123 //zklaim_print(ctx);
124
125 //zklaim_ctx_sign(ctx, priv);
126
127
128 printf("-> signing context: %s\n", zklaim_ctx_sign(ctx, priv) ? "failed" : "passed");
129
130 unsigned char* ctx_issuer;
131
132 printf("\n[ISSUER] serializing context\n");
133 size_t len = zklaim_ctx_serialize(ctx, &ctx_issuer);
134
135 /*
136 * - 4 -
137 * generate proof
138 */
139
140 //printf("\n-> signing context: %s\n", zklaim_ctx_sign(ctx, priv) ? "failed" : "passed");
141
142 //unsigned char* proof;
143 //size_t proof_size = zklaim_proof_serialize(ctx, &proof);
144 //printf("serialized proof size: %zuB\n", proof_size);
145
146 //zklaim_proof* zkproof_imported;
147
148 //zklaim_proof_deserialize(ctx, proof, proof_size);
149
150 printf("===========================================================================\n");
151 printf("===========================================================================\n");
152 printf("============================== PROVER =====================================\n");
153 printf("===========================================================================\n");
154 printf("===========================================================================\n");
155
156
157 zklaim_ctx* ctx_prover = zklaim_context_new();
158 printf("\n[PROVER] deserializing context\n");
159 printf("-> deserialisation status: %s\n\n", zklaim_ctx_deserialize(ctx_prover, ctx_issuer, len) ? "failed" : "passed");
160
161 zklaim_print(ctx_prover);
162
163 ctx_prover->pk = ctx->pk;
164
165 int res = zklaim_ctx_verify(ctx_prover);
166 printf("[PROVER] verification result: %d %s\n", res, (res ? "failed" : "passed"));
167 printf(" ^--- failure with code 3 (ZKLAIM_INVALID_PROOF) is ok for the prover, as signature passes, but (non-existing) proof fails\n\n");
168
169 printf("[PROVER] resetting operations and reference values to create taylored proof\n");
170 printf("[PROVER] generating proof\n");
171
172 ctx_prover->pk = (unsigned char*) calloc(1, ctx->pk_size);
173 ctx_prover->pk_size = ctx->pk_size;
174 memcpy(ctx_prover->pk, ctx->pk, ctx_prover->pk_size);
175
176 // set custom prover reference values here:
177 ctx_prover->pl_ctx_head->pl.data0_ref = 20;
178 //ctx_prover->pl_ctx_head->pl.data0_op = zklaim_less;
179 ctx_prover->pl_ctx_head->pl.data4_ref = 0;
180 ctx_prover->pl_ctx_head->pl.data4_op = zklaim_noop;
181
182 ctx_prover->pl_ctx_head->pl.data1_ref = 0;
183 ctx_prover->pl_ctx_head->pl.data1_op = zklaim_noop;
184
185 ctx_prover->pl_ctx_head->pl.data2_ref = 0;
186 ctx_prover->pl_ctx_head->pl.data2_op = zklaim_noop;
187
188 ctx_prover->pl_ctx_head->pl.data3_ref = 0;
189 ctx_prover->pl_ctx_head->pl.data3_op = zklaim_noop;
190
191 zklaim_print(ctx_prover);
192
193 printf("-> proof generation status: %s\n\n", (zklaim_proof_generate(ctx_prover) ? "failed" : "passed"));
194
195
196 printf("[PROVER] blinding attributes\n");
197 zklaim_clear_pres(ctx_prover);
198
199
200 printf("[PROVER] serializing context\n\n");
201
202 unsigned char *ctx_prover_buf;
203 len = zklaim_ctx_serialize(ctx_prover, &ctx_prover_buf);
204
205 /*
206 * - 5 -
207 * verify proof
208 */
209 printf("===========================================================================\n");
210 printf("===========================================================================\n");
211 printf("============================= VERIFIER ====================================\n");
212 printf("===========================================================================\n");
213 printf("===========================================================================\n");
214
215 zklaim_ctx* ctx_verifier = zklaim_context_new();
216 printf("\n[VERIFIER] deserializing context\n");
217 printf("-> deserialisation status: %s\n\n", zklaim_ctx_deserialize(ctx_verifier, ctx_prover_buf, len) ? "failed" : "passed");
218 printf("[VERIFIER] verifying proof and context\n");
219 res = zklaim_ctx_verify(ctx_verifier);
220 printf("verification result: %d %s\n\n", res, (res ? "failed" : "passed"));
221
222 zklaim_print(ctx_verifier);
223
224 free(ctx_prover_buf);
225 free(ctx_issuer);
226 zklaim_ctx_free(ctx);
227 gcry_sexp_release(priv);
228 gcry_sexp_release(pub);
229 zklaim_ctx_free(ctx_prover);
230 zklaim_ctx_free(ctx_verifier);
231
232 return ZKLAIM_OK;
233}
234
235int main() {
236 return worker();
237}
diff --git a/src/zklaim/zklaim.c b/src/zklaim/zklaim.c
new file mode 100644
index 000000000..a53c193d1
--- /dev/null
+++ b/src/zklaim/zklaim.c
@@ -0,0 +1,79 @@
1/*
2 This file is part of GNUnet. Copyright (C) 2001-2018 Christian Grothoff
3 (and other contributing authors)
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20/**
21 * @file abe/abe.c
22 * @brief functions for Attribute-Based Encryption
23 * @author Martin Schanzenbach
24 */
25
26
27#include "platform.h"
28#include <zklaim/zklaim.h>
29#include "gnunet_crypto_lib.h"
30
31struct GNUNET_ZKLAIM_Context
32{
33 zklaim_ctx* ctx;
34 gcry_sexp_t priv;
35 gcry_sexp_t pub;
36};
37
38struct GNUNET_ZKLAIM_Payload
39{
40 zklaim_payload pl;
41};
42
43struct GNUNET_ZKLAIM_Context*
44GNUNET_ZKLAIM_new ()
45{
46 struct GNUNET_ZKLAIM_Context *ctx;
47 unsigned char *pubbuf;
48 size_t publen;
49
50 ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context);
51 ctx->ctx = zklaim_context_new();
52 zklaim_pub2buf(ctx->pub, &pubbuf, &publen);
53 zklaim_gen_pk(&ctx->priv);
54 zklaim_get_pub(ctx->priv, &ctx->pub);
55 if (sizeof(ctx->ctx->pub_key) != publen) {
56 printf("size mismatch!");
57 return NULL;
58 }
59
60 memcpy(ctx->ctx->pub_key, pubbuf, sizeof(ctx->ctx->pub_key));
61 free(pubbuf);
62 return ctx;
63}
64
65int
66GNUNET_ZKLAIM_add_payload (struct GNUNET_ZKLAIM_Context *ctx,
67 struct GNUNET_ZKLAIM_Payload *pl)
68{
69 zklaim_add_pl (ctx->ctx, pl->pl);
70 return GNUNET_OK;
71}
72
73int
74GNUNET_ZKLAIM_finalize (struct GNUNET_ZKLAIM_Context *ctx)
75{
76 zklaim_hash_ctx (ctx->ctx);
77 zklaim_ctx_sign (ctx->ctx, ctx->priv);
78 return 1;
79}