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.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/src/zklaim/zklaim_functions.c b/src/zklaim/zklaim_functions.c
index 0c6ea67cc..b528e1bbf 100644
--- a/src/zklaim/zklaim_functions.c
+++ b/src/zklaim/zklaim_functions.c
@@ -34,7 +34,12 @@ ZKLAIM_context_sign (struct GNUNET_ZKLAIM_Context *ctx,
34 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key) 34 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key)
35{ 35{
36 int rc; 36 int rc;
37 unsigned char *pubbuf;
38 size_t publen;
37 gcry_sexp_t priv; 39 gcry_sexp_t priv;
40 gcry_sexp_t pub;
41 gcry_mpi_t q;
42 gcry_ctx_t gctx;
38 43
39 //TODO how to ensure not hashed?? 44 //TODO how to ensure not hashed??
40 zklaim_hash_ctx (ctx->ctx); 45 zklaim_hash_ctx (ctx->ctx);
@@ -46,9 +51,22 @@ ZKLAIM_context_sign (struct GNUNET_ZKLAIM_Context *ctx,
46 { 51 {
47 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 52 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
48 "GCRY error...\n"); 53 "GCRY error...\n");
49 //send_issue_response (ih, NULL, 0);
50 return GNUNET_SYSERR; 54 return GNUNET_SYSERR;
51 } 55 }
56 gcry_mpi_ec_new (&gctx, priv, NULL);
57 q = gcry_mpi_ec_get_mpi ("q@eddsa", gctx, 0);
58 rc = gcry_sexp_build(&pub, NULL, "(key-data (public-key (ecc (curve Ed25519) (q %M))))", q);
59 if (0 != rc) {
60 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
61 "GCRY error...\n");
62 return GNUNET_SYSERR;
63 }
64 gcry_mpi_release(q);
65 zklaim_pub2buf(pub, &pubbuf, &publen);
66 gcry_sexp_release(pub);
67 gcry_ctx_release (gctx);
68 memcpy(ctx->ctx->pub_key, pubbuf, sizeof(ctx->ctx->pub_key));
69 free(pubbuf);
52 return zklaim_ctx_sign (ctx->ctx, priv); 70 return zklaim_ctx_sign (ctx->ctx, priv);
53} 71}
54 72
@@ -113,6 +131,7 @@ ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
113{ 131{
114 int i; 132 int i;
115 int j; 133 int j;
134 int ret;
116 char *attr_name; 135 char *attr_name;
117 char *tmp; 136 char *tmp;
118 zklaim_wrap_payload_ctx *plw; 137 zklaim_wrap_payload_ctx *plw;
@@ -153,13 +172,48 @@ ZKLAIM_context_prove (struct GNUNET_ZKLAIM_Context *ctx,
153 GNUNET_assert (NULL != plw); 172 GNUNET_assert (NULL != plw);
154 } 173 }
155 GNUNET_free (tmp); 174 GNUNET_free (tmp);
156 return zklaim_proof_generate (ctx->ctx); 175 ret = zklaim_proof_generate (ctx->ctx);
176 zklaim_clear_pres(ctx->ctx);
177 return ret;
157} 178}
158 179
159int 180int
160ZKLAIM_context_verify (struct GNUNET_ZKLAIM_Context *ctx, 181ZKLAIM_context_verify (struct GNUNET_ZKLAIM_Context *ctx,
161 const struct GNUNET_CRYPTO_EcdsaPublicKey *ttp) 182 GNUNET_ZKLAIM_PredicateIterator iter,
183 void *iter_cls)
162{ 184{
163 //TODO check ttp pubkey against pubkey in ctx 185 int i;
186 int j;
187 char *attr_name;
188 char *tmp;
189 zklaim_wrap_payload_ctx *plw;
190
191 tmp = GNUNET_strdup (ctx->attrs);
192 attr_name = strtok (tmp, ",");
193 plw = ctx->ctx->pl_ctx_head;
194 for (i = 0; i < ctx->ctx->num_of_payloads; i++)
195 {
196 for (j = 0; j < ZKLAIM_MAX_PAYLOAD_ATTRIBUTES; j++)
197 {
198
199 if (NULL == attr_name)
200 break;
201 iter (iter_cls,
202 attr_name,
203 &plw->pl.data_op[j],
204 &plw->pl.data_ref[j]);
205 if ((attr_name - tmp) == (strlen (attr_name) + 1))
206 {
207 attr_name = NULL;
208 break;
209 }
210 attr_name = strtok (attr_name + strlen (attr_name) + 1, ",");
211 }
212 if (NULL == attr_name)
213 break;
214 plw = plw->next;
215 GNUNET_assert (NULL != plw);
216 }
217 GNUNET_free (tmp);
164 return zklaim_ctx_verify (ctx->ctx); 218 return zklaim_ctx_verify (ctx->ctx);
165} 219}