aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-05-09 16:34:57 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-05-09 16:34:57 +0800
commitb38e1ecee938ccd3904f314cf153aa8a98a4a190 (patch)
treefd33dae1add5b90c3ab52577fca378a45c7368f7
parent0dcb4d0a90d18a20cfe0ab46d2dd6a7ceba1bfa9 (diff)
downloaddexon-mcl-b38e1ecee938ccd3904f314cf153aa8a98a4a190.tar.gz
dexon-mcl-b38e1ecee938ccd3904f314cf153aa8a98a4a190.tar.zst
dexon-mcl-b38e1ecee938ccd3904f314cf153aa8a98a4a190.zip
simplify C# method
-rw-r--r--ffi/cs/bn256.cs336
-rw-r--r--ffi/cs/bn256_test.cs44
2 files changed, 182 insertions, 198 deletions
diff --git a/ffi/cs/bn256.cs b/ffi/cs/bn256.cs
index 95048e1..7a01627 100644
--- a/ffi/cs/bn256.cs
+++ b/ffi/cs/bn256.cs
@@ -9,471 +9,455 @@ namespace mcl {
[DllImport("bn256.dll")]
public static extern int BN256_init();
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_clear([Out] Fr x);
+ public static extern void BN256_Fr_clear(ref Fr x);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_setInt([Out] Fr y, int x);
+ public static extern void BN256_Fr_setInt(ref Fr y, int x);
[DllImport("bn256.dll")]
- public static extern int BN256_Fr_setStr([Out] Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ public static extern int BN256_Fr_setStr(ref Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bn256.dll")]
- public static extern int BN256_Fr_isValid([In] Fr x);
+ public static extern int BN256_Fr_isValid(ref Fr x);
[DllImport("bn256.dll")]
- public static extern int BN256_Fr_isSame([In] Fr x, [In] Fr y);
+ public static extern int BN256_Fr_isSame(ref Fr x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern int BN256_Fr_isZero([In] Fr x);
+ public static extern int BN256_Fr_isZero(ref Fr x);
[DllImport("bn256.dll")]
- public static extern int BN256_Fr_isOne([In] Fr x);
+ public static extern int BN256_Fr_isOne(ref Fr x);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_setRand([Out] Fr x);
+ public static extern void BN256_Fr_setRand(ref Fr x);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_setMsg([Out] Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ public static extern void BN256_Fr_setMsg(ref Fr x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bn256.dll")]
- public static extern int BN256_Fr_getStr([Out]StringBuilder buf, int maxBufSize, [In] Fr x);
+ public static extern int BN256_Fr_getStr([Out]StringBuilder buf, int maxBufSize, ref Fr x);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_neg([Out] Fr y, [In] Fr x);
+ public static extern void BN256_Fr_neg(ref Fr y, ref Fr x);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_inv([Out] Fr y, [In] Fr x);
+ public static extern void BN256_Fr_inv(ref Fr y, ref Fr x);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_add([Out] Fr z, [In] Fr x, [In] Fr y);
+ public static extern void BN256_Fr_add(ref Fr z, ref Fr x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_sub([Out] Fr z, [In] Fr x, [In] Fr y);
+ public static extern void BN256_Fr_sub(ref Fr z, ref Fr x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_mul([Out] Fr z, [In] Fr x, [In] Fr y);
+ public static extern void BN256_Fr_mul(ref Fr z, ref Fr x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern void BN256_Fr_div([Out] Fr z, [In] Fr x, [In] Fr y);
+ public static extern void BN256_Fr_div(ref Fr z, ref Fr x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern void BN256_G1_clear([Out] G1 x);
+ public static extern void BN256_G1_clear(ref G1 x);
[DllImport("bn256.dll")]
- public static extern int BN256_G1_setStr([Out] G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ public static extern int BN256_G1_setStr(ref G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bn256.dll")]
- public static extern int BN256_G1_isValid([In] G1 x);
+ public static extern int BN256_G1_isValid(ref G1 x);
[DllImport("bn256.dll")]
- public static extern int BN256_G1_isSame([In] G1 x, [In] G1 y);
+ public static extern int BN256_G1_isSame(ref G1 x, ref G1 y);
[DllImport("bn256.dll")]
- public static extern int BN256_G1_isZero([In] G1 x);
+ public static extern int BN256_G1_isZero(ref G1 x);
[DllImport("bn256.dll")]
- public static extern int BN256_G1_hashAndMapTo([Out] G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ public static extern int BN256_G1_hashAndMapTo(ref G1 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bn256.dll")]
- public static extern int BN256_G1_getStr([Out]StringBuilder buf, int maxBufSize, [In] G1 x);
+ public static extern int BN256_G1_getStr([Out]StringBuilder buf, int maxBufSize, ref G1 x);
[DllImport("bn256.dll")]
- public static extern void BN256_G1_neg([Out] G1 y, [In] G1 x);
+ public static extern void BN256_G1_neg(ref G1 y, ref G1 x);
[DllImport("bn256.dll")]
- public static extern void BN256_G1_dbl([Out] G1 y, [In] G1 x);
+ public static extern void BN256_G1_dbl(ref G1 y, ref G1 x);
[DllImport("bn256.dll")]
- public static extern void BN256_G1_add([Out] G1 z, [In] G1 x, [In] G1 y);
+ public static extern void BN256_G1_add(ref G1 z, ref G1 x, ref G1 y);
[DllImport("bn256.dll")]
- public static extern void BN256_G1_sub([Out] G1 z, [In] G1 x, [In] G1 y);
+ public static extern void BN256_G1_sub(ref G1 z, ref G1 x, ref G1 y);
[DllImport("bn256.dll")]
- public static extern void BN256_G1_mul([Out] G1 z, [In] G1 x, [In] Fr y);
+ public static extern void BN256_G1_mul(ref G1 z, ref G1 x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern void BN256_G2_clear([Out] G2 x);
+ public static extern void BN256_G2_clear(ref G2 x);
[DllImport("bn256.dll")]
- public static extern int BN256_G2_setStr([Out] G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ public static extern int BN256_G2_setStr(ref G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bn256.dll")]
- public static extern int BN256_G2_isValid([In] G2 x);
+ public static extern int BN256_G2_isValid(ref G2 x);
[DllImport("bn256.dll")]
- public static extern int BN256_G2_isSame([In] G2 x, [In] G2 y);
+ public static extern int BN256_G2_isSame(ref G2 x, ref G2 y);
[DllImport("bn256.dll")]
- public static extern int BN256_G2_isZero([In] G2 x);
+ public static extern int BN256_G2_isZero(ref G2 x);
[DllImport("bn256.dll")]
- public static extern int BN256_G2_hashAndMapTo([Out] G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ public static extern int BN256_G2_hashAndMapTo(ref G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bn256.dll")]
- public static extern int BN256_G2_getStr([Out]StringBuilder buf, int maxBufSize, [In] G2 x);
+ public static extern int BN256_G2_getStr([Out]StringBuilder buf, int maxBufSize, ref G2 x);
[DllImport("bn256.dll")]
- public static extern void BN256_G2_neg([Out] G2 y, [In] G2 x);
+ public static extern void BN256_G2_neg(ref G2 y, ref G2 x);
[DllImport("bn256.dll")]
- public static extern void BN256_G2_dbl([Out] G2 y, [In] G2 x);
+ public static extern void BN256_G2_dbl(ref G2 y, ref G2 x);
[DllImport("bn256.dll")]
- public static extern void BN256_G2_add([Out] G2 z, [In] G2 x, [In] G2 y);
+ public static extern void BN256_G2_add(ref G2 z, ref G2 x, ref G2 y);
[DllImport("bn256.dll")]
- public static extern void BN256_G2_sub([Out] G2 z, [In] G2 x, [In] G2 y);
+ public static extern void BN256_G2_sub(ref G2 z, ref G2 x, ref G2 y);
[DllImport("bn256.dll")]
- public static extern void BN256_G2_mul([Out] G2 z, [In] G2 x, [In] Fr y);
+ public static extern void BN256_G2_mul(ref G2 z, ref G2 x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_clear([Out] GT x);
+ public static extern void BN256_GT_clear(ref GT x);
[DllImport("bn256.dll")]
- public static extern int BN256_GT_setStr([Out] GT x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
+ public static extern int BN256_GT_setStr(ref GT x, [In][MarshalAs(UnmanagedType.LPStr)] string s);
[DllImport("bn256.dll")]
- public static extern int BN256_GT_isSame([In] GT x, [In] GT y);
+ public static extern int BN256_GT_isSame(ref GT x, ref GT y);
[DllImport("bn256.dll")]
- public static extern int BN256_GT_isZero([In] GT x);
+ public static extern int BN256_GT_isZero(ref GT x);
[DllImport("bn256.dll")]
- public static extern int BN256_GT_isOne([In] GT x);
+ public static extern int BN256_GT_isOne(ref GT x);
[DllImport("bn256.dll")]
- public static extern int BN256_GT_getStr([Out]StringBuilder buf, int maxBufSize, [In] GT x);
+ public static extern int BN256_GT_getStr([Out]StringBuilder buf, int maxBufSize, ref GT x);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_neg([Out] GT y, [In] GT x);
+ public static extern void BN256_GT_neg(ref GT y, ref GT x);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_inv([Out] GT y, [In] GT x);
+ public static extern void BN256_GT_inv(ref GT y, ref GT x);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_add([Out] GT z, [In] GT x, [In] GT y);
+ public static extern void BN256_GT_add(ref GT z, ref GT x, ref GT y);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_sub([Out] GT z, [In] GT x, [In] GT y);
+ public static extern void BN256_GT_sub(ref GT z, ref GT x, ref GT y);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_mul([Out] GT z, [In] GT x, [In] GT y);
+ public static extern void BN256_GT_mul(ref GT z, ref GT x, ref GT y);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_div([Out] GT z, [In] GT x, [In] GT y);
+ public static extern void BN256_GT_div(ref GT z, ref GT x, ref GT y);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_finalExp([Out] GT y, [In] GT x);
+ public static extern void BN256_GT_finalExp(ref GT y, ref GT x);
[DllImport("bn256.dll")]
- public static extern void BN256_GT_pow([Out] GT z, [In] GT x, [In] Fr y);
+ public static extern void BN256_GT_pow(ref GT z, ref GT x, ref Fr y);
[DllImport("bn256.dll")]
- public static extern void BN256_pairing([Out] GT z, [In] G1 x, [In] G2 y);
+ public static extern void BN256_pairing(ref GT z, ref G1 x, ref G2 y);
[DllImport("bn256.dll")]
- public static extern void BN256_millerLoop([Out] GT z, [In] G1 x, [In] G2 y);
+ public static extern void BN256_millerLoop(ref GT z, ref G1 x, ref G2 y);
[StructLayout(LayoutKind.Sequential)]
- public class Fr {
+ public struct Fr {
private ulong v0, v1, v2, v3;
public void Clear()
{
- BN256_Fr_clear(this);
+ BN256_Fr_clear(ref this);
}
public void SetInt(int x)
{
- BN256_Fr_setInt(this, x);
- }
- public Fr Clone()
- {
- return (Fr)MemberwiseClone();
+ BN256_Fr_setInt(ref this, x);
}
public void SetStr(string s)
{
- if (BN256_Fr_setStr(this, s) != 0) {
+ if (BN256_Fr_setStr(ref this, s) != 0) {
throw new ArgumentException("BN256_Fr_setStr", s);
}
}
public bool IsValid()
{
- return BN256_Fr_isValid(this) == 1;
+ return BN256_Fr_isValid(ref this) == 1;
}
public bool Equals(Fr rhs)
{
- return BN256_Fr_isSame(this, rhs) == 1;
+ return BN256_Fr_isSame(ref this, ref rhs) == 1;
}
public bool IsZero()
{
- return BN256_Fr_isZero(this) == 1;
+ return BN256_Fr_isZero(ref this) == 1;
}
public bool IsOne()
{
- return BN256_Fr_isOne(this) == 1;
+ return BN256_Fr_isOne(ref this) == 1;
}
public void SetRand()
{
- BN256_Fr_setRand(this);
+ BN256_Fr_setRand(ref this);
}
public void SetMsg(String s)
{
- BN256_Fr_setMsg(this, s);
+ BN256_Fr_setMsg(ref this, s);
}
public override string ToString()
{
StringBuilder sb = new StringBuilder(1024);
- if (BN256_Fr_getStr(sb, sb.Capacity + 1, this) != 0) {
- throw new ArgumentException("BN256_Fr_getStr");
+ if (BN256_Fr_getStr(sb, sb.Capacity + 1, ref this) != 0) {
+ return "ERR:BN256_Fr_getStr";
}
return sb.ToString();
}
- public static void Neg(Fr y, Fr x)
+ public void Neg(Fr x)
{
- BN256_Fr_neg(y, x);
+ BN256_Fr_neg(ref this, ref x);
}
- public static void Inv(Fr y, Fr x)
+ public void Inv(Fr x)
{
- BN256_Fr_inv(y, x);
+ BN256_Fr_inv(ref this, ref x);
}
- public static void Add(Fr z, Fr y, Fr x)
+ public void Add(Fr x, Fr y)
{
- BN256_Fr_add(z, y, x);
+ BN256_Fr_add(ref this, ref x, ref y);
}
- public static void Sub(Fr z, Fr y, Fr x)
+ public void Sub(Fr x, Fr y)
{
- BN256_Fr_sub(z, y, x);
+ BN256_Fr_sub(ref this, ref x, ref y);
}
- public static void Mul(Fr z, Fr y, Fr x)
+ public void Mul(Fr x, Fr y)
{
- BN256_Fr_mul(z, y, x);
+ BN256_Fr_mul(ref this, ref x, ref y);
}
- public static void Div(Fr z, Fr y, Fr x)
+ public void Div(Fr x, Fr y)
{
- BN256_Fr_div(z, y, x);
+ BN256_Fr_div(ref this, ref x, ref y);
}
public static Fr operator -(Fr x)
{
Fr y = new Fr();
- Neg(y, x);
+ y.Neg(x);
return y;
}
public static Fr operator +(Fr x, Fr y)
{
Fr z = new Fr();
- Add(z, x, y);
+ z.Add(x, y);
return z;
}
public static Fr operator -(Fr x, Fr y)
{
Fr z = new Fr();
- Sub(z, x, y);
+ z.Sub(x, y);
return z;
}
public static Fr operator *(Fr x, Fr y)
{
Fr z = new Fr();
- Mul(z, x, y);
+ z.Mul(x, y);
return z;
}
public static Fr operator /(Fr x, Fr y)
{
Fr z = new Fr();
- Div(z, x, y);
+ z.Div(x, y);
return z;
}
}
[StructLayout(LayoutKind.Sequential)]
- public class G1 {
+ public struct G1 {
private ulong v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11;
public void Clear()
{
- BN256_G1_clear(this);
+ BN256_G1_clear(ref this);
}
public void setStr(String s)
{
- if (BN256_G1_setStr(this, s) != 0) {
+ if (BN256_G1_setStr(ref this, s) != 0) {
throw new ArgumentException("BN256_G1_setStr", s);
}
}
- public G1 Clone()
- {
- return (G1)MemberwiseClone();
- }
public bool IsValid()
{
- return BN256_G1_isValid(this) == 1;
+ return BN256_G1_isValid(ref this) == 1;
}
public bool Equals(G1 rhs)
{
- return BN256_G1_isSame(this, rhs) == 1;
+ return BN256_G1_isSame(ref this, ref rhs) == 1;
}
public bool IsZero()
{
- return BN256_G1_isZero(this) == 1;
+ return BN256_G1_isZero(ref this) == 1;
}
public void HashAndMapTo(String s)
{
- if (BN256_G1_hashAndMapTo(this, s) != 0) {
+ if (BN256_G1_hashAndMapTo(ref this, s) != 0) {
throw new ArgumentException("BN256_G1_hashAndMapTo", s);
}
}
public override string ToString()
{
StringBuilder sb = new StringBuilder(1024);
- if (BN256_G1_getStr(sb, sb.Capacity + 1, this) != 0) {
- throw new ArgumentException("BN256_G1_getStr");
+ if (BN256_G1_getStr(sb, sb.Capacity + 1, ref this) != 0) {
+ return "ERR:BN256_G1_getStr";
}
return sb.ToString();
}
- public static void Neg(G1 y, G1 x)
+ public void Neg(G1 x)
{
- BN256_G1_neg(y, x);
+ BN256_G1_neg(ref this, ref x);
}
- public static void Dbl(G1 y, G1 x)
+ public void Dbl(G1 x)
{
- BN256_G1_dbl(y, x);
+ BN256_G1_dbl(ref this, ref x);
}
- public static void Add(G1 z, G1 y, G1 x)
+ public void Add(G1 x, G1 y)
{
- BN256_G1_add(z, y, x);
+ BN256_G1_add(ref this, ref x, ref y);
}
- public static void Sub(G1 z, G1 y, G1 x)
+ public void Sub(G1 x, G1 y)
{
- BN256_G1_sub(z, y, x);
+ BN256_G1_sub(ref this, ref x, ref y);
}
- public static void Mul(G1 z, G1 y, Fr x)
+ public void Mul(G1 x, Fr y)
{
- BN256_G1_mul(z, y, x);
+ BN256_G1_mul(ref this, ref x, ref y);
}
}
[StructLayout(LayoutKind.Sequential)]
- public class G2 {
+ public struct G2 {
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;
public void Clear()
{
- BN256_G2_clear(this);
+ BN256_G2_clear(ref this);
}
public void setStr(String s)
{
- if (BN256_G2_setStr(this, s) != 0) {
+ if (BN256_G2_setStr(ref this, s) != 0) {
throw new ArgumentException("BN256_G2_setStr", s);
}
}
- public G2 Clone()
- {
- return (G2)MemberwiseClone();
- }
public bool IsValid()
{
- return BN256_G2_isValid(this) == 1;
+ return BN256_G2_isValid(ref this) == 1;
}
public bool Equals(G2 rhs)
{
- return BN256_G2_isSame(this, rhs) == 1;
+ return BN256_G2_isSame(ref this, ref rhs) == 1;
}
public bool IsZero()
{
- return BN256_G2_isZero(this) == 1;
+ return BN256_G2_isZero(ref this) == 1;
}
public void HashAndMapTo(String s)
{
- if (BN256_G2_hashAndMapTo(this, s) != 0) {
+ if (BN256_G2_hashAndMapTo(ref this, s) != 0) {
throw new ArgumentException("BN256_G2_hashAndMapTo", s);
}
}
public override string ToString()
{
StringBuilder sb = new StringBuilder(1024);
- if (BN256_G2_getStr(sb, sb.Capacity + 1, this) != 0) {
- throw new ArgumentException("BN256_G2_getStr");
+ if (BN256_G2_getStr(sb, sb.Capacity + 1, ref this) != 0) {
+ return "ERR:BN256_G2_getStr";
}
return sb.ToString();
}
- public static void Neg(G2 y, G2 x)
+ public void Neg(G2 x)
{
- BN256_G2_neg(y, x);
+ BN256_G2_neg(ref this, ref x);
}
- public static void Dbl(G2 y, G2 x)
+ public void Dbl(G2 x)
{
- BN256_G2_dbl(y, x);
+ BN256_G2_dbl(ref this, ref x);
}
- public static void Add(G2 z, G2 y, G2 x)
+ public void Add(G2 x, G2 y)
{
- BN256_G2_add(z, y, x);
+ BN256_G2_add(ref this, ref x, ref y);
}
- public static void Sub(G2 z, G2 y, G2 x)
+ public void Sub(G2 x, G2 y)
{
- BN256_G2_sub(z, y, x);
+ BN256_G2_sub(ref this, ref x, ref y);
}
- public static void Mul(G2 z, G2 y, Fr x)
+ public void Mul(G2 x, Fr y)
{
- BN256_G2_mul(z, y, x);
+ BN256_G2_mul(ref this, ref x, ref y);
}
}
[StructLayout(LayoutKind.Sequential)]
- public class GT {
+ public struct 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);
+ BN256_GT_clear(ref this);
}
public void setStr(String s)
{
- if (BN256_GT_setStr(this, s) != 0) {
+ if (BN256_GT_setStr(ref 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;
+ return BN256_GT_isSame(ref this, ref rhs) == 1;
}
public bool IsZero()
{
- return BN256_GT_isZero(this) == 1;
+ return BN256_GT_isZero(ref this) == 1;
}
public bool IsOne()
{
- return BN256_GT_isOne(this) == 1;
+ return BN256_GT_isOne(ref 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");
+ if (BN256_GT_getStr(sb, sb.Capacity + 1, ref this) != 0) {
+ return "ERR:BN256_GT_getStr";
}
return sb.ToString();
}
- public static void Neg(GT y, GT x)
+ public void Neg(GT x)
{
- BN256_GT_neg(y, x);
+ BN256_GT_neg(ref this, ref x);
}
- public static void Inv(GT y, GT x)
+ public void Inv(GT x)
{
- BN256_GT_inv(y, x);
+ BN256_GT_inv(ref this, ref x);
}
- public static void Add(GT z, GT y, GT x)
+ public void Add(GT x, GT y)
{
- BN256_GT_add(z, y, x);
+ BN256_GT_add(ref this, ref x, ref this);
}
- public static void Sub(GT z, GT y, GT x)
+ public void Sub(GT x, GT y)
{
- BN256_GT_sub(z, y, x);
+ BN256_GT_sub(ref this, ref x, ref this);
}
- public static void Mul(GT z, GT y, GT x)
+ public void Mul(GT x, GT y)
{
- BN256_GT_mul(z, y, x);
+ BN256_GT_mul(ref this, ref x, ref this);
}
- public static void Div(GT z, GT y, GT x)
+ public void Div(GT x, GT y)
{
- BN256_GT_div(z, y, x);
+ BN256_GT_div(ref this, ref x, ref this);
}
public static GT operator -(GT x)
{
GT y = new GT();
- Neg(y, x);
+ y.Neg(x);
return y;
}
public static GT operator +(GT x, GT y)
{
GT z = new GT();
- Add(z, x, y);
+ z.Add(x, y);
return z;
}
public static GT operator -(GT x, GT y)
{
GT z = new GT();
- Sub(z, x, y);
+ z.Sub(x, y);
return z;
}
public static GT operator *(GT x, GT y)
{
GT z = new GT();
- Mul(z, x, y);
+ z.Mul(x, y);
return z;
}
public static GT operator /(GT x, GT y)
{
GT z = new GT();
- Div(z, x, y);
+ z.Div(x, y);
return z;
}
- public static void FinalExp(GT y, GT x)
+ public void FinalExp(GT x)
{
- BN256_GT_finalExp(y, x);
+ BN256_GT_finalExp(ref this, ref x);
}
- public static void Pow(GT z, GT x, Fr y)
+ public void Pow(GT x, Fr y)
{
- BN256_GT_pow(z, x, y);
+ BN256_GT_pow(ref this, ref x, ref y);
+ }
+ public void Pairing(G1 x, G2 y)
+ {
+ BN256_pairing(ref this, ref x, ref y);
+ }
+ public void MillerLoop(G1 x, G2 y)
+ {
+ BN256_millerLoop(ref this, ref x, ref 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);
}
}
}
diff --git a/ffi/cs/bn256_test.cs b/ffi/cs/bn256_test.cs
index 6a21b99..30c3ce1 100644
--- a/ffi/cs/bn256_test.cs
+++ b/ffi/cs/bn256_test.cs
@@ -55,7 +55,7 @@ namespace mcl {
x = x * x;
assert("16", x.ToString() == "16");
Fr y;
- y = x.Clone();
+ y = x;
assert("x == y", x.Equals(y));
x.SetInt(123);
assert("123", x.ToString() == "123");
@@ -81,19 +81,19 @@ namespace mcl {
assert("P.IsValid", P.IsValid());
assert("!P.IsZero", !P.IsZero());
G1 Q = new G1();
- Q = P.Clone();
+ Q = P;
assert("P == Q", Q.Equals(P));
- G1.Neg(Q, P);
- G1.Add(Q, Q, P);
+ Q.Neg(P);
+ Q.Add(Q, P);
assert("P = Q", Q.IsZero());
- G1.Dbl(Q, P);
+ Q.Dbl(P);
G1 R = new G1();
- G1.Add(R, P, P);
+ R.Add(P, P);
assert("Q == R", Q.Equals(R));
Fr x = new Fr();
x.SetInt(3);
- G1.Add(R, R, P);
- G1.Mul(Q, P, x);
+ R.Add(R, P);
+ Q.Mul(P, x);
assert("Q == R", Q.Equals(R));
}
static void TestG2()
@@ -108,19 +108,19 @@ namespace mcl {
assert("P is valid", P.IsValid());
assert("P is not zero", !P.IsZero());
G2 Q = new G2();
- Q = P.Clone();
+ Q = P;
assert("P == Q", Q.Equals(P));
- G2.Neg(Q, P);
- G2.Add(Q, Q, P);
+ Q.Neg(P);
+ Q.Add(Q, P);
assert("Q is zero", Q.IsZero());
- G2.Dbl(Q, P);
+ Q.Dbl(P);
G2 R = new G2();
- G2.Add(R, P, P);
+ R.Add(P, P);
assert("Q == R", Q.Equals(R));
Fr x = new Fr();
x.SetInt(3);
- G2.Add(R, R, P);
- G2.Mul(Q, P, x);
+ R.Add(R, P);
+ Q.Mul(P, x);
assert("Q == R", Q.Equals(R));
}
static void TestPairing()
@@ -136,17 +136,17 @@ namespace mcl {
b.SetStr("230498230982394243424");
G1 aP = new G1();
G2 bQ = new G2();
- G1.Mul(aP, P, a);
- G2.Mul(bQ, Q, b);
+ aP.Mul(P, a);
+ bQ.Mul(Q, b);
GT e1 = new GT();
GT e2 = new GT();
GT e3 = new GT();
- Pairing(e1, P, Q);
- Pairing(e2, aP, Q);
- GT.Pow(e3, e1, a);
+ e1.Pairing(P, Q);
+ e2.Pairing(aP, Q);
+ e3.Pow(e1, a);
assert("e2.Equals(e3)", e2.Equals(e3));
- Pairing(e2, P, bQ);
- GT.Pow(e3, e1, b);
+ e2.Pairing(P, bQ);
+ e3.Pow(e1, b);
assert("e2.Equals(e3)", e2.Equals(e3));
}
}