rename mbn to mclBn

dev
MITSUNARI Shigeo 8 years ago
parent 5926add18d
commit 27575dd92e
  1. 4
      Makefile
  2. 370
      ffi/cs/bn256.cs
  3. 4
      ffi/cs/bn256_test.cs
  4. 196
      include/mcl/bn.h
  5. 8
      mklib.bat
  6. 208
      src/bn_c.cpp
  7. 4
      test/bn_c256_test.cpp
  8. 4
      test/bn_c384_test.cpp
  9. 354
      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) -DMBN_FP_UNIT_SIZE=4
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_OP_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) -DMBN_FP_UNIT_SIZE=6
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_OP_UNIT_SIZE=6"
$(ASM_OBJ): $(ASM_SRC)
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS)

@ -4,135 +4,135 @@ using System.Runtime.InteropServices;
namespace mcl {
class BN256 {
[DllImport("mclbn256.dll")]
public static extern int mbn_setErrFile([In][MarshalAs(UnmanagedType.LPStr)] string name);
[DllImport("mclbn256.dll")]
public static extern int mbn_init(int curve, int maxUnitSize);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_clear(ref Fr x);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_setInt(ref Fr y, int x);
[DllImport("mclbn256.dll")]
public static extern int mbnFr_setStr(ref Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclbn256.dll")]
public static extern int mbnFr_isValid(ref Fr x);
[DllImport("mclbn256.dll")]
public static extern int mbnFr_isEqual(ref Fr x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern int mbnFr_isZero(ref Fr x);
[DllImport("mclbn256.dll")]
public static extern int mbnFr_isOne(ref Fr x);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_setByCSPRNG(ref Fr x);
[DllImport("mclBn256.dll")]
public static extern int mclBn_setErrFile([In][MarshalAs(UnmanagedType.LPStr)] string name);
[DllImport("mclBn256.dll")]
public static extern int mclBn_init(int curve, int maxUnitSize);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_clear(ref Fr x);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_setInt(ref Fr y, int x);
[DllImport("mclBn256.dll")]
public static extern int mclBnFr_setStr(ref Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclBn256.dll")]
public static extern int mclBnFr_isValid(ref Fr x);
[DllImport("mclBn256.dll")]
public static extern int mclBnFr_isEqual(ref Fr x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern int mclBnFr_isZero(ref Fr x);
[DllImport("mclBn256.dll")]
public static extern int mclBnFr_isOne(ref Fr x);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_setByCSPRNG(ref Fr x);
[DllImport("mclbn256.dll")]
public static extern int mbnFr_setHashOf(ref Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize);
[DllImport("mclbn256.dll")]
public static extern int mbnFr_getStr([Out]StringBuilder buf, long maxBufSize, ref Fr x, int ioMode);
[DllImport("mclBn256.dll")]
public static extern int mclBnFr_setHashOf(ref Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize);
[DllImport("mclBn256.dll")]
public static extern int mclBnFr_getStr([Out]StringBuilder buf, long maxBufSize, ref Fr x, int ioMode);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_neg(ref Fr y, ref Fr x);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_inv(ref Fr y, ref Fr x);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_add(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_sub(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_mul(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern void mbnFr_div(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_neg(ref Fr y, ref Fr x);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_inv(ref Fr y, ref Fr x);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_add(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_sub(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_mul(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern void mclBnFr_div(ref Fr z, ref Fr x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern void mbnG1_clear(ref G1 x);
[DllImport("mclbn256.dll")]
public static extern int mbnG1_setStr(ref G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclbn256.dll")]
public static extern int mbnG1_isValid(ref G1 x);
[DllImport("mclbn256.dll")]
public static extern int mbnG1_isEqual(ref G1 x, ref G1 y);
[DllImport("mclbn256.dll")]
public static extern int mbnG1_isZero(ref G1 x);
[DllImport("mclbn256.dll")]
public static extern int mbnG1_hashAndMapTo(ref G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize);
[DllImport("mclbn256.dll")]
public static extern long mbnG1_getStr([Out]StringBuilder buf, long maxBufSize, ref G1 x, int ioMode);
[DllImport("mclbn256.dll")]
public static extern void mbnG1_neg(ref G1 y, ref G1 x);
[DllImport("mclbn256.dll")]
public static extern void mbnG1_dbl(ref G1 y, ref G1 x);
[DllImport("mclbn256.dll")]
public static extern void mbnG1_add(ref G1 z, ref G1 x, ref G1 y);
[DllImport("mclbn256.dll")]
public static extern void mbnG1_sub(ref G1 z, ref G1 x, ref G1 y);
[DllImport("mclbn256.dll")]
public static extern void mbnG1_mul(ref G1 z, ref G1 x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern void mclBnG1_clear(ref G1 x);
[DllImport("mclBn256.dll")]
public static extern int mclBnG1_setStr(ref G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclBn256.dll")]
public static extern int mclBnG1_isValid(ref G1 x);
[DllImport("mclBn256.dll")]
public static extern int mclBnG1_isEqual(ref G1 x, ref G1 y);
[DllImport("mclBn256.dll")]
public static extern int mclBnG1_isZero(ref G1 x);
[DllImport("mclBn256.dll")]
public static extern int mclBnG1_hashAndMapTo(ref G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize);
[DllImport("mclBn256.dll")]
public static extern long mclBnG1_getStr([Out]StringBuilder buf, long maxBufSize, ref G1 x, int ioMode);
[DllImport("mclBn256.dll")]
public static extern void mclBnG1_neg(ref G1 y, ref G1 x);
[DllImport("mclBn256.dll")]
public static extern void mclBnG1_dbl(ref G1 y, ref G1 x);
[DllImport("mclBn256.dll")]
public static extern void mclBnG1_add(ref G1 z, ref G1 x, ref G1 y);
[DllImport("mclBn256.dll")]
public static extern void mclBnG1_sub(ref G1 z, ref G1 x, ref G1 y);
[DllImport("mclBn256.dll")]
public static extern void mclBnG1_mul(ref G1 z, ref G1 x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern void mbnG2_clear(ref G2 x);
[DllImport("mclbn256.dll")]
public static extern int mbnG2_setStr(ref G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclbn256.dll")]
public static extern int mbnG2_isValid(ref G2 x);
[DllImport("mclbn256.dll")]
public static extern int mbnG2_isEqual(ref G2 x, ref G2 y);
[DllImport("mclbn256.dll")]
public static extern int mbnG2_isZero(ref G2 x);
[DllImport("mclbn256.dll")]
public static extern int mbnG2_hashAndMapTo(ref G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize);
[DllImport("mclbn256.dll")]
public static extern long mbnG2_getStr([Out]StringBuilder buf, long maxBufSize, ref G2 x, int ioMode);
[DllImport("mclbn256.dll")]
public static extern void mbnG2_neg(ref G2 y, ref G2 x);
[DllImport("mclbn256.dll")]
public static extern void mbnG2_dbl(ref G2 y, ref G2 x);
[DllImport("mclbn256.dll")]
public static extern void mbnG2_add(ref G2 z, ref G2 x, ref G2 y);
[DllImport("mclbn256.dll")]
public static extern void mbnG2_sub(ref G2 z, ref G2 x, ref G2 y);
[DllImport("mclbn256.dll")]
public static extern void mbnG2_mul(ref G2 z, ref G2 x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern void mclBnG2_clear(ref G2 x);
[DllImport("mclBn256.dll")]
public static extern int mclBnG2_setStr(ref G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclBn256.dll")]
public static extern int mclBnG2_isValid(ref G2 x);
[DllImport("mclBn256.dll")]
public static extern int mclBnG2_isEqual(ref G2 x, ref G2 y);
[DllImport("mclBn256.dll")]
public static extern int mclBnG2_isZero(ref G2 x);
[DllImport("mclBn256.dll")]
public static extern int mclBnG2_hashAndMapTo(ref G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize);
[DllImport("mclBn256.dll")]
public static extern long mclBnG2_getStr([Out]StringBuilder buf, long maxBufSize, ref G2 x, int ioMode);
[DllImport("mclBn256.dll")]
public static extern void mclBnG2_neg(ref G2 y, ref G2 x);
[DllImport("mclBn256.dll")]
public static extern void mclBnG2_dbl(ref G2 y, ref G2 x);
[DllImport("mclBn256.dll")]
public static extern void mclBnG2_add(ref G2 z, ref G2 x, ref G2 y);
[DllImport("mclBn256.dll")]
public static extern void mclBnG2_sub(ref G2 z, ref G2 x, ref G2 y);
[DllImport("mclBn256.dll")]
public static extern void mclBnG2_mul(ref G2 z, ref G2 x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_clear(ref GT x);
[DllImport("mclbn256.dll")]
public static extern int mbnGT_setStr(ref GT x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclbn256.dll")]
public static extern int mbnGT_isEqual(ref GT x, ref GT y);
[DllImport("mclbn256.dll")]
public static extern int mbnGT_isZero(ref GT x);
[DllImport("mclbn256.dll")]
public static extern int mbnGT_isOne(ref GT x);
[DllImport("mclbn256.dll")]
public static extern long mbnGT_getStr([Out]StringBuilder buf, long maxBufSize, ref GT x, int ioMode);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_neg(ref GT y, ref GT x);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_inv(ref GT y, ref GT x);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_add(ref GT z, ref GT x, ref GT y);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_sub(ref GT z, ref GT x, ref GT y);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_mul(ref GT z, ref GT x, ref GT y);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_div(ref GT z, ref GT x, ref GT y);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_clear(ref GT x);
[DllImport("mclBn256.dll")]
public static extern int mclBnGT_setStr(ref GT x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode);
[DllImport("mclBn256.dll")]
public static extern int mclBnGT_isEqual(ref GT x, ref GT y);
[DllImport("mclBn256.dll")]
public static extern int mclBnGT_isZero(ref GT x);
[DllImport("mclBn256.dll")]
public static extern int mclBnGT_isOne(ref GT x);
[DllImport("mclBn256.dll")]
public static extern long mclBnGT_getStr([Out]StringBuilder buf, long maxBufSize, ref GT x, int ioMode);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_neg(ref GT y, ref GT x);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_inv(ref GT y, ref GT x);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_add(ref GT z, ref GT x, ref GT y);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_sub(ref GT z, ref GT x, ref GT y);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_mul(ref GT z, ref GT x, ref GT y);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_div(ref GT z, ref GT x, ref GT y);
[DllImport("mclbn256.dll")]
public static extern void mbnGT_pow(ref GT z, ref GT x, ref Fr y);
[DllImport("mclbn256.dll")]
public static extern void mbn_pairing(ref GT z, ref G1 x, ref G2 y);
[DllImport("mclbn256.dll")]
public static extern void mbn_finalExp(ref GT y, ref GT x);
[DllImport("mclbn256.dll")]
public static extern void mbn_millerLoop(ref GT z, ref G1 x, ref G2 y);
[DllImport("mclBn256.dll")]
public static extern void mclBnGT_pow(ref GT z, ref GT x, ref Fr y);
[DllImport("mclBn256.dll")]
public static extern void mclBn_pairing(ref GT z, ref G1 x, ref G2 y);
[DllImport("mclBn256.dll")]
public static extern void mclBn_finalExp(ref GT y, ref GT x);
[DllImport("mclBn256.dll")]
public static extern void mclBn_millerLoop(ref GT z, ref G1 x, ref G2 y);
public static void init()
{
const int curveFp254BNb = 0;
const int maxUnitSize = 4;
if (mbn_init(curveFp254BNb, maxUnitSize) != 0) {
throw new InvalidOperationException("mbn_init");
if (mclBn_init(curveFp254BNb, maxUnitSize) != 0) {
throw new InvalidOperationException("mclBn_init");
}
}
[StructLayout(LayoutKind.Sequential)]
@ -140,76 +140,76 @@ namespace mcl {
private ulong v0, v1, v2, v3;
public void Clear()
{
mbnFr_clear(ref this);
mclBnFr_clear(ref this);
}
public void SetInt(int x)
{
mbnFr_setInt(ref this, x);
mclBnFr_setInt(ref this, x);
}
public void SetStr(string s, int ioMode)
{
if (mbnFr_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mbnFr_setStr" + s);
if (mclBnFr_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mclBnFr_setStr" + s);
}
}
public bool IsValid()
{
return mbnFr_isValid(ref this) == 1;
return mclBnFr_isValid(ref this) == 1;
}
public bool Equals(Fr rhs)
{
return mbnFr_isEqual(ref this, ref rhs) == 1;
return mclBnFr_isEqual(ref this, ref rhs) == 1;
}
public bool IsZero()
{
return mbnFr_isZero(ref this) == 1;
return mclBnFr_isZero(ref this) == 1;
}
public bool IsOne()
{
return mbnFr_isOne(ref this) == 1;
return mclBnFr_isOne(ref this) == 1;
}
public void SetByCSPRNG()
{
mbnFr_setByCSPRNG(ref this);
mclBnFr_setByCSPRNG(ref this);
}
public void SetHashOf(String s)
{
if (mbnFr_setHashOf(ref this, s, s.Length) != 0) {
throw new InvalidOperationException("mbnFr_setHashOf:" + s);
if (mclBnFr_setHashOf(ref this, s, s.Length) != 0) {
throw new InvalidOperationException("mclBnFr_setHashOf:" + s);
}
}
public string GetStr(int ioMode)
{
StringBuilder sb = new StringBuilder(1024);
long size = mbnFr_getStr(sb, sb.Capacity, ref this, ioMode);
long size = mclBnFr_getStr(sb, sb.Capacity, ref this, ioMode);
if (size == 0) {
throw new InvalidOperationException("mbnFr_getStr:");
throw new InvalidOperationException("mclBnFr_getStr:");
}
return sb.ToString();
}
public void Neg(Fr x)
{
mbnFr_neg(ref this, ref x);
mclBnFr_neg(ref this, ref x);
}
public void Inv(Fr x)
{
mbnFr_inv(ref this, ref x);
mclBnFr_inv(ref this, ref x);
}
public void Add(Fr x, Fr y)
{
mbnFr_add(ref this, ref x, ref y);
mclBnFr_add(ref this, ref x, ref y);
}
public void Sub(Fr x, Fr y)
{
mbnFr_sub(ref this, ref x, ref y);
mclBnFr_sub(ref this, ref x, ref y);
}
public void Mul(Fr x, Fr y)
{
mbnFr_mul(ref this, ref x, ref y);
mclBnFr_mul(ref this, ref x, ref y);
}
public void Div(Fr x, Fr y)
{
mbnFr_div(ref this, ref x, ref y);
mclBnFr_div(ref this, ref x, ref y);
}
public static Fr operator -(Fr x)
{
@ -247,60 +247,60 @@ namespace mcl {
private ulong v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11;
public void Clear()
{
mbnG1_clear(ref this);
mclBnG1_clear(ref this);
}
public void setStr(String s, int ioMode)
{
if (mbnG1_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mbnG1_setStr:" + s);
if (mclBnG1_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mclBnG1_setStr:" + s);
}
}
public bool IsValid()
{
return mbnG1_isValid(ref this) == 1;
return mclBnG1_isValid(ref this) == 1;
}
public bool Equals(G1 rhs)
{
return mbnG1_isEqual(ref this, ref rhs) == 1;
return mclBnG1_isEqual(ref this, ref rhs) == 1;
}
public bool IsZero()
{
return mbnG1_isZero(ref this) == 1;
return mclBnG1_isZero(ref this) == 1;
}
public void HashAndMapTo(String s)
{
if (mbnG1_hashAndMapTo(ref this, s, s.Length) != 0) {
throw new ArgumentException("mbnG1_hashAndMapTo:" + s);
if (mclBnG1_hashAndMapTo(ref this, s, s.Length) != 0) {
throw new ArgumentException("mclBnG1_hashAndMapTo:" + s);
}
}
public string GetStr(int ioMode)
{
StringBuilder sb = new StringBuilder(1024);
long size = mbnG1_getStr(sb, sb.Capacity, ref this, ioMode);
long size = mclBnG1_getStr(sb, sb.Capacity, ref this, ioMode);
if (size == 0) {
throw new InvalidOperationException("mbnG1_getStr:");
throw new InvalidOperationException("mclBnG1_getStr:");
}
return sb.ToString();
}
public void Neg(G1 x)
{
mbnG1_neg(ref this, ref x);
mclBnG1_neg(ref this, ref x);
}
public void Dbl(G1 x)
{
mbnG1_dbl(ref this, ref x);
mclBnG1_dbl(ref this, ref x);
}
public void Add(G1 x, G1 y)
{
mbnG1_add(ref this, ref x, ref y);
mclBnG1_add(ref this, ref x, ref y);
}
public void Sub(G1 x, G1 y)
{
mbnG1_sub(ref this, ref x, ref y);
mclBnG1_sub(ref this, ref x, ref y);
}
public void Mul(G1 x, Fr y)
{
mbnG1_mul(ref this, ref x, ref y);
mclBnG1_mul(ref this, ref x, ref y);
}
}
[StructLayout(LayoutKind.Sequential)]
@ -309,60 +309,60 @@ namespace mcl {
private ulong v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23;
public void Clear()
{
mbnG2_clear(ref this);
mclBnG2_clear(ref this);
}
public void setStr(String s, int ioMode)
{
if (mbnG2_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mbnG2_setStr:" + s);
if (mclBnG2_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mclBnG2_setStr:" + s);
}
}
public bool IsValid()
{
return mbnG2_isValid(ref this) == 1;
return mclBnG2_isValid(ref this) == 1;
}
public bool Equals(G2 rhs)
{
return mbnG2_isEqual(ref this, ref rhs) == 1;
return mclBnG2_isEqual(ref this, ref rhs) == 1;
}
public bool IsZero()
{
return mbnG2_isZero(ref this) == 1;
return mclBnG2_isZero(ref this) == 1;
}
public void HashAndMapTo(String s)
{
if (mbnG2_hashAndMapTo(ref this, s, s.Length) != 0) {
throw new ArgumentException("mbnG2_hashAndMapTo:" + s);
if (mclBnG2_hashAndMapTo(ref this, s, s.Length) != 0) {
throw new ArgumentException("mclBnG2_hashAndMapTo:" + s);
}
}
public string GetStr(int ioMode)
{
StringBuilder sb = new StringBuilder(1024);
long size = mbnG2_getStr(sb, sb.Capacity, ref this, ioMode);
long size = mclBnG2_getStr(sb, sb.Capacity, ref this, ioMode);
if (size == 0) {
throw new InvalidOperationException("mbnG2_getStr:");
throw new InvalidOperationException("mclBnG2_getStr:");
}
return sb.ToString();
}
public void Neg(G2 x)
{
mbnG2_neg(ref this, ref x);
mclBnG2_neg(ref this, ref x);
}
public void Dbl(G2 x)
{
mbnG2_dbl(ref this, ref x);
mclBnG2_dbl(ref this, ref x);
}
public void Add(G2 x, G2 y)
{
mbnG2_add(ref this, ref x, ref y);
mclBnG2_add(ref this, ref x, ref y);
}
public void Sub(G2 x, G2 y)
{
mbnG2_sub(ref this, ref x, ref y);
mclBnG2_sub(ref this, ref x, ref y);
}
public void Mul(G2 x, Fr y)
{
mbnG2_mul(ref this, ref x, ref y);
mclBnG2_mul(ref this, ref x, ref y);
}
}
[StructLayout(LayoutKind.Sequential)]
@ -373,58 +373,58 @@ namespace mcl {
private ulong v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47;
public void Clear()
{
mbnGT_clear(ref this);
mclBnGT_clear(ref this);
}
public void setStr(String s, int ioMode)
{
if (mbnGT_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mbnGT_setStr:" + s);
if (mclBnGT_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mclBnGT_setStr:" + s);
}
}
public bool Equals(GT rhs)
{
return mbnGT_isEqual(ref this, ref rhs) == 1;
return mclBnGT_isEqual(ref this, ref rhs) == 1;
}
public bool IsZero()
{
return mbnGT_isZero(ref this) == 1;
return mclBnGT_isZero(ref this) == 1;
}
public bool IsOne()
{
return mbnGT_isOne(ref this) == 1;
return mclBnGT_isOne(ref this) == 1;
}
public string GetStr(int ioMode)
{
StringBuilder sb = new StringBuilder(1024);
long size = mbnGT_getStr(sb, sb.Capacity, ref this, ioMode);
long size = mclBnGT_getStr(sb, sb.Capacity, ref this, ioMode);
if (size == 0) {
throw new InvalidOperationException("mbnGT_getStr:");
throw new InvalidOperationException("mclBnGT_getStr:");
}
return sb.ToString();
}
public void Neg(GT x)
{
mbnGT_neg(ref this, ref x);
mclBnGT_neg(ref this, ref x);
}
public void Inv(GT x)
{
mbnGT_inv(ref this, ref x);
mclBnGT_inv(ref this, ref x);
}
public void Add(GT x, GT y)
{
mbnGT_add(ref this, ref x, ref this);
mclBnGT_add(ref this, ref x, ref this);
}
public void Sub(GT x, GT y)
{
mbnGT_sub(ref this, ref x, ref this);
mclBnGT_sub(ref this, ref x, ref this);
}
public void Mul(GT x, GT y)
{
mbnGT_mul(ref this, ref x, ref this);
mclBnGT_mul(ref this, ref x, ref this);
}
public void Div(GT x, GT y)
{
mbnGT_div(ref this, ref x, ref this);
mclBnGT_div(ref this, ref x, ref this);
}
public static GT operator -(GT x)
{
@ -458,19 +458,19 @@ namespace mcl {
}
public void Pow(GT x, Fr y)
{
mbnGT_pow(ref this, ref x, ref y);
mclBnGT_pow(ref this, ref x, ref y);
}
public void Pairing(G1 x, G2 y)
{
mbn_pairing(ref this, ref x, ref y);
mclBn_pairing(ref this, ref x, ref y);
}
public void FinalExp(GT x)
{
mbn_finalExp(ref this, ref x);
mclBn_finalExp(ref this, ref x);
}
public void MillerLoop(G1 x, G2 y)
{
mbn_millerLoop(ref this, ref x, ref y);
mclBn_millerLoop(ref this, ref x, ref y);
}
}
}

@ -16,8 +16,8 @@ namespace mcl {
assert("64bit system", System.Environment.Is64BitProcess);
init();
int ret;
ret = mbn_setErrFile("mbn_test.txt");
assert("mbn_setErrFile", ret == 0);
ret = mclBn_setErrFile("mclbn_test.txt");
assert("mclbn_setErrFile", ret == 0);
TestFr();
TestG1();
TestG2();

@ -6,20 +6,20 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#ifndef MBN_FP_UNIT_SIZE
#error "define MBN_FP_UNIT_SIZE 4(or 6)"
#ifndef MCLBN_OP_UNIT_SIZE
#error "define MCLBN_OP_UNIT_SIZE 4(or 6)"
#endif
#include <stdint.h> // for uint64_t, uint8_t
#include <stdlib.h> // for size_t
#ifdef _MSC_VER
#ifdef MBN_DLL_EXPORT
#define MBN_DLL_API __declspec(dllexport)
#ifdef MCLBN_DLL_EXPORT
#define MCLBN_DLL_API __declspec(dllexport)
#else
#define MBN_DLL_API __declspec(dllimport)
#define MCLBN_DLL_API __declspec(dllimport)
#ifndef MCL_NO_AUTOLINK
#if MBN_FP_UNIT_SIZE == 4
#if MCLBN_OP_UNIT_SIZE == 4
#pragma comment(lib, "mclbn256.lib")
#else
#pragma comment(lib, "mclbn384.lib")
@ -27,37 +27,37 @@
#endif
#endif
#else
#define MBN_DLL_API
#define MCLBN_DLL_API
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef MBN_DEFINE_STRUCT
#ifdef MCLBN_DEFINE_STRUCT
typedef struct {
uint64_t d[MBN_FP_UNIT_SIZE];
} mbnFr;
uint64_t d[MCLBN_OP_UNIT_SIZE];
} mclBnFr;
typedef struct {
uint64_t d[MBN_FP_UNIT_SIZE * 3];
} mbnG1;
uint64_t d[MCLBN_OP_UNIT_SIZE * 3];
} mclBnG1;
typedef struct {
uint64_t d[MBN_FP_UNIT_SIZE * 2 * 3];
} mbnG2;
uint64_t d[MCLBN_OP_UNIT_SIZE * 2 * 3];
} mclBnG2;
typedef struct {
uint64_t d[MBN_FP_UNIT_SIZE * 12];
} mbnGT;
uint64_t d[MCLBN_OP_UNIT_SIZE * 12];
} mclBnGT;
#else
typedef struct mbnFr mbnFr;
typedef struct mbnG1 mbnG1;
typedef struct mbnG2 mbnG2;
typedef struct mbnGT mbnGT;
typedef struct mclBnFr mclBnFr;
typedef struct mclBnG1 mclBnG1;
typedef struct mclBnG2 mclBnG2;
typedef struct mclBnGT mclBnGT;
#endif
@ -68,31 +68,31 @@ typedef struct mbnGT mbnGT;
return 0 if success
@note not threadsafe
*/
MBN_DLL_API int mbn_setErrFile(const char *name);
MCLBN_DLL_API int mclBn_setErrFile(const char *name);
enum {
mbn_curveFp254BNb = 0,
mbn_curveFp382_1 = 1,
mbn_curveFp382_2 = 2
mclBn_curveFp254BNb = 0,
mclBn_curveFp382_1 = 1,
mclBn_curveFp382_2 = 2
};
/*
init library
@param curve [in] type of bn curve
@param maxUnitSize [in] 4 or 6
curve = MBN_CurveFp254BNb is allowed if maxUnitSize = 4
curve = MBN_CurveFp254BNb/MBN_CurveFp382_1/MBN_CurveFp382_2 are allowed if maxUnitSize = 6
curve = MCLBN_CurveFp254BNb is allowed if maxUnitSize = 4
curve = MCLBN_CurveFp254BNb/MCLBN_CurveFp382_1/MCLBN_CurveFp382_2 are allowed if maxUnitSize = 6
@note not threadsafe
@note MBN_init is used in libeay32
@note MCLBN_init is used in libeay32
*/
MBN_DLL_API int mbn_init(int curve, int maxUnitSize);
MCLBN_DLL_API int mclBn_init(int curve, int maxUnitSize);
////////////////////////////////////////////////
// set zero
MBN_DLL_API void mbnFr_clear(mbnFr *x);
MCLBN_DLL_API void mclBnFr_clear(mclBnFr *x);
// set x to y
MBN_DLL_API void mbnFr_setInt(mbnFr *y, int x);
MCLBN_DLL_API void mclBnFr_setInt(mclBnFr *y, int x);
/*
ioMode
@ -100,125 +100,125 @@ MBN_DLL_API void mbnFr_setInt(mbnFr *y, int x);
16 : hexadecimal number
*/
// return 0 if success
MBN_DLL_API int mbnFr_setStr(mbnFr *x, const char *buf, size_t bufSize, int ioMode);
MBN_DLL_API int mbnFr_deserialize(mbnFr *x, const char *buf, size_t bufSize);
MCLBN_DLL_API int mclBnFr_setStr(mclBnFr *x, const char *buf, size_t bufSize, int ioMode);
MCLBN_DLL_API int mclBnFr_deserialize(mclBnFr *x, const char *buf, size_t bufSize);
// mask buf with (1 << (bitLen(r) - 1)) - 1 if buf >= r
MBN_DLL_API int mbnFr_setLittleEndian(mbnFr *x, const void *buf, size_t bufSize);
MCLBN_DLL_API int mclBnFr_setLittleEndian(mclBnFr *x, const void *buf, size_t bufSize);
// return 1 if true and 0 otherwise
MBN_DLL_API int mbnFr_isValid(const mbnFr *x);
MBN_DLL_API int mbnFr_isEqual(const mbnFr *x, const mbnFr *y);
MBN_DLL_API int mbnFr_isZero(const mbnFr *x);
MBN_DLL_API int mbnFr_isOne(const mbnFr *x);
MCLBN_DLL_API int mclBnFr_isValid(const mclBnFr *x);
MCLBN_DLL_API int mclBnFr_isEqual(const mclBnFr *x, const mclBnFr *y);
MCLBN_DLL_API int mclBnFr_isZero(const mclBnFr *x);
MCLBN_DLL_API int mclBnFr_isOne(const mclBnFr *x);
MBN_DLL_API void mbnFr_setByCSPRNG(mbnFr *x);
MCLBN_DLL_API void mclBnFr_setByCSPRNG(mclBnFr *x);
// hash(s) and set x
MBN_DLL_API int mbnFr_setHashOf(mbnFr *x, const void *buf, size_t bufSize);
MCLBN_DLL_API int mclBnFr_setHashOf(mclBnFr *x, const void *buf, size_t bufSize);
// return strlen(buf) if sucess else 0
MBN_DLL_API size_t mbnFr_getStr(char *buf, size_t maxBufSize, const mbnFr *x, int ioMode);
MCLBN_DLL_API size_t mclBnFr_getStr(char *buf, size_t maxBufSize, const mclBnFr *x, int ioMode);
// return written byte if sucess else 0
MBN_DLL_API size_t mbnFr_serialize(void *buf, size_t maxBufSize, const mbnFr *x);
MCLBN_DLL_API size_t mclBnFr_serialize(void *buf, size_t maxBufSize, const mclBnFr *x);
MBN_DLL_API void mbnFr_neg(mbnFr *y, const mbnFr *x);
MBN_DLL_API void mbnFr_inv(mbnFr *y, const mbnFr *x);
MBN_DLL_API void mbnFr_add(mbnFr *z, const mbnFr *x, const mbnFr *y);
MBN_DLL_API void mbnFr_sub(mbnFr *z, const mbnFr *x, const mbnFr *y);
MBN_DLL_API void mbnFr_mul(mbnFr *z, const mbnFr *x, const mbnFr *y);
MBN_DLL_API void mbnFr_div(mbnFr *z, const mbnFr *x, const mbnFr *y);
MCLBN_DLL_API void mclBnFr_neg(mclBnFr *y, const mclBnFr *x);
MCLBN_DLL_API void mclBnFr_inv(mclBnFr *y, const mclBnFr *x);
MCLBN_DLL_API void mclBnFr_add(mclBnFr *z, const mclBnFr *x, const mclBnFr *y);
MCLBN_DLL_API void mclBnFr_sub(mclBnFr *z, const mclBnFr *x, const mclBnFr *y);
MCLBN_DLL_API void mclBnFr_mul(mclBnFr *z, const mclBnFr *x, const mclBnFr *y);
MCLBN_DLL_API void mclBnFr_div(mclBnFr *z, const mclBnFr *x, const mclBnFr *y);
////////////////////////////////////////////////
// set zero
MBN_DLL_API void mbnG1_clear(mbnG1 *x);
MCLBN_DLL_API void mclBnG1_clear(mclBnG1 *x);
// return 0 if success
MBN_DLL_API int mbnG1_setStr(mbnG1 *x, const char *buf, size_t bufSize, int ioMode);
MBN_DLL_API int mbnG1_deserialize(mbnG1 *x, const char *buf, size_t bufSize);
MCLBN_DLL_API int mclBnG1_setStr(mclBnG1 *x, const char *buf, size_t bufSize, int ioMode);
MCLBN_DLL_API int mclBnG1_deserialize(mclBnG1 *x, const char *buf, size_t bufSize);
// return 1 if true and 0 otherwise
MBN_DLL_API int mbnG1_isValid(const mbnG1 *x);
MBN_DLL_API int mbnG1_isEqual(const mbnG1 *x, const mbnG1 *y);
MBN_DLL_API int mbnG1_isZero(const mbnG1 *x);
MCLBN_DLL_API int mclBnG1_isValid(const mclBnG1 *x);
MCLBN_DLL_API int mclBnG1_isEqual(const mclBnG1 *x, const mclBnG1 *y);
MCLBN_DLL_API int mclBnG1_isZero(const mclBnG1 *x);
MBN_DLL_API int mbnG1_hashAndMapTo(mbnG1 *x, const void *buf, size_t bufSize);
MCLBN_DLL_API int mclBnG1_hashAndMapTo(mclBnG1 *x, const void *buf, size_t bufSize);
// return 0 if success
MBN_DLL_API size_t mbnG1_getStr(char *buf, size_t maxBufSize, const mbnG1 *x, int ioMode);
MCLBN_DLL_API size_t mclBnG1_getStr(char *buf, size_t maxBufSize, const mclBnG1 *x, int ioMode);
// return written size if sucess else 0
MBN_DLL_API size_t mbnG1_serialize(void *buf, size_t maxBufSize, const mbnG1 *x);
MCLBN_DLL_API size_t mclBnG1_serialize(void *buf, size_t maxBufSize, const mclBnG1 *x);
MBN_DLL_API void mbnG1_neg(mbnG1 *y, const mbnG1 *x);
MBN_DLL_API void mbnG1_dbl(mbnG1 *y, const mbnG1 *x);
MBN_DLL_API void mbnG1_add(mbnG1 *z, const mbnG1 *x, const mbnG1 *y);
MBN_DLL_API void mbnG1_sub(mbnG1 *z, const mbnG1 *x, const mbnG1 *y);
MBN_DLL_API void mbnG1_mul(mbnG1 *z, const mbnG1 *x, const mbnFr *y);
MCLBN_DLL_API void mclBnG1_neg(mclBnG1 *y, const mclBnG1 *x);
MCLBN_DLL_API void mclBnG1_dbl(mclBnG1 *y, const mclBnG1 *x);
MCLBN_DLL_API void mclBnG1_add(mclBnG1 *z, const mclBnG1 *x, const mclBnG1 *y);
MCLBN_DLL_API void mclBnG1_sub(mclBnG1 *z, const mclBnG1 *x, const mclBnG1 *y);
MCLBN_DLL_API void mclBnG1_mul(mclBnG1 *z, const mclBnG1 *x, const mclBnFr *y);
////////////////////////////////////////////////
// set zero
MBN_DLL_API void mbnG2_clear(mbnG2 *x);
MCLBN_DLL_API void mclBnG2_clear(mclBnG2 *x);
// return 0 if success
MBN_DLL_API int mbnG2_setStr(mbnG2 *x, const char *buf, size_t bufSize, int ioMode);
MBN_DLL_API int mbnG2_deserialize(mbnG2 *x, const char *buf, size_t bufSize);
MCLBN_DLL_API int mclBnG2_setStr(mclBnG2 *x, const char *buf, size_t bufSize, int ioMode);
MCLBN_DLL_API int mclBnG2_deserialize(mclBnG2 *x, const char *buf, size_t bufSize);
// return 1 if true and 0 otherwise
MBN_DLL_API int mbnG2_isValid(const mbnG2 *x);
MBN_DLL_API int mbnG2_isEqual(const mbnG2 *x, const mbnG2 *y);
MBN_DLL_API int mbnG2_isZero(const mbnG2 *x);
MCLBN_DLL_API int mclBnG2_isValid(const mclBnG2 *x);
MCLBN_DLL_API int mclBnG2_isEqual(const mclBnG2 *x, const mclBnG2 *y);
MCLBN_DLL_API int mclBnG2_isZero(const mclBnG2 *x);
MBN_DLL_API int mbnG2_hashAndMapTo(mbnG2 *x, const void *buf, size_t bufSize);
MCLBN_DLL_API int mclBnG2_hashAndMapTo(mclBnG2 *x, const void *buf, size_t bufSize);
// return 0 if success
MBN_DLL_API size_t mbnG2_getStr(char *buf, size_t maxBufSize, const mbnG2 *x, int ioMode);
MCLBN_DLL_API size_t mclBnG2_getStr(char *buf, size_t maxBufSize, const mclBnG2 *x, int ioMode);
// return written size if sucess else 0
MBN_DLL_API size_t mbnG2_serialize(void *buf, size_t maxBufSize, const mbnG2 *x);
MCLBN_DLL_API size_t mclBnG2_serialize(void *buf, size_t maxBufSize, const mclBnG2 *x);
MBN_DLL_API void mbnG2_neg(mbnG2 *y, const mbnG2 *x);
MBN_DLL_API void mbnG2_dbl(mbnG2 *y, const mbnG2 *x);
MBN_DLL_API void mbnG2_add(mbnG2 *z, const mbnG2 *x, const mbnG2 *y);
MBN_DLL_API void mbnG2_sub(mbnG2 *z, const mbnG2 *x, const mbnG2 *y);
MBN_DLL_API void mbnG2_mul(mbnG2 *z, const mbnG2 *x, const mbnFr *y);
MCLBN_DLL_API void mclBnG2_neg(mclBnG2 *y, const mclBnG2 *x);
MCLBN_DLL_API void mclBnG2_dbl(mclBnG2 *y, const mclBnG2 *x);
MCLBN_DLL_API void mclBnG2_add(mclBnG2 *z, const mclBnG2 *x, const mclBnG2 *y);
MCLBN_DLL_API void mclBnG2_sub(mclBnG2 *z, const mclBnG2 *x, const mclBnG2 *y);
MCLBN_DLL_API void mclBnG2_mul(mclBnG2 *z, const mclBnG2 *x, const mclBnFr *y);
////////////////////////////////////////////////
// set zero
MBN_DLL_API void mbnGT_clear(mbnGT *x);
MCLBN_DLL_API void mclBnGT_clear(mclBnGT *x);
// return 0 if success
MBN_DLL_API int mbnGT_setStr(mbnGT *x, const char *buf, size_t bufSize, int ioMode);
MBN_DLL_API int mbnGT_deserialize(mbnGT *x, const char *buf, size_t bufSize);
MCLBN_DLL_API int mclBnGT_setStr(mclBnGT *x, const char *buf, size_t bufSize, int ioMode);
MCLBN_DLL_API int mclBnGT_deserialize(mclBnGT *x, const char *buf, size_t bufSize);
// return 1 if true and 0 otherwise
MBN_DLL_API int mbnGT_isEqual(const mbnGT *x, const mbnGT *y);
MBN_DLL_API int mbnGT_isZero(const mbnGT *x);
MBN_DLL_API int mbnGT_isOne(const mbnGT *x);
MCLBN_DLL_API int mclBnGT_isEqual(const mclBnGT *x, const mclBnGT *y);
MCLBN_DLL_API int mclBnGT_isZero(const mclBnGT *x);
MCLBN_DLL_API int mclBnGT_isOne(const mclBnGT *x);
// return 0 if success
MBN_DLL_API size_t mbnGT_getStr(char *buf, size_t maxBufSize, const mbnGT *x, int ioMode);
MCLBN_DLL_API size_t mclBnGT_getStr(char *buf, size_t maxBufSize, const mclBnGT *x, int ioMode);
// return written size if sucess else 0
MBN_DLL_API size_t mbnGT_serialize(void *buf, size_t maxBufSize, const mbnGT *x);
MCLBN_DLL_API size_t mclBnGT_serialize(void *buf, size_t maxBufSize, const mclBnGT *x);
MBN_DLL_API void mbnGT_neg(mbnGT *y, const mbnGT *x);
MBN_DLL_API void mbnGT_inv(mbnGT *y, const mbnGT *x);
MBN_DLL_API void mbnGT_add(mbnGT *z, const mbnGT *x, const mbnGT *y);
MBN_DLL_API void mbnGT_sub(mbnGT *z, const mbnGT *x, const mbnGT *y);
MBN_DLL_API void mbnGT_mul(mbnGT *z, const mbnGT *x, const mbnGT *y);
MBN_DLL_API void mbnGT_div(mbnGT *z, const mbnGT *x, const mbnGT *y);
MCLBN_DLL_API void mclBnGT_neg(mclBnGT *y, const mclBnGT *x);
MCLBN_DLL_API void mclBnGT_inv(mclBnGT *y, const mclBnGT *x);
MCLBN_DLL_API void mclBnGT_add(mclBnGT *z, const mclBnGT *x, const mclBnGT *y);
MCLBN_DLL_API void mclBnGT_sub(mclBnGT *z, const mclBnGT *x, const mclBnGT *y);
MCLBN_DLL_API void mclBnGT_mul(mclBnGT *z, const mclBnGT *x, const mclBnGT *y);
MCLBN_DLL_API void mclBnGT_div(mclBnGT *z, const mclBnGT *x, const mclBnGT *y);
MBN_DLL_API void mbnGT_pow(mbnGT *z, const mbnGT *x, const mbnFr *y);
MCLBN_DLL_API void mclBnGT_pow(mclBnGT *z, const mclBnGT *x, const mclBnFr *y);
MBN_DLL_API void mbn_pairing(mbnGT *z, const mbnG1 *x, const mbnG2 *y);
MBN_DLL_API void mbn_finalExp(mbnGT *y, const mbnGT *x);
MBN_DLL_API void mbn_millerLoop(mbnGT *z, const mbnG1 *x, const mbnG2 *y);
MCLBN_DLL_API void mclBn_pairing(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y);
MCLBN_DLL_API void mclBn_finalExp(mclBnGT *y, const mclBnGT *x);
MCLBN_DLL_API void mclBn_millerLoop(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y);
// return precomputedQcoeffSize * sizeof(Fp6) / sizeof(uint64_t)
MBN_DLL_API int mbn_getUint64NumToPrecompute(void);
MCLBN_DLL_API int mclBn_getUint64NumToPrecompute(void);
// allocate Qbuf[MBN_getUint64NumToPrecompute()] before calling this
MBN_DLL_API void mbn_precomputeG2(uint64_t *Qbuf, const mbnG2 *Q);
// allocate Qbuf[MCLBN_getUint64NumToPrecompute()] before calling this
MCLBN_DLL_API void mclBn_precomputeG2(uint64_t *Qbuf, const mclBnG2 *Q);
MBN_DLL_API void mbn_precomputedMillerLoop(mbnGT *f, const mbnG1 *P, const uint64_t *Qbuf);
MBN_DLL_API void mbn_precomputedMillerLoop2(mbnGT *f, const mbnG1 *P1, const uint64_t *Q1buf, const mbnG1 *P2, const uint64_t *Q2buf);
MCLBN_DLL_API void mclBn_precomputedMillerLoop(mclBnGT *f, const mclBnG1 *P, const uint64_t *Qbuf);
MCLBN_DLL_API void mclBn_precomputedMillerLoop2(mclBnGT *f, const mclBnG1 *P1, const uint64_t *Q1buf, const mclBnG1 *P2, const uint64_t *Q2buf);
#ifdef __cplusplus
}

@ -8,12 +8,12 @@ echo cl /c %CFLAGS% src\fp.cpp /Foobj\fp.obj
echo lib /nologo /OUT:lib\mcl.lib /nodefaultlib obj\fp.obj
lib /nologo /OUT:lib\mcl.lib /nodefaultlib obj\fp.obj
echo cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c256.obj /DMBN_FP_UNIT_SIZE=4
cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c256.obj /DMBN_FP_UNIT_SIZE=4
echo cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c256.obj /D"MCLBN_OP_UNIT_SIZE=4"
cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c256.obj /D"MCLBN_OP_UNIT_SIZE=4"
echo link /nologo /DLL /OUT:bin\mclbn256.dll obj\bn_c256.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn256.lib
link /nologo /DLL /OUT:bin\mclbn256.dll obj\bn_c256.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn256.lib
echo cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c384.obj /DMBN_FP_UNIT_SIZE=6
cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c384.obj /DMBN_FP_UNIT_SIZE=6
echo cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c384.obj /D"MCLBN_OP_UNIT_SIZE=6"
cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c384.obj /D"MCLBN_OP_UNIT_SIZE=6"
echo link /nologo /DLL /OUT:bin\mclbn384.dll obj\bn_c384.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn384.lib
link /nologo /DLL /OUT:bin\mclbn384.dll obj\bn_c384.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn384.lib

@ -1,5 +1,5 @@
#define MBN_DLL_EXPORT
#define MBN_DEFINE_STRUCT
#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 +9,7 @@ static std::random_device g_rg;
static cybozu::RandomGenerator g_rg;
#endif
#if MBN_FP_UNIT_SIZE == 4
#if MCLBN_OP_UNIT_SIZE == 4
#include <mcl/bn256.hpp>
using namespace mcl::bn256;
#else
@ -19,17 +19,17 @@ using namespace mcl::bn384;
static FILE *g_fp = NULL;
static Fr *cast(mbnFr *p) { return reinterpret_cast<Fr*>(p); }
static const Fr *cast(const mbnFr *p) { return reinterpret_cast<const Fr*>(p); }
static Fr *cast(mclBnFr *p) { return reinterpret_cast<Fr*>(p); }
static const Fr *cast(const mclBnFr *p) { return reinterpret_cast<const Fr*>(p); }
static G1 *cast(mbnG1 *p) { return reinterpret_cast<G1*>(p); }
static const G1 *cast(const mbnG1 *p) { return reinterpret_cast<const G1*>(p); }
static G1 *cast(mclBnG1 *p) { return reinterpret_cast<G1*>(p); }
static const G1 *cast(const mclBnG1 *p) { return reinterpret_cast<const G1*>(p); }
static G2 *cast(mbnG2 *p) { return reinterpret_cast<G2*>(p); }
static const G2 *cast(const mbnG2 *p) { return reinterpret_cast<const G2*>(p); }
static G2 *cast(mclBnG2 *p) { return reinterpret_cast<G2*>(p); }
static const G2 *cast(const mclBnG2 *p) { return reinterpret_cast<const G2*>(p); }
static Fp12 *cast(mbnGT *p) { return reinterpret_cast<Fp12*>(p); }
static const Fp12 *cast(const mbnGT *p) { return reinterpret_cast<const Fp12*>(p); }
static Fp12 *cast(mclBnGT *p) { return reinterpret_cast<Fp12*>(p); }
static const Fp12 *cast(const mclBnGT *p) { return reinterpret_cast<const Fp12*>(p); }
static Fp6 *cast(uint64_t *p) { return reinterpret_cast<Fp6*>(p); }
static const Fp6 *cast(const uint64_t *p) { return reinterpret_cast<const Fp6*>(p); }
@ -85,7 +85,7 @@ int deserialize(T *x, const void *buf, size_t bufSize, int ioMode, const char *m
return -1;
}
int mbn_setErrFile(const char *name)
int mclBn_setErrFile(const char *name)
{
int ret = closeErrFile();
if (name == NULL || *name == '\0') {
@ -104,31 +104,31 @@ int mbn_setErrFile(const char *name)
#endif
}
int mbn_init(int curve, int maxUnitSize)
int mclBn_init(int curve, int maxUnitSize)
try
{
if (maxUnitSize != MBN_FP_UNIT_SIZE) {
if (g_fp) fprintf(g_fp, "mbn_init:maxUnitSize is mismatch %d %d\n", maxUnitSize, MBN_FP_UNIT_SIZE);
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);
return -1;
}
mcl::bn::CurveParam cp;
switch (curve) {
case mbn_curveFp254BNb:
case mclBn_curveFp254BNb:
cp = mcl::bn::CurveFp254BNb;
break;
#if MBN_FP_UNIT_SIZE == 6
case mbn_curveFp382_1:
#if MCLBN_OP_UNIT_SIZE == 6
case mclBn_curveFp382_1:
cp = mcl::bn::CurveFp382_1;
break;
case mbn_curveFp382_2:
case mclBn_curveFp382_2:
cp = mcl::bn::CurveFp382_2;
break;
#endif
default:
if (g_fp) fprintf(g_fp, "MBN_init:not supported curve %d\n", curve);
if (g_fp) fprintf(g_fp, "MCLBN_init:not supported curve %d\n", curve);
return -1;
}
#if MBN_FP_UNIT_SIZE == 4
#if MCLBN_OP_UNIT_SIZE == 4
bn256init(cp);
#else
bn384init(cp);
@ -141,128 +141,128 @@ int mbn_init(int curve, int maxUnitSize)
////////////////////////////////////////////////
// set zero
void mbnFr_clear(mbnFr *x)
void mclBnFr_clear(mclBnFr *x)
{
cast(x)->clear();
}
// set x to y
void mbnFr_setInt(mbnFr *y, int x)
void mclBnFr_setInt(mclBnFr *y, int x)
{
*cast(y) = x;
}
int mbnFr_setStr(mbnFr *x, const char *buf, size_t bufSize, int ioMode)
int mclBnFr_setStr(mclBnFr *x, const char *buf, size_t bufSize, int ioMode)
{
return deserialize(x, buf, bufSize, ioMode, "mbnFr_setStr", false);
return deserialize(x, buf, bufSize, ioMode, "mclBnFr_setStr", false);
}
int mbnFr_setLittleEndian(mbnFr *x, const void *buf, size_t bufSize)
int mclBnFr_setLittleEndian(mclBnFr *x, const void *buf, size_t bufSize)
{
const size_t byteSize = cast(x)->getByteSize();
if (bufSize > byteSize) bufSize = byteSize;
std::string s((const char *)buf, bufSize);
s.resize(byteSize);
return deserialize(x, s.c_str(), s.size(), mcl::IoFixedSizeByteSeq, "mbnFr_setLittleEndian", false);
return deserialize(x, s.c_str(), s.size(), mcl::IoFixedSizeByteSeq, "mclBnFr_setLittleEndian", false);
}
int mbnFr_deserialize(mbnFr *x, const char *buf, size_t bufSize)
int mclBnFr_deserialize(mclBnFr *x, const char *buf, size_t bufSize)
{
return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "mbnFr_deserialize", false);
return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "mclBnFr_deserialize", false);
}
// return 1 if true
int mbnFr_isValid(const mbnFr *x)
int mclBnFr_isValid(const mclBnFr *x)
{
return cast(x)->isValid();
}
int mbnFr_isEqual(const mbnFr *x, const mbnFr *y)
int mclBnFr_isEqual(const mclBnFr *x, const mclBnFr *y)
{
return *cast(x) == *cast(y);
}
int mbnFr_isZero(const mbnFr *x)
int mclBnFr_isZero(const mclBnFr *x)
{
return cast(x)->isZero();
}
int mbnFr_isOne(const mbnFr *x)
int mclBnFr_isOne(const mclBnFr *x)
{
return cast(x)->isOne();
}
void mbnFr_setByCSPRNG(mbnFr *x)
void mclBnFr_setByCSPRNG(mclBnFr *x)
{
cast(x)->setRand(g_rg);
}
// hash(buf) and set x
int mbnFr_setHashOf(mbnFr *x, const void *buf, size_t bufSize)
int mclBnFr_setHashOf(mclBnFr *x, const void *buf, size_t bufSize)
try
{
cast(x)->setHashOf(buf, bufSize);
return 0;
} catch (std::exception& e) {
if (g_fp) fprintf(g_fp, "mbnFr_setHashOf %s\n", e.what());
if (g_fp) fprintf(g_fp, "mclBnFr_setHashOf %s\n", e.what());
return -1;
}
size_t mbnFr_getStr(char *buf, size_t maxBufSize, const mbnFr *x, int ioMode)
size_t mclBnFr_getStr(char *buf, size_t maxBufSize, const mclBnFr *x, int ioMode)
{
return serialize(buf, maxBufSize, x, ioMode, "mbnFr_getStr", false);
return serialize(buf, maxBufSize, x, ioMode, "mclBnFr_getStr", false);
}
size_t mbnFr_serialize(void *buf, size_t maxBufSize, const mbnFr *x)
size_t mclBnFr_serialize(void *buf, size_t maxBufSize, const mclBnFr *x)
{
return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "mbnFr_serialize", false);
return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "mclBnFr_serialize", false);
}
void mbnFr_neg(mbnFr *y, const mbnFr *x)
void mclBnFr_neg(mclBnFr *y, const mclBnFr *x)
{
Fr::neg(*cast(y), *cast(x));
}
void mbnFr_inv(mbnFr *y, const mbnFr *x)
void mclBnFr_inv(mclBnFr *y, const mclBnFr *x)
{
Fr::inv(*cast(y), *cast(x));
}
void mbnFr_add(mbnFr *z, const mbnFr *x, const mbnFr *y)
void mclBnFr_add(mclBnFr *z, const mclBnFr *x, const mclBnFr *y)
{
Fr::add(*cast(z),*cast(x), *cast(y));
}
void mbnFr_sub(mbnFr *z, const mbnFr *x, const mbnFr *y)
void mclBnFr_sub(mclBnFr *z, const mclBnFr *x, const mclBnFr *y)
{
Fr::sub(*cast(z),*cast(x), *cast(y));
}
void mbnFr_mul(mbnFr *z, const mbnFr *x, const mbnFr *y)
void mclBnFr_mul(mclBnFr *z, const mclBnFr *x, const mclBnFr *y)
{
Fr::mul(*cast(z),*cast(x), *cast(y));
}
void mbnFr_div(mbnFr *z, const mbnFr *x, const mbnFr *y)
void mclBnFr_div(mclBnFr *z, const mclBnFr *x, const mclBnFr *y)
{
Fr::div(*cast(z),*cast(x), *cast(y));
}
////////////////////////////////////////////////
// set zero
void mbnG1_clear(mbnG1 *x)
void mclBnG1_clear(mclBnG1 *x)
{
cast(x)->clear();
}
int mbnG1_setStr(mbnG1 *x, const char *buf, size_t bufSize, int ioMode)
int mclBnG1_setStr(mclBnG1 *x, const char *buf, size_t bufSize, int ioMode)
{
return deserialize(x, buf, bufSize, ioMode, "mbnG1_setStr", false);
return deserialize(x, buf, bufSize, ioMode, "mclBnG1_setStr", false);
}
// return 1 if true
int mbnG1_isValid(const mbnG1 *x)
int mclBnG1_isValid(const mclBnG1 *x)
{
return cast(x)->isValid();
}
int mbnG1_isEqual(const mbnG1 *x, const mbnG1 *y)
int mclBnG1_isEqual(const mclBnG1 *x, const mclBnG1 *y)
{
return *cast(x) == *cast(y);
}
int mbnG1_isZero(const mbnG1 *x)
int mclBnG1_isZero(const mclBnG1 *x)
{
return cast(x)->isZero();
}
int mbnG1_hashAndMapTo(mbnG1 *x, const void *buf, size_t bufSize)
int mclBnG1_hashAndMapTo(mclBnG1 *x, const void *buf, size_t bufSize)
try
{
Fp y;
@ -270,68 +270,68 @@ int mbnG1_hashAndMapTo(mbnG1 *x, const void *buf, size_t bufSize)
BN::mapToG1(*cast(x), y);
return 0;
} catch (std::exception& e) {
if (g_fp) fprintf(g_fp, "mbnG1_hashAndMapTo %s\n", e.what());
if (g_fp) fprintf(g_fp, "mclBnG1_hashAndMapTo %s\n", e.what());
return 1;
}
size_t mbnG1_getStr(char *buf, size_t maxBufSize, const mbnG1 *x, int ioMode)
size_t mclBnG1_getStr(char *buf, size_t maxBufSize, const mclBnG1 *x, int ioMode)
{
return serialize(buf, maxBufSize, x, ioMode, "mbnG1_getStr", false);
return serialize(buf, maxBufSize, x, ioMode, "mclBnG1_getStr", false);
}
size_t mbnG1_serialize(void *buf, size_t maxBufSize, const mbnG1 *x)
size_t mclBnG1_serialize(void *buf, size_t maxBufSize, const mclBnG1 *x)
{
return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "mbnG1_serialize", false);
return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "mclBnG1_serialize", false);
}
void mbnG1_neg(mbnG1 *y, const mbnG1 *x)
void mclBnG1_neg(mclBnG1 *y, const mclBnG1 *x)
{
G1::neg(*cast(y), *cast(x));
}
void mbnG1_dbl(mbnG1 *y, const mbnG1 *x)
void mclBnG1_dbl(mclBnG1 *y, const mclBnG1 *x)
{
G1::dbl(*cast(y), *cast(x));
}
void mbnG1_add(mbnG1 *z, const mbnG1 *x, const mbnG1 *y)
void mclBnG1_add(mclBnG1 *z, const mclBnG1 *x, const mclBnG1 *y)
{
G1::add(*cast(z),*cast(x), *cast(y));
}
void mbnG1_sub(mbnG1 *z, const mbnG1 *x, const mbnG1 *y)
void mclBnG1_sub(mclBnG1 *z, const mclBnG1 *x, const mclBnG1 *y)
{
G1::sub(*cast(z),*cast(x), *cast(y));
}
void mbnG1_mul(mbnG1 *z, const mbnG1 *x, const mbnFr *y)
void mclBnG1_mul(mclBnG1 *z, const mclBnG1 *x, const mclBnFr *y)
{
G1::mul(*cast(z),*cast(x), *cast(y));
}
////////////////////////////////////////////////
// set zero
void mbnG2_clear(mbnG2 *x)
void mclBnG2_clear(mclBnG2 *x)
{
cast(x)->clear();
}
int mbnG2_setStr(mbnG2 *x, const char *buf, size_t bufSize, int ioMode)
int mclBnG2_setStr(mclBnG2 *x, const char *buf, size_t bufSize, int ioMode)
{
return deserialize(x, buf, bufSize, ioMode, "mbnG2_setStr", false);
return deserialize(x, buf, bufSize, ioMode, "mclBnG2_setStr", false);
}
// return 1 if true
int mbnG2_isValid(const mbnG2 *x)
int mclBnG2_isValid(const mclBnG2 *x)
{
return cast(x)->isValid();
}
int mbnG2_isEqual(const mbnG2 *x, const mbnG2 *y)
int mclBnG2_isEqual(const mclBnG2 *x, const mclBnG2 *y)
{
return *cast(x) == *cast(y);
}
int mbnG2_isZero(const mbnG2 *x)
int mclBnG2_isZero(const mclBnG2 *x)
{
return cast(x)->isZero();
}
int mbnG2_hashAndMapTo(mbnG2 *x, const void *buf, size_t bufSize)
int mclBnG2_hashAndMapTo(mclBnG2 *x, const void *buf, size_t bufSize)
try
{
Fp y;
@ -339,134 +339,134 @@ int mbnG2_hashAndMapTo(mbnG2 *x, const void *buf, size_t bufSize)
BN::mapToG2(*cast(x), Fp2(y, 0));
return 0;
} catch (std::exception& e) {
if (g_fp) fprintf(g_fp, "mbnG2_hashAndMapTo %s\n", e.what());
if (g_fp) fprintf(g_fp, "mclBnG2_hashAndMapTo %s\n", e.what());
return 1;
}
size_t mbnG2_getStr(char *buf, size_t maxBufSize, const mbnG2 *x, int ioMode)
size_t mclBnG2_getStr(char *buf, size_t maxBufSize, const mclBnG2 *x, int ioMode)
{
return serialize(buf, maxBufSize, x, ioMode, "mbnG2_getStr", false);
return serialize(buf, maxBufSize, x, ioMode, "mclBnG2_getStr", false);
}
void mbnG2_neg(mbnG2 *y, const mbnG2 *x)
void mclBnG2_neg(mclBnG2 *y, const mclBnG2 *x)
{
G2::neg(*cast(y), *cast(x));
}
void mbnG2_dbl(mbnG2 *y, const mbnG2 *x)
void mclBnG2_dbl(mclBnG2 *y, const mclBnG2 *x)
{
G2::dbl(*cast(y), *cast(x));
}
void mbnG2_add(mbnG2 *z, const mbnG2 *x, const mbnG2 *y)
void mclBnG2_add(mclBnG2 *z, const mclBnG2 *x, const mclBnG2 *y)
{
G2::add(*cast(z),*cast(x), *cast(y));
}
void mbnG2_sub(mbnG2 *z, const mbnG2 *x, const mbnG2 *y)
void mclBnG2_sub(mclBnG2 *z, const mclBnG2 *x, const mclBnG2 *y)
{
G2::sub(*cast(z),*cast(x), *cast(y));
}
void mbnG2_mul(mbnG2 *z, const mbnG2 *x, const mbnFr *y)
void mclBnG2_mul(mclBnG2 *z, const mclBnG2 *x, const mclBnFr *y)
{
G2::mul(*cast(z),*cast(x), *cast(y));
}
////////////////////////////////////////////////
// set zero
void mbnGT_clear(mbnGT *x)
void mclBnGT_clear(mclBnGT *x)
{
cast(x)->clear();
}
int mbnGT_setStr(mbnGT *x, const char *buf, size_t bufSize, int ioMode)
int mclBnGT_setStr(mclBnGT *x, const char *buf, size_t bufSize, int ioMode)
{
return deserialize(x, buf, bufSize, ioMode, "mbnGT_setStr", false);
return deserialize(x, buf, bufSize, ioMode, "mclBnGT_setStr", false);
}
int mbnGT_deserialize(mbnGT *x, const char *buf, size_t bufSize)
int mclBnGT_deserialize(mclBnGT *x, const char *buf, size_t bufSize)
{
return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "mbnGT_deserialize", false);
return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "mclBnGT_deserialize", false);
}
// return 1 if true
int mbnGT_isEqual(const mbnGT *x, const mbnGT *y)
int mclBnGT_isEqual(const mclBnGT *x, const mclBnGT *y)
{
return *cast(x) == *cast(y);
}
int mbnGT_isZero(const mbnGT *x)
int mclBnGT_isZero(const mclBnGT *x)
{
return cast(x)->isZero();
}
int mbnGT_isOne(const mbnGT *x)
int mclBnGT_isOne(const mclBnGT *x)
{
return cast(x)->isOne();
}
size_t mbnGT_getStr(char *buf, size_t maxBufSize, const mbnGT *x, int ioMode)
size_t mclBnGT_getStr(char *buf, size_t maxBufSize, const mclBnGT *x, int ioMode)
{
return serialize(buf, maxBufSize, x, ioMode, "mbnGT_getStr", false);
return serialize(buf, maxBufSize, x, ioMode, "mclBnGT_getStr", false);
}
size_t mbnGT_serialize(void *buf, size_t maxBufSize, const mbnGT *x)
size_t mclBnGT_serialize(void *buf, size_t maxBufSize, const mclBnGT *x)
{
return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "mbnGT_serialize", false);
return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "mclBnGT_serialize", false);
}
void mbnGT_neg(mbnGT *y, const mbnGT *x)
void mclBnGT_neg(mclBnGT *y, const mclBnGT *x)
{
Fp12::neg(*cast(y), *cast(x));
}
void mbnGT_inv(mbnGT *y, const mbnGT *x)
void mclBnGT_inv(mclBnGT *y, const mclBnGT *x)
{
Fp12::inv(*cast(y), *cast(x));
}
void mbnGT_add(mbnGT *z, const mbnGT *x, const mbnGT *y)
void mclBnGT_add(mclBnGT *z, const mclBnGT *x, const mclBnGT *y)
{
Fp12::add(*cast(z),*cast(x), *cast(y));
}
void mbnGT_sub(mbnGT *z, const mbnGT *x, const mbnGT *y)
void mclBnGT_sub(mclBnGT *z, const mclBnGT *x, const mclBnGT *y)
{
Fp12::sub(*cast(z),*cast(x), *cast(y));
}
void mbnGT_mul(mbnGT *z, const mbnGT *x, const mbnGT *y)
void mclBnGT_mul(mclBnGT *z, const mclBnGT *x, const mclBnGT *y)
{
Fp12::mul(*cast(z),*cast(x), *cast(y));
}
void mbnGT_div(mbnGT *z, const mbnGT *x, const mbnGT *y)
void mclBnGT_div(mclBnGT *z, const mclBnGT *x, const mclBnGT *y)
{
Fp12::div(*cast(z),*cast(x), *cast(y));
}
void mbnGT_pow(mbnGT *z, const mbnGT *x, const mbnFr *y)
void mclBnGT_pow(mclBnGT *z, const mclBnGT *x, const mclBnFr *y)
{
Fp12::pow(*cast(z), *cast(x), *cast(y));
}
void mbn_pairing(mbnGT *z, const mbnG1 *x, const mbnG2 *y)
void mclBn_pairing(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y)
{
BN::pairing(*cast(z), *cast(x), *cast(y));
}
void mbn_finalExp(mbnGT *y, const mbnGT *x)
void mclBn_finalExp(mclBnGT *y, const mclBnGT *x)
{
BN::finalExp(*cast(y), *cast(x));
}
void mbn_millerLoop(mbnGT *z, const mbnG1 *x, const mbnG2 *y)
void mclBn_millerLoop(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y)
{
BN::millerLoop(*cast(z), *cast(x), *cast(y));
}
int mbn_getUint64NumToPrecompute(void)
int mclBn_getUint64NumToPrecompute(void)
{
return int(BN::param.precomputedQcoeffSize * sizeof(Fp6) / sizeof(uint64_t));
}
void mbn_precomputeG2(uint64_t *Qbuf, const mbnG2 *Q)
void mclBn_precomputeG2(uint64_t *Qbuf, const mclBnG2 *Q)
{
BN::precomputeG2(cast(Qbuf), *cast(Q));
}
void mbn_precomputedMillerLoop(mbnGT *f, const mbnG1 *P, const uint64_t *Qbuf)
void mclBn_precomputedMillerLoop(mclBnGT *f, const mclBnG1 *P, const uint64_t *Qbuf)
{
BN::precomputedMillerLoop(*cast(f), *cast(P), cast(Qbuf));
}
void mbn_precomputedMillerLoop2(mbnGT *f, const mbnG1 *P1, const uint64_t *Q1buf, const mbnG1 *P2, const uint64_t *Q2buf)
void mclBn_precomputedMillerLoop2(mclBnGT *f, const mclBnG1 *P1, const uint64_t *Q1buf, const mclBnG1 *P2, const uint64_t *Q2buf)
{
BN::precomputedMillerLoop2(*cast(f), *cast(P1), cast(Q1buf), *cast(P2), cast(Q2buf));
}

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

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

@ -19,298 +19,298 @@ std::ostream dump(std::ostream& os, const uint64_t (&x)[N])
CYBOZU_TEST_AUTO(init)
{
int ret;
CYBOZU_TEST_EQUAL(sizeof(mbnFr), sizeof(Fr));
CYBOZU_TEST_EQUAL(sizeof(mbnG1), sizeof(G1));
CYBOZU_TEST_EQUAL(sizeof(mbnG2), sizeof(G2));
CYBOZU_TEST_EQUAL(sizeof(mbnGT), sizeof(Fp12));
CYBOZU_TEST_EQUAL(sizeof(mclBnFr), sizeof(Fr));
CYBOZU_TEST_EQUAL(sizeof(mclBnG1), sizeof(G1));
CYBOZU_TEST_EQUAL(sizeof(mclBnG2), sizeof(G2));
CYBOZU_TEST_EQUAL(sizeof(mclBnGT), sizeof(Fp12));
ret = mbn_setErrFile("stderr");
ret = mclBn_setErrFile("stderr");
CYBOZU_TEST_EQUAL(ret, 0);
#if MBN_FP_UNIT_SIZE == 4
printf("test MBN_curveFp254BNb %d\n", MBN_FP_UNIT_SIZE);
ret = mbn_init(mbn_curveFp254BNb, MBN_FP_UNIT_SIZE);
#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);
#else
printf("test MBN_curveFp382_1 %d\n", MBN_FP_UNIT_SIZE);
ret = mbn_init(mbn_curveFp382_1, MBN_FP_UNIT_SIZE);
printf("test MCLBN_curveFp382_1 %d\n", MCLBN_OP_UNIT_SIZE);
ret = mclBn_init(mclBn_curveFp382_1, MCLBN_OP_UNIT_SIZE);
#endif
CYBOZU_TEST_EQUAL(ret, 0);
}
CYBOZU_TEST_AUTO(Fr)
{
mbnFr x, y;
mclBnFr x, y;
memset(&x, 0xff, sizeof(x));
CYBOZU_TEST_ASSERT(!mbnFr_isValid(&x));
CYBOZU_TEST_ASSERT(!mclBnFr_isValid(&x));
memset(&x, 1, sizeof(x));
CYBOZU_TEST_ASSERT(mbnFr_isValid(&x));
CYBOZU_TEST_ASSERT(!mbnFr_isZero(&x));
CYBOZU_TEST_ASSERT(mclBnFr_isValid(&x));
CYBOZU_TEST_ASSERT(!mclBnFr_isZero(&x));
mbnFr_clear(&x);
CYBOZU_TEST_ASSERT(mbnFr_isZero(&x));
mclBnFr_clear(&x);
CYBOZU_TEST_ASSERT(mclBnFr_isZero(&x));
mbnFr_setInt(&x, 1);
CYBOZU_TEST_ASSERT(mbnFr_isOne(&x));
mclBnFr_setInt(&x, 1);
CYBOZU_TEST_ASSERT(mclBnFr_isOne(&x));
mbnFr_setInt(&y, -1);
CYBOZU_TEST_ASSERT(!mbnFr_isEqual(&x, &y));
mclBnFr_setInt(&y, -1);
CYBOZU_TEST_ASSERT(!mclBnFr_isEqual(&x, &y));
y = x;
CYBOZU_TEST_ASSERT(mbnFr_isEqual(&x, &y));
CYBOZU_TEST_ASSERT(mclBnFr_isEqual(&x, &y));
mbnFr_setHashOf(&x, "", 0);
mbnFr_setHashOf(&y, "abc", 3);
CYBOZU_TEST_ASSERT(!mbnFr_isEqual(&x, &y));
mbnFr_setHashOf(&x, "abc", 3);
CYBOZU_TEST_ASSERT(mbnFr_isEqual(&x, &y));
mclBnFr_setHashOf(&x, "", 0);
mclBnFr_setHashOf(&y, "abc", 3);
CYBOZU_TEST_ASSERT(!mclBnFr_isEqual(&x, &y));
mclBnFr_setHashOf(&x, "abc", 3);
CYBOZU_TEST_ASSERT(mclBnFr_isEqual(&x, &y));
char buf[1024];
mbnFr_setInt(&x, 12345678);
mclBnFr_setInt(&x, 12345678);
size_t size;
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_EQUAL(size, 8);
CYBOZU_TEST_EQUAL(buf, "12345678");
mbnFr_setInt(&x, -7654321);
mbnFr_neg(&x, &x);
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
mclBnFr_setInt(&x, -7654321);
mclBnFr_neg(&x, &x);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_EQUAL(size, 7);
CYBOZU_TEST_EQUAL(buf, "7654321");
mbnFr_setInt(&y, 123 - 7654321);
mbnFr_add(&x, &x, &y);
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
mclBnFr_setInt(&y, 123 - 7654321);
mclBnFr_add(&x, &x, &y);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_EQUAL(size, 3);
CYBOZU_TEST_EQUAL(buf, "123");
mbnFr_setInt(&y, 100);
mbnFr_sub(&x, &x, &y);
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
mclBnFr_setInt(&y, 100);
mclBnFr_sub(&x, &x, &y);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_EQUAL(size, 2);
CYBOZU_TEST_EQUAL(buf, "23");
mbnFr_mul(&x, &x, &y);
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
mclBnFr_mul(&x, &x, &y);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_EQUAL(size, 4);
CYBOZU_TEST_EQUAL(buf, "2300");
mbnFr_div(&x, &x, &y);
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
mclBnFr_div(&x, &x, &y);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_EQUAL(size, 2);
CYBOZU_TEST_EQUAL(buf, "23");
const char *s = "12345678901234567";
CYBOZU_TEST_ASSERT(!mbnFr_setStr(&x, s, strlen(s), 10));
CYBOZU_TEST_ASSERT(!mclBnFr_setStr(&x, s, strlen(s), 10));
s = "20000000000000000";
CYBOZU_TEST_ASSERT(!mbnFr_setStr(&y, s, strlen(s), 10));
mbnFr_add(&x, &x, &y);
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_ASSERT(!mclBnFr_setStr(&y, s, strlen(s), 10));
mclBnFr_add(&x, &x, &y);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_EQUAL(size, 17);
CYBOZU_TEST_EQUAL(buf, "32345678901234567");
mbnFr_setInt(&x, 1);
mbnFr_neg(&x, &x);
size = mbnFr_getStr(buf, sizeof(buf), &x, 10);
mclBnFr_setInt(&x, 1);
mclBnFr_neg(&x, &x);
size = mclBnFr_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_ASSERT(size > 0);
CYBOZU_TEST_EQUAL(size, strlen(buf));
CYBOZU_TEST_ASSERT(!mbnFr_setStr(&y, buf, size, 10));
CYBOZU_TEST_ASSERT(mbnFr_isEqual(&x, &y));
CYBOZU_TEST_ASSERT(!mclBnFr_setStr(&y, buf, size, 10));
CYBOZU_TEST_ASSERT(mclBnFr_isEqual(&x, &y));
}
CYBOZU_TEST_AUTO(G1)
{
mbnG1 x, y, z;
mclBnG1 x, y, z;
memset(&x, 0xff, sizeof(x));
CYBOZU_TEST_ASSERT(!mbnG1_isValid(&x));
mbnG1_clear(&x);
CYBOZU_TEST_ASSERT(mbnG1_isValid(&x));
CYBOZU_TEST_ASSERT(mbnG1_isZero(&x));
CYBOZU_TEST_ASSERT(!mclBnG1_isValid(&x));
mclBnG1_clear(&x);
CYBOZU_TEST_ASSERT(mclBnG1_isValid(&x));
CYBOZU_TEST_ASSERT(mclBnG1_isZero(&x));
CYBOZU_TEST_ASSERT(!mbnG1_hashAndMapTo(&y, "abc", 3));
CYBOZU_TEST_ASSERT(!mclBnG1_hashAndMapTo(&y, "abc", 3));
char buf[1024];
size_t size;
size = mbnG1_getStr(buf, sizeof(buf), &x, 10);
size = mclBnG1_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_ASSERT(size > 0);
CYBOZU_TEST_EQUAL(size, strlen(buf));
CYBOZU_TEST_ASSERT(!mbnG1_setStr(&y, buf, strlen(buf), 10));
CYBOZU_TEST_ASSERT(mbnG1_isEqual(&x, &y));
mbnG1_neg(&x, &x);
mbnG1_add(&x, &x, &y);
CYBOZU_TEST_ASSERT(mbnG1_isZero(&x));
mbnG1_dbl(&x, &y); // x = 2y
mbnG1_add(&z, &y, &y);
CYBOZU_TEST_ASSERT(mbnG1_isEqual(&x, &z));
mbnG1_add(&z, &z, &y); // z = 3y
mbnFr n;
mbnFr_setInt(&n, 3);
mbnG1_mul(&x, &y, &n); // x = 3y
CYBOZU_TEST_ASSERT(mbnG1_isEqual(&x, &z));
mbnG1_sub(&x, &x, &y); // x = 2y
mbnFr_setInt(&n, 2);
mbnG1_mul(&z, &y, &n); // z = 2y
CYBOZU_TEST_ASSERT(mbnG1_isEqual(&x, &z));
CYBOZU_TEST_ASSERT(!mclBnG1_setStr(&y, buf, strlen(buf), 10));
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&x, &y));
mclBnG1_neg(&x, &x);
mclBnG1_add(&x, &x, &y);
CYBOZU_TEST_ASSERT(mclBnG1_isZero(&x));
mclBnG1_dbl(&x, &y); // x = 2y
mclBnG1_add(&z, &y, &y);
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&x, &z));
mclBnG1_add(&z, &z, &y); // z = 3y
mclBnFr n;
mclBnFr_setInt(&n, 3);
mclBnG1_mul(&x, &y, &n); // x = 3y
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&x, &z));
mclBnG1_sub(&x, &x, &y); // x = 2y
mclBnFr_setInt(&n, 2);
mclBnG1_mul(&z, &y, &n); // z = 2y
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&x, &z));
}
CYBOZU_TEST_AUTO(G2)
{
mbnG2 x, y, z;
mclBnG2 x, y, z;
memset(&x, 0xff, sizeof(x));
CYBOZU_TEST_ASSERT(!mbnG2_isValid(&x));
mbnG2_clear(&x);
CYBOZU_TEST_ASSERT(mbnG2_isValid(&x));
CYBOZU_TEST_ASSERT(mbnG2_isZero(&x));
CYBOZU_TEST_ASSERT(!mclBnG2_isValid(&x));
mclBnG2_clear(&x);
CYBOZU_TEST_ASSERT(mclBnG2_isValid(&x));
CYBOZU_TEST_ASSERT(mclBnG2_isZero(&x));
CYBOZU_TEST_ASSERT(!mbnG2_hashAndMapTo(&x, "abc", 3));
CYBOZU_TEST_ASSERT(!mclBnG2_hashAndMapTo(&x, "abc", 3));
char buf[1024];
size_t size;
size = mbnG2_getStr(buf, sizeof(buf), &x, 10);
size = mclBnG2_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_ASSERT(size > 0);
CYBOZU_TEST_EQUAL(size, strlen(buf));
CYBOZU_TEST_ASSERT(!mbnG2_setStr(&y, buf, strlen(buf), 10));
CYBOZU_TEST_ASSERT(mbnG2_isEqual(&x, &y));
mbnG2_neg(&x, &x);
mbnG2_add(&x, &x, &y);
CYBOZU_TEST_ASSERT(mbnG2_isZero(&x));
mbnG2_dbl(&x, &y); // x = 2y
mbnG2_add(&z, &y, &y);
CYBOZU_TEST_ASSERT(mbnG2_isEqual(&x, &z));
mbnG2_add(&z, &z, &y); // z = 3y
mbnFr n;
mbnFr_setInt(&n, 3);
mbnG2_mul(&x, &y, &n); // x = 3y
CYBOZU_TEST_ASSERT(mbnG2_isEqual(&x, &z));
mbnG2_sub(&x, &x, &y); // x = 2y
mbnFr_setInt(&n, 2);
mbnG2_mul(&z, &y, &n); // z = 2y
CYBOZU_TEST_ASSERT(mbnG2_isEqual(&x, &z));
CYBOZU_TEST_ASSERT(!mclBnG2_setStr(&y, buf, strlen(buf), 10));
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&x, &y));
mclBnG2_neg(&x, &x);
mclBnG2_add(&x, &x, &y);
CYBOZU_TEST_ASSERT(mclBnG2_isZero(&x));
mclBnG2_dbl(&x, &y); // x = 2y
mclBnG2_add(&z, &y, &y);
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&x, &z));
mclBnG2_add(&z, &z, &y); // z = 3y
mclBnFr n;
mclBnFr_setInt(&n, 3);
mclBnG2_mul(&x, &y, &n); // x = 3y
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&x, &z));
mclBnG2_sub(&x, &x, &y); // x = 2y
mclBnFr_setInt(&n, 2);
mclBnG2_mul(&z, &y, &n); // z = 2y
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&x, &z));
}
CYBOZU_TEST_AUTO(GT)
{
mbnGT x, y, z;
mclBnGT x, y, z;
memset(&x, 1, sizeof(x));
CYBOZU_TEST_ASSERT(!mbnGT_isZero(&x));
CYBOZU_TEST_ASSERT(!mclBnGT_isZero(&x));
mbnGT_clear(&x);
CYBOZU_TEST_ASSERT(mbnGT_isZero(&x));
mclBnGT_clear(&x);
CYBOZU_TEST_ASSERT(mclBnGT_isZero(&x));
char buf[2048];
const char *s = "1 2 3 4 5 6 7 8 9 10 11 12";
size_t size;
CYBOZU_TEST_ASSERT(!mbnGT_setStr(&x,s , strlen(s), 10));
size = mbnGT_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_ASSERT(!mclBnGT_setStr(&x,s , strlen(s), 10));
size = mclBnGT_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_ASSERT(size > 0);
CYBOZU_TEST_EQUAL(size, strlen(buf));
CYBOZU_TEST_EQUAL(buf, s);
y = x;
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&x, &y));
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&x, &y));
s = "-1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12";
CYBOZU_TEST_ASSERT(!mbnGT_setStr(&z, s, strlen(s), 10));
size = mbnGT_getStr(buf, sizeof(buf), &z, 10);
CYBOZU_TEST_ASSERT(!mclBnGT_setStr(&z, s, strlen(s), 10));
size = mclBnGT_getStr(buf, sizeof(buf), &z, 10);
CYBOZU_TEST_ASSERT(size > 0);
CYBOZU_TEST_EQUAL(size, strlen(buf));
CYBOZU_TEST_ASSERT(!mbnGT_setStr(&y, buf, size, 10));
CYBOZU_TEST_ASSERT(!mclBnGT_setStr(&y, buf, size, 10));
mbnGT_neg(&z, &y);
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&x, &z));
mclBnGT_neg(&z, &y);
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&x, &z));
mbnGT_add(&y, &x, &y);
CYBOZU_TEST_ASSERT(mbnGT_isZero(&y));
mclBnGT_add(&y, &x, &y);
CYBOZU_TEST_ASSERT(mclBnGT_isZero(&y));
s = "2 0 0 0 0 0 0 0 0 0 0 0";
CYBOZU_TEST_ASSERT(!mbnGT_setStr(&y, s, strlen(s), 10));
mbnGT_mul(&z, &x, &y);
size = mbnGT_getStr(buf, sizeof(buf), &z, 10);
CYBOZU_TEST_ASSERT(!mclBnGT_setStr(&y, s, strlen(s), 10));
mclBnGT_mul(&z, &x, &y);
size = mclBnGT_getStr(buf, sizeof(buf), &z, 10);
CYBOZU_TEST_ASSERT(size > 0);
CYBOZU_TEST_EQUAL(size, strlen(buf));
CYBOZU_TEST_EQUAL(buf, "2 4 6 8 10 12 14 16 18 20 22 24");
mbnGT_div(&z, &z, &y);
size = mbnGT_getStr(buf, sizeof(buf), &x, 10);
mclBnGT_div(&z, &z, &y);
size = mclBnGT_getStr(buf, sizeof(buf), &x, 10);
CYBOZU_TEST_ASSERT(size > 0);
CYBOZU_TEST_EQUAL(size, strlen(buf));
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&x, &z));
mbnFr n;
mbnFr_setInt(&n, 3);
mbnGT_pow(&z, &x, &n);
mbnGT_mul(&y, &x, &x);
mbnGT_mul(&y, &y, &x);
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&y, &z));
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&x, &z));
mclBnFr n;
mclBnFr_setInt(&n, 3);
mclBnGT_pow(&z, &x, &n);
mclBnGT_mul(&y, &x, &x);
mclBnGT_mul(&y, &y, &x);
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&y, &z));
}
CYBOZU_TEST_AUTO(pairing)
{
mbnFr a, b, ab;
mbnFr_setInt(&a, 123);
mbnFr_setInt(&b, 456);
mbnFr_mul(&ab, &a, &b);
mbnG1 P, aP;
mbnG2 Q, bQ;
mbnGT e, e1, e2;
CYBOZU_TEST_ASSERT(!mbnG1_hashAndMapTo(&P, "1", 1));
CYBOZU_TEST_ASSERT(!mbnG2_hashAndMapTo(&Q, "1", 1));
mbnG1_mul(&aP, &P, &a);
mbnG2_mul(&bQ, &Q, &b);
mbn_pairing(&e, &P, &Q);
mbnGT_pow(&e1, &e, &a);
mbn_pairing(&e2, &aP, &Q);
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&e1, &e2));
mbnGT_pow(&e1, &e, &b);
mbn_pairing(&e2, &P, &bQ);
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&e1, &e2));
mclBnFr a, b, ab;
mclBnFr_setInt(&a, 123);
mclBnFr_setInt(&b, 456);
mclBnFr_mul(&ab, &a, &b);
mclBnG1 P, aP;
mclBnG2 Q, bQ;
mclBnGT e, e1, e2;
CYBOZU_TEST_ASSERT(!mclBnG1_hashAndMapTo(&P, "1", 1));
CYBOZU_TEST_ASSERT(!mclBnG2_hashAndMapTo(&Q, "1", 1));
mclBnG1_mul(&aP, &P, &a);
mclBnG2_mul(&bQ, &Q, &b);
mclBn_pairing(&e, &P, &Q);
mclBnGT_pow(&e1, &e, &a);
mclBn_pairing(&e2, &aP, &Q);
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&e1, &e2));
mclBnGT_pow(&e1, &e, &b);
mclBn_pairing(&e2, &P, &bQ);
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&e1, &e2));
}
CYBOZU_TEST_AUTO(precomputed)
{
mbnG1 P1, P2;
mbnG2 Q1, Q2;
CYBOZU_TEST_ASSERT(!mbnG1_hashAndMapTo(&P1, "1", 1));
CYBOZU_TEST_ASSERT(!mbnG1_hashAndMapTo(&P2, "123", 3));
CYBOZU_TEST_ASSERT(!mbnG2_hashAndMapTo(&Q1, "1", 1));
CYBOZU_TEST_ASSERT(!mbnG2_hashAndMapTo(&Q2, "2", 1));
const int size = mbn_getUint64NumToPrecompute();
mclBnG1 P1, P2;
mclBnG2 Q1, Q2;
CYBOZU_TEST_ASSERT(!mclBnG1_hashAndMapTo(&P1, "1", 1));
CYBOZU_TEST_ASSERT(!mclBnG1_hashAndMapTo(&P2, "123", 3));
CYBOZU_TEST_ASSERT(!mclBnG2_hashAndMapTo(&Q1, "1", 1));
CYBOZU_TEST_ASSERT(!mclBnG2_hashAndMapTo(&Q2, "2", 1));
const int size = mclBn_getUint64NumToPrecompute();
std::vector<uint64_t> Q1buf, Q2buf;
Q1buf.resize(size);
Q2buf.resize(size);
mbn_precomputeG2(Q1buf.data(), &Q1);
mbn_precomputeG2(Q2buf.data(), &Q2);
mclBn_precomputeG2(Q1buf.data(), &Q1);
mclBn_precomputeG2(Q2buf.data(), &Q2);
mbnGT e1, e2, f1, f2, f3;
mbn_pairing(&e1, &P1, &Q1);
mbn_precomputedMillerLoop(&f1, &P1, Q1buf.data());
mbn_finalExp(&f1, &f1);
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&e1, &f1));
mclBnGT e1, e2, f1, f2, f3;
mclBn_pairing(&e1, &P1, &Q1);
mclBn_precomputedMillerLoop(&f1, &P1, Q1buf.data());
mclBn_finalExp(&f1, &f1);
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&e1, &f1));
mbn_pairing(&e2, &P2, &Q2);
mbn_precomputedMillerLoop(&f2, &P2, Q2buf.data());
mbn_finalExp(&f2, &f2);
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&e2, &f2));
mclBn_pairing(&e2, &P2, &Q2);
mclBn_precomputedMillerLoop(&f2, &P2, Q2buf.data());
mclBn_finalExp(&f2, &f2);
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&e2, &f2));
mbn_precomputedMillerLoop2(&f3, &P1, Q1buf.data(), &P2, Q2buf.data());
mbn_finalExp(&f3, &f3);
mclBn_precomputedMillerLoop2(&f3, &P1, Q1buf.data(), &P2, Q2buf.data());
mclBn_finalExp(&f3, &f3);
mbnGT_mul(&e1, &e1, &e2);
CYBOZU_TEST_ASSERT(mbnGT_isEqual(&e1, &f3));
mclBnGT_mul(&e1, &e1, &e2);
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&e1, &f3));
}
CYBOZU_TEST_AUTO(end)
{
int ret = mbn_setErrFile("bn_if.log");
int ret = mclBn_setErrFile("bn_if.log");
CYBOZU_TEST_EQUAL(ret, 0);
}

Loading…
Cancel
Save