diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2019-08-31 09:35:15 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2019-08-31 09:35:15 +0800 |
commit | 802c12dffb921818f74df3bcd4c129b644683dc6 (patch) | |
tree | 2c8093b75d65408f6dc29ed45c67774d5eb30d58 | |
parent | 671dcb837bd7515126d3907ccca5c77b89e28cb1 (diff) | |
download | tangerine-bls-dev.tar.gz tangerine-bls-dev.tar.zst tangerine-bls-dev.zip |
add sample for bls12-381dev
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | include/bls/bls256.h | 12 | ||||
-rw-r--r-- | include/bls/bls384_256.h | 12 | ||||
-rw-r--r-- | sample/bls12_381_smpl.cpp | 21 | ||||
-rw-r--r-- | sample/bls_smpl.cpp | 2 |
5 files changed, 50 insertions, 5 deletions
@@ -13,7 +13,7 @@ CFLAGS += -std=c++11 SRC_SRC=bls_c256.cpp bls_c384.cpp bls_c384_256.cpp bls_c512.cpp TEST_SRC=bls256_test.cpp bls384_test.cpp bls384_256_test.cpp bls_c256_test.cpp bls_c384_test.cpp bls_c384_256_test.cpp bls_c512_test.cpp -SAMPLE_SRC=bls256_smpl.cpp bls384_smpl.cpp +SAMPLE_SRC=bls_smpl.cpp bls12_381_smpl.cpp CFLAGS+=-I$(MCL_DIR)/include ifneq ($(MCL_MAX_BIT_SIZE),) @@ -93,9 +93,9 @@ $(EXE_DIR)/%512_test.exe: $(OBJ_DIR)/%512_test.o $(BLS512_LIB) $(MCL_LIB) $(EXE_DIR)/%256_test.exe: $(OBJ_DIR)/%256_test.o $(BLS256_LIB) $(MCL_LIB) $(PRE)$(CXX) $< -o $@ $(BLS256_LIB) -L$(MCL_DIR)/lib -lmcl $(LDFLAGS) -# sample exe links libbls256.a -$(EXE_DIR)/%.exe: $(OBJ_DIR)/%.o $(BLS256_LIB) $(MCL_LIB) - $(PRE)$(CXX) $< -o $@ $(BLS256_LIB) -L$(MCL_DIR)/lib -lmcl $(LDFLAGS) +# sample exe links libbls384_256.a +$(EXE_DIR)/%.exe: $(OBJ_DIR)/%.o $(BLS384_256_LIB) $(MCL_LIB) + $(PRE)$(CXX) $< -o $@ $(BLS384_256_LIB) -L$(MCL_DIR)/lib -lmcl $(LDFLAGS) ifeq ($(OS),mac) install_name_tool bin/bls_smpl.exe -change lib/libmcl.dylib $(MCL_DIR)/lib/libmcl.dylib endif diff --git a/include/bls/bls256.h b/include/bls/bls256.h new file mode 100644 index 0000000..9549012 --- /dev/null +++ b/include/bls/bls256.h @@ -0,0 +1,12 @@ +#pragma once +/** + @file + @brief C API of 256-bit + @author MITSUNARI Shigeo(@herumi) + @license modified new BSD license + http://opensource.org/licenses/BSD-3-Clause +*/ +#define MCLBN_FP_UNIT_SIZE 4 +#define MCLBN_FR_UNIT_SIZE 4 +#include <bls/bls.h> + diff --git a/include/bls/bls384_256.h b/include/bls/bls384_256.h new file mode 100644 index 0000000..4977aae --- /dev/null +++ b/include/bls/bls384_256.h @@ -0,0 +1,12 @@ +#pragma once +/** + @file + @brief C API of 384/256-bit + @author MITSUNARI Shigeo(@herumi) + @license modified new BSD license + http://opensource.org/licenses/BSD-3-Clause +*/ +#define MCLBN_FP_UNIT_SIZE 6 +#define MCLBN_FR_UNIT_SIZE 4 +#include <bls/bls.h> + diff --git a/sample/bls12_381_smpl.cpp b/sample/bls12_381_smpl.cpp new file mode 100644 index 0000000..c324ffa --- /dev/null +++ b/sample/bls12_381_smpl.cpp @@ -0,0 +1,21 @@ +#include <bls/bls384_256.h> +#include <string.h> +#include <stdio.h> + +int main() +{ + blsSecretKey sec; + blsPublicKey pub; + blsSignature sig; + const char *msg = "abc"; + const size_t msgSize = strlen(msg); + int ret = blsInit(MCL_BLS12_381, MCLBN_COMPILED_TIME_VAR); + if (ret) { + printf("err %d\n", ret); + return 1; + } + blsSecretKeySetByCSPRNG(&sec); + blsGetPublicKey(&pub, &sec); + blsSign(&sig, &sec, msg, msgSize); + printf("verify %d\n", blsVerify(&sig, &pub, msg, msgSize)); +} diff --git a/sample/bls_smpl.cpp b/sample/bls_smpl.cpp index e812cd5..ffd48ba 100644 --- a/sample/bls_smpl.cpp +++ b/sample/bls_smpl.cpp @@ -1,4 +1,4 @@ -#define MCLBN_FP_UNIT_SIZE 4 +#include <bls/bls384_256.h> #include <bls/bls.hpp> #include <cybozu/option.hpp> #include <cybozu/itoa.hpp> |