curve25519.c 192 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062
  1. // The MIT License (MIT)
  2. //
  3. // Copyright (c) 2015-2016 the fiat-crypto authors (see the AUTHORS file).
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all
  13. // copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. // SOFTWARE.
  22. // Some of this code is taken from the ref10 version of Ed25519 in SUPERCOP
  23. // 20141124 (http://bench.cr.yp.to/supercop.html). That code is released as
  24. // public domain but parts have been replaced with code generated by Fiat
  25. // (https://github.com/mit-plv/fiat-crypto), which is MIT licensed.
  26. //
  27. // The field functions are shared by Ed25519 and X25519 where possible.
  28. #include <openssl/curve25519.h>
  29. #include <assert.h>
  30. #include <string.h>
  31. #include <openssl/cpu.h>
  32. #include <openssl/mem.h>
  33. #include <openssl/rand.h>
  34. #include <openssl/sha.h>
  35. #include "internal.h"
  36. #include "../../crypto/internal.h"
  37. static const int64_t kBottom25Bits = INT64_C(0x1ffffff);
  38. static const int64_t kBottom26Bits = INT64_C(0x3ffffff);
  39. static uint64_t load_3(const uint8_t *in) {
  40. uint64_t result;
  41. result = (uint64_t)in[0];
  42. result |= ((uint64_t)in[1]) << 8;
  43. result |= ((uint64_t)in[2]) << 16;
  44. return result;
  45. }
  46. static uint64_t load_4(const uint8_t *in) {
  47. uint64_t result;
  48. result = (uint64_t)in[0];
  49. result |= ((uint64_t)in[1]) << 8;
  50. result |= ((uint64_t)in[2]) << 16;
  51. result |= ((uint64_t)in[3]) << 24;
  52. return result;
  53. }
  54. #define assert_fe(f) do { \
  55. for (unsigned _assert_fe_i = 0; _assert_fe_i< 10; _assert_fe_i++) { \
  56. assert(f[_assert_fe_i] < 1.125*(1<<(26-(_assert_fe_i&1)))); \
  57. } \
  58. } while (0)
  59. #define assert_fe_loose(f) do { \
  60. for (unsigned _assert_fe_i = 0; _assert_fe_i< 10; _assert_fe_i++) { \
  61. assert(f[_assert_fe_i] < 3.375*(1<<(26-(_assert_fe_i&1)))); \
  62. } \
  63. } while (0)
  64. static void fe_frombytes_impl(uint32_t h[10], const uint8_t *s) {
  65. // Ignores top bit of s.
  66. uint32_t a0 = load_4(s);
  67. uint32_t a1 = load_4(s+4);
  68. uint32_t a2 = load_4(s+8);
  69. uint32_t a3 = load_4(s+12);
  70. uint32_t a4 = load_4(s+16);
  71. uint32_t a5 = load_4(s+20);
  72. uint32_t a6 = load_4(s+24);
  73. uint32_t a7 = load_4(s+28);
  74. h[0] = a0&((1<<26)-1); // 26 used, 32-26 left. 26
  75. h[1] = (a0>>26) | ((a1&((1<<19)-1))<< 6); // (32-26) + 19 = 6+19 = 25
  76. h[2] = (a1>>19) | ((a2&((1<<13)-1))<<13); // (32-19) + 13 = 13+13 = 26
  77. h[3] = (a2>>13) | ((a3&((1<< 6)-1))<<19); // (32-13) + 6 = 19+ 6 = 25
  78. h[4] = (a3>> 6); // (32- 6) = 26
  79. h[5] = a4&((1<<25)-1); // 25
  80. h[6] = (a4>>25) | ((a5&((1<<19)-1))<< 7); // (32-25) + 19 = 7+19 = 26
  81. h[7] = (a5>>19) | ((a6&((1<<12)-1))<<13); // (32-19) + 12 = 13+12 = 25
  82. h[8] = (a6>>12) | ((a7&((1<< 6)-1))<<20); // (32-12) + 6 = 20+ 6 = 26
  83. h[9] = (a7>> 6)&((1<<25)-1); // 25
  84. assert_fe(h);
  85. }
  86. static void fe_frombytes(fe *h, const uint8_t *s) {
  87. fe_frombytes_impl(h->v, s);
  88. }
  89. // Preconditions:
  90. // |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
  91. //
  92. // Write p=2^255-19; q=floor(h/p).
  93. // Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
  94. //
  95. // Proof:
  96. // Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
  97. // Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.
  98. //
  99. // Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
  100. // Then 0<y<1.
  101. //
  102. // Write r=h-pq.
  103. // Have 0<=r<=p-1=2^255-20.
  104. // Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
  105. //
  106. // Write x=r+19(2^-255)r+y.
  107. // Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
  108. //
  109. // Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
  110. // so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
  111. static void fe_tobytes_impl(uint8_t *s, const uint32_t h[10]) {
  112. assert_fe_loose(h);
  113. int32_t h0 = h[0];
  114. int32_t h1 = h[1];
  115. int32_t h2 = h[2];
  116. int32_t h3 = h[3];
  117. int32_t h4 = h[4];
  118. int32_t h5 = h[5];
  119. int32_t h6 = h[6];
  120. int32_t h7 = h[7];
  121. int32_t h8 = h[8];
  122. int32_t h9 = h[9];
  123. int32_t q;
  124. q = (19 * h9 + (((int32_t) 1) << 24)) >> 25;
  125. q = (h0 + q) >> 26;
  126. q = (h1 + q) >> 25;
  127. q = (h2 + q) >> 26;
  128. q = (h3 + q) >> 25;
  129. q = (h4 + q) >> 26;
  130. q = (h5 + q) >> 25;
  131. q = (h6 + q) >> 26;
  132. q = (h7 + q) >> 25;
  133. q = (h8 + q) >> 26;
  134. q = (h9 + q) >> 25;
  135. // Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20.
  136. h0 += 19 * q;
  137. // Goal: Output h-2^255 q, which is between 0 and 2^255-20.
  138. h1 += h0 >> 26; h0 &= kBottom26Bits;
  139. h2 += h1 >> 25; h1 &= kBottom25Bits;
  140. h3 += h2 >> 26; h2 &= kBottom26Bits;
  141. h4 += h3 >> 25; h3 &= kBottom25Bits;
  142. h5 += h4 >> 26; h4 &= kBottom26Bits;
  143. h6 += h5 >> 25; h5 &= kBottom25Bits;
  144. h7 += h6 >> 26; h6 &= kBottom26Bits;
  145. h8 += h7 >> 25; h7 &= kBottom25Bits;
  146. h9 += h8 >> 26; h8 &= kBottom26Bits;
  147. h9 &= kBottom25Bits;
  148. // h10 = carry9
  149. // Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.
  150. // Have h0+...+2^230 h9 between 0 and 2^255-1;
  151. // evidently 2^255 h10-2^255 q = 0.
  152. // Goal: Output h0+...+2^230 h9.
  153. s[0] = h0 >> 0;
  154. s[1] = h0 >> 8;
  155. s[2] = h0 >> 16;
  156. s[3] = (h0 >> 24) | ((uint32_t)(h1) << 2);
  157. s[4] = h1 >> 6;
  158. s[5] = h1 >> 14;
  159. s[6] = (h1 >> 22) | ((uint32_t)(h2) << 3);
  160. s[7] = h2 >> 5;
  161. s[8] = h2 >> 13;
  162. s[9] = (h2 >> 21) | ((uint32_t)(h3) << 5);
  163. s[10] = h3 >> 3;
  164. s[11] = h3 >> 11;
  165. s[12] = (h3 >> 19) | ((uint32_t)(h4) << 6);
  166. s[13] = h4 >> 2;
  167. s[14] = h4 >> 10;
  168. s[15] = h4 >> 18;
  169. s[16] = h5 >> 0;
  170. s[17] = h5 >> 8;
  171. s[18] = h5 >> 16;
  172. s[19] = (h5 >> 24) | ((uint32_t)(h6) << 1);
  173. s[20] = h6 >> 7;
  174. s[21] = h6 >> 15;
  175. s[22] = (h6 >> 23) | ((uint32_t)(h7) << 3);
  176. s[23] = h7 >> 5;
  177. s[24] = h7 >> 13;
  178. s[25] = (h7 >> 21) | ((uint32_t)(h8) << 4);
  179. s[26] = h8 >> 4;
  180. s[27] = h8 >> 12;
  181. s[28] = (h8 >> 20) | ((uint32_t)(h9) << 6);
  182. s[29] = h9 >> 2;
  183. s[30] = h9 >> 10;
  184. s[31] = h9 >> 18;
  185. }
  186. static void fe_tobytes(uint8_t *s, const fe *h) {
  187. fe_tobytes_impl(s, h->v);
  188. }
  189. static void fe_loose_tobytes(uint8_t *s, const fe_loose *h) {
  190. fe_tobytes_impl(s, h->v);
  191. }
  192. // h = f
  193. static void fe_copy(fe *h, const fe *f) {
  194. OPENSSL_memmove(h, f, sizeof(uint32_t) * 10);
  195. }
  196. static void fe_copy_lt(fe_loose *h, const fe *f) {
  197. OPENSSL_memmove(h, f, sizeof(uint32_t) * 10);
  198. }
  199. #if !defined(OPENSSL_SMALL)
  200. static void fe_copy_ll(fe_loose *h, const fe_loose *f) {
  201. OPENSSL_memmove(h, f, sizeof(uint32_t) * 10);
  202. }
  203. #endif // !defined(OPENSSL_SMALL)
  204. // h = 0
  205. static void fe_0(fe *h) {
  206. OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
  207. }
  208. static void fe_loose_0(fe_loose *h) {
  209. OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
  210. }
  211. // h = 1
  212. static void fe_1(fe *h) {
  213. OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
  214. h->v[0] = 1;
  215. }
  216. static void fe_loose_1(fe_loose *h) {
  217. OPENSSL_memset(h, 0, sizeof(uint32_t) * 10);
  218. h->v[0] = 1;
  219. }
  220. static void fe_add_impl(uint32_t out[10], const uint32_t in1[10], const uint32_t in2[10]) {
  221. { const uint32_t x20 = in1[9];
  222. { const uint32_t x21 = in1[8];
  223. { const uint32_t x19 = in1[7];
  224. { const uint32_t x17 = in1[6];
  225. { const uint32_t x15 = in1[5];
  226. { const uint32_t x13 = in1[4];
  227. { const uint32_t x11 = in1[3];
  228. { const uint32_t x9 = in1[2];
  229. { const uint32_t x7 = in1[1];
  230. { const uint32_t x5 = in1[0];
  231. { const uint32_t x38 = in2[9];
  232. { const uint32_t x39 = in2[8];
  233. { const uint32_t x37 = in2[7];
  234. { const uint32_t x35 = in2[6];
  235. { const uint32_t x33 = in2[5];
  236. { const uint32_t x31 = in2[4];
  237. { const uint32_t x29 = in2[3];
  238. { const uint32_t x27 = in2[2];
  239. { const uint32_t x25 = in2[1];
  240. { const uint32_t x23 = in2[0];
  241. out[0] = (x5 + x23);
  242. out[1] = (x7 + x25);
  243. out[2] = (x9 + x27);
  244. out[3] = (x11 + x29);
  245. out[4] = (x13 + x31);
  246. out[5] = (x15 + x33);
  247. out[6] = (x17 + x35);
  248. out[7] = (x19 + x37);
  249. out[8] = (x21 + x39);
  250. out[9] = (x20 + x38);
  251. }}}}}}}}}}}}}}}}}}}}
  252. }
  253. // h = f + g
  254. // Can overlap h with f or g.
  255. //
  256. // Preconditions:
  257. // |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
  258. // |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
  259. //
  260. // Postconditions:
  261. // |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
  262. static void fe_add(fe_loose *h, const fe *f, const fe *g) {
  263. assert_fe(f->v);
  264. assert_fe(g->v);
  265. fe_add_impl(h->v, f->v, g->v);
  266. assert_fe_loose(h->v);
  267. }
  268. static void fe_sub_impl(uint32_t out[10], const uint32_t in1[10], const uint32_t in2[10]) {
  269. { const uint32_t x20 = in1[9];
  270. { const uint32_t x21 = in1[8];
  271. { const uint32_t x19 = in1[7];
  272. { const uint32_t x17 = in1[6];
  273. { const uint32_t x15 = in1[5];
  274. { const uint32_t x13 = in1[4];
  275. { const uint32_t x11 = in1[3];
  276. { const uint32_t x9 = in1[2];
  277. { const uint32_t x7 = in1[1];
  278. { const uint32_t x5 = in1[0];
  279. { const uint32_t x38 = in2[9];
  280. { const uint32_t x39 = in2[8];
  281. { const uint32_t x37 = in2[7];
  282. { const uint32_t x35 = in2[6];
  283. { const uint32_t x33 = in2[5];
  284. { const uint32_t x31 = in2[4];
  285. { const uint32_t x29 = in2[3];
  286. { const uint32_t x27 = in2[2];
  287. { const uint32_t x25 = in2[1];
  288. { const uint32_t x23 = in2[0];
  289. out[0] = ((0x7ffffda + x5) - x23);
  290. out[1] = ((0x3fffffe + x7) - x25);
  291. out[2] = ((0x7fffffe + x9) - x27);
  292. out[3] = ((0x3fffffe + x11) - x29);
  293. out[4] = ((0x7fffffe + x13) - x31);
  294. out[5] = ((0x3fffffe + x15) - x33);
  295. out[6] = ((0x7fffffe + x17) - x35);
  296. out[7] = ((0x3fffffe + x19) - x37);
  297. out[8] = ((0x7fffffe + x21) - x39);
  298. out[9] = ((0x3fffffe + x20) - x38);
  299. }}}}}}}}}}}}}}}}}}}}
  300. }
  301. // h = f - g
  302. // Can overlap h with f or g.
  303. //
  304. // Preconditions:
  305. // |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
  306. // |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
  307. //
  308. // Postconditions:
  309. // |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
  310. static void fe_sub(fe_loose *h, const fe *f, const fe *g) {
  311. assert_fe(f->v);
  312. assert_fe(g->v);
  313. fe_sub_impl(h->v, f->v, g->v);
  314. assert_fe_loose(h->v);
  315. }
  316. static void fe_carry_impl(uint32_t out[10], const uint32_t in1[10]) {
  317. { const uint32_t x17 = in1[9];
  318. { const uint32_t x18 = in1[8];
  319. { const uint32_t x16 = in1[7];
  320. { const uint32_t x14 = in1[6];
  321. { const uint32_t x12 = in1[5];
  322. { const uint32_t x10 = in1[4];
  323. { const uint32_t x8 = in1[3];
  324. { const uint32_t x6 = in1[2];
  325. { const uint32_t x4 = in1[1];
  326. { const uint32_t x2 = in1[0];
  327. { uint32_t x19 = (x2 >> 0x1a);
  328. { uint32_t x20 = (x2 & 0x3ffffff);
  329. { uint32_t x21 = (x19 + x4);
  330. { uint32_t x22 = (x21 >> 0x19);
  331. { uint32_t x23 = (x21 & 0x1ffffff);
  332. { uint32_t x24 = (x22 + x6);
  333. { uint32_t x25 = (x24 >> 0x1a);
  334. { uint32_t x26 = (x24 & 0x3ffffff);
  335. { uint32_t x27 = (x25 + x8);
  336. { uint32_t x28 = (x27 >> 0x19);
  337. { uint32_t x29 = (x27 & 0x1ffffff);
  338. { uint32_t x30 = (x28 + x10);
  339. { uint32_t x31 = (x30 >> 0x1a);
  340. { uint32_t x32 = (x30 & 0x3ffffff);
  341. { uint32_t x33 = (x31 + x12);
  342. { uint32_t x34 = (x33 >> 0x19);
  343. { uint32_t x35 = (x33 & 0x1ffffff);
  344. { uint32_t x36 = (x34 + x14);
  345. { uint32_t x37 = (x36 >> 0x1a);
  346. { uint32_t x38 = (x36 & 0x3ffffff);
  347. { uint32_t x39 = (x37 + x16);
  348. { uint32_t x40 = (x39 >> 0x19);
  349. { uint32_t x41 = (x39 & 0x1ffffff);
  350. { uint32_t x42 = (x40 + x18);
  351. { uint32_t x43 = (x42 >> 0x1a);
  352. { uint32_t x44 = (x42 & 0x3ffffff);
  353. { uint32_t x45 = (x43 + x17);
  354. { uint32_t x46 = (x45 >> 0x19);
  355. { uint32_t x47 = (x45 & 0x1ffffff);
  356. { uint32_t x48 = (x20 + (0x13 * x46));
  357. { uint32_t x49 = (x48 >> 0x1a);
  358. { uint32_t x50 = (x48 & 0x3ffffff);
  359. { uint32_t x51 = (x49 + x23);
  360. { uint32_t x52 = (x51 >> 0x19);
  361. { uint32_t x53 = (x51 & 0x1ffffff);
  362. out[0] = x50;
  363. out[1] = x53;
  364. out[2] = (x52 + x26);
  365. out[3] = x29;
  366. out[4] = x32;
  367. out[5] = x35;
  368. out[6] = x38;
  369. out[7] = x41;
  370. out[8] = x44;
  371. out[9] = x47;
  372. }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
  373. }
  374. static void fe_carry(fe *h, const fe_loose* f) {
  375. assert_fe_loose(f->v);
  376. fe_carry_impl(h->v, f->v);
  377. assert_fe(h->v);
  378. }
  379. static void fe_mul_impl(uint32_t out[10], const uint32_t in1[10], const uint32_t in2[10]) {
  380. assert_fe_loose(in1);
  381. assert_fe_loose(in2);
  382. { const uint32_t x20 = in1[9];
  383. { const uint32_t x21 = in1[8];
  384. { const uint32_t x19 = in1[7];
  385. { const uint32_t x17 = in1[6];
  386. { const uint32_t x15 = in1[5];
  387. { const uint32_t x13 = in1[4];
  388. { const uint32_t x11 = in1[3];
  389. { const uint32_t x9 = in1[2];
  390. { const uint32_t x7 = in1[1];
  391. { const uint32_t x5 = in1[0];
  392. { const uint32_t x38 = in2[9];
  393. { const uint32_t x39 = in2[8];
  394. { const uint32_t x37 = in2[7];
  395. { const uint32_t x35 = in2[6];
  396. { const uint32_t x33 = in2[5];
  397. { const uint32_t x31 = in2[4];
  398. { const uint32_t x29 = in2[3];
  399. { const uint32_t x27 = in2[2];
  400. { const uint32_t x25 = in2[1];
  401. { const uint32_t x23 = in2[0];
  402. { uint64_t x40 = ((uint64_t)x23 * x5);
  403. { uint64_t x41 = (((uint64_t)x23 * x7) + ((uint64_t)x25 * x5));
  404. { uint64_t x42 = ((((uint64_t)(0x2 * x25) * x7) + ((uint64_t)x23 * x9)) + ((uint64_t)x27 * x5));
  405. { uint64_t x43 = (((((uint64_t)x25 * x9) + ((uint64_t)x27 * x7)) + ((uint64_t)x23 * x11)) + ((uint64_t)x29 * x5));
  406. { uint64_t x44 = (((((uint64_t)x27 * x9) + (0x2 * (((uint64_t)x25 * x11) + ((uint64_t)x29 * x7)))) + ((uint64_t)x23 * x13)) + ((uint64_t)x31 * x5));
  407. { uint64_t x45 = (((((((uint64_t)x27 * x11) + ((uint64_t)x29 * x9)) + ((uint64_t)x25 * x13)) + ((uint64_t)x31 * x7)) + ((uint64_t)x23 * x15)) + ((uint64_t)x33 * x5));
  408. { uint64_t x46 = (((((0x2 * ((((uint64_t)x29 * x11) + ((uint64_t)x25 * x15)) + ((uint64_t)x33 * x7))) + ((uint64_t)x27 * x13)) + ((uint64_t)x31 * x9)) + ((uint64_t)x23 * x17)) + ((uint64_t)x35 * x5));
  409. { uint64_t x47 = (((((((((uint64_t)x29 * x13) + ((uint64_t)x31 * x11)) + ((uint64_t)x27 * x15)) + ((uint64_t)x33 * x9)) + ((uint64_t)x25 * x17)) + ((uint64_t)x35 * x7)) + ((uint64_t)x23 * x19)) + ((uint64_t)x37 * x5));
  410. { uint64_t x48 = (((((((uint64_t)x31 * x13) + (0x2 * (((((uint64_t)x29 * x15) + ((uint64_t)x33 * x11)) + ((uint64_t)x25 * x19)) + ((uint64_t)x37 * x7)))) + ((uint64_t)x27 * x17)) + ((uint64_t)x35 * x9)) + ((uint64_t)x23 * x21)) + ((uint64_t)x39 * x5));
  411. { uint64_t x49 = (((((((((((uint64_t)x31 * x15) + ((uint64_t)x33 * x13)) + ((uint64_t)x29 * x17)) + ((uint64_t)x35 * x11)) + ((uint64_t)x27 * x19)) + ((uint64_t)x37 * x9)) + ((uint64_t)x25 * x21)) + ((uint64_t)x39 * x7)) + ((uint64_t)x23 * x20)) + ((uint64_t)x38 * x5));
  412. { uint64_t x50 = (((((0x2 * ((((((uint64_t)x33 * x15) + ((uint64_t)x29 * x19)) + ((uint64_t)x37 * x11)) + ((uint64_t)x25 * x20)) + ((uint64_t)x38 * x7))) + ((uint64_t)x31 * x17)) + ((uint64_t)x35 * x13)) + ((uint64_t)x27 * x21)) + ((uint64_t)x39 * x9));
  413. { uint64_t x51 = (((((((((uint64_t)x33 * x17) + ((uint64_t)x35 * x15)) + ((uint64_t)x31 * x19)) + ((uint64_t)x37 * x13)) + ((uint64_t)x29 * x21)) + ((uint64_t)x39 * x11)) + ((uint64_t)x27 * x20)) + ((uint64_t)x38 * x9));
  414. { uint64_t x52 = (((((uint64_t)x35 * x17) + (0x2 * (((((uint64_t)x33 * x19) + ((uint64_t)x37 * x15)) + ((uint64_t)x29 * x20)) + ((uint64_t)x38 * x11)))) + ((uint64_t)x31 * x21)) + ((uint64_t)x39 * x13));
  415. { uint64_t x53 = (((((((uint64_t)x35 * x19) + ((uint64_t)x37 * x17)) + ((uint64_t)x33 * x21)) + ((uint64_t)x39 * x15)) + ((uint64_t)x31 * x20)) + ((uint64_t)x38 * x13));
  416. { uint64_t x54 = (((0x2 * ((((uint64_t)x37 * x19) + ((uint64_t)x33 * x20)) + ((uint64_t)x38 * x15))) + ((uint64_t)x35 * x21)) + ((uint64_t)x39 * x17));
  417. { uint64_t x55 = (((((uint64_t)x37 * x21) + ((uint64_t)x39 * x19)) + ((uint64_t)x35 * x20)) + ((uint64_t)x38 * x17));
  418. { uint64_t x56 = (((uint64_t)x39 * x21) + (0x2 * (((uint64_t)x37 * x20) + ((uint64_t)x38 * x19))));
  419. { uint64_t x57 = (((uint64_t)x39 * x20) + ((uint64_t)x38 * x21));
  420. { uint64_t x58 = ((uint64_t)(0x2 * x38) * x20);
  421. { uint64_t x59 = (x48 + (x58 << 0x4));
  422. { uint64_t x60 = (x59 + (x58 << 0x1));
  423. { uint64_t x61 = (x60 + x58);
  424. { uint64_t x62 = (x47 + (x57 << 0x4));
  425. { uint64_t x63 = (x62 + (x57 << 0x1));
  426. { uint64_t x64 = (x63 + x57);
  427. { uint64_t x65 = (x46 + (x56 << 0x4));
  428. { uint64_t x66 = (x65 + (x56 << 0x1));
  429. { uint64_t x67 = (x66 + x56);
  430. { uint64_t x68 = (x45 + (x55 << 0x4));
  431. { uint64_t x69 = (x68 + (x55 << 0x1));
  432. { uint64_t x70 = (x69 + x55);
  433. { uint64_t x71 = (x44 + (x54 << 0x4));
  434. { uint64_t x72 = (x71 + (x54 << 0x1));
  435. { uint64_t x73 = (x72 + x54);
  436. { uint64_t x74 = (x43 + (x53 << 0x4));
  437. { uint64_t x75 = (x74 + (x53 << 0x1));
  438. { uint64_t x76 = (x75 + x53);
  439. { uint64_t x77 = (x42 + (x52 << 0x4));
  440. { uint64_t x78 = (x77 + (x52 << 0x1));
  441. { uint64_t x79 = (x78 + x52);
  442. { uint64_t x80 = (x41 + (x51 << 0x4));
  443. { uint64_t x81 = (x80 + (x51 << 0x1));
  444. { uint64_t x82 = (x81 + x51);
  445. { uint64_t x83 = (x40 + (x50 << 0x4));
  446. { uint64_t x84 = (x83 + (x50 << 0x1));
  447. { uint64_t x85 = (x84 + x50);
  448. { uint64_t x86 = (x85 >> 0x1a);
  449. { uint32_t x87 = ((uint32_t)x85 & 0x3ffffff);
  450. { uint64_t x88 = (x86 + x82);
  451. { uint64_t x89 = (x88 >> 0x19);
  452. { uint32_t x90 = ((uint32_t)x88 & 0x1ffffff);
  453. { uint64_t x91 = (x89 + x79);
  454. { uint64_t x92 = (x91 >> 0x1a);
  455. { uint32_t x93 = ((uint32_t)x91 & 0x3ffffff);
  456. { uint64_t x94 = (x92 + x76);
  457. { uint64_t x95 = (x94 >> 0x19);
  458. { uint32_t x96 = ((uint32_t)x94 & 0x1ffffff);
  459. { uint64_t x97 = (x95 + x73);
  460. { uint64_t x98 = (x97 >> 0x1a);
  461. { uint32_t x99 = ((uint32_t)x97 & 0x3ffffff);
  462. { uint64_t x100 = (x98 + x70);
  463. { uint64_t x101 = (x100 >> 0x19);
  464. { uint32_t x102 = ((uint32_t)x100 & 0x1ffffff);
  465. { uint64_t x103 = (x101 + x67);
  466. { uint64_t x104 = (x103 >> 0x1a);
  467. { uint32_t x105 = ((uint32_t)x103 & 0x3ffffff);
  468. { uint64_t x106 = (x104 + x64);
  469. { uint64_t x107 = (x106 >> 0x19);
  470. { uint32_t x108 = ((uint32_t)x106 & 0x1ffffff);
  471. { uint64_t x109 = (x107 + x61);
  472. { uint64_t x110 = (x109 >> 0x1a);
  473. { uint32_t x111 = ((uint32_t)x109 & 0x3ffffff);
  474. { uint64_t x112 = (x110 + x49);
  475. { uint64_t x113 = (x112 >> 0x19);
  476. { uint32_t x114 = ((uint32_t)x112 & 0x1ffffff);
  477. { uint64_t x115 = (x87 + (0x13 * x113));
  478. { uint32_t x116 = (uint32_t) (x115 >> 0x1a);
  479. { uint32_t x117 = ((uint32_t)x115 & 0x3ffffff);
  480. { uint32_t x118 = (x116 + x90);
  481. { uint32_t x119 = (x118 >> 0x19);
  482. { uint32_t x120 = (x118 & 0x1ffffff);
  483. out[0] = x117;
  484. out[1] = x120;
  485. out[2] = (x119 + x93);
  486. out[3] = x96;
  487. out[4] = x99;
  488. out[5] = x102;
  489. out[6] = x105;
  490. out[7] = x108;
  491. out[8] = x111;
  492. out[9] = x114;
  493. }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
  494. assert_fe(out);
  495. }
  496. static void fe_mul_ltt(fe_loose *h, const fe *f, const fe *g) {
  497. fe_mul_impl(h->v, f->v, g->v);
  498. }
  499. static void fe_mul_llt(fe_loose *h, const fe_loose *f, const fe *g) {
  500. fe_mul_impl(h->v, f->v, g->v);
  501. }
  502. static void fe_mul_ttt(fe *h, const fe *f, const fe *g) {
  503. fe_mul_impl(h->v, f->v, g->v);
  504. }
  505. static void fe_mul_tlt(fe *h, const fe_loose *f, const fe *g) {
  506. fe_mul_impl(h->v, f->v, g->v);
  507. }
  508. static void fe_mul_ttl(fe *h, const fe *f, const fe_loose *g) {
  509. fe_mul_impl(h->v, f->v, g->v);
  510. }
  511. static void fe_mul_tll(fe *h, const fe_loose *f, const fe_loose *g) {
  512. fe_mul_impl(h->v, f->v, g->v);
  513. }
  514. static void fe_sqr_impl(uint32_t out[10], const uint32_t in1[10]) {
  515. assert_fe_loose(in1);
  516. { const uint32_t x17 = in1[9];
  517. { const uint32_t x18 = in1[8];
  518. { const uint32_t x16 = in1[7];
  519. { const uint32_t x14 = in1[6];
  520. { const uint32_t x12 = in1[5];
  521. { const uint32_t x10 = in1[4];
  522. { const uint32_t x8 = in1[3];
  523. { const uint32_t x6 = in1[2];
  524. { const uint32_t x4 = in1[1];
  525. { const uint32_t x2 = in1[0];
  526. { uint64_t x19 = ((uint64_t)x2 * x2);
  527. { uint64_t x20 = ((uint64_t)(0x2 * x2) * x4);
  528. { uint64_t x21 = (0x2 * (((uint64_t)x4 * x4) + ((uint64_t)x2 * x6)));
  529. { uint64_t x22 = (0x2 * (((uint64_t)x4 * x6) + ((uint64_t)x2 * x8)));
  530. { uint64_t x23 = ((((uint64_t)x6 * x6) + ((uint64_t)(0x4 * x4) * x8)) + ((uint64_t)(0x2 * x2) * x10));
  531. { uint64_t x24 = (0x2 * ((((uint64_t)x6 * x8) + ((uint64_t)x4 * x10)) + ((uint64_t)x2 * x12)));
  532. { uint64_t x25 = (0x2 * (((((uint64_t)x8 * x8) + ((uint64_t)x6 * x10)) + ((uint64_t)x2 * x14)) + ((uint64_t)(0x2 * x4) * x12)));
  533. { uint64_t x26 = (0x2 * (((((uint64_t)x8 * x10) + ((uint64_t)x6 * x12)) + ((uint64_t)x4 * x14)) + ((uint64_t)x2 * x16)));
  534. { uint64_t x27 = (((uint64_t)x10 * x10) + (0x2 * ((((uint64_t)x6 * x14) + ((uint64_t)x2 * x18)) + (0x2 * (((uint64_t)x4 * x16) + ((uint64_t)x8 * x12))))));
  535. { uint64_t x28 = (0x2 * ((((((uint64_t)x10 * x12) + ((uint64_t)x8 * x14)) + ((uint64_t)x6 * x16)) + ((uint64_t)x4 * x18)) + ((uint64_t)x2 * x17)));
  536. { uint64_t x29 = (0x2 * (((((uint64_t)x12 * x12) + ((uint64_t)x10 * x14)) + ((uint64_t)x6 * x18)) + (0x2 * (((uint64_t)x8 * x16) + ((uint64_t)x4 * x17)))));
  537. { uint64_t x30 = (0x2 * (((((uint64_t)x12 * x14) + ((uint64_t)x10 * x16)) + ((uint64_t)x8 * x18)) + ((uint64_t)x6 * x17)));
  538. { uint64_t x31 = (((uint64_t)x14 * x14) + (0x2 * (((uint64_t)x10 * x18) + (0x2 * (((uint64_t)x12 * x16) + ((uint64_t)x8 * x17))))));
  539. { uint64_t x32 = (0x2 * ((((uint64_t)x14 * x16) + ((uint64_t)x12 * x18)) + ((uint64_t)x10 * x17)));
  540. { uint64_t x33 = (0x2 * ((((uint64_t)x16 * x16) + ((uint64_t)x14 * x18)) + ((uint64_t)(0x2 * x12) * x17)));
  541. { uint64_t x34 = (0x2 * (((uint64_t)x16 * x18) + ((uint64_t)x14 * x17)));
  542. { uint64_t x35 = (((uint64_t)x18 * x18) + ((uint64_t)(0x4 * x16) * x17));
  543. { uint64_t x36 = ((uint64_t)(0x2 * x18) * x17);
  544. { uint64_t x37 = ((uint64_t)(0x2 * x17) * x17);
  545. { uint64_t x38 = (x27 + (x37 << 0x4));
  546. { uint64_t x39 = (x38 + (x37 << 0x1));
  547. { uint64_t x40 = (x39 + x37);
  548. { uint64_t x41 = (x26 + (x36 << 0x4));
  549. { uint64_t x42 = (x41 + (x36 << 0x1));
  550. { uint64_t x43 = (x42 + x36);
  551. { uint64_t x44 = (x25 + (x35 << 0x4));
  552. { uint64_t x45 = (x44 + (x35 << 0x1));
  553. { uint64_t x46 = (x45 + x35);
  554. { uint64_t x47 = (x24 + (x34 << 0x4));
  555. { uint64_t x48 = (x47 + (x34 << 0x1));
  556. { uint64_t x49 = (x48 + x34);
  557. { uint64_t x50 = (x23 + (x33 << 0x4));
  558. { uint64_t x51 = (x50 + (x33 << 0x1));
  559. { uint64_t x52 = (x51 + x33);
  560. { uint64_t x53 = (x22 + (x32 << 0x4));
  561. { uint64_t x54 = (x53 + (x32 << 0x1));
  562. { uint64_t x55 = (x54 + x32);
  563. { uint64_t x56 = (x21 + (x31 << 0x4));
  564. { uint64_t x57 = (x56 + (x31 << 0x1));
  565. { uint64_t x58 = (x57 + x31);
  566. { uint64_t x59 = (x20 + (x30 << 0x4));
  567. { uint64_t x60 = (x59 + (x30 << 0x1));
  568. { uint64_t x61 = (x60 + x30);
  569. { uint64_t x62 = (x19 + (x29 << 0x4));
  570. { uint64_t x63 = (x62 + (x29 << 0x1));
  571. { uint64_t x64 = (x63 + x29);
  572. { uint64_t x65 = (x64 >> 0x1a);
  573. { uint32_t x66 = ((uint32_t)x64 & 0x3ffffff);
  574. { uint64_t x67 = (x65 + x61);
  575. { uint64_t x68 = (x67 >> 0x19);
  576. { uint32_t x69 = ((uint32_t)x67 & 0x1ffffff);
  577. { uint64_t x70 = (x68 + x58);
  578. { uint64_t x71 = (x70 >> 0x1a);
  579. { uint32_t x72 = ((uint32_t)x70 & 0x3ffffff);
  580. { uint64_t x73 = (x71 + x55);
  581. { uint64_t x74 = (x73 >> 0x19);
  582. { uint32_t x75 = ((uint32_t)x73 & 0x1ffffff);
  583. { uint64_t x76 = (x74 + x52);
  584. { uint64_t x77 = (x76 >> 0x1a);
  585. { uint32_t x78 = ((uint32_t)x76 & 0x3ffffff);
  586. { uint64_t x79 = (x77 + x49);
  587. { uint64_t x80 = (x79 >> 0x19);
  588. { uint32_t x81 = ((uint32_t)x79 & 0x1ffffff);
  589. { uint64_t x82 = (x80 + x46);
  590. { uint64_t x83 = (x82 >> 0x1a);
  591. { uint32_t x84 = ((uint32_t)x82 & 0x3ffffff);
  592. { uint64_t x85 = (x83 + x43);
  593. { uint64_t x86 = (x85 >> 0x19);
  594. { uint32_t x87 = ((uint32_t)x85 & 0x1ffffff);
  595. { uint64_t x88 = (x86 + x40);
  596. { uint64_t x89 = (x88 >> 0x1a);
  597. { uint32_t x90 = ((uint32_t)x88 & 0x3ffffff);
  598. { uint64_t x91 = (x89 + x28);
  599. { uint64_t x92 = (x91 >> 0x19);
  600. { uint32_t x93 = ((uint32_t)x91 & 0x1ffffff);
  601. { uint64_t x94 = (x66 + (0x13 * x92));
  602. { uint32_t x95 = (uint32_t) (x94 >> 0x1a);
  603. { uint32_t x96 = ((uint32_t)x94 & 0x3ffffff);
  604. { uint32_t x97 = (x95 + x69);
  605. { uint32_t x98 = (x97 >> 0x19);
  606. { uint32_t x99 = (x97 & 0x1ffffff);
  607. out[0] = x96;
  608. out[1] = x99;
  609. out[2] = (x98 + x72);
  610. out[3] = x75;
  611. out[4] = x78;
  612. out[5] = x81;
  613. out[6] = x84;
  614. out[7] = x87;
  615. out[8] = x90;
  616. out[9] = x93;
  617. }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
  618. assert_fe(out);
  619. }
  620. static void fe_sq_tl(fe *h, const fe_loose *f) {
  621. fe_sqr_impl(h->v, f->v);
  622. }
  623. static void fe_sq_tt(fe *h, const fe *f) {
  624. fe_sqr_impl(h->v, f->v);
  625. }
  626. static void fe_loose_invert(fe *out, const fe_loose *z) {
  627. fe t0;
  628. fe t1;
  629. fe t2;
  630. fe t3;
  631. int i;
  632. fe_sq_tl(&t0, z);
  633. fe_sq_tt(&t1, &t0);
  634. for (i = 1; i < 2; ++i) {
  635. fe_sq_tt(&t1, &t1);
  636. }
  637. fe_mul_tlt(&t1, z, &t1);
  638. fe_mul_ttt(&t0, &t0, &t1);
  639. fe_sq_tt(&t2, &t0);
  640. fe_mul_ttt(&t1, &t1, &t2);
  641. fe_sq_tt(&t2, &t1);
  642. for (i = 1; i < 5; ++i) {
  643. fe_sq_tt(&t2, &t2);
  644. }
  645. fe_mul_ttt(&t1, &t2, &t1);
  646. fe_sq_tt(&t2, &t1);
  647. for (i = 1; i < 10; ++i) {
  648. fe_sq_tt(&t2, &t2);
  649. }
  650. fe_mul_ttt(&t2, &t2, &t1);
  651. fe_sq_tt(&t3, &t2);
  652. for (i = 1; i < 20; ++i) {
  653. fe_sq_tt(&t3, &t3);
  654. }
  655. fe_mul_ttt(&t2, &t3, &t2);
  656. fe_sq_tt(&t2, &t2);
  657. for (i = 1; i < 10; ++i) {
  658. fe_sq_tt(&t2, &t2);
  659. }
  660. fe_mul_ttt(&t1, &t2, &t1);
  661. fe_sq_tt(&t2, &t1);
  662. for (i = 1; i < 50; ++i) {
  663. fe_sq_tt(&t2, &t2);
  664. }
  665. fe_mul_ttt(&t2, &t2, &t1);
  666. fe_sq_tt(&t3, &t2);
  667. for (i = 1; i < 100; ++i) {
  668. fe_sq_tt(&t3, &t3);
  669. }
  670. fe_mul_ttt(&t2, &t3, &t2);
  671. fe_sq_tt(&t2, &t2);
  672. for (i = 1; i < 50; ++i) {
  673. fe_sq_tt(&t2, &t2);
  674. }
  675. fe_mul_ttt(&t1, &t2, &t1);
  676. fe_sq_tt(&t1, &t1);
  677. for (i = 1; i < 5; ++i) {
  678. fe_sq_tt(&t1, &t1);
  679. }
  680. fe_mul_ttt(out, &t1, &t0);
  681. }
  682. static void fe_invert(fe *out, const fe *z) {
  683. fe_loose l;
  684. fe_copy_lt(&l, z);
  685. fe_loose_invert(out, &l);
  686. }
  687. static void fe_neg_impl(uint32_t out[10], const uint32_t in2[10]) {
  688. { const uint32_t x20 = 0;
  689. { const uint32_t x21 = 0;
  690. { const uint32_t x19 = 0;
  691. { const uint32_t x17 = 0;
  692. { const uint32_t x15 = 0;
  693. { const uint32_t x13 = 0;
  694. { const uint32_t x11 = 0;
  695. { const uint32_t x9 = 0;
  696. { const uint32_t x7 = 0;
  697. { const uint32_t x5 = 0;
  698. { const uint32_t x38 = in2[9];
  699. { const uint32_t x39 = in2[8];
  700. { const uint32_t x37 = in2[7];
  701. { const uint32_t x35 = in2[6];
  702. { const uint32_t x33 = in2[5];
  703. { const uint32_t x31 = in2[4];
  704. { const uint32_t x29 = in2[3];
  705. { const uint32_t x27 = in2[2];
  706. { const uint32_t x25 = in2[1];
  707. { const uint32_t x23 = in2[0];
  708. out[0] = ((0x7ffffda + x5) - x23);
  709. out[1] = ((0x3fffffe + x7) - x25);
  710. out[2] = ((0x7fffffe + x9) - x27);
  711. out[3] = ((0x3fffffe + x11) - x29);
  712. out[4] = ((0x7fffffe + x13) - x31);
  713. out[5] = ((0x3fffffe + x15) - x33);
  714. out[6] = ((0x7fffffe + x17) - x35);
  715. out[7] = ((0x3fffffe + x19) - x37);
  716. out[8] = ((0x7fffffe + x21) - x39);
  717. out[9] = ((0x3fffffe + x20) - x38);
  718. }}}}}}}}}}}}}}}}}}}}
  719. }
  720. // h = -f
  721. //
  722. // Preconditions:
  723. // |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
  724. //
  725. // Postconditions:
  726. // |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
  727. static void fe_neg(fe_loose *h, const fe *f) {
  728. assert_fe(f->v);
  729. fe_neg_impl(h->v, f->v);
  730. assert_fe_loose(h->v);
  731. }
  732. // Replace (f,g) with (g,g) if b == 1;
  733. // replace (f,g) with (f,g) if b == 0.
  734. //
  735. // Preconditions: b in {0,1}.
  736. static void fe_cmov(fe_loose *f, const fe_loose *g, unsigned b) {
  737. b = 0-b;
  738. unsigned i;
  739. for (i = 0; i < 10; i++) {
  740. uint32_t x = f->v[i] ^ g->v[i];
  741. x &= b;
  742. f->v[i] ^= x;
  743. }
  744. }
  745. // return 0 if f == 0
  746. // return 1 if f != 0
  747. //
  748. // Preconditions:
  749. // |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
  750. static int fe_isnonzero(const fe_loose *f) {
  751. uint8_t s[32];
  752. fe_loose_tobytes(s, f);
  753. static const uint8_t zero[32] = {0};
  754. return CRYPTO_memcmp(s, zero, sizeof(zero)) != 0;
  755. }
  756. // return 1 if f is in {1,3,5,...,q-2}
  757. // return 0 if f is in {0,2,4,...,q-1}
  758. //
  759. // Preconditions:
  760. // |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
  761. static int fe_isnegative(const fe *f) {
  762. uint8_t s[32];
  763. fe_tobytes(s, f);
  764. return s[0] & 1;
  765. }
  766. // NOTE: based on fiat-crypto fe_mul, edited for in2=2*in1
  767. static void fe_sq2_impl(uint32_t out[10], const uint32_t in1[10]) {
  768. assert_fe_loose(in1);
  769. { const uint32_t x20 = in1[9];
  770. { const uint32_t x21 = in1[8];
  771. { const uint32_t x19 = in1[7];
  772. { const uint32_t x17 = in1[6];
  773. { const uint32_t x15 = in1[5];
  774. { const uint32_t x13 = in1[4];
  775. { const uint32_t x11 = in1[3];
  776. { const uint32_t x9 = in1[2];
  777. { const uint32_t x7 = in1[1];
  778. { const uint32_t x5 = in1[0];
  779. { const uint32_t x38 = 2*in1[9];
  780. { const uint32_t x39 = 2*in1[8];
  781. { const uint32_t x37 = 2*in1[7];
  782. { const uint32_t x35 = 2*in1[6];
  783. { const uint32_t x33 = 2*in1[5];
  784. { const uint32_t x31 = 2*in1[4];
  785. { const uint32_t x29 = 2*in1[3];
  786. { const uint32_t x27 = 2*in1[2];
  787. { const uint32_t x25 = 2*in1[1];
  788. { const uint32_t x23 = 2*in1[0];
  789. { uint64_t x40 = ((uint64_t)x23 * x5);
  790. { uint64_t x41 = (((uint64_t)x23 * x7) + ((uint64_t)x25 * x5));
  791. { uint64_t x42 = ((((uint64_t)(0x2 * x25) * x7) + ((uint64_t)x23 * x9)) + ((uint64_t)x27 * x5));
  792. { uint64_t x43 = (((((uint64_t)x25 * x9) + ((uint64_t)x27 * x7)) + ((uint64_t)x23 * x11)) + ((uint64_t)x29 * x5));
  793. { uint64_t x44 = (((((uint64_t)x27 * x9) + (0x2 * (((uint64_t)x25 * x11) + ((uint64_t)x29 * x7)))) + ((uint64_t)x23 * x13)) + ((uint64_t)x31 * x5));
  794. { uint64_t x45 = (((((((uint64_t)x27 * x11) + ((uint64_t)x29 * x9)) + ((uint64_t)x25 * x13)) + ((uint64_t)x31 * x7)) + ((uint64_t)x23 * x15)) + ((uint64_t)x33 * x5));
  795. { uint64_t x46 = (((((0x2 * ((((uint64_t)x29 * x11) + ((uint64_t)x25 * x15)) + ((uint64_t)x33 * x7))) + ((uint64_t)x27 * x13)) + ((uint64_t)x31 * x9)) + ((uint64_t)x23 * x17)) + ((uint64_t)x35 * x5));
  796. { uint64_t x47 = (((((((((uint64_t)x29 * x13) + ((uint64_t)x31 * x11)) + ((uint64_t)x27 * x15)) + ((uint64_t)x33 * x9)) + ((uint64_t)x25 * x17)) + ((uint64_t)x35 * x7)) + ((uint64_t)x23 * x19)) + ((uint64_t)x37 * x5));
  797. { uint64_t x48 = (((((((uint64_t)x31 * x13) + (0x2 * (((((uint64_t)x29 * x15) + ((uint64_t)x33 * x11)) + ((uint64_t)x25 * x19)) + ((uint64_t)x37 * x7)))) + ((uint64_t)x27 * x17)) + ((uint64_t)x35 * x9)) + ((uint64_t)x23 * x21)) + ((uint64_t)x39 * x5));
  798. { uint64_t x49 = (((((((((((uint64_t)x31 * x15) + ((uint64_t)x33 * x13)) + ((uint64_t)x29 * x17)) + ((uint64_t)x35 * x11)) + ((uint64_t)x27 * x19)) + ((uint64_t)x37 * x9)) + ((uint64_t)x25 * x21)) + ((uint64_t)x39 * x7)) + ((uint64_t)x23 * x20)) + ((uint64_t)x38 * x5));
  799. { uint64_t x50 = (((((0x2 * ((((((uint64_t)x33 * x15) + ((uint64_t)x29 * x19)) + ((uint64_t)x37 * x11)) + ((uint64_t)x25 * x20)) + ((uint64_t)x38 * x7))) + ((uint64_t)x31 * x17)) + ((uint64_t)x35 * x13)) + ((uint64_t)x27 * x21)) + ((uint64_t)x39 * x9));
  800. { uint64_t x51 = (((((((((uint64_t)x33 * x17) + ((uint64_t)x35 * x15)) + ((uint64_t)x31 * x19)) + ((uint64_t)x37 * x13)) + ((uint64_t)x29 * x21)) + ((uint64_t)x39 * x11)) + ((uint64_t)x27 * x20)) + ((uint64_t)x38 * x9));
  801. { uint64_t x52 = (((((uint64_t)x35 * x17) + (0x2 * (((((uint64_t)x33 * x19) + ((uint64_t)x37 * x15)) + ((uint64_t)x29 * x20)) + ((uint64_t)x38 * x11)))) + ((uint64_t)x31 * x21)) + ((uint64_t)x39 * x13));
  802. { uint64_t x53 = (((((((uint64_t)x35 * x19) + ((uint64_t)x37 * x17)) + ((uint64_t)x33 * x21)) + ((uint64_t)x39 * x15)) + ((uint64_t)x31 * x20)) + ((uint64_t)x38 * x13));
  803. { uint64_t x54 = (((0x2 * ((((uint64_t)x37 * x19) + ((uint64_t)x33 * x20)) + ((uint64_t)x38 * x15))) + ((uint64_t)x35 * x21)) + ((uint64_t)x39 * x17));
  804. { uint64_t x55 = (((((uint64_t)x37 * x21) + ((uint64_t)x39 * x19)) + ((uint64_t)x35 * x20)) + ((uint64_t)x38 * x17));
  805. { uint64_t x56 = (((uint64_t)x39 * x21) + (0x2 * (((uint64_t)x37 * x20) + ((uint64_t)x38 * x19))));
  806. { uint64_t x57 = (((uint64_t)x39 * x20) + ((uint64_t)x38 * x21));
  807. { uint64_t x58 = ((uint64_t)(0x2 * x38) * x20);
  808. { uint64_t x59 = (x48 + (x58 << 0x4));
  809. { uint64_t x60 = (x59 + (x58 << 0x1));
  810. { uint64_t x61 = (x60 + x58);
  811. { uint64_t x62 = (x47 + (x57 << 0x4));
  812. { uint64_t x63 = (x62 + (x57 << 0x1));
  813. { uint64_t x64 = (x63 + x57);
  814. { uint64_t x65 = (x46 + (x56 << 0x4));
  815. { uint64_t x66 = (x65 + (x56 << 0x1));
  816. { uint64_t x67 = (x66 + x56);
  817. { uint64_t x68 = (x45 + (x55 << 0x4));
  818. { uint64_t x69 = (x68 + (x55 << 0x1));
  819. { uint64_t x70 = (x69 + x55);
  820. { uint64_t x71 = (x44 + (x54 << 0x4));
  821. { uint64_t x72 = (x71 + (x54 << 0x1));
  822. { uint64_t x73 = (x72 + x54);
  823. { uint64_t x74 = (x43 + (x53 << 0x4));
  824. { uint64_t x75 = (x74 + (x53 << 0x1));
  825. { uint64_t x76 = (x75 + x53);
  826. { uint64_t x77 = (x42 + (x52 << 0x4));
  827. { uint64_t x78 = (x77 + (x52 << 0x1));
  828. { uint64_t x79 = (x78 + x52);
  829. { uint64_t x80 = (x41 + (x51 << 0x4));
  830. { uint64_t x81 = (x80 + (x51 << 0x1));
  831. { uint64_t x82 = (x81 + x51);
  832. { uint64_t x83 = (x40 + (x50 << 0x4));
  833. { uint64_t x84 = (x83 + (x50 << 0x1));
  834. { uint64_t x85 = (x84 + x50);
  835. { uint64_t x86 = (x85 >> 0x1a);
  836. { uint32_t x87 = ((uint32_t)x85 & 0x3ffffff);
  837. { uint64_t x88 = (x86 + x82);
  838. { uint64_t x89 = (x88 >> 0x19);
  839. { uint32_t x90 = ((uint32_t)x88 & 0x1ffffff);
  840. { uint64_t x91 = (x89 + x79);
  841. { uint64_t x92 = (x91 >> 0x1a);
  842. { uint32_t x93 = ((uint32_t)x91 & 0x3ffffff);
  843. { uint64_t x94 = (x92 + x76);
  844. { uint64_t x95 = (x94 >> 0x19);
  845. { uint32_t x96 = ((uint32_t)x94 & 0x1ffffff);
  846. { uint64_t x97 = (x95 + x73);
  847. { uint64_t x98 = (x97 >> 0x1a);
  848. { uint32_t x99 = ((uint32_t)x97 & 0x3ffffff);
  849. { uint64_t x100 = (x98 + x70);
  850. { uint64_t x101 = (x100 >> 0x19);
  851. { uint32_t x102 = ((uint32_t)x100 & 0x1ffffff);
  852. { uint64_t x103 = (x101 + x67);
  853. { uint64_t x104 = (x103 >> 0x1a);
  854. { uint32_t x105 = ((uint32_t)x103 & 0x3ffffff);
  855. { uint64_t x106 = (x104 + x64);
  856. { uint64_t x107 = (x106 >> 0x19);
  857. { uint32_t x108 = ((uint32_t)x106 & 0x1ffffff);
  858. { uint64_t x109 = (x107 + x61);
  859. { uint64_t x110 = (x109 >> 0x1a);
  860. { uint32_t x111 = ((uint32_t)x109 & 0x3ffffff);
  861. { uint64_t x112 = (x110 + x49);
  862. { uint64_t x113 = (x112 >> 0x19);
  863. { uint32_t x114 = ((uint32_t)x112 & 0x1ffffff);
  864. { uint64_t x115 = (x87 + (0x13 * x113));
  865. { uint32_t x116 = (uint32_t) (x115 >> 0x1a);
  866. { uint32_t x117 = ((uint32_t)x115 & 0x3ffffff);
  867. { uint32_t x118 = (x116 + x90);
  868. { uint32_t x119 = (x118 >> 0x19);
  869. { uint32_t x120 = (x118 & 0x1ffffff);
  870. out[0] = x117;
  871. out[1] = x120;
  872. out[2] = (x119 + x93);
  873. out[3] = x96;
  874. out[4] = x99;
  875. out[5] = x102;
  876. out[6] = x105;
  877. out[7] = x108;
  878. out[8] = x111;
  879. out[9] = x114;
  880. }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
  881. assert_fe(out);
  882. }
  883. static void fe_sq2_tt(fe *h, const fe *f) {
  884. fe_sq2_impl(h->v, f->v);
  885. }
  886. static void fe_pow22523(fe *out, const fe *z) {
  887. fe t0;
  888. fe t1;
  889. fe t2;
  890. int i;
  891. fe_sq_tt(&t0, z);
  892. fe_sq_tt(&t1, &t0);
  893. for (i = 1; i < 2; ++i) {
  894. fe_sq_tt(&t1, &t1);
  895. }
  896. fe_mul_ttt(&t1, z, &t1);
  897. fe_mul_ttt(&t0, &t0, &t1);
  898. fe_sq_tt(&t0, &t0);
  899. fe_mul_ttt(&t0, &t1, &t0);
  900. fe_sq_tt(&t1, &t0);
  901. for (i = 1; i < 5; ++i) {
  902. fe_sq_tt(&t1, &t1);
  903. }
  904. fe_mul_ttt(&t0, &t1, &t0);
  905. fe_sq_tt(&t1, &t0);
  906. for (i = 1; i < 10; ++i) {
  907. fe_sq_tt(&t1, &t1);
  908. }
  909. fe_mul_ttt(&t1, &t1, &t0);
  910. fe_sq_tt(&t2, &t1);
  911. for (i = 1; i < 20; ++i) {
  912. fe_sq_tt(&t2, &t2);
  913. }
  914. fe_mul_ttt(&t1, &t2, &t1);
  915. fe_sq_tt(&t1, &t1);
  916. for (i = 1; i < 10; ++i) {
  917. fe_sq_tt(&t1, &t1);
  918. }
  919. fe_mul_ttt(&t0, &t1, &t0);
  920. fe_sq_tt(&t1, &t0);
  921. for (i = 1; i < 50; ++i) {
  922. fe_sq_tt(&t1, &t1);
  923. }
  924. fe_mul_ttt(&t1, &t1, &t0);
  925. fe_sq_tt(&t2, &t1);
  926. for (i = 1; i < 100; ++i) {
  927. fe_sq_tt(&t2, &t2);
  928. }
  929. fe_mul_ttt(&t1, &t2, &t1);
  930. fe_sq_tt(&t1, &t1);
  931. for (i = 1; i < 50; ++i) {
  932. fe_sq_tt(&t1, &t1);
  933. }
  934. fe_mul_ttt(&t0, &t1, &t0);
  935. fe_sq_tt(&t0, &t0);
  936. for (i = 1; i < 2; ++i) {
  937. fe_sq_tt(&t0, &t0);
  938. }
  939. fe_mul_ttt(out, &t0, z);
  940. }
  941. void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h) {
  942. fe recip;
  943. fe x;
  944. fe y;
  945. fe_invert(&recip, &h->Z);
  946. fe_mul_ttt(&x, &h->X, &recip);
  947. fe_mul_ttt(&y, &h->Y, &recip);
  948. fe_tobytes(s, &y);
  949. s[31] ^= fe_isnegative(&x) << 7;
  950. }
  951. static void ge_p3_tobytes(uint8_t *s, const ge_p3 *h) {
  952. fe recip;
  953. fe x;
  954. fe y;
  955. fe_invert(&recip, &h->Z);
  956. fe_mul_ttt(&x, &h->X, &recip);
  957. fe_mul_ttt(&y, &h->Y, &recip);
  958. fe_tobytes(s, &y);
  959. s[31] ^= fe_isnegative(&x) << 7;
  960. }
  961. static const fe d = {{56195235, 13857412, 51736253, 6949390, 114729,
  962. 24766616, 60832955, 30306712, 48412415, 21499315}};
  963. static const fe sqrtm1 = {{34513072, 25610706, 9377949, 3500415, 12389472,
  964. 33281959, 41962654, 31548777, 326685, 11406482}};
  965. int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s) {
  966. fe u;
  967. fe_loose v;
  968. fe v3;
  969. fe vxx;
  970. fe_loose check;
  971. fe_frombytes(&h->Y, s);
  972. fe_1(&h->Z);
  973. fe_sq_tt(&v3, &h->Y);
  974. fe_mul_ttt(&vxx, &v3, &d);
  975. fe_sub(&v, &v3, &h->Z); // u = y^2-1
  976. fe_carry(&u, &v);
  977. fe_add(&v, &vxx, &h->Z); // v = dy^2+1
  978. fe_sq_tl(&v3, &v);
  979. fe_mul_ttl(&v3, &v3, &v); // v3 = v^3
  980. fe_sq_tt(&h->X, &v3);
  981. fe_mul_ttl(&h->X, &h->X, &v);
  982. fe_mul_ttt(&h->X, &h->X, &u); // x = uv^7
  983. fe_pow22523(&h->X, &h->X); // x = (uv^7)^((q-5)/8)
  984. fe_mul_ttt(&h->X, &h->X, &v3);
  985. fe_mul_ttt(&h->X, &h->X, &u); // x = uv^3(uv^7)^((q-5)/8)
  986. fe_sq_tt(&vxx, &h->X);
  987. fe_mul_ttl(&vxx, &vxx, &v);
  988. fe_sub(&check, &vxx, &u);
  989. if (fe_isnonzero(&check)) {
  990. fe_add(&check, &vxx, &u);
  991. if (fe_isnonzero(&check)) {
  992. return -1;
  993. }
  994. fe_mul_ttt(&h->X, &h->X, &sqrtm1);
  995. }
  996. if (fe_isnegative(&h->X) != (s[31] >> 7)) {
  997. fe_loose t;
  998. fe_neg(&t, &h->X);
  999. fe_carry(&h->X, &t);
  1000. }
  1001. fe_mul_ttt(&h->T, &h->X, &h->Y);
  1002. return 0;
  1003. }
  1004. static void ge_p2_0(ge_p2 *h) {
  1005. fe_0(&h->X);
  1006. fe_1(&h->Y);
  1007. fe_1(&h->Z);
  1008. }
  1009. static void ge_p3_0(ge_p3 *h) {
  1010. fe_0(&h->X);
  1011. fe_1(&h->Y);
  1012. fe_1(&h->Z);
  1013. fe_0(&h->T);
  1014. }
  1015. static void ge_cached_0(ge_cached *h) {
  1016. fe_loose_1(&h->YplusX);
  1017. fe_loose_1(&h->YminusX);
  1018. fe_loose_1(&h->Z);
  1019. fe_loose_0(&h->T2d);
  1020. }
  1021. static void ge_precomp_0(ge_precomp *h) {
  1022. fe_loose_1(&h->yplusx);
  1023. fe_loose_1(&h->yminusx);
  1024. fe_loose_0(&h->xy2d);
  1025. }
  1026. // r = p
  1027. static void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) {
  1028. fe_copy(&r->X, &p->X);
  1029. fe_copy(&r->Y, &p->Y);
  1030. fe_copy(&r->Z, &p->Z);
  1031. }
  1032. static const fe d2 = {{45281625, 27714825, 36363642, 13898781, 229458,
  1033. 15978800, 54557047, 27058993, 29715967, 9444199}};
  1034. // r = p
  1035. void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p) {
  1036. fe_add(&r->YplusX, &p->Y, &p->X);
  1037. fe_sub(&r->YminusX, &p->Y, &p->X);
  1038. fe_copy_lt(&r->Z, &p->Z);
  1039. fe_mul_ltt(&r->T2d, &p->T, &d2);
  1040. }
  1041. // r = p
  1042. void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) {
  1043. fe_mul_tll(&r->X, &p->X, &p->T);
  1044. fe_mul_tll(&r->Y, &p->Y, &p->Z);
  1045. fe_mul_tll(&r->Z, &p->Z, &p->T);
  1046. }
  1047. // r = p
  1048. void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) {
  1049. fe_mul_tll(&r->X, &p->X, &p->T);
  1050. fe_mul_tll(&r->Y, &p->Y, &p->Z);
  1051. fe_mul_tll(&r->Z, &p->Z, &p->T);
  1052. fe_mul_tll(&r->T, &p->X, &p->Y);
  1053. }
  1054. // r = p
  1055. static void ge_p1p1_to_cached(ge_cached *r, const ge_p1p1 *p) {
  1056. ge_p3 t;
  1057. x25519_ge_p1p1_to_p3(&t, p);
  1058. x25519_ge_p3_to_cached(r, &t);
  1059. }
  1060. // r = 2 * p
  1061. static void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) {
  1062. fe trX, trZ, trT;
  1063. fe t0;
  1064. fe_sq_tt(&trX, &p->X);
  1065. fe_sq_tt(&trZ, &p->Y);
  1066. fe_sq2_tt(&trT, &p->Z);
  1067. fe_add(&r->Y, &p->X, &p->Y);
  1068. fe_sq_tl(&t0, &r->Y);
  1069. fe_add(&r->Y, &trZ, &trX);
  1070. fe_sub(&r->Z, &trZ, &trX);
  1071. fe_carry(&trZ, &r->Y);
  1072. fe_sub(&r->X, &t0, &trZ);
  1073. fe_carry(&trZ, &r->Z);
  1074. fe_sub(&r->T, &trT, &trZ);
  1075. }
  1076. // r = 2 * p
  1077. static void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
  1078. ge_p2 q;
  1079. ge_p3_to_p2(&q, p);
  1080. ge_p2_dbl(r, &q);
  1081. }
  1082. // r = p + q
  1083. static void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
  1084. fe trY, trZ, trT;
  1085. fe_add(&r->X, &p->Y, &p->X);
  1086. fe_sub(&r->Y, &p->Y, &p->X);
  1087. fe_mul_tll(&trZ, &r->X, &q->yplusx);
  1088. fe_mul_tll(&trY, &r->Y, &q->yminusx);
  1089. fe_mul_tlt(&trT, &q->xy2d, &p->T);
  1090. fe_add(&r->T, &p->Z, &p->Z);
  1091. fe_sub(&r->X, &trZ, &trY);
  1092. fe_add(&r->Y, &trZ, &trY);
  1093. fe_carry(&trZ, &r->T);
  1094. fe_add(&r->Z, &trZ, &trT);
  1095. fe_sub(&r->T, &trZ, &trT);
  1096. }
  1097. // r = p - q
  1098. static void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
  1099. fe trY, trZ, trT;
  1100. fe_add(&r->X, &p->Y, &p->X);
  1101. fe_sub(&r->Y, &p->Y, &p->X);
  1102. fe_mul_tll(&trZ, &r->X, &q->yminusx);
  1103. fe_mul_tll(&trY, &r->Y, &q->yplusx);
  1104. fe_mul_tlt(&trT, &q->xy2d, &p->T);
  1105. fe_add(&r->T, &p->Z, &p->Z);
  1106. fe_sub(&r->X, &trZ, &trY);
  1107. fe_add(&r->Y, &trZ, &trY);
  1108. fe_carry(&trZ, &r->T);
  1109. fe_sub(&r->Z, &trZ, &trT);
  1110. fe_add(&r->T, &trZ, &trT);
  1111. }
  1112. // r = p + q
  1113. void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
  1114. fe trX, trY, trZ, trT;
  1115. fe_add(&r->X, &p->Y, &p->X);
  1116. fe_sub(&r->Y, &p->Y, &p->X);
  1117. fe_mul_tll(&trZ, &r->X, &q->YplusX);
  1118. fe_mul_tll(&trY, &r->Y, &q->YminusX);
  1119. fe_mul_tlt(&trT, &q->T2d, &p->T);
  1120. fe_mul_ttl(&trX, &p->Z, &q->Z);
  1121. fe_add(&r->T, &trX, &trX);
  1122. fe_sub(&r->X, &trZ, &trY);
  1123. fe_add(&r->Y, &trZ, &trY);
  1124. fe_carry(&trZ, &r->T);
  1125. fe_add(&r->Z, &trZ, &trT);
  1126. fe_sub(&r->T, &trZ, &trT);
  1127. }
  1128. // r = p - q
  1129. void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
  1130. fe trX, trY, trZ, trT;
  1131. fe_add(&r->X, &p->Y, &p->X);
  1132. fe_sub(&r->Y, &p->Y, &p->X);
  1133. fe_mul_tll(&trZ, &r->X, &q->YminusX);
  1134. fe_mul_tll(&trY, &r->Y, &q->YplusX);
  1135. fe_mul_tlt(&trT, &q->T2d, &p->T);
  1136. fe_mul_ttl(&trX, &p->Z, &q->Z);
  1137. fe_add(&r->T, &trX, &trX);
  1138. fe_sub(&r->X, &trZ, &trY);
  1139. fe_add(&r->Y, &trZ, &trY);
  1140. fe_carry(&trZ, &r->T);
  1141. fe_sub(&r->Z, &trZ, &trT);
  1142. fe_add(&r->T, &trZ, &trT);
  1143. }
  1144. static uint8_t equal(signed char b, signed char c) {
  1145. uint8_t ub = b;
  1146. uint8_t uc = c;
  1147. uint8_t x = ub ^ uc; // 0: yes; 1..255: no
  1148. uint32_t y = x; // 0: yes; 1..255: no
  1149. y -= 1; // 4294967295: yes; 0..254: no
  1150. y >>= 31; // 1: yes; 0: no
  1151. return y;
  1152. }
  1153. static void cmov(ge_precomp *t, const ge_precomp *u, uint8_t b) {
  1154. fe_cmov(&t->yplusx, &u->yplusx, b);
  1155. fe_cmov(&t->yminusx, &u->yminusx, b);
  1156. fe_cmov(&t->xy2d, &u->xy2d, b);
  1157. }
  1158. void x25519_ge_scalarmult_small_precomp(
  1159. ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]) {
  1160. // precomp_table is first expanded into matching |ge_precomp|
  1161. // elements.
  1162. ge_precomp multiples[15];
  1163. unsigned i;
  1164. for (i = 0; i < 15; i++) {
  1165. const uint8_t *bytes = &precomp_table[i*(2 * 32)];
  1166. fe x, y;
  1167. fe_frombytes(&x, bytes);
  1168. fe_frombytes(&y, bytes + 32);
  1169. ge_precomp *out = &multiples[i];
  1170. fe_add(&out->yplusx, &y, &x);
  1171. fe_sub(&out->yminusx, &y, &x);
  1172. fe_mul_ltt(&out->xy2d, &x, &y);
  1173. fe_mul_llt(&out->xy2d, &out->xy2d, &d2);
  1174. }
  1175. // See the comment above |k25519SmallPrecomp| about the structure of the
  1176. // precomputed elements. This loop does 64 additions and 64 doublings to
  1177. // calculate the result.
  1178. ge_p3_0(h);
  1179. for (i = 63; i < 64; i--) {
  1180. unsigned j;
  1181. signed char index = 0;
  1182. for (j = 0; j < 4; j++) {
  1183. const uint8_t bit = 1 & (a[(8 * j) + (i / 8)] >> (i & 7));
  1184. index |= (bit << j);
  1185. }
  1186. ge_precomp e;
  1187. ge_precomp_0(&e);
  1188. for (j = 1; j < 16; j++) {
  1189. cmov(&e, &multiples[j-1], equal(index, j));
  1190. }
  1191. ge_cached cached;
  1192. ge_p1p1 r;
  1193. x25519_ge_p3_to_cached(&cached, h);
  1194. x25519_ge_add(&r, h, &cached);
  1195. x25519_ge_p1p1_to_p3(h, &r);
  1196. ge_madd(&r, h, &e);
  1197. x25519_ge_p1p1_to_p3(h, &r);
  1198. }
  1199. }
  1200. #if defined(OPENSSL_SMALL)
  1201. // This block of code replaces the standard base-point table with a much smaller
  1202. // one. The standard table is 30,720 bytes while this one is just 960.
  1203. //
  1204. // This table contains 15 pairs of group elements, (x, y), where each field
  1205. // element is serialised with |fe_tobytes|. If |i| is the index of the group
  1206. // element then consider i+1 as a four-bit number: (i₀, i₁, i₂, i₃) (where i₀
  1207. // is the most significant bit). The value of the group element is then:
  1208. // (i₀×2^192 + i₁×2^128 + i₂×2^64 + i₃)G, where G is the generator.
  1209. static const uint8_t k25519SmallPrecomp[15 * 2 * 32] = {
  1210. 0x1a, 0xd5, 0x25, 0x8f, 0x60, 0x2d, 0x56, 0xc9, 0xb2, 0xa7, 0x25, 0x95,
  1211. 0x60, 0xc7, 0x2c, 0x69, 0x5c, 0xdc, 0xd6, 0xfd, 0x31, 0xe2, 0xa4, 0xc0,
  1212. 0xfe, 0x53, 0x6e, 0xcd, 0xd3, 0x36, 0x69, 0x21, 0x58, 0x66, 0x66, 0x66,
  1213. 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
  1214. 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
  1215. 0x66, 0x66, 0x66, 0x66, 0x02, 0xa2, 0xed, 0xf4, 0x8f, 0x6b, 0x0b, 0x3e,
  1216. 0xeb, 0x35, 0x1a, 0xd5, 0x7e, 0xdb, 0x78, 0x00, 0x96, 0x8a, 0xa0, 0xb4,
  1217. 0xcf, 0x60, 0x4b, 0xd4, 0xd5, 0xf9, 0x2d, 0xbf, 0x88, 0xbd, 0x22, 0x62,
  1218. 0x13, 0x53, 0xe4, 0x82, 0x57, 0xfa, 0x1e, 0x8f, 0x06, 0x2b, 0x90, 0xba,
  1219. 0x08, 0xb6, 0x10, 0x54, 0x4f, 0x7c, 0x1b, 0x26, 0xed, 0xda, 0x6b, 0xdd,
  1220. 0x25, 0xd0, 0x4e, 0xea, 0x42, 0xbb, 0x25, 0x03, 0xa2, 0xfb, 0xcc, 0x61,
  1221. 0x67, 0x06, 0x70, 0x1a, 0xc4, 0x78, 0x3a, 0xff, 0x32, 0x62, 0xdd, 0x2c,
  1222. 0xab, 0x50, 0x19, 0x3b, 0xf2, 0x9b, 0x7d, 0xb8, 0xfd, 0x4f, 0x29, 0x9c,
  1223. 0xa7, 0x91, 0xba, 0x0e, 0x46, 0x5e, 0x51, 0xfe, 0x1d, 0xbf, 0xe5, 0xe5,
  1224. 0x9b, 0x95, 0x0d, 0x67, 0xf8, 0xd1, 0xb5, 0x5a, 0xa1, 0x93, 0x2c, 0xc3,
  1225. 0xde, 0x0e, 0x97, 0x85, 0x2d, 0x7f, 0xea, 0xab, 0x3e, 0x47, 0x30, 0x18,
  1226. 0x24, 0xe8, 0xb7, 0x60, 0xae, 0x47, 0x80, 0xfc, 0xe5, 0x23, 0xe7, 0xc2,
  1227. 0xc9, 0x85, 0xe6, 0x98, 0xa0, 0x29, 0x4e, 0xe1, 0x84, 0x39, 0x2d, 0x95,
  1228. 0x2c, 0xf3, 0x45, 0x3c, 0xff, 0xaf, 0x27, 0x4c, 0x6b, 0xa6, 0xf5, 0x4b,
  1229. 0x11, 0xbd, 0xba, 0x5b, 0x9e, 0xc4, 0xa4, 0x51, 0x1e, 0xbe, 0xd0, 0x90,
  1230. 0x3a, 0x9c, 0xc2, 0x26, 0xb6, 0x1e, 0xf1, 0x95, 0x7d, 0xc8, 0x6d, 0x52,
  1231. 0xe6, 0x99, 0x2c, 0x5f, 0x9a, 0x96, 0x0c, 0x68, 0x29, 0xfd, 0xe2, 0xfb,
  1232. 0xe6, 0xbc, 0xec, 0x31, 0x08, 0xec, 0xe6, 0xb0, 0x53, 0x60, 0xc3, 0x8c,
  1233. 0xbe, 0xc1, 0xb3, 0x8a, 0x8f, 0xe4, 0x88, 0x2b, 0x55, 0xe5, 0x64, 0x6e,
  1234. 0x9b, 0xd0, 0xaf, 0x7b, 0x64, 0x2a, 0x35, 0x25, 0x10, 0x52, 0xc5, 0x9e,
  1235. 0x58, 0x11, 0x39, 0x36, 0x45, 0x51, 0xb8, 0x39, 0x93, 0xfc, 0x9d, 0x6a,
  1236. 0xbe, 0x58, 0xcb, 0xa4, 0x0f, 0x51, 0x3c, 0x38, 0x05, 0xca, 0xab, 0x43,
  1237. 0x63, 0x0e, 0xf3, 0x8b, 0x41, 0xa6, 0xf8, 0x9b, 0x53, 0x70, 0x80, 0x53,
  1238. 0x86, 0x5e, 0x8f, 0xe3, 0xc3, 0x0d, 0x18, 0xc8, 0x4b, 0x34, 0x1f, 0xd8,
  1239. 0x1d, 0xbc, 0xf2, 0x6d, 0x34, 0x3a, 0xbe, 0xdf, 0xd9, 0xf6, 0xf3, 0x89,
  1240. 0xa1, 0xe1, 0x94, 0x9f, 0x5d, 0x4c, 0x5d, 0xe9, 0xa1, 0x49, 0x92, 0xef,
  1241. 0x0e, 0x53, 0x81, 0x89, 0x58, 0x87, 0xa6, 0x37, 0xf1, 0xdd, 0x62, 0x60,
  1242. 0x63, 0x5a, 0x9d, 0x1b, 0x8c, 0xc6, 0x7d, 0x52, 0xea, 0x70, 0x09, 0x6a,
  1243. 0xe1, 0x32, 0xf3, 0x73, 0x21, 0x1f, 0x07, 0x7b, 0x7c, 0x9b, 0x49, 0xd8,
  1244. 0xc0, 0xf3, 0x25, 0x72, 0x6f, 0x9d, 0xed, 0x31, 0x67, 0x36, 0x36, 0x54,
  1245. 0x40, 0x92, 0x71, 0xe6, 0x11, 0x28, 0x11, 0xad, 0x93, 0x32, 0x85, 0x7b,
  1246. 0x3e, 0xb7, 0x3b, 0x49, 0x13, 0x1c, 0x07, 0xb0, 0x2e, 0x93, 0xaa, 0xfd,
  1247. 0xfd, 0x28, 0x47, 0x3d, 0x8d, 0xd2, 0xda, 0xc7, 0x44, 0xd6, 0x7a, 0xdb,
  1248. 0x26, 0x7d, 0x1d, 0xb8, 0xe1, 0xde, 0x9d, 0x7a, 0x7d, 0x17, 0x7e, 0x1c,
  1249. 0x37, 0x04, 0x8d, 0x2d, 0x7c, 0x5e, 0x18, 0x38, 0x1e, 0xaf, 0xc7, 0x1b,
  1250. 0x33, 0x48, 0x31, 0x00, 0x59, 0xf6, 0xf2, 0xca, 0x0f, 0x27, 0x1b, 0x63,
  1251. 0x12, 0x7e, 0x02, 0x1d, 0x49, 0xc0, 0x5d, 0x79, 0x87, 0xef, 0x5e, 0x7a,
  1252. 0x2f, 0x1f, 0x66, 0x55, 0xd8, 0x09, 0xd9, 0x61, 0x38, 0x68, 0xb0, 0x07,
  1253. 0xa3, 0xfc, 0xcc, 0x85, 0x10, 0x7f, 0x4c, 0x65, 0x65, 0xb3, 0xfa, 0xfa,
  1254. 0xa5, 0x53, 0x6f, 0xdb, 0x74, 0x4c, 0x56, 0x46, 0x03, 0xe2, 0xd5, 0x7a,
  1255. 0x29, 0x1c, 0xc6, 0x02, 0xbc, 0x59, 0xf2, 0x04, 0x75, 0x63, 0xc0, 0x84,
  1256. 0x2f, 0x60, 0x1c, 0x67, 0x76, 0xfd, 0x63, 0x86, 0xf3, 0xfa, 0xbf, 0xdc,
  1257. 0xd2, 0x2d, 0x90, 0x91, 0xbd, 0x33, 0xa9, 0xe5, 0x66, 0x0c, 0xda, 0x42,
  1258. 0x27, 0xca, 0xf4, 0x66, 0xc2, 0xec, 0x92, 0x14, 0x57, 0x06, 0x63, 0xd0,
  1259. 0x4d, 0x15, 0x06, 0xeb, 0x69, 0x58, 0x4f, 0x77, 0xc5, 0x8b, 0xc7, 0xf0,
  1260. 0x8e, 0xed, 0x64, 0xa0, 0xb3, 0x3c, 0x66, 0x71, 0xc6, 0x2d, 0xda, 0x0a,
  1261. 0x0d, 0xfe, 0x70, 0x27, 0x64, 0xf8, 0x27, 0xfa, 0xf6, 0x5f, 0x30, 0xa5,
  1262. 0x0d, 0x6c, 0xda, 0xf2, 0x62, 0x5e, 0x78, 0x47, 0xd3, 0x66, 0x00, 0x1c,
  1263. 0xfd, 0x56, 0x1f, 0x5d, 0x3f, 0x6f, 0xf4, 0x4c, 0xd8, 0xfd, 0x0e, 0x27,
  1264. 0xc9, 0x5c, 0x2b, 0xbc, 0xc0, 0xa4, 0xe7, 0x23, 0x29, 0x02, 0x9f, 0x31,
  1265. 0xd6, 0xe9, 0xd7, 0x96, 0xf4, 0xe0, 0x5e, 0x0b, 0x0e, 0x13, 0xee, 0x3c,
  1266. 0x09, 0xed, 0xf2, 0x3d, 0x76, 0x91, 0xc3, 0xa4, 0x97, 0xae, 0xd4, 0x87,
  1267. 0xd0, 0x5d, 0xf6, 0x18, 0x47, 0x1f, 0x1d, 0x67, 0xf2, 0xcf, 0x63, 0xa0,
  1268. 0x91, 0x27, 0xf8, 0x93, 0x45, 0x75, 0x23, 0x3f, 0xd1, 0xf1, 0xad, 0x23,
  1269. 0xdd, 0x64, 0x93, 0x96, 0x41, 0x70, 0x7f, 0xf7, 0xf5, 0xa9, 0x89, 0xa2,
  1270. 0x34, 0xb0, 0x8d, 0x1b, 0xae, 0x19, 0x15, 0x49, 0x58, 0x23, 0x6d, 0x87,
  1271. 0x15, 0x4f, 0x81, 0x76, 0xfb, 0x23, 0xb5, 0xea, 0xcf, 0xac, 0x54, 0x8d,
  1272. 0x4e, 0x42, 0x2f, 0xeb, 0x0f, 0x63, 0xdb, 0x68, 0x37, 0xa8, 0xcf, 0x8b,
  1273. 0xab, 0xf5, 0xa4, 0x6e, 0x96, 0x2a, 0xb2, 0xd6, 0xbe, 0x9e, 0xbd, 0x0d,
  1274. 0xb4, 0x42, 0xa9, 0xcf, 0x01, 0x83, 0x8a, 0x17, 0x47, 0x76, 0xc4, 0xc6,
  1275. 0x83, 0x04, 0x95, 0x0b, 0xfc, 0x11, 0xc9, 0x62, 0xb8, 0x0c, 0x76, 0x84,
  1276. 0xd9, 0xb9, 0x37, 0xfa, 0xfc, 0x7c, 0xc2, 0x6d, 0x58, 0x3e, 0xb3, 0x04,
  1277. 0xbb, 0x8c, 0x8f, 0x48, 0xbc, 0x91, 0x27, 0xcc, 0xf9, 0xb7, 0x22, 0x19,
  1278. 0x83, 0x2e, 0x09, 0xb5, 0x72, 0xd9, 0x54, 0x1c, 0x4d, 0xa1, 0xea, 0x0b,
  1279. 0xf1, 0xc6, 0x08, 0x72, 0x46, 0x87, 0x7a, 0x6e, 0x80, 0x56, 0x0a, 0x8a,
  1280. 0xc0, 0xdd, 0x11, 0x6b, 0xd6, 0xdd, 0x47, 0xdf, 0x10, 0xd9, 0xd8, 0xea,
  1281. 0x7c, 0xb0, 0x8f, 0x03, 0x00, 0x2e, 0xc1, 0x8f, 0x44, 0xa8, 0xd3, 0x30,
  1282. 0x06, 0x89, 0xa2, 0xf9, 0x34, 0xad, 0xdc, 0x03, 0x85, 0xed, 0x51, 0xa7,
  1283. 0x82, 0x9c, 0xe7, 0x5d, 0x52, 0x93, 0x0c, 0x32, 0x9a, 0x5b, 0xe1, 0xaa,
  1284. 0xca, 0xb8, 0x02, 0x6d, 0x3a, 0xd4, 0xb1, 0x3a, 0xf0, 0x5f, 0xbe, 0xb5,
  1285. 0x0d, 0x10, 0x6b, 0x38, 0x32, 0xac, 0x76, 0x80, 0xbd, 0xca, 0x94, 0x71,
  1286. 0x7a, 0xf2, 0xc9, 0x35, 0x2a, 0xde, 0x9f, 0x42, 0x49, 0x18, 0x01, 0xab,
  1287. 0xbc, 0xef, 0x7c, 0x64, 0x3f, 0x58, 0x3d, 0x92, 0x59, 0xdb, 0x13, 0xdb,
  1288. 0x58, 0x6e, 0x0a, 0xe0, 0xb7, 0x91, 0x4a, 0x08, 0x20, 0xd6, 0x2e, 0x3c,
  1289. 0x45, 0xc9, 0x8b, 0x17, 0x79, 0xe7, 0xc7, 0x90, 0x99, 0x3a, 0x18, 0x25,
  1290. };
  1291. void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
  1292. x25519_ge_scalarmult_small_precomp(h, a, k25519SmallPrecomp);
  1293. }
  1294. #else
  1295. // k25519Precomp[i][j] = (j+1)*256^i*B
  1296. static const ge_precomp k25519Precomp[32][8] = {
  1297. {
  1298. {
  1299. {{25967493, 19198397, 29566455, 3660896, 54414519, 4014786,
  1300. 27544626, 21800161, 61029707, 2047604}},
  1301. {{54563134, 934261, 64385954, 3049989, 66381436, 9406985, 12720692,
  1302. 5043384, 19500929, 18085054}},
  1303. {{58370664, 4489569, 9688441, 18769238, 10184608, 21191052,
  1304. 29287918, 11864899, 42594502, 29115885}},
  1305. },
  1306. {
  1307. {{54292951, 20578084, 45527620, 11784319, 41753206, 30803714,
  1308. 55390960, 29739860, 66750418, 23343128}},
  1309. {{45405608, 6903824, 27185491, 6451973, 37531140, 24000426,
  1310. 51492312, 11189267, 40279186, 28235350}},
  1311. {{26966623, 11152617, 32442495, 15396054, 14353839, 20802097,
  1312. 63980037, 24013313, 51636816, 29387734}},
  1313. },
  1314. {
  1315. {{15636272, 23865875, 24204772, 25642034, 616976, 16869170,
  1316. 27787599, 18782243, 28944399, 32004408}},
  1317. {{16568933, 4717097, 55552716, 32452109, 15682895, 21747389,
  1318. 16354576, 21778470, 7689661, 11199574}},
  1319. {{30464137, 27578307, 55329429, 17883566, 23220364, 15915852,
  1320. 7512774, 10017326, 49359771, 23634074}},
  1321. },
  1322. {
  1323. {{50071967, 13921891, 10945806, 27521001, 27105051, 17470053,
  1324. 38182653, 15006022, 3284568, 27277892}},
  1325. {{23599295, 25248385, 55915199, 25867015, 13236773, 10506355,
  1326. 7464579, 9656445, 13059162, 10374397}},
  1327. {{7798537, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664,
  1328. 29715387, 66467155, 33453106}},
  1329. },
  1330. {
  1331. {{10861363, 11473154, 27284546, 1981175, 37044515, 12577860,
  1332. 32867885, 14515107, 51670560, 10819379}},
  1333. {{4708026, 6336745, 20377586, 9066809, 55836755, 6594695, 41455196,
  1334. 12483687, 54440373, 5581305}},
  1335. {{19563141, 16186464, 37722007, 4097518, 10237984, 29206317,
  1336. 28542349, 13850243, 43430843, 17738489}},
  1337. },
  1338. {
  1339. {{51736881, 20691677, 32573249, 4720197, 40672342, 5875510,
  1340. 47920237, 18329612, 57289923, 21468654}},
  1341. {{58559652, 109982, 15149363, 2178705, 22900618, 4543417, 3044240,
  1342. 17864545, 1762327, 14866737}},
  1343. {{48909169, 17603008, 56635573, 1707277, 49922944, 3916100,
  1344. 38872452, 3959420, 27914454, 4383652}},
  1345. },
  1346. {
  1347. {{5153727, 9909285, 1723747, 30776558, 30523604, 5516873, 19480852,
  1348. 5230134, 43156425, 18378665}},
  1349. {{36839857, 30090922, 7665485, 10083793, 28475525, 1649722,
  1350. 20654025, 16520125, 30598449, 7715701}},
  1351. {{28881826, 14381568, 9657904, 3680757, 46927229, 7843315,
  1352. 35708204, 1370707, 29794553, 32145132}},
  1353. },
  1354. {
  1355. {{14499471, 30824833, 33917750, 29299779, 28494861, 14271267,
  1356. 30290735, 10876454, 33954766, 2381725}},
  1357. {{59913433, 30899068, 52378708, 462250, 39384538, 3941371,
  1358. 60872247, 3696004, 34808032, 15351954}},
  1359. {{27431194, 8222322, 16448760, 29646437, 48401861, 11938354,
  1360. 34147463, 30583916, 29551812, 10109425}},
  1361. },
  1362. },
  1363. {
  1364. {
  1365. {{53451805, 20399000, 35825113, 11777097, 21447386, 6519384,
  1366. 64730580, 31926875, 10092782, 28790261}},
  1367. {{27939166, 14210322, 4677035, 16277044, 44144402, 21156292,
  1368. 34600109, 12005537, 49298737, 12803509}},
  1369. {{17228999, 17892808, 65875336, 300139, 65883994, 21839654,
  1370. 30364212, 24516238, 18016356, 4397660}},
  1371. },
  1372. {
  1373. {{56150021, 25864224, 4776340, 18600194, 27850027, 17952220,
  1374. 40489757, 14544524, 49631360, 982638}},
  1375. {{29253598, 15796703, 64244882, 23645547, 10057022, 3163536, 7332899,
  1376. 29434304, 46061167, 9934962}},
  1377. {{5793284, 16271923, 42977250, 23438027, 29188559, 1206517,
  1378. 52360934, 4559894, 36984942, 22656481}},
  1379. },
  1380. {
  1381. {{39464912, 22061425, 16282656, 22517939, 28414020, 18542168,
  1382. 24191033, 4541697, 53770555, 5500567}},
  1383. {{12650548, 32057319, 9052870, 11355358, 49428827, 25154267,
  1384. 49678271, 12264342, 10874051, 13524335}},
  1385. {{25556948, 30508442, 714650, 2510400, 23394682, 23139102, 33119037,
  1386. 5080568, 44580805, 5376627}},
  1387. },
  1388. {
  1389. {{41020600, 29543379, 50095164, 30016803, 60382070, 1920896,
  1390. 44787559, 24106988, 4535767, 1569007}},
  1391. {{64853442, 14606629, 45416424, 25514613, 28430648, 8775819,
  1392. 36614302, 3044289, 31848280, 12543772}},
  1393. {{45080285, 2943892, 35251351, 6777305, 13784462, 29262229,
  1394. 39731668, 31491700, 7718481, 14474653}},
  1395. },
  1396. {
  1397. {{2385296, 2454213, 44477544, 46602, 62670929, 17874016, 656964,
  1398. 26317767, 24316167, 28300865}},
  1399. {{13741529, 10911568, 33875447, 24950694, 46931033, 32521134,
  1400. 33040650, 20129900, 46379407, 8321685}},
  1401. {{21060490, 31341688, 15712756, 29218333, 1639039, 10656336,
  1402. 23845965, 21679594, 57124405, 608371}},
  1403. },
  1404. {
  1405. {{53436132, 18466845, 56219170, 25997372, 61071954, 11305546,
  1406. 1123968, 26773855, 27229398, 23887}},
  1407. {{43864724, 33260226, 55364135, 14712570, 37643165, 31524814,
  1408. 12797023, 27114124, 65475458, 16678953}},
  1409. {{37608244, 4770661, 51054477, 14001337, 7830047, 9564805,
  1410. 65600720, 28759386, 49939598, 4904952}},
  1411. },
  1412. {
  1413. {{24059538, 14617003, 19037157, 18514524, 19766092, 18648003,
  1414. 5169210, 16191880, 2128236, 29227599}},
  1415. {{50127693, 4124965, 58568254, 22900634, 30336521, 19449185,
  1416. 37302527, 916032, 60226322, 30567899}},
  1417. {{44477957, 12419371, 59974635, 26081060, 50629959, 16739174,
  1418. 285431, 2763829, 15736322, 4143876}},
  1419. },
  1420. {
  1421. {{2379333, 11839345, 62998462, 27565766, 11274297, 794957, 212801,
  1422. 18959769, 23527083, 17096164}},
  1423. {{33431108, 22423954, 49269897, 17927531, 8909498, 8376530,
  1424. 34483524, 4087880, 51919953, 19138217}},
  1425. {{1767664, 7197987, 53903638, 31531796, 54017513, 448825, 5799055,
  1426. 4357868, 62334673, 17231393}},
  1427. },
  1428. },
  1429. {
  1430. {
  1431. {{6721966, 13833823, 43585476, 32003117, 26354292, 21691111,
  1432. 23365146, 29604700, 7390889, 2759800}},
  1433. {{4409022, 2052381, 23373853, 10530217, 7676779, 20668478, 21302352,
  1434. 29290375, 1244379, 20634787}},
  1435. {{62687625, 7169618, 4982368, 30596842, 30256824, 30776892, 14086412,
  1436. 9208236, 15886429, 16489664}},
  1437. },
  1438. {
  1439. {{1996056, 10375649, 14346367, 13311202, 60234729, 17116020,
  1440. 53415665, 398368, 36502409, 32841498}},
  1441. {{41801399, 9795879, 64331450, 14878808, 33577029, 14780362,
  1442. 13348553, 12076947, 36272402, 5113181}},
  1443. {{49338080, 11797795, 31950843, 13929123, 41220562, 12288343,
  1444. 36767763, 26218045, 13847710, 5387222}},
  1445. },
  1446. {
  1447. {{48526701, 30138214, 17824842, 31213466, 22744342, 23111821,
  1448. 8763060, 3617786, 47508202, 10370990}},
  1449. {{20246567, 19185054, 22358228, 33010720, 18507282, 23140436,
  1450. 14554436, 24808340, 32232923, 16763880}},
  1451. {{9648486, 10094563, 26416693, 14745928, 36734546, 27081810,
  1452. 11094160, 15689506, 3140038, 17044340}},
  1453. },
  1454. {
  1455. {{50948792, 5472694, 31895588, 4744994, 8823515, 10365685,
  1456. 39884064, 9448612, 38334410, 366294}},
  1457. {{19153450, 11523972, 56012374, 27051289, 42461232, 5420646,
  1458. 28344573, 8041113, 719605, 11671788}},
  1459. {{8678006, 2694440, 60300850, 2517371, 4964326, 11152271, 51675948,
  1460. 18287915, 27000812, 23358879}},
  1461. },
  1462. {
  1463. {{51950941, 7134311, 8639287, 30739555, 59873175, 10421741, 564065,
  1464. 5336097, 6750977, 19033406}},
  1465. {{11836410, 29574944, 26297893, 16080799, 23455045, 15735944,
  1466. 1695823, 24735310, 8169719, 16220347}},
  1467. {{48993007, 8653646, 17578566, 27461813, 59083086, 17541668,
  1468. 55964556, 30926767, 61118155, 19388398}},
  1469. },
  1470. {
  1471. {{43800366, 22586119, 15213227, 23473218, 36255258, 22504427,
  1472. 27884328, 2847284, 2655861, 1738395}},
  1473. {{39571412, 19301410, 41772562, 25551651, 57738101, 8129820,
  1474. 21651608, 30315096, 48021414, 22549153}},
  1475. {{1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092,
  1476. 5821408, 10478196, 8544890}},
  1477. },
  1478. {
  1479. {{32173102, 17425121, 24896206, 3921497, 22579056, 30143578,
  1480. 19270448, 12217473, 17789017, 30158437}},
  1481. {{36555903, 31326030, 51530034, 23407230, 13243888, 517024,
  1482. 15479401, 29701199, 30460519, 1052596}},
  1483. {{55493970, 13323617, 32618793, 8175907, 51878691, 12596686,
  1484. 27491595, 28942073, 3179267, 24075541}},
  1485. },
  1486. {
  1487. {{31947050, 19187781, 62468280, 18214510, 51982886, 27514722,
  1488. 52352086, 17142691, 19072639, 24043372}},
  1489. {{11685058, 11822410, 3158003, 19601838, 33402193, 29389366,
  1490. 5977895, 28339415, 473098, 5040608}},
  1491. {{46817982, 8198641, 39698732, 11602122, 1290375, 30754672,
  1492. 28326861, 1721092, 47550222, 30422825}},
  1493. },
  1494. },
  1495. {
  1496. {
  1497. {{7881532, 10687937, 7578723, 7738378, 48157852, 31000479, 21820785,
  1498. 8076149, 39240368, 11538388}},
  1499. {{47173198, 3899860, 18283497, 26752864, 51380203, 22305220,
  1500. 8754524, 7446702, 61432810, 5797015}},
  1501. {{55813245, 29760862, 51326753, 25589858, 12708868, 25098233,
  1502. 2014098, 24503858, 64739691, 27677090}},
  1503. },
  1504. {
  1505. {{44636488, 21985690, 39426843, 1146374, 18956691, 16640559,
  1506. 1192730, 29840233, 15123618, 10811505}},
  1507. {{14352079, 30134717, 48166819, 10822654, 32750596, 4699007, 67038501,
  1508. 15776355, 38222085, 21579878}},
  1509. {{38867681, 25481956, 62129901, 28239114, 29416930, 1847569,
  1510. 46454691, 17069576, 4714546, 23953777}},
  1511. },
  1512. {
  1513. {{15200332, 8368572, 19679101, 15970074, 35236190, 1959450,
  1514. 24611599, 29010600, 55362987, 12340219}},
  1515. {{12876937, 23074376, 33134380, 6590940, 60801088, 14872439,
  1516. 9613953, 8241152, 15370987, 9608631}},
  1517. {{62965568, 21540023, 8446280, 33162829, 4407737, 13629032, 59383996,
  1518. 15866073, 38898243, 24740332}},
  1519. },
  1520. {
  1521. {{26660628, 17876777, 8393733, 358047, 59707573, 992987, 43204631,
  1522. 858696, 20571223, 8420556}},
  1523. {{14620696, 13067227, 51661590, 8264466, 14106269, 15080814,
  1524. 33531827, 12516406, 45534429, 21077682}},
  1525. {{236881, 10476226, 57258, 18877408, 6472997, 2466984, 17258519,
  1526. 7256740, 8791136, 15069930}},
  1527. },
  1528. {
  1529. {{1276391, 24182514, 22949634, 17231625, 43615824, 27852245,
  1530. 14711874, 4874229, 36445724, 31223040}},
  1531. {{5855666, 4990204, 53397016, 7294283, 59304582, 1924646, 65685689,
  1532. 25642053, 34039526, 9234252}},
  1533. {{20590503, 24535444, 31529743, 26201766, 64402029, 10650547,
  1534. 31559055, 21944845, 18979185, 13396066}},
  1535. },
  1536. {
  1537. {{24474287, 4968103, 22267082, 4407354, 24063882, 25229252,
  1538. 48291976, 13594781, 33514650, 7021958}},
  1539. {{55541958, 26988926, 45743778, 15928891, 40950559, 4315420,
  1540. 41160136, 29637754, 45628383, 12868081}},
  1541. {{38473832, 13504660, 19988037, 31421671, 21078224, 6443208,
  1542. 45662757, 2244499, 54653067, 25465048}},
  1543. },
  1544. {
  1545. {{36513336, 13793478, 61256044, 319135, 41385692, 27290532,
  1546. 33086545, 8957937, 51875216, 5540520}},
  1547. {{55478669, 22050529, 58989363, 25911358, 2620055, 1022908,
  1548. 43398120, 31985447, 50980335, 18591624}},
  1549. {{23152952, 775386, 27395463, 14006635, 57407746, 4649511, 1689819,
  1550. 892185, 55595587, 18348483}},
  1551. },
  1552. {
  1553. {{9770129, 9586738, 26496094, 4324120, 1556511, 30004408, 27453818,
  1554. 4763127, 47929250, 5867133}},
  1555. {{34343820, 1927589, 31726409, 28801137, 23962433, 17534932,
  1556. 27846558, 5931263, 37359161, 17445976}},
  1557. {{27461885, 30576896, 22380809, 1815854, 44075111, 30522493,
  1558. 7283489, 18406359, 47582163, 7734628}},
  1559. },
  1560. },
  1561. {
  1562. {
  1563. {{59098600, 23963614, 55988460, 6196037, 29344158, 20123547,
  1564. 7585294, 30377806, 18549496, 15302069}},
  1565. {{34450527, 27383209, 59436070, 22502750, 6258877, 13504381,
  1566. 10458790, 27135971, 58236621, 8424745}},
  1567. {{24687186, 8613276, 36441818, 30320886, 1863891, 31723888,
  1568. 19206233, 7134917, 55824382, 32725512}},
  1569. },
  1570. {
  1571. {{11334899, 24336410, 8025292, 12707519, 17523892, 23078361,
  1572. 10243737, 18868971, 62042829, 16498836}},
  1573. {{8911542, 6887158, 57524604, 26595841, 11145640, 24010752, 17303924,
  1574. 19430194, 6536640, 10543906}},
  1575. {{38162480, 15479762, 49642029, 568875, 65611181, 11223453,
  1576. 64439674, 16928857, 39873154, 8876770}},
  1577. },
  1578. {
  1579. {{41365946, 20987567, 51458897, 32707824, 34082177, 32758143,
  1580. 33627041, 15824473, 66504438, 24514614}},
  1581. {{10330056, 70051, 7957388, 24551765, 9764901, 15609756, 27698697,
  1582. 28664395, 1657393, 3084098}},
  1583. {{10477963, 26084172, 12119565, 20303627, 29016246, 28188843,
  1584. 31280318, 14396151, 36875289, 15272408}},
  1585. },
  1586. {
  1587. {{54820555, 3169462, 28813183, 16658753, 25116432, 27923966,
  1588. 41934906, 20918293, 42094106, 1950503}},
  1589. {{40928506, 9489186, 11053416, 18808271, 36055143, 5825629,
  1590. 58724558, 24786899, 15341278, 8373727}},
  1591. {{28685821, 7759505, 52730348, 21551571, 35137043, 4079241,
  1592. 298136, 23321830, 64230656, 15190419}},
  1593. },
  1594. {
  1595. {{34175969, 13806335, 52771379, 17760000, 43104243, 10940927,
  1596. 8669718, 2742393, 41075551, 26679428}},
  1597. {{65528476, 21825014, 41129205, 22109408, 49696989, 22641577,
  1598. 9291593, 17306653, 54954121, 6048604}},
  1599. {{36803549, 14843443, 1539301, 11864366, 20201677, 1900163,
  1600. 13934231, 5128323, 11213262, 9168384}},
  1601. },
  1602. {
  1603. {{40828332, 11007846, 19408960, 32613674, 48515898, 29225851,
  1604. 62020803, 22449281, 20470156, 17155731}},
  1605. {{43972811, 9282191, 14855179, 18164354, 59746048, 19145871,
  1606. 44324911, 14461607, 14042978, 5230683}},
  1607. {{29969548, 30812838, 50396996, 25001989, 9175485, 31085458,
  1608. 21556950, 3506042, 61174973, 21104723}},
  1609. },
  1610. {
  1611. {{63964118, 8744660, 19704003, 4581278, 46678178, 6830682,
  1612. 45824694, 8971512, 38569675, 15326562}},
  1613. {{47644235, 10110287, 49846336, 30050539, 43608476, 1355668,
  1614. 51585814, 15300987, 46594746, 9168259}},
  1615. {{61755510, 4488612, 43305616, 16314346, 7780487, 17915493,
  1616. 38160505, 9601604, 33087103, 24543045}},
  1617. },
  1618. {
  1619. {{47665694, 18041531, 46311396, 21109108, 37284416, 10229460,
  1620. 39664535, 18553900, 61111993, 15664671}},
  1621. {{23294591, 16921819, 44458082, 25083453, 27844203, 11461195,
  1622. 13099750, 31094076, 18151675, 13417686}},
  1623. {{42385932, 29377914, 35958184, 5988918, 40250079, 6685064,
  1624. 1661597, 21002991, 15271675, 18101767}},
  1625. },
  1626. },
  1627. {
  1628. {
  1629. {{11433023, 20325767, 8239630, 28274915, 65123427, 32828713,
  1630. 48410099, 2167543, 60187563, 20114249}},
  1631. {{35672693, 15575145, 30436815, 12192228, 44645511, 9395378,
  1632. 57191156, 24915434, 12215109, 12028277}},
  1633. {{14098381, 6555944, 23007258, 5757252, 51681032, 20603929,
  1634. 30123439, 4617780, 50208775, 32898803}},
  1635. },
  1636. {
  1637. {{63082644, 18313596, 11893167, 13718664, 52299402, 1847384,
  1638. 51288865, 10154008, 23973261, 20869958}},
  1639. {{40577025, 29858441, 65199965, 2534300, 35238307, 17004076,
  1640. 18341389, 22134481, 32013173, 23450893}},
  1641. {{41629544, 10876442, 55337778, 18929291, 54739296, 1838103,
  1642. 21911214, 6354752, 4425632, 32716610}},
  1643. },
  1644. {
  1645. {{56675475, 18941465, 22229857, 30463385, 53917697, 776728,
  1646. 49693489, 21533969, 4725004, 14044970}},
  1647. {{19268631, 26250011, 1555348, 8692754, 45634805, 23643767, 6347389,
  1648. 32142648, 47586572, 17444675}},
  1649. {{42244775, 12986007, 56209986, 27995847, 55796492, 33405905,
  1650. 19541417, 8180106, 9282262, 10282508}},
  1651. },
  1652. {
  1653. {{40903763, 4428546, 58447668, 20360168, 4098401, 19389175,
  1654. 15522534, 8372215, 5542595, 22851749}},
  1655. {{56546323, 14895632, 26814552, 16880582, 49628109, 31065071,
  1656. 64326972, 6993760, 49014979, 10114654}},
  1657. {{47001790, 32625013, 31422703, 10427861, 59998115, 6150668,
  1658. 38017109, 22025285, 25953724, 33448274}},
  1659. },
  1660. {
  1661. {{62874467, 25515139, 57989738, 3045999, 2101609, 20947138,
  1662. 19390019, 6094296, 63793585, 12831124}},
  1663. {{51110167, 7578151, 5310217, 14408357, 33560244, 33329692,
  1664. 31575953, 6326196, 7381791, 31132593}},
  1665. {{46206085, 3296810, 24736065, 17226043, 18374253, 7318640,
  1666. 6295303, 8082724, 51746375, 12339663}},
  1667. },
  1668. {
  1669. {{27724736, 2291157, 6088201, 19369634, 1792726, 5857634, 13848414,
  1670. 15768922, 25091167, 14856294}},
  1671. {{48242193, 8331042, 24373479, 8541013, 66406866, 24284974, 12927299,
  1672. 20858939, 44926390, 24541532}},
  1673. {{55685435, 28132841, 11632844, 3405020, 30536730, 21880393,
  1674. 39848098, 13866389, 30146206, 9142070}},
  1675. },
  1676. {
  1677. {{3924129, 18246916, 53291741, 23499471, 12291819, 32886066,
  1678. 39406089, 9326383, 58871006, 4171293}},
  1679. {{51186905, 16037936, 6713787, 16606682, 45496729, 2790943,
  1680. 26396185, 3731949, 345228, 28091483}},
  1681. {{45781307, 13448258, 25284571, 1143661, 20614966, 24705045,
  1682. 2031538, 21163201, 50855680, 19972348}},
  1683. },
  1684. {
  1685. {{31016192, 16832003, 26371391, 19103199, 62081514, 14854136,
  1686. 17477601, 3842657, 28012650, 17149012}},
  1687. {{62033029, 9368965, 58546785, 28953529, 51858910, 6970559,
  1688. 57918991, 16292056, 58241707, 3507939}},
  1689. {{29439664, 3537914, 23333589, 6997794, 49553303, 22536363,
  1690. 51899661, 18503164, 57943934, 6580395}},
  1691. },
  1692. },
  1693. {
  1694. {
  1695. {{54923003, 25874643, 16438268, 10826160, 58412047, 27318820,
  1696. 17860443, 24280586, 65013061, 9304566}},
  1697. {{20714545, 29217521, 29088194, 7406487, 11426967, 28458727,
  1698. 14792666, 18945815, 5289420, 33077305}},
  1699. {{50443312, 22903641, 60948518, 20248671, 9192019, 31751970,
  1700. 17271489, 12349094, 26939669, 29802138}},
  1701. },
  1702. {
  1703. {{54218966, 9373457, 31595848, 16374215, 21471720, 13221525,
  1704. 39825369, 21205872, 63410057, 117886}},
  1705. {{22263325, 26994382, 3984569, 22379786, 51994855, 32987646,
  1706. 28311252, 5358056, 43789084, 541963}},
  1707. {{16259200, 3261970, 2309254, 18019958, 50223152, 28972515,
  1708. 24134069, 16848603, 53771797, 20002236}},
  1709. },
  1710. {
  1711. {{9378160, 20414246, 44262881, 20809167, 28198280, 26310334,
  1712. 64709179, 32837080, 690425, 14876244}},
  1713. {{24977353, 33240048, 58884894, 20089345, 28432342, 32378079,
  1714. 54040059, 21257083, 44727879, 6618998}},
  1715. {{65570671, 11685645, 12944378, 13682314, 42719353, 19141238,
  1716. 8044828, 19737104, 32239828, 27901670}},
  1717. },
  1718. {
  1719. {{48505798, 4762989, 66182614, 8885303, 38696384, 30367116, 9781646,
  1720. 23204373, 32779358, 5095274}},
  1721. {{34100715, 28339925, 34843976, 29869215, 9460460, 24227009,
  1722. 42507207, 14506723, 21639561, 30924196}},
  1723. {{50707921, 20442216, 25239337, 15531969, 3987758, 29055114,
  1724. 65819361, 26690896, 17874573, 558605}},
  1725. },
  1726. {
  1727. {{53508735, 10240080, 9171883, 16131053, 46239610, 9599699,
  1728. 33499487, 5080151, 2085892, 5119761}},
  1729. {{44903700, 31034903, 50727262, 414690, 42089314, 2170429,
  1730. 30634760, 25190818, 35108870, 27794547}},
  1731. {{60263160, 15791201, 8550074, 32241778, 29928808, 21462176,
  1732. 27534429, 26362287, 44757485, 12961481}},
  1733. },
  1734. {
  1735. {{42616785, 23983660, 10368193, 11582341, 43711571, 31309144,
  1736. 16533929, 8206996, 36914212, 28394793}},
  1737. {{55987368, 30172197, 2307365, 6362031, 66973409, 8868176, 50273234,
  1738. 7031274, 7589640, 8945490}},
  1739. {{34956097, 8917966, 6661220, 21876816, 65916803, 17761038,
  1740. 7251488, 22372252, 24099108, 19098262}},
  1741. },
  1742. {
  1743. {{5019539, 25646962, 4244126, 18840076, 40175591, 6453164,
  1744. 47990682, 20265406, 60876967, 23273695}},
  1745. {{10853575, 10721687, 26480089, 5861829, 44113045, 1972174,
  1746. 65242217, 22996533, 63745412, 27113307}},
  1747. {{50106456, 5906789, 221599, 26991285, 7828207, 20305514, 24362660,
  1748. 31546264, 53242455, 7421391}},
  1749. },
  1750. {
  1751. {{8139908, 27007935, 32257645, 27663886, 30375718, 1886181,
  1752. 45933756, 15441251, 28826358, 29431403}},
  1753. {{6267067, 9695052, 7709135, 16950835, 34239795, 31668296,
  1754. 14795159, 25714308, 13746020, 31812384}},
  1755. {{28584883, 7787108, 60375922, 18503702, 22846040, 25983196,
  1756. 63926927, 33190907, 4771361, 25134474}},
  1757. },
  1758. },
  1759. {
  1760. {
  1761. {{24949256, 6376279, 39642383, 25379823, 48462709, 23623825,
  1762. 33543568, 21412737, 3569626, 11342593}},
  1763. {{26514970, 4740088, 27912651, 3697550, 19331575, 22082093, 6809885,
  1764. 4608608, 7325975, 18753361}},
  1765. {{55490446, 19000001, 42787651, 7655127, 65739590, 5214311,
  1766. 39708324, 10258389, 49462170, 25367739}},
  1767. },
  1768. {
  1769. {{11431185, 15823007, 26570245, 14329124, 18029990, 4796082,
  1770. 35662685, 15580663, 9280358, 29580745}},
  1771. {{66948081, 23228174, 44253547, 29249434, 46247496, 19933429,
  1772. 34297962, 22372809, 51563772, 4387440}},
  1773. {{46309467, 12194511, 3937617, 27748540, 39954043, 9340369,
  1774. 42594872, 8548136, 20617071, 26072431}},
  1775. },
  1776. {
  1777. {{66170039, 29623845, 58394552, 16124717, 24603125, 27329039,
  1778. 53333511, 21678609, 24345682, 10325460}},
  1779. {{47253587, 31985546, 44906155, 8714033, 14007766, 6928528,
  1780. 16318175, 32543743, 4766742, 3552007}},
  1781. {{45357481, 16823515, 1351762, 32751011, 63099193, 3950934, 3217514,
  1782. 14481909, 10988822, 29559670}},
  1783. },
  1784. {
  1785. {{15564307, 19242862, 3101242, 5684148, 30446780, 25503076,
  1786. 12677126, 27049089, 58813011, 13296004}},
  1787. {{57666574, 6624295, 36809900, 21640754, 62437882, 31497052,
  1788. 31521203, 9614054, 37108040, 12074673}},
  1789. {{4771172, 33419193, 14290748, 20464580, 27992297, 14998318,
  1790. 65694928, 31997715, 29832612, 17163397}},
  1791. },
  1792. {
  1793. {{7064884, 26013258, 47946901, 28486894, 48217594, 30641695,
  1794. 25825241, 5293297, 39986204, 13101589}},
  1795. {{64810282, 2439669, 59642254, 1719964, 39841323, 17225986,
  1796. 32512468, 28236839, 36752793, 29363474}},
  1797. {{37102324, 10162315, 33928688, 3981722, 50626726, 20484387,
  1798. 14413973, 9515896, 19568978, 9628812}},
  1799. },
  1800. {
  1801. {{33053803, 199357, 15894591, 1583059, 27380243, 28973997, 49269969,
  1802. 27447592, 60817077, 3437739}},
  1803. {{48129987, 3884492, 19469877, 12726490, 15913552, 13614290,
  1804. 44147131, 70103, 7463304, 4176122}},
  1805. {{39984863, 10659916, 11482427, 17484051, 12771466, 26919315,
  1806. 34389459, 28231680, 24216881, 5944158}},
  1807. },
  1808. {
  1809. {{8894125, 7450974, 64444715, 23788679, 39028346, 21165316,
  1810. 19345745, 14680796, 11632993, 5847885}},
  1811. {{26942781, 31239115, 9129563, 28647825, 26024104, 11769399,
  1812. 55590027, 6367193, 57381634, 4782139}},
  1813. {{19916442, 28726022, 44198159, 22140040, 25606323, 27581991,
  1814. 33253852, 8220911, 6358847, 31680575}},
  1815. },
  1816. {
  1817. {{801428, 31472730, 16569427, 11065167, 29875704, 96627, 7908388,
  1818. 29073952, 53570360, 1387154}},
  1819. {{19646058, 5720633, 55692158, 12814208, 11607948, 12749789,
  1820. 14147075, 15156355, 45242033, 11835259}},
  1821. {{19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523,
  1822. 15467869, 40548314, 5052482}},
  1823. },
  1824. },
  1825. {
  1826. {
  1827. {{64091413, 10058205, 1980837, 3964243, 22160966, 12322533, 60677741,
  1828. 20936246, 12228556, 26550755}},
  1829. {{32944382, 14922211, 44263970, 5188527, 21913450, 24834489,
  1830. 4001464, 13238564, 60994061, 8653814}},
  1831. {{22865569, 28901697, 27603667, 21009037, 14348957, 8234005,
  1832. 24808405, 5719875, 28483275, 2841751}},
  1833. },
  1834. {
  1835. {{50687877, 32441126, 66781144, 21446575, 21886281, 18001658,
  1836. 65220897, 33238773, 19932057, 20815229}},
  1837. {{55452759, 10087520, 58243976, 28018288, 47830290, 30498519,
  1838. 3999227, 13239134, 62331395, 19644223}},
  1839. {{1382174, 21859713, 17266789, 9194690, 53784508, 9720080,
  1840. 20403944, 11284705, 53095046, 3093229}},
  1841. },
  1842. {
  1843. {{16650902, 22516500, 66044685, 1570628, 58779118, 7352752, 66806440,
  1844. 16271224, 43059443, 26862581}},
  1845. {{45197768, 27626490, 62497547, 27994275, 35364760, 22769138,
  1846. 24123613, 15193618, 45456747, 16815042}},
  1847. {{57172930, 29264984, 41829040, 4372841, 2087473, 10399484,
  1848. 31870908, 14690798, 17361620, 11864968}},
  1849. },
  1850. {
  1851. {{55801235, 6210371, 13206574, 5806320, 38091172, 19587231,
  1852. 54777658, 26067830, 41530403, 17313742}},
  1853. {{14668443, 21284197, 26039038, 15305210, 25515617, 4542480,
  1854. 10453892, 6577524, 9145645, 27110552}},
  1855. {{5974855, 3053895, 57675815, 23169240, 35243739, 3225008,
  1856. 59136222, 3936127, 61456591, 30504127}},
  1857. },
  1858. {
  1859. {{30625386, 28825032, 41552902, 20761565, 46624288, 7695098,
  1860. 17097188, 17250936, 39109084, 1803631}},
  1861. {{63555773, 9865098, 61880298, 4272700, 61435032, 16864731,
  1862. 14911343, 12196514, 45703375, 7047411}},
  1863. {{20093258, 9920966, 55970670, 28210574, 13161586, 12044805,
  1864. 34252013, 4124600, 34765036, 23296865}},
  1865. },
  1866. {
  1867. {{46320040, 14084653, 53577151, 7842146, 19119038, 19731827,
  1868. 4752376, 24839792, 45429205, 2288037}},
  1869. {{40289628, 30270716, 29965058, 3039786, 52635099, 2540456,
  1870. 29457502, 14625692, 42289247, 12570231}},
  1871. {{66045306, 22002608, 16920317, 12494842, 1278292, 27685323,
  1872. 45948920, 30055751, 55134159, 4724942}},
  1873. },
  1874. {
  1875. {{17960970, 21778898, 62967895, 23851901, 58232301, 32143814,
  1876. 54201480, 24894499, 37532563, 1903855}},
  1877. {{23134274, 19275300, 56426866, 31942495, 20684484, 15770816,
  1878. 54119114, 3190295, 26955097, 14109738}},
  1879. {{15308788, 5320727, 36995055, 19235554, 22902007, 7767164,
  1880. 29425325, 22276870, 31960941, 11934971}},
  1881. },
  1882. {
  1883. {{39713153, 8435795, 4109644, 12222639, 42480996, 14818668,
  1884. 20638173, 4875028, 10491392, 1379718}},
  1885. {{53949449, 9197840, 3875503, 24618324, 65725151, 27674630,
  1886. 33518458, 16176658, 21432314, 12180697}},
  1887. {{55321537, 11500837, 13787581, 19721842, 44678184, 10140204,
  1888. 1465425, 12689540, 56807545, 19681548}},
  1889. },
  1890. },
  1891. {
  1892. {
  1893. {{5414091, 18168391, 46101199, 9643569, 12834970, 1186149,
  1894. 64485948, 32212200, 26128230, 6032912}},
  1895. {{40771450, 19788269, 32496024, 19900513, 17847800, 20885276,
  1896. 3604024, 8316894, 41233830, 23117073}},
  1897. {{3296484, 6223048, 24680646, 21307972, 44056843, 5903204,
  1898. 58246567, 28915267, 12376616, 3188849}},
  1899. },
  1900. {
  1901. {{29190469, 18895386, 27549112, 32370916, 3520065, 22857131,
  1902. 32049514, 26245319, 50999629, 23702124}},
  1903. {{52364359, 24245275, 735817, 32955454, 46701176, 28496527,
  1904. 25246077, 17758763, 18640740, 32593455}},
  1905. {{60180029, 17123636, 10361373, 5642961, 4910474, 12345252,
  1906. 35470478, 33060001, 10530746, 1053335}},
  1907. },
  1908. {
  1909. {{37842897, 19367626, 53570647, 21437058, 47651804, 22899047,
  1910. 35646494, 30605446, 24018830, 15026644}},
  1911. {{44516310, 30409154, 64819587, 5953842, 53668675, 9425630,
  1912. 25310643, 13003497, 64794073, 18408815}},
  1913. {{39688860, 32951110, 59064879, 31885314, 41016598, 13987818,
  1914. 39811242, 187898, 43942445, 31022696}},
  1915. },
  1916. {
  1917. {{45364466, 19743956, 1844839, 5021428, 56674465, 17642958,
  1918. 9716666, 16266922, 62038647, 726098}},
  1919. {{29370903, 27500434, 7334070, 18212173, 9385286, 2247707,
  1920. 53446902, 28714970, 30007387, 17731091}},
  1921. {{66172485, 16086690, 23751945, 33011114, 65941325, 28365395, 9137108,
  1922. 730663, 9835848, 4555336}},
  1923. },
  1924. {
  1925. {{43732429, 1410445, 44855111, 20654817, 30867634, 15826977,
  1926. 17693930, 544696, 55123566, 12422645}},
  1927. {{31117226, 21338698, 53606025, 6561946, 57231997, 20796761,
  1928. 61990178, 29457725, 29120152, 13924425}},
  1929. {{49707966, 19321222, 19675798, 30819676, 56101901, 27695611,
  1930. 57724924, 22236731, 7240930, 33317044}},
  1931. },
  1932. {
  1933. {{35747106, 22207651, 52101416, 27698213, 44655523, 21401660,
  1934. 1222335, 4389483, 3293637, 18002689}},
  1935. {{50424044, 19110186, 11038543, 11054958, 53307689, 30215898,
  1936. 42789283, 7733546, 12796905, 27218610}},
  1937. {{58349431, 22736595, 41689999, 10783768, 36493307, 23807620,
  1938. 38855524, 3647835, 3222231, 22393970}},
  1939. },
  1940. {
  1941. {{18606113, 1693100, 41660478, 18384159, 4112352, 10045021,
  1942. 23603893, 31506198, 59558087, 2484984}},
  1943. {{9255298, 30423235, 54952701, 32550175, 13098012, 24339566,
  1944. 16377219, 31451620, 47306788, 30519729}},
  1945. {{44379556, 7496159, 61366665, 11329248, 19991973, 30206930,
  1946. 35390715, 9936965, 37011176, 22935634}},
  1947. },
  1948. {
  1949. {{21878571, 28553135, 4338335, 13643897, 64071999, 13160959,
  1950. 19708896, 5415497, 59748361, 29445138}},
  1951. {{27736842, 10103576, 12500508, 8502413, 63695848, 23920873,
  1952. 10436917, 32004156, 43449720, 25422331}},
  1953. {{19492550, 21450067, 37426887, 32701801, 63900692, 12403436,
  1954. 30066266, 8367329, 13243957, 8709688}},
  1955. },
  1956. },
  1957. {
  1958. {
  1959. {{12015105, 2801261, 28198131, 10151021, 24818120, 28811299,
  1960. 55914672, 27908697, 5150967, 7274186}},
  1961. {{2831347, 21062286, 1478974, 6122054, 23825128, 20820846,
  1962. 31097298, 6083058, 31021603, 23760822}},
  1963. {{64578913, 31324785, 445612, 10720828, 53259337, 22048494,
  1964. 43601132, 16354464, 15067285, 19406725}},
  1965. },
  1966. {
  1967. {{7840923, 14037873, 33744001, 15934015, 66380651, 29911725,
  1968. 21403987, 1057586, 47729402, 21151211}},
  1969. {{915865, 17085158, 15608284, 24765302, 42751837, 6060029,
  1970. 49737545, 8410996, 59888403, 16527024}},
  1971. {{32922597, 32997445, 20336073, 17369864, 10903704, 28169945,
  1972. 16957573, 52992, 23834301, 6588044}},
  1973. },
  1974. {
  1975. {{32752011, 11232950, 3381995, 24839566, 22652987, 22810329,
  1976. 17159698, 16689107, 46794284, 32248439}},
  1977. {{62419196, 9166775, 41398568, 22707125, 11576751, 12733943,
  1978. 7924251, 30802151, 1976122, 26305405}},
  1979. {{21251203, 16309901, 64125849, 26771309, 30810596, 12967303, 156041,
  1980. 30183180, 12331344, 25317235}},
  1981. },
  1982. {
  1983. {{8651595, 29077400, 51023227, 28557437, 13002506, 2950805,
  1984. 29054427, 28447462, 10008135, 28886531}},
  1985. {{31486061, 15114593, 52847614, 12951353, 14369431, 26166587,
  1986. 16347320, 19892343, 8684154, 23021480}},
  1987. {{19443825, 11385320, 24468943, 23895364, 43189605, 2187568,
  1988. 40845657, 27467510, 31316347, 14219878}},
  1989. },
  1990. {
  1991. {{38514374, 1193784, 32245219, 11392485, 31092169, 15722801,
  1992. 27146014, 6992409, 29126555, 9207390}},
  1993. {{32382916, 1110093, 18477781, 11028262, 39697101, 26006320,
  1994. 62128346, 10843781, 59151264, 19118701}},
  1995. {{2814918, 7836403, 27519878, 25686276, 46214848, 22000742,
  1996. 45614304, 8550129, 28346258, 1994730}},
  1997. },
  1998. {
  1999. {{47530565, 8085544, 53108345, 29605809, 2785837, 17323125,
  2000. 47591912, 7174893, 22628102, 8115180}},
  2001. {{36703732, 955510, 55975026, 18476362, 34661776, 20276352,
  2002. 41457285, 3317159, 57165847, 930271}},
  2003. {{51805164, 26720662, 28856489, 1357446, 23421993, 1057177,
  2004. 24091212, 32165462, 44343487, 22903716}},
  2005. },
  2006. {
  2007. {{44357633, 28250434, 54201256, 20785565, 51297352, 25757378,
  2008. 52269845, 17000211, 65241845, 8398969}},
  2009. {{35139535, 2106402, 62372504, 1362500, 12813763, 16200670,
  2010. 22981545, 27263159, 18009407, 17781660}},
  2011. {{49887941, 24009210, 39324209, 14166834, 29815394, 7444469,
  2012. 29551787, 29827013, 19288548, 1325865}},
  2013. },
  2014. {
  2015. {{15100138, 17718680, 43184885, 32549333, 40658671, 15509407,
  2016. 12376730, 30075286, 33166106, 25511682}},
  2017. {{20909212, 13023121, 57899112, 16251777, 61330449, 25459517,
  2018. 12412150, 10018715, 2213263, 19676059}},
  2019. {{32529814, 22479743, 30361438, 16864679, 57972923, 1513225,
  2020. 22922121, 6382134, 61341936, 8371347}},
  2021. },
  2022. },
  2023. {
  2024. {
  2025. {{9923462, 11271500, 12616794, 3544722, 37110496, 31832805,
  2026. 12891686, 25361300, 40665920, 10486143}},
  2027. {{44511638, 26541766, 8587002, 25296571, 4084308, 20584370, 361725,
  2028. 2610596, 43187334, 22099236}},
  2029. {{5408392, 32417741, 62139741, 10561667, 24145918, 14240566,
  2030. 31319731, 29318891, 19985174, 30118346}},
  2031. },
  2032. {
  2033. {{53114407, 16616820, 14549246, 3341099, 32155958, 13648976,
  2034. 49531796, 8849296, 65030, 8370684}},
  2035. {{58787919, 21504805, 31204562, 5839400, 46481576, 32497154,
  2036. 47665921, 6922163, 12743482, 23753914}},
  2037. {{64747493, 12678784, 28815050, 4759974, 43215817, 4884716,
  2038. 23783145, 11038569, 18800704, 255233}},
  2039. },
  2040. {
  2041. {{61839187, 31780545, 13957885, 7990715, 23132995, 728773, 13393847,
  2042. 9066957, 19258688, 18800639}},
  2043. {{64172210, 22726896, 56676774, 14516792, 63468078, 4372540,
  2044. 35173943, 2209389, 65584811, 2055793}},
  2045. {{580882, 16705327, 5468415, 30871414, 36182444, 18858431,
  2046. 59905517, 24560042, 37087844, 7394434}},
  2047. },
  2048. {
  2049. {{23838809, 1822728, 51370421, 15242726, 8318092, 29821328,
  2050. 45436683, 30062226, 62287122, 14799920}},
  2051. {{13345610, 9759151, 3371034, 17416641, 16353038, 8577942, 31129804,
  2052. 13496856, 58052846, 7402517}},
  2053. {{2286874, 29118501, 47066405, 31546095, 53412636, 5038121,
  2054. 11006906, 17794080, 8205060, 1607563}},
  2055. },
  2056. {
  2057. {{14414067, 25552300, 3331829, 30346215, 22249150, 27960244,
  2058. 18364660, 30647474, 30019586, 24525154}},
  2059. {{39420813, 1585952, 56333811, 931068, 37988643, 22552112,
  2060. 52698034, 12029092, 9944378, 8024}},
  2061. {{4368715, 29844802, 29874199, 18531449, 46878477, 22143727,
  2062. 50994269, 32555346, 58966475, 5640029}},
  2063. },
  2064. {
  2065. {{10299591, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887,
  2066. 16859868, 15219797, 19226649}},
  2067. {{27425505, 27835351, 3055005, 10660664, 23458024, 595578, 51710259,
  2068. 32381236, 48766680, 9742716}},
  2069. {{6744077, 2427284, 26042789, 2720740, 66260958, 1118973, 32324614,
  2070. 7406442, 12420155, 1994844}},
  2071. },
  2072. {
  2073. {{14012502, 28529712, 48724410, 23975962, 40623521, 29617992,
  2074. 54075385, 22644628, 24319928, 27108099}},
  2075. {{16412671, 29047065, 10772640, 15929391, 50040076, 28895810,
  2076. 10555944, 23070383, 37006495, 28815383}},
  2077. {{22397363, 25786748, 57815702, 20761563, 17166286, 23799296,
  2078. 39775798, 6199365, 21880021, 21303672}},
  2079. },
  2080. {
  2081. {{62825557, 5368522, 35991846, 8163388, 36785801, 3209127,
  2082. 16557151, 8890729, 8840445, 4957760}},
  2083. {{51661137, 709326, 60189418, 22684253, 37330941, 6522331,
  2084. 45388683, 12130071, 52312361, 5005756}},
  2085. {{64994094, 19246303, 23019041, 15765735, 41839181, 6002751,
  2086. 10183197, 20315106, 50713577, 31378319}},
  2087. },
  2088. },
  2089. {
  2090. {
  2091. {{48083108, 1632004, 13466291, 25559332, 43468412, 16573536,
  2092. 35094956, 30497327, 22208661, 2000468}},
  2093. {{3065054, 32141671, 41510189, 33192999, 49425798, 27851016,
  2094. 58944651, 11248526, 63417650, 26140247}},
  2095. {{10379208, 27508878, 8877318, 1473647, 37817580, 21046851,
  2096. 16690914, 2553332, 63976176, 16400288}},
  2097. },
  2098. {
  2099. {{15716668, 1254266, 48636174, 7446273, 58659946, 6344163,
  2100. 45011593, 26268851, 26894936, 9132066}},
  2101. {{24158868, 12938817, 11085297, 25376834, 39045385, 29097348,
  2102. 36532400, 64451, 60291780, 30861549}},
  2103. {{13488534, 7794716, 22236231, 5989356, 25426474, 20976224, 2350709,
  2104. 30135921, 62420857, 2364225}},
  2105. },
  2106. {
  2107. {{16335033, 9132434, 25640582, 6678888, 1725628, 8517937, 55301840,
  2108. 21856974, 15445874, 25756331}},
  2109. {{29004188, 25687351, 28661401, 32914020, 54314860, 25611345,
  2110. 31863254, 29418892, 66830813, 17795152}},
  2111. {{60986784, 18687766, 38493958, 14569918, 56250865, 29962602,
  2112. 10343411, 26578142, 37280576, 22738620}},
  2113. },
  2114. {
  2115. {{27081650, 3463984, 14099042, 29036828, 1616302, 27348828, 29542635,
  2116. 15372179, 17293797, 960709}},
  2117. {{20263915, 11434237, 61343429, 11236809, 13505955, 22697330,
  2118. 50997518, 6493121, 47724353, 7639713}},
  2119. {{64278047, 18715199, 25403037, 25339236, 58791851, 17380732,
  2120. 18006286, 17510682, 29994676, 17746311}},
  2121. },
  2122. {
  2123. {{9769828, 5202651, 42951466, 19923039, 39057860, 21992807,
  2124. 42495722, 19693649, 35924288, 709463}},
  2125. {{12286395, 13076066, 45333675, 32377809, 42105665, 4057651,
  2126. 35090736, 24663557, 16102006, 13205847}},
  2127. {{13733362, 5599946, 10557076, 3195751, 61550873, 8536969, 41568694,
  2128. 8525971, 10151379, 10394400}},
  2129. },
  2130. {
  2131. {{4024660, 17416881, 22436261, 12276534, 58009849, 30868332,
  2132. 19698228, 11743039, 33806530, 8934413}},
  2133. {{51229064, 29029191, 58528116, 30620370, 14634844, 32856154,
  2134. 57659786, 3137093, 55571978, 11721157}},
  2135. {{17555920, 28540494, 8268605, 2331751, 44370049, 9761012, 9319229,
  2136. 8835153, 57903375, 32274386}},
  2137. },
  2138. {
  2139. {{66647436, 25724417, 20614117, 16688288, 59594098, 28747312,
  2140. 22300303, 505429, 6108462, 27371017}},
  2141. {{62038564, 12367916, 36445330, 3234472, 32617080, 25131790,
  2142. 29880582, 20071101, 40210373, 25686972}},
  2143. {{35133562, 5726538, 26934134, 10237677, 63935147, 32949378,
  2144. 24199303, 3795095, 7592688, 18562353}},
  2145. },
  2146. {
  2147. {{21594432, 18590204, 17466407, 29477210, 32537083, 2739898,
  2148. 6407723, 12018833, 38852812, 4298411}},
  2149. {{46458361, 21592935, 39872588, 570497, 3767144, 31836892,
  2150. 13891941, 31985238, 13717173, 10805743}},
  2151. {{52432215, 17910135, 15287173, 11927123, 24177847, 25378864,
  2152. 66312432, 14860608, 40169934, 27690595}},
  2153. },
  2154. },
  2155. {
  2156. {
  2157. {{12962541, 5311799, 57048096, 11658279, 18855286, 25600231,
  2158. 13286262, 20745728, 62727807, 9882021}},
  2159. {{18512060, 11319350, 46985740, 15090308, 18818594, 5271736,
  2160. 44380960, 3666878, 43141434, 30255002}},
  2161. {{60319844, 30408388, 16192428, 13241070, 15898607, 19348318,
  2162. 57023983, 26893321, 64705764, 5276064}},
  2163. },
  2164. {
  2165. {{30169808, 28236784, 26306205, 21803573, 27814963, 7069267,
  2166. 7152851, 3684982, 1449224, 13082861}},
  2167. {{10342807, 3098505, 2119311, 193222, 25702612, 12233820, 23697382,
  2168. 15056736, 46092426, 25352431}},
  2169. {{33958735, 3261607, 22745853, 7948688, 19370557, 18376767,
  2170. 40936887, 6482813, 56808784, 22494330}},
  2171. },
  2172. {
  2173. {{32869458, 28145887, 25609742, 15678670, 56421095, 18083360,
  2174. 26112420, 2521008, 44444576, 6904814}},
  2175. {{29506904, 4457497, 3377935, 23757988, 36598817, 12935079, 1561737,
  2176. 3841096, 38105225, 26896789}},
  2177. {{10340844, 26924055, 48452231, 31276001, 12621150, 20215377,
  2178. 30878496, 21730062, 41524312, 5181965}},
  2179. },
  2180. {
  2181. {{25940096, 20896407, 17324187, 23247058, 58437395, 15029093,
  2182. 24396252, 17103510, 64786011, 21165857}},
  2183. {{45343161, 9916822, 65808455, 4079497, 66080518, 11909558, 1782390,
  2184. 12641087, 20603771, 26992690}},
  2185. {{48226577, 21881051, 24849421, 11501709, 13161720, 28785558,
  2186. 1925522, 11914390, 4662781, 7820689}},
  2187. },
  2188. {
  2189. {{12241050, 33128450, 8132690, 9393934, 32846760, 31954812, 29749455,
  2190. 12172924, 16136752, 15264020}},
  2191. {{56758909, 18873868, 58896884, 2330219, 49446315, 19008651,
  2192. 10658212, 6671822, 19012087, 3772772}},
  2193. {{3753511, 30133366, 10617073, 2028709, 14841030, 26832768, 28718731,
  2194. 17791548, 20527770, 12988982}},
  2195. },
  2196. {
  2197. {{52286360, 27757162, 63400876, 12689772, 66209881, 22639565,
  2198. 42925817, 22989488, 3299664, 21129479}},
  2199. {{50331161, 18301130, 57466446, 4978982, 3308785, 8755439, 6943197,
  2200. 6461331, 41525717, 8991217}},
  2201. {{49882601, 1816361, 65435576, 27467992, 31783887, 25378441,
  2202. 34160718, 7417949, 36866577, 1507264}},
  2203. },
  2204. {
  2205. {{29692644, 6829891, 56610064, 4334895, 20945975, 21647936,
  2206. 38221255, 8209390, 14606362, 22907359}},
  2207. {{63627275, 8707080, 32188102, 5672294, 22096700, 1711240, 34088169,
  2208. 9761486, 4170404, 31469107}},
  2209. {{55521375, 14855944, 62981086, 32022574, 40459774, 15084045,
  2210. 22186522, 16002000, 52832027, 25153633}},
  2211. },
  2212. {
  2213. {{62297408, 13761028, 35404987, 31070512, 63796392, 7869046,
  2214. 59995292, 23934339, 13240844, 10965870}},
  2215. {{59366301, 25297669, 52340529, 19898171, 43876480, 12387165,
  2216. 4498947, 14147411, 29514390, 4302863}},
  2217. {{53695440, 21146572, 20757301, 19752600, 14785142, 8976368,
  2218. 62047588, 31410058, 17846987, 19582505}},
  2219. },
  2220. },
  2221. {
  2222. {
  2223. {{64864412, 32799703, 62511833, 32488122, 60861691, 1455298,
  2224. 45461136, 24339642, 61886162, 12650266}},
  2225. {{57202067, 17484121, 21134159, 12198166, 40044289, 708125, 387813,
  2226. 13770293, 47974538, 10958662}},
  2227. {{22470984, 12369526, 23446014, 28113323, 45588061, 23855708,
  2228. 55336367, 21979976, 42025033, 4271861}},
  2229. },
  2230. {
  2231. {{41939299, 23500789, 47199531, 15361594, 61124506, 2159191,
  2232. 75375, 29275903, 34582642, 8469672}},
  2233. {{15854951, 4148314, 58214974, 7259001, 11666551, 13824734,
  2234. 36577666, 2697371, 24154791, 24093489}},
  2235. {{15446137, 17747788, 29759746, 14019369, 30811221, 23944241,
  2236. 35526855, 12840103, 24913809, 9815020}},
  2237. },
  2238. {
  2239. {{62399578, 27940162, 35267365, 21265538, 52665326, 10799413,
  2240. 58005188, 13438768, 18735128, 9466238}},
  2241. {{11933045, 9281483, 5081055, 28370608, 64480701, 28648802, 59381042,
  2242. 22658328, 44380208, 16199063}},
  2243. {{14576810, 379472, 40322331, 25237195, 37682355, 22741457,
  2244. 67006097, 1876698, 30801119, 2164795}},
  2245. },
  2246. {
  2247. {{15995086, 3199873, 13672555, 13712240, 47730029, 28906785,
  2248. 54027253, 18058162, 53616056, 1268051}},
  2249. {{56818250, 29895392, 63822271, 10948817, 23037027, 3794475,
  2250. 63638526, 20954210, 50053494, 3565903}},
  2251. {{29210069, 24135095, 61189071, 28601646, 10834810, 20226706,
  2252. 50596761, 22733718, 39946641, 19523900}},
  2253. },
  2254. {
  2255. {{53946955, 15508587, 16663704, 25398282, 38758921, 9019122,
  2256. 37925443, 29785008, 2244110, 19552453}},
  2257. {{61955989, 29753495, 57802388, 27482848, 16243068, 14684434,
  2258. 41435776, 17373631, 13491505, 4641841}},
  2259. {{10813398, 643330, 47920349, 32825515, 30292061, 16954354,
  2260. 27548446, 25833190, 14476988, 20787001}},
  2261. },
  2262. {
  2263. {{10292079, 9984945, 6481436, 8279905, 59857350, 7032742, 27282937,
  2264. 31910173, 39196053, 12651323}},
  2265. {{35923332, 32741048, 22271203, 11835308, 10201545, 15351028,
  2266. 17099662, 3988035, 21721536, 30405492}},
  2267. {{10202177, 27008593, 35735631, 23979793, 34958221, 25434748,
  2268. 54202543, 3852693, 13216206, 14842320}},
  2269. },
  2270. {
  2271. {{51293224, 22953365, 60569911, 26295436, 60124204, 26972653,
  2272. 35608016, 13765823, 39674467, 9900183}},
  2273. {{14465486, 19721101, 34974879, 18815558, 39665676, 12990491,
  2274. 33046193, 15796406, 60056998, 25514317}},
  2275. {{30924398, 25274812, 6359015, 20738097, 16508376, 9071735,
  2276. 41620263, 15413634, 9524356, 26535554}},
  2277. },
  2278. {
  2279. {{12274201, 20378885, 32627640, 31769106, 6736624, 13267305,
  2280. 5237659, 28444949, 15663515, 4035784}},
  2281. {{64157555, 8903984, 17349946, 601635, 50676049, 28941875,
  2282. 53376124, 17665097, 44850385, 4659090}},
  2283. {{50192582, 28601458, 36715152, 18395610, 20774811, 15897498,
  2284. 5736189, 15026997, 64930608, 20098846}},
  2285. },
  2286. },
  2287. {
  2288. {
  2289. {{58249865, 31335375, 28571665, 23398914, 66634396, 23448733,
  2290. 63307367, 278094, 23440562, 33264224}},
  2291. {{10226222, 27625730, 15139955, 120818, 52241171, 5218602, 32937275,
  2292. 11551483, 50536904, 26111567}},
  2293. {{17932739, 21117156, 43069306, 10749059, 11316803, 7535897,
  2294. 22503767, 5561594, 63462240, 3898660}},
  2295. },
  2296. {
  2297. {{7749907, 32584865, 50769132, 33537967, 42090752, 15122142, 65535333,
  2298. 7152529, 21831162, 1245233}},
  2299. {{26958440, 18896406, 4314585, 8346991, 61431100, 11960071,
  2300. 34519569, 32934396, 36706772, 16838219}},
  2301. {{54942968, 9166946, 33491384, 13673479, 29787085, 13096535,
  2302. 6280834, 14587357, 44770839, 13987524}},
  2303. },
  2304. {
  2305. {{42758936, 7778774, 21116000, 15572597, 62275598, 28196653,
  2306. 62807965, 28429792, 59639082, 30696363}},
  2307. {{9681908, 26817309, 35157219, 13591837, 60225043, 386949, 31622781,
  2308. 6439245, 52527852, 4091396}},
  2309. {{58682418, 1470726, 38999185, 31957441, 3978626, 28430809,
  2310. 47486180, 12092162, 29077877, 18812444}},
  2311. },
  2312. {
  2313. {{5269168, 26694706, 53878652, 25533716, 25932562, 1763552,
  2314. 61502754, 28048550, 47091016, 2357888}},
  2315. {{32264008, 18146780, 61721128, 32394338, 65017541, 29607531,
  2316. 23104803, 20684524, 5727337, 189038}},
  2317. {{14609104, 24599962, 61108297, 16931650, 52531476, 25810533,
  2318. 40363694, 10942114, 41219933, 18669734}},
  2319. },
  2320. {
  2321. {{20513481, 5557931, 51504251, 7829530, 26413943, 31535028,
  2322. 45729895, 7471780, 13913677, 28416557}},
  2323. {{41534488, 11967825, 29233242, 12948236, 60354399, 4713226,
  2324. 58167894, 14059179, 12878652, 8511905}},
  2325. {{41452044, 3393630, 64153449, 26478905, 64858154, 9366907,
  2326. 36885446, 6812973, 5568676, 30426776}},
  2327. },
  2328. {
  2329. {{11630004, 12144454, 2116339, 13606037, 27378885, 15676917,
  2330. 49700111, 20050058, 52713667, 8070817}},
  2331. {{27117677, 23547054, 35826092, 27984343, 1127281, 12772488,
  2332. 37262958, 10483305, 55556115, 32525717}},
  2333. {{10637467, 27866368, 5674780, 1072708, 40765276, 26572129,
  2334. 65424888, 9177852, 39615702, 15431202}},
  2335. },
  2336. {
  2337. {{20525126, 10892566, 54366392, 12779442, 37615830, 16150074,
  2338. 38868345, 14943141, 52052074, 25618500}},
  2339. {{37084402, 5626925, 66557297, 23573344, 753597, 11981191, 25244767,
  2340. 30314666, 63752313, 9594023}},
  2341. {{43356201, 2636869, 61944954, 23450613, 585133, 7877383, 11345683,
  2342. 27062142, 13352334, 22577348}},
  2343. },
  2344. {
  2345. {{65177046, 28146973, 3304648, 20669563, 17015805, 28677341,
  2346. 37325013, 25801949, 53893326, 33235227}},
  2347. {{20239939, 6607058, 6203985, 3483793, 48721888, 32775202, 46385121,
  2348. 15077869, 44358105, 14523816}},
  2349. {{27406023, 27512775, 27423595, 29057038, 4996213, 10002360,
  2350. 38266833, 29008937, 36936121, 28748764}},
  2351. },
  2352. },
  2353. {
  2354. {
  2355. {{11374242, 12660715, 17861383, 21013599, 10935567, 1099227,
  2356. 53222788, 24462691, 39381819, 11358503}},
  2357. {{54378055, 10311866, 1510375, 10778093, 64989409, 24408729,
  2358. 32676002, 11149336, 40985213, 4985767}},
  2359. {{48012542, 341146, 60911379, 33315398, 15756972, 24757770, 66125820,
  2360. 13794113, 47694557, 17933176}},
  2361. },
  2362. {
  2363. {{6490062, 11940286, 25495923, 25828072, 8668372, 24803116, 3367602,
  2364. 6970005, 65417799, 24549641}},
  2365. {{1656478, 13457317, 15370807, 6364910, 13605745, 8362338, 47934242,
  2366. 28078708, 50312267, 28522993}},
  2367. {{44835530, 20030007, 67044178, 29220208, 48503227, 22632463,
  2368. 46537798, 26546453, 67009010, 23317098}},
  2369. },
  2370. {
  2371. {{17747446, 10039260, 19368299, 29503841, 46478228, 17513145,
  2372. 31992682, 17696456, 37848500, 28042460}},
  2373. {{31932008, 28568291, 47496481, 16366579, 22023614, 88450, 11371999,
  2374. 29810185, 4882241, 22927527}},
  2375. {{29796488, 37186, 19818052, 10115756, 55279832, 3352735, 18551198,
  2376. 3272828, 61917932, 29392022}},
  2377. },
  2378. {
  2379. {{12501267, 4044383, 58495907, 20162046, 34678811, 5136598,
  2380. 47878486, 30024734, 330069, 29895023}},
  2381. {{6384877, 2899513, 17807477, 7663917, 64749976, 12363164, 25366522,
  2382. 24980540, 66837568, 12071498}},
  2383. {{58743349, 29511910, 25133447, 29037077, 60897836, 2265926,
  2384. 34339246, 1936674, 61949167, 3829362}},
  2385. },
  2386. {
  2387. {{28425966, 27718999, 66531773, 28857233, 52891308, 6870929, 7921550,
  2388. 26986645, 26333139, 14267664}},
  2389. {{56041645, 11871230, 27385719, 22994888, 62522949, 22365119,
  2390. 10004785, 24844944, 45347639, 8930323}},
  2391. {{45911060, 17158396, 25654215, 31829035, 12282011, 11008919,
  2392. 1541940, 4757911, 40617363, 17145491}},
  2393. },
  2394. {
  2395. {{13537262, 25794942, 46504023, 10961926, 61186044, 20336366,
  2396. 53952279, 6217253, 51165165, 13814989}},
  2397. {{49686272, 15157789, 18705543, 29619, 24409717, 33293956, 27361680,
  2398. 9257833, 65152338, 31777517}},
  2399. {{42063564, 23362465, 15366584, 15166509, 54003778, 8423555,
  2400. 37937324, 12361134, 48422886, 4578289}},
  2401. },
  2402. {
  2403. {{24579768, 3711570, 1342322, 22374306, 40103728, 14124955,
  2404. 44564335, 14074918, 21964432, 8235257}},
  2405. {{60580251, 31142934, 9442965, 27628844, 12025639, 32067012,
  2406. 64127349, 31885225, 13006805, 2355433}},
  2407. {{50803946, 19949172, 60476436, 28412082, 16974358, 22643349,
  2408. 27202043, 1719366, 1141648, 20758196}},
  2409. },
  2410. {
  2411. {{54244920, 20334445, 58790597, 22536340, 60298718, 28710537,
  2412. 13475065, 30420460, 32674894, 13715045}},
  2413. {{11423316, 28086373, 32344215, 8962751, 24989809, 9241752,
  2414. 53843611, 16086211, 38367983, 17912338}},
  2415. {{65699196, 12530727, 60740138, 10847386, 19531186, 19422272,
  2416. 55399715, 7791793, 39862921, 4383346}},
  2417. },
  2418. },
  2419. {
  2420. {
  2421. {{38137966, 5271446, 65842855, 23817442, 54653627, 16732598,
  2422. 62246457, 28647982, 27193556, 6245191}},
  2423. {{51914908, 5362277, 65324971, 2695833, 4960227, 12840725, 23061898,
  2424. 3260492, 22510453, 8577507}},
  2425. {{54476394, 11257345, 34415870, 13548176, 66387860, 10879010,
  2426. 31168030, 13952092, 37537372, 29918525}},
  2427. },
  2428. {
  2429. {{3877321, 23981693, 32416691, 5405324, 56104457, 19897796,
  2430. 3759768, 11935320, 5611860, 8164018}},
  2431. {{50833043, 14667796, 15906460, 12155291, 44997715, 24514713,
  2432. 32003001, 24722143, 5773084, 25132323}},
  2433. {{43320746, 25300131, 1950874, 8937633, 18686727, 16459170, 66203139,
  2434. 12376319, 31632953, 190926}},
  2435. },
  2436. {
  2437. {{42515238, 17415546, 58684872, 13378745, 14162407, 6901328,
  2438. 58820115, 4508563, 41767309, 29926903}},
  2439. {{8884438, 27670423, 6023973, 10104341, 60227295, 28612898, 18722940,
  2440. 18768427, 65436375, 827624}},
  2441. {{34388281, 17265135, 34605316, 7101209, 13354605, 2659080,
  2442. 65308289, 19446395, 42230385, 1541285}},
  2443. },
  2444. {
  2445. {{2901328, 32436745, 3880375, 23495044, 49487923, 29941650,
  2446. 45306746, 29986950, 20456844, 31669399}},
  2447. {{27019610, 12299467, 53450576, 31951197, 54247203, 28692960,
  2448. 47568713, 28538373, 29439640, 15138866}},
  2449. {{21536104, 26928012, 34661045, 22864223, 44700786, 5175813,
  2450. 61688824, 17193268, 7779327, 109896}},
  2451. },
  2452. {
  2453. {{30279725, 14648750, 59063993, 6425557, 13639621, 32810923, 28698389,
  2454. 12180118, 23177719, 33000357}},
  2455. {{26572828, 3405927, 35407164, 12890904, 47843196, 5335865,
  2456. 60615096, 2378491, 4439158, 20275085}},
  2457. {{44392139, 3489069, 57883598, 33221678, 18875721, 32414337,
  2458. 14819433, 20822905, 49391106, 28092994}},
  2459. },
  2460. {
  2461. {{62052362, 16566550, 15953661, 3767752, 56672365, 15627059,
  2462. 66287910, 2177224, 8550082, 18440267}},
  2463. {{48635543, 16596774, 66727204, 15663610, 22860960, 15585581,
  2464. 39264755, 29971692, 43848403, 25125843}},
  2465. {{34628313, 15707274, 58902952, 27902350, 29464557, 2713815,
  2466. 44383727, 15860481, 45206294, 1494192}},
  2467. },
  2468. {
  2469. {{47546773, 19467038, 41524991, 24254879, 13127841, 759709,
  2470. 21923482, 16529112, 8742704, 12967017}},
  2471. {{38643965, 1553204, 32536856, 23080703, 42417258, 33148257,
  2472. 58194238, 30620535, 37205105, 15553882}},
  2473. {{21877890, 3230008, 9881174, 10539357, 62311749, 2841331, 11543572,
  2474. 14513274, 19375923, 20906471}},
  2475. },
  2476. {
  2477. {{8832269, 19058947, 13253510, 5137575, 5037871, 4078777, 24880818,
  2478. 27331716, 2862652, 9455043}},
  2479. {{29306751, 5123106, 20245049, 19404543, 9592565, 8447059, 65031740,
  2480. 30564351, 15511448, 4789663}},
  2481. {{46429108, 7004546, 8824831, 24119455, 63063159, 29803695,
  2482. 61354101, 108892, 23513200, 16652362}},
  2483. },
  2484. },
  2485. {
  2486. {
  2487. {{33852691, 4144781, 62632835, 26975308, 10770038, 26398890,
  2488. 60458447, 20618131, 48789665, 10212859}},
  2489. {{2756062, 8598110, 7383731, 26694540, 22312758, 32449420, 21179800,
  2490. 2600940, 57120566, 21047965}},
  2491. {{42463153, 13317461, 36659605, 17900503, 21365573, 22684775,
  2492. 11344423, 864440, 64609187, 16844368}},
  2493. },
  2494. {
  2495. {{40676061, 6148328, 49924452, 19080277, 18782928, 33278435,
  2496. 44547329, 211299, 2719757, 4940997}},
  2497. {{65784982, 3911312, 60160120, 14759764, 37081714, 7851206,
  2498. 21690126, 8518463, 26699843, 5276295}},
  2499. {{53958991, 27125364, 9396248, 365013, 24703301, 23065493, 1321585,
  2500. 149635, 51656090, 7159368}},
  2501. },
  2502. {
  2503. {{9987761, 30149673, 17507961, 9505530, 9731535, 31388918, 22356008,
  2504. 8312176, 22477218, 25151047}},
  2505. {{18155857, 17049442, 19744715, 9006923, 15154154, 23015456,
  2506. 24256459, 28689437, 44560690, 9334108}},
  2507. {{2986088, 28642539, 10776627, 30080588, 10620589, 26471229,
  2508. 45695018, 14253544, 44521715, 536905}},
  2509. },
  2510. {
  2511. {{4377737, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551,
  2512. 10589625, 10838060, 18134008}},
  2513. {{47766460, 867879, 9277171, 30335973, 52677291, 31567988,
  2514. 19295825, 17757482, 6378259, 699185}},
  2515. {{7895007, 4057113, 60027092, 20476675, 49222032, 33231305, 66392824,
  2516. 15693154, 62063800, 20180469}},
  2517. },
  2518. {
  2519. {{59371282, 27685029, 52542544, 26147512, 11385653, 13201616,
  2520. 31730678, 22591592, 63190227, 23885106}},
  2521. {{10188286, 17783598, 59772502, 13427542, 22223443, 14896287,
  2522. 30743455, 7116568, 45322357, 5427592}},
  2523. {{696102, 13206899, 27047647, 22922350, 15285304, 23701253,
  2524. 10798489, 28975712, 19236242, 12477404}},
  2525. },
  2526. {
  2527. {{55879425, 11243795, 50054594, 25513566, 66320635, 25386464,
  2528. 63211194, 11180503, 43939348, 7733643}},
  2529. {{17800790, 19518253, 40108434, 21787760, 23887826, 3149671,
  2530. 23466177, 23016261, 10322026, 15313801}},
  2531. {{26246234, 11968874, 32263343, 28085704, 6830754, 20231401,
  2532. 51314159, 33452449, 42659621, 10890803}},
  2533. },
  2534. {
  2535. {{35743198, 10271362, 54448239, 27287163, 16690206, 20491888,
  2536. 52126651, 16484930, 25180797, 28219548}},
  2537. {{66522290, 10376443, 34522450, 22268075, 19801892, 10997610,
  2538. 2276632, 9482883, 316878, 13820577}},
  2539. {{57226037, 29044064, 64993357, 16457135, 56008783, 11674995,
  2540. 30756178, 26039378, 30696929, 29841583}},
  2541. },
  2542. {
  2543. {{32988917, 23951020, 12499365, 7910787, 56491607, 21622917,
  2544. 59766047, 23569034, 34759346, 7392472}},
  2545. {{58253184, 15927860, 9866406, 29905021, 64711949, 16898650,
  2546. 36699387, 24419436, 25112946, 30627788}},
  2547. {{64604801, 33117465, 25621773, 27875660, 15085041, 28074555,
  2548. 42223985, 20028237, 5537437, 19640113}},
  2549. },
  2550. },
  2551. {
  2552. {
  2553. {{55883280, 2320284, 57524584, 10149186, 33664201, 5808647,
  2554. 52232613, 31824764, 31234589, 6090599}},
  2555. {{57475529, 116425, 26083934, 2897444, 60744427, 30866345, 609720,
  2556. 15878753, 60138459, 24519663}},
  2557. {{39351007, 247743, 51914090, 24551880, 23288160, 23542496,
  2558. 43239268, 6503645, 20650474, 1804084}},
  2559. },
  2560. {
  2561. {{39519059, 15456423, 8972517, 8469608, 15640622, 4439847, 3121995,
  2562. 23224719, 27842615, 33352104}},
  2563. {{51801891, 2839643, 22530074, 10026331, 4602058, 5048462, 28248656,
  2564. 5031932, 55733782, 12714368}},
  2565. {{20807691, 26283607, 29286140, 11421711, 39232341, 19686201,
  2566. 45881388, 1035545, 47375635, 12796919}},
  2567. },
  2568. {
  2569. {{12076880, 19253146, 58323862, 21705509, 42096072, 16400683,
  2570. 49517369, 20654993, 3480664, 18371617}},
  2571. {{34747315, 5457596, 28548107, 7833186, 7303070, 21600887,
  2572. 42745799, 17632556, 33734809, 2771024}},
  2573. {{45719598, 421931, 26597266, 6860826, 22486084, 26817260,
  2574. 49971378, 29344205, 42556581, 15673396}},
  2575. },
  2576. {
  2577. {{46924223, 2338215, 19788685, 23933476, 63107598, 24813538,
  2578. 46837679, 4733253, 3727144, 20619984}},
  2579. {{6120100, 814863, 55314462, 32931715, 6812204, 17806661, 2019593,
  2580. 7975683, 31123697, 22595451}},
  2581. {{30069250, 22119100, 30434653, 2958439, 18399564, 32578143,
  2582. 12296868, 9204260, 50676426, 9648164}},
  2583. },
  2584. {
  2585. {{32705413, 32003455, 30705657, 7451065, 55303258, 9631812, 3305266,
  2586. 5248604, 41100532, 22176930}},
  2587. {{17219846, 2375039, 35537917, 27978816, 47649184, 9219902, 294711,
  2588. 15298639, 2662509, 17257359}},
  2589. {{65935918, 25995736, 62742093, 29266687, 45762450, 25120105,
  2590. 32087528, 32331655, 32247247, 19164571}},
  2591. },
  2592. {
  2593. {{14312609, 1221556, 17395390, 24854289, 62163122, 24869796,
  2594. 38911119, 23916614, 51081240, 20175586}},
  2595. {{65680039, 23875441, 57873182, 6549686, 59725795, 33085767, 23046501,
  2596. 9803137, 17597934, 2346211}},
  2597. {{18510781, 15337574, 26171504, 981392, 44867312, 7827555,
  2598. 43617730, 22231079, 3059832, 21771562}},
  2599. },
  2600. {
  2601. {{10141598, 6082907, 17829293, 31606789, 9830091, 13613136,
  2602. 41552228, 28009845, 33606651, 3592095}},
  2603. {{33114149, 17665080, 40583177, 20211034, 33076704, 8716171,
  2604. 1151462, 1521897, 66126199, 26716628}},
  2605. {{34169699, 29298616, 23947180, 33230254, 34035889, 21248794,
  2606. 50471177, 3891703, 26353178, 693168}},
  2607. },
  2608. {
  2609. {{30374239, 1595580, 50224825, 13186930, 4600344, 406904, 9585294,
  2610. 33153764, 31375463, 14369965}},
  2611. {{52738210, 25781902, 1510300, 6434173, 48324075, 27291703,
  2612. 32732229, 20445593, 17901440, 16011505}},
  2613. {{18171223, 21619806, 54608461, 15197121, 56070717, 18324396,
  2614. 47936623, 17508055, 8764034, 12309598}},
  2615. },
  2616. },
  2617. {
  2618. {
  2619. {{5975889, 28311244, 47649501, 23872684, 55567586, 14015781,
  2620. 43443107, 1228318, 17544096, 22960650}},
  2621. {{5811932, 31839139, 3442886, 31285122, 48741515, 25194890,
  2622. 49064820, 18144304, 61543482, 12348899}},
  2623. {{35709185, 11407554, 25755363, 6891399, 63851926, 14872273,
  2624. 42259511, 8141294, 56476330, 32968952}},
  2625. },
  2626. {
  2627. {{54433560, 694025, 62032719, 13300343, 14015258, 19103038,
  2628. 57410191, 22225381, 30944592, 1130208}},
  2629. {{8247747, 26843490, 40546482, 25845122, 52706924, 18905521,
  2630. 4652151, 2488540, 23550156, 33283200}},
  2631. {{17294297, 29765994, 7026747, 15626851, 22990044, 113481, 2267737,
  2632. 27646286, 66700045, 33416712}},
  2633. },
  2634. {
  2635. {{16091066, 17300506, 18599251, 7340678, 2137637, 32332775,
  2636. 63744702, 14550935, 3260525, 26388161}},
  2637. {{62198760, 20221544, 18550886, 10864893, 50649539, 26262835,
  2638. 44079994, 20349526, 54360141, 2701325}},
  2639. {{58534169, 16099414, 4629974, 17213908, 46322650, 27548999,
  2640. 57090500, 9276970, 11329923, 1862132}},
  2641. },
  2642. {
  2643. {{14763057, 17650824, 36190593, 3689866, 3511892, 10313526,
  2644. 45157776, 12219230, 58070901, 32614131}},
  2645. {{8894987, 30108338, 6150752, 3013931, 301220, 15693451, 35127648,
  2646. 30644714, 51670695, 11595569}},
  2647. {{15214943, 3537601, 40870142, 19495559, 4418656, 18323671,
  2648. 13947275, 10730794, 53619402, 29190761}},
  2649. },
  2650. {
  2651. {{64570558, 7682792, 32759013, 263109, 37124133, 25598979,
  2652. 44776739, 23365796, 977107, 699994}},
  2653. {{54642373, 4195083, 57897332, 550903, 51543527, 12917919,
  2654. 19118110, 33114591, 36574330, 19216518}},
  2655. {{31788442, 19046775, 4799988, 7372237, 8808585, 18806489, 9408236,
  2656. 23502657, 12493931, 28145115}},
  2657. },
  2658. {
  2659. {{41428258, 5260743, 47873055, 27269961, 63412921, 16566086,
  2660. 27218280, 2607121, 29375955, 6024730}},
  2661. {{842132, 30759739, 62345482, 24831616, 26332017, 21148791,
  2662. 11831879, 6985184, 57168503, 2854095}},
  2663. {{62261602, 25585100, 2516241, 27706719, 9695690, 26333246, 16512644,
  2664. 960770, 12121869, 16648078}},
  2665. },
  2666. {
  2667. {{51890212, 14667095, 53772635, 2013716, 30598287, 33090295,
  2668. 35603941, 25672367, 20237805, 2838411}},
  2669. {{47820798, 4453151, 15298546, 17376044, 22115042, 17581828,
  2670. 12544293, 20083975, 1068880, 21054527}},
  2671. {{57549981, 17035596, 33238497, 13506958, 30505848, 32439836,
  2672. 58621956, 30924378, 12521377, 4845654}},
  2673. },
  2674. {
  2675. {{38910324, 10744107, 64150484, 10199663, 7759311, 20465832,
  2676. 3409347, 32681032, 60626557, 20668561}},
  2677. {{43547042, 6230155, 46726851, 10655313, 43068279, 21933259,
  2678. 10477733, 32314216, 63995636, 13974497}},
  2679. {{12966261, 15550616, 35069916, 31939085, 21025979, 32924988,
  2680. 5642324, 7188737, 18895762, 12629579}},
  2681. },
  2682. },
  2683. {
  2684. {
  2685. {{14741879, 18607545, 22177207, 21833195, 1279740, 8058600,
  2686. 11758140, 789443, 32195181, 3895677}},
  2687. {{10758205, 15755439, 62598914, 9243697, 62229442, 6879878, 64904289,
  2688. 29988312, 58126794, 4429646}},
  2689. {{64654951, 15725972, 46672522, 23143759, 61304955, 22514211,
  2690. 59972993, 21911536, 18047435, 18272689}},
  2691. },
  2692. {
  2693. {{41935844, 22247266, 29759955, 11776784, 44846481, 17733976,
  2694. 10993113, 20703595, 49488162, 24145963}},
  2695. {{21987233, 700364, 42603816, 14972007, 59334599, 27836036,
  2696. 32155025, 2581431, 37149879, 8773374}},
  2697. {{41540495, 454462, 53896929, 16126714, 25240068, 8594567,
  2698. 20656846, 12017935, 59234475, 19634276}},
  2699. },
  2700. {
  2701. {{6028163, 6263078, 36097058, 22252721, 66289944, 2461771,
  2702. 35267690, 28086389, 65387075, 30777706}},
  2703. {{54829870, 16624276, 987579, 27631834, 32908202, 1248608, 7719845,
  2704. 29387734, 28408819, 6816612}},
  2705. {{56750770, 25316602, 19549650, 21385210, 22082622, 16147817,
  2706. 20613181, 13982702, 56769294, 5067942}},
  2707. },
  2708. {
  2709. {{36602878, 29732664, 12074680, 13582412, 47230892, 2443950,
  2710. 47389578, 12746131, 5331210, 23448488}},
  2711. {{30528792, 3601899, 65151774, 4619784, 39747042, 18118043,
  2712. 24180792, 20984038, 27679907, 31905504}},
  2713. {{9402385, 19597367, 32834042, 10838634, 40528714, 20317236,
  2714. 26653273, 24868867, 22611443, 20839026}},
  2715. },
  2716. {
  2717. {{22190590, 1118029, 22736441, 15130463, 36648172, 27563110,
  2718. 19189624, 28905490, 4854858, 6622139}},
  2719. {{58798126, 30600981, 58846284, 30166382, 56707132, 33282502,
  2720. 13424425, 29987205, 26404408, 13001963}},
  2721. {{35867026, 18138731, 64114613, 8939345, 11562230, 20713762,
  2722. 41044498, 21932711, 51703708, 11020692}},
  2723. },
  2724. {
  2725. {{1866042, 25604943, 59210214, 23253421, 12483314, 13477547,
  2726. 3175636, 21130269, 28761761, 1406734}},
  2727. {{66660290, 31776765, 13018550, 3194501, 57528444, 22392694,
  2728. 24760584, 29207344, 25577410, 20175752}},
  2729. {{42818486, 4759344, 66418211, 31701615, 2066746, 10693769,
  2730. 37513074, 9884935, 57739938, 4745409}},
  2731. },
  2732. {
  2733. {{57967561, 6049713, 47577803, 29213020, 35848065, 9944275,
  2734. 51646856, 22242579, 10931923, 21622501}},
  2735. {{50547351, 14112679, 59096219, 4817317, 59068400, 22139825,
  2736. 44255434, 10856640, 46638094, 13434653}},
  2737. {{22759470, 23480998, 50342599, 31683009, 13637441, 23386341,
  2738. 1765143, 20900106, 28445306, 28189722}},
  2739. },
  2740. {
  2741. {{29875063, 12493613, 2795536, 29768102, 1710619, 15181182,
  2742. 56913147, 24765756, 9074233, 1167180}},
  2743. {{40903181, 11014232, 57266213, 30918946, 40200743, 7532293,
  2744. 48391976, 24018933, 3843902, 9367684}},
  2745. {{56139269, 27150720, 9591133, 9582310, 11349256, 108879, 16235123,
  2746. 8601684, 66969667, 4242894}},
  2747. },
  2748. },
  2749. {
  2750. {
  2751. {{22092954, 20363309, 65066070, 21585919, 32186752, 22037044,
  2752. 60534522, 2470659, 39691498, 16625500}},
  2753. {{56051142, 3042015, 13770083, 24296510, 584235, 33009577, 59338006,
  2754. 2602724, 39757248, 14247412}},
  2755. {{6314156, 23289540, 34336361, 15957556, 56951134, 168749,
  2756. 58490057, 14290060, 27108877, 32373552}},
  2757. },
  2758. {
  2759. {{58522267, 26383465, 13241781, 10960156, 34117849, 19759835,
  2760. 33547975, 22495543, 39960412, 981873}},
  2761. {{22833421, 9293594, 34459416, 19935764, 57971897, 14756818,
  2762. 44180005, 19583651, 56629059, 17356469}},
  2763. {{59340277, 3326785, 38997067, 10783823, 19178761, 14905060,
  2764. 22680049, 13906969, 51175174, 3797898}},
  2765. },
  2766. {
  2767. {{21721337, 29341686, 54902740, 9310181, 63226625, 19901321,
  2768. 23740223, 30845200, 20491982, 25512280}},
  2769. {{9209251, 18419377, 53852306, 27386633, 66377847, 15289672,
  2770. 25947805, 15286587, 30997318, 26851369}},
  2771. {{7392013, 16618386, 23946583, 25514540, 53843699, 32020573,
  2772. 52911418, 31232855, 17649997, 33304352}},
  2773. },
  2774. {
  2775. {{57807776, 19360604, 30609525, 30504889, 41933794, 32270679,
  2776. 51867297, 24028707, 64875610, 7662145}},
  2777. {{49550191, 1763593, 33994528, 15908609, 37067994, 21380136,
  2778. 7335079, 25082233, 63934189, 3440182}},
  2779. {{47219164, 27577423, 42997570, 23865561, 10799742, 16982475,
  2780. 40449, 29122597, 4862399, 1133}},
  2781. },
  2782. {
  2783. {{34252636, 25680474, 61686474, 14860949, 50789833, 7956141,
  2784. 7258061, 311861, 36513873, 26175010}},
  2785. {{63335436, 31988495, 28985339, 7499440, 24445838, 9325937, 29727763,
  2786. 16527196, 18278453, 15405622}},
  2787. {{62726958, 8508651, 47210498, 29880007, 61124410, 15149969,
  2788. 53795266, 843522, 45233802, 13626196}},
  2789. },
  2790. {
  2791. {{2281448, 20067377, 56193445, 30944521, 1879357, 16164207,
  2792. 56324982, 3953791, 13340839, 15928663}},
  2793. {{31727126, 26374577, 48671360, 25270779, 2875792, 17164102,
  2794. 41838969, 26539605, 43656557, 5964752}},
  2795. {{4100401, 27594980, 49929526, 6017713, 48403027, 12227140,
  2796. 40424029, 11344143, 2538215, 25983677}},
  2797. },
  2798. {
  2799. {{57675240, 6123112, 11159803, 31397824, 30016279, 14966241,
  2800. 46633881, 1485420, 66479608, 17595569}},
  2801. {{40304287, 4260918, 11851389, 9658551, 35091757, 16367491,
  2802. 46903439, 20363143, 11659921, 22439314}},
  2803. {{26180377, 10015009, 36264640, 24973138, 5418196, 9480663, 2231568,
  2804. 23384352, 33100371, 32248261}},
  2805. },
  2806. {
  2807. {{15121094, 28352561, 56718958, 15427820, 39598927, 17561924,
  2808. 21670946, 4486675, 61177054, 19088051}},
  2809. {{16166467, 24070699, 56004733, 6023907, 35182066, 32189508,
  2810. 2340059, 17299464, 56373093, 23514607}},
  2811. {{28042865, 29997343, 54982337, 12259705, 63391366, 26608532,
  2812. 6766452, 24864833, 18036435, 5803270}},
  2813. },
  2814. },
  2815. {
  2816. {
  2817. {{66291264, 6763911, 11803561, 1585585, 10958447, 30883267, 23855390,
  2818. 4598332, 60949433, 19436993}},
  2819. {{36077558, 19298237, 17332028, 31170912, 31312681, 27587249,
  2820. 696308, 50292, 47013125, 11763583}},
  2821. {{66514282, 31040148, 34874710, 12643979, 12650761, 14811489, 665117,
  2822. 20940800, 47335652, 22840869}},
  2823. },
  2824. {
  2825. {{30464590, 22291560, 62981387, 20819953, 19835326, 26448819,
  2826. 42712688, 2075772, 50088707, 992470}},
  2827. {{18357166, 26559999, 7766381, 16342475, 37783946, 411173, 14578841,
  2828. 8080033, 55534529, 22952821}},
  2829. {{19598397, 10334610, 12555054, 2555664, 18821899, 23214652,
  2830. 21873262, 16014234, 26224780, 16452269}},
  2831. },
  2832. {
  2833. {{36884939, 5145195, 5944548, 16385966, 3976735, 2009897, 55731060,
  2834. 25936245, 46575034, 3698649}},
  2835. {{14187449, 3448569, 56472628, 22743496, 44444983, 30120835,
  2836. 7268409, 22663988, 27394300, 12015369}},
  2837. {{19695742, 16087646, 28032085, 12999827, 6817792, 11427614,
  2838. 20244189, 32241655, 53849736, 30151970}},
  2839. },
  2840. {
  2841. {{30860084, 12735208, 65220619, 28854697, 50133957, 2256939,
  2842. 58942851, 12298311, 58558340, 23160969}},
  2843. {{61389038, 22309106, 65198214, 15569034, 26642876, 25966672,
  2844. 61319509, 18435777, 62132699, 12651792}},
  2845. {{64260450, 9953420, 11531313, 28271553, 26895122, 20857343,
  2846. 53990043, 17036529, 9768697, 31021214}},
  2847. },
  2848. {
  2849. {{42389405, 1894650, 66821166, 28850346, 15348718, 25397902,
  2850. 32767512, 12765450, 4940095, 10678226}},
  2851. {{18860224, 15980149, 48121624, 31991861, 40875851, 22482575,
  2852. 59264981, 13944023, 42736516, 16582018}},
  2853. {{51604604, 4970267, 37215820, 4175592, 46115652, 31354675,
  2854. 55404809, 15444559, 56105103, 7989036}},
  2855. },
  2856. {
  2857. {{31490433, 5568061, 64696061, 2182382, 34772017, 4531685,
  2858. 35030595, 6200205, 47422751, 18754260}},
  2859. {{49800177, 17674491, 35586086, 33551600, 34221481, 16375548,
  2860. 8680158, 17182719, 28550067, 26697300}},
  2861. {{38981977, 27866340, 16837844, 31733974, 60258182, 12700015,
  2862. 37068883, 4364037, 1155602, 5988841}},
  2863. },
  2864. {
  2865. {{21890435, 20281525, 54484852, 12154348, 59276991, 15300495,
  2866. 23148983, 29083951, 24618406, 8283181}},
  2867. {{33972757, 23041680, 9975415, 6841041, 35549071, 16356535,
  2868. 3070187, 26528504, 1466168, 10740210}},
  2869. {{65599446, 18066246, 53605478, 22898515, 32799043, 909394,
  2870. 53169961, 27774712, 34944214, 18227391}},
  2871. },
  2872. {
  2873. {{3960804, 19286629, 39082773, 17636380, 47704005, 13146867,
  2874. 15567327, 951507, 63848543, 32980496}},
  2875. {{24740822, 5052253, 37014733, 8961360, 25877428, 6165135,
  2876. 42740684, 14397371, 59728495, 27410326}},
  2877. {{38220480, 3510802, 39005586, 32395953, 55870735, 22922977,
  2878. 51667400, 19101303, 65483377, 27059617}},
  2879. },
  2880. },
  2881. {
  2882. {
  2883. {{793280, 24323954, 8836301, 27318725, 39747955, 31184838, 33152842,
  2884. 28669181, 57202663, 32932579}},
  2885. {{5666214, 525582, 20782575, 25516013, 42570364, 14657739, 16099374,
  2886. 1468826, 60937436, 18367850}},
  2887. {{62249590, 29775088, 64191105, 26806412, 7778749, 11688288,
  2888. 36704511, 23683193, 65549940, 23690785}},
  2889. },
  2890. {
  2891. {{10896313, 25834728, 824274, 472601, 47648556, 3009586, 25248958,
  2892. 14783338, 36527388, 17796587}},
  2893. {{10566929, 12612572, 35164652, 11118702, 54475488, 12362878,
  2894. 21752402, 8822496, 24003793, 14264025}},
  2895. {{27713843, 26198459, 56100623, 9227529, 27050101, 2504721,
  2896. 23886875, 20436907, 13958494, 27821979}},
  2897. },
  2898. {
  2899. {{43627235, 4867225, 39861736, 3900520, 29838369, 25342141,
  2900. 35219464, 23512650, 7340520, 18144364}},
  2901. {{4646495, 25543308, 44342840, 22021777, 23184552, 8566613,
  2902. 31366726, 32173371, 52042079, 23179239}},
  2903. {{49838347, 12723031, 50115803, 14878793, 21619651, 27356856,
  2904. 27584816, 3093888, 58265170, 3849920}},
  2905. },
  2906. {
  2907. {{58043933, 2103171, 25561640, 18428694, 61869039, 9582957,
  2908. 32477045, 24536477, 5002293, 18004173}},
  2909. {{55051311, 22376525, 21115584, 20189277, 8808711, 21523724,
  2910. 16489529, 13378448, 41263148, 12741425}},
  2911. {{61162478, 10645102, 36197278, 15390283, 63821882, 26435754,
  2912. 24306471, 15852464, 28834118, 25908360}},
  2913. },
  2914. {
  2915. {{49773116, 24447374, 42577584, 9434952, 58636780, 32971069,
  2916. 54018092, 455840, 20461858, 5491305}},
  2917. {{13669229, 17458950, 54626889, 23351392, 52539093, 21661233,
  2918. 42112877, 11293806, 38520660, 24132599}},
  2919. {{28497909, 6272777, 34085870, 14470569, 8906179, 32328802,
  2920. 18504673, 19389266, 29867744, 24758489}},
  2921. },
  2922. {
  2923. {{50901822, 13517195, 39309234, 19856633, 24009063, 27180541,
  2924. 60741263, 20379039, 22853428, 29542421}},
  2925. {{24191359, 16712145, 53177067, 15217830, 14542237, 1646131,
  2926. 18603514, 22516545, 12876622, 31441985}},
  2927. {{17902668, 4518229, 66697162, 30725184, 26878216, 5258055, 54248111,
  2928. 608396, 16031844, 3723494}},
  2929. },
  2930. {
  2931. {{38476072, 12763727, 46662418, 7577503, 33001348, 20536687,
  2932. 17558841, 25681542, 23896953, 29240187}},
  2933. {{47103464, 21542479, 31520463, 605201, 2543521, 5991821, 64163800,
  2934. 7229063, 57189218, 24727572}},
  2935. {{28816026, 298879, 38943848, 17633493, 19000927, 31888542,
  2936. 54428030, 30605106, 49057085, 31471516}},
  2937. },
  2938. {
  2939. {{16000882, 33209536, 3493091, 22107234, 37604268, 20394642,
  2940. 12577739, 16041268, 47393624, 7847706}},
  2941. {{10151868, 10572098, 27312476, 7922682, 14825339, 4723128,
  2942. 34252933, 27035413, 57088296, 3852847}},
  2943. {{55678375, 15697595, 45987307, 29133784, 5386313, 15063598,
  2944. 16514493, 17622322, 29330898, 18478208}},
  2945. },
  2946. },
  2947. {
  2948. {
  2949. {{41609129, 29175637, 51885955, 26653220, 16615730, 2051784,
  2950. 3303702, 15490, 39560068, 12314390}},
  2951. {{15683501, 27551389, 18109119, 23573784, 15337967, 27556609,
  2952. 50391428, 15921865, 16103996, 29823217}},
  2953. {{43939021, 22773182, 13588191, 31925625, 63310306, 32479502,
  2954. 47835256, 5402698, 37293151, 23713330}},
  2955. },
  2956. {
  2957. {{23190676, 2384583, 34394524, 3462153, 37205209, 32025299,
  2958. 55842007, 8911516, 41903005, 2739712}},
  2959. {{21374101, 30000182, 33584214, 9874410, 15377179, 11831242,
  2960. 33578960, 6134906, 4931255, 11987849}},
  2961. {{67101132, 30575573, 50885377, 7277596, 105524, 33232381, 35628324,
  2962. 13861387, 37032554, 10117929}},
  2963. },
  2964. {
  2965. {{37607694, 22809559, 40945095, 13051538, 41483300, 5089642,
  2966. 60783361, 6704078, 12890019, 15728940}},
  2967. {{45136504, 21783052, 66157804, 29135591, 14704839, 2695116, 903376,
  2968. 23126293, 12885166, 8311031}},
  2969. {{49592363, 5352193, 10384213, 19742774, 7506450, 13453191,
  2970. 26423267, 4384730, 1888765, 28119028}},
  2971. },
  2972. {
  2973. {{41291507, 30447119, 53614264, 30371925, 30896458, 19632703,
  2974. 34857219, 20846562, 47644429, 30214188}},
  2975. {{43500868, 30888657, 66582772, 4651135, 5765089, 4618330, 6092245,
  2976. 14845197, 17151279, 23700316}},
  2977. {{42278406, 20820711, 51942885, 10367249, 37577956, 33289075,
  2978. 22825804, 26467153, 50242379, 16176524}},
  2979. },
  2980. {
  2981. {{43525589, 6564960, 20063689, 3798228, 62368686, 7359224, 2006182,
  2982. 23191006, 38362610, 23356922}},
  2983. {{56482264, 29068029, 53788301, 28429114, 3432135, 27161203,
  2984. 23632036, 31613822, 32808309, 1099883}},
  2985. {{15030958, 5768825, 39657628, 30667132, 60681485, 18193060,
  2986. 51830967, 26745081, 2051440, 18328567}},
  2987. },
  2988. {
  2989. {{63746541, 26315059, 7517889, 9824992, 23555850, 295369, 5148398,
  2990. 19400244, 44422509, 16633659}},
  2991. {{4577067, 16802144, 13249840, 18250104, 19958762, 19017158,
  2992. 18559669, 22794883, 8402477, 23690159}},
  2993. {{38702534, 32502850, 40318708, 32646733, 49896449, 22523642,
  2994. 9453450, 18574360, 17983009, 9967138}},
  2995. },
  2996. {
  2997. {{41346370, 6524721, 26585488, 9969270, 24709298, 1220360, 65430874,
  2998. 7806336, 17507396, 3651560}},
  2999. {{56688388, 29436320, 14584638, 15971087, 51340543, 8861009,
  3000. 26556809, 27979875, 48555541, 22197296}},
  3001. {{2839082, 14284142, 4029895, 3472686, 14402957, 12689363, 40466743,
  3002. 8459446, 61503401, 25932490}},
  3003. },
  3004. {
  3005. {{62269556, 30018987, 9744960, 2871048, 25113978, 3187018, 41998051,
  3006. 32705365, 17258083, 25576693}},
  3007. {{18164541, 22959256, 49953981, 32012014, 19237077, 23809137,
  3008. 23357532, 18337424, 26908269, 12150756}},
  3009. {{36843994, 25906566, 5112248, 26517760, 65609056, 26580174, 43167,
  3010. 28016731, 34806789, 16215818}},
  3011. },
  3012. },
  3013. {
  3014. {
  3015. {{60209940, 9824393, 54804085, 29153342, 35711722, 27277596,
  3016. 32574488, 12532905, 59605792, 24879084}},
  3017. {{39765323, 17038963, 39957339, 22831480, 946345, 16291093,
  3018. 254968, 7168080, 21676107, 31611404}},
  3019. {{21260942, 25129680, 50276977, 21633609, 43430902, 3968120,
  3020. 63456915, 27338965, 63552672, 25641356}},
  3021. },
  3022. {
  3023. {{16544735, 13250366, 50304436, 15546241, 62525861, 12757257,
  3024. 64646556, 24874095, 48201831, 23891632}},
  3025. {{64693606, 17976703, 18312302, 4964443, 51836334, 20900867,
  3026. 26820650, 16690659, 25459437, 28989823}},
  3027. {{41964155, 11425019, 28423002, 22533875, 60963942, 17728207,
  3028. 9142794, 31162830, 60676445, 31909614}},
  3029. },
  3030. {
  3031. {{44004212, 6253475, 16964147, 29785560, 41994891, 21257994,
  3032. 39651638, 17209773, 6335691, 7249989}},
  3033. {{36775618, 13979674, 7503222, 21186118, 55152142, 28932738,
  3034. 36836594, 2682241, 25993170, 21075909}},
  3035. {{4364628, 5930691, 32304656, 23509878, 59054082, 15091130,
  3036. 22857016, 22955477, 31820367, 15075278}},
  3037. },
  3038. {
  3039. {{31879134, 24635739, 17258760, 90626, 59067028, 28636722, 24162787,
  3040. 23903546, 49138625, 12833044}},
  3041. {{19073683, 14851414, 42705695, 21694263, 7625277, 11091125,
  3042. 47489674, 2074448, 57694925, 14905376}},
  3043. {{24483648, 21618865, 64589997, 22007013, 65555733, 15355505,
  3044. 41826784, 9253128, 27628530, 25998952}},
  3045. },
  3046. {
  3047. {{17597607, 8340603, 19355617, 552187, 26198470, 30377849, 4593323,
  3048. 24396850, 52997988, 15297015}},
  3049. {{510886, 14337390, 35323607, 16638631, 6328095, 2713355, 46891447,
  3050. 21690211, 8683220, 2921426}},
  3051. {{18606791, 11874196, 27155355, 28272950, 43077121, 6265445,
  3052. 41930624, 32275507, 4674689, 13890525}},
  3053. },
  3054. {
  3055. {{13609624, 13069022, 39736503, 20498523, 24360585, 9592974,
  3056. 14977157, 9835105, 4389687, 288396}},
  3057. {{9922506, 33035038, 13613106, 5883594, 48350519, 33120168, 54804801,
  3058. 8317627, 23388070, 16052080}},
  3059. {{12719997, 11937594, 35138804, 28525742, 26900119, 8561328,
  3060. 46953177, 21921452, 52354592, 22741539}},
  3061. },
  3062. {
  3063. {{15961858, 14150409, 26716931, 32888600, 44314535, 13603568,
  3064. 11829573, 7467844, 38286736, 929274}},
  3065. {{11038231, 21972036, 39798381, 26237869, 56610336, 17246600,
  3066. 43629330, 24182562, 45715720, 2465073}},
  3067. {{20017144, 29231206, 27915241, 1529148, 12396362, 15675764,
  3068. 13817261, 23896366, 2463390, 28932292}},
  3069. },
  3070. {
  3071. {{50749986, 20890520, 55043680, 4996453, 65852442, 1073571,
  3072. 9583558, 12851107, 4003896, 12673717}},
  3073. {{65377275, 18398561, 63845933, 16143081, 19294135, 13385325,
  3074. 14741514, 24450706, 7903885, 2348101}},
  3075. {{24536016, 17039225, 12715591, 29692277, 1511292, 10047386,
  3076. 63266518, 26425272, 38731325, 10048126}},
  3077. },
  3078. },
  3079. {
  3080. {
  3081. {{54486638, 27349611, 30718824, 2591312, 56491836, 12192839,
  3082. 18873298, 26257342, 34811107, 15221631}},
  3083. {{40630742, 22450567, 11546243, 31701949, 9180879, 7656409,
  3084. 45764914, 2095754, 29769758, 6593415}},
  3085. {{35114656, 30646970, 4176911, 3264766, 12538965, 32686321, 26312344,
  3086. 27435754, 30958053, 8292160}},
  3087. },
  3088. {
  3089. {{31429803, 19595316, 29173531, 15632448, 12174511, 30794338,
  3090. 32808830, 3977186, 26143136, 30405556}},
  3091. {{22648882, 1402143, 44308880, 13746058, 7936347, 365344, 58440231,
  3092. 31879998, 63350620, 31249806}},
  3093. {{51616947, 8012312, 64594134, 20851969, 43143017, 23300402,
  3094. 65496150, 32018862, 50444388, 8194477}},
  3095. },
  3096. {
  3097. {{27338066, 26047012, 59694639, 10140404, 48082437, 26964542,
  3098. 27277190, 8855376, 28572286, 3005164}},
  3099. {{26287105, 4821776, 25476601, 29408529, 63344350, 17765447,
  3100. 49100281, 1182478, 41014043, 20474836}},
  3101. {{59937691, 3178079, 23970071, 6201893, 49913287, 29065239,
  3102. 45232588, 19571804, 32208682, 32356184}},
  3103. },
  3104. {
  3105. {{50451143, 2817642, 56822502, 14811297, 6024667, 13349505,
  3106. 39793360, 23056589, 39436278, 22014573}},
  3107. {{15941010, 24148500, 45741813, 8062054, 31876073, 33315803,
  3108. 51830470, 32110002, 15397330, 29424239}},
  3109. {{8934485, 20068965, 43822466, 20131190, 34662773, 14047985,
  3110. 31170398, 32113411, 39603297, 15087183}},
  3111. },
  3112. {
  3113. {{48751602, 31397940, 24524912, 16876564, 15520426, 27193656,
  3114. 51606457, 11461895, 16788528, 27685490}},
  3115. {{65161459, 16013772, 21750665, 3714552, 49707082, 17498998,
  3116. 63338576, 23231111, 31322513, 21938797}},
  3117. {{21426636, 27904214, 53460576, 28206894, 38296674, 28633461,
  3118. 48833472, 18933017, 13040861, 21441484}},
  3119. },
  3120. {
  3121. {{11293895, 12478086, 39972463, 15083749, 37801443, 14748871,
  3122. 14555558, 20137329, 1613710, 4896935}},
  3123. {{41213962, 15323293, 58619073, 25496531, 25967125, 20128972,
  3124. 2825959, 28657387, 43137087, 22287016}},
  3125. {{51184079, 28324551, 49665331, 6410663, 3622847, 10243618,
  3126. 20615400, 12405433, 43355834, 25118015}},
  3127. },
  3128. {
  3129. {{60017550, 12556207, 46917512, 9025186, 50036385, 4333800,
  3130. 4378436, 2432030, 23097949, 32988414}},
  3131. {{4565804, 17528778, 20084411, 25711615, 1724998, 189254, 24767264,
  3132. 10103221, 48596551, 2424777}},
  3133. {{366633, 21577626, 8173089, 26664313, 30788633, 5745705, 59940186,
  3134. 1344108, 63466311, 12412658}},
  3135. },
  3136. {
  3137. {{43107073, 7690285, 14929416, 33386175, 34898028, 20141445,
  3138. 24162696, 18227928, 63967362, 11179384}},
  3139. {{18289503, 18829478, 8056944, 16430056, 45379140, 7842513,
  3140. 61107423, 32067534, 48424218, 22110928}},
  3141. {{476239, 6601091, 60956074, 23831056, 17503544, 28690532, 27672958,
  3142. 13403813, 11052904, 5219329}},
  3143. },
  3144. },
  3145. {
  3146. {
  3147. {{20678527, 25178694, 34436965, 8849122, 62099106, 14574751,
  3148. 31186971, 29580702, 9014761, 24975376}},
  3149. {{53464795, 23204192, 51146355, 5075807, 65594203, 22019831,
  3150. 34006363, 9160279, 8473550, 30297594}},
  3151. {{24900749, 14435722, 17209120, 18261891, 44516588, 9878982,
  3152. 59419555, 17218610, 42540382, 11788947}},
  3153. },
  3154. {
  3155. {{63990690, 22159237, 53306774, 14797440, 9652448, 26708528,
  3156. 47071426, 10410732, 42540394, 32095740}},
  3157. {{51449703, 16736705, 44641714, 10215877, 58011687, 7563910,
  3158. 11871841, 21049238, 48595538, 8464117}},
  3159. {{43708233, 8348506, 52522913, 32692717, 63158658, 27181012,
  3160. 14325288, 8628612, 33313881, 25183915}},
  3161. },
  3162. {
  3163. {{46921872, 28586496, 22367355, 5271547, 66011747, 28765593,
  3164. 42303196, 23317577, 58168128, 27736162}},
  3165. {{60160060, 31759219, 34483180, 17533252, 32635413, 26180187,
  3166. 15989196, 20716244, 28358191, 29300528}},
  3167. {{43547083, 30755372, 34757181, 31892468, 57961144, 10429266,
  3168. 50471180, 4072015, 61757200, 5596588}},
  3169. },
  3170. {
  3171. {{38872266, 30164383, 12312895, 6213178, 3117142, 16078565,
  3172. 29266239, 2557221, 1768301, 15373193}},
  3173. {{59865506, 30307471, 62515396, 26001078, 66980936, 32642186, 66017961,
  3174. 29049440, 42448372, 3442909}},
  3175. {{36898293, 5124042, 14181784, 8197961, 18964734, 21615339,
  3176. 22597930, 7176455, 48523386, 13365929}},
  3177. },
  3178. {
  3179. {{59231455, 32054473, 8324672, 4690079, 6261860, 890446, 24538107,
  3180. 24984246, 57419264, 30522764}},
  3181. {{25008885, 22782833, 62803832, 23916421, 16265035, 15721635,
  3182. 683793, 21730648, 15723478, 18390951}},
  3183. {{57448220, 12374378, 40101865, 26528283, 59384749, 21239917,
  3184. 11879681, 5400171, 519526, 32318556}},
  3185. },
  3186. {
  3187. {{22258397, 17222199, 59239046, 14613015, 44588609, 30603508,
  3188. 46754982, 7315966, 16648397, 7605640}},
  3189. {{59027556, 25089834, 58885552, 9719709, 19259459, 18206220,
  3190. 23994941, 28272877, 57640015, 4763277}},
  3191. {{45409620, 9220968, 51378240, 1084136, 41632757, 30702041,
  3192. 31088446, 25789909, 55752334, 728111}},
  3193. },
  3194. {
  3195. {{26047201, 21802961, 60208540, 17032633, 24092067, 9158119,
  3196. 62835319, 20998873, 37743427, 28056159}},
  3197. {{17510331, 33231575, 5854288, 8403524, 17133918, 30441820, 38997856,
  3198. 12327944, 10750447, 10014012}},
  3199. {{56796096, 3936951, 9156313, 24656749, 16498691, 32559785,
  3200. 39627812, 32887699, 3424690, 7540221}},
  3201. },
  3202. {
  3203. {{30322361, 26590322, 11361004, 29411115, 7433303, 4989748, 60037442,
  3204. 17237212, 57864598, 15258045}},
  3205. {{13054543, 30774935, 19155473, 469045, 54626067, 4566041, 5631406,
  3206. 2711395, 1062915, 28418087}},
  3207. {{47868616, 22299832, 37599834, 26054466, 61273100, 13005410,
  3208. 61042375, 12194496, 32960380, 1459310}},
  3209. },
  3210. },
  3211. {
  3212. {
  3213. {{19852015, 7027924, 23669353, 10020366, 8586503, 26896525, 394196,
  3214. 27452547, 18638002, 22379495}},
  3215. {{31395515, 15098109, 26581030, 8030562, 50580950, 28547297,
  3216. 9012485, 25970078, 60465776, 28111795}},
  3217. {{57916680, 31207054, 65111764, 4529533, 25766844, 607986, 67095642,
  3218. 9677542, 34813975, 27098423}},
  3219. },
  3220. {
  3221. {{64664349, 33404494, 29348901, 8186665, 1873760, 12489863, 36174285,
  3222. 25714739, 59256019, 25416002}},
  3223. {{51872508, 18120922, 7766469, 746860, 26346930, 23332670,
  3224. 39775412, 10754587, 57677388, 5203575}},
  3225. {{31834314, 14135496, 66338857, 5159117, 20917671, 16786336,
  3226. 59640890, 26216907, 31809242, 7347066}},
  3227. },
  3228. {
  3229. {{57502122, 21680191, 20414458, 13033986, 13716524, 21862551,
  3230. 19797969, 21343177, 15192875, 31466942}},
  3231. {{54445282, 31372712, 1168161, 29749623, 26747876, 19416341,
  3232. 10609329, 12694420, 33473243, 20172328}},
  3233. {{33184999, 11180355, 15832085, 22169002, 65475192, 225883,
  3234. 15089336, 22530529, 60973201, 14480052}},
  3235. },
  3236. {
  3237. {{31308717, 27934434, 31030839, 31657333, 15674546, 26971549,
  3238. 5496207, 13685227, 27595050, 8737275}},
  3239. {{46790012, 18404192, 10933842, 17376410, 8335351, 26008410,
  3240. 36100512, 20943827, 26498113, 66511}},
  3241. {{22644435, 24792703, 50437087, 4884561, 64003250, 19995065,
  3242. 30540765, 29267685, 53781076, 26039336}},
  3243. },
  3244. {
  3245. {{39091017, 9834844, 18617207, 30873120, 63706907, 20246925,
  3246. 8205539, 13585437, 49981399, 15115438}},
  3247. {{23711543, 32881517, 31206560, 25191721, 6164646, 23844445,
  3248. 33572981, 32128335, 8236920, 16492939}},
  3249. {{43198286, 20038905, 40809380, 29050590, 25005589, 25867162,
  3250. 19574901, 10071562, 6708380, 27332008}},
  3251. },
  3252. {
  3253. {{2101372, 28624378, 19702730, 2367575, 51681697, 1047674, 5301017,
  3254. 9328700, 29955601, 21876122}},
  3255. {{3096359, 9271816, 45488000, 18032587, 52260867, 25961494,
  3256. 41216721, 20918836, 57191288, 6216607}},
  3257. {{34493015, 338662, 41913253, 2510421, 37895298, 19734218,
  3258. 24822829, 27407865, 40341383, 7525078}},
  3259. },
  3260. {
  3261. {{44042215, 19568808, 16133486, 25658254, 63719298, 778787,
  3262. 66198528, 30771936, 47722230, 11994100}},
  3263. {{21691500, 19929806, 66467532, 19187410, 3285880, 30070836,
  3264. 42044197, 9718257, 59631427, 13381417}},
  3265. {{18445390, 29352196, 14979845, 11622458, 65381754, 29971451,
  3266. 23111647, 27179185, 28535281, 15779576}},
  3267. },
  3268. {
  3269. {{30098034, 3089662, 57874477, 16662134, 45801924, 11308410,
  3270. 53040410, 12021729, 9955285, 17251076}},
  3271. {{9734894, 18977602, 59635230, 24415696, 2060391, 11313496,
  3272. 48682835, 9924398, 20194861, 13380996}},
  3273. {{40730762, 25589224, 44941042, 15789296, 49053522, 27385639,
  3274. 65123949, 15707770, 26342023, 10146099}},
  3275. },
  3276. },
  3277. {
  3278. {
  3279. {{41091971, 33334488, 21339190, 33513044, 19745255, 30675732,
  3280. 37471583, 2227039, 21612326, 33008704}},
  3281. {{54031477, 1184227, 23562814, 27583990, 46757619, 27205717,
  3282. 25764460, 12243797, 46252298, 11649657}},
  3283. {{57077370, 11262625, 27384172, 2271902, 26947504, 17556661, 39943,
  3284. 6114064, 33514190, 2333242}},
  3285. },
  3286. {
  3287. {{45675257, 21132610, 8119781, 7219913, 45278342, 24538297,
  3288. 60429113, 20883793, 24350577, 20104431}},
  3289. {{62992557, 22282898, 43222677, 4843614, 37020525, 690622,
  3290. 35572776, 23147595, 8317859, 12352766}},
  3291. {{18200138, 19078521, 34021104, 30857812, 43406342, 24451920,
  3292. 43556767, 31266881, 20712162, 6719373}},
  3293. },
  3294. {
  3295. {{26656189, 6075253, 59250308, 1886071, 38764821, 4262325, 11117530,
  3296. 29791222, 26224234, 30256974}},
  3297. {{49939907, 18700334, 63713187, 17184554, 47154818, 14050419,
  3298. 21728352, 9493610, 18620611, 17125804}},
  3299. {{53785524, 13325348, 11432106, 5964811, 18609221, 6062965,
  3300. 61839393, 23828875, 36407290, 17074774}},
  3301. },
  3302. {
  3303. {{43248326, 22321272, 26961356, 1640861, 34695752, 16816491,
  3304. 12248508, 28313793, 13735341, 1934062}},
  3305. {{25089769, 6742589, 17081145, 20148166, 21909292, 17486451,
  3306. 51972569, 29789085, 45830866, 5473615}},
  3307. {{31883658, 25593331, 1083431, 21982029, 22828470, 13290673,
  3308. 59983779, 12469655, 29111212, 28103418}},
  3309. },
  3310. {
  3311. {{24244947, 18504025, 40845887, 2791539, 52111265, 16666677,
  3312. 24367466, 6388839, 56813277, 452382}},
  3313. {{41468082, 30136590, 5217915, 16224624, 19987036, 29472163,
  3314. 42872612, 27639183, 15766061, 8407814}},
  3315. {{46701865, 13990230, 15495425, 16395525, 5377168, 15166495,
  3316. 58191841, 29165478, 59040954, 2276717}},
  3317. },
  3318. {
  3319. {{30157899, 12924066, 49396814, 9245752, 19895028, 3368142,
  3320. 43281277, 5096218, 22740376, 26251015}},
  3321. {{2041139, 19298082, 7783686, 13876377, 41161879, 20201972,
  3322. 24051123, 13742383, 51471265, 13295221}},
  3323. {{33338218, 25048699, 12532112, 7977527, 9106186, 31839181,
  3324. 49388668, 28941459, 62657506, 18884987}},
  3325. },
  3326. {
  3327. {{47063583, 5454096, 52762316, 6447145, 28862071, 1883651,
  3328. 64639598, 29412551, 7770568, 9620597}},
  3329. {{23208049, 7979712, 33071466, 8149229, 1758231, 22719437, 30945527,
  3330. 31860109, 33606523, 18786461}},
  3331. {{1439939, 17283952, 66028874, 32760649, 4625401, 10647766, 62065063,
  3332. 1220117, 30494170, 22113633}},
  3333. },
  3334. {
  3335. {{62071265, 20526136, 64138304, 30492664, 15640973, 26852766,
  3336. 40369837, 926049, 65424525, 20220784}},
  3337. {{13908495, 30005160, 30919927, 27280607, 45587000, 7989038,
  3338. 9021034, 9078865, 3353509, 4033511}},
  3339. {{37445433, 18440821, 32259990, 33209950, 24295848, 20642309,
  3340. 23161162, 8839127, 27485041, 7356032}},
  3341. },
  3342. },
  3343. {
  3344. {
  3345. {{9661008, 705443, 11980065, 28184278, 65480320, 14661172, 60762722,
  3346. 2625014, 28431036, 16782598}},
  3347. {{43269631, 25243016, 41163352, 7480957, 49427195, 25200248,
  3348. 44562891, 14150564, 15970762, 4099461}},
  3349. {{29262576, 16756590, 26350592, 24760869, 8529670, 22346382,
  3350. 13617292, 23617289, 11465738, 8317062}},
  3351. },
  3352. {
  3353. {{41615764, 26591503, 32500199, 24135381, 44070139, 31252209,
  3354. 14898636, 3848455, 20969334, 28396916}},
  3355. {{46724414, 19206718, 48772458, 13884721, 34069410, 2842113,
  3356. 45498038, 29904543, 11177094, 14989547}},
  3357. {{42612143, 21838415, 16959895, 2278463, 12066309, 10137771,
  3358. 13515641, 2581286, 38621356, 9930239}},
  3359. },
  3360. {
  3361. {{49357223, 31456605, 16544299, 20545132, 51194056, 18605350,
  3362. 18345766, 20150679, 16291480, 28240394}},
  3363. {{33879670, 2553287, 32678213, 9875984, 8534129, 6889387, 57432090,
  3364. 6957616, 4368891, 9788741}},
  3365. {{16660737, 7281060, 56278106, 12911819, 20108584, 25452756,
  3366. 45386327, 24941283, 16250551, 22443329}},
  3367. },
  3368. {
  3369. {{47343357, 2390525, 50557833, 14161979, 1905286, 6414907, 4689584,
  3370. 10604807, 36918461, 4782746}},
  3371. {{65754325, 14736940, 59741422, 20261545, 7710541, 19398842,
  3372. 57127292, 4383044, 22546403, 437323}},
  3373. {{31665558, 21373968, 50922033, 1491338, 48740239, 3294681,
  3374. 27343084, 2786261, 36475274, 19457415}},
  3375. },
  3376. {
  3377. {{52641566, 32870716, 33734756, 7448551, 19294360, 14334329,
  3378. 47418233, 2355318, 47824193, 27440058}},
  3379. {{15121312, 17758270, 6377019, 27523071, 56310752, 20596586,
  3380. 18952176, 15496498, 37728731, 11754227}},
  3381. {{64471568, 20071356, 8488726, 19250536, 12728760, 31931939,
  3382. 7141595, 11724556, 22761615, 23420291}},
  3383. },
  3384. {
  3385. {{16918416, 11729663, 49025285, 3022986, 36093132, 20214772,
  3386. 38367678, 21327038, 32851221, 11717399}},
  3387. {{11166615, 7338049, 60386341, 4531519, 37640192, 26252376,
  3388. 31474878, 3483633, 65915689, 29523600}},
  3389. {{66923210, 9921304, 31456609, 20017994, 55095045, 13348922,
  3390. 33142652, 6546660, 47123585, 29606055}},
  3391. },
  3392. {
  3393. {{34648249, 11266711, 55911757, 25655328, 31703693, 3855903,
  3394. 58571733, 20721383, 36336829, 18068118}},
  3395. {{49102387, 12709067, 3991746, 27075244, 45617340, 23004006,
  3396. 35973516, 17504552, 10928916, 3011958}},
  3397. {{60151107, 17960094, 31696058, 334240, 29576716, 14796075,
  3398. 36277808, 20749251, 18008030, 10258577}},
  3399. },
  3400. {
  3401. {{44660220, 15655568, 7018479, 29144429, 36794597, 32352840,
  3402. 65255398, 1367119, 25127874, 6671743}},
  3403. {{29701166, 19180498, 56230743, 9279287, 67091296, 13127209,
  3404. 21382910, 11042292, 25838796, 4642684}},
  3405. {{46678630, 14955536, 42982517, 8124618, 61739576, 27563961,
  3406. 30468146, 19653792, 18423288, 4177476}},
  3407. },
  3408. },
  3409. };
  3410. static uint8_t negative(signed char b) {
  3411. uint32_t x = b;
  3412. x >>= 31; // 1: yes; 0: no
  3413. return x;
  3414. }
  3415. static void table_select(ge_precomp *t, int pos, signed char b) {
  3416. ge_precomp minust;
  3417. uint8_t bnegative = negative(b);
  3418. uint8_t babs = b - ((uint8_t)((-bnegative) & b) << 1);
  3419. ge_precomp_0(t);
  3420. cmov(t, &k25519Precomp[pos][0], equal(babs, 1));
  3421. cmov(t, &k25519Precomp[pos][1], equal(babs, 2));
  3422. cmov(t, &k25519Precomp[pos][2], equal(babs, 3));
  3423. cmov(t, &k25519Precomp[pos][3], equal(babs, 4));
  3424. cmov(t, &k25519Precomp[pos][4], equal(babs, 5));
  3425. cmov(t, &k25519Precomp[pos][5], equal(babs, 6));
  3426. cmov(t, &k25519Precomp[pos][6], equal(babs, 7));
  3427. cmov(t, &k25519Precomp[pos][7], equal(babs, 8));
  3428. fe_copy_ll(&minust.yplusx, &t->yminusx);
  3429. fe_copy_ll(&minust.yminusx, &t->yplusx);
  3430. // NOTE: the input table is canonical, but types don't encode it
  3431. fe tmp;
  3432. fe_carry(&tmp, &t->xy2d);
  3433. fe_neg(&minust.xy2d, &tmp);
  3434. cmov(t, &minust, bnegative);
  3435. }
  3436. // h = a * B
  3437. // where a = a[0]+256*a[1]+...+256^31 a[31]
  3438. // B is the Ed25519 base point (x,4/5) with x positive.
  3439. //
  3440. // Preconditions:
  3441. // a[31] <= 127
  3442. void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t *a) {
  3443. signed char e[64];
  3444. signed char carry;
  3445. ge_p1p1 r;
  3446. ge_p2 s;
  3447. ge_precomp t;
  3448. int i;
  3449. for (i = 0; i < 32; ++i) {
  3450. e[2 * i + 0] = (a[i] >> 0) & 15;
  3451. e[2 * i + 1] = (a[i] >> 4) & 15;
  3452. }
  3453. // each e[i] is between 0 and 15
  3454. // e[63] is between 0 and 7
  3455. carry = 0;
  3456. for (i = 0; i < 63; ++i) {
  3457. e[i] += carry;
  3458. carry = e[i] + 8;
  3459. carry >>= 4;
  3460. e[i] -= carry << 4;
  3461. }
  3462. e[63] += carry;
  3463. // each e[i] is between -8 and 8
  3464. ge_p3_0(h);
  3465. for (i = 1; i < 64; i += 2) {
  3466. table_select(&t, i / 2, e[i]);
  3467. ge_madd(&r, h, &t);
  3468. x25519_ge_p1p1_to_p3(h, &r);
  3469. }
  3470. ge_p3_dbl(&r, h);
  3471. x25519_ge_p1p1_to_p2(&s, &r);
  3472. ge_p2_dbl(&r, &s);
  3473. x25519_ge_p1p1_to_p2(&s, &r);
  3474. ge_p2_dbl(&r, &s);
  3475. x25519_ge_p1p1_to_p2(&s, &r);
  3476. ge_p2_dbl(&r, &s);
  3477. x25519_ge_p1p1_to_p3(h, &r);
  3478. for (i = 0; i < 64; i += 2) {
  3479. table_select(&t, i / 2, e[i]);
  3480. ge_madd(&r, h, &t);
  3481. x25519_ge_p1p1_to_p3(h, &r);
  3482. }
  3483. }
  3484. #endif
  3485. static void cmov_cached(ge_cached *t, ge_cached *u, uint8_t b) {
  3486. fe_cmov(&t->YplusX, &u->YplusX, b);
  3487. fe_cmov(&t->YminusX, &u->YminusX, b);
  3488. fe_cmov(&t->Z, &u->Z, b);
  3489. fe_cmov(&t->T2d, &u->T2d, b);
  3490. }
  3491. // r = scalar * A.
  3492. // where a = a[0]+256*a[1]+...+256^31 a[31].
  3493. void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A) {
  3494. ge_p2 Ai_p2[8];
  3495. ge_cached Ai[16];
  3496. ge_p1p1 t;
  3497. ge_cached_0(&Ai[0]);
  3498. x25519_ge_p3_to_cached(&Ai[1], A);
  3499. ge_p3_to_p2(&Ai_p2[1], A);
  3500. unsigned i;
  3501. for (i = 2; i < 16; i += 2) {
  3502. ge_p2_dbl(&t, &Ai_p2[i / 2]);
  3503. ge_p1p1_to_cached(&Ai[i], &t);
  3504. if (i < 8) {
  3505. x25519_ge_p1p1_to_p2(&Ai_p2[i], &t);
  3506. }
  3507. x25519_ge_add(&t, A, &Ai[i]);
  3508. ge_p1p1_to_cached(&Ai[i + 1], &t);
  3509. if (i < 7) {
  3510. x25519_ge_p1p1_to_p2(&Ai_p2[i + 1], &t);
  3511. }
  3512. }
  3513. ge_p2_0(r);
  3514. ge_p3 u;
  3515. for (i = 0; i < 256; i += 4) {
  3516. ge_p2_dbl(&t, r);
  3517. x25519_ge_p1p1_to_p2(r, &t);
  3518. ge_p2_dbl(&t, r);
  3519. x25519_ge_p1p1_to_p2(r, &t);
  3520. ge_p2_dbl(&t, r);
  3521. x25519_ge_p1p1_to_p2(r, &t);
  3522. ge_p2_dbl(&t, r);
  3523. x25519_ge_p1p1_to_p3(&u, &t);
  3524. uint8_t index = scalar[31 - i/8];
  3525. index >>= 4 - (i & 4);
  3526. index &= 0xf;
  3527. unsigned j;
  3528. ge_cached selected;
  3529. ge_cached_0(&selected);
  3530. for (j = 0; j < 16; j++) {
  3531. cmov_cached(&selected, &Ai[j], equal(j, index));
  3532. }
  3533. x25519_ge_add(&t, &u, &selected);
  3534. x25519_ge_p1p1_to_p2(r, &t);
  3535. }
  3536. }
  3537. static void slide(signed char *r, const uint8_t *a) {
  3538. int i;
  3539. int b;
  3540. int k;
  3541. for (i = 0; i < 256; ++i) {
  3542. r[i] = 1 & (a[i >> 3] >> (i & 7));
  3543. }
  3544. for (i = 0; i < 256; ++i) {
  3545. if (r[i]) {
  3546. for (b = 1; b <= 6 && i + b < 256; ++b) {
  3547. if (r[i + b]) {
  3548. if (r[i] + (r[i + b] << b) <= 15) {
  3549. r[i] += r[i + b] << b;
  3550. r[i + b] = 0;
  3551. } else if (r[i] - (r[i + b] << b) >= -15) {
  3552. r[i] -= r[i + b] << b;
  3553. for (k = i + b; k < 256; ++k) {
  3554. if (!r[k]) {
  3555. r[k] = 1;
  3556. break;
  3557. }
  3558. r[k] = 0;
  3559. }
  3560. } else {
  3561. break;
  3562. }
  3563. }
  3564. }
  3565. }
  3566. }
  3567. }
  3568. static const ge_precomp Bi[8] = {
  3569. {
  3570. {{25967493, 19198397, 29566455, 3660896, 54414519, 4014786, 27544626,
  3571. 21800161, 61029707, 2047604}},
  3572. {{54563134, 934261, 64385954, 3049989, 66381436, 9406985, 12720692,
  3573. 5043384, 19500929, 18085054}},
  3574. {{58370664, 4489569, 9688441, 18769238, 10184608, 21191052, 29287918,
  3575. 11864899, 42594502, 29115885}},
  3576. },
  3577. {
  3578. {{15636272, 23865875, 24204772, 25642034, 616976, 16869170, 27787599,
  3579. 18782243, 28944399, 32004408}},
  3580. {{16568933, 4717097, 55552716, 32452109, 15682895, 21747389, 16354576,
  3581. 21778470, 7689661, 11199574}},
  3582. {{30464137, 27578307, 55329429, 17883566, 23220364, 15915852, 7512774,
  3583. 10017326, 49359771, 23634074}},
  3584. },
  3585. {
  3586. {{10861363, 11473154, 27284546, 1981175, 37044515, 12577860, 32867885,
  3587. 14515107, 51670560, 10819379}},
  3588. {{4708026, 6336745, 20377586, 9066809, 55836755, 6594695, 41455196,
  3589. 12483687, 54440373, 5581305}},
  3590. {{19563141, 16186464, 37722007, 4097518, 10237984, 29206317, 28542349,
  3591. 13850243, 43430843, 17738489}},
  3592. },
  3593. {
  3594. {{5153727, 9909285, 1723747, 30776558, 30523604, 5516873, 19480852,
  3595. 5230134, 43156425, 18378665}},
  3596. {{36839857, 30090922, 7665485, 10083793, 28475525, 1649722, 20654025,
  3597. 16520125, 30598449, 7715701}},
  3598. {{28881826, 14381568, 9657904, 3680757, 46927229, 7843315, 35708204,
  3599. 1370707, 29794553, 32145132}},
  3600. },
  3601. {
  3602. {{44589871, 26862249, 14201701, 24808930, 43598457, 8844725, 18474211,
  3603. 32192982, 54046167, 13821876}},
  3604. {{60653668, 25714560, 3374701, 28813570, 40010246, 22982724, 31655027,
  3605. 26342105, 18853321, 19333481}},
  3606. {{4566811, 20590564, 38133974, 21313742, 59506191, 30723862, 58594505,
  3607. 23123294, 2207752, 30344648}},
  3608. },
  3609. {
  3610. {{41954014, 29368610, 29681143, 7868801, 60254203, 24130566, 54671499,
  3611. 32891431, 35997400, 17421995}},
  3612. {{25576264, 30851218, 7349803, 21739588, 16472781, 9300885, 3844789,
  3613. 15725684, 171356, 6466918}},
  3614. {{23103977, 13316479, 9739013, 17404951, 817874, 18515490, 8965338,
  3615. 19466374, 36393951, 16193876}},
  3616. },
  3617. {
  3618. {{33587053, 3180712, 64714734, 14003686, 50205390, 17283591, 17238397,
  3619. 4729455, 49034351, 9256799}},
  3620. {{41926547, 29380300, 32336397, 5036987, 45872047, 11360616, 22616405,
  3621. 9761698, 47281666, 630304}},
  3622. {{53388152, 2639452, 42871404, 26147950, 9494426, 27780403, 60554312,
  3623. 17593437, 64659607, 19263131}},
  3624. },
  3625. {
  3626. {{63957664, 28508356, 9282713, 6866145, 35201802, 32691408, 48168288,
  3627. 15033783, 25105118, 25659556}},
  3628. {{42782475, 15950225, 35307649, 18961608, 55446126, 28463506,
  3629. 1573891, 30928545, 2198789, 17749813}},
  3630. {{64009494, 10324966, 64867251, 7453182, 61661885, 30818928, 53296841,
  3631. 17317989, 34647629, 21263748}},
  3632. },
  3633. };
  3634. // r = a * A + b * B
  3635. // where a = a[0]+256*a[1]+...+256^31 a[31].
  3636. // and b = b[0]+256*b[1]+...+256^31 b[31].
  3637. // B is the Ed25519 base point (x,4/5) with x positive.
  3638. static void ge_double_scalarmult_vartime(ge_p2 *r, const uint8_t *a,
  3639. const ge_p3 *A, const uint8_t *b) {
  3640. signed char aslide[256];
  3641. signed char bslide[256];
  3642. ge_cached Ai[8]; // A,3A,5A,7A,9A,11A,13A,15A
  3643. ge_p1p1 t;
  3644. ge_p3 u;
  3645. ge_p3 A2;
  3646. int i;
  3647. slide(aslide, a);
  3648. slide(bslide, b);
  3649. x25519_ge_p3_to_cached(&Ai[0], A);
  3650. ge_p3_dbl(&t, A);
  3651. x25519_ge_p1p1_to_p3(&A2, &t);
  3652. x25519_ge_add(&t, &A2, &Ai[0]);
  3653. x25519_ge_p1p1_to_p3(&u, &t);
  3654. x25519_ge_p3_to_cached(&Ai[1], &u);
  3655. x25519_ge_add(&t, &A2, &Ai[1]);
  3656. x25519_ge_p1p1_to_p3(&u, &t);
  3657. x25519_ge_p3_to_cached(&Ai[2], &u);
  3658. x25519_ge_add(&t, &A2, &Ai[2]);
  3659. x25519_ge_p1p1_to_p3(&u, &t);
  3660. x25519_ge_p3_to_cached(&Ai[3], &u);
  3661. x25519_ge_add(&t, &A2, &Ai[3]);
  3662. x25519_ge_p1p1_to_p3(&u, &t);
  3663. x25519_ge_p3_to_cached(&Ai[4], &u);
  3664. x25519_ge_add(&t, &A2, &Ai[4]);
  3665. x25519_ge_p1p1_to_p3(&u, &t);
  3666. x25519_ge_p3_to_cached(&Ai[5], &u);
  3667. x25519_ge_add(&t, &A2, &Ai[5]);
  3668. x25519_ge_p1p1_to_p3(&u, &t);
  3669. x25519_ge_p3_to_cached(&Ai[6], &u);
  3670. x25519_ge_add(&t, &A2, &Ai[6]);
  3671. x25519_ge_p1p1_to_p3(&u, &t);
  3672. x25519_ge_p3_to_cached(&Ai[7], &u);
  3673. ge_p2_0(r);
  3674. for (i = 255; i >= 0; --i) {
  3675. if (aslide[i] || bslide[i]) {
  3676. break;
  3677. }
  3678. }
  3679. for (; i >= 0; --i) {
  3680. ge_p2_dbl(&t, r);
  3681. if (aslide[i] > 0) {
  3682. x25519_ge_p1p1_to_p3(&u, &t);
  3683. x25519_ge_add(&t, &u, &Ai[aslide[i] / 2]);
  3684. } else if (aslide[i] < 0) {
  3685. x25519_ge_p1p1_to_p3(&u, &t);
  3686. x25519_ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
  3687. }
  3688. if (bslide[i] > 0) {
  3689. x25519_ge_p1p1_to_p3(&u, &t);
  3690. ge_madd(&t, &u, &Bi[bslide[i] / 2]);
  3691. } else if (bslide[i] < 0) {
  3692. x25519_ge_p1p1_to_p3(&u, &t);
  3693. ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
  3694. }
  3695. x25519_ge_p1p1_to_p2(r, &t);
  3696. }
  3697. }
  3698. // The set of scalars is \Z/l
  3699. // where l = 2^252 + 27742317777372353535851937790883648493.
  3700. // Input:
  3701. // s[0]+256*s[1]+...+256^63*s[63] = s
  3702. //
  3703. // Output:
  3704. // s[0]+256*s[1]+...+256^31*s[31] = s mod l
  3705. // where l = 2^252 + 27742317777372353535851937790883648493.
  3706. // Overwrites s in place.
  3707. void x25519_sc_reduce(uint8_t *s) {
  3708. int64_t s0 = 2097151 & load_3(s);
  3709. int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
  3710. int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
  3711. int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
  3712. int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
  3713. int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
  3714. int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
  3715. int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
  3716. int64_t s8 = 2097151 & load_3(s + 21);
  3717. int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
  3718. int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
  3719. int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
  3720. int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
  3721. int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
  3722. int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
  3723. int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
  3724. int64_t s16 = 2097151 & load_3(s + 42);
  3725. int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
  3726. int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
  3727. int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
  3728. int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
  3729. int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
  3730. int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
  3731. int64_t s23 = (load_4(s + 60) >> 3);
  3732. int64_t carry0;
  3733. int64_t carry1;
  3734. int64_t carry2;
  3735. int64_t carry3;
  3736. int64_t carry4;
  3737. int64_t carry5;
  3738. int64_t carry6;
  3739. int64_t carry7;
  3740. int64_t carry8;
  3741. int64_t carry9;
  3742. int64_t carry10;
  3743. int64_t carry11;
  3744. int64_t carry12;
  3745. int64_t carry13;
  3746. int64_t carry14;
  3747. int64_t carry15;
  3748. int64_t carry16;
  3749. s11 += s23 * 666643;
  3750. s12 += s23 * 470296;
  3751. s13 += s23 * 654183;
  3752. s14 -= s23 * 997805;
  3753. s15 += s23 * 136657;
  3754. s16 -= s23 * 683901;
  3755. s23 = 0;
  3756. s10 += s22 * 666643;
  3757. s11 += s22 * 470296;
  3758. s12 += s22 * 654183;
  3759. s13 -= s22 * 997805;
  3760. s14 += s22 * 136657;
  3761. s15 -= s22 * 683901;
  3762. s22 = 0;
  3763. s9 += s21 * 666643;
  3764. s10 += s21 * 470296;
  3765. s11 += s21 * 654183;
  3766. s12 -= s21 * 997805;
  3767. s13 += s21 * 136657;
  3768. s14 -= s21 * 683901;
  3769. s21 = 0;
  3770. s8 += s20 * 666643;
  3771. s9 += s20 * 470296;
  3772. s10 += s20 * 654183;
  3773. s11 -= s20 * 997805;
  3774. s12 += s20 * 136657;
  3775. s13 -= s20 * 683901;
  3776. s20 = 0;
  3777. s7 += s19 * 666643;
  3778. s8 += s19 * 470296;
  3779. s9 += s19 * 654183;
  3780. s10 -= s19 * 997805;
  3781. s11 += s19 * 136657;
  3782. s12 -= s19 * 683901;
  3783. s19 = 0;
  3784. s6 += s18 * 666643;
  3785. s7 += s18 * 470296;
  3786. s8 += s18 * 654183;
  3787. s9 -= s18 * 997805;
  3788. s10 += s18 * 136657;
  3789. s11 -= s18 * 683901;
  3790. s18 = 0;
  3791. carry6 = (s6 + (1 << 20)) >> 21;
  3792. s7 += carry6;
  3793. s6 -= carry6 << 21;
  3794. carry8 = (s8 + (1 << 20)) >> 21;
  3795. s9 += carry8;
  3796. s8 -= carry8 << 21;
  3797. carry10 = (s10 + (1 << 20)) >> 21;
  3798. s11 += carry10;
  3799. s10 -= carry10 << 21;
  3800. carry12 = (s12 + (1 << 20)) >> 21;
  3801. s13 += carry12;
  3802. s12 -= carry12 << 21;
  3803. carry14 = (s14 + (1 << 20)) >> 21;
  3804. s15 += carry14;
  3805. s14 -= carry14 << 21;
  3806. carry16 = (s16 + (1 << 20)) >> 21;
  3807. s17 += carry16;
  3808. s16 -= carry16 << 21;
  3809. carry7 = (s7 + (1 << 20)) >> 21;
  3810. s8 += carry7;
  3811. s7 -= carry7 << 21;
  3812. carry9 = (s9 + (1 << 20)) >> 21;
  3813. s10 += carry9;
  3814. s9 -= carry9 << 21;
  3815. carry11 = (s11 + (1 << 20)) >> 21;
  3816. s12 += carry11;
  3817. s11 -= carry11 << 21;
  3818. carry13 = (s13 + (1 << 20)) >> 21;
  3819. s14 += carry13;
  3820. s13 -= carry13 << 21;
  3821. carry15 = (s15 + (1 << 20)) >> 21;
  3822. s16 += carry15;
  3823. s15 -= carry15 << 21;
  3824. s5 += s17 * 666643;
  3825. s6 += s17 * 470296;
  3826. s7 += s17 * 654183;
  3827. s8 -= s17 * 997805;
  3828. s9 += s17 * 136657;
  3829. s10 -= s17 * 683901;
  3830. s17 = 0;
  3831. s4 += s16 * 666643;
  3832. s5 += s16 * 470296;
  3833. s6 += s16 * 654183;
  3834. s7 -= s16 * 997805;
  3835. s8 += s16 * 136657;
  3836. s9 -= s16 * 683901;
  3837. s16 = 0;
  3838. s3 += s15 * 666643;
  3839. s4 += s15 * 470296;
  3840. s5 += s15 * 654183;
  3841. s6 -= s15 * 997805;
  3842. s7 += s15 * 136657;
  3843. s8 -= s15 * 683901;
  3844. s15 = 0;
  3845. s2 += s14 * 666643;
  3846. s3 += s14 * 470296;
  3847. s4 += s14 * 654183;
  3848. s5 -= s14 * 997805;
  3849. s6 += s14 * 136657;
  3850. s7 -= s14 * 683901;
  3851. s14 = 0;
  3852. s1 += s13 * 666643;
  3853. s2 += s13 * 470296;
  3854. s3 += s13 * 654183;
  3855. s4 -= s13 * 997805;
  3856. s5 += s13 * 136657;
  3857. s6 -= s13 * 683901;
  3858. s13 = 0;
  3859. s0 += s12 * 666643;
  3860. s1 += s12 * 470296;
  3861. s2 += s12 * 654183;
  3862. s3 -= s12 * 997805;
  3863. s4 += s12 * 136657;
  3864. s5 -= s12 * 683901;
  3865. s12 = 0;
  3866. carry0 = (s0 + (1 << 20)) >> 21;
  3867. s1 += carry0;
  3868. s0 -= carry0 << 21;
  3869. carry2 = (s2 + (1 << 20)) >> 21;
  3870. s3 += carry2;
  3871. s2 -= carry2 << 21;
  3872. carry4 = (s4 + (1 << 20)) >> 21;
  3873. s5 += carry4;
  3874. s4 -= carry4 << 21;
  3875. carry6 = (s6 + (1 << 20)) >> 21;
  3876. s7 += carry6;
  3877. s6 -= carry6 << 21;
  3878. carry8 = (s8 + (1 << 20)) >> 21;
  3879. s9 += carry8;
  3880. s8 -= carry8 << 21;
  3881. carry10 = (s10 + (1 << 20)) >> 21;
  3882. s11 += carry10;
  3883. s10 -= carry10 << 21;
  3884. carry1 = (s1 + (1 << 20)) >> 21;
  3885. s2 += carry1;
  3886. s1 -= carry1 << 21;
  3887. carry3 = (s3 + (1 << 20)) >> 21;
  3888. s4 += carry3;
  3889. s3 -= carry3 << 21;
  3890. carry5 = (s5 + (1 << 20)) >> 21;
  3891. s6 += carry5;
  3892. s5 -= carry5 << 21;
  3893. carry7 = (s7 + (1 << 20)) >> 21;
  3894. s8 += carry7;
  3895. s7 -= carry7 << 21;
  3896. carry9 = (s9 + (1 << 20)) >> 21;
  3897. s10 += carry9;
  3898. s9 -= carry9 << 21;
  3899. carry11 = (s11 + (1 << 20)) >> 21;
  3900. s12 += carry11;
  3901. s11 -= carry11 << 21;
  3902. s0 += s12 * 666643;
  3903. s1 += s12 * 470296;
  3904. s2 += s12 * 654183;
  3905. s3 -= s12 * 997805;
  3906. s4 += s12 * 136657;
  3907. s5 -= s12 * 683901;
  3908. s12 = 0;
  3909. carry0 = s0 >> 21;
  3910. s1 += carry0;
  3911. s0 -= carry0 << 21;
  3912. carry1 = s1 >> 21;
  3913. s2 += carry1;
  3914. s1 -= carry1 << 21;
  3915. carry2 = s2 >> 21;
  3916. s3 += carry2;
  3917. s2 -= carry2 << 21;
  3918. carry3 = s3 >> 21;
  3919. s4 += carry3;
  3920. s3 -= carry3 << 21;
  3921. carry4 = s4 >> 21;
  3922. s5 += carry4;
  3923. s4 -= carry4 << 21;
  3924. carry5 = s5 >> 21;
  3925. s6 += carry5;
  3926. s5 -= carry5 << 21;
  3927. carry6 = s6 >> 21;
  3928. s7 += carry6;
  3929. s6 -= carry6 << 21;
  3930. carry7 = s7 >> 21;
  3931. s8 += carry7;
  3932. s7 -= carry7 << 21;
  3933. carry8 = s8 >> 21;
  3934. s9 += carry8;
  3935. s8 -= carry8 << 21;
  3936. carry9 = s9 >> 21;
  3937. s10 += carry9;
  3938. s9 -= carry9 << 21;
  3939. carry10 = s10 >> 21;
  3940. s11 += carry10;
  3941. s10 -= carry10 << 21;
  3942. carry11 = s11 >> 21;
  3943. s12 += carry11;
  3944. s11 -= carry11 << 21;
  3945. s0 += s12 * 666643;
  3946. s1 += s12 * 470296;
  3947. s2 += s12 * 654183;
  3948. s3 -= s12 * 997805;
  3949. s4 += s12 * 136657;
  3950. s5 -= s12 * 683901;
  3951. s12 = 0;
  3952. carry0 = s0 >> 21;
  3953. s1 += carry0;
  3954. s0 -= carry0 << 21;
  3955. carry1 = s1 >> 21;
  3956. s2 += carry1;
  3957. s1 -= carry1 << 21;
  3958. carry2 = s2 >> 21;
  3959. s3 += carry2;
  3960. s2 -= carry2 << 21;
  3961. carry3 = s3 >> 21;
  3962. s4 += carry3;
  3963. s3 -= carry3 << 21;
  3964. carry4 = s4 >> 21;
  3965. s5 += carry4;
  3966. s4 -= carry4 << 21;
  3967. carry5 = s5 >> 21;
  3968. s6 += carry5;
  3969. s5 -= carry5 << 21;
  3970. carry6 = s6 >> 21;
  3971. s7 += carry6;
  3972. s6 -= carry6 << 21;
  3973. carry7 = s7 >> 21;
  3974. s8 += carry7;
  3975. s7 -= carry7 << 21;
  3976. carry8 = s8 >> 21;
  3977. s9 += carry8;
  3978. s8 -= carry8 << 21;
  3979. carry9 = s9 >> 21;
  3980. s10 += carry9;
  3981. s9 -= carry9 << 21;
  3982. carry10 = s10 >> 21;
  3983. s11 += carry10;
  3984. s10 -= carry10 << 21;
  3985. s[0] = s0 >> 0;
  3986. s[1] = s0 >> 8;
  3987. s[2] = (s0 >> 16) | (s1 << 5);
  3988. s[3] = s1 >> 3;
  3989. s[4] = s1 >> 11;
  3990. s[5] = (s1 >> 19) | (s2 << 2);
  3991. s[6] = s2 >> 6;
  3992. s[7] = (s2 >> 14) | (s3 << 7);
  3993. s[8] = s3 >> 1;
  3994. s[9] = s3 >> 9;
  3995. s[10] = (s3 >> 17) | (s4 << 4);
  3996. s[11] = s4 >> 4;
  3997. s[12] = s4 >> 12;
  3998. s[13] = (s4 >> 20) | (s5 << 1);
  3999. s[14] = s5 >> 7;
  4000. s[15] = (s5 >> 15) | (s6 << 6);
  4001. s[16] = s6 >> 2;
  4002. s[17] = s6 >> 10;
  4003. s[18] = (s6 >> 18) | (s7 << 3);
  4004. s[19] = s7 >> 5;
  4005. s[20] = s7 >> 13;
  4006. s[21] = s8 >> 0;
  4007. s[22] = s8 >> 8;
  4008. s[23] = (s8 >> 16) | (s9 << 5);
  4009. s[24] = s9 >> 3;
  4010. s[25] = s9 >> 11;
  4011. s[26] = (s9 >> 19) | (s10 << 2);
  4012. s[27] = s10 >> 6;
  4013. s[28] = (s10 >> 14) | (s11 << 7);
  4014. s[29] = s11 >> 1;
  4015. s[30] = s11 >> 9;
  4016. s[31] = s11 >> 17;
  4017. }
  4018. // Input:
  4019. // a[0]+256*a[1]+...+256^31*a[31] = a
  4020. // b[0]+256*b[1]+...+256^31*b[31] = b
  4021. // c[0]+256*c[1]+...+256^31*c[31] = c
  4022. //
  4023. // Output:
  4024. // s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
  4025. // where l = 2^252 + 27742317777372353535851937790883648493.
  4026. static void sc_muladd(uint8_t *s, const uint8_t *a, const uint8_t *b,
  4027. const uint8_t *c) {
  4028. int64_t a0 = 2097151 & load_3(a);
  4029. int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
  4030. int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
  4031. int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
  4032. int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
  4033. int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
  4034. int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
  4035. int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
  4036. int64_t a8 = 2097151 & load_3(a + 21);
  4037. int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
  4038. int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
  4039. int64_t a11 = (load_4(a + 28) >> 7);
  4040. int64_t b0 = 2097151 & load_3(b);
  4041. int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
  4042. int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
  4043. int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
  4044. int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
  4045. int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
  4046. int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
  4047. int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
  4048. int64_t b8 = 2097151 & load_3(b + 21);
  4049. int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
  4050. int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
  4051. int64_t b11 = (load_4(b + 28) >> 7);
  4052. int64_t c0 = 2097151 & load_3(c);
  4053. int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
  4054. int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
  4055. int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
  4056. int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
  4057. int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
  4058. int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
  4059. int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
  4060. int64_t c8 = 2097151 & load_3(c + 21);
  4061. int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
  4062. int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
  4063. int64_t c11 = (load_4(c + 28) >> 7);
  4064. int64_t s0;
  4065. int64_t s1;
  4066. int64_t s2;
  4067. int64_t s3;
  4068. int64_t s4;
  4069. int64_t s5;
  4070. int64_t s6;
  4071. int64_t s7;
  4072. int64_t s8;
  4073. int64_t s9;
  4074. int64_t s10;
  4075. int64_t s11;
  4076. int64_t s12;
  4077. int64_t s13;
  4078. int64_t s14;
  4079. int64_t s15;
  4080. int64_t s16;
  4081. int64_t s17;
  4082. int64_t s18;
  4083. int64_t s19;
  4084. int64_t s20;
  4085. int64_t s21;
  4086. int64_t s22;
  4087. int64_t s23;
  4088. int64_t carry0;
  4089. int64_t carry1;
  4090. int64_t carry2;
  4091. int64_t carry3;
  4092. int64_t carry4;
  4093. int64_t carry5;
  4094. int64_t carry6;
  4095. int64_t carry7;
  4096. int64_t carry8;
  4097. int64_t carry9;
  4098. int64_t carry10;
  4099. int64_t carry11;
  4100. int64_t carry12;
  4101. int64_t carry13;
  4102. int64_t carry14;
  4103. int64_t carry15;
  4104. int64_t carry16;
  4105. int64_t carry17;
  4106. int64_t carry18;
  4107. int64_t carry19;
  4108. int64_t carry20;
  4109. int64_t carry21;
  4110. int64_t carry22;
  4111. s0 = c0 + a0 * b0;
  4112. s1 = c1 + a0 * b1 + a1 * b0;
  4113. s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;
  4114. s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
  4115. s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
  4116. s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
  4117. s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0;
  4118. s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
  4119. a6 * b1 + a7 * b0;
  4120. s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
  4121. a6 * b2 + a7 * b1 + a8 * b0;
  4122. s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
  4123. a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
  4124. s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
  4125. a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
  4126. s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
  4127. a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
  4128. s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 +
  4129. a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
  4130. s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 +
  4131. a9 * b4 + a10 * b3 + a11 * b2;
  4132. s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 +
  4133. a10 * b4 + a11 * b3;
  4134. s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 +
  4135. a11 * b4;
  4136. s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
  4137. s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
  4138. s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
  4139. s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
  4140. s20 = a9 * b11 + a10 * b10 + a11 * b9;
  4141. s21 = a10 * b11 + a11 * b10;
  4142. s22 = a11 * b11;
  4143. s23 = 0;
  4144. carry0 = (s0 + (1 << 20)) >> 21;
  4145. s1 += carry0;
  4146. s0 -= carry0 << 21;
  4147. carry2 = (s2 + (1 << 20)) >> 21;
  4148. s3 += carry2;
  4149. s2 -= carry2 << 21;
  4150. carry4 = (s4 + (1 << 20)) >> 21;
  4151. s5 += carry4;
  4152. s4 -= carry4 << 21;
  4153. carry6 = (s6 + (1 << 20)) >> 21;
  4154. s7 += carry6;
  4155. s6 -= carry6 << 21;
  4156. carry8 = (s8 + (1 << 20)) >> 21;
  4157. s9 += carry8;
  4158. s8 -= carry8 << 21;
  4159. carry10 = (s10 + (1 << 20)) >> 21;
  4160. s11 += carry10;
  4161. s10 -= carry10 << 21;
  4162. carry12 = (s12 + (1 << 20)) >> 21;
  4163. s13 += carry12;
  4164. s12 -= carry12 << 21;
  4165. carry14 = (s14 + (1 << 20)) >> 21;
  4166. s15 += carry14;
  4167. s14 -= carry14 << 21;
  4168. carry16 = (s16 + (1 << 20)) >> 21;
  4169. s17 += carry16;
  4170. s16 -= carry16 << 21;
  4171. carry18 = (s18 + (1 << 20)) >> 21;
  4172. s19 += carry18;
  4173. s18 -= carry18 << 21;
  4174. carry20 = (s20 + (1 << 20)) >> 21;
  4175. s21 += carry20;
  4176. s20 -= carry20 << 21;
  4177. carry22 = (s22 + (1 << 20)) >> 21;
  4178. s23 += carry22;
  4179. s22 -= carry22 << 21;
  4180. carry1 = (s1 + (1 << 20)) >> 21;
  4181. s2 += carry1;
  4182. s1 -= carry1 << 21;
  4183. carry3 = (s3 + (1 << 20)) >> 21;
  4184. s4 += carry3;
  4185. s3 -= carry3 << 21;
  4186. carry5 = (s5 + (1 << 20)) >> 21;
  4187. s6 += carry5;
  4188. s5 -= carry5 << 21;
  4189. carry7 = (s7 + (1 << 20)) >> 21;
  4190. s8 += carry7;
  4191. s7 -= carry7 << 21;
  4192. carry9 = (s9 + (1 << 20)) >> 21;
  4193. s10 += carry9;
  4194. s9 -= carry9 << 21;
  4195. carry11 = (s11 + (1 << 20)) >> 21;
  4196. s12 += carry11;
  4197. s11 -= carry11 << 21;
  4198. carry13 = (s13 + (1 << 20)) >> 21;
  4199. s14 += carry13;
  4200. s13 -= carry13 << 21;
  4201. carry15 = (s15 + (1 << 20)) >> 21;
  4202. s16 += carry15;
  4203. s15 -= carry15 << 21;
  4204. carry17 = (s17 + (1 << 20)) >> 21;
  4205. s18 += carry17;
  4206. s17 -= carry17 << 21;
  4207. carry19 = (s19 + (1 << 20)) >> 21;
  4208. s20 += carry19;
  4209. s19 -= carry19 << 21;
  4210. carry21 = (s21 + (1 << 20)) >> 21;
  4211. s22 += carry21;
  4212. s21 -= carry21 << 21;
  4213. s11 += s23 * 666643;
  4214. s12 += s23 * 470296;
  4215. s13 += s23 * 654183;
  4216. s14 -= s23 * 997805;
  4217. s15 += s23 * 136657;
  4218. s16 -= s23 * 683901;
  4219. s23 = 0;
  4220. s10 += s22 * 666643;
  4221. s11 += s22 * 470296;
  4222. s12 += s22 * 654183;
  4223. s13 -= s22 * 997805;
  4224. s14 += s22 * 136657;
  4225. s15 -= s22 * 683901;
  4226. s22 = 0;
  4227. s9 += s21 * 666643;
  4228. s10 += s21 * 470296;
  4229. s11 += s21 * 654183;
  4230. s12 -= s21 * 997805;
  4231. s13 += s21 * 136657;
  4232. s14 -= s21 * 683901;
  4233. s21 = 0;
  4234. s8 += s20 * 666643;
  4235. s9 += s20 * 470296;
  4236. s10 += s20 * 654183;
  4237. s11 -= s20 * 997805;
  4238. s12 += s20 * 136657;
  4239. s13 -= s20 * 683901;
  4240. s20 = 0;
  4241. s7 += s19 * 666643;
  4242. s8 += s19 * 470296;
  4243. s9 += s19 * 654183;
  4244. s10 -= s19 * 997805;
  4245. s11 += s19 * 136657;
  4246. s12 -= s19 * 683901;
  4247. s19 = 0;
  4248. s6 += s18 * 666643;
  4249. s7 += s18 * 470296;
  4250. s8 += s18 * 654183;
  4251. s9 -= s18 * 997805;
  4252. s10 += s18 * 136657;
  4253. s11 -= s18 * 683901;
  4254. s18 = 0;
  4255. carry6 = (s6 + (1 << 20)) >> 21;
  4256. s7 += carry6;
  4257. s6 -= carry6 << 21;
  4258. carry8 = (s8 + (1 << 20)) >> 21;
  4259. s9 += carry8;
  4260. s8 -= carry8 << 21;
  4261. carry10 = (s10 + (1 << 20)) >> 21;
  4262. s11 += carry10;
  4263. s10 -= carry10 << 21;
  4264. carry12 = (s12 + (1 << 20)) >> 21;
  4265. s13 += carry12;
  4266. s12 -= carry12 << 21;
  4267. carry14 = (s14 + (1 << 20)) >> 21;
  4268. s15 += carry14;
  4269. s14 -= carry14 << 21;
  4270. carry16 = (s16 + (1 << 20)) >> 21;
  4271. s17 += carry16;
  4272. s16 -= carry16 << 21;
  4273. carry7 = (s7 + (1 << 20)) >> 21;
  4274. s8 += carry7;
  4275. s7 -= carry7 << 21;
  4276. carry9 = (s9 + (1 << 20)) >> 21;
  4277. s10 += carry9;
  4278. s9 -= carry9 << 21;
  4279. carry11 = (s11 + (1 << 20)) >> 21;
  4280. s12 += carry11;
  4281. s11 -= carry11 << 21;
  4282. carry13 = (s13 + (1 << 20)) >> 21;
  4283. s14 += carry13;
  4284. s13 -= carry13 << 21;
  4285. carry15 = (s15 + (1 << 20)) >> 21;
  4286. s16 += carry15;
  4287. s15 -= carry15 << 21;
  4288. s5 += s17 * 666643;
  4289. s6 += s17 * 470296;
  4290. s7 += s17 * 654183;
  4291. s8 -= s17 * 997805;
  4292. s9 += s17 * 136657;
  4293. s10 -= s17 * 683901;
  4294. s17 = 0;
  4295. s4 += s16 * 666643;
  4296. s5 += s16 * 470296;
  4297. s6 += s16 * 654183;
  4298. s7 -= s16 * 997805;
  4299. s8 += s16 * 136657;
  4300. s9 -= s16 * 683901;
  4301. s16 = 0;
  4302. s3 += s15 * 666643;
  4303. s4 += s15 * 470296;
  4304. s5 += s15 * 654183;
  4305. s6 -= s15 * 997805;
  4306. s7 += s15 * 136657;
  4307. s8 -= s15 * 683901;
  4308. s15 = 0;
  4309. s2 += s14 * 666643;
  4310. s3 += s14 * 470296;
  4311. s4 += s14 * 654183;
  4312. s5 -= s14 * 997805;
  4313. s6 += s14 * 136657;
  4314. s7 -= s14 * 683901;
  4315. s14 = 0;
  4316. s1 += s13 * 666643;
  4317. s2 += s13 * 470296;
  4318. s3 += s13 * 654183;
  4319. s4 -= s13 * 997805;
  4320. s5 += s13 * 136657;
  4321. s6 -= s13 * 683901;
  4322. s13 = 0;
  4323. s0 += s12 * 666643;
  4324. s1 += s12 * 470296;
  4325. s2 += s12 * 654183;
  4326. s3 -= s12 * 997805;
  4327. s4 += s12 * 136657;
  4328. s5 -= s12 * 683901;
  4329. s12 = 0;
  4330. carry0 = (s0 + (1 << 20)) >> 21;
  4331. s1 += carry0;
  4332. s0 -= carry0 << 21;
  4333. carry2 = (s2 + (1 << 20)) >> 21;
  4334. s3 += carry2;
  4335. s2 -= carry2 << 21;
  4336. carry4 = (s4 + (1 << 20)) >> 21;
  4337. s5 += carry4;
  4338. s4 -= carry4 << 21;
  4339. carry6 = (s6 + (1 << 20)) >> 21;
  4340. s7 += carry6;
  4341. s6 -= carry6 << 21;
  4342. carry8 = (s8 + (1 << 20)) >> 21;
  4343. s9 += carry8;
  4344. s8 -= carry8 << 21;
  4345. carry10 = (s10 + (1 << 20)) >> 21;
  4346. s11 += carry10;
  4347. s10 -= carry10 << 21;
  4348. carry1 = (s1 + (1 << 20)) >> 21;
  4349. s2 += carry1;
  4350. s1 -= carry1 << 21;
  4351. carry3 = (s3 + (1 << 20)) >> 21;
  4352. s4 += carry3;
  4353. s3 -= carry3 << 21;
  4354. carry5 = (s5 + (1 << 20)) >> 21;
  4355. s6 += carry5;
  4356. s5 -= carry5 << 21;
  4357. carry7 = (s7 + (1 << 20)) >> 21;
  4358. s8 += carry7;
  4359. s7 -= carry7 << 21;
  4360. carry9 = (s9 + (1 << 20)) >> 21;
  4361. s10 += carry9;
  4362. s9 -= carry9 << 21;
  4363. carry11 = (s11 + (1 << 20)) >> 21;
  4364. s12 += carry11;
  4365. s11 -= carry11 << 21;
  4366. s0 += s12 * 666643;
  4367. s1 += s12 * 470296;
  4368. s2 += s12 * 654183;
  4369. s3 -= s12 * 997805;
  4370. s4 += s12 * 136657;
  4371. s5 -= s12 * 683901;
  4372. s12 = 0;
  4373. carry0 = s0 >> 21;
  4374. s1 += carry0;
  4375. s0 -= carry0 << 21;
  4376. carry1 = s1 >> 21;
  4377. s2 += carry1;
  4378. s1 -= carry1 << 21;
  4379. carry2 = s2 >> 21;
  4380. s3 += carry2;
  4381. s2 -= carry2 << 21;
  4382. carry3 = s3 >> 21;
  4383. s4 += carry3;
  4384. s3 -= carry3 << 21;
  4385. carry4 = s4 >> 21;
  4386. s5 += carry4;
  4387. s4 -= carry4 << 21;
  4388. carry5 = s5 >> 21;
  4389. s6 += carry5;
  4390. s5 -= carry5 << 21;
  4391. carry6 = s6 >> 21;
  4392. s7 += carry6;
  4393. s6 -= carry6 << 21;
  4394. carry7 = s7 >> 21;
  4395. s8 += carry7;
  4396. s7 -= carry7 << 21;
  4397. carry8 = s8 >> 21;
  4398. s9 += carry8;
  4399. s8 -= carry8 << 21;
  4400. carry9 = s9 >> 21;
  4401. s10 += carry9;
  4402. s9 -= carry9 << 21;
  4403. carry10 = s10 >> 21;
  4404. s11 += carry10;
  4405. s10 -= carry10 << 21;
  4406. carry11 = s11 >> 21;
  4407. s12 += carry11;
  4408. s11 -= carry11 << 21;
  4409. s0 += s12 * 666643;
  4410. s1 += s12 * 470296;
  4411. s2 += s12 * 654183;
  4412. s3 -= s12 * 997805;
  4413. s4 += s12 * 136657;
  4414. s5 -= s12 * 683901;
  4415. s12 = 0;
  4416. carry0 = s0 >> 21;
  4417. s1 += carry0;
  4418. s0 -= carry0 << 21;
  4419. carry1 = s1 >> 21;
  4420. s2 += carry1;
  4421. s1 -= carry1 << 21;
  4422. carry2 = s2 >> 21;
  4423. s3 += carry2;
  4424. s2 -= carry2 << 21;
  4425. carry3 = s3 >> 21;
  4426. s4 += carry3;
  4427. s3 -= carry3 << 21;
  4428. carry4 = s4 >> 21;
  4429. s5 += carry4;
  4430. s4 -= carry4 << 21;
  4431. carry5 = s5 >> 21;
  4432. s6 += carry5;
  4433. s5 -= carry5 << 21;
  4434. carry6 = s6 >> 21;
  4435. s7 += carry6;
  4436. s6 -= carry6 << 21;
  4437. carry7 = s7 >> 21;
  4438. s8 += carry7;
  4439. s7 -= carry7 << 21;
  4440. carry8 = s8 >> 21;
  4441. s9 += carry8;
  4442. s8 -= carry8 << 21;
  4443. carry9 = s9 >> 21;
  4444. s10 += carry9;
  4445. s9 -= carry9 << 21;
  4446. carry10 = s10 >> 21;
  4447. s11 += carry10;
  4448. s10 -= carry10 << 21;
  4449. s[0] = s0 >> 0;
  4450. s[1] = s0 >> 8;
  4451. s[2] = (s0 >> 16) | (s1 << 5);
  4452. s[3] = s1 >> 3;
  4453. s[4] = s1 >> 11;
  4454. s[5] = (s1 >> 19) | (s2 << 2);
  4455. s[6] = s2 >> 6;
  4456. s[7] = (s2 >> 14) | (s3 << 7);
  4457. s[8] = s3 >> 1;
  4458. s[9] = s3 >> 9;
  4459. s[10] = (s3 >> 17) | (s4 << 4);
  4460. s[11] = s4 >> 4;
  4461. s[12] = s4 >> 12;
  4462. s[13] = (s4 >> 20) | (s5 << 1);
  4463. s[14] = s5 >> 7;
  4464. s[15] = (s5 >> 15) | (s6 << 6);
  4465. s[16] = s6 >> 2;
  4466. s[17] = s6 >> 10;
  4467. s[18] = (s6 >> 18) | (s7 << 3);
  4468. s[19] = s7 >> 5;
  4469. s[20] = s7 >> 13;
  4470. s[21] = s8 >> 0;
  4471. s[22] = s8 >> 8;
  4472. s[23] = (s8 >> 16) | (s9 << 5);
  4473. s[24] = s9 >> 3;
  4474. s[25] = s9 >> 11;
  4475. s[26] = (s9 >> 19) | (s10 << 2);
  4476. s[27] = s10 >> 6;
  4477. s[28] = (s10 >> 14) | (s11 << 7);
  4478. s[29] = s11 >> 1;
  4479. s[30] = s11 >> 9;
  4480. s[31] = s11 >> 17;
  4481. }
  4482. void ED25519_keypair(uint8_t out_public_key[32], uint8_t out_private_key[64]) {
  4483. uint8_t seed[32];
  4484. RAND_bytes(seed, 32);
  4485. ED25519_keypair_from_seed(out_public_key, out_private_key, seed);
  4486. }
  4487. int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,
  4488. const uint8_t private_key[64]) {
  4489. uint8_t az[SHA512_DIGEST_LENGTH];
  4490. SHA512(private_key, 32, az);
  4491. az[0] &= 248;
  4492. az[31] &= 63;
  4493. az[31] |= 64;
  4494. SHA512_CTX hash_ctx;
  4495. SHA512_Init(&hash_ctx);
  4496. SHA512_Update(&hash_ctx, az + 32, 32);
  4497. SHA512_Update(&hash_ctx, message, message_len);
  4498. uint8_t nonce[SHA512_DIGEST_LENGTH];
  4499. SHA512_Final(nonce, &hash_ctx);
  4500. x25519_sc_reduce(nonce);
  4501. ge_p3 R;
  4502. x25519_ge_scalarmult_base(&R, nonce);
  4503. ge_p3_tobytes(out_sig, &R);
  4504. SHA512_Init(&hash_ctx);
  4505. SHA512_Update(&hash_ctx, out_sig, 32);
  4506. SHA512_Update(&hash_ctx, private_key + 32, 32);
  4507. SHA512_Update(&hash_ctx, message, message_len);
  4508. uint8_t hram[SHA512_DIGEST_LENGTH];
  4509. SHA512_Final(hram, &hash_ctx);
  4510. x25519_sc_reduce(hram);
  4511. sc_muladd(out_sig + 32, hram, az, nonce);
  4512. return 1;
  4513. }
  4514. int ED25519_verify(const uint8_t *message, size_t message_len,
  4515. const uint8_t signature[64], const uint8_t public_key[32]) {
  4516. ge_p3 A;
  4517. if ((signature[63] & 224) != 0 ||
  4518. x25519_ge_frombytes_vartime(&A, public_key) != 0) {
  4519. return 0;
  4520. }
  4521. fe_loose t;
  4522. fe_neg(&t, &A.X);
  4523. fe_carry(&A.X, &t);
  4524. fe_neg(&t, &A.T);
  4525. fe_carry(&A.T, &t);
  4526. uint8_t pkcopy[32];
  4527. OPENSSL_memcpy(pkcopy, public_key, 32);
  4528. uint8_t rcopy[32];
  4529. OPENSSL_memcpy(rcopy, signature, 32);
  4530. uint8_t scopy[32];
  4531. OPENSSL_memcpy(scopy, signature + 32, 32);
  4532. SHA512_CTX hash_ctx;
  4533. SHA512_Init(&hash_ctx);
  4534. SHA512_Update(&hash_ctx, signature, 32);
  4535. SHA512_Update(&hash_ctx, public_key, 32);
  4536. SHA512_Update(&hash_ctx, message, message_len);
  4537. uint8_t h[SHA512_DIGEST_LENGTH];
  4538. SHA512_Final(h, &hash_ctx);
  4539. x25519_sc_reduce(h);
  4540. ge_p2 R;
  4541. ge_double_scalarmult_vartime(&R, h, &A, scopy);
  4542. uint8_t rcheck[32];
  4543. x25519_ge_tobytes(rcheck, &R);
  4544. return CRYPTO_memcmp(rcheck, rcopy, sizeof(rcheck)) == 0;
  4545. }
  4546. void ED25519_keypair_from_seed(uint8_t out_public_key[32],
  4547. uint8_t out_private_key[64],
  4548. const uint8_t seed[32]) {
  4549. uint8_t az[SHA512_DIGEST_LENGTH];
  4550. SHA512(seed, 32, az);
  4551. az[0] &= 248;
  4552. az[31] &= 63;
  4553. az[31] |= 64;
  4554. ge_p3 A;
  4555. x25519_ge_scalarmult_base(&A, az);
  4556. ge_p3_tobytes(out_public_key, &A);
  4557. OPENSSL_memcpy(out_private_key, seed, 32);
  4558. OPENSSL_memcpy(out_private_key + 32, out_public_key, 32);
  4559. }
  4560. #if defined(BORINGSSL_X25519_X86_64)
  4561. static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
  4562. const uint8_t point[32]) {
  4563. x25519_x86_64(out, scalar, point);
  4564. }
  4565. #else
  4566. // Replace (f,g) with (g,f) if b == 1;
  4567. // replace (f,g) with (f,g) if b == 0.
  4568. //
  4569. // Preconditions: b in {0,1}.
  4570. static void fe_cswap(fe *f, fe *g, unsigned int b) {
  4571. b = 0-b;
  4572. unsigned i;
  4573. for (i = 0; i < 10; i++) {
  4574. uint32_t x = f->v[i] ^ g->v[i];
  4575. x &= b;
  4576. f->v[i] ^= x;
  4577. g->v[i] ^= x;
  4578. }
  4579. }
  4580. // NOTE: based on fiat-crypto fe_mul, edited for in2=121666, 0, 0..
  4581. static void fe_mul_121666_impl(uint32_t out[10], const uint32_t in1[10]) {
  4582. assert_fe_loose(in1);
  4583. { const uint32_t x20 = in1[9];
  4584. { const uint32_t x21 = in1[8];
  4585. { const uint32_t x19 = in1[7];
  4586. { const uint32_t x17 = in1[6];
  4587. { const uint32_t x15 = in1[5];
  4588. { const uint32_t x13 = in1[4];
  4589. { const uint32_t x11 = in1[3];
  4590. { const uint32_t x9 = in1[2];
  4591. { const uint32_t x7 = in1[1];
  4592. { const uint32_t x5 = in1[0];
  4593. { const uint32_t x38 = 0;
  4594. { const uint32_t x39 = 0;
  4595. { const uint32_t x37 = 0;
  4596. { const uint32_t x35 = 0;
  4597. { const uint32_t x33 = 0;
  4598. { const uint32_t x31 = 0;
  4599. { const uint32_t x29 = 0;
  4600. { const uint32_t x27 = 0;
  4601. { const uint32_t x25 = 0;
  4602. { const uint32_t x23 = 121666;
  4603. { uint64_t x40 = ((uint64_t)x23 * x5);
  4604. { uint64_t x41 = (((uint64_t)x23 * x7) + ((uint64_t)x25 * x5));
  4605. { uint64_t x42 = ((((uint64_t)(0x2 * x25) * x7) + ((uint64_t)x23 * x9)) + ((uint64_t)x27 * x5));
  4606. { uint64_t x43 = (((((uint64_t)x25 * x9) + ((uint64_t)x27 * x7)) + ((uint64_t)x23 * x11)) + ((uint64_t)x29 * x5));
  4607. { uint64_t x44 = (((((uint64_t)x27 * x9) + (0x2 * (((uint64_t)x25 * x11) + ((uint64_t)x29 * x7)))) + ((uint64_t)x23 * x13)) + ((uint64_t)x31 * x5));
  4608. { uint64_t x45 = (((((((uint64_t)x27 * x11) + ((uint64_t)x29 * x9)) + ((uint64_t)x25 * x13)) + ((uint64_t)x31 * x7)) + ((uint64_t)x23 * x15)) + ((uint64_t)x33 * x5));
  4609. { uint64_t x46 = (((((0x2 * ((((uint64_t)x29 * x11) + ((uint64_t)x25 * x15)) + ((uint64_t)x33 * x7))) + ((uint64_t)x27 * x13)) + ((uint64_t)x31 * x9)) + ((uint64_t)x23 * x17)) + ((uint64_t)x35 * x5));
  4610. { uint64_t x47 = (((((((((uint64_t)x29 * x13) + ((uint64_t)x31 * x11)) + ((uint64_t)x27 * x15)) + ((uint64_t)x33 * x9)) + ((uint64_t)x25 * x17)) + ((uint64_t)x35 * x7)) + ((uint64_t)x23 * x19)) + ((uint64_t)x37 * x5));
  4611. { uint64_t x48 = (((((((uint64_t)x31 * x13) + (0x2 * (((((uint64_t)x29 * x15) + ((uint64_t)x33 * x11)) + ((uint64_t)x25 * x19)) + ((uint64_t)x37 * x7)))) + ((uint64_t)x27 * x17)) + ((uint64_t)x35 * x9)) + ((uint64_t)x23 * x21)) + ((uint64_t)x39 * x5));
  4612. { uint64_t x49 = (((((((((((uint64_t)x31 * x15) + ((uint64_t)x33 * x13)) + ((uint64_t)x29 * x17)) + ((uint64_t)x35 * x11)) + ((uint64_t)x27 * x19)) + ((uint64_t)x37 * x9)) + ((uint64_t)x25 * x21)) + ((uint64_t)x39 * x7)) + ((uint64_t)x23 * x20)) + ((uint64_t)x38 * x5));
  4613. { uint64_t x50 = (((((0x2 * ((((((uint64_t)x33 * x15) + ((uint64_t)x29 * x19)) + ((uint64_t)x37 * x11)) + ((uint64_t)x25 * x20)) + ((uint64_t)x38 * x7))) + ((uint64_t)x31 * x17)) + ((uint64_t)x35 * x13)) + ((uint64_t)x27 * x21)) + ((uint64_t)x39 * x9));
  4614. { uint64_t x51 = (((((((((uint64_t)x33 * x17) + ((uint64_t)x35 * x15)) + ((uint64_t)x31 * x19)) + ((uint64_t)x37 * x13)) + ((uint64_t)x29 * x21)) + ((uint64_t)x39 * x11)) + ((uint64_t)x27 * x20)) + ((uint64_t)x38 * x9));
  4615. { uint64_t x52 = (((((uint64_t)x35 * x17) + (0x2 * (((((uint64_t)x33 * x19) + ((uint64_t)x37 * x15)) + ((uint64_t)x29 * x20)) + ((uint64_t)x38 * x11)))) + ((uint64_t)x31 * x21)) + ((uint64_t)x39 * x13));
  4616. { uint64_t x53 = (((((((uint64_t)x35 * x19) + ((uint64_t)x37 * x17)) + ((uint64_t)x33 * x21)) + ((uint64_t)x39 * x15)) + ((uint64_t)x31 * x20)) + ((uint64_t)x38 * x13));
  4617. { uint64_t x54 = (((0x2 * ((((uint64_t)x37 * x19) + ((uint64_t)x33 * x20)) + ((uint64_t)x38 * x15))) + ((uint64_t)x35 * x21)) + ((uint64_t)x39 * x17));
  4618. { uint64_t x55 = (((((uint64_t)x37 * x21) + ((uint64_t)x39 * x19)) + ((uint64_t)x35 * x20)) + ((uint64_t)x38 * x17));
  4619. { uint64_t x56 = (((uint64_t)x39 * x21) + (0x2 * (((uint64_t)x37 * x20) + ((uint64_t)x38 * x19))));
  4620. { uint64_t x57 = (((uint64_t)x39 * x20) + ((uint64_t)x38 * x21));
  4621. { uint64_t x58 = ((uint64_t)(0x2 * x38) * x20);
  4622. { uint64_t x59 = (x48 + (x58 << 0x4));
  4623. { uint64_t x60 = (x59 + (x58 << 0x1));
  4624. { uint64_t x61 = (x60 + x58);
  4625. { uint64_t x62 = (x47 + (x57 << 0x4));
  4626. { uint64_t x63 = (x62 + (x57 << 0x1));
  4627. { uint64_t x64 = (x63 + x57);
  4628. { uint64_t x65 = (x46 + (x56 << 0x4));
  4629. { uint64_t x66 = (x65 + (x56 << 0x1));
  4630. { uint64_t x67 = (x66 + x56);
  4631. { uint64_t x68 = (x45 + (x55 << 0x4));
  4632. { uint64_t x69 = (x68 + (x55 << 0x1));
  4633. { uint64_t x70 = (x69 + x55);
  4634. { uint64_t x71 = (x44 + (x54 << 0x4));
  4635. { uint64_t x72 = (x71 + (x54 << 0x1));
  4636. { uint64_t x73 = (x72 + x54);
  4637. { uint64_t x74 = (x43 + (x53 << 0x4));
  4638. { uint64_t x75 = (x74 + (x53 << 0x1));
  4639. { uint64_t x76 = (x75 + x53);
  4640. { uint64_t x77 = (x42 + (x52 << 0x4));
  4641. { uint64_t x78 = (x77 + (x52 << 0x1));
  4642. { uint64_t x79 = (x78 + x52);
  4643. { uint64_t x80 = (x41 + (x51 << 0x4));
  4644. { uint64_t x81 = (x80 + (x51 << 0x1));
  4645. { uint64_t x82 = (x81 + x51);
  4646. { uint64_t x83 = (x40 + (x50 << 0x4));
  4647. { uint64_t x84 = (x83 + (x50 << 0x1));
  4648. { uint64_t x85 = (x84 + x50);
  4649. { uint64_t x86 = (x85 >> 0x1a);
  4650. { uint32_t x87 = ((uint32_t)x85 & 0x3ffffff);
  4651. { uint64_t x88 = (x86 + x82);
  4652. { uint64_t x89 = (x88 >> 0x19);
  4653. { uint32_t x90 = ((uint32_t)x88 & 0x1ffffff);
  4654. { uint64_t x91 = (x89 + x79);
  4655. { uint64_t x92 = (x91 >> 0x1a);
  4656. { uint32_t x93 = ((uint32_t)x91 & 0x3ffffff);
  4657. { uint64_t x94 = (x92 + x76);
  4658. { uint64_t x95 = (x94 >> 0x19);
  4659. { uint32_t x96 = ((uint32_t)x94 & 0x1ffffff);
  4660. { uint64_t x97 = (x95 + x73);
  4661. { uint64_t x98 = (x97 >> 0x1a);
  4662. { uint32_t x99 = ((uint32_t)x97 & 0x3ffffff);
  4663. { uint64_t x100 = (x98 + x70);
  4664. { uint64_t x101 = (x100 >> 0x19);
  4665. { uint32_t x102 = ((uint32_t)x100 & 0x1ffffff);
  4666. { uint64_t x103 = (x101 + x67);
  4667. { uint64_t x104 = (x103 >> 0x1a);
  4668. { uint32_t x105 = ((uint32_t)x103 & 0x3ffffff);
  4669. { uint64_t x106 = (x104 + x64);
  4670. { uint64_t x107 = (x106 >> 0x19);
  4671. { uint32_t x108 = ((uint32_t)x106 & 0x1ffffff);
  4672. { uint64_t x109 = (x107 + x61);
  4673. { uint64_t x110 = (x109 >> 0x1a);
  4674. { uint32_t x111 = ((uint32_t)x109 & 0x3ffffff);
  4675. { uint64_t x112 = (x110 + x49);
  4676. { uint64_t x113 = (x112 >> 0x19);
  4677. { uint32_t x114 = ((uint32_t)x112 & 0x1ffffff);
  4678. { uint64_t x115 = (x87 + (0x13 * x113));
  4679. { uint32_t x116 = (uint32_t) (x115 >> 0x1a);
  4680. { uint32_t x117 = ((uint32_t)x115 & 0x3ffffff);
  4681. { uint32_t x118 = (x116 + x90);
  4682. { uint32_t x119 = (x118 >> 0x19);
  4683. { uint32_t x120 = (x118 & 0x1ffffff);
  4684. out[0] = x117;
  4685. out[1] = x120;
  4686. out[2] = (x119 + x93);
  4687. out[3] = x96;
  4688. out[4] = x99;
  4689. out[5] = x102;
  4690. out[6] = x105;
  4691. out[7] = x108;
  4692. out[8] = x111;
  4693. out[9] = x114;
  4694. }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
  4695. assert_fe(out);
  4696. }
  4697. static void fe_mul121666(fe *h, const fe_loose *f) {
  4698. assert_fe_loose(f->v);
  4699. fe_mul_121666_impl(h->v, f->v);
  4700. assert_fe(h->v);
  4701. }
  4702. static void x25519_scalar_mult_generic(uint8_t out[32],
  4703. const uint8_t scalar[32],
  4704. const uint8_t point[32]) {
  4705. fe x1, x2, z2, x3, z3, tmp0, tmp1;
  4706. fe_loose x2l, z2l, x3l, tmp0l, tmp1l;
  4707. uint8_t e[32];
  4708. OPENSSL_memcpy(e, scalar, 32);
  4709. e[0] &= 248;
  4710. e[31] &= 127;
  4711. e[31] |= 64;
  4712. fe_frombytes(&x1, point);
  4713. fe_1(&x2);
  4714. fe_0(&z2);
  4715. fe_copy(&x3, &x1);
  4716. fe_1(&z3);
  4717. unsigned swap = 0;
  4718. int pos;
  4719. for (pos = 254; pos >= 0; --pos) {
  4720. unsigned b = 1 & (e[pos / 8] >> (pos & 7));
  4721. swap ^= b;
  4722. fe_cswap(&x2, &x3, swap);
  4723. fe_cswap(&z2, &z3, swap);
  4724. swap = b;
  4725. fe_sub(&tmp0l, &x3, &z3);
  4726. fe_sub(&tmp1l, &x2, &z2);
  4727. fe_add(&x2l, &x2, &z2);
  4728. fe_add(&z2l, &x3, &z3);
  4729. fe_mul_tll(&z3, &tmp0l, &x2l);
  4730. fe_mul_tll(&z2, &z2l, &tmp1l);
  4731. fe_sq_tl(&tmp0, &tmp1l);
  4732. fe_sq_tl(&tmp1, &x2l);
  4733. fe_add(&x3l, &z3, &z2);
  4734. fe_sub(&z2l, &z3, &z2);
  4735. fe_mul_ttt(&x2, &tmp1, &tmp0);
  4736. fe_sub(&tmp1l, &tmp1, &tmp0);
  4737. fe_sq_tl(&z2, &z2l);
  4738. fe_mul121666(&z3, &tmp1l);
  4739. fe_sq_tl(&x3, &x3l);
  4740. fe_add(&tmp0l, &tmp0, &z3);
  4741. fe_mul_ttt(&z3, &x1, &z2);
  4742. fe_mul_tll(&z2, &tmp1l, &tmp0l);
  4743. }
  4744. fe_cswap(&x2, &x3, swap);
  4745. fe_cswap(&z2, &z3, swap);
  4746. fe_invert(&z2, &z2);
  4747. fe_mul_ttt(&x2, &x2, &z2);
  4748. fe_tobytes(out, &x2);
  4749. }
  4750. static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
  4751. const uint8_t point[32]) {
  4752. #if defined(BORINGSSL_X25519_NEON)
  4753. if (CRYPTO_is_NEON_capable()) {
  4754. x25519_NEON(out, scalar, point);
  4755. return;
  4756. }
  4757. #endif
  4758. x25519_scalar_mult_generic(out, scalar, point);
  4759. }
  4760. #endif // BORINGSSL_X25519_X86_64
  4761. void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]) {
  4762. RAND_bytes(out_private_key, 32);
  4763. // All X25519 implementations should decode scalars correctly (see
  4764. // https://tools.ietf.org/html/rfc7748#section-5). However, if an
  4765. // implementation doesn't then it might interoperate with random keys a
  4766. // fraction of the time because they'll, randomly, happen to be correctly
  4767. // formed.
  4768. //
  4769. // Thus we do the opposite of the masking here to make sure that our private
  4770. // keys are never correctly masked and so, hopefully, any incorrect
  4771. // implementations are deterministically broken.
  4772. //
  4773. // This does not affect security because, although we're throwing away
  4774. // entropy, a valid implementation of scalarmult should throw away the exact
  4775. // same bits anyway.
  4776. out_private_key[0] |= 7;
  4777. out_private_key[31] &= 63;
  4778. out_private_key[31] |= 128;
  4779. X25519_public_from_private(out_public_value, out_private_key);
  4780. }
  4781. int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
  4782. const uint8_t peer_public_value[32]) {
  4783. static const uint8_t kZeros[32] = {0};
  4784. x25519_scalar_mult(out_shared_key, private_key, peer_public_value);
  4785. // The all-zero output results when the input is a point of small order.
  4786. return CRYPTO_memcmp(kZeros, out_shared_key, 32) != 0;
  4787. }
  4788. #if defined(BORINGSSL_X25519_X86_64)
  4789. // When |BORINGSSL_X25519_X86_64| is set, base point multiplication is done with
  4790. // the Montgomery ladder because it's faster. Otherwise it's done using the
  4791. // Ed25519 tables.
  4792. void X25519_public_from_private(uint8_t out_public_value[32],
  4793. const uint8_t private_key[32]) {
  4794. static const uint8_t kMongomeryBasePoint[32] = {9};
  4795. x25519_scalar_mult(out_public_value, private_key, kMongomeryBasePoint);
  4796. }
  4797. #else
  4798. void X25519_public_from_private(uint8_t out_public_value[32],
  4799. const uint8_t private_key[32]) {
  4800. #if defined(BORINGSSL_X25519_NEON)
  4801. if (CRYPTO_is_NEON_capable()) {
  4802. static const uint8_t kMongomeryBasePoint[32] = {9};
  4803. x25519_NEON(out_public_value, private_key, kMongomeryBasePoint);
  4804. return;
  4805. }
  4806. #endif
  4807. uint8_t e[32];
  4808. OPENSSL_memcpy(e, private_key, 32);
  4809. e[0] &= 248;
  4810. e[31] &= 127;
  4811. e[31] |= 64;
  4812. ge_p3 A;
  4813. x25519_ge_scalarmult_base(&A, e);
  4814. // We only need the u-coordinate of the curve25519 point. The map is
  4815. // u=(y+1)/(1-y). Since y=Y/Z, this gives u=(Z+Y)/(Z-Y).
  4816. fe_loose zplusy, zminusy;
  4817. fe zminusy_inv;
  4818. fe_add(&zplusy, &A.Z, &A.Y);
  4819. fe_sub(&zminusy, &A.Z, &A.Y);
  4820. fe_loose_invert(&zminusy_inv, &zminusy);
  4821. fe_mul_tlt(&zminusy_inv, &zplusy, &zminusy_inv);
  4822. fe_tobytes(out_public_value, &zminusy_inv);
  4823. }
  4824. #endif // BORINGSSL_X25519_X86_64