3#ifndef XBYAK_NO_OP_NAMES
4 #define XBYAK_NO_OP_NAMES
14#define NUM_OF_ARRAY(x) (sizeof(x) / sizeof(*x))
19static int s_errNum = 0;
20static int s_testNum = 0;
22#define TEST_EQUAL(x, y) { s_testNum++; if (x != y) { s_errNum++; printf("%s(%d): err %s != %s\n", __FILE__, __LINE__, #x, #y); std::cout << "lhs=" << (x) << "\nrhs=" << (y) << std::endl; } }
23#define TEST_ASSERT(x) { s_testNum++; if (!(x)) { s_errNum++; printf("%s(%d): err assert %s\n", __FILE__, __LINE__, #x); } }
25#define FATAL_EXIT(msg) { printf("%s(%d): err %s\n", __FILE__, __LINE__, msg); exit(1); }
32 Fp x(
"1234566239428049280498203948209482039482");
33 Fp y(
"999999999999999999999999999999999999999");
49 x.b_.
set(
"464652165165");
74 const Fp g1[3] = { pt.
g1.a, pt.
g1.b, 1 };
82 std::vector<Fp6> Qcoeff;
94#ifdef BN_SUPPORT_SNARK
101 if (b != 3 && b != 82) {
102 printf(
"not support b=%d\n", b);
106 printf(
"SNARK b = %d\n", b);
112 printf(
"err=%d(test=%d)\n", s_errNum, s_testNum);
128 const Fp Py =
Fp(
"16740896641879863340107777353588575149660814923656713498672603551465628253431");
137 const Fp P2x =
Fp(
"13438486984812665827952643313785387127911349697151255879146972340858203091778");
145 const Fp P2y =
Fp(
"12741389316352206200828479361093127917015298445269456291074734498988157668221");
164 const Fp Zero[] = { 1, 1, 0 };
176 const Fp* ok =
tbl[i].ok;
178 for (
int m = 0; m < 2; m++) {
213 Fp(
"933228262834212904718933563457318550549399284524392769385206412559597436928"),
214 Fp(
"13081617668227268048378253503661144166646030151223471427486357073175298320248"),
217 const Fp Zero[] = { 1, 1, 0 };
232 { Zero, Zero, Zero },
238 const Fp* ok =
tbl[i].ok;
240 for (
int m = 0; m < 3; m++) {
277 const Fp* ok =
tbl[i].ok;
279 for (
int m = 0; m < 2; m++) {
286 ECAdd(out, out, out);
310 Fp(
"13444485882265322272857095018562747159513775856924555608551532122942502696033"),
311 Fp(
"11811997307285544251176681325629039017467625014708607213193666012921830535998"),
318 Fp(
"933228262834212904718933563457318550549399284524392769385206412559597436928"),
319 Fp(
"13081617668227268048378253503661144166646030151223471427486357073175298320248"),
324 Fp(
"5029559281027098065112074313654538061170641740632027092904459697655977527307"),
325 Fp(
"8600928869174184710378059261155172010154737801304483073001259795547035852644"),
329 const std::string m_str(
"9347746330740818252600716999005395295745642941583534686803606077666502");
331 Fp(
"8336933749104329731435220896541057907796368507118046070748143351359530106012"),
332 Fp(
"4188048486869311245492662268177668835013141885357103548787568172806640854865"),
348 Fp P3[] = {
P[0],
P[1],
P[2], };
349 Fp PR[] = {
P[0],
P[1],
P[2], };
350 ECAdd(P3, P3, P2_ok);
368 Fp Pm[3], Pm_norm[3];
441 x.b_.
set(
"464652165165");
442 z.a_.
set(
"16798108731015832284940804142231733909889187121439069633032080833550314387514");
443 z.b_.
set(
"3717217321320");
449 std::ostringstream oss;
451 std::istringstream iss(oss.str());
463 Fp c1 = x.a_ /
Fp(2);
469 Fp c1 = x.b_ /
Fp(2);
475 Fp c1 = y.a_ /
Fp(2);
481 Fp c1 = y.b_ /
Fp(2);
487 Fp c1 = z.a_ /
Fp(2);
493 Fp c1 = z.b_ /
Fp(2);
499 Fp c1 = x.a_ /
Fp(4);
505 Fp c1 = x.b_ /
Fp(4);
511 Fp c1 = y.a_ /
Fp(4);
517 Fp c1 = y.b_ /
Fp(4);
523 Fp c1 = z.a_ /
Fp(4);
529 Fp c1 = z.b_ /
Fp(4);
561 static const Fp2 Qx =
Fp2(
562 Fp(
"13234664681033688271405396239524358974366484883419628236101274746557464997054"),
563 Fp(
"11347691494386824311357230151706543132011346014309658325337514955760433353199")
572 static const Fp2 Qy =
Fp2(
573 Fp(
"9427224573130940705767837740977388851395498800066112237265227139877389298881"),
574 Fp(
"8452141316509224651353689669356928563000175149166480473836682926961687453514")
584 static const Fp2 Q2x =
Fp2(
585 Fp(
"5299180442706306781938040029147283818308705141288620744338313273731299805815"),
586 Fp(
"15797930548095856607649462137302524883761892212429298307727251696384886639045")
595 static const Fp2 Q2y =
Fp2(
596 Fp(
"14682155566465612687855553028405011181016442868657350988232774125667855691350"),
597 Fp(
"16774596877583816470230777985570065066758171976339091353731418650582998086894")
612 Fp2(
Fp(
"11704862095684563340633177014105692338896570212191553344841646079297773588350"),
613 Fp(
"8109660419091099176077386016058664786484443690836266670000859598224113683590")),
614 Fp2(
Fp(
"13675004707765291840926741134330657174325775842323897203730447415462283202661"),
615 Fp(
"6686821593302402098300348923000142044418144174058402521315042066378362212321")),
627 const Fp2 P3_ok[] = {
628 Fp2(
Fp(
"5041208034834306969246893597801606913952969715168759592126996067188338654460"),
629 Fp(
"4745545055096211316438209286296610929317392331700796959265362461502810670741")),
630 Fp2(
Fp(
"4448845430036386900904134218385919238634516280940850750340057793276116990520"),
631 Fp(
"5381197710638591824110650873873102215710463161465576982098481156644922737066")),
638 const Fp2 PR_ok[] = {
639 Fp2(
Fp(
"4101018695001932981939478048097100312454053747763620019092459247845054185862"),
640 Fp(
"11837424651832479256515762856497142957022424405035735958314961199911873048158")),
641 Fp2(
Fp(
"4188277960223912253520496835244041970690458283101292677577969922331161931355"),
642 Fp(
"6626563699999679639856135562000857142994474772523438562835858347560344528530")),
646 const std::string m_str(
"9347746330740818252600716999005395295745642941583534686803606077666502");
647 const Fp2 Pm_ok[] = {
648 Fp2(
Fp(
"10441210346477881509066116513368913513335705597787319222238764774307447511387"),
649 Fp(
"14433824588814776544086946350203752791948488948859728417684455048057787177915")),
650 Fp2(
Fp(
"5562925282053339482485224304075873800061135879275456976861613117140339306723"),
651 Fp(
"4780189879307383623106336041945958171623286554407266664048019152689513531681")),
672 Fp2 P3_norm[3], PR_norm[3];
686 Fp2 Pm[3], Pm_norm[3];
750 for (
int i = 0; i < 6; i++) {
751 x.
get()[i] = i * i + 3;
760#ifdef MIE_ATE_USE_GMP
771 std::ostringstream oss;
773 std::istringstream iss(oss.str());
790 Fp2(
Fp(
"12962627302162075398060982177087436574303347298537835668202414221253817262982"),
791 Fp(
"138260844306952217670025767932179019912073169546101859135312230638880521223")),
792 Fp2(
Fp(
"15137160497776903814679214726809029070339754602997091488396727793679994724725"),
793 Fp(
"14585393257630973637130780517598702183004769121002667593088137712456098389147")),
794 Fp2(
Fp(
"11656022636984400462137420855351583248422833051633377387451406154513829093114"),
795 Fp(
"14215712895255419029580702653008196543286207503420913686381671784091829605544")));
797 "1593170926598915345387635677083748286590764833236455841205970156921632690659321696124459206976218892050264244158092130253877279907839544343324979280024170",
798 "1179973114230341892737360925692630156593789184269536881494768733457774943578761248088761269289336962320683158703377660715101868763181549734994595794867496",
799 "730145342724752832742804498354752537572280628992449438960103160339237082085998618512864763426475086477471191730731012602806937310004548457512536010563048",
800 "678118683224664762511490289199702755525092922001331540945747396044828904358828485331396580462479434002293484047506951365087686946333164073941237815303466",
801 "1696690105116639227371389908462484956149748096108668929604390112965542312011722226936838080163446882161586173219949938265621015171049147844994233756309066",
802 "67733454177668654989670636173597892971566229940879910979133487599488650994140729503900163935167021366038874739997773956034575689900205013416256257888322");
804 Fp2(
Fp(
"13266032064412835795130953448702250621050762510696965292045893361178860841079"),
805 Fp(
"2457069570102593370680131966272186058752442119075136300728910430721054975883")),
806 Fp2(
Fp(
"2761323283613335519656714595170176518640718973086035562998271277678441691369"),
807 Fp(
"9282239544249417776161170354699989681427448957391036300962080470210029743316")),
808 Fp2(
Fp(
"4725335130491002940371667092034595414883167034697622603206446595963780685950"),
809 Fp(
"2979604114551910299899042707207603351108418195709860388438523763202896562826")));
811 "1475839844663843322570757741744775997036014731165662766646651170904291281982509370757030826186551260691254724613316384521255185802946693994015137182068602",
812 "1095370597739171250835471130891927869346414000670922062465412467538839645554804526075383358963227758462571697459677545719232104735169846503013457660892884",
813 "536047623091184724949149589675730696115091482580183754959193574690322789326610874996202176921473611369946983196347243075470791570525589963488361345383304",
814 "567095369910236561517167429427649270237483207499847850016456655352630986857858611181208043791533419484288551607360907558060915416405739300095090914524646",
815 "1628045414693061051387160519487414991569044842223778536119706327028677432835046952047761290724596114203937423373736927070986873116393928193270995863382370",
816 "113601886886856063908255915522830311745119439542360068010955258226612862901220453756679629604364967513217403777663391468064348420745734171787344796709574");
826 const Fp6Dbl cd = ad + bd;
840 const Fp6Dbl cd = ad - bd;
861 for (
int i = 0; i < 12; i++) {
872 for (
int i = 0; i < 12; i++) {
876#ifdef MIE_ATE_USE_GMP
880 p12 = p12 * p12 * p12;
888 std::ostringstream oss;
890 std::istringstream iss(oss.str());
902 std::string x_ok[] = {
903 "11740569797851521013113382206139723952380476000114006726254700017011388077491",
904 "11620869091920297152310912851876223249241005004927120638208161874259694264776",
905 "14319816424335732586640646744712820835577263950059423761702049659454143614010",
906 "8979195516353115834499099104570340580610233612320353839807503737299124538894",
907 "3889724809319970439398470559040488185853720726993744629936064081043226370937",
908 "8413606802647893249443694454915434425270568587052196647221488597304121045130",
909 "14595160807872212739731328980223779718645553907712177545489677083052892894971",
910 "14502774460357020920607411114414652729864247679483682272558415181562578814999",
911 "10561873726035110127922260604858986830025105803068865817827274807245635306750",
912 "7550390871387103641373102946170924993232803081589755675446081315707092125599",
913 "6140564006391685719531664678338338121143689549850528456971885232802932902162",
914 "15817781432103820015704945553128688539437475919918982282164580563407301207430",
918 for (
int i = 0; i < 12; i++) {
919 z.get()[i] =
Fp(x_ok[i]);
924 for (
int i = 0; i < 12; i++) {
931 mie::Vsint d_prime = (2 * zi) * (6 * zi * zi + 3 * zi + 1);
941 for (
size_t i = 0; i < 12; i++) {
967 Fp(
"1218653166067285584538203738497237160646510048316462546675922230477971988366"),
968 Fp(
"13444680966039708564821554178786623445404802733727517756140842427775282241991"));
970 Fp(
"14669021325553969631665050171167465779242435633491920423094037145439504174348"),
971 Fp(
"771665946433473991711581179554051515057882422398978711857886722975787742693"));
973 Fp(
"5083654211557558794221004641727153878275981283694826539168100383303202382274"),
974 Fp(
"6366225659089551329035322836142125548492356702076290974152251785589487583351"));
975 Fp2 Q2[] = { Q[0], Q[1], Q[2], };
1005 Fp2(
Fp(
"538403429049656139897565072692893539987872088302878297862474357627057534036"),
1006 Fp(
"9360831036830943010552886973925002873262696706980698595440552561606683082311")),
1007 Fp2(
Fp(
"4602226271967538444445722209125398887820203020623789000433097490686198967692"),
1008 Fp(
"10027082368454222153717339435200994429592852929609246856551738735310444995281")),
1015 const Fp2 RQ_ok[] = {
1016 Fp2(
Fp(
"14462635707798746157040779719592332683099281599171708385749388482446745043127"),
1017 Fp(
"5086071869627888235657453291665320777682769673183769388625923076659929904768")),
1018 Fp2(
Fp(
"16071875127812105172451027231039463141848166104557696531987123967356838839389"),
1019 Fp(
"15279844061281116178616101791776992126994407482416317579299271742300496066177")),
1023 const Fp2 l00_ok(
Fp(
"10013952835140506910916067999531081753178250370402232448154990388205483309972"),
1024 Fp(
"4926609310552091279051699015655777273195016616696233579052261219295065454280"));
1025 const Fp2 l02_ok(
Fp(
"9649996602326804522644231063703979927150591558884646473664259298382380662378"),
1026 Fp(
"13648226627125837280213504610543602176703831560553537083503603809375238781189"));
1027 const Fp2 l11_ok(
Fp(
"10422676207793898611344309297861346302460414709615008088696917811505787281979"),
1028 Fp(
"7036010756497237943264447921878652888644981129674790435334341908753079422899"));
1029 Fp2 RQ[] = {
R[0],
R[1],
R[2], };
1052 for (
int i = 0; i < 12; ++i) {
1079 for (
int i = 0; i < 12; ++i) {
1105 for (
int i = 0; i < 12; ++i) {
1125 for (
int i = 0; i < 12; ++i) {
1150 Fp2(
Fp(
"2056759109515975861665426147192151608007308721500683629663464772885511939168"),
1151 Fp(
"10296094419291805247741898368672988774667071764149880389566192920518825046253")),
1152 Fp2(
Fp(
"15318789889948026269195465641311637076887470214980886516517795245676250468201"),
1153 Fp(
"16086843419903922136591069704206201345656058171834106763866049911942744484945")),
1160 for (
size_t i = 1; i < 12; ++i) {
1178 const Fp2 Qp2_ok[] = {
1179 Fp2(
Fp(
"10065458361706171050734313676266120070744817595308631072199963185069217686139"),
1180 Fp(
"3393658127113032111918147843333039169870532385628727893932735697426808572356")),
1181 Fp2(
Fp(
"7370884157884891579172966401254345058493688321372957611668488286195364565842"),
1182 Fp(
"8345967414506607633587114472874805346889011972272589375097032499111066411209")),
1189 for (
size_t i = 1; i < 6; ++i) {
1218 for (
int j = 0;
j < 4;
j++) {
1219 double begin = GetCurrTime();
1221 const int N = 10000;
1224 for (
int i = 0; i <
N; i++) {
1229 double end = GetCurrTime();
1230 printf(
"opt_ate:%.2fclk(N=%d) ", clk.
getClock() /
double(
N),
N);
1231 printf(
"%.3fmsec\n", (end - begin) * 1e3 /
N);
1255 x.
set(
"13235535167791909954945079826683319167288269422503395778717464766711290103089");
1256 y.set(
"12009422934659625156361067360716584218353200927749721008493193292779219981220");
1265 for (
int i = 0; i < 100000; i++) {
1274 printf(
"err %d\n", i);
1275 std::cout <<
"x=" << y << std::endl;
1276 std::cout <<
"1=" << x << std::endl;
1277 std::cout <<
"2=" << z << std::endl;
1301 {
"12345",
"6789",
"19134" },
1302 {
"0x2523648240000001ba344d80000000086121000000000013a700000000000012",
"1",
"0" },
1303 {
"0x2523648240000001ba344d80000000086121000000000013a700000000000012",
"2",
"1" },
1304 {
"0x2523648240000001ba344d80000000086121000000000013a700000000000012",
"0x2000000000000000000000000000000000000000000000000000000000000000",
"0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" },
1305 {
"0x2523648240000001ba344d80000000086121000000000013a700000000000012",
"0x2523648240000001ba344d80000000086121000000000013a700000000000012",
"0x2523648240000001ba344d80000000086121000000000013a700000000000011" },
1324 const size_t UnitLen =
sizeof(
mie::Unit) * 8;
1326 static bool isFirst =
true;
1340 const size_t n = 256 / UnitLen;
1342 for (
size_t i = 0; i < n; i++) {
1350 const size_t n = 256 / UnitLen;
1352 for (
size_t i = 0; i < n; i++) {
1353 Unit t = y.size() > i ? y[i] : 0;
1385 t = (
p - 1) * (
p - 2);
1399 "0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
1400 "0x000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
1403 "0x2370fb049d410fbe4e761a9886e502417d023f40180000017e805370fb049d410fbe4e761a9886e50241370fb049d410fbe4e761a9886e502410000000003334",
1404 "0x2370fb049d410fbe4e761a9886e502417d01a9886e502417d023f40180000017e805370fb049d410fbe4e761a9886e50241370fb049d410fbe4e761a9886e502",
1407 "0x70fb049d410fbe4e761a9886e502417d023f40180000017e805370fb049d410fbe4e761a9886e50241370fb049d410fbe4e761a9886e502410000000003334",
1408 "0x70fb049d410fbe4e761a9886e502417d01a9886e502417d023f40180000017e805370fb049d410fbe4e761a9886e50241370fb049d410fbe4e761a9886e502",
1420 y.set(
s.const_ptr(),
Fp::N * 2);
1429 const char* as =
"0x826db9eced02a46cccc83dd73d7ee9a1ac44da788daff6d90f91e0a49dfcd5e";
1430 const char* ads =
"0x10e6616f9d658d62913a152516a1930d3b95eb1c4f69dd334c286bf2e322e34fab44d283e8ef4e6491c7fef40ca63362182fb3be3aad38785109f6b1a568c24";
1431 const char* bs =
"0xbb4674a8b1fc189e5402353d6d991585e9a93a1fccb6bb48991033aa064661f";
1432 const char* bds =
"0x18440289e040f84f0f8bb27b1f5607ad646bfeccbd737684bfdfeae964fd3bb4c5bb9f032044cb265788331de43a90e842b3b1e88eb9817676c8fe4934a8632";
1438 const FpDbl ad(ads);
1439 const FpDbl bd(bds);
1448 const char* cs =
"0x13db42e959efebd0b20ca7314ab17ff2795ee14985a66b221a8a2144ea44337d";
1449 const char* cds =
"0x292a63f97da685b1a0c5c7a035f79abaa001e9e90cdd53b80c0856dc48201f04710071870934198ae9503211f0e0c44a5ae365a6c966b9eec7d2f4fada11256";
1451 const FpDbl bd(bds);
1452 const FpDbl cd(cds);
1462 const char* a2s =
"0x104db73d9da0548d999907bae7afdd3435889b4f11b5fedb21f23c1493bf9abc";
1463 const char* a2ds =
"0x21ccc2df3acb1ac522742a4a2d43261a772bd6389ed3ba669850d7e5c645c69f5689a507d1de9cc9238ffde8194c66c4305f677c755a70f0a213ed634ad1848";
1465 const FpDbl a2d(a2ds);
1494 const char* cds =
"0x2414fe6b4629a72b9120ac2dae95e6d78d67a14e3b096240723d7940d1cdd1de054bb2d7c1710b19b6e38010bf359cc9de7d04c41c552c787aef6094e5a973dc";
1496 const FpDbl cd(cds);
1524 const char* as =
"121311891827543957596909773033357421921766710831251548159956972926334483720";
1525 const char* bs =
"4250864531853689066995024032521947485438864668614304877798137152237875276659";
1526 const char* cs =
"6130604890643875446660330430071165035373943332034046310134586930404838747383";
1527 const char* cds =
"515680418261778013941729031428717927558491170998041032206579966438977948938767928415397290640890254719024071470552752738210640396059153581666931491480";
1552 Fp(
"11670776793662220163659381041821071042189526350599853354176183114948400476854"),
1553 Fp(
"16720058771622958239847090974706681762823587016948988460920422070188238301920"));
1555 "43365626183362451296144273927903491721178106337019849480533874426567558421999199112585229298328261724838400974530624189976754698034274243846379138263798",
1556 "146841205705169330240495767599698200797060877501089277217144673667296710106404940569619328012833781922979497600339156163032435697636816808188620084421142");
1564 const Fp2 b(
Fp(
"0"),
Fp(
"1"));
1573 const Fp2 b(
Fp(
"123"),
Fp(
"456"));
1588 Fp(
"0x19cd6cf2a9dc668d011b54f13a92591457dcdd5b946cf92af95ca820077972b6"),
1589 Fp(
"0x24f737c85b07fa5103d2dfa5a44d0a9c2ee6138de25c709cdd2f526dab19eae0"));
1591 "0xd3f77def5c0d18d7f1449afb9c117dfeb51c1fe1208d056ad21c679c5ec71c4642b58a8c4f44ce7ed74f49cf92ae8428d5741cc65ee00bf090ec506c952af6",
1592 "0x2cdbeaf4c89f0e69e52a72dddfc13f8ca9ee571933484140d9e3c395bf9056b44719b54117e71bb62f41ed10ccec31240535f52ea74b4829c2a5fded0e52216");
1594 Fp(
"0x26dbd9018fa1dc1a7b555a80895ba00a4fbfb7ba8bcf7d3deb53452d65180c0"),
1595 Fp(
"0x20618bd9d595b08223a03e66294e8a4a10e688a696c0af9daca0faa041d884a7"));
1597 "0x2dfa943203451554f15ba5a92717a16a0f9a97dbec7d0dae70dc2ea57ff90d04e8c9f1ebfa99415ad41e9ac35c33b297b9fb4da61ff1b550dfc28c584e912d8",
1598 "0x23f0eb05bb2bc09bd2f9b1a71d6e2b94b28a4d1b6321dcfd44e8e72c1d7a992ad361a7b73aaf1cf5feca656ac0bddf20f549594ae1e65e9e567839d4f482176");
1621 const Fp2 c =
a + b;
1623 Fp(
"12769297135811847170252627178279277434270214741555565448692771341243685466998"),
1624 Fp(
"14568310576098881131032985368780468502614655635084870456076855826537822449524"));
1634 const Fp2 c =
a - b;
1680 Fp(
"0x19cd6cf2a9dc668d011b54f13a92591457dcdd5b946cf92af95ca820077972b6"),
1681 Fp(
"0x24f737c85b07fa5103d2dfa5a44d0a9c2ee6138de25c709cdd2f526dab19eae0"));
1683 "0xd3f77def5c0d18d7f1449afb9c117dfeb51c1fe1208d056ad21c679c5ec71c4642b58a8c4f44ce7ed74f49cf92ae8428d5741cc65ee00bf090ec506c952af6",
1684 "0x2cdbeaf4c89f0e69e52a72dddfc13f8ca9ee571933484140d9e3c395bf9056b44719b54117e71bb62f41ed10ccec31240535f52ea74b4829c2a5fded0e52216");
1686 Fp(
"0x26dbd9018fa1dc1a7b555a80895ba00a4fbfb7ba8bcf7d3deb53452d65180c0"),
1687 Fp(
"0x20618bd9d595b08223a03e66294e8a4a10e688a696c0af9daca0faa041d884a7"));
1689 "0x2dfa943203451554f15ba5a92717a16a0f9a97dbec7d0dae70dc2ea57ff90d04e8c9f1ebfa99415ad41e9ac35c33b297b9fb4da61ff1b550dfc28c584e912d8",
1690 "0x23f0eb05bb2bc09bd2f9b1a71d6e2b94b28a4d1b6321dcfd44e8e72c1d7a992ad361a7b73aaf1cf5feca656ac0bddf20f549594ae1e65e9e567839d4f482176");
1700 const Fp2 c =
a * b;
1708 const Fp2 c =
a *
a;
1721 const mie::Vuint p_ok(
"16798108731015832284940804142231733909889187121439069848933715426072753864723");
1728 const mie::Vuint r_ok(
"16798108731015832284940804142231733909759579603404752749028378864165570215949");
1733 const Fp Z_ok(
"1807136345283977465813277102364620289631804529403213381639");
1734 Fp t = Z_ok * Z_ok + Z_ok + 1;
1736 t = Z_ok * Z_ok * Z_ok;
1748 Fp(
"16798108731015832283133667796947756444075910019074449559301910896669540483083"));
1754 Fp(
"16226349498735898878582721725794281106152147739300925444201528929117996286405"),
1755 Fp(
"16226349498735898878582721725794281106152147739300925444201528929117996286405"));
1764#ifdef BN_SUPPORT_SNARK
1769 const Fp2_str gammar_str[] = {
1771 "12310438583873020660552735091161044116898065562217439662059245424880585960937",
1772 "4487670147142811624388069051070689792991121559221630186874470001192167903786"
1776 "16798108731015832283133667796947756444075910019074449559301910896669540483083"
1779 "16226349498735898878582721725794281106152147739300925444201528929117996286405",
1780 "16226349498735898878582721725794281106152147739300925444201528929117996286405"
1783 "16798108731015832283133667796947756444075910019074449559301910896669540483084",
1787 "11738679351593087254194652674723591313161026180079295257327058927925828382619",
1788 "5059429379422745030746151467508142596728160941359774591606656498146925482104"
1793 for (
size_t i = 0; i <
sizeof(gammar_ok) /
sizeof(*gammar_ok); ++i) {
1794 gammar_ok[i].get()[0].
set(gammar_str[i].
a);
1795 gammar_ok[i].get()[1].
set(gammar_str[i].b);
1797 if (gammar[i] != gammar_ok[i]) {
1805 const Fp2_str gammar2_str[] = {
1807 "1807136345283977465813277102364620289631804529403213381640",
"0"
1810 "1807136345283977465813277102364620289631804529403213381639",
"0"
1813 "16798108731015832284940804142231733909889187121439069848933715426072753864722",
"0"
1816 "16798108731015832283133667796947756444075910019074449559301910896669540483083",
"0"
1819 "16798108731015832283133667796947756444075910019074449559301910896669540483084",
"0"
1824 for (
size_t i = 0; i <
sizeof(gammar2_ok) /
sizeof(*gammar2_ok); ++i) {
1825 gammar2_ok[i].get()[0].
set(gammar2_str[i].
a);
1826 gammar2_ok[i].get()[1].
set(gammar2_str[i].b);
1828 if (gammar2[i] != gammar2_ok[i]) {
1836 const Fp2_str gammar3_str[] = {
1838 "571759232279933406358082416437452803737039382138144404732186496954757578318",
1839 "16226349498735898878582721725794281106152147739300925444201528929117996286405"
1843 "571759232279933406358082416437452803737039382138144404732186496954757578318",
1844 "571759232279933406358082416437452803737039382138144404732186496954757578318"
1847 "16798108731015832284940804142231733909889187121439069848933715426072753864722",
"0"
1850 "16226349498735898878582721725794281106152147739300925444201528929117996286405",
1851 "571759232279933406358082416437452803737039382138144404732186496954757578318"
1856 for (
size_t i = 0; i <
sizeof(gammar3_ok) /
sizeof(*gammar3_ok); ++i) {
1857 gammar3_ok[i].get()[0].
set(gammar3_str[i].
a);
1858 gammar3_ok[i].get()[1].
set(gammar3_str[i].b);
1860 if (gammar3[i] != gammar3_ok[i]) {
1872 Fp(
"12723517038133731887338407189719511622662176727675373276651903807414909099441"),
1873 Fp(
"4168783608814932154536427934509895782246573715297911553964171371032945126671")
1876 Fp(
"13891744915211034074451795021214165905772212241412891944830863846330766296736"),
1877 Fp(
"7937318970632701341203597196594272556916396164729705624521405069090520231616")
1882 Fp(
"1674578968009266105367653690721407808692458796109485353026408377634195183292"),
1883 Fp(
"8299158460239932124995104248858950945965255982743525836869552923398581964065"),
1892 printf(
" e(g2, 0) = 1 : %s\n", e == 1 ?
"ok" :
"ng");
1898 printf(
" e(0, g1) = 1 : %s\n", e == 1 ?
"ok" :
"ng");
1917 printf(
" e(g2, g1) : %s\n", e1 == e ?
"ok" :
"ng");
1924 const char* ads =
"0x10e6616f9d658d62913a152516a1930d3b95eb1c4f69dd334c286bf2e322e34fab44d283e8ef4e6491c7fef40ca63362182fb3be3aad38785109f6b1a568c24";
1925 const char* bds =
"0x18440289e040f84f0f8bb27b1f5607ad646bfeccbd737684bfdfeae964fd3bb4c5bb9f032044cb265788331de43a90e842b3b1e88eb9817676c8fe4934a8632";
1926 FpDbl ad(ads), bd(bds);
1938 for (
int i = 0; i < 6; i++) {
1939 x.
get()[i] = i * i + 3;
1950 for (
int i = 0; i < 12; i++) {
1951 x.get()[i] = i * i + 3;
1961 const mie::Vuint m(
"9347746330740818252600716999005395295745642941583534686803606077666502");
1971 const mie::Vuint m(
"9347746330740818252600716999005395295745642941583534686803606077666502");
1980 Fp6Dbl x(
"999111",
"999222",
"999333",
"999444",
"999555",
"999666");
1981 Fp6Dbl y(
"1999111",
"9919222",
"9199333",
"9919444",
"9919555",
"9919666");
1983 for (
int i = 0; i < 6; i++) {
1984 a.get()[i] = i * i + 3;
2011 Fp yy = x * x * x + 2;
2019 puts(
"no squareRoot");
2021 for (
int i = 1; i < 100; i++) {
2032 bool useMulx =
true;
2033 bool allBench =
false;
2036 if (argc > 1 && strcmp(*
argv,
"-m") == 0) {
2040 if (argc > 1 && strcmp(*
argv,
"-mulx") == 0) {
2042 useMulx = atoi(*
argv) == 1;
2044 if (strcmp(*
argv,
"-all") == 0) {
2048 printf(
"bn [-m (0|1)][-mulx (0|1)][-all]\n");
2090 printf(
"err=%d(test=%d)\n", s_errNum, s_testNum);
2093}
catch (std::exception& e) {
2094 fprintf(stderr,
"std::exception %s\n", e.what());
measure exec time of function
#define CYBOZU_BENCH(msg, func,...)
#define CYBOZU_BENCH_C(msg, _N, func,...)
void montgomery(mie::Vuint &z, const mie::Vuint &x, const mie::Vuint &y)
void testECOperationsG2()
void testFp2Dbl_add_sub(bool allBench)
void test_compressed_fixed_power(bool allBench)
void test_pointAddLineEval(bool allBench)
void test_pointDblLineEval(bool allBench)
void benchAll(bool benchAll)
void test_FrobEndOnTwist_2(bool allBench)
void test_FrobEndOnTwist_1(bool allBench)
void test_compression(bool allBench)
void test_sqru(bool allBench)
void testECOperationsG1(bool allBench)
void test_multi(const bn::CurveParam &cp)
void SetJacobi(F out[3], const F *in)
void test_compressed_square(bool allBench)
void testFp2Dbl_mul_mod()
void set(const std::string &str)
std::string toString() const
static void(* add)(Fp &out, const Fp &x, const Fp &y)
static void(* mul)(Fp &out, const Fp &x, const Fp &y)
static void inv(Fp &out, const Fp &x)
static const mie::Vuint & getModulo()
static void divBy2(Fp &z, const Fp &x)
static void(* neg)(Fp &out, const Fp &x)
static void divBy4(Fp &z, const Fp &x)
static void(* sub)(Fp &out, const Fp &x, const Fp &y)
static MIE_FORCE_INLINE void setDirect(Fp &out, const T &in)
static bool squareRoot(Fp &y, const Fp &x)
static void absolute(V &out, const VsintT &in)
std::string toString(int base=10) const
LOGGING_API void printf(Category category, const char *format,...)
void millerLoop(Fp12 &f, const std::vector< Fp6 > &Qcoeff, const Fp precP[2])
void precomputeG2(std::vector< Fp6 > &coeff, Fp2 Q[3], const Fp2 inQ[3])
void ECDouble(FF *out, const FF *in)
bool isOnTwistECJac3(const Fp2T< Fp > *P)
bool isOnECHom3(const Fp *P)
void copy(FF *out, const FF *in)
void FrobEndOnTwist_2(Fp2T< Fp > *Q, const Fp2T< Fp > *P)
void ScalarMult(FF *out, const FF *in, const INT &m)
bool isOnTwistECHom3(const Fp2T< Fp > *P)
void NormalizeJac(FF *out, const FF *in)
void NormalizeHom(FF *out, const FF *in)
bool isOnTwistECHom2(const Fp2T< Fp > *P)
void ECAdd(FF *out, const FF *a, const FF *b)
bool isOnECJac3(const Fp *P)
bool isOnECHom2(const Fp *P)
void FrobEndOnTwist_1(Fp2T< Fp > *Q, const Fp2T< Fp > *P)
void opt_atePairingJac(Fp12T< Fp6T< Fp2T< Fp > > > &f, const Fp2T< Fp > _Q[3], const Fp _P[3])
const CurveParam CurveFp254BNb
void opt_atePairing(Fp12T< Fp6T< Fp2T< Fp > > > &f, const Fp2T< Fp > Q[2], const Fp P[2])
T power(const T &x, const S &y)
VuintT< local::FixedBuffer< mie::Unit, MIE_ZM_VUINT_BIT_LEN > > Vuint
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
_W64 unsigned int uintptr_t
static void fixed_power(Fp12 &z, const Fp12 &x)
static void(* square_n)(CompressT &z, int n)
static void(* mul)(Fp12T &z, const Fp12T &x, const Fp12T &y)
static void add(Fp12T &z, const Fp12T &x, const Fp12T &y)
static void sub(Fp12T &z, const Fp12T &x, const Fp12T &y)
static void(* square)(Fp12T &z)
static void(* mod)(Fp2T &z, const Dbl &x)
void setDirect(const mie::Vuint &a, const mie::Vuint &b)
static void(* square)(Dbl &z, const Fp2T &x)
static void(* mulOpt1)(Dbl &z, const Fp2T &x, const Fp2T &y)
static void(* mulOpt2)(Dbl &z, const Fp2T &x, const Fp2T &y)
static void neg(Fp2T &z, const Fp2T &x)
static void(* square)(Fp2T &z, const Fp2T &x)
static void mul_Fp_1(Fp2T &z, const Fp &y_b)
static void(* addNC)(Fp2T &z, const Fp2T &x, const Fp2T &y)
static void(* divBy2)(Fp2T &z, const Fp2T &x)
static void divBy4(Fp2T &z, const Fp2T &x)
static void(* mul_Fp_0)(Fp2T &z, const Fp2T &x, const Fp &b)
static void(* sub)(Fp2T &z, const Fp2T &x, const Fp2T &y)
static void(* mul_xi)(Fp2T &z, const Fp2T &x)
static void(* add)(Fp2T &z, const Fp2T &x, const Fp2T &y)
static void(* mul)(Fp2T &z, const Fp2T &x, const Fp2T &y)
static void sub(Dbl &z, const Dbl &x, const Dbl &y)
static void(* mul)(Dbl &, const Fp6T &x, const Fp6T &y)
static void subNC(Dbl &z, const Dbl &x, const Dbl &y)
static void neg(Dbl &z, const Dbl &x)
static void mod(Fp6T &z, const Dbl &x)
static void addNC(Dbl &z, const Dbl &x, const Dbl &y)
static void add(Dbl &z, const Dbl &x, const Dbl &y)
static void square(Fp6T &z, const Fp6T &x)
static void pointAddLineEval(Fp6T &l, Fp2 *R, const Fp2 *Q, const Fp *P)
static void(* pointDblLineEval)(Fp6T &l, Fp2 *R, const Fp *P)
static void(* sub)(Fp6T &z, const Fp6T &x, const Fp6T &y)
static void(* add)(Fp6T &z, const Fp6T &x, const Fp6T &y)
static void(* mul)(Fp6T &z, const Fp6T &x, const Fp6T &y)
static void init(const CurveParam &cp, int mode=-1, bool useMulx=true)
static MIE_FORCE_INLINE void setDirect(Dbl &out, const mie::Vuint &in)
static void(* mod)(Fp &z, const Dbl &x)
mie::Vuint getDirect() const
static void(* mul)(Dbl &z, const Fp &x, const Fp &y)
std::string toStr(int base=10) const
const Point & selectPoint(const bn::CurveParam &cp)
void bt(const Operand &op, const Reg ®)