Skip to content

Commit

Permalink
GPSW serialization (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibsG committed Feb 8, 2021
1 parent 808672e commit e587b8f
Show file tree
Hide file tree
Showing 27 changed files with 3,716 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ jobs:
python -m pip install --upgrade pip
pip install cmake
- run:
name: Install Protobuff
command: |
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.2/protobuf-cpp-3.12.2.tar.gz
tar xvzf protobuf-cpp-3.12.2.tar.gz --no-same-owner
cd protobuf-3.12.2
./configure
make
make check
make install
ldconfig
- run:
name: Install Protobuff-c
command: |
wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.3.3/protobuf-c-1.3.3.tar.gz
tar xvzf protobuf-c-1.3.3.tar.gz --no-same-owner
cd protobuf-c-1.3.3
./configure && make && make install
- run:
name: Install AMCL
command: |
Expand Down
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,28 @@ set(library_SOURCES
src/abe/fame.c
src/abe/dippe.c
src/quadratic/sgp.c
src/serialization/fame_ser.c
src/serialization/data_ser.c
src/serialization/gpsw_ser.c
include/cifer/serialization/fame.pb-c.c
include/cifer/serialization/data.pb-c.c
include/cifer/serialization/gpsw.pb-c.c
)

add_library(cifer SHARED ${library_SOURCES})

# Link libraries that are used in our library
target_link_libraries(cifer gmp sodium m amcl)
# Search for protobuf-c library
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PBUFC "libprotobuf-c >= 1.0.0")
if (PBUFC_FOUND)
target_link_libraries(cifer ${PBUFC_LIBRARIES})
add_definitions(${PBUFC_CFLAGS} ${PBUFC_CFLAGS_OTHER})
link_directories(${PBUFC_LIBRARY_DIRS})
endif()
endif()

# Install library and copy header to install dir
install(TARGETS cifer DESTINATION lib)
Expand Down Expand Up @@ -114,6 +130,9 @@ set(binary_SOURCES
test/abe/dippe.c
external/munit/munit.c
test/quadratic/sgp.c
test/serialization/data_ser.c
test/serialization/fame_ser.c
test/serialization/gpsw_ser.c
)

add_executable(cifer_test ${binary_SOURCES})
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,25 @@ cfe_fame_generate_attrib_keys(&keys, owned_attrib, 3, &sk, &fame);
FP12_BN254 decryption;
cfe_fame_decrypt(&decryption, &cipher, &keys, &fame);
```

##### Serialize ABE material

In the example below we demonstrate how to serialize public key for ABE scheme GPSW.
The serialization is done by using [Protobuf](https://github.com/protocolbuffers/protobuf)
library, converting CiFEr structures to a single array of bytes.
The serialization is currently available for ABE schemes FAME and GPSW.
```c
// create GPSW structure
cfe_gpsw gpsw;
cfe_gpsw_init(&gpsw, 10);

// create and init GPSW master keys
cfe_gpsw_pub_key pk;
cfe_vec sk;
cfe_gpsw_master_keys_init(&pk, &sk, &gpsw);
cfe_gpsw_generate_master_keys(&pk, &sk, &gpsw);

// serialize public key into a buffer of bytes
cfe_ser buf;
cfe_gpsw_pub_key_ser(&pk, &buf);
```
25 changes: 25 additions & 0 deletions include/cifer/data/vec_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ typedef struct cfe_vec_GT {
size_t size; /** The size of the vector */
} cfe_vec_GT;

/**
* Vector of octets elements.
*/
typedef struct cfe_vec_octet {
octet *vec; /** A pointer to the first element */
size_t size; /** The size of the vector */
} cfe_vec_octet;

/**
* Initializes a vector of ECP_BN254 elements of given size.
*
Expand Down Expand Up @@ -178,4 +186,21 @@ void cfe_vec_G2_free(cfe_vec_G2 *v);
*/
void cfe_vec_GT_free(cfe_vec_GT *v);

/**
* Initializes a vector of octet elements of given size.
*
* @param v A pointer to an uninitialized cfe_vec_G1 vector
* @param size Size of the vector
*/
void cfe_vec_octet_init(cfe_vec_octet *v, size_t size);

/**
* Frees the memory occupied by the struct members. It does not free
* memory occupied by the struct itself.
*
* @param v A pointer to a vector (*initialized*
* cfe_vec_octet struct)
*/
void cfe_vec_octet_free(cfe_vec_octet *v);

#endif
Loading

0 comments on commit e587b8f

Please sign in to comment.