diff --git a/src/groupsig/cpy06/join_mem.c b/src/groupsig/cpy06/join_mem.c index c228312..119bda5 100644 --- a/src/groupsig/cpy06/join_mem.c +++ b/src/groupsig/cpy06/join_mem.c @@ -32,7 +32,7 @@ * Note: cpy06_join_mem and cpy06_join_mgr compose an interactive protocol, * as described in the CPY06 paper. Here, as in the paper, we assume that * this protocol is run in a confidential and authenticated channel, with - * protection against replays. The user of this protocol should make sure of + * protection against replays. The user of this protocol should make sure of * that. */ int cpy06_join_mem(message_t **mout, @@ -84,7 +84,7 @@ int cpy06_join_mem(message_t **mout, if (!(r = pbcext_element_Fr_init())) GOTOENDRC(IERROR, cpy06_join_mem); if (pbcext_element_Fr_random(r) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mem); + GOTOENDRC(IERROR, cpy06_join_mem); /* I = yG1 + rQ */ if (!(g1 = pbcext_element_G1_init())) @@ -110,30 +110,30 @@ int cpy06_join_mem(message_t **mout, GOTOENDRC(IERROR, cpy06_join_mem); if (pbcext_element_Fr_set(cpy06_memkey->_r, r) == IERROR) GOTOENDRC(IERROR, cpy06_join_mem); - + /* First message is I */ if (pbcext_dump_element_G1_bytes(&bmsg, &len, I) == IERROR) GOTOENDRC(IERROR, cpy06_join_mem) if(!*mout) { if(!(_mout = message_from_bytes(bmsg, len))) - GOTOENDRC(IERROR, cpy06_join_mem); + GOTOENDRC(IERROR, cpy06_join_mem); *mout = _mout; } else { _mout = *mout; if(message_set_bytes(*mout, bmsg, len) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mem); + GOTOENDRC(IERROR, cpy06_join_mem); } - + } - - /* 2nd step by member (seq 2/4): generate non-adaptive random xi with member + + /* 2nd step by member (seq 2/4): generate non-adaptive random xi with member committed randomness, and manager provided randomness */ else if (seq == 2) { - + /* y and r values from seq = 0 are fetched from the memkey */ - /* min = + /* min = Read u, v and I values from input message */ if (!(u = pbcext_element_Fr_init())) GOTOENDRC(IERROR, cpy06_join_mem); @@ -190,7 +190,7 @@ int cpy06_join_mem(message_t **mout, x[0] = cpy06_memkey->x; x[1] = v; x[2] = u; - x[3] = rr; + x[3] = rr; i[0][0] = 0; i[0][1] = 0; // x*g1 (g[0],x[0]) i[1][0] = 1; i[1][1] = 0; // v*g1 (g[0],x[1]) @@ -219,9 +219,9 @@ int cpy06_join_mem(message_t **mout, /* Output message is */ if (pbcext_dump_element_G1_bytes(&bI, &Ilen, I) == IERROR) GOTOENDRC(IERROR, cpy06_join_mem); - + len = Ilen + pilen + spklen; - + if (!(bmsg = (byte_t *) mem_malloc(sizeof(byte_t)*len))) GOTOENDRC(IERROR, cpy06_join_mem); memcpy(bmsg, bI, Ilen); @@ -230,14 +230,14 @@ int cpy06_join_mem(message_t **mout, if(!*mout) { if(!(_mout = message_from_bytes(bmsg, len))) - GOTOENDRC(IERROR, cpy06_join_mem); + GOTOENDRC(IERROR, cpy06_join_mem); *mout = _mout; } else { _mout = *mout; if(message_set_bytes(*mout, bmsg, len) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mem); + GOTOENDRC(IERROR, cpy06_join_mem); } - + } /* 3rd step by member (seq 4/4): check cert */ @@ -292,6 +292,7 @@ int cpy06_join_mem(message_t **mout, if (pbcext_element_Fr_set(cpy06_memkey->t, _cpy06_memkey->t) == IERROR) GOTOENDRC(IERROR, cpy06_join_mem); + if (_memkey) { cpy06_mem_key_free(_memkey); _memkey = NULL; } } else { @@ -347,28 +348,28 @@ int cpy06_join_mem(message_t **mout, pbcext_element_G1_free(cpy06_memkey->A); cpy06_memkey->A = NULL; } } - if (bkey) { mem_free(bkey); bkey = NULL; } if (bmsg) { mem_free(bmsg); bmsg = NULL; } if (bpi) { mem_free(bpi); bpi = NULL; } if (bspk) { mem_free(bspk); bspk = NULL; } + if (spk) { spk_rep_free(spk); spk = NULL; } if (bI) { mem_free(bI); bI = NULL; } if (y) { pbcext_element_Fr_free(y); y = NULL; } if (r) { pbcext_element_Fr_free(r); r = NULL; } if (u) { pbcext_element_Fr_free(u); u = NULL; } if (v) { pbcext_element_Fr_free(v); v = NULL; } if (rr) { pbcext_element_Fr_free(rr); rr = NULL; } - if (g1) { pbcext_element_G1_free(g1); g1 = NULL; } + if (g1) { pbcext_element_G1_free(g1); g1 = NULL; } if (I) { pbcext_element_G1_free(I); I = NULL; } if (pi) { pbcext_element_G1_free(pi); pi = NULL; } - if (aux_g1) { pbcext_element_G1_free(aux_g1); aux_g1 = NULL; } + if (aux_g1) { pbcext_element_G1_free(aux_g1); aux_g1 = NULL; } if (g2) { pbcext_element_G2_free(g2); g2 = NULL; } - if (aux_g2) { pbcext_element_G2_free(aux_g2); aux_g2 = NULL; } + if (aux_g2) { pbcext_element_G2_free(aux_g2); aux_g2 = NULL; } if (aux_gt1) { pbcext_element_GT_free(aux_gt1); aux_gt1 = NULL; } - if (aux_gt2) { pbcext_element_GT_free(aux_gt2); aux_gt2 = NULL; } + if (aux_gt2) { pbcext_element_GT_free(aux_gt2); aux_gt2 = NULL; } return rc; - + } /* join.c ends here */ diff --git a/src/groupsig/cpy06/join_mgr.c b/src/groupsig/cpy06/join_mgr.c index 6c1720a..2dee1e0 100644 --- a/src/groupsig/cpy06/join_mgr.c +++ b/src/groupsig/cpy06/join_mgr.c @@ -53,7 +53,7 @@ int cpy06_join_mgr(message_t **mout, int seq, message_t *min, groupsig_key_t *grpkey) { - + groupsig_key_t *memkey; cpy06_mem_key_t *cpy06_memkey; cpy06_mgr_key_t *cpy06_mgrkey; @@ -110,7 +110,7 @@ int cpy06_join_mgr(message_t **mout, if (!(v = pbcext_element_Fr_init())) GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_element_Fr_random(v) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); /* Send u, v, I to member */ if (pbcext_dump_element_Fr_bytes(&bu, &ulen, u) == IERROR) @@ -118,29 +118,25 @@ int cpy06_join_mgr(message_t **mout, if (pbcext_dump_element_Fr_bytes(&bv, &vlen, v) == IERROR) GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_dump_element_G1_bytes(&bI, &Ilen, I) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); len = ulen + vlen + Ilen; - + if (!(bmsg = (byte_t *) mem_malloc(sizeof(byte_t)*len))) GOTOENDRC(IERROR, cpy06_join_mgr); memcpy(bmsg, bu, ulen); memcpy(&bmsg[ulen], bv, vlen); memcpy(&bmsg[ulen+vlen], bI, Ilen); - - if(!*mout) { + + if(!*mout) { if(!(_mout = message_from_bytes(bmsg, len))) { - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); } - *mout = _mout; - } else { - _mout = *mout; if(message_set_bytes(*mout, bmsg, len) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); - - } + GOTOENDRC(IERROR, cpy06_join_mgr); + } } @@ -155,7 +151,7 @@ int cpy06_join_mgr(message_t **mout, if (pbcext_get_element_G1_bytes(I, &Ilen, min->bytes) == IERROR) GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_get_element_G1_bytes(pi, &pilen, min->bytes + Ilen) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); if (!(spk = spk_rep_import(min->bytes + Ilen + pilen, &len))) GOTOENDRC(IERROR, cpy06_join_mgr); @@ -163,7 +159,7 @@ int cpy06_join_mgr(message_t **mout, GOTOENDRC(IERROR, cpy06_join_mgr); if (!(g1 = pbcext_element_G1_init())) GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_element_G1_from_string(&g1, BLS12_381_P, 10) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); /* Verify spk */ Y[0] = pi; @@ -180,7 +176,7 @@ int cpy06_join_mgr(message_t **mout, prods[0] = 1; prods[1] = 3; - + if (spk_rep_verify(&ok, Y, 2, G, 3, @@ -190,7 +186,7 @@ int cpy06_join_mgr(message_t **mout, bpi, pilen) == IERROR) GOTOENDRC(IERROR, cpy06_join_mgr); - + if (!(memkey = cpy06_mem_key_init())) GOTOENDRC(IERROR, cpy06_join_mgr); cpy06_memkey = (cpy06_mem_key_t *) memkey->key; @@ -199,18 +195,15 @@ int cpy06_join_mgr(message_t **mout, /* GOTOENDRC(IERROR, cpy06_join_mgr); */ /* if (pbcext_element_Fr_random(cpy06_memkey->x) == IERROR) */ /* GOTOENDRC(IERROR, cpy06_join_mgr); */ - + /* t \in_R Z^*_p */ if (!(cpy06_memkey->t = pbcext_element_Fr_init())) GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_element_Fr_random(cpy06_memkey->t) == IERROR) GOTOENDRC(IERROR, cpy06_join_mgr); - + // /* A = (q*g_1^x)^(1/t+\gamma) */ /* A = (q*pi)^(1/t+\gamma) */ - if (!(g1 = pbcext_element_G1_init())) GOTOENDRC(IERROR, cpy06_join_mgr); - if (pbcext_element_G1_from_string(&g1, BLS12_381_P, 10) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); if (!(gammat = pbcext_element_Fr_init())) GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_element_Fr_add(gammat, cpy06_mgrkey->gamma, @@ -232,65 +225,65 @@ int cpy06_join_mgr(message_t **mout, cpy06_memkey->A, gammat) == IERROR) GOTOENDRC(IERROR, cpy06_join_mgr); - + /* Set memkey->x to 0 for export to work */ if (!(cpy06_memkey->x = pbcext_element_Fr_init())) GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_element_Fr_clear(cpy06_memkey->x) == IERROR) GOTOENDRC(IERROR, cpy06_join_mgr); - + /* Write the memkey into mout */ bkey = NULL; if (cpy06_mem_key_export(&bkey, &size, memkey) == IERROR) GOTOENDRC(IERROR, cpy06_join_mgr); - + if(!*mout) { if(!(_mout = message_from_bytes(bkey, size))) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); *mout = _mout; } else { _mout = *mout; if(message_set_bytes(_mout, bkey, size) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); } - + /* Update the gml, if any */ if(gml) { - + /* Initialize the GML entry */ if(!(gml_entry = cpy06_gml_entry_init())) - GOTOENDRC(IERROR, cpy06_join_mgr); - + GOTOENDRC(IERROR, cpy06_join_mgr); + cpy06_data = gml_entry->data; if (!(cpy06_data->trapdoor = trapdoor_init(GROUPSIG_CPY06_CODE))) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); cpy06_trap = (cpy06_trapdoor_t *) cpy06_data->trapdoor->trap; - + /* Open trapdoor */ if (!(cpy06_trap->open = pbcext_element_G1_init())) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_element_G1_set(cpy06_trap->open, cpy06_memkey->A)) - GOTOENDRC(IERROR, cpy06_join_mgr); - + GOTOENDRC(IERROR, cpy06_join_mgr); + /* Trace trapdoor */ if (!(cpy06_trap->trace = pbcext_element_G1_init())) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); if (pbcext_element_G1_set(cpy06_trap->trace, pi)) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); /* if (pbcext_element_G1_mul(cpy06_trap->trace, */ /* g1, */ /* cpy06_memkey->x)) */ /* GOTOENDRC(IERROR, cpy06_join_mgr); */ - + /* Currently, CPY06 identities are just uint64_t's */ if (!(cpy06_data->id = identity_init(GROUPSIG_CPY06_CODE))) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); *(cpy06_identity_t *) cpy06_data->id->id = gml->n; - + if(gml_insert(gml, gml_entry) == IERROR) - GOTOENDRC(IERROR, cpy06_join_mgr); + GOTOENDRC(IERROR, cpy06_join_mgr); } - + } else { @@ -316,9 +309,10 @@ int cpy06_join_mgr(message_t **mout, if (v) { pbcext_element_Fr_free(v); v = NULL; } if (g1) { pbcext_element_G1_free(g1); g1 = NULL; } if (I) { pbcext_element_G1_free(I); I = NULL; } - if (pi) { pbcext_element_G1_free(pi); pi = NULL; } + if (pi) { pbcext_element_G1_free(pi); pi = NULL; } if (memkey) { cpy06_mem_key_free(memkey); memkey = NULL; } if (bkey) { mem_free(bkey); bkey = NULL; } + if (spk) { spk_rep_free(spk); spk = NULL; } if (bpi) { mem_free(bpi); bpi = NULL; } if (bmsg) { mem_free(bmsg); bmsg = NULL; } if (bu) { mem_free(bu); bu = NULL; } diff --git a/src/groupsig/cpy06/mem_key.c b/src/groupsig/cpy06/mem_key.c index be1c9e8..a8f4586 100644 --- a/src/groupsig/cpy06/mem_key.c +++ b/src/groupsig/cpy06/mem_key.c @@ -1,4 +1,4 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -35,7 +35,7 @@ #include "sys/mem.h" groupsig_key_t* cpy06_mem_key_init() { - + groupsig_key_t *key; cpy06_mem_key_t *cpy06_key; @@ -63,14 +63,14 @@ int cpy06_mem_key_free(groupsig_key_t *key) { cpy06_mem_key_t *cpy06_key; if(!key) { - LOG_EINVAL_MSG(&logger, __FILE__, "cpy06_mem_key_free", __LINE__, + LOG_EINVAL_MSG(&logger, __FILE__, "cpy06_mem_key_free", __LINE__, "Nothing to free.", LOGWARN); - return IOK; + return IOK; } if(key->scheme != GROUPSIG_CPY06_CODE) { LOG_EINVAL(&logger, __FILE__, "cpy06_mem_key_free", __LINE__, LOGERROR); - return IERROR; + return IERROR; } if(key->key) { @@ -84,10 +84,16 @@ int cpy06_mem_key_free(groupsig_key_t *key) { if (cpy06_key->A) { pbcext_element_G1_free(cpy06_key->A); cpy06_key->A = NULL; } + if (cpy06_key->_y) { + pbcext_element_Fr_free(cpy06_key->_y); cpy06_key->_y = NULL; + } + if (cpy06_key->_r) { + pbcext_element_Fr_free(cpy06_key->_r); cpy06_key->_r = NULL; + } mem_free(key->key); key->key = NULL; } - + mem_free(key); return IOK; @@ -134,7 +140,7 @@ int cpy06_mem_key_copy(groupsig_key_t *dst, groupsig_key_t *src) { } if (cpy06_dst->A) { pbcext_element_G1_free(cpy06_dst->A); cpy06_dst->A = NULL; - } + } } return rc; @@ -214,7 +220,7 @@ char* cpy06_mem_key_to_string(groupsig_key_t *key) { if (A) { mem_free(A); A = NULL; } if (rc == IERROR && skey) { mem_free(skey); skey = NULL; } - + return skey; } @@ -270,7 +276,7 @@ int cpy06_mem_key_export(byte_t **bytes, __bytes = &_bytes[ctr]; if(pbcext_dump_element_G1_bytes(&__bytes, &len, cpy06_key->A) == IERROR) GOTOENDRC(IERROR, cpy06_mem_key_export); - ctr += len; + ctr += len; /* Prepare the return */ if(!*bytes) { @@ -279,7 +285,7 @@ int cpy06_mem_key_export(byte_t **bytes, memcpy(*bytes, _bytes, ctr); mem_free(_bytes); _bytes = NULL; } - + /* Sanity check */ if (ctr != _size) { LOG_ERRORCODE_MSG(&logger, __FILE__, "cpy06_mem_key_export", __LINE__, @@ -295,8 +301,8 @@ int cpy06_mem_key_export(byte_t **bytes, if(_bytes) { mem_free(_bytes); _bytes = NULL; } } - return rc; - + return rc; + } groupsig_key_t* cpy06_mem_key_import(byte_t *source, uint32_t size) { @@ -356,10 +362,10 @@ groupsig_key_t* cpy06_mem_key_import(byte_t *source, uint32_t size) { GOTOENDRC(IERROR, cpy06_mem_key_import); if(pbcext_get_element_G1_bytes(cpy06_key->A, &len, &source[ctr]) == IERROR) GOTOENDRC(IERROR, cpy06_mem_key_import); - ctr += len; + ctr += len; cpy06_mem_key_import_end: - + if(rc == IERROR && key) { cpy06_mem_key_free(key); key = NULL; } if(rc == IOK) return key; diff --git a/src/test/basic/basic.c b/src/test/basic/basic.c index 464ac21..27bf303 100644 --- a/src/test/basic/basic.c +++ b/src/test/basic/basic.c @@ -159,7 +159,7 @@ int main(int argc, char **argv) { setup_matrices(); if (!benchmark_flag) { - if (!strcmp(argv[1], "all")) + if (!strcmp(scheme, "all")) for (int i = 0; i < N_SCHEMES; i++) { printf("#### Testing %s\n", SCHEMES[i]); test_libgroupsig(SCHEMES[i]);