diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2025-07-29 22:54:38 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2025-07-29 22:54:38 +0200 |
| commit | c2f1680b6718a01c128fbb83ba3c50b70c3c5d7c (patch) | |
| tree | c22e558df7bfd2bfaa5a8b8176d78d674c4ed053 /test/test_fp12.ml | |
| parent | 771605c6264289210a097dd5bbabbd709f549205 (diff) | |
Refactor Fields to be Functor Based
Prime fields and polynomial extension fields are now functor based.
That is, you define field parameters and a functor will produce a
field module.
This is the first step to moving all BLS12-381 pairing definitions to
a single module, instead of splitting them. This makes the "this is
the curve and its pairing" very central, with the field and curve
modules being generic over their respective parameterization.
Added field exponentiation - and found out that Zarith supports
negative exponents, and `powm x ~-1 p` is a much more efficient way of
computing a field inverse (tests run ~5 times quicker).
Diffstat (limited to 'test/test_fp12.ml')
| -rw-r--r-- | test/test_fp12.ml | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/test/test_fp12.ml b/test/test_fp12.ml index 6807d0f..040bea8 100644 --- a/test/test_fp12.ml +++ b/test/test_fp12.ml @@ -357,6 +357,126 @@ let test_inv () = Alcotest.(check fp12) "equals" Fp12.one (Fp12.mul a (Fp12.inv a)); Alcotest.(check fp12) "equals" Fp12.zero (Fp12.inv Fp12.zero) +let test_pow () = + Alcotest.(check fp12) "equals" Fp12.zero Fp12.(pow zero Z.zero); + let a = + f + [| + "3243946662156380360401533691271902622351216700088828801371694425169510018967527607195510653472613127628684457518895"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + |] + in + let exp = + Z.of_string + "4786395996711131997851369005645373402034333833710769512437307609838449510878590131404494026990569494826881867762725" + in + Alcotest.(check fp12) + "equals" + (f + [| + "93505687369509791585523581418311859879808007995075528779053674394162338631824811308905650303250543152947425931864"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + "0"; + |]) + (Fp12.pow a exp); + let a = + f + [| + "581184364395709998532427920065204131097627572243414467773984372410930594032604783915123507383421084980957463121074"; + "2632456401246680983721085320745914343873827696323764944744909114035458049120708554529974176475513328251247147836109"; + "24345862764080708067934017839092765694372561325369394824358778494499957277645028739526134943517661202607195681874"; + "2654060922890107462430619070159723322802664028016101999580163834909869729412457392616437464520060328985029635369899"; + "1234199423993097969388562903710956069098291646153620227683382690044719081978395203667156040012577821217408074874361"; + "2327254416315986733730126201873032747694702671280192172720971579574777885381686040178833996348099474109238030990438"; + "308456031957100469469026660074251580523576344563743597543846510047273452631171833183938660416210087947577740395957"; + "2070641978992199849713397118375564104488717989981967333699186001535709721572872457631373642046564356166890693724525"; + "1023115789687830757320296131233972372806693488520357178009183008096126250029658521153644503180508667254344969657933"; + "2771708931742116174029064994358808349206398185573306516963793281889674054650455265946393136685382711512086095486153"; + "2415935655833924444587585147004375260727208675807945593059746951931040642185593984108205203840145367007729879698502"; + "3747451142253730570511648553667071849534921523034778216681941333936844891879955748062523628659060692375379991747670"; + |] + in + let exp = + Z.of_string + "4635419594850854522995180126268396373397782627168612260872144180754217625899496757038300024715816053523747817924459" + in + Alcotest.(check fp12) + "equals" + (f + [| + "2438171351058836832369911502732339870005598901564531105907103021028264831134869120777132856961562084121531742783535"; + "1097012181782714231544213745005695044345330467519225986859898554381542803267478493509808468367873481243049888913481"; + "3441010539322298489597317353107916838786869966838301203783777602998428100162154678688942721030940877368891071276372"; + "3593500705793409307232272185743009596418063943678130894945284701622786996176800414429475246325197262589426620173858"; + "964224237371176259088842629766232638500742818372760021780790193279027515591323535144113122546903105322182676907862"; + "3684244022634105112704496490992911506549020986026906093605209267003449476801356226047451076092998396677303085121809"; + "1965489668709265814072193089447911761432074428191996806738429523212667383283896153392549640989745803011537725980936"; + "2551726489979038828948495463625657418800786828538215581426649722088527266035405451818233303351446481412104533533364"; + "3964495084560562221340255167677547850832406051894824346109563370270525276347653640848719119649764365606267783038033"; + "2866503721379455577991619765590795362830616055864444930975126436054827719887566874168103260196645293003945616411536"; + "3692743837621692913449496726591269549647593441723033661300120151666779123446873010864470091860812844172699271693312"; + "982267349706018011588333944011806032269384205274857614588482845900836245714620157539009784576658152730964002634141"; + |]) + (Fp12.pow a exp); + let a = + f + [| + "517554183474565900946818039009633520572576806453115590677457726872451536258897896625585575140288687629345028556687"; + "804192970074616669533467647394379953654107179940186436178127026151992832864814401261296545974230007591965462103056"; + "2503639195058255885119003112929617238334162143220485778531810479310221150572133796548682240164964042178173586634141"; + "3431424336172958736295465509239701653584585432691078671221927189971363708827182094133397404147985425759490280378706"; + "953285779753237668442931840498081005646288619461422772012651004147820333482663712112141889782072093341181928817686"; + "3711169283099264542922435637442151317386528554971948266366687273289063043069918796381040804380529583766240342013513"; + "1791471994755958914271980585077660655286607863946512699149289608031009310612204307552330931844413095653965765327758"; + "3008466831712656130005727986998419703746889516538057258400795824261402981674823740163694825164287433960375111029620"; + "2387950836082387027973169497589631641161156457719183784873528937718893927814612246905389531036355149097312143657775"; + "2571808137740754351942389542927111675955441592454531894705216542351374812484180762764896669806426501173261426585268"; + "549253400379930422329621510413460874866344551229142442812532136611231511345405457803439222143097301551334881103094"; + "597296218403409837200855257971214266530681970030808478517056660057461542523203616410446873972385495777887414127138"; + |] + in + let exp = + Z.of_string + "-3667081312888142516070958782736288102210645458674689131546095190584164448587870524463541023829639780830349310002188" + in + Alcotest.(check fp12) + "equals" + (f + [| + "3778225024695192726450053538672271960465063334975822169885989605299905198600554611286690862277006898262692393173204"; + "1100678303917569754073715448443872121669768946382076991745600699949236869847922040927866727318805460066075347408056"; + "2575434022406640282647396997235375073255786637198979034483306201439250156054828532722759380529451673142400582558319"; + "141030785938329416380297660581416487681561455268895551048692156869124237201619702441378197235235154631299159110590"; + "3818386169472484912594997885361299732069360949602244204012368075962936301921746721896556883215834634668221667632031"; + "431068183083318414141019877550130820538186918053706113005381257264282126636474327359650258197178732294565622826902"; + "1444821826621931088190793564436822532840471337479364966075772563973043866193644452117965281678067289101527064145382"; + "326705016751523330711231810902065778158048061222978975631028088465968483398111642382574581611053002594065419984370"; + "2590558016277599639325970669172815909591831863058757858275263285669958704344475473881605742238108942152775575819921"; + "860801923520796484127388756389887657380482233286294407214932626052789638279849320104552687581993207164608583794675"; + "3397659117957673478090316761897634222297760936461824966172431604521997466498354729809670376239331734393424886923691"; + "1809397363561603126960710152825757691419619983666237192735364118138290701919129233449204965301855024045028933401664"; + |]) + (Fp12.pow a exp) + let tests = Alcotest. [ @@ -367,4 +487,5 @@ let tests = test_case "Division" `Quick test_div; test_case "Additive Inverse" `Quick test_neg; test_case "Multiplicative Inverse" `Quick test_inv; + test_case "Exponentiation" `Quick test_pow; ] |
