Skip to content

Commit

Permalink
Fix export/import error of GML in BBS04/KLAP20
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Chica committed Jun 21, 2024
1 parent c76afba commit 17a2a47
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 595 deletions.
1 change: 1 addition & 0 deletions cmake_modules/mcl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)

ExternalProject_Add(mclproject
GIT_REPOSITORY https://github.com/herumi/mcl.git
GIT_TAG v1.93
CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DMCL_TEST_WITH_GMP=OFF
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
Expand Down
72 changes: 36 additions & 36 deletions src/groupsig/bbs04/gml.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 @@ -77,7 +77,7 @@ int bbs04_gml_insert(gml_t *gml, gml_entry_t *entry) {
return IERROR;
}

if(!(gml->entries = (gml_entry_t **)
if(!(gml->entries = (gml_entry_t **)
realloc(gml->entries, sizeof(gml_entry_t *)*(gml->n+1)))) {
LOG_ERRORCODE(&logger, __FILE__, "bbs04_gml_insert", __LINE__, errno,
LOGERROR);
Expand Down Expand Up @@ -107,7 +107,7 @@ int bbs04_gml_remove(gml_t *gml, uint64_t index) {
/* Just set it to NULL */
/** @todo This will generate a lot of unused memory! Use some other ADT */
gml->entries[index] = NULL;

/* Decrement the number of entries */
gml->n--;

Expand All @@ -129,16 +129,16 @@ gml_entry_t* bbs04_gml_get(gml_t *gml, uint64_t index) {
}

return gml->entries[index];

}

int bbs04_gml_export(byte_t **bytes, uint32_t *size, gml_t *gml) {

byte_t *bentry, *_bytes;
uint64_t i;
int rc;
int rc;
uint32_t total_size, entry_size;

if (!bytes || !size || !gml || gml->scheme != GROUPSIG_BBS04_CODE) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_export", __LINE__, LOGERROR);
return IERROR;
Expand Down Expand Up @@ -181,7 +181,7 @@ int bbs04_gml_export(byte_t **bytes, uint32_t *size, gml_t *gml) {
}

if (bentry) { mem_free(bentry); bentry = NULL; }

return rc;

}
Expand All @@ -192,7 +192,7 @@ gml_t* bbs04_gml_import(byte_t *bytes, uint32_t size) {
uint64_t i;
uint32_t read;
int entry_size, rc;

if(!bytes || !size) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_import", __LINE__, LOGERROR);
return NULL;
Expand All @@ -201,7 +201,7 @@ gml_t* bbs04_gml_import(byte_t *bytes, uint32_t size) {
read = 0;
gml = NULL;
rc = IOK;

if (!(gml = bbs04_gml_init())) GOTOENDRC(IERROR, bbs04_gml_import);

/* Read the nubmer of entries to process */
Expand All @@ -216,23 +216,23 @@ gml_t* bbs04_gml_import(byte_t *bytes, uint32_t size) {

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

if ((entry_size = bbs04_gml_entry_get_size(gml->entries[i])) == -1)
GOTOENDRC(IERROR, bbs04_gml_import);

read += entry_size;

}

bbs04_gml_import_end:

if (rc == IERROR) {
bbs04_gml_free(gml);
gml = NULL;
}

return gml;

}

gml_entry_t* bbs04_gml_entry_init() {
Expand All @@ -248,7 +248,7 @@ gml_entry_t* bbs04_gml_entry_init() {
entry->scheme = GROUPSIG_BBS04_CODE;
entry->id = 0;
entry->data = NULL;

return entry;

}
Expand All @@ -257,7 +257,7 @@ gml_entry_t* bbs04_gml_entry_init() {
int bbs04_gml_entry_free(gml_entry_t *entry) {

int rc;

if(!entry) {
LOG_EINVAL_MSG(&logger, __FILE__, "bbs04_gml_entry_free", __LINE__,
"Nothing to free.", LOGWARN);
Expand All @@ -270,17 +270,17 @@ int bbs04_gml_entry_free(gml_entry_t *entry) {
rc = pbcext_element_G1_free(entry->data);
entry->data = NULL;
}
mem_free(entry);

mem_free(entry);

return rc;

}

int bbs04_gml_entry_get_size(gml_entry_t *entry) {

uint64_t sG1;

if (!entry) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_entry_get_size", __LINE__, LOGERROR);
return -1;
Expand All @@ -289,11 +289,11 @@ int bbs04_gml_entry_get_size(gml_entry_t *entry) {
if (pbcext_element_G1_byte_size(&sG1) == -1)
return -1;

if (sG1 > INT_MAX) return -1;
if (sG1 + sizeof(int) + sizeof(uint64_t) > INT_MAX) return -1;

return (int) sG1 + sizeof(int) + sizeof(uint64_t);


return (int) sG1 + sizeof(int);


}

int bbs04_gml_entry_export(byte_t **bytes,
Expand All @@ -302,16 +302,16 @@ int bbs04_gml_entry_export(byte_t **bytes,

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

if (!bytes || !size || !entry) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_entry_export", __LINE__, LOGERROR);
return IERROR;
return IERROR;
}

/* Calculate size */
if ((_size = bbs04_gml_entry_get_size(entry)) == -1) return IERROR;
_size += sizeof(int) + sizeof(uint64_t);
/* _size += sizeof(int) + sizeof(uint64_t); */

if (!(_bytes = mem_malloc(sizeof(byte_t)*_size))) return IERROR;

/* First, dump the identity */
Expand All @@ -337,7 +337,7 @@ int bbs04_gml_entry_export(byte_t **bytes,
*size = _size;

return IOK;

}

gml_entry_t* bbs04_gml_entry_import(byte_t *bytes, uint32_t size) {
Expand All @@ -347,7 +347,7 @@ gml_entry_t* bbs04_gml_entry_import(byte_t *bytes, uint32_t size) {

if (!bytes || !size) {
LOG_EINVAL(&logger, __FILE__, "bbs04_gml_entry_import", __LINE__, LOGERROR);
return NULL;
return NULL;
}

if (!(entry = bbs04_gml_entry_init())) return NULL;
Expand All @@ -360,21 +360,21 @@ gml_entry_t* bbs04_gml_entry_import(byte_t *bytes, uint32_t size) {
bbs04_gml_entry_free(entry); entry = NULL;
return NULL;
}

if (pbcext_get_element_G1_bytes(entry->data,
&len,
&bytes[sizeof(uint64_t)]) == IERROR) {
bbs04_gml_entry_free(entry); entry = NULL;
return NULL;
return NULL;
}

if (!len) {
bbs04_gml_entry_free(entry); entry = NULL;
return NULL;
return NULL;
}

return entry;

}

char* bbs04_gml_entry_to_string(gml_entry_t *entry) {
Expand All @@ -388,7 +388,7 @@ char* bbs04_gml_entry_to_string(gml_entry_t *entry) {
return NULL;
}

/* A string representation of a GML entry will be:
/* A string representation of a GML entry will be:
<id>\t<trapdoor> */

/* Get the string representations of the entry's fields */
Expand Down Expand Up @@ -418,7 +418,7 @@ char* bbs04_gml_entry_to_string(gml_entry_t *entry) {
mem_free(sdata); sdata = NULL;

return sentry;

}

/* gml.c ends here */
Loading

0 comments on commit 17a2a47

Please sign in to comment.