break backword compatibility of 2nd argument of mclBn_init

dev
MITSUNARI Shigeo 6 years ago
parent 8f53a5dd00
commit 6ff80eb6fd
  1. 2
      ffi/go/mcl/mcl.go
  2. 17
      include/mcl/bn.h
  3. 8
      include/mcl/she.h
  4. 1
      readme.md
  5. 4
      src/bn_c_impl.hpp
  6. 4
      src/she_c_impl.hpp
  7. 8
      test/bn_c_test.hpp

@ -32,7 +32,7 @@ const IoSerializeHexStr = C.MCLBN_IO_SERIALIZE_HEX_STR
// call this function before calling all the other operations // call this function before calling all the other operations
// this function is not thread safe // this function is not thread safe
func Init(curve int) error { func Init(curve int) error {
err := C.mclBn_init(C.int(curve), C.MCLBN_FP_UNIT_SIZE) err := C.mclBn_init(C.int(curve), C.MCLBN_COMPILED_TIME_VAR)
if err != 0 { if err != 0 {
return fmt.Errorf("ERR mclBn_init curve=%d", curve) return fmt.Errorf("ERR mclBn_init curve=%d", curve)
} }

@ -6,9 +6,16 @@
@license modified new BSD license @license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause http://opensource.org/licenses/BSD-3-Clause
*/ */
/*
the order of an elliptic curve over Fp is Fr
*/
#ifndef MCLBN_FP_UNIT_SIZE #ifndef MCLBN_FP_UNIT_SIZE
#error "define MCLBN_FP_UNIT_SIZE 4(, 6 or 8)" #error "define MCLBN_FP_UNIT_SIZE 4(, 6 or 8)"
#endif #endif
#ifndef MCLBN_FR_UNIT_SIZE
#define MCLBN_FR_UNIT_SIZE MCLBN_FP_UNIT_SIZE
#endif
#define MCLBN_COMPILED_TIME_VAR ((MCLBN_FR_UNIT_SIZE) * 10 + (MCLBN_FP_UNIT_SIZE))
#include <stdint.h> // for uint64_t, uint8_t #include <stdint.h> // for uint64_t, uint8_t
#include <stdlib.h> // for size_t #include <stdlib.h> // for size_t
@ -65,7 +72,7 @@ typedef struct mclBnGT mclBnGT;
#else #else
typedef struct { typedef struct {
uint64_t d[MCLBN_FP_UNIT_SIZE]; uint64_t d[MCLBN_FR_UNIT_SIZE];
} mclBnFr; } mclBnFr;
typedef struct { typedef struct {
@ -98,15 +105,17 @@ enum {
/* /*
init library init library
@param curve [in] type of bn curve @param curve [in] type of bn curve
@param maxUnitSize [in] MCLBN_FP_UNIT_SIZE @param compiledTimeVar [in] specify MCLBN_COMPILED_TIME_VAR,
return 0 if success else -1 which macro is used to make sure that the values
are the same when the library is built and used
@return 0 if success
curve = BN254/BN_SNARK1 is allowed if maxUnitSize = 4 curve = BN254/BN_SNARK1 is allowed if maxUnitSize = 4
curve = BN381_1/BN381_2/BLS12_381 are allowed if maxUnitSize = 6 curve = BN381_1/BN381_2/BLS12_381 are allowed if maxUnitSize = 6
This parameter is used to detect a library compiled with different MCLBN_FP_UNIT_SIZE for safety. This parameter is used to detect a library compiled with different MCLBN_FP_UNIT_SIZE for safety.
@note not threadsafe @note not threadsafe
@note BN_init is used in libeay32 @note BN_init is used in libeay32
*/ */
MCLBN_DLL_API int mclBn_init(int curve, int maxUnitSize); MCLBN_DLL_API int mclBn_init(int curve, int compiledTimeVar);
/* /*

@ -78,12 +78,14 @@ typedef struct {
initialize this library initialize this library
call this once before using the other functions call this once before using the other functions
@param curve [in] enum value defined in mcl/bn.h @param curve [in] enum value defined in mcl/bn.h
@param maxUnitSize [in] MCLBN_FP_UNIT_SIZE (fixed) @param compiledTimeVar [in] specify MCLBN_COMPILED_TIME_VAR,
return 0 if success which macro is used to make sure that the values
are the same when the library is built and used
@return 0 if success
@note sheInit() is thread safe and serialized if it is called simultaneously @note sheInit() is thread safe and serialized if it is called simultaneously
but don't call it while using other functions. but don't call it while using other functions.
*/ */
MCLSHE_DLL_API int sheInit(int curve, int maxUnitSize); MCLSHE_DLL_API int sheInit(int curve, int compiledTimeVar);
// return written byte size if success else 0 // return written byte size if success else 0
MCLSHE_DLL_API mclSize sheSecretKeySerialize(void *buf, mclSize maxBufSize, const sheSecretKey *sec); MCLSHE_DLL_API mclSize sheSecretKeySerialize(void *buf, mclSize maxBufSize, const sheSecretKey *sec);

@ -10,6 +10,7 @@ mcl is a library for pairing-based cryptography.
The current version supports the optimal Ate pairing over BN curves and BLS12-381 curves. The current version supports the optimal Ate pairing over BN curves and BLS12-381 curves.
# News # News
* 2nd argument of `mclBn_init` is changed from `maxUnitSize` to `compiledTimeVar`, which must be `MCLBN_COMPILED_TIME_VAR`.
* break backward compatibility of mapToGi for BLS12. A map-to-function for BN is used. * break backward compatibility of mapToGi for BLS12. A map-to-function for BN is used.
If `MCL_USE_OLD_MAPTO_FOR_BLS12` is defined, then the old function is used, but this will be removed in the future. If `MCL_USE_OLD_MAPTO_FOR_BLS12` is defined, then the old function is used, but this will be removed in the future.

@ -45,9 +45,9 @@ extern "C" MCLBN_DLL_API void mclBnFree(void *p)
} }
#endif #endif
int mclBn_init(int curve, int maxUnitSize) int mclBn_init(int curve, int compiledTimeVar)
{ {
if (maxUnitSize != MCLBN_FP_UNIT_SIZE) { if (compiledTimeVar != MCLBN_COMPILED_TIME_VAR) {
return -10; return -10;
} }
const mcl::CurveParam& cp = mcl::getCurveParam(curve); const mcl::CurveParam& cp = mcl::getCurveParam(curve);

@ -41,10 +41,10 @@ static const ZkpEq *cast(const sheZkpEq *p) { return reinterpret_cast<const ZkpE
static ZkpBinEq *cast(sheZkpBinEq *p) { return reinterpret_cast<ZkpBinEq*>(p); } static ZkpBinEq *cast(sheZkpBinEq *p) { return reinterpret_cast<ZkpBinEq*>(p); }
static const ZkpBinEq *cast(const sheZkpBinEq *p) { return reinterpret_cast<const ZkpBinEq*>(p); } static const ZkpBinEq *cast(const sheZkpBinEq *p) { return reinterpret_cast<const ZkpBinEq*>(p); }
int sheInit(int curve, int maxUnitSize) int sheInit(int curve, int compiledTimeVar)
try try
{ {
if (maxUnitSize != MCLBN_FP_UNIT_SIZE) { if (compiledTimeVar != MCLBN_COMPILED_TIME_VAR) {
return -2; return -2;
} }
mcl::CurveParam cp; mcl::CurveParam cp;

@ -26,13 +26,13 @@ CYBOZU_TEST_AUTO(init)
#if MCLBN_FP_UNIT_SIZE == 4 #if MCLBN_FP_UNIT_SIZE == 4
printf("test BN254 %d\n", MCLBN_FP_UNIT_SIZE); printf("test BN254 %d\n", MCLBN_FP_UNIT_SIZE);
ret = mclBn_init(MCL_BN254, MCLBN_FP_UNIT_SIZE); ret = mclBn_init(MCL_BN254, MCLBN_COMPILED_TIME_VAR);
#elif MCLBN_FP_UNIT_SIZE == 6 #elif MCLBN_FP_UNIT_SIZE == 6
printf("test BN381_1 %d\n", MCLBN_FP_UNIT_SIZE); printf("test BN381_1 %d\n", MCLBN_FP_UNIT_SIZE);
ret = mclBn_init(MCL_BN381_1, MCLBN_FP_UNIT_SIZE); ret = mclBn_init(MCL_BN381_1, MCLBN_COMPILED_TIME_VAR);
#elif MCLBN_FP_UNIT_SIZE == 8 #elif MCLBN_FP_UNIT_SIZE == 8
printf("test BN462 %d\n", MCLBN_FP_UNIT_SIZE); printf("test BN462 %d\n", MCLBN_FP_UNIT_SIZE);
ret = mclBn_init(MCL_BN462, MCLBN_FP_UNIT_SIZE); ret = mclBn_init(MCL_BN462, MCLBN_COMPILED_TIME_VAR);
#else #else
#error "bad MCLBN_FP_UNIT_SIZE" #error "bad MCLBN_FP_UNIT_SIZE"
#endif #endif
@ -508,7 +508,7 @@ CYBOZU_TEST_AUTO(serializeToHexStr)
CYBOZU_TEST_AUTO(badG2) CYBOZU_TEST_AUTO(badG2)
{ {
int ret; int ret;
ret = mclBn_init(MCL_BN381_1, MCLBN_FP_UNIT_SIZE); ret = mclBn_init(MCL_BN381_1, MCLBN_COMPILED_TIME_VAR);
CYBOZU_TEST_EQUAL(ret, 0); CYBOZU_TEST_EQUAL(ret, 0);
const char *s = "1 18d3d8c085a5a5e7553c3a4eb628e88b8465bf4de2612e35a0a4eb018fb0c82e9698896031e62fd7633ffd824a859474 1dc6edfcf33e29575d4791faed8e7203832217423bf7f7fbf1f6b36625b12e7132c15fbc15562ce93362a322fb83dd0d 65836963b1f7b6959030ddfa15ab38ce056097e91dedffd996c1808624fa7e2644a77be606290aa555cda8481cfb3cb 1b77b708d3d4f65aeedf54b58393463a42f0dc5856baadb5ce608036baeca398c5d9e6b169473a8838098fd72fd28b50"; const char *s = "1 18d3d8c085a5a5e7553c3a4eb628e88b8465bf4de2612e35a0a4eb018fb0c82e9698896031e62fd7633ffd824a859474 1dc6edfcf33e29575d4791faed8e7203832217423bf7f7fbf1f6b36625b12e7132c15fbc15562ce93362a322fb83dd0d 65836963b1f7b6959030ddfa15ab38ce056097e91dedffd996c1808624fa7e2644a77be606290aa555cda8481cfb3cb 1b77b708d3d4f65aeedf54b58393463a42f0dc5856baadb5ce608036baeca398c5d9e6b169473a8838098fd72fd28b50";
mclBnG2 Q; mclBnG2 Q;

Loading…
Cancel
Save