aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-03-04 06:18:54 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-03-04 06:18:54 +0800
commit0e0659a51a838bd3f89732530fa9871f680ccc28 (patch)
tree47eb612063a4d534189a8a066263616d2575f894
parent2b2ad5db031f0488697180edfca481cfa021c801 (diff)
downloaddexon-mcl-0e0659a51a838bd3f89732530fa9871f680ccc28.tar.gz
dexon-mcl-0e0659a51a838bd3f89732530fa9871f680ccc28.tar.zst
dexon-mcl-0e0659a51a838bd3f89732530fa9871f680ccc28.zip
add GT for C#
-rw-r--r--ffi/cs/Program.cs155
1 files changed, 146 insertions, 9 deletions
diff --git a/ffi/cs/Program.cs b/ffi/cs/Program.cs
index eb38042..0646601 100644
--- a/ffi/cs/Program.cs
+++ b/ffi/cs/Program.cs
@@ -2,8 +2,8 @@
using System.Text;
using System.Runtime.InteropServices;
-namespace bn256 {
- class X {
+namespace mcl {
+ class BN256 {
[DllImport("bn256_if.dll")] public static extern int BN256_setErrFile([In][MarshalAs(UnmanagedType.LPStr)] string name);
[DllImport("bn256_if.dll")] public static extern int BN256_init();
[DllImport("bn256_if.dll")] public static extern void BN256_Fr_clear([Out] Fr x);
@@ -51,6 +51,24 @@ namespace bn256 {
[DllImport("bn256_if.dll")] public static extern void BN256_G2_sub([Out] G2 z, [In] G2 x, [In] G2 y);
[DllImport("bn256_if.dll")] public static extern void BN256_G2_mul([Out] G2 z, [In] G2 x, [In] Fr y);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_clear([Out] GT x);
+ [DllImport("bn256_if.dll")] public static extern int BN256_GT_setStr([Out] GT x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ [DllImport("bn256_if.dll")] public static extern int BN256_GT_isSame([In] GT x, [In] GT y);
+ [DllImport("bn256_if.dll")] public static extern int BN256_GT_isZero([In] GT x);
+ [DllImport("bn256_if.dll")] public static extern int BN256_GT_isOne([In] GT x);
+ [DllImport("bn256_if.dll")] public static extern int BN256_GT_getStr([Out]StringBuilder buf, long maxBufSize, [In] GT x);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_neg([Out] GT y, [In] GT x);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_inv([Out] GT y, [In] GT x);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_add([Out] GT z, [In] GT x, [In] GT y);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_sub([Out] GT z, [In] GT x, [In] GT y);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_mul([Out] GT z, [In] GT x, [In] GT y);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_div([Out] GT z, [In] GT x, [In] GT y);
+
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_finalExp([Out] GT y, [In] GT x);
+ [DllImport("bn256_if.dll")] public static extern void BN256_GT_pow([Out] GT z, [In] GT x, [In] Fr y);
+ [DllImport("bn256_if.dll")] public static extern void BN256_pairing([Out] GT z, [In] G1 x, [In] G2 y);
+ [DllImport("bn256_if.dll")] public static extern void BN256_millerLoop([Out] GT z, [In] G1 x, [In] G2 y);
+
[StructLayout(LayoutKind.Sequential)]
public class Fr {
private ulong v0, v1, v2, v3;
@@ -86,13 +104,13 @@ namespace bn256 {
}
public bool IsOne()
{
- return BN256_Fr_isZero(this) == 1;
+ return BN256_Fr_isOne(this) == 1;
}
public void SetRand()
{
BN256_Fr_setRand(this);
}
- public void SsetMsg(String s)
+ public void SetMsg(String s)
{
BN256_Fr_setMsg(this, s);
}
@@ -128,31 +146,31 @@ namespace bn256 {
{
BN256_Fr_div(z, y, x);
}
- public static Fr operator -(Fr x)
+ public static Fr operator-(Fr x)
{
Fr y = new Fr();
Neg(y, x);
return y;
}
- public static Fr operator +(Fr x, Fr y)
+ public static Fr operator+(Fr x, Fr y)
{
Fr z = new Fr();
Add(z, x, y);
return z;
}
- public static Fr operator -(Fr x, Fr y)
+ public static Fr operator-(Fr x, Fr y)
{
Fr z = new Fr();
Sub(z, x, y);
return z;
}
- public static Fr operator *(Fr x, Fr y)
+ public static Fr operator*(Fr x, Fr y)
{
Fr z = new Fr();
Mul(z, x, y);
return z;
}
- public static Fr operator /(Fr x, Fr y)
+ public static Fr operator/(Fr x, Fr y)
{
Fr z = new Fr();
Div(z, x, y);
@@ -172,6 +190,10 @@ namespace bn256 {
throw new ArgumentException("BN256_G1_setStr", s);
}
}
+ public G1 Clone()
+ {
+ return (G1)MemberwiseClone();
+ }
public bool IsValid()
{
return BN256_G1_isValid(this) == 1;
@@ -233,6 +255,10 @@ namespace bn256 {
throw new ArgumentException("BN256_G2_setStr", s);
}
}
+ public G2 Clone()
+ {
+ return (G2)MemberwiseClone();
+ }
public bool IsValid()
{
return BN256_G2_isValid(this) == 1;
@@ -280,6 +306,117 @@ namespace bn256 {
BN256_G2_mul(z, y, x);
}
}
+ [StructLayout(LayoutKind.Sequential)]
+ public class GT {
+ private ulong v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11;
+ private ulong v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23;
+ private ulong v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35;
+ private ulong v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47;
+ public void Clear()
+ {
+ BN256_GT_clear(this);
+ }
+ public void setStr(String s)
+ {
+ if (BN256_GT_setStr(this, s) != 0) {
+ throw new ArgumentException("BN256_GT_setStr", s);
+ }
+ }
+ public GT Clone()
+ {
+ return (GT)MemberwiseClone();
+ }
+ public bool Equals(GT rhs)
+ {
+ return BN256_GT_isSame(this, rhs) == 1;
+ }
+ public bool IsZero()
+ {
+ return BN256_GT_isZero(this) == 1;
+ }
+ public bool IsOne()
+ {
+ return BN256_GT_isOne(this) == 1;
+ }
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder(1024);
+ if (BN256_GT_getStr(sb, sb.Capacity + 1, this) != 0) {
+ throw new ArgumentException("BN256_GT_getStr");
+ }
+ return sb.ToString();
+ }
+ public static void Neg(GT y, GT x)
+ {
+ BN256_GT_neg(y, x);
+ }
+ public static void Inv(GT y, GT x)
+ {
+ BN256_GT_inv(y, x);
+ }
+ public static void Add(GT z, GT y, GT x)
+ {
+ BN256_GT_add(z, y, x);
+ }
+ public static void Sub(GT z, GT y, GT x)
+ {
+ BN256_GT_sub(z, y, x);
+ }
+ public static void Mul(GT z, GT y, GT x)
+ {
+ BN256_GT_mul(z, y, x);
+ }
+ public static void Div(GT z, GT y, GT x)
+ {
+ BN256_GT_div(z, y, x);
+ }
+ public static GT operator-(GT x)
+ {
+ GT y = new GT();
+ Neg(y, x);
+ return y;
+ }
+ public static GT operator+(GT x, GT y)
+ {
+ GT z = new GT();
+ Add(z, x, y);
+ return z;
+ }
+ public static GT operator-(GT x, GT y)
+ {
+ GT z = new GT();
+ Sub(z, x, y);
+ return z;
+ }
+ public static GT operator*(GT x, GT y)
+ {
+ GT z = new GT();
+ Mul(z, x, y);
+ return z;
+ }
+ public static GT operator/(GT x, GT y)
+ {
+ GT z = new GT();
+ Div(z, x, y);
+ return z;
+ }
+ public static void FinalExp(GT y, GT x)
+ {
+ BN256_GT_finalExp(y, x);
+ }
+ public static void Pow(GT z, GT x, Fr y)
+ {
+ BN256_GT_pow(z, x, y);
+ }
+ }
+ public static void Pairing(GT z, G1 x, G2 y)
+ {
+ BN256_pairing(z, x, y);
+ }
+ public static void MillerLoop(GT z, G1 x, G2 y)
+ {
+ BN256_millerLoop(z, x, y);
+ }
static void Main(string[] args)
{