aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/zklaim_functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zklaim/zklaim_functions.c')
-rw-r--r--src/zklaim/zklaim_functions.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/zklaim/zklaim_functions.c b/src/zklaim/zklaim_functions.c
new file mode 100644
index 000000000..1c66b421c
--- /dev/null
+++ b/src/zklaim/zklaim_functions.c
@@ -0,0 +1,75 @@
1#include "platform.h"
2#include "zklaim/zklaim.h"
3#include "gcrypt.h"
4#include "gnunet_zklaim_service.h"
5#include "zklaim_functions.h"
6
7int
8ZKLAIM_context_sign (struct GNUNET_ZKLAIM_Context *ctx,
9 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key)
10{
11 int rc;
12 gcry_sexp_t priv;
13
14 //TODO how to ensure not hashed??
15 zklaim_hash_ctx (ctx->ctx);
16 rc = gcry_sexp_build (&priv, NULL,
17 "(private-key(ecc(curve \"Ed25519\")"
18 "(d %b)))",
19 (int) sizeof (key->d), key->d);
20 if (0 != rc)
21 {
22 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
23 "GCRY error...\n");
24 //send_issue_response (ih, NULL, 0);
25 return GNUNET_SYSERR;
26 }
27 return zklaim_ctx_sign (ctx->ctx, priv);
28}
29
30void
31ZKLAIM_context_attributes_iterate (const struct GNUNET_ZKLAIM_Context *ctx,
32 GNUNET_ZKLAIM_PayloadIterator iter,
33 void *iter_cls)
34{
35 int i;
36 int j;
37 uint64_t data;
38 char *attr_name;
39 char *tmp;
40 zklaim_wrap_payload_ctx *plw;
41
42 tmp = GNUNET_strdup (ctx->attrs);
43 attr_name = strtok (tmp, ",");
44 plw = ctx->ctx->pl_ctx_head;
45
46 for (i = 0; i < ctx->ctx->num_of_payloads; i++)
47 {
48 for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
49 {
50 GNUNET_assert (NULL != attr_name);
51 iter (iter_cls, attr_name, &data);
52 zklaim_set_attr (&plw->pl,
53 data,
54 j);
55 attr_name = strtok (NULL, ",");
56 }
57 plw = plw->next;
58 GNUNET_assert (NULL != plw);
59 }
60 GNUNET_free (tmp);
61
62}
63
64void
65ZKLAIM_context_issue (struct GNUNET_ZKLAIM_Context *ctx,
66 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
67 GNUNET_ZKLAIM_PayloadIterator iter,
68 void *iter_cls)
69{
70 ZKLAIM_context_attributes_iterate (ctx,
71 iter,
72 iter_cls);
73 ZKLAIM_context_sign (ctx,
74 key);
75}