Skip to content

Commit

Permalink
Fixed bug in bbs04/klap20 gml export/import. Implemented function to …
Browse files Browse the repository at this point in the history
…retrieve public/private key of blind key. Added tests and benchmarks compatible with all schemas
  • Loading branch information
Sergio Chica committed Jul 1, 2024
1 parent 17a2a47 commit 07d4db8
Show file tree
Hide file tree
Showing 16 changed files with 2,219 additions and 1,843 deletions.
35 changes: 29 additions & 6 deletions src/groupsig/bbs04/gml.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ gml_t* bbs04_gml_import(byte_t *bytes, uint32_t size) {
gml_t *gml;
uint64_t i;
uint32_t read;
int entry_size, rc;
int entry_size, rc, _entry_size;

if(!bytes || !size) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_import", __LINE__, LOGERROR);
Expand All @@ -208,13 +208,15 @@ gml_t* bbs04_gml_import(byte_t *bytes, uint32_t size) {
memcpy(&gml->n, bytes, sizeof(uint64_t));
read += sizeof(uint64_t);

_entry_size = (size - read) / gml->n;

if (!(gml->entries = mem_malloc(sizeof(gml_entry_t *)*gml->n)))
GOTOENDRC(IERROR, bbs04_gml_import);

/* Import the entries one by one */
for (i=0; i<gml->n; i++) {

if (!(gml->entries[i] = bbs04_gml_entry_import(&bytes[read], size-read)))
if (!(gml->entries[i] = bbs04_gml_entry_import(&bytes[read], _entry_size)))
GOTOENDRC(IERROR, bbs04_gml_import);

if ((entry_size = bbs04_gml_entry_get_size(gml->entries[i])) == -1)
Expand Down Expand Up @@ -301,7 +303,7 @@ int bbs04_gml_entry_export(byte_t **bytes,
gml_entry_t *entry) {

byte_t *_bytes, *__bytes;
uint64_t _size, len;
uint64_t _size, len, offset;

if (!bytes || !size || !entry) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_entry_export", __LINE__, LOGERROR);
Expand All @@ -316,15 +318,25 @@ int bbs04_gml_entry_export(byte_t **bytes,

/* First, dump the identity */
memcpy(_bytes, &entry->id, sizeof(uint64_t));
offset = sizeof(uint64_t);

/* Next, dump the data, which for BBS04 is just the G1 element */
__bytes = &_bytes[sizeof(uint64_t)];
__bytes = &_bytes[offset];
if (pbcext_dump_element_G1_bytes(&__bytes,
&len,
entry->data) == IERROR) {
mem_free(_bytes); _bytes = NULL;
return IERROR;
}
offset += len;

/* Sanity check */
if (offset != _size) {
LOG_ERRORCODE_MSG(&logger, __FILE__, "bbs04_gml_entry_export", __LINE__,
EDQUOT, "Unexpected size.", LOGERROR);
mem_free(_bytes); _bytes = NULL;
return IERROR;
}

/* Prepare exit */
if (!*bytes) {
Expand All @@ -343,7 +355,7 @@ int bbs04_gml_entry_export(byte_t **bytes,
gml_entry_t* bbs04_gml_entry_import(byte_t *bytes, uint32_t size) {

gml_entry_t *entry;
uint64_t len;
uint64_t len, offset;

if (!bytes || !size) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_entry_import", __LINE__, LOGERROR);
Expand All @@ -354,6 +366,7 @@ gml_entry_t* bbs04_gml_entry_import(byte_t *bytes, uint32_t size) {

/* First, read the identity */
memcpy(&entry->id, bytes, sizeof(uint64_t));
offset = sizeof(uint64_t);

/* Next, read the data (just a G1 element) */
if(!(entry->data = pbcext_element_G1_init())) {
Expand All @@ -363,7 +376,7 @@ gml_entry_t* bbs04_gml_entry_import(byte_t *bytes, uint32_t size) {

if (pbcext_get_element_G1_bytes(entry->data,
&len,
&bytes[sizeof(uint64_t)]) == IERROR) {
&bytes[offset]) == IERROR) {
bbs04_gml_entry_free(entry); entry = NULL;
return NULL;
}
Expand All @@ -373,6 +386,16 @@ gml_entry_t* bbs04_gml_entry_import(byte_t *bytes, uint32_t size) {
return NULL;
}

offset += len;

/* Sanity check */
if (offset != size) {
LOG_ERRORCODE_MSG(&logger, __FILE__, "bbs04_gml_entry_import", __LINE__,
EDQUOT, "Unexpected size.", LOGERROR);
bbs04_gml_entry_free(entry); entry = NULL;
return NULL;
}

return entry;

}
Expand Down
58 changes: 47 additions & 11 deletions src/groupsig/bld_key.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,7 +40,7 @@ groupsig_key_t* groupsig_bld_key_init(uint8_t code) {

if(!(gkh = groupsig_bld_key_handle_from_code(code))) {
return NULL;
}
}

return gkh->init();

Expand All @@ -59,9 +59,9 @@ int groupsig_bld_key_free(groupsig_key_t *key) {
if(!(gkh = groupsig_bld_key_handle_from_code(key->scheme))) {
return IERROR;
}

gkh->free(key);

return IOK;

}
Expand All @@ -73,7 +73,7 @@ groupsig_key_t* groupsig_bld_key_random(uint8_t code, void *param) {
if(!(gkh = groupsig_bld_key_handle_from_code(code))) {
return NULL;
}

return gkh->random(param);

}
Expand Down Expand Up @@ -145,13 +145,31 @@ int groupsig_bld_key_export_pub(byte_t **dst,
__LINE__, LOGERROR);
return IERROR;
}

if(!(gkh = groupsig_bld_key_handle_from_code(key->scheme))) {
return IERROR;
}

return gkh->gexport_pub(dst, size, key);


}

int groupsig_bld_key_pub(groupsig_key_t *key, groupsig_key_t **pub) {

const bld_key_handle_t *gkh;

if(!key) {
LOG_EINVAL(&logger, __FILE__, "groupsig_bld_key_pub",
__LINE__, LOGERROR);
return IERROR;
}

if(!(gkh = groupsig_bld_key_handle_from_code(key->scheme))) {
return IERROR;
}

return gkh->pub(key, pub);

}

int groupsig_bld_key_export_prv(byte_t **dst,
Expand All @@ -164,13 +182,31 @@ int groupsig_bld_key_export_prv(byte_t **dst,
LOG_EINVAL(&logger, __FILE__, "groupsig_bld_key_export_prv", __LINE__, LOGERROR);
return IERROR;
}

if(!(gkh = groupsig_bld_key_handle_from_code(key->scheme))) {
return IERROR;
}

return gkh->gexport_prv(dst, size, key);


}

int groupsig_bld_key_prv(groupsig_key_t *key, groupsig_key_t **prv) {

const bld_key_handle_t *gkh;

if(!key) {
LOG_EINVAL(&logger, __FILE__, "groupsig_bld_key_prv",
__LINE__, LOGERROR);
return IERROR;
}

if(!(gkh = groupsig_bld_key_handle_from_code(key->scheme))) {
return IERROR;
}

return gkh->prv(key, prv);

}

groupsig_key_t* groupsig_bld_key_import(uint8_t code,
Expand Down
Loading

0 comments on commit 07d4db8

Please sign in to comment.