├── src ├── wrappers │ ├── python │ │ ├── tests │ │ │ └── __init__.py │ │ ├── .coveragerc │ │ ├── codecov.yml │ │ ├── pygroupsig │ │ │ ├── common_build.py │ │ │ ├── __init__.py │ │ │ ├── types_build.py │ │ │ ├── constants.py │ │ │ ├── proof.py │ │ │ ├── message_build.py │ │ │ ├── trapdoor_build.py │ │ │ ├── exim_build.py │ │ │ ├── grpkey.py │ │ │ ├── mgrkey.py │ │ │ ├── identity_build.py │ │ │ ├── bbs04_build.py │ │ │ ├── blindsig.py │ │ │ ├── memkey.py │ │ │ ├── signature.py │ │ │ ├── gml.py │ │ │ ├── ps16_build.py │ │ │ ├── identity.py │ │ │ ├── proof_build.py │ │ │ ├── message.py │ │ │ ├── gl19_build.py │ │ │ ├── klap20_build.py │ │ │ ├── blindsig_build.py │ │ │ ├── signature_build.py │ │ │ ├── key_build.py │ │ │ ├── crl_build.py │ │ │ ├── mem_key_build.py │ │ │ ├── mgr_key_build.py │ │ │ ├── bldkey.py │ │ │ └── grp_key_build.py │ │ ├── samples │ │ │ ├── hello.py │ │ │ ├── sign.py │ │ │ ├── unblind.py │ │ │ ├── join-mem-seq1.py │ │ │ ├── join-mem-seq3.py │ │ │ ├── sign_bbs04.py │ │ │ ├── sign_gl19.py │ │ │ └── blind.py │ │ ├── README.md │ │ ├── Dockerfile │ │ └── setup.py │ ├── nodejs │ │ ├── server │ │ │ ├── .babelrc │ │ │ ├── src │ │ │ │ ├── routes │ │ │ │ │ └── index.js │ │ │ │ ├── models │ │ │ │ │ ├── index.js │ │ │ │ │ ├── member.js │ │ │ │ │ └── group.js │ │ │ │ └── index.js │ │ │ ├── .env │ │ │ ├── mocks │ │ │ │ ├── behavior.js │ │ │ │ └── fixtures │ │ │ │ │ └── pki.js │ │ │ ├── postman │ │ │ │ └── libgroupsig-local.postman_environment.json │ │ │ ├── Dockerfile │ │ │ └── package.json │ │ ├── jsgroupsig │ │ │ ├── README.md │ │ │ ├── cmake_modules │ │ │ │ └── libgroupsig.cmake │ │ │ ├── CMakeLists.txt │ │ │ ├── package.json │ │ │ └── src │ │ │ │ └── base64.h │ │ └── samples │ │ │ ├── sign_gl19.js │ │ │ └── sign_bbs04.js │ └── java │ │ └── jgroupsig │ │ ├── java │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── ibm │ │ │ └── jgroupsig │ │ │ ├── Util.java │ │ │ ├── Gml.java │ │ │ ├── Proof.java │ │ │ └── GrpKey.java │ │ ├── pom.xml │ │ └── samples │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── ibm │ │ └── jgroupsig │ │ └── executable │ │ ├── SignBBS04.java │ │ ├── Sign.java │ │ └── Unblind.java ├── logger │ └── CMakeLists.txt ├── sys │ ├── CMakeLists.txt │ ├── mem.c │ └── mem.h ├── msg │ └── CMakeLists.txt ├── math │ ├── CMakeLists.txt │ ├── rnd.h │ ├── perm.h │ ├── rnd.c │ └── perm.c ├── crypto │ └── CMakeLists.txt ├── misc │ ├── CMakeLists.txt │ └── profile.h ├── tools │ ├── process-benchmarks.sh │ ├── parse-prof.sh │ └── plot.gnp ├── groupsig │ ├── bbs04 │ │ ├── CMakeLists.txt │ │ ├── update_env.c │ │ ├── env.c │ │ ├── claim_verify.c │ │ ├── claim.c │ │ └── join_mem.c │ ├── ps16 │ │ ├── CMakeLists.txt │ │ └── open_verify.c │ ├── klap20 │ │ ├── CMakeLists.txt │ │ └── open_verify.c │ ├── dl21 │ │ └── CMakeLists.txt │ ├── gl19 │ │ ├── CMakeLists.txt │ │ └── env.c │ ├── dl21seq │ │ └── CMakeLists.txt │ ├── kty04 │ │ ├── CMakeLists.txt │ │ ├── claim_verify.c │ │ ├── claim.c │ │ ├── trace.c │ │ ├── reveal.c │ │ └── join_mem.c │ ├── cpy06 │ │ ├── CMakeLists.txt │ │ ├── update_env.c │ │ ├── env.c │ │ ├── claim_verify.c │ │ ├── claim.c │ │ ├── reveal.c │ │ └── trace.c │ ├── CMakeLists.txt │ └── trapdoor.c ├── shim │ ├── CMakeLists.txt │ ├── base64.h │ └── rsa.h ├── include │ ├── registered_groupsigs.h │ ├── bld_key_handles.h │ ├── crl_handles.h │ ├── blindsig_handles.h │ ├── trapdoor_handles.h │ ├── big.h │ ├── gml_handles.h │ ├── identity_handles.h │ ├── proof_handles.h │ ├── mem_key_handles.h │ ├── grp_key_handles.h │ ├── mgr_key_handles.h │ └── signature_handles.h └── test │ └── CMakeLists.txt ├── codecov.yml ├── .github └── codecov.yml ├── NOTICE ├── CMakeLists.txt.in ├── FindGMP.cmake ├── cmake_modules ├── mcl.cmake ├── gtest.cmake └── gcovr.cmake ├── FindMCL.cmake ├── README.md ├── Changelog └── CMakeLists.txt /src/wrappers/python/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | fixes: 2 | - "/home/runner/work/libgroupsig/::" 3 | -------------------------------------------------------------------------------- /src/logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # liblogger 2 | add_library (logger logger.c) 3 | -------------------------------------------------------------------------------- /src/wrappers/python/.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = pygroupsig/*_build.py,setup.py 3 | -------------------------------------------------------------------------------- /src/sys/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libsys 2 | add_library (sys 3 | mem.c 4 | sysenv.c 5 | mem.h) 6 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/src/routes/index.js: -------------------------------------------------------------------------------- 1 | import group from './group'; 2 | 3 | export default { 4 | group, 5 | }; 6 | -------------------------------------------------------------------------------- /src/wrappers/python/codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | fixes: 3 | - "pygroupsig/::src/groupsig/wrappers/python/pygroupsig/" 4 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/common_build.py: -------------------------------------------------------------------------------- 1 | # file "common_build.py" 2 | 3 | from cffi import FFI 4 | ffibuilder = FFI() 5 | -------------------------------------------------------------------------------- /src/msg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libmsg 2 | add_library (msg message.c) #misc.c misc.h message.c) 3 | target_link_libraries (msg base64) 4 | -------------------------------------------------------------------------------- /src/math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libmath 2 | add_library (math nt.c rnd.c perm.c nt.h rnd.h perm.h) 3 | target_link_libraries (math big m) 4 | -------------------------------------------------------------------------------- /src/wrappers/python/samples/hello.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from pygroupsig import groupsig 4 | 5 | groupsig.hello_world() 6 | 7 | -------------------------------------------------------------------------------- /src/crypto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libgcrypto 2 | add_library (gcrypto spk.c prf.c) 3 | target_link_libraries (gcrypto PRIVATE ${OPENSSL_LIBRARIES}) 4 | -------------------------------------------------------------------------------- /.github/codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | fixes: 3 | - "pygroupsig/::src/wrappers/python/pygroupsig/" 4 | codecov: 5 | disable_default_path_fixes: false 6 | -------------------------------------------------------------------------------- /src/misc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library (misc 2 | misc.c 3 | misc.h 4 | profile.c 5 | profile.h) 6 | 7 | target_link_libraries (misc PUBLIC base64 m) 8 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache libgroupsig 2 | Copyright [2019-2020] The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /src/wrappers/python/README.md: -------------------------------------------------------------------------------- 1 | Python wrapper for libgroupsig, a library for group signatures. 2 | 3 | Please go to [the Github repository](https://github.com/IBM/libgroupsig) for more information. 4 | -------------------------------------------------------------------------------- /src/tools/process-benchmarks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | schemes="BBS04 GL19 PS16 KLAP20 DL21 DL21SEQ" 4 | for scheme in $schemes; do 5 | awk -v scheme="$scheme" '$1==scheme { print $2, $5, $6 }' $1 > "$scheme.log" 6 | done 7 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = [ 2 | "groupsig", 3 | "grpkey", 4 | "mgrkey", 5 | "memkey", 6 | "bldkey", 7 | "signature", 8 | "blindsig", 9 | "gml", 10 | "message", 11 | "constants" 12 | ] 13 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/jsgroupsig/README.md: -------------------------------------------------------------------------------- 1 | A native addon of libgroupsig (a library for group signatures) for NodeJS. 2 | 3 | It is built using cmake-js, so you need a local installation of CMake in order 4 | to install it. 5 | 6 | Please go to [the Github repo](https://github.com/IBM/libgroupsig/wiki) for 7 | more information, including a tutorial on how to use it. 8 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/.env: -------------------------------------------------------------------------------- 1 | PORT=3000 2 | PORT_ISSUER=3000 3 | PORT_CONVERTER=3001 4 | 5 | DATABASE=groupsig 6 | DATABASE_USER=groupsig 7 | DATABASE_PASSWORD=groupsig 8 | 9 | PKI_CHECK=false 10 | PKI_ENDPOINT="http://localhost:3100/cert/verify" 11 | PKI_APIKEY="1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" 12 | 13 | API_VERSION=v1 14 | -------------------------------------------------------------------------------- /src/tools/parse-prof.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | awk ' 4 | BEGIN { 5 | t=0 6 | } 7 | { 8 | t=(t+$2-$1); 9 | s[NR]=($2-$1); 10 | } 11 | END { 12 | avg = t/NR; 13 | std = 0; 14 | for (i=0; i { 18 | if ('associate' in models[key]) { 19 | models[key].associate(models); 20 | } 21 | }); 22 | 23 | export { sequelize }; 24 | 25 | export default models; 26 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/constants.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | 3 | IERROR = lib.IERROR 4 | IOK = lib.IOK 5 | GL19_CODE = lib.GROUPSIG_GL19_CODE 6 | GL19_JOIN_START = lib.GL19_JOIN_START 7 | GL19_JOIN_SEQ = lib.GL19_JOIN_SEQ 8 | BBS04_CODE = lib.GROUPSIG_BBS04_CODE 9 | BBS04_JOIN_START = lib.BBS04_JOIN_START 10 | BBS04_JOIN_SEQ = lib.BBS04_JOIN_SEQ 11 | PS16_CODE = lib.GROUPSIG_PS16_CODE 12 | PS16_JOIN_START = lib.PS16_JOIN_START 13 | PS16_JOIN_SEQ = lib.PS16_JOIN_SEQ 14 | KLAP20_CODE = lib.GROUPSIG_KLAP20_CODE 15 | KLAP20_JOIN_START = lib.KLAP20_JOIN_START 16 | KLAP20_JOIN_SEQ = lib.KLAP20_JOIN_SEQ 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/groupsig/dl21seq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories ("${PROJECT_SOURCE_DIR}/src/include" 2 | "${PROJECT_SOURCE_DIR}/src") 3 | 4 | add_library (dl21seq 5 | grp_key.c grp_key.h 6 | mgr_key.c mgr_key.h 7 | mem_key.c mem_key.h 8 | signature.c signature.h 9 | setup.c 10 | join_mem.c 11 | join_mgr.c 12 | sign.c 13 | verify.c 14 | identify.c 15 | link.c 16 | verify_link.c 17 | seqlink.c 18 | verify_seqlink.c 19 | proof.c proof.h 20 | identity.c identity.h) 21 | 22 | target_include_directories (dl21seq PRIVATE ${OPENSSL_INCLUDE_DIR}) 23 | target_link_libraries (dl21seq ${OPENSSL_LIBRARIES}) 24 | -------------------------------------------------------------------------------- /src/groupsig/kty04/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories ("${PROJECT_SOURCE_DIR}/src/include" 2 | "${PROJECT_SOURCE_DIR}/src/global") 3 | 4 | add_library (libkty04 grp_key.c grp_key.h mgr_key.c mgr_key.h mem_key.c 5 | mem_key.h signature.c signature.h sphere.c sphere.h setup.c 6 | join_mem.c join_mgr.c sign.c verify.c open.c reveal.c trace.c claim.c 7 | claim_verify.c prove_equality.c prove_equality_verify.c gml.c gml.h 8 | crl.c crl.h proof.c proof.h identity.c identity.h trapdoor.c trapdoor.h) 9 | 10 | target_include_directories (libkty04 PRIVATE ${OPENSSL_INCLUDE_DIR}) 11 | target_link_libraries (libkty04 PRIVATE ${OPENSSL_LIBRARIES}) 12 | -------------------------------------------------------------------------------- /FindGMP.cmake: -------------------------------------------------------------------------------- 1 | set(GMP_PREFIX "" CACHE PATH "path ") 2 | 3 | 4 | find_path(GMP_INCLUDE_DIR gmp.h gmpxx.h 5 | PATHS ${GMP_PREFIX}/include /usr/include /usr/local/include ) 6 | 7 | find_library(GMP_LIBRARY NAMES gmp libgmp 8 | PATHS ${GMP_PREFIX}/lib /usr/lib /usr/local/lib) 9 | 10 | 11 | if(GMP_INCLUDE_DIR AND GMP_LIBRARY) 12 | get_filename_component(GMP_LIBRARY_DIR ${GMP_LIBRARY} PATH) 13 | set(GMP_FOUND TRUE) 14 | endif() 15 | 16 | if(GMP_FOUND) 17 | if(NOT GMP_FIND_QUIETLY) 18 | MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}") 19 | endif() 20 | elseif(GMP_FOUND) 21 | if(GMP_FIND_REQUIRED) 22 | message(FATAL_ERROR "Could not find GMP") 23 | endif() 24 | endif() 25 | -------------------------------------------------------------------------------- /cmake_modules/mcl.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external) 3 | 4 | ExternalProject_Add(mclproject 5 | GIT_REPOSITORY https://github.com/herumi/mcl.git 6 | CMAKE_ARGS 7 | -DMCL_USE_GMP=OFF 8 | -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} 9 | -DCMAKE_INSTALL_RPATH=${EXTERNAL_INSTALL_LOCATION}/lib 10 | -DCMAKE_CXX_FLAGS=-fPIC 11 | INSTALL_COMMAND make install 12 | ) 13 | 14 | install(DIRECTORY "${EXTERNAL_INSTALL_LOCATION}/include" DESTINATION ${CMAKE_INSTALL_PREFIX}) 15 | install(DIRECTORY "${EXTERNAL_INSTALL_LOCATION}/lib" DESTINATION ${CMAKE_INSTALL_PREFIX}) 16 | 17 | # Set variables for libgroupsig building 18 | set(MCL_LIBRARY mcl) 19 | set(MCL384_256_LIBRARY mclbn384_256) 20 | -------------------------------------------------------------------------------- /src/groupsig/cpy06/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories ("${PROJECT_SOURCE_DIR}/src/include" 2 | "${PROJECT_SOURCE_DIR}/src/global") 3 | 4 | add_library (libcpy06 5 | grp_key.c grp_key.h 6 | mgr_key.c mgr_key.h 7 | mem_key.c mem_key.h 8 | signature.c signature.h 9 | setup.c 10 | join_mem.c 11 | join_mgr.c 12 | sign.c 13 | verify.c 14 | open.c 15 | reveal.c 16 | trace.c 17 | claim.c 18 | claim_verify.c 19 | prove_equality.c 20 | prove_equality_verify.c 21 | gml.c gml.h 22 | crl.c crl.h 23 | proof.c proof.h 24 | identity.c identity.h 25 | trapdoor.c trapdoor.h 26 | env.c) 27 | 28 | target_include_directories (libcpy06 PRIVATE ${OPENSSL_INCLUDE_DIR}) 29 | target_link_libraries (libcpy06 PRIVATE ${OPENSSL_LIBRARIES}) 30 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/src/models/member.js: -------------------------------------------------------------------------------- 1 | const member = (sequelize, DataTypes) => { 2 | const Member = sequelize.define('member', { 3 | seq: { 4 | type: DataTypes.INTEGER, 5 | unique: false, 6 | allowNull: false, 7 | validate: { 8 | notEmpty: true, 9 | }, 10 | }, 11 | challenge: { 12 | type: DataTypes.TEXT, 13 | unique: true, 14 | allowNull: false, 15 | validate: { 16 | notEmpty: true, 17 | }, 18 | }, 19 | }); 20 | 21 | Member.associate = models => { 22 | Member.belongsTo(models.Group); 23 | }; 24 | 25 | Member.findByChallenge = async chal => { 26 | let member = await Member.findOne({ 27 | where: { challenge: chal }, 28 | }); 29 | return member; 30 | }; 31 | 32 | return Member; 33 | }; 34 | 35 | export default member; 36 | -------------------------------------------------------------------------------- /src/wrappers/python/samples/sign.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from pygroupsig import groupsig 4 | from pygroupsig import signature 5 | from pygroupsig import blindsig 6 | from pygroupsig import memkey 7 | from pygroupsig import grpkey 8 | from pygroupsig import mgrkey 9 | from pygroupsig import bldkey 10 | from pygroupsig import constants 11 | 12 | if len(sys.argv) != 4: 13 | print ("Usage: $python3 sign.py "); 14 | sys.exit(); 15 | 16 | # Init scheme 17 | groupsig.init(constants.GL19_CODE, 0) 18 | 19 | # Import grpkey 20 | gpk = grpkey.grpkey_import(constants.GL19_CODE, sys.argv[1]) 21 | 22 | # Import mem key 23 | usk = memkey.memkey_import(constants.GL19_CODE, sys.argv[2]) 24 | 25 | # Read file 26 | sig = groupsig.sign(sys.argv[3], usk, gpk) 27 | 28 | ssig = signature.signature_export(sig) 29 | print("Signature: %s" % ssig) 30 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/postman/libgroupsig-local.postman_environment.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "2a189aa7-9e31-4640-86d9-f1d9412ddfce", 3 | "name": "libgroupsig-local", 4 | "values": [ 5 | { 6 | "key": "url", 7 | "value": "localhost", 8 | "enabled": true 9 | }, 10 | { 11 | "key": "port", 12 | "value": "3000", 13 | "enabled": true 14 | }, 15 | { 16 | "key": "version", 17 | "value": "v1", 18 | "enabled": true 19 | }, 20 | { 21 | "key": "GL19_CODE", 22 | "value": "3", 23 | "enabled": true 24 | }, 25 | { 26 | "key": "port-issuer", 27 | "value": "3000", 28 | "enabled": true 29 | }, 30 | { 31 | "key": "port-converter", 32 | "value": "3001", 33 | "enabled": true 34 | } 35 | ], 36 | "_postman_variable_scope": "environment", 37 | "_postman_exported_at": "2021-08-10T11:48:48.999Z", 38 | "_postman_exported_using": "Postman/7.36.5" 39 | } -------------------------------------------------------------------------------- /src/wrappers/python/samples/unblind.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from pygroupsig import groupsig 4 | from pygroupsig import bldkey 5 | from pygroupsig import blindsig 6 | from pygroupsig import constants 7 | 8 | if len(sys.argv) != 4: 9 | print ("Usage: $python blind.py "); 10 | sys.exit(); 11 | 12 | groupsig.init(constants.GL19_CODE, 0) 13 | 14 | # Import blinding key 15 | bsk = bldkey.bldkey_import(constants.GL19_CODE, sys.argv[1]) 16 | 17 | # Import converted signatures 18 | csig1 = blindsig.blindsig_import(constants.GL19_CODE, sys.argv[2]) 19 | csig2 = blindsig.blindsig_import(constants.GL19_CODE, sys.argv[3]) 20 | 21 | # Unblind 22 | nym1 = groupsig.unblind(csig1, bsk) 23 | nym2 = groupsig.unblind(csig2, bsk) 24 | 25 | print ("Sig1:\n\tNym: %s\n\tMessage: %s" % (nym1['nym'], nym1['msg'])) 26 | print ("Sig2:\n\tNym: %s\n\tMessage: %s" % (nym2['nym'], nym2['msg'])) 27 | -------------------------------------------------------------------------------- /src/tools/plot.gnp: -------------------------------------------------------------------------------- 1 | set terminal png size 1024,1024 2 | set output 'measurements.png' 3 | set style data histograms 4 | set style fill solid 1 border lt -1 5 | set boxwidth 0.9 6 | set xlabel "Operation" font ", 20" rotate by 0 offset 0,-0.5,0 7 | set xtics noenhanced rotate by 30 right font ", 15" offset 0,-0.1,0 8 | set yrange [0:*] 9 | set ylabel "Time (ms)" font ", 20" offset -0.1,0,0 10 | set ytics font ", 15" 11 | set key left font ", 12" 12 | set style histogram errorbars lw 1 13 | plot 'BBS04.log' using ($2/1000):($3/1000):xtic(1) title "BBS04", \ 14 | 'GL19.log' using ($2/1000):($3/1000):xtic(1) title "GL19", \ 15 | 'PS16.log' using ($2/1000):($3/1000):xtic(1) title "PS16", \ 16 | 'KLAP20.log' using ($2/1000):($3/1000):xtic(1) title "KLAP20", \ 17 | 'DL21.log' using ($2/1000):($3/1000):xtic(1) title "DL21", \ 18 | 'DL21SEQ.log' using ($2/1000):($3/1000):xtic(1) title "DL21SEQ" 19 | 20 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/java/src/main/java/com/ibm/jgroupsig/Util.java: -------------------------------------------------------------------------------- 1 | package com.ibm.jgroupsig; 2 | 3 | import java.net.URL; 4 | import java.io.File; 5 | import java.io.InputStream; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | 9 | public class Util { 10 | 11 | public Util () {}; 12 | 13 | public static void LoadNativeLib(String libName) { 14 | 15 | try { 16 | URL url = Util.class.getResource("/" + libName); 17 | File tmpDir = Files.createTempDirectory(libName).toFile(); 18 | tmpDir.deleteOnExit(); 19 | File nativeLibTmpFile = new File(tmpDir, libName); 20 | nativeLibTmpFile.deleteOnExit(); 21 | InputStream in = url.openStream(); 22 | Files.copy(in, nativeLibTmpFile.toPath()); 23 | System.load(nativeLibTmpFile.getAbsolutePath()); 24 | } catch (IOException ioe) { 25 | ioe.printStackTrace(); 26 | } 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cmake_modules/gtest.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external) 3 | 4 | ExternalProject_Add(gtest-project 5 | GIT_REPOSITORY https://github.com/google/googletest.git 6 | CMAKE_ARGS 7 | -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} 8 | -DCMAKE_INSTALL_RPATH=${EXTERNAL_INSTALL_LOCATION}/lib 9 | -DCMAKE_CXX_FLAGS=-fPIC 10 | INSTALL_COMMAND make install 11 | ) 12 | 13 | install(DIRECTORY "${EXTERNAL_INSTALL_LOCATION}/include" DESTINATION ${CMAKE_INSTALL_PREFIX}) 14 | install(DIRECTORY "${EXTERNAL_INSTALL_LOCATION}/lib" DESTINATION ${CMAKE_INSTALL_PREFIX}) 15 | 16 | SET(GCC_TEST_COMPILE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") 17 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") 18 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_TEST_COMPILE_FLAGS}" ) 19 | 20 | enable_testing() 21 | add_subdirectory(${PROJECT_SOURCE_DIR}/src/test) 22 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | com.ibm.jgroupsig 7 | jgroupsig 8 | 1.1.0 9 | pom 10 | 11 | jgroupsig 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | UTF-8 18 | 19 | 20 | 21 | jni 22 | java 23 | samples 24 | 25 | 26 | -------------------------------------------------------------------------------- /FindMCL.cmake: -------------------------------------------------------------------------------- 1 | find_package(PkgConfig) 2 | set(MCL_PREFIX "${CMAKE_BINARY_DIR}/mcl" CACHE PATH "path ") 3 | 4 | message(${MCL_PREFIX}) 5 | 6 | find_path(MCL_INCLUDE_DIR 7 | NAMES bn.h 8 | PATHS ${MCL_PREFIX})#/include/mcl /usr/include/mcl /usr/local/include/mcl) 9 | 10 | find_library(MCL_LIBRARY 11 | NAMES mcl # mcl mclbn384_256 #libmcl #libmclbn384_256 12 | PATHS ${MCL_PREFIX}/lib)# /usr/lib /usr/local/lib) 13 | 14 | find_library(MCL384_256_LIBRARY 15 | NAMES mclbn384_256 16 | PATHS ${MCL_PREFIX}/lib)# /usr/lib /usr/local/lib) 17 | 18 | if(MCL_INCLUDE_DIR AND MCL_LIBRARY) 19 | get_filename_component(MCL_LIBRARY_DIR ${MCL_LIBRARY} PATH) 20 | set(MCL_FOUND TRUE) 21 | endif() 22 | 23 | if(MCL_FOUND) 24 | set(MCL_INCLUDE_DIRS ${MCL_INCLUDE_DIR}) 25 | if(NOT MCL_FIND_QUIETLY) 26 | MESSAGE(STATUS "Found MCL: ${MCL_LIBRARY}") 27 | endif() 28 | elseif(MCL_FOUND) 29 | if(MCL_FIND_REQUIRED) 30 | message(FATAL_ERROR "Could not find MCL") 31 | endif() 32 | endif() 33 | -------------------------------------------------------------------------------- /src/wrappers/python/samples/join-mem-seq1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | 4 | from pygroupsig import groupsig 5 | from pygroupsig import memkey 6 | from pygroupsig import grpkey 7 | from pygroupsig import message 8 | from pygroupsig import constants 9 | 10 | if len(sys.argv) != 3: 11 | print ("Usage: $python3 join-mem-seq1.py "); 12 | sys.exit(); 13 | 14 | # Init scheme 15 | groupsig.init(constants.GL19_CODE, 0) 16 | 17 | # Import grpkey from the string received from the command line 18 | gpk = grpkey.grpkey_import(constants.GL19_CODE, sys.argv[1]) 19 | 20 | # Run second join member operation 21 | msgin = message.message_from_base64(sys.argv[2]); 22 | msgout = groupsig.join_mem(1, gpk, msgin = msgin) 23 | usk = msgout['memkey'] 24 | 25 | # Print the challenge response and the temporary key 26 | response = msgout['msgout'] 27 | print("Response: %s" % message.message_to_base64(response)); 28 | print("Temporary member key: %s" % memkey.memkey_export(usk)); 29 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:lts-buster-slim 2 | 3 | # Copy the server files 4 | RUN mkdir /opt/server 5 | WORKDIR /opt/server 6 | COPY ./ /opt/server/ 7 | 8 | # Install and configure postgresql, and build the server (all in one line to save docker layers) 9 | RUN apt update && apt install postgresql cmake build-essential git libssl-dev -y 10 | RUN sed -i -e "s/local\s\{1,\}all\s\{1,\}postgres\s\{1,\}peer/local\tall\t\tall\t\t\t\t\ttrust/" /etc/postgresql/11/main/pg_hba.conf 11 | RUN service postgresql start && \ 12 | psql -U postgres -c "CREATE USER groupsig WITH PASSWORD 'groupsig';" && \ 13 | psql -U postgres -c "CREATE DATABASE groupsig;" && \ 14 | psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE groupsig to groupsig;" && \ 15 | npm install && \ 16 | apt purge cmake build-essential git -y 17 | 18 | RUN echo '#!/bin/bash\nport=$1\n\nif [ -z "$port" ]; then\n\tport=3000\nfi\n\nservice postgresql start\nPORT=$port npm start' > start.sh 19 | 20 | ENTRYPOINT ["bash", "start.sh"] 21 | -------------------------------------------------------------------------------- /src/wrappers/python/samples/join-mem-seq3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | 5 | from pygroupsig import groupsig 6 | from pygroupsig import memkey 7 | from pygroupsig import grpkey 8 | from pygroupsig import message 9 | from pygroupsig import constants 10 | 11 | if len(sys.argv) != 4: 12 | print ("Usage: $python3 join-seq3.py ") 13 | sys.exit() 14 | 15 | # Init scheme 16 | groupsig.init(constants.GL19_CODE, 0) 17 | 18 | # Import grpkey from the string received from the command line 19 | gpk = grpkey.grpkey_import(constants.GL19_CODE, sys.argv[1]) 20 | 21 | # Import initial member key 22 | usk = memkey.memkey_import(constants.GL19_CODE, sys.argv[2]) 23 | 24 | # Run second join member operation 25 | msgin = message.message_from_base64(sys.argv[3])#.encode()) 26 | msgout = groupsig.join_mem(3, gpk, msgin = msgin, memkey = usk) 27 | usk = msgout['memkey'] 28 | 29 | # Print the challenge response and the temporary key 30 | print("Member key: %s" % memkey.memkey_export(usk)) 31 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/jsgroupsig/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project (jsgroupsig) 3 | 4 | # Add modules 5 | list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules) 6 | 7 | # Install libgroupsig 8 | include(libgroupsig) 9 | 10 | include_directories( 11 | build/external/include/groupsig) 12 | 13 | link_directories( 14 | build/external/lib 15 | build/libgroupsig-prefix/src/libgroupsig-build/external/lib) 16 | 17 | file(GLOB SOURCE_C_FILES "src/*") 18 | #file(GLOB SOURCE_JS_FILES "lib/*") 19 | 20 | add_library(${PROJECT_NAME} 21 | SHARED 22 | ${SOURCE_C_FILES} 23 | ${SOURCE_JS_FILES}) 24 | 25 | add_dependencies(${PROJECT_NAME} libgroupsig) 26 | 27 | set_target_properties(${PROJECT_NAME} 28 | PROPERTIES PREFIX "" SUFFIX ".node") 29 | target_include_directories(${PROJECT_NAME} 30 | PRIVATE 31 | "${CMAKE_SOURCE_DIR}/node_modules/node-addon-api") 32 | target_link_libraries(${PROJECT_NAME} 33 | PUBLIC 34 | groupsig) 35 | 36 | #target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}) 37 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/proof.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def proof_export(proof): 6 | 7 | bproof = ffi.new("byte_t **") 8 | bproof[0] = ffi.NULL 9 | size = ffi.new("uint32_t *") 10 | if lib.groupsig_proof_export(bproof, size, proof) == constants.IERROR: 11 | raise Exception('Error exporting proof.') 12 | b64proof = base64.b64encode(ffi.buffer(bproof[0], size[0])) 13 | # lib.free(bproof[0]) 14 | return b64proof 15 | 16 | def proof_import(code, b64proof): 17 | 18 | b = base64.b64decode(b64proof) 19 | proof = lib.groupsig_proof_import(code, b, len(b)) 20 | if proof == ffi.NULL: 21 | raise Exception('Error importing proof.') 22 | return proof 23 | 24 | def proof_to_string(proof): 25 | 26 | _str = ffi.new("char *") 27 | _str = lib.groupsig_proof_to_string(proof) 28 | if _str == ffi.NULL: 29 | raise Exception('Error converting proof to string.') 30 | return ffi.string(_str).decode('utf8') 31 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/src/models/group.js: -------------------------------------------------------------------------------- 1 | const group = (sequelize, DataTypes) => { 2 | const Group = sequelize.define('group', { 3 | code: { 4 | type: DataTypes.INTEGER, 5 | unique: false, 6 | allowNull: false, 7 | validate: { 8 | notEmpty: true, 9 | }, 10 | }, 11 | grpkey: { 12 | type: DataTypes.TEXT, 13 | unique: true, 14 | allowNull: false, 15 | validate: { 16 | notEmpty: true, 17 | }, 18 | }, 19 | mgrkey: { 20 | type: DataTypes.TEXT, 21 | unique: true, 22 | allowNull: false, 23 | validate: { 24 | notEmpty: true, 25 | }, 26 | }, 27 | }); 28 | 29 | Group.associate = models => { 30 | Group.hasMany(models.Member, { onDelete: 'CASCADE' }); 31 | }; 32 | 33 | Group.findByGroupKey = async grpkey => { 34 | let group = await Group.findOne({ 35 | where: { grpkey: grpkey }, 36 | }); 37 | 38 | return group; 39 | }; 40 | 41 | return Group; 42 | }; 43 | 44 | export default group; 45 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/jsgroupsig/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsgroupsig", 3 | "author": "Jesus Diaz Vico", 4 | "email": "jdv@zurich.ibm.com", 5 | "version": "1.1.0", 6 | "description": "Node.js wrapper for libgroupsig, a library for group signatures", 7 | "main": "./lib/index.js", 8 | "dependencies": { 9 | "bindings": "~1.2.1", 10 | "cmake-js": "^6.1.0", 11 | "install": "^0.13.0", 12 | "npm": "^6.14.6" 13 | }, 14 | "scripts": { 15 | "install": "cmake-js compile", 16 | "test": "nyc --reporter=lcov --reporter=clover ./node_modules/.bin/mocha --reporter spec" 17 | }, 18 | "devDependencies": { 19 | "chai": "^4.2.0", 20 | "mocha": "^8.0.1", 21 | "nyc": "^15.1.0" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/IBM/libgroupsig.git" 26 | }, 27 | "homepage": "https://github.com/IBM/libgroupsig.git", 28 | "keywords": [ 29 | "Group signatures", 30 | "Cryptography", 31 | "Privacy" 32 | ], 33 | "license": "Apache-2.0" 34 | } 35 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "libgroupsig-server", 3 | "version": "0.0.0", 4 | "description": "REST interface for several libgroupsig operations.", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "nodemon --exec babel-node src/index.js", 8 | "test": "mocha --require @babel/register src/tests/*.js --exit", 9 | "mocks": "mocks-server" 10 | }, 11 | "author": "", 12 | "license": "Apache-2.0", 13 | "devDependencies": { 14 | "@babel/core": "^7.10.2", 15 | "@babel/node": "^7.10.1", 16 | "@babel/preset-env": "^7.10.2", 17 | "babel-core": "^7.0.0-bridge.0", 18 | "chai": "^4.2.0", 19 | "chai-http": "^4.3.0", 20 | "jsgroupsig": "^1.0.0", 21 | "mocha": "^8.2.1", 22 | "nodemon": "^2.0.4", 23 | "request": "^2.88.2" 24 | }, 25 | "dependencies": { 26 | "@mocks-server/main": "^1.8.7", 27 | "axios": "^0.21.0", 28 | "cors": "^2.8.5", 29 | "dotenv": "^8.2.0", 30 | "express": "^4.17.1", 31 | "node-addon-api": "^3.1.0", 32 | "pg": "^8.2.1", 33 | "sequelize": "^5.21.11" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/wrappers/python/samples/sign_bbs04.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from pygroupsig import groupsig 3 | from pygroupsig import signature 4 | from pygroupsig import memkey 5 | from pygroupsig import grpkey 6 | from pygroupsig import mgrkey 7 | from pygroupsig import gml 8 | from pygroupsig import identity 9 | from pygroupsig import constants 10 | 11 | # Setup 12 | bbs04 = groupsig.setup(constants.BBS04_CODE) 13 | gpk = bbs04['grpkey'] 14 | msk = bbs04['mgrkey'] 15 | gml = bbs04['gml'] 16 | 17 | # Join 18 | msg1 = groupsig.join_mgr(0, msk, gpk, gml = gml) 19 | msg2 = groupsig.join_mem(1, gpk, msgin = msg1) 20 | usk = msg2['memkey'] 21 | 22 | # Sign 23 | sig = groupsig.sign("Hello, World!", usk, gpk) 24 | 25 | # Verify 26 | b = groupsig.verify(sig, "Hello, World!", gpk) 27 | 28 | if b == True: 29 | print ("VALID signature.") 30 | else: 31 | print ("WRONG signature.") 32 | sys.exit() 33 | 34 | # Open 35 | id = groupsig.open(sig, msk, gpk, gml) 36 | str = identity.identity_to_string(id) 37 | 38 | print("Identity: %s" % str) 39 | 40 | groupsig.clear(constants.BBS04_CODE, bbs04['config']) 41 | 42 | -------------------------------------------------------------------------------- /src/wrappers/python/setup.py: -------------------------------------------------------------------------------- 1 | #from skbuild import setup # This line replaces 'from setuptools import setup' 2 | from setuptools import setup, find_packages 3 | 4 | with open("README.md", "r") as fh: 5 | long_description = fh.read() 6 | 7 | setup( 8 | name="pygroupsig", 9 | version="1.1.0", 10 | author="Jesus Diaz Vico", 11 | author_email="jdv@zurich.ibm.com", 12 | description="A Python wrapper for libgroupsig", 13 | long_description=long_description, 14 | long_description_content_type="text/markdown", 15 | url="https://github.com/IBM/libgroupsig.git", 16 | classifiers=[ 17 | "Programming Language :: Python :: 3", 18 | "License :: OSI Approved :: Apache Software License", 19 | "Operating System :: OS Independent", 20 | ], 21 | package_dir={'pygroupsig': 'pygroupsig'}, 22 | packages=['pygroupsig'], 23 | python_requires='>=3', 24 | setup_requires=["cffi"], 25 | cffi_modules=["pygroupsig/libgroupsig_build.py:ffibuilder"], 26 | install_requires=["cffi", "path.py"], 27 | test_suite="nose.collector", 28 | tests_require=["nose"], 29 | ) 30 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/src/index.js: -------------------------------------------------------------------------------- 1 | import 'dotenv/config'; 2 | import cors from 'cors'; 3 | import express from 'express'; 4 | import routes from './routes'; 5 | import models, { sequelize } from './models'; 6 | 7 | const app = express(); 8 | 9 | // @TODO Implement CORS whitelisting! 10 | app.use(cors()); 11 | app.use(express.json()); 12 | app.use(express.urlencoded({ extended: true })); 13 | 14 | /* Pass the models to all routes */ 15 | app.use((req, res, next) => { 16 | req.context = { 17 | models, 18 | }; 19 | next(); 20 | }); 21 | 22 | app.use('/'+process.env.API_VERSION+'/group', routes.group); 23 | 24 | /* Error handler */ 25 | app.use((err, req, res, next) => { 26 | res.status(err.status || 500) 27 | .json({ 28 | message: err.message, 29 | error: {} 30 | }); 31 | }); 32 | 33 | /* Set to true for erasing DB upon Express restart (for testing) */ 34 | //const eraseDatabaseOnSync = true; 35 | const eraseDatabaseOnSync = false; 36 | sequelize.sync({ force: eraseDatabaseOnSync }).then(async () => { 37 | app.listen(process.env.PORT, () => { 38 | console.log(`Listening on port ${process.env.PORT}!`) 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libgroupsig 2 | 3 | Welcome to _libgroupsig_, an extensible library for group signatures. Below, 4 | you can find basic information about how to build the library. For more detailed 5 | information on building it (the core and its wrappers), using it, contributing 6 | and more, please check the [wiki](https://github.com/IBM/libgroupsig/wiki) 7 | out. 8 | 9 | ## Build 10 | 11 | To build the library, run the following commands. 12 | 13 | ``` 14 | mkdir build 15 | cd build 16 | cmake .. 17 | make 18 | ``` 19 | 20 | ## Install 21 | 22 | To install the library, run the commands in build. Then, run: 23 | 24 | ``` 25 | make install 26 | ``` 27 | 28 | **Note**: You may require to run the previous command as super user. 29 | 30 | ## Tests and coverage 31 | 32 | ``` 33 | mkdir build 34 | cd build 35 | cmake -DUSE_GTEST=ON -DUSE_GCOV=ON .. 36 | make && make test && make coverage 37 | ``` 38 | 39 | (Note: To build with debug flags, add the `-DCMAKE_BUILD_TYPE=Debug` modifier to 40 | cmake in the prevous sequence of commands.) 41 | 42 | Tests can alternatively be run with `ctest` from the build directory, or with 43 | `ctest -T memcheck` to check memory-related bugs. 44 | 45 | -------------------------------------------------------------------------------- /src/wrappers/python/samples/sign_gl19.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from pygroupsig import groupsig 4 | from pygroupsig import signature 5 | from pygroupsig import memkey 6 | from pygroupsig import grpkey 7 | from pygroupsig import mgrkey 8 | from pygroupsig import constants 9 | 10 | # Setup 11 | issuer = groupsig.setup(constants.GL19_CODE) 12 | _gpk = issuer['grpkey'] 13 | isk = issuer['mgrkey'] 14 | converter = groupsig.setup(constants.GL19_CODE, _gpk); 15 | csk = converter['mgrkey'] 16 | gpk = converter['grpkey'] 17 | 18 | # Join 19 | msg1 = groupsig.join_mgr(0, isk, gpk) 20 | msg2 = groupsig.join_mem(1, gpk, msgin = msg1) 21 | usk = msg2['memkey'] 22 | msg3 = groupsig.join_mgr(2, isk, gpk, msg2['msgout']) 23 | msg4 = groupsig.join_mem(3, gpk, msgin = msg3, memkey = usk) 24 | usk = msg4['memkey'] 25 | 26 | # Sign 27 | sig = groupsig.sign("Hello, World!", usk, gpk) 28 | 29 | # Verify 30 | b = groupsig.verify(sig, "Hello, World!", gpk) 31 | 32 | if b == True: 33 | print ("VALID signature.") 34 | else: 35 | print ("WRONG signature.") 36 | sys.exit() 37 | 38 | groupsig.clear(constants.GL19_CODE, issuer['config']) 39 | groupsig.clear(constants.GL19_CODE, converter['config']) 40 | -------------------------------------------------------------------------------- /src/groupsig/bbs04/update_env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | int bbs04_update_env(void *data) { 21 | 22 | if(!data) { 23 | LOG_EINVAL(&logger, __FILE__, "bbs04_update_env", __LINE__, LOGERROR); 24 | return IERROR; 25 | } 26 | 27 | /* Just update the sysenv->data pointer. */ 28 | sysenv->data = data; 29 | 30 | return IOK; 31 | 32 | } 33 | 34 | /* update_env.c ends here */ 35 | -------------------------------------------------------------------------------- /src/groupsig/cpy06/update_env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | int cpy06_update_env(void *data) { 21 | 22 | if(!data) { 23 | LOG_EINVAL(&logger, __FILE__, "cpy06_update_env", __LINE__, LOGERROR); 24 | return IERROR; 25 | } 26 | 27 | /* Just update the sysenv->data pointer. */ 28 | sysenv->data = data; 29 | 30 | return IOK; 31 | 32 | } 33 | 34 | /* update_env.c ends here */ 35 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/server/mocks/fixtures/pki.js: -------------------------------------------------------------------------------- 1 | // mocks/fixtures/pki.js 2 | 3 | const TEST_CERT_AND_SIGN = [ 4 | { 5 | cert: "sample-cert", 6 | sign: "sample-signature", 7 | message: "sample-message" 8 | } 9 | ]; 10 | 11 | const verifyCert = { 12 | id: "verify-cert", 13 | url: "/cert/verify", 14 | method: "POST", 15 | response: (req, res) => { 16 | const reqCert = req.body.cert; 17 | const reqSig = req.body.sign; 18 | const reqMsg = req.body.message; 19 | 20 | /* Just accept all requests. If further testing is desired, checks for 21 | hard-coded certificates and signatures can be done by properly 22 | setting the "TEST_CERT_AND_SIGN" array, and something like the 23 | following commented code. */ 24 | 25 | res.status(200); 26 | data = { 27 | 'status' : 'ok', 28 | 'reason' : 'valid_signature' 29 | }; 30 | res.send(data); 31 | 32 | // const cert = TEST_CERT_AND_SIGN.find(data => data.cert == reqCert); 33 | // if (cert && cert.cert == reqCert && reqSig == cert.sign) { 34 | // res.status(200); 35 | // res.send(true); 36 | // } else { 37 | // res.status(200); 38 | // res.send(false); 39 | // } 40 | } 41 | }; 42 | 43 | module.exports = { 44 | verifyCert 45 | }; 46 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/message_build.py: -------------------------------------------------------------------------------- 1 | # file "message_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | import pygroupsig.types_build 5 | 6 | ffibuilder.cdef(""" 7 | typedef struct _message_t { 8 | byte_t *bytes; 9 | uint64_t length; 10 | } message_t; 11 | """) 12 | 13 | ffibuilder.cdef(""" 14 | message_t* message_init(void); 15 | """) 16 | 17 | ffibuilder.cdef(""" 18 | message_t* message_from_string(char *str); 19 | """) 20 | 21 | ffibuilder.cdef(""" 22 | message_t* message_from_bytes(byte_t *bytes, uint64_t length); 23 | """) 24 | 25 | ffibuilder.cdef(""" 26 | int message_free(message_t *msg); 27 | """) 28 | 29 | ffibuilder.cdef(""" 30 | int message_set_bytes(message_t *msg, byte_t *bytes, uint64_t length); 31 | """) 32 | 33 | ffibuilder.cdef(""" 34 | int message_set_bytes_from_string(message_t *msg, char *string); 35 | """) 36 | 37 | ffibuilder.cdef(""" 38 | int message_copy(message_t *dst, message_t *src); 39 | """) 40 | 41 | ffibuilder.cdef(""" 42 | char* message_to_string(message_t *msg); 43 | """) 44 | 45 | ffibuilder.cdef(""" 46 | char* message_to_base64(message_t *msg); 47 | """) 48 | 49 | ffibuilder.cdef(""" 50 | message_t* message_from_base64(char *str); 51 | """) 52 | -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 20200730: First release 4 | 5 | Summary: 6 | 7 | First release. 8 | 9 | Versions: 10 | 11 | - Core: 0.1.0 12 | - Python: 0.1.0 13 | - NodeJS: 0.1.3 14 | - Java: 0.1.0 15 | 16 | 20200908: Hotfix 17 | 18 | Summary: 19 | 20 | Fixed a bug in the Base64 encoding of the Python and NodeJS wrappers. 21 | Added basic CICD workflow to the master and develop branches. Will be improved 22 | in the next release. 23 | 24 | Versions: 25 | - Core: 0.1.1 26 | - Python: 0.1.1 27 | - NodeJS: 0.1.3 28 | - Java: 0.1.0 29 | 30 | 20200112: 31 | 32 | Summary: Added PS16 and KLAP20 schemes, as well as many important 33 | improvements and bugfixes. 34 | 35 | Versions: 36 | - Core: 1.0.0 37 | - Python: 1.0.0 38 | - NodeJS: 1.0.0 39 | - Java: 1.0.0 40 | 41 | 20210531: DL21 and bugfixing 42 | 43 | Summary: 44 | 45 | Added DL21 and DL21SEQ schemes (only in Core). 46 | 47 | There was a bug in PS16 GML management, making export an import unsuccessful. 48 | Since the bug was in the Core library, it affects all wrappers too. It has 49 | been fixed, and a new unit test has been added that detects it. 50 | 51 | Versions: 52 | - Core: 1.1.0 53 | - Python: 1.1.0 54 | - NodeJS: 1.1.0 55 | - Java: 1.1.0 56 | -------------------------------------------------------------------------------- /cmake_modules/gcovr.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | ExternalProject_Add(gcovr 3 | #URL https://github.com/gcovr/gcovr/archive/3.2.zip 4 | #URL_HASH SHA1=7411d3989116c5fa65519ee1a54237df16944ad2 5 | URL https://github.com/gcovr/gcovr/archive/4.2.zip 6 | URL_HASH SHA1=f8f33794d7e09a4009e3623009b3769a726b1908 7 | CONFIGURE_COMMAND "" 8 | BUILD_COMMAND "" 9 | INSTALL_COMMAND "" 10 | ) 11 | 12 | ExternalProject_Get_Property(gcovr source_dir) 13 | SET(GCOVR gcovr) 14 | 15 | SET(GCC_COVERAGE_COMPILE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") 16 | SET(GCC_COVERAGE_LINK_FLAGS "-lgcov") 17 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" ) 18 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" ) 19 | 20 | add_custom_command(OUTPUT _run_gcovr_parser 21 | POST_BUILD 22 | COMMAND python -m ${GCOVR} -r ${CMAKE_SOURCE_DIR} --xml -o ${CMAKE_BINARY_DIR}/coverage.xml --object-dir=${CMAKE_BINARY_DIR} -e test_* --exclude-directories=gtest*,src/wrappers 23 | # COMMAND python -m ${GCOVR} -r ${CMAKE_SOURCE_DIR} --html --html-details -o ${CMAKE_BINARY_DIR}/coverage.html --object-dir=${CMAKE_BINARY_DIR} -e test_* --exclude-directories=gtest* 24 | WORKING_DIRECTORY ${source_dir}) 25 | add_custom_target (coverage DEPENDS _run_gcovr_parser) 26 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/samples/sign_gl19.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nodejs 2 | 3 | const jsgroupsig = require('jsgroupsig'); 4 | 5 | /* Init groupsig */ 6 | jsgroupsig.init(jsgroupsig.GL19); 7 | 8 | /* Init grp_key */ 9 | let grpkey = jsgroupsig.grp_key_init(jsgroupsig.GL19); 10 | 11 | /* Init issuer and converter keys */ 12 | let isskey = jsgroupsig.mgr_key_init(jsgroupsig.GL19); 13 | let cnvkey = jsgroupsig.mgr_key_init(jsgroupsig.GL19); 14 | 15 | /* Setup call 1: initializes (partial) group key and issuer key */ 16 | jsgroupsig.setup(jsgroupsig.GL19, grpkey, isskey); 17 | 18 | /* Setup call 2: completes group key and initializes converter key */ 19 | jsgroupsig.setup(jsgroupsig.GL19, grpkey, cnvkey); 20 | 21 | /* Add a member */ 22 | let memkey = jsgroupsig.mem_key_init(jsgroupsig.GL19); 23 | let msg1 = jsgroupsig.join_mgr(0, isskey, grpkey); 24 | let msg2 = jsgroupsig.join_mem(1, memkey, grpkey, msg1); 25 | let msg3 = jsgroupsig.join_mgr(2, isskey, grpkey, msg2); 26 | let msg4 = jsgroupsig.join_mem(3, memkey, grpkey, msg3); 27 | 28 | /* sign */ 29 | let sig = jsgroupsig.sign("Hello, World!", memkey, grpkey); 30 | 31 | /* verify */ 32 | let ok = jsgroupsig.verify(sig, "Hello, World!", grpkey); 33 | 34 | if (ok) console.log("VALID signature."); 35 | else console.log("WRONG signature."); 36 | 37 | jsgroupsig.clear(jsgroupsig.GL19); 38 | -------------------------------------------------------------------------------- /src/wrappers/python/samples/blind.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from pygroupsig import groupsig 4 | from pygroupsig import signature 5 | from pygroupsig import grpkey 6 | from pygroupsig import bldkey 7 | from pygroupsig import blindsig 8 | from pygroupsig import constants 9 | 10 | if len(sys.argv) != 6: 11 | print ("Usage: $python blind.py "); 12 | sys.exit(); 13 | 14 | groupsig.init(constants.GL19_CODE, 0) 15 | 16 | # Import grpkey 17 | gpk = grpkey.grpkey_import(constants.GL19_CODE, sys.argv[1]) 18 | 19 | # Import signatures 20 | sig1 = signature.signature_import(constants.GL19_CODE, sys.argv[2]) 21 | sig2 = signature.signature_import(constants.GL19_CODE, sys.argv[4]) 22 | 23 | # Blind 24 | bdk = bldkey.bldkey_random(constants.GL19_CODE, gpk) 25 | out = groupsig.blind(gpk, sig1, sys.argv[3], bdk) 26 | bsig1 = out['bsig'] 27 | 28 | out2 = groupsig.blind(gpk, sig2, sys.argv[5], bdk) 29 | bsig2 = out2['bsig'] 30 | 31 | ## Export Blinded sigs 32 | sbsig1 = blindsig.blindsig_export(bsig1) 33 | sbsig2 = blindsig.blindsig_export(bsig2) 34 | 35 | ## Export blinding key 36 | sbdk_pub = bldkey.bldkey_export_pub(bdk) 37 | sbdk = bldkey.bldkey_export(bdk) 38 | 39 | ## Output 40 | print("Blinded sig1: %s" % sbsig1) 41 | print("Blinded sig2: %s" % sbsig2) 42 | print("Blinding public key: %s" % sbdk_pub) 43 | print("Blinding keypair: %s" % sbdk) 44 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/samples/sign_bbs04.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nodejs 2 | 3 | const jsgroupsig = require('jsgroupsig'); 4 | 5 | /* Init groupsig */ 6 | jsgroupsig.init(jsgroupsig.BBS04); 7 | 8 | /* Init grp_key */ 9 | let grpkey = jsgroupsig.grp_key_init(jsgroupsig.BBS04); 10 | 11 | /* Init manager key */ 12 | let mgrkey = jsgroupsig.mgr_key_init(jsgroupsig.BBS04); 13 | 14 | /* Init GML */ 15 | let gml = jsgroupsig.gml_init(jsgroupsig.BBS04); 16 | 17 | /* Setup call: initializes group key and manager key */ 18 | jsgroupsig.setup(jsgroupsig.BBS04, grpkey, mgrkey, gml); 19 | 20 | /* Add a member */ 21 | let memkey = jsgroupsig.mem_key_init(jsgroupsig.BBS04); 22 | let msg1 = jsgroupsig.join_mgr(0, mgrkey, grpkey, null, gml); 23 | let msg2 = jsgroupsig.join_mem(1, memkey, grpkey, msg1); 24 | 25 | /* sign */ 26 | let sig = jsgroupsig.sign("Hello, World!", memkey, grpkey); 27 | 28 | /* verify */ 29 | let ok = jsgroupsig.verify(sig, "Hello, World!", grpkey); 30 | 31 | if (ok) console.log("VALID signature."); 32 | else console.log("WRONG signature."); 33 | 34 | /* Open the signature */ 35 | let id = jsgroupsig.open(sig, grpkey, mgrkey, gml); 36 | let { index, proof } = jsgroupsig.open(sig, grpkey, mgrkey, gml); 37 | console.log("Signer was: "+index); 38 | 39 | /* Free stuff */ 40 | jsgroupsig.gml_free(gml); 41 | jsgroupsig.grp_key_free(grpkey); 42 | jsgroupsig.mgr_key_free(mgrkey); 43 | jsgroupsig.mem_key_free(memkey); 44 | jsgroupsig.clear(jsgroupsig.BBS04); 45 | -------------------------------------------------------------------------------- /src/include/registered_groupsigs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _REGISTERED_GROUPSIGS_H 21 | #define _REGISTERED_GROUPSIGS_H 22 | 23 | /* Registered groupsigs */ 24 | #include "groupsig.h" 25 | /* #include "kty04.h" */ 26 | #include "bbs04.h" 27 | /* #include "cpy06.h" */ 28 | #include "gl19.h" 29 | #include "ps16.h" 30 | #include "klap20.h" 31 | #include "dl21.h" 32 | #include "dl21seq.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | /* Write any cplusplus specific code here */ 44 | #endif 45 | 46 | #endif /* _REGISTERED_GROUPSIGS_H */ 47 | 48 | /* registered_groupsigs.h ends here */ 49 | -------------------------------------------------------------------------------- /src/math/rnd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _RND_H 21 | #define _RND_H 22 | 23 | #include "types.h" 24 | 25 | /** 26 | * @fn int random_get_random_int_in_range(uint64_t *r, uint64_t n) 27 | * @brief Returns a random integer in the interval [0,n]. The system's 28 | * random number generator must have been initialized with a call to srand 29 | * before calling this function. (This can be done by calling groupsig_init.) 30 | * 31 | * @param[in,out] r Pointer to uint64_t to store the produced number. 32 | * @param[in] n The upper limit of the interval. 33 | * 34 | * @return IOK or IERROR. 35 | */ 36 | int rnd_get_random_int_in_range(uint64_t *r, uint64_t n); 37 | 38 | #endif 39 | 40 | /* rnd.h ends here */ 41 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/trapdoor_build.py: -------------------------------------------------------------------------------- 1 | # file "trapdoor_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef struct { 7 | uint8_t scheme; 8 | void *trap; 9 | } trapdoor_t; 10 | """) 11 | 12 | ffibuilder.cdef(""" 13 | typedef trapdoor_t* (*trapdoor_init_f)(void); 14 | """) 15 | 16 | ffibuilder.cdef(""" 17 | typedef int (*trapdoor_free_f)(trapdoor_t *trap); 18 | """) 19 | 20 | ffibuilder.cdef(""" 21 | typedef int (*trapdoor_copy_f)(trapdoor_t *dst, trapdoor_t *src); 22 | """) 23 | 24 | ffibuilder.cdef(""" 25 | typedef char* (*trapdoor_to_string_f)(trapdoor_t *trap); 26 | """) 27 | 28 | ffibuilder.cdef(""" 29 | typedef trapdoor_t* (*trapdoor_from_string_f)(char *strap); 30 | """) 31 | 32 | ffibuilder.cdef(""" 33 | typedef struct { 34 | uint8_t scheme; 35 | trapdoor_init_f init; 36 | trapdoor_free_f free; 37 | trapdoor_copy_f copy; 38 | trapdoor_to_string_f to_string; 39 | trapdoor_from_string_f from_string; 40 | } trapdoor_handle_t; 41 | """) 42 | 43 | ffibuilder.cdef(""" 44 | const trapdoor_handle_t* trapdoor_handle_from_code(uint8_t code); 45 | """) 46 | 47 | ffibuilder.cdef(""" 48 | trapdoor_t* trapdoor_init(uint8_t code); 49 | """) 50 | 51 | ffibuilder.cdef(""" 52 | int trapdoor_free(trapdoor_t *trap); 53 | """) 54 | 55 | ffibuilder.cdef(""" 56 | int trapdoor_copy(trapdoor_t *dst, trapdoor_t *src); 57 | """) 58 | 59 | ffibuilder.cdef(""" 60 | char* trapdoor_to_string(trapdoor_t *trap); 61 | """) 62 | 63 | ffibuilder.cdef(""" 64 | trapdoor_t *trapdoor_from_string(uint8_t code, char *strap); 65 | """) 66 | -------------------------------------------------------------------------------- /src/math/perm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _PERM_H 21 | #define _PERM_H 22 | 23 | #include "types.h" 24 | 25 | /** 26 | * @fn int perm_durstenfeld_inplace_int(void **array, int size); 27 | * @brief Uses Durstenfeld variant of the Fisher-Yates in place permutation 28 | * algorithm to output a random permutation of the given array. 29 | * 30 | * See https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm 31 | * for a definition of the algorithm. 32 | * 33 | * @param[in,out] array The array of pointers to permute. 34 | * @param[in] size The number of elements in the array. 35 | * 36 | * @return IOK or IERROR 37 | */ 38 | int perm_durstenfeld_inplace(void **array, int size); 39 | 40 | #endif 41 | 42 | /* perm.h ends here */ 43 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/exim_build.py: -------------------------------------------------------------------------------- 1 | # file "exim_build.py" 2 | 3 | from common_build import ffibuilder 4 | 5 | # Define data types 6 | 7 | ffibuilder.cdef(""" 8 | typedef enum { 9 | EXIM_FORMAT_FILE_NULL, 10 | EXIM_FORMAT_FILE_NULL_B64, 11 | EXIM_FORMAT_STRING_NULL_B64, 12 | EXIM_FORMAT_MESSAGE_NULL, 13 | EXIM_FORMAT_MESSAGE_NULL_B64, 14 | EXIM_FORMAT_BYTEARRAY_NULL, 15 | } exim_format_t; 16 | """) 17 | 18 | ffibuilder.cdef(""" 19 | typedef struct exim_handle_t exim_handle_t; 20 | """) 21 | 22 | ffibuilder.cdef(""" 23 | typedef struct exim_t exim_t; 24 | """) 25 | 26 | ffibuilder.cdef(""" 27 | typedef int (*exim_get_size_bytearray_null_f)(exim_t* obj); 28 | """) 29 | 30 | ffibuilder.cdef(""" 31 | typedef int (*exim_export_bytearray_fd_f)(exim_t* obj, FILE* fd); 32 | """) 33 | 34 | ffibuilder.cdef(""" 35 | typedef int (*exim_import_bytearray_fd_f)(FILE *fd, exim_t* obj); 36 | """) 37 | 38 | ffibuilder.cdef(""" 39 | struct exim_handle_t { 40 | exim_get_size_bytearray_null_f get_size_bytearray_null; 41 | exim_export_bytearray_fd_f export_bytearray_fd; 42 | exim_import_bytearray_fd_f import_bytearray_fd; 43 | }; 44 | """) 45 | 46 | ffibuilder.cdef(""" 47 | struct exim_t { 48 | void *eximable; 49 | exim_handle_t *funcs; 50 | }; 51 | """) 52 | 53 | ffibuilder.cdef(""" 54 | int exim_get_size_in_format(exim_t *obj, exim_format_t format); 55 | """) 56 | 57 | ffibuilder.cdef(""" 58 | int exim_export(exim_t* obj, exim_format_t format, void *dst); 59 | """) 60 | 61 | ffibuilder.cdef(""" 62 | int exim_import(exim_format_t format, void *source, exim_t* obj); 63 | """) 64 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/grpkey.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def grpkey_export(grpkey): 6 | """ 7 | Exports the given group key to a Base64 string. 8 | 9 | Parameters: 10 | grpkey: The native group key data structure. 11 | Returns: 12 | A Base64 string. On error, an Exception is thrown. 13 | """ 14 | 15 | bkey = ffi.new("byte_t **") 16 | bkey[0] = ffi.NULL 17 | size = ffi.new("uint32_t *") 18 | if lib.groupsig_grp_key_export(bkey, size, grpkey) == constants.IERROR: 19 | raise Exception('Error exporting group key.') 20 | b64 = base64.b64encode(ffi.buffer(bkey[0],size[0])) 21 | b64 = b64.decode('utf-8').replace('\n', '') 22 | # lib.free(bkey[0]) 23 | return b64 24 | 25 | def grpkey_import(code, b64key): 26 | """ 27 | Imports a group key from a Base64 string. 28 | 29 | Parameters: 30 | code: The code corresponding to the group signature scheme. 31 | b64key: The Base64 string. 32 | Returns: 33 | A group key. On error, an Exception is thrown. 34 | """ 35 | 36 | b = base64.b64decode(b64key) 37 | grpkey = lib.groupsig_grp_key_import(code, b, len(b)) 38 | if grpkey == ffi.NULL: 39 | raise Exception('Error importing group key.') 40 | return grpkey 41 | 42 | #def grpkey_to_string(key): 43 | # 44 | # _str = ffi.new("char *") 45 | # _str = lib.groupsig_grp_key_to_string(key) 46 | # if _str == ffi.NULL: 47 | # raise Exception('Error converting grpkey to string.') 48 | # return ffi.string(_str).decode('utf8') 49 | -------------------------------------------------------------------------------- /src/groupsig/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(src 2 | groupsig.c 3 | grp_key.c 4 | mgr_key.c 5 | mem_key.c 6 | bld_key.c 7 | signature.c 8 | blindsig.c 9 | proof.c 10 | identity.c 11 | trapdoor.c 12 | gml.c 13 | crl.c) 14 | 15 | # this is the "object library" target: compiles the sources only once 16 | add_library(objlib OBJECT ${src}) 17 | 18 | # shared libraries need PIC 19 | set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1) 20 | 21 | # shared and static libraries built from the same object files 22 | add_library(groupsig SHARED $) 23 | add_library(groupsig-static STATIC $) 24 | 25 | target_link_libraries (groupsig 26 | #PUBLIC kty04 27 | PUBLIC bbs04 28 | #PUBLIC cpy06 29 | PUBLIC gl19 30 | PUBLIC ps16 31 | PUBLIC klap20 32 | PUBLIC dl21 33 | PUBLIC dl21seq 34 | PUBLIC sys 35 | PUBLIC math 36 | PUBLIC base64 37 | PUBLIC misc 38 | PUBLIC hash 39 | PUBLIC gcrypto 40 | PUBLIC msg 41 | PUBLIC pbcext 42 | PUBLIC logger 43 | PUBLIC ${OPENSSL_LIBRARIES} 44 | PUBLIC ${MCL_LIBRARY} 45 | PUBLIC ${MCL384_256_LIBRARY}) 46 | 47 | # Install rules 48 | install (TARGETS groupsig DESTINATION lib) 49 | install (DIRECTORY "${PROJECT_SOURCE_DIR}/src/include/" 50 | DESTINATION "include/groupsig" 51 | FILES_MATCHING PATTERN "*.h") 52 | 53 | # Ignore kty04 and cpy06 until I adapt them to the new pbc and join 54 | add_subdirectory(bbs04) 55 | #add_subdirectory(kty04) 56 | #add_subdirectory(cpy06) 57 | add_subdirectory(gl19) 58 | add_subdirectory(ps16) 59 | add_subdirectory(klap20) 60 | add_subdirectory(dl21) 61 | add_subdirectory(dl21seq) 62 | -------------------------------------------------------------------------------- /src/groupsig/bbs04/env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "bbs04.h" 21 | #include "sysenv.h" 22 | #include "sys/mem.h" 23 | #include "shim/pbc_ext.h" 24 | 25 | int bbs04_sysenv_update(void *data) { 26 | 27 | /* if(!data) { */ 28 | /* LOG_EINVAL(&logger, __FILE__, "bbs04_sysenv_update", __LINE__, LOGERROR); */ 29 | /* return IERROR; */ 30 | /* } */ 31 | 32 | /* sysenv->data = data; */ 33 | 34 | return IOK; 35 | 36 | } 37 | 38 | int bbs04_sysenv_free() { 39 | 40 | /* if(sysenv->data) { */ 41 | /* pairing_clear(((bbs04_sysenv_t *) sysenv->data)->pairing); */ 42 | /* pbc_param_clear(((bbs04_sysenv_t *) sysenv->data)->param); */ 43 | /* mem_free(sysenv->data); sysenv->data = NULL; */ 44 | /* } */ 45 | 46 | return IOK; 47 | 48 | } 49 | 50 | /* env.c ends here */ 51 | -------------------------------------------------------------------------------- /src/groupsig/cpy06/env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "sysenv.h" 21 | #include "sys/mem.h" 22 | #include "wrappers/pbc_ext.h" 23 | 24 | int cpy06_sysenv_update(void *data) { 25 | 26 | if(!data) { 27 | LOG_EINVAL(&logger, __FILE__, "cpy06_sysenv_update", __LINE__, LOGERROR); 28 | return IERROR; 29 | } 30 | 31 | sysenv->data = data; 32 | 33 | return IOK; 34 | 35 | } 36 | 37 | void* cpy06_sysenv_get() { 38 | return sysenv->data; 39 | } 40 | 41 | int cpy06_sysenv_free() { 42 | 43 | if (sysenv->data) { 44 | 45 | pairing_clear(((cpy06_sysenv_t *) sysenv->data)->pairing); 46 | pbc_param_clear(((cpy06_sysenv_t *) sysenv->data)->param); 47 | mem_free(sysenv->data); sysenv->data = NULL; 48 | 49 | } 50 | 51 | return IOK; 52 | 53 | } 54 | 55 | /* env.c ends here */ 56 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/mgrkey.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def mgrkey_export(mgrkey): 6 | """ 7 | Exports the given manager key to a Base64 string. 8 | 9 | Parameters: 10 | mgrkey: The native manager key data structure. 11 | Returns: 12 | A Base64 string. On error, an Exception is thrown. 13 | """ 14 | 15 | bkey = ffi.new("byte_t **") 16 | bkey[0] = ffi.NULL 17 | size = ffi.new("uint32_t *") 18 | if lib.groupsig_mgr_key_export(bkey, size, mgrkey) == constants.IERROR: 19 | raise Exception('Error exporting manager key.') 20 | b64key = base64.b64encode(ffi.buffer(bkey[0],size[0])) 21 | b64key = b64key.decode('utf-8').replace('\n', '') 22 | # lib.free(bkey[0]) 23 | return b64key 24 | 25 | def mgrkey_import(code, b64key): 26 | """ 27 | Imports a manager key from a Base64 string. 28 | 29 | Parameters: 30 | code: The code corresponding to the group signature scheme. 31 | b64key: The Base64 string. 32 | Returns: 33 | A manager key. On error, an Exception is thrown. 34 | """ 35 | 36 | b = base64.b64decode(b64key) 37 | mgrkey = lib.groupsig_mgr_key_import(code, b, len(b)) 38 | if mgrkey == ffi.NULL: 39 | raise Exception('Error importing manager key.') 40 | return mgrkey 41 | 42 | #def mgrkey_to_string(key): 43 | # 44 | # _str = ffi.new("char *") 45 | # _str = lib.groupsig_mgr_key_to_string(key) 46 | # if _str == ffi.NULL: 47 | # raise Exception('Error converting manager key to string.') 48 | # return ffi.string(_str).decode('utf8') 49 | -------------------------------------------------------------------------------- /src/math/rnd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | 22 | #include "sysenv.h" 23 | #include "rnd.h" 24 | #include "logger.h" 25 | 26 | int rnd_get_random_int_in_range(uint64_t *r, uint64_t n) { 27 | 28 | int attempts, rc; 29 | uint64_t _r; 30 | 31 | if (!r || n < 0) { 32 | LOG_EINVAL(&logger, __FILE__, "rnd_get_random_int_in_range", 33 | __LINE__, LOGERROR); 34 | return IERROR; 35 | } 36 | 37 | /* Call sysenv_getrandom, which uses the best available randomness source. */ 38 | if (sysenv_getrandom(&_r, sizeof(uint64_t)) == IERROR) { 39 | LOG_ERRORCODE(&logger, __FILE__, "rnd_get_random_int_in_range", __LINE__, 40 | errno, LOGERROR); 41 | return IERROR; 42 | } 43 | 44 | *r = _r % (n+1); 45 | 46 | return IOK; 47 | 48 | } 49 | 50 | /* rnd.c ends here */ 51 | -------------------------------------------------------------------------------- /src/sys/mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "mem.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include "types.h" 26 | 27 | void* mem_malloc(size_t size) { 28 | 29 | void *p; 30 | 31 | if(!size) { 32 | errno = EINVAL; 33 | return NULL; 34 | } 35 | 36 | if(!(p = malloc(size))) { 37 | return NULL; 38 | } 39 | 40 | memset(p, 0, size); 41 | 42 | return p; 43 | 44 | } 45 | 46 | void* mem_realloc(void *ptr, size_t size) { 47 | 48 | if(!ptr) return mem_malloc(size); 49 | 50 | if(!(ptr = realloc(ptr, size))) { 51 | return NULL; 52 | } 53 | 54 | return ptr; 55 | 56 | } 57 | 58 | int mem_free(void *p) { 59 | 60 | if(!p) { 61 | errno = EINVAL; 62 | return IOK; 63 | } 64 | 65 | free(p); 66 | p = NULL; 67 | return IOK; 68 | 69 | } 70 | 71 | /* mem.c ends here */ 72 | -------------------------------------------------------------------------------- /src/include/bld_key_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _BLD_KEY_HANDLES_H 21 | #define _BLD_KEY_HANDLES_H 22 | 23 | #include "bld_key.h" 24 | #include "groupsig/gl19/bld_key.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /** 31 | * @def GROUPSIG_BLD_KEY_HANDLES_N 32 | * @brief Number of known handles of blinding key schemes. 33 | */ 34 | #define GROUPSIG_BLD_KEY_HANDLES_N 1 35 | 36 | /** 37 | * @var GROUPSIG_BLD_KEY_HANDLES 38 | * @brief List of handles of supported blinding key schemes. 39 | */ 40 | static const bld_key_handle_t *GROUPSIG_BLD_KEY_HANDLES[GROUPSIG_BLD_KEY_HANDLES_N] = { 41 | &gl19_bld_key_handle, 42 | }; 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #ifdef __cplusplus 49 | /* Write any cplusplus specific code here */ 50 | #endif 51 | 52 | #endif /* _BLD_KEY_HANDLES_H */ 53 | 54 | /* bld_key_handles.h ends here */ 55 | -------------------------------------------------------------------------------- /src/math/perm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "perm.h" 21 | #include "rnd.h" 22 | #include "logger.h" 23 | 24 | int perm_durstenfeld_inplace(void **array, int size) { 25 | 26 | void *tmp; 27 | uint64_t i, j; 28 | 29 | if (!array || size <= 0) { 30 | LOG_EINVAL(&logger, __FILE__, "perm_durstenfeld_inplace", 31 | __LINE__, LOGERROR); 32 | return IERROR; 33 | } 34 | 35 | for (i=size-1; i>0; i--) { 36 | 37 | /* j random integer in [0,i] */ 38 | if(rnd_get_random_int_in_range(&j, i) == IERROR) { 39 | LOG_ERRORCODE(&logger, __FILE__, "perm_durstenfeld_inplace", __LINE__, 40 | errno, LOGERROR); 41 | return IERROR; 42 | } 43 | 44 | /* Swap array[i] and array[j] */ 45 | tmp = array[i]; 46 | array[i] = array[j]; 47 | array[j] = tmp; 48 | 49 | } 50 | 51 | return IOK; 52 | 53 | } 54 | 55 | /* perm.c ends here */ 56 | -------------------------------------------------------------------------------- /src/groupsig/gl19/env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "gl19.h" 21 | #include "sysenv.h" 22 | #include "logger.h" 23 | #include "shim/pbc_ext.h" 24 | #include "sys/mem.h" 25 | 26 | int gl19_sysenv_update(void *data) { 27 | 28 | /* if(!data) { */ 29 | /* LOG_EINVAL(&logger, __FILE__, "gl19_sysenv_update", __LINE__, LOGERROR); */ 30 | /* return IERROR; */ 31 | /* } */ 32 | 33 | /* sysenv->data = data; */ 34 | 35 | return IOK; 36 | 37 | } 38 | 39 | void* gl19_sysenv_get() { 40 | return sysenv->data; 41 | } 42 | 43 | int gl19_sysenv_free() { 44 | 45 | /* if (sysenv->data) { */ 46 | 47 | /* pairing_clear(((gl19_sysenv_t *) sysenv->data)->pairing); */ 48 | /* pbc_param_clear(((gl19_sysenv_t *) sysenv->data)->param); */ 49 | /* mem_free(sysenv->data); sysenv->data = NULL; */ 50 | 51 | /* } */ 52 | 53 | return IOK; 54 | 55 | } 56 | 57 | /* env.c ends here */ 58 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/samples/src/main/java/com/ibm/jgroupsig/executable/SignBBS04.java: -------------------------------------------------------------------------------- 1 | package com.ibm.jgroupsig.executable; 2 | 3 | import com.ibm.jgroupsig.GS; 4 | import com.ibm.jgroupsig.BBS04; 5 | import com.ibm.jgroupsig.Signature; 6 | import com.ibm.jgroupsig.MemKey; 7 | 8 | import java.io.UnsupportedEncodingException; 9 | import java.lang.IllegalArgumentException; 10 | 11 | public class SignBBS04 { 12 | 13 | public static void main (String args[]) { 14 | 15 | try { 16 | /* 17 | Instantiate and setup the group. 18 | To simulate a real setting, we use three different 19 | "environments", issuer (who controls the issuing key), 20 | converter (who controls the converter key), and user 21 | (who controls a member key) 22 | */ 23 | BBS04 issuer = new BBS04(); 24 | BBS04 user = new BBS04(); 25 | 26 | issuer.setup(); 27 | user.setGrpKey(issuer.getGrpKey()); 28 | 29 | /* Simulate adding one member */ 30 | MemKey memkey = new MemKey(GS.BBS04_CODE); 31 | long mout1 = issuer.joinMgr(0, 0); 32 | long mout2 = issuer.joinMem(memkey, 1, mout1); 33 | 34 | /* Create sample signatures */ 35 | Signature sig = user.sign("Hello, World!", memkey); 36 | boolean b = user.verify(sig, "Hello, World!"); 37 | 38 | if (b == true) { 39 | System.out.println("VALID signature."); 40 | } else { 41 | System.out.println("WRONG signature."); 42 | } 43 | 44 | issuer.finalize(); 45 | user.finalize(); 46 | 47 | return; 48 | 49 | } catch(UnsupportedEncodingException | 50 | IllegalArgumentException e) { 51 | e.printStackTrace(); 52 | } catch(Exception e) { 53 | e.printStackTrace(); 54 | } 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/include/crl_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _CRL_HANDLES_H 21 | #define _CRL_HANDLES_H 22 | 23 | #include "crl.h" 24 | /* #include "groupsig/kty04/crl.h" */ 25 | /* #include "groupsig/bbs04/crl.h" */ 26 | /* #include "groupsig/cpy06/crl.h" */ 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /** 33 | * @def CRL_HANDLES_N 34 | * @brief Number of supported CRL implementations. 35 | */ 36 | #define CRL_HANDLES_N 0//3 37 | 38 | /** 39 | * @var CRL_HANDLES 40 | * @brief List of handles of CRL implementations. 41 | */ 42 | const crl_handle_t *CRL_HANDLES[CRL_HANDLES_N] = { 43 | /* &kty04_crl_handle, */ 44 | /* &bbs04_crl_handle, */ 45 | /* &cpy06_crl_handle, */ 46 | }; 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | /* Write any cplusplus specific code here */ 54 | #endif 55 | 56 | #endif /* _CRL_HANDLES_H */ 57 | 58 | /* crl_handles.h ends here */ 59 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/identity_build.py: -------------------------------------------------------------------------------- 1 | # file "identity_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef struct { 7 | uint8_t scheme; 8 | void *id; 9 | } identity_t; 10 | """) 11 | 12 | ffibuilder.cdef(""" 13 | typedef identity_t* (*identity_init_f)(void); 14 | """) 15 | 16 | ffibuilder.cdef(""" 17 | typedef int (*identity_free_f)(identity_t *id); 18 | """) 19 | 20 | ffibuilder.cdef(""" 21 | typedef int (*identity_copy_f)(identity_t *dst, identity_t *src); 22 | """) 23 | 24 | ffibuilder.cdef(""" 25 | typedef uint8_t (*identity_cmp_f)(identity_t *id1, identity_t *id2); 26 | """) 27 | 28 | ffibuilder.cdef(""" 29 | typedef char* (*identity_to_string_f)(identity_t *id); 30 | """) 31 | 32 | ffibuilder.cdef(""" 33 | typedef identity_t* (*identity_from_string_f)(char *sid); 34 | """) 35 | 36 | ffibuilder.cdef(""" 37 | typedef struct { 38 | uint8_t scheme; 39 | identity_init_f init; 40 | identity_free_f free; 41 | identity_copy_f copy; 42 | identity_cmp_f cmp; 43 | identity_to_string_f to_string; 44 | identity_from_string_f from_string; 45 | } identity_handle_t; 46 | """) 47 | 48 | ffibuilder.cdef(""" 49 | const identity_handle_t* identity_handle_from_code(uint8_t code); 50 | """) 51 | 52 | ffibuilder.cdef(""" 53 | identity_t* identity_init(uint8_t code); 54 | """) 55 | 56 | ffibuilder.cdef(""" 57 | int identity_free(identity_t *id); 58 | """) 59 | 60 | ffibuilder.cdef(""" 61 | int identity_copy(identity_t *dst, identity_t *src); 62 | """) 63 | 64 | ffibuilder.cdef(""" 65 | uint8_t identity_cmp(identity_t *id1, identity_t *id2); 66 | """) 67 | 68 | ffibuilder.cdef(""" 69 | char* identity_to_string(identity_t *id); 70 | """) 71 | 72 | ffibuilder.cdef(""" 73 | identity_t *identity_from_string(uint8_t code, char *sid); 74 | """) 75 | -------------------------------------------------------------------------------- /src/include/blindsig_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _BLINDSIG_HANDLES_H 21 | #define _BLINDSIG_HANDLES_H 22 | 23 | #include "blindsig.h" 24 | #include "groupsig/gl19/blindsig.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /** 31 | * @def GROUPSIG_BLINDSIG_HANDLES_N 32 | * @brief Number of supported set of handles for managing blinded group signatures. 33 | */ 34 | #define GROUPSIG_BLINDSIG_HANDLES_N 1 35 | 36 | /** 37 | * @var GROUPSIG_BLINDSIG_HANDLES 38 | * @brief List of supported set of handles for managing blinded group signatures. 39 | */ 40 | static const groupsig_blindsig_handle_t *GROUPSIG_BLINDSIG_HANDLES[GROUPSIG_BLINDSIG_HANDLES_N] = { 41 | &gl19_blindsig_handle, 42 | }; 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #ifdef __cplusplus 49 | /* Write any cplusplus specific code here */ 50 | #endif 51 | 52 | #endif /* _BLINDSIG_HANDLES_H */ 53 | 54 | /* blindsig_handles.h ends here */ 55 | -------------------------------------------------------------------------------- /src/include/trapdoor_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _TRAPDOOR_HANDLES_H 21 | #define _TRAPDOOR_HANDLES_H 22 | 23 | #include "string.h" 24 | #include "trapdoor.h" 25 | /* #include "groupsig/kty04/trapdoor.h" */ 26 | /* #include "groupsig/cpy06/trapdoor.h" */ 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /** 33 | * @def TRAPDOOR_HANDLES_N 34 | * @brief Number of supported trapdoors. 35 | */ 36 | #define TRAPDOOR_HANDLES_N 1//3 37 | 38 | /** 39 | * @var TRAPDOOR_HANDLES 40 | * @brief List of supported trapdoors. 41 | */ 42 | static const trapdoor_handle_t *TRAPDOOR_HANDLES[TRAPDOOR_HANDLES_N] = { 43 | // &kty04_trapdoor_handle, 44 | // &cpy06_trapdoor_handle, 45 | NULL, 46 | }; 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | /* Write any cplusplus specific code here */ 54 | #endif 55 | 56 | #endif /* _TRAPDOOR_HANDLES_H */ 57 | 58 | /* trapdoor_handles.h ends here */ 59 | -------------------------------------------------------------------------------- /src/include/big.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _BIG_H 21 | #define _BIG_H 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * OpenSSL's BIGNUM operations usually require a BN_CTX 31 | * structure. This will be initialized by groupsig_init, which 32 | * needs to be executed before using the library, and freed 33 | * by groupsig_clear. 34 | */ 35 | typedef BN_CTX *big_ctx_t; 36 | 37 | /** 38 | * Big Integer type definition. 39 | */ 40 | typedef BIGNUM *bigz_t;//mpz_t *bigz_t; 41 | 42 | /** 43 | * Big Float type definition. 44 | */ 45 | //typedef mpf_t *bigf_t; 46 | 47 | /** 48 | * Random state definition. 49 | */ 50 | //typedef gmp_randstate_t bigz_randstate_t; 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | /* Write any cplusplus specific code here */ 58 | #endif 59 | 60 | #endif /* _BIG_H */ 61 | 62 | /* big.h ends here */ 63 | -------------------------------------------------------------------------------- /src/include/gml_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _GML_HANDLES_H 21 | #define _GML_HANDLES_H 22 | 23 | #include "gml.h" 24 | /* #include "groupsig/kty04/gml.h" */ 25 | #include "groupsig/bbs04/gml.h" 26 | /* #include "groupsig/cpy06/gml.h" */ 27 | #include "groupsig/ps16/gml.h" 28 | #include "groupsig/klap20/gml.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * @def GML_HANDLES_N 36 | * @brief Number of known GML implementation handles. 37 | */ 38 | #define GML_HANDLES_N 3 39 | 40 | /** 41 | * @var GML_HANDLES 42 | * @brief Set of handles of known GML implementations. 43 | */ 44 | const gml_handle_t *GML_HANDLES[GML_HANDLES_N] = { 45 | /* &kty04_gml_handle, */ 46 | &bbs04_gml_handle, 47 | /* &cpy06_gml_handle, */ 48 | &ps16_gml_handle, 49 | &klap20_gml_handle, 50 | }; 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | /* Write any cplusplus specific code here */ 58 | #endif 59 | 60 | #endif /* _GML_HANDLES_H */ 61 | 62 | /* gml_handles.h ends here */ 63 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/bbs04_build.py: -------------------------------------------------------------------------------- 1 | # file "bbs04_build" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef("#define GROUPSIG_BBS04_CODE 1") 6 | #ffibuilder.cdef('#define GROUPSIG_BBS04_NAME "BBS04"') 7 | ffibuilder.cdef("#define BBS04_JOIN_START 0") 8 | ffibuilder.cdef("#define BBS04_JOIN_SEQ 1") 9 | 10 | ffibuilder.cdef(""" 11 | int bbs04_init(); 12 | """) 13 | 14 | ffibuilder.cdef(""" 15 | int bbs04_clear(); 16 | """) 17 | 18 | ffibuilder.cdef(""" 19 | int bbs04_setup( 20 | groupsig_key_t *grpkey, 21 | groupsig_key_t *mgrkey, 22 | gml_t *gml); 23 | """) 24 | 25 | ffibuilder.cdef(""" 26 | int bbs04_get_joinseq(uint8_t *seq); 27 | """) 28 | 29 | ffibuilder.cdef(""" 30 | int bbs04_get_joinstart(uint8_t *start); 31 | """) 32 | 33 | ffibuilder.cdef(""" 34 | int bbs04_join_mem( 35 | message_t **mout, 36 | groupsig_key_t *memkey, 37 | int seq, 38 | message_t *min, 39 | groupsig_key_t *grpkey); 40 | """) 41 | 42 | ffibuilder.cdef(""" 43 | int bbs04_join_mgr( 44 | message_t **mout, 45 | gml_t *gml, 46 | groupsig_key_t *mgrkey, 47 | int seq, 48 | message_t *min, 49 | groupsig_key_t *grpkey); 50 | """) 51 | 52 | ffibuilder.cdef(""" 53 | int bbs04_sign( 54 | groupsig_signature_t *sig, 55 | message_t *msg, 56 | groupsig_key_t *memkey, 57 | groupsig_key_t *grpkey, 58 | unsigned int seed); 59 | """) 60 | 61 | ffibuilder.cdef(""" 62 | int bbs04_verify( 63 | uint8_t *ok, 64 | groupsig_signature_t *sig, 65 | message_t *msg, 66 | groupsig_key_t *grpkey); 67 | """) 68 | 69 | ffibuilder.cdef(""" 70 | int bbs04_open( 71 | uint64_t *index, 72 | groupsig_proof_t *proof, 73 | crl_t *crl, 74 | groupsig_signature_t *sig, 75 | groupsig_key_t *grpkey, 76 | groupsig_key_t *mgrkey, gml_t *gml); 77 | """) 78 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/blindsig.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def blindsig_export(sig): 6 | """ 7 | Exports the given blinded signature to a Base64 string. 8 | 9 | Parameters: 10 | sig: The blinded signature to export. 11 | Returns: 12 | The produced Base64 string. On error, an Exception is thrown. 13 | """ 14 | 15 | bsig = ffi.new("byte_t **") 16 | bsig[0] = ffi.NULL 17 | size = ffi.new("uint32_t *") 18 | if lib.groupsig_blindsig_export(bsig, size, sig) == constants.IERROR: 19 | raise Exception('Error exporting blindsig.') 20 | b64sig = base64.b64encode(ffi.buffer(bsig[0],size[0])) 21 | b64sig = b64sig.decode('utf-8').replace('\n', '') 22 | # lib.free(bsig[0]) 23 | return b64sig 24 | 25 | def blindsig_import(code, b64sig): 26 | """ 27 | Imports the given blinded signature from a Base64 string. 28 | 29 | Parameters: 30 | sig: The blinded signature to import. 31 | Returns: 32 | The imported blinded signature. On error, an Exception is thrown. 33 | """ 34 | 35 | b = base64.b64decode(b64sig) 36 | sig = lib.groupsig_blindsig_import(code, b, len(b)) 37 | if sig == ffi.NULL: 38 | raise Exception('Error importing blindsig.') 39 | return sig 40 | 41 | 42 | def blindsig_to_string(sig): 43 | """ 44 | Returns a human readable string corresponding to the given blinded signature. 45 | 46 | Parameters: 47 | sig: The blinded signature to print. 48 | Returns: 49 | The produced string. On error, an Exception is thrown. 50 | """ 51 | _str = ffi.new("char *") 52 | _str = lib.groupsig_blindsig_to_string(sig) 53 | if _str == ffi.NULL: 54 | raise Exception('Error converting blindsig to string.') 55 | return ffi.string(_str).decode('utf8') 56 | -------------------------------------------------------------------------------- /src/wrappers/nodejs/jsgroupsig/src/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _BASE64_H 21 | #define _BASE64_H 22 | 23 | #include 24 | 25 | /** 26 | * @fn char* base64_encode(const unsigned char *in, uint64_t length) 27 | * @brief Base64-encodes the specified byte array. 28 | * 29 | * @param[in] in The byte array to encode. 30 | * @param[in] length The number of bytes in in. 31 | * 32 | * @return A pointer to the resulting Base64 string, or NULL if error. 33 | */ 34 | char* base64_encode(const unsigned char *in, uint64_t length, uint8_t nl); 35 | 36 | /** 37 | * @fn unsigned char* base64_decode(const char *in, uint64_t *length_dec) 38 | * @brief Decodes the given Base64 encoded string. 39 | * 40 | * @param[in] in The Base64 string to decode. 41 | * @param[in,out] length_dec Will be set to the size of the decoded byte array. 42 | * 43 | * @return A pointer to the decoded byte array. 44 | */ 45 | unsigned char* base64_decode(const char *in, uint64_t *length_dec); 46 | 47 | #endif /* _BASE64_H */ 48 | 49 | /* base64.h ends here */ 50 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/memkey.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def memkey_export(memkey): 6 | """ 7 | Exports the given member key to a Base64 string. 8 | 9 | Parameters: 10 | memkey: The native member key data structure. 11 | Returns: 12 | A Base64 string. On error, an Exception is thrown. 13 | """ 14 | 15 | bkey = ffi.new("byte_t **") 16 | bkey[0] = ffi.NULL 17 | size = ffi.new("uint32_t *") 18 | if lib.groupsig_mem_key_export(bkey, size, memkey) == constants.IERROR: 19 | raise Exception('Error exporting member key.') 20 | b64key = base64.b64encode(ffi.buffer(bkey[0],size[0])) 21 | b64key = b64key.decode('utf-8').replace('\n', '') 22 | # lib.free(bkey) 23 | return b64key 24 | 25 | def memkey_import(code, b64key): 26 | """ 27 | Imports a member key from a Base64 string. 28 | 29 | Parameters: 30 | code: The code corresponding to the group signature scheme. 31 | b64key: The Base64 string. 32 | Returns: 33 | A member key. On error, an Exception is thrown. 34 | """ 35 | 36 | b = base64.b64decode(b64key) 37 | memkey = lib.groupsig_mem_key_import(code, b, len(b)) 38 | if memkey == ffi.NULL: 39 | raise Exception('Error importing member key.') 40 | return memkey 41 | 42 | def memkey_to_string(key): 43 | """ 44 | Returns a human readable string for the given member key. 45 | 46 | Parameters: 47 | key: The native member key data structure. 48 | Returns: 49 | A human readable string. On error, an Exception is thrown. 50 | """ 51 | 52 | _str = ffi.new("char *") 53 | _str = lib.groupsig_mem_key_to_string(key) 54 | if _str == ffi.NULL: 55 | raise Exception('Error converting member key to string.') 56 | return ffi.string(_str).decode('utf8') 57 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/signature.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def signature_export(sig): 6 | """ 7 | Exports the given group signature a Base64 string. 8 | 9 | Parameters: 10 | sig: The native group signature data structure. 11 | Returns: 12 | A Base64 string. On error, an Exception is thrown. 13 | """ 14 | 15 | bsig = ffi.new("byte_t **") 16 | bsig[0] = ffi.NULL 17 | size = ffi.new("uint32_t *") 18 | if lib.groupsig_signature_export(bsig, size, sig) == constants.IERROR: 19 | raise Exception('Error exporting signature.') 20 | b64sig = base64.b64encode(ffi.buffer(bsig[0],size[0])) 21 | b64sig = b64sig.decode('utf-8').replace('\n', '') 22 | # lib.free(bsig[0]) 23 | return b64sig 24 | 25 | def signature_import(code, b64sig): 26 | """ 27 | Imports a group signature from a Base64 string. 28 | 29 | Parameters: 30 | code: The code corresponding to the group signature scheme. 31 | b64sig: The Base64 string. 32 | Returns: 33 | A group signature. On error, an Exception is thrown. 34 | """ 35 | 36 | b = base64.b64decode(b64sig) 37 | sig = lib.groupsig_signature_import(code, b, len(b)) 38 | if sig == ffi.NULL: 39 | raise Exception('Error importing signature.') 40 | return sig 41 | 42 | def signature_to_string(sig): 43 | """ 44 | Returns a human readable string for the given group signature. 45 | 46 | Parameters: 47 | sig: The group signature. 48 | Returns: 49 | A human readable string. On error, an Exception is thrown. 50 | """ 51 | 52 | _str = ffi.new("char *") 53 | _str = lib.groupsig_signature_to_string(sig) 54 | if _str == ffi.NULL: 55 | raise Exception('Error converting signature to string.') 56 | return ffi.string(_str).decode('utf8') 57 | -------------------------------------------------------------------------------- /src/groupsig/cpy06/claim_verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "sys/mem.h" 21 | #include "cpy06.h" 22 | 23 | int cpy06_claim_verify(uint8_t *ok, groupsig_proof_t *proof, 24 | groupsig_signature_t *sig, groupsig_key_t *grpkey) { 25 | 26 | groupsig_signature_t **sigs; 27 | int rc; 28 | 29 | if(!ok || 30 | !proof || proof->scheme != GROUPSIG_CPY06_CODE || 31 | !grpkey || grpkey->scheme != GROUPSIG_CPY06_CODE || 32 | !sig || sig->scheme != GROUPSIG_CPY06_CODE) { 33 | LOG_EINVAL(&logger, __FILE__, "cpy06_claim_verify", __LINE__, LOGERROR); 34 | return IERROR; 35 | } 36 | 37 | /* A claim is just similar to proving "equality" of N sigature, but just 38 | for 1 signature */ 39 | if(!(sigs = (groupsig_signature_t **) mem_malloc(sizeof(groupsig_signature_t *)))) { 40 | LOG_ERRORCODE(&logger, __FILE__, "cpy06_claim", __LINE__, errno, LOGERROR); 41 | return IERROR; 42 | } 43 | 44 | sigs[0] = sig; 45 | 46 | rc = cpy06_prove_equality_verify(ok, proof, grpkey, sigs, 1); 47 | mem_free(sigs); sigs = NULL; 48 | 49 | return rc; 50 | 51 | } 52 | 53 | /* claim_verify.c ends here */ 54 | -------------------------------------------------------------------------------- /src/groupsig/kty04/claim_verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "sys/mem.h" 21 | #include "kty04.h" 22 | 23 | int kty04_claim_verify(uint8_t *ok, groupsig_proof_t *proof, 24 | groupsig_signature_t *sig, groupsig_key_t *grpkey) { 25 | 26 | groupsig_signature_t **sigs; 27 | int rc; 28 | 29 | if(!ok || 30 | !proof || proof->scheme != GROUPSIG_KTY04_CODE || 31 | !grpkey || grpkey->scheme != GROUPSIG_KTY04_CODE || 32 | !sig || sig->scheme != GROUPSIG_KTY04_CODE) { 33 | LOG_EINVAL(&logger, __FILE__, "kty04_claim_verify", __LINE__, LOGERROR); 34 | return IERROR; 35 | } 36 | 37 | /* A claim is just similar to proving "equality" of N sigature, but just 38 | for 1 signature */ 39 | if(!(sigs = (groupsig_signature_t **) mem_malloc(sizeof(groupsig_signature_t *)))) { 40 | LOG_ERRORCODE(&logger, __FILE__, "kty04_claim", __LINE__, errno, LOGERROR); 41 | return IERROR; 42 | } 43 | 44 | sigs[0] = sig; 45 | 46 | rc = kty04_prove_equality_verify(ok, proof, grpkey, sigs, 1); 47 | mem_free(sigs); sigs = NULL; 48 | 49 | return rc; 50 | 51 | } 52 | 53 | /* claim_verify.c ends here */ 54 | -------------------------------------------------------------------------------- /src/include/identity_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _IDENTITY_HANDLES_H 21 | #define _IDENTITY_HANDLES_H 22 | 23 | #include "identity.h" 24 | /* #include "groupsig/kty04/identity.h" */ 25 | /* #include "groupsig/cpy06/identity.h" */ 26 | #include "groupsig/gl19/identity.h" 27 | #include "groupsig/dl21/identity.h" 28 | #include "groupsig/dl21seq/identity.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * @def IDENTITY_HANDLES_N 36 | * @brief Number of supported identity handles. 37 | */ 38 | #define IDENTITY_HANDLES_N 3 39 | 40 | /** 41 | * @var IDENTITY_HANDLES 42 | * @brief List of supported identity handles. 43 | */ 44 | static const identity_handle_t *IDENTITY_HANDLES[IDENTITY_HANDLES_N] = { 45 | /* &kty04_identity_handle, */ 46 | /* &cpy06_identity_handle, */ 47 | &gl19_identity_handle, 48 | &dl21_identity_handle, 49 | &dl21seq_identity_handle, 50 | }; 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | /* Write any cplusplus specific code here */ 58 | #endif 59 | 60 | #endif /* _IDENTITY_HANDLES_H */ 61 | 62 | /* identity_handles.h ends here */ 63 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/samples/src/main/java/com/ibm/jgroupsig/executable/Sign.java: -------------------------------------------------------------------------------- 1 | package com.ibm.jgroupsig.executable; 2 | 3 | import com.ibm.jgroupsig.GS; 4 | import com.ibm.jgroupsig.GL19; 5 | import com.ibm.jgroupsig.Signature; 6 | import com.ibm.jgroupsig.MemKey; 7 | 8 | import java.io.UnsupportedEncodingException; 9 | import java.lang.IllegalArgumentException; 10 | 11 | public class Sign { 12 | 13 | public static void main (String args[]) { 14 | 15 | try { 16 | /* 17 | Instantiate and setup the group. 18 | To simulate a real setting, we use three different 19 | "environments", issuer (who controls the issuing key), 20 | converter (who controls the converter key), and user 21 | (who controls a member key) 22 | */ 23 | GL19 issuer = new GL19(); 24 | GL19 converter = new GL19(); 25 | GL19 user = new GL19(); 26 | 27 | issuer.setup(); 28 | converter.setup(issuer.getGrpKey()); 29 | issuer.setup(converter.getGrpKey()); 30 | user.setGrpKey(issuer.getGrpKey()); 31 | 32 | /* Simulate adding one member */ 33 | MemKey memkey = new MemKey(GS.GL19_CODE); 34 | long mout1 = issuer.joinMgr(0, 0); 35 | long mout2 = issuer.joinMem(memkey, 1, mout1); 36 | long mout3 = issuer.joinMgr(2, mout2); 37 | issuer.joinMem(memkey, 3, mout3); 38 | 39 | /* Create sample signatures */ 40 | Signature sig = user.sign("Hello, World!", memkey); 41 | boolean b = user.verify(sig, "Hello, World!"); 42 | 43 | if (b == true) { 44 | System.out.println("VALID signature."); 45 | } else { 46 | System.out.println("WRONG signature."); 47 | } 48 | 49 | issuer.finalize(); 50 | converter.finalize(); 51 | user.finalize(); 52 | 53 | return; 54 | 55 | } catch(UnsupportedEncodingException | 56 | IllegalArgumentException e) { 57 | e.printStackTrace(); 58 | } catch(Exception e) { 59 | e.printStackTrace(); 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/groupsig/cpy06/claim.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "sys/mem.h" 21 | #include "cpy06.h" 22 | 23 | int cpy06_claim(groupsig_proof_t *proof, groupsig_key_t *memkey, 24 | groupsig_key_t *grpkey, groupsig_signature_t *sig) { 25 | 26 | groupsig_signature_t **sigs; 27 | int rc; 28 | 29 | if(!proof || proof->scheme != GROUPSIG_CPY06_CODE || 30 | !memkey || memkey->scheme != GROUPSIG_CPY06_CODE || 31 | !grpkey || grpkey->scheme != GROUPSIG_CPY06_CODE || 32 | !sig || sig->scheme != GROUPSIG_CPY06_CODE) { 33 | LOG_EINVAL(&logger, __FILE__, "cpy06_claim", __LINE__, LOGERROR); 34 | return IERROR; 35 | } 36 | 37 | /* A claim is just similar to proving "equality" of N sigature, but just 38 | for 1 signature */ 39 | if(!(sigs = (groupsig_signature_t **) mem_malloc(sizeof(groupsig_signature_t *)))) { 40 | LOG_ERRORCODE(&logger, __FILE__, "cpy06_claim", __LINE__, errno, LOGERROR); 41 | return IERROR; 42 | } 43 | 44 | sigs[0] = sig; 45 | 46 | rc = cpy06_prove_equality(proof, memkey, grpkey, sigs, 1); 47 | mem_free(sigs); sigs = NULL; 48 | 49 | return rc; 50 | 51 | } 52 | 53 | /* claim.c ends here */ 54 | -------------------------------------------------------------------------------- /src/groupsig/kty04/claim.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "sys/mem.h" 21 | #include "kty04.h" 22 | 23 | int kty04_claim(groupsig_proof_t *proof, groupsig_key_t *memkey, 24 | groupsig_key_t *grpkey, groupsig_signature_t *sig) { 25 | 26 | groupsig_signature_t **sigs; 27 | int rc; 28 | 29 | if(!proof || proof->scheme != GROUPSIG_KTY04_CODE || 30 | !memkey || memkey->scheme != GROUPSIG_KTY04_CODE || 31 | !grpkey || grpkey->scheme != GROUPSIG_KTY04_CODE || 32 | !sig || sig->scheme != GROUPSIG_KTY04_CODE) { 33 | LOG_EINVAL(&logger, __FILE__, "kty04_claim", __LINE__, LOGERROR); 34 | return IERROR; 35 | } 36 | 37 | /* A claim is just similar to proving "equality" of N sigature, but just 38 | for 1 signature */ 39 | if(!(sigs = (groupsig_signature_t **) mem_malloc(sizeof(groupsig_signature_t *)))) { 40 | LOG_ERRORCODE(&logger, __FILE__, "kty04_claim", __LINE__, errno, LOGERROR); 41 | return IERROR; 42 | } 43 | 44 | sigs[0] = sig; 45 | 46 | rc = kty04_prove_equality(proof, memkey, grpkey, sigs, 1); 47 | mem_free(sigs); sigs = NULL; 48 | 49 | return rc; 50 | 51 | } 52 | 53 | /* claim.c ends here */ 54 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/gml.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def gml_init(code): 6 | """ 7 | Initializes a Group Membership List (GML) for schemes of the given type. 8 | 9 | Parameters: 10 | code: The code of the scheme. 11 | Returns: 12 | A native object representing the GML. Throws an Exception on error. 13 | """ 14 | gml = lib.gml_init(code) 15 | if gml == ffi.NULL: 16 | raise Exception('Error initializing GML.') 17 | return gml 18 | 19 | def gml_free(gml): 20 | """ 21 | Frees the native memory used to represent the given GML. 22 | 23 | Parameters: 24 | gml: The GML structure to free. 25 | Returns: 26 | IOK (1) or IERROR (0) 27 | """ 28 | return lib.gml_free(gml) 29 | 30 | def gml_export(gml): 31 | """ 32 | Exports a GML to a Base64 string. 33 | 34 | Parameters: 35 | gml: The GML to export. 36 | Returns: 37 | A Base64 string. On error, an Exception is thrown. 38 | """ 39 | 40 | bgml = ffi.new("byte_t **") 41 | bgml[0] = ffi.NULL 42 | size = ffi.new("uint32_t *") 43 | if lib.gml_export(bgml, size, gml) == constants.IERROR: 44 | raise Exception('Error exporting GML.') 45 | b64gml = base64.b64encode(ffi.buffer(bgml[0],size[0])) 46 | b64gml = b64gml.decode('utf-8').replace('\n', '') 47 | # lib.free(bgml[0]) 48 | return b64gml 49 | 50 | def gml_import(code, b64gml): 51 | """ 52 | Imports a GML from a Base64 string. 53 | 54 | Parameters: 55 | code: The code of the scheme related to this GML. 56 | b64gml: The Base64 string. 57 | Returns: 58 | The imported GML native data structure. Throws an Exception on error. 59 | """ 60 | 61 | b = base64.b64decode(b64gml) 62 | gml = lib.gml_import(code, b, len(b)) 63 | if gml == ffi.NULL: 64 | raise Exception('Error importing GML.') 65 | return gml 66 | -------------------------------------------------------------------------------- /src/shim/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _BASE64_H 21 | #define _BASE64_H 22 | 23 | #include 24 | #include "types.h" 25 | 26 | /** 27 | * @fn char* base64_encode(const byte_t *in, uint64_t length, uint8_t nl) 28 | * @brief Base64-encodes the specified byte array. 29 | * 30 | * @param[in] in The byte array to encode. 31 | * @param[in] length The number of bytes in in. 32 | * @param[in] nl If 0, no line feeds will be added every 72 chars nor 33 | * at the end of the resulting string. Else, they will. 34 | * 35 | * @return A pointer to the resulting Base64 string, or NULL if error. 36 | */ 37 | char* base64_encode(const byte_t *in, uint64_t length, uint8_t nl); 38 | 39 | /** 40 | * @fn byte_t* base64_decode(const char *in, uint64_t *length_dec) 41 | * @brief Decodes the given Base64 encoded string. 42 | * 43 | * @param[in] in The Base64 string to decode. 44 | * @param[in,out] length_dec Will be set to the size of the decoded byte array. 45 | * 46 | * @return A pointer to the decoded byte array. 47 | */ 48 | byte_t* base64_decode(const char *in, uint64_t *length_dec); 49 | 50 | #endif /* _BASE64_H */ 51 | 52 | /* base64.h ends here */ 53 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/ps16_build.py: -------------------------------------------------------------------------------- 1 | # file "ps16_build" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef("#define GROUPSIG_PS16_CODE 4") 6 | #ffibuilder.cdef('#define GROUPSIG_PS16_NAME "PS16"') 7 | ffibuilder.cdef("#define PS16_JOIN_START 0") 8 | ffibuilder.cdef("#define PS16_JOIN_SEQ 3") 9 | 10 | ffibuilder.cdef(""" 11 | int ps16_init(); 12 | """) 13 | 14 | ffibuilder.cdef(""" 15 | int ps16_clear(); 16 | """) 17 | 18 | ffibuilder.cdef(""" 19 | int ps16_setup( 20 | groupsig_key_t *grpkey, 21 | groupsig_key_t *mgrkey, 22 | gml_t *gml); 23 | """) 24 | 25 | ffibuilder.cdef(""" 26 | int ps16_get_joinseq(uint8_t *seq); 27 | """) 28 | 29 | ffibuilder.cdef(""" 30 | int ps16_get_joinstart(uint8_t *start); 31 | """) 32 | 33 | ffibuilder.cdef(""" 34 | int ps16_join_mem( 35 | message_t **mout, 36 | groupsig_key_t *memkey, 37 | int seq, 38 | message_t *min, 39 | groupsig_key_t *grpkey); 40 | """) 41 | 42 | ffibuilder.cdef(""" 43 | int ps16_join_mgr( 44 | message_t **mout, 45 | gml_t *gml, 46 | groupsig_key_t *mgrkey, 47 | int seq, 48 | message_t *min, 49 | groupsig_key_t *grpkey); 50 | """) 51 | 52 | ffibuilder.cdef(""" 53 | int ps16_sign( 54 | groupsig_signature_t *sig, 55 | message_t *msg, 56 | groupsig_key_t *memkey, 57 | groupsig_key_t *grpkey, 58 | unsigned int seed); 59 | """) 60 | 61 | ffibuilder.cdef(""" 62 | int ps16_verify( 63 | uint8_t *ok, 64 | groupsig_signature_t *sig, 65 | message_t *msg, 66 | groupsig_key_t *grpkey); 67 | """) 68 | 69 | ffibuilder.cdef(""" 70 | int ps16_open( 71 | uint64_t *index, 72 | groupsig_proof_t *proof, 73 | crl_t *crl, 74 | groupsig_signature_t *sig, 75 | groupsig_key_t *grpkey, 76 | groupsig_key_t *mgrkey, gml_t *gml); 77 | """) 78 | 79 | ffibuilder.cdef(""" 80 | int ps16_open_verify( 81 | uint8_t *ok, 82 | groupsig_proof_t *proof, 83 | groupsig_signature_t *sig, 84 | groupsig_key_t *grpkey); 85 | """) 86 | -------------------------------------------------------------------------------- /src/include/proof_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _PROOF_HANDLES_H 21 | #define _PROOF_HANDLES_H 22 | 23 | #include 24 | #include "proof.h" 25 | /* #include "groupsig/kty04/proof.h" */ 26 | /* #include "groupsig/cpy06/proof.h" */ 27 | #include "groupsig/ps16/proof.h" 28 | #include "groupsig/klap20/proof.h" 29 | #include "groupsig/dl21/proof.h" 30 | #include "groupsig/dl21seq/proof.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /** 37 | * @def GROUPSIG_PROOF_HANDLES_N 38 | * @brief Number of supported proof bundles. 39 | */ 40 | #define GROUPSIG_PROOF_HANDLES_N 4 41 | 42 | /** 43 | * @var GROUPSIG_PROOF_HANDLES 44 | * @brief List of supported bundles for managing proofs. 45 | */ 46 | static const groupsig_proof_handle_t *GROUPSIG_PROOF_HANDLES[GROUPSIG_PROOF_HANDLES_N] = { 47 | //&kty04_proof_handle, 48 | //&cpy06_proof_handle, 49 | &ps16_proof_handle, 50 | &klap20_proof_handle, 51 | &dl21_proof_handle, 52 | &dl21seq_proof_handle, 53 | }; 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | /* Write any cplusplus specific code here */ 61 | #endif 62 | 63 | #endif /* _PROOF_HANDLES_H */ 64 | 65 | /* proof_handles.h ends here */ 66 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/identity.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | 4 | def identity_init(code): 5 | """ 6 | Initializes an identity for schemes of the specified type. 7 | 8 | Parameters: 9 | code: The group signature scheme code. 10 | Returns: 11 | A native identity data structure. On error, an Exception is thrown. 12 | """ 13 | 14 | identity = lib.identity_init(code) 15 | if identity == ffi.NULL: 16 | raise Exception('Error initializing identity.') 17 | return identity 18 | 19 | def identity_free(identity): 20 | """ 21 | Frees the memory used for the given identity. 22 | 23 | Parameters: 24 | identity: The identity data to free. 25 | """ 26 | 27 | return lib.identity_free(identity) 28 | 29 | def identity_cmp(id1, id2): 30 | """ 31 | Compares two identities. 32 | 33 | Parameters: 34 | id1: The first identity. 35 | id2: The second identity. 36 | Returns: 37 | 0 if the identities are the same, not 0 if they are different. 38 | """ 39 | 40 | return lib.identity_cmp(id1, id2) 41 | 42 | def identity_to_string(identity): 43 | """ 44 | Exports the given identity to a string. 45 | 46 | Parameters: 47 | identity: The identity to export. 48 | Returns: 49 | A string. On error, an Exception is thrown. 50 | """ 51 | 52 | string = lib.identity_to_string(identity) 53 | if string == ffi.NULL: 54 | raise Exception('Error converting id to string.') 55 | return ffi.string(string).decode('utf8') 56 | 57 | def identity_from_string(string): 58 | """ 59 | Imports an identity from the given string. 60 | 61 | Parameters: 62 | string: The string containing the identity to import. 63 | Returns: 64 | An identity. On error, an Exception is thrown. 65 | """ 66 | 67 | identity = lib.identity_from_string(string) 68 | if identity == ffi.NULL: 69 | raise Exception('Error getting id from string.') 70 | return identity 71 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/proof_build.py: -------------------------------------------------------------------------------- 1 | # file "proof_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef struct { 7 | uint8_t scheme; 8 | void *proof; 9 | } groupsig_proof_t; 10 | """) 11 | 12 | ffibuilder.cdef(""" 13 | typedef groupsig_proof_t* (*groupsig_proof_init_f)(void); 14 | """) 15 | 16 | ffibuilder.cdef(""" 17 | typedef int (*groupsig_proof_free_f)(groupsig_proof_t *proof); 18 | """) 19 | 20 | ffibuilder.cdef(""" 21 | typedef int (*groupsig_proof_get_size_f)(groupsig_proof_t *proof); 22 | """) 23 | 24 | ffibuilder.cdef(""" 25 | typedef int (*groupsig_proof_export_f)( 26 | byte_t **bytes, 27 | uint32_t *size, 28 | groupsig_proof_t *proof); 29 | """) 30 | 31 | ffibuilder.cdef(""" 32 | typedef groupsig_proof_t* (*groupsig_proof_import_f)( 33 | byte_t *source, 34 | uint32_t size); 35 | """) 36 | 37 | ffibuilder.cdef(""" 38 | typedef char* (*groupsig_proof_to_string_f)(groupsig_proof_t *proof); 39 | """) 40 | 41 | ffibuilder.cdef(""" 42 | typedef struct { 43 | uint8_t scheme; 44 | groupsig_proof_init_f init; 45 | groupsig_proof_free_f free; 46 | groupsig_proof_get_size_f get_size; 47 | groupsig_proof_export_f gexport; 48 | groupsig_proof_import_f gimport; 49 | groupsig_proof_to_string_f to_string; 50 | } groupsig_proof_handle_t; 51 | """) 52 | 53 | ffibuilder.cdef(""" 54 | const groupsig_proof_handle_t* groupsig_proof_handle_from_code(uint8_t code); 55 | """) 56 | 57 | ffibuilder.cdef(""" 58 | groupsig_proof_t* groupsig_proof_init(uint8_t code); 59 | """) 60 | 61 | ffibuilder.cdef(""" 62 | int groupsig_proof_free(groupsig_proof_t *proof); 63 | """) 64 | 65 | ffibuilder.cdef(""" 66 | int groupsig_proof_get_size(groupsig_proof_t *proof); 67 | """) 68 | 69 | ffibuilder.cdef(""" 70 | int groupsig_proof_export( 71 | byte_t **bytes, 72 | uint32_t *size, 73 | groupsig_proof_t *proof); 74 | """) 75 | 76 | ffibuilder.cdef(""" 77 | groupsig_proof_t* groupsig_proof_import( 78 | uint8_t code, 79 | byte_t *bytes, 80 | uint32_t size); 81 | """) 82 | 83 | ffibuilder.cdef(""" 84 | char* groupsig_proof_to_string(groupsig_proof_t *proof); 85 | """) 86 | -------------------------------------------------------------------------------- /src/sys/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _MEM_H 21 | #define _MEM_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include 28 | 29 | /** 30 | * @fn void* mem_malloc(size_t *size) 31 | * @brief Like malloc, but sets all the allocated bytes to 0. 32 | * 33 | * @param[in] size The number of bytes to allocate. 34 | * 35 | * @return The allocated pointer, or NULL. 36 | */ 37 | void* mem_malloc(size_t size); 38 | 39 | /** 40 | * @fn void* mem_realloc(void* ptr, size_t size) 41 | * Like normal realloc, but sets to 0 all the newly allocated memory. 42 | * Actually... @todo 43 | * 44 | * @param[in,out] ptr A pointer to the memory to reallocate. 45 | * @param[in] size The new size. 46 | * 47 | * @return A pointer to the reallocated memory. 48 | */ 49 | void* mem_realloc(void* ptr, size_t size); 50 | 51 | /** 52 | * @fn int mem_free(void* p) 53 | * @brief Frees the given pointer and sets it to NULL; 54 | * 55 | * @param[in,out] p The pointer to free. 56 | * 57 | * @return IOK. 58 | */ 59 | int mem_free(void *p); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #ifdef __cplusplus 66 | /* Write any cplusplus specific code here */ 67 | #endif 68 | 69 | #endif /* _MEM_H */ 70 | 71 | /* mem.h ends here */ 72 | -------------------------------------------------------------------------------- /src/groupsig/bbs04/claim_verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "sys/mem.h" 21 | #include "bbs04.h" 22 | 23 | int bbs04_claim_verify(uint8_t *ok, groupsig_proof_t *proof, 24 | groupsig_signature_t *sig, groupsig_key_t *grpkey) { 25 | 26 | /* groupsig_signature_t **sigs; */ 27 | /* int rc; */ 28 | 29 | /* if(!ok || */ 30 | /* !proof || proof->scheme != GROUPSIG_BBS04_CODE || */ 31 | /* !grpkey || grpkey->scheme != GROUPSIG_BBS04_CODE || */ 32 | /* !sig || sig->scheme != GROUPSIG_BBS04_CODE) { */ 33 | /* LOG_EINVAL(&logger, __FILE__, "bbs04_claim_verify", __LINE__, LOGERROR); */ 34 | /* return IERROR; */ 35 | /* } */ 36 | 37 | /* /\* A claim is just similar to proving "equality" of N sigature, but just */ 38 | /* for 1 signature *\/ */ 39 | /* if(!(sigs = (groupsig_signature_t **) mem_malloc(sizeof(groupsig_signature_t *)))) { */ 40 | /* LOG_ERRORCODE(&logger, __FILE__, "bbs04_claim", __LINE__, errno, LOGERROR); */ 41 | /* return IERROR; */ 42 | /* } */ 43 | 44 | /* sigs[0] = sig; */ 45 | 46 | /* rc = bbs04_prove_equality_verify(ok, proof, grpkey, sigs, 1); */ 47 | /* mem_free(sigs); sigs = NULL; */ 48 | 49 | /* return rc; */ 50 | return IOK; 51 | 52 | } 53 | 54 | /* claim_verify.c ends here */ 55 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/message.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def message_from_string(mstr): 6 | """ 7 | Imports a message from a UTF-8 string. 8 | 9 | Parameters: 10 | mstr: The string. 11 | Returns: 12 | A message data structure. On error, an Exception is thrown. 13 | """ 14 | 15 | msg = lib.message_from_string(mstr.encode('utf8')) 16 | if msg == ffi.NULL: 17 | raise Exception('Error parsing message the given string.') 18 | return msg 19 | 20 | def message_to_string(msg): 21 | """ 22 | Exports the given message object to a UTF-8 string. Use only for messages 23 | that are ensured to be strings. 24 | 25 | Parameters: 26 | msg: The message to export to a string. 27 | Returns: 28 | A UTF-8 string. On error, an Exception is thrown. 29 | """ 30 | 31 | _str = ffi.new("char *") 32 | _str = lib.message_to_string(msg) 33 | if _str == ffi.NULL: 34 | raise Exception('Error converting message to string.') 35 | return ffi.string(_str).decode('utf8') 36 | 37 | def message_from_base64(b64): 38 | """ 39 | Imports a message from a Base64 string. 40 | 41 | Parameters: 42 | b64: The Base64 string. 43 | Returns: 44 | A message data structure. On error, an Exception is thrown. 45 | """ 46 | 47 | b = base64.b64decode(b64) 48 | msg = lib.message_from_bytes(b, len(b)) 49 | if msg == ffi.NULL: 50 | raise Exception('Error parsing message the given Base64 string.') 51 | return msg 52 | 53 | def message_to_base64(msg): 54 | """ 55 | Exports the given message object to a Base64 string. 56 | 57 | Parameters: 58 | msg: The message to export to a string. 59 | Returns: 60 | A Base64 string. On error, an Exception is thrown. 61 | """ 62 | 63 | _str = ffi.new("char *") 64 | _str = lib.message_to_base64(msg) 65 | if _str == ffi.NULL: 66 | raise Exception('Error converting message to a Base64 string.') 67 | return ffi.string(_str).decode('utf8') 68 | -------------------------------------------------------------------------------- /src/groupsig/bbs04/claim.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "sys/mem.h" 21 | #include "bbs04.h" 22 | 23 | int bbs04_claim(groupsig_proof_t *proof, groupsig_key_t *memkey, 24 | groupsig_key_t *grpkey, groupsig_signature_t *sig) { 25 | 26 | /* groupsig_signature_t **sigs; */ 27 | /* int rc; */ 28 | 29 | /* if(!proof || proof->scheme != GROUPSIG_BBS04_CODE || */ 30 | /* !memkey || memkey->scheme != GROUPSIG_BBS04_CODE || */ 31 | /* !grpkey || grpkey->scheme != GROUPSIG_BBS04_CODE || */ 32 | /* !sig || sig->scheme != GROUPSIG_BBS04_CODE) { */ 33 | /* LOG_EINVAL(&logger, __FILE__, "bbs04_claim", __LINE__, LOGERROR); */ 34 | /* return IERROR; */ 35 | /* } */ 36 | 37 | /* /\* A claim is just similar to proving "equality" of N sigature, but just */ 38 | /* for 1 signature *\/ */ 39 | /* if(!(sigs = (groupsig_signature_t **) mem_malloc(sizeof(groupsig_signature_t *)))) { */ 40 | /* LOG_ERRORCODE(&logger, __FILE__, "bbs04_claim", __LINE__, errno, LOGERROR); */ 41 | /* return IERROR; */ 42 | /* } */ 43 | 44 | /* sigs[0] = sig; */ 45 | 46 | /* rc = bbs04_prove_equality(proof, memkey, grpkey, sigs, 1); */ 47 | /* mem_free(sigs); sigs = NULL; */ 48 | 49 | /* return rc; */ 50 | 51 | return IOK; 52 | 53 | } 54 | 55 | /* claim.c ends here */ 56 | -------------------------------------------------------------------------------- /src/misc/profile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _PROFILE_H 21 | #define _PROFILE_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | typedef struct { 28 | struct timeval tvbegin; 29 | struct timeval tvend; 30 | clock_t clckbegin; 31 | clock_t clckend; 32 | uint64_t cyclebegin; 33 | uint64_t cycleend; 34 | } profile_entry_t; 35 | 36 | typedef struct { 37 | char *filename; 38 | profile_entry_t *entries; 39 | uint64_t n; 40 | uint64_t printed; 41 | } profile_t; 42 | 43 | uint64_t rdtsc(); 44 | profile_t* profile_begin(char *filename); 45 | int profile_free(profile_t *profile); 46 | int profile_get_time(struct timeval *tv, clock_t *clck, uint64_t *cycle); 47 | int profile_add_entry(profile_t *profile, struct timeval *tvbegin, struct timeval *tvend, 48 | clock_t clckbegin, clock_t clckend, uint64_t cyclebegin, uint64_t cycleend); 49 | 50 | /* 51 | Utility function: given the entries in prof, computes their average and 52 | standard deviation, and appends to the file specified in prof, a line with 53 | format: 54 | \t\t\t\t\t\n 55 | */ 56 | int profile_process_and_dump(profile_t *prof, int code, char *operation); 57 | 58 | #endif 59 | 60 | /* profile.h ends here */ 61 | -------------------------------------------------------------------------------- /src/include/mem_key_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _MEM_KEY_HANDLES_H 21 | #define _MEM_KEY_HANDLES_H 22 | 23 | #include "mem_key.h" 24 | /* #include "groupsig/kty04/mem_key.h" */ 25 | #include "groupsig/bbs04/mem_key.h" 26 | /* #include "groupsig/cpy06/mem_key.h" */ 27 | #include "groupsig/gl19/mem_key.h" 28 | #include "groupsig/ps16/mem_key.h" 29 | #include "groupsig/klap20/mem_key.h" 30 | #include "groupsig/dl21/mem_key.h" 31 | #include "groupsig/dl21seq/mem_key.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** 38 | * @def GROUPSIG_MEM_KEY_HANDLES_N 39 | * @brief Number of known handles of member key schemes. 40 | */ 41 | #define GROUPSIG_MEM_KEY_HANDLES_N 6 42 | 43 | /** 44 | * @var GROUPSIG_MEM_KEY_HANDLES 45 | * @brief List of handles of supported member key schemes. 46 | */ 47 | static const mem_key_handle_t *GROUPSIG_MEM_KEY_HANDLES[GROUPSIG_MEM_KEY_HANDLES_N] = { 48 | /* &kty04_mem_key_handle, */ 49 | &bbs04_mem_key_handle, 50 | /* &cpy06_mem_key_handle, */ 51 | &gl19_mem_key_handle, 52 | &ps16_mem_key_handle, 53 | &klap20_mem_key_handle, 54 | &dl21_mem_key_handle, 55 | &dl21seq_mem_key_handle, 56 | }; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | /* Write any cplusplus specific code here */ 64 | #endif 65 | 66 | #endif /* _MEM_KEY_HANDLES_H */ 67 | 68 | /* mem_key_handles.h ends here */ 69 | -------------------------------------------------------------------------------- /src/include/grp_key_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _GRP_KEY_HANDLES_H 21 | #define _GRP_KEY_HANDLES_H 22 | 23 | #include "grp_key.h" 24 | /* #include "groupsig/kty04/grp_key.h" */ 25 | #include "groupsig/bbs04/grp_key.h" 26 | /* #include "groupsig/cpy06/grp_key.h" */ 27 | #include "groupsig/gl19/grp_key.h" 28 | #include "groupsig/ps16/grp_key.h" 29 | #include "groupsig/klap20/grp_key.h" 30 | #include "groupsig/dl21/grp_key.h" 31 | #include "groupsig/dl21seq/grp_key.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** 38 | * @def GROUPSIG_GRP_KEY_HANDLES_N 39 | * @brief Number of supported group key implementations. 40 | */ 41 | #define GROUPSIG_GRP_KEY_HANDLES_N 6 42 | 43 | /** 44 | * @var GROUPSIG_GRP_KEY_HANDLES 45 | * @brief Set of handles for the known group key implementations. 46 | */ 47 | static const grp_key_handle_t *GROUPSIG_GRP_KEY_HANDLES[GROUPSIG_GRP_KEY_HANDLES_N] = { 48 | /* &kty04_grp_key_handle, */ 49 | &bbs04_grp_key_handle, 50 | /* &cpy06_grp_key_handle, */ 51 | &gl19_grp_key_handle, 52 | &ps16_grp_key_handle, 53 | &klap20_grp_key_handle, 54 | &dl21_grp_key_handle, 55 | &dl21seq_grp_key_handle, 56 | }; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | /* Write any cplusplus specific code here */ 64 | #endif 65 | 66 | #endif /* _GRP_KEY_HANDLES_H */ 67 | 68 | /* grp_key_handles.h ends here */ 69 | -------------------------------------------------------------------------------- /src/include/mgr_key_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _MGR_KEY_HANDLES_H 21 | #define _MGR_KEY_HANDLES_H 22 | 23 | #include "mgr_key.h" 24 | /* #include "groupsig/kty04/mgr_key.h" */ 25 | #include "groupsig/bbs04/mgr_key.h" 26 | /* #include "groupsig/cpy06/mgr_key.h" */ 27 | #include "groupsig/gl19/mgr_key.h" 28 | #include "groupsig/ps16/mgr_key.h" 29 | #include "groupsig/klap20/mgr_key.h" 30 | #include "groupsig/dl21/mgr_key.h" 31 | #include "groupsig/dl21seq/mgr_key.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** 38 | * @def GROUPSIG_MGR_KEY_HANDLES_N 39 | * @brief Number of supported bundles of manager key handles. 40 | */ 41 | #define GROUPSIG_MGR_KEY_HANDLES_N 6 42 | 43 | /** 44 | * @var GROUPSIG_MGR_KEY_HANDLES 45 | * @brief List of supported bundles of manager key handles. 46 | */ 47 | static const mgr_key_handle_t *GROUPSIG_MGR_KEY_HANDLES[GROUPSIG_MGR_KEY_HANDLES_N] = { 48 | /* &kty04_mgr_key_handle, */ 49 | &bbs04_mgr_key_handle, 50 | /* &cpy06_mgr_key_handle, */ 51 | &gl19_mgr_key_handle, 52 | &ps16_mgr_key_handle, 53 | &klap20_mgr_key_handle, 54 | &dl21_mgr_key_handle, 55 | &dl21seq_mgr_key_handle, 56 | }; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | /* Write any cplusplus specific code here */ 64 | #endif 65 | 66 | #endif /* _MGR_KEY_HANDLES_H */ 67 | 68 | /* mgr_key_handles.h ends here */ 69 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/gl19_build.py: -------------------------------------------------------------------------------- 1 | # file "gl19_build" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef("#define GROUPSIG_GL19_CODE 3") 6 | #ffibuilder.cdef('#define GROUPSIG_GL19_NAME "GL19"') 7 | ffibuilder.cdef("#define GL19_JOIN_START 0") 8 | ffibuilder.cdef("#define GL19_JOIN_SEQ 3") 9 | 10 | ffibuilder.cdef(""" 11 | int gl19_init(); 12 | """) 13 | 14 | ffibuilder.cdef(""" 15 | int gl19_clear(); 16 | """) 17 | 18 | ffibuilder.cdef(""" 19 | int gl19_setup(groupsig_key_t *grpkey, groupsig_key_t *mgrkey, gml_t *gml); 20 | """) 21 | 22 | ffibuilder.cdef(""" 23 | int gl19_get_joinseq(uint8_t *seq); 24 | """) 25 | 26 | ffibuilder.cdef(""" 27 | int gl19_get_joinstart(uint8_t *start); 28 | """) 29 | 30 | ffibuilder.cdef(""" 31 | int gl19_join_mem(message_t **mout, groupsig_key_t *memkey, 32 | int seq, message_t *min, groupsig_key_t *grpkey); 33 | """) 34 | 35 | ffibuilder.cdef(""" 36 | int gl19_join_mgr(message_t **mout, gml_t *gml, 37 | groupsig_key_t *mgrkey, 38 | int seq, message_t *min, groupsig_key_t *grpkey); 39 | """) 40 | 41 | ffibuilder.cdef(""" 42 | int gl19_sign(groupsig_signature_t *sig, message_t *msg, groupsig_key_t *memkey, 43 | groupsig_key_t *grpkey, unsigned int seed); 44 | """) 45 | 46 | ffibuilder.cdef(""" 47 | int gl19_verify(uint8_t *ok, groupsig_signature_t *sig, message_t *msg, 48 | groupsig_key_t *grpkey); 49 | """) 50 | 51 | ffibuilder.cdef(""" 52 | int gl19_blind(groupsig_blindsig_t *bsig, groupsig_key_t **bldkey, 53 | groupsig_key_t *grpkey, groupsig_signature_t *sig, 54 | message_t *msg); 55 | """) 56 | 57 | ffibuilder.cdef(""" 58 | int gl19_convert(groupsig_blindsig_t **csig, 59 | groupsig_blindsig_t **bsig, uint32_t n_bsigs, 60 | groupsig_key_t *grpkey, groupsig_key_t *mgrkey, 61 | groupsig_key_t *bldkey, message_t *msg); 62 | """) 63 | 64 | ffibuilder.cdef(""" 65 | int gl19_unblind(identity_t *nym, groupsig_signature_t *sig, 66 | groupsig_blindsig_t *bsig, 67 | groupsig_key_t *grpkey, groupsig_key_t *bldkey, 68 | message_t *msg); 69 | """) 70 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/klap20_build.py: -------------------------------------------------------------------------------- 1 | # file "klap20_build" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef("#define GROUPSIG_KLAP20_CODE 5") 6 | #ffibuilder.cdef('#define GROUPSIG_KLAP20_NAME "KLAP20"') 7 | ffibuilder.cdef("#define KLAP20_JOIN_START 0") 8 | ffibuilder.cdef("#define KLAP20_JOIN_SEQ 3") 9 | 10 | ffibuilder.cdef(""" 11 | int klap20_init(); 12 | """) 13 | 14 | ffibuilder.cdef(""" 15 | int klap20_clear(); 16 | """) 17 | 18 | ffibuilder.cdef(""" 19 | int klap20_setup( 20 | groupsig_key_t *grpkey, 21 | groupsig_key_t *mgrkey, 22 | gml_t *gml); 23 | """) 24 | 25 | ffibuilder.cdef(""" 26 | int klap20_get_joinseq(uint8_t *seq); 27 | """) 28 | 29 | ffibuilder.cdef(""" 30 | int klap20_get_joinstart(uint8_t *start); 31 | """) 32 | 33 | ffibuilder.cdef(""" 34 | int klap20_join_mem( 35 | message_t **mout, 36 | groupsig_key_t *memkey, 37 | int seq, 38 | message_t *min, 39 | groupsig_key_t *grpkey); 40 | """) 41 | 42 | ffibuilder.cdef(""" 43 | int klap20_join_mgr( 44 | message_t **mout, 45 | gml_t *gml, 46 | groupsig_key_t *mgrkey, 47 | int seq, 48 | message_t *min, 49 | groupsig_key_t *grpkey); 50 | """) 51 | 52 | ffibuilder.cdef(""" 53 | int klap20_sign( 54 | groupsig_signature_t *sig, 55 | message_t *msg, 56 | groupsig_key_t *memkey, 57 | groupsig_key_t *grpkey, 58 | unsigned int seed); 59 | """) 60 | 61 | ffibuilder.cdef(""" 62 | int klap20_verify( 63 | uint8_t *ok, 64 | groupsig_signature_t *sig, 65 | message_t *msg, 66 | groupsig_key_t *grpkey); 67 | """) 68 | 69 | ffibuilder.cdef(""" 70 | int klap20_verify_batch( 71 | uint8_t *ok, 72 | groupsig_signature_t **sigs, 73 | message_t **msgs, 74 | uint32_t n, 75 | groupsig_key_t *grpkey); 76 | """) 77 | 78 | ffibuilder.cdef(""" 79 | int klap20_open( 80 | uint64_t *index, 81 | groupsig_proof_t *proof, 82 | crl_t *crl, 83 | groupsig_signature_t *sig, 84 | groupsig_key_t *grpkey, 85 | groupsig_key_t *mgrkey, gml_t *gml); 86 | """) 87 | 88 | ffibuilder.cdef(""" 89 | int klap20_open_verify( 90 | uint8_t *ok, 91 | groupsig_proof_t *proof, 92 | groupsig_signature_t *sig, 93 | groupsig_key_t *grpkey); 94 | """) 95 | -------------------------------------------------------------------------------- /src/include/signature_handles.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _SIGNATURE_HANDLES_H 21 | #define _SIGNATURE_HANDLES_H 22 | 23 | #include "signature.h" 24 | /* #include "groupsig/kty04/signature.h" */ 25 | #include "groupsig/bbs04/signature.h" 26 | /* #include "groupsig/cpy06/signature.h" */ 27 | #include "groupsig/gl19/signature.h" 28 | #include "groupsig/ps16/signature.h" 29 | #include "groupsig/klap20/signature.h" 30 | #include "groupsig/dl21/signature.h" 31 | #include "groupsig/dl21seq/signature.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** 38 | * @def GROUPSIG_SIGNATURE_HANDLES_N 39 | * @brief Number of supported set of handles for managing group signatures. 40 | */ 41 | #define GROUPSIG_SIGNATURE_HANDLES_N 6 42 | 43 | /** 44 | * @var GROUPSIG_SIGNATURE_HANDLES 45 | * @brief List of supported set of handles for managing group signatures. 46 | */ 47 | static const groupsig_signature_handle_t *GROUPSIG_SIGNATURE_HANDLES[GROUPSIG_SIGNATURE_HANDLES_N] = { 48 | /* &kty04_signature_handle, */ 49 | &bbs04_signature_handle, 50 | /* &cpy06_signature_handle, */ 51 | &gl19_signature_handle, 52 | &ps16_signature_handle, 53 | &klap20_signature_handle, 54 | &dl21_signature_handle, 55 | &dl21seq_signature_handle, 56 | }; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | /* Write any cplusplus specific code here */ 64 | #endif 65 | 66 | #endif /* _SIGNATURE_HANDLES_H */ 67 | 68 | /* signature_handles.h ends here */ 69 | -------------------------------------------------------------------------------- /src/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Test suites 2 | 3 | # Tests for GL19 4 | add_executable(GL19Test test_gl19.cpp) 5 | target_link_libraries(GL19Test 6 | PUBLIC 7 | groupsig 8 | big 9 | sys 10 | logger 11 | gtest_main 12 | gtest 13 | pthread) 14 | add_test(NAME GL19Test COMMAND GL19Test) 15 | 16 | # Tests for BBS04 17 | add_executable(BBS04Test test_bbs04.cpp) 18 | target_link_libraries(BBS04Test 19 | PUBLIC 20 | groupsig 21 | big 22 | sys 23 | logger 24 | gtest_main 25 | gtest 26 | pthread) 27 | add_test(NAME BBS04Test COMMAND BBS04Test) 28 | 29 | # Tests for PS16 30 | add_executable(PS16Test test_ps16.cpp) 31 | target_link_libraries(PS16Test 32 | PUBLIC 33 | groupsig 34 | big 35 | sys 36 | logger 37 | gtest_main 38 | gtest 39 | pthread) 40 | add_test(NAME PS16Test COMMAND PS16Test) 41 | 42 | # Tests for KLAP20 43 | add_executable(KLAP20Test test_klap20.cpp) 44 | target_link_libraries(KLAP20Test 45 | PUBLIC 46 | groupsig 47 | big 48 | sys 49 | logger 50 | gtest_main 51 | gtest 52 | pthread) 53 | add_test(NAME KLAP20Test COMMAND KLAP20Test) 54 | 55 | # Tests for DL21 56 | add_executable(DL21Test test_dl21.cpp) 57 | target_link_libraries(DL21Test 58 | PUBLIC 59 | groupsig 60 | big 61 | sys 62 | logger 63 | gtest_main 64 | gtest 65 | pthread) 66 | add_test(NAME DL21Test COMMAND DL21Test) 67 | 68 | # Tests for DL21SEQ 69 | add_executable(DL21SEQTest test_dl21seq.cpp) 70 | target_link_libraries(DL21SEQTest 71 | PUBLIC 72 | groupsig 73 | big 74 | sys 75 | logger 76 | gtest_main 77 | gtest 78 | pthread) 79 | add_test(NAME DL21SEQTest COMMAND DL21SEQTest) 80 | 81 | # Tests for Bigz 82 | add_executable(BigzTest test_bigz.cpp) 83 | target_link_libraries(BigzTest 84 | PUBLIC 85 | big 86 | sys 87 | logger 88 | gtest_main 89 | gtest 90 | pthread) 91 | add_test(NAME BigzTest COMMAND BigzTest) 92 | 93 | # Tests for PBC 94 | add_executable(PBCTest test_pbc.cpp) 95 | target_link_libraries(PBCTest 96 | PUBLIC 97 | pbcext 98 | base64 99 | sys 100 | logger 101 | gtest_main 102 | gtest 103 | pthread) 104 | add_test(NAME PBCTest COMMAND PBCTest) 105 | 106 | # Tests for Hash 107 | add_executable(HashTest test_hash.cpp) 108 | target_link_libraries(HashTest 109 | PUBLIC 110 | hash 111 | sys 112 | logger 113 | gtest_main 114 | gtest 115 | pthread) 116 | add_test(NAME HashTest COMMAND HashTest) 117 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/blindsig_build.py: -------------------------------------------------------------------------------- 1 | # file "blindsig_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef struct { 7 | uint8_t scheme; 8 | void *sig; 9 | } groupsig_blindsig_t; 10 | """) 11 | 12 | ffibuilder.cdef(""" 13 | typedef groupsig_blindsig_t* (*groupsig_blindsig_init_f)(void); 14 | """) 15 | 16 | ffibuilder.cdef(""" 17 | typedef int (*groupsig_blindsig_free_f)(groupsig_blindsig_t *blindsig); 18 | """) 19 | 20 | ffibuilder.cdef(""" 21 | typedef int (*groupsig_blindsig_copy_f)(groupsig_blindsig_t *dst, groupsig_blindsig_t *src); 22 | """) 23 | 24 | ffibuilder.cdef(""" 25 | typedef int (*groupsig_blindsig_get_size_f)(groupsig_blindsig_t *sig); 26 | """) 27 | 28 | ffibuilder.cdef(""" 29 | typedef int (*groupsig_blindsig_export_f)(unsigned char **bytes, 30 | uint32_t *size, 31 | groupsig_blindsig_t *blindsig); 32 | """) 33 | 34 | ffibuilder.cdef(""" 35 | typedef groupsig_blindsig_t* (*groupsig_blindsig_import_f)(unsigned char *source, 36 | uint32_t size); 37 | """) 38 | 39 | ffibuilder.cdef(""" 40 | typedef char* (*groupsig_blindsig_to_string_f)(groupsig_blindsig_t *blindsig); 41 | """) 42 | 43 | ffibuilder.cdef(""" 44 | typedef struct { 45 | uint8_t scheme; 46 | groupsig_blindsig_init_f init; 47 | groupsig_blindsig_free_f free; 48 | groupsig_blindsig_copy_f copy; 49 | groupsig_blindsig_get_size_f get_size; 50 | groupsig_blindsig_export_f gexport; 51 | groupsig_blindsig_import_f gimport; 52 | groupsig_blindsig_to_string_f to_string; 53 | } groupsig_blindsig_handle_t; 54 | """) 55 | 56 | ffibuilder.cdef(""" 57 | const groupsig_blindsig_handle_t* groupsig_blindsig_handle_from_code(uint8_t code); 58 | """) 59 | 60 | ffibuilder.cdef(""" 61 | groupsig_blindsig_t* groupsig_blindsig_init(uint8_t code); 62 | """) 63 | 64 | ffibuilder.cdef(""" 65 | int groupsig_blindsig_free(groupsig_blindsig_t *sig); 66 | """) 67 | 68 | ffibuilder.cdef(""" 69 | int groupsig_blindsig_copy(groupsig_blindsig_t *dst, groupsig_blindsig_t *src); 70 | """) 71 | 72 | ffibuilder.cdef(""" 73 | int groupsig_blindsig_get_size(groupsig_blindsig_t *sig); 74 | """) 75 | 76 | ffibuilder.cdef(""" 77 | int groupsig_blindsig_export( 78 | unsigned char **bytes, 79 | uint32_t *size, 80 | groupsig_blindsig_t *sig); 81 | """) 82 | 83 | ffibuilder.cdef(""" 84 | groupsig_blindsig_t* groupsig_blindsig_import( 85 | uint8_t code, 86 | unsigned char *source, 87 | uint32_t size); 88 | """) 89 | 90 | ffibuilder.cdef(""" 91 | char* groupsig_blindsig_to_string(groupsig_blindsig_t *sig); 92 | """) 93 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake requirements 2 | cmake_minimum_required (VERSION 3.13) 3 | set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}") 4 | 5 | # Generic library information 6 | project (libgroupsig) 7 | set (libgroupsig_VERSION_MAJOR 1) 8 | set (libgroupsig_VERSION_MINOR 0) 9 | set (libgroupsig_VERSION_PATCH 0) 10 | 11 | # Set the paths for produced libraries and runtime binaries 12 | set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 13 | set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 14 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 15 | set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") 16 | 17 | # Global compiler flags 18 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") 19 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") 20 | 21 | # Add the binary tree to the search path for include files 22 | include_directories("${CMAKE_SOURCE_DIR}/src") 23 | include_directories("${CMAKE_SOURCE_DIR}/src/include") 24 | include_directories("${CMAKE_BINARY_DIR}/external/include") 25 | link_directories("${CMAKE_BINARY_DIR}/external/lib") 26 | 27 | # Check dependencies 28 | 29 | ## OpenSSL 30 | find_package (OpenSSL REQUIRED) 31 | 32 | # Add modules 33 | list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules) 34 | 35 | ## Configure options 36 | option ( 37 | USE_GTEST 38 | "Build with GoogleTest for testing.") 39 | 40 | option ( 41 | USE_GCOV 42 | "Build with GCov for coverage reporting.") 43 | 44 | option ( 45 | USE_MCL 46 | "Build a local version of MCL for pairing based crypto." 47 | ON) 48 | 49 | ## Google Test 50 | if (USE_GTEST) 51 | # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -fprofile-arcs -ftest-coverage") 52 | # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_TEST_COMPILE_FLAGS}" ) 53 | include (gtest) 54 | endif (USE_GTEST) 55 | 56 | ## GCOV 57 | if (USE_GCOV) 58 | include (gcovr) 59 | endif (USE_GCOV) 60 | 61 | ## MCL 62 | if (USE_MCL) 63 | include (mcl) 64 | # link_directories("${CMAKE_BINARY_DIR}/external/kk/lib") 65 | else () 66 | find_package (MCL REQUIRED) 67 | include_directories(${MCL_INCLUDE_DIRS}) 68 | endif (USE_MCL) 69 | 70 | ## @TODO Is this needed/used? 71 | ## CTest 72 | include (CTest) 73 | 74 | # Subdirectories 75 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/logger) 76 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/msg) 77 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/sys) 78 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/shim) 79 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/crypto) 80 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/math) 81 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/misc) 82 | add_subdirectory (${CMAKE_SOURCE_DIR}/src/groupsig) 83 | add_subdirectory (${PROJECT_SOURCE_DIR}/src/tools) 84 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/samples/src/main/java/com/ibm/jgroupsig/executable/Unblind.java: -------------------------------------------------------------------------------- 1 | package com.ibm.jgroupsig.executable; 2 | 3 | import com.ibm.jgroupsig.*; 4 | 5 | import java.io.UnsupportedEncodingException; 6 | import java.lang.IllegalArgumentException; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | import java.io.FileWriter; 10 | import java.io.FileReader; 11 | import java.io.BufferedReader; 12 | 13 | public class Unblind { 14 | 15 | /* Credit to https://stackoverflow.com/a/13006907 */ 16 | private static String byteArrayToHex(byte[] a) { 17 | StringBuilder sb = new StringBuilder(a.length * 2); 18 | for(byte b: a) 19 | sb.append(String.format("%02x", b)); 20 | return sb.toString(); 21 | } 22 | 23 | /* Credit to https://stackoverflow.com/a/4716623 */ 24 | private static String file2String(String fileName) { 25 | try(BufferedReader br = new BufferedReader(new FileReader(fileName))) { 26 | StringBuilder sb = new StringBuilder(); 27 | String line = br.readLine(); 28 | 29 | while (line != null) { 30 | sb.append(line); 31 | sb.append(System.lineSeparator()); 32 | line = br.readLine(); 33 | } 34 | String everything = sb.toString(); 35 | return everything; 36 | } catch(FileNotFoundException fnfe) { 37 | System.out.println(fnfe); 38 | } catch(IOException ioe) { 39 | System.out.println(ioe); 40 | } 41 | return null; 42 | } 43 | 44 | public static void main(String args[]) { 45 | 46 | if (args.length != 2) { 47 | System.out.println("Usage: java Unblind "); 48 | return; 49 | } 50 | 51 | try { 52 | 53 | GL19 user = new GL19(); 54 | 55 | /* Import bldkey from the first string in the command line args */ 56 | String bldstr = file2String(args[0]); 57 | BldKey bldkey = new BldKey(GS.GL19_CODE, bldstr); 58 | 59 | /* Import converted signature from the second string in the command 60 | line args */ 61 | String sigstr = file2String(args[1]); 62 | BlindSignature cSig = new BlindSignature(GS.GL19_CODE, sigstr); 63 | 64 | /* Unblind */ 65 | Identity id = user.unblind(cSig, bldkey); 66 | 67 | /* Print result */ 68 | System.out.println("ID: "+id.toStr()+ 69 | "\nMessage hash: 0x"+byteArrayToHex(id.getMsg()).substring(0,32)+"..."); 70 | 71 | } catch (UnsupportedEncodingException uee) { 72 | System.out.println(uee); 73 | } catch (IllegalArgumentException iae) { 74 | System.out.println(iae); 75 | } catch (Exception e) { 76 | System.out.println(e); 77 | } 78 | 79 | return; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/groupsig/bbs04/join_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "bbs04.h" 25 | #include "groupsig/bbs04/grp_key.h" 26 | #include "groupsig/bbs04/mem_key.h" 27 | #include "bigz.h" 28 | #include "sys/mem.h" 29 | 30 | /** 31 | * @fn int bbs04_join_mem(groupsig_key_t *memkey, groupsig_key_t *grpkey) 32 | * @brief Member side join procedure. 33 | * 34 | * The original proposal does not include a "join" procedure. Instead, it is the 35 | * private-key issuer generates and distributes the member keys, and requires a 36 | * predefined group size. We adopt this approach to allow dynamic addition of group 37 | * members. 38 | * 39 | * @param[in,out] memkey Will be set to the produced member key. 40 | * @param[in] grpkey The group key. 41 | * 42 | * @return IOK or IERROR. 43 | */ 44 | int bbs04_join_mem(message_t **mout, groupsig_key_t *memkey, 45 | int seq, message_t *min, groupsig_key_t *grpkey) { 46 | 47 | groupsig_key_t *_memkey; 48 | int rc; 49 | 50 | if(!memkey || memkey->scheme != GROUPSIG_BBS04_CODE || 51 | !min || seq != 1) { 52 | LOG_EINVAL(&logger, __FILE__, "bbs04_join_mem", __LINE__, LOGERROR); 53 | return IERROR; 54 | } 55 | 56 | _memkey = NULL; 57 | rc = IOK; 58 | 59 | /* This is mainly an utility function to keep uniformity across schemes: 60 | Just import the memkey from the received message and copy it into the 61 | provided memkey*/ 62 | if(!(_memkey = bbs04_mem_key_import(min->bytes, min->length))) 63 | GOTOENDRC(IERROR, bbs04_join_mem); 64 | 65 | if(bbs04_mem_key_copy(memkey, _memkey) == IERROR) 66 | GOTOENDRC(IERROR, bbs04_join_mem); 67 | 68 | bbs04_join_mem_end: 69 | 70 | bbs04_mem_key_free(_memkey); _memkey = NULL; 71 | 72 | return rc; 73 | 74 | } 75 | 76 | /* join_mem.c ends here */ 77 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/signature_build.py: -------------------------------------------------------------------------------- 1 | # file "signature_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef struct { 7 | uint8_t scheme; 8 | void *sig; 9 | } groupsig_signature_t; 10 | """) 11 | 12 | ffibuilder.cdef(""" 13 | typedef groupsig_signature_t* (*groupsig_signature_init_f)(void); 14 | """) 15 | 16 | ffibuilder.cdef(""" 17 | typedef int (*groupsig_signature_free_f)(groupsig_signature_t *signature); 18 | """) 19 | 20 | ffibuilder.cdef(""" 21 | typedef int (*groupsig_signature_copy_f)( 22 | groupsig_signature_t *dst, 23 | groupsig_signature_t *src); 24 | """) 25 | 26 | ffibuilder.cdef(""" 27 | typedef int (*groupsig_signature_get_size_f)( 28 | groupsig_signature_t *sig); 29 | """) 30 | 31 | ffibuilder.cdef(""" 32 | typedef int (*groupsig_signature_export_f)( 33 | unsigned char **bytes, 34 | uint32_t *size, 35 | groupsig_signature_t *signature); 36 | """) 37 | 38 | ffibuilder.cdef(""" 39 | typedef groupsig_signature_t* (*groupsig_signature_import_f)( 40 | unsigned char *source, 41 | uint32_t size); 42 | """) 43 | 44 | ffibuilder.cdef(""" 45 | typedef char* (*groupsig_signature_to_string_f)( 46 | groupsig_signature_t *signature); 47 | """) 48 | 49 | ffibuilder.cdef(""" 50 | typedef struct { 51 | uint8_t scheme; 52 | groupsig_signature_init_f init; 53 | groupsig_signature_free_f free; 54 | groupsig_signature_copy_f copy; 55 | groupsig_signature_get_size_f get_size; 56 | groupsig_signature_export_f gexport; 57 | groupsig_signature_import_f gimport; 58 | groupsig_signature_to_string_f to_string; 59 | } groupsig_signature_handle_t; 60 | """) 61 | 62 | ffibuilder.cdef(""" 63 | const groupsig_signature_handle_t* groupsig_signature_handle_from_code(uint8_t code); 64 | """) 65 | 66 | ffibuilder.cdef(""" 67 | groupsig_signature_t* groupsig_signature_init(uint8_t code) 68 | ;""") 69 | 70 | ffibuilder.cdef(""" 71 | int groupsig_signature_free(groupsig_signature_t *sig); 72 | """) 73 | 74 | ffibuilder.cdef(""" 75 | int groupsig_signature_copy( 76 | groupsig_signature_t *dst, 77 | groupsig_signature_t *src); 78 | """) 79 | 80 | ffibuilder.cdef(""" 81 | int groupsig_signature_get_size( 82 | groupsig_signature_t *sig); 83 | """) 84 | 85 | ffibuilder.cdef(""" 86 | int groupsig_signature_export( 87 | unsigned char **bytes, 88 | uint32_t *size, 89 | groupsig_signature_t *sig); 90 | """) 91 | 92 | ffibuilder.cdef(""" 93 | groupsig_signature_t* groupsig_signature_import( 94 | uint8_t code, 95 | unsigned char *source, 96 | uint32_t size); 97 | """) 98 | 99 | ffibuilder.cdef(""" 100 | char* groupsig_signature_to_string(groupsig_signature_t *sig); 101 | """) 102 | -------------------------------------------------------------------------------- /src/groupsig/kty04/trace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "include/crl.h" 26 | #include "bigz.h" 27 | #include "kty04.h" 28 | #include "groupsig/kty04/signature.h" 29 | #include "groupsig/kty04/grp_key.h" 30 | #include "groupsig/kty04/crl.h" 31 | 32 | int kty04_trace(uint8_t *ok, groupsig_signature_t *sig, groupsig_key_t *grpkey, crl_t *crl, groupsig_key_t *mgrkey, gml_t *gml) { 33 | 34 | kty04_signature_t *kty04_sig; 35 | kty04_grp_key_t *gkey; 36 | bigz_t a3t, aux; 37 | uint64_t i; 38 | uint8_t revoked; 39 | 40 | if(!ok || !sig || sig->scheme != GROUPSIG_KTY04_CODE || 41 | !grpkey || grpkey->scheme != GROUPSIG_KTY04_CODE || 42 | !crl) { 43 | LOG_EINVAL(&logger, __FILE__, "kty04_trace", __LINE__, LOGERROR); 44 | return IERROR; 45 | } 46 | 47 | gkey = (kty04_grp_key_t *) grpkey->key; 48 | kty04_sig = (kty04_signature_t *) sig->sig; 49 | 50 | /* To test whether the signature has been issued with the member with tracing 51 | trapdoor "trapdoor", we have to check if sig->A[3]^trapdoor == sig->A[11]. */ 52 | if(!(a3t = bigz_init())) return IERROR; 53 | 54 | i = 0; revoked = 0; 55 | while(i < crl->n) { 56 | 57 | /* Get the next trapdoor to test */ 58 | aux = ((kty04_crl_entry_t *) crl_get(crl, i))->trapdoor; 59 | 60 | if(bigz_powm(a3t, kty04_sig->A[3], aux, gkey->n)) { 61 | bigz_free(a3t); 62 | return IERROR; 63 | } 64 | 65 | errno = 0; 66 | if(!bigz_cmp(a3t, kty04_sig->A[11])) { 67 | if(errno) { 68 | bigz_free(a3t); 69 | return IERROR; 70 | } 71 | revoked = 1; 72 | break; 73 | } else { 74 | if(errno) { 75 | bigz_free(a3t); 76 | return IERROR; 77 | } 78 | } 79 | 80 | i++; 81 | 82 | } 83 | 84 | *ok = revoked; 85 | 86 | bigz_free(a3t); 87 | 88 | return IOK; 89 | 90 | } 91 | 92 | /* trace.c ends here */ 93 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/key_build.py: -------------------------------------------------------------------------------- 1 | # file "key_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | # Define data types 6 | ffibuilder.cdef(""" 7 | typedef enum { 8 | GROUPSIG_KEY_GRPKEY, 9 | GROUPSIG_KEY_MGRKEY, 10 | GROUPSIG_KEY_MEMKEY, 11 | GROUPSIG_KEY_BLDKEY, 12 | } groupsig_key_types; 13 | """) 14 | 15 | ffibuilder.cdef(""" 16 | typedef struct { 17 | uint8_t scheme; 18 | void *key; 19 | } groupsig_key_t; 20 | """) 21 | 22 | ffibuilder.cdef(""" 23 | typedef groupsig_key_t* (*groupsig_key_init_f)(void); 24 | """) 25 | 26 | ffibuilder.cdef(""" 27 | typedef int (*groupsig_key_free_f)(groupsig_key_t *key); 28 | """) 29 | 30 | ffibuilder.cdef(""" 31 | typedef int (*groupsig_key_copy_f)( 32 | groupsig_key_t *dst, 33 | groupsig_key_t *src); 34 | """) 35 | 36 | ffibuilder.cdef(""" 37 | typedef int (*groupsig_key_get_size_f)( 38 | groupsig_key_t *key); 39 | """) 40 | 41 | ffibuilder.cdef(""" 42 | typedef groupsig_key_t* (*groupsig_key_prv_get_f)(groupsig_key_t *key); 43 | """) 44 | 45 | ffibuilder.cdef(""" 46 | typedef groupsig_key_t* (*groupsig_key_pub_get_f)(groupsig_key_t *key); 47 | """) 48 | 49 | ffibuilder.cdef(""" 50 | typedef int (*groupsig_key_prv_set_f)( 51 | void *dst, 52 | void *src); 53 | """) 54 | 55 | ffibuilder.cdef(""" 56 | typedef int (*groupsig_key_pub_set_f)( 57 | void *dst, 58 | void *src); 59 | """) 60 | 61 | ffibuilder.cdef(""" 62 | typedef int (*groupsig_key_export_f)( 63 | unsigned char **bytes, 64 | uint32_t *size, 65 | groupsig_key_t *key); 66 | """) 67 | ffibuilder.cdef(""" 68 | typedef int (*groupsig_key_pub_export_f)( 69 | unsigned char **bytes, 70 | uint32_t *size, 71 | groupsig_key_t *key); 72 | """) 73 | 74 | ffibuilder.cdef(""" 75 | typedef int (*groupsig_key_prv_export_f)( 76 | unsigned char **bytes, 77 | uint32_t *size, 78 | groupsig_key_t *key); 79 | """) 80 | 81 | ffibuilder.cdef(""" 82 | typedef groupsig_key_t* (*groupsig_key_import_f)( 83 | unsigned char *source, 84 | uint32_t size); 85 | """) 86 | 87 | ffibuilder.cdef(""" 88 | typedef groupsig_key_t* (*groupsig_key_prv_import_f)( 89 | unsigned char *source, 90 | uint32_t size); 91 | """) 92 | 93 | ffibuilder.cdef(""" 94 | typedef groupsig_key_t* (*groupsig_key_pub_import_f)( 95 | unsigned char *source, 96 | uint32_t size); 97 | """) 98 | 99 | ffibuilder.cdef(""" 100 | typedef char* (*groupsig_key_to_string_f)(groupsig_key_t *key); 101 | """) 102 | 103 | ffibuilder.cdef(""" 104 | typedef char* (*groupsig_key_prv_to_string_f)(groupsig_key_t *key); 105 | """) 106 | 107 | ffibuilder.cdef(""" 108 | typedef char* (*groupsig_key_pub_to_string_f)(groupsig_key_t *key); 109 | """) 110 | -------------------------------------------------------------------------------- /src/groupsig/cpy06/reveal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "sysenv.h" 25 | #include "bigz.h" 26 | #include "cpy06.h" 27 | #include "groupsig/cpy06/mem_key.h" 28 | #include "groupsig/cpy06/gml.h" 29 | #include "groupsig/cpy06/crl.h" 30 | #include "groupsig/cpy06/trapdoor.h" 31 | 32 | int cpy06_reveal(trapdoor_t *trap, crl_t *crl, gml_t *gml, uint64_t index) { 33 | 34 | cpy06_crl_entry_t *crl_entry; 35 | cpy06_gml_entry_t *gml_entry; 36 | trapdoor_t* crl_trap; 37 | 38 | 39 | if(!trap || trap->scheme != GROUPSIG_CPY06_CODE || 40 | !gml || gml->scheme != GROUPSIG_CPY06_CODE || 41 | (crl && crl->scheme != GROUPSIG_CPY06_CODE)) { 42 | LOG_EINVAL(&logger, __FILE__, "cpy06_reveal", __LINE__, LOGERROR); 43 | return IERROR; 44 | } 45 | 46 | if(!(crl_trap = trapdoor_init(trap->scheme))){ 47 | LOG_EINVAL(&logger, __FILE__, "cpy06_reveal", __LINE__, LOGERROR); 48 | return IERROR; 49 | } 50 | 51 | /* The tracing trapdoor for the i-th member is the C value computed during join */ 52 | if(!(gml_entry = ((cpy06_gml_entry_t *) gml_get(gml, index)))) { 53 | return IERROR; 54 | } 55 | 56 | if(cpy06_trapdoor_copy(trap, (trapdoor_t *) gml_entry->trapdoor) == IERROR) { 57 | return IERROR; 58 | } 59 | 60 | /* If we have received a CRL, update it with the "revoked" member */ 61 | if(crl) { 62 | 63 | if(!(crl_entry = cpy06_crl_entry_init())) { 64 | return IERROR; 65 | } 66 | 67 | if(cpy06_identity_copy(crl_entry->id, gml_entry->id) == IERROR) { 68 | cpy06_crl_entry_free(crl_entry); 69 | return IERROR; 70 | } 71 | 72 | cpy06_trapdoor_copy(crl_trap, trap); 73 | crl_entry->trapdoor = crl_trap; 74 | 75 | if(cpy06_crl_insert(crl, crl_entry) == IERROR) { 76 | cpy06_crl_entry_free(crl_entry); 77 | return IERROR; 78 | } 79 | 80 | } 81 | 82 | return IOK; 83 | 84 | } 85 | 86 | /* reveal.c ends here */ 87 | -------------------------------------------------------------------------------- /src/shim/rsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef _RSA_H 21 | #define _RSA_H 22 | 23 | #include 24 | #include "types.h" 25 | #include "sysenv.h" 26 | 27 | /** 28 | * @struct rsa_keypair_t 29 | * @brief An RSA cryptosystem structure. 30 | */ 31 | typedef struct { 32 | mpz_t p; /**< The p prime */ 33 | mpz_t q; /**< The q prime */ 34 | mpz_t n; /**< The modulus */ 35 | mpz_t phin; /**< phi(n) */ 36 | mpz_t e; /**< Public exponent */ 37 | mpz_t d; /**< Private exponent */ 38 | } rsa_keypair_t; 39 | 40 | /** 41 | * @fn int rsa_keypair_init(rsa_keypair_t *rsa) 42 | * @brief Initializes a rsa keypair structure. 43 | * 44 | * @param[in,out] rsa A pointer to the structure 45 | * 46 | * @return IOK or IERROR 47 | */ 48 | int rsa_keypair_init(rsa_keypair_t *rsa); 49 | 50 | /** 51 | * @fn int rsa_keypair_free(rsa_keypair_t *rsa) 52 | * @brief Frees the memory allocated forthe received rsa keypair structure. 53 | * 54 | * @param[in,out] rsa A pointer to the structure to free. 55 | * 56 | * @return IOK or IERROR 57 | */ 58 | int rsa_keypair_free(rsa_keypair_t *rsa); 59 | 60 | /** 61 | * @fn int rsa_keypair_fprintf(FILE *fd, rsa_keypair_t *rsa) 62 | * @brief Prints the keypair into the specified ouptut. 63 | * 64 | * @param[in] fd The file descriptor to print to. 65 | * @param[in] rsa The key to print. 66 | * 67 | * @return IOK or IERROR 68 | */ 69 | int rsa_keypair_fprintf(FILE *fd, rsa_keypair_t *rsa); 70 | 71 | /** 72 | * @fn int rsa_keygen(uint64_t primesize, rsa_keys_t *rsa) 73 | * @brief Generates a private-public RSA keypair. 74 | * 75 | * The generated keypair is special in the sense that the generated primes p and q 76 | * are of the shape t=2Rt'+1, where t' is also prime and R is some composite of 77 | * known factorization. 78 | * 79 | * @param[in] primesize The desired (approximate) size, in bits, of the RSA primes. 80 | * @param rsa The structure to store the keypair in. 81 | * 82 | * @return IOK or IERROR 83 | */ 84 | int rsa_keygen(uint64_t primesize, rsa_keypair_t *rsa); 85 | 86 | #endif /* _RSA_H */ 87 | 88 | /* rsa.h ends here */ 89 | -------------------------------------------------------------------------------- /src/groupsig/klap20/open_verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "types.h" 25 | #include "sysenv.h" 26 | #include "klap20.h" 27 | #include "sys/mem.h" 28 | #include "crypto/spk.h" 29 | #include "groupsig/klap20/proof.h" 30 | #include "groupsig/klap20/grp_key.h" 31 | #include "groupsig/klap20/signature.h" 32 | #include "groupsig/klap20/gml.h" 33 | 34 | int klap20_open_verify(uint8_t *ok, 35 | groupsig_proof_t *proof, 36 | groupsig_signature_t *sig, 37 | groupsig_key_t *grpkey) { 38 | 39 | pbcext_element_GT_t *e2; 40 | klap20_signature_t *klap20_sig; 41 | klap20_proof_t *klap20_proof; 42 | klap20_grp_key_t *klap20_grpkey; 43 | byte_t *bsig; 44 | int rc; 45 | uint32_t slen; 46 | uint8_t _ok; 47 | 48 | if (!proof || proof->scheme != GROUPSIG_KLAP20_CODE || 49 | !sig || sig->scheme != GROUPSIG_KLAP20_CODE || 50 | !grpkey || grpkey->scheme != GROUPSIG_KLAP20_CODE) { 51 | LOG_EINVAL(&logger, __FILE__, "klap20_open_verify", __LINE__, LOGERROR); 52 | return IERROR; 53 | } 54 | 55 | klap20_sig = sig->sig; 56 | klap20_grpkey = grpkey->key; 57 | klap20_proof = proof->proof; 58 | rc = IOK; 59 | e2 = NULL; 60 | 61 | if (!(e2 = pbcext_element_GT_init())) GOTOENDRC(IERROR, klap20_open_verify); 62 | if (pbcext_pairing(e2, klap20_sig->ww, klap20_grpkey->gg) == IERROR) 63 | GOTOENDRC(IERROR, klap20_open_verify); 64 | 65 | /* Export the signature as an array of bytes */ 66 | bsig = NULL; 67 | if (klap20_signature_export(&bsig, &slen, sig) == IERROR) 68 | GOTOENDRC(IERROR, klap20_open_verify); 69 | 70 | if (klap20_spk1_verify(&_ok, 71 | klap20_proof, 72 | klap20_sig->uu, 73 | klap20_grpkey->g, 74 | e2, 75 | klap20_proof->tau, 76 | bsig, 77 | slen) == IERROR) 78 | GOTOENDRC(IERROR, klap20_open_verify); 79 | 80 | *ok = _ok; 81 | 82 | klap20_open_verify_end: 83 | 84 | if (e2) { pbcext_element_GT_free(e2); e2 = NULL; } 85 | if (bsig) { mem_free(bsig); bsig = NULL; } 86 | 87 | return rc; 88 | 89 | } 90 | 91 | /* open.c ends here */ 92 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/crl_build.py: -------------------------------------------------------------------------------- 1 | # file "crl_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef enum { 7 | CRL_FILE, 8 | CRL_DATABASE, 9 | } crl_format_t; 10 | """) 11 | 12 | ffibuilder.cdef(""" 13 | typedef struct { 14 | uint8_t scheme; 15 | void **entries; 16 | uint64_t n; 17 | } crl_t; 18 | """) 19 | 20 | ffibuilder.cdef(""" 21 | typedef crl_t* (*crl_init_f)(void); 22 | """) 23 | 24 | ffibuilder.cdef(""" 25 | typedef int (*crl_free_f)(crl_t *crl); 26 | """) 27 | 28 | ffibuilder.cdef(""" 29 | typedef int (*crl_insert_f)(crl_t *crl, void *entry); 30 | """) 31 | 32 | ffibuilder.cdef(""" 33 | typedef int (*crl_remove_f)(crl_t *crl, uint64_t index); 34 | """) 35 | 36 | ffibuilder.cdef(""" 37 | typedef void* (*crl_get_f)(crl_t *crl, uint64_t index); 38 | """) 39 | 40 | ffibuilder.cdef(""" 41 | typedef crl_t* (*crl_import_f)(crl_format_t format, void *src); 42 | """) 43 | 44 | ffibuilder.cdef(""" 45 | typedef int (*crl_export_f)(crl_t *crl, void *dst, crl_format_t format); 46 | """) 47 | 48 | ffibuilder.cdef(""" 49 | typedef int (*crl_entry_exists_f)(crl_t *crl, void *entry); 50 | """) 51 | 52 | ffibuilder.cdef(""" 53 | typedef int (*crl_trapdoor_exists_f)(crl_t *crl, trapdoor_t *trap); 54 | """) 55 | 56 | ffibuilder.cdef(""" 57 | typedef struct { 58 | uint8_t scheme; 59 | crl_init_f crl_init; 60 | crl_free_f crl_free; 61 | crl_insert_f crl_insert; 62 | crl_remove_f crl_remove; 63 | crl_get_f crl_get; 64 | crl_import_f crl_import; 65 | crl_export_f crl_export; 66 | crl_entry_exists_f crl_entry_exists; 67 | crl_trapdoor_exists_f crl_trapdoor_exists; 68 | } crl_handle_t; 69 | """) 70 | 71 | ffibuilder.cdef(""" 72 | typedef int (*crl_cmp_entries_f)(void *entry1, void *entry2); 73 | """) 74 | 75 | ffibuilder.cdef(""" 76 | const crl_handle_t* crl_handle_from_code(uint8_t code); 77 | """) 78 | 79 | ffibuilder.cdef(""" 80 | crl_t* crl_init(uint8_t scheme); 81 | """) 82 | 83 | ffibuilder.cdef(""" 84 | int crl_free(crl_t *crl); 85 | """) 86 | 87 | ffibuilder.cdef(""" 88 | int crl_insert(crl_t *crl, void *entry); 89 | """) 90 | 91 | ffibuilder.cdef(""" 92 | int crl_remove(crl_t *crl, uint64_t index); 93 | """) 94 | 95 | ffibuilder.cdef(""" 96 | void* crl_get(crl_t *crl, uint64_t index); 97 | """) 98 | 99 | ffibuilder.cdef(""" 100 | crl_t* crl_import(uint8_t code, crl_format_t format, void *source); 101 | """) 102 | 103 | ffibuilder.cdef(""" 104 | int crl_export(crl_t *crl, void *dst, crl_format_t format); 105 | """) 106 | 107 | #ffibuilder.cdef(""" 108 | #void* crl_entry_init(crl_t *crl); 109 | #""") 110 | 111 | ffibuilder.cdef(""" 112 | int crl_compare_entries(int *eq, void *entry1, void *entry2, crl_cmp_entries_f cmp); 113 | """) 114 | 115 | ffibuilder.cdef(""" 116 | int crl_entry_exists(crl_t *crl, void *entry); 117 | """) 118 | 119 | ffibuilder.cdef(""" 120 | int crl_trapdoor_exists(crl_t *crl, trapdoor_t *trap); 121 | """) 122 | -------------------------------------------------------------------------------- /src/groupsig/kty04/reveal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "sysenv.h" 25 | #include "bigz.h" 26 | #include "kty04.h" 27 | #include "groupsig/kty04/mem_key.h" 28 | #include "groupsig/kty04/gml.h" 29 | #include "groupsig/kty04/crl.h" 30 | #include "groupsig/kty04/trapdoor.h" 31 | 32 | int kty04_reveal(trapdoor_t *trap, crl_t *crl, gml_t *gml, uint64_t index) { 33 | 34 | kty04_crl_entry_t *crl_entry; 35 | kty04_gml_entry_t *gml_entry; 36 | bigz_t trapdoor; 37 | 38 | if(!trap || trap->scheme != GROUPSIG_KTY04_CODE || 39 | !gml || gml->scheme != GROUPSIG_KTY04_CODE || 40 | (crl && crl->scheme != GROUPSIG_KTY04_CODE)) { 41 | LOG_EINVAL(&logger, __FILE__, "kty04_reveal", __LINE__, LOGERROR); 42 | return IERROR; 43 | } 44 | 45 | trapdoor = *(bigz_t *) trap->trap; 46 | 47 | /* The tracing trapdoor for the i-th member is the x field of its member key */ 48 | if(!(gml_entry = ((kty04_gml_entry_t *) gml_get(gml, index)))) { 49 | LOG_EINVAL(&logger, __FILE__, "kty04_reveal", __LINE__, LOGERROR); 50 | return IERROR; 51 | } 52 | 53 | if(bigz_set(trapdoor, *(kty04_trapdoor_t *) gml_entry->trapdoor->trap) == IERROR) { 54 | LOG_EINVAL(&logger, __FILE__, "kty04_reveal", __LINE__, LOGERROR); 55 | return IERROR; 56 | } 57 | 58 | /* If we have received a CRL, update it with the "revoked" member */ 59 | if(crl) { 60 | 61 | if(!(crl_entry = kty04_crl_entry_init())) { 62 | LOG_EINVAL(&logger, __FILE__, "kty04_reveal", __LINE__, LOGERROR); 63 | return IERROR; 64 | } 65 | 66 | bigz_set(crl_entry->trapdoor, trapdoor); 67 | 68 | if(kty04_identity_copy(crl_entry->id, gml_entry->id) == IERROR) { 69 | LOG_EINVAL(&logger, __FILE__, "kty04_reveal", __LINE__, LOGERROR); 70 | kty04_crl_entry_free(crl_entry); 71 | return IERROR; 72 | } 73 | 74 | if(kty04_crl_insert(crl, crl_entry) == IERROR) { 75 | LOG_EINVAL(&logger, __FILE__, "kty04_reveal", __LINE__, LOGERROR); 76 | kty04_crl_entry_free(crl_entry); 77 | return IERROR; 78 | } 79 | 80 | } 81 | 82 | return IOK; 83 | } 84 | 85 | /* reveal.c ends here */ 86 | -------------------------------------------------------------------------------- /src/groupsig/kty04/join_mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "kty04.h" 25 | #include "groupsig/kty04/sphere.h" 26 | #include "groupsig/kty04/grp_key.h" 27 | #include "groupsig/kty04/mem_key.h" 28 | #include "bigz.h" 29 | #include "sys/mem.h" 30 | 31 | /** 32 | * @todo The Join procedure includes a protocol for non-adaptive drawing of 33 | * random powers such that the group member gets x, and the group manager gets 34 | * b^x (mod n). For now, and for testing purposes, we just let the user choose 35 | * a random x and send it to the manager, but we must implement it as soon as 36 | * everything is working correctly. 37 | */ 38 | 39 | /* static int _join_mem_draw_random_pow(kty04_grp_key_t *grpkey, kty04_mem_key_t *memkey) { */ 40 | /* return IERROR; */ 41 | /* } */ 42 | 43 | /* @TODO This function still follows the old variable structure for join and 44 | I am just changing the interface to remove compiler complaints. But this 45 | breaks the functionality! Fix! */ 46 | // groupsig_key_t *memkey, groupsig_key_t *grpkey) { 47 | int kty04_join_mem(void **mout, groupsig_key_t *memkey, 48 | int seq, void *min, groupsig_key_t *grpkey) { 49 | 50 | kty04_grp_key_t *gkey; 51 | kty04_mem_key_t *mkey; 52 | 53 | if(!mout || !memkey || memkey->scheme != GROUPSIG_KTY04_CODE || 54 | !grpkey || grpkey->scheme != GROUPSIG_KTY04_CODE) { 55 | LOG_EINVAL(&logger, __FILE__, "kty04_join_mem", __LINE__, LOGERROR); 56 | return IERROR; 57 | } 58 | 59 | gkey = (kty04_grp_key_t *) grpkey->key; 60 | mkey = (kty04_mem_key_t *) memkey->key; 61 | 62 | /* Get a random power in the inner sphere of Lambda */ 63 | #ifdef DEBUG 64 | log_printf(&logger, LOGDEBUG, 65 | "@todo Warning: This should be done with a protocol for non-adaptive" 66 | " drawing of random powers!\n"); 67 | #endif 68 | 69 | if(sphere_get_random(gkey->inner_lambda, mkey->xx) == IERROR) { 70 | return IERROR; 71 | } 72 | 73 | /* Set C = b^xx */ 74 | if(bigz_powm(mkey->C, gkey->b, mkey->xx, gkey->n) == IERROR) { 75 | return IERROR; 76 | } 77 | 78 | return IOK; 79 | 80 | } 81 | 82 | /* join.c ends here */ 83 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/mem_key_build.py: -------------------------------------------------------------------------------- 1 | # file "mem_key_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef groupsig_key_init_f mem_key_init_f; 7 | """) 8 | 9 | ffibuilder.cdef(""" 10 | typedef groupsig_key_free_f mem_key_free_f; 11 | """) 12 | 13 | ffibuilder.cdef(""" 14 | typedef groupsig_key_copy_f mem_key_copy_f; 15 | """) 16 | 17 | ffibuilder.cdef(""" 18 | typedef groupsig_key_get_size_f mem_key_get_size_f; 19 | """) 20 | 21 | ffibuilder.cdef(""" 22 | typedef groupsig_key_prv_get_f mem_key_prv_get_f; 23 | """) 24 | ffibuilder.cdef(""" 25 | typedef groupsig_key_pub_get_f mem_key_pub_get_f; 26 | """) 27 | ffibuilder.cdef(""" 28 | typedef groupsig_key_prv_set_f mem_key_prv_set_f; 29 | """) 30 | ffibuilder.cdef(""" 31 | typedef groupsig_key_pub_set_f mem_key_pub_set_f; 32 | """) 33 | 34 | ffibuilder.cdef(""" 35 | typedef groupsig_key_export_f mem_key_export_f; 36 | """) 37 | ffibuilder.cdef(""" 38 | typedef groupsig_key_pub_export_f mem_key_pub_export_f; 39 | """) 40 | ffibuilder.cdef(""" 41 | typedef groupsig_key_prv_export_f mem_key_prv_export_f; 42 | """) 43 | 44 | ffibuilder.cdef(""" 45 | typedef groupsig_key_import_f mem_key_import_f; 46 | """) 47 | 48 | ffibuilder.cdef(""" 49 | typedef groupsig_key_prv_import_f mem_key_prv_import_f; 50 | """) 51 | 52 | ffibuilder.cdef(""" 53 | typedef groupsig_key_pub_import_f mem_key_pub_import_f; 54 | """) 55 | 56 | ffibuilder.cdef(""" 57 | typedef groupsig_key_to_string_f mem_key_to_string_f; 58 | """) 59 | ffibuilder.cdef(""" 60 | typedef groupsig_key_prv_to_string_f mem_key_prv_to_string_f; 61 | """) 62 | 63 | ffibuilder.cdef(""" 64 | typedef groupsig_key_pub_to_string_f mem_key_pub_to_string_f; 65 | """) 66 | 67 | ffibuilder.cdef(""" 68 | typedef struct { 69 | uint8_t code; 70 | mem_key_init_f init; 71 | mem_key_free_f free; 72 | mem_key_copy_f copy; 73 | mem_key_get_size_f get_size; 74 | mem_key_export_f gexport; 75 | mem_key_import_f gimport; 76 | mem_key_to_string_f to_string; 77 | } mem_key_handle_t; 78 | """) 79 | 80 | ffibuilder.cdef(""" 81 | const mem_key_handle_t* groupsig_mem_key_handle_from_code(uint8_t code); 82 | """) 83 | 84 | ffibuilder.cdef(""" 85 | groupsig_key_t* groupsig_mem_key_init(uint8_t code); 86 | """) 87 | 88 | ffibuilder.cdef(""" 89 | int groupsig_mem_key_free(groupsig_key_t *key); 90 | """) 91 | 92 | ffibuilder.cdef(""" 93 | int groupsig_mem_key_copy(groupsig_key_t *dst, groupsig_key_t *src); 94 | """) 95 | 96 | ffibuilder.cdef(""" 97 | int groupsig_mem_key_get_size( 98 | groupsig_key_t *key); 99 | """) 100 | 101 | ffibuilder.cdef(""" 102 | int groupsig_mem_key_export( 103 | unsigned char **bytes, 104 | uint32_t *size, 105 | groupsig_key_t *key); 106 | """) 107 | 108 | ffibuilder.cdef(""" 109 | groupsig_key_t* groupsig_mem_key_import( 110 | uint8_t code, 111 | unsigned char *source, 112 | uint32_t size); 113 | """) 114 | 115 | ffibuilder.cdef(""" 116 | char* groupsig_mem_key_to_string(groupsig_key_t *key); 117 | """) 118 | -------------------------------------------------------------------------------- /src/groupsig/cpy06/trace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "include/crl.h" 26 | #include "bigz.h" 27 | #include "cpy06.h" 28 | #include "groupsig/cpy06/signature.h" 29 | #include "groupsig/cpy06/grp_key.h" 30 | #include "groupsig/cpy06/mgr_key.h" 31 | #include "groupsig/cpy06/crl.h" 32 | #include "groupsig/cpy06/gml.h" 33 | #include "groupsig/cpy06/trapdoor.h" 34 | #include "groupsig/cpy06/identity.h" 35 | 36 | int cpy06_trace(uint8_t *ok, groupsig_signature_t *sig, groupsig_key_t *grpkey, crl_t *crl, groupsig_key_t *mgrkey, gml_t *gml) { 37 | 38 | cpy06_signature_t *cpy06_sig; 39 | cpy06_grp_key_t *gkey; 40 | //cpy06_mgr_key_t *mkey; 41 | cpy06_sysenv_t *cpy06_sysenv; 42 | trapdoor_t *trapi; 43 | element_t e; 44 | uint64_t i; 45 | uint8_t revoked; 46 | 47 | if(!ok || !sig || sig->scheme != GROUPSIG_CPY06_CODE || 48 | !grpkey || grpkey->scheme != GROUPSIG_CPY06_CODE || 49 | //!mgrkey || mgrkey->scheme != GROUPSIG_CPY06_CODE || 50 | //!gml || 51 | !crl) { 52 | LOG_EINVAL(&logger, __FILE__, "cpy06_trace", __LINE__, LOGERROR); 53 | return IERROR; 54 | } 55 | 56 | gkey = (cpy06_grp_key_t *) grpkey->key; 57 | //mkey = (cpy06_mgr_key_t *) mgrkey->key; 58 | cpy06_sig = (cpy06_signature_t *) sig->sig; 59 | cpy06_sysenv = sysenv->data; 60 | 61 | element_init_GT(e, cpy06_sysenv->pairing); 62 | 63 | i = 0; revoked = 0; 64 | while(i < crl->n) { 65 | 66 | // @bug Memory leak here... but uncommenting crashes the program 67 | /* if(!(trapi = cpy06_trapdoor_init())) { */ 68 | /* element_clear(e); */ 69 | /* return IERROR; */ 70 | /* } */ 71 | 72 | /* Get the next trapdoor to test */ 73 | trapi = ((cpy06_crl_entry_t *) crl_get(crl, i))->trapdoor; 74 | 75 | /* Compute e(trapi->C, sig->T4) */ 76 | element_pairing(e, ((cpy06_trapdoor_t *) trapi->trap)->trace, cpy06_sig->T4); 77 | if(!element_cmp(e, cpy06_sig->T5)) { 78 | revoked = 1; 79 | } 80 | 81 | /* trapdoor_free(trapi); trapi = NULL; */ 82 | 83 | i++; 84 | 85 | } 86 | 87 | *ok = revoked; 88 | 89 | return IOK; 90 | 91 | 92 | } 93 | 94 | /* trace.c ends here */ 95 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/mgr_key_build.py: -------------------------------------------------------------------------------- 1 | # file mgr_key_build 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | 5 | ffibuilder.cdef(""" 6 | typedef groupsig_key_init_f mgr_key_init_f; 7 | """) 8 | 9 | ffibuilder.cdef(""" 10 | typedef groupsig_key_free_f mgr_key_free_f; 11 | """) 12 | 13 | ffibuilder.cdef(""" 14 | typedef groupsig_key_copy_f mgr_key_copy_f; 15 | """) 16 | 17 | ffibuilder.cdef(""" 18 | typedef groupsig_key_get_size_f mgr_key_get_size_f; 19 | """) 20 | 21 | ffibuilder.cdef(""" 22 | typedef groupsig_key_prv_get_f mgr_key_prv_get_f; 23 | """) 24 | 25 | ffibuilder.cdef(""" 26 | typedef groupsig_key_pub_get_f mgr_key_pub_get; 27 | """) 28 | 29 | ffibuilder.cdef(""" 30 | typedef groupsig_key_prv_set_f mgr_key_prv_set_f; 31 | """) 32 | 33 | ffibuilder.cdef(""" 34 | typedef groupsig_key_pub_set_f mgr_key_pub_set_f; 35 | """) 36 | 37 | ffibuilder.cdef(""" 38 | typedef groupsig_key_export_f mgr_key_export_f; 39 | """) 40 | 41 | ffibuilder.cdef(""" 42 | typedef groupsig_key_pub_export_f mgr_key_pub_export_f; 43 | """) 44 | 45 | ffibuilder.cdef(""" 46 | typedef groupsig_key_prv_export_f mgr_key_prv_export_f; 47 | """) 48 | 49 | ffibuilder.cdef(""" 50 | typedef groupsig_key_import_f mgr_key_import_f; 51 | """) 52 | 53 | ffibuilder.cdef(""" 54 | typedef groupsig_key_prv_import_f mgr_key_prv_import_f; 55 | """) 56 | 57 | ffibuilder.cdef(""" 58 | typedef groupsig_key_pub_import_f mgr_key_pub_import_f; 59 | """) 60 | 61 | ffibuilder.cdef(""" 62 | typedef groupsig_key_to_string_f mgr_key_to_string_f; 63 | """) 64 | 65 | ffibuilder.cdef(""" 66 | typedef groupsig_key_prv_to_string_f mgr_key_prv_to_string_f; 67 | """) 68 | 69 | ffibuilder.cdef(""" 70 | typedef groupsig_key_pub_to_string_f mgr_key_pub_to_string_f; 71 | """) 72 | 73 | ffibuilder.cdef(""" 74 | typedef struct { 75 | uint8_t code; 76 | mgr_key_init_f init; 77 | mgr_key_free_f free; 78 | mgr_key_copy_f copy; 79 | mgr_key_export_f gexport; 80 | mgr_key_import_f gimport; 81 | mgr_key_to_string_f to_string; 82 | mgr_key_get_size_f get_size; 83 | } mgr_key_handle_t; 84 | """) 85 | 86 | ffibuilder.cdef(""" 87 | const mgr_key_handle_t* groupsig_mgr_key_handle_from_code(uint8_t code); 88 | """) 89 | 90 | ffibuilder.cdef(""" 91 | groupsig_key_t* groupsig_mgr_key_init(uint8_t code); 92 | """) 93 | 94 | ffibuilder.cdef(""" 95 | int groupsig_mgr_key_free(groupsig_key_t *key); 96 | """) 97 | 98 | ffibuilder.cdef(""" 99 | int groupsig_mgr_key_copy(groupsig_key_t *dst, groupsig_key_t *src); 100 | """) 101 | 102 | ffibuilder.cdef(""" 103 | int groupsig_mgr_key_get_size(groupsig_key_t *key); 104 | """) 105 | 106 | ffibuilder.cdef(""" 107 | int groupsig_mgr_key_export( 108 | unsigned char **bytes, 109 | uint32_t *size, 110 | groupsig_key_t *key); 111 | """) 112 | 113 | ffibuilder.cdef(""" 114 | groupsig_key_t* groupsig_mgr_key_import( 115 | uint8_t code, 116 | unsigned char *source, 117 | uint32_t size); 118 | """) 119 | 120 | ffibuilder.cdef(""" 121 | char* groupsig_mgr_key_to_string(groupsig_key_t *key); 122 | """) 123 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/bldkey.py: -------------------------------------------------------------------------------- 1 | from _groupsig import lib, ffi 2 | from . import constants 3 | import base64 4 | 5 | def bldkey_random(code, grpkey): 6 | """ 7 | Generates a random blinding keypair for schemes of the specified code. 8 | 9 | Parameters: 10 | code: The code specifying the type of scheme the key belongs to. 11 | grpkey: The group key of the scheme. Should contain all parameters 12 | needed to generate a random blinding key. 13 | Returns: 14 | A native data structure containing the blinding keypair. On error, 15 | an exception is thrown. 16 | """ 17 | bldkey = lib.groupsig_bld_key_random(code, grpkey) 18 | if bldkey == ffi.NULL: 19 | raise Exception('Error importing blinding key.') 20 | return bldkey 21 | 22 | def bldkey_export(bldkey): 23 | """ 24 | Exports the given blinding keypair to a Base64 string. 25 | 26 | Parameters: 27 | bldkey: The blinding key to export. 28 | Returns: 29 | The produced Base64 string. On error, an Exception is thrown. 30 | """ 31 | 32 | bkey = ffi.new("byte_t **") 33 | bkey[0] = ffi.NULL 34 | size = ffi.new("uint32_t *") 35 | if lib.groupsig_bld_key_export(bkey, size, bldkey) == constants.IERROR: 36 | raise Exception('Error exporting blinding key.') 37 | b64key = base64.b64encode(ffi.buffer(bkey[0],size[0])) 38 | b64key = b64key.decode('utf-8').replace('\n', '') 39 | # lib.free(bkey[0]) 40 | return b64key 41 | 42 | def bldkey_export_pub(bldkey): 43 | """ 44 | Exports the public part of given blinding keypair to a Base64 string. 45 | 46 | Parameters: 47 | bldkey: The blinding key to export. 48 | Returns: 49 | The produced Base64 string. On error, an Exception is thrown. 50 | """ 51 | 52 | bkey = ffi.new("byte_t **") 53 | bkey[0] = ffi.NULL 54 | size = ffi.new("uint32_t *") 55 | if lib.groupsig_bld_key_export_pub(bkey, size, bldkey) == constants.IERROR: 56 | raise Exception('Error exporting blinding public key.') 57 | b64key = base64.b64encode(ffi.buffer(bkey[0],size[0])) 58 | b64key = b64key.decode('utf-8').replace('\n', '') 59 | # lib.free(bkey[0]) 60 | return b64key 61 | 62 | def bldkey_import(code, b64key): 63 | """ 64 | Imports the given blinding keypair from a Base64 string. Works both for full 65 | keypairs and for public keys. 66 | 67 | Parameters: 68 | bldkey: The blinding key to export. 69 | Returns: 70 | The imported keypair. On error, an Exception is thrown. 71 | """ 72 | 73 | b = base64.b64decode(b64key) 74 | bldkey = lib.groupsig_bld_key_import(code, b, len(b)) 75 | if bldkey == ffi.NULL: 76 | raise Exception('Error importing blinding key.') 77 | return bldkey 78 | 79 | #def bldkey_to_string(key): 80 | # 81 | # _str = ffi.new("char *") 82 | # _str = lib.groupsig_bld_key_to_string(key) 83 | # if _str == ffi.NULL: 84 | # raise Exception('Error converting blinding key to string.') 85 | # return ffi.string(_str).decode('utf8') 86 | -------------------------------------------------------------------------------- /src/groupsig/trapdoor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include "logger.h" 21 | #include "types.h" 22 | #include "trapdoor_handles.h" 23 | 24 | const trapdoor_handle_t* trapdoor_handle_from_code(uint8_t code) { 25 | 26 | int i; 27 | 28 | for(i=0; ischeme) 30 | return TRAPDOOR_HANDLES[i]; 31 | } 32 | 33 | return NULL; 34 | 35 | } 36 | 37 | trapdoor_t* trapdoor_init(uint8_t code) { 38 | 39 | const trapdoor_handle_t *tdh; 40 | 41 | if(!(tdh = trapdoor_handle_from_code(code))) { 42 | LOG_EINVAL(&logger, __FILE__, "trapdoor_init", __LINE__, LOGERROR); 43 | return NULL; 44 | } 45 | 46 | return tdh->init(); 47 | 48 | } 49 | 50 | int trapdoor_free(trapdoor_t *trap) { 51 | 52 | const trapdoor_handle_t *tdh; 53 | 54 | if(!(tdh = trapdoor_handle_from_code(trap->scheme))) { 55 | LOG_EINVAL(&logger, __FILE__, "trapdoor_free", __LINE__, LOGERROR); 56 | return IERROR; 57 | } 58 | 59 | return tdh->free(trap); 60 | 61 | } 62 | 63 | int trapdoor_copy(trapdoor_t *dst, trapdoor_t *src) { 64 | 65 | const trapdoor_handle_t *tdh; 66 | 67 | if(dst->scheme != src->scheme) { 68 | LOG_EINVAL(&logger, __FILE__, "trapdoor_copy", __LINE__, LOGERROR); 69 | return IERROR; 70 | } 71 | 72 | if(!(tdh = trapdoor_handle_from_code(dst->scheme))) { 73 | LOG_EINVAL(&logger, __FILE__, "trapdoor_copy", __LINE__, LOGERROR); 74 | return IERROR; 75 | } 76 | 77 | return tdh->copy(dst, src); 78 | 79 | } 80 | 81 | char* trapdoor_to_string(trapdoor_t *trap) { 82 | 83 | const trapdoor_handle_t *tdh; 84 | 85 | if(!(tdh = trapdoor_handle_from_code(trap->scheme))) { 86 | LOG_EINVAL(&logger, __FILE__, "trapdoor_to_string", __LINE__, LOGERROR); 87 | return NULL; 88 | } 89 | 90 | return tdh->to_string(trap); 91 | 92 | } 93 | 94 | trapdoor_t* trapdoor_from_string(uint8_t code, char *strap) { 95 | 96 | const trapdoor_handle_t *tdh; 97 | 98 | if(!(tdh = trapdoor_handle_from_code(code))) { 99 | LOG_EINVAL(&logger, __FILE__, "trapdoor_to_string", __LINE__, LOGERROR); 100 | return NULL; 101 | } 102 | 103 | return tdh->from_string(strap); 104 | 105 | } 106 | 107 | /* trapdoor.c ends here */ 108 | -------------------------------------------------------------------------------- /src/wrappers/python/pygroupsig/grp_key_build.py: -------------------------------------------------------------------------------- 1 | # file "grp_key_build.py" 2 | 3 | from pygroupsig.common_build import ffibuilder 4 | import pygroupsig.key_build 5 | 6 | # Define data types 7 | 8 | ffibuilder.cdef(""" 9 | typedef groupsig_key_init_f grp_key_init_f; 10 | """) 11 | 12 | ffibuilder.cdef(""" 13 | typedef groupsig_key_free_f grp_key_free_f; 14 | """) 15 | 16 | ffibuilder.cdef(""" 17 | typedef groupsig_key_copy_f grp_key_copy_f; 18 | """) 19 | 20 | ffibuilder.cdef(""" 21 | typedef groupsig_key_get_size_f grp_key_get_size_f; 22 | """) 23 | 24 | ffibuilder.cdef(""" 25 | typedef groupsig_key_prv_get_f grp_key_prv_get_f; 26 | """) 27 | 28 | ffibuilder.cdef(""" 29 | typedef groupsig_key_pub_get_f grp_key_pub_get_f; 30 | """) 31 | 32 | ffibuilder.cdef(""" 33 | typedef groupsig_key_prv_set_f grp_key_prv_set_f; 34 | """) 35 | 36 | ffibuilder.cdef(""" 37 | typedef groupsig_key_pub_set_f grp_key_pub_set_f; 38 | """) 39 | 40 | ffibuilder.cdef(""" 41 | typedef groupsig_key_export_f grp_key_export_f; 42 | """) 43 | 44 | ffibuilder.cdef(""" 45 | typedef groupsig_key_pub_export_f grp_key_pub_export_f; 46 | """) 47 | 48 | ffibuilder.cdef(""" 49 | typedef groupsig_key_prv_export_f grp_key_prv_export_f; 50 | """) 51 | 52 | ffibuilder.cdef(""" 53 | typedef groupsig_key_import_f grp_key_import_f; 54 | """) 55 | 56 | ffibuilder.cdef(""" 57 | typedef groupsig_key_prv_import_f grp_key_prv_import_f; 58 | """) 59 | 60 | ffibuilder.cdef(""" 61 | typedef groupsig_key_pub_import_f grp_key_pub_import_f; 62 | """) 63 | 64 | ffibuilder.cdef(""" 65 | typedef groupsig_key_to_string_f grp_key_to_string_f; 66 | """) 67 | 68 | ffibuilder.cdef(""" 69 | typedef groupsig_key_prv_to_string_f grp_key_prv_to_string_f; 70 | """) 71 | 72 | ffibuilder.cdef(""" 73 | typedef groupsig_key_pub_to_string_f grp_key_pub_to_string_f; 74 | """) 75 | 76 | ffibuilder.cdef(""" 77 | typedef struct { 78 | uint8_t code; 79 | grp_key_init_f init; 80 | grp_key_free_f free; 81 | grp_key_copy_f copy; 82 | grp_key_export_f gexport; 83 | grp_key_import_f gimport; 84 | grp_key_to_string_f to_string; 85 | grp_key_get_size_f get_size; 86 | } grp_key_handle_t; 87 | """) 88 | 89 | ffibuilder.cdef(""" 90 | const grp_key_handle_t* groupsig_grp_key_handle_from_code(uint8_t code); 91 | """) 92 | 93 | ffibuilder.cdef(""" 94 | groupsig_key_t* groupsig_grp_key_init(uint8_t code); 95 | """) 96 | 97 | ffibuilder.cdef(""" 98 | int groupsig_grp_key_free(groupsig_key_t *key); 99 | """) 100 | 101 | ffibuilder.cdef(""" 102 | int groupsig_grp_key_copy( 103 | groupsig_key_t *dst, 104 | groupsig_key_t *src); 105 | """) 106 | 107 | ffibuilder.cdef(""" 108 | int groupsig_grp_key_get_size( 109 | groupsig_key_t *key); 110 | """) 111 | 112 | ffibuilder.cdef(""" 113 | int groupsig_grp_key_export( 114 | unsigned char **dst, 115 | uint32_t *size, 116 | groupsig_key_t *key); 117 | """) 118 | 119 | ffibuilder.cdef(""" 120 | groupsig_key_t* groupsig_grp_key_import( 121 | uint8_t code, 122 | unsigned char *src, 123 | uint32_t size); 124 | """) 125 | 126 | ffibuilder.cdef(""" 127 | char* groupsig_grp_key_to_string(groupsig_key_t *key); 128 | """) 129 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/java/src/main/java/com/ibm/jgroupsig/Gml.java: -------------------------------------------------------------------------------- 1 | package com.ibm.jgroupsig; 2 | 3 | import java.util.Base64; 4 | 5 | /** 6 | * Class for Group Membership Lists (GMLs) in the groupsig package. 7 | * 8 | * Offers several interfaces to create and operate with GMLs. 9 | * It is part of the groupsig package. 10 | */ 11 | public class Gml { 12 | 13 | /** 14 | * The GS scheme code. 15 | */ 16 | private int code = -1; 17 | 18 | /** 19 | * The internal JNI pointer. 20 | */ 21 | private long ptr = 0; 22 | 23 | public Gml() {} 24 | 25 | /** 26 | * Creates a new instance of GML (Group Membership List) for the given 27 | * scheme. 28 | * 29 | * @param code The code identifying the GS scheme. 30 | * @exception IllegalArgumentException 31 | * @exception Exception 32 | */ 33 | public Gml(int code) 34 | throws IllegalArgumentException, 35 | Exception 36 | { 37 | this.code = code; 38 | this.ptr = groupsig_gmlInit(code); 39 | return; 40 | } 41 | 42 | /** 43 | * Creates a new instance of gml for the given scheme, importing 44 | * the gml data from the given string. 45 | * 46 | * @param code The code identifying the GS scheme. 47 | * @param str A string containing a previously exported gml. 48 | * @exception IllegalArgumentException 49 | * @exception Exception 50 | */ 51 | public Gml(int code, String str) 52 | throws IllegalArgumentException, 53 | Exception 54 | { 55 | byte[] b = Base64.getMimeDecoder().decode(str); 56 | this.ptr = groupsig_gmlImport(code, b, b.length); 57 | this.code = code; 58 | } 59 | 60 | /** 61 | * Exports this instance of a GML (currently, to a base64 string). 62 | * 63 | * @return A base64-encoded string. 64 | * @exception IllegalArgumentException 65 | * @exception Exception 66 | */ 67 | public String export() 68 | throws IllegalArgumentException, 69 | Exception 70 | { 71 | byte[] b = groupsig_gmlExport(this.ptr); 72 | return Base64.getMimeEncoder().encodeToString(b); 73 | } 74 | 75 | /** 76 | * Frees the memory allocated for the current gml instance. 77 | */ 78 | protected void finalize() { 79 | groupsig_gmlFree(this.ptr); 80 | } 81 | 82 | /** 83 | * Returns the pointer of the internal JNI object for this gml. 84 | * 85 | * @return A pointer to the internal JNI object for this gml. 86 | */ 87 | public long getObject() { return ptr; } 88 | 89 | /** 90 | * Returns the code for this GML's scheme. 91 | * 92 | * @return The GML scheme. 93 | */ 94 | public int getCode() { return this.code; } 95 | 96 | static { System.loadLibrary("jnigroupsig"); } 97 | 98 | private static native long groupsig_gmlInit(int code); 99 | private static native int groupsig_gmlFree(long ptr); 100 | private static native byte[] groupsig_gmlExport(long ptr); 101 | private static native long groupsig_gmlImport(int code, byte[] b, int size); 102 | } 103 | -------------------------------------------------------------------------------- /src/groupsig/ps16/open_verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "types.h" 25 | #include "sysenv.h" 26 | #include "ps16.h" 27 | #include "sys/mem.h" 28 | #include "crypto/spk.h" 29 | #include "groupsig/ps16/proof.h" 30 | #include "groupsig/ps16/grp_key.h" 31 | #include "groupsig/ps16/signature.h" 32 | #include "groupsig/ps16/gml.h" 33 | 34 | int ps16_open_verify(uint8_t *ok, 35 | groupsig_proof_t *proof, 36 | groupsig_signature_t *sig, 37 | groupsig_key_t *grpkey) { 38 | 39 | pbcext_element_GT_t *e1, *e2; 40 | ps16_signature_t *ps16_sig; 41 | ps16_proof_t *ps16_proof; 42 | ps16_grp_key_t *ps16_grpkey; 43 | byte_t *bsig; 44 | int rc; 45 | uint32_t slen; 46 | uint8_t _ok; 47 | 48 | if (!proof || proof->scheme != GROUPSIG_PS16_CODE || 49 | !sig || sig->scheme != GROUPSIG_PS16_CODE || 50 | !grpkey || grpkey->scheme != GROUPSIG_PS16_CODE) { 51 | LOG_EINVAL(&logger, __FILE__, "ps16_open_verify", __LINE__, LOGERROR); 52 | return IERROR; 53 | } 54 | 55 | ps16_sig = sig->sig; 56 | ps16_grpkey = grpkey->key; 57 | ps16_proof = proof->proof; 58 | rc = IOK; 59 | e1 = e2 = NULL; 60 | 61 | if (!(e1 = pbcext_element_GT_init())) GOTOENDRC(IERROR, ps16_open_verify); 62 | if (pbcext_pairing(e1, ps16_sig->sigma2, ps16_grpkey->gg) == IERROR) 63 | GOTOENDRC(IERROR, ps16_open_verify); 64 | if (!(e2 = pbcext_element_GT_init())) GOTOENDRC(IERROR, ps16_open_verify); 65 | if (pbcext_pairing(e2, ps16_sig->sigma1, ps16_grpkey->X) == IERROR) 66 | GOTOENDRC(IERROR, ps16_open_verify); 67 | if (pbcext_element_GT_div(e1, e1, e2) == IERROR) GOTOENDRC(IERROR, ps16_open_verify); 68 | 69 | /* Export the signature as an array of bytes */ 70 | bsig = NULL; 71 | if (ps16_signature_export(&bsig, &slen, sig) == IERROR) 72 | GOTOENDRC(IERROR, ps16_open_verify); 73 | 74 | if (spk_pairing_homomorphism_G2_verify(&_ok, 75 | ps16_sig->sigma1, 76 | e1, 77 | ps16_proof, 78 | bsig, 79 | slen) == IERROR) 80 | GOTOENDRC(IERROR, ps16_open_verify); 81 | 82 | *ok = _ok; 83 | 84 | ps16_open_verify_end: 85 | 86 | if (e1) { pbcext_element_GT_free(e1); e1 = NULL; } 87 | if (e2) { pbcext_element_GT_free(e2); e2 = NULL; } 88 | if (bsig) { mem_free(bsig); bsig = NULL; } 89 | 90 | return rc; 91 | 92 | } 93 | 94 | /* open.c ends here */ 95 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/java/src/main/java/com/ibm/jgroupsig/Proof.java: -------------------------------------------------------------------------------- 1 | package com.ibm.jgroupsig; 2 | 3 | import java.util.Base64; 4 | 5 | /** 6 | * Class for Proofs in the groupsig package. 7 | * 8 | * Offers several interfaces to create and operate with group proofs. 9 | * It is part of the groupsig package. 10 | */ 11 | public class Proof { 12 | 13 | /** 14 | * The GS scheme code. 15 | */ 16 | private int code = -1; 17 | 18 | /** 19 | * The internal JNI pointer. 20 | */ 21 | private long ptr = 0; 22 | 23 | public Proof() {} 24 | 25 | /** 26 | * Creates a new instance of proof for the given scheme. 27 | * 28 | * @param code The code identifying the GS scheme. 29 | * @exception IllegalArgumentException 30 | * @exception Exception 31 | */ 32 | public Proof(int code) 33 | throws IllegalArgumentException, 34 | Exception 35 | { 36 | this.code = code; 37 | this.ptr = groupsig_proofInit(code); 38 | return; 39 | } 40 | 41 | /** 42 | * Creates a new instance of proof for the given scheme, importing 43 | * the proof data from the given string. 44 | * 45 | * @param code The code identifying the GS scheme. 46 | * @param str A string containing a previously exported proof. 47 | * @exception IllegalArgumentException 48 | * @exception Exception 49 | */ 50 | public Proof(int code, String str) 51 | throws IllegalArgumentException, 52 | Exception 53 | { 54 | byte[] b = Base64.getMimeDecoder().decode(str); 55 | this.ptr = groupsig_proofImport(code, b, b.length); 56 | this.code = code; 57 | } 58 | 59 | /** 60 | * Frees the memory allocated for the current proof instance. 61 | */ 62 | protected void finalize() { 63 | groupsig_proofFree(this.ptr); 64 | } 65 | 66 | /** 67 | * Exports this instance of a proof (currently, to a base64 string). 68 | * 69 | * @return A base64-encoded string. 70 | * @exception IllegalArgumentException 71 | * @exception Exception 72 | */ 73 | public String export() 74 | throws IllegalArgumentException, 75 | Exception 76 | { 77 | byte[] b = groupsig_proofExport(this.ptr); 78 | return Base64.getMimeEncoder().encodeToString(b); 79 | } 80 | 81 | /** 82 | * Returns the pointer of the internal JNI object for this proof. 83 | * 84 | * @return A pointer to the internal JNI object for this proof. 85 | */ 86 | public long getObject() { return ptr; } 87 | 88 | /** 89 | * Returns the code for this proof's scheme. 90 | * 91 | * @return The proof scheme. 92 | */ 93 | public int getCode() { return this.code; } 94 | 95 | static { System.loadLibrary("jnigroupsig"); } 96 | 97 | private static native long groupsig_proofInit(int code); 98 | private static native int groupsig_proofFree(long ptr); 99 | private static native int groupsig_proofGetCode(long ptr); 100 | private static native byte[] groupsig_proofExport(long ptr); 101 | private static native long groupsig_proofImport(int code, byte[] b, int size); 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/wrappers/java/jgroupsig/java/src/main/java/com/ibm/jgroupsig/GrpKey.java: -------------------------------------------------------------------------------- 1 | package com.ibm.jgroupsig; 2 | 3 | import java.util.Base64; 4 | 5 | /** 6 | * Class for Group Keys in the groupsig package. 7 | * 8 | * Offers several interfaces to create and operate with group keys. 9 | * It is part of the groupsig package. 10 | */ 11 | public class GrpKey { 12 | 13 | /** 14 | * The GS scheme code. 15 | */ 16 | private int code = -1; 17 | 18 | /** 19 | * The internal JNI pointer. 20 | */ 21 | private long ptr = 0; 22 | 23 | public GrpKey() {} 24 | 25 | /** 26 | * Creates a new instance of group key for the given scheme. 27 | * 28 | * @param code The code identifying the GS scheme. 29 | * @exception IllegalArgumentException 30 | * @exception Exception 31 | */ 32 | public GrpKey(int code) 33 | throws IllegalArgumentException, 34 | Exception 35 | { 36 | this.code = code; 37 | this.ptr = groupsig_grpKeyInit(code); 38 | return; 39 | } 40 | 41 | /** 42 | * Creates a new instance of group key for the given scheme, importing 43 | * the key material from the given string. 44 | * 45 | * @param code The code identifying the GS scheme. 46 | * @param str A string containing a previously exported group key. 47 | * @exception IllegalArgumentException 48 | * @exception Exception 49 | */ 50 | public GrpKey(int code, String str) 51 | throws IllegalArgumentException, 52 | Exception 53 | { 54 | byte[] b = Base64.getMimeDecoder().decode(str); 55 | this.ptr = groupsig_grpKeyImport(code, b, b.length); 56 | this.code = code; 57 | } 58 | 59 | /** 60 | * Frees the memory allocated for the current blinding key instance. 61 | */ 62 | protected void finalize() { 63 | groupsig_grpKeyFree(this.ptr); 64 | } 65 | 66 | /** 67 | * Exports this instance of a group key (currently, to a base64 string). 68 | * 69 | * @return A base64-encoded string. 70 | * @exception IllegalArgumentException 71 | * @exception Exception 72 | */ 73 | public String export() 74 | throws IllegalArgumentException, 75 | Exception 76 | { 77 | byte[] b = groupsig_grpKeyExport(this.ptr); 78 | return Base64.getMimeEncoder().encodeToString(b); 79 | } 80 | 81 | /** 82 | * Returns the pointer of the internal JNI object for this key. 83 | * 84 | * @return A pointer to the internal JNI object for this key. 85 | */ 86 | public long getObject() { return ptr; } 87 | 88 | /** 89 | * Returns the code for this key's scheme. 90 | * 91 | * @return The key scheme. 92 | */ 93 | public int getCode() { return this.code; } 94 | 95 | static { System.loadLibrary("jnigroupsig"); } 96 | 97 | private static native long groupsig_grpKeyInit(int code); 98 | private static native int groupsig_grpKeyFree(long ptr); 99 | private static native int groupsig_grpKeyGetCode(long ptr); 100 | private static native byte[] groupsig_grpKeyExport(long ptr); 101 | private static native long groupsig_grpKeyImport(int code, byte[] b, int size); 102 | 103 | } 104 | --------------------------------------------------------------------------------