From d5201f6da99b0b983d13064b0014d0313aa91d8f Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Tue, 15 May 2018 19:15:19 +0200 Subject: start zklaim --- configure.ac | 11 +++ po/POTFILES.in | 1 + src/Makefile.am | 5 +- src/zklaim/Makefile.am | 31 +++++++ src/zklaim/main.c | 237 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 src/zklaim/Makefile.am create mode 100644 src/zklaim/main.c diff --git a/configure.ac b/configure.ac index 668ac7529..fb9012f33 100644 --- a/configure.ac +++ b/configure.ac @@ -445,6 +445,16 @@ AC_CHECK_LIB(ogg, ogg_stream_flush_fill, AM_CONDITIONAL(HAVE_OGG, false) ogg=0) +# check for zklaims +zklaim=0 +AC_CHECK_HEADER([zklaim.h],zklaim=1) +AM_CONDITIONAL(HAVE_ZKLAIM, [test "$zklaim" = 1]) +if test "x$zklaim" = x1 +then + AC_DEFINE([HAVE_ZKLAIM],[1],[Have zklaim library]) +else + AC_DEFINE([HAVE_ZKLAIM],[0],[Lacking zklaim library]) +fi PKG_CHECK_MODULES([GLIB], [glib-2.0], # check for pbc library @@ -1678,6 +1688,7 @@ src/zonemaster/Makefile src/zonemaster/zonemaster.conf src/rest/Makefile src/abe/Makefile +src/zklaim/Makefile src/identity-attribute/Makefile src/identity-provider/Makefile pkgconfig/Makefile diff --git a/po/POTFILES.in b/po/POTFILES.in index 50cf97613..d710eaba8 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -507,6 +507,7 @@ src/vpn/gnunet-helper-vpn.c src/vpn/gnunet-service-vpn.c src/vpn/gnunet-vpn.c src/vpn/vpn_api.c +src/zklaim/main.c src/zonemaster/gnunet-service-zonemaster.c src/fs/fs_api.h src/include/gnunet_common.h diff --git a/src/Makefile.am b/src/Makefile.am index d8d548706..61e96c75b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,10 @@ if HAVE_ABE abe \ credential \ identity-attribute \ - identity-provider + identity-provider +if HAVE_ZKLAIM + EXP_DIR += zklaim +endif endif if HAVE_JSON EXP_DIR += \ diff --git a/src/zklaim/Makefile.am b/src/zklaim/Makefile.am new file mode 100644 index 000000000..44f016f2b --- /dev/null +++ b/src/zklaim/Makefile.am @@ -0,0 +1,31 @@ +# This Makefile.am is in the public domain +AM_CPPFLAGS = -I$(top_srcdir)/src/include + +if MINGW + WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols +endif + +if USE_COVERAGE + AM_CFLAGS = --coverage -O0 + XLIB = -lgcov +endif + +bin_PROGRAMS = \ + gnunet-zklaim + +gnunet_zklaim_SOURCES = \ + main.c +gnunet_zklaim_LDFLAGS = -rdynamic +gnunet_zklaim_LDADD = \ + -lzklaim \ + -lgcrypt \ + -lsnark \ + -lff \ + -lgmp \ + -lgmpxx \ + -lcrypto \ + -lprocps \ + -lzm \ + -lstdc++ \ + -lm + diff --git a/src/zklaim/main.c b/src/zklaim/main.c new file mode 100644 index 000000000..3fe823ba1 --- /dev/null +++ b/src/zklaim/main.c @@ -0,0 +1,237 @@ +/** + * Test File for zklaim c implementation + */ + +#include "zklaim.h" +#include "zklaim_ecc.h" +#include "zklaim_hash.h" +#include +#include +#include +#include + +// to boost up valgrind +int worker() { + gcry_sexp_t priv, pub; + zklaim_gen_pk(&priv); + zklaim_get_pub(priv, &pub); + unsigned char *pubbuf; + size_t publen; + zklaim_pub2buf(pub, &pubbuf, &publen); + + printf("===========================================================================\n"); + printf("===========================================================================\n"); + printf("============================== ISSUER =====================================\n"); + printf("===========================================================================\n"); + printf("===========================================================================\n"); + //zklaim_ctx* ctx = zklaim_context_init(); + //zklaim_proving_key* pk = zklaim_proving_key_get(ctx); + /* + * - 1 - + * initialize data structures + */ + printf("[ISSUER] initializing context\n"); + zklaim_ctx *ctx = zklaim_context_new(); + + if (sizeof(ctx->pub_key) != publen) { + printf("size mismatch!"); + return 1; + } + + // TODO: there should be a zklaim method for this + memcpy(ctx->pub_key, pubbuf, sizeof(ctx->pub_key)); + free(pubbuf); + + //print_sexp(pub); + + /* + * - 2 - + * setup the first payload + */ + printf("[ISSUER] Setting up payloads..\n"); + zklaim_payload pl, pl2; + memset(&pl, 0, sizeof(zklaim_payload)); + pl.data0_ref = 18; + pl.data0_op = (enum zklaim_op) (zklaim_greater | zklaim_eq); + pl.data1_ref = 1; + pl.data1_op = zklaim_eq; + pl.data2_ref = 2; + pl.data2_op = zklaim_eq; + pl.data3_ref = 3; + pl.data3_op = zklaim_eq; + pl.data4_ref = 600; + pl.data4_op = zklaim_less; + pl.priv = 0; + + memset(&pl2, 0, sizeof(zklaim_payload)); + pl2.data0_ref = 0; + pl2.data0_op = zklaim_noop; + pl2.data1_ref = 0; + pl2.data1_op = zklaim_noop; + pl2.data2_ref = 0; + pl2.data2_op = zklaim_noop; + pl2.data3_ref = 0; + pl2.data3_op = zklaim_noop; + pl2.data4_ref = 9223372036854775807; + pl2.data4_op = zklaim_less_or_eq; + pl2.priv = 0; + + // fill in the values + zklaim_set_attr(&pl, 23, 0); + zklaim_set_attr(&pl, 1, 1); + zklaim_set_attr(&pl, 2, 2); + zklaim_set_attr(&pl, 3, 3); + zklaim_set_attr(&pl, 599, 4); + + zklaim_set_attr(&pl2, 0, 0); + zklaim_set_attr(&pl2, 0, 1); + zklaim_set_attr(&pl2, 0, 2); + zklaim_set_attr(&pl2, 0, 3); + zklaim_set_attr(&pl2, 9223372036854775807, 4); + + /* + * - 3 - + * add payload to context + */ + printf("[ISSUER] adding payloads to context\n"); + zklaim_add_pl(ctx, pl); + //zklaim_add_pl(ctx, pl2); + //zklaim_add_pl(ctx, pl2); + zklaim_hash_ctx(ctx); + + printf("[ISSUER] performing trusted setup in order to generate keys\n"); + printf("-> trusted setup result: %s\n", (zklaim_trusted_setup(ctx) ? "failed" : "passed")); + + //unsigned char* buf; + //size_t vksize = zklaim_verification_key_serialize(ctx, &buf); + //printf("serialized vk size: %zuB\n", vksize); + + // write key to disk + //FILE* f = fopen("/tmp/vk1", "w"); + //fwrite(buf, vksize, 1, f); + //fclose(f); + + //zklaim_verification_key_deserialize(ctx2, buf, vksize); + + //free(buf); + + //size_t pksize = zklaim_proving_key_serialize(ctx, &buf); + //printf("serialized pk size: %.2fMB\n", ((float) pksize)/1000/1000); + + //zklaim_proving_key_deserialize(ctx, buf, pksize); + + //zklaim_print(ctx); + + //zklaim_ctx_sign(ctx, priv); + + + printf("-> signing context: %s\n", zklaim_ctx_sign(ctx, priv) ? "failed" : "passed"); + + unsigned char* ctx_issuer; + + printf("\n[ISSUER] serializing context\n"); + size_t len = zklaim_ctx_serialize(ctx, &ctx_issuer); + + /* + * - 4 - + * generate proof + */ + + //printf("\n-> signing context: %s\n", zklaim_ctx_sign(ctx, priv) ? "failed" : "passed"); + + //unsigned char* proof; + //size_t proof_size = zklaim_proof_serialize(ctx, &proof); + //printf("serialized proof size: %zuB\n", proof_size); + + //zklaim_proof* zkproof_imported; + + //zklaim_proof_deserialize(ctx, proof, proof_size); + + printf("===========================================================================\n"); + printf("===========================================================================\n"); + printf("============================== PROVER =====================================\n"); + printf("===========================================================================\n"); + printf("===========================================================================\n"); + + + zklaim_ctx* ctx_prover = zklaim_context_new(); + printf("\n[PROVER] deserializing context\n"); + printf("-> deserialisation status: %s\n\n", zklaim_ctx_deserialize(ctx_prover, ctx_issuer, len) ? "failed" : "passed"); + + zklaim_print(ctx_prover); + + ctx_prover->pk = ctx->pk; + + int res = zklaim_ctx_verify(ctx_prover); + printf("[PROVER] verification result: %d %s\n", res, (res ? "failed" : "passed")); + printf(" ^--- failure with code 3 (ZKLAIM_INVALID_PROOF) is ok for the prover, as signature passes, but (non-existing) proof fails\n\n"); + + printf("[PROVER] resetting operations and reference values to create taylored proof\n"); + printf("[PROVER] generating proof\n"); + + ctx_prover->pk = (unsigned char*) calloc(1, ctx->pk_size); + ctx_prover->pk_size = ctx->pk_size; + memcpy(ctx_prover->pk, ctx->pk, ctx_prover->pk_size); + + // set custom prover reference values here: + ctx_prover->pl_ctx_head->pl.data0_ref = 20; + //ctx_prover->pl_ctx_head->pl.data0_op = zklaim_less; + ctx_prover->pl_ctx_head->pl.data4_ref = 0; + ctx_prover->pl_ctx_head->pl.data4_op = zklaim_noop; + + ctx_prover->pl_ctx_head->pl.data1_ref = 0; + ctx_prover->pl_ctx_head->pl.data1_op = zklaim_noop; + + ctx_prover->pl_ctx_head->pl.data2_ref = 0; + ctx_prover->pl_ctx_head->pl.data2_op = zklaim_noop; + + ctx_prover->pl_ctx_head->pl.data3_ref = 0; + ctx_prover->pl_ctx_head->pl.data3_op = zklaim_noop; + + zklaim_print(ctx_prover); + + printf("-> proof generation status: %s\n\n", (zklaim_proof_generate(ctx_prover) ? "failed" : "passed")); + + + printf("[PROVER] blinding attributes\n"); + zklaim_clear_pres(ctx_prover); + + + printf("[PROVER] serializing context\n\n"); + + unsigned char *ctx_prover_buf; + len = zklaim_ctx_serialize(ctx_prover, &ctx_prover_buf); + + /* + * - 5 - + * verify proof + */ + printf("===========================================================================\n"); + printf("===========================================================================\n"); + printf("============================= VERIFIER ====================================\n"); + printf("===========================================================================\n"); + printf("===========================================================================\n"); + + zklaim_ctx* ctx_verifier = zklaim_context_new(); + printf("\n[VERIFIER] deserializing context\n"); + printf("-> deserialisation status: %s\n\n", zklaim_ctx_deserialize(ctx_verifier, ctx_prover_buf, len) ? "failed" : "passed"); + printf("[VERIFIER] verifying proof and context\n"); + res = zklaim_ctx_verify(ctx_verifier); + printf("verification result: %d %s\n\n", res, (res ? "failed" : "passed")); + + zklaim_print(ctx_verifier); + + free(ctx_prover_buf); + free(ctx_issuer); + zklaim_ctx_free(ctx); + gcry_sexp_release(priv); + gcry_sexp_release(pub); + zklaim_ctx_free(ctx_prover); + zklaim_ctx_free(ctx_verifier); + + return ZKLAIM_OK; +} + +int main() { + return worker(); +} -- cgit v1.2.3 From 880320a15023f951568bdfaff3c2f5291408cdf8 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Fri, 18 May 2018 21:07:19 +0200 Subject: fix --- src/zklaim/Makefile.am | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/zklaim/Makefile.am b/src/zklaim/Makefile.am index 44f016f2b..b2876d274 100644 --- a/src/zklaim/Makefile.am +++ b/src/zklaim/Makefile.am @@ -18,14 +18,5 @@ gnunet_zklaim_SOURCES = \ gnunet_zklaim_LDFLAGS = -rdynamic gnunet_zklaim_LDADD = \ -lzklaim \ - -lgcrypt \ - -lsnark \ - -lff \ - -lgmp \ - -lgmpxx \ - -lcrypto \ - -lprocps \ - -lzm \ - -lstdc++ \ - -lm + -lgcrypt -- cgit v1.2.3 From cc2b5d996a08f649b0630a88c8aa32edf3119a82 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Mon, 13 Aug 2018 21:44:21 +0200 Subject: start zklaim integration again --- configure.ac | 2 +- po/POTFILES.in | 1 + src/zklaim/Makefile.am | 47 +++++++--- src/zklaim/main.c | 237 ------------------------------------------------- src/zklaim/zklaim.c | 79 +++++++++++++++++ 5 files changed, 117 insertions(+), 249 deletions(-) delete mode 100644 src/zklaim/main.c create mode 100644 src/zklaim/zklaim.c 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, # check for zklaims zklaim=0 -AC_CHECK_HEADER([zklaim.h],zklaim=1) +AC_CHECK_HEADER([zklaim/zklaim.h],zklaim=1) AM_CONDITIONAL(HAVE_ZKLAIM, [test "$zklaim" = 1]) if test "x$zklaim" = x1 then 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 src/vpn/gnunet-vpn.c src/vpn/vpn_api.c src/zklaim/main.c +src/zklaim/zklaim.c src/zonemaster/gnunet-service-zonemaster.c src/fs/fs_api.h src/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 @@ # This Makefile.am is in the public domain AM_CPPFLAGS = -I$(top_srcdir)/src/include -if MINGW - WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -endif +plugindir = $(libdir)/gnunet + +libexecdir= $(pkglibdir)/libexec/ + +pkgcfgdir= $(pkgdatadir)/config.d/ if USE_COVERAGE AM_CFLAGS = --coverage -O0 XLIB = -lgcov endif -bin_PROGRAMS = \ - gnunet-zklaim -gnunet_zklaim_SOURCES = \ - main.c -gnunet_zklaim_LDFLAGS = -rdynamic -gnunet_zklaim_LDADD = \ - -lzklaim \ - -lgcrypt +libgnunetzklaim_la_SOURCES = zklaim.c +libgnunetzklaim_la_LIBADD = \ + $(GCLIBADD)\ + $(LIBGCRYPT_LIBS) \ + -lzklaim \ + -lgcrypt \ + -lgmp \ + -lgmpxx \ + -lcrypto \ + -lprocps \ + -lstdc++ \ + -lm +libgnunetzklaim_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) \ + -version-info 1:0:0 + +lib_LTLIBRARIES = libgnunetzklaim.la + +if ENABLE_TEST_RUN +AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; +TESTS = $(check_PROGRAMS) +endif + +#check_PROGRAMS = test_cpabe +#test_cpabe_SOURCES = \ +# test_cpabe.c +#test_cpabe_LDADD = \ +# libgnunetabe.la \ +# $(top_builddir)/src/util/libgnunetutil.la +#check_PROGRAMS += \ +# 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 @@ -/** - * Test File for zklaim c implementation - */ - -#include "zklaim.h" -#include "zklaim_ecc.h" -#include "zklaim_hash.h" -#include -#include -#include -#include - -// to boost up valgrind -int worker() { - gcry_sexp_t priv, pub; - zklaim_gen_pk(&priv); - zklaim_get_pub(priv, &pub); - unsigned char *pubbuf; - size_t publen; - zklaim_pub2buf(pub, &pubbuf, &publen); - - printf("===========================================================================\n"); - printf("===========================================================================\n"); - printf("============================== ISSUER =====================================\n"); - printf("===========================================================================\n"); - printf("===========================================================================\n"); - //zklaim_ctx* ctx = zklaim_context_init(); - //zklaim_proving_key* pk = zklaim_proving_key_get(ctx); - /* - * - 1 - - * initialize data structures - */ - printf("[ISSUER] initializing context\n"); - zklaim_ctx *ctx = zklaim_context_new(); - - if (sizeof(ctx->pub_key) != publen) { - printf("size mismatch!"); - return 1; - } - - // TODO: there should be a zklaim method for this - memcpy(ctx->pub_key, pubbuf, sizeof(ctx->pub_key)); - free(pubbuf); - - //print_sexp(pub); - - /* - * - 2 - - * setup the first payload - */ - printf("[ISSUER] Setting up payloads..\n"); - zklaim_payload pl, pl2; - memset(&pl, 0, sizeof(zklaim_payload)); - pl.data0_ref = 18; - pl.data0_op = (enum zklaim_op) (zklaim_greater | zklaim_eq); - pl.data1_ref = 1; - pl.data1_op = zklaim_eq; - pl.data2_ref = 2; - pl.data2_op = zklaim_eq; - pl.data3_ref = 3; - pl.data3_op = zklaim_eq; - pl.data4_ref = 600; - pl.data4_op = zklaim_less; - pl.priv = 0; - - memset(&pl2, 0, sizeof(zklaim_payload)); - pl2.data0_ref = 0; - pl2.data0_op = zklaim_noop; - pl2.data1_ref = 0; - pl2.data1_op = zklaim_noop; - pl2.data2_ref = 0; - pl2.data2_op = zklaim_noop; - pl2.data3_ref = 0; - pl2.data3_op = zklaim_noop; - pl2.data4_ref = 9223372036854775807; - pl2.data4_op = zklaim_less_or_eq; - pl2.priv = 0; - - // fill in the values - zklaim_set_attr(&pl, 23, 0); - zklaim_set_attr(&pl, 1, 1); - zklaim_set_attr(&pl, 2, 2); - zklaim_set_attr(&pl, 3, 3); - zklaim_set_attr(&pl, 599, 4); - - zklaim_set_attr(&pl2, 0, 0); - zklaim_set_attr(&pl2, 0, 1); - zklaim_set_attr(&pl2, 0, 2); - zklaim_set_attr(&pl2, 0, 3); - zklaim_set_attr(&pl2, 9223372036854775807, 4); - - /* - * - 3 - - * add payload to context - */ - printf("[ISSUER] adding payloads to context\n"); - zklaim_add_pl(ctx, pl); - //zklaim_add_pl(ctx, pl2); - //zklaim_add_pl(ctx, pl2); - zklaim_hash_ctx(ctx); - - printf("[ISSUER] performing trusted setup in order to generate keys\n"); - printf("-> trusted setup result: %s\n", (zklaim_trusted_setup(ctx) ? "failed" : "passed")); - - //unsigned char* buf; - //size_t vksize = zklaim_verification_key_serialize(ctx, &buf); - //printf("serialized vk size: %zuB\n", vksize); - - // write key to disk - //FILE* f = fopen("/tmp/vk1", "w"); - //fwrite(buf, vksize, 1, f); - //fclose(f); - - //zklaim_verification_key_deserialize(ctx2, buf, vksize); - - //free(buf); - - //size_t pksize = zklaim_proving_key_serialize(ctx, &buf); - //printf("serialized pk size: %.2fMB\n", ((float) pksize)/1000/1000); - - //zklaim_proving_key_deserialize(ctx, buf, pksize); - - //zklaim_print(ctx); - - //zklaim_ctx_sign(ctx, priv); - - - printf("-> signing context: %s\n", zklaim_ctx_sign(ctx, priv) ? "failed" : "passed"); - - unsigned char* ctx_issuer; - - printf("\n[ISSUER] serializing context\n"); - size_t len = zklaim_ctx_serialize(ctx, &ctx_issuer); - - /* - * - 4 - - * generate proof - */ - - //printf("\n-> signing context: %s\n", zklaim_ctx_sign(ctx, priv) ? "failed" : "passed"); - - //unsigned char* proof; - //size_t proof_size = zklaim_proof_serialize(ctx, &proof); - //printf("serialized proof size: %zuB\n", proof_size); - - //zklaim_proof* zkproof_imported; - - //zklaim_proof_deserialize(ctx, proof, proof_size); - - printf("===========================================================================\n"); - printf("===========================================================================\n"); - printf("============================== PROVER =====================================\n"); - printf("===========================================================================\n"); - printf("===========================================================================\n"); - - - zklaim_ctx* ctx_prover = zklaim_context_new(); - printf("\n[PROVER] deserializing context\n"); - printf("-> deserialisation status: %s\n\n", zklaim_ctx_deserialize(ctx_prover, ctx_issuer, len) ? "failed" : "passed"); - - zklaim_print(ctx_prover); - - ctx_prover->pk = ctx->pk; - - int res = zklaim_ctx_verify(ctx_prover); - printf("[PROVER] verification result: %d %s\n", res, (res ? "failed" : "passed")); - printf(" ^--- failure with code 3 (ZKLAIM_INVALID_PROOF) is ok for the prover, as signature passes, but (non-existing) proof fails\n\n"); - - printf("[PROVER] resetting operations and reference values to create taylored proof\n"); - printf("[PROVER] generating proof\n"); - - ctx_prover->pk = (unsigned char*) calloc(1, ctx->pk_size); - ctx_prover->pk_size = ctx->pk_size; - memcpy(ctx_prover->pk, ctx->pk, ctx_prover->pk_size); - - // set custom prover reference values here: - ctx_prover->pl_ctx_head->pl.data0_ref = 20; - //ctx_prover->pl_ctx_head->pl.data0_op = zklaim_less; - ctx_prover->pl_ctx_head->pl.data4_ref = 0; - ctx_prover->pl_ctx_head->pl.data4_op = zklaim_noop; - - ctx_prover->pl_ctx_head->pl.data1_ref = 0; - ctx_prover->pl_ctx_head->pl.data1_op = zklaim_noop; - - ctx_prover->pl_ctx_head->pl.data2_ref = 0; - ctx_prover->pl_ctx_head->pl.data2_op = zklaim_noop; - - ctx_prover->pl_ctx_head->pl.data3_ref = 0; - ctx_prover->pl_ctx_head->pl.data3_op = zklaim_noop; - - zklaim_print(ctx_prover); - - printf("-> proof generation status: %s\n\n", (zklaim_proof_generate(ctx_prover) ? "failed" : "passed")); - - - printf("[PROVER] blinding attributes\n"); - zklaim_clear_pres(ctx_prover); - - - printf("[PROVER] serializing context\n\n"); - - unsigned char *ctx_prover_buf; - len = zklaim_ctx_serialize(ctx_prover, &ctx_prover_buf); - - /* - * - 5 - - * verify proof - */ - printf("===========================================================================\n"); - printf("===========================================================================\n"); - printf("============================= VERIFIER ====================================\n"); - printf("===========================================================================\n"); - printf("===========================================================================\n"); - - zklaim_ctx* ctx_verifier = zklaim_context_new(); - printf("\n[VERIFIER] deserializing context\n"); - printf("-> deserialisation status: %s\n\n", zklaim_ctx_deserialize(ctx_verifier, ctx_prover_buf, len) ? "failed" : "passed"); - printf("[VERIFIER] verifying proof and context\n"); - res = zklaim_ctx_verify(ctx_verifier); - printf("verification result: %d %s\n\n", res, (res ? "failed" : "passed")); - - zklaim_print(ctx_verifier); - - free(ctx_prover_buf); - free(ctx_issuer); - zklaim_ctx_free(ctx); - gcry_sexp_release(priv); - gcry_sexp_release(pub); - zklaim_ctx_free(ctx_prover); - zklaim_ctx_free(ctx_verifier); - - return ZKLAIM_OK; -} - -int main() { - return worker(); -} 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 @@ +/* + This file is part of GNUnet. Copyright (C) 2001-2018 Christian Grothoff + (and other contributing authors) + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +*/ + +/** + * @file abe/abe.c + * @brief functions for Attribute-Based Encryption + * @author Martin Schanzenbach + */ + + +#include "platform.h" +#include +#include "gnunet_crypto_lib.h" + +struct GNUNET_ZKLAIM_Context +{ + zklaim_ctx* ctx; + gcry_sexp_t priv; + gcry_sexp_t pub; +}; + +struct GNUNET_ZKLAIM_Payload +{ + zklaim_payload pl; +}; + +struct GNUNET_ZKLAIM_Context* +GNUNET_ZKLAIM_new () +{ + struct GNUNET_ZKLAIM_Context *ctx; + unsigned char *pubbuf; + size_t publen; + + ctx = GNUNET_new (struct GNUNET_ZKLAIM_Context); + ctx->ctx = zklaim_context_new(); + zklaim_pub2buf(ctx->pub, &pubbuf, &publen); + zklaim_gen_pk(&ctx->priv); + zklaim_get_pub(ctx->priv, &ctx->pub); + if (sizeof(ctx->ctx->pub_key) != publen) { + printf("size mismatch!"); + return NULL; + } + + memcpy(ctx->ctx->pub_key, pubbuf, sizeof(ctx->ctx->pub_key)); + free(pubbuf); + return ctx; +} + +int +GNUNET_ZKLAIM_add_payload (struct GNUNET_ZKLAIM_Context *ctx, + struct GNUNET_ZKLAIM_Payload *pl) +{ + zklaim_add_pl (ctx->ctx, pl->pl); + return GNUNET_OK; +} + +int +GNUNET_ZKLAIM_finalize (struct GNUNET_ZKLAIM_Context *ctx) +{ + zklaim_hash_ctx (ctx->ctx); + zklaim_ctx_sign (ctx->ctx, ctx->priv); + return 1; +} -- cgit v1.2.3 From d3f934f742ae17ed0b2dad577897b5a226e644c2 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Tue, 14 Aug 2018 12:23:38 +0200 Subject: start API --- src/include/gnunet_zklaim_lib.h | 131 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/include/gnunet_zklaim_lib.h diff --git a/src/include/gnunet_zklaim_lib.h b/src/include/gnunet_zklaim_lib.h new file mode 100644 index 000000000..a1fd1f017 --- /dev/null +++ b/src/include/gnunet_zklaim_lib.h @@ -0,0 +1,131 @@ +/* + This file is part of GNUnet. + Copyright (C) 2001-2018 GNUnet e.V. + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** + * @file include/gnunet_zklaim_lib.h + * @brief ZKlaim functions for GNUnet + * + * @author Martin Schanzenbach + * + * @defgroup zklaim ZKlaim library: Zero-Knowledge Credentials + * + */ +#ifndef GNUNET_ZKLAIM_LIB_H +#define GNUNET_ZKLAIM_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" + +/** + * @brief type for ZKlaim context + */ +struct GNUNET_ZKLAIM_Context; + +/** + * @brief type for ZKlaim payload + */ +struct GNUNET_ZKLAIM_Payload; + + +/** + * @ingroup zklaim + * Create a new ZKlaim context. Caller must free return value. + * TODO: parameters: keys etc. + * + * @return fresh context; free using #GNUNET_free + */ +struct GNUNET_ZKLAIM_Context * +GNUNET_ZKLAIM_context_create (void); + +/** + * @ingroup zklaim + * Create a payload. + * TODO: parameters, attributes etc. + * + * @return fresh payload; free using #GNUNET_free + */ +void +GNUNET_ZKLAIM_payload_create (void); + +/** + * @ingroup zklaim + * Create a payload. + * TODO: parameters, attributes etc. + * + * @return GNUNET_OK is successful + */ +int +GNUNET_ZKLAIM_context_add_payload (struct GNUNET_ZKLAIM_Context *ctx, + struct GNUNET_ZKLAIM_Payload* pl); + + +/** + * @ingroup zklaim + * Create a payload. + * TODO: parameters, attributes etc. + * + * @return size needed for serialized context, -1 on error + */ +ssize_t +GNUNET_ZKLAIM_context_serialize_get_size (struct GNUNET_ZKLAIM_Context *ctx); + + +/** + * @ingroup zklaim + * Create a payload. + * TODO: parameters, attributes etc. + * + */ +void +GNUNET_ZKLAIM_context_serialize (struct GNUNET_ZKLAIM_Context *ctx, + char* buf); + + +/** + * @ingroup zklaim + * Create a payload. + * TODO: parameters, attributes etc. + * + * @return fresh payload; free using #GNUNET_free + */ +char * +GNUNET_ZKLAIM_context_to_string (struct GNUNET_ZKLAIM_Context *ctx); + + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_ZKLAIM_LIB_H */ +#endif +/* end of gnunet_zklaim_lib.h */ -- cgit v1.2.3