|
|
|
@ -19,7 +19,6 @@ namespace mcl { |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_init(int curve, int compiledTimeVar); |
|
|
|
|
[DllImport(dllName)] public static extern void mclBn_setETHserialization(int enable); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_setMapToMode(int mode); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_FrEvaluatePolynomial(ref Fr z, [In] Fr[] poly, long bufSize, in Fr y); |
|
|
|
|
[DllImport(dllName)] public static extern void mclBnFr_clear(ref Fr x); |
|
|
|
|
[DllImport(dllName)] public static extern void mclBnFr_setInt(ref Fr y, int x); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBnFr_setStr(ref Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode); |
|
|
|
@ -122,6 +121,12 @@ namespace mcl { |
|
|
|
|
[DllImport(dllName)] public static extern ulong mclBnG1_deserialize(ref G1 x, [In] byte[] buf, ulong bufSize); |
|
|
|
|
[DllImport(dllName)] public static extern ulong mclBnG2_deserialize(ref G2 x, [In] byte[] buf, ulong bufSize); |
|
|
|
|
|
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_FrEvaluatePolynomial(ref Fr z, [In] Fr[] cVec, ulong cSize, in Fr x); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_G1EvaluatePolynomial(ref G1 z, [In] G1[] cVec, ulong cSize, in Fr x); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_G2EvaluatePolynomial(ref G2 z, [In] G2[] cVec, ulong cSize, in Fr x); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_FrLagrangeInterpolation(ref Fr z, [In] Fr[] xVec, [In] Fr[] yVec, ulong k); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_G1LagrangeInterpolation(ref G1 z, [In] Fr[] xVec, [In] G1[] yVec, ulong k); |
|
|
|
|
[DllImport(dllName)] public static extern int mclBn_G2LagrangeInterpolation(ref G2 z, [In] Fr[] xVec, [In] G2[] yVec, ulong k); |
|
|
|
|
public static void Init(int curveType = BN254) |
|
|
|
|
{ |
|
|
|
|
if (!System.Environment.Is64BitProcess) { |
|
|
|
@ -302,6 +307,65 @@ namespace mcl { |
|
|
|
|
{ |
|
|
|
|
mclBn_millerLoop(ref z, x, y); |
|
|
|
|
} |
|
|
|
|
// y = f(x) with a polynomial f(t) = sum_i cVec[i] t^i |
|
|
|
|
public static void Share(ref Fr y, in Fr[] cVec, in Fr x) |
|
|
|
|
{ |
|
|
|
|
ulong k = (ulong)cVec.Length; |
|
|
|
|
int ret = mclBn_FrEvaluatePolynomial(ref y, cVec, k, x); |
|
|
|
|
if (ret != 0) { |
|
|
|
|
throw new ArgumentException("mclBn_FrEvaluatePolynomial"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public static void Share(ref G1 y, in G1[] cVec, in Fr x) |
|
|
|
|
{ |
|
|
|
|
ulong k = (ulong)cVec.Length; |
|
|
|
|
int ret = mclBn_G1EvaluatePolynomial(ref y, cVec, k, x); |
|
|
|
|
if (ret != 0) { |
|
|
|
|
throw new ArgumentException("mclBn_G1EvaluatePolynomial"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public static void Share(ref G2 y, in G2[] cVec, in Fr x) |
|
|
|
|
{ |
|
|
|
|
ulong k = (ulong)cVec.Length; |
|
|
|
|
int ret = mclBn_G2EvaluatePolynomial(ref y, cVec, k, x); |
|
|
|
|
if (ret != 0) { |
|
|
|
|
throw new ArgumentException("mclBn_G2EvaluatePolynomial"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// recover z by Lagrange interpolation with {xVec[i], yVec[i]} |
|
|
|
|
public static void Recover(ref Fr z, in Fr[] xVec, in Fr[] yVec) |
|
|
|
|
{ |
|
|
|
|
if (xVec.Length != yVec.Length) { |
|
|
|
|
throw new ArgumentException("bad length"); |
|
|
|
|
} |
|
|
|
|
ulong k = (ulong)xVec.Length; |
|
|
|
|
int ret = mclBn_FrLagrangeInterpolation(ref z, xVec, yVec, k); |
|
|
|
|
if (ret != 0) { |
|
|
|
|
throw new ArgumentException("mclBn_FrLagrangeInterpolation:" + ret.ToString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public static void Recover(ref G1 z, in Fr[] xVec, in G1[] yVec) |
|
|
|
|
{ |
|
|
|
|
if (xVec.Length != yVec.Length) { |
|
|
|
|
throw new ArgumentException("bad length"); |
|
|
|
|
} |
|
|
|
|
ulong k = (ulong)xVec.Length; |
|
|
|
|
int ret = mclBn_G1LagrangeInterpolation(ref z, xVec, yVec, k); |
|
|
|
|
if (ret != 0) { |
|
|
|
|
throw new ArgumentException("mclBn_G1LagrangeInterpolation:" + ret.ToString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public static void Recover(ref G2 z, in Fr[] xVec, in G2[] yVec) |
|
|
|
|
{ |
|
|
|
|
if (xVec.Length != yVec.Length) { |
|
|
|
|
throw new ArgumentException("bad length"); |
|
|
|
|
} |
|
|
|
|
ulong k = (ulong)xVec.Length; |
|
|
|
|
int ret = mclBn_G2LagrangeInterpolation(ref z, xVec, yVec, k); |
|
|
|
|
if (ret != 0) { |
|
|
|
|
throw new ArgumentException("mclBn_G2LagrangeInterpolation:" + ret.ToString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
[StructLayout(LayoutKind.Sequential)] |
|
|
|
|
struct U128 { |
|
|
|
|
private ulong v0, v1; |
|
|
|
@ -638,6 +702,10 @@ namespace mcl { |
|
|
|
|
throw new ArgumentException("mclBnG1_hashAndMapTo:" + s); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public void SetHashOf(String s) |
|
|
|
|
{ |
|
|
|
|
HashAndMapTo(s); |
|
|
|
|
} |
|
|
|
|
public string GetStr(int ioMode) |
|
|
|
|
{ |
|
|
|
|
StringBuilder sb = new StringBuilder(1024); |
|
|
|
@ -748,6 +816,10 @@ namespace mcl { |
|
|
|
|
throw new ArgumentException("mclBnG2_hashAndMapTo:" + s); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public void SetHashOf(String s) |
|
|
|
|
{ |
|
|
|
|
HashAndMapTo(s); |
|
|
|
|
} |
|
|
|
|
public string GetStr(int ioMode) |
|
|
|
|
{ |
|
|
|
|
StringBuilder sb = new StringBuilder(1024); |
|
|
|
|