rename MCLBN_OP_UNIT_SIZE to MCLBN_FP_UNIT_SIZE

dev
MITSUNARI Shigeo 8 years ago
parent 15e511bbb3
commit 4876e522f7
  1. 4
      Makefile
  2. 12
      ffi/go/mcl/mcl.go
  3. 30
      include/mcl/bn.h
  4. 11
      src/bn_c.cpp
  5. 2
      test/bn_c256_test.cpp
  6. 2
      test/bn_c384_test.cpp
  7. 10
      test/bn_c_test.hpp

@ -97,7 +97,7 @@ $(BN256_SLIB): $(LIB_OBJ) $(BN256_OBJ)
$(PRE)$(CXX) -o $@ $(LIB_OBJ) $(BN256_OBJ) -shared
$(BN256_OBJ): src/bn_c.cpp
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_OP_UNIT_SIZE=4"
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_FP_UNIT_SIZE=4"
$(BN384_LIB): $(LIB_OBJ) $(BN384_OBJ)
$(AR) $@ $(LIB_OBJ) $(BN384_OBJ)
@ -106,7 +106,7 @@ $(BN384_SLIB): $(LIB_OBJ) $(BN384_OBJ)
$(PRE)$(CXX) -o $@ $(LIB_OBJ) $(BN384_OBJ) -shared
$(BN384_OBJ): src/bn_c.cpp
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_OP_UNIT_SIZE=6"
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_FP_UNIT_SIZE=6"
$(ASM_OBJ): $(ASM_SRC)
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS)

@ -1,7 +1,7 @@
package mcl
/*
#cgo CFLAGS:-D"MCLBN_OP_UNIT_SIZE=6"
#cgo CFLAGS:-D"MCLBN_FP_UNIT_SIZE=6"
#cgo LDFLAGS:-lmclbn384_dy -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto
#include <mcl/bn.h>
*/
@ -22,7 +22,7 @@ const CurveFp382_2 = 2
// call this function before calling all the other operations
// this function is not thread safe
func Init(curve int) error {
err := C.mclBn_init(C.int(curve), C.MCLBN_OP_UNIT_SIZE)
err := C.mclBn_init(C.int(curve), C.MCLBN_FP_UNIT_SIZE)
if err != 0 {
return fmt.Errorf("ERR mclBn_init curve=%d", curve)
}
@ -32,7 +32,7 @@ func Init(curve int) error {
////////////////////////////////////////////////
// Fr --
type Fr struct {
v [C.MCLBN_OP_UNIT_SIZE]C.uint64_t
v C.mclBnFr
}
// getPointer --
@ -168,7 +168,7 @@ func FrDiv(out *Fr, x *Fr, y *Fr) {
////////////////////////////////////////////
// G1 --
type G1 struct {
v [C.MCLBN_OP_UNIT_SIZE * 3]C.uint64_t
v C.mclBnG1
}
// getPointer --
@ -274,7 +274,7 @@ func G1Mul(out *G1, x *G1, y *Fr) {
////////////////////////////////////////////
// G2 --
type G2 struct {
v [C.MCLBN_OP_UNIT_SIZE * 2 * 3]C.uint64_t
v C.mclBnG1
}
// getPointer --
@ -380,7 +380,7 @@ func G2Mul(out *G2, x *G2, y *Fr) {
///////////////////////////////////////////////////////
// GT --
type GT struct {
v [C.MCLBN_OP_UNIT_SIZE * 12]C.uint64_t
v C.mclBnGT
}
// getPointer --

@ -6,8 +6,8 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#ifndef MCLBN_OP_UNIT_SIZE
#error "define MCLBN_OP_UNIT_SIZE 4(or 6)"
#ifndef MCLBN_FP_UNIT_SIZE
#error "define MCLBN_FP_UNIT_SIZE 4(or 6)"
#endif
#include <stdint.h> // for uint64_t, uint8_t
@ -19,7 +19,7 @@
#else
#define MCLBN_DLL_API __declspec(dllimport)
#ifndef MCL_NO_AUTOLINK
#if MCLBN_OP_UNIT_SIZE == 4
#if MCLBN_FP_UNIT_SIZE == 4
#pragma comment(lib, "mclbn256.lib")
#else
#pragma comment(lib, "mclbn384.lib")
@ -34,31 +34,31 @@
extern "C" {
#endif
#ifdef MCLBN_DEFINE_STRUCT
#ifdef MCLBN_NOT_DEFINE_STRUCT
typedef struct mclBnFr mclBnFr;
typedef struct mclBnG1 mclBnG1;
typedef struct mclBnG2 mclBnG2;
typedef struct mclBnGT mclBnGT;
#else
typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE];
uint64_t d[MCLBN_FP_UNIT_SIZE];
} mclBnFr;
typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE * 3];
uint64_t d[MCLBN_FP_UNIT_SIZE * 3];
} mclBnG1;
typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE * 2 * 3];
uint64_t d[MCLBN_FP_UNIT_SIZE * 2 * 3];
} mclBnG2;
typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE * 12];
uint64_t d[MCLBN_FP_UNIT_SIZE * 12];
} mclBnGT;
#else
typedef struct mclBnFr mclBnFr;
typedef struct mclBnG1 mclBnG1;
typedef struct mclBnG2 mclBnG2;
typedef struct mclBnGT mclBnGT;
#endif
/*

@ -1,5 +1,4 @@
#define MCLBN_DLL_EXPORT
#define MCLBN_DEFINE_STRUCT
#include <mcl/bn.h>
#if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11
#include <random>
@ -9,7 +8,7 @@ static std::random_device g_rg;
static cybozu::RandomGenerator g_rg;
#endif
#if MCLBN_OP_UNIT_SIZE == 4
#if MCLBN_FP_UNIT_SIZE == 4
#include <mcl/bn256.hpp>
using namespace mcl::bn256;
#else
@ -107,8 +106,8 @@ int mclBn_setErrFile(const char *name)
int mclBn_init(int curve, int maxUnitSize)
try
{
if (maxUnitSize != MCLBN_OP_UNIT_SIZE) {
if (g_fp) fprintf(g_fp, "mclBn_init:maxUnitSize is mismatch %d %d\n", maxUnitSize, MCLBN_OP_UNIT_SIZE);
if (maxUnitSize != MCLBN_FP_UNIT_SIZE) {
if (g_fp) fprintf(g_fp, "mclBn_init:maxUnitSize is mismatch %d %d\n", maxUnitSize, MCLBN_FP_UNIT_SIZE);
return -1;
}
mcl::bn::CurveParam cp;
@ -116,7 +115,7 @@ int mclBn_init(int curve, int maxUnitSize)
case mclBn_curveFp254BNb:
cp = mcl::bn::CurveFp254BNb;
break;
#if MCLBN_OP_UNIT_SIZE == 6
#if MCLBN_FP_UNIT_SIZE == 6
case mclBn_curveFp382_1:
cp = mcl::bn::CurveFp382_1;
break;
@ -128,7 +127,7 @@ int mclBn_init(int curve, int maxUnitSize)
if (g_fp) fprintf(g_fp, "MCLBN_init:not supported curve %d\n", curve);
return -1;
}
#if MCLBN_OP_UNIT_SIZE == 4
#if MCLBN_FP_UNIT_SIZE == 4
bn256init(cp);
#else
bn384init(cp);

@ -1,6 +1,6 @@
#include <mcl/bn256.hpp>
using namespace mcl::bn256;
#define MCLBN_DEFINE_STRUCT
#define MCLBN_OP_UNIT_SIZE 4
#define MCLBN_FP_UNIT_SIZE 4
#include "bn_c_test.hpp"

@ -1,6 +1,6 @@
#include <mcl/bn384.hpp>
using namespace mcl::bn384;
#define MCLBN_DEFINE_STRUCT
#define MCLBN_OP_UNIT_SIZE 6
#define MCLBN_FP_UNIT_SIZE 6
#include "bn_c_test.hpp"

@ -27,12 +27,12 @@ CYBOZU_TEST_AUTO(init)
ret = mclBn_setErrFile("stderr");
CYBOZU_TEST_EQUAL(ret, 0);
#if MCLBN_OP_UNIT_SIZE == 4
printf("test MCLBN_curveFp254BNb %d\n", MCLBN_OP_UNIT_SIZE);
ret = mclBn_init(mclBn_curveFp254BNb, MCLBN_OP_UNIT_SIZE);
#if MCLBN_FP_UNIT_SIZE == 4
printf("test MCLBN_curveFp254BNb %d\n", MCLBN_FP_UNIT_SIZE);
ret = mclBn_init(mclBn_curveFp254BNb, MCLBN_FP_UNIT_SIZE);
#else
printf("test MCLBN_curveFp382_1 %d\n", MCLBN_OP_UNIT_SIZE);
ret = mclBn_init(mclBn_curveFp382_1, MCLBN_OP_UNIT_SIZE);
printf("test MCLBN_curveFp382_1 %d\n", MCLBN_FP_UNIT_SIZE);
ret = mclBn_init(mclBn_curveFp382_1, MCLBN_FP_UNIT_SIZE);
#endif
CYBOZU_TEST_EQUAL(ret, 0);
}

Loading…
Cancel
Save