const char* pkey_fn,
GNUNET_ZKLAIM_PredicateIterator iter,
void* iter_cls);
+int
+GNUNET_ZKLAIM_context_verify (struct GNUNET_ZKLAIM_Context *ctx,
+ GNUNET_ZKLAIM_PredicateIterator iter,
+ void* iter_cls);
#if 0 /* keep Emacsens' auto-indent happy */
*/
static char* pkey_fn;
+/**
+ * The proof to verify
+ */
+static char* verify_proof;
+
+
/**
* ZKLAIM handle
*/
int32_t success,
const char* emsg)
{
+ zklaim_op = NULL;
if (GNUNET_OK == success)
fprintf (stdout,
"Created.\n");
char* data;
char *str;
+ zklaim_op = NULL;
if (NULL == ctx)
{
fprintf (stderr,
}
+const char* zklaim_parse_op (enum zklaim_op e) {
+ switch (e) {
+ case zklaim_noop:
+ return "noop";
+ case zklaim_less:
+ return "<";
+ case zklaim_less_or_eq:
+ return "<=";
+ case zklaim_eq:
+ return "=";
+ case zklaim_greater_or_eq:
+ return ">=";
+ case zklaim_greater:
+ return ">";
+ case zklaim_not_eq:
+ return "!=";
+ default:
+ return "enum zklaim_op: no valid value";
+ }
+}
+
+void
+verify_iter (void *cls,
+ const char* name,
+ enum zklaim_op *zop,
+ uint64_t *ref)
+{
+ const char *op = zklaim_parse_op (*zop);
+ fprintf (stdout,
+ "%s %s %lu\n", name, op, *ref);
+}
+
static void
handle_arguments ()
{
struct GNUNET_ZKLAIM_Context *ctx;
size_t len;
char *data;
+ char *proof_str;
+ char *proof_data;
int ret;
+ size_t proof_size;
timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
&timeout_task,
NULL);
fprintf (stdout,
"%s\n", ret ? "failed." : "success.");
+ proof_size = GNUNET_ZKLAIM_context_serialize (ctx,
+ &proof_data);
+ GNUNET_STRINGS_base64_encode (proof_data,
+ proof_size,
+ &proof_str);
+ fprintf (stdout,
+ "Here is your proof:\n%s\n", proof_str);
+ GNUNET_free (proof_str);
+ GNUNET_free (proof_data);
+ GNUNET_ZKLAIM_context_destroy (ctx);
+ }
+ else if (verify_proof)
+ {
+ proof_size = GNUNET_STRINGS_base64_decode (verify_proof,
+ strlen (verify_proof),
+ (void**)&proof_data);
+ ctx = GNUNET_ZKLAIM_context_deserialize (proof_data,
+ proof_size);
+ ret = GNUNET_ZKLAIM_context_verify (ctx,
+ &verify_iter,
+ NULL);
+ fprintf (stdout,
+ "Proof is %s (%d)\n", ret ? "INVALID" : "VALID", ret);
+ GNUNET_free (proof_data);
+ GNUNET_ZKLAIM_context_destroy (ctx);
}
cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
}
NULL,
gettext_noop ("The proving key to use"),
&pkey_fn),
+ GNUNET_GETOPT_option_string ('V',
+ "verify",
+ NULL,
+ gettext_noop ("Proof to verify"),
+ &verify_proof),
+
GNUNET_GETOPT_OPTION_END
};
if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",
iter_cls);
}
+
+int
+GNUNET_ZKLAIM_context_verify (struct GNUNET_ZKLAIM_Context *ctx,
+ GNUNET_ZKLAIM_PredicateIterator iter,
+ void* iter_cls)
+{
+ return ZKLAIM_context_verify (ctx,
+ iter,
+ iter_cls);
+}
+
+
/* end of zklaim_api.c */
const struct GNUNET_CRYPTO_EcdsaPrivateKey *key)
{
int rc;
+ unsigned char *pubbuf;
+ size_t publen;
gcry_sexp_t priv;
+ gcry_sexp_t pub;
+ gcry_mpi_t q;
+ gcry_ctx_t gctx;
//TODO how to ensure not hashed??
zklaim_hash_ctx (ctx->ctx);
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"GCRY error...\n");
- //send_issue_response (ih, NULL, 0);
return GNUNET_SYSERR;
}
+ gcry_mpi_ec_new (&gctx, priv, NULL);
+ q = gcry_mpi_ec_get_mpi ("q@eddsa", gctx, 0);
+ rc = gcry_sexp_build(&pub, NULL, "(key-data (public-key (ecc (curve Ed25519) (q %M))))", q);
+ if (0 != rc) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "GCRY error...\n");
+ return GNUNET_SYSERR;
+ }
+ gcry_mpi_release(q);
+ zklaim_pub2buf(pub, &pubbuf, &publen);
+ gcry_sexp_release(pub);
+ gcry_ctx_release (gctx);
+ memcpy(ctx->ctx->pub_key, pubbuf, sizeof(ctx->ctx->pub_key));
+ free(pubbuf);
return zklaim_ctx_sign (ctx->ctx, priv);
}
{
int i;
int j;
+ int ret;
char *attr_name;
char *tmp;
zklaim_wrap_payload_ctx *plw;
GNUNET_assert (NULL != plw);
}
GNUNET_free (tmp);
- return zklaim_proof_generate (ctx->ctx);
+ ret = zklaim_proof_generate (ctx->ctx);
+ zklaim_clear_pres(ctx->ctx);
+ return ret;
}
int
ZKLAIM_context_verify (struct GNUNET_ZKLAIM_Context *ctx,
- const struct GNUNET_CRYPTO_EcdsaPublicKey *ttp)
+ GNUNET_ZKLAIM_PredicateIterator iter,
+ void *iter_cls)
{
- //TODO check ttp pubkey against pubkey in ctx
+ int i;
+ int j;
+ char *attr_name;
+ char *tmp;
+ zklaim_wrap_payload_ctx *plw;
+
+ tmp = GNUNET_strdup (ctx->attrs);
+ attr_name = strtok (tmp, ",");
+ plw = ctx->ctx->pl_ctx_head;
+ for (i = 0; i < ctx->ctx->num_of_payloads; i++)
+ {
+ for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
+ {
+
+ if (NULL == attr_name)
+ break;
+ iter (iter_cls,
+ attr_name,
+ &plw->pl.data_op[j],
+ &plw->pl.data_ref[j]);
+ if ((attr_name - tmp) == (strlen (attr_name) + 1))
+ {
+ attr_name = NULL;
+ break;
+ }
+ attr_name = strtok (attr_name + strlen (attr_name) + 1, ",");
+ }
+ if (NULL == attr_name)
+ break;
+ plw = plw->next;
+ GNUNET_assert (NULL != plw);
+ }
+ GNUNET_free (tmp);
return zklaim_ctx_verify (ctx->ctx);
}
GNUNET_ZKLAIM_PredicateIterator iter,
void *iter_cls);
+
+int
+ZKLAIM_context_verify (struct GNUNET_ZKLAIM_Context *ctx,
+ GNUNET_ZKLAIM_PredicateIterator iter,
+ void *iter_cls);
+
#endif