From 8da8ecabb6500fad06e6ae72ad573265e7ad45fe Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 29 Jan 2024 14:12:49 +0900 Subject: [PATCH 01/10] [sample] add g1 option --- sample/mt_test.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sample/mt_test.cpp b/sample/mt_test.cpp index 293bcb14..5dd72d6d 100644 --- a/sample/mt_test.cpp +++ b/sample/mt_test.cpp @@ -14,34 +14,37 @@ int main(int argc, char *argv[]) { cybozu::Option opt; size_t n; + int bit; size_t cpuN; + bool g1only; + int C; opt.appendOpt(&n, 100, "n"); opt.appendOpt(&cpuN, 0, "cpu"); + opt.appendOpt(&C, 50, "c"); + opt.appendOpt(&bit, 0, "b"); + opt.appendBoolOpt(&g1only, "g1"); opt.appendHelp("h"); if (!opt.parse(argc, argv)) { opt.usage(); return 1; } - printf("n=%zd cpuN=%zd\n", n, cpuN); - int C = 10; - if (n >= 1000) { - C = 1; - } + if (bit) n = 1u << bit; + printf("n=%zd cpuN=%zd C=%d\n", n, cpuN, C); initPairing(mcl::BLS12_381); cybozu::XorShift rg; std::vector Pvec(n); std::vector Qvec(n); std::vector xVec(n); - char c = '0'; - for (size_t i = 0; i < n; i++) { - hashAndMapToG1(Pvec[i], &c, 1); - hashAndMapToG2(Qvec[i], &c, 1); - xVec[i].setRand(rg); - c++; + hashAndMapToG1(Pvec[0], "abc", 3); + hashAndMapToG2(Qvec[0], "abc", 3); + for (size_t i = 1; i < n; i++) { + G1::add(Pvec[i], Pvec[i-1], Pvec[0]); + G2::add(Qvec[i], Qvec[i-1], Qvec[0]); } G1 P1, P2; CYBOZU_BENCH_C("single", C, G1::mulVec, P1, Pvec.data(), xVec.data(), n); + if (g1only) return 0; CYBOZU_BENCH_C("multi ", C, G1::mulVecMT, P2, Pvec.data(), xVec.data(), n, cpuN); printf("G1 ret %s\n", P1 == P2 ? "ok" : "ng"); G2 Q1, Q2; From dad162b3f4e0b944f5838d9dae8c5359846d869f Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Wed, 31 Jan 2024 10:18:44 +0900 Subject: [PATCH 02/10] remove duplicated getReadSize --- include/mcl/vint.hpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/include/mcl/vint.hpp b/include/mcl/vint.hpp index 25a80fb2..37af10ac 100644 --- a/include/mcl/vint.hpp +++ b/include/mcl/vint.hpp @@ -22,17 +22,6 @@ namespace mcl { -// return the max size in x[0..n) -inline int getRealSize(const Unit *x, int n) -{ - assert(n > 0); - while (n > 0) { - if (x[n - 1]) return n; - n--; - } - return 1; -} - /** signed integer with variable length */ From e8efab848ac365cb82ea9b0aa0d161347ef3dd97 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Thu, 1 Feb 2024 17:10:20 +0900 Subject: [PATCH 03/10] [test] refactor mont.hpp in test --- test/mont.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/mont.hpp b/test/mont.hpp index 6c3d37e2..42b0beb8 100644 --- a/test/mont.hpp +++ b/test/mont.hpp @@ -33,12 +33,11 @@ class Montgomery { mR = 1; mR = (mR << (N * sizeof(Unit) * 8)) % mp; mR2 = (mR * mR) % mp; - v_.resize(N * 2); - Unit *base = &v_[N]; + v_.resize(N + 1); + Unit *base = &v_[1]; mcl::gmp::getArray(base, N, _p); - rp = mcl::bint::getMontgomeryCoeff(v_[0]); + base[-1] = rp = mcl::bint::getMontgomeryCoeff(base[0]); p = base; - rp = base[-1]; isFullBit = p[N - 1] >> (sizeof(Unit) * 8 - 1); } From 7042a444c8454981f7020bc9db2402a935280ee0 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 13 Feb 2024 12:27:53 +0900 Subject: [PATCH 04/10] add conversion between Proj and Jacobi --- include/mcl/ec.hpp | 23 +++++++++++++++++++++++ test/ec_test.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 2cd5a87a..4bba163b 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -226,6 +226,29 @@ void normalizeVecT(Eout& Q, Ein& P, size_t n, size_t N = 256) } // mcl::ec::local +// [X:Y:Z] as Proj = (X/Z, Y/Z) as Affine = [XZ:YZ^2:Z] as Jacobi +template +void ProjToJacobi(E& Q, const E& P) +{ + typedef typename E::Fp F; + F::mul(Q.x, P.x, P.z); + F::mul(Q.y, P.y, P.z); + Q.y *= P.z; + Q.z = P.z; +} + +// [X:Y:Z] as Jacobi = (X/Z^2, Y/Z^3) as Affine = [XZ:Y:Z^3] as Proj +template +void JacobiToProj(E& Q, const E& P) +{ + typedef typename E::Fp F; + F::mul(Q.x, P.x, P.z); + Q.y = P.y; + F t; + F::sqr(t, P.z); + F::mul(Q.z, P.z, t); +} + template void normalizeJacobi(E& P) { diff --git a/test/ec_test.cpp b/test/ec_test.cpp index c461b00f..160d0239 100644 --- a/test/ec_test.cpp +++ b/test/ec_test.cpp @@ -627,6 +627,29 @@ struct Test { Ec::add(R, Zero, Zero); CYBOZU_TEST_EQUAL(Q, R); } + void ProjJacobi() const + { + if (Ec::getMode() == mcl::ec::Affine) return; + Fp x(para.gx); + Fp y(para.gy); + Ec P(x, y), Q, R; + P *= 123; + if (Ec::getMode() == mcl::ec::Proj) { + mcl::ec::ProjToJacobi(Q, P); + mcl::ec::normalizeJacobi(Q); + CYBOZU_TEST_EQUAL(Q, P); + mcl::ec::ProjToJacobi(Q, P); + mcl::ec::JacobiToProj(R, Q); + CYBOZU_TEST_EQUAL(R, P); + } else { + mcl::ec::JacobiToProj(Q, P); + mcl::ec::normalizeProj(Q); + CYBOZU_TEST_EQUAL(Q, P); + mcl::ec::JacobiToProj(Q, P); + mcl::ec::ProjToJacobi(R, Q); + CYBOZU_TEST_EQUAL(R, P); + } + } template void test(F f, const char *msg) const @@ -672,6 +695,7 @@ mul 499.00usec mulCT(); compare(); addCT(); + ProjJacobi(); } private: Test(const Test&); From 3cf65bb40e3aaf5309631e24aad8eed09f65701e Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 13 Feb 2024 14:58:31 +0900 Subject: [PATCH 05/10] add dblCTProj --- include/mcl/ec.hpp | 54 +++++++++++++++++++++++++++++++++++++--------- test/ec_test.cpp | 13 +++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 4bba163b..1e36339c 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -505,17 +505,23 @@ void addJacobi(E& R, const E& P, const E& Q) /* accept P == Q https://github.com/apache/incubator-milagro-crypto-c/blob/fa0a45a3/src/ecp.c.in#L767-L976 + // 14M (x, y, z) is zero <=> x = 0, y = 1, z = 0 */ +template +void clearCTProj(E& P) +{ + P.x.clear(); + P.y = 1; + P.z.clear(); +} + template void addCTProj(E& R, const E& P, const E& Q) { typedef typename E::Fp F; assert(E::a_ == 0); - F b3; - F::add(b3, E::b_, E::b_); - b3 += E::b_; - F t0, t1, t2, t3, t4, x3, y3, z3; + F t0, t1, t2, t3, t4, x3, y3; F::mul(t0, P.x, Q.x); F::mul(t1, P.y, Q.y); F::mul(t2, P.z, Q.z); @@ -536,19 +542,44 @@ void addCTProj(E& R, const E& P, const E& Q) F::sub(y3, x3, y3); F::add(x3, t0, t0); F::add(t0, t0, x3); - t2 *= b3; - F::add(z3, t1, t2); + t2 *= E::b3_; + F::add(R.z, t1, t2); F::sub(t1, t1, t2); - y3 *= b3; + y3 *= E::b3_; F::mul(x3, y3, t4); F::mul(t2, t3, t1); F::sub(R.x, t2, x3); F::mul(y3, y3, t0); - F::mul(t1, t1, z3); + F::mul(t1, t1, R.z); F::add(R.y, y3, t1); F::mul(t0, t0, t3); - F::mul(z3, z3, t4); - F::add(R.z, z3, t0); + F::mul(R.z, R.z, t4); + F::add(R.z, R.z, t0); +} +template +void dblCTProj(E& R, const E& P) +{ + typedef typename E::Fp F; + assert(E::a_ == 0); + F t0, t1, t2, x3, y3; + F::sqr(t0, P.y); + F::mul(t1, P.y, P.z); + F::sqr(t2, P.z); + F::add(R.z, t0, t0); + F::add(R.z, R.z, R.z); + F::add(R.z, R.z, R.z); + F::mul(t2, t2, E::b3_); + F::mul(x3, t2, P.z); + F::add(y3, t0, t2); + F::mul(R.z, R.z, t1); + F::add(t1, t2, t2); + F::add(t2, t2, t1); + F::mul(t1, P.x, P.y); + F::sub(t0, t0, t2); + F::mul(R.y, y3, t0); + R.y += x3; + F::mul(R.x, t0, t1); + R.x += R.x; } template @@ -1237,6 +1268,7 @@ class EcT : public fp::Serializable > { static int mode_; static Fp a_; static Fp b_; + static Fp b3_; static int specialA_; static int ioMode_; /* @@ -1294,6 +1326,7 @@ class EcT : public fp::Serializable > { { a_ = a; b_ = b; + b3_ = b * 3; if (a_.isZero()) { specialA_ = ec::Zero; } else if (a_ == -3) { @@ -2100,6 +2133,7 @@ class EcT : public fp::Serializable > { template Fp EcT::a_; template Fp EcT::b_; +template Fp EcT::b3_; template int EcT::specialA_; template int EcT::ioMode_; template bool EcT::verifyOrder_; diff --git a/test/ec_test.cpp b/test/ec_test.cpp index 160d0239..4c2cfc44 100644 --- a/test/ec_test.cpp +++ b/test/ec_test.cpp @@ -626,6 +626,19 @@ struct Test { mcl::ec::addCTProj(Q, Zero, Zero); Ec::add(R, Zero, Zero); CYBOZU_TEST_EQUAL(Q, R); + mcl::ec::addCTProj(Q, Q, Q); + Ec::add(R, R, R); + CYBOZU_TEST_EQUAL(Q, R); + + // dbl + mcl::ec::dblCTProj(P, Q); + Ec::dbl(R, R); + CYBOZU_TEST_EQUAL(Q, R); + mcl::ec::dblCTProj(Q, Q); + Ec::dbl(R, R); + CYBOZU_TEST_EQUAL(Q, R); + mcl::ec::dblCTProj(Q, Zero); + CYBOZU_TEST_EQUAL(Q, Zero); } void ProjJacobi() const { From 9e4934474004cca82474ca517e4f35ae6756588b Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 13 Feb 2024 15:17:07 +0900 Subject: [PATCH 06/10] avoid arithmetic operation in addCTProj, dblCTProj --- include/mcl/ec.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 1e36339c..54a0418a 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -505,7 +505,6 @@ void addJacobi(E& R, const E& P, const E& Q) /* accept P == Q https://github.com/apache/incubator-milagro-crypto-c/blob/fa0a45a3/src/ecp.c.in#L767-L976 - // 14M (x, y, z) is zero <=> x = 0, y = 1, z = 0 */ template @@ -516,6 +515,7 @@ void clearCTProj(E& P) P.z.clear(); } +// 14M template void addCTProj(E& R, const E& P, const E& Q) { @@ -542,10 +542,10 @@ void addCTProj(E& R, const E& P, const E& Q) F::sub(y3, x3, y3); F::add(x3, t0, t0); F::add(t0, t0, x3); - t2 *= E::b3_; + F::mul(t2, t2, E::b3_); F::add(R.z, t1, t2); F::sub(t1, t1, t2); - y3 *= E::b3_; + F::mul(y3, y3, E::b3_); F::mul(x3, y3, t4); F::mul(t2, t3, t1); F::sub(R.x, t2, x3); @@ -556,6 +556,7 @@ void addCTProj(E& R, const E& P, const E& Q) F::mul(R.z, R.z, t4); F::add(R.z, R.z, t0); } +// 7M+2S template void dblCTProj(E& R, const E& P) { @@ -577,9 +578,9 @@ void dblCTProj(E& R, const E& P) F::mul(t1, P.x, P.y); F::sub(t0, t0, t2); F::mul(R.y, y3, t0); - R.y += x3; + F::add(R.y, R.y, x3); F::mul(R.x, t0, t1); - R.x += R.x; + F::add(R.x, R.x, R.x); } template From 2c3c70cc1bd094512d81b187614366917af5cd28 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 17 Feb 2024 09:08:37 +0900 Subject: [PATCH 07/10] [doc] add params of BN_SNARK1 --- api.md | 1 + 1 file changed, 1 insertion(+) diff --git a/api.md b/api.md index 4d927487..e7b6836a 100644 --- a/api.md +++ b/api.md @@ -61,6 +61,7 @@ r = |G1| = |G2| = |GT| curveType | b| r and p | ------------|--|------------------| BN254 | 2|r = 0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d
p = 0x2523648240000001ba344d80000000086121000000000013a700000000000013 | +BN_SNARK1|3|r = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47
p = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47| BLS12-381 | 4|r = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
p = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab | BN381 | 2|r = 0x240026400f3d82b2e42de125b00158405b710818ac000007e0042f008e3e00000000001080046200000000000000000d
p = 0x240026400f3d82b2e42de125b00158405b710818ac00000840046200950400000000001380052e000000000000000013 | From b0ba10ea012b4ea9605e2d44e3860dcaa5858430 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 17 Feb 2024 09:09:26 +0900 Subject: [PATCH 08/10] [C#] update target framework to net8.0 --- ffi/cs/mcl/mcl.csproj | 3 ++- ffi/cs/test/test.csproj | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ffi/cs/mcl/mcl.csproj b/ffi/cs/mcl/mcl.csproj index ec210537..df9f03db 100644 --- a/ffi/cs/mcl/mcl.csproj +++ b/ffi/cs/mcl/mcl.csproj @@ -1,7 +1,8 @@ - netstandard2.1 + net8.0 + x64 diff --git a/ffi/cs/test/test.csproj b/ffi/cs/test/test.csproj index ddabc650..b8cf9dd3 100644 --- a/ffi/cs/test/test.csproj +++ b/ffi/cs/test/test.csproj @@ -12,7 +12,7 @@ Exe - netcoreapp3.1 + net8.0 From d3b7c01dd388cabc79b3e7198c89bae6217b98d5 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 17 Feb 2024 15:12:21 +0900 Subject: [PATCH 09/10] [C#] add GT serialization function --- ffi/cs/mcl/mcl.cs | 18 ++++++++++++++++++ ffi/cs/test/test.cs | 10 ++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ffi/cs/mcl/mcl.cs b/ffi/cs/mcl/mcl.cs index 7eb1e433..24dce6ea 100644 --- a/ffi/cs/mcl/mcl.cs +++ b/ffi/cs/mcl/mcl.cs @@ -116,10 +116,12 @@ public class MCL { [DllImport(dllName)] public static extern ulong mclBnFr_serialize([Out] byte[] buf, ulong maxBufSize, in Fr x); [DllImport(dllName)] public static extern ulong mclBnG1_serialize([Out] byte[] buf, ulong maxBufSize, in G1 x); [DllImport(dllName)] public static extern ulong mclBnG2_serialize([Out] byte[] buf, ulong maxBufSize, in G2 x); + [DllImport(dllName)] public static extern ulong mclBnGT_serialize([Out] byte[] buf, ulong maxBufSize, in GT x); [DllImport(dllName)] public static extern ulong mclBnFr_deserialize(ref Fr x, [In] byte[] buf, ulong bufSize); [DllImport(dllName)] public static extern ulong mclBnFp_deserialize(ref Fp x, [In] byte[] buf, ulong bufSize); [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 ulong mclBnGT_deserialize(ref GT 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); @@ -948,6 +950,22 @@ public string GetStr(int ioMode) } return sb.ToString(); } + public byte[] Serialize() + { + byte[] buf = new byte[mclBn_getFpByteSize()*12]; + ulong n = mclBnGT_serialize(buf, (ulong)buf.Length, this); + if (n != (ulong)buf.Length) { + throw new ArithmeticException("mclBnGT_serialize"); + } + return buf; + } + public void Deserialize(byte[] buf) + { + ulong n = mclBnGT_deserialize(ref this, buf, (ulong)buf.Length); + if (n == 0) { + throw new ArithmeticException("mclBnGT_deserialize"); + } + } public void Neg(in GT x) { MCL.Neg(ref this, x); diff --git a/ffi/cs/test/test.cs b/ffi/cs/test/test.cs index b41aab42..c9d1301b 100644 --- a/ffi/cs/test/test.cs +++ b/ffi/cs/test/test.cs @@ -77,7 +77,7 @@ static void TestFr() Console.WriteLine("exception test"); try { x.SetStr("1234567891234x", 10); - Console.WriteLine("x = {0}", x); + Console.WriteLine("ERR ; not here"); } catch (Exception e) { Console.WriteLine("OK ; expected exception: {0}", e); } @@ -123,7 +123,7 @@ static void TestFp() Console.WriteLine("exception test"); try { x.SetStr("1234567891234x", 10); - Console.WriteLine("x = {0}", x); + Console.WriteLine("ERR ; not here"); } catch (Exception e) { Console.WriteLine("OK ; expected exception: {0}", e); } @@ -258,6 +258,12 @@ static void TestPairing() e2.Pairing(P, bQ); e3.Pow(e1, b); assert("e2.Equals(e3)", e2.Equals(e3)); + { + byte[] buf = e1.Serialize(); + e2.Clear(); + e2.Deserialize(buf); + assert("e1 == e2", e1.Equals(e2)); + } } static void TestETH_mapToG1() { From cb48a23eeafbbd8b09c2cf272ffb98bc36115412 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 17 Feb 2024 15:12:46 +0900 Subject: [PATCH 10/10] [C#] format --- ffi/cs/mcl/mcl.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ffi/cs/mcl/mcl.cs b/ffi/cs/mcl/mcl.cs index 24dce6ea..17d69f83 100644 --- a/ffi/cs/mcl/mcl.cs +++ b/ffi/cs/mcl/mcl.cs @@ -28,7 +28,7 @@ public class MCL { [DllImport(dllName)] public static extern int mclBnFr_isOne(in Fr x); [DllImport(dllName)] public static extern void mclBnFr_setByCSPRNG(ref Fr x); - [DllImport(dllName)] public static extern int mclBnFr_setHashOf(ref Fr x, [In]byte[] buf, long bufSize); + [DllImport(dllName)] public static extern int mclBnFr_setHashOf(ref Fr x, [In] byte[] buf, long bufSize); [DllImport(dllName)] public static extern int mclBnFr_getStr([Out] StringBuilder buf, long maxBufSize, in Fr x, int ioMode); [DllImport(dllName)] public static extern void mclBnFr_neg(ref Fr y, in Fr x); @@ -48,7 +48,7 @@ public class MCL { [DllImport(dllName)] public static extern int mclBnFp_isOne(in Fp x); [DllImport(dllName)] public static extern void mclBnFp_setByCSPRNG(ref Fp x); - [DllImport(dllName)] public static extern int mclBnFp_setHashOf(ref Fp x, [In]byte[] buf, long bufSize); + [DllImport(dllName)] public static extern int mclBnFp_setHashOf(ref Fp x, [In] byte[] buf, long bufSize); [DllImport(dllName)] public static extern int mclBnFp_getStr([Out] StringBuilder buf, long maxBufSize, in Fp x, int ioMode); [DllImport(dllName)] public static extern void mclBnFp_neg(ref Fp y, in Fp x); @@ -64,7 +64,7 @@ public class MCL { [DllImport(dllName)] public static extern int mclBnG1_isValid(in G1 x); [DllImport(dllName)] public static extern int mclBnG1_isEqual(in G1 x, in G1 y); [DllImport(dllName)] public static extern int mclBnG1_isZero(in G1 x); - [DllImport(dllName)] public static extern int mclBnG1_hashAndMapTo(ref G1 x, [In]byte[] buf, long bufSize); + [DllImport(dllName)] public static extern int mclBnG1_hashAndMapTo(ref G1 x, [In] byte[] buf, long bufSize); [DllImport(dllName)] public static extern long mclBnG1_getStr([Out] StringBuilder buf, long maxBufSize, in G1 x, int ioMode); [DllImport(dllName)] public static extern void mclBnG1_neg(ref G1 y, in G1 x); [DllImport(dllName)] public static extern void mclBnG1_dbl(ref G1 y, in G1 x); @@ -79,7 +79,7 @@ public class MCL { [DllImport(dllName)] public static extern int mclBnG2_isValid(in G2 x); [DllImport(dllName)] public static extern int mclBnG2_isEqual(in G2 x, in G2 y); [DllImport(dllName)] public static extern int mclBnG2_isZero(in G2 x); - [DllImport(dllName)] public static extern int mclBnG2_hashAndMapTo(ref G2 x, [In]byte[] buf, long bufSize); + [DllImport(dllName)] public static extern int mclBnG2_hashAndMapTo(ref G2 x, [In] byte[] buf, long bufSize); [DllImport(dllName)] public static extern long mclBnG2_getStr([Out] StringBuilder buf, long maxBufSize, in G2 x, int ioMode); [DllImport(dllName)] public static extern void mclBnG2_neg(ref G2 y, in G2 x); [DllImport(dllName)] public static extern void mclBnG2_dbl(ref G2 y, in G2 x); @@ -952,7 +952,7 @@ public string GetStr(int ioMode) } public byte[] Serialize() { - byte[] buf = new byte[mclBn_getFpByteSize()*12]; + byte[] buf = new byte[mclBn_getFpByteSize() * 12]; ulong n = mclBnGT_serialize(buf, (ulong)buf.Length, this); if (n != (ulong)buf.Length) { throw new ArithmeticException("mclBnGT_serialize");