|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|