sp_c64.c 1.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487
  1. /* sp.c
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* Implementation by Sean Parkinson. */
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25. #include <wolfssl/wolfcrypt/settings.h>
  26. #if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH) || \
  27. defined(WOLFSSL_HAVE_SP_ECC)
  28. #include <wolfssl/wolfcrypt/error-crypt.h>
  29. #include <wolfssl/wolfcrypt/cpuid.h>
  30. #ifdef NO_INLINE
  31. #include <wolfssl/wolfcrypt/misc.h>
  32. #else
  33. #define WOLFSSL_MISC_INCLUDED
  34. #include <wolfcrypt/src/misc.c>
  35. #endif
  36. #ifdef RSA_LOW_MEM
  37. #ifndef SP_RSA_PRIVATE_EXP_D
  38. #define SP_RSA_PRIVATE_EXP_D
  39. #endif
  40. #ifndef WOLFSSL_SP_SMALL
  41. #define WOLFSSL_SP_SMALL
  42. #endif
  43. #endif
  44. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
  45. #undef WOLFSSL_SP_SMALL_STACK
  46. #define WOLFSSL_SP_SMALL_STACK
  47. #endif
  48. #include <wolfssl/wolfcrypt/sp.h>
  49. #ifdef __IAR_SYSTEMS_ICC__
  50. #define __asm__ asm
  51. #define __volatile__ volatile
  52. #endif /* __IAR_SYSTEMS_ICC__ */
  53. #ifdef __KEIL__
  54. #define __asm__ __asm
  55. #define __volatile__ volatile
  56. #endif
  57. #ifndef WOLFSSL_SP_ASM
  58. #if SP_WORD_SIZE == 64
  59. #define SP_PRINT_NUM(var, name, total, words, bits) \
  60. do { \
  61. int ii; \
  62. byte nb[(bits + 7) / 8]; \
  63. sp_digit _s[words]; \
  64. XMEMCPY(_s, var, sizeof(_s)); \
  65. sp_##total##_norm_##words(_s); \
  66. sp_##total##_to_bin_##words(_s, nb); \
  67. fprintf(stderr, name "=0x"); \
  68. for (ii=0; ii<(bits + 7) / 8; ii++) \
  69. fprintf(stderr, "%02x", nb[ii]); \
  70. fprintf(stderr, "\n"); \
  71. } while (0)
  72. #define SP_PRINT_VAL(var, name) \
  73. fprintf(stderr, name "=0x" SP_PRINT_FMT "\n", var)
  74. #define SP_PRINT_INT(var, name) \
  75. fprintf(stderr, name "=%d\n", var)
  76. #if ((defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH)) && \
  77. ((!defined(WC_NO_CACHE_RESISTANT) && \
  78. (defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH))) || \
  79. (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP))) && \
  80. !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || (defined(WOLFSSL_SP_SMALL) && \
  81. defined(WOLFSSL_HAVE_SP_ECC) && (!defined(WOLFSSL_SP_NO_256) || \
  82. defined(WOLFSSL_SP_384) || defined(WOLFSSL_SP_521) || \
  83. defined(WOLFSSL_SP_1024)))
  84. /* Mask for address to obfuscate which of the two address will be used. */
  85. static const size_t addr_mask[2] = { 0, (size_t)-1 };
  86. #endif
  87. #if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || \
  88. !defined(WOLFSSL_SP_SMALL))
  89. #error SP non-blocking requires small and no-malloc (WOLFSSL_SP_SMALL and WOLFSSL_SP_NO_MALLOC)
  90. #endif
  91. #if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH)
  92. #ifndef WOLFSSL_SP_NO_2048
  93. #ifdef WOLFSSL_SP_SMALL
  94. /* Read big endian unsigned byte array into r.
  95. *
  96. * r A single precision integer.
  97. * size Maximum number of bytes to convert
  98. * a Byte array.
  99. * n Number of bytes in array to read.
  100. */
  101. static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n)
  102. {
  103. int i;
  104. int j = 0;
  105. word32 s = 0;
  106. r[0] = 0;
  107. for (i = n-1; i >= 0; i--) {
  108. r[j] |= (((sp_digit)a[i]) << s);
  109. if (s >= 53U) {
  110. r[j] &= 0x1fffffffffffffffL;
  111. s = 61U - s;
  112. if (j + 1 >= size) {
  113. break;
  114. }
  115. r[++j] = (sp_digit)a[i] >> s;
  116. s = 8U - s;
  117. }
  118. else {
  119. s += 8U;
  120. }
  121. }
  122. for (j++; j < size; j++) {
  123. r[j] = 0;
  124. }
  125. }
  126. /* Convert an mp_int to an array of sp_digit.
  127. *
  128. * r A single precision integer.
  129. * size Maximum number of bytes to convert
  130. * a A multi-precision integer.
  131. */
  132. static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a)
  133. {
  134. #if DIGIT_BIT == 61
  135. int i;
  136. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  137. int o = 0;
  138. for (i = 0; i < size; i++) {
  139. sp_digit mask = (sp_digit)0 - (j >> 60);
  140. r[i] = a->dp[o] & mask;
  141. j++;
  142. o += (int)(j >> 60);
  143. }
  144. #elif DIGIT_BIT > 61
  145. unsigned int i;
  146. int j = 0;
  147. word32 s = 0;
  148. r[0] = 0;
  149. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  150. r[j] |= ((sp_digit)a->dp[i] << s);
  151. r[j] &= 0x1fffffffffffffffL;
  152. s = 61U - s;
  153. if (j + 1 >= size) {
  154. break;
  155. }
  156. /* lint allow cast of mismatch word32 and mp_digit */
  157. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  158. while ((s + 61U) <= (word32)DIGIT_BIT) {
  159. s += 61U;
  160. r[j] &= 0x1fffffffffffffffL;
  161. if (j + 1 >= size) {
  162. break;
  163. }
  164. if (s < (word32)DIGIT_BIT) {
  165. /* lint allow cast of mismatch word32 and mp_digit */
  166. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  167. }
  168. else {
  169. r[++j] = (sp_digit)0;
  170. }
  171. }
  172. s = (word32)DIGIT_BIT - s;
  173. }
  174. for (j++; j < size; j++) {
  175. r[j] = 0;
  176. }
  177. #else
  178. unsigned int i;
  179. int j = 0;
  180. int s = 0;
  181. r[0] = 0;
  182. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  183. r[j] |= ((sp_digit)a->dp[i]) << s;
  184. if (s + DIGIT_BIT >= 61) {
  185. r[j] &= 0x1fffffffffffffffL;
  186. if (j + 1 >= size) {
  187. break;
  188. }
  189. s = 61 - s;
  190. if (s == DIGIT_BIT) {
  191. r[++j] = 0;
  192. s = 0;
  193. }
  194. else {
  195. r[++j] = a->dp[i] >> s;
  196. s = DIGIT_BIT - s;
  197. }
  198. }
  199. else {
  200. s += DIGIT_BIT;
  201. }
  202. }
  203. for (j++; j < size; j++) {
  204. r[j] = 0;
  205. }
  206. #endif
  207. }
  208. /* Write r as big endian to byte array.
  209. * Fixed length number of bytes written: 256
  210. *
  211. * r A single precision integer.
  212. * a Byte array.
  213. */
  214. static void sp_2048_to_bin_34(sp_digit* r, byte* a)
  215. {
  216. int i;
  217. int j;
  218. int s = 0;
  219. int b;
  220. for (i=0; i<33; i++) {
  221. r[i+1] += r[i] >> 61;
  222. r[i] &= 0x1fffffffffffffffL;
  223. }
  224. j = 2055 / 8 - 1;
  225. a[j] = 0;
  226. for (i=0; i<34 && j>=0; i++) {
  227. b = 0;
  228. /* lint allow cast of mismatch sp_digit and int */
  229. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  230. b += 8 - s;
  231. if (j < 0) {
  232. break;
  233. }
  234. while (b < 61) {
  235. a[j--] = (byte)(r[i] >> b);
  236. b += 8;
  237. if (j < 0) {
  238. break;
  239. }
  240. }
  241. s = 8 - (b - 61);
  242. if (j >= 0) {
  243. a[j] = 0;
  244. }
  245. if (s != 0) {
  246. j++;
  247. }
  248. }
  249. }
  250. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  251. /* Normalize the values in each word to 61 bits.
  252. *
  253. * a Array of sp_digit to normalize.
  254. */
  255. static void sp_2048_norm_17(sp_digit* a)
  256. {
  257. int i;
  258. for (i = 0; i < 16; i++) {
  259. a[i+1] += a[i] >> 61;
  260. a[i] &= 0x1fffffffffffffffL;
  261. }
  262. }
  263. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  264. /* Normalize the values in each word to 61 bits.
  265. *
  266. * a Array of sp_digit to normalize.
  267. */
  268. static void sp_2048_norm_34(sp_digit* a)
  269. {
  270. int i;
  271. for (i = 0; i < 33; i++) {
  272. a[i+1] += a[i] >> 61;
  273. a[i] &= 0x1fffffffffffffffL;
  274. }
  275. }
  276. /* Multiply a and b into r. (r = a * b)
  277. *
  278. * r A single precision integer.
  279. * a A single precision integer.
  280. * b A single precision integer.
  281. */
  282. SP_NOINLINE static void sp_2048_mul_34(sp_digit* r, const sp_digit* a,
  283. const sp_digit* b)
  284. {
  285. int i;
  286. int imax;
  287. int k;
  288. sp_uint128 c;
  289. sp_uint128 lo;
  290. c = ((sp_uint128)a[33]) * b[33];
  291. r[67] = (sp_digit)(c >> 61);
  292. c &= 0x1fffffffffffffffL;
  293. for (k = 65; k >= 0; k--) {
  294. if (k >= 34) {
  295. i = k - 33;
  296. imax = 33;
  297. }
  298. else {
  299. i = 0;
  300. imax = k;
  301. }
  302. if (imax - i > 15) {
  303. int imaxlo;
  304. lo = 0;
  305. for (imaxlo = i; imaxlo <= imax; imaxlo += 15) {
  306. for (; i <= imax && i < imaxlo + 15; i++) {
  307. lo += ((sp_uint128)a[i]) * b[k - i];
  308. }
  309. c += lo >> 61;
  310. lo &= 0x1fffffffffffffffL;
  311. }
  312. r[k + 2] += (sp_digit)(c >> 61);
  313. r[k + 1] = (sp_digit)(c & 0x1fffffffffffffffL);
  314. c = lo & 0x1fffffffffffffffL;
  315. }
  316. else {
  317. lo = 0;
  318. for (; i <= imax; i++) {
  319. lo += ((sp_uint128)a[i]) * b[k - i];
  320. }
  321. c += lo >> 61;
  322. r[k + 2] += (sp_digit)(c >> 61);
  323. r[k + 1] = (sp_digit)(c & 0x1fffffffffffffffL);
  324. c = lo & 0x1fffffffffffffffL;
  325. }
  326. }
  327. r[0] = (sp_digit)c;
  328. }
  329. /* Square a and put result in r. (r = a * a)
  330. *
  331. * r A single precision integer.
  332. * a A single precision integer.
  333. */
  334. SP_NOINLINE static void sp_2048_sqr_34(sp_digit* r, const sp_digit* a)
  335. {
  336. int i;
  337. int imax;
  338. int k;
  339. sp_uint128 c;
  340. sp_uint128 t;
  341. c = ((sp_uint128)a[33]) * a[33];
  342. r[67] = (sp_digit)(c >> 61);
  343. c = (c & 0x1fffffffffffffffL) << 61;
  344. for (k = 65; k >= 0; k--) {
  345. i = (k + 1) / 2;
  346. if ((k & 1) == 0) {
  347. c += ((sp_uint128)a[i]) * a[i];
  348. i++;
  349. }
  350. if (k < 33) {
  351. imax = k;
  352. }
  353. else {
  354. imax = 33;
  355. }
  356. if (imax - i >= 14) {
  357. int imaxlo;
  358. sp_uint128 hi;
  359. hi = c >> 61;
  360. c &= 0x1fffffffffffffffL;
  361. for (imaxlo = i; imaxlo <= imax; imaxlo += 14) {
  362. t = 0;
  363. for (; i <= imax && i < imaxlo + 14; i++) {
  364. t += ((sp_uint128)a[i]) * a[k - i];
  365. }
  366. c += t * 2;
  367. hi += c >> 61;
  368. c &= 0x1fffffffffffffffL;
  369. }
  370. r[k + 2] += (sp_digit)(hi >> 61);
  371. r[k + 1] = (sp_digit)(hi & 0x1fffffffffffffffL);
  372. c <<= 61;
  373. }
  374. else
  375. {
  376. t = 0;
  377. for (; i <= imax; i++) {
  378. t += ((sp_uint128)a[i]) * a[k - i];
  379. }
  380. c += t * 2;
  381. r[k + 2] += (sp_digit) (c >> 122);
  382. r[k + 1] = (sp_digit)((c >> 61) & 0x1fffffffffffffffL);
  383. c = (c & 0x1fffffffffffffffL) << 61;
  384. }
  385. }
  386. r[0] = (sp_digit)(c >> 61);
  387. }
  388. /* Calculate the bottom digit of -1/a mod 2^n.
  389. *
  390. * a A single precision number.
  391. * rho Bottom word of inverse.
  392. */
  393. static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho)
  394. {
  395. sp_digit x;
  396. sp_digit b;
  397. b = a[0];
  398. x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
  399. x *= 2 - b * x; /* here x*a==1 mod 2**8 */
  400. x *= 2 - b * x; /* here x*a==1 mod 2**16 */
  401. x *= 2 - b * x; /* here x*a==1 mod 2**32 */
  402. x *= 2 - b * x; /* here x*a==1 mod 2**64 */
  403. x &= 0x1fffffffffffffffL;
  404. /* rho = -1/m mod b */
  405. *rho = ((sp_digit)1 << 61) - x;
  406. }
  407. /* Multiply a by scalar b into r. (r = a * b)
  408. *
  409. * r A single precision integer.
  410. * a A single precision integer.
  411. * b A scalar.
  412. */
  413. SP_NOINLINE static void sp_2048_mul_d_34(sp_digit* r, const sp_digit* a,
  414. sp_digit b)
  415. {
  416. sp_int128 tb = b;
  417. sp_int128 t = 0;
  418. int i;
  419. for (i = 0; i < 34; i++) {
  420. t += tb * a[i];
  421. r[i] = (sp_digit)(t & 0x1fffffffffffffffL);
  422. t >>= 61;
  423. }
  424. r[34] = (sp_digit)t;
  425. }
  426. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  427. /* Sub b from a into r. (r = a - b)
  428. *
  429. * r A single precision integer.
  430. * a A single precision integer.
  431. * b A single precision integer.
  432. */
  433. SP_NOINLINE static int sp_2048_sub_17(sp_digit* r, const sp_digit* a,
  434. const sp_digit* b)
  435. {
  436. int i;
  437. for (i = 0; i < 17; i++) {
  438. r[i] = a[i] - b[i];
  439. }
  440. return 0;
  441. }
  442. /* r = 2^n mod m where n is the number of bits to reduce by.
  443. * Given m must be 2048 bits, just need to subtract.
  444. *
  445. * r A single precision number.
  446. * m A single precision number.
  447. */
  448. static void sp_2048_mont_norm_17(sp_digit* r, const sp_digit* m)
  449. {
  450. /* Set r = 2^n - 1. */
  451. int i;
  452. for (i=0; i<16; i++) {
  453. r[i] = 0x1fffffffffffffffL;
  454. }
  455. r[16] = 0xffffffffffffL;
  456. /* r = (2^n - 1) mod n */
  457. (void)sp_2048_sub_17(r, r, m);
  458. /* Add one so r = 2^n mod m */
  459. r[0] += 1;
  460. }
  461. /* Compare a with b in constant time.
  462. *
  463. * a A single precision integer.
  464. * b A single precision integer.
  465. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  466. * respectively.
  467. */
  468. static sp_digit sp_2048_cmp_17(const sp_digit* a, const sp_digit* b)
  469. {
  470. sp_digit r = 0;
  471. int i;
  472. for (i=16; i>=0; i--) {
  473. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 60);
  474. }
  475. return r;
  476. }
  477. /* Conditionally subtract b from a using the mask m.
  478. * m is -1 to subtract and 0 when not.
  479. *
  480. * r A single precision number representing condition subtract result.
  481. * a A single precision number to subtract from.
  482. * b A single precision number to subtract.
  483. * m Mask value to apply.
  484. */
  485. static void sp_2048_cond_sub_17(sp_digit* r, const sp_digit* a,
  486. const sp_digit* b, const sp_digit m)
  487. {
  488. int i;
  489. for (i = 0; i < 17; i++) {
  490. r[i] = a[i] - (b[i] & m);
  491. }
  492. }
  493. /* Mul a by scalar b and add into r. (r += a * b)
  494. *
  495. * r A single precision integer.
  496. * a A single precision integer.
  497. * b A scalar.
  498. */
  499. SP_NOINLINE static void sp_2048_mul_add_17(sp_digit* r, const sp_digit* a,
  500. const sp_digit b)
  501. {
  502. sp_int128 tb = b;
  503. sp_int128 t[4];
  504. int i;
  505. t[0] = 0;
  506. for (i = 0; i < 16; i += 4) {
  507. t[0] += (tb * a[i+0]) + r[i+0];
  508. t[1] = (tb * a[i+1]) + r[i+1];
  509. t[2] = (tb * a[i+2]) + r[i+2];
  510. t[3] = (tb * a[i+3]) + r[i+3];
  511. r[i+0] = t[0] & 0x1fffffffffffffffL;
  512. t[1] += t[0] >> 61;
  513. r[i+1] = t[1] & 0x1fffffffffffffffL;
  514. t[2] += t[1] >> 61;
  515. r[i+2] = t[2] & 0x1fffffffffffffffL;
  516. t[3] += t[2] >> 61;
  517. r[i+3] = t[3] & 0x1fffffffffffffffL;
  518. t[0] = t[3] >> 61;
  519. }
  520. t[0] += (tb * a[16]) + r[16];
  521. r[16] = t[0] & 0x1fffffffffffffffL;
  522. r[17] += (sp_digit)(t[0] >> 61);
  523. }
  524. /* Shift the result in the high 1024 bits down to the bottom.
  525. *
  526. * r A single precision number.
  527. * a A single precision number.
  528. */
  529. static void sp_2048_mont_shift_17(sp_digit* r, const sp_digit* a)
  530. {
  531. int i;
  532. sp_int128 n = a[16] >> 48;
  533. n += ((sp_int128)a[17]) << 13;
  534. for (i = 0; i < 16; i++) {
  535. r[i] = n & 0x1fffffffffffffffL;
  536. n >>= 61;
  537. n += ((sp_int128)a[18 + i]) << 13;
  538. }
  539. r[16] = (sp_digit)n;
  540. XMEMSET(&r[17], 0, sizeof(*r) * 17U);
  541. }
  542. /* Reduce the number back to 2048 bits using Montgomery reduction.
  543. *
  544. * a A single precision number to reduce in place.
  545. * m The single precision number representing the modulus.
  546. * mp The digit representing the negative inverse of m mod 2^n.
  547. */
  548. static void sp_2048_mont_reduce_17(sp_digit* a, const sp_digit* m, sp_digit mp)
  549. {
  550. int i;
  551. sp_digit mu;
  552. sp_digit over;
  553. sp_2048_norm_17(a + 17);
  554. for (i=0; i<16; i++) {
  555. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffffL;
  556. sp_2048_mul_add_17(a+i, m, mu);
  557. a[i+1] += a[i] >> 61;
  558. }
  559. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xffffffffffffL;
  560. sp_2048_mul_add_17(a+i, m, mu);
  561. a[i+1] += a[i] >> 61;
  562. a[i] &= 0x1fffffffffffffffL;
  563. sp_2048_mont_shift_17(a, a);
  564. over = a[16] - m[16];
  565. sp_2048_cond_sub_17(a, a, m, ~((over - 1) >> 63));
  566. sp_2048_norm_17(a);
  567. }
  568. /* Multiply a and b into r. (r = a * b)
  569. *
  570. * r A single precision integer.
  571. * a A single precision integer.
  572. * b A single precision integer.
  573. */
  574. SP_NOINLINE static void sp_2048_mul_17(sp_digit* r, const sp_digit* a,
  575. const sp_digit* b)
  576. {
  577. int i;
  578. int imax;
  579. int k;
  580. sp_uint128 c;
  581. sp_uint128 lo;
  582. c = ((sp_uint128)a[16]) * b[16];
  583. r[33] = (sp_digit)(c >> 61);
  584. c &= 0x1fffffffffffffffL;
  585. for (k = 31; k >= 0; k--) {
  586. if (k >= 17) {
  587. i = k - 16;
  588. imax = 16;
  589. }
  590. else {
  591. i = 0;
  592. imax = k;
  593. }
  594. if (imax - i > 15) {
  595. int imaxlo;
  596. lo = 0;
  597. for (imaxlo = i; imaxlo <= imax; imaxlo += 15) {
  598. for (; i <= imax && i < imaxlo + 15; i++) {
  599. lo += ((sp_uint128)a[i]) * b[k - i];
  600. }
  601. c += lo >> 61;
  602. lo &= 0x1fffffffffffffffL;
  603. }
  604. r[k + 2] += (sp_digit)(c >> 61);
  605. r[k + 1] = (sp_digit)(c & 0x1fffffffffffffffL);
  606. c = lo & 0x1fffffffffffffffL;
  607. }
  608. else {
  609. lo = 0;
  610. for (; i <= imax; i++) {
  611. lo += ((sp_uint128)a[i]) * b[k - i];
  612. }
  613. c += lo >> 61;
  614. r[k + 2] += (sp_digit)(c >> 61);
  615. r[k + 1] = (sp_digit)(c & 0x1fffffffffffffffL);
  616. c = lo & 0x1fffffffffffffffL;
  617. }
  618. }
  619. r[0] = (sp_digit)c;
  620. }
  621. /* Multiply two Montgomery form numbers mod the modulus (prime).
  622. * (r = a * b mod m)
  623. *
  624. * r Result of multiplication.
  625. * a First number to multiply in Montgomery form.
  626. * b Second number to multiply in Montgomery form.
  627. * m Modulus (prime).
  628. * mp Montgomery multiplier.
  629. */
  630. SP_NOINLINE static void sp_2048_mont_mul_17(sp_digit* r, const sp_digit* a,
  631. const sp_digit* b, const sp_digit* m, sp_digit mp)
  632. {
  633. sp_2048_mul_17(r, a, b);
  634. sp_2048_mont_reduce_17(r, m, mp);
  635. }
  636. /* Square a and put result in r. (r = a * a)
  637. *
  638. * r A single precision integer.
  639. * a A single precision integer.
  640. */
  641. SP_NOINLINE static void sp_2048_sqr_17(sp_digit* r, const sp_digit* a)
  642. {
  643. int i;
  644. int imax;
  645. int k;
  646. sp_uint128 c;
  647. sp_uint128 t;
  648. c = ((sp_uint128)a[16]) * a[16];
  649. r[33] = (sp_digit)(c >> 61);
  650. c = (c & 0x1fffffffffffffffL) << 61;
  651. for (k = 31; k >= 0; k--) {
  652. i = (k + 1) / 2;
  653. if ((k & 1) == 0) {
  654. c += ((sp_uint128)a[i]) * a[i];
  655. i++;
  656. }
  657. if (k < 16) {
  658. imax = k;
  659. }
  660. else {
  661. imax = 16;
  662. }
  663. if (imax - i >= 14) {
  664. int imaxlo;
  665. sp_uint128 hi;
  666. hi = c >> 61;
  667. c &= 0x1fffffffffffffffL;
  668. for (imaxlo = i; imaxlo <= imax; imaxlo += 14) {
  669. t = 0;
  670. for (; i <= imax && i < imaxlo + 14; i++) {
  671. t += ((sp_uint128)a[i]) * a[k - i];
  672. }
  673. c += t * 2;
  674. hi += c >> 61;
  675. c &= 0x1fffffffffffffffL;
  676. }
  677. r[k + 2] += (sp_digit)(hi >> 61);
  678. r[k + 1] = (sp_digit)(hi & 0x1fffffffffffffffL);
  679. c <<= 61;
  680. }
  681. else
  682. {
  683. t = 0;
  684. for (; i <= imax; i++) {
  685. t += ((sp_uint128)a[i]) * a[k - i];
  686. }
  687. c += t * 2;
  688. r[k + 2] += (sp_digit) (c >> 122);
  689. r[k + 1] = (sp_digit)((c >> 61) & 0x1fffffffffffffffL);
  690. c = (c & 0x1fffffffffffffffL) << 61;
  691. }
  692. }
  693. r[0] = (sp_digit)(c >> 61);
  694. }
  695. /* Square the Montgomery form number. (r = a * a mod m)
  696. *
  697. * r Result of squaring.
  698. * a Number to square in Montgomery form.
  699. * m Modulus (prime).
  700. * mp Montgomery multiplier.
  701. */
  702. SP_NOINLINE static void sp_2048_mont_sqr_17(sp_digit* r, const sp_digit* a,
  703. const sp_digit* m, sp_digit mp)
  704. {
  705. sp_2048_sqr_17(r, a);
  706. sp_2048_mont_reduce_17(r, m, mp);
  707. }
  708. /* Multiply a by scalar b into r. (r = a * b)
  709. *
  710. * r A single precision integer.
  711. * a A single precision integer.
  712. * b A scalar.
  713. */
  714. SP_NOINLINE static void sp_2048_mul_d_17(sp_digit* r, const sp_digit* a,
  715. sp_digit b)
  716. {
  717. sp_int128 tb = b;
  718. sp_int128 t = 0;
  719. int i;
  720. for (i = 0; i < 17; i++) {
  721. t += tb * a[i];
  722. r[i] = (sp_digit)(t & 0x1fffffffffffffffL);
  723. t >>= 61;
  724. }
  725. r[17] = (sp_digit)t;
  726. }
  727. #ifdef WOLFSSL_SP_SMALL
  728. /* Conditionally add a and b using the mask m.
  729. * m is -1 to add and 0 when not.
  730. *
  731. * r A single precision number representing conditional add result.
  732. * a A single precision number to add with.
  733. * b A single precision number to add.
  734. * m Mask value to apply.
  735. */
  736. static void sp_2048_cond_add_17(sp_digit* r, const sp_digit* a,
  737. const sp_digit* b, const sp_digit m)
  738. {
  739. int i;
  740. for (i = 0; i < 17; i++) {
  741. r[i] = a[i] + (b[i] & m);
  742. }
  743. }
  744. #endif /* WOLFSSL_SP_SMALL */
  745. /* Add b to a into r. (r = a + b)
  746. *
  747. * r A single precision integer.
  748. * a A single precision integer.
  749. * b A single precision integer.
  750. */
  751. SP_NOINLINE static int sp_2048_add_17(sp_digit* r, const sp_digit* a,
  752. const sp_digit* b)
  753. {
  754. int i;
  755. for (i = 0; i < 17; i++) {
  756. r[i] = a[i] + b[i];
  757. }
  758. return 0;
  759. }
  760. SP_NOINLINE static void sp_2048_rshift_17(sp_digit* r, const sp_digit* a,
  761. byte n)
  762. {
  763. int i;
  764. for (i=0; i<16; i++) {
  765. r[i] = ((a[i] >> n) | (a[i + 1] << (61 - n))) & 0x1fffffffffffffffL;
  766. }
  767. r[16] = a[16] >> n;
  768. }
  769. static WC_INLINE sp_digit sp_2048_div_word_17(sp_digit d1, sp_digit d0,
  770. sp_digit div)
  771. {
  772. #ifdef SP_USE_DIVTI3
  773. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  774. return d / div;
  775. #elif defined(__x86_64__) || defined(__i386__)
  776. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  777. sp_uint64 lo = (sp_uint64)d;
  778. sp_digit hi = (sp_digit)(d >> 64);
  779. __asm__ __volatile__ (
  780. "idiv %2"
  781. : "+a" (lo)
  782. : "d" (hi), "r" (div)
  783. : "cc"
  784. );
  785. return (sp_digit)lo;
  786. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  787. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  788. sp_digit dv = (div >> 1) + 1;
  789. sp_digit t1 = (sp_digit)(d >> 61);
  790. sp_digit t0 = (sp_digit)(d & 0x1fffffffffffffffL);
  791. sp_digit t2;
  792. sp_digit sign;
  793. sp_digit r;
  794. int i;
  795. sp_int128 m;
  796. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  797. t1 -= dv & (0 - r);
  798. for (i = 59; i >= 1; i--) {
  799. t1 += t1 + (((sp_uint64)t0 >> 60) & 1);
  800. t0 <<= 1;
  801. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  802. r += r + t2;
  803. t1 -= dv & (0 - t2);
  804. t1 += t2;
  805. }
  806. r += r + 1;
  807. m = d - ((sp_int128)r * div);
  808. r += (sp_digit)(m >> 61);
  809. m = d - ((sp_int128)r * div);
  810. r += (sp_digit)(m >> 122) - (sp_digit)(d >> 122);
  811. m = d - ((sp_int128)r * div);
  812. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  813. m *= sign;
  814. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  815. r += sign * t2;
  816. m = d - ((sp_int128)r * div);
  817. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  818. m *= sign;
  819. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  820. r += sign * t2;
  821. return r;
  822. #else
  823. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  824. sp_digit r = 0;
  825. sp_digit t;
  826. sp_digit dv = (div >> 30) + 1;
  827. t = (sp_digit)(d >> 60);
  828. t = (t / dv) << 30;
  829. r += t;
  830. d -= (sp_int128)t * div;
  831. t = (sp_digit)(d >> 29);
  832. t = t / (dv << 1);
  833. r += t;
  834. d -= (sp_int128)t * div;
  835. t = (sp_digit)d;
  836. t = t / div;
  837. r += t;
  838. d -= (sp_int128)t * div;
  839. return r;
  840. #endif
  841. }
  842. static WC_INLINE sp_digit sp_2048_word_div_word_17(sp_digit d, sp_digit div)
  843. {
  844. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  845. defined(SP_DIV_WORD_USE_DIV)
  846. return d / div;
  847. #else
  848. return (sp_digit)((sp_uint64)(div - d) >> 63);
  849. #endif
  850. }
  851. /* Divide d in a and put remainder into r (m*d + r = a)
  852. * m is not calculated as it is not needed at this time.
  853. *
  854. * Full implementation.
  855. *
  856. * a Number to be divided.
  857. * d Number to divide with.
  858. * m Multiplier result.
  859. * r Remainder from the division.
  860. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  861. */
  862. static int sp_2048_div_17(const sp_digit* a, const sp_digit* d,
  863. const sp_digit* m, sp_digit* r)
  864. {
  865. int i;
  866. #ifndef WOLFSSL_SP_DIV_64
  867. #endif
  868. sp_digit dv;
  869. sp_digit r1;
  870. #ifdef WOLFSSL_SP_SMALL_STACK
  871. sp_digit* t1 = NULL;
  872. #else
  873. sp_digit t1[4 * 17 + 3];
  874. #endif
  875. sp_digit* t2 = NULL;
  876. sp_digit* sd = NULL;
  877. int err = MP_OKAY;
  878. (void)m;
  879. #ifdef WOLFSSL_SP_SMALL_STACK
  880. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 17 + 3), NULL,
  881. DYNAMIC_TYPE_TMP_BUFFER);
  882. if (t1 == NULL)
  883. err = MEMORY_E;
  884. #endif
  885. (void)m;
  886. if (err == MP_OKAY) {
  887. t2 = t1 + 34 + 1;
  888. sd = t2 + 17 + 1;
  889. sp_2048_mul_d_17(sd, d, (sp_digit)1 << 13);
  890. sp_2048_mul_d_34(t1, a, (sp_digit)1 << 13);
  891. dv = sd[16];
  892. t1[17 + 17] += t1[17 + 17 - 1] >> 61;
  893. t1[17 + 17 - 1] &= 0x1fffffffffffffffL;
  894. for (i=17; i>=0; i--) {
  895. r1 = sp_2048_div_word_17(t1[17 + i], t1[17 + i - 1], dv);
  896. sp_2048_mul_d_17(t2, sd, r1);
  897. (void)sp_2048_sub_17(&t1[i], &t1[i], t2);
  898. sp_2048_norm_17(&t1[i]);
  899. t1[17 + i] -= t2[17];
  900. t1[17 + i] += t1[17 + i - 1] >> 61;
  901. t1[17 + i - 1] &= 0x1fffffffffffffffL;
  902. r1 = sp_2048_div_word_17(-t1[17 + i], -t1[17 + i - 1], dv);
  903. r1 -= t1[17 + i];
  904. sp_2048_mul_d_17(t2, sd, r1);
  905. (void)sp_2048_add_17(&t1[i], &t1[i], t2);
  906. t1[17 + i] += t1[17 + i - 1] >> 61;
  907. t1[17 + i - 1] &= 0x1fffffffffffffffL;
  908. }
  909. t1[17 - 1] += t1[17 - 2] >> 61;
  910. t1[17 - 2] &= 0x1fffffffffffffffL;
  911. r1 = sp_2048_word_div_word_17(t1[17 - 1], dv);
  912. sp_2048_mul_d_17(t2, sd, r1);
  913. sp_2048_sub_17(t1, t1, t2);
  914. XMEMCPY(r, t1, sizeof(*r) * 34U);
  915. for (i=0; i<16; i++) {
  916. r[i+1] += r[i] >> 61;
  917. r[i] &= 0x1fffffffffffffffL;
  918. }
  919. sp_2048_cond_add_17(r, r, sd, r[16] >> 63);
  920. sp_2048_norm_17(r);
  921. sp_2048_rshift_17(r, r, 13);
  922. }
  923. #ifdef WOLFSSL_SP_SMALL_STACK
  924. if (t1 != NULL)
  925. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  926. #endif
  927. return err;
  928. }
  929. /* Reduce a modulo m into r. (r = a mod m)
  930. *
  931. * r A single precision number that is the reduced result.
  932. * a A single precision number that is to be reduced.
  933. * m A single precision number that is the modulus to reduce with.
  934. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  935. */
  936. static int sp_2048_mod_17(sp_digit* r, const sp_digit* a, const sp_digit* m)
  937. {
  938. return sp_2048_div_17(a, m, NULL, r);
  939. }
  940. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  941. *
  942. * r A single precision number that is the result of the operation.
  943. * a A single precision number being exponentiated.
  944. * e A single precision number that is the exponent.
  945. * bits The number of bits in the exponent.
  946. * m A single precision number that is the modulus.
  947. * returns 0 on success.
  948. * returns MEMORY_E on dynamic memory allocation failure.
  949. * returns MP_VAL when base is even or exponent is 0.
  950. */
  951. static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e,
  952. int bits, const sp_digit* m, int reduceA)
  953. {
  954. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  955. #ifdef WOLFSSL_SP_SMALL_STACK
  956. sp_digit* td = NULL;
  957. #else
  958. sp_digit td[3 * 34];
  959. #endif
  960. sp_digit* t[3] = {0, 0, 0};
  961. sp_digit* norm = NULL;
  962. sp_digit mp = 1;
  963. sp_digit n;
  964. int i;
  965. int c;
  966. byte y;
  967. int err = MP_OKAY;
  968. if (bits == 0) {
  969. err = MP_VAL;
  970. }
  971. #ifdef WOLFSSL_SP_SMALL_STACK
  972. if (err == MP_OKAY) {
  973. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 17 * 2, NULL,
  974. DYNAMIC_TYPE_TMP_BUFFER);
  975. if (td == NULL)
  976. err = MEMORY_E;
  977. }
  978. #endif
  979. if (err == MP_OKAY) {
  980. norm = td;
  981. for (i=0; i<3; i++) {
  982. t[i] = td + (i * 17 * 2);
  983. XMEMSET(t[i], 0, sizeof(sp_digit) * 17U * 2U);
  984. }
  985. sp_2048_mont_setup(m, &mp);
  986. sp_2048_mont_norm_17(norm, m);
  987. if (reduceA != 0) {
  988. err = sp_2048_mod_17(t[1], a, m);
  989. }
  990. else {
  991. XMEMCPY(t[1], a, sizeof(sp_digit) * 17U);
  992. }
  993. }
  994. if (err == MP_OKAY) {
  995. sp_2048_mul_17(t[1], t[1], norm);
  996. err = sp_2048_mod_17(t[1], t[1], m);
  997. }
  998. if (err == MP_OKAY) {
  999. i = bits / 61;
  1000. c = bits % 61;
  1001. n = e[i--] << (61 - c);
  1002. for (; ; c--) {
  1003. if (c == 0) {
  1004. if (i == -1) {
  1005. break;
  1006. }
  1007. n = e[i--];
  1008. c = 61;
  1009. }
  1010. y = (int)((n >> 60) & 1);
  1011. n <<= 1;
  1012. sp_2048_mont_mul_17(t[y^1], t[0], t[1], m, mp);
  1013. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  1014. ((size_t)t[1] & addr_mask[y])),
  1015. sizeof(*t[2]) * 17 * 2);
  1016. sp_2048_mont_sqr_17(t[2], t[2], m, mp);
  1017. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  1018. ((size_t)t[1] & addr_mask[y])), t[2],
  1019. sizeof(*t[2]) * 17 * 2);
  1020. }
  1021. sp_2048_mont_reduce_17(t[0], m, mp);
  1022. n = sp_2048_cmp_17(t[0], m);
  1023. sp_2048_cond_sub_17(t[0], t[0], m, ~(n >> 63));
  1024. XMEMCPY(r, t[0], sizeof(*r) * 17 * 2);
  1025. }
  1026. #ifdef WOLFSSL_SP_SMALL_STACK
  1027. if (td != NULL)
  1028. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1029. #endif
  1030. return err;
  1031. #elif !defined(WC_NO_CACHE_RESISTANT)
  1032. #ifdef WOLFSSL_SP_SMALL_STACK
  1033. sp_digit* td = NULL;
  1034. #else
  1035. sp_digit td[3 * 34];
  1036. #endif
  1037. sp_digit* t[3] = {0, 0, 0};
  1038. sp_digit* norm = NULL;
  1039. sp_digit mp = 1;
  1040. sp_digit n;
  1041. int i;
  1042. int c;
  1043. byte y;
  1044. int err = MP_OKAY;
  1045. if (bits == 0) {
  1046. err = MP_VAL;
  1047. }
  1048. #ifdef WOLFSSL_SP_SMALL_STACK
  1049. if (err == MP_OKAY) {
  1050. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 17 * 2, NULL,
  1051. DYNAMIC_TYPE_TMP_BUFFER);
  1052. if (td == NULL)
  1053. err = MEMORY_E;
  1054. }
  1055. #endif
  1056. if (err == MP_OKAY) {
  1057. norm = td;
  1058. for (i=0; i<3; i++) {
  1059. t[i] = td + (i * 17 * 2);
  1060. }
  1061. sp_2048_mont_setup(m, &mp);
  1062. sp_2048_mont_norm_17(norm, m);
  1063. if (reduceA != 0) {
  1064. err = sp_2048_mod_17(t[1], a, m);
  1065. if (err == MP_OKAY) {
  1066. sp_2048_mul_17(t[1], t[1], norm);
  1067. err = sp_2048_mod_17(t[1], t[1], m);
  1068. }
  1069. }
  1070. else {
  1071. sp_2048_mul_17(t[1], a, norm);
  1072. err = sp_2048_mod_17(t[1], t[1], m);
  1073. }
  1074. }
  1075. if (err == MP_OKAY) {
  1076. i = bits / 61;
  1077. c = bits % 61;
  1078. n = e[i--] << (61 - c);
  1079. for (; ; c--) {
  1080. if (c == 0) {
  1081. if (i == -1) {
  1082. break;
  1083. }
  1084. n = e[i--];
  1085. c = 61;
  1086. }
  1087. y = (int)((n >> 60) & 1);
  1088. n <<= 1;
  1089. sp_2048_mont_mul_17(t[y^1], t[0], t[1], m, mp);
  1090. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  1091. ((size_t)t[1] & addr_mask[y])),
  1092. sizeof(*t[2]) * 17 * 2);
  1093. sp_2048_mont_sqr_17(t[2], t[2], m, mp);
  1094. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  1095. ((size_t)t[1] & addr_mask[y])), t[2],
  1096. sizeof(*t[2]) * 17 * 2);
  1097. }
  1098. sp_2048_mont_reduce_17(t[0], m, mp);
  1099. n = sp_2048_cmp_17(t[0], m);
  1100. sp_2048_cond_sub_17(t[0], t[0], m, ~(n >> 63));
  1101. XMEMCPY(r, t[0], sizeof(*r) * 17 * 2);
  1102. }
  1103. #ifdef WOLFSSL_SP_SMALL_STACK
  1104. if (td != NULL)
  1105. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1106. #endif
  1107. return err;
  1108. #else
  1109. #ifdef WOLFSSL_SP_SMALL_STACK
  1110. sp_digit* td = NULL;
  1111. #else
  1112. sp_digit td[(32 * 34) + 34];
  1113. #endif
  1114. sp_digit* t[32];
  1115. sp_digit* rt = NULL;
  1116. sp_digit* norm = NULL;
  1117. sp_digit mp = 1;
  1118. sp_digit n;
  1119. int i;
  1120. int c;
  1121. byte y;
  1122. int err = MP_OKAY;
  1123. if (bits == 0) {
  1124. err = MP_VAL;
  1125. }
  1126. #ifdef WOLFSSL_SP_SMALL_STACK
  1127. if (err == MP_OKAY) {
  1128. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 34) + 34), NULL,
  1129. DYNAMIC_TYPE_TMP_BUFFER);
  1130. if (td == NULL)
  1131. err = MEMORY_E;
  1132. }
  1133. #endif
  1134. if (err == MP_OKAY) {
  1135. norm = td;
  1136. for (i=0; i<32; i++)
  1137. t[i] = td + i * 34;
  1138. rt = td + 1088;
  1139. sp_2048_mont_setup(m, &mp);
  1140. sp_2048_mont_norm_17(norm, m);
  1141. if (reduceA != 0) {
  1142. err = sp_2048_mod_17(t[1], a, m);
  1143. if (err == MP_OKAY) {
  1144. sp_2048_mul_17(t[1], t[1], norm);
  1145. err = sp_2048_mod_17(t[1], t[1], m);
  1146. }
  1147. }
  1148. else {
  1149. sp_2048_mul_17(t[1], a, norm);
  1150. err = sp_2048_mod_17(t[1], t[1], m);
  1151. }
  1152. }
  1153. if (err == MP_OKAY) {
  1154. sp_2048_mont_sqr_17(t[ 2], t[ 1], m, mp);
  1155. sp_2048_mont_mul_17(t[ 3], t[ 2], t[ 1], m, mp);
  1156. sp_2048_mont_sqr_17(t[ 4], t[ 2], m, mp);
  1157. sp_2048_mont_mul_17(t[ 5], t[ 3], t[ 2], m, mp);
  1158. sp_2048_mont_sqr_17(t[ 6], t[ 3], m, mp);
  1159. sp_2048_mont_mul_17(t[ 7], t[ 4], t[ 3], m, mp);
  1160. sp_2048_mont_sqr_17(t[ 8], t[ 4], m, mp);
  1161. sp_2048_mont_mul_17(t[ 9], t[ 5], t[ 4], m, mp);
  1162. sp_2048_mont_sqr_17(t[10], t[ 5], m, mp);
  1163. sp_2048_mont_mul_17(t[11], t[ 6], t[ 5], m, mp);
  1164. sp_2048_mont_sqr_17(t[12], t[ 6], m, mp);
  1165. sp_2048_mont_mul_17(t[13], t[ 7], t[ 6], m, mp);
  1166. sp_2048_mont_sqr_17(t[14], t[ 7], m, mp);
  1167. sp_2048_mont_mul_17(t[15], t[ 8], t[ 7], m, mp);
  1168. sp_2048_mont_sqr_17(t[16], t[ 8], m, mp);
  1169. sp_2048_mont_mul_17(t[17], t[ 9], t[ 8], m, mp);
  1170. sp_2048_mont_sqr_17(t[18], t[ 9], m, mp);
  1171. sp_2048_mont_mul_17(t[19], t[10], t[ 9], m, mp);
  1172. sp_2048_mont_sqr_17(t[20], t[10], m, mp);
  1173. sp_2048_mont_mul_17(t[21], t[11], t[10], m, mp);
  1174. sp_2048_mont_sqr_17(t[22], t[11], m, mp);
  1175. sp_2048_mont_mul_17(t[23], t[12], t[11], m, mp);
  1176. sp_2048_mont_sqr_17(t[24], t[12], m, mp);
  1177. sp_2048_mont_mul_17(t[25], t[13], t[12], m, mp);
  1178. sp_2048_mont_sqr_17(t[26], t[13], m, mp);
  1179. sp_2048_mont_mul_17(t[27], t[14], t[13], m, mp);
  1180. sp_2048_mont_sqr_17(t[28], t[14], m, mp);
  1181. sp_2048_mont_mul_17(t[29], t[15], t[14], m, mp);
  1182. sp_2048_mont_sqr_17(t[30], t[15], m, mp);
  1183. sp_2048_mont_mul_17(t[31], t[16], t[15], m, mp);
  1184. bits = ((bits + 4) / 5) * 5;
  1185. i = ((bits + 60) / 61) - 1;
  1186. c = bits % 61;
  1187. if (c == 0) {
  1188. c = 61;
  1189. }
  1190. if (i < 17) {
  1191. n = e[i--] << (64 - c);
  1192. }
  1193. else {
  1194. n = 0;
  1195. i--;
  1196. }
  1197. if (c < 5) {
  1198. n |= e[i--] << (3 - c);
  1199. c += 61;
  1200. }
  1201. y = (int)((n >> 59) & 0x1f);
  1202. n <<= 5;
  1203. c -= 5;
  1204. XMEMCPY(rt, t[y], sizeof(sp_digit) * 34);
  1205. while ((i >= 0) || (c >= 5)) {
  1206. if (c >= 5) {
  1207. y = (byte)((n >> 59) & 0x1f);
  1208. n <<= 5;
  1209. c -= 5;
  1210. }
  1211. else if (c == 0) {
  1212. n = e[i--] << 3;
  1213. y = (byte)((n >> 59) & 0x1f);
  1214. n <<= 5;
  1215. c = 56;
  1216. }
  1217. else {
  1218. y = (byte)((n >> 59) & 0x1f);
  1219. n = e[i--] << 3;
  1220. c = 5 - c;
  1221. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  1222. n <<= c;
  1223. c = 61 - c;
  1224. }
  1225. sp_2048_mont_sqr_17(rt, rt, m, mp);
  1226. sp_2048_mont_sqr_17(rt, rt, m, mp);
  1227. sp_2048_mont_sqr_17(rt, rt, m, mp);
  1228. sp_2048_mont_sqr_17(rt, rt, m, mp);
  1229. sp_2048_mont_sqr_17(rt, rt, m, mp);
  1230. sp_2048_mont_mul_17(rt, rt, t[y], m, mp);
  1231. }
  1232. sp_2048_mont_reduce_17(rt, m, mp);
  1233. n = sp_2048_cmp_17(rt, m);
  1234. sp_2048_cond_sub_17(rt, rt, m, ~(n >> 63));
  1235. XMEMCPY(r, rt, sizeof(sp_digit) * 34);
  1236. }
  1237. #ifdef WOLFSSL_SP_SMALL_STACK
  1238. if (td != NULL)
  1239. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1240. #endif
  1241. return err;
  1242. #endif
  1243. }
  1244. #endif /* (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) | WOLFSSL_HAVE_SP_DH */
  1245. /* Sub b from a into r. (r = a - b)
  1246. *
  1247. * r A single precision integer.
  1248. * a A single precision integer.
  1249. * b A single precision integer.
  1250. */
  1251. SP_NOINLINE static int sp_2048_sub_34(sp_digit* r, const sp_digit* a,
  1252. const sp_digit* b)
  1253. {
  1254. int i;
  1255. for (i = 0; i < 34; i++) {
  1256. r[i] = a[i] - b[i];
  1257. }
  1258. return 0;
  1259. }
  1260. /* r = 2^n mod m where n is the number of bits to reduce by.
  1261. * Given m must be 2048 bits, just need to subtract.
  1262. *
  1263. * r A single precision number.
  1264. * m A single precision number.
  1265. */
  1266. static void sp_2048_mont_norm_34(sp_digit* r, const sp_digit* m)
  1267. {
  1268. /* Set r = 2^n - 1. */
  1269. int i;
  1270. for (i=0; i<33; i++) {
  1271. r[i] = 0x1fffffffffffffffL;
  1272. }
  1273. r[33] = 0x7ffffffffL;
  1274. /* r = (2^n - 1) mod n */
  1275. (void)sp_2048_sub_34(r, r, m);
  1276. /* Add one so r = 2^n mod m */
  1277. r[0] += 1;
  1278. }
  1279. /* Compare a with b in constant time.
  1280. *
  1281. * a A single precision integer.
  1282. * b A single precision integer.
  1283. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  1284. * respectively.
  1285. */
  1286. static sp_digit sp_2048_cmp_34(const sp_digit* a, const sp_digit* b)
  1287. {
  1288. sp_digit r = 0;
  1289. int i;
  1290. for (i=33; i>=0; i--) {
  1291. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 60);
  1292. }
  1293. return r;
  1294. }
  1295. /* Conditionally subtract b from a using the mask m.
  1296. * m is -1 to subtract and 0 when not.
  1297. *
  1298. * r A single precision number representing condition subtract result.
  1299. * a A single precision number to subtract from.
  1300. * b A single precision number to subtract.
  1301. * m Mask value to apply.
  1302. */
  1303. static void sp_2048_cond_sub_34(sp_digit* r, const sp_digit* a,
  1304. const sp_digit* b, const sp_digit m)
  1305. {
  1306. int i;
  1307. for (i = 0; i < 34; i++) {
  1308. r[i] = a[i] - (b[i] & m);
  1309. }
  1310. }
  1311. /* Mul a by scalar b and add into r. (r += a * b)
  1312. *
  1313. * r A single precision integer.
  1314. * a A single precision integer.
  1315. * b A scalar.
  1316. */
  1317. SP_NOINLINE static void sp_2048_mul_add_34(sp_digit* r, const sp_digit* a,
  1318. const sp_digit b)
  1319. {
  1320. sp_int128 tb = b;
  1321. sp_int128 t[4];
  1322. int i;
  1323. t[0] = 0;
  1324. for (i = 0; i < 32; i += 4) {
  1325. t[0] += (tb * a[i+0]) + r[i+0];
  1326. t[1] = (tb * a[i+1]) + r[i+1];
  1327. t[2] = (tb * a[i+2]) + r[i+2];
  1328. t[3] = (tb * a[i+3]) + r[i+3];
  1329. r[i+0] = t[0] & 0x1fffffffffffffffL;
  1330. t[1] += t[0] >> 61;
  1331. r[i+1] = t[1] & 0x1fffffffffffffffL;
  1332. t[2] += t[1] >> 61;
  1333. r[i+2] = t[2] & 0x1fffffffffffffffL;
  1334. t[3] += t[2] >> 61;
  1335. r[i+3] = t[3] & 0x1fffffffffffffffL;
  1336. t[0] = t[3] >> 61;
  1337. }
  1338. t[0] += (tb * a[32]) + r[32];
  1339. t[1] = (tb * a[33]) + r[33];
  1340. r[32] = t[0] & 0x1fffffffffffffffL;
  1341. t[1] += t[0] >> 61;
  1342. r[33] = t[1] & 0x1fffffffffffffffL;
  1343. r[34] += (sp_digit)(t[1] >> 61);
  1344. }
  1345. /* Shift the result in the high 2048 bits down to the bottom.
  1346. *
  1347. * r A single precision number.
  1348. * a A single precision number.
  1349. */
  1350. static void sp_2048_mont_shift_34(sp_digit* r, const sp_digit* a)
  1351. {
  1352. int i;
  1353. sp_int128 n = a[33] >> 35;
  1354. n += ((sp_int128)a[34]) << 26;
  1355. for (i = 0; i < 33; i++) {
  1356. r[i] = n & 0x1fffffffffffffffL;
  1357. n >>= 61;
  1358. n += ((sp_int128)a[35 + i]) << 26;
  1359. }
  1360. r[33] = (sp_digit)n;
  1361. XMEMSET(&r[34], 0, sizeof(*r) * 34U);
  1362. }
  1363. /* Reduce the number back to 2048 bits using Montgomery reduction.
  1364. *
  1365. * a A single precision number to reduce in place.
  1366. * m The single precision number representing the modulus.
  1367. * mp The digit representing the negative inverse of m mod 2^n.
  1368. */
  1369. static void sp_2048_mont_reduce_34(sp_digit* a, const sp_digit* m, sp_digit mp)
  1370. {
  1371. int i;
  1372. sp_digit mu;
  1373. sp_digit over;
  1374. sp_2048_norm_34(a + 34);
  1375. #ifdef WOLFSSL_SP_DH
  1376. if (mp != 1) {
  1377. for (i=0; i<33; i++) {
  1378. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffffL;
  1379. sp_2048_mul_add_34(a+i, m, mu);
  1380. a[i+1] += a[i] >> 61;
  1381. }
  1382. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7ffffffffL;
  1383. sp_2048_mul_add_34(a+i, m, mu);
  1384. a[i+1] += a[i] >> 61;
  1385. a[i] &= 0x1fffffffffffffffL;
  1386. }
  1387. else {
  1388. for (i=0; i<33; i++) {
  1389. mu = a[i] & 0x1fffffffffffffffL;
  1390. sp_2048_mul_add_34(a+i, m, mu);
  1391. a[i+1] += a[i] >> 61;
  1392. }
  1393. mu = a[i] & 0x7ffffffffL;
  1394. sp_2048_mul_add_34(a+i, m, mu);
  1395. a[i+1] += a[i] >> 61;
  1396. a[i] &= 0x1fffffffffffffffL;
  1397. }
  1398. #else
  1399. for (i=0; i<33; i++) {
  1400. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffffL;
  1401. sp_2048_mul_add_34(a+i, m, mu);
  1402. a[i+1] += a[i] >> 61;
  1403. }
  1404. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7ffffffffL;
  1405. sp_2048_mul_add_34(a+i, m, mu);
  1406. a[i+1] += a[i] >> 61;
  1407. a[i] &= 0x1fffffffffffffffL;
  1408. #endif
  1409. sp_2048_mont_shift_34(a, a);
  1410. over = a[33] - m[33];
  1411. sp_2048_cond_sub_34(a, a, m, ~((over - 1) >> 63));
  1412. sp_2048_norm_34(a);
  1413. }
  1414. /* Multiply two Montgomery form numbers mod the modulus (prime).
  1415. * (r = a * b mod m)
  1416. *
  1417. * r Result of multiplication.
  1418. * a First number to multiply in Montgomery form.
  1419. * b Second number to multiply in Montgomery form.
  1420. * m Modulus (prime).
  1421. * mp Montgomery multiplier.
  1422. */
  1423. SP_NOINLINE static void sp_2048_mont_mul_34(sp_digit* r, const sp_digit* a,
  1424. const sp_digit* b, const sp_digit* m, sp_digit mp)
  1425. {
  1426. sp_2048_mul_34(r, a, b);
  1427. sp_2048_mont_reduce_34(r, m, mp);
  1428. }
  1429. /* Square the Montgomery form number. (r = a * a mod m)
  1430. *
  1431. * r Result of squaring.
  1432. * a Number to square in Montgomery form.
  1433. * m Modulus (prime).
  1434. * mp Montgomery multiplier.
  1435. */
  1436. SP_NOINLINE static void sp_2048_mont_sqr_34(sp_digit* r, const sp_digit* a,
  1437. const sp_digit* m, sp_digit mp)
  1438. {
  1439. sp_2048_sqr_34(r, a);
  1440. sp_2048_mont_reduce_34(r, m, mp);
  1441. }
  1442. /* Multiply a by scalar b into r. (r = a * b)
  1443. *
  1444. * r A single precision integer.
  1445. * a A single precision integer.
  1446. * b A scalar.
  1447. */
  1448. SP_NOINLINE static void sp_2048_mul_d_68(sp_digit* r, const sp_digit* a,
  1449. sp_digit b)
  1450. {
  1451. sp_int128 tb = b;
  1452. sp_int128 t = 0;
  1453. int i;
  1454. for (i = 0; i < 68; i++) {
  1455. t += tb * a[i];
  1456. r[i] = (sp_digit)(t & 0x1fffffffffffffffL);
  1457. t >>= 61;
  1458. }
  1459. r[68] = (sp_digit)t;
  1460. }
  1461. #ifdef WOLFSSL_SP_SMALL
  1462. /* Conditionally add a and b using the mask m.
  1463. * m is -1 to add and 0 when not.
  1464. *
  1465. * r A single precision number representing conditional add result.
  1466. * a A single precision number to add with.
  1467. * b A single precision number to add.
  1468. * m Mask value to apply.
  1469. */
  1470. static void sp_2048_cond_add_34(sp_digit* r, const sp_digit* a,
  1471. const sp_digit* b, const sp_digit m)
  1472. {
  1473. int i;
  1474. for (i = 0; i < 34; i++) {
  1475. r[i] = a[i] + (b[i] & m);
  1476. }
  1477. }
  1478. #endif /* WOLFSSL_SP_SMALL */
  1479. /* Add b to a into r. (r = a + b)
  1480. *
  1481. * r A single precision integer.
  1482. * a A single precision integer.
  1483. * b A single precision integer.
  1484. */
  1485. SP_NOINLINE static int sp_2048_add_34(sp_digit* r, const sp_digit* a,
  1486. const sp_digit* b)
  1487. {
  1488. int i;
  1489. for (i = 0; i < 34; i++) {
  1490. r[i] = a[i] + b[i];
  1491. }
  1492. return 0;
  1493. }
  1494. SP_NOINLINE static void sp_2048_rshift_34(sp_digit* r, const sp_digit* a,
  1495. byte n)
  1496. {
  1497. int i;
  1498. for (i=0; i<33; i++) {
  1499. r[i] = ((a[i] >> n) | (a[i + 1] << (61 - n))) & 0x1fffffffffffffffL;
  1500. }
  1501. r[33] = a[33] >> n;
  1502. }
  1503. static WC_INLINE sp_digit sp_2048_div_word_34(sp_digit d1, sp_digit d0,
  1504. sp_digit div)
  1505. {
  1506. #ifdef SP_USE_DIVTI3
  1507. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  1508. return d / div;
  1509. #elif defined(__x86_64__) || defined(__i386__)
  1510. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  1511. sp_uint64 lo = (sp_uint64)d;
  1512. sp_digit hi = (sp_digit)(d >> 64);
  1513. __asm__ __volatile__ (
  1514. "idiv %2"
  1515. : "+a" (lo)
  1516. : "d" (hi), "r" (div)
  1517. : "cc"
  1518. );
  1519. return (sp_digit)lo;
  1520. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  1521. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  1522. sp_digit dv = (div >> 1) + 1;
  1523. sp_digit t1 = (sp_digit)(d >> 61);
  1524. sp_digit t0 = (sp_digit)(d & 0x1fffffffffffffffL);
  1525. sp_digit t2;
  1526. sp_digit sign;
  1527. sp_digit r;
  1528. int i;
  1529. sp_int128 m;
  1530. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  1531. t1 -= dv & (0 - r);
  1532. for (i = 59; i >= 1; i--) {
  1533. t1 += t1 + (((sp_uint64)t0 >> 60) & 1);
  1534. t0 <<= 1;
  1535. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  1536. r += r + t2;
  1537. t1 -= dv & (0 - t2);
  1538. t1 += t2;
  1539. }
  1540. r += r + 1;
  1541. m = d - ((sp_int128)r * div);
  1542. r += (sp_digit)(m >> 61);
  1543. m = d - ((sp_int128)r * div);
  1544. r += (sp_digit)(m >> 122) - (sp_digit)(d >> 122);
  1545. m = d - ((sp_int128)r * div);
  1546. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  1547. m *= sign;
  1548. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  1549. r += sign * t2;
  1550. m = d - ((sp_int128)r * div);
  1551. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  1552. m *= sign;
  1553. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  1554. r += sign * t2;
  1555. return r;
  1556. #else
  1557. sp_int128 d = ((sp_int128)d1 << 61) + d0;
  1558. sp_digit r = 0;
  1559. sp_digit t;
  1560. sp_digit dv = (div >> 30) + 1;
  1561. t = (sp_digit)(d >> 60);
  1562. t = (t / dv) << 30;
  1563. r += t;
  1564. d -= (sp_int128)t * div;
  1565. t = (sp_digit)(d >> 29);
  1566. t = t / (dv << 1);
  1567. r += t;
  1568. d -= (sp_int128)t * div;
  1569. t = (sp_digit)d;
  1570. t = t / div;
  1571. r += t;
  1572. d -= (sp_int128)t * div;
  1573. return r;
  1574. #endif
  1575. }
  1576. static WC_INLINE sp_digit sp_2048_word_div_word_34(sp_digit d, sp_digit div)
  1577. {
  1578. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  1579. defined(SP_DIV_WORD_USE_DIV)
  1580. return d / div;
  1581. #else
  1582. return (sp_digit)((sp_uint64)(div - d) >> 63);
  1583. #endif
  1584. }
  1585. /* Divide d in a and put remainder into r (m*d + r = a)
  1586. * m is not calculated as it is not needed at this time.
  1587. *
  1588. * Full implementation.
  1589. *
  1590. * a Number to be divided.
  1591. * d Number to divide with.
  1592. * m Multiplier result.
  1593. * r Remainder from the division.
  1594. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  1595. */
  1596. static int sp_2048_div_34(const sp_digit* a, const sp_digit* d,
  1597. const sp_digit* m, sp_digit* r)
  1598. {
  1599. int i;
  1600. #ifndef WOLFSSL_SP_DIV_64
  1601. #endif
  1602. sp_digit dv;
  1603. sp_digit r1;
  1604. #ifdef WOLFSSL_SP_SMALL_STACK
  1605. sp_digit* t1 = NULL;
  1606. #else
  1607. sp_digit t1[4 * 34 + 3];
  1608. #endif
  1609. sp_digit* t2 = NULL;
  1610. sp_digit* sd = NULL;
  1611. int err = MP_OKAY;
  1612. (void)m;
  1613. #ifdef WOLFSSL_SP_SMALL_STACK
  1614. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 34 + 3), NULL,
  1615. DYNAMIC_TYPE_TMP_BUFFER);
  1616. if (t1 == NULL)
  1617. err = MEMORY_E;
  1618. #endif
  1619. (void)m;
  1620. if (err == MP_OKAY) {
  1621. t2 = t1 + 68 + 1;
  1622. sd = t2 + 34 + 1;
  1623. sp_2048_mul_d_34(sd, d, (sp_digit)1 << 26);
  1624. sp_2048_mul_d_68(t1, a, (sp_digit)1 << 26);
  1625. dv = sd[33];
  1626. t1[34 + 34] += t1[34 + 34 - 1] >> 61;
  1627. t1[34 + 34 - 1] &= 0x1fffffffffffffffL;
  1628. for (i=34; i>=0; i--) {
  1629. r1 = sp_2048_div_word_34(t1[34 + i], t1[34 + i - 1], dv);
  1630. sp_2048_mul_d_34(t2, sd, r1);
  1631. (void)sp_2048_sub_34(&t1[i], &t1[i], t2);
  1632. sp_2048_norm_34(&t1[i]);
  1633. t1[34 + i] -= t2[34];
  1634. t1[34 + i] += t1[34 + i - 1] >> 61;
  1635. t1[34 + i - 1] &= 0x1fffffffffffffffL;
  1636. r1 = sp_2048_div_word_34(-t1[34 + i], -t1[34 + i - 1], dv);
  1637. r1 -= t1[34 + i];
  1638. sp_2048_mul_d_34(t2, sd, r1);
  1639. (void)sp_2048_add_34(&t1[i], &t1[i], t2);
  1640. t1[34 + i] += t1[34 + i - 1] >> 61;
  1641. t1[34 + i - 1] &= 0x1fffffffffffffffL;
  1642. }
  1643. t1[34 - 1] += t1[34 - 2] >> 61;
  1644. t1[34 - 2] &= 0x1fffffffffffffffL;
  1645. r1 = sp_2048_word_div_word_34(t1[34 - 1], dv);
  1646. sp_2048_mul_d_34(t2, sd, r1);
  1647. sp_2048_sub_34(t1, t1, t2);
  1648. XMEMCPY(r, t1, sizeof(*r) * 68U);
  1649. for (i=0; i<33; i++) {
  1650. r[i+1] += r[i] >> 61;
  1651. r[i] &= 0x1fffffffffffffffL;
  1652. }
  1653. sp_2048_cond_add_34(r, r, sd, r[33] >> 63);
  1654. sp_2048_norm_34(r);
  1655. sp_2048_rshift_34(r, r, 26);
  1656. }
  1657. #ifdef WOLFSSL_SP_SMALL_STACK
  1658. if (t1 != NULL)
  1659. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1660. #endif
  1661. return err;
  1662. }
  1663. /* Reduce a modulo m into r. (r = a mod m)
  1664. *
  1665. * r A single precision number that is the reduced result.
  1666. * a A single precision number that is to be reduced.
  1667. * m A single precision number that is the modulus to reduce with.
  1668. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  1669. */
  1670. static int sp_2048_mod_34(sp_digit* r, const sp_digit* a, const sp_digit* m)
  1671. {
  1672. return sp_2048_div_34(a, m, NULL, r);
  1673. }
  1674. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  1675. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  1676. *
  1677. * r A single precision number that is the result of the operation.
  1678. * a A single precision number being exponentiated.
  1679. * e A single precision number that is the exponent.
  1680. * bits The number of bits in the exponent.
  1681. * m A single precision number that is the modulus.
  1682. * returns 0 on success.
  1683. * returns MEMORY_E on dynamic memory allocation failure.
  1684. * returns MP_VAL when base is even or exponent is 0.
  1685. */
  1686. static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e,
  1687. int bits, const sp_digit* m, int reduceA)
  1688. {
  1689. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  1690. #ifdef WOLFSSL_SP_SMALL_STACK
  1691. sp_digit* td = NULL;
  1692. #else
  1693. sp_digit td[3 * 68];
  1694. #endif
  1695. sp_digit* t[3] = {0, 0, 0};
  1696. sp_digit* norm = NULL;
  1697. sp_digit mp = 1;
  1698. sp_digit n;
  1699. int i;
  1700. int c;
  1701. byte y;
  1702. int err = MP_OKAY;
  1703. if (bits == 0) {
  1704. err = MP_VAL;
  1705. }
  1706. #ifdef WOLFSSL_SP_SMALL_STACK
  1707. if (err == MP_OKAY) {
  1708. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 34 * 2, NULL,
  1709. DYNAMIC_TYPE_TMP_BUFFER);
  1710. if (td == NULL)
  1711. err = MEMORY_E;
  1712. }
  1713. #endif
  1714. if (err == MP_OKAY) {
  1715. norm = td;
  1716. for (i=0; i<3; i++) {
  1717. t[i] = td + (i * 34 * 2);
  1718. XMEMSET(t[i], 0, sizeof(sp_digit) * 34U * 2U);
  1719. }
  1720. sp_2048_mont_setup(m, &mp);
  1721. sp_2048_mont_norm_34(norm, m);
  1722. if (reduceA != 0) {
  1723. err = sp_2048_mod_34(t[1], a, m);
  1724. }
  1725. else {
  1726. XMEMCPY(t[1], a, sizeof(sp_digit) * 34U);
  1727. }
  1728. }
  1729. if (err == MP_OKAY) {
  1730. sp_2048_mul_34(t[1], t[1], norm);
  1731. err = sp_2048_mod_34(t[1], t[1], m);
  1732. }
  1733. if (err == MP_OKAY) {
  1734. i = bits / 61;
  1735. c = bits % 61;
  1736. n = e[i--] << (61 - c);
  1737. for (; ; c--) {
  1738. if (c == 0) {
  1739. if (i == -1) {
  1740. break;
  1741. }
  1742. n = e[i--];
  1743. c = 61;
  1744. }
  1745. y = (int)((n >> 60) & 1);
  1746. n <<= 1;
  1747. sp_2048_mont_mul_34(t[y^1], t[0], t[1], m, mp);
  1748. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  1749. ((size_t)t[1] & addr_mask[y])),
  1750. sizeof(*t[2]) * 34 * 2);
  1751. sp_2048_mont_sqr_34(t[2], t[2], m, mp);
  1752. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  1753. ((size_t)t[1] & addr_mask[y])), t[2],
  1754. sizeof(*t[2]) * 34 * 2);
  1755. }
  1756. sp_2048_mont_reduce_34(t[0], m, mp);
  1757. n = sp_2048_cmp_34(t[0], m);
  1758. sp_2048_cond_sub_34(t[0], t[0], m, ~(n >> 63));
  1759. XMEMCPY(r, t[0], sizeof(*r) * 34 * 2);
  1760. }
  1761. #ifdef WOLFSSL_SP_SMALL_STACK
  1762. if (td != NULL)
  1763. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1764. #endif
  1765. return err;
  1766. #elif !defined(WC_NO_CACHE_RESISTANT)
  1767. #ifdef WOLFSSL_SP_SMALL_STACK
  1768. sp_digit* td = NULL;
  1769. #else
  1770. sp_digit td[3 * 68];
  1771. #endif
  1772. sp_digit* t[3] = {0, 0, 0};
  1773. sp_digit* norm = NULL;
  1774. sp_digit mp = 1;
  1775. sp_digit n;
  1776. int i;
  1777. int c;
  1778. byte y;
  1779. int err = MP_OKAY;
  1780. if (bits == 0) {
  1781. err = MP_VAL;
  1782. }
  1783. #ifdef WOLFSSL_SP_SMALL_STACK
  1784. if (err == MP_OKAY) {
  1785. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 34 * 2, NULL,
  1786. DYNAMIC_TYPE_TMP_BUFFER);
  1787. if (td == NULL)
  1788. err = MEMORY_E;
  1789. }
  1790. #endif
  1791. if (err == MP_OKAY) {
  1792. norm = td;
  1793. for (i=0; i<3; i++) {
  1794. t[i] = td + (i * 34 * 2);
  1795. }
  1796. sp_2048_mont_setup(m, &mp);
  1797. sp_2048_mont_norm_34(norm, m);
  1798. if (reduceA != 0) {
  1799. err = sp_2048_mod_34(t[1], a, m);
  1800. if (err == MP_OKAY) {
  1801. sp_2048_mul_34(t[1], t[1], norm);
  1802. err = sp_2048_mod_34(t[1], t[1], m);
  1803. }
  1804. }
  1805. else {
  1806. sp_2048_mul_34(t[1], a, norm);
  1807. err = sp_2048_mod_34(t[1], t[1], m);
  1808. }
  1809. }
  1810. if (err == MP_OKAY) {
  1811. i = bits / 61;
  1812. c = bits % 61;
  1813. n = e[i--] << (61 - c);
  1814. for (; ; c--) {
  1815. if (c == 0) {
  1816. if (i == -1) {
  1817. break;
  1818. }
  1819. n = e[i--];
  1820. c = 61;
  1821. }
  1822. y = (int)((n >> 60) & 1);
  1823. n <<= 1;
  1824. sp_2048_mont_mul_34(t[y^1], t[0], t[1], m, mp);
  1825. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  1826. ((size_t)t[1] & addr_mask[y])),
  1827. sizeof(*t[2]) * 34 * 2);
  1828. sp_2048_mont_sqr_34(t[2], t[2], m, mp);
  1829. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  1830. ((size_t)t[1] & addr_mask[y])), t[2],
  1831. sizeof(*t[2]) * 34 * 2);
  1832. }
  1833. sp_2048_mont_reduce_34(t[0], m, mp);
  1834. n = sp_2048_cmp_34(t[0], m);
  1835. sp_2048_cond_sub_34(t[0], t[0], m, ~(n >> 63));
  1836. XMEMCPY(r, t[0], sizeof(*r) * 34 * 2);
  1837. }
  1838. #ifdef WOLFSSL_SP_SMALL_STACK
  1839. if (td != NULL)
  1840. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1841. #endif
  1842. return err;
  1843. #else
  1844. #ifdef WOLFSSL_SP_SMALL_STACK
  1845. sp_digit* td = NULL;
  1846. #else
  1847. sp_digit td[(16 * 68) + 68];
  1848. #endif
  1849. sp_digit* t[16];
  1850. sp_digit* rt = NULL;
  1851. sp_digit* norm = NULL;
  1852. sp_digit mp = 1;
  1853. sp_digit n;
  1854. int i;
  1855. int c;
  1856. byte y;
  1857. int err = MP_OKAY;
  1858. if (bits == 0) {
  1859. err = MP_VAL;
  1860. }
  1861. #ifdef WOLFSSL_SP_SMALL_STACK
  1862. if (err == MP_OKAY) {
  1863. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 68) + 68), NULL,
  1864. DYNAMIC_TYPE_TMP_BUFFER);
  1865. if (td == NULL)
  1866. err = MEMORY_E;
  1867. }
  1868. #endif
  1869. if (err == MP_OKAY) {
  1870. norm = td;
  1871. for (i=0; i<16; i++)
  1872. t[i] = td + i * 68;
  1873. rt = td + 1088;
  1874. sp_2048_mont_setup(m, &mp);
  1875. sp_2048_mont_norm_34(norm, m);
  1876. if (reduceA != 0) {
  1877. err = sp_2048_mod_34(t[1], a, m);
  1878. if (err == MP_OKAY) {
  1879. sp_2048_mul_34(t[1], t[1], norm);
  1880. err = sp_2048_mod_34(t[1], t[1], m);
  1881. }
  1882. }
  1883. else {
  1884. sp_2048_mul_34(t[1], a, norm);
  1885. err = sp_2048_mod_34(t[1], t[1], m);
  1886. }
  1887. }
  1888. if (err == MP_OKAY) {
  1889. sp_2048_mont_sqr_34(t[ 2], t[ 1], m, mp);
  1890. sp_2048_mont_mul_34(t[ 3], t[ 2], t[ 1], m, mp);
  1891. sp_2048_mont_sqr_34(t[ 4], t[ 2], m, mp);
  1892. sp_2048_mont_mul_34(t[ 5], t[ 3], t[ 2], m, mp);
  1893. sp_2048_mont_sqr_34(t[ 6], t[ 3], m, mp);
  1894. sp_2048_mont_mul_34(t[ 7], t[ 4], t[ 3], m, mp);
  1895. sp_2048_mont_sqr_34(t[ 8], t[ 4], m, mp);
  1896. sp_2048_mont_mul_34(t[ 9], t[ 5], t[ 4], m, mp);
  1897. sp_2048_mont_sqr_34(t[10], t[ 5], m, mp);
  1898. sp_2048_mont_mul_34(t[11], t[ 6], t[ 5], m, mp);
  1899. sp_2048_mont_sqr_34(t[12], t[ 6], m, mp);
  1900. sp_2048_mont_mul_34(t[13], t[ 7], t[ 6], m, mp);
  1901. sp_2048_mont_sqr_34(t[14], t[ 7], m, mp);
  1902. sp_2048_mont_mul_34(t[15], t[ 8], t[ 7], m, mp);
  1903. bits = ((bits + 3) / 4) * 4;
  1904. i = ((bits + 60) / 61) - 1;
  1905. c = bits % 61;
  1906. if (c == 0) {
  1907. c = 61;
  1908. }
  1909. if (i < 34) {
  1910. n = e[i--] << (64 - c);
  1911. }
  1912. else {
  1913. n = 0;
  1914. i--;
  1915. }
  1916. if (c < 4) {
  1917. n |= e[i--] << (3 - c);
  1918. c += 61;
  1919. }
  1920. y = (int)((n >> 60) & 0xf);
  1921. n <<= 4;
  1922. c -= 4;
  1923. XMEMCPY(rt, t[y], sizeof(sp_digit) * 68);
  1924. while ((i >= 0) || (c >= 4)) {
  1925. if (c >= 4) {
  1926. y = (byte)((n >> 60) & 0xf);
  1927. n <<= 4;
  1928. c -= 4;
  1929. }
  1930. else if (c == 0) {
  1931. n = e[i--] << 3;
  1932. y = (byte)((n >> 60) & 0xf);
  1933. n <<= 4;
  1934. c = 57;
  1935. }
  1936. else {
  1937. y = (byte)((n >> 60) & 0xf);
  1938. n = e[i--] << 3;
  1939. c = 4 - c;
  1940. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  1941. n <<= c;
  1942. c = 61 - c;
  1943. }
  1944. sp_2048_mont_sqr_34(rt, rt, m, mp);
  1945. sp_2048_mont_sqr_34(rt, rt, m, mp);
  1946. sp_2048_mont_sqr_34(rt, rt, m, mp);
  1947. sp_2048_mont_sqr_34(rt, rt, m, mp);
  1948. sp_2048_mont_mul_34(rt, rt, t[y], m, mp);
  1949. }
  1950. sp_2048_mont_reduce_34(rt, m, mp);
  1951. n = sp_2048_cmp_34(rt, m);
  1952. sp_2048_cond_sub_34(rt, rt, m, ~(n >> 63));
  1953. XMEMCPY(r, rt, sizeof(sp_digit) * 68);
  1954. }
  1955. #ifdef WOLFSSL_SP_SMALL_STACK
  1956. if (td != NULL)
  1957. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1958. #endif
  1959. return err;
  1960. #endif
  1961. }
  1962. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  1963. #ifdef WOLFSSL_HAVE_SP_RSA
  1964. /* RSA public key operation.
  1965. *
  1966. * in Array of bytes representing the number to exponentiate, base.
  1967. * inLen Number of bytes in base.
  1968. * em Public exponent.
  1969. * mm Modulus.
  1970. * out Buffer to hold big-endian bytes of exponentiation result.
  1971. * Must be at least 256 bytes long.
  1972. * outLen Number of bytes in result.
  1973. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  1974. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  1975. */
  1976. int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em,
  1977. const mp_int* mm, byte* out, word32* outLen)
  1978. {
  1979. #ifdef WOLFSSL_SP_SMALL
  1980. #ifdef WOLFSSL_SP_SMALL_STACK
  1981. sp_digit* a = NULL;
  1982. #else
  1983. sp_digit a[34 * 5];
  1984. #endif
  1985. sp_digit* m = NULL;
  1986. sp_digit* r = NULL;
  1987. sp_digit* norm = NULL;
  1988. sp_digit e[1] = {0};
  1989. sp_digit mp = 0;
  1990. int i;
  1991. int err = MP_OKAY;
  1992. if (*outLen < 256U) {
  1993. err = MP_TO_E;
  1994. }
  1995. if (err == MP_OKAY) {
  1996. if (mp_count_bits(em) > 61) {
  1997. err = MP_READ_E;
  1998. }
  1999. else if (inLen > 256U) {
  2000. err = MP_READ_E;
  2001. }
  2002. else if (mp_count_bits(mm) != 2048) {
  2003. err = MP_READ_E;
  2004. }
  2005. else if (mp_iseven(mm)) {
  2006. err = MP_VAL;
  2007. }
  2008. }
  2009. #ifdef WOLFSSL_SP_SMALL_STACK
  2010. if (err == MP_OKAY) {
  2011. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 5, NULL,
  2012. DYNAMIC_TYPE_RSA);
  2013. if (a == NULL)
  2014. err = MEMORY_E;
  2015. }
  2016. #endif
  2017. if (err == MP_OKAY) {
  2018. r = a + 34 * 2;
  2019. m = r + 34 * 2;
  2020. norm = r;
  2021. sp_2048_from_bin(a, 34, in, inLen);
  2022. #if DIGIT_BIT >= 61
  2023. e[0] = (sp_digit)em->dp[0];
  2024. #else
  2025. e[0] = (sp_digit)em->dp[0];
  2026. if (em->used > 1) {
  2027. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  2028. }
  2029. #endif
  2030. if (e[0] == 0) {
  2031. err = MP_EXPTMOD_E;
  2032. }
  2033. }
  2034. if (err == MP_OKAY) {
  2035. sp_2048_from_mp(m, 34, mm);
  2036. sp_2048_mont_setup(m, &mp);
  2037. sp_2048_mont_norm_34(norm, m);
  2038. }
  2039. if (err == MP_OKAY) {
  2040. sp_2048_mul_34(a, a, norm);
  2041. err = sp_2048_mod_34(a, a, m);
  2042. }
  2043. if (err == MP_OKAY) {
  2044. for (i=60; i>=0; i--) {
  2045. if ((e[0] >> i) != 0) {
  2046. break;
  2047. }
  2048. }
  2049. XMEMCPY(r, a, sizeof(sp_digit) * 34 * 2);
  2050. for (i--; i>=0; i--) {
  2051. sp_2048_mont_sqr_34(r, r, m, mp);
  2052. if (((e[0] >> i) & 1) == 1) {
  2053. sp_2048_mont_mul_34(r, r, a, m, mp);
  2054. }
  2055. }
  2056. sp_2048_mont_reduce_34(r, m, mp);
  2057. mp = sp_2048_cmp_34(r, m);
  2058. sp_2048_cond_sub_34(r, r, m, ~(mp >> 63));
  2059. sp_2048_to_bin_34(r, out);
  2060. *outLen = 256;
  2061. }
  2062. #ifdef WOLFSSL_SP_SMALL_STACK
  2063. if (a != NULL)
  2064. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  2065. #endif
  2066. return err;
  2067. #else
  2068. #ifdef WOLFSSL_SP_SMALL_STACK
  2069. sp_digit* d = NULL;
  2070. #else
  2071. sp_digit d[34 * 5];
  2072. #endif
  2073. sp_digit* a = NULL;
  2074. sp_digit* m = NULL;
  2075. sp_digit* r = NULL;
  2076. sp_digit e[1] = {0};
  2077. int err = MP_OKAY;
  2078. if (*outLen < 256U) {
  2079. err = MP_TO_E;
  2080. }
  2081. if (err == MP_OKAY) {
  2082. if (mp_count_bits(em) > 61) {
  2083. err = MP_READ_E;
  2084. }
  2085. else if (inLen > 256U) {
  2086. err = MP_READ_E;
  2087. }
  2088. else if (mp_count_bits(mm) != 2048) {
  2089. err = MP_READ_E;
  2090. }
  2091. else if (mp_iseven(mm)) {
  2092. err = MP_VAL;
  2093. }
  2094. }
  2095. #ifdef WOLFSSL_SP_SMALL_STACK
  2096. if (err == MP_OKAY) {
  2097. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 5, NULL,
  2098. DYNAMIC_TYPE_RSA);
  2099. if (d == NULL)
  2100. err = MEMORY_E;
  2101. }
  2102. #endif
  2103. if (err == MP_OKAY) {
  2104. a = d;
  2105. r = a + 34 * 2;
  2106. m = r + 34 * 2;
  2107. sp_2048_from_bin(a, 34, in, inLen);
  2108. #if DIGIT_BIT >= 61
  2109. e[0] = (sp_digit)em->dp[0];
  2110. #else
  2111. e[0] = (sp_digit)em->dp[0];
  2112. if (em->used > 1) {
  2113. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  2114. }
  2115. #endif
  2116. if (e[0] == 0) {
  2117. err = MP_EXPTMOD_E;
  2118. }
  2119. }
  2120. if (err == MP_OKAY) {
  2121. sp_2048_from_mp(m, 34, mm);
  2122. if (e[0] == 0x3) {
  2123. sp_2048_sqr_34(r, a);
  2124. err = sp_2048_mod_34(r, r, m);
  2125. if (err == MP_OKAY) {
  2126. sp_2048_mul_34(r, a, r);
  2127. err = sp_2048_mod_34(r, r, m);
  2128. }
  2129. }
  2130. else {
  2131. sp_digit* norm = r;
  2132. int i;
  2133. sp_digit mp;
  2134. sp_2048_mont_setup(m, &mp);
  2135. sp_2048_mont_norm_34(norm, m);
  2136. sp_2048_mul_34(a, a, norm);
  2137. err = sp_2048_mod_34(a, a, m);
  2138. if (err == MP_OKAY) {
  2139. for (i=60; i>=0; i--) {
  2140. if ((e[0] >> i) != 0) {
  2141. break;
  2142. }
  2143. }
  2144. XMEMCPY(r, a, sizeof(sp_digit) * 68U);
  2145. for (i--; i>=0; i--) {
  2146. sp_2048_mont_sqr_34(r, r, m, mp);
  2147. if (((e[0] >> i) & 1) == 1) {
  2148. sp_2048_mont_mul_34(r, r, a, m, mp);
  2149. }
  2150. }
  2151. sp_2048_mont_reduce_34(r, m, mp);
  2152. mp = sp_2048_cmp_34(r, m);
  2153. sp_2048_cond_sub_34(r, r, m, ~(mp >> 63));
  2154. }
  2155. }
  2156. }
  2157. if (err == MP_OKAY) {
  2158. sp_2048_to_bin_34(r, out);
  2159. *outLen = 256;
  2160. }
  2161. #ifdef WOLFSSL_SP_SMALL_STACK
  2162. if (d != NULL)
  2163. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  2164. #endif
  2165. return err;
  2166. #endif /* WOLFSSL_SP_SMALL */
  2167. }
  2168. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  2169. #if !defined(SP_RSA_PRIVATE_EXP_D) && !defined(RSA_LOW_MEM)
  2170. #endif /* !SP_RSA_PRIVATE_EXP_D & !RSA_LOW_MEM */
  2171. /* RSA private key operation.
  2172. *
  2173. * in Array of bytes representing the number to exponentiate, base.
  2174. * inLen Number of bytes in base.
  2175. * dm Private exponent.
  2176. * pm First prime.
  2177. * qm Second prime.
  2178. * dpm First prime's CRT exponent.
  2179. * dqm Second prime's CRT exponent.
  2180. * qim Inverse of second prime mod p.
  2181. * mm Modulus.
  2182. * out Buffer to hold big-endian bytes of exponentiation result.
  2183. * Must be at least 256 bytes long.
  2184. * outLen Number of bytes in result.
  2185. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  2186. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  2187. */
  2188. int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm,
  2189. const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm,
  2190. const mp_int* qim, const mp_int* mm, byte* out, word32* outLen)
  2191. {
  2192. #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM)
  2193. #if defined(WOLFSSL_SP_SMALL)
  2194. #ifdef WOLFSSL_SP_SMALL_STACK
  2195. sp_digit* d = NULL;
  2196. #else
  2197. sp_digit d[34 * 4];
  2198. #endif
  2199. sp_digit* a = NULL;
  2200. sp_digit* m = NULL;
  2201. sp_digit* r = NULL;
  2202. int err = MP_OKAY;
  2203. (void)pm;
  2204. (void)qm;
  2205. (void)dpm;
  2206. (void)dqm;
  2207. (void)qim;
  2208. if (*outLen < 256U) {
  2209. err = MP_TO_E;
  2210. }
  2211. if (err == MP_OKAY) {
  2212. if (mp_count_bits(dm) > 2048) {
  2213. err = MP_READ_E;
  2214. }
  2215. else if (inLen > 256) {
  2216. err = MP_READ_E;
  2217. }
  2218. else if (mp_count_bits(mm) != 2048) {
  2219. err = MP_READ_E;
  2220. }
  2221. else if (mp_iseven(mm)) {
  2222. err = MP_VAL;
  2223. }
  2224. }
  2225. #ifdef WOLFSSL_SP_SMALL_STACK
  2226. if (err == MP_OKAY) {
  2227. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL,
  2228. DYNAMIC_TYPE_RSA);
  2229. if (d == NULL)
  2230. err = MEMORY_E;
  2231. }
  2232. #endif
  2233. if (err == MP_OKAY) {
  2234. a = d + 34;
  2235. m = a + 68;
  2236. r = a;
  2237. sp_2048_from_bin(a, 34, in, inLen);
  2238. sp_2048_from_mp(d, 34, dm);
  2239. sp_2048_from_mp(m, 34, mm);
  2240. err = sp_2048_mod_exp_34(r, a, d, 2048, m, 0);
  2241. }
  2242. if (err == MP_OKAY) {
  2243. sp_2048_to_bin_34(r, out);
  2244. *outLen = 256;
  2245. }
  2246. #ifdef WOLFSSL_SP_SMALL_STACK
  2247. if (d != NULL)
  2248. #endif
  2249. {
  2250. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  2251. if (a != NULL)
  2252. ForceZero(a, sizeof(sp_digit) * 34);
  2253. #ifdef WOLFSSL_SP_SMALL_STACK
  2254. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  2255. #endif
  2256. }
  2257. return err;
  2258. #else
  2259. #ifdef WOLFSSL_SP_SMALL_STACK
  2260. sp_digit* d = NULL;
  2261. #else
  2262. sp_digit d[34 * 4];
  2263. #endif
  2264. sp_digit* a = NULL;
  2265. sp_digit* m = NULL;
  2266. sp_digit* r = NULL;
  2267. int err = MP_OKAY;
  2268. (void)pm;
  2269. (void)qm;
  2270. (void)dpm;
  2271. (void)dqm;
  2272. (void)qim;
  2273. if (*outLen < 256U) {
  2274. err = MP_TO_E;
  2275. }
  2276. if (err == MP_OKAY) {
  2277. if (mp_count_bits(dm) > 2048) {
  2278. err = MP_READ_E;
  2279. }
  2280. else if (inLen > 256U) {
  2281. err = MP_READ_E;
  2282. }
  2283. else if (mp_count_bits(mm) != 2048) {
  2284. err = MP_READ_E;
  2285. }
  2286. else if (mp_iseven(mm)) {
  2287. err = MP_VAL;
  2288. }
  2289. }
  2290. #ifdef WOLFSSL_SP_SMALL_STACK
  2291. if (err == MP_OKAY) {
  2292. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL,
  2293. DYNAMIC_TYPE_RSA);
  2294. if (d == NULL)
  2295. err = MEMORY_E;
  2296. }
  2297. #endif
  2298. if (err == MP_OKAY) {
  2299. a = d + 34;
  2300. m = a + 68;
  2301. r = a;
  2302. sp_2048_from_bin(a, 34, in, inLen);
  2303. sp_2048_from_mp(d, 34, dm);
  2304. sp_2048_from_mp(m, 34, mm);
  2305. err = sp_2048_mod_exp_34(r, a, d, 2048, m, 0);
  2306. }
  2307. if (err == MP_OKAY) {
  2308. sp_2048_to_bin_34(r, out);
  2309. *outLen = 256;
  2310. }
  2311. #ifdef WOLFSSL_SP_SMALL_STACK
  2312. if (d != NULL)
  2313. #endif
  2314. {
  2315. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  2316. if (a != NULL)
  2317. ForceZero(a, sizeof(sp_digit) * 34);
  2318. #ifdef WOLFSSL_SP_SMALL_STACK
  2319. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  2320. #endif
  2321. }
  2322. return err;
  2323. #endif /* WOLFSSL_SP_SMALL */
  2324. #else
  2325. #if defined(WOLFSSL_SP_SMALL)
  2326. #ifdef WOLFSSL_SP_SMALL_STACK
  2327. sp_digit* a = NULL;
  2328. #else
  2329. sp_digit a[17 * 8];
  2330. #endif
  2331. sp_digit* p = NULL;
  2332. sp_digit* dp = NULL;
  2333. sp_digit* dq = NULL;
  2334. sp_digit* qi = NULL;
  2335. sp_digit* tmpa = NULL;
  2336. sp_digit* tmpb = NULL;
  2337. sp_digit* r = NULL;
  2338. int err = MP_OKAY;
  2339. (void)dm;
  2340. (void)mm;
  2341. if (*outLen < 256U) {
  2342. err = MP_TO_E;
  2343. }
  2344. if (err == MP_OKAY) {
  2345. if (inLen > 256) {
  2346. err = MP_READ_E;
  2347. }
  2348. else if (mp_count_bits(mm) != 2048) {
  2349. err = MP_READ_E;
  2350. }
  2351. else if (mp_iseven(mm)) {
  2352. err = MP_VAL;
  2353. }
  2354. else if (mp_iseven(pm)) {
  2355. err = MP_VAL;
  2356. }
  2357. else if (mp_iseven(qm)) {
  2358. err = MP_VAL;
  2359. }
  2360. }
  2361. #ifdef WOLFSSL_SP_SMALL_STACK
  2362. if (err == MP_OKAY) {
  2363. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 8, NULL,
  2364. DYNAMIC_TYPE_RSA);
  2365. if (a == NULL)
  2366. err = MEMORY_E;
  2367. }
  2368. #endif
  2369. if (err == MP_OKAY) {
  2370. p = a + 34;
  2371. qi = dq = dp = p + 17;
  2372. tmpa = qi + 17;
  2373. tmpb = tmpa + 34;
  2374. r = a;
  2375. sp_2048_from_bin(a, 34, in, inLen);
  2376. sp_2048_from_mp(p, 17, pm);
  2377. sp_2048_from_mp(dp, 17, dpm);
  2378. err = sp_2048_mod_exp_17(tmpa, a, dp, 1024, p, 1);
  2379. }
  2380. if (err == MP_OKAY) {
  2381. sp_2048_from_mp(p, 17, qm);
  2382. sp_2048_from_mp(dq, 17, dqm);
  2383. err = sp_2048_mod_exp_17(tmpb, a, dq, 1024, p, 1);
  2384. }
  2385. if (err == MP_OKAY) {
  2386. sp_2048_from_mp(p, 17, pm);
  2387. (void)sp_2048_sub_17(tmpa, tmpa, tmpb);
  2388. sp_2048_norm_17(tmpa);
  2389. sp_2048_cond_add_17(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[16] >> 63));
  2390. sp_2048_cond_add_17(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[16] >> 63));
  2391. sp_2048_norm_17(tmpa);
  2392. sp_2048_from_mp(qi, 17, qim);
  2393. sp_2048_mul_17(tmpa, tmpa, qi);
  2394. err = sp_2048_mod_17(tmpa, tmpa, p);
  2395. }
  2396. if (err == MP_OKAY) {
  2397. sp_2048_from_mp(p, 17, qm);
  2398. sp_2048_mul_17(tmpa, p, tmpa);
  2399. (void)sp_2048_add_34(r, tmpb, tmpa);
  2400. sp_2048_norm_34(r);
  2401. sp_2048_to_bin_34(r, out);
  2402. *outLen = 256;
  2403. }
  2404. #ifdef WOLFSSL_SP_SMALL_STACK
  2405. if (a != NULL)
  2406. #endif
  2407. {
  2408. ForceZero(a, sizeof(sp_digit) * 17 * 8);
  2409. #ifdef WOLFSSL_SP_SMALL_STACK
  2410. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  2411. #endif
  2412. }
  2413. return err;
  2414. #else
  2415. #ifdef WOLFSSL_SP_SMALL_STACK
  2416. sp_digit* a = NULL;
  2417. #else
  2418. sp_digit a[17 * 13];
  2419. #endif
  2420. sp_digit* p = NULL;
  2421. sp_digit* q = NULL;
  2422. sp_digit* dp = NULL;
  2423. sp_digit* dq = NULL;
  2424. sp_digit* qi = NULL;
  2425. sp_digit* tmpa = NULL;
  2426. sp_digit* tmpb = NULL;
  2427. sp_digit* r = NULL;
  2428. int err = MP_OKAY;
  2429. (void)dm;
  2430. (void)mm;
  2431. if (*outLen < 256U) {
  2432. err = MP_TO_E;
  2433. }
  2434. if (err == MP_OKAY) {
  2435. if (inLen > 256U) {
  2436. err = MP_READ_E;
  2437. }
  2438. else if (mp_count_bits(mm) != 2048) {
  2439. err = MP_READ_E;
  2440. }
  2441. else if (mp_iseven(mm)) {
  2442. err = MP_VAL;
  2443. }
  2444. else if (mp_iseven(pm)) {
  2445. err = MP_VAL;
  2446. }
  2447. else if (mp_iseven(qm)) {
  2448. err = MP_VAL;
  2449. }
  2450. }
  2451. #ifdef WOLFSSL_SP_SMALL_STACK
  2452. if (err == MP_OKAY) {
  2453. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 13, NULL,
  2454. DYNAMIC_TYPE_RSA);
  2455. if (a == NULL)
  2456. err = MEMORY_E;
  2457. }
  2458. #endif
  2459. if (err == MP_OKAY) {
  2460. p = a + 34 * 2;
  2461. q = p + 17;
  2462. dp = q + 17;
  2463. dq = dp + 17;
  2464. qi = dq + 17;
  2465. tmpa = qi + 17;
  2466. tmpb = tmpa + 34;
  2467. r = a;
  2468. sp_2048_from_bin(a, 34, in, inLen);
  2469. sp_2048_from_mp(p, 17, pm);
  2470. sp_2048_from_mp(q, 17, qm);
  2471. sp_2048_from_mp(dp, 17, dpm);
  2472. sp_2048_from_mp(dq, 17, dqm);
  2473. sp_2048_from_mp(qi, 17, qim);
  2474. err = sp_2048_mod_exp_17(tmpa, a, dp, 1024, p, 1);
  2475. }
  2476. if (err == MP_OKAY) {
  2477. err = sp_2048_mod_exp_17(tmpb, a, dq, 1024, q, 1);
  2478. }
  2479. if (err == MP_OKAY) {
  2480. (void)sp_2048_sub_17(tmpa, tmpa, tmpb);
  2481. sp_2048_norm_17(tmpa);
  2482. sp_2048_cond_add_17(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[16] >> 63));
  2483. sp_2048_cond_add_17(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[16] >> 63));
  2484. sp_2048_norm_17(tmpa);
  2485. sp_2048_mul_17(tmpa, tmpa, qi);
  2486. err = sp_2048_mod_17(tmpa, tmpa, p);
  2487. }
  2488. if (err == MP_OKAY) {
  2489. sp_2048_mul_17(tmpa, tmpa, q);
  2490. (void)sp_2048_add_34(r, tmpb, tmpa);
  2491. sp_2048_norm_34(r);
  2492. sp_2048_to_bin_34(r, out);
  2493. *outLen = 256;
  2494. }
  2495. #ifdef WOLFSSL_SP_SMALL_STACK
  2496. if (a != NULL)
  2497. #endif
  2498. {
  2499. ForceZero(a, sizeof(sp_digit) * 17 * 13);
  2500. #ifdef WOLFSSL_SP_SMALL_STACK
  2501. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  2502. #endif
  2503. }
  2504. return err;
  2505. #endif /* WOLFSSL_SP_SMALL */
  2506. #endif /* SP_RSA_PRIVATE_EXP_D || RSA_LOW_MEM */
  2507. }
  2508. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  2509. #endif /* WOLFSSL_HAVE_SP_RSA */
  2510. #if defined(WOLFSSL_HAVE_SP_DH) || (defined(WOLFSSL_HAVE_SP_RSA) && \
  2511. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  2512. /* Convert an array of sp_digit to an mp_int.
  2513. *
  2514. * a A single precision integer.
  2515. * r A multi-precision integer.
  2516. */
  2517. static int sp_2048_to_mp(const sp_digit* a, mp_int* r)
  2518. {
  2519. int err;
  2520. err = mp_grow(r, (2048 + DIGIT_BIT - 1) / DIGIT_BIT);
  2521. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  2522. #if DIGIT_BIT == 61
  2523. XMEMCPY(r->dp, a, sizeof(sp_digit) * 34);
  2524. r->used = 34;
  2525. mp_clamp(r);
  2526. #elif DIGIT_BIT < 61
  2527. int i;
  2528. int j = 0;
  2529. int s = 0;
  2530. r->dp[0] = 0;
  2531. for (i = 0; i < 34; i++) {
  2532. r->dp[j] |= (mp_digit)(a[i] << s);
  2533. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  2534. s = DIGIT_BIT - s;
  2535. r->dp[++j] = (mp_digit)(a[i] >> s);
  2536. while (s + DIGIT_BIT <= 61) {
  2537. s += DIGIT_BIT;
  2538. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  2539. if (s == SP_WORD_SIZE) {
  2540. r->dp[j] = 0;
  2541. }
  2542. else {
  2543. r->dp[j] = (mp_digit)(a[i] >> s);
  2544. }
  2545. }
  2546. s = 61 - s;
  2547. }
  2548. r->used = (2048 + DIGIT_BIT - 1) / DIGIT_BIT;
  2549. mp_clamp(r);
  2550. #else
  2551. int i;
  2552. int j = 0;
  2553. int s = 0;
  2554. r->dp[0] = 0;
  2555. for (i = 0; i < 34; i++) {
  2556. r->dp[j] |= ((mp_digit)a[i]) << s;
  2557. if (s + 61 >= DIGIT_BIT) {
  2558. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  2559. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  2560. #endif
  2561. s = DIGIT_BIT - s;
  2562. r->dp[++j] = a[i] >> s;
  2563. s = 61 - s;
  2564. }
  2565. else {
  2566. s += 61;
  2567. }
  2568. }
  2569. r->used = (2048 + DIGIT_BIT - 1) / DIGIT_BIT;
  2570. mp_clamp(r);
  2571. #endif
  2572. }
  2573. return err;
  2574. }
  2575. /* Perform the modular exponentiation for Diffie-Hellman.
  2576. *
  2577. * base Base. MP integer.
  2578. * exp Exponent. MP integer.
  2579. * mod Modulus. MP integer.
  2580. * res Result. MP integer.
  2581. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  2582. * and MEMORY_E if memory allocation fails.
  2583. */
  2584. int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod,
  2585. mp_int* res)
  2586. {
  2587. #ifdef WOLFSSL_SP_SMALL
  2588. int err = MP_OKAY;
  2589. #ifdef WOLFSSL_SP_SMALL_STACK
  2590. sp_digit* b = NULL;
  2591. #else
  2592. sp_digit b[34 * 4];
  2593. #endif
  2594. sp_digit* e = NULL;
  2595. sp_digit* m = NULL;
  2596. sp_digit* r = NULL;
  2597. int expBits = mp_count_bits(exp);
  2598. if (mp_count_bits(base) > 2048) {
  2599. err = MP_READ_E;
  2600. }
  2601. else if (expBits > 2048) {
  2602. err = MP_READ_E;
  2603. }
  2604. else if (mp_count_bits(mod) != 2048) {
  2605. err = MP_READ_E;
  2606. }
  2607. else if (mp_iseven(mod)) {
  2608. err = MP_VAL;
  2609. }
  2610. #ifdef WOLFSSL_SP_SMALL_STACK
  2611. if (err == MP_OKAY) {
  2612. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL,
  2613. DYNAMIC_TYPE_DH);
  2614. if (b == NULL)
  2615. err = MEMORY_E;
  2616. }
  2617. #endif
  2618. if (err == MP_OKAY) {
  2619. e = b + 34 * 2;
  2620. m = e + 34;
  2621. r = b;
  2622. sp_2048_from_mp(b, 34, base);
  2623. sp_2048_from_mp(e, 34, exp);
  2624. sp_2048_from_mp(m, 34, mod);
  2625. err = sp_2048_mod_exp_34(r, b, e, mp_count_bits(exp), m, 0);
  2626. }
  2627. if (err == MP_OKAY) {
  2628. err = sp_2048_to_mp(r, res);
  2629. }
  2630. #ifdef WOLFSSL_SP_SMALL_STACK
  2631. if (b != NULL)
  2632. #endif
  2633. {
  2634. /* only "e" is sensitive and needs zeroized */
  2635. if (e != NULL)
  2636. ForceZero(e, sizeof(sp_digit) * 34U);
  2637. #ifdef WOLFSSL_SP_SMALL_STACK
  2638. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  2639. #endif
  2640. }
  2641. return err;
  2642. #else
  2643. #ifdef WOLFSSL_SP_SMALL_STACK
  2644. sp_digit* b = NULL;
  2645. #else
  2646. sp_digit b[34 * 4];
  2647. #endif
  2648. sp_digit* e = NULL;
  2649. sp_digit* m = NULL;
  2650. sp_digit* r = NULL;
  2651. int err = MP_OKAY;
  2652. int expBits = mp_count_bits(exp);
  2653. if (mp_count_bits(base) > 2048) {
  2654. err = MP_READ_E;
  2655. }
  2656. else if (expBits > 2048) {
  2657. err = MP_READ_E;
  2658. }
  2659. else if (mp_count_bits(mod) != 2048) {
  2660. err = MP_READ_E;
  2661. }
  2662. else if (mp_iseven(mod)) {
  2663. err = MP_VAL;
  2664. }
  2665. #ifdef WOLFSSL_SP_SMALL_STACK
  2666. if (err == MP_OKAY) {
  2667. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL, DYNAMIC_TYPE_DH);
  2668. if (b == NULL)
  2669. err = MEMORY_E;
  2670. }
  2671. #endif
  2672. if (err == MP_OKAY) {
  2673. e = b + 34 * 2;
  2674. m = e + 34;
  2675. r = b;
  2676. sp_2048_from_mp(b, 34, base);
  2677. sp_2048_from_mp(e, 34, exp);
  2678. sp_2048_from_mp(m, 34, mod);
  2679. err = sp_2048_mod_exp_34(r, b, e, expBits, m, 0);
  2680. }
  2681. if (err == MP_OKAY) {
  2682. err = sp_2048_to_mp(r, res);
  2683. }
  2684. #ifdef WOLFSSL_SP_SMALL_STACK
  2685. if (b != NULL)
  2686. #endif
  2687. {
  2688. /* only "e" is sensitive and needs zeroized */
  2689. if (e != NULL)
  2690. ForceZero(e, sizeof(sp_digit) * 34U);
  2691. #ifdef WOLFSSL_SP_SMALL_STACK
  2692. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  2693. #endif
  2694. }
  2695. return err;
  2696. #endif
  2697. }
  2698. #ifdef WOLFSSL_HAVE_SP_DH
  2699. #ifdef HAVE_FFDHE_2048
  2700. SP_NOINLINE static void sp_2048_lshift_34(sp_digit* r, const sp_digit* a,
  2701. byte n)
  2702. {
  2703. int i;
  2704. r[34] = a[33] >> (61 - n);
  2705. for (i=33; i>0; i--) {
  2706. r[i] = ((a[i] << n) | (a[i-1] >> (61 - n))) & 0x1fffffffffffffffL;
  2707. }
  2708. r[0] = (a[0] << n) & 0x1fffffffffffffffL;
  2709. }
  2710. /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m)
  2711. *
  2712. * r A single precision number that is the result of the operation.
  2713. * e A single precision number that is the exponent.
  2714. * bits The number of bits in the exponent.
  2715. * m A single precision number that is the modulus.
  2716. * returns 0 on success.
  2717. * returns MEMORY_E on dynamic memory allocation failure.
  2718. * returns MP_VAL when base is even.
  2719. */
  2720. static int sp_2048_mod_exp_2_34(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
  2721. {
  2722. #ifdef WOLFSSL_SP_SMALL_STACK
  2723. sp_digit* td = NULL;
  2724. #else
  2725. sp_digit td[103];
  2726. #endif
  2727. sp_digit* norm = NULL;
  2728. sp_digit* tmp = NULL;
  2729. sp_digit mp = 1;
  2730. sp_digit n;
  2731. sp_digit o;
  2732. int i;
  2733. int c;
  2734. byte y;
  2735. int err = MP_OKAY;
  2736. if (bits == 0) {
  2737. err = MP_VAL;
  2738. }
  2739. #ifdef WOLFSSL_SP_SMALL_STACK
  2740. if (err == MP_OKAY) {
  2741. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 103, NULL,
  2742. DYNAMIC_TYPE_TMP_BUFFER);
  2743. if (td == NULL)
  2744. err = MEMORY_E;
  2745. }
  2746. #endif
  2747. if (err == MP_OKAY) {
  2748. norm = td;
  2749. tmp = td + 68;
  2750. XMEMSET(td, 0, sizeof(sp_digit) * 103);
  2751. sp_2048_mont_setup(m, &mp);
  2752. sp_2048_mont_norm_34(norm, m);
  2753. bits = ((bits + 4) / 5) * 5;
  2754. i = ((bits + 60) / 61) - 1;
  2755. c = bits % 61;
  2756. if (c == 0) {
  2757. c = 61;
  2758. }
  2759. if (i < 34) {
  2760. n = e[i--] << (64 - c);
  2761. }
  2762. else {
  2763. n = 0;
  2764. i--;
  2765. }
  2766. if (c < 5) {
  2767. n |= e[i--] << (3 - c);
  2768. c += 61;
  2769. }
  2770. y = (int)((n >> 59) & 0x1f);
  2771. n <<= 5;
  2772. c -= 5;
  2773. sp_2048_lshift_34(r, norm, (byte)y);
  2774. while ((i >= 0) || (c >= 5)) {
  2775. if (c >= 5) {
  2776. y = (byte)((n >> 59) & 0x1f);
  2777. n <<= 5;
  2778. c -= 5;
  2779. }
  2780. else if (c == 0) {
  2781. n = e[i--] << 3;
  2782. y = (byte)((n >> 59) & 0x1f);
  2783. n <<= 5;
  2784. c = 56;
  2785. }
  2786. else {
  2787. y = (byte)((n >> 59) & 0x1f);
  2788. n = e[i--] << 3;
  2789. c = 5 - c;
  2790. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  2791. n <<= c;
  2792. c = 61 - c;
  2793. }
  2794. sp_2048_mont_sqr_34(r, r, m, mp);
  2795. sp_2048_mont_sqr_34(r, r, m, mp);
  2796. sp_2048_mont_sqr_34(r, r, m, mp);
  2797. sp_2048_mont_sqr_34(r, r, m, mp);
  2798. sp_2048_mont_sqr_34(r, r, m, mp);
  2799. sp_2048_lshift_34(r, r, (byte)y);
  2800. sp_2048_mul_d_34(tmp, norm, (r[34] << 26) + (r[33] >> 35));
  2801. r[34] = 0;
  2802. r[33] &= 0x7ffffffffL;
  2803. (void)sp_2048_add_34(r, r, tmp);
  2804. sp_2048_norm_34(r);
  2805. o = sp_2048_cmp_34(r, m);
  2806. sp_2048_cond_sub_34(r, r, m, ~(o >> 63));
  2807. }
  2808. sp_2048_mont_reduce_34(r, m, mp);
  2809. n = sp_2048_cmp_34(r, m);
  2810. sp_2048_cond_sub_34(r, r, m, ~(n >> 63));
  2811. }
  2812. #ifdef WOLFSSL_SP_SMALL_STACK
  2813. if (td != NULL)
  2814. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  2815. #endif
  2816. return err;
  2817. }
  2818. #endif /* HAVE_FFDHE_2048 */
  2819. /* Perform the modular exponentiation for Diffie-Hellman.
  2820. *
  2821. * base Base.
  2822. * exp Array of bytes that is the exponent.
  2823. * expLen Length of data, in bytes, in exponent.
  2824. * mod Modulus.
  2825. * out Buffer to hold big-endian bytes of exponentiation result.
  2826. * Must be at least 256 bytes long.
  2827. * outLen Length, in bytes, of exponentiation result.
  2828. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  2829. * and MEMORY_E if memory allocation fails.
  2830. */
  2831. int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen,
  2832. const mp_int* mod, byte* out, word32* outLen)
  2833. {
  2834. #ifdef WOLFSSL_SP_SMALL_STACK
  2835. sp_digit* b = NULL;
  2836. #else
  2837. sp_digit b[34 * 4];
  2838. #endif
  2839. sp_digit* e = NULL;
  2840. sp_digit* m = NULL;
  2841. sp_digit* r = NULL;
  2842. word32 i;
  2843. int err = MP_OKAY;
  2844. if (mp_count_bits(base) > 2048) {
  2845. err = MP_READ_E;
  2846. }
  2847. else if (expLen > 256U) {
  2848. err = MP_READ_E;
  2849. }
  2850. else if (mp_count_bits(mod) != 2048) {
  2851. err = MP_READ_E;
  2852. }
  2853. else if (mp_iseven(mod)) {
  2854. err = MP_VAL;
  2855. }
  2856. #ifdef WOLFSSL_SP_SMALL_STACK
  2857. if (err == MP_OKAY) {
  2858. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL,
  2859. DYNAMIC_TYPE_DH);
  2860. if (b == NULL)
  2861. err = MEMORY_E;
  2862. }
  2863. #endif
  2864. if (err == MP_OKAY) {
  2865. e = b + 34 * 2;
  2866. m = e + 34;
  2867. r = b;
  2868. sp_2048_from_mp(b, 34, base);
  2869. sp_2048_from_bin(e, 34, exp, expLen);
  2870. sp_2048_from_mp(m, 34, mod);
  2871. #ifdef HAVE_FFDHE_2048
  2872. if (base->used == 1 && base->dp[0] == 2U &&
  2873. (m[33] >> 3) == 0xffffffffL) {
  2874. err = sp_2048_mod_exp_2_34(r, e, expLen * 8U, m);
  2875. }
  2876. else {
  2877. #endif
  2878. err = sp_2048_mod_exp_34(r, b, e, expLen * 8U, m, 0);
  2879. #ifdef HAVE_FFDHE_2048
  2880. }
  2881. #endif
  2882. }
  2883. if (err == MP_OKAY) {
  2884. sp_2048_to_bin_34(r, out);
  2885. *outLen = 256;
  2886. for (i=0; i<256U && out[i] == 0U; i++) {
  2887. /* Search for first non-zero. */
  2888. }
  2889. *outLen -= i;
  2890. XMEMMOVE(out, out + i, *outLen);
  2891. }
  2892. #ifdef WOLFSSL_SP_SMALL_STACK
  2893. if (b != NULL)
  2894. #endif
  2895. {
  2896. /* only "e" is sensitive and needs zeroized */
  2897. if (e != NULL)
  2898. ForceZero(e, sizeof(sp_digit) * 34U);
  2899. #ifdef WOLFSSL_SP_SMALL_STACK
  2900. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  2901. #endif
  2902. }
  2903. return err;
  2904. }
  2905. #endif /* WOLFSSL_HAVE_SP_DH */
  2906. /* Perform the modular exponentiation for Diffie-Hellman.
  2907. *
  2908. * base Base. MP integer.
  2909. * exp Exponent. MP integer.
  2910. * mod Modulus. MP integer.
  2911. * res Result. MP integer.
  2912. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  2913. * and MEMORY_E if memory allocation fails.
  2914. */
  2915. int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod,
  2916. mp_int* res)
  2917. {
  2918. #ifdef WOLFSSL_SP_SMALL
  2919. int err = MP_OKAY;
  2920. #ifdef WOLFSSL_SP_SMALL_STACK
  2921. sp_digit* b = NULL;
  2922. #else
  2923. sp_digit b[17 * 4];
  2924. #endif
  2925. sp_digit* e = NULL;
  2926. sp_digit* m = NULL;
  2927. sp_digit* r = NULL;
  2928. int expBits = mp_count_bits(exp);
  2929. if (mp_count_bits(base) > 1024) {
  2930. err = MP_READ_E;
  2931. }
  2932. else if (expBits > 1024) {
  2933. err = MP_READ_E;
  2934. }
  2935. else if (mp_count_bits(mod) != 1024) {
  2936. err = MP_READ_E;
  2937. }
  2938. else if (mp_iseven(mod)) {
  2939. err = MP_VAL;
  2940. }
  2941. #ifdef WOLFSSL_SP_SMALL_STACK
  2942. if (err == MP_OKAY) {
  2943. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 4, NULL,
  2944. DYNAMIC_TYPE_DH);
  2945. if (b == NULL)
  2946. err = MEMORY_E;
  2947. }
  2948. #endif
  2949. if (err == MP_OKAY) {
  2950. e = b + 17 * 2;
  2951. m = e + 17;
  2952. r = b;
  2953. sp_2048_from_mp(b, 17, base);
  2954. sp_2048_from_mp(e, 17, exp);
  2955. sp_2048_from_mp(m, 17, mod);
  2956. err = sp_2048_mod_exp_17(r, b, e, mp_count_bits(exp), m, 0);
  2957. }
  2958. if (err == MP_OKAY) {
  2959. XMEMSET(r + 17, 0, sizeof(*r) * 17U);
  2960. err = sp_2048_to_mp(r, res);
  2961. }
  2962. #ifdef WOLFSSL_SP_SMALL_STACK
  2963. if (b != NULL)
  2964. #endif
  2965. {
  2966. /* only "e" is sensitive and needs zeroized */
  2967. if (e != NULL)
  2968. ForceZero(e, sizeof(sp_digit) * 34U);
  2969. #ifdef WOLFSSL_SP_SMALL_STACK
  2970. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  2971. #endif
  2972. }
  2973. return err;
  2974. #else
  2975. #ifdef WOLFSSL_SP_SMALL_STACK
  2976. sp_digit* b = NULL;
  2977. #else
  2978. sp_digit b[17 * 4];
  2979. #endif
  2980. sp_digit* e = NULL;
  2981. sp_digit* m = NULL;
  2982. sp_digit* r = NULL;
  2983. int err = MP_OKAY;
  2984. int expBits = mp_count_bits(exp);
  2985. if (mp_count_bits(base) > 1024) {
  2986. err = MP_READ_E;
  2987. }
  2988. else if (expBits > 1024) {
  2989. err = MP_READ_E;
  2990. }
  2991. else if (mp_count_bits(mod) != 1024) {
  2992. err = MP_READ_E;
  2993. }
  2994. else if (mp_iseven(mod)) {
  2995. err = MP_VAL;
  2996. }
  2997. #ifdef WOLFSSL_SP_SMALL_STACK
  2998. if (err == MP_OKAY) {
  2999. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 4, NULL, DYNAMIC_TYPE_DH);
  3000. if (b == NULL)
  3001. err = MEMORY_E;
  3002. }
  3003. #endif
  3004. if (err == MP_OKAY) {
  3005. e = b + 17 * 2;
  3006. m = e + 17;
  3007. r = b;
  3008. sp_2048_from_mp(b, 17, base);
  3009. sp_2048_from_mp(e, 17, exp);
  3010. sp_2048_from_mp(m, 17, mod);
  3011. err = sp_2048_mod_exp_17(r, b, e, expBits, m, 0);
  3012. }
  3013. if (err == MP_OKAY) {
  3014. XMEMSET(r + 17, 0, sizeof(*r) * 17U);
  3015. err = sp_2048_to_mp(r, res);
  3016. }
  3017. #ifdef WOLFSSL_SP_SMALL_STACK
  3018. if (b != NULL)
  3019. #endif
  3020. {
  3021. /* only "e" is sensitive and needs zeroized */
  3022. if (e != NULL)
  3023. ForceZero(e, sizeof(sp_digit) * 34U);
  3024. #ifdef WOLFSSL_SP_SMALL_STACK
  3025. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  3026. #endif
  3027. }
  3028. return err;
  3029. #endif
  3030. }
  3031. #endif /* WOLFSSL_HAVE_SP_DH | (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) */
  3032. #else
  3033. /* Read big endian unsigned byte array into r.
  3034. *
  3035. * r A single precision integer.
  3036. * size Maximum number of bytes to convert
  3037. * a Byte array.
  3038. * n Number of bytes in array to read.
  3039. */
  3040. static void sp_2048_from_bin(sp_digit* r, int size, const byte* a, int n)
  3041. {
  3042. int i;
  3043. int j = 0;
  3044. word32 s = 0;
  3045. r[0] = 0;
  3046. for (i = n-1; i >= 0; i--) {
  3047. r[j] |= (((sp_digit)a[i]) << s);
  3048. if (s >= 49U) {
  3049. r[j] &= 0x1ffffffffffffffL;
  3050. s = 57U - s;
  3051. if (j + 1 >= size) {
  3052. break;
  3053. }
  3054. r[++j] = (sp_digit)a[i] >> s;
  3055. s = 8U - s;
  3056. }
  3057. else {
  3058. s += 8U;
  3059. }
  3060. }
  3061. for (j++; j < size; j++) {
  3062. r[j] = 0;
  3063. }
  3064. }
  3065. /* Convert an mp_int to an array of sp_digit.
  3066. *
  3067. * r A single precision integer.
  3068. * size Maximum number of bytes to convert
  3069. * a A multi-precision integer.
  3070. */
  3071. static void sp_2048_from_mp(sp_digit* r, int size, const mp_int* a)
  3072. {
  3073. #if DIGIT_BIT == 57
  3074. int i;
  3075. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  3076. int o = 0;
  3077. for (i = 0; i < size; i++) {
  3078. sp_digit mask = (sp_digit)0 - (j >> 56);
  3079. r[i] = a->dp[o] & mask;
  3080. j++;
  3081. o += (int)(j >> 56);
  3082. }
  3083. #elif DIGIT_BIT > 57
  3084. unsigned int i;
  3085. int j = 0;
  3086. word32 s = 0;
  3087. r[0] = 0;
  3088. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  3089. r[j] |= ((sp_digit)a->dp[i] << s);
  3090. r[j] &= 0x1ffffffffffffffL;
  3091. s = 57U - s;
  3092. if (j + 1 >= size) {
  3093. break;
  3094. }
  3095. /* lint allow cast of mismatch word32 and mp_digit */
  3096. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  3097. while ((s + 57U) <= (word32)DIGIT_BIT) {
  3098. s += 57U;
  3099. r[j] &= 0x1ffffffffffffffL;
  3100. if (j + 1 >= size) {
  3101. break;
  3102. }
  3103. if (s < (word32)DIGIT_BIT) {
  3104. /* lint allow cast of mismatch word32 and mp_digit */
  3105. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  3106. }
  3107. else {
  3108. r[++j] = (sp_digit)0;
  3109. }
  3110. }
  3111. s = (word32)DIGIT_BIT - s;
  3112. }
  3113. for (j++; j < size; j++) {
  3114. r[j] = 0;
  3115. }
  3116. #else
  3117. unsigned int i;
  3118. int j = 0;
  3119. int s = 0;
  3120. r[0] = 0;
  3121. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  3122. r[j] |= ((sp_digit)a->dp[i]) << s;
  3123. if (s + DIGIT_BIT >= 57) {
  3124. r[j] &= 0x1ffffffffffffffL;
  3125. if (j + 1 >= size) {
  3126. break;
  3127. }
  3128. s = 57 - s;
  3129. if (s == DIGIT_BIT) {
  3130. r[++j] = 0;
  3131. s = 0;
  3132. }
  3133. else {
  3134. r[++j] = a->dp[i] >> s;
  3135. s = DIGIT_BIT - s;
  3136. }
  3137. }
  3138. else {
  3139. s += DIGIT_BIT;
  3140. }
  3141. }
  3142. for (j++; j < size; j++) {
  3143. r[j] = 0;
  3144. }
  3145. #endif
  3146. }
  3147. /* Write r as big endian to byte array.
  3148. * Fixed length number of bytes written: 256
  3149. *
  3150. * r A single precision integer.
  3151. * a Byte array.
  3152. */
  3153. static void sp_2048_to_bin_36(sp_digit* r, byte* a)
  3154. {
  3155. int i;
  3156. int j;
  3157. int s = 0;
  3158. int b;
  3159. for (i=0; i<35; i++) {
  3160. r[i+1] += r[i] >> 57;
  3161. r[i] &= 0x1ffffffffffffffL;
  3162. }
  3163. j = 2055 / 8 - 1;
  3164. a[j] = 0;
  3165. for (i=0; i<36 && j>=0; i++) {
  3166. b = 0;
  3167. /* lint allow cast of mismatch sp_digit and int */
  3168. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  3169. b += 8 - s;
  3170. if (j < 0) {
  3171. break;
  3172. }
  3173. while (b < 57) {
  3174. a[j--] = (byte)(r[i] >> b);
  3175. b += 8;
  3176. if (j < 0) {
  3177. break;
  3178. }
  3179. }
  3180. s = 8 - (b - 57);
  3181. if (j >= 0) {
  3182. a[j] = 0;
  3183. }
  3184. if (s != 0) {
  3185. j++;
  3186. }
  3187. }
  3188. }
  3189. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  3190. /* Normalize the values in each word to 57 bits.
  3191. *
  3192. * a Array of sp_digit to normalize.
  3193. */
  3194. static void sp_2048_norm_18(sp_digit* a)
  3195. {
  3196. int i;
  3197. for (i = 0; i < 16; i += 8) {
  3198. a[i+1] += a[i+0] >> 57; a[i+0] &= 0x1ffffffffffffffL;
  3199. a[i+2] += a[i+1] >> 57; a[i+1] &= 0x1ffffffffffffffL;
  3200. a[i+3] += a[i+2] >> 57; a[i+2] &= 0x1ffffffffffffffL;
  3201. a[i+4] += a[i+3] >> 57; a[i+3] &= 0x1ffffffffffffffL;
  3202. a[i+5] += a[i+4] >> 57; a[i+4] &= 0x1ffffffffffffffL;
  3203. a[i+6] += a[i+5] >> 57; a[i+5] &= 0x1ffffffffffffffL;
  3204. a[i+7] += a[i+6] >> 57; a[i+6] &= 0x1ffffffffffffffL;
  3205. a[i+8] += a[i+7] >> 57; a[i+7] &= 0x1ffffffffffffffL;
  3206. }
  3207. a[17] += a[16] >> 57; a[16] &= 0x1ffffffffffffffL;
  3208. }
  3209. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  3210. /* Normalize the values in each word to 57 bits.
  3211. *
  3212. * a Array of sp_digit to normalize.
  3213. */
  3214. static void sp_2048_norm_36(sp_digit* a)
  3215. {
  3216. int i;
  3217. for (i = 0; i < 32; i += 8) {
  3218. a[i+1] += a[i+0] >> 57; a[i+0] &= 0x1ffffffffffffffL;
  3219. a[i+2] += a[i+1] >> 57; a[i+1] &= 0x1ffffffffffffffL;
  3220. a[i+3] += a[i+2] >> 57; a[i+2] &= 0x1ffffffffffffffL;
  3221. a[i+4] += a[i+3] >> 57; a[i+3] &= 0x1ffffffffffffffL;
  3222. a[i+5] += a[i+4] >> 57; a[i+4] &= 0x1ffffffffffffffL;
  3223. a[i+6] += a[i+5] >> 57; a[i+5] &= 0x1ffffffffffffffL;
  3224. a[i+7] += a[i+6] >> 57; a[i+6] &= 0x1ffffffffffffffL;
  3225. a[i+8] += a[i+7] >> 57; a[i+7] &= 0x1ffffffffffffffL;
  3226. }
  3227. a[33] += a[32] >> 57; a[32] &= 0x1ffffffffffffffL;
  3228. a[34] += a[33] >> 57; a[33] &= 0x1ffffffffffffffL;
  3229. a[35] += a[34] >> 57; a[34] &= 0x1ffffffffffffffL;
  3230. }
  3231. #ifndef WOLFSSL_SP_SMALL
  3232. /* Multiply a and b into r. (r = a * b)
  3233. *
  3234. * r A single precision integer.
  3235. * a A single precision integer.
  3236. * b A single precision integer.
  3237. */
  3238. SP_NOINLINE static void sp_2048_mul_9(sp_digit* r, const sp_digit* a,
  3239. const sp_digit* b)
  3240. {
  3241. sp_uint128 t0;
  3242. sp_uint128 t1;
  3243. sp_digit t[9];
  3244. t0 = ((sp_uint128)a[ 0]) * b[ 0];
  3245. t1 = ((sp_uint128)a[ 0]) * b[ 1]
  3246. + ((sp_uint128)a[ 1]) * b[ 0];
  3247. t[ 0] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3248. t0 = ((sp_uint128)a[ 0]) * b[ 2]
  3249. + ((sp_uint128)a[ 1]) * b[ 1]
  3250. + ((sp_uint128)a[ 2]) * b[ 0];
  3251. t[ 1] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3252. t1 = ((sp_uint128)a[ 0]) * b[ 3]
  3253. + ((sp_uint128)a[ 1]) * b[ 2]
  3254. + ((sp_uint128)a[ 2]) * b[ 1]
  3255. + ((sp_uint128)a[ 3]) * b[ 0];
  3256. t[ 2] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3257. t0 = ((sp_uint128)a[ 0]) * b[ 4]
  3258. + ((sp_uint128)a[ 1]) * b[ 3]
  3259. + ((sp_uint128)a[ 2]) * b[ 2]
  3260. + ((sp_uint128)a[ 3]) * b[ 1]
  3261. + ((sp_uint128)a[ 4]) * b[ 0];
  3262. t[ 3] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3263. t1 = ((sp_uint128)a[ 0]) * b[ 5]
  3264. + ((sp_uint128)a[ 1]) * b[ 4]
  3265. + ((sp_uint128)a[ 2]) * b[ 3]
  3266. + ((sp_uint128)a[ 3]) * b[ 2]
  3267. + ((sp_uint128)a[ 4]) * b[ 1]
  3268. + ((sp_uint128)a[ 5]) * b[ 0];
  3269. t[ 4] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3270. t0 = ((sp_uint128)a[ 0]) * b[ 6]
  3271. + ((sp_uint128)a[ 1]) * b[ 5]
  3272. + ((sp_uint128)a[ 2]) * b[ 4]
  3273. + ((sp_uint128)a[ 3]) * b[ 3]
  3274. + ((sp_uint128)a[ 4]) * b[ 2]
  3275. + ((sp_uint128)a[ 5]) * b[ 1]
  3276. + ((sp_uint128)a[ 6]) * b[ 0];
  3277. t[ 5] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3278. t1 = ((sp_uint128)a[ 0]) * b[ 7]
  3279. + ((sp_uint128)a[ 1]) * b[ 6]
  3280. + ((sp_uint128)a[ 2]) * b[ 5]
  3281. + ((sp_uint128)a[ 3]) * b[ 4]
  3282. + ((sp_uint128)a[ 4]) * b[ 3]
  3283. + ((sp_uint128)a[ 5]) * b[ 2]
  3284. + ((sp_uint128)a[ 6]) * b[ 1]
  3285. + ((sp_uint128)a[ 7]) * b[ 0];
  3286. t[ 6] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3287. t0 = ((sp_uint128)a[ 0]) * b[ 8]
  3288. + ((sp_uint128)a[ 1]) * b[ 7]
  3289. + ((sp_uint128)a[ 2]) * b[ 6]
  3290. + ((sp_uint128)a[ 3]) * b[ 5]
  3291. + ((sp_uint128)a[ 4]) * b[ 4]
  3292. + ((sp_uint128)a[ 5]) * b[ 3]
  3293. + ((sp_uint128)a[ 6]) * b[ 2]
  3294. + ((sp_uint128)a[ 7]) * b[ 1]
  3295. + ((sp_uint128)a[ 8]) * b[ 0];
  3296. t[ 7] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3297. t1 = ((sp_uint128)a[ 1]) * b[ 8]
  3298. + ((sp_uint128)a[ 2]) * b[ 7]
  3299. + ((sp_uint128)a[ 3]) * b[ 6]
  3300. + ((sp_uint128)a[ 4]) * b[ 5]
  3301. + ((sp_uint128)a[ 5]) * b[ 4]
  3302. + ((sp_uint128)a[ 6]) * b[ 3]
  3303. + ((sp_uint128)a[ 7]) * b[ 2]
  3304. + ((sp_uint128)a[ 8]) * b[ 1];
  3305. t[ 8] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3306. t0 = ((sp_uint128)a[ 2]) * b[ 8]
  3307. + ((sp_uint128)a[ 3]) * b[ 7]
  3308. + ((sp_uint128)a[ 4]) * b[ 6]
  3309. + ((sp_uint128)a[ 5]) * b[ 5]
  3310. + ((sp_uint128)a[ 6]) * b[ 4]
  3311. + ((sp_uint128)a[ 7]) * b[ 3]
  3312. + ((sp_uint128)a[ 8]) * b[ 2];
  3313. r[ 9] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3314. t1 = ((sp_uint128)a[ 3]) * b[ 8]
  3315. + ((sp_uint128)a[ 4]) * b[ 7]
  3316. + ((sp_uint128)a[ 5]) * b[ 6]
  3317. + ((sp_uint128)a[ 6]) * b[ 5]
  3318. + ((sp_uint128)a[ 7]) * b[ 4]
  3319. + ((sp_uint128)a[ 8]) * b[ 3];
  3320. r[10] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3321. t0 = ((sp_uint128)a[ 4]) * b[ 8]
  3322. + ((sp_uint128)a[ 5]) * b[ 7]
  3323. + ((sp_uint128)a[ 6]) * b[ 6]
  3324. + ((sp_uint128)a[ 7]) * b[ 5]
  3325. + ((sp_uint128)a[ 8]) * b[ 4];
  3326. r[11] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3327. t1 = ((sp_uint128)a[ 5]) * b[ 8]
  3328. + ((sp_uint128)a[ 6]) * b[ 7]
  3329. + ((sp_uint128)a[ 7]) * b[ 6]
  3330. + ((sp_uint128)a[ 8]) * b[ 5];
  3331. r[12] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3332. t0 = ((sp_uint128)a[ 6]) * b[ 8]
  3333. + ((sp_uint128)a[ 7]) * b[ 7]
  3334. + ((sp_uint128)a[ 8]) * b[ 6];
  3335. r[13] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3336. t1 = ((sp_uint128)a[ 7]) * b[ 8]
  3337. + ((sp_uint128)a[ 8]) * b[ 7];
  3338. r[14] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3339. t0 = ((sp_uint128)a[ 8]) * b[ 8];
  3340. r[15] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3341. r[16] = t0 & 0x1ffffffffffffffL;
  3342. r[17] = (sp_digit)(t0 >> 57);
  3343. XMEMCPY(r, t, sizeof(t));
  3344. }
  3345. /* Add b to a into r. (r = a + b)
  3346. *
  3347. * r A single precision integer.
  3348. * a A single precision integer.
  3349. * b A single precision integer.
  3350. */
  3351. SP_NOINLINE static int sp_2048_add_9(sp_digit* r, const sp_digit* a,
  3352. const sp_digit* b)
  3353. {
  3354. r[ 0] = a[ 0] + b[ 0];
  3355. r[ 1] = a[ 1] + b[ 1];
  3356. r[ 2] = a[ 2] + b[ 2];
  3357. r[ 3] = a[ 3] + b[ 3];
  3358. r[ 4] = a[ 4] + b[ 4];
  3359. r[ 5] = a[ 5] + b[ 5];
  3360. r[ 6] = a[ 6] + b[ 6];
  3361. r[ 7] = a[ 7] + b[ 7];
  3362. r[ 8] = a[ 8] + b[ 8];
  3363. return 0;
  3364. }
  3365. /* Add b to a into r. (r = a + b)
  3366. *
  3367. * r A single precision integer.
  3368. * a A single precision integer.
  3369. * b A single precision integer.
  3370. */
  3371. SP_NOINLINE static int sp_2048_add_18(sp_digit* r, const sp_digit* a,
  3372. const sp_digit* b)
  3373. {
  3374. int i;
  3375. for (i = 0; i < 16; i += 8) {
  3376. r[i + 0] = a[i + 0] + b[i + 0];
  3377. r[i + 1] = a[i + 1] + b[i + 1];
  3378. r[i + 2] = a[i + 2] + b[i + 2];
  3379. r[i + 3] = a[i + 3] + b[i + 3];
  3380. r[i + 4] = a[i + 4] + b[i + 4];
  3381. r[i + 5] = a[i + 5] + b[i + 5];
  3382. r[i + 6] = a[i + 6] + b[i + 6];
  3383. r[i + 7] = a[i + 7] + b[i + 7];
  3384. }
  3385. r[16] = a[16] + b[16];
  3386. r[17] = a[17] + b[17];
  3387. return 0;
  3388. }
  3389. /* Sub b from a into r. (r = a - b)
  3390. *
  3391. * r A single precision integer.
  3392. * a A single precision integer.
  3393. * b A single precision integer.
  3394. */
  3395. SP_NOINLINE static int sp_2048_sub_18(sp_digit* r, const sp_digit* a,
  3396. const sp_digit* b)
  3397. {
  3398. int i;
  3399. for (i = 0; i < 16; i += 8) {
  3400. r[i + 0] = a[i + 0] - b[i + 0];
  3401. r[i + 1] = a[i + 1] - b[i + 1];
  3402. r[i + 2] = a[i + 2] - b[i + 2];
  3403. r[i + 3] = a[i + 3] - b[i + 3];
  3404. r[i + 4] = a[i + 4] - b[i + 4];
  3405. r[i + 5] = a[i + 5] - b[i + 5];
  3406. r[i + 6] = a[i + 6] - b[i + 6];
  3407. r[i + 7] = a[i + 7] - b[i + 7];
  3408. }
  3409. r[16] = a[16] - b[16];
  3410. r[17] = a[17] - b[17];
  3411. return 0;
  3412. }
  3413. /* Multiply a and b into r. (r = a * b)
  3414. *
  3415. * r A single precision integer.
  3416. * a A single precision integer.
  3417. * b A single precision integer.
  3418. */
  3419. SP_NOINLINE static void sp_2048_mul_18(sp_digit* r, const sp_digit* a,
  3420. const sp_digit* b)
  3421. {
  3422. sp_digit* z0 = r;
  3423. sp_digit z1[18];
  3424. sp_digit* a1 = z1;
  3425. sp_digit b1[9];
  3426. sp_digit* z2 = r + 18;
  3427. (void)sp_2048_add_9(a1, a, &a[9]);
  3428. (void)sp_2048_add_9(b1, b, &b[9]);
  3429. sp_2048_mul_9(z2, &a[9], &b[9]);
  3430. sp_2048_mul_9(z0, a, b);
  3431. sp_2048_mul_9(z1, a1, b1);
  3432. (void)sp_2048_sub_18(z1, z1, z2);
  3433. (void)sp_2048_sub_18(z1, z1, z0);
  3434. (void)sp_2048_add_18(r + 9, r + 9, z1);
  3435. }
  3436. /* Add b to a into r. (r = a + b)
  3437. *
  3438. * r A single precision integer.
  3439. * a A single precision integer.
  3440. * b A single precision integer.
  3441. */
  3442. SP_NOINLINE static int sp_2048_add_36(sp_digit* r, const sp_digit* a,
  3443. const sp_digit* b)
  3444. {
  3445. int i;
  3446. for (i = 0; i < 32; i += 8) {
  3447. r[i + 0] = a[i + 0] + b[i + 0];
  3448. r[i + 1] = a[i + 1] + b[i + 1];
  3449. r[i + 2] = a[i + 2] + b[i + 2];
  3450. r[i + 3] = a[i + 3] + b[i + 3];
  3451. r[i + 4] = a[i + 4] + b[i + 4];
  3452. r[i + 5] = a[i + 5] + b[i + 5];
  3453. r[i + 6] = a[i + 6] + b[i + 6];
  3454. r[i + 7] = a[i + 7] + b[i + 7];
  3455. }
  3456. r[32] = a[32] + b[32];
  3457. r[33] = a[33] + b[33];
  3458. r[34] = a[34] + b[34];
  3459. r[35] = a[35] + b[35];
  3460. return 0;
  3461. }
  3462. /* Sub b from a into r. (r = a - b)
  3463. *
  3464. * r A single precision integer.
  3465. * a A single precision integer.
  3466. * b A single precision integer.
  3467. */
  3468. SP_NOINLINE static int sp_2048_sub_36(sp_digit* r, const sp_digit* a,
  3469. const sp_digit* b)
  3470. {
  3471. int i;
  3472. for (i = 0; i < 32; i += 8) {
  3473. r[i + 0] = a[i + 0] - b[i + 0];
  3474. r[i + 1] = a[i + 1] - b[i + 1];
  3475. r[i + 2] = a[i + 2] - b[i + 2];
  3476. r[i + 3] = a[i + 3] - b[i + 3];
  3477. r[i + 4] = a[i + 4] - b[i + 4];
  3478. r[i + 5] = a[i + 5] - b[i + 5];
  3479. r[i + 6] = a[i + 6] - b[i + 6];
  3480. r[i + 7] = a[i + 7] - b[i + 7];
  3481. }
  3482. r[32] = a[32] - b[32];
  3483. r[33] = a[33] - b[33];
  3484. r[34] = a[34] - b[34];
  3485. r[35] = a[35] - b[35];
  3486. return 0;
  3487. }
  3488. /* Multiply a and b into r. (r = a * b)
  3489. *
  3490. * r A single precision integer.
  3491. * a A single precision integer.
  3492. * b A single precision integer.
  3493. */
  3494. SP_NOINLINE static void sp_2048_mul_36(sp_digit* r, const sp_digit* a,
  3495. const sp_digit* b)
  3496. {
  3497. sp_digit* z0 = r;
  3498. sp_digit z1[36];
  3499. sp_digit* a1 = z1;
  3500. sp_digit b1[18];
  3501. sp_digit* z2 = r + 36;
  3502. (void)sp_2048_add_18(a1, a, &a[18]);
  3503. (void)sp_2048_add_18(b1, b, &b[18]);
  3504. sp_2048_mul_18(z2, &a[18], &b[18]);
  3505. sp_2048_mul_18(z0, a, b);
  3506. sp_2048_mul_18(z1, a1, b1);
  3507. (void)sp_2048_sub_36(z1, z1, z2);
  3508. (void)sp_2048_sub_36(z1, z1, z0);
  3509. (void)sp_2048_add_36(r + 18, r + 18, z1);
  3510. }
  3511. /* Square a and put result in r. (r = a * a)
  3512. *
  3513. * r A single precision integer.
  3514. * a A single precision integer.
  3515. */
  3516. SP_NOINLINE static void sp_2048_sqr_9(sp_digit* r, const sp_digit* a)
  3517. {
  3518. sp_uint128 t0;
  3519. sp_uint128 t1;
  3520. sp_digit t[9];
  3521. t0 = ((sp_uint128)a[ 0]) * a[ 0];
  3522. t1 = (((sp_uint128)a[ 0]) * a[ 1]) * 2;
  3523. t[ 0] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3524. t0 = (((sp_uint128)a[ 0]) * a[ 2]) * 2
  3525. + ((sp_uint128)a[ 1]) * a[ 1];
  3526. t[ 1] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3527. t1 = (((sp_uint128)a[ 0]) * a[ 3]
  3528. + ((sp_uint128)a[ 1]) * a[ 2]) * 2;
  3529. t[ 2] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3530. t0 = (((sp_uint128)a[ 0]) * a[ 4]
  3531. + ((sp_uint128)a[ 1]) * a[ 3]) * 2
  3532. + ((sp_uint128)a[ 2]) * a[ 2];
  3533. t[ 3] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3534. t1 = (((sp_uint128)a[ 0]) * a[ 5]
  3535. + ((sp_uint128)a[ 1]) * a[ 4]
  3536. + ((sp_uint128)a[ 2]) * a[ 3]) * 2;
  3537. t[ 4] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3538. t0 = (((sp_uint128)a[ 0]) * a[ 6]
  3539. + ((sp_uint128)a[ 1]) * a[ 5]
  3540. + ((sp_uint128)a[ 2]) * a[ 4]) * 2
  3541. + ((sp_uint128)a[ 3]) * a[ 3];
  3542. t[ 5] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3543. t1 = (((sp_uint128)a[ 0]) * a[ 7]
  3544. + ((sp_uint128)a[ 1]) * a[ 6]
  3545. + ((sp_uint128)a[ 2]) * a[ 5]
  3546. + ((sp_uint128)a[ 3]) * a[ 4]) * 2;
  3547. t[ 6] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3548. t0 = (((sp_uint128)a[ 0]) * a[ 8]
  3549. + ((sp_uint128)a[ 1]) * a[ 7]
  3550. + ((sp_uint128)a[ 2]) * a[ 6]
  3551. + ((sp_uint128)a[ 3]) * a[ 5]) * 2
  3552. + ((sp_uint128)a[ 4]) * a[ 4];
  3553. t[ 7] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3554. t1 = (((sp_uint128)a[ 1]) * a[ 8]
  3555. + ((sp_uint128)a[ 2]) * a[ 7]
  3556. + ((sp_uint128)a[ 3]) * a[ 6]
  3557. + ((sp_uint128)a[ 4]) * a[ 5]) * 2;
  3558. t[ 8] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3559. t0 = (((sp_uint128)a[ 2]) * a[ 8]
  3560. + ((sp_uint128)a[ 3]) * a[ 7]
  3561. + ((sp_uint128)a[ 4]) * a[ 6]) * 2
  3562. + ((sp_uint128)a[ 5]) * a[ 5];
  3563. r[ 9] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3564. t1 = (((sp_uint128)a[ 3]) * a[ 8]
  3565. + ((sp_uint128)a[ 4]) * a[ 7]
  3566. + ((sp_uint128)a[ 5]) * a[ 6]) * 2;
  3567. r[10] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3568. t0 = (((sp_uint128)a[ 4]) * a[ 8]
  3569. + ((sp_uint128)a[ 5]) * a[ 7]) * 2
  3570. + ((sp_uint128)a[ 6]) * a[ 6];
  3571. r[11] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3572. t1 = (((sp_uint128)a[ 5]) * a[ 8]
  3573. + ((sp_uint128)a[ 6]) * a[ 7]) * 2;
  3574. r[12] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3575. t0 = (((sp_uint128)a[ 6]) * a[ 8]) * 2
  3576. + ((sp_uint128)a[ 7]) * a[ 7];
  3577. r[13] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3578. t1 = (((sp_uint128)a[ 7]) * a[ 8]) * 2;
  3579. r[14] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  3580. t0 = ((sp_uint128)a[ 8]) * a[ 8];
  3581. r[15] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  3582. r[16] = t0 & 0x1ffffffffffffffL;
  3583. r[17] = (sp_digit)(t0 >> 57);
  3584. XMEMCPY(r, t, sizeof(t));
  3585. }
  3586. /* Square a and put result in r. (r = a * a)
  3587. *
  3588. * r A single precision integer.
  3589. * a A single precision integer.
  3590. */
  3591. SP_NOINLINE static void sp_2048_sqr_18(sp_digit* r, const sp_digit* a)
  3592. {
  3593. sp_digit* z0 = r;
  3594. sp_digit z1[18];
  3595. sp_digit* a1 = z1;
  3596. sp_digit* z2 = r + 18;
  3597. (void)sp_2048_add_9(a1, a, &a[9]);
  3598. sp_2048_sqr_9(z2, &a[9]);
  3599. sp_2048_sqr_9(z0, a);
  3600. sp_2048_sqr_9(z1, a1);
  3601. (void)sp_2048_sub_18(z1, z1, z2);
  3602. (void)sp_2048_sub_18(z1, z1, z0);
  3603. (void)sp_2048_add_18(r + 9, r + 9, z1);
  3604. }
  3605. /* Square a and put result in r. (r = a * a)
  3606. *
  3607. * r A single precision integer.
  3608. * a A single precision integer.
  3609. */
  3610. SP_NOINLINE static void sp_2048_sqr_36(sp_digit* r, const sp_digit* a)
  3611. {
  3612. sp_digit* z0 = r;
  3613. sp_digit z1[36];
  3614. sp_digit* a1 = z1;
  3615. sp_digit* z2 = r + 36;
  3616. (void)sp_2048_add_18(a1, a, &a[18]);
  3617. sp_2048_sqr_18(z2, &a[18]);
  3618. sp_2048_sqr_18(z0, a);
  3619. sp_2048_sqr_18(z1, a1);
  3620. (void)sp_2048_sub_36(z1, z1, z2);
  3621. (void)sp_2048_sub_36(z1, z1, z0);
  3622. (void)sp_2048_add_36(r + 18, r + 18, z1);
  3623. }
  3624. #endif /* !WOLFSSL_SP_SMALL */
  3625. /* Calculate the bottom digit of -1/a mod 2^n.
  3626. *
  3627. * a A single precision number.
  3628. * rho Bottom word of inverse.
  3629. */
  3630. static void sp_2048_mont_setup(const sp_digit* a, sp_digit* rho)
  3631. {
  3632. sp_digit x;
  3633. sp_digit b;
  3634. b = a[0];
  3635. x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
  3636. x *= 2 - b * x; /* here x*a==1 mod 2**8 */
  3637. x *= 2 - b * x; /* here x*a==1 mod 2**16 */
  3638. x *= 2 - b * x; /* here x*a==1 mod 2**32 */
  3639. x *= 2 - b * x; /* here x*a==1 mod 2**64 */
  3640. x &= 0x1ffffffffffffffL;
  3641. /* rho = -1/m mod b */
  3642. *rho = ((sp_digit)1 << 57) - x;
  3643. }
  3644. /* Multiply a by scalar b into r. (r = a * b)
  3645. *
  3646. * r A single precision integer.
  3647. * a A single precision integer.
  3648. * b A scalar.
  3649. */
  3650. SP_NOINLINE static void sp_2048_mul_d_36(sp_digit* r, const sp_digit* a,
  3651. sp_digit b)
  3652. {
  3653. sp_int128 tb = b;
  3654. sp_int128 t = 0;
  3655. sp_digit t2;
  3656. sp_int128 p[4];
  3657. int i;
  3658. for (i = 0; i < 36; i += 4) {
  3659. p[0] = tb * a[i + 0];
  3660. p[1] = tb * a[i + 1];
  3661. p[2] = tb * a[i + 2];
  3662. p[3] = tb * a[i + 3];
  3663. t += p[0];
  3664. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3665. t >>= 57;
  3666. r[i + 0] = (sp_digit)t2;
  3667. t += p[1];
  3668. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3669. t >>= 57;
  3670. r[i + 1] = (sp_digit)t2;
  3671. t += p[2];
  3672. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3673. t >>= 57;
  3674. r[i + 2] = (sp_digit)t2;
  3675. t += p[3];
  3676. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3677. t >>= 57;
  3678. r[i + 3] = (sp_digit)t2;
  3679. }
  3680. r[36] = (sp_digit)(t & 0x1ffffffffffffffL);
  3681. }
  3682. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  3683. /* r = 2^n mod m where n is the number of bits to reduce by.
  3684. * Given m must be 2048 bits, just need to subtract.
  3685. *
  3686. * r A single precision number.
  3687. * m A single precision number.
  3688. */
  3689. static void sp_2048_mont_norm_18(sp_digit* r, const sp_digit* m)
  3690. {
  3691. /* Set r = 2^n - 1. */
  3692. int i;
  3693. for (i = 0; i < 16; i += 8) {
  3694. r[i + 0] = 0x1ffffffffffffffL;
  3695. r[i + 1] = 0x1ffffffffffffffL;
  3696. r[i + 2] = 0x1ffffffffffffffL;
  3697. r[i + 3] = 0x1ffffffffffffffL;
  3698. r[i + 4] = 0x1ffffffffffffffL;
  3699. r[i + 5] = 0x1ffffffffffffffL;
  3700. r[i + 6] = 0x1ffffffffffffffL;
  3701. r[i + 7] = 0x1ffffffffffffffL;
  3702. }
  3703. r[16] = 0x1ffffffffffffffL;
  3704. r[17] = 0x7fffffffffffffL;
  3705. /* r = (2^n - 1) mod n */
  3706. (void)sp_2048_sub_18(r, r, m);
  3707. /* Add one so r = 2^n mod m */
  3708. r[0] += 1;
  3709. }
  3710. /* Compare a with b in constant time.
  3711. *
  3712. * a A single precision integer.
  3713. * b A single precision integer.
  3714. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  3715. * respectively.
  3716. */
  3717. static sp_digit sp_2048_cmp_18(const sp_digit* a, const sp_digit* b)
  3718. {
  3719. sp_digit r = 0;
  3720. int i;
  3721. r |= (a[17] - b[17]) & (0 - (sp_digit)1);
  3722. r |= (a[16] - b[16]) & ~(((sp_digit)0 - r) >> 56);
  3723. for (i = 8; i >= 0; i -= 8) {
  3724. r |= (a[i + 7] - b[i + 7]) & ~(((sp_digit)0 - r) >> 56);
  3725. r |= (a[i + 6] - b[i + 6]) & ~(((sp_digit)0 - r) >> 56);
  3726. r |= (a[i + 5] - b[i + 5]) & ~(((sp_digit)0 - r) >> 56);
  3727. r |= (a[i + 4] - b[i + 4]) & ~(((sp_digit)0 - r) >> 56);
  3728. r |= (a[i + 3] - b[i + 3]) & ~(((sp_digit)0 - r) >> 56);
  3729. r |= (a[i + 2] - b[i + 2]) & ~(((sp_digit)0 - r) >> 56);
  3730. r |= (a[i + 1] - b[i + 1]) & ~(((sp_digit)0 - r) >> 56);
  3731. r |= (a[i + 0] - b[i + 0]) & ~(((sp_digit)0 - r) >> 56);
  3732. }
  3733. return r;
  3734. }
  3735. /* Conditionally subtract b from a using the mask m.
  3736. * m is -1 to subtract and 0 when not.
  3737. *
  3738. * r A single precision number representing condition subtract result.
  3739. * a A single precision number to subtract from.
  3740. * b A single precision number to subtract.
  3741. * m Mask value to apply.
  3742. */
  3743. static void sp_2048_cond_sub_18(sp_digit* r, const sp_digit* a,
  3744. const sp_digit* b, const sp_digit m)
  3745. {
  3746. int i;
  3747. for (i = 0; i < 16; i += 8) {
  3748. r[i + 0] = a[i + 0] - (b[i + 0] & m);
  3749. r[i + 1] = a[i + 1] - (b[i + 1] & m);
  3750. r[i + 2] = a[i + 2] - (b[i + 2] & m);
  3751. r[i + 3] = a[i + 3] - (b[i + 3] & m);
  3752. r[i + 4] = a[i + 4] - (b[i + 4] & m);
  3753. r[i + 5] = a[i + 5] - (b[i + 5] & m);
  3754. r[i + 6] = a[i + 6] - (b[i + 6] & m);
  3755. r[i + 7] = a[i + 7] - (b[i + 7] & m);
  3756. }
  3757. r[16] = a[16] - (b[16] & m);
  3758. r[17] = a[17] - (b[17] & m);
  3759. }
  3760. /* Mul a by scalar b and add into r. (r += a * b)
  3761. *
  3762. * r A single precision integer.
  3763. * a A single precision integer.
  3764. * b A scalar.
  3765. */
  3766. SP_NOINLINE static void sp_2048_mul_add_18(sp_digit* r, const sp_digit* a,
  3767. const sp_digit b)
  3768. {
  3769. sp_int128 tb = b;
  3770. sp_int128 t[8];
  3771. int i;
  3772. t[0] = tb * a[0]; r[0] += (sp_digit)(t[0] & 0x1ffffffffffffffL);
  3773. for (i = 0; i < 16; i += 8) {
  3774. t[1] = tb * a[i+1];
  3775. r[i+1] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  3776. t[2] = tb * a[i+2];
  3777. r[i+2] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  3778. t[3] = tb * a[i+3];
  3779. r[i+3] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL));
  3780. t[4] = tb * a[i+4];
  3781. r[i+4] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL));
  3782. t[5] = tb * a[i+5];
  3783. r[i+5] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL));
  3784. t[6] = tb * a[i+6];
  3785. r[i+6] += (sp_digit)((t[5] >> 57) + (t[6] & 0x1ffffffffffffffL));
  3786. t[7] = tb * a[i+7];
  3787. r[i+7] += (sp_digit)((t[6] >> 57) + (t[7] & 0x1ffffffffffffffL));
  3788. t[0] = tb * a[i+8];
  3789. r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL));
  3790. }
  3791. t[1] = tb * a[17];
  3792. r[17] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  3793. r[18] += (sp_digit)(t[1] >> 57);
  3794. }
  3795. /* Shift the result in the high 1024 bits down to the bottom.
  3796. *
  3797. * r A single precision number.
  3798. * a A single precision number.
  3799. */
  3800. static void sp_2048_mont_shift_18(sp_digit* r, const sp_digit* a)
  3801. {
  3802. sp_uint64 n;
  3803. int i;
  3804. n = (sp_uint64)a[17];
  3805. n = n >> 55U;
  3806. for (i = 0; i < 16; i += 8) {
  3807. n += (sp_uint64)a[i+18] << 2U; r[i+0] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3808. n += (sp_uint64)a[i+19] << 2U; r[i+1] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3809. n += (sp_uint64)a[i+20] << 2U; r[i+2] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3810. n += (sp_uint64)a[i+21] << 2U; r[i+3] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3811. n += (sp_uint64)a[i+22] << 2U; r[i+4] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3812. n += (sp_uint64)a[i+23] << 2U; r[i+5] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3813. n += (sp_uint64)a[i+24] << 2U; r[i+6] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3814. n += (sp_uint64)a[i+25] << 2U; r[i+7] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3815. }
  3816. n += (sp_uint64)a[34] << 2U; r[16] = n & 0x1ffffffffffffffUL; n >>= 57U;
  3817. n += (sp_uint64)a[35] << 2U; r[17] = n;
  3818. XMEMSET(&r[18], 0, sizeof(*r) * 18U);
  3819. }
  3820. /* Reduce the number back to 2048 bits using Montgomery reduction.
  3821. *
  3822. * a A single precision number to reduce in place.
  3823. * m The single precision number representing the modulus.
  3824. * mp The digit representing the negative inverse of m mod 2^n.
  3825. */
  3826. static void sp_2048_mont_reduce_18(sp_digit* a, const sp_digit* m, sp_digit mp)
  3827. {
  3828. int i;
  3829. sp_digit mu;
  3830. sp_digit over;
  3831. sp_2048_norm_18(a + 18);
  3832. for (i=0; i<17; i++) {
  3833. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL;
  3834. sp_2048_mul_add_18(a+i, m, mu);
  3835. a[i+1] += a[i] >> 57;
  3836. }
  3837. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7fffffffffffffL;
  3838. sp_2048_mul_add_18(a+i, m, mu);
  3839. a[i+1] += a[i] >> 57;
  3840. a[i] &= 0x1ffffffffffffffL;
  3841. sp_2048_mont_shift_18(a, a);
  3842. over = a[17] - m[17];
  3843. sp_2048_cond_sub_18(a, a, m, ~((over - 1) >> 63));
  3844. sp_2048_norm_18(a);
  3845. }
  3846. /* Multiply two Montgomery form numbers mod the modulus (prime).
  3847. * (r = a * b mod m)
  3848. *
  3849. * r Result of multiplication.
  3850. * a First number to multiply in Montgomery form.
  3851. * b Second number to multiply in Montgomery form.
  3852. * m Modulus (prime).
  3853. * mp Montgomery multiplier.
  3854. */
  3855. SP_NOINLINE static void sp_2048_mont_mul_18(sp_digit* r, const sp_digit* a,
  3856. const sp_digit* b, const sp_digit* m, sp_digit mp)
  3857. {
  3858. sp_2048_mul_18(r, a, b);
  3859. sp_2048_mont_reduce_18(r, m, mp);
  3860. }
  3861. /* Square the Montgomery form number. (r = a * a mod m)
  3862. *
  3863. * r Result of squaring.
  3864. * a Number to square in Montgomery form.
  3865. * m Modulus (prime).
  3866. * mp Montgomery multiplier.
  3867. */
  3868. SP_NOINLINE static void sp_2048_mont_sqr_18(sp_digit* r, const sp_digit* a,
  3869. const sp_digit* m, sp_digit mp)
  3870. {
  3871. sp_2048_sqr_18(r, a);
  3872. sp_2048_mont_reduce_18(r, m, mp);
  3873. }
  3874. /* Multiply a by scalar b into r. (r = a * b)
  3875. *
  3876. * r A single precision integer.
  3877. * a A single precision integer.
  3878. * b A scalar.
  3879. */
  3880. SP_NOINLINE static void sp_2048_mul_d_18(sp_digit* r, const sp_digit* a,
  3881. sp_digit b)
  3882. {
  3883. sp_int128 tb = b;
  3884. sp_int128 t = 0;
  3885. sp_digit t2;
  3886. sp_int128 p[4];
  3887. int i;
  3888. for (i = 0; i < 16; i += 4) {
  3889. p[0] = tb * a[i + 0];
  3890. p[1] = tb * a[i + 1];
  3891. p[2] = tb * a[i + 2];
  3892. p[3] = tb * a[i + 3];
  3893. t += p[0];
  3894. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3895. t >>= 57;
  3896. r[i + 0] = (sp_digit)t2;
  3897. t += p[1];
  3898. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3899. t >>= 57;
  3900. r[i + 1] = (sp_digit)t2;
  3901. t += p[2];
  3902. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3903. t >>= 57;
  3904. r[i + 2] = (sp_digit)t2;
  3905. t += p[3];
  3906. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  3907. t >>= 57;
  3908. r[i + 3] = (sp_digit)t2;
  3909. }
  3910. t += tb * a[16];
  3911. r[16] = (sp_digit)(t & 0x1ffffffffffffffL);
  3912. t >>= 57;
  3913. t += tb * a[17];
  3914. r[17] = (sp_digit)(t & 0x1ffffffffffffffL);
  3915. t >>= 57;
  3916. r[18] = (sp_digit)(t & 0x1ffffffffffffffL);
  3917. }
  3918. #ifndef WOLFSSL_SP_SMALL
  3919. /* Conditionally add a and b using the mask m.
  3920. * m is -1 to add and 0 when not.
  3921. *
  3922. * r A single precision number representing conditional add result.
  3923. * a A single precision number to add with.
  3924. * b A single precision number to add.
  3925. * m Mask value to apply.
  3926. */
  3927. static void sp_2048_cond_add_18(sp_digit* r, const sp_digit* a,
  3928. const sp_digit* b, const sp_digit m)
  3929. {
  3930. int i;
  3931. for (i = 0; i < 16; i += 8) {
  3932. r[i + 0] = a[i + 0] + (b[i + 0] & m);
  3933. r[i + 1] = a[i + 1] + (b[i + 1] & m);
  3934. r[i + 2] = a[i + 2] + (b[i + 2] & m);
  3935. r[i + 3] = a[i + 3] + (b[i + 3] & m);
  3936. r[i + 4] = a[i + 4] + (b[i + 4] & m);
  3937. r[i + 5] = a[i + 5] + (b[i + 5] & m);
  3938. r[i + 6] = a[i + 6] + (b[i + 6] & m);
  3939. r[i + 7] = a[i + 7] + (b[i + 7] & m);
  3940. }
  3941. r[16] = a[16] + (b[16] & m);
  3942. r[17] = a[17] + (b[17] & m);
  3943. }
  3944. #endif /* !WOLFSSL_SP_SMALL */
  3945. SP_NOINLINE static void sp_2048_rshift_18(sp_digit* r, const sp_digit* a,
  3946. byte n)
  3947. {
  3948. int i;
  3949. for (i=0; i<16; i += 8) {
  3950. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (57 - n)) & 0x1ffffffffffffffL);
  3951. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (57 - n)) & 0x1ffffffffffffffL);
  3952. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (57 - n)) & 0x1ffffffffffffffL);
  3953. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (57 - n)) & 0x1ffffffffffffffL);
  3954. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (57 - n)) & 0x1ffffffffffffffL);
  3955. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (57 - n)) & 0x1ffffffffffffffL);
  3956. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (57 - n)) & 0x1ffffffffffffffL);
  3957. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (57 - n)) & 0x1ffffffffffffffL);
  3958. }
  3959. r[16] = (a[16] >> n) | ((a[17] << (57 - n)) & 0x1ffffffffffffffL);
  3960. r[17] = a[17] >> n;
  3961. }
  3962. static WC_INLINE sp_digit sp_2048_div_word_18(sp_digit d1, sp_digit d0,
  3963. sp_digit div)
  3964. {
  3965. #ifdef SP_USE_DIVTI3
  3966. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  3967. return d / div;
  3968. #elif defined(__x86_64__) || defined(__i386__)
  3969. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  3970. sp_uint64 lo = (sp_uint64)d;
  3971. sp_digit hi = (sp_digit)(d >> 64);
  3972. __asm__ __volatile__ (
  3973. "idiv %2"
  3974. : "+a" (lo)
  3975. : "d" (hi), "r" (div)
  3976. : "cc"
  3977. );
  3978. return (sp_digit)lo;
  3979. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  3980. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  3981. sp_digit dv = (div >> 1) + 1;
  3982. sp_digit t1 = (sp_digit)(d >> 57);
  3983. sp_digit t0 = (sp_digit)(d & 0x1ffffffffffffffL);
  3984. sp_digit t2;
  3985. sp_digit sign;
  3986. sp_digit r;
  3987. int i;
  3988. sp_int128 m;
  3989. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  3990. t1 -= dv & (0 - r);
  3991. for (i = 55; i >= 1; i--) {
  3992. t1 += t1 + (((sp_uint64)t0 >> 56) & 1);
  3993. t0 <<= 1;
  3994. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  3995. r += r + t2;
  3996. t1 -= dv & (0 - t2);
  3997. t1 += t2;
  3998. }
  3999. r += r + 1;
  4000. m = d - ((sp_int128)r * div);
  4001. r += (sp_digit)(m >> 57);
  4002. m = d - ((sp_int128)r * div);
  4003. r += (sp_digit)(m >> 114) - (sp_digit)(d >> 114);
  4004. m = d - ((sp_int128)r * div);
  4005. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  4006. m *= sign;
  4007. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  4008. r += sign * t2;
  4009. m = d - ((sp_int128)r * div);
  4010. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  4011. m *= sign;
  4012. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  4013. r += sign * t2;
  4014. return r;
  4015. #else
  4016. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  4017. sp_digit r = 0;
  4018. sp_digit t;
  4019. sp_digit dv = (div >> 26) + 1;
  4020. t = (sp_digit)(d >> 52);
  4021. t = (t / dv) << 26;
  4022. r += t;
  4023. d -= (sp_int128)t * div;
  4024. t = (sp_digit)(d >> 21);
  4025. t = t / (dv << 5);
  4026. r += t;
  4027. d -= (sp_int128)t * div;
  4028. t = (sp_digit)d;
  4029. t = t / div;
  4030. r += t;
  4031. d -= (sp_int128)t * div;
  4032. return r;
  4033. #endif
  4034. }
  4035. static WC_INLINE sp_digit sp_2048_word_div_word_18(sp_digit d, sp_digit div)
  4036. {
  4037. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  4038. defined(SP_DIV_WORD_USE_DIV)
  4039. return d / div;
  4040. #else
  4041. return (sp_digit)((sp_uint64)(div - d) >> 63);
  4042. #endif
  4043. }
  4044. /* Divide d in a and put remainder into r (m*d + r = a)
  4045. * m is not calculated as it is not needed at this time.
  4046. *
  4047. * Full implementation.
  4048. *
  4049. * a Number to be divided.
  4050. * d Number to divide with.
  4051. * m Multiplier result.
  4052. * r Remainder from the division.
  4053. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  4054. */
  4055. static int sp_2048_div_18(const sp_digit* a, const sp_digit* d,
  4056. const sp_digit* m, sp_digit* r)
  4057. {
  4058. int i;
  4059. #ifndef WOLFSSL_SP_DIV_64
  4060. #endif
  4061. sp_digit dv;
  4062. sp_digit r1;
  4063. #ifdef WOLFSSL_SP_SMALL_STACK
  4064. sp_digit* t1 = NULL;
  4065. #else
  4066. sp_digit t1[4 * 18 + 3];
  4067. #endif
  4068. sp_digit* t2 = NULL;
  4069. sp_digit* sd = NULL;
  4070. int err = MP_OKAY;
  4071. (void)m;
  4072. #ifdef WOLFSSL_SP_SMALL_STACK
  4073. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 18 + 3), NULL,
  4074. DYNAMIC_TYPE_TMP_BUFFER);
  4075. if (t1 == NULL)
  4076. err = MEMORY_E;
  4077. #endif
  4078. (void)m;
  4079. if (err == MP_OKAY) {
  4080. t2 = t1 + 36 + 1;
  4081. sd = t2 + 18 + 1;
  4082. sp_2048_mul_d_18(sd, d, (sp_digit)1 << 2);
  4083. sp_2048_mul_d_36(t1, a, (sp_digit)1 << 2);
  4084. dv = sd[17];
  4085. t1[18 + 18] += t1[18 + 18 - 1] >> 57;
  4086. t1[18 + 18 - 1] &= 0x1ffffffffffffffL;
  4087. for (i=18; i>=0; i--) {
  4088. r1 = sp_2048_div_word_18(t1[18 + i], t1[18 + i - 1], dv);
  4089. sp_2048_mul_d_18(t2, sd, r1);
  4090. (void)sp_2048_sub_18(&t1[i], &t1[i], t2);
  4091. sp_2048_norm_18(&t1[i]);
  4092. t1[18 + i] -= t2[18];
  4093. t1[18 + i] += t1[18 + i - 1] >> 57;
  4094. t1[18 + i - 1] &= 0x1ffffffffffffffL;
  4095. r1 = sp_2048_div_word_18(-t1[18 + i], -t1[18 + i - 1], dv);
  4096. r1 -= t1[18 + i];
  4097. sp_2048_mul_d_18(t2, sd, r1);
  4098. (void)sp_2048_add_18(&t1[i], &t1[i], t2);
  4099. t1[18 + i] += t1[18 + i - 1] >> 57;
  4100. t1[18 + i - 1] &= 0x1ffffffffffffffL;
  4101. }
  4102. t1[18 - 1] += t1[18 - 2] >> 57;
  4103. t1[18 - 2] &= 0x1ffffffffffffffL;
  4104. r1 = sp_2048_word_div_word_18(t1[18 - 1], dv);
  4105. sp_2048_mul_d_18(t2, sd, r1);
  4106. sp_2048_sub_18(t1, t1, t2);
  4107. XMEMCPY(r, t1, sizeof(*r) * 36U);
  4108. for (i=0; i<17; i++) {
  4109. r[i+1] += r[i] >> 57;
  4110. r[i] &= 0x1ffffffffffffffL;
  4111. }
  4112. sp_2048_cond_add_18(r, r, sd, r[17] >> 63);
  4113. sp_2048_norm_18(r);
  4114. sp_2048_rshift_18(r, r, 2);
  4115. }
  4116. #ifdef WOLFSSL_SP_SMALL_STACK
  4117. if (t1 != NULL)
  4118. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4119. #endif
  4120. return err;
  4121. }
  4122. /* Reduce a modulo m into r. (r = a mod m)
  4123. *
  4124. * r A single precision number that is the reduced result.
  4125. * a A single precision number that is to be reduced.
  4126. * m A single precision number that is the modulus to reduce with.
  4127. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  4128. */
  4129. static int sp_2048_mod_18(sp_digit* r, const sp_digit* a, const sp_digit* m)
  4130. {
  4131. return sp_2048_div_18(a, m, NULL, r);
  4132. }
  4133. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  4134. *
  4135. * r A single precision number that is the result of the operation.
  4136. * a A single precision number being exponentiated.
  4137. * e A single precision number that is the exponent.
  4138. * bits The number of bits in the exponent.
  4139. * m A single precision number that is the modulus.
  4140. * returns 0 on success.
  4141. * returns MEMORY_E on dynamic memory allocation failure.
  4142. * returns MP_VAL when base is even or exponent is 0.
  4143. */
  4144. static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e,
  4145. int bits, const sp_digit* m, int reduceA)
  4146. {
  4147. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  4148. #ifdef WOLFSSL_SP_SMALL_STACK
  4149. sp_digit* td = NULL;
  4150. #else
  4151. sp_digit td[3 * 36];
  4152. #endif
  4153. sp_digit* t[3] = {0, 0, 0};
  4154. sp_digit* norm = NULL;
  4155. sp_digit mp = 1;
  4156. sp_digit n;
  4157. int i;
  4158. int c;
  4159. byte y;
  4160. int err = MP_OKAY;
  4161. if (bits == 0) {
  4162. err = MP_VAL;
  4163. }
  4164. #ifdef WOLFSSL_SP_SMALL_STACK
  4165. if (err == MP_OKAY) {
  4166. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 18 * 2, NULL,
  4167. DYNAMIC_TYPE_TMP_BUFFER);
  4168. if (td == NULL)
  4169. err = MEMORY_E;
  4170. }
  4171. #endif
  4172. if (err == MP_OKAY) {
  4173. norm = td;
  4174. for (i=0; i<3; i++) {
  4175. t[i] = td + (i * 18 * 2);
  4176. XMEMSET(t[i], 0, sizeof(sp_digit) * 18U * 2U);
  4177. }
  4178. sp_2048_mont_setup(m, &mp);
  4179. sp_2048_mont_norm_18(norm, m);
  4180. if (reduceA != 0) {
  4181. err = sp_2048_mod_18(t[1], a, m);
  4182. }
  4183. else {
  4184. XMEMCPY(t[1], a, sizeof(sp_digit) * 18U);
  4185. }
  4186. }
  4187. if (err == MP_OKAY) {
  4188. sp_2048_mul_18(t[1], t[1], norm);
  4189. err = sp_2048_mod_18(t[1], t[1], m);
  4190. }
  4191. if (err == MP_OKAY) {
  4192. i = bits / 57;
  4193. c = bits % 57;
  4194. n = e[i--] << (57 - c);
  4195. for (; ; c--) {
  4196. if (c == 0) {
  4197. if (i == -1) {
  4198. break;
  4199. }
  4200. n = e[i--];
  4201. c = 57;
  4202. }
  4203. y = (int)((n >> 56) & 1);
  4204. n <<= 1;
  4205. sp_2048_mont_mul_18(t[y^1], t[0], t[1], m, mp);
  4206. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  4207. ((size_t)t[1] & addr_mask[y])),
  4208. sizeof(*t[2]) * 18 * 2);
  4209. sp_2048_mont_sqr_18(t[2], t[2], m, mp);
  4210. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  4211. ((size_t)t[1] & addr_mask[y])), t[2],
  4212. sizeof(*t[2]) * 18 * 2);
  4213. }
  4214. sp_2048_mont_reduce_18(t[0], m, mp);
  4215. n = sp_2048_cmp_18(t[0], m);
  4216. sp_2048_cond_sub_18(t[0], t[0], m, ~(n >> 63));
  4217. XMEMCPY(r, t[0], sizeof(*r) * 18 * 2);
  4218. }
  4219. #ifdef WOLFSSL_SP_SMALL_STACK
  4220. if (td != NULL)
  4221. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4222. #endif
  4223. return err;
  4224. #elif !defined(WC_NO_CACHE_RESISTANT)
  4225. #ifdef WOLFSSL_SP_SMALL_STACK
  4226. sp_digit* td = NULL;
  4227. #else
  4228. sp_digit td[3 * 36];
  4229. #endif
  4230. sp_digit* t[3] = {0, 0, 0};
  4231. sp_digit* norm = NULL;
  4232. sp_digit mp = 1;
  4233. sp_digit n;
  4234. int i;
  4235. int c;
  4236. byte y;
  4237. int err = MP_OKAY;
  4238. if (bits == 0) {
  4239. err = MP_VAL;
  4240. }
  4241. #ifdef WOLFSSL_SP_SMALL_STACK
  4242. if (err == MP_OKAY) {
  4243. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 18 * 2, NULL,
  4244. DYNAMIC_TYPE_TMP_BUFFER);
  4245. if (td == NULL)
  4246. err = MEMORY_E;
  4247. }
  4248. #endif
  4249. if (err == MP_OKAY) {
  4250. norm = td;
  4251. for (i=0; i<3; i++) {
  4252. t[i] = td + (i * 18 * 2);
  4253. }
  4254. sp_2048_mont_setup(m, &mp);
  4255. sp_2048_mont_norm_18(norm, m);
  4256. if (reduceA != 0) {
  4257. err = sp_2048_mod_18(t[1], a, m);
  4258. if (err == MP_OKAY) {
  4259. sp_2048_mul_18(t[1], t[1], norm);
  4260. err = sp_2048_mod_18(t[1], t[1], m);
  4261. }
  4262. }
  4263. else {
  4264. sp_2048_mul_18(t[1], a, norm);
  4265. err = sp_2048_mod_18(t[1], t[1], m);
  4266. }
  4267. }
  4268. if (err == MP_OKAY) {
  4269. i = bits / 57;
  4270. c = bits % 57;
  4271. n = e[i--] << (57 - c);
  4272. for (; ; c--) {
  4273. if (c == 0) {
  4274. if (i == -1) {
  4275. break;
  4276. }
  4277. n = e[i--];
  4278. c = 57;
  4279. }
  4280. y = (int)((n >> 56) & 1);
  4281. n <<= 1;
  4282. sp_2048_mont_mul_18(t[y^1], t[0], t[1], m, mp);
  4283. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  4284. ((size_t)t[1] & addr_mask[y])),
  4285. sizeof(*t[2]) * 18 * 2);
  4286. sp_2048_mont_sqr_18(t[2], t[2], m, mp);
  4287. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  4288. ((size_t)t[1] & addr_mask[y])), t[2],
  4289. sizeof(*t[2]) * 18 * 2);
  4290. }
  4291. sp_2048_mont_reduce_18(t[0], m, mp);
  4292. n = sp_2048_cmp_18(t[0], m);
  4293. sp_2048_cond_sub_18(t[0], t[0], m, ~(n >> 63));
  4294. XMEMCPY(r, t[0], sizeof(*r) * 18 * 2);
  4295. }
  4296. #ifdef WOLFSSL_SP_SMALL_STACK
  4297. if (td != NULL)
  4298. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4299. #endif
  4300. return err;
  4301. #else
  4302. #ifdef WOLFSSL_SP_SMALL_STACK
  4303. sp_digit* td = NULL;
  4304. #else
  4305. sp_digit td[(32 * 36) + 36];
  4306. #endif
  4307. sp_digit* t[32];
  4308. sp_digit* rt = NULL;
  4309. sp_digit* norm = NULL;
  4310. sp_digit mp = 1;
  4311. sp_digit n;
  4312. int i;
  4313. int c;
  4314. byte y;
  4315. int err = MP_OKAY;
  4316. if (bits == 0) {
  4317. err = MP_VAL;
  4318. }
  4319. #ifdef WOLFSSL_SP_SMALL_STACK
  4320. if (err == MP_OKAY) {
  4321. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 36) + 36), NULL,
  4322. DYNAMIC_TYPE_TMP_BUFFER);
  4323. if (td == NULL)
  4324. err = MEMORY_E;
  4325. }
  4326. #endif
  4327. if (err == MP_OKAY) {
  4328. norm = td;
  4329. for (i=0; i<32; i++)
  4330. t[i] = td + i * 36;
  4331. rt = td + 1152;
  4332. sp_2048_mont_setup(m, &mp);
  4333. sp_2048_mont_norm_18(norm, m);
  4334. if (reduceA != 0) {
  4335. err = sp_2048_mod_18(t[1], a, m);
  4336. if (err == MP_OKAY) {
  4337. sp_2048_mul_18(t[1], t[1], norm);
  4338. err = sp_2048_mod_18(t[1], t[1], m);
  4339. }
  4340. }
  4341. else {
  4342. sp_2048_mul_18(t[1], a, norm);
  4343. err = sp_2048_mod_18(t[1], t[1], m);
  4344. }
  4345. }
  4346. if (err == MP_OKAY) {
  4347. sp_2048_mont_sqr_18(t[ 2], t[ 1], m, mp);
  4348. sp_2048_mont_mul_18(t[ 3], t[ 2], t[ 1], m, mp);
  4349. sp_2048_mont_sqr_18(t[ 4], t[ 2], m, mp);
  4350. sp_2048_mont_mul_18(t[ 5], t[ 3], t[ 2], m, mp);
  4351. sp_2048_mont_sqr_18(t[ 6], t[ 3], m, mp);
  4352. sp_2048_mont_mul_18(t[ 7], t[ 4], t[ 3], m, mp);
  4353. sp_2048_mont_sqr_18(t[ 8], t[ 4], m, mp);
  4354. sp_2048_mont_mul_18(t[ 9], t[ 5], t[ 4], m, mp);
  4355. sp_2048_mont_sqr_18(t[10], t[ 5], m, mp);
  4356. sp_2048_mont_mul_18(t[11], t[ 6], t[ 5], m, mp);
  4357. sp_2048_mont_sqr_18(t[12], t[ 6], m, mp);
  4358. sp_2048_mont_mul_18(t[13], t[ 7], t[ 6], m, mp);
  4359. sp_2048_mont_sqr_18(t[14], t[ 7], m, mp);
  4360. sp_2048_mont_mul_18(t[15], t[ 8], t[ 7], m, mp);
  4361. sp_2048_mont_sqr_18(t[16], t[ 8], m, mp);
  4362. sp_2048_mont_mul_18(t[17], t[ 9], t[ 8], m, mp);
  4363. sp_2048_mont_sqr_18(t[18], t[ 9], m, mp);
  4364. sp_2048_mont_mul_18(t[19], t[10], t[ 9], m, mp);
  4365. sp_2048_mont_sqr_18(t[20], t[10], m, mp);
  4366. sp_2048_mont_mul_18(t[21], t[11], t[10], m, mp);
  4367. sp_2048_mont_sqr_18(t[22], t[11], m, mp);
  4368. sp_2048_mont_mul_18(t[23], t[12], t[11], m, mp);
  4369. sp_2048_mont_sqr_18(t[24], t[12], m, mp);
  4370. sp_2048_mont_mul_18(t[25], t[13], t[12], m, mp);
  4371. sp_2048_mont_sqr_18(t[26], t[13], m, mp);
  4372. sp_2048_mont_mul_18(t[27], t[14], t[13], m, mp);
  4373. sp_2048_mont_sqr_18(t[28], t[14], m, mp);
  4374. sp_2048_mont_mul_18(t[29], t[15], t[14], m, mp);
  4375. sp_2048_mont_sqr_18(t[30], t[15], m, mp);
  4376. sp_2048_mont_mul_18(t[31], t[16], t[15], m, mp);
  4377. bits = ((bits + 4) / 5) * 5;
  4378. i = ((bits + 56) / 57) - 1;
  4379. c = bits % 57;
  4380. if (c == 0) {
  4381. c = 57;
  4382. }
  4383. if (i < 18) {
  4384. n = e[i--] << (64 - c);
  4385. }
  4386. else {
  4387. n = 0;
  4388. i--;
  4389. }
  4390. if (c < 5) {
  4391. n |= e[i--] << (7 - c);
  4392. c += 57;
  4393. }
  4394. y = (int)((n >> 59) & 0x1f);
  4395. n <<= 5;
  4396. c -= 5;
  4397. XMEMCPY(rt, t[y], sizeof(sp_digit) * 36);
  4398. while ((i >= 0) || (c >= 5)) {
  4399. if (c >= 5) {
  4400. y = (byte)((n >> 59) & 0x1f);
  4401. n <<= 5;
  4402. c -= 5;
  4403. }
  4404. else if (c == 0) {
  4405. n = e[i--] << 7;
  4406. y = (byte)((n >> 59) & 0x1f);
  4407. n <<= 5;
  4408. c = 52;
  4409. }
  4410. else {
  4411. y = (byte)((n >> 59) & 0x1f);
  4412. n = e[i--] << 7;
  4413. c = 5 - c;
  4414. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  4415. n <<= c;
  4416. c = 57 - c;
  4417. }
  4418. sp_2048_mont_sqr_18(rt, rt, m, mp);
  4419. sp_2048_mont_sqr_18(rt, rt, m, mp);
  4420. sp_2048_mont_sqr_18(rt, rt, m, mp);
  4421. sp_2048_mont_sqr_18(rt, rt, m, mp);
  4422. sp_2048_mont_sqr_18(rt, rt, m, mp);
  4423. sp_2048_mont_mul_18(rt, rt, t[y], m, mp);
  4424. }
  4425. sp_2048_mont_reduce_18(rt, m, mp);
  4426. n = sp_2048_cmp_18(rt, m);
  4427. sp_2048_cond_sub_18(rt, rt, m, ~(n >> 63));
  4428. XMEMCPY(r, rt, sizeof(sp_digit) * 36);
  4429. }
  4430. #ifdef WOLFSSL_SP_SMALL_STACK
  4431. if (td != NULL)
  4432. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4433. #endif
  4434. return err;
  4435. #endif
  4436. }
  4437. #endif /* (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) | WOLFSSL_HAVE_SP_DH */
  4438. /* r = 2^n mod m where n is the number of bits to reduce by.
  4439. * Given m must be 2048 bits, just need to subtract.
  4440. *
  4441. * r A single precision number.
  4442. * m A single precision number.
  4443. */
  4444. static void sp_2048_mont_norm_36(sp_digit* r, const sp_digit* m)
  4445. {
  4446. /* Set r = 2^n - 1. */
  4447. int i;
  4448. for (i = 0; i < 32; i += 8) {
  4449. r[i + 0] = 0x1ffffffffffffffL;
  4450. r[i + 1] = 0x1ffffffffffffffL;
  4451. r[i + 2] = 0x1ffffffffffffffL;
  4452. r[i + 3] = 0x1ffffffffffffffL;
  4453. r[i + 4] = 0x1ffffffffffffffL;
  4454. r[i + 5] = 0x1ffffffffffffffL;
  4455. r[i + 6] = 0x1ffffffffffffffL;
  4456. r[i + 7] = 0x1ffffffffffffffL;
  4457. }
  4458. r[32] = 0x1ffffffffffffffL;
  4459. r[33] = 0x1ffffffffffffffL;
  4460. r[34] = 0x1ffffffffffffffL;
  4461. r[35] = 0x1fffffffffffffL;
  4462. /* r = (2^n - 1) mod n */
  4463. (void)sp_2048_sub_36(r, r, m);
  4464. /* Add one so r = 2^n mod m */
  4465. r[0] += 1;
  4466. }
  4467. /* Compare a with b in constant time.
  4468. *
  4469. * a A single precision integer.
  4470. * b A single precision integer.
  4471. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  4472. * respectively.
  4473. */
  4474. static sp_digit sp_2048_cmp_36(const sp_digit* a, const sp_digit* b)
  4475. {
  4476. sp_digit r = 0;
  4477. int i;
  4478. r |= (a[35] - b[35]) & (0 - (sp_digit)1);
  4479. r |= (a[34] - b[34]) & ~(((sp_digit)0 - r) >> 56);
  4480. r |= (a[33] - b[33]) & ~(((sp_digit)0 - r) >> 56);
  4481. r |= (a[32] - b[32]) & ~(((sp_digit)0 - r) >> 56);
  4482. for (i = 24; i >= 0; i -= 8) {
  4483. r |= (a[i + 7] - b[i + 7]) & ~(((sp_digit)0 - r) >> 56);
  4484. r |= (a[i + 6] - b[i + 6]) & ~(((sp_digit)0 - r) >> 56);
  4485. r |= (a[i + 5] - b[i + 5]) & ~(((sp_digit)0 - r) >> 56);
  4486. r |= (a[i + 4] - b[i + 4]) & ~(((sp_digit)0 - r) >> 56);
  4487. r |= (a[i + 3] - b[i + 3]) & ~(((sp_digit)0 - r) >> 56);
  4488. r |= (a[i + 2] - b[i + 2]) & ~(((sp_digit)0 - r) >> 56);
  4489. r |= (a[i + 1] - b[i + 1]) & ~(((sp_digit)0 - r) >> 56);
  4490. r |= (a[i + 0] - b[i + 0]) & ~(((sp_digit)0 - r) >> 56);
  4491. }
  4492. return r;
  4493. }
  4494. /* Conditionally subtract b from a using the mask m.
  4495. * m is -1 to subtract and 0 when not.
  4496. *
  4497. * r A single precision number representing condition subtract result.
  4498. * a A single precision number to subtract from.
  4499. * b A single precision number to subtract.
  4500. * m Mask value to apply.
  4501. */
  4502. static void sp_2048_cond_sub_36(sp_digit* r, const sp_digit* a,
  4503. const sp_digit* b, const sp_digit m)
  4504. {
  4505. int i;
  4506. for (i = 0; i < 32; i += 8) {
  4507. r[i + 0] = a[i + 0] - (b[i + 0] & m);
  4508. r[i + 1] = a[i + 1] - (b[i + 1] & m);
  4509. r[i + 2] = a[i + 2] - (b[i + 2] & m);
  4510. r[i + 3] = a[i + 3] - (b[i + 3] & m);
  4511. r[i + 4] = a[i + 4] - (b[i + 4] & m);
  4512. r[i + 5] = a[i + 5] - (b[i + 5] & m);
  4513. r[i + 6] = a[i + 6] - (b[i + 6] & m);
  4514. r[i + 7] = a[i + 7] - (b[i + 7] & m);
  4515. }
  4516. r[32] = a[32] - (b[32] & m);
  4517. r[33] = a[33] - (b[33] & m);
  4518. r[34] = a[34] - (b[34] & m);
  4519. r[35] = a[35] - (b[35] & m);
  4520. }
  4521. /* Mul a by scalar b and add into r. (r += a * b)
  4522. *
  4523. * r A single precision integer.
  4524. * a A single precision integer.
  4525. * b A scalar.
  4526. */
  4527. SP_NOINLINE static void sp_2048_mul_add_36(sp_digit* r, const sp_digit* a,
  4528. const sp_digit b)
  4529. {
  4530. sp_int128 tb = b;
  4531. sp_int128 t[8];
  4532. int i;
  4533. t[0] = tb * a[0]; r[0] += (sp_digit)(t[0] & 0x1ffffffffffffffL);
  4534. for (i = 0; i < 32; i += 8) {
  4535. t[1] = tb * a[i+1];
  4536. r[i+1] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  4537. t[2] = tb * a[i+2];
  4538. r[i+2] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  4539. t[3] = tb * a[i+3];
  4540. r[i+3] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL));
  4541. t[4] = tb * a[i+4];
  4542. r[i+4] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL));
  4543. t[5] = tb * a[i+5];
  4544. r[i+5] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL));
  4545. t[6] = tb * a[i+6];
  4546. r[i+6] += (sp_digit)((t[5] >> 57) + (t[6] & 0x1ffffffffffffffL));
  4547. t[7] = tb * a[i+7];
  4548. r[i+7] += (sp_digit)((t[6] >> 57) + (t[7] & 0x1ffffffffffffffL));
  4549. t[0] = tb * a[i+8];
  4550. r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL));
  4551. }
  4552. t[1] = tb * a[33];
  4553. r[33] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  4554. t[2] = tb * a[34];
  4555. r[34] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  4556. t[3] = tb * a[35];
  4557. r[35] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL));
  4558. r[36] += (sp_digit)(t[3] >> 57);
  4559. }
  4560. /* Shift the result in the high 2048 bits down to the bottom.
  4561. *
  4562. * r A single precision number.
  4563. * a A single precision number.
  4564. */
  4565. static void sp_2048_mont_shift_36(sp_digit* r, const sp_digit* a)
  4566. {
  4567. sp_digit n;
  4568. sp_digit s;
  4569. int i;
  4570. s = a[36]; n = a[35] >> 53;
  4571. for (i = 0; i < 32; i += 8) {
  4572. n += (s & 0x1ffffffffffffffL) << 4; r[i+0] = n & 0x1ffffffffffffffL;
  4573. n >>= 57; s = a[i+37] + (s >> 57);
  4574. n += (s & 0x1ffffffffffffffL) << 4; r[i+1] = n & 0x1ffffffffffffffL;
  4575. n >>= 57; s = a[i+38] + (s >> 57);
  4576. n += (s & 0x1ffffffffffffffL) << 4; r[i+2] = n & 0x1ffffffffffffffL;
  4577. n >>= 57; s = a[i+39] + (s >> 57);
  4578. n += (s & 0x1ffffffffffffffL) << 4; r[i+3] = n & 0x1ffffffffffffffL;
  4579. n >>= 57; s = a[i+40] + (s >> 57);
  4580. n += (s & 0x1ffffffffffffffL) << 4; r[i+4] = n & 0x1ffffffffffffffL;
  4581. n >>= 57; s = a[i+41] + (s >> 57);
  4582. n += (s & 0x1ffffffffffffffL) << 4; r[i+5] = n & 0x1ffffffffffffffL;
  4583. n >>= 57; s = a[i+42] + (s >> 57);
  4584. n += (s & 0x1ffffffffffffffL) << 4; r[i+6] = n & 0x1ffffffffffffffL;
  4585. n >>= 57; s = a[i+43] + (s >> 57);
  4586. n += (s & 0x1ffffffffffffffL) << 4; r[i+7] = n & 0x1ffffffffffffffL;
  4587. n >>= 57; s = a[i+44] + (s >> 57);
  4588. }
  4589. n += (s & 0x1ffffffffffffffL) << 4; r[32] = n & 0x1ffffffffffffffL;
  4590. n >>= 57; s = a[69] + (s >> 57);
  4591. n += (s & 0x1ffffffffffffffL) << 4; r[33] = n & 0x1ffffffffffffffL;
  4592. n >>= 57; s = a[70] + (s >> 57);
  4593. n += (s & 0x1ffffffffffffffL) << 4; r[34] = n & 0x1ffffffffffffffL;
  4594. n >>= 57; s = a[71] + (s >> 57);
  4595. n += s << 4; r[35] = n;
  4596. XMEMSET(&r[36], 0, sizeof(*r) * 36U);
  4597. }
  4598. /* Reduce the number back to 2048 bits using Montgomery reduction.
  4599. *
  4600. * a A single precision number to reduce in place.
  4601. * m The single precision number representing the modulus.
  4602. * mp The digit representing the negative inverse of m mod 2^n.
  4603. */
  4604. static void sp_2048_mont_reduce_36(sp_digit* a, const sp_digit* m, sp_digit mp)
  4605. {
  4606. int i;
  4607. sp_digit mu;
  4608. sp_digit over;
  4609. sp_2048_norm_36(a + 36);
  4610. #ifdef WOLFSSL_SP_DH
  4611. if (mp != 1) {
  4612. for (i=0; i<35; i++) {
  4613. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL;
  4614. sp_2048_mul_add_36(a+i, m, mu);
  4615. a[i+1] += a[i] >> 57;
  4616. }
  4617. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffL;
  4618. sp_2048_mul_add_36(a+i, m, mu);
  4619. a[i+1] += a[i] >> 57;
  4620. a[i] &= 0x1ffffffffffffffL;
  4621. }
  4622. else {
  4623. for (i=0; i<35; i++) {
  4624. mu = a[i] & 0x1ffffffffffffffL;
  4625. sp_2048_mul_add_36(a+i, m, mu);
  4626. a[i+1] += a[i] >> 57;
  4627. }
  4628. mu = a[i] & 0x1fffffffffffffL;
  4629. sp_2048_mul_add_36(a+i, m, mu);
  4630. a[i+1] += a[i] >> 57;
  4631. a[i] &= 0x1ffffffffffffffL;
  4632. }
  4633. #else
  4634. for (i=0; i<35; i++) {
  4635. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL;
  4636. sp_2048_mul_add_36(a+i, m, mu);
  4637. a[i+1] += a[i] >> 57;
  4638. }
  4639. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffL;
  4640. sp_2048_mul_add_36(a+i, m, mu);
  4641. a[i+1] += a[i] >> 57;
  4642. a[i] &= 0x1ffffffffffffffL;
  4643. #endif
  4644. sp_2048_mont_shift_36(a, a);
  4645. over = a[35] - m[35];
  4646. sp_2048_cond_sub_36(a, a, m, ~((over - 1) >> 63));
  4647. sp_2048_norm_36(a);
  4648. }
  4649. /* Multiply two Montgomery form numbers mod the modulus (prime).
  4650. * (r = a * b mod m)
  4651. *
  4652. * r Result of multiplication.
  4653. * a First number to multiply in Montgomery form.
  4654. * b Second number to multiply in Montgomery form.
  4655. * m Modulus (prime).
  4656. * mp Montgomery multiplier.
  4657. */
  4658. SP_NOINLINE static void sp_2048_mont_mul_36(sp_digit* r, const sp_digit* a,
  4659. const sp_digit* b, const sp_digit* m, sp_digit mp)
  4660. {
  4661. sp_2048_mul_36(r, a, b);
  4662. sp_2048_mont_reduce_36(r, m, mp);
  4663. }
  4664. /* Square the Montgomery form number. (r = a * a mod m)
  4665. *
  4666. * r Result of squaring.
  4667. * a Number to square in Montgomery form.
  4668. * m Modulus (prime).
  4669. * mp Montgomery multiplier.
  4670. */
  4671. SP_NOINLINE static void sp_2048_mont_sqr_36(sp_digit* r, const sp_digit* a,
  4672. const sp_digit* m, sp_digit mp)
  4673. {
  4674. sp_2048_sqr_36(r, a);
  4675. sp_2048_mont_reduce_36(r, m, mp);
  4676. }
  4677. /* Multiply a by scalar b into r. (r = a * b)
  4678. *
  4679. * r A single precision integer.
  4680. * a A single precision integer.
  4681. * b A scalar.
  4682. */
  4683. SP_NOINLINE static void sp_2048_mul_d_72(sp_digit* r, const sp_digit* a,
  4684. sp_digit b)
  4685. {
  4686. sp_int128 tb = b;
  4687. sp_int128 t = 0;
  4688. sp_digit t2;
  4689. sp_int128 p[4];
  4690. int i;
  4691. for (i = 0; i < 72; i += 4) {
  4692. p[0] = tb * a[i + 0];
  4693. p[1] = tb * a[i + 1];
  4694. p[2] = tb * a[i + 2];
  4695. p[3] = tb * a[i + 3];
  4696. t += p[0];
  4697. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  4698. t >>= 57;
  4699. r[i + 0] = (sp_digit)t2;
  4700. t += p[1];
  4701. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  4702. t >>= 57;
  4703. r[i + 1] = (sp_digit)t2;
  4704. t += p[2];
  4705. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  4706. t >>= 57;
  4707. r[i + 2] = (sp_digit)t2;
  4708. t += p[3];
  4709. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  4710. t >>= 57;
  4711. r[i + 3] = (sp_digit)t2;
  4712. }
  4713. r[72] = (sp_digit)(t & 0x1ffffffffffffffL);
  4714. }
  4715. #ifndef WOLFSSL_SP_SMALL
  4716. /* Conditionally add a and b using the mask m.
  4717. * m is -1 to add and 0 when not.
  4718. *
  4719. * r A single precision number representing conditional add result.
  4720. * a A single precision number to add with.
  4721. * b A single precision number to add.
  4722. * m Mask value to apply.
  4723. */
  4724. static void sp_2048_cond_add_36(sp_digit* r, const sp_digit* a,
  4725. const sp_digit* b, const sp_digit m)
  4726. {
  4727. int i;
  4728. for (i = 0; i < 32; i += 8) {
  4729. r[i + 0] = a[i + 0] + (b[i + 0] & m);
  4730. r[i + 1] = a[i + 1] + (b[i + 1] & m);
  4731. r[i + 2] = a[i + 2] + (b[i + 2] & m);
  4732. r[i + 3] = a[i + 3] + (b[i + 3] & m);
  4733. r[i + 4] = a[i + 4] + (b[i + 4] & m);
  4734. r[i + 5] = a[i + 5] + (b[i + 5] & m);
  4735. r[i + 6] = a[i + 6] + (b[i + 6] & m);
  4736. r[i + 7] = a[i + 7] + (b[i + 7] & m);
  4737. }
  4738. r[32] = a[32] + (b[32] & m);
  4739. r[33] = a[33] + (b[33] & m);
  4740. r[34] = a[34] + (b[34] & m);
  4741. r[35] = a[35] + (b[35] & m);
  4742. }
  4743. #endif /* !WOLFSSL_SP_SMALL */
  4744. SP_NOINLINE static void sp_2048_rshift_36(sp_digit* r, const sp_digit* a,
  4745. byte n)
  4746. {
  4747. int i;
  4748. for (i=0; i<32; i += 8) {
  4749. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (57 - n)) & 0x1ffffffffffffffL);
  4750. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (57 - n)) & 0x1ffffffffffffffL);
  4751. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (57 - n)) & 0x1ffffffffffffffL);
  4752. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (57 - n)) & 0x1ffffffffffffffL);
  4753. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (57 - n)) & 0x1ffffffffffffffL);
  4754. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (57 - n)) & 0x1ffffffffffffffL);
  4755. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (57 - n)) & 0x1ffffffffffffffL);
  4756. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (57 - n)) & 0x1ffffffffffffffL);
  4757. }
  4758. r[32] = (a[32] >> n) | ((a[33] << (57 - n)) & 0x1ffffffffffffffL);
  4759. r[33] = (a[33] >> n) | ((a[34] << (57 - n)) & 0x1ffffffffffffffL);
  4760. r[34] = (a[34] >> n) | ((a[35] << (57 - n)) & 0x1ffffffffffffffL);
  4761. r[35] = a[35] >> n;
  4762. }
  4763. static WC_INLINE sp_digit sp_2048_div_word_36(sp_digit d1, sp_digit d0,
  4764. sp_digit div)
  4765. {
  4766. #ifdef SP_USE_DIVTI3
  4767. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  4768. return d / div;
  4769. #elif defined(__x86_64__) || defined(__i386__)
  4770. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  4771. sp_uint64 lo = (sp_uint64)d;
  4772. sp_digit hi = (sp_digit)(d >> 64);
  4773. __asm__ __volatile__ (
  4774. "idiv %2"
  4775. : "+a" (lo)
  4776. : "d" (hi), "r" (div)
  4777. : "cc"
  4778. );
  4779. return (sp_digit)lo;
  4780. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  4781. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  4782. sp_digit dv = (div >> 1) + 1;
  4783. sp_digit t1 = (sp_digit)(d >> 57);
  4784. sp_digit t0 = (sp_digit)(d & 0x1ffffffffffffffL);
  4785. sp_digit t2;
  4786. sp_digit sign;
  4787. sp_digit r;
  4788. int i;
  4789. sp_int128 m;
  4790. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  4791. t1 -= dv & (0 - r);
  4792. for (i = 55; i >= 1; i--) {
  4793. t1 += t1 + (((sp_uint64)t0 >> 56) & 1);
  4794. t0 <<= 1;
  4795. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  4796. r += r + t2;
  4797. t1 -= dv & (0 - t2);
  4798. t1 += t2;
  4799. }
  4800. r += r + 1;
  4801. m = d - ((sp_int128)r * div);
  4802. r += (sp_digit)(m >> 57);
  4803. m = d - ((sp_int128)r * div);
  4804. r += (sp_digit)(m >> 114) - (sp_digit)(d >> 114);
  4805. m = d - ((sp_int128)r * div);
  4806. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  4807. m *= sign;
  4808. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  4809. r += sign * t2;
  4810. m = d - ((sp_int128)r * div);
  4811. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  4812. m *= sign;
  4813. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  4814. r += sign * t2;
  4815. return r;
  4816. #else
  4817. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  4818. sp_digit r = 0;
  4819. sp_digit t;
  4820. sp_digit dv = (div >> 26) + 1;
  4821. t = (sp_digit)(d >> 52);
  4822. t = (t / dv) << 26;
  4823. r += t;
  4824. d -= (sp_int128)t * div;
  4825. t = (sp_digit)(d >> 21);
  4826. t = t / (dv << 5);
  4827. r += t;
  4828. d -= (sp_int128)t * div;
  4829. t = (sp_digit)d;
  4830. t = t / div;
  4831. r += t;
  4832. d -= (sp_int128)t * div;
  4833. return r;
  4834. #endif
  4835. }
  4836. static WC_INLINE sp_digit sp_2048_word_div_word_36(sp_digit d, sp_digit div)
  4837. {
  4838. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  4839. defined(SP_DIV_WORD_USE_DIV)
  4840. return d / div;
  4841. #else
  4842. return (sp_digit)((sp_uint64)(div - d) >> 63);
  4843. #endif
  4844. }
  4845. /* Divide d in a and put remainder into r (m*d + r = a)
  4846. * m is not calculated as it is not needed at this time.
  4847. *
  4848. * Full implementation.
  4849. *
  4850. * a Number to be divided.
  4851. * d Number to divide with.
  4852. * m Multiplier result.
  4853. * r Remainder from the division.
  4854. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  4855. */
  4856. static int sp_2048_div_36(const sp_digit* a, const sp_digit* d,
  4857. const sp_digit* m, sp_digit* r)
  4858. {
  4859. int i;
  4860. #ifndef WOLFSSL_SP_DIV_64
  4861. #endif
  4862. sp_digit dv;
  4863. sp_digit r1;
  4864. #ifdef WOLFSSL_SP_SMALL_STACK
  4865. sp_digit* t1 = NULL;
  4866. #else
  4867. sp_digit t1[4 * 36 + 3];
  4868. #endif
  4869. sp_digit* t2 = NULL;
  4870. sp_digit* sd = NULL;
  4871. int err = MP_OKAY;
  4872. (void)m;
  4873. #ifdef WOLFSSL_SP_SMALL_STACK
  4874. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 36 + 3), NULL,
  4875. DYNAMIC_TYPE_TMP_BUFFER);
  4876. if (t1 == NULL)
  4877. err = MEMORY_E;
  4878. #endif
  4879. (void)m;
  4880. if (err == MP_OKAY) {
  4881. t2 = t1 + 72 + 1;
  4882. sd = t2 + 36 + 1;
  4883. sp_2048_mul_d_36(sd, d, (sp_digit)1 << 4);
  4884. sp_2048_mul_d_72(t1, a, (sp_digit)1 << 4);
  4885. dv = sd[35];
  4886. t1[36 + 36] += t1[36 + 36 - 1] >> 57;
  4887. t1[36 + 36 - 1] &= 0x1ffffffffffffffL;
  4888. for (i=36; i>=0; i--) {
  4889. r1 = sp_2048_div_word_36(t1[36 + i], t1[36 + i - 1], dv);
  4890. sp_2048_mul_d_36(t2, sd, r1);
  4891. (void)sp_2048_sub_36(&t1[i], &t1[i], t2);
  4892. sp_2048_norm_36(&t1[i]);
  4893. t1[36 + i] -= t2[36];
  4894. t1[36 + i] += t1[36 + i - 1] >> 57;
  4895. t1[36 + i - 1] &= 0x1ffffffffffffffL;
  4896. r1 = sp_2048_div_word_36(-t1[36 + i], -t1[36 + i - 1], dv);
  4897. r1 -= t1[36 + i];
  4898. sp_2048_mul_d_36(t2, sd, r1);
  4899. (void)sp_2048_add_36(&t1[i], &t1[i], t2);
  4900. t1[36 + i] += t1[36 + i - 1] >> 57;
  4901. t1[36 + i - 1] &= 0x1ffffffffffffffL;
  4902. }
  4903. t1[36 - 1] += t1[36 - 2] >> 57;
  4904. t1[36 - 2] &= 0x1ffffffffffffffL;
  4905. r1 = sp_2048_word_div_word_36(t1[36 - 1], dv);
  4906. sp_2048_mul_d_36(t2, sd, r1);
  4907. sp_2048_sub_36(t1, t1, t2);
  4908. XMEMCPY(r, t1, sizeof(*r) * 72U);
  4909. for (i=0; i<35; i++) {
  4910. r[i+1] += r[i] >> 57;
  4911. r[i] &= 0x1ffffffffffffffL;
  4912. }
  4913. sp_2048_cond_add_36(r, r, sd, r[35] >> 63);
  4914. sp_2048_norm_36(r);
  4915. sp_2048_rshift_36(r, r, 4);
  4916. }
  4917. #ifdef WOLFSSL_SP_SMALL_STACK
  4918. if (t1 != NULL)
  4919. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4920. #endif
  4921. return err;
  4922. }
  4923. /* Reduce a modulo m into r. (r = a mod m)
  4924. *
  4925. * r A single precision number that is the reduced result.
  4926. * a A single precision number that is to be reduced.
  4927. * m A single precision number that is the modulus to reduce with.
  4928. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  4929. */
  4930. static int sp_2048_mod_36(sp_digit* r, const sp_digit* a, const sp_digit* m)
  4931. {
  4932. return sp_2048_div_36(a, m, NULL, r);
  4933. }
  4934. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  4935. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  4936. defined(WOLFSSL_HAVE_SP_DH)
  4937. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  4938. *
  4939. * r A single precision number that is the result of the operation.
  4940. * a A single precision number being exponentiated.
  4941. * e A single precision number that is the exponent.
  4942. * bits The number of bits in the exponent.
  4943. * m A single precision number that is the modulus.
  4944. * returns 0 on success.
  4945. * returns MEMORY_E on dynamic memory allocation failure.
  4946. * returns MP_VAL when base is even or exponent is 0.
  4947. */
  4948. static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e,
  4949. int bits, const sp_digit* m, int reduceA)
  4950. {
  4951. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  4952. #ifdef WOLFSSL_SP_SMALL_STACK
  4953. sp_digit* td = NULL;
  4954. #else
  4955. sp_digit td[3 * 72];
  4956. #endif
  4957. sp_digit* t[3] = {0, 0, 0};
  4958. sp_digit* norm = NULL;
  4959. sp_digit mp = 1;
  4960. sp_digit n;
  4961. int i;
  4962. int c;
  4963. byte y;
  4964. int err = MP_OKAY;
  4965. if (bits == 0) {
  4966. err = MP_VAL;
  4967. }
  4968. #ifdef WOLFSSL_SP_SMALL_STACK
  4969. if (err == MP_OKAY) {
  4970. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL,
  4971. DYNAMIC_TYPE_TMP_BUFFER);
  4972. if (td == NULL)
  4973. err = MEMORY_E;
  4974. }
  4975. #endif
  4976. if (err == MP_OKAY) {
  4977. norm = td;
  4978. for (i=0; i<3; i++) {
  4979. t[i] = td + (i * 36 * 2);
  4980. XMEMSET(t[i], 0, sizeof(sp_digit) * 36U * 2U);
  4981. }
  4982. sp_2048_mont_setup(m, &mp);
  4983. sp_2048_mont_norm_36(norm, m);
  4984. if (reduceA != 0) {
  4985. err = sp_2048_mod_36(t[1], a, m);
  4986. }
  4987. else {
  4988. XMEMCPY(t[1], a, sizeof(sp_digit) * 36U);
  4989. }
  4990. }
  4991. if (err == MP_OKAY) {
  4992. sp_2048_mul_36(t[1], t[1], norm);
  4993. err = sp_2048_mod_36(t[1], t[1], m);
  4994. }
  4995. if (err == MP_OKAY) {
  4996. i = bits / 57;
  4997. c = bits % 57;
  4998. n = e[i--] << (57 - c);
  4999. for (; ; c--) {
  5000. if (c == 0) {
  5001. if (i == -1) {
  5002. break;
  5003. }
  5004. n = e[i--];
  5005. c = 57;
  5006. }
  5007. y = (int)((n >> 56) & 1);
  5008. n <<= 1;
  5009. sp_2048_mont_mul_36(t[y^1], t[0], t[1], m, mp);
  5010. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  5011. ((size_t)t[1] & addr_mask[y])),
  5012. sizeof(*t[2]) * 36 * 2);
  5013. sp_2048_mont_sqr_36(t[2], t[2], m, mp);
  5014. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  5015. ((size_t)t[1] & addr_mask[y])), t[2],
  5016. sizeof(*t[2]) * 36 * 2);
  5017. }
  5018. sp_2048_mont_reduce_36(t[0], m, mp);
  5019. n = sp_2048_cmp_36(t[0], m);
  5020. sp_2048_cond_sub_36(t[0], t[0], m, ~(n >> 63));
  5021. XMEMCPY(r, t[0], sizeof(*r) * 36 * 2);
  5022. }
  5023. #ifdef WOLFSSL_SP_SMALL_STACK
  5024. if (td != NULL)
  5025. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5026. #endif
  5027. return err;
  5028. #elif !defined(WC_NO_CACHE_RESISTANT)
  5029. #ifdef WOLFSSL_SP_SMALL_STACK
  5030. sp_digit* td = NULL;
  5031. #else
  5032. sp_digit td[3 * 72];
  5033. #endif
  5034. sp_digit* t[3] = {0, 0, 0};
  5035. sp_digit* norm = NULL;
  5036. sp_digit mp = 1;
  5037. sp_digit n;
  5038. int i;
  5039. int c;
  5040. byte y;
  5041. int err = MP_OKAY;
  5042. if (bits == 0) {
  5043. err = MP_VAL;
  5044. }
  5045. #ifdef WOLFSSL_SP_SMALL_STACK
  5046. if (err == MP_OKAY) {
  5047. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL,
  5048. DYNAMIC_TYPE_TMP_BUFFER);
  5049. if (td == NULL)
  5050. err = MEMORY_E;
  5051. }
  5052. #endif
  5053. if (err == MP_OKAY) {
  5054. norm = td;
  5055. for (i=0; i<3; i++) {
  5056. t[i] = td + (i * 36 * 2);
  5057. }
  5058. sp_2048_mont_setup(m, &mp);
  5059. sp_2048_mont_norm_36(norm, m);
  5060. if (reduceA != 0) {
  5061. err = sp_2048_mod_36(t[1], a, m);
  5062. if (err == MP_OKAY) {
  5063. sp_2048_mul_36(t[1], t[1], norm);
  5064. err = sp_2048_mod_36(t[1], t[1], m);
  5065. }
  5066. }
  5067. else {
  5068. sp_2048_mul_36(t[1], a, norm);
  5069. err = sp_2048_mod_36(t[1], t[1], m);
  5070. }
  5071. }
  5072. if (err == MP_OKAY) {
  5073. i = bits / 57;
  5074. c = bits % 57;
  5075. n = e[i--] << (57 - c);
  5076. for (; ; c--) {
  5077. if (c == 0) {
  5078. if (i == -1) {
  5079. break;
  5080. }
  5081. n = e[i--];
  5082. c = 57;
  5083. }
  5084. y = (int)((n >> 56) & 1);
  5085. n <<= 1;
  5086. sp_2048_mont_mul_36(t[y^1], t[0], t[1], m, mp);
  5087. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  5088. ((size_t)t[1] & addr_mask[y])),
  5089. sizeof(*t[2]) * 36 * 2);
  5090. sp_2048_mont_sqr_36(t[2], t[2], m, mp);
  5091. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  5092. ((size_t)t[1] & addr_mask[y])), t[2],
  5093. sizeof(*t[2]) * 36 * 2);
  5094. }
  5095. sp_2048_mont_reduce_36(t[0], m, mp);
  5096. n = sp_2048_cmp_36(t[0], m);
  5097. sp_2048_cond_sub_36(t[0], t[0], m, ~(n >> 63));
  5098. XMEMCPY(r, t[0], sizeof(*r) * 36 * 2);
  5099. }
  5100. #ifdef WOLFSSL_SP_SMALL_STACK
  5101. if (td != NULL)
  5102. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5103. #endif
  5104. return err;
  5105. #else
  5106. #ifdef WOLFSSL_SP_SMALL_STACK
  5107. sp_digit* td = NULL;
  5108. #else
  5109. sp_digit td[(16 * 72) + 72];
  5110. #endif
  5111. sp_digit* t[16];
  5112. sp_digit* rt = NULL;
  5113. sp_digit* norm = NULL;
  5114. sp_digit mp = 1;
  5115. sp_digit n;
  5116. int i;
  5117. int c;
  5118. byte y;
  5119. int err = MP_OKAY;
  5120. if (bits == 0) {
  5121. err = MP_VAL;
  5122. }
  5123. #ifdef WOLFSSL_SP_SMALL_STACK
  5124. if (err == MP_OKAY) {
  5125. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 72) + 72), NULL,
  5126. DYNAMIC_TYPE_TMP_BUFFER);
  5127. if (td == NULL)
  5128. err = MEMORY_E;
  5129. }
  5130. #endif
  5131. if (err == MP_OKAY) {
  5132. norm = td;
  5133. for (i=0; i<16; i++)
  5134. t[i] = td + i * 72;
  5135. rt = td + 1152;
  5136. sp_2048_mont_setup(m, &mp);
  5137. sp_2048_mont_norm_36(norm, m);
  5138. if (reduceA != 0) {
  5139. err = sp_2048_mod_36(t[1], a, m);
  5140. if (err == MP_OKAY) {
  5141. sp_2048_mul_36(t[1], t[1], norm);
  5142. err = sp_2048_mod_36(t[1], t[1], m);
  5143. }
  5144. }
  5145. else {
  5146. sp_2048_mul_36(t[1], a, norm);
  5147. err = sp_2048_mod_36(t[1], t[1], m);
  5148. }
  5149. }
  5150. if (err == MP_OKAY) {
  5151. sp_2048_mont_sqr_36(t[ 2], t[ 1], m, mp);
  5152. sp_2048_mont_mul_36(t[ 3], t[ 2], t[ 1], m, mp);
  5153. sp_2048_mont_sqr_36(t[ 4], t[ 2], m, mp);
  5154. sp_2048_mont_mul_36(t[ 5], t[ 3], t[ 2], m, mp);
  5155. sp_2048_mont_sqr_36(t[ 6], t[ 3], m, mp);
  5156. sp_2048_mont_mul_36(t[ 7], t[ 4], t[ 3], m, mp);
  5157. sp_2048_mont_sqr_36(t[ 8], t[ 4], m, mp);
  5158. sp_2048_mont_mul_36(t[ 9], t[ 5], t[ 4], m, mp);
  5159. sp_2048_mont_sqr_36(t[10], t[ 5], m, mp);
  5160. sp_2048_mont_mul_36(t[11], t[ 6], t[ 5], m, mp);
  5161. sp_2048_mont_sqr_36(t[12], t[ 6], m, mp);
  5162. sp_2048_mont_mul_36(t[13], t[ 7], t[ 6], m, mp);
  5163. sp_2048_mont_sqr_36(t[14], t[ 7], m, mp);
  5164. sp_2048_mont_mul_36(t[15], t[ 8], t[ 7], m, mp);
  5165. bits = ((bits + 3) / 4) * 4;
  5166. i = ((bits + 56) / 57) - 1;
  5167. c = bits % 57;
  5168. if (c == 0) {
  5169. c = 57;
  5170. }
  5171. if (i < 36) {
  5172. n = e[i--] << (64 - c);
  5173. }
  5174. else {
  5175. n = 0;
  5176. i--;
  5177. }
  5178. if (c < 4) {
  5179. n |= e[i--] << (7 - c);
  5180. c += 57;
  5181. }
  5182. y = (int)((n >> 60) & 0xf);
  5183. n <<= 4;
  5184. c -= 4;
  5185. XMEMCPY(rt, t[y], sizeof(sp_digit) * 72);
  5186. while ((i >= 0) || (c >= 4)) {
  5187. if (c >= 4) {
  5188. y = (byte)((n >> 60) & 0xf);
  5189. n <<= 4;
  5190. c -= 4;
  5191. }
  5192. else if (c == 0) {
  5193. n = e[i--] << 7;
  5194. y = (byte)((n >> 60) & 0xf);
  5195. n <<= 4;
  5196. c = 53;
  5197. }
  5198. else {
  5199. y = (byte)((n >> 60) & 0xf);
  5200. n = e[i--] << 7;
  5201. c = 4 - c;
  5202. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  5203. n <<= c;
  5204. c = 57 - c;
  5205. }
  5206. sp_2048_mont_sqr_36(rt, rt, m, mp);
  5207. sp_2048_mont_sqr_36(rt, rt, m, mp);
  5208. sp_2048_mont_sqr_36(rt, rt, m, mp);
  5209. sp_2048_mont_sqr_36(rt, rt, m, mp);
  5210. sp_2048_mont_mul_36(rt, rt, t[y], m, mp);
  5211. }
  5212. sp_2048_mont_reduce_36(rt, m, mp);
  5213. n = sp_2048_cmp_36(rt, m);
  5214. sp_2048_cond_sub_36(rt, rt, m, ~(n >> 63));
  5215. XMEMCPY(r, rt, sizeof(sp_digit) * 72);
  5216. }
  5217. #ifdef WOLFSSL_SP_SMALL_STACK
  5218. if (td != NULL)
  5219. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5220. #endif
  5221. return err;
  5222. #endif
  5223. }
  5224. #endif /* (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) || */
  5225. /* WOLFSSL_HAVE_SP_DH */
  5226. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  5227. #ifdef WOLFSSL_HAVE_SP_RSA
  5228. /* RSA public key operation.
  5229. *
  5230. * in Array of bytes representing the number to exponentiate, base.
  5231. * inLen Number of bytes in base.
  5232. * em Public exponent.
  5233. * mm Modulus.
  5234. * out Buffer to hold big-endian bytes of exponentiation result.
  5235. * Must be at least 256 bytes long.
  5236. * outLen Number of bytes in result.
  5237. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  5238. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  5239. */
  5240. int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em,
  5241. const mp_int* mm, byte* out, word32* outLen)
  5242. {
  5243. #ifdef WOLFSSL_SP_SMALL
  5244. #ifdef WOLFSSL_SP_SMALL_STACK
  5245. sp_digit* a = NULL;
  5246. #else
  5247. sp_digit a[36 * 5];
  5248. #endif
  5249. sp_digit* m = NULL;
  5250. sp_digit* r = NULL;
  5251. sp_digit* norm = NULL;
  5252. sp_digit e[1] = {0};
  5253. sp_digit mp = 0;
  5254. int i;
  5255. int err = MP_OKAY;
  5256. if (*outLen < 256U) {
  5257. err = MP_TO_E;
  5258. }
  5259. if (err == MP_OKAY) {
  5260. if (mp_count_bits(em) > 57) {
  5261. err = MP_READ_E;
  5262. }
  5263. else if (inLen > 256U) {
  5264. err = MP_READ_E;
  5265. }
  5266. else if (mp_count_bits(mm) != 2048) {
  5267. err = MP_READ_E;
  5268. }
  5269. else if (mp_iseven(mm)) {
  5270. err = MP_VAL;
  5271. }
  5272. }
  5273. #ifdef WOLFSSL_SP_SMALL_STACK
  5274. if (err == MP_OKAY) {
  5275. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 5, NULL,
  5276. DYNAMIC_TYPE_RSA);
  5277. if (a == NULL)
  5278. err = MEMORY_E;
  5279. }
  5280. #endif
  5281. if (err == MP_OKAY) {
  5282. r = a + 36 * 2;
  5283. m = r + 36 * 2;
  5284. norm = r;
  5285. sp_2048_from_bin(a, 36, in, inLen);
  5286. #if DIGIT_BIT >= 57
  5287. e[0] = (sp_digit)em->dp[0];
  5288. #else
  5289. e[0] = (sp_digit)em->dp[0];
  5290. if (em->used > 1) {
  5291. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  5292. }
  5293. #endif
  5294. if (e[0] == 0) {
  5295. err = MP_EXPTMOD_E;
  5296. }
  5297. }
  5298. if (err == MP_OKAY) {
  5299. sp_2048_from_mp(m, 36, mm);
  5300. sp_2048_mont_setup(m, &mp);
  5301. sp_2048_mont_norm_36(norm, m);
  5302. }
  5303. if (err == MP_OKAY) {
  5304. sp_2048_mul_36(a, a, norm);
  5305. err = sp_2048_mod_36(a, a, m);
  5306. }
  5307. if (err == MP_OKAY) {
  5308. for (i=56; i>=0; i--) {
  5309. if ((e[0] >> i) != 0) {
  5310. break;
  5311. }
  5312. }
  5313. XMEMCPY(r, a, sizeof(sp_digit) * 36 * 2);
  5314. for (i--; i>=0; i--) {
  5315. sp_2048_mont_sqr_36(r, r, m, mp);
  5316. if (((e[0] >> i) & 1) == 1) {
  5317. sp_2048_mont_mul_36(r, r, a, m, mp);
  5318. }
  5319. }
  5320. sp_2048_mont_reduce_36(r, m, mp);
  5321. mp = sp_2048_cmp_36(r, m);
  5322. sp_2048_cond_sub_36(r, r, m, ~(mp >> 63));
  5323. sp_2048_to_bin_36(r, out);
  5324. *outLen = 256;
  5325. }
  5326. #ifdef WOLFSSL_SP_SMALL_STACK
  5327. if (a != NULL)
  5328. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  5329. #endif
  5330. return err;
  5331. #else
  5332. #ifdef WOLFSSL_SP_SMALL_STACK
  5333. sp_digit* d = NULL;
  5334. #else
  5335. sp_digit d[36 * 5];
  5336. #endif
  5337. sp_digit* a = NULL;
  5338. sp_digit* m = NULL;
  5339. sp_digit* r = NULL;
  5340. sp_digit e[1] = {0};
  5341. int err = MP_OKAY;
  5342. if (*outLen < 256U) {
  5343. err = MP_TO_E;
  5344. }
  5345. if (err == MP_OKAY) {
  5346. if (mp_count_bits(em) > 57) {
  5347. err = MP_READ_E;
  5348. }
  5349. else if (inLen > 256U) {
  5350. err = MP_READ_E;
  5351. }
  5352. else if (mp_count_bits(mm) != 2048) {
  5353. err = MP_READ_E;
  5354. }
  5355. else if (mp_iseven(mm)) {
  5356. err = MP_VAL;
  5357. }
  5358. }
  5359. #ifdef WOLFSSL_SP_SMALL_STACK
  5360. if (err == MP_OKAY) {
  5361. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 5, NULL,
  5362. DYNAMIC_TYPE_RSA);
  5363. if (d == NULL)
  5364. err = MEMORY_E;
  5365. }
  5366. #endif
  5367. if (err == MP_OKAY) {
  5368. a = d;
  5369. r = a + 36 * 2;
  5370. m = r + 36 * 2;
  5371. sp_2048_from_bin(a, 36, in, inLen);
  5372. #if DIGIT_BIT >= 57
  5373. e[0] = (sp_digit)em->dp[0];
  5374. #else
  5375. e[0] = (sp_digit)em->dp[0];
  5376. if (em->used > 1) {
  5377. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  5378. }
  5379. #endif
  5380. if (e[0] == 0) {
  5381. err = MP_EXPTMOD_E;
  5382. }
  5383. }
  5384. if (err == MP_OKAY) {
  5385. sp_2048_from_mp(m, 36, mm);
  5386. if (e[0] == 0x3) {
  5387. sp_2048_sqr_36(r, a);
  5388. err = sp_2048_mod_36(r, r, m);
  5389. if (err == MP_OKAY) {
  5390. sp_2048_mul_36(r, a, r);
  5391. err = sp_2048_mod_36(r, r, m);
  5392. }
  5393. }
  5394. else {
  5395. sp_digit* norm = r;
  5396. int i;
  5397. sp_digit mp;
  5398. sp_2048_mont_setup(m, &mp);
  5399. sp_2048_mont_norm_36(norm, m);
  5400. sp_2048_mul_36(a, a, norm);
  5401. err = sp_2048_mod_36(a, a, m);
  5402. if (err == MP_OKAY) {
  5403. for (i=56; i>=0; i--) {
  5404. if ((e[0] >> i) != 0) {
  5405. break;
  5406. }
  5407. }
  5408. XMEMCPY(r, a, sizeof(sp_digit) * 72U);
  5409. for (i--; i>=0; i--) {
  5410. sp_2048_mont_sqr_36(r, r, m, mp);
  5411. if (((e[0] >> i) & 1) == 1) {
  5412. sp_2048_mont_mul_36(r, r, a, m, mp);
  5413. }
  5414. }
  5415. sp_2048_mont_reduce_36(r, m, mp);
  5416. mp = sp_2048_cmp_36(r, m);
  5417. sp_2048_cond_sub_36(r, r, m, ~(mp >> 63));
  5418. }
  5419. }
  5420. }
  5421. if (err == MP_OKAY) {
  5422. sp_2048_to_bin_36(r, out);
  5423. *outLen = 256;
  5424. }
  5425. #ifdef WOLFSSL_SP_SMALL_STACK
  5426. if (d != NULL)
  5427. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  5428. #endif
  5429. return err;
  5430. #endif /* WOLFSSL_SP_SMALL */
  5431. }
  5432. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  5433. #if !defined(SP_RSA_PRIVATE_EXP_D) && !defined(RSA_LOW_MEM)
  5434. #endif /* !SP_RSA_PRIVATE_EXP_D & !RSA_LOW_MEM */
  5435. /* RSA private key operation.
  5436. *
  5437. * in Array of bytes representing the number to exponentiate, base.
  5438. * inLen Number of bytes in base.
  5439. * dm Private exponent.
  5440. * pm First prime.
  5441. * qm Second prime.
  5442. * dpm First prime's CRT exponent.
  5443. * dqm Second prime's CRT exponent.
  5444. * qim Inverse of second prime mod p.
  5445. * mm Modulus.
  5446. * out Buffer to hold big-endian bytes of exponentiation result.
  5447. * Must be at least 256 bytes long.
  5448. * outLen Number of bytes in result.
  5449. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  5450. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  5451. */
  5452. int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm,
  5453. const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm,
  5454. const mp_int* qim, const mp_int* mm, byte* out, word32* outLen)
  5455. {
  5456. #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM)
  5457. #if defined(WOLFSSL_SP_SMALL)
  5458. #ifdef WOLFSSL_SP_SMALL_STACK
  5459. sp_digit* d = NULL;
  5460. #else
  5461. sp_digit d[36 * 4];
  5462. #endif
  5463. sp_digit* a = NULL;
  5464. sp_digit* m = NULL;
  5465. sp_digit* r = NULL;
  5466. int err = MP_OKAY;
  5467. (void)pm;
  5468. (void)qm;
  5469. (void)dpm;
  5470. (void)dqm;
  5471. (void)qim;
  5472. if (*outLen < 256U) {
  5473. err = MP_TO_E;
  5474. }
  5475. if (err == MP_OKAY) {
  5476. if (mp_count_bits(dm) > 2048) {
  5477. err = MP_READ_E;
  5478. }
  5479. else if (inLen > 256) {
  5480. err = MP_READ_E;
  5481. }
  5482. else if (mp_count_bits(mm) != 2048) {
  5483. err = MP_READ_E;
  5484. }
  5485. else if (mp_iseven(mm)) {
  5486. err = MP_VAL;
  5487. }
  5488. }
  5489. #ifdef WOLFSSL_SP_SMALL_STACK
  5490. if (err == MP_OKAY) {
  5491. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL,
  5492. DYNAMIC_TYPE_RSA);
  5493. if (d == NULL)
  5494. err = MEMORY_E;
  5495. }
  5496. #endif
  5497. if (err == MP_OKAY) {
  5498. a = d + 36;
  5499. m = a + 72;
  5500. r = a;
  5501. sp_2048_from_bin(a, 36, in, inLen);
  5502. sp_2048_from_mp(d, 36, dm);
  5503. sp_2048_from_mp(m, 36, mm);
  5504. err = sp_2048_mod_exp_36(r, a, d, 2048, m, 0);
  5505. }
  5506. if (err == MP_OKAY) {
  5507. sp_2048_to_bin_36(r, out);
  5508. *outLen = 256;
  5509. }
  5510. #ifdef WOLFSSL_SP_SMALL_STACK
  5511. if (d != NULL)
  5512. #endif
  5513. {
  5514. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  5515. if (a != NULL)
  5516. ForceZero(a, sizeof(sp_digit) * 36);
  5517. #ifdef WOLFSSL_SP_SMALL_STACK
  5518. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  5519. #endif
  5520. }
  5521. return err;
  5522. #else
  5523. #ifdef WOLFSSL_SP_SMALL_STACK
  5524. sp_digit* d = NULL;
  5525. #else
  5526. sp_digit d[36 * 4];
  5527. #endif
  5528. sp_digit* a = NULL;
  5529. sp_digit* m = NULL;
  5530. sp_digit* r = NULL;
  5531. int err = MP_OKAY;
  5532. (void)pm;
  5533. (void)qm;
  5534. (void)dpm;
  5535. (void)dqm;
  5536. (void)qim;
  5537. if (*outLen < 256U) {
  5538. err = MP_TO_E;
  5539. }
  5540. if (err == MP_OKAY) {
  5541. if (mp_count_bits(dm) > 2048) {
  5542. err = MP_READ_E;
  5543. }
  5544. else if (inLen > 256U) {
  5545. err = MP_READ_E;
  5546. }
  5547. else if (mp_count_bits(mm) != 2048) {
  5548. err = MP_READ_E;
  5549. }
  5550. else if (mp_iseven(mm)) {
  5551. err = MP_VAL;
  5552. }
  5553. }
  5554. #ifdef WOLFSSL_SP_SMALL_STACK
  5555. if (err == MP_OKAY) {
  5556. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL,
  5557. DYNAMIC_TYPE_RSA);
  5558. if (d == NULL)
  5559. err = MEMORY_E;
  5560. }
  5561. #endif
  5562. if (err == MP_OKAY) {
  5563. a = d + 36;
  5564. m = a + 72;
  5565. r = a;
  5566. sp_2048_from_bin(a, 36, in, inLen);
  5567. sp_2048_from_mp(d, 36, dm);
  5568. sp_2048_from_mp(m, 36, mm);
  5569. err = sp_2048_mod_exp_36(r, a, d, 2048, m, 0);
  5570. }
  5571. if (err == MP_OKAY) {
  5572. sp_2048_to_bin_36(r, out);
  5573. *outLen = 256;
  5574. }
  5575. #ifdef WOLFSSL_SP_SMALL_STACK
  5576. if (d != NULL)
  5577. #endif
  5578. {
  5579. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  5580. if (a != NULL)
  5581. ForceZero(a, sizeof(sp_digit) * 36);
  5582. #ifdef WOLFSSL_SP_SMALL_STACK
  5583. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  5584. #endif
  5585. }
  5586. return err;
  5587. #endif /* WOLFSSL_SP_SMALL */
  5588. #else
  5589. #if defined(WOLFSSL_SP_SMALL)
  5590. #ifdef WOLFSSL_SP_SMALL_STACK
  5591. sp_digit* a = NULL;
  5592. #else
  5593. sp_digit a[18 * 8];
  5594. #endif
  5595. sp_digit* p = NULL;
  5596. sp_digit* dp = NULL;
  5597. sp_digit* dq = NULL;
  5598. sp_digit* qi = NULL;
  5599. sp_digit* tmpa = NULL;
  5600. sp_digit* tmpb = NULL;
  5601. sp_digit* r = NULL;
  5602. int err = MP_OKAY;
  5603. (void)dm;
  5604. (void)mm;
  5605. if (*outLen < 256U) {
  5606. err = MP_TO_E;
  5607. }
  5608. if (err == MP_OKAY) {
  5609. if (inLen > 256) {
  5610. err = MP_READ_E;
  5611. }
  5612. else if (mp_count_bits(mm) != 2048) {
  5613. err = MP_READ_E;
  5614. }
  5615. else if (mp_iseven(mm)) {
  5616. err = MP_VAL;
  5617. }
  5618. else if (mp_iseven(pm)) {
  5619. err = MP_VAL;
  5620. }
  5621. else if (mp_iseven(qm)) {
  5622. err = MP_VAL;
  5623. }
  5624. }
  5625. #ifdef WOLFSSL_SP_SMALL_STACK
  5626. if (err == MP_OKAY) {
  5627. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 8, NULL,
  5628. DYNAMIC_TYPE_RSA);
  5629. if (a == NULL)
  5630. err = MEMORY_E;
  5631. }
  5632. #endif
  5633. if (err == MP_OKAY) {
  5634. p = a + 36;
  5635. qi = dq = dp = p + 18;
  5636. tmpa = qi + 18;
  5637. tmpb = tmpa + 36;
  5638. r = a;
  5639. sp_2048_from_bin(a, 36, in, inLen);
  5640. sp_2048_from_mp(p, 18, pm);
  5641. sp_2048_from_mp(dp, 18, dpm);
  5642. err = sp_2048_mod_exp_18(tmpa, a, dp, 1024, p, 1);
  5643. }
  5644. if (err == MP_OKAY) {
  5645. sp_2048_from_mp(p, 18, qm);
  5646. sp_2048_from_mp(dq, 18, dqm);
  5647. err = sp_2048_mod_exp_18(tmpb, a, dq, 1024, p, 1);
  5648. }
  5649. if (err == MP_OKAY) {
  5650. sp_2048_from_mp(p, 18, pm);
  5651. (void)sp_2048_sub_18(tmpa, tmpa, tmpb);
  5652. sp_2048_norm_18(tmpa);
  5653. sp_2048_cond_add_18(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[17] >> 63));
  5654. sp_2048_cond_add_18(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[17] >> 63));
  5655. sp_2048_norm_18(tmpa);
  5656. sp_2048_from_mp(qi, 18, qim);
  5657. sp_2048_mul_18(tmpa, tmpa, qi);
  5658. err = sp_2048_mod_18(tmpa, tmpa, p);
  5659. }
  5660. if (err == MP_OKAY) {
  5661. sp_2048_from_mp(p, 18, qm);
  5662. sp_2048_mul_18(tmpa, p, tmpa);
  5663. (void)sp_2048_add_36(r, tmpb, tmpa);
  5664. sp_2048_norm_36(r);
  5665. sp_2048_to_bin_36(r, out);
  5666. *outLen = 256;
  5667. }
  5668. #ifdef WOLFSSL_SP_SMALL_STACK
  5669. if (a != NULL)
  5670. #endif
  5671. {
  5672. ForceZero(a, sizeof(sp_digit) * 18 * 8);
  5673. #ifdef WOLFSSL_SP_SMALL_STACK
  5674. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  5675. #endif
  5676. }
  5677. return err;
  5678. #else
  5679. #ifdef WOLFSSL_SP_SMALL_STACK
  5680. sp_digit* a = NULL;
  5681. #else
  5682. sp_digit a[18 * 13];
  5683. #endif
  5684. sp_digit* p = NULL;
  5685. sp_digit* q = NULL;
  5686. sp_digit* dp = NULL;
  5687. sp_digit* dq = NULL;
  5688. sp_digit* qi = NULL;
  5689. sp_digit* tmpa = NULL;
  5690. sp_digit* tmpb = NULL;
  5691. sp_digit* r = NULL;
  5692. int err = MP_OKAY;
  5693. (void)dm;
  5694. (void)mm;
  5695. if (*outLen < 256U) {
  5696. err = MP_TO_E;
  5697. }
  5698. if (err == MP_OKAY) {
  5699. if (inLen > 256U) {
  5700. err = MP_READ_E;
  5701. }
  5702. else if (mp_count_bits(mm) != 2048) {
  5703. err = MP_READ_E;
  5704. }
  5705. else if (mp_iseven(mm)) {
  5706. err = MP_VAL;
  5707. }
  5708. else if (mp_iseven(pm)) {
  5709. err = MP_VAL;
  5710. }
  5711. else if (mp_iseven(qm)) {
  5712. err = MP_VAL;
  5713. }
  5714. }
  5715. #ifdef WOLFSSL_SP_SMALL_STACK
  5716. if (err == MP_OKAY) {
  5717. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 13, NULL,
  5718. DYNAMIC_TYPE_RSA);
  5719. if (a == NULL)
  5720. err = MEMORY_E;
  5721. }
  5722. #endif
  5723. if (err == MP_OKAY) {
  5724. p = a + 36 * 2;
  5725. q = p + 18;
  5726. dp = q + 18;
  5727. dq = dp + 18;
  5728. qi = dq + 18;
  5729. tmpa = qi + 18;
  5730. tmpb = tmpa + 36;
  5731. r = a;
  5732. sp_2048_from_bin(a, 36, in, inLen);
  5733. sp_2048_from_mp(p, 18, pm);
  5734. sp_2048_from_mp(q, 18, qm);
  5735. sp_2048_from_mp(dp, 18, dpm);
  5736. sp_2048_from_mp(dq, 18, dqm);
  5737. sp_2048_from_mp(qi, 18, qim);
  5738. err = sp_2048_mod_exp_18(tmpa, a, dp, 1024, p, 1);
  5739. }
  5740. if (err == MP_OKAY) {
  5741. err = sp_2048_mod_exp_18(tmpb, a, dq, 1024, q, 1);
  5742. }
  5743. if (err == MP_OKAY) {
  5744. (void)sp_2048_sub_18(tmpa, tmpa, tmpb);
  5745. sp_2048_norm_18(tmpa);
  5746. sp_2048_cond_add_18(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[17] >> 63));
  5747. sp_2048_cond_add_18(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[17] >> 63));
  5748. sp_2048_norm_18(tmpa);
  5749. sp_2048_mul_18(tmpa, tmpa, qi);
  5750. err = sp_2048_mod_18(tmpa, tmpa, p);
  5751. }
  5752. if (err == MP_OKAY) {
  5753. sp_2048_mul_18(tmpa, tmpa, q);
  5754. (void)sp_2048_add_36(r, tmpb, tmpa);
  5755. sp_2048_norm_36(r);
  5756. sp_2048_to_bin_36(r, out);
  5757. *outLen = 256;
  5758. }
  5759. #ifdef WOLFSSL_SP_SMALL_STACK
  5760. if (a != NULL)
  5761. #endif
  5762. {
  5763. ForceZero(a, sizeof(sp_digit) * 18 * 13);
  5764. #ifdef WOLFSSL_SP_SMALL_STACK
  5765. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  5766. #endif
  5767. }
  5768. return err;
  5769. #endif /* WOLFSSL_SP_SMALL */
  5770. #endif /* SP_RSA_PRIVATE_EXP_D || RSA_LOW_MEM */
  5771. }
  5772. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  5773. #endif /* WOLFSSL_HAVE_SP_RSA */
  5774. #if defined(WOLFSSL_HAVE_SP_DH) || (defined(WOLFSSL_HAVE_SP_RSA) && \
  5775. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  5776. /* Convert an array of sp_digit to an mp_int.
  5777. *
  5778. * a A single precision integer.
  5779. * r A multi-precision integer.
  5780. */
  5781. static int sp_2048_to_mp(const sp_digit* a, mp_int* r)
  5782. {
  5783. int err;
  5784. err = mp_grow(r, (2048 + DIGIT_BIT - 1) / DIGIT_BIT);
  5785. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  5786. #if DIGIT_BIT == 57
  5787. XMEMCPY(r->dp, a, sizeof(sp_digit) * 36);
  5788. r->used = 36;
  5789. mp_clamp(r);
  5790. #elif DIGIT_BIT < 57
  5791. int i;
  5792. int j = 0;
  5793. int s = 0;
  5794. r->dp[0] = 0;
  5795. for (i = 0; i < 36; i++) {
  5796. r->dp[j] |= (mp_digit)(a[i] << s);
  5797. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  5798. s = DIGIT_BIT - s;
  5799. r->dp[++j] = (mp_digit)(a[i] >> s);
  5800. while (s + DIGIT_BIT <= 57) {
  5801. s += DIGIT_BIT;
  5802. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  5803. if (s == SP_WORD_SIZE) {
  5804. r->dp[j] = 0;
  5805. }
  5806. else {
  5807. r->dp[j] = (mp_digit)(a[i] >> s);
  5808. }
  5809. }
  5810. s = 57 - s;
  5811. }
  5812. r->used = (2048 + DIGIT_BIT - 1) / DIGIT_BIT;
  5813. mp_clamp(r);
  5814. #else
  5815. int i;
  5816. int j = 0;
  5817. int s = 0;
  5818. r->dp[0] = 0;
  5819. for (i = 0; i < 36; i++) {
  5820. r->dp[j] |= ((mp_digit)a[i]) << s;
  5821. if (s + 57 >= DIGIT_BIT) {
  5822. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  5823. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  5824. #endif
  5825. s = DIGIT_BIT - s;
  5826. r->dp[++j] = a[i] >> s;
  5827. s = 57 - s;
  5828. }
  5829. else {
  5830. s += 57;
  5831. }
  5832. }
  5833. r->used = (2048 + DIGIT_BIT - 1) / DIGIT_BIT;
  5834. mp_clamp(r);
  5835. #endif
  5836. }
  5837. return err;
  5838. }
  5839. /* Perform the modular exponentiation for Diffie-Hellman.
  5840. *
  5841. * base Base. MP integer.
  5842. * exp Exponent. MP integer.
  5843. * mod Modulus. MP integer.
  5844. * res Result. MP integer.
  5845. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  5846. * and MEMORY_E if memory allocation fails.
  5847. */
  5848. int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod,
  5849. mp_int* res)
  5850. {
  5851. #ifdef WOLFSSL_SP_SMALL
  5852. int err = MP_OKAY;
  5853. #ifdef WOLFSSL_SP_SMALL_STACK
  5854. sp_digit* b = NULL;
  5855. #else
  5856. sp_digit b[36 * 4];
  5857. #endif
  5858. sp_digit* e = NULL;
  5859. sp_digit* m = NULL;
  5860. sp_digit* r = NULL;
  5861. int expBits = mp_count_bits(exp);
  5862. if (mp_count_bits(base) > 2048) {
  5863. err = MP_READ_E;
  5864. }
  5865. else if (expBits > 2048) {
  5866. err = MP_READ_E;
  5867. }
  5868. else if (mp_count_bits(mod) != 2048) {
  5869. err = MP_READ_E;
  5870. }
  5871. else if (mp_iseven(mod)) {
  5872. err = MP_VAL;
  5873. }
  5874. #ifdef WOLFSSL_SP_SMALL_STACK
  5875. if (err == MP_OKAY) {
  5876. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL,
  5877. DYNAMIC_TYPE_DH);
  5878. if (b == NULL)
  5879. err = MEMORY_E;
  5880. }
  5881. #endif
  5882. if (err == MP_OKAY) {
  5883. e = b + 36 * 2;
  5884. m = e + 36;
  5885. r = b;
  5886. sp_2048_from_mp(b, 36, base);
  5887. sp_2048_from_mp(e, 36, exp);
  5888. sp_2048_from_mp(m, 36, mod);
  5889. err = sp_2048_mod_exp_36(r, b, e, mp_count_bits(exp), m, 0);
  5890. }
  5891. if (err == MP_OKAY) {
  5892. err = sp_2048_to_mp(r, res);
  5893. }
  5894. #ifdef WOLFSSL_SP_SMALL_STACK
  5895. if (b != NULL)
  5896. #endif
  5897. {
  5898. /* only "e" is sensitive and needs zeroized */
  5899. if (e != NULL)
  5900. ForceZero(e, sizeof(sp_digit) * 36U);
  5901. #ifdef WOLFSSL_SP_SMALL_STACK
  5902. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  5903. #endif
  5904. }
  5905. return err;
  5906. #else
  5907. #ifdef WOLFSSL_SP_SMALL_STACK
  5908. sp_digit* b = NULL;
  5909. #else
  5910. sp_digit b[36 * 4];
  5911. #endif
  5912. sp_digit* e = NULL;
  5913. sp_digit* m = NULL;
  5914. sp_digit* r = NULL;
  5915. int err = MP_OKAY;
  5916. int expBits = mp_count_bits(exp);
  5917. if (mp_count_bits(base) > 2048) {
  5918. err = MP_READ_E;
  5919. }
  5920. else if (expBits > 2048) {
  5921. err = MP_READ_E;
  5922. }
  5923. else if (mp_count_bits(mod) != 2048) {
  5924. err = MP_READ_E;
  5925. }
  5926. else if (mp_iseven(mod)) {
  5927. err = MP_VAL;
  5928. }
  5929. #ifdef WOLFSSL_SP_SMALL_STACK
  5930. if (err == MP_OKAY) {
  5931. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_DH);
  5932. if (b == NULL)
  5933. err = MEMORY_E;
  5934. }
  5935. #endif
  5936. if (err == MP_OKAY) {
  5937. e = b + 36 * 2;
  5938. m = e + 36;
  5939. r = b;
  5940. sp_2048_from_mp(b, 36, base);
  5941. sp_2048_from_mp(e, 36, exp);
  5942. sp_2048_from_mp(m, 36, mod);
  5943. err = sp_2048_mod_exp_36(r, b, e, expBits, m, 0);
  5944. }
  5945. if (err == MP_OKAY) {
  5946. err = sp_2048_to_mp(r, res);
  5947. }
  5948. #ifdef WOLFSSL_SP_SMALL_STACK
  5949. if (b != NULL)
  5950. #endif
  5951. {
  5952. /* only "e" is sensitive and needs zeroized */
  5953. if (e != NULL)
  5954. ForceZero(e, sizeof(sp_digit) * 36U);
  5955. #ifdef WOLFSSL_SP_SMALL_STACK
  5956. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  5957. #endif
  5958. }
  5959. return err;
  5960. #endif
  5961. }
  5962. #ifdef WOLFSSL_HAVE_SP_DH
  5963. #ifdef HAVE_FFDHE_2048
  5964. SP_NOINLINE static void sp_2048_lshift_36(sp_digit* r, const sp_digit* a,
  5965. byte n)
  5966. {
  5967. sp_int_digit s;
  5968. sp_int_digit t;
  5969. s = (sp_int_digit)a[35];
  5970. r[36] = s >> (57U - n);
  5971. s = (sp_int_digit)(a[35]); t = (sp_int_digit)(a[34]);
  5972. r[35] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5973. s = (sp_int_digit)(a[34]); t = (sp_int_digit)(a[33]);
  5974. r[34] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5975. s = (sp_int_digit)(a[33]); t = (sp_int_digit)(a[32]);
  5976. r[33] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5977. s = (sp_int_digit)(a[32]); t = (sp_int_digit)(a[31]);
  5978. r[32] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5979. s = (sp_int_digit)(a[31]); t = (sp_int_digit)(a[30]);
  5980. r[31] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5981. s = (sp_int_digit)(a[30]); t = (sp_int_digit)(a[29]);
  5982. r[30] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5983. s = (sp_int_digit)(a[29]); t = (sp_int_digit)(a[28]);
  5984. r[29] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5985. s = (sp_int_digit)(a[28]); t = (sp_int_digit)(a[27]);
  5986. r[28] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5987. s = (sp_int_digit)(a[27]); t = (sp_int_digit)(a[26]);
  5988. r[27] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5989. s = (sp_int_digit)(a[26]); t = (sp_int_digit)(a[25]);
  5990. r[26] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5991. s = (sp_int_digit)(a[25]); t = (sp_int_digit)(a[24]);
  5992. r[25] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5993. s = (sp_int_digit)(a[24]); t = (sp_int_digit)(a[23]);
  5994. r[24] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5995. s = (sp_int_digit)(a[23]); t = (sp_int_digit)(a[22]);
  5996. r[23] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5997. s = (sp_int_digit)(a[22]); t = (sp_int_digit)(a[21]);
  5998. r[22] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  5999. s = (sp_int_digit)(a[21]); t = (sp_int_digit)(a[20]);
  6000. r[21] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6001. s = (sp_int_digit)(a[20]); t = (sp_int_digit)(a[19]);
  6002. r[20] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6003. s = (sp_int_digit)(a[19]); t = (sp_int_digit)(a[18]);
  6004. r[19] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6005. s = (sp_int_digit)(a[18]); t = (sp_int_digit)(a[17]);
  6006. r[18] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6007. s = (sp_int_digit)(a[17]); t = (sp_int_digit)(a[16]);
  6008. r[17] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6009. s = (sp_int_digit)(a[16]); t = (sp_int_digit)(a[15]);
  6010. r[16] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6011. s = (sp_int_digit)(a[15]); t = (sp_int_digit)(a[14]);
  6012. r[15] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6013. s = (sp_int_digit)(a[14]); t = (sp_int_digit)(a[13]);
  6014. r[14] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6015. s = (sp_int_digit)(a[13]); t = (sp_int_digit)(a[12]);
  6016. r[13] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6017. s = (sp_int_digit)(a[12]); t = (sp_int_digit)(a[11]);
  6018. r[12] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6019. s = (sp_int_digit)(a[11]); t = (sp_int_digit)(a[10]);
  6020. r[11] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6021. s = (sp_int_digit)(a[10]); t = (sp_int_digit)(a[9]);
  6022. r[10] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6023. s = (sp_int_digit)(a[9]); t = (sp_int_digit)(a[8]);
  6024. r[9] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6025. s = (sp_int_digit)(a[8]); t = (sp_int_digit)(a[7]);
  6026. r[8] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6027. s = (sp_int_digit)(a[7]); t = (sp_int_digit)(a[6]);
  6028. r[7] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6029. s = (sp_int_digit)(a[6]); t = (sp_int_digit)(a[5]);
  6030. r[6] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6031. s = (sp_int_digit)(a[5]); t = (sp_int_digit)(a[4]);
  6032. r[5] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6033. s = (sp_int_digit)(a[4]); t = (sp_int_digit)(a[3]);
  6034. r[4] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6035. s = (sp_int_digit)(a[3]); t = (sp_int_digit)(a[2]);
  6036. r[3] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6037. s = (sp_int_digit)(a[2]); t = (sp_int_digit)(a[1]);
  6038. r[2] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6039. s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]);
  6040. r[1] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  6041. r[0] = (a[0] << n) & 0x1ffffffffffffffL;
  6042. }
  6043. /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m)
  6044. *
  6045. * r A single precision number that is the result of the operation.
  6046. * e A single precision number that is the exponent.
  6047. * bits The number of bits in the exponent.
  6048. * m A single precision number that is the modulus.
  6049. * returns 0 on success.
  6050. * returns MEMORY_E on dynamic memory allocation failure.
  6051. * returns MP_VAL when base is even.
  6052. */
  6053. static int sp_2048_mod_exp_2_36(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
  6054. {
  6055. #ifdef WOLFSSL_SP_SMALL_STACK
  6056. sp_digit* td = NULL;
  6057. #else
  6058. sp_digit td[109];
  6059. #endif
  6060. sp_digit* norm = NULL;
  6061. sp_digit* tmp = NULL;
  6062. sp_digit mp = 1;
  6063. sp_digit n;
  6064. sp_digit o;
  6065. int i;
  6066. int c;
  6067. byte y;
  6068. int err = MP_OKAY;
  6069. if (bits == 0) {
  6070. err = MP_VAL;
  6071. }
  6072. #ifdef WOLFSSL_SP_SMALL_STACK
  6073. if (err == MP_OKAY) {
  6074. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 109, NULL,
  6075. DYNAMIC_TYPE_TMP_BUFFER);
  6076. if (td == NULL)
  6077. err = MEMORY_E;
  6078. }
  6079. #endif
  6080. if (err == MP_OKAY) {
  6081. norm = td;
  6082. tmp = td + 72;
  6083. XMEMSET(td, 0, sizeof(sp_digit) * 109);
  6084. sp_2048_mont_setup(m, &mp);
  6085. sp_2048_mont_norm_36(norm, m);
  6086. bits = ((bits + 4) / 5) * 5;
  6087. i = ((bits + 56) / 57) - 1;
  6088. c = bits % 57;
  6089. if (c == 0) {
  6090. c = 57;
  6091. }
  6092. if (i < 36) {
  6093. n = e[i--] << (64 - c);
  6094. }
  6095. else {
  6096. n = 0;
  6097. i--;
  6098. }
  6099. if (c < 5) {
  6100. n |= e[i--] << (7 - c);
  6101. c += 57;
  6102. }
  6103. y = (int)((n >> 59) & 0x1f);
  6104. n <<= 5;
  6105. c -= 5;
  6106. sp_2048_lshift_36(r, norm, (byte)y);
  6107. while ((i >= 0) || (c >= 5)) {
  6108. if (c >= 5) {
  6109. y = (byte)((n >> 59) & 0x1f);
  6110. n <<= 5;
  6111. c -= 5;
  6112. }
  6113. else if (c == 0) {
  6114. n = e[i--] << 7;
  6115. y = (byte)((n >> 59) & 0x1f);
  6116. n <<= 5;
  6117. c = 52;
  6118. }
  6119. else {
  6120. y = (byte)((n >> 59) & 0x1f);
  6121. n = e[i--] << 7;
  6122. c = 5 - c;
  6123. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  6124. n <<= c;
  6125. c = 57 - c;
  6126. }
  6127. sp_2048_mont_sqr_36(r, r, m, mp);
  6128. sp_2048_mont_sqr_36(r, r, m, mp);
  6129. sp_2048_mont_sqr_36(r, r, m, mp);
  6130. sp_2048_mont_sqr_36(r, r, m, mp);
  6131. sp_2048_mont_sqr_36(r, r, m, mp);
  6132. sp_2048_lshift_36(r, r, (byte)y);
  6133. sp_2048_mul_d_36(tmp, norm, (r[36] << 4) + (r[35] >> 53));
  6134. r[36] = 0;
  6135. r[35] &= 0x1fffffffffffffL;
  6136. (void)sp_2048_add_36(r, r, tmp);
  6137. sp_2048_norm_36(r);
  6138. o = sp_2048_cmp_36(r, m);
  6139. sp_2048_cond_sub_36(r, r, m, ~(o >> 63));
  6140. }
  6141. sp_2048_mont_reduce_36(r, m, mp);
  6142. n = sp_2048_cmp_36(r, m);
  6143. sp_2048_cond_sub_36(r, r, m, ~(n >> 63));
  6144. }
  6145. #ifdef WOLFSSL_SP_SMALL_STACK
  6146. if (td != NULL)
  6147. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  6148. #endif
  6149. return err;
  6150. }
  6151. #endif /* HAVE_FFDHE_2048 */
  6152. /* Perform the modular exponentiation for Diffie-Hellman.
  6153. *
  6154. * base Base.
  6155. * exp Array of bytes that is the exponent.
  6156. * expLen Length of data, in bytes, in exponent.
  6157. * mod Modulus.
  6158. * out Buffer to hold big-endian bytes of exponentiation result.
  6159. * Must be at least 256 bytes long.
  6160. * outLen Length, in bytes, of exponentiation result.
  6161. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  6162. * and MEMORY_E if memory allocation fails.
  6163. */
  6164. int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen,
  6165. const mp_int* mod, byte* out, word32* outLen)
  6166. {
  6167. #ifdef WOLFSSL_SP_SMALL_STACK
  6168. sp_digit* b = NULL;
  6169. #else
  6170. sp_digit b[36 * 4];
  6171. #endif
  6172. sp_digit* e = NULL;
  6173. sp_digit* m = NULL;
  6174. sp_digit* r = NULL;
  6175. word32 i;
  6176. int err = MP_OKAY;
  6177. if (mp_count_bits(base) > 2048) {
  6178. err = MP_READ_E;
  6179. }
  6180. else if (expLen > 256U) {
  6181. err = MP_READ_E;
  6182. }
  6183. else if (mp_count_bits(mod) != 2048) {
  6184. err = MP_READ_E;
  6185. }
  6186. else if (mp_iseven(mod)) {
  6187. err = MP_VAL;
  6188. }
  6189. #ifdef WOLFSSL_SP_SMALL_STACK
  6190. if (err == MP_OKAY) {
  6191. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL,
  6192. DYNAMIC_TYPE_DH);
  6193. if (b == NULL)
  6194. err = MEMORY_E;
  6195. }
  6196. #endif
  6197. if (err == MP_OKAY) {
  6198. e = b + 36 * 2;
  6199. m = e + 36;
  6200. r = b;
  6201. sp_2048_from_mp(b, 36, base);
  6202. sp_2048_from_bin(e, 36, exp, expLen);
  6203. sp_2048_from_mp(m, 36, mod);
  6204. #ifdef HAVE_FFDHE_2048
  6205. if (base->used == 1 && base->dp[0] == 2U &&
  6206. (m[35] >> 21) == 0xffffffffL) {
  6207. err = sp_2048_mod_exp_2_36(r, e, expLen * 8U, m);
  6208. }
  6209. else {
  6210. #endif
  6211. err = sp_2048_mod_exp_36(r, b, e, expLen * 8U, m, 0);
  6212. #ifdef HAVE_FFDHE_2048
  6213. }
  6214. #endif
  6215. }
  6216. if (err == MP_OKAY) {
  6217. sp_2048_to_bin_36(r, out);
  6218. *outLen = 256;
  6219. for (i=0; i<256U && out[i] == 0U; i++) {
  6220. /* Search for first non-zero. */
  6221. }
  6222. *outLen -= i;
  6223. XMEMMOVE(out, out + i, *outLen);
  6224. }
  6225. #ifdef WOLFSSL_SP_SMALL_STACK
  6226. if (b != NULL)
  6227. #endif
  6228. {
  6229. /* only "e" is sensitive and needs zeroized */
  6230. if (e != NULL)
  6231. ForceZero(e, sizeof(sp_digit) * 36U);
  6232. #ifdef WOLFSSL_SP_SMALL_STACK
  6233. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  6234. #endif
  6235. }
  6236. return err;
  6237. }
  6238. #endif /* WOLFSSL_HAVE_SP_DH */
  6239. /* Perform the modular exponentiation for Diffie-Hellman.
  6240. *
  6241. * base Base. MP integer.
  6242. * exp Exponent. MP integer.
  6243. * mod Modulus. MP integer.
  6244. * res Result. MP integer.
  6245. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  6246. * and MEMORY_E if memory allocation fails.
  6247. */
  6248. int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod,
  6249. mp_int* res)
  6250. {
  6251. #ifdef WOLFSSL_SP_SMALL
  6252. int err = MP_OKAY;
  6253. #ifdef WOLFSSL_SP_SMALL_STACK
  6254. sp_digit* b = NULL;
  6255. #else
  6256. sp_digit b[18 * 4];
  6257. #endif
  6258. sp_digit* e = NULL;
  6259. sp_digit* m = NULL;
  6260. sp_digit* r = NULL;
  6261. int expBits = mp_count_bits(exp);
  6262. if (mp_count_bits(base) > 1024) {
  6263. err = MP_READ_E;
  6264. }
  6265. else if (expBits > 1024) {
  6266. err = MP_READ_E;
  6267. }
  6268. else if (mp_count_bits(mod) != 1024) {
  6269. err = MP_READ_E;
  6270. }
  6271. else if (mp_iseven(mod)) {
  6272. err = MP_VAL;
  6273. }
  6274. #ifdef WOLFSSL_SP_SMALL_STACK
  6275. if (err == MP_OKAY) {
  6276. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 4, NULL,
  6277. DYNAMIC_TYPE_DH);
  6278. if (b == NULL)
  6279. err = MEMORY_E;
  6280. }
  6281. #endif
  6282. if (err == MP_OKAY) {
  6283. e = b + 18 * 2;
  6284. m = e + 18;
  6285. r = b;
  6286. sp_2048_from_mp(b, 18, base);
  6287. sp_2048_from_mp(e, 18, exp);
  6288. sp_2048_from_mp(m, 18, mod);
  6289. err = sp_2048_mod_exp_18(r, b, e, mp_count_bits(exp), m, 0);
  6290. }
  6291. if (err == MP_OKAY) {
  6292. XMEMSET(r + 18, 0, sizeof(*r) * 18U);
  6293. err = sp_2048_to_mp(r, res);
  6294. }
  6295. #ifdef WOLFSSL_SP_SMALL_STACK
  6296. if (b != NULL)
  6297. #endif
  6298. {
  6299. /* only "e" is sensitive and needs zeroized */
  6300. if (e != NULL)
  6301. ForceZero(e, sizeof(sp_digit) * 36U);
  6302. #ifdef WOLFSSL_SP_SMALL_STACK
  6303. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  6304. #endif
  6305. }
  6306. return err;
  6307. #else
  6308. #ifdef WOLFSSL_SP_SMALL_STACK
  6309. sp_digit* b = NULL;
  6310. #else
  6311. sp_digit b[18 * 4];
  6312. #endif
  6313. sp_digit* e = NULL;
  6314. sp_digit* m = NULL;
  6315. sp_digit* r = NULL;
  6316. int err = MP_OKAY;
  6317. int expBits = mp_count_bits(exp);
  6318. if (mp_count_bits(base) > 1024) {
  6319. err = MP_READ_E;
  6320. }
  6321. else if (expBits > 1024) {
  6322. err = MP_READ_E;
  6323. }
  6324. else if (mp_count_bits(mod) != 1024) {
  6325. err = MP_READ_E;
  6326. }
  6327. else if (mp_iseven(mod)) {
  6328. err = MP_VAL;
  6329. }
  6330. #ifdef WOLFSSL_SP_SMALL_STACK
  6331. if (err == MP_OKAY) {
  6332. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 4, NULL, DYNAMIC_TYPE_DH);
  6333. if (b == NULL)
  6334. err = MEMORY_E;
  6335. }
  6336. #endif
  6337. if (err == MP_OKAY) {
  6338. e = b + 18 * 2;
  6339. m = e + 18;
  6340. r = b;
  6341. sp_2048_from_mp(b, 18, base);
  6342. sp_2048_from_mp(e, 18, exp);
  6343. sp_2048_from_mp(m, 18, mod);
  6344. err = sp_2048_mod_exp_18(r, b, e, expBits, m, 0);
  6345. }
  6346. if (err == MP_OKAY) {
  6347. XMEMSET(r + 18, 0, sizeof(*r) * 18U);
  6348. err = sp_2048_to_mp(r, res);
  6349. }
  6350. #ifdef WOLFSSL_SP_SMALL_STACK
  6351. if (b != NULL)
  6352. #endif
  6353. {
  6354. /* only "e" is sensitive and needs zeroized */
  6355. if (e != NULL)
  6356. ForceZero(e, sizeof(sp_digit) * 36U);
  6357. #ifdef WOLFSSL_SP_SMALL_STACK
  6358. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  6359. #endif
  6360. }
  6361. return err;
  6362. #endif
  6363. }
  6364. #endif /* WOLFSSL_HAVE_SP_DH | (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) */
  6365. #endif /* WOLFSSL_SP_SMALL */
  6366. #endif /* !WOLFSSL_SP_NO_2048 */
  6367. #ifndef WOLFSSL_SP_NO_3072
  6368. #ifdef WOLFSSL_SP_SMALL
  6369. /* Read big endian unsigned byte array into r.
  6370. *
  6371. * r A single precision integer.
  6372. * size Maximum number of bytes to convert
  6373. * a Byte array.
  6374. * n Number of bytes in array to read.
  6375. */
  6376. static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n)
  6377. {
  6378. int i;
  6379. int j = 0;
  6380. word32 s = 0;
  6381. r[0] = 0;
  6382. for (i = n-1; i >= 0; i--) {
  6383. r[j] |= (((sp_digit)a[i]) << s);
  6384. if (s >= 52U) {
  6385. r[j] &= 0xfffffffffffffffL;
  6386. s = 60U - s;
  6387. if (j + 1 >= size) {
  6388. break;
  6389. }
  6390. r[++j] = (sp_digit)a[i] >> s;
  6391. s = 8U - s;
  6392. }
  6393. else {
  6394. s += 8U;
  6395. }
  6396. }
  6397. for (j++; j < size; j++) {
  6398. r[j] = 0;
  6399. }
  6400. }
  6401. /* Convert an mp_int to an array of sp_digit.
  6402. *
  6403. * r A single precision integer.
  6404. * size Maximum number of bytes to convert
  6405. * a A multi-precision integer.
  6406. */
  6407. static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a)
  6408. {
  6409. #if DIGIT_BIT == 60
  6410. int i;
  6411. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  6412. int o = 0;
  6413. for (i = 0; i < size; i++) {
  6414. sp_digit mask = (sp_digit)0 - (j >> 59);
  6415. r[i] = a->dp[o] & mask;
  6416. j++;
  6417. o += (int)(j >> 59);
  6418. }
  6419. #elif DIGIT_BIT > 60
  6420. unsigned int i;
  6421. int j = 0;
  6422. word32 s = 0;
  6423. r[0] = 0;
  6424. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  6425. r[j] |= ((sp_digit)a->dp[i] << s);
  6426. r[j] &= 0xfffffffffffffffL;
  6427. s = 60U - s;
  6428. if (j + 1 >= size) {
  6429. break;
  6430. }
  6431. /* lint allow cast of mismatch word32 and mp_digit */
  6432. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  6433. while ((s + 60U) <= (word32)DIGIT_BIT) {
  6434. s += 60U;
  6435. r[j] &= 0xfffffffffffffffL;
  6436. if (j + 1 >= size) {
  6437. break;
  6438. }
  6439. if (s < (word32)DIGIT_BIT) {
  6440. /* lint allow cast of mismatch word32 and mp_digit */
  6441. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  6442. }
  6443. else {
  6444. r[++j] = (sp_digit)0;
  6445. }
  6446. }
  6447. s = (word32)DIGIT_BIT - s;
  6448. }
  6449. for (j++; j < size; j++) {
  6450. r[j] = 0;
  6451. }
  6452. #else
  6453. unsigned int i;
  6454. int j = 0;
  6455. int s = 0;
  6456. r[0] = 0;
  6457. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  6458. r[j] |= ((sp_digit)a->dp[i]) << s;
  6459. if (s + DIGIT_BIT >= 60) {
  6460. r[j] &= 0xfffffffffffffffL;
  6461. if (j + 1 >= size) {
  6462. break;
  6463. }
  6464. s = 60 - s;
  6465. if (s == DIGIT_BIT) {
  6466. r[++j] = 0;
  6467. s = 0;
  6468. }
  6469. else {
  6470. r[++j] = a->dp[i] >> s;
  6471. s = DIGIT_BIT - s;
  6472. }
  6473. }
  6474. else {
  6475. s += DIGIT_BIT;
  6476. }
  6477. }
  6478. for (j++; j < size; j++) {
  6479. r[j] = 0;
  6480. }
  6481. #endif
  6482. }
  6483. /* Write r as big endian to byte array.
  6484. * Fixed length number of bytes written: 384
  6485. *
  6486. * r A single precision integer.
  6487. * a Byte array.
  6488. */
  6489. static void sp_3072_to_bin_52(sp_digit* r, byte* a)
  6490. {
  6491. int i;
  6492. int j;
  6493. int s = 0;
  6494. int b;
  6495. for (i=0; i<51; i++) {
  6496. r[i+1] += r[i] >> 60;
  6497. r[i] &= 0xfffffffffffffffL;
  6498. }
  6499. j = 3079 / 8 - 1;
  6500. a[j] = 0;
  6501. for (i=0; i<52 && j>=0; i++) {
  6502. b = 0;
  6503. /* lint allow cast of mismatch sp_digit and int */
  6504. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  6505. b += 8 - s;
  6506. if (j < 0) {
  6507. break;
  6508. }
  6509. while (b < 60) {
  6510. a[j--] = (byte)(r[i] >> b);
  6511. b += 8;
  6512. if (j < 0) {
  6513. break;
  6514. }
  6515. }
  6516. s = 8 - (b - 60);
  6517. if (j >= 0) {
  6518. a[j] = 0;
  6519. }
  6520. if (s != 0) {
  6521. j++;
  6522. }
  6523. }
  6524. }
  6525. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  6526. /* Normalize the values in each word to 60 bits.
  6527. *
  6528. * a Array of sp_digit to normalize.
  6529. */
  6530. static void sp_3072_norm_26(sp_digit* a)
  6531. {
  6532. int i;
  6533. for (i = 0; i < 25; i++) {
  6534. a[i+1] += a[i] >> 60;
  6535. a[i] &= 0xfffffffffffffffL;
  6536. }
  6537. }
  6538. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  6539. /* Normalize the values in each word to 60 bits.
  6540. *
  6541. * a Array of sp_digit to normalize.
  6542. */
  6543. static void sp_3072_norm_52(sp_digit* a)
  6544. {
  6545. int i;
  6546. for (i = 0; i < 51; i++) {
  6547. a[i+1] += a[i] >> 60;
  6548. a[i] &= 0xfffffffffffffffL;
  6549. }
  6550. }
  6551. /* Multiply a and b into r. (r = a * b)
  6552. *
  6553. * r A single precision integer.
  6554. * a A single precision integer.
  6555. * b A single precision integer.
  6556. */
  6557. SP_NOINLINE static void sp_3072_mul_52(sp_digit* r, const sp_digit* a,
  6558. const sp_digit* b)
  6559. {
  6560. int i;
  6561. int imax;
  6562. int k;
  6563. sp_uint128 c;
  6564. sp_uint128 lo;
  6565. c = ((sp_uint128)a[51]) * b[51];
  6566. r[103] = (sp_digit)(c >> 60);
  6567. c &= 0xfffffffffffffffL;
  6568. for (k = 101; k >= 0; k--) {
  6569. if (k >= 52) {
  6570. i = k - 51;
  6571. imax = 51;
  6572. }
  6573. else {
  6574. i = 0;
  6575. imax = k;
  6576. }
  6577. lo = 0;
  6578. for (; i <= imax; i++) {
  6579. lo += ((sp_uint128)a[i]) * b[k - i];
  6580. }
  6581. c += lo >> 60;
  6582. r[k + 2] += (sp_digit)(c >> 60);
  6583. r[k + 1] = (sp_digit)(c & 0xfffffffffffffffL);
  6584. c = lo & 0xfffffffffffffffL;
  6585. }
  6586. r[0] = (sp_digit)c;
  6587. }
  6588. /* Square a and put result in r. (r = a * a)
  6589. *
  6590. * r A single precision integer.
  6591. * a A single precision integer.
  6592. */
  6593. SP_NOINLINE static void sp_3072_sqr_52(sp_digit* r, const sp_digit* a)
  6594. {
  6595. int i;
  6596. int imax;
  6597. int k;
  6598. sp_uint128 c;
  6599. sp_uint128 t;
  6600. c = ((sp_uint128)a[51]) * a[51];
  6601. r[103] = (sp_digit)(c >> 60);
  6602. c = (c & 0xfffffffffffffffL) << 60;
  6603. for (k = 101; k >= 0; k--) {
  6604. i = (k + 1) / 2;
  6605. if ((k & 1) == 0) {
  6606. c += ((sp_uint128)a[i]) * a[i];
  6607. i++;
  6608. }
  6609. if (k < 51) {
  6610. imax = k;
  6611. }
  6612. else {
  6613. imax = 51;
  6614. }
  6615. t = 0;
  6616. for (; i <= imax; i++) {
  6617. t += ((sp_uint128)a[i]) * a[k - i];
  6618. }
  6619. c += t * 2;
  6620. r[k + 2] += (sp_digit) (c >> 120);
  6621. r[k + 1] = (sp_digit)((c >> 60) & 0xfffffffffffffffL);
  6622. c = (c & 0xfffffffffffffffL) << 60;
  6623. }
  6624. r[0] = (sp_digit)(c >> 60);
  6625. }
  6626. /* Calculate the bottom digit of -1/a mod 2^n.
  6627. *
  6628. * a A single precision number.
  6629. * rho Bottom word of inverse.
  6630. */
  6631. static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho)
  6632. {
  6633. sp_digit x;
  6634. sp_digit b;
  6635. b = a[0];
  6636. x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
  6637. x *= 2 - b * x; /* here x*a==1 mod 2**8 */
  6638. x *= 2 - b * x; /* here x*a==1 mod 2**16 */
  6639. x *= 2 - b * x; /* here x*a==1 mod 2**32 */
  6640. x *= 2 - b * x; /* here x*a==1 mod 2**64 */
  6641. x &= 0xfffffffffffffffL;
  6642. /* rho = -1/m mod b */
  6643. *rho = ((sp_digit)1 << 60) - x;
  6644. }
  6645. /* Multiply a by scalar b into r. (r = a * b)
  6646. *
  6647. * r A single precision integer.
  6648. * a A single precision integer.
  6649. * b A scalar.
  6650. */
  6651. SP_NOINLINE static void sp_3072_mul_d_52(sp_digit* r, const sp_digit* a,
  6652. sp_digit b)
  6653. {
  6654. sp_int128 tb = b;
  6655. sp_int128 t = 0;
  6656. int i;
  6657. for (i = 0; i < 52; i++) {
  6658. t += tb * a[i];
  6659. r[i] = (sp_digit)(t & 0xfffffffffffffffL);
  6660. t >>= 60;
  6661. }
  6662. r[52] = (sp_digit)t;
  6663. }
  6664. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  6665. /* Sub b from a into r. (r = a - b)
  6666. *
  6667. * r A single precision integer.
  6668. * a A single precision integer.
  6669. * b A single precision integer.
  6670. */
  6671. SP_NOINLINE static int sp_3072_sub_26(sp_digit* r, const sp_digit* a,
  6672. const sp_digit* b)
  6673. {
  6674. int i;
  6675. for (i = 0; i < 26; i++) {
  6676. r[i] = a[i] - b[i];
  6677. }
  6678. return 0;
  6679. }
  6680. /* r = 2^n mod m where n is the number of bits to reduce by.
  6681. * Given m must be 3072 bits, just need to subtract.
  6682. *
  6683. * r A single precision number.
  6684. * m A single precision number.
  6685. */
  6686. static void sp_3072_mont_norm_26(sp_digit* r, const sp_digit* m)
  6687. {
  6688. /* Set r = 2^n - 1. */
  6689. int i;
  6690. for (i=0; i<25; i++) {
  6691. r[i] = 0xfffffffffffffffL;
  6692. }
  6693. r[25] = 0xfffffffffL;
  6694. /* r = (2^n - 1) mod n */
  6695. (void)sp_3072_sub_26(r, r, m);
  6696. /* Add one so r = 2^n mod m */
  6697. r[0] += 1;
  6698. }
  6699. /* Compare a with b in constant time.
  6700. *
  6701. * a A single precision integer.
  6702. * b A single precision integer.
  6703. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  6704. * respectively.
  6705. */
  6706. static sp_digit sp_3072_cmp_26(const sp_digit* a, const sp_digit* b)
  6707. {
  6708. sp_digit r = 0;
  6709. int i;
  6710. for (i=25; i>=0; i--) {
  6711. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 59);
  6712. }
  6713. return r;
  6714. }
  6715. /* Conditionally subtract b from a using the mask m.
  6716. * m is -1 to subtract and 0 when not.
  6717. *
  6718. * r A single precision number representing condition subtract result.
  6719. * a A single precision number to subtract from.
  6720. * b A single precision number to subtract.
  6721. * m Mask value to apply.
  6722. */
  6723. static void sp_3072_cond_sub_26(sp_digit* r, const sp_digit* a,
  6724. const sp_digit* b, const sp_digit m)
  6725. {
  6726. int i;
  6727. for (i = 0; i < 26; i++) {
  6728. r[i] = a[i] - (b[i] & m);
  6729. }
  6730. }
  6731. /* Mul a by scalar b and add into r. (r += a * b)
  6732. *
  6733. * r A single precision integer.
  6734. * a A single precision integer.
  6735. * b A scalar.
  6736. */
  6737. SP_NOINLINE static void sp_3072_mul_add_26(sp_digit* r, const sp_digit* a,
  6738. const sp_digit b)
  6739. {
  6740. sp_int128 tb = b;
  6741. sp_int128 t[4];
  6742. int i;
  6743. t[0] = 0;
  6744. for (i = 0; i < 24; i += 4) {
  6745. t[0] += (tb * a[i+0]) + r[i+0];
  6746. t[1] = (tb * a[i+1]) + r[i+1];
  6747. t[2] = (tb * a[i+2]) + r[i+2];
  6748. t[3] = (tb * a[i+3]) + r[i+3];
  6749. r[i+0] = t[0] & 0xfffffffffffffffL;
  6750. t[1] += t[0] >> 60;
  6751. r[i+1] = t[1] & 0xfffffffffffffffL;
  6752. t[2] += t[1] >> 60;
  6753. r[i+2] = t[2] & 0xfffffffffffffffL;
  6754. t[3] += t[2] >> 60;
  6755. r[i+3] = t[3] & 0xfffffffffffffffL;
  6756. t[0] = t[3] >> 60;
  6757. }
  6758. t[0] += (tb * a[24]) + r[24];
  6759. t[1] = (tb * a[25]) + r[25];
  6760. r[24] = t[0] & 0xfffffffffffffffL;
  6761. t[1] += t[0] >> 60;
  6762. r[25] = t[1] & 0xfffffffffffffffL;
  6763. r[26] += (sp_digit)(t[1] >> 60);
  6764. }
  6765. /* Shift the result in the high 1536 bits down to the bottom.
  6766. *
  6767. * r A single precision number.
  6768. * a A single precision number.
  6769. */
  6770. static void sp_3072_mont_shift_26(sp_digit* r, const sp_digit* a)
  6771. {
  6772. int i;
  6773. sp_int128 n = a[25] >> 36;
  6774. n += ((sp_int128)a[26]) << 24;
  6775. for (i = 0; i < 25; i++) {
  6776. r[i] = n & 0xfffffffffffffffL;
  6777. n >>= 60;
  6778. n += ((sp_int128)a[27 + i]) << 24;
  6779. }
  6780. r[25] = (sp_digit)n;
  6781. XMEMSET(&r[26], 0, sizeof(*r) * 26U);
  6782. }
  6783. /* Reduce the number back to 3072 bits using Montgomery reduction.
  6784. *
  6785. * a A single precision number to reduce in place.
  6786. * m The single precision number representing the modulus.
  6787. * mp The digit representing the negative inverse of m mod 2^n.
  6788. */
  6789. static void sp_3072_mont_reduce_26(sp_digit* a, const sp_digit* m, sp_digit mp)
  6790. {
  6791. int i;
  6792. sp_digit mu;
  6793. sp_digit over;
  6794. sp_3072_norm_26(a + 26);
  6795. for (i=0; i<25; i++) {
  6796. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xfffffffffffffffL;
  6797. sp_3072_mul_add_26(a+i, m, mu);
  6798. a[i+1] += a[i] >> 60;
  6799. }
  6800. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xfffffffffL;
  6801. sp_3072_mul_add_26(a+i, m, mu);
  6802. a[i+1] += a[i] >> 60;
  6803. a[i] &= 0xfffffffffffffffL;
  6804. sp_3072_mont_shift_26(a, a);
  6805. over = a[25] - m[25];
  6806. sp_3072_cond_sub_26(a, a, m, ~((over - 1) >> 63));
  6807. sp_3072_norm_26(a);
  6808. }
  6809. /* Multiply a and b into r. (r = a * b)
  6810. *
  6811. * r A single precision integer.
  6812. * a A single precision integer.
  6813. * b A single precision integer.
  6814. */
  6815. SP_NOINLINE static void sp_3072_mul_26(sp_digit* r, const sp_digit* a,
  6816. const sp_digit* b)
  6817. {
  6818. int i;
  6819. int imax;
  6820. int k;
  6821. sp_uint128 c;
  6822. sp_uint128 lo;
  6823. c = ((sp_uint128)a[25]) * b[25];
  6824. r[51] = (sp_digit)(c >> 60);
  6825. c &= 0xfffffffffffffffL;
  6826. for (k = 49; k >= 0; k--) {
  6827. if (k >= 26) {
  6828. i = k - 25;
  6829. imax = 25;
  6830. }
  6831. else {
  6832. i = 0;
  6833. imax = k;
  6834. }
  6835. lo = 0;
  6836. for (; i <= imax; i++) {
  6837. lo += ((sp_uint128)a[i]) * b[k - i];
  6838. }
  6839. c += lo >> 60;
  6840. r[k + 2] += (sp_digit)(c >> 60);
  6841. r[k + 1] = (sp_digit)(c & 0xfffffffffffffffL);
  6842. c = lo & 0xfffffffffffffffL;
  6843. }
  6844. r[0] = (sp_digit)c;
  6845. }
  6846. /* Multiply two Montgomery form numbers mod the modulus (prime).
  6847. * (r = a * b mod m)
  6848. *
  6849. * r Result of multiplication.
  6850. * a First number to multiply in Montgomery form.
  6851. * b Second number to multiply in Montgomery form.
  6852. * m Modulus (prime).
  6853. * mp Montgomery multiplier.
  6854. */
  6855. SP_NOINLINE static void sp_3072_mont_mul_26(sp_digit* r, const sp_digit* a,
  6856. const sp_digit* b, const sp_digit* m, sp_digit mp)
  6857. {
  6858. sp_3072_mul_26(r, a, b);
  6859. sp_3072_mont_reduce_26(r, m, mp);
  6860. }
  6861. /* Square a and put result in r. (r = a * a)
  6862. *
  6863. * r A single precision integer.
  6864. * a A single precision integer.
  6865. */
  6866. SP_NOINLINE static void sp_3072_sqr_26(sp_digit* r, const sp_digit* a)
  6867. {
  6868. int i;
  6869. int imax;
  6870. int k;
  6871. sp_uint128 c;
  6872. sp_uint128 t;
  6873. c = ((sp_uint128)a[25]) * a[25];
  6874. r[51] = (sp_digit)(c >> 60);
  6875. c = (c & 0xfffffffffffffffL) << 60;
  6876. for (k = 49; k >= 0; k--) {
  6877. i = (k + 1) / 2;
  6878. if ((k & 1) == 0) {
  6879. c += ((sp_uint128)a[i]) * a[i];
  6880. i++;
  6881. }
  6882. if (k < 25) {
  6883. imax = k;
  6884. }
  6885. else {
  6886. imax = 25;
  6887. }
  6888. t = 0;
  6889. for (; i <= imax; i++) {
  6890. t += ((sp_uint128)a[i]) * a[k - i];
  6891. }
  6892. c += t * 2;
  6893. r[k + 2] += (sp_digit) (c >> 120);
  6894. r[k + 1] = (sp_digit)((c >> 60) & 0xfffffffffffffffL);
  6895. c = (c & 0xfffffffffffffffL) << 60;
  6896. }
  6897. r[0] = (sp_digit)(c >> 60);
  6898. }
  6899. /* Square the Montgomery form number. (r = a * a mod m)
  6900. *
  6901. * r Result of squaring.
  6902. * a Number to square in Montgomery form.
  6903. * m Modulus (prime).
  6904. * mp Montgomery multiplier.
  6905. */
  6906. SP_NOINLINE static void sp_3072_mont_sqr_26(sp_digit* r, const sp_digit* a,
  6907. const sp_digit* m, sp_digit mp)
  6908. {
  6909. sp_3072_sqr_26(r, a);
  6910. sp_3072_mont_reduce_26(r, m, mp);
  6911. }
  6912. /* Multiply a by scalar b into r. (r = a * b)
  6913. *
  6914. * r A single precision integer.
  6915. * a A single precision integer.
  6916. * b A scalar.
  6917. */
  6918. SP_NOINLINE static void sp_3072_mul_d_26(sp_digit* r, const sp_digit* a,
  6919. sp_digit b)
  6920. {
  6921. sp_int128 tb = b;
  6922. sp_int128 t = 0;
  6923. int i;
  6924. for (i = 0; i < 26; i++) {
  6925. t += tb * a[i];
  6926. r[i] = (sp_digit)(t & 0xfffffffffffffffL);
  6927. t >>= 60;
  6928. }
  6929. r[26] = (sp_digit)t;
  6930. }
  6931. #ifdef WOLFSSL_SP_SMALL
  6932. /* Conditionally add a and b using the mask m.
  6933. * m is -1 to add and 0 when not.
  6934. *
  6935. * r A single precision number representing conditional add result.
  6936. * a A single precision number to add with.
  6937. * b A single precision number to add.
  6938. * m Mask value to apply.
  6939. */
  6940. static void sp_3072_cond_add_26(sp_digit* r, const sp_digit* a,
  6941. const sp_digit* b, const sp_digit m)
  6942. {
  6943. int i;
  6944. for (i = 0; i < 26; i++) {
  6945. r[i] = a[i] + (b[i] & m);
  6946. }
  6947. }
  6948. #endif /* WOLFSSL_SP_SMALL */
  6949. /* Add b to a into r. (r = a + b)
  6950. *
  6951. * r A single precision integer.
  6952. * a A single precision integer.
  6953. * b A single precision integer.
  6954. */
  6955. SP_NOINLINE static int sp_3072_add_26(sp_digit* r, const sp_digit* a,
  6956. const sp_digit* b)
  6957. {
  6958. int i;
  6959. for (i = 0; i < 26; i++) {
  6960. r[i] = a[i] + b[i];
  6961. }
  6962. return 0;
  6963. }
  6964. SP_NOINLINE static void sp_3072_rshift_26(sp_digit* r, const sp_digit* a,
  6965. byte n)
  6966. {
  6967. int i;
  6968. for (i=0; i<25; i++) {
  6969. r[i] = ((a[i] >> n) | (a[i + 1] << (60 - n))) & 0xfffffffffffffffL;
  6970. }
  6971. r[25] = a[25] >> n;
  6972. }
  6973. static WC_INLINE sp_digit sp_3072_div_word_26(sp_digit d1, sp_digit d0,
  6974. sp_digit div)
  6975. {
  6976. #ifdef SP_USE_DIVTI3
  6977. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  6978. return d / div;
  6979. #elif defined(__x86_64__) || defined(__i386__)
  6980. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  6981. sp_uint64 lo = (sp_uint64)d;
  6982. sp_digit hi = (sp_digit)(d >> 64);
  6983. __asm__ __volatile__ (
  6984. "idiv %2"
  6985. : "+a" (lo)
  6986. : "d" (hi), "r" (div)
  6987. : "cc"
  6988. );
  6989. return (sp_digit)lo;
  6990. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  6991. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  6992. sp_digit dv = (div >> 1) + 1;
  6993. sp_digit t1 = (sp_digit)(d >> 60);
  6994. sp_digit t0 = (sp_digit)(d & 0xfffffffffffffffL);
  6995. sp_digit t2;
  6996. sp_digit sign;
  6997. sp_digit r;
  6998. int i;
  6999. sp_int128 m;
  7000. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  7001. t1 -= dv & (0 - r);
  7002. for (i = 58; i >= 1; i--) {
  7003. t1 += t1 + (((sp_uint64)t0 >> 59) & 1);
  7004. t0 <<= 1;
  7005. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  7006. r += r + t2;
  7007. t1 -= dv & (0 - t2);
  7008. t1 += t2;
  7009. }
  7010. r += r + 1;
  7011. m = d - ((sp_int128)r * div);
  7012. r += (sp_digit)(m >> 60);
  7013. m = d - ((sp_int128)r * div);
  7014. r += (sp_digit)(m >> 120) - (sp_digit)(d >> 120);
  7015. m = d - ((sp_int128)r * div);
  7016. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  7017. m *= sign;
  7018. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  7019. r += sign * t2;
  7020. m = d - ((sp_int128)r * div);
  7021. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  7022. m *= sign;
  7023. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  7024. r += sign * t2;
  7025. return r;
  7026. #else
  7027. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  7028. sp_digit r = 0;
  7029. sp_digit t;
  7030. sp_digit dv = (div >> 29) + 1;
  7031. t = (sp_digit)(d >> 58);
  7032. t = (t / dv) << 29;
  7033. r += t;
  7034. d -= (sp_int128)t * div;
  7035. t = (sp_digit)(d >> 27);
  7036. t = t / (dv << 2);
  7037. r += t;
  7038. d -= (sp_int128)t * div;
  7039. t = (sp_digit)d;
  7040. t = t / div;
  7041. r += t;
  7042. d -= (sp_int128)t * div;
  7043. return r;
  7044. #endif
  7045. }
  7046. static WC_INLINE sp_digit sp_3072_word_div_word_26(sp_digit d, sp_digit div)
  7047. {
  7048. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  7049. defined(SP_DIV_WORD_USE_DIV)
  7050. return d / div;
  7051. #else
  7052. return (sp_digit)((sp_uint64)(div - d) >> 63);
  7053. #endif
  7054. }
  7055. /* Divide d in a and put remainder into r (m*d + r = a)
  7056. * m is not calculated as it is not needed at this time.
  7057. *
  7058. * Full implementation.
  7059. *
  7060. * a Number to be divided.
  7061. * d Number to divide with.
  7062. * m Multiplier result.
  7063. * r Remainder from the division.
  7064. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  7065. */
  7066. static int sp_3072_div_26(const sp_digit* a, const sp_digit* d,
  7067. const sp_digit* m, sp_digit* r)
  7068. {
  7069. int i;
  7070. #ifndef WOLFSSL_SP_DIV_64
  7071. #endif
  7072. sp_digit dv;
  7073. sp_digit r1;
  7074. #ifdef WOLFSSL_SP_SMALL_STACK
  7075. sp_digit* t1 = NULL;
  7076. #else
  7077. sp_digit t1[4 * 26 + 3];
  7078. #endif
  7079. sp_digit* t2 = NULL;
  7080. sp_digit* sd = NULL;
  7081. int err = MP_OKAY;
  7082. (void)m;
  7083. #ifdef WOLFSSL_SP_SMALL_STACK
  7084. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 26 + 3), NULL,
  7085. DYNAMIC_TYPE_TMP_BUFFER);
  7086. if (t1 == NULL)
  7087. err = MEMORY_E;
  7088. #endif
  7089. (void)m;
  7090. if (err == MP_OKAY) {
  7091. t2 = t1 + 52 + 1;
  7092. sd = t2 + 26 + 1;
  7093. sp_3072_mul_d_26(sd, d, (sp_digit)1 << 24);
  7094. sp_3072_mul_d_52(t1, a, (sp_digit)1 << 24);
  7095. dv = sd[25];
  7096. t1[26 + 26] += t1[26 + 26 - 1] >> 60;
  7097. t1[26 + 26 - 1] &= 0xfffffffffffffffL;
  7098. for (i=26; i>=0; i--) {
  7099. r1 = sp_3072_div_word_26(t1[26 + i], t1[26 + i - 1], dv);
  7100. sp_3072_mul_d_26(t2, sd, r1);
  7101. (void)sp_3072_sub_26(&t1[i], &t1[i], t2);
  7102. sp_3072_norm_26(&t1[i]);
  7103. t1[26 + i] -= t2[26];
  7104. t1[26 + i] += t1[26 + i - 1] >> 60;
  7105. t1[26 + i - 1] &= 0xfffffffffffffffL;
  7106. r1 = sp_3072_div_word_26(-t1[26 + i], -t1[26 + i - 1], dv);
  7107. r1 -= t1[26 + i];
  7108. sp_3072_mul_d_26(t2, sd, r1);
  7109. (void)sp_3072_add_26(&t1[i], &t1[i], t2);
  7110. t1[26 + i] += t1[26 + i - 1] >> 60;
  7111. t1[26 + i - 1] &= 0xfffffffffffffffL;
  7112. }
  7113. t1[26 - 1] += t1[26 - 2] >> 60;
  7114. t1[26 - 2] &= 0xfffffffffffffffL;
  7115. r1 = sp_3072_word_div_word_26(t1[26 - 1], dv);
  7116. sp_3072_mul_d_26(t2, sd, r1);
  7117. sp_3072_sub_26(t1, t1, t2);
  7118. XMEMCPY(r, t1, sizeof(*r) * 52U);
  7119. for (i=0; i<25; i++) {
  7120. r[i+1] += r[i] >> 60;
  7121. r[i] &= 0xfffffffffffffffL;
  7122. }
  7123. sp_3072_cond_add_26(r, r, sd, r[25] >> 63);
  7124. sp_3072_norm_26(r);
  7125. sp_3072_rshift_26(r, r, 24);
  7126. }
  7127. #ifdef WOLFSSL_SP_SMALL_STACK
  7128. if (t1 != NULL)
  7129. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7130. #endif
  7131. return err;
  7132. }
  7133. /* Reduce a modulo m into r. (r = a mod m)
  7134. *
  7135. * r A single precision number that is the reduced result.
  7136. * a A single precision number that is to be reduced.
  7137. * m A single precision number that is the modulus to reduce with.
  7138. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  7139. */
  7140. static int sp_3072_mod_26(sp_digit* r, const sp_digit* a, const sp_digit* m)
  7141. {
  7142. return sp_3072_div_26(a, m, NULL, r);
  7143. }
  7144. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  7145. *
  7146. * r A single precision number that is the result of the operation.
  7147. * a A single precision number being exponentiated.
  7148. * e A single precision number that is the exponent.
  7149. * bits The number of bits in the exponent.
  7150. * m A single precision number that is the modulus.
  7151. * returns 0 on success.
  7152. * returns MEMORY_E on dynamic memory allocation failure.
  7153. * returns MP_VAL when base is even or exponent is 0.
  7154. */
  7155. static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e,
  7156. int bits, const sp_digit* m, int reduceA)
  7157. {
  7158. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  7159. #ifdef WOLFSSL_SP_SMALL_STACK
  7160. sp_digit* td = NULL;
  7161. #else
  7162. sp_digit td[3 * 52];
  7163. #endif
  7164. sp_digit* t[3] = {0, 0, 0};
  7165. sp_digit* norm = NULL;
  7166. sp_digit mp = 1;
  7167. sp_digit n;
  7168. int i;
  7169. int c;
  7170. byte y;
  7171. int err = MP_OKAY;
  7172. if (bits == 0) {
  7173. err = MP_VAL;
  7174. }
  7175. #ifdef WOLFSSL_SP_SMALL_STACK
  7176. if (err == MP_OKAY) {
  7177. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 26 * 2, NULL,
  7178. DYNAMIC_TYPE_TMP_BUFFER);
  7179. if (td == NULL)
  7180. err = MEMORY_E;
  7181. }
  7182. #endif
  7183. if (err == MP_OKAY) {
  7184. norm = td;
  7185. for (i=0; i<3; i++) {
  7186. t[i] = td + (i * 26 * 2);
  7187. XMEMSET(t[i], 0, sizeof(sp_digit) * 26U * 2U);
  7188. }
  7189. sp_3072_mont_setup(m, &mp);
  7190. sp_3072_mont_norm_26(norm, m);
  7191. if (reduceA != 0) {
  7192. err = sp_3072_mod_26(t[1], a, m);
  7193. }
  7194. else {
  7195. XMEMCPY(t[1], a, sizeof(sp_digit) * 26U);
  7196. }
  7197. }
  7198. if (err == MP_OKAY) {
  7199. sp_3072_mul_26(t[1], t[1], norm);
  7200. err = sp_3072_mod_26(t[1], t[1], m);
  7201. }
  7202. if (err == MP_OKAY) {
  7203. i = bits / 60;
  7204. c = bits % 60;
  7205. n = e[i--] << (60 - c);
  7206. for (; ; c--) {
  7207. if (c == 0) {
  7208. if (i == -1) {
  7209. break;
  7210. }
  7211. n = e[i--];
  7212. c = 60;
  7213. }
  7214. y = (int)((n >> 59) & 1);
  7215. n <<= 1;
  7216. sp_3072_mont_mul_26(t[y^1], t[0], t[1], m, mp);
  7217. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  7218. ((size_t)t[1] & addr_mask[y])),
  7219. sizeof(*t[2]) * 26 * 2);
  7220. sp_3072_mont_sqr_26(t[2], t[2], m, mp);
  7221. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  7222. ((size_t)t[1] & addr_mask[y])), t[2],
  7223. sizeof(*t[2]) * 26 * 2);
  7224. }
  7225. sp_3072_mont_reduce_26(t[0], m, mp);
  7226. n = sp_3072_cmp_26(t[0], m);
  7227. sp_3072_cond_sub_26(t[0], t[0], m, ~(n >> 63));
  7228. XMEMCPY(r, t[0], sizeof(*r) * 26 * 2);
  7229. }
  7230. #ifdef WOLFSSL_SP_SMALL_STACK
  7231. if (td != NULL)
  7232. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7233. #endif
  7234. return err;
  7235. #elif !defined(WC_NO_CACHE_RESISTANT)
  7236. #ifdef WOLFSSL_SP_SMALL_STACK
  7237. sp_digit* td = NULL;
  7238. #else
  7239. sp_digit td[3 * 52];
  7240. #endif
  7241. sp_digit* t[3] = {0, 0, 0};
  7242. sp_digit* norm = NULL;
  7243. sp_digit mp = 1;
  7244. sp_digit n;
  7245. int i;
  7246. int c;
  7247. byte y;
  7248. int err = MP_OKAY;
  7249. if (bits == 0) {
  7250. err = MP_VAL;
  7251. }
  7252. #ifdef WOLFSSL_SP_SMALL_STACK
  7253. if (err == MP_OKAY) {
  7254. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 26 * 2, NULL,
  7255. DYNAMIC_TYPE_TMP_BUFFER);
  7256. if (td == NULL)
  7257. err = MEMORY_E;
  7258. }
  7259. #endif
  7260. if (err == MP_OKAY) {
  7261. norm = td;
  7262. for (i=0; i<3; i++) {
  7263. t[i] = td + (i * 26 * 2);
  7264. }
  7265. sp_3072_mont_setup(m, &mp);
  7266. sp_3072_mont_norm_26(norm, m);
  7267. if (reduceA != 0) {
  7268. err = sp_3072_mod_26(t[1], a, m);
  7269. if (err == MP_OKAY) {
  7270. sp_3072_mul_26(t[1], t[1], norm);
  7271. err = sp_3072_mod_26(t[1], t[1], m);
  7272. }
  7273. }
  7274. else {
  7275. sp_3072_mul_26(t[1], a, norm);
  7276. err = sp_3072_mod_26(t[1], t[1], m);
  7277. }
  7278. }
  7279. if (err == MP_OKAY) {
  7280. i = bits / 60;
  7281. c = bits % 60;
  7282. n = e[i--] << (60 - c);
  7283. for (; ; c--) {
  7284. if (c == 0) {
  7285. if (i == -1) {
  7286. break;
  7287. }
  7288. n = e[i--];
  7289. c = 60;
  7290. }
  7291. y = (int)((n >> 59) & 1);
  7292. n <<= 1;
  7293. sp_3072_mont_mul_26(t[y^1], t[0], t[1], m, mp);
  7294. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  7295. ((size_t)t[1] & addr_mask[y])),
  7296. sizeof(*t[2]) * 26 * 2);
  7297. sp_3072_mont_sqr_26(t[2], t[2], m, mp);
  7298. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  7299. ((size_t)t[1] & addr_mask[y])), t[2],
  7300. sizeof(*t[2]) * 26 * 2);
  7301. }
  7302. sp_3072_mont_reduce_26(t[0], m, mp);
  7303. n = sp_3072_cmp_26(t[0], m);
  7304. sp_3072_cond_sub_26(t[0], t[0], m, ~(n >> 63));
  7305. XMEMCPY(r, t[0], sizeof(*r) * 26 * 2);
  7306. }
  7307. #ifdef WOLFSSL_SP_SMALL_STACK
  7308. if (td != NULL)
  7309. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7310. #endif
  7311. return err;
  7312. #else
  7313. #ifdef WOLFSSL_SP_SMALL_STACK
  7314. sp_digit* td = NULL;
  7315. #else
  7316. sp_digit td[(32 * 52) + 52];
  7317. #endif
  7318. sp_digit* t[32];
  7319. sp_digit* rt = NULL;
  7320. sp_digit* norm = NULL;
  7321. sp_digit mp = 1;
  7322. sp_digit n;
  7323. int i;
  7324. int c;
  7325. byte y;
  7326. int err = MP_OKAY;
  7327. if (bits == 0) {
  7328. err = MP_VAL;
  7329. }
  7330. #ifdef WOLFSSL_SP_SMALL_STACK
  7331. if (err == MP_OKAY) {
  7332. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 52) + 52), NULL,
  7333. DYNAMIC_TYPE_TMP_BUFFER);
  7334. if (td == NULL)
  7335. err = MEMORY_E;
  7336. }
  7337. #endif
  7338. if (err == MP_OKAY) {
  7339. norm = td;
  7340. for (i=0; i<32; i++)
  7341. t[i] = td + i * 52;
  7342. rt = td + 1664;
  7343. sp_3072_mont_setup(m, &mp);
  7344. sp_3072_mont_norm_26(norm, m);
  7345. if (reduceA != 0) {
  7346. err = sp_3072_mod_26(t[1], a, m);
  7347. if (err == MP_OKAY) {
  7348. sp_3072_mul_26(t[1], t[1], norm);
  7349. err = sp_3072_mod_26(t[1], t[1], m);
  7350. }
  7351. }
  7352. else {
  7353. sp_3072_mul_26(t[1], a, norm);
  7354. err = sp_3072_mod_26(t[1], t[1], m);
  7355. }
  7356. }
  7357. if (err == MP_OKAY) {
  7358. sp_3072_mont_sqr_26(t[ 2], t[ 1], m, mp);
  7359. sp_3072_mont_mul_26(t[ 3], t[ 2], t[ 1], m, mp);
  7360. sp_3072_mont_sqr_26(t[ 4], t[ 2], m, mp);
  7361. sp_3072_mont_mul_26(t[ 5], t[ 3], t[ 2], m, mp);
  7362. sp_3072_mont_sqr_26(t[ 6], t[ 3], m, mp);
  7363. sp_3072_mont_mul_26(t[ 7], t[ 4], t[ 3], m, mp);
  7364. sp_3072_mont_sqr_26(t[ 8], t[ 4], m, mp);
  7365. sp_3072_mont_mul_26(t[ 9], t[ 5], t[ 4], m, mp);
  7366. sp_3072_mont_sqr_26(t[10], t[ 5], m, mp);
  7367. sp_3072_mont_mul_26(t[11], t[ 6], t[ 5], m, mp);
  7368. sp_3072_mont_sqr_26(t[12], t[ 6], m, mp);
  7369. sp_3072_mont_mul_26(t[13], t[ 7], t[ 6], m, mp);
  7370. sp_3072_mont_sqr_26(t[14], t[ 7], m, mp);
  7371. sp_3072_mont_mul_26(t[15], t[ 8], t[ 7], m, mp);
  7372. sp_3072_mont_sqr_26(t[16], t[ 8], m, mp);
  7373. sp_3072_mont_mul_26(t[17], t[ 9], t[ 8], m, mp);
  7374. sp_3072_mont_sqr_26(t[18], t[ 9], m, mp);
  7375. sp_3072_mont_mul_26(t[19], t[10], t[ 9], m, mp);
  7376. sp_3072_mont_sqr_26(t[20], t[10], m, mp);
  7377. sp_3072_mont_mul_26(t[21], t[11], t[10], m, mp);
  7378. sp_3072_mont_sqr_26(t[22], t[11], m, mp);
  7379. sp_3072_mont_mul_26(t[23], t[12], t[11], m, mp);
  7380. sp_3072_mont_sqr_26(t[24], t[12], m, mp);
  7381. sp_3072_mont_mul_26(t[25], t[13], t[12], m, mp);
  7382. sp_3072_mont_sqr_26(t[26], t[13], m, mp);
  7383. sp_3072_mont_mul_26(t[27], t[14], t[13], m, mp);
  7384. sp_3072_mont_sqr_26(t[28], t[14], m, mp);
  7385. sp_3072_mont_mul_26(t[29], t[15], t[14], m, mp);
  7386. sp_3072_mont_sqr_26(t[30], t[15], m, mp);
  7387. sp_3072_mont_mul_26(t[31], t[16], t[15], m, mp);
  7388. bits = ((bits + 4) / 5) * 5;
  7389. i = ((bits + 59) / 60) - 1;
  7390. c = bits % 60;
  7391. if (c == 0) {
  7392. c = 60;
  7393. }
  7394. if (i < 26) {
  7395. n = e[i--] << (64 - c);
  7396. }
  7397. else {
  7398. n = 0;
  7399. i--;
  7400. }
  7401. if (c < 5) {
  7402. n |= e[i--] << (4 - c);
  7403. c += 60;
  7404. }
  7405. y = (int)((n >> 59) & 0x1f);
  7406. n <<= 5;
  7407. c -= 5;
  7408. XMEMCPY(rt, t[y], sizeof(sp_digit) * 52);
  7409. while ((i >= 0) || (c >= 5)) {
  7410. if (c >= 5) {
  7411. y = (byte)((n >> 59) & 0x1f);
  7412. n <<= 5;
  7413. c -= 5;
  7414. }
  7415. else if (c == 0) {
  7416. n = e[i--] << 4;
  7417. y = (byte)((n >> 59) & 0x1f);
  7418. n <<= 5;
  7419. c = 55;
  7420. }
  7421. else {
  7422. y = (byte)((n >> 59) & 0x1f);
  7423. n = e[i--] << 4;
  7424. c = 5 - c;
  7425. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  7426. n <<= c;
  7427. c = 60 - c;
  7428. }
  7429. sp_3072_mont_sqr_26(rt, rt, m, mp);
  7430. sp_3072_mont_sqr_26(rt, rt, m, mp);
  7431. sp_3072_mont_sqr_26(rt, rt, m, mp);
  7432. sp_3072_mont_sqr_26(rt, rt, m, mp);
  7433. sp_3072_mont_sqr_26(rt, rt, m, mp);
  7434. sp_3072_mont_mul_26(rt, rt, t[y], m, mp);
  7435. }
  7436. sp_3072_mont_reduce_26(rt, m, mp);
  7437. n = sp_3072_cmp_26(rt, m);
  7438. sp_3072_cond_sub_26(rt, rt, m, ~(n >> 63));
  7439. XMEMCPY(r, rt, sizeof(sp_digit) * 52);
  7440. }
  7441. #ifdef WOLFSSL_SP_SMALL_STACK
  7442. if (td != NULL)
  7443. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7444. #endif
  7445. return err;
  7446. #endif
  7447. }
  7448. #endif /* (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) | WOLFSSL_HAVE_SP_DH */
  7449. /* Sub b from a into r. (r = a - b)
  7450. *
  7451. * r A single precision integer.
  7452. * a A single precision integer.
  7453. * b A single precision integer.
  7454. */
  7455. SP_NOINLINE static int sp_3072_sub_52(sp_digit* r, const sp_digit* a,
  7456. const sp_digit* b)
  7457. {
  7458. int i;
  7459. for (i = 0; i < 52; i++) {
  7460. r[i] = a[i] - b[i];
  7461. }
  7462. return 0;
  7463. }
  7464. /* r = 2^n mod m where n is the number of bits to reduce by.
  7465. * Given m must be 3072 bits, just need to subtract.
  7466. *
  7467. * r A single precision number.
  7468. * m A single precision number.
  7469. */
  7470. static void sp_3072_mont_norm_52(sp_digit* r, const sp_digit* m)
  7471. {
  7472. /* Set r = 2^n - 1. */
  7473. int i;
  7474. for (i=0; i<51; i++) {
  7475. r[i] = 0xfffffffffffffffL;
  7476. }
  7477. r[51] = 0xfffL;
  7478. /* r = (2^n - 1) mod n */
  7479. (void)sp_3072_sub_52(r, r, m);
  7480. /* Add one so r = 2^n mod m */
  7481. r[0] += 1;
  7482. }
  7483. /* Compare a with b in constant time.
  7484. *
  7485. * a A single precision integer.
  7486. * b A single precision integer.
  7487. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  7488. * respectively.
  7489. */
  7490. static sp_digit sp_3072_cmp_52(const sp_digit* a, const sp_digit* b)
  7491. {
  7492. sp_digit r = 0;
  7493. int i;
  7494. for (i=51; i>=0; i--) {
  7495. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 59);
  7496. }
  7497. return r;
  7498. }
  7499. /* Conditionally subtract b from a using the mask m.
  7500. * m is -1 to subtract and 0 when not.
  7501. *
  7502. * r A single precision number representing condition subtract result.
  7503. * a A single precision number to subtract from.
  7504. * b A single precision number to subtract.
  7505. * m Mask value to apply.
  7506. */
  7507. static void sp_3072_cond_sub_52(sp_digit* r, const sp_digit* a,
  7508. const sp_digit* b, const sp_digit m)
  7509. {
  7510. int i;
  7511. for (i = 0; i < 52; i++) {
  7512. r[i] = a[i] - (b[i] & m);
  7513. }
  7514. }
  7515. /* Mul a by scalar b and add into r. (r += a * b)
  7516. *
  7517. * r A single precision integer.
  7518. * a A single precision integer.
  7519. * b A scalar.
  7520. */
  7521. SP_NOINLINE static void sp_3072_mul_add_52(sp_digit* r, const sp_digit* a,
  7522. const sp_digit b)
  7523. {
  7524. sp_int128 tb = b;
  7525. sp_int128 t[4];
  7526. int i;
  7527. t[0] = 0;
  7528. for (i = 0; i < 48; i += 4) {
  7529. t[0] += (tb * a[i+0]) + r[i+0];
  7530. t[1] = (tb * a[i+1]) + r[i+1];
  7531. t[2] = (tb * a[i+2]) + r[i+2];
  7532. t[3] = (tb * a[i+3]) + r[i+3];
  7533. r[i+0] = t[0] & 0xfffffffffffffffL;
  7534. t[1] += t[0] >> 60;
  7535. r[i+1] = t[1] & 0xfffffffffffffffL;
  7536. t[2] += t[1] >> 60;
  7537. r[i+2] = t[2] & 0xfffffffffffffffL;
  7538. t[3] += t[2] >> 60;
  7539. r[i+3] = t[3] & 0xfffffffffffffffL;
  7540. t[0] = t[3] >> 60;
  7541. }
  7542. t[0] += (tb * a[48]) + r[48];
  7543. t[1] = (tb * a[49]) + r[49];
  7544. t[2] = (tb * a[50]) + r[50];
  7545. t[3] = (tb * a[51]) + r[51];
  7546. r[48] = t[0] & 0xfffffffffffffffL;
  7547. t[1] += t[0] >> 60;
  7548. r[49] = t[1] & 0xfffffffffffffffL;
  7549. t[2] += t[1] >> 60;
  7550. r[50] = t[2] & 0xfffffffffffffffL;
  7551. t[3] += t[2] >> 60;
  7552. r[51] = t[3] & 0xfffffffffffffffL;
  7553. r[52] += (sp_digit)(t[3] >> 60);
  7554. }
  7555. /* Shift the result in the high 3072 bits down to the bottom.
  7556. *
  7557. * r A single precision number.
  7558. * a A single precision number.
  7559. */
  7560. static void sp_3072_mont_shift_52(sp_digit* r, const sp_digit* a)
  7561. {
  7562. int i;
  7563. sp_int128 n = a[51] >> 12;
  7564. n += ((sp_int128)a[52]) << 48;
  7565. for (i = 0; i < 51; i++) {
  7566. r[i] = n & 0xfffffffffffffffL;
  7567. n >>= 60;
  7568. n += ((sp_int128)a[53 + i]) << 48;
  7569. }
  7570. r[51] = (sp_digit)n;
  7571. XMEMSET(&r[52], 0, sizeof(*r) * 52U);
  7572. }
  7573. /* Reduce the number back to 3072 bits using Montgomery reduction.
  7574. *
  7575. * a A single precision number to reduce in place.
  7576. * m The single precision number representing the modulus.
  7577. * mp The digit representing the negative inverse of m mod 2^n.
  7578. */
  7579. static void sp_3072_mont_reduce_52(sp_digit* a, const sp_digit* m, sp_digit mp)
  7580. {
  7581. int i;
  7582. sp_digit mu;
  7583. sp_digit over;
  7584. sp_3072_norm_52(a + 52);
  7585. #ifdef WOLFSSL_SP_DH
  7586. if (mp != 1) {
  7587. for (i=0; i<51; i++) {
  7588. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xfffffffffffffffL;
  7589. sp_3072_mul_add_52(a+i, m, mu);
  7590. a[i+1] += a[i] >> 60;
  7591. }
  7592. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xfffL;
  7593. sp_3072_mul_add_52(a+i, m, mu);
  7594. a[i+1] += a[i] >> 60;
  7595. a[i] &= 0xfffffffffffffffL;
  7596. }
  7597. else {
  7598. for (i=0; i<51; i++) {
  7599. mu = a[i] & 0xfffffffffffffffL;
  7600. sp_3072_mul_add_52(a+i, m, mu);
  7601. a[i+1] += a[i] >> 60;
  7602. }
  7603. mu = a[i] & 0xfffL;
  7604. sp_3072_mul_add_52(a+i, m, mu);
  7605. a[i+1] += a[i] >> 60;
  7606. a[i] &= 0xfffffffffffffffL;
  7607. }
  7608. #else
  7609. for (i=0; i<51; i++) {
  7610. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xfffffffffffffffL;
  7611. sp_3072_mul_add_52(a+i, m, mu);
  7612. a[i+1] += a[i] >> 60;
  7613. }
  7614. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xfffL;
  7615. sp_3072_mul_add_52(a+i, m, mu);
  7616. a[i+1] += a[i] >> 60;
  7617. a[i] &= 0xfffffffffffffffL;
  7618. #endif
  7619. sp_3072_mont_shift_52(a, a);
  7620. over = a[51] - m[51];
  7621. sp_3072_cond_sub_52(a, a, m, ~((over - 1) >> 63));
  7622. sp_3072_norm_52(a);
  7623. }
  7624. /* Multiply two Montgomery form numbers mod the modulus (prime).
  7625. * (r = a * b mod m)
  7626. *
  7627. * r Result of multiplication.
  7628. * a First number to multiply in Montgomery form.
  7629. * b Second number to multiply in Montgomery form.
  7630. * m Modulus (prime).
  7631. * mp Montgomery multiplier.
  7632. */
  7633. SP_NOINLINE static void sp_3072_mont_mul_52(sp_digit* r, const sp_digit* a,
  7634. const sp_digit* b, const sp_digit* m, sp_digit mp)
  7635. {
  7636. sp_3072_mul_52(r, a, b);
  7637. sp_3072_mont_reduce_52(r, m, mp);
  7638. }
  7639. /* Square the Montgomery form number. (r = a * a mod m)
  7640. *
  7641. * r Result of squaring.
  7642. * a Number to square in Montgomery form.
  7643. * m Modulus (prime).
  7644. * mp Montgomery multiplier.
  7645. */
  7646. SP_NOINLINE static void sp_3072_mont_sqr_52(sp_digit* r, const sp_digit* a,
  7647. const sp_digit* m, sp_digit mp)
  7648. {
  7649. sp_3072_sqr_52(r, a);
  7650. sp_3072_mont_reduce_52(r, m, mp);
  7651. }
  7652. /* Multiply a by scalar b into r. (r = a * b)
  7653. *
  7654. * r A single precision integer.
  7655. * a A single precision integer.
  7656. * b A scalar.
  7657. */
  7658. SP_NOINLINE static void sp_3072_mul_d_104(sp_digit* r, const sp_digit* a,
  7659. sp_digit b)
  7660. {
  7661. sp_int128 tb = b;
  7662. sp_int128 t = 0;
  7663. int i;
  7664. for (i = 0; i < 104; i++) {
  7665. t += tb * a[i];
  7666. r[i] = (sp_digit)(t & 0xfffffffffffffffL);
  7667. t >>= 60;
  7668. }
  7669. r[104] = (sp_digit)t;
  7670. }
  7671. #ifdef WOLFSSL_SP_SMALL
  7672. /* Conditionally add a and b using the mask m.
  7673. * m is -1 to add and 0 when not.
  7674. *
  7675. * r A single precision number representing conditional add result.
  7676. * a A single precision number to add with.
  7677. * b A single precision number to add.
  7678. * m Mask value to apply.
  7679. */
  7680. static void sp_3072_cond_add_52(sp_digit* r, const sp_digit* a,
  7681. const sp_digit* b, const sp_digit m)
  7682. {
  7683. int i;
  7684. for (i = 0; i < 52; i++) {
  7685. r[i] = a[i] + (b[i] & m);
  7686. }
  7687. }
  7688. #endif /* WOLFSSL_SP_SMALL */
  7689. /* Add b to a into r. (r = a + b)
  7690. *
  7691. * r A single precision integer.
  7692. * a A single precision integer.
  7693. * b A single precision integer.
  7694. */
  7695. SP_NOINLINE static int sp_3072_add_52(sp_digit* r, const sp_digit* a,
  7696. const sp_digit* b)
  7697. {
  7698. int i;
  7699. for (i = 0; i < 52; i++) {
  7700. r[i] = a[i] + b[i];
  7701. }
  7702. return 0;
  7703. }
  7704. SP_NOINLINE static void sp_3072_rshift_52(sp_digit* r, const sp_digit* a,
  7705. byte n)
  7706. {
  7707. int i;
  7708. for (i=0; i<51; i++) {
  7709. r[i] = ((a[i] >> n) | (a[i + 1] << (60 - n))) & 0xfffffffffffffffL;
  7710. }
  7711. r[51] = a[51] >> n;
  7712. }
  7713. static WC_INLINE sp_digit sp_3072_div_word_52(sp_digit d1, sp_digit d0,
  7714. sp_digit div)
  7715. {
  7716. #ifdef SP_USE_DIVTI3
  7717. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  7718. return d / div;
  7719. #elif defined(__x86_64__) || defined(__i386__)
  7720. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  7721. sp_uint64 lo = (sp_uint64)d;
  7722. sp_digit hi = (sp_digit)(d >> 64);
  7723. __asm__ __volatile__ (
  7724. "idiv %2"
  7725. : "+a" (lo)
  7726. : "d" (hi), "r" (div)
  7727. : "cc"
  7728. );
  7729. return (sp_digit)lo;
  7730. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  7731. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  7732. sp_digit dv = (div >> 1) + 1;
  7733. sp_digit t1 = (sp_digit)(d >> 60);
  7734. sp_digit t0 = (sp_digit)(d & 0xfffffffffffffffL);
  7735. sp_digit t2;
  7736. sp_digit sign;
  7737. sp_digit r;
  7738. int i;
  7739. sp_int128 m;
  7740. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  7741. t1 -= dv & (0 - r);
  7742. for (i = 58; i >= 1; i--) {
  7743. t1 += t1 + (((sp_uint64)t0 >> 59) & 1);
  7744. t0 <<= 1;
  7745. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  7746. r += r + t2;
  7747. t1 -= dv & (0 - t2);
  7748. t1 += t2;
  7749. }
  7750. r += r + 1;
  7751. m = d - ((sp_int128)r * div);
  7752. r += (sp_digit)(m >> 60);
  7753. m = d - ((sp_int128)r * div);
  7754. r += (sp_digit)(m >> 120) - (sp_digit)(d >> 120);
  7755. m = d - ((sp_int128)r * div);
  7756. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  7757. m *= sign;
  7758. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  7759. r += sign * t2;
  7760. m = d - ((sp_int128)r * div);
  7761. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  7762. m *= sign;
  7763. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  7764. r += sign * t2;
  7765. return r;
  7766. #else
  7767. sp_int128 d = ((sp_int128)d1 << 60) + d0;
  7768. sp_digit r = 0;
  7769. sp_digit t;
  7770. sp_digit dv = (div >> 29) + 1;
  7771. t = (sp_digit)(d >> 58);
  7772. t = (t / dv) << 29;
  7773. r += t;
  7774. d -= (sp_int128)t * div;
  7775. t = (sp_digit)(d >> 27);
  7776. t = t / (dv << 2);
  7777. r += t;
  7778. d -= (sp_int128)t * div;
  7779. t = (sp_digit)d;
  7780. t = t / div;
  7781. r += t;
  7782. d -= (sp_int128)t * div;
  7783. return r;
  7784. #endif
  7785. }
  7786. static WC_INLINE sp_digit sp_3072_word_div_word_52(sp_digit d, sp_digit div)
  7787. {
  7788. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  7789. defined(SP_DIV_WORD_USE_DIV)
  7790. return d / div;
  7791. #else
  7792. return (sp_digit)((sp_uint64)(div - d) >> 63);
  7793. #endif
  7794. }
  7795. /* Divide d in a and put remainder into r (m*d + r = a)
  7796. * m is not calculated as it is not needed at this time.
  7797. *
  7798. * Full implementation.
  7799. *
  7800. * a Number to be divided.
  7801. * d Number to divide with.
  7802. * m Multiplier result.
  7803. * r Remainder from the division.
  7804. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  7805. */
  7806. static int sp_3072_div_52(const sp_digit* a, const sp_digit* d,
  7807. const sp_digit* m, sp_digit* r)
  7808. {
  7809. int i;
  7810. #ifndef WOLFSSL_SP_DIV_64
  7811. #endif
  7812. sp_digit dv;
  7813. sp_digit r1;
  7814. #ifdef WOLFSSL_SP_SMALL_STACK
  7815. sp_digit* t1 = NULL;
  7816. #else
  7817. sp_digit t1[4 * 52 + 3];
  7818. #endif
  7819. sp_digit* t2 = NULL;
  7820. sp_digit* sd = NULL;
  7821. int err = MP_OKAY;
  7822. (void)m;
  7823. #ifdef WOLFSSL_SP_SMALL_STACK
  7824. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 52 + 3), NULL,
  7825. DYNAMIC_TYPE_TMP_BUFFER);
  7826. if (t1 == NULL)
  7827. err = MEMORY_E;
  7828. #endif
  7829. (void)m;
  7830. if (err == MP_OKAY) {
  7831. t2 = t1 + 104 + 1;
  7832. sd = t2 + 52 + 1;
  7833. sp_3072_mul_d_52(sd, d, (sp_digit)1 << 48);
  7834. sp_3072_mul_d_104(t1, a, (sp_digit)1 << 48);
  7835. dv = sd[51];
  7836. t1[52 + 52] += t1[52 + 52 - 1] >> 60;
  7837. t1[52 + 52 - 1] &= 0xfffffffffffffffL;
  7838. for (i=52; i>=0; i--) {
  7839. r1 = sp_3072_div_word_52(t1[52 + i], t1[52 + i - 1], dv);
  7840. sp_3072_mul_d_52(t2, sd, r1);
  7841. (void)sp_3072_sub_52(&t1[i], &t1[i], t2);
  7842. sp_3072_norm_52(&t1[i]);
  7843. t1[52 + i] -= t2[52];
  7844. t1[52 + i] += t1[52 + i - 1] >> 60;
  7845. t1[52 + i - 1] &= 0xfffffffffffffffL;
  7846. r1 = sp_3072_div_word_52(-t1[52 + i], -t1[52 + i - 1], dv);
  7847. r1 -= t1[52 + i];
  7848. sp_3072_mul_d_52(t2, sd, r1);
  7849. (void)sp_3072_add_52(&t1[i], &t1[i], t2);
  7850. t1[52 + i] += t1[52 + i - 1] >> 60;
  7851. t1[52 + i - 1] &= 0xfffffffffffffffL;
  7852. }
  7853. t1[52 - 1] += t1[52 - 2] >> 60;
  7854. t1[52 - 2] &= 0xfffffffffffffffL;
  7855. r1 = sp_3072_word_div_word_52(t1[52 - 1], dv);
  7856. sp_3072_mul_d_52(t2, sd, r1);
  7857. sp_3072_sub_52(t1, t1, t2);
  7858. XMEMCPY(r, t1, sizeof(*r) * 104U);
  7859. for (i=0; i<51; i++) {
  7860. r[i+1] += r[i] >> 60;
  7861. r[i] &= 0xfffffffffffffffL;
  7862. }
  7863. sp_3072_cond_add_52(r, r, sd, r[51] >> 63);
  7864. sp_3072_norm_52(r);
  7865. sp_3072_rshift_52(r, r, 48);
  7866. }
  7867. #ifdef WOLFSSL_SP_SMALL_STACK
  7868. if (t1 != NULL)
  7869. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7870. #endif
  7871. return err;
  7872. }
  7873. /* Reduce a modulo m into r. (r = a mod m)
  7874. *
  7875. * r A single precision number that is the reduced result.
  7876. * a A single precision number that is to be reduced.
  7877. * m A single precision number that is the modulus to reduce with.
  7878. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  7879. */
  7880. static int sp_3072_mod_52(sp_digit* r, const sp_digit* a, const sp_digit* m)
  7881. {
  7882. return sp_3072_div_52(a, m, NULL, r);
  7883. }
  7884. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  7885. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  7886. *
  7887. * r A single precision number that is the result of the operation.
  7888. * a A single precision number being exponentiated.
  7889. * e A single precision number that is the exponent.
  7890. * bits The number of bits in the exponent.
  7891. * m A single precision number that is the modulus.
  7892. * returns 0 on success.
  7893. * returns MEMORY_E on dynamic memory allocation failure.
  7894. * returns MP_VAL when base is even or exponent is 0.
  7895. */
  7896. static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e,
  7897. int bits, const sp_digit* m, int reduceA)
  7898. {
  7899. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  7900. #ifdef WOLFSSL_SP_SMALL_STACK
  7901. sp_digit* td = NULL;
  7902. #else
  7903. sp_digit td[3 * 104];
  7904. #endif
  7905. sp_digit* t[3] = {0, 0, 0};
  7906. sp_digit* norm = NULL;
  7907. sp_digit mp = 1;
  7908. sp_digit n;
  7909. int i;
  7910. int c;
  7911. byte y;
  7912. int err = MP_OKAY;
  7913. if (bits == 0) {
  7914. err = MP_VAL;
  7915. }
  7916. #ifdef WOLFSSL_SP_SMALL_STACK
  7917. if (err == MP_OKAY) {
  7918. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 52 * 2, NULL,
  7919. DYNAMIC_TYPE_TMP_BUFFER);
  7920. if (td == NULL)
  7921. err = MEMORY_E;
  7922. }
  7923. #endif
  7924. if (err == MP_OKAY) {
  7925. norm = td;
  7926. for (i=0; i<3; i++) {
  7927. t[i] = td + (i * 52 * 2);
  7928. XMEMSET(t[i], 0, sizeof(sp_digit) * 52U * 2U);
  7929. }
  7930. sp_3072_mont_setup(m, &mp);
  7931. sp_3072_mont_norm_52(norm, m);
  7932. if (reduceA != 0) {
  7933. err = sp_3072_mod_52(t[1], a, m);
  7934. }
  7935. else {
  7936. XMEMCPY(t[1], a, sizeof(sp_digit) * 52U);
  7937. }
  7938. }
  7939. if (err == MP_OKAY) {
  7940. sp_3072_mul_52(t[1], t[1], norm);
  7941. err = sp_3072_mod_52(t[1], t[1], m);
  7942. }
  7943. if (err == MP_OKAY) {
  7944. i = bits / 60;
  7945. c = bits % 60;
  7946. n = e[i--] << (60 - c);
  7947. for (; ; c--) {
  7948. if (c == 0) {
  7949. if (i == -1) {
  7950. break;
  7951. }
  7952. n = e[i--];
  7953. c = 60;
  7954. }
  7955. y = (int)((n >> 59) & 1);
  7956. n <<= 1;
  7957. sp_3072_mont_mul_52(t[y^1], t[0], t[1], m, mp);
  7958. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  7959. ((size_t)t[1] & addr_mask[y])),
  7960. sizeof(*t[2]) * 52 * 2);
  7961. sp_3072_mont_sqr_52(t[2], t[2], m, mp);
  7962. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  7963. ((size_t)t[1] & addr_mask[y])), t[2],
  7964. sizeof(*t[2]) * 52 * 2);
  7965. }
  7966. sp_3072_mont_reduce_52(t[0], m, mp);
  7967. n = sp_3072_cmp_52(t[0], m);
  7968. sp_3072_cond_sub_52(t[0], t[0], m, ~(n >> 63));
  7969. XMEMCPY(r, t[0], sizeof(*r) * 52 * 2);
  7970. }
  7971. #ifdef WOLFSSL_SP_SMALL_STACK
  7972. if (td != NULL)
  7973. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7974. #endif
  7975. return err;
  7976. #elif !defined(WC_NO_CACHE_RESISTANT)
  7977. #ifdef WOLFSSL_SP_SMALL_STACK
  7978. sp_digit* td = NULL;
  7979. #else
  7980. sp_digit td[3 * 104];
  7981. #endif
  7982. sp_digit* t[3] = {0, 0, 0};
  7983. sp_digit* norm = NULL;
  7984. sp_digit mp = 1;
  7985. sp_digit n;
  7986. int i;
  7987. int c;
  7988. byte y;
  7989. int err = MP_OKAY;
  7990. if (bits == 0) {
  7991. err = MP_VAL;
  7992. }
  7993. #ifdef WOLFSSL_SP_SMALL_STACK
  7994. if (err == MP_OKAY) {
  7995. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 52 * 2, NULL,
  7996. DYNAMIC_TYPE_TMP_BUFFER);
  7997. if (td == NULL)
  7998. err = MEMORY_E;
  7999. }
  8000. #endif
  8001. if (err == MP_OKAY) {
  8002. norm = td;
  8003. for (i=0; i<3; i++) {
  8004. t[i] = td + (i * 52 * 2);
  8005. }
  8006. sp_3072_mont_setup(m, &mp);
  8007. sp_3072_mont_norm_52(norm, m);
  8008. if (reduceA != 0) {
  8009. err = sp_3072_mod_52(t[1], a, m);
  8010. if (err == MP_OKAY) {
  8011. sp_3072_mul_52(t[1], t[1], norm);
  8012. err = sp_3072_mod_52(t[1], t[1], m);
  8013. }
  8014. }
  8015. else {
  8016. sp_3072_mul_52(t[1], a, norm);
  8017. err = sp_3072_mod_52(t[1], t[1], m);
  8018. }
  8019. }
  8020. if (err == MP_OKAY) {
  8021. i = bits / 60;
  8022. c = bits % 60;
  8023. n = e[i--] << (60 - c);
  8024. for (; ; c--) {
  8025. if (c == 0) {
  8026. if (i == -1) {
  8027. break;
  8028. }
  8029. n = e[i--];
  8030. c = 60;
  8031. }
  8032. y = (int)((n >> 59) & 1);
  8033. n <<= 1;
  8034. sp_3072_mont_mul_52(t[y^1], t[0], t[1], m, mp);
  8035. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  8036. ((size_t)t[1] & addr_mask[y])),
  8037. sizeof(*t[2]) * 52 * 2);
  8038. sp_3072_mont_sqr_52(t[2], t[2], m, mp);
  8039. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  8040. ((size_t)t[1] & addr_mask[y])), t[2],
  8041. sizeof(*t[2]) * 52 * 2);
  8042. }
  8043. sp_3072_mont_reduce_52(t[0], m, mp);
  8044. n = sp_3072_cmp_52(t[0], m);
  8045. sp_3072_cond_sub_52(t[0], t[0], m, ~(n >> 63));
  8046. XMEMCPY(r, t[0], sizeof(*r) * 52 * 2);
  8047. }
  8048. #ifdef WOLFSSL_SP_SMALL_STACK
  8049. if (td != NULL)
  8050. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  8051. #endif
  8052. return err;
  8053. #else
  8054. #ifdef WOLFSSL_SP_SMALL_STACK
  8055. sp_digit* td = NULL;
  8056. #else
  8057. sp_digit td[(16 * 104) + 104];
  8058. #endif
  8059. sp_digit* t[16];
  8060. sp_digit* rt = NULL;
  8061. sp_digit* norm = NULL;
  8062. sp_digit mp = 1;
  8063. sp_digit n;
  8064. int i;
  8065. int c;
  8066. byte y;
  8067. int err = MP_OKAY;
  8068. if (bits == 0) {
  8069. err = MP_VAL;
  8070. }
  8071. #ifdef WOLFSSL_SP_SMALL_STACK
  8072. if (err == MP_OKAY) {
  8073. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 104) + 104), NULL,
  8074. DYNAMIC_TYPE_TMP_BUFFER);
  8075. if (td == NULL)
  8076. err = MEMORY_E;
  8077. }
  8078. #endif
  8079. if (err == MP_OKAY) {
  8080. norm = td;
  8081. for (i=0; i<16; i++)
  8082. t[i] = td + i * 104;
  8083. rt = td + 1664;
  8084. sp_3072_mont_setup(m, &mp);
  8085. sp_3072_mont_norm_52(norm, m);
  8086. if (reduceA != 0) {
  8087. err = sp_3072_mod_52(t[1], a, m);
  8088. if (err == MP_OKAY) {
  8089. sp_3072_mul_52(t[1], t[1], norm);
  8090. err = sp_3072_mod_52(t[1], t[1], m);
  8091. }
  8092. }
  8093. else {
  8094. sp_3072_mul_52(t[1], a, norm);
  8095. err = sp_3072_mod_52(t[1], t[1], m);
  8096. }
  8097. }
  8098. if (err == MP_OKAY) {
  8099. sp_3072_mont_sqr_52(t[ 2], t[ 1], m, mp);
  8100. sp_3072_mont_mul_52(t[ 3], t[ 2], t[ 1], m, mp);
  8101. sp_3072_mont_sqr_52(t[ 4], t[ 2], m, mp);
  8102. sp_3072_mont_mul_52(t[ 5], t[ 3], t[ 2], m, mp);
  8103. sp_3072_mont_sqr_52(t[ 6], t[ 3], m, mp);
  8104. sp_3072_mont_mul_52(t[ 7], t[ 4], t[ 3], m, mp);
  8105. sp_3072_mont_sqr_52(t[ 8], t[ 4], m, mp);
  8106. sp_3072_mont_mul_52(t[ 9], t[ 5], t[ 4], m, mp);
  8107. sp_3072_mont_sqr_52(t[10], t[ 5], m, mp);
  8108. sp_3072_mont_mul_52(t[11], t[ 6], t[ 5], m, mp);
  8109. sp_3072_mont_sqr_52(t[12], t[ 6], m, mp);
  8110. sp_3072_mont_mul_52(t[13], t[ 7], t[ 6], m, mp);
  8111. sp_3072_mont_sqr_52(t[14], t[ 7], m, mp);
  8112. sp_3072_mont_mul_52(t[15], t[ 8], t[ 7], m, mp);
  8113. bits = ((bits + 3) / 4) * 4;
  8114. i = ((bits + 59) / 60) - 1;
  8115. c = bits % 60;
  8116. if (c == 0) {
  8117. c = 60;
  8118. }
  8119. if (i < 52) {
  8120. n = e[i--] << (64 - c);
  8121. }
  8122. else {
  8123. n = 0;
  8124. i--;
  8125. }
  8126. if (c < 4) {
  8127. n |= e[i--] << (4 - c);
  8128. c += 60;
  8129. }
  8130. y = (int)((n >> 60) & 0xf);
  8131. n <<= 4;
  8132. c -= 4;
  8133. XMEMCPY(rt, t[y], sizeof(sp_digit) * 104);
  8134. while ((i >= 0) || (c >= 4)) {
  8135. if (c >= 4) {
  8136. y = (byte)((n >> 60) & 0xf);
  8137. n <<= 4;
  8138. c -= 4;
  8139. }
  8140. else if (c == 0) {
  8141. n = e[i--] << 4;
  8142. y = (byte)((n >> 60) & 0xf);
  8143. n <<= 4;
  8144. c = 56;
  8145. }
  8146. else {
  8147. y = (byte)((n >> 60) & 0xf);
  8148. n = e[i--] << 4;
  8149. c = 4 - c;
  8150. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  8151. n <<= c;
  8152. c = 60 - c;
  8153. }
  8154. sp_3072_mont_sqr_52(rt, rt, m, mp);
  8155. sp_3072_mont_sqr_52(rt, rt, m, mp);
  8156. sp_3072_mont_sqr_52(rt, rt, m, mp);
  8157. sp_3072_mont_sqr_52(rt, rt, m, mp);
  8158. sp_3072_mont_mul_52(rt, rt, t[y], m, mp);
  8159. }
  8160. sp_3072_mont_reduce_52(rt, m, mp);
  8161. n = sp_3072_cmp_52(rt, m);
  8162. sp_3072_cond_sub_52(rt, rt, m, ~(n >> 63));
  8163. XMEMCPY(r, rt, sizeof(sp_digit) * 104);
  8164. }
  8165. #ifdef WOLFSSL_SP_SMALL_STACK
  8166. if (td != NULL)
  8167. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  8168. #endif
  8169. return err;
  8170. #endif
  8171. }
  8172. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  8173. #ifdef WOLFSSL_HAVE_SP_RSA
  8174. /* RSA public key operation.
  8175. *
  8176. * in Array of bytes representing the number to exponentiate, base.
  8177. * inLen Number of bytes in base.
  8178. * em Public exponent.
  8179. * mm Modulus.
  8180. * out Buffer to hold big-endian bytes of exponentiation result.
  8181. * Must be at least 384 bytes long.
  8182. * outLen Number of bytes in result.
  8183. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  8184. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  8185. */
  8186. int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em,
  8187. const mp_int* mm, byte* out, word32* outLen)
  8188. {
  8189. #ifdef WOLFSSL_SP_SMALL
  8190. #ifdef WOLFSSL_SP_SMALL_STACK
  8191. sp_digit* a = NULL;
  8192. #else
  8193. sp_digit a[52 * 5];
  8194. #endif
  8195. sp_digit* m = NULL;
  8196. sp_digit* r = NULL;
  8197. sp_digit* norm = NULL;
  8198. sp_digit e[1] = {0};
  8199. sp_digit mp = 0;
  8200. int i;
  8201. int err = MP_OKAY;
  8202. if (*outLen < 384U) {
  8203. err = MP_TO_E;
  8204. }
  8205. if (err == MP_OKAY) {
  8206. if (mp_count_bits(em) > 60) {
  8207. err = MP_READ_E;
  8208. }
  8209. else if (inLen > 384U) {
  8210. err = MP_READ_E;
  8211. }
  8212. else if (mp_count_bits(mm) != 3072) {
  8213. err = MP_READ_E;
  8214. }
  8215. else if (mp_iseven(mm)) {
  8216. err = MP_VAL;
  8217. }
  8218. }
  8219. #ifdef WOLFSSL_SP_SMALL_STACK
  8220. if (err == MP_OKAY) {
  8221. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 5, NULL,
  8222. DYNAMIC_TYPE_RSA);
  8223. if (a == NULL)
  8224. err = MEMORY_E;
  8225. }
  8226. #endif
  8227. if (err == MP_OKAY) {
  8228. r = a + 52 * 2;
  8229. m = r + 52 * 2;
  8230. norm = r;
  8231. sp_3072_from_bin(a, 52, in, inLen);
  8232. #if DIGIT_BIT >= 60
  8233. e[0] = (sp_digit)em->dp[0];
  8234. #else
  8235. e[0] = (sp_digit)em->dp[0];
  8236. if (em->used > 1) {
  8237. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  8238. }
  8239. #endif
  8240. if (e[0] == 0) {
  8241. err = MP_EXPTMOD_E;
  8242. }
  8243. }
  8244. if (err == MP_OKAY) {
  8245. sp_3072_from_mp(m, 52, mm);
  8246. sp_3072_mont_setup(m, &mp);
  8247. sp_3072_mont_norm_52(norm, m);
  8248. }
  8249. if (err == MP_OKAY) {
  8250. sp_3072_mul_52(a, a, norm);
  8251. err = sp_3072_mod_52(a, a, m);
  8252. }
  8253. if (err == MP_OKAY) {
  8254. for (i=59; i>=0; i--) {
  8255. if ((e[0] >> i) != 0) {
  8256. break;
  8257. }
  8258. }
  8259. XMEMCPY(r, a, sizeof(sp_digit) * 52 * 2);
  8260. for (i--; i>=0; i--) {
  8261. sp_3072_mont_sqr_52(r, r, m, mp);
  8262. if (((e[0] >> i) & 1) == 1) {
  8263. sp_3072_mont_mul_52(r, r, a, m, mp);
  8264. }
  8265. }
  8266. sp_3072_mont_reduce_52(r, m, mp);
  8267. mp = sp_3072_cmp_52(r, m);
  8268. sp_3072_cond_sub_52(r, r, m, ~(mp >> 63));
  8269. sp_3072_to_bin_52(r, out);
  8270. *outLen = 384;
  8271. }
  8272. #ifdef WOLFSSL_SP_SMALL_STACK
  8273. if (a != NULL)
  8274. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  8275. #endif
  8276. return err;
  8277. #else
  8278. #ifdef WOLFSSL_SP_SMALL_STACK
  8279. sp_digit* d = NULL;
  8280. #else
  8281. sp_digit d[52 * 5];
  8282. #endif
  8283. sp_digit* a = NULL;
  8284. sp_digit* m = NULL;
  8285. sp_digit* r = NULL;
  8286. sp_digit e[1] = {0};
  8287. int err = MP_OKAY;
  8288. if (*outLen < 384U) {
  8289. err = MP_TO_E;
  8290. }
  8291. if (err == MP_OKAY) {
  8292. if (mp_count_bits(em) > 60) {
  8293. err = MP_READ_E;
  8294. }
  8295. else if (inLen > 384U) {
  8296. err = MP_READ_E;
  8297. }
  8298. else if (mp_count_bits(mm) != 3072) {
  8299. err = MP_READ_E;
  8300. }
  8301. else if (mp_iseven(mm)) {
  8302. err = MP_VAL;
  8303. }
  8304. }
  8305. #ifdef WOLFSSL_SP_SMALL_STACK
  8306. if (err == MP_OKAY) {
  8307. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 5, NULL,
  8308. DYNAMIC_TYPE_RSA);
  8309. if (d == NULL)
  8310. err = MEMORY_E;
  8311. }
  8312. #endif
  8313. if (err == MP_OKAY) {
  8314. a = d;
  8315. r = a + 52 * 2;
  8316. m = r + 52 * 2;
  8317. sp_3072_from_bin(a, 52, in, inLen);
  8318. #if DIGIT_BIT >= 60
  8319. e[0] = (sp_digit)em->dp[0];
  8320. #else
  8321. e[0] = (sp_digit)em->dp[0];
  8322. if (em->used > 1) {
  8323. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  8324. }
  8325. #endif
  8326. if (e[0] == 0) {
  8327. err = MP_EXPTMOD_E;
  8328. }
  8329. }
  8330. if (err == MP_OKAY) {
  8331. sp_3072_from_mp(m, 52, mm);
  8332. if (e[0] == 0x3) {
  8333. sp_3072_sqr_52(r, a);
  8334. err = sp_3072_mod_52(r, r, m);
  8335. if (err == MP_OKAY) {
  8336. sp_3072_mul_52(r, a, r);
  8337. err = sp_3072_mod_52(r, r, m);
  8338. }
  8339. }
  8340. else {
  8341. sp_digit* norm = r;
  8342. int i;
  8343. sp_digit mp;
  8344. sp_3072_mont_setup(m, &mp);
  8345. sp_3072_mont_norm_52(norm, m);
  8346. sp_3072_mul_52(a, a, norm);
  8347. err = sp_3072_mod_52(a, a, m);
  8348. if (err == MP_OKAY) {
  8349. for (i=59; i>=0; i--) {
  8350. if ((e[0] >> i) != 0) {
  8351. break;
  8352. }
  8353. }
  8354. XMEMCPY(r, a, sizeof(sp_digit) * 104U);
  8355. for (i--; i>=0; i--) {
  8356. sp_3072_mont_sqr_52(r, r, m, mp);
  8357. if (((e[0] >> i) & 1) == 1) {
  8358. sp_3072_mont_mul_52(r, r, a, m, mp);
  8359. }
  8360. }
  8361. sp_3072_mont_reduce_52(r, m, mp);
  8362. mp = sp_3072_cmp_52(r, m);
  8363. sp_3072_cond_sub_52(r, r, m, ~(mp >> 63));
  8364. }
  8365. }
  8366. }
  8367. if (err == MP_OKAY) {
  8368. sp_3072_to_bin_52(r, out);
  8369. *outLen = 384;
  8370. }
  8371. #ifdef WOLFSSL_SP_SMALL_STACK
  8372. if (d != NULL)
  8373. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  8374. #endif
  8375. return err;
  8376. #endif /* WOLFSSL_SP_SMALL */
  8377. }
  8378. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  8379. #if !defined(SP_RSA_PRIVATE_EXP_D) && !defined(RSA_LOW_MEM)
  8380. #endif /* !SP_RSA_PRIVATE_EXP_D & !RSA_LOW_MEM */
  8381. /* RSA private key operation.
  8382. *
  8383. * in Array of bytes representing the number to exponentiate, base.
  8384. * inLen Number of bytes in base.
  8385. * dm Private exponent.
  8386. * pm First prime.
  8387. * qm Second prime.
  8388. * dpm First prime's CRT exponent.
  8389. * dqm Second prime's CRT exponent.
  8390. * qim Inverse of second prime mod p.
  8391. * mm Modulus.
  8392. * out Buffer to hold big-endian bytes of exponentiation result.
  8393. * Must be at least 384 bytes long.
  8394. * outLen Number of bytes in result.
  8395. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  8396. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  8397. */
  8398. int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm,
  8399. const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm,
  8400. const mp_int* qim, const mp_int* mm, byte* out, word32* outLen)
  8401. {
  8402. #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM)
  8403. #if defined(WOLFSSL_SP_SMALL)
  8404. #ifdef WOLFSSL_SP_SMALL_STACK
  8405. sp_digit* d = NULL;
  8406. #else
  8407. sp_digit d[52 * 4];
  8408. #endif
  8409. sp_digit* a = NULL;
  8410. sp_digit* m = NULL;
  8411. sp_digit* r = NULL;
  8412. int err = MP_OKAY;
  8413. (void)pm;
  8414. (void)qm;
  8415. (void)dpm;
  8416. (void)dqm;
  8417. (void)qim;
  8418. if (*outLen < 384U) {
  8419. err = MP_TO_E;
  8420. }
  8421. if (err == MP_OKAY) {
  8422. if (mp_count_bits(dm) > 3072) {
  8423. err = MP_READ_E;
  8424. }
  8425. else if (inLen > 384) {
  8426. err = MP_READ_E;
  8427. }
  8428. else if (mp_count_bits(mm) != 3072) {
  8429. err = MP_READ_E;
  8430. }
  8431. else if (mp_iseven(mm)) {
  8432. err = MP_VAL;
  8433. }
  8434. }
  8435. #ifdef WOLFSSL_SP_SMALL_STACK
  8436. if (err == MP_OKAY) {
  8437. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL,
  8438. DYNAMIC_TYPE_RSA);
  8439. if (d == NULL)
  8440. err = MEMORY_E;
  8441. }
  8442. #endif
  8443. if (err == MP_OKAY) {
  8444. a = d + 52;
  8445. m = a + 104;
  8446. r = a;
  8447. sp_3072_from_bin(a, 52, in, inLen);
  8448. sp_3072_from_mp(d, 52, dm);
  8449. sp_3072_from_mp(m, 52, mm);
  8450. err = sp_3072_mod_exp_52(r, a, d, 3072, m, 0);
  8451. }
  8452. if (err == MP_OKAY) {
  8453. sp_3072_to_bin_52(r, out);
  8454. *outLen = 384;
  8455. }
  8456. #ifdef WOLFSSL_SP_SMALL_STACK
  8457. if (d != NULL)
  8458. #endif
  8459. {
  8460. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  8461. if (a != NULL)
  8462. ForceZero(a, sizeof(sp_digit) * 52);
  8463. #ifdef WOLFSSL_SP_SMALL_STACK
  8464. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  8465. #endif
  8466. }
  8467. return err;
  8468. #else
  8469. #ifdef WOLFSSL_SP_SMALL_STACK
  8470. sp_digit* d = NULL;
  8471. #else
  8472. sp_digit d[52 * 4];
  8473. #endif
  8474. sp_digit* a = NULL;
  8475. sp_digit* m = NULL;
  8476. sp_digit* r = NULL;
  8477. int err = MP_OKAY;
  8478. (void)pm;
  8479. (void)qm;
  8480. (void)dpm;
  8481. (void)dqm;
  8482. (void)qim;
  8483. if (*outLen < 384U) {
  8484. err = MP_TO_E;
  8485. }
  8486. if (err == MP_OKAY) {
  8487. if (mp_count_bits(dm) > 3072) {
  8488. err = MP_READ_E;
  8489. }
  8490. else if (inLen > 384U) {
  8491. err = MP_READ_E;
  8492. }
  8493. else if (mp_count_bits(mm) != 3072) {
  8494. err = MP_READ_E;
  8495. }
  8496. else if (mp_iseven(mm)) {
  8497. err = MP_VAL;
  8498. }
  8499. }
  8500. #ifdef WOLFSSL_SP_SMALL_STACK
  8501. if (err == MP_OKAY) {
  8502. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL,
  8503. DYNAMIC_TYPE_RSA);
  8504. if (d == NULL)
  8505. err = MEMORY_E;
  8506. }
  8507. #endif
  8508. if (err == MP_OKAY) {
  8509. a = d + 52;
  8510. m = a + 104;
  8511. r = a;
  8512. sp_3072_from_bin(a, 52, in, inLen);
  8513. sp_3072_from_mp(d, 52, dm);
  8514. sp_3072_from_mp(m, 52, mm);
  8515. err = sp_3072_mod_exp_52(r, a, d, 3072, m, 0);
  8516. }
  8517. if (err == MP_OKAY) {
  8518. sp_3072_to_bin_52(r, out);
  8519. *outLen = 384;
  8520. }
  8521. #ifdef WOLFSSL_SP_SMALL_STACK
  8522. if (d != NULL)
  8523. #endif
  8524. {
  8525. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  8526. if (a != NULL)
  8527. ForceZero(a, sizeof(sp_digit) * 52);
  8528. #ifdef WOLFSSL_SP_SMALL_STACK
  8529. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  8530. #endif
  8531. }
  8532. return err;
  8533. #endif /* WOLFSSL_SP_SMALL */
  8534. #else
  8535. #if defined(WOLFSSL_SP_SMALL)
  8536. #ifdef WOLFSSL_SP_SMALL_STACK
  8537. sp_digit* a = NULL;
  8538. #else
  8539. sp_digit a[26 * 8];
  8540. #endif
  8541. sp_digit* p = NULL;
  8542. sp_digit* dp = NULL;
  8543. sp_digit* dq = NULL;
  8544. sp_digit* qi = NULL;
  8545. sp_digit* tmpa = NULL;
  8546. sp_digit* tmpb = NULL;
  8547. sp_digit* r = NULL;
  8548. int err = MP_OKAY;
  8549. (void)dm;
  8550. (void)mm;
  8551. if (*outLen < 384U) {
  8552. err = MP_TO_E;
  8553. }
  8554. if (err == MP_OKAY) {
  8555. if (inLen > 384) {
  8556. err = MP_READ_E;
  8557. }
  8558. else if (mp_count_bits(mm) != 3072) {
  8559. err = MP_READ_E;
  8560. }
  8561. else if (mp_iseven(mm)) {
  8562. err = MP_VAL;
  8563. }
  8564. else if (mp_iseven(pm)) {
  8565. err = MP_VAL;
  8566. }
  8567. else if (mp_iseven(qm)) {
  8568. err = MP_VAL;
  8569. }
  8570. }
  8571. #ifdef WOLFSSL_SP_SMALL_STACK
  8572. if (err == MP_OKAY) {
  8573. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 8, NULL,
  8574. DYNAMIC_TYPE_RSA);
  8575. if (a == NULL)
  8576. err = MEMORY_E;
  8577. }
  8578. #endif
  8579. if (err == MP_OKAY) {
  8580. p = a + 52;
  8581. qi = dq = dp = p + 26;
  8582. tmpa = qi + 26;
  8583. tmpb = tmpa + 52;
  8584. r = a;
  8585. sp_3072_from_bin(a, 52, in, inLen);
  8586. sp_3072_from_mp(p, 26, pm);
  8587. sp_3072_from_mp(dp, 26, dpm);
  8588. err = sp_3072_mod_exp_26(tmpa, a, dp, 1536, p, 1);
  8589. }
  8590. if (err == MP_OKAY) {
  8591. sp_3072_from_mp(p, 26, qm);
  8592. sp_3072_from_mp(dq, 26, dqm);
  8593. err = sp_3072_mod_exp_26(tmpb, a, dq, 1536, p, 1);
  8594. }
  8595. if (err == MP_OKAY) {
  8596. sp_3072_from_mp(p, 26, pm);
  8597. (void)sp_3072_sub_26(tmpa, tmpa, tmpb);
  8598. sp_3072_norm_26(tmpa);
  8599. sp_3072_cond_add_26(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[25] >> 63));
  8600. sp_3072_cond_add_26(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[25] >> 63));
  8601. sp_3072_norm_26(tmpa);
  8602. sp_3072_from_mp(qi, 26, qim);
  8603. sp_3072_mul_26(tmpa, tmpa, qi);
  8604. err = sp_3072_mod_26(tmpa, tmpa, p);
  8605. }
  8606. if (err == MP_OKAY) {
  8607. sp_3072_from_mp(p, 26, qm);
  8608. sp_3072_mul_26(tmpa, p, tmpa);
  8609. (void)sp_3072_add_52(r, tmpb, tmpa);
  8610. sp_3072_norm_52(r);
  8611. sp_3072_to_bin_52(r, out);
  8612. *outLen = 384;
  8613. }
  8614. #ifdef WOLFSSL_SP_SMALL_STACK
  8615. if (a != NULL)
  8616. #endif
  8617. {
  8618. ForceZero(a, sizeof(sp_digit) * 26 * 8);
  8619. #ifdef WOLFSSL_SP_SMALL_STACK
  8620. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  8621. #endif
  8622. }
  8623. return err;
  8624. #else
  8625. #ifdef WOLFSSL_SP_SMALL_STACK
  8626. sp_digit* a = NULL;
  8627. #else
  8628. sp_digit a[26 * 13];
  8629. #endif
  8630. sp_digit* p = NULL;
  8631. sp_digit* q = NULL;
  8632. sp_digit* dp = NULL;
  8633. sp_digit* dq = NULL;
  8634. sp_digit* qi = NULL;
  8635. sp_digit* tmpa = NULL;
  8636. sp_digit* tmpb = NULL;
  8637. sp_digit* r = NULL;
  8638. int err = MP_OKAY;
  8639. (void)dm;
  8640. (void)mm;
  8641. if (*outLen < 384U) {
  8642. err = MP_TO_E;
  8643. }
  8644. if (err == MP_OKAY) {
  8645. if (inLen > 384U) {
  8646. err = MP_READ_E;
  8647. }
  8648. else if (mp_count_bits(mm) != 3072) {
  8649. err = MP_READ_E;
  8650. }
  8651. else if (mp_iseven(mm)) {
  8652. err = MP_VAL;
  8653. }
  8654. else if (mp_iseven(pm)) {
  8655. err = MP_VAL;
  8656. }
  8657. else if (mp_iseven(qm)) {
  8658. err = MP_VAL;
  8659. }
  8660. }
  8661. #ifdef WOLFSSL_SP_SMALL_STACK
  8662. if (err == MP_OKAY) {
  8663. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 13, NULL,
  8664. DYNAMIC_TYPE_RSA);
  8665. if (a == NULL)
  8666. err = MEMORY_E;
  8667. }
  8668. #endif
  8669. if (err == MP_OKAY) {
  8670. p = a + 52 * 2;
  8671. q = p + 26;
  8672. dp = q + 26;
  8673. dq = dp + 26;
  8674. qi = dq + 26;
  8675. tmpa = qi + 26;
  8676. tmpb = tmpa + 52;
  8677. r = a;
  8678. sp_3072_from_bin(a, 52, in, inLen);
  8679. sp_3072_from_mp(p, 26, pm);
  8680. sp_3072_from_mp(q, 26, qm);
  8681. sp_3072_from_mp(dp, 26, dpm);
  8682. sp_3072_from_mp(dq, 26, dqm);
  8683. sp_3072_from_mp(qi, 26, qim);
  8684. err = sp_3072_mod_exp_26(tmpa, a, dp, 1536, p, 1);
  8685. }
  8686. if (err == MP_OKAY) {
  8687. err = sp_3072_mod_exp_26(tmpb, a, dq, 1536, q, 1);
  8688. }
  8689. if (err == MP_OKAY) {
  8690. (void)sp_3072_sub_26(tmpa, tmpa, tmpb);
  8691. sp_3072_norm_26(tmpa);
  8692. sp_3072_cond_add_26(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[25] >> 63));
  8693. sp_3072_cond_add_26(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[25] >> 63));
  8694. sp_3072_norm_26(tmpa);
  8695. sp_3072_mul_26(tmpa, tmpa, qi);
  8696. err = sp_3072_mod_26(tmpa, tmpa, p);
  8697. }
  8698. if (err == MP_OKAY) {
  8699. sp_3072_mul_26(tmpa, tmpa, q);
  8700. (void)sp_3072_add_52(r, tmpb, tmpa);
  8701. sp_3072_norm_52(r);
  8702. sp_3072_to_bin_52(r, out);
  8703. *outLen = 384;
  8704. }
  8705. #ifdef WOLFSSL_SP_SMALL_STACK
  8706. if (a != NULL)
  8707. #endif
  8708. {
  8709. ForceZero(a, sizeof(sp_digit) * 26 * 13);
  8710. #ifdef WOLFSSL_SP_SMALL_STACK
  8711. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  8712. #endif
  8713. }
  8714. return err;
  8715. #endif /* WOLFSSL_SP_SMALL */
  8716. #endif /* SP_RSA_PRIVATE_EXP_D || RSA_LOW_MEM */
  8717. }
  8718. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  8719. #endif /* WOLFSSL_HAVE_SP_RSA */
  8720. #if defined(WOLFSSL_HAVE_SP_DH) || (defined(WOLFSSL_HAVE_SP_RSA) && \
  8721. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  8722. /* Convert an array of sp_digit to an mp_int.
  8723. *
  8724. * a A single precision integer.
  8725. * r A multi-precision integer.
  8726. */
  8727. static int sp_3072_to_mp(const sp_digit* a, mp_int* r)
  8728. {
  8729. int err;
  8730. err = mp_grow(r, (3072 + DIGIT_BIT - 1) / DIGIT_BIT);
  8731. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  8732. #if DIGIT_BIT == 60
  8733. XMEMCPY(r->dp, a, sizeof(sp_digit) * 52);
  8734. r->used = 52;
  8735. mp_clamp(r);
  8736. #elif DIGIT_BIT < 60
  8737. int i;
  8738. int j = 0;
  8739. int s = 0;
  8740. r->dp[0] = 0;
  8741. for (i = 0; i < 52; i++) {
  8742. r->dp[j] |= (mp_digit)(a[i] << s);
  8743. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  8744. s = DIGIT_BIT - s;
  8745. r->dp[++j] = (mp_digit)(a[i] >> s);
  8746. while (s + DIGIT_BIT <= 60) {
  8747. s += DIGIT_BIT;
  8748. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  8749. if (s == SP_WORD_SIZE) {
  8750. r->dp[j] = 0;
  8751. }
  8752. else {
  8753. r->dp[j] = (mp_digit)(a[i] >> s);
  8754. }
  8755. }
  8756. s = 60 - s;
  8757. }
  8758. r->used = (3072 + DIGIT_BIT - 1) / DIGIT_BIT;
  8759. mp_clamp(r);
  8760. #else
  8761. int i;
  8762. int j = 0;
  8763. int s = 0;
  8764. r->dp[0] = 0;
  8765. for (i = 0; i < 52; i++) {
  8766. r->dp[j] |= ((mp_digit)a[i]) << s;
  8767. if (s + 60 >= DIGIT_BIT) {
  8768. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  8769. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  8770. #endif
  8771. s = DIGIT_BIT - s;
  8772. r->dp[++j] = a[i] >> s;
  8773. s = 60 - s;
  8774. }
  8775. else {
  8776. s += 60;
  8777. }
  8778. }
  8779. r->used = (3072 + DIGIT_BIT - 1) / DIGIT_BIT;
  8780. mp_clamp(r);
  8781. #endif
  8782. }
  8783. return err;
  8784. }
  8785. /* Perform the modular exponentiation for Diffie-Hellman.
  8786. *
  8787. * base Base. MP integer.
  8788. * exp Exponent. MP integer.
  8789. * mod Modulus. MP integer.
  8790. * res Result. MP integer.
  8791. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  8792. * and MEMORY_E if memory allocation fails.
  8793. */
  8794. int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod,
  8795. mp_int* res)
  8796. {
  8797. #ifdef WOLFSSL_SP_SMALL
  8798. int err = MP_OKAY;
  8799. #ifdef WOLFSSL_SP_SMALL_STACK
  8800. sp_digit* b = NULL;
  8801. #else
  8802. sp_digit b[52 * 4];
  8803. #endif
  8804. sp_digit* e = NULL;
  8805. sp_digit* m = NULL;
  8806. sp_digit* r = NULL;
  8807. int expBits = mp_count_bits(exp);
  8808. if (mp_count_bits(base) > 3072) {
  8809. err = MP_READ_E;
  8810. }
  8811. else if (expBits > 3072) {
  8812. err = MP_READ_E;
  8813. }
  8814. else if (mp_count_bits(mod) != 3072) {
  8815. err = MP_READ_E;
  8816. }
  8817. else if (mp_iseven(mod)) {
  8818. err = MP_VAL;
  8819. }
  8820. #ifdef WOLFSSL_SP_SMALL_STACK
  8821. if (err == MP_OKAY) {
  8822. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL,
  8823. DYNAMIC_TYPE_DH);
  8824. if (b == NULL)
  8825. err = MEMORY_E;
  8826. }
  8827. #endif
  8828. if (err == MP_OKAY) {
  8829. e = b + 52 * 2;
  8830. m = e + 52;
  8831. r = b;
  8832. sp_3072_from_mp(b, 52, base);
  8833. sp_3072_from_mp(e, 52, exp);
  8834. sp_3072_from_mp(m, 52, mod);
  8835. err = sp_3072_mod_exp_52(r, b, e, mp_count_bits(exp), m, 0);
  8836. }
  8837. if (err == MP_OKAY) {
  8838. err = sp_3072_to_mp(r, res);
  8839. }
  8840. #ifdef WOLFSSL_SP_SMALL_STACK
  8841. if (b != NULL)
  8842. #endif
  8843. {
  8844. /* only "e" is sensitive and needs zeroized */
  8845. if (e != NULL)
  8846. ForceZero(e, sizeof(sp_digit) * 52U);
  8847. #ifdef WOLFSSL_SP_SMALL_STACK
  8848. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  8849. #endif
  8850. }
  8851. return err;
  8852. #else
  8853. #ifdef WOLFSSL_SP_SMALL_STACK
  8854. sp_digit* b = NULL;
  8855. #else
  8856. sp_digit b[52 * 4];
  8857. #endif
  8858. sp_digit* e = NULL;
  8859. sp_digit* m = NULL;
  8860. sp_digit* r = NULL;
  8861. int err = MP_OKAY;
  8862. int expBits = mp_count_bits(exp);
  8863. if (mp_count_bits(base) > 3072) {
  8864. err = MP_READ_E;
  8865. }
  8866. else if (expBits > 3072) {
  8867. err = MP_READ_E;
  8868. }
  8869. else if (mp_count_bits(mod) != 3072) {
  8870. err = MP_READ_E;
  8871. }
  8872. else if (mp_iseven(mod)) {
  8873. err = MP_VAL;
  8874. }
  8875. #ifdef WOLFSSL_SP_SMALL_STACK
  8876. if (err == MP_OKAY) {
  8877. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL, DYNAMIC_TYPE_DH);
  8878. if (b == NULL)
  8879. err = MEMORY_E;
  8880. }
  8881. #endif
  8882. if (err == MP_OKAY) {
  8883. e = b + 52 * 2;
  8884. m = e + 52;
  8885. r = b;
  8886. sp_3072_from_mp(b, 52, base);
  8887. sp_3072_from_mp(e, 52, exp);
  8888. sp_3072_from_mp(m, 52, mod);
  8889. err = sp_3072_mod_exp_52(r, b, e, expBits, m, 0);
  8890. }
  8891. if (err == MP_OKAY) {
  8892. err = sp_3072_to_mp(r, res);
  8893. }
  8894. #ifdef WOLFSSL_SP_SMALL_STACK
  8895. if (b != NULL)
  8896. #endif
  8897. {
  8898. /* only "e" is sensitive and needs zeroized */
  8899. if (e != NULL)
  8900. ForceZero(e, sizeof(sp_digit) * 52U);
  8901. #ifdef WOLFSSL_SP_SMALL_STACK
  8902. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  8903. #endif
  8904. }
  8905. return err;
  8906. #endif
  8907. }
  8908. #ifdef WOLFSSL_HAVE_SP_DH
  8909. #ifdef HAVE_FFDHE_3072
  8910. SP_NOINLINE static void sp_3072_lshift_52(sp_digit* r, const sp_digit* a,
  8911. byte n)
  8912. {
  8913. int i;
  8914. r[52] = a[51] >> (60 - n);
  8915. for (i=51; i>0; i--) {
  8916. r[i] = ((a[i] << n) | (a[i-1] >> (60 - n))) & 0xfffffffffffffffL;
  8917. }
  8918. r[0] = (a[0] << n) & 0xfffffffffffffffL;
  8919. }
  8920. /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m)
  8921. *
  8922. * r A single precision number that is the result of the operation.
  8923. * e A single precision number that is the exponent.
  8924. * bits The number of bits in the exponent.
  8925. * m A single precision number that is the modulus.
  8926. * returns 0 on success.
  8927. * returns MEMORY_E on dynamic memory allocation failure.
  8928. * returns MP_VAL when base is even.
  8929. */
  8930. static int sp_3072_mod_exp_2_52(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
  8931. {
  8932. #ifdef WOLFSSL_SP_SMALL_STACK
  8933. sp_digit* td = NULL;
  8934. #else
  8935. sp_digit td[157];
  8936. #endif
  8937. sp_digit* norm = NULL;
  8938. sp_digit* tmp = NULL;
  8939. sp_digit mp = 1;
  8940. sp_digit n;
  8941. sp_digit o;
  8942. int i;
  8943. int c;
  8944. byte y;
  8945. int err = MP_OKAY;
  8946. if (bits == 0) {
  8947. err = MP_VAL;
  8948. }
  8949. #ifdef WOLFSSL_SP_SMALL_STACK
  8950. if (err == MP_OKAY) {
  8951. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 157, NULL,
  8952. DYNAMIC_TYPE_TMP_BUFFER);
  8953. if (td == NULL)
  8954. err = MEMORY_E;
  8955. }
  8956. #endif
  8957. if (err == MP_OKAY) {
  8958. norm = td;
  8959. tmp = td + 104;
  8960. XMEMSET(td, 0, sizeof(sp_digit) * 157);
  8961. sp_3072_mont_setup(m, &mp);
  8962. sp_3072_mont_norm_52(norm, m);
  8963. bits = ((bits + 4) / 5) * 5;
  8964. i = ((bits + 59) / 60) - 1;
  8965. c = bits % 60;
  8966. if (c == 0) {
  8967. c = 60;
  8968. }
  8969. if (i < 52) {
  8970. n = e[i--] << (64 - c);
  8971. }
  8972. else {
  8973. n = 0;
  8974. i--;
  8975. }
  8976. if (c < 5) {
  8977. n |= e[i--] << (4 - c);
  8978. c += 60;
  8979. }
  8980. y = (int)((n >> 59) & 0x1f);
  8981. n <<= 5;
  8982. c -= 5;
  8983. sp_3072_lshift_52(r, norm, (byte)y);
  8984. while ((i >= 0) || (c >= 5)) {
  8985. if (c >= 5) {
  8986. y = (byte)((n >> 59) & 0x1f);
  8987. n <<= 5;
  8988. c -= 5;
  8989. }
  8990. else if (c == 0) {
  8991. n = e[i--] << 4;
  8992. y = (byte)((n >> 59) & 0x1f);
  8993. n <<= 5;
  8994. c = 55;
  8995. }
  8996. else {
  8997. y = (byte)((n >> 59) & 0x1f);
  8998. n = e[i--] << 4;
  8999. c = 5 - c;
  9000. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  9001. n <<= c;
  9002. c = 60 - c;
  9003. }
  9004. sp_3072_mont_sqr_52(r, r, m, mp);
  9005. sp_3072_mont_sqr_52(r, r, m, mp);
  9006. sp_3072_mont_sqr_52(r, r, m, mp);
  9007. sp_3072_mont_sqr_52(r, r, m, mp);
  9008. sp_3072_mont_sqr_52(r, r, m, mp);
  9009. sp_3072_lshift_52(r, r, (byte)y);
  9010. sp_3072_mul_d_52(tmp, norm, (r[52] << 48) + (r[51] >> 12));
  9011. r[52] = 0;
  9012. r[51] &= 0xfffL;
  9013. (void)sp_3072_add_52(r, r, tmp);
  9014. sp_3072_norm_52(r);
  9015. o = sp_3072_cmp_52(r, m);
  9016. sp_3072_cond_sub_52(r, r, m, ~(o >> 63));
  9017. }
  9018. sp_3072_mont_reduce_52(r, m, mp);
  9019. n = sp_3072_cmp_52(r, m);
  9020. sp_3072_cond_sub_52(r, r, m, ~(n >> 63));
  9021. }
  9022. #ifdef WOLFSSL_SP_SMALL_STACK
  9023. if (td != NULL)
  9024. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  9025. #endif
  9026. return err;
  9027. }
  9028. #endif /* HAVE_FFDHE_3072 */
  9029. /* Perform the modular exponentiation for Diffie-Hellman.
  9030. *
  9031. * base Base.
  9032. * exp Array of bytes that is the exponent.
  9033. * expLen Length of data, in bytes, in exponent.
  9034. * mod Modulus.
  9035. * out Buffer to hold big-endian bytes of exponentiation result.
  9036. * Must be at least 384 bytes long.
  9037. * outLen Length, in bytes, of exponentiation result.
  9038. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  9039. * and MEMORY_E if memory allocation fails.
  9040. */
  9041. int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen,
  9042. const mp_int* mod, byte* out, word32* outLen)
  9043. {
  9044. #ifdef WOLFSSL_SP_SMALL_STACK
  9045. sp_digit* b = NULL;
  9046. #else
  9047. sp_digit b[52 * 4];
  9048. #endif
  9049. sp_digit* e = NULL;
  9050. sp_digit* m = NULL;
  9051. sp_digit* r = NULL;
  9052. word32 i;
  9053. int err = MP_OKAY;
  9054. if (mp_count_bits(base) > 3072) {
  9055. err = MP_READ_E;
  9056. }
  9057. else if (expLen > 384U) {
  9058. err = MP_READ_E;
  9059. }
  9060. else if (mp_count_bits(mod) != 3072) {
  9061. err = MP_READ_E;
  9062. }
  9063. else if (mp_iseven(mod)) {
  9064. err = MP_VAL;
  9065. }
  9066. #ifdef WOLFSSL_SP_SMALL_STACK
  9067. if (err == MP_OKAY) {
  9068. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL,
  9069. DYNAMIC_TYPE_DH);
  9070. if (b == NULL)
  9071. err = MEMORY_E;
  9072. }
  9073. #endif
  9074. if (err == MP_OKAY) {
  9075. e = b + 52 * 2;
  9076. m = e + 52;
  9077. r = b;
  9078. sp_3072_from_mp(b, 52, base);
  9079. sp_3072_from_bin(e, 52, exp, expLen);
  9080. sp_3072_from_mp(m, 52, mod);
  9081. #ifdef HAVE_FFDHE_3072
  9082. if (base->used == 1 && base->dp[0] == 2U &&
  9083. ((m[51] << 20) | (m[50] >> 40)) == 0xffffffffL) {
  9084. err = sp_3072_mod_exp_2_52(r, e, expLen * 8U, m);
  9085. }
  9086. else {
  9087. #endif
  9088. err = sp_3072_mod_exp_52(r, b, e, expLen * 8U, m, 0);
  9089. #ifdef HAVE_FFDHE_3072
  9090. }
  9091. #endif
  9092. }
  9093. if (err == MP_OKAY) {
  9094. sp_3072_to_bin_52(r, out);
  9095. *outLen = 384;
  9096. for (i=0; i<384U && out[i] == 0U; i++) {
  9097. /* Search for first non-zero. */
  9098. }
  9099. *outLen -= i;
  9100. XMEMMOVE(out, out + i, *outLen);
  9101. }
  9102. #ifdef WOLFSSL_SP_SMALL_STACK
  9103. if (b != NULL)
  9104. #endif
  9105. {
  9106. /* only "e" is sensitive and needs zeroized */
  9107. if (e != NULL)
  9108. ForceZero(e, sizeof(sp_digit) * 52U);
  9109. #ifdef WOLFSSL_SP_SMALL_STACK
  9110. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  9111. #endif
  9112. }
  9113. return err;
  9114. }
  9115. #endif /* WOLFSSL_HAVE_SP_DH */
  9116. /* Perform the modular exponentiation for Diffie-Hellman.
  9117. *
  9118. * base Base. MP integer.
  9119. * exp Exponent. MP integer.
  9120. * mod Modulus. MP integer.
  9121. * res Result. MP integer.
  9122. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  9123. * and MEMORY_E if memory allocation fails.
  9124. */
  9125. int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod,
  9126. mp_int* res)
  9127. {
  9128. #ifdef WOLFSSL_SP_SMALL
  9129. int err = MP_OKAY;
  9130. #ifdef WOLFSSL_SP_SMALL_STACK
  9131. sp_digit* b = NULL;
  9132. #else
  9133. sp_digit b[26 * 4];
  9134. #endif
  9135. sp_digit* e = NULL;
  9136. sp_digit* m = NULL;
  9137. sp_digit* r = NULL;
  9138. int expBits = mp_count_bits(exp);
  9139. if (mp_count_bits(base) > 1536) {
  9140. err = MP_READ_E;
  9141. }
  9142. else if (expBits > 1536) {
  9143. err = MP_READ_E;
  9144. }
  9145. else if (mp_count_bits(mod) != 1536) {
  9146. err = MP_READ_E;
  9147. }
  9148. else if (mp_iseven(mod)) {
  9149. err = MP_VAL;
  9150. }
  9151. #ifdef WOLFSSL_SP_SMALL_STACK
  9152. if (err == MP_OKAY) {
  9153. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 4, NULL,
  9154. DYNAMIC_TYPE_DH);
  9155. if (b == NULL)
  9156. err = MEMORY_E;
  9157. }
  9158. #endif
  9159. if (err == MP_OKAY) {
  9160. e = b + 26 * 2;
  9161. m = e + 26;
  9162. r = b;
  9163. sp_3072_from_mp(b, 26, base);
  9164. sp_3072_from_mp(e, 26, exp);
  9165. sp_3072_from_mp(m, 26, mod);
  9166. err = sp_3072_mod_exp_26(r, b, e, mp_count_bits(exp), m, 0);
  9167. }
  9168. if (err == MP_OKAY) {
  9169. XMEMSET(r + 26, 0, sizeof(*r) * 26U);
  9170. err = sp_3072_to_mp(r, res);
  9171. }
  9172. #ifdef WOLFSSL_SP_SMALL_STACK
  9173. if (b != NULL)
  9174. #endif
  9175. {
  9176. /* only "e" is sensitive and needs zeroized */
  9177. if (e != NULL)
  9178. ForceZero(e, sizeof(sp_digit) * 52U);
  9179. #ifdef WOLFSSL_SP_SMALL_STACK
  9180. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  9181. #endif
  9182. }
  9183. return err;
  9184. #else
  9185. #ifdef WOLFSSL_SP_SMALL_STACK
  9186. sp_digit* b = NULL;
  9187. #else
  9188. sp_digit b[26 * 4];
  9189. #endif
  9190. sp_digit* e = NULL;
  9191. sp_digit* m = NULL;
  9192. sp_digit* r = NULL;
  9193. int err = MP_OKAY;
  9194. int expBits = mp_count_bits(exp);
  9195. if (mp_count_bits(base) > 1536) {
  9196. err = MP_READ_E;
  9197. }
  9198. else if (expBits > 1536) {
  9199. err = MP_READ_E;
  9200. }
  9201. else if (mp_count_bits(mod) != 1536) {
  9202. err = MP_READ_E;
  9203. }
  9204. else if (mp_iseven(mod)) {
  9205. err = MP_VAL;
  9206. }
  9207. #ifdef WOLFSSL_SP_SMALL_STACK
  9208. if (err == MP_OKAY) {
  9209. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 4, NULL, DYNAMIC_TYPE_DH);
  9210. if (b == NULL)
  9211. err = MEMORY_E;
  9212. }
  9213. #endif
  9214. if (err == MP_OKAY) {
  9215. e = b + 26 * 2;
  9216. m = e + 26;
  9217. r = b;
  9218. sp_3072_from_mp(b, 26, base);
  9219. sp_3072_from_mp(e, 26, exp);
  9220. sp_3072_from_mp(m, 26, mod);
  9221. err = sp_3072_mod_exp_26(r, b, e, expBits, m, 0);
  9222. }
  9223. if (err == MP_OKAY) {
  9224. XMEMSET(r + 26, 0, sizeof(*r) * 26U);
  9225. err = sp_3072_to_mp(r, res);
  9226. }
  9227. #ifdef WOLFSSL_SP_SMALL_STACK
  9228. if (b != NULL)
  9229. #endif
  9230. {
  9231. /* only "e" is sensitive and needs zeroized */
  9232. if (e != NULL)
  9233. ForceZero(e, sizeof(sp_digit) * 52U);
  9234. #ifdef WOLFSSL_SP_SMALL_STACK
  9235. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  9236. #endif
  9237. }
  9238. return err;
  9239. #endif
  9240. }
  9241. #endif /* WOLFSSL_HAVE_SP_DH | (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) */
  9242. #else
  9243. /* Read big endian unsigned byte array into r.
  9244. *
  9245. * r A single precision integer.
  9246. * size Maximum number of bytes to convert
  9247. * a Byte array.
  9248. * n Number of bytes in array to read.
  9249. */
  9250. static void sp_3072_from_bin(sp_digit* r, int size, const byte* a, int n)
  9251. {
  9252. int i;
  9253. int j = 0;
  9254. word32 s = 0;
  9255. r[0] = 0;
  9256. for (i = n-1; i >= 0; i--) {
  9257. r[j] |= (((sp_digit)a[i]) << s);
  9258. if (s >= 49U) {
  9259. r[j] &= 0x1ffffffffffffffL;
  9260. s = 57U - s;
  9261. if (j + 1 >= size) {
  9262. break;
  9263. }
  9264. r[++j] = (sp_digit)a[i] >> s;
  9265. s = 8U - s;
  9266. }
  9267. else {
  9268. s += 8U;
  9269. }
  9270. }
  9271. for (j++; j < size; j++) {
  9272. r[j] = 0;
  9273. }
  9274. }
  9275. /* Convert an mp_int to an array of sp_digit.
  9276. *
  9277. * r A single precision integer.
  9278. * size Maximum number of bytes to convert
  9279. * a A multi-precision integer.
  9280. */
  9281. static void sp_3072_from_mp(sp_digit* r, int size, const mp_int* a)
  9282. {
  9283. #if DIGIT_BIT == 57
  9284. int i;
  9285. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  9286. int o = 0;
  9287. for (i = 0; i < size; i++) {
  9288. sp_digit mask = (sp_digit)0 - (j >> 56);
  9289. r[i] = a->dp[o] & mask;
  9290. j++;
  9291. o += (int)(j >> 56);
  9292. }
  9293. #elif DIGIT_BIT > 57
  9294. unsigned int i;
  9295. int j = 0;
  9296. word32 s = 0;
  9297. r[0] = 0;
  9298. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  9299. r[j] |= ((sp_digit)a->dp[i] << s);
  9300. r[j] &= 0x1ffffffffffffffL;
  9301. s = 57U - s;
  9302. if (j + 1 >= size) {
  9303. break;
  9304. }
  9305. /* lint allow cast of mismatch word32 and mp_digit */
  9306. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  9307. while ((s + 57U) <= (word32)DIGIT_BIT) {
  9308. s += 57U;
  9309. r[j] &= 0x1ffffffffffffffL;
  9310. if (j + 1 >= size) {
  9311. break;
  9312. }
  9313. if (s < (word32)DIGIT_BIT) {
  9314. /* lint allow cast of mismatch word32 and mp_digit */
  9315. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  9316. }
  9317. else {
  9318. r[++j] = (sp_digit)0;
  9319. }
  9320. }
  9321. s = (word32)DIGIT_BIT - s;
  9322. }
  9323. for (j++; j < size; j++) {
  9324. r[j] = 0;
  9325. }
  9326. #else
  9327. unsigned int i;
  9328. int j = 0;
  9329. int s = 0;
  9330. r[0] = 0;
  9331. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  9332. r[j] |= ((sp_digit)a->dp[i]) << s;
  9333. if (s + DIGIT_BIT >= 57) {
  9334. r[j] &= 0x1ffffffffffffffL;
  9335. if (j + 1 >= size) {
  9336. break;
  9337. }
  9338. s = 57 - s;
  9339. if (s == DIGIT_BIT) {
  9340. r[++j] = 0;
  9341. s = 0;
  9342. }
  9343. else {
  9344. r[++j] = a->dp[i] >> s;
  9345. s = DIGIT_BIT - s;
  9346. }
  9347. }
  9348. else {
  9349. s += DIGIT_BIT;
  9350. }
  9351. }
  9352. for (j++; j < size; j++) {
  9353. r[j] = 0;
  9354. }
  9355. #endif
  9356. }
  9357. /* Write r as big endian to byte array.
  9358. * Fixed length number of bytes written: 384
  9359. *
  9360. * r A single precision integer.
  9361. * a Byte array.
  9362. */
  9363. static void sp_3072_to_bin_54(sp_digit* r, byte* a)
  9364. {
  9365. int i;
  9366. int j;
  9367. int s = 0;
  9368. int b;
  9369. for (i=0; i<53; i++) {
  9370. r[i+1] += r[i] >> 57;
  9371. r[i] &= 0x1ffffffffffffffL;
  9372. }
  9373. j = 3079 / 8 - 1;
  9374. a[j] = 0;
  9375. for (i=0; i<54 && j>=0; i++) {
  9376. b = 0;
  9377. /* lint allow cast of mismatch sp_digit and int */
  9378. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  9379. b += 8 - s;
  9380. if (j < 0) {
  9381. break;
  9382. }
  9383. while (b < 57) {
  9384. a[j--] = (byte)(r[i] >> b);
  9385. b += 8;
  9386. if (j < 0) {
  9387. break;
  9388. }
  9389. }
  9390. s = 8 - (b - 57);
  9391. if (j >= 0) {
  9392. a[j] = 0;
  9393. }
  9394. if (s != 0) {
  9395. j++;
  9396. }
  9397. }
  9398. }
  9399. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  9400. /* Normalize the values in each word to 57 bits.
  9401. *
  9402. * a Array of sp_digit to normalize.
  9403. */
  9404. static void sp_3072_norm_27(sp_digit* a)
  9405. {
  9406. int i;
  9407. for (i = 0; i < 24; i += 8) {
  9408. a[i+1] += a[i+0] >> 57; a[i+0] &= 0x1ffffffffffffffL;
  9409. a[i+2] += a[i+1] >> 57; a[i+1] &= 0x1ffffffffffffffL;
  9410. a[i+3] += a[i+2] >> 57; a[i+2] &= 0x1ffffffffffffffL;
  9411. a[i+4] += a[i+3] >> 57; a[i+3] &= 0x1ffffffffffffffL;
  9412. a[i+5] += a[i+4] >> 57; a[i+4] &= 0x1ffffffffffffffL;
  9413. a[i+6] += a[i+5] >> 57; a[i+5] &= 0x1ffffffffffffffL;
  9414. a[i+7] += a[i+6] >> 57; a[i+6] &= 0x1ffffffffffffffL;
  9415. a[i+8] += a[i+7] >> 57; a[i+7] &= 0x1ffffffffffffffL;
  9416. }
  9417. a[25] += a[24] >> 57; a[24] &= 0x1ffffffffffffffL;
  9418. a[26] += a[25] >> 57; a[25] &= 0x1ffffffffffffffL;
  9419. }
  9420. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  9421. /* Normalize the values in each word to 57 bits.
  9422. *
  9423. * a Array of sp_digit to normalize.
  9424. */
  9425. static void sp_3072_norm_54(sp_digit* a)
  9426. {
  9427. int i;
  9428. for (i = 0; i < 48; i += 8) {
  9429. a[i+1] += a[i+0] >> 57; a[i+0] &= 0x1ffffffffffffffL;
  9430. a[i+2] += a[i+1] >> 57; a[i+1] &= 0x1ffffffffffffffL;
  9431. a[i+3] += a[i+2] >> 57; a[i+2] &= 0x1ffffffffffffffL;
  9432. a[i+4] += a[i+3] >> 57; a[i+3] &= 0x1ffffffffffffffL;
  9433. a[i+5] += a[i+4] >> 57; a[i+4] &= 0x1ffffffffffffffL;
  9434. a[i+6] += a[i+5] >> 57; a[i+5] &= 0x1ffffffffffffffL;
  9435. a[i+7] += a[i+6] >> 57; a[i+6] &= 0x1ffffffffffffffL;
  9436. a[i+8] += a[i+7] >> 57; a[i+7] &= 0x1ffffffffffffffL;
  9437. }
  9438. a[49] += a[48] >> 57; a[48] &= 0x1ffffffffffffffL;
  9439. a[50] += a[49] >> 57; a[49] &= 0x1ffffffffffffffL;
  9440. a[51] += a[50] >> 57; a[50] &= 0x1ffffffffffffffL;
  9441. a[52] += a[51] >> 57; a[51] &= 0x1ffffffffffffffL;
  9442. a[53] += a[52] >> 57; a[52] &= 0x1ffffffffffffffL;
  9443. }
  9444. #ifndef WOLFSSL_SP_SMALL
  9445. /* Multiply a and b into r. (r = a * b)
  9446. *
  9447. * r A single precision integer.
  9448. * a A single precision integer.
  9449. * b A single precision integer.
  9450. */
  9451. SP_NOINLINE static void sp_3072_mul_9(sp_digit* r, const sp_digit* a,
  9452. const sp_digit* b)
  9453. {
  9454. sp_uint128 t0;
  9455. sp_uint128 t1;
  9456. sp_digit t[9];
  9457. t0 = ((sp_uint128)a[ 0]) * b[ 0];
  9458. t1 = ((sp_uint128)a[ 0]) * b[ 1]
  9459. + ((sp_uint128)a[ 1]) * b[ 0];
  9460. t[ 0] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9461. t0 = ((sp_uint128)a[ 0]) * b[ 2]
  9462. + ((sp_uint128)a[ 1]) * b[ 1]
  9463. + ((sp_uint128)a[ 2]) * b[ 0];
  9464. t[ 1] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9465. t1 = ((sp_uint128)a[ 0]) * b[ 3]
  9466. + ((sp_uint128)a[ 1]) * b[ 2]
  9467. + ((sp_uint128)a[ 2]) * b[ 1]
  9468. + ((sp_uint128)a[ 3]) * b[ 0];
  9469. t[ 2] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9470. t0 = ((sp_uint128)a[ 0]) * b[ 4]
  9471. + ((sp_uint128)a[ 1]) * b[ 3]
  9472. + ((sp_uint128)a[ 2]) * b[ 2]
  9473. + ((sp_uint128)a[ 3]) * b[ 1]
  9474. + ((sp_uint128)a[ 4]) * b[ 0];
  9475. t[ 3] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9476. t1 = ((sp_uint128)a[ 0]) * b[ 5]
  9477. + ((sp_uint128)a[ 1]) * b[ 4]
  9478. + ((sp_uint128)a[ 2]) * b[ 3]
  9479. + ((sp_uint128)a[ 3]) * b[ 2]
  9480. + ((sp_uint128)a[ 4]) * b[ 1]
  9481. + ((sp_uint128)a[ 5]) * b[ 0];
  9482. t[ 4] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9483. t0 = ((sp_uint128)a[ 0]) * b[ 6]
  9484. + ((sp_uint128)a[ 1]) * b[ 5]
  9485. + ((sp_uint128)a[ 2]) * b[ 4]
  9486. + ((sp_uint128)a[ 3]) * b[ 3]
  9487. + ((sp_uint128)a[ 4]) * b[ 2]
  9488. + ((sp_uint128)a[ 5]) * b[ 1]
  9489. + ((sp_uint128)a[ 6]) * b[ 0];
  9490. t[ 5] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9491. t1 = ((sp_uint128)a[ 0]) * b[ 7]
  9492. + ((sp_uint128)a[ 1]) * b[ 6]
  9493. + ((sp_uint128)a[ 2]) * b[ 5]
  9494. + ((sp_uint128)a[ 3]) * b[ 4]
  9495. + ((sp_uint128)a[ 4]) * b[ 3]
  9496. + ((sp_uint128)a[ 5]) * b[ 2]
  9497. + ((sp_uint128)a[ 6]) * b[ 1]
  9498. + ((sp_uint128)a[ 7]) * b[ 0];
  9499. t[ 6] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9500. t0 = ((sp_uint128)a[ 0]) * b[ 8]
  9501. + ((sp_uint128)a[ 1]) * b[ 7]
  9502. + ((sp_uint128)a[ 2]) * b[ 6]
  9503. + ((sp_uint128)a[ 3]) * b[ 5]
  9504. + ((sp_uint128)a[ 4]) * b[ 4]
  9505. + ((sp_uint128)a[ 5]) * b[ 3]
  9506. + ((sp_uint128)a[ 6]) * b[ 2]
  9507. + ((sp_uint128)a[ 7]) * b[ 1]
  9508. + ((sp_uint128)a[ 8]) * b[ 0];
  9509. t[ 7] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9510. t1 = ((sp_uint128)a[ 1]) * b[ 8]
  9511. + ((sp_uint128)a[ 2]) * b[ 7]
  9512. + ((sp_uint128)a[ 3]) * b[ 6]
  9513. + ((sp_uint128)a[ 4]) * b[ 5]
  9514. + ((sp_uint128)a[ 5]) * b[ 4]
  9515. + ((sp_uint128)a[ 6]) * b[ 3]
  9516. + ((sp_uint128)a[ 7]) * b[ 2]
  9517. + ((sp_uint128)a[ 8]) * b[ 1];
  9518. t[ 8] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9519. t0 = ((sp_uint128)a[ 2]) * b[ 8]
  9520. + ((sp_uint128)a[ 3]) * b[ 7]
  9521. + ((sp_uint128)a[ 4]) * b[ 6]
  9522. + ((sp_uint128)a[ 5]) * b[ 5]
  9523. + ((sp_uint128)a[ 6]) * b[ 4]
  9524. + ((sp_uint128)a[ 7]) * b[ 3]
  9525. + ((sp_uint128)a[ 8]) * b[ 2];
  9526. r[ 9] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9527. t1 = ((sp_uint128)a[ 3]) * b[ 8]
  9528. + ((sp_uint128)a[ 4]) * b[ 7]
  9529. + ((sp_uint128)a[ 5]) * b[ 6]
  9530. + ((sp_uint128)a[ 6]) * b[ 5]
  9531. + ((sp_uint128)a[ 7]) * b[ 4]
  9532. + ((sp_uint128)a[ 8]) * b[ 3];
  9533. r[10] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9534. t0 = ((sp_uint128)a[ 4]) * b[ 8]
  9535. + ((sp_uint128)a[ 5]) * b[ 7]
  9536. + ((sp_uint128)a[ 6]) * b[ 6]
  9537. + ((sp_uint128)a[ 7]) * b[ 5]
  9538. + ((sp_uint128)a[ 8]) * b[ 4];
  9539. r[11] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9540. t1 = ((sp_uint128)a[ 5]) * b[ 8]
  9541. + ((sp_uint128)a[ 6]) * b[ 7]
  9542. + ((sp_uint128)a[ 7]) * b[ 6]
  9543. + ((sp_uint128)a[ 8]) * b[ 5];
  9544. r[12] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9545. t0 = ((sp_uint128)a[ 6]) * b[ 8]
  9546. + ((sp_uint128)a[ 7]) * b[ 7]
  9547. + ((sp_uint128)a[ 8]) * b[ 6];
  9548. r[13] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9549. t1 = ((sp_uint128)a[ 7]) * b[ 8]
  9550. + ((sp_uint128)a[ 8]) * b[ 7];
  9551. r[14] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9552. t0 = ((sp_uint128)a[ 8]) * b[ 8];
  9553. r[15] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9554. r[16] = t0 & 0x1ffffffffffffffL;
  9555. r[17] = (sp_digit)(t0 >> 57);
  9556. XMEMCPY(r, t, sizeof(t));
  9557. }
  9558. /* Add b to a into r. (r = a + b)
  9559. *
  9560. * r A single precision integer.
  9561. * a A single precision integer.
  9562. * b A single precision integer.
  9563. */
  9564. SP_NOINLINE static int sp_3072_add_9(sp_digit* r, const sp_digit* a,
  9565. const sp_digit* b)
  9566. {
  9567. r[ 0] = a[ 0] + b[ 0];
  9568. r[ 1] = a[ 1] + b[ 1];
  9569. r[ 2] = a[ 2] + b[ 2];
  9570. r[ 3] = a[ 3] + b[ 3];
  9571. r[ 4] = a[ 4] + b[ 4];
  9572. r[ 5] = a[ 5] + b[ 5];
  9573. r[ 6] = a[ 6] + b[ 6];
  9574. r[ 7] = a[ 7] + b[ 7];
  9575. r[ 8] = a[ 8] + b[ 8];
  9576. return 0;
  9577. }
  9578. /* Sub b from a into r. (r = a - b)
  9579. *
  9580. * r A single precision integer.
  9581. * a A single precision integer.
  9582. * b A single precision integer.
  9583. */
  9584. SP_NOINLINE static int sp_3072_sub_18(sp_digit* r, const sp_digit* a,
  9585. const sp_digit* b)
  9586. {
  9587. int i;
  9588. for (i = 0; i < 16; i += 8) {
  9589. r[i + 0] = a[i + 0] - b[i + 0];
  9590. r[i + 1] = a[i + 1] - b[i + 1];
  9591. r[i + 2] = a[i + 2] - b[i + 2];
  9592. r[i + 3] = a[i + 3] - b[i + 3];
  9593. r[i + 4] = a[i + 4] - b[i + 4];
  9594. r[i + 5] = a[i + 5] - b[i + 5];
  9595. r[i + 6] = a[i + 6] - b[i + 6];
  9596. r[i + 7] = a[i + 7] - b[i + 7];
  9597. }
  9598. r[16] = a[16] - b[16];
  9599. r[17] = a[17] - b[17];
  9600. return 0;
  9601. }
  9602. /* Add b to a into r. (r = a + b)
  9603. *
  9604. * r A single precision integer.
  9605. * a A single precision integer.
  9606. * b A single precision integer.
  9607. */
  9608. SP_NOINLINE static int sp_3072_add_18(sp_digit* r, const sp_digit* a,
  9609. const sp_digit* b)
  9610. {
  9611. int i;
  9612. for (i = 0; i < 16; i += 8) {
  9613. r[i + 0] = a[i + 0] + b[i + 0];
  9614. r[i + 1] = a[i + 1] + b[i + 1];
  9615. r[i + 2] = a[i + 2] + b[i + 2];
  9616. r[i + 3] = a[i + 3] + b[i + 3];
  9617. r[i + 4] = a[i + 4] + b[i + 4];
  9618. r[i + 5] = a[i + 5] + b[i + 5];
  9619. r[i + 6] = a[i + 6] + b[i + 6];
  9620. r[i + 7] = a[i + 7] + b[i + 7];
  9621. }
  9622. r[16] = a[16] + b[16];
  9623. r[17] = a[17] + b[17];
  9624. return 0;
  9625. }
  9626. /* Multiply a and b into r. (r = a * b)
  9627. *
  9628. * r A single precision integer.
  9629. * a A single precision integer.
  9630. * b A single precision integer.
  9631. */
  9632. SP_NOINLINE static void sp_3072_mul_27(sp_digit* r, const sp_digit* a,
  9633. const sp_digit* b)
  9634. {
  9635. sp_digit p0[18];
  9636. sp_digit p1[18];
  9637. sp_digit p2[18];
  9638. sp_digit p3[18];
  9639. sp_digit p4[18];
  9640. sp_digit p5[18];
  9641. sp_digit t0[18];
  9642. sp_digit t1[18];
  9643. sp_digit t2[18];
  9644. sp_digit a0[9];
  9645. sp_digit a1[9];
  9646. sp_digit a2[9];
  9647. sp_digit b0[9];
  9648. sp_digit b1[9];
  9649. sp_digit b2[9];
  9650. (void)sp_3072_add_9(a0, a, &a[9]);
  9651. (void)sp_3072_add_9(b0, b, &b[9]);
  9652. (void)sp_3072_add_9(a1, &a[9], &a[18]);
  9653. (void)sp_3072_add_9(b1, &b[9], &b[18]);
  9654. (void)sp_3072_add_9(a2, a0, &a[18]);
  9655. (void)sp_3072_add_9(b2, b0, &b[18]);
  9656. sp_3072_mul_9(p0, a, b);
  9657. sp_3072_mul_9(p2, &a[9], &b[9]);
  9658. sp_3072_mul_9(p4, &a[18], &b[18]);
  9659. sp_3072_mul_9(p1, a0, b0);
  9660. sp_3072_mul_9(p3, a1, b1);
  9661. sp_3072_mul_9(p5, a2, b2);
  9662. XMEMSET(r, 0, sizeof(*r)*2U*27U);
  9663. (void)sp_3072_sub_18(t0, p3, p2);
  9664. (void)sp_3072_sub_18(t1, p1, p2);
  9665. (void)sp_3072_sub_18(t2, p5, t0);
  9666. (void)sp_3072_sub_18(t2, t2, t1);
  9667. (void)sp_3072_sub_18(t0, t0, p4);
  9668. (void)sp_3072_sub_18(t1, t1, p0);
  9669. (void)sp_3072_add_18(r, r, p0);
  9670. (void)sp_3072_add_18(&r[9], &r[9], t1);
  9671. (void)sp_3072_add_18(&r[18], &r[18], t2);
  9672. (void)sp_3072_add_18(&r[27], &r[27], t0);
  9673. (void)sp_3072_add_18(&r[36], &r[36], p4);
  9674. }
  9675. /* Add b to a into r. (r = a + b)
  9676. *
  9677. * r A single precision integer.
  9678. * a A single precision integer.
  9679. * b A single precision integer.
  9680. */
  9681. SP_NOINLINE static int sp_3072_add_27(sp_digit* r, const sp_digit* a,
  9682. const sp_digit* b)
  9683. {
  9684. int i;
  9685. for (i = 0; i < 24; i += 8) {
  9686. r[i + 0] = a[i + 0] + b[i + 0];
  9687. r[i + 1] = a[i + 1] + b[i + 1];
  9688. r[i + 2] = a[i + 2] + b[i + 2];
  9689. r[i + 3] = a[i + 3] + b[i + 3];
  9690. r[i + 4] = a[i + 4] + b[i + 4];
  9691. r[i + 5] = a[i + 5] + b[i + 5];
  9692. r[i + 6] = a[i + 6] + b[i + 6];
  9693. r[i + 7] = a[i + 7] + b[i + 7];
  9694. }
  9695. r[24] = a[24] + b[24];
  9696. r[25] = a[25] + b[25];
  9697. r[26] = a[26] + b[26];
  9698. return 0;
  9699. }
  9700. /* Add b to a into r. (r = a + b)
  9701. *
  9702. * r A single precision integer.
  9703. * a A single precision integer.
  9704. * b A single precision integer.
  9705. */
  9706. SP_NOINLINE static int sp_3072_add_54(sp_digit* r, const sp_digit* a,
  9707. const sp_digit* b)
  9708. {
  9709. int i;
  9710. for (i = 0; i < 48; i += 8) {
  9711. r[i + 0] = a[i + 0] + b[i + 0];
  9712. r[i + 1] = a[i + 1] + b[i + 1];
  9713. r[i + 2] = a[i + 2] + b[i + 2];
  9714. r[i + 3] = a[i + 3] + b[i + 3];
  9715. r[i + 4] = a[i + 4] + b[i + 4];
  9716. r[i + 5] = a[i + 5] + b[i + 5];
  9717. r[i + 6] = a[i + 6] + b[i + 6];
  9718. r[i + 7] = a[i + 7] + b[i + 7];
  9719. }
  9720. r[48] = a[48] + b[48];
  9721. r[49] = a[49] + b[49];
  9722. r[50] = a[50] + b[50];
  9723. r[51] = a[51] + b[51];
  9724. r[52] = a[52] + b[52];
  9725. r[53] = a[53] + b[53];
  9726. return 0;
  9727. }
  9728. /* Sub b from a into r. (r = a - b)
  9729. *
  9730. * r A single precision integer.
  9731. * a A single precision integer.
  9732. * b A single precision integer.
  9733. */
  9734. SP_NOINLINE static int sp_3072_sub_54(sp_digit* r, const sp_digit* a,
  9735. const sp_digit* b)
  9736. {
  9737. int i;
  9738. for (i = 0; i < 48; i += 8) {
  9739. r[i + 0] = a[i + 0] - b[i + 0];
  9740. r[i + 1] = a[i + 1] - b[i + 1];
  9741. r[i + 2] = a[i + 2] - b[i + 2];
  9742. r[i + 3] = a[i + 3] - b[i + 3];
  9743. r[i + 4] = a[i + 4] - b[i + 4];
  9744. r[i + 5] = a[i + 5] - b[i + 5];
  9745. r[i + 6] = a[i + 6] - b[i + 6];
  9746. r[i + 7] = a[i + 7] - b[i + 7];
  9747. }
  9748. r[48] = a[48] - b[48];
  9749. r[49] = a[49] - b[49];
  9750. r[50] = a[50] - b[50];
  9751. r[51] = a[51] - b[51];
  9752. r[52] = a[52] - b[52];
  9753. r[53] = a[53] - b[53];
  9754. return 0;
  9755. }
  9756. /* Multiply a and b into r. (r = a * b)
  9757. *
  9758. * r A single precision integer.
  9759. * a A single precision integer.
  9760. * b A single precision integer.
  9761. */
  9762. SP_NOINLINE static void sp_3072_mul_54(sp_digit* r, const sp_digit* a,
  9763. const sp_digit* b)
  9764. {
  9765. sp_digit* z0 = r;
  9766. sp_digit z1[54];
  9767. sp_digit* a1 = z1;
  9768. sp_digit b1[27];
  9769. sp_digit* z2 = r + 54;
  9770. (void)sp_3072_add_27(a1, a, &a[27]);
  9771. (void)sp_3072_add_27(b1, b, &b[27]);
  9772. sp_3072_mul_27(z2, &a[27], &b[27]);
  9773. sp_3072_mul_27(z0, a, b);
  9774. sp_3072_mul_27(z1, a1, b1);
  9775. (void)sp_3072_sub_54(z1, z1, z2);
  9776. (void)sp_3072_sub_54(z1, z1, z0);
  9777. (void)sp_3072_add_54(r + 27, r + 27, z1);
  9778. }
  9779. /* Square a and put result in r. (r = a * a)
  9780. *
  9781. * r A single precision integer.
  9782. * a A single precision integer.
  9783. */
  9784. SP_NOINLINE static void sp_3072_sqr_9(sp_digit* r, const sp_digit* a)
  9785. {
  9786. sp_uint128 t0;
  9787. sp_uint128 t1;
  9788. sp_digit t[9];
  9789. t0 = ((sp_uint128)a[ 0]) * a[ 0];
  9790. t1 = (((sp_uint128)a[ 0]) * a[ 1]) * 2;
  9791. t[ 0] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9792. t0 = (((sp_uint128)a[ 0]) * a[ 2]) * 2
  9793. + ((sp_uint128)a[ 1]) * a[ 1];
  9794. t[ 1] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9795. t1 = (((sp_uint128)a[ 0]) * a[ 3]
  9796. + ((sp_uint128)a[ 1]) * a[ 2]) * 2;
  9797. t[ 2] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9798. t0 = (((sp_uint128)a[ 0]) * a[ 4]
  9799. + ((sp_uint128)a[ 1]) * a[ 3]) * 2
  9800. + ((sp_uint128)a[ 2]) * a[ 2];
  9801. t[ 3] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9802. t1 = (((sp_uint128)a[ 0]) * a[ 5]
  9803. + ((sp_uint128)a[ 1]) * a[ 4]
  9804. + ((sp_uint128)a[ 2]) * a[ 3]) * 2;
  9805. t[ 4] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9806. t0 = (((sp_uint128)a[ 0]) * a[ 6]
  9807. + ((sp_uint128)a[ 1]) * a[ 5]
  9808. + ((sp_uint128)a[ 2]) * a[ 4]) * 2
  9809. + ((sp_uint128)a[ 3]) * a[ 3];
  9810. t[ 5] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9811. t1 = (((sp_uint128)a[ 0]) * a[ 7]
  9812. + ((sp_uint128)a[ 1]) * a[ 6]
  9813. + ((sp_uint128)a[ 2]) * a[ 5]
  9814. + ((sp_uint128)a[ 3]) * a[ 4]) * 2;
  9815. t[ 6] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9816. t0 = (((sp_uint128)a[ 0]) * a[ 8]
  9817. + ((sp_uint128)a[ 1]) * a[ 7]
  9818. + ((sp_uint128)a[ 2]) * a[ 6]
  9819. + ((sp_uint128)a[ 3]) * a[ 5]) * 2
  9820. + ((sp_uint128)a[ 4]) * a[ 4];
  9821. t[ 7] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9822. t1 = (((sp_uint128)a[ 1]) * a[ 8]
  9823. + ((sp_uint128)a[ 2]) * a[ 7]
  9824. + ((sp_uint128)a[ 3]) * a[ 6]
  9825. + ((sp_uint128)a[ 4]) * a[ 5]) * 2;
  9826. t[ 8] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9827. t0 = (((sp_uint128)a[ 2]) * a[ 8]
  9828. + ((sp_uint128)a[ 3]) * a[ 7]
  9829. + ((sp_uint128)a[ 4]) * a[ 6]) * 2
  9830. + ((sp_uint128)a[ 5]) * a[ 5];
  9831. r[ 9] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9832. t1 = (((sp_uint128)a[ 3]) * a[ 8]
  9833. + ((sp_uint128)a[ 4]) * a[ 7]
  9834. + ((sp_uint128)a[ 5]) * a[ 6]) * 2;
  9835. r[10] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9836. t0 = (((sp_uint128)a[ 4]) * a[ 8]
  9837. + ((sp_uint128)a[ 5]) * a[ 7]) * 2
  9838. + ((sp_uint128)a[ 6]) * a[ 6];
  9839. r[11] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9840. t1 = (((sp_uint128)a[ 5]) * a[ 8]
  9841. + ((sp_uint128)a[ 6]) * a[ 7]) * 2;
  9842. r[12] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9843. t0 = (((sp_uint128)a[ 6]) * a[ 8]) * 2
  9844. + ((sp_uint128)a[ 7]) * a[ 7];
  9845. r[13] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9846. t1 = (((sp_uint128)a[ 7]) * a[ 8]) * 2;
  9847. r[14] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  9848. t0 = ((sp_uint128)a[ 8]) * a[ 8];
  9849. r[15] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  9850. r[16] = t0 & 0x1ffffffffffffffL;
  9851. r[17] = (sp_digit)(t0 >> 57);
  9852. XMEMCPY(r, t, sizeof(t));
  9853. }
  9854. /* Square a into r. (r = a * a)
  9855. *
  9856. * r A single precision integer.
  9857. * a A single precision integer.
  9858. */
  9859. SP_NOINLINE static void sp_3072_sqr_27(sp_digit* r, const sp_digit* a)
  9860. {
  9861. sp_digit p0[18];
  9862. sp_digit p1[18];
  9863. sp_digit p2[18];
  9864. sp_digit p3[18];
  9865. sp_digit p4[18];
  9866. sp_digit p5[18];
  9867. sp_digit t0[18];
  9868. sp_digit t1[18];
  9869. sp_digit t2[18];
  9870. sp_digit a0[9];
  9871. sp_digit a1[9];
  9872. sp_digit a2[9];
  9873. (void)sp_3072_add_9(a0, a, &a[9]);
  9874. (void)sp_3072_add_9(a1, &a[9], &a[18]);
  9875. (void)sp_3072_add_9(a2, a0, &a[18]);
  9876. sp_3072_sqr_9(p0, a);
  9877. sp_3072_sqr_9(p2, &a[9]);
  9878. sp_3072_sqr_9(p4, &a[18]);
  9879. sp_3072_sqr_9(p1, a0);
  9880. sp_3072_sqr_9(p3, a1);
  9881. sp_3072_sqr_9(p5, a2);
  9882. XMEMSET(r, 0, sizeof(*r)*2U*27U);
  9883. (void)sp_3072_sub_18(t0, p3, p2);
  9884. (void)sp_3072_sub_18(t1, p1, p2);
  9885. (void)sp_3072_sub_18(t2, p5, t0);
  9886. (void)sp_3072_sub_18(t2, t2, t1);
  9887. (void)sp_3072_sub_18(t0, t0, p4);
  9888. (void)sp_3072_sub_18(t1, t1, p0);
  9889. (void)sp_3072_add_18(r, r, p0);
  9890. (void)sp_3072_add_18(&r[9], &r[9], t1);
  9891. (void)sp_3072_add_18(&r[18], &r[18], t2);
  9892. (void)sp_3072_add_18(&r[27], &r[27], t0);
  9893. (void)sp_3072_add_18(&r[36], &r[36], p4);
  9894. }
  9895. /* Square a and put result in r. (r = a * a)
  9896. *
  9897. * r A single precision integer.
  9898. * a A single precision integer.
  9899. */
  9900. SP_NOINLINE static void sp_3072_sqr_54(sp_digit* r, const sp_digit* a)
  9901. {
  9902. sp_digit* z0 = r;
  9903. sp_digit z1[54];
  9904. sp_digit* a1 = z1;
  9905. sp_digit* z2 = r + 54;
  9906. (void)sp_3072_add_27(a1, a, &a[27]);
  9907. sp_3072_sqr_27(z2, &a[27]);
  9908. sp_3072_sqr_27(z0, a);
  9909. sp_3072_sqr_27(z1, a1);
  9910. (void)sp_3072_sub_54(z1, z1, z2);
  9911. (void)sp_3072_sub_54(z1, z1, z0);
  9912. (void)sp_3072_add_54(r + 27, r + 27, z1);
  9913. }
  9914. #endif /* !WOLFSSL_SP_SMALL */
  9915. /* Calculate the bottom digit of -1/a mod 2^n.
  9916. *
  9917. * a A single precision number.
  9918. * rho Bottom word of inverse.
  9919. */
  9920. static void sp_3072_mont_setup(const sp_digit* a, sp_digit* rho)
  9921. {
  9922. sp_digit x;
  9923. sp_digit b;
  9924. b = a[0];
  9925. x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
  9926. x *= 2 - b * x; /* here x*a==1 mod 2**8 */
  9927. x *= 2 - b * x; /* here x*a==1 mod 2**16 */
  9928. x *= 2 - b * x; /* here x*a==1 mod 2**32 */
  9929. x *= 2 - b * x; /* here x*a==1 mod 2**64 */
  9930. x &= 0x1ffffffffffffffL;
  9931. /* rho = -1/m mod b */
  9932. *rho = ((sp_digit)1 << 57) - x;
  9933. }
  9934. /* Multiply a by scalar b into r. (r = a * b)
  9935. *
  9936. * r A single precision integer.
  9937. * a A single precision integer.
  9938. * b A scalar.
  9939. */
  9940. SP_NOINLINE static void sp_3072_mul_d_54(sp_digit* r, const sp_digit* a,
  9941. sp_digit b)
  9942. {
  9943. sp_int128 tb = b;
  9944. sp_int128 t = 0;
  9945. sp_digit t2;
  9946. sp_int128 p[4];
  9947. int i;
  9948. for (i = 0; i < 52; i += 4) {
  9949. p[0] = tb * a[i + 0];
  9950. p[1] = tb * a[i + 1];
  9951. p[2] = tb * a[i + 2];
  9952. p[3] = tb * a[i + 3];
  9953. t += p[0];
  9954. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  9955. t >>= 57;
  9956. r[i + 0] = (sp_digit)t2;
  9957. t += p[1];
  9958. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  9959. t >>= 57;
  9960. r[i + 1] = (sp_digit)t2;
  9961. t += p[2];
  9962. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  9963. t >>= 57;
  9964. r[i + 2] = (sp_digit)t2;
  9965. t += p[3];
  9966. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  9967. t >>= 57;
  9968. r[i + 3] = (sp_digit)t2;
  9969. }
  9970. t += tb * a[52];
  9971. r[52] = (sp_digit)(t & 0x1ffffffffffffffL);
  9972. t >>= 57;
  9973. t += tb * a[53];
  9974. r[53] = (sp_digit)(t & 0x1ffffffffffffffL);
  9975. t >>= 57;
  9976. r[54] = (sp_digit)(t & 0x1ffffffffffffffL);
  9977. }
  9978. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  9979. /* Sub b from a into r. (r = a - b)
  9980. *
  9981. * r A single precision integer.
  9982. * a A single precision integer.
  9983. * b A single precision integer.
  9984. */
  9985. SP_NOINLINE static int sp_3072_sub_27(sp_digit* r, const sp_digit* a,
  9986. const sp_digit* b)
  9987. {
  9988. int i;
  9989. for (i = 0; i < 24; i += 8) {
  9990. r[i + 0] = a[i + 0] - b[i + 0];
  9991. r[i + 1] = a[i + 1] - b[i + 1];
  9992. r[i + 2] = a[i + 2] - b[i + 2];
  9993. r[i + 3] = a[i + 3] - b[i + 3];
  9994. r[i + 4] = a[i + 4] - b[i + 4];
  9995. r[i + 5] = a[i + 5] - b[i + 5];
  9996. r[i + 6] = a[i + 6] - b[i + 6];
  9997. r[i + 7] = a[i + 7] - b[i + 7];
  9998. }
  9999. r[24] = a[24] - b[24];
  10000. r[25] = a[25] - b[25];
  10001. r[26] = a[26] - b[26];
  10002. return 0;
  10003. }
  10004. /* r = 2^n mod m where n is the number of bits to reduce by.
  10005. * Given m must be 3072 bits, just need to subtract.
  10006. *
  10007. * r A single precision number.
  10008. * m A single precision number.
  10009. */
  10010. static void sp_3072_mont_norm_27(sp_digit* r, const sp_digit* m)
  10011. {
  10012. /* Set r = 2^n - 1. */
  10013. int i;
  10014. for (i = 0; i < 24; i += 8) {
  10015. r[i + 0] = 0x1ffffffffffffffL;
  10016. r[i + 1] = 0x1ffffffffffffffL;
  10017. r[i + 2] = 0x1ffffffffffffffL;
  10018. r[i + 3] = 0x1ffffffffffffffL;
  10019. r[i + 4] = 0x1ffffffffffffffL;
  10020. r[i + 5] = 0x1ffffffffffffffL;
  10021. r[i + 6] = 0x1ffffffffffffffL;
  10022. r[i + 7] = 0x1ffffffffffffffL;
  10023. }
  10024. r[24] = 0x1ffffffffffffffL;
  10025. r[25] = 0x1ffffffffffffffL;
  10026. r[26] = 0x3fffffffffffffL;
  10027. /* r = (2^n - 1) mod n */
  10028. (void)sp_3072_sub_27(r, r, m);
  10029. /* Add one so r = 2^n mod m */
  10030. r[0] += 1;
  10031. }
  10032. /* Compare a with b in constant time.
  10033. *
  10034. * a A single precision integer.
  10035. * b A single precision integer.
  10036. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  10037. * respectively.
  10038. */
  10039. static sp_digit sp_3072_cmp_27(const sp_digit* a, const sp_digit* b)
  10040. {
  10041. sp_digit r = 0;
  10042. int i;
  10043. r |= (a[26] - b[26]) & (0 - (sp_digit)1);
  10044. r |= (a[25] - b[25]) & ~(((sp_digit)0 - r) >> 56);
  10045. r |= (a[24] - b[24]) & ~(((sp_digit)0 - r) >> 56);
  10046. for (i = 16; i >= 0; i -= 8) {
  10047. r |= (a[i + 7] - b[i + 7]) & ~(((sp_digit)0 - r) >> 56);
  10048. r |= (a[i + 6] - b[i + 6]) & ~(((sp_digit)0 - r) >> 56);
  10049. r |= (a[i + 5] - b[i + 5]) & ~(((sp_digit)0 - r) >> 56);
  10050. r |= (a[i + 4] - b[i + 4]) & ~(((sp_digit)0 - r) >> 56);
  10051. r |= (a[i + 3] - b[i + 3]) & ~(((sp_digit)0 - r) >> 56);
  10052. r |= (a[i + 2] - b[i + 2]) & ~(((sp_digit)0 - r) >> 56);
  10053. r |= (a[i + 1] - b[i + 1]) & ~(((sp_digit)0 - r) >> 56);
  10054. r |= (a[i + 0] - b[i + 0]) & ~(((sp_digit)0 - r) >> 56);
  10055. }
  10056. return r;
  10057. }
  10058. /* Conditionally subtract b from a using the mask m.
  10059. * m is -1 to subtract and 0 when not.
  10060. *
  10061. * r A single precision number representing condition subtract result.
  10062. * a A single precision number to subtract from.
  10063. * b A single precision number to subtract.
  10064. * m Mask value to apply.
  10065. */
  10066. static void sp_3072_cond_sub_27(sp_digit* r, const sp_digit* a,
  10067. const sp_digit* b, const sp_digit m)
  10068. {
  10069. int i;
  10070. for (i = 0; i < 24; i += 8) {
  10071. r[i + 0] = a[i + 0] - (b[i + 0] & m);
  10072. r[i + 1] = a[i + 1] - (b[i + 1] & m);
  10073. r[i + 2] = a[i + 2] - (b[i + 2] & m);
  10074. r[i + 3] = a[i + 3] - (b[i + 3] & m);
  10075. r[i + 4] = a[i + 4] - (b[i + 4] & m);
  10076. r[i + 5] = a[i + 5] - (b[i + 5] & m);
  10077. r[i + 6] = a[i + 6] - (b[i + 6] & m);
  10078. r[i + 7] = a[i + 7] - (b[i + 7] & m);
  10079. }
  10080. r[24] = a[24] - (b[24] & m);
  10081. r[25] = a[25] - (b[25] & m);
  10082. r[26] = a[26] - (b[26] & m);
  10083. }
  10084. /* Mul a by scalar b and add into r. (r += a * b)
  10085. *
  10086. * r A single precision integer.
  10087. * a A single precision integer.
  10088. * b A scalar.
  10089. */
  10090. SP_NOINLINE static void sp_3072_mul_add_27(sp_digit* r, const sp_digit* a,
  10091. const sp_digit b)
  10092. {
  10093. sp_int128 tb = b;
  10094. sp_int128 t[8];
  10095. int i;
  10096. t[0] = tb * a[0]; r[0] += (sp_digit)(t[0] & 0x1ffffffffffffffL);
  10097. for (i = 0; i < 24; i += 8) {
  10098. t[1] = tb * a[i+1];
  10099. r[i+1] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  10100. t[2] = tb * a[i+2];
  10101. r[i+2] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  10102. t[3] = tb * a[i+3];
  10103. r[i+3] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL));
  10104. t[4] = tb * a[i+4];
  10105. r[i+4] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL));
  10106. t[5] = tb * a[i+5];
  10107. r[i+5] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL));
  10108. t[6] = tb * a[i+6];
  10109. r[i+6] += (sp_digit)((t[5] >> 57) + (t[6] & 0x1ffffffffffffffL));
  10110. t[7] = tb * a[i+7];
  10111. r[i+7] += (sp_digit)((t[6] >> 57) + (t[7] & 0x1ffffffffffffffL));
  10112. t[0] = tb * a[i+8];
  10113. r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL));
  10114. }
  10115. t[1] = tb * a[25];
  10116. r[25] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  10117. t[2] = tb * a[26];
  10118. r[26] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  10119. r[27] += (sp_digit)(t[2] >> 57);
  10120. }
  10121. /* Shift the result in the high 1536 bits down to the bottom.
  10122. *
  10123. * r A single precision number.
  10124. * a A single precision number.
  10125. */
  10126. static void sp_3072_mont_shift_27(sp_digit* r, const sp_digit* a)
  10127. {
  10128. sp_digit n;
  10129. sp_digit s;
  10130. int i;
  10131. s = a[27]; n = a[26] >> 54;
  10132. for (i = 0; i < 24; i += 8) {
  10133. n += (s & 0x1ffffffffffffffL) << 3; r[i+0] = n & 0x1ffffffffffffffL;
  10134. n >>= 57; s = a[i+28] + (s >> 57);
  10135. n += (s & 0x1ffffffffffffffL) << 3; r[i+1] = n & 0x1ffffffffffffffL;
  10136. n >>= 57; s = a[i+29] + (s >> 57);
  10137. n += (s & 0x1ffffffffffffffL) << 3; r[i+2] = n & 0x1ffffffffffffffL;
  10138. n >>= 57; s = a[i+30] + (s >> 57);
  10139. n += (s & 0x1ffffffffffffffL) << 3; r[i+3] = n & 0x1ffffffffffffffL;
  10140. n >>= 57; s = a[i+31] + (s >> 57);
  10141. n += (s & 0x1ffffffffffffffL) << 3; r[i+4] = n & 0x1ffffffffffffffL;
  10142. n >>= 57; s = a[i+32] + (s >> 57);
  10143. n += (s & 0x1ffffffffffffffL) << 3; r[i+5] = n & 0x1ffffffffffffffL;
  10144. n >>= 57; s = a[i+33] + (s >> 57);
  10145. n += (s & 0x1ffffffffffffffL) << 3; r[i+6] = n & 0x1ffffffffffffffL;
  10146. n >>= 57; s = a[i+34] + (s >> 57);
  10147. n += (s & 0x1ffffffffffffffL) << 3; r[i+7] = n & 0x1ffffffffffffffL;
  10148. n >>= 57; s = a[i+35] + (s >> 57);
  10149. }
  10150. n += (s & 0x1ffffffffffffffL) << 3; r[24] = n & 0x1ffffffffffffffL;
  10151. n >>= 57; s = a[52] + (s >> 57);
  10152. n += (s & 0x1ffffffffffffffL) << 3; r[25] = n & 0x1ffffffffffffffL;
  10153. n >>= 57; s = a[53] + (s >> 57);
  10154. n += s << 3; r[26] = n;
  10155. XMEMSET(&r[27], 0, sizeof(*r) * 27U);
  10156. }
  10157. /* Reduce the number back to 3072 bits using Montgomery reduction.
  10158. *
  10159. * a A single precision number to reduce in place.
  10160. * m The single precision number representing the modulus.
  10161. * mp The digit representing the negative inverse of m mod 2^n.
  10162. */
  10163. static void sp_3072_mont_reduce_27(sp_digit* a, const sp_digit* m, sp_digit mp)
  10164. {
  10165. int i;
  10166. sp_digit mu;
  10167. sp_digit over;
  10168. sp_3072_norm_27(a + 27);
  10169. for (i=0; i<26; i++) {
  10170. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL;
  10171. sp_3072_mul_add_27(a+i, m, mu);
  10172. a[i+1] += a[i] >> 57;
  10173. }
  10174. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x3fffffffffffffL;
  10175. sp_3072_mul_add_27(a+i, m, mu);
  10176. a[i+1] += a[i] >> 57;
  10177. a[i] &= 0x1ffffffffffffffL;
  10178. sp_3072_mont_shift_27(a, a);
  10179. over = a[26] - m[26];
  10180. sp_3072_cond_sub_27(a, a, m, ~((over - 1) >> 63));
  10181. sp_3072_norm_27(a);
  10182. }
  10183. /* Multiply two Montgomery form numbers mod the modulus (prime).
  10184. * (r = a * b mod m)
  10185. *
  10186. * r Result of multiplication.
  10187. * a First number to multiply in Montgomery form.
  10188. * b Second number to multiply in Montgomery form.
  10189. * m Modulus (prime).
  10190. * mp Montgomery multiplier.
  10191. */
  10192. SP_NOINLINE static void sp_3072_mont_mul_27(sp_digit* r, const sp_digit* a,
  10193. const sp_digit* b, const sp_digit* m, sp_digit mp)
  10194. {
  10195. sp_3072_mul_27(r, a, b);
  10196. sp_3072_mont_reduce_27(r, m, mp);
  10197. }
  10198. /* Square the Montgomery form number. (r = a * a mod m)
  10199. *
  10200. * r Result of squaring.
  10201. * a Number to square in Montgomery form.
  10202. * m Modulus (prime).
  10203. * mp Montgomery multiplier.
  10204. */
  10205. SP_NOINLINE static void sp_3072_mont_sqr_27(sp_digit* r, const sp_digit* a,
  10206. const sp_digit* m, sp_digit mp)
  10207. {
  10208. sp_3072_sqr_27(r, a);
  10209. sp_3072_mont_reduce_27(r, m, mp);
  10210. }
  10211. /* Multiply a by scalar b into r. (r = a * b)
  10212. *
  10213. * r A single precision integer.
  10214. * a A single precision integer.
  10215. * b A scalar.
  10216. */
  10217. SP_NOINLINE static void sp_3072_mul_d_27(sp_digit* r, const sp_digit* a,
  10218. sp_digit b)
  10219. {
  10220. sp_int128 tb = b;
  10221. sp_int128 t = 0;
  10222. sp_digit t2;
  10223. sp_int128 p[4];
  10224. int i;
  10225. for (i = 0; i < 24; i += 4) {
  10226. p[0] = tb * a[i + 0];
  10227. p[1] = tb * a[i + 1];
  10228. p[2] = tb * a[i + 2];
  10229. p[3] = tb * a[i + 3];
  10230. t += p[0];
  10231. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  10232. t >>= 57;
  10233. r[i + 0] = (sp_digit)t2;
  10234. t += p[1];
  10235. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  10236. t >>= 57;
  10237. r[i + 1] = (sp_digit)t2;
  10238. t += p[2];
  10239. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  10240. t >>= 57;
  10241. r[i + 2] = (sp_digit)t2;
  10242. t += p[3];
  10243. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  10244. t >>= 57;
  10245. r[i + 3] = (sp_digit)t2;
  10246. }
  10247. t += tb * a[24];
  10248. r[24] = (sp_digit)(t & 0x1ffffffffffffffL);
  10249. t >>= 57;
  10250. t += tb * a[25];
  10251. r[25] = (sp_digit)(t & 0x1ffffffffffffffL);
  10252. t >>= 57;
  10253. t += tb * a[26];
  10254. r[26] = (sp_digit)(t & 0x1ffffffffffffffL);
  10255. t >>= 57;
  10256. r[27] = (sp_digit)(t & 0x1ffffffffffffffL);
  10257. }
  10258. #ifndef WOLFSSL_SP_SMALL
  10259. /* Conditionally add a and b using the mask m.
  10260. * m is -1 to add and 0 when not.
  10261. *
  10262. * r A single precision number representing conditional add result.
  10263. * a A single precision number to add with.
  10264. * b A single precision number to add.
  10265. * m Mask value to apply.
  10266. */
  10267. static void sp_3072_cond_add_27(sp_digit* r, const sp_digit* a,
  10268. const sp_digit* b, const sp_digit m)
  10269. {
  10270. int i;
  10271. for (i = 0; i < 24; i += 8) {
  10272. r[i + 0] = a[i + 0] + (b[i + 0] & m);
  10273. r[i + 1] = a[i + 1] + (b[i + 1] & m);
  10274. r[i + 2] = a[i + 2] + (b[i + 2] & m);
  10275. r[i + 3] = a[i + 3] + (b[i + 3] & m);
  10276. r[i + 4] = a[i + 4] + (b[i + 4] & m);
  10277. r[i + 5] = a[i + 5] + (b[i + 5] & m);
  10278. r[i + 6] = a[i + 6] + (b[i + 6] & m);
  10279. r[i + 7] = a[i + 7] + (b[i + 7] & m);
  10280. }
  10281. r[24] = a[24] + (b[24] & m);
  10282. r[25] = a[25] + (b[25] & m);
  10283. r[26] = a[26] + (b[26] & m);
  10284. }
  10285. #endif /* !WOLFSSL_SP_SMALL */
  10286. SP_NOINLINE static void sp_3072_rshift_27(sp_digit* r, const sp_digit* a,
  10287. byte n)
  10288. {
  10289. int i;
  10290. for (i=0; i<24; i += 8) {
  10291. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (57 - n)) & 0x1ffffffffffffffL);
  10292. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (57 - n)) & 0x1ffffffffffffffL);
  10293. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (57 - n)) & 0x1ffffffffffffffL);
  10294. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (57 - n)) & 0x1ffffffffffffffL);
  10295. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (57 - n)) & 0x1ffffffffffffffL);
  10296. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (57 - n)) & 0x1ffffffffffffffL);
  10297. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (57 - n)) & 0x1ffffffffffffffL);
  10298. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (57 - n)) & 0x1ffffffffffffffL);
  10299. }
  10300. r[24] = (a[24] >> n) | ((a[25] << (57 - n)) & 0x1ffffffffffffffL);
  10301. r[25] = (a[25] >> n) | ((a[26] << (57 - n)) & 0x1ffffffffffffffL);
  10302. r[26] = a[26] >> n;
  10303. }
  10304. static WC_INLINE sp_digit sp_3072_div_word_27(sp_digit d1, sp_digit d0,
  10305. sp_digit div)
  10306. {
  10307. #ifdef SP_USE_DIVTI3
  10308. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  10309. return d / div;
  10310. #elif defined(__x86_64__) || defined(__i386__)
  10311. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  10312. sp_uint64 lo = (sp_uint64)d;
  10313. sp_digit hi = (sp_digit)(d >> 64);
  10314. __asm__ __volatile__ (
  10315. "idiv %2"
  10316. : "+a" (lo)
  10317. : "d" (hi), "r" (div)
  10318. : "cc"
  10319. );
  10320. return (sp_digit)lo;
  10321. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  10322. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  10323. sp_digit dv = (div >> 1) + 1;
  10324. sp_digit t1 = (sp_digit)(d >> 57);
  10325. sp_digit t0 = (sp_digit)(d & 0x1ffffffffffffffL);
  10326. sp_digit t2;
  10327. sp_digit sign;
  10328. sp_digit r;
  10329. int i;
  10330. sp_int128 m;
  10331. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  10332. t1 -= dv & (0 - r);
  10333. for (i = 55; i >= 1; i--) {
  10334. t1 += t1 + (((sp_uint64)t0 >> 56) & 1);
  10335. t0 <<= 1;
  10336. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  10337. r += r + t2;
  10338. t1 -= dv & (0 - t2);
  10339. t1 += t2;
  10340. }
  10341. r += r + 1;
  10342. m = d - ((sp_int128)r * div);
  10343. r += (sp_digit)(m >> 57);
  10344. m = d - ((sp_int128)r * div);
  10345. r += (sp_digit)(m >> 114) - (sp_digit)(d >> 114);
  10346. m = d - ((sp_int128)r * div);
  10347. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  10348. m *= sign;
  10349. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  10350. r += sign * t2;
  10351. m = d - ((sp_int128)r * div);
  10352. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  10353. m *= sign;
  10354. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  10355. r += sign * t2;
  10356. return r;
  10357. #else
  10358. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  10359. sp_digit r = 0;
  10360. sp_digit t;
  10361. sp_digit dv = (div >> 26) + 1;
  10362. t = (sp_digit)(d >> 52);
  10363. t = (t / dv) << 26;
  10364. r += t;
  10365. d -= (sp_int128)t * div;
  10366. t = (sp_digit)(d >> 21);
  10367. t = t / (dv << 5);
  10368. r += t;
  10369. d -= (sp_int128)t * div;
  10370. t = (sp_digit)d;
  10371. t = t / div;
  10372. r += t;
  10373. d -= (sp_int128)t * div;
  10374. return r;
  10375. #endif
  10376. }
  10377. static WC_INLINE sp_digit sp_3072_word_div_word_27(sp_digit d, sp_digit div)
  10378. {
  10379. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  10380. defined(SP_DIV_WORD_USE_DIV)
  10381. return d / div;
  10382. #else
  10383. return (sp_digit)((sp_uint64)(div - d) >> 63);
  10384. #endif
  10385. }
  10386. /* Divide d in a and put remainder into r (m*d + r = a)
  10387. * m is not calculated as it is not needed at this time.
  10388. *
  10389. * Full implementation.
  10390. *
  10391. * a Number to be divided.
  10392. * d Number to divide with.
  10393. * m Multiplier result.
  10394. * r Remainder from the division.
  10395. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  10396. */
  10397. static int sp_3072_div_27(const sp_digit* a, const sp_digit* d,
  10398. const sp_digit* m, sp_digit* r)
  10399. {
  10400. int i;
  10401. #ifndef WOLFSSL_SP_DIV_64
  10402. #endif
  10403. sp_digit dv;
  10404. sp_digit r1;
  10405. #ifdef WOLFSSL_SP_SMALL_STACK
  10406. sp_digit* t1 = NULL;
  10407. #else
  10408. sp_digit t1[4 * 27 + 3];
  10409. #endif
  10410. sp_digit* t2 = NULL;
  10411. sp_digit* sd = NULL;
  10412. int err = MP_OKAY;
  10413. (void)m;
  10414. #ifdef WOLFSSL_SP_SMALL_STACK
  10415. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 27 + 3), NULL,
  10416. DYNAMIC_TYPE_TMP_BUFFER);
  10417. if (t1 == NULL)
  10418. err = MEMORY_E;
  10419. #endif
  10420. (void)m;
  10421. if (err == MP_OKAY) {
  10422. t2 = t1 + 54 + 1;
  10423. sd = t2 + 27 + 1;
  10424. sp_3072_mul_d_27(sd, d, (sp_digit)1 << 3);
  10425. sp_3072_mul_d_54(t1, a, (sp_digit)1 << 3);
  10426. dv = sd[26];
  10427. t1[27 + 27] += t1[27 + 27 - 1] >> 57;
  10428. t1[27 + 27 - 1] &= 0x1ffffffffffffffL;
  10429. for (i=27; i>=0; i--) {
  10430. r1 = sp_3072_div_word_27(t1[27 + i], t1[27 + i - 1], dv);
  10431. sp_3072_mul_d_27(t2, sd, r1);
  10432. (void)sp_3072_sub_27(&t1[i], &t1[i], t2);
  10433. sp_3072_norm_27(&t1[i]);
  10434. t1[27 + i] -= t2[27];
  10435. t1[27 + i] += t1[27 + i - 1] >> 57;
  10436. t1[27 + i - 1] &= 0x1ffffffffffffffL;
  10437. r1 = sp_3072_div_word_27(-t1[27 + i], -t1[27 + i - 1], dv);
  10438. r1 -= t1[27 + i];
  10439. sp_3072_mul_d_27(t2, sd, r1);
  10440. (void)sp_3072_add_27(&t1[i], &t1[i], t2);
  10441. t1[27 + i] += t1[27 + i - 1] >> 57;
  10442. t1[27 + i - 1] &= 0x1ffffffffffffffL;
  10443. }
  10444. t1[27 - 1] += t1[27 - 2] >> 57;
  10445. t1[27 - 2] &= 0x1ffffffffffffffL;
  10446. r1 = sp_3072_word_div_word_27(t1[27 - 1], dv);
  10447. sp_3072_mul_d_27(t2, sd, r1);
  10448. sp_3072_sub_27(t1, t1, t2);
  10449. XMEMCPY(r, t1, sizeof(*r) * 54U);
  10450. for (i=0; i<26; i++) {
  10451. r[i+1] += r[i] >> 57;
  10452. r[i] &= 0x1ffffffffffffffL;
  10453. }
  10454. sp_3072_cond_add_27(r, r, sd, r[26] >> 63);
  10455. sp_3072_norm_27(r);
  10456. sp_3072_rshift_27(r, r, 3);
  10457. }
  10458. #ifdef WOLFSSL_SP_SMALL_STACK
  10459. if (t1 != NULL)
  10460. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  10461. #endif
  10462. return err;
  10463. }
  10464. /* Reduce a modulo m into r. (r = a mod m)
  10465. *
  10466. * r A single precision number that is the reduced result.
  10467. * a A single precision number that is to be reduced.
  10468. * m A single precision number that is the modulus to reduce with.
  10469. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  10470. */
  10471. static int sp_3072_mod_27(sp_digit* r, const sp_digit* a, const sp_digit* m)
  10472. {
  10473. return sp_3072_div_27(a, m, NULL, r);
  10474. }
  10475. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  10476. *
  10477. * r A single precision number that is the result of the operation.
  10478. * a A single precision number being exponentiated.
  10479. * e A single precision number that is the exponent.
  10480. * bits The number of bits in the exponent.
  10481. * m A single precision number that is the modulus.
  10482. * returns 0 on success.
  10483. * returns MEMORY_E on dynamic memory allocation failure.
  10484. * returns MP_VAL when base is even or exponent is 0.
  10485. */
  10486. static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e,
  10487. int bits, const sp_digit* m, int reduceA)
  10488. {
  10489. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  10490. #ifdef WOLFSSL_SP_SMALL_STACK
  10491. sp_digit* td = NULL;
  10492. #else
  10493. sp_digit td[3 * 54];
  10494. #endif
  10495. sp_digit* t[3] = {0, 0, 0};
  10496. sp_digit* norm = NULL;
  10497. sp_digit mp = 1;
  10498. sp_digit n;
  10499. int i;
  10500. int c;
  10501. byte y;
  10502. int err = MP_OKAY;
  10503. if (bits == 0) {
  10504. err = MP_VAL;
  10505. }
  10506. #ifdef WOLFSSL_SP_SMALL_STACK
  10507. if (err == MP_OKAY) {
  10508. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 27 * 2, NULL,
  10509. DYNAMIC_TYPE_TMP_BUFFER);
  10510. if (td == NULL)
  10511. err = MEMORY_E;
  10512. }
  10513. #endif
  10514. if (err == MP_OKAY) {
  10515. norm = td;
  10516. for (i=0; i<3; i++) {
  10517. t[i] = td + (i * 27 * 2);
  10518. XMEMSET(t[i], 0, sizeof(sp_digit) * 27U * 2U);
  10519. }
  10520. sp_3072_mont_setup(m, &mp);
  10521. sp_3072_mont_norm_27(norm, m);
  10522. if (reduceA != 0) {
  10523. err = sp_3072_mod_27(t[1], a, m);
  10524. }
  10525. else {
  10526. XMEMCPY(t[1], a, sizeof(sp_digit) * 27U);
  10527. }
  10528. }
  10529. if (err == MP_OKAY) {
  10530. sp_3072_mul_27(t[1], t[1], norm);
  10531. err = sp_3072_mod_27(t[1], t[1], m);
  10532. }
  10533. if (err == MP_OKAY) {
  10534. i = bits / 57;
  10535. c = bits % 57;
  10536. n = e[i--] << (57 - c);
  10537. for (; ; c--) {
  10538. if (c == 0) {
  10539. if (i == -1) {
  10540. break;
  10541. }
  10542. n = e[i--];
  10543. c = 57;
  10544. }
  10545. y = (int)((n >> 56) & 1);
  10546. n <<= 1;
  10547. sp_3072_mont_mul_27(t[y^1], t[0], t[1], m, mp);
  10548. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  10549. ((size_t)t[1] & addr_mask[y])),
  10550. sizeof(*t[2]) * 27 * 2);
  10551. sp_3072_mont_sqr_27(t[2], t[2], m, mp);
  10552. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  10553. ((size_t)t[1] & addr_mask[y])), t[2],
  10554. sizeof(*t[2]) * 27 * 2);
  10555. }
  10556. sp_3072_mont_reduce_27(t[0], m, mp);
  10557. n = sp_3072_cmp_27(t[0], m);
  10558. sp_3072_cond_sub_27(t[0], t[0], m, ~(n >> 63));
  10559. XMEMCPY(r, t[0], sizeof(*r) * 27 * 2);
  10560. }
  10561. #ifdef WOLFSSL_SP_SMALL_STACK
  10562. if (td != NULL)
  10563. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  10564. #endif
  10565. return err;
  10566. #elif !defined(WC_NO_CACHE_RESISTANT)
  10567. #ifdef WOLFSSL_SP_SMALL_STACK
  10568. sp_digit* td = NULL;
  10569. #else
  10570. sp_digit td[3 * 54];
  10571. #endif
  10572. sp_digit* t[3] = {0, 0, 0};
  10573. sp_digit* norm = NULL;
  10574. sp_digit mp = 1;
  10575. sp_digit n;
  10576. int i;
  10577. int c;
  10578. byte y;
  10579. int err = MP_OKAY;
  10580. if (bits == 0) {
  10581. err = MP_VAL;
  10582. }
  10583. #ifdef WOLFSSL_SP_SMALL_STACK
  10584. if (err == MP_OKAY) {
  10585. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 27 * 2, NULL,
  10586. DYNAMIC_TYPE_TMP_BUFFER);
  10587. if (td == NULL)
  10588. err = MEMORY_E;
  10589. }
  10590. #endif
  10591. if (err == MP_OKAY) {
  10592. norm = td;
  10593. for (i=0; i<3; i++) {
  10594. t[i] = td + (i * 27 * 2);
  10595. }
  10596. sp_3072_mont_setup(m, &mp);
  10597. sp_3072_mont_norm_27(norm, m);
  10598. if (reduceA != 0) {
  10599. err = sp_3072_mod_27(t[1], a, m);
  10600. if (err == MP_OKAY) {
  10601. sp_3072_mul_27(t[1], t[1], norm);
  10602. err = sp_3072_mod_27(t[1], t[1], m);
  10603. }
  10604. }
  10605. else {
  10606. sp_3072_mul_27(t[1], a, norm);
  10607. err = sp_3072_mod_27(t[1], t[1], m);
  10608. }
  10609. }
  10610. if (err == MP_OKAY) {
  10611. i = bits / 57;
  10612. c = bits % 57;
  10613. n = e[i--] << (57 - c);
  10614. for (; ; c--) {
  10615. if (c == 0) {
  10616. if (i == -1) {
  10617. break;
  10618. }
  10619. n = e[i--];
  10620. c = 57;
  10621. }
  10622. y = (int)((n >> 56) & 1);
  10623. n <<= 1;
  10624. sp_3072_mont_mul_27(t[y^1], t[0], t[1], m, mp);
  10625. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  10626. ((size_t)t[1] & addr_mask[y])),
  10627. sizeof(*t[2]) * 27 * 2);
  10628. sp_3072_mont_sqr_27(t[2], t[2], m, mp);
  10629. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  10630. ((size_t)t[1] & addr_mask[y])), t[2],
  10631. sizeof(*t[2]) * 27 * 2);
  10632. }
  10633. sp_3072_mont_reduce_27(t[0], m, mp);
  10634. n = sp_3072_cmp_27(t[0], m);
  10635. sp_3072_cond_sub_27(t[0], t[0], m, ~(n >> 63));
  10636. XMEMCPY(r, t[0], sizeof(*r) * 27 * 2);
  10637. }
  10638. #ifdef WOLFSSL_SP_SMALL_STACK
  10639. if (td != NULL)
  10640. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  10641. #endif
  10642. return err;
  10643. #else
  10644. #ifdef WOLFSSL_SP_SMALL_STACK
  10645. sp_digit* td = NULL;
  10646. #else
  10647. sp_digit td[(32 * 54) + 54];
  10648. #endif
  10649. sp_digit* t[32];
  10650. sp_digit* rt = NULL;
  10651. sp_digit* norm = NULL;
  10652. sp_digit mp = 1;
  10653. sp_digit n;
  10654. int i;
  10655. int c;
  10656. byte y;
  10657. int err = MP_OKAY;
  10658. if (bits == 0) {
  10659. err = MP_VAL;
  10660. }
  10661. #ifdef WOLFSSL_SP_SMALL_STACK
  10662. if (err == MP_OKAY) {
  10663. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 54) + 54), NULL,
  10664. DYNAMIC_TYPE_TMP_BUFFER);
  10665. if (td == NULL)
  10666. err = MEMORY_E;
  10667. }
  10668. #endif
  10669. if (err == MP_OKAY) {
  10670. norm = td;
  10671. for (i=0; i<32; i++)
  10672. t[i] = td + i * 54;
  10673. rt = td + 1728;
  10674. sp_3072_mont_setup(m, &mp);
  10675. sp_3072_mont_norm_27(norm, m);
  10676. if (reduceA != 0) {
  10677. err = sp_3072_mod_27(t[1], a, m);
  10678. if (err == MP_OKAY) {
  10679. sp_3072_mul_27(t[1], t[1], norm);
  10680. err = sp_3072_mod_27(t[1], t[1], m);
  10681. }
  10682. }
  10683. else {
  10684. sp_3072_mul_27(t[1], a, norm);
  10685. err = sp_3072_mod_27(t[1], t[1], m);
  10686. }
  10687. }
  10688. if (err == MP_OKAY) {
  10689. sp_3072_mont_sqr_27(t[ 2], t[ 1], m, mp);
  10690. sp_3072_mont_mul_27(t[ 3], t[ 2], t[ 1], m, mp);
  10691. sp_3072_mont_sqr_27(t[ 4], t[ 2], m, mp);
  10692. sp_3072_mont_mul_27(t[ 5], t[ 3], t[ 2], m, mp);
  10693. sp_3072_mont_sqr_27(t[ 6], t[ 3], m, mp);
  10694. sp_3072_mont_mul_27(t[ 7], t[ 4], t[ 3], m, mp);
  10695. sp_3072_mont_sqr_27(t[ 8], t[ 4], m, mp);
  10696. sp_3072_mont_mul_27(t[ 9], t[ 5], t[ 4], m, mp);
  10697. sp_3072_mont_sqr_27(t[10], t[ 5], m, mp);
  10698. sp_3072_mont_mul_27(t[11], t[ 6], t[ 5], m, mp);
  10699. sp_3072_mont_sqr_27(t[12], t[ 6], m, mp);
  10700. sp_3072_mont_mul_27(t[13], t[ 7], t[ 6], m, mp);
  10701. sp_3072_mont_sqr_27(t[14], t[ 7], m, mp);
  10702. sp_3072_mont_mul_27(t[15], t[ 8], t[ 7], m, mp);
  10703. sp_3072_mont_sqr_27(t[16], t[ 8], m, mp);
  10704. sp_3072_mont_mul_27(t[17], t[ 9], t[ 8], m, mp);
  10705. sp_3072_mont_sqr_27(t[18], t[ 9], m, mp);
  10706. sp_3072_mont_mul_27(t[19], t[10], t[ 9], m, mp);
  10707. sp_3072_mont_sqr_27(t[20], t[10], m, mp);
  10708. sp_3072_mont_mul_27(t[21], t[11], t[10], m, mp);
  10709. sp_3072_mont_sqr_27(t[22], t[11], m, mp);
  10710. sp_3072_mont_mul_27(t[23], t[12], t[11], m, mp);
  10711. sp_3072_mont_sqr_27(t[24], t[12], m, mp);
  10712. sp_3072_mont_mul_27(t[25], t[13], t[12], m, mp);
  10713. sp_3072_mont_sqr_27(t[26], t[13], m, mp);
  10714. sp_3072_mont_mul_27(t[27], t[14], t[13], m, mp);
  10715. sp_3072_mont_sqr_27(t[28], t[14], m, mp);
  10716. sp_3072_mont_mul_27(t[29], t[15], t[14], m, mp);
  10717. sp_3072_mont_sqr_27(t[30], t[15], m, mp);
  10718. sp_3072_mont_mul_27(t[31], t[16], t[15], m, mp);
  10719. bits = ((bits + 4) / 5) * 5;
  10720. i = ((bits + 56) / 57) - 1;
  10721. c = bits % 57;
  10722. if (c == 0) {
  10723. c = 57;
  10724. }
  10725. if (i < 27) {
  10726. n = e[i--] << (64 - c);
  10727. }
  10728. else {
  10729. n = 0;
  10730. i--;
  10731. }
  10732. if (c < 5) {
  10733. n |= e[i--] << (7 - c);
  10734. c += 57;
  10735. }
  10736. y = (int)((n >> 59) & 0x1f);
  10737. n <<= 5;
  10738. c -= 5;
  10739. XMEMCPY(rt, t[y], sizeof(sp_digit) * 54);
  10740. while ((i >= 0) || (c >= 5)) {
  10741. if (c >= 5) {
  10742. y = (byte)((n >> 59) & 0x1f);
  10743. n <<= 5;
  10744. c -= 5;
  10745. }
  10746. else if (c == 0) {
  10747. n = e[i--] << 7;
  10748. y = (byte)((n >> 59) & 0x1f);
  10749. n <<= 5;
  10750. c = 52;
  10751. }
  10752. else {
  10753. y = (byte)((n >> 59) & 0x1f);
  10754. n = e[i--] << 7;
  10755. c = 5 - c;
  10756. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  10757. n <<= c;
  10758. c = 57 - c;
  10759. }
  10760. sp_3072_mont_sqr_27(rt, rt, m, mp);
  10761. sp_3072_mont_sqr_27(rt, rt, m, mp);
  10762. sp_3072_mont_sqr_27(rt, rt, m, mp);
  10763. sp_3072_mont_sqr_27(rt, rt, m, mp);
  10764. sp_3072_mont_sqr_27(rt, rt, m, mp);
  10765. sp_3072_mont_mul_27(rt, rt, t[y], m, mp);
  10766. }
  10767. sp_3072_mont_reduce_27(rt, m, mp);
  10768. n = sp_3072_cmp_27(rt, m);
  10769. sp_3072_cond_sub_27(rt, rt, m, ~(n >> 63));
  10770. XMEMCPY(r, rt, sizeof(sp_digit) * 54);
  10771. }
  10772. #ifdef WOLFSSL_SP_SMALL_STACK
  10773. if (td != NULL)
  10774. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  10775. #endif
  10776. return err;
  10777. #endif
  10778. }
  10779. #endif /* (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) | WOLFSSL_HAVE_SP_DH */
  10780. /* r = 2^n mod m where n is the number of bits to reduce by.
  10781. * Given m must be 3072 bits, just need to subtract.
  10782. *
  10783. * r A single precision number.
  10784. * m A single precision number.
  10785. */
  10786. static void sp_3072_mont_norm_54(sp_digit* r, const sp_digit* m)
  10787. {
  10788. /* Set r = 2^n - 1. */
  10789. int i;
  10790. for (i = 0; i < 48; i += 8) {
  10791. r[i + 0] = 0x1ffffffffffffffL;
  10792. r[i + 1] = 0x1ffffffffffffffL;
  10793. r[i + 2] = 0x1ffffffffffffffL;
  10794. r[i + 3] = 0x1ffffffffffffffL;
  10795. r[i + 4] = 0x1ffffffffffffffL;
  10796. r[i + 5] = 0x1ffffffffffffffL;
  10797. r[i + 6] = 0x1ffffffffffffffL;
  10798. r[i + 7] = 0x1ffffffffffffffL;
  10799. }
  10800. r[48] = 0x1ffffffffffffffL;
  10801. r[49] = 0x1ffffffffffffffL;
  10802. r[50] = 0x1ffffffffffffffL;
  10803. r[51] = 0x1ffffffffffffffL;
  10804. r[52] = 0x1ffffffffffffffL;
  10805. r[53] = 0x7ffffffffffffL;
  10806. /* r = (2^n - 1) mod n */
  10807. (void)sp_3072_sub_54(r, r, m);
  10808. /* Add one so r = 2^n mod m */
  10809. r[0] += 1;
  10810. }
  10811. /* Compare a with b in constant time.
  10812. *
  10813. * a A single precision integer.
  10814. * b A single precision integer.
  10815. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  10816. * respectively.
  10817. */
  10818. static sp_digit sp_3072_cmp_54(const sp_digit* a, const sp_digit* b)
  10819. {
  10820. sp_digit r = 0;
  10821. int i;
  10822. r |= (a[53] - b[53]) & (0 - (sp_digit)1);
  10823. r |= (a[52] - b[52]) & ~(((sp_digit)0 - r) >> 56);
  10824. r |= (a[51] - b[51]) & ~(((sp_digit)0 - r) >> 56);
  10825. r |= (a[50] - b[50]) & ~(((sp_digit)0 - r) >> 56);
  10826. r |= (a[49] - b[49]) & ~(((sp_digit)0 - r) >> 56);
  10827. r |= (a[48] - b[48]) & ~(((sp_digit)0 - r) >> 56);
  10828. for (i = 40; i >= 0; i -= 8) {
  10829. r |= (a[i + 7] - b[i + 7]) & ~(((sp_digit)0 - r) >> 56);
  10830. r |= (a[i + 6] - b[i + 6]) & ~(((sp_digit)0 - r) >> 56);
  10831. r |= (a[i + 5] - b[i + 5]) & ~(((sp_digit)0 - r) >> 56);
  10832. r |= (a[i + 4] - b[i + 4]) & ~(((sp_digit)0 - r) >> 56);
  10833. r |= (a[i + 3] - b[i + 3]) & ~(((sp_digit)0 - r) >> 56);
  10834. r |= (a[i + 2] - b[i + 2]) & ~(((sp_digit)0 - r) >> 56);
  10835. r |= (a[i + 1] - b[i + 1]) & ~(((sp_digit)0 - r) >> 56);
  10836. r |= (a[i + 0] - b[i + 0]) & ~(((sp_digit)0 - r) >> 56);
  10837. }
  10838. return r;
  10839. }
  10840. /* Conditionally subtract b from a using the mask m.
  10841. * m is -1 to subtract and 0 when not.
  10842. *
  10843. * r A single precision number representing condition subtract result.
  10844. * a A single precision number to subtract from.
  10845. * b A single precision number to subtract.
  10846. * m Mask value to apply.
  10847. */
  10848. static void sp_3072_cond_sub_54(sp_digit* r, const sp_digit* a,
  10849. const sp_digit* b, const sp_digit m)
  10850. {
  10851. int i;
  10852. for (i = 0; i < 48; i += 8) {
  10853. r[i + 0] = a[i + 0] - (b[i + 0] & m);
  10854. r[i + 1] = a[i + 1] - (b[i + 1] & m);
  10855. r[i + 2] = a[i + 2] - (b[i + 2] & m);
  10856. r[i + 3] = a[i + 3] - (b[i + 3] & m);
  10857. r[i + 4] = a[i + 4] - (b[i + 4] & m);
  10858. r[i + 5] = a[i + 5] - (b[i + 5] & m);
  10859. r[i + 6] = a[i + 6] - (b[i + 6] & m);
  10860. r[i + 7] = a[i + 7] - (b[i + 7] & m);
  10861. }
  10862. r[48] = a[48] - (b[48] & m);
  10863. r[49] = a[49] - (b[49] & m);
  10864. r[50] = a[50] - (b[50] & m);
  10865. r[51] = a[51] - (b[51] & m);
  10866. r[52] = a[52] - (b[52] & m);
  10867. r[53] = a[53] - (b[53] & m);
  10868. }
  10869. /* Mul a by scalar b and add into r. (r += a * b)
  10870. *
  10871. * r A single precision integer.
  10872. * a A single precision integer.
  10873. * b A scalar.
  10874. */
  10875. SP_NOINLINE static void sp_3072_mul_add_54(sp_digit* r, const sp_digit* a,
  10876. const sp_digit b)
  10877. {
  10878. sp_int128 tb = b;
  10879. sp_int128 t[8];
  10880. int i;
  10881. t[0] = tb * a[0]; r[0] += (sp_digit)(t[0] & 0x1ffffffffffffffL);
  10882. for (i = 0; i < 48; i += 8) {
  10883. t[1] = tb * a[i+1];
  10884. r[i+1] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  10885. t[2] = tb * a[i+2];
  10886. r[i+2] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  10887. t[3] = tb * a[i+3];
  10888. r[i+3] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL));
  10889. t[4] = tb * a[i+4];
  10890. r[i+4] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL));
  10891. t[5] = tb * a[i+5];
  10892. r[i+5] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL));
  10893. t[6] = tb * a[i+6];
  10894. r[i+6] += (sp_digit)((t[5] >> 57) + (t[6] & 0x1ffffffffffffffL));
  10895. t[7] = tb * a[i+7];
  10896. r[i+7] += (sp_digit)((t[6] >> 57) + (t[7] & 0x1ffffffffffffffL));
  10897. t[0] = tb * a[i+8];
  10898. r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL));
  10899. }
  10900. t[1] = tb * a[49];
  10901. r[49] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  10902. t[2] = tb * a[50];
  10903. r[50] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  10904. t[3] = tb * a[51];
  10905. r[51] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL));
  10906. t[4] = tb * a[52];
  10907. r[52] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL));
  10908. t[5] = tb * a[53];
  10909. r[53] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL));
  10910. r[54] += (sp_digit)(t[5] >> 57);
  10911. }
  10912. /* Shift the result in the high 3072 bits down to the bottom.
  10913. *
  10914. * r A single precision number.
  10915. * a A single precision number.
  10916. */
  10917. static void sp_3072_mont_shift_54(sp_digit* r, const sp_digit* a)
  10918. {
  10919. int i;
  10920. sp_int128 n = a[53] >> 51;
  10921. n += ((sp_int128)a[54]) << 6;
  10922. for (i = 0; i < 48; i += 8) {
  10923. r[i + 0] = n & 0x1ffffffffffffffL;
  10924. n >>= 57; n += ((sp_int128)a[i + 55]) << 6;
  10925. r[i + 1] = n & 0x1ffffffffffffffL;
  10926. n >>= 57; n += ((sp_int128)a[i + 56]) << 6;
  10927. r[i + 2] = n & 0x1ffffffffffffffL;
  10928. n >>= 57; n += ((sp_int128)a[i + 57]) << 6;
  10929. r[i + 3] = n & 0x1ffffffffffffffL;
  10930. n >>= 57; n += ((sp_int128)a[i + 58]) << 6;
  10931. r[i + 4] = n & 0x1ffffffffffffffL;
  10932. n >>= 57; n += ((sp_int128)a[i + 59]) << 6;
  10933. r[i + 5] = n & 0x1ffffffffffffffL;
  10934. n >>= 57; n += ((sp_int128)a[i + 60]) << 6;
  10935. r[i + 6] = n & 0x1ffffffffffffffL;
  10936. n >>= 57; n += ((sp_int128)a[i + 61]) << 6;
  10937. r[i + 7] = n & 0x1ffffffffffffffL;
  10938. n >>= 57; n += ((sp_int128)a[i + 62]) << 6;
  10939. }
  10940. r[48] = n & 0x1ffffffffffffffL; n >>= 57; n += ((sp_int128)a[103]) << 6;
  10941. r[49] = n & 0x1ffffffffffffffL; n >>= 57; n += ((sp_int128)a[104]) << 6;
  10942. r[50] = n & 0x1ffffffffffffffL; n >>= 57; n += ((sp_int128)a[105]) << 6;
  10943. r[51] = n & 0x1ffffffffffffffL; n >>= 57; n += ((sp_int128)a[106]) << 6;
  10944. r[52] = n & 0x1ffffffffffffffL; n >>= 57; n += ((sp_int128)a[107]) << 6;
  10945. r[53] = (sp_digit)n;
  10946. XMEMSET(&r[54], 0, sizeof(*r) * 54U);
  10947. }
  10948. /* Reduce the number back to 3072 bits using Montgomery reduction.
  10949. *
  10950. * a A single precision number to reduce in place.
  10951. * m The single precision number representing the modulus.
  10952. * mp The digit representing the negative inverse of m mod 2^n.
  10953. */
  10954. static void sp_3072_mont_reduce_54(sp_digit* a, const sp_digit* m, sp_digit mp)
  10955. {
  10956. int i;
  10957. sp_digit mu;
  10958. sp_digit over;
  10959. sp_3072_norm_54(a + 54);
  10960. #ifdef WOLFSSL_SP_DH
  10961. if (mp != 1) {
  10962. for (i=0; i<53; i++) {
  10963. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL;
  10964. sp_3072_mul_add_54(a+i, m, mu);
  10965. a[i+1] += a[i] >> 57;
  10966. }
  10967. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7ffffffffffffL;
  10968. sp_3072_mul_add_54(a+i, m, mu);
  10969. a[i+1] += a[i] >> 57;
  10970. a[i] &= 0x1ffffffffffffffL;
  10971. }
  10972. else {
  10973. for (i=0; i<53; i++) {
  10974. mu = a[i] & 0x1ffffffffffffffL;
  10975. sp_3072_mul_add_54(a+i, m, mu);
  10976. a[i+1] += a[i] >> 57;
  10977. }
  10978. mu = a[i] & 0x7ffffffffffffL;
  10979. sp_3072_mul_add_54(a+i, m, mu);
  10980. a[i+1] += a[i] >> 57;
  10981. a[i] &= 0x1ffffffffffffffL;
  10982. }
  10983. #else
  10984. for (i=0; i<53; i++) {
  10985. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL;
  10986. sp_3072_mul_add_54(a+i, m, mu);
  10987. a[i+1] += a[i] >> 57;
  10988. }
  10989. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7ffffffffffffL;
  10990. sp_3072_mul_add_54(a+i, m, mu);
  10991. a[i+1] += a[i] >> 57;
  10992. a[i] &= 0x1ffffffffffffffL;
  10993. #endif
  10994. sp_3072_mont_shift_54(a, a);
  10995. over = a[53] - m[53];
  10996. sp_3072_cond_sub_54(a, a, m, ~((over - 1) >> 63));
  10997. sp_3072_norm_54(a);
  10998. }
  10999. /* Multiply two Montgomery form numbers mod the modulus (prime).
  11000. * (r = a * b mod m)
  11001. *
  11002. * r Result of multiplication.
  11003. * a First number to multiply in Montgomery form.
  11004. * b Second number to multiply in Montgomery form.
  11005. * m Modulus (prime).
  11006. * mp Montgomery multiplier.
  11007. */
  11008. SP_NOINLINE static void sp_3072_mont_mul_54(sp_digit* r, const sp_digit* a,
  11009. const sp_digit* b, const sp_digit* m, sp_digit mp)
  11010. {
  11011. sp_3072_mul_54(r, a, b);
  11012. sp_3072_mont_reduce_54(r, m, mp);
  11013. }
  11014. /* Square the Montgomery form number. (r = a * a mod m)
  11015. *
  11016. * r Result of squaring.
  11017. * a Number to square in Montgomery form.
  11018. * m Modulus (prime).
  11019. * mp Montgomery multiplier.
  11020. */
  11021. SP_NOINLINE static void sp_3072_mont_sqr_54(sp_digit* r, const sp_digit* a,
  11022. const sp_digit* m, sp_digit mp)
  11023. {
  11024. sp_3072_sqr_54(r, a);
  11025. sp_3072_mont_reduce_54(r, m, mp);
  11026. }
  11027. /* Multiply a by scalar b into r. (r = a * b)
  11028. *
  11029. * r A single precision integer.
  11030. * a A single precision integer.
  11031. * b A scalar.
  11032. */
  11033. SP_NOINLINE static void sp_3072_mul_d_108(sp_digit* r, const sp_digit* a,
  11034. sp_digit b)
  11035. {
  11036. sp_int128 tb = b;
  11037. sp_int128 t = 0;
  11038. sp_digit t2;
  11039. sp_int128 p[4];
  11040. int i;
  11041. for (i = 0; i < 108; i += 4) {
  11042. p[0] = tb * a[i + 0];
  11043. p[1] = tb * a[i + 1];
  11044. p[2] = tb * a[i + 2];
  11045. p[3] = tb * a[i + 3];
  11046. t += p[0];
  11047. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  11048. t >>= 57;
  11049. r[i + 0] = (sp_digit)t2;
  11050. t += p[1];
  11051. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  11052. t >>= 57;
  11053. r[i + 1] = (sp_digit)t2;
  11054. t += p[2];
  11055. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  11056. t >>= 57;
  11057. r[i + 2] = (sp_digit)t2;
  11058. t += p[3];
  11059. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  11060. t >>= 57;
  11061. r[i + 3] = (sp_digit)t2;
  11062. }
  11063. r[108] = (sp_digit)(t & 0x1ffffffffffffffL);
  11064. }
  11065. #ifndef WOLFSSL_SP_SMALL
  11066. /* Conditionally add a and b using the mask m.
  11067. * m is -1 to add and 0 when not.
  11068. *
  11069. * r A single precision number representing conditional add result.
  11070. * a A single precision number to add with.
  11071. * b A single precision number to add.
  11072. * m Mask value to apply.
  11073. */
  11074. static void sp_3072_cond_add_54(sp_digit* r, const sp_digit* a,
  11075. const sp_digit* b, const sp_digit m)
  11076. {
  11077. int i;
  11078. for (i = 0; i < 48; i += 8) {
  11079. r[i + 0] = a[i + 0] + (b[i + 0] & m);
  11080. r[i + 1] = a[i + 1] + (b[i + 1] & m);
  11081. r[i + 2] = a[i + 2] + (b[i + 2] & m);
  11082. r[i + 3] = a[i + 3] + (b[i + 3] & m);
  11083. r[i + 4] = a[i + 4] + (b[i + 4] & m);
  11084. r[i + 5] = a[i + 5] + (b[i + 5] & m);
  11085. r[i + 6] = a[i + 6] + (b[i + 6] & m);
  11086. r[i + 7] = a[i + 7] + (b[i + 7] & m);
  11087. }
  11088. r[48] = a[48] + (b[48] & m);
  11089. r[49] = a[49] + (b[49] & m);
  11090. r[50] = a[50] + (b[50] & m);
  11091. r[51] = a[51] + (b[51] & m);
  11092. r[52] = a[52] + (b[52] & m);
  11093. r[53] = a[53] + (b[53] & m);
  11094. }
  11095. #endif /* !WOLFSSL_SP_SMALL */
  11096. SP_NOINLINE static void sp_3072_rshift_54(sp_digit* r, const sp_digit* a,
  11097. byte n)
  11098. {
  11099. int i;
  11100. for (i=0; i<48; i += 8) {
  11101. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (57 - n)) & 0x1ffffffffffffffL);
  11102. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (57 - n)) & 0x1ffffffffffffffL);
  11103. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (57 - n)) & 0x1ffffffffffffffL);
  11104. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (57 - n)) & 0x1ffffffffffffffL);
  11105. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (57 - n)) & 0x1ffffffffffffffL);
  11106. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (57 - n)) & 0x1ffffffffffffffL);
  11107. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (57 - n)) & 0x1ffffffffffffffL);
  11108. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (57 - n)) & 0x1ffffffffffffffL);
  11109. }
  11110. r[48] = (a[48] >> n) | ((a[49] << (57 - n)) & 0x1ffffffffffffffL);
  11111. r[49] = (a[49] >> n) | ((a[50] << (57 - n)) & 0x1ffffffffffffffL);
  11112. r[50] = (a[50] >> n) | ((a[51] << (57 - n)) & 0x1ffffffffffffffL);
  11113. r[51] = (a[51] >> n) | ((a[52] << (57 - n)) & 0x1ffffffffffffffL);
  11114. r[52] = (a[52] >> n) | ((a[53] << (57 - n)) & 0x1ffffffffffffffL);
  11115. r[53] = a[53] >> n;
  11116. }
  11117. static WC_INLINE sp_digit sp_3072_div_word_54(sp_digit d1, sp_digit d0,
  11118. sp_digit div)
  11119. {
  11120. #ifdef SP_USE_DIVTI3
  11121. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  11122. return d / div;
  11123. #elif defined(__x86_64__) || defined(__i386__)
  11124. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  11125. sp_uint64 lo = (sp_uint64)d;
  11126. sp_digit hi = (sp_digit)(d >> 64);
  11127. __asm__ __volatile__ (
  11128. "idiv %2"
  11129. : "+a" (lo)
  11130. : "d" (hi), "r" (div)
  11131. : "cc"
  11132. );
  11133. return (sp_digit)lo;
  11134. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  11135. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  11136. sp_digit dv = (div >> 1) + 1;
  11137. sp_digit t1 = (sp_digit)(d >> 57);
  11138. sp_digit t0 = (sp_digit)(d & 0x1ffffffffffffffL);
  11139. sp_digit t2;
  11140. sp_digit sign;
  11141. sp_digit r;
  11142. int i;
  11143. sp_int128 m;
  11144. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  11145. t1 -= dv & (0 - r);
  11146. for (i = 55; i >= 1; i--) {
  11147. t1 += t1 + (((sp_uint64)t0 >> 56) & 1);
  11148. t0 <<= 1;
  11149. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  11150. r += r + t2;
  11151. t1 -= dv & (0 - t2);
  11152. t1 += t2;
  11153. }
  11154. r += r + 1;
  11155. m = d - ((sp_int128)r * div);
  11156. r += (sp_digit)(m >> 57);
  11157. m = d - ((sp_int128)r * div);
  11158. r += (sp_digit)(m >> 114) - (sp_digit)(d >> 114);
  11159. m = d - ((sp_int128)r * div);
  11160. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  11161. m *= sign;
  11162. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  11163. r += sign * t2;
  11164. m = d - ((sp_int128)r * div);
  11165. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  11166. m *= sign;
  11167. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  11168. r += sign * t2;
  11169. return r;
  11170. #else
  11171. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  11172. sp_digit r = 0;
  11173. sp_digit t;
  11174. sp_digit dv = (div >> 26) + 1;
  11175. t = (sp_digit)(d >> 52);
  11176. t = (t / dv) << 26;
  11177. r += t;
  11178. d -= (sp_int128)t * div;
  11179. t = (sp_digit)(d >> 21);
  11180. t = t / (dv << 5);
  11181. r += t;
  11182. d -= (sp_int128)t * div;
  11183. t = (sp_digit)d;
  11184. t = t / div;
  11185. r += t;
  11186. d -= (sp_int128)t * div;
  11187. return r;
  11188. #endif
  11189. }
  11190. static WC_INLINE sp_digit sp_3072_word_div_word_54(sp_digit d, sp_digit div)
  11191. {
  11192. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  11193. defined(SP_DIV_WORD_USE_DIV)
  11194. return d / div;
  11195. #else
  11196. return (sp_digit)((sp_uint64)(div - d) >> 63);
  11197. #endif
  11198. }
  11199. /* Divide d in a and put remainder into r (m*d + r = a)
  11200. * m is not calculated as it is not needed at this time.
  11201. *
  11202. * Full implementation.
  11203. *
  11204. * a Number to be divided.
  11205. * d Number to divide with.
  11206. * m Multiplier result.
  11207. * r Remainder from the division.
  11208. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  11209. */
  11210. static int sp_3072_div_54(const sp_digit* a, const sp_digit* d,
  11211. const sp_digit* m, sp_digit* r)
  11212. {
  11213. int i;
  11214. #ifndef WOLFSSL_SP_DIV_64
  11215. #endif
  11216. sp_digit dv;
  11217. sp_digit r1;
  11218. #ifdef WOLFSSL_SP_SMALL_STACK
  11219. sp_digit* t1 = NULL;
  11220. #else
  11221. sp_digit t1[4 * 54 + 3];
  11222. #endif
  11223. sp_digit* t2 = NULL;
  11224. sp_digit* sd = NULL;
  11225. int err = MP_OKAY;
  11226. (void)m;
  11227. #ifdef WOLFSSL_SP_SMALL_STACK
  11228. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 54 + 3), NULL,
  11229. DYNAMIC_TYPE_TMP_BUFFER);
  11230. if (t1 == NULL)
  11231. err = MEMORY_E;
  11232. #endif
  11233. (void)m;
  11234. if (err == MP_OKAY) {
  11235. t2 = t1 + 108 + 1;
  11236. sd = t2 + 54 + 1;
  11237. sp_3072_mul_d_54(sd, d, (sp_digit)1 << 6);
  11238. sp_3072_mul_d_108(t1, a, (sp_digit)1 << 6);
  11239. dv = sd[53];
  11240. t1[54 + 54] += t1[54 + 54 - 1] >> 57;
  11241. t1[54 + 54 - 1] &= 0x1ffffffffffffffL;
  11242. for (i=54; i>=0; i--) {
  11243. r1 = sp_3072_div_word_54(t1[54 + i], t1[54 + i - 1], dv);
  11244. sp_3072_mul_d_54(t2, sd, r1);
  11245. (void)sp_3072_sub_54(&t1[i], &t1[i], t2);
  11246. sp_3072_norm_54(&t1[i]);
  11247. t1[54 + i] -= t2[54];
  11248. t1[54 + i] += t1[54 + i - 1] >> 57;
  11249. t1[54 + i - 1] &= 0x1ffffffffffffffL;
  11250. r1 = sp_3072_div_word_54(-t1[54 + i], -t1[54 + i - 1], dv);
  11251. r1 -= t1[54 + i];
  11252. sp_3072_mul_d_54(t2, sd, r1);
  11253. (void)sp_3072_add_54(&t1[i], &t1[i], t2);
  11254. t1[54 + i] += t1[54 + i - 1] >> 57;
  11255. t1[54 + i - 1] &= 0x1ffffffffffffffL;
  11256. }
  11257. t1[54 - 1] += t1[54 - 2] >> 57;
  11258. t1[54 - 2] &= 0x1ffffffffffffffL;
  11259. r1 = sp_3072_word_div_word_54(t1[54 - 1], dv);
  11260. sp_3072_mul_d_54(t2, sd, r1);
  11261. sp_3072_sub_54(t1, t1, t2);
  11262. XMEMCPY(r, t1, sizeof(*r) * 108U);
  11263. for (i=0; i<53; i++) {
  11264. r[i+1] += r[i] >> 57;
  11265. r[i] &= 0x1ffffffffffffffL;
  11266. }
  11267. sp_3072_cond_add_54(r, r, sd, r[53] >> 63);
  11268. sp_3072_norm_54(r);
  11269. sp_3072_rshift_54(r, r, 6);
  11270. }
  11271. #ifdef WOLFSSL_SP_SMALL_STACK
  11272. if (t1 != NULL)
  11273. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11274. #endif
  11275. return err;
  11276. }
  11277. /* Reduce a modulo m into r. (r = a mod m)
  11278. *
  11279. * r A single precision number that is the reduced result.
  11280. * a A single precision number that is to be reduced.
  11281. * m A single precision number that is the modulus to reduce with.
  11282. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  11283. */
  11284. static int sp_3072_mod_54(sp_digit* r, const sp_digit* a, const sp_digit* m)
  11285. {
  11286. return sp_3072_div_54(a, m, NULL, r);
  11287. }
  11288. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  11289. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  11290. defined(WOLFSSL_HAVE_SP_DH)
  11291. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  11292. *
  11293. * r A single precision number that is the result of the operation.
  11294. * a A single precision number being exponentiated.
  11295. * e A single precision number that is the exponent.
  11296. * bits The number of bits in the exponent.
  11297. * m A single precision number that is the modulus.
  11298. * returns 0 on success.
  11299. * returns MEMORY_E on dynamic memory allocation failure.
  11300. * returns MP_VAL when base is even or exponent is 0.
  11301. */
  11302. static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e,
  11303. int bits, const sp_digit* m, int reduceA)
  11304. {
  11305. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  11306. #ifdef WOLFSSL_SP_SMALL_STACK
  11307. sp_digit* td = NULL;
  11308. #else
  11309. sp_digit td[3 * 108];
  11310. #endif
  11311. sp_digit* t[3] = {0, 0, 0};
  11312. sp_digit* norm = NULL;
  11313. sp_digit mp = 1;
  11314. sp_digit n;
  11315. int i;
  11316. int c;
  11317. byte y;
  11318. int err = MP_OKAY;
  11319. if (bits == 0) {
  11320. err = MP_VAL;
  11321. }
  11322. #ifdef WOLFSSL_SP_SMALL_STACK
  11323. if (err == MP_OKAY) {
  11324. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 54 * 2, NULL,
  11325. DYNAMIC_TYPE_TMP_BUFFER);
  11326. if (td == NULL)
  11327. err = MEMORY_E;
  11328. }
  11329. #endif
  11330. if (err == MP_OKAY) {
  11331. norm = td;
  11332. for (i=0; i<3; i++) {
  11333. t[i] = td + (i * 54 * 2);
  11334. XMEMSET(t[i], 0, sizeof(sp_digit) * 54U * 2U);
  11335. }
  11336. sp_3072_mont_setup(m, &mp);
  11337. sp_3072_mont_norm_54(norm, m);
  11338. if (reduceA != 0) {
  11339. err = sp_3072_mod_54(t[1], a, m);
  11340. }
  11341. else {
  11342. XMEMCPY(t[1], a, sizeof(sp_digit) * 54U);
  11343. }
  11344. }
  11345. if (err == MP_OKAY) {
  11346. sp_3072_mul_54(t[1], t[1], norm);
  11347. err = sp_3072_mod_54(t[1], t[1], m);
  11348. }
  11349. if (err == MP_OKAY) {
  11350. i = bits / 57;
  11351. c = bits % 57;
  11352. n = e[i--] << (57 - c);
  11353. for (; ; c--) {
  11354. if (c == 0) {
  11355. if (i == -1) {
  11356. break;
  11357. }
  11358. n = e[i--];
  11359. c = 57;
  11360. }
  11361. y = (int)((n >> 56) & 1);
  11362. n <<= 1;
  11363. sp_3072_mont_mul_54(t[y^1], t[0], t[1], m, mp);
  11364. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  11365. ((size_t)t[1] & addr_mask[y])),
  11366. sizeof(*t[2]) * 54 * 2);
  11367. sp_3072_mont_sqr_54(t[2], t[2], m, mp);
  11368. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  11369. ((size_t)t[1] & addr_mask[y])), t[2],
  11370. sizeof(*t[2]) * 54 * 2);
  11371. }
  11372. sp_3072_mont_reduce_54(t[0], m, mp);
  11373. n = sp_3072_cmp_54(t[0], m);
  11374. sp_3072_cond_sub_54(t[0], t[0], m, ~(n >> 63));
  11375. XMEMCPY(r, t[0], sizeof(*r) * 54 * 2);
  11376. }
  11377. #ifdef WOLFSSL_SP_SMALL_STACK
  11378. if (td != NULL)
  11379. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11380. #endif
  11381. return err;
  11382. #elif !defined(WC_NO_CACHE_RESISTANT)
  11383. #ifdef WOLFSSL_SP_SMALL_STACK
  11384. sp_digit* td = NULL;
  11385. #else
  11386. sp_digit td[3 * 108];
  11387. #endif
  11388. sp_digit* t[3] = {0, 0, 0};
  11389. sp_digit* norm = NULL;
  11390. sp_digit mp = 1;
  11391. sp_digit n;
  11392. int i;
  11393. int c;
  11394. byte y;
  11395. int err = MP_OKAY;
  11396. if (bits == 0) {
  11397. err = MP_VAL;
  11398. }
  11399. #ifdef WOLFSSL_SP_SMALL_STACK
  11400. if (err == MP_OKAY) {
  11401. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 54 * 2, NULL,
  11402. DYNAMIC_TYPE_TMP_BUFFER);
  11403. if (td == NULL)
  11404. err = MEMORY_E;
  11405. }
  11406. #endif
  11407. if (err == MP_OKAY) {
  11408. norm = td;
  11409. for (i=0; i<3; i++) {
  11410. t[i] = td + (i * 54 * 2);
  11411. }
  11412. sp_3072_mont_setup(m, &mp);
  11413. sp_3072_mont_norm_54(norm, m);
  11414. if (reduceA != 0) {
  11415. err = sp_3072_mod_54(t[1], a, m);
  11416. if (err == MP_OKAY) {
  11417. sp_3072_mul_54(t[1], t[1], norm);
  11418. err = sp_3072_mod_54(t[1], t[1], m);
  11419. }
  11420. }
  11421. else {
  11422. sp_3072_mul_54(t[1], a, norm);
  11423. err = sp_3072_mod_54(t[1], t[1], m);
  11424. }
  11425. }
  11426. if (err == MP_OKAY) {
  11427. i = bits / 57;
  11428. c = bits % 57;
  11429. n = e[i--] << (57 - c);
  11430. for (; ; c--) {
  11431. if (c == 0) {
  11432. if (i == -1) {
  11433. break;
  11434. }
  11435. n = e[i--];
  11436. c = 57;
  11437. }
  11438. y = (int)((n >> 56) & 1);
  11439. n <<= 1;
  11440. sp_3072_mont_mul_54(t[y^1], t[0], t[1], m, mp);
  11441. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  11442. ((size_t)t[1] & addr_mask[y])),
  11443. sizeof(*t[2]) * 54 * 2);
  11444. sp_3072_mont_sqr_54(t[2], t[2], m, mp);
  11445. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  11446. ((size_t)t[1] & addr_mask[y])), t[2],
  11447. sizeof(*t[2]) * 54 * 2);
  11448. }
  11449. sp_3072_mont_reduce_54(t[0], m, mp);
  11450. n = sp_3072_cmp_54(t[0], m);
  11451. sp_3072_cond_sub_54(t[0], t[0], m, ~(n >> 63));
  11452. XMEMCPY(r, t[0], sizeof(*r) * 54 * 2);
  11453. }
  11454. #ifdef WOLFSSL_SP_SMALL_STACK
  11455. if (td != NULL)
  11456. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11457. #endif
  11458. return err;
  11459. #else
  11460. #ifdef WOLFSSL_SP_SMALL_STACK
  11461. sp_digit* td = NULL;
  11462. #else
  11463. sp_digit td[(16 * 108) + 108];
  11464. #endif
  11465. sp_digit* t[16];
  11466. sp_digit* rt = NULL;
  11467. sp_digit* norm = NULL;
  11468. sp_digit mp = 1;
  11469. sp_digit n;
  11470. int i;
  11471. int c;
  11472. byte y;
  11473. int err = MP_OKAY;
  11474. if (bits == 0) {
  11475. err = MP_VAL;
  11476. }
  11477. #ifdef WOLFSSL_SP_SMALL_STACK
  11478. if (err == MP_OKAY) {
  11479. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 108) + 108), NULL,
  11480. DYNAMIC_TYPE_TMP_BUFFER);
  11481. if (td == NULL)
  11482. err = MEMORY_E;
  11483. }
  11484. #endif
  11485. if (err == MP_OKAY) {
  11486. norm = td;
  11487. for (i=0; i<16; i++)
  11488. t[i] = td + i * 108;
  11489. rt = td + 1728;
  11490. sp_3072_mont_setup(m, &mp);
  11491. sp_3072_mont_norm_54(norm, m);
  11492. if (reduceA != 0) {
  11493. err = sp_3072_mod_54(t[1], a, m);
  11494. if (err == MP_OKAY) {
  11495. sp_3072_mul_54(t[1], t[1], norm);
  11496. err = sp_3072_mod_54(t[1], t[1], m);
  11497. }
  11498. }
  11499. else {
  11500. sp_3072_mul_54(t[1], a, norm);
  11501. err = sp_3072_mod_54(t[1], t[1], m);
  11502. }
  11503. }
  11504. if (err == MP_OKAY) {
  11505. sp_3072_mont_sqr_54(t[ 2], t[ 1], m, mp);
  11506. sp_3072_mont_mul_54(t[ 3], t[ 2], t[ 1], m, mp);
  11507. sp_3072_mont_sqr_54(t[ 4], t[ 2], m, mp);
  11508. sp_3072_mont_mul_54(t[ 5], t[ 3], t[ 2], m, mp);
  11509. sp_3072_mont_sqr_54(t[ 6], t[ 3], m, mp);
  11510. sp_3072_mont_mul_54(t[ 7], t[ 4], t[ 3], m, mp);
  11511. sp_3072_mont_sqr_54(t[ 8], t[ 4], m, mp);
  11512. sp_3072_mont_mul_54(t[ 9], t[ 5], t[ 4], m, mp);
  11513. sp_3072_mont_sqr_54(t[10], t[ 5], m, mp);
  11514. sp_3072_mont_mul_54(t[11], t[ 6], t[ 5], m, mp);
  11515. sp_3072_mont_sqr_54(t[12], t[ 6], m, mp);
  11516. sp_3072_mont_mul_54(t[13], t[ 7], t[ 6], m, mp);
  11517. sp_3072_mont_sqr_54(t[14], t[ 7], m, mp);
  11518. sp_3072_mont_mul_54(t[15], t[ 8], t[ 7], m, mp);
  11519. bits = ((bits + 3) / 4) * 4;
  11520. i = ((bits + 56) / 57) - 1;
  11521. c = bits % 57;
  11522. if (c == 0) {
  11523. c = 57;
  11524. }
  11525. if (i < 54) {
  11526. n = e[i--] << (64 - c);
  11527. }
  11528. else {
  11529. n = 0;
  11530. i--;
  11531. }
  11532. if (c < 4) {
  11533. n |= e[i--] << (7 - c);
  11534. c += 57;
  11535. }
  11536. y = (int)((n >> 60) & 0xf);
  11537. n <<= 4;
  11538. c -= 4;
  11539. XMEMCPY(rt, t[y], sizeof(sp_digit) * 108);
  11540. while ((i >= 0) || (c >= 4)) {
  11541. if (c >= 4) {
  11542. y = (byte)((n >> 60) & 0xf);
  11543. n <<= 4;
  11544. c -= 4;
  11545. }
  11546. else if (c == 0) {
  11547. n = e[i--] << 7;
  11548. y = (byte)((n >> 60) & 0xf);
  11549. n <<= 4;
  11550. c = 53;
  11551. }
  11552. else {
  11553. y = (byte)((n >> 60) & 0xf);
  11554. n = e[i--] << 7;
  11555. c = 4 - c;
  11556. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  11557. n <<= c;
  11558. c = 57 - c;
  11559. }
  11560. sp_3072_mont_sqr_54(rt, rt, m, mp);
  11561. sp_3072_mont_sqr_54(rt, rt, m, mp);
  11562. sp_3072_mont_sqr_54(rt, rt, m, mp);
  11563. sp_3072_mont_sqr_54(rt, rt, m, mp);
  11564. sp_3072_mont_mul_54(rt, rt, t[y], m, mp);
  11565. }
  11566. sp_3072_mont_reduce_54(rt, m, mp);
  11567. n = sp_3072_cmp_54(rt, m);
  11568. sp_3072_cond_sub_54(rt, rt, m, ~(n >> 63));
  11569. XMEMCPY(r, rt, sizeof(sp_digit) * 108);
  11570. }
  11571. #ifdef WOLFSSL_SP_SMALL_STACK
  11572. if (td != NULL)
  11573. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11574. #endif
  11575. return err;
  11576. #endif
  11577. }
  11578. #endif /* (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) || */
  11579. /* WOLFSSL_HAVE_SP_DH */
  11580. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  11581. #ifdef WOLFSSL_HAVE_SP_RSA
  11582. /* RSA public key operation.
  11583. *
  11584. * in Array of bytes representing the number to exponentiate, base.
  11585. * inLen Number of bytes in base.
  11586. * em Public exponent.
  11587. * mm Modulus.
  11588. * out Buffer to hold big-endian bytes of exponentiation result.
  11589. * Must be at least 384 bytes long.
  11590. * outLen Number of bytes in result.
  11591. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  11592. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  11593. */
  11594. int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em,
  11595. const mp_int* mm, byte* out, word32* outLen)
  11596. {
  11597. #ifdef WOLFSSL_SP_SMALL
  11598. #ifdef WOLFSSL_SP_SMALL_STACK
  11599. sp_digit* a = NULL;
  11600. #else
  11601. sp_digit a[54 * 5];
  11602. #endif
  11603. sp_digit* m = NULL;
  11604. sp_digit* r = NULL;
  11605. sp_digit* norm = NULL;
  11606. sp_digit e[1] = {0};
  11607. sp_digit mp = 0;
  11608. int i;
  11609. int err = MP_OKAY;
  11610. if (*outLen < 384U) {
  11611. err = MP_TO_E;
  11612. }
  11613. if (err == MP_OKAY) {
  11614. if (mp_count_bits(em) > 57) {
  11615. err = MP_READ_E;
  11616. }
  11617. else if (inLen > 384U) {
  11618. err = MP_READ_E;
  11619. }
  11620. else if (mp_count_bits(mm) != 3072) {
  11621. err = MP_READ_E;
  11622. }
  11623. else if (mp_iseven(mm)) {
  11624. err = MP_VAL;
  11625. }
  11626. }
  11627. #ifdef WOLFSSL_SP_SMALL_STACK
  11628. if (err == MP_OKAY) {
  11629. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 5, NULL,
  11630. DYNAMIC_TYPE_RSA);
  11631. if (a == NULL)
  11632. err = MEMORY_E;
  11633. }
  11634. #endif
  11635. if (err == MP_OKAY) {
  11636. r = a + 54 * 2;
  11637. m = r + 54 * 2;
  11638. norm = r;
  11639. sp_3072_from_bin(a, 54, in, inLen);
  11640. #if DIGIT_BIT >= 57
  11641. e[0] = (sp_digit)em->dp[0];
  11642. #else
  11643. e[0] = (sp_digit)em->dp[0];
  11644. if (em->used > 1) {
  11645. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  11646. }
  11647. #endif
  11648. if (e[0] == 0) {
  11649. err = MP_EXPTMOD_E;
  11650. }
  11651. }
  11652. if (err == MP_OKAY) {
  11653. sp_3072_from_mp(m, 54, mm);
  11654. sp_3072_mont_setup(m, &mp);
  11655. sp_3072_mont_norm_54(norm, m);
  11656. }
  11657. if (err == MP_OKAY) {
  11658. sp_3072_mul_54(a, a, norm);
  11659. err = sp_3072_mod_54(a, a, m);
  11660. }
  11661. if (err == MP_OKAY) {
  11662. for (i=56; i>=0; i--) {
  11663. if ((e[0] >> i) != 0) {
  11664. break;
  11665. }
  11666. }
  11667. XMEMCPY(r, a, sizeof(sp_digit) * 54 * 2);
  11668. for (i--; i>=0; i--) {
  11669. sp_3072_mont_sqr_54(r, r, m, mp);
  11670. if (((e[0] >> i) & 1) == 1) {
  11671. sp_3072_mont_mul_54(r, r, a, m, mp);
  11672. }
  11673. }
  11674. sp_3072_mont_reduce_54(r, m, mp);
  11675. mp = sp_3072_cmp_54(r, m);
  11676. sp_3072_cond_sub_54(r, r, m, ~(mp >> 63));
  11677. sp_3072_to_bin_54(r, out);
  11678. *outLen = 384;
  11679. }
  11680. #ifdef WOLFSSL_SP_SMALL_STACK
  11681. if (a != NULL)
  11682. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  11683. #endif
  11684. return err;
  11685. #else
  11686. #ifdef WOLFSSL_SP_SMALL_STACK
  11687. sp_digit* d = NULL;
  11688. #else
  11689. sp_digit d[54 * 5];
  11690. #endif
  11691. sp_digit* a = NULL;
  11692. sp_digit* m = NULL;
  11693. sp_digit* r = NULL;
  11694. sp_digit e[1] = {0};
  11695. int err = MP_OKAY;
  11696. if (*outLen < 384U) {
  11697. err = MP_TO_E;
  11698. }
  11699. if (err == MP_OKAY) {
  11700. if (mp_count_bits(em) > 57) {
  11701. err = MP_READ_E;
  11702. }
  11703. else if (inLen > 384U) {
  11704. err = MP_READ_E;
  11705. }
  11706. else if (mp_count_bits(mm) != 3072) {
  11707. err = MP_READ_E;
  11708. }
  11709. else if (mp_iseven(mm)) {
  11710. err = MP_VAL;
  11711. }
  11712. }
  11713. #ifdef WOLFSSL_SP_SMALL_STACK
  11714. if (err == MP_OKAY) {
  11715. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 5, NULL,
  11716. DYNAMIC_TYPE_RSA);
  11717. if (d == NULL)
  11718. err = MEMORY_E;
  11719. }
  11720. #endif
  11721. if (err == MP_OKAY) {
  11722. a = d;
  11723. r = a + 54 * 2;
  11724. m = r + 54 * 2;
  11725. sp_3072_from_bin(a, 54, in, inLen);
  11726. #if DIGIT_BIT >= 57
  11727. e[0] = (sp_digit)em->dp[0];
  11728. #else
  11729. e[0] = (sp_digit)em->dp[0];
  11730. if (em->used > 1) {
  11731. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  11732. }
  11733. #endif
  11734. if (e[0] == 0) {
  11735. err = MP_EXPTMOD_E;
  11736. }
  11737. }
  11738. if (err == MP_OKAY) {
  11739. sp_3072_from_mp(m, 54, mm);
  11740. if (e[0] == 0x3) {
  11741. sp_3072_sqr_54(r, a);
  11742. err = sp_3072_mod_54(r, r, m);
  11743. if (err == MP_OKAY) {
  11744. sp_3072_mul_54(r, a, r);
  11745. err = sp_3072_mod_54(r, r, m);
  11746. }
  11747. }
  11748. else {
  11749. sp_digit* norm = r;
  11750. int i;
  11751. sp_digit mp;
  11752. sp_3072_mont_setup(m, &mp);
  11753. sp_3072_mont_norm_54(norm, m);
  11754. sp_3072_mul_54(a, a, norm);
  11755. err = sp_3072_mod_54(a, a, m);
  11756. if (err == MP_OKAY) {
  11757. for (i=56; i>=0; i--) {
  11758. if ((e[0] >> i) != 0) {
  11759. break;
  11760. }
  11761. }
  11762. XMEMCPY(r, a, sizeof(sp_digit) * 108U);
  11763. for (i--; i>=0; i--) {
  11764. sp_3072_mont_sqr_54(r, r, m, mp);
  11765. if (((e[0] >> i) & 1) == 1) {
  11766. sp_3072_mont_mul_54(r, r, a, m, mp);
  11767. }
  11768. }
  11769. sp_3072_mont_reduce_54(r, m, mp);
  11770. mp = sp_3072_cmp_54(r, m);
  11771. sp_3072_cond_sub_54(r, r, m, ~(mp >> 63));
  11772. }
  11773. }
  11774. }
  11775. if (err == MP_OKAY) {
  11776. sp_3072_to_bin_54(r, out);
  11777. *outLen = 384;
  11778. }
  11779. #ifdef WOLFSSL_SP_SMALL_STACK
  11780. if (d != NULL)
  11781. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  11782. #endif
  11783. return err;
  11784. #endif /* WOLFSSL_SP_SMALL */
  11785. }
  11786. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  11787. #if !defined(SP_RSA_PRIVATE_EXP_D) && !defined(RSA_LOW_MEM)
  11788. #endif /* !SP_RSA_PRIVATE_EXP_D & !RSA_LOW_MEM */
  11789. /* RSA private key operation.
  11790. *
  11791. * in Array of bytes representing the number to exponentiate, base.
  11792. * inLen Number of bytes in base.
  11793. * dm Private exponent.
  11794. * pm First prime.
  11795. * qm Second prime.
  11796. * dpm First prime's CRT exponent.
  11797. * dqm Second prime's CRT exponent.
  11798. * qim Inverse of second prime mod p.
  11799. * mm Modulus.
  11800. * out Buffer to hold big-endian bytes of exponentiation result.
  11801. * Must be at least 384 bytes long.
  11802. * outLen Number of bytes in result.
  11803. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  11804. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  11805. */
  11806. int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm,
  11807. const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm,
  11808. const mp_int* qim, const mp_int* mm, byte* out, word32* outLen)
  11809. {
  11810. #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM)
  11811. #if defined(WOLFSSL_SP_SMALL)
  11812. #ifdef WOLFSSL_SP_SMALL_STACK
  11813. sp_digit* d = NULL;
  11814. #else
  11815. sp_digit d[54 * 4];
  11816. #endif
  11817. sp_digit* a = NULL;
  11818. sp_digit* m = NULL;
  11819. sp_digit* r = NULL;
  11820. int err = MP_OKAY;
  11821. (void)pm;
  11822. (void)qm;
  11823. (void)dpm;
  11824. (void)dqm;
  11825. (void)qim;
  11826. if (*outLen < 384U) {
  11827. err = MP_TO_E;
  11828. }
  11829. if (err == MP_OKAY) {
  11830. if (mp_count_bits(dm) > 3072) {
  11831. err = MP_READ_E;
  11832. }
  11833. else if (inLen > 384) {
  11834. err = MP_READ_E;
  11835. }
  11836. else if (mp_count_bits(mm) != 3072) {
  11837. err = MP_READ_E;
  11838. }
  11839. else if (mp_iseven(mm)) {
  11840. err = MP_VAL;
  11841. }
  11842. }
  11843. #ifdef WOLFSSL_SP_SMALL_STACK
  11844. if (err == MP_OKAY) {
  11845. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL,
  11846. DYNAMIC_TYPE_RSA);
  11847. if (d == NULL)
  11848. err = MEMORY_E;
  11849. }
  11850. #endif
  11851. if (err == MP_OKAY) {
  11852. a = d + 54;
  11853. m = a + 108;
  11854. r = a;
  11855. sp_3072_from_bin(a, 54, in, inLen);
  11856. sp_3072_from_mp(d, 54, dm);
  11857. sp_3072_from_mp(m, 54, mm);
  11858. err = sp_3072_mod_exp_54(r, a, d, 3072, m, 0);
  11859. }
  11860. if (err == MP_OKAY) {
  11861. sp_3072_to_bin_54(r, out);
  11862. *outLen = 384;
  11863. }
  11864. #ifdef WOLFSSL_SP_SMALL_STACK
  11865. if (d != NULL)
  11866. #endif
  11867. {
  11868. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  11869. if (a != NULL)
  11870. ForceZero(a, sizeof(sp_digit) * 54);
  11871. #ifdef WOLFSSL_SP_SMALL_STACK
  11872. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  11873. #endif
  11874. }
  11875. return err;
  11876. #else
  11877. #ifdef WOLFSSL_SP_SMALL_STACK
  11878. sp_digit* d = NULL;
  11879. #else
  11880. sp_digit d[54 * 4];
  11881. #endif
  11882. sp_digit* a = NULL;
  11883. sp_digit* m = NULL;
  11884. sp_digit* r = NULL;
  11885. int err = MP_OKAY;
  11886. (void)pm;
  11887. (void)qm;
  11888. (void)dpm;
  11889. (void)dqm;
  11890. (void)qim;
  11891. if (*outLen < 384U) {
  11892. err = MP_TO_E;
  11893. }
  11894. if (err == MP_OKAY) {
  11895. if (mp_count_bits(dm) > 3072) {
  11896. err = MP_READ_E;
  11897. }
  11898. else if (inLen > 384U) {
  11899. err = MP_READ_E;
  11900. }
  11901. else if (mp_count_bits(mm) != 3072) {
  11902. err = MP_READ_E;
  11903. }
  11904. else if (mp_iseven(mm)) {
  11905. err = MP_VAL;
  11906. }
  11907. }
  11908. #ifdef WOLFSSL_SP_SMALL_STACK
  11909. if (err == MP_OKAY) {
  11910. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL,
  11911. DYNAMIC_TYPE_RSA);
  11912. if (d == NULL)
  11913. err = MEMORY_E;
  11914. }
  11915. #endif
  11916. if (err == MP_OKAY) {
  11917. a = d + 54;
  11918. m = a + 108;
  11919. r = a;
  11920. sp_3072_from_bin(a, 54, in, inLen);
  11921. sp_3072_from_mp(d, 54, dm);
  11922. sp_3072_from_mp(m, 54, mm);
  11923. err = sp_3072_mod_exp_54(r, a, d, 3072, m, 0);
  11924. }
  11925. if (err == MP_OKAY) {
  11926. sp_3072_to_bin_54(r, out);
  11927. *outLen = 384;
  11928. }
  11929. #ifdef WOLFSSL_SP_SMALL_STACK
  11930. if (d != NULL)
  11931. #endif
  11932. {
  11933. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  11934. if (a != NULL)
  11935. ForceZero(a, sizeof(sp_digit) * 54);
  11936. #ifdef WOLFSSL_SP_SMALL_STACK
  11937. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  11938. #endif
  11939. }
  11940. return err;
  11941. #endif /* WOLFSSL_SP_SMALL */
  11942. #else
  11943. #if defined(WOLFSSL_SP_SMALL)
  11944. #ifdef WOLFSSL_SP_SMALL_STACK
  11945. sp_digit* a = NULL;
  11946. #else
  11947. sp_digit a[27 * 8];
  11948. #endif
  11949. sp_digit* p = NULL;
  11950. sp_digit* dp = NULL;
  11951. sp_digit* dq = NULL;
  11952. sp_digit* qi = NULL;
  11953. sp_digit* tmpa = NULL;
  11954. sp_digit* tmpb = NULL;
  11955. sp_digit* r = NULL;
  11956. int err = MP_OKAY;
  11957. (void)dm;
  11958. (void)mm;
  11959. if (*outLen < 384U) {
  11960. err = MP_TO_E;
  11961. }
  11962. if (err == MP_OKAY) {
  11963. if (inLen > 384) {
  11964. err = MP_READ_E;
  11965. }
  11966. else if (mp_count_bits(mm) != 3072) {
  11967. err = MP_READ_E;
  11968. }
  11969. else if (mp_iseven(mm)) {
  11970. err = MP_VAL;
  11971. }
  11972. else if (mp_iseven(pm)) {
  11973. err = MP_VAL;
  11974. }
  11975. else if (mp_iseven(qm)) {
  11976. err = MP_VAL;
  11977. }
  11978. }
  11979. #ifdef WOLFSSL_SP_SMALL_STACK
  11980. if (err == MP_OKAY) {
  11981. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 8, NULL,
  11982. DYNAMIC_TYPE_RSA);
  11983. if (a == NULL)
  11984. err = MEMORY_E;
  11985. }
  11986. #endif
  11987. if (err == MP_OKAY) {
  11988. p = a + 54;
  11989. qi = dq = dp = p + 27;
  11990. tmpa = qi + 27;
  11991. tmpb = tmpa + 54;
  11992. r = a;
  11993. sp_3072_from_bin(a, 54, in, inLen);
  11994. sp_3072_from_mp(p, 27, pm);
  11995. sp_3072_from_mp(dp, 27, dpm);
  11996. err = sp_3072_mod_exp_27(tmpa, a, dp, 1536, p, 1);
  11997. }
  11998. if (err == MP_OKAY) {
  11999. sp_3072_from_mp(p, 27, qm);
  12000. sp_3072_from_mp(dq, 27, dqm);
  12001. err = sp_3072_mod_exp_27(tmpb, a, dq, 1536, p, 1);
  12002. }
  12003. if (err == MP_OKAY) {
  12004. sp_3072_from_mp(p, 27, pm);
  12005. (void)sp_3072_sub_27(tmpa, tmpa, tmpb);
  12006. sp_3072_norm_27(tmpa);
  12007. sp_3072_cond_add_27(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[26] >> 63));
  12008. sp_3072_cond_add_27(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[26] >> 63));
  12009. sp_3072_norm_27(tmpa);
  12010. sp_3072_from_mp(qi, 27, qim);
  12011. sp_3072_mul_27(tmpa, tmpa, qi);
  12012. err = sp_3072_mod_27(tmpa, tmpa, p);
  12013. }
  12014. if (err == MP_OKAY) {
  12015. sp_3072_from_mp(p, 27, qm);
  12016. sp_3072_mul_27(tmpa, p, tmpa);
  12017. (void)sp_3072_add_54(r, tmpb, tmpa);
  12018. sp_3072_norm_54(r);
  12019. sp_3072_to_bin_54(r, out);
  12020. *outLen = 384;
  12021. }
  12022. #ifdef WOLFSSL_SP_SMALL_STACK
  12023. if (a != NULL)
  12024. #endif
  12025. {
  12026. ForceZero(a, sizeof(sp_digit) * 27 * 8);
  12027. #ifdef WOLFSSL_SP_SMALL_STACK
  12028. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  12029. #endif
  12030. }
  12031. return err;
  12032. #else
  12033. #ifdef WOLFSSL_SP_SMALL_STACK
  12034. sp_digit* a = NULL;
  12035. #else
  12036. sp_digit a[27 * 13];
  12037. #endif
  12038. sp_digit* p = NULL;
  12039. sp_digit* q = NULL;
  12040. sp_digit* dp = NULL;
  12041. sp_digit* dq = NULL;
  12042. sp_digit* qi = NULL;
  12043. sp_digit* tmpa = NULL;
  12044. sp_digit* tmpb = NULL;
  12045. sp_digit* r = NULL;
  12046. int err = MP_OKAY;
  12047. (void)dm;
  12048. (void)mm;
  12049. if (*outLen < 384U) {
  12050. err = MP_TO_E;
  12051. }
  12052. if (err == MP_OKAY) {
  12053. if (inLen > 384U) {
  12054. err = MP_READ_E;
  12055. }
  12056. else if (mp_count_bits(mm) != 3072) {
  12057. err = MP_READ_E;
  12058. }
  12059. else if (mp_iseven(mm)) {
  12060. err = MP_VAL;
  12061. }
  12062. else if (mp_iseven(pm)) {
  12063. err = MP_VAL;
  12064. }
  12065. else if (mp_iseven(qm)) {
  12066. err = MP_VAL;
  12067. }
  12068. }
  12069. #ifdef WOLFSSL_SP_SMALL_STACK
  12070. if (err == MP_OKAY) {
  12071. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 13, NULL,
  12072. DYNAMIC_TYPE_RSA);
  12073. if (a == NULL)
  12074. err = MEMORY_E;
  12075. }
  12076. #endif
  12077. if (err == MP_OKAY) {
  12078. p = a + 54 * 2;
  12079. q = p + 27;
  12080. dp = q + 27;
  12081. dq = dp + 27;
  12082. qi = dq + 27;
  12083. tmpa = qi + 27;
  12084. tmpb = tmpa + 54;
  12085. r = a;
  12086. sp_3072_from_bin(a, 54, in, inLen);
  12087. sp_3072_from_mp(p, 27, pm);
  12088. sp_3072_from_mp(q, 27, qm);
  12089. sp_3072_from_mp(dp, 27, dpm);
  12090. sp_3072_from_mp(dq, 27, dqm);
  12091. sp_3072_from_mp(qi, 27, qim);
  12092. err = sp_3072_mod_exp_27(tmpa, a, dp, 1536, p, 1);
  12093. }
  12094. if (err == MP_OKAY) {
  12095. err = sp_3072_mod_exp_27(tmpb, a, dq, 1536, q, 1);
  12096. }
  12097. if (err == MP_OKAY) {
  12098. (void)sp_3072_sub_27(tmpa, tmpa, tmpb);
  12099. sp_3072_norm_27(tmpa);
  12100. sp_3072_cond_add_27(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[26] >> 63));
  12101. sp_3072_cond_add_27(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[26] >> 63));
  12102. sp_3072_norm_27(tmpa);
  12103. sp_3072_mul_27(tmpa, tmpa, qi);
  12104. err = sp_3072_mod_27(tmpa, tmpa, p);
  12105. }
  12106. if (err == MP_OKAY) {
  12107. sp_3072_mul_27(tmpa, tmpa, q);
  12108. (void)sp_3072_add_54(r, tmpb, tmpa);
  12109. sp_3072_norm_54(r);
  12110. sp_3072_to_bin_54(r, out);
  12111. *outLen = 384;
  12112. }
  12113. #ifdef WOLFSSL_SP_SMALL_STACK
  12114. if (a != NULL)
  12115. #endif
  12116. {
  12117. ForceZero(a, sizeof(sp_digit) * 27 * 13);
  12118. #ifdef WOLFSSL_SP_SMALL_STACK
  12119. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  12120. #endif
  12121. }
  12122. return err;
  12123. #endif /* WOLFSSL_SP_SMALL */
  12124. #endif /* SP_RSA_PRIVATE_EXP_D || RSA_LOW_MEM */
  12125. }
  12126. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  12127. #endif /* WOLFSSL_HAVE_SP_RSA */
  12128. #if defined(WOLFSSL_HAVE_SP_DH) || (defined(WOLFSSL_HAVE_SP_RSA) && \
  12129. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  12130. /* Convert an array of sp_digit to an mp_int.
  12131. *
  12132. * a A single precision integer.
  12133. * r A multi-precision integer.
  12134. */
  12135. static int sp_3072_to_mp(const sp_digit* a, mp_int* r)
  12136. {
  12137. int err;
  12138. err = mp_grow(r, (3072 + DIGIT_BIT - 1) / DIGIT_BIT);
  12139. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  12140. #if DIGIT_BIT == 57
  12141. XMEMCPY(r->dp, a, sizeof(sp_digit) * 54);
  12142. r->used = 54;
  12143. mp_clamp(r);
  12144. #elif DIGIT_BIT < 57
  12145. int i;
  12146. int j = 0;
  12147. int s = 0;
  12148. r->dp[0] = 0;
  12149. for (i = 0; i < 54; i++) {
  12150. r->dp[j] |= (mp_digit)(a[i] << s);
  12151. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  12152. s = DIGIT_BIT - s;
  12153. r->dp[++j] = (mp_digit)(a[i] >> s);
  12154. while (s + DIGIT_BIT <= 57) {
  12155. s += DIGIT_BIT;
  12156. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  12157. if (s == SP_WORD_SIZE) {
  12158. r->dp[j] = 0;
  12159. }
  12160. else {
  12161. r->dp[j] = (mp_digit)(a[i] >> s);
  12162. }
  12163. }
  12164. s = 57 - s;
  12165. }
  12166. r->used = (3072 + DIGIT_BIT - 1) / DIGIT_BIT;
  12167. mp_clamp(r);
  12168. #else
  12169. int i;
  12170. int j = 0;
  12171. int s = 0;
  12172. r->dp[0] = 0;
  12173. for (i = 0; i < 54; i++) {
  12174. r->dp[j] |= ((mp_digit)a[i]) << s;
  12175. if (s + 57 >= DIGIT_BIT) {
  12176. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  12177. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  12178. #endif
  12179. s = DIGIT_BIT - s;
  12180. r->dp[++j] = a[i] >> s;
  12181. s = 57 - s;
  12182. }
  12183. else {
  12184. s += 57;
  12185. }
  12186. }
  12187. r->used = (3072 + DIGIT_BIT - 1) / DIGIT_BIT;
  12188. mp_clamp(r);
  12189. #endif
  12190. }
  12191. return err;
  12192. }
  12193. /* Perform the modular exponentiation for Diffie-Hellman.
  12194. *
  12195. * base Base. MP integer.
  12196. * exp Exponent. MP integer.
  12197. * mod Modulus. MP integer.
  12198. * res Result. MP integer.
  12199. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  12200. * and MEMORY_E if memory allocation fails.
  12201. */
  12202. int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod,
  12203. mp_int* res)
  12204. {
  12205. #ifdef WOLFSSL_SP_SMALL
  12206. int err = MP_OKAY;
  12207. #ifdef WOLFSSL_SP_SMALL_STACK
  12208. sp_digit* b = NULL;
  12209. #else
  12210. sp_digit b[54 * 4];
  12211. #endif
  12212. sp_digit* e = NULL;
  12213. sp_digit* m = NULL;
  12214. sp_digit* r = NULL;
  12215. int expBits = mp_count_bits(exp);
  12216. if (mp_count_bits(base) > 3072) {
  12217. err = MP_READ_E;
  12218. }
  12219. else if (expBits > 3072) {
  12220. err = MP_READ_E;
  12221. }
  12222. else if (mp_count_bits(mod) != 3072) {
  12223. err = MP_READ_E;
  12224. }
  12225. else if (mp_iseven(mod)) {
  12226. err = MP_VAL;
  12227. }
  12228. #ifdef WOLFSSL_SP_SMALL_STACK
  12229. if (err == MP_OKAY) {
  12230. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL,
  12231. DYNAMIC_TYPE_DH);
  12232. if (b == NULL)
  12233. err = MEMORY_E;
  12234. }
  12235. #endif
  12236. if (err == MP_OKAY) {
  12237. e = b + 54 * 2;
  12238. m = e + 54;
  12239. r = b;
  12240. sp_3072_from_mp(b, 54, base);
  12241. sp_3072_from_mp(e, 54, exp);
  12242. sp_3072_from_mp(m, 54, mod);
  12243. err = sp_3072_mod_exp_54(r, b, e, mp_count_bits(exp), m, 0);
  12244. }
  12245. if (err == MP_OKAY) {
  12246. err = sp_3072_to_mp(r, res);
  12247. }
  12248. #ifdef WOLFSSL_SP_SMALL_STACK
  12249. if (b != NULL)
  12250. #endif
  12251. {
  12252. /* only "e" is sensitive and needs zeroized */
  12253. if (e != NULL)
  12254. ForceZero(e, sizeof(sp_digit) * 54U);
  12255. #ifdef WOLFSSL_SP_SMALL_STACK
  12256. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  12257. #endif
  12258. }
  12259. return err;
  12260. #else
  12261. #ifdef WOLFSSL_SP_SMALL_STACK
  12262. sp_digit* b = NULL;
  12263. #else
  12264. sp_digit b[54 * 4];
  12265. #endif
  12266. sp_digit* e = NULL;
  12267. sp_digit* m = NULL;
  12268. sp_digit* r = NULL;
  12269. int err = MP_OKAY;
  12270. int expBits = mp_count_bits(exp);
  12271. if (mp_count_bits(base) > 3072) {
  12272. err = MP_READ_E;
  12273. }
  12274. else if (expBits > 3072) {
  12275. err = MP_READ_E;
  12276. }
  12277. else if (mp_count_bits(mod) != 3072) {
  12278. err = MP_READ_E;
  12279. }
  12280. else if (mp_iseven(mod)) {
  12281. err = MP_VAL;
  12282. }
  12283. #ifdef WOLFSSL_SP_SMALL_STACK
  12284. if (err == MP_OKAY) {
  12285. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL, DYNAMIC_TYPE_DH);
  12286. if (b == NULL)
  12287. err = MEMORY_E;
  12288. }
  12289. #endif
  12290. if (err == MP_OKAY) {
  12291. e = b + 54 * 2;
  12292. m = e + 54;
  12293. r = b;
  12294. sp_3072_from_mp(b, 54, base);
  12295. sp_3072_from_mp(e, 54, exp);
  12296. sp_3072_from_mp(m, 54, mod);
  12297. err = sp_3072_mod_exp_54(r, b, e, expBits, m, 0);
  12298. }
  12299. if (err == MP_OKAY) {
  12300. err = sp_3072_to_mp(r, res);
  12301. }
  12302. #ifdef WOLFSSL_SP_SMALL_STACK
  12303. if (b != NULL)
  12304. #endif
  12305. {
  12306. /* only "e" is sensitive and needs zeroized */
  12307. if (e != NULL)
  12308. ForceZero(e, sizeof(sp_digit) * 54U);
  12309. #ifdef WOLFSSL_SP_SMALL_STACK
  12310. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  12311. #endif
  12312. }
  12313. return err;
  12314. #endif
  12315. }
  12316. #ifdef WOLFSSL_HAVE_SP_DH
  12317. #ifdef HAVE_FFDHE_3072
  12318. SP_NOINLINE static void sp_3072_lshift_54(sp_digit* r, const sp_digit* a,
  12319. byte n)
  12320. {
  12321. sp_int_digit s;
  12322. sp_int_digit t;
  12323. s = (sp_int_digit)a[53];
  12324. r[54] = s >> (57U - n);
  12325. s = (sp_int_digit)(a[53]); t = (sp_int_digit)(a[52]);
  12326. r[53] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12327. s = (sp_int_digit)(a[52]); t = (sp_int_digit)(a[51]);
  12328. r[52] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12329. s = (sp_int_digit)(a[51]); t = (sp_int_digit)(a[50]);
  12330. r[51] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12331. s = (sp_int_digit)(a[50]); t = (sp_int_digit)(a[49]);
  12332. r[50] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12333. s = (sp_int_digit)(a[49]); t = (sp_int_digit)(a[48]);
  12334. r[49] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12335. s = (sp_int_digit)(a[48]); t = (sp_int_digit)(a[47]);
  12336. r[48] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12337. s = (sp_int_digit)(a[47]); t = (sp_int_digit)(a[46]);
  12338. r[47] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12339. s = (sp_int_digit)(a[46]); t = (sp_int_digit)(a[45]);
  12340. r[46] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12341. s = (sp_int_digit)(a[45]); t = (sp_int_digit)(a[44]);
  12342. r[45] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12343. s = (sp_int_digit)(a[44]); t = (sp_int_digit)(a[43]);
  12344. r[44] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12345. s = (sp_int_digit)(a[43]); t = (sp_int_digit)(a[42]);
  12346. r[43] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12347. s = (sp_int_digit)(a[42]); t = (sp_int_digit)(a[41]);
  12348. r[42] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12349. s = (sp_int_digit)(a[41]); t = (sp_int_digit)(a[40]);
  12350. r[41] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12351. s = (sp_int_digit)(a[40]); t = (sp_int_digit)(a[39]);
  12352. r[40] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12353. s = (sp_int_digit)(a[39]); t = (sp_int_digit)(a[38]);
  12354. r[39] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12355. s = (sp_int_digit)(a[38]); t = (sp_int_digit)(a[37]);
  12356. r[38] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12357. s = (sp_int_digit)(a[37]); t = (sp_int_digit)(a[36]);
  12358. r[37] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12359. s = (sp_int_digit)(a[36]); t = (sp_int_digit)(a[35]);
  12360. r[36] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12361. s = (sp_int_digit)(a[35]); t = (sp_int_digit)(a[34]);
  12362. r[35] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12363. s = (sp_int_digit)(a[34]); t = (sp_int_digit)(a[33]);
  12364. r[34] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12365. s = (sp_int_digit)(a[33]); t = (sp_int_digit)(a[32]);
  12366. r[33] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12367. s = (sp_int_digit)(a[32]); t = (sp_int_digit)(a[31]);
  12368. r[32] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12369. s = (sp_int_digit)(a[31]); t = (sp_int_digit)(a[30]);
  12370. r[31] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12371. s = (sp_int_digit)(a[30]); t = (sp_int_digit)(a[29]);
  12372. r[30] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12373. s = (sp_int_digit)(a[29]); t = (sp_int_digit)(a[28]);
  12374. r[29] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12375. s = (sp_int_digit)(a[28]); t = (sp_int_digit)(a[27]);
  12376. r[28] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12377. s = (sp_int_digit)(a[27]); t = (sp_int_digit)(a[26]);
  12378. r[27] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12379. s = (sp_int_digit)(a[26]); t = (sp_int_digit)(a[25]);
  12380. r[26] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12381. s = (sp_int_digit)(a[25]); t = (sp_int_digit)(a[24]);
  12382. r[25] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12383. s = (sp_int_digit)(a[24]); t = (sp_int_digit)(a[23]);
  12384. r[24] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12385. s = (sp_int_digit)(a[23]); t = (sp_int_digit)(a[22]);
  12386. r[23] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12387. s = (sp_int_digit)(a[22]); t = (sp_int_digit)(a[21]);
  12388. r[22] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12389. s = (sp_int_digit)(a[21]); t = (sp_int_digit)(a[20]);
  12390. r[21] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12391. s = (sp_int_digit)(a[20]); t = (sp_int_digit)(a[19]);
  12392. r[20] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12393. s = (sp_int_digit)(a[19]); t = (sp_int_digit)(a[18]);
  12394. r[19] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12395. s = (sp_int_digit)(a[18]); t = (sp_int_digit)(a[17]);
  12396. r[18] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12397. s = (sp_int_digit)(a[17]); t = (sp_int_digit)(a[16]);
  12398. r[17] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12399. s = (sp_int_digit)(a[16]); t = (sp_int_digit)(a[15]);
  12400. r[16] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12401. s = (sp_int_digit)(a[15]); t = (sp_int_digit)(a[14]);
  12402. r[15] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12403. s = (sp_int_digit)(a[14]); t = (sp_int_digit)(a[13]);
  12404. r[14] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12405. s = (sp_int_digit)(a[13]); t = (sp_int_digit)(a[12]);
  12406. r[13] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12407. s = (sp_int_digit)(a[12]); t = (sp_int_digit)(a[11]);
  12408. r[12] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12409. s = (sp_int_digit)(a[11]); t = (sp_int_digit)(a[10]);
  12410. r[11] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12411. s = (sp_int_digit)(a[10]); t = (sp_int_digit)(a[9]);
  12412. r[10] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12413. s = (sp_int_digit)(a[9]); t = (sp_int_digit)(a[8]);
  12414. r[9] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12415. s = (sp_int_digit)(a[8]); t = (sp_int_digit)(a[7]);
  12416. r[8] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12417. s = (sp_int_digit)(a[7]); t = (sp_int_digit)(a[6]);
  12418. r[7] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12419. s = (sp_int_digit)(a[6]); t = (sp_int_digit)(a[5]);
  12420. r[6] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12421. s = (sp_int_digit)(a[5]); t = (sp_int_digit)(a[4]);
  12422. r[5] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12423. s = (sp_int_digit)(a[4]); t = (sp_int_digit)(a[3]);
  12424. r[4] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12425. s = (sp_int_digit)(a[3]); t = (sp_int_digit)(a[2]);
  12426. r[3] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12427. s = (sp_int_digit)(a[2]); t = (sp_int_digit)(a[1]);
  12428. r[2] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12429. s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]);
  12430. r[1] = ((s << n) | (t >> (57U - n))) & 0x1ffffffffffffffUL;
  12431. r[0] = (a[0] << n) & 0x1ffffffffffffffL;
  12432. }
  12433. /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m)
  12434. *
  12435. * r A single precision number that is the result of the operation.
  12436. * e A single precision number that is the exponent.
  12437. * bits The number of bits in the exponent.
  12438. * m A single precision number that is the modulus.
  12439. * returns 0 on success.
  12440. * returns MEMORY_E on dynamic memory allocation failure.
  12441. * returns MP_VAL when base is even.
  12442. */
  12443. static int sp_3072_mod_exp_2_54(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
  12444. {
  12445. #ifdef WOLFSSL_SP_SMALL_STACK
  12446. sp_digit* td = NULL;
  12447. #else
  12448. sp_digit td[163];
  12449. #endif
  12450. sp_digit* norm = NULL;
  12451. sp_digit* tmp = NULL;
  12452. sp_digit mp = 1;
  12453. sp_digit n;
  12454. sp_digit o;
  12455. int i;
  12456. int c;
  12457. byte y;
  12458. int err = MP_OKAY;
  12459. if (bits == 0) {
  12460. err = MP_VAL;
  12461. }
  12462. #ifdef WOLFSSL_SP_SMALL_STACK
  12463. if (err == MP_OKAY) {
  12464. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 163, NULL,
  12465. DYNAMIC_TYPE_TMP_BUFFER);
  12466. if (td == NULL)
  12467. err = MEMORY_E;
  12468. }
  12469. #endif
  12470. if (err == MP_OKAY) {
  12471. norm = td;
  12472. tmp = td + 108;
  12473. XMEMSET(td, 0, sizeof(sp_digit) * 163);
  12474. sp_3072_mont_setup(m, &mp);
  12475. sp_3072_mont_norm_54(norm, m);
  12476. bits = ((bits + 4) / 5) * 5;
  12477. i = ((bits + 56) / 57) - 1;
  12478. c = bits % 57;
  12479. if (c == 0) {
  12480. c = 57;
  12481. }
  12482. if (i < 54) {
  12483. n = e[i--] << (64 - c);
  12484. }
  12485. else {
  12486. n = 0;
  12487. i--;
  12488. }
  12489. if (c < 5) {
  12490. n |= e[i--] << (7 - c);
  12491. c += 57;
  12492. }
  12493. y = (int)((n >> 59) & 0x1f);
  12494. n <<= 5;
  12495. c -= 5;
  12496. sp_3072_lshift_54(r, norm, (byte)y);
  12497. while ((i >= 0) || (c >= 5)) {
  12498. if (c >= 5) {
  12499. y = (byte)((n >> 59) & 0x1f);
  12500. n <<= 5;
  12501. c -= 5;
  12502. }
  12503. else if (c == 0) {
  12504. n = e[i--] << 7;
  12505. y = (byte)((n >> 59) & 0x1f);
  12506. n <<= 5;
  12507. c = 52;
  12508. }
  12509. else {
  12510. y = (byte)((n >> 59) & 0x1f);
  12511. n = e[i--] << 7;
  12512. c = 5 - c;
  12513. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  12514. n <<= c;
  12515. c = 57 - c;
  12516. }
  12517. sp_3072_mont_sqr_54(r, r, m, mp);
  12518. sp_3072_mont_sqr_54(r, r, m, mp);
  12519. sp_3072_mont_sqr_54(r, r, m, mp);
  12520. sp_3072_mont_sqr_54(r, r, m, mp);
  12521. sp_3072_mont_sqr_54(r, r, m, mp);
  12522. sp_3072_lshift_54(r, r, (byte)y);
  12523. sp_3072_mul_d_54(tmp, norm, (r[54] << 6) + (r[53] >> 51));
  12524. r[54] = 0;
  12525. r[53] &= 0x7ffffffffffffL;
  12526. (void)sp_3072_add_54(r, r, tmp);
  12527. sp_3072_norm_54(r);
  12528. o = sp_3072_cmp_54(r, m);
  12529. sp_3072_cond_sub_54(r, r, m, ~(o >> 63));
  12530. }
  12531. sp_3072_mont_reduce_54(r, m, mp);
  12532. n = sp_3072_cmp_54(r, m);
  12533. sp_3072_cond_sub_54(r, r, m, ~(n >> 63));
  12534. }
  12535. #ifdef WOLFSSL_SP_SMALL_STACK
  12536. if (td != NULL)
  12537. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  12538. #endif
  12539. return err;
  12540. }
  12541. #endif /* HAVE_FFDHE_3072 */
  12542. /* Perform the modular exponentiation for Diffie-Hellman.
  12543. *
  12544. * base Base.
  12545. * exp Array of bytes that is the exponent.
  12546. * expLen Length of data, in bytes, in exponent.
  12547. * mod Modulus.
  12548. * out Buffer to hold big-endian bytes of exponentiation result.
  12549. * Must be at least 384 bytes long.
  12550. * outLen Length, in bytes, of exponentiation result.
  12551. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  12552. * and MEMORY_E if memory allocation fails.
  12553. */
  12554. int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen,
  12555. const mp_int* mod, byte* out, word32* outLen)
  12556. {
  12557. #ifdef WOLFSSL_SP_SMALL_STACK
  12558. sp_digit* b = NULL;
  12559. #else
  12560. sp_digit b[54 * 4];
  12561. #endif
  12562. sp_digit* e = NULL;
  12563. sp_digit* m = NULL;
  12564. sp_digit* r = NULL;
  12565. word32 i;
  12566. int err = MP_OKAY;
  12567. if (mp_count_bits(base) > 3072) {
  12568. err = MP_READ_E;
  12569. }
  12570. else if (expLen > 384U) {
  12571. err = MP_READ_E;
  12572. }
  12573. else if (mp_count_bits(mod) != 3072) {
  12574. err = MP_READ_E;
  12575. }
  12576. else if (mp_iseven(mod)) {
  12577. err = MP_VAL;
  12578. }
  12579. #ifdef WOLFSSL_SP_SMALL_STACK
  12580. if (err == MP_OKAY) {
  12581. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL,
  12582. DYNAMIC_TYPE_DH);
  12583. if (b == NULL)
  12584. err = MEMORY_E;
  12585. }
  12586. #endif
  12587. if (err == MP_OKAY) {
  12588. e = b + 54 * 2;
  12589. m = e + 54;
  12590. r = b;
  12591. sp_3072_from_mp(b, 54, base);
  12592. sp_3072_from_bin(e, 54, exp, expLen);
  12593. sp_3072_from_mp(m, 54, mod);
  12594. #ifdef HAVE_FFDHE_3072
  12595. if (base->used == 1 && base->dp[0] == 2U &&
  12596. (m[53] >> 19) == 0xffffffffL) {
  12597. err = sp_3072_mod_exp_2_54(r, e, expLen * 8U, m);
  12598. }
  12599. else {
  12600. #endif
  12601. err = sp_3072_mod_exp_54(r, b, e, expLen * 8U, m, 0);
  12602. #ifdef HAVE_FFDHE_3072
  12603. }
  12604. #endif
  12605. }
  12606. if (err == MP_OKAY) {
  12607. sp_3072_to_bin_54(r, out);
  12608. *outLen = 384;
  12609. for (i=0; i<384U && out[i] == 0U; i++) {
  12610. /* Search for first non-zero. */
  12611. }
  12612. *outLen -= i;
  12613. XMEMMOVE(out, out + i, *outLen);
  12614. }
  12615. #ifdef WOLFSSL_SP_SMALL_STACK
  12616. if (b != NULL)
  12617. #endif
  12618. {
  12619. /* only "e" is sensitive and needs zeroized */
  12620. if (e != NULL)
  12621. ForceZero(e, sizeof(sp_digit) * 54U);
  12622. #ifdef WOLFSSL_SP_SMALL_STACK
  12623. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  12624. #endif
  12625. }
  12626. return err;
  12627. }
  12628. #endif /* WOLFSSL_HAVE_SP_DH */
  12629. /* Perform the modular exponentiation for Diffie-Hellman.
  12630. *
  12631. * base Base. MP integer.
  12632. * exp Exponent. MP integer.
  12633. * mod Modulus. MP integer.
  12634. * res Result. MP integer.
  12635. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  12636. * and MEMORY_E if memory allocation fails.
  12637. */
  12638. int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod,
  12639. mp_int* res)
  12640. {
  12641. #ifdef WOLFSSL_SP_SMALL
  12642. int err = MP_OKAY;
  12643. #ifdef WOLFSSL_SP_SMALL_STACK
  12644. sp_digit* b = NULL;
  12645. #else
  12646. sp_digit b[27 * 4];
  12647. #endif
  12648. sp_digit* e = NULL;
  12649. sp_digit* m = NULL;
  12650. sp_digit* r = NULL;
  12651. int expBits = mp_count_bits(exp);
  12652. if (mp_count_bits(base) > 1536) {
  12653. err = MP_READ_E;
  12654. }
  12655. else if (expBits > 1536) {
  12656. err = MP_READ_E;
  12657. }
  12658. else if (mp_count_bits(mod) != 1536) {
  12659. err = MP_READ_E;
  12660. }
  12661. else if (mp_iseven(mod)) {
  12662. err = MP_VAL;
  12663. }
  12664. #ifdef WOLFSSL_SP_SMALL_STACK
  12665. if (err == MP_OKAY) {
  12666. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 4, NULL,
  12667. DYNAMIC_TYPE_DH);
  12668. if (b == NULL)
  12669. err = MEMORY_E;
  12670. }
  12671. #endif
  12672. if (err == MP_OKAY) {
  12673. e = b + 27 * 2;
  12674. m = e + 27;
  12675. r = b;
  12676. sp_3072_from_mp(b, 27, base);
  12677. sp_3072_from_mp(e, 27, exp);
  12678. sp_3072_from_mp(m, 27, mod);
  12679. err = sp_3072_mod_exp_27(r, b, e, mp_count_bits(exp), m, 0);
  12680. }
  12681. if (err == MP_OKAY) {
  12682. XMEMSET(r + 27, 0, sizeof(*r) * 27U);
  12683. err = sp_3072_to_mp(r, res);
  12684. }
  12685. #ifdef WOLFSSL_SP_SMALL_STACK
  12686. if (b != NULL)
  12687. #endif
  12688. {
  12689. /* only "e" is sensitive and needs zeroized */
  12690. if (e != NULL)
  12691. ForceZero(e, sizeof(sp_digit) * 54U);
  12692. #ifdef WOLFSSL_SP_SMALL_STACK
  12693. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  12694. #endif
  12695. }
  12696. return err;
  12697. #else
  12698. #ifdef WOLFSSL_SP_SMALL_STACK
  12699. sp_digit* b = NULL;
  12700. #else
  12701. sp_digit b[27 * 4];
  12702. #endif
  12703. sp_digit* e = NULL;
  12704. sp_digit* m = NULL;
  12705. sp_digit* r = NULL;
  12706. int err = MP_OKAY;
  12707. int expBits = mp_count_bits(exp);
  12708. if (mp_count_bits(base) > 1536) {
  12709. err = MP_READ_E;
  12710. }
  12711. else if (expBits > 1536) {
  12712. err = MP_READ_E;
  12713. }
  12714. else if (mp_count_bits(mod) != 1536) {
  12715. err = MP_READ_E;
  12716. }
  12717. else if (mp_iseven(mod)) {
  12718. err = MP_VAL;
  12719. }
  12720. #ifdef WOLFSSL_SP_SMALL_STACK
  12721. if (err == MP_OKAY) {
  12722. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 4, NULL, DYNAMIC_TYPE_DH);
  12723. if (b == NULL)
  12724. err = MEMORY_E;
  12725. }
  12726. #endif
  12727. if (err == MP_OKAY) {
  12728. e = b + 27 * 2;
  12729. m = e + 27;
  12730. r = b;
  12731. sp_3072_from_mp(b, 27, base);
  12732. sp_3072_from_mp(e, 27, exp);
  12733. sp_3072_from_mp(m, 27, mod);
  12734. err = sp_3072_mod_exp_27(r, b, e, expBits, m, 0);
  12735. }
  12736. if (err == MP_OKAY) {
  12737. XMEMSET(r + 27, 0, sizeof(*r) * 27U);
  12738. err = sp_3072_to_mp(r, res);
  12739. }
  12740. #ifdef WOLFSSL_SP_SMALL_STACK
  12741. if (b != NULL)
  12742. #endif
  12743. {
  12744. /* only "e" is sensitive and needs zeroized */
  12745. if (e != NULL)
  12746. ForceZero(e, sizeof(sp_digit) * 54U);
  12747. #ifdef WOLFSSL_SP_SMALL_STACK
  12748. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  12749. #endif
  12750. }
  12751. return err;
  12752. #endif
  12753. }
  12754. #endif /* WOLFSSL_HAVE_SP_DH | (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) */
  12755. #endif /* WOLFSSL_SP_SMALL */
  12756. #endif /* !WOLFSSL_SP_NO_3072 */
  12757. #ifdef WOLFSSL_SP_4096
  12758. #ifdef WOLFSSL_SP_SMALL
  12759. /* Read big endian unsigned byte array into r.
  12760. *
  12761. * r A single precision integer.
  12762. * size Maximum number of bytes to convert
  12763. * a Byte array.
  12764. * n Number of bytes in array to read.
  12765. */
  12766. static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n)
  12767. {
  12768. int i;
  12769. int j = 0;
  12770. word32 s = 0;
  12771. r[0] = 0;
  12772. for (i = n-1; i >= 0; i--) {
  12773. r[j] |= (((sp_digit)a[i]) << s);
  12774. if (s >= 51U) {
  12775. r[j] &= 0x7ffffffffffffffL;
  12776. s = 59U - s;
  12777. if (j + 1 >= size) {
  12778. break;
  12779. }
  12780. r[++j] = (sp_digit)a[i] >> s;
  12781. s = 8U - s;
  12782. }
  12783. else {
  12784. s += 8U;
  12785. }
  12786. }
  12787. for (j++; j < size; j++) {
  12788. r[j] = 0;
  12789. }
  12790. }
  12791. /* Convert an mp_int to an array of sp_digit.
  12792. *
  12793. * r A single precision integer.
  12794. * size Maximum number of bytes to convert
  12795. * a A multi-precision integer.
  12796. */
  12797. static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a)
  12798. {
  12799. #if DIGIT_BIT == 59
  12800. int i;
  12801. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  12802. int o = 0;
  12803. for (i = 0; i < size; i++) {
  12804. sp_digit mask = (sp_digit)0 - (j >> 58);
  12805. r[i] = a->dp[o] & mask;
  12806. j++;
  12807. o += (int)(j >> 58);
  12808. }
  12809. #elif DIGIT_BIT > 59
  12810. unsigned int i;
  12811. int j = 0;
  12812. word32 s = 0;
  12813. r[0] = 0;
  12814. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  12815. r[j] |= ((sp_digit)a->dp[i] << s);
  12816. r[j] &= 0x7ffffffffffffffL;
  12817. s = 59U - s;
  12818. if (j + 1 >= size) {
  12819. break;
  12820. }
  12821. /* lint allow cast of mismatch word32 and mp_digit */
  12822. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  12823. while ((s + 59U) <= (word32)DIGIT_BIT) {
  12824. s += 59U;
  12825. r[j] &= 0x7ffffffffffffffL;
  12826. if (j + 1 >= size) {
  12827. break;
  12828. }
  12829. if (s < (word32)DIGIT_BIT) {
  12830. /* lint allow cast of mismatch word32 and mp_digit */
  12831. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  12832. }
  12833. else {
  12834. r[++j] = (sp_digit)0;
  12835. }
  12836. }
  12837. s = (word32)DIGIT_BIT - s;
  12838. }
  12839. for (j++; j < size; j++) {
  12840. r[j] = 0;
  12841. }
  12842. #else
  12843. unsigned int i;
  12844. int j = 0;
  12845. int s = 0;
  12846. r[0] = 0;
  12847. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  12848. r[j] |= ((sp_digit)a->dp[i]) << s;
  12849. if (s + DIGIT_BIT >= 59) {
  12850. r[j] &= 0x7ffffffffffffffL;
  12851. if (j + 1 >= size) {
  12852. break;
  12853. }
  12854. s = 59 - s;
  12855. if (s == DIGIT_BIT) {
  12856. r[++j] = 0;
  12857. s = 0;
  12858. }
  12859. else {
  12860. r[++j] = a->dp[i] >> s;
  12861. s = DIGIT_BIT - s;
  12862. }
  12863. }
  12864. else {
  12865. s += DIGIT_BIT;
  12866. }
  12867. }
  12868. for (j++; j < size; j++) {
  12869. r[j] = 0;
  12870. }
  12871. #endif
  12872. }
  12873. /* Write r as big endian to byte array.
  12874. * Fixed length number of bytes written: 512
  12875. *
  12876. * r A single precision integer.
  12877. * a Byte array.
  12878. */
  12879. static void sp_4096_to_bin_70(sp_digit* r, byte* a)
  12880. {
  12881. int i;
  12882. int j;
  12883. int s = 0;
  12884. int b;
  12885. for (i=0; i<69; i++) {
  12886. r[i+1] += r[i] >> 59;
  12887. r[i] &= 0x7ffffffffffffffL;
  12888. }
  12889. j = 4103 / 8 - 1;
  12890. a[j] = 0;
  12891. for (i=0; i<70 && j>=0; i++) {
  12892. b = 0;
  12893. /* lint allow cast of mismatch sp_digit and int */
  12894. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  12895. b += 8 - s;
  12896. if (j < 0) {
  12897. break;
  12898. }
  12899. while (b < 59) {
  12900. a[j--] = (byte)(r[i] >> b);
  12901. b += 8;
  12902. if (j < 0) {
  12903. break;
  12904. }
  12905. }
  12906. s = 8 - (b - 59);
  12907. if (j >= 0) {
  12908. a[j] = 0;
  12909. }
  12910. if (s != 0) {
  12911. j++;
  12912. }
  12913. }
  12914. }
  12915. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  12916. #if defined(WOLFSSL_HAVE_SP_RSA) && !defined(SP_RSA_PRIVATE_EXP_D)
  12917. /* Normalize the values in each word to 59 bits.
  12918. *
  12919. * a Array of sp_digit to normalize.
  12920. */
  12921. static void sp_4096_norm_35(sp_digit* a)
  12922. {
  12923. int i;
  12924. for (i = 0; i < 34; i++) {
  12925. a[i+1] += a[i] >> 59;
  12926. a[i] &= 0x7ffffffffffffffL;
  12927. }
  12928. }
  12929. #endif /* WOLFSSL_HAVE_SP_RSA & !SP_RSA_PRIVATE_EXP_D */
  12930. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  12931. /* Normalize the values in each word to 59 bits.
  12932. *
  12933. * a Array of sp_digit to normalize.
  12934. */
  12935. static void sp_4096_norm_70(sp_digit* a)
  12936. {
  12937. int i;
  12938. for (i = 0; i < 69; i++) {
  12939. a[i+1] += a[i] >> 59;
  12940. a[i] &= 0x7ffffffffffffffL;
  12941. }
  12942. }
  12943. /* Multiply a and b into r. (r = a * b)
  12944. *
  12945. * r A single precision integer.
  12946. * a A single precision integer.
  12947. * b A single precision integer.
  12948. */
  12949. SP_NOINLINE static void sp_4096_mul_70(sp_digit* r, const sp_digit* a,
  12950. const sp_digit* b)
  12951. {
  12952. int i;
  12953. int imax;
  12954. int k;
  12955. sp_uint128 c;
  12956. sp_uint128 lo;
  12957. c = ((sp_uint128)a[69]) * b[69];
  12958. r[139] = (sp_digit)(c >> 59);
  12959. c &= 0x7ffffffffffffffL;
  12960. for (k = 137; k >= 0; k--) {
  12961. if (k >= 70) {
  12962. i = k - 69;
  12963. imax = 69;
  12964. }
  12965. else {
  12966. i = 0;
  12967. imax = k;
  12968. }
  12969. lo = 0;
  12970. for (; i <= imax; i++) {
  12971. lo += ((sp_uint128)a[i]) * b[k - i];
  12972. }
  12973. c += lo >> 59;
  12974. r[k + 2] += (sp_digit)(c >> 59);
  12975. r[k + 1] = (sp_digit)(c & 0x7ffffffffffffffL);
  12976. c = lo & 0x7ffffffffffffffL;
  12977. }
  12978. r[0] = (sp_digit)c;
  12979. }
  12980. /* Square a and put result in r. (r = a * a)
  12981. *
  12982. * r A single precision integer.
  12983. * a A single precision integer.
  12984. */
  12985. SP_NOINLINE static void sp_4096_sqr_70(sp_digit* r, const sp_digit* a)
  12986. {
  12987. int i;
  12988. int imax;
  12989. int k;
  12990. sp_uint128 c;
  12991. sp_uint128 t;
  12992. c = ((sp_uint128)a[69]) * a[69];
  12993. r[139] = (sp_digit)(c >> 59);
  12994. c = (c & 0x7ffffffffffffffL) << 59;
  12995. for (k = 137; k >= 0; k--) {
  12996. i = (k + 1) / 2;
  12997. if ((k & 1) == 0) {
  12998. c += ((sp_uint128)a[i]) * a[i];
  12999. i++;
  13000. }
  13001. if (k < 69) {
  13002. imax = k;
  13003. }
  13004. else {
  13005. imax = 69;
  13006. }
  13007. t = 0;
  13008. for (; i <= imax; i++) {
  13009. t += ((sp_uint128)a[i]) * a[k - i];
  13010. }
  13011. c += t * 2;
  13012. r[k + 2] += (sp_digit) (c >> 118);
  13013. r[k + 1] = (sp_digit)((c >> 59) & 0x7ffffffffffffffL);
  13014. c = (c & 0x7ffffffffffffffL) << 59;
  13015. }
  13016. r[0] = (sp_digit)(c >> 59);
  13017. }
  13018. /* Calculate the bottom digit of -1/a mod 2^n.
  13019. *
  13020. * a A single precision number.
  13021. * rho Bottom word of inverse.
  13022. */
  13023. static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho)
  13024. {
  13025. sp_digit x;
  13026. sp_digit b;
  13027. b = a[0];
  13028. x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
  13029. x *= 2 - b * x; /* here x*a==1 mod 2**8 */
  13030. x *= 2 - b * x; /* here x*a==1 mod 2**16 */
  13031. x *= 2 - b * x; /* here x*a==1 mod 2**32 */
  13032. x *= 2 - b * x; /* here x*a==1 mod 2**64 */
  13033. x &= 0x7ffffffffffffffL;
  13034. /* rho = -1/m mod b */
  13035. *rho = ((sp_digit)1 << 59) - x;
  13036. }
  13037. /* Multiply a by scalar b into r. (r = a * b)
  13038. *
  13039. * r A single precision integer.
  13040. * a A single precision integer.
  13041. * b A scalar.
  13042. */
  13043. SP_NOINLINE static void sp_4096_mul_d_70(sp_digit* r, const sp_digit* a,
  13044. sp_digit b)
  13045. {
  13046. sp_int128 tb = b;
  13047. sp_int128 t = 0;
  13048. int i;
  13049. for (i = 0; i < 70; i++) {
  13050. t += tb * a[i];
  13051. r[i] = (sp_digit)(t & 0x7ffffffffffffffL);
  13052. t >>= 59;
  13053. }
  13054. r[70] = (sp_digit)t;
  13055. }
  13056. #if (defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH)) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  13057. #if defined(WOLFSSL_HAVE_SP_RSA) && !defined(SP_RSA_PRIVATE_EXP_D)
  13058. /* Sub b from a into r. (r = a - b)
  13059. *
  13060. * r A single precision integer.
  13061. * a A single precision integer.
  13062. * b A single precision integer.
  13063. */
  13064. SP_NOINLINE static int sp_4096_sub_35(sp_digit* r, const sp_digit* a,
  13065. const sp_digit* b)
  13066. {
  13067. int i;
  13068. for (i = 0; i < 35; i++) {
  13069. r[i] = a[i] - b[i];
  13070. }
  13071. return 0;
  13072. }
  13073. /* r = 2^n mod m where n is the number of bits to reduce by.
  13074. * Given m must be 4096 bits, just need to subtract.
  13075. *
  13076. * r A single precision number.
  13077. * m A single precision number.
  13078. */
  13079. static void sp_4096_mont_norm_35(sp_digit* r, const sp_digit* m)
  13080. {
  13081. /* Set r = 2^n - 1. */
  13082. int i;
  13083. for (i=0; i<34; i++) {
  13084. r[i] = 0x7ffffffffffffffL;
  13085. }
  13086. r[34] = 0x3ffffffffffL;
  13087. /* r = (2^n - 1) mod n */
  13088. (void)sp_4096_sub_35(r, r, m);
  13089. /* Add one so r = 2^n mod m */
  13090. r[0] += 1;
  13091. }
  13092. /* Compare a with b in constant time.
  13093. *
  13094. * a A single precision integer.
  13095. * b A single precision integer.
  13096. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  13097. * respectively.
  13098. */
  13099. static sp_digit sp_4096_cmp_35(const sp_digit* a, const sp_digit* b)
  13100. {
  13101. sp_digit r = 0;
  13102. int i;
  13103. for (i=34; i>=0; i--) {
  13104. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 58);
  13105. }
  13106. return r;
  13107. }
  13108. /* Conditionally subtract b from a using the mask m.
  13109. * m is -1 to subtract and 0 when not.
  13110. *
  13111. * r A single precision number representing condition subtract result.
  13112. * a A single precision number to subtract from.
  13113. * b A single precision number to subtract.
  13114. * m Mask value to apply.
  13115. */
  13116. static void sp_4096_cond_sub_35(sp_digit* r, const sp_digit* a,
  13117. const sp_digit* b, const sp_digit m)
  13118. {
  13119. int i;
  13120. for (i = 0; i < 35; i++) {
  13121. r[i] = a[i] - (b[i] & m);
  13122. }
  13123. }
  13124. /* Mul a by scalar b and add into r. (r += a * b)
  13125. *
  13126. * r A single precision integer.
  13127. * a A single precision integer.
  13128. * b A scalar.
  13129. */
  13130. SP_NOINLINE static void sp_4096_mul_add_35(sp_digit* r, const sp_digit* a,
  13131. const sp_digit b)
  13132. {
  13133. sp_int128 tb = b;
  13134. sp_int128 t[4];
  13135. int i;
  13136. t[0] = 0;
  13137. for (i = 0; i < 32; i += 4) {
  13138. t[0] += (tb * a[i+0]) + r[i+0];
  13139. t[1] = (tb * a[i+1]) + r[i+1];
  13140. t[2] = (tb * a[i+2]) + r[i+2];
  13141. t[3] = (tb * a[i+3]) + r[i+3];
  13142. r[i+0] = t[0] & 0x7ffffffffffffffL;
  13143. t[1] += t[0] >> 59;
  13144. r[i+1] = t[1] & 0x7ffffffffffffffL;
  13145. t[2] += t[1] >> 59;
  13146. r[i+2] = t[2] & 0x7ffffffffffffffL;
  13147. t[3] += t[2] >> 59;
  13148. r[i+3] = t[3] & 0x7ffffffffffffffL;
  13149. t[0] = t[3] >> 59;
  13150. }
  13151. t[0] += (tb * a[32]) + r[32];
  13152. t[1] = (tb * a[33]) + r[33];
  13153. t[2] = (tb * a[34]) + r[34];
  13154. r[32] = t[0] & 0x7ffffffffffffffL;
  13155. t[1] += t[0] >> 59;
  13156. r[33] = t[1] & 0x7ffffffffffffffL;
  13157. t[2] += t[1] >> 59;
  13158. r[34] = t[2] & 0x7ffffffffffffffL;
  13159. r[35] += (sp_digit)(t[2] >> 59);
  13160. }
  13161. /* Shift the result in the high 2048 bits down to the bottom.
  13162. *
  13163. * r A single precision number.
  13164. * a A single precision number.
  13165. */
  13166. static void sp_4096_mont_shift_35(sp_digit* r, const sp_digit* a)
  13167. {
  13168. int i;
  13169. sp_int128 n = a[34] >> 42;
  13170. n += ((sp_int128)a[35]) << 17;
  13171. for (i = 0; i < 34; i++) {
  13172. r[i] = n & 0x7ffffffffffffffL;
  13173. n >>= 59;
  13174. n += ((sp_int128)a[36 + i]) << 17;
  13175. }
  13176. r[34] = (sp_digit)n;
  13177. XMEMSET(&r[35], 0, sizeof(*r) * 35U);
  13178. }
  13179. /* Reduce the number back to 4096 bits using Montgomery reduction.
  13180. *
  13181. * a A single precision number to reduce in place.
  13182. * m The single precision number representing the modulus.
  13183. * mp The digit representing the negative inverse of m mod 2^n.
  13184. */
  13185. static void sp_4096_mont_reduce_35(sp_digit* a, const sp_digit* m, sp_digit mp)
  13186. {
  13187. int i;
  13188. sp_digit mu;
  13189. sp_digit over;
  13190. sp_4096_norm_35(a + 35);
  13191. for (i=0; i<34; i++) {
  13192. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7ffffffffffffffL;
  13193. sp_4096_mul_add_35(a+i, m, mu);
  13194. a[i+1] += a[i] >> 59;
  13195. }
  13196. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x3ffffffffffL;
  13197. sp_4096_mul_add_35(a+i, m, mu);
  13198. a[i+1] += a[i] >> 59;
  13199. a[i] &= 0x7ffffffffffffffL;
  13200. sp_4096_mont_shift_35(a, a);
  13201. over = a[34] - m[34];
  13202. sp_4096_cond_sub_35(a, a, m, ~((over - 1) >> 63));
  13203. sp_4096_norm_35(a);
  13204. }
  13205. /* Multiply a and b into r. (r = a * b)
  13206. *
  13207. * r A single precision integer.
  13208. * a A single precision integer.
  13209. * b A single precision integer.
  13210. */
  13211. SP_NOINLINE static void sp_4096_mul_35(sp_digit* r, const sp_digit* a,
  13212. const sp_digit* b)
  13213. {
  13214. int i;
  13215. int imax;
  13216. int k;
  13217. sp_uint128 c;
  13218. sp_uint128 lo;
  13219. c = ((sp_uint128)a[34]) * b[34];
  13220. r[69] = (sp_digit)(c >> 59);
  13221. c &= 0x7ffffffffffffffL;
  13222. for (k = 67; k >= 0; k--) {
  13223. if (k >= 35) {
  13224. i = k - 34;
  13225. imax = 34;
  13226. }
  13227. else {
  13228. i = 0;
  13229. imax = k;
  13230. }
  13231. lo = 0;
  13232. for (; i <= imax; i++) {
  13233. lo += ((sp_uint128)a[i]) * b[k - i];
  13234. }
  13235. c += lo >> 59;
  13236. r[k + 2] += (sp_digit)(c >> 59);
  13237. r[k + 1] = (sp_digit)(c & 0x7ffffffffffffffL);
  13238. c = lo & 0x7ffffffffffffffL;
  13239. }
  13240. r[0] = (sp_digit)c;
  13241. }
  13242. /* Multiply two Montgomery form numbers mod the modulus (prime).
  13243. * (r = a * b mod m)
  13244. *
  13245. * r Result of multiplication.
  13246. * a First number to multiply in Montgomery form.
  13247. * b Second number to multiply in Montgomery form.
  13248. * m Modulus (prime).
  13249. * mp Montgomery multiplier.
  13250. */
  13251. SP_NOINLINE static void sp_4096_mont_mul_35(sp_digit* r, const sp_digit* a,
  13252. const sp_digit* b, const sp_digit* m, sp_digit mp)
  13253. {
  13254. sp_4096_mul_35(r, a, b);
  13255. sp_4096_mont_reduce_35(r, m, mp);
  13256. }
  13257. /* Square a and put result in r. (r = a * a)
  13258. *
  13259. * r A single precision integer.
  13260. * a A single precision integer.
  13261. */
  13262. SP_NOINLINE static void sp_4096_sqr_35(sp_digit* r, const sp_digit* a)
  13263. {
  13264. int i;
  13265. int imax;
  13266. int k;
  13267. sp_uint128 c;
  13268. sp_uint128 t;
  13269. c = ((sp_uint128)a[34]) * a[34];
  13270. r[69] = (sp_digit)(c >> 59);
  13271. c = (c & 0x7ffffffffffffffL) << 59;
  13272. for (k = 67; k >= 0; k--) {
  13273. i = (k + 1) / 2;
  13274. if ((k & 1) == 0) {
  13275. c += ((sp_uint128)a[i]) * a[i];
  13276. i++;
  13277. }
  13278. if (k < 34) {
  13279. imax = k;
  13280. }
  13281. else {
  13282. imax = 34;
  13283. }
  13284. t = 0;
  13285. for (; i <= imax; i++) {
  13286. t += ((sp_uint128)a[i]) * a[k - i];
  13287. }
  13288. c += t * 2;
  13289. r[k + 2] += (sp_digit) (c >> 118);
  13290. r[k + 1] = (sp_digit)((c >> 59) & 0x7ffffffffffffffL);
  13291. c = (c & 0x7ffffffffffffffL) << 59;
  13292. }
  13293. r[0] = (sp_digit)(c >> 59);
  13294. }
  13295. /* Square the Montgomery form number. (r = a * a mod m)
  13296. *
  13297. * r Result of squaring.
  13298. * a Number to square in Montgomery form.
  13299. * m Modulus (prime).
  13300. * mp Montgomery multiplier.
  13301. */
  13302. SP_NOINLINE static void sp_4096_mont_sqr_35(sp_digit* r, const sp_digit* a,
  13303. const sp_digit* m, sp_digit mp)
  13304. {
  13305. sp_4096_sqr_35(r, a);
  13306. sp_4096_mont_reduce_35(r, m, mp);
  13307. }
  13308. /* Multiply a by scalar b into r. (r = a * b)
  13309. *
  13310. * r A single precision integer.
  13311. * a A single precision integer.
  13312. * b A scalar.
  13313. */
  13314. SP_NOINLINE static void sp_4096_mul_d_35(sp_digit* r, const sp_digit* a,
  13315. sp_digit b)
  13316. {
  13317. sp_int128 tb = b;
  13318. sp_int128 t = 0;
  13319. int i;
  13320. for (i = 0; i < 35; i++) {
  13321. t += tb * a[i];
  13322. r[i] = (sp_digit)(t & 0x7ffffffffffffffL);
  13323. t >>= 59;
  13324. }
  13325. r[35] = (sp_digit)t;
  13326. }
  13327. #ifdef WOLFSSL_SP_SMALL
  13328. /* Conditionally add a and b using the mask m.
  13329. * m is -1 to add and 0 when not.
  13330. *
  13331. * r A single precision number representing conditional add result.
  13332. * a A single precision number to add with.
  13333. * b A single precision number to add.
  13334. * m Mask value to apply.
  13335. */
  13336. static void sp_4096_cond_add_35(sp_digit* r, const sp_digit* a,
  13337. const sp_digit* b, const sp_digit m)
  13338. {
  13339. int i;
  13340. for (i = 0; i < 35; i++) {
  13341. r[i] = a[i] + (b[i] & m);
  13342. }
  13343. }
  13344. #endif /* WOLFSSL_SP_SMALL */
  13345. /* Add b to a into r. (r = a + b)
  13346. *
  13347. * r A single precision integer.
  13348. * a A single precision integer.
  13349. * b A single precision integer.
  13350. */
  13351. SP_NOINLINE static int sp_4096_add_35(sp_digit* r, const sp_digit* a,
  13352. const sp_digit* b)
  13353. {
  13354. int i;
  13355. for (i = 0; i < 35; i++) {
  13356. r[i] = a[i] + b[i];
  13357. }
  13358. return 0;
  13359. }
  13360. SP_NOINLINE static void sp_4096_rshift_35(sp_digit* r, const sp_digit* a,
  13361. byte n)
  13362. {
  13363. int i;
  13364. for (i=0; i<34; i++) {
  13365. r[i] = ((a[i] >> n) | (a[i + 1] << (59 - n))) & 0x7ffffffffffffffL;
  13366. }
  13367. r[34] = a[34] >> n;
  13368. }
  13369. static WC_INLINE sp_digit sp_4096_div_word_35(sp_digit d1, sp_digit d0,
  13370. sp_digit div)
  13371. {
  13372. #ifdef SP_USE_DIVTI3
  13373. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  13374. return d / div;
  13375. #elif defined(__x86_64__) || defined(__i386__)
  13376. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  13377. sp_uint64 lo = (sp_uint64)d;
  13378. sp_digit hi = (sp_digit)(d >> 64);
  13379. __asm__ __volatile__ (
  13380. "idiv %2"
  13381. : "+a" (lo)
  13382. : "d" (hi), "r" (div)
  13383. : "cc"
  13384. );
  13385. return (sp_digit)lo;
  13386. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  13387. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  13388. sp_digit dv = (div >> 1) + 1;
  13389. sp_digit t1 = (sp_digit)(d >> 59);
  13390. sp_digit t0 = (sp_digit)(d & 0x7ffffffffffffffL);
  13391. sp_digit t2;
  13392. sp_digit sign;
  13393. sp_digit r;
  13394. int i;
  13395. sp_int128 m;
  13396. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  13397. t1 -= dv & (0 - r);
  13398. for (i = 57; i >= 1; i--) {
  13399. t1 += t1 + (((sp_uint64)t0 >> 58) & 1);
  13400. t0 <<= 1;
  13401. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  13402. r += r + t2;
  13403. t1 -= dv & (0 - t2);
  13404. t1 += t2;
  13405. }
  13406. r += r + 1;
  13407. m = d - ((sp_int128)r * div);
  13408. r += (sp_digit)(m >> 59);
  13409. m = d - ((sp_int128)r * div);
  13410. r += (sp_digit)(m >> 118) - (sp_digit)(d >> 118);
  13411. m = d - ((sp_int128)r * div);
  13412. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  13413. m *= sign;
  13414. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  13415. r += sign * t2;
  13416. m = d - ((sp_int128)r * div);
  13417. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  13418. m *= sign;
  13419. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  13420. r += sign * t2;
  13421. return r;
  13422. #else
  13423. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  13424. sp_digit r = 0;
  13425. sp_digit t;
  13426. sp_digit dv = (div >> 28) + 1;
  13427. t = (sp_digit)(d >> 56);
  13428. t = (t / dv) << 28;
  13429. r += t;
  13430. d -= (sp_int128)t * div;
  13431. t = (sp_digit)(d >> 25);
  13432. t = t / (dv << 3);
  13433. r += t;
  13434. d -= (sp_int128)t * div;
  13435. t = (sp_digit)d;
  13436. t = t / div;
  13437. r += t;
  13438. d -= (sp_int128)t * div;
  13439. return r;
  13440. #endif
  13441. }
  13442. static WC_INLINE sp_digit sp_4096_word_div_word_35(sp_digit d, sp_digit div)
  13443. {
  13444. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  13445. defined(SP_DIV_WORD_USE_DIV)
  13446. return d / div;
  13447. #else
  13448. return (sp_digit)((sp_uint64)(div - d) >> 63);
  13449. #endif
  13450. }
  13451. /* Divide d in a and put remainder into r (m*d + r = a)
  13452. * m is not calculated as it is not needed at this time.
  13453. *
  13454. * Full implementation.
  13455. *
  13456. * a Number to be divided.
  13457. * d Number to divide with.
  13458. * m Multiplier result.
  13459. * r Remainder from the division.
  13460. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  13461. */
  13462. static int sp_4096_div_35(const sp_digit* a, const sp_digit* d,
  13463. const sp_digit* m, sp_digit* r)
  13464. {
  13465. int i;
  13466. #ifndef WOLFSSL_SP_DIV_64
  13467. #endif
  13468. sp_digit dv;
  13469. sp_digit r1;
  13470. #ifdef WOLFSSL_SP_SMALL_STACK
  13471. sp_digit* t1 = NULL;
  13472. #else
  13473. sp_digit t1[4 * 35 + 3];
  13474. #endif
  13475. sp_digit* t2 = NULL;
  13476. sp_digit* sd = NULL;
  13477. int err = MP_OKAY;
  13478. (void)m;
  13479. #ifdef WOLFSSL_SP_SMALL_STACK
  13480. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 35 + 3), NULL,
  13481. DYNAMIC_TYPE_TMP_BUFFER);
  13482. if (t1 == NULL)
  13483. err = MEMORY_E;
  13484. #endif
  13485. (void)m;
  13486. if (err == MP_OKAY) {
  13487. t2 = t1 + 70 + 1;
  13488. sd = t2 + 35 + 1;
  13489. sp_4096_mul_d_35(sd, d, (sp_digit)1 << 17);
  13490. sp_4096_mul_d_70(t1, a, (sp_digit)1 << 17);
  13491. dv = sd[34];
  13492. t1[35 + 35] += t1[35 + 35 - 1] >> 59;
  13493. t1[35 + 35 - 1] &= 0x7ffffffffffffffL;
  13494. for (i=35; i>=0; i--) {
  13495. r1 = sp_4096_div_word_35(t1[35 + i], t1[35 + i - 1], dv);
  13496. sp_4096_mul_d_35(t2, sd, r1);
  13497. (void)sp_4096_sub_35(&t1[i], &t1[i], t2);
  13498. sp_4096_norm_35(&t1[i]);
  13499. t1[35 + i] -= t2[35];
  13500. t1[35 + i] += t1[35 + i - 1] >> 59;
  13501. t1[35 + i - 1] &= 0x7ffffffffffffffL;
  13502. r1 = sp_4096_div_word_35(-t1[35 + i], -t1[35 + i - 1], dv);
  13503. r1 -= t1[35 + i];
  13504. sp_4096_mul_d_35(t2, sd, r1);
  13505. (void)sp_4096_add_35(&t1[i], &t1[i], t2);
  13506. t1[35 + i] += t1[35 + i - 1] >> 59;
  13507. t1[35 + i - 1] &= 0x7ffffffffffffffL;
  13508. }
  13509. t1[35 - 1] += t1[35 - 2] >> 59;
  13510. t1[35 - 2] &= 0x7ffffffffffffffL;
  13511. r1 = sp_4096_word_div_word_35(t1[35 - 1], dv);
  13512. sp_4096_mul_d_35(t2, sd, r1);
  13513. sp_4096_sub_35(t1, t1, t2);
  13514. XMEMCPY(r, t1, sizeof(*r) * 70U);
  13515. for (i=0; i<34; i++) {
  13516. r[i+1] += r[i] >> 59;
  13517. r[i] &= 0x7ffffffffffffffL;
  13518. }
  13519. sp_4096_cond_add_35(r, r, sd, r[34] >> 63);
  13520. sp_4096_norm_35(r);
  13521. sp_4096_rshift_35(r, r, 17);
  13522. }
  13523. #ifdef WOLFSSL_SP_SMALL_STACK
  13524. if (t1 != NULL)
  13525. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  13526. #endif
  13527. return err;
  13528. }
  13529. /* Reduce a modulo m into r. (r = a mod m)
  13530. *
  13531. * r A single precision number that is the reduced result.
  13532. * a A single precision number that is to be reduced.
  13533. * m A single precision number that is the modulus to reduce with.
  13534. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  13535. */
  13536. static int sp_4096_mod_35(sp_digit* r, const sp_digit* a, const sp_digit* m)
  13537. {
  13538. return sp_4096_div_35(a, m, NULL, r);
  13539. }
  13540. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  13541. *
  13542. * r A single precision number that is the result of the operation.
  13543. * a A single precision number being exponentiated.
  13544. * e A single precision number that is the exponent.
  13545. * bits The number of bits in the exponent.
  13546. * m A single precision number that is the modulus.
  13547. * returns 0 on success.
  13548. * returns MEMORY_E on dynamic memory allocation failure.
  13549. * returns MP_VAL when base is even or exponent is 0.
  13550. */
  13551. static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e,
  13552. int bits, const sp_digit* m, int reduceA)
  13553. {
  13554. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  13555. #ifdef WOLFSSL_SP_SMALL_STACK
  13556. sp_digit* td = NULL;
  13557. #else
  13558. sp_digit td[3 * 70];
  13559. #endif
  13560. sp_digit* t[3] = {0, 0, 0};
  13561. sp_digit* norm = NULL;
  13562. sp_digit mp = 1;
  13563. sp_digit n;
  13564. int i;
  13565. int c;
  13566. byte y;
  13567. int err = MP_OKAY;
  13568. if (bits == 0) {
  13569. err = MP_VAL;
  13570. }
  13571. #ifdef WOLFSSL_SP_SMALL_STACK
  13572. if (err == MP_OKAY) {
  13573. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 35 * 2, NULL,
  13574. DYNAMIC_TYPE_TMP_BUFFER);
  13575. if (td == NULL)
  13576. err = MEMORY_E;
  13577. }
  13578. #endif
  13579. if (err == MP_OKAY) {
  13580. norm = td;
  13581. for (i=0; i<3; i++) {
  13582. t[i] = td + (i * 35 * 2);
  13583. XMEMSET(t[i], 0, sizeof(sp_digit) * 35U * 2U);
  13584. }
  13585. sp_4096_mont_setup(m, &mp);
  13586. sp_4096_mont_norm_35(norm, m);
  13587. if (reduceA != 0) {
  13588. err = sp_4096_mod_35(t[1], a, m);
  13589. }
  13590. else {
  13591. XMEMCPY(t[1], a, sizeof(sp_digit) * 35U);
  13592. }
  13593. }
  13594. if (err == MP_OKAY) {
  13595. sp_4096_mul_35(t[1], t[1], norm);
  13596. err = sp_4096_mod_35(t[1], t[1], m);
  13597. }
  13598. if (err == MP_OKAY) {
  13599. i = bits / 59;
  13600. c = bits % 59;
  13601. n = e[i--] << (59 - c);
  13602. for (; ; c--) {
  13603. if (c == 0) {
  13604. if (i == -1) {
  13605. break;
  13606. }
  13607. n = e[i--];
  13608. c = 59;
  13609. }
  13610. y = (int)((n >> 58) & 1);
  13611. n <<= 1;
  13612. sp_4096_mont_mul_35(t[y^1], t[0], t[1], m, mp);
  13613. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  13614. ((size_t)t[1] & addr_mask[y])),
  13615. sizeof(*t[2]) * 35 * 2);
  13616. sp_4096_mont_sqr_35(t[2], t[2], m, mp);
  13617. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  13618. ((size_t)t[1] & addr_mask[y])), t[2],
  13619. sizeof(*t[2]) * 35 * 2);
  13620. }
  13621. sp_4096_mont_reduce_35(t[0], m, mp);
  13622. n = sp_4096_cmp_35(t[0], m);
  13623. sp_4096_cond_sub_35(t[0], t[0], m, ~(n >> 63));
  13624. XMEMCPY(r, t[0], sizeof(*r) * 35 * 2);
  13625. }
  13626. #ifdef WOLFSSL_SP_SMALL_STACK
  13627. if (td != NULL)
  13628. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  13629. #endif
  13630. return err;
  13631. #elif !defined(WC_NO_CACHE_RESISTANT)
  13632. #ifdef WOLFSSL_SP_SMALL_STACK
  13633. sp_digit* td = NULL;
  13634. #else
  13635. sp_digit td[3 * 70];
  13636. #endif
  13637. sp_digit* t[3] = {0, 0, 0};
  13638. sp_digit* norm = NULL;
  13639. sp_digit mp = 1;
  13640. sp_digit n;
  13641. int i;
  13642. int c;
  13643. byte y;
  13644. int err = MP_OKAY;
  13645. if (bits == 0) {
  13646. err = MP_VAL;
  13647. }
  13648. #ifdef WOLFSSL_SP_SMALL_STACK
  13649. if (err == MP_OKAY) {
  13650. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 35 * 2, NULL,
  13651. DYNAMIC_TYPE_TMP_BUFFER);
  13652. if (td == NULL)
  13653. err = MEMORY_E;
  13654. }
  13655. #endif
  13656. if (err == MP_OKAY) {
  13657. norm = td;
  13658. for (i=0; i<3; i++) {
  13659. t[i] = td + (i * 35 * 2);
  13660. }
  13661. sp_4096_mont_setup(m, &mp);
  13662. sp_4096_mont_norm_35(norm, m);
  13663. if (reduceA != 0) {
  13664. err = sp_4096_mod_35(t[1], a, m);
  13665. if (err == MP_OKAY) {
  13666. sp_4096_mul_35(t[1], t[1], norm);
  13667. err = sp_4096_mod_35(t[1], t[1], m);
  13668. }
  13669. }
  13670. else {
  13671. sp_4096_mul_35(t[1], a, norm);
  13672. err = sp_4096_mod_35(t[1], t[1], m);
  13673. }
  13674. }
  13675. if (err == MP_OKAY) {
  13676. i = bits / 59;
  13677. c = bits % 59;
  13678. n = e[i--] << (59 - c);
  13679. for (; ; c--) {
  13680. if (c == 0) {
  13681. if (i == -1) {
  13682. break;
  13683. }
  13684. n = e[i--];
  13685. c = 59;
  13686. }
  13687. y = (int)((n >> 58) & 1);
  13688. n <<= 1;
  13689. sp_4096_mont_mul_35(t[y^1], t[0], t[1], m, mp);
  13690. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  13691. ((size_t)t[1] & addr_mask[y])),
  13692. sizeof(*t[2]) * 35 * 2);
  13693. sp_4096_mont_sqr_35(t[2], t[2], m, mp);
  13694. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  13695. ((size_t)t[1] & addr_mask[y])), t[2],
  13696. sizeof(*t[2]) * 35 * 2);
  13697. }
  13698. sp_4096_mont_reduce_35(t[0], m, mp);
  13699. n = sp_4096_cmp_35(t[0], m);
  13700. sp_4096_cond_sub_35(t[0], t[0], m, ~(n >> 63));
  13701. XMEMCPY(r, t[0], sizeof(*r) * 35 * 2);
  13702. }
  13703. #ifdef WOLFSSL_SP_SMALL_STACK
  13704. if (td != NULL)
  13705. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  13706. #endif
  13707. return err;
  13708. #else
  13709. #ifdef WOLFSSL_SP_SMALL_STACK
  13710. sp_digit* td = NULL;
  13711. #else
  13712. sp_digit td[(32 * 70) + 70];
  13713. #endif
  13714. sp_digit* t[32];
  13715. sp_digit* rt = NULL;
  13716. sp_digit* norm = NULL;
  13717. sp_digit mp = 1;
  13718. sp_digit n;
  13719. int i;
  13720. int c;
  13721. byte y;
  13722. int err = MP_OKAY;
  13723. if (bits == 0) {
  13724. err = MP_VAL;
  13725. }
  13726. #ifdef WOLFSSL_SP_SMALL_STACK
  13727. if (err == MP_OKAY) {
  13728. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 70) + 70), NULL,
  13729. DYNAMIC_TYPE_TMP_BUFFER);
  13730. if (td == NULL)
  13731. err = MEMORY_E;
  13732. }
  13733. #endif
  13734. if (err == MP_OKAY) {
  13735. norm = td;
  13736. for (i=0; i<32; i++)
  13737. t[i] = td + i * 70;
  13738. rt = td + 2240;
  13739. sp_4096_mont_setup(m, &mp);
  13740. sp_4096_mont_norm_35(norm, m);
  13741. if (reduceA != 0) {
  13742. err = sp_4096_mod_35(t[1], a, m);
  13743. if (err == MP_OKAY) {
  13744. sp_4096_mul_35(t[1], t[1], norm);
  13745. err = sp_4096_mod_35(t[1], t[1], m);
  13746. }
  13747. }
  13748. else {
  13749. sp_4096_mul_35(t[1], a, norm);
  13750. err = sp_4096_mod_35(t[1], t[1], m);
  13751. }
  13752. }
  13753. if (err == MP_OKAY) {
  13754. sp_4096_mont_sqr_35(t[ 2], t[ 1], m, mp);
  13755. sp_4096_mont_mul_35(t[ 3], t[ 2], t[ 1], m, mp);
  13756. sp_4096_mont_sqr_35(t[ 4], t[ 2], m, mp);
  13757. sp_4096_mont_mul_35(t[ 5], t[ 3], t[ 2], m, mp);
  13758. sp_4096_mont_sqr_35(t[ 6], t[ 3], m, mp);
  13759. sp_4096_mont_mul_35(t[ 7], t[ 4], t[ 3], m, mp);
  13760. sp_4096_mont_sqr_35(t[ 8], t[ 4], m, mp);
  13761. sp_4096_mont_mul_35(t[ 9], t[ 5], t[ 4], m, mp);
  13762. sp_4096_mont_sqr_35(t[10], t[ 5], m, mp);
  13763. sp_4096_mont_mul_35(t[11], t[ 6], t[ 5], m, mp);
  13764. sp_4096_mont_sqr_35(t[12], t[ 6], m, mp);
  13765. sp_4096_mont_mul_35(t[13], t[ 7], t[ 6], m, mp);
  13766. sp_4096_mont_sqr_35(t[14], t[ 7], m, mp);
  13767. sp_4096_mont_mul_35(t[15], t[ 8], t[ 7], m, mp);
  13768. sp_4096_mont_sqr_35(t[16], t[ 8], m, mp);
  13769. sp_4096_mont_mul_35(t[17], t[ 9], t[ 8], m, mp);
  13770. sp_4096_mont_sqr_35(t[18], t[ 9], m, mp);
  13771. sp_4096_mont_mul_35(t[19], t[10], t[ 9], m, mp);
  13772. sp_4096_mont_sqr_35(t[20], t[10], m, mp);
  13773. sp_4096_mont_mul_35(t[21], t[11], t[10], m, mp);
  13774. sp_4096_mont_sqr_35(t[22], t[11], m, mp);
  13775. sp_4096_mont_mul_35(t[23], t[12], t[11], m, mp);
  13776. sp_4096_mont_sqr_35(t[24], t[12], m, mp);
  13777. sp_4096_mont_mul_35(t[25], t[13], t[12], m, mp);
  13778. sp_4096_mont_sqr_35(t[26], t[13], m, mp);
  13779. sp_4096_mont_mul_35(t[27], t[14], t[13], m, mp);
  13780. sp_4096_mont_sqr_35(t[28], t[14], m, mp);
  13781. sp_4096_mont_mul_35(t[29], t[15], t[14], m, mp);
  13782. sp_4096_mont_sqr_35(t[30], t[15], m, mp);
  13783. sp_4096_mont_mul_35(t[31], t[16], t[15], m, mp);
  13784. bits = ((bits + 4) / 5) * 5;
  13785. i = ((bits + 58) / 59) - 1;
  13786. c = bits % 59;
  13787. if (c == 0) {
  13788. c = 59;
  13789. }
  13790. if (i < 35) {
  13791. n = e[i--] << (64 - c);
  13792. }
  13793. else {
  13794. n = 0;
  13795. i--;
  13796. }
  13797. if (c < 5) {
  13798. n |= e[i--] << (5 - c);
  13799. c += 59;
  13800. }
  13801. y = (int)((n >> 59) & 0x1f);
  13802. n <<= 5;
  13803. c -= 5;
  13804. XMEMCPY(rt, t[y], sizeof(sp_digit) * 70);
  13805. while ((i >= 0) || (c >= 5)) {
  13806. if (c >= 5) {
  13807. y = (byte)((n >> 59) & 0x1f);
  13808. n <<= 5;
  13809. c -= 5;
  13810. }
  13811. else if (c == 0) {
  13812. n = e[i--] << 5;
  13813. y = (byte)((n >> 59) & 0x1f);
  13814. n <<= 5;
  13815. c = 54;
  13816. }
  13817. else {
  13818. y = (byte)((n >> 59) & 0x1f);
  13819. n = e[i--] << 5;
  13820. c = 5 - c;
  13821. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  13822. n <<= c;
  13823. c = 59 - c;
  13824. }
  13825. sp_4096_mont_sqr_35(rt, rt, m, mp);
  13826. sp_4096_mont_sqr_35(rt, rt, m, mp);
  13827. sp_4096_mont_sqr_35(rt, rt, m, mp);
  13828. sp_4096_mont_sqr_35(rt, rt, m, mp);
  13829. sp_4096_mont_sqr_35(rt, rt, m, mp);
  13830. sp_4096_mont_mul_35(rt, rt, t[y], m, mp);
  13831. }
  13832. sp_4096_mont_reduce_35(rt, m, mp);
  13833. n = sp_4096_cmp_35(rt, m);
  13834. sp_4096_cond_sub_35(rt, rt, m, ~(n >> 63));
  13835. XMEMCPY(r, rt, sizeof(sp_digit) * 70);
  13836. }
  13837. #ifdef WOLFSSL_SP_SMALL_STACK
  13838. if (td != NULL)
  13839. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  13840. #endif
  13841. return err;
  13842. #endif
  13843. }
  13844. #endif /* WOLFSSL_HAVE_SP_RSA & !SP_RSA_PRIVATE_EXP_D */
  13845. #endif /* (WOLFSSL_HAVE_SP_RSA | WOLFSSL_HAVE_SP_DH) & !WOLFSSL_RSA_PUBLIC_ONLY */
  13846. /* Sub b from a into r. (r = a - b)
  13847. *
  13848. * r A single precision integer.
  13849. * a A single precision integer.
  13850. * b A single precision integer.
  13851. */
  13852. SP_NOINLINE static int sp_4096_sub_70(sp_digit* r, const sp_digit* a,
  13853. const sp_digit* b)
  13854. {
  13855. int i;
  13856. for (i = 0; i < 70; i++) {
  13857. r[i] = a[i] - b[i];
  13858. }
  13859. return 0;
  13860. }
  13861. /* r = 2^n mod m where n is the number of bits to reduce by.
  13862. * Given m must be 4096 bits, just need to subtract.
  13863. *
  13864. * r A single precision number.
  13865. * m A single precision number.
  13866. */
  13867. static void sp_4096_mont_norm_70(sp_digit* r, const sp_digit* m)
  13868. {
  13869. /* Set r = 2^n - 1. */
  13870. int i;
  13871. for (i=0; i<69; i++) {
  13872. r[i] = 0x7ffffffffffffffL;
  13873. }
  13874. r[69] = 0x1ffffffL;
  13875. /* r = (2^n - 1) mod n */
  13876. (void)sp_4096_sub_70(r, r, m);
  13877. /* Add one so r = 2^n mod m */
  13878. r[0] += 1;
  13879. }
  13880. /* Compare a with b in constant time.
  13881. *
  13882. * a A single precision integer.
  13883. * b A single precision integer.
  13884. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  13885. * respectively.
  13886. */
  13887. static sp_digit sp_4096_cmp_70(const sp_digit* a, const sp_digit* b)
  13888. {
  13889. sp_digit r = 0;
  13890. int i;
  13891. for (i=69; i>=0; i--) {
  13892. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 58);
  13893. }
  13894. return r;
  13895. }
  13896. /* Conditionally subtract b from a using the mask m.
  13897. * m is -1 to subtract and 0 when not.
  13898. *
  13899. * r A single precision number representing condition subtract result.
  13900. * a A single precision number to subtract from.
  13901. * b A single precision number to subtract.
  13902. * m Mask value to apply.
  13903. */
  13904. static void sp_4096_cond_sub_70(sp_digit* r, const sp_digit* a,
  13905. const sp_digit* b, const sp_digit m)
  13906. {
  13907. int i;
  13908. for (i = 0; i < 70; i++) {
  13909. r[i] = a[i] - (b[i] & m);
  13910. }
  13911. }
  13912. /* Mul a by scalar b and add into r. (r += a * b)
  13913. *
  13914. * r A single precision integer.
  13915. * a A single precision integer.
  13916. * b A scalar.
  13917. */
  13918. SP_NOINLINE static void sp_4096_mul_add_70(sp_digit* r, const sp_digit* a,
  13919. const sp_digit b)
  13920. {
  13921. sp_int128 tb = b;
  13922. sp_int128 t[4];
  13923. int i;
  13924. t[0] = 0;
  13925. for (i = 0; i < 68; i += 4) {
  13926. t[0] += (tb * a[i+0]) + r[i+0];
  13927. t[1] = (tb * a[i+1]) + r[i+1];
  13928. t[2] = (tb * a[i+2]) + r[i+2];
  13929. t[3] = (tb * a[i+3]) + r[i+3];
  13930. r[i+0] = t[0] & 0x7ffffffffffffffL;
  13931. t[1] += t[0] >> 59;
  13932. r[i+1] = t[1] & 0x7ffffffffffffffL;
  13933. t[2] += t[1] >> 59;
  13934. r[i+2] = t[2] & 0x7ffffffffffffffL;
  13935. t[3] += t[2] >> 59;
  13936. r[i+3] = t[3] & 0x7ffffffffffffffL;
  13937. t[0] = t[3] >> 59;
  13938. }
  13939. t[0] += (tb * a[68]) + r[68];
  13940. t[1] = (tb * a[69]) + r[69];
  13941. r[68] = t[0] & 0x7ffffffffffffffL;
  13942. t[1] += t[0] >> 59;
  13943. r[69] = t[1] & 0x7ffffffffffffffL;
  13944. r[70] += (sp_digit)(t[1] >> 59);
  13945. }
  13946. /* Shift the result in the high 4096 bits down to the bottom.
  13947. *
  13948. * r A single precision number.
  13949. * a A single precision number.
  13950. */
  13951. static void sp_4096_mont_shift_70(sp_digit* r, const sp_digit* a)
  13952. {
  13953. int i;
  13954. sp_int128 n = a[69] >> 25;
  13955. n += ((sp_int128)a[70]) << 34;
  13956. for (i = 0; i < 69; i++) {
  13957. r[i] = n & 0x7ffffffffffffffL;
  13958. n >>= 59;
  13959. n += ((sp_int128)a[71 + i]) << 34;
  13960. }
  13961. r[69] = (sp_digit)n;
  13962. XMEMSET(&r[70], 0, sizeof(*r) * 70U);
  13963. }
  13964. /* Reduce the number back to 4096 bits using Montgomery reduction.
  13965. *
  13966. * a A single precision number to reduce in place.
  13967. * m The single precision number representing the modulus.
  13968. * mp The digit representing the negative inverse of m mod 2^n.
  13969. */
  13970. static void sp_4096_mont_reduce_70(sp_digit* a, const sp_digit* m, sp_digit mp)
  13971. {
  13972. int i;
  13973. sp_digit mu;
  13974. sp_digit over;
  13975. sp_4096_norm_70(a + 70);
  13976. #ifdef WOLFSSL_SP_DH
  13977. if (mp != 1) {
  13978. for (i=0; i<69; i++) {
  13979. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7ffffffffffffffL;
  13980. sp_4096_mul_add_70(a+i, m, mu);
  13981. a[i+1] += a[i] >> 59;
  13982. }
  13983. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffL;
  13984. sp_4096_mul_add_70(a+i, m, mu);
  13985. a[i+1] += a[i] >> 59;
  13986. a[i] &= 0x7ffffffffffffffL;
  13987. }
  13988. else {
  13989. for (i=0; i<69; i++) {
  13990. mu = a[i] & 0x7ffffffffffffffL;
  13991. sp_4096_mul_add_70(a+i, m, mu);
  13992. a[i+1] += a[i] >> 59;
  13993. }
  13994. mu = a[i] & 0x1ffffffL;
  13995. sp_4096_mul_add_70(a+i, m, mu);
  13996. a[i+1] += a[i] >> 59;
  13997. a[i] &= 0x7ffffffffffffffL;
  13998. }
  13999. #else
  14000. for (i=0; i<69; i++) {
  14001. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7ffffffffffffffL;
  14002. sp_4096_mul_add_70(a+i, m, mu);
  14003. a[i+1] += a[i] >> 59;
  14004. }
  14005. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffL;
  14006. sp_4096_mul_add_70(a+i, m, mu);
  14007. a[i+1] += a[i] >> 59;
  14008. a[i] &= 0x7ffffffffffffffL;
  14009. #endif
  14010. sp_4096_mont_shift_70(a, a);
  14011. over = a[69] - m[69];
  14012. sp_4096_cond_sub_70(a, a, m, ~((over - 1) >> 63));
  14013. sp_4096_norm_70(a);
  14014. }
  14015. /* Multiply two Montgomery form numbers mod the modulus (prime).
  14016. * (r = a * b mod m)
  14017. *
  14018. * r Result of multiplication.
  14019. * a First number to multiply in Montgomery form.
  14020. * b Second number to multiply in Montgomery form.
  14021. * m Modulus (prime).
  14022. * mp Montgomery multiplier.
  14023. */
  14024. SP_NOINLINE static void sp_4096_mont_mul_70(sp_digit* r, const sp_digit* a,
  14025. const sp_digit* b, const sp_digit* m, sp_digit mp)
  14026. {
  14027. sp_4096_mul_70(r, a, b);
  14028. sp_4096_mont_reduce_70(r, m, mp);
  14029. }
  14030. /* Square the Montgomery form number. (r = a * a mod m)
  14031. *
  14032. * r Result of squaring.
  14033. * a Number to square in Montgomery form.
  14034. * m Modulus (prime).
  14035. * mp Montgomery multiplier.
  14036. */
  14037. SP_NOINLINE static void sp_4096_mont_sqr_70(sp_digit* r, const sp_digit* a,
  14038. const sp_digit* m, sp_digit mp)
  14039. {
  14040. sp_4096_sqr_70(r, a);
  14041. sp_4096_mont_reduce_70(r, m, mp);
  14042. }
  14043. /* Multiply a by scalar b into r. (r = a * b)
  14044. *
  14045. * r A single precision integer.
  14046. * a A single precision integer.
  14047. * b A scalar.
  14048. */
  14049. SP_NOINLINE static void sp_4096_mul_d_140(sp_digit* r, const sp_digit* a,
  14050. sp_digit b)
  14051. {
  14052. sp_int128 tb = b;
  14053. sp_int128 t = 0;
  14054. int i;
  14055. for (i = 0; i < 140; i++) {
  14056. t += tb * a[i];
  14057. r[i] = (sp_digit)(t & 0x7ffffffffffffffL);
  14058. t >>= 59;
  14059. }
  14060. r[140] = (sp_digit)t;
  14061. }
  14062. #ifdef WOLFSSL_SP_SMALL
  14063. /* Conditionally add a and b using the mask m.
  14064. * m is -1 to add and 0 when not.
  14065. *
  14066. * r A single precision number representing conditional add result.
  14067. * a A single precision number to add with.
  14068. * b A single precision number to add.
  14069. * m Mask value to apply.
  14070. */
  14071. static void sp_4096_cond_add_70(sp_digit* r, const sp_digit* a,
  14072. const sp_digit* b, const sp_digit m)
  14073. {
  14074. int i;
  14075. for (i = 0; i < 70; i++) {
  14076. r[i] = a[i] + (b[i] & m);
  14077. }
  14078. }
  14079. #endif /* WOLFSSL_SP_SMALL */
  14080. /* Add b to a into r. (r = a + b)
  14081. *
  14082. * r A single precision integer.
  14083. * a A single precision integer.
  14084. * b A single precision integer.
  14085. */
  14086. SP_NOINLINE static int sp_4096_add_70(sp_digit* r, const sp_digit* a,
  14087. const sp_digit* b)
  14088. {
  14089. int i;
  14090. for (i = 0; i < 70; i++) {
  14091. r[i] = a[i] + b[i];
  14092. }
  14093. return 0;
  14094. }
  14095. SP_NOINLINE static void sp_4096_rshift_70(sp_digit* r, const sp_digit* a,
  14096. byte n)
  14097. {
  14098. int i;
  14099. for (i=0; i<69; i++) {
  14100. r[i] = ((a[i] >> n) | (a[i + 1] << (59 - n))) & 0x7ffffffffffffffL;
  14101. }
  14102. r[69] = a[69] >> n;
  14103. }
  14104. static WC_INLINE sp_digit sp_4096_div_word_70(sp_digit d1, sp_digit d0,
  14105. sp_digit div)
  14106. {
  14107. #ifdef SP_USE_DIVTI3
  14108. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  14109. return d / div;
  14110. #elif defined(__x86_64__) || defined(__i386__)
  14111. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  14112. sp_uint64 lo = (sp_uint64)d;
  14113. sp_digit hi = (sp_digit)(d >> 64);
  14114. __asm__ __volatile__ (
  14115. "idiv %2"
  14116. : "+a" (lo)
  14117. : "d" (hi), "r" (div)
  14118. : "cc"
  14119. );
  14120. return (sp_digit)lo;
  14121. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  14122. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  14123. sp_digit dv = (div >> 1) + 1;
  14124. sp_digit t1 = (sp_digit)(d >> 59);
  14125. sp_digit t0 = (sp_digit)(d & 0x7ffffffffffffffL);
  14126. sp_digit t2;
  14127. sp_digit sign;
  14128. sp_digit r;
  14129. int i;
  14130. sp_int128 m;
  14131. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  14132. t1 -= dv & (0 - r);
  14133. for (i = 57; i >= 1; i--) {
  14134. t1 += t1 + (((sp_uint64)t0 >> 58) & 1);
  14135. t0 <<= 1;
  14136. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  14137. r += r + t2;
  14138. t1 -= dv & (0 - t2);
  14139. t1 += t2;
  14140. }
  14141. r += r + 1;
  14142. m = d - ((sp_int128)r * div);
  14143. r += (sp_digit)(m >> 59);
  14144. m = d - ((sp_int128)r * div);
  14145. r += (sp_digit)(m >> 118) - (sp_digit)(d >> 118);
  14146. m = d - ((sp_int128)r * div);
  14147. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  14148. m *= sign;
  14149. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  14150. r += sign * t2;
  14151. m = d - ((sp_int128)r * div);
  14152. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  14153. m *= sign;
  14154. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  14155. r += sign * t2;
  14156. return r;
  14157. #else
  14158. sp_int128 d = ((sp_int128)d1 << 59) + d0;
  14159. sp_digit r = 0;
  14160. sp_digit t;
  14161. sp_digit dv = (div >> 28) + 1;
  14162. t = (sp_digit)(d >> 56);
  14163. t = (t / dv) << 28;
  14164. r += t;
  14165. d -= (sp_int128)t * div;
  14166. t = (sp_digit)(d >> 25);
  14167. t = t / (dv << 3);
  14168. r += t;
  14169. d -= (sp_int128)t * div;
  14170. t = (sp_digit)d;
  14171. t = t / div;
  14172. r += t;
  14173. d -= (sp_int128)t * div;
  14174. return r;
  14175. #endif
  14176. }
  14177. static WC_INLINE sp_digit sp_4096_word_div_word_70(sp_digit d, sp_digit div)
  14178. {
  14179. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  14180. defined(SP_DIV_WORD_USE_DIV)
  14181. return d / div;
  14182. #else
  14183. return (sp_digit)((sp_uint64)(div - d) >> 63);
  14184. #endif
  14185. }
  14186. /* Divide d in a and put remainder into r (m*d + r = a)
  14187. * m is not calculated as it is not needed at this time.
  14188. *
  14189. * Full implementation.
  14190. *
  14191. * a Number to be divided.
  14192. * d Number to divide with.
  14193. * m Multiplier result.
  14194. * r Remainder from the division.
  14195. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  14196. */
  14197. static int sp_4096_div_70(const sp_digit* a, const sp_digit* d,
  14198. const sp_digit* m, sp_digit* r)
  14199. {
  14200. int i;
  14201. #ifndef WOLFSSL_SP_DIV_64
  14202. #endif
  14203. sp_digit dv;
  14204. sp_digit r1;
  14205. #ifdef WOLFSSL_SP_SMALL_STACK
  14206. sp_digit* t1 = NULL;
  14207. #else
  14208. sp_digit t1[4 * 70 + 3];
  14209. #endif
  14210. sp_digit* t2 = NULL;
  14211. sp_digit* sd = NULL;
  14212. int err = MP_OKAY;
  14213. (void)m;
  14214. #ifdef WOLFSSL_SP_SMALL_STACK
  14215. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 70 + 3), NULL,
  14216. DYNAMIC_TYPE_TMP_BUFFER);
  14217. if (t1 == NULL)
  14218. err = MEMORY_E;
  14219. #endif
  14220. (void)m;
  14221. if (err == MP_OKAY) {
  14222. t2 = t1 + 140 + 1;
  14223. sd = t2 + 70 + 1;
  14224. sp_4096_mul_d_70(sd, d, (sp_digit)1 << 34);
  14225. sp_4096_mul_d_140(t1, a, (sp_digit)1 << 34);
  14226. dv = sd[69];
  14227. t1[70 + 70] += t1[70 + 70 - 1] >> 59;
  14228. t1[70 + 70 - 1] &= 0x7ffffffffffffffL;
  14229. for (i=70; i>=0; i--) {
  14230. r1 = sp_4096_div_word_70(t1[70 + i], t1[70 + i - 1], dv);
  14231. sp_4096_mul_d_70(t2, sd, r1);
  14232. (void)sp_4096_sub_70(&t1[i], &t1[i], t2);
  14233. sp_4096_norm_70(&t1[i]);
  14234. t1[70 + i] -= t2[70];
  14235. t1[70 + i] += t1[70 + i - 1] >> 59;
  14236. t1[70 + i - 1] &= 0x7ffffffffffffffL;
  14237. r1 = sp_4096_div_word_70(-t1[70 + i], -t1[70 + i - 1], dv);
  14238. r1 -= t1[70 + i];
  14239. sp_4096_mul_d_70(t2, sd, r1);
  14240. (void)sp_4096_add_70(&t1[i], &t1[i], t2);
  14241. t1[70 + i] += t1[70 + i - 1] >> 59;
  14242. t1[70 + i - 1] &= 0x7ffffffffffffffL;
  14243. }
  14244. t1[70 - 1] += t1[70 - 2] >> 59;
  14245. t1[70 - 2] &= 0x7ffffffffffffffL;
  14246. r1 = sp_4096_word_div_word_70(t1[70 - 1], dv);
  14247. sp_4096_mul_d_70(t2, sd, r1);
  14248. sp_4096_sub_70(t1, t1, t2);
  14249. XMEMCPY(r, t1, sizeof(*r) * 140U);
  14250. for (i=0; i<69; i++) {
  14251. r[i+1] += r[i] >> 59;
  14252. r[i] &= 0x7ffffffffffffffL;
  14253. }
  14254. sp_4096_cond_add_70(r, r, sd, r[69] >> 63);
  14255. sp_4096_norm_70(r);
  14256. sp_4096_rshift_70(r, r, 34);
  14257. }
  14258. #ifdef WOLFSSL_SP_SMALL_STACK
  14259. if (t1 != NULL)
  14260. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  14261. #endif
  14262. return err;
  14263. }
  14264. /* Reduce a modulo m into r. (r = a mod m)
  14265. *
  14266. * r A single precision number that is the reduced result.
  14267. * a A single precision number that is to be reduced.
  14268. * m A single precision number that is the modulus to reduce with.
  14269. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  14270. */
  14271. static int sp_4096_mod_70(sp_digit* r, const sp_digit* a, const sp_digit* m)
  14272. {
  14273. return sp_4096_div_70(a, m, NULL, r);
  14274. }
  14275. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  14276. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  14277. *
  14278. * r A single precision number that is the result of the operation.
  14279. * a A single precision number being exponentiated.
  14280. * e A single precision number that is the exponent.
  14281. * bits The number of bits in the exponent.
  14282. * m A single precision number that is the modulus.
  14283. * returns 0 on success.
  14284. * returns MEMORY_E on dynamic memory allocation failure.
  14285. * returns MP_VAL when base is even or exponent is 0.
  14286. */
  14287. static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e,
  14288. int bits, const sp_digit* m, int reduceA)
  14289. {
  14290. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  14291. #ifdef WOLFSSL_SP_SMALL_STACK
  14292. sp_digit* td = NULL;
  14293. #else
  14294. sp_digit td[3 * 140];
  14295. #endif
  14296. sp_digit* t[3] = {0, 0, 0};
  14297. sp_digit* norm = NULL;
  14298. sp_digit mp = 1;
  14299. sp_digit n;
  14300. int i;
  14301. int c;
  14302. byte y;
  14303. int err = MP_OKAY;
  14304. if (bits == 0) {
  14305. err = MP_VAL;
  14306. }
  14307. #ifdef WOLFSSL_SP_SMALL_STACK
  14308. if (err == MP_OKAY) {
  14309. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 70 * 2, NULL,
  14310. DYNAMIC_TYPE_TMP_BUFFER);
  14311. if (td == NULL)
  14312. err = MEMORY_E;
  14313. }
  14314. #endif
  14315. if (err == MP_OKAY) {
  14316. norm = td;
  14317. for (i=0; i<3; i++) {
  14318. t[i] = td + (i * 70 * 2);
  14319. XMEMSET(t[i], 0, sizeof(sp_digit) * 70U * 2U);
  14320. }
  14321. sp_4096_mont_setup(m, &mp);
  14322. sp_4096_mont_norm_70(norm, m);
  14323. if (reduceA != 0) {
  14324. err = sp_4096_mod_70(t[1], a, m);
  14325. }
  14326. else {
  14327. XMEMCPY(t[1], a, sizeof(sp_digit) * 70U);
  14328. }
  14329. }
  14330. if (err == MP_OKAY) {
  14331. sp_4096_mul_70(t[1], t[1], norm);
  14332. err = sp_4096_mod_70(t[1], t[1], m);
  14333. }
  14334. if (err == MP_OKAY) {
  14335. i = bits / 59;
  14336. c = bits % 59;
  14337. n = e[i--] << (59 - c);
  14338. for (; ; c--) {
  14339. if (c == 0) {
  14340. if (i == -1) {
  14341. break;
  14342. }
  14343. n = e[i--];
  14344. c = 59;
  14345. }
  14346. y = (int)((n >> 58) & 1);
  14347. n <<= 1;
  14348. sp_4096_mont_mul_70(t[y^1], t[0], t[1], m, mp);
  14349. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  14350. ((size_t)t[1] & addr_mask[y])),
  14351. sizeof(*t[2]) * 70 * 2);
  14352. sp_4096_mont_sqr_70(t[2], t[2], m, mp);
  14353. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  14354. ((size_t)t[1] & addr_mask[y])), t[2],
  14355. sizeof(*t[2]) * 70 * 2);
  14356. }
  14357. sp_4096_mont_reduce_70(t[0], m, mp);
  14358. n = sp_4096_cmp_70(t[0], m);
  14359. sp_4096_cond_sub_70(t[0], t[0], m, ~(n >> 63));
  14360. XMEMCPY(r, t[0], sizeof(*r) * 70 * 2);
  14361. }
  14362. #ifdef WOLFSSL_SP_SMALL_STACK
  14363. if (td != NULL)
  14364. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  14365. #endif
  14366. return err;
  14367. #elif !defined(WC_NO_CACHE_RESISTANT)
  14368. #ifdef WOLFSSL_SP_SMALL_STACK
  14369. sp_digit* td = NULL;
  14370. #else
  14371. sp_digit td[3 * 140];
  14372. #endif
  14373. sp_digit* t[3] = {0, 0, 0};
  14374. sp_digit* norm = NULL;
  14375. sp_digit mp = 1;
  14376. sp_digit n;
  14377. int i;
  14378. int c;
  14379. byte y;
  14380. int err = MP_OKAY;
  14381. if (bits == 0) {
  14382. err = MP_VAL;
  14383. }
  14384. #ifdef WOLFSSL_SP_SMALL_STACK
  14385. if (err == MP_OKAY) {
  14386. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 70 * 2, NULL,
  14387. DYNAMIC_TYPE_TMP_BUFFER);
  14388. if (td == NULL)
  14389. err = MEMORY_E;
  14390. }
  14391. #endif
  14392. if (err == MP_OKAY) {
  14393. norm = td;
  14394. for (i=0; i<3; i++) {
  14395. t[i] = td + (i * 70 * 2);
  14396. }
  14397. sp_4096_mont_setup(m, &mp);
  14398. sp_4096_mont_norm_70(norm, m);
  14399. if (reduceA != 0) {
  14400. err = sp_4096_mod_70(t[1], a, m);
  14401. if (err == MP_OKAY) {
  14402. sp_4096_mul_70(t[1], t[1], norm);
  14403. err = sp_4096_mod_70(t[1], t[1], m);
  14404. }
  14405. }
  14406. else {
  14407. sp_4096_mul_70(t[1], a, norm);
  14408. err = sp_4096_mod_70(t[1], t[1], m);
  14409. }
  14410. }
  14411. if (err == MP_OKAY) {
  14412. i = bits / 59;
  14413. c = bits % 59;
  14414. n = e[i--] << (59 - c);
  14415. for (; ; c--) {
  14416. if (c == 0) {
  14417. if (i == -1) {
  14418. break;
  14419. }
  14420. n = e[i--];
  14421. c = 59;
  14422. }
  14423. y = (int)((n >> 58) & 1);
  14424. n <<= 1;
  14425. sp_4096_mont_mul_70(t[y^1], t[0], t[1], m, mp);
  14426. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  14427. ((size_t)t[1] & addr_mask[y])),
  14428. sizeof(*t[2]) * 70 * 2);
  14429. sp_4096_mont_sqr_70(t[2], t[2], m, mp);
  14430. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  14431. ((size_t)t[1] & addr_mask[y])), t[2],
  14432. sizeof(*t[2]) * 70 * 2);
  14433. }
  14434. sp_4096_mont_reduce_70(t[0], m, mp);
  14435. n = sp_4096_cmp_70(t[0], m);
  14436. sp_4096_cond_sub_70(t[0], t[0], m, ~(n >> 63));
  14437. XMEMCPY(r, t[0], sizeof(*r) * 70 * 2);
  14438. }
  14439. #ifdef WOLFSSL_SP_SMALL_STACK
  14440. if (td != NULL)
  14441. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  14442. #endif
  14443. return err;
  14444. #else
  14445. #ifdef WOLFSSL_SP_SMALL_STACK
  14446. sp_digit* td = NULL;
  14447. #else
  14448. sp_digit td[(16 * 140) + 140];
  14449. #endif
  14450. sp_digit* t[16];
  14451. sp_digit* rt = NULL;
  14452. sp_digit* norm = NULL;
  14453. sp_digit mp = 1;
  14454. sp_digit n;
  14455. int i;
  14456. int c;
  14457. byte y;
  14458. int err = MP_OKAY;
  14459. if (bits == 0) {
  14460. err = MP_VAL;
  14461. }
  14462. #ifdef WOLFSSL_SP_SMALL_STACK
  14463. if (err == MP_OKAY) {
  14464. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 140) + 140), NULL,
  14465. DYNAMIC_TYPE_TMP_BUFFER);
  14466. if (td == NULL)
  14467. err = MEMORY_E;
  14468. }
  14469. #endif
  14470. if (err == MP_OKAY) {
  14471. norm = td;
  14472. for (i=0; i<16; i++)
  14473. t[i] = td + i * 140;
  14474. rt = td + 2240;
  14475. sp_4096_mont_setup(m, &mp);
  14476. sp_4096_mont_norm_70(norm, m);
  14477. if (reduceA != 0) {
  14478. err = sp_4096_mod_70(t[1], a, m);
  14479. if (err == MP_OKAY) {
  14480. sp_4096_mul_70(t[1], t[1], norm);
  14481. err = sp_4096_mod_70(t[1], t[1], m);
  14482. }
  14483. }
  14484. else {
  14485. sp_4096_mul_70(t[1], a, norm);
  14486. err = sp_4096_mod_70(t[1], t[1], m);
  14487. }
  14488. }
  14489. if (err == MP_OKAY) {
  14490. sp_4096_mont_sqr_70(t[ 2], t[ 1], m, mp);
  14491. sp_4096_mont_mul_70(t[ 3], t[ 2], t[ 1], m, mp);
  14492. sp_4096_mont_sqr_70(t[ 4], t[ 2], m, mp);
  14493. sp_4096_mont_mul_70(t[ 5], t[ 3], t[ 2], m, mp);
  14494. sp_4096_mont_sqr_70(t[ 6], t[ 3], m, mp);
  14495. sp_4096_mont_mul_70(t[ 7], t[ 4], t[ 3], m, mp);
  14496. sp_4096_mont_sqr_70(t[ 8], t[ 4], m, mp);
  14497. sp_4096_mont_mul_70(t[ 9], t[ 5], t[ 4], m, mp);
  14498. sp_4096_mont_sqr_70(t[10], t[ 5], m, mp);
  14499. sp_4096_mont_mul_70(t[11], t[ 6], t[ 5], m, mp);
  14500. sp_4096_mont_sqr_70(t[12], t[ 6], m, mp);
  14501. sp_4096_mont_mul_70(t[13], t[ 7], t[ 6], m, mp);
  14502. sp_4096_mont_sqr_70(t[14], t[ 7], m, mp);
  14503. sp_4096_mont_mul_70(t[15], t[ 8], t[ 7], m, mp);
  14504. bits = ((bits + 3) / 4) * 4;
  14505. i = ((bits + 58) / 59) - 1;
  14506. c = bits % 59;
  14507. if (c == 0) {
  14508. c = 59;
  14509. }
  14510. if (i < 70) {
  14511. n = e[i--] << (64 - c);
  14512. }
  14513. else {
  14514. n = 0;
  14515. i--;
  14516. }
  14517. if (c < 4) {
  14518. n |= e[i--] << (5 - c);
  14519. c += 59;
  14520. }
  14521. y = (int)((n >> 60) & 0xf);
  14522. n <<= 4;
  14523. c -= 4;
  14524. XMEMCPY(rt, t[y], sizeof(sp_digit) * 140);
  14525. while ((i >= 0) || (c >= 4)) {
  14526. if (c >= 4) {
  14527. y = (byte)((n >> 60) & 0xf);
  14528. n <<= 4;
  14529. c -= 4;
  14530. }
  14531. else if (c == 0) {
  14532. n = e[i--] << 5;
  14533. y = (byte)((n >> 60) & 0xf);
  14534. n <<= 4;
  14535. c = 55;
  14536. }
  14537. else {
  14538. y = (byte)((n >> 60) & 0xf);
  14539. n = e[i--] << 5;
  14540. c = 4 - c;
  14541. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  14542. n <<= c;
  14543. c = 59 - c;
  14544. }
  14545. sp_4096_mont_sqr_70(rt, rt, m, mp);
  14546. sp_4096_mont_sqr_70(rt, rt, m, mp);
  14547. sp_4096_mont_sqr_70(rt, rt, m, mp);
  14548. sp_4096_mont_sqr_70(rt, rt, m, mp);
  14549. sp_4096_mont_mul_70(rt, rt, t[y], m, mp);
  14550. }
  14551. sp_4096_mont_reduce_70(rt, m, mp);
  14552. n = sp_4096_cmp_70(rt, m);
  14553. sp_4096_cond_sub_70(rt, rt, m, ~(n >> 63));
  14554. XMEMCPY(r, rt, sizeof(sp_digit) * 140);
  14555. }
  14556. #ifdef WOLFSSL_SP_SMALL_STACK
  14557. if (td != NULL)
  14558. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  14559. #endif
  14560. return err;
  14561. #endif
  14562. }
  14563. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  14564. #ifdef WOLFSSL_HAVE_SP_RSA
  14565. /* RSA public key operation.
  14566. *
  14567. * in Array of bytes representing the number to exponentiate, base.
  14568. * inLen Number of bytes in base.
  14569. * em Public exponent.
  14570. * mm Modulus.
  14571. * out Buffer to hold big-endian bytes of exponentiation result.
  14572. * Must be at least 512 bytes long.
  14573. * outLen Number of bytes in result.
  14574. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  14575. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  14576. */
  14577. int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em,
  14578. const mp_int* mm, byte* out, word32* outLen)
  14579. {
  14580. #ifdef WOLFSSL_SP_SMALL
  14581. #ifdef WOLFSSL_SP_SMALL_STACK
  14582. sp_digit* a = NULL;
  14583. #else
  14584. sp_digit a[70 * 5];
  14585. #endif
  14586. sp_digit* m = NULL;
  14587. sp_digit* r = NULL;
  14588. sp_digit* norm = NULL;
  14589. sp_digit e[1] = {0};
  14590. sp_digit mp = 0;
  14591. int i;
  14592. int err = MP_OKAY;
  14593. if (*outLen < 512U) {
  14594. err = MP_TO_E;
  14595. }
  14596. if (err == MP_OKAY) {
  14597. if (mp_count_bits(em) > 59) {
  14598. err = MP_READ_E;
  14599. }
  14600. else if (inLen > 512U) {
  14601. err = MP_READ_E;
  14602. }
  14603. else if (mp_count_bits(mm) != 4096) {
  14604. err = MP_READ_E;
  14605. }
  14606. else if (mp_iseven(mm)) {
  14607. err = MP_VAL;
  14608. }
  14609. }
  14610. #ifdef WOLFSSL_SP_SMALL_STACK
  14611. if (err == MP_OKAY) {
  14612. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 5, NULL,
  14613. DYNAMIC_TYPE_RSA);
  14614. if (a == NULL)
  14615. err = MEMORY_E;
  14616. }
  14617. #endif
  14618. if (err == MP_OKAY) {
  14619. r = a + 70 * 2;
  14620. m = r + 70 * 2;
  14621. norm = r;
  14622. sp_4096_from_bin(a, 70, in, inLen);
  14623. #if DIGIT_BIT >= 59
  14624. e[0] = (sp_digit)em->dp[0];
  14625. #else
  14626. e[0] = (sp_digit)em->dp[0];
  14627. if (em->used > 1) {
  14628. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  14629. }
  14630. #endif
  14631. if (e[0] == 0) {
  14632. err = MP_EXPTMOD_E;
  14633. }
  14634. }
  14635. if (err == MP_OKAY) {
  14636. sp_4096_from_mp(m, 70, mm);
  14637. sp_4096_mont_setup(m, &mp);
  14638. sp_4096_mont_norm_70(norm, m);
  14639. }
  14640. if (err == MP_OKAY) {
  14641. sp_4096_mul_70(a, a, norm);
  14642. err = sp_4096_mod_70(a, a, m);
  14643. }
  14644. if (err == MP_OKAY) {
  14645. for (i=58; i>=0; i--) {
  14646. if ((e[0] >> i) != 0) {
  14647. break;
  14648. }
  14649. }
  14650. XMEMCPY(r, a, sizeof(sp_digit) * 70 * 2);
  14651. for (i--; i>=0; i--) {
  14652. sp_4096_mont_sqr_70(r, r, m, mp);
  14653. if (((e[0] >> i) & 1) == 1) {
  14654. sp_4096_mont_mul_70(r, r, a, m, mp);
  14655. }
  14656. }
  14657. sp_4096_mont_reduce_70(r, m, mp);
  14658. mp = sp_4096_cmp_70(r, m);
  14659. sp_4096_cond_sub_70(r, r, m, ~(mp >> 63));
  14660. sp_4096_to_bin_70(r, out);
  14661. *outLen = 512;
  14662. }
  14663. #ifdef WOLFSSL_SP_SMALL_STACK
  14664. if (a != NULL)
  14665. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  14666. #endif
  14667. return err;
  14668. #else
  14669. #ifdef WOLFSSL_SP_SMALL_STACK
  14670. sp_digit* d = NULL;
  14671. #else
  14672. sp_digit d[70 * 5];
  14673. #endif
  14674. sp_digit* a = NULL;
  14675. sp_digit* m = NULL;
  14676. sp_digit* r = NULL;
  14677. sp_digit e[1] = {0};
  14678. int err = MP_OKAY;
  14679. if (*outLen < 512U) {
  14680. err = MP_TO_E;
  14681. }
  14682. if (err == MP_OKAY) {
  14683. if (mp_count_bits(em) > 59) {
  14684. err = MP_READ_E;
  14685. }
  14686. else if (inLen > 512U) {
  14687. err = MP_READ_E;
  14688. }
  14689. else if (mp_count_bits(mm) != 4096) {
  14690. err = MP_READ_E;
  14691. }
  14692. else if (mp_iseven(mm)) {
  14693. err = MP_VAL;
  14694. }
  14695. }
  14696. #ifdef WOLFSSL_SP_SMALL_STACK
  14697. if (err == MP_OKAY) {
  14698. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 5, NULL,
  14699. DYNAMIC_TYPE_RSA);
  14700. if (d == NULL)
  14701. err = MEMORY_E;
  14702. }
  14703. #endif
  14704. if (err == MP_OKAY) {
  14705. a = d;
  14706. r = a + 70 * 2;
  14707. m = r + 70 * 2;
  14708. sp_4096_from_bin(a, 70, in, inLen);
  14709. #if DIGIT_BIT >= 59
  14710. e[0] = (sp_digit)em->dp[0];
  14711. #else
  14712. e[0] = (sp_digit)em->dp[0];
  14713. if (em->used > 1) {
  14714. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  14715. }
  14716. #endif
  14717. if (e[0] == 0) {
  14718. err = MP_EXPTMOD_E;
  14719. }
  14720. }
  14721. if (err == MP_OKAY) {
  14722. sp_4096_from_mp(m, 70, mm);
  14723. if (e[0] == 0x3) {
  14724. sp_4096_sqr_70(r, a);
  14725. err = sp_4096_mod_70(r, r, m);
  14726. if (err == MP_OKAY) {
  14727. sp_4096_mul_70(r, a, r);
  14728. err = sp_4096_mod_70(r, r, m);
  14729. }
  14730. }
  14731. else {
  14732. sp_digit* norm = r;
  14733. int i;
  14734. sp_digit mp;
  14735. sp_4096_mont_setup(m, &mp);
  14736. sp_4096_mont_norm_70(norm, m);
  14737. sp_4096_mul_70(a, a, norm);
  14738. err = sp_4096_mod_70(a, a, m);
  14739. if (err == MP_OKAY) {
  14740. for (i=58; i>=0; i--) {
  14741. if ((e[0] >> i) != 0) {
  14742. break;
  14743. }
  14744. }
  14745. XMEMCPY(r, a, sizeof(sp_digit) * 140U);
  14746. for (i--; i>=0; i--) {
  14747. sp_4096_mont_sqr_70(r, r, m, mp);
  14748. if (((e[0] >> i) & 1) == 1) {
  14749. sp_4096_mont_mul_70(r, r, a, m, mp);
  14750. }
  14751. }
  14752. sp_4096_mont_reduce_70(r, m, mp);
  14753. mp = sp_4096_cmp_70(r, m);
  14754. sp_4096_cond_sub_70(r, r, m, ~(mp >> 63));
  14755. }
  14756. }
  14757. }
  14758. if (err == MP_OKAY) {
  14759. sp_4096_to_bin_70(r, out);
  14760. *outLen = 512;
  14761. }
  14762. #ifdef WOLFSSL_SP_SMALL_STACK
  14763. if (d != NULL)
  14764. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  14765. #endif
  14766. return err;
  14767. #endif /* WOLFSSL_SP_SMALL */
  14768. }
  14769. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  14770. #if !defined(SP_RSA_PRIVATE_EXP_D) && !defined(RSA_LOW_MEM)
  14771. #endif /* !SP_RSA_PRIVATE_EXP_D & !RSA_LOW_MEM */
  14772. /* RSA private key operation.
  14773. *
  14774. * in Array of bytes representing the number to exponentiate, base.
  14775. * inLen Number of bytes in base.
  14776. * dm Private exponent.
  14777. * pm First prime.
  14778. * qm Second prime.
  14779. * dpm First prime's CRT exponent.
  14780. * dqm Second prime's CRT exponent.
  14781. * qim Inverse of second prime mod p.
  14782. * mm Modulus.
  14783. * out Buffer to hold big-endian bytes of exponentiation result.
  14784. * Must be at least 512 bytes long.
  14785. * outLen Number of bytes in result.
  14786. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  14787. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  14788. */
  14789. int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm,
  14790. const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm,
  14791. const mp_int* qim, const mp_int* mm, byte* out, word32* outLen)
  14792. {
  14793. #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM)
  14794. #if defined(WOLFSSL_SP_SMALL)
  14795. #ifdef WOLFSSL_SP_SMALL_STACK
  14796. sp_digit* d = NULL;
  14797. #else
  14798. sp_digit d[70 * 4];
  14799. #endif
  14800. sp_digit* a = NULL;
  14801. sp_digit* m = NULL;
  14802. sp_digit* r = NULL;
  14803. int err = MP_OKAY;
  14804. (void)pm;
  14805. (void)qm;
  14806. (void)dpm;
  14807. (void)dqm;
  14808. (void)qim;
  14809. if (*outLen < 512U) {
  14810. err = MP_TO_E;
  14811. }
  14812. if (err == MP_OKAY) {
  14813. if (mp_count_bits(dm) > 4096) {
  14814. err = MP_READ_E;
  14815. }
  14816. else if (inLen > 512) {
  14817. err = MP_READ_E;
  14818. }
  14819. else if (mp_count_bits(mm) != 4096) {
  14820. err = MP_READ_E;
  14821. }
  14822. else if (mp_iseven(mm)) {
  14823. err = MP_VAL;
  14824. }
  14825. }
  14826. #ifdef WOLFSSL_SP_SMALL_STACK
  14827. if (err == MP_OKAY) {
  14828. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL,
  14829. DYNAMIC_TYPE_RSA);
  14830. if (d == NULL)
  14831. err = MEMORY_E;
  14832. }
  14833. #endif
  14834. if (err == MP_OKAY) {
  14835. a = d + 70;
  14836. m = a + 140;
  14837. r = a;
  14838. sp_4096_from_bin(a, 70, in, inLen);
  14839. sp_4096_from_mp(d, 70, dm);
  14840. sp_4096_from_mp(m, 70, mm);
  14841. err = sp_4096_mod_exp_70(r, a, d, 4096, m, 0);
  14842. }
  14843. if (err == MP_OKAY) {
  14844. sp_4096_to_bin_70(r, out);
  14845. *outLen = 512;
  14846. }
  14847. #ifdef WOLFSSL_SP_SMALL_STACK
  14848. if (d != NULL)
  14849. #endif
  14850. {
  14851. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  14852. if (a != NULL)
  14853. ForceZero(a, sizeof(sp_digit) * 70);
  14854. #ifdef WOLFSSL_SP_SMALL_STACK
  14855. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  14856. #endif
  14857. }
  14858. return err;
  14859. #else
  14860. #ifdef WOLFSSL_SP_SMALL_STACK
  14861. sp_digit* d = NULL;
  14862. #else
  14863. sp_digit d[70 * 4];
  14864. #endif
  14865. sp_digit* a = NULL;
  14866. sp_digit* m = NULL;
  14867. sp_digit* r = NULL;
  14868. int err = MP_OKAY;
  14869. (void)pm;
  14870. (void)qm;
  14871. (void)dpm;
  14872. (void)dqm;
  14873. (void)qim;
  14874. if (*outLen < 512U) {
  14875. err = MP_TO_E;
  14876. }
  14877. if (err == MP_OKAY) {
  14878. if (mp_count_bits(dm) > 4096) {
  14879. err = MP_READ_E;
  14880. }
  14881. else if (inLen > 512U) {
  14882. err = MP_READ_E;
  14883. }
  14884. else if (mp_count_bits(mm) != 4096) {
  14885. err = MP_READ_E;
  14886. }
  14887. else if (mp_iseven(mm)) {
  14888. err = MP_VAL;
  14889. }
  14890. }
  14891. #ifdef WOLFSSL_SP_SMALL_STACK
  14892. if (err == MP_OKAY) {
  14893. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL,
  14894. DYNAMIC_TYPE_RSA);
  14895. if (d == NULL)
  14896. err = MEMORY_E;
  14897. }
  14898. #endif
  14899. if (err == MP_OKAY) {
  14900. a = d + 70;
  14901. m = a + 140;
  14902. r = a;
  14903. sp_4096_from_bin(a, 70, in, inLen);
  14904. sp_4096_from_mp(d, 70, dm);
  14905. sp_4096_from_mp(m, 70, mm);
  14906. err = sp_4096_mod_exp_70(r, a, d, 4096, m, 0);
  14907. }
  14908. if (err == MP_OKAY) {
  14909. sp_4096_to_bin_70(r, out);
  14910. *outLen = 512;
  14911. }
  14912. #ifdef WOLFSSL_SP_SMALL_STACK
  14913. if (d != NULL)
  14914. #endif
  14915. {
  14916. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  14917. if (a != NULL)
  14918. ForceZero(a, sizeof(sp_digit) * 70);
  14919. #ifdef WOLFSSL_SP_SMALL_STACK
  14920. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  14921. #endif
  14922. }
  14923. return err;
  14924. #endif /* WOLFSSL_SP_SMALL */
  14925. #else
  14926. #if defined(WOLFSSL_SP_SMALL)
  14927. #ifdef WOLFSSL_SP_SMALL_STACK
  14928. sp_digit* a = NULL;
  14929. #else
  14930. sp_digit a[35 * 8];
  14931. #endif
  14932. sp_digit* p = NULL;
  14933. sp_digit* dp = NULL;
  14934. sp_digit* dq = NULL;
  14935. sp_digit* qi = NULL;
  14936. sp_digit* tmpa = NULL;
  14937. sp_digit* tmpb = NULL;
  14938. sp_digit* r = NULL;
  14939. int err = MP_OKAY;
  14940. (void)dm;
  14941. (void)mm;
  14942. if (*outLen < 512U) {
  14943. err = MP_TO_E;
  14944. }
  14945. if (err == MP_OKAY) {
  14946. if (inLen > 512) {
  14947. err = MP_READ_E;
  14948. }
  14949. else if (mp_count_bits(mm) != 4096) {
  14950. err = MP_READ_E;
  14951. }
  14952. else if (mp_iseven(mm)) {
  14953. err = MP_VAL;
  14954. }
  14955. else if (mp_iseven(pm)) {
  14956. err = MP_VAL;
  14957. }
  14958. else if (mp_iseven(qm)) {
  14959. err = MP_VAL;
  14960. }
  14961. }
  14962. #ifdef WOLFSSL_SP_SMALL_STACK
  14963. if (err == MP_OKAY) {
  14964. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 35 * 8, NULL,
  14965. DYNAMIC_TYPE_RSA);
  14966. if (a == NULL)
  14967. err = MEMORY_E;
  14968. }
  14969. #endif
  14970. if (err == MP_OKAY) {
  14971. p = a + 70;
  14972. qi = dq = dp = p + 35;
  14973. tmpa = qi + 35;
  14974. tmpb = tmpa + 70;
  14975. r = a;
  14976. sp_4096_from_bin(a, 70, in, inLen);
  14977. sp_4096_from_mp(p, 35, pm);
  14978. sp_4096_from_mp(dp, 35, dpm);
  14979. err = sp_4096_mod_exp_35(tmpa, a, dp, 2048, p, 1);
  14980. }
  14981. if (err == MP_OKAY) {
  14982. sp_4096_from_mp(p, 35, qm);
  14983. sp_4096_from_mp(dq, 35, dqm);
  14984. err = sp_4096_mod_exp_35(tmpb, a, dq, 2048, p, 1);
  14985. }
  14986. if (err == MP_OKAY) {
  14987. sp_4096_from_mp(p, 35, pm);
  14988. (void)sp_4096_sub_35(tmpa, tmpa, tmpb);
  14989. sp_4096_norm_35(tmpa);
  14990. sp_4096_cond_add_35(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[34] >> 63));
  14991. sp_4096_cond_add_35(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[34] >> 63));
  14992. sp_4096_norm_35(tmpa);
  14993. sp_4096_from_mp(qi, 35, qim);
  14994. sp_4096_mul_35(tmpa, tmpa, qi);
  14995. err = sp_4096_mod_35(tmpa, tmpa, p);
  14996. }
  14997. if (err == MP_OKAY) {
  14998. sp_4096_from_mp(p, 35, qm);
  14999. sp_4096_mul_35(tmpa, p, tmpa);
  15000. (void)sp_4096_add_70(r, tmpb, tmpa);
  15001. sp_4096_norm_70(r);
  15002. sp_4096_to_bin_70(r, out);
  15003. *outLen = 512;
  15004. }
  15005. #ifdef WOLFSSL_SP_SMALL_STACK
  15006. if (a != NULL)
  15007. #endif
  15008. {
  15009. ForceZero(a, sizeof(sp_digit) * 35 * 8);
  15010. #ifdef WOLFSSL_SP_SMALL_STACK
  15011. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  15012. #endif
  15013. }
  15014. return err;
  15015. #else
  15016. #ifdef WOLFSSL_SP_SMALL_STACK
  15017. sp_digit* a = NULL;
  15018. #else
  15019. sp_digit a[35 * 13];
  15020. #endif
  15021. sp_digit* p = NULL;
  15022. sp_digit* q = NULL;
  15023. sp_digit* dp = NULL;
  15024. sp_digit* dq = NULL;
  15025. sp_digit* qi = NULL;
  15026. sp_digit* tmpa = NULL;
  15027. sp_digit* tmpb = NULL;
  15028. sp_digit* r = NULL;
  15029. int err = MP_OKAY;
  15030. (void)dm;
  15031. (void)mm;
  15032. if (*outLen < 512U) {
  15033. err = MP_TO_E;
  15034. }
  15035. if (err == MP_OKAY) {
  15036. if (inLen > 512U) {
  15037. err = MP_READ_E;
  15038. }
  15039. else if (mp_count_bits(mm) != 4096) {
  15040. err = MP_READ_E;
  15041. }
  15042. else if (mp_iseven(mm)) {
  15043. err = MP_VAL;
  15044. }
  15045. else if (mp_iseven(pm)) {
  15046. err = MP_VAL;
  15047. }
  15048. else if (mp_iseven(qm)) {
  15049. err = MP_VAL;
  15050. }
  15051. }
  15052. #ifdef WOLFSSL_SP_SMALL_STACK
  15053. if (err == MP_OKAY) {
  15054. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 35 * 13, NULL,
  15055. DYNAMIC_TYPE_RSA);
  15056. if (a == NULL)
  15057. err = MEMORY_E;
  15058. }
  15059. #endif
  15060. if (err == MP_OKAY) {
  15061. p = a + 70 * 2;
  15062. q = p + 35;
  15063. dp = q + 35;
  15064. dq = dp + 35;
  15065. qi = dq + 35;
  15066. tmpa = qi + 35;
  15067. tmpb = tmpa + 70;
  15068. r = a;
  15069. sp_4096_from_bin(a, 70, in, inLen);
  15070. sp_4096_from_mp(p, 35, pm);
  15071. sp_4096_from_mp(q, 35, qm);
  15072. sp_4096_from_mp(dp, 35, dpm);
  15073. sp_4096_from_mp(dq, 35, dqm);
  15074. sp_4096_from_mp(qi, 35, qim);
  15075. err = sp_4096_mod_exp_35(tmpa, a, dp, 2048, p, 1);
  15076. }
  15077. if (err == MP_OKAY) {
  15078. err = sp_4096_mod_exp_35(tmpb, a, dq, 2048, q, 1);
  15079. }
  15080. if (err == MP_OKAY) {
  15081. (void)sp_4096_sub_35(tmpa, tmpa, tmpb);
  15082. sp_4096_norm_35(tmpa);
  15083. sp_4096_cond_add_35(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[34] >> 63));
  15084. sp_4096_cond_add_35(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[34] >> 63));
  15085. sp_4096_norm_35(tmpa);
  15086. sp_4096_mul_35(tmpa, tmpa, qi);
  15087. err = sp_4096_mod_35(tmpa, tmpa, p);
  15088. }
  15089. if (err == MP_OKAY) {
  15090. sp_4096_mul_35(tmpa, tmpa, q);
  15091. (void)sp_4096_add_70(r, tmpb, tmpa);
  15092. sp_4096_norm_70(r);
  15093. sp_4096_to_bin_70(r, out);
  15094. *outLen = 512;
  15095. }
  15096. #ifdef WOLFSSL_SP_SMALL_STACK
  15097. if (a != NULL)
  15098. #endif
  15099. {
  15100. ForceZero(a, sizeof(sp_digit) * 35 * 13);
  15101. #ifdef WOLFSSL_SP_SMALL_STACK
  15102. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  15103. #endif
  15104. }
  15105. return err;
  15106. #endif /* WOLFSSL_SP_SMALL */
  15107. #endif /* SP_RSA_PRIVATE_EXP_D || RSA_LOW_MEM */
  15108. }
  15109. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  15110. #endif /* WOLFSSL_HAVE_SP_RSA */
  15111. #if defined(WOLFSSL_HAVE_SP_DH) || (defined(WOLFSSL_HAVE_SP_RSA) && \
  15112. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  15113. /* Convert an array of sp_digit to an mp_int.
  15114. *
  15115. * a A single precision integer.
  15116. * r A multi-precision integer.
  15117. */
  15118. static int sp_4096_to_mp(const sp_digit* a, mp_int* r)
  15119. {
  15120. int err;
  15121. err = mp_grow(r, (4096 + DIGIT_BIT - 1) / DIGIT_BIT);
  15122. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  15123. #if DIGIT_BIT == 59
  15124. XMEMCPY(r->dp, a, sizeof(sp_digit) * 70);
  15125. r->used = 70;
  15126. mp_clamp(r);
  15127. #elif DIGIT_BIT < 59
  15128. int i;
  15129. int j = 0;
  15130. int s = 0;
  15131. r->dp[0] = 0;
  15132. for (i = 0; i < 70; i++) {
  15133. r->dp[j] |= (mp_digit)(a[i] << s);
  15134. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  15135. s = DIGIT_BIT - s;
  15136. r->dp[++j] = (mp_digit)(a[i] >> s);
  15137. while (s + DIGIT_BIT <= 59) {
  15138. s += DIGIT_BIT;
  15139. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  15140. if (s == SP_WORD_SIZE) {
  15141. r->dp[j] = 0;
  15142. }
  15143. else {
  15144. r->dp[j] = (mp_digit)(a[i] >> s);
  15145. }
  15146. }
  15147. s = 59 - s;
  15148. }
  15149. r->used = (4096 + DIGIT_BIT - 1) / DIGIT_BIT;
  15150. mp_clamp(r);
  15151. #else
  15152. int i;
  15153. int j = 0;
  15154. int s = 0;
  15155. r->dp[0] = 0;
  15156. for (i = 0; i < 70; i++) {
  15157. r->dp[j] |= ((mp_digit)a[i]) << s;
  15158. if (s + 59 >= DIGIT_BIT) {
  15159. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  15160. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  15161. #endif
  15162. s = DIGIT_BIT - s;
  15163. r->dp[++j] = a[i] >> s;
  15164. s = 59 - s;
  15165. }
  15166. else {
  15167. s += 59;
  15168. }
  15169. }
  15170. r->used = (4096 + DIGIT_BIT - 1) / DIGIT_BIT;
  15171. mp_clamp(r);
  15172. #endif
  15173. }
  15174. return err;
  15175. }
  15176. /* Perform the modular exponentiation for Diffie-Hellman.
  15177. *
  15178. * base Base. MP integer.
  15179. * exp Exponent. MP integer.
  15180. * mod Modulus. MP integer.
  15181. * res Result. MP integer.
  15182. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  15183. * and MEMORY_E if memory allocation fails.
  15184. */
  15185. int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod,
  15186. mp_int* res)
  15187. {
  15188. #ifdef WOLFSSL_SP_SMALL
  15189. int err = MP_OKAY;
  15190. #ifdef WOLFSSL_SP_SMALL_STACK
  15191. sp_digit* b = NULL;
  15192. #else
  15193. sp_digit b[70 * 4];
  15194. #endif
  15195. sp_digit* e = NULL;
  15196. sp_digit* m = NULL;
  15197. sp_digit* r = NULL;
  15198. int expBits = mp_count_bits(exp);
  15199. if (mp_count_bits(base) > 4096) {
  15200. err = MP_READ_E;
  15201. }
  15202. else if (expBits > 4096) {
  15203. err = MP_READ_E;
  15204. }
  15205. else if (mp_count_bits(mod) != 4096) {
  15206. err = MP_READ_E;
  15207. }
  15208. else if (mp_iseven(mod)) {
  15209. err = MP_VAL;
  15210. }
  15211. #ifdef WOLFSSL_SP_SMALL_STACK
  15212. if (err == MP_OKAY) {
  15213. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL,
  15214. DYNAMIC_TYPE_DH);
  15215. if (b == NULL)
  15216. err = MEMORY_E;
  15217. }
  15218. #endif
  15219. if (err == MP_OKAY) {
  15220. e = b + 70 * 2;
  15221. m = e + 70;
  15222. r = b;
  15223. sp_4096_from_mp(b, 70, base);
  15224. sp_4096_from_mp(e, 70, exp);
  15225. sp_4096_from_mp(m, 70, mod);
  15226. err = sp_4096_mod_exp_70(r, b, e, mp_count_bits(exp), m, 0);
  15227. }
  15228. if (err == MP_OKAY) {
  15229. err = sp_4096_to_mp(r, res);
  15230. }
  15231. #ifdef WOLFSSL_SP_SMALL_STACK
  15232. if (b != NULL)
  15233. #endif
  15234. {
  15235. /* only "e" is sensitive and needs zeroized */
  15236. if (e != NULL)
  15237. ForceZero(e, sizeof(sp_digit) * 70U);
  15238. #ifdef WOLFSSL_SP_SMALL_STACK
  15239. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  15240. #endif
  15241. }
  15242. return err;
  15243. #else
  15244. #ifdef WOLFSSL_SP_SMALL_STACK
  15245. sp_digit* b = NULL;
  15246. #else
  15247. sp_digit b[70 * 4];
  15248. #endif
  15249. sp_digit* e = NULL;
  15250. sp_digit* m = NULL;
  15251. sp_digit* r = NULL;
  15252. int err = MP_OKAY;
  15253. int expBits = mp_count_bits(exp);
  15254. if (mp_count_bits(base) > 4096) {
  15255. err = MP_READ_E;
  15256. }
  15257. else if (expBits > 4096) {
  15258. err = MP_READ_E;
  15259. }
  15260. else if (mp_count_bits(mod) != 4096) {
  15261. err = MP_READ_E;
  15262. }
  15263. else if (mp_iseven(mod)) {
  15264. err = MP_VAL;
  15265. }
  15266. #ifdef WOLFSSL_SP_SMALL_STACK
  15267. if (err == MP_OKAY) {
  15268. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL, DYNAMIC_TYPE_DH);
  15269. if (b == NULL)
  15270. err = MEMORY_E;
  15271. }
  15272. #endif
  15273. if (err == MP_OKAY) {
  15274. e = b + 70 * 2;
  15275. m = e + 70;
  15276. r = b;
  15277. sp_4096_from_mp(b, 70, base);
  15278. sp_4096_from_mp(e, 70, exp);
  15279. sp_4096_from_mp(m, 70, mod);
  15280. err = sp_4096_mod_exp_70(r, b, e, expBits, m, 0);
  15281. }
  15282. if (err == MP_OKAY) {
  15283. err = sp_4096_to_mp(r, res);
  15284. }
  15285. #ifdef WOLFSSL_SP_SMALL_STACK
  15286. if (b != NULL)
  15287. #endif
  15288. {
  15289. /* only "e" is sensitive and needs zeroized */
  15290. if (e != NULL)
  15291. ForceZero(e, sizeof(sp_digit) * 70U);
  15292. #ifdef WOLFSSL_SP_SMALL_STACK
  15293. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  15294. #endif
  15295. }
  15296. return err;
  15297. #endif
  15298. }
  15299. #ifdef WOLFSSL_HAVE_SP_DH
  15300. #ifdef HAVE_FFDHE_4096
  15301. SP_NOINLINE static void sp_4096_lshift_70(sp_digit* r, const sp_digit* a,
  15302. byte n)
  15303. {
  15304. int i;
  15305. r[70] = a[69] >> (59 - n);
  15306. for (i=69; i>0; i--) {
  15307. r[i] = ((a[i] << n) | (a[i-1] >> (59 - n))) & 0x7ffffffffffffffL;
  15308. }
  15309. r[0] = (a[0] << n) & 0x7ffffffffffffffL;
  15310. }
  15311. /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m)
  15312. *
  15313. * r A single precision number that is the result of the operation.
  15314. * e A single precision number that is the exponent.
  15315. * bits The number of bits in the exponent.
  15316. * m A single precision number that is the modulus.
  15317. * returns 0 on success.
  15318. * returns MEMORY_E on dynamic memory allocation failure.
  15319. * returns MP_VAL when base is even.
  15320. */
  15321. static int sp_4096_mod_exp_2_70(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
  15322. {
  15323. #ifdef WOLFSSL_SP_SMALL_STACK
  15324. sp_digit* td = NULL;
  15325. #else
  15326. sp_digit td[211];
  15327. #endif
  15328. sp_digit* norm = NULL;
  15329. sp_digit* tmp = NULL;
  15330. sp_digit mp = 1;
  15331. sp_digit n;
  15332. sp_digit o;
  15333. int i;
  15334. int c;
  15335. byte y;
  15336. int err = MP_OKAY;
  15337. if (bits == 0) {
  15338. err = MP_VAL;
  15339. }
  15340. #ifdef WOLFSSL_SP_SMALL_STACK
  15341. if (err == MP_OKAY) {
  15342. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 211, NULL,
  15343. DYNAMIC_TYPE_TMP_BUFFER);
  15344. if (td == NULL)
  15345. err = MEMORY_E;
  15346. }
  15347. #endif
  15348. if (err == MP_OKAY) {
  15349. norm = td;
  15350. tmp = td + 140;
  15351. XMEMSET(td, 0, sizeof(sp_digit) * 211);
  15352. sp_4096_mont_setup(m, &mp);
  15353. sp_4096_mont_norm_70(norm, m);
  15354. bits = ((bits + 4) / 5) * 5;
  15355. i = ((bits + 58) / 59) - 1;
  15356. c = bits % 59;
  15357. if (c == 0) {
  15358. c = 59;
  15359. }
  15360. if (i < 70) {
  15361. n = e[i--] << (64 - c);
  15362. }
  15363. else {
  15364. n = 0;
  15365. i--;
  15366. }
  15367. if (c < 5) {
  15368. n |= e[i--] << (5 - c);
  15369. c += 59;
  15370. }
  15371. y = (int)((n >> 59) & 0x1f);
  15372. n <<= 5;
  15373. c -= 5;
  15374. sp_4096_lshift_70(r, norm, (byte)y);
  15375. while ((i >= 0) || (c >= 5)) {
  15376. if (c >= 5) {
  15377. y = (byte)((n >> 59) & 0x1f);
  15378. n <<= 5;
  15379. c -= 5;
  15380. }
  15381. else if (c == 0) {
  15382. n = e[i--] << 5;
  15383. y = (byte)((n >> 59) & 0x1f);
  15384. n <<= 5;
  15385. c = 54;
  15386. }
  15387. else {
  15388. y = (byte)((n >> 59) & 0x1f);
  15389. n = e[i--] << 5;
  15390. c = 5 - c;
  15391. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  15392. n <<= c;
  15393. c = 59 - c;
  15394. }
  15395. sp_4096_mont_sqr_70(r, r, m, mp);
  15396. sp_4096_mont_sqr_70(r, r, m, mp);
  15397. sp_4096_mont_sqr_70(r, r, m, mp);
  15398. sp_4096_mont_sqr_70(r, r, m, mp);
  15399. sp_4096_mont_sqr_70(r, r, m, mp);
  15400. sp_4096_lshift_70(r, r, (byte)y);
  15401. sp_4096_mul_d_70(tmp, norm, (r[70] << 34) + (r[69] >> 25));
  15402. r[70] = 0;
  15403. r[69] &= 0x1ffffffL;
  15404. (void)sp_4096_add_70(r, r, tmp);
  15405. sp_4096_norm_70(r);
  15406. o = sp_4096_cmp_70(r, m);
  15407. sp_4096_cond_sub_70(r, r, m, ~(o >> 63));
  15408. }
  15409. sp_4096_mont_reduce_70(r, m, mp);
  15410. n = sp_4096_cmp_70(r, m);
  15411. sp_4096_cond_sub_70(r, r, m, ~(n >> 63));
  15412. }
  15413. #ifdef WOLFSSL_SP_SMALL_STACK
  15414. if (td != NULL)
  15415. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  15416. #endif
  15417. return err;
  15418. }
  15419. #endif /* HAVE_FFDHE_4096 */
  15420. /* Perform the modular exponentiation for Diffie-Hellman.
  15421. *
  15422. * base Base.
  15423. * exp Array of bytes that is the exponent.
  15424. * expLen Length of data, in bytes, in exponent.
  15425. * mod Modulus.
  15426. * out Buffer to hold big-endian bytes of exponentiation result.
  15427. * Must be at least 512 bytes long.
  15428. * outLen Length, in bytes, of exponentiation result.
  15429. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  15430. * and MEMORY_E if memory allocation fails.
  15431. */
  15432. int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen,
  15433. const mp_int* mod, byte* out, word32* outLen)
  15434. {
  15435. #ifdef WOLFSSL_SP_SMALL_STACK
  15436. sp_digit* b = NULL;
  15437. #else
  15438. sp_digit b[70 * 4];
  15439. #endif
  15440. sp_digit* e = NULL;
  15441. sp_digit* m = NULL;
  15442. sp_digit* r = NULL;
  15443. word32 i;
  15444. int err = MP_OKAY;
  15445. if (mp_count_bits(base) > 4096) {
  15446. err = MP_READ_E;
  15447. }
  15448. else if (expLen > 512U) {
  15449. err = MP_READ_E;
  15450. }
  15451. else if (mp_count_bits(mod) != 4096) {
  15452. err = MP_READ_E;
  15453. }
  15454. else if (mp_iseven(mod)) {
  15455. err = MP_VAL;
  15456. }
  15457. #ifdef WOLFSSL_SP_SMALL_STACK
  15458. if (err == MP_OKAY) {
  15459. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL,
  15460. DYNAMIC_TYPE_DH);
  15461. if (b == NULL)
  15462. err = MEMORY_E;
  15463. }
  15464. #endif
  15465. if (err == MP_OKAY) {
  15466. e = b + 70 * 2;
  15467. m = e + 70;
  15468. r = b;
  15469. sp_4096_from_mp(b, 70, base);
  15470. sp_4096_from_bin(e, 70, exp, expLen);
  15471. sp_4096_from_mp(m, 70, mod);
  15472. #ifdef HAVE_FFDHE_4096
  15473. if (base->used == 1 && base->dp[0] == 2U &&
  15474. ((m[69] << 7) | (m[68] >> 52)) == 0xffffffffL) {
  15475. err = sp_4096_mod_exp_2_70(r, e, expLen * 8U, m);
  15476. }
  15477. else {
  15478. #endif
  15479. err = sp_4096_mod_exp_70(r, b, e, expLen * 8U, m, 0);
  15480. #ifdef HAVE_FFDHE_4096
  15481. }
  15482. #endif
  15483. }
  15484. if (err == MP_OKAY) {
  15485. sp_4096_to_bin_70(r, out);
  15486. *outLen = 512;
  15487. for (i=0; i<512U && out[i] == 0U; i++) {
  15488. /* Search for first non-zero. */
  15489. }
  15490. *outLen -= i;
  15491. XMEMMOVE(out, out + i, *outLen);
  15492. }
  15493. #ifdef WOLFSSL_SP_SMALL_STACK
  15494. if (b != NULL)
  15495. #endif
  15496. {
  15497. /* only "e" is sensitive and needs zeroized */
  15498. if (e != NULL)
  15499. ForceZero(e, sizeof(sp_digit) * 70U);
  15500. #ifdef WOLFSSL_SP_SMALL_STACK
  15501. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  15502. #endif
  15503. }
  15504. return err;
  15505. }
  15506. #endif /* WOLFSSL_HAVE_SP_DH */
  15507. #endif /* WOLFSSL_HAVE_SP_DH | (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) */
  15508. #else
  15509. /* Read big endian unsigned byte array into r.
  15510. *
  15511. * r A single precision integer.
  15512. * size Maximum number of bytes to convert
  15513. * a Byte array.
  15514. * n Number of bytes in array to read.
  15515. */
  15516. static void sp_4096_from_bin(sp_digit* r, int size, const byte* a, int n)
  15517. {
  15518. int i;
  15519. int j = 0;
  15520. word32 s = 0;
  15521. r[0] = 0;
  15522. for (i = n-1; i >= 0; i--) {
  15523. r[j] |= (((sp_digit)a[i]) << s);
  15524. if (s >= 45U) {
  15525. r[j] &= 0x1fffffffffffffL;
  15526. s = 53U - s;
  15527. if (j + 1 >= size) {
  15528. break;
  15529. }
  15530. r[++j] = (sp_digit)a[i] >> s;
  15531. s = 8U - s;
  15532. }
  15533. else {
  15534. s += 8U;
  15535. }
  15536. }
  15537. for (j++; j < size; j++) {
  15538. r[j] = 0;
  15539. }
  15540. }
  15541. /* Convert an mp_int to an array of sp_digit.
  15542. *
  15543. * r A single precision integer.
  15544. * size Maximum number of bytes to convert
  15545. * a A multi-precision integer.
  15546. */
  15547. static void sp_4096_from_mp(sp_digit* r, int size, const mp_int* a)
  15548. {
  15549. #if DIGIT_BIT == 53
  15550. int i;
  15551. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  15552. int o = 0;
  15553. for (i = 0; i < size; i++) {
  15554. sp_digit mask = (sp_digit)0 - (j >> 52);
  15555. r[i] = a->dp[o] & mask;
  15556. j++;
  15557. o += (int)(j >> 52);
  15558. }
  15559. #elif DIGIT_BIT > 53
  15560. unsigned int i;
  15561. int j = 0;
  15562. word32 s = 0;
  15563. r[0] = 0;
  15564. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  15565. r[j] |= ((sp_digit)a->dp[i] << s);
  15566. r[j] &= 0x1fffffffffffffL;
  15567. s = 53U - s;
  15568. if (j + 1 >= size) {
  15569. break;
  15570. }
  15571. /* lint allow cast of mismatch word32 and mp_digit */
  15572. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  15573. while ((s + 53U) <= (word32)DIGIT_BIT) {
  15574. s += 53U;
  15575. r[j] &= 0x1fffffffffffffL;
  15576. if (j + 1 >= size) {
  15577. break;
  15578. }
  15579. if (s < (word32)DIGIT_BIT) {
  15580. /* lint allow cast of mismatch word32 and mp_digit */
  15581. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  15582. }
  15583. else {
  15584. r[++j] = (sp_digit)0;
  15585. }
  15586. }
  15587. s = (word32)DIGIT_BIT - s;
  15588. }
  15589. for (j++; j < size; j++) {
  15590. r[j] = 0;
  15591. }
  15592. #else
  15593. unsigned int i;
  15594. int j = 0;
  15595. int s = 0;
  15596. r[0] = 0;
  15597. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  15598. r[j] |= ((sp_digit)a->dp[i]) << s;
  15599. if (s + DIGIT_BIT >= 53) {
  15600. r[j] &= 0x1fffffffffffffL;
  15601. if (j + 1 >= size) {
  15602. break;
  15603. }
  15604. s = 53 - s;
  15605. if (s == DIGIT_BIT) {
  15606. r[++j] = 0;
  15607. s = 0;
  15608. }
  15609. else {
  15610. r[++j] = a->dp[i] >> s;
  15611. s = DIGIT_BIT - s;
  15612. }
  15613. }
  15614. else {
  15615. s += DIGIT_BIT;
  15616. }
  15617. }
  15618. for (j++; j < size; j++) {
  15619. r[j] = 0;
  15620. }
  15621. #endif
  15622. }
  15623. /* Write r as big endian to byte array.
  15624. * Fixed length number of bytes written: 512
  15625. *
  15626. * r A single precision integer.
  15627. * a Byte array.
  15628. */
  15629. static void sp_4096_to_bin_78(sp_digit* r, byte* a)
  15630. {
  15631. int i;
  15632. int j;
  15633. int s = 0;
  15634. int b;
  15635. for (i=0; i<77; i++) {
  15636. r[i+1] += r[i] >> 53;
  15637. r[i] &= 0x1fffffffffffffL;
  15638. }
  15639. j = 4103 / 8 - 1;
  15640. a[j] = 0;
  15641. for (i=0; i<78 && j>=0; i++) {
  15642. b = 0;
  15643. /* lint allow cast of mismatch sp_digit and int */
  15644. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  15645. b += 8 - s;
  15646. if (j < 0) {
  15647. break;
  15648. }
  15649. while (b < 53) {
  15650. a[j--] = (byte)(r[i] >> b);
  15651. b += 8;
  15652. if (j < 0) {
  15653. break;
  15654. }
  15655. }
  15656. s = 8 - (b - 53);
  15657. if (j >= 0) {
  15658. a[j] = 0;
  15659. }
  15660. if (s != 0) {
  15661. j++;
  15662. }
  15663. }
  15664. }
  15665. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  15666. #if defined(WOLFSSL_HAVE_SP_RSA) && !defined(SP_RSA_PRIVATE_EXP_D)
  15667. /* Normalize the values in each word to 53 bits.
  15668. *
  15669. * a Array of sp_digit to normalize.
  15670. */
  15671. static void sp_4096_norm_39(sp_digit* a)
  15672. {
  15673. int i;
  15674. for (i = 0; i < 32; i += 8) {
  15675. a[i+1] += a[i+0] >> 53; a[i+0] &= 0x1fffffffffffffL;
  15676. a[i+2] += a[i+1] >> 53; a[i+1] &= 0x1fffffffffffffL;
  15677. a[i+3] += a[i+2] >> 53; a[i+2] &= 0x1fffffffffffffL;
  15678. a[i+4] += a[i+3] >> 53; a[i+3] &= 0x1fffffffffffffL;
  15679. a[i+5] += a[i+4] >> 53; a[i+4] &= 0x1fffffffffffffL;
  15680. a[i+6] += a[i+5] >> 53; a[i+5] &= 0x1fffffffffffffL;
  15681. a[i+7] += a[i+6] >> 53; a[i+6] &= 0x1fffffffffffffL;
  15682. a[i+8] += a[i+7] >> 53; a[i+7] &= 0x1fffffffffffffL;
  15683. }
  15684. a[33] += a[32] >> 53; a[32] &= 0x1fffffffffffffL;
  15685. a[34] += a[33] >> 53; a[33] &= 0x1fffffffffffffL;
  15686. a[35] += a[34] >> 53; a[34] &= 0x1fffffffffffffL;
  15687. a[36] += a[35] >> 53; a[35] &= 0x1fffffffffffffL;
  15688. a[37] += a[36] >> 53; a[36] &= 0x1fffffffffffffL;
  15689. a[38] += a[37] >> 53; a[37] &= 0x1fffffffffffffL;
  15690. }
  15691. #endif /* WOLFSSL_HAVE_SP_RSA & !SP_RSA_PRIVATE_EXP_D */
  15692. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  15693. /* Normalize the values in each word to 53 bits.
  15694. *
  15695. * a Array of sp_digit to normalize.
  15696. */
  15697. static void sp_4096_norm_78(sp_digit* a)
  15698. {
  15699. int i;
  15700. for (i = 0; i < 72; i += 8) {
  15701. a[i+1] += a[i+0] >> 53; a[i+0] &= 0x1fffffffffffffL;
  15702. a[i+2] += a[i+1] >> 53; a[i+1] &= 0x1fffffffffffffL;
  15703. a[i+3] += a[i+2] >> 53; a[i+2] &= 0x1fffffffffffffL;
  15704. a[i+4] += a[i+3] >> 53; a[i+3] &= 0x1fffffffffffffL;
  15705. a[i+5] += a[i+4] >> 53; a[i+4] &= 0x1fffffffffffffL;
  15706. a[i+6] += a[i+5] >> 53; a[i+5] &= 0x1fffffffffffffL;
  15707. a[i+7] += a[i+6] >> 53; a[i+6] &= 0x1fffffffffffffL;
  15708. a[i+8] += a[i+7] >> 53; a[i+7] &= 0x1fffffffffffffL;
  15709. }
  15710. a[73] += a[72] >> 53; a[72] &= 0x1fffffffffffffL;
  15711. a[74] += a[73] >> 53; a[73] &= 0x1fffffffffffffL;
  15712. a[75] += a[74] >> 53; a[74] &= 0x1fffffffffffffL;
  15713. a[76] += a[75] >> 53; a[75] &= 0x1fffffffffffffL;
  15714. a[77] += a[76] >> 53; a[76] &= 0x1fffffffffffffL;
  15715. }
  15716. #ifndef WOLFSSL_SP_SMALL
  15717. /* Multiply a and b into r. (r = a * b)
  15718. *
  15719. * r A single precision integer.
  15720. * a A single precision integer.
  15721. * b A single precision integer.
  15722. */
  15723. SP_NOINLINE static void sp_4096_mul_13(sp_digit* r, const sp_digit* a,
  15724. const sp_digit* b)
  15725. {
  15726. sp_uint128 t0;
  15727. sp_uint128 t1;
  15728. sp_digit t[13];
  15729. t0 = ((sp_uint128)a[ 0]) * b[ 0];
  15730. t1 = ((sp_uint128)a[ 0]) * b[ 1]
  15731. + ((sp_uint128)a[ 1]) * b[ 0];
  15732. t[ 0] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15733. t0 = ((sp_uint128)a[ 0]) * b[ 2]
  15734. + ((sp_uint128)a[ 1]) * b[ 1]
  15735. + ((sp_uint128)a[ 2]) * b[ 0];
  15736. t[ 1] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15737. t1 = ((sp_uint128)a[ 0]) * b[ 3]
  15738. + ((sp_uint128)a[ 1]) * b[ 2]
  15739. + ((sp_uint128)a[ 2]) * b[ 1]
  15740. + ((sp_uint128)a[ 3]) * b[ 0];
  15741. t[ 2] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15742. t0 = ((sp_uint128)a[ 0]) * b[ 4]
  15743. + ((sp_uint128)a[ 1]) * b[ 3]
  15744. + ((sp_uint128)a[ 2]) * b[ 2]
  15745. + ((sp_uint128)a[ 3]) * b[ 1]
  15746. + ((sp_uint128)a[ 4]) * b[ 0];
  15747. t[ 3] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15748. t1 = ((sp_uint128)a[ 0]) * b[ 5]
  15749. + ((sp_uint128)a[ 1]) * b[ 4]
  15750. + ((sp_uint128)a[ 2]) * b[ 3]
  15751. + ((sp_uint128)a[ 3]) * b[ 2]
  15752. + ((sp_uint128)a[ 4]) * b[ 1]
  15753. + ((sp_uint128)a[ 5]) * b[ 0];
  15754. t[ 4] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15755. t0 = ((sp_uint128)a[ 0]) * b[ 6]
  15756. + ((sp_uint128)a[ 1]) * b[ 5]
  15757. + ((sp_uint128)a[ 2]) * b[ 4]
  15758. + ((sp_uint128)a[ 3]) * b[ 3]
  15759. + ((sp_uint128)a[ 4]) * b[ 2]
  15760. + ((sp_uint128)a[ 5]) * b[ 1]
  15761. + ((sp_uint128)a[ 6]) * b[ 0];
  15762. t[ 5] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15763. t1 = ((sp_uint128)a[ 0]) * b[ 7]
  15764. + ((sp_uint128)a[ 1]) * b[ 6]
  15765. + ((sp_uint128)a[ 2]) * b[ 5]
  15766. + ((sp_uint128)a[ 3]) * b[ 4]
  15767. + ((sp_uint128)a[ 4]) * b[ 3]
  15768. + ((sp_uint128)a[ 5]) * b[ 2]
  15769. + ((sp_uint128)a[ 6]) * b[ 1]
  15770. + ((sp_uint128)a[ 7]) * b[ 0];
  15771. t[ 6] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15772. t0 = ((sp_uint128)a[ 0]) * b[ 8]
  15773. + ((sp_uint128)a[ 1]) * b[ 7]
  15774. + ((sp_uint128)a[ 2]) * b[ 6]
  15775. + ((sp_uint128)a[ 3]) * b[ 5]
  15776. + ((sp_uint128)a[ 4]) * b[ 4]
  15777. + ((sp_uint128)a[ 5]) * b[ 3]
  15778. + ((sp_uint128)a[ 6]) * b[ 2]
  15779. + ((sp_uint128)a[ 7]) * b[ 1]
  15780. + ((sp_uint128)a[ 8]) * b[ 0];
  15781. t[ 7] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15782. t1 = ((sp_uint128)a[ 0]) * b[ 9]
  15783. + ((sp_uint128)a[ 1]) * b[ 8]
  15784. + ((sp_uint128)a[ 2]) * b[ 7]
  15785. + ((sp_uint128)a[ 3]) * b[ 6]
  15786. + ((sp_uint128)a[ 4]) * b[ 5]
  15787. + ((sp_uint128)a[ 5]) * b[ 4]
  15788. + ((sp_uint128)a[ 6]) * b[ 3]
  15789. + ((sp_uint128)a[ 7]) * b[ 2]
  15790. + ((sp_uint128)a[ 8]) * b[ 1]
  15791. + ((sp_uint128)a[ 9]) * b[ 0];
  15792. t[ 8] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15793. t0 = ((sp_uint128)a[ 0]) * b[10]
  15794. + ((sp_uint128)a[ 1]) * b[ 9]
  15795. + ((sp_uint128)a[ 2]) * b[ 8]
  15796. + ((sp_uint128)a[ 3]) * b[ 7]
  15797. + ((sp_uint128)a[ 4]) * b[ 6]
  15798. + ((sp_uint128)a[ 5]) * b[ 5]
  15799. + ((sp_uint128)a[ 6]) * b[ 4]
  15800. + ((sp_uint128)a[ 7]) * b[ 3]
  15801. + ((sp_uint128)a[ 8]) * b[ 2]
  15802. + ((sp_uint128)a[ 9]) * b[ 1]
  15803. + ((sp_uint128)a[10]) * b[ 0];
  15804. t[ 9] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15805. t1 = ((sp_uint128)a[ 0]) * b[11]
  15806. + ((sp_uint128)a[ 1]) * b[10]
  15807. + ((sp_uint128)a[ 2]) * b[ 9]
  15808. + ((sp_uint128)a[ 3]) * b[ 8]
  15809. + ((sp_uint128)a[ 4]) * b[ 7]
  15810. + ((sp_uint128)a[ 5]) * b[ 6]
  15811. + ((sp_uint128)a[ 6]) * b[ 5]
  15812. + ((sp_uint128)a[ 7]) * b[ 4]
  15813. + ((sp_uint128)a[ 8]) * b[ 3]
  15814. + ((sp_uint128)a[ 9]) * b[ 2]
  15815. + ((sp_uint128)a[10]) * b[ 1]
  15816. + ((sp_uint128)a[11]) * b[ 0];
  15817. t[10] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15818. t0 = ((sp_uint128)a[ 0]) * b[12]
  15819. + ((sp_uint128)a[ 1]) * b[11]
  15820. + ((sp_uint128)a[ 2]) * b[10]
  15821. + ((sp_uint128)a[ 3]) * b[ 9]
  15822. + ((sp_uint128)a[ 4]) * b[ 8]
  15823. + ((sp_uint128)a[ 5]) * b[ 7]
  15824. + ((sp_uint128)a[ 6]) * b[ 6]
  15825. + ((sp_uint128)a[ 7]) * b[ 5]
  15826. + ((sp_uint128)a[ 8]) * b[ 4]
  15827. + ((sp_uint128)a[ 9]) * b[ 3]
  15828. + ((sp_uint128)a[10]) * b[ 2]
  15829. + ((sp_uint128)a[11]) * b[ 1]
  15830. + ((sp_uint128)a[12]) * b[ 0];
  15831. t[11] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15832. t1 = ((sp_uint128)a[ 1]) * b[12]
  15833. + ((sp_uint128)a[ 2]) * b[11]
  15834. + ((sp_uint128)a[ 3]) * b[10]
  15835. + ((sp_uint128)a[ 4]) * b[ 9]
  15836. + ((sp_uint128)a[ 5]) * b[ 8]
  15837. + ((sp_uint128)a[ 6]) * b[ 7]
  15838. + ((sp_uint128)a[ 7]) * b[ 6]
  15839. + ((sp_uint128)a[ 8]) * b[ 5]
  15840. + ((sp_uint128)a[ 9]) * b[ 4]
  15841. + ((sp_uint128)a[10]) * b[ 3]
  15842. + ((sp_uint128)a[11]) * b[ 2]
  15843. + ((sp_uint128)a[12]) * b[ 1];
  15844. t[12] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15845. t0 = ((sp_uint128)a[ 2]) * b[12]
  15846. + ((sp_uint128)a[ 3]) * b[11]
  15847. + ((sp_uint128)a[ 4]) * b[10]
  15848. + ((sp_uint128)a[ 5]) * b[ 9]
  15849. + ((sp_uint128)a[ 6]) * b[ 8]
  15850. + ((sp_uint128)a[ 7]) * b[ 7]
  15851. + ((sp_uint128)a[ 8]) * b[ 6]
  15852. + ((sp_uint128)a[ 9]) * b[ 5]
  15853. + ((sp_uint128)a[10]) * b[ 4]
  15854. + ((sp_uint128)a[11]) * b[ 3]
  15855. + ((sp_uint128)a[12]) * b[ 2];
  15856. r[13] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15857. t1 = ((sp_uint128)a[ 3]) * b[12]
  15858. + ((sp_uint128)a[ 4]) * b[11]
  15859. + ((sp_uint128)a[ 5]) * b[10]
  15860. + ((sp_uint128)a[ 6]) * b[ 9]
  15861. + ((sp_uint128)a[ 7]) * b[ 8]
  15862. + ((sp_uint128)a[ 8]) * b[ 7]
  15863. + ((sp_uint128)a[ 9]) * b[ 6]
  15864. + ((sp_uint128)a[10]) * b[ 5]
  15865. + ((sp_uint128)a[11]) * b[ 4]
  15866. + ((sp_uint128)a[12]) * b[ 3];
  15867. r[14] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15868. t0 = ((sp_uint128)a[ 4]) * b[12]
  15869. + ((sp_uint128)a[ 5]) * b[11]
  15870. + ((sp_uint128)a[ 6]) * b[10]
  15871. + ((sp_uint128)a[ 7]) * b[ 9]
  15872. + ((sp_uint128)a[ 8]) * b[ 8]
  15873. + ((sp_uint128)a[ 9]) * b[ 7]
  15874. + ((sp_uint128)a[10]) * b[ 6]
  15875. + ((sp_uint128)a[11]) * b[ 5]
  15876. + ((sp_uint128)a[12]) * b[ 4];
  15877. r[15] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15878. t1 = ((sp_uint128)a[ 5]) * b[12]
  15879. + ((sp_uint128)a[ 6]) * b[11]
  15880. + ((sp_uint128)a[ 7]) * b[10]
  15881. + ((sp_uint128)a[ 8]) * b[ 9]
  15882. + ((sp_uint128)a[ 9]) * b[ 8]
  15883. + ((sp_uint128)a[10]) * b[ 7]
  15884. + ((sp_uint128)a[11]) * b[ 6]
  15885. + ((sp_uint128)a[12]) * b[ 5];
  15886. r[16] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15887. t0 = ((sp_uint128)a[ 6]) * b[12]
  15888. + ((sp_uint128)a[ 7]) * b[11]
  15889. + ((sp_uint128)a[ 8]) * b[10]
  15890. + ((sp_uint128)a[ 9]) * b[ 9]
  15891. + ((sp_uint128)a[10]) * b[ 8]
  15892. + ((sp_uint128)a[11]) * b[ 7]
  15893. + ((sp_uint128)a[12]) * b[ 6];
  15894. r[17] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15895. t1 = ((sp_uint128)a[ 7]) * b[12]
  15896. + ((sp_uint128)a[ 8]) * b[11]
  15897. + ((sp_uint128)a[ 9]) * b[10]
  15898. + ((sp_uint128)a[10]) * b[ 9]
  15899. + ((sp_uint128)a[11]) * b[ 8]
  15900. + ((sp_uint128)a[12]) * b[ 7];
  15901. r[18] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15902. t0 = ((sp_uint128)a[ 8]) * b[12]
  15903. + ((sp_uint128)a[ 9]) * b[11]
  15904. + ((sp_uint128)a[10]) * b[10]
  15905. + ((sp_uint128)a[11]) * b[ 9]
  15906. + ((sp_uint128)a[12]) * b[ 8];
  15907. r[19] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15908. t1 = ((sp_uint128)a[ 9]) * b[12]
  15909. + ((sp_uint128)a[10]) * b[11]
  15910. + ((sp_uint128)a[11]) * b[10]
  15911. + ((sp_uint128)a[12]) * b[ 9];
  15912. r[20] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15913. t0 = ((sp_uint128)a[10]) * b[12]
  15914. + ((sp_uint128)a[11]) * b[11]
  15915. + ((sp_uint128)a[12]) * b[10];
  15916. r[21] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15917. t1 = ((sp_uint128)a[11]) * b[12]
  15918. + ((sp_uint128)a[12]) * b[11];
  15919. r[22] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  15920. t0 = ((sp_uint128)a[12]) * b[12];
  15921. r[23] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  15922. r[24] = t0 & 0x1fffffffffffffL;
  15923. r[25] = (sp_digit)(t0 >> 53);
  15924. XMEMCPY(r, t, sizeof(t));
  15925. }
  15926. /* Add b to a into r. (r = a + b)
  15927. *
  15928. * r A single precision integer.
  15929. * a A single precision integer.
  15930. * b A single precision integer.
  15931. */
  15932. SP_NOINLINE static int sp_4096_add_13(sp_digit* r, const sp_digit* a,
  15933. const sp_digit* b)
  15934. {
  15935. r[ 0] = a[ 0] + b[ 0];
  15936. r[ 1] = a[ 1] + b[ 1];
  15937. r[ 2] = a[ 2] + b[ 2];
  15938. r[ 3] = a[ 3] + b[ 3];
  15939. r[ 4] = a[ 4] + b[ 4];
  15940. r[ 5] = a[ 5] + b[ 5];
  15941. r[ 6] = a[ 6] + b[ 6];
  15942. r[ 7] = a[ 7] + b[ 7];
  15943. r[ 8] = a[ 8] + b[ 8];
  15944. r[ 9] = a[ 9] + b[ 9];
  15945. r[10] = a[10] + b[10];
  15946. r[11] = a[11] + b[11];
  15947. r[12] = a[12] + b[12];
  15948. return 0;
  15949. }
  15950. /* Sub b from a into r. (r = a - b)
  15951. *
  15952. * r A single precision integer.
  15953. * a A single precision integer.
  15954. * b A single precision integer.
  15955. */
  15956. SP_NOINLINE static int sp_4096_sub_26(sp_digit* r, const sp_digit* a,
  15957. const sp_digit* b)
  15958. {
  15959. int i;
  15960. for (i = 0; i < 24; i += 8) {
  15961. r[i + 0] = a[i + 0] - b[i + 0];
  15962. r[i + 1] = a[i + 1] - b[i + 1];
  15963. r[i + 2] = a[i + 2] - b[i + 2];
  15964. r[i + 3] = a[i + 3] - b[i + 3];
  15965. r[i + 4] = a[i + 4] - b[i + 4];
  15966. r[i + 5] = a[i + 5] - b[i + 5];
  15967. r[i + 6] = a[i + 6] - b[i + 6];
  15968. r[i + 7] = a[i + 7] - b[i + 7];
  15969. }
  15970. r[24] = a[24] - b[24];
  15971. r[25] = a[25] - b[25];
  15972. return 0;
  15973. }
  15974. /* Add b to a into r. (r = a + b)
  15975. *
  15976. * r A single precision integer.
  15977. * a A single precision integer.
  15978. * b A single precision integer.
  15979. */
  15980. SP_NOINLINE static int sp_4096_add_26(sp_digit* r, const sp_digit* a,
  15981. const sp_digit* b)
  15982. {
  15983. int i;
  15984. for (i = 0; i < 24; i += 8) {
  15985. r[i + 0] = a[i + 0] + b[i + 0];
  15986. r[i + 1] = a[i + 1] + b[i + 1];
  15987. r[i + 2] = a[i + 2] + b[i + 2];
  15988. r[i + 3] = a[i + 3] + b[i + 3];
  15989. r[i + 4] = a[i + 4] + b[i + 4];
  15990. r[i + 5] = a[i + 5] + b[i + 5];
  15991. r[i + 6] = a[i + 6] + b[i + 6];
  15992. r[i + 7] = a[i + 7] + b[i + 7];
  15993. }
  15994. r[24] = a[24] + b[24];
  15995. r[25] = a[25] + b[25];
  15996. return 0;
  15997. }
  15998. /* Multiply a and b into r. (r = a * b)
  15999. *
  16000. * r A single precision integer.
  16001. * a A single precision integer.
  16002. * b A single precision integer.
  16003. */
  16004. SP_NOINLINE static void sp_4096_mul_39(sp_digit* r, const sp_digit* a,
  16005. const sp_digit* b)
  16006. {
  16007. sp_digit p0[26];
  16008. sp_digit p1[26];
  16009. sp_digit p2[26];
  16010. sp_digit p3[26];
  16011. sp_digit p4[26];
  16012. sp_digit p5[26];
  16013. sp_digit t0[26];
  16014. sp_digit t1[26];
  16015. sp_digit t2[26];
  16016. sp_digit a0[13];
  16017. sp_digit a1[13];
  16018. sp_digit a2[13];
  16019. sp_digit b0[13];
  16020. sp_digit b1[13];
  16021. sp_digit b2[13];
  16022. (void)sp_4096_add_13(a0, a, &a[13]);
  16023. (void)sp_4096_add_13(b0, b, &b[13]);
  16024. (void)sp_4096_add_13(a1, &a[13], &a[26]);
  16025. (void)sp_4096_add_13(b1, &b[13], &b[26]);
  16026. (void)sp_4096_add_13(a2, a0, &a[26]);
  16027. (void)sp_4096_add_13(b2, b0, &b[26]);
  16028. sp_4096_mul_13(p0, a, b);
  16029. sp_4096_mul_13(p2, &a[13], &b[13]);
  16030. sp_4096_mul_13(p4, &a[26], &b[26]);
  16031. sp_4096_mul_13(p1, a0, b0);
  16032. sp_4096_mul_13(p3, a1, b1);
  16033. sp_4096_mul_13(p5, a2, b2);
  16034. XMEMSET(r, 0, sizeof(*r)*2U*39U);
  16035. (void)sp_4096_sub_26(t0, p3, p2);
  16036. (void)sp_4096_sub_26(t1, p1, p2);
  16037. (void)sp_4096_sub_26(t2, p5, t0);
  16038. (void)sp_4096_sub_26(t2, t2, t1);
  16039. (void)sp_4096_sub_26(t0, t0, p4);
  16040. (void)sp_4096_sub_26(t1, t1, p0);
  16041. (void)sp_4096_add_26(r, r, p0);
  16042. (void)sp_4096_add_26(&r[13], &r[13], t1);
  16043. (void)sp_4096_add_26(&r[26], &r[26], t2);
  16044. (void)sp_4096_add_26(&r[39], &r[39], t0);
  16045. (void)sp_4096_add_26(&r[52], &r[52], p4);
  16046. }
  16047. /* Add b to a into r. (r = a + b)
  16048. *
  16049. * r A single precision integer.
  16050. * a A single precision integer.
  16051. * b A single precision integer.
  16052. */
  16053. SP_NOINLINE static int sp_4096_add_39(sp_digit* r, const sp_digit* a,
  16054. const sp_digit* b)
  16055. {
  16056. int i;
  16057. for (i = 0; i < 32; i += 8) {
  16058. r[i + 0] = a[i + 0] + b[i + 0];
  16059. r[i + 1] = a[i + 1] + b[i + 1];
  16060. r[i + 2] = a[i + 2] + b[i + 2];
  16061. r[i + 3] = a[i + 3] + b[i + 3];
  16062. r[i + 4] = a[i + 4] + b[i + 4];
  16063. r[i + 5] = a[i + 5] + b[i + 5];
  16064. r[i + 6] = a[i + 6] + b[i + 6];
  16065. r[i + 7] = a[i + 7] + b[i + 7];
  16066. }
  16067. r[32] = a[32] + b[32];
  16068. r[33] = a[33] + b[33];
  16069. r[34] = a[34] + b[34];
  16070. r[35] = a[35] + b[35];
  16071. r[36] = a[36] + b[36];
  16072. r[37] = a[37] + b[37];
  16073. r[38] = a[38] + b[38];
  16074. return 0;
  16075. }
  16076. /* Add b to a into r. (r = a + b)
  16077. *
  16078. * r A single precision integer.
  16079. * a A single precision integer.
  16080. * b A single precision integer.
  16081. */
  16082. SP_NOINLINE static int sp_4096_add_78(sp_digit* r, const sp_digit* a,
  16083. const sp_digit* b)
  16084. {
  16085. int i;
  16086. for (i = 0; i < 72; i += 8) {
  16087. r[i + 0] = a[i + 0] + b[i + 0];
  16088. r[i + 1] = a[i + 1] + b[i + 1];
  16089. r[i + 2] = a[i + 2] + b[i + 2];
  16090. r[i + 3] = a[i + 3] + b[i + 3];
  16091. r[i + 4] = a[i + 4] + b[i + 4];
  16092. r[i + 5] = a[i + 5] + b[i + 5];
  16093. r[i + 6] = a[i + 6] + b[i + 6];
  16094. r[i + 7] = a[i + 7] + b[i + 7];
  16095. }
  16096. r[72] = a[72] + b[72];
  16097. r[73] = a[73] + b[73];
  16098. r[74] = a[74] + b[74];
  16099. r[75] = a[75] + b[75];
  16100. r[76] = a[76] + b[76];
  16101. r[77] = a[77] + b[77];
  16102. return 0;
  16103. }
  16104. /* Sub b from a into r. (r = a - b)
  16105. *
  16106. * r A single precision integer.
  16107. * a A single precision integer.
  16108. * b A single precision integer.
  16109. */
  16110. SP_NOINLINE static int sp_4096_sub_78(sp_digit* r, const sp_digit* a,
  16111. const sp_digit* b)
  16112. {
  16113. int i;
  16114. for (i = 0; i < 72; i += 8) {
  16115. r[i + 0] = a[i + 0] - b[i + 0];
  16116. r[i + 1] = a[i + 1] - b[i + 1];
  16117. r[i + 2] = a[i + 2] - b[i + 2];
  16118. r[i + 3] = a[i + 3] - b[i + 3];
  16119. r[i + 4] = a[i + 4] - b[i + 4];
  16120. r[i + 5] = a[i + 5] - b[i + 5];
  16121. r[i + 6] = a[i + 6] - b[i + 6];
  16122. r[i + 7] = a[i + 7] - b[i + 7];
  16123. }
  16124. r[72] = a[72] - b[72];
  16125. r[73] = a[73] - b[73];
  16126. r[74] = a[74] - b[74];
  16127. r[75] = a[75] - b[75];
  16128. r[76] = a[76] - b[76];
  16129. r[77] = a[77] - b[77];
  16130. return 0;
  16131. }
  16132. /* Multiply a and b into r. (r = a * b)
  16133. *
  16134. * r A single precision integer.
  16135. * a A single precision integer.
  16136. * b A single precision integer.
  16137. */
  16138. SP_NOINLINE static void sp_4096_mul_78(sp_digit* r, const sp_digit* a,
  16139. const sp_digit* b)
  16140. {
  16141. sp_digit* z0 = r;
  16142. sp_digit z1[78];
  16143. sp_digit* a1 = z1;
  16144. sp_digit b1[39];
  16145. sp_digit* z2 = r + 78;
  16146. (void)sp_4096_add_39(a1, a, &a[39]);
  16147. (void)sp_4096_add_39(b1, b, &b[39]);
  16148. sp_4096_mul_39(z2, &a[39], &b[39]);
  16149. sp_4096_mul_39(z0, a, b);
  16150. sp_4096_mul_39(z1, a1, b1);
  16151. (void)sp_4096_sub_78(z1, z1, z2);
  16152. (void)sp_4096_sub_78(z1, z1, z0);
  16153. (void)sp_4096_add_78(r + 39, r + 39, z1);
  16154. }
  16155. /* Square a and put result in r. (r = a * a)
  16156. *
  16157. * r A single precision integer.
  16158. * a A single precision integer.
  16159. */
  16160. SP_NOINLINE static void sp_4096_sqr_13(sp_digit* r, const sp_digit* a)
  16161. {
  16162. sp_uint128 t0;
  16163. sp_uint128 t1;
  16164. sp_digit t[13];
  16165. t0 = ((sp_uint128)a[ 0]) * a[ 0];
  16166. t1 = (((sp_uint128)a[ 0]) * a[ 1]) * 2;
  16167. t[ 0] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16168. t0 = (((sp_uint128)a[ 0]) * a[ 2]) * 2
  16169. + ((sp_uint128)a[ 1]) * a[ 1];
  16170. t[ 1] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16171. t1 = (((sp_uint128)a[ 0]) * a[ 3]
  16172. + ((sp_uint128)a[ 1]) * a[ 2]) * 2;
  16173. t[ 2] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16174. t0 = (((sp_uint128)a[ 0]) * a[ 4]
  16175. + ((sp_uint128)a[ 1]) * a[ 3]) * 2
  16176. + ((sp_uint128)a[ 2]) * a[ 2];
  16177. t[ 3] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16178. t1 = (((sp_uint128)a[ 0]) * a[ 5]
  16179. + ((sp_uint128)a[ 1]) * a[ 4]
  16180. + ((sp_uint128)a[ 2]) * a[ 3]) * 2;
  16181. t[ 4] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16182. t0 = (((sp_uint128)a[ 0]) * a[ 6]
  16183. + ((sp_uint128)a[ 1]) * a[ 5]
  16184. + ((sp_uint128)a[ 2]) * a[ 4]) * 2
  16185. + ((sp_uint128)a[ 3]) * a[ 3];
  16186. t[ 5] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16187. t1 = (((sp_uint128)a[ 0]) * a[ 7]
  16188. + ((sp_uint128)a[ 1]) * a[ 6]
  16189. + ((sp_uint128)a[ 2]) * a[ 5]
  16190. + ((sp_uint128)a[ 3]) * a[ 4]) * 2;
  16191. t[ 6] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16192. t0 = (((sp_uint128)a[ 0]) * a[ 8]
  16193. + ((sp_uint128)a[ 1]) * a[ 7]
  16194. + ((sp_uint128)a[ 2]) * a[ 6]
  16195. + ((sp_uint128)a[ 3]) * a[ 5]) * 2
  16196. + ((sp_uint128)a[ 4]) * a[ 4];
  16197. t[ 7] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16198. t1 = (((sp_uint128)a[ 0]) * a[ 9]
  16199. + ((sp_uint128)a[ 1]) * a[ 8]
  16200. + ((sp_uint128)a[ 2]) * a[ 7]
  16201. + ((sp_uint128)a[ 3]) * a[ 6]
  16202. + ((sp_uint128)a[ 4]) * a[ 5]) * 2;
  16203. t[ 8] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16204. t0 = (((sp_uint128)a[ 0]) * a[10]
  16205. + ((sp_uint128)a[ 1]) * a[ 9]
  16206. + ((sp_uint128)a[ 2]) * a[ 8]
  16207. + ((sp_uint128)a[ 3]) * a[ 7]
  16208. + ((sp_uint128)a[ 4]) * a[ 6]) * 2
  16209. + ((sp_uint128)a[ 5]) * a[ 5];
  16210. t[ 9] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16211. t1 = (((sp_uint128)a[ 0]) * a[11]
  16212. + ((sp_uint128)a[ 1]) * a[10]
  16213. + ((sp_uint128)a[ 2]) * a[ 9]
  16214. + ((sp_uint128)a[ 3]) * a[ 8]
  16215. + ((sp_uint128)a[ 4]) * a[ 7]
  16216. + ((sp_uint128)a[ 5]) * a[ 6]) * 2;
  16217. t[10] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16218. t0 = (((sp_uint128)a[ 0]) * a[12]
  16219. + ((sp_uint128)a[ 1]) * a[11]
  16220. + ((sp_uint128)a[ 2]) * a[10]
  16221. + ((sp_uint128)a[ 3]) * a[ 9]
  16222. + ((sp_uint128)a[ 4]) * a[ 8]
  16223. + ((sp_uint128)a[ 5]) * a[ 7]) * 2
  16224. + ((sp_uint128)a[ 6]) * a[ 6];
  16225. t[11] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16226. t1 = (((sp_uint128)a[ 1]) * a[12]
  16227. + ((sp_uint128)a[ 2]) * a[11]
  16228. + ((sp_uint128)a[ 3]) * a[10]
  16229. + ((sp_uint128)a[ 4]) * a[ 9]
  16230. + ((sp_uint128)a[ 5]) * a[ 8]
  16231. + ((sp_uint128)a[ 6]) * a[ 7]) * 2;
  16232. t[12] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16233. t0 = (((sp_uint128)a[ 2]) * a[12]
  16234. + ((sp_uint128)a[ 3]) * a[11]
  16235. + ((sp_uint128)a[ 4]) * a[10]
  16236. + ((sp_uint128)a[ 5]) * a[ 9]
  16237. + ((sp_uint128)a[ 6]) * a[ 8]) * 2
  16238. + ((sp_uint128)a[ 7]) * a[ 7];
  16239. r[13] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16240. t1 = (((sp_uint128)a[ 3]) * a[12]
  16241. + ((sp_uint128)a[ 4]) * a[11]
  16242. + ((sp_uint128)a[ 5]) * a[10]
  16243. + ((sp_uint128)a[ 6]) * a[ 9]
  16244. + ((sp_uint128)a[ 7]) * a[ 8]) * 2;
  16245. r[14] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16246. t0 = (((sp_uint128)a[ 4]) * a[12]
  16247. + ((sp_uint128)a[ 5]) * a[11]
  16248. + ((sp_uint128)a[ 6]) * a[10]
  16249. + ((sp_uint128)a[ 7]) * a[ 9]) * 2
  16250. + ((sp_uint128)a[ 8]) * a[ 8];
  16251. r[15] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16252. t1 = (((sp_uint128)a[ 5]) * a[12]
  16253. + ((sp_uint128)a[ 6]) * a[11]
  16254. + ((sp_uint128)a[ 7]) * a[10]
  16255. + ((sp_uint128)a[ 8]) * a[ 9]) * 2;
  16256. r[16] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16257. t0 = (((sp_uint128)a[ 6]) * a[12]
  16258. + ((sp_uint128)a[ 7]) * a[11]
  16259. + ((sp_uint128)a[ 8]) * a[10]) * 2
  16260. + ((sp_uint128)a[ 9]) * a[ 9];
  16261. r[17] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16262. t1 = (((sp_uint128)a[ 7]) * a[12]
  16263. + ((sp_uint128)a[ 8]) * a[11]
  16264. + ((sp_uint128)a[ 9]) * a[10]) * 2;
  16265. r[18] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16266. t0 = (((sp_uint128)a[ 8]) * a[12]
  16267. + ((sp_uint128)a[ 9]) * a[11]) * 2
  16268. + ((sp_uint128)a[10]) * a[10];
  16269. r[19] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16270. t1 = (((sp_uint128)a[ 9]) * a[12]
  16271. + ((sp_uint128)a[10]) * a[11]) * 2;
  16272. r[20] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16273. t0 = (((sp_uint128)a[10]) * a[12]) * 2
  16274. + ((sp_uint128)a[11]) * a[11];
  16275. r[21] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16276. t1 = (((sp_uint128)a[11]) * a[12]) * 2;
  16277. r[22] = t0 & 0x1fffffffffffffL; t1 += t0 >> 53;
  16278. t0 = ((sp_uint128)a[12]) * a[12];
  16279. r[23] = t1 & 0x1fffffffffffffL; t0 += t1 >> 53;
  16280. r[24] = t0 & 0x1fffffffffffffL;
  16281. r[25] = (sp_digit)(t0 >> 53);
  16282. XMEMCPY(r, t, sizeof(t));
  16283. }
  16284. /* Square a into r. (r = a * a)
  16285. *
  16286. * r A single precision integer.
  16287. * a A single precision integer.
  16288. */
  16289. SP_NOINLINE static void sp_4096_sqr_39(sp_digit* r, const sp_digit* a)
  16290. {
  16291. sp_digit p0[26];
  16292. sp_digit p1[26];
  16293. sp_digit p2[26];
  16294. sp_digit p3[26];
  16295. sp_digit p4[26];
  16296. sp_digit p5[26];
  16297. sp_digit t0[26];
  16298. sp_digit t1[26];
  16299. sp_digit t2[26];
  16300. sp_digit a0[13];
  16301. sp_digit a1[13];
  16302. sp_digit a2[13];
  16303. (void)sp_4096_add_13(a0, a, &a[13]);
  16304. (void)sp_4096_add_13(a1, &a[13], &a[26]);
  16305. (void)sp_4096_add_13(a2, a0, &a[26]);
  16306. sp_4096_sqr_13(p0, a);
  16307. sp_4096_sqr_13(p2, &a[13]);
  16308. sp_4096_sqr_13(p4, &a[26]);
  16309. sp_4096_sqr_13(p1, a0);
  16310. sp_4096_sqr_13(p3, a1);
  16311. sp_4096_sqr_13(p5, a2);
  16312. XMEMSET(r, 0, sizeof(*r)*2U*39U);
  16313. (void)sp_4096_sub_26(t0, p3, p2);
  16314. (void)sp_4096_sub_26(t1, p1, p2);
  16315. (void)sp_4096_sub_26(t2, p5, t0);
  16316. (void)sp_4096_sub_26(t2, t2, t1);
  16317. (void)sp_4096_sub_26(t0, t0, p4);
  16318. (void)sp_4096_sub_26(t1, t1, p0);
  16319. (void)sp_4096_add_26(r, r, p0);
  16320. (void)sp_4096_add_26(&r[13], &r[13], t1);
  16321. (void)sp_4096_add_26(&r[26], &r[26], t2);
  16322. (void)sp_4096_add_26(&r[39], &r[39], t0);
  16323. (void)sp_4096_add_26(&r[52], &r[52], p4);
  16324. }
  16325. /* Square a and put result in r. (r = a * a)
  16326. *
  16327. * r A single precision integer.
  16328. * a A single precision integer.
  16329. */
  16330. SP_NOINLINE static void sp_4096_sqr_78(sp_digit* r, const sp_digit* a)
  16331. {
  16332. sp_digit* z0 = r;
  16333. sp_digit z1[78];
  16334. sp_digit* a1 = z1;
  16335. sp_digit* z2 = r + 78;
  16336. (void)sp_4096_add_39(a1, a, &a[39]);
  16337. sp_4096_sqr_39(z2, &a[39]);
  16338. sp_4096_sqr_39(z0, a);
  16339. sp_4096_sqr_39(z1, a1);
  16340. (void)sp_4096_sub_78(z1, z1, z2);
  16341. (void)sp_4096_sub_78(z1, z1, z0);
  16342. (void)sp_4096_add_78(r + 39, r + 39, z1);
  16343. }
  16344. #endif /* !WOLFSSL_SP_SMALL */
  16345. /* Calculate the bottom digit of -1/a mod 2^n.
  16346. *
  16347. * a A single precision number.
  16348. * rho Bottom word of inverse.
  16349. */
  16350. static void sp_4096_mont_setup(const sp_digit* a, sp_digit* rho)
  16351. {
  16352. sp_digit x;
  16353. sp_digit b;
  16354. b = a[0];
  16355. x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
  16356. x *= 2 - b * x; /* here x*a==1 mod 2**8 */
  16357. x *= 2 - b * x; /* here x*a==1 mod 2**16 */
  16358. x *= 2 - b * x; /* here x*a==1 mod 2**32 */
  16359. x *= 2 - b * x; /* here x*a==1 mod 2**64 */
  16360. x &= 0x1fffffffffffffL;
  16361. /* rho = -1/m mod b */
  16362. *rho = ((sp_digit)1 << 53) - x;
  16363. }
  16364. /* Multiply a by scalar b into r. (r = a * b)
  16365. *
  16366. * r A single precision integer.
  16367. * a A single precision integer.
  16368. * b A scalar.
  16369. */
  16370. SP_NOINLINE static void sp_4096_mul_d_78(sp_digit* r, const sp_digit* a,
  16371. sp_digit b)
  16372. {
  16373. sp_int128 tb = b;
  16374. sp_int128 t = 0;
  16375. sp_digit t2;
  16376. sp_int128 p[4];
  16377. int i;
  16378. for (i = 0; i < 76; i += 4) {
  16379. p[0] = tb * a[i + 0];
  16380. p[1] = tb * a[i + 1];
  16381. p[2] = tb * a[i + 2];
  16382. p[3] = tb * a[i + 3];
  16383. t += p[0];
  16384. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16385. t >>= 53;
  16386. r[i + 0] = (sp_digit)t2;
  16387. t += p[1];
  16388. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16389. t >>= 53;
  16390. r[i + 1] = (sp_digit)t2;
  16391. t += p[2];
  16392. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16393. t >>= 53;
  16394. r[i + 2] = (sp_digit)t2;
  16395. t += p[3];
  16396. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16397. t >>= 53;
  16398. r[i + 3] = (sp_digit)t2;
  16399. }
  16400. t += tb * a[76];
  16401. r[76] = (sp_digit)(t & 0x1fffffffffffffL);
  16402. t >>= 53;
  16403. t += tb * a[77];
  16404. r[77] = (sp_digit)(t & 0x1fffffffffffffL);
  16405. t >>= 53;
  16406. r[78] = (sp_digit)(t & 0x1fffffffffffffL);
  16407. }
  16408. #if (defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH)) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  16409. #if defined(WOLFSSL_HAVE_SP_RSA) && !defined(SP_RSA_PRIVATE_EXP_D)
  16410. /* Sub b from a into r. (r = a - b)
  16411. *
  16412. * r A single precision integer.
  16413. * a A single precision integer.
  16414. * b A single precision integer.
  16415. */
  16416. SP_NOINLINE static int sp_4096_sub_39(sp_digit* r, const sp_digit* a,
  16417. const sp_digit* b)
  16418. {
  16419. int i;
  16420. for (i = 0; i < 32; i += 8) {
  16421. r[i + 0] = a[i + 0] - b[i + 0];
  16422. r[i + 1] = a[i + 1] - b[i + 1];
  16423. r[i + 2] = a[i + 2] - b[i + 2];
  16424. r[i + 3] = a[i + 3] - b[i + 3];
  16425. r[i + 4] = a[i + 4] - b[i + 4];
  16426. r[i + 5] = a[i + 5] - b[i + 5];
  16427. r[i + 6] = a[i + 6] - b[i + 6];
  16428. r[i + 7] = a[i + 7] - b[i + 7];
  16429. }
  16430. r[32] = a[32] - b[32];
  16431. r[33] = a[33] - b[33];
  16432. r[34] = a[34] - b[34];
  16433. r[35] = a[35] - b[35];
  16434. r[36] = a[36] - b[36];
  16435. r[37] = a[37] - b[37];
  16436. r[38] = a[38] - b[38];
  16437. return 0;
  16438. }
  16439. /* r = 2^n mod m where n is the number of bits to reduce by.
  16440. * Given m must be 4096 bits, just need to subtract.
  16441. *
  16442. * r A single precision number.
  16443. * m A single precision number.
  16444. */
  16445. static void sp_4096_mont_norm_39(sp_digit* r, const sp_digit* m)
  16446. {
  16447. /* Set r = 2^n - 1. */
  16448. int i;
  16449. for (i = 0; i < 32; i += 8) {
  16450. r[i + 0] = 0x1fffffffffffffL;
  16451. r[i + 1] = 0x1fffffffffffffL;
  16452. r[i + 2] = 0x1fffffffffffffL;
  16453. r[i + 3] = 0x1fffffffffffffL;
  16454. r[i + 4] = 0x1fffffffffffffL;
  16455. r[i + 5] = 0x1fffffffffffffL;
  16456. r[i + 6] = 0x1fffffffffffffL;
  16457. r[i + 7] = 0x1fffffffffffffL;
  16458. }
  16459. r[32] = 0x1fffffffffffffL;
  16460. r[33] = 0x1fffffffffffffL;
  16461. r[34] = 0x1fffffffffffffL;
  16462. r[35] = 0x1fffffffffffffL;
  16463. r[36] = 0x1fffffffffffffL;
  16464. r[37] = 0x1fffffffffffffL;
  16465. r[38] = 0x3ffffffffL;
  16466. /* r = (2^n - 1) mod n */
  16467. (void)sp_4096_sub_39(r, r, m);
  16468. /* Add one so r = 2^n mod m */
  16469. r[0] += 1;
  16470. }
  16471. /* Compare a with b in constant time.
  16472. *
  16473. * a A single precision integer.
  16474. * b A single precision integer.
  16475. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  16476. * respectively.
  16477. */
  16478. static sp_digit sp_4096_cmp_39(const sp_digit* a, const sp_digit* b)
  16479. {
  16480. sp_digit r = 0;
  16481. int i;
  16482. r |= (a[38] - b[38]) & (0 - (sp_digit)1);
  16483. r |= (a[37] - b[37]) & ~(((sp_digit)0 - r) >> 52);
  16484. r |= (a[36] - b[36]) & ~(((sp_digit)0 - r) >> 52);
  16485. r |= (a[35] - b[35]) & ~(((sp_digit)0 - r) >> 52);
  16486. r |= (a[34] - b[34]) & ~(((sp_digit)0 - r) >> 52);
  16487. r |= (a[33] - b[33]) & ~(((sp_digit)0 - r) >> 52);
  16488. r |= (a[32] - b[32]) & ~(((sp_digit)0 - r) >> 52);
  16489. for (i = 24; i >= 0; i -= 8) {
  16490. r |= (a[i + 7] - b[i + 7]) & ~(((sp_digit)0 - r) >> 52);
  16491. r |= (a[i + 6] - b[i + 6]) & ~(((sp_digit)0 - r) >> 52);
  16492. r |= (a[i + 5] - b[i + 5]) & ~(((sp_digit)0 - r) >> 52);
  16493. r |= (a[i + 4] - b[i + 4]) & ~(((sp_digit)0 - r) >> 52);
  16494. r |= (a[i + 3] - b[i + 3]) & ~(((sp_digit)0 - r) >> 52);
  16495. r |= (a[i + 2] - b[i + 2]) & ~(((sp_digit)0 - r) >> 52);
  16496. r |= (a[i + 1] - b[i + 1]) & ~(((sp_digit)0 - r) >> 52);
  16497. r |= (a[i + 0] - b[i + 0]) & ~(((sp_digit)0 - r) >> 52);
  16498. }
  16499. return r;
  16500. }
  16501. /* Conditionally subtract b from a using the mask m.
  16502. * m is -1 to subtract and 0 when not.
  16503. *
  16504. * r A single precision number representing condition subtract result.
  16505. * a A single precision number to subtract from.
  16506. * b A single precision number to subtract.
  16507. * m Mask value to apply.
  16508. */
  16509. static void sp_4096_cond_sub_39(sp_digit* r, const sp_digit* a,
  16510. const sp_digit* b, const sp_digit m)
  16511. {
  16512. int i;
  16513. for (i = 0; i < 32; i += 8) {
  16514. r[i + 0] = a[i + 0] - (b[i + 0] & m);
  16515. r[i + 1] = a[i + 1] - (b[i + 1] & m);
  16516. r[i + 2] = a[i + 2] - (b[i + 2] & m);
  16517. r[i + 3] = a[i + 3] - (b[i + 3] & m);
  16518. r[i + 4] = a[i + 4] - (b[i + 4] & m);
  16519. r[i + 5] = a[i + 5] - (b[i + 5] & m);
  16520. r[i + 6] = a[i + 6] - (b[i + 6] & m);
  16521. r[i + 7] = a[i + 7] - (b[i + 7] & m);
  16522. }
  16523. r[32] = a[32] - (b[32] & m);
  16524. r[33] = a[33] - (b[33] & m);
  16525. r[34] = a[34] - (b[34] & m);
  16526. r[35] = a[35] - (b[35] & m);
  16527. r[36] = a[36] - (b[36] & m);
  16528. r[37] = a[37] - (b[37] & m);
  16529. r[38] = a[38] - (b[38] & m);
  16530. }
  16531. /* Mul a by scalar b and add into r. (r += a * b)
  16532. *
  16533. * r A single precision integer.
  16534. * a A single precision integer.
  16535. * b A scalar.
  16536. */
  16537. SP_NOINLINE static void sp_4096_mul_add_39(sp_digit* r, const sp_digit* a,
  16538. const sp_digit b)
  16539. {
  16540. sp_int128 tb = b;
  16541. sp_int128 t[8];
  16542. int i;
  16543. t[0] = tb * a[0]; r[0] += (sp_digit)(t[0] & 0x1fffffffffffffL);
  16544. for (i = 0; i < 32; i += 8) {
  16545. t[1] = tb * a[i+1];
  16546. r[i+1] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL));
  16547. t[2] = tb * a[i+2];
  16548. r[i+2] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL));
  16549. t[3] = tb * a[i+3];
  16550. r[i+3] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL));
  16551. t[4] = tb * a[i+4];
  16552. r[i+4] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL));
  16553. t[5] = tb * a[i+5];
  16554. r[i+5] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL));
  16555. t[6] = tb * a[i+6];
  16556. r[i+6] += (sp_digit)((t[5] >> 53) + (t[6] & 0x1fffffffffffffL));
  16557. t[7] = tb * a[i+7];
  16558. r[i+7] += (sp_digit)((t[6] >> 53) + (t[7] & 0x1fffffffffffffL));
  16559. t[0] = tb * a[i+8];
  16560. r[i+8] += (sp_digit)((t[7] >> 53) + (t[0] & 0x1fffffffffffffL));
  16561. }
  16562. t[1] = tb * a[33];
  16563. r[33] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL));
  16564. t[2] = tb * a[34];
  16565. r[34] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL));
  16566. t[3] = tb * a[35];
  16567. r[35] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL));
  16568. t[4] = tb * a[36];
  16569. r[36] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL));
  16570. t[5] = tb * a[37];
  16571. r[37] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL));
  16572. t[6] = tb * a[38];
  16573. r[38] += (sp_digit)((t[5] >> 53) + (t[6] & 0x1fffffffffffffL));
  16574. r[39] += (sp_digit)(t[6] >> 53);
  16575. }
  16576. /* Shift the result in the high 2048 bits down to the bottom.
  16577. *
  16578. * r A single precision number.
  16579. * a A single precision number.
  16580. */
  16581. static void sp_4096_mont_shift_39(sp_digit* r, const sp_digit* a)
  16582. {
  16583. int i;
  16584. sp_int128 n = a[38] >> 34;
  16585. n += ((sp_int128)a[39]) << 19;
  16586. for (i = 0; i < 32; i += 8) {
  16587. r[i + 0] = n & 0x1fffffffffffffL;
  16588. n >>= 53; n += ((sp_int128)a[i + 40]) << 19;
  16589. r[i + 1] = n & 0x1fffffffffffffL;
  16590. n >>= 53; n += ((sp_int128)a[i + 41]) << 19;
  16591. r[i + 2] = n & 0x1fffffffffffffL;
  16592. n >>= 53; n += ((sp_int128)a[i + 42]) << 19;
  16593. r[i + 3] = n & 0x1fffffffffffffL;
  16594. n >>= 53; n += ((sp_int128)a[i + 43]) << 19;
  16595. r[i + 4] = n & 0x1fffffffffffffL;
  16596. n >>= 53; n += ((sp_int128)a[i + 44]) << 19;
  16597. r[i + 5] = n & 0x1fffffffffffffL;
  16598. n >>= 53; n += ((sp_int128)a[i + 45]) << 19;
  16599. r[i + 6] = n & 0x1fffffffffffffL;
  16600. n >>= 53; n += ((sp_int128)a[i + 46]) << 19;
  16601. r[i + 7] = n & 0x1fffffffffffffL;
  16602. n >>= 53; n += ((sp_int128)a[i + 47]) << 19;
  16603. }
  16604. r[32] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[72]) << 19;
  16605. r[33] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[73]) << 19;
  16606. r[34] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[74]) << 19;
  16607. r[35] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[75]) << 19;
  16608. r[36] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[76]) << 19;
  16609. r[37] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[77]) << 19;
  16610. r[38] = (sp_digit)n;
  16611. XMEMSET(&r[39], 0, sizeof(*r) * 39U);
  16612. }
  16613. /* Reduce the number back to 4096 bits using Montgomery reduction.
  16614. *
  16615. * a A single precision number to reduce in place.
  16616. * m The single precision number representing the modulus.
  16617. * mp The digit representing the negative inverse of m mod 2^n.
  16618. */
  16619. static void sp_4096_mont_reduce_39(sp_digit* a, const sp_digit* m, sp_digit mp)
  16620. {
  16621. int i;
  16622. sp_digit mu;
  16623. sp_digit over;
  16624. sp_4096_norm_39(a + 39);
  16625. for (i=0; i<38; i++) {
  16626. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffL;
  16627. sp_4096_mul_add_39(a+i, m, mu);
  16628. a[i+1] += a[i] >> 53;
  16629. }
  16630. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x3ffffffffL;
  16631. sp_4096_mul_add_39(a+i, m, mu);
  16632. a[i+1] += a[i] >> 53;
  16633. a[i] &= 0x1fffffffffffffL;
  16634. sp_4096_mont_shift_39(a, a);
  16635. over = a[38] - m[38];
  16636. sp_4096_cond_sub_39(a, a, m, ~((over - 1) >> 63));
  16637. sp_4096_norm_39(a);
  16638. }
  16639. /* Multiply two Montgomery form numbers mod the modulus (prime).
  16640. * (r = a * b mod m)
  16641. *
  16642. * r Result of multiplication.
  16643. * a First number to multiply in Montgomery form.
  16644. * b Second number to multiply in Montgomery form.
  16645. * m Modulus (prime).
  16646. * mp Montgomery multiplier.
  16647. */
  16648. SP_NOINLINE static void sp_4096_mont_mul_39(sp_digit* r, const sp_digit* a,
  16649. const sp_digit* b, const sp_digit* m, sp_digit mp)
  16650. {
  16651. sp_4096_mul_39(r, a, b);
  16652. sp_4096_mont_reduce_39(r, m, mp);
  16653. }
  16654. /* Square the Montgomery form number. (r = a * a mod m)
  16655. *
  16656. * r Result of squaring.
  16657. * a Number to square in Montgomery form.
  16658. * m Modulus (prime).
  16659. * mp Montgomery multiplier.
  16660. */
  16661. SP_NOINLINE static void sp_4096_mont_sqr_39(sp_digit* r, const sp_digit* a,
  16662. const sp_digit* m, sp_digit mp)
  16663. {
  16664. sp_4096_sqr_39(r, a);
  16665. sp_4096_mont_reduce_39(r, m, mp);
  16666. }
  16667. /* Multiply a by scalar b into r. (r = a * b)
  16668. *
  16669. * r A single precision integer.
  16670. * a A single precision integer.
  16671. * b A scalar.
  16672. */
  16673. SP_NOINLINE static void sp_4096_mul_d_39(sp_digit* r, const sp_digit* a,
  16674. sp_digit b)
  16675. {
  16676. sp_int128 tb = b;
  16677. sp_int128 t = 0;
  16678. sp_digit t2;
  16679. sp_int128 p[4];
  16680. int i;
  16681. for (i = 0; i < 36; i += 4) {
  16682. p[0] = tb * a[i + 0];
  16683. p[1] = tb * a[i + 1];
  16684. p[2] = tb * a[i + 2];
  16685. p[3] = tb * a[i + 3];
  16686. t += p[0];
  16687. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16688. t >>= 53;
  16689. r[i + 0] = (sp_digit)t2;
  16690. t += p[1];
  16691. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16692. t >>= 53;
  16693. r[i + 1] = (sp_digit)t2;
  16694. t += p[2];
  16695. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16696. t >>= 53;
  16697. r[i + 2] = (sp_digit)t2;
  16698. t += p[3];
  16699. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  16700. t >>= 53;
  16701. r[i + 3] = (sp_digit)t2;
  16702. }
  16703. t += tb * a[36];
  16704. r[36] = (sp_digit)(t & 0x1fffffffffffffL);
  16705. t >>= 53;
  16706. t += tb * a[37];
  16707. r[37] = (sp_digit)(t & 0x1fffffffffffffL);
  16708. t >>= 53;
  16709. t += tb * a[38];
  16710. r[38] = (sp_digit)(t & 0x1fffffffffffffL);
  16711. t >>= 53;
  16712. r[39] = (sp_digit)(t & 0x1fffffffffffffL);
  16713. }
  16714. #ifndef WOLFSSL_SP_SMALL
  16715. /* Conditionally add a and b using the mask m.
  16716. * m is -1 to add and 0 when not.
  16717. *
  16718. * r A single precision number representing conditional add result.
  16719. * a A single precision number to add with.
  16720. * b A single precision number to add.
  16721. * m Mask value to apply.
  16722. */
  16723. static void sp_4096_cond_add_39(sp_digit* r, const sp_digit* a,
  16724. const sp_digit* b, const sp_digit m)
  16725. {
  16726. int i;
  16727. for (i = 0; i < 32; i += 8) {
  16728. r[i + 0] = a[i + 0] + (b[i + 0] & m);
  16729. r[i + 1] = a[i + 1] + (b[i + 1] & m);
  16730. r[i + 2] = a[i + 2] + (b[i + 2] & m);
  16731. r[i + 3] = a[i + 3] + (b[i + 3] & m);
  16732. r[i + 4] = a[i + 4] + (b[i + 4] & m);
  16733. r[i + 5] = a[i + 5] + (b[i + 5] & m);
  16734. r[i + 6] = a[i + 6] + (b[i + 6] & m);
  16735. r[i + 7] = a[i + 7] + (b[i + 7] & m);
  16736. }
  16737. r[32] = a[32] + (b[32] & m);
  16738. r[33] = a[33] + (b[33] & m);
  16739. r[34] = a[34] + (b[34] & m);
  16740. r[35] = a[35] + (b[35] & m);
  16741. r[36] = a[36] + (b[36] & m);
  16742. r[37] = a[37] + (b[37] & m);
  16743. r[38] = a[38] + (b[38] & m);
  16744. }
  16745. #endif /* !WOLFSSL_SP_SMALL */
  16746. SP_NOINLINE static void sp_4096_rshift_39(sp_digit* r, const sp_digit* a,
  16747. byte n)
  16748. {
  16749. int i;
  16750. for (i=0; i<32; i += 8) {
  16751. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (53 - n)) & 0x1fffffffffffffL);
  16752. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (53 - n)) & 0x1fffffffffffffL);
  16753. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (53 - n)) & 0x1fffffffffffffL);
  16754. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (53 - n)) & 0x1fffffffffffffL);
  16755. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (53 - n)) & 0x1fffffffffffffL);
  16756. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (53 - n)) & 0x1fffffffffffffL);
  16757. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (53 - n)) & 0x1fffffffffffffL);
  16758. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (53 - n)) & 0x1fffffffffffffL);
  16759. }
  16760. r[32] = (a[32] >> n) | ((a[33] << (53 - n)) & 0x1fffffffffffffL);
  16761. r[33] = (a[33] >> n) | ((a[34] << (53 - n)) & 0x1fffffffffffffL);
  16762. r[34] = (a[34] >> n) | ((a[35] << (53 - n)) & 0x1fffffffffffffL);
  16763. r[35] = (a[35] >> n) | ((a[36] << (53 - n)) & 0x1fffffffffffffL);
  16764. r[36] = (a[36] >> n) | ((a[37] << (53 - n)) & 0x1fffffffffffffL);
  16765. r[37] = (a[37] >> n) | ((a[38] << (53 - n)) & 0x1fffffffffffffL);
  16766. r[38] = a[38] >> n;
  16767. }
  16768. static WC_INLINE sp_digit sp_4096_div_word_39(sp_digit d1, sp_digit d0,
  16769. sp_digit div)
  16770. {
  16771. #ifdef SP_USE_DIVTI3
  16772. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  16773. return d / div;
  16774. #elif defined(__x86_64__) || defined(__i386__)
  16775. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  16776. sp_uint64 lo = (sp_uint64)d;
  16777. sp_digit hi = (sp_digit)(d >> 64);
  16778. __asm__ __volatile__ (
  16779. "idiv %2"
  16780. : "+a" (lo)
  16781. : "d" (hi), "r" (div)
  16782. : "cc"
  16783. );
  16784. return (sp_digit)lo;
  16785. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  16786. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  16787. sp_digit dv = (div >> 1) + 1;
  16788. sp_digit t1 = (sp_digit)(d >> 53);
  16789. sp_digit t0 = (sp_digit)(d & 0x1fffffffffffffL);
  16790. sp_digit t2;
  16791. sp_digit sign;
  16792. sp_digit r;
  16793. int i;
  16794. sp_int128 m;
  16795. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  16796. t1 -= dv & (0 - r);
  16797. for (i = 51; i >= 1; i--) {
  16798. t1 += t1 + (((sp_uint64)t0 >> 52) & 1);
  16799. t0 <<= 1;
  16800. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  16801. r += r + t2;
  16802. t1 -= dv & (0 - t2);
  16803. t1 += t2;
  16804. }
  16805. r += r + 1;
  16806. m = d - ((sp_int128)r * div);
  16807. r += (sp_digit)(m >> 53);
  16808. m = d - ((sp_int128)r * div);
  16809. r += (sp_digit)(m >> 106) - (sp_digit)(d >> 106);
  16810. m = d - ((sp_int128)r * div);
  16811. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  16812. m *= sign;
  16813. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  16814. r += sign * t2;
  16815. m = d - ((sp_int128)r * div);
  16816. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  16817. m *= sign;
  16818. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  16819. r += sign * t2;
  16820. return r;
  16821. #else
  16822. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  16823. sp_digit r = 0;
  16824. sp_digit t;
  16825. sp_digit dv = (div >> 22) + 1;
  16826. t = (sp_digit)(d >> 44);
  16827. t = (t / dv) << 22;
  16828. r += t;
  16829. d -= (sp_int128)t * div;
  16830. t = (sp_digit)(d >> 13);
  16831. t = t / (dv << 9);
  16832. r += t;
  16833. d -= (sp_int128)t * div;
  16834. t = (sp_digit)d;
  16835. t = t / div;
  16836. r += t;
  16837. d -= (sp_int128)t * div;
  16838. return r;
  16839. #endif
  16840. }
  16841. static WC_INLINE sp_digit sp_4096_word_div_word_39(sp_digit d, sp_digit div)
  16842. {
  16843. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  16844. defined(SP_DIV_WORD_USE_DIV)
  16845. return d / div;
  16846. #else
  16847. return (sp_digit)((sp_uint64)(div - d) >> 63);
  16848. #endif
  16849. }
  16850. /* Divide d in a and put remainder into r (m*d + r = a)
  16851. * m is not calculated as it is not needed at this time.
  16852. *
  16853. * Full implementation.
  16854. *
  16855. * a Number to be divided.
  16856. * d Number to divide with.
  16857. * m Multiplier result.
  16858. * r Remainder from the division.
  16859. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  16860. */
  16861. static int sp_4096_div_39(const sp_digit* a, const sp_digit* d,
  16862. const sp_digit* m, sp_digit* r)
  16863. {
  16864. int i;
  16865. #ifndef WOLFSSL_SP_DIV_64
  16866. #endif
  16867. sp_digit dv;
  16868. sp_digit r1;
  16869. #ifdef WOLFSSL_SP_SMALL_STACK
  16870. sp_digit* t1 = NULL;
  16871. #else
  16872. sp_digit t1[4 * 39 + 3];
  16873. #endif
  16874. sp_digit* t2 = NULL;
  16875. sp_digit* sd = NULL;
  16876. int err = MP_OKAY;
  16877. (void)m;
  16878. #ifdef WOLFSSL_SP_SMALL_STACK
  16879. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 39 + 3), NULL,
  16880. DYNAMIC_TYPE_TMP_BUFFER);
  16881. if (t1 == NULL)
  16882. err = MEMORY_E;
  16883. #endif
  16884. (void)m;
  16885. if (err == MP_OKAY) {
  16886. t2 = t1 + 78 + 1;
  16887. sd = t2 + 39 + 1;
  16888. sp_4096_mul_d_39(sd, d, (sp_digit)1 << 19);
  16889. sp_4096_mul_d_78(t1, a, (sp_digit)1 << 19);
  16890. dv = sd[38];
  16891. t1[39 + 39] += t1[39 + 39 - 1] >> 53;
  16892. t1[39 + 39 - 1] &= 0x1fffffffffffffL;
  16893. for (i=39; i>=0; i--) {
  16894. r1 = sp_4096_div_word_39(t1[39 + i], t1[39 + i - 1], dv);
  16895. sp_4096_mul_d_39(t2, sd, r1);
  16896. (void)sp_4096_sub_39(&t1[i], &t1[i], t2);
  16897. sp_4096_norm_39(&t1[i]);
  16898. t1[39 + i] -= t2[39];
  16899. t1[39 + i] += t1[39 + i - 1] >> 53;
  16900. t1[39 + i - 1] &= 0x1fffffffffffffL;
  16901. r1 = sp_4096_div_word_39(-t1[39 + i], -t1[39 + i - 1], dv);
  16902. r1 -= t1[39 + i];
  16903. sp_4096_mul_d_39(t2, sd, r1);
  16904. (void)sp_4096_add_39(&t1[i], &t1[i], t2);
  16905. t1[39 + i] += t1[39 + i - 1] >> 53;
  16906. t1[39 + i - 1] &= 0x1fffffffffffffL;
  16907. }
  16908. t1[39 - 1] += t1[39 - 2] >> 53;
  16909. t1[39 - 2] &= 0x1fffffffffffffL;
  16910. r1 = sp_4096_word_div_word_39(t1[39 - 1], dv);
  16911. sp_4096_mul_d_39(t2, sd, r1);
  16912. sp_4096_sub_39(t1, t1, t2);
  16913. XMEMCPY(r, t1, sizeof(*r) * 78U);
  16914. for (i=0; i<38; i++) {
  16915. r[i+1] += r[i] >> 53;
  16916. r[i] &= 0x1fffffffffffffL;
  16917. }
  16918. sp_4096_cond_add_39(r, r, sd, r[38] >> 63);
  16919. sp_4096_norm_39(r);
  16920. sp_4096_rshift_39(r, r, 19);
  16921. }
  16922. #ifdef WOLFSSL_SP_SMALL_STACK
  16923. if (t1 != NULL)
  16924. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  16925. #endif
  16926. return err;
  16927. }
  16928. /* Reduce a modulo m into r. (r = a mod m)
  16929. *
  16930. * r A single precision number that is the reduced result.
  16931. * a A single precision number that is to be reduced.
  16932. * m A single precision number that is the modulus to reduce with.
  16933. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  16934. */
  16935. static int sp_4096_mod_39(sp_digit* r, const sp_digit* a, const sp_digit* m)
  16936. {
  16937. return sp_4096_div_39(a, m, NULL, r);
  16938. }
  16939. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  16940. *
  16941. * r A single precision number that is the result of the operation.
  16942. * a A single precision number being exponentiated.
  16943. * e A single precision number that is the exponent.
  16944. * bits The number of bits in the exponent.
  16945. * m A single precision number that is the modulus.
  16946. * returns 0 on success.
  16947. * returns MEMORY_E on dynamic memory allocation failure.
  16948. * returns MP_VAL when base is even or exponent is 0.
  16949. */
  16950. static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e,
  16951. int bits, const sp_digit* m, int reduceA)
  16952. {
  16953. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  16954. #ifdef WOLFSSL_SP_SMALL_STACK
  16955. sp_digit* td = NULL;
  16956. #else
  16957. sp_digit td[3 * 78];
  16958. #endif
  16959. sp_digit* t[3] = {0, 0, 0};
  16960. sp_digit* norm = NULL;
  16961. sp_digit mp = 1;
  16962. sp_digit n;
  16963. int i;
  16964. int c;
  16965. byte y;
  16966. int err = MP_OKAY;
  16967. if (bits == 0) {
  16968. err = MP_VAL;
  16969. }
  16970. #ifdef WOLFSSL_SP_SMALL_STACK
  16971. if (err == MP_OKAY) {
  16972. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 39 * 2, NULL,
  16973. DYNAMIC_TYPE_TMP_BUFFER);
  16974. if (td == NULL)
  16975. err = MEMORY_E;
  16976. }
  16977. #endif
  16978. if (err == MP_OKAY) {
  16979. norm = td;
  16980. for (i=0; i<3; i++) {
  16981. t[i] = td + (i * 39 * 2);
  16982. XMEMSET(t[i], 0, sizeof(sp_digit) * 39U * 2U);
  16983. }
  16984. sp_4096_mont_setup(m, &mp);
  16985. sp_4096_mont_norm_39(norm, m);
  16986. if (reduceA != 0) {
  16987. err = sp_4096_mod_39(t[1], a, m);
  16988. }
  16989. else {
  16990. XMEMCPY(t[1], a, sizeof(sp_digit) * 39U);
  16991. }
  16992. }
  16993. if (err == MP_OKAY) {
  16994. sp_4096_mul_39(t[1], t[1], norm);
  16995. err = sp_4096_mod_39(t[1], t[1], m);
  16996. }
  16997. if (err == MP_OKAY) {
  16998. i = bits / 53;
  16999. c = bits % 53;
  17000. n = e[i--] << (53 - c);
  17001. for (; ; c--) {
  17002. if (c == 0) {
  17003. if (i == -1) {
  17004. break;
  17005. }
  17006. n = e[i--];
  17007. c = 53;
  17008. }
  17009. y = (int)((n >> 52) & 1);
  17010. n <<= 1;
  17011. sp_4096_mont_mul_39(t[y^1], t[0], t[1], m, mp);
  17012. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  17013. ((size_t)t[1] & addr_mask[y])),
  17014. sizeof(*t[2]) * 39 * 2);
  17015. sp_4096_mont_sqr_39(t[2], t[2], m, mp);
  17016. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  17017. ((size_t)t[1] & addr_mask[y])), t[2],
  17018. sizeof(*t[2]) * 39 * 2);
  17019. }
  17020. sp_4096_mont_reduce_39(t[0], m, mp);
  17021. n = sp_4096_cmp_39(t[0], m);
  17022. sp_4096_cond_sub_39(t[0], t[0], m, ~(n >> 63));
  17023. XMEMCPY(r, t[0], sizeof(*r) * 39 * 2);
  17024. }
  17025. #ifdef WOLFSSL_SP_SMALL_STACK
  17026. if (td != NULL)
  17027. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17028. #endif
  17029. return err;
  17030. #elif !defined(WC_NO_CACHE_RESISTANT)
  17031. #ifdef WOLFSSL_SP_SMALL_STACK
  17032. sp_digit* td = NULL;
  17033. #else
  17034. sp_digit td[3 * 78];
  17035. #endif
  17036. sp_digit* t[3] = {0, 0, 0};
  17037. sp_digit* norm = NULL;
  17038. sp_digit mp = 1;
  17039. sp_digit n;
  17040. int i;
  17041. int c;
  17042. byte y;
  17043. int err = MP_OKAY;
  17044. if (bits == 0) {
  17045. err = MP_VAL;
  17046. }
  17047. #ifdef WOLFSSL_SP_SMALL_STACK
  17048. if (err == MP_OKAY) {
  17049. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 39 * 2, NULL,
  17050. DYNAMIC_TYPE_TMP_BUFFER);
  17051. if (td == NULL)
  17052. err = MEMORY_E;
  17053. }
  17054. #endif
  17055. if (err == MP_OKAY) {
  17056. norm = td;
  17057. for (i=0; i<3; i++) {
  17058. t[i] = td + (i * 39 * 2);
  17059. }
  17060. sp_4096_mont_setup(m, &mp);
  17061. sp_4096_mont_norm_39(norm, m);
  17062. if (reduceA != 0) {
  17063. err = sp_4096_mod_39(t[1], a, m);
  17064. if (err == MP_OKAY) {
  17065. sp_4096_mul_39(t[1], t[1], norm);
  17066. err = sp_4096_mod_39(t[1], t[1], m);
  17067. }
  17068. }
  17069. else {
  17070. sp_4096_mul_39(t[1], a, norm);
  17071. err = sp_4096_mod_39(t[1], t[1], m);
  17072. }
  17073. }
  17074. if (err == MP_OKAY) {
  17075. i = bits / 53;
  17076. c = bits % 53;
  17077. n = e[i--] << (53 - c);
  17078. for (; ; c--) {
  17079. if (c == 0) {
  17080. if (i == -1) {
  17081. break;
  17082. }
  17083. n = e[i--];
  17084. c = 53;
  17085. }
  17086. y = (int)((n >> 52) & 1);
  17087. n <<= 1;
  17088. sp_4096_mont_mul_39(t[y^1], t[0], t[1], m, mp);
  17089. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  17090. ((size_t)t[1] & addr_mask[y])),
  17091. sizeof(*t[2]) * 39 * 2);
  17092. sp_4096_mont_sqr_39(t[2], t[2], m, mp);
  17093. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  17094. ((size_t)t[1] & addr_mask[y])), t[2],
  17095. sizeof(*t[2]) * 39 * 2);
  17096. }
  17097. sp_4096_mont_reduce_39(t[0], m, mp);
  17098. n = sp_4096_cmp_39(t[0], m);
  17099. sp_4096_cond_sub_39(t[0], t[0], m, ~(n >> 63));
  17100. XMEMCPY(r, t[0], sizeof(*r) * 39 * 2);
  17101. }
  17102. #ifdef WOLFSSL_SP_SMALL_STACK
  17103. if (td != NULL)
  17104. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17105. #endif
  17106. return err;
  17107. #else
  17108. #ifdef WOLFSSL_SP_SMALL_STACK
  17109. sp_digit* td = NULL;
  17110. #else
  17111. sp_digit td[(32 * 78) + 78];
  17112. #endif
  17113. sp_digit* t[32];
  17114. sp_digit* rt = NULL;
  17115. sp_digit* norm = NULL;
  17116. sp_digit mp = 1;
  17117. sp_digit n;
  17118. int i;
  17119. int c;
  17120. byte y;
  17121. int err = MP_OKAY;
  17122. if (bits == 0) {
  17123. err = MP_VAL;
  17124. }
  17125. #ifdef WOLFSSL_SP_SMALL_STACK
  17126. if (err == MP_OKAY) {
  17127. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 78) + 78), NULL,
  17128. DYNAMIC_TYPE_TMP_BUFFER);
  17129. if (td == NULL)
  17130. err = MEMORY_E;
  17131. }
  17132. #endif
  17133. if (err == MP_OKAY) {
  17134. norm = td;
  17135. for (i=0; i<32; i++)
  17136. t[i] = td + i * 78;
  17137. rt = td + 2496;
  17138. sp_4096_mont_setup(m, &mp);
  17139. sp_4096_mont_norm_39(norm, m);
  17140. if (reduceA != 0) {
  17141. err = sp_4096_mod_39(t[1], a, m);
  17142. if (err == MP_OKAY) {
  17143. sp_4096_mul_39(t[1], t[1], norm);
  17144. err = sp_4096_mod_39(t[1], t[1], m);
  17145. }
  17146. }
  17147. else {
  17148. sp_4096_mul_39(t[1], a, norm);
  17149. err = sp_4096_mod_39(t[1], t[1], m);
  17150. }
  17151. }
  17152. if (err == MP_OKAY) {
  17153. sp_4096_mont_sqr_39(t[ 2], t[ 1], m, mp);
  17154. sp_4096_mont_mul_39(t[ 3], t[ 2], t[ 1], m, mp);
  17155. sp_4096_mont_sqr_39(t[ 4], t[ 2], m, mp);
  17156. sp_4096_mont_mul_39(t[ 5], t[ 3], t[ 2], m, mp);
  17157. sp_4096_mont_sqr_39(t[ 6], t[ 3], m, mp);
  17158. sp_4096_mont_mul_39(t[ 7], t[ 4], t[ 3], m, mp);
  17159. sp_4096_mont_sqr_39(t[ 8], t[ 4], m, mp);
  17160. sp_4096_mont_mul_39(t[ 9], t[ 5], t[ 4], m, mp);
  17161. sp_4096_mont_sqr_39(t[10], t[ 5], m, mp);
  17162. sp_4096_mont_mul_39(t[11], t[ 6], t[ 5], m, mp);
  17163. sp_4096_mont_sqr_39(t[12], t[ 6], m, mp);
  17164. sp_4096_mont_mul_39(t[13], t[ 7], t[ 6], m, mp);
  17165. sp_4096_mont_sqr_39(t[14], t[ 7], m, mp);
  17166. sp_4096_mont_mul_39(t[15], t[ 8], t[ 7], m, mp);
  17167. sp_4096_mont_sqr_39(t[16], t[ 8], m, mp);
  17168. sp_4096_mont_mul_39(t[17], t[ 9], t[ 8], m, mp);
  17169. sp_4096_mont_sqr_39(t[18], t[ 9], m, mp);
  17170. sp_4096_mont_mul_39(t[19], t[10], t[ 9], m, mp);
  17171. sp_4096_mont_sqr_39(t[20], t[10], m, mp);
  17172. sp_4096_mont_mul_39(t[21], t[11], t[10], m, mp);
  17173. sp_4096_mont_sqr_39(t[22], t[11], m, mp);
  17174. sp_4096_mont_mul_39(t[23], t[12], t[11], m, mp);
  17175. sp_4096_mont_sqr_39(t[24], t[12], m, mp);
  17176. sp_4096_mont_mul_39(t[25], t[13], t[12], m, mp);
  17177. sp_4096_mont_sqr_39(t[26], t[13], m, mp);
  17178. sp_4096_mont_mul_39(t[27], t[14], t[13], m, mp);
  17179. sp_4096_mont_sqr_39(t[28], t[14], m, mp);
  17180. sp_4096_mont_mul_39(t[29], t[15], t[14], m, mp);
  17181. sp_4096_mont_sqr_39(t[30], t[15], m, mp);
  17182. sp_4096_mont_mul_39(t[31], t[16], t[15], m, mp);
  17183. bits = ((bits + 4) / 5) * 5;
  17184. i = ((bits + 52) / 53) - 1;
  17185. c = bits % 53;
  17186. if (c == 0) {
  17187. c = 53;
  17188. }
  17189. if (i < 39) {
  17190. n = e[i--] << (64 - c);
  17191. }
  17192. else {
  17193. n = 0;
  17194. i--;
  17195. }
  17196. if (c < 5) {
  17197. n |= e[i--] << (11 - c);
  17198. c += 53;
  17199. }
  17200. y = (int)((n >> 59) & 0x1f);
  17201. n <<= 5;
  17202. c -= 5;
  17203. XMEMCPY(rt, t[y], sizeof(sp_digit) * 78);
  17204. while ((i >= 0) || (c >= 5)) {
  17205. if (c >= 5) {
  17206. y = (byte)((n >> 59) & 0x1f);
  17207. n <<= 5;
  17208. c -= 5;
  17209. }
  17210. else if (c == 0) {
  17211. n = e[i--] << 11;
  17212. y = (byte)((n >> 59) & 0x1f);
  17213. n <<= 5;
  17214. c = 48;
  17215. }
  17216. else {
  17217. y = (byte)((n >> 59) & 0x1f);
  17218. n = e[i--] << 11;
  17219. c = 5 - c;
  17220. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  17221. n <<= c;
  17222. c = 53 - c;
  17223. }
  17224. sp_4096_mont_sqr_39(rt, rt, m, mp);
  17225. sp_4096_mont_sqr_39(rt, rt, m, mp);
  17226. sp_4096_mont_sqr_39(rt, rt, m, mp);
  17227. sp_4096_mont_sqr_39(rt, rt, m, mp);
  17228. sp_4096_mont_sqr_39(rt, rt, m, mp);
  17229. sp_4096_mont_mul_39(rt, rt, t[y], m, mp);
  17230. }
  17231. sp_4096_mont_reduce_39(rt, m, mp);
  17232. n = sp_4096_cmp_39(rt, m);
  17233. sp_4096_cond_sub_39(rt, rt, m, ~(n >> 63));
  17234. XMEMCPY(r, rt, sizeof(sp_digit) * 78);
  17235. }
  17236. #ifdef WOLFSSL_SP_SMALL_STACK
  17237. if (td != NULL)
  17238. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17239. #endif
  17240. return err;
  17241. #endif
  17242. }
  17243. #endif /* WOLFSSL_HAVE_SP_RSA & !SP_RSA_PRIVATE_EXP_D */
  17244. #endif /* (WOLFSSL_HAVE_SP_RSA | WOLFSSL_HAVE_SP_DH) & !WOLFSSL_RSA_PUBLIC_ONLY */
  17245. /* r = 2^n mod m where n is the number of bits to reduce by.
  17246. * Given m must be 4096 bits, just need to subtract.
  17247. *
  17248. * r A single precision number.
  17249. * m A single precision number.
  17250. */
  17251. static void sp_4096_mont_norm_78(sp_digit* r, const sp_digit* m)
  17252. {
  17253. /* Set r = 2^n - 1. */
  17254. int i;
  17255. for (i = 0; i < 72; i += 8) {
  17256. r[i + 0] = 0x1fffffffffffffL;
  17257. r[i + 1] = 0x1fffffffffffffL;
  17258. r[i + 2] = 0x1fffffffffffffL;
  17259. r[i + 3] = 0x1fffffffffffffL;
  17260. r[i + 4] = 0x1fffffffffffffL;
  17261. r[i + 5] = 0x1fffffffffffffL;
  17262. r[i + 6] = 0x1fffffffffffffL;
  17263. r[i + 7] = 0x1fffffffffffffL;
  17264. }
  17265. r[72] = 0x1fffffffffffffL;
  17266. r[73] = 0x1fffffffffffffL;
  17267. r[74] = 0x1fffffffffffffL;
  17268. r[75] = 0x1fffffffffffffL;
  17269. r[76] = 0x1fffffffffffffL;
  17270. r[77] = 0x7fffL;
  17271. /* r = (2^n - 1) mod n */
  17272. (void)sp_4096_sub_78(r, r, m);
  17273. /* Add one so r = 2^n mod m */
  17274. r[0] += 1;
  17275. }
  17276. /* Compare a with b in constant time.
  17277. *
  17278. * a A single precision integer.
  17279. * b A single precision integer.
  17280. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  17281. * respectively.
  17282. */
  17283. static sp_digit sp_4096_cmp_78(const sp_digit* a, const sp_digit* b)
  17284. {
  17285. sp_digit r = 0;
  17286. int i;
  17287. r |= (a[77] - b[77]) & (0 - (sp_digit)1);
  17288. r |= (a[76] - b[76]) & ~(((sp_digit)0 - r) >> 52);
  17289. r |= (a[75] - b[75]) & ~(((sp_digit)0 - r) >> 52);
  17290. r |= (a[74] - b[74]) & ~(((sp_digit)0 - r) >> 52);
  17291. r |= (a[73] - b[73]) & ~(((sp_digit)0 - r) >> 52);
  17292. r |= (a[72] - b[72]) & ~(((sp_digit)0 - r) >> 52);
  17293. for (i = 64; i >= 0; i -= 8) {
  17294. r |= (a[i + 7] - b[i + 7]) & ~(((sp_digit)0 - r) >> 52);
  17295. r |= (a[i + 6] - b[i + 6]) & ~(((sp_digit)0 - r) >> 52);
  17296. r |= (a[i + 5] - b[i + 5]) & ~(((sp_digit)0 - r) >> 52);
  17297. r |= (a[i + 4] - b[i + 4]) & ~(((sp_digit)0 - r) >> 52);
  17298. r |= (a[i + 3] - b[i + 3]) & ~(((sp_digit)0 - r) >> 52);
  17299. r |= (a[i + 2] - b[i + 2]) & ~(((sp_digit)0 - r) >> 52);
  17300. r |= (a[i + 1] - b[i + 1]) & ~(((sp_digit)0 - r) >> 52);
  17301. r |= (a[i + 0] - b[i + 0]) & ~(((sp_digit)0 - r) >> 52);
  17302. }
  17303. return r;
  17304. }
  17305. /* Conditionally subtract b from a using the mask m.
  17306. * m is -1 to subtract and 0 when not.
  17307. *
  17308. * r A single precision number representing condition subtract result.
  17309. * a A single precision number to subtract from.
  17310. * b A single precision number to subtract.
  17311. * m Mask value to apply.
  17312. */
  17313. static void sp_4096_cond_sub_78(sp_digit* r, const sp_digit* a,
  17314. const sp_digit* b, const sp_digit m)
  17315. {
  17316. int i;
  17317. for (i = 0; i < 72; i += 8) {
  17318. r[i + 0] = a[i + 0] - (b[i + 0] & m);
  17319. r[i + 1] = a[i + 1] - (b[i + 1] & m);
  17320. r[i + 2] = a[i + 2] - (b[i + 2] & m);
  17321. r[i + 3] = a[i + 3] - (b[i + 3] & m);
  17322. r[i + 4] = a[i + 4] - (b[i + 4] & m);
  17323. r[i + 5] = a[i + 5] - (b[i + 5] & m);
  17324. r[i + 6] = a[i + 6] - (b[i + 6] & m);
  17325. r[i + 7] = a[i + 7] - (b[i + 7] & m);
  17326. }
  17327. r[72] = a[72] - (b[72] & m);
  17328. r[73] = a[73] - (b[73] & m);
  17329. r[74] = a[74] - (b[74] & m);
  17330. r[75] = a[75] - (b[75] & m);
  17331. r[76] = a[76] - (b[76] & m);
  17332. r[77] = a[77] - (b[77] & m);
  17333. }
  17334. /* Mul a by scalar b and add into r. (r += a * b)
  17335. *
  17336. * r A single precision integer.
  17337. * a A single precision integer.
  17338. * b A scalar.
  17339. */
  17340. SP_NOINLINE static void sp_4096_mul_add_78(sp_digit* r, const sp_digit* a,
  17341. const sp_digit b)
  17342. {
  17343. sp_int128 tb = b;
  17344. sp_int128 t[8];
  17345. int i;
  17346. t[0] = tb * a[0]; r[0] += (sp_digit)(t[0] & 0x1fffffffffffffL);
  17347. for (i = 0; i < 72; i += 8) {
  17348. t[1] = tb * a[i+1];
  17349. r[i+1] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL));
  17350. t[2] = tb * a[i+2];
  17351. r[i+2] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL));
  17352. t[3] = tb * a[i+3];
  17353. r[i+3] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL));
  17354. t[4] = tb * a[i+4];
  17355. r[i+4] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL));
  17356. t[5] = tb * a[i+5];
  17357. r[i+5] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL));
  17358. t[6] = tb * a[i+6];
  17359. r[i+6] += (sp_digit)((t[5] >> 53) + (t[6] & 0x1fffffffffffffL));
  17360. t[7] = tb * a[i+7];
  17361. r[i+7] += (sp_digit)((t[6] >> 53) + (t[7] & 0x1fffffffffffffL));
  17362. t[0] = tb * a[i+8];
  17363. r[i+8] += (sp_digit)((t[7] >> 53) + (t[0] & 0x1fffffffffffffL));
  17364. }
  17365. t[1] = tb * a[73];
  17366. r[73] += (sp_digit)((t[0] >> 53) + (t[1] & 0x1fffffffffffffL));
  17367. t[2] = tb * a[74];
  17368. r[74] += (sp_digit)((t[1] >> 53) + (t[2] & 0x1fffffffffffffL));
  17369. t[3] = tb * a[75];
  17370. r[75] += (sp_digit)((t[2] >> 53) + (t[3] & 0x1fffffffffffffL));
  17371. t[4] = tb * a[76];
  17372. r[76] += (sp_digit)((t[3] >> 53) + (t[4] & 0x1fffffffffffffL));
  17373. t[5] = tb * a[77];
  17374. r[77] += (sp_digit)((t[4] >> 53) + (t[5] & 0x1fffffffffffffL));
  17375. r[78] += (sp_digit)(t[5] >> 53);
  17376. }
  17377. /* Shift the result in the high 4096 bits down to the bottom.
  17378. *
  17379. * r A single precision number.
  17380. * a A single precision number.
  17381. */
  17382. static void sp_4096_mont_shift_78(sp_digit* r, const sp_digit* a)
  17383. {
  17384. int i;
  17385. sp_int128 n = a[77] >> 15;
  17386. n += ((sp_int128)a[78]) << 38;
  17387. for (i = 0; i < 72; i += 8) {
  17388. r[i + 0] = n & 0x1fffffffffffffL;
  17389. n >>= 53; n += ((sp_int128)a[i + 79]) << 38;
  17390. r[i + 1] = n & 0x1fffffffffffffL;
  17391. n >>= 53; n += ((sp_int128)a[i + 80]) << 38;
  17392. r[i + 2] = n & 0x1fffffffffffffL;
  17393. n >>= 53; n += ((sp_int128)a[i + 81]) << 38;
  17394. r[i + 3] = n & 0x1fffffffffffffL;
  17395. n >>= 53; n += ((sp_int128)a[i + 82]) << 38;
  17396. r[i + 4] = n & 0x1fffffffffffffL;
  17397. n >>= 53; n += ((sp_int128)a[i + 83]) << 38;
  17398. r[i + 5] = n & 0x1fffffffffffffL;
  17399. n >>= 53; n += ((sp_int128)a[i + 84]) << 38;
  17400. r[i + 6] = n & 0x1fffffffffffffL;
  17401. n >>= 53; n += ((sp_int128)a[i + 85]) << 38;
  17402. r[i + 7] = n & 0x1fffffffffffffL;
  17403. n >>= 53; n += ((sp_int128)a[i + 86]) << 38;
  17404. }
  17405. r[72] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[151]) << 38;
  17406. r[73] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[152]) << 38;
  17407. r[74] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[153]) << 38;
  17408. r[75] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[154]) << 38;
  17409. r[76] = n & 0x1fffffffffffffL; n >>= 53; n += ((sp_int128)a[155]) << 38;
  17410. r[77] = (sp_digit)n;
  17411. XMEMSET(&r[78], 0, sizeof(*r) * 78U);
  17412. }
  17413. /* Reduce the number back to 4096 bits using Montgomery reduction.
  17414. *
  17415. * a A single precision number to reduce in place.
  17416. * m The single precision number representing the modulus.
  17417. * mp The digit representing the negative inverse of m mod 2^n.
  17418. */
  17419. static void sp_4096_mont_reduce_78(sp_digit* a, const sp_digit* m, sp_digit mp)
  17420. {
  17421. int i;
  17422. sp_digit mu;
  17423. sp_digit over;
  17424. sp_4096_norm_78(a + 78);
  17425. #ifdef WOLFSSL_SP_DH
  17426. if (mp != 1) {
  17427. for (i=0; i<77; i++) {
  17428. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffL;
  17429. sp_4096_mul_add_78(a+i, m, mu);
  17430. a[i+1] += a[i] >> 53;
  17431. }
  17432. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7fffL;
  17433. sp_4096_mul_add_78(a+i, m, mu);
  17434. a[i+1] += a[i] >> 53;
  17435. a[i] &= 0x1fffffffffffffL;
  17436. }
  17437. else {
  17438. for (i=0; i<77; i++) {
  17439. mu = a[i] & 0x1fffffffffffffL;
  17440. sp_4096_mul_add_78(a+i, m, mu);
  17441. a[i+1] += a[i] >> 53;
  17442. }
  17443. mu = a[i] & 0x7fffL;
  17444. sp_4096_mul_add_78(a+i, m, mu);
  17445. a[i+1] += a[i] >> 53;
  17446. a[i] &= 0x1fffffffffffffL;
  17447. }
  17448. #else
  17449. for (i=0; i<77; i++) {
  17450. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1fffffffffffffL;
  17451. sp_4096_mul_add_78(a+i, m, mu);
  17452. a[i+1] += a[i] >> 53;
  17453. }
  17454. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7fffL;
  17455. sp_4096_mul_add_78(a+i, m, mu);
  17456. a[i+1] += a[i] >> 53;
  17457. a[i] &= 0x1fffffffffffffL;
  17458. #endif
  17459. sp_4096_mont_shift_78(a, a);
  17460. over = a[77] - m[77];
  17461. sp_4096_cond_sub_78(a, a, m, ~((over - 1) >> 63));
  17462. sp_4096_norm_78(a);
  17463. }
  17464. /* Multiply two Montgomery form numbers mod the modulus (prime).
  17465. * (r = a * b mod m)
  17466. *
  17467. * r Result of multiplication.
  17468. * a First number to multiply in Montgomery form.
  17469. * b Second number to multiply in Montgomery form.
  17470. * m Modulus (prime).
  17471. * mp Montgomery multiplier.
  17472. */
  17473. SP_NOINLINE static void sp_4096_mont_mul_78(sp_digit* r, const sp_digit* a,
  17474. const sp_digit* b, const sp_digit* m, sp_digit mp)
  17475. {
  17476. sp_4096_mul_78(r, a, b);
  17477. sp_4096_mont_reduce_78(r, m, mp);
  17478. }
  17479. /* Square the Montgomery form number. (r = a * a mod m)
  17480. *
  17481. * r Result of squaring.
  17482. * a Number to square in Montgomery form.
  17483. * m Modulus (prime).
  17484. * mp Montgomery multiplier.
  17485. */
  17486. SP_NOINLINE static void sp_4096_mont_sqr_78(sp_digit* r, const sp_digit* a,
  17487. const sp_digit* m, sp_digit mp)
  17488. {
  17489. sp_4096_sqr_78(r, a);
  17490. sp_4096_mont_reduce_78(r, m, mp);
  17491. }
  17492. /* Multiply a by scalar b into r. (r = a * b)
  17493. *
  17494. * r A single precision integer.
  17495. * a A single precision integer.
  17496. * b A scalar.
  17497. */
  17498. SP_NOINLINE static void sp_4096_mul_d_156(sp_digit* r, const sp_digit* a,
  17499. sp_digit b)
  17500. {
  17501. sp_int128 tb = b;
  17502. sp_int128 t = 0;
  17503. sp_digit t2;
  17504. sp_int128 p[4];
  17505. int i;
  17506. for (i = 0; i < 156; i += 4) {
  17507. p[0] = tb * a[i + 0];
  17508. p[1] = tb * a[i + 1];
  17509. p[2] = tb * a[i + 2];
  17510. p[3] = tb * a[i + 3];
  17511. t += p[0];
  17512. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  17513. t >>= 53;
  17514. r[i + 0] = (sp_digit)t2;
  17515. t += p[1];
  17516. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  17517. t >>= 53;
  17518. r[i + 1] = (sp_digit)t2;
  17519. t += p[2];
  17520. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  17521. t >>= 53;
  17522. r[i + 2] = (sp_digit)t2;
  17523. t += p[3];
  17524. t2 = (sp_digit)(t & 0x1fffffffffffffL);
  17525. t >>= 53;
  17526. r[i + 3] = (sp_digit)t2;
  17527. }
  17528. r[156] = (sp_digit)(t & 0x1fffffffffffffL);
  17529. }
  17530. #ifndef WOLFSSL_SP_SMALL
  17531. /* Conditionally add a and b using the mask m.
  17532. * m is -1 to add and 0 when not.
  17533. *
  17534. * r A single precision number representing conditional add result.
  17535. * a A single precision number to add with.
  17536. * b A single precision number to add.
  17537. * m Mask value to apply.
  17538. */
  17539. static void sp_4096_cond_add_78(sp_digit* r, const sp_digit* a,
  17540. const sp_digit* b, const sp_digit m)
  17541. {
  17542. int i;
  17543. for (i = 0; i < 72; i += 8) {
  17544. r[i + 0] = a[i + 0] + (b[i + 0] & m);
  17545. r[i + 1] = a[i + 1] + (b[i + 1] & m);
  17546. r[i + 2] = a[i + 2] + (b[i + 2] & m);
  17547. r[i + 3] = a[i + 3] + (b[i + 3] & m);
  17548. r[i + 4] = a[i + 4] + (b[i + 4] & m);
  17549. r[i + 5] = a[i + 5] + (b[i + 5] & m);
  17550. r[i + 6] = a[i + 6] + (b[i + 6] & m);
  17551. r[i + 7] = a[i + 7] + (b[i + 7] & m);
  17552. }
  17553. r[72] = a[72] + (b[72] & m);
  17554. r[73] = a[73] + (b[73] & m);
  17555. r[74] = a[74] + (b[74] & m);
  17556. r[75] = a[75] + (b[75] & m);
  17557. r[76] = a[76] + (b[76] & m);
  17558. r[77] = a[77] + (b[77] & m);
  17559. }
  17560. #endif /* !WOLFSSL_SP_SMALL */
  17561. SP_NOINLINE static void sp_4096_rshift_78(sp_digit* r, const sp_digit* a,
  17562. byte n)
  17563. {
  17564. int i;
  17565. for (i=0; i<72; i += 8) {
  17566. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (53 - n)) & 0x1fffffffffffffL);
  17567. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (53 - n)) & 0x1fffffffffffffL);
  17568. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (53 - n)) & 0x1fffffffffffffL);
  17569. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (53 - n)) & 0x1fffffffffffffL);
  17570. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (53 - n)) & 0x1fffffffffffffL);
  17571. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (53 - n)) & 0x1fffffffffffffL);
  17572. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (53 - n)) & 0x1fffffffffffffL);
  17573. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (53 - n)) & 0x1fffffffffffffL);
  17574. }
  17575. r[72] = (a[72] >> n) | ((a[73] << (53 - n)) & 0x1fffffffffffffL);
  17576. r[73] = (a[73] >> n) | ((a[74] << (53 - n)) & 0x1fffffffffffffL);
  17577. r[74] = (a[74] >> n) | ((a[75] << (53 - n)) & 0x1fffffffffffffL);
  17578. r[75] = (a[75] >> n) | ((a[76] << (53 - n)) & 0x1fffffffffffffL);
  17579. r[76] = (a[76] >> n) | ((a[77] << (53 - n)) & 0x1fffffffffffffL);
  17580. r[77] = a[77] >> n;
  17581. }
  17582. static WC_INLINE sp_digit sp_4096_div_word_78(sp_digit d1, sp_digit d0,
  17583. sp_digit div)
  17584. {
  17585. #ifdef SP_USE_DIVTI3
  17586. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  17587. return d / div;
  17588. #elif defined(__x86_64__) || defined(__i386__)
  17589. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  17590. sp_uint64 lo = (sp_uint64)d;
  17591. sp_digit hi = (sp_digit)(d >> 64);
  17592. __asm__ __volatile__ (
  17593. "idiv %2"
  17594. : "+a" (lo)
  17595. : "d" (hi), "r" (div)
  17596. : "cc"
  17597. );
  17598. return (sp_digit)lo;
  17599. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  17600. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  17601. sp_digit dv = (div >> 1) + 1;
  17602. sp_digit t1 = (sp_digit)(d >> 53);
  17603. sp_digit t0 = (sp_digit)(d & 0x1fffffffffffffL);
  17604. sp_digit t2;
  17605. sp_digit sign;
  17606. sp_digit r;
  17607. int i;
  17608. sp_int128 m;
  17609. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  17610. t1 -= dv & (0 - r);
  17611. for (i = 51; i >= 1; i--) {
  17612. t1 += t1 + (((sp_uint64)t0 >> 52) & 1);
  17613. t0 <<= 1;
  17614. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  17615. r += r + t2;
  17616. t1 -= dv & (0 - t2);
  17617. t1 += t2;
  17618. }
  17619. r += r + 1;
  17620. m = d - ((sp_int128)r * div);
  17621. r += (sp_digit)(m >> 53);
  17622. m = d - ((sp_int128)r * div);
  17623. r += (sp_digit)(m >> 106) - (sp_digit)(d >> 106);
  17624. m = d - ((sp_int128)r * div);
  17625. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  17626. m *= sign;
  17627. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  17628. r += sign * t2;
  17629. m = d - ((sp_int128)r * div);
  17630. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  17631. m *= sign;
  17632. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  17633. r += sign * t2;
  17634. return r;
  17635. #else
  17636. sp_int128 d = ((sp_int128)d1 << 53) + d0;
  17637. sp_digit r = 0;
  17638. sp_digit t;
  17639. sp_digit dv = (div >> 22) + 1;
  17640. t = (sp_digit)(d >> 44);
  17641. t = (t / dv) << 22;
  17642. r += t;
  17643. d -= (sp_int128)t * div;
  17644. t = (sp_digit)(d >> 13);
  17645. t = t / (dv << 9);
  17646. r += t;
  17647. d -= (sp_int128)t * div;
  17648. t = (sp_digit)d;
  17649. t = t / div;
  17650. r += t;
  17651. d -= (sp_int128)t * div;
  17652. return r;
  17653. #endif
  17654. }
  17655. static WC_INLINE sp_digit sp_4096_word_div_word_78(sp_digit d, sp_digit div)
  17656. {
  17657. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  17658. defined(SP_DIV_WORD_USE_DIV)
  17659. return d / div;
  17660. #else
  17661. return (sp_digit)((sp_uint64)(div - d) >> 63);
  17662. #endif
  17663. }
  17664. /* Divide d in a and put remainder into r (m*d + r = a)
  17665. * m is not calculated as it is not needed at this time.
  17666. *
  17667. * Full implementation.
  17668. *
  17669. * a Number to be divided.
  17670. * d Number to divide with.
  17671. * m Multiplier result.
  17672. * r Remainder from the division.
  17673. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  17674. */
  17675. static int sp_4096_div_78(const sp_digit* a, const sp_digit* d,
  17676. const sp_digit* m, sp_digit* r)
  17677. {
  17678. int i;
  17679. #ifndef WOLFSSL_SP_DIV_64
  17680. #endif
  17681. sp_digit dv;
  17682. sp_digit r1;
  17683. #ifdef WOLFSSL_SP_SMALL_STACK
  17684. sp_digit* t1 = NULL;
  17685. #else
  17686. sp_digit t1[4 * 78 + 3];
  17687. #endif
  17688. sp_digit* t2 = NULL;
  17689. sp_digit* sd = NULL;
  17690. int err = MP_OKAY;
  17691. (void)m;
  17692. #ifdef WOLFSSL_SP_SMALL_STACK
  17693. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 78 + 3), NULL,
  17694. DYNAMIC_TYPE_TMP_BUFFER);
  17695. if (t1 == NULL)
  17696. err = MEMORY_E;
  17697. #endif
  17698. (void)m;
  17699. if (err == MP_OKAY) {
  17700. t2 = t1 + 156 + 1;
  17701. sd = t2 + 78 + 1;
  17702. sp_4096_mul_d_78(sd, d, (sp_digit)1 << 38);
  17703. sp_4096_mul_d_156(t1, a, (sp_digit)1 << 38);
  17704. dv = sd[77];
  17705. t1[78 + 78] += t1[78 + 78 - 1] >> 53;
  17706. t1[78 + 78 - 1] &= 0x1fffffffffffffL;
  17707. for (i=78; i>=0; i--) {
  17708. r1 = sp_4096_div_word_78(t1[78 + i], t1[78 + i - 1], dv);
  17709. sp_4096_mul_d_78(t2, sd, r1);
  17710. (void)sp_4096_sub_78(&t1[i], &t1[i], t2);
  17711. sp_4096_norm_78(&t1[i]);
  17712. t1[78 + i] -= t2[78];
  17713. t1[78 + i] += t1[78 + i - 1] >> 53;
  17714. t1[78 + i - 1] &= 0x1fffffffffffffL;
  17715. r1 = sp_4096_div_word_78(-t1[78 + i], -t1[78 + i - 1], dv);
  17716. r1 -= t1[78 + i];
  17717. sp_4096_mul_d_78(t2, sd, r1);
  17718. (void)sp_4096_add_78(&t1[i], &t1[i], t2);
  17719. t1[78 + i] += t1[78 + i - 1] >> 53;
  17720. t1[78 + i - 1] &= 0x1fffffffffffffL;
  17721. }
  17722. t1[78 - 1] += t1[78 - 2] >> 53;
  17723. t1[78 - 2] &= 0x1fffffffffffffL;
  17724. r1 = sp_4096_word_div_word_78(t1[78 - 1], dv);
  17725. sp_4096_mul_d_78(t2, sd, r1);
  17726. sp_4096_sub_78(t1, t1, t2);
  17727. XMEMCPY(r, t1, sizeof(*r) * 156U);
  17728. for (i=0; i<77; i++) {
  17729. r[i+1] += r[i] >> 53;
  17730. r[i] &= 0x1fffffffffffffL;
  17731. }
  17732. sp_4096_cond_add_78(r, r, sd, r[77] >> 63);
  17733. sp_4096_norm_78(r);
  17734. sp_4096_rshift_78(r, r, 38);
  17735. }
  17736. #ifdef WOLFSSL_SP_SMALL_STACK
  17737. if (t1 != NULL)
  17738. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17739. #endif
  17740. return err;
  17741. }
  17742. /* Reduce a modulo m into r. (r = a mod m)
  17743. *
  17744. * r A single precision number that is the reduced result.
  17745. * a A single precision number that is to be reduced.
  17746. * m A single precision number that is the modulus to reduce with.
  17747. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  17748. */
  17749. static int sp_4096_mod_78(sp_digit* r, const sp_digit* a, const sp_digit* m)
  17750. {
  17751. return sp_4096_div_78(a, m, NULL, r);
  17752. }
  17753. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_HAVE_SP_DH)
  17754. #if (defined(WOLFSSL_HAVE_SP_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  17755. defined(WOLFSSL_HAVE_SP_DH)
  17756. /* Modular exponentiate a to the e mod m. (r = a^e mod m)
  17757. *
  17758. * r A single precision number that is the result of the operation.
  17759. * a A single precision number being exponentiated.
  17760. * e A single precision number that is the exponent.
  17761. * bits The number of bits in the exponent.
  17762. * m A single precision number that is the modulus.
  17763. * returns 0 on success.
  17764. * returns MEMORY_E on dynamic memory allocation failure.
  17765. * returns MP_VAL when base is even or exponent is 0.
  17766. */
  17767. static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e,
  17768. int bits, const sp_digit* m, int reduceA)
  17769. {
  17770. #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP)
  17771. #ifdef WOLFSSL_SP_SMALL_STACK
  17772. sp_digit* td = NULL;
  17773. #else
  17774. sp_digit td[3 * 156];
  17775. #endif
  17776. sp_digit* t[3] = {0, 0, 0};
  17777. sp_digit* norm = NULL;
  17778. sp_digit mp = 1;
  17779. sp_digit n;
  17780. int i;
  17781. int c;
  17782. byte y;
  17783. int err = MP_OKAY;
  17784. if (bits == 0) {
  17785. err = MP_VAL;
  17786. }
  17787. #ifdef WOLFSSL_SP_SMALL_STACK
  17788. if (err == MP_OKAY) {
  17789. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 78 * 2, NULL,
  17790. DYNAMIC_TYPE_TMP_BUFFER);
  17791. if (td == NULL)
  17792. err = MEMORY_E;
  17793. }
  17794. #endif
  17795. if (err == MP_OKAY) {
  17796. norm = td;
  17797. for (i=0; i<3; i++) {
  17798. t[i] = td + (i * 78 * 2);
  17799. XMEMSET(t[i], 0, sizeof(sp_digit) * 78U * 2U);
  17800. }
  17801. sp_4096_mont_setup(m, &mp);
  17802. sp_4096_mont_norm_78(norm, m);
  17803. if (reduceA != 0) {
  17804. err = sp_4096_mod_78(t[1], a, m);
  17805. }
  17806. else {
  17807. XMEMCPY(t[1], a, sizeof(sp_digit) * 78U);
  17808. }
  17809. }
  17810. if (err == MP_OKAY) {
  17811. sp_4096_mul_78(t[1], t[1], norm);
  17812. err = sp_4096_mod_78(t[1], t[1], m);
  17813. }
  17814. if (err == MP_OKAY) {
  17815. i = bits / 53;
  17816. c = bits % 53;
  17817. n = e[i--] << (53 - c);
  17818. for (; ; c--) {
  17819. if (c == 0) {
  17820. if (i == -1) {
  17821. break;
  17822. }
  17823. n = e[i--];
  17824. c = 53;
  17825. }
  17826. y = (int)((n >> 52) & 1);
  17827. n <<= 1;
  17828. sp_4096_mont_mul_78(t[y^1], t[0], t[1], m, mp);
  17829. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  17830. ((size_t)t[1] & addr_mask[y])),
  17831. sizeof(*t[2]) * 78 * 2);
  17832. sp_4096_mont_sqr_78(t[2], t[2], m, mp);
  17833. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  17834. ((size_t)t[1] & addr_mask[y])), t[2],
  17835. sizeof(*t[2]) * 78 * 2);
  17836. }
  17837. sp_4096_mont_reduce_78(t[0], m, mp);
  17838. n = sp_4096_cmp_78(t[0], m);
  17839. sp_4096_cond_sub_78(t[0], t[0], m, ~(n >> 63));
  17840. XMEMCPY(r, t[0], sizeof(*r) * 78 * 2);
  17841. }
  17842. #ifdef WOLFSSL_SP_SMALL_STACK
  17843. if (td != NULL)
  17844. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17845. #endif
  17846. return err;
  17847. #elif !defined(WC_NO_CACHE_RESISTANT)
  17848. #ifdef WOLFSSL_SP_SMALL_STACK
  17849. sp_digit* td = NULL;
  17850. #else
  17851. sp_digit td[3 * 156];
  17852. #endif
  17853. sp_digit* t[3] = {0, 0, 0};
  17854. sp_digit* norm = NULL;
  17855. sp_digit mp = 1;
  17856. sp_digit n;
  17857. int i;
  17858. int c;
  17859. byte y;
  17860. int err = MP_OKAY;
  17861. if (bits == 0) {
  17862. err = MP_VAL;
  17863. }
  17864. #ifdef WOLFSSL_SP_SMALL_STACK
  17865. if (err == MP_OKAY) {
  17866. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 78 * 2, NULL,
  17867. DYNAMIC_TYPE_TMP_BUFFER);
  17868. if (td == NULL)
  17869. err = MEMORY_E;
  17870. }
  17871. #endif
  17872. if (err == MP_OKAY) {
  17873. norm = td;
  17874. for (i=0; i<3; i++) {
  17875. t[i] = td + (i * 78 * 2);
  17876. }
  17877. sp_4096_mont_setup(m, &mp);
  17878. sp_4096_mont_norm_78(norm, m);
  17879. if (reduceA != 0) {
  17880. err = sp_4096_mod_78(t[1], a, m);
  17881. if (err == MP_OKAY) {
  17882. sp_4096_mul_78(t[1], t[1], norm);
  17883. err = sp_4096_mod_78(t[1], t[1], m);
  17884. }
  17885. }
  17886. else {
  17887. sp_4096_mul_78(t[1], a, norm);
  17888. err = sp_4096_mod_78(t[1], t[1], m);
  17889. }
  17890. }
  17891. if (err == MP_OKAY) {
  17892. i = bits / 53;
  17893. c = bits % 53;
  17894. n = e[i--] << (53 - c);
  17895. for (; ; c--) {
  17896. if (c == 0) {
  17897. if (i == -1) {
  17898. break;
  17899. }
  17900. n = e[i--];
  17901. c = 53;
  17902. }
  17903. y = (int)((n >> 52) & 1);
  17904. n <<= 1;
  17905. sp_4096_mont_mul_78(t[y^1], t[0], t[1], m, mp);
  17906. XMEMCPY(t[2], (void*)(((size_t)t[0] & addr_mask[y^1]) +
  17907. ((size_t)t[1] & addr_mask[y])),
  17908. sizeof(*t[2]) * 78 * 2);
  17909. sp_4096_mont_sqr_78(t[2], t[2], m, mp);
  17910. XMEMCPY((void*)(((size_t)t[0] & addr_mask[y^1]) +
  17911. ((size_t)t[1] & addr_mask[y])), t[2],
  17912. sizeof(*t[2]) * 78 * 2);
  17913. }
  17914. sp_4096_mont_reduce_78(t[0], m, mp);
  17915. n = sp_4096_cmp_78(t[0], m);
  17916. sp_4096_cond_sub_78(t[0], t[0], m, ~(n >> 63));
  17917. XMEMCPY(r, t[0], sizeof(*r) * 78 * 2);
  17918. }
  17919. #ifdef WOLFSSL_SP_SMALL_STACK
  17920. if (td != NULL)
  17921. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17922. #endif
  17923. return err;
  17924. #else
  17925. #ifdef WOLFSSL_SP_SMALL_STACK
  17926. sp_digit* td = NULL;
  17927. #else
  17928. sp_digit td[(16 * 156) + 156];
  17929. #endif
  17930. sp_digit* t[16];
  17931. sp_digit* rt = NULL;
  17932. sp_digit* norm = NULL;
  17933. sp_digit mp = 1;
  17934. sp_digit n;
  17935. int i;
  17936. int c;
  17937. byte y;
  17938. int err = MP_OKAY;
  17939. if (bits == 0) {
  17940. err = MP_VAL;
  17941. }
  17942. #ifdef WOLFSSL_SP_SMALL_STACK
  17943. if (err == MP_OKAY) {
  17944. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 156) + 156), NULL,
  17945. DYNAMIC_TYPE_TMP_BUFFER);
  17946. if (td == NULL)
  17947. err = MEMORY_E;
  17948. }
  17949. #endif
  17950. if (err == MP_OKAY) {
  17951. norm = td;
  17952. for (i=0; i<16; i++)
  17953. t[i] = td + i * 156;
  17954. rt = td + 2496;
  17955. sp_4096_mont_setup(m, &mp);
  17956. sp_4096_mont_norm_78(norm, m);
  17957. if (reduceA != 0) {
  17958. err = sp_4096_mod_78(t[1], a, m);
  17959. if (err == MP_OKAY) {
  17960. sp_4096_mul_78(t[1], t[1], norm);
  17961. err = sp_4096_mod_78(t[1], t[1], m);
  17962. }
  17963. }
  17964. else {
  17965. sp_4096_mul_78(t[1], a, norm);
  17966. err = sp_4096_mod_78(t[1], t[1], m);
  17967. }
  17968. }
  17969. if (err == MP_OKAY) {
  17970. sp_4096_mont_sqr_78(t[ 2], t[ 1], m, mp);
  17971. sp_4096_mont_mul_78(t[ 3], t[ 2], t[ 1], m, mp);
  17972. sp_4096_mont_sqr_78(t[ 4], t[ 2], m, mp);
  17973. sp_4096_mont_mul_78(t[ 5], t[ 3], t[ 2], m, mp);
  17974. sp_4096_mont_sqr_78(t[ 6], t[ 3], m, mp);
  17975. sp_4096_mont_mul_78(t[ 7], t[ 4], t[ 3], m, mp);
  17976. sp_4096_mont_sqr_78(t[ 8], t[ 4], m, mp);
  17977. sp_4096_mont_mul_78(t[ 9], t[ 5], t[ 4], m, mp);
  17978. sp_4096_mont_sqr_78(t[10], t[ 5], m, mp);
  17979. sp_4096_mont_mul_78(t[11], t[ 6], t[ 5], m, mp);
  17980. sp_4096_mont_sqr_78(t[12], t[ 6], m, mp);
  17981. sp_4096_mont_mul_78(t[13], t[ 7], t[ 6], m, mp);
  17982. sp_4096_mont_sqr_78(t[14], t[ 7], m, mp);
  17983. sp_4096_mont_mul_78(t[15], t[ 8], t[ 7], m, mp);
  17984. bits = ((bits + 3) / 4) * 4;
  17985. i = ((bits + 52) / 53) - 1;
  17986. c = bits % 53;
  17987. if (c == 0) {
  17988. c = 53;
  17989. }
  17990. if (i < 78) {
  17991. n = e[i--] << (64 - c);
  17992. }
  17993. else {
  17994. n = 0;
  17995. i--;
  17996. }
  17997. if (c < 4) {
  17998. n |= e[i--] << (11 - c);
  17999. c += 53;
  18000. }
  18001. y = (int)((n >> 60) & 0xf);
  18002. n <<= 4;
  18003. c -= 4;
  18004. XMEMCPY(rt, t[y], sizeof(sp_digit) * 156);
  18005. while ((i >= 0) || (c >= 4)) {
  18006. if (c >= 4) {
  18007. y = (byte)((n >> 60) & 0xf);
  18008. n <<= 4;
  18009. c -= 4;
  18010. }
  18011. else if (c == 0) {
  18012. n = e[i--] << 11;
  18013. y = (byte)((n >> 60) & 0xf);
  18014. n <<= 4;
  18015. c = 49;
  18016. }
  18017. else {
  18018. y = (byte)((n >> 60) & 0xf);
  18019. n = e[i--] << 11;
  18020. c = 4 - c;
  18021. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  18022. n <<= c;
  18023. c = 53 - c;
  18024. }
  18025. sp_4096_mont_sqr_78(rt, rt, m, mp);
  18026. sp_4096_mont_sqr_78(rt, rt, m, mp);
  18027. sp_4096_mont_sqr_78(rt, rt, m, mp);
  18028. sp_4096_mont_sqr_78(rt, rt, m, mp);
  18029. sp_4096_mont_mul_78(rt, rt, t[y], m, mp);
  18030. }
  18031. sp_4096_mont_reduce_78(rt, m, mp);
  18032. n = sp_4096_cmp_78(rt, m);
  18033. sp_4096_cond_sub_78(rt, rt, m, ~(n >> 63));
  18034. XMEMCPY(r, rt, sizeof(sp_digit) * 156);
  18035. }
  18036. #ifdef WOLFSSL_SP_SMALL_STACK
  18037. if (td != NULL)
  18038. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18039. #endif
  18040. return err;
  18041. #endif
  18042. }
  18043. #endif /* (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) || */
  18044. /* WOLFSSL_HAVE_SP_DH */
  18045. #endif /* (WOLFSSL_HAVE_SP_RSA && !WOLFSSL_RSA_PUBLIC_ONLY) || WOLFSSL_HAVE_SP_DH */
  18046. #ifdef WOLFSSL_HAVE_SP_RSA
  18047. /* RSA public key operation.
  18048. *
  18049. * in Array of bytes representing the number to exponentiate, base.
  18050. * inLen Number of bytes in base.
  18051. * em Public exponent.
  18052. * mm Modulus.
  18053. * out Buffer to hold big-endian bytes of exponentiation result.
  18054. * Must be at least 512 bytes long.
  18055. * outLen Number of bytes in result.
  18056. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  18057. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  18058. */
  18059. int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em,
  18060. const mp_int* mm, byte* out, word32* outLen)
  18061. {
  18062. #ifdef WOLFSSL_SP_SMALL
  18063. #ifdef WOLFSSL_SP_SMALL_STACK
  18064. sp_digit* a = NULL;
  18065. #else
  18066. sp_digit a[78 * 5];
  18067. #endif
  18068. sp_digit* m = NULL;
  18069. sp_digit* r = NULL;
  18070. sp_digit* norm = NULL;
  18071. sp_digit e[1] = {0};
  18072. sp_digit mp = 0;
  18073. int i;
  18074. int err = MP_OKAY;
  18075. if (*outLen < 512U) {
  18076. err = MP_TO_E;
  18077. }
  18078. if (err == MP_OKAY) {
  18079. if (mp_count_bits(em) > 53) {
  18080. err = MP_READ_E;
  18081. }
  18082. else if (inLen > 512U) {
  18083. err = MP_READ_E;
  18084. }
  18085. else if (mp_count_bits(mm) != 4096) {
  18086. err = MP_READ_E;
  18087. }
  18088. else if (mp_iseven(mm)) {
  18089. err = MP_VAL;
  18090. }
  18091. }
  18092. #ifdef WOLFSSL_SP_SMALL_STACK
  18093. if (err == MP_OKAY) {
  18094. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 5, NULL,
  18095. DYNAMIC_TYPE_RSA);
  18096. if (a == NULL)
  18097. err = MEMORY_E;
  18098. }
  18099. #endif
  18100. if (err == MP_OKAY) {
  18101. r = a + 78 * 2;
  18102. m = r + 78 * 2;
  18103. norm = r;
  18104. sp_4096_from_bin(a, 78, in, inLen);
  18105. #if DIGIT_BIT >= 53
  18106. e[0] = (sp_digit)em->dp[0];
  18107. #else
  18108. e[0] = (sp_digit)em->dp[0];
  18109. if (em->used > 1) {
  18110. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  18111. }
  18112. #endif
  18113. if (e[0] == 0) {
  18114. err = MP_EXPTMOD_E;
  18115. }
  18116. }
  18117. if (err == MP_OKAY) {
  18118. sp_4096_from_mp(m, 78, mm);
  18119. sp_4096_mont_setup(m, &mp);
  18120. sp_4096_mont_norm_78(norm, m);
  18121. }
  18122. if (err == MP_OKAY) {
  18123. sp_4096_mul_78(a, a, norm);
  18124. err = sp_4096_mod_78(a, a, m);
  18125. }
  18126. if (err == MP_OKAY) {
  18127. for (i=52; i>=0; i--) {
  18128. if ((e[0] >> i) != 0) {
  18129. break;
  18130. }
  18131. }
  18132. XMEMCPY(r, a, sizeof(sp_digit) * 78 * 2);
  18133. for (i--; i>=0; i--) {
  18134. sp_4096_mont_sqr_78(r, r, m, mp);
  18135. if (((e[0] >> i) & 1) == 1) {
  18136. sp_4096_mont_mul_78(r, r, a, m, mp);
  18137. }
  18138. }
  18139. sp_4096_mont_reduce_78(r, m, mp);
  18140. mp = sp_4096_cmp_78(r, m);
  18141. sp_4096_cond_sub_78(r, r, m, ~(mp >> 63));
  18142. sp_4096_to_bin_78(r, out);
  18143. *outLen = 512;
  18144. }
  18145. #ifdef WOLFSSL_SP_SMALL_STACK
  18146. if (a != NULL)
  18147. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  18148. #endif
  18149. return err;
  18150. #else
  18151. #ifdef WOLFSSL_SP_SMALL_STACK
  18152. sp_digit* d = NULL;
  18153. #else
  18154. sp_digit d[78 * 5];
  18155. #endif
  18156. sp_digit* a = NULL;
  18157. sp_digit* m = NULL;
  18158. sp_digit* r = NULL;
  18159. sp_digit e[1] = {0};
  18160. int err = MP_OKAY;
  18161. if (*outLen < 512U) {
  18162. err = MP_TO_E;
  18163. }
  18164. if (err == MP_OKAY) {
  18165. if (mp_count_bits(em) > 53) {
  18166. err = MP_READ_E;
  18167. }
  18168. else if (inLen > 512U) {
  18169. err = MP_READ_E;
  18170. }
  18171. else if (mp_count_bits(mm) != 4096) {
  18172. err = MP_READ_E;
  18173. }
  18174. else if (mp_iseven(mm)) {
  18175. err = MP_VAL;
  18176. }
  18177. }
  18178. #ifdef WOLFSSL_SP_SMALL_STACK
  18179. if (err == MP_OKAY) {
  18180. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 5, NULL,
  18181. DYNAMIC_TYPE_RSA);
  18182. if (d == NULL)
  18183. err = MEMORY_E;
  18184. }
  18185. #endif
  18186. if (err == MP_OKAY) {
  18187. a = d;
  18188. r = a + 78 * 2;
  18189. m = r + 78 * 2;
  18190. sp_4096_from_bin(a, 78, in, inLen);
  18191. #if DIGIT_BIT >= 53
  18192. e[0] = (sp_digit)em->dp[0];
  18193. #else
  18194. e[0] = (sp_digit)em->dp[0];
  18195. if (em->used > 1) {
  18196. e[0] |= ((sp_digit)em->dp[1]) << DIGIT_BIT;
  18197. }
  18198. #endif
  18199. if (e[0] == 0) {
  18200. err = MP_EXPTMOD_E;
  18201. }
  18202. }
  18203. if (err == MP_OKAY) {
  18204. sp_4096_from_mp(m, 78, mm);
  18205. if (e[0] == 0x3) {
  18206. sp_4096_sqr_78(r, a);
  18207. err = sp_4096_mod_78(r, r, m);
  18208. if (err == MP_OKAY) {
  18209. sp_4096_mul_78(r, a, r);
  18210. err = sp_4096_mod_78(r, r, m);
  18211. }
  18212. }
  18213. else {
  18214. sp_digit* norm = r;
  18215. int i;
  18216. sp_digit mp;
  18217. sp_4096_mont_setup(m, &mp);
  18218. sp_4096_mont_norm_78(norm, m);
  18219. sp_4096_mul_78(a, a, norm);
  18220. err = sp_4096_mod_78(a, a, m);
  18221. if (err == MP_OKAY) {
  18222. for (i=52; i>=0; i--) {
  18223. if ((e[0] >> i) != 0) {
  18224. break;
  18225. }
  18226. }
  18227. XMEMCPY(r, a, sizeof(sp_digit) * 156U);
  18228. for (i--; i>=0; i--) {
  18229. sp_4096_mont_sqr_78(r, r, m, mp);
  18230. if (((e[0] >> i) & 1) == 1) {
  18231. sp_4096_mont_mul_78(r, r, a, m, mp);
  18232. }
  18233. }
  18234. sp_4096_mont_reduce_78(r, m, mp);
  18235. mp = sp_4096_cmp_78(r, m);
  18236. sp_4096_cond_sub_78(r, r, m, ~(mp >> 63));
  18237. }
  18238. }
  18239. }
  18240. if (err == MP_OKAY) {
  18241. sp_4096_to_bin_78(r, out);
  18242. *outLen = 512;
  18243. }
  18244. #ifdef WOLFSSL_SP_SMALL_STACK
  18245. if (d != NULL)
  18246. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  18247. #endif
  18248. return err;
  18249. #endif /* WOLFSSL_SP_SMALL */
  18250. }
  18251. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18252. #if !defined(SP_RSA_PRIVATE_EXP_D) && !defined(RSA_LOW_MEM)
  18253. #endif /* !SP_RSA_PRIVATE_EXP_D & !RSA_LOW_MEM */
  18254. /* RSA private key operation.
  18255. *
  18256. * in Array of bytes representing the number to exponentiate, base.
  18257. * inLen Number of bytes in base.
  18258. * dm Private exponent.
  18259. * pm First prime.
  18260. * qm Second prime.
  18261. * dpm First prime's CRT exponent.
  18262. * dqm Second prime's CRT exponent.
  18263. * qim Inverse of second prime mod p.
  18264. * mm Modulus.
  18265. * out Buffer to hold big-endian bytes of exponentiation result.
  18266. * Must be at least 512 bytes long.
  18267. * outLen Number of bytes in result.
  18268. * returns 0 on success, MP_TO_E when the outLen is too small, MP_READ_E when
  18269. * an array is too long and MEMORY_E when dynamic memory allocation fails.
  18270. */
  18271. int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm,
  18272. const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm,
  18273. const mp_int* qim, const mp_int* mm, byte* out, word32* outLen)
  18274. {
  18275. #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM)
  18276. #if defined(WOLFSSL_SP_SMALL)
  18277. #ifdef WOLFSSL_SP_SMALL_STACK
  18278. sp_digit* d = NULL;
  18279. #else
  18280. sp_digit d[78 * 4];
  18281. #endif
  18282. sp_digit* a = NULL;
  18283. sp_digit* m = NULL;
  18284. sp_digit* r = NULL;
  18285. int err = MP_OKAY;
  18286. (void)pm;
  18287. (void)qm;
  18288. (void)dpm;
  18289. (void)dqm;
  18290. (void)qim;
  18291. if (*outLen < 512U) {
  18292. err = MP_TO_E;
  18293. }
  18294. if (err == MP_OKAY) {
  18295. if (mp_count_bits(dm) > 4096) {
  18296. err = MP_READ_E;
  18297. }
  18298. else if (inLen > 512) {
  18299. err = MP_READ_E;
  18300. }
  18301. else if (mp_count_bits(mm) != 4096) {
  18302. err = MP_READ_E;
  18303. }
  18304. else if (mp_iseven(mm)) {
  18305. err = MP_VAL;
  18306. }
  18307. }
  18308. #ifdef WOLFSSL_SP_SMALL_STACK
  18309. if (err == MP_OKAY) {
  18310. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL,
  18311. DYNAMIC_TYPE_RSA);
  18312. if (d == NULL)
  18313. err = MEMORY_E;
  18314. }
  18315. #endif
  18316. if (err == MP_OKAY) {
  18317. a = d + 78;
  18318. m = a + 156;
  18319. r = a;
  18320. sp_4096_from_bin(a, 78, in, inLen);
  18321. sp_4096_from_mp(d, 78, dm);
  18322. sp_4096_from_mp(m, 78, mm);
  18323. err = sp_4096_mod_exp_78(r, a, d, 4096, m, 0);
  18324. }
  18325. if (err == MP_OKAY) {
  18326. sp_4096_to_bin_78(r, out);
  18327. *outLen = 512;
  18328. }
  18329. #ifdef WOLFSSL_SP_SMALL_STACK
  18330. if (d != NULL)
  18331. #endif
  18332. {
  18333. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  18334. if (a != NULL)
  18335. ForceZero(a, sizeof(sp_digit) * 78);
  18336. #ifdef WOLFSSL_SP_SMALL_STACK
  18337. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  18338. #endif
  18339. }
  18340. return err;
  18341. #else
  18342. #ifdef WOLFSSL_SP_SMALL_STACK
  18343. sp_digit* d = NULL;
  18344. #else
  18345. sp_digit d[78 * 4];
  18346. #endif
  18347. sp_digit* a = NULL;
  18348. sp_digit* m = NULL;
  18349. sp_digit* r = NULL;
  18350. int err = MP_OKAY;
  18351. (void)pm;
  18352. (void)qm;
  18353. (void)dpm;
  18354. (void)dqm;
  18355. (void)qim;
  18356. if (*outLen < 512U) {
  18357. err = MP_TO_E;
  18358. }
  18359. if (err == MP_OKAY) {
  18360. if (mp_count_bits(dm) > 4096) {
  18361. err = MP_READ_E;
  18362. }
  18363. else if (inLen > 512U) {
  18364. err = MP_READ_E;
  18365. }
  18366. else if (mp_count_bits(mm) != 4096) {
  18367. err = MP_READ_E;
  18368. }
  18369. else if (mp_iseven(mm)) {
  18370. err = MP_VAL;
  18371. }
  18372. }
  18373. #ifdef WOLFSSL_SP_SMALL_STACK
  18374. if (err == MP_OKAY) {
  18375. d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL,
  18376. DYNAMIC_TYPE_RSA);
  18377. if (d == NULL)
  18378. err = MEMORY_E;
  18379. }
  18380. #endif
  18381. if (err == MP_OKAY) {
  18382. a = d + 78;
  18383. m = a + 156;
  18384. r = a;
  18385. sp_4096_from_bin(a, 78, in, inLen);
  18386. sp_4096_from_mp(d, 78, dm);
  18387. sp_4096_from_mp(m, 78, mm);
  18388. err = sp_4096_mod_exp_78(r, a, d, 4096, m, 0);
  18389. }
  18390. if (err == MP_OKAY) {
  18391. sp_4096_to_bin_78(r, out);
  18392. *outLen = 512;
  18393. }
  18394. #ifdef WOLFSSL_SP_SMALL_STACK
  18395. if (d != NULL)
  18396. #endif
  18397. {
  18398. /* only "a" and "r" are sensitive and need zeroized (same pointer) */
  18399. if (a != NULL)
  18400. ForceZero(a, sizeof(sp_digit) * 78);
  18401. #ifdef WOLFSSL_SP_SMALL_STACK
  18402. XFREE(d, NULL, DYNAMIC_TYPE_RSA);
  18403. #endif
  18404. }
  18405. return err;
  18406. #endif /* WOLFSSL_SP_SMALL */
  18407. #else
  18408. #if defined(WOLFSSL_SP_SMALL)
  18409. #ifdef WOLFSSL_SP_SMALL_STACK
  18410. sp_digit* a = NULL;
  18411. #else
  18412. sp_digit a[39 * 8];
  18413. #endif
  18414. sp_digit* p = NULL;
  18415. sp_digit* dp = NULL;
  18416. sp_digit* dq = NULL;
  18417. sp_digit* qi = NULL;
  18418. sp_digit* tmpa = NULL;
  18419. sp_digit* tmpb = NULL;
  18420. sp_digit* r = NULL;
  18421. int err = MP_OKAY;
  18422. (void)dm;
  18423. (void)mm;
  18424. if (*outLen < 512U) {
  18425. err = MP_TO_E;
  18426. }
  18427. if (err == MP_OKAY) {
  18428. if (inLen > 512) {
  18429. err = MP_READ_E;
  18430. }
  18431. else if (mp_count_bits(mm) != 4096) {
  18432. err = MP_READ_E;
  18433. }
  18434. else if (mp_iseven(mm)) {
  18435. err = MP_VAL;
  18436. }
  18437. else if (mp_iseven(pm)) {
  18438. err = MP_VAL;
  18439. }
  18440. else if (mp_iseven(qm)) {
  18441. err = MP_VAL;
  18442. }
  18443. }
  18444. #ifdef WOLFSSL_SP_SMALL_STACK
  18445. if (err == MP_OKAY) {
  18446. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 8, NULL,
  18447. DYNAMIC_TYPE_RSA);
  18448. if (a == NULL)
  18449. err = MEMORY_E;
  18450. }
  18451. #endif
  18452. if (err == MP_OKAY) {
  18453. p = a + 78;
  18454. qi = dq = dp = p + 39;
  18455. tmpa = qi + 39;
  18456. tmpb = tmpa + 78;
  18457. r = a;
  18458. sp_4096_from_bin(a, 78, in, inLen);
  18459. sp_4096_from_mp(p, 39, pm);
  18460. sp_4096_from_mp(dp, 39, dpm);
  18461. err = sp_4096_mod_exp_39(tmpa, a, dp, 2048, p, 1);
  18462. }
  18463. if (err == MP_OKAY) {
  18464. sp_4096_from_mp(p, 39, qm);
  18465. sp_4096_from_mp(dq, 39, dqm);
  18466. err = sp_4096_mod_exp_39(tmpb, a, dq, 2048, p, 1);
  18467. }
  18468. if (err == MP_OKAY) {
  18469. sp_4096_from_mp(p, 39, pm);
  18470. (void)sp_4096_sub_39(tmpa, tmpa, tmpb);
  18471. sp_4096_norm_39(tmpa);
  18472. sp_4096_cond_add_39(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[38] >> 63));
  18473. sp_4096_cond_add_39(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[38] >> 63));
  18474. sp_4096_norm_39(tmpa);
  18475. sp_4096_from_mp(qi, 39, qim);
  18476. sp_4096_mul_39(tmpa, tmpa, qi);
  18477. err = sp_4096_mod_39(tmpa, tmpa, p);
  18478. }
  18479. if (err == MP_OKAY) {
  18480. sp_4096_from_mp(p, 39, qm);
  18481. sp_4096_mul_39(tmpa, p, tmpa);
  18482. (void)sp_4096_add_78(r, tmpb, tmpa);
  18483. sp_4096_norm_78(r);
  18484. sp_4096_to_bin_78(r, out);
  18485. *outLen = 512;
  18486. }
  18487. #ifdef WOLFSSL_SP_SMALL_STACK
  18488. if (a != NULL)
  18489. #endif
  18490. {
  18491. ForceZero(a, sizeof(sp_digit) * 39 * 8);
  18492. #ifdef WOLFSSL_SP_SMALL_STACK
  18493. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  18494. #endif
  18495. }
  18496. return err;
  18497. #else
  18498. #ifdef WOLFSSL_SP_SMALL_STACK
  18499. sp_digit* a = NULL;
  18500. #else
  18501. sp_digit a[39 * 13];
  18502. #endif
  18503. sp_digit* p = NULL;
  18504. sp_digit* q = NULL;
  18505. sp_digit* dp = NULL;
  18506. sp_digit* dq = NULL;
  18507. sp_digit* qi = NULL;
  18508. sp_digit* tmpa = NULL;
  18509. sp_digit* tmpb = NULL;
  18510. sp_digit* r = NULL;
  18511. int err = MP_OKAY;
  18512. (void)dm;
  18513. (void)mm;
  18514. if (*outLen < 512U) {
  18515. err = MP_TO_E;
  18516. }
  18517. if (err == MP_OKAY) {
  18518. if (inLen > 512U) {
  18519. err = MP_READ_E;
  18520. }
  18521. else if (mp_count_bits(mm) != 4096) {
  18522. err = MP_READ_E;
  18523. }
  18524. else if (mp_iseven(mm)) {
  18525. err = MP_VAL;
  18526. }
  18527. else if (mp_iseven(pm)) {
  18528. err = MP_VAL;
  18529. }
  18530. else if (mp_iseven(qm)) {
  18531. err = MP_VAL;
  18532. }
  18533. }
  18534. #ifdef WOLFSSL_SP_SMALL_STACK
  18535. if (err == MP_OKAY) {
  18536. a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 13, NULL,
  18537. DYNAMIC_TYPE_RSA);
  18538. if (a == NULL)
  18539. err = MEMORY_E;
  18540. }
  18541. #endif
  18542. if (err == MP_OKAY) {
  18543. p = a + 78 * 2;
  18544. q = p + 39;
  18545. dp = q + 39;
  18546. dq = dp + 39;
  18547. qi = dq + 39;
  18548. tmpa = qi + 39;
  18549. tmpb = tmpa + 78;
  18550. r = a;
  18551. sp_4096_from_bin(a, 78, in, inLen);
  18552. sp_4096_from_mp(p, 39, pm);
  18553. sp_4096_from_mp(q, 39, qm);
  18554. sp_4096_from_mp(dp, 39, dpm);
  18555. sp_4096_from_mp(dq, 39, dqm);
  18556. sp_4096_from_mp(qi, 39, qim);
  18557. err = sp_4096_mod_exp_39(tmpa, a, dp, 2048, p, 1);
  18558. }
  18559. if (err == MP_OKAY) {
  18560. err = sp_4096_mod_exp_39(tmpb, a, dq, 2048, q, 1);
  18561. }
  18562. if (err == MP_OKAY) {
  18563. (void)sp_4096_sub_39(tmpa, tmpa, tmpb);
  18564. sp_4096_norm_39(tmpa);
  18565. sp_4096_cond_add_39(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[38] >> 63));
  18566. sp_4096_cond_add_39(tmpa, tmpa, p, 0 - ((sp_int_digit)tmpa[38] >> 63));
  18567. sp_4096_norm_39(tmpa);
  18568. sp_4096_mul_39(tmpa, tmpa, qi);
  18569. err = sp_4096_mod_39(tmpa, tmpa, p);
  18570. }
  18571. if (err == MP_OKAY) {
  18572. sp_4096_mul_39(tmpa, tmpa, q);
  18573. (void)sp_4096_add_78(r, tmpb, tmpa);
  18574. sp_4096_norm_78(r);
  18575. sp_4096_to_bin_78(r, out);
  18576. *outLen = 512;
  18577. }
  18578. #ifdef WOLFSSL_SP_SMALL_STACK
  18579. if (a != NULL)
  18580. #endif
  18581. {
  18582. ForceZero(a, sizeof(sp_digit) * 39 * 13);
  18583. #ifdef WOLFSSL_SP_SMALL_STACK
  18584. XFREE(a, NULL, DYNAMIC_TYPE_RSA);
  18585. #endif
  18586. }
  18587. return err;
  18588. #endif /* WOLFSSL_SP_SMALL */
  18589. #endif /* SP_RSA_PRIVATE_EXP_D || RSA_LOW_MEM */
  18590. }
  18591. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  18592. #endif /* WOLFSSL_HAVE_SP_RSA */
  18593. #if defined(WOLFSSL_HAVE_SP_DH) || (defined(WOLFSSL_HAVE_SP_RSA) && \
  18594. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  18595. /* Convert an array of sp_digit to an mp_int.
  18596. *
  18597. * a A single precision integer.
  18598. * r A multi-precision integer.
  18599. */
  18600. static int sp_4096_to_mp(const sp_digit* a, mp_int* r)
  18601. {
  18602. int err;
  18603. err = mp_grow(r, (4096 + DIGIT_BIT - 1) / DIGIT_BIT);
  18604. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  18605. #if DIGIT_BIT == 53
  18606. XMEMCPY(r->dp, a, sizeof(sp_digit) * 78);
  18607. r->used = 78;
  18608. mp_clamp(r);
  18609. #elif DIGIT_BIT < 53
  18610. int i;
  18611. int j = 0;
  18612. int s = 0;
  18613. r->dp[0] = 0;
  18614. for (i = 0; i < 78; i++) {
  18615. r->dp[j] |= (mp_digit)(a[i] << s);
  18616. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  18617. s = DIGIT_BIT - s;
  18618. r->dp[++j] = (mp_digit)(a[i] >> s);
  18619. while (s + DIGIT_BIT <= 53) {
  18620. s += DIGIT_BIT;
  18621. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  18622. if (s == SP_WORD_SIZE) {
  18623. r->dp[j] = 0;
  18624. }
  18625. else {
  18626. r->dp[j] = (mp_digit)(a[i] >> s);
  18627. }
  18628. }
  18629. s = 53 - s;
  18630. }
  18631. r->used = (4096 + DIGIT_BIT - 1) / DIGIT_BIT;
  18632. mp_clamp(r);
  18633. #else
  18634. int i;
  18635. int j = 0;
  18636. int s = 0;
  18637. r->dp[0] = 0;
  18638. for (i = 0; i < 78; i++) {
  18639. r->dp[j] |= ((mp_digit)a[i]) << s;
  18640. if (s + 53 >= DIGIT_BIT) {
  18641. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  18642. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  18643. #endif
  18644. s = DIGIT_BIT - s;
  18645. r->dp[++j] = a[i] >> s;
  18646. s = 53 - s;
  18647. }
  18648. else {
  18649. s += 53;
  18650. }
  18651. }
  18652. r->used = (4096 + DIGIT_BIT - 1) / DIGIT_BIT;
  18653. mp_clamp(r);
  18654. #endif
  18655. }
  18656. return err;
  18657. }
  18658. /* Perform the modular exponentiation for Diffie-Hellman.
  18659. *
  18660. * base Base. MP integer.
  18661. * exp Exponent. MP integer.
  18662. * mod Modulus. MP integer.
  18663. * res Result. MP integer.
  18664. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  18665. * and MEMORY_E if memory allocation fails.
  18666. */
  18667. int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod,
  18668. mp_int* res)
  18669. {
  18670. #ifdef WOLFSSL_SP_SMALL
  18671. int err = MP_OKAY;
  18672. #ifdef WOLFSSL_SP_SMALL_STACK
  18673. sp_digit* b = NULL;
  18674. #else
  18675. sp_digit b[78 * 4];
  18676. #endif
  18677. sp_digit* e = NULL;
  18678. sp_digit* m = NULL;
  18679. sp_digit* r = NULL;
  18680. int expBits = mp_count_bits(exp);
  18681. if (mp_count_bits(base) > 4096) {
  18682. err = MP_READ_E;
  18683. }
  18684. else if (expBits > 4096) {
  18685. err = MP_READ_E;
  18686. }
  18687. else if (mp_count_bits(mod) != 4096) {
  18688. err = MP_READ_E;
  18689. }
  18690. else if (mp_iseven(mod)) {
  18691. err = MP_VAL;
  18692. }
  18693. #ifdef WOLFSSL_SP_SMALL_STACK
  18694. if (err == MP_OKAY) {
  18695. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL,
  18696. DYNAMIC_TYPE_DH);
  18697. if (b == NULL)
  18698. err = MEMORY_E;
  18699. }
  18700. #endif
  18701. if (err == MP_OKAY) {
  18702. e = b + 78 * 2;
  18703. m = e + 78;
  18704. r = b;
  18705. sp_4096_from_mp(b, 78, base);
  18706. sp_4096_from_mp(e, 78, exp);
  18707. sp_4096_from_mp(m, 78, mod);
  18708. err = sp_4096_mod_exp_78(r, b, e, mp_count_bits(exp), m, 0);
  18709. }
  18710. if (err == MP_OKAY) {
  18711. err = sp_4096_to_mp(r, res);
  18712. }
  18713. #ifdef WOLFSSL_SP_SMALL_STACK
  18714. if (b != NULL)
  18715. #endif
  18716. {
  18717. /* only "e" is sensitive and needs zeroized */
  18718. if (e != NULL)
  18719. ForceZero(e, sizeof(sp_digit) * 78U);
  18720. #ifdef WOLFSSL_SP_SMALL_STACK
  18721. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  18722. #endif
  18723. }
  18724. return err;
  18725. #else
  18726. #ifdef WOLFSSL_SP_SMALL_STACK
  18727. sp_digit* b = NULL;
  18728. #else
  18729. sp_digit b[78 * 4];
  18730. #endif
  18731. sp_digit* e = NULL;
  18732. sp_digit* m = NULL;
  18733. sp_digit* r = NULL;
  18734. int err = MP_OKAY;
  18735. int expBits = mp_count_bits(exp);
  18736. if (mp_count_bits(base) > 4096) {
  18737. err = MP_READ_E;
  18738. }
  18739. else if (expBits > 4096) {
  18740. err = MP_READ_E;
  18741. }
  18742. else if (mp_count_bits(mod) != 4096) {
  18743. err = MP_READ_E;
  18744. }
  18745. else if (mp_iseven(mod)) {
  18746. err = MP_VAL;
  18747. }
  18748. #ifdef WOLFSSL_SP_SMALL_STACK
  18749. if (err == MP_OKAY) {
  18750. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL, DYNAMIC_TYPE_DH);
  18751. if (b == NULL)
  18752. err = MEMORY_E;
  18753. }
  18754. #endif
  18755. if (err == MP_OKAY) {
  18756. e = b + 78 * 2;
  18757. m = e + 78;
  18758. r = b;
  18759. sp_4096_from_mp(b, 78, base);
  18760. sp_4096_from_mp(e, 78, exp);
  18761. sp_4096_from_mp(m, 78, mod);
  18762. err = sp_4096_mod_exp_78(r, b, e, expBits, m, 0);
  18763. }
  18764. if (err == MP_OKAY) {
  18765. err = sp_4096_to_mp(r, res);
  18766. }
  18767. #ifdef WOLFSSL_SP_SMALL_STACK
  18768. if (b != NULL)
  18769. #endif
  18770. {
  18771. /* only "e" is sensitive and needs zeroized */
  18772. if (e != NULL)
  18773. ForceZero(e, sizeof(sp_digit) * 78U);
  18774. #ifdef WOLFSSL_SP_SMALL_STACK
  18775. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  18776. #endif
  18777. }
  18778. return err;
  18779. #endif
  18780. }
  18781. #ifdef WOLFSSL_HAVE_SP_DH
  18782. #ifdef HAVE_FFDHE_4096
  18783. SP_NOINLINE static void sp_4096_lshift_78(sp_digit* r, const sp_digit* a,
  18784. byte n)
  18785. {
  18786. sp_int_digit s;
  18787. sp_int_digit t;
  18788. s = (sp_int_digit)a[77];
  18789. r[78] = s >> (53U - n);
  18790. s = (sp_int_digit)(a[77]); t = (sp_int_digit)(a[76]);
  18791. r[77] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18792. s = (sp_int_digit)(a[76]); t = (sp_int_digit)(a[75]);
  18793. r[76] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18794. s = (sp_int_digit)(a[75]); t = (sp_int_digit)(a[74]);
  18795. r[75] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18796. s = (sp_int_digit)(a[74]); t = (sp_int_digit)(a[73]);
  18797. r[74] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18798. s = (sp_int_digit)(a[73]); t = (sp_int_digit)(a[72]);
  18799. r[73] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18800. s = (sp_int_digit)(a[72]); t = (sp_int_digit)(a[71]);
  18801. r[72] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18802. s = (sp_int_digit)(a[71]); t = (sp_int_digit)(a[70]);
  18803. r[71] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18804. s = (sp_int_digit)(a[70]); t = (sp_int_digit)(a[69]);
  18805. r[70] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18806. s = (sp_int_digit)(a[69]); t = (sp_int_digit)(a[68]);
  18807. r[69] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18808. s = (sp_int_digit)(a[68]); t = (sp_int_digit)(a[67]);
  18809. r[68] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18810. s = (sp_int_digit)(a[67]); t = (sp_int_digit)(a[66]);
  18811. r[67] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18812. s = (sp_int_digit)(a[66]); t = (sp_int_digit)(a[65]);
  18813. r[66] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18814. s = (sp_int_digit)(a[65]); t = (sp_int_digit)(a[64]);
  18815. r[65] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18816. s = (sp_int_digit)(a[64]); t = (sp_int_digit)(a[63]);
  18817. r[64] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18818. s = (sp_int_digit)(a[63]); t = (sp_int_digit)(a[62]);
  18819. r[63] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18820. s = (sp_int_digit)(a[62]); t = (sp_int_digit)(a[61]);
  18821. r[62] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18822. s = (sp_int_digit)(a[61]); t = (sp_int_digit)(a[60]);
  18823. r[61] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18824. s = (sp_int_digit)(a[60]); t = (sp_int_digit)(a[59]);
  18825. r[60] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18826. s = (sp_int_digit)(a[59]); t = (sp_int_digit)(a[58]);
  18827. r[59] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18828. s = (sp_int_digit)(a[58]); t = (sp_int_digit)(a[57]);
  18829. r[58] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18830. s = (sp_int_digit)(a[57]); t = (sp_int_digit)(a[56]);
  18831. r[57] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18832. s = (sp_int_digit)(a[56]); t = (sp_int_digit)(a[55]);
  18833. r[56] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18834. s = (sp_int_digit)(a[55]); t = (sp_int_digit)(a[54]);
  18835. r[55] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18836. s = (sp_int_digit)(a[54]); t = (sp_int_digit)(a[53]);
  18837. r[54] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18838. s = (sp_int_digit)(a[53]); t = (sp_int_digit)(a[52]);
  18839. r[53] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18840. s = (sp_int_digit)(a[52]); t = (sp_int_digit)(a[51]);
  18841. r[52] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18842. s = (sp_int_digit)(a[51]); t = (sp_int_digit)(a[50]);
  18843. r[51] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18844. s = (sp_int_digit)(a[50]); t = (sp_int_digit)(a[49]);
  18845. r[50] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18846. s = (sp_int_digit)(a[49]); t = (sp_int_digit)(a[48]);
  18847. r[49] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18848. s = (sp_int_digit)(a[48]); t = (sp_int_digit)(a[47]);
  18849. r[48] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18850. s = (sp_int_digit)(a[47]); t = (sp_int_digit)(a[46]);
  18851. r[47] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18852. s = (sp_int_digit)(a[46]); t = (sp_int_digit)(a[45]);
  18853. r[46] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18854. s = (sp_int_digit)(a[45]); t = (sp_int_digit)(a[44]);
  18855. r[45] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18856. s = (sp_int_digit)(a[44]); t = (sp_int_digit)(a[43]);
  18857. r[44] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18858. s = (sp_int_digit)(a[43]); t = (sp_int_digit)(a[42]);
  18859. r[43] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18860. s = (sp_int_digit)(a[42]); t = (sp_int_digit)(a[41]);
  18861. r[42] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18862. s = (sp_int_digit)(a[41]); t = (sp_int_digit)(a[40]);
  18863. r[41] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18864. s = (sp_int_digit)(a[40]); t = (sp_int_digit)(a[39]);
  18865. r[40] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18866. s = (sp_int_digit)(a[39]); t = (sp_int_digit)(a[38]);
  18867. r[39] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18868. s = (sp_int_digit)(a[38]); t = (sp_int_digit)(a[37]);
  18869. r[38] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18870. s = (sp_int_digit)(a[37]); t = (sp_int_digit)(a[36]);
  18871. r[37] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18872. s = (sp_int_digit)(a[36]); t = (sp_int_digit)(a[35]);
  18873. r[36] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18874. s = (sp_int_digit)(a[35]); t = (sp_int_digit)(a[34]);
  18875. r[35] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18876. s = (sp_int_digit)(a[34]); t = (sp_int_digit)(a[33]);
  18877. r[34] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18878. s = (sp_int_digit)(a[33]); t = (sp_int_digit)(a[32]);
  18879. r[33] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18880. s = (sp_int_digit)(a[32]); t = (sp_int_digit)(a[31]);
  18881. r[32] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18882. s = (sp_int_digit)(a[31]); t = (sp_int_digit)(a[30]);
  18883. r[31] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18884. s = (sp_int_digit)(a[30]); t = (sp_int_digit)(a[29]);
  18885. r[30] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18886. s = (sp_int_digit)(a[29]); t = (sp_int_digit)(a[28]);
  18887. r[29] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18888. s = (sp_int_digit)(a[28]); t = (sp_int_digit)(a[27]);
  18889. r[28] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18890. s = (sp_int_digit)(a[27]); t = (sp_int_digit)(a[26]);
  18891. r[27] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18892. s = (sp_int_digit)(a[26]); t = (sp_int_digit)(a[25]);
  18893. r[26] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18894. s = (sp_int_digit)(a[25]); t = (sp_int_digit)(a[24]);
  18895. r[25] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18896. s = (sp_int_digit)(a[24]); t = (sp_int_digit)(a[23]);
  18897. r[24] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18898. s = (sp_int_digit)(a[23]); t = (sp_int_digit)(a[22]);
  18899. r[23] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18900. s = (sp_int_digit)(a[22]); t = (sp_int_digit)(a[21]);
  18901. r[22] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18902. s = (sp_int_digit)(a[21]); t = (sp_int_digit)(a[20]);
  18903. r[21] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18904. s = (sp_int_digit)(a[20]); t = (sp_int_digit)(a[19]);
  18905. r[20] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18906. s = (sp_int_digit)(a[19]); t = (sp_int_digit)(a[18]);
  18907. r[19] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18908. s = (sp_int_digit)(a[18]); t = (sp_int_digit)(a[17]);
  18909. r[18] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18910. s = (sp_int_digit)(a[17]); t = (sp_int_digit)(a[16]);
  18911. r[17] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18912. s = (sp_int_digit)(a[16]); t = (sp_int_digit)(a[15]);
  18913. r[16] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18914. s = (sp_int_digit)(a[15]); t = (sp_int_digit)(a[14]);
  18915. r[15] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18916. s = (sp_int_digit)(a[14]); t = (sp_int_digit)(a[13]);
  18917. r[14] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18918. s = (sp_int_digit)(a[13]); t = (sp_int_digit)(a[12]);
  18919. r[13] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18920. s = (sp_int_digit)(a[12]); t = (sp_int_digit)(a[11]);
  18921. r[12] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18922. s = (sp_int_digit)(a[11]); t = (sp_int_digit)(a[10]);
  18923. r[11] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18924. s = (sp_int_digit)(a[10]); t = (sp_int_digit)(a[9]);
  18925. r[10] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18926. s = (sp_int_digit)(a[9]); t = (sp_int_digit)(a[8]);
  18927. r[9] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18928. s = (sp_int_digit)(a[8]); t = (sp_int_digit)(a[7]);
  18929. r[8] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18930. s = (sp_int_digit)(a[7]); t = (sp_int_digit)(a[6]);
  18931. r[7] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18932. s = (sp_int_digit)(a[6]); t = (sp_int_digit)(a[5]);
  18933. r[6] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18934. s = (sp_int_digit)(a[5]); t = (sp_int_digit)(a[4]);
  18935. r[5] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18936. s = (sp_int_digit)(a[4]); t = (sp_int_digit)(a[3]);
  18937. r[4] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18938. s = (sp_int_digit)(a[3]); t = (sp_int_digit)(a[2]);
  18939. r[3] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18940. s = (sp_int_digit)(a[2]); t = (sp_int_digit)(a[1]);
  18941. r[2] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18942. s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]);
  18943. r[1] = ((s << n) | (t >> (53U - n))) & 0x1fffffffffffffUL;
  18944. r[0] = (a[0] << n) & 0x1fffffffffffffL;
  18945. }
  18946. /* Modular exponentiate 2 to the e mod m. (r = 2^e mod m)
  18947. *
  18948. * r A single precision number that is the result of the operation.
  18949. * e A single precision number that is the exponent.
  18950. * bits The number of bits in the exponent.
  18951. * m A single precision number that is the modulus.
  18952. * returns 0 on success.
  18953. * returns MEMORY_E on dynamic memory allocation failure.
  18954. * returns MP_VAL when base is even.
  18955. */
  18956. static int sp_4096_mod_exp_2_78(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m)
  18957. {
  18958. #ifdef WOLFSSL_SP_SMALL_STACK
  18959. sp_digit* td = NULL;
  18960. #else
  18961. sp_digit td[235];
  18962. #endif
  18963. sp_digit* norm = NULL;
  18964. sp_digit* tmp = NULL;
  18965. sp_digit mp = 1;
  18966. sp_digit n;
  18967. sp_digit o;
  18968. int i;
  18969. int c;
  18970. byte y;
  18971. int err = MP_OKAY;
  18972. if (bits == 0) {
  18973. err = MP_VAL;
  18974. }
  18975. #ifdef WOLFSSL_SP_SMALL_STACK
  18976. if (err == MP_OKAY) {
  18977. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 235, NULL,
  18978. DYNAMIC_TYPE_TMP_BUFFER);
  18979. if (td == NULL)
  18980. err = MEMORY_E;
  18981. }
  18982. #endif
  18983. if (err == MP_OKAY) {
  18984. norm = td;
  18985. tmp = td + 156;
  18986. XMEMSET(td, 0, sizeof(sp_digit) * 235);
  18987. sp_4096_mont_setup(m, &mp);
  18988. sp_4096_mont_norm_78(norm, m);
  18989. bits = ((bits + 4) / 5) * 5;
  18990. i = ((bits + 52) / 53) - 1;
  18991. c = bits % 53;
  18992. if (c == 0) {
  18993. c = 53;
  18994. }
  18995. if (i < 78) {
  18996. n = e[i--] << (64 - c);
  18997. }
  18998. else {
  18999. n = 0;
  19000. i--;
  19001. }
  19002. if (c < 5) {
  19003. n |= e[i--] << (11 - c);
  19004. c += 53;
  19005. }
  19006. y = (int)((n >> 59) & 0x1f);
  19007. n <<= 5;
  19008. c -= 5;
  19009. sp_4096_lshift_78(r, norm, (byte)y);
  19010. while ((i >= 0) || (c >= 5)) {
  19011. if (c >= 5) {
  19012. y = (byte)((n >> 59) & 0x1f);
  19013. n <<= 5;
  19014. c -= 5;
  19015. }
  19016. else if (c == 0) {
  19017. n = e[i--] << 11;
  19018. y = (byte)((n >> 59) & 0x1f);
  19019. n <<= 5;
  19020. c = 48;
  19021. }
  19022. else {
  19023. y = (byte)((n >> 59) & 0x1f);
  19024. n = e[i--] << 11;
  19025. c = 5 - c;
  19026. y |= (byte)((n >> (64 - c)) & ((1 << c) - 1));
  19027. n <<= c;
  19028. c = 53 - c;
  19029. }
  19030. sp_4096_mont_sqr_78(r, r, m, mp);
  19031. sp_4096_mont_sqr_78(r, r, m, mp);
  19032. sp_4096_mont_sqr_78(r, r, m, mp);
  19033. sp_4096_mont_sqr_78(r, r, m, mp);
  19034. sp_4096_mont_sqr_78(r, r, m, mp);
  19035. sp_4096_lshift_78(r, r, (byte)y);
  19036. sp_4096_mul_d_78(tmp, norm, (r[78] << 38) + (r[77] >> 15));
  19037. r[78] = 0;
  19038. r[77] &= 0x7fffL;
  19039. (void)sp_4096_add_78(r, r, tmp);
  19040. sp_4096_norm_78(r);
  19041. o = sp_4096_cmp_78(r, m);
  19042. sp_4096_cond_sub_78(r, r, m, ~(o >> 63));
  19043. }
  19044. sp_4096_mont_reduce_78(r, m, mp);
  19045. n = sp_4096_cmp_78(r, m);
  19046. sp_4096_cond_sub_78(r, r, m, ~(n >> 63));
  19047. }
  19048. #ifdef WOLFSSL_SP_SMALL_STACK
  19049. if (td != NULL)
  19050. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  19051. #endif
  19052. return err;
  19053. }
  19054. #endif /* HAVE_FFDHE_4096 */
  19055. /* Perform the modular exponentiation for Diffie-Hellman.
  19056. *
  19057. * base Base.
  19058. * exp Array of bytes that is the exponent.
  19059. * expLen Length of data, in bytes, in exponent.
  19060. * mod Modulus.
  19061. * out Buffer to hold big-endian bytes of exponentiation result.
  19062. * Must be at least 512 bytes long.
  19063. * outLen Length, in bytes, of exponentiation result.
  19064. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  19065. * and MEMORY_E if memory allocation fails.
  19066. */
  19067. int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen,
  19068. const mp_int* mod, byte* out, word32* outLen)
  19069. {
  19070. #ifdef WOLFSSL_SP_SMALL_STACK
  19071. sp_digit* b = NULL;
  19072. #else
  19073. sp_digit b[78 * 4];
  19074. #endif
  19075. sp_digit* e = NULL;
  19076. sp_digit* m = NULL;
  19077. sp_digit* r = NULL;
  19078. word32 i;
  19079. int err = MP_OKAY;
  19080. if (mp_count_bits(base) > 4096) {
  19081. err = MP_READ_E;
  19082. }
  19083. else if (expLen > 512U) {
  19084. err = MP_READ_E;
  19085. }
  19086. else if (mp_count_bits(mod) != 4096) {
  19087. err = MP_READ_E;
  19088. }
  19089. else if (mp_iseven(mod)) {
  19090. err = MP_VAL;
  19091. }
  19092. #ifdef WOLFSSL_SP_SMALL_STACK
  19093. if (err == MP_OKAY) {
  19094. b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL,
  19095. DYNAMIC_TYPE_DH);
  19096. if (b == NULL)
  19097. err = MEMORY_E;
  19098. }
  19099. #endif
  19100. if (err == MP_OKAY) {
  19101. e = b + 78 * 2;
  19102. m = e + 78;
  19103. r = b;
  19104. sp_4096_from_mp(b, 78, base);
  19105. sp_4096_from_bin(e, 78, exp, expLen);
  19106. sp_4096_from_mp(m, 78, mod);
  19107. #ifdef HAVE_FFDHE_4096
  19108. if (base->used == 1 && base->dp[0] == 2U &&
  19109. ((m[77] << 17) | (m[76] >> 36)) == 0xffffffffL) {
  19110. err = sp_4096_mod_exp_2_78(r, e, expLen * 8U, m);
  19111. }
  19112. else {
  19113. #endif
  19114. err = sp_4096_mod_exp_78(r, b, e, expLen * 8U, m, 0);
  19115. #ifdef HAVE_FFDHE_4096
  19116. }
  19117. #endif
  19118. }
  19119. if (err == MP_OKAY) {
  19120. sp_4096_to_bin_78(r, out);
  19121. *outLen = 512;
  19122. for (i=0; i<512U && out[i] == 0U; i++) {
  19123. /* Search for first non-zero. */
  19124. }
  19125. *outLen -= i;
  19126. XMEMMOVE(out, out + i, *outLen);
  19127. }
  19128. #ifdef WOLFSSL_SP_SMALL_STACK
  19129. if (b != NULL)
  19130. #endif
  19131. {
  19132. /* only "e" is sensitive and needs zeroized */
  19133. if (e != NULL)
  19134. ForceZero(e, sizeof(sp_digit) * 78U);
  19135. #ifdef WOLFSSL_SP_SMALL_STACK
  19136. XFREE(b, NULL, DYNAMIC_TYPE_DH);
  19137. #endif
  19138. }
  19139. return err;
  19140. }
  19141. #endif /* WOLFSSL_HAVE_SP_DH */
  19142. #endif /* WOLFSSL_HAVE_SP_DH | (WOLFSSL_HAVE_SP_RSA & !WOLFSSL_RSA_PUBLIC_ONLY) */
  19143. #endif /* WOLFSSL_SP_SMALL */
  19144. #endif /* WOLFSSL_SP_4096 */
  19145. #endif /* WOLFSSL_HAVE_SP_RSA | WOLFSSL_HAVE_SP_DH */
  19146. #ifdef WOLFSSL_HAVE_SP_ECC
  19147. #ifndef WOLFSSL_SP_NO_256
  19148. /* Point structure to use. */
  19149. typedef struct sp_point_256 {
  19150. /* X ordinate of point. */
  19151. sp_digit x[2 * 5];
  19152. /* Y ordinate of point. */
  19153. sp_digit y[2 * 5];
  19154. /* Z ordinate of point. */
  19155. sp_digit z[2 * 5];
  19156. /* Indicates point is at infinity. */
  19157. int infinity;
  19158. } sp_point_256;
  19159. /* The modulus (prime) of the curve P256. */
  19160. static const sp_digit p256_mod[5] = {
  19161. 0xfffffffffffffL,0x00fffffffffffL,0x0000000000000L,0x0001000000000L,
  19162. 0x0ffffffff0000L
  19163. };
  19164. /* The Montgomery normalizer for modulus of the curve P256. */
  19165. static const sp_digit p256_norm_mod[5] = {
  19166. 0x0000000000001L,0xff00000000000L,0xfffffffffffffL,0xfffefffffffffL,
  19167. 0x000000000ffffL
  19168. };
  19169. /* The Montgomery multiplier for modulus of the curve P256. */
  19170. static const sp_digit p256_mp_mod = 0x0000000000001;
  19171. #if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
  19172. defined(HAVE_ECC_VERIFY)
  19173. /* The order of the curve P256. */
  19174. static const sp_digit p256_order[5] = {
  19175. 0x9cac2fc632551L,0xada7179e84f3bL,0xfffffffbce6faL,0x0000fffffffffL,
  19176. 0x0ffffffff0000L
  19177. };
  19178. #endif
  19179. /* The order of the curve P256 minus 2. */
  19180. static const sp_digit p256_order2[5] = {
  19181. 0x9cac2fc63254fL,0xada7179e84f3bL,0xfffffffbce6faL,0x0000fffffffffL,
  19182. 0x0ffffffff0000L
  19183. };
  19184. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  19185. /* The Montgomery normalizer for order of the curve P256. */
  19186. static const sp_digit p256_norm_order[5] = {
  19187. 0x6353d039cdaafL,0x5258e8617b0c4L,0x0000000431905L,0xffff000000000L,
  19188. 0x000000000ffffL
  19189. };
  19190. #endif
  19191. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  19192. /* The Montgomery multiplier for order of the curve P256. */
  19193. static const sp_digit p256_mp_order = 0x1c8aaee00bc4fL;
  19194. #endif
  19195. /* The base point of curve P256. */
  19196. static const sp_point_256 p256_base = {
  19197. /* X ordinate */
  19198. {
  19199. 0x13945d898c296L,0x812deb33a0f4aL,0x3a440f277037dL,0x4247f8bce6e56L,
  19200. 0x06b17d1f2e12cL,
  19201. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0
  19202. },
  19203. /* Y ordinate */
  19204. {
  19205. 0x6406837bf51f5L,0x576b315ececbbL,0xc0f9e162bce33L,0x7f9b8ee7eb4a7L,
  19206. 0x04fe342e2fe1aL,
  19207. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0
  19208. },
  19209. /* Z ordinate */
  19210. {
  19211. 0x0000000000001L,0x0000000000000L,0x0000000000000L,0x0000000000000L,
  19212. 0x0000000000000L,
  19213. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0
  19214. },
  19215. /* infinity */
  19216. 0
  19217. };
  19218. #if defined(HAVE_ECC_CHECK_KEY) || defined(HAVE_COMP_KEY)
  19219. static const sp_digit p256_b[5] = {
  19220. 0xe3c3e27d2604bL,0xb0cc53b0f63bcL,0x69886bc651d06L,0x93e7b3ebbd557L,
  19221. 0x05ac635d8aa3aL
  19222. };
  19223. #endif
  19224. #ifdef WOLFSSL_SP_SMALL
  19225. /* Multiply a and b into r. (r = a * b)
  19226. *
  19227. * r A single precision integer.
  19228. * a A single precision integer.
  19229. * b A single precision integer.
  19230. */
  19231. SP_NOINLINE static void sp_256_mul_5(sp_digit* r, const sp_digit* a,
  19232. const sp_digit* b)
  19233. {
  19234. int i;
  19235. int imax;
  19236. int k;
  19237. sp_uint128 c;
  19238. sp_uint128 lo;
  19239. c = ((sp_uint128)a[4]) * b[4];
  19240. r[9] = (sp_digit)(c >> 52);
  19241. c &= 0xfffffffffffffL;
  19242. for (k = 7; k >= 0; k--) {
  19243. if (k >= 5) {
  19244. i = k - 4;
  19245. imax = 4;
  19246. }
  19247. else {
  19248. i = 0;
  19249. imax = k;
  19250. }
  19251. lo = 0;
  19252. for (; i <= imax; i++) {
  19253. lo += ((sp_uint128)a[i]) * b[k - i];
  19254. }
  19255. c += lo >> 52;
  19256. r[k + 2] += (sp_digit)(c >> 52);
  19257. r[k + 1] = (sp_digit)(c & 0xfffffffffffffL);
  19258. c = lo & 0xfffffffffffffL;
  19259. }
  19260. r[0] = (sp_digit)c;
  19261. }
  19262. #else
  19263. /* Multiply a and b into r. (r = a * b)
  19264. *
  19265. * r A single precision integer.
  19266. * a A single precision integer.
  19267. * b A single precision integer.
  19268. */
  19269. SP_NOINLINE static void sp_256_mul_5(sp_digit* r, const sp_digit* a,
  19270. const sp_digit* b)
  19271. {
  19272. sp_int128 t0 = ((sp_int128)a[ 0]) * b[ 0];
  19273. sp_int128 t1 = ((sp_int128)a[ 0]) * b[ 1]
  19274. + ((sp_int128)a[ 1]) * b[ 0];
  19275. sp_int128 t2 = ((sp_int128)a[ 0]) * b[ 2]
  19276. + ((sp_int128)a[ 1]) * b[ 1]
  19277. + ((sp_int128)a[ 2]) * b[ 0];
  19278. sp_int128 t3 = ((sp_int128)a[ 0]) * b[ 3]
  19279. + ((sp_int128)a[ 1]) * b[ 2]
  19280. + ((sp_int128)a[ 2]) * b[ 1]
  19281. + ((sp_int128)a[ 3]) * b[ 0];
  19282. sp_int128 t4 = ((sp_int128)a[ 0]) * b[ 4]
  19283. + ((sp_int128)a[ 1]) * b[ 3]
  19284. + ((sp_int128)a[ 2]) * b[ 2]
  19285. + ((sp_int128)a[ 3]) * b[ 1]
  19286. + ((sp_int128)a[ 4]) * b[ 0];
  19287. sp_int128 t5 = ((sp_int128)a[ 1]) * b[ 4]
  19288. + ((sp_int128)a[ 2]) * b[ 3]
  19289. + ((sp_int128)a[ 3]) * b[ 2]
  19290. + ((sp_int128)a[ 4]) * b[ 1];
  19291. sp_int128 t6 = ((sp_int128)a[ 2]) * b[ 4]
  19292. + ((sp_int128)a[ 3]) * b[ 3]
  19293. + ((sp_int128)a[ 4]) * b[ 2];
  19294. sp_int128 t7 = ((sp_int128)a[ 3]) * b[ 4]
  19295. + ((sp_int128)a[ 4]) * b[ 3];
  19296. sp_int128 t8 = ((sp_int128)a[ 4]) * b[ 4];
  19297. t1 += t0 >> 52; r[ 0] = t0 & 0xfffffffffffffL;
  19298. t2 += t1 >> 52; r[ 1] = t1 & 0xfffffffffffffL;
  19299. t3 += t2 >> 52; r[ 2] = t2 & 0xfffffffffffffL;
  19300. t4 += t3 >> 52; r[ 3] = t3 & 0xfffffffffffffL;
  19301. t5 += t4 >> 52; r[ 4] = t4 & 0xfffffffffffffL;
  19302. t6 += t5 >> 52; r[ 5] = t5 & 0xfffffffffffffL;
  19303. t7 += t6 >> 52; r[ 6] = t6 & 0xfffffffffffffL;
  19304. t8 += t7 >> 52; r[ 7] = t7 & 0xfffffffffffffL;
  19305. r[9] = (sp_digit)(t8 >> 52);
  19306. r[8] = t8 & 0xfffffffffffffL;
  19307. }
  19308. #endif /* WOLFSSL_SP_SMALL */
  19309. #ifdef WOLFSSL_SP_SMALL
  19310. /* Square a and put result in r. (r = a * a)
  19311. *
  19312. * r A single precision integer.
  19313. * a A single precision integer.
  19314. */
  19315. SP_NOINLINE static void sp_256_sqr_5(sp_digit* r, const sp_digit* a)
  19316. {
  19317. int i;
  19318. int imax;
  19319. int k;
  19320. sp_uint128 c;
  19321. sp_uint128 t;
  19322. c = ((sp_uint128)a[4]) * a[4];
  19323. r[9] = (sp_digit)(c >> 52);
  19324. c = (c & 0xfffffffffffffL) << 52;
  19325. for (k = 7; k >= 0; k--) {
  19326. i = (k + 1) / 2;
  19327. if ((k & 1) == 0) {
  19328. c += ((sp_uint128)a[i]) * a[i];
  19329. i++;
  19330. }
  19331. if (k < 4) {
  19332. imax = k;
  19333. }
  19334. else {
  19335. imax = 4;
  19336. }
  19337. t = 0;
  19338. for (; i <= imax; i++) {
  19339. t += ((sp_uint128)a[i]) * a[k - i];
  19340. }
  19341. c += t * 2;
  19342. r[k + 2] += (sp_digit) (c >> 104);
  19343. r[k + 1] = (sp_digit)((c >> 52) & 0xfffffffffffffL);
  19344. c = (c & 0xfffffffffffffL) << 52;
  19345. }
  19346. r[0] = (sp_digit)(c >> 52);
  19347. }
  19348. #else
  19349. /* Square a and put result in r. (r = a * a)
  19350. *
  19351. * r A single precision integer.
  19352. * a A single precision integer.
  19353. */
  19354. SP_NOINLINE static void sp_256_sqr_5(sp_digit* r, const sp_digit* a)
  19355. {
  19356. sp_int128 t0 = ((sp_int128)a[ 0]) * a[ 0];
  19357. sp_int128 t1 = (((sp_int128)a[ 0]) * a[ 1]) * 2;
  19358. sp_int128 t2 = (((sp_int128)a[ 0]) * a[ 2]) * 2
  19359. + ((sp_int128)a[ 1]) * a[ 1];
  19360. sp_int128 t3 = (((sp_int128)a[ 0]) * a[ 3]
  19361. + ((sp_int128)a[ 1]) * a[ 2]) * 2;
  19362. sp_int128 t4 = (((sp_int128)a[ 0]) * a[ 4]
  19363. + ((sp_int128)a[ 1]) * a[ 3]) * 2
  19364. + ((sp_int128)a[ 2]) * a[ 2];
  19365. sp_int128 t5 = (((sp_int128)a[ 1]) * a[ 4]
  19366. + ((sp_int128)a[ 2]) * a[ 3]) * 2;
  19367. sp_int128 t6 = (((sp_int128)a[ 2]) * a[ 4]) * 2
  19368. + ((sp_int128)a[ 3]) * a[ 3];
  19369. sp_int128 t7 = (((sp_int128)a[ 3]) * a[ 4]) * 2;
  19370. sp_int128 t8 = ((sp_int128)a[ 4]) * a[ 4];
  19371. t1 += t0 >> 52; r[ 0] = t0 & 0xfffffffffffffL;
  19372. t2 += t1 >> 52; r[ 1] = t1 & 0xfffffffffffffL;
  19373. t3 += t2 >> 52; r[ 2] = t2 & 0xfffffffffffffL;
  19374. t4 += t3 >> 52; r[ 3] = t3 & 0xfffffffffffffL;
  19375. t5 += t4 >> 52; r[ 4] = t4 & 0xfffffffffffffL;
  19376. t6 += t5 >> 52; r[ 5] = t5 & 0xfffffffffffffL;
  19377. t7 += t6 >> 52; r[ 6] = t6 & 0xfffffffffffffL;
  19378. t8 += t7 >> 52; r[ 7] = t7 & 0xfffffffffffffL;
  19379. r[9] = (sp_digit)(t8 >> 52);
  19380. r[8] = t8 & 0xfffffffffffffL;
  19381. }
  19382. #endif /* WOLFSSL_SP_SMALL */
  19383. #ifdef WOLFSSL_SP_SMALL
  19384. /* Add b to a into r. (r = a + b)
  19385. *
  19386. * r A single precision integer.
  19387. * a A single precision integer.
  19388. * b A single precision integer.
  19389. */
  19390. SP_NOINLINE static int sp_256_add_5(sp_digit* r, const sp_digit* a,
  19391. const sp_digit* b)
  19392. {
  19393. int i;
  19394. for (i = 0; i < 5; i++) {
  19395. r[i] = a[i] + b[i];
  19396. }
  19397. return 0;
  19398. }
  19399. #else
  19400. /* Add b to a into r. (r = a + b)
  19401. *
  19402. * r A single precision integer.
  19403. * a A single precision integer.
  19404. * b A single precision integer.
  19405. */
  19406. SP_NOINLINE static int sp_256_add_5(sp_digit* r, const sp_digit* a,
  19407. const sp_digit* b)
  19408. {
  19409. r[ 0] = a[ 0] + b[ 0];
  19410. r[ 1] = a[ 1] + b[ 1];
  19411. r[ 2] = a[ 2] + b[ 2];
  19412. r[ 3] = a[ 3] + b[ 3];
  19413. r[ 4] = a[ 4] + b[ 4];
  19414. return 0;
  19415. }
  19416. #endif /* WOLFSSL_SP_SMALL */
  19417. #ifdef WOLFSSL_SP_SMALL
  19418. /* Sub b from a into r. (r = a - b)
  19419. *
  19420. * r A single precision integer.
  19421. * a A single precision integer.
  19422. * b A single precision integer.
  19423. */
  19424. SP_NOINLINE static int sp_256_sub_5(sp_digit* r, const sp_digit* a,
  19425. const sp_digit* b)
  19426. {
  19427. int i;
  19428. for (i = 0; i < 5; i++) {
  19429. r[i] = a[i] - b[i];
  19430. }
  19431. return 0;
  19432. }
  19433. #else
  19434. /* Sub b from a into r. (r = a - b)
  19435. *
  19436. * r A single precision integer.
  19437. * a A single precision integer.
  19438. * b A single precision integer.
  19439. */
  19440. SP_NOINLINE static int sp_256_sub_5(sp_digit* r, const sp_digit* a,
  19441. const sp_digit* b)
  19442. {
  19443. r[ 0] = a[ 0] - b[ 0];
  19444. r[ 1] = a[ 1] - b[ 1];
  19445. r[ 2] = a[ 2] - b[ 2];
  19446. r[ 3] = a[ 3] - b[ 3];
  19447. r[ 4] = a[ 4] - b[ 4];
  19448. return 0;
  19449. }
  19450. #endif /* WOLFSSL_SP_SMALL */
  19451. /* Convert an mp_int to an array of sp_digit.
  19452. *
  19453. * r A single precision integer.
  19454. * size Maximum number of bytes to convert
  19455. * a A multi-precision integer.
  19456. */
  19457. static void sp_256_from_mp(sp_digit* r, int size, const mp_int* a)
  19458. {
  19459. #if DIGIT_BIT == 52
  19460. int i;
  19461. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  19462. int o = 0;
  19463. for (i = 0; i < size; i++) {
  19464. sp_digit mask = (sp_digit)0 - (j >> 51);
  19465. r[i] = a->dp[o] & mask;
  19466. j++;
  19467. o += (int)(j >> 51);
  19468. }
  19469. #elif DIGIT_BIT > 52
  19470. unsigned int i;
  19471. int j = 0;
  19472. word32 s = 0;
  19473. r[0] = 0;
  19474. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  19475. r[j] |= ((sp_digit)a->dp[i] << s);
  19476. r[j] &= 0xfffffffffffffL;
  19477. s = 52U - s;
  19478. if (j + 1 >= size) {
  19479. break;
  19480. }
  19481. /* lint allow cast of mismatch word32 and mp_digit */
  19482. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  19483. while ((s + 52U) <= (word32)DIGIT_BIT) {
  19484. s += 52U;
  19485. r[j] &= 0xfffffffffffffL;
  19486. if (j + 1 >= size) {
  19487. break;
  19488. }
  19489. if (s < (word32)DIGIT_BIT) {
  19490. /* lint allow cast of mismatch word32 and mp_digit */
  19491. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  19492. }
  19493. else {
  19494. r[++j] = (sp_digit)0;
  19495. }
  19496. }
  19497. s = (word32)DIGIT_BIT - s;
  19498. }
  19499. for (j++; j < size; j++) {
  19500. r[j] = 0;
  19501. }
  19502. #else
  19503. unsigned int i;
  19504. int j = 0;
  19505. int s = 0;
  19506. r[0] = 0;
  19507. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  19508. r[j] |= ((sp_digit)a->dp[i]) << s;
  19509. if (s + DIGIT_BIT >= 52) {
  19510. r[j] &= 0xfffffffffffffL;
  19511. if (j + 1 >= size) {
  19512. break;
  19513. }
  19514. s = 52 - s;
  19515. if (s == DIGIT_BIT) {
  19516. r[++j] = 0;
  19517. s = 0;
  19518. }
  19519. else {
  19520. r[++j] = a->dp[i] >> s;
  19521. s = DIGIT_BIT - s;
  19522. }
  19523. }
  19524. else {
  19525. s += DIGIT_BIT;
  19526. }
  19527. }
  19528. for (j++; j < size; j++) {
  19529. r[j] = 0;
  19530. }
  19531. #endif
  19532. }
  19533. /* Convert a point of type ecc_point to type sp_point_256.
  19534. *
  19535. * p Point of type sp_point_256 (result).
  19536. * pm Point of type ecc_point.
  19537. */
  19538. static void sp_256_point_from_ecc_point_5(sp_point_256* p,
  19539. const ecc_point* pm)
  19540. {
  19541. XMEMSET(p->x, 0, sizeof(p->x));
  19542. XMEMSET(p->y, 0, sizeof(p->y));
  19543. XMEMSET(p->z, 0, sizeof(p->z));
  19544. sp_256_from_mp(p->x, 5, pm->x);
  19545. sp_256_from_mp(p->y, 5, pm->y);
  19546. sp_256_from_mp(p->z, 5, pm->z);
  19547. p->infinity = 0;
  19548. }
  19549. /* Convert an array of sp_digit to an mp_int.
  19550. *
  19551. * a A single precision integer.
  19552. * r A multi-precision integer.
  19553. */
  19554. static int sp_256_to_mp(const sp_digit* a, mp_int* r)
  19555. {
  19556. int err;
  19557. err = mp_grow(r, (256 + DIGIT_BIT - 1) / DIGIT_BIT);
  19558. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  19559. #if DIGIT_BIT == 52
  19560. XMEMCPY(r->dp, a, sizeof(sp_digit) * 5);
  19561. r->used = 5;
  19562. mp_clamp(r);
  19563. #elif DIGIT_BIT < 52
  19564. int i;
  19565. int j = 0;
  19566. int s = 0;
  19567. r->dp[0] = 0;
  19568. for (i = 0; i < 5; i++) {
  19569. r->dp[j] |= (mp_digit)(a[i] << s);
  19570. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  19571. s = DIGIT_BIT - s;
  19572. r->dp[++j] = (mp_digit)(a[i] >> s);
  19573. while (s + DIGIT_BIT <= 52) {
  19574. s += DIGIT_BIT;
  19575. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  19576. if (s == SP_WORD_SIZE) {
  19577. r->dp[j] = 0;
  19578. }
  19579. else {
  19580. r->dp[j] = (mp_digit)(a[i] >> s);
  19581. }
  19582. }
  19583. s = 52 - s;
  19584. }
  19585. r->used = (256 + DIGIT_BIT - 1) / DIGIT_BIT;
  19586. mp_clamp(r);
  19587. #else
  19588. int i;
  19589. int j = 0;
  19590. int s = 0;
  19591. r->dp[0] = 0;
  19592. for (i = 0; i < 5; i++) {
  19593. r->dp[j] |= ((mp_digit)a[i]) << s;
  19594. if (s + 52 >= DIGIT_BIT) {
  19595. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  19596. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  19597. #endif
  19598. s = DIGIT_BIT - s;
  19599. r->dp[++j] = a[i] >> s;
  19600. s = 52 - s;
  19601. }
  19602. else {
  19603. s += 52;
  19604. }
  19605. }
  19606. r->used = (256 + DIGIT_BIT - 1) / DIGIT_BIT;
  19607. mp_clamp(r);
  19608. #endif
  19609. }
  19610. return err;
  19611. }
  19612. /* Convert a point of type sp_point_256 to type ecc_point.
  19613. *
  19614. * p Point of type sp_point_256.
  19615. * pm Point of type ecc_point (result).
  19616. * returns MEMORY_E when allocation of memory in ecc_point fails otherwise
  19617. * MP_OKAY.
  19618. */
  19619. static int sp_256_point_to_ecc_point_5(const sp_point_256* p, ecc_point* pm)
  19620. {
  19621. int err;
  19622. err = sp_256_to_mp(p->x, pm->x);
  19623. if (err == MP_OKAY) {
  19624. err = sp_256_to_mp(p->y, pm->y);
  19625. }
  19626. if (err == MP_OKAY) {
  19627. err = sp_256_to_mp(p->z, pm->z);
  19628. }
  19629. return err;
  19630. }
  19631. /* Compare a with b in constant time.
  19632. *
  19633. * a A single precision integer.
  19634. * b A single precision integer.
  19635. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  19636. * respectively.
  19637. */
  19638. static sp_digit sp_256_cmp_5(const sp_digit* a, const sp_digit* b)
  19639. {
  19640. sp_digit r = 0;
  19641. #ifdef WOLFSSL_SP_SMALL
  19642. int i;
  19643. for (i=4; i>=0; i--) {
  19644. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 51);
  19645. }
  19646. #else
  19647. r |= (a[ 4] - b[ 4]) & (0 - (sp_digit)1);
  19648. r |= (a[ 3] - b[ 3]) & ~(((sp_digit)0 - r) >> 51);
  19649. r |= (a[ 2] - b[ 2]) & ~(((sp_digit)0 - r) >> 51);
  19650. r |= (a[ 1] - b[ 1]) & ~(((sp_digit)0 - r) >> 51);
  19651. r |= (a[ 0] - b[ 0]) & ~(((sp_digit)0 - r) >> 51);
  19652. #endif /* WOLFSSL_SP_SMALL */
  19653. return r;
  19654. }
  19655. /* Conditionally subtract b from a using the mask m.
  19656. * m is -1 to subtract and 0 when not.
  19657. *
  19658. * r A single precision number representing condition subtract result.
  19659. * a A single precision number to subtract from.
  19660. * b A single precision number to subtract.
  19661. * m Mask value to apply.
  19662. */
  19663. static void sp_256_cond_sub_5(sp_digit* r, const sp_digit* a,
  19664. const sp_digit* b, const sp_digit m)
  19665. {
  19666. #ifdef WOLFSSL_SP_SMALL
  19667. int i;
  19668. for (i = 0; i < 5; i++) {
  19669. r[i] = a[i] - (b[i] & m);
  19670. }
  19671. #else
  19672. r[ 0] = a[ 0] - (b[ 0] & m);
  19673. r[ 1] = a[ 1] - (b[ 1] & m);
  19674. r[ 2] = a[ 2] - (b[ 2] & m);
  19675. r[ 3] = a[ 3] - (b[ 3] & m);
  19676. r[ 4] = a[ 4] - (b[ 4] & m);
  19677. #endif /* WOLFSSL_SP_SMALL */
  19678. }
  19679. /* Mul a by scalar b and add into r. (r += a * b)
  19680. *
  19681. * r A single precision integer.
  19682. * a A single precision integer.
  19683. * b A scalar.
  19684. */
  19685. SP_NOINLINE static void sp_256_mul_add_5(sp_digit* r, const sp_digit* a,
  19686. const sp_digit b)
  19687. {
  19688. #ifdef WOLFSSL_SP_SMALL
  19689. sp_int128 tb = b;
  19690. sp_int128 t[4];
  19691. int i;
  19692. t[0] = 0;
  19693. for (i = 0; i < 4; i += 4) {
  19694. t[0] += (tb * a[i+0]) + r[i+0];
  19695. t[1] = (tb * a[i+1]) + r[i+1];
  19696. t[2] = (tb * a[i+2]) + r[i+2];
  19697. t[3] = (tb * a[i+3]) + r[i+3];
  19698. r[i+0] = t[0] & 0xfffffffffffffL;
  19699. t[1] += t[0] >> 52;
  19700. r[i+1] = t[1] & 0xfffffffffffffL;
  19701. t[2] += t[1] >> 52;
  19702. r[i+2] = t[2] & 0xfffffffffffffL;
  19703. t[3] += t[2] >> 52;
  19704. r[i+3] = t[3] & 0xfffffffffffffL;
  19705. t[0] = t[3] >> 52;
  19706. }
  19707. t[0] += (tb * a[4]) + r[4];
  19708. r[4] = t[0] & 0xfffffffffffffL;
  19709. r[5] += (sp_digit)(t[0] >> 52);
  19710. #else
  19711. sp_int128 tb = b;
  19712. sp_int128 t[5];
  19713. t[ 0] = tb * a[ 0];
  19714. t[ 1] = tb * a[ 1];
  19715. t[ 2] = tb * a[ 2];
  19716. t[ 3] = tb * a[ 3];
  19717. t[ 4] = tb * a[ 4];
  19718. r[ 0] += (sp_digit) (t[ 0] & 0xfffffffffffffL);
  19719. r[ 1] += (sp_digit)((t[ 0] >> 52) + (t[ 1] & 0xfffffffffffffL));
  19720. r[ 2] += (sp_digit)((t[ 1] >> 52) + (t[ 2] & 0xfffffffffffffL));
  19721. r[ 3] += (sp_digit)((t[ 2] >> 52) + (t[ 3] & 0xfffffffffffffL));
  19722. r[ 4] += (sp_digit)((t[ 3] >> 52) + (t[ 4] & 0xfffffffffffffL));
  19723. r[ 5] += (sp_digit) (t[ 4] >> 52);
  19724. #endif /* WOLFSSL_SP_SMALL */
  19725. }
  19726. /* Normalize the values in each word to 52 bits.
  19727. *
  19728. * a Array of sp_digit to normalize.
  19729. */
  19730. static void sp_256_norm_5(sp_digit* a)
  19731. {
  19732. #ifdef WOLFSSL_SP_SMALL
  19733. int i;
  19734. for (i = 0; i < 4; i++) {
  19735. a[i+1] += a[i] >> 52;
  19736. a[i] &= 0xfffffffffffffL;
  19737. }
  19738. #else
  19739. a[1] += a[0] >> 52; a[0] &= 0xfffffffffffffL;
  19740. a[2] += a[1] >> 52; a[1] &= 0xfffffffffffffL;
  19741. a[3] += a[2] >> 52; a[2] &= 0xfffffffffffffL;
  19742. a[4] += a[3] >> 52; a[3] &= 0xfffffffffffffL;
  19743. #endif /* WOLFSSL_SP_SMALL */
  19744. }
  19745. /* Shift the result in the high 256 bits down to the bottom.
  19746. *
  19747. * r A single precision number.
  19748. * a A single precision number.
  19749. */
  19750. static void sp_256_mont_shift_5(sp_digit* r, const sp_digit* a)
  19751. {
  19752. #ifdef WOLFSSL_SP_SMALL
  19753. int i;
  19754. sp_uint64 n;
  19755. n = a[4] >> 48;
  19756. for (i = 0; i < 4; i++) {
  19757. n += (sp_uint64)a[5 + i] << 4;
  19758. r[i] = n & 0xfffffffffffffL;
  19759. n >>= 52;
  19760. }
  19761. n += (sp_uint64)a[9] << 4;
  19762. r[4] = n;
  19763. #else
  19764. sp_uint64 n;
  19765. n = a[4] >> 48;
  19766. n += (sp_uint64)a[ 5] << 4U; r[ 0] = n & 0xfffffffffffffUL; n >>= 52U;
  19767. n += (sp_uint64)a[ 6] << 4U; r[ 1] = n & 0xfffffffffffffUL; n >>= 52U;
  19768. n += (sp_uint64)a[ 7] << 4U; r[ 2] = n & 0xfffffffffffffUL; n >>= 52U;
  19769. n += (sp_uint64)a[ 8] << 4U; r[ 3] = n & 0xfffffffffffffUL; n >>= 52U;
  19770. n += (sp_uint64)a[ 9] << 4U; r[ 4] = n;
  19771. #endif /* WOLFSSL_SP_SMALL */
  19772. XMEMSET(&r[5], 0, sizeof(*r) * 5U);
  19773. }
  19774. /* Reduce the number back to 256 bits using Montgomery reduction.
  19775. *
  19776. * a A single precision number to reduce in place.
  19777. * m The single precision number representing the modulus.
  19778. * mp The digit representing the negative inverse of m mod 2^n.
  19779. */
  19780. static void sp_256_mont_reduce_order_5(sp_digit* a, const sp_digit* m, sp_digit mp)
  19781. {
  19782. int i;
  19783. sp_digit mu;
  19784. sp_digit over;
  19785. sp_256_norm_5(a + 5);
  19786. for (i=0; i<4; i++) {
  19787. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xfffffffffffffL;
  19788. sp_256_mul_add_5(a+i, m, mu);
  19789. a[i+1] += a[i] >> 52;
  19790. }
  19791. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0xffffffffffffL;
  19792. sp_256_mul_add_5(a+i, m, mu);
  19793. a[i+1] += a[i] >> 52;
  19794. a[i] &= 0xfffffffffffffL;
  19795. sp_256_mont_shift_5(a, a);
  19796. over = a[4] >> 48;
  19797. sp_256_cond_sub_5(a, a, m, ~((over - 1) >> 63));
  19798. sp_256_norm_5(a);
  19799. }
  19800. /* Reduce the number back to 256 bits using Montgomery reduction.
  19801. *
  19802. * a A single precision number to reduce in place.
  19803. * m The single precision number representing the modulus.
  19804. * mp The digit representing the negative inverse of m mod 2^n.
  19805. */
  19806. static void sp_256_mont_reduce_5(sp_digit* a, const sp_digit* m, sp_digit mp)
  19807. {
  19808. int i;
  19809. sp_int128 t;
  19810. sp_digit am;
  19811. (void)m;
  19812. (void)mp;
  19813. for (i = 0; i < 4; i++) {
  19814. am = a[i] & 0xfffffffffffffL;
  19815. /* Fifth word of modulus word */
  19816. t = am; t *= 0x0ffffffff0000L;
  19817. a[i + 1] += (am << 44) & 0xfffffffffffffL;
  19818. a[i + 2] += am >> 8;
  19819. a[i + 3] += (am << 36) & 0xfffffffffffffL;
  19820. a[i + 4] += (am >> 16) + (t & 0xfffffffffffffL);
  19821. a[i + 5] += t >> 52;
  19822. a[i + 1] += a[i] >> 52;
  19823. }
  19824. am = a[4] & 0xffffffffffff;
  19825. /* Fifth word of modulus word */
  19826. t = am; t *= 0x0ffffffff0000L;
  19827. a[4 + 1] += (am << 44) & 0xfffffffffffffL;
  19828. a[4 + 2] += am >> 8;
  19829. a[4 + 3] += (am << 36) & 0xfffffffffffffL;
  19830. a[4 + 4] += (am >> 16) + (t & 0xfffffffffffffL);
  19831. a[4 + 5] += t >> 52;
  19832. a[0] = (a[4] >> 48) + ((a[5] << 4) & 0xfffffffffffffL);
  19833. a[1] = (a[5] >> 48) + ((a[6] << 4) & 0xfffffffffffffL);
  19834. a[2] = (a[6] >> 48) + ((a[7] << 4) & 0xfffffffffffffL);
  19835. a[3] = (a[7] >> 48) + ((a[8] << 4) & 0xfffffffffffffL);
  19836. a[4] = (a[8] >> 48) + (a[9] << 4);
  19837. a[1] += a[0] >> 52; a[0] &= 0xfffffffffffffL;
  19838. a[2] += a[1] >> 52; a[1] &= 0xfffffffffffffL;
  19839. a[3] += a[2] >> 52; a[2] &= 0xfffffffffffffL;
  19840. a[4] += a[3] >> 52; a[3] &= 0xfffffffffffffL;
  19841. /* Get the bit over, if any. */
  19842. am = a[4] >> 48;
  19843. /* Create mask. */
  19844. am = 0 - am;
  19845. a[0] -= 0x000fffffffffffffL & am;
  19846. a[1] -= 0x00000fffffffffffL & am;
  19847. /* p256_mod[2] is zero */
  19848. a[3] -= 0x0000001000000000L & am;
  19849. a[4] -= 0x0000ffffffff0000L & am;
  19850. a[1] += a[0] >> 52; a[0] &= 0xfffffffffffffL;
  19851. a[2] += a[1] >> 52; a[1] &= 0xfffffffffffffL;
  19852. a[3] += a[2] >> 52; a[2] &= 0xfffffffffffffL;
  19853. a[4] += a[3] >> 52; a[3] &= 0xfffffffffffffL;
  19854. }
  19855. /* Multiply two Montgomery form numbers mod the modulus (prime).
  19856. * (r = a * b mod m)
  19857. *
  19858. * r Result of multiplication.
  19859. * a First number to multiply in Montgomery form.
  19860. * b Second number to multiply in Montgomery form.
  19861. * m Modulus (prime).
  19862. * mp Montgomery multiplier.
  19863. */
  19864. SP_NOINLINE static void sp_256_mont_mul_5(sp_digit* r, const sp_digit* a,
  19865. const sp_digit* b, const sp_digit* m, sp_digit mp)
  19866. {
  19867. sp_256_mul_5(r, a, b);
  19868. sp_256_mont_reduce_5(r, m, mp);
  19869. }
  19870. /* Square the Montgomery form number. (r = a * a mod m)
  19871. *
  19872. * r Result of squaring.
  19873. * a Number to square in Montgomery form.
  19874. * m Modulus (prime).
  19875. * mp Montgomery multiplier.
  19876. */
  19877. SP_NOINLINE static void sp_256_mont_sqr_5(sp_digit* r, const sp_digit* a,
  19878. const sp_digit* m, sp_digit mp)
  19879. {
  19880. sp_256_sqr_5(r, a);
  19881. sp_256_mont_reduce_5(r, m, mp);
  19882. }
  19883. #if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY)
  19884. /* Square the Montgomery form number a number of times. (r = a ^ n mod m)
  19885. *
  19886. * r Result of squaring.
  19887. * a Number to square in Montgomery form.
  19888. * n Number of times to square.
  19889. * m Modulus (prime).
  19890. * mp Montgomery multiplier.
  19891. */
  19892. static void sp_256_mont_sqr_n_5(sp_digit* r, const sp_digit* a, int n,
  19893. const sp_digit* m, sp_digit mp)
  19894. {
  19895. sp_256_mont_sqr_5(r, a, m, mp);
  19896. for (; n > 1; n--) {
  19897. sp_256_mont_sqr_5(r, r, m, mp);
  19898. }
  19899. }
  19900. #endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */
  19901. #ifdef WOLFSSL_SP_SMALL
  19902. /* Mod-2 for the P256 curve. */
  19903. static const uint64_t p256_mod_minus_2[4] = {
  19904. 0xfffffffffffffffdU,0x00000000ffffffffU,0x0000000000000000U,
  19905. 0xffffffff00000001U
  19906. };
  19907. #endif /* !WOLFSSL_SP_SMALL */
  19908. /* Invert the number, in Montgomery form, modulo the modulus (prime) of the
  19909. * P256 curve. (r = 1 / a mod m)
  19910. *
  19911. * r Inverse result.
  19912. * a Number to invert.
  19913. * td Temporary data.
  19914. */
  19915. static void sp_256_mont_inv_5(sp_digit* r, const sp_digit* a, sp_digit* td)
  19916. {
  19917. #ifdef WOLFSSL_SP_SMALL
  19918. sp_digit* t = td;
  19919. int i;
  19920. XMEMCPY(t, a, sizeof(sp_digit) * 5);
  19921. for (i=254; i>=0; i--) {
  19922. sp_256_mont_sqr_5(t, t, p256_mod, p256_mp_mod);
  19923. if (p256_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
  19924. sp_256_mont_mul_5(t, t, a, p256_mod, p256_mp_mod);
  19925. }
  19926. XMEMCPY(r, t, sizeof(sp_digit) * 5);
  19927. #else
  19928. sp_digit* t1 = td;
  19929. sp_digit* t2 = td + 2 * 5;
  19930. sp_digit* t3 = td + 4 * 5;
  19931. /* 0x2 */
  19932. sp_256_mont_sqr_5(t1, a, p256_mod, p256_mp_mod);
  19933. /* 0x3 */
  19934. sp_256_mont_mul_5(t2, t1, a, p256_mod, p256_mp_mod);
  19935. /* 0xc */
  19936. sp_256_mont_sqr_n_5(t1, t2, 2, p256_mod, p256_mp_mod);
  19937. /* 0xd */
  19938. sp_256_mont_mul_5(t3, t1, a, p256_mod, p256_mp_mod);
  19939. /* 0xf */
  19940. sp_256_mont_mul_5(t2, t2, t1, p256_mod, p256_mp_mod);
  19941. /* 0xf0 */
  19942. sp_256_mont_sqr_n_5(t1, t2, 4, p256_mod, p256_mp_mod);
  19943. /* 0xfd */
  19944. sp_256_mont_mul_5(t3, t3, t1, p256_mod, p256_mp_mod);
  19945. /* 0xff */
  19946. sp_256_mont_mul_5(t2, t2, t1, p256_mod, p256_mp_mod);
  19947. /* 0xff00 */
  19948. sp_256_mont_sqr_n_5(t1, t2, 8, p256_mod, p256_mp_mod);
  19949. /* 0xfffd */
  19950. sp_256_mont_mul_5(t3, t3, t1, p256_mod, p256_mp_mod);
  19951. /* 0xffff */
  19952. sp_256_mont_mul_5(t2, t2, t1, p256_mod, p256_mp_mod);
  19953. /* 0xffff0000 */
  19954. sp_256_mont_sqr_n_5(t1, t2, 16, p256_mod, p256_mp_mod);
  19955. /* 0xfffffffd */
  19956. sp_256_mont_mul_5(t3, t3, t1, p256_mod, p256_mp_mod);
  19957. /* 0xffffffff */
  19958. sp_256_mont_mul_5(t2, t2, t1, p256_mod, p256_mp_mod);
  19959. /* 0xffffffff00000000 */
  19960. sp_256_mont_sqr_n_5(t1, t2, 32, p256_mod, p256_mp_mod);
  19961. /* 0xffffffffffffffff */
  19962. sp_256_mont_mul_5(t2, t2, t1, p256_mod, p256_mp_mod);
  19963. /* 0xffffffff00000001 */
  19964. sp_256_mont_mul_5(r, t1, a, p256_mod, p256_mp_mod);
  19965. /* 0xffffffff000000010000000000000000000000000000000000000000 */
  19966. sp_256_mont_sqr_n_5(r, r, 160, p256_mod, p256_mp_mod);
  19967. /* 0xffffffff00000001000000000000000000000000ffffffffffffffff */
  19968. sp_256_mont_mul_5(r, r, t2, p256_mod, p256_mp_mod);
  19969. /* 0xffffffff00000001000000000000000000000000ffffffffffffffff00000000 */
  19970. sp_256_mont_sqr_n_5(r, r, 32, p256_mod, p256_mp_mod);
  19971. /* 0xffffffff00000001000000000000000000000000fffffffffffffffffffffffd */
  19972. sp_256_mont_mul_5(r, r, t3, p256_mod, p256_mp_mod);
  19973. #endif /* WOLFSSL_SP_SMALL */
  19974. }
  19975. /* Map the Montgomery form projective coordinate point to an affine point.
  19976. *
  19977. * r Resulting affine coordinate point.
  19978. * p Montgomery form projective coordinate point.
  19979. * t Temporary ordinate data.
  19980. */
  19981. static void sp_256_map_5(sp_point_256* r, const sp_point_256* p,
  19982. sp_digit* t)
  19983. {
  19984. sp_digit* t1 = t;
  19985. sp_digit* t2 = t + 2*5;
  19986. sp_int64 n;
  19987. sp_256_mont_inv_5(t1, p->z, t + 2*5);
  19988. sp_256_mont_sqr_5(t2, t1, p256_mod, p256_mp_mod);
  19989. sp_256_mont_mul_5(t1, t2, t1, p256_mod, p256_mp_mod);
  19990. /* x /= z^2 */
  19991. sp_256_mont_mul_5(r->x, p->x, t2, p256_mod, p256_mp_mod);
  19992. XMEMSET(r->x + 5, 0, sizeof(sp_digit) * 5U);
  19993. sp_256_mont_reduce_5(r->x, p256_mod, p256_mp_mod);
  19994. /* Reduce x to less than modulus */
  19995. n = sp_256_cmp_5(r->x, p256_mod);
  19996. sp_256_cond_sub_5(r->x, r->x, p256_mod, ~(n >> 51));
  19997. sp_256_norm_5(r->x);
  19998. /* y /= z^3 */
  19999. sp_256_mont_mul_5(r->y, p->y, t1, p256_mod, p256_mp_mod);
  20000. XMEMSET(r->y + 5, 0, sizeof(sp_digit) * 5U);
  20001. sp_256_mont_reduce_5(r->y, p256_mod, p256_mp_mod);
  20002. /* Reduce y to less than modulus */
  20003. n = sp_256_cmp_5(r->y, p256_mod);
  20004. sp_256_cond_sub_5(r->y, r->y, p256_mod, ~(n >> 51));
  20005. sp_256_norm_5(r->y);
  20006. XMEMSET(r->z, 0, sizeof(r->z) / 2);
  20007. r->z[0] = 1;
  20008. }
  20009. /* Add two Montgomery form numbers (r = a + b % m).
  20010. *
  20011. * r Result of addition.
  20012. * a First number to add in Montgomery form.
  20013. * b Second number to add in Montgomery form.
  20014. * m Modulus (prime).
  20015. */
  20016. static void sp_256_mont_add_5(sp_digit* r, const sp_digit* a, const sp_digit* b,
  20017. const sp_digit* m)
  20018. {
  20019. sp_digit over;
  20020. (void)sp_256_add_5(r, a, b);
  20021. sp_256_norm_5(r);
  20022. over = r[4] >> 48;
  20023. sp_256_cond_sub_5(r, r, m, ~((over - 1) >> 63));
  20024. sp_256_norm_5(r);
  20025. }
  20026. /* Double a Montgomery form number (r = a + a % m).
  20027. *
  20028. * r Result of doubling.
  20029. * a Number to double in Montgomery form.
  20030. * m Modulus (prime).
  20031. */
  20032. static void sp_256_mont_dbl_5(sp_digit* r, const sp_digit* a, const sp_digit* m)
  20033. {
  20034. sp_digit over;
  20035. (void)sp_256_add_5(r, a, a);
  20036. sp_256_norm_5(r);
  20037. over = r[4] >> 48;
  20038. sp_256_cond_sub_5(r, r, m, ~((over - 1) >> 63));
  20039. sp_256_norm_5(r);
  20040. }
  20041. /* Triple a Montgomery form number (r = a + a + a % m).
  20042. *
  20043. * r Result of Tripling.
  20044. * a Number to triple in Montgomery form.
  20045. * m Modulus (prime).
  20046. */
  20047. static void sp_256_mont_tpl_5(sp_digit* r, const sp_digit* a, const sp_digit* m)
  20048. {
  20049. sp_digit over;
  20050. (void)sp_256_add_5(r, a, a);
  20051. sp_256_norm_5(r);
  20052. over = r[4] >> 48;
  20053. sp_256_cond_sub_5(r, r, m, ~((over - 1) >> 63));
  20054. sp_256_norm_5(r);
  20055. (void)sp_256_add_5(r, r, a);
  20056. sp_256_norm_5(r);
  20057. over = r[4] >> 48;
  20058. sp_256_cond_sub_5(r, r, m, ~((over - 1) >> 63));
  20059. sp_256_norm_5(r);
  20060. }
  20061. #ifdef WOLFSSL_SP_SMALL
  20062. /* Conditionally add a and b using the mask m.
  20063. * m is -1 to add and 0 when not.
  20064. *
  20065. * r A single precision number representing conditional add result.
  20066. * a A single precision number to add with.
  20067. * b A single precision number to add.
  20068. * m Mask value to apply.
  20069. */
  20070. static void sp_256_cond_add_5(sp_digit* r, const sp_digit* a,
  20071. const sp_digit* b, const sp_digit m)
  20072. {
  20073. int i;
  20074. for (i = 0; i < 5; i++) {
  20075. r[i] = a[i] + (b[i] & m);
  20076. }
  20077. }
  20078. #endif /* WOLFSSL_SP_SMALL */
  20079. #ifndef WOLFSSL_SP_SMALL
  20080. /* Conditionally add a and b using the mask m.
  20081. * m is -1 to add and 0 when not.
  20082. *
  20083. * r A single precision number representing conditional add result.
  20084. * a A single precision number to add with.
  20085. * b A single precision number to add.
  20086. * m Mask value to apply.
  20087. */
  20088. static void sp_256_cond_add_5(sp_digit* r, const sp_digit* a,
  20089. const sp_digit* b, const sp_digit m)
  20090. {
  20091. r[ 0] = a[ 0] + (b[ 0] & m);
  20092. r[ 1] = a[ 1] + (b[ 1] & m);
  20093. r[ 2] = a[ 2] + (b[ 2] & m);
  20094. r[ 3] = a[ 3] + (b[ 3] & m);
  20095. r[ 4] = a[ 4] + (b[ 4] & m);
  20096. }
  20097. #endif /* !WOLFSSL_SP_SMALL */
  20098. /* Subtract two Montgomery form numbers (r = a - b % m).
  20099. *
  20100. * r Result of subtration.
  20101. * a Number to subtract from in Montgomery form.
  20102. * b Number to subtract with in Montgomery form.
  20103. * m Modulus (prime).
  20104. */
  20105. static void sp_256_mont_sub_5(sp_digit* r, const sp_digit* a, const sp_digit* b,
  20106. const sp_digit* m)
  20107. {
  20108. (void)sp_256_sub_5(r, a, b);
  20109. sp_256_norm_5(r);
  20110. sp_256_cond_add_5(r, r, m, r[4] >> 48);
  20111. sp_256_norm_5(r);
  20112. }
  20113. /* Shift number left one bit.
  20114. * Bottom bit is lost.
  20115. *
  20116. * r Result of shift.
  20117. * a Number to shift.
  20118. */
  20119. SP_NOINLINE static void sp_256_rshift1_5(sp_digit* r, const sp_digit* a)
  20120. {
  20121. #ifdef WOLFSSL_SP_SMALL
  20122. int i;
  20123. for (i=0; i<4; i++) {
  20124. r[i] = (a[i] >> 1) + ((a[i + 1] << 51) & 0xfffffffffffffL);
  20125. }
  20126. #else
  20127. r[0] = (a[0] >> 1) + ((a[1] << 51) & 0xfffffffffffffL);
  20128. r[1] = (a[1] >> 1) + ((a[2] << 51) & 0xfffffffffffffL);
  20129. r[2] = (a[2] >> 1) + ((a[3] << 51) & 0xfffffffffffffL);
  20130. r[3] = (a[3] >> 1) + ((a[4] << 51) & 0xfffffffffffffL);
  20131. #endif
  20132. r[4] = a[4] >> 1;
  20133. }
  20134. /* Divide the number by 2 mod the modulus (prime). (r = a / 2 % m)
  20135. *
  20136. * r Result of division by 2.
  20137. * a Number to divide.
  20138. * m Modulus (prime).
  20139. */
  20140. static void sp_256_mont_div2_5(sp_digit* r, const sp_digit* a,
  20141. const sp_digit* m)
  20142. {
  20143. sp_256_cond_add_5(r, a, m, 0 - (a[0] & 1));
  20144. sp_256_norm_5(r);
  20145. sp_256_rshift1_5(r, r);
  20146. }
  20147. /* Double the Montgomery form projective point p.
  20148. *
  20149. * r Result of doubling point.
  20150. * p Point to double.
  20151. * t Temporary ordinate data.
  20152. */
  20153. static void sp_256_proj_point_dbl_5(sp_point_256* r, const sp_point_256* p,
  20154. sp_digit* t)
  20155. {
  20156. sp_digit* t1 = t;
  20157. sp_digit* t2 = t + 2*5;
  20158. sp_digit* x;
  20159. sp_digit* y;
  20160. sp_digit* z;
  20161. x = r->x;
  20162. y = r->y;
  20163. z = r->z;
  20164. /* Put infinity into result. */
  20165. if (r != p) {
  20166. r->infinity = p->infinity;
  20167. }
  20168. /* T1 = Z * Z */
  20169. sp_256_mont_sqr_5(t1, p->z, p256_mod, p256_mp_mod);
  20170. /* Z = Y * Z */
  20171. sp_256_mont_mul_5(z, p->y, p->z, p256_mod, p256_mp_mod);
  20172. /* Z = 2Z */
  20173. sp_256_mont_dbl_5(z, z, p256_mod);
  20174. /* T2 = X - T1 */
  20175. sp_256_mont_sub_5(t2, p->x, t1, p256_mod);
  20176. /* T1 = X + T1 */
  20177. sp_256_mont_add_5(t1, p->x, t1, p256_mod);
  20178. /* T2 = T1 * T2 */
  20179. sp_256_mont_mul_5(t2, t1, t2, p256_mod, p256_mp_mod);
  20180. /* T1 = 3T2 */
  20181. sp_256_mont_tpl_5(t1, t2, p256_mod);
  20182. /* Y = 2Y */
  20183. sp_256_mont_dbl_5(y, p->y, p256_mod);
  20184. /* Y = Y * Y */
  20185. sp_256_mont_sqr_5(y, y, p256_mod, p256_mp_mod);
  20186. /* T2 = Y * Y */
  20187. sp_256_mont_sqr_5(t2, y, p256_mod, p256_mp_mod);
  20188. /* T2 = T2/2 */
  20189. sp_256_mont_div2_5(t2, t2, p256_mod);
  20190. /* Y = Y * X */
  20191. sp_256_mont_mul_5(y, y, p->x, p256_mod, p256_mp_mod);
  20192. /* X = T1 * T1 */
  20193. sp_256_mont_sqr_5(x, t1, p256_mod, p256_mp_mod);
  20194. /* X = X - Y */
  20195. sp_256_mont_sub_5(x, x, y, p256_mod);
  20196. /* X = X - Y */
  20197. sp_256_mont_sub_5(x, x, y, p256_mod);
  20198. /* Y = Y - X */
  20199. sp_256_mont_sub_5(y, y, x, p256_mod);
  20200. /* Y = Y * T1 */
  20201. sp_256_mont_mul_5(y, y, t1, p256_mod, p256_mp_mod);
  20202. /* Y = Y - T2 */
  20203. sp_256_mont_sub_5(y, y, t2, p256_mod);
  20204. }
  20205. #ifdef WOLFSSL_SP_NONBLOCK
  20206. typedef struct sp_256_proj_point_dbl_5_ctx {
  20207. int state;
  20208. sp_digit* t1;
  20209. sp_digit* t2;
  20210. sp_digit* x;
  20211. sp_digit* y;
  20212. sp_digit* z;
  20213. } sp_256_proj_point_dbl_5_ctx;
  20214. /* Double the Montgomery form projective point p.
  20215. *
  20216. * r Result of doubling point.
  20217. * p Point to double.
  20218. * t Temporary ordinate data.
  20219. */
  20220. static int sp_256_proj_point_dbl_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
  20221. const sp_point_256* p, sp_digit* t)
  20222. {
  20223. int err = FP_WOULDBLOCK;
  20224. sp_256_proj_point_dbl_5_ctx* ctx = (sp_256_proj_point_dbl_5_ctx*)sp_ctx->data;
  20225. typedef char ctx_size_test[sizeof(sp_256_proj_point_dbl_5_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  20226. (void)sizeof(ctx_size_test);
  20227. switch (ctx->state) {
  20228. case 0:
  20229. ctx->t1 = t;
  20230. ctx->t2 = t + 2*5;
  20231. ctx->x = r->x;
  20232. ctx->y = r->y;
  20233. ctx->z = r->z;
  20234. /* Put infinity into result. */
  20235. if (r != p) {
  20236. r->infinity = p->infinity;
  20237. }
  20238. ctx->state = 1;
  20239. break;
  20240. case 1:
  20241. /* T1 = Z * Z */
  20242. sp_256_mont_sqr_5(ctx->t1, p->z, p256_mod, p256_mp_mod);
  20243. ctx->state = 2;
  20244. break;
  20245. case 2:
  20246. /* Z = Y * Z */
  20247. sp_256_mont_mul_5(ctx->z, p->y, p->z, p256_mod, p256_mp_mod);
  20248. ctx->state = 3;
  20249. break;
  20250. case 3:
  20251. /* Z = 2Z */
  20252. sp_256_mont_dbl_5(ctx->z, ctx->z, p256_mod);
  20253. ctx->state = 4;
  20254. break;
  20255. case 4:
  20256. /* T2 = X - T1 */
  20257. sp_256_mont_sub_5(ctx->t2, p->x, ctx->t1, p256_mod);
  20258. ctx->state = 5;
  20259. break;
  20260. case 5:
  20261. /* T1 = X + T1 */
  20262. sp_256_mont_add_5(ctx->t1, p->x, ctx->t1, p256_mod);
  20263. ctx->state = 6;
  20264. break;
  20265. case 6:
  20266. /* T2 = T1 * T2 */
  20267. sp_256_mont_mul_5(ctx->t2, ctx->t1, ctx->t2, p256_mod, p256_mp_mod);
  20268. ctx->state = 7;
  20269. break;
  20270. case 7:
  20271. /* T1 = 3T2 */
  20272. sp_256_mont_tpl_5(ctx->t1, ctx->t2, p256_mod);
  20273. ctx->state = 8;
  20274. break;
  20275. case 8:
  20276. /* Y = 2Y */
  20277. sp_256_mont_dbl_5(ctx->y, p->y, p256_mod);
  20278. ctx->state = 9;
  20279. break;
  20280. case 9:
  20281. /* Y = Y * Y */
  20282. sp_256_mont_sqr_5(ctx->y, ctx->y, p256_mod, p256_mp_mod);
  20283. ctx->state = 10;
  20284. break;
  20285. case 10:
  20286. /* T2 = Y * Y */
  20287. sp_256_mont_sqr_5(ctx->t2, ctx->y, p256_mod, p256_mp_mod);
  20288. ctx->state = 11;
  20289. break;
  20290. case 11:
  20291. /* T2 = T2/2 */
  20292. sp_256_mont_div2_5(ctx->t2, ctx->t2, p256_mod);
  20293. ctx->state = 12;
  20294. break;
  20295. case 12:
  20296. /* Y = Y * X */
  20297. sp_256_mont_mul_5(ctx->y, ctx->y, p->x, p256_mod, p256_mp_mod);
  20298. ctx->state = 13;
  20299. break;
  20300. case 13:
  20301. /* X = T1 * T1 */
  20302. sp_256_mont_sqr_5(ctx->x, ctx->t1, p256_mod, p256_mp_mod);
  20303. ctx->state = 14;
  20304. break;
  20305. case 14:
  20306. /* X = X - Y */
  20307. sp_256_mont_sub_5(ctx->x, ctx->x, ctx->y, p256_mod);
  20308. ctx->state = 15;
  20309. break;
  20310. case 15:
  20311. /* X = X - Y */
  20312. sp_256_mont_sub_5(ctx->x, ctx->x, ctx->y, p256_mod);
  20313. ctx->state = 16;
  20314. break;
  20315. case 16:
  20316. /* Y = Y - X */
  20317. sp_256_mont_sub_5(ctx->y, ctx->y, ctx->x, p256_mod);
  20318. ctx->state = 17;
  20319. break;
  20320. case 17:
  20321. /* Y = Y * T1 */
  20322. sp_256_mont_mul_5(ctx->y, ctx->y, ctx->t1, p256_mod, p256_mp_mod);
  20323. ctx->state = 18;
  20324. break;
  20325. case 18:
  20326. /* Y = Y - T2 */
  20327. sp_256_mont_sub_5(ctx->y, ctx->y, ctx->t2, p256_mod);
  20328. ctx->state = 19;
  20329. /* fall-through */
  20330. case 19:
  20331. err = MP_OKAY;
  20332. break;
  20333. }
  20334. if (err == MP_OKAY && ctx->state != 19) {
  20335. err = FP_WOULDBLOCK;
  20336. }
  20337. return err;
  20338. }
  20339. #endif /* WOLFSSL_SP_NONBLOCK */
  20340. /* Compare two numbers to determine if they are equal.
  20341. * Constant time implementation.
  20342. *
  20343. * a First number to compare.
  20344. * b Second number to compare.
  20345. * returns 1 when equal and 0 otherwise.
  20346. */
  20347. static int sp_256_cmp_equal_5(const sp_digit* a, const sp_digit* b)
  20348. {
  20349. return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) |
  20350. (a[3] ^ b[3]) | (a[4] ^ b[4])) == 0;
  20351. }
  20352. /* Returns 1 if the number of zero.
  20353. * Implementation is constant time.
  20354. *
  20355. * a Number to check.
  20356. * returns 1 if the number is zero and 0 otherwise.
  20357. */
  20358. static int sp_256_iszero_5(const sp_digit* a)
  20359. {
  20360. return (a[0] | a[1] | a[2] | a[3] | a[4]) == 0;
  20361. }
  20362. /* Add two Montgomery form projective points.
  20363. *
  20364. * r Result of addition.
  20365. * p First point to add.
  20366. * q Second point to add.
  20367. * t Temporary ordinate data.
  20368. */
  20369. static void sp_256_proj_point_add_5(sp_point_256* r,
  20370. const sp_point_256* p, const sp_point_256* q, sp_digit* t)
  20371. {
  20372. sp_digit* t6 = t;
  20373. sp_digit* t1 = t + 2*5;
  20374. sp_digit* t2 = t + 4*5;
  20375. sp_digit* t3 = t + 6*5;
  20376. sp_digit* t4 = t + 8*5;
  20377. sp_digit* t5 = t + 10*5;
  20378. /* U1 = X1*Z2^2 */
  20379. sp_256_mont_sqr_5(t1, q->z, p256_mod, p256_mp_mod);
  20380. sp_256_mont_mul_5(t3, t1, q->z, p256_mod, p256_mp_mod);
  20381. sp_256_mont_mul_5(t1, t1, p->x, p256_mod, p256_mp_mod);
  20382. /* U2 = X2*Z1^2 */
  20383. sp_256_mont_sqr_5(t2, p->z, p256_mod, p256_mp_mod);
  20384. sp_256_mont_mul_5(t4, t2, p->z, p256_mod, p256_mp_mod);
  20385. sp_256_mont_mul_5(t2, t2, q->x, p256_mod, p256_mp_mod);
  20386. /* S1 = Y1*Z2^3 */
  20387. sp_256_mont_mul_5(t3, t3, p->y, p256_mod, p256_mp_mod);
  20388. /* S2 = Y2*Z1^3 */
  20389. sp_256_mont_mul_5(t4, t4, q->y, p256_mod, p256_mp_mod);
  20390. /* Check double */
  20391. if ((~p->infinity) & (~q->infinity) &
  20392. sp_256_cmp_equal_5(t2, t1) &
  20393. sp_256_cmp_equal_5(t4, t3)) {
  20394. sp_256_proj_point_dbl_5(r, p, t);
  20395. }
  20396. else {
  20397. sp_digit* x = t6;
  20398. sp_digit* y = t1;
  20399. sp_digit* z = t2;
  20400. /* H = U2 - U1 */
  20401. sp_256_mont_sub_5(t2, t2, t1, p256_mod);
  20402. /* R = S2 - S1 */
  20403. sp_256_mont_sub_5(t4, t4, t3, p256_mod);
  20404. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  20405. sp_256_mont_sqr_5(t5, t2, p256_mod, p256_mp_mod);
  20406. sp_256_mont_mul_5(y, t1, t5, p256_mod, p256_mp_mod);
  20407. sp_256_mont_mul_5(t5, t5, t2, p256_mod, p256_mp_mod);
  20408. /* Z3 = H*Z1*Z2 */
  20409. sp_256_mont_mul_5(z, p->z, t2, p256_mod, p256_mp_mod);
  20410. sp_256_mont_mul_5(z, z, q->z, p256_mod, p256_mp_mod);
  20411. sp_256_mont_sqr_5(x, t4, p256_mod, p256_mp_mod);
  20412. sp_256_mont_sub_5(x, x, t5, p256_mod);
  20413. sp_256_mont_mul_5(t5, t5, t3, p256_mod, p256_mp_mod);
  20414. sp_256_mont_dbl_5(t3, y, p256_mod);
  20415. sp_256_mont_sub_5(x, x, t3, p256_mod);
  20416. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  20417. sp_256_mont_sub_5(y, y, x, p256_mod);
  20418. sp_256_mont_mul_5(y, y, t4, p256_mod, p256_mp_mod);
  20419. sp_256_mont_sub_5(y, y, t5, p256_mod);
  20420. {
  20421. int i;
  20422. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  20423. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  20424. sp_digit maskt = ~(maskp | maskq);
  20425. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  20426. for (i = 0; i < 5; i++) {
  20427. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  20428. (x[i] & maskt);
  20429. }
  20430. for (i = 0; i < 5; i++) {
  20431. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  20432. (y[i] & maskt);
  20433. }
  20434. for (i = 0; i < 5; i++) {
  20435. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  20436. (z[i] & maskt);
  20437. }
  20438. r->z[0] |= inf;
  20439. r->infinity = (word32)inf;
  20440. }
  20441. }
  20442. }
  20443. #ifdef WOLFSSL_SP_NONBLOCK
  20444. typedef struct sp_256_proj_point_add_5_ctx {
  20445. int state;
  20446. sp_256_proj_point_dbl_5_ctx dbl_ctx;
  20447. const sp_point_256* ap[2];
  20448. sp_point_256* rp[2];
  20449. sp_digit* t1;
  20450. sp_digit* t2;
  20451. sp_digit* t3;
  20452. sp_digit* t4;
  20453. sp_digit* t5;
  20454. sp_digit* t6;
  20455. sp_digit* x;
  20456. sp_digit* y;
  20457. sp_digit* z;
  20458. } sp_256_proj_point_add_5_ctx;
  20459. /* Add two Montgomery form projective points.
  20460. *
  20461. * r Result of addition.
  20462. * p First point to add.
  20463. * q Second point to add.
  20464. * t Temporary ordinate data.
  20465. */
  20466. static int sp_256_proj_point_add_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
  20467. const sp_point_256* p, const sp_point_256* q, sp_digit* t)
  20468. {
  20469. int err = FP_WOULDBLOCK;
  20470. sp_256_proj_point_add_5_ctx* ctx = (sp_256_proj_point_add_5_ctx*)sp_ctx->data;
  20471. /* Ensure only the first point is the same as the result. */
  20472. if (q == r) {
  20473. const sp_point_256* a = p;
  20474. p = q;
  20475. q = a;
  20476. }
  20477. typedef char ctx_size_test[sizeof(sp_256_proj_point_add_5_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  20478. (void)sizeof(ctx_size_test);
  20479. switch (ctx->state) {
  20480. case 0: /* INIT */
  20481. ctx->t6 = t;
  20482. ctx->t1 = t + 2*5;
  20483. ctx->t2 = t + 4*5;
  20484. ctx->t3 = t + 6*5;
  20485. ctx->t4 = t + 8*5;
  20486. ctx->t5 = t + 10*5;
  20487. ctx->x = ctx->t6;
  20488. ctx->y = ctx->t1;
  20489. ctx->z = ctx->t2;
  20490. ctx->state = 1;
  20491. break;
  20492. case 1:
  20493. /* U1 = X1*Z2^2 */
  20494. sp_256_mont_sqr_5(ctx->t1, q->z, p256_mod, p256_mp_mod);
  20495. ctx->state = 2;
  20496. break;
  20497. case 2:
  20498. sp_256_mont_mul_5(ctx->t3, ctx->t1, q->z, p256_mod, p256_mp_mod);
  20499. ctx->state = 3;
  20500. break;
  20501. case 3:
  20502. sp_256_mont_mul_5(ctx->t1, ctx->t1, p->x, p256_mod, p256_mp_mod);
  20503. ctx->state = 4;
  20504. break;
  20505. case 4:
  20506. /* U2 = X2*Z1^2 */
  20507. sp_256_mont_sqr_5(ctx->t2, p->z, p256_mod, p256_mp_mod);
  20508. ctx->state = 5;
  20509. break;
  20510. case 5:
  20511. sp_256_mont_mul_5(ctx->t4, ctx->t2, p->z, p256_mod, p256_mp_mod);
  20512. ctx->state = 6;
  20513. break;
  20514. case 6:
  20515. sp_256_mont_mul_5(ctx->t2, ctx->t2, q->x, p256_mod, p256_mp_mod);
  20516. ctx->state = 7;
  20517. break;
  20518. case 7:
  20519. /* S1 = Y1*Z2^3 */
  20520. sp_256_mont_mul_5(ctx->t3, ctx->t3, p->y, p256_mod, p256_mp_mod);
  20521. ctx->state = 8;
  20522. break;
  20523. case 8:
  20524. /* S2 = Y2*Z1^3 */
  20525. sp_256_mont_mul_5(ctx->t4, ctx->t4, q->y, p256_mod, p256_mp_mod);
  20526. ctx->state = 9;
  20527. break;
  20528. case 9:
  20529. /* Check double */
  20530. if ((~p->infinity) & (~q->infinity) &
  20531. sp_256_cmp_equal_5(ctx->t2, ctx->t1) &
  20532. sp_256_cmp_equal_5(ctx->t4, ctx->t3)) {
  20533. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  20534. sp_256_proj_point_dbl_5(r, p, t);
  20535. ctx->state = 25;
  20536. }
  20537. else {
  20538. ctx->state = 10;
  20539. }
  20540. break;
  20541. case 10:
  20542. /* H = U2 - U1 */
  20543. sp_256_mont_sub_5(ctx->t2, ctx->t2, ctx->t1, p256_mod);
  20544. ctx->state = 11;
  20545. break;
  20546. case 11:
  20547. /* R = S2 - S1 */
  20548. sp_256_mont_sub_5(ctx->t4, ctx->t4, ctx->t3, p256_mod);
  20549. ctx->state = 12;
  20550. break;
  20551. case 12:
  20552. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  20553. sp_256_mont_sqr_5(ctx->t5, ctx->t2, p256_mod, p256_mp_mod);
  20554. ctx->state = 13;
  20555. break;
  20556. case 13:
  20557. sp_256_mont_mul_5(ctx->y, ctx->t1, ctx->t5, p256_mod, p256_mp_mod);
  20558. ctx->state = 14;
  20559. break;
  20560. case 14:
  20561. sp_256_mont_mul_5(ctx->t5, ctx->t5, ctx->t2, p256_mod, p256_mp_mod);
  20562. ctx->state = 15;
  20563. break;
  20564. case 15:
  20565. /* Z3 = H*Z1*Z2 */
  20566. sp_256_mont_mul_5(ctx->z, p->z, ctx->t2, p256_mod, p256_mp_mod);
  20567. ctx->state = 16;
  20568. break;
  20569. case 16:
  20570. sp_256_mont_mul_5(ctx->z, ctx->z, q->z, p256_mod, p256_mp_mod);
  20571. ctx->state = 17;
  20572. break;
  20573. case 17:
  20574. sp_256_mont_sqr_5(ctx->x, ctx->t4, p256_mod, p256_mp_mod);
  20575. ctx->state = 18;
  20576. break;
  20577. case 18:
  20578. sp_256_mont_sub_5(ctx->x, ctx->x, ctx->t5, p256_mod);
  20579. ctx->state = 19;
  20580. break;
  20581. case 19:
  20582. sp_256_mont_mul_5(ctx->t5, ctx->t5, ctx->t3, p256_mod, p256_mp_mod);
  20583. ctx->state = 20;
  20584. break;
  20585. case 20:
  20586. sp_256_mont_dbl_5(ctx->t3, ctx->y, p256_mod);
  20587. sp_256_mont_sub_5(ctx->x, ctx->x, ctx->t3, p256_mod);
  20588. ctx->state = 21;
  20589. break;
  20590. case 21:
  20591. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  20592. sp_256_mont_sub_5(ctx->y, ctx->y, ctx->x, p256_mod);
  20593. ctx->state = 22;
  20594. break;
  20595. case 22:
  20596. sp_256_mont_mul_5(ctx->y, ctx->y, ctx->t4, p256_mod, p256_mp_mod);
  20597. ctx->state = 23;
  20598. break;
  20599. case 23:
  20600. sp_256_mont_sub_5(ctx->y, ctx->y, ctx->t5, p256_mod);
  20601. ctx->state = 24;
  20602. break;
  20603. case 24:
  20604. {
  20605. {
  20606. int i;
  20607. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  20608. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  20609. sp_digit maskt = ~(maskp | maskq);
  20610. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  20611. for (i = 0; i < 5; i++) {
  20612. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  20613. (ctx->x[i] & maskt);
  20614. }
  20615. for (i = 0; i < 5; i++) {
  20616. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  20617. (ctx->y[i] & maskt);
  20618. }
  20619. for (i = 0; i < 5; i++) {
  20620. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  20621. (ctx->z[i] & maskt);
  20622. }
  20623. r->z[0] |= inf;
  20624. r->infinity = (word32)inf;
  20625. }
  20626. ctx->state = 25;
  20627. break;
  20628. }
  20629. case 25:
  20630. err = MP_OKAY;
  20631. break;
  20632. }
  20633. if (err == MP_OKAY && ctx->state != 25) {
  20634. err = FP_WOULDBLOCK;
  20635. }
  20636. return err;
  20637. }
  20638. #endif /* WOLFSSL_SP_NONBLOCK */
  20639. /* Multiply a number by Montgomery normalizer mod modulus (prime).
  20640. *
  20641. * r The resulting Montgomery form number.
  20642. * a The number to convert.
  20643. * m The modulus (prime).
  20644. * returns MEMORY_E when memory allocation fails and MP_OKAY otherwise.
  20645. */
  20646. static int sp_256_mod_mul_norm_5(sp_digit* r, const sp_digit* a, const sp_digit* m)
  20647. {
  20648. #ifdef WOLFSSL_SP_SMALL_STACK
  20649. int64_t* t = NULL;
  20650. #else
  20651. int64_t t[2 * 8];
  20652. #endif
  20653. int64_t* a32 = NULL;
  20654. int64_t o;
  20655. int err = MP_OKAY;
  20656. (void)m;
  20657. #ifdef WOLFSSL_SP_SMALL_STACK
  20658. t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 8, NULL, DYNAMIC_TYPE_ECC);
  20659. if (t == NULL)
  20660. return MEMORY_E;
  20661. #endif
  20662. if (err == MP_OKAY) {
  20663. a32 = t + 8;
  20664. a32[0] = (sp_digit)(a[0]) & 0xffffffffL;
  20665. a32[1] = (sp_digit)(a[0] >> 32U);
  20666. a32[1] |= (sp_digit)(a[1] << 20U);
  20667. a32[1] &= 0xffffffffL;
  20668. a32[2] = (sp_digit)(a[1] >> 12U) & 0xffffffffL;
  20669. a32[3] = (sp_digit)(a[1] >> 44U);
  20670. a32[3] |= (sp_digit)(a[2] << 8U);
  20671. a32[3] &= 0xffffffffL;
  20672. a32[4] = (sp_digit)(a[2] >> 24U);
  20673. a32[4] |= (sp_digit)(a[3] << 28U);
  20674. a32[4] &= 0xffffffffL;
  20675. a32[5] = (sp_digit)(a[3] >> 4U) & 0xffffffffL;
  20676. a32[6] = (sp_digit)(a[3] >> 36U);
  20677. a32[6] |= (sp_digit)(a[4] << 16U);
  20678. a32[6] &= 0xffffffffL;
  20679. a32[7] = (sp_digit)(a[4] >> 16U) & 0xffffffffL;
  20680. /* 1 1 0 -1 -1 -1 -1 0 */
  20681. t[0] = 0 + a32[0] + a32[1] - a32[3] - a32[4] - a32[5] - a32[6];
  20682. /* 0 1 1 0 -1 -1 -1 -1 */
  20683. t[1] = 0 + a32[1] + a32[2] - a32[4] - a32[5] - a32[6] - a32[7];
  20684. /* 0 0 1 1 0 -1 -1 -1 */
  20685. t[2] = 0 + a32[2] + a32[3] - a32[5] - a32[6] - a32[7];
  20686. /* -1 -1 0 2 2 1 0 -1 */
  20687. t[3] = 0 - a32[0] - a32[1] + 2 * a32[3] + 2 * a32[4] + a32[5] - a32[7];
  20688. /* 0 -1 -1 0 2 2 1 0 */
  20689. t[4] = 0 - a32[1] - a32[2] + 2 * a32[4] + 2 * a32[5] + a32[6];
  20690. /* 0 0 -1 -1 0 2 2 1 */
  20691. t[5] = 0 - a32[2] - a32[3] + 2 * a32[5] + 2 * a32[6] + a32[7];
  20692. /* -1 -1 0 0 0 1 3 2 */
  20693. t[6] = 0 - a32[0] - a32[1] + a32[5] + 3 * a32[6] + 2 * a32[7];
  20694. /* 1 0 -1 -1 -1 -1 0 3 */
  20695. t[7] = 0 + a32[0] - a32[2] - a32[3] - a32[4] - a32[5] + 3 * a32[7];
  20696. t[1] += t[0] >> 32U; t[0] &= 0xffffffffL;
  20697. t[2] += t[1] >> 32U; t[1] &= 0xffffffffL;
  20698. t[3] += t[2] >> 32U; t[2] &= 0xffffffffL;
  20699. t[4] += t[3] >> 32U; t[3] &= 0xffffffffL;
  20700. t[5] += t[4] >> 32U; t[4] &= 0xffffffffL;
  20701. t[6] += t[5] >> 32U; t[5] &= 0xffffffffL;
  20702. t[7] += t[6] >> 32U; t[6] &= 0xffffffffL;
  20703. o = t[7] >> 32U; t[7] &= 0xffffffffL;
  20704. t[0] += o;
  20705. t[3] -= o;
  20706. t[6] -= o;
  20707. t[7] += o;
  20708. t[1] += t[0] >> 32U; t[0] &= 0xffffffffL;
  20709. t[2] += t[1] >> 32U; t[1] &= 0xffffffffL;
  20710. t[3] += t[2] >> 32U; t[2] &= 0xffffffffL;
  20711. t[4] += t[3] >> 32U; t[3] &= 0xffffffffL;
  20712. t[5] += t[4] >> 32U; t[4] &= 0xffffffffL;
  20713. t[6] += t[5] >> 32U; t[5] &= 0xffffffffL;
  20714. t[7] += t[6] >> 32U; t[6] &= 0xffffffffL;
  20715. r[0] = t[0];
  20716. r[0] |= t[1] << 32U;
  20717. r[0] &= 0xfffffffffffffLL;
  20718. r[1] = (t[1] >> 20);
  20719. r[1] |= t[2] << 12U;
  20720. r[1] |= t[3] << 44U;
  20721. r[1] &= 0xfffffffffffffLL;
  20722. r[2] = (t[3] >> 8);
  20723. r[2] |= t[4] << 24U;
  20724. r[2] &= 0xfffffffffffffLL;
  20725. r[3] = (t[4] >> 28);
  20726. r[3] |= t[5] << 4U;
  20727. r[3] |= t[6] << 36U;
  20728. r[3] &= 0xfffffffffffffLL;
  20729. r[4] = (t[6] >> 16);
  20730. r[4] |= t[7] << 16U;
  20731. }
  20732. #ifdef WOLFSSL_SP_SMALL_STACK
  20733. if (t != NULL)
  20734. XFREE(t, NULL, DYNAMIC_TYPE_ECC);
  20735. #endif
  20736. return err;
  20737. }
  20738. #ifdef WOLFSSL_SP_SMALL
  20739. /* Multiply the point by the scalar and return the result.
  20740. * If map is true then convert result to affine coordinates.
  20741. *
  20742. * Small implementation using add and double that is cache attack resistant but
  20743. * allocates memory rather than use large stacks.
  20744. * 256 adds and doubles.
  20745. *
  20746. * r Resulting point.
  20747. * g Point to multiply.
  20748. * k Scalar to multiply by.
  20749. * map Indicates whether to convert result to affine.
  20750. * ct Constant time required.
  20751. * heap Heap to use for allocation.
  20752. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  20753. */
  20754. static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g,
  20755. const sp_digit* k, int map, int ct, void* heap)
  20756. {
  20757. #ifdef WOLFSSL_SP_SMALL_STACK
  20758. sp_point_256* t = NULL;
  20759. sp_digit* tmp = NULL;
  20760. #else
  20761. sp_point_256 t[3];
  20762. sp_digit tmp[2 * 5 * 6];
  20763. #endif
  20764. sp_digit n;
  20765. int i;
  20766. int c;
  20767. int y;
  20768. int err = MP_OKAY;
  20769. /* Implementation is constant time. */
  20770. (void)ct;
  20771. (void)heap;
  20772. #ifdef WOLFSSL_SP_SMALL_STACK
  20773. t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap,
  20774. DYNAMIC_TYPE_ECC);
  20775. if (t == NULL)
  20776. err = MEMORY_E;
  20777. if (err == MP_OKAY) {
  20778. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 6, heap,
  20779. DYNAMIC_TYPE_ECC);
  20780. if (tmp == NULL)
  20781. err = MEMORY_E;
  20782. }
  20783. #endif
  20784. if (err == MP_OKAY) {
  20785. XMEMSET(t, 0, sizeof(sp_point_256) * 3);
  20786. /* t[0] = {0, 0, 1} * norm */
  20787. t[0].infinity = 1;
  20788. /* t[1] = {g->x, g->y, g->z} * norm */
  20789. err = sp_256_mod_mul_norm_5(t[1].x, g->x, p256_mod);
  20790. }
  20791. if (err == MP_OKAY)
  20792. err = sp_256_mod_mul_norm_5(t[1].y, g->y, p256_mod);
  20793. if (err == MP_OKAY)
  20794. err = sp_256_mod_mul_norm_5(t[1].z, g->z, p256_mod);
  20795. if (err == MP_OKAY) {
  20796. i = 4;
  20797. c = 48;
  20798. n = k[i--] << (52 - c);
  20799. for (; ; c--) {
  20800. if (c == 0) {
  20801. if (i == -1)
  20802. break;
  20803. n = k[i--];
  20804. c = 52;
  20805. }
  20806. y = (n >> 51) & 1;
  20807. n <<= 1;
  20808. sp_256_proj_point_add_5(&t[y^1], &t[0], &t[1], tmp);
  20809. XMEMCPY(&t[2], (void*)(((size_t)&t[0] & addr_mask[y^1]) +
  20810. ((size_t)&t[1] & addr_mask[y])),
  20811. sizeof(sp_point_256));
  20812. sp_256_proj_point_dbl_5(&t[2], &t[2], tmp);
  20813. XMEMCPY((void*)(((size_t)&t[0] & addr_mask[y^1]) +
  20814. ((size_t)&t[1] & addr_mask[y])), &t[2],
  20815. sizeof(sp_point_256));
  20816. }
  20817. if (map != 0) {
  20818. sp_256_map_5(r, &t[0], tmp);
  20819. }
  20820. else {
  20821. XMEMCPY(r, &t[0], sizeof(sp_point_256));
  20822. }
  20823. }
  20824. #ifdef WOLFSSL_SP_SMALL_STACK
  20825. if (tmp != NULL)
  20826. #endif
  20827. {
  20828. ForceZero(tmp, sizeof(sp_digit) * 2 * 5 * 6);
  20829. #ifdef WOLFSSL_SP_SMALL_STACK
  20830. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  20831. #endif
  20832. }
  20833. #ifdef WOLFSSL_SP_SMALL_STACK
  20834. if (t != NULL)
  20835. #endif
  20836. {
  20837. ForceZero(t, sizeof(sp_point_256) * 3);
  20838. #ifdef WOLFSSL_SP_SMALL_STACK
  20839. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  20840. #endif
  20841. }
  20842. return err;
  20843. }
  20844. #ifdef WOLFSSL_SP_NONBLOCK
  20845. typedef struct sp_256_ecc_mulmod_5_ctx {
  20846. int state;
  20847. union {
  20848. sp_256_proj_point_dbl_5_ctx dbl_ctx;
  20849. sp_256_proj_point_add_5_ctx add_ctx;
  20850. };
  20851. sp_point_256 t[3];
  20852. sp_digit tmp[2 * 5 * 6];
  20853. sp_digit n;
  20854. int i;
  20855. int c;
  20856. int y;
  20857. } sp_256_ecc_mulmod_5_ctx;
  20858. static int sp_256_ecc_mulmod_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
  20859. const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap)
  20860. {
  20861. int err = FP_WOULDBLOCK;
  20862. sp_256_ecc_mulmod_5_ctx* ctx = (sp_256_ecc_mulmod_5_ctx*)sp_ctx->data;
  20863. typedef char ctx_size_test[sizeof(sp_256_ecc_mulmod_5_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  20864. (void)sizeof(ctx_size_test);
  20865. /* Implementation is constant time. */
  20866. (void)ct;
  20867. switch (ctx->state) {
  20868. case 0: /* INIT */
  20869. XMEMSET(ctx->t, 0, sizeof(sp_point_256) * 3);
  20870. ctx->i = 4;
  20871. ctx->c = 48;
  20872. ctx->n = k[ctx->i--] << (52 - ctx->c);
  20873. /* t[0] = {0, 0, 1} * norm */
  20874. ctx->t[0].infinity = 1;
  20875. ctx->state = 1;
  20876. break;
  20877. case 1: /* T1X */
  20878. /* t[1] = {g->x, g->y, g->z} * norm */
  20879. err = sp_256_mod_mul_norm_5(ctx->t[1].x, g->x, p256_mod);
  20880. ctx->state = 2;
  20881. break;
  20882. case 2: /* T1Y */
  20883. err = sp_256_mod_mul_norm_5(ctx->t[1].y, g->y, p256_mod);
  20884. ctx->state = 3;
  20885. break;
  20886. case 3: /* T1Z */
  20887. err = sp_256_mod_mul_norm_5(ctx->t[1].z, g->z, p256_mod);
  20888. ctx->state = 4;
  20889. break;
  20890. case 4: /* ADDPREP */
  20891. if (ctx->c == 0) {
  20892. if (ctx->i == -1) {
  20893. ctx->state = 7;
  20894. break;
  20895. }
  20896. ctx->n = k[ctx->i--];
  20897. ctx->c = 52;
  20898. }
  20899. ctx->y = (ctx->n >> 51) & 1;
  20900. ctx->n <<= 1;
  20901. XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx));
  20902. ctx->state = 5;
  20903. break;
  20904. case 5: /* ADD */
  20905. err = sp_256_proj_point_add_5_nb((sp_ecc_ctx_t*)&ctx->add_ctx,
  20906. &ctx->t[ctx->y^1], &ctx->t[0], &ctx->t[1], ctx->tmp);
  20907. if (err == MP_OKAY) {
  20908. XMEMCPY(&ctx->t[2], (void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  20909. ((size_t)&ctx->t[1] & addr_mask[ctx->y])),
  20910. sizeof(sp_point_256));
  20911. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  20912. ctx->state = 6;
  20913. }
  20914. break;
  20915. case 6: /* DBL */
  20916. err = sp_256_proj_point_dbl_5_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->t[2],
  20917. &ctx->t[2], ctx->tmp);
  20918. if (err == MP_OKAY) {
  20919. XMEMCPY((void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  20920. ((size_t)&ctx->t[1] & addr_mask[ctx->y])), &ctx->t[2],
  20921. sizeof(sp_point_256));
  20922. ctx->state = 4;
  20923. ctx->c--;
  20924. }
  20925. break;
  20926. case 7: /* MAP */
  20927. if (map != 0) {
  20928. sp_256_map_5(r, &ctx->t[0], ctx->tmp);
  20929. }
  20930. else {
  20931. XMEMCPY(r, &ctx->t[0], sizeof(sp_point_256));
  20932. }
  20933. err = MP_OKAY;
  20934. break;
  20935. }
  20936. if (err == MP_OKAY && ctx->state != 7) {
  20937. err = FP_WOULDBLOCK;
  20938. }
  20939. if (err != FP_WOULDBLOCK) {
  20940. ForceZero(ctx->tmp, sizeof(ctx->tmp));
  20941. ForceZero(ctx->t, sizeof(ctx->t));
  20942. }
  20943. (void)heap;
  20944. return err;
  20945. }
  20946. #endif /* WOLFSSL_SP_NONBLOCK */
  20947. #else
  20948. /* A table entry for pre-computed points. */
  20949. typedef struct sp_table_entry_256 {
  20950. sp_digit x[5];
  20951. sp_digit y[5];
  20952. } sp_table_entry_256;
  20953. /* Conditionally copy a into r using the mask m.
  20954. * m is -1 to copy and 0 when not.
  20955. *
  20956. * r A single precision number to copy over.
  20957. * a A single precision number to copy.
  20958. * m Mask value to apply.
  20959. */
  20960. static void sp_256_cond_copy_5(sp_digit* r, const sp_digit* a, const sp_digit m)
  20961. {
  20962. sp_digit t[5];
  20963. #ifdef WOLFSSL_SP_SMALL
  20964. int i;
  20965. for (i = 0; i < 5; i++) {
  20966. t[i] = r[i] ^ a[i];
  20967. }
  20968. for (i = 0; i < 5; i++) {
  20969. r[i] ^= t[i] & m;
  20970. }
  20971. #else
  20972. t[ 0] = r[ 0] ^ a[ 0];
  20973. t[ 1] = r[ 1] ^ a[ 1];
  20974. t[ 2] = r[ 2] ^ a[ 2];
  20975. t[ 3] = r[ 3] ^ a[ 3];
  20976. t[ 4] = r[ 4] ^ a[ 4];
  20977. r[ 0] ^= t[ 0] & m;
  20978. r[ 1] ^= t[ 1] & m;
  20979. r[ 2] ^= t[ 2] & m;
  20980. r[ 3] ^= t[ 3] & m;
  20981. r[ 4] ^= t[ 4] & m;
  20982. #endif /* WOLFSSL_SP_SMALL */
  20983. }
  20984. /* Double the Montgomery form projective point p a number of times.
  20985. *
  20986. * r Result of repeated doubling of point.
  20987. * p Point to double.
  20988. * n Number of times to double
  20989. * t Temporary ordinate data.
  20990. */
  20991. static void sp_256_proj_point_dbl_n_5(sp_point_256* p, int i,
  20992. sp_digit* t)
  20993. {
  20994. sp_digit* w = t;
  20995. sp_digit* a = t + 2*5;
  20996. sp_digit* b = t + 4*5;
  20997. sp_digit* t1 = t + 6*5;
  20998. sp_digit* t2 = t + 8*5;
  20999. sp_digit* x;
  21000. sp_digit* y;
  21001. sp_digit* z;
  21002. volatile int n = i;
  21003. x = p->x;
  21004. y = p->y;
  21005. z = p->z;
  21006. /* Y = 2*Y */
  21007. sp_256_mont_dbl_5(y, y, p256_mod);
  21008. /* W = Z^4 */
  21009. sp_256_mont_sqr_5(w, z, p256_mod, p256_mp_mod);
  21010. sp_256_mont_sqr_5(w, w, p256_mod, p256_mp_mod);
  21011. #ifndef WOLFSSL_SP_SMALL
  21012. while (--n > 0)
  21013. #else
  21014. while (--n >= 0)
  21015. #endif
  21016. {
  21017. /* A = 3*(X^2 - W) */
  21018. sp_256_mont_sqr_5(t1, x, p256_mod, p256_mp_mod);
  21019. sp_256_mont_sub_5(t1, t1, w, p256_mod);
  21020. sp_256_mont_tpl_5(a, t1, p256_mod);
  21021. /* B = X*Y^2 */
  21022. sp_256_mont_sqr_5(t1, y, p256_mod, p256_mp_mod);
  21023. sp_256_mont_mul_5(b, t1, x, p256_mod, p256_mp_mod);
  21024. /* X = A^2 - 2B */
  21025. sp_256_mont_sqr_5(x, a, p256_mod, p256_mp_mod);
  21026. sp_256_mont_dbl_5(t2, b, p256_mod);
  21027. sp_256_mont_sub_5(x, x, t2, p256_mod);
  21028. /* B = 2.(B - X) */
  21029. sp_256_mont_sub_5(t2, b, x, p256_mod);
  21030. sp_256_mont_dbl_5(b, t2, p256_mod);
  21031. /* Z = Z*Y */
  21032. sp_256_mont_mul_5(z, z, y, p256_mod, p256_mp_mod);
  21033. /* t1 = Y^4 */
  21034. sp_256_mont_sqr_5(t1, t1, p256_mod, p256_mp_mod);
  21035. #ifdef WOLFSSL_SP_SMALL
  21036. if (n != 0)
  21037. #endif
  21038. {
  21039. /* W = W*Y^4 */
  21040. sp_256_mont_mul_5(w, w, t1, p256_mod, p256_mp_mod);
  21041. }
  21042. /* y = 2*A*(B - X) - Y^4 */
  21043. sp_256_mont_mul_5(y, b, a, p256_mod, p256_mp_mod);
  21044. sp_256_mont_sub_5(y, y, t1, p256_mod);
  21045. }
  21046. #ifndef WOLFSSL_SP_SMALL
  21047. /* A = 3*(X^2 - W) */
  21048. sp_256_mont_sqr_5(t1, x, p256_mod, p256_mp_mod);
  21049. sp_256_mont_sub_5(t1, t1, w, p256_mod);
  21050. sp_256_mont_tpl_5(a, t1, p256_mod);
  21051. /* B = X*Y^2 */
  21052. sp_256_mont_sqr_5(t1, y, p256_mod, p256_mp_mod);
  21053. sp_256_mont_mul_5(b, t1, x, p256_mod, p256_mp_mod);
  21054. /* X = A^2 - 2B */
  21055. sp_256_mont_sqr_5(x, a, p256_mod, p256_mp_mod);
  21056. sp_256_mont_dbl_5(t2, b, p256_mod);
  21057. sp_256_mont_sub_5(x, x, t2, p256_mod);
  21058. /* B = 2.(B - X) */
  21059. sp_256_mont_sub_5(t2, b, x, p256_mod);
  21060. sp_256_mont_dbl_5(b, t2, p256_mod);
  21061. /* Z = Z*Y */
  21062. sp_256_mont_mul_5(z, z, y, p256_mod, p256_mp_mod);
  21063. /* t1 = Y^4 */
  21064. sp_256_mont_sqr_5(t1, t1, p256_mod, p256_mp_mod);
  21065. /* y = 2*A*(B - X) - Y^4 */
  21066. sp_256_mont_mul_5(y, b, a, p256_mod, p256_mp_mod);
  21067. sp_256_mont_sub_5(y, y, t1, p256_mod);
  21068. #endif /* WOLFSSL_SP_SMALL */
  21069. /* Y = Y/2 */
  21070. sp_256_mont_div2_5(y, y, p256_mod);
  21071. }
  21072. /* Double the Montgomery form projective point p a number of times.
  21073. *
  21074. * r Result of repeated doubling of point.
  21075. * p Point to double.
  21076. * n Number of times to double
  21077. * t Temporary ordinate data.
  21078. */
  21079. static void sp_256_proj_point_dbl_n_store_5(sp_point_256* r,
  21080. const sp_point_256* p, int n, int m, sp_digit* t)
  21081. {
  21082. sp_digit* w = t;
  21083. sp_digit* a = t + 2*5;
  21084. sp_digit* b = t + 4*5;
  21085. sp_digit* t1 = t + 6*5;
  21086. sp_digit* t2 = t + 8*5;
  21087. sp_digit* x = r[2*m].x;
  21088. sp_digit* y = r[(1<<n)*m].y;
  21089. sp_digit* z = r[2*m].z;
  21090. int i;
  21091. int j;
  21092. for (i=0; i<5; i++) {
  21093. x[i] = p->x[i];
  21094. }
  21095. for (i=0; i<5; i++) {
  21096. y[i] = p->y[i];
  21097. }
  21098. for (i=0; i<5; i++) {
  21099. z[i] = p->z[i];
  21100. }
  21101. /* Y = 2*Y */
  21102. sp_256_mont_dbl_5(y, y, p256_mod);
  21103. /* W = Z^4 */
  21104. sp_256_mont_sqr_5(w, z, p256_mod, p256_mp_mod);
  21105. sp_256_mont_sqr_5(w, w, p256_mod, p256_mp_mod);
  21106. j = m;
  21107. for (i=1; i<=n; i++) {
  21108. j *= 2;
  21109. /* A = 3*(X^2 - W) */
  21110. sp_256_mont_sqr_5(t1, x, p256_mod, p256_mp_mod);
  21111. sp_256_mont_sub_5(t1, t1, w, p256_mod);
  21112. sp_256_mont_tpl_5(a, t1, p256_mod);
  21113. /* B = X*Y^2 */
  21114. sp_256_mont_sqr_5(t1, y, p256_mod, p256_mp_mod);
  21115. sp_256_mont_mul_5(b, t1, x, p256_mod, p256_mp_mod);
  21116. x = r[j].x;
  21117. /* X = A^2 - 2B */
  21118. sp_256_mont_sqr_5(x, a, p256_mod, p256_mp_mod);
  21119. sp_256_mont_dbl_5(t2, b, p256_mod);
  21120. sp_256_mont_sub_5(x, x, t2, p256_mod);
  21121. /* B = 2.(B - X) */
  21122. sp_256_mont_sub_5(t2, b, x, p256_mod);
  21123. sp_256_mont_dbl_5(b, t2, p256_mod);
  21124. /* Z = Z*Y */
  21125. sp_256_mont_mul_5(r[j].z, z, y, p256_mod, p256_mp_mod);
  21126. z = r[j].z;
  21127. /* t1 = Y^4 */
  21128. sp_256_mont_sqr_5(t1, t1, p256_mod, p256_mp_mod);
  21129. if (i != n) {
  21130. /* W = W*Y^4 */
  21131. sp_256_mont_mul_5(w, w, t1, p256_mod, p256_mp_mod);
  21132. }
  21133. /* y = 2*A*(B - X) - Y^4 */
  21134. sp_256_mont_mul_5(y, b, a, p256_mod, p256_mp_mod);
  21135. sp_256_mont_sub_5(y, y, t1, p256_mod);
  21136. /* Y = Y/2 */
  21137. sp_256_mont_div2_5(r[j].y, y, p256_mod);
  21138. r[j].infinity = 0;
  21139. }
  21140. }
  21141. /* Add two Montgomery form projective points.
  21142. *
  21143. * ra Result of addition.
  21144. * rs Result of subtraction.
  21145. * p First point to add.
  21146. * q Second point to add.
  21147. * t Temporary ordinate data.
  21148. */
  21149. static void sp_256_proj_point_add_sub_5(sp_point_256* ra,
  21150. sp_point_256* rs, const sp_point_256* p, const sp_point_256* q,
  21151. sp_digit* t)
  21152. {
  21153. sp_digit* t1 = t;
  21154. sp_digit* t2 = t + 2*5;
  21155. sp_digit* t3 = t + 4*5;
  21156. sp_digit* t4 = t + 6*5;
  21157. sp_digit* t5 = t + 8*5;
  21158. sp_digit* t6 = t + 10*5;
  21159. sp_digit* xa = ra->x;
  21160. sp_digit* ya = ra->y;
  21161. sp_digit* za = ra->z;
  21162. sp_digit* xs = rs->x;
  21163. sp_digit* ys = rs->y;
  21164. sp_digit* zs = rs->z;
  21165. XMEMCPY(xa, p->x, sizeof(p->x) / 2);
  21166. XMEMCPY(ya, p->y, sizeof(p->y) / 2);
  21167. XMEMCPY(za, p->z, sizeof(p->z) / 2);
  21168. ra->infinity = 0;
  21169. rs->infinity = 0;
  21170. /* U1 = X1*Z2^2 */
  21171. sp_256_mont_sqr_5(t1, q->z, p256_mod, p256_mp_mod);
  21172. sp_256_mont_mul_5(t3, t1, q->z, p256_mod, p256_mp_mod);
  21173. sp_256_mont_mul_5(t1, t1, xa, p256_mod, p256_mp_mod);
  21174. /* U2 = X2*Z1^2 */
  21175. sp_256_mont_sqr_5(t2, za, p256_mod, p256_mp_mod);
  21176. sp_256_mont_mul_5(t4, t2, za, p256_mod, p256_mp_mod);
  21177. sp_256_mont_mul_5(t2, t2, q->x, p256_mod, p256_mp_mod);
  21178. /* S1 = Y1*Z2^3 */
  21179. sp_256_mont_mul_5(t3, t3, ya, p256_mod, p256_mp_mod);
  21180. /* S2 = Y2*Z1^3 */
  21181. sp_256_mont_mul_5(t4, t4, q->y, p256_mod, p256_mp_mod);
  21182. /* H = U2 - U1 */
  21183. sp_256_mont_sub_5(t2, t2, t1, p256_mod);
  21184. /* RS = S2 + S1 */
  21185. sp_256_mont_add_5(t6, t4, t3, p256_mod);
  21186. /* R = S2 - S1 */
  21187. sp_256_mont_sub_5(t4, t4, t3, p256_mod);
  21188. /* Z3 = H*Z1*Z2 */
  21189. /* ZS = H*Z1*Z2 */
  21190. sp_256_mont_mul_5(za, za, q->z, p256_mod, p256_mp_mod);
  21191. sp_256_mont_mul_5(za, za, t2, p256_mod, p256_mp_mod);
  21192. XMEMCPY(zs, za, sizeof(p->z)/2);
  21193. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  21194. /* XS = RS^2 - H^3 - 2*U1*H^2 */
  21195. sp_256_mont_sqr_5(xa, t4, p256_mod, p256_mp_mod);
  21196. sp_256_mont_sqr_5(xs, t6, p256_mod, p256_mp_mod);
  21197. sp_256_mont_sqr_5(t5, t2, p256_mod, p256_mp_mod);
  21198. sp_256_mont_mul_5(ya, t1, t5, p256_mod, p256_mp_mod);
  21199. sp_256_mont_mul_5(t5, t5, t2, p256_mod, p256_mp_mod);
  21200. sp_256_mont_sub_5(xa, xa, t5, p256_mod);
  21201. sp_256_mont_sub_5(xs, xs, t5, p256_mod);
  21202. sp_256_mont_dbl_5(t1, ya, p256_mod);
  21203. sp_256_mont_sub_5(xa, xa, t1, p256_mod);
  21204. sp_256_mont_sub_5(xs, xs, t1, p256_mod);
  21205. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  21206. /* YS = -RS*(U1*H^2 - XS) - S1*H^3 */
  21207. sp_256_mont_sub_5(ys, ya, xs, p256_mod);
  21208. sp_256_mont_sub_5(ya, ya, xa, p256_mod);
  21209. sp_256_mont_mul_5(ya, ya, t4, p256_mod, p256_mp_mod);
  21210. sp_256_sub_5(t6, p256_mod, t6);
  21211. sp_256_mont_mul_5(ys, ys, t6, p256_mod, p256_mp_mod);
  21212. sp_256_mont_mul_5(t5, t5, t3, p256_mod, p256_mp_mod);
  21213. sp_256_mont_sub_5(ya, ya, t5, p256_mod);
  21214. sp_256_mont_sub_5(ys, ys, t5, p256_mod);
  21215. }
  21216. /* Structure used to describe recoding of scalar multiplication. */
  21217. typedef struct ecc_recode_256 {
  21218. /* Index into pre-computation table. */
  21219. uint8_t i;
  21220. /* Use the negative of the point. */
  21221. uint8_t neg;
  21222. } ecc_recode_256;
  21223. /* The index into pre-computation table to use. */
  21224. static const uint8_t recode_index_5_6[66] = {
  21225. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  21226. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  21227. 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
  21228. 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
  21229. 0, 1,
  21230. };
  21231. /* Whether to negate y-ordinate. */
  21232. static const uint8_t recode_neg_5_6[66] = {
  21233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21235. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  21236. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  21237. 0, 0,
  21238. };
  21239. /* Recode the scalar for multiplication using pre-computed values and
  21240. * subtraction.
  21241. *
  21242. * k Scalar to multiply by.
  21243. * v Vector of operations to perform.
  21244. */
  21245. static void sp_256_ecc_recode_6_5(const sp_digit* k, ecc_recode_256* v)
  21246. {
  21247. int i;
  21248. int j;
  21249. uint8_t y;
  21250. int carry = 0;
  21251. int o;
  21252. sp_digit n;
  21253. j = 0;
  21254. n = k[j];
  21255. o = 0;
  21256. for (i=0; i<43; i++) {
  21257. y = (int8_t)n;
  21258. if (o + 6 < 52) {
  21259. y &= 0x3f;
  21260. n >>= 6;
  21261. o += 6;
  21262. }
  21263. else if (o + 6 == 52) {
  21264. n >>= 6;
  21265. if (++j < 5)
  21266. n = k[j];
  21267. o = 0;
  21268. }
  21269. else if (++j < 5) {
  21270. n = k[j];
  21271. y |= (uint8_t)((n << (52 - o)) & 0x3f);
  21272. o -= 46;
  21273. n >>= o;
  21274. }
  21275. y += (uint8_t)carry;
  21276. v[i].i = recode_index_5_6[y];
  21277. v[i].neg = recode_neg_5_6[y];
  21278. carry = (y >> 6) + v[i].neg;
  21279. }
  21280. }
  21281. #ifndef WC_NO_CACHE_RESISTANT
  21282. /* Touch each possible point that could be being copied.
  21283. *
  21284. * r Point to copy into.
  21285. * table Table - start of the entries to access
  21286. * idx Index of entry to retrieve.
  21287. */
  21288. static void sp_256_get_point_33_5(sp_point_256* r, const sp_point_256* table,
  21289. int idx)
  21290. {
  21291. int i;
  21292. sp_digit mask;
  21293. r->x[0] = 0;
  21294. r->x[1] = 0;
  21295. r->x[2] = 0;
  21296. r->x[3] = 0;
  21297. r->x[4] = 0;
  21298. r->y[0] = 0;
  21299. r->y[1] = 0;
  21300. r->y[2] = 0;
  21301. r->y[3] = 0;
  21302. r->y[4] = 0;
  21303. r->z[0] = 0;
  21304. r->z[1] = 0;
  21305. r->z[2] = 0;
  21306. r->z[3] = 0;
  21307. r->z[4] = 0;
  21308. for (i = 1; i < 33; i++) {
  21309. mask = 0 - (i == idx);
  21310. r->x[0] |= mask & table[i].x[0];
  21311. r->x[1] |= mask & table[i].x[1];
  21312. r->x[2] |= mask & table[i].x[2];
  21313. r->x[3] |= mask & table[i].x[3];
  21314. r->x[4] |= mask & table[i].x[4];
  21315. r->y[0] |= mask & table[i].y[0];
  21316. r->y[1] |= mask & table[i].y[1];
  21317. r->y[2] |= mask & table[i].y[2];
  21318. r->y[3] |= mask & table[i].y[3];
  21319. r->y[4] |= mask & table[i].y[4];
  21320. r->z[0] |= mask & table[i].z[0];
  21321. r->z[1] |= mask & table[i].z[1];
  21322. r->z[2] |= mask & table[i].z[2];
  21323. r->z[3] |= mask & table[i].z[3];
  21324. r->z[4] |= mask & table[i].z[4];
  21325. }
  21326. }
  21327. #endif /* !WC_NO_CACHE_RESISTANT */
  21328. /* Multiply the point by the scalar and return the result.
  21329. * If map is true then convert result to affine coordinates.
  21330. *
  21331. * Window technique of 6 bits. (Add-Sub variation.)
  21332. * Calculate 0..32 times the point. Use function that adds and
  21333. * subtracts the same two points.
  21334. * Recode to add or subtract one of the computed points.
  21335. * Double to push up.
  21336. * NOT a sliding window.
  21337. *
  21338. * r Resulting point.
  21339. * g Point to multiply.
  21340. * k Scalar to multiply by.
  21341. * map Indicates whether to convert result to affine.
  21342. * ct Constant time required.
  21343. * heap Heap to use for allocation.
  21344. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  21345. */
  21346. static int sp_256_ecc_mulmod_win_add_sub_5(sp_point_256* r, const sp_point_256* g,
  21347. const sp_digit* k, int map, int ct, void* heap)
  21348. {
  21349. #ifdef WOLFSSL_SP_SMALL_STACK
  21350. sp_point_256* t = NULL;
  21351. sp_digit* tmp = NULL;
  21352. #else
  21353. sp_point_256 t[33+2];
  21354. sp_digit tmp[2 * 5 * 6];
  21355. #endif
  21356. sp_point_256* rt = NULL;
  21357. sp_point_256* p = NULL;
  21358. sp_digit* negy;
  21359. int i;
  21360. ecc_recode_256 v[43];
  21361. int err = MP_OKAY;
  21362. /* Constant time used for cache attack resistance implementation. */
  21363. (void)ct;
  21364. (void)heap;
  21365. #ifdef WOLFSSL_SP_SMALL_STACK
  21366. t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) *
  21367. (33+2), heap, DYNAMIC_TYPE_ECC);
  21368. if (t == NULL)
  21369. err = MEMORY_E;
  21370. if (err == MP_OKAY) {
  21371. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 6,
  21372. heap, DYNAMIC_TYPE_ECC);
  21373. if (tmp == NULL)
  21374. err = MEMORY_E;
  21375. }
  21376. #endif
  21377. if (err == MP_OKAY) {
  21378. rt = t + 33;
  21379. p = t + 33+1;
  21380. /* t[0] = {0, 0, 1} * norm */
  21381. XMEMSET(&t[0], 0, sizeof(t[0]));
  21382. t[0].infinity = 1;
  21383. /* t[1] = {g->x, g->y, g->z} * norm */
  21384. err = sp_256_mod_mul_norm_5(t[1].x, g->x, p256_mod);
  21385. }
  21386. if (err == MP_OKAY) {
  21387. err = sp_256_mod_mul_norm_5(t[1].y, g->y, p256_mod);
  21388. }
  21389. if (err == MP_OKAY) {
  21390. err = sp_256_mod_mul_norm_5(t[1].z, g->z, p256_mod);
  21391. }
  21392. if (err == MP_OKAY) {
  21393. t[1].infinity = 0;
  21394. /* t[2] ... t[32] */
  21395. sp_256_proj_point_dbl_n_store_5(t, &t[ 1], 5, 1, tmp);
  21396. sp_256_proj_point_add_5(&t[ 3], &t[ 2], &t[ 1], tmp);
  21397. sp_256_proj_point_dbl_5(&t[ 6], &t[ 3], tmp);
  21398. sp_256_proj_point_add_sub_5(&t[ 7], &t[ 5], &t[ 6], &t[ 1], tmp);
  21399. sp_256_proj_point_dbl_5(&t[10], &t[ 5], tmp);
  21400. sp_256_proj_point_add_sub_5(&t[11], &t[ 9], &t[10], &t[ 1], tmp);
  21401. sp_256_proj_point_dbl_5(&t[12], &t[ 6], tmp);
  21402. sp_256_proj_point_dbl_5(&t[14], &t[ 7], tmp);
  21403. sp_256_proj_point_add_sub_5(&t[15], &t[13], &t[14], &t[ 1], tmp);
  21404. sp_256_proj_point_dbl_5(&t[18], &t[ 9], tmp);
  21405. sp_256_proj_point_add_sub_5(&t[19], &t[17], &t[18], &t[ 1], tmp);
  21406. sp_256_proj_point_dbl_5(&t[20], &t[10], tmp);
  21407. sp_256_proj_point_dbl_5(&t[22], &t[11], tmp);
  21408. sp_256_proj_point_add_sub_5(&t[23], &t[21], &t[22], &t[ 1], tmp);
  21409. sp_256_proj_point_dbl_5(&t[24], &t[12], tmp);
  21410. sp_256_proj_point_dbl_5(&t[26], &t[13], tmp);
  21411. sp_256_proj_point_add_sub_5(&t[27], &t[25], &t[26], &t[ 1], tmp);
  21412. sp_256_proj_point_dbl_5(&t[28], &t[14], tmp);
  21413. sp_256_proj_point_dbl_5(&t[30], &t[15], tmp);
  21414. sp_256_proj_point_add_sub_5(&t[31], &t[29], &t[30], &t[ 1], tmp);
  21415. negy = t[0].y;
  21416. sp_256_ecc_recode_6_5(k, v);
  21417. i = 42;
  21418. #ifndef WC_NO_CACHE_RESISTANT
  21419. if (ct) {
  21420. sp_256_get_point_33_5(rt, t, v[i].i);
  21421. rt->infinity = !v[i].i;
  21422. }
  21423. else
  21424. #endif
  21425. {
  21426. XMEMCPY(rt, &t[v[i].i], sizeof(sp_point_256));
  21427. }
  21428. for (--i; i>=0; i--) {
  21429. sp_256_proj_point_dbl_n_5(rt, 6, tmp);
  21430. #ifndef WC_NO_CACHE_RESISTANT
  21431. if (ct) {
  21432. sp_256_get_point_33_5(p, t, v[i].i);
  21433. p->infinity = !v[i].i;
  21434. }
  21435. else
  21436. #endif
  21437. {
  21438. XMEMCPY(p, &t[v[i].i], sizeof(sp_point_256));
  21439. }
  21440. sp_256_sub_5(negy, p256_mod, p->y);
  21441. sp_256_norm_5(negy);
  21442. sp_256_cond_copy_5(p->y, negy, (sp_digit)0 - v[i].neg);
  21443. sp_256_proj_point_add_5(rt, rt, p, tmp);
  21444. }
  21445. if (map != 0) {
  21446. sp_256_map_5(r, rt, tmp);
  21447. }
  21448. else {
  21449. XMEMCPY(r, rt, sizeof(sp_point_256));
  21450. }
  21451. }
  21452. #ifdef WOLFSSL_SP_SMALL_STACK
  21453. if (t != NULL)
  21454. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  21455. if (tmp != NULL)
  21456. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  21457. #endif
  21458. return err;
  21459. }
  21460. #ifdef FP_ECC
  21461. #endif /* FP_ECC */
  21462. /* Add two Montgomery form projective points. The second point has a q value of
  21463. * one.
  21464. * Only the first point can be the same pointer as the result point.
  21465. *
  21466. * r Result of addition.
  21467. * p First point to add.
  21468. * q Second point to add.
  21469. * t Temporary ordinate data.
  21470. */
  21471. static void sp_256_proj_point_add_qz1_5(sp_point_256* r,
  21472. const sp_point_256* p, const sp_point_256* q, sp_digit* t)
  21473. {
  21474. sp_digit* t2 = t;
  21475. sp_digit* t3 = t + 2*5;
  21476. sp_digit* t6 = t + 4*5;
  21477. sp_digit* t1 = t + 6*5;
  21478. sp_digit* t4 = t + 8*5;
  21479. sp_digit* t5 = t + 10*5;
  21480. /* Calculate values to subtract from P->x and P->y. */
  21481. /* U2 = X2*Z1^2 */
  21482. sp_256_mont_sqr_5(t2, p->z, p256_mod, p256_mp_mod);
  21483. sp_256_mont_mul_5(t4, t2, p->z, p256_mod, p256_mp_mod);
  21484. sp_256_mont_mul_5(t2, t2, q->x, p256_mod, p256_mp_mod);
  21485. /* S2 = Y2*Z1^3 */
  21486. sp_256_mont_mul_5(t4, t4, q->y, p256_mod, p256_mp_mod);
  21487. if ((~p->infinity) & (~q->infinity) &
  21488. sp_256_cmp_equal_5(p->x, t2) &
  21489. sp_256_cmp_equal_5(p->y, t4)) {
  21490. sp_256_proj_point_dbl_5(r, p, t);
  21491. }
  21492. else {
  21493. sp_digit* x = t2;
  21494. sp_digit* y = t3;
  21495. sp_digit* z = t6;
  21496. /* H = U2 - X1 */
  21497. sp_256_mont_sub_5(t2, t2, p->x, p256_mod);
  21498. /* R = S2 - Y1 */
  21499. sp_256_mont_sub_5(t4, t4, p->y, p256_mod);
  21500. /* Z3 = H*Z1 */
  21501. sp_256_mont_mul_5(z, p->z, t2, p256_mod, p256_mp_mod);
  21502. /* X3 = R^2 - H^3 - 2*X1*H^2 */
  21503. sp_256_mont_sqr_5(t1, t2, p256_mod, p256_mp_mod);
  21504. sp_256_mont_mul_5(t3, p->x, t1, p256_mod, p256_mp_mod);
  21505. sp_256_mont_mul_5(t1, t1, t2, p256_mod, p256_mp_mod);
  21506. sp_256_mont_sqr_5(t2, t4, p256_mod, p256_mp_mod);
  21507. sp_256_mont_sub_5(t2, t2, t1, p256_mod);
  21508. sp_256_mont_dbl_5(t5, t3, p256_mod);
  21509. sp_256_mont_sub_5(x, t2, t5, p256_mod);
  21510. /* Y3 = R*(X1*H^2 - X3) - Y1*H^3 */
  21511. sp_256_mont_sub_5(t3, t3, x, p256_mod);
  21512. sp_256_mont_mul_5(t3, t3, t4, p256_mod, p256_mp_mod);
  21513. sp_256_mont_mul_5(t1, t1, p->y, p256_mod, p256_mp_mod);
  21514. sp_256_mont_sub_5(y, t3, t1, p256_mod);
  21515. {
  21516. int i;
  21517. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  21518. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  21519. sp_digit maskt = ~(maskp | maskq);
  21520. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  21521. for (i = 0; i < 5; i++) {
  21522. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  21523. (x[i] & maskt);
  21524. }
  21525. for (i = 0; i < 5; i++) {
  21526. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  21527. (y[i] & maskt);
  21528. }
  21529. for (i = 0; i < 5; i++) {
  21530. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  21531. (z[i] & maskt);
  21532. }
  21533. r->z[0] |= inf;
  21534. r->infinity = (word32)inf;
  21535. }
  21536. }
  21537. }
  21538. #ifdef FP_ECC
  21539. /* Convert the projective point to affine.
  21540. * Ordinates are in Montgomery form.
  21541. *
  21542. * a Point to convert.
  21543. * t Temporary data.
  21544. */
  21545. static void sp_256_proj_to_affine_5(sp_point_256* a, sp_digit* t)
  21546. {
  21547. sp_digit* t1 = t;
  21548. sp_digit* t2 = t + 2 * 5;
  21549. sp_digit* tmp = t + 4 * 5;
  21550. sp_256_mont_inv_5(t1, a->z, tmp);
  21551. sp_256_mont_sqr_5(t2, t1, p256_mod, p256_mp_mod);
  21552. sp_256_mont_mul_5(t1, t2, t1, p256_mod, p256_mp_mod);
  21553. sp_256_mont_mul_5(a->x, a->x, t2, p256_mod, p256_mp_mod);
  21554. sp_256_mont_mul_5(a->y, a->y, t1, p256_mod, p256_mp_mod);
  21555. XMEMCPY(a->z, p256_norm_mod, sizeof(p256_norm_mod));
  21556. }
  21557. /* Generate the pre-computed table of points for the base point.
  21558. *
  21559. * width = 8
  21560. * 256 entries
  21561. * 32 bits between
  21562. *
  21563. * a The base point.
  21564. * table Place to store generated point data.
  21565. * tmp Temporary data.
  21566. * heap Heap to use for allocation.
  21567. */
  21568. static int sp_256_gen_stripe_table_5(const sp_point_256* a,
  21569. sp_table_entry_256* table, sp_digit* tmp, void* heap)
  21570. {
  21571. #ifdef WOLFSSL_SP_SMALL_STACK
  21572. sp_point_256* t = NULL;
  21573. #else
  21574. sp_point_256 t[3];
  21575. #endif
  21576. sp_point_256* s1 = NULL;
  21577. sp_point_256* s2 = NULL;
  21578. int i;
  21579. int j;
  21580. int err = MP_OKAY;
  21581. (void)heap;
  21582. #ifdef WOLFSSL_SP_SMALL_STACK
  21583. t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap,
  21584. DYNAMIC_TYPE_ECC);
  21585. if (t == NULL)
  21586. err = MEMORY_E;
  21587. #endif
  21588. if (err == MP_OKAY) {
  21589. s1 = t + 1;
  21590. s2 = t + 2;
  21591. err = sp_256_mod_mul_norm_5(t->x, a->x, p256_mod);
  21592. }
  21593. if (err == MP_OKAY) {
  21594. err = sp_256_mod_mul_norm_5(t->y, a->y, p256_mod);
  21595. }
  21596. if (err == MP_OKAY) {
  21597. err = sp_256_mod_mul_norm_5(t->z, a->z, p256_mod);
  21598. }
  21599. if (err == MP_OKAY) {
  21600. t->infinity = 0;
  21601. sp_256_proj_to_affine_5(t, tmp);
  21602. XMEMCPY(s1->z, p256_norm_mod, sizeof(p256_norm_mod));
  21603. s1->infinity = 0;
  21604. XMEMCPY(s2->z, p256_norm_mod, sizeof(p256_norm_mod));
  21605. s2->infinity = 0;
  21606. /* table[0] = {0, 0, infinity} */
  21607. XMEMSET(&table[0], 0, sizeof(sp_table_entry_256));
  21608. /* table[1] = Affine version of 'a' in Montgomery form */
  21609. XMEMCPY(table[1].x, t->x, sizeof(table->x));
  21610. XMEMCPY(table[1].y, t->y, sizeof(table->y));
  21611. for (i=1; i<8; i++) {
  21612. sp_256_proj_point_dbl_n_5(t, 32, tmp);
  21613. sp_256_proj_to_affine_5(t, tmp);
  21614. XMEMCPY(table[1<<i].x, t->x, sizeof(table->x));
  21615. XMEMCPY(table[1<<i].y, t->y, sizeof(table->y));
  21616. }
  21617. for (i=1; i<8; i++) {
  21618. XMEMCPY(s1->x, table[1<<i].x, sizeof(table->x));
  21619. XMEMCPY(s1->y, table[1<<i].y, sizeof(table->y));
  21620. for (j=(1<<i)+1; j<(1<<(i+1)); j++) {
  21621. XMEMCPY(s2->x, table[j-(1<<i)].x, sizeof(table->x));
  21622. XMEMCPY(s2->y, table[j-(1<<i)].y, sizeof(table->y));
  21623. sp_256_proj_point_add_qz1_5(t, s1, s2, tmp);
  21624. sp_256_proj_to_affine_5(t, tmp);
  21625. XMEMCPY(table[j].x, t->x, sizeof(table->x));
  21626. XMEMCPY(table[j].y, t->y, sizeof(table->y));
  21627. }
  21628. }
  21629. }
  21630. #ifdef WOLFSSL_SP_SMALL_STACK
  21631. if (t != NULL)
  21632. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  21633. #endif
  21634. return err;
  21635. }
  21636. #endif /* FP_ECC */
  21637. #ifndef WC_NO_CACHE_RESISTANT
  21638. /* Touch each possible entry that could be being copied.
  21639. *
  21640. * r Point to copy into.
  21641. * table Table - start of the entries to access
  21642. * idx Index of entry to retrieve.
  21643. */
  21644. static void sp_256_get_entry_256_5(sp_point_256* r,
  21645. const sp_table_entry_256* table, int idx)
  21646. {
  21647. int i;
  21648. sp_digit mask;
  21649. r->x[0] = 0;
  21650. r->x[1] = 0;
  21651. r->x[2] = 0;
  21652. r->x[3] = 0;
  21653. r->x[4] = 0;
  21654. r->y[0] = 0;
  21655. r->y[1] = 0;
  21656. r->y[2] = 0;
  21657. r->y[3] = 0;
  21658. r->y[4] = 0;
  21659. for (i = 1; i < 256; i++) {
  21660. mask = 0 - (i == idx);
  21661. r->x[0] |= mask & table[i].x[0];
  21662. r->x[1] |= mask & table[i].x[1];
  21663. r->x[2] |= mask & table[i].x[2];
  21664. r->x[3] |= mask & table[i].x[3];
  21665. r->x[4] |= mask & table[i].x[4];
  21666. r->y[0] |= mask & table[i].y[0];
  21667. r->y[1] |= mask & table[i].y[1];
  21668. r->y[2] |= mask & table[i].y[2];
  21669. r->y[3] |= mask & table[i].y[3];
  21670. r->y[4] |= mask & table[i].y[4];
  21671. }
  21672. }
  21673. #endif /* !WC_NO_CACHE_RESISTANT */
  21674. /* Multiply the point by the scalar and return the result.
  21675. * If map is true then convert result to affine coordinates.
  21676. *
  21677. * Stripe implementation.
  21678. * Pre-generated: 2^0, 2^32, ...
  21679. * Pre-generated: products of all combinations of above.
  21680. * 8 doubles and adds (with qz=1)
  21681. *
  21682. * r Resulting point.
  21683. * k Scalar to multiply by.
  21684. * table Pre-computed table.
  21685. * map Indicates whether to convert result to affine.
  21686. * ct Constant time required.
  21687. * heap Heap to use for allocation.
  21688. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  21689. */
  21690. static int sp_256_ecc_mulmod_stripe_5(sp_point_256* r, const sp_point_256* g,
  21691. const sp_table_entry_256* table, const sp_digit* k, int map,
  21692. int ct, void* heap)
  21693. {
  21694. #ifdef WOLFSSL_SP_SMALL_STACK
  21695. sp_point_256* rt = NULL;
  21696. sp_digit* t = NULL;
  21697. #else
  21698. sp_point_256 rt[2];
  21699. sp_digit t[2 * 5 * 6];
  21700. #endif
  21701. sp_point_256* p = NULL;
  21702. int i;
  21703. int j;
  21704. int y;
  21705. int x;
  21706. int err = MP_OKAY;
  21707. (void)g;
  21708. /* Constant time used for cache attack resistance implementation. */
  21709. (void)ct;
  21710. (void)heap;
  21711. #ifdef WOLFSSL_SP_SMALL_STACK
  21712. rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap,
  21713. DYNAMIC_TYPE_ECC);
  21714. if (rt == NULL)
  21715. err = MEMORY_E;
  21716. if (err == MP_OKAY) {
  21717. t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 6, heap,
  21718. DYNAMIC_TYPE_ECC);
  21719. if (t == NULL)
  21720. err = MEMORY_E;
  21721. }
  21722. #endif
  21723. if (err == MP_OKAY) {
  21724. p = rt + 1;
  21725. XMEMCPY(p->z, p256_norm_mod, sizeof(p256_norm_mod));
  21726. XMEMCPY(rt->z, p256_norm_mod, sizeof(p256_norm_mod));
  21727. y = 0;
  21728. x = 31;
  21729. for (j=0; j<8; j++) {
  21730. y |= (int)(((k[x / 52] >> (x % 52)) & 1) << j);
  21731. x += 32;
  21732. }
  21733. #ifndef WC_NO_CACHE_RESISTANT
  21734. if (ct) {
  21735. sp_256_get_entry_256_5(rt, table, y);
  21736. } else
  21737. #endif
  21738. {
  21739. XMEMCPY(rt->x, table[y].x, sizeof(table[y].x));
  21740. XMEMCPY(rt->y, table[y].y, sizeof(table[y].y));
  21741. }
  21742. rt->infinity = !y;
  21743. for (i=30; i>=0; i--) {
  21744. y = 0;
  21745. x = i;
  21746. for (j=0; j<8; j++) {
  21747. y |= (int)(((k[x / 52] >> (x % 52)) & 1) << j);
  21748. x += 32;
  21749. }
  21750. sp_256_proj_point_dbl_5(rt, rt, t);
  21751. #ifndef WC_NO_CACHE_RESISTANT
  21752. if (ct) {
  21753. sp_256_get_entry_256_5(p, table, y);
  21754. }
  21755. else
  21756. #endif
  21757. {
  21758. XMEMCPY(p->x, table[y].x, sizeof(table[y].x));
  21759. XMEMCPY(p->y, table[y].y, sizeof(table[y].y));
  21760. }
  21761. p->infinity = !y;
  21762. sp_256_proj_point_add_qz1_5(rt, rt, p, t);
  21763. }
  21764. if (map != 0) {
  21765. sp_256_map_5(r, rt, t);
  21766. }
  21767. else {
  21768. XMEMCPY(r, rt, sizeof(sp_point_256));
  21769. }
  21770. }
  21771. #ifdef WOLFSSL_SP_SMALL_STACK
  21772. if (t != NULL)
  21773. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  21774. if (rt != NULL)
  21775. XFREE(rt, heap, DYNAMIC_TYPE_ECC);
  21776. #endif
  21777. return err;
  21778. }
  21779. #ifdef FP_ECC
  21780. #ifndef FP_ENTRIES
  21781. #define FP_ENTRIES 16
  21782. #endif
  21783. /* Cache entry - holds precomputation tables for a point. */
  21784. typedef struct sp_cache_256_t {
  21785. /* X ordinate of point that table was generated from. */
  21786. sp_digit x[5];
  21787. /* Y ordinate of point that table was generated from. */
  21788. sp_digit y[5];
  21789. /* Precomputation table for point. */
  21790. sp_table_entry_256 table[256];
  21791. /* Count of entries in table. */
  21792. uint32_t cnt;
  21793. /* Point and table set in entry. */
  21794. int set;
  21795. } sp_cache_256_t;
  21796. /* Cache of tables. */
  21797. static THREAD_LS_T sp_cache_256_t sp_cache_256[FP_ENTRIES];
  21798. /* Index of last entry in cache. */
  21799. static THREAD_LS_T int sp_cache_256_last = -1;
  21800. /* Cache has been initialized. */
  21801. static THREAD_LS_T int sp_cache_256_inited = 0;
  21802. #ifndef HAVE_THREAD_LS
  21803. static volatile int initCacheMutex_256 = 0;
  21804. static wolfSSL_Mutex sp_cache_256_lock;
  21805. #endif
  21806. /* Get the cache entry for the point.
  21807. *
  21808. * g [in] Point scalar multiplying.
  21809. * cache [out] Cache table to use.
  21810. */
  21811. static void sp_ecc_get_cache_256(const sp_point_256* g, sp_cache_256_t** cache)
  21812. {
  21813. int i;
  21814. int j;
  21815. uint32_t least;
  21816. if (sp_cache_256_inited == 0) {
  21817. for (i=0; i<FP_ENTRIES; i++) {
  21818. sp_cache_256[i].set = 0;
  21819. }
  21820. sp_cache_256_inited = 1;
  21821. }
  21822. /* Compare point with those in cache. */
  21823. for (i=0; i<FP_ENTRIES; i++) {
  21824. if (!sp_cache_256[i].set)
  21825. continue;
  21826. if (sp_256_cmp_equal_5(g->x, sp_cache_256[i].x) &
  21827. sp_256_cmp_equal_5(g->y, sp_cache_256[i].y)) {
  21828. sp_cache_256[i].cnt++;
  21829. break;
  21830. }
  21831. }
  21832. /* No match. */
  21833. if (i == FP_ENTRIES) {
  21834. /* Find empty entry. */
  21835. i = (sp_cache_256_last + 1) % FP_ENTRIES;
  21836. for (; i != sp_cache_256_last; i=(i+1)%FP_ENTRIES) {
  21837. if (!sp_cache_256[i].set) {
  21838. break;
  21839. }
  21840. }
  21841. /* Evict least used. */
  21842. if (i == sp_cache_256_last) {
  21843. least = sp_cache_256[0].cnt;
  21844. for (j=1; j<FP_ENTRIES; j++) {
  21845. if (sp_cache_256[j].cnt < least) {
  21846. i = j;
  21847. least = sp_cache_256[i].cnt;
  21848. }
  21849. }
  21850. }
  21851. XMEMCPY(sp_cache_256[i].x, g->x, sizeof(sp_cache_256[i].x));
  21852. XMEMCPY(sp_cache_256[i].y, g->y, sizeof(sp_cache_256[i].y));
  21853. sp_cache_256[i].set = 1;
  21854. sp_cache_256[i].cnt = 1;
  21855. }
  21856. *cache = &sp_cache_256[i];
  21857. sp_cache_256_last = i;
  21858. }
  21859. #endif /* FP_ECC */
  21860. /* Multiply the base point of P256 by the scalar and return the result.
  21861. * If map is true then convert result to affine coordinates.
  21862. *
  21863. * r Resulting point.
  21864. * g Point to multiply.
  21865. * k Scalar to multiply by.
  21866. * map Indicates whether to convert result to affine.
  21867. * ct Constant time required.
  21868. * heap Heap to use for allocation.
  21869. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  21870. */
  21871. static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g,
  21872. const sp_digit* k, int map, int ct, void* heap)
  21873. {
  21874. #ifndef FP_ECC
  21875. return sp_256_ecc_mulmod_win_add_sub_5(r, g, k, map, ct, heap);
  21876. #else
  21877. #ifdef WOLFSSL_SP_SMALL_STACK
  21878. sp_digit* tmp;
  21879. #else
  21880. sp_digit tmp[2 * 5 * 6];
  21881. #endif
  21882. sp_cache_256_t* cache;
  21883. int err = MP_OKAY;
  21884. #ifdef WOLFSSL_SP_SMALL_STACK
  21885. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 6, heap, DYNAMIC_TYPE_ECC);
  21886. if (tmp == NULL) {
  21887. err = MEMORY_E;
  21888. }
  21889. #endif
  21890. #ifndef HAVE_THREAD_LS
  21891. if (err == MP_OKAY) {
  21892. if (initCacheMutex_256 == 0) {
  21893. wc_InitMutex(&sp_cache_256_lock);
  21894. initCacheMutex_256 = 1;
  21895. }
  21896. if (wc_LockMutex(&sp_cache_256_lock) != 0) {
  21897. err = BAD_MUTEX_E;
  21898. }
  21899. }
  21900. #endif /* HAVE_THREAD_LS */
  21901. if (err == MP_OKAY) {
  21902. sp_ecc_get_cache_256(g, &cache);
  21903. if (cache->cnt == 2)
  21904. sp_256_gen_stripe_table_5(g, cache->table, tmp, heap);
  21905. #ifndef HAVE_THREAD_LS
  21906. wc_UnLockMutex(&sp_cache_256_lock);
  21907. #endif /* HAVE_THREAD_LS */
  21908. if (cache->cnt < 2) {
  21909. err = sp_256_ecc_mulmod_win_add_sub_5(r, g, k, map, ct, heap);
  21910. }
  21911. else {
  21912. err = sp_256_ecc_mulmod_stripe_5(r, g, cache->table, k,
  21913. map, ct, heap);
  21914. }
  21915. }
  21916. #ifdef WOLFSSL_SP_SMALL_STACK
  21917. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  21918. #endif
  21919. return err;
  21920. #endif
  21921. }
  21922. #endif
  21923. /* Multiply the point by the scalar and return the result.
  21924. * If map is true then convert result to affine coordinates.
  21925. *
  21926. * km Scalar to multiply by.
  21927. * p Point to multiply.
  21928. * r Resulting point.
  21929. * map Indicates whether to convert result to affine.
  21930. * heap Heap to use for allocation.
  21931. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  21932. */
  21933. int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r,
  21934. int map, void* heap)
  21935. {
  21936. #ifdef WOLFSSL_SP_SMALL_STACK
  21937. sp_point_256* point = NULL;
  21938. sp_digit* k = NULL;
  21939. #else
  21940. sp_point_256 point[1];
  21941. sp_digit k[5];
  21942. #endif
  21943. int err = MP_OKAY;
  21944. #ifdef WOLFSSL_SP_SMALL_STACK
  21945. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap,
  21946. DYNAMIC_TYPE_ECC);
  21947. if (point == NULL)
  21948. err = MEMORY_E;
  21949. if (err == MP_OKAY) {
  21950. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5, heap,
  21951. DYNAMIC_TYPE_ECC);
  21952. if (k == NULL)
  21953. err = MEMORY_E;
  21954. }
  21955. #endif
  21956. if (err == MP_OKAY) {
  21957. sp_256_from_mp(k, 5, km);
  21958. sp_256_point_from_ecc_point_5(point, gm);
  21959. err = sp_256_ecc_mulmod_5(point, point, k, map, 1, heap);
  21960. }
  21961. if (err == MP_OKAY) {
  21962. err = sp_256_point_to_ecc_point_5(point, r);
  21963. }
  21964. #ifdef WOLFSSL_SP_SMALL_STACK
  21965. if (k != NULL)
  21966. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  21967. if (point != NULL)
  21968. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  21969. #endif
  21970. return err;
  21971. }
  21972. /* Multiply the point by the scalar, add point a and return the result.
  21973. * If map is true then convert result to affine coordinates.
  21974. *
  21975. * km Scalar to multiply by.
  21976. * p Point to multiply.
  21977. * am Point to add to scalar multiply result.
  21978. * inMont Point to add is in montgomery form.
  21979. * r Resulting point.
  21980. * map Indicates whether to convert result to affine.
  21981. * heap Heap to use for allocation.
  21982. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  21983. */
  21984. int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm,
  21985. const ecc_point* am, int inMont, ecc_point* r, int map, void* heap)
  21986. {
  21987. #ifdef WOLFSSL_SP_SMALL_STACK
  21988. sp_point_256* point = NULL;
  21989. sp_digit* k = NULL;
  21990. #else
  21991. sp_point_256 point[2];
  21992. sp_digit k[5 + 5 * 2 * 6];
  21993. #endif
  21994. sp_point_256* addP = NULL;
  21995. sp_digit* tmp = NULL;
  21996. int err = MP_OKAY;
  21997. #ifdef WOLFSSL_SP_SMALL_STACK
  21998. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap,
  21999. DYNAMIC_TYPE_ECC);
  22000. if (point == NULL)
  22001. err = MEMORY_E;
  22002. if (err == MP_OKAY) {
  22003. k = (sp_digit*)XMALLOC(
  22004. sizeof(sp_digit) * (5 + 5 * 2 * 6), heap,
  22005. DYNAMIC_TYPE_ECC);
  22006. if (k == NULL)
  22007. err = MEMORY_E;
  22008. }
  22009. #endif
  22010. if (err == MP_OKAY) {
  22011. addP = point + 1;
  22012. tmp = k + 5;
  22013. sp_256_from_mp(k, 5, km);
  22014. sp_256_point_from_ecc_point_5(point, gm);
  22015. sp_256_point_from_ecc_point_5(addP, am);
  22016. }
  22017. if ((err == MP_OKAY) && (!inMont)) {
  22018. err = sp_256_mod_mul_norm_5(addP->x, addP->x, p256_mod);
  22019. }
  22020. if ((err == MP_OKAY) && (!inMont)) {
  22021. err = sp_256_mod_mul_norm_5(addP->y, addP->y, p256_mod);
  22022. }
  22023. if ((err == MP_OKAY) && (!inMont)) {
  22024. err = sp_256_mod_mul_norm_5(addP->z, addP->z, p256_mod);
  22025. }
  22026. if (err == MP_OKAY) {
  22027. err = sp_256_ecc_mulmod_5(point, point, k, 0, 0, heap);
  22028. }
  22029. if (err == MP_OKAY) {
  22030. sp_256_proj_point_add_5(point, point, addP, tmp);
  22031. if (map) {
  22032. sp_256_map_5(point, point, tmp);
  22033. }
  22034. err = sp_256_point_to_ecc_point_5(point, r);
  22035. }
  22036. #ifdef WOLFSSL_SP_SMALL_STACK
  22037. if (k != NULL)
  22038. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  22039. if (point != NULL)
  22040. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  22041. #endif
  22042. return err;
  22043. }
  22044. #ifdef WOLFSSL_SP_SMALL
  22045. /* Multiply the base point of P256 by the scalar and return the result.
  22046. * If map is true then convert result to affine coordinates.
  22047. *
  22048. * r Resulting point.
  22049. * k Scalar to multiply by.
  22050. * map Indicates whether to convert result to affine.
  22051. * heap Heap to use for allocation.
  22052. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  22053. */
  22054. static int sp_256_ecc_mulmod_base_5(sp_point_256* r, const sp_digit* k,
  22055. int map, int ct, void* heap)
  22056. {
  22057. /* No pre-computed values. */
  22058. return sp_256_ecc_mulmod_5(r, &p256_base, k, map, ct, heap);
  22059. }
  22060. #ifdef WOLFSSL_SP_NONBLOCK
  22061. static int sp_256_ecc_mulmod_base_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
  22062. const sp_digit* k, int map, int ct, void* heap)
  22063. {
  22064. /* No pre-computed values. */
  22065. return sp_256_ecc_mulmod_5_nb(sp_ctx, r, &p256_base, k, map, ct, heap);
  22066. }
  22067. #endif /* WOLFSSL_SP_NONBLOCK */
  22068. #else
  22069. /* Striping precomputation table.
  22070. * 8 points combined into a table of 256 points.
  22071. * Distance of 32 between points.
  22072. */
  22073. static const sp_table_entry_256 p256_table[256] = {
  22074. /* 0 */
  22075. { { 0x00, 0x00, 0x00, 0x00, 0x00 },
  22076. { 0x00, 0x00, 0x00, 0x00, 0x00 } },
  22077. /* 1 */
  22078. { { 0x730d418a9143cL,0xfc5fedb60179eL,0x762251075ba95L,0x55c679fb732b7L,
  22079. 0x018905f76a537L },
  22080. { 0x25357ce95560aL,0xe4ba19e45cddfL,0xd21f3258b4ab8L,0x5d85d2e88688dL,
  22081. 0x08571ff182588L } },
  22082. /* 2 */
  22083. { { 0x886024147519aL,0xac26b372f0202L,0x785ebc8d0981eL,0x58e9a9d4a7caaL,
  22084. 0x0d953c50ddbdfL },
  22085. { 0x361ccfd590f8fL,0x6b44e6c9179d6L,0x2eb64cf72e962L,0x88f37fd961102L,
  22086. 0x0863ebb7e9eb2L } },
  22087. /* 3 */
  22088. { { 0x6b6235cdb6485L,0xa22f0a2f97785L,0xf7e300b808f0eL,0x80a03e68d9544L,
  22089. 0x000076055b5ffL },
  22090. { 0x4eb9b838d2010L,0xbb3243708a763L,0x42a660654014fL,0x3ee0e0e47d398L,
  22091. 0x0830877613437L } },
  22092. /* 4 */
  22093. { { 0x22fc516a0d2bbL,0x6c1a6234994f9L,0x7c62c8b0d5cc1L,0x667f9241cf3a5L,
  22094. 0x02f5e6961fd1bL },
  22095. { 0x5c70bf5a01797L,0x4d609561925c1L,0x71fdb523d20b4L,0x0f7b04911b370L,
  22096. 0x0f648f9168d6fL } },
  22097. /* 5 */
  22098. { { 0x66847e137bbbcL,0x9e8a6a0bec9e5L,0x9d73463e43446L,0x0015b1c427617L,
  22099. 0x05abe0285133dL },
  22100. { 0xa837cc04c7dabL,0x4c43260c0792aL,0x8e6cc37573d9fL,0x73830c9315627L,
  22101. 0x094bb725b6b6fL } },
  22102. /* 6 */
  22103. { { 0x9b48f720f141cL,0xcd2df5bc74bbfL,0x11045c46199b3L,0xc4efdc3f61294L,
  22104. 0x0cdd6bbcb2f7dL },
  22105. { 0x6700beaf436fdL,0x6db99326beccaL,0x14f25226f647fL,0xe5f60c0fa7920L,
  22106. 0x0a361bebd4bdaL } },
  22107. /* 7 */
  22108. { { 0xa2558597c13c7L,0x5f50b7c3e128aL,0x3c09d1dc38d63L,0x292c07039aecfL,
  22109. 0x0ba12ca09c4b5L },
  22110. { 0x08fa459f91dfdL,0x66ceea07fb9e4L,0xd780b293af43bL,0xef4b1eceb0899L,
  22111. 0x053ebb99d701fL } },
  22112. /* 8 */
  22113. { { 0x7ee31b0e63d34L,0x72a9e54fab4feL,0x5e7b5a4f46005L,0x4831c0493334dL,
  22114. 0x08589fb9206d5L },
  22115. { 0x0f5cc6583553aL,0x4ae25649e5aa7L,0x0044652087909L,0x1c4fcc9045071L,
  22116. 0x0ebb0696d0254L } },
  22117. /* 9 */
  22118. { { 0x6ca15ac1647c5L,0x47c4cf5799461L,0x64dfbacb8127dL,0x7da3dc666aa37L,
  22119. 0x0eb2820cbd1b2L },
  22120. { 0x6f8d86a87e008L,0x9d922378f3940L,0x0ccecb2d87dfaL,0xda1d56ed2e428L,
  22121. 0x01f28289b55a7L } },
  22122. /* 10 */
  22123. { { 0xaa0c03b89da99L,0x9eb8284022abbL,0x81c05e8a6f2d7L,0x4d6327847862bL,
  22124. 0x0337a4b5905e5L },
  22125. { 0x7500d21f7794aL,0xb77d6d7f613c6L,0x4cfd6e8207005L,0xfbd60a5a37810L,
  22126. 0x00d65e0d5f4c2L } },
  22127. /* 11 */
  22128. { { 0x09bbeb5275d38L,0x450be0a358d9dL,0x73eb2654268a7L,0xa232f0762ff49L,
  22129. 0x0c23da24252f4L },
  22130. { 0x1b84f0b94520cL,0x63b05bd78e5daL,0x4d29ea1096667L,0xcff13a4dcb869L,
  22131. 0x019de3b8cc790L } },
  22132. /* 12 */
  22133. { { 0xa716c26c5fe04L,0x0b3bba1bdb183L,0x4cb712c3b28deL,0xcbfd7432c586aL,
  22134. 0x0e34dcbd491fcL },
  22135. { 0x8d46baaa58403L,0x8682e97a53b40L,0x6aaa8af9a6974L,0x0f7f9e3901273L,
  22136. 0x0e7641f447b4eL } },
  22137. /* 13 */
  22138. { { 0x53941df64ba59L,0xec0b0242fc7d7L,0x1581859d33f10L,0x57bf4f06dfc6aL,
  22139. 0x04a12df57052aL },
  22140. { 0x6338f9439dbd0L,0xd4bde53e1fbfaL,0x1f1b314d3c24bL,0xea46fd5e4ffa2L,
  22141. 0x06af5aa93bb5bL } },
  22142. /* 14 */
  22143. { { 0x0b69910c91999L,0x402a580491da1L,0x8cc20900a24b4L,0x40133e0094b4bL,
  22144. 0x05fe3475a66a4L },
  22145. { 0x8cabdf93e7b4bL,0x1a7c23f91ab0fL,0xd1e6263292b50L,0xa91642e889aecL,
  22146. 0x0b544e308ecfeL } },
  22147. /* 15 */
  22148. { { 0x8c6e916ddfdceL,0x66f89179e6647L,0xd4e67e12c3291L,0xc20b4e8d6e764L,
  22149. 0x0e0b6b2bda6b0L },
  22150. { 0x12df2bb7efb57L,0xde790c40070d3L,0x79bc9441aac0dL,0x3774f90336ad6L,
  22151. 0x071c023de25a6L } },
  22152. /* 16 */
  22153. { { 0x8c244bfe20925L,0xc38fdce86762aL,0xd38706391c19aL,0x24f65a96a5d5dL,
  22154. 0x061d587d421d3L },
  22155. { 0x673a2a37173eaL,0x0853778b65e87L,0x5bab43e238480L,0xefbe10f8441e0L,
  22156. 0x0fa11fe124621L } },
  22157. /* 17 */
  22158. { { 0x91f2b2cb19ffdL,0x5bb1923c231c8L,0xac5ca8e01ba8dL,0xbedcb6d03d678L,
  22159. 0x0586eb04c1f13L },
  22160. { 0x5c6e527e8ed09L,0x3c1819ede20c3L,0x6c652fa1e81a3L,0x4f11278fd6c05L,
  22161. 0x019d5ac087086L } },
  22162. /* 18 */
  22163. { { 0x9f581309a4e1fL,0x1be92700741e9L,0xfd28d20ab7de7L,0x563f26a5ef0beL,
  22164. 0x0e7c0073f7f9cL },
  22165. { 0xd663a0ef59f76L,0x5420fcb0501f6L,0xa6602d4669b3bL,0x3c0ac08c1f7a7L,
  22166. 0x0e08504fec65bL } },
  22167. /* 19 */
  22168. { { 0x8f68da031b3caL,0x9ee6da6d66f09L,0x4f246e86d1cabL,0x96b45bfd81fa9L,
  22169. 0x078f018825b09L },
  22170. { 0xefde43a25787fL,0x0d1dccac9bb7eL,0x35bfc368016f8L,0x747a0cea4877bL,
  22171. 0x043a773b87e94L } },
  22172. /* 20 */
  22173. { { 0x77734d2b533d5L,0xf6a1bdddc0625L,0x79ec293673b8aL,0x66b1577e7c9aaL,
  22174. 0x0bb6de651c3b2L },
  22175. { 0x9303ab65259b3L,0xd3d03a7480e7eL,0xb3cfc27d6a0afL,0xb99bc5ac83d19L,
  22176. 0x060b4619a5d18L } },
  22177. /* 21 */
  22178. { { 0xa38e11ae5aa1cL,0x2b49e73658bd6L,0xe5f87edb8b765L,0xffcd0b130014eL,
  22179. 0x09d0f27b2aeebL },
  22180. { 0x246317a730a55L,0x2fddbbc83aca9L,0xc019a719c955bL,0xc48d07c1dfe0aL,
  22181. 0x0244a566d356eL } },
  22182. /* 22 */
  22183. { { 0x0394aeacf1f96L,0xa9024c271c6dbL,0x2cbd3b99f2122L,0xef692626ac1b8L,
  22184. 0x045e58c873581L },
  22185. { 0xf479da38f9dbcL,0x46e888a040d3fL,0x6e0bed7a8aaf1L,0xb7a4945adfb24L,
  22186. 0x0c040e21cc1e4L } },
  22187. /* 23 */
  22188. { { 0xaf0006f8117b6L,0xff73a35433847L,0xd9475eb651969L,0x6ec7482b35761L,
  22189. 0x01cdf5c97682cL },
  22190. { 0x775b411f04839L,0xf448de16987dbL,0x70b32197dbeacL,0xff3db2921dd1bL,
  22191. 0x0046755f8a92dL } },
  22192. /* 24 */
  22193. { { 0xac5d2bce8ffcdL,0x8b2fe61a82cc8L,0x202d6c70d53c4L,0xa5f3f6f161727L,
  22194. 0x0046e5e113b83L },
  22195. { 0x8ff64d8007f01L,0x125af43183e7bL,0x5e1a03c7fb1efL,0x005b045c5ea63L,
  22196. 0x06e0106c3303dL } },
  22197. /* 25 */
  22198. { { 0x7358488dd73b1L,0x8f995ed0d948cL,0x56a2ab7767070L,0xcf1f38385ea8cL,
  22199. 0x0442594ede901L },
  22200. { 0xaa2c912d4b65bL,0x3b96c90c37f8fL,0xe978d1f94c234L,0xe68ed326e4a15L,
  22201. 0x0a796fa514c2eL } },
  22202. /* 26 */
  22203. { { 0xfb604823addd7L,0x83e56693b3359L,0xcbf3c809e2a61L,0x66e9f885b78e3L,
  22204. 0x0e4ad2da9c697L },
  22205. { 0xf7f428e048a61L,0x8cc092d9a0357L,0x03ed8ef082d19L,0x5143fc3a1af4cL,
  22206. 0x0c5e94046c37bL } },
  22207. /* 27 */
  22208. { { 0xa538c2be75f9eL,0xe8cb123a78476L,0x109c04b6fd1a9L,0x4747d85e4df0bL,
  22209. 0x063283dafdb46L },
  22210. { 0x28cf7baf2df15L,0x550ad9a7f4ce7L,0x834bcc3e592c4L,0xa938fab226adeL,
  22211. 0x068bd19ab1981L } },
  22212. /* 28 */
  22213. { { 0xead511887d659L,0xf4b359305ac08L,0xfe74fe33374d5L,0xdfd696986981cL,
  22214. 0x0495292f53c6fL },
  22215. { 0x78c9e1acec896L,0x10ec5b44844a8L,0x64d60a7d964b2L,0x68376696f7e26L,
  22216. 0x00ec7530d2603L } },
  22217. /* 29 */
  22218. { { 0x13a05ad2687bbL,0x6af32e21fa2daL,0xdd4607ba1f83bL,0x3f0b390f5ef51L,
  22219. 0x00f6207a66486L },
  22220. { 0x7e3bb0f138233L,0x6c272aa718bd6L,0x6ec88aedd66b9L,0x6dcf8ed004072L,
  22221. 0x0ff0db07208edL } },
  22222. /* 30 */
  22223. { { 0xfa1014c95d553L,0xfd5d680a8a749L,0xf3b566fa44052L,0x0ea3183b4317fL,
  22224. 0x0313b513c8874L },
  22225. { 0x2e2ac08d11549L,0x0bb4dee21cb40L,0x7f2320e071ee1L,0x9f8126b987dd4L,
  22226. 0x02d3abcf986f1L } },
  22227. /* 31 */
  22228. { { 0x88501815581a2L,0x56632211af4c2L,0xcab2e999a0a6dL,0x8cdf19ba7a0f0L,
  22229. 0x0c036fa10ded9L },
  22230. { 0xe08bac1fbd009L,0x9006d1581629aL,0xb9e0d8f0b68b1L,0x0194c2eb32779L,
  22231. 0x0a6b2a2c4b6d4L } },
  22232. /* 32 */
  22233. { { 0x3e50f6d3549cfL,0x6ffacd665ed43L,0xe11fcb46f3369L,0x9860695bfdaccL,
  22234. 0x0810ee252af7cL },
  22235. { 0x50fe17159bb2cL,0xbe758b357b654L,0x69fea72f7dfbeL,0x17452b057e74dL,
  22236. 0x0d485717a9273L } },
  22237. /* 33 */
  22238. { { 0x41a8af0cb5a98L,0x931f3110bf117L,0xb382adfd3da8fL,0x604e1994e2cbaL,
  22239. 0x06a6045a72f9aL },
  22240. { 0xc0d3fa2b2411dL,0x3e510e96e0170L,0x865b3ccbe0eb8L,0x57903bcc9f738L,
  22241. 0x0d3e45cfaf9e1L } },
  22242. /* 34 */
  22243. { { 0xf69bbe83f7669L,0x8272877d6bce1L,0x244278d09f8aeL,0xc19c9548ae543L,
  22244. 0x0207755dee3c2L },
  22245. { 0xd61d96fef1945L,0xefb12d28c387bL,0x2df64aa18813cL,0xb00d9fbcd1d67L,
  22246. 0x048dc5ee57154L } },
  22247. /* 35 */
  22248. { { 0x790bff7e5a199L,0xcf989ccbb7123L,0xa519c79e0efb8L,0xf445c27a2bfe0L,
  22249. 0x0f2fb0aeddff6L },
  22250. { 0x09575f0b5025fL,0xd740fa9f2241cL,0x80bfbd0550543L,0xd5258fa3c8ad3L,
  22251. 0x0a13e9015db28L } },
  22252. /* 36 */
  22253. { { 0x7a350a2b65cbcL,0x722a464226f9fL,0x23f07a10b04b9L,0x526f265ce241eL,
  22254. 0x02bf0d6b01497L },
  22255. { 0x4dd3f4b216fb7L,0x67fbdda26ad3dL,0x708505cf7d7b8L,0xe89faeb7b83f6L,
  22256. 0x042a94a5a162fL } },
  22257. /* 37 */
  22258. { { 0x6ad0beaadf191L,0x9025a268d7584L,0x94dc1f60f8a48L,0xde3de86030504L,
  22259. 0x02c2dd969c65eL },
  22260. { 0x2171d93849c17L,0xba1da250dd6d0L,0xc3a5485460488L,0x6dbc4810c7063L,
  22261. 0x0f437fa1f42c5L } },
  22262. /* 38 */
  22263. { { 0x0d7144a0f7dabL,0x931776e9ac6aaL,0x5f397860f0497L,0x7aa852c0a050fL,
  22264. 0x0aaf45b335470L },
  22265. { 0x37c33c18d364aL,0x063e49716585eL,0x5ec5444d40b9bL,0x72bcf41716811L,
  22266. 0x0cdf6310df4f2L } },
  22267. /* 39 */
  22268. { { 0x3c6238ea8b7efL,0x1885bc2287747L,0xbda8e3408e935L,0x2ff2419567722L,
  22269. 0x0f0d008bada9eL },
  22270. { 0x2671d2414d3b1L,0x85b019ea76291L,0x53bcbdbb37549L,0x7b8b5c61b96d4L,
  22271. 0x05bd5c2f5ca88L } },
  22272. /* 40 */
  22273. { { 0xf469ef49a3154L,0x956e2b2e9aef0L,0xa924a9c3e85a5L,0x471945aaec1eaL,
  22274. 0x0aa12dfc8a09eL },
  22275. { 0x272274df69f1dL,0x2ca2ff5e7326fL,0x7a9dd44e0e4c8L,0xa901b9d8ce73bL,
  22276. 0x06c036e73e48cL } },
  22277. /* 41 */
  22278. { { 0xae12a0f6e3138L,0x0025ad345a5cfL,0x5672bc56966efL,0xbe248993c64b4L,
  22279. 0x0292ff65896afL },
  22280. { 0x50d445e213402L,0x274392c9fed52L,0xa1c72e8f6580eL,0x7276097b397fdL,
  22281. 0x0644e0c90311bL } },
  22282. /* 42 */
  22283. { { 0x421e1a47153f0L,0x79920418c9e1eL,0x05d7672b86c3bL,0x9a7793bdce877L,
  22284. 0x0f25ae793cab7L },
  22285. { 0x194a36d869d0cL,0x824986c2641f3L,0x96e945e9d55c8L,0x0a3e49fb5ea30L,
  22286. 0x039b8e65313dbL } },
  22287. /* 43 */
  22288. { { 0x54200b6fd2e59L,0x669255c98f377L,0xe2a573935e2c0L,0xdb06d9dab21a0L,
  22289. 0x039122f2f0f19L },
  22290. { 0xce1e003cad53cL,0x0fe65c17e3cfbL,0xaa13877225b2cL,0xff8d72baf1d29L,
  22291. 0x08de80af8ce80L } },
  22292. /* 44 */
  22293. { { 0xea8d9207bbb76L,0x7c21782758afbL,0xc0436b1921c7eL,0x8c04dfa2b74b1L,
  22294. 0x0871949062e36L },
  22295. { 0x928bba3993df5L,0xb5f3b3d26ab5fL,0x5b55050639d75L,0xfde1011aa78a8L,
  22296. 0x0fc315e6a5b74L } },
  22297. /* 45 */
  22298. { { 0xfd41ae8d6ecfaL,0xf61aec7f86561L,0x924741d5f8c44L,0x908898452a7b4L,
  22299. 0x0e6d4a7adee38L },
  22300. { 0x52ed14593c75dL,0xa4dd271162605L,0xba2c7db70a70dL,0xae57d2aede937L,
  22301. 0x035dfaf9a9be2L } },
  22302. /* 46 */
  22303. { { 0x56fcdaa736636L,0x97ae2cab7e6b9L,0xf34996609f51dL,0x0d2bfb10bf410L,
  22304. 0x01da5c7d71c83L },
  22305. { 0x1e4833cce6825L,0x8ff9573c3b5c4L,0x23036b815ad11L,0xb9d6a28552c7fL,
  22306. 0x07077c0fddbf4L } },
  22307. /* 47 */
  22308. { { 0x3ff8d46b9661cL,0x6b0d2cfd71bf6L,0x847f8f7a1dfd3L,0xfe440373e140aL,
  22309. 0x053a8632ee50eL },
  22310. { 0x6ff68696d8051L,0x95c74f468a097L,0xe4e26bddaec0cL,0xfcc162994dc35L,
  22311. 0x0028ca76d34e1L } },
  22312. /* 48 */
  22313. { { 0xd47dcfc9877eeL,0x10801d0002d11L,0x4c260b6c8b362L,0xf046d002c1175L,
  22314. 0x004c17cd86962L },
  22315. { 0xbd094b0daddf5L,0x7524ce55c06d9L,0x2da03b5bea235L,0x7474663356e67L,
  22316. 0x0f7ba4de9fed9L } },
  22317. /* 49 */
  22318. { { 0xbfa34ebe1263fL,0x3571ae7ce6d0dL,0x2a6f523557637L,0x1c41d24405538L,
  22319. 0x0e31f96005213L },
  22320. { 0xb9216ea6b6ec6L,0x2e73c2fc44d1bL,0x9d0a29437a1d1L,0xd47bc10e7eac8L,
  22321. 0x0aa3a6259ce34L } },
  22322. /* 50 */
  22323. { { 0xf9df536f3dcd3L,0x50d2bf7360fbcL,0xf504f5b6cededL,0xdaee491710fadL,
  22324. 0x02398dd627e79L },
  22325. { 0x705a36d09569eL,0xbb5149f769cf4L,0x5f6034cea0619L,0x6210ff9c03773L,
  22326. 0x05717f5b21c04L } },
  22327. /* 51 */
  22328. { { 0x229c921dd895eL,0x0040c284519feL,0xd637ecd8e5185L,0x28defa13d2391L,
  22329. 0x0660a2c560e3cL },
  22330. { 0xa88aed67fcbd0L,0x780ea9f0969ccL,0x2e92b4dc84724L,0x245332b2f4817L,
  22331. 0x0624ee54c4f52L } },
  22332. /* 52 */
  22333. { { 0x49ce4d897ecccL,0xd93f9880aa095L,0x43a7c204d49d1L,0xfbc0723c24230L,
  22334. 0x04f392afb92bdL },
  22335. { 0x9f8fa7de44fd9L,0xe457b32156696L,0x68ebc3cb66cfbL,0x399cdb2fa8033L,
  22336. 0x08a3e7977ccdbL } },
  22337. /* 53 */
  22338. { { 0x1881f06c4b125L,0x00f6e3ca8cddeL,0xc7a13e9ae34e3L,0x4404ef6999de5L,
  22339. 0x03888d02370c2L },
  22340. { 0x8035644f91081L,0x615f015504762L,0x32cd36e3d9fcfL,0x23361827edc86L,
  22341. 0x0a5e62e471810L } },
  22342. /* 54 */
  22343. { { 0x25ee32facd6c8L,0x5454bcbc661a8L,0x8df9931699c63L,0x5adc0ce3edf79L,
  22344. 0x02c4768e6466aL },
  22345. { 0x6ff8c90a64bc9L,0x20e4779f5cb34L,0xc05e884630a60L,0x52a0d949d064bL,
  22346. 0x07b5e6441f9e6L } },
  22347. /* 55 */
  22348. { { 0x9422c1d28444aL,0xd8be136a39216L,0xb0c7fcee996c5L,0x744a2387afe5fL,
  22349. 0x0b8af73cb0c8dL },
  22350. { 0xe83aa338b86fdL,0x58a58a5cff5fdL,0x0ac9433fee3f1L,0x0895c9ee8f6f2L,
  22351. 0x0a036395f7f3fL } },
  22352. /* 56 */
  22353. { { 0x3c6bba10f7770L,0x81a12a0e248c7L,0x1bc2b9fa6f16dL,0xb533100df6825L,
  22354. 0x04be36b01875fL },
  22355. { 0x6086e9fb56dbbL,0x8b07e7a4f8922L,0x6d52f20306fefL,0x00c0eeaccc056L,
  22356. 0x08cbc9a871bdcL } },
  22357. /* 57 */
  22358. { { 0x1895cc0dac4abL,0x40712ff112e13L,0xa1cee57a874a4L,0x35f86332ae7c6L,
  22359. 0x044e7553e0c08L },
  22360. { 0x03fff7734002dL,0x8b0b34425c6d5L,0xe8738b59d35cbL,0xfc1895f702760L,
  22361. 0x0470a683a5eb8L } },
  22362. /* 58 */
  22363. { { 0x761dc90513482L,0x2a01e9276a81bL,0xce73083028720L,0xc6efcda441ee0L,
  22364. 0x016410690c63dL },
  22365. { 0x34a066d06a2edL,0x45189b100bf50L,0xb8218c9dd4d77L,0xbb4fd914ae72aL,
  22366. 0x0d73479fd7abcL } },
  22367. /* 59 */
  22368. { { 0xefb165ad4c6e5L,0x8f5b06d04d7edL,0x575cb14262cf0L,0x666b12ed5bb18L,
  22369. 0x0816469e30771L },
  22370. { 0xb9d79561e291eL,0x22c1de1661d7aL,0x35e0513eb9dafL,0x3f9cf49827eb1L,
  22371. 0x00a36dd23f0ddL } },
  22372. /* 60 */
  22373. { { 0xd32c741d5533cL,0x9e8684628f098L,0x349bd117c5f5aL,0xb11839a228adeL,
  22374. 0x0e331dfd6fdbaL },
  22375. { 0x0ab686bcc6ed8L,0xbdef7a260e510L,0xce850d77160c3L,0x33899063d9a7bL,
  22376. 0x0d3b4782a492eL } },
  22377. /* 61 */
  22378. { { 0x9b6e8f3821f90L,0xed66eb7aada14L,0xa01311692edd9L,0xa5bd0bb669531L,
  22379. 0x07281275a4c86L },
  22380. { 0x858f7d3ff47e5L,0xbc61016441503L,0xdfd9bb15e1616L,0x505962b0f11a7L,
  22381. 0x02c062e7ece14L } },
  22382. /* 62 */
  22383. { { 0xf996f0159ac2eL,0x36cbdb2713a76L,0x8e46047281e77L,0x7ef12ad6d2880L,
  22384. 0x0282a35f92c4eL },
  22385. { 0x54b1ec0ce5cd2L,0xc91379c2299c3L,0xe82c11ecf99efL,0x2abd992caf383L,
  22386. 0x0c71cd513554dL } },
  22387. /* 63 */
  22388. { { 0x5de9c09b578f4L,0x58e3affa7a488L,0x9182f1f1884e2L,0xf3a38f76b1b75L,
  22389. 0x0c50f6740cf47L },
  22390. { 0x4adf3374b68eaL,0x2369965fe2a9cL,0x5a53050a406f3L,0x58dc2f86a2228L,
  22391. 0x0b9ecb3a72129L } },
  22392. /* 64 */
  22393. { { 0x8410ef4f8b16aL,0xfec47b266a56fL,0xd9c87c197241aL,0xab1b0a406b8e6L,
  22394. 0x0803f3e02cd42L },
  22395. { 0x309a804dbec69L,0xf73bbad05f7f0L,0xd8e197fa83b85L,0xadc1c6097273aL,
  22396. 0x0c097440e5067L } },
  22397. /* 65 */
  22398. { { 0xa56f2c379ab34L,0x8b841df8d1846L,0x76c68efa8ee06L,0x1f30203144591L,
  22399. 0x0f1af32d5915fL },
  22400. { 0x375315d75bd50L,0xbaf72f67bc99cL,0x8d7723f837cffL,0x1c8b0613a4184L,
  22401. 0x023d0f130e2d4L } },
  22402. /* 66 */
  22403. { { 0xab6edf41500d9L,0xe5fcbeada8857L,0x97259510d890aL,0xfadd52fe86488L,
  22404. 0x0b0288dd6c0a3L },
  22405. { 0x20f30650bcb08L,0x13695d6e16853L,0x989aa7671af63L,0xc8d231f520a7bL,
  22406. 0x0ffd3724ff408L } },
  22407. /* 67 */
  22408. { { 0x68e64b458e6cbL,0x20317a5d28539L,0xaa75f56992dadL,0x26df3814ae0b7L,
  22409. 0x0f5590f4ad78cL },
  22410. { 0x24bd3cf0ba55aL,0x4a0c778bae0fcL,0x83b674a0fc472L,0x4a201ce9864f6L,
  22411. 0x018d6da54f6f7L } },
  22412. /* 68 */
  22413. { { 0x3e225d5be5a2bL,0x835934f3c6ed9L,0x2626ffc6fe799L,0x216a431409262L,
  22414. 0x050bbb4d97990L },
  22415. { 0x191c6e57ec63eL,0x40181dcdb2378L,0x236e0f665422cL,0x49c341a8099b0L,
  22416. 0x02b10011801feL } },
  22417. /* 69 */
  22418. { { 0x8b5c59b391593L,0xa2598270fcfc6L,0x19adcbbc385f5L,0xae0c7144f3aadL,
  22419. 0x0dd55899983fbL },
  22420. { 0x88b8e74b82ff4L,0x4071e734c993bL,0x3c0322ad2e03cL,0x60419a7a9eaf4L,
  22421. 0x0e6e4c551149dL } },
  22422. /* 70 */
  22423. { { 0x655bb1e9af288L,0x64f7ada93155fL,0xb2820e5647e1aL,0x56ff43697e4bcL,
  22424. 0x051e00db107edL },
  22425. { 0x169b8771c327eL,0x0b4a96c2ad43dL,0xdeb477929cdb2L,0x9177c07d51f53L,
  22426. 0x0e22f42414982L } },
  22427. /* 71 */
  22428. { { 0x5e8f4635f1abbL,0xb568538874cd4L,0x5a8034d7edc0cL,0x48c9c9472c1fbL,
  22429. 0x0f709373d52dcL },
  22430. { 0x966bba8af30d6L,0x4af137b69c401L,0x361c47e95bf5fL,0x5b113966162a9L,
  22431. 0x0bd52d288e727L } },
  22432. /* 72 */
  22433. { { 0x55c7a9c5fa877L,0x727d3a3d48ab1L,0x3d189d817dad6L,0x77a643f43f9e7L,
  22434. 0x0a0d0f8e4c8aaL },
  22435. { 0xeafd8cc94f92dL,0xbe0c4ddb3a0bbL,0x82eba14d818c8L,0x6a0022cc65f8bL,
  22436. 0x0a56c78c7946dL } },
  22437. /* 73 */
  22438. { { 0x2391b0dd09529L,0xa63daddfcf296L,0xb5bf481803e0eL,0x367a2c77351f5L,
  22439. 0x0d8befdf8731aL },
  22440. { 0x19d42fc0157f4L,0xd7fec8e650ab9L,0x2d48b0af51caeL,0x6478cdf9cb400L,
  22441. 0x0854a68a5ce9fL } },
  22442. /* 74 */
  22443. { { 0x5f67b63506ea5L,0x89a4fe0d66dc3L,0xe95cd4d9286c4L,0x6a953f101d3bfL,
  22444. 0x05cacea0b9884L },
  22445. { 0xdf60c9ceac44dL,0xf4354d1c3aa90L,0xd5dbabe3db29aL,0xefa908dd3de8aL,
  22446. 0x0e4982d1235e4L } },
  22447. /* 75 */
  22448. { { 0x04a22c34cd55eL,0xb32680d132231L,0xfa1d94358695bL,0x0499fb345afa1L,
  22449. 0x08046b7f616b2L },
  22450. { 0x3581e38e7d098L,0x8df46f0b70b53L,0x4cb78c4d7f61eL,0xaf5530dea9ea4L,
  22451. 0x0eb17ca7b9082L } },
  22452. /* 76 */
  22453. { { 0x1b59876a145b9L,0x0fc1bc71ec175L,0x92715bba5cf6bL,0xe131d3e035653L,
  22454. 0x0097b00bafab5L },
  22455. { 0x6c8e9565f69e1L,0x5ab5be5199aa6L,0xa4fd98477e8f7L,0xcc9e6033ba11dL,
  22456. 0x0f95c747bafdbL } },
  22457. /* 77 */
  22458. { { 0xf01d3bebae45eL,0xf0c4bc6955558L,0xbc64fc6a8ebe9L,0xd837aeb705b1dL,
  22459. 0x03512601e566eL },
  22460. { 0x6f1e1fa1161cdL,0xd54c65ef87933L,0x24f21e5328ab8L,0xab6b4757eee27L,
  22461. 0x00ef971236068L } },
  22462. /* 78 */
  22463. { { 0x98cf754ca4226L,0x38f8642c8e025L,0x68e17905eede1L,0xbc9548963f744L,
  22464. 0x0fc16d9333b4fL },
  22465. { 0x6fb31e7c800caL,0x312678adaabe9L,0xff3e8b5138063L,0x7a173d6244976L,
  22466. 0x014ca4af1b95dL } },
  22467. /* 79 */
  22468. { { 0x771babd2f81d5L,0x6901f7d1967a4L,0xad9c9071a5f9dL,0x231dd898bef7cL,
  22469. 0x04057b063f59cL },
  22470. { 0xd82fe89c05c0aL,0x6f1dc0df85bffL,0x35a16dbe4911cL,0x0b133befccaeaL,
  22471. 0x01c3b5d64f133L } },
  22472. /* 80 */
  22473. { { 0x14bfe80ec21feL,0x6ac255be825feL,0xf4a5d67f6ce11L,0x63af98bc5a072L,
  22474. 0x0fad27148db7eL },
  22475. { 0x0b6ac29ab05b3L,0x3c4e251ae690cL,0x2aade7d37a9a8L,0x1a840a7dc875cL,
  22476. 0x077387de39f0eL } },
  22477. /* 81 */
  22478. { { 0xecc49a56c0dd7L,0xd846086c741e9L,0x505aecea5cffcL,0xc47e8f7a1408fL,
  22479. 0x0b37b85c0bef0L },
  22480. { 0x6b6e4cc0e6a8fL,0xbf6b388f23359L,0x39cef4efd6d4bL,0x28d5aba453facL,
  22481. 0x09c135ac8f9f6L } },
  22482. /* 82 */
  22483. { { 0xa320284e35743L,0xb185a3cdef32aL,0xdf19819320d6aL,0x851fb821b1761L,
  22484. 0x05721361fc433L },
  22485. { 0xdb36a71fc9168L,0x735e5c403c1f0L,0x7bcd8f55f98baL,0x11bdf64ca87e3L,
  22486. 0x0dcbac3c9e6bbL } },
  22487. /* 83 */
  22488. { { 0xd99684518cbe2L,0x189c9eb04ef01L,0x47feebfd242fcL,0x6862727663c7eL,
  22489. 0x0b8c1c89e2d62L },
  22490. { 0x58bddc8e1d569L,0xc8b7d88cd051aL,0x11f31eb563809L,0x22d426c27fd9fL,
  22491. 0x05d23bbda2f94L } },
  22492. /* 84 */
  22493. { { 0xc729495c8f8beL,0x803bf362bf0a1L,0xf63d4ac2961c4L,0xe9009e418403dL,
  22494. 0x0c109f9cb91ecL },
  22495. { 0x095d058945705L,0x96ddeb85c0c2dL,0xa40449bb9083dL,0x1ee184692b8d7L,
  22496. 0x09bc3344f2eeeL } },
  22497. /* 85 */
  22498. { { 0xae35642913074L,0x2748a542b10d5L,0x310732a55491bL,0x4cc1469ca665bL,
  22499. 0x029591d525f1aL },
  22500. { 0xf5b6bb84f983fL,0x419f5f84e1e76L,0x0baa189be7eefL,0x332c1200d4968L,
  22501. 0x06376551f18efL } },
  22502. /* 86 */
  22503. { { 0x5f14e562976ccL,0xe60ef12c38bdaL,0xcca985222bca3L,0x987abbfa30646L,
  22504. 0x0bdb79dc808e2L },
  22505. { 0xcb5c9cb06a772L,0xaafe536dcefd2L,0xc2b5db838f475L,0xc14ac2a3e0227L,
  22506. 0x08ee86001add3L } },
  22507. /* 87 */
  22508. { { 0x96981a4ade873L,0x4dc4fba48ccbeL,0xa054ba57ee9aaL,0xaa4b2cee28995L,
  22509. 0x092e51d7a6f77L },
  22510. { 0xbafa87190a34dL,0x5bf6bd1ed1948L,0xcaf1144d698f7L,0xaaaad00ee6e30L,
  22511. 0x05182f86f0a56L } },
  22512. /* 88 */
  22513. { { 0x6212c7a4cc99cL,0x683e6d9ca1fbaL,0xac98c5aff609bL,0xa6f25dbb27cb5L,
  22514. 0x091dcab5d4073L },
  22515. { 0x6cc3d5f575a70L,0x396f8d87fa01bL,0x99817360cb361L,0x4f2b165d4e8c8L,
  22516. 0x017a0cedb9797L } },
  22517. /* 89 */
  22518. { { 0x61e2a076c8d3aL,0x39210f924b388L,0x3a835d9701aadL,0xdf4194d0eae41L,
  22519. 0x02e8ce36c7f4cL },
  22520. { 0x73dab037a862bL,0xb760e4c8fa912L,0x3baf2dd01ba9bL,0x68f3f96453883L,
  22521. 0x0f4ccc6cb34f6L } },
  22522. /* 90 */
  22523. { { 0xf525cf1f79687L,0x9592efa81544eL,0x5c78d297c5954L,0xf3c9e1231741aL,
  22524. 0x0ac0db4889a0dL },
  22525. { 0xfc711df01747fL,0x58ef17df1386bL,0xccb6bb5592b93L,0x74a2e5880e4f5L,
  22526. 0x095a64a6194c9L } },
  22527. /* 91 */
  22528. { { 0x1efdac15a4c93L,0x738258514172cL,0x6cb0bad40269bL,0x06776a8dfb1c1L,
  22529. 0x0231e54ba2921L },
  22530. { 0xdf9178ae6d2dcL,0x3f39112918a70L,0xe5b72234d6aa6L,0x31e1f627726b5L,
  22531. 0x0ab0be032d8a7L } },
  22532. /* 92 */
  22533. { { 0xad0e98d131f2dL,0xe33b04f101097L,0x5e9a748637f09L,0xa6791ac86196dL,
  22534. 0x0f1bcc8802cf6L },
  22535. { 0x69140e8daacb4L,0x5560f6500925cL,0x77937a63c4e40L,0xb271591cc8fc4L,
  22536. 0x0851694695aebL } },
  22537. /* 93 */
  22538. { { 0x5c143f1dcf593L,0x29b018be3bde3L,0xbdd9d3d78202bL,0x55d8e9cdadc29L,
  22539. 0x08f67d9d2daadL },
  22540. { 0x116567481ea5fL,0xe9e34c590c841L,0x5053fa8e7d2ddL,0x8b5dffdd43f40L,
  22541. 0x0f84572b9c072L } },
  22542. /* 94 */
  22543. { { 0xa7a7197af71c9L,0x447a7365655e1L,0xe1d5063a14494L,0x2c19a1b4ae070L,
  22544. 0x0edee2710616bL },
  22545. { 0x034f511734121L,0x554a25e9f0b2fL,0x40c2ecf1cac6eL,0xd7f48dc148f3aL,
  22546. 0x09fd27e9b44ebL } },
  22547. /* 95 */
  22548. { { 0x7658af6e2cb16L,0x2cfe5919b63ccL,0x68d5583e3eb7dL,0xf3875a8c58161L,
  22549. 0x0a40c2fb6958fL },
  22550. { 0xec560fedcc158L,0xc655f230568c9L,0xa307e127ad804L,0xdecfd93967049L,
  22551. 0x099bc9bb87dc6L } },
  22552. /* 96 */
  22553. { { 0x9521d927dafc6L,0x695c09cd1984aL,0x9366dde52c1fbL,0x7e649d9581a0fL,
  22554. 0x09abe210ba16dL },
  22555. { 0xaf84a48915220L,0x6a4dd816c6480L,0x681ca5afa7317L,0x44b0c7d539871L,
  22556. 0x07881c25787f3L } },
  22557. /* 97 */
  22558. { { 0x99b51e0bcf3ffL,0xc5127f74f6933L,0xd01d9680d02cbL,0x89408fb465a2dL,
  22559. 0x015e6e319a30eL },
  22560. { 0xd6e0d3e0e05f4L,0xdc43588404646L,0x4f850d3fad7bdL,0x72cebe61c7d1cL,
  22561. 0x00e55facf1911L } },
  22562. /* 98 */
  22563. { { 0xd9806f8787564L,0x2131e85ce67e9L,0x819e8d61a3317L,0x65776b0158cabL,
  22564. 0x0d73d09766fe9L },
  22565. { 0x834251eb7206eL,0x0fc618bb42424L,0xe30a520a51929L,0xa50b5dcbb8595L,
  22566. 0x09250a3748f15L } },
  22567. /* 99 */
  22568. { { 0xf08f8be577410L,0x035077a8c6cafL,0xc0a63a4fd408aL,0x8c0bf1f63289eL,
  22569. 0x077414082c1ccL },
  22570. { 0x40fa6eb0991cdL,0x6649fdc29605aL,0x324fd40c1ca08L,0x20b93a68a3c7bL,
  22571. 0x08cb04f4d12ebL } },
  22572. /* 100 */
  22573. { { 0x2d0556906171cL,0xcdb0240c3fb1cL,0x89068419073e9L,0x3b51db8e6b4fdL,
  22574. 0x0e4e429ef4712L },
  22575. { 0xdd53c38ec36f4L,0x01ff4b6a270b8L,0x79a9a48f9d2dcL,0x65525d066e078L,
  22576. 0x037bca2ff3c6eL } },
  22577. /* 101 */
  22578. { { 0x2e3c7df562470L,0xa2c0964ac94cdL,0x0c793be44f272L,0xb22a7c6d5df98L,
  22579. 0x059913edc3002L },
  22580. { 0x39a835750592aL,0x80e783de027a1L,0xa05d64f99e01dL,0xe226cf8c0375eL,
  22581. 0x043786e4ab013L } },
  22582. /* 102 */
  22583. { { 0x2b0ed9e56b5a6L,0xa6d9fc68f9ff3L,0x97846a70750d9L,0x9e7aec15e8455L,
  22584. 0x08638ca98b7e7L },
  22585. { 0xae0960afc24b2L,0xaf4dace8f22f5L,0xecba78f05398eL,0xa6f03b765dd0aL,
  22586. 0x01ecdd36a7b3aL } },
  22587. /* 103 */
  22588. { { 0xacd626c5ff2f3L,0xc02873a9785d3L,0x2110d54a2d516L,0xf32dad94c9fadL,
  22589. 0x0d85d0f85d459L },
  22590. { 0x00b8d10b11da3L,0x30a78318c49f7L,0x208decdd2c22cL,0x3c62556988f49L,
  22591. 0x0a04f19c3b4edL } },
  22592. /* 104 */
  22593. { { 0x924c8ed7f93bdL,0x5d392f51f6087L,0x21b71afcb64acL,0x50b07cae330a8L,
  22594. 0x092b2eeea5c09L },
  22595. { 0xc4c9485b6e235L,0xa92936c0f085aL,0x0508891ab2ca4L,0x276c80faa6b3eL,
  22596. 0x01ee782215834L } },
  22597. /* 105 */
  22598. { { 0xa2e00e63e79f7L,0xb2f399d906a60L,0x607c09df590e7L,0xe1509021054a6L,
  22599. 0x0f3f2ced857a6L },
  22600. { 0x510f3f10d9b55L,0xacd8642648200L,0x8bd0e7c9d2fcfL,0xe210e5631aa7eL,
  22601. 0x00f56a4543da3L } },
  22602. /* 106 */
  22603. { { 0x1bffa1043e0dfL,0xcc9c007e6d5b2L,0x4a8517a6c74b6L,0xe2631a656ec0dL,
  22604. 0x0bd8f17411969L },
  22605. { 0xbbb86beb7494aL,0x6f45f3b8388a9L,0x4e5a79a1567d4L,0xfa09df7a12a7aL,
  22606. 0x02d1a1c3530ccL } },
  22607. /* 107 */
  22608. { { 0xe3813506508daL,0xc4a1d795a7192L,0xa9944b3336180L,0xba46cddb59497L,
  22609. 0x0a107a65eb91fL },
  22610. { 0x1d1c50f94d639L,0x758a58b7d7e6dL,0xd37ca1c8b4af3L,0x9af21a7c5584bL,
  22611. 0x0183d760af87aL } },
  22612. /* 108 */
  22613. { { 0x697110dde59a4L,0x070e8bef8729dL,0xf2ebe78f1ad8dL,0xd754229b49634L,
  22614. 0x01d44179dc269L },
  22615. { 0xdc0cf8390d30eL,0x530de8110cb32L,0xbc0339a0a3b27L,0xd26231af1dc52L,
  22616. 0x0771f9cc29606L } },
  22617. /* 109 */
  22618. { { 0x93e7785040739L,0xb98026a939999L,0x5f8fc2644539dL,0x718ecf40f6f2fL,
  22619. 0x064427a310362L },
  22620. { 0xf2d8785428aa8L,0x3febfb49a84f4L,0x23d01ac7b7adcL,0x0d6d201b2c6dfL,
  22621. 0x049d9b7496ae9L } },
  22622. /* 110 */
  22623. { { 0x8d8bc435d1099L,0x4e8e8d1a08cc7L,0xcb68a412adbcdL,0x544502c2e2a02L,
  22624. 0x09037d81b3f60L },
  22625. { 0xbac27074c7b61L,0xab57bfd72e7cdL,0x96d5352fe2031L,0x639c61ccec965L,
  22626. 0x008c3de6a7cc0L } },
  22627. /* 111 */
  22628. { { 0xdd020f6d552abL,0x9805cd81f120fL,0x135129156baffL,0x6b2f06fb7c3e9L,
  22629. 0x0c69094424579L },
  22630. { 0x3ae9c41231bd1L,0x875cc5820517bL,0x9d6a1221eac6eL,0x3ac0208837abfL,
  22631. 0x03fa3db02cafeL } },
  22632. /* 112 */
  22633. { { 0xa3e6505058880L,0xef643943f2d75L,0xab249257da365L,0x08ff4147861cfL,
  22634. 0x0c5c4bdb0fdb8L },
  22635. { 0x13e34b272b56bL,0x9511b9043a735L,0x8844969c8327eL,0xb6b5fd8ce37dfL,
  22636. 0x02d56db9446c2L } },
  22637. /* 113 */
  22638. { { 0x1782fff46ac6bL,0x2607a2e425246L,0x9a48de1d19f79L,0xba42fafea3c40L,
  22639. 0x00f56bd9de503L },
  22640. { 0xd4ed1345cda49L,0xfc816f299d137L,0xeb43402821158L,0xb5f1e7c6a54aaL,
  22641. 0x04003bb9d1173L } },
  22642. /* 114 */
  22643. { { 0xe8189a0803387L,0xf539cbd4043b8L,0x2877f21ece115L,0x2f9e4297208ddL,
  22644. 0x053765522a07fL },
  22645. { 0x80a21a8a4182dL,0x7a3219df79a49L,0xa19a2d4a2bbd0L,0x4549674d0a2e1L,
  22646. 0x07a056f586c5dL } },
  22647. /* 115 */
  22648. { { 0xb25589d8a2a47L,0x48c3df2773646L,0xbf0d5395b5829L,0x267551ec000eaL,
  22649. 0x077d482f17a1aL },
  22650. { 0x1bd9587853948L,0xbd6cfbffeeb8aL,0x0681e47a6f817L,0xb0e4ab6ec0578L,
  22651. 0x04115012b2b38L } },
  22652. /* 116 */
  22653. { { 0x3f0f46de28cedL,0x609b13ec473c7L,0xe5c63921d5da7L,0x094661b8ce9e6L,
  22654. 0x0cdf04572fbeaL },
  22655. { 0x3c58b6c53c3b0L,0x10447b843c1cbL,0xcb9780e97fe3cL,0x3109fb2b8ae12L,
  22656. 0x0ee703dda9738L } },
  22657. /* 117 */
  22658. { { 0x15140ff57e43aL,0xd3b1b811b8345L,0xf42b986d44660L,0xce212b3b5dff8L,
  22659. 0x02a0ad89da162L },
  22660. { 0x4a6946bc277baL,0x54c141c27664eL,0xabf6274c788c9L,0x4659141aa64ccL,
  22661. 0x0d62d0b67ac2bL } },
  22662. /* 118 */
  22663. { { 0x5d87b2c054ac4L,0x59f27df78839cL,0x18128d6570058L,0x2426edf7cbf3bL,
  22664. 0x0b39a23f2991cL },
  22665. { 0x84a15f0b16ae5L,0xb1a136f51b952L,0x27007830c6a05L,0x4cc51d63c137fL,
  22666. 0x004ed0092c067L } },
  22667. /* 119 */
  22668. { { 0x185d19ae90393L,0x294a3d64e61f4L,0x854fc143047b4L,0xc387ae0001a69L,
  22669. 0x0a0a91fc10177L },
  22670. { 0xa3f01ae2c831eL,0x822b727e16ff0L,0xa3075b4bb76aeL,0x0c418f12c8a15L,
  22671. 0x0084cf9889ed2L } },
  22672. /* 120 */
  22673. { { 0x509defca6becfL,0x807dffb328d98L,0x778e8b92fceaeL,0xf77e5d8a15c44L,
  22674. 0x0d57955b273abL },
  22675. { 0xda79e31b5d4f1L,0x4b3cfa7a1c210L,0xc27c20baa52f0L,0x41f1d4d12089dL,
  22676. 0x08e14ea4202d1L } },
  22677. /* 121 */
  22678. { { 0x50345f2897042L,0x1f43402c4aeedL,0x8bdfb218d0533L,0xd158c8d9c194cL,
  22679. 0x0597e1a372aa4L },
  22680. { 0x7ec1acf0bd68cL,0xdcab024945032L,0x9fe3e846d4be0L,0x4dea5b9c8d7acL,
  22681. 0x0ca3f0236199bL } },
  22682. /* 122 */
  22683. { { 0xa10b56170bd20L,0xf16d3f5de7592L,0x4b2ade20ea897L,0x07e4a3363ff14L,
  22684. 0x0bde7fd7e309cL },
  22685. { 0xbb6d2b8f5432cL,0xcbe043444b516L,0x8f95b5a210dc1L,0xd1983db01e6ffL,
  22686. 0x0b623ad0e0a7dL } },
  22687. /* 123 */
  22688. { { 0xbd67560c7b65bL,0x9023a4a289a75L,0x7b26795ab8c55L,0x137bf8220fd0dL,
  22689. 0x0d6aa2e4658ecL },
  22690. { 0xbc00b5138bb85L,0x21d833a95c10aL,0x702a32e8c31d1L,0x513ab24ff00b1L,
  22691. 0x0111662e02dccL } },
  22692. /* 124 */
  22693. { { 0x14015efb42b87L,0x701b6c4dff781L,0x7d7c129bd9f5dL,0x50f866ecccd7aL,
  22694. 0x0db3ee1cb94b7L },
  22695. { 0xf3db0f34837cfL,0x8bb9578d4fb26L,0xc56657de7eed1L,0x6a595d2cdf937L,
  22696. 0x0886a64425220L } },
  22697. /* 125 */
  22698. { { 0x34cfb65b569eaL,0x41f72119c13c2L,0x15a619e200111L,0x17bc8badc85daL,
  22699. 0x0a70cf4eb018aL },
  22700. { 0xf97ae8c4a6a65L,0x270134378f224L,0xf7e096036e5cfL,0x7b77be3a609e4L,
  22701. 0x0aa4772abd174L } },
  22702. /* 126 */
  22703. { { 0x761317aa60cc0L,0x610368115f676L,0xbc1bb5ac79163L,0xf974ded98bb4bL,
  22704. 0x0611a6ddc30faL },
  22705. { 0x78cbcc15ee47aL,0x824e0d96a530eL,0xdd9ed882e8962L,0x9c8836f35adf3L,
  22706. 0x05cfffaf81642L } },
  22707. /* 127 */
  22708. { { 0x54cff9b7a99cdL,0x9d843c45a1c0dL,0x2c739e17bf3b9L,0x994c038a908f6L,
  22709. 0x06e5a6b237dc1L },
  22710. { 0xb454e0ba5db77L,0x7facf60d63ef8L,0x6608378b7b880L,0xabcce591c0c67L,
  22711. 0x0481a238d242dL } },
  22712. /* 128 */
  22713. { { 0x17bc035d0b34aL,0x6b8327c0a7e34L,0xc0362d1440b38L,0xf9438fb7262daL,
  22714. 0x02c41114ce0cdL },
  22715. { 0x5cef1ad95a0b1L,0xa867d543622baL,0x1e486c9c09b37L,0x929726d6cdd20L,
  22716. 0x020477abf42ffL } },
  22717. /* 129 */
  22718. { { 0x5173c18d65dbfL,0x0e339edad82f7L,0xcf1001c77bf94L,0x96b67022d26bdL,
  22719. 0x0ac66409ac773L },
  22720. { 0xbb36fc6261cc3L,0xc9190e7e908b0L,0x45e6c10213f7bL,0x2f856541cebaaL,
  22721. 0x0ce8e6975cc12L } },
  22722. /* 130 */
  22723. { { 0x21b41bc0a67d2L,0x0a444d248a0f1L,0x59b473762d476L,0xb4a80e044f1d6L,
  22724. 0x008fde365250bL },
  22725. { 0xec3da848bf287L,0x82d3369d6eaceL,0x2449482c2a621L,0x6cd73582dfdc9L,
  22726. 0x02f7e2fd2565dL } },
  22727. /* 131 */
  22728. { { 0xb92dbc3770fa7L,0x5c379043f9ae4L,0x7761171095e8dL,0x02ae54f34e9d1L,
  22729. 0x0c65be92e9077L },
  22730. { 0x8a303f6fd0a40L,0xe3bcce784b275L,0xf9767bfe7d822L,0x3b3a7ae4f5854L,
  22731. 0x04bff8e47d119L } },
  22732. /* 132 */
  22733. { { 0x1d21f00ff1480L,0x7d0754db16cd4L,0xbe0f3ea2ab8fbL,0x967dac81d2efbL,
  22734. 0x03e4e4ae65772L },
  22735. { 0x8f36d3c5303e6L,0x4b922623977e1L,0x324c3c03bd999L,0x60289ed70e261L,
  22736. 0x05388aefd58ecL } },
  22737. /* 133 */
  22738. { { 0x317eb5e5d7713L,0xee75de49daad1L,0x74fb26109b985L,0xbe0e32f5bc4fcL,
  22739. 0x05cf908d14f75L },
  22740. { 0x435108e657b12L,0xa5b96ed9e6760L,0x970ccc2bfd421L,0x0ce20e29f51f8L,
  22741. 0x0a698ba4060f0L } },
  22742. /* 134 */
  22743. { { 0xb1686ef748fecL,0xa27e9d2cf973dL,0xe265effe6e755L,0xad8d630b6544cL,
  22744. 0x0b142ef8a7aebL },
  22745. { 0x1af9f17d5770aL,0x672cb3412fad3L,0xf3359de66af3bL,0x50756bd60d1bdL,
  22746. 0x0d1896a965851L } },
  22747. /* 135 */
  22748. { { 0x957ab33c41c08L,0xac5468e2e1ec5L,0xc472f6c87de94L,0xda3918816b73aL,
  22749. 0x0267b0e0b7981L },
  22750. { 0x54e5d8e62b988L,0x55116d21e76e5L,0xd2a6f99d8ddc7L,0x93934610faf03L,
  22751. 0x0b54e287aa111L } },
  22752. /* 136 */
  22753. { { 0x122b5178a876bL,0xff085104b40a0L,0x4f29f7651ff96L,0xd4e6050b31ab1L,
  22754. 0x084abb28b5f87L },
  22755. { 0xd439f8270790aL,0x9d85e3f46bd5eL,0xc1e22122d6cb5L,0x564075f55c1b6L,
  22756. 0x0e5436f671765L } },
  22757. /* 137 */
  22758. { { 0x9025e2286e8d5L,0xb4864453be53fL,0x408e3a0353c95L,0xe99ed832f5bdeL,
  22759. 0x00404f68b5b9cL },
  22760. { 0x33bdea781e8e5L,0x18163c2f5bcadL,0x119caa33cdf50L,0xc701575769600L,
  22761. 0x03a4263df0ac1L } },
  22762. /* 138 */
  22763. { { 0x65ecc9aeb596dL,0xe7023c92b4c29L,0xe01396101ea03L,0xa3674704b4b62L,
  22764. 0x00ca8fd3f905eL },
  22765. { 0x23a42551b2b61L,0x9c390fcd06925L,0x392a63e1eb7a8L,0x0c33e7f1d2be0L,
  22766. 0x096dca2644ddbL } },
  22767. /* 139 */
  22768. { { 0xbb43a387510afL,0xa8a9a36a01203L,0xf950378846feaL,0x59dcd23a57702L,
  22769. 0x04363e2123aadL },
  22770. { 0x3a1c740246a47L,0xd2e55dd24dca4L,0xd8faf96b362b8L,0x98c4f9b086045L,
  22771. 0x0840e115cd8bbL } },
  22772. /* 140 */
  22773. { { 0x205e21023e8a7L,0xcdd8dc7a0bf12L,0x63a5ddfc808a8L,0xd6d4e292a2721L,
  22774. 0x05e0d6abd30deL },
  22775. { 0x721c27cfc0f64L,0x1d0e55ed8807aL,0xd1f9db242eec0L,0xa25a26a7bef91L,
  22776. 0x07dea48f42945L } },
  22777. /* 141 */
  22778. { { 0xf6f1ce5060a81L,0x72f8f95615abdL,0x6ac268be79f9cL,0x16d1cfd36c540L,
  22779. 0x0abc2a2beebfdL },
  22780. { 0x66f91d3e2eac7L,0x63d2dd04668acL,0x282d31b6f10baL,0xefc16790e3770L,
  22781. 0x04ea353946c7eL } },
  22782. /* 142 */
  22783. { { 0xa2f8d5266309dL,0xc081945a3eed8L,0x78c5dc10a51c6L,0xffc3cecaf45a5L,
  22784. 0x03a76e6891c94L },
  22785. { 0xce8a47d7b0d0fL,0x968f584a5f9aaL,0xe697fbe963aceL,0x646451a30c724L,
  22786. 0x08212a10a465eL } },
  22787. /* 143 */
  22788. { { 0xc61c3cfab8caaL,0x840e142390ef7L,0xe9733ca18eb8eL,0xb164cd1dff677L,
  22789. 0x0aa7cab71599cL },
  22790. { 0xc9273bc837bd1L,0xd0c36af5d702fL,0x423da49c06407L,0x17c317621292fL,
  22791. 0x040e38073fe06L } },
  22792. /* 144 */
  22793. { { 0x80824a7bf9b7cL,0x203fbe30d0f4fL,0x7cf9ce3365d23L,0x5526bfbe53209L,
  22794. 0x0e3604700b305L },
  22795. { 0xb99116cc6c2c7L,0x08ba4cbee64dcL,0x37ad9ec726837L,0xe15fdcded4346L,
  22796. 0x06542d677a3deL } },
  22797. /* 145 */
  22798. { { 0x2b6d07b6c377aL,0x47903448be3f3L,0x0da8af76cb038L,0x6f21d6fdd3a82L,
  22799. 0x0a6534aee09bbL },
  22800. { 0x1780d1035facfL,0x339dcb47e630aL,0x447f39335e55aL,0xef226ea50fe1cL,
  22801. 0x0f3cb672fdc9aL } },
  22802. /* 146 */
  22803. { { 0x719fe3b55fd83L,0x6c875ddd10eb3L,0x5cea784e0d7a4L,0x70e733ac9fa90L,
  22804. 0x07cafaa2eaae8L },
  22805. { 0x14d041d53b338L,0xa0ef87e6c69b8L,0x1672b0fe0acc0L,0x522efb93d1081L,
  22806. 0x00aab13c1b9bdL } },
  22807. /* 147 */
  22808. { { 0xce278d2681297L,0xb1b509546addcL,0x661aaf2cb350eL,0x12e92dc431737L,
  22809. 0x04b91a6028470L },
  22810. { 0xf109572f8ddcfL,0x1e9a911af4dcfL,0x372430e08ebf6L,0x1cab48f4360acL,
  22811. 0x049534c537232L } },
  22812. /* 148 */
  22813. { { 0xf7d71f07b7e9dL,0xa313cd516f83dL,0xc047ee3a478efL,0xc5ee78ef264b6L,
  22814. 0x0caf46c4fd65aL },
  22815. { 0xd0c7792aa8266L,0x66913684bba04L,0xe4b16b0edf454L,0x770f56e65168aL,
  22816. 0x014ce9e5704c6L } },
  22817. /* 149 */
  22818. { { 0x45e3e965e8f91L,0xbacb0f2492994L,0x0c8a0a0d3aca1L,0x9a71d31cc70f9L,
  22819. 0x01bb708a53e4cL },
  22820. { 0xa9e69558bdd7aL,0x08018a26b1d5cL,0xc9cf1ec734a05L,0x0102b093aa714L,
  22821. 0x0f9d126f2da30L } },
  22822. /* 150 */
  22823. { { 0xbca7aaff9563eL,0xfeb49914a0749L,0xf5f1671dd077aL,0xcc69e27a0311bL,
  22824. 0x0807afcb9729eL },
  22825. { 0xa9337c9b08b77L,0x85443c7e387f8L,0x76fd8ba86c3a7L,0xcd8c85fafa594L,
  22826. 0x0751adcd16568L } },
  22827. /* 151 */
  22828. { { 0xa38b410715c0dL,0x718f7697f78aeL,0x3fbf06dd113eaL,0x743f665eab149L,
  22829. 0x029ec44682537L },
  22830. { 0x4719cb50bebbcL,0xbfe45054223d9L,0xd2dedb1399ee5L,0x077d90cd5b3a8L,
  22831. 0x0ff9370e392a4L } },
  22832. /* 152 */
  22833. { { 0x2d69bc6b75b65L,0xd5266651c559aL,0xde9d7d24188f8L,0xd01a28a9f33e3L,
  22834. 0x09776478ba2a9L },
  22835. { 0x2622d929af2c7L,0x6d4e690923885L,0x89a51e9334f5dL,0x82face6cc7e5aL,
  22836. 0x074a6313fac2fL } },
  22837. /* 153 */
  22838. { { 0x4dfddb75f079cL,0x9518e36fbbb2fL,0x7cd36dd85b07cL,0x863d1b6cfcf0eL,
  22839. 0x0ab75be150ff4L },
  22840. { 0x367c0173fc9b7L,0x20d2594fd081bL,0x4091236b90a74L,0x59f615fdbf03cL,
  22841. 0x04ebeac2e0b44L } },
  22842. /* 154 */
  22843. { { 0xc5fe75c9f2c53L,0x118eae9411eb6L,0x95ac5d8d25220L,0xaffcc8887633fL,
  22844. 0x0df99887b2c1bL },
  22845. { 0x8eed2850aaecbL,0x1b01d6a272bb7L,0x1cdbcac9d4918L,0x4058978dd511bL,
  22846. 0x027b040a7779fL } },
  22847. /* 155 */
  22848. { { 0x05db7f73b2eb2L,0x088e1b2118904L,0x962327ee0df85L,0xa3f5501b71525L,
  22849. 0x0b393dd37e4cfL },
  22850. { 0x30e7b3fd75165L,0xc2bcd33554a12L,0xf7b5022d66344L,0x34196c36f1be0L,
  22851. 0x009588c12d046L } },
  22852. /* 156 */
  22853. { { 0x6093f02601c3bL,0xf8cf5c335fe08L,0x94aff28fb0252L,0x648b955cf2808L,
  22854. 0x081c879a9db9fL },
  22855. { 0xe687cc6f56c51L,0x693f17618c040L,0x059353bfed471L,0x1bc444f88a419L,
  22856. 0x0fa0d48f55fc1L } },
  22857. /* 157 */
  22858. { { 0xe1c9de1608e4dL,0x113582822cbc6L,0x57ec2d7010ddaL,0x67d6f6b7ddc11L,
  22859. 0x08ea0e156b6a3L },
  22860. { 0x4e02f2383b3b4L,0x943f01f53ca35L,0xde03ca569966bL,0xb5ac4ff6632b2L,
  22861. 0x03f5ab924fa00L } },
  22862. /* 158 */
  22863. { { 0xbb0d959739efbL,0xf4e7ebec0d337L,0x11a67d1c751b0L,0x256e2da52dd64L,
  22864. 0x08bc768872b74L },
  22865. { 0xe3b7282d3d253L,0xa1f58d779fa5bL,0x16767bba9f679L,0xf34fa1cac168eL,
  22866. 0x0b386f19060fcL } },
  22867. /* 159 */
  22868. { { 0x3c1352fedcfc2L,0x6262f8af0d31fL,0x57288c25396bfL,0x9c4d9a02b4eaeL,
  22869. 0x04cb460f71b06L },
  22870. { 0x7b4d35b8095eaL,0x596fc07603ae6L,0x614a16592bbf8L,0x5223e1475f66bL,
  22871. 0x052c0d50895efL } },
  22872. /* 160 */
  22873. { { 0xc210e15339848L,0xe870778c8d231L,0x956e170e87a28L,0x9c0b9d1de6616L,
  22874. 0x04ac3c9382bb0L },
  22875. { 0xe05516998987dL,0xc4ae09f4d619bL,0xa3f933d8b2376L,0x05f41de0b7651L,
  22876. 0x0380d94c7e397L } },
  22877. /* 161 */
  22878. { { 0x355aa81542e75L,0xa1ee01b9b701aL,0x24d708796c724L,0x37af6b3a29776L,
  22879. 0x02ce3e171de26L },
  22880. { 0xfeb49f5d5bc1aL,0x7e2777e2b5cfeL,0x513756ca65560L,0x4e4d4feaac2f9L,
  22881. 0x02e6cd8520b62L } },
  22882. /* 162 */
  22883. { { 0x5954b8c31c31dL,0x005bf21a0c368L,0x5c79ec968533dL,0x9d540bd7626e7L,
  22884. 0x0ca17754742c6L },
  22885. { 0xedafff6d2dbb2L,0xbd174a9d18cc6L,0xa4578e8fd0d8cL,0x2ce6875e8793aL,
  22886. 0x0a976a7139cabL } },
  22887. /* 163 */
  22888. { { 0x51f1b93fb353dL,0x8b57fcfa720a6L,0x1b15281d75cabL,0x4999aa88cfa73L,
  22889. 0x08720a7170a1fL },
  22890. { 0xe8d37693e1b90L,0x0b16f6dfc38c3L,0x52a8742d345dcL,0x893c8ea8d00abL,
  22891. 0x09719ef29c769L } },
  22892. /* 164 */
  22893. { { 0xeed8d58e35909L,0xdc33ddc116820L,0xe2050269366d8L,0x04c1d7f999d06L,
  22894. 0x0a5072976e157L },
  22895. { 0xa37eac4e70b2eL,0x576890aa8a002L,0x45b2a5c84dcf6L,0x7725cd71bf186L,
  22896. 0x099389c9df7b7L } },
  22897. /* 165 */
  22898. { { 0xc08f27ada7a4bL,0x03fd389366238L,0x66f512c3abe9dL,0x82e46b672e897L,
  22899. 0x0a88806aa202cL },
  22900. { 0x2044ad380184eL,0xc4126a8b85660L,0xd844f17a8cb78L,0xdcfe79d670c0aL,
  22901. 0x00043bffb4738L } },
  22902. /* 166 */
  22903. { { 0x9b5dc36d5192eL,0xd34590b2af8d5L,0x1601781acf885L,0x486683566d0a1L,
  22904. 0x052f3ef01ba6cL },
  22905. { 0x6732a0edcb64dL,0x238068379f398L,0x040f3090a482cL,0x7e7516cbe5fa7L,
  22906. 0x03296bd899ef2L } },
  22907. /* 167 */
  22908. { { 0xaba89454d81d7L,0xef51eb9b3c476L,0x1c579869eade7L,0x71e9619a21cd8L,
  22909. 0x03b90febfaee5L },
  22910. { 0x3023e5496f7cbL,0xd87fb51bc4939L,0x9beb5ce55be41L,0x0b1803f1dd489L,
  22911. 0x06e88069d9f81L } },
  22912. /* 168 */
  22913. { { 0x7ab11b43ea1dbL,0xa95259d292ce3L,0xf84f1860a7ff1L,0xad13851b02218L,
  22914. 0x0a7222beadefaL },
  22915. { 0xc78ec2b0a9144L,0x51f2fa59c5a2aL,0x147ce385a0240L,0xc69091d1eca56L,
  22916. 0x0be94d523bc2aL } },
  22917. /* 169 */
  22918. { { 0x4945e0b226ce7L,0x47967e8b7072fL,0x5a6c63eb8afd7L,0xc766edea46f18L,
  22919. 0x07782defe9be8L },
  22920. { 0xd2aa43db38626L,0x8776f67ad1760L,0x4499cdb460ae7L,0x2e4b341b86fc5L,
  22921. 0x003838567a289L } },
  22922. /* 170 */
  22923. { { 0xdaefd79ec1a0fL,0xfdceb39c972d8L,0x8f61a953bbcd6L,0xb420f5575ffc5L,
  22924. 0x0dbd986c4adf7L },
  22925. { 0xa881415f39eb7L,0xf5b98d976c81aL,0xf2f717d6ee2fcL,0xbbd05465475dcL,
  22926. 0x08e24d3c46860L } },
  22927. /* 171 */
  22928. { { 0xd8e549a587390L,0x4f0cbec588749L,0x25983c612bb19L,0xafc846e07da4bL,
  22929. 0x0541a99c4407bL },
  22930. { 0x41692624c8842L,0x2ad86c05ffdb2L,0xf7fcf626044c1L,0x35d1c59d14b44L,
  22931. 0x0c0092c49f57dL } },
  22932. /* 172 */
  22933. { { 0xc75c3df2e61efL,0xc82e1b35cad3cL,0x09f29f47e8841L,0x944dc62d30d19L,
  22934. 0x075e406347286L },
  22935. { 0x41fc5bbc237d0L,0xf0ec4f01c9e7dL,0x82bd534c9537bL,0x858691c51a162L,
  22936. 0x05b7cb658c784L } },
  22937. /* 173 */
  22938. { { 0xa70848a28ead1L,0x08fd3b47f6964L,0x67e5b39802dc5L,0x97a19ae4bfd17L,
  22939. 0x07ae13eba8df0L },
  22940. { 0x16ef8eadd384eL,0xd9b6b2ff06fd2L,0xbcdb5f30361a2L,0xe3fd204b98784L,
  22941. 0x0787d8074e2a8L } },
  22942. /* 174 */
  22943. { { 0x25d6b757fbb1cL,0xb2ca201debc5eL,0xd2233ffe47bddL,0x84844a55e9a36L,
  22944. 0x05c2228199ef2L },
  22945. { 0xd4a8588315250L,0x2b827097c1773L,0xef5d33f21b21aL,0xf2b0ab7c4ea1dL,
  22946. 0x0e45d37abbaf0L } },
  22947. /* 175 */
  22948. { { 0xf1e3428511c8aL,0xc8bdca6cd3d2dL,0x27c39a7ebb229L,0xb9d3578a71a76L,
  22949. 0x0ed7bc12284dfL },
  22950. { 0x2a6df93dea561L,0x8dd48f0ed1cf2L,0xbad23e85443f1L,0x6d27d8b861405L,
  22951. 0x0aac97cc945caL } },
  22952. /* 176 */
  22953. { { 0x4ea74a16bd00aL,0xadf5c0bcc1eb5L,0xf9bfc06d839e9L,0xdc4e092bb7f11L,
  22954. 0x0318f97b31163L },
  22955. { 0x0c5bec30d7138L,0x23abc30220eccL,0x022360644e8dfL,0xff4d2bb7972fbL,
  22956. 0x0fa41faa19a84L } },
  22957. /* 177 */
  22958. { { 0x2d974a6642269L,0xce9bb783bd440L,0x941e60bc81814L,0xe9e2398d38e47L,
  22959. 0x038bb6b2c1d26L },
  22960. { 0xe4a256a577f87L,0x53dc11fe1cc64L,0x22807288b52d2L,0x01a5ff336abf6L,
  22961. 0x094dd0905ce76L } },
  22962. /* 178 */
  22963. { { 0xcf7dcde93f92aL,0xcb89b5f315156L,0x995e750a01333L,0x2ae902404df9cL,
  22964. 0x092077867d25cL },
  22965. { 0x71e010bf39d44L,0x2096bb53d7e24L,0xc9c3d8f5f2c90L,0xeb514c44b7b35L,
  22966. 0x081e8428bd29bL } },
  22967. /* 179 */
  22968. { { 0x9c2bac477199fL,0xee6b5ecdd96ddL,0xe40fd0e8cb8eeL,0xa4b18af7db3feL,
  22969. 0x01b94ab62dbbfL },
  22970. { 0x0d8b3ce47f143L,0xfc63f4616344fL,0xc59938351e623L,0x90eef18f270fcL,
  22971. 0x006a38e280555L } },
  22972. /* 180 */
  22973. { { 0xb0139b3355b49L,0x60b4ebf99b2e5L,0x269f3dc20e265L,0xd4f8c08ffa6bdL,
  22974. 0x0a7b36c2083d9L },
  22975. { 0x15c3a1b3e8830L,0xe1a89f9c0b64dL,0x2d16930d5fceaL,0x2a20cfeee4a2eL,
  22976. 0x0be54c6b4a282L } },
  22977. /* 181 */
  22978. { { 0xdb3df8d91167cL,0x79e7a6625ed6cL,0x46ac7f4517c3fL,0x22bb7105648f3L,
  22979. 0x0bf30a5abeae0L },
  22980. { 0x785be93828a68L,0x327f3ef0368e7L,0x92146b25161c3L,0xd13ae11b5feb5L,
  22981. 0x0d1c820de2732L } },
  22982. /* 182 */
  22983. { { 0xe13479038b363L,0x546b05e519043L,0x026cad158c11fL,0x8da34fe57abe6L,
  22984. 0x0b7d17bed68a1L },
  22985. { 0xa5891e29c2559L,0x765bfffd8444cL,0x4e469484f7a03L,0xcc64498de4af7L,
  22986. 0x03997fd5e6412L } },
  22987. /* 183 */
  22988. { { 0x746828bd61507L,0xd534a64d2af20L,0xa8a15e329e132L,0x13e8ffeddfb08L,
  22989. 0x00eeb89293c6cL },
  22990. { 0x69a3ea7e259f8L,0xe6d13e7e67e9bL,0xd1fa685ce1db7L,0xb6ef277318f6aL,
  22991. 0x0228916f8c922L } },
  22992. /* 184 */
  22993. { { 0xae25b0a12ab5bL,0x1f957bc136959L,0x16e2b0ccc1117L,0x097e8058429edL,
  22994. 0x0ec05ad1d6e93L },
  22995. { 0xba5beac3f3708L,0x3530b59d77157L,0x18234e531baf9L,0x1b3747b552371L,
  22996. 0x07d3141567ff1L } },
  22997. /* 185 */
  22998. { { 0x9c05cf6dfefabL,0x68dcb377077bdL,0xa38bb95be2f22L,0xd7a3e53ead973L,
  22999. 0x0e9ce66fc9bc1L },
  23000. { 0xa15766f6a02a1L,0xdf60e600ed75aL,0x8cdc1b938c087L,0x0651f8947f346L,
  23001. 0x0d9650b017228L } },
  23002. /* 186 */
  23003. { { 0xb4c4a5a057e60L,0xbe8def25e4504L,0x7c1ccbdcbccc3L,0xb7a2a63532081L,
  23004. 0x014d6699a804eL },
  23005. { 0xa8415db1f411aL,0x0bf80d769c2c8L,0xc2f77ad09fbafL,0x598ab4deef901L,
  23006. 0x06f4c68410d43L } },
  23007. /* 187 */
  23008. { { 0x6df4e96c24a96L,0x85fcbd99a3872L,0xb2ae30a534dbcL,0x9abb3c466ef28L,
  23009. 0x04c4350fd6118L },
  23010. { 0x7f716f855b8daL,0x94463c38a1296L,0xae9334341a423L,0x18b5c37e1413eL,
  23011. 0x0a726d2425a31L } },
  23012. /* 188 */
  23013. { { 0x6b3ee948c1086L,0x3dcbd3a2e1daeL,0x3d022f3f1de50L,0xf3923f35ed3f0L,
  23014. 0x013639e82cc6cL },
  23015. { 0x938fbcdafaa86L,0xfb2654a2589acL,0x5051329f45bc5L,0x35a31963b26e4L,
  23016. 0x0ca9365e1c1a3L } },
  23017. /* 189 */
  23018. { { 0x5ac754c3b2d20L,0x17904e241b361L,0xc9d071d742a54L,0x72a5b08521c4cL,
  23019. 0x09ce29c34970bL },
  23020. { 0x81f736d3e0ad6L,0x9ef2f8434c8ccL,0xce862d98060daL,0xaf9835ed1d1a6L,
  23021. 0x048c4abd7ab42L } },
  23022. /* 190 */
  23023. { { 0x1b0cc40c7485aL,0xbbe5274dbfd22L,0x263d2e8ead455L,0x33cb493c76989L,
  23024. 0x078017c32f67bL },
  23025. { 0x35769930cb5eeL,0x940c408ed2b9dL,0x72f1a4dc0d14eL,0x1c04f8b7bf552L,
  23026. 0x053cd0454de5cL } },
  23027. /* 191 */
  23028. { { 0x585fa5d28ccacL,0x56005b746ebcdL,0xd0123aa5f823eL,0xfa8f7c79f0a1cL,
  23029. 0x0eea465c1d3d7L },
  23030. { 0x0659f0551803bL,0x9f7ce6af70781L,0x9288e706c0b59L,0x91934195a7702L,
  23031. 0x01b6e42a47ae6L } },
  23032. /* 192 */
  23033. { { 0x0937cf67d04c3L,0xe289eeb8112e8L,0x2594d601e312bL,0xbd3d56b5d8879L,
  23034. 0x00224da14187fL },
  23035. { 0xbb8630c5fe36fL,0x604ef51f5f87aL,0x3b429ec580f3cL,0xff33964fb1bfbL,
  23036. 0x060838ef042bfL } },
  23037. /* 193 */
  23038. { { 0xcb2f27e0bbe99L,0xf304aa39ee432L,0xfa939037bda44L,0x16435f497c7a9L,
  23039. 0x0636eb2022d33L },
  23040. { 0xd0e6193ae00aaL,0xfe31ae6d2ffcfL,0xf93901c875a00L,0x8bacf43658a29L,
  23041. 0x08844eeb63921L } },
  23042. /* 194 */
  23043. { { 0x171d26b3bae58L,0x7117e39f3e114L,0x1a8eada7db3dfL,0x789ecd37bc7f8L,
  23044. 0x027ba83dc51fbL },
  23045. { 0xf439ffbf54de5L,0x0bb5fe1a71a7dL,0xb297a48727703L,0xa4ab42ee8e35dL,
  23046. 0x0adb62d3487f3L } },
  23047. /* 195 */
  23048. { { 0x168a2a175df2aL,0x4f618c32e99b1L,0x46b0916082aa0L,0xc8b2c9e4f2e71L,
  23049. 0x0b990fd7675e7L },
  23050. { 0x9d96b4df37313L,0x79d0b40789082L,0x80877111c2055L,0xd18d66c9ae4a7L,
  23051. 0x081707ef94d10L } },
  23052. /* 196 */
  23053. { { 0x7cab203d6ff96L,0xfc0d84336097dL,0x042db4b5b851bL,0xaa5c268823c4dL,
  23054. 0x03792daead5a8L },
  23055. { 0x18865941afa0bL,0x4142d83671528L,0xbe4e0a7f3e9e7L,0x01ba17c825275L,
  23056. 0x05abd635e94b0L } },
  23057. /* 197 */
  23058. { { 0xfa84e0ac4927cL,0x35a7c8cf23727L,0xadca0dfe38860L,0xb610a4bcd5ea4L,
  23059. 0x05995bf21846aL },
  23060. { 0xf860b829dfa33L,0xae958fc18be90L,0x8630366caafe2L,0x411e9b3baf447L,
  23061. 0x044c32ca2d483L } },
  23062. /* 198 */
  23063. { { 0xa97f1e40ed80cL,0xb131d2ca82a74L,0xc2d6ad95f938cL,0xa54c53f2124b7L,
  23064. 0x01f2162fb8082L },
  23065. { 0x67cc5720b173eL,0x66085f12f97e4L,0xc9d65dc40e8a6L,0x07c98cebc20e4L,
  23066. 0x08f1d402bc3e9L } },
  23067. /* 199 */
  23068. { { 0x92f9cfbc4058aL,0xb6292f56704f5L,0xc1d8c57b15e14L,0xdbf9c55cfe37bL,
  23069. 0x0b1980f43926eL },
  23070. { 0x33e0932c76b09L,0x9d33b07f7898cL,0x63bb4611df527L,0x8e456f08ead48L,
  23071. 0x02828ad9b3744L } },
  23072. /* 200 */
  23073. { { 0x722c4c4cf4ac5L,0x3fdde64afb696L,0x0890832f5ac1aL,0xb3900551baa2eL,
  23074. 0x04973f1275a14L },
  23075. { 0xd8335322eac5dL,0xf50bd9b568e59L,0x25883935e07eeL,0x8ac7ab36720faL,
  23076. 0x06dac8ed0db16L } },
  23077. /* 201 */
  23078. { { 0x545aeeda835efL,0xd21d10ed51f7bL,0x3741b094aa113L,0xde4c035a65e01L,
  23079. 0x04b23ef5920b9L },
  23080. { 0xbb6803c4c7341L,0x6d3f58bc37e82L,0x51e3ee8d45770L,0x9a4e73527863aL,
  23081. 0x04dd71534ddf4L } },
  23082. /* 202 */
  23083. { { 0x4467295476cd9L,0x2fe31a725bbf9L,0xc4b67e0648d07L,0x4dbb1441c8b8fL,
  23084. 0x0fd3170002f4aL },
  23085. { 0x43ff48995d0e1L,0xd10ef729aa1cbL,0x179898276e695L,0xf365e0d5f9764L,
  23086. 0x014fac58c9569L } },
  23087. /* 203 */
  23088. { { 0xa0065f312ae18L,0xc0fcc93fc9ad9L,0xa7d284651958dL,0xda50d9a142408L,
  23089. 0x0ed7c765136abL },
  23090. { 0x70f1a25d4abbcL,0xf3f1a113ea462L,0xb51952f9b5dd8L,0x9f53c609b0755L,
  23091. 0x0fefcb7f74d2eL } },
  23092. /* 204 */
  23093. { { 0x9497aba119185L,0x30aac45ba4bd0L,0xa521179d54e8cL,0xd80b492479deaL,
  23094. 0x01801a57e87e0L },
  23095. { 0xd3f8dfcafffb0L,0x0bae255240073L,0xb5fdfbc6cf33cL,0x1064781d763b5L,
  23096. 0x09f8fc11e1eadL } },
  23097. /* 205 */
  23098. { { 0x3a1715e69544cL,0x67f04b7813158L,0x78a4c320eaf85L,0x69a91e22a8fd2L,
  23099. 0x0a9d3809d3d3aL },
  23100. { 0xc2c2c59a2da3bL,0xf61895c847936L,0x3d5086938ccbcL,0x8ef75e65244e6L,
  23101. 0x03006b9aee117L } },
  23102. /* 206 */
  23103. { { 0x1f2b0c9eead28L,0x5d89f4dfbc0bbL,0x2ce89397eef63L,0xf761074757fdbL,
  23104. 0x00ab85fd745f8L },
  23105. { 0xa7c933e5b4549L,0x5c97922f21ecdL,0x43b80404be2bbL,0x42c2261a1274bL,
  23106. 0x0b122d67511e9L } },
  23107. /* 207 */
  23108. { { 0x607be66a5ae7aL,0xfa76adcbe33beL,0xeb6e5c501e703L,0xbaecaf9043014L,
  23109. 0x09f599dc1097dL },
  23110. { 0x5b7180ff250edL,0x74349a20dc6d7L,0x0b227a38eb915L,0x4b78425605a41L,
  23111. 0x07d5528e08a29L } },
  23112. /* 208 */
  23113. { { 0x58f6620c26defL,0xea582b2d1ef0fL,0x1ce3881025585L,0x1730fbe7d79b0L,
  23114. 0x028ccea01303fL },
  23115. { 0xabcd179644ba5L,0xe806fff0b8d1dL,0x6b3e17b1fc643L,0x13bfa60a76fc6L,
  23116. 0x0c18baf48a1d0L } },
  23117. /* 209 */
  23118. { { 0x638c85dc4216dL,0x67206142ac34eL,0x5f5064a00c010L,0x596bd453a1719L,
  23119. 0x09def809db7a9L },
  23120. { 0x8642e67ab8d2cL,0x336237a2b641eL,0x4c4218bb42404L,0x8ce57d506a6d6L,
  23121. 0x00357f8b06880L } },
  23122. /* 210 */
  23123. { { 0xdbe644cd2cc88L,0x8df0b8f39d8e9L,0xd30a0c8cc61c2L,0x98874a309874cL,
  23124. 0x0e4a01add1b48L },
  23125. { 0x1eeacf57cd8f9L,0x3ebd594c482edL,0xbd2f7871b767dL,0xcc30a7295c717L,
  23126. 0x0466d7d79ce10L } },
  23127. /* 211 */
  23128. { { 0x318929dada2c7L,0xc38f9aa27d47dL,0x20a59e14fa0a6L,0xad1a90e4fd288L,
  23129. 0x0c672a522451eL },
  23130. { 0x07cc85d86b655L,0x3bf9ad4af1306L,0x71172a6f0235dL,0x751399a086805L,
  23131. 0x05e3d64faf2a6L } },
  23132. /* 212 */
  23133. { { 0x410c79b3b4416L,0x85eab26d99aa6L,0xb656a74cd8fcfL,0x42fc5ebff74adL,
  23134. 0x06c8a7a95eb8eL },
  23135. { 0x60ba7b02a63bdL,0x038b8f004710cL,0x12d90b06b2f23L,0xca918c6c37383L,
  23136. 0x0348ae422ad82L } },
  23137. /* 213 */
  23138. { { 0x746635ccda2fbL,0xa18e0726d27f4L,0x92b1f2022accaL,0x2d2e85adf7824L,
  23139. 0x0c1074de0d9efL },
  23140. { 0x3ce44ae9a65b3L,0xac05d7151bfcfL,0xe6a9788fd71e4L,0x4ffcd4711f50cL,
  23141. 0x0fbadfbdbc9e5L } },
  23142. /* 214 */
  23143. { { 0x3f1cd20a99363L,0x8f6cf22775171L,0x4d359b2b91565L,0x6fcd968175cd2L,
  23144. 0x0b7f976b48371L },
  23145. { 0x8e24d5d6dbf74L,0xfd71c3af36575L,0x243dfe38d23baL,0xc80548f477600L,
  23146. 0x0f4d41b2ecafcL } },
  23147. /* 215 */
  23148. { { 0x1cf28fdabd48dL,0x3632c078a451fL,0x17146e9ce81beL,0x0f106ace29741L,
  23149. 0x0180824eae016L },
  23150. { 0x7698b66e58358L,0x52ce6ca358038L,0xe41e6c5635687L,0x6d2582380e345L,
  23151. 0x067e5f63983cfL } },
  23152. /* 216 */
  23153. { { 0xccb8dcf4899efL,0xf09ebb44c0f89L,0x2598ec9949015L,0x1fc6546f9276bL,
  23154. 0x09fef789a04c1L },
  23155. { 0x67ecf53d2a071L,0x7fa4519b096d3L,0x11e2eefb10e1aL,0x4e20ca6b3fb06L,
  23156. 0x0bc80c181a99cL } },
  23157. /* 217 */
  23158. { { 0x536f8e5eb82e6L,0xc7f56cb920972L,0x0b5da5e1a484fL,0xdf10c78e21715L,
  23159. 0x049270e629f8cL },
  23160. { 0x9b7bbea6b50adL,0xc1a2388ffc1a3L,0x107197b9a0284L,0x2f7f5403eb178L,
  23161. 0x0d2ee52f96137L } },
  23162. /* 218 */
  23163. { { 0xcd28588e0362aL,0xa78fa5d94dd37L,0x434a526442fa8L,0xb733aff836e5aL,
  23164. 0x0dfb478bee5abL },
  23165. { 0xf1ce7673eede6L,0xd42b5b2f04a91L,0x530da2fa5390aL,0x473a5e66f7bf5L,
  23166. 0x0d9a140b408dfL } },
  23167. /* 219 */
  23168. { { 0x221b56e8ea498L,0x293563ee090e0L,0x35d2ade623478L,0x4b1ae06b83913L,
  23169. 0x0760c058d623fL },
  23170. { 0x9b58cc198aa79L,0xd2f07aba7f0b8L,0xde2556af74890L,0x04094e204110fL,
  23171. 0x07141982d8f19L } },
  23172. /* 220 */
  23173. { { 0xa0e334d4b0f45L,0x38392a94e16f0L,0x3c61d5ed9280bL,0x4e473af324c6bL,
  23174. 0x03af9d1ce89d5L },
  23175. { 0xf798120930371L,0x4c21c17097fd8L,0xc42309beda266L,0x7dd60e9545dcdL,
  23176. 0x0b1f815c37395L } },
  23177. /* 221 */
  23178. { { 0xaa78e89fec44aL,0x473caa4caf84fL,0x1b6a624c8c2aeL,0xf052691c807dcL,
  23179. 0x0a41aed141543L },
  23180. { 0x353997d5ffe04L,0xdf625b6e20424L,0x78177758bacb2L,0x60ef85d660be8L,
  23181. 0x0d6e9c1dd86fbL } },
  23182. /* 222 */
  23183. { { 0x2e97ec6853264L,0xb7e2304a0b3aaL,0x8eae9be771533L,0xf8c21b912bb7bL,
  23184. 0x09c9c6e10ae9bL },
  23185. { 0x09a59e030b74cL,0x4d6a631e90a23L,0x49b79f24ed749L,0x61b689f44b23aL,
  23186. 0x0566bd59640faL } },
  23187. /* 223 */
  23188. { { 0xc0118c18061f3L,0xd37c83fc70066L,0x7273245190b25L,0x345ef05fc8e02L,
  23189. 0x0cf2c7390f525L },
  23190. { 0xbceb410eb30cfL,0xba0d77703aa09L,0x50ff255cfd2ebL,0x0979e842c43a1L,
  23191. 0x002f517558aa2L } },
  23192. /* 224 */
  23193. { { 0xef794addb7d07L,0x4224455500396L,0x78aa3ce0b4fc7L,0xd97dfaff8eaccL,
  23194. 0x014e9ada5e8d4L },
  23195. { 0x480a12f7079e2L,0xcde4b0800edaaL,0x838157d45baa3L,0x9ae801765e2d7L,
  23196. 0x0a0ad4fab8e9dL } },
  23197. /* 225 */
  23198. { { 0xb76214a653618L,0x3c31eaaa5f0bfL,0x4949d5e187281L,0xed1e1553e7374L,
  23199. 0x0bcd530b86e56L },
  23200. { 0xbe85332e9c47bL,0xfeb50059ab169L,0x92bfbb4dc2776L,0x341dcdba97611L,
  23201. 0x0909283cf6979L } },
  23202. /* 226 */
  23203. { { 0x0032476e81a13L,0x996217123967bL,0x32e19d69bee1aL,0x549a08ed361bdL,
  23204. 0x035eeb7c9ace1L },
  23205. { 0x0ae5a7e4e5bdcL,0xd3b6ceec6e128L,0xe266bc12dcd2cL,0xe86452e4224c6L,
  23206. 0x09a8b2cf4448aL } },
  23207. /* 227 */
  23208. { { 0x71bf209d03b59L,0xa3b65af2abf64L,0xbd5eec9c90e62L,0x1379ff7ff168eL,
  23209. 0x06bdb60f4d449L },
  23210. { 0xafebc8a55bc30L,0x1610097fe0dadL,0xc1e3bddc79eadL,0x08a942e197414L,
  23211. 0x001ec3cfd94baL } },
  23212. /* 228 */
  23213. { { 0x277ebdc9485c2L,0x7922fb10c7ba6L,0x0a28d8a48cc9aL,0x64f64f61d60f7L,
  23214. 0x0d1acb1c04754L },
  23215. { 0x902b126f36612L,0x4ee0618d8bd26L,0x08357ee59c3a4L,0x26c24df8a8133L,
  23216. 0x07dcd079d4056L } },
  23217. /* 229 */
  23218. { { 0x7d4d3f05a4b48L,0x52372307725ceL,0x12a915aadcd29L,0x19b8d18f79718L,
  23219. 0x00bf53589377dL },
  23220. { 0xcd95a6c68ea73L,0xca823a584d35eL,0x473a723c7f3bbL,0x86fc9fb674c6fL,
  23221. 0x0d28be4d9e166L } },
  23222. /* 230 */
  23223. { { 0xb990638fa8e4bL,0x6e893fd8fc5d2L,0x36fb6fc559f18L,0x88ce3a6de2aa4L,
  23224. 0x0d76007aa510fL },
  23225. { 0x0aab6523a4988L,0x4474dd02732d1L,0x3407278b455cfL,0xbb017f467082aL,
  23226. 0x0f2b52f68b303L } },
  23227. /* 231 */
  23228. { { 0x7eafa9835b4caL,0xfcbb669cbc0d5L,0x66431982d2232L,0xed3a8eeeb680cL,
  23229. 0x0d8dbe98ecc5aL },
  23230. { 0x9be3fc5a02709L,0xe5f5ba1fa8cbaL,0x10ea85230be68L,0x9705febd43cdfL,
  23231. 0x0e01593a3ee55L } },
  23232. /* 232 */
  23233. { { 0x5af50ea75a0a6L,0xac57858033d3eL,0x0176406512226L,0xef066fe6d50fdL,
  23234. 0x0afec07b1aeb8L },
  23235. { 0x9956780bb0a31L,0xcc37309aae7fbL,0x1abf3896f1af3L,0xbfdd9153a15a0L,
  23236. 0x0a71b93546e2dL } },
  23237. /* 233 */
  23238. { { 0xe12e018f593d2L,0x28a078122bbf8L,0xba4f2add1a904L,0x23d9150505db0L,
  23239. 0x053a2005c6285L },
  23240. { 0x8b639e7f2b935L,0x5ac182961a07cL,0x518ca2c2bff97L,0x8e3d86bceea77L,
  23241. 0x0bf47d19b3d58L } },
  23242. /* 234 */
  23243. { { 0x967a7dd7665d5L,0x572f2f4de5672L,0x0d4903f4e3030L,0xa1b6144005ae8L,
  23244. 0x0001c2c7f39c9L },
  23245. { 0xa801469efc6d6L,0xaa7bc7a724143L,0x78150a4c810bdL,0xb99b5f65670baL,
  23246. 0x0fdadf8e786ffL } },
  23247. /* 235 */
  23248. { { 0x8cb88ffc00785L,0x913b48eb67fd3L,0xf368fbc77fa75L,0x3c940454d055bL,
  23249. 0x03a838e4d5aa4L },
  23250. { 0x663293e97bb9aL,0x63441d94d9561L,0xadb2a839eb933L,0x1da3515591a60L,
  23251. 0x03cdb8257873eL } },
  23252. /* 236 */
  23253. { { 0x140a97de77eabL,0x0d41648109137L,0xeb1d0dff7e1c5L,0x7fba762dcad2cL,
  23254. 0x05a60cc89f1f5L },
  23255. { 0x3638240d45673L,0x195913c65580bL,0xd64b7411b82beL,0x8fc0057284b8dL,
  23256. 0x0922ff56fdbfdL } },
  23257. /* 237 */
  23258. { { 0x65deec9a129a1L,0x57cc284e041b2L,0xebfbe3ca5b1ceL,0xcd6204380c46cL,
  23259. 0x072919a7df6c5L },
  23260. { 0xf453a8fb90f9aL,0x0b88e4031b298L,0x96f1856d719c0L,0x089ae32c0e777L,
  23261. 0x05e7917803624L } },
  23262. /* 238 */
  23263. { { 0x6ec557f63cdfbL,0x71f1cae4fd5c1L,0x60597ca8e6a35L,0x2fabfce26bea5L,
  23264. 0x04e0a5371e24cL },
  23265. { 0xa40d3a5765357L,0x440d73a2b4276L,0x1d11a323c89afL,0x04eeb8f370ae4L,
  23266. 0x0f5ff7818d566L } },
  23267. /* 239 */
  23268. { { 0x3e3fe1a09df21L,0x8ee66e8e47fbfL,0x9c8901526d5d2L,0x5e642096bd0a2L,
  23269. 0x0e41df0e9533fL },
  23270. { 0xfda40b3ba9e3fL,0xeb2604d895305L,0xf0367c7f2340cL,0x155f0866e1927L,
  23271. 0x08edd7d6eac4fL } },
  23272. /* 240 */
  23273. { { 0x1dc0e0bfc8ff3L,0x2be936f42fc9aL,0xca381ef14efd8L,0xee9667016f7ccL,
  23274. 0x01432c1caed8aL },
  23275. { 0x8482970b23c26L,0x730735b273ec6L,0xaef0f5aa64fe8L,0xd2c6e389f6e5eL,
  23276. 0x0caef480b5ac8L } },
  23277. /* 241 */
  23278. { { 0x5c97875315922L,0x713063cca5524L,0x64ef2cbd82951L,0xe236f3ce60d0bL,
  23279. 0x0d0ba177e8efaL },
  23280. { 0x9ae8fb1b3af60L,0xe53d2da20e53aL,0xf9eef281a796aL,0xae1601d63605dL,
  23281. 0x0f31c957c1c54L } },
  23282. /* 242 */
  23283. { { 0x58d5249cc4597L,0xb0bae0a028c0fL,0x34a814adc5015L,0x7c3aefc5fc557L,
  23284. 0x0013404cb96e1L },
  23285. { 0xe2585c9a824bfL,0x5e001eaed7b29L,0x1ef68acd59318L,0x3e6c8d6ee6826L,
  23286. 0x06f377c4b9193L } },
  23287. /* 243 */
  23288. { { 0x3bad1a8333fd2L,0x025a2a95b89f9L,0xaf75acea89302L,0x9506211e5037eL,
  23289. 0x06dba3e4ed2d0L },
  23290. { 0xef98cd04399cdL,0x6ee6b73adea48L,0x17ecaf31811c6L,0xf4a772f60752cL,
  23291. 0x0f13cf3423becL } },
  23292. /* 244 */
  23293. { { 0xb9ec0a919e2ebL,0x95f62c0f68ceeL,0xaba229983a9a1L,0xbad3cfba3bb67L,
  23294. 0x0c83fa9a9274bL },
  23295. { 0xd1b0b62fa1ce0L,0xf53418efbf0d7L,0x2706f04e58b60L,0x2683bfa8ef9e5L,
  23296. 0x0b49d70f45d70L } },
  23297. /* 245 */
  23298. { { 0xc7510fad5513bL,0xecb1751e2d914L,0x9fb9d5905f32eL,0xf1cf6d850418dL,
  23299. 0x059cfadbb0c30L },
  23300. { 0x7ac2355cb7fd6L,0xb8820426a3e16L,0x0a78864249367L,0x4b67eaeec58c9L,
  23301. 0x05babf362354aL } },
  23302. /* 246 */
  23303. { { 0x981d1ee424865L,0x78f2e5577f37cL,0x9e0c0588b0028L,0xc8f0702970f1bL,
  23304. 0x06188c6a79026L },
  23305. { 0x9a19bd0f244daL,0x5cfb08087306fL,0xf2136371eccedL,0xb9d935470f9b9L,
  23306. 0x0993fe475df50L } },
  23307. /* 247 */
  23308. { { 0x31cdf9b2c3609L,0xc02c46d4ea68eL,0xa77510184eb19L,0x616b7ac9ec1a9L,
  23309. 0x081f764664c80L },
  23310. { 0xc2a5a75fbe978L,0xd3f183b3561d7L,0x01dd2bf6743feL,0x060d838d1f045L,
  23311. 0x0564a812a5fe9L } },
  23312. /* 248 */
  23313. { { 0xa64f4fa817d1dL,0x44bea82e0f7a5L,0xd57f9aa55f968L,0x1d6cb5ff5a0fcL,
  23314. 0x0226bf3cf00e5L },
  23315. { 0x1a9f92f2833cfL,0x5a4f4f89a8d6dL,0xf3f7f7720a0a3L,0x783611536c498L,
  23316. 0x068779f47ff25L } },
  23317. /* 249 */
  23318. { { 0x0c1c173043d08L,0x741fc020fa79bL,0xa6d26d0a54467L,0x2e0bd3767e289L,
  23319. 0x097bcb0d1eb09L },
  23320. { 0x6eaa8f32ed3c3L,0x51b281bc482abL,0xfa178f3c8a4f1L,0x46554d1bf4f3bL,
  23321. 0x0a872ffe80a78L } },
  23322. /* 250 */
  23323. { { 0xb7935a32b2086L,0x0e8160f486b1aL,0xb6ae6bee1eb71L,0xa36a9bd0cd913L,
  23324. 0x002812bfcb732L },
  23325. { 0xfd7cacf605318L,0x50fdfd6d1da63L,0x102d619646e5dL,0x96afa1d683982L,
  23326. 0x007391cc9fe53L } },
  23327. /* 251 */
  23328. { { 0x157f08b80d02bL,0xd162877f7fc50L,0x8d542ae6b8333L,0x2a087aca1af87L,
  23329. 0x0355d2adc7e6dL },
  23330. { 0xf335a287386e1L,0x94f8e43275b41L,0x79989eafd272aL,0x3a79286ca2cdeL,
  23331. 0x03dc2b1e37c2aL } },
  23332. /* 252 */
  23333. { { 0x9d21c04581352L,0x25376782bed68L,0xfed701f0a00c8L,0x846b203bd5909L,
  23334. 0x0c47869103ccdL },
  23335. { 0xa770824c768edL,0x026841f6575dbL,0xaccce0e72feeaL,0x4d3273313ed56L,
  23336. 0x0ccc42968d5bbL } },
  23337. /* 253 */
  23338. { { 0x50de13d7620b9L,0x8a5992a56a94eL,0x75487c9d89a5cL,0x71cfdc0076406L,
  23339. 0x0e147eb42aa48L },
  23340. { 0xab4eeacf3ae46L,0xfb50350fbe274L,0x8c840eafd4936L,0x96e3df2afe474L,
  23341. 0x0239ac047080eL } },
  23342. /* 254 */
  23343. { { 0xd1f352bfee8d4L,0xcffa7b0fec481L,0xce9af3cce80b5L,0xe59d105c4c9e2L,
  23344. 0x0c55fa1a3f5f7L },
  23345. { 0x6f14e8257c227L,0x3f342be00b318L,0xa904fb2c5b165L,0xb69909afc998aL,
  23346. 0x0094cd99cd4f4L } },
  23347. /* 255 */
  23348. { { 0x81c84d703bebaL,0x5032ceb2918a9L,0x3bd49ec8631d1L,0xad33a445f2c9eL,
  23349. 0x0b90a30b642abL },
  23350. { 0x5404fb4a5abf9L,0xc375db7603b46L,0xa35d89f004750L,0x24f76f9a42cccL,
  23351. 0x0019f8b9a1b79L } },
  23352. };
  23353. /* Multiply the base point of P256 by the scalar and return the result.
  23354. * If map is true then convert result to affine coordinates.
  23355. *
  23356. * Stripe implementation.
  23357. * Pre-generated: 2^0, 2^32, ...
  23358. * Pre-generated: products of all combinations of above.
  23359. * 8 doubles and adds (with qz=1)
  23360. *
  23361. * r Resulting point.
  23362. * k Scalar to multiply by.
  23363. * map Indicates whether to convert result to affine.
  23364. * ct Constant time required.
  23365. * heap Heap to use for allocation.
  23366. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  23367. */
  23368. static int sp_256_ecc_mulmod_base_5(sp_point_256* r, const sp_digit* k,
  23369. int map, int ct, void* heap)
  23370. {
  23371. return sp_256_ecc_mulmod_stripe_5(r, &p256_base, p256_table,
  23372. k, map, ct, heap);
  23373. }
  23374. #endif
  23375. /* Multiply the base point of P256 by the scalar and return the result.
  23376. * If map is true then convert result to affine coordinates.
  23377. *
  23378. * km Scalar to multiply by.
  23379. * r Resulting point.
  23380. * map Indicates whether to convert result to affine.
  23381. * heap Heap to use for allocation.
  23382. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  23383. */
  23384. int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap)
  23385. {
  23386. #ifdef WOLFSSL_SP_SMALL_STACK
  23387. sp_point_256* point = NULL;
  23388. sp_digit* k = NULL;
  23389. #else
  23390. sp_point_256 point[1];
  23391. sp_digit k[5];
  23392. #endif
  23393. int err = MP_OKAY;
  23394. #ifdef WOLFSSL_SP_SMALL_STACK
  23395. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap,
  23396. DYNAMIC_TYPE_ECC);
  23397. if (point == NULL)
  23398. err = MEMORY_E;
  23399. if (err == MP_OKAY) {
  23400. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5, heap,
  23401. DYNAMIC_TYPE_ECC);
  23402. if (k == NULL)
  23403. err = MEMORY_E;
  23404. }
  23405. #endif
  23406. if (err == MP_OKAY) {
  23407. sp_256_from_mp(k, 5, km);
  23408. err = sp_256_ecc_mulmod_base_5(point, k, map, 1, heap);
  23409. }
  23410. if (err == MP_OKAY) {
  23411. err = sp_256_point_to_ecc_point_5(point, r);
  23412. }
  23413. #ifdef WOLFSSL_SP_SMALL_STACK
  23414. if (k != NULL)
  23415. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  23416. if (point != NULL)
  23417. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  23418. #endif
  23419. return err;
  23420. }
  23421. /* Multiply the base point of P256 by the scalar, add point a and return
  23422. * the result. If map is true then convert result to affine coordinates.
  23423. *
  23424. * km Scalar to multiply by.
  23425. * am Point to add to scalar multiply result.
  23426. * inMont Point to add is in montgomery form.
  23427. * r Resulting point.
  23428. * map Indicates whether to convert result to affine.
  23429. * heap Heap to use for allocation.
  23430. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  23431. */
  23432. int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am,
  23433. int inMont, ecc_point* r, int map, void* heap)
  23434. {
  23435. #ifdef WOLFSSL_SP_SMALL_STACK
  23436. sp_point_256* point = NULL;
  23437. sp_digit* k = NULL;
  23438. #else
  23439. sp_point_256 point[2];
  23440. sp_digit k[5 + 5 * 2 * 6];
  23441. #endif
  23442. sp_point_256* addP = NULL;
  23443. sp_digit* tmp = NULL;
  23444. int err = MP_OKAY;
  23445. #ifdef WOLFSSL_SP_SMALL_STACK
  23446. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap,
  23447. DYNAMIC_TYPE_ECC);
  23448. if (point == NULL)
  23449. err = MEMORY_E;
  23450. if (err == MP_OKAY) {
  23451. k = (sp_digit*)XMALLOC(
  23452. sizeof(sp_digit) * (5 + 5 * 2 * 6),
  23453. heap, DYNAMIC_TYPE_ECC);
  23454. if (k == NULL)
  23455. err = MEMORY_E;
  23456. }
  23457. #endif
  23458. if (err == MP_OKAY) {
  23459. addP = point + 1;
  23460. tmp = k + 5;
  23461. sp_256_from_mp(k, 5, km);
  23462. sp_256_point_from_ecc_point_5(addP, am);
  23463. }
  23464. if ((err == MP_OKAY) && (!inMont)) {
  23465. err = sp_256_mod_mul_norm_5(addP->x, addP->x, p256_mod);
  23466. }
  23467. if ((err == MP_OKAY) && (!inMont)) {
  23468. err = sp_256_mod_mul_norm_5(addP->y, addP->y, p256_mod);
  23469. }
  23470. if ((err == MP_OKAY) && (!inMont)) {
  23471. err = sp_256_mod_mul_norm_5(addP->z, addP->z, p256_mod);
  23472. }
  23473. if (err == MP_OKAY) {
  23474. err = sp_256_ecc_mulmod_base_5(point, k, 0, 0, heap);
  23475. }
  23476. if (err == MP_OKAY) {
  23477. sp_256_proj_point_add_5(point, point, addP, tmp);
  23478. if (map) {
  23479. sp_256_map_5(point, point, tmp);
  23480. }
  23481. err = sp_256_point_to_ecc_point_5(point, r);
  23482. }
  23483. #ifdef WOLFSSL_SP_SMALL_STACK
  23484. if (k != NULL)
  23485. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  23486. if (point)
  23487. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  23488. #endif
  23489. return err;
  23490. }
  23491. #if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
  23492. defined(HAVE_ECC_VERIFY)
  23493. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN | HAVE_ECC_SIGN | HAVE_ECC_VERIFY */
  23494. /* Add 1 to a. (a = a + 1)
  23495. *
  23496. * r A single precision integer.
  23497. * a A single precision integer.
  23498. */
  23499. SP_NOINLINE static void sp_256_add_one_5(sp_digit* a)
  23500. {
  23501. a[0]++;
  23502. sp_256_norm_5(a);
  23503. }
  23504. /* Read big endian unsigned byte array into r.
  23505. *
  23506. * r A single precision integer.
  23507. * size Maximum number of bytes to convert
  23508. * a Byte array.
  23509. * n Number of bytes in array to read.
  23510. */
  23511. static void sp_256_from_bin(sp_digit* r, int size, const byte* a, int n)
  23512. {
  23513. int i;
  23514. int j = 0;
  23515. word32 s = 0;
  23516. r[0] = 0;
  23517. for (i = n-1; i >= 0; i--) {
  23518. r[j] |= (((sp_digit)a[i]) << s);
  23519. if (s >= 44U) {
  23520. r[j] &= 0xfffffffffffffL;
  23521. s = 52U - s;
  23522. if (j + 1 >= size) {
  23523. break;
  23524. }
  23525. r[++j] = (sp_digit)a[i] >> s;
  23526. s = 8U - s;
  23527. }
  23528. else {
  23529. s += 8U;
  23530. }
  23531. }
  23532. for (j++; j < size; j++) {
  23533. r[j] = 0;
  23534. }
  23535. }
  23536. /* Generates a scalar that is in the range 1..order-1.
  23537. *
  23538. * rng Random number generator.
  23539. * k Scalar value.
  23540. * returns RNG failures, MEMORY_E when memory allocation fails and
  23541. * MP_OKAY on success.
  23542. */
  23543. static int sp_256_ecc_gen_k_5(WC_RNG* rng, sp_digit* k)
  23544. {
  23545. int err;
  23546. byte buf[32];
  23547. do {
  23548. err = wc_RNG_GenerateBlock(rng, buf, sizeof(buf));
  23549. if (err == 0) {
  23550. sp_256_from_bin(k, 5, buf, (int)sizeof(buf));
  23551. if (sp_256_cmp_5(k, p256_order2) <= 0) {
  23552. sp_256_add_one_5(k);
  23553. break;
  23554. }
  23555. }
  23556. }
  23557. while (err == 0);
  23558. return err;
  23559. }
  23560. /* Makes a random EC key pair.
  23561. *
  23562. * rng Random number generator.
  23563. * priv Generated private value.
  23564. * pub Generated public point.
  23565. * heap Heap to use for allocation.
  23566. * returns ECC_INF_E when the point does not have the correct order, RNG
  23567. * failures, MEMORY_E when memory allocation fails and MP_OKAY on success.
  23568. */
  23569. int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
  23570. {
  23571. #ifdef WOLFSSL_SP_SMALL_STACK
  23572. sp_point_256* point = NULL;
  23573. sp_digit* k = NULL;
  23574. #else
  23575. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23576. sp_point_256 point[2];
  23577. #else
  23578. sp_point_256 point[1];
  23579. #endif
  23580. sp_digit k[5];
  23581. #endif
  23582. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23583. sp_point_256* infinity = NULL;
  23584. #endif
  23585. int err = MP_OKAY;
  23586. (void)heap;
  23587. #ifdef WOLFSSL_SP_SMALL_STACK
  23588. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23589. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC);
  23590. #else
  23591. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC);
  23592. #endif
  23593. if (point == NULL)
  23594. err = MEMORY_E;
  23595. if (err == MP_OKAY) {
  23596. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5, heap,
  23597. DYNAMIC_TYPE_ECC);
  23598. if (k == NULL)
  23599. err = MEMORY_E;
  23600. }
  23601. #endif
  23602. if (err == MP_OKAY) {
  23603. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23604. infinity = point + 1;
  23605. #endif
  23606. err = sp_256_ecc_gen_k_5(rng, k);
  23607. }
  23608. if (err == MP_OKAY) {
  23609. err = sp_256_ecc_mulmod_base_5(point, k, 1, 1, NULL);
  23610. }
  23611. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23612. if (err == MP_OKAY) {
  23613. err = sp_256_ecc_mulmod_5(infinity, point, p256_order, 1, 1, NULL);
  23614. }
  23615. if (err == MP_OKAY) {
  23616. if (sp_256_iszero_5(point->x) || sp_256_iszero_5(point->y)) {
  23617. err = ECC_INF_E;
  23618. }
  23619. }
  23620. #endif
  23621. if (err == MP_OKAY) {
  23622. err = sp_256_to_mp(k, priv);
  23623. }
  23624. if (err == MP_OKAY) {
  23625. err = sp_256_point_to_ecc_point_5(point, pub);
  23626. }
  23627. #ifdef WOLFSSL_SP_SMALL_STACK
  23628. if (k != NULL)
  23629. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  23630. if (point != NULL) {
  23631. /* point is not sensitive, so no need to zeroize */
  23632. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  23633. }
  23634. #endif
  23635. return err;
  23636. }
  23637. #ifdef WOLFSSL_SP_NONBLOCK
  23638. typedef struct sp_ecc_key_gen_256_ctx {
  23639. int state;
  23640. sp_256_ecc_mulmod_5_ctx mulmod_ctx;
  23641. sp_digit k[5];
  23642. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23643. sp_point_256 point[2];
  23644. #else
  23645. sp_point_256 point[1];
  23646. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  23647. } sp_ecc_key_gen_256_ctx;
  23648. int sp_ecc_make_key_256_nb(sp_ecc_ctx_t* sp_ctx, WC_RNG* rng, mp_int* priv,
  23649. ecc_point* pub, void* heap)
  23650. {
  23651. int err = FP_WOULDBLOCK;
  23652. sp_ecc_key_gen_256_ctx* ctx = (sp_ecc_key_gen_256_ctx*)sp_ctx->data;
  23653. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23654. sp_point_256* infinity = ctx->point + 1;
  23655. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  23656. typedef char ctx_size_test[sizeof(sp_ecc_key_gen_256_ctx)
  23657. >= sizeof(*sp_ctx) ? -1 : 1];
  23658. (void)sizeof(ctx_size_test);
  23659. switch (ctx->state) {
  23660. case 0:
  23661. err = sp_256_ecc_gen_k_5(rng, ctx->k);
  23662. if (err == MP_OKAY) {
  23663. err = FP_WOULDBLOCK;
  23664. ctx->state = 1;
  23665. }
  23666. break;
  23667. case 1:
  23668. err = sp_256_ecc_mulmod_base_5_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  23669. ctx->point, ctx->k, 1, 1, heap);
  23670. if (err == MP_OKAY) {
  23671. err = FP_WOULDBLOCK;
  23672. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23673. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  23674. ctx->state = 2;
  23675. #else
  23676. ctx->state = 3;
  23677. #endif
  23678. }
  23679. break;
  23680. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  23681. case 2:
  23682. err = sp_256_ecc_mulmod_5_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  23683. infinity, ctx->point, p256_order, 1, 1);
  23684. if (err == MP_OKAY) {
  23685. if (sp_256_iszero_5(ctx->point->x) ||
  23686. sp_256_iszero_5(ctx->point->y)) {
  23687. err = ECC_INF_E;
  23688. }
  23689. else {
  23690. err = FP_WOULDBLOCK;
  23691. ctx->state = 3;
  23692. }
  23693. }
  23694. break;
  23695. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  23696. case 3:
  23697. err = sp_256_to_mp(ctx->k, priv);
  23698. if (err == MP_OKAY) {
  23699. err = sp_256_point_to_ecc_point_5(ctx->point, pub);
  23700. }
  23701. break;
  23702. }
  23703. if (err != FP_WOULDBLOCK) {
  23704. XMEMSET(ctx, 0, sizeof(sp_ecc_key_gen_256_ctx));
  23705. }
  23706. return err;
  23707. }
  23708. #endif /* WOLFSSL_SP_NONBLOCK */
  23709. #ifdef HAVE_ECC_DHE
  23710. /* Write r as big endian to byte array.
  23711. * Fixed length number of bytes written: 32
  23712. *
  23713. * r A single precision integer.
  23714. * a Byte array.
  23715. */
  23716. static void sp_256_to_bin_5(sp_digit* r, byte* a)
  23717. {
  23718. int i;
  23719. int j;
  23720. int s = 0;
  23721. int b;
  23722. for (i=0; i<4; i++) {
  23723. r[i+1] += r[i] >> 52;
  23724. r[i] &= 0xfffffffffffffL;
  23725. }
  23726. j = 263 / 8 - 1;
  23727. a[j] = 0;
  23728. for (i=0; i<5 && j>=0; i++) {
  23729. b = 0;
  23730. /* lint allow cast of mismatch sp_digit and int */
  23731. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  23732. b += 8 - s;
  23733. if (j < 0) {
  23734. break;
  23735. }
  23736. while (b < 52) {
  23737. a[j--] = (byte)(r[i] >> b);
  23738. b += 8;
  23739. if (j < 0) {
  23740. break;
  23741. }
  23742. }
  23743. s = 8 - (b - 52);
  23744. if (j >= 0) {
  23745. a[j] = 0;
  23746. }
  23747. if (s != 0) {
  23748. j++;
  23749. }
  23750. }
  23751. }
  23752. /* Multiply the point by the scalar and serialize the X ordinate.
  23753. * The number is 0 padded to maximum size on output.
  23754. *
  23755. * priv Scalar to multiply the point by.
  23756. * pub Point to multiply.
  23757. * out Buffer to hold X ordinate.
  23758. * outLen On entry, size of the buffer in bytes.
  23759. * On exit, length of data in buffer in bytes.
  23760. * heap Heap to use for allocation.
  23761. * returns BUFFER_E if the buffer is to small for output size,
  23762. * MEMORY_E when memory allocation fails and MP_OKAY on success.
  23763. */
  23764. int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out,
  23765. word32* outLen, void* heap)
  23766. {
  23767. #ifdef WOLFSSL_SP_SMALL_STACK
  23768. sp_point_256* point = NULL;
  23769. sp_digit* k = NULL;
  23770. #else
  23771. sp_point_256 point[1];
  23772. sp_digit k[5];
  23773. #endif
  23774. int err = MP_OKAY;
  23775. if (*outLen < 32U) {
  23776. err = BUFFER_E;
  23777. }
  23778. #ifdef WOLFSSL_SP_SMALL_STACK
  23779. if (err == MP_OKAY) {
  23780. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap,
  23781. DYNAMIC_TYPE_ECC);
  23782. if (point == NULL)
  23783. err = MEMORY_E;
  23784. }
  23785. if (err == MP_OKAY) {
  23786. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5, heap,
  23787. DYNAMIC_TYPE_ECC);
  23788. if (k == NULL)
  23789. err = MEMORY_E;
  23790. }
  23791. #endif
  23792. if (err == MP_OKAY) {
  23793. sp_256_from_mp(k, 5, priv);
  23794. sp_256_point_from_ecc_point_5(point, pub);
  23795. err = sp_256_ecc_mulmod_5(point, point, k, 1, 1, heap);
  23796. }
  23797. if (err == MP_OKAY) {
  23798. sp_256_to_bin_5(point->x, out);
  23799. *outLen = 32;
  23800. }
  23801. #ifdef WOLFSSL_SP_SMALL_STACK
  23802. if (k != NULL)
  23803. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  23804. if (point != NULL)
  23805. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  23806. #endif
  23807. return err;
  23808. }
  23809. #ifdef WOLFSSL_SP_NONBLOCK
  23810. typedef struct sp_ecc_sec_gen_256_ctx {
  23811. int state;
  23812. union {
  23813. sp_256_ecc_mulmod_5_ctx mulmod_ctx;
  23814. };
  23815. sp_digit k[5];
  23816. sp_point_256 point;
  23817. } sp_ecc_sec_gen_256_ctx;
  23818. int sp_ecc_secret_gen_256_nb(sp_ecc_ctx_t* sp_ctx, const mp_int* priv,
  23819. const ecc_point* pub, byte* out, word32* outLen, void* heap)
  23820. {
  23821. int err = FP_WOULDBLOCK;
  23822. sp_ecc_sec_gen_256_ctx* ctx = (sp_ecc_sec_gen_256_ctx*)sp_ctx->data;
  23823. typedef char ctx_size_test[sizeof(sp_ecc_sec_gen_256_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  23824. (void)sizeof(ctx_size_test);
  23825. if (*outLen < 32U) {
  23826. err = BUFFER_E;
  23827. }
  23828. switch (ctx->state) {
  23829. case 0:
  23830. sp_256_from_mp(ctx->k, 5, priv);
  23831. sp_256_point_from_ecc_point_5(&ctx->point, pub);
  23832. ctx->state = 1;
  23833. break;
  23834. case 1:
  23835. err = sp_256_ecc_mulmod_5_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  23836. &ctx->point, &ctx->point, ctx->k, 1, 1, heap);
  23837. if (err == MP_OKAY) {
  23838. sp_256_to_bin_5(ctx->point.x, out);
  23839. *outLen = 32;
  23840. }
  23841. break;
  23842. }
  23843. if (err == MP_OKAY && ctx->state != 1) {
  23844. err = FP_WOULDBLOCK;
  23845. }
  23846. if (err != FP_WOULDBLOCK) {
  23847. XMEMSET(ctx, 0, sizeof(sp_ecc_sec_gen_256_ctx));
  23848. }
  23849. return err;
  23850. }
  23851. #endif /* WOLFSSL_SP_NONBLOCK */
  23852. #endif /* HAVE_ECC_DHE */
  23853. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  23854. #endif
  23855. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  23856. SP_NOINLINE static void sp_256_rshift_5(sp_digit* r, const sp_digit* a,
  23857. byte n)
  23858. {
  23859. int i;
  23860. #ifdef WOLFSSL_SP_SMALL
  23861. for (i=0; i<4; i++) {
  23862. r[i] = ((a[i] >> n) | (a[i + 1] << (52 - n))) & 0xfffffffffffffL;
  23863. }
  23864. #else
  23865. for (i=0; i<0; i += 8) {
  23866. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (52 - n)) & 0xfffffffffffffL);
  23867. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (52 - n)) & 0xfffffffffffffL);
  23868. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (52 - n)) & 0xfffffffffffffL);
  23869. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (52 - n)) & 0xfffffffffffffL);
  23870. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (52 - n)) & 0xfffffffffffffL);
  23871. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (52 - n)) & 0xfffffffffffffL);
  23872. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (52 - n)) & 0xfffffffffffffL);
  23873. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (52 - n)) & 0xfffffffffffffL);
  23874. }
  23875. r[0] = (a[0] >> n) | ((a[1] << (52 - n)) & 0xfffffffffffffL);
  23876. r[1] = (a[1] >> n) | ((a[2] << (52 - n)) & 0xfffffffffffffL);
  23877. r[2] = (a[2] >> n) | ((a[3] << (52 - n)) & 0xfffffffffffffL);
  23878. r[3] = (a[3] >> n) | ((a[4] << (52 - n)) & 0xfffffffffffffL);
  23879. #endif /* WOLFSSL_SP_SMALL */
  23880. r[4] = a[4] >> n;
  23881. }
  23882. /* Multiply a by scalar b into r. (r = a * b)
  23883. *
  23884. * r A single precision integer.
  23885. * a A single precision integer.
  23886. * b A scalar.
  23887. */
  23888. SP_NOINLINE static void sp_256_mul_d_5(sp_digit* r, const sp_digit* a,
  23889. sp_digit b)
  23890. {
  23891. #ifdef WOLFSSL_SP_SMALL
  23892. sp_int128 tb = b;
  23893. sp_int128 t = 0;
  23894. int i;
  23895. for (i = 0; i < 5; i++) {
  23896. t += tb * a[i];
  23897. r[i] = (sp_digit)(t & 0xfffffffffffffL);
  23898. t >>= 52;
  23899. }
  23900. r[5] = (sp_digit)t;
  23901. #else
  23902. sp_int128 tb = b;
  23903. sp_int128 t[5];
  23904. t[ 0] = tb * a[ 0];
  23905. t[ 1] = tb * a[ 1];
  23906. t[ 2] = tb * a[ 2];
  23907. t[ 3] = tb * a[ 3];
  23908. t[ 4] = tb * a[ 4];
  23909. r[ 0] = (sp_digit) (t[ 0] & 0xfffffffffffffL);
  23910. r[ 1] = (sp_digit)((t[ 0] >> 52) + (t[ 1] & 0xfffffffffffffL));
  23911. r[ 2] = (sp_digit)((t[ 1] >> 52) + (t[ 2] & 0xfffffffffffffL));
  23912. r[ 3] = (sp_digit)((t[ 2] >> 52) + (t[ 3] & 0xfffffffffffffL));
  23913. r[ 4] = (sp_digit)((t[ 3] >> 52) + (t[ 4] & 0xfffffffffffffL));
  23914. r[ 5] = (sp_digit) (t[ 4] >> 52);
  23915. #endif /* WOLFSSL_SP_SMALL */
  23916. }
  23917. SP_NOINLINE static void sp_256_lshift_10(sp_digit* r, const sp_digit* a,
  23918. byte n)
  23919. {
  23920. #ifdef WOLFSSL_SP_SMALL
  23921. int i;
  23922. r[10] = a[9] >> (52 - n);
  23923. for (i=9; i>0; i--) {
  23924. r[i] = ((a[i] << n) | (a[i-1] >> (52 - n))) & 0xfffffffffffffL;
  23925. }
  23926. #else
  23927. sp_int_digit s;
  23928. sp_int_digit t;
  23929. s = (sp_int_digit)a[9];
  23930. r[10] = s >> (52U - n);
  23931. s = (sp_int_digit)(a[9]); t = (sp_int_digit)(a[8]);
  23932. r[9] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23933. s = (sp_int_digit)(a[8]); t = (sp_int_digit)(a[7]);
  23934. r[8] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23935. s = (sp_int_digit)(a[7]); t = (sp_int_digit)(a[6]);
  23936. r[7] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23937. s = (sp_int_digit)(a[6]); t = (sp_int_digit)(a[5]);
  23938. r[6] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23939. s = (sp_int_digit)(a[5]); t = (sp_int_digit)(a[4]);
  23940. r[5] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23941. s = (sp_int_digit)(a[4]); t = (sp_int_digit)(a[3]);
  23942. r[4] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23943. s = (sp_int_digit)(a[3]); t = (sp_int_digit)(a[2]);
  23944. r[3] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23945. s = (sp_int_digit)(a[2]); t = (sp_int_digit)(a[1]);
  23946. r[2] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23947. s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]);
  23948. r[1] = ((s << n) | (t >> (52U - n))) & 0xfffffffffffffUL;
  23949. #endif /* WOLFSSL_SP_SMALL */
  23950. r[0] = (a[0] << n) & 0xfffffffffffffL;
  23951. }
  23952. /* Divide d in a and put remainder into r (m*d + r = a)
  23953. * m is not calculated as it is not needed at this time.
  23954. *
  23955. * Simplified based on top word of divisor being very large.
  23956. *
  23957. * a Number to be divided.
  23958. * d Number to divide with.
  23959. * m Multiplier result.
  23960. * r Remainder from the division.
  23961. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  23962. */
  23963. static int sp_256_div_5(const sp_digit* a, const sp_digit* d,
  23964. const sp_digit* m, sp_digit* r)
  23965. {
  23966. int i;
  23967. sp_digit r1;
  23968. sp_digit mask;
  23969. #ifdef WOLFSSL_SP_SMALL_STACK
  23970. sp_digit* t1 = NULL;
  23971. #else
  23972. sp_digit t1[4 * 5 + 3];
  23973. #endif
  23974. sp_digit* t2 = NULL;
  23975. sp_digit* sd = NULL;
  23976. int err = MP_OKAY;
  23977. (void)m;
  23978. #ifdef WOLFSSL_SP_SMALL_STACK
  23979. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 5 + 3), NULL,
  23980. DYNAMIC_TYPE_TMP_BUFFER);
  23981. if (t1 == NULL)
  23982. err = MEMORY_E;
  23983. #endif
  23984. (void)m;
  23985. if (err == MP_OKAY) {
  23986. t2 = t1 + 10 + 1;
  23987. sd = t2 + 5 + 1;
  23988. sp_256_mul_d_5(sd, d, (sp_digit)1 << 4);
  23989. sp_256_lshift_10(t1, a, 4);
  23990. t1[5 + 5] += t1[5 + 5 - 1] >> 52;
  23991. t1[5 + 5 - 1] &= 0xfffffffffffffL;
  23992. for (i=4; i>=0; i--) {
  23993. r1 = t1[5 + i];
  23994. sp_256_mul_d_5(t2, sd, r1);
  23995. (void)sp_256_sub_5(&t1[i], &t1[i], t2);
  23996. t1[5 + i] -= t2[5];
  23997. sp_256_norm_5(&t1[i + 1]);
  23998. r1 = t1[5 + i];
  23999. sp_256_mul_d_5(t2, sd, r1);
  24000. (void)sp_256_sub_5(&t1[i], &t1[i], t2);
  24001. t1[5 + i] -= t2[5];
  24002. sp_256_norm_5(&t1[i + 1]);
  24003. mask = ~((t1[5 + i] - 1) >> 63);
  24004. sp_256_cond_sub_5(t1 + i, t1 + i, sd, mask);
  24005. sp_256_norm_5(&t1[i + 1]);
  24006. }
  24007. sp_256_norm_5(t1);
  24008. sp_256_rshift_5(r, t1, 4);
  24009. }
  24010. #ifdef WOLFSSL_SP_SMALL_STACK
  24011. if (t1 != NULL)
  24012. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  24013. #endif
  24014. return err;
  24015. }
  24016. /* Reduce a modulo m into r. (r = a mod m)
  24017. *
  24018. * r A single precision number that is the reduced result.
  24019. * a A single precision number that is to be reduced.
  24020. * m A single precision number that is the modulus to reduce with.
  24021. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  24022. */
  24023. static int sp_256_mod_5(sp_digit* r, const sp_digit* a, const sp_digit* m)
  24024. {
  24025. return sp_256_div_5(a, m, NULL, r);
  24026. }
  24027. #endif
  24028. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  24029. /* Multiply two number mod the order of P256 curve. (r = a * b mod order)
  24030. *
  24031. * r Result of the multiplication.
  24032. * a First operand of the multiplication.
  24033. * b Second operand of the multiplication.
  24034. */
  24035. static void sp_256_mont_mul_order_5(sp_digit* r, const sp_digit* a, const sp_digit* b)
  24036. {
  24037. sp_256_mul_5(r, a, b);
  24038. sp_256_mont_reduce_order_5(r, p256_order, p256_mp_order);
  24039. }
  24040. #if defined(HAVE_ECC_SIGN) || (defined(HAVE_ECC_VERIFY) && defined(WOLFSSL_SP_SMALL))
  24041. #ifdef WOLFSSL_SP_SMALL
  24042. /* Order-2 for the P256 curve. */
  24043. static const uint64_t p256_order_minus_2[4] = {
  24044. 0xf3b9cac2fc63254fU,0xbce6faada7179e84U,0xffffffffffffffffU,
  24045. 0xffffffff00000000U
  24046. };
  24047. #else
  24048. /* The low half of the order-2 of the P256 curve. */
  24049. static const sp_int_digit p256_order_low[2] = {
  24050. 0xf3b9cac2fc63254fU,0xbce6faada7179e84U
  24051. };
  24052. #endif /* WOLFSSL_SP_SMALL */
  24053. /* Square number mod the order of P256 curve. (r = a * a mod order)
  24054. *
  24055. * r Result of the squaring.
  24056. * a Number to square.
  24057. */
  24058. static void sp_256_mont_sqr_order_5(sp_digit* r, const sp_digit* a)
  24059. {
  24060. sp_256_sqr_5(r, a);
  24061. sp_256_mont_reduce_order_5(r, p256_order, p256_mp_order);
  24062. }
  24063. #ifndef WOLFSSL_SP_SMALL
  24064. /* Square number mod the order of P256 curve a number of times.
  24065. * (r = a ^ n mod order)
  24066. *
  24067. * r Result of the squaring.
  24068. * a Number to square.
  24069. */
  24070. static void sp_256_mont_sqr_n_order_5(sp_digit* r, const sp_digit* a, int n)
  24071. {
  24072. int i;
  24073. sp_256_mont_sqr_order_5(r, a);
  24074. for (i=1; i<n; i++) {
  24075. sp_256_mont_sqr_order_5(r, r);
  24076. }
  24077. }
  24078. #endif /* !WOLFSSL_SP_SMALL */
  24079. /* Invert the number, in Montgomery form, modulo the order of the P256 curve.
  24080. * (r = 1 / a mod order)
  24081. *
  24082. * r Inverse result.
  24083. * a Number to invert.
  24084. * td Temporary data.
  24085. */
  24086. #ifdef WOLFSSL_SP_NONBLOCK
  24087. typedef struct sp_256_mont_inv_order_5_ctx {
  24088. int state;
  24089. int i;
  24090. } sp_256_mont_inv_order_5_ctx;
  24091. static int sp_256_mont_inv_order_5_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const sp_digit* a,
  24092. sp_digit* t)
  24093. {
  24094. int err = FP_WOULDBLOCK;
  24095. sp_256_mont_inv_order_5_ctx* ctx = (sp_256_mont_inv_order_5_ctx*)sp_ctx;
  24096. typedef char ctx_size_test[sizeof(sp_256_mont_inv_order_5_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  24097. (void)sizeof(ctx_size_test);
  24098. switch (ctx->state) {
  24099. case 0:
  24100. XMEMCPY(t, a, sizeof(sp_digit) * 5);
  24101. ctx->i = 254;
  24102. ctx->state = 1;
  24103. break;
  24104. case 1:
  24105. sp_256_mont_sqr_order_5(t, t);
  24106. ctx->state = 2;
  24107. break;
  24108. case 2:
  24109. if ((p256_order_minus_2[ctx->i / 64] & ((sp_int_digit)1 << (ctx->i % 64))) != 0) {
  24110. sp_256_mont_mul_order_5(t, t, a);
  24111. }
  24112. ctx->i--;
  24113. ctx->state = (ctx->i == 0) ? 3 : 1;
  24114. break;
  24115. case 3:
  24116. XMEMCPY(r, t, sizeof(sp_digit) * 5U);
  24117. err = MP_OKAY;
  24118. break;
  24119. }
  24120. return err;
  24121. }
  24122. #endif /* WOLFSSL_SP_NONBLOCK */
  24123. static void sp_256_mont_inv_order_5(sp_digit* r, const sp_digit* a,
  24124. sp_digit* td)
  24125. {
  24126. #ifdef WOLFSSL_SP_SMALL
  24127. sp_digit* t = td;
  24128. int i;
  24129. XMEMCPY(t, a, sizeof(sp_digit) * 5);
  24130. for (i=254; i>=0; i--) {
  24131. sp_256_mont_sqr_order_5(t, t);
  24132. if ((p256_order_minus_2[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  24133. sp_256_mont_mul_order_5(t, t, a);
  24134. }
  24135. }
  24136. XMEMCPY(r, t, sizeof(sp_digit) * 5U);
  24137. #else
  24138. sp_digit* t = td;
  24139. sp_digit* t2 = td + 2 * 5;
  24140. sp_digit* t3 = td + 4 * 5;
  24141. int i;
  24142. /* t = a^2 */
  24143. sp_256_mont_sqr_order_5(t, a);
  24144. /* t = a^3 = t * a */
  24145. sp_256_mont_mul_order_5(t, t, a);
  24146. /* t2= a^c = t ^ 2 ^ 2 */
  24147. sp_256_mont_sqr_n_order_5(t2, t, 2);
  24148. /* t3= a^f = t2 * t */
  24149. sp_256_mont_mul_order_5(t3, t2, t);
  24150. /* t2= a^f0 = t3 ^ 2 ^ 4 */
  24151. sp_256_mont_sqr_n_order_5(t2, t3, 4);
  24152. /* t = a^ff = t2 * t3 */
  24153. sp_256_mont_mul_order_5(t, t2, t3);
  24154. /* t2= a^ff00 = t ^ 2 ^ 8 */
  24155. sp_256_mont_sqr_n_order_5(t2, t, 8);
  24156. /* t = a^ffff = t2 * t */
  24157. sp_256_mont_mul_order_5(t, t2, t);
  24158. /* t2= a^ffff0000 = t ^ 2 ^ 16 */
  24159. sp_256_mont_sqr_n_order_5(t2, t, 16);
  24160. /* t = a^ffffffff = t2 * t */
  24161. sp_256_mont_mul_order_5(t, t2, t);
  24162. /* t2= a^ffffffff0000000000000000 = t ^ 2 ^ 64 */
  24163. sp_256_mont_sqr_n_order_5(t2, t, 64);
  24164. /* t2= a^ffffffff00000000ffffffff = t2 * t */
  24165. sp_256_mont_mul_order_5(t2, t2, t);
  24166. /* t2= a^ffffffff00000000ffffffff00000000 = t2 ^ 2 ^ 32 */
  24167. sp_256_mont_sqr_n_order_5(t2, t2, 32);
  24168. /* t2= a^ffffffff00000000ffffffffffffffff = t2 * t */
  24169. sp_256_mont_mul_order_5(t2, t2, t);
  24170. /* t2= a^ffffffff00000000ffffffffffffffffbce6 */
  24171. sp_256_mont_sqr_order_5(t2, t2);
  24172. sp_256_mont_mul_order_5(t2, t2, a);
  24173. sp_256_mont_sqr_n_order_5(t2, t2, 5);
  24174. sp_256_mont_mul_order_5(t2, t2, t3);
  24175. for (i=121; i>=112; i--) {
  24176. sp_256_mont_sqr_order_5(t2, t2);
  24177. if ((p256_order_low[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  24178. sp_256_mont_mul_order_5(t2, t2, a);
  24179. }
  24180. }
  24181. /* t2= a^ffffffff00000000ffffffffffffffffbce6f */
  24182. sp_256_mont_sqr_n_order_5(t2, t2, 4);
  24183. sp_256_mont_mul_order_5(t2, t2, t3);
  24184. /* t2= a^ffffffff00000000ffffffffffffffffbce6faada7179e84 */
  24185. for (i=107; i>=64; i--) {
  24186. sp_256_mont_sqr_order_5(t2, t2);
  24187. if ((p256_order_low[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  24188. sp_256_mont_mul_order_5(t2, t2, a);
  24189. }
  24190. }
  24191. /* t2= a^ffffffff00000000ffffffffffffffffbce6faada7179e84f */
  24192. sp_256_mont_sqr_n_order_5(t2, t2, 4);
  24193. sp_256_mont_mul_order_5(t2, t2, t3);
  24194. /* t2= a^ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2 */
  24195. for (i=59; i>=32; i--) {
  24196. sp_256_mont_sqr_order_5(t2, t2);
  24197. if ((p256_order_low[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  24198. sp_256_mont_mul_order_5(t2, t2, a);
  24199. }
  24200. }
  24201. /* t2= a^ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2f */
  24202. sp_256_mont_sqr_n_order_5(t2, t2, 4);
  24203. sp_256_mont_mul_order_5(t2, t2, t3);
  24204. /* t2= a^ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63254 */
  24205. for (i=27; i>=0; i--) {
  24206. sp_256_mont_sqr_order_5(t2, t2);
  24207. if ((p256_order_low[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  24208. sp_256_mont_mul_order_5(t2, t2, a);
  24209. }
  24210. }
  24211. /* t2= a^ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632540 */
  24212. sp_256_mont_sqr_n_order_5(t2, t2, 4);
  24213. /* r = a^ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63254f */
  24214. sp_256_mont_mul_order_5(r, t2, t3);
  24215. #endif /* WOLFSSL_SP_SMALL */
  24216. }
  24217. #endif /* HAVE_ECC_SIGN || (HAVE_ECC_VERIFY && WOLFSSL_SP_SMALL) */
  24218. #endif /* HAVE_ECC_SIGN | HAVE_ECC_VERIFY */
  24219. #ifdef HAVE_ECC_SIGN
  24220. #ifndef SP_ECC_MAX_SIG_GEN
  24221. #define SP_ECC_MAX_SIG_GEN 64
  24222. #endif
  24223. /* Calculate second signature value S from R, k and private value.
  24224. *
  24225. * s = (r * x + e) / k
  24226. *
  24227. * s Signature value.
  24228. * r First signature value.
  24229. * k Ephemeral private key.
  24230. * x Private key as a number.
  24231. * e Hash of message as a number.
  24232. * tmp Temporary storage for intermediate numbers.
  24233. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  24234. */
  24235. static int sp_256_calc_s_5(sp_digit* s, const sp_digit* r, sp_digit* k,
  24236. sp_digit* x, const sp_digit* e, sp_digit* tmp)
  24237. {
  24238. int err;
  24239. sp_digit carry;
  24240. sp_int64 c;
  24241. sp_digit* kInv = k;
  24242. /* Conv k to Montgomery form (mod order) */
  24243. sp_256_mul_5(k, k, p256_norm_order);
  24244. err = sp_256_mod_5(k, k, p256_order);
  24245. if (err == MP_OKAY) {
  24246. sp_256_norm_5(k);
  24247. /* kInv = 1/k mod order */
  24248. sp_256_mont_inv_order_5(kInv, k, tmp);
  24249. sp_256_norm_5(kInv);
  24250. /* s = r * x + e */
  24251. sp_256_mul_5(x, x, r);
  24252. err = sp_256_mod_5(x, x, p256_order);
  24253. }
  24254. if (err == MP_OKAY) {
  24255. sp_256_norm_5(x);
  24256. carry = sp_256_add_5(s, e, x);
  24257. sp_256_cond_sub_5(s, s, p256_order, 0 - carry);
  24258. sp_256_norm_5(s);
  24259. c = sp_256_cmp_5(s, p256_order);
  24260. sp_256_cond_sub_5(s, s, p256_order,
  24261. (sp_digit)0 - (sp_digit)(c >= 0));
  24262. sp_256_norm_5(s);
  24263. /* s = s * k^-1 mod order */
  24264. sp_256_mont_mul_order_5(s, s, kInv);
  24265. sp_256_norm_5(s);
  24266. }
  24267. return err;
  24268. }
  24269. /* Sign the hash using the private key.
  24270. * e = [hash, 256 bits] from binary
  24271. * r = (k.G)->x mod order
  24272. * s = (r * x + e) / k mod order
  24273. * The hash is truncated to the first 256 bits.
  24274. *
  24275. * hash Hash to sign.
  24276. * hashLen Length of the hash data.
  24277. * rng Random number generator.
  24278. * priv Private part of key - scalar.
  24279. * rm First part of result as an mp_int.
  24280. * sm Sirst part of result as an mp_int.
  24281. * heap Heap to use for allocation.
  24282. * returns RNG failures, MEMORY_E when memory allocation fails and
  24283. * MP_OKAY on success.
  24284. */
  24285. int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng,
  24286. const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap)
  24287. {
  24288. #ifdef WOLFSSL_SP_SMALL_STACK
  24289. sp_digit* e = NULL;
  24290. sp_point_256* point = NULL;
  24291. #else
  24292. sp_digit e[7 * 2 * 5];
  24293. sp_point_256 point[1];
  24294. #endif
  24295. sp_digit* x = NULL;
  24296. sp_digit* k = NULL;
  24297. sp_digit* r = NULL;
  24298. sp_digit* tmp = NULL;
  24299. sp_digit* s = NULL;
  24300. sp_int64 c;
  24301. int err = MP_OKAY;
  24302. int i;
  24303. (void)heap;
  24304. #ifdef WOLFSSL_SP_SMALL_STACK
  24305. if (err == MP_OKAY) {
  24306. point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap,
  24307. DYNAMIC_TYPE_ECC);
  24308. if (point == NULL)
  24309. err = MEMORY_E;
  24310. }
  24311. if (err == MP_OKAY) {
  24312. e = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7 * 2 * 5, heap,
  24313. DYNAMIC_TYPE_ECC);
  24314. if (e == NULL)
  24315. err = MEMORY_E;
  24316. }
  24317. #endif
  24318. if (err == MP_OKAY) {
  24319. x = e + 2 * 5;
  24320. k = e + 4 * 5;
  24321. r = e + 6 * 5;
  24322. tmp = e + 8 * 5;
  24323. s = e;
  24324. if (hashLen > 32U) {
  24325. hashLen = 32U;
  24326. }
  24327. }
  24328. for (i = SP_ECC_MAX_SIG_GEN; err == MP_OKAY && i > 0; i--) {
  24329. /* New random point. */
  24330. if (km == NULL || mp_iszero(km)) {
  24331. err = sp_256_ecc_gen_k_5(rng, k);
  24332. }
  24333. else {
  24334. sp_256_from_mp(k, 5, km);
  24335. mp_zero(km);
  24336. }
  24337. if (err == MP_OKAY) {
  24338. err = sp_256_ecc_mulmod_base_5(point, k, 1, 1, heap);
  24339. }
  24340. if (err == MP_OKAY) {
  24341. /* r = point->x mod order */
  24342. XMEMCPY(r, point->x, sizeof(sp_digit) * 5U);
  24343. sp_256_norm_5(r);
  24344. c = sp_256_cmp_5(r, p256_order);
  24345. sp_256_cond_sub_5(r, r, p256_order,
  24346. (sp_digit)0 - (sp_digit)(c >= 0));
  24347. sp_256_norm_5(r);
  24348. if (!sp_256_iszero_5(r)) {
  24349. /* x is modified in calculation of s. */
  24350. sp_256_from_mp(x, 5, priv);
  24351. /* s ptr == e ptr, e is modified in calculation of s. */
  24352. sp_256_from_bin(e, 5, hash, (int)hashLen);
  24353. err = sp_256_calc_s_5(s, r, k, x, e, tmp);
  24354. /* Check that signature is usable. */
  24355. if ((err == MP_OKAY) && (!sp_256_iszero_5(s))) {
  24356. break;
  24357. }
  24358. }
  24359. }
  24360. #ifdef WOLFSSL_ECDSA_SET_K_ONE_LOOP
  24361. i = 1;
  24362. #endif
  24363. }
  24364. if (i == 0) {
  24365. err = RNG_FAILURE_E;
  24366. }
  24367. if (err == MP_OKAY) {
  24368. err = sp_256_to_mp(r, rm);
  24369. }
  24370. if (err == MP_OKAY) {
  24371. err = sp_256_to_mp(s, sm);
  24372. }
  24373. #ifdef WOLFSSL_SP_SMALL_STACK
  24374. if (e != NULL)
  24375. #endif
  24376. {
  24377. ForceZero(e, sizeof(sp_digit) * 7 * 2 * 5);
  24378. #ifdef WOLFSSL_SP_SMALL_STACK
  24379. XFREE(e, heap, DYNAMIC_TYPE_ECC);
  24380. #endif
  24381. }
  24382. #ifdef WOLFSSL_SP_SMALL_STACK
  24383. if (point != NULL)
  24384. #endif
  24385. {
  24386. ForceZero(point, sizeof(sp_point_256));
  24387. #ifdef WOLFSSL_SP_SMALL_STACK
  24388. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  24389. #endif
  24390. }
  24391. return err;
  24392. }
  24393. #ifdef WOLFSSL_SP_NONBLOCK
  24394. typedef struct sp_ecc_sign_256_ctx {
  24395. int state;
  24396. union {
  24397. sp_256_ecc_mulmod_5_ctx mulmod_ctx;
  24398. sp_256_mont_inv_order_5_ctx mont_inv_order_ctx;
  24399. };
  24400. sp_digit e[2*5];
  24401. sp_digit x[2*5];
  24402. sp_digit k[2*5];
  24403. sp_digit r[2*5];
  24404. sp_digit tmp[3 * 2*5];
  24405. sp_point_256 point;
  24406. sp_digit* s;
  24407. sp_digit* kInv;
  24408. int i;
  24409. } sp_ecc_sign_256_ctx;
  24410. int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, WC_RNG* rng,
  24411. mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap)
  24412. {
  24413. int err = FP_WOULDBLOCK;
  24414. sp_ecc_sign_256_ctx* ctx = (sp_ecc_sign_256_ctx*)sp_ctx->data;
  24415. typedef char ctx_size_test[sizeof(sp_ecc_sign_256_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  24416. (void)sizeof(ctx_size_test);
  24417. switch (ctx->state) {
  24418. case 0: /* INIT */
  24419. ctx->s = ctx->e;
  24420. ctx->kInv = ctx->k;
  24421. ctx->i = SP_ECC_MAX_SIG_GEN;
  24422. ctx->state = 1;
  24423. break;
  24424. case 1: /* GEN */
  24425. /* New random point. */
  24426. if (km == NULL || mp_iszero(km)) {
  24427. err = sp_256_ecc_gen_k_5(rng, ctx->k);
  24428. }
  24429. else {
  24430. sp_256_from_mp(ctx->k, 5, km);
  24431. mp_zero(km);
  24432. }
  24433. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  24434. ctx->state = 2;
  24435. break;
  24436. case 2: /* MULMOD */
  24437. err = sp_256_ecc_mulmod_5_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  24438. &ctx->point, &p256_base, ctx->k, 1, 1, heap);
  24439. if (err == MP_OKAY) {
  24440. ctx->state = 3;
  24441. }
  24442. break;
  24443. case 3: /* MODORDER */
  24444. {
  24445. sp_int64 c;
  24446. /* r = point->x mod order */
  24447. XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 5U);
  24448. sp_256_norm_5(ctx->r);
  24449. c = sp_256_cmp_5(ctx->r, p256_order);
  24450. sp_256_cond_sub_5(ctx->r, ctx->r, p256_order,
  24451. (sp_digit)0 - (sp_digit)(c >= 0));
  24452. sp_256_norm_5(ctx->r);
  24453. if (hashLen > 32U) {
  24454. hashLen = 32U;
  24455. }
  24456. sp_256_from_mp(ctx->x, 5, priv);
  24457. sp_256_from_bin(ctx->e, 5, hash, (int)hashLen);
  24458. ctx->state = 4;
  24459. break;
  24460. }
  24461. case 4: /* KMODORDER */
  24462. /* Conv k to Montgomery form (mod order) */
  24463. sp_256_mul_5(ctx->k, ctx->k, p256_norm_order);
  24464. err = sp_256_mod_5(ctx->k, ctx->k, p256_order);
  24465. if (err == MP_OKAY) {
  24466. sp_256_norm_5(ctx->k);
  24467. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  24468. ctx->state = 5;
  24469. }
  24470. break;
  24471. case 5: /* KINV */
  24472. /* kInv = 1/k mod order */
  24473. err = sp_256_mont_inv_order_5_nb((sp_ecc_ctx_t*)&ctx->mont_inv_order_ctx, ctx->kInv, ctx->k, ctx->tmp);
  24474. if (err == MP_OKAY) {
  24475. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  24476. ctx->state = 6;
  24477. }
  24478. break;
  24479. case 6: /* KINVNORM */
  24480. sp_256_norm_5(ctx->kInv);
  24481. ctx->state = 7;
  24482. break;
  24483. case 7: /* R */
  24484. /* s = r * x + e */
  24485. sp_256_mul_5(ctx->x, ctx->x, ctx->r);
  24486. ctx->state = 8;
  24487. break;
  24488. case 8: /* S1 */
  24489. err = sp_256_mod_5(ctx->x, ctx->x, p256_order);
  24490. if (err == MP_OKAY)
  24491. ctx->state = 9;
  24492. break;
  24493. case 9: /* S2 */
  24494. {
  24495. sp_digit carry;
  24496. sp_int64 c;
  24497. sp_256_norm_5(ctx->x);
  24498. carry = sp_256_add_5(ctx->s, ctx->e, ctx->x);
  24499. sp_256_cond_sub_5(ctx->s, ctx->s,
  24500. p256_order, 0 - carry);
  24501. sp_256_norm_5(ctx->s);
  24502. c = sp_256_cmp_5(ctx->s, p256_order);
  24503. sp_256_cond_sub_5(ctx->s, ctx->s, p256_order,
  24504. (sp_digit)0 - (sp_digit)(c >= 0));
  24505. sp_256_norm_5(ctx->s);
  24506. /* s = s * k^-1 mod order */
  24507. sp_256_mont_mul_order_5(ctx->s, ctx->s, ctx->kInv);
  24508. sp_256_norm_5(ctx->s);
  24509. /* Check that signature is usable. */
  24510. if (sp_256_iszero_5(ctx->s) == 0) {
  24511. ctx->state = 10;
  24512. break;
  24513. }
  24514. #ifdef WOLFSSL_ECDSA_SET_K_ONE_LOOP
  24515. ctx->i = 1;
  24516. #endif
  24517. /* not usable gen, try again */
  24518. ctx->i--;
  24519. if (ctx->i == 0) {
  24520. err = RNG_FAILURE_E;
  24521. }
  24522. ctx->state = 1;
  24523. break;
  24524. }
  24525. case 10: /* RES */
  24526. err = sp_256_to_mp(ctx->r, rm);
  24527. if (err == MP_OKAY) {
  24528. err = sp_256_to_mp(ctx->s, sm);
  24529. }
  24530. break;
  24531. }
  24532. if (err == MP_OKAY && ctx->state != 10) {
  24533. err = FP_WOULDBLOCK;
  24534. }
  24535. if (err != FP_WOULDBLOCK) {
  24536. XMEMSET(ctx->e, 0, sizeof(sp_digit) * 2U * 5U);
  24537. XMEMSET(ctx->x, 0, sizeof(sp_digit) * 2U * 5U);
  24538. XMEMSET(ctx->k, 0, sizeof(sp_digit) * 2U * 5U);
  24539. XMEMSET(ctx->r, 0, sizeof(sp_digit) * 2U * 5U);
  24540. XMEMSET(ctx->tmp, 0, sizeof(sp_digit) * 3U * 2U * 5U);
  24541. }
  24542. return err;
  24543. }
  24544. #endif /* WOLFSSL_SP_NONBLOCK */
  24545. #endif /* HAVE_ECC_SIGN */
  24546. #ifndef WOLFSSL_SP_SMALL
  24547. static const char sp_256_tab64_5[64] = {
  24548. 64, 1, 59, 2, 60, 48, 54, 3,
  24549. 61, 40, 49, 28, 55, 34, 43, 4,
  24550. 62, 52, 38, 41, 50, 19, 29, 21,
  24551. 56, 31, 35, 12, 44, 15, 23, 5,
  24552. 63, 58, 47, 53, 39, 27, 33, 42,
  24553. 51, 37, 18, 20, 30, 11, 14, 22,
  24554. 57, 46, 26, 32, 36, 17, 10, 13,
  24555. 45, 25, 16, 9, 24, 8, 7, 6};
  24556. static int sp_256_num_bits_52_5(sp_digit v)
  24557. {
  24558. v |= v >> 1;
  24559. v |= v >> 2;
  24560. v |= v >> 4;
  24561. v |= v >> 8;
  24562. v |= v >> 16;
  24563. v |= v >> 32;
  24564. return sp_256_tab64_5[((uint64_t)((v - (v >> 1))*0x07EDD5E59A4E28C2)) >> 58];
  24565. }
  24566. static int sp_256_num_bits_5(const sp_digit* a)
  24567. {
  24568. int i;
  24569. int r = 0;
  24570. for (i = 4; i >= 0; i--) {
  24571. if (a[i] != 0) {
  24572. r = sp_256_num_bits_52_5(a[i]);
  24573. r += i * 52;
  24574. break;
  24575. }
  24576. }
  24577. return r;
  24578. }
  24579. /* Non-constant time modular inversion.
  24580. *
  24581. * @param [out] r Resulting number.
  24582. * @param [in] a Number to invert.
  24583. * @param [in] m Modulus.
  24584. * @return MP_OKAY on success.
  24585. * @return MEMEORY_E when dynamic memory allocation fails.
  24586. */
  24587. static int sp_256_mod_inv_5(sp_digit* r, const sp_digit* a, const sp_digit* m)
  24588. {
  24589. int err = MP_OKAY;
  24590. #ifdef WOLFSSL_SP_SMALL_STACK
  24591. sp_digit* u = NULL;
  24592. #else
  24593. sp_digit u[5 * 4];
  24594. #endif
  24595. sp_digit* v = NULL;
  24596. sp_digit* b = NULL;
  24597. sp_digit* d = NULL;
  24598. int ut;
  24599. int vt;
  24600. #ifdef WOLFSSL_SP_SMALL_STACK
  24601. u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 4, NULL,
  24602. DYNAMIC_TYPE_ECC);
  24603. if (u == NULL)
  24604. err = MEMORY_E;
  24605. #endif
  24606. if (err == MP_OKAY) {
  24607. v = u + 5;
  24608. b = u + 2 * 5;
  24609. d = u + 3 * 5;
  24610. XMEMCPY(u, m, sizeof(sp_digit) * 5);
  24611. XMEMCPY(v, a, sizeof(sp_digit) * 5);
  24612. ut = sp_256_num_bits_5(u);
  24613. vt = sp_256_num_bits_5(v);
  24614. XMEMSET(b, 0, sizeof(sp_digit) * 5);
  24615. if ((v[0] & 1) == 0) {
  24616. sp_256_rshift1_5(v, v);
  24617. XMEMCPY(d, m, sizeof(sp_digit) * 5);
  24618. d[0]++;
  24619. sp_256_rshift1_5(d, d);
  24620. vt--;
  24621. while ((v[0] & 1) == 0) {
  24622. sp_256_rshift1_5(v, v);
  24623. if (d[0] & 1)
  24624. sp_256_add_5(d, d, m);
  24625. sp_256_rshift1_5(d, d);
  24626. vt--;
  24627. }
  24628. }
  24629. else {
  24630. XMEMSET(d+1, 0, sizeof(sp_digit) * (5 - 1));
  24631. d[0] = 1;
  24632. }
  24633. while (ut > 1 && vt > 1) {
  24634. if ((ut > vt) || ((ut == vt) &&
  24635. (sp_256_cmp_5(u, v) >= 0))) {
  24636. sp_256_sub_5(u, u, v);
  24637. sp_256_norm_5(u);
  24638. sp_256_sub_5(b, b, d);
  24639. sp_256_norm_5(b);
  24640. if (b[4] < 0)
  24641. sp_256_add_5(b, b, m);
  24642. sp_256_norm_5(b);
  24643. ut = sp_256_num_bits_5(u);
  24644. do {
  24645. sp_256_rshift1_5(u, u);
  24646. if (b[0] & 1)
  24647. sp_256_add_5(b, b, m);
  24648. sp_256_rshift1_5(b, b);
  24649. ut--;
  24650. }
  24651. while (ut > 0 && (u[0] & 1) == 0);
  24652. }
  24653. else {
  24654. sp_256_sub_5(v, v, u);
  24655. sp_256_norm_5(v);
  24656. sp_256_sub_5(d, d, b);
  24657. sp_256_norm_5(d);
  24658. if (d[4] < 0)
  24659. sp_256_add_5(d, d, m);
  24660. sp_256_norm_5(d);
  24661. vt = sp_256_num_bits_5(v);
  24662. do {
  24663. sp_256_rshift1_5(v, v);
  24664. if (d[0] & 1)
  24665. sp_256_add_5(d, d, m);
  24666. sp_256_rshift1_5(d, d);
  24667. vt--;
  24668. }
  24669. while (vt > 0 && (v[0] & 1) == 0);
  24670. }
  24671. }
  24672. if (ut == 1)
  24673. XMEMCPY(r, b, sizeof(sp_digit) * 5);
  24674. else
  24675. XMEMCPY(r, d, sizeof(sp_digit) * 5);
  24676. }
  24677. #ifdef WOLFSSL_SP_SMALL_STACK
  24678. if (u != NULL)
  24679. XFREE(u, NULL, DYNAMIC_TYPE_ECC);
  24680. #endif
  24681. return err;
  24682. }
  24683. #endif /* WOLFSSL_SP_SMALL */
  24684. /* Add point p1 into point p2. Handles p1 == p2 and result at infinity.
  24685. *
  24686. * p1 First point to add and holds result.
  24687. * p2 Second point to add.
  24688. * tmp Temporary storage for intermediate numbers.
  24689. */
  24690. static void sp_256_add_points_5(sp_point_256* p1, const sp_point_256* p2,
  24691. sp_digit* tmp)
  24692. {
  24693. sp_256_proj_point_add_5(p1, p1, p2, tmp);
  24694. if (sp_256_iszero_5(p1->z)) {
  24695. if (sp_256_iszero_5(p1->x) && sp_256_iszero_5(p1->y)) {
  24696. sp_256_proj_point_dbl_5(p1, p2, tmp);
  24697. }
  24698. else {
  24699. /* Y ordinate is not used from here - don't set. */
  24700. p1->x[0] = 0;
  24701. p1->x[1] = 0;
  24702. p1->x[2] = 0;
  24703. p1->x[3] = 0;
  24704. p1->x[4] = 0;
  24705. XMEMCPY(p1->z, p256_norm_mod, sizeof(p256_norm_mod));
  24706. }
  24707. }
  24708. }
  24709. /* Calculate the verification point: [e/s]G + [r/s]Q
  24710. *
  24711. * p1 Calculated point.
  24712. * p2 Public point and temporary.
  24713. * s Second part of signature as a number.
  24714. * u1 Temporary number.
  24715. * u2 Temporary number.
  24716. * heap Heap to use for allocation.
  24717. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  24718. */
  24719. static int sp_256_calc_vfy_point_5(sp_point_256* p1, sp_point_256* p2,
  24720. sp_digit* s, sp_digit* u1, sp_digit* u2, sp_digit* tmp, void* heap)
  24721. {
  24722. int err;
  24723. #ifndef WOLFSSL_SP_SMALL
  24724. err = sp_256_mod_inv_5(s, s, p256_order);
  24725. if (err == MP_OKAY)
  24726. #endif /* !WOLFSSL_SP_SMALL */
  24727. {
  24728. sp_256_mul_5(s, s, p256_norm_order);
  24729. err = sp_256_mod_5(s, s, p256_order);
  24730. }
  24731. if (err == MP_OKAY) {
  24732. sp_256_norm_5(s);
  24733. #ifdef WOLFSSL_SP_SMALL
  24734. {
  24735. sp_256_mont_inv_order_5(s, s, tmp);
  24736. sp_256_mont_mul_order_5(u1, u1, s);
  24737. sp_256_mont_mul_order_5(u2, u2, s);
  24738. }
  24739. #else
  24740. {
  24741. sp_256_mont_mul_order_5(u1, u1, s);
  24742. sp_256_mont_mul_order_5(u2, u2, s);
  24743. }
  24744. #endif /* WOLFSSL_SP_SMALL */
  24745. {
  24746. err = sp_256_ecc_mulmod_base_5(p1, u1, 0, 0, heap);
  24747. }
  24748. }
  24749. if ((err == MP_OKAY) && sp_256_iszero_5(p1->z)) {
  24750. p1->infinity = 1;
  24751. }
  24752. if (err == MP_OKAY) {
  24753. err = sp_256_ecc_mulmod_5(p2, p2, u2, 0, 0, heap);
  24754. }
  24755. if ((err == MP_OKAY) && sp_256_iszero_5(p2->z)) {
  24756. p2->infinity = 1;
  24757. }
  24758. if (err == MP_OKAY) {
  24759. sp_256_add_points_5(p1, p2, tmp);
  24760. }
  24761. return err;
  24762. }
  24763. #ifdef HAVE_ECC_VERIFY
  24764. /* Verify the signature values with the hash and public key.
  24765. * e = Truncate(hash, 256)
  24766. * u1 = e/s mod order
  24767. * u2 = r/s mod order
  24768. * r == (u1.G + u2.Q)->x mod order
  24769. * Optimization: Leave point in projective form.
  24770. * (x, y, 1) == (x' / z'*z', y' / z'*z'*z', z' / z')
  24771. * (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x'
  24772. * The hash is truncated to the first 256 bits.
  24773. *
  24774. * hash Hash to sign.
  24775. * hashLen Length of the hash data.
  24776. * rng Random number generator.
  24777. * priv Private part of key - scalar.
  24778. * rm First part of result as an mp_int.
  24779. * sm Sirst part of result as an mp_int.
  24780. * heap Heap to use for allocation.
  24781. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  24782. */
  24783. int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX,
  24784. const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm,
  24785. int* res, void* heap)
  24786. {
  24787. #ifdef WOLFSSL_SP_SMALL_STACK
  24788. sp_digit* u1 = NULL;
  24789. sp_point_256* p1 = NULL;
  24790. #else
  24791. sp_digit u1[18 * 5];
  24792. sp_point_256 p1[2];
  24793. #endif
  24794. sp_digit* u2 = NULL;
  24795. sp_digit* s = NULL;
  24796. sp_digit* tmp = NULL;
  24797. sp_point_256* p2 = NULL;
  24798. sp_digit carry;
  24799. sp_int64 c = 0;
  24800. int err = MP_OKAY;
  24801. #ifdef WOLFSSL_SP_SMALL_STACK
  24802. if (err == MP_OKAY) {
  24803. p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap,
  24804. DYNAMIC_TYPE_ECC);
  24805. if (p1 == NULL)
  24806. err = MEMORY_E;
  24807. }
  24808. if (err == MP_OKAY) {
  24809. u1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 5, heap,
  24810. DYNAMIC_TYPE_ECC);
  24811. if (u1 == NULL)
  24812. err = MEMORY_E;
  24813. }
  24814. #endif
  24815. if (err == MP_OKAY) {
  24816. u2 = u1 + 2 * 5;
  24817. s = u1 + 4 * 5;
  24818. tmp = u1 + 6 * 5;
  24819. p2 = p1 + 1;
  24820. if (hashLen > 32U) {
  24821. hashLen = 32U;
  24822. }
  24823. sp_256_from_bin(u1, 5, hash, (int)hashLen);
  24824. sp_256_from_mp(u2, 5, rm);
  24825. sp_256_from_mp(s, 5, sm);
  24826. sp_256_from_mp(p2->x, 5, pX);
  24827. sp_256_from_mp(p2->y, 5, pY);
  24828. sp_256_from_mp(p2->z, 5, pZ);
  24829. err = sp_256_calc_vfy_point_5(p1, p2, s, u1, u2, tmp, heap);
  24830. }
  24831. if (err == MP_OKAY) {
  24832. /* (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x' */
  24833. /* Reload r and convert to Montgomery form. */
  24834. sp_256_from_mp(u2, 5, rm);
  24835. err = sp_256_mod_mul_norm_5(u2, u2, p256_mod);
  24836. }
  24837. if (err == MP_OKAY) {
  24838. /* u1 = r.z'.z' mod prime */
  24839. sp_256_mont_sqr_5(p1->z, p1->z, p256_mod, p256_mp_mod);
  24840. sp_256_mont_mul_5(u1, u2, p1->z, p256_mod, p256_mp_mod);
  24841. *res = (int)(sp_256_cmp_5(p1->x, u1) == 0);
  24842. if (*res == 0) {
  24843. /* Reload r and add order. */
  24844. sp_256_from_mp(u2, 5, rm);
  24845. carry = sp_256_add_5(u2, u2, p256_order);
  24846. /* Carry means result is greater than mod and is not valid. */
  24847. if (carry == 0) {
  24848. sp_256_norm_5(u2);
  24849. /* Compare with mod and if greater or equal then not valid. */
  24850. c = sp_256_cmp_5(u2, p256_mod);
  24851. }
  24852. }
  24853. if ((*res == 0) && (c < 0)) {
  24854. /* Convert to Montogomery form */
  24855. err = sp_256_mod_mul_norm_5(u2, u2, p256_mod);
  24856. if (err == MP_OKAY) {
  24857. /* u1 = (r + 1*order).z'.z' mod prime */
  24858. {
  24859. sp_256_mont_mul_5(u1, u2, p1->z, p256_mod, p256_mp_mod);
  24860. }
  24861. *res = (sp_256_cmp_5(p1->x, u1) == 0);
  24862. }
  24863. }
  24864. }
  24865. #ifdef WOLFSSL_SP_SMALL_STACK
  24866. if (u1 != NULL)
  24867. XFREE(u1, heap, DYNAMIC_TYPE_ECC);
  24868. if (p1 != NULL)
  24869. XFREE(p1, heap, DYNAMIC_TYPE_ECC);
  24870. #endif
  24871. return err;
  24872. }
  24873. #ifdef WOLFSSL_SP_NONBLOCK
  24874. typedef struct sp_ecc_verify_256_ctx {
  24875. int state;
  24876. union {
  24877. sp_256_ecc_mulmod_5_ctx mulmod_ctx;
  24878. sp_256_mont_inv_order_5_ctx mont_inv_order_ctx;
  24879. sp_256_proj_point_dbl_5_ctx dbl_ctx;
  24880. sp_256_proj_point_add_5_ctx add_ctx;
  24881. };
  24882. sp_digit u1[2*5];
  24883. sp_digit u2[2*5];
  24884. sp_digit s[2*5];
  24885. sp_digit tmp[2*5 * 6];
  24886. sp_point_256 p1;
  24887. sp_point_256 p2;
  24888. } sp_ecc_verify_256_ctx;
  24889. int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash,
  24890. word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ,
  24891. const mp_int* rm, const mp_int* sm, int* res, void* heap)
  24892. {
  24893. int err = FP_WOULDBLOCK;
  24894. sp_ecc_verify_256_ctx* ctx = (sp_ecc_verify_256_ctx*)sp_ctx->data;
  24895. typedef char ctx_size_test[sizeof(sp_ecc_verify_256_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  24896. (void)sizeof(ctx_size_test);
  24897. switch (ctx->state) {
  24898. case 0: /* INIT */
  24899. if (hashLen > 32U) {
  24900. hashLen = 32U;
  24901. }
  24902. sp_256_from_bin(ctx->u1, 5, hash, (int)hashLen);
  24903. sp_256_from_mp(ctx->u2, 5, rm);
  24904. sp_256_from_mp(ctx->s, 5, sm);
  24905. sp_256_from_mp(ctx->p2.x, 5, pX);
  24906. sp_256_from_mp(ctx->p2.y, 5, pY);
  24907. sp_256_from_mp(ctx->p2.z, 5, pZ);
  24908. ctx->state = 1;
  24909. break;
  24910. case 1: /* NORMS0 */
  24911. sp_256_mul_5(ctx->s, ctx->s, p256_norm_order);
  24912. err = sp_256_mod_5(ctx->s, ctx->s, p256_order);
  24913. if (err == MP_OKAY)
  24914. ctx->state = 2;
  24915. break;
  24916. case 2: /* NORMS1 */
  24917. sp_256_norm_5(ctx->s);
  24918. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  24919. ctx->state = 3;
  24920. break;
  24921. case 3: /* NORMS2 */
  24922. err = sp_256_mont_inv_order_5_nb((sp_ecc_ctx_t*)&ctx->mont_inv_order_ctx, ctx->s, ctx->s, ctx->tmp);
  24923. if (err == MP_OKAY) {
  24924. ctx->state = 4;
  24925. }
  24926. break;
  24927. case 4: /* NORMS3 */
  24928. sp_256_mont_mul_order_5(ctx->u1, ctx->u1, ctx->s);
  24929. ctx->state = 5;
  24930. break;
  24931. case 5: /* NORMS4 */
  24932. sp_256_mont_mul_order_5(ctx->u2, ctx->u2, ctx->s);
  24933. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  24934. ctx->state = 6;
  24935. break;
  24936. case 6: /* MULBASE */
  24937. err = sp_256_ecc_mulmod_5_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx, &ctx->p1, &p256_base, ctx->u1, 0, 0, heap);
  24938. if (err == MP_OKAY) {
  24939. if (sp_256_iszero_5(ctx->p1.z)) {
  24940. ctx->p1.infinity = 1;
  24941. }
  24942. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  24943. ctx->state = 7;
  24944. }
  24945. break;
  24946. case 7: /* MULMOD */
  24947. err = sp_256_ecc_mulmod_5_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx, &ctx->p2, &ctx->p2, ctx->u2, 0, 0, heap);
  24948. if (err == MP_OKAY) {
  24949. if (sp_256_iszero_5(ctx->p2.z)) {
  24950. ctx->p2.infinity = 1;
  24951. }
  24952. XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx));
  24953. ctx->state = 8;
  24954. }
  24955. break;
  24956. case 8: /* ADD */
  24957. err = sp_256_proj_point_add_5_nb((sp_ecc_ctx_t*)&ctx->add_ctx, &ctx->p1, &ctx->p1, &ctx->p2, ctx->tmp);
  24958. if (err == MP_OKAY)
  24959. ctx->state = 9;
  24960. break;
  24961. case 9: /* MONT */
  24962. /* (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x' */
  24963. /* Reload r and convert to Montgomery form. */
  24964. sp_256_from_mp(ctx->u2, 5, rm);
  24965. err = sp_256_mod_mul_norm_5(ctx->u2, ctx->u2, p256_mod);
  24966. if (err == MP_OKAY)
  24967. ctx->state = 10;
  24968. break;
  24969. case 10: /* SQR */
  24970. /* u1 = r.z'.z' mod prime */
  24971. sp_256_mont_sqr_5(ctx->p1.z, ctx->p1.z, p256_mod, p256_mp_mod);
  24972. ctx->state = 11;
  24973. break;
  24974. case 11: /* MUL */
  24975. sp_256_mont_mul_5(ctx->u1, ctx->u2, ctx->p1.z, p256_mod, p256_mp_mod);
  24976. ctx->state = 12;
  24977. break;
  24978. case 12: /* RES */
  24979. {
  24980. sp_int64 c = 0;
  24981. err = MP_OKAY; /* math okay, now check result */
  24982. *res = (int)(sp_256_cmp_5(ctx->p1.x, ctx->u1) == 0);
  24983. if (*res == 0) {
  24984. sp_digit carry;
  24985. /* Reload r and add order. */
  24986. sp_256_from_mp(ctx->u2, 5, rm);
  24987. carry = sp_256_add_5(ctx->u2, ctx->u2, p256_order);
  24988. /* Carry means result is greater than mod and is not valid. */
  24989. if (carry == 0) {
  24990. sp_256_norm_5(ctx->u2);
  24991. /* Compare with mod and if greater or equal then not valid. */
  24992. c = sp_256_cmp_5(ctx->u2, p256_mod);
  24993. }
  24994. }
  24995. if ((*res == 0) && (c < 0)) {
  24996. /* Convert to Montogomery form */
  24997. err = sp_256_mod_mul_norm_5(ctx->u2, ctx->u2, p256_mod);
  24998. if (err == MP_OKAY) {
  24999. /* u1 = (r + 1*order).z'.z' mod prime */
  25000. sp_256_mont_mul_5(ctx->u1, ctx->u2, ctx->p1.z, p256_mod,
  25001. p256_mp_mod);
  25002. *res = (int)(sp_256_cmp_5(ctx->p1.x, ctx->u1) == 0);
  25003. }
  25004. }
  25005. break;
  25006. }
  25007. } /* switch */
  25008. if (err == MP_OKAY && ctx->state != 12) {
  25009. err = FP_WOULDBLOCK;
  25010. }
  25011. return err;
  25012. }
  25013. #endif /* WOLFSSL_SP_NONBLOCK */
  25014. #endif /* HAVE_ECC_VERIFY */
  25015. #ifdef HAVE_ECC_CHECK_KEY
  25016. /* Check that the x and y oridinates are a valid point on the curve.
  25017. *
  25018. * point EC point.
  25019. * heap Heap to use if dynamically allocating.
  25020. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  25021. * not on the curve and MP_OKAY otherwise.
  25022. */
  25023. static int sp_256_ecc_is_point_5(const sp_point_256* point,
  25024. void* heap)
  25025. {
  25026. #ifdef WOLFSSL_SP_SMALL_STACK
  25027. sp_digit* t1 = NULL;
  25028. #else
  25029. sp_digit t1[5 * 4];
  25030. #endif
  25031. sp_digit* t2 = NULL;
  25032. int err = MP_OKAY;
  25033. #ifdef WOLFSSL_SP_SMALL_STACK
  25034. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 4, heap, DYNAMIC_TYPE_ECC);
  25035. if (t1 == NULL)
  25036. err = MEMORY_E;
  25037. #endif
  25038. (void)heap;
  25039. if (err == MP_OKAY) {
  25040. t2 = t1 + 2 * 5;
  25041. /* y^2 - x^3 - a.x = b */
  25042. sp_256_sqr_5(t1, point->y);
  25043. (void)sp_256_mod_5(t1, t1, p256_mod);
  25044. sp_256_sqr_5(t2, point->x);
  25045. (void)sp_256_mod_5(t2, t2, p256_mod);
  25046. sp_256_mul_5(t2, t2, point->x);
  25047. (void)sp_256_mod_5(t2, t2, p256_mod);
  25048. sp_256_mont_sub_5(t1, t1, t2, p256_mod);
  25049. /* y^2 - x^3 + 3.x = b, when a = -3 */
  25050. sp_256_mont_add_5(t1, t1, point->x, p256_mod);
  25051. sp_256_mont_add_5(t1, t1, point->x, p256_mod);
  25052. sp_256_mont_add_5(t1, t1, point->x, p256_mod);
  25053. if (sp_256_cmp_5(t1, p256_b) != 0) {
  25054. err = MP_VAL;
  25055. }
  25056. }
  25057. #ifdef WOLFSSL_SP_SMALL_STACK
  25058. if (t1 != NULL)
  25059. XFREE(t1, heap, DYNAMIC_TYPE_ECC);
  25060. #endif
  25061. return err;
  25062. }
  25063. /* Check that the x and y oridinates are a valid point on the curve.
  25064. *
  25065. * pX X ordinate of EC point.
  25066. * pY Y ordinate of EC point.
  25067. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  25068. * not on the curve and MP_OKAY otherwise.
  25069. */
  25070. int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY)
  25071. {
  25072. #ifdef WOLFSSL_SP_SMALL_STACK
  25073. sp_point_256* pub = NULL;
  25074. #else
  25075. sp_point_256 pub[1];
  25076. #endif
  25077. const byte one[1] = { 1 };
  25078. int err = MP_OKAY;
  25079. #ifdef WOLFSSL_SP_SMALL_STACK
  25080. pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL,
  25081. DYNAMIC_TYPE_ECC);
  25082. if (pub == NULL)
  25083. err = MEMORY_E;
  25084. #endif
  25085. if (err == MP_OKAY) {
  25086. sp_256_from_mp(pub->x, 5, pX);
  25087. sp_256_from_mp(pub->y, 5, pY);
  25088. sp_256_from_bin(pub->z, 5, one, (int)sizeof(one));
  25089. err = sp_256_ecc_is_point_5(pub, NULL);
  25090. }
  25091. #ifdef WOLFSSL_SP_SMALL_STACK
  25092. if (pub != NULL)
  25093. XFREE(pub, NULL, DYNAMIC_TYPE_ECC);
  25094. #endif
  25095. return err;
  25096. }
  25097. /* Check that the private scalar generates the EC point (px, py), the point is
  25098. * on the curve and the point has the correct order.
  25099. *
  25100. * pX X ordinate of EC point.
  25101. * pY Y ordinate of EC point.
  25102. * privm Private scalar that generates EC point.
  25103. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  25104. * not on the curve, ECC_INF_E if the point does not have the correct order,
  25105. * ECC_PRIV_KEY_E when the private scalar doesn't generate the EC point and
  25106. * MP_OKAY otherwise.
  25107. */
  25108. int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY,
  25109. const mp_int* privm, void* heap)
  25110. {
  25111. #ifdef WOLFSSL_SP_SMALL_STACK
  25112. sp_digit* priv = NULL;
  25113. sp_point_256* pub = NULL;
  25114. #else
  25115. sp_digit priv[5];
  25116. sp_point_256 pub[2];
  25117. #endif
  25118. sp_point_256* p = NULL;
  25119. const byte one[1] = { 1 };
  25120. int err = MP_OKAY;
  25121. /* Quick check the lengs of public key ordinates and private key are in
  25122. * range. Proper check later.
  25123. */
  25124. if (((mp_count_bits(pX) > 256) ||
  25125. (mp_count_bits(pY) > 256) ||
  25126. ((privm != NULL) && (mp_count_bits(privm) > 256)))) {
  25127. err = ECC_OUT_OF_RANGE_E;
  25128. }
  25129. #ifdef WOLFSSL_SP_SMALL_STACK
  25130. if (err == MP_OKAY) {
  25131. pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap,
  25132. DYNAMIC_TYPE_ECC);
  25133. if (pub == NULL)
  25134. err = MEMORY_E;
  25135. }
  25136. if (err == MP_OKAY && privm) {
  25137. priv = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5, heap,
  25138. DYNAMIC_TYPE_ECC);
  25139. if (priv == NULL)
  25140. err = MEMORY_E;
  25141. }
  25142. #endif
  25143. if (err == MP_OKAY) {
  25144. p = pub + 1;
  25145. sp_256_from_mp(pub->x, 5, pX);
  25146. sp_256_from_mp(pub->y, 5, pY);
  25147. sp_256_from_bin(pub->z, 5, one, (int)sizeof(one));
  25148. if (privm)
  25149. sp_256_from_mp(priv, 5, privm);
  25150. /* Check point at infinitiy. */
  25151. if ((sp_256_iszero_5(pub->x) != 0) &&
  25152. (sp_256_iszero_5(pub->y) != 0)) {
  25153. err = ECC_INF_E;
  25154. }
  25155. }
  25156. /* Check range of X and Y */
  25157. if ((err == MP_OKAY) &&
  25158. ((sp_256_cmp_5(pub->x, p256_mod) >= 0) ||
  25159. (sp_256_cmp_5(pub->y, p256_mod) >= 0))) {
  25160. err = ECC_OUT_OF_RANGE_E;
  25161. }
  25162. if (err == MP_OKAY) {
  25163. /* Check point is on curve */
  25164. err = sp_256_ecc_is_point_5(pub, heap);
  25165. }
  25166. if (err == MP_OKAY) {
  25167. /* Point * order = infinity */
  25168. err = sp_256_ecc_mulmod_5(p, pub, p256_order, 1, 1, heap);
  25169. }
  25170. /* Check result is infinity */
  25171. if ((err == MP_OKAY) && ((sp_256_iszero_5(p->x) == 0) ||
  25172. (sp_256_iszero_5(p->y) == 0))) {
  25173. err = ECC_INF_E;
  25174. }
  25175. if (privm) {
  25176. if (err == MP_OKAY) {
  25177. /* Base * private = point */
  25178. err = sp_256_ecc_mulmod_base_5(p, priv, 1, 1, heap);
  25179. }
  25180. /* Check result is public key */
  25181. if ((err == MP_OKAY) &&
  25182. ((sp_256_cmp_5(p->x, pub->x) != 0) ||
  25183. (sp_256_cmp_5(p->y, pub->y) != 0))) {
  25184. err = ECC_PRIV_KEY_E;
  25185. }
  25186. }
  25187. #ifdef WOLFSSL_SP_SMALL_STACK
  25188. if (pub != NULL)
  25189. XFREE(pub, heap, DYNAMIC_TYPE_ECC);
  25190. if (priv != NULL)
  25191. XFREE(priv, heap, DYNAMIC_TYPE_ECC);
  25192. #endif
  25193. return err;
  25194. }
  25195. #endif
  25196. #ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL
  25197. /* Add two projective EC points together.
  25198. * (pX, pY, pZ) + (qX, qY, qZ) = (rX, rY, rZ)
  25199. *
  25200. * pX First EC point's X ordinate.
  25201. * pY First EC point's Y ordinate.
  25202. * pZ First EC point's Z ordinate.
  25203. * qX Second EC point's X ordinate.
  25204. * qY Second EC point's Y ordinate.
  25205. * qZ Second EC point's Z ordinate.
  25206. * rX Resultant EC point's X ordinate.
  25207. * rY Resultant EC point's Y ordinate.
  25208. * rZ Resultant EC point's Z ordinate.
  25209. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  25210. */
  25211. int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ,
  25212. mp_int* qX, mp_int* qY, mp_int* qZ,
  25213. mp_int* rX, mp_int* rY, mp_int* rZ)
  25214. {
  25215. #ifdef WOLFSSL_SP_SMALL_STACK
  25216. sp_digit* tmp = NULL;
  25217. sp_point_256* p = NULL;
  25218. #else
  25219. sp_digit tmp[2 * 5 * 6];
  25220. sp_point_256 p[2];
  25221. #endif
  25222. sp_point_256* q = NULL;
  25223. int err = MP_OKAY;
  25224. #ifdef WOLFSSL_SP_SMALL_STACK
  25225. if (err == MP_OKAY) {
  25226. p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL,
  25227. DYNAMIC_TYPE_ECC);
  25228. if (p == NULL)
  25229. err = MEMORY_E;
  25230. }
  25231. if (err == MP_OKAY) {
  25232. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 6, NULL,
  25233. DYNAMIC_TYPE_ECC);
  25234. if (tmp == NULL) {
  25235. err = MEMORY_E;
  25236. }
  25237. }
  25238. #endif
  25239. if (err == MP_OKAY) {
  25240. q = p + 1;
  25241. sp_256_from_mp(p->x, 5, pX);
  25242. sp_256_from_mp(p->y, 5, pY);
  25243. sp_256_from_mp(p->z, 5, pZ);
  25244. sp_256_from_mp(q->x, 5, qX);
  25245. sp_256_from_mp(q->y, 5, qY);
  25246. sp_256_from_mp(q->z, 5, qZ);
  25247. p->infinity = sp_256_iszero_5(p->x) &
  25248. sp_256_iszero_5(p->y);
  25249. q->infinity = sp_256_iszero_5(q->x) &
  25250. sp_256_iszero_5(q->y);
  25251. sp_256_proj_point_add_5(p, p, q, tmp);
  25252. }
  25253. if (err == MP_OKAY) {
  25254. err = sp_256_to_mp(p->x, rX);
  25255. }
  25256. if (err == MP_OKAY) {
  25257. err = sp_256_to_mp(p->y, rY);
  25258. }
  25259. if (err == MP_OKAY) {
  25260. err = sp_256_to_mp(p->z, rZ);
  25261. }
  25262. #ifdef WOLFSSL_SP_SMALL_STACK
  25263. if (tmp != NULL)
  25264. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  25265. if (p != NULL)
  25266. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  25267. #endif
  25268. return err;
  25269. }
  25270. /* Double a projective EC point.
  25271. * (pX, pY, pZ) + (pX, pY, pZ) = (rX, rY, rZ)
  25272. *
  25273. * pX EC point's X ordinate.
  25274. * pY EC point's Y ordinate.
  25275. * pZ EC point's Z ordinate.
  25276. * rX Resultant EC point's X ordinate.
  25277. * rY Resultant EC point's Y ordinate.
  25278. * rZ Resultant EC point's Z ordinate.
  25279. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  25280. */
  25281. int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ,
  25282. mp_int* rX, mp_int* rY, mp_int* rZ)
  25283. {
  25284. #ifdef WOLFSSL_SP_SMALL_STACK
  25285. sp_digit* tmp = NULL;
  25286. sp_point_256* p = NULL;
  25287. #else
  25288. sp_digit tmp[2 * 5 * 2];
  25289. sp_point_256 p[1];
  25290. #endif
  25291. int err = MP_OKAY;
  25292. #ifdef WOLFSSL_SP_SMALL_STACK
  25293. if (err == MP_OKAY) {
  25294. p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL,
  25295. DYNAMIC_TYPE_ECC);
  25296. if (p == NULL)
  25297. err = MEMORY_E;
  25298. }
  25299. if (err == MP_OKAY) {
  25300. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 2, NULL,
  25301. DYNAMIC_TYPE_ECC);
  25302. if (tmp == NULL)
  25303. err = MEMORY_E;
  25304. }
  25305. #endif
  25306. if (err == MP_OKAY) {
  25307. sp_256_from_mp(p->x, 5, pX);
  25308. sp_256_from_mp(p->y, 5, pY);
  25309. sp_256_from_mp(p->z, 5, pZ);
  25310. p->infinity = sp_256_iszero_5(p->x) &
  25311. sp_256_iszero_5(p->y);
  25312. sp_256_proj_point_dbl_5(p, p, tmp);
  25313. }
  25314. if (err == MP_OKAY) {
  25315. err = sp_256_to_mp(p->x, rX);
  25316. }
  25317. if (err == MP_OKAY) {
  25318. err = sp_256_to_mp(p->y, rY);
  25319. }
  25320. if (err == MP_OKAY) {
  25321. err = sp_256_to_mp(p->z, rZ);
  25322. }
  25323. #ifdef WOLFSSL_SP_SMALL_STACK
  25324. if (tmp != NULL)
  25325. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  25326. if (p != NULL)
  25327. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  25328. #endif
  25329. return err;
  25330. }
  25331. /* Map a projective EC point to affine in place.
  25332. * pZ will be one.
  25333. *
  25334. * pX EC point's X ordinate.
  25335. * pY EC point's Y ordinate.
  25336. * pZ EC point's Z ordinate.
  25337. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  25338. */
  25339. int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ)
  25340. {
  25341. #ifdef WOLFSSL_SP_SMALL_STACK
  25342. sp_digit* tmp = NULL;
  25343. sp_point_256* p = NULL;
  25344. #else
  25345. sp_digit tmp[2 * 5 * 4];
  25346. sp_point_256 p[1];
  25347. #endif
  25348. int err = MP_OKAY;
  25349. #ifdef WOLFSSL_SP_SMALL_STACK
  25350. if (err == MP_OKAY) {
  25351. p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL,
  25352. DYNAMIC_TYPE_ECC);
  25353. if (p == NULL)
  25354. err = MEMORY_E;
  25355. }
  25356. if (err == MP_OKAY) {
  25357. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 4, NULL,
  25358. DYNAMIC_TYPE_ECC);
  25359. if (tmp == NULL)
  25360. err = MEMORY_E;
  25361. }
  25362. #endif
  25363. if (err == MP_OKAY) {
  25364. sp_256_from_mp(p->x, 5, pX);
  25365. sp_256_from_mp(p->y, 5, pY);
  25366. sp_256_from_mp(p->z, 5, pZ);
  25367. p->infinity = sp_256_iszero_5(p->x) &
  25368. sp_256_iszero_5(p->y);
  25369. sp_256_map_5(p, p, tmp);
  25370. }
  25371. if (err == MP_OKAY) {
  25372. err = sp_256_to_mp(p->x, pX);
  25373. }
  25374. if (err == MP_OKAY) {
  25375. err = sp_256_to_mp(p->y, pY);
  25376. }
  25377. if (err == MP_OKAY) {
  25378. err = sp_256_to_mp(p->z, pZ);
  25379. }
  25380. #ifdef WOLFSSL_SP_SMALL_STACK
  25381. if (tmp != NULL)
  25382. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  25383. if (p != NULL)
  25384. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  25385. #endif
  25386. return err;
  25387. }
  25388. #endif /* WOLFSSL_PUBLIC_ECC_ADD_DBL */
  25389. #ifdef HAVE_COMP_KEY
  25390. /* Find the square root of a number mod the prime of the curve.
  25391. *
  25392. * y The number to operate on and the result.
  25393. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  25394. */
  25395. static int sp_256_mont_sqrt_5(sp_digit* y)
  25396. {
  25397. #ifdef WOLFSSL_SP_SMALL_STACK
  25398. sp_digit* t1 = NULL;
  25399. #else
  25400. sp_digit t1[4 * 5];
  25401. #endif
  25402. sp_digit* t2 = NULL;
  25403. int err = MP_OKAY;
  25404. #ifdef WOLFSSL_SP_SMALL_STACK
  25405. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 5, NULL, DYNAMIC_TYPE_ECC);
  25406. if (t1 == NULL) {
  25407. err = MEMORY_E;
  25408. }
  25409. #endif
  25410. if (err == MP_OKAY) {
  25411. t2 = t1 + 2 * 5;
  25412. {
  25413. /* t2 = y ^ 0x2 */
  25414. sp_256_mont_sqr_5(t2, y, p256_mod, p256_mp_mod);
  25415. /* t1 = y ^ 0x3 */
  25416. sp_256_mont_mul_5(t1, t2, y, p256_mod, p256_mp_mod);
  25417. /* t2 = y ^ 0xc */
  25418. sp_256_mont_sqr_n_5(t2, t1, 2, p256_mod, p256_mp_mod);
  25419. /* t1 = y ^ 0xf */
  25420. sp_256_mont_mul_5(t1, t1, t2, p256_mod, p256_mp_mod);
  25421. /* t2 = y ^ 0xf0 */
  25422. sp_256_mont_sqr_n_5(t2, t1, 4, p256_mod, p256_mp_mod);
  25423. /* t1 = y ^ 0xff */
  25424. sp_256_mont_mul_5(t1, t1, t2, p256_mod, p256_mp_mod);
  25425. /* t2 = y ^ 0xff00 */
  25426. sp_256_mont_sqr_n_5(t2, t1, 8, p256_mod, p256_mp_mod);
  25427. /* t1 = y ^ 0xffff */
  25428. sp_256_mont_mul_5(t1, t1, t2, p256_mod, p256_mp_mod);
  25429. /* t2 = y ^ 0xffff0000 */
  25430. sp_256_mont_sqr_n_5(t2, t1, 16, p256_mod, p256_mp_mod);
  25431. /* t1 = y ^ 0xffffffff */
  25432. sp_256_mont_mul_5(t1, t1, t2, p256_mod, p256_mp_mod);
  25433. /* t1 = y ^ 0xffffffff00000000 */
  25434. sp_256_mont_sqr_n_5(t1, t1, 32, p256_mod, p256_mp_mod);
  25435. /* t1 = y ^ 0xffffffff00000001 */
  25436. sp_256_mont_mul_5(t1, t1, y, p256_mod, p256_mp_mod);
  25437. /* t1 = y ^ 0xffffffff00000001000000000000000000000000 */
  25438. sp_256_mont_sqr_n_5(t1, t1, 96, p256_mod, p256_mp_mod);
  25439. /* t1 = y ^ 0xffffffff00000001000000000000000000000001 */
  25440. sp_256_mont_mul_5(t1, t1, y, p256_mod, p256_mp_mod);
  25441. sp_256_mont_sqr_n_5(y, t1, 94, p256_mod, p256_mp_mod);
  25442. }
  25443. }
  25444. #ifdef WOLFSSL_SP_SMALL_STACK
  25445. if (t1 != NULL)
  25446. XFREE(t1, NULL, DYNAMIC_TYPE_ECC);
  25447. #endif
  25448. return err;
  25449. }
  25450. /* Uncompress the point given the X ordinate.
  25451. *
  25452. * xm X ordinate.
  25453. * odd Whether the Y ordinate is odd.
  25454. * ym Calculated Y ordinate.
  25455. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  25456. */
  25457. int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym)
  25458. {
  25459. #ifdef WOLFSSL_SP_SMALL_STACK
  25460. sp_digit* x = NULL;
  25461. #else
  25462. sp_digit x[4 * 5];
  25463. #endif
  25464. sp_digit* y = NULL;
  25465. int err = MP_OKAY;
  25466. #ifdef WOLFSSL_SP_SMALL_STACK
  25467. x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 5, NULL, DYNAMIC_TYPE_ECC);
  25468. if (x == NULL)
  25469. err = MEMORY_E;
  25470. #endif
  25471. if (err == MP_OKAY) {
  25472. y = x + 2 * 5;
  25473. sp_256_from_mp(x, 5, xm);
  25474. err = sp_256_mod_mul_norm_5(x, x, p256_mod);
  25475. }
  25476. if (err == MP_OKAY) {
  25477. /* y = x^3 */
  25478. {
  25479. sp_256_mont_sqr_5(y, x, p256_mod, p256_mp_mod);
  25480. sp_256_mont_mul_5(y, y, x, p256_mod, p256_mp_mod);
  25481. }
  25482. /* y = x^3 - 3x */
  25483. sp_256_mont_sub_5(y, y, x, p256_mod);
  25484. sp_256_mont_sub_5(y, y, x, p256_mod);
  25485. sp_256_mont_sub_5(y, y, x, p256_mod);
  25486. /* y = x^3 - 3x + b */
  25487. err = sp_256_mod_mul_norm_5(x, p256_b, p256_mod);
  25488. }
  25489. if (err == MP_OKAY) {
  25490. sp_256_mont_add_5(y, y, x, p256_mod);
  25491. /* y = sqrt(x^3 - 3x + b) */
  25492. err = sp_256_mont_sqrt_5(y);
  25493. }
  25494. if (err == MP_OKAY) {
  25495. XMEMSET(y + 5, 0, 5U * sizeof(sp_digit));
  25496. sp_256_mont_reduce_5(y, p256_mod, p256_mp_mod);
  25497. if ((((word32)y[0] ^ (word32)odd) & 1U) != 0U) {
  25498. sp_256_mont_sub_5(y, p256_mod, y, p256_mod);
  25499. }
  25500. err = sp_256_to_mp(y, ym);
  25501. }
  25502. #ifdef WOLFSSL_SP_SMALL_STACK
  25503. if (x != NULL)
  25504. XFREE(x, NULL, DYNAMIC_TYPE_ECC);
  25505. #endif
  25506. return err;
  25507. }
  25508. #endif
  25509. #endif /* !WOLFSSL_SP_NO_256 */
  25510. #ifdef WOLFSSL_SP_384
  25511. /* Point structure to use. */
  25512. typedef struct sp_point_384 {
  25513. /* X ordinate of point. */
  25514. sp_digit x[2 * 7];
  25515. /* Y ordinate of point. */
  25516. sp_digit y[2 * 7];
  25517. /* Z ordinate of point. */
  25518. sp_digit z[2 * 7];
  25519. /* Indicates point is at infinity. */
  25520. int infinity;
  25521. } sp_point_384;
  25522. /* The modulus (prime) of the curve P384. */
  25523. static const sp_digit p384_mod[7] = {
  25524. 0x000000ffffffffL,0x7ffe0000000000L,0x7ffffffffbffffL,0x7fffffffffffffL,
  25525. 0x7fffffffffffffL,0x7fffffffffffffL,0x3fffffffffffffL
  25526. };
  25527. /* The Montgomery normalizer for modulus of the curve P384. */
  25528. static const sp_digit p384_norm_mod[7] = {
  25529. 0x7fffff00000001L,0x0001ffffffffffL,0x00000000040000L,0x00000000000000L,
  25530. 0x00000000000000L,0x00000000000000L,0x00000000000000L
  25531. };
  25532. /* The Montgomery multiplier for modulus of the curve P384. */
  25533. static sp_digit p384_mp_mod = 0x0000100000001;
  25534. #if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
  25535. defined(HAVE_ECC_VERIFY)
  25536. /* The order of the curve P384. */
  25537. static const sp_digit p384_order[7] = {
  25538. 0x6c196accc52973L,0x1b6491614ef5d9L,0x07d0dcb77d6068L,0x7ffffffe3b1a6cL,
  25539. 0x7fffffffffffffL,0x7fffffffffffffL,0x3fffffffffffffL
  25540. };
  25541. #endif
  25542. /* The order of the curve P384 minus 2. */
  25543. static const sp_digit p384_order2[7] = {
  25544. 0x6c196accc52971L,0x1b6491614ef5d9L,0x07d0dcb77d6068L,0x7ffffffe3b1a6cL,
  25545. 0x7fffffffffffffL,0x7fffffffffffffL,0x3fffffffffffffL
  25546. };
  25547. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  25548. /* The Montgomery normalizer for order of the curve P384. */
  25549. static const sp_digit p384_norm_order[7] = {
  25550. 0x13e695333ad68dL,0x649b6e9eb10a26L,0x782f2348829f97L,0x00000001c4e593L,
  25551. 0x00000000000000L,0x00000000000000L,0x00000000000000L
  25552. };
  25553. #endif
  25554. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  25555. /* The Montgomery multiplier for order of the curve P384. */
  25556. static sp_digit p384_mp_order = 0x546089e88fdc45L;
  25557. #endif
  25558. /* The base point of curve P384. */
  25559. static const sp_point_384 p384_base = {
  25560. /* X ordinate */
  25561. {
  25562. 0x545e3872760ab7L,0x64bb7eaa52d874L,0x020950a8e1540bL,0x5d3cdcc2cfba0fL,
  25563. 0x0ad746e1d3b628L,0x26f1d638e3de64L,0x2aa1f288afa2c1L,
  25564. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  25565. (sp_digit)0, (sp_digit)0
  25566. },
  25567. /* Y ordinate */
  25568. {
  25569. 0x431d7c90ea0e5fL,0x639c3afd033af4L,0x4ed7c2e3002982L,0x44d0a3e74ed188L,
  25570. 0x2dc29f8f41dbd2L,0x0debb3d317f252L,0x0d85f792a5898bL,
  25571. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  25572. (sp_digit)0, (sp_digit)0
  25573. },
  25574. /* Z ordinate */
  25575. {
  25576. 0x00000000000001L,0x00000000000000L,0x00000000000000L,0x00000000000000L,
  25577. 0x00000000000000L,0x00000000000000L,0x00000000000000L,
  25578. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  25579. (sp_digit)0, (sp_digit)0
  25580. },
  25581. /* infinity */
  25582. 0
  25583. };
  25584. #if defined(HAVE_ECC_CHECK_KEY) || defined(HAVE_COMP_KEY)
  25585. static const sp_digit p384_b[7] = {
  25586. 0x05c8edd3ec2aefL,0x731b145da33a55L,0x3d404e1d6b1958L,0x740a089018a044L,
  25587. 0x02d19181d9c6efL,0x7c9311c0ad7c7fL,0x2ccc4be9f88fb9L
  25588. };
  25589. #endif
  25590. #ifdef WOLFSSL_SP_SMALL
  25591. /* Multiply a and b into r. (r = a * b)
  25592. *
  25593. * r A single precision integer.
  25594. * a A single precision integer.
  25595. * b A single precision integer.
  25596. */
  25597. SP_NOINLINE static void sp_384_mul_7(sp_digit* r, const sp_digit* a,
  25598. const sp_digit* b)
  25599. {
  25600. int i;
  25601. int imax;
  25602. int k;
  25603. sp_uint128 c;
  25604. sp_uint128 lo;
  25605. c = ((sp_uint128)a[6]) * b[6];
  25606. r[13] = (sp_digit)(c >> 55);
  25607. c &= 0x7fffffffffffffL;
  25608. for (k = 11; k >= 0; k--) {
  25609. if (k >= 7) {
  25610. i = k - 6;
  25611. imax = 6;
  25612. }
  25613. else {
  25614. i = 0;
  25615. imax = k;
  25616. }
  25617. lo = 0;
  25618. for (; i <= imax; i++) {
  25619. lo += ((sp_uint128)a[i]) * b[k - i];
  25620. }
  25621. c += lo >> 55;
  25622. r[k + 2] += (sp_digit)(c >> 55);
  25623. r[k + 1] = (sp_digit)(c & 0x7fffffffffffffL);
  25624. c = lo & 0x7fffffffffffffL;
  25625. }
  25626. r[0] = (sp_digit)c;
  25627. }
  25628. #else
  25629. /* Multiply a and b into r. (r = a * b)
  25630. *
  25631. * r A single precision integer.
  25632. * a A single precision integer.
  25633. * b A single precision integer.
  25634. */
  25635. SP_NOINLINE static void sp_384_mul_7(sp_digit* r, const sp_digit* a,
  25636. const sp_digit* b)
  25637. {
  25638. sp_int128 t0 = ((sp_int128)a[ 0]) * b[ 0];
  25639. sp_int128 t1 = ((sp_int128)a[ 0]) * b[ 1]
  25640. + ((sp_int128)a[ 1]) * b[ 0];
  25641. sp_int128 t2 = ((sp_int128)a[ 0]) * b[ 2]
  25642. + ((sp_int128)a[ 1]) * b[ 1]
  25643. + ((sp_int128)a[ 2]) * b[ 0];
  25644. sp_int128 t3 = ((sp_int128)a[ 0]) * b[ 3]
  25645. + ((sp_int128)a[ 1]) * b[ 2]
  25646. + ((sp_int128)a[ 2]) * b[ 1]
  25647. + ((sp_int128)a[ 3]) * b[ 0];
  25648. sp_int128 t4 = ((sp_int128)a[ 0]) * b[ 4]
  25649. + ((sp_int128)a[ 1]) * b[ 3]
  25650. + ((sp_int128)a[ 2]) * b[ 2]
  25651. + ((sp_int128)a[ 3]) * b[ 1]
  25652. + ((sp_int128)a[ 4]) * b[ 0];
  25653. sp_int128 t5 = ((sp_int128)a[ 0]) * b[ 5]
  25654. + ((sp_int128)a[ 1]) * b[ 4]
  25655. + ((sp_int128)a[ 2]) * b[ 3]
  25656. + ((sp_int128)a[ 3]) * b[ 2]
  25657. + ((sp_int128)a[ 4]) * b[ 1]
  25658. + ((sp_int128)a[ 5]) * b[ 0];
  25659. sp_int128 t6 = ((sp_int128)a[ 0]) * b[ 6]
  25660. + ((sp_int128)a[ 1]) * b[ 5]
  25661. + ((sp_int128)a[ 2]) * b[ 4]
  25662. + ((sp_int128)a[ 3]) * b[ 3]
  25663. + ((sp_int128)a[ 4]) * b[ 2]
  25664. + ((sp_int128)a[ 5]) * b[ 1]
  25665. + ((sp_int128)a[ 6]) * b[ 0];
  25666. sp_int128 t7 = ((sp_int128)a[ 1]) * b[ 6]
  25667. + ((sp_int128)a[ 2]) * b[ 5]
  25668. + ((sp_int128)a[ 3]) * b[ 4]
  25669. + ((sp_int128)a[ 4]) * b[ 3]
  25670. + ((sp_int128)a[ 5]) * b[ 2]
  25671. + ((sp_int128)a[ 6]) * b[ 1];
  25672. sp_int128 t8 = ((sp_int128)a[ 2]) * b[ 6]
  25673. + ((sp_int128)a[ 3]) * b[ 5]
  25674. + ((sp_int128)a[ 4]) * b[ 4]
  25675. + ((sp_int128)a[ 5]) * b[ 3]
  25676. + ((sp_int128)a[ 6]) * b[ 2];
  25677. sp_int128 t9 = ((sp_int128)a[ 3]) * b[ 6]
  25678. + ((sp_int128)a[ 4]) * b[ 5]
  25679. + ((sp_int128)a[ 5]) * b[ 4]
  25680. + ((sp_int128)a[ 6]) * b[ 3];
  25681. sp_int128 t10 = ((sp_int128)a[ 4]) * b[ 6]
  25682. + ((sp_int128)a[ 5]) * b[ 5]
  25683. + ((sp_int128)a[ 6]) * b[ 4];
  25684. sp_int128 t11 = ((sp_int128)a[ 5]) * b[ 6]
  25685. + ((sp_int128)a[ 6]) * b[ 5];
  25686. sp_int128 t12 = ((sp_int128)a[ 6]) * b[ 6];
  25687. t1 += t0 >> 55; r[ 0] = t0 & 0x7fffffffffffffL;
  25688. t2 += t1 >> 55; r[ 1] = t1 & 0x7fffffffffffffL;
  25689. t3 += t2 >> 55; r[ 2] = t2 & 0x7fffffffffffffL;
  25690. t4 += t3 >> 55; r[ 3] = t3 & 0x7fffffffffffffL;
  25691. t5 += t4 >> 55; r[ 4] = t4 & 0x7fffffffffffffL;
  25692. t6 += t5 >> 55; r[ 5] = t5 & 0x7fffffffffffffL;
  25693. t7 += t6 >> 55; r[ 6] = t6 & 0x7fffffffffffffL;
  25694. t8 += t7 >> 55; r[ 7] = t7 & 0x7fffffffffffffL;
  25695. t9 += t8 >> 55; r[ 8] = t8 & 0x7fffffffffffffL;
  25696. t10 += t9 >> 55; r[ 9] = t9 & 0x7fffffffffffffL;
  25697. t11 += t10 >> 55; r[10] = t10 & 0x7fffffffffffffL;
  25698. t12 += t11 >> 55; r[11] = t11 & 0x7fffffffffffffL;
  25699. r[13] = (sp_digit)(t12 >> 55);
  25700. r[12] = t12 & 0x7fffffffffffffL;
  25701. }
  25702. #endif /* WOLFSSL_SP_SMALL */
  25703. #ifdef WOLFSSL_SP_SMALL
  25704. /* Square a and put result in r. (r = a * a)
  25705. *
  25706. * r A single precision integer.
  25707. * a A single precision integer.
  25708. */
  25709. SP_NOINLINE static void sp_384_sqr_7(sp_digit* r, const sp_digit* a)
  25710. {
  25711. int i;
  25712. int imax;
  25713. int k;
  25714. sp_uint128 c;
  25715. sp_uint128 t;
  25716. c = ((sp_uint128)a[6]) * a[6];
  25717. r[13] = (sp_digit)(c >> 55);
  25718. c = (c & 0x7fffffffffffffL) << 55;
  25719. for (k = 11; k >= 0; k--) {
  25720. i = (k + 1) / 2;
  25721. if ((k & 1) == 0) {
  25722. c += ((sp_uint128)a[i]) * a[i];
  25723. i++;
  25724. }
  25725. if (k < 6) {
  25726. imax = k;
  25727. }
  25728. else {
  25729. imax = 6;
  25730. }
  25731. t = 0;
  25732. for (; i <= imax; i++) {
  25733. t += ((sp_uint128)a[i]) * a[k - i];
  25734. }
  25735. c += t * 2;
  25736. r[k + 2] += (sp_digit) (c >> 110);
  25737. r[k + 1] = (sp_digit)((c >> 55) & 0x7fffffffffffffL);
  25738. c = (c & 0x7fffffffffffffL) << 55;
  25739. }
  25740. r[0] = (sp_digit)(c >> 55);
  25741. }
  25742. #else
  25743. /* Square a and put result in r. (r = a * a)
  25744. *
  25745. * r A single precision integer.
  25746. * a A single precision integer.
  25747. */
  25748. SP_NOINLINE static void sp_384_sqr_7(sp_digit* r, const sp_digit* a)
  25749. {
  25750. sp_int128 t0 = ((sp_int128)a[ 0]) * a[ 0];
  25751. sp_int128 t1 = (((sp_int128)a[ 0]) * a[ 1]) * 2;
  25752. sp_int128 t2 = (((sp_int128)a[ 0]) * a[ 2]) * 2
  25753. + ((sp_int128)a[ 1]) * a[ 1];
  25754. sp_int128 t3 = (((sp_int128)a[ 0]) * a[ 3]
  25755. + ((sp_int128)a[ 1]) * a[ 2]) * 2;
  25756. sp_int128 t4 = (((sp_int128)a[ 0]) * a[ 4]
  25757. + ((sp_int128)a[ 1]) * a[ 3]) * 2
  25758. + ((sp_int128)a[ 2]) * a[ 2];
  25759. sp_int128 t5 = (((sp_int128)a[ 0]) * a[ 5]
  25760. + ((sp_int128)a[ 1]) * a[ 4]
  25761. + ((sp_int128)a[ 2]) * a[ 3]) * 2;
  25762. sp_int128 t6 = (((sp_int128)a[ 0]) * a[ 6]
  25763. + ((sp_int128)a[ 1]) * a[ 5]
  25764. + ((sp_int128)a[ 2]) * a[ 4]) * 2
  25765. + ((sp_int128)a[ 3]) * a[ 3];
  25766. sp_int128 t7 = (((sp_int128)a[ 1]) * a[ 6]
  25767. + ((sp_int128)a[ 2]) * a[ 5]
  25768. + ((sp_int128)a[ 3]) * a[ 4]) * 2;
  25769. sp_int128 t8 = (((sp_int128)a[ 2]) * a[ 6]
  25770. + ((sp_int128)a[ 3]) * a[ 5]) * 2
  25771. + ((sp_int128)a[ 4]) * a[ 4];
  25772. sp_int128 t9 = (((sp_int128)a[ 3]) * a[ 6]
  25773. + ((sp_int128)a[ 4]) * a[ 5]) * 2;
  25774. sp_int128 t10 = (((sp_int128)a[ 4]) * a[ 6]) * 2
  25775. + ((sp_int128)a[ 5]) * a[ 5];
  25776. sp_int128 t11 = (((sp_int128)a[ 5]) * a[ 6]) * 2;
  25777. sp_int128 t12 = ((sp_int128)a[ 6]) * a[ 6];
  25778. t1 += t0 >> 55; r[ 0] = t0 & 0x7fffffffffffffL;
  25779. t2 += t1 >> 55; r[ 1] = t1 & 0x7fffffffffffffL;
  25780. t3 += t2 >> 55; r[ 2] = t2 & 0x7fffffffffffffL;
  25781. t4 += t3 >> 55; r[ 3] = t3 & 0x7fffffffffffffL;
  25782. t5 += t4 >> 55; r[ 4] = t4 & 0x7fffffffffffffL;
  25783. t6 += t5 >> 55; r[ 5] = t5 & 0x7fffffffffffffL;
  25784. t7 += t6 >> 55; r[ 6] = t6 & 0x7fffffffffffffL;
  25785. t8 += t7 >> 55; r[ 7] = t7 & 0x7fffffffffffffL;
  25786. t9 += t8 >> 55; r[ 8] = t8 & 0x7fffffffffffffL;
  25787. t10 += t9 >> 55; r[ 9] = t9 & 0x7fffffffffffffL;
  25788. t11 += t10 >> 55; r[10] = t10 & 0x7fffffffffffffL;
  25789. t12 += t11 >> 55; r[11] = t11 & 0x7fffffffffffffL;
  25790. r[13] = (sp_digit)(t12 >> 55);
  25791. r[12] = t12 & 0x7fffffffffffffL;
  25792. }
  25793. #endif /* WOLFSSL_SP_SMALL */
  25794. #ifdef WOLFSSL_SP_SMALL
  25795. /* Add b to a into r. (r = a + b)
  25796. *
  25797. * r A single precision integer.
  25798. * a A single precision integer.
  25799. * b A single precision integer.
  25800. */
  25801. SP_NOINLINE static int sp_384_add_7(sp_digit* r, const sp_digit* a,
  25802. const sp_digit* b)
  25803. {
  25804. int i;
  25805. for (i = 0; i < 7; i++) {
  25806. r[i] = a[i] + b[i];
  25807. }
  25808. return 0;
  25809. }
  25810. #else
  25811. /* Add b to a into r. (r = a + b)
  25812. *
  25813. * r A single precision integer.
  25814. * a A single precision integer.
  25815. * b A single precision integer.
  25816. */
  25817. SP_NOINLINE static int sp_384_add_7(sp_digit* r, const sp_digit* a,
  25818. const sp_digit* b)
  25819. {
  25820. r[ 0] = a[ 0] + b[ 0];
  25821. r[ 1] = a[ 1] + b[ 1];
  25822. r[ 2] = a[ 2] + b[ 2];
  25823. r[ 3] = a[ 3] + b[ 3];
  25824. r[ 4] = a[ 4] + b[ 4];
  25825. r[ 5] = a[ 5] + b[ 5];
  25826. r[ 6] = a[ 6] + b[ 6];
  25827. return 0;
  25828. }
  25829. #endif /* WOLFSSL_SP_SMALL */
  25830. #ifdef WOLFSSL_SP_SMALL
  25831. /* Sub b from a into r. (r = a - b)
  25832. *
  25833. * r A single precision integer.
  25834. * a A single precision integer.
  25835. * b A single precision integer.
  25836. */
  25837. SP_NOINLINE static int sp_384_sub_7(sp_digit* r, const sp_digit* a,
  25838. const sp_digit* b)
  25839. {
  25840. int i;
  25841. for (i = 0; i < 7; i++) {
  25842. r[i] = a[i] - b[i];
  25843. }
  25844. return 0;
  25845. }
  25846. #else
  25847. /* Sub b from a into r. (r = a - b)
  25848. *
  25849. * r A single precision integer.
  25850. * a A single precision integer.
  25851. * b A single precision integer.
  25852. */
  25853. SP_NOINLINE static int sp_384_sub_7(sp_digit* r, const sp_digit* a,
  25854. const sp_digit* b)
  25855. {
  25856. r[ 0] = a[ 0] - b[ 0];
  25857. r[ 1] = a[ 1] - b[ 1];
  25858. r[ 2] = a[ 2] - b[ 2];
  25859. r[ 3] = a[ 3] - b[ 3];
  25860. r[ 4] = a[ 4] - b[ 4];
  25861. r[ 5] = a[ 5] - b[ 5];
  25862. r[ 6] = a[ 6] - b[ 6];
  25863. return 0;
  25864. }
  25865. #endif /* WOLFSSL_SP_SMALL */
  25866. /* Convert an mp_int to an array of sp_digit.
  25867. *
  25868. * r A single precision integer.
  25869. * size Maximum number of bytes to convert
  25870. * a A multi-precision integer.
  25871. */
  25872. static void sp_384_from_mp(sp_digit* r, int size, const mp_int* a)
  25873. {
  25874. #if DIGIT_BIT == 55
  25875. int i;
  25876. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  25877. int o = 0;
  25878. for (i = 0; i < size; i++) {
  25879. sp_digit mask = (sp_digit)0 - (j >> 54);
  25880. r[i] = a->dp[o] & mask;
  25881. j++;
  25882. o += (int)(j >> 54);
  25883. }
  25884. #elif DIGIT_BIT > 55
  25885. unsigned int i;
  25886. int j = 0;
  25887. word32 s = 0;
  25888. r[0] = 0;
  25889. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  25890. r[j] |= ((sp_digit)a->dp[i] << s);
  25891. r[j] &= 0x7fffffffffffffL;
  25892. s = 55U - s;
  25893. if (j + 1 >= size) {
  25894. break;
  25895. }
  25896. /* lint allow cast of mismatch word32 and mp_digit */
  25897. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  25898. while ((s + 55U) <= (word32)DIGIT_BIT) {
  25899. s += 55U;
  25900. r[j] &= 0x7fffffffffffffL;
  25901. if (j + 1 >= size) {
  25902. break;
  25903. }
  25904. if (s < (word32)DIGIT_BIT) {
  25905. /* lint allow cast of mismatch word32 and mp_digit */
  25906. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  25907. }
  25908. else {
  25909. r[++j] = (sp_digit)0;
  25910. }
  25911. }
  25912. s = (word32)DIGIT_BIT - s;
  25913. }
  25914. for (j++; j < size; j++) {
  25915. r[j] = 0;
  25916. }
  25917. #else
  25918. unsigned int i;
  25919. int j = 0;
  25920. int s = 0;
  25921. r[0] = 0;
  25922. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  25923. r[j] |= ((sp_digit)a->dp[i]) << s;
  25924. if (s + DIGIT_BIT >= 55) {
  25925. r[j] &= 0x7fffffffffffffL;
  25926. if (j + 1 >= size) {
  25927. break;
  25928. }
  25929. s = 55 - s;
  25930. if (s == DIGIT_BIT) {
  25931. r[++j] = 0;
  25932. s = 0;
  25933. }
  25934. else {
  25935. r[++j] = a->dp[i] >> s;
  25936. s = DIGIT_BIT - s;
  25937. }
  25938. }
  25939. else {
  25940. s += DIGIT_BIT;
  25941. }
  25942. }
  25943. for (j++; j < size; j++) {
  25944. r[j] = 0;
  25945. }
  25946. #endif
  25947. }
  25948. /* Convert a point of type ecc_point to type sp_point_384.
  25949. *
  25950. * p Point of type sp_point_384 (result).
  25951. * pm Point of type ecc_point.
  25952. */
  25953. static void sp_384_point_from_ecc_point_7(sp_point_384* p,
  25954. const ecc_point* pm)
  25955. {
  25956. XMEMSET(p->x, 0, sizeof(p->x));
  25957. XMEMSET(p->y, 0, sizeof(p->y));
  25958. XMEMSET(p->z, 0, sizeof(p->z));
  25959. sp_384_from_mp(p->x, 7, pm->x);
  25960. sp_384_from_mp(p->y, 7, pm->y);
  25961. sp_384_from_mp(p->z, 7, pm->z);
  25962. p->infinity = 0;
  25963. }
  25964. /* Convert an array of sp_digit to an mp_int.
  25965. *
  25966. * a A single precision integer.
  25967. * r A multi-precision integer.
  25968. */
  25969. static int sp_384_to_mp(const sp_digit* a, mp_int* r)
  25970. {
  25971. int err;
  25972. err = mp_grow(r, (384 + DIGIT_BIT - 1) / DIGIT_BIT);
  25973. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  25974. #if DIGIT_BIT == 55
  25975. XMEMCPY(r->dp, a, sizeof(sp_digit) * 7);
  25976. r->used = 7;
  25977. mp_clamp(r);
  25978. #elif DIGIT_BIT < 55
  25979. int i;
  25980. int j = 0;
  25981. int s = 0;
  25982. r->dp[0] = 0;
  25983. for (i = 0; i < 7; i++) {
  25984. r->dp[j] |= (mp_digit)(a[i] << s);
  25985. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  25986. s = DIGIT_BIT - s;
  25987. r->dp[++j] = (mp_digit)(a[i] >> s);
  25988. while (s + DIGIT_BIT <= 55) {
  25989. s += DIGIT_BIT;
  25990. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  25991. if (s == SP_WORD_SIZE) {
  25992. r->dp[j] = 0;
  25993. }
  25994. else {
  25995. r->dp[j] = (mp_digit)(a[i] >> s);
  25996. }
  25997. }
  25998. s = 55 - s;
  25999. }
  26000. r->used = (384 + DIGIT_BIT - 1) / DIGIT_BIT;
  26001. mp_clamp(r);
  26002. #else
  26003. int i;
  26004. int j = 0;
  26005. int s = 0;
  26006. r->dp[0] = 0;
  26007. for (i = 0; i < 7; i++) {
  26008. r->dp[j] |= ((mp_digit)a[i]) << s;
  26009. if (s + 55 >= DIGIT_BIT) {
  26010. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  26011. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  26012. #endif
  26013. s = DIGIT_BIT - s;
  26014. r->dp[++j] = a[i] >> s;
  26015. s = 55 - s;
  26016. }
  26017. else {
  26018. s += 55;
  26019. }
  26020. }
  26021. r->used = (384 + DIGIT_BIT - 1) / DIGIT_BIT;
  26022. mp_clamp(r);
  26023. #endif
  26024. }
  26025. return err;
  26026. }
  26027. /* Convert a point of type sp_point_384 to type ecc_point.
  26028. *
  26029. * p Point of type sp_point_384.
  26030. * pm Point of type ecc_point (result).
  26031. * returns MEMORY_E when allocation of memory in ecc_point fails otherwise
  26032. * MP_OKAY.
  26033. */
  26034. static int sp_384_point_to_ecc_point_7(const sp_point_384* p, ecc_point* pm)
  26035. {
  26036. int err;
  26037. err = sp_384_to_mp(p->x, pm->x);
  26038. if (err == MP_OKAY) {
  26039. err = sp_384_to_mp(p->y, pm->y);
  26040. }
  26041. if (err == MP_OKAY) {
  26042. err = sp_384_to_mp(p->z, pm->z);
  26043. }
  26044. return err;
  26045. }
  26046. /* Compare a with b in constant time.
  26047. *
  26048. * a A single precision integer.
  26049. * b A single precision integer.
  26050. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  26051. * respectively.
  26052. */
  26053. static sp_digit sp_384_cmp_7(const sp_digit* a, const sp_digit* b)
  26054. {
  26055. sp_digit r = 0;
  26056. #ifdef WOLFSSL_SP_SMALL
  26057. int i;
  26058. for (i=6; i>=0; i--) {
  26059. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 54);
  26060. }
  26061. #else
  26062. r |= (a[ 6] - b[ 6]) & (0 - (sp_digit)1);
  26063. r |= (a[ 5] - b[ 5]) & ~(((sp_digit)0 - r) >> 54);
  26064. r |= (a[ 4] - b[ 4]) & ~(((sp_digit)0 - r) >> 54);
  26065. r |= (a[ 3] - b[ 3]) & ~(((sp_digit)0 - r) >> 54);
  26066. r |= (a[ 2] - b[ 2]) & ~(((sp_digit)0 - r) >> 54);
  26067. r |= (a[ 1] - b[ 1]) & ~(((sp_digit)0 - r) >> 54);
  26068. r |= (a[ 0] - b[ 0]) & ~(((sp_digit)0 - r) >> 54);
  26069. #endif /* WOLFSSL_SP_SMALL */
  26070. return r;
  26071. }
  26072. /* Conditionally subtract b from a using the mask m.
  26073. * m is -1 to subtract and 0 when not.
  26074. *
  26075. * r A single precision number representing condition subtract result.
  26076. * a A single precision number to subtract from.
  26077. * b A single precision number to subtract.
  26078. * m Mask value to apply.
  26079. */
  26080. static void sp_384_cond_sub_7(sp_digit* r, const sp_digit* a,
  26081. const sp_digit* b, const sp_digit m)
  26082. {
  26083. #ifdef WOLFSSL_SP_SMALL
  26084. int i;
  26085. for (i = 0; i < 7; i++) {
  26086. r[i] = a[i] - (b[i] & m);
  26087. }
  26088. #else
  26089. r[ 0] = a[ 0] - (b[ 0] & m);
  26090. r[ 1] = a[ 1] - (b[ 1] & m);
  26091. r[ 2] = a[ 2] - (b[ 2] & m);
  26092. r[ 3] = a[ 3] - (b[ 3] & m);
  26093. r[ 4] = a[ 4] - (b[ 4] & m);
  26094. r[ 5] = a[ 5] - (b[ 5] & m);
  26095. r[ 6] = a[ 6] - (b[ 6] & m);
  26096. #endif /* WOLFSSL_SP_SMALL */
  26097. }
  26098. /* Mul a by scalar b and add into r. (r += a * b)
  26099. *
  26100. * r A single precision integer.
  26101. * a A single precision integer.
  26102. * b A scalar.
  26103. */
  26104. SP_NOINLINE static void sp_384_mul_add_7(sp_digit* r, const sp_digit* a,
  26105. const sp_digit b)
  26106. {
  26107. #ifdef WOLFSSL_SP_SMALL
  26108. sp_int128 tb = b;
  26109. sp_int128 t[4];
  26110. int i;
  26111. t[0] = 0;
  26112. for (i = 0; i < 4; i += 4) {
  26113. t[0] += (tb * a[i+0]) + r[i+0];
  26114. t[1] = (tb * a[i+1]) + r[i+1];
  26115. t[2] = (tb * a[i+2]) + r[i+2];
  26116. t[3] = (tb * a[i+3]) + r[i+3];
  26117. r[i+0] = t[0] & 0x7fffffffffffffL;
  26118. t[1] += t[0] >> 55;
  26119. r[i+1] = t[1] & 0x7fffffffffffffL;
  26120. t[2] += t[1] >> 55;
  26121. r[i+2] = t[2] & 0x7fffffffffffffL;
  26122. t[3] += t[2] >> 55;
  26123. r[i+3] = t[3] & 0x7fffffffffffffL;
  26124. t[0] = t[3] >> 55;
  26125. }
  26126. t[0] += (tb * a[4]) + r[4];
  26127. t[1] = (tb * a[5]) + r[5];
  26128. t[2] = (tb * a[6]) + r[6];
  26129. r[4] = t[0] & 0x7fffffffffffffL;
  26130. t[1] += t[0] >> 55;
  26131. r[5] = t[1] & 0x7fffffffffffffL;
  26132. t[2] += t[1] >> 55;
  26133. r[6] = t[2] & 0x7fffffffffffffL;
  26134. r[7] += (sp_digit)(t[2] >> 55);
  26135. #else
  26136. sp_int128 tb = b;
  26137. sp_int128 t[7];
  26138. t[ 0] = tb * a[ 0];
  26139. t[ 1] = tb * a[ 1];
  26140. t[ 2] = tb * a[ 2];
  26141. t[ 3] = tb * a[ 3];
  26142. t[ 4] = tb * a[ 4];
  26143. t[ 5] = tb * a[ 5];
  26144. t[ 6] = tb * a[ 6];
  26145. r[ 0] += (sp_digit) (t[ 0] & 0x7fffffffffffffL);
  26146. r[ 1] += (sp_digit)((t[ 0] >> 55) + (t[ 1] & 0x7fffffffffffffL));
  26147. r[ 2] += (sp_digit)((t[ 1] >> 55) + (t[ 2] & 0x7fffffffffffffL));
  26148. r[ 3] += (sp_digit)((t[ 2] >> 55) + (t[ 3] & 0x7fffffffffffffL));
  26149. r[ 4] += (sp_digit)((t[ 3] >> 55) + (t[ 4] & 0x7fffffffffffffL));
  26150. r[ 5] += (sp_digit)((t[ 4] >> 55) + (t[ 5] & 0x7fffffffffffffL));
  26151. r[ 6] += (sp_digit)((t[ 5] >> 55) + (t[ 6] & 0x7fffffffffffffL));
  26152. r[ 7] += (sp_digit) (t[ 6] >> 55);
  26153. #endif /* WOLFSSL_SP_SMALL */
  26154. }
  26155. /* Normalize the values in each word to 55 bits.
  26156. *
  26157. * a Array of sp_digit to normalize.
  26158. */
  26159. static void sp_384_norm_7(sp_digit* a)
  26160. {
  26161. #ifdef WOLFSSL_SP_SMALL
  26162. int i;
  26163. for (i = 0; i < 6; i++) {
  26164. a[i+1] += a[i] >> 55;
  26165. a[i] &= 0x7fffffffffffffL;
  26166. }
  26167. #else
  26168. a[1] += a[0] >> 55; a[0] &= 0x7fffffffffffffL;
  26169. a[2] += a[1] >> 55; a[1] &= 0x7fffffffffffffL;
  26170. a[3] += a[2] >> 55; a[2] &= 0x7fffffffffffffL;
  26171. a[4] += a[3] >> 55; a[3] &= 0x7fffffffffffffL;
  26172. a[5] += a[4] >> 55; a[4] &= 0x7fffffffffffffL;
  26173. a[6] += a[5] >> 55; a[5] &= 0x7fffffffffffffL;
  26174. #endif /* WOLFSSL_SP_SMALL */
  26175. }
  26176. /* Shift the result in the high 384 bits down to the bottom.
  26177. *
  26178. * r A single precision number.
  26179. * a A single precision number.
  26180. */
  26181. static void sp_384_mont_shift_7(sp_digit* r, const sp_digit* a)
  26182. {
  26183. #ifdef WOLFSSL_SP_SMALL
  26184. int i;
  26185. sp_uint64 n;
  26186. n = a[6] >> 54;
  26187. for (i = 0; i < 6; i++) {
  26188. n += (sp_uint64)a[7 + i] << 1;
  26189. r[i] = n & 0x7fffffffffffffL;
  26190. n >>= 55;
  26191. }
  26192. n += (sp_uint64)a[13] << 1;
  26193. r[6] = n;
  26194. #else
  26195. sp_uint64 n;
  26196. n = a[6] >> 54;
  26197. n += (sp_uint64)a[ 7] << 1U; r[ 0] = n & 0x7fffffffffffffUL; n >>= 55U;
  26198. n += (sp_uint64)a[ 8] << 1U; r[ 1] = n & 0x7fffffffffffffUL; n >>= 55U;
  26199. n += (sp_uint64)a[ 9] << 1U; r[ 2] = n & 0x7fffffffffffffUL; n >>= 55U;
  26200. n += (sp_uint64)a[10] << 1U; r[ 3] = n & 0x7fffffffffffffUL; n >>= 55U;
  26201. n += (sp_uint64)a[11] << 1U; r[ 4] = n & 0x7fffffffffffffUL; n >>= 55U;
  26202. n += (sp_uint64)a[12] << 1U; r[ 5] = n & 0x7fffffffffffffUL; n >>= 55U;
  26203. n += (sp_uint64)a[13] << 1U; r[ 6] = n;
  26204. #endif /* WOLFSSL_SP_SMALL */
  26205. XMEMSET(&r[7], 0, sizeof(*r) * 7U);
  26206. }
  26207. /* Reduce the number back to 384 bits using Montgomery reduction.
  26208. *
  26209. * a A single precision number to reduce in place.
  26210. * m The single precision number representing the modulus.
  26211. * mp The digit representing the negative inverse of m mod 2^n.
  26212. */
  26213. static void sp_384_mont_reduce_order_7(sp_digit* a, const sp_digit* m, sp_digit mp)
  26214. {
  26215. int i;
  26216. sp_digit mu;
  26217. sp_digit over;
  26218. sp_384_norm_7(a + 7);
  26219. for (i=0; i<6; i++) {
  26220. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x7fffffffffffffL;
  26221. sp_384_mul_add_7(a+i, m, mu);
  26222. a[i+1] += a[i] >> 55;
  26223. }
  26224. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x3fffffffffffffL;
  26225. sp_384_mul_add_7(a+i, m, mu);
  26226. a[i+1] += a[i] >> 55;
  26227. a[i] &= 0x7fffffffffffffL;
  26228. sp_384_mont_shift_7(a, a);
  26229. over = a[6] >> 54;
  26230. sp_384_cond_sub_7(a, a, m, ~((over - 1) >> 63));
  26231. sp_384_norm_7(a);
  26232. }
  26233. /* Reduce the number back to 384 bits using Montgomery reduction.
  26234. *
  26235. * a A single precision number to reduce in place.
  26236. * m The single precision number representing the modulus.
  26237. * mp The digit representing the negative inverse of m mod 2^n.
  26238. */
  26239. static void sp_384_mont_reduce_7(sp_digit* a, const sp_digit* m, sp_digit mp)
  26240. {
  26241. int i;
  26242. sp_digit am;
  26243. (void)m;
  26244. (void)mp;
  26245. for (i = 0; i < 6; i++) {
  26246. am = (a[i] * 0x100000001) & 0x7fffffffffffffL;
  26247. a[i + 0] += (am << 32) & 0x7fffffffffffffL;
  26248. a[i + 1] += (am >> 23) - ((am << 41) & 0x7fffffffffffffL);
  26249. a[i + 2] += -(am >> 14) - ((am << 18) & 0x7fffffffffffffL);
  26250. a[i + 3] += -(am >> 37);
  26251. a[i + 6] += (am << 54) & 0x7fffffffffffffL;
  26252. a[i + 7] += am >> 1;
  26253. a[i + 1] += a[i] >> 55;
  26254. }
  26255. am = (a[6] * 0x100000001) & 0x3fffffffffffff;
  26256. a[6 + 0] += (am << 32) & 0x7fffffffffffffL;
  26257. a[6 + 1] += (am >> 23) - ((am << 41) & 0x7fffffffffffffL);
  26258. a[6 + 2] += -(am >> 14) - ((am << 18) & 0x7fffffffffffffL);
  26259. a[6 + 3] += -(am >> 37);
  26260. a[6 + 6] += (am << 54) & 0x7fffffffffffffL;
  26261. a[6 + 7] += am >> 1;
  26262. a[0] = (a[6] >> 54) + ((a[7] << 1) & 0x7fffffffffffffL);
  26263. a[1] = (a[7] >> 54) + ((a[8] << 1) & 0x7fffffffffffffL);
  26264. a[2] = (a[8] >> 54) + ((a[9] << 1) & 0x7fffffffffffffL);
  26265. a[3] = (a[9] >> 54) + ((a[10] << 1) & 0x7fffffffffffffL);
  26266. a[4] = (a[10] >> 54) + ((a[11] << 1) & 0x7fffffffffffffL);
  26267. a[5] = (a[11] >> 54) + ((a[12] << 1) & 0x7fffffffffffffL);
  26268. a[6] = (a[12] >> 54) + (a[13] << 1);
  26269. a[1] += a[0] >> 55; a[0] &= 0x7fffffffffffffL;
  26270. a[2] += a[1] >> 55; a[1] &= 0x7fffffffffffffL;
  26271. a[3] += a[2] >> 55; a[2] &= 0x7fffffffffffffL;
  26272. a[4] += a[3] >> 55; a[3] &= 0x7fffffffffffffL;
  26273. a[5] += a[4] >> 55; a[4] &= 0x7fffffffffffffL;
  26274. a[6] += a[5] >> 55; a[5] &= 0x7fffffffffffffL;
  26275. /* Get the bit over, if any. */
  26276. am = a[6] >> 54;
  26277. /* Create mask. */
  26278. am = 0 - am;
  26279. a[0] -= 0x00000000ffffffffL & am;
  26280. a[1] -= 0x007ffe0000000000L & am;
  26281. a[2] -= 0x007ffffffffbffffL & am;
  26282. a[3] -= 0x007fffffffffffffL & am;
  26283. a[4] -= 0x007fffffffffffffL & am;
  26284. a[5] -= 0x007fffffffffffffL & am;
  26285. a[6] -= 0x003fffffffffffffL & am;
  26286. a[1] += a[0] >> 55; a[0] &= 0x7fffffffffffffL;
  26287. a[2] += a[1] >> 55; a[1] &= 0x7fffffffffffffL;
  26288. a[3] += a[2] >> 55; a[2] &= 0x7fffffffffffffL;
  26289. a[4] += a[3] >> 55; a[3] &= 0x7fffffffffffffL;
  26290. a[5] += a[4] >> 55; a[4] &= 0x7fffffffffffffL;
  26291. a[6] += a[5] >> 55; a[5] &= 0x7fffffffffffffL;
  26292. }
  26293. /* Multiply two Montgomery form numbers mod the modulus (prime).
  26294. * (r = a * b mod m)
  26295. *
  26296. * r Result of multiplication.
  26297. * a First number to multiply in Montgomery form.
  26298. * b Second number to multiply in Montgomery form.
  26299. * m Modulus (prime).
  26300. * mp Montgomery multiplier.
  26301. */
  26302. SP_NOINLINE static void sp_384_mont_mul_7(sp_digit* r, const sp_digit* a,
  26303. const sp_digit* b, const sp_digit* m, sp_digit mp)
  26304. {
  26305. sp_384_mul_7(r, a, b);
  26306. sp_384_mont_reduce_7(r, m, mp);
  26307. }
  26308. /* Square the Montgomery form number. (r = a * a mod m)
  26309. *
  26310. * r Result of squaring.
  26311. * a Number to square in Montgomery form.
  26312. * m Modulus (prime).
  26313. * mp Montgomery multiplier.
  26314. */
  26315. SP_NOINLINE static void sp_384_mont_sqr_7(sp_digit* r, const sp_digit* a,
  26316. const sp_digit* m, sp_digit mp)
  26317. {
  26318. sp_384_sqr_7(r, a);
  26319. sp_384_mont_reduce_7(r, m, mp);
  26320. }
  26321. #if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY)
  26322. /* Square the Montgomery form number a number of times. (r = a ^ n mod m)
  26323. *
  26324. * r Result of squaring.
  26325. * a Number to square in Montgomery form.
  26326. * n Number of times to square.
  26327. * m Modulus (prime).
  26328. * mp Montgomery multiplier.
  26329. */
  26330. static void sp_384_mont_sqr_n_7(sp_digit* r, const sp_digit* a, int n,
  26331. const sp_digit* m, sp_digit mp)
  26332. {
  26333. sp_384_mont_sqr_7(r, a, m, mp);
  26334. for (; n > 1; n--) {
  26335. sp_384_mont_sqr_7(r, r, m, mp);
  26336. }
  26337. }
  26338. #endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */
  26339. #ifdef WOLFSSL_SP_SMALL
  26340. /* Mod-2 for the P384 curve. */
  26341. static const uint64_t p384_mod_minus_2[6] = {
  26342. 0x00000000fffffffdU,0xffffffff00000000U,0xfffffffffffffffeU,
  26343. 0xffffffffffffffffU,0xffffffffffffffffU,0xffffffffffffffffU
  26344. };
  26345. #endif /* !WOLFSSL_SP_SMALL */
  26346. /* Invert the number, in Montgomery form, modulo the modulus (prime) of the
  26347. * P384 curve. (r = 1 / a mod m)
  26348. *
  26349. * r Inverse result.
  26350. * a Number to invert.
  26351. * td Temporary data.
  26352. */
  26353. static void sp_384_mont_inv_7(sp_digit* r, const sp_digit* a, sp_digit* td)
  26354. {
  26355. #ifdef WOLFSSL_SP_SMALL
  26356. sp_digit* t = td;
  26357. int i;
  26358. XMEMCPY(t, a, sizeof(sp_digit) * 7);
  26359. for (i=382; i>=0; i--) {
  26360. sp_384_mont_sqr_7(t, t, p384_mod, p384_mp_mod);
  26361. if (p384_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
  26362. sp_384_mont_mul_7(t, t, a, p384_mod, p384_mp_mod);
  26363. }
  26364. XMEMCPY(r, t, sizeof(sp_digit) * 7);
  26365. #else
  26366. sp_digit* t1 = td;
  26367. sp_digit* t2 = td + 2 * 7;
  26368. sp_digit* t3 = td + 4 * 7;
  26369. sp_digit* t4 = td + 6 * 7;
  26370. sp_digit* t5 = td + 8 * 7;
  26371. /* 0x2 */
  26372. sp_384_mont_sqr_7(t1, a, p384_mod, p384_mp_mod);
  26373. /* 0x3 */
  26374. sp_384_mont_mul_7(t5, t1, a, p384_mod, p384_mp_mod);
  26375. /* 0xc */
  26376. sp_384_mont_sqr_n_7(t1, t5, 2, p384_mod, p384_mp_mod);
  26377. /* 0xf */
  26378. sp_384_mont_mul_7(t2, t5, t1, p384_mod, p384_mp_mod);
  26379. /* 0x1e */
  26380. sp_384_mont_sqr_7(t1, t2, p384_mod, p384_mp_mod);
  26381. /* 0x1f */
  26382. sp_384_mont_mul_7(t4, t1, a, p384_mod, p384_mp_mod);
  26383. /* 0x3e0 */
  26384. sp_384_mont_sqr_n_7(t1, t4, 5, p384_mod, p384_mp_mod);
  26385. /* 0x3ff */
  26386. sp_384_mont_mul_7(t2, t4, t1, p384_mod, p384_mp_mod);
  26387. /* 0x7fe0 */
  26388. sp_384_mont_sqr_n_7(t1, t2, 5, p384_mod, p384_mp_mod);
  26389. /* 0x7fff */
  26390. sp_384_mont_mul_7(t4, t4, t1, p384_mod, p384_mp_mod);
  26391. /* 0x3fff8000 */
  26392. sp_384_mont_sqr_n_7(t1, t4, 15, p384_mod, p384_mp_mod);
  26393. /* 0x3fffffff */
  26394. sp_384_mont_mul_7(t2, t4, t1, p384_mod, p384_mp_mod);
  26395. /* 0xfffffffc */
  26396. sp_384_mont_sqr_n_7(t3, t2, 2, p384_mod, p384_mp_mod);
  26397. /* 0xfffffffd */
  26398. sp_384_mont_mul_7(r, t3, a, p384_mod, p384_mp_mod);
  26399. /* 0xffffffff */
  26400. sp_384_mont_mul_7(t3, t5, t3, p384_mod, p384_mp_mod);
  26401. /* 0xfffffffc0000000 */
  26402. sp_384_mont_sqr_n_7(t1, t2, 30, p384_mod, p384_mp_mod);
  26403. /* 0xfffffffffffffff */
  26404. sp_384_mont_mul_7(t2, t2, t1, p384_mod, p384_mp_mod);
  26405. /* 0xfffffffffffffff000000000000000 */
  26406. sp_384_mont_sqr_n_7(t1, t2, 60, p384_mod, p384_mp_mod);
  26407. /* 0xffffffffffffffffffffffffffffff */
  26408. sp_384_mont_mul_7(t2, t2, t1, p384_mod, p384_mp_mod);
  26409. /* 0xffffffffffffffffffffffffffffff000000000000000000000000000000 */
  26410. sp_384_mont_sqr_n_7(t1, t2, 120, p384_mod, p384_mp_mod);
  26411. /* 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
  26412. sp_384_mont_mul_7(t2, t2, t1, p384_mod, p384_mp_mod);
  26413. /* 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000 */
  26414. sp_384_mont_sqr_n_7(t1, t2, 15, p384_mod, p384_mp_mod);
  26415. /* 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
  26416. sp_384_mont_mul_7(t2, t4, t1, p384_mod, p384_mp_mod);
  26417. /* 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00000000 */
  26418. sp_384_mont_sqr_n_7(t1, t2, 33, p384_mod, p384_mp_mod);
  26419. /* 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff */
  26420. sp_384_mont_mul_7(t2, t3, t1, p384_mod, p384_mp_mod);
  26421. /* 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff000000000000000000000000 */
  26422. sp_384_mont_sqr_n_7(t1, t2, 96, p384_mod, p384_mp_mod);
  26423. /* 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffd */
  26424. sp_384_mont_mul_7(r, r, t1, p384_mod, p384_mp_mod);
  26425. #endif /* WOLFSSL_SP_SMALL */
  26426. }
  26427. /* Map the Montgomery form projective coordinate point to an affine point.
  26428. *
  26429. * r Resulting affine coordinate point.
  26430. * p Montgomery form projective coordinate point.
  26431. * t Temporary ordinate data.
  26432. */
  26433. static void sp_384_map_7(sp_point_384* r, const sp_point_384* p,
  26434. sp_digit* t)
  26435. {
  26436. sp_digit* t1 = t;
  26437. sp_digit* t2 = t + 2*7;
  26438. sp_int64 n;
  26439. sp_384_mont_inv_7(t1, p->z, t + 2*7);
  26440. sp_384_mont_sqr_7(t2, t1, p384_mod, p384_mp_mod);
  26441. sp_384_mont_mul_7(t1, t2, t1, p384_mod, p384_mp_mod);
  26442. /* x /= z^2 */
  26443. sp_384_mont_mul_7(r->x, p->x, t2, p384_mod, p384_mp_mod);
  26444. XMEMSET(r->x + 7, 0, sizeof(sp_digit) * 7U);
  26445. sp_384_mont_reduce_7(r->x, p384_mod, p384_mp_mod);
  26446. /* Reduce x to less than modulus */
  26447. n = sp_384_cmp_7(r->x, p384_mod);
  26448. sp_384_cond_sub_7(r->x, r->x, p384_mod, ~(n >> 54));
  26449. sp_384_norm_7(r->x);
  26450. /* y /= z^3 */
  26451. sp_384_mont_mul_7(r->y, p->y, t1, p384_mod, p384_mp_mod);
  26452. XMEMSET(r->y + 7, 0, sizeof(sp_digit) * 7U);
  26453. sp_384_mont_reduce_7(r->y, p384_mod, p384_mp_mod);
  26454. /* Reduce y to less than modulus */
  26455. n = sp_384_cmp_7(r->y, p384_mod);
  26456. sp_384_cond_sub_7(r->y, r->y, p384_mod, ~(n >> 54));
  26457. sp_384_norm_7(r->y);
  26458. XMEMSET(r->z, 0, sizeof(r->z) / 2);
  26459. r->z[0] = 1;
  26460. }
  26461. /* Add two Montgomery form numbers (r = a + b % m).
  26462. *
  26463. * r Result of addition.
  26464. * a First number to add in Montgomery form.
  26465. * b Second number to add in Montgomery form.
  26466. * m Modulus (prime).
  26467. */
  26468. static void sp_384_mont_add_7(sp_digit* r, const sp_digit* a, const sp_digit* b,
  26469. const sp_digit* m)
  26470. {
  26471. sp_digit over;
  26472. (void)sp_384_add_7(r, a, b);
  26473. sp_384_norm_7(r);
  26474. over = r[6] >> 54;
  26475. sp_384_cond_sub_7(r, r, m, ~((over - 1) >> 63));
  26476. sp_384_norm_7(r);
  26477. }
  26478. /* Double a Montgomery form number (r = a + a % m).
  26479. *
  26480. * r Result of doubling.
  26481. * a Number to double in Montgomery form.
  26482. * m Modulus (prime).
  26483. */
  26484. static void sp_384_mont_dbl_7(sp_digit* r, const sp_digit* a, const sp_digit* m)
  26485. {
  26486. sp_digit over;
  26487. (void)sp_384_add_7(r, a, a);
  26488. sp_384_norm_7(r);
  26489. over = r[6] >> 54;
  26490. sp_384_cond_sub_7(r, r, m, ~((over - 1) >> 63));
  26491. sp_384_norm_7(r);
  26492. }
  26493. /* Triple a Montgomery form number (r = a + a + a % m).
  26494. *
  26495. * r Result of Tripling.
  26496. * a Number to triple in Montgomery form.
  26497. * m Modulus (prime).
  26498. */
  26499. static void sp_384_mont_tpl_7(sp_digit* r, const sp_digit* a, const sp_digit* m)
  26500. {
  26501. sp_digit over;
  26502. (void)sp_384_add_7(r, a, a);
  26503. sp_384_norm_7(r);
  26504. over = r[6] >> 54;
  26505. sp_384_cond_sub_7(r, r, m, ~((over - 1) >> 63));
  26506. sp_384_norm_7(r);
  26507. (void)sp_384_add_7(r, r, a);
  26508. sp_384_norm_7(r);
  26509. over = r[6] >> 54;
  26510. sp_384_cond_sub_7(r, r, m, ~((over - 1) >> 63));
  26511. sp_384_norm_7(r);
  26512. }
  26513. #ifdef WOLFSSL_SP_SMALL
  26514. /* Conditionally add a and b using the mask m.
  26515. * m is -1 to add and 0 when not.
  26516. *
  26517. * r A single precision number representing conditional add result.
  26518. * a A single precision number to add with.
  26519. * b A single precision number to add.
  26520. * m Mask value to apply.
  26521. */
  26522. static void sp_384_cond_add_7(sp_digit* r, const sp_digit* a,
  26523. const sp_digit* b, const sp_digit m)
  26524. {
  26525. int i;
  26526. for (i = 0; i < 7; i++) {
  26527. r[i] = a[i] + (b[i] & m);
  26528. }
  26529. }
  26530. #endif /* WOLFSSL_SP_SMALL */
  26531. #ifndef WOLFSSL_SP_SMALL
  26532. /* Conditionally add a and b using the mask m.
  26533. * m is -1 to add and 0 when not.
  26534. *
  26535. * r A single precision number representing conditional add result.
  26536. * a A single precision number to add with.
  26537. * b A single precision number to add.
  26538. * m Mask value to apply.
  26539. */
  26540. static void sp_384_cond_add_7(sp_digit* r, const sp_digit* a,
  26541. const sp_digit* b, const sp_digit m)
  26542. {
  26543. r[ 0] = a[ 0] + (b[ 0] & m);
  26544. r[ 1] = a[ 1] + (b[ 1] & m);
  26545. r[ 2] = a[ 2] + (b[ 2] & m);
  26546. r[ 3] = a[ 3] + (b[ 3] & m);
  26547. r[ 4] = a[ 4] + (b[ 4] & m);
  26548. r[ 5] = a[ 5] + (b[ 5] & m);
  26549. r[ 6] = a[ 6] + (b[ 6] & m);
  26550. }
  26551. #endif /* !WOLFSSL_SP_SMALL */
  26552. /* Subtract two Montgomery form numbers (r = a - b % m).
  26553. *
  26554. * r Result of subtration.
  26555. * a Number to subtract from in Montgomery form.
  26556. * b Number to subtract with in Montgomery form.
  26557. * m Modulus (prime).
  26558. */
  26559. static void sp_384_mont_sub_7(sp_digit* r, const sp_digit* a, const sp_digit* b,
  26560. const sp_digit* m)
  26561. {
  26562. (void)sp_384_sub_7(r, a, b);
  26563. sp_384_norm_7(r);
  26564. sp_384_cond_add_7(r, r, m, r[6] >> 54);
  26565. sp_384_norm_7(r);
  26566. }
  26567. /* Shift number left one bit.
  26568. * Bottom bit is lost.
  26569. *
  26570. * r Result of shift.
  26571. * a Number to shift.
  26572. */
  26573. SP_NOINLINE static void sp_384_rshift1_7(sp_digit* r, const sp_digit* a)
  26574. {
  26575. #ifdef WOLFSSL_SP_SMALL
  26576. int i;
  26577. for (i=0; i<6; i++) {
  26578. r[i] = (a[i] >> 1) + ((a[i + 1] << 54) & 0x7fffffffffffffL);
  26579. }
  26580. #else
  26581. r[0] = (a[0] >> 1) + ((a[1] << 54) & 0x7fffffffffffffL);
  26582. r[1] = (a[1] >> 1) + ((a[2] << 54) & 0x7fffffffffffffL);
  26583. r[2] = (a[2] >> 1) + ((a[3] << 54) & 0x7fffffffffffffL);
  26584. r[3] = (a[3] >> 1) + ((a[4] << 54) & 0x7fffffffffffffL);
  26585. r[4] = (a[4] >> 1) + ((a[5] << 54) & 0x7fffffffffffffL);
  26586. r[5] = (a[5] >> 1) + ((a[6] << 54) & 0x7fffffffffffffL);
  26587. #endif
  26588. r[6] = a[6] >> 1;
  26589. }
  26590. /* Divide the number by 2 mod the modulus (prime). (r = a / 2 % m)
  26591. *
  26592. * r Result of division by 2.
  26593. * a Number to divide.
  26594. * m Modulus (prime).
  26595. */
  26596. static void sp_384_mont_div2_7(sp_digit* r, const sp_digit* a,
  26597. const sp_digit* m)
  26598. {
  26599. sp_384_cond_add_7(r, a, m, 0 - (a[0] & 1));
  26600. sp_384_norm_7(r);
  26601. sp_384_rshift1_7(r, r);
  26602. }
  26603. /* Double the Montgomery form projective point p.
  26604. *
  26605. * r Result of doubling point.
  26606. * p Point to double.
  26607. * t Temporary ordinate data.
  26608. */
  26609. static void sp_384_proj_point_dbl_7(sp_point_384* r, const sp_point_384* p,
  26610. sp_digit* t)
  26611. {
  26612. sp_digit* t1 = t;
  26613. sp_digit* t2 = t + 2*7;
  26614. sp_digit* x;
  26615. sp_digit* y;
  26616. sp_digit* z;
  26617. x = r->x;
  26618. y = r->y;
  26619. z = r->z;
  26620. /* Put infinity into result. */
  26621. if (r != p) {
  26622. r->infinity = p->infinity;
  26623. }
  26624. /* T1 = Z * Z */
  26625. sp_384_mont_sqr_7(t1, p->z, p384_mod, p384_mp_mod);
  26626. /* Z = Y * Z */
  26627. sp_384_mont_mul_7(z, p->y, p->z, p384_mod, p384_mp_mod);
  26628. /* Z = 2Z */
  26629. sp_384_mont_dbl_7(z, z, p384_mod);
  26630. /* T2 = X - T1 */
  26631. sp_384_mont_sub_7(t2, p->x, t1, p384_mod);
  26632. /* T1 = X + T1 */
  26633. sp_384_mont_add_7(t1, p->x, t1, p384_mod);
  26634. /* T2 = T1 * T2 */
  26635. sp_384_mont_mul_7(t2, t1, t2, p384_mod, p384_mp_mod);
  26636. /* T1 = 3T2 */
  26637. sp_384_mont_tpl_7(t1, t2, p384_mod);
  26638. /* Y = 2Y */
  26639. sp_384_mont_dbl_7(y, p->y, p384_mod);
  26640. /* Y = Y * Y */
  26641. sp_384_mont_sqr_7(y, y, p384_mod, p384_mp_mod);
  26642. /* T2 = Y * Y */
  26643. sp_384_mont_sqr_7(t2, y, p384_mod, p384_mp_mod);
  26644. /* T2 = T2/2 */
  26645. sp_384_mont_div2_7(t2, t2, p384_mod);
  26646. /* Y = Y * X */
  26647. sp_384_mont_mul_7(y, y, p->x, p384_mod, p384_mp_mod);
  26648. /* X = T1 * T1 */
  26649. sp_384_mont_sqr_7(x, t1, p384_mod, p384_mp_mod);
  26650. /* X = X - Y */
  26651. sp_384_mont_sub_7(x, x, y, p384_mod);
  26652. /* X = X - Y */
  26653. sp_384_mont_sub_7(x, x, y, p384_mod);
  26654. /* Y = Y - X */
  26655. sp_384_mont_sub_7(y, y, x, p384_mod);
  26656. /* Y = Y * T1 */
  26657. sp_384_mont_mul_7(y, y, t1, p384_mod, p384_mp_mod);
  26658. /* Y = Y - T2 */
  26659. sp_384_mont_sub_7(y, y, t2, p384_mod);
  26660. }
  26661. #ifdef WOLFSSL_SP_NONBLOCK
  26662. typedef struct sp_384_proj_point_dbl_7_ctx {
  26663. int state;
  26664. sp_digit* t1;
  26665. sp_digit* t2;
  26666. sp_digit* x;
  26667. sp_digit* y;
  26668. sp_digit* z;
  26669. } sp_384_proj_point_dbl_7_ctx;
  26670. /* Double the Montgomery form projective point p.
  26671. *
  26672. * r Result of doubling point.
  26673. * p Point to double.
  26674. * t Temporary ordinate data.
  26675. */
  26676. static int sp_384_proj_point_dbl_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
  26677. const sp_point_384* p, sp_digit* t)
  26678. {
  26679. int err = FP_WOULDBLOCK;
  26680. sp_384_proj_point_dbl_7_ctx* ctx = (sp_384_proj_point_dbl_7_ctx*)sp_ctx->data;
  26681. typedef char ctx_size_test[sizeof(sp_384_proj_point_dbl_7_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  26682. (void)sizeof(ctx_size_test);
  26683. switch (ctx->state) {
  26684. case 0:
  26685. ctx->t1 = t;
  26686. ctx->t2 = t + 2*7;
  26687. ctx->x = r->x;
  26688. ctx->y = r->y;
  26689. ctx->z = r->z;
  26690. /* Put infinity into result. */
  26691. if (r != p) {
  26692. r->infinity = p->infinity;
  26693. }
  26694. ctx->state = 1;
  26695. break;
  26696. case 1:
  26697. /* T1 = Z * Z */
  26698. sp_384_mont_sqr_7(ctx->t1, p->z, p384_mod, p384_mp_mod);
  26699. ctx->state = 2;
  26700. break;
  26701. case 2:
  26702. /* Z = Y * Z */
  26703. sp_384_mont_mul_7(ctx->z, p->y, p->z, p384_mod, p384_mp_mod);
  26704. ctx->state = 3;
  26705. break;
  26706. case 3:
  26707. /* Z = 2Z */
  26708. sp_384_mont_dbl_7(ctx->z, ctx->z, p384_mod);
  26709. ctx->state = 4;
  26710. break;
  26711. case 4:
  26712. /* T2 = X - T1 */
  26713. sp_384_mont_sub_7(ctx->t2, p->x, ctx->t1, p384_mod);
  26714. ctx->state = 5;
  26715. break;
  26716. case 5:
  26717. /* T1 = X + T1 */
  26718. sp_384_mont_add_7(ctx->t1, p->x, ctx->t1, p384_mod);
  26719. ctx->state = 6;
  26720. break;
  26721. case 6:
  26722. /* T2 = T1 * T2 */
  26723. sp_384_mont_mul_7(ctx->t2, ctx->t1, ctx->t2, p384_mod, p384_mp_mod);
  26724. ctx->state = 7;
  26725. break;
  26726. case 7:
  26727. /* T1 = 3T2 */
  26728. sp_384_mont_tpl_7(ctx->t1, ctx->t2, p384_mod);
  26729. ctx->state = 8;
  26730. break;
  26731. case 8:
  26732. /* Y = 2Y */
  26733. sp_384_mont_dbl_7(ctx->y, p->y, p384_mod);
  26734. ctx->state = 9;
  26735. break;
  26736. case 9:
  26737. /* Y = Y * Y */
  26738. sp_384_mont_sqr_7(ctx->y, ctx->y, p384_mod, p384_mp_mod);
  26739. ctx->state = 10;
  26740. break;
  26741. case 10:
  26742. /* T2 = Y * Y */
  26743. sp_384_mont_sqr_7(ctx->t2, ctx->y, p384_mod, p384_mp_mod);
  26744. ctx->state = 11;
  26745. break;
  26746. case 11:
  26747. /* T2 = T2/2 */
  26748. sp_384_mont_div2_7(ctx->t2, ctx->t2, p384_mod);
  26749. ctx->state = 12;
  26750. break;
  26751. case 12:
  26752. /* Y = Y * X */
  26753. sp_384_mont_mul_7(ctx->y, ctx->y, p->x, p384_mod, p384_mp_mod);
  26754. ctx->state = 13;
  26755. break;
  26756. case 13:
  26757. /* X = T1 * T1 */
  26758. sp_384_mont_sqr_7(ctx->x, ctx->t1, p384_mod, p384_mp_mod);
  26759. ctx->state = 14;
  26760. break;
  26761. case 14:
  26762. /* X = X - Y */
  26763. sp_384_mont_sub_7(ctx->x, ctx->x, ctx->y, p384_mod);
  26764. ctx->state = 15;
  26765. break;
  26766. case 15:
  26767. /* X = X - Y */
  26768. sp_384_mont_sub_7(ctx->x, ctx->x, ctx->y, p384_mod);
  26769. ctx->state = 16;
  26770. break;
  26771. case 16:
  26772. /* Y = Y - X */
  26773. sp_384_mont_sub_7(ctx->y, ctx->y, ctx->x, p384_mod);
  26774. ctx->state = 17;
  26775. break;
  26776. case 17:
  26777. /* Y = Y * T1 */
  26778. sp_384_mont_mul_7(ctx->y, ctx->y, ctx->t1, p384_mod, p384_mp_mod);
  26779. ctx->state = 18;
  26780. break;
  26781. case 18:
  26782. /* Y = Y - T2 */
  26783. sp_384_mont_sub_7(ctx->y, ctx->y, ctx->t2, p384_mod);
  26784. ctx->state = 19;
  26785. /* fall-through */
  26786. case 19:
  26787. err = MP_OKAY;
  26788. break;
  26789. }
  26790. if (err == MP_OKAY && ctx->state != 19) {
  26791. err = FP_WOULDBLOCK;
  26792. }
  26793. return err;
  26794. }
  26795. #endif /* WOLFSSL_SP_NONBLOCK */
  26796. /* Compare two numbers to determine if they are equal.
  26797. * Constant time implementation.
  26798. *
  26799. * a First number to compare.
  26800. * b Second number to compare.
  26801. * returns 1 when equal and 0 otherwise.
  26802. */
  26803. static int sp_384_cmp_equal_7(const sp_digit* a, const sp_digit* b)
  26804. {
  26805. return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) |
  26806. (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) |
  26807. (a[6] ^ b[6])) == 0;
  26808. }
  26809. /* Returns 1 if the number of zero.
  26810. * Implementation is constant time.
  26811. *
  26812. * a Number to check.
  26813. * returns 1 if the number is zero and 0 otherwise.
  26814. */
  26815. static int sp_384_iszero_7(const sp_digit* a)
  26816. {
  26817. return (a[0] | a[1] | a[2] | a[3] | a[4] | a[5] | a[6]) == 0;
  26818. }
  26819. /* Add two Montgomery form projective points.
  26820. *
  26821. * r Result of addition.
  26822. * p First point to add.
  26823. * q Second point to add.
  26824. * t Temporary ordinate data.
  26825. */
  26826. static void sp_384_proj_point_add_7(sp_point_384* r,
  26827. const sp_point_384* p, const sp_point_384* q, sp_digit* t)
  26828. {
  26829. sp_digit* t6 = t;
  26830. sp_digit* t1 = t + 2*7;
  26831. sp_digit* t2 = t + 4*7;
  26832. sp_digit* t3 = t + 6*7;
  26833. sp_digit* t4 = t + 8*7;
  26834. sp_digit* t5 = t + 10*7;
  26835. /* U1 = X1*Z2^2 */
  26836. sp_384_mont_sqr_7(t1, q->z, p384_mod, p384_mp_mod);
  26837. sp_384_mont_mul_7(t3, t1, q->z, p384_mod, p384_mp_mod);
  26838. sp_384_mont_mul_7(t1, t1, p->x, p384_mod, p384_mp_mod);
  26839. /* U2 = X2*Z1^2 */
  26840. sp_384_mont_sqr_7(t2, p->z, p384_mod, p384_mp_mod);
  26841. sp_384_mont_mul_7(t4, t2, p->z, p384_mod, p384_mp_mod);
  26842. sp_384_mont_mul_7(t2, t2, q->x, p384_mod, p384_mp_mod);
  26843. /* S1 = Y1*Z2^3 */
  26844. sp_384_mont_mul_7(t3, t3, p->y, p384_mod, p384_mp_mod);
  26845. /* S2 = Y2*Z1^3 */
  26846. sp_384_mont_mul_7(t4, t4, q->y, p384_mod, p384_mp_mod);
  26847. /* Check double */
  26848. if ((~p->infinity) & (~q->infinity) &
  26849. sp_384_cmp_equal_7(t2, t1) &
  26850. sp_384_cmp_equal_7(t4, t3)) {
  26851. sp_384_proj_point_dbl_7(r, p, t);
  26852. }
  26853. else {
  26854. sp_digit* x = t6;
  26855. sp_digit* y = t1;
  26856. sp_digit* z = t2;
  26857. /* H = U2 - U1 */
  26858. sp_384_mont_sub_7(t2, t2, t1, p384_mod);
  26859. /* R = S2 - S1 */
  26860. sp_384_mont_sub_7(t4, t4, t3, p384_mod);
  26861. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  26862. sp_384_mont_sqr_7(t5, t2, p384_mod, p384_mp_mod);
  26863. sp_384_mont_mul_7(y, t1, t5, p384_mod, p384_mp_mod);
  26864. sp_384_mont_mul_7(t5, t5, t2, p384_mod, p384_mp_mod);
  26865. /* Z3 = H*Z1*Z2 */
  26866. sp_384_mont_mul_7(z, p->z, t2, p384_mod, p384_mp_mod);
  26867. sp_384_mont_mul_7(z, z, q->z, p384_mod, p384_mp_mod);
  26868. sp_384_mont_sqr_7(x, t4, p384_mod, p384_mp_mod);
  26869. sp_384_mont_sub_7(x, x, t5, p384_mod);
  26870. sp_384_mont_mul_7(t5, t5, t3, p384_mod, p384_mp_mod);
  26871. sp_384_mont_dbl_7(t3, y, p384_mod);
  26872. sp_384_mont_sub_7(x, x, t3, p384_mod);
  26873. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  26874. sp_384_mont_sub_7(y, y, x, p384_mod);
  26875. sp_384_mont_mul_7(y, y, t4, p384_mod, p384_mp_mod);
  26876. sp_384_mont_sub_7(y, y, t5, p384_mod);
  26877. {
  26878. int i;
  26879. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  26880. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  26881. sp_digit maskt = ~(maskp | maskq);
  26882. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  26883. for (i = 0; i < 7; i++) {
  26884. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  26885. (x[i] & maskt);
  26886. }
  26887. for (i = 0; i < 7; i++) {
  26888. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  26889. (y[i] & maskt);
  26890. }
  26891. for (i = 0; i < 7; i++) {
  26892. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  26893. (z[i] & maskt);
  26894. }
  26895. r->z[0] |= inf;
  26896. r->infinity = (word32)inf;
  26897. }
  26898. }
  26899. }
  26900. #ifdef WOLFSSL_SP_NONBLOCK
  26901. typedef struct sp_384_proj_point_add_7_ctx {
  26902. int state;
  26903. sp_384_proj_point_dbl_7_ctx dbl_ctx;
  26904. const sp_point_384* ap[2];
  26905. sp_point_384* rp[2];
  26906. sp_digit* t1;
  26907. sp_digit* t2;
  26908. sp_digit* t3;
  26909. sp_digit* t4;
  26910. sp_digit* t5;
  26911. sp_digit* t6;
  26912. sp_digit* x;
  26913. sp_digit* y;
  26914. sp_digit* z;
  26915. } sp_384_proj_point_add_7_ctx;
  26916. /* Add two Montgomery form projective points.
  26917. *
  26918. * r Result of addition.
  26919. * p First point to add.
  26920. * q Second point to add.
  26921. * t Temporary ordinate data.
  26922. */
  26923. static int sp_384_proj_point_add_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
  26924. const sp_point_384* p, const sp_point_384* q, sp_digit* t)
  26925. {
  26926. int err = FP_WOULDBLOCK;
  26927. sp_384_proj_point_add_7_ctx* ctx = (sp_384_proj_point_add_7_ctx*)sp_ctx->data;
  26928. /* Ensure only the first point is the same as the result. */
  26929. if (q == r) {
  26930. const sp_point_384* a = p;
  26931. p = q;
  26932. q = a;
  26933. }
  26934. typedef char ctx_size_test[sizeof(sp_384_proj_point_add_7_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  26935. (void)sizeof(ctx_size_test);
  26936. switch (ctx->state) {
  26937. case 0: /* INIT */
  26938. ctx->t6 = t;
  26939. ctx->t1 = t + 2*7;
  26940. ctx->t2 = t + 4*7;
  26941. ctx->t3 = t + 6*7;
  26942. ctx->t4 = t + 8*7;
  26943. ctx->t5 = t + 10*7;
  26944. ctx->x = ctx->t6;
  26945. ctx->y = ctx->t1;
  26946. ctx->z = ctx->t2;
  26947. ctx->state = 1;
  26948. break;
  26949. case 1:
  26950. /* U1 = X1*Z2^2 */
  26951. sp_384_mont_sqr_7(ctx->t1, q->z, p384_mod, p384_mp_mod);
  26952. ctx->state = 2;
  26953. break;
  26954. case 2:
  26955. sp_384_mont_mul_7(ctx->t3, ctx->t1, q->z, p384_mod, p384_mp_mod);
  26956. ctx->state = 3;
  26957. break;
  26958. case 3:
  26959. sp_384_mont_mul_7(ctx->t1, ctx->t1, p->x, p384_mod, p384_mp_mod);
  26960. ctx->state = 4;
  26961. break;
  26962. case 4:
  26963. /* U2 = X2*Z1^2 */
  26964. sp_384_mont_sqr_7(ctx->t2, p->z, p384_mod, p384_mp_mod);
  26965. ctx->state = 5;
  26966. break;
  26967. case 5:
  26968. sp_384_mont_mul_7(ctx->t4, ctx->t2, p->z, p384_mod, p384_mp_mod);
  26969. ctx->state = 6;
  26970. break;
  26971. case 6:
  26972. sp_384_mont_mul_7(ctx->t2, ctx->t2, q->x, p384_mod, p384_mp_mod);
  26973. ctx->state = 7;
  26974. break;
  26975. case 7:
  26976. /* S1 = Y1*Z2^3 */
  26977. sp_384_mont_mul_7(ctx->t3, ctx->t3, p->y, p384_mod, p384_mp_mod);
  26978. ctx->state = 8;
  26979. break;
  26980. case 8:
  26981. /* S2 = Y2*Z1^3 */
  26982. sp_384_mont_mul_7(ctx->t4, ctx->t4, q->y, p384_mod, p384_mp_mod);
  26983. ctx->state = 9;
  26984. break;
  26985. case 9:
  26986. /* Check double */
  26987. if ((~p->infinity) & (~q->infinity) &
  26988. sp_384_cmp_equal_7(ctx->t2, ctx->t1) &
  26989. sp_384_cmp_equal_7(ctx->t4, ctx->t3)) {
  26990. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  26991. sp_384_proj_point_dbl_7(r, p, t);
  26992. ctx->state = 25;
  26993. }
  26994. else {
  26995. ctx->state = 10;
  26996. }
  26997. break;
  26998. case 10:
  26999. /* H = U2 - U1 */
  27000. sp_384_mont_sub_7(ctx->t2, ctx->t2, ctx->t1, p384_mod);
  27001. ctx->state = 11;
  27002. break;
  27003. case 11:
  27004. /* R = S2 - S1 */
  27005. sp_384_mont_sub_7(ctx->t4, ctx->t4, ctx->t3, p384_mod);
  27006. ctx->state = 12;
  27007. break;
  27008. case 12:
  27009. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  27010. sp_384_mont_sqr_7(ctx->t5, ctx->t2, p384_mod, p384_mp_mod);
  27011. ctx->state = 13;
  27012. break;
  27013. case 13:
  27014. sp_384_mont_mul_7(ctx->y, ctx->t1, ctx->t5, p384_mod, p384_mp_mod);
  27015. ctx->state = 14;
  27016. break;
  27017. case 14:
  27018. sp_384_mont_mul_7(ctx->t5, ctx->t5, ctx->t2, p384_mod, p384_mp_mod);
  27019. ctx->state = 15;
  27020. break;
  27021. case 15:
  27022. /* Z3 = H*Z1*Z2 */
  27023. sp_384_mont_mul_7(ctx->z, p->z, ctx->t2, p384_mod, p384_mp_mod);
  27024. ctx->state = 16;
  27025. break;
  27026. case 16:
  27027. sp_384_mont_mul_7(ctx->z, ctx->z, q->z, p384_mod, p384_mp_mod);
  27028. ctx->state = 17;
  27029. break;
  27030. case 17:
  27031. sp_384_mont_sqr_7(ctx->x, ctx->t4, p384_mod, p384_mp_mod);
  27032. ctx->state = 18;
  27033. break;
  27034. case 18:
  27035. sp_384_mont_sub_7(ctx->x, ctx->x, ctx->t5, p384_mod);
  27036. ctx->state = 19;
  27037. break;
  27038. case 19:
  27039. sp_384_mont_mul_7(ctx->t5, ctx->t5, ctx->t3, p384_mod, p384_mp_mod);
  27040. ctx->state = 20;
  27041. break;
  27042. case 20:
  27043. sp_384_mont_dbl_7(ctx->t3, ctx->y, p384_mod);
  27044. sp_384_mont_sub_7(ctx->x, ctx->x, ctx->t3, p384_mod);
  27045. ctx->state = 21;
  27046. break;
  27047. case 21:
  27048. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  27049. sp_384_mont_sub_7(ctx->y, ctx->y, ctx->x, p384_mod);
  27050. ctx->state = 22;
  27051. break;
  27052. case 22:
  27053. sp_384_mont_mul_7(ctx->y, ctx->y, ctx->t4, p384_mod, p384_mp_mod);
  27054. ctx->state = 23;
  27055. break;
  27056. case 23:
  27057. sp_384_mont_sub_7(ctx->y, ctx->y, ctx->t5, p384_mod);
  27058. ctx->state = 24;
  27059. break;
  27060. case 24:
  27061. {
  27062. {
  27063. int i;
  27064. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  27065. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  27066. sp_digit maskt = ~(maskp | maskq);
  27067. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  27068. for (i = 0; i < 7; i++) {
  27069. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  27070. (ctx->x[i] & maskt);
  27071. }
  27072. for (i = 0; i < 7; i++) {
  27073. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  27074. (ctx->y[i] & maskt);
  27075. }
  27076. for (i = 0; i < 7; i++) {
  27077. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  27078. (ctx->z[i] & maskt);
  27079. }
  27080. r->z[0] |= inf;
  27081. r->infinity = (word32)inf;
  27082. }
  27083. ctx->state = 25;
  27084. break;
  27085. }
  27086. case 25:
  27087. err = MP_OKAY;
  27088. break;
  27089. }
  27090. if (err == MP_OKAY && ctx->state != 25) {
  27091. err = FP_WOULDBLOCK;
  27092. }
  27093. return err;
  27094. }
  27095. #endif /* WOLFSSL_SP_NONBLOCK */
  27096. /* Multiply a number by Montgomery normalizer mod modulus (prime).
  27097. *
  27098. * r The resulting Montgomery form number.
  27099. * a The number to convert.
  27100. * m The modulus (prime).
  27101. * returns MEMORY_E when memory allocation fails and MP_OKAY otherwise.
  27102. */
  27103. static int sp_384_mod_mul_norm_7(sp_digit* r, const sp_digit* a, const sp_digit* m)
  27104. {
  27105. #ifdef WOLFSSL_SP_SMALL_STACK
  27106. int64_t* t = NULL;
  27107. #else
  27108. int64_t t[2 * 12];
  27109. #endif
  27110. int64_t* a32 = NULL;
  27111. int64_t o;
  27112. int err = MP_OKAY;
  27113. (void)m;
  27114. #ifdef WOLFSSL_SP_SMALL_STACK
  27115. t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 12, NULL, DYNAMIC_TYPE_ECC);
  27116. if (t == NULL)
  27117. err = MEMORY_E;
  27118. #endif
  27119. if (err == MP_OKAY) {
  27120. a32 = t + 12;
  27121. a32[0] = (sp_digit)(a[0]) & 0xffffffffL;
  27122. a32[1] = (sp_digit)(a[0] >> 32U);
  27123. a32[1] |= (sp_digit)(a[1] << 23U);
  27124. a32[1] &= 0xffffffffL;
  27125. a32[2] = (sp_digit)(a[1] >> 9U) & 0xffffffffL;
  27126. a32[3] = (sp_digit)(a[1] >> 41U);
  27127. a32[3] |= (sp_digit)(a[2] << 14U);
  27128. a32[3] &= 0xffffffffL;
  27129. a32[4] = (sp_digit)(a[2] >> 18U) & 0xffffffffL;
  27130. a32[5] = (sp_digit)(a[2] >> 50U);
  27131. a32[5] |= (sp_digit)(a[3] << 5U);
  27132. a32[5] &= 0xffffffffL;
  27133. a32[6] = (sp_digit)(a[3] >> 27U);
  27134. a32[6] |= (sp_digit)(a[4] << 28U);
  27135. a32[6] &= 0xffffffffL;
  27136. a32[7] = (sp_digit)(a[4] >> 4U) & 0xffffffffL;
  27137. a32[8] = (sp_digit)(a[4] >> 36U);
  27138. a32[8] |= (sp_digit)(a[5] << 19U);
  27139. a32[8] &= 0xffffffffL;
  27140. a32[9] = (sp_digit)(a[5] >> 13U) & 0xffffffffL;
  27141. a32[10] = (sp_digit)(a[5] >> 45U);
  27142. a32[10] |= (sp_digit)(a[6] << 10U);
  27143. a32[10] &= 0xffffffffL;
  27144. a32[11] = (sp_digit)(a[6] >> 22U) & 0xffffffffL;
  27145. /* 1 0 0 0 0 0 0 0 1 1 0 -1 */
  27146. t[0] = 0 + a32[0] + a32[8] + a32[9] - a32[11];
  27147. /* -1 1 0 0 0 0 0 0 -1 0 1 1 */
  27148. t[1] = 0 - a32[0] + a32[1] - a32[8] + a32[10] + a32[11];
  27149. /* 0 -1 1 0 0 0 0 0 0 -1 0 1 */
  27150. t[2] = 0 - a32[1] + a32[2] - a32[9] + a32[11];
  27151. /* 1 0 -1 1 0 0 0 0 1 1 -1 -1 */
  27152. t[3] = 0 + a32[0] - a32[2] + a32[3] + a32[8] + a32[9] - a32[10] - a32[11];
  27153. /* 1 1 0 -1 1 0 0 0 1 2 1 -2 */
  27154. t[4] = 0 + a32[0] + a32[1] - a32[3] + a32[4] + a32[8] + 2 * a32[9] + a32[10] - 2 * a32[11];
  27155. /* 0 1 1 0 -1 1 0 0 0 1 2 1 */
  27156. t[5] = 0 + a32[1] + a32[2] - a32[4] + a32[5] + a32[9] + 2 * a32[10] + a32[11];
  27157. /* 0 0 1 1 0 -1 1 0 0 0 1 2 */
  27158. t[6] = 0 + a32[2] + a32[3] - a32[5] + a32[6] + a32[10] + 2 * a32[11];
  27159. /* 0 0 0 1 1 0 -1 1 0 0 0 1 */
  27160. t[7] = 0 + a32[3] + a32[4] - a32[6] + a32[7] + a32[11];
  27161. /* 0 0 0 0 1 1 0 -1 1 0 0 0 */
  27162. t[8] = 0 + a32[4] + a32[5] - a32[7] + a32[8];
  27163. /* 0 0 0 0 0 1 1 0 -1 1 0 0 */
  27164. t[9] = 0 + a32[5] + a32[6] - a32[8] + a32[9];
  27165. /* 0 0 0 0 0 0 1 1 0 -1 1 0 */
  27166. t[10] = 0 + a32[6] + a32[7] - a32[9] + a32[10];
  27167. /* 0 0 0 0 0 0 0 1 1 0 -1 1 */
  27168. t[11] = 0 + a32[7] + a32[8] - a32[10] + a32[11];
  27169. t[1] += t[0] >> 32; t[0] &= 0xffffffff;
  27170. t[2] += t[1] >> 32; t[1] &= 0xffffffff;
  27171. t[3] += t[2] >> 32; t[2] &= 0xffffffff;
  27172. t[4] += t[3] >> 32; t[3] &= 0xffffffff;
  27173. t[5] += t[4] >> 32; t[4] &= 0xffffffff;
  27174. t[6] += t[5] >> 32; t[5] &= 0xffffffff;
  27175. t[7] += t[6] >> 32; t[6] &= 0xffffffff;
  27176. t[8] += t[7] >> 32; t[7] &= 0xffffffff;
  27177. t[9] += t[8] >> 32; t[8] &= 0xffffffff;
  27178. t[10] += t[9] >> 32; t[9] &= 0xffffffff;
  27179. t[11] += t[10] >> 32; t[10] &= 0xffffffff;
  27180. o = t[11] >> 32; t[11] &= 0xffffffff;
  27181. t[0] += o;
  27182. t[1] -= o;
  27183. t[3] += o;
  27184. t[4] += o;
  27185. t[1] += t[0] >> 32; t[0] &= 0xffffffff;
  27186. t[2] += t[1] >> 32; t[1] &= 0xffffffff;
  27187. t[3] += t[2] >> 32; t[2] &= 0xffffffff;
  27188. t[4] += t[3] >> 32; t[3] &= 0xffffffff;
  27189. t[5] += t[4] >> 32; t[4] &= 0xffffffff;
  27190. t[6] += t[5] >> 32; t[5] &= 0xffffffff;
  27191. t[7] += t[6] >> 32; t[6] &= 0xffffffff;
  27192. t[8] += t[7] >> 32; t[7] &= 0xffffffff;
  27193. t[9] += t[8] >> 32; t[8] &= 0xffffffff;
  27194. t[10] += t[9] >> 32; t[9] &= 0xffffffff;
  27195. t[11] += t[10] >> 32; t[10] &= 0xffffffff;
  27196. r[0] = t[0];
  27197. r[0] |= t[1] << 32U;
  27198. r[0] &= 0x7fffffffffffffLL;
  27199. r[1] = (t[1] >> 23);
  27200. r[1] |= t[2] << 9U;
  27201. r[1] |= t[3] << 41U;
  27202. r[1] &= 0x7fffffffffffffLL;
  27203. r[2] = (t[3] >> 14);
  27204. r[2] |= t[4] << 18U;
  27205. r[2] |= t[5] << 50U;
  27206. r[2] &= 0x7fffffffffffffLL;
  27207. r[3] = (t[5] >> 5);
  27208. r[3] |= t[6] << 27U;
  27209. r[3] &= 0x7fffffffffffffLL;
  27210. r[4] = (t[6] >> 28);
  27211. r[4] |= t[7] << 4U;
  27212. r[4] |= t[8] << 36U;
  27213. r[4] &= 0x7fffffffffffffLL;
  27214. r[5] = (t[8] >> 19);
  27215. r[5] |= t[9] << 13U;
  27216. r[5] |= t[10] << 45U;
  27217. r[5] &= 0x7fffffffffffffLL;
  27218. r[6] = (t[10] >> 10);
  27219. r[6] |= t[11] << 22U;
  27220. }
  27221. #ifdef WOLFSSL_SP_SMALL_STACK
  27222. if (t != NULL)
  27223. XFREE(t, NULL, DYNAMIC_TYPE_ECC);
  27224. #endif
  27225. return err;
  27226. }
  27227. #ifdef WOLFSSL_SP_SMALL
  27228. /* Multiply the point by the scalar and return the result.
  27229. * If map is true then convert result to affine coordinates.
  27230. *
  27231. * Small implementation using add and double that is cache attack resistant but
  27232. * allocates memory rather than use large stacks.
  27233. * 384 adds and doubles.
  27234. *
  27235. * r Resulting point.
  27236. * g Point to multiply.
  27237. * k Scalar to multiply by.
  27238. * map Indicates whether to convert result to affine.
  27239. * ct Constant time required.
  27240. * heap Heap to use for allocation.
  27241. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  27242. */
  27243. static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g,
  27244. const sp_digit* k, int map, int ct, void* heap)
  27245. {
  27246. #ifdef WOLFSSL_SP_SMALL_STACK
  27247. sp_point_384* t = NULL;
  27248. sp_digit* tmp = NULL;
  27249. #else
  27250. sp_point_384 t[3];
  27251. sp_digit tmp[2 * 7 * 6];
  27252. #endif
  27253. sp_digit n;
  27254. int i;
  27255. int c;
  27256. int y;
  27257. int err = MP_OKAY;
  27258. /* Implementation is constant time. */
  27259. (void)ct;
  27260. (void)heap;
  27261. #ifdef WOLFSSL_SP_SMALL_STACK
  27262. t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap,
  27263. DYNAMIC_TYPE_ECC);
  27264. if (t == NULL)
  27265. err = MEMORY_E;
  27266. if (err == MP_OKAY) {
  27267. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 6, heap,
  27268. DYNAMIC_TYPE_ECC);
  27269. if (tmp == NULL)
  27270. err = MEMORY_E;
  27271. }
  27272. #endif
  27273. if (err == MP_OKAY) {
  27274. XMEMSET(t, 0, sizeof(sp_point_384) * 3);
  27275. /* t[0] = {0, 0, 1} * norm */
  27276. t[0].infinity = 1;
  27277. /* t[1] = {g->x, g->y, g->z} * norm */
  27278. err = sp_384_mod_mul_norm_7(t[1].x, g->x, p384_mod);
  27279. }
  27280. if (err == MP_OKAY)
  27281. err = sp_384_mod_mul_norm_7(t[1].y, g->y, p384_mod);
  27282. if (err == MP_OKAY)
  27283. err = sp_384_mod_mul_norm_7(t[1].z, g->z, p384_mod);
  27284. if (err == MP_OKAY) {
  27285. i = 6;
  27286. c = 54;
  27287. n = k[i--] << (55 - c);
  27288. for (; ; c--) {
  27289. if (c == 0) {
  27290. if (i == -1)
  27291. break;
  27292. n = k[i--];
  27293. c = 55;
  27294. }
  27295. y = (n >> 54) & 1;
  27296. n <<= 1;
  27297. sp_384_proj_point_add_7(&t[y^1], &t[0], &t[1], tmp);
  27298. XMEMCPY(&t[2], (void*)(((size_t)&t[0] & addr_mask[y^1]) +
  27299. ((size_t)&t[1] & addr_mask[y])),
  27300. sizeof(sp_point_384));
  27301. sp_384_proj_point_dbl_7(&t[2], &t[2], tmp);
  27302. XMEMCPY((void*)(((size_t)&t[0] & addr_mask[y^1]) +
  27303. ((size_t)&t[1] & addr_mask[y])), &t[2],
  27304. sizeof(sp_point_384));
  27305. }
  27306. if (map != 0) {
  27307. sp_384_map_7(r, &t[0], tmp);
  27308. }
  27309. else {
  27310. XMEMCPY(r, &t[0], sizeof(sp_point_384));
  27311. }
  27312. }
  27313. #ifdef WOLFSSL_SP_SMALL_STACK
  27314. if (tmp != NULL)
  27315. #endif
  27316. {
  27317. ForceZero(tmp, sizeof(sp_digit) * 2 * 7 * 6);
  27318. #ifdef WOLFSSL_SP_SMALL_STACK
  27319. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  27320. #endif
  27321. }
  27322. #ifdef WOLFSSL_SP_SMALL_STACK
  27323. if (t != NULL)
  27324. #endif
  27325. {
  27326. ForceZero(t, sizeof(sp_point_384) * 3);
  27327. #ifdef WOLFSSL_SP_SMALL_STACK
  27328. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  27329. #endif
  27330. }
  27331. return err;
  27332. }
  27333. #ifdef WOLFSSL_SP_NONBLOCK
  27334. typedef struct sp_384_ecc_mulmod_7_ctx {
  27335. int state;
  27336. union {
  27337. sp_384_proj_point_dbl_7_ctx dbl_ctx;
  27338. sp_384_proj_point_add_7_ctx add_ctx;
  27339. };
  27340. sp_point_384 t[3];
  27341. sp_digit tmp[2 * 7 * 6];
  27342. sp_digit n;
  27343. int i;
  27344. int c;
  27345. int y;
  27346. } sp_384_ecc_mulmod_7_ctx;
  27347. static int sp_384_ecc_mulmod_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
  27348. const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap)
  27349. {
  27350. int err = FP_WOULDBLOCK;
  27351. sp_384_ecc_mulmod_7_ctx* ctx = (sp_384_ecc_mulmod_7_ctx*)sp_ctx->data;
  27352. typedef char ctx_size_test[sizeof(sp_384_ecc_mulmod_7_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  27353. (void)sizeof(ctx_size_test);
  27354. /* Implementation is constant time. */
  27355. (void)ct;
  27356. switch (ctx->state) {
  27357. case 0: /* INIT */
  27358. XMEMSET(ctx->t, 0, sizeof(sp_point_384) * 3);
  27359. ctx->i = 6;
  27360. ctx->c = 54;
  27361. ctx->n = k[ctx->i--] << (55 - ctx->c);
  27362. /* t[0] = {0, 0, 1} * norm */
  27363. ctx->t[0].infinity = 1;
  27364. ctx->state = 1;
  27365. break;
  27366. case 1: /* T1X */
  27367. /* t[1] = {g->x, g->y, g->z} * norm */
  27368. err = sp_384_mod_mul_norm_7(ctx->t[1].x, g->x, p384_mod);
  27369. ctx->state = 2;
  27370. break;
  27371. case 2: /* T1Y */
  27372. err = sp_384_mod_mul_norm_7(ctx->t[1].y, g->y, p384_mod);
  27373. ctx->state = 3;
  27374. break;
  27375. case 3: /* T1Z */
  27376. err = sp_384_mod_mul_norm_7(ctx->t[1].z, g->z, p384_mod);
  27377. ctx->state = 4;
  27378. break;
  27379. case 4: /* ADDPREP */
  27380. if (ctx->c == 0) {
  27381. if (ctx->i == -1) {
  27382. ctx->state = 7;
  27383. break;
  27384. }
  27385. ctx->n = k[ctx->i--];
  27386. ctx->c = 55;
  27387. }
  27388. ctx->y = (ctx->n >> 54) & 1;
  27389. ctx->n <<= 1;
  27390. XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx));
  27391. ctx->state = 5;
  27392. break;
  27393. case 5: /* ADD */
  27394. err = sp_384_proj_point_add_7_nb((sp_ecc_ctx_t*)&ctx->add_ctx,
  27395. &ctx->t[ctx->y^1], &ctx->t[0], &ctx->t[1], ctx->tmp);
  27396. if (err == MP_OKAY) {
  27397. XMEMCPY(&ctx->t[2], (void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  27398. ((size_t)&ctx->t[1] & addr_mask[ctx->y])),
  27399. sizeof(sp_point_384));
  27400. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  27401. ctx->state = 6;
  27402. }
  27403. break;
  27404. case 6: /* DBL */
  27405. err = sp_384_proj_point_dbl_7_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->t[2],
  27406. &ctx->t[2], ctx->tmp);
  27407. if (err == MP_OKAY) {
  27408. XMEMCPY((void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  27409. ((size_t)&ctx->t[1] & addr_mask[ctx->y])), &ctx->t[2],
  27410. sizeof(sp_point_384));
  27411. ctx->state = 4;
  27412. ctx->c--;
  27413. }
  27414. break;
  27415. case 7: /* MAP */
  27416. if (map != 0) {
  27417. sp_384_map_7(r, &ctx->t[0], ctx->tmp);
  27418. }
  27419. else {
  27420. XMEMCPY(r, &ctx->t[0], sizeof(sp_point_384));
  27421. }
  27422. err = MP_OKAY;
  27423. break;
  27424. }
  27425. if (err == MP_OKAY && ctx->state != 7) {
  27426. err = FP_WOULDBLOCK;
  27427. }
  27428. if (err != FP_WOULDBLOCK) {
  27429. ForceZero(ctx->tmp, sizeof(ctx->tmp));
  27430. ForceZero(ctx->t, sizeof(ctx->t));
  27431. }
  27432. (void)heap;
  27433. return err;
  27434. }
  27435. #endif /* WOLFSSL_SP_NONBLOCK */
  27436. #else
  27437. /* A table entry for pre-computed points. */
  27438. typedef struct sp_table_entry_384 {
  27439. sp_digit x[7];
  27440. sp_digit y[7];
  27441. } sp_table_entry_384;
  27442. /* Conditionally copy a into r using the mask m.
  27443. * m is -1 to copy and 0 when not.
  27444. *
  27445. * r A single precision number to copy over.
  27446. * a A single precision number to copy.
  27447. * m Mask value to apply.
  27448. */
  27449. static void sp_384_cond_copy_7(sp_digit* r, const sp_digit* a, const sp_digit m)
  27450. {
  27451. sp_digit t[7];
  27452. #ifdef WOLFSSL_SP_SMALL
  27453. int i;
  27454. for (i = 0; i < 7; i++) {
  27455. t[i] = r[i] ^ a[i];
  27456. }
  27457. for (i = 0; i < 7; i++) {
  27458. r[i] ^= t[i] & m;
  27459. }
  27460. #else
  27461. t[ 0] = r[ 0] ^ a[ 0];
  27462. t[ 1] = r[ 1] ^ a[ 1];
  27463. t[ 2] = r[ 2] ^ a[ 2];
  27464. t[ 3] = r[ 3] ^ a[ 3];
  27465. t[ 4] = r[ 4] ^ a[ 4];
  27466. t[ 5] = r[ 5] ^ a[ 5];
  27467. t[ 6] = r[ 6] ^ a[ 6];
  27468. r[ 0] ^= t[ 0] & m;
  27469. r[ 1] ^= t[ 1] & m;
  27470. r[ 2] ^= t[ 2] & m;
  27471. r[ 3] ^= t[ 3] & m;
  27472. r[ 4] ^= t[ 4] & m;
  27473. r[ 5] ^= t[ 5] & m;
  27474. r[ 6] ^= t[ 6] & m;
  27475. #endif /* WOLFSSL_SP_SMALL */
  27476. }
  27477. /* Double the Montgomery form projective point p a number of times.
  27478. *
  27479. * r Result of repeated doubling of point.
  27480. * p Point to double.
  27481. * n Number of times to double
  27482. * t Temporary ordinate data.
  27483. */
  27484. static void sp_384_proj_point_dbl_n_7(sp_point_384* p, int i,
  27485. sp_digit* t)
  27486. {
  27487. sp_digit* w = t;
  27488. sp_digit* a = t + 2*7;
  27489. sp_digit* b = t + 4*7;
  27490. sp_digit* t1 = t + 6*7;
  27491. sp_digit* t2 = t + 8*7;
  27492. sp_digit* x;
  27493. sp_digit* y;
  27494. sp_digit* z;
  27495. volatile int n = i;
  27496. x = p->x;
  27497. y = p->y;
  27498. z = p->z;
  27499. /* Y = 2*Y */
  27500. sp_384_mont_dbl_7(y, y, p384_mod);
  27501. /* W = Z^4 */
  27502. sp_384_mont_sqr_7(w, z, p384_mod, p384_mp_mod);
  27503. sp_384_mont_sqr_7(w, w, p384_mod, p384_mp_mod);
  27504. #ifndef WOLFSSL_SP_SMALL
  27505. while (--n > 0)
  27506. #else
  27507. while (--n >= 0)
  27508. #endif
  27509. {
  27510. /* A = 3*(X^2 - W) */
  27511. sp_384_mont_sqr_7(t1, x, p384_mod, p384_mp_mod);
  27512. sp_384_mont_sub_7(t1, t1, w, p384_mod);
  27513. sp_384_mont_tpl_7(a, t1, p384_mod);
  27514. /* B = X*Y^2 */
  27515. sp_384_mont_sqr_7(t1, y, p384_mod, p384_mp_mod);
  27516. sp_384_mont_mul_7(b, t1, x, p384_mod, p384_mp_mod);
  27517. /* X = A^2 - 2B */
  27518. sp_384_mont_sqr_7(x, a, p384_mod, p384_mp_mod);
  27519. sp_384_mont_dbl_7(t2, b, p384_mod);
  27520. sp_384_mont_sub_7(x, x, t2, p384_mod);
  27521. /* B = 2.(B - X) */
  27522. sp_384_mont_sub_7(t2, b, x, p384_mod);
  27523. sp_384_mont_dbl_7(b, t2, p384_mod);
  27524. /* Z = Z*Y */
  27525. sp_384_mont_mul_7(z, z, y, p384_mod, p384_mp_mod);
  27526. /* t1 = Y^4 */
  27527. sp_384_mont_sqr_7(t1, t1, p384_mod, p384_mp_mod);
  27528. #ifdef WOLFSSL_SP_SMALL
  27529. if (n != 0)
  27530. #endif
  27531. {
  27532. /* W = W*Y^4 */
  27533. sp_384_mont_mul_7(w, w, t1, p384_mod, p384_mp_mod);
  27534. }
  27535. /* y = 2*A*(B - X) - Y^4 */
  27536. sp_384_mont_mul_7(y, b, a, p384_mod, p384_mp_mod);
  27537. sp_384_mont_sub_7(y, y, t1, p384_mod);
  27538. }
  27539. #ifndef WOLFSSL_SP_SMALL
  27540. /* A = 3*(X^2 - W) */
  27541. sp_384_mont_sqr_7(t1, x, p384_mod, p384_mp_mod);
  27542. sp_384_mont_sub_7(t1, t1, w, p384_mod);
  27543. sp_384_mont_tpl_7(a, t1, p384_mod);
  27544. /* B = X*Y^2 */
  27545. sp_384_mont_sqr_7(t1, y, p384_mod, p384_mp_mod);
  27546. sp_384_mont_mul_7(b, t1, x, p384_mod, p384_mp_mod);
  27547. /* X = A^2 - 2B */
  27548. sp_384_mont_sqr_7(x, a, p384_mod, p384_mp_mod);
  27549. sp_384_mont_dbl_7(t2, b, p384_mod);
  27550. sp_384_mont_sub_7(x, x, t2, p384_mod);
  27551. /* B = 2.(B - X) */
  27552. sp_384_mont_sub_7(t2, b, x, p384_mod);
  27553. sp_384_mont_dbl_7(b, t2, p384_mod);
  27554. /* Z = Z*Y */
  27555. sp_384_mont_mul_7(z, z, y, p384_mod, p384_mp_mod);
  27556. /* t1 = Y^4 */
  27557. sp_384_mont_sqr_7(t1, t1, p384_mod, p384_mp_mod);
  27558. /* y = 2*A*(B - X) - Y^4 */
  27559. sp_384_mont_mul_7(y, b, a, p384_mod, p384_mp_mod);
  27560. sp_384_mont_sub_7(y, y, t1, p384_mod);
  27561. #endif /* WOLFSSL_SP_SMALL */
  27562. /* Y = Y/2 */
  27563. sp_384_mont_div2_7(y, y, p384_mod);
  27564. }
  27565. /* Double the Montgomery form projective point p a number of times.
  27566. *
  27567. * r Result of repeated doubling of point.
  27568. * p Point to double.
  27569. * n Number of times to double
  27570. * t Temporary ordinate data.
  27571. */
  27572. static void sp_384_proj_point_dbl_n_store_7(sp_point_384* r,
  27573. const sp_point_384* p, int n, int m, sp_digit* t)
  27574. {
  27575. sp_digit* w = t;
  27576. sp_digit* a = t + 2*7;
  27577. sp_digit* b = t + 4*7;
  27578. sp_digit* t1 = t + 6*7;
  27579. sp_digit* t2 = t + 8*7;
  27580. sp_digit* x = r[2*m].x;
  27581. sp_digit* y = r[(1<<n)*m].y;
  27582. sp_digit* z = r[2*m].z;
  27583. int i;
  27584. int j;
  27585. for (i=0; i<7; i++) {
  27586. x[i] = p->x[i];
  27587. }
  27588. for (i=0; i<7; i++) {
  27589. y[i] = p->y[i];
  27590. }
  27591. for (i=0; i<7; i++) {
  27592. z[i] = p->z[i];
  27593. }
  27594. /* Y = 2*Y */
  27595. sp_384_mont_dbl_7(y, y, p384_mod);
  27596. /* W = Z^4 */
  27597. sp_384_mont_sqr_7(w, z, p384_mod, p384_mp_mod);
  27598. sp_384_mont_sqr_7(w, w, p384_mod, p384_mp_mod);
  27599. j = m;
  27600. for (i=1; i<=n; i++) {
  27601. j *= 2;
  27602. /* A = 3*(X^2 - W) */
  27603. sp_384_mont_sqr_7(t1, x, p384_mod, p384_mp_mod);
  27604. sp_384_mont_sub_7(t1, t1, w, p384_mod);
  27605. sp_384_mont_tpl_7(a, t1, p384_mod);
  27606. /* B = X*Y^2 */
  27607. sp_384_mont_sqr_7(t1, y, p384_mod, p384_mp_mod);
  27608. sp_384_mont_mul_7(b, t1, x, p384_mod, p384_mp_mod);
  27609. x = r[j].x;
  27610. /* X = A^2 - 2B */
  27611. sp_384_mont_sqr_7(x, a, p384_mod, p384_mp_mod);
  27612. sp_384_mont_dbl_7(t2, b, p384_mod);
  27613. sp_384_mont_sub_7(x, x, t2, p384_mod);
  27614. /* B = 2.(B - X) */
  27615. sp_384_mont_sub_7(t2, b, x, p384_mod);
  27616. sp_384_mont_dbl_7(b, t2, p384_mod);
  27617. /* Z = Z*Y */
  27618. sp_384_mont_mul_7(r[j].z, z, y, p384_mod, p384_mp_mod);
  27619. z = r[j].z;
  27620. /* t1 = Y^4 */
  27621. sp_384_mont_sqr_7(t1, t1, p384_mod, p384_mp_mod);
  27622. if (i != n) {
  27623. /* W = W*Y^4 */
  27624. sp_384_mont_mul_7(w, w, t1, p384_mod, p384_mp_mod);
  27625. }
  27626. /* y = 2*A*(B - X) - Y^4 */
  27627. sp_384_mont_mul_7(y, b, a, p384_mod, p384_mp_mod);
  27628. sp_384_mont_sub_7(y, y, t1, p384_mod);
  27629. /* Y = Y/2 */
  27630. sp_384_mont_div2_7(r[j].y, y, p384_mod);
  27631. r[j].infinity = 0;
  27632. }
  27633. }
  27634. /* Add two Montgomery form projective points.
  27635. *
  27636. * ra Result of addition.
  27637. * rs Result of subtraction.
  27638. * p First point to add.
  27639. * q Second point to add.
  27640. * t Temporary ordinate data.
  27641. */
  27642. static void sp_384_proj_point_add_sub_7(sp_point_384* ra,
  27643. sp_point_384* rs, const sp_point_384* p, const sp_point_384* q,
  27644. sp_digit* t)
  27645. {
  27646. sp_digit* t1 = t;
  27647. sp_digit* t2 = t + 2*7;
  27648. sp_digit* t3 = t + 4*7;
  27649. sp_digit* t4 = t + 6*7;
  27650. sp_digit* t5 = t + 8*7;
  27651. sp_digit* t6 = t + 10*7;
  27652. sp_digit* xa = ra->x;
  27653. sp_digit* ya = ra->y;
  27654. sp_digit* za = ra->z;
  27655. sp_digit* xs = rs->x;
  27656. sp_digit* ys = rs->y;
  27657. sp_digit* zs = rs->z;
  27658. XMEMCPY(xa, p->x, sizeof(p->x) / 2);
  27659. XMEMCPY(ya, p->y, sizeof(p->y) / 2);
  27660. XMEMCPY(za, p->z, sizeof(p->z) / 2);
  27661. ra->infinity = 0;
  27662. rs->infinity = 0;
  27663. /* U1 = X1*Z2^2 */
  27664. sp_384_mont_sqr_7(t1, q->z, p384_mod, p384_mp_mod);
  27665. sp_384_mont_mul_7(t3, t1, q->z, p384_mod, p384_mp_mod);
  27666. sp_384_mont_mul_7(t1, t1, xa, p384_mod, p384_mp_mod);
  27667. /* U2 = X2*Z1^2 */
  27668. sp_384_mont_sqr_7(t2, za, p384_mod, p384_mp_mod);
  27669. sp_384_mont_mul_7(t4, t2, za, p384_mod, p384_mp_mod);
  27670. sp_384_mont_mul_7(t2, t2, q->x, p384_mod, p384_mp_mod);
  27671. /* S1 = Y1*Z2^3 */
  27672. sp_384_mont_mul_7(t3, t3, ya, p384_mod, p384_mp_mod);
  27673. /* S2 = Y2*Z1^3 */
  27674. sp_384_mont_mul_7(t4, t4, q->y, p384_mod, p384_mp_mod);
  27675. /* H = U2 - U1 */
  27676. sp_384_mont_sub_7(t2, t2, t1, p384_mod);
  27677. /* RS = S2 + S1 */
  27678. sp_384_mont_add_7(t6, t4, t3, p384_mod);
  27679. /* R = S2 - S1 */
  27680. sp_384_mont_sub_7(t4, t4, t3, p384_mod);
  27681. /* Z3 = H*Z1*Z2 */
  27682. /* ZS = H*Z1*Z2 */
  27683. sp_384_mont_mul_7(za, za, q->z, p384_mod, p384_mp_mod);
  27684. sp_384_mont_mul_7(za, za, t2, p384_mod, p384_mp_mod);
  27685. XMEMCPY(zs, za, sizeof(p->z)/2);
  27686. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  27687. /* XS = RS^2 - H^3 - 2*U1*H^2 */
  27688. sp_384_mont_sqr_7(xa, t4, p384_mod, p384_mp_mod);
  27689. sp_384_mont_sqr_7(xs, t6, p384_mod, p384_mp_mod);
  27690. sp_384_mont_sqr_7(t5, t2, p384_mod, p384_mp_mod);
  27691. sp_384_mont_mul_7(ya, t1, t5, p384_mod, p384_mp_mod);
  27692. sp_384_mont_mul_7(t5, t5, t2, p384_mod, p384_mp_mod);
  27693. sp_384_mont_sub_7(xa, xa, t5, p384_mod);
  27694. sp_384_mont_sub_7(xs, xs, t5, p384_mod);
  27695. sp_384_mont_dbl_7(t1, ya, p384_mod);
  27696. sp_384_mont_sub_7(xa, xa, t1, p384_mod);
  27697. sp_384_mont_sub_7(xs, xs, t1, p384_mod);
  27698. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  27699. /* YS = -RS*(U1*H^2 - XS) - S1*H^3 */
  27700. sp_384_mont_sub_7(ys, ya, xs, p384_mod);
  27701. sp_384_mont_sub_7(ya, ya, xa, p384_mod);
  27702. sp_384_mont_mul_7(ya, ya, t4, p384_mod, p384_mp_mod);
  27703. sp_384_sub_7(t6, p384_mod, t6);
  27704. sp_384_mont_mul_7(ys, ys, t6, p384_mod, p384_mp_mod);
  27705. sp_384_mont_mul_7(t5, t5, t3, p384_mod, p384_mp_mod);
  27706. sp_384_mont_sub_7(ya, ya, t5, p384_mod);
  27707. sp_384_mont_sub_7(ys, ys, t5, p384_mod);
  27708. }
  27709. /* Structure used to describe recoding of scalar multiplication. */
  27710. typedef struct ecc_recode_384 {
  27711. /* Index into pre-computation table. */
  27712. uint8_t i;
  27713. /* Use the negative of the point. */
  27714. uint8_t neg;
  27715. } ecc_recode_384;
  27716. /* The index into pre-computation table to use. */
  27717. static const uint8_t recode_index_7_6[66] = {
  27718. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  27719. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  27720. 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
  27721. 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
  27722. 0, 1,
  27723. };
  27724. /* Whether to negate y-ordinate. */
  27725. static const uint8_t recode_neg_7_6[66] = {
  27726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  27727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  27728. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  27729. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  27730. 0, 0,
  27731. };
  27732. /* Recode the scalar for multiplication using pre-computed values and
  27733. * subtraction.
  27734. *
  27735. * k Scalar to multiply by.
  27736. * v Vector of operations to perform.
  27737. */
  27738. static void sp_384_ecc_recode_6_7(const sp_digit* k, ecc_recode_384* v)
  27739. {
  27740. int i;
  27741. int j;
  27742. uint8_t y;
  27743. int carry = 0;
  27744. int o;
  27745. sp_digit n;
  27746. j = 0;
  27747. n = k[j];
  27748. o = 0;
  27749. for (i=0; i<65; i++) {
  27750. y = (int8_t)n;
  27751. if (o + 6 < 55) {
  27752. y &= 0x3f;
  27753. n >>= 6;
  27754. o += 6;
  27755. }
  27756. else if (o + 6 == 55) {
  27757. n >>= 6;
  27758. if (++j < 7)
  27759. n = k[j];
  27760. o = 0;
  27761. }
  27762. else if (++j < 7) {
  27763. n = k[j];
  27764. y |= (uint8_t)((n << (55 - o)) & 0x3f);
  27765. o -= 49;
  27766. n >>= o;
  27767. }
  27768. y += (uint8_t)carry;
  27769. v[i].i = recode_index_7_6[y];
  27770. v[i].neg = recode_neg_7_6[y];
  27771. carry = (y >> 6) + v[i].neg;
  27772. }
  27773. }
  27774. #ifndef WC_NO_CACHE_RESISTANT
  27775. /* Touch each possible point that could be being copied.
  27776. *
  27777. * r Point to copy into.
  27778. * table Table - start of the entries to access
  27779. * idx Index of entry to retrieve.
  27780. */
  27781. static void sp_384_get_point_33_7(sp_point_384* r, const sp_point_384* table,
  27782. int idx)
  27783. {
  27784. int i;
  27785. sp_digit mask;
  27786. r->x[0] = 0;
  27787. r->x[1] = 0;
  27788. r->x[2] = 0;
  27789. r->x[3] = 0;
  27790. r->x[4] = 0;
  27791. r->x[5] = 0;
  27792. r->x[6] = 0;
  27793. r->y[0] = 0;
  27794. r->y[1] = 0;
  27795. r->y[2] = 0;
  27796. r->y[3] = 0;
  27797. r->y[4] = 0;
  27798. r->y[5] = 0;
  27799. r->y[6] = 0;
  27800. r->z[0] = 0;
  27801. r->z[1] = 0;
  27802. r->z[2] = 0;
  27803. r->z[3] = 0;
  27804. r->z[4] = 0;
  27805. r->z[5] = 0;
  27806. r->z[6] = 0;
  27807. for (i = 1; i < 33; i++) {
  27808. mask = 0 - (i == idx);
  27809. r->x[0] |= mask & table[i].x[0];
  27810. r->x[1] |= mask & table[i].x[1];
  27811. r->x[2] |= mask & table[i].x[2];
  27812. r->x[3] |= mask & table[i].x[3];
  27813. r->x[4] |= mask & table[i].x[4];
  27814. r->x[5] |= mask & table[i].x[5];
  27815. r->x[6] |= mask & table[i].x[6];
  27816. r->y[0] |= mask & table[i].y[0];
  27817. r->y[1] |= mask & table[i].y[1];
  27818. r->y[2] |= mask & table[i].y[2];
  27819. r->y[3] |= mask & table[i].y[3];
  27820. r->y[4] |= mask & table[i].y[4];
  27821. r->y[5] |= mask & table[i].y[5];
  27822. r->y[6] |= mask & table[i].y[6];
  27823. r->z[0] |= mask & table[i].z[0];
  27824. r->z[1] |= mask & table[i].z[1];
  27825. r->z[2] |= mask & table[i].z[2];
  27826. r->z[3] |= mask & table[i].z[3];
  27827. r->z[4] |= mask & table[i].z[4];
  27828. r->z[5] |= mask & table[i].z[5];
  27829. r->z[6] |= mask & table[i].z[6];
  27830. }
  27831. }
  27832. #endif /* !WC_NO_CACHE_RESISTANT */
  27833. /* Multiply the point by the scalar and return the result.
  27834. * If map is true then convert result to affine coordinates.
  27835. *
  27836. * Window technique of 6 bits. (Add-Sub variation.)
  27837. * Calculate 0..32 times the point. Use function that adds and
  27838. * subtracts the same two points.
  27839. * Recode to add or subtract one of the computed points.
  27840. * Double to push up.
  27841. * NOT a sliding window.
  27842. *
  27843. * r Resulting point.
  27844. * g Point to multiply.
  27845. * k Scalar to multiply by.
  27846. * map Indicates whether to convert result to affine.
  27847. * ct Constant time required.
  27848. * heap Heap to use for allocation.
  27849. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  27850. */
  27851. static int sp_384_ecc_mulmod_win_add_sub_7(sp_point_384* r, const sp_point_384* g,
  27852. const sp_digit* k, int map, int ct, void* heap)
  27853. {
  27854. #ifdef WOLFSSL_SP_SMALL_STACK
  27855. sp_point_384* t = NULL;
  27856. sp_digit* tmp = NULL;
  27857. #else
  27858. sp_point_384 t[33+2];
  27859. sp_digit tmp[2 * 7 * 6];
  27860. #endif
  27861. sp_point_384* rt = NULL;
  27862. sp_point_384* p = NULL;
  27863. sp_digit* negy;
  27864. int i;
  27865. ecc_recode_384 v[65];
  27866. int err = MP_OKAY;
  27867. /* Constant time used for cache attack resistance implementation. */
  27868. (void)ct;
  27869. (void)heap;
  27870. #ifdef WOLFSSL_SP_SMALL_STACK
  27871. t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) *
  27872. (33+2), heap, DYNAMIC_TYPE_ECC);
  27873. if (t == NULL)
  27874. err = MEMORY_E;
  27875. if (err == MP_OKAY) {
  27876. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 6,
  27877. heap, DYNAMIC_TYPE_ECC);
  27878. if (tmp == NULL)
  27879. err = MEMORY_E;
  27880. }
  27881. #endif
  27882. if (err == MP_OKAY) {
  27883. rt = t + 33;
  27884. p = t + 33+1;
  27885. /* t[0] = {0, 0, 1} * norm */
  27886. XMEMSET(&t[0], 0, sizeof(t[0]));
  27887. t[0].infinity = 1;
  27888. /* t[1] = {g->x, g->y, g->z} * norm */
  27889. err = sp_384_mod_mul_norm_7(t[1].x, g->x, p384_mod);
  27890. }
  27891. if (err == MP_OKAY) {
  27892. err = sp_384_mod_mul_norm_7(t[1].y, g->y, p384_mod);
  27893. }
  27894. if (err == MP_OKAY) {
  27895. err = sp_384_mod_mul_norm_7(t[1].z, g->z, p384_mod);
  27896. }
  27897. if (err == MP_OKAY) {
  27898. t[1].infinity = 0;
  27899. /* t[2] ... t[32] */
  27900. sp_384_proj_point_dbl_n_store_7(t, &t[ 1], 5, 1, tmp);
  27901. sp_384_proj_point_add_7(&t[ 3], &t[ 2], &t[ 1], tmp);
  27902. sp_384_proj_point_dbl_7(&t[ 6], &t[ 3], tmp);
  27903. sp_384_proj_point_add_sub_7(&t[ 7], &t[ 5], &t[ 6], &t[ 1], tmp);
  27904. sp_384_proj_point_dbl_7(&t[10], &t[ 5], tmp);
  27905. sp_384_proj_point_add_sub_7(&t[11], &t[ 9], &t[10], &t[ 1], tmp);
  27906. sp_384_proj_point_dbl_7(&t[12], &t[ 6], tmp);
  27907. sp_384_proj_point_dbl_7(&t[14], &t[ 7], tmp);
  27908. sp_384_proj_point_add_sub_7(&t[15], &t[13], &t[14], &t[ 1], tmp);
  27909. sp_384_proj_point_dbl_7(&t[18], &t[ 9], tmp);
  27910. sp_384_proj_point_add_sub_7(&t[19], &t[17], &t[18], &t[ 1], tmp);
  27911. sp_384_proj_point_dbl_7(&t[20], &t[10], tmp);
  27912. sp_384_proj_point_dbl_7(&t[22], &t[11], tmp);
  27913. sp_384_proj_point_add_sub_7(&t[23], &t[21], &t[22], &t[ 1], tmp);
  27914. sp_384_proj_point_dbl_7(&t[24], &t[12], tmp);
  27915. sp_384_proj_point_dbl_7(&t[26], &t[13], tmp);
  27916. sp_384_proj_point_add_sub_7(&t[27], &t[25], &t[26], &t[ 1], tmp);
  27917. sp_384_proj_point_dbl_7(&t[28], &t[14], tmp);
  27918. sp_384_proj_point_dbl_7(&t[30], &t[15], tmp);
  27919. sp_384_proj_point_add_sub_7(&t[31], &t[29], &t[30], &t[ 1], tmp);
  27920. negy = t[0].y;
  27921. sp_384_ecc_recode_6_7(k, v);
  27922. i = 64;
  27923. #ifndef WC_NO_CACHE_RESISTANT
  27924. if (ct) {
  27925. sp_384_get_point_33_7(rt, t, v[i].i);
  27926. rt->infinity = !v[i].i;
  27927. }
  27928. else
  27929. #endif
  27930. {
  27931. XMEMCPY(rt, &t[v[i].i], sizeof(sp_point_384));
  27932. }
  27933. for (--i; i>=0; i--) {
  27934. sp_384_proj_point_dbl_n_7(rt, 6, tmp);
  27935. #ifndef WC_NO_CACHE_RESISTANT
  27936. if (ct) {
  27937. sp_384_get_point_33_7(p, t, v[i].i);
  27938. p->infinity = !v[i].i;
  27939. }
  27940. else
  27941. #endif
  27942. {
  27943. XMEMCPY(p, &t[v[i].i], sizeof(sp_point_384));
  27944. }
  27945. sp_384_sub_7(negy, p384_mod, p->y);
  27946. sp_384_norm_7(negy);
  27947. sp_384_cond_copy_7(p->y, negy, (sp_digit)0 - v[i].neg);
  27948. sp_384_proj_point_add_7(rt, rt, p, tmp);
  27949. }
  27950. if (map != 0) {
  27951. sp_384_map_7(r, rt, tmp);
  27952. }
  27953. else {
  27954. XMEMCPY(r, rt, sizeof(sp_point_384));
  27955. }
  27956. }
  27957. #ifdef WOLFSSL_SP_SMALL_STACK
  27958. if (t != NULL)
  27959. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  27960. if (tmp != NULL)
  27961. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  27962. #endif
  27963. return err;
  27964. }
  27965. #ifdef FP_ECC
  27966. #endif /* FP_ECC */
  27967. /* Add two Montgomery form projective points. The second point has a q value of
  27968. * one.
  27969. * Only the first point can be the same pointer as the result point.
  27970. *
  27971. * r Result of addition.
  27972. * p First point to add.
  27973. * q Second point to add.
  27974. * t Temporary ordinate data.
  27975. */
  27976. static void sp_384_proj_point_add_qz1_7(sp_point_384* r,
  27977. const sp_point_384* p, const sp_point_384* q, sp_digit* t)
  27978. {
  27979. sp_digit* t2 = t;
  27980. sp_digit* t3 = t + 2*7;
  27981. sp_digit* t6 = t + 4*7;
  27982. sp_digit* t1 = t + 6*7;
  27983. sp_digit* t4 = t + 8*7;
  27984. sp_digit* t5 = t + 10*7;
  27985. /* Calculate values to subtract from P->x and P->y. */
  27986. /* U2 = X2*Z1^2 */
  27987. sp_384_mont_sqr_7(t2, p->z, p384_mod, p384_mp_mod);
  27988. sp_384_mont_mul_7(t4, t2, p->z, p384_mod, p384_mp_mod);
  27989. sp_384_mont_mul_7(t2, t2, q->x, p384_mod, p384_mp_mod);
  27990. /* S2 = Y2*Z1^3 */
  27991. sp_384_mont_mul_7(t4, t4, q->y, p384_mod, p384_mp_mod);
  27992. if ((~p->infinity) & (~q->infinity) &
  27993. sp_384_cmp_equal_7(p->x, t2) &
  27994. sp_384_cmp_equal_7(p->y, t4)) {
  27995. sp_384_proj_point_dbl_7(r, p, t);
  27996. }
  27997. else {
  27998. sp_digit* x = t2;
  27999. sp_digit* y = t3;
  28000. sp_digit* z = t6;
  28001. /* H = U2 - X1 */
  28002. sp_384_mont_sub_7(t2, t2, p->x, p384_mod);
  28003. /* R = S2 - Y1 */
  28004. sp_384_mont_sub_7(t4, t4, p->y, p384_mod);
  28005. /* Z3 = H*Z1 */
  28006. sp_384_mont_mul_7(z, p->z, t2, p384_mod, p384_mp_mod);
  28007. /* X3 = R^2 - H^3 - 2*X1*H^2 */
  28008. sp_384_mont_sqr_7(t1, t2, p384_mod, p384_mp_mod);
  28009. sp_384_mont_mul_7(t3, p->x, t1, p384_mod, p384_mp_mod);
  28010. sp_384_mont_mul_7(t1, t1, t2, p384_mod, p384_mp_mod);
  28011. sp_384_mont_sqr_7(t2, t4, p384_mod, p384_mp_mod);
  28012. sp_384_mont_sub_7(t2, t2, t1, p384_mod);
  28013. sp_384_mont_dbl_7(t5, t3, p384_mod);
  28014. sp_384_mont_sub_7(x, t2, t5, p384_mod);
  28015. /* Y3 = R*(X1*H^2 - X3) - Y1*H^3 */
  28016. sp_384_mont_sub_7(t3, t3, x, p384_mod);
  28017. sp_384_mont_mul_7(t3, t3, t4, p384_mod, p384_mp_mod);
  28018. sp_384_mont_mul_7(t1, t1, p->y, p384_mod, p384_mp_mod);
  28019. sp_384_mont_sub_7(y, t3, t1, p384_mod);
  28020. {
  28021. int i;
  28022. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  28023. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  28024. sp_digit maskt = ~(maskp | maskq);
  28025. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  28026. for (i = 0; i < 7; i++) {
  28027. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  28028. (x[i] & maskt);
  28029. }
  28030. for (i = 0; i < 7; i++) {
  28031. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  28032. (y[i] & maskt);
  28033. }
  28034. for (i = 0; i < 7; i++) {
  28035. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  28036. (z[i] & maskt);
  28037. }
  28038. r->z[0] |= inf;
  28039. r->infinity = (word32)inf;
  28040. }
  28041. }
  28042. }
  28043. #ifdef FP_ECC
  28044. /* Convert the projective point to affine.
  28045. * Ordinates are in Montgomery form.
  28046. *
  28047. * a Point to convert.
  28048. * t Temporary data.
  28049. */
  28050. static void sp_384_proj_to_affine_7(sp_point_384* a, sp_digit* t)
  28051. {
  28052. sp_digit* t1 = t;
  28053. sp_digit* t2 = t + 2 * 7;
  28054. sp_digit* tmp = t + 4 * 7;
  28055. sp_384_mont_inv_7(t1, a->z, tmp);
  28056. sp_384_mont_sqr_7(t2, t1, p384_mod, p384_mp_mod);
  28057. sp_384_mont_mul_7(t1, t2, t1, p384_mod, p384_mp_mod);
  28058. sp_384_mont_mul_7(a->x, a->x, t2, p384_mod, p384_mp_mod);
  28059. sp_384_mont_mul_7(a->y, a->y, t1, p384_mod, p384_mp_mod);
  28060. XMEMCPY(a->z, p384_norm_mod, sizeof(p384_norm_mod));
  28061. }
  28062. /* Generate the pre-computed table of points for the base point.
  28063. *
  28064. * width = 8
  28065. * 256 entries
  28066. * 48 bits between
  28067. *
  28068. * a The base point.
  28069. * table Place to store generated point data.
  28070. * tmp Temporary data.
  28071. * heap Heap to use for allocation.
  28072. */
  28073. static int sp_384_gen_stripe_table_7(const sp_point_384* a,
  28074. sp_table_entry_384* table, sp_digit* tmp, void* heap)
  28075. {
  28076. #ifdef WOLFSSL_SP_SMALL_STACK
  28077. sp_point_384* t = NULL;
  28078. #else
  28079. sp_point_384 t[3];
  28080. #endif
  28081. sp_point_384* s1 = NULL;
  28082. sp_point_384* s2 = NULL;
  28083. int i;
  28084. int j;
  28085. int err = MP_OKAY;
  28086. (void)heap;
  28087. #ifdef WOLFSSL_SP_SMALL_STACK
  28088. t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap,
  28089. DYNAMIC_TYPE_ECC);
  28090. if (t == NULL)
  28091. err = MEMORY_E;
  28092. #endif
  28093. if (err == MP_OKAY) {
  28094. s1 = t + 1;
  28095. s2 = t + 2;
  28096. err = sp_384_mod_mul_norm_7(t->x, a->x, p384_mod);
  28097. }
  28098. if (err == MP_OKAY) {
  28099. err = sp_384_mod_mul_norm_7(t->y, a->y, p384_mod);
  28100. }
  28101. if (err == MP_OKAY) {
  28102. err = sp_384_mod_mul_norm_7(t->z, a->z, p384_mod);
  28103. }
  28104. if (err == MP_OKAY) {
  28105. t->infinity = 0;
  28106. sp_384_proj_to_affine_7(t, tmp);
  28107. XMEMCPY(s1->z, p384_norm_mod, sizeof(p384_norm_mod));
  28108. s1->infinity = 0;
  28109. XMEMCPY(s2->z, p384_norm_mod, sizeof(p384_norm_mod));
  28110. s2->infinity = 0;
  28111. /* table[0] = {0, 0, infinity} */
  28112. XMEMSET(&table[0], 0, sizeof(sp_table_entry_384));
  28113. /* table[1] = Affine version of 'a' in Montgomery form */
  28114. XMEMCPY(table[1].x, t->x, sizeof(table->x));
  28115. XMEMCPY(table[1].y, t->y, sizeof(table->y));
  28116. for (i=1; i<8; i++) {
  28117. sp_384_proj_point_dbl_n_7(t, 48, tmp);
  28118. sp_384_proj_to_affine_7(t, tmp);
  28119. XMEMCPY(table[1<<i].x, t->x, sizeof(table->x));
  28120. XMEMCPY(table[1<<i].y, t->y, sizeof(table->y));
  28121. }
  28122. for (i=1; i<8; i++) {
  28123. XMEMCPY(s1->x, table[1<<i].x, sizeof(table->x));
  28124. XMEMCPY(s1->y, table[1<<i].y, sizeof(table->y));
  28125. for (j=(1<<i)+1; j<(1<<(i+1)); j++) {
  28126. XMEMCPY(s2->x, table[j-(1<<i)].x, sizeof(table->x));
  28127. XMEMCPY(s2->y, table[j-(1<<i)].y, sizeof(table->y));
  28128. sp_384_proj_point_add_qz1_7(t, s1, s2, tmp);
  28129. sp_384_proj_to_affine_7(t, tmp);
  28130. XMEMCPY(table[j].x, t->x, sizeof(table->x));
  28131. XMEMCPY(table[j].y, t->y, sizeof(table->y));
  28132. }
  28133. }
  28134. }
  28135. #ifdef WOLFSSL_SP_SMALL_STACK
  28136. if (t != NULL)
  28137. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  28138. #endif
  28139. return err;
  28140. }
  28141. #endif /* FP_ECC */
  28142. #ifndef WC_NO_CACHE_RESISTANT
  28143. /* Touch each possible entry that could be being copied.
  28144. *
  28145. * r Point to copy into.
  28146. * table Table - start of the entries to access
  28147. * idx Index of entry to retrieve.
  28148. */
  28149. static void sp_384_get_entry_256_7(sp_point_384* r,
  28150. const sp_table_entry_384* table, int idx)
  28151. {
  28152. int i;
  28153. sp_digit mask;
  28154. r->x[0] = 0;
  28155. r->x[1] = 0;
  28156. r->x[2] = 0;
  28157. r->x[3] = 0;
  28158. r->x[4] = 0;
  28159. r->x[5] = 0;
  28160. r->x[6] = 0;
  28161. r->y[0] = 0;
  28162. r->y[1] = 0;
  28163. r->y[2] = 0;
  28164. r->y[3] = 0;
  28165. r->y[4] = 0;
  28166. r->y[5] = 0;
  28167. r->y[6] = 0;
  28168. for (i = 1; i < 256; i++) {
  28169. mask = 0 - (i == idx);
  28170. r->x[0] |= mask & table[i].x[0];
  28171. r->x[1] |= mask & table[i].x[1];
  28172. r->x[2] |= mask & table[i].x[2];
  28173. r->x[3] |= mask & table[i].x[3];
  28174. r->x[4] |= mask & table[i].x[4];
  28175. r->x[5] |= mask & table[i].x[5];
  28176. r->x[6] |= mask & table[i].x[6];
  28177. r->y[0] |= mask & table[i].y[0];
  28178. r->y[1] |= mask & table[i].y[1];
  28179. r->y[2] |= mask & table[i].y[2];
  28180. r->y[3] |= mask & table[i].y[3];
  28181. r->y[4] |= mask & table[i].y[4];
  28182. r->y[5] |= mask & table[i].y[5];
  28183. r->y[6] |= mask & table[i].y[6];
  28184. }
  28185. }
  28186. #endif /* !WC_NO_CACHE_RESISTANT */
  28187. /* Multiply the point by the scalar and return the result.
  28188. * If map is true then convert result to affine coordinates.
  28189. *
  28190. * Stripe implementation.
  28191. * Pre-generated: 2^0, 2^48, ...
  28192. * Pre-generated: products of all combinations of above.
  28193. * 8 doubles and adds (with qz=1)
  28194. *
  28195. * r Resulting point.
  28196. * k Scalar to multiply by.
  28197. * table Pre-computed table.
  28198. * map Indicates whether to convert result to affine.
  28199. * ct Constant time required.
  28200. * heap Heap to use for allocation.
  28201. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  28202. */
  28203. static int sp_384_ecc_mulmod_stripe_7(sp_point_384* r, const sp_point_384* g,
  28204. const sp_table_entry_384* table, const sp_digit* k, int map,
  28205. int ct, void* heap)
  28206. {
  28207. #ifdef WOLFSSL_SP_SMALL_STACK
  28208. sp_point_384* rt = NULL;
  28209. sp_digit* t = NULL;
  28210. #else
  28211. sp_point_384 rt[2];
  28212. sp_digit t[2 * 7 * 6];
  28213. #endif
  28214. sp_point_384* p = NULL;
  28215. int i;
  28216. int j;
  28217. int y;
  28218. int x;
  28219. int err = MP_OKAY;
  28220. (void)g;
  28221. /* Constant time used for cache attack resistance implementation. */
  28222. (void)ct;
  28223. (void)heap;
  28224. #ifdef WOLFSSL_SP_SMALL_STACK
  28225. rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap,
  28226. DYNAMIC_TYPE_ECC);
  28227. if (rt == NULL)
  28228. err = MEMORY_E;
  28229. if (err == MP_OKAY) {
  28230. t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 6, heap,
  28231. DYNAMIC_TYPE_ECC);
  28232. if (t == NULL)
  28233. err = MEMORY_E;
  28234. }
  28235. #endif
  28236. if (err == MP_OKAY) {
  28237. p = rt + 1;
  28238. XMEMCPY(p->z, p384_norm_mod, sizeof(p384_norm_mod));
  28239. XMEMCPY(rt->z, p384_norm_mod, sizeof(p384_norm_mod));
  28240. y = 0;
  28241. x = 47;
  28242. for (j=0; j<8; j++) {
  28243. y |= (int)(((k[x / 55] >> (x % 55)) & 1) << j);
  28244. x += 48;
  28245. }
  28246. #ifndef WC_NO_CACHE_RESISTANT
  28247. if (ct) {
  28248. sp_384_get_entry_256_7(rt, table, y);
  28249. } else
  28250. #endif
  28251. {
  28252. XMEMCPY(rt->x, table[y].x, sizeof(table[y].x));
  28253. XMEMCPY(rt->y, table[y].y, sizeof(table[y].y));
  28254. }
  28255. rt->infinity = !y;
  28256. for (i=46; i>=0; i--) {
  28257. y = 0;
  28258. x = i;
  28259. for (j=0; j<8; j++) {
  28260. y |= (int)(((k[x / 55] >> (x % 55)) & 1) << j);
  28261. x += 48;
  28262. }
  28263. sp_384_proj_point_dbl_7(rt, rt, t);
  28264. #ifndef WC_NO_CACHE_RESISTANT
  28265. if (ct) {
  28266. sp_384_get_entry_256_7(p, table, y);
  28267. }
  28268. else
  28269. #endif
  28270. {
  28271. XMEMCPY(p->x, table[y].x, sizeof(table[y].x));
  28272. XMEMCPY(p->y, table[y].y, sizeof(table[y].y));
  28273. }
  28274. p->infinity = !y;
  28275. sp_384_proj_point_add_qz1_7(rt, rt, p, t);
  28276. }
  28277. if (map != 0) {
  28278. sp_384_map_7(r, rt, t);
  28279. }
  28280. else {
  28281. XMEMCPY(r, rt, sizeof(sp_point_384));
  28282. }
  28283. }
  28284. #ifdef WOLFSSL_SP_SMALL_STACK
  28285. if (t != NULL)
  28286. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  28287. if (rt != NULL)
  28288. XFREE(rt, heap, DYNAMIC_TYPE_ECC);
  28289. #endif
  28290. return err;
  28291. }
  28292. #ifdef FP_ECC
  28293. #ifndef FP_ENTRIES
  28294. #define FP_ENTRIES 16
  28295. #endif
  28296. /* Cache entry - holds precomputation tables for a point. */
  28297. typedef struct sp_cache_384_t {
  28298. /* X ordinate of point that table was generated from. */
  28299. sp_digit x[7];
  28300. /* Y ordinate of point that table was generated from. */
  28301. sp_digit y[7];
  28302. /* Precomputation table for point. */
  28303. sp_table_entry_384 table[256];
  28304. /* Count of entries in table. */
  28305. uint32_t cnt;
  28306. /* Point and table set in entry. */
  28307. int set;
  28308. } sp_cache_384_t;
  28309. /* Cache of tables. */
  28310. static THREAD_LS_T sp_cache_384_t sp_cache_384[FP_ENTRIES];
  28311. /* Index of last entry in cache. */
  28312. static THREAD_LS_T int sp_cache_384_last = -1;
  28313. /* Cache has been initialized. */
  28314. static THREAD_LS_T int sp_cache_384_inited = 0;
  28315. #ifndef HAVE_THREAD_LS
  28316. static volatile int initCacheMutex_384 = 0;
  28317. static wolfSSL_Mutex sp_cache_384_lock;
  28318. #endif
  28319. /* Get the cache entry for the point.
  28320. *
  28321. * g [in] Point scalar multiplying.
  28322. * cache [out] Cache table to use.
  28323. */
  28324. static void sp_ecc_get_cache_384(const sp_point_384* g, sp_cache_384_t** cache)
  28325. {
  28326. int i;
  28327. int j;
  28328. uint32_t least;
  28329. if (sp_cache_384_inited == 0) {
  28330. for (i=0; i<FP_ENTRIES; i++) {
  28331. sp_cache_384[i].set = 0;
  28332. }
  28333. sp_cache_384_inited = 1;
  28334. }
  28335. /* Compare point with those in cache. */
  28336. for (i=0; i<FP_ENTRIES; i++) {
  28337. if (!sp_cache_384[i].set)
  28338. continue;
  28339. if (sp_384_cmp_equal_7(g->x, sp_cache_384[i].x) &
  28340. sp_384_cmp_equal_7(g->y, sp_cache_384[i].y)) {
  28341. sp_cache_384[i].cnt++;
  28342. break;
  28343. }
  28344. }
  28345. /* No match. */
  28346. if (i == FP_ENTRIES) {
  28347. /* Find empty entry. */
  28348. i = (sp_cache_384_last + 1) % FP_ENTRIES;
  28349. for (; i != sp_cache_384_last; i=(i+1)%FP_ENTRIES) {
  28350. if (!sp_cache_384[i].set) {
  28351. break;
  28352. }
  28353. }
  28354. /* Evict least used. */
  28355. if (i == sp_cache_384_last) {
  28356. least = sp_cache_384[0].cnt;
  28357. for (j=1; j<FP_ENTRIES; j++) {
  28358. if (sp_cache_384[j].cnt < least) {
  28359. i = j;
  28360. least = sp_cache_384[i].cnt;
  28361. }
  28362. }
  28363. }
  28364. XMEMCPY(sp_cache_384[i].x, g->x, sizeof(sp_cache_384[i].x));
  28365. XMEMCPY(sp_cache_384[i].y, g->y, sizeof(sp_cache_384[i].y));
  28366. sp_cache_384[i].set = 1;
  28367. sp_cache_384[i].cnt = 1;
  28368. }
  28369. *cache = &sp_cache_384[i];
  28370. sp_cache_384_last = i;
  28371. }
  28372. #endif /* FP_ECC */
  28373. /* Multiply the base point of P384 by the scalar and return the result.
  28374. * If map is true then convert result to affine coordinates.
  28375. *
  28376. * r Resulting point.
  28377. * g Point to multiply.
  28378. * k Scalar to multiply by.
  28379. * map Indicates whether to convert result to affine.
  28380. * ct Constant time required.
  28381. * heap Heap to use for allocation.
  28382. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  28383. */
  28384. static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g,
  28385. const sp_digit* k, int map, int ct, void* heap)
  28386. {
  28387. #ifndef FP_ECC
  28388. return sp_384_ecc_mulmod_win_add_sub_7(r, g, k, map, ct, heap);
  28389. #else
  28390. #ifdef WOLFSSL_SP_SMALL_STACK
  28391. sp_digit* tmp;
  28392. #else
  28393. sp_digit tmp[2 * 7 * 7];
  28394. #endif
  28395. sp_cache_384_t* cache;
  28396. int err = MP_OKAY;
  28397. #ifdef WOLFSSL_SP_SMALL_STACK
  28398. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 7, heap, DYNAMIC_TYPE_ECC);
  28399. if (tmp == NULL) {
  28400. err = MEMORY_E;
  28401. }
  28402. #endif
  28403. #ifndef HAVE_THREAD_LS
  28404. if (err == MP_OKAY) {
  28405. if (initCacheMutex_384 == 0) {
  28406. wc_InitMutex(&sp_cache_384_lock);
  28407. initCacheMutex_384 = 1;
  28408. }
  28409. if (wc_LockMutex(&sp_cache_384_lock) != 0) {
  28410. err = BAD_MUTEX_E;
  28411. }
  28412. }
  28413. #endif /* HAVE_THREAD_LS */
  28414. if (err == MP_OKAY) {
  28415. sp_ecc_get_cache_384(g, &cache);
  28416. if (cache->cnt == 2)
  28417. sp_384_gen_stripe_table_7(g, cache->table, tmp, heap);
  28418. #ifndef HAVE_THREAD_LS
  28419. wc_UnLockMutex(&sp_cache_384_lock);
  28420. #endif /* HAVE_THREAD_LS */
  28421. if (cache->cnt < 2) {
  28422. err = sp_384_ecc_mulmod_win_add_sub_7(r, g, k, map, ct, heap);
  28423. }
  28424. else {
  28425. err = sp_384_ecc_mulmod_stripe_7(r, g, cache->table, k,
  28426. map, ct, heap);
  28427. }
  28428. }
  28429. #ifdef WOLFSSL_SP_SMALL_STACK
  28430. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  28431. #endif
  28432. return err;
  28433. #endif
  28434. }
  28435. #endif
  28436. /* Multiply the point by the scalar and return the result.
  28437. * If map is true then convert result to affine coordinates.
  28438. *
  28439. * km Scalar to multiply by.
  28440. * p Point to multiply.
  28441. * r Resulting point.
  28442. * map Indicates whether to convert result to affine.
  28443. * heap Heap to use for allocation.
  28444. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  28445. */
  28446. int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r,
  28447. int map, void* heap)
  28448. {
  28449. #ifdef WOLFSSL_SP_SMALL_STACK
  28450. sp_point_384* point = NULL;
  28451. sp_digit* k = NULL;
  28452. #else
  28453. sp_point_384 point[1];
  28454. sp_digit k[7];
  28455. #endif
  28456. int err = MP_OKAY;
  28457. #ifdef WOLFSSL_SP_SMALL_STACK
  28458. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap,
  28459. DYNAMIC_TYPE_ECC);
  28460. if (point == NULL)
  28461. err = MEMORY_E;
  28462. if (err == MP_OKAY) {
  28463. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7, heap,
  28464. DYNAMIC_TYPE_ECC);
  28465. if (k == NULL)
  28466. err = MEMORY_E;
  28467. }
  28468. #endif
  28469. if (err == MP_OKAY) {
  28470. sp_384_from_mp(k, 7, km);
  28471. sp_384_point_from_ecc_point_7(point, gm);
  28472. err = sp_384_ecc_mulmod_7(point, point, k, map, 1, heap);
  28473. }
  28474. if (err == MP_OKAY) {
  28475. err = sp_384_point_to_ecc_point_7(point, r);
  28476. }
  28477. #ifdef WOLFSSL_SP_SMALL_STACK
  28478. if (k != NULL)
  28479. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  28480. if (point != NULL)
  28481. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  28482. #endif
  28483. return err;
  28484. }
  28485. /* Multiply the point by the scalar, add point a and return the result.
  28486. * If map is true then convert result to affine coordinates.
  28487. *
  28488. * km Scalar to multiply by.
  28489. * p Point to multiply.
  28490. * am Point to add to scalar multiply result.
  28491. * inMont Point to add is in montgomery form.
  28492. * r Resulting point.
  28493. * map Indicates whether to convert result to affine.
  28494. * heap Heap to use for allocation.
  28495. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  28496. */
  28497. int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm,
  28498. const ecc_point* am, int inMont, ecc_point* r, int map, void* heap)
  28499. {
  28500. #ifdef WOLFSSL_SP_SMALL_STACK
  28501. sp_point_384* point = NULL;
  28502. sp_digit* k = NULL;
  28503. #else
  28504. sp_point_384 point[2];
  28505. sp_digit k[7 + 7 * 2 * 6];
  28506. #endif
  28507. sp_point_384* addP = NULL;
  28508. sp_digit* tmp = NULL;
  28509. int err = MP_OKAY;
  28510. #ifdef WOLFSSL_SP_SMALL_STACK
  28511. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap,
  28512. DYNAMIC_TYPE_ECC);
  28513. if (point == NULL)
  28514. err = MEMORY_E;
  28515. if (err == MP_OKAY) {
  28516. k = (sp_digit*)XMALLOC(
  28517. sizeof(sp_digit) * (7 + 7 * 2 * 6), heap,
  28518. DYNAMIC_TYPE_ECC);
  28519. if (k == NULL)
  28520. err = MEMORY_E;
  28521. }
  28522. #endif
  28523. if (err == MP_OKAY) {
  28524. addP = point + 1;
  28525. tmp = k + 7;
  28526. sp_384_from_mp(k, 7, km);
  28527. sp_384_point_from_ecc_point_7(point, gm);
  28528. sp_384_point_from_ecc_point_7(addP, am);
  28529. }
  28530. if ((err == MP_OKAY) && (!inMont)) {
  28531. err = sp_384_mod_mul_norm_7(addP->x, addP->x, p384_mod);
  28532. }
  28533. if ((err == MP_OKAY) && (!inMont)) {
  28534. err = sp_384_mod_mul_norm_7(addP->y, addP->y, p384_mod);
  28535. }
  28536. if ((err == MP_OKAY) && (!inMont)) {
  28537. err = sp_384_mod_mul_norm_7(addP->z, addP->z, p384_mod);
  28538. }
  28539. if (err == MP_OKAY) {
  28540. err = sp_384_ecc_mulmod_7(point, point, k, 0, 0, heap);
  28541. }
  28542. if (err == MP_OKAY) {
  28543. sp_384_proj_point_add_7(point, point, addP, tmp);
  28544. if (map) {
  28545. sp_384_map_7(point, point, tmp);
  28546. }
  28547. err = sp_384_point_to_ecc_point_7(point, r);
  28548. }
  28549. #ifdef WOLFSSL_SP_SMALL_STACK
  28550. if (k != NULL)
  28551. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  28552. if (point != NULL)
  28553. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  28554. #endif
  28555. return err;
  28556. }
  28557. #ifdef WOLFSSL_SP_SMALL
  28558. /* Multiply the base point of P384 by the scalar and return the result.
  28559. * If map is true then convert result to affine coordinates.
  28560. *
  28561. * r Resulting point.
  28562. * k Scalar to multiply by.
  28563. * map Indicates whether to convert result to affine.
  28564. * heap Heap to use for allocation.
  28565. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  28566. */
  28567. static int sp_384_ecc_mulmod_base_7(sp_point_384* r, const sp_digit* k,
  28568. int map, int ct, void* heap)
  28569. {
  28570. /* No pre-computed values. */
  28571. return sp_384_ecc_mulmod_7(r, &p384_base, k, map, ct, heap);
  28572. }
  28573. #ifdef WOLFSSL_SP_NONBLOCK
  28574. static int sp_384_ecc_mulmod_base_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
  28575. const sp_digit* k, int map, int ct, void* heap)
  28576. {
  28577. /* No pre-computed values. */
  28578. return sp_384_ecc_mulmod_7_nb(sp_ctx, r, &p384_base, k, map, ct, heap);
  28579. }
  28580. #endif /* WOLFSSL_SP_NONBLOCK */
  28581. #else
  28582. /* Striping precomputation table.
  28583. * 8 points combined into a table of 256 points.
  28584. * Distance of 48 between points.
  28585. */
  28586. static const sp_table_entry_384 p384_table[256] = {
  28587. /* 0 */
  28588. { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  28589. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
  28590. /* 1 */
  28591. { { 0x50756649c0b528L,0x71c541ad9c707bL,0x71506d35b8838dL,
  28592. 0x4d1877fc3ce1d7L,0x6de2b645486845L,0x227025fee46c29L,
  28593. 0x134eab708a6785L },
  28594. { 0x043dad4b03a4feL,0x517ef769535846L,0x58ba0ec14286feL,
  28595. 0x47a7fecc5d6f3aL,0x1a840c6c352196L,0x3d3bb00044c72dL,
  28596. 0x0ade2af0968571L } },
  28597. /* 2 */
  28598. { { 0x0647532b0c535bL,0x52a6e0a0c52c53L,0x5085aae6b24375L,
  28599. 0x7096bb501c66b5L,0x47bdb3df9b7b7bL,0x11227e9b2f0be6L,
  28600. 0x088b172704fa51L },
  28601. { 0x0e796f2680dc64L,0x796eb06a482ebfL,0x2b441d02e04839L,
  28602. 0x19bef7312a5aecL,0x02247c38b8efb5L,0x099ed1185c329eL,
  28603. 0x1ed71d7cdb096fL } },
  28604. /* 3 */
  28605. { { 0x6a3cc39edffea5L,0x7a386fafd3f9c4L,0x366f78fbd8d6efL,
  28606. 0x529c7ad7873b80L,0x79eb30380eb471L,0x07c5d3b51760b7L,
  28607. 0x36ee4f1cc69183L },
  28608. { 0x5ba260f526b605L,0x2f1dfaf0aa6e6fL,0x6bb5ca812a5752L,
  28609. 0x3002d8d1276bc9L,0x01f82269483777L,0x1df33eaaf733cdL,
  28610. 0x2b97e555f59255L } },
  28611. /* 4 */
  28612. { { 0x480c57f26feef9L,0x4d28741c248048L,0x0c9cf8af1f0c68L,
  28613. 0x778f6a639a8016L,0x148e88c42e9c53L,0x464051757ecfe9L,
  28614. 0x1a940bd0e2a5e1L },
  28615. { 0x713a46b74536feL,0x1757b153e1d7ebL,0x30dc8c9da07486L,
  28616. 0x3b7460c1879b5eL,0x4b766c5317b315L,0x1b9de3aaf4d377L,
  28617. 0x245f124c2cf8f5L } },
  28618. /* 5 */
  28619. { { 0x426e2ee349ddd0L,0x7df3365f84a022L,0x03b005d29a7c45L,
  28620. 0x422c2337f9b5a4L,0x060494f4bde761L,0x5245e5db6da0b0L,
  28621. 0x22b71d744677f2L },
  28622. { 0x19d097b7d5a7ceL,0x6bcb468823d34cL,0x1c3692d3be1d09L,
  28623. 0x3c80ec7aa01f02L,0x7170f2ebaafd97L,0x06cbcc7d79d4e8L,
  28624. 0x04a8da511fe760L } },
  28625. /* 6 */
  28626. { { 0x79c07a4fc52870L,0x6e9034a752c251L,0x603860a367382cL,
  28627. 0x56d912d6aa87d0L,0x0a348a24abaf76L,0x6c5a23da14adcbL,
  28628. 0x3cf60479a522b2L },
  28629. { 0x18dd774c61ed22L,0x0ff30168f93b0cL,0x3f79ae15642eddL,
  28630. 0x40510f4915fbcbL,0x2c9ddfdfd1c6d6L,0x67b81b62aee55eL,
  28631. 0x2824de79b07a43L } },
  28632. /* 7 */
  28633. { { 0x6c66efe085c629L,0x48c212b7913470L,0x4480fd2d057f0aL,
  28634. 0x725ec7a89a9eb1L,0x78ce97ca1972b7L,0x54760ee70154fbL,
  28635. 0x362a40e27b9f93L },
  28636. { 0x474dc7e7b14461L,0x602819389ef037L,0x1a13bc284370b2L,
  28637. 0x0193ff1295a59dL,0x79615bde6ea5d2L,0x2e76e3d886acc1L,
  28638. 0x3bb796812e2b60L } },
  28639. /* 8 */
  28640. { { 0x04cbb3893b9a2dL,0x4c16010a18baabL,0x19f7cb50f60831L,
  28641. 0x084f400a0936c1L,0x72f1cdd5bbbf00L,0x1b30b725dc6702L,
  28642. 0x182753e4fcc50cL },
  28643. { 0x059a07eadaf9d6L,0x26d81e24bf603cL,0x45583c839dc399L,
  28644. 0x5579d4d6b1103aL,0x2e14ea59489ae7L,0x492f6e1c5ecc97L,
  28645. 0x03740dc05db420L } },
  28646. /* 9 */
  28647. { { 0x413be88510521fL,0x3753ee49982e99L,0x6cd4f7098e1cc5L,
  28648. 0x613c92bda4ec1dL,0x495378b677efe0L,0x132a2143839927L,
  28649. 0x0cf8c336291c0bL },
  28650. { 0x7fc89d2208353fL,0x751b9da85657e1L,0x349b8a97d405c3L,
  28651. 0x65a964b048428fL,0x1adf481276455eL,0x5560c8d89c2ffcL,
  28652. 0x144fc11fac21a3L } },
  28653. /* 10 */
  28654. { { 0x7611f4df5bdf53L,0x634eb16234db80L,0x3c713b8e51174cL,
  28655. 0x52c3c68ac4b2edL,0x53025ba8bebe75L,0x7175d98143105bL,
  28656. 0x33ca8e266a48faL },
  28657. { 0x0c9281d24fd048L,0x76b3177604bbf3L,0x3b26ae754e106fL,
  28658. 0x7f782275c6efc6L,0x36662538a4cb67L,0x0ca1255843e464L,
  28659. 0x2a4674e142d9bcL } },
  28660. /* 11 */
  28661. { { 0x303b4085d480d8L,0x68f23650f4fa7bL,0x552a3ceeba3367L,
  28662. 0x6da0c4947926e3L,0x6e0f5482eb8003L,0x0de717f3d6738aL,
  28663. 0x22e5dcc826a477L },
  28664. { 0x1b05b27209cfc2L,0x7f0a0b65b6e146L,0x63586549ed3126L,
  28665. 0x7d628dd2b23124L,0x383423fe510391L,0x57ff609eabd569L,
  28666. 0x301f04370131baL } },
  28667. /* 12 */
  28668. { { 0x22fe4cdb32f048L,0x7f228ebdadbf5aL,0x02a99adb2d7c8eL,
  28669. 0x01a02e05286706L,0x62d6adf627a89fL,0x49c6ce906fbf2bL,
  28670. 0x0207256dae90b9L },
  28671. { 0x23e036e71d6cebL,0x199ed8d604e3d7L,0x0c1a11c076d16fL,
  28672. 0x389291fb3da3f3L,0x47adc60f8f942eL,0x177048468e4b9aL,
  28673. 0x20c09f5e61d927L } },
  28674. /* 13 */
  28675. { { 0x129ea63615b0b8L,0x03fb4a9b588367L,0x5ad6da8da2d051L,
  28676. 0x33f782f44caeaaL,0x5a27fa80d45291L,0x6d1ed796942da4L,
  28677. 0x08435a931ef556L },
  28678. { 0x004abb25351130L,0x6d33207c6fd7e7L,0x702130972074b7L,
  28679. 0x0e34748af900f7L,0x762a531a28c87aL,0x3a903b5a4a6ac7L,
  28680. 0x1775b79c35b105L } },
  28681. /* 14 */
  28682. { { 0x7470fd846612ceL,0x7dd9b431b32e53L,0x04bcd2be1a61bcL,
  28683. 0x36ed7c5b5c260bL,0x6795f5ef0a4084L,0x46e2880b401c93L,
  28684. 0x17d246c5aa8bdeL },
  28685. { 0x707ae4db41b38dL,0x233c31f7f9558fL,0x585110ec67bdf4L,
  28686. 0x4d0cc931d0c703L,0x26fbe4356841a7L,0x64323e95239c44L,
  28687. 0x371dc9230f3221L } },
  28688. /* 15 */
  28689. { { 0x70ff1ae4b1ec9dL,0x7c1dcfddee0daaL,0x53286782188748L,
  28690. 0x6a5d9381e6f207L,0x3aa6c7d6523c4cL,0x6c02d83e0d97e2L,
  28691. 0x16a9c916b45312L },
  28692. { 0x78146744b74de8L,0x742ec415269c6fL,0x237a2c6a860e79L,
  28693. 0x186baf17ba68a7L,0x4261e8789fa51fL,0x3dc136480a5903L,
  28694. 0x1953899e0cf159L } },
  28695. /* 16 */
  28696. { { 0x0205de2f9fbe67L,0x1706fee51c886fL,0x31a0b803c712bfL,
  28697. 0x0a6aa11ede7603L,0x2463ef2a145c31L,0x615403b30e8f4aL,
  28698. 0x3f024d6c5f5c5eL },
  28699. { 0x53bc4fd4d01f95L,0x7d512ac15a692cL,0x72be38fcfe6aa0L,
  28700. 0x437f0b77bbca1eL,0x7fdcf70774a10eL,0x392d6c5cde37f3L,
  28701. 0x229cbce79621d1L } },
  28702. /* 17 */
  28703. { { 0x2de4da2341c342L,0x5ca9d4e08844e7L,0x60dd073bcf74c9L,
  28704. 0x4f30aa499b63ecL,0x23efd1eafa00d5L,0x7c99a7db1257b3L,
  28705. 0x00febc9b3171b1L },
  28706. { 0x7e2fcf3045f8acL,0x2a642e9e3ce610L,0x23f82be69c5299L,
  28707. 0x66e49ad967c279L,0x1c895ddfd7a842L,0x798981e22f6d25L,
  28708. 0x0d595cb59322f3L } },
  28709. /* 18 */
  28710. { { 0x4bac017d8c1bbaL,0x73872161e7aafdL,0x0fd865f43d8163L,
  28711. 0x019d89457708b7L,0x1b983c4dd70684L,0x095e109b74d841L,
  28712. 0x25f1f0b3e0c76fL },
  28713. { 0x4e61ddf96010e8L,0x1c40a53f542e5eL,0x01a74dfc8365f9L,
  28714. 0x69b36b92773333L,0x08e0fccc139ed3L,0x266d216ddc4269L,
  28715. 0x1f2b47717ce9b5L } },
  28716. /* 19 */
  28717. { { 0x0a9a81da57a41fL,0x0825d800736cccL,0x2d7876b4579d28L,
  28718. 0x3340ea6211a1e3L,0x49e89284f3ff54L,0x6276a210fe2c6eL,
  28719. 0x01c3c8f31be7cbL },
  28720. { 0x2211da5d186e14L,0x1e6ffbb61bfea8L,0x536c7d060211d2L,
  28721. 0x320168720d1d55L,0x5835525ed667baL,0x5125e52495205eL,
  28722. 0x16113b9f3e9129L } },
  28723. /* 20 */
  28724. { { 0x3086073f3b236fL,0x283b03c443b5f5L,0x78e49ed0a067a7L,
  28725. 0x2a878fb79fb2b8L,0x662f04348a9337L,0x57ee2cf732d50bL,
  28726. 0x18b50dd65fd514L },
  28727. { 0x5feb9ef2955926L,0x2c3edbef06a7b0L,0x32728dad651029L,
  28728. 0x116d00b1c4b347L,0x13254052bf1a1aL,0x3e77bf7fee5ec1L,
  28729. 0x253943ca388882L } },
  28730. /* 21 */
  28731. { { 0x32e5b33062e8afL,0x46ebd147a6d321L,0x2c8076dec6a15cL,
  28732. 0x7328d511ff0d80L,0x10ad7e926def0eL,0x4e8ca85937d736L,
  28733. 0x02638c26e8bf2fL },
  28734. { 0x1deeb3fff1d63fL,0x5014417fa6e8efL,0x6e1da3de5c8f43L,
  28735. 0x7ca942b42295d9L,0x23faacf75bb4d1L,0x4a71fcd680053dL,
  28736. 0x04af4f90204dceL } },
  28737. /* 22 */
  28738. { { 0x23780d104cbba5L,0x4e8ff46bba9980L,0x2072a6da8d881fL,
  28739. 0x3cc3d881ae11c9L,0x2eee84ff19be89L,0x69b708ed77f004L,
  28740. 0x2a82928534eef9L },
  28741. { 0x794331187d4543L,0x70e0f3edc0cc41L,0x3ab1fa0b84c854L,
  28742. 0x1478355c1d87baL,0x6f35fa7748ba28L,0x37b8be0531584dL,
  28743. 0x03c3141c23a69fL } },
  28744. /* 23 */
  28745. { { 0x5c244cdef029ddL,0x0d0f0a0cc37018L,0x17f8476604f6afL,
  28746. 0x13a6dd6ccc95c3L,0x5a242e9801b8f6L,0x211ca9cc632131L,
  28747. 0x264a6a46a4694fL },
  28748. { 0x3ffd7235285887L,0x284be28302046fL,0x57f4b9b882f1d6L,
  28749. 0x5e21772c940661L,0x7619a735c600cfL,0x2f76f5a50c9106L,
  28750. 0x28d89c8c69de31L } },
  28751. /* 24 */
  28752. { { 0x799b5c91361ed8L,0x36ead8c66cd95cL,0x046c9969a91f5cL,
  28753. 0x46bbdba2a66ea9L,0x29db0e0215a599L,0x26c8849b36f756L,
  28754. 0x22c3feb31ff679L },
  28755. { 0x585d1237b5d9efL,0x5ac57f522e8e8dL,0x617e66e8b56c41L,
  28756. 0x68826f276823cfL,0x0983f0e6f39231L,0x4e1075099084bdL,
  28757. 0x2a541f82be0416L } },
  28758. /* 25 */
  28759. { { 0x468a6e14cf381cL,0x4f7b845c6399edL,0x36aa29732ebe74L,
  28760. 0x19c726911ab46aL,0x2ad1fe431eec0eL,0x301e35051fd1eaL,
  28761. 0x36da815e7a1ab3L },
  28762. { 0x05672e4507832aL,0x4ebf10fca51251L,0x6015843421cff0L,
  28763. 0x3affad832fc013L,0x712b58d9b45540L,0x1e4751d1f6213eL,
  28764. 0x0e7c2b218bafa7L } },
  28765. /* 26 */
  28766. { { 0x7abf784c52edf5L,0x6fcb4b135ca7b1L,0x435e46ac5f735cL,
  28767. 0x67f8364ca48c5fL,0x46d45b5fbd956bL,0x10deda6065db94L,
  28768. 0x0b37fdf85068f9L },
  28769. { 0x74b3ba61f47ec8L,0x42c7ddf08c10ccL,0x1531a1fe422a20L,
  28770. 0x366f913d12be38L,0x6a846e30cb2edfL,0x2785898c994fedL,
  28771. 0x061be85f331af3L } },
  28772. /* 27 */
  28773. { { 0x23f5361dfcb91eL,0x3c26c8da6b1491L,0x6e444a1e620d65L,
  28774. 0x0c3babd5e8ac13L,0x573723ce612b82L,0x2d10e62a142c37L,
  28775. 0x3d1a114c2d98bdL },
  28776. { 0x33950b401896f6L,0x7134efe7c12110L,0x31239fd2978472L,
  28777. 0x30333bf5978965L,0x79f93313dd769fL,0x457fb9e11662caL,
  28778. 0x190a73b251ae3cL } },
  28779. /* 28 */
  28780. { { 0x04dd54bb75f9a4L,0x0d7253a76ae093L,0x08f5b930792bbcL,
  28781. 0x041f79adafc265L,0x4a9ff24c61c11bL,0x0019c94e724725L,
  28782. 0x21975945d9cc2aL },
  28783. { 0x3dfe76722b4a2bL,0x17f2f6107c1d94L,0x546e1ae2944b01L,
  28784. 0x53f1f06401e72dL,0x2dbe43fc7632d6L,0x5639132e185903L,
  28785. 0x0f2f34eb448385L } },
  28786. /* 29 */
  28787. { { 0x7b4cc7ec30ce93L,0x58fb6e4e4145f7L,0x5d1ed5540043b5L,
  28788. 0x19ffbe1f633adfL,0x5bfc0907259033L,0x6378f872e7ca0eL,
  28789. 0x2c127b2c01eb3cL },
  28790. { 0x076eaf4f58839cL,0x2db54560bc9f68L,0x42ad0319b84062L,
  28791. 0x46c325d1fb019dL,0x76d2a19ee9eebcL,0x6fbd6d9e2aa8f7L,
  28792. 0x2396a598fe0991L } },
  28793. /* 30 */
  28794. { { 0x662fddf7fbd5e1L,0x7ca8ed22563ad3L,0x5b4768efece3b3L,
  28795. 0x643786a422d1eaL,0x36ce80494950e1L,0x1a30795b7f2778L,
  28796. 0x107f395c93f332L },
  28797. { 0x7939c28332c144L,0x491610e3c8dc0bL,0x099ba2bfdac5fcL,
  28798. 0x5c2e3149ec29a7L,0x31b731d06f1dc3L,0x1cbb60d465d462L,
  28799. 0x3ca5461362cfd9L } },
  28800. /* 31 */
  28801. { { 0x653ff736ddc103L,0x7c6f2bdec0dfb2L,0x73f81b73a097d0L,
  28802. 0x05b775f84f180fL,0x56b2085af23413L,0x0d6f36256a61feL,
  28803. 0x26d3ed267fa68fL },
  28804. { 0x54f89251d27ac2L,0x4fc6ad94a71202L,0x7ebf01969b4cc5L,
  28805. 0x7ba364dbc14760L,0x4f8370959a2587L,0x7b7631e37c6188L,
  28806. 0x29e51845f104cbL } },
  28807. /* 32 */
  28808. { { 0x426b775e3c647bL,0x327319e0a69180L,0x0c5cb034f6ff2fL,
  28809. 0x73aa39b98e9897L,0x7ee615f49fde6eL,0x3f712aa61e0db4L,
  28810. 0x33ca06c2ba2ce9L },
  28811. { 0x14973541b8a543L,0x4b4e6101ba61faL,0x1d94e4233d0698L,
  28812. 0x501513c715d570L,0x1b8f8c3d01436bL,0x52f41a0445cf64L,
  28813. 0x3f709c3a75fb04L } },
  28814. /* 33 */
  28815. { { 0x073c0cbc7f41d6L,0x227c36f5ac8201L,0x508e110fef65d8L,
  28816. 0x0f317229529b7fL,0x45fc6030d00e24L,0x118a65d30cebeaL,
  28817. 0x3340cc4223a448L },
  28818. { 0x204c999797612cL,0x7c05dd4ce9c5a3L,0x7b865d0a8750e4L,
  28819. 0x2f82c876ab7d34L,0x2243ddd2ab4808L,0x6834b9df8a4914L,
  28820. 0x123319ed950e0fL } },
  28821. /* 34 */
  28822. { { 0x50430efc14ab48L,0x7e9e4ce0d4e89cL,0x2332207fd8656dL,
  28823. 0x4a2809e97f4511L,0x2162bb1b968e2dL,0x29526d54af2972L,
  28824. 0x13edd9adcd939dL },
  28825. { 0x793bca31e1ff7fL,0x6b959c9e4d2227L,0x628ac27809a5baL,
  28826. 0x2c71ffc7fbaa5fL,0x0c0b058f13c9ceL,0x5676eae68de2cfL,
  28827. 0x35508036ea19a4L } },
  28828. /* 35 */
  28829. { { 0x030bbd6dda1265L,0x67f9d12e31bb34L,0x7e4d8196e3ded3L,
  28830. 0x7b9120e5352498L,0x75857bce72d875L,0x4ead976a396caeL,
  28831. 0x31c5860553a64dL },
  28832. { 0x1a0f792ee32189L,0x564c4efb8165d0L,0x7adc7d1a7fbcbeL,
  28833. 0x7ed7c2ccf327b7L,0x35df1b448ce33dL,0x6f67eb838997cdL,
  28834. 0x3ee37ec0077917L } },
  28835. /* 36 */
  28836. { { 0x345fa74d5bb921L,0x097c9a56ccfd8eL,0x00a0b5e8f971f8L,
  28837. 0x723d95223f69d4L,0x08e2e5c2777f87L,0x68b13676200109L,
  28838. 0x26ab5df0acbad6L },
  28839. { 0x01bca7daac34aeL,0x49ca4d5f664dadL,0x110687b850914bL,
  28840. 0x1203d6f06443c9L,0x7a2ac743b04d4cL,0x40d96bd3337f82L,
  28841. 0x13728be0929c06L } },
  28842. /* 37 */
  28843. { { 0x631ca61127bc1aL,0x2b362fd5a77cd1L,0x17897d68568fb7L,
  28844. 0x21070af33db5b2L,0x6872e76221794aL,0x436f29fb076963L,
  28845. 0x1f2acfc0ecb7b3L },
  28846. { 0x19bf15ca9b3586L,0x32489a4a17aee2L,0x2b31af3c929551L,
  28847. 0x0db7c420b9b19fL,0x538c39bd308c2bL,0x438775c0dea88fL,
  28848. 0x1537304d7cd07fL } },
  28849. /* 38 */
  28850. { { 0x53598d943caf0dL,0x1d5244bfe266adL,0x7158feb7ab3811L,
  28851. 0x1f46e13cf6fb53L,0x0dcab632eb9447L,0x46302968cfc632L,
  28852. 0x0b53d3cc5b6ec7L },
  28853. { 0x69811ca143b7caL,0x5865bcf9f2a11aL,0x74ded7fa093b06L,
  28854. 0x1c878ec911d5afL,0x04610e82616e49L,0x1e157fe9640eb0L,
  28855. 0x046e6f8561d6c2L } },
  28856. /* 39 */
  28857. { { 0x631a3d3bbe682cL,0x3a4ce9dde5ba95L,0x28f11f7502f1f1L,
  28858. 0x0a55cf0c957e88L,0x495e4ec7e0a3bcL,0x30ad4d87ba365cL,
  28859. 0x0217b97a4c26f3L },
  28860. { 0x01a9088c2e67fdL,0x7501c4c3d5e5e7L,0x265b7bb854c820L,
  28861. 0x729263c87e6b52L,0x308b9e3b8fb035L,0x33f1b86c1b23abL,
  28862. 0x0e81b8b21fc99cL } },
  28863. /* 40 */
  28864. { { 0x59f5a87237cac0L,0x6b3a86b0cf28b9L,0x13a53db13a4fc2L,
  28865. 0x313c169a1c253bL,0x060158304ed2bbL,0x21e171b71679bcL,
  28866. 0x10cdb754d76f86L },
  28867. { 0x44355392ab473aL,0x64eb7cbda08caeL,0x3086426a900c71L,
  28868. 0x49016ed9f3c33cL,0x7e6354ab7e04f9L,0x17c4c91a40cd2eL,
  28869. 0x3509f461024c66L } },
  28870. /* 41 */
  28871. { { 0x2848f50f9b5a31L,0x68d1755b6c5504L,0x48cd5d5672ec00L,
  28872. 0x4d77421919d023L,0x1e1e349ef68807L,0x4ab5130cf415d7L,
  28873. 0x305464c6c7dbe6L },
  28874. { 0x64eb0bad74251eL,0x64c6957e52bda4L,0x6c12583440dee6L,
  28875. 0x6d3bee05b00490L,0x186970de53dbc4L,0x3be03b37567a56L,
  28876. 0x2b553b1ebdc55bL } },
  28877. /* 42 */
  28878. { { 0x74dc3579efdc58L,0x26d29fed1bb71cL,0x334c825a9515afL,
  28879. 0x433c1e839273a6L,0x0d8a4e41cff423L,0x3454098fe42f8eL,
  28880. 0x1046674bf98686L },
  28881. { 0x09a3e029c05dd2L,0x54d7cfc7fb53a7L,0x35f0ad37e14d7cL,
  28882. 0x73a294a13767b9L,0x3f519678275f4fL,0x788c63393993a4L,
  28883. 0x0781680b620123L } },
  28884. /* 43 */
  28885. { { 0x4c8e2ed4d5ffe8L,0x112db7d42fe4ebL,0x433b8f2d2be2edL,
  28886. 0x23e30b29a82cbcL,0x35d2f4c06ee85aL,0x78ff31ffe4b252L,
  28887. 0x0d31295c8cbff5L },
  28888. { 0x314806ea0376a2L,0x4ea09e22bc0589L,0x0879575f00ba97L,
  28889. 0x188226d2996bb7L,0x7799368dc9411fL,0x7ab24e5c8cae36L,
  28890. 0x2b6a8e2ee4ea33L } },
  28891. /* 44 */
  28892. { { 0x70c7127d4ed72aL,0x24c9743ef34697L,0x2fd30e7a93683aL,
  28893. 0x538a89c246012cL,0x6c660a5394ed82L,0x79a95ea239d7e0L,
  28894. 0x3f3af3bbfb170dL },
  28895. { 0x3b75aa779ae8c1L,0x33995a3cc0dde4L,0x7489d5720b7bfdL,
  28896. 0x599677ef9fa937L,0x3defd64c5ab44bL,0x27d52dc234522bL,
  28897. 0x2ac65d1a8450e0L } },
  28898. /* 45 */
  28899. { { 0x478585ec837d7dL,0x5f7971dc174887L,0x67576ed7bb296dL,
  28900. 0x5a78e529a74926L,0x640f73f4fa104bL,0x7d42a8b16e4730L,
  28901. 0x108c7eaa75fd01L },
  28902. { 0x60661ef96e6896L,0x18d3a0761f3aa7L,0x6e71e163455539L,
  28903. 0x165827d6a7e583L,0x4e7f77e9527935L,0x790bebe2ae912eL,
  28904. 0x0b8fe9561adb55L } },
  28905. /* 46 */
  28906. { { 0x4d48036a9951a8L,0x371084f255a085L,0x66aeca69cea2c5L,
  28907. 0x04c99f40c745e7L,0x08dc4bfd9a0924L,0x0b0ec146b29df7L,
  28908. 0x05106218d01c91L },
  28909. { 0x2a56ee99caedc7L,0x5d9b23a203922cL,0x1ce4c80b6a3ec4L,
  28910. 0x2666bcb75338cbL,0x185a81aac8c4aaL,0x2b4fb60a06c39eL,
  28911. 0x0327e1b3633f42L } },
  28912. /* 47 */
  28913. { { 0x72814710b2a556L,0x52c864f6e16534L,0x4978de66ddd9f2L,
  28914. 0x151f5950276cf0L,0x450ac6781d2dc2L,0x114b7a22dd61b2L,
  28915. 0x3b32b07f29faf8L },
  28916. { 0x68444fdc2d6e94L,0x68526bd9e437bcL,0x0ca780e8b0d887L,
  28917. 0x69f3f850a716aaL,0x500b953e42cd57L,0x4e57744d812e7dL,
  28918. 0x000a5f0e715f48L } },
  28919. /* 48 */
  28920. { { 0x2aab10b8243a7dL,0x727d1f4b18b675L,0x0e6b9fdd91bbbbL,
  28921. 0x0d58269fc337e5L,0x45d6664105a266L,0x11946af1b14072L,
  28922. 0x2c2334f91e46e1L },
  28923. { 0x6dc5f8756d2411L,0x21b34eaa25188bL,0x0d2797da83529eL,
  28924. 0x324df55616784bL,0x7039ec66d267dfL,0x2de79cdb2d108cL,
  28925. 0x14011b1ad0bde0L } },
  28926. /* 49 */
  28927. { { 0x2e160266425043L,0x55fbe11b712125L,0x7e3c58b3947fd9L,
  28928. 0x67aacc79c37ad3L,0x4a18e18d2dea0fL,0x5eef06e5674351L,
  28929. 0x37c3483ae33439L },
  28930. { 0x5d5e1d75bb4045L,0x0f9d72db296efdL,0x60b1899dd894a9L,
  28931. 0x06e8818ded949aL,0x747fd853c39434L,0x0953b937d9efabL,
  28932. 0x09f08c0beeb901L } },
  28933. /* 50 */
  28934. { { 0x1d208a8f2d49ceL,0x54042c5be1445aL,0x1c2681fd943646L,
  28935. 0x219c8094e2e674L,0x442cddf07238b8L,0x574a051c590832L,
  28936. 0x0b72f4d61c818aL },
  28937. { 0x7bc3cbe4680967L,0x0c8b3f25ae596bL,0x0445b0da74a9efL,
  28938. 0x0bbf46c40363b7L,0x1df575c50677a3L,0x016ea6e73d68adL,
  28939. 0x0b5207bd8db0fdL } },
  28940. /* 51 */
  28941. { { 0x2d39fdfea1103eL,0x2b252bf0362e34L,0x63d66c992baab9L,
  28942. 0x5ac97706de8550L,0x0cca390c39c1acL,0x0d9bec5f01b2eaL,
  28943. 0x369360a0f7e5f3L },
  28944. { 0x6dd3461e201067L,0x70b2d3f63ed614L,0x487580487c54c7L,
  28945. 0x6020e48a44af2aL,0x1ccf80b21aab04L,0x3cf3b12d88d798L,
  28946. 0x349368eccc506fL } },
  28947. /* 52 */
  28948. { { 0x5a053753b0a354L,0x65e818dbb9b0aeL,0x7d5855ee50e4bfL,
  28949. 0x58dc06885c7467L,0x5ee15073e57bd3L,0x63254ebc1e07fdL,
  28950. 0x1d48e0392aa39bL },
  28951. { 0x4e227c6558ffe9L,0x0c3033d8a82a3eL,0x7bde65c214e8d2L,
  28952. 0x6e23561559c16aL,0x5094c5e6deaffdL,0x78dca2880f1f91L,
  28953. 0x3d9d3f947d838dL } },
  28954. /* 53 */
  28955. { { 0x387ae5af63408fL,0x6d539aeb4e6edfL,0x7f3d3186368e70L,
  28956. 0x01a6446bc19989L,0x35288fbcd4482fL,0x39288d34ec2736L,
  28957. 0x1de9c47159ad76L },
  28958. { 0x695dc7944f8d65L,0x3eca2c35575094L,0x0c918059a79b69L,
  28959. 0x4573a48c32a74eL,0x580d8bc8b93f52L,0x190be3a3d071eaL,
  28960. 0x2333e686b3a8cbL } },
  28961. /* 54 */
  28962. { { 0x2b110c7196fee2L,0x3ac70e99128a51L,0x20a6bb6b75d5e6L,
  28963. 0x5f447fa513149aL,0x560d69714cc7b2L,0x1d3ee25279fab1L,
  28964. 0x369adb2ccca959L },
  28965. { 0x3fddb13dd821c2L,0x70bf21ba647be8L,0x64121227e3cbc9L,
  28966. 0x12633a4c892320L,0x3c15c61660f26dL,0x1932c3b3d19900L,
  28967. 0x18c718563eab71L } },
  28968. /* 55 */
  28969. { { 0x72ebe0fd752366L,0x681c2737d11759L,0x143c805e7ae4f0L,
  28970. 0x78ed3c2cc7b324L,0x5c16e14820254fL,0x226a4f1c4ec9f0L,
  28971. 0x2891bb915eaac6L },
  28972. { 0x061eb453763b33L,0x07f88b81781a87L,0x72b5ac7a87127cL,
  28973. 0x7ea4e4cd7ff8b5L,0x5e8c3ce33908b6L,0x0bcb8a3d37feffL,
  28974. 0x01da9e8e7fc50bL } },
  28975. /* 56 */
  28976. { { 0x639dfe9e338d10L,0x32dfe856823608L,0x46a1d73bca3b9aL,
  28977. 0x2da685d4b0230eL,0x6e0bc1057b6d69L,0x7144ec724a5520L,
  28978. 0x0b067c26b87083L },
  28979. { 0x0fc3f0eef4c43dL,0x63500f509552b7L,0x220d74af6f8b86L,
  28980. 0x038996eafa2aa9L,0x7f6750f4aee4d2L,0x3e1d3f06718720L,
  28981. 0x1ea1d37243814cL } },
  28982. /* 57 */
  28983. { { 0x322d4597c27050L,0x1beeb3ce17f109L,0x15e5ce2e6ef42eL,
  28984. 0x6c8be27da6b3a0L,0x66e3347f4d5f5cL,0x7172133899c279L,
  28985. 0x250aff4e548743L },
  28986. { 0x28f0f6a43b566dL,0x0cd2437fefbca0L,0x5b1108cb36bdbaL,
  28987. 0x48a834d41fb7c2L,0x6cb8565680579fL,0x42da2412b45d9fL,
  28988. 0x33dfc1abb6c06eL } },
  28989. /* 58 */
  28990. { { 0x56e3c48ef96c80L,0x65667bb6c1381eL,0x09f70514375487L,
  28991. 0x1548ff115f4a08L,0x237de2d21a0710L,0x1425cdee9f43dfL,
  28992. 0x26a6a42e055b0aL },
  28993. { 0x4ea9ea9dc7dfcbL,0x4df858583ac58aL,0x1d274f819f1d39L,
  28994. 0x26e9c56cf91fcbL,0x6cee31c7c3a465L,0x0bb8e00b108b28L,
  28995. 0x226158da117301L } },
  28996. /* 59 */
  28997. { { 0x5a7cd4fce73946L,0x7b6a462d0ac653L,0x732ea4bb1a3da5L,
  28998. 0x7c8e9f54711af4L,0x0a6cd55d4655f9L,0x341e6d13e4754aL,
  28999. 0x373c87098879a8L },
  29000. { 0x7bc82e61b818bfL,0x5f2db48f44879fL,0x2a2f06833f1d28L,
  29001. 0x494e5b691a74c0L,0x17d6cf35fd6b57L,0x5f7028d1c25dfcL,
  29002. 0x377a9ab9562cb6L } },
  29003. /* 60 */
  29004. { { 0x4de8877e787b2eL,0x183e7352621a52L,0x2ab0509974962bL,
  29005. 0x045a450496cb8aL,0x3bf7118b5591c7L,0x7724f98d761c35L,
  29006. 0x301607e8d5a0c1L },
  29007. { 0x0f58a3f24d4d58L,0x3771c19c464f3cL,0x06746f9c0bfafaL,
  29008. 0x56564c9c8feb52L,0x0d66d9a7d8a45fL,0x403578141193caL,
  29009. 0x00b0d0bdc19260L } },
  29010. /* 61 */
  29011. { { 0x571407157bdbc2L,0x138d5a1c2c0b99L,0x2ee4a8057dcbeaL,
  29012. 0x051ff2b58e9ed1L,0x067378ad9e7cdaL,0x7cc2c1db97a49eL,
  29013. 0x1e7536ccd849d6L },
  29014. { 0x531fd95f3497c4L,0x55dc08325f61a7L,0x144e942bce32bfL,
  29015. 0x642d572f09e53aL,0x556ff188261678L,0x3e79c0d9d513d6L,
  29016. 0x0bbbc6656f6d52L } },
  29017. /* 62 */
  29018. { { 0x57d3eb50596edcL,0x26c520a487451dL,0x0a92db40aea8d6L,
  29019. 0x27df6345109616L,0x7733d611fd727cL,0x61d14171fef709L,
  29020. 0x36169ae417c36bL },
  29021. { 0x6899f5d4091cf7L,0x56ce5dfe4ed0c1L,0x2c430ce5913fbcL,
  29022. 0x1b13547e0f8caeL,0x4840a8275d3699L,0x59b8ef209e81adL,
  29023. 0x22362dff5ea1a2L } },
  29024. /* 63 */
  29025. { { 0x7237237bd98425L,0x73258e162a9d0bL,0x0a59a1e8bb5118L,
  29026. 0x4190a7ee5d8077L,0x13684905fdbf7cL,0x31c4033a52626bL,
  29027. 0x010a30e4fbd448L },
  29028. { 0x47623f981e909aL,0x670af7c325b481L,0x3d004241fa4944L,
  29029. 0x0905a2ca47f240L,0x58f3cdd7a187c3L,0x78b93aee05b43fL,
  29030. 0x19b91d4ef8d63bL } },
  29031. /* 64 */
  29032. { { 0x0d34e116973cf4L,0x4116fc9e69ee0eL,0x657ae2b4a482bbL,
  29033. 0x3522eed134d7cdL,0x741e0dde0a036aL,0x6554316a51cc7bL,
  29034. 0x00f31c6ca89837L },
  29035. { 0x26770aa06b1dd7L,0x38233a4ceba649L,0x065a1110c96feaL,
  29036. 0x18d367839e0f15L,0x794543660558d1L,0x39b605139065dcL,
  29037. 0x29abbec071b637L } },
  29038. /* 65 */
  29039. { { 0x1464b401ab5245L,0x16db891b27ff74L,0x724eb49cb26e34L,
  29040. 0x74fee3bc9cc33eL,0x6a8bdbebe085eaL,0x5c2e75ca207129L,
  29041. 0x1d03f2268e6b08L },
  29042. { 0x28b0a328e23b23L,0x645dc26209a0bcL,0x62c28990348d49L,
  29043. 0x4dd9be1fa333d0L,0x6183aac74a72e4L,0x1d6f3ee69e1d03L,
  29044. 0x2fff96db0ff670L } },
  29045. /* 66 */
  29046. { { 0x2358f5c6a2123fL,0x5b2bfc51bedb63L,0x4fc6674be649ecL,
  29047. 0x51fc16e44b813aL,0x2ffe10a73754c1L,0x69a0c7a053aeefL,
  29048. 0x150e605fb6b9b4L },
  29049. { 0x179eef6b8b83c4L,0x64293b28ad05efL,0x331795fab98572L,
  29050. 0x09823eec78727dL,0x36508042b89b81L,0x65f1106adb927eL,
  29051. 0x2fc0234617f47cL } },
  29052. /* 67 */
  29053. { { 0x12aa244e8068dbL,0x0c834ae5348f00L,0x310fc1a4771cb3L,
  29054. 0x6c90a2f9e19ef9L,0x77946fa0573471L,0x37f5df81e5f72fL,
  29055. 0x204f5d72cbe048L },
  29056. { 0x613c724383bba6L,0x1ce14844967e0aL,0x797c85e69aa493L,
  29057. 0x4fb15b0f2ce765L,0x5807978e2e8aa7L,0x52c75859876a75L,
  29058. 0x1554635c763d3eL } },
  29059. /* 68 */
  29060. { { 0x4f292200623f3bL,0x6222be53d7fe07L,0x1e02a9a08c2571L,
  29061. 0x22c6058216b912L,0x1ec20044c7ba17L,0x53f94c5efde12bL,
  29062. 0x102b8aadfe32a4L },
  29063. { 0x45377aa927b102L,0x0d41b8062ee371L,0x77085a9018e62aL,
  29064. 0x0c69980024847cL,0x14739b423a73a9L,0x52ec6961fe3c17L,
  29065. 0x38a779c94b5a7dL } },
  29066. /* 69 */
  29067. { { 0x4d14008435af04L,0x363bfd8325b4e8L,0x48cdb715097c95L,
  29068. 0x1b534540f8bee0L,0x4ca1e5c90c2a76L,0x4b52c193d6eee0L,
  29069. 0x277a33c79becf5L },
  29070. { 0x0fee0d511d3d06L,0x4627f3d6a58f8cL,0x7c81ac245119b8L,
  29071. 0x0c8d526ba1e07aL,0x3dbc242f55bac2L,0x2399df8f91fffdL,
  29072. 0x353e982079ba3bL } },
  29073. /* 70 */
  29074. { { 0x6405d3b0ab9645L,0x7f31abe3ee236bL,0x456170a9babbb1L,
  29075. 0x09634a2456a118L,0x5b1c6045acb9e5L,0x2c75c20d89d521L,
  29076. 0x2e27ccf5626399L },
  29077. { 0x307cd97fed2ce4L,0x1c2fbb02b64087L,0x542a068d27e64dL,
  29078. 0x148c030b3bc6a6L,0x671129e616ade5L,0x123f40db60dafcL,
  29079. 0x07688f3c621220L } },
  29080. /* 71 */
  29081. { { 0x1c46b342f2c4b5L,0x27decc0b3c8f04L,0x0d9bd433464c54L,
  29082. 0x1f3d893b818572L,0x2536043b536c94L,0x57e00c4b19ebf9L,
  29083. 0x3938fb9e5ad55eL },
  29084. { 0x6b390024c8b22fL,0x4583f97e20a976L,0x2559d24abcbad7L,
  29085. 0x67a9cabc9bd8c6L,0x73a56f09432e4aL,0x79eb0beb53a3b7L,
  29086. 0x3e19d47f6f8221L } },
  29087. /* 72 */
  29088. { { 0x7399cb9d10e0b2L,0x32acc1b8a36e2aL,0x287d60c2407035L,
  29089. 0x42c82420ea4b5cL,0x13f286658bc268L,0x3c91181156e064L,
  29090. 0x234b83dcdeb963L },
  29091. { 0x79bc95486cfee6L,0x4d8fd3cb78af36L,0x07362ba5e80da8L,
  29092. 0x79d024a0d681b0L,0x6b58406907f87fL,0x4b40f1e977e58fL,
  29093. 0x38dcc6fd5fa342L } },
  29094. /* 73 */
  29095. { { 0x72282be1cd0abeL,0x02bd0fdfdf44e5L,0x19b0e0d2f753e4L,
  29096. 0x4514e76ce8c4c0L,0x02ebc9c8cdcc1bL,0x6ac0c0373e9fddL,
  29097. 0x0dc414af1c81a9L },
  29098. { 0x7a109246f32562L,0x26982e6a3768edL,0x5ecd8daed76ab5L,
  29099. 0x2eaa70061eb261L,0x09e7c038a8c514L,0x2a2603cc300658L,
  29100. 0x25d93ab9e55cd4L } },
  29101. /* 74 */
  29102. { { 0x11b19fcbd5256aL,0x41e4d94274770fL,0x0133c1a411001fL,
  29103. 0x360bac481dbca3L,0x45908b18a9c22bL,0x1e34396fafb03aL,
  29104. 0x1b84fea7486edaL },
  29105. { 0x183c62a71e6e16L,0x5f1dc30e93da8eL,0x6cb97b502573c3L,
  29106. 0x3708bf0964e3fcL,0x35a7f042eeacceL,0x56370da902c27fL,
  29107. 0x3a873c3b72797fL } },
  29108. /* 75 */
  29109. { { 0x6573c9cea4cc9bL,0x2c3b5f9d91e6dcL,0x2a90e2dbd9505eL,
  29110. 0x66a75444025f81L,0x1571fb894b03cdL,0x5d1a1f00fd26f3L,
  29111. 0x0d19a9fd618855L },
  29112. { 0x659acd56515664L,0x7279478bd616a3L,0x09a909e76d56c3L,
  29113. 0x2fd70474250358L,0x3a1a25c850579cL,0x11b9e0f71b74ccL,
  29114. 0x1268daef3d1bffL } },
  29115. /* 76 */
  29116. { { 0x7f5acc46d93106L,0x5bc15512f939c8L,0x504b5f92f996deL,
  29117. 0x25965549be7a64L,0x357a3a2ae9b80dL,0x3f2bcf9c139cc0L,
  29118. 0x0a7ddd99f23b35L },
  29119. { 0x6868f5a8a0b1c5L,0x319ec52f15b1beL,0x0770000a849021L,
  29120. 0x7f4d50287bd608L,0x62c971d28a9d7fL,0x164e89309acb72L,
  29121. 0x2a29f002cf4a32L } },
  29122. /* 77 */
  29123. { { 0x58a852ae11a338L,0x27e3a35f2dcef8L,0x494d5731ce9e18L,
  29124. 0x49516f33f4bb3eL,0x386b26ba370097L,0x4e8fac1ec30248L,
  29125. 0x2ac26d4c44455dL },
  29126. { 0x20484198eb9dd0L,0x75982a0e06512bL,0x152271b9279b05L,
  29127. 0x5908a9857e36d2L,0x6a933ab45a60abL,0x58d8b1acb24fafL,
  29128. 0x28fbcf19425590L } },
  29129. /* 78 */
  29130. { { 0x5420e9df010879L,0x4aba72aec2f313L,0x438e544eda7494L,
  29131. 0x2e8e189ce6f7eaL,0x2f771e4efe45bdL,0x0d780293bce7efL,
  29132. 0x1569ad3d0d02acL },
  29133. { 0x325251ebeaf771L,0x02510f1a8511e2L,0x3863816bf8aad1L,
  29134. 0x60fdb15fe6ac19L,0x4792aef52a348cL,0x38e57a104e9838L,
  29135. 0x0d171611a1df1bL } },
  29136. /* 79 */
  29137. { { 0x15ceb0bea65e90L,0x6e56482db339bcL,0x37f618f7b0261fL,
  29138. 0x6351abc226dabcL,0x0e999f617b74baL,0x37d3cc57af5b69L,
  29139. 0x21df2b987aac68L },
  29140. { 0x2dddaa3a358610L,0x2da264bc560e47L,0x545615d538bf13L,
  29141. 0x1c95ac244b8cc7L,0x77de1f741852cbL,0x75d324f00996abL,
  29142. 0x3a79b13b46aa3bL } },
  29143. /* 80 */
  29144. { { 0x7db63998683186L,0x6849bb989d530cL,0x7b53c39ef7ed73L,
  29145. 0x53bcfbf664d3ffL,0x25ef27c57f71c7L,0x50120ee80f3ad6L,
  29146. 0x243aba40ed0205L },
  29147. { 0x2aae5e0ee1fcebL,0x3449d0d8343fbeL,0x5b2864fb7cffc7L,
  29148. 0x64dceb5407ac3eL,0x20303a5695523dL,0x3def70812010b2L,
  29149. 0x07be937f2e9b6fL } },
  29150. /* 81 */
  29151. { { 0x5838f9e0540015L,0x728d8720efb9f7L,0x1ab5864490b0c8L,
  29152. 0x6531754458fdcfL,0x600ff9612440c0L,0x48735b36a585b7L,
  29153. 0x3d4aaea86b865dL },
  29154. { 0x6898942cac32adL,0x3c84c5531f23a1L,0x3c9dbd572f7edeL,
  29155. 0x5691f0932a2976L,0x186f0db1ac0d27L,0x4fbed18bed5bc9L,
  29156. 0x0e26b0dee0b38cL } },
  29157. /* 82 */
  29158. { { 0x1188b4f8e60f5bL,0x602a915455b4a2L,0x60e06af289ff99L,
  29159. 0x579fe4bed999e5L,0x2bc03b15e6d9ddL,0x1689649edd66d5L,
  29160. 0x3165e277dca9d2L },
  29161. { 0x7cb8a529cf5279L,0x57f8035b34d84dL,0x352e2eb26de8f1L,
  29162. 0x6406820c3367c4L,0x5d148f4c899899L,0x483e1408482e15L,
  29163. 0x1680bd1e517606L } },
  29164. /* 83 */
  29165. { { 0x5c877cc1c90202L,0x2881f158eae1f4L,0x6f45e207df4267L,
  29166. 0x59280eba1452d8L,0x4465b61e267db5L,0x171f1137e09e5cL,
  29167. 0x1368eb821daa93L },
  29168. { 0x70fe26e3e66861L,0x52a6663170da7dL,0x71d1ce5b7d79dcL,
  29169. 0x1cffe9be1e1afdL,0x703745115a29c4L,0x73b7f897b2f65aL,
  29170. 0x02218c3a95891aL } },
  29171. /* 84 */
  29172. { { 0x16866db8a9e8c9L,0x4770b770123d9bL,0x4c116cf34a8465L,
  29173. 0x079b28263fc86aL,0x3751c755a72b58L,0x7bc8df1673243aL,
  29174. 0x12fff72454f064L },
  29175. { 0x15c049b89554e7L,0x4ea9ef44d7cd9aL,0x42f50765c0d4f1L,
  29176. 0x158bb603cb011bL,0x0809dde16470b1L,0x63cad7422ea819L,
  29177. 0x38b6cd70f90d7eL } },
  29178. /* 85 */
  29179. { { 0x1e4aab6328e33fL,0x70575f026da3aeL,0x7e1b55c8c55219L,
  29180. 0x328d4b403d24caL,0x03b6df1f0a5bd1L,0x26b4bb8b648ed0L,
  29181. 0x17161f2f10b76aL },
  29182. { 0x6cdb32bae8b4c0L,0x33176266227056L,0x4975fa58519b45L,
  29183. 0x254602ea511d96L,0x4e82e93e402a67L,0x0ca8b5929cdb4fL,
  29184. 0x3ae7e0a07918f5L } },
  29185. /* 86 */
  29186. { { 0x60f9d1fecf5b9bL,0x6257e40d2cd469L,0x6c7aa814d28456L,
  29187. 0x58aac7caac8e79L,0x703a55f0293cbfL,0x702390a0f48378L,
  29188. 0x24b9ae07218b07L },
  29189. { 0x1ebc66cdaf24e3L,0x7d9ae5f9f8e199L,0x42055ee921a245L,
  29190. 0x035595936e4d49L,0x129c45d425c08bL,0x6486c5f19ce6ddL,
  29191. 0x027dbd5f18ba24L } },
  29192. /* 87 */
  29193. { { 0x7d6b78d29375fbL,0x0a3dc6ba22ae38L,0x35090fa91feaf6L,
  29194. 0x7f18587fb7b16eL,0x6e7091dd924608L,0x54e102cdbf5ff8L,
  29195. 0x31b131a4c22079L },
  29196. { 0x368f87d6a53fb0L,0x1d3f3d69a3f240L,0x36bf5f9e40e1c6L,
  29197. 0x17f150e01f8456L,0x76e5d0835eb447L,0x662fc0a1207100L,
  29198. 0x14e3dd97a98e39L } },
  29199. /* 88 */
  29200. { { 0x0249d9c2663b4bL,0x56b68f9a71ba1cL,0x74b119567f9c02L,
  29201. 0x5e6f336d8c92acL,0x2ced58f9f74a84L,0x4b75a2c2a467c5L,
  29202. 0x30557011cf740eL },
  29203. { 0x6a87993be454ebL,0x29b7076fb99a68L,0x62ae74aaf99bbaL,
  29204. 0x399f9aa8fb6c1bL,0x553c24a396dd27L,0x2868337a815ea6L,
  29205. 0x343ab6635cc776L } },
  29206. /* 89 */
  29207. { { 0x0e0b0eec142408L,0x79728229662121L,0x605d0ac75e6250L,
  29208. 0x49a097a01edfbeL,0x1e20cd270df6b6L,0x7438a0ca9291edL,
  29209. 0x29daa430da5f90L },
  29210. { 0x7a33844624825aL,0x181715986985c1L,0x53a6853cae0b92L,
  29211. 0x6d98401bd925e8L,0x5a0a34f5dd5e24L,0x7b818ef53cf265L,
  29212. 0x0836e43c9d3194L } },
  29213. /* 90 */
  29214. { { 0x1179b70e6c5fd9L,0x0246d9305dd44cL,0x635255edfbe2fbL,
  29215. 0x5397b3523b4199L,0x59350cc47e6640L,0x2b57aa97ed4375L,
  29216. 0x37efd31abd153aL },
  29217. { 0x7a7afa6907f4faL,0x75c10cb94e6a7eL,0x60a925ab69cc47L,
  29218. 0x2ff5bcd9239bd5L,0x13c2113e425f11L,0x56bd3d2f8a1437L,
  29219. 0x2c9adbab13774fL } },
  29220. /* 91 */
  29221. { { 0x4ab9f52a2e5f2bL,0x5e537e70b58903L,0x0f242658ebe4f2L,
  29222. 0x2648a1e7a5f9aeL,0x1b4c5081e73007L,0x6827d4aff51850L,
  29223. 0x3925e41726cd01L },
  29224. { 0x56dd8a55ab3cfbL,0x72d6a31b6d5beaL,0x697bd2e5575112L,
  29225. 0x66935519a7aa12L,0x55e97dda7a3aceL,0x0e16afb4237b4cL,
  29226. 0x00b68fbff08093L } },
  29227. /* 92 */
  29228. { { 0x4b00366481d0d9L,0x37cb031fbfc5c4L,0x14643f6800dd03L,
  29229. 0x6793fef60fe0faL,0x4f43e329c92803L,0x1fce86b96a6d26L,
  29230. 0x0ad416975e213aL },
  29231. { 0x7cc6a6711adcc9L,0x64b8a63c43c2d9L,0x1e6caa2a67c0d0L,
  29232. 0x610deffd17a54bL,0x57d669d5f38423L,0x77364b8f022636L,
  29233. 0x36d4d13602e024L } },
  29234. /* 93 */
  29235. { { 0x72e667ae50a2f5L,0x1b15c950c3a21aL,0x3ccc37c72e6dfeL,
  29236. 0x027f7e1d094fb8L,0x43ae1e90aa5d7eL,0x3f5feac3d97ce5L,
  29237. 0x0363ed0a336e55L },
  29238. { 0x235f73d7663784L,0x5d8cfc588ad5a4L,0x10ab6ff333016eL,
  29239. 0x7d8886af2e1497L,0x549f34fd17988eL,0x3fc4fcaee69a33L,
  29240. 0x0622b133a13d9eL } },
  29241. /* 94 */
  29242. { { 0x6344cfa796c53eL,0x0e9a10d00136fdL,0x5d1d284a56efd8L,
  29243. 0x608b1968f8aca7L,0x2fa5a66776edcaL,0x13430c44f1609cL,
  29244. 0x1499973cb2152aL },
  29245. { 0x3764648104ab58L,0x3226e409fadafcL,0x1513a8466459ddL,
  29246. 0x649206ec365035L,0x46149aa3f765b1L,0x3aebf0a035248eL,
  29247. 0x1ee60b8c373494L } },
  29248. /* 95 */
  29249. { { 0x4e9efcc15f3060L,0x5e5d50fd77cdc8L,0x071e5403516b58L,
  29250. 0x1b7d4e89b24ceaL,0x53b1fa66d6dc03L,0x457f15f892ab5fL,
  29251. 0x076332c9397260L },
  29252. { 0x31422b79d7584bL,0x0b01d47e41ba80L,0x3e5611a3171528L,
  29253. 0x5f53b9a9fc1be4L,0x7e2fc3d82f110fL,0x006cf350ef0fbfL,
  29254. 0x123ae98ec81c12L } },
  29255. /* 96 */
  29256. { { 0x310d41df46e2f6L,0x2ff032a286cf13L,0x64751a721c4eadL,
  29257. 0x7b62bcc0339b95L,0x49acf0c195afa4L,0x359d48742544e5L,
  29258. 0x276b7632d9e2afL },
  29259. { 0x656c6be182579aL,0x75b65a4d85b199L,0x04a911d1721bfaL,
  29260. 0x46e023d0e33477L,0x1ec2d580acd869L,0x540b456f398a37L,
  29261. 0x001f698210153dL } },
  29262. /* 97 */
  29263. { { 0x3ca35217b00dd0L,0x73961d034f4d3cL,0x4f520b61c4119dL,
  29264. 0x4919fde5cccff7L,0x4d0e0e6f38134dL,0x55c22586003e91L,
  29265. 0x24d39d5d8f1b19L },
  29266. { 0x4d4fc3d73234dcL,0x40c50c9d5f8368L,0x149afbc86bf2b8L,
  29267. 0x1dbafefc21d7f1L,0x42e6b61355107fL,0x6e506cf4b54f29L,
  29268. 0x0f498a6c615228L } },
  29269. /* 98 */
  29270. { { 0x30618f437cfaf8L,0x059640658532c4L,0x1c8a4d90e96e1dL,
  29271. 0x4a327bcca4fb92L,0x54143b8040f1a0L,0x4ec0928c5a49e4L,
  29272. 0x2af5ad488d9b1fL },
  29273. { 0x1b392bd5338f55L,0x539c0292b41823L,0x1fe35d4df86a02L,
  29274. 0x5fa5bb17988c65L,0x02b6cb715adc26L,0x09a48a0c2cb509L,
  29275. 0x365635f1a5a9f2L } },
  29276. /* 99 */
  29277. { { 0x58aa87bdc21f31L,0x156900c7cb1935L,0x0ec1f75ee2b6cfL,
  29278. 0x5f3e35a77ec314L,0x582dec7b9b7621L,0x3e65deb0e8202aL,
  29279. 0x325c314b8a66b7L },
  29280. { 0x702e2a22f24d66L,0x3a20e9982014f1L,0x6424c5b86bbfb0L,
  29281. 0x424eea4d795351L,0x7fc4cce7c22055L,0x581383fceb92d7L,
  29282. 0x32b663f49ee81bL } },
  29283. /* 100 */
  29284. { { 0x76e2d0b648b73eL,0x59ca39fa50bddaL,0x18bb44f786a7e4L,
  29285. 0x28c8d49d464360L,0x1b8bf1d3a574eaL,0x7c670b9bf1635aL,
  29286. 0x2efb30a291f4b3L },
  29287. { 0x5326c069cec548L,0x03bbe481416531L,0x08a415c8d93d6fL,
  29288. 0x3414a52120d383L,0x1f17a0fc6e9c5cL,0x0de9a090717463L,
  29289. 0x22d84b3c67ff07L } },
  29290. /* 101 */
  29291. { { 0x30b5014c3830ebL,0x70791dc1a18b37L,0x09e6ea4e24f423L,
  29292. 0x65e148a5253132L,0x446f05d5d40449L,0x7ad5d3d707c0e9L,
  29293. 0x18eedd63dd3ab5L },
  29294. { 0x40d2eac6bb29e0L,0x5b0e9605e83c38L,0x554f2c666a56a8L,
  29295. 0x0ac27b6c94c48bL,0x1aaecdd91bafe5L,0x73c6e2bdf72634L,
  29296. 0x306dab96d19e03L } },
  29297. /* 102 */
  29298. { { 0x6d3e4b42772f41L,0x1aba7796f3a39bL,0x3a03fbb980e9c0L,
  29299. 0x2f2ea5da2186a8L,0x358ff444ef1fcfL,0x0798cc0329fcdcL,
  29300. 0x39a28bcc9aa46dL },
  29301. { 0x42775c977fe4d2L,0x5eb8fc5483d6b0L,0x0bfe37c039e3f7L,
  29302. 0x429292eaf9df60L,0x188bdf4b840cd5L,0x06e10e090749cdL,
  29303. 0x0e52678e73192eL } },
  29304. /* 103 */
  29305. { { 0x05de80b08df5feL,0x2af8c77406c5f8L,0x53573c50a0304aL,
  29306. 0x277b10b751bca0L,0x65cf8c559132a5L,0x4c667abe25f73cL,
  29307. 0x0271809e05a575L },
  29308. { 0x41ced461f7a2fbL,0x0889a9ebdd7075L,0x320c63f2b7760eL,
  29309. 0x4f8d4324151c63L,0x5af47315be2e5eL,0x73c62f6aee2885L,
  29310. 0x206d6412a56a97L } },
  29311. /* 104 */
  29312. { { 0x6b1c508b21d232L,0x3781185974ead6L,0x1aba7c3ebe1fcfL,
  29313. 0x5bdc03cd3f3a5aL,0x74a25036a0985bL,0x5929e30b7211b2L,
  29314. 0x16a9f3bc366bd7L },
  29315. { 0x566a7057dcfffcL,0x23b5708a644bc0L,0x348cda2aa5ba8cL,
  29316. 0x466aa96b9750d4L,0x6a435ed9b20834L,0x2e7730f2cf9901L,
  29317. 0x2b5cd71d5b0410L } },
  29318. /* 105 */
  29319. { { 0x285ab3cee76ef4L,0x68895e3a57275dL,0x6fab2e48fd1265L,
  29320. 0x0f1de060428c94L,0x668a2b080b5905L,0x1b589dc3b0cb37L,
  29321. 0x3c037886592c9bL },
  29322. { 0x7fb5c0f2e90d4dL,0x334eefb3d8c91aL,0x75747124700388L,
  29323. 0x547a2c2e2737f5L,0x2af9c080e37541L,0x0a295370d9091aL,
  29324. 0x0bb5c36dad99e6L } },
  29325. /* 106 */
  29326. { { 0x644116586f25cbL,0x0c3f41f9ee1f5dL,0x00628d43a3dedaL,
  29327. 0x16e1437aae9669L,0x6aba7861bf3e59L,0x60735631ff4c44L,
  29328. 0x345609efaa615eL },
  29329. { 0x41f54792e6acefL,0x4791583f75864dL,0x37f2ff5c7508b1L,
  29330. 0x1288912516c3b0L,0x51a2135f6a539bL,0x3b775511f42091L,
  29331. 0x127c6afa7afe66L } },
  29332. /* 107 */
  29333. { { 0x79f4f4f7492b73L,0x583d967256342dL,0x51a729bff33ca3L,
  29334. 0x3977d2c22d8986L,0x066f528ba8d40bL,0x5d759d30f8eb94L,
  29335. 0x0f8e649192b408L },
  29336. { 0x22d84e752555bbL,0x76953855c728c7L,0x3b2254e72aaaa4L,
  29337. 0x508cd4ce6c0212L,0x726296d6b5a6daL,0x7a77aa066986f3L,
  29338. 0x2267a497bbcf31L } },
  29339. /* 108 */
  29340. { { 0x7f3651bf825dc4L,0x3988817388c56fL,0x257313ed6c3dd0L,
  29341. 0x3feab7f3b8ffadL,0x6c0d3cb9e9c9b4L,0x1317be0a7b6ac4L,
  29342. 0x2a5f399d7df850L },
  29343. { 0x2fe5a36c934f5eL,0x429199df88ded1L,0x435ea21619b357L,
  29344. 0x6aac6a063bac2bL,0x600c149978f5edL,0x76543aa1114c95L,
  29345. 0x163ca9c83c7596L } },
  29346. /* 109 */
  29347. { { 0x7dda4a3e4daedbL,0x1824cba360a4cdL,0x09312efd70e0c6L,
  29348. 0x454e68a146c885L,0x40aee762fe5c47L,0x29811cbd755a59L,
  29349. 0x34b37c95f28319L },
  29350. { 0x77c58b08b717d2L,0x309470d9a0f491L,0x1ab9f40448e01cL,
  29351. 0x21c8bd819207b1L,0x6a01803e9361bcL,0x6e5e4c350ec415L,
  29352. 0x14fd55a91f8798L } },
  29353. /* 110 */
  29354. { { 0x4cee562f512a90L,0x0008361d53e390L,0x3789b307a892cfL,
  29355. 0x064f7be8770ae9L,0x41435d848762cfL,0x662204dd38baa6L,
  29356. 0x23d6dcf73f6c5aL },
  29357. { 0x69bef2d2c75d95L,0x2b037c0c9bb43eL,0x495fb4d79a34cfL,
  29358. 0x184e140c601260L,0x60193f8d435f9cL,0x283fa52a0c3ad2L,
  29359. 0x1998635e3a7925L } },
  29360. /* 111 */
  29361. { { 0x1cfd458ce382deL,0x0dddbd201bbcaeL,0x14d2ae8ed45d60L,
  29362. 0x73d764ab0c24cbL,0x2a97fe899778adL,0x0dbd1e01eddfe9L,
  29363. 0x2ba5c72d4042c3L },
  29364. { 0x27eebc3af788f1L,0x53ffc827fc5a30L,0x6d1d0726d35188L,
  29365. 0x4721275c50aa2aL,0x077125f02e690fL,0x6da8142405db5dL,
  29366. 0x126cef68992513L } },
  29367. /* 112 */
  29368. { { 0x3c6067035b2d69L,0x2a1ad7db2361acL,0x3debece6cad41cL,
  29369. 0x30095b30f9afc1L,0x25f50b9bd9c011L,0x79201b2f2c1da1L,
  29370. 0x3b5c151449c5bdL },
  29371. { 0x76eff4127abdb4L,0x2d31e03ce0382aL,0x24ff21f8bda143L,
  29372. 0x0671f244fd3ebaL,0x0c1c00b6bcc6fbL,0x18de9f7c3ebefbL,
  29373. 0x33dd48c3809c67L } },
  29374. /* 113 */
  29375. { { 0x61d6c2722d94edL,0x7e426e31041cceL,0x4097439f1b47b0L,
  29376. 0x579e798b2d205bL,0x6a430d67f830ebL,0x0d2c676700f727L,
  29377. 0x05fea83a82f25bL },
  29378. { 0x3f3482df866b98L,0x3dd353b6a5a9cdL,0x77fe6ae1a48170L,
  29379. 0x2f75cc2a8f7cddL,0x7442a3863dad17L,0x643de42d877a79L,
  29380. 0x0fec8a38fe7238L } },
  29381. /* 114 */
  29382. { { 0x79b70c0760ac07L,0x195d3af37e9b29L,0x1317ff20f7cf27L,
  29383. 0x624e1c739e7504L,0x67330ef50f943dL,0x775e8cf455d793L,
  29384. 0x17b94d2d913a9fL },
  29385. { 0x4b627203609e7fL,0x06aac5fb93e041L,0x603c515fdc2611L,
  29386. 0x2592ca0d7ae472L,0x02395d1f50a6cbL,0x466ef9648f85d9L,
  29387. 0x297cf879768f72L } },
  29388. /* 115 */
  29389. { { 0x3489d67d85fa94L,0x0a6e5b739c8e04L,0x7ebb5eab442e90L,
  29390. 0x52665a007efbd0L,0x0967ca57b0d739L,0x24891f9d932b63L,
  29391. 0x3cc2d6dbadc9d3L },
  29392. { 0x4b4773c81c5338L,0x73cd47dad7a0f9L,0x7c755bab6ae158L,
  29393. 0x50b03d6becefcaL,0x574d6e256d57f0L,0x188db4fffb92aeL,
  29394. 0x197e10118071eaL } },
  29395. /* 116 */
  29396. { { 0x45d0cbcba1e7f1L,0x1180056abec91aL,0x6c5f86624bbc28L,
  29397. 0x442c83f3b8e518L,0x4e16ae1843ecb4L,0x670cef2fd786c9L,
  29398. 0x205b4acb637d2cL },
  29399. { 0x70b0e539aa8671L,0x67c982056bebd0L,0x645c831a5e7c36L,
  29400. 0x09e06951a14b32L,0x5dd610ad4c89e6L,0x41c35f20164831L,
  29401. 0x3821f29cb4cdb8L } },
  29402. /* 117 */
  29403. { { 0x2831ffaba10079L,0x70f6dac9ffe444L,0x1cfa32ccc03717L,
  29404. 0x01519fda22a3c8L,0x23215e815aaa27L,0x390671ad65cbf7L,
  29405. 0x03dd4d72de7d52L },
  29406. { 0x1ecd972ee95923L,0x166f8da3813e8eL,0x33199bbd387a1aL,
  29407. 0x04525fe15e3dc7L,0x44d2ef54165898L,0x4b7e47d3dc47f7L,
  29408. 0x10d5c8db0b5d44L } },
  29409. /* 118 */
  29410. { { 0x176d95ba9cdb1bL,0x14025f04f23dfcL,0x49379332891687L,
  29411. 0x6625e5ccbb2a57L,0x7ac0abdbf9d0e5L,0x7aded4fbea15b2L,
  29412. 0x314844ac184d67L },
  29413. { 0x6d9ce34f05eae3L,0x3805d2875856d2L,0x1c2122f85e40ebL,
  29414. 0x51cb9f2d483a9aL,0x367e91e20f1702L,0x573c3559838dfdL,
  29415. 0x0b282b0cb85af1L } },
  29416. /* 119 */
  29417. { { 0x6a12e4ef871eb5L,0x64bb517e14f5ffL,0x29e04d3aaa530bL,
  29418. 0x1b07d88268f261L,0x411be11ed16fb0L,0x1f480536db70bfL,
  29419. 0x17a7deadfd34e4L },
  29420. { 0x76d72f30646612L,0x5a3bbb43a1b0a0L,0x5e1687440e82bfL,
  29421. 0x713b5e69481112L,0x46c3dcb499e174L,0x0862da3b4e2a24L,
  29422. 0x31cb55b4d62681L } },
  29423. /* 120 */
  29424. { { 0x5ffc74dae5bb45L,0x18944c37adb9beL,0x6aaa63b1ee641aL,
  29425. 0x090f4b6ee057d3L,0x4045cedd2ee00fL,0x21c2c798f7c282L,
  29426. 0x2c2c6ef38cd6bdL },
  29427. { 0x40d78501a06293L,0x56f8caa5cc89a8L,0x7231d5f91b37aeL,
  29428. 0x655f1e5a465c6dL,0x3f59a81f9cf783L,0x09bbba04c23624L,
  29429. 0x0f71ee23bbacdeL } },
  29430. /* 121 */
  29431. { { 0x38d398c4741456L,0x5204c0654243c3L,0x34498c916ea77eL,
  29432. 0x12238c60e5fe43L,0x0fc54f411c7625L,0x30b2ca43aa80b6L,
  29433. 0x06bead1bb6ea92L },
  29434. { 0x5902ba8674b4adL,0x075ab5b0fa254eL,0x58db83426521adL,
  29435. 0x5b66b6b3958e39L,0x2ce4e39890e07bL,0x46702513338b37L,
  29436. 0x363690c2ded4d7L } },
  29437. /* 122 */
  29438. { { 0x765642c6b75791L,0x0f4c4300d7f673L,0x404d8bbe101425L,
  29439. 0x61e91c88651f1bL,0x61ddc9bc60aed8L,0x0ef36910ce2e65L,
  29440. 0x04b44367aa63b8L },
  29441. { 0x72822d3651b7dcL,0x4b750157a2716dL,0x091cb4f2118d16L,
  29442. 0x662ba93b101993L,0x447cbd54a1d40aL,0x12cdd48d674848L,
  29443. 0x16f10415cbec69L } },
  29444. /* 123 */
  29445. { { 0x0c57a3a751cd0eL,0x0833d7478fadceL,0x1e751f55686436L,
  29446. 0x489636c58e1df7L,0x26ad6da941266fL,0x22225d3559880fL,
  29447. 0x35b397c45ba0e2L },
  29448. { 0x3ca97b70e1f2ceL,0x78e50427a8680cL,0x06137e042a8f91L,
  29449. 0x7ec40d2500b712L,0x3f0ad688ad7b0dL,0x24746fb33f9513L,
  29450. 0x3638fcce688f0bL } },
  29451. /* 124 */
  29452. { { 0x753163750bed6fL,0x786507cd16157bL,0x1d6ec228ce022aL,
  29453. 0x587255f42d1b31L,0x0c6adf72a3a0f6L,0x4bfeee2da33f5eL,
  29454. 0x08b7300814de6cL },
  29455. { 0x00bf8df9a56e11L,0x75aead48fe42e8L,0x3de9bad911b2e2L,
  29456. 0x0fadb233e4b8bbL,0x5b054e8fd84f7dL,0x5eb3064152889bL,
  29457. 0x01c1c6e8c777a1L } },
  29458. /* 125 */
  29459. { { 0x5fa0e598f8fcb9L,0x11c129a1ae18dfL,0x5c41b482a2273bL,
  29460. 0x545664e5044c9cL,0x7e01c915bfb9abL,0x7f626e19296aa0L,
  29461. 0x20c91a9822a087L },
  29462. { 0x273a9fbe3c378fL,0x0f126b44b7d350L,0x493764a75df951L,
  29463. 0x32dec3c367d24bL,0x1a7ae987fed9d3L,0x58a93055928b85L,
  29464. 0x11626975d7775fL } },
  29465. /* 126 */
  29466. { { 0x2bb174a95540a9L,0x10de02c58b613fL,0x2fa8f7b861f3eeL,
  29467. 0x44731260bdf3b3L,0x19c38ff7da41feL,0x3535a16e3d7172L,
  29468. 0x21a948b83cc7feL },
  29469. { 0x0e6f72868bc259L,0x0c70799df3c979L,0x526919955584c3L,
  29470. 0x4d95fda04f8fa2L,0x7bb228e6c0f091L,0x4f728b88d92194L,
  29471. 0x2b361c5a136bedL } },
  29472. /* 127 */
  29473. { { 0x0c72ca10c53841L,0x4036ab49f9da12L,0x578408d2b7082bL,
  29474. 0x2c4903201fbf5eL,0x14722b3f42a6a8L,0x1997b786181694L,
  29475. 0x25c6f10de32849L },
  29476. { 0x79f46d517ff2ffL,0x2dc5d97528f6deL,0x518a494489aa72L,
  29477. 0x52748f8af3cf97L,0x472da30a96bb16L,0x1be228f92465a9L,
  29478. 0x196f0c47d60479L } },
  29479. /* 128 */
  29480. { { 0x47dd7d139b3239L,0x049c9b06775d0fL,0x627ffc00562d5eL,
  29481. 0x04f578d5e5e243L,0x43a788ffcef8b9L,0x7db320be9dde28L,
  29482. 0x00837528b8572fL },
  29483. { 0x2969eca306d695L,0x195b72795ec194L,0x5e1fa9b8e77e50L,
  29484. 0x4c627f2b3fbfd5L,0x4b91e0d0ee10ffL,0x5698c8d0f35833L,
  29485. 0x12d3a9431f475eL } },
  29486. /* 129 */
  29487. { { 0x6409457a0db57eL,0x795b35192e0433L,0x146f973fe79805L,
  29488. 0x3d49c516dfb9cfL,0x50dfc3646b3cdaL,0x16a08a2210ad06L,
  29489. 0x2b4ef5bcd5b826L },
  29490. { 0x5ebabfee2e3e3eL,0x2e048e724d9726L,0x0a7a7ed6abef40L,
  29491. 0x71ff7f83e39ad8L,0x3405ac52a1b852L,0x2e3233357a608dL,
  29492. 0x38c1bf3b0e40e6L } },
  29493. /* 130 */
  29494. { { 0x59aec823e4712cL,0x6ed9878331ddadL,0x1cc6faf629f2a0L,
  29495. 0x445ff79f36c18cL,0x4edc7ed57aff3dL,0x22ee54c8bdd9e8L,
  29496. 0x35398f42d72ec5L },
  29497. { 0x4e7a1cceee0ecfL,0x4c66a707dd1d31L,0x629ad157a23c04L,
  29498. 0x3b2c6031dc3c83L,0x3336acbcd3d96cL,0x26ce43adfce0f0L,
  29499. 0x3c869c98d699dcL } },
  29500. /* 131 */
  29501. { { 0x58b3cd9586ba11L,0x5d6514b8090033L,0x7c88c3bd736782L,
  29502. 0x1735f84f2130edL,0x47784095a9dee0L,0x76312c6e47901bL,
  29503. 0x1725f6ebc51455L },
  29504. { 0x6744344bc4503eL,0x16630b4d66e12fL,0x7b3481752c3ec7L,
  29505. 0x47bb2ed1f46f95L,0x08a1a497dd1bcfL,0x1f525df2b8ed93L,
  29506. 0x0fe492ea993713L } },
  29507. /* 132 */
  29508. { { 0x71b8dd7268b448L,0x1743dfaf3728d7L,0x23938d547f530aL,
  29509. 0x648c3d497d0fc6L,0x26c0d769e3ad45L,0x4d25108769a806L,
  29510. 0x3fbf2025143575L },
  29511. { 0x485bfd90339366L,0x2de2b99ed87461L,0x24a33347713badL,
  29512. 0x1674bc7073958aL,0x5bb2373ee85b5fL,0x57f9bd657e662cL,
  29513. 0x2041b248d39042L } },
  29514. /* 133 */
  29515. { { 0x5f01617d02f4eeL,0x2a8e31c4244b91L,0x2dab3e790229e0L,
  29516. 0x72d319ea7544afL,0x01ffb8b000cb56L,0x065e63b0daafd3L,
  29517. 0x3d7200a7111d6fL },
  29518. { 0x4561ce1b568973L,0x37034c532dd8ecL,0x1368215020be02L,
  29519. 0x30e7184cf289ebL,0x199e0c27d815deL,0x7ee1b4dff324e5L,
  29520. 0x2f4a11de7fab5cL } },
  29521. /* 134 */
  29522. { { 0x33c2f99b1cdf2bL,0x1e0d78bf42a2c0L,0x64485dececaa67L,
  29523. 0x2242a41be93e92L,0x62297b1f15273cL,0x16ebfaafb02205L,
  29524. 0x0f50f805f1fdabL },
  29525. { 0x28bb0b3a70eb28L,0x5b1c7d0160d683L,0x05c30a37959f78L,
  29526. 0x3d9301184922d2L,0x46c1ead7dbcb1aL,0x03ee161146a597L,
  29527. 0x2d413ed9a6ccc1L } },
  29528. /* 135 */
  29529. { { 0x685ab5f97a27c2L,0x59178214023751L,0x4ffef3c585ab17L,
  29530. 0x2bc85302aba2a9L,0x675b001780e856L,0x103c8a37f0b33dL,
  29531. 0x2241e98ece70a6L },
  29532. { 0x546738260189edL,0x086c8f7a6b96edL,0x00832ad878a129L,
  29533. 0x0b679056ba7462L,0x020ce6264bf8c4L,0x3f9f4b4d92abfbL,
  29534. 0x3e9c55343c92edL } },
  29535. /* 136 */
  29536. { { 0x482cec9b3f5034L,0x08b59b3cd1fa30L,0x5a55d1bc8e58b5L,
  29537. 0x464a5259337d8eL,0x0a5b6c66ade5a5L,0x55db77b504ddadL,
  29538. 0x015992935eac35L },
  29539. { 0x54fe51025e32fcL,0x5d7f52dbe4a579L,0x08c564a8c58696L,
  29540. 0x4482a8bec4503fL,0x440e75d9d94de9L,0x6992d768020bfaL,
  29541. 0x06c311e8ba01f6L } },
  29542. /* 137 */
  29543. { { 0x2a6ac808223878L,0x04d3ccb4aab0b8L,0x6e6ef09ff6e823L,
  29544. 0x15cb03ee9158dcL,0x0dc58919171bf7L,0x3273568abf3cb1L,
  29545. 0x1b55245b88d98bL },
  29546. { 0x28e9383b1de0c1L,0x30d5009e4f1f1bL,0x334d185a56a134L,
  29547. 0x0875865dfa4c46L,0x266edf5eae3beeL,0x2e03ff16d1f7e5L,
  29548. 0x29a36bd9f0c16dL } },
  29549. /* 138 */
  29550. { { 0x004cff44b2e045L,0x426c96380ba982L,0x422292281e46d7L,
  29551. 0x508dd8d29d7204L,0x3a4ea73fb2995eL,0x4be64090ae07b2L,
  29552. 0x3339177a0eff22L },
  29553. { 0x74a97ec2b3106eL,0x0c616d09169f5fL,0x1bb5d8907241a7L,
  29554. 0x661fb67f6d41bdL,0x018a88a0daf136L,0x746333a093a7b4L,
  29555. 0x3e19f1ac76424eL } },
  29556. /* 139 */
  29557. { { 0x542a5656527296L,0x0e7b9ce22f1bc9L,0x31b0945992b89bL,
  29558. 0x6e0570eb85056dL,0x32daf813483ae5L,0x69eeae9d59bb55L,
  29559. 0x315ad4b730b557L },
  29560. { 0x2bc16795f32923L,0x6b02b7ba55130eL,0x1e9da67c012f85L,
  29561. 0x5616f014dabf8fL,0x777395fcd9c723L,0x2ff075e7743246L,
  29562. 0x2993538aff142eL } },
  29563. /* 140 */
  29564. { { 0x72dae20e552b40L,0x2e4ba69aa5d042L,0x001e563e618bd2L,
  29565. 0x28feeba3c98772L,0x648c356da2a907L,0x687e2325069ea7L,
  29566. 0x0d34ab09a394f0L },
  29567. { 0x73c21813111286L,0x5829b53b304e20L,0x6fba574de08076L,
  29568. 0x79f7058f61614eL,0x4e71c9316f1191L,0x24ef12193e0a89L,
  29569. 0x35dc4e2bc9d848L } },
  29570. /* 141 */
  29571. { { 0x045e6d3b4ad1cdL,0x729c95493782f0L,0x77f59de85b361aL,
  29572. 0x5309b4babf28f8L,0x4d893d9290935fL,0x736f47f2b2669eL,
  29573. 0x23270922d757f3L },
  29574. { 0x23a4826f70d4e9L,0x68a8c63215d33eL,0x4d6c2069205c9cL,
  29575. 0x46b2938a5eebe0L,0x41d1f1e2de3892L,0x5ca1775544bcb0L,
  29576. 0x3130629e5d19dcL } },
  29577. /* 142 */
  29578. { { 0x6e2681593375acL,0x117cfbabc22621L,0x6c903cd4e13ccaL,
  29579. 0x6f358f14d4bd97L,0x1bc58fa11089f1L,0x36aa2db4ac426aL,
  29580. 0x15ced8464b7ea1L },
  29581. { 0x6966836cba7df5L,0x7c2b1851568113L,0x22b50ff2ffca66L,
  29582. 0x50e77d9f48e49aL,0x32775e9bbc7cc9L,0x403915bb0ece71L,
  29583. 0x1b8ec7cb9dd7aaL } },
  29584. /* 143 */
  29585. { { 0x65a888b677788bL,0x51887fac2e7806L,0x06792636f98d2bL,
  29586. 0x47bbcd59824c3bL,0x1aca908c43e6dcL,0x2e00d15c708981L,
  29587. 0x08e031c2c80634L },
  29588. { 0x77fbc3a297c5ecL,0x10a7948af2919eL,0x10cdafb1fb6b2fL,
  29589. 0x27762309b486f0L,0x13abf26bbac641L,0x53da38478fc3eeL,
  29590. 0x3c22eff379bf55L } },
  29591. /* 144 */
  29592. { { 0x0163f484770ee3L,0x7f28e8942e0cbfL,0x5f86cb51b43831L,
  29593. 0x00feccd4e4782fL,0x40e5b417eafe7dL,0x79e5742bbea228L,
  29594. 0x3717154aa469beL },
  29595. { 0x271d74a270f721L,0x40eb400890b70cL,0x0e37be81d4cb02L,
  29596. 0x786907f4e8d43fL,0x5a1f5b590a7acbL,0x048861883851fdL,
  29597. 0x11534a1e563dbbL } },
  29598. /* 145 */
  29599. { { 0x37a6357c525435L,0x6afe6f897b78a5L,0x7b7ff311d4f67bL,
  29600. 0x38879df15dc9f4L,0x727def7b8ba987L,0x20285dd0db4436L,
  29601. 0x156b0fc64b9243L },
  29602. { 0x7e3a6ec0c1c390L,0x668a88d9bcf690L,0x5925aba5440dbeL,
  29603. 0x0f6891a044f593L,0x70b46edfed4d97L,0x1a6cc361bab201L,
  29604. 0x046f5bc6e160bcL } },
  29605. /* 146 */
  29606. { { 0x79350f076bc9d1L,0x077d9e79a586b9L,0x0896bc0c705764L,
  29607. 0x58e632b90e7e46L,0x14e87e0ad32488L,0x4b1bb3f72c6e00L,
  29608. 0x3c3ce9684a5fc5L },
  29609. { 0x108fbaf1f703aaL,0x08405ecec17577L,0x199a8e2d44be73L,
  29610. 0x2eb22ed0067763L,0x633944deda3300L,0x20d739eb8e5efbL,
  29611. 0x2bbbd94086b532L } },
  29612. /* 147 */
  29613. { { 0x03c8b17a19045dL,0x6205a0a504980bL,0x67fdb3e962b9f0L,
  29614. 0x16399e01511a4bL,0x44b09fe9dffc96L,0x00a74ff44a1381L,
  29615. 0x14590deed3f886L },
  29616. { 0x54e3d5c2a23ddbL,0x310e5138209d28L,0x613f45490c1c9bL,
  29617. 0x6bbc85d44bbec8L,0x2f85fc559e73f6L,0x0d71fa7d0fa8cbL,
  29618. 0x2898571d17fbb9L } },
  29619. /* 148 */
  29620. { { 0x5607a84335167dL,0x3009c1eb910f91L,0x7ce63447e62d0bL,
  29621. 0x03a0633afcf89eL,0x1234b5aaa50872L,0x5a307b534d547bL,
  29622. 0x2f4e97138a952eL },
  29623. { 0x13914c2db0f658L,0x6cdcb47e6e75baL,0x5549169caca772L,
  29624. 0x0f20423dfeb16fL,0x6b1ae19d180239L,0x0b7b3bee9b7626L,
  29625. 0x1ca81adacfe4efL } },
  29626. /* 149 */
  29627. { { 0x219ec3ad19d96fL,0x3549f6548132dbL,0x699889c7aacd0bL,
  29628. 0x74602a58730b19L,0x62dc63bcece81cL,0x316f991c0c317aL,
  29629. 0x2b8627867b95e3L },
  29630. { 0x67a25ddced1eedL,0x7e14f0eba756e7L,0x0873fbc09b0495L,
  29631. 0x0fefb0e16596adL,0x03e6cd98ef39bbL,0x1179b1cded249dL,
  29632. 0x35c79c1db1edc2L } },
  29633. /* 150 */
  29634. { { 0x1368309d4245bfL,0x442e55852a7667L,0x095b0f0f348b65L,
  29635. 0x6834cf459dfad4L,0x6645950c9be910L,0x06bd81288c71e6L,
  29636. 0x1b015b6e944edfL },
  29637. { 0x7a6a83045ab0e3L,0x6afe88b9252ad0L,0x2285bd65523502L,
  29638. 0x6c78543879a282L,0x1c5e264b5c6393L,0x3a820c6a7453eeL,
  29639. 0x37562d1d61d3c3L } },
  29640. /* 151 */
  29641. { { 0x6c084f62230c72L,0x599490270bc6cfL,0x1d3369ddd3c53dL,
  29642. 0x516ddb5fac5da0L,0x35ab1e15011b1aL,0x5fba9106d3a180L,
  29643. 0x3be0f092a0917cL },
  29644. { 0x57328f9fdc2538L,0x0526323fc8d5f6L,0x10cbb79521e602L,
  29645. 0x50d01167147ae2L,0x2ec7f1b3cda99eL,0x43073cc736e7beL,
  29646. 0x1ded89cadd83a6L } },
  29647. /* 152 */
  29648. { { 0x1d51bda65d56d5L,0x63f2fd4d2dc056L,0x326413d310ea6dL,
  29649. 0x3abba5bca92876L,0x6b9aa8bc4d6ebeL,0x1961c687f15d5dL,
  29650. 0x311cf07464c381L },
  29651. { 0x2321b1064cd8aeL,0x6e3caac4443850L,0x3346fc4887d2d0L,
  29652. 0x1640417e0e640fL,0x4a958a52a07a9eL,0x1346a1b1cb374cL,
  29653. 0x0a793cf79beccbL } },
  29654. /* 153 */
  29655. { { 0x29d56cba89aaa5L,0x1581898c0b3c15L,0x1af5b77293c082L,
  29656. 0x1617ba53a006ceL,0x62dd3b384e475fL,0x71a9820c3f962aL,
  29657. 0x0e4938920b854eL },
  29658. { 0x0b8d98849808abL,0x64c14923546de7L,0x6a20883b78a6fcL,
  29659. 0x72de211428acd6L,0x009678b47915bbL,0x21b5269ae5dae6L,
  29660. 0x313cc0e60b9457L } },
  29661. /* 154 */
  29662. { { 0x69ee421b1de38bL,0x44b484c6cec1c7L,0x0240596c6a8493L,
  29663. 0x2321a62c85fb9eL,0x7a10921802a341L,0x3d2a95507e45c3L,
  29664. 0x0752f40f3b6714L },
  29665. { 0x596a38798751e6L,0x46bf186a0feb85L,0x0b23093e23b49cL,
  29666. 0x1bfa7bc5afdc07L,0x4ba96f873eefadL,0x292e453fae9e44L,
  29667. 0x2773646667b75cL } },
  29668. /* 155 */
  29669. { { 0x1f81a64e94f22aL,0x3125ee3d8683ddL,0x76a660a13b9582L,
  29670. 0x5aa584c3640c6eL,0x27cc99fd472953L,0x7048f4d58061d1L,
  29671. 0x379a1397ac81e8L },
  29672. { 0x5d1ecd2b6b956bL,0x0829e0366b0697L,0x49548cec502421L,
  29673. 0x7af5e2f717c059L,0x329a25a0fec54eL,0x028e99e4bcd7f1L,
  29674. 0x071d5fe81fca78L } },
  29675. /* 156 */
  29676. { { 0x4b5c4aeb0fdfe4L,0x1367e11326ce37L,0x7c16f020ef5f19L,
  29677. 0x3c55303d77b471L,0x23a4457a06e46aL,0x2174426dd98424L,
  29678. 0x226f592114bd69L },
  29679. { 0x4411b94455f15aL,0x52e0115381fae4L,0x45b6d8efbc8f7eL,
  29680. 0x58b1221bd86d26L,0x284fb6f8a7ec1fL,0x045835939ddd30L,
  29681. 0x0216960accd598L } },
  29682. /* 157 */
  29683. { { 0x4b61f9ec1f138aL,0x4460cd1e18502bL,0x277e4fce3c4726L,
  29684. 0x0244246d6414b9L,0x28fbfcef256984L,0x3347ed0db40577L,
  29685. 0x3b57fa9e044718L },
  29686. { 0x4f73bcd6d1c833L,0x2c0d0dcf7f0136L,0x2010ac75454254L,
  29687. 0x7dc4f6151539a8L,0x0b8929ef6ea495L,0x517e20119d2bdfL,
  29688. 0x1e29f9a126ba15L } },
  29689. /* 158 */
  29690. { { 0x683a7c10470cd8L,0x0d05f0dbe0007fL,0x2f6a5026d649cdL,
  29691. 0x249ce2fdaed603L,0x116dc1e7a96609L,0x199bd8d82a0b98L,
  29692. 0x0694ad0219aeb2L },
  29693. { 0x03a3656e864045L,0x4e552273df82a6L,0x19bcc7553d17abL,
  29694. 0x74ac536c1df632L,0x440302fb4a86f6L,0x1becec0e31c9feL,
  29695. 0x002045f8fa46b8L } },
  29696. /* 159 */
  29697. { { 0x5833ba384310a2L,0x1db83fad93f8baL,0x0a12713ee2f7edL,
  29698. 0x40e0f0fdcd2788L,0x1746de5fb239a5L,0x573748965cfa15L,
  29699. 0x1e3dedda0ef650L },
  29700. { 0x6c8ca1c87607aeL,0x785dab9554fc0eL,0x649d8f91860ac8L,
  29701. 0x4436f88b52c0f9L,0x67f22ca8a5e4a3L,0x1f990fd219e4c9L,
  29702. 0x013dd21c08573fL } },
  29703. /* 160 */
  29704. { { 0x05d116141d161cL,0x5c1d2789da2ea5L,0x11f0d861f99f34L,
  29705. 0x692c2650963153L,0x3bd69f5329539eL,0x215898eef8885fL,
  29706. 0x041f79dd86f7f1L },
  29707. { 0x76dcc5e96beebdL,0x7f2b50cb42a332L,0x067621cabef8abL,
  29708. 0x31e0be607054edL,0x4c67c5e357a3daL,0x5b1a63fbfb1c2bL,
  29709. 0x3112efbf5e5c31L } },
  29710. /* 161 */
  29711. { { 0x3f83e24c0c62f1L,0x51dc9c32aae4e0L,0x2ff89b33b66c78L,
  29712. 0x21b1c7d354142cL,0x243d8d381c84bcL,0x68729ee50cf4b7L,
  29713. 0x0ed29e0f442e09L },
  29714. { 0x1ad7b57576451eL,0x6b2e296d6b91dcL,0x53f2b306e30f42L,
  29715. 0x3964ebd9ee184aL,0x0a32855df110e4L,0x31f2f90ddae05fL,
  29716. 0x3410cd04e23702L } },
  29717. /* 162 */
  29718. { { 0x60d1522ca8f2feL,0x12909237a83e34L,0x15637f80d58590L,
  29719. 0x3c72431b6d714dL,0x7c8e59a615bea2L,0x5f977b688ef35aL,
  29720. 0x071c198c0b3ab0L },
  29721. { 0x2b54c699699b4bL,0x14da473c2fd0bcL,0x7ba818ea0ad427L,
  29722. 0x35117013940b2fL,0x6e1df6b5e609dbL,0x3f42502720b64dL,
  29723. 0x01ee7dc890e524L } },
  29724. /* 163 */
  29725. { { 0x12ec1448ff4e49L,0x3e2edac882522bL,0x20455ab300f93aL,
  29726. 0x5849585bd67c14L,0x0393d5aa34ba8bL,0x30f9a1f2044fa7L,
  29727. 0x1059c9377a93e0L },
  29728. { 0x4e641cc0139e73L,0x0d9f23c9b0fa78L,0x4b2ad87e2b83f9L,
  29729. 0x1c343a9f6d9e3cL,0x1098a4cb46de4dL,0x4ddc893843a41eL,
  29730. 0x1797f4167d6e3aL } },
  29731. /* 164 */
  29732. { { 0x4add4675856031L,0x499bd5e5f7a0ffL,0x39ea1f1202271eL,
  29733. 0x0ecd7480d7a91eL,0x395f5e5fc10956L,0x0fa7f6b0c9f79bL,
  29734. 0x2fad4623aed6cbL },
  29735. { 0x1563c33ae65825L,0x29881cafac827aL,0x50650baf4c45a1L,
  29736. 0x034aad988fb9e9L,0x20a6224dc5904cL,0x6fb141a990732bL,
  29737. 0x3ec9ae1b5755deL } },
  29738. /* 165 */
  29739. { { 0x3108e7c686ae17L,0x2e73a383b4ad8aL,0x4e6bb142ba4243L,
  29740. 0x24d355922c1d80L,0x2f850dd9a088baL,0x21c50325dd5e70L,
  29741. 0x33237dd5bd7fa4L },
  29742. { 0x7823a39cab7630L,0x1535f71cff830eL,0x70d92ff0599261L,
  29743. 0x227154d2a2477cL,0x495e9bbb4f871cL,0x40d2034835686bL,
  29744. 0x31b08f97eaa942L } },
  29745. /* 166 */
  29746. { { 0x0016c19034d8ddL,0x68961627cf376fL,0x6acc90681615aeL,
  29747. 0x6bc7690c2e3204L,0x6ddf28d2fe19a2L,0x609b98f84dae4dL,
  29748. 0x0f32bfd7c94413L },
  29749. { 0x7d7edc6b21f843L,0x49bbd2ebbc9872L,0x593d6ada7b6a23L,
  29750. 0x55736602939e9cL,0x79461537680e39L,0x7a7ee9399ca7cdL,
  29751. 0x008776f6655effL } },
  29752. /* 167 */
  29753. { { 0x64585f777233cfL,0x63ec12854de0f6L,0x6b7f9bbbc3f99dL,
  29754. 0x301c014b1b55d3L,0x7cf3663bbeb568L,0x24959dcb085bd1L,
  29755. 0x12366aa6752881L },
  29756. { 0x77a74c0da5e57aL,0x3279ca93ad939fL,0x33c3c8a1ef08c9L,
  29757. 0x641b05ab42825eL,0x02f416d7d098dbL,0x7e3d58be292b68L,
  29758. 0x1864dbc46e1f46L } },
  29759. /* 168 */
  29760. { { 0x1da167b8153a9dL,0x47593d07d9e155L,0x386d984e12927fL,
  29761. 0x421a6f08a60c7cL,0x5ae9661c24dab3L,0x7927b2e7874507L,
  29762. 0x3266ea80609d53L },
  29763. { 0x7d198f4c26b1e3L,0x430d4ea2c4048eL,0x58d8ab77e84ba3L,
  29764. 0x1cb14299c37297L,0x6db6031e8f695cL,0x159bd855e26d55L,
  29765. 0x3f3f6d318a73ddL } },
  29766. /* 169 */
  29767. { { 0x3ee958cca40298L,0x02a7e5eba32ad6L,0x43b4bab96f0e1eL,
  29768. 0x534be79062b2b1L,0x029ead089b37e3L,0x4d585da558f5aaL,
  29769. 0x1f9737eb43c376L },
  29770. { 0x0426dfd9b86202L,0x4162866bc0a9f3L,0x18fc518e7bb465L,
  29771. 0x6db63380fed812L,0x421e117f709c30L,0x1597f8d0f5cee6L,
  29772. 0x04ffbf1289b06aL } },
  29773. /* 170 */
  29774. { { 0x61a1987ffa0a5fL,0x42058c7fc213c6L,0x15b1d38447d2c9L,
  29775. 0x3d5f5d7932565eL,0x5db754af445fa7L,0x5d489189fba499L,
  29776. 0x02c4c55f51141bL },
  29777. { 0x26b15972e9993dL,0x2fc90bcbd97c45L,0x2ff60f8684b0f1L,
  29778. 0x1dc641dd339ab0L,0x3e38e6be23f82cL,0x3368162752c817L,
  29779. 0x19bba80ceb45ceL } },
  29780. /* 171 */
  29781. { { 0x7c6e95b4c6c693L,0x6bbc6d5efa7093L,0x74d7f90bf3bf1cL,
  29782. 0x54d5be1f0299a1L,0x7cb24f0aa427c6L,0x0a18f3e086c941L,
  29783. 0x058a1c90e4faefL },
  29784. { 0x3d6bd016927e1eL,0x1da4ce773098b8L,0x2133522e690056L,
  29785. 0x0751416d3fc37eL,0x1beed1643eda66L,0x5288b6727d5c54L,
  29786. 0x199320e78655c6L } },
  29787. /* 172 */
  29788. { { 0x74575027eeaf94L,0x124bd533c3ceaeL,0x69421ab7a8a1d7L,
  29789. 0x37f2127e093f3dL,0x40281765252a08L,0x25a228798d856dL,
  29790. 0x326eca62759c4cL },
  29791. { 0x0c337c51acb0a5L,0x122ba78c1ef110L,0x02498adbb68dc4L,
  29792. 0x67240c124b089eL,0x135865d25d9f89L,0x338a76d5ae5670L,
  29793. 0x03a8efaf130385L } },
  29794. /* 173 */
  29795. { { 0x3a450ac5e49beaL,0x282af80bb4b395L,0x6779eb0db1a139L,
  29796. 0x737cabdd174e55L,0x017b14ca79b5f2L,0x61fdef6048e137L,
  29797. 0x3acc12641f6277L },
  29798. { 0x0f730746fe5096L,0x21d05c09d55ea1L,0x64d44bddb1a560L,
  29799. 0x75e5035c4778deL,0x158b7776613513L,0x7b5efa90c7599eL,
  29800. 0x2caa0791253b95L } },
  29801. /* 174 */
  29802. { { 0x288e5b6d53e6baL,0x435228909d45feL,0x33b4cf23b2a437L,
  29803. 0x45b352017d6db0L,0x4372d579d6ef32L,0x0fa9e5badbbd84L,
  29804. 0x3a78cff24759bbL },
  29805. { 0x0899d2039eab6eL,0x4cf47d2f76bc22L,0x373f739a3a8c69L,
  29806. 0x09beaa5b1000b3L,0x0acdfbe83ebae5L,0x10c10befb0e900L,
  29807. 0x33d2ac4cc31be3L } },
  29808. /* 175 */
  29809. { { 0x765845931e08fbL,0x2a3c2a0dc58007L,0x7270da587d90e1L,
  29810. 0x1ee648b2bc8f86L,0x5d2ca68107b29eL,0x2b7064846e9e92L,
  29811. 0x3633ed98dbb962L },
  29812. { 0x5e0f16a0349b1bL,0x58d8941f570ca4L,0x20abe376a4cf34L,
  29813. 0x0f4bd69a360977L,0x21eb07cc424ba7L,0x720d2ecdbbe6ecL,
  29814. 0x255597d5a97c34L } },
  29815. /* 176 */
  29816. { { 0x67bbf21a0f5e94L,0x422a3b05a64fc1L,0x773ac447ebddc7L,
  29817. 0x1a1331c08019f1L,0x01ef6d269744ddL,0x55f7be5b3b401aL,
  29818. 0x072e031c681273L },
  29819. { 0x7183289e21c677L,0x5e0a3391f3162fL,0x5e02d9e65d914aL,
  29820. 0x07c79ea1adce2fL,0x667ca5c2e1cbe4L,0x4f287f22caccdaL,
  29821. 0x27eaa81673e75bL } },
  29822. /* 177 */
  29823. { { 0x5246180a078fe6L,0x67cc8c9fa3bb15L,0x370f8dd123db31L,
  29824. 0x1938dafa69671aL,0x5af72624950c5eL,0x78cc5221ebddf8L,
  29825. 0x22d616fe2a84caL },
  29826. { 0x723985a839327fL,0x24fa95584a5e22L,0x3d8a5b3138d38bL,
  29827. 0x3829ef4a017acfL,0x4f09b00ae055c4L,0x01df84552e4516L,
  29828. 0x2a7a18993e8306L } },
  29829. /* 178 */
  29830. { { 0x7b6224bc310eccL,0x69e2cff429da16L,0x01c850e5722869L,
  29831. 0x2e4889443ee84bL,0x264a8df1b3d09fL,0x18a73fe478d0d6L,
  29832. 0x370b52740f9635L },
  29833. { 0x52b7d3a9d6f501L,0x5c49808129ee42L,0x5b64e2643fd30cL,
  29834. 0x27d903fe31b32cL,0x594cb084d078f9L,0x567fb33e3ae650L,
  29835. 0x0db7be9932cb65L } },
  29836. /* 179 */
  29837. { { 0x19b78113ed7cbeL,0x002b2f097a1c8cL,0x70b1dc17fa5794L,
  29838. 0x786e8419519128L,0x1a45ba376af995L,0x4f6aa84b8d806cL,
  29839. 0x204b4b3bc7ca47L },
  29840. { 0x7581a05fd94972L,0x1c73cadb870799L,0x758f6fefc09b88L,
  29841. 0x35c62ba8049b42L,0x6f5e71fc164cc3L,0x0cd738b5702721L,
  29842. 0x10021afac9a423L } },
  29843. /* 180 */
  29844. { { 0x654f7937e3c115L,0x5d198288b515cbL,0x4add965c25a6e3L,
  29845. 0x5a37df33cd76ffL,0x57bb7e288e1631L,0x049b69089e1a31L,
  29846. 0x383a88f4122a99L },
  29847. { 0x4c0e4ef3d80a73L,0x553c77ac9f30e2L,0x20bb18c2021e82L,
  29848. 0x2aec0d1c4225c5L,0x397fce0ac9c302L,0x2ab0c2a246e8aaL,
  29849. 0x02e5e5190be080L } },
  29850. /* 181 */
  29851. { { 0x7a255a4ae03080L,0x0d68b01513f624L,0x29905bd4e48c8cL,
  29852. 0x1d81507027466bL,0x1684aaeb70dee1L,0x7dd460719f0981L,
  29853. 0x29c43b0f0a390cL },
  29854. { 0x272567681b1f7dL,0x1d2a5f8502e0efL,0x0fd5cd6b221befL,
  29855. 0x5eb4749e9a0434L,0x7d1553a324e2a6L,0x2eefd8e86a7804L,
  29856. 0x2ad80d5335109cL } },
  29857. /* 182 */
  29858. { { 0x25342aef4c209dL,0x24e811ac4e0865L,0x3f209757f8ae9dL,
  29859. 0x1473ff8a5da57bL,0x340f61c3919cedL,0x7523bf85fb9bc0L,
  29860. 0x319602ebca7cceL },
  29861. { 0x121e7541d442cbL,0x4ffa748e49c95cL,0x11493cd1d131dcL,
  29862. 0x42b215172ab6b5L,0x045fd87e13cc77L,0x0ae305df76342fL,
  29863. 0x373b033c538512L } },
  29864. /* 183 */
  29865. { { 0x389541e9539819L,0x769f3b29b7e239L,0x0d05f695e3232cL,
  29866. 0x029d04f0e9a9fbL,0x58b78b7a697fb8L,0x7531b082e6386bL,
  29867. 0x215d235bed95a9L },
  29868. { 0x503947c1859c5dL,0x4b82a6ba45443fL,0x78328eab71b3a5L,
  29869. 0x7d8a77f8cb3509L,0x53fcd9802e41d4L,0x77552091976edbL,
  29870. 0x226c60ad7a5156L } },
  29871. /* 184 */
  29872. { { 0x77ad6a43360710L,0x0fdeabd326d7aeL,0x4012886c92104aL,
  29873. 0x2d6c378dd7ae33L,0x7e72ef2c0725f3L,0x4a4671f4ca18e0L,
  29874. 0x0afe3b4bb6220fL },
  29875. { 0x212cf4b56e0d6aL,0x7c24d086521960L,0x0662cf71bd414dL,
  29876. 0x1085b916c58c25L,0x781eed2be9a350L,0x26880e80db6ab2L,
  29877. 0x169e356442f061L } },
  29878. /* 185 */
  29879. { { 0x57aa2ad748b02cL,0x68a34256772a9aL,0x1591c44962f96cL,
  29880. 0x110a9edd6e53d2L,0x31eab597e091a3L,0x603e64e200c65dL,
  29881. 0x2f66b72e8a1cfcL },
  29882. { 0x5c79d138543f7fL,0x412524363fdfa3L,0x547977e3b40008L,
  29883. 0x735ca25436d9f7L,0x232b4888cae049L,0x27ce37a53d8f23L,
  29884. 0x34d45881a9b470L } },
  29885. /* 186 */
  29886. { { 0x76b95255924f43L,0x035c9f3bd1aa5dL,0x5eb71a010b4bd0L,
  29887. 0x6ce8dda7e39f46L,0x35679627ea70c0L,0x5c987767c7d77eL,
  29888. 0x1fa28952b620b7L },
  29889. { 0x106f50b5924407L,0x1cc3435a889411L,0x0597cdce3bc528L,
  29890. 0x738f8b0d5077d1L,0x5894dd60c7dd6aL,0x0013d0721f5e2eL,
  29891. 0x344573480527d3L } },
  29892. /* 187 */
  29893. { { 0x2e2c1da52abf77L,0x394aa8464ad05eL,0x095259b7330a83L,
  29894. 0x686e81cf6a11f5L,0x405c7e48c93c7cL,0x65c3ca9444a2ecL,
  29895. 0x07bed6c59c3563L },
  29896. { 0x51f9d994fb1471L,0x3c3ecfa5283b4eL,0x494dccda63f6ccL,
  29897. 0x4d07b255363a75L,0x0d2b6d3155d118L,0x3c688299fc9497L,
  29898. 0x235692fa3dea3aL } },
  29899. /* 188 */
  29900. { { 0x16b4d452669e98L,0x72451fa85406b9L,0x674a145d39151fL,
  29901. 0x325ffd067ae098L,0x527e7805cd1ae0L,0x422a1d1789e48dL,
  29902. 0x3e27be63f55e07L },
  29903. { 0x7f95f6dee0b63fL,0x008e444cc74969L,0x01348f3a72b614L,
  29904. 0x000cfac81348c3L,0x508ae3e5309ce5L,0x2584fcdee44d34L,
  29905. 0x3a4dd994899ee9L } },
  29906. /* 189 */
  29907. { { 0x4d289cc0368708L,0x0e5ebc60dc3b40L,0x78cc44bfab1162L,
  29908. 0x77ef2173b7d11eL,0x06091718e39746L,0x30fe19319b83a4L,
  29909. 0x17e8f2988529c6L },
  29910. { 0x68188bdcaa9f2aL,0x0e64b1350c1bddL,0x5b18ebac7cc4b3L,
  29911. 0x75315a9fcc046eL,0x36e9770fd43db4L,0x54c5857fc69121L,
  29912. 0x0417e18f3e909aL } },
  29913. /* 190 */
  29914. { { 0x29795db38059adL,0x6efd20c8fd4016L,0x3b6d1ce8f95a1aL,
  29915. 0x4db68f177f8238L,0x14ec7278d2340fL,0x47bd77ff2b77abL,
  29916. 0x3d2dc8cd34e9fcL },
  29917. { 0x285980a5a83f0bL,0x08352e2d516654L,0x74894460481e1bL,
  29918. 0x17f6f3709c480dL,0x6b590d1b55221eL,0x45c100dc4c9be9L,
  29919. 0x1b13225f9d8b91L } },
  29920. /* 191 */
  29921. { { 0x0b905fb4b41d9dL,0x48cc8a474cb7a2L,0x4eda67e8de09b2L,
  29922. 0x1de47c829adde8L,0x118ad5b9933d77L,0x7a12665ac3f9a4L,
  29923. 0x05631a4fb52997L },
  29924. { 0x5fb2a8e6806e63L,0x27d96bbcca369bL,0x46066f1a6b8c7bL,
  29925. 0x63b58fc7ca3072L,0x170a36229c0d62L,0x57176f1e463203L,
  29926. 0x0c7ce083e73b9cL } },
  29927. /* 192 */
  29928. { { 0x31caf2c09e1c72L,0x6530253219e9d2L,0x7650c98b601c57L,
  29929. 0x182469f99d56c0L,0x415f65d292b7a7L,0x30f62a55549b8eL,
  29930. 0x30f443f643f465L },
  29931. { 0x6b35c575ddadd0L,0x14a23cf6d299eeL,0x2f0198c0967d7dL,
  29932. 0x1013058178d5bfL,0x39da601c9cc879L,0x09d8963ec340baL,
  29933. 0x1b735db13ad2a7L } },
  29934. /* 193 */
  29935. { { 0x20916ffdc83f01L,0x16892aa7c9f217L,0x6bff179888d532L,
  29936. 0x4adf3c3d366288L,0x41a62b954726aeL,0x3139609022aeb6L,
  29937. 0x3e8ab9b37aff7aL },
  29938. { 0x76bbc70f24659aL,0x33fa98513886c6L,0x13b26af62c4ea6L,
  29939. 0x3c4d5826389a0cL,0x526ec28c02bf6aL,0x751ff083d79a7cL,
  29940. 0x110ac647990224L } },
  29941. /* 194 */
  29942. { { 0x2c6c62fa2b6e20L,0x3d37edad30c299L,0x6ef25b44b65fcaL,
  29943. 0x7470846914558eL,0x712456eb913275L,0x075a967a9a280eL,
  29944. 0x186c8188f2a2a0L },
  29945. { 0x2f3b41a6a560b1L,0x3a8070b3f9e858L,0x140936ff0e1e78L,
  29946. 0x5fd298abe6da8aL,0x3823a55d08f153L,0x3445eafaee7552L,
  29947. 0x2a5fc96731a8b2L } },
  29948. /* 195 */
  29949. { { 0x06317be58edbbbL,0x4a38f3bfbe2786L,0x445b60f75896b7L,
  29950. 0x6ec7c92b5adf57L,0x07b6be8038a441L,0x1bcfe002879655L,
  29951. 0x2a2174037d6d0eL },
  29952. { 0x776790cf9e48bdL,0x73e14a2c4ed1d3L,0x7eb5ed5f2fc2f7L,
  29953. 0x3e0aedb821b384L,0x0ee3b7e151c12fL,0x51a6a29e044bb2L,
  29954. 0x0ba13a00cb0d86L } },
  29955. /* 196 */
  29956. { { 0x77607d563ec8d8L,0x023fc726996e44L,0x6bd63f577a9986L,
  29957. 0x114a6351e53973L,0x3efe97989da046L,0x1051166e117ed7L,
  29958. 0x0354933dd4fb5fL },
  29959. { 0x7699ca2f30c073L,0x4c973b83b9e6d3L,0x2017c2abdbc3e8L,
  29960. 0x0cdcdd7a26522bL,0x511070f5b23c7dL,0x70672327e83d57L,
  29961. 0x278f842b4a9f26L } },
  29962. /* 197 */
  29963. { { 0x0824f0d4ae972fL,0x60578dd08dcf52L,0x48a74858290fbbL,
  29964. 0x7302748bf23030L,0x184b229a178acfL,0x3e8460ade089d6L,
  29965. 0x13f2b557fad533L },
  29966. { 0x7f96f3ae728d15L,0x018d8d40066341L,0x01fb94955a289aL,
  29967. 0x2d32ed6afc2657L,0x23f4f5e462c3acL,0x60eba5703bfc5aL,
  29968. 0x1b91cc06f16c7aL } },
  29969. /* 198 */
  29970. { { 0x411d68af8219b9L,0x79cca36320f4eeL,0x5c404e0ed72e20L,
  29971. 0x417cb8692e43f2L,0x305d29c7d98599L,0x3b754d5794a230L,
  29972. 0x1c97fb4be404e9L },
  29973. { 0x7cdbafababd109L,0x1ead0eb0ca5090L,0x1a2b56095303e3L,
  29974. 0x75dea935012c8fL,0x67e31c071b1d1dL,0x7c324fbfd172c3L,
  29975. 0x157e257e6498f7L } },
  29976. /* 199 */
  29977. { { 0x19b00db175645bL,0x4c4f6cb69725f1L,0x36d9ce67bd47ceL,
  29978. 0x2005e105179d64L,0x7b952e717867feL,0x3c28599204032cL,
  29979. 0x0f5659d44fb347L },
  29980. { 0x1ebcdedb979775L,0x4378d45cfd11a8L,0x14c85413ca66e9L,
  29981. 0x3dd17d681c8a4dL,0x58368e7dc23142L,0x14f3eaac6116afL,
  29982. 0x0adb45b255f6a0L } },
  29983. /* 200 */
  29984. { { 0x2f5e76279ad982L,0x125b3917034d09L,0x3839a6399e6ed3L,
  29985. 0x32fe0b3ebcd6a2L,0x24ccce8be90482L,0x467e26befcc187L,
  29986. 0x2828434e2e218eL },
  29987. { 0x17247cd386efd9L,0x27f36a468d85c3L,0x65e181ef203bbfL,
  29988. 0x0433a6761120afL,0x1d607a2a8f8625L,0x49f4e55a13d919L,
  29989. 0x3367c3b7943e9dL } },
  29990. /* 201 */
  29991. { { 0x3391c7d1a46d4dL,0x38233d602d260cL,0x02127a0f78b7d4L,
  29992. 0x56841c162c24c0L,0x4273648fd09aa8L,0x019480bb0e754eL,
  29993. 0x3b927987b87e58L },
  29994. { 0x6676be48c76f73L,0x01ec024e9655aeL,0x720fe1c6376704L,
  29995. 0x17e06b98885db3L,0x656adec85a4200L,0x73780893c3ce88L,
  29996. 0x0a339cdd8df664L } },
  29997. /* 202 */
  29998. { { 0x69af7244544ac7L,0x31ab7402084d2fL,0x67eceb7ef7cb19L,
  29999. 0x16f8583b996f61L,0x1e208d12faf91aL,0x4a91584ce4a42eL,
  30000. 0x3e08337216c93eL },
  30001. { 0x7a6eea94f4cf77L,0x07a52894678c60L,0x302dd06b14631eL,
  30002. 0x7fddb7225c9ceaL,0x55e441d7acd153L,0x2a00d4490b0f44L,
  30003. 0x053ef125338cdbL } },
  30004. /* 203 */
  30005. { { 0x120c0c51584e3cL,0x78b3efca804f37L,0x662108aefb1dccL,
  30006. 0x11deb55f126709L,0x66def11ada8125L,0x05bbc0d1001711L,
  30007. 0x1ee1c99c7fa316L },
  30008. { 0x746f287de53510L,0x1733ef2e32d09cL,0x1df64a2b0924beL,
  30009. 0x19758da8f6405eL,0x28f6eb3913e484L,0x7175a1090cc640L,
  30010. 0x048aee0d63f0bcL } },
  30011. /* 204 */
  30012. { { 0x1f3b1e3b0b29c3L,0x48649f4882a215L,0x485eca3a9e0dedL,
  30013. 0x4228ba85cc82e4L,0x36da1f39bc9379L,0x1659a7078499d1L,
  30014. 0x0a67d5f6c04188L },
  30015. { 0x6ac39658afdce3L,0x0d667a0bde8ef6L,0x0ae6ec0bfe8548L,
  30016. 0x6d9cb2650571bfL,0x54bea107760ab9L,0x705c53bd340cf2L,
  30017. 0x111a86b610c70fL } },
  30018. /* 205 */
  30019. { { 0x7ecea05c6b8195L,0x4f8be93ce3738dL,0x305de9eb9f5d12L,
  30020. 0x2c3b9d3d474b56L,0x673691a05746c3L,0x2e3482c428c6eaL,
  30021. 0x2a8085fde1f472L },
  30022. { 0x69d15877fd3226L,0x4609c9ec017cc3L,0x71e9b7fc1c3dbcL,
  30023. 0x4f8951254e2675L,0x63ee9d15afa010L,0x0f05775b645190L,
  30024. 0x28a0a439397ae3L } },
  30025. /* 206 */
  30026. { { 0x387fa03e9de330L,0x40cc32b828b6abL,0x02a482fbc04ac9L,
  30027. 0x68cad6e70429b7L,0x741877bff6f2c4L,0x48efe633d3b28bL,
  30028. 0x3e612218fe24b3L },
  30029. { 0x6fc1d34fe37657L,0x3d04b9e1c8b5a1L,0x6a2c332ef8f163L,
  30030. 0x7ca97e2b135690L,0x37357d2a31208aL,0x29f02f2332bd68L,
  30031. 0x17c674c3e63a57L } },
  30032. /* 207 */
  30033. { { 0x683d9a0e6865bbL,0x5e77ec68ad4ce5L,0x4d18f236788bd6L,
  30034. 0x7f34b87204f4e3L,0x391ca40e9e578dL,0x3470ed6ddf4e23L,
  30035. 0x225544b3e50989L },
  30036. { 0x48eda8cb4e462bL,0x2a948825cf9109L,0x473adedc7e1300L,
  30037. 0x37b843b82192edL,0x2b9ac1537dde36L,0x4efe7412732332L,
  30038. 0x29cc5981b5262bL } },
  30039. /* 208 */
  30040. { { 0x190d2fcad260f5L,0x7c53dd81d18027L,0x003def5f55db0eL,
  30041. 0x7f5ed25bee2df7L,0x2b87e9be167d2eL,0x2b999c7bbcd224L,
  30042. 0x1d68a2c260ad50L },
  30043. { 0x010bcde84607a6L,0x0250de9b7e1bedL,0x746d36bfaf1b56L,
  30044. 0x3359475ff56abbL,0x7e84b9bc440b20L,0x2eaa7e3b52f162L,
  30045. 0x01165412f36a69L } },
  30046. /* 209 */
  30047. { { 0x639a02329e5836L,0x7aa3ee2e4d3a27L,0x5bc9b258ecb279L,
  30048. 0x4cb3dfae2d62c6L,0x08d9d3b0c6c437L,0x5a2c177d47eab2L,
  30049. 0x36120479fc1f26L },
  30050. { 0x7609a75bd20e4aL,0x3ba414e17551fcL,0x42cd800e1b90c9L,
  30051. 0x04921811b88f9bL,0x4443697f9562fdL,0x3a8081b8186959L,
  30052. 0x3f5b5c97379e73L } },
  30053. /* 210 */
  30054. { { 0x6fd0e3cf13eafbL,0x3976b5415cbf67L,0x4de40889e48402L,
  30055. 0x17e4d36f24062aL,0x16ae7755cf334bL,0x2730ac94b7e0e1L,
  30056. 0x377592742f48e0L },
  30057. { 0x5e10b18a045041L,0x682792afaae5a1L,0x19383ec971b816L,
  30058. 0x208b17dae2ffc0L,0x439f9d933179b6L,0x55485a9090bcaeL,
  30059. 0x1c316f42a2a35cL } },
  30060. /* 211 */
  30061. { { 0x67173897bdf646L,0x0b6956653ef94eL,0x5be3c97f7ea852L,
  30062. 0x3110c12671f08eL,0x2474076a3fc7ecL,0x53408be503fe72L,
  30063. 0x09155f53a5b44eL },
  30064. { 0x5c804bdd4c27cdL,0x61e81eb8ffd50eL,0x2f7157fdf84717L,
  30065. 0x081f880d646440L,0x7aa892acddec51L,0x6ae70683443f33L,
  30066. 0x31ed9e8b33a75aL } },
  30067. /* 212 */
  30068. { { 0x0d724f8e357586L,0x1febbec91b4134L,0x6ff7b98a9475fdL,
  30069. 0x1c4d9b94e1f364L,0x2b8790499cef00L,0x42fd2080a1b31dL,
  30070. 0x3a3bbc6d9b0145L },
  30071. { 0x75bfebc37e3ca9L,0x28db49c1723bd7L,0x50b12fa8a1f17aL,
  30072. 0x733d95bbc84b98L,0x45ede81f6c109eL,0x18f5e46fb37b5fL,
  30073. 0x34b980804aaec1L } },
  30074. /* 213 */
  30075. { { 0x56060c8a4f57bfL,0x0d2dfe223054c2L,0x718a5bbc03e5d6L,
  30076. 0x7b3344cc19b3b9L,0x4d11c9c054bcefL,0x1f5ad422c22e33L,
  30077. 0x2609299076f86bL },
  30078. { 0x7b7a5fba89fd01L,0x7013113ef3b016L,0x23d5e0a173e34eL,
  30079. 0x736c14462f0f50L,0x1ef5f7ac74536aL,0x4baba6f4400ea4L,
  30080. 0x17b310612c9828L } },
  30081. /* 214 */
  30082. { { 0x4ebb19a708c8d3L,0x209f8c7f03d9bbL,0x00461cfe5798fbL,
  30083. 0x4f93b6ae822fadL,0x2e5b33b5ad5447L,0x40b024e547a84bL,
  30084. 0x22ffad40443385L },
  30085. { 0x33809c888228bfL,0x559f655fefbe84L,0x0032f529fd2f60L,
  30086. 0x5a2191ece3478cL,0x5b957fcd771246L,0x6fec181f9ed123L,
  30087. 0x33eed3624136a3L } },
  30088. /* 215 */
  30089. { { 0x6a5df93b26139aL,0x55076598fd7134L,0x356a592f34f81dL,
  30090. 0x493c6b5a3d4741L,0x435498a4e2a39bL,0x2cd26a0d931c88L,
  30091. 0x01925ea3fc7835L },
  30092. { 0x6e8d992b1efa05L,0x79508a727c667bL,0x5f3c15e6b4b698L,
  30093. 0x11b6c755257b93L,0x617f5af4b46393L,0x248d995b2b6656L,
  30094. 0x339db62e2e22ecL } },
  30095. /* 216 */
  30096. { { 0x52537a083843dcL,0x6a283c82a768c7L,0x13aa6bf25227acL,
  30097. 0x768d76ba8baf5eL,0x682977a6525808L,0x67ace52ac23b0bL,
  30098. 0x2374b5a2ed612dL },
  30099. { 0x7139e60133c3a4L,0x715697a4f1d446L,0x4b018bf36677a0L,
  30100. 0x1dd43837414d83L,0x505ec70730d4f6L,0x09ac100907fa79L,
  30101. 0x21caad6e03217eL } },
  30102. /* 217 */
  30103. { { 0x0776d3999d4d49L,0x33bdd87e8bcff8L,0x1036b87f068fadL,
  30104. 0x0a9b8ffde4c872L,0x7ab2533596b1eaL,0x305a88fb965378L,
  30105. 0x3356d8fa4d65e5L },
  30106. { 0x3366fa77d1ff11L,0x1e0bdbdcd2075cL,0x46910cefc967caL,
  30107. 0x7ce700737a1ff6L,0x1c5dc15409c9bdL,0x368436b9bdb595L,
  30108. 0x3e7ccd6560b5efL } },
  30109. /* 218 */
  30110. { { 0x1443789422c792L,0x524792b1717f2bL,0x1f7c1d95048e7aL,
  30111. 0x5cfe2a225b0d12L,0x245594d29ce85bL,0x20134d254ce168L,
  30112. 0x1b83296803921aL },
  30113. { 0x79a78285b3beceL,0x3c738c3f3124d6L,0x6ab9d1fe0907cdL,
  30114. 0x0652ceb7fc104cL,0x06b5f58c8ae3fdL,0x486959261c5328L,
  30115. 0x0b3813ae677c90L } },
  30116. /* 219 */
  30117. { { 0x66b9941ac37b82L,0x651a4b609b0686L,0x046711edf3fc31L,
  30118. 0x77f89f38faa89bL,0x2683ddbf2d5edbL,0x389ef1dfaa3c25L,
  30119. 0x20b3616e66273eL },
  30120. { 0x3c6db6e0cb5d37L,0x5d7ae5dc342bc4L,0x74a1dc6c52062bL,
  30121. 0x6f7c0bec109557L,0x5c51f7bc221d91L,0x0d7b5880745288L,
  30122. 0x1c46c145c4b0ddL } },
  30123. /* 220 */
  30124. { { 0x59ed485ea99eccL,0x201b71956bc21dL,0x72d5c32f73de65L,
  30125. 0x1aefd76547643eL,0x580a452cfb2c2dL,0x7cb1a63f5c4dc9L,
  30126. 0x39a8df727737aaL },
  30127. { 0x365a341deca452L,0x714a1ad1689cbaL,0x16981d12c42697L,
  30128. 0x5a124f4ac91c75L,0x1b2e3f2fedc0dbL,0x4a1c72b8e9d521L,
  30129. 0x3855b4694e4e20L } },
  30130. /* 221 */
  30131. { { 0x16b3d047181ae9L,0x17508832f011afL,0x50d33cfeb2ebd1L,
  30132. 0x1deae237349984L,0x147c641aa6adecL,0x24a9fb4ebb1ddbL,
  30133. 0x2b367504a7a969L },
  30134. { 0x4c55a3d430301bL,0x379ef6a5d492cbL,0x3c56541fc0f269L,
  30135. 0x73a546e91698ceL,0x2c2b62ee0b9b5dL,0x6284184d43d0efL,
  30136. 0x0e1f5cf6a4b9f0L } },
  30137. /* 222 */
  30138. { { 0x44833e8cd3fdacL,0x28e6665cb71c27L,0x2f8bf87f4ddbf3L,
  30139. 0x6cc6c767fb38daL,0x3bc114d734e8b5L,0x12963d5a78ca29L,
  30140. 0x34532a161ece41L },
  30141. { 0x2443af5d2d37e9L,0x54e6008c8c452bL,0x2c55d54111cf1bL,
  30142. 0x55ac7f7522575aL,0x00a6fba3f8575fL,0x3f92ef3b793b8dL,
  30143. 0x387b97d69ecdf7L } },
  30144. /* 223 */
  30145. { { 0x0b464812d29f46L,0x36161daa626f9aL,0x5202fbdb264ca5L,
  30146. 0x21245805ff1304L,0x7f9c4a65657885L,0x542d3887f9501cL,
  30147. 0x086420deef8507L },
  30148. { 0x5e159aa1b26cfbL,0x3f0ef5ffd0a50eL,0x364b29663a432aL,
  30149. 0x49c56888af32a8L,0x6f937e3e0945d1L,0x3cbdeec6d766cdL,
  30150. 0x2d80d342ece61aL } },
  30151. /* 224 */
  30152. { { 0x255e3026d8356eL,0x4ddba628c4de9aL,0x074323b593e0d9L,
  30153. 0x333bdb0a10eefbL,0x318b396e473c52L,0x6ebb5a95efd3d3L,
  30154. 0x3f3bff52aa4e4fL },
  30155. { 0x3138a111c731d5L,0x674365e283b308L,0x5585edd9c416f2L,
  30156. 0x466763d9070fd4L,0x1b568befce8128L,0x16eb040e7b921eL,
  30157. 0x3d5c898687c157L } },
  30158. /* 225 */
  30159. { { 0x14827736973088L,0x4e110d53f301e6L,0x1f811b09870023L,
  30160. 0x53b5e500dbcacaL,0x4ddf0df1e6a7dcL,0x1e9575fb10ce35L,
  30161. 0x3fdc153644d936L },
  30162. { 0x763547e2260594L,0x26e5ae764efc59L,0x13be6f4d791a29L,
  30163. 0x2021e61e3a0cf1L,0x339cd2b4a1c202L,0x5c7451e08f5121L,
  30164. 0x3728b3a851be68L } },
  30165. /* 226 */
  30166. { { 0x78873653277538L,0x444b9ed2ee7156L,0x79ac8b8b069cd3L,
  30167. 0x5f0e90933770e8L,0x307662c615389eL,0x40fe6d95a80057L,
  30168. 0x04822170cf993cL },
  30169. { 0x677d5690fbfec2L,0x0355af4ae95cb3L,0x417411794fe79eL,
  30170. 0x48daf87400a085L,0x33521d3b5f0aaaL,0x53567a3be00ff7L,
  30171. 0x04712ccfb1cafbL } },
  30172. /* 227 */
  30173. { { 0x2b983283c3a7f3L,0x579f11b146a9a6L,0x1143d3b16a020eL,
  30174. 0x20f1483ef58b20L,0x3f03e18d747f06L,0x3129d12f15de37L,
  30175. 0x24c911f7222833L },
  30176. { 0x1e0febcf3d5897L,0x505e26c01cdaacL,0x4f45a9adcff0e9L,
  30177. 0x14dfac063c5cebL,0x69e5ce713fededL,0x3481444a44611aL,
  30178. 0x0ea49295c7fdffL } },
  30179. /* 228 */
  30180. { { 0x64554cb4093beeL,0x344b4b18dd81f6L,0x350f43b4de9b59L,
  30181. 0x28a96a220934caL,0x4aa8da5689a515L,0x27171cbd518509L,
  30182. 0x0cfc1753f47c95L },
  30183. { 0x7dfe091b615d6eL,0x7d1ee0aa0fb5c1L,0x145eef3200b7b5L,
  30184. 0x33fe88feeab18fL,0x1d62d4f87453e2L,0x43b8db4e47fff1L,
  30185. 0x1572f2b8b8f368L } },
  30186. /* 229 */
  30187. { { 0x6bc94e6b4e84f3L,0x60629dee586a66L,0x3bbad5fe65ca18L,
  30188. 0x217670db6c2fefL,0x0320a7f4e3272aL,0x3ccff0d976a6deL,
  30189. 0x3c26da8ae48cccL },
  30190. { 0x53ecf156778435L,0x7533064765a443L,0x6c5c12f03ca5deL,
  30191. 0x44f8245350dabfL,0x342cdd777cf8b3L,0x2b539c42e9f58dL,
  30192. 0x10138affc279b1L } },
  30193. /* 230 */
  30194. { { 0x1b135e204c5ddbL,0x40887dfeaa1d37L,0x7fb0ef83da76ffL,
  30195. 0x521f2b79af55a5L,0x3f9b38b4c3f0d0L,0x20a9838cce61ceL,
  30196. 0x24bb4e2f4b1e32L },
  30197. { 0x003f6aa386e27cL,0x68df59db0a0f8eL,0x21677d5192e713L,
  30198. 0x14ab9757501276L,0x411944af961524L,0x3184f39abc5c3fL,
  30199. 0x2a8dda80ca078dL } },
  30200. /* 231 */
  30201. { { 0x0592233cdbc95cL,0x54d5de5c66f40fL,0x351caa1512ab86L,
  30202. 0x681bdbee020084L,0x6ee2480c853e68L,0x6a5a44262b918fL,
  30203. 0x06574e15a3b91dL },
  30204. { 0x31ba03dacd7fbeL,0x0c3da7c18a57a9L,0x49aaaded492d6bL,
  30205. 0x3071ff53469e02L,0x5efb4f0d7248c6L,0x6db5fb67f12628L,
  30206. 0x29cff668e3d024L } },
  30207. /* 232 */
  30208. { { 0x1b9ef3bb1b17ceL,0x6ccf8c24fe6312L,0x34c15487f45008L,
  30209. 0x1a84044095972cL,0x515073a47e449eL,0x2ddc93f9097feeL,
  30210. 0x1008fdc894c434L },
  30211. { 0x08e5edb73399faL,0x65b1aa65547d4cL,0x3a117a1057c498L,
  30212. 0x7e16c3089d13acL,0x502f2ae4b6f851L,0x57a70f3eb62673L,
  30213. 0x111b48a9a03667L } },
  30214. /* 233 */
  30215. { { 0x5023024be164f1L,0x25ad117032401eL,0x46612b3bfe3427L,
  30216. 0x2f4f406a8a02b7L,0x16a93a5c4ddf07L,0x7ee71968fcdbe9L,
  30217. 0x2267875ace37daL },
  30218. { 0x687e88b59eb2a6L,0x3ac7368fe716d3L,0x28d953a554a036L,
  30219. 0x34d52c0acca08fL,0x742a7cf8dd4fd9L,0x10bfeb8575ea60L,
  30220. 0x290e454d868dccL } },
  30221. /* 234 */
  30222. { { 0x4e72a3a8a4bdd2L,0x1ba36d1dee04d5L,0x7a43136b63195bL,
  30223. 0x6ca8e286a519f3L,0x568e64aece08a9L,0x571d5000b5c10bL,
  30224. 0x3f75e9f5dbdd40L },
  30225. { 0x6fb0a698d6fa45L,0x0ce42209d7199cL,0x1f68275f708a3eL,
  30226. 0x5749832e91ec3cL,0x6c3665521428b2L,0x14b2bf5747bd4aL,
  30227. 0x3b6f940e42a22bL } },
  30228. /* 235 */
  30229. { { 0x4da0adbfb26c82L,0x16792a585f39acL,0x17df9dfda3975cL,
  30230. 0x4796b4afaf479bL,0x67be67234e0020L,0x69df5f201dda25L,
  30231. 0x09f71a4d12b3dcL },
  30232. { 0x64ff5ec260a46aL,0x579c5b86385101L,0x4f29a7d549f697L,
  30233. 0x4e64261242e2ebL,0x54ecacdfb6b296L,0x46e0638b5fddadL,
  30234. 0x31eefd3208891dL } },
  30235. /* 236 */
  30236. { { 0x5b72c749fe01b2L,0x230cf27523713aL,0x533d1810e0d1e1L,
  30237. 0x5590db7d1dd1e2L,0x7b8ab73e8e43d3L,0x4c8a19bd1c17caL,
  30238. 0x19222ce9f74810L },
  30239. { 0x6398b3dddc4582L,0x0352b7d88dfd53L,0x3c55b4e10c5a63L,
  30240. 0x38194d13f8a237L,0x106683fd25dd87L,0x59e0b62443458eL,
  30241. 0x196cb70aa9cbb9L } },
  30242. /* 237 */
  30243. { { 0x2885f7cd021d63L,0x162bfd4c3e1043L,0x77173dcf98fcd1L,
  30244. 0x13d4591d6add36L,0x59311154d0d8f2L,0x74336e86e79b8aL,
  30245. 0x13faadc5661883L },
  30246. { 0x18938e7d9ec924L,0x14bcda8fcaa0a1L,0x706d85d41a1355L,
  30247. 0x0ac34520d168deL,0x5a92499fe17826L,0x36c2e3b4f00600L,
  30248. 0x29c2fd7b5f63deL } },
  30249. /* 238 */
  30250. { { 0x41250dfe2216c5L,0x44a0ec0366a217L,0x575bc1adf8b0dfL,
  30251. 0x5ff5cdbdb1800bL,0x7843d4dde8ca18L,0x5fa9e420865705L,
  30252. 0x235c38be6c6b02L },
  30253. { 0x473b78aae91abbL,0x39470c6051e44bL,0x3f973cc2dc08c3L,
  30254. 0x2837932c5c91f6L,0x25e39ed754ec25L,0x1371c837118e53L,
  30255. 0x3b99f3b0aeafe2L } },
  30256. /* 239 */
  30257. { { 0x03acf51be46c65L,0x271fceacbaf5c3L,0x476589ed3a5e25L,
  30258. 0x78ec8c3c3c399cL,0x1f5c8bf4ac4c19L,0x730bb733ec68d2L,
  30259. 0x29a37e00dd287eL },
  30260. { 0x448ed1bf92b5faL,0x10827c17b86478L,0x55e6fc05b28263L,
  30261. 0x0af1226c73a66aL,0x0b66e5df0d09c1L,0x26128315a02682L,
  30262. 0x22d84932c5e808L } },
  30263. /* 240 */
  30264. { { 0x5ec3afc26e3392L,0x08e142e45c0084L,0x4388d5ad0f01feL,
  30265. 0x0f7acd36e6140cL,0x028c14ed97dffbL,0x311845675a38c6L,
  30266. 0x01c1c8f09a3062L },
  30267. { 0x5a302f4cf49e7dL,0x79267e254a44e1L,0x746165052317a1L,
  30268. 0x53a09263a566e8L,0x7d478ad5f73abcL,0x187ce5c947dad3L,
  30269. 0x18564e1a1ec45fL } },
  30270. /* 241 */
  30271. { { 0x7b9577a9aa0486L,0x766b40c7aaaef6L,0x1f6a411f5db907L,
  30272. 0x4543dd4d80beaeL,0x0ad938c7482806L,0x451568bf4b9be1L,
  30273. 0x3367ec85d30a22L },
  30274. { 0x5446425747843dL,0x18d94ac223c6b2L,0x052ff3a354d359L,
  30275. 0x0b4933f89723f5L,0x03fb517740e056L,0x226b892871dddaL,
  30276. 0x2768c2b753f0fdL } },
  30277. /* 242 */
  30278. { { 0x685282ccfa5200L,0x411ed433627b89L,0x77d5c9b8bc9c1dL,
  30279. 0x4a13ef2ee5cd29L,0x5582a612407c9eL,0x2307cb42fc3aa9L,
  30280. 0x2e661df79956b8L },
  30281. { 0x0e972b015254deL,0x5b63e14def8adeL,0x06995be2ca4a95L,
  30282. 0x6cc0cc1e94bf27L,0x7ed8499fe0052aL,0x671a6ca5a5e0f9L,
  30283. 0x31e10d4ba10f05L } },
  30284. /* 243 */
  30285. { { 0x690af07e9b2d8aL,0x6030af9e32c8ddL,0x45c7ca3bf2b235L,
  30286. 0x40959077b76c81L,0x61eee7f70d5a96L,0x6b04f6aafe9e38L,
  30287. 0x3c726f55f1898dL },
  30288. { 0x77d0142a1a6194L,0x1c1631215708b9L,0x403a4f0a9b7585L,
  30289. 0x066c8e29f7cef0L,0x6fc32f98cf575eL,0x518a09d818c297L,
  30290. 0x34144e99989e75L } },
  30291. /* 244 */
  30292. { { 0x6adbada859fb6aL,0x0dcfb6506ccd51L,0x68f88b8d573e0dL,
  30293. 0x4b1ce35bd9af30L,0x241c8293ece2c9L,0x3b5f402c5c4adeL,
  30294. 0x34b9b1ee6fde87L },
  30295. { 0x5e625340075e63L,0x54c3f3d9050da1L,0x2a3f9152509016L,
  30296. 0x3274e46111bc18L,0x3a7504fd01ac73L,0x4169b387a43209L,
  30297. 0x35626f852bc6d4L } },
  30298. /* 245 */
  30299. { { 0x576a4f4662e53bL,0x5ea3f20eecec26L,0x4e5f02be5cd7b0L,
  30300. 0x72cc5ac3314be8L,0x0f604ed3201fe9L,0x2a29378ea54bceL,
  30301. 0x2d52bd4d6ec4b6L },
  30302. { 0x6a4c2b212c1c76L,0x778fd64a1bfa6dL,0x326828691863d6L,
  30303. 0x5616c8bd06a336L,0x5fab552564da4dL,0x46640cab3e91d2L,
  30304. 0x1d21f06427299eL } },
  30305. /* 246 */
  30306. { { 0x2bfe37dde98e9cL,0x164c54822332ebL,0x5b736c7df266e4L,
  30307. 0x59dab3a8da084cL,0x0ae1eab346f118L,0x182090a4327e3fL,
  30308. 0x07b13489dae2e6L },
  30309. { 0x3bc92645452baaL,0x30b159894ae574L,0x5b947c5c78e1f4L,
  30310. 0x18f0e004a3c77fL,0x48ca8f357077d9L,0x349ffdcef9bca9L,
  30311. 0x3ed224bfd54772L } },
  30312. /* 247 */
  30313. { { 0x1bdad02db8dff8L,0x69fab4450b44b6L,0x3b6802d187518bL,
  30314. 0x098368d8eb556cL,0x3fe1943fbefcf4L,0x008851d0de6d42L,
  30315. 0x322cbc4605fe25L },
  30316. { 0x2528aaf0d51afbL,0x7d48a9363a0cecL,0x4ba8f77d9a8f8bL,
  30317. 0x7dee903437d6c7L,0x1ff5a0d9ccc4b4L,0x34d9bd2fa99831L,
  30318. 0x30d9e4f58667c6L } },
  30319. /* 248 */
  30320. { { 0x38909b51b85197L,0x7ba16992512bd4L,0x2c776cfcfffec5L,
  30321. 0x2be7879075843cL,0x557e2b05d28ffcL,0x641b17bc5ce357L,
  30322. 0x1fcaf8a3710306L },
  30323. { 0x54dca2299a2d48L,0x745d06ef305acaL,0x7c41c65c6944c2L,
  30324. 0x679412ec431902L,0x48f2b15ee62827L,0x341a96d8afe06eL,
  30325. 0x2a78fd3690c0e1L } },
  30326. /* 249 */
  30327. { { 0x6b7cec83fbc9c6L,0x238e8a82eefc67L,0x5d3c1d9ff0928cL,
  30328. 0x55b816d6409bbfL,0x7969612adae364L,0x55b6ff96db654eL,
  30329. 0x129beca10073a9L },
  30330. { 0x0b1d2acdfc73deL,0x5d1a3605fa64bdL,0x436076146743beL,
  30331. 0x64044b89fcce0cL,0x7ae7b3c18f7fafL,0x7f083ee27cea36L,
  30332. 0x0292cd0d7c1ff0L } },
  30333. /* 250 */
  30334. { { 0x5a3c4c019b7d2eL,0x1a35a9b89712fbL,0x38736cc4f18c72L,
  30335. 0x603dd832a44e6bL,0x000d1d44aed104L,0x69b1f2fc274ebeL,
  30336. 0x03a7b993f76977L },
  30337. { 0x299f3b3e346910L,0x5243f45295afd5L,0x34342cbfa588bdL,
  30338. 0x72c40dd1155510L,0x718024fed2f991L,0x2f935e765ad82aL,
  30339. 0x246799ea371fb8L } },
  30340. /* 251 */
  30341. { { 0x24fe4c76250533L,0x01cafb02fdf18eL,0x505cb25d462882L,
  30342. 0x3e038175157d87L,0x7e3e99b10cdeb1L,0x38b7e72ebc7936L,
  30343. 0x081845f7c73433L },
  30344. { 0x049e61be05ebd5L,0x6ab82d8f0581f6L,0x62adffb427ac2eL,
  30345. 0x19431f809d198dL,0x36195f6c58b1d6L,0x22cc4c9dedc9a7L,
  30346. 0x24b146d8e694fcL } },
  30347. /* 252 */
  30348. { { 0x7c7bc8288b364dL,0x5c10f683cb894aL,0x19a62a68452958L,
  30349. 0x1fc24dcb4ce90eL,0x726baa4ed9581fL,0x1f34447dde73d6L,
  30350. 0x04c56708f30a21L },
  30351. { 0x131e583a3f4963L,0x071215b4d502e7L,0x196aca542e5940L,
  30352. 0x3afd5a91f7450eL,0x671b6eedf49497L,0x6aac7aca5c29e4L,
  30353. 0x3fb512470f138bL } },
  30354. /* 253 */
  30355. { { 0x5eadc3f4eb453eL,0x16c795ba34b666L,0x5d7612a4697fddL,
  30356. 0x24dd19bb499e86L,0x415b89ca3eeb9bL,0x7c83edf599d809L,
  30357. 0x13bc64c9b70269L },
  30358. { 0x52d3243dca3233L,0x0b21444b3a96a7L,0x6d551bc0083b90L,
  30359. 0x4f535b88c61176L,0x11e61924298010L,0x0a155b415bb61dL,
  30360. 0x17f94fbd26658fL } },
  30361. /* 254 */
  30362. { { 0x2dd06b90c28c65L,0x48582339c8fa6eL,0x01ac8bf2085d94L,
  30363. 0x053e660e020fdcL,0x1bece667edf07bL,0x4558f2b33ce24cL,
  30364. 0x2f1a766e8673fcL },
  30365. { 0x1d77cd13c06819L,0x4d5dc5056f3a01L,0x18896c6fa18d69L,
  30366. 0x120047ca76d625L,0x6af8457d4f4e45L,0x70ddc53358b60aL,
  30367. 0x330e11130e82f0L } },
  30368. /* 255 */
  30369. { { 0x0643b1cd4c2356L,0x10a2ea0a8f7c92L,0x2752513011d029L,
  30370. 0x4cd4c50321f579L,0x5fdf9ba5724792L,0x2f691653e2ddc0L,
  30371. 0x0cfed3d84226cbL },
  30372. { 0x704902a950f955L,0x069bfdb87bbf0cL,0x5817eeda8a5f84L,
  30373. 0x1914cdd9089905L,0x0e4a323d7b93f4L,0x1cc3fc340af0b2L,
  30374. 0x23874161bd6303L } },
  30375. };
  30376. /* Multiply the base point of P384 by the scalar and return the result.
  30377. * If map is true then convert result to affine coordinates.
  30378. *
  30379. * Stripe implementation.
  30380. * Pre-generated: 2^0, 2^48, ...
  30381. * Pre-generated: products of all combinations of above.
  30382. * 8 doubles and adds (with qz=1)
  30383. *
  30384. * r Resulting point.
  30385. * k Scalar to multiply by.
  30386. * map Indicates whether to convert result to affine.
  30387. * ct Constant time required.
  30388. * heap Heap to use for allocation.
  30389. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  30390. */
  30391. static int sp_384_ecc_mulmod_base_7(sp_point_384* r, const sp_digit* k,
  30392. int map, int ct, void* heap)
  30393. {
  30394. return sp_384_ecc_mulmod_stripe_7(r, &p384_base, p384_table,
  30395. k, map, ct, heap);
  30396. }
  30397. #endif
  30398. /* Multiply the base point of P384 by the scalar and return the result.
  30399. * If map is true then convert result to affine coordinates.
  30400. *
  30401. * km Scalar to multiply by.
  30402. * r Resulting point.
  30403. * map Indicates whether to convert result to affine.
  30404. * heap Heap to use for allocation.
  30405. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  30406. */
  30407. int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap)
  30408. {
  30409. #ifdef WOLFSSL_SP_SMALL_STACK
  30410. sp_point_384* point = NULL;
  30411. sp_digit* k = NULL;
  30412. #else
  30413. sp_point_384 point[1];
  30414. sp_digit k[7];
  30415. #endif
  30416. int err = MP_OKAY;
  30417. #ifdef WOLFSSL_SP_SMALL_STACK
  30418. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap,
  30419. DYNAMIC_TYPE_ECC);
  30420. if (point == NULL)
  30421. err = MEMORY_E;
  30422. if (err == MP_OKAY) {
  30423. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7, heap,
  30424. DYNAMIC_TYPE_ECC);
  30425. if (k == NULL)
  30426. err = MEMORY_E;
  30427. }
  30428. #endif
  30429. if (err == MP_OKAY) {
  30430. sp_384_from_mp(k, 7, km);
  30431. err = sp_384_ecc_mulmod_base_7(point, k, map, 1, heap);
  30432. }
  30433. if (err == MP_OKAY) {
  30434. err = sp_384_point_to_ecc_point_7(point, r);
  30435. }
  30436. #ifdef WOLFSSL_SP_SMALL_STACK
  30437. if (k != NULL)
  30438. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  30439. if (point != NULL)
  30440. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  30441. #endif
  30442. return err;
  30443. }
  30444. /* Multiply the base point of P384 by the scalar, add point a and return
  30445. * the result. If map is true then convert result to affine coordinates.
  30446. *
  30447. * km Scalar to multiply by.
  30448. * am Point to add to scalar multiply result.
  30449. * inMont Point to add is in montgomery form.
  30450. * r Resulting point.
  30451. * map Indicates whether to convert result to affine.
  30452. * heap Heap to use for allocation.
  30453. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  30454. */
  30455. int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am,
  30456. int inMont, ecc_point* r, int map, void* heap)
  30457. {
  30458. #ifdef WOLFSSL_SP_SMALL_STACK
  30459. sp_point_384* point = NULL;
  30460. sp_digit* k = NULL;
  30461. #else
  30462. sp_point_384 point[2];
  30463. sp_digit k[7 + 7 * 2 * 6];
  30464. #endif
  30465. sp_point_384* addP = NULL;
  30466. sp_digit* tmp = NULL;
  30467. int err = MP_OKAY;
  30468. #ifdef WOLFSSL_SP_SMALL_STACK
  30469. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap,
  30470. DYNAMIC_TYPE_ECC);
  30471. if (point == NULL)
  30472. err = MEMORY_E;
  30473. if (err == MP_OKAY) {
  30474. k = (sp_digit*)XMALLOC(
  30475. sizeof(sp_digit) * (7 + 7 * 2 * 6),
  30476. heap, DYNAMIC_TYPE_ECC);
  30477. if (k == NULL)
  30478. err = MEMORY_E;
  30479. }
  30480. #endif
  30481. if (err == MP_OKAY) {
  30482. addP = point + 1;
  30483. tmp = k + 7;
  30484. sp_384_from_mp(k, 7, km);
  30485. sp_384_point_from_ecc_point_7(addP, am);
  30486. }
  30487. if ((err == MP_OKAY) && (!inMont)) {
  30488. err = sp_384_mod_mul_norm_7(addP->x, addP->x, p384_mod);
  30489. }
  30490. if ((err == MP_OKAY) && (!inMont)) {
  30491. err = sp_384_mod_mul_norm_7(addP->y, addP->y, p384_mod);
  30492. }
  30493. if ((err == MP_OKAY) && (!inMont)) {
  30494. err = sp_384_mod_mul_norm_7(addP->z, addP->z, p384_mod);
  30495. }
  30496. if (err == MP_OKAY) {
  30497. err = sp_384_ecc_mulmod_base_7(point, k, 0, 0, heap);
  30498. }
  30499. if (err == MP_OKAY) {
  30500. sp_384_proj_point_add_7(point, point, addP, tmp);
  30501. if (map) {
  30502. sp_384_map_7(point, point, tmp);
  30503. }
  30504. err = sp_384_point_to_ecc_point_7(point, r);
  30505. }
  30506. #ifdef WOLFSSL_SP_SMALL_STACK
  30507. if (k != NULL)
  30508. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  30509. if (point)
  30510. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  30511. #endif
  30512. return err;
  30513. }
  30514. #if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
  30515. defined(HAVE_ECC_VERIFY)
  30516. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN | HAVE_ECC_SIGN | HAVE_ECC_VERIFY */
  30517. /* Add 1 to a. (a = a + 1)
  30518. *
  30519. * r A single precision integer.
  30520. * a A single precision integer.
  30521. */
  30522. SP_NOINLINE static void sp_384_add_one_7(sp_digit* a)
  30523. {
  30524. a[0]++;
  30525. sp_384_norm_7(a);
  30526. }
  30527. /* Read big endian unsigned byte array into r.
  30528. *
  30529. * r A single precision integer.
  30530. * size Maximum number of bytes to convert
  30531. * a Byte array.
  30532. * n Number of bytes in array to read.
  30533. */
  30534. static void sp_384_from_bin(sp_digit* r, int size, const byte* a, int n)
  30535. {
  30536. int i;
  30537. int j = 0;
  30538. word32 s = 0;
  30539. r[0] = 0;
  30540. for (i = n-1; i >= 0; i--) {
  30541. r[j] |= (((sp_digit)a[i]) << s);
  30542. if (s >= 47U) {
  30543. r[j] &= 0x7fffffffffffffL;
  30544. s = 55U - s;
  30545. if (j + 1 >= size) {
  30546. break;
  30547. }
  30548. r[++j] = (sp_digit)a[i] >> s;
  30549. s = 8U - s;
  30550. }
  30551. else {
  30552. s += 8U;
  30553. }
  30554. }
  30555. for (j++; j < size; j++) {
  30556. r[j] = 0;
  30557. }
  30558. }
  30559. /* Generates a scalar that is in the range 1..order-1.
  30560. *
  30561. * rng Random number generator.
  30562. * k Scalar value.
  30563. * returns RNG failures, MEMORY_E when memory allocation fails and
  30564. * MP_OKAY on success.
  30565. */
  30566. static int sp_384_ecc_gen_k_7(WC_RNG* rng, sp_digit* k)
  30567. {
  30568. int err;
  30569. byte buf[48];
  30570. do {
  30571. err = wc_RNG_GenerateBlock(rng, buf, sizeof(buf));
  30572. if (err == 0) {
  30573. sp_384_from_bin(k, 7, buf, (int)sizeof(buf));
  30574. if (sp_384_cmp_7(k, p384_order2) <= 0) {
  30575. sp_384_add_one_7(k);
  30576. break;
  30577. }
  30578. }
  30579. }
  30580. while (err == 0);
  30581. return err;
  30582. }
  30583. /* Makes a random EC key pair.
  30584. *
  30585. * rng Random number generator.
  30586. * priv Generated private value.
  30587. * pub Generated public point.
  30588. * heap Heap to use for allocation.
  30589. * returns ECC_INF_E when the point does not have the correct order, RNG
  30590. * failures, MEMORY_E when memory allocation fails and MP_OKAY on success.
  30591. */
  30592. int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
  30593. {
  30594. #ifdef WOLFSSL_SP_SMALL_STACK
  30595. sp_point_384* point = NULL;
  30596. sp_digit* k = NULL;
  30597. #else
  30598. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30599. sp_point_384 point[2];
  30600. #else
  30601. sp_point_384 point[1];
  30602. #endif
  30603. sp_digit k[7];
  30604. #endif
  30605. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30606. sp_point_384* infinity = NULL;
  30607. #endif
  30608. int err = MP_OKAY;
  30609. (void)heap;
  30610. #ifdef WOLFSSL_SP_SMALL_STACK
  30611. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30612. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC);
  30613. #else
  30614. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC);
  30615. #endif
  30616. if (point == NULL)
  30617. err = MEMORY_E;
  30618. if (err == MP_OKAY) {
  30619. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7, heap,
  30620. DYNAMIC_TYPE_ECC);
  30621. if (k == NULL)
  30622. err = MEMORY_E;
  30623. }
  30624. #endif
  30625. if (err == MP_OKAY) {
  30626. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30627. infinity = point + 1;
  30628. #endif
  30629. err = sp_384_ecc_gen_k_7(rng, k);
  30630. }
  30631. if (err == MP_OKAY) {
  30632. err = sp_384_ecc_mulmod_base_7(point, k, 1, 1, NULL);
  30633. }
  30634. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30635. if (err == MP_OKAY) {
  30636. err = sp_384_ecc_mulmod_7(infinity, point, p384_order, 1, 1, NULL);
  30637. }
  30638. if (err == MP_OKAY) {
  30639. if (sp_384_iszero_7(point->x) || sp_384_iszero_7(point->y)) {
  30640. err = ECC_INF_E;
  30641. }
  30642. }
  30643. #endif
  30644. if (err == MP_OKAY) {
  30645. err = sp_384_to_mp(k, priv);
  30646. }
  30647. if (err == MP_OKAY) {
  30648. err = sp_384_point_to_ecc_point_7(point, pub);
  30649. }
  30650. #ifdef WOLFSSL_SP_SMALL_STACK
  30651. if (k != NULL)
  30652. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  30653. if (point != NULL) {
  30654. /* point is not sensitive, so no need to zeroize */
  30655. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  30656. }
  30657. #endif
  30658. return err;
  30659. }
  30660. #ifdef WOLFSSL_SP_NONBLOCK
  30661. typedef struct sp_ecc_key_gen_384_ctx {
  30662. int state;
  30663. sp_384_ecc_mulmod_7_ctx mulmod_ctx;
  30664. sp_digit k[7];
  30665. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30666. sp_point_384 point[2];
  30667. #else
  30668. sp_point_384 point[1];
  30669. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  30670. } sp_ecc_key_gen_384_ctx;
  30671. int sp_ecc_make_key_384_nb(sp_ecc_ctx_t* sp_ctx, WC_RNG* rng, mp_int* priv,
  30672. ecc_point* pub, void* heap)
  30673. {
  30674. int err = FP_WOULDBLOCK;
  30675. sp_ecc_key_gen_384_ctx* ctx = (sp_ecc_key_gen_384_ctx*)sp_ctx->data;
  30676. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30677. sp_point_384* infinity = ctx->point + 1;
  30678. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  30679. typedef char ctx_size_test[sizeof(sp_ecc_key_gen_384_ctx)
  30680. >= sizeof(*sp_ctx) ? -1 : 1];
  30681. (void)sizeof(ctx_size_test);
  30682. switch (ctx->state) {
  30683. case 0:
  30684. err = sp_384_ecc_gen_k_7(rng, ctx->k);
  30685. if (err == MP_OKAY) {
  30686. err = FP_WOULDBLOCK;
  30687. ctx->state = 1;
  30688. }
  30689. break;
  30690. case 1:
  30691. err = sp_384_ecc_mulmod_base_7_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  30692. ctx->point, ctx->k, 1, 1, heap);
  30693. if (err == MP_OKAY) {
  30694. err = FP_WOULDBLOCK;
  30695. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30696. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  30697. ctx->state = 2;
  30698. #else
  30699. ctx->state = 3;
  30700. #endif
  30701. }
  30702. break;
  30703. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  30704. case 2:
  30705. err = sp_384_ecc_mulmod_7_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  30706. infinity, ctx->point, p384_order, 1, 1);
  30707. if (err == MP_OKAY) {
  30708. if (sp_384_iszero_7(ctx->point->x) ||
  30709. sp_384_iszero_7(ctx->point->y)) {
  30710. err = ECC_INF_E;
  30711. }
  30712. else {
  30713. err = FP_WOULDBLOCK;
  30714. ctx->state = 3;
  30715. }
  30716. }
  30717. break;
  30718. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  30719. case 3:
  30720. err = sp_384_to_mp(ctx->k, priv);
  30721. if (err == MP_OKAY) {
  30722. err = sp_384_point_to_ecc_point_7(ctx->point, pub);
  30723. }
  30724. break;
  30725. }
  30726. if (err != FP_WOULDBLOCK) {
  30727. XMEMSET(ctx, 0, sizeof(sp_ecc_key_gen_384_ctx));
  30728. }
  30729. return err;
  30730. }
  30731. #endif /* WOLFSSL_SP_NONBLOCK */
  30732. #ifdef HAVE_ECC_DHE
  30733. /* Write r as big endian to byte array.
  30734. * Fixed length number of bytes written: 48
  30735. *
  30736. * r A single precision integer.
  30737. * a Byte array.
  30738. */
  30739. static void sp_384_to_bin_7(sp_digit* r, byte* a)
  30740. {
  30741. int i;
  30742. int j;
  30743. int s = 0;
  30744. int b;
  30745. for (i=0; i<6; i++) {
  30746. r[i+1] += r[i] >> 55;
  30747. r[i] &= 0x7fffffffffffffL;
  30748. }
  30749. j = 391 / 8 - 1;
  30750. a[j] = 0;
  30751. for (i=0; i<7 && j>=0; i++) {
  30752. b = 0;
  30753. /* lint allow cast of mismatch sp_digit and int */
  30754. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  30755. b += 8 - s;
  30756. if (j < 0) {
  30757. break;
  30758. }
  30759. while (b < 55) {
  30760. a[j--] = (byte)(r[i] >> b);
  30761. b += 8;
  30762. if (j < 0) {
  30763. break;
  30764. }
  30765. }
  30766. s = 8 - (b - 55);
  30767. if (j >= 0) {
  30768. a[j] = 0;
  30769. }
  30770. if (s != 0) {
  30771. j++;
  30772. }
  30773. }
  30774. }
  30775. /* Multiply the point by the scalar and serialize the X ordinate.
  30776. * The number is 0 padded to maximum size on output.
  30777. *
  30778. * priv Scalar to multiply the point by.
  30779. * pub Point to multiply.
  30780. * out Buffer to hold X ordinate.
  30781. * outLen On entry, size of the buffer in bytes.
  30782. * On exit, length of data in buffer in bytes.
  30783. * heap Heap to use for allocation.
  30784. * returns BUFFER_E if the buffer is to small for output size,
  30785. * MEMORY_E when memory allocation fails and MP_OKAY on success.
  30786. */
  30787. int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out,
  30788. word32* outLen, void* heap)
  30789. {
  30790. #ifdef WOLFSSL_SP_SMALL_STACK
  30791. sp_point_384* point = NULL;
  30792. sp_digit* k = NULL;
  30793. #else
  30794. sp_point_384 point[1];
  30795. sp_digit k[7];
  30796. #endif
  30797. int err = MP_OKAY;
  30798. if (*outLen < 48U) {
  30799. err = BUFFER_E;
  30800. }
  30801. #ifdef WOLFSSL_SP_SMALL_STACK
  30802. if (err == MP_OKAY) {
  30803. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap,
  30804. DYNAMIC_TYPE_ECC);
  30805. if (point == NULL)
  30806. err = MEMORY_E;
  30807. }
  30808. if (err == MP_OKAY) {
  30809. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7, heap,
  30810. DYNAMIC_TYPE_ECC);
  30811. if (k == NULL)
  30812. err = MEMORY_E;
  30813. }
  30814. #endif
  30815. if (err == MP_OKAY) {
  30816. sp_384_from_mp(k, 7, priv);
  30817. sp_384_point_from_ecc_point_7(point, pub);
  30818. err = sp_384_ecc_mulmod_7(point, point, k, 1, 1, heap);
  30819. }
  30820. if (err == MP_OKAY) {
  30821. sp_384_to_bin_7(point->x, out);
  30822. *outLen = 48;
  30823. }
  30824. #ifdef WOLFSSL_SP_SMALL_STACK
  30825. if (k != NULL)
  30826. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  30827. if (point != NULL)
  30828. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  30829. #endif
  30830. return err;
  30831. }
  30832. #ifdef WOLFSSL_SP_NONBLOCK
  30833. typedef struct sp_ecc_sec_gen_384_ctx {
  30834. int state;
  30835. union {
  30836. sp_384_ecc_mulmod_7_ctx mulmod_ctx;
  30837. };
  30838. sp_digit k[7];
  30839. sp_point_384 point;
  30840. } sp_ecc_sec_gen_384_ctx;
  30841. int sp_ecc_secret_gen_384_nb(sp_ecc_ctx_t* sp_ctx, const mp_int* priv,
  30842. const ecc_point* pub, byte* out, word32* outLen, void* heap)
  30843. {
  30844. int err = FP_WOULDBLOCK;
  30845. sp_ecc_sec_gen_384_ctx* ctx = (sp_ecc_sec_gen_384_ctx*)sp_ctx->data;
  30846. typedef char ctx_size_test[sizeof(sp_ecc_sec_gen_384_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  30847. (void)sizeof(ctx_size_test);
  30848. if (*outLen < 32U) {
  30849. err = BUFFER_E;
  30850. }
  30851. switch (ctx->state) {
  30852. case 0:
  30853. sp_384_from_mp(ctx->k, 7, priv);
  30854. sp_384_point_from_ecc_point_7(&ctx->point, pub);
  30855. ctx->state = 1;
  30856. break;
  30857. case 1:
  30858. err = sp_384_ecc_mulmod_7_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  30859. &ctx->point, &ctx->point, ctx->k, 1, 1, heap);
  30860. if (err == MP_OKAY) {
  30861. sp_384_to_bin_7(ctx->point.x, out);
  30862. *outLen = 48;
  30863. }
  30864. break;
  30865. }
  30866. if (err == MP_OKAY && ctx->state != 1) {
  30867. err = FP_WOULDBLOCK;
  30868. }
  30869. if (err != FP_WOULDBLOCK) {
  30870. XMEMSET(ctx, 0, sizeof(sp_ecc_sec_gen_384_ctx));
  30871. }
  30872. return err;
  30873. }
  30874. #endif /* WOLFSSL_SP_NONBLOCK */
  30875. #endif /* HAVE_ECC_DHE */
  30876. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  30877. #endif
  30878. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  30879. SP_NOINLINE static void sp_384_rshift_7(sp_digit* r, const sp_digit* a,
  30880. byte n)
  30881. {
  30882. int i;
  30883. #ifdef WOLFSSL_SP_SMALL
  30884. for (i=0; i<6; i++) {
  30885. r[i] = ((a[i] >> n) | (a[i + 1] << (55 - n))) & 0x7fffffffffffffL;
  30886. }
  30887. #else
  30888. for (i=0; i<0; i += 8) {
  30889. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (55 - n)) & 0x7fffffffffffffL);
  30890. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (55 - n)) & 0x7fffffffffffffL);
  30891. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (55 - n)) & 0x7fffffffffffffL);
  30892. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (55 - n)) & 0x7fffffffffffffL);
  30893. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (55 - n)) & 0x7fffffffffffffL);
  30894. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (55 - n)) & 0x7fffffffffffffL);
  30895. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (55 - n)) & 0x7fffffffffffffL);
  30896. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (55 - n)) & 0x7fffffffffffffL);
  30897. }
  30898. r[0] = (a[0] >> n) | ((a[1] << (55 - n)) & 0x7fffffffffffffL);
  30899. r[1] = (a[1] >> n) | ((a[2] << (55 - n)) & 0x7fffffffffffffL);
  30900. r[2] = (a[2] >> n) | ((a[3] << (55 - n)) & 0x7fffffffffffffL);
  30901. r[3] = (a[3] >> n) | ((a[4] << (55 - n)) & 0x7fffffffffffffL);
  30902. r[4] = (a[4] >> n) | ((a[5] << (55 - n)) & 0x7fffffffffffffL);
  30903. r[5] = (a[5] >> n) | ((a[6] << (55 - n)) & 0x7fffffffffffffL);
  30904. #endif /* WOLFSSL_SP_SMALL */
  30905. r[6] = a[6] >> n;
  30906. }
  30907. /* Multiply a by scalar b into r. (r = a * b)
  30908. *
  30909. * r A single precision integer.
  30910. * a A single precision integer.
  30911. * b A scalar.
  30912. */
  30913. SP_NOINLINE static void sp_384_mul_d_7(sp_digit* r, const sp_digit* a,
  30914. sp_digit b)
  30915. {
  30916. #ifdef WOLFSSL_SP_SMALL
  30917. sp_int128 tb = b;
  30918. sp_int128 t = 0;
  30919. int i;
  30920. for (i = 0; i < 7; i++) {
  30921. t += tb * a[i];
  30922. r[i] = (sp_digit)(t & 0x7fffffffffffffL);
  30923. t >>= 55;
  30924. }
  30925. r[7] = (sp_digit)t;
  30926. #else
  30927. sp_int128 tb = b;
  30928. sp_int128 t[7];
  30929. t[ 0] = tb * a[ 0];
  30930. t[ 1] = tb * a[ 1];
  30931. t[ 2] = tb * a[ 2];
  30932. t[ 3] = tb * a[ 3];
  30933. t[ 4] = tb * a[ 4];
  30934. t[ 5] = tb * a[ 5];
  30935. t[ 6] = tb * a[ 6];
  30936. r[ 0] = (sp_digit) (t[ 0] & 0x7fffffffffffffL);
  30937. r[ 1] = (sp_digit)((t[ 0] >> 55) + (t[ 1] & 0x7fffffffffffffL));
  30938. r[ 2] = (sp_digit)((t[ 1] >> 55) + (t[ 2] & 0x7fffffffffffffL));
  30939. r[ 3] = (sp_digit)((t[ 2] >> 55) + (t[ 3] & 0x7fffffffffffffL));
  30940. r[ 4] = (sp_digit)((t[ 3] >> 55) + (t[ 4] & 0x7fffffffffffffL));
  30941. r[ 5] = (sp_digit)((t[ 4] >> 55) + (t[ 5] & 0x7fffffffffffffL));
  30942. r[ 6] = (sp_digit)((t[ 5] >> 55) + (t[ 6] & 0x7fffffffffffffL));
  30943. r[ 7] = (sp_digit) (t[ 6] >> 55);
  30944. #endif /* WOLFSSL_SP_SMALL */
  30945. }
  30946. SP_NOINLINE static void sp_384_lshift_14(sp_digit* r, const sp_digit* a,
  30947. byte n)
  30948. {
  30949. #ifdef WOLFSSL_SP_SMALL
  30950. int i;
  30951. r[14] = a[13] >> (55 - n);
  30952. for (i=13; i>0; i--) {
  30953. r[i] = ((a[i] << n) | (a[i-1] >> (55 - n))) & 0x7fffffffffffffL;
  30954. }
  30955. #else
  30956. sp_int_digit s;
  30957. sp_int_digit t;
  30958. s = (sp_int_digit)a[13];
  30959. r[14] = s >> (55U - n);
  30960. s = (sp_int_digit)(a[13]); t = (sp_int_digit)(a[12]);
  30961. r[13] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30962. s = (sp_int_digit)(a[12]); t = (sp_int_digit)(a[11]);
  30963. r[12] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30964. s = (sp_int_digit)(a[11]); t = (sp_int_digit)(a[10]);
  30965. r[11] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30966. s = (sp_int_digit)(a[10]); t = (sp_int_digit)(a[9]);
  30967. r[10] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30968. s = (sp_int_digit)(a[9]); t = (sp_int_digit)(a[8]);
  30969. r[9] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30970. s = (sp_int_digit)(a[8]); t = (sp_int_digit)(a[7]);
  30971. r[8] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30972. s = (sp_int_digit)(a[7]); t = (sp_int_digit)(a[6]);
  30973. r[7] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30974. s = (sp_int_digit)(a[6]); t = (sp_int_digit)(a[5]);
  30975. r[6] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30976. s = (sp_int_digit)(a[5]); t = (sp_int_digit)(a[4]);
  30977. r[5] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30978. s = (sp_int_digit)(a[4]); t = (sp_int_digit)(a[3]);
  30979. r[4] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30980. s = (sp_int_digit)(a[3]); t = (sp_int_digit)(a[2]);
  30981. r[3] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30982. s = (sp_int_digit)(a[2]); t = (sp_int_digit)(a[1]);
  30983. r[2] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30984. s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]);
  30985. r[1] = ((s << n) | (t >> (55U - n))) & 0x7fffffffffffffUL;
  30986. #endif /* WOLFSSL_SP_SMALL */
  30987. r[0] = (a[0] << n) & 0x7fffffffffffffL;
  30988. }
  30989. /* Divide d in a and put remainder into r (m*d + r = a)
  30990. * m is not calculated as it is not needed at this time.
  30991. *
  30992. * Simplified based on top word of divisor being (1 << 55) - 1
  30993. *
  30994. * a Number to be divided.
  30995. * d Number to divide with.
  30996. * m Multiplier result.
  30997. * r Remainder from the division.
  30998. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  30999. */
  31000. static int sp_384_div_7(const sp_digit* a, const sp_digit* d,
  31001. const sp_digit* m, sp_digit* r)
  31002. {
  31003. int i;
  31004. sp_digit r1;
  31005. sp_digit mask;
  31006. #ifdef WOLFSSL_SP_SMALL_STACK
  31007. sp_digit* t1 = NULL;
  31008. #else
  31009. sp_digit t1[4 * 7 + 3];
  31010. #endif
  31011. sp_digit* t2 = NULL;
  31012. sp_digit* sd = NULL;
  31013. int err = MP_OKAY;
  31014. (void)m;
  31015. #ifdef WOLFSSL_SP_SMALL_STACK
  31016. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 7 + 3), NULL,
  31017. DYNAMIC_TYPE_TMP_BUFFER);
  31018. if (t1 == NULL)
  31019. err = MEMORY_E;
  31020. #endif
  31021. (void)m;
  31022. if (err == MP_OKAY) {
  31023. t2 = t1 + 14 + 1;
  31024. sd = t2 + 7 + 1;
  31025. sp_384_mul_d_7(sd, d, (sp_digit)1 << 1);
  31026. sp_384_lshift_14(t1, a, 1);
  31027. t1[7 + 7] += t1[7 + 7 - 1] >> 55;
  31028. t1[7 + 7 - 1] &= 0x7fffffffffffffL;
  31029. for (i=6; i>=0; i--) {
  31030. r1 = t1[7 + i];
  31031. sp_384_mul_d_7(t2, sd, r1);
  31032. (void)sp_384_sub_7(&t1[i], &t1[i], t2);
  31033. t1[7 + i] -= t2[7];
  31034. sp_384_norm_7(&t1[i + 1]);
  31035. mask = ~((t1[7 + i] - 1) >> 63);
  31036. sp_384_cond_sub_7(t1 + i, t1 + i, sd, mask);
  31037. sp_384_norm_7(&t1[i + 1]);
  31038. }
  31039. sp_384_norm_7(t1);
  31040. sp_384_rshift_7(r, t1, 1);
  31041. }
  31042. #ifdef WOLFSSL_SP_SMALL_STACK
  31043. if (t1 != NULL)
  31044. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31045. #endif
  31046. return err;
  31047. }
  31048. /* Reduce a modulo m into r. (r = a mod m)
  31049. *
  31050. * r A single precision number that is the reduced result.
  31051. * a A single precision number that is to be reduced.
  31052. * m A single precision number that is the modulus to reduce with.
  31053. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  31054. */
  31055. static int sp_384_mod_7(sp_digit* r, const sp_digit* a, const sp_digit* m)
  31056. {
  31057. return sp_384_div_7(a, m, NULL, r);
  31058. }
  31059. #endif
  31060. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  31061. /* Multiply two number mod the order of P384 curve. (r = a * b mod order)
  31062. *
  31063. * r Result of the multiplication.
  31064. * a First operand of the multiplication.
  31065. * b Second operand of the multiplication.
  31066. */
  31067. static void sp_384_mont_mul_order_7(sp_digit* r, const sp_digit* a, const sp_digit* b)
  31068. {
  31069. sp_384_mul_7(r, a, b);
  31070. sp_384_mont_reduce_order_7(r, p384_order, p384_mp_order);
  31071. }
  31072. #if defined(HAVE_ECC_SIGN) || (defined(HAVE_ECC_VERIFY) && defined(WOLFSSL_SP_SMALL))
  31073. #ifdef WOLFSSL_SP_SMALL
  31074. /* Order-2 for the P384 curve. */
  31075. static const uint64_t p384_order_minus_2[6] = {
  31076. 0xecec196accc52971U,0x581a0db248b0a77aU,0xc7634d81f4372ddfU,
  31077. 0xffffffffffffffffU,0xffffffffffffffffU,0xffffffffffffffffU
  31078. };
  31079. #else
  31080. /* The low half of the order-2 of the P384 curve. */
  31081. static const uint64_t p384_order_low[3] = {
  31082. 0xecec196accc52971U,0x581a0db248b0a77aU,0xc7634d81f4372ddfU
  31083. };
  31084. #endif /* WOLFSSL_SP_SMALL */
  31085. /* Square number mod the order of P384 curve. (r = a * a mod order)
  31086. *
  31087. * r Result of the squaring.
  31088. * a Number to square.
  31089. */
  31090. static void sp_384_mont_sqr_order_7(sp_digit* r, const sp_digit* a)
  31091. {
  31092. sp_384_sqr_7(r, a);
  31093. sp_384_mont_reduce_order_7(r, p384_order, p384_mp_order);
  31094. }
  31095. #ifndef WOLFSSL_SP_SMALL
  31096. /* Square number mod the order of P384 curve a number of times.
  31097. * (r = a ^ n mod order)
  31098. *
  31099. * r Result of the squaring.
  31100. * a Number to square.
  31101. */
  31102. static void sp_384_mont_sqr_n_order_7(sp_digit* r, const sp_digit* a, int n)
  31103. {
  31104. int i;
  31105. sp_384_mont_sqr_order_7(r, a);
  31106. for (i=1; i<n; i++) {
  31107. sp_384_mont_sqr_order_7(r, r);
  31108. }
  31109. }
  31110. #endif /* !WOLFSSL_SP_SMALL */
  31111. /* Invert the number, in Montgomery form, modulo the order of the P384 curve.
  31112. * (r = 1 / a mod order)
  31113. *
  31114. * r Inverse result.
  31115. * a Number to invert.
  31116. * td Temporary data.
  31117. */
  31118. #ifdef WOLFSSL_SP_NONBLOCK
  31119. typedef struct sp_384_mont_inv_order_7_ctx {
  31120. int state;
  31121. int i;
  31122. } sp_384_mont_inv_order_7_ctx;
  31123. static int sp_384_mont_inv_order_7_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const sp_digit* a,
  31124. sp_digit* t)
  31125. {
  31126. int err = FP_WOULDBLOCK;
  31127. sp_384_mont_inv_order_7_ctx* ctx = (sp_384_mont_inv_order_7_ctx*)sp_ctx;
  31128. typedef char ctx_size_test[sizeof(sp_384_mont_inv_order_7_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  31129. (void)sizeof(ctx_size_test);
  31130. switch (ctx->state) {
  31131. case 0:
  31132. XMEMCPY(t, a, sizeof(sp_digit) * 7);
  31133. ctx->i = 382;
  31134. ctx->state = 1;
  31135. break;
  31136. case 1:
  31137. sp_384_mont_sqr_order_7(t, t);
  31138. ctx->state = 2;
  31139. break;
  31140. case 2:
  31141. if ((p384_order_minus_2[ctx->i / 64] & ((sp_int_digit)1 << (ctx->i % 64))) != 0) {
  31142. sp_384_mont_mul_order_7(t, t, a);
  31143. }
  31144. ctx->i--;
  31145. ctx->state = (ctx->i == 0) ? 3 : 1;
  31146. break;
  31147. case 3:
  31148. XMEMCPY(r, t, sizeof(sp_digit) * 7U);
  31149. err = MP_OKAY;
  31150. break;
  31151. }
  31152. return err;
  31153. }
  31154. #endif /* WOLFSSL_SP_NONBLOCK */
  31155. static void sp_384_mont_inv_order_7(sp_digit* r, const sp_digit* a,
  31156. sp_digit* td)
  31157. {
  31158. #ifdef WOLFSSL_SP_SMALL
  31159. sp_digit* t = td;
  31160. int i;
  31161. XMEMCPY(t, a, sizeof(sp_digit) * 7);
  31162. for (i=382; i>=0; i--) {
  31163. sp_384_mont_sqr_order_7(t, t);
  31164. if ((p384_order_minus_2[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  31165. sp_384_mont_mul_order_7(t, t, a);
  31166. }
  31167. }
  31168. XMEMCPY(r, t, sizeof(sp_digit) * 7U);
  31169. #else
  31170. sp_digit* t = td;
  31171. sp_digit* t2 = td + 2 * 7;
  31172. sp_digit* t3 = td + 4 * 7;
  31173. int i;
  31174. /* t = a^2 */
  31175. sp_384_mont_sqr_order_7(t, a);
  31176. /* t = a^3 = t * a */
  31177. sp_384_mont_mul_order_7(t, t, a);
  31178. /* t2= a^c = t ^ 2 ^ 2 */
  31179. sp_384_mont_sqr_n_order_7(t2, t, 2);
  31180. /* t = a^f = t2 * t */
  31181. sp_384_mont_mul_order_7(t, t2, t);
  31182. /* t2= a^f0 = t ^ 2 ^ 4 */
  31183. sp_384_mont_sqr_n_order_7(t2, t, 4);
  31184. /* t = a^ff = t2 * t */
  31185. sp_384_mont_mul_order_7(t, t2, t);
  31186. /* t2= a^ff00 = t ^ 2 ^ 8 */
  31187. sp_384_mont_sqr_n_order_7(t2, t, 8);
  31188. /* t3= a^ffff = t2 * t */
  31189. sp_384_mont_mul_order_7(t3, t2, t);
  31190. /* t2= a^ffff0000 = t3 ^ 2 ^ 16 */
  31191. sp_384_mont_sqr_n_order_7(t2, t3, 16);
  31192. /* t = a^ffffffff = t2 * t3 */
  31193. sp_384_mont_mul_order_7(t, t2, t3);
  31194. /* t2= a^ffffffff0000 = t ^ 2 ^ 16 */
  31195. sp_384_mont_sqr_n_order_7(t2, t, 16);
  31196. /* t = a^ffffffffffff = t2 * t3 */
  31197. sp_384_mont_mul_order_7(t, t2, t3);
  31198. /* t2= a^ffffffffffff000000000000 = t ^ 2 ^ 48 */
  31199. sp_384_mont_sqr_n_order_7(t2, t, 48);
  31200. /* t= a^fffffffffffffffffffffffff = t2 * t */
  31201. sp_384_mont_mul_order_7(t, t2, t);
  31202. /* t2= a^ffffffffffffffffffffffff000000000000000000000000 */
  31203. sp_384_mont_sqr_n_order_7(t2, t, 96);
  31204. /* t2= a^ffffffffffffffffffffffffffffffffffffffffffffffff = t2 * t */
  31205. sp_384_mont_mul_order_7(t2, t2, t);
  31206. for (i=191; i>=1; i--) {
  31207. sp_384_mont_sqr_order_7(t2, t2);
  31208. if ((p384_order_low[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  31209. sp_384_mont_mul_order_7(t2, t2, a);
  31210. }
  31211. }
  31212. sp_384_mont_sqr_order_7(t2, t2);
  31213. sp_384_mont_mul_order_7(r, t2, a);
  31214. #endif /* WOLFSSL_SP_SMALL */
  31215. }
  31216. #endif /* HAVE_ECC_SIGN || (HAVE_ECC_VERIFY && WOLFSSL_SP_SMALL) */
  31217. #endif /* HAVE_ECC_SIGN | HAVE_ECC_VERIFY */
  31218. #ifdef HAVE_ECC_SIGN
  31219. #ifndef SP_ECC_MAX_SIG_GEN
  31220. #define SP_ECC_MAX_SIG_GEN 64
  31221. #endif
  31222. /* Calculate second signature value S from R, k and private value.
  31223. *
  31224. * s = (r * x + e) / k
  31225. *
  31226. * s Signature value.
  31227. * r First signature value.
  31228. * k Ephemeral private key.
  31229. * x Private key as a number.
  31230. * e Hash of message as a number.
  31231. * tmp Temporary storage for intermediate numbers.
  31232. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  31233. */
  31234. static int sp_384_calc_s_7(sp_digit* s, const sp_digit* r, sp_digit* k,
  31235. sp_digit* x, const sp_digit* e, sp_digit* tmp)
  31236. {
  31237. int err;
  31238. sp_digit carry;
  31239. sp_int64 c;
  31240. sp_digit* kInv = k;
  31241. /* Conv k to Montgomery form (mod order) */
  31242. sp_384_mul_7(k, k, p384_norm_order);
  31243. err = sp_384_mod_7(k, k, p384_order);
  31244. if (err == MP_OKAY) {
  31245. sp_384_norm_7(k);
  31246. /* kInv = 1/k mod order */
  31247. sp_384_mont_inv_order_7(kInv, k, tmp);
  31248. sp_384_norm_7(kInv);
  31249. /* s = r * x + e */
  31250. sp_384_mul_7(x, x, r);
  31251. err = sp_384_mod_7(x, x, p384_order);
  31252. }
  31253. if (err == MP_OKAY) {
  31254. sp_384_norm_7(x);
  31255. carry = sp_384_add_7(s, e, x);
  31256. sp_384_cond_sub_7(s, s, p384_order, 0 - carry);
  31257. sp_384_norm_7(s);
  31258. c = sp_384_cmp_7(s, p384_order);
  31259. sp_384_cond_sub_7(s, s, p384_order,
  31260. (sp_digit)0 - (sp_digit)(c >= 0));
  31261. sp_384_norm_7(s);
  31262. /* s = s * k^-1 mod order */
  31263. sp_384_mont_mul_order_7(s, s, kInv);
  31264. sp_384_norm_7(s);
  31265. }
  31266. return err;
  31267. }
  31268. /* Sign the hash using the private key.
  31269. * e = [hash, 384 bits] from binary
  31270. * r = (k.G)->x mod order
  31271. * s = (r * x + e) / k mod order
  31272. * The hash is truncated to the first 384 bits.
  31273. *
  31274. * hash Hash to sign.
  31275. * hashLen Length of the hash data.
  31276. * rng Random number generator.
  31277. * priv Private part of key - scalar.
  31278. * rm First part of result as an mp_int.
  31279. * sm Sirst part of result as an mp_int.
  31280. * heap Heap to use for allocation.
  31281. * returns RNG failures, MEMORY_E when memory allocation fails and
  31282. * MP_OKAY on success.
  31283. */
  31284. int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng,
  31285. const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap)
  31286. {
  31287. #ifdef WOLFSSL_SP_SMALL_STACK
  31288. sp_digit* e = NULL;
  31289. sp_point_384* point = NULL;
  31290. #else
  31291. sp_digit e[7 * 2 * 7];
  31292. sp_point_384 point[1];
  31293. #endif
  31294. sp_digit* x = NULL;
  31295. sp_digit* k = NULL;
  31296. sp_digit* r = NULL;
  31297. sp_digit* tmp = NULL;
  31298. sp_digit* s = NULL;
  31299. sp_int64 c;
  31300. int err = MP_OKAY;
  31301. int i;
  31302. (void)heap;
  31303. #ifdef WOLFSSL_SP_SMALL_STACK
  31304. if (err == MP_OKAY) {
  31305. point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap,
  31306. DYNAMIC_TYPE_ECC);
  31307. if (point == NULL)
  31308. err = MEMORY_E;
  31309. }
  31310. if (err == MP_OKAY) {
  31311. e = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7 * 2 * 7, heap,
  31312. DYNAMIC_TYPE_ECC);
  31313. if (e == NULL)
  31314. err = MEMORY_E;
  31315. }
  31316. #endif
  31317. if (err == MP_OKAY) {
  31318. x = e + 2 * 7;
  31319. k = e + 4 * 7;
  31320. r = e + 6 * 7;
  31321. tmp = e + 8 * 7;
  31322. s = e;
  31323. if (hashLen > 48U) {
  31324. hashLen = 48U;
  31325. }
  31326. }
  31327. for (i = SP_ECC_MAX_SIG_GEN; err == MP_OKAY && i > 0; i--) {
  31328. /* New random point. */
  31329. if (km == NULL || mp_iszero(km)) {
  31330. err = sp_384_ecc_gen_k_7(rng, k);
  31331. }
  31332. else {
  31333. sp_384_from_mp(k, 7, km);
  31334. mp_zero(km);
  31335. }
  31336. if (err == MP_OKAY) {
  31337. err = sp_384_ecc_mulmod_base_7(point, k, 1, 1, heap);
  31338. }
  31339. if (err == MP_OKAY) {
  31340. /* r = point->x mod order */
  31341. XMEMCPY(r, point->x, sizeof(sp_digit) * 7U);
  31342. sp_384_norm_7(r);
  31343. c = sp_384_cmp_7(r, p384_order);
  31344. sp_384_cond_sub_7(r, r, p384_order,
  31345. (sp_digit)0 - (sp_digit)(c >= 0));
  31346. sp_384_norm_7(r);
  31347. if (!sp_384_iszero_7(r)) {
  31348. /* x is modified in calculation of s. */
  31349. sp_384_from_mp(x, 7, priv);
  31350. /* s ptr == e ptr, e is modified in calculation of s. */
  31351. sp_384_from_bin(e, 7, hash, (int)hashLen);
  31352. err = sp_384_calc_s_7(s, r, k, x, e, tmp);
  31353. /* Check that signature is usable. */
  31354. if ((err == MP_OKAY) && (!sp_384_iszero_7(s))) {
  31355. break;
  31356. }
  31357. }
  31358. }
  31359. #ifdef WOLFSSL_ECDSA_SET_K_ONE_LOOP
  31360. i = 1;
  31361. #endif
  31362. }
  31363. if (i == 0) {
  31364. err = RNG_FAILURE_E;
  31365. }
  31366. if (err == MP_OKAY) {
  31367. err = sp_384_to_mp(r, rm);
  31368. }
  31369. if (err == MP_OKAY) {
  31370. err = sp_384_to_mp(s, sm);
  31371. }
  31372. #ifdef WOLFSSL_SP_SMALL_STACK
  31373. if (e != NULL)
  31374. #endif
  31375. {
  31376. ForceZero(e, sizeof(sp_digit) * 7 * 2 * 7);
  31377. #ifdef WOLFSSL_SP_SMALL_STACK
  31378. XFREE(e, heap, DYNAMIC_TYPE_ECC);
  31379. #endif
  31380. }
  31381. #ifdef WOLFSSL_SP_SMALL_STACK
  31382. if (point != NULL)
  31383. #endif
  31384. {
  31385. ForceZero(point, sizeof(sp_point_384));
  31386. #ifdef WOLFSSL_SP_SMALL_STACK
  31387. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  31388. #endif
  31389. }
  31390. return err;
  31391. }
  31392. #ifdef WOLFSSL_SP_NONBLOCK
  31393. typedef struct sp_ecc_sign_384_ctx {
  31394. int state;
  31395. union {
  31396. sp_384_ecc_mulmod_7_ctx mulmod_ctx;
  31397. sp_384_mont_inv_order_7_ctx mont_inv_order_ctx;
  31398. };
  31399. sp_digit e[2*7];
  31400. sp_digit x[2*7];
  31401. sp_digit k[2*7];
  31402. sp_digit r[2*7];
  31403. sp_digit tmp[3 * 2*7];
  31404. sp_point_384 point;
  31405. sp_digit* s;
  31406. sp_digit* kInv;
  31407. int i;
  31408. } sp_ecc_sign_384_ctx;
  31409. int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, WC_RNG* rng,
  31410. mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap)
  31411. {
  31412. int err = FP_WOULDBLOCK;
  31413. sp_ecc_sign_384_ctx* ctx = (sp_ecc_sign_384_ctx*)sp_ctx->data;
  31414. typedef char ctx_size_test[sizeof(sp_ecc_sign_384_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  31415. (void)sizeof(ctx_size_test);
  31416. switch (ctx->state) {
  31417. case 0: /* INIT */
  31418. ctx->s = ctx->e;
  31419. ctx->kInv = ctx->k;
  31420. ctx->i = SP_ECC_MAX_SIG_GEN;
  31421. ctx->state = 1;
  31422. break;
  31423. case 1: /* GEN */
  31424. /* New random point. */
  31425. if (km == NULL || mp_iszero(km)) {
  31426. err = sp_384_ecc_gen_k_7(rng, ctx->k);
  31427. }
  31428. else {
  31429. sp_384_from_mp(ctx->k, 7, km);
  31430. mp_zero(km);
  31431. }
  31432. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  31433. ctx->state = 2;
  31434. break;
  31435. case 2: /* MULMOD */
  31436. err = sp_384_ecc_mulmod_7_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  31437. &ctx->point, &p384_base, ctx->k, 1, 1, heap);
  31438. if (err == MP_OKAY) {
  31439. ctx->state = 3;
  31440. }
  31441. break;
  31442. case 3: /* MODORDER */
  31443. {
  31444. sp_int64 c;
  31445. /* r = point->x mod order */
  31446. XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 7U);
  31447. sp_384_norm_7(ctx->r);
  31448. c = sp_384_cmp_7(ctx->r, p384_order);
  31449. sp_384_cond_sub_7(ctx->r, ctx->r, p384_order,
  31450. (sp_digit)0 - (sp_digit)(c >= 0));
  31451. sp_384_norm_7(ctx->r);
  31452. if (hashLen > 48U) {
  31453. hashLen = 48U;
  31454. }
  31455. sp_384_from_mp(ctx->x, 7, priv);
  31456. sp_384_from_bin(ctx->e, 7, hash, (int)hashLen);
  31457. ctx->state = 4;
  31458. break;
  31459. }
  31460. case 4: /* KMODORDER */
  31461. /* Conv k to Montgomery form (mod order) */
  31462. sp_384_mul_7(ctx->k, ctx->k, p384_norm_order);
  31463. err = sp_384_mod_7(ctx->k, ctx->k, p384_order);
  31464. if (err == MP_OKAY) {
  31465. sp_384_norm_7(ctx->k);
  31466. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  31467. ctx->state = 5;
  31468. }
  31469. break;
  31470. case 5: /* KINV */
  31471. /* kInv = 1/k mod order */
  31472. err = sp_384_mont_inv_order_7_nb((sp_ecc_ctx_t*)&ctx->mont_inv_order_ctx, ctx->kInv, ctx->k, ctx->tmp);
  31473. if (err == MP_OKAY) {
  31474. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  31475. ctx->state = 6;
  31476. }
  31477. break;
  31478. case 6: /* KINVNORM */
  31479. sp_384_norm_7(ctx->kInv);
  31480. ctx->state = 7;
  31481. break;
  31482. case 7: /* R */
  31483. /* s = r * x + e */
  31484. sp_384_mul_7(ctx->x, ctx->x, ctx->r);
  31485. ctx->state = 8;
  31486. break;
  31487. case 8: /* S1 */
  31488. err = sp_384_mod_7(ctx->x, ctx->x, p384_order);
  31489. if (err == MP_OKAY)
  31490. ctx->state = 9;
  31491. break;
  31492. case 9: /* S2 */
  31493. {
  31494. sp_digit carry;
  31495. sp_int64 c;
  31496. sp_384_norm_7(ctx->x);
  31497. carry = sp_384_add_7(ctx->s, ctx->e, ctx->x);
  31498. sp_384_cond_sub_7(ctx->s, ctx->s,
  31499. p384_order, 0 - carry);
  31500. sp_384_norm_7(ctx->s);
  31501. c = sp_384_cmp_7(ctx->s, p384_order);
  31502. sp_384_cond_sub_7(ctx->s, ctx->s, p384_order,
  31503. (sp_digit)0 - (sp_digit)(c >= 0));
  31504. sp_384_norm_7(ctx->s);
  31505. /* s = s * k^-1 mod order */
  31506. sp_384_mont_mul_order_7(ctx->s, ctx->s, ctx->kInv);
  31507. sp_384_norm_7(ctx->s);
  31508. /* Check that signature is usable. */
  31509. if (sp_384_iszero_7(ctx->s) == 0) {
  31510. ctx->state = 10;
  31511. break;
  31512. }
  31513. #ifdef WOLFSSL_ECDSA_SET_K_ONE_LOOP
  31514. ctx->i = 1;
  31515. #endif
  31516. /* not usable gen, try again */
  31517. ctx->i--;
  31518. if (ctx->i == 0) {
  31519. err = RNG_FAILURE_E;
  31520. }
  31521. ctx->state = 1;
  31522. break;
  31523. }
  31524. case 10: /* RES */
  31525. err = sp_384_to_mp(ctx->r, rm);
  31526. if (err == MP_OKAY) {
  31527. err = sp_384_to_mp(ctx->s, sm);
  31528. }
  31529. break;
  31530. }
  31531. if (err == MP_OKAY && ctx->state != 10) {
  31532. err = FP_WOULDBLOCK;
  31533. }
  31534. if (err != FP_WOULDBLOCK) {
  31535. XMEMSET(ctx->e, 0, sizeof(sp_digit) * 2U * 7U);
  31536. XMEMSET(ctx->x, 0, sizeof(sp_digit) * 2U * 7U);
  31537. XMEMSET(ctx->k, 0, sizeof(sp_digit) * 2U * 7U);
  31538. XMEMSET(ctx->r, 0, sizeof(sp_digit) * 2U * 7U);
  31539. XMEMSET(ctx->tmp, 0, sizeof(sp_digit) * 3U * 2U * 7U);
  31540. }
  31541. return err;
  31542. }
  31543. #endif /* WOLFSSL_SP_NONBLOCK */
  31544. #endif /* HAVE_ECC_SIGN */
  31545. #ifndef WOLFSSL_SP_SMALL
  31546. static const char sp_384_tab64_7[64] = {
  31547. 64, 1, 59, 2, 60, 48, 54, 3,
  31548. 61, 40, 49, 28, 55, 34, 43, 4,
  31549. 62, 52, 38, 41, 50, 19, 29, 21,
  31550. 56, 31, 35, 12, 44, 15, 23, 5,
  31551. 63, 58, 47, 53, 39, 27, 33, 42,
  31552. 51, 37, 18, 20, 30, 11, 14, 22,
  31553. 57, 46, 26, 32, 36, 17, 10, 13,
  31554. 45, 25, 16, 9, 24, 8, 7, 6};
  31555. static int sp_384_num_bits_55_7(sp_digit v)
  31556. {
  31557. v |= v >> 1;
  31558. v |= v >> 2;
  31559. v |= v >> 4;
  31560. v |= v >> 8;
  31561. v |= v >> 16;
  31562. v |= v >> 32;
  31563. return sp_384_tab64_7[((uint64_t)((v - (v >> 1))*0x07EDD5E59A4E28C2)) >> 58];
  31564. }
  31565. static int sp_384_num_bits_7(const sp_digit* a)
  31566. {
  31567. int i;
  31568. int r = 0;
  31569. for (i = 6; i >= 0; i--) {
  31570. if (a[i] != 0) {
  31571. r = sp_384_num_bits_55_7(a[i]);
  31572. r += i * 55;
  31573. break;
  31574. }
  31575. }
  31576. return r;
  31577. }
  31578. /* Non-constant time modular inversion.
  31579. *
  31580. * @param [out] r Resulting number.
  31581. * @param [in] a Number to invert.
  31582. * @param [in] m Modulus.
  31583. * @return MP_OKAY on success.
  31584. * @return MEMEORY_E when dynamic memory allocation fails.
  31585. */
  31586. static int sp_384_mod_inv_7(sp_digit* r, const sp_digit* a, const sp_digit* m)
  31587. {
  31588. int err = MP_OKAY;
  31589. #ifdef WOLFSSL_SP_SMALL_STACK
  31590. sp_digit* u = NULL;
  31591. #else
  31592. sp_digit u[7 * 4];
  31593. #endif
  31594. sp_digit* v = NULL;
  31595. sp_digit* b = NULL;
  31596. sp_digit* d = NULL;
  31597. int ut;
  31598. int vt;
  31599. #ifdef WOLFSSL_SP_SMALL_STACK
  31600. u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7 * 4, NULL,
  31601. DYNAMIC_TYPE_ECC);
  31602. if (u == NULL)
  31603. err = MEMORY_E;
  31604. #endif
  31605. if (err == MP_OKAY) {
  31606. v = u + 7;
  31607. b = u + 2 * 7;
  31608. d = u + 3 * 7;
  31609. XMEMCPY(u, m, sizeof(sp_digit) * 7);
  31610. XMEMCPY(v, a, sizeof(sp_digit) * 7);
  31611. ut = sp_384_num_bits_7(u);
  31612. vt = sp_384_num_bits_7(v);
  31613. XMEMSET(b, 0, sizeof(sp_digit) * 7);
  31614. if ((v[0] & 1) == 0) {
  31615. sp_384_rshift1_7(v, v);
  31616. XMEMCPY(d, m, sizeof(sp_digit) * 7);
  31617. d[0]++;
  31618. sp_384_rshift1_7(d, d);
  31619. vt--;
  31620. while ((v[0] & 1) == 0) {
  31621. sp_384_rshift1_7(v, v);
  31622. if (d[0] & 1)
  31623. sp_384_add_7(d, d, m);
  31624. sp_384_rshift1_7(d, d);
  31625. vt--;
  31626. }
  31627. }
  31628. else {
  31629. XMEMSET(d+1, 0, sizeof(sp_digit) * (7 - 1));
  31630. d[0] = 1;
  31631. }
  31632. while (ut > 1 && vt > 1) {
  31633. if ((ut > vt) || ((ut == vt) &&
  31634. (sp_384_cmp_7(u, v) >= 0))) {
  31635. sp_384_sub_7(u, u, v);
  31636. sp_384_norm_7(u);
  31637. sp_384_sub_7(b, b, d);
  31638. sp_384_norm_7(b);
  31639. if (b[6] < 0)
  31640. sp_384_add_7(b, b, m);
  31641. sp_384_norm_7(b);
  31642. ut = sp_384_num_bits_7(u);
  31643. do {
  31644. sp_384_rshift1_7(u, u);
  31645. if (b[0] & 1)
  31646. sp_384_add_7(b, b, m);
  31647. sp_384_rshift1_7(b, b);
  31648. ut--;
  31649. }
  31650. while (ut > 0 && (u[0] & 1) == 0);
  31651. }
  31652. else {
  31653. sp_384_sub_7(v, v, u);
  31654. sp_384_norm_7(v);
  31655. sp_384_sub_7(d, d, b);
  31656. sp_384_norm_7(d);
  31657. if (d[6] < 0)
  31658. sp_384_add_7(d, d, m);
  31659. sp_384_norm_7(d);
  31660. vt = sp_384_num_bits_7(v);
  31661. do {
  31662. sp_384_rshift1_7(v, v);
  31663. if (d[0] & 1)
  31664. sp_384_add_7(d, d, m);
  31665. sp_384_rshift1_7(d, d);
  31666. vt--;
  31667. }
  31668. while (vt > 0 && (v[0] & 1) == 0);
  31669. }
  31670. }
  31671. if (ut == 1)
  31672. XMEMCPY(r, b, sizeof(sp_digit) * 7);
  31673. else
  31674. XMEMCPY(r, d, sizeof(sp_digit) * 7);
  31675. }
  31676. #ifdef WOLFSSL_SP_SMALL_STACK
  31677. if (u != NULL)
  31678. XFREE(u, NULL, DYNAMIC_TYPE_ECC);
  31679. #endif
  31680. return err;
  31681. }
  31682. #endif /* WOLFSSL_SP_SMALL */
  31683. /* Add point p1 into point p2. Handles p1 == p2 and result at infinity.
  31684. *
  31685. * p1 First point to add and holds result.
  31686. * p2 Second point to add.
  31687. * tmp Temporary storage for intermediate numbers.
  31688. */
  31689. static void sp_384_add_points_7(sp_point_384* p1, const sp_point_384* p2,
  31690. sp_digit* tmp)
  31691. {
  31692. sp_384_proj_point_add_7(p1, p1, p2, tmp);
  31693. if (sp_384_iszero_7(p1->z)) {
  31694. if (sp_384_iszero_7(p1->x) && sp_384_iszero_7(p1->y)) {
  31695. sp_384_proj_point_dbl_7(p1, p2, tmp);
  31696. }
  31697. else {
  31698. /* Y ordinate is not used from here - don't set. */
  31699. p1->x[0] = 0;
  31700. p1->x[1] = 0;
  31701. p1->x[2] = 0;
  31702. p1->x[3] = 0;
  31703. p1->x[4] = 0;
  31704. p1->x[5] = 0;
  31705. p1->x[6] = 0;
  31706. XMEMCPY(p1->z, p384_norm_mod, sizeof(p384_norm_mod));
  31707. }
  31708. }
  31709. }
  31710. /* Calculate the verification point: [e/s]G + [r/s]Q
  31711. *
  31712. * p1 Calculated point.
  31713. * p2 Public point and temporary.
  31714. * s Second part of signature as a number.
  31715. * u1 Temporary number.
  31716. * u2 Temporary number.
  31717. * heap Heap to use for allocation.
  31718. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  31719. */
  31720. static int sp_384_calc_vfy_point_7(sp_point_384* p1, sp_point_384* p2,
  31721. sp_digit* s, sp_digit* u1, sp_digit* u2, sp_digit* tmp, void* heap)
  31722. {
  31723. int err;
  31724. #ifndef WOLFSSL_SP_SMALL
  31725. err = sp_384_mod_inv_7(s, s, p384_order);
  31726. if (err == MP_OKAY)
  31727. #endif /* !WOLFSSL_SP_SMALL */
  31728. {
  31729. sp_384_mul_7(s, s, p384_norm_order);
  31730. err = sp_384_mod_7(s, s, p384_order);
  31731. }
  31732. if (err == MP_OKAY) {
  31733. sp_384_norm_7(s);
  31734. #ifdef WOLFSSL_SP_SMALL
  31735. {
  31736. sp_384_mont_inv_order_7(s, s, tmp);
  31737. sp_384_mont_mul_order_7(u1, u1, s);
  31738. sp_384_mont_mul_order_7(u2, u2, s);
  31739. }
  31740. #else
  31741. {
  31742. sp_384_mont_mul_order_7(u1, u1, s);
  31743. sp_384_mont_mul_order_7(u2, u2, s);
  31744. }
  31745. #endif /* WOLFSSL_SP_SMALL */
  31746. {
  31747. err = sp_384_ecc_mulmod_base_7(p1, u1, 0, 0, heap);
  31748. }
  31749. }
  31750. if ((err == MP_OKAY) && sp_384_iszero_7(p1->z)) {
  31751. p1->infinity = 1;
  31752. }
  31753. if (err == MP_OKAY) {
  31754. err = sp_384_ecc_mulmod_7(p2, p2, u2, 0, 0, heap);
  31755. }
  31756. if ((err == MP_OKAY) && sp_384_iszero_7(p2->z)) {
  31757. p2->infinity = 1;
  31758. }
  31759. if (err == MP_OKAY) {
  31760. sp_384_add_points_7(p1, p2, tmp);
  31761. }
  31762. return err;
  31763. }
  31764. #ifdef HAVE_ECC_VERIFY
  31765. /* Verify the signature values with the hash and public key.
  31766. * e = Truncate(hash, 384)
  31767. * u1 = e/s mod order
  31768. * u2 = r/s mod order
  31769. * r == (u1.G + u2.Q)->x mod order
  31770. * Optimization: Leave point in projective form.
  31771. * (x, y, 1) == (x' / z'*z', y' / z'*z'*z', z' / z')
  31772. * (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x'
  31773. * The hash is truncated to the first 384 bits.
  31774. *
  31775. * hash Hash to sign.
  31776. * hashLen Length of the hash data.
  31777. * rng Random number generator.
  31778. * priv Private part of key - scalar.
  31779. * rm First part of result as an mp_int.
  31780. * sm Sirst part of result as an mp_int.
  31781. * heap Heap to use for allocation.
  31782. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  31783. */
  31784. int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX,
  31785. const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm,
  31786. int* res, void* heap)
  31787. {
  31788. #ifdef WOLFSSL_SP_SMALL_STACK
  31789. sp_digit* u1 = NULL;
  31790. sp_point_384* p1 = NULL;
  31791. #else
  31792. sp_digit u1[18 * 7];
  31793. sp_point_384 p1[2];
  31794. #endif
  31795. sp_digit* u2 = NULL;
  31796. sp_digit* s = NULL;
  31797. sp_digit* tmp = NULL;
  31798. sp_point_384* p2 = NULL;
  31799. sp_digit carry;
  31800. sp_int64 c = 0;
  31801. int err = MP_OKAY;
  31802. #ifdef WOLFSSL_SP_SMALL_STACK
  31803. if (err == MP_OKAY) {
  31804. p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap,
  31805. DYNAMIC_TYPE_ECC);
  31806. if (p1 == NULL)
  31807. err = MEMORY_E;
  31808. }
  31809. if (err == MP_OKAY) {
  31810. u1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 7, heap,
  31811. DYNAMIC_TYPE_ECC);
  31812. if (u1 == NULL)
  31813. err = MEMORY_E;
  31814. }
  31815. #endif
  31816. if (err == MP_OKAY) {
  31817. u2 = u1 + 2 * 7;
  31818. s = u1 + 4 * 7;
  31819. tmp = u1 + 6 * 7;
  31820. p2 = p1 + 1;
  31821. if (hashLen > 48U) {
  31822. hashLen = 48U;
  31823. }
  31824. sp_384_from_bin(u1, 7, hash, (int)hashLen);
  31825. sp_384_from_mp(u2, 7, rm);
  31826. sp_384_from_mp(s, 7, sm);
  31827. sp_384_from_mp(p2->x, 7, pX);
  31828. sp_384_from_mp(p2->y, 7, pY);
  31829. sp_384_from_mp(p2->z, 7, pZ);
  31830. err = sp_384_calc_vfy_point_7(p1, p2, s, u1, u2, tmp, heap);
  31831. }
  31832. if (err == MP_OKAY) {
  31833. /* (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x' */
  31834. /* Reload r and convert to Montgomery form. */
  31835. sp_384_from_mp(u2, 7, rm);
  31836. err = sp_384_mod_mul_norm_7(u2, u2, p384_mod);
  31837. }
  31838. if (err == MP_OKAY) {
  31839. /* u1 = r.z'.z' mod prime */
  31840. sp_384_mont_sqr_7(p1->z, p1->z, p384_mod, p384_mp_mod);
  31841. sp_384_mont_mul_7(u1, u2, p1->z, p384_mod, p384_mp_mod);
  31842. *res = (int)(sp_384_cmp_7(p1->x, u1) == 0);
  31843. if (*res == 0) {
  31844. /* Reload r and add order. */
  31845. sp_384_from_mp(u2, 7, rm);
  31846. carry = sp_384_add_7(u2, u2, p384_order);
  31847. /* Carry means result is greater than mod and is not valid. */
  31848. if (carry == 0) {
  31849. sp_384_norm_7(u2);
  31850. /* Compare with mod and if greater or equal then not valid. */
  31851. c = sp_384_cmp_7(u2, p384_mod);
  31852. }
  31853. }
  31854. if ((*res == 0) && (c < 0)) {
  31855. /* Convert to Montogomery form */
  31856. err = sp_384_mod_mul_norm_7(u2, u2, p384_mod);
  31857. if (err == MP_OKAY) {
  31858. /* u1 = (r + 1*order).z'.z' mod prime */
  31859. {
  31860. sp_384_mont_mul_7(u1, u2, p1->z, p384_mod, p384_mp_mod);
  31861. }
  31862. *res = (sp_384_cmp_7(p1->x, u1) == 0);
  31863. }
  31864. }
  31865. }
  31866. #ifdef WOLFSSL_SP_SMALL_STACK
  31867. if (u1 != NULL)
  31868. XFREE(u1, heap, DYNAMIC_TYPE_ECC);
  31869. if (p1 != NULL)
  31870. XFREE(p1, heap, DYNAMIC_TYPE_ECC);
  31871. #endif
  31872. return err;
  31873. }
  31874. #ifdef WOLFSSL_SP_NONBLOCK
  31875. typedef struct sp_ecc_verify_384_ctx {
  31876. int state;
  31877. union {
  31878. sp_384_ecc_mulmod_7_ctx mulmod_ctx;
  31879. sp_384_mont_inv_order_7_ctx mont_inv_order_ctx;
  31880. sp_384_proj_point_dbl_7_ctx dbl_ctx;
  31881. sp_384_proj_point_add_7_ctx add_ctx;
  31882. };
  31883. sp_digit u1[2*7];
  31884. sp_digit u2[2*7];
  31885. sp_digit s[2*7];
  31886. sp_digit tmp[2*7 * 6];
  31887. sp_point_384 p1;
  31888. sp_point_384 p2;
  31889. } sp_ecc_verify_384_ctx;
  31890. int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash,
  31891. word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ,
  31892. const mp_int* rm, const mp_int* sm, int* res, void* heap)
  31893. {
  31894. int err = FP_WOULDBLOCK;
  31895. sp_ecc_verify_384_ctx* ctx = (sp_ecc_verify_384_ctx*)sp_ctx->data;
  31896. typedef char ctx_size_test[sizeof(sp_ecc_verify_384_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  31897. (void)sizeof(ctx_size_test);
  31898. switch (ctx->state) {
  31899. case 0: /* INIT */
  31900. if (hashLen > 48U) {
  31901. hashLen = 48U;
  31902. }
  31903. sp_384_from_bin(ctx->u1, 7, hash, (int)hashLen);
  31904. sp_384_from_mp(ctx->u2, 7, rm);
  31905. sp_384_from_mp(ctx->s, 7, sm);
  31906. sp_384_from_mp(ctx->p2.x, 7, pX);
  31907. sp_384_from_mp(ctx->p2.y, 7, pY);
  31908. sp_384_from_mp(ctx->p2.z, 7, pZ);
  31909. ctx->state = 1;
  31910. break;
  31911. case 1: /* NORMS0 */
  31912. sp_384_mul_7(ctx->s, ctx->s, p384_norm_order);
  31913. err = sp_384_mod_7(ctx->s, ctx->s, p384_order);
  31914. if (err == MP_OKAY)
  31915. ctx->state = 2;
  31916. break;
  31917. case 2: /* NORMS1 */
  31918. sp_384_norm_7(ctx->s);
  31919. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  31920. ctx->state = 3;
  31921. break;
  31922. case 3: /* NORMS2 */
  31923. err = sp_384_mont_inv_order_7_nb((sp_ecc_ctx_t*)&ctx->mont_inv_order_ctx, ctx->s, ctx->s, ctx->tmp);
  31924. if (err == MP_OKAY) {
  31925. ctx->state = 4;
  31926. }
  31927. break;
  31928. case 4: /* NORMS3 */
  31929. sp_384_mont_mul_order_7(ctx->u1, ctx->u1, ctx->s);
  31930. ctx->state = 5;
  31931. break;
  31932. case 5: /* NORMS4 */
  31933. sp_384_mont_mul_order_7(ctx->u2, ctx->u2, ctx->s);
  31934. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  31935. ctx->state = 6;
  31936. break;
  31937. case 6: /* MULBASE */
  31938. err = sp_384_ecc_mulmod_7_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx, &ctx->p1, &p384_base, ctx->u1, 0, 0, heap);
  31939. if (err == MP_OKAY) {
  31940. if (sp_384_iszero_7(ctx->p1.z)) {
  31941. ctx->p1.infinity = 1;
  31942. }
  31943. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  31944. ctx->state = 7;
  31945. }
  31946. break;
  31947. case 7: /* MULMOD */
  31948. err = sp_384_ecc_mulmod_7_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx, &ctx->p2, &ctx->p2, ctx->u2, 0, 0, heap);
  31949. if (err == MP_OKAY) {
  31950. if (sp_384_iszero_7(ctx->p2.z)) {
  31951. ctx->p2.infinity = 1;
  31952. }
  31953. XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx));
  31954. ctx->state = 8;
  31955. }
  31956. break;
  31957. case 8: /* ADD */
  31958. err = sp_384_proj_point_add_7_nb((sp_ecc_ctx_t*)&ctx->add_ctx, &ctx->p1, &ctx->p1, &ctx->p2, ctx->tmp);
  31959. if (err == MP_OKAY)
  31960. ctx->state = 9;
  31961. break;
  31962. case 9: /* MONT */
  31963. /* (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x' */
  31964. /* Reload r and convert to Montgomery form. */
  31965. sp_384_from_mp(ctx->u2, 7, rm);
  31966. err = sp_384_mod_mul_norm_7(ctx->u2, ctx->u2, p384_mod);
  31967. if (err == MP_OKAY)
  31968. ctx->state = 10;
  31969. break;
  31970. case 10: /* SQR */
  31971. /* u1 = r.z'.z' mod prime */
  31972. sp_384_mont_sqr_7(ctx->p1.z, ctx->p1.z, p384_mod, p384_mp_mod);
  31973. ctx->state = 11;
  31974. break;
  31975. case 11: /* MUL */
  31976. sp_384_mont_mul_7(ctx->u1, ctx->u2, ctx->p1.z, p384_mod, p384_mp_mod);
  31977. ctx->state = 12;
  31978. break;
  31979. case 12: /* RES */
  31980. {
  31981. sp_int64 c = 0;
  31982. err = MP_OKAY; /* math okay, now check result */
  31983. *res = (int)(sp_384_cmp_7(ctx->p1.x, ctx->u1) == 0);
  31984. if (*res == 0) {
  31985. sp_digit carry;
  31986. /* Reload r and add order. */
  31987. sp_384_from_mp(ctx->u2, 7, rm);
  31988. carry = sp_384_add_7(ctx->u2, ctx->u2, p384_order);
  31989. /* Carry means result is greater than mod and is not valid. */
  31990. if (carry == 0) {
  31991. sp_384_norm_7(ctx->u2);
  31992. /* Compare with mod and if greater or equal then not valid. */
  31993. c = sp_384_cmp_7(ctx->u2, p384_mod);
  31994. }
  31995. }
  31996. if ((*res == 0) && (c < 0)) {
  31997. /* Convert to Montogomery form */
  31998. err = sp_384_mod_mul_norm_7(ctx->u2, ctx->u2, p384_mod);
  31999. if (err == MP_OKAY) {
  32000. /* u1 = (r + 1*order).z'.z' mod prime */
  32001. sp_384_mont_mul_7(ctx->u1, ctx->u2, ctx->p1.z, p384_mod,
  32002. p384_mp_mod);
  32003. *res = (int)(sp_384_cmp_7(ctx->p1.x, ctx->u1) == 0);
  32004. }
  32005. }
  32006. break;
  32007. }
  32008. } /* switch */
  32009. if (err == MP_OKAY && ctx->state != 12) {
  32010. err = FP_WOULDBLOCK;
  32011. }
  32012. return err;
  32013. }
  32014. #endif /* WOLFSSL_SP_NONBLOCK */
  32015. #endif /* HAVE_ECC_VERIFY */
  32016. #ifdef HAVE_ECC_CHECK_KEY
  32017. /* Check that the x and y oridinates are a valid point on the curve.
  32018. *
  32019. * point EC point.
  32020. * heap Heap to use if dynamically allocating.
  32021. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  32022. * not on the curve and MP_OKAY otherwise.
  32023. */
  32024. static int sp_384_ecc_is_point_7(const sp_point_384* point,
  32025. void* heap)
  32026. {
  32027. #ifdef WOLFSSL_SP_SMALL_STACK
  32028. sp_digit* t1 = NULL;
  32029. #else
  32030. sp_digit t1[7 * 4];
  32031. #endif
  32032. sp_digit* t2 = NULL;
  32033. int err = MP_OKAY;
  32034. #ifdef WOLFSSL_SP_SMALL_STACK
  32035. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7 * 4, heap, DYNAMIC_TYPE_ECC);
  32036. if (t1 == NULL)
  32037. err = MEMORY_E;
  32038. #endif
  32039. (void)heap;
  32040. if (err == MP_OKAY) {
  32041. t2 = t1 + 2 * 7;
  32042. /* y^2 - x^3 - a.x = b */
  32043. sp_384_sqr_7(t1, point->y);
  32044. (void)sp_384_mod_7(t1, t1, p384_mod);
  32045. sp_384_sqr_7(t2, point->x);
  32046. (void)sp_384_mod_7(t2, t2, p384_mod);
  32047. sp_384_mul_7(t2, t2, point->x);
  32048. (void)sp_384_mod_7(t2, t2, p384_mod);
  32049. sp_384_mont_sub_7(t1, t1, t2, p384_mod);
  32050. /* y^2 - x^3 + 3.x = b, when a = -3 */
  32051. sp_384_mont_add_7(t1, t1, point->x, p384_mod);
  32052. sp_384_mont_add_7(t1, t1, point->x, p384_mod);
  32053. sp_384_mont_add_7(t1, t1, point->x, p384_mod);
  32054. if (sp_384_cmp_7(t1, p384_b) != 0) {
  32055. err = MP_VAL;
  32056. }
  32057. }
  32058. #ifdef WOLFSSL_SP_SMALL_STACK
  32059. if (t1 != NULL)
  32060. XFREE(t1, heap, DYNAMIC_TYPE_ECC);
  32061. #endif
  32062. return err;
  32063. }
  32064. /* Check that the x and y oridinates are a valid point on the curve.
  32065. *
  32066. * pX X ordinate of EC point.
  32067. * pY Y ordinate of EC point.
  32068. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  32069. * not on the curve and MP_OKAY otherwise.
  32070. */
  32071. int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY)
  32072. {
  32073. #ifdef WOLFSSL_SP_SMALL_STACK
  32074. sp_point_384* pub = NULL;
  32075. #else
  32076. sp_point_384 pub[1];
  32077. #endif
  32078. const byte one[1] = { 1 };
  32079. int err = MP_OKAY;
  32080. #ifdef WOLFSSL_SP_SMALL_STACK
  32081. pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL,
  32082. DYNAMIC_TYPE_ECC);
  32083. if (pub == NULL)
  32084. err = MEMORY_E;
  32085. #endif
  32086. if (err == MP_OKAY) {
  32087. sp_384_from_mp(pub->x, 7, pX);
  32088. sp_384_from_mp(pub->y, 7, pY);
  32089. sp_384_from_bin(pub->z, 7, one, (int)sizeof(one));
  32090. err = sp_384_ecc_is_point_7(pub, NULL);
  32091. }
  32092. #ifdef WOLFSSL_SP_SMALL_STACK
  32093. if (pub != NULL)
  32094. XFREE(pub, NULL, DYNAMIC_TYPE_ECC);
  32095. #endif
  32096. return err;
  32097. }
  32098. /* Check that the private scalar generates the EC point (px, py), the point is
  32099. * on the curve and the point has the correct order.
  32100. *
  32101. * pX X ordinate of EC point.
  32102. * pY Y ordinate of EC point.
  32103. * privm Private scalar that generates EC point.
  32104. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  32105. * not on the curve, ECC_INF_E if the point does not have the correct order,
  32106. * ECC_PRIV_KEY_E when the private scalar doesn't generate the EC point and
  32107. * MP_OKAY otherwise.
  32108. */
  32109. int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY,
  32110. const mp_int* privm, void* heap)
  32111. {
  32112. #ifdef WOLFSSL_SP_SMALL_STACK
  32113. sp_digit* priv = NULL;
  32114. sp_point_384* pub = NULL;
  32115. #else
  32116. sp_digit priv[7];
  32117. sp_point_384 pub[2];
  32118. #endif
  32119. sp_point_384* p = NULL;
  32120. const byte one[1] = { 1 };
  32121. int err = MP_OKAY;
  32122. /* Quick check the lengs of public key ordinates and private key are in
  32123. * range. Proper check later.
  32124. */
  32125. if (((mp_count_bits(pX) > 384) ||
  32126. (mp_count_bits(pY) > 384) ||
  32127. ((privm != NULL) && (mp_count_bits(privm) > 384)))) {
  32128. err = ECC_OUT_OF_RANGE_E;
  32129. }
  32130. #ifdef WOLFSSL_SP_SMALL_STACK
  32131. if (err == MP_OKAY) {
  32132. pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap,
  32133. DYNAMIC_TYPE_ECC);
  32134. if (pub == NULL)
  32135. err = MEMORY_E;
  32136. }
  32137. if (err == MP_OKAY && privm) {
  32138. priv = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7, heap,
  32139. DYNAMIC_TYPE_ECC);
  32140. if (priv == NULL)
  32141. err = MEMORY_E;
  32142. }
  32143. #endif
  32144. if (err == MP_OKAY) {
  32145. p = pub + 1;
  32146. sp_384_from_mp(pub->x, 7, pX);
  32147. sp_384_from_mp(pub->y, 7, pY);
  32148. sp_384_from_bin(pub->z, 7, one, (int)sizeof(one));
  32149. if (privm)
  32150. sp_384_from_mp(priv, 7, privm);
  32151. /* Check point at infinitiy. */
  32152. if ((sp_384_iszero_7(pub->x) != 0) &&
  32153. (sp_384_iszero_7(pub->y) != 0)) {
  32154. err = ECC_INF_E;
  32155. }
  32156. }
  32157. /* Check range of X and Y */
  32158. if ((err == MP_OKAY) &&
  32159. ((sp_384_cmp_7(pub->x, p384_mod) >= 0) ||
  32160. (sp_384_cmp_7(pub->y, p384_mod) >= 0))) {
  32161. err = ECC_OUT_OF_RANGE_E;
  32162. }
  32163. if (err == MP_OKAY) {
  32164. /* Check point is on curve */
  32165. err = sp_384_ecc_is_point_7(pub, heap);
  32166. }
  32167. if (err == MP_OKAY) {
  32168. /* Point * order = infinity */
  32169. err = sp_384_ecc_mulmod_7(p, pub, p384_order, 1, 1, heap);
  32170. }
  32171. /* Check result is infinity */
  32172. if ((err == MP_OKAY) && ((sp_384_iszero_7(p->x) == 0) ||
  32173. (sp_384_iszero_7(p->y) == 0))) {
  32174. err = ECC_INF_E;
  32175. }
  32176. if (privm) {
  32177. if (err == MP_OKAY) {
  32178. /* Base * private = point */
  32179. err = sp_384_ecc_mulmod_base_7(p, priv, 1, 1, heap);
  32180. }
  32181. /* Check result is public key */
  32182. if ((err == MP_OKAY) &&
  32183. ((sp_384_cmp_7(p->x, pub->x) != 0) ||
  32184. (sp_384_cmp_7(p->y, pub->y) != 0))) {
  32185. err = ECC_PRIV_KEY_E;
  32186. }
  32187. }
  32188. #ifdef WOLFSSL_SP_SMALL_STACK
  32189. if (pub != NULL)
  32190. XFREE(pub, heap, DYNAMIC_TYPE_ECC);
  32191. if (priv != NULL)
  32192. XFREE(priv, heap, DYNAMIC_TYPE_ECC);
  32193. #endif
  32194. return err;
  32195. }
  32196. #endif
  32197. #ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL
  32198. /* Add two projective EC points together.
  32199. * (pX, pY, pZ) + (qX, qY, qZ) = (rX, rY, rZ)
  32200. *
  32201. * pX First EC point's X ordinate.
  32202. * pY First EC point's Y ordinate.
  32203. * pZ First EC point's Z ordinate.
  32204. * qX Second EC point's X ordinate.
  32205. * qY Second EC point's Y ordinate.
  32206. * qZ Second EC point's Z ordinate.
  32207. * rX Resultant EC point's X ordinate.
  32208. * rY Resultant EC point's Y ordinate.
  32209. * rZ Resultant EC point's Z ordinate.
  32210. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  32211. */
  32212. int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ,
  32213. mp_int* qX, mp_int* qY, mp_int* qZ,
  32214. mp_int* rX, mp_int* rY, mp_int* rZ)
  32215. {
  32216. #ifdef WOLFSSL_SP_SMALL_STACK
  32217. sp_digit* tmp = NULL;
  32218. sp_point_384* p = NULL;
  32219. #else
  32220. sp_digit tmp[2 * 7 * 6];
  32221. sp_point_384 p[2];
  32222. #endif
  32223. sp_point_384* q = NULL;
  32224. int err = MP_OKAY;
  32225. #ifdef WOLFSSL_SP_SMALL_STACK
  32226. if (err == MP_OKAY) {
  32227. p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL,
  32228. DYNAMIC_TYPE_ECC);
  32229. if (p == NULL)
  32230. err = MEMORY_E;
  32231. }
  32232. if (err == MP_OKAY) {
  32233. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 6, NULL,
  32234. DYNAMIC_TYPE_ECC);
  32235. if (tmp == NULL) {
  32236. err = MEMORY_E;
  32237. }
  32238. }
  32239. #endif
  32240. if (err == MP_OKAY) {
  32241. q = p + 1;
  32242. sp_384_from_mp(p->x, 7, pX);
  32243. sp_384_from_mp(p->y, 7, pY);
  32244. sp_384_from_mp(p->z, 7, pZ);
  32245. sp_384_from_mp(q->x, 7, qX);
  32246. sp_384_from_mp(q->y, 7, qY);
  32247. sp_384_from_mp(q->z, 7, qZ);
  32248. p->infinity = sp_384_iszero_7(p->x) &
  32249. sp_384_iszero_7(p->y);
  32250. q->infinity = sp_384_iszero_7(q->x) &
  32251. sp_384_iszero_7(q->y);
  32252. sp_384_proj_point_add_7(p, p, q, tmp);
  32253. }
  32254. if (err == MP_OKAY) {
  32255. err = sp_384_to_mp(p->x, rX);
  32256. }
  32257. if (err == MP_OKAY) {
  32258. err = sp_384_to_mp(p->y, rY);
  32259. }
  32260. if (err == MP_OKAY) {
  32261. err = sp_384_to_mp(p->z, rZ);
  32262. }
  32263. #ifdef WOLFSSL_SP_SMALL_STACK
  32264. if (tmp != NULL)
  32265. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  32266. if (p != NULL)
  32267. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  32268. #endif
  32269. return err;
  32270. }
  32271. /* Double a projective EC point.
  32272. * (pX, pY, pZ) + (pX, pY, pZ) = (rX, rY, rZ)
  32273. *
  32274. * pX EC point's X ordinate.
  32275. * pY EC point's Y ordinate.
  32276. * pZ EC point's Z ordinate.
  32277. * rX Resultant EC point's X ordinate.
  32278. * rY Resultant EC point's Y ordinate.
  32279. * rZ Resultant EC point's Z ordinate.
  32280. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  32281. */
  32282. int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ,
  32283. mp_int* rX, mp_int* rY, mp_int* rZ)
  32284. {
  32285. #ifdef WOLFSSL_SP_SMALL_STACK
  32286. sp_digit* tmp = NULL;
  32287. sp_point_384* p = NULL;
  32288. #else
  32289. sp_digit tmp[2 * 7 * 2];
  32290. sp_point_384 p[1];
  32291. #endif
  32292. int err = MP_OKAY;
  32293. #ifdef WOLFSSL_SP_SMALL_STACK
  32294. if (err == MP_OKAY) {
  32295. p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL,
  32296. DYNAMIC_TYPE_ECC);
  32297. if (p == NULL)
  32298. err = MEMORY_E;
  32299. }
  32300. if (err == MP_OKAY) {
  32301. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 2, NULL,
  32302. DYNAMIC_TYPE_ECC);
  32303. if (tmp == NULL)
  32304. err = MEMORY_E;
  32305. }
  32306. #endif
  32307. if (err == MP_OKAY) {
  32308. sp_384_from_mp(p->x, 7, pX);
  32309. sp_384_from_mp(p->y, 7, pY);
  32310. sp_384_from_mp(p->z, 7, pZ);
  32311. p->infinity = sp_384_iszero_7(p->x) &
  32312. sp_384_iszero_7(p->y);
  32313. sp_384_proj_point_dbl_7(p, p, tmp);
  32314. }
  32315. if (err == MP_OKAY) {
  32316. err = sp_384_to_mp(p->x, rX);
  32317. }
  32318. if (err == MP_OKAY) {
  32319. err = sp_384_to_mp(p->y, rY);
  32320. }
  32321. if (err == MP_OKAY) {
  32322. err = sp_384_to_mp(p->z, rZ);
  32323. }
  32324. #ifdef WOLFSSL_SP_SMALL_STACK
  32325. if (tmp != NULL)
  32326. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  32327. if (p != NULL)
  32328. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  32329. #endif
  32330. return err;
  32331. }
  32332. /* Map a projective EC point to affine in place.
  32333. * pZ will be one.
  32334. *
  32335. * pX EC point's X ordinate.
  32336. * pY EC point's Y ordinate.
  32337. * pZ EC point's Z ordinate.
  32338. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  32339. */
  32340. int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ)
  32341. {
  32342. #ifdef WOLFSSL_SP_SMALL_STACK
  32343. sp_digit* tmp = NULL;
  32344. sp_point_384* p = NULL;
  32345. #else
  32346. sp_digit tmp[2 * 7 * 6];
  32347. sp_point_384 p[1];
  32348. #endif
  32349. int err = MP_OKAY;
  32350. #ifdef WOLFSSL_SP_SMALL_STACK
  32351. if (err == MP_OKAY) {
  32352. p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL,
  32353. DYNAMIC_TYPE_ECC);
  32354. if (p == NULL)
  32355. err = MEMORY_E;
  32356. }
  32357. if (err == MP_OKAY) {
  32358. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 6, NULL,
  32359. DYNAMIC_TYPE_ECC);
  32360. if (tmp == NULL)
  32361. err = MEMORY_E;
  32362. }
  32363. #endif
  32364. if (err == MP_OKAY) {
  32365. sp_384_from_mp(p->x, 7, pX);
  32366. sp_384_from_mp(p->y, 7, pY);
  32367. sp_384_from_mp(p->z, 7, pZ);
  32368. p->infinity = sp_384_iszero_7(p->x) &
  32369. sp_384_iszero_7(p->y);
  32370. sp_384_map_7(p, p, tmp);
  32371. }
  32372. if (err == MP_OKAY) {
  32373. err = sp_384_to_mp(p->x, pX);
  32374. }
  32375. if (err == MP_OKAY) {
  32376. err = sp_384_to_mp(p->y, pY);
  32377. }
  32378. if (err == MP_OKAY) {
  32379. err = sp_384_to_mp(p->z, pZ);
  32380. }
  32381. #ifdef WOLFSSL_SP_SMALL_STACK
  32382. if (tmp != NULL)
  32383. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  32384. if (p != NULL)
  32385. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  32386. #endif
  32387. return err;
  32388. }
  32389. #endif /* WOLFSSL_PUBLIC_ECC_ADD_DBL */
  32390. #ifdef HAVE_COMP_KEY
  32391. /* Find the square root of a number mod the prime of the curve.
  32392. *
  32393. * y The number to operate on and the result.
  32394. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  32395. */
  32396. static int sp_384_mont_sqrt_7(sp_digit* y)
  32397. {
  32398. #ifdef WOLFSSL_SP_SMALL_STACK
  32399. sp_digit* t1 = NULL;
  32400. #else
  32401. sp_digit t1[5 * 2 * 7];
  32402. #endif
  32403. sp_digit* t2 = NULL;
  32404. sp_digit* t3 = NULL;
  32405. sp_digit* t4 = NULL;
  32406. sp_digit* t5 = NULL;
  32407. int err = MP_OKAY;
  32408. #ifdef WOLFSSL_SP_SMALL_STACK
  32409. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 7, NULL, DYNAMIC_TYPE_ECC);
  32410. if (t1 == NULL)
  32411. err = MEMORY_E;
  32412. #endif
  32413. if (err == MP_OKAY) {
  32414. t2 = t1 + 2 * 7;
  32415. t3 = t1 + 4 * 7;
  32416. t4 = t1 + 6 * 7;
  32417. t5 = t1 + 8 * 7;
  32418. {
  32419. /* t2 = y ^ 0x2 */
  32420. sp_384_mont_sqr_7(t2, y, p384_mod, p384_mp_mod);
  32421. /* t1 = y ^ 0x3 */
  32422. sp_384_mont_mul_7(t1, t2, y, p384_mod, p384_mp_mod);
  32423. /* t5 = y ^ 0xc */
  32424. sp_384_mont_sqr_n_7(t5, t1, 2, p384_mod, p384_mp_mod);
  32425. /* t1 = y ^ 0xf */
  32426. sp_384_mont_mul_7(t1, t1, t5, p384_mod, p384_mp_mod);
  32427. /* t2 = y ^ 0x1e */
  32428. sp_384_mont_sqr_7(t2, t1, p384_mod, p384_mp_mod);
  32429. /* t3 = y ^ 0x1f */
  32430. sp_384_mont_mul_7(t3, t2, y, p384_mod, p384_mp_mod);
  32431. /* t2 = y ^ 0x3e0 */
  32432. sp_384_mont_sqr_n_7(t2, t3, 5, p384_mod, p384_mp_mod);
  32433. /* t1 = y ^ 0x3ff */
  32434. sp_384_mont_mul_7(t1, t3, t2, p384_mod, p384_mp_mod);
  32435. /* t2 = y ^ 0x7fe0 */
  32436. sp_384_mont_sqr_n_7(t2, t1, 5, p384_mod, p384_mp_mod);
  32437. /* t3 = y ^ 0x7fff */
  32438. sp_384_mont_mul_7(t3, t3, t2, p384_mod, p384_mp_mod);
  32439. /* t2 = y ^ 0x3fff800 */
  32440. sp_384_mont_sqr_n_7(t2, t3, 15, p384_mod, p384_mp_mod);
  32441. /* t4 = y ^ 0x3ffffff */
  32442. sp_384_mont_mul_7(t4, t3, t2, p384_mod, p384_mp_mod);
  32443. /* t2 = y ^ 0xffffffc000000 */
  32444. sp_384_mont_sqr_n_7(t2, t4, 30, p384_mod, p384_mp_mod);
  32445. /* t1 = y ^ 0xfffffffffffff */
  32446. sp_384_mont_mul_7(t1, t4, t2, p384_mod, p384_mp_mod);
  32447. /* t2 = y ^ 0xfffffffffffffff000000000000000 */
  32448. sp_384_mont_sqr_n_7(t2, t1, 60, p384_mod, p384_mp_mod);
  32449. /* t1 = y ^ 0xffffffffffffffffffffffffffffff */
  32450. sp_384_mont_mul_7(t1, t1, t2, p384_mod, p384_mp_mod);
  32451. /* t2 = y ^ 0xffffffffffffffffffffffffffffff000000000000000000000000000000 */
  32452. sp_384_mont_sqr_n_7(t2, t1, 120, p384_mod, p384_mp_mod);
  32453. /* t1 = y ^ 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
  32454. sp_384_mont_mul_7(t1, t1, t2, p384_mod, p384_mp_mod);
  32455. /* t2 = y ^ 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000 */
  32456. sp_384_mont_sqr_n_7(t2, t1, 15, p384_mod, p384_mp_mod);
  32457. /* t1 = y ^ 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
  32458. sp_384_mont_mul_7(t1, t3, t2, p384_mod, p384_mp_mod);
  32459. /* t2 = y ^ 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000 */
  32460. sp_384_mont_sqr_n_7(t2, t1, 31, p384_mod, p384_mp_mod);
  32461. /* t1 = y ^ 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffff */
  32462. sp_384_mont_mul_7(t1, t4, t2, p384_mod, p384_mp_mod);
  32463. /* t2 = y ^ 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffff0 */
  32464. sp_384_mont_sqr_n_7(t2, t1, 4, p384_mod, p384_mp_mod);
  32465. /* t1 = y ^ 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffc */
  32466. sp_384_mont_mul_7(t1, t5, t2, p384_mod, p384_mp_mod);
  32467. /* t2 = y ^ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000 */
  32468. sp_384_mont_sqr_n_7(t2, t1, 62, p384_mod, p384_mp_mod);
  32469. /* t1 = y ^ 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000001 */
  32470. sp_384_mont_mul_7(t1, y, t2, p384_mod, p384_mp_mod);
  32471. /* t2 = y ^ 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffc00000000000000040000000 */
  32472. sp_384_mont_sqr_n_7(y, t1, 30, p384_mod, p384_mp_mod);
  32473. }
  32474. }
  32475. #ifdef WOLFSSL_SP_SMALL_STACK
  32476. if (t1 != NULL)
  32477. XFREE(t1, NULL, DYNAMIC_TYPE_ECC);
  32478. #endif
  32479. return err;
  32480. }
  32481. /* Uncompress the point given the X ordinate.
  32482. *
  32483. * xm X ordinate.
  32484. * odd Whether the Y ordinate is odd.
  32485. * ym Calculated Y ordinate.
  32486. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  32487. */
  32488. int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym)
  32489. {
  32490. #ifdef WOLFSSL_SP_SMALL_STACK
  32491. sp_digit* x = NULL;
  32492. #else
  32493. sp_digit x[4 * 7];
  32494. #endif
  32495. sp_digit* y = NULL;
  32496. int err = MP_OKAY;
  32497. #ifdef WOLFSSL_SP_SMALL_STACK
  32498. x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 7, NULL, DYNAMIC_TYPE_ECC);
  32499. if (x == NULL)
  32500. err = MEMORY_E;
  32501. #endif
  32502. if (err == MP_OKAY) {
  32503. y = x + 2 * 7;
  32504. sp_384_from_mp(x, 7, xm);
  32505. err = sp_384_mod_mul_norm_7(x, x, p384_mod);
  32506. }
  32507. if (err == MP_OKAY) {
  32508. /* y = x^3 */
  32509. {
  32510. sp_384_mont_sqr_7(y, x, p384_mod, p384_mp_mod);
  32511. sp_384_mont_mul_7(y, y, x, p384_mod, p384_mp_mod);
  32512. }
  32513. /* y = x^3 - 3x */
  32514. sp_384_mont_sub_7(y, y, x, p384_mod);
  32515. sp_384_mont_sub_7(y, y, x, p384_mod);
  32516. sp_384_mont_sub_7(y, y, x, p384_mod);
  32517. /* y = x^3 - 3x + b */
  32518. err = sp_384_mod_mul_norm_7(x, p384_b, p384_mod);
  32519. }
  32520. if (err == MP_OKAY) {
  32521. sp_384_mont_add_7(y, y, x, p384_mod);
  32522. /* y = sqrt(x^3 - 3x + b) */
  32523. err = sp_384_mont_sqrt_7(y);
  32524. }
  32525. if (err == MP_OKAY) {
  32526. XMEMSET(y + 7, 0, 7U * sizeof(sp_digit));
  32527. sp_384_mont_reduce_7(y, p384_mod, p384_mp_mod);
  32528. if ((((word32)y[0] ^ (word32)odd) & 1U) != 0U) {
  32529. sp_384_mont_sub_7(y, p384_mod, y, p384_mod);
  32530. }
  32531. err = sp_384_to_mp(y, ym);
  32532. }
  32533. #ifdef WOLFSSL_SP_SMALL_STACK
  32534. if (x != NULL)
  32535. XFREE(x, NULL, DYNAMIC_TYPE_ECC);
  32536. #endif
  32537. return err;
  32538. }
  32539. #endif
  32540. #endif /* WOLFSSL_SP_384 */
  32541. #ifdef WOLFSSL_SP_521
  32542. /* Point structure to use. */
  32543. typedef struct sp_point_521 {
  32544. /* X ordinate of point. */
  32545. sp_digit x[2 * 9];
  32546. /* Y ordinate of point. */
  32547. sp_digit y[2 * 9];
  32548. /* Z ordinate of point. */
  32549. sp_digit z[2 * 9];
  32550. /* Indicates point is at infinity. */
  32551. int infinity;
  32552. } sp_point_521;
  32553. /* The modulus (prime) of the curve P521. */
  32554. static const sp_digit p521_mod[9] = {
  32555. 0x3ffffffffffffffL,0x3ffffffffffffffL,0x3ffffffffffffffL,0x3ffffffffffffffL,
  32556. 0x3ffffffffffffffL,0x3ffffffffffffffL,0x3ffffffffffffffL,0x3ffffffffffffffL,
  32557. 0x1ffffffffffffffL
  32558. };
  32559. /* The Montgomery normalizer for modulus of the curve P521. */
  32560. static const sp_digit p521_norm_mod[9] = {
  32561. 0x000000000000001L,0x000000000000000L,0x000000000000000L,0x000000000000000L,
  32562. 0x000000000000000L,0x000000000000000L,0x000000000000000L,0x000000000000000L,
  32563. 0x000000000000000L
  32564. };
  32565. /* The Montgomery multiplier for modulus of the curve P521. */
  32566. static sp_digit p521_mp_mod = 0x00000000000001;
  32567. #if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
  32568. defined(HAVE_ECC_VERIFY)
  32569. /* The order of the curve P521. */
  32570. static const sp_digit p521_order[9] = {
  32571. 0x36fb71e91386409L,0x1726e226711ebaeL,0x0148f709a5d03bbL,0x20efcbe59adff30L,
  32572. 0x3fffffffa518687L,0x3ffffffffffffffL,0x3ffffffffffffffL,0x3ffffffffffffffL,
  32573. 0x1ffffffffffffffL
  32574. };
  32575. #endif
  32576. /* The order of the curve P521 minus 2. */
  32577. static const sp_digit p521_order2[9] = {
  32578. 0x36fb71e91386407L,0x1726e226711ebaeL,0x0148f709a5d03bbL,0x20efcbe59adff30L,
  32579. 0x3fffffffa518687L,0x3ffffffffffffffL,0x3ffffffffffffffL,0x3ffffffffffffffL,
  32580. 0x1ffffffffffffffL
  32581. };
  32582. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  32583. /* The Montgomery normalizer for order of the curve P521. */
  32584. static const sp_digit p521_norm_order[9] = {
  32585. 0x09048e16ec79bf7L,0x28d91dd98ee1451L,0x3eb708f65a2fc44L,0x1f10341a65200cfL,
  32586. 0x000000005ae7978L,0x000000000000000L,0x000000000000000L,0x000000000000000L,
  32587. 0x000000000000000L
  32588. };
  32589. #endif
  32590. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  32591. /* The Montgomery multiplier for order of the curve P521. */
  32592. static sp_digit p521_mp_order = 0x12f5ccd79a995c7L;
  32593. #endif
  32594. /* The base point of curve P521. */
  32595. static const sp_point_521 p521_base = {
  32596. /* X ordinate */
  32597. {
  32598. 0x17e7e31c2e5bd66L,0x22cf0615a90a6feL,0x0127a2ffa8de334L,
  32599. 0x1dfbf9d64a3f877L,0x06b4d3dbaa14b5eL,0x14fed487e0a2bd8L,
  32600. 0x15b4429c6481390L,0x3a73678fb2d988eL,0x0c6858e06b70404L,
  32601. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  32602. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0
  32603. },
  32604. /* Y ordinate */
  32605. {
  32606. 0x0be94769fd16650L,0x31c21a89cb09022L,0x39013fad0761353L,
  32607. 0x2657bd099031542L,0x3273e662c97ee72L,0x1e6d11a05ebef45L,
  32608. 0x3d1bd998f544495L,0x3001172297ed0b1L,0x11839296a789a3bL,
  32609. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  32610. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0
  32611. },
  32612. /* Z ordinate */
  32613. {
  32614. 0x000000000000001L,0x000000000000000L,0x000000000000000L,
  32615. 0x000000000000000L,0x000000000000000L,0x000000000000000L,
  32616. 0x000000000000000L,0x000000000000000L,0x000000000000000L,
  32617. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  32618. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0
  32619. },
  32620. /* infinity */
  32621. 0
  32622. };
  32623. #if defined(HAVE_ECC_CHECK_KEY) || defined(HAVE_COMP_KEY)
  32624. static const sp_digit p521_b[9] = {
  32625. 0x3451fd46b503f00L,0x0f7e20f4b0d3c7bL,0x00bd3bb1bf07357L,0x147b1fa4dec594bL,
  32626. 0x18ef109e1561939L,0x26cc57cee2d2264L,0x0540eea2da725b9L,0x2687e4a688682daL,
  32627. 0x051953eb9618e1cL
  32628. };
  32629. #endif
  32630. #ifdef WOLFSSL_SP_SMALL
  32631. /* Multiply a and b into r. (r = a * b)
  32632. *
  32633. * r A single precision integer.
  32634. * a A single precision integer.
  32635. * b A single precision integer.
  32636. */
  32637. SP_NOINLINE static void sp_521_mul_9(sp_digit* r, const sp_digit* a,
  32638. const sp_digit* b)
  32639. {
  32640. int i;
  32641. int imax;
  32642. int k;
  32643. sp_uint128 c;
  32644. sp_uint128 lo;
  32645. c = ((sp_uint128)a[8]) * b[8];
  32646. r[17] = (sp_digit)(c >> 58);
  32647. c &= 0x3ffffffffffffffL;
  32648. for (k = 15; k >= 0; k--) {
  32649. if (k >= 9) {
  32650. i = k - 8;
  32651. imax = 8;
  32652. }
  32653. else {
  32654. i = 0;
  32655. imax = k;
  32656. }
  32657. lo = 0;
  32658. for (; i <= imax; i++) {
  32659. lo += ((sp_uint128)a[i]) * b[k - i];
  32660. }
  32661. c += lo >> 58;
  32662. r[k + 2] += (sp_digit)(c >> 58);
  32663. r[k + 1] = (sp_digit)(c & 0x3ffffffffffffffL);
  32664. c = lo & 0x3ffffffffffffffL;
  32665. }
  32666. r[0] = (sp_digit)c;
  32667. }
  32668. #else
  32669. /* Multiply a and b into r. (r = a * b)
  32670. *
  32671. * r A single precision integer.
  32672. * a A single precision integer.
  32673. * b A single precision integer.
  32674. */
  32675. SP_NOINLINE static void sp_521_mul_9(sp_digit* r, const sp_digit* a,
  32676. const sp_digit* b)
  32677. {
  32678. sp_int128 t0;
  32679. sp_int128 t1;
  32680. sp_digit t[9];
  32681. t0 = ((sp_int128)a[ 0]) * b[ 0];
  32682. t1 = ((sp_int128)a[ 0]) * b[ 1]
  32683. + ((sp_int128)a[ 1]) * b[ 0];
  32684. t[ 0] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32685. t0 = ((sp_int128)a[ 0]) * b[ 2]
  32686. + ((sp_int128)a[ 1]) * b[ 1]
  32687. + ((sp_int128)a[ 2]) * b[ 0];
  32688. t[ 1] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32689. t1 = ((sp_int128)a[ 0]) * b[ 3]
  32690. + ((sp_int128)a[ 1]) * b[ 2]
  32691. + ((sp_int128)a[ 2]) * b[ 1]
  32692. + ((sp_int128)a[ 3]) * b[ 0];
  32693. t[ 2] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32694. t0 = ((sp_int128)a[ 0]) * b[ 4]
  32695. + ((sp_int128)a[ 1]) * b[ 3]
  32696. + ((sp_int128)a[ 2]) * b[ 2]
  32697. + ((sp_int128)a[ 3]) * b[ 1]
  32698. + ((sp_int128)a[ 4]) * b[ 0];
  32699. t[ 3] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32700. t1 = ((sp_int128)a[ 0]) * b[ 5]
  32701. + ((sp_int128)a[ 1]) * b[ 4]
  32702. + ((sp_int128)a[ 2]) * b[ 3]
  32703. + ((sp_int128)a[ 3]) * b[ 2]
  32704. + ((sp_int128)a[ 4]) * b[ 1]
  32705. + ((sp_int128)a[ 5]) * b[ 0];
  32706. t[ 4] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32707. t0 = ((sp_int128)a[ 0]) * b[ 6]
  32708. + ((sp_int128)a[ 1]) * b[ 5]
  32709. + ((sp_int128)a[ 2]) * b[ 4]
  32710. + ((sp_int128)a[ 3]) * b[ 3]
  32711. + ((sp_int128)a[ 4]) * b[ 2]
  32712. + ((sp_int128)a[ 5]) * b[ 1]
  32713. + ((sp_int128)a[ 6]) * b[ 0];
  32714. t[ 5] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32715. t1 = ((sp_int128)a[ 0]) * b[ 7]
  32716. + ((sp_int128)a[ 1]) * b[ 6]
  32717. + ((sp_int128)a[ 2]) * b[ 5]
  32718. + ((sp_int128)a[ 3]) * b[ 4]
  32719. + ((sp_int128)a[ 4]) * b[ 3]
  32720. + ((sp_int128)a[ 5]) * b[ 2]
  32721. + ((sp_int128)a[ 6]) * b[ 1]
  32722. + ((sp_int128)a[ 7]) * b[ 0];
  32723. t[ 6] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32724. t0 = ((sp_int128)a[ 0]) * b[ 8]
  32725. + ((sp_int128)a[ 1]) * b[ 7]
  32726. + ((sp_int128)a[ 2]) * b[ 6]
  32727. + ((sp_int128)a[ 3]) * b[ 5]
  32728. + ((sp_int128)a[ 4]) * b[ 4]
  32729. + ((sp_int128)a[ 5]) * b[ 3]
  32730. + ((sp_int128)a[ 6]) * b[ 2]
  32731. + ((sp_int128)a[ 7]) * b[ 1]
  32732. + ((sp_int128)a[ 8]) * b[ 0];
  32733. t[ 7] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32734. t1 = ((sp_int128)a[ 1]) * b[ 8]
  32735. + ((sp_int128)a[ 2]) * b[ 7]
  32736. + ((sp_int128)a[ 3]) * b[ 6]
  32737. + ((sp_int128)a[ 4]) * b[ 5]
  32738. + ((sp_int128)a[ 5]) * b[ 4]
  32739. + ((sp_int128)a[ 6]) * b[ 3]
  32740. + ((sp_int128)a[ 7]) * b[ 2]
  32741. + ((sp_int128)a[ 8]) * b[ 1];
  32742. t[ 8] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32743. t0 = ((sp_int128)a[ 2]) * b[ 8]
  32744. + ((sp_int128)a[ 3]) * b[ 7]
  32745. + ((sp_int128)a[ 4]) * b[ 6]
  32746. + ((sp_int128)a[ 5]) * b[ 5]
  32747. + ((sp_int128)a[ 6]) * b[ 4]
  32748. + ((sp_int128)a[ 7]) * b[ 3]
  32749. + ((sp_int128)a[ 8]) * b[ 2];
  32750. r[ 9] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32751. t1 = ((sp_int128)a[ 3]) * b[ 8]
  32752. + ((sp_int128)a[ 4]) * b[ 7]
  32753. + ((sp_int128)a[ 5]) * b[ 6]
  32754. + ((sp_int128)a[ 6]) * b[ 5]
  32755. + ((sp_int128)a[ 7]) * b[ 4]
  32756. + ((sp_int128)a[ 8]) * b[ 3];
  32757. r[10] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32758. t0 = ((sp_int128)a[ 4]) * b[ 8]
  32759. + ((sp_int128)a[ 5]) * b[ 7]
  32760. + ((sp_int128)a[ 6]) * b[ 6]
  32761. + ((sp_int128)a[ 7]) * b[ 5]
  32762. + ((sp_int128)a[ 8]) * b[ 4];
  32763. r[11] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32764. t1 = ((sp_int128)a[ 5]) * b[ 8]
  32765. + ((sp_int128)a[ 6]) * b[ 7]
  32766. + ((sp_int128)a[ 7]) * b[ 6]
  32767. + ((sp_int128)a[ 8]) * b[ 5];
  32768. r[12] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32769. t0 = ((sp_int128)a[ 6]) * b[ 8]
  32770. + ((sp_int128)a[ 7]) * b[ 7]
  32771. + ((sp_int128)a[ 8]) * b[ 6];
  32772. r[13] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32773. t1 = ((sp_int128)a[ 7]) * b[ 8]
  32774. + ((sp_int128)a[ 8]) * b[ 7];
  32775. r[14] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32776. t0 = ((sp_int128)a[ 8]) * b[ 8];
  32777. r[15] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32778. r[16] = t0 & 0x3ffffffffffffffL;
  32779. r[17] = (sp_digit)(t0 >> 58);
  32780. XMEMCPY(r, t, sizeof(t));
  32781. }
  32782. #endif /* WOLFSSL_SP_SMALL */
  32783. #ifdef WOLFSSL_SP_SMALL
  32784. /* Square a and put result in r. (r = a * a)
  32785. *
  32786. * r A single precision integer.
  32787. * a A single precision integer.
  32788. */
  32789. SP_NOINLINE static void sp_521_sqr_9(sp_digit* r, const sp_digit* a)
  32790. {
  32791. int i;
  32792. int imax;
  32793. int k;
  32794. sp_uint128 c;
  32795. sp_uint128 t;
  32796. c = ((sp_uint128)a[8]) * a[8];
  32797. r[17] = (sp_digit)(c >> 58);
  32798. c = (c & 0x3ffffffffffffffL) << 58;
  32799. for (k = 15; k >= 0; k--) {
  32800. i = (k + 1) / 2;
  32801. if ((k & 1) == 0) {
  32802. c += ((sp_uint128)a[i]) * a[i];
  32803. i++;
  32804. }
  32805. if (k < 8) {
  32806. imax = k;
  32807. }
  32808. else {
  32809. imax = 8;
  32810. }
  32811. t = 0;
  32812. for (; i <= imax; i++) {
  32813. t += ((sp_uint128)a[i]) * a[k - i];
  32814. }
  32815. c += t * 2;
  32816. r[k + 2] += (sp_digit) (c >> 116);
  32817. r[k + 1] = (sp_digit)((c >> 58) & 0x3ffffffffffffffL);
  32818. c = (c & 0x3ffffffffffffffL) << 58;
  32819. }
  32820. r[0] = (sp_digit)(c >> 58);
  32821. }
  32822. #else
  32823. /* Square a and put result in r. (r = a * a)
  32824. *
  32825. * r A single precision integer.
  32826. * a A single precision integer.
  32827. */
  32828. SP_NOINLINE static void sp_521_sqr_9(sp_digit* r, const sp_digit* a)
  32829. {
  32830. sp_int128 t0;
  32831. sp_int128 t1;
  32832. sp_digit t[9];
  32833. t0 = ((sp_int128)a[ 0]) * a[ 0];
  32834. t1 = (((sp_int128)a[ 0]) * a[ 1]) * 2;
  32835. t[ 0] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32836. t0 = (((sp_int128)a[ 0]) * a[ 2]) * 2
  32837. + ((sp_int128)a[ 1]) * a[ 1];
  32838. t[ 1] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32839. t1 = (((sp_int128)a[ 0]) * a[ 3]
  32840. + ((sp_int128)a[ 1]) * a[ 2]) * 2;
  32841. t[ 2] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32842. t0 = (((sp_int128)a[ 0]) * a[ 4]
  32843. + ((sp_int128)a[ 1]) * a[ 3]) * 2
  32844. + ((sp_int128)a[ 2]) * a[ 2];
  32845. t[ 3] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32846. t1 = (((sp_int128)a[ 0]) * a[ 5]
  32847. + ((sp_int128)a[ 1]) * a[ 4]
  32848. + ((sp_int128)a[ 2]) * a[ 3]) * 2;
  32849. t[ 4] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32850. t0 = (((sp_int128)a[ 0]) * a[ 6]
  32851. + ((sp_int128)a[ 1]) * a[ 5]
  32852. + ((sp_int128)a[ 2]) * a[ 4]) * 2
  32853. + ((sp_int128)a[ 3]) * a[ 3];
  32854. t[ 5] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32855. t1 = (((sp_int128)a[ 0]) * a[ 7]
  32856. + ((sp_int128)a[ 1]) * a[ 6]
  32857. + ((sp_int128)a[ 2]) * a[ 5]
  32858. + ((sp_int128)a[ 3]) * a[ 4]) * 2;
  32859. t[ 6] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32860. t0 = (((sp_int128)a[ 0]) * a[ 8]
  32861. + ((sp_int128)a[ 1]) * a[ 7]
  32862. + ((sp_int128)a[ 2]) * a[ 6]
  32863. + ((sp_int128)a[ 3]) * a[ 5]) * 2
  32864. + ((sp_int128)a[ 4]) * a[ 4];
  32865. t[ 7] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32866. t1 = (((sp_int128)a[ 1]) * a[ 8]
  32867. + ((sp_int128)a[ 2]) * a[ 7]
  32868. + ((sp_int128)a[ 3]) * a[ 6]
  32869. + ((sp_int128)a[ 4]) * a[ 5]) * 2;
  32870. t[ 8] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32871. t0 = (((sp_int128)a[ 2]) * a[ 8]
  32872. + ((sp_int128)a[ 3]) * a[ 7]
  32873. + ((sp_int128)a[ 4]) * a[ 6]) * 2
  32874. + ((sp_int128)a[ 5]) * a[ 5];
  32875. r[ 9] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32876. t1 = (((sp_int128)a[ 3]) * a[ 8]
  32877. + ((sp_int128)a[ 4]) * a[ 7]
  32878. + ((sp_int128)a[ 5]) * a[ 6]) * 2;
  32879. r[10] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32880. t0 = (((sp_int128)a[ 4]) * a[ 8]
  32881. + ((sp_int128)a[ 5]) * a[ 7]) * 2
  32882. + ((sp_int128)a[ 6]) * a[ 6];
  32883. r[11] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32884. t1 = (((sp_int128)a[ 5]) * a[ 8]
  32885. + ((sp_int128)a[ 6]) * a[ 7]) * 2;
  32886. r[12] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32887. t0 = (((sp_int128)a[ 6]) * a[ 8]) * 2
  32888. + ((sp_int128)a[ 7]) * a[ 7];
  32889. r[13] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32890. t1 = (((sp_int128)a[ 7]) * a[ 8]) * 2;
  32891. r[14] = t0 & 0x3ffffffffffffffL; t1 += t0 >> 58;
  32892. t0 = ((sp_int128)a[ 8]) * a[ 8];
  32893. r[15] = t1 & 0x3ffffffffffffffL; t0 += t1 >> 58;
  32894. r[16] = t0 & 0x3ffffffffffffffL;
  32895. r[17] = (sp_digit)(t0 >> 58);
  32896. XMEMCPY(r, t, sizeof(t));
  32897. }
  32898. #endif /* WOLFSSL_SP_SMALL */
  32899. #ifdef WOLFSSL_SP_SMALL
  32900. /* Add b to a into r. (r = a + b)
  32901. *
  32902. * r A single precision integer.
  32903. * a A single precision integer.
  32904. * b A single precision integer.
  32905. */
  32906. SP_NOINLINE static int sp_521_add_9(sp_digit* r, const sp_digit* a,
  32907. const sp_digit* b)
  32908. {
  32909. int i;
  32910. for (i = 0; i < 9; i++) {
  32911. r[i] = a[i] + b[i];
  32912. }
  32913. return 0;
  32914. }
  32915. #else
  32916. /* Add b to a into r. (r = a + b)
  32917. *
  32918. * r A single precision integer.
  32919. * a A single precision integer.
  32920. * b A single precision integer.
  32921. */
  32922. SP_NOINLINE static int sp_521_add_9(sp_digit* r, const sp_digit* a,
  32923. const sp_digit* b)
  32924. {
  32925. r[ 0] = a[ 0] + b[ 0];
  32926. r[ 1] = a[ 1] + b[ 1];
  32927. r[ 2] = a[ 2] + b[ 2];
  32928. r[ 3] = a[ 3] + b[ 3];
  32929. r[ 4] = a[ 4] + b[ 4];
  32930. r[ 5] = a[ 5] + b[ 5];
  32931. r[ 6] = a[ 6] + b[ 6];
  32932. r[ 7] = a[ 7] + b[ 7];
  32933. r[ 8] = a[ 8] + b[ 8];
  32934. return 0;
  32935. }
  32936. #endif /* WOLFSSL_SP_SMALL */
  32937. #ifdef WOLFSSL_SP_SMALL
  32938. /* Sub b from a into r. (r = a - b)
  32939. *
  32940. * r A single precision integer.
  32941. * a A single precision integer.
  32942. * b A single precision integer.
  32943. */
  32944. SP_NOINLINE static int sp_521_sub_9(sp_digit* r, const sp_digit* a,
  32945. const sp_digit* b)
  32946. {
  32947. int i;
  32948. for (i = 0; i < 9; i++) {
  32949. r[i] = a[i] - b[i];
  32950. }
  32951. return 0;
  32952. }
  32953. #else
  32954. /* Sub b from a into r. (r = a - b)
  32955. *
  32956. * r A single precision integer.
  32957. * a A single precision integer.
  32958. * b A single precision integer.
  32959. */
  32960. SP_NOINLINE static int sp_521_sub_9(sp_digit* r, const sp_digit* a,
  32961. const sp_digit* b)
  32962. {
  32963. r[ 0] = a[ 0] - b[ 0];
  32964. r[ 1] = a[ 1] - b[ 1];
  32965. r[ 2] = a[ 2] - b[ 2];
  32966. r[ 3] = a[ 3] - b[ 3];
  32967. r[ 4] = a[ 4] - b[ 4];
  32968. r[ 5] = a[ 5] - b[ 5];
  32969. r[ 6] = a[ 6] - b[ 6];
  32970. r[ 7] = a[ 7] - b[ 7];
  32971. r[ 8] = a[ 8] - b[ 8];
  32972. return 0;
  32973. }
  32974. #endif /* WOLFSSL_SP_SMALL */
  32975. /* Convert an mp_int to an array of sp_digit.
  32976. *
  32977. * r A single precision integer.
  32978. * size Maximum number of bytes to convert
  32979. * a A multi-precision integer.
  32980. */
  32981. static void sp_521_from_mp(sp_digit* r, int size, const mp_int* a)
  32982. {
  32983. #if DIGIT_BIT == 58
  32984. int i;
  32985. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  32986. int o = 0;
  32987. for (i = 0; i < size; i++) {
  32988. sp_digit mask = (sp_digit)0 - (j >> 57);
  32989. r[i] = a->dp[o] & mask;
  32990. j++;
  32991. o += (int)(j >> 57);
  32992. }
  32993. #elif DIGIT_BIT > 58
  32994. unsigned int i;
  32995. int j = 0;
  32996. word32 s = 0;
  32997. r[0] = 0;
  32998. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  32999. r[j] |= ((sp_digit)a->dp[i] << s);
  33000. r[j] &= 0x3ffffffffffffffL;
  33001. s = 58U - s;
  33002. if (j + 1 >= size) {
  33003. break;
  33004. }
  33005. /* lint allow cast of mismatch word32 and mp_digit */
  33006. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  33007. while ((s + 58U) <= (word32)DIGIT_BIT) {
  33008. s += 58U;
  33009. r[j] &= 0x3ffffffffffffffL;
  33010. if (j + 1 >= size) {
  33011. break;
  33012. }
  33013. if (s < (word32)DIGIT_BIT) {
  33014. /* lint allow cast of mismatch word32 and mp_digit */
  33015. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  33016. }
  33017. else {
  33018. r[++j] = (sp_digit)0;
  33019. }
  33020. }
  33021. s = (word32)DIGIT_BIT - s;
  33022. }
  33023. for (j++; j < size; j++) {
  33024. r[j] = 0;
  33025. }
  33026. #else
  33027. unsigned int i;
  33028. int j = 0;
  33029. int s = 0;
  33030. r[0] = 0;
  33031. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  33032. r[j] |= ((sp_digit)a->dp[i]) << s;
  33033. if (s + DIGIT_BIT >= 58) {
  33034. r[j] &= 0x3ffffffffffffffL;
  33035. if (j + 1 >= size) {
  33036. break;
  33037. }
  33038. s = 58 - s;
  33039. if (s == DIGIT_BIT) {
  33040. r[++j] = 0;
  33041. s = 0;
  33042. }
  33043. else {
  33044. r[++j] = a->dp[i] >> s;
  33045. s = DIGIT_BIT - s;
  33046. }
  33047. }
  33048. else {
  33049. s += DIGIT_BIT;
  33050. }
  33051. }
  33052. for (j++; j < size; j++) {
  33053. r[j] = 0;
  33054. }
  33055. #endif
  33056. }
  33057. /* Convert a point of type ecc_point to type sp_point_521.
  33058. *
  33059. * p Point of type sp_point_521 (result).
  33060. * pm Point of type ecc_point.
  33061. */
  33062. static void sp_521_point_from_ecc_point_9(sp_point_521* p,
  33063. const ecc_point* pm)
  33064. {
  33065. XMEMSET(p->x, 0, sizeof(p->x));
  33066. XMEMSET(p->y, 0, sizeof(p->y));
  33067. XMEMSET(p->z, 0, sizeof(p->z));
  33068. sp_521_from_mp(p->x, 9, pm->x);
  33069. sp_521_from_mp(p->y, 9, pm->y);
  33070. sp_521_from_mp(p->z, 9, pm->z);
  33071. p->infinity = 0;
  33072. }
  33073. /* Convert an array of sp_digit to an mp_int.
  33074. *
  33075. * a A single precision integer.
  33076. * r A multi-precision integer.
  33077. */
  33078. static int sp_521_to_mp(const sp_digit* a, mp_int* r)
  33079. {
  33080. int err;
  33081. err = mp_grow(r, (521 + DIGIT_BIT - 1) / DIGIT_BIT);
  33082. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  33083. #if DIGIT_BIT == 58
  33084. XMEMCPY(r->dp, a, sizeof(sp_digit) * 9);
  33085. r->used = 9;
  33086. mp_clamp(r);
  33087. #elif DIGIT_BIT < 58
  33088. int i;
  33089. int j = 0;
  33090. int s = 0;
  33091. r->dp[0] = 0;
  33092. for (i = 0; i < 9; i++) {
  33093. r->dp[j] |= (mp_digit)(a[i] << s);
  33094. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  33095. s = DIGIT_BIT - s;
  33096. r->dp[++j] = (mp_digit)(a[i] >> s);
  33097. while (s + DIGIT_BIT <= 58) {
  33098. s += DIGIT_BIT;
  33099. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  33100. if (s == SP_WORD_SIZE) {
  33101. r->dp[j] = 0;
  33102. }
  33103. else {
  33104. r->dp[j] = (mp_digit)(a[i] >> s);
  33105. }
  33106. }
  33107. s = 58 - s;
  33108. }
  33109. r->used = (521 + DIGIT_BIT - 1) / DIGIT_BIT;
  33110. mp_clamp(r);
  33111. #else
  33112. int i;
  33113. int j = 0;
  33114. int s = 0;
  33115. r->dp[0] = 0;
  33116. for (i = 0; i < 9; i++) {
  33117. r->dp[j] |= ((mp_digit)a[i]) << s;
  33118. if (s + 58 >= DIGIT_BIT) {
  33119. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  33120. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  33121. #endif
  33122. s = DIGIT_BIT - s;
  33123. r->dp[++j] = a[i] >> s;
  33124. s = 58 - s;
  33125. }
  33126. else {
  33127. s += 58;
  33128. }
  33129. }
  33130. r->used = (521 + DIGIT_BIT - 1) / DIGIT_BIT;
  33131. mp_clamp(r);
  33132. #endif
  33133. }
  33134. return err;
  33135. }
  33136. /* Convert a point of type sp_point_521 to type ecc_point.
  33137. *
  33138. * p Point of type sp_point_521.
  33139. * pm Point of type ecc_point (result).
  33140. * returns MEMORY_E when allocation of memory in ecc_point fails otherwise
  33141. * MP_OKAY.
  33142. */
  33143. static int sp_521_point_to_ecc_point_9(const sp_point_521* p, ecc_point* pm)
  33144. {
  33145. int err;
  33146. err = sp_521_to_mp(p->x, pm->x);
  33147. if (err == MP_OKAY) {
  33148. err = sp_521_to_mp(p->y, pm->y);
  33149. }
  33150. if (err == MP_OKAY) {
  33151. err = sp_521_to_mp(p->z, pm->z);
  33152. }
  33153. return err;
  33154. }
  33155. /* Normalize the values in each word to 58 bits.
  33156. *
  33157. * a Array of sp_digit to normalize.
  33158. */
  33159. static void sp_521_norm_9(sp_digit* a)
  33160. {
  33161. #ifdef WOLFSSL_SP_SMALL
  33162. int i;
  33163. for (i = 0; i < 8; i++) {
  33164. a[i+1] += a[i] >> 58;
  33165. a[i] &= 0x3ffffffffffffffL;
  33166. }
  33167. #else
  33168. a[1] += a[0] >> 58; a[0] &= 0x3ffffffffffffffL;
  33169. a[2] += a[1] >> 58; a[1] &= 0x3ffffffffffffffL;
  33170. a[3] += a[2] >> 58; a[2] &= 0x3ffffffffffffffL;
  33171. a[4] += a[3] >> 58; a[3] &= 0x3ffffffffffffffL;
  33172. a[5] += a[4] >> 58; a[4] &= 0x3ffffffffffffffL;
  33173. a[6] += a[5] >> 58; a[5] &= 0x3ffffffffffffffL;
  33174. a[7] += a[6] >> 58; a[6] &= 0x3ffffffffffffffL;
  33175. a[8] += a[7] >> 58; a[7] &= 0x3ffffffffffffffL;
  33176. #endif /* WOLFSSL_SP_SMALL */
  33177. }
  33178. /* Reduce the number back to 521 bits using Montgomery reduction.
  33179. *
  33180. * a A single precision number to reduce in place.
  33181. * m The single precision number representing the modulus.
  33182. * mp The digit representing the negative inverse of m mod 2^n.
  33183. */
  33184. static void sp_521_mont_reduce_9(sp_digit* a, const sp_digit* m, sp_digit mp)
  33185. {
  33186. int i;
  33187. (void)m;
  33188. (void)mp;
  33189. for (i = 0; i < 8; i++) {
  33190. a[i] += ((a[8 + i] >> 57) + (a[8 + i + 1] << 1)) & 0x3ffffffffffffffL;
  33191. }
  33192. a[8] &= 0x1ffffffffffffff;
  33193. a[8] += ((a[16] >> 57) + (a[17] << 1)) & 0x3ffffffffffffffL;
  33194. sp_521_norm_9(a);
  33195. a[0] += a[8] >> 57;
  33196. a[8] &= 0x1ffffffffffffff;
  33197. }
  33198. /* Compare a with b in constant time.
  33199. *
  33200. * a A single precision integer.
  33201. * b A single precision integer.
  33202. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  33203. * respectively.
  33204. */
  33205. static sp_digit sp_521_cmp_9(const sp_digit* a, const sp_digit* b)
  33206. {
  33207. sp_digit r = 0;
  33208. #ifdef WOLFSSL_SP_SMALL
  33209. int i;
  33210. for (i=8; i>=0; i--) {
  33211. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 57);
  33212. }
  33213. #else
  33214. r |= (a[ 8] - b[ 8]) & (0 - (sp_digit)1);
  33215. r |= (a[ 7] - b[ 7]) & ~(((sp_digit)0 - r) >> 57);
  33216. r |= (a[ 6] - b[ 6]) & ~(((sp_digit)0 - r) >> 57);
  33217. r |= (a[ 5] - b[ 5]) & ~(((sp_digit)0 - r) >> 57);
  33218. r |= (a[ 4] - b[ 4]) & ~(((sp_digit)0 - r) >> 57);
  33219. r |= (a[ 3] - b[ 3]) & ~(((sp_digit)0 - r) >> 57);
  33220. r |= (a[ 2] - b[ 2]) & ~(((sp_digit)0 - r) >> 57);
  33221. r |= (a[ 1] - b[ 1]) & ~(((sp_digit)0 - r) >> 57);
  33222. r |= (a[ 0] - b[ 0]) & ~(((sp_digit)0 - r) >> 57);
  33223. #endif /* WOLFSSL_SP_SMALL */
  33224. return r;
  33225. }
  33226. /* Conditionally subtract b from a using the mask m.
  33227. * m is -1 to subtract and 0 when not.
  33228. *
  33229. * r A single precision number representing condition subtract result.
  33230. * a A single precision number to subtract from.
  33231. * b A single precision number to subtract.
  33232. * m Mask value to apply.
  33233. */
  33234. static void sp_521_cond_sub_9(sp_digit* r, const sp_digit* a,
  33235. const sp_digit* b, const sp_digit m)
  33236. {
  33237. #ifdef WOLFSSL_SP_SMALL
  33238. int i;
  33239. for (i = 0; i < 9; i++) {
  33240. r[i] = a[i] - (b[i] & m);
  33241. }
  33242. #else
  33243. r[ 0] = a[ 0] - (b[ 0] & m);
  33244. r[ 1] = a[ 1] - (b[ 1] & m);
  33245. r[ 2] = a[ 2] - (b[ 2] & m);
  33246. r[ 3] = a[ 3] - (b[ 3] & m);
  33247. r[ 4] = a[ 4] - (b[ 4] & m);
  33248. r[ 5] = a[ 5] - (b[ 5] & m);
  33249. r[ 6] = a[ 6] - (b[ 6] & m);
  33250. r[ 7] = a[ 7] - (b[ 7] & m);
  33251. r[ 8] = a[ 8] - (b[ 8] & m);
  33252. #endif /* WOLFSSL_SP_SMALL */
  33253. }
  33254. /* Mul a by scalar b and add into r. (r += a * b)
  33255. *
  33256. * r A single precision integer.
  33257. * a A single precision integer.
  33258. * b A scalar.
  33259. */
  33260. SP_NOINLINE static void sp_521_mul_add_9(sp_digit* r, const sp_digit* a,
  33261. const sp_digit b)
  33262. {
  33263. #ifdef WOLFSSL_SP_SMALL
  33264. sp_int128 tb = b;
  33265. sp_int128 t[4];
  33266. int i;
  33267. t[0] = 0;
  33268. for (i = 0; i < 8; i += 4) {
  33269. t[0] += (tb * a[i+0]) + r[i+0];
  33270. t[1] = (tb * a[i+1]) + r[i+1];
  33271. t[2] = (tb * a[i+2]) + r[i+2];
  33272. t[3] = (tb * a[i+3]) + r[i+3];
  33273. r[i+0] = t[0] & 0x3ffffffffffffffL;
  33274. t[1] += t[0] >> 58;
  33275. r[i+1] = t[1] & 0x3ffffffffffffffL;
  33276. t[2] += t[1] >> 58;
  33277. r[i+2] = t[2] & 0x3ffffffffffffffL;
  33278. t[3] += t[2] >> 58;
  33279. r[i+3] = t[3] & 0x3ffffffffffffffL;
  33280. t[0] = t[3] >> 58;
  33281. }
  33282. t[0] += (tb * a[8]) + r[8];
  33283. r[8] = t[0] & 0x3ffffffffffffffL;
  33284. r[9] += (sp_digit)(t[0] >> 58);
  33285. #else
  33286. sp_int128 tb = b;
  33287. sp_int128 t[9];
  33288. t[ 0] = tb * a[ 0];
  33289. t[ 1] = tb * a[ 1];
  33290. t[ 2] = tb * a[ 2];
  33291. t[ 3] = tb * a[ 3];
  33292. t[ 4] = tb * a[ 4];
  33293. t[ 5] = tb * a[ 5];
  33294. t[ 6] = tb * a[ 6];
  33295. t[ 7] = tb * a[ 7];
  33296. t[ 8] = tb * a[ 8];
  33297. r[ 0] += (sp_digit) (t[ 0] & 0x3ffffffffffffffL);
  33298. r[ 1] += (sp_digit)((t[ 0] >> 58) + (t[ 1] & 0x3ffffffffffffffL));
  33299. r[ 2] += (sp_digit)((t[ 1] >> 58) + (t[ 2] & 0x3ffffffffffffffL));
  33300. r[ 3] += (sp_digit)((t[ 2] >> 58) + (t[ 3] & 0x3ffffffffffffffL));
  33301. r[ 4] += (sp_digit)((t[ 3] >> 58) + (t[ 4] & 0x3ffffffffffffffL));
  33302. r[ 5] += (sp_digit)((t[ 4] >> 58) + (t[ 5] & 0x3ffffffffffffffL));
  33303. r[ 6] += (sp_digit)((t[ 5] >> 58) + (t[ 6] & 0x3ffffffffffffffL));
  33304. r[ 7] += (sp_digit)((t[ 6] >> 58) + (t[ 7] & 0x3ffffffffffffffL));
  33305. r[ 8] += (sp_digit)((t[ 7] >> 58) + (t[ 8] & 0x3ffffffffffffffL));
  33306. r[ 9] += (sp_digit) (t[ 8] >> 58);
  33307. #endif /* WOLFSSL_SP_SMALL */
  33308. }
  33309. /* Shift the result in the high 521 bits down to the bottom.
  33310. *
  33311. * r A single precision number.
  33312. * a A single precision number.
  33313. */
  33314. static void sp_521_mont_shift_9(sp_digit* r, const sp_digit* a)
  33315. {
  33316. #ifdef WOLFSSL_SP_SMALL
  33317. int i;
  33318. sp_uint64 n;
  33319. n = a[8] >> 57;
  33320. for (i = 0; i < 8; i++) {
  33321. n += (sp_uint64)a[9 + i] << 1;
  33322. r[i] = n & 0x3ffffffffffffffL;
  33323. n >>= 58;
  33324. }
  33325. n += (sp_uint64)a[17] << 1;
  33326. r[8] = n;
  33327. #else
  33328. sp_uint64 n;
  33329. n = a[8] >> 57;
  33330. n += (sp_uint64)a[ 9] << 1U; r[ 0] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33331. n += (sp_uint64)a[10] << 1U; r[ 1] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33332. n += (sp_uint64)a[11] << 1U; r[ 2] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33333. n += (sp_uint64)a[12] << 1U; r[ 3] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33334. n += (sp_uint64)a[13] << 1U; r[ 4] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33335. n += (sp_uint64)a[14] << 1U; r[ 5] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33336. n += (sp_uint64)a[15] << 1U; r[ 6] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33337. n += (sp_uint64)a[16] << 1U; r[ 7] = n & 0x3ffffffffffffffUL; n >>= 58U;
  33338. n += (sp_uint64)a[17] << 1U; r[ 8] = n;
  33339. #endif /* WOLFSSL_SP_SMALL */
  33340. XMEMSET(&r[9], 0, sizeof(*r) * 9U);
  33341. }
  33342. /* Reduce the number back to 521 bits using Montgomery reduction.
  33343. *
  33344. * a A single precision number to reduce in place.
  33345. * m The single precision number representing the modulus.
  33346. * mp The digit representing the negative inverse of m mod 2^n.
  33347. */
  33348. static void sp_521_mont_reduce_order_9(sp_digit* a, const sp_digit* m, sp_digit mp)
  33349. {
  33350. int i;
  33351. sp_digit mu;
  33352. sp_digit over;
  33353. sp_521_norm_9(a + 9);
  33354. for (i=0; i<8; i++) {
  33355. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x3ffffffffffffffL;
  33356. sp_521_mul_add_9(a+i, m, mu);
  33357. a[i+1] += a[i] >> 58;
  33358. }
  33359. mu = ((sp_uint64)a[i] * (sp_uint64)mp) & 0x1ffffffffffffffL;
  33360. sp_521_mul_add_9(a+i, m, mu);
  33361. a[i+1] += a[i] >> 58;
  33362. a[i] &= 0x3ffffffffffffffL;
  33363. sp_521_mont_shift_9(a, a);
  33364. over = a[8] >> 57;
  33365. sp_521_cond_sub_9(a, a, m, ~((over - 1) >> 63));
  33366. sp_521_norm_9(a);
  33367. }
  33368. /* Multiply two Montgomery form numbers mod the modulus (prime).
  33369. * (r = a * b mod m)
  33370. *
  33371. * r Result of multiplication.
  33372. * a First number to multiply in Montgomery form.
  33373. * b Second number to multiply in Montgomery form.
  33374. * m Modulus (prime).
  33375. * mp Montgomery multiplier.
  33376. */
  33377. SP_NOINLINE static void sp_521_mont_mul_9(sp_digit* r, const sp_digit* a,
  33378. const sp_digit* b, const sp_digit* m, sp_digit mp)
  33379. {
  33380. sp_521_mul_9(r, a, b);
  33381. sp_521_mont_reduce_9(r, m, mp);
  33382. }
  33383. /* Square the Montgomery form number. (r = a * a mod m)
  33384. *
  33385. * r Result of squaring.
  33386. * a Number to square in Montgomery form.
  33387. * m Modulus (prime).
  33388. * mp Montgomery multiplier.
  33389. */
  33390. SP_NOINLINE static void sp_521_mont_sqr_9(sp_digit* r, const sp_digit* a,
  33391. const sp_digit* m, sp_digit mp)
  33392. {
  33393. sp_521_sqr_9(r, a);
  33394. sp_521_mont_reduce_9(r, m, mp);
  33395. }
  33396. #ifndef WOLFSSL_SP_SMALL
  33397. /* Square the Montgomery form number a number of times. (r = a ^ n mod m)
  33398. *
  33399. * r Result of squaring.
  33400. * a Number to square in Montgomery form.
  33401. * n Number of times to square.
  33402. * m Modulus (prime).
  33403. * mp Montgomery multiplier.
  33404. */
  33405. static void sp_521_mont_sqr_n_9(sp_digit* r, const sp_digit* a, int n,
  33406. const sp_digit* m, sp_digit mp)
  33407. {
  33408. sp_521_mont_sqr_9(r, a, m, mp);
  33409. for (; n > 1; n--) {
  33410. sp_521_mont_sqr_9(r, r, m, mp);
  33411. }
  33412. }
  33413. #endif /* !WOLFSSL_SP_SMALL */
  33414. #ifdef WOLFSSL_SP_SMALL
  33415. /* Mod-2 for the P521 curve. */
  33416. static const uint64_t p521_mod_minus_2[9] = {
  33417. 0xfffffffffffffffdU,0xffffffffffffffffU,0xffffffffffffffffU,
  33418. 0xffffffffffffffffU,0xffffffffffffffffU,0xffffffffffffffffU,
  33419. 0xffffffffffffffffU,0xffffffffffffffffU,0x00000000000001ffU
  33420. };
  33421. #endif /* !WOLFSSL_SP_SMALL */
  33422. /* Invert the number, in Montgomery form, modulo the modulus (prime) of the
  33423. * P521 curve. (r = 1 / a mod m)
  33424. *
  33425. * r Inverse result.
  33426. * a Number to invert.
  33427. * td Temporary data.
  33428. */
  33429. static void sp_521_mont_inv_9(sp_digit* r, const sp_digit* a, sp_digit* td)
  33430. {
  33431. #ifdef WOLFSSL_SP_SMALL
  33432. sp_digit* t = td;
  33433. int i;
  33434. XMEMCPY(t, a, sizeof(sp_digit) * 9);
  33435. for (i=519; i>=0; i--) {
  33436. sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod);
  33437. if (p521_mod_minus_2[i / 64] & ((sp_digit)1 << (i % 64)))
  33438. sp_521_mont_mul_9(t, t, a, p521_mod, p521_mp_mod);
  33439. }
  33440. XMEMCPY(r, t, sizeof(sp_digit) * 9);
  33441. #else
  33442. sp_digit* t1 = td;
  33443. sp_digit* t2 = td + 2 * 9;
  33444. sp_digit* t3 = td + 4 * 9;
  33445. /* 0x2 */
  33446. sp_521_mont_sqr_9(t1, a, p521_mod, p521_mp_mod);
  33447. /* 0x3 */
  33448. sp_521_mont_mul_9(t2, t1, a, p521_mod, p521_mp_mod);
  33449. /* 0x6 */
  33450. sp_521_mont_sqr_9(t1, t2, p521_mod, p521_mp_mod);
  33451. /* 0x7 */
  33452. sp_521_mont_mul_9(t3, t1, a, p521_mod, p521_mp_mod);
  33453. /* 0xc */
  33454. sp_521_mont_sqr_n_9(t1, t2, 2, p521_mod, p521_mp_mod);
  33455. /* 0xf */
  33456. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33457. /* 0x78 */
  33458. sp_521_mont_sqr_n_9(t1, t2, 3, p521_mod, p521_mp_mod);
  33459. /* 0x7f */
  33460. sp_521_mont_mul_9(t3, t3, t1, p521_mod, p521_mp_mod);
  33461. /* 0xf0 */
  33462. sp_521_mont_sqr_n_9(t1, t2, 4, p521_mod, p521_mp_mod);
  33463. /* 0xff */
  33464. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33465. /* 0xff00 */
  33466. sp_521_mont_sqr_n_9(t1, t2, 8, p521_mod, p521_mp_mod);
  33467. /* 0xffff */
  33468. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33469. /* 0xffff0000 */
  33470. sp_521_mont_sqr_n_9(t1, t2, 16, p521_mod, p521_mp_mod);
  33471. /* 0xffffffff */
  33472. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33473. /* 0xffffffff00000000 */
  33474. sp_521_mont_sqr_n_9(t1, t2, 32, p521_mod, p521_mp_mod);
  33475. /* 0xffffffffffffffff */
  33476. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33477. /* 0xffffffffffffffff0000000000000000 */
  33478. sp_521_mont_sqr_n_9(t1, t2, 64, p521_mod, p521_mp_mod);
  33479. /* 0xffffffffffffffffffffffffffffffff */
  33480. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33481. /* 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000 */
  33482. sp_521_mont_sqr_n_9(t1, t2, 128, p521_mod, p521_mp_mod);
  33483. /* 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
  33484. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33485. /* 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000 */
  33486. sp_521_mont_sqr_n_9(t1, t2, 256, p521_mod, p521_mp_mod);
  33487. /* 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
  33488. sp_521_mont_mul_9(t2, t2, t1, p521_mod, p521_mp_mod);
  33489. /* 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80 */
  33490. sp_521_mont_sqr_n_9(t1, t2, 7, p521_mod, p521_mp_mod);
  33491. /* 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff */
  33492. sp_521_mont_mul_9(t2, t3, t1, p521_mod, p521_mp_mod);
  33493. /* 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc */
  33494. sp_521_mont_sqr_n_9(t1, t2, 2, p521_mod, p521_mp_mod);
  33495. /* 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd */
  33496. sp_521_mont_mul_9(r, t1, a, p521_mod, p521_mp_mod);
  33497. #endif /* WOLFSSL_SP_SMALL */
  33498. }
  33499. /* Map the Montgomery form projective coordinate point to an affine point.
  33500. *
  33501. * r Resulting affine coordinate point.
  33502. * p Montgomery form projective coordinate point.
  33503. * t Temporary ordinate data.
  33504. */
  33505. static void sp_521_map_9(sp_point_521* r, const sp_point_521* p,
  33506. sp_digit* t)
  33507. {
  33508. sp_digit* t1 = t;
  33509. sp_digit* t2 = t + 2*9;
  33510. sp_int64 n;
  33511. sp_521_mont_inv_9(t1, p->z, t + 2*9);
  33512. sp_521_mont_sqr_9(t2, t1, p521_mod, p521_mp_mod);
  33513. sp_521_mont_mul_9(t1, t2, t1, p521_mod, p521_mp_mod);
  33514. /* x /= z^2 */
  33515. sp_521_mont_mul_9(r->x, p->x, t2, p521_mod, p521_mp_mod);
  33516. XMEMSET(r->x + 9, 0, sizeof(sp_digit) * 9U);
  33517. sp_521_mont_reduce_9(r->x, p521_mod, p521_mp_mod);
  33518. /* Reduce x to less than modulus */
  33519. n = sp_521_cmp_9(r->x, p521_mod);
  33520. sp_521_cond_sub_9(r->x, r->x, p521_mod, ~(n >> 57));
  33521. sp_521_norm_9(r->x);
  33522. /* y /= z^3 */
  33523. sp_521_mont_mul_9(r->y, p->y, t1, p521_mod, p521_mp_mod);
  33524. XMEMSET(r->y + 9, 0, sizeof(sp_digit) * 9U);
  33525. sp_521_mont_reduce_9(r->y, p521_mod, p521_mp_mod);
  33526. /* Reduce y to less than modulus */
  33527. n = sp_521_cmp_9(r->y, p521_mod);
  33528. sp_521_cond_sub_9(r->y, r->y, p521_mod, ~(n >> 57));
  33529. sp_521_norm_9(r->y);
  33530. XMEMSET(r->z, 0, sizeof(r->z) / 2);
  33531. r->z[0] = 1;
  33532. }
  33533. /* Add two Montgomery form numbers (r = a + b % m).
  33534. *
  33535. * r Result of addition.
  33536. * a First number to add in Montgomery form.
  33537. * b Second number to add in Montgomery form.
  33538. * m Modulus (prime).
  33539. */
  33540. static void sp_521_mont_add_9(sp_digit* r, const sp_digit* a, const sp_digit* b,
  33541. const sp_digit* m)
  33542. {
  33543. sp_digit over;
  33544. (void)sp_521_add_9(r, a, b);
  33545. sp_521_norm_9(r);
  33546. over = r[8] >> 57;
  33547. sp_521_cond_sub_9(r, r, m, ~((over - 1) >> 63));
  33548. sp_521_norm_9(r);
  33549. }
  33550. /* Double a Montgomery form number (r = a + a % m).
  33551. *
  33552. * r Result of doubling.
  33553. * a Number to double in Montgomery form.
  33554. * m Modulus (prime).
  33555. */
  33556. static void sp_521_mont_dbl_9(sp_digit* r, const sp_digit* a, const sp_digit* m)
  33557. {
  33558. sp_digit over;
  33559. (void)sp_521_add_9(r, a, a);
  33560. sp_521_norm_9(r);
  33561. over = r[8] >> 57;
  33562. sp_521_cond_sub_9(r, r, m, ~((over - 1) >> 63));
  33563. sp_521_norm_9(r);
  33564. }
  33565. /* Triple a Montgomery form number (r = a + a + a % m).
  33566. *
  33567. * r Result of Tripling.
  33568. * a Number to triple in Montgomery form.
  33569. * m Modulus (prime).
  33570. */
  33571. static void sp_521_mont_tpl_9(sp_digit* r, const sp_digit* a, const sp_digit* m)
  33572. {
  33573. sp_digit over;
  33574. (void)sp_521_add_9(r, a, a);
  33575. sp_521_norm_9(r);
  33576. over = r[8] >> 57;
  33577. sp_521_cond_sub_9(r, r, m, ~((over - 1) >> 63));
  33578. sp_521_norm_9(r);
  33579. (void)sp_521_add_9(r, r, a);
  33580. sp_521_norm_9(r);
  33581. over = r[8] >> 57;
  33582. sp_521_cond_sub_9(r, r, m, ~((over - 1) >> 63));
  33583. sp_521_norm_9(r);
  33584. }
  33585. #ifdef WOLFSSL_SP_SMALL
  33586. /* Conditionally add a and b using the mask m.
  33587. * m is -1 to add and 0 when not.
  33588. *
  33589. * r A single precision number representing conditional add result.
  33590. * a A single precision number to add with.
  33591. * b A single precision number to add.
  33592. * m Mask value to apply.
  33593. */
  33594. static void sp_521_cond_add_9(sp_digit* r, const sp_digit* a,
  33595. const sp_digit* b, const sp_digit m)
  33596. {
  33597. int i;
  33598. for (i = 0; i < 9; i++) {
  33599. r[i] = a[i] + (b[i] & m);
  33600. }
  33601. }
  33602. #endif /* WOLFSSL_SP_SMALL */
  33603. #ifndef WOLFSSL_SP_SMALL
  33604. /* Conditionally add a and b using the mask m.
  33605. * m is -1 to add and 0 when not.
  33606. *
  33607. * r A single precision number representing conditional add result.
  33608. * a A single precision number to add with.
  33609. * b A single precision number to add.
  33610. * m Mask value to apply.
  33611. */
  33612. static void sp_521_cond_add_9(sp_digit* r, const sp_digit* a,
  33613. const sp_digit* b, const sp_digit m)
  33614. {
  33615. r[ 0] = a[ 0] + (b[ 0] & m);
  33616. r[ 1] = a[ 1] + (b[ 1] & m);
  33617. r[ 2] = a[ 2] + (b[ 2] & m);
  33618. r[ 3] = a[ 3] + (b[ 3] & m);
  33619. r[ 4] = a[ 4] + (b[ 4] & m);
  33620. r[ 5] = a[ 5] + (b[ 5] & m);
  33621. r[ 6] = a[ 6] + (b[ 6] & m);
  33622. r[ 7] = a[ 7] + (b[ 7] & m);
  33623. r[ 8] = a[ 8] + (b[ 8] & m);
  33624. }
  33625. #endif /* !WOLFSSL_SP_SMALL */
  33626. /* Subtract two Montgomery form numbers (r = a - b % m).
  33627. *
  33628. * r Result of subtration.
  33629. * a Number to subtract from in Montgomery form.
  33630. * b Number to subtract with in Montgomery form.
  33631. * m Modulus (prime).
  33632. */
  33633. static void sp_521_mont_sub_9(sp_digit* r, const sp_digit* a, const sp_digit* b,
  33634. const sp_digit* m)
  33635. {
  33636. (void)sp_521_sub_9(r, a, b);
  33637. sp_521_norm_9(r);
  33638. sp_521_cond_add_9(r, r, m, r[8] >> 57);
  33639. sp_521_norm_9(r);
  33640. }
  33641. /* Shift number left one bit.
  33642. * Bottom bit is lost.
  33643. *
  33644. * r Result of shift.
  33645. * a Number to shift.
  33646. */
  33647. SP_NOINLINE static void sp_521_rshift1_9(sp_digit* r, const sp_digit* a)
  33648. {
  33649. #ifdef WOLFSSL_SP_SMALL
  33650. int i;
  33651. for (i=0; i<8; i++) {
  33652. r[i] = (a[i] >> 1) + ((a[i + 1] << 57) & 0x3ffffffffffffffL);
  33653. }
  33654. #else
  33655. r[0] = (a[0] >> 1) + ((a[1] << 57) & 0x3ffffffffffffffL);
  33656. r[1] = (a[1] >> 1) + ((a[2] << 57) & 0x3ffffffffffffffL);
  33657. r[2] = (a[2] >> 1) + ((a[3] << 57) & 0x3ffffffffffffffL);
  33658. r[3] = (a[3] >> 1) + ((a[4] << 57) & 0x3ffffffffffffffL);
  33659. r[4] = (a[4] >> 1) + ((a[5] << 57) & 0x3ffffffffffffffL);
  33660. r[5] = (a[5] >> 1) + ((a[6] << 57) & 0x3ffffffffffffffL);
  33661. r[6] = (a[6] >> 1) + ((a[7] << 57) & 0x3ffffffffffffffL);
  33662. r[7] = (a[7] >> 1) + ((a[8] << 57) & 0x3ffffffffffffffL);
  33663. #endif
  33664. r[8] = a[8] >> 1;
  33665. }
  33666. /* Divide the number by 2 mod the modulus (prime). (r = a / 2 % m)
  33667. *
  33668. * r Result of division by 2.
  33669. * a Number to divide.
  33670. * m Modulus (prime).
  33671. */
  33672. static void sp_521_mont_div2_9(sp_digit* r, const sp_digit* a,
  33673. const sp_digit* m)
  33674. {
  33675. sp_521_cond_add_9(r, a, m, 0 - (a[0] & 1));
  33676. sp_521_norm_9(r);
  33677. sp_521_rshift1_9(r, r);
  33678. }
  33679. /* Double the Montgomery form projective point p.
  33680. *
  33681. * r Result of doubling point.
  33682. * p Point to double.
  33683. * t Temporary ordinate data.
  33684. */
  33685. static void sp_521_proj_point_dbl_9(sp_point_521* r, const sp_point_521* p,
  33686. sp_digit* t)
  33687. {
  33688. sp_digit* t1 = t;
  33689. sp_digit* t2 = t + 2*9;
  33690. sp_digit* x;
  33691. sp_digit* y;
  33692. sp_digit* z;
  33693. x = r->x;
  33694. y = r->y;
  33695. z = r->z;
  33696. /* Put infinity into result. */
  33697. if (r != p) {
  33698. r->infinity = p->infinity;
  33699. }
  33700. /* T1 = Z * Z */
  33701. sp_521_mont_sqr_9(t1, p->z, p521_mod, p521_mp_mod);
  33702. /* Z = Y * Z */
  33703. sp_521_mont_mul_9(z, p->y, p->z, p521_mod, p521_mp_mod);
  33704. /* Z = 2Z */
  33705. sp_521_mont_dbl_9(z, z, p521_mod);
  33706. /* T2 = X - T1 */
  33707. sp_521_mont_sub_9(t2, p->x, t1, p521_mod);
  33708. /* T1 = X + T1 */
  33709. sp_521_mont_add_9(t1, p->x, t1, p521_mod);
  33710. /* T2 = T1 * T2 */
  33711. sp_521_mont_mul_9(t2, t1, t2, p521_mod, p521_mp_mod);
  33712. /* T1 = 3T2 */
  33713. sp_521_mont_tpl_9(t1, t2, p521_mod);
  33714. /* Y = 2Y */
  33715. sp_521_mont_dbl_9(y, p->y, p521_mod);
  33716. /* Y = Y * Y */
  33717. sp_521_mont_sqr_9(y, y, p521_mod, p521_mp_mod);
  33718. /* T2 = Y * Y */
  33719. sp_521_mont_sqr_9(t2, y, p521_mod, p521_mp_mod);
  33720. /* T2 = T2/2 */
  33721. sp_521_mont_div2_9(t2, t2, p521_mod);
  33722. /* Y = Y * X */
  33723. sp_521_mont_mul_9(y, y, p->x, p521_mod, p521_mp_mod);
  33724. /* X = T1 * T1 */
  33725. sp_521_mont_sqr_9(x, t1, p521_mod, p521_mp_mod);
  33726. /* X = X - Y */
  33727. sp_521_mont_sub_9(x, x, y, p521_mod);
  33728. /* X = X - Y */
  33729. sp_521_mont_sub_9(x, x, y, p521_mod);
  33730. /* Y = Y - X */
  33731. sp_521_mont_sub_9(y, y, x, p521_mod);
  33732. /* Y = Y * T1 */
  33733. sp_521_mont_mul_9(y, y, t1, p521_mod, p521_mp_mod);
  33734. /* Y = Y - T2 */
  33735. sp_521_mont_sub_9(y, y, t2, p521_mod);
  33736. }
  33737. #ifdef WOLFSSL_SP_NONBLOCK
  33738. typedef struct sp_521_proj_point_dbl_9_ctx {
  33739. int state;
  33740. sp_digit* t1;
  33741. sp_digit* t2;
  33742. sp_digit* x;
  33743. sp_digit* y;
  33744. sp_digit* z;
  33745. } sp_521_proj_point_dbl_9_ctx;
  33746. /* Double the Montgomery form projective point p.
  33747. *
  33748. * r Result of doubling point.
  33749. * p Point to double.
  33750. * t Temporary ordinate data.
  33751. */
  33752. static int sp_521_proj_point_dbl_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
  33753. const sp_point_521* p, sp_digit* t)
  33754. {
  33755. int err = FP_WOULDBLOCK;
  33756. sp_521_proj_point_dbl_9_ctx* ctx = (sp_521_proj_point_dbl_9_ctx*)sp_ctx->data;
  33757. typedef char ctx_size_test[sizeof(sp_521_proj_point_dbl_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  33758. (void)sizeof(ctx_size_test);
  33759. switch (ctx->state) {
  33760. case 0:
  33761. ctx->t1 = t;
  33762. ctx->t2 = t + 2*9;
  33763. ctx->x = r->x;
  33764. ctx->y = r->y;
  33765. ctx->z = r->z;
  33766. /* Put infinity into result. */
  33767. if (r != p) {
  33768. r->infinity = p->infinity;
  33769. }
  33770. ctx->state = 1;
  33771. break;
  33772. case 1:
  33773. /* T1 = Z * Z */
  33774. sp_521_mont_sqr_9(ctx->t1, p->z, p521_mod, p521_mp_mod);
  33775. ctx->state = 2;
  33776. break;
  33777. case 2:
  33778. /* Z = Y * Z */
  33779. sp_521_mont_mul_9(ctx->z, p->y, p->z, p521_mod, p521_mp_mod);
  33780. ctx->state = 3;
  33781. break;
  33782. case 3:
  33783. /* Z = 2Z */
  33784. sp_521_mont_dbl_9(ctx->z, ctx->z, p521_mod);
  33785. ctx->state = 4;
  33786. break;
  33787. case 4:
  33788. /* T2 = X - T1 */
  33789. sp_521_mont_sub_9(ctx->t2, p->x, ctx->t1, p521_mod);
  33790. ctx->state = 5;
  33791. break;
  33792. case 5:
  33793. /* T1 = X + T1 */
  33794. sp_521_mont_add_9(ctx->t1, p->x, ctx->t1, p521_mod);
  33795. ctx->state = 6;
  33796. break;
  33797. case 6:
  33798. /* T2 = T1 * T2 */
  33799. sp_521_mont_mul_9(ctx->t2, ctx->t1, ctx->t2, p521_mod, p521_mp_mod);
  33800. ctx->state = 7;
  33801. break;
  33802. case 7:
  33803. /* T1 = 3T2 */
  33804. sp_521_mont_tpl_9(ctx->t1, ctx->t2, p521_mod);
  33805. ctx->state = 8;
  33806. break;
  33807. case 8:
  33808. /* Y = 2Y */
  33809. sp_521_mont_dbl_9(ctx->y, p->y, p521_mod);
  33810. ctx->state = 9;
  33811. break;
  33812. case 9:
  33813. /* Y = Y * Y */
  33814. sp_521_mont_sqr_9(ctx->y, ctx->y, p521_mod, p521_mp_mod);
  33815. ctx->state = 10;
  33816. break;
  33817. case 10:
  33818. /* T2 = Y * Y */
  33819. sp_521_mont_sqr_9(ctx->t2, ctx->y, p521_mod, p521_mp_mod);
  33820. ctx->state = 11;
  33821. break;
  33822. case 11:
  33823. /* T2 = T2/2 */
  33824. sp_521_mont_div2_9(ctx->t2, ctx->t2, p521_mod);
  33825. ctx->state = 12;
  33826. break;
  33827. case 12:
  33828. /* Y = Y * X */
  33829. sp_521_mont_mul_9(ctx->y, ctx->y, p->x, p521_mod, p521_mp_mod);
  33830. ctx->state = 13;
  33831. break;
  33832. case 13:
  33833. /* X = T1 * T1 */
  33834. sp_521_mont_sqr_9(ctx->x, ctx->t1, p521_mod, p521_mp_mod);
  33835. ctx->state = 14;
  33836. break;
  33837. case 14:
  33838. /* X = X - Y */
  33839. sp_521_mont_sub_9(ctx->x, ctx->x, ctx->y, p521_mod);
  33840. ctx->state = 15;
  33841. break;
  33842. case 15:
  33843. /* X = X - Y */
  33844. sp_521_mont_sub_9(ctx->x, ctx->x, ctx->y, p521_mod);
  33845. ctx->state = 16;
  33846. break;
  33847. case 16:
  33848. /* Y = Y - X */
  33849. sp_521_mont_sub_9(ctx->y, ctx->y, ctx->x, p521_mod);
  33850. ctx->state = 17;
  33851. break;
  33852. case 17:
  33853. /* Y = Y * T1 */
  33854. sp_521_mont_mul_9(ctx->y, ctx->y, ctx->t1, p521_mod, p521_mp_mod);
  33855. ctx->state = 18;
  33856. break;
  33857. case 18:
  33858. /* Y = Y - T2 */
  33859. sp_521_mont_sub_9(ctx->y, ctx->y, ctx->t2, p521_mod);
  33860. ctx->state = 19;
  33861. /* fall-through */
  33862. case 19:
  33863. err = MP_OKAY;
  33864. break;
  33865. }
  33866. if (err == MP_OKAY && ctx->state != 19) {
  33867. err = FP_WOULDBLOCK;
  33868. }
  33869. return err;
  33870. }
  33871. #endif /* WOLFSSL_SP_NONBLOCK */
  33872. /* Compare two numbers to determine if they are equal.
  33873. * Constant time implementation.
  33874. *
  33875. * a First number to compare.
  33876. * b Second number to compare.
  33877. * returns 1 when equal and 0 otherwise.
  33878. */
  33879. static int sp_521_cmp_equal_9(const sp_digit* a, const sp_digit* b)
  33880. {
  33881. return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) |
  33882. (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) |
  33883. (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8])) == 0;
  33884. }
  33885. /* Returns 1 if the number of zero.
  33886. * Implementation is constant time.
  33887. *
  33888. * a Number to check.
  33889. * returns 1 if the number is zero and 0 otherwise.
  33890. */
  33891. static int sp_521_iszero_9(const sp_digit* a)
  33892. {
  33893. return (a[0] | a[1] | a[2] | a[3] | a[4] | a[5] | a[6] | a[7] |
  33894. a[8]) == 0;
  33895. }
  33896. /* Add two Montgomery form projective points.
  33897. *
  33898. * r Result of addition.
  33899. * p First point to add.
  33900. * q Second point to add.
  33901. * t Temporary ordinate data.
  33902. */
  33903. static void sp_521_proj_point_add_9(sp_point_521* r,
  33904. const sp_point_521* p, const sp_point_521* q, sp_digit* t)
  33905. {
  33906. sp_digit* t6 = t;
  33907. sp_digit* t1 = t + 2*9;
  33908. sp_digit* t2 = t + 4*9;
  33909. sp_digit* t3 = t + 6*9;
  33910. sp_digit* t4 = t + 8*9;
  33911. sp_digit* t5 = t + 10*9;
  33912. /* U1 = X1*Z2^2 */
  33913. sp_521_mont_sqr_9(t1, q->z, p521_mod, p521_mp_mod);
  33914. sp_521_mont_mul_9(t3, t1, q->z, p521_mod, p521_mp_mod);
  33915. sp_521_mont_mul_9(t1, t1, p->x, p521_mod, p521_mp_mod);
  33916. /* U2 = X2*Z1^2 */
  33917. sp_521_mont_sqr_9(t2, p->z, p521_mod, p521_mp_mod);
  33918. sp_521_mont_mul_9(t4, t2, p->z, p521_mod, p521_mp_mod);
  33919. sp_521_mont_mul_9(t2, t2, q->x, p521_mod, p521_mp_mod);
  33920. /* S1 = Y1*Z2^3 */
  33921. sp_521_mont_mul_9(t3, t3, p->y, p521_mod, p521_mp_mod);
  33922. /* S2 = Y2*Z1^3 */
  33923. sp_521_mont_mul_9(t4, t4, q->y, p521_mod, p521_mp_mod);
  33924. /* Check double */
  33925. if ((~p->infinity) & (~q->infinity) &
  33926. sp_521_cmp_equal_9(t2, t1) &
  33927. sp_521_cmp_equal_9(t4, t3)) {
  33928. sp_521_proj_point_dbl_9(r, p, t);
  33929. }
  33930. else {
  33931. sp_digit* x = t6;
  33932. sp_digit* y = t1;
  33933. sp_digit* z = t2;
  33934. /* H = U2 - U1 */
  33935. sp_521_mont_sub_9(t2, t2, t1, p521_mod);
  33936. /* R = S2 - S1 */
  33937. sp_521_mont_sub_9(t4, t4, t3, p521_mod);
  33938. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  33939. sp_521_mont_sqr_9(t5, t2, p521_mod, p521_mp_mod);
  33940. sp_521_mont_mul_9(y, t1, t5, p521_mod, p521_mp_mod);
  33941. sp_521_mont_mul_9(t5, t5, t2, p521_mod, p521_mp_mod);
  33942. /* Z3 = H*Z1*Z2 */
  33943. sp_521_mont_mul_9(z, p->z, t2, p521_mod, p521_mp_mod);
  33944. sp_521_mont_mul_9(z, z, q->z, p521_mod, p521_mp_mod);
  33945. sp_521_mont_sqr_9(x, t4, p521_mod, p521_mp_mod);
  33946. sp_521_mont_sub_9(x, x, t5, p521_mod);
  33947. sp_521_mont_mul_9(t5, t5, t3, p521_mod, p521_mp_mod);
  33948. sp_521_mont_dbl_9(t3, y, p521_mod);
  33949. sp_521_mont_sub_9(x, x, t3, p521_mod);
  33950. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  33951. sp_521_mont_sub_9(y, y, x, p521_mod);
  33952. sp_521_mont_mul_9(y, y, t4, p521_mod, p521_mp_mod);
  33953. sp_521_mont_sub_9(y, y, t5, p521_mod);
  33954. {
  33955. int i;
  33956. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  33957. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  33958. sp_digit maskt = ~(maskp | maskq);
  33959. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  33960. for (i = 0; i < 9; i++) {
  33961. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  33962. (x[i] & maskt);
  33963. }
  33964. for (i = 0; i < 9; i++) {
  33965. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  33966. (y[i] & maskt);
  33967. }
  33968. for (i = 0; i < 9; i++) {
  33969. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  33970. (z[i] & maskt);
  33971. }
  33972. r->z[0] |= inf;
  33973. r->infinity = (word32)inf;
  33974. }
  33975. }
  33976. }
  33977. #ifdef WOLFSSL_SP_NONBLOCK
  33978. typedef struct sp_521_proj_point_add_9_ctx {
  33979. int state;
  33980. sp_521_proj_point_dbl_9_ctx dbl_ctx;
  33981. const sp_point_521* ap[2];
  33982. sp_point_521* rp[2];
  33983. sp_digit* t1;
  33984. sp_digit* t2;
  33985. sp_digit* t3;
  33986. sp_digit* t4;
  33987. sp_digit* t5;
  33988. sp_digit* t6;
  33989. sp_digit* x;
  33990. sp_digit* y;
  33991. sp_digit* z;
  33992. } sp_521_proj_point_add_9_ctx;
  33993. /* Add two Montgomery form projective points.
  33994. *
  33995. * r Result of addition.
  33996. * p First point to add.
  33997. * q Second point to add.
  33998. * t Temporary ordinate data.
  33999. */
  34000. static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
  34001. const sp_point_521* p, const sp_point_521* q, sp_digit* t)
  34002. {
  34003. int err = FP_WOULDBLOCK;
  34004. sp_521_proj_point_add_9_ctx* ctx = (sp_521_proj_point_add_9_ctx*)sp_ctx->data;
  34005. /* Ensure only the first point is the same as the result. */
  34006. if (q == r) {
  34007. const sp_point_521* a = p;
  34008. p = q;
  34009. q = a;
  34010. }
  34011. typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  34012. (void)sizeof(ctx_size_test);
  34013. switch (ctx->state) {
  34014. case 0: /* INIT */
  34015. ctx->t6 = t;
  34016. ctx->t1 = t + 2*9;
  34017. ctx->t2 = t + 4*9;
  34018. ctx->t3 = t + 6*9;
  34019. ctx->t4 = t + 8*9;
  34020. ctx->t5 = t + 10*9;
  34021. ctx->x = ctx->t6;
  34022. ctx->y = ctx->t1;
  34023. ctx->z = ctx->t2;
  34024. ctx->state = 1;
  34025. break;
  34026. case 1:
  34027. /* U1 = X1*Z2^2 */
  34028. sp_521_mont_sqr_9(ctx->t1, q->z, p521_mod, p521_mp_mod);
  34029. ctx->state = 2;
  34030. break;
  34031. case 2:
  34032. sp_521_mont_mul_9(ctx->t3, ctx->t1, q->z, p521_mod, p521_mp_mod);
  34033. ctx->state = 3;
  34034. break;
  34035. case 3:
  34036. sp_521_mont_mul_9(ctx->t1, ctx->t1, p->x, p521_mod, p521_mp_mod);
  34037. ctx->state = 4;
  34038. break;
  34039. case 4:
  34040. /* U2 = X2*Z1^2 */
  34041. sp_521_mont_sqr_9(ctx->t2, p->z, p521_mod, p521_mp_mod);
  34042. ctx->state = 5;
  34043. break;
  34044. case 5:
  34045. sp_521_mont_mul_9(ctx->t4, ctx->t2, p->z, p521_mod, p521_mp_mod);
  34046. ctx->state = 6;
  34047. break;
  34048. case 6:
  34049. sp_521_mont_mul_9(ctx->t2, ctx->t2, q->x, p521_mod, p521_mp_mod);
  34050. ctx->state = 7;
  34051. break;
  34052. case 7:
  34053. /* S1 = Y1*Z2^3 */
  34054. sp_521_mont_mul_9(ctx->t3, ctx->t3, p->y, p521_mod, p521_mp_mod);
  34055. ctx->state = 8;
  34056. break;
  34057. case 8:
  34058. /* S2 = Y2*Z1^3 */
  34059. sp_521_mont_mul_9(ctx->t4, ctx->t4, q->y, p521_mod, p521_mp_mod);
  34060. ctx->state = 9;
  34061. break;
  34062. case 9:
  34063. /* Check double */
  34064. if ((~p->infinity) & (~q->infinity) &
  34065. sp_521_cmp_equal_9(ctx->t2, ctx->t1) &
  34066. sp_521_cmp_equal_9(ctx->t4, ctx->t3)) {
  34067. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  34068. sp_521_proj_point_dbl_9(r, p, t);
  34069. ctx->state = 25;
  34070. }
  34071. else {
  34072. ctx->state = 10;
  34073. }
  34074. break;
  34075. case 10:
  34076. /* H = U2 - U1 */
  34077. sp_521_mont_sub_9(ctx->t2, ctx->t2, ctx->t1, p521_mod);
  34078. ctx->state = 11;
  34079. break;
  34080. case 11:
  34081. /* R = S2 - S1 */
  34082. sp_521_mont_sub_9(ctx->t4, ctx->t4, ctx->t3, p521_mod);
  34083. ctx->state = 12;
  34084. break;
  34085. case 12:
  34086. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  34087. sp_521_mont_sqr_9(ctx->t5, ctx->t2, p521_mod, p521_mp_mod);
  34088. ctx->state = 13;
  34089. break;
  34090. case 13:
  34091. sp_521_mont_mul_9(ctx->y, ctx->t1, ctx->t5, p521_mod, p521_mp_mod);
  34092. ctx->state = 14;
  34093. break;
  34094. case 14:
  34095. sp_521_mont_mul_9(ctx->t5, ctx->t5, ctx->t2, p521_mod, p521_mp_mod);
  34096. ctx->state = 15;
  34097. break;
  34098. case 15:
  34099. /* Z3 = H*Z1*Z2 */
  34100. sp_521_mont_mul_9(ctx->z, p->z, ctx->t2, p521_mod, p521_mp_mod);
  34101. ctx->state = 16;
  34102. break;
  34103. case 16:
  34104. sp_521_mont_mul_9(ctx->z, ctx->z, q->z, p521_mod, p521_mp_mod);
  34105. ctx->state = 17;
  34106. break;
  34107. case 17:
  34108. sp_521_mont_sqr_9(ctx->x, ctx->t4, p521_mod, p521_mp_mod);
  34109. ctx->state = 18;
  34110. break;
  34111. case 18:
  34112. sp_521_mont_sub_9(ctx->x, ctx->x, ctx->t5, p521_mod);
  34113. ctx->state = 19;
  34114. break;
  34115. case 19:
  34116. sp_521_mont_mul_9(ctx->t5, ctx->t5, ctx->t3, p521_mod, p521_mp_mod);
  34117. ctx->state = 20;
  34118. break;
  34119. case 20:
  34120. sp_521_mont_dbl_9(ctx->t3, ctx->y, p521_mod);
  34121. sp_521_mont_sub_9(ctx->x, ctx->x, ctx->t3, p521_mod);
  34122. ctx->state = 21;
  34123. break;
  34124. case 21:
  34125. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  34126. sp_521_mont_sub_9(ctx->y, ctx->y, ctx->x, p521_mod);
  34127. ctx->state = 22;
  34128. break;
  34129. case 22:
  34130. sp_521_mont_mul_9(ctx->y, ctx->y, ctx->t4, p521_mod, p521_mp_mod);
  34131. ctx->state = 23;
  34132. break;
  34133. case 23:
  34134. sp_521_mont_sub_9(ctx->y, ctx->y, ctx->t5, p521_mod);
  34135. ctx->state = 24;
  34136. break;
  34137. case 24:
  34138. {
  34139. {
  34140. int i;
  34141. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  34142. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  34143. sp_digit maskt = ~(maskp | maskq);
  34144. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  34145. for (i = 0; i < 9; i++) {
  34146. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  34147. (ctx->x[i] & maskt);
  34148. }
  34149. for (i = 0; i < 9; i++) {
  34150. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  34151. (ctx->y[i] & maskt);
  34152. }
  34153. for (i = 0; i < 9; i++) {
  34154. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  34155. (ctx->z[i] & maskt);
  34156. }
  34157. r->z[0] |= inf;
  34158. r->infinity = (word32)inf;
  34159. }
  34160. ctx->state = 25;
  34161. break;
  34162. }
  34163. case 25:
  34164. err = MP_OKAY;
  34165. break;
  34166. }
  34167. if (err == MP_OKAY && ctx->state != 25) {
  34168. err = FP_WOULDBLOCK;
  34169. }
  34170. return err;
  34171. }
  34172. #endif /* WOLFSSL_SP_NONBLOCK */
  34173. /* Multiply a number by Montgomery normalizer mod modulus (prime).
  34174. *
  34175. * r The resulting Montgomery form number.
  34176. * a The number to convert.
  34177. * m The modulus (prime).
  34178. * returns MEMORY_E when memory allocation fails and MP_OKAY otherwise.
  34179. */
  34180. static int sp_521_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit* m)
  34181. {
  34182. (void)m;
  34183. if (r != a) {
  34184. XMEMCPY(r, a, 9 * sizeof(sp_digit));
  34185. }
  34186. return MP_OKAY;
  34187. }
  34188. #ifdef WOLFSSL_SP_SMALL
  34189. /* Multiply the point by the scalar and return the result.
  34190. * If map is true then convert result to affine coordinates.
  34191. *
  34192. * Small implementation using add and double that is cache attack resistant but
  34193. * allocates memory rather than use large stacks.
  34194. * 521 adds and doubles.
  34195. *
  34196. * r Resulting point.
  34197. * g Point to multiply.
  34198. * k Scalar to multiply by.
  34199. * map Indicates whether to convert result to affine.
  34200. * ct Constant time required.
  34201. * heap Heap to use for allocation.
  34202. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  34203. */
  34204. static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g,
  34205. const sp_digit* k, int map, int ct, void* heap)
  34206. {
  34207. #ifdef WOLFSSL_SP_SMALL_STACK
  34208. sp_point_521* t = NULL;
  34209. sp_digit* tmp = NULL;
  34210. #else
  34211. sp_point_521 t[3];
  34212. sp_digit tmp[2 * 9 * 6];
  34213. #endif
  34214. sp_digit n;
  34215. int i;
  34216. int c;
  34217. int y;
  34218. int err = MP_OKAY;
  34219. /* Implementation is constant time. */
  34220. (void)ct;
  34221. (void)heap;
  34222. #ifdef WOLFSSL_SP_SMALL_STACK
  34223. t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap,
  34224. DYNAMIC_TYPE_ECC);
  34225. if (t == NULL)
  34226. err = MEMORY_E;
  34227. if (err == MP_OKAY) {
  34228. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap,
  34229. DYNAMIC_TYPE_ECC);
  34230. if (tmp == NULL)
  34231. err = MEMORY_E;
  34232. }
  34233. #endif
  34234. if (err == MP_OKAY) {
  34235. XMEMSET(t, 0, sizeof(sp_point_521) * 3);
  34236. /* t[0] = {0, 0, 1} * norm */
  34237. t[0].infinity = 1;
  34238. /* t[1] = {g->x, g->y, g->z} * norm */
  34239. err = sp_521_mod_mul_norm_9(t[1].x, g->x, p521_mod);
  34240. }
  34241. if (err == MP_OKAY)
  34242. err = sp_521_mod_mul_norm_9(t[1].y, g->y, p521_mod);
  34243. if (err == MP_OKAY)
  34244. err = sp_521_mod_mul_norm_9(t[1].z, g->z, p521_mod);
  34245. if (err == MP_OKAY) {
  34246. i = 8;
  34247. c = 57;
  34248. n = k[i--] << (58 - c);
  34249. for (; ; c--) {
  34250. if (c == 0) {
  34251. if (i == -1)
  34252. break;
  34253. n = k[i--];
  34254. c = 58;
  34255. }
  34256. y = (n >> 57) & 1;
  34257. n <<= 1;
  34258. sp_521_proj_point_add_9(&t[y^1], &t[0], &t[1], tmp);
  34259. XMEMCPY(&t[2], (void*)(((size_t)&t[0] & addr_mask[y^1]) +
  34260. ((size_t)&t[1] & addr_mask[y])),
  34261. sizeof(sp_point_521));
  34262. sp_521_proj_point_dbl_9(&t[2], &t[2], tmp);
  34263. XMEMCPY((void*)(((size_t)&t[0] & addr_mask[y^1]) +
  34264. ((size_t)&t[1] & addr_mask[y])), &t[2],
  34265. sizeof(sp_point_521));
  34266. }
  34267. if (map != 0) {
  34268. sp_521_map_9(r, &t[0], tmp);
  34269. }
  34270. else {
  34271. XMEMCPY(r, &t[0], sizeof(sp_point_521));
  34272. }
  34273. }
  34274. #ifdef WOLFSSL_SP_SMALL_STACK
  34275. if (tmp != NULL)
  34276. #endif
  34277. {
  34278. ForceZero(tmp, sizeof(sp_digit) * 2 * 9 * 6);
  34279. #ifdef WOLFSSL_SP_SMALL_STACK
  34280. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  34281. #endif
  34282. }
  34283. #ifdef WOLFSSL_SP_SMALL_STACK
  34284. if (t != NULL)
  34285. #endif
  34286. {
  34287. ForceZero(t, sizeof(sp_point_521) * 3);
  34288. #ifdef WOLFSSL_SP_SMALL_STACK
  34289. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  34290. #endif
  34291. }
  34292. return err;
  34293. }
  34294. #ifdef WOLFSSL_SP_NONBLOCK
  34295. typedef struct sp_521_ecc_mulmod_9_ctx {
  34296. int state;
  34297. union {
  34298. sp_521_proj_point_dbl_9_ctx dbl_ctx;
  34299. sp_521_proj_point_add_9_ctx add_ctx;
  34300. };
  34301. sp_point_521 t[3];
  34302. sp_digit tmp[2 * 9 * 6];
  34303. sp_digit n;
  34304. int i;
  34305. int c;
  34306. int y;
  34307. } sp_521_ecc_mulmod_9_ctx;
  34308. static int sp_521_ecc_mulmod_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
  34309. const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap)
  34310. {
  34311. int err = FP_WOULDBLOCK;
  34312. sp_521_ecc_mulmod_9_ctx* ctx = (sp_521_ecc_mulmod_9_ctx*)sp_ctx->data;
  34313. typedef char ctx_size_test[sizeof(sp_521_ecc_mulmod_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  34314. (void)sizeof(ctx_size_test);
  34315. /* Implementation is constant time. */
  34316. (void)ct;
  34317. switch (ctx->state) {
  34318. case 0: /* INIT */
  34319. XMEMSET(ctx->t, 0, sizeof(sp_point_521) * 3);
  34320. ctx->i = 8;
  34321. ctx->c = 57;
  34322. ctx->n = k[ctx->i--] << (58 - ctx->c);
  34323. /* t[0] = {0, 0, 1} * norm */
  34324. ctx->t[0].infinity = 1;
  34325. ctx->state = 1;
  34326. break;
  34327. case 1: /* T1X */
  34328. /* t[1] = {g->x, g->y, g->z} * norm */
  34329. err = sp_521_mod_mul_norm_9(ctx->t[1].x, g->x, p521_mod);
  34330. ctx->state = 2;
  34331. break;
  34332. case 2: /* T1Y */
  34333. err = sp_521_mod_mul_norm_9(ctx->t[1].y, g->y, p521_mod);
  34334. ctx->state = 3;
  34335. break;
  34336. case 3: /* T1Z */
  34337. err = sp_521_mod_mul_norm_9(ctx->t[1].z, g->z, p521_mod);
  34338. ctx->state = 4;
  34339. break;
  34340. case 4: /* ADDPREP */
  34341. if (ctx->c == 0) {
  34342. if (ctx->i == -1) {
  34343. ctx->state = 7;
  34344. break;
  34345. }
  34346. ctx->n = k[ctx->i--];
  34347. ctx->c = 58;
  34348. }
  34349. ctx->y = (ctx->n >> 57) & 1;
  34350. ctx->n <<= 1;
  34351. XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx));
  34352. ctx->state = 5;
  34353. break;
  34354. case 5: /* ADD */
  34355. err = sp_521_proj_point_add_9_nb((sp_ecc_ctx_t*)&ctx->add_ctx,
  34356. &ctx->t[ctx->y^1], &ctx->t[0], &ctx->t[1], ctx->tmp);
  34357. if (err == MP_OKAY) {
  34358. XMEMCPY(&ctx->t[2], (void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  34359. ((size_t)&ctx->t[1] & addr_mask[ctx->y])),
  34360. sizeof(sp_point_521));
  34361. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  34362. ctx->state = 6;
  34363. }
  34364. break;
  34365. case 6: /* DBL */
  34366. err = sp_521_proj_point_dbl_9_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->t[2],
  34367. &ctx->t[2], ctx->tmp);
  34368. if (err == MP_OKAY) {
  34369. XMEMCPY((void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  34370. ((size_t)&ctx->t[1] & addr_mask[ctx->y])), &ctx->t[2],
  34371. sizeof(sp_point_521));
  34372. ctx->state = 4;
  34373. ctx->c--;
  34374. }
  34375. break;
  34376. case 7: /* MAP */
  34377. if (map != 0) {
  34378. sp_521_map_9(r, &ctx->t[0], ctx->tmp);
  34379. }
  34380. else {
  34381. XMEMCPY(r, &ctx->t[0], sizeof(sp_point_521));
  34382. }
  34383. err = MP_OKAY;
  34384. break;
  34385. }
  34386. if (err == MP_OKAY && ctx->state != 7) {
  34387. err = FP_WOULDBLOCK;
  34388. }
  34389. if (err != FP_WOULDBLOCK) {
  34390. ForceZero(ctx->tmp, sizeof(ctx->tmp));
  34391. ForceZero(ctx->t, sizeof(ctx->t));
  34392. }
  34393. (void)heap;
  34394. return err;
  34395. }
  34396. #endif /* WOLFSSL_SP_NONBLOCK */
  34397. #else
  34398. /* A table entry for pre-computed points. */
  34399. typedef struct sp_table_entry_521 {
  34400. sp_digit x[9];
  34401. sp_digit y[9];
  34402. } sp_table_entry_521;
  34403. /* Conditionally copy a into r using the mask m.
  34404. * m is -1 to copy and 0 when not.
  34405. *
  34406. * r A single precision number to copy over.
  34407. * a A single precision number to copy.
  34408. * m Mask value to apply.
  34409. */
  34410. static void sp_521_cond_copy_9(sp_digit* r, const sp_digit* a, const sp_digit m)
  34411. {
  34412. sp_digit t[9];
  34413. #ifdef WOLFSSL_SP_SMALL
  34414. int i;
  34415. for (i = 0; i < 9; i++) {
  34416. t[i] = r[i] ^ a[i];
  34417. }
  34418. for (i = 0; i < 9; i++) {
  34419. r[i] ^= t[i] & m;
  34420. }
  34421. #else
  34422. t[ 0] = r[ 0] ^ a[ 0];
  34423. t[ 1] = r[ 1] ^ a[ 1];
  34424. t[ 2] = r[ 2] ^ a[ 2];
  34425. t[ 3] = r[ 3] ^ a[ 3];
  34426. t[ 4] = r[ 4] ^ a[ 4];
  34427. t[ 5] = r[ 5] ^ a[ 5];
  34428. t[ 6] = r[ 6] ^ a[ 6];
  34429. t[ 7] = r[ 7] ^ a[ 7];
  34430. t[ 8] = r[ 8] ^ a[ 8];
  34431. r[ 0] ^= t[ 0] & m;
  34432. r[ 1] ^= t[ 1] & m;
  34433. r[ 2] ^= t[ 2] & m;
  34434. r[ 3] ^= t[ 3] & m;
  34435. r[ 4] ^= t[ 4] & m;
  34436. r[ 5] ^= t[ 5] & m;
  34437. r[ 6] ^= t[ 6] & m;
  34438. r[ 7] ^= t[ 7] & m;
  34439. r[ 8] ^= t[ 8] & m;
  34440. #endif /* WOLFSSL_SP_SMALL */
  34441. }
  34442. /* Double the Montgomery form projective point p a number of times.
  34443. *
  34444. * r Result of repeated doubling of point.
  34445. * p Point to double.
  34446. * n Number of times to double
  34447. * t Temporary ordinate data.
  34448. */
  34449. static void sp_521_proj_point_dbl_n_9(sp_point_521* p, int i,
  34450. sp_digit* t)
  34451. {
  34452. sp_digit* w = t;
  34453. sp_digit* a = t + 2*9;
  34454. sp_digit* b = t + 4*9;
  34455. sp_digit* t1 = t + 6*9;
  34456. sp_digit* t2 = t + 8*9;
  34457. sp_digit* x;
  34458. sp_digit* y;
  34459. sp_digit* z;
  34460. volatile int n = i;
  34461. x = p->x;
  34462. y = p->y;
  34463. z = p->z;
  34464. /* Y = 2*Y */
  34465. sp_521_mont_dbl_9(y, y, p521_mod);
  34466. /* W = Z^4 */
  34467. sp_521_mont_sqr_9(w, z, p521_mod, p521_mp_mod);
  34468. sp_521_mont_sqr_9(w, w, p521_mod, p521_mp_mod);
  34469. #ifndef WOLFSSL_SP_SMALL
  34470. while (--n > 0)
  34471. #else
  34472. while (--n >= 0)
  34473. #endif
  34474. {
  34475. /* A = 3*(X^2 - W) */
  34476. sp_521_mont_sqr_9(t1, x, p521_mod, p521_mp_mod);
  34477. sp_521_mont_sub_9(t1, t1, w, p521_mod);
  34478. sp_521_mont_tpl_9(a, t1, p521_mod);
  34479. /* B = X*Y^2 */
  34480. sp_521_mont_sqr_9(t1, y, p521_mod, p521_mp_mod);
  34481. sp_521_mont_mul_9(b, t1, x, p521_mod, p521_mp_mod);
  34482. /* X = A^2 - 2B */
  34483. sp_521_mont_sqr_9(x, a, p521_mod, p521_mp_mod);
  34484. sp_521_mont_dbl_9(t2, b, p521_mod);
  34485. sp_521_mont_sub_9(x, x, t2, p521_mod);
  34486. /* B = 2.(B - X) */
  34487. sp_521_mont_sub_9(t2, b, x, p521_mod);
  34488. sp_521_mont_dbl_9(b, t2, p521_mod);
  34489. /* Z = Z*Y */
  34490. sp_521_mont_mul_9(z, z, y, p521_mod, p521_mp_mod);
  34491. /* t1 = Y^4 */
  34492. sp_521_mont_sqr_9(t1, t1, p521_mod, p521_mp_mod);
  34493. #ifdef WOLFSSL_SP_SMALL
  34494. if (n != 0)
  34495. #endif
  34496. {
  34497. /* W = W*Y^4 */
  34498. sp_521_mont_mul_9(w, w, t1, p521_mod, p521_mp_mod);
  34499. }
  34500. /* y = 2*A*(B - X) - Y^4 */
  34501. sp_521_mont_mul_9(y, b, a, p521_mod, p521_mp_mod);
  34502. sp_521_mont_sub_9(y, y, t1, p521_mod);
  34503. }
  34504. #ifndef WOLFSSL_SP_SMALL
  34505. /* A = 3*(X^2 - W) */
  34506. sp_521_mont_sqr_9(t1, x, p521_mod, p521_mp_mod);
  34507. sp_521_mont_sub_9(t1, t1, w, p521_mod);
  34508. sp_521_mont_tpl_9(a, t1, p521_mod);
  34509. /* B = X*Y^2 */
  34510. sp_521_mont_sqr_9(t1, y, p521_mod, p521_mp_mod);
  34511. sp_521_mont_mul_9(b, t1, x, p521_mod, p521_mp_mod);
  34512. /* X = A^2 - 2B */
  34513. sp_521_mont_sqr_9(x, a, p521_mod, p521_mp_mod);
  34514. sp_521_mont_dbl_9(t2, b, p521_mod);
  34515. sp_521_mont_sub_9(x, x, t2, p521_mod);
  34516. /* B = 2.(B - X) */
  34517. sp_521_mont_sub_9(t2, b, x, p521_mod);
  34518. sp_521_mont_dbl_9(b, t2, p521_mod);
  34519. /* Z = Z*Y */
  34520. sp_521_mont_mul_9(z, z, y, p521_mod, p521_mp_mod);
  34521. /* t1 = Y^4 */
  34522. sp_521_mont_sqr_9(t1, t1, p521_mod, p521_mp_mod);
  34523. /* y = 2*A*(B - X) - Y^4 */
  34524. sp_521_mont_mul_9(y, b, a, p521_mod, p521_mp_mod);
  34525. sp_521_mont_sub_9(y, y, t1, p521_mod);
  34526. #endif /* WOLFSSL_SP_SMALL */
  34527. /* Y = Y/2 */
  34528. sp_521_mont_div2_9(y, y, p521_mod);
  34529. }
  34530. /* Double the Montgomery form projective point p a number of times.
  34531. *
  34532. * r Result of repeated doubling of point.
  34533. * p Point to double.
  34534. * n Number of times to double
  34535. * t Temporary ordinate data.
  34536. */
  34537. static void sp_521_proj_point_dbl_n_store_9(sp_point_521* r,
  34538. const sp_point_521* p, int n, int m, sp_digit* t)
  34539. {
  34540. sp_digit* w = t;
  34541. sp_digit* a = t + 2*9;
  34542. sp_digit* b = t + 4*9;
  34543. sp_digit* t1 = t + 6*9;
  34544. sp_digit* t2 = t + 8*9;
  34545. sp_digit* x = r[2*m].x;
  34546. sp_digit* y = r[(1<<n)*m].y;
  34547. sp_digit* z = r[2*m].z;
  34548. int i;
  34549. int j;
  34550. for (i=0; i<9; i++) {
  34551. x[i] = p->x[i];
  34552. }
  34553. for (i=0; i<9; i++) {
  34554. y[i] = p->y[i];
  34555. }
  34556. for (i=0; i<9; i++) {
  34557. z[i] = p->z[i];
  34558. }
  34559. /* Y = 2*Y */
  34560. sp_521_mont_dbl_9(y, y, p521_mod);
  34561. /* W = Z^4 */
  34562. sp_521_mont_sqr_9(w, z, p521_mod, p521_mp_mod);
  34563. sp_521_mont_sqr_9(w, w, p521_mod, p521_mp_mod);
  34564. j = m;
  34565. for (i=1; i<=n; i++) {
  34566. j *= 2;
  34567. /* A = 3*(X^2 - W) */
  34568. sp_521_mont_sqr_9(t1, x, p521_mod, p521_mp_mod);
  34569. sp_521_mont_sub_9(t1, t1, w, p521_mod);
  34570. sp_521_mont_tpl_9(a, t1, p521_mod);
  34571. /* B = X*Y^2 */
  34572. sp_521_mont_sqr_9(t1, y, p521_mod, p521_mp_mod);
  34573. sp_521_mont_mul_9(b, t1, x, p521_mod, p521_mp_mod);
  34574. x = r[j].x;
  34575. /* X = A^2 - 2B */
  34576. sp_521_mont_sqr_9(x, a, p521_mod, p521_mp_mod);
  34577. sp_521_mont_dbl_9(t2, b, p521_mod);
  34578. sp_521_mont_sub_9(x, x, t2, p521_mod);
  34579. /* B = 2.(B - X) */
  34580. sp_521_mont_sub_9(t2, b, x, p521_mod);
  34581. sp_521_mont_dbl_9(b, t2, p521_mod);
  34582. /* Z = Z*Y */
  34583. sp_521_mont_mul_9(r[j].z, z, y, p521_mod, p521_mp_mod);
  34584. z = r[j].z;
  34585. /* t1 = Y^4 */
  34586. sp_521_mont_sqr_9(t1, t1, p521_mod, p521_mp_mod);
  34587. if (i != n) {
  34588. /* W = W*Y^4 */
  34589. sp_521_mont_mul_9(w, w, t1, p521_mod, p521_mp_mod);
  34590. }
  34591. /* y = 2*A*(B - X) - Y^4 */
  34592. sp_521_mont_mul_9(y, b, a, p521_mod, p521_mp_mod);
  34593. sp_521_mont_sub_9(y, y, t1, p521_mod);
  34594. /* Y = Y/2 */
  34595. sp_521_mont_div2_9(r[j].y, y, p521_mod);
  34596. r[j].infinity = 0;
  34597. }
  34598. }
  34599. /* Add two Montgomery form projective points.
  34600. *
  34601. * ra Result of addition.
  34602. * rs Result of subtraction.
  34603. * p First point to add.
  34604. * q Second point to add.
  34605. * t Temporary ordinate data.
  34606. */
  34607. static void sp_521_proj_point_add_sub_9(sp_point_521* ra,
  34608. sp_point_521* rs, const sp_point_521* p, const sp_point_521* q,
  34609. sp_digit* t)
  34610. {
  34611. sp_digit* t1 = t;
  34612. sp_digit* t2 = t + 2*9;
  34613. sp_digit* t3 = t + 4*9;
  34614. sp_digit* t4 = t + 6*9;
  34615. sp_digit* t5 = t + 8*9;
  34616. sp_digit* t6 = t + 10*9;
  34617. sp_digit* xa = ra->x;
  34618. sp_digit* ya = ra->y;
  34619. sp_digit* za = ra->z;
  34620. sp_digit* xs = rs->x;
  34621. sp_digit* ys = rs->y;
  34622. sp_digit* zs = rs->z;
  34623. XMEMCPY(xa, p->x, sizeof(p->x) / 2);
  34624. XMEMCPY(ya, p->y, sizeof(p->y) / 2);
  34625. XMEMCPY(za, p->z, sizeof(p->z) / 2);
  34626. ra->infinity = 0;
  34627. rs->infinity = 0;
  34628. /* U1 = X1*Z2^2 */
  34629. sp_521_mont_sqr_9(t1, q->z, p521_mod, p521_mp_mod);
  34630. sp_521_mont_mul_9(t3, t1, q->z, p521_mod, p521_mp_mod);
  34631. sp_521_mont_mul_9(t1, t1, xa, p521_mod, p521_mp_mod);
  34632. /* U2 = X2*Z1^2 */
  34633. sp_521_mont_sqr_9(t2, za, p521_mod, p521_mp_mod);
  34634. sp_521_mont_mul_9(t4, t2, za, p521_mod, p521_mp_mod);
  34635. sp_521_mont_mul_9(t2, t2, q->x, p521_mod, p521_mp_mod);
  34636. /* S1 = Y1*Z2^3 */
  34637. sp_521_mont_mul_9(t3, t3, ya, p521_mod, p521_mp_mod);
  34638. /* S2 = Y2*Z1^3 */
  34639. sp_521_mont_mul_9(t4, t4, q->y, p521_mod, p521_mp_mod);
  34640. /* H = U2 - U1 */
  34641. sp_521_mont_sub_9(t2, t2, t1, p521_mod);
  34642. /* RS = S2 + S1 */
  34643. sp_521_mont_add_9(t6, t4, t3, p521_mod);
  34644. /* R = S2 - S1 */
  34645. sp_521_mont_sub_9(t4, t4, t3, p521_mod);
  34646. /* Z3 = H*Z1*Z2 */
  34647. /* ZS = H*Z1*Z2 */
  34648. sp_521_mont_mul_9(za, za, q->z, p521_mod, p521_mp_mod);
  34649. sp_521_mont_mul_9(za, za, t2, p521_mod, p521_mp_mod);
  34650. XMEMCPY(zs, za, sizeof(p->z)/2);
  34651. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  34652. /* XS = RS^2 - H^3 - 2*U1*H^2 */
  34653. sp_521_mont_sqr_9(xa, t4, p521_mod, p521_mp_mod);
  34654. sp_521_mont_sqr_9(xs, t6, p521_mod, p521_mp_mod);
  34655. sp_521_mont_sqr_9(t5, t2, p521_mod, p521_mp_mod);
  34656. sp_521_mont_mul_9(ya, t1, t5, p521_mod, p521_mp_mod);
  34657. sp_521_mont_mul_9(t5, t5, t2, p521_mod, p521_mp_mod);
  34658. sp_521_mont_sub_9(xa, xa, t5, p521_mod);
  34659. sp_521_mont_sub_9(xs, xs, t5, p521_mod);
  34660. sp_521_mont_dbl_9(t1, ya, p521_mod);
  34661. sp_521_mont_sub_9(xa, xa, t1, p521_mod);
  34662. sp_521_mont_sub_9(xs, xs, t1, p521_mod);
  34663. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  34664. /* YS = -RS*(U1*H^2 - XS) - S1*H^3 */
  34665. sp_521_mont_sub_9(ys, ya, xs, p521_mod);
  34666. sp_521_mont_sub_9(ya, ya, xa, p521_mod);
  34667. sp_521_mont_mul_9(ya, ya, t4, p521_mod, p521_mp_mod);
  34668. sp_521_sub_9(t6, p521_mod, t6);
  34669. sp_521_mont_mul_9(ys, ys, t6, p521_mod, p521_mp_mod);
  34670. sp_521_mont_mul_9(t5, t5, t3, p521_mod, p521_mp_mod);
  34671. sp_521_mont_sub_9(ya, ya, t5, p521_mod);
  34672. sp_521_mont_sub_9(ys, ys, t5, p521_mod);
  34673. }
  34674. /* Structure used to describe recoding of scalar multiplication. */
  34675. typedef struct ecc_recode_521 {
  34676. /* Index into pre-computation table. */
  34677. uint8_t i;
  34678. /* Use the negative of the point. */
  34679. uint8_t neg;
  34680. } ecc_recode_521;
  34681. /* The index into pre-computation table to use. */
  34682. static const uint8_t recode_index_9_6[66] = {
  34683. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  34684. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  34685. 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
  34686. 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
  34687. 0, 1,
  34688. };
  34689. /* Whether to negate y-ordinate. */
  34690. static const uint8_t recode_neg_9_6[66] = {
  34691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34693. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  34694. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  34695. 0, 0,
  34696. };
  34697. /* Recode the scalar for multiplication using pre-computed values and
  34698. * subtraction.
  34699. *
  34700. * k Scalar to multiply by.
  34701. * v Vector of operations to perform.
  34702. */
  34703. static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v)
  34704. {
  34705. int i;
  34706. int j;
  34707. uint8_t y;
  34708. int carry = 0;
  34709. int o;
  34710. sp_digit n;
  34711. j = 0;
  34712. n = k[j];
  34713. o = 0;
  34714. for (i=0; i<87; i++) {
  34715. y = (int8_t)n;
  34716. if (o + 6 < 58) {
  34717. y &= 0x3f;
  34718. n >>= 6;
  34719. o += 6;
  34720. }
  34721. else if (o + 6 == 58) {
  34722. n >>= 6;
  34723. if (++j < 9)
  34724. n = k[j];
  34725. o = 0;
  34726. }
  34727. else if (++j < 9) {
  34728. n = k[j];
  34729. y |= (uint8_t)((n << (58 - o)) & 0x3f);
  34730. o -= 52;
  34731. n >>= o;
  34732. }
  34733. y += (uint8_t)carry;
  34734. v[i].i = recode_index_9_6[y];
  34735. v[i].neg = recode_neg_9_6[y];
  34736. carry = (y >> 6) + v[i].neg;
  34737. }
  34738. }
  34739. #ifndef WC_NO_CACHE_RESISTANT
  34740. /* Touch each possible point that could be being copied.
  34741. *
  34742. * r Point to copy into.
  34743. * table Table - start of the entries to access
  34744. * idx Index of entry to retrieve.
  34745. */
  34746. static void sp_521_get_point_33_9(sp_point_521* r, const sp_point_521* table,
  34747. int idx)
  34748. {
  34749. int i;
  34750. sp_digit mask;
  34751. r->x[0] = 0;
  34752. r->x[1] = 0;
  34753. r->x[2] = 0;
  34754. r->x[3] = 0;
  34755. r->x[4] = 0;
  34756. r->x[5] = 0;
  34757. r->x[6] = 0;
  34758. r->x[7] = 0;
  34759. r->x[8] = 0;
  34760. r->y[0] = 0;
  34761. r->y[1] = 0;
  34762. r->y[2] = 0;
  34763. r->y[3] = 0;
  34764. r->y[4] = 0;
  34765. r->y[5] = 0;
  34766. r->y[6] = 0;
  34767. r->y[7] = 0;
  34768. r->y[8] = 0;
  34769. r->z[0] = 0;
  34770. r->z[1] = 0;
  34771. r->z[2] = 0;
  34772. r->z[3] = 0;
  34773. r->z[4] = 0;
  34774. r->z[5] = 0;
  34775. r->z[6] = 0;
  34776. r->z[7] = 0;
  34777. r->z[8] = 0;
  34778. for (i = 1; i < 33; i++) {
  34779. mask = 0 - (i == idx);
  34780. r->x[0] |= mask & table[i].x[0];
  34781. r->x[1] |= mask & table[i].x[1];
  34782. r->x[2] |= mask & table[i].x[2];
  34783. r->x[3] |= mask & table[i].x[3];
  34784. r->x[4] |= mask & table[i].x[4];
  34785. r->x[5] |= mask & table[i].x[5];
  34786. r->x[6] |= mask & table[i].x[6];
  34787. r->x[7] |= mask & table[i].x[7];
  34788. r->x[8] |= mask & table[i].x[8];
  34789. r->y[0] |= mask & table[i].y[0];
  34790. r->y[1] |= mask & table[i].y[1];
  34791. r->y[2] |= mask & table[i].y[2];
  34792. r->y[3] |= mask & table[i].y[3];
  34793. r->y[4] |= mask & table[i].y[4];
  34794. r->y[5] |= mask & table[i].y[5];
  34795. r->y[6] |= mask & table[i].y[6];
  34796. r->y[7] |= mask & table[i].y[7];
  34797. r->y[8] |= mask & table[i].y[8];
  34798. r->z[0] |= mask & table[i].z[0];
  34799. r->z[1] |= mask & table[i].z[1];
  34800. r->z[2] |= mask & table[i].z[2];
  34801. r->z[3] |= mask & table[i].z[3];
  34802. r->z[4] |= mask & table[i].z[4];
  34803. r->z[5] |= mask & table[i].z[5];
  34804. r->z[6] |= mask & table[i].z[6];
  34805. r->z[7] |= mask & table[i].z[7];
  34806. r->z[8] |= mask & table[i].z[8];
  34807. }
  34808. }
  34809. #endif /* !WC_NO_CACHE_RESISTANT */
  34810. /* Multiply the point by the scalar and return the result.
  34811. * If map is true then convert result to affine coordinates.
  34812. *
  34813. * Window technique of 6 bits. (Add-Sub variation.)
  34814. * Calculate 0..32 times the point. Use function that adds and
  34815. * subtracts the same two points.
  34816. * Recode to add or subtract one of the computed points.
  34817. * Double to push up.
  34818. * NOT a sliding window.
  34819. *
  34820. * r Resulting point.
  34821. * g Point to multiply.
  34822. * k Scalar to multiply by.
  34823. * map Indicates whether to convert result to affine.
  34824. * ct Constant time required.
  34825. * heap Heap to use for allocation.
  34826. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  34827. */
  34828. static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* g,
  34829. const sp_digit* k, int map, int ct, void* heap)
  34830. {
  34831. #ifdef WOLFSSL_SP_SMALL_STACK
  34832. sp_point_521* t = NULL;
  34833. sp_digit* tmp = NULL;
  34834. #else
  34835. sp_point_521 t[33+2];
  34836. sp_digit tmp[2 * 9 * 6];
  34837. #endif
  34838. sp_point_521* rt = NULL;
  34839. sp_point_521* p = NULL;
  34840. sp_digit* negy;
  34841. int i;
  34842. ecc_recode_521 v[87];
  34843. int err = MP_OKAY;
  34844. /* Constant time used for cache attack resistance implementation. */
  34845. (void)ct;
  34846. (void)heap;
  34847. #ifdef WOLFSSL_SP_SMALL_STACK
  34848. t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) *
  34849. (33+2), heap, DYNAMIC_TYPE_ECC);
  34850. if (t == NULL)
  34851. err = MEMORY_E;
  34852. if (err == MP_OKAY) {
  34853. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6,
  34854. heap, DYNAMIC_TYPE_ECC);
  34855. if (tmp == NULL)
  34856. err = MEMORY_E;
  34857. }
  34858. #endif
  34859. if (err == MP_OKAY) {
  34860. rt = t + 33;
  34861. p = t + 33+1;
  34862. /* t[0] = {0, 0, 1} * norm */
  34863. XMEMSET(&t[0], 0, sizeof(t[0]));
  34864. t[0].infinity = 1;
  34865. /* t[1] = {g->x, g->y, g->z} * norm */
  34866. err = sp_521_mod_mul_norm_9(t[1].x, g->x, p521_mod);
  34867. }
  34868. if (err == MP_OKAY) {
  34869. err = sp_521_mod_mul_norm_9(t[1].y, g->y, p521_mod);
  34870. }
  34871. if (err == MP_OKAY) {
  34872. err = sp_521_mod_mul_norm_9(t[1].z, g->z, p521_mod);
  34873. }
  34874. if (err == MP_OKAY) {
  34875. t[1].infinity = 0;
  34876. /* t[2] ... t[32] */
  34877. sp_521_proj_point_dbl_n_store_9(t, &t[ 1], 5, 1, tmp);
  34878. sp_521_proj_point_add_9(&t[ 3], &t[ 2], &t[ 1], tmp);
  34879. sp_521_proj_point_dbl_9(&t[ 6], &t[ 3], tmp);
  34880. sp_521_proj_point_add_sub_9(&t[ 7], &t[ 5], &t[ 6], &t[ 1], tmp);
  34881. sp_521_proj_point_dbl_9(&t[10], &t[ 5], tmp);
  34882. sp_521_proj_point_add_sub_9(&t[11], &t[ 9], &t[10], &t[ 1], tmp);
  34883. sp_521_proj_point_dbl_9(&t[12], &t[ 6], tmp);
  34884. sp_521_proj_point_dbl_9(&t[14], &t[ 7], tmp);
  34885. sp_521_proj_point_add_sub_9(&t[15], &t[13], &t[14], &t[ 1], tmp);
  34886. sp_521_proj_point_dbl_9(&t[18], &t[ 9], tmp);
  34887. sp_521_proj_point_add_sub_9(&t[19], &t[17], &t[18], &t[ 1], tmp);
  34888. sp_521_proj_point_dbl_9(&t[20], &t[10], tmp);
  34889. sp_521_proj_point_dbl_9(&t[22], &t[11], tmp);
  34890. sp_521_proj_point_add_sub_9(&t[23], &t[21], &t[22], &t[ 1], tmp);
  34891. sp_521_proj_point_dbl_9(&t[24], &t[12], tmp);
  34892. sp_521_proj_point_dbl_9(&t[26], &t[13], tmp);
  34893. sp_521_proj_point_add_sub_9(&t[27], &t[25], &t[26], &t[ 1], tmp);
  34894. sp_521_proj_point_dbl_9(&t[28], &t[14], tmp);
  34895. sp_521_proj_point_dbl_9(&t[30], &t[15], tmp);
  34896. sp_521_proj_point_add_sub_9(&t[31], &t[29], &t[30], &t[ 1], tmp);
  34897. negy = t[0].y;
  34898. sp_521_ecc_recode_6_9(k, v);
  34899. i = 86;
  34900. #ifndef WC_NO_CACHE_RESISTANT
  34901. if (ct) {
  34902. sp_521_get_point_33_9(rt, t, v[i].i);
  34903. rt->infinity = !v[i].i;
  34904. }
  34905. else
  34906. #endif
  34907. {
  34908. XMEMCPY(rt, &t[v[i].i], sizeof(sp_point_521));
  34909. }
  34910. for (--i; i>=0; i--) {
  34911. sp_521_proj_point_dbl_n_9(rt, 6, tmp);
  34912. #ifndef WC_NO_CACHE_RESISTANT
  34913. if (ct) {
  34914. sp_521_get_point_33_9(p, t, v[i].i);
  34915. p->infinity = !v[i].i;
  34916. }
  34917. else
  34918. #endif
  34919. {
  34920. XMEMCPY(p, &t[v[i].i], sizeof(sp_point_521));
  34921. }
  34922. sp_521_sub_9(negy, p521_mod, p->y);
  34923. sp_521_norm_9(negy);
  34924. sp_521_cond_copy_9(p->y, negy, (sp_digit)0 - v[i].neg);
  34925. sp_521_proj_point_add_9(rt, rt, p, tmp);
  34926. }
  34927. if (map != 0) {
  34928. sp_521_map_9(r, rt, tmp);
  34929. }
  34930. else {
  34931. XMEMCPY(r, rt, sizeof(sp_point_521));
  34932. }
  34933. }
  34934. #ifdef WOLFSSL_SP_SMALL_STACK
  34935. if (t != NULL)
  34936. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  34937. if (tmp != NULL)
  34938. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  34939. #endif
  34940. return err;
  34941. }
  34942. #ifdef FP_ECC
  34943. #endif /* FP_ECC */
  34944. /* Add two Montgomery form projective points. The second point has a q value of
  34945. * one.
  34946. * Only the first point can be the same pointer as the result point.
  34947. *
  34948. * r Result of addition.
  34949. * p First point to add.
  34950. * q Second point to add.
  34951. * t Temporary ordinate data.
  34952. */
  34953. static void sp_521_proj_point_add_qz1_9(sp_point_521* r,
  34954. const sp_point_521* p, const sp_point_521* q, sp_digit* t)
  34955. {
  34956. sp_digit* t2 = t;
  34957. sp_digit* t3 = t + 2*9;
  34958. sp_digit* t6 = t + 4*9;
  34959. sp_digit* t1 = t + 6*9;
  34960. sp_digit* t4 = t + 8*9;
  34961. sp_digit* t5 = t + 10*9;
  34962. /* Calculate values to subtract from P->x and P->y. */
  34963. /* U2 = X2*Z1^2 */
  34964. sp_521_mont_sqr_9(t2, p->z, p521_mod, p521_mp_mod);
  34965. sp_521_mont_mul_9(t4, t2, p->z, p521_mod, p521_mp_mod);
  34966. sp_521_mont_mul_9(t2, t2, q->x, p521_mod, p521_mp_mod);
  34967. /* S2 = Y2*Z1^3 */
  34968. sp_521_mont_mul_9(t4, t4, q->y, p521_mod, p521_mp_mod);
  34969. if ((~p->infinity) & (~q->infinity) &
  34970. sp_521_cmp_equal_9(p->x, t2) &
  34971. sp_521_cmp_equal_9(p->y, t4)) {
  34972. sp_521_proj_point_dbl_9(r, p, t);
  34973. }
  34974. else {
  34975. sp_digit* x = t2;
  34976. sp_digit* y = t3;
  34977. sp_digit* z = t6;
  34978. /* H = U2 - X1 */
  34979. sp_521_mont_sub_9(t2, t2, p->x, p521_mod);
  34980. /* R = S2 - Y1 */
  34981. sp_521_mont_sub_9(t4, t4, p->y, p521_mod);
  34982. /* Z3 = H*Z1 */
  34983. sp_521_mont_mul_9(z, p->z, t2, p521_mod, p521_mp_mod);
  34984. /* X3 = R^2 - H^3 - 2*X1*H^2 */
  34985. sp_521_mont_sqr_9(t1, t2, p521_mod, p521_mp_mod);
  34986. sp_521_mont_mul_9(t3, p->x, t1, p521_mod, p521_mp_mod);
  34987. sp_521_mont_mul_9(t1, t1, t2, p521_mod, p521_mp_mod);
  34988. sp_521_mont_sqr_9(t2, t4, p521_mod, p521_mp_mod);
  34989. sp_521_mont_sub_9(t2, t2, t1, p521_mod);
  34990. sp_521_mont_dbl_9(t5, t3, p521_mod);
  34991. sp_521_mont_sub_9(x, t2, t5, p521_mod);
  34992. /* Y3 = R*(X1*H^2 - X3) - Y1*H^3 */
  34993. sp_521_mont_sub_9(t3, t3, x, p521_mod);
  34994. sp_521_mont_mul_9(t3, t3, t4, p521_mod, p521_mp_mod);
  34995. sp_521_mont_mul_9(t1, t1, p->y, p521_mod, p521_mp_mod);
  34996. sp_521_mont_sub_9(y, t3, t1, p521_mod);
  34997. {
  34998. int i;
  34999. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  35000. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  35001. sp_digit maskt = ~(maskp | maskq);
  35002. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  35003. for (i = 0; i < 9; i++) {
  35004. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  35005. (x[i] & maskt);
  35006. }
  35007. for (i = 0; i < 9; i++) {
  35008. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  35009. (y[i] & maskt);
  35010. }
  35011. for (i = 0; i < 9; i++) {
  35012. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  35013. (z[i] & maskt);
  35014. }
  35015. r->z[0] |= inf;
  35016. r->infinity = (word32)inf;
  35017. }
  35018. }
  35019. }
  35020. #ifdef FP_ECC
  35021. /* Convert the projective point to affine.
  35022. * Ordinates are in Montgomery form.
  35023. *
  35024. * a Point to convert.
  35025. * t Temporary data.
  35026. */
  35027. static void sp_521_proj_to_affine_9(sp_point_521* a, sp_digit* t)
  35028. {
  35029. sp_digit* t1 = t;
  35030. sp_digit* t2 = t + 2 * 9;
  35031. sp_digit* tmp = t + 4 * 9;
  35032. sp_521_mont_inv_9(t1, a->z, tmp);
  35033. sp_521_mont_sqr_9(t2, t1, p521_mod, p521_mp_mod);
  35034. sp_521_mont_mul_9(t1, t2, t1, p521_mod, p521_mp_mod);
  35035. sp_521_mont_mul_9(a->x, a->x, t2, p521_mod, p521_mp_mod);
  35036. sp_521_mont_mul_9(a->y, a->y, t1, p521_mod, p521_mp_mod);
  35037. XMEMCPY(a->z, p521_norm_mod, sizeof(p521_norm_mod));
  35038. }
  35039. /* Generate the pre-computed table of points for the base point.
  35040. *
  35041. * width = 8
  35042. * 256 entries
  35043. * 65 bits between
  35044. *
  35045. * a The base point.
  35046. * table Place to store generated point data.
  35047. * tmp Temporary data.
  35048. * heap Heap to use for allocation.
  35049. */
  35050. static int sp_521_gen_stripe_table_9(const sp_point_521* a,
  35051. sp_table_entry_521* table, sp_digit* tmp, void* heap)
  35052. {
  35053. #ifdef WOLFSSL_SP_SMALL_STACK
  35054. sp_point_521* t = NULL;
  35055. #else
  35056. sp_point_521 t[3];
  35057. #endif
  35058. sp_point_521* s1 = NULL;
  35059. sp_point_521* s2 = NULL;
  35060. int i;
  35061. int j;
  35062. int err = MP_OKAY;
  35063. (void)heap;
  35064. #ifdef WOLFSSL_SP_SMALL_STACK
  35065. t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap,
  35066. DYNAMIC_TYPE_ECC);
  35067. if (t == NULL)
  35068. err = MEMORY_E;
  35069. #endif
  35070. if (err == MP_OKAY) {
  35071. s1 = t + 1;
  35072. s2 = t + 2;
  35073. err = sp_521_mod_mul_norm_9(t->x, a->x, p521_mod);
  35074. }
  35075. if (err == MP_OKAY) {
  35076. err = sp_521_mod_mul_norm_9(t->y, a->y, p521_mod);
  35077. }
  35078. if (err == MP_OKAY) {
  35079. err = sp_521_mod_mul_norm_9(t->z, a->z, p521_mod);
  35080. }
  35081. if (err == MP_OKAY) {
  35082. t->infinity = 0;
  35083. sp_521_proj_to_affine_9(t, tmp);
  35084. XMEMCPY(s1->z, p521_norm_mod, sizeof(p521_norm_mod));
  35085. s1->infinity = 0;
  35086. XMEMCPY(s2->z, p521_norm_mod, sizeof(p521_norm_mod));
  35087. s2->infinity = 0;
  35088. /* table[0] = {0, 0, infinity} */
  35089. XMEMSET(&table[0], 0, sizeof(sp_table_entry_521));
  35090. /* table[1] = Affine version of 'a' in Montgomery form */
  35091. XMEMCPY(table[1].x, t->x, sizeof(table->x));
  35092. XMEMCPY(table[1].y, t->y, sizeof(table->y));
  35093. for (i=1; i<8; i++) {
  35094. sp_521_proj_point_dbl_n_9(t, 66, tmp);
  35095. sp_521_proj_to_affine_9(t, tmp);
  35096. XMEMCPY(table[1<<i].x, t->x, sizeof(table->x));
  35097. XMEMCPY(table[1<<i].y, t->y, sizeof(table->y));
  35098. }
  35099. for (i=1; i<8; i++) {
  35100. XMEMCPY(s1->x, table[1<<i].x, sizeof(table->x));
  35101. XMEMCPY(s1->y, table[1<<i].y, sizeof(table->y));
  35102. for (j=(1<<i)+1; j<(1<<(i+1)); j++) {
  35103. XMEMCPY(s2->x, table[j-(1<<i)].x, sizeof(table->x));
  35104. XMEMCPY(s2->y, table[j-(1<<i)].y, sizeof(table->y));
  35105. sp_521_proj_point_add_qz1_9(t, s1, s2, tmp);
  35106. sp_521_proj_to_affine_9(t, tmp);
  35107. XMEMCPY(table[j].x, t->x, sizeof(table->x));
  35108. XMEMCPY(table[j].y, t->y, sizeof(table->y));
  35109. }
  35110. }
  35111. }
  35112. #ifdef WOLFSSL_SP_SMALL_STACK
  35113. if (t != NULL)
  35114. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  35115. #endif
  35116. return err;
  35117. }
  35118. #endif /* FP_ECC */
  35119. #ifndef WC_NO_CACHE_RESISTANT
  35120. /* Touch each possible entry that could be being copied.
  35121. *
  35122. * r Point to copy into.
  35123. * table Table - start of the entries to access
  35124. * idx Index of entry to retrieve.
  35125. */
  35126. static void sp_521_get_entry_256_9(sp_point_521* r,
  35127. const sp_table_entry_521* table, int idx)
  35128. {
  35129. int i;
  35130. sp_digit mask;
  35131. r->x[0] = 0;
  35132. r->x[1] = 0;
  35133. r->x[2] = 0;
  35134. r->x[3] = 0;
  35135. r->x[4] = 0;
  35136. r->x[5] = 0;
  35137. r->x[6] = 0;
  35138. r->x[7] = 0;
  35139. r->x[8] = 0;
  35140. r->y[0] = 0;
  35141. r->y[1] = 0;
  35142. r->y[2] = 0;
  35143. r->y[3] = 0;
  35144. r->y[4] = 0;
  35145. r->y[5] = 0;
  35146. r->y[6] = 0;
  35147. r->y[7] = 0;
  35148. r->y[8] = 0;
  35149. for (i = 1; i < 256; i++) {
  35150. mask = 0 - (i == idx);
  35151. r->x[0] |= mask & table[i].x[0];
  35152. r->x[1] |= mask & table[i].x[1];
  35153. r->x[2] |= mask & table[i].x[2];
  35154. r->x[3] |= mask & table[i].x[3];
  35155. r->x[4] |= mask & table[i].x[4];
  35156. r->x[5] |= mask & table[i].x[5];
  35157. r->x[6] |= mask & table[i].x[6];
  35158. r->x[7] |= mask & table[i].x[7];
  35159. r->x[8] |= mask & table[i].x[8];
  35160. r->y[0] |= mask & table[i].y[0];
  35161. r->y[1] |= mask & table[i].y[1];
  35162. r->y[2] |= mask & table[i].y[2];
  35163. r->y[3] |= mask & table[i].y[3];
  35164. r->y[4] |= mask & table[i].y[4];
  35165. r->y[5] |= mask & table[i].y[5];
  35166. r->y[6] |= mask & table[i].y[6];
  35167. r->y[7] |= mask & table[i].y[7];
  35168. r->y[8] |= mask & table[i].y[8];
  35169. }
  35170. }
  35171. #endif /* !WC_NO_CACHE_RESISTANT */
  35172. /* Multiply the point by the scalar and return the result.
  35173. * If map is true then convert result to affine coordinates.
  35174. *
  35175. * Stripe implementation.
  35176. * Pre-generated: 2^0, 2^65, ...
  35177. * Pre-generated: products of all combinations of above.
  35178. * 8 doubles and adds (with qz=1)
  35179. *
  35180. * r Resulting point.
  35181. * k Scalar to multiply by.
  35182. * table Pre-computed table.
  35183. * map Indicates whether to convert result to affine.
  35184. * ct Constant time required.
  35185. * heap Heap to use for allocation.
  35186. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  35187. */
  35188. static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g,
  35189. const sp_table_entry_521* table, const sp_digit* k, int map,
  35190. int ct, void* heap)
  35191. {
  35192. #ifdef WOLFSSL_SP_SMALL_STACK
  35193. sp_point_521* rt = NULL;
  35194. sp_digit* t = NULL;
  35195. #else
  35196. sp_point_521 rt[2];
  35197. sp_digit t[2 * 9 * 6];
  35198. #endif
  35199. sp_point_521* p = NULL;
  35200. int i;
  35201. int j;
  35202. int y;
  35203. int x;
  35204. int err = MP_OKAY;
  35205. (void)g;
  35206. /* Constant time used for cache attack resistance implementation. */
  35207. (void)ct;
  35208. (void)heap;
  35209. #ifdef WOLFSSL_SP_SMALL_STACK
  35210. rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap,
  35211. DYNAMIC_TYPE_ECC);
  35212. if (rt == NULL)
  35213. err = MEMORY_E;
  35214. if (err == MP_OKAY) {
  35215. t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap,
  35216. DYNAMIC_TYPE_ECC);
  35217. if (t == NULL)
  35218. err = MEMORY_E;
  35219. }
  35220. #endif
  35221. if (err == MP_OKAY) {
  35222. p = rt + 1;
  35223. XMEMCPY(p->z, p521_norm_mod, sizeof(p521_norm_mod));
  35224. XMEMCPY(rt->z, p521_norm_mod, sizeof(p521_norm_mod));
  35225. y = 0;
  35226. x = 65;
  35227. for (j=0; j<8 && x<521; j++) {
  35228. y |= (int)(((k[x / 58] >> (x % 58)) & 1) << j);
  35229. x += 66;
  35230. }
  35231. #ifndef WC_NO_CACHE_RESISTANT
  35232. if (ct) {
  35233. sp_521_get_entry_256_9(rt, table, y);
  35234. } else
  35235. #endif
  35236. {
  35237. XMEMCPY(rt->x, table[y].x, sizeof(table[y].x));
  35238. XMEMCPY(rt->y, table[y].y, sizeof(table[y].y));
  35239. }
  35240. rt->infinity = !y;
  35241. for (i=64; i>=0; i--) {
  35242. y = 0;
  35243. x = i;
  35244. for (j=0; j<8 && x<521; j++) {
  35245. y |= (int)(((k[x / 58] >> (x % 58)) & 1) << j);
  35246. x += 66;
  35247. }
  35248. sp_521_proj_point_dbl_9(rt, rt, t);
  35249. #ifndef WC_NO_CACHE_RESISTANT
  35250. if (ct) {
  35251. sp_521_get_entry_256_9(p, table, y);
  35252. }
  35253. else
  35254. #endif
  35255. {
  35256. XMEMCPY(p->x, table[y].x, sizeof(table[y].x));
  35257. XMEMCPY(p->y, table[y].y, sizeof(table[y].y));
  35258. }
  35259. p->infinity = !y;
  35260. sp_521_proj_point_add_qz1_9(rt, rt, p, t);
  35261. }
  35262. if (map != 0) {
  35263. sp_521_map_9(r, rt, t);
  35264. }
  35265. else {
  35266. XMEMCPY(r, rt, sizeof(sp_point_521));
  35267. }
  35268. }
  35269. #ifdef WOLFSSL_SP_SMALL_STACK
  35270. if (t != NULL)
  35271. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  35272. if (rt != NULL)
  35273. XFREE(rt, heap, DYNAMIC_TYPE_ECC);
  35274. #endif
  35275. return err;
  35276. }
  35277. #ifdef FP_ECC
  35278. #ifndef FP_ENTRIES
  35279. #define FP_ENTRIES 16
  35280. #endif
  35281. /* Cache entry - holds precomputation tables for a point. */
  35282. typedef struct sp_cache_521_t {
  35283. /* X ordinate of point that table was generated from. */
  35284. sp_digit x[9];
  35285. /* Y ordinate of point that table was generated from. */
  35286. sp_digit y[9];
  35287. /* Precomputation table for point. */
  35288. sp_table_entry_521 table[256];
  35289. /* Count of entries in table. */
  35290. uint32_t cnt;
  35291. /* Point and table set in entry. */
  35292. int set;
  35293. } sp_cache_521_t;
  35294. /* Cache of tables. */
  35295. static THREAD_LS_T sp_cache_521_t sp_cache_521[FP_ENTRIES];
  35296. /* Index of last entry in cache. */
  35297. static THREAD_LS_T int sp_cache_521_last = -1;
  35298. /* Cache has been initialized. */
  35299. static THREAD_LS_T int sp_cache_521_inited = 0;
  35300. #ifndef HAVE_THREAD_LS
  35301. static volatile int initCacheMutex_521 = 0;
  35302. static wolfSSL_Mutex sp_cache_521_lock;
  35303. #endif
  35304. /* Get the cache entry for the point.
  35305. *
  35306. * g [in] Point scalar multiplying.
  35307. * cache [out] Cache table to use.
  35308. */
  35309. static void sp_ecc_get_cache_521(const sp_point_521* g, sp_cache_521_t** cache)
  35310. {
  35311. int i;
  35312. int j;
  35313. uint32_t least;
  35314. if (sp_cache_521_inited == 0) {
  35315. for (i=0; i<FP_ENTRIES; i++) {
  35316. sp_cache_521[i].set = 0;
  35317. }
  35318. sp_cache_521_inited = 1;
  35319. }
  35320. /* Compare point with those in cache. */
  35321. for (i=0; i<FP_ENTRIES; i++) {
  35322. if (!sp_cache_521[i].set)
  35323. continue;
  35324. if (sp_521_cmp_equal_9(g->x, sp_cache_521[i].x) &
  35325. sp_521_cmp_equal_9(g->y, sp_cache_521[i].y)) {
  35326. sp_cache_521[i].cnt++;
  35327. break;
  35328. }
  35329. }
  35330. /* No match. */
  35331. if (i == FP_ENTRIES) {
  35332. /* Find empty entry. */
  35333. i = (sp_cache_521_last + 1) % FP_ENTRIES;
  35334. for (; i != sp_cache_521_last; i=(i+1)%FP_ENTRIES) {
  35335. if (!sp_cache_521[i].set) {
  35336. break;
  35337. }
  35338. }
  35339. /* Evict least used. */
  35340. if (i == sp_cache_521_last) {
  35341. least = sp_cache_521[0].cnt;
  35342. for (j=1; j<FP_ENTRIES; j++) {
  35343. if (sp_cache_521[j].cnt < least) {
  35344. i = j;
  35345. least = sp_cache_521[i].cnt;
  35346. }
  35347. }
  35348. }
  35349. XMEMCPY(sp_cache_521[i].x, g->x, sizeof(sp_cache_521[i].x));
  35350. XMEMCPY(sp_cache_521[i].y, g->y, sizeof(sp_cache_521[i].y));
  35351. sp_cache_521[i].set = 1;
  35352. sp_cache_521[i].cnt = 1;
  35353. }
  35354. *cache = &sp_cache_521[i];
  35355. sp_cache_521_last = i;
  35356. }
  35357. #endif /* FP_ECC */
  35358. /* Multiply the base point of P521 by the scalar and return the result.
  35359. * If map is true then convert result to affine coordinates.
  35360. *
  35361. * r Resulting point.
  35362. * g Point to multiply.
  35363. * k Scalar to multiply by.
  35364. * map Indicates whether to convert result to affine.
  35365. * ct Constant time required.
  35366. * heap Heap to use for allocation.
  35367. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  35368. */
  35369. static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g,
  35370. const sp_digit* k, int map, int ct, void* heap)
  35371. {
  35372. #ifndef FP_ECC
  35373. return sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap);
  35374. #else
  35375. #ifdef WOLFSSL_SP_SMALL_STACK
  35376. sp_digit* tmp;
  35377. #else
  35378. sp_digit tmp[2 * 9 * 6];
  35379. #endif
  35380. sp_cache_521_t* cache;
  35381. int err = MP_OKAY;
  35382. #ifdef WOLFSSL_SP_SMALL_STACK
  35383. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC);
  35384. if (tmp == NULL) {
  35385. err = MEMORY_E;
  35386. }
  35387. #endif
  35388. #ifndef HAVE_THREAD_LS
  35389. if (err == MP_OKAY) {
  35390. if (initCacheMutex_521 == 0) {
  35391. wc_InitMutex(&sp_cache_521_lock);
  35392. initCacheMutex_521 = 1;
  35393. }
  35394. if (wc_LockMutex(&sp_cache_521_lock) != 0) {
  35395. err = BAD_MUTEX_E;
  35396. }
  35397. }
  35398. #endif /* HAVE_THREAD_LS */
  35399. if (err == MP_OKAY) {
  35400. sp_ecc_get_cache_521(g, &cache);
  35401. if (cache->cnt == 2)
  35402. sp_521_gen_stripe_table_9(g, cache->table, tmp, heap);
  35403. #ifndef HAVE_THREAD_LS
  35404. wc_UnLockMutex(&sp_cache_521_lock);
  35405. #endif /* HAVE_THREAD_LS */
  35406. if (cache->cnt < 2) {
  35407. err = sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap);
  35408. }
  35409. else {
  35410. err = sp_521_ecc_mulmod_stripe_9(r, g, cache->table, k,
  35411. map, ct, heap);
  35412. }
  35413. }
  35414. #ifdef WOLFSSL_SP_SMALL_STACK
  35415. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  35416. #endif
  35417. return err;
  35418. #endif
  35419. }
  35420. #endif
  35421. /* Multiply the point by the scalar and return the result.
  35422. * If map is true then convert result to affine coordinates.
  35423. *
  35424. * km Scalar to multiply by.
  35425. * p Point to multiply.
  35426. * r Resulting point.
  35427. * map Indicates whether to convert result to affine.
  35428. * heap Heap to use for allocation.
  35429. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  35430. */
  35431. int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r,
  35432. int map, void* heap)
  35433. {
  35434. #ifdef WOLFSSL_SP_SMALL_STACK
  35435. sp_point_521* point = NULL;
  35436. sp_digit* k = NULL;
  35437. #else
  35438. sp_point_521 point[1];
  35439. sp_digit k[9];
  35440. #endif
  35441. int err = MP_OKAY;
  35442. #ifdef WOLFSSL_SP_SMALL_STACK
  35443. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap,
  35444. DYNAMIC_TYPE_ECC);
  35445. if (point == NULL)
  35446. err = MEMORY_E;
  35447. if (err == MP_OKAY) {
  35448. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9, heap,
  35449. DYNAMIC_TYPE_ECC);
  35450. if (k == NULL)
  35451. err = MEMORY_E;
  35452. }
  35453. #endif
  35454. if (err == MP_OKAY) {
  35455. sp_521_from_mp(k, 9, km);
  35456. sp_521_point_from_ecc_point_9(point, gm);
  35457. err = sp_521_ecc_mulmod_9(point, point, k, map, 1, heap);
  35458. }
  35459. if (err == MP_OKAY) {
  35460. err = sp_521_point_to_ecc_point_9(point, r);
  35461. }
  35462. #ifdef WOLFSSL_SP_SMALL_STACK
  35463. if (k != NULL)
  35464. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  35465. if (point != NULL)
  35466. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  35467. #endif
  35468. return err;
  35469. }
  35470. /* Multiply the point by the scalar, add point a and return the result.
  35471. * If map is true then convert result to affine coordinates.
  35472. *
  35473. * km Scalar to multiply by.
  35474. * p Point to multiply.
  35475. * am Point to add to scalar multiply result.
  35476. * inMont Point to add is in montgomery form.
  35477. * r Resulting point.
  35478. * map Indicates whether to convert result to affine.
  35479. * heap Heap to use for allocation.
  35480. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  35481. */
  35482. int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm,
  35483. const ecc_point* am, int inMont, ecc_point* r, int map, void* heap)
  35484. {
  35485. #ifdef WOLFSSL_SP_SMALL_STACK
  35486. sp_point_521* point = NULL;
  35487. sp_digit* k = NULL;
  35488. #else
  35489. sp_point_521 point[2];
  35490. sp_digit k[9 + 9 * 2 * 6];
  35491. #endif
  35492. sp_point_521* addP = NULL;
  35493. sp_digit* tmp = NULL;
  35494. int err = MP_OKAY;
  35495. #ifdef WOLFSSL_SP_SMALL_STACK
  35496. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap,
  35497. DYNAMIC_TYPE_ECC);
  35498. if (point == NULL)
  35499. err = MEMORY_E;
  35500. if (err == MP_OKAY) {
  35501. k = (sp_digit*)XMALLOC(
  35502. sizeof(sp_digit) * (9 + 9 * 2 * 6), heap,
  35503. DYNAMIC_TYPE_ECC);
  35504. if (k == NULL)
  35505. err = MEMORY_E;
  35506. }
  35507. #endif
  35508. if (err == MP_OKAY) {
  35509. addP = point + 1;
  35510. tmp = k + 9;
  35511. sp_521_from_mp(k, 9, km);
  35512. sp_521_point_from_ecc_point_9(point, gm);
  35513. sp_521_point_from_ecc_point_9(addP, am);
  35514. }
  35515. if ((err == MP_OKAY) && (!inMont)) {
  35516. err = sp_521_mod_mul_norm_9(addP->x, addP->x, p521_mod);
  35517. }
  35518. if ((err == MP_OKAY) && (!inMont)) {
  35519. err = sp_521_mod_mul_norm_9(addP->y, addP->y, p521_mod);
  35520. }
  35521. if ((err == MP_OKAY) && (!inMont)) {
  35522. err = sp_521_mod_mul_norm_9(addP->z, addP->z, p521_mod);
  35523. }
  35524. if (err == MP_OKAY) {
  35525. err = sp_521_ecc_mulmod_9(point, point, k, 0, 0, heap);
  35526. }
  35527. if (err == MP_OKAY) {
  35528. sp_521_proj_point_add_9(point, point, addP, tmp);
  35529. if (map) {
  35530. sp_521_map_9(point, point, tmp);
  35531. }
  35532. err = sp_521_point_to_ecc_point_9(point, r);
  35533. }
  35534. #ifdef WOLFSSL_SP_SMALL_STACK
  35535. if (k != NULL)
  35536. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  35537. if (point != NULL)
  35538. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  35539. #endif
  35540. return err;
  35541. }
  35542. #ifdef WOLFSSL_SP_SMALL
  35543. /* Multiply the base point of P521 by the scalar and return the result.
  35544. * If map is true then convert result to affine coordinates.
  35545. *
  35546. * r Resulting point.
  35547. * k Scalar to multiply by.
  35548. * map Indicates whether to convert result to affine.
  35549. * heap Heap to use for allocation.
  35550. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  35551. */
  35552. static int sp_521_ecc_mulmod_base_9(sp_point_521* r, const sp_digit* k,
  35553. int map, int ct, void* heap)
  35554. {
  35555. /* No pre-computed values. */
  35556. return sp_521_ecc_mulmod_9(r, &p521_base, k, map, ct, heap);
  35557. }
  35558. #ifdef WOLFSSL_SP_NONBLOCK
  35559. static int sp_521_ecc_mulmod_base_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
  35560. const sp_digit* k, int map, int ct, void* heap)
  35561. {
  35562. /* No pre-computed values. */
  35563. return sp_521_ecc_mulmod_9_nb(sp_ctx, r, &p521_base, k, map, ct, heap);
  35564. }
  35565. #endif /* WOLFSSL_SP_NONBLOCK */
  35566. #else
  35567. /* Striping precomputation table.
  35568. * 8 points combined into a table of 256 points.
  35569. * Distance of 66 between points.
  35570. */
  35571. static const sp_table_entry_521 p521_table[256] = {
  35572. /* 0 */
  35573. { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  35574. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
  35575. /* 1 */
  35576. { { 0x17e7e31c2e5bd66L,0x22cf0615a90a6feL,0x0127a2ffa8de334L,
  35577. 0x1dfbf9d64a3f877L,0x06b4d3dbaa14b5eL,0x14fed487e0a2bd8L,
  35578. 0x15b4429c6481390L,0x3a73678fb2d988eL,0x0c6858e06b70404L },
  35579. { 0x0be94769fd16650L,0x31c21a89cb09022L,0x39013fad0761353L,
  35580. 0x2657bd099031542L,0x3273e662c97ee72L,0x1e6d11a05ebef45L,
  35581. 0x3d1bd998f544495L,0x3001172297ed0b1L,0x11839296a789a3bL } },
  35582. /* 2 */
  35583. { { 0x03986670f0ccb51L,0x387404d9525d2a0L,0x0f21b2b29ed9b87L,
  35584. 0x2aa8eb74cddfd63L,0x0e9d08ffb06c0e9L,0x19d8589fc4ecd74L,
  35585. 0x0a3ef4dd8bf44c9L,0x0eb6e92863051d6L,0x13e96a576dda004L },
  35586. { 0x3de24f8632d95a3L,0x057bc5314920a4aL,0x063e9bdaba1979fL,
  35587. 0x3d2a58adc1eab76L,0x214258d98dde053L,0x18708d7316628b7L,
  35588. 0x3fd32c9fa5a19d0L,0x33ab03b519443a3L,0x1852aea9dd1ef78L } },
  35589. /* 3 */
  35590. { { 0x0a91dd8eaaf1fe3L,0x0e19891002d4af4L,0x06a921abf0d20dbL,
  35591. 0x26a9da32503fda8L,0x09a1eec37941287L,0x1ce0d0f3cde46afL,
  35592. 0x22abc1c913fbe62L,0x3cc4dca2d0aaf88L,0x157874c0a862b9eL },
  35593. { 0x2c8f184e6f03d49L,0x0d5f907922f80c2L,0x1ef3815cbdefa9cL,
  35594. 0x2ad7f6370f00b39L,0x1faeb109d7a41c7L,0x213d34e12fbd9f2L,
  35595. 0x2f0aae2f98cca1aL,0x25a2df80f51f59cL,0x00724b1ab581d58L } },
  35596. /* 4 */
  35597. { { 0x04f2d4bdf9314e0L,0x3a14379e802ab24L,0x1083582efb03daaL,
  35598. 0x20fb1ff9b49e48cL,0x2199d74a880f1c2L,0x25401f9cb56ce65L,
  35599. 0x33f03e5f120b9b3L,0x2da18c348ddcd1dL,0x121f4c192733b78L },
  35600. { 0x103ff6dfa8b51f0L,0x2bed45038af7c3cL,0x380e83254171ae7L,
  35601. 0x2e33684365444c0L,0x24f3a8c01e83501L,0x3201c1a4415ddc7L,
  35602. 0x2238218f52196aaL,0x29fc4d826c2aa95L,0x1db8c25790694a0L } },
  35603. /* 5 */
  35604. { { 0x00370ccb2c0958dL,0x3bc599a69ece1ccL,0x33cf480c9b3889aL,
  35605. 0x3cbeacf85249e4bL,0x2507489670b2984L,0x34cf6caa5d4790dL,
  35606. 0x0a4daa9cab99d5aL,0x1cc95365174cad1L,0x00aa26cca5216c7L },
  35607. { 0x1be1d41f9e66d18L,0x3bbe5aa845f9eb3L,0x14a2ddb0d24b80aL,
  35608. 0x09d7262defc14c8L,0x2dfd3c8486dcfb2L,0x329354b184f9d0dL,
  35609. 0x151e646e703fa13L,0x149f43238a5dc61L,0x1c6f5e90eacbfa8L } },
  35610. /* 6 */
  35611. { { 0x2c2f1e74ab2d58fL,0x2fe0b0a825e00a8L,0x2b24770bb76ac1bL,
  35612. 0x3b5599fdef5960fL,0x2fd96897e8e4ed9L,0x3ef83c576300761L,
  35613. 0x1cdcb166395a133L,0x3ac954793ce7766L,0x082de08424a720dL },
  35614. { 0x3aa53b260ea91afL,0x212bdde8c77f765L,0x32395cd09bbea43L,
  35615. 0x36bcc016387360bL,0x2e5c78e97997c19L,0x1d6c611510ed831L,
  35616. 0x02ce16faae9b5f5L,0x3ea1973a1bccc23L,0x073983ce58f4f63L } },
  35617. /* 7 */
  35618. { { 0x2e931318217609dL,0x2a7750904bf002bL,0x264c286c63297f8L,
  35619. 0x359efc7197b845fL,0x38d03eee5cc3782L,0x2ae4de67a305136L,
  35620. 0x3784c701acacb29L,0x3361c857ac6d6c1L,0x0f82c409fa81affL },
  35621. { 0x07d3766378139a4L,0x25a7aed56faa4c0L,0x0d6f68c8bc9dc6dL,
  35622. 0x1857e4fc90b1f18L,0x2741717d9844e84L,0x02fc483a118728aL,
  35623. 0x1699d78e930e79fL,0x2db7b85552809adL,0x07de69c77026a4fL } },
  35624. /* 8 */
  35625. { { 0x1b51bb04bee80d7L,0x3da87dda4b79a58L,0x246ca0ebc3bd0e1L,
  35626. 0x29e4c1913c20de7L,0x3390db0771c0bffL,0x2b6873a65f19ee1L,
  35627. 0x14b512095c33e1fL,0x21958f1402b76b1L,0x0b0c231d360d311L },
  35628. { 0x228929839bcab2fL,0x019e01937488281L,0x2084763dc2a0c0cL,
  35629. 0x1cc64e30f8c18bdL,0x152e46eb988e9daL,0x297783f5a6fa3cbL,
  35630. 0x2c0e26e55c8d2d6L,0x3fd5fce8ff58f6cL,0x14a899c6d9f1e4bL } },
  35631. /* 9 */
  35632. { { 0x3f6e3a1ec05ce88L,0x30925adabf480a7L,0x20776fbeb007f8fL,
  35633. 0x2f7baf7b5002e74L,0x2693700f7b50ec0L,0x3dec0c3abbe5dd0L,
  35634. 0x101f77806e37a13L,0x2b83d73c5f45c6eL,0x1599036e5dfca95L },
  35635. { 0x0af64b5000e8e0cL,0x0ab8101bed37e40L,0x1a67449f23bad3fL,
  35636. 0x108956c96a57d87L,0x28e33c6500ca918L,0x0b009f07e9abcf9L,
  35637. 0x2840a514373c00cL,0x1090267cf36865cL,0x0e798c62b79d0e8L } },
  35638. /* 10 */
  35639. { { 0x0c7c4a8ae4d0f28L,0x2957bd59b401bbaL,0x1f65066e40233a8L,
  35640. 0x2d574c86dd8de61L,0x2b8351b078deccaL,0x1f5522ace2e59b5L,
  35641. 0x31ab0b2e889e535L,0x14dedea7a38bf98L,0x05945c60f95e75cL },
  35642. { 0x0a27d347867d79cL,0x182c5607206602fL,0x19ab976b8c517f4L,
  35643. 0x21986e47b65fb0bL,0x1d9c1d15ffcd044L,0x253276e5cc29e89L,
  35644. 0x2c5a3b8a2cf259fL,0x0c7ba39e12e1d77L,0x004062526073e51L } },
  35645. /* 11 */
  35646. { { 0x2e04e5cf1631bbaL,0x1b077c55bd14937L,0x3f30e4c3099040eL,
  35647. 0x10dadaafb1c1980L,0x0f6b94f6edb649aL,0x1adf82d4d53d427L,
  35648. 0x1e6dd27fecf4693L,0x1432a9e9c41fae8L,0x022889edac56894L },
  35649. { 0x012916ed05596f2L,0x0076b2c08f2e2e4L,0x13ece7d4abe1e39L,
  35650. 0x102a7240c4c9407L,0x1c6d146d0b28150L,0x13b8625a76f34fcL,
  35651. 0x1226fb6fa1d5b17L,0x0261126ba8586a4L,0x154754ceedfb8a8L } },
  35652. /* 12 */
  35653. { { 0x24e27b04270b2f0L,0x0d3922fd35d35edL,0x3e8b0c2722ba84bL,
  35654. 0x2767fe6dc72c61aL,0x334fd6bc4f54a58L,0x104bd276621f937L,
  35655. 0x389d16b7c669fd7L,0x381d1002366eddfL,0x1cfafb9426bc902L },
  35656. { 0x0a4f2d1662935caL,0x1f1c0e65f7311b3L,0x29e5353c79f8284L,
  35657. 0x2254857c3d30227L,0x080911b9d9ed8d9L,0x3789ea8d673c22fL,
  35658. 0x1e320d4b03540e6L,0x064ed4bd358fbdaL,0x0e6a0217fd694efL } },
  35659. /* 13 */
  35660. { { 0x37de62774214780L,0x19a05c81d167aadL,0x39b7e9c7fb01ca0L,
  35661. 0x3075b52df1fde15L,0x0a66caa39e55548L,0x2141693d15d5864L,
  35662. 0x0864ebf8141b039L,0x274fe972835f132L,0x053bf8af9509e12L },
  35663. { 0x09b29d885285092L,0x0c76aa3bb5797efL,0x290ef618aab982fL,
  35664. 0x3d34989bb4670cdL,0x307ed8e090eee14L,0x1cdb410108a55c2L,
  35665. 0x27d01d1977920e8L,0x2dced1fb897ffb7L,0x1b93c921c3abc7aL } },
  35666. /* 14 */
  35667. { { 0x36a07cca08b2b14L,0x1e37aefc5d31fc2L,0x3828c40cb2a4aa9L,
  35668. 0x1ca42b720e0a472L,0x28c1edde695c782L,0x03ef4880236a2caL,
  35669. 0x2db94e741ceb2f9L,0x152397e272794c8L,0x07d18266085b73cL },
  35670. { 0x1ebf82a2defd012L,0x32c2516854dfbdaL,0x35353ef0811d01eL,
  35671. 0x29ecaf537a8f155L,0x27bf969c859c882L,0x2c96b46c0287e5cL,
  35672. 0x136005063adf5e0L,0x3f861307fcc1bc9L,0x1178e515bec4112L } },
  35673. /* 15 */
  35674. { { 0x314787fefe3d3d5L,0x1dbd967625c89e4L,0x3ed1e0b6acf529eL,
  35675. 0x080717a3764571dL,0x15f5667af9c2b7bL,0x0d5dbbd1e200e3cL,
  35676. 0x00154af38c766ffL,0x0ed4e7c188f2001L,0x09647d3c44bde88L },
  35677. { 0x2075638de1b21a4L,0x0e67055c420704cL,0x206775c03599bb6L,
  35678. 0x1feb79833d4c8b9L,0x0efc190595c7fdeL,0x35ece5806c65510L,
  35679. 0x2fa73e7e70ac8cdL,0x01d912a96a0f5a9L,0x04234f8cfac6308L } },
  35680. /* 16 */
  35681. { { 0x231e71a286492adL,0x0f791197e1ab13bL,0x00d4da713cb408fL,
  35682. 0x3a6a1adc413a25cL,0x32572c1617ad0f5L,0x173072676698b93L,
  35683. 0x162e0c77d223ef2L,0x2c817b7fda584eeL,0x08e818d28f381d8L },
  35684. { 0x21231cf8cdf1f60L,0x103cad9c5dd83dcL,0x2f8ce045a4038b6L,
  35685. 0x3700dc1a27ef9c9L,0x372ea0dcb422285L,0x2021988dc65afe3L,
  35686. 0x26fe48a16f7855cL,0x2fd1353867f1f0cL,0x13efdbc856e8f68L } },
  35687. /* 17 */
  35688. { { 0x234d04fe6a3ace5L,0x2d80fa258647077L,0x0007f75ed0f40dbL,
  35689. 0x2f256c966d6d370L,0x22615f02015e0e6L,0x0c7a8fe37ef2e99L,
  35690. 0x3ff824b2ec5433dL,0x0ccb90ac2c39040L,0x11119315060c480L },
  35691. { 0x197ea28045452f1L,0x19e33dc7cfdcee6L,0x3ddc41e9328e80bL,
  35692. 0x1bb9abc708d294aL,0x1b44215e7b7f265L,0x02900a2f10e016eL,
  35693. 0x2476e23aa734f2fL,0x033df8f1c91e508L,0x1f16dc2e8b068c6L } },
  35694. /* 18 */
  35695. { { 0x0dfae6ffffc0de5L,0x06053ead297c92fL,0x3658ea2aa8dda80L,
  35696. 0x3d7693c11046404L,0x334100611f3b1caL,0x1b833e23c92e736L,
  35697. 0x055c8248c324ed9L,0x0b8a52dfa8cd08cL,0x1d36e835b648909L },
  35698. { 0x2b77ae707372f27L,0x26d3ea0eeb8669fL,0x1ae165429ebb477L,
  35699. 0x19bf00fbcfe85d7L,0x16991c7c4942ec2L,0x1894f4f0397f1aaL,
  35700. 0x34e738a0f61e4f5L,0x3a465e847fd6379L,0x00260524cd4624dL } },
  35701. /* 19 */
  35702. { { 0x1b5d0ca01342e08L,0x3b53c2dd27c2bd1L,0x02d96529d804509L,
  35703. 0x36db600d673ad54L,0x34c3848005eb087L,0x1d6a1e13aa99aa1L,
  35704. 0x34317ee972c7a0cL,0x3efd2305a7885a1L,0x14f81c556e0e5c9L },
  35705. { 0x2b0b12be120674dL,0x3c26e4867c02b09L,0x332dd658caa6c6bL,
  35706. 0x2be0a4b66787879L,0x125fdbf80c771c5L,0x199b0df57604d4aL,
  35707. 0x0df680e61bd7983L,0x0260e36b251a874L,0x09f58dcf684c39fL } },
  35708. /* 20 */
  35709. { { 0x01691027b7dc837L,0x065d52d43ac7105L,0x092ad7e6741b2d7L,
  35710. 0x076f20928e013d0L,0x2c8e20bcf1d0a7fL,0x286076c15c2c815L,
  35711. 0x3b508a6732e3b9dL,0x01249e2018db829L,0x04511af502cc9f7L },
  35712. { 0x3820d94c56f4ffaL,0x08168b13c303e82L,0x3d4ea1a0606a1c6L,
  35713. 0x199e6cc5bee67ccL,0x2e4f240fc1bab64L,0x0b5f710c16a8214L,
  35714. 0x23c07322539b789L,0x198cc0d95fc481bL,0x05928405280cedbL } },
  35715. /* 21 */
  35716. { { 0x0d087114397760cL,0x082dd8727f341a4L,0x07fa987e24f7b90L,
  35717. 0x281488cd6831ffbL,0x1ae21ca100e33b8L,0x2c0c8881cf6fabfL,
  35718. 0x145da6458c060a3L,0x18bbe6e71cee3b8L,0x0aa31c661e527ffL },
  35719. { 0x3518eb081430b5eL,0x3e73a943b835a6bL,0x30b5aa6ebe8bb32L,
  35720. 0x3ca7f875a243b36L,0x31a59cc9a1f15f7L,0x22aca98f3975a3cL,
  35721. 0x07ce54f4d679940L,0x01ddba16c73bd0dL,0x1768ff423c0286dL } },
  35722. /* 22 */
  35723. { { 0x164104c33dcec23L,0x03586f3741d4661L,0x2f514c4f309abafL,
  35724. 0x3d779221c5521b6L,0x1d3539ba3f01bc8L,0x28efa3b3775aebcL,
  35725. 0x1d865fbb7e665d3L,0x12683e4676b0f2dL,0x173fe203da3f121L },
  35726. { 0x03ae9a178d4a3d1L,0x173d62194c5b601L,0x26c041176463a4dL,
  35727. 0x23fe12be913abc0L,0x3ffea422d316c63L,0x188ad84d44bc8e5L,
  35728. 0x27068d691eaa046L,0x2ccf12215ba8e5fL,0x1b542d1b2e3f4a1L } },
  35729. /* 23 */
  35730. { { 0x11b2d5e1f487402L,0x005b99eabc7757dL,0x31f56da9c20ae36L,
  35731. 0x187b3916ff47acfL,0x3027a9e1825b7d3L,0x210459250b6c18cL,
  35732. 0x0773d0bf228777eL,0x297c3d7f3831116L,0x01fb2b3151d2dd7L },
  35733. { 0x02773e8fbaa096aL,0x1c9baf824ea1e04L,0x0d072c7f1781152L,
  35734. 0x342ad7729d9714fL,0x187ef2d4a38d3dfL,0x1fac470aed29f61L,
  35735. 0x2da22f5c9c2013bL,0x3b2b578d4f0d02dL,0x039846d50a5a325L } },
  35736. /* 24 */
  35737. { { 0x2da77361677df58L,0x2f559c72d435b1dL,0x07d70a080ff2364L,
  35738. 0x0a6194c90c0110fL,0x2c35101e7a0a854L,0x231735da0800b74L,
  35739. 0x2cf13fbebc61434L,0x23703fc5646bb29L,0x0fb91c7c2e698bfL },
  35740. { 0x27c5cad12de14d5L,0x12317d95872089aL,0x24307cdbb3dabc4L,
  35741. 0x0471da0475e7e37L,0x2754620499c58f0L,0x269d39247a2601bL,
  35742. 0x3e37c3e52ad0a2cL,0x31cb480d1a172caL,0x0ec7a8632450a0bL } },
  35743. /* 25 */
  35744. { { 0x3818c218a86786eL,0x0dfdd084df8b20cL,0x10d1a7e6eb20ed5L,
  35745. 0x1c17371200d765aL,0x024f7bd759790ecL,0x387c3c511a458b2L,
  35746. 0x1915ca09e7ef9d4L,0x089bf4c304a2f3aL,0x02d810145f66c71L },
  35747. { 0x12749f5b71d87e5L,0x0ec505ec0b3b68cL,0x2d2ee0baff1625fL,
  35748. 0x2a7f2b9989c0915L,0x337bd985f97f7b3L,0x3e9b430435bafe3L,
  35749. 0x32f13720aa81b97L,0x376c6ca7c680487L,0x03de326a2f85cc0L } },
  35750. /* 26 */
  35751. { { 0x2f3398b38c2ee78L,0x0f44069d682fb89L,0x1706565a7f8e40cL,
  35752. 0x38c10067974d68cL,0x2b8174b6ed12985L,0x3e0294a8878a990L,
  35753. 0x18d80e25a15ee8aL,0x3aa6974783f9a14L,0x0848cbbc13804f6L },
  35754. { 0x2828690dfd45169L,0x1f8261674fa341dL,0x0811cdb8bfc238dL,
  35755. 0x1e858b3d9208dd6L,0x3b4d15b8c849954L,0x18126699252eaceL,
  35756. 0x21cfed822cbc57cL,0x1662eb10c893aa2L,0x0d94356346957c6L } },
  35757. /* 27 */
  35758. { { 0x306925368271323L,0x2782a12734135caL,0x1fbf2b31cc7d24dL,
  35759. 0x13d5e8f8d86ab8dL,0x20294e85644f64bL,0x0f3b52b852411a1L,
  35760. 0x2cda47ddc82ee74L,0x3e5a32e4a9a95f8L,0x13f989c42efbfc1L },
  35761. { 0x2d98bdfb8651600L,0x18d0d1e8f3ebbafL,0x254335b1a2268c3L,
  35762. 0x3775609541e4e84L,0x3852eb1e9558da7L,0x0a57d516945cec8L,
  35763. 0x06d101df5ae5852L,0x3e18b951b8bbd99L,0x1faf7e16a2c5d89L } },
  35764. /* 28 */
  35765. { { 0x1746c8ec7ec136dL,0x07609f3444d46c3L,0x3ad3f187a116f8eL,
  35766. 0x23c4dba1195d928L,0x0850983c22f1b96L,0x39c5c967506a8a5L,
  35767. 0x3c149c2123ecc4bL,0x2e0b77372ad49d8L,0x16da7f50b181022L },
  35768. { 0x19e532d0ca5e258L,0x22b45e5ed8a9efeL,0x242ec77fddefa14L,
  35769. 0x335d3e6db123428L,0x07fd122d458518bL,0x2d42cb5f14ecc2eL,
  35770. 0x01aae9bb8cd193fL,0x1b824685a6bbaf0L,0x1c57e49b10a1de2L } },
  35771. /* 29 */
  35772. { { 0x0abe67521210716L,0x0a5a8c1f809000bL,0x011d8c83795b81aL,
  35773. 0x0d3767be9aa52bfL,0x3677d686f68f203L,0x3d7389d56f8be7aL,
  35774. 0x357c5c6a13f277bL,0x12e33df648906e5L,0x13270c3d2f4c74fL },
  35775. { 0x1c8609c8d209aa4L,0x104e8b6cad50dbeL,0x2d1a2992345d46fL,
  35776. 0x3ae521f0d3e5adcL,0x2b440a375186f2aL,0x3694d6393e9c85dL,
  35777. 0x25b3103a4209367L,0x182e3c47ab78ffcL,0x1a99a570153505dL } },
  35778. /* 30 */
  35779. { { 0x21513936e7495bbL,0x0bf4a12421e746bL,0x2b0b29fd76fcebdL,
  35780. 0x26f1839c872708cL,0x3517a09e2a1a0d4L,0x362eb7e27d60ae0L,
  35781. 0x148bb4ac37809e9L,0x3121d2a937a782bL,0x027fd041312cb6cL },
  35782. { 0x05502eeead4fb6dL,0x3097b42980b2fb0L,0x2841bd7f4a07760L,
  35783. 0x0c953b7385162e9L,0x10397614cc28b60L,0x207bb64ee75078eL,
  35784. 0x2d4b0b4221b71d1L,0x3906740438f08ccL,0x096dfe58a27dab0L } },
  35785. /* 31 */
  35786. { { 0x0d6fcd67debd24eL,0x3f29826b8ac1d53L,0x022ef217c26cbe3L,
  35787. 0x382e58838fe9f63L,0x2c7f9f87dd42d03L,0x25cbffb98d2fc85L,
  35788. 0x0d3e7722b1ec538L,0x14dfa0ea55f0758L,0x162edfe5f860f6aL },
  35789. { 0x0a05400f0ea20b8L,0x0ab1f875e5a4010L,0x25c90edb0cac287L,
  35790. 0x0c2d8a4e69ddd96L,0x2af2cb7089df5b9L,0x0bfaf04bde299dbL,
  35791. 0x190ad3030732bf5L,0x38d04e999037ae8L,0x0d536eae15f93e7L } },
  35792. /* 32 */
  35793. { { 0x06119f6a1c88f3cL,0x397fb0bb1a5129bL,0x2c605742ff2a924L,
  35794. 0x07b76c8b1f1322aL,0x0fa5d25bb60addeL,0x3045f7825ca24e3L,
  35795. 0x2929c1fa5ac4f7eL,0x257d507cd6add20L,0x180d1c4e8f90afdL },
  35796. { 0x3c4e73da7cd8358L,0x18695fca872480bL,0x3130ad94d288393L,
  35797. 0x198ada9e38bdbcbL,0x379c262cde37e24L,0x06d65ee42eaffe2L,
  35798. 0x0d4e646cae01ef6L,0x3e1167078cfc298L,0x00e52a42280dd01L } },
  35799. /* 33 */
  35800. { { 0x2d640a40f013755L,0x3739dfee0e03a5cL,0x0e797eb64b310b6L,
  35801. 0x02e4f2968d89e27L,0x358bdffc98e704bL,0x08c30dc8630d83fL,
  35802. 0x3385d153b1f323bL,0x0efdf5ace422169L,0x04a071130f556b9L },
  35803. { 0x1a2096bfeef3f88L,0x2ea1a6e0ace514aL,0x184a872664a722eL,
  35804. 0x286163fe509ff88L,0x17490c9daa0dc0bL,0x056233a0cde67adL,
  35805. 0x32cee21d356f628L,0x2bba5f766f1fe9eL,0x0d21e61a4e8a3cfL } },
  35806. /* 34 */
  35807. { { 0x05db629e9068656L,0x2f5c327fb7937fbL,0x15bdfcd45546623L,
  35808. 0x3498a469d071e2bL,0x2761e688ef7981dL,0x16e49cbceb14f64L,
  35809. 0x146fec6a96892a5L,0x0bd59085f9ee019L,0x15e793c03cbab9eL },
  35810. { 0x0fd95436eff39beL,0x2bc1fb6ffd3da02L,0x3abdb02416165a1L,
  35811. 0x3f751e600a60f51L,0x060b2e6fb37c5d2L,0x3a36e662761b65eL,
  35812. 0x28b9bbe3e3284ecL,0x062ce7c127ad761L,0x18e3b3e8a789dadL } },
  35813. /* 35 */
  35814. { { 0x3026c56e51e61f0L,0x2f2a8cc1fc9d5d5L,0x26ebb1aeaf41dddL,
  35815. 0x1f38b5fd6ea4a80L,0x2bc5ead91a33e93L,0x391a01f47df3007L,
  35816. 0x01951990ab665d2L,0x101270a913d554dL,0x0aa099c1ca67966L },
  35817. { 0x161a9098f97e387L,0x145de1178775a6dL,0x112b7ff1d6abf60L,
  35818. 0x293426a72247fe9L,0x1d2282e2b42da55L,0x1d0616b57969f1cL,
  35819. 0x0baeffdfa5a203eL,0x0285866c4da77a8L,0x1a3a5eef9141eccL } },
  35820. /* 36 */
  35821. { { 0x2f20d0a7a573b81L,0x3072a1986533bcaL,0x2d8d0b711c347eaL,
  35822. 0x1b2e826750bbc34L,0x05067a8ca6aea01L,0x284d47be998274aL,
  35823. 0x1c26346a52c6007L,0x00cf36ae16062c4L,0x121f17fa45dbb1cL },
  35824. { 0x3b8b87afc3279d6L,0x39daaf0807c7867L,0x2a83806c21dde30L,
  35825. 0x0af18fe093c0abdL,0x246bd1a53eafd7eL,0x084e4591ec1d389L,
  35826. 0x32d9bfcd6f4931aL,0x273c6acb3f4e705L,0x10a62f3eb4b4db5L } },
  35827. /* 37 */
  35828. { { 0x002de36e0689a1bL,0x3327f5f72bf9cb9L,0x2d7e255d0bfb9dcL,
  35829. 0x3b92b681367937aL,0x2bfd2e774d7ee87L,0x1c2cae6d6a140e7L,
  35830. 0x103bba282c66577L,0x141c69eb2a09ae8L,0x11aac7028bac7cdL },
  35831. { 0x261d39c680c8f04L,0x271332d22ced78bL,0x09bd95744f3c2f0L,
  35832. 0x2d2ab32d64c4c58L,0x25adfb2096d72e4L,0x3f4fb33f6dc1832L,
  35833. 0x352a73c67d9e431L,0x215f0521e89bf85L,0x1e33d95366364d0L } },
  35834. /* 38 */
  35835. { { 0x264506b4cec9e7fL,0x1592d0c2aae63f9L,0x101f173fa284a44L,
  35836. 0x1f85725d1c9786dL,0x082dec033e7b7bdL,0x298edd8b5b319eaL,
  35837. 0x0e2fcd1fe2e9340L,0x39d48e821386cfeL,0x0fdccce4da89ae6L },
  35838. { 0x397f8eec12fd820L,0x3e24aa5b691ccc1L,0x241d55997bf4325L,
  35839. 0x2b00add4f3d65f4L,0x1f677ceba3aef35L,0x06eeb1b229cfe57L,
  35840. 0x1278b05b2892b7dL,0x117da41d4560f31L,0x01c2f5ed53fa47fL } },
  35841. /* 39 */
  35842. { { 0x114165eab40b79cL,0x1bbb6096d226a0eL,0x2b7d8a6c107fbfbL,
  35843. 0x22e3807ca2f684dL,0x1a4d79907d431dbL,0x11c79a161397437L,
  35844. 0x376ff869a91472aL,0x047f56341a5a660L,0x006ce369b74c463L },
  35845. { 0x00773d11add1452L,0x3a7257b63a68a9bL,0x0e32ca15a40c2e4L,
  35846. 0x0dabd8bc63fa3feL,0x2eec9484b3fcb7dL,0x2c81016cb28cdbbL,
  35847. 0x2d8352a4d6e7a93L,0x00f9db64340c655L,0x0e5dd375603d9caL } },
  35848. /* 40 */
  35849. { { 0x05f297d8b481bf7L,0x0a8f90a84ce0f33L,0x128cdc40b96c06aL,
  35850. 0x17c462768f27851L,0x16cd57fa79a2bf3L,0x0d5f4caee2b6e62L,
  35851. 0x176fadc1a4935c9L,0x0f78547ec96030bL,0x1ba98721eb424f2L },
  35852. { 0x002daaf52a4b397L,0x17d330342d39523L,0x0db37b7e79cdc3cL,
  35853. 0x3b2cce5c2d8a6f9L,0x092808c7ff34336L,0x08a236c7b4f72dfL,
  35854. 0x2ed59aec290eff0L,0x3e97ca91e7547a5L,0x0929d7ed87076d8L } },
  35855. /* 41 */
  35856. { { 0x0edaf0be660043cL,0x28b32c05b81d376L,0x28e7e2cc3b3d84aL,
  35857. 0x0c1709a7f12748dL,0x13de33e3647b501L,0x2272941340653b8L,
  35858. 0x0db11ddb3361b97L,0x24bc2335460ce61L,0x0c6d5b801ecc8ecL },
  35859. { 0x3f91c1547ab9887L,0x2178a9ad6ac044cL,0x0e5a133fc8182f2L,
  35860. 0x1d0e361a4b26dcdL,0x043282e815c435aL,0x31ef36a8f24ad1fL,
  35861. 0x158c86191231f59L,0x0f328eb90970d34L,0x0117f568febc5a2L } },
  35862. /* 42 */
  35863. { { 0x0cbd9d5bf5caa87L,0x3f183da37632763L,0x0dbbc7d4dede17bL,
  35864. 0x11609c2d6fd8fadL,0x1cc098fe7bf6e59L,0x175ee3d621c4de9L,
  35865. 0x25a533ca5eb6870L,0x029b12df7bbb92cL,0x0ef8e045c324a70L },
  35866. { 0x20c1c9270cf52bcL,0x0fd8ea43318a605L,0x021cbf3028fb4bfL,
  35867. 0x35d48efbfc57ffdL,0x38b9ce1050a8102L,0x19886c7bfccc268L,
  35868. 0x0a78078e9da4d00L,0x2184a5dd7e27f30L,0x0eb590448650017L } },
  35869. /* 43 */
  35870. { { 0x26664fdebbd33ecL,0x269983396b55e62L,0x2c0550fb56ed0cfL,
  35871. 0x2b4756aa9bbb341L,0x3948a7f07b4ca5fL,0x3f870468db6bb96L,
  35872. 0x12544bd2e37887eL,0x363a907d86b1247L,0x0be49df70712bffL },
  35873. { 0x0e2f1f565acdb56L,0x04f21179796f798L,0x1354e17a0412f2fL,
  35874. 0x33f6724efbee5ffL,0x325a957e48a2867L,0x28618d7e72a745aL,
  35875. 0x26ae711f55c19b4L,0x150766ce1a3d634L,0x000ac4480414c94L } },
  35876. /* 44 */
  35877. { { 0x01bcf89d4ad38dbL,0x03ce04f5c51445bL,0x2759cb70243a118L,
  35878. 0x18c58e9c5b16d30L,0x213648bdb5dd64dL,0x137a65a6ef4bbfaL,
  35879. 0x1e8c45a47187f9eL,0x3429d9779a44b8bL,0x048e075f29c4bdaL },
  35880. { 0x03354745e4dd88dL,0x20d8e2015debf00L,0x1c01227288f7182L,
  35881. 0x2479a26277b92cdL,0x1cd3f71bad008fdL,0x3936878908508c5L,
  35882. 0x262bb15cb023ff3L,0x13f95f9ae70d6d5L,0x072143f41657fb0L } },
  35883. /* 45 */
  35884. { { 0x06b046c26f40f2cL,0x3491b1b35f0c76cL,0x22701953a9b7bd5L,
  35885. 0x2e23c010dbeaa95L,0x021d0660d5ac929L,0x2f5b6f9864dce4bL,
  35886. 0x3c43f9d279ed159L,0x34094ddf1356b45L,0x179800eda50b8fcL },
  35887. { 0x08ddc0b36132f31L,0x3d3c04ab79ce8eeL,0x1ec3203de2b96f8L,
  35888. 0x0508c6d94cce216L,0x0a14093caedb038L,0x30af8be6b423348L,
  35889. 0x2bc09fb9f86d445L,0x11e37f4f654cbdbL,0x13d757b58991aefL } },
  35890. /* 46 */
  35891. { { 0x19ad100580f894bL,0x09222b649791bdfL,0x3e142e5a6865b61L,
  35892. 0x14c5fe6a04d1525L,0x2f8a33541c86e10L,0x299b55e362aa082L,
  35893. 0x358e23a67906607L,0x2ad711f7d82b97dL,0x107cadd4c90a7f8L },
  35894. { 0x16b044f6764ad0eL,0x3f8384940626ccdL,0x0a625f14db6af69L,
  35895. 0x27c6f5df550b7abL,0x25cfa895ce9f277L,0x1bc66b0e5e6447cL,
  35896. 0x2f44b1d4e94cedbL,0x09fd70d4cd05c06L,0x03bcac43fff50c7L } },
  35897. /* 47 */
  35898. { { 0x342951c83c1d4cfL,0x1e4742c9170d3c5L,0x0ef69c2dcc71e03L,
  35899. 0x0a4a8c41d9faa3eL,0x3b12948bd2ea57aL,0x3fabae0c956d1aeL,
  35900. 0x1abf592adc1e090L,0x29a26834b463112L,0x0199e8c9ff5c4a8L },
  35901. { 0x1f7b9cdeb28171aL,0x1e100f55da61ef2L,0x33bf22ff824cefdL,
  35902. 0x24efcccf31562d3L,0x2b01ceb72ee09b3L,0x080a6737affe0e8L,
  35903. 0x2bf7515bb34c452L,0x173ce8f0fa2819bL,0x1a65dee07bb49d0L } },
  35904. /* 48 */
  35905. { { 0x1a958d6b114257bL,0x2bf507525d78c02L,0x39b53aae7b11729L,
  35906. 0x24fb746b20c1ca1L,0x11eb679750791b0L,0x099d6d2b3fbf1f4L,
  35907. 0x29517f0e54bd37eL,0x0268e2698b5fa35L,0x06b96f805d82021L },
  35908. { 0x015d51757b5f9f4L,0x2790d9016d13452L,0x1de0e4870160e5cL,
  35909. 0x2547bdacfe0d10bL,0x1f7497faf953fefL,0x05bbc2de467933dL,
  35910. 0x12eeed24e3cc4d0L,0x05c0ff172aa1c94L,0x1b6f1ba4029a3bdL } },
  35911. /* 49 */
  35912. { { 0x2668435529252acL,0x189b01d39ec360aL,0x0cc1e0be86ab3daL,
  35913. 0x3dd3b57714d5420L,0x00cd41fd0534a53L,0x19d22472a7bfc50L,
  35914. 0x13b5ad0e7c945c5L,0x026237a92e257b1L,0x1ffefc67bef1515L },
  35915. { 0x08dc109306033fdL,0x21e5e7cda1d7666L,0x2f26e3c335c51b2L,
  35916. 0x3f44938a75934e6L,0x0c41dbdfca47259L,0x33036255758315cL,
  35917. 0x28ff8606224b610L,0x21c1e81075397baL,0x1fd2920e15cae4dL } },
  35918. /* 50 */
  35919. { { 0x2d15f0ccd67da85L,0x22dbd16b1528559L,0x2021f1ac71c3ae9L,
  35920. 0x0991d564890bc17L,0x166e856dc1feb22L,0x3ed2e91ca8bc558L,
  35921. 0x1d920b65eb14566L,0x32e6cd1a22f4a8aL,0x061943ce86ef9d4L },
  35922. { 0x0696218aac91174L,0x1467b1077648d2dL,0x2df29f0763a485bL,
  35923. 0x09dc4b22ccedfbeL,0x3b053863098517fL,0x3fcf8f9280b9fb0L,
  35924. 0x09648646bc45bb1L,0x2e4fd1aba25bca5L,0x1462aeb1649ebd2L } },
  35925. /* 51 */
  35926. { { 0x334f41fe8e4d3c3L,0x361ffd6edfa76c7L,0x2c0ad910b579c80L,
  35927. 0x186e1cd26bbc085L,0x02b0a6cc02a24b7L,0x3cb4655c152f14aL,
  35928. 0x3e6cdd3b4c7029aL,0x028d0392e438ab6L,0x0cf8e774f812606L },
  35929. { 0x07f9dbc2e229950L,0x07e11b67e0adc0fL,0x19a3f10c05f3ab1L,
  35930. 0x13c3c608328adebL,0x0ccbfb332203eadL,0x199c1bc5476f2f2L,
  35931. 0x059d5e3bd9caf00L,0x3993968e6f89418L,0x14c984387c8dcafL } },
  35932. /* 52 */
  35933. { { 0x08a757f8e011531L,0x16c5cb0f7355f1cL,0x09fdc2d99e297f4L,
  35934. 0x07ee4ed9056a3abL,0x0a5488e869d4ee8L,0x2edeadc2960ced5L,
  35935. 0x3df3a9ddd561c30L,0x0ccaed6f68e12ceL,0x124f909f8e01ddfL },
  35936. { 0x1b8aa84ab41e782L,0x08049a14776e1f1L,0x2a7d99482bd21deL,
  35937. 0x3afd2d904efd26eL,0x37cd1e22405963dL,0x2eb583bbb4da7eeL,
  35938. 0x2e30eddcf495dd1L,0x084b7ad1d5a4e24L,0x10baaf11bd8af0aL } },
  35939. /* 53 */
  35940. { { 0x146017416ec64e2L,0x052b3df5f1baf9cL,0x04a3668b7176bfdL,
  35941. 0x3cdd06c107078d4L,0x22d3b67b072e3f3L,0x15f64a35947e952L,
  35942. 0x08f419623edca3eL,0x2ebbca6dd3a2dcbL,0x0383d99cb47327aL },
  35943. { 0x08dd0b3da342a3fL,0x00918b7bd2a5520L,0x242eeab5a860120L,
  35944. 0x0141b952db46c71L,0x310c6cf1a5e1e2aL,0x3e40f3426e85c43L,
  35945. 0x0166f5334fc3660L,0x10d4e5a7800044dL,0x0fafaa26074155cL } },
  35946. /* 54 */
  35947. { { 0x05cd0e6712de285L,0x3fe2c21a7d77172L,0x2b92df4ed389cd2L,
  35948. 0x0c156e67210dca8L,0x2e07a003363524dL,0x1b82524d1bfbd68L,
  35949. 0x28952b0a2c82dadL,0x1fadacd899885caL,0x02c9afcb188af21L },
  35950. { 0x3b9d4769a64c5b5L,0x23577913133f874L,0x18ef11c6dbffa0dL,
  35951. 0x23d07052bb55821L,0x235efe854ce1d97L,0x11d15d74947e79cL,
  35952. 0x289c03f9d0c14c0L,0x2770034b20e3af6L,0x16fa25f040b36ccL } },
  35953. /* 55 */
  35954. { { 0x23d9dea9cad682dL,0x32c6cd18da4e46cL,0x19885c0f24d787aL,
  35955. 0x31f50620f3a7d70L,0x353555e46dff62fL,0x2473681746aca77L,
  35956. 0x0633ed569b1cb28L,0x150a36c536f114bL,0x1941acbb86c2a34L },
  35957. { 0x06a70c824db8127L,0x1958fd06df3d6f6L,0x1abeb908d9b484aL,
  35958. 0x18e2670982a3613L,0x344436957aaeaaeL,0x02a4b2344fb5acaL,
  35959. 0x0bcb973bc94f99dL,0x1597e5e3cb8af41L,0x07456a388ef716aL } },
  35960. /* 56 */
  35961. { { 0x082dfe496fc1f77L,0x310d7c4d1eb5a98L,0x14dc25ebe457b04L,
  35962. 0x1a6dbdd92abd09aL,0x104d83da164a170L,0x03208cc380e1cf5L,
  35963. 0x239b3eb0b9db52eL,0x0536a621acd3b50L,0x16a76587f2a5988L },
  35964. { 0x118f8e8ebc71a5dL,0x10690a150148cdaL,0x09ccc182cbcc491L,
  35965. 0x34f82415e9f58fcL,0x1e239d8eb4afe59L,0x365252cb98cf6c3L,
  35966. 0x04fd61bac8582dfL,0x3bf662e4569051cL,0x10ee0866a9dfceaL } },
  35967. /* 57 */
  35968. { { 0x350c47052e07a4dL,0x34e2e3975d1740aL,0x047ce1af12267f6L,
  35969. 0x12ce71417ded053L,0x186f739be03e4b4L,0x1f0bc6f167cf5e5L,
  35970. 0x23fad4ca19bca7eL,0x22bec7147007b01L,0x080da3937a57f42L },
  35971. { 0x1d8ca9d102369faL,0x26ffedc1b038d7aL,0x19a796b55d80e00L,
  35972. 0x37ab0342530b828L,0x1787c187ada0e42L,0x33e812d9b06f8b1L,
  35973. 0x1773406d4ae2cc9L,0x18a156c33a981d9L,0x0d82d525245c7c9L } },
  35974. /* 58 */
  35975. { { 0x1cb238cae93de69L,0x0f20cceff6ba6dbL,0x1f4de8b79836496L,
  35976. 0x112ba2fe2b8cf20L,0x24c3ebacce13a22L,0x15696b582f1b9e1L,
  35977. 0x3e9459a837a53c5L,0x1bf361d7634d6f1L,0x01fb3705534f9f4L },
  35978. { 0x0e9270c7fb974a1L,0x123e83a7b49205eL,0x2c3d64bffbd4234L,
  35979. 0x10f5e7d2cf05059L,0x13b9f32a0a05aa4L,0x32408d7b615693cL,
  35980. 0x352b484bebcf8daL,0x027459612661e36L,0x183aa4d59f1e48dL } },
  35981. /* 59 */
  35982. { { 0x2585d75dbffad9fL,0x3d85d3d06763f3bL,0x3f59e6c6934564dL,
  35983. 0x3460f566c31bdceL,0x3929c8950b80793L,0x2658aeadaebd3f0L,
  35984. 0x291273bd445a952L,0x1e16d4ad86517aaL,0x1be4fccdfff3d1cL },
  35985. { 0x1c384d97cb2857fL,0x20c1601adeafd01L,0x1d1743ace6b24cfL,
  35986. 0x28af10f5adbd4a3L,0x314e564b92c7b8fL,0x0ae7c06a3c38a2fL,
  35987. 0x1383e61b69bc73dL,0x251aeae2fad00f7L,0x0aeaccea0c59791L } },
  35988. /* 60 */
  35989. { { 0x268baee0163c2deL,0x342cafac9da2926L,0x3124ffdae767c42L,
  35990. 0x3542ab2a50d5a1bL,0x2e01091cf926da5L,0x0c92fb35a670d33L,
  35991. 0x13a0a93d2545405L,0x332746dad63c506L,0x14ff144925ed611L },
  35992. { 0x361a60cc1ed9259L,0x0dea8cbc7569fdfL,0x313d07aef4311beL,
  35993. 0x12539be9ee80e11L,0x28bd3730c99f33dL,0x2e555f710e4a305L,
  35994. 0x22bee573cf8ccf5L,0x158402f1b518346L,0x14527cd194383b1L } },
  35995. /* 61 */
  35996. { { 0x3e651353427af4eL,0x302ec4c4364df52L,0x276acaa671c32e6L,
  35997. 0x3534ea70ddaf63aL,0x3471709aa9d7b3fL,0x060147004933a18L,
  35998. 0x28ee1c225ce41d0L,0x13b215224a13fe7L,0x13d22d829c9535cL },
  35999. { 0x301ed9da1b15e02L,0x24aeb0c07961a1aL,0x21835764135b1d0L,
  36000. 0x2ddbdc56692fe9eL,0x118090d0dc0ee59L,0x2014865a45c6814L,
  36001. 0x1279045c1531bbbL,0x1da15d024c3f082L,0x008963b48cc7633L } },
  36002. /* 62 */
  36003. { { 0x3e8b620f4aaaed5L,0x2379f7fa1c7ba03L,0x030ffebfcb4b106L,
  36004. 0x39f0e88556cac88L,0x02769b805d4dfbeL,0x34e7abc29e89aa3L,
  36005. 0x15f032377de7706L,0x2dcc7c6a4911fd8L,0x12aa1b81a8442d9L },
  36006. { 0x19e67d0b1152e8fL,0x1cf65e4ad78530aL,0x1073f1cb57a22e7L,
  36007. 0x272fc76928b8360L,0x2c22b449a03af0aL,0x34b5f4745a6c583L,
  36008. 0x098ee4b82c1ac8dL,0x3a855d422b29affL,0x15054992440e3cbL } },
  36009. /* 63 */
  36010. { { 0x0004a0aa13a4602L,0x31c68f434b1839cL,0x2463a6d79bc5505L,
  36011. 0x0eb553677d293f8L,0x373d3c7b8e878ebL,0x113b3e95fb32a41L,
  36012. 0x24d1795b3bb2782L,0x0abc228c3d87ec4L,0x1155b7e50014f63L },
  36013. { 0x2c42ecc9ef0021aL,0x05ff5fe15b27518L,0x03b82e6478bc580L,
  36014. 0x1a45416936c4389L,0x04cd7eea5af0746L,0x14abb42b66ec287L,
  36015. 0x09f09de8ba39a2dL,0x3e9901d1d126ad5L,0x13fd5c8f7bd9e57L } },
  36016. /* 64 */
  36017. { { 0x3d8ce7b5a53c22bL,0x0cff35f2ad11a86L,0x24e248acb394787L,
  36018. 0x07a8e31e43f1132L,0x315c34237a9888bL,0x2dc0818cdabedbaL,
  36019. 0x3508fab913b8a8fL,0x1ccacd2ddf31645L,0x050a931d7a7f9e4L },
  36020. { 0x10a429056d21d18L,0x198c1d56d04286aL,0x0a8b894a6b05826L,
  36021. 0x18e0a33dd72d1a1L,0x2127702a38a1adeL,0x37dedc253ecbe16L,
  36022. 0x0d1db683ff7d05aL,0x3357074fd6a4a9aL,0x0f5243ce1dbc093L } },
  36023. /* 65 */
  36024. { { 0x3c183c3d37d7891L,0x140527f6197b2a3L,0x03d68f21844117bL,
  36025. 0x095681fd9603db9L,0x3ad303202af51ecL,0x019dbbd63f969b2L,
  36026. 0x0e000c95de68f31L,0x14951d4238c7f29L,0x159783e5a957773L },
  36027. { 0x01db5712e537ad9L,0x1c44b4d6fa73defL,0x2b48d57f9bcb5e8L,
  36028. 0x242a2cf2f1eed48L,0x1e5ecdb5c1eff78L,0x0e1f9fb53cc1b84L,
  36029. 0x321e3d30da83923L,0x299f13647f3d1c8L,0x09f8487bb62e412L } },
  36030. /* 66 */
  36031. { { 0x2f5f80f8cb8e08eL,0x34b104925bfb5a1L,0x374360b7dcdf7cfL,
  36032. 0x37d5fd3417c0186L,0x2458061f24dbaffL,0x37a65312c664f0aL,
  36033. 0x07e0626c6ca8d09L,0x172f3bdc349349dL,0x0ffd4e5d4e3b999L },
  36034. { 0x171e245c6f40077L,0x0b81141c8f9418cL,0x2f7e6a6bfd88159L,
  36035. 0x345b6767380d721L,0x03eb5770cba0959L,0x10358f74b9fe3faL,
  36036. 0x1e441958eb0881cL,0x07d3558ccef6baeL,0x034fb0397df3afdL } },
  36037. /* 67 */
  36038. { { 0x384e05eb358815cL,0x32cb5390421f65eL,0x188907f05d7a3abL,
  36039. 0x355ea7520721e9dL,0x042d64cbd350778L,0x33ca27fa74d33feL,
  36040. 0x2b2c6e0859cd5acL,0x02d8a0dcb564774L,0x06bc06d482e18b4L },
  36041. { 0x10695a0da4ed375L,0x2bd620a636abab4L,0x21b4f4b7092c51bL,
  36042. 0x2b9e8cd6cd6c0a2L,0x20567efd88ab87dL,0x0c830dd29cd64d8L,
  36043. 0x158b307a49fc103L,0x33a6dcdeb2b128dL,0x01ed30696a34c0fL } },
  36044. /* 68 */
  36045. { { 0x1550ab0bd3902feL,0x292d2e1aa74ecf6L,0x20a9975cac379bbL,
  36046. 0x0c4ccd81770e967L,0x21afc2c58045e87L,0x3be72fc7cb16630L,
  36047. 0x383c4281ff8d6feL,0x0c7560afb57426fL,0x1579d1d9d5b5281L },
  36048. { 0x07da3055519258eL,0x14e7e409f78aa1aL,0x1747d6a230d673fL,
  36049. 0x08d7d745a11a7eaL,0x35f7e41f5ab1aebL,0x1a9ffacd6effa51L,
  36050. 0x2d5187bd546abb1L,0x14f74abef53a385L,0x1607437be13bcc9L } },
  36051. /* 69 */
  36052. { { 0x1f165a9ee9755a3L,0x35686ae0b26ac55L,0x245aab6b97e60c8L,
  36053. 0x2c2ac1789c59687L,0x26db0830f3004cdL,0x16b2f7ae7830ed4L,
  36054. 0x1e8498aae1ec1a7L,0x318b904f51211d8L,0x1e9589e09bbb1b9L },
  36055. { 0x35120819c72258dL,0x335cd170564f519L,0x3a7b91c11fdb61dL,
  36056. 0x2fe215e4239b189L,0x2530bc68ed1d3e9L,0x2d6d13fe6ab01bfL,
  36057. 0x10edd5125c16bb6L,0x36d70e2182edb6eL,0x1aa96fe8b08fbbeL } },
  36058. /* 70 */
  36059. { { 0x23a5dd8f257c0f8L,0x13724b74e84364cL,0x39cebbb8ce03488L,
  36060. 0x14e91c98aa40fcdL,0x352e06c6d6217adL,0x0c90a336877c805L,
  36061. 0x30c62cf5b723e0cL,0x20b307974e224b0L,0x1fdd9a90f1f477fL },
  36062. { 0x30d27ba1763ab59L,0x1f64f9c8de0fa60L,0x0264945968aacf2L,
  36063. 0x0c85c0357560556L,0x303146d9f63251aL,0x196fc3cb3daef9cL,
  36064. 0x2323fb6cdcf455eL,0x11d1202a803398cL,0x1496e49e62cd96aL } },
  36065. /* 71 */
  36066. { { 0x2ff0b7e40574c09L,0x3c990cffa03a5afL,0x1352eb237d91b76L,
  36067. 0x2ddfb70c4082cefL,0x3424a36dc3c0c62L,0x31b10d7be624e52L,
  36068. 0x08d076e9ea64c27L,0x2792cb7f087138eL,0x139cc3852f6a4e6L },
  36069. { 0x238a3ffbb096b91L,0x0b2795cf6350f94L,0x1b118c577558ee7L,
  36070. 0x34b711f52d3045bL,0x142e1955f54ec89L,0x10dd1d70801b74dL,
  36071. 0x2e9041004aed6a7L,0x0cb2707770ca8afL,0x1fb597417a2ed93L } },
  36072. /* 72 */
  36073. { { 0x00f1981859bae66L,0x23a6c61175f06cfL,0x1c03452a3c1eab4L,
  36074. 0x033fe040ce71b3aL,0x15f98d6fe2384a0L,0x2283756f35fb784L,
  36075. 0x3e1c06f7a00e3d3L,0x2987d5b765228f1L,0x0d09d21a7d18e53L },
  36076. { 0x1cfdbaf880eb3fbL,0x3f4a5d7a0fdf27eL,0x3d6fa28a74b464cL,
  36077. 0x17f7ec4f80d86e9L,0x3232a6128b8200dL,0x06a361b80ef23d2L,
  36078. 0x2d6ea7d1fb92c28L,0x06309a19d7eb9c1L,0x11d9b08608aefabL } },
  36079. /* 73 */
  36080. { { 0x3cf6146bbd2f539L,0x14bf01db89ae885L,0x1d18d4be4a67960L,
  36081. 0x08a7cfce6a0da08L,0x1433f873a8f8234L,0x05bd15a1a2e11aeL,
  36082. 0x1477507a1d3f367L,0x3889b7d80f8a0bfL,0x00377cb02c56975L },
  36083. { 0x275add38c01dd59L,0x04ea7ae7068debcL,0x11044dfc54039c2L,
  36084. 0x0181fb83619a42bL,0x1661fc40e202ee2L,0x02c0bd5a25bb7a5L,
  36085. 0x2f1a246b4d7398dL,0x1c49732e5a64796L,0x09fd5c281afc13fL } },
  36086. /* 74 */
  36087. { { 0x058c54bd7073a5aL,0x206972187ab1f72L,0x0a39e720201a87cL,
  36088. 0x23903800f3947e1L,0x358f199de952a9fL,0x15b300addaf712aL,
  36089. 0x3162f31cf12322dL,0x27846d98d398e0fL,0x16984c017ee8f96L },
  36090. { 0x1f433625c89f1faL,0x0a98c2da5ec1e3cL,0x1e5c4b05b7f44a0L,
  36091. 0x1453fb79330ccc4L,0x04b025aa4a7ccaeL,0x2136deb4349ba1dL,
  36092. 0x31c1fe7d5b77bbfL,0x33480e7bc6aa3d5L,0x18d65eba928418cL } },
  36093. /* 75 */
  36094. { { 0x37866ab8abb2537L,0x3132ed96cc25be8L,0x27ed2a428ad314aL,
  36095. 0x18843a7865a09feL,0x089801b4e95d19fL,0x2ba2e08cc7ae5e8L,
  36096. 0x1c9642aae77a62aL,0x22e125a4f58a97dL,0x0adff5bfe973e36L },
  36097. { 0x3efae21492b0deeL,0x0fa7ba580b0b3a8L,0x3c996f3b99e5214L,
  36098. 0x2c3a4ee3d6484d9L,0x01064c13edd78b2L,0x15ce39ea355070eL,
  36099. 0x33b1a4e6b970dafL,0x0823ebdbb305a0dL,0x180dbfa3f4f74aeL } },
  36100. /* 76 */
  36101. { { 0x024621a907a6aa0L,0x1b2da101e1e7dacL,0x0b688168a934ef5L,
  36102. 0x34e6e6a4121130eL,0x082541f2070d638L,0x3f222d41a5a32a8L,
  36103. 0x2357840c5970531L,0x2533d55937b56bdL,0x097e7e898c7c4d4L },
  36104. { 0x1dc98d96b6ebb2fL,0x285ff1eaa7849b8L,0x0fdbfa2a2c68292L,
  36105. 0x032cb86146ed83cL,0x181ca4cfe9c6327L,0x046567562636c99L,
  36106. 0x0b8d1994082638bL,0x0c253913cc23a95L,0x0d696399eb844e6L } },
  36107. /* 77 */
  36108. { { 0x200f362b83769eeL,0x0102b0fbf132cfeL,0x388957abd68772dL,
  36109. 0x0965029c4a30e4cL,0x3ec242a31622644L,0x168695464271323L,
  36110. 0x1c2172d1e48f1e6L,0x1ff51a2f5c3c412L,0x041c8692d2b709bL },
  36111. { 0x2388aa1df816784L,0x23229406f9d7393L,0x1ffb02a678124a5L,
  36112. 0x383b69c87826d27L,0x1e67a65eca73299L,0x15b1c6da282f47dL,
  36113. 0x05aa30d81e91e88L,0x2efc8debb8bd300L,0x073d94007500595L } },
  36114. /* 78 */
  36115. { { 0x112ac4a010c0ef3L,0x152f613a06c682aL,0x23dc4f3535090e6L,
  36116. 0x3ced1f4626a3c15L,0x2f238c09c10dc41L,0x106b3d9c48bb741L,
  36117. 0x358520224c16afcL,0x2b9bc732e4cd20dL,0x1271a4b5f292275L },
  36118. { 0x12fd4733ce688b5L,0x19b4df72a71a2deL,0x326e541711d0145L,
  36119. 0x3b8f30d06a3f3a4L,0x02122c11fe3ba14L,0x174de6d5ae2ad33L,
  36120. 0x122f91c0fa763bfL,0x25696578b4abbc5L,0x0acd4e21b3d31cfL } },
  36121. /* 79 */
  36122. { { 0x013a7791d8e061aL,0x01f9c2b32128c10L,0x0266eb2f636a627L,
  36123. 0x085dec97275ab02L,0x170ff35cfe917eaL,0x106262fb76de2efL,
  36124. 0x0ae4455008db2b0L,0x3439c3d6293f338L,0x043ed0923972257L },
  36125. { 0x0ad77b3e2e129e6L,0x312a1c3c6f935cbL,0x0dff20056333fb8L,
  36126. 0x304a9a4550ebb94L,0x2b8fe2640bc2658L,0x259682be5770332L,
  36127. 0x11d99e694eb5841L,0x3721df4eea94fb7L,0x0832df13b208a1eL } },
  36128. /* 80 */
  36129. { { 0x2ad2247d181c3f2L,0x34d6fbccdec8fffL,0x3cba74890672915L,
  36130. 0x23ff69e8e876d33L,0x179275686e4f70dL,0x3fc7de7889ad906L,
  36131. 0x1fa4e8e80408636L,0x27d8263a12ce73dL,0x0da57aa0be9d8a0L },
  36132. { 0x00cecf54efcea66L,0x3cabb2bf1dbebb5L,0x1a48c91585a898dL,
  36133. 0x29c4fc02a958fc6L,0x344b5cb9fb111bdL,0x149883459a1ebeaL,
  36134. 0x0b35abc6d5fb126L,0x3134abe54fc6eebL,0x0ed99709370ff94L } },
  36135. /* 81 */
  36136. { { 0x09f56e068b54c89L,0x3305f739cdf08abL,0x283fab089b5308eL,
  36137. 0x0a550fef46c823bL,0x0844dd706b0f3a1L,0x3b0b90346c8133eL,
  36138. 0x19914a80975c89dL,0x137dc22c046ba4eL,0x0176b4ba1707467L },
  36139. { 0x1216ea98fdfc175L,0x1ff18df83d6c31cL,0x285fceb33a3477bL,
  36140. 0x13c088faade2340L,0x351c6d922b67981L,0x304fd47641e1c82L,
  36141. 0x2d60b55859d5a49L,0x32acb9a7e142febL,0x05c2499a8446d0cL } },
  36142. /* 82 */
  36143. { { 0x1d581fb73e7bcf1L,0x37987374f05ef90L,0x17ecfa199fd916dL,
  36144. 0x1cf05676e5f18a6L,0x2641328301a7588L,0x250aa4613b5de25L,
  36145. 0x2ba4bb9672ce892L,0x375ffcfb9161e05L,0x1234fb7a148ce54L },
  36146. { 0x05d80aff009be8cL,0x24e35de37c6e87cL,0x2e84312de62062eL,
  36147. 0x1fd81c312e69f88L,0x3a1b5da3748d29eL,0x11c5d14d73670faL,
  36148. 0x2b9e671e51bd2faL,0x31a8650262ac15aL,0x049bb584abc49f7L } },
  36149. /* 83 */
  36150. { { 0x1f255301ea470f7L,0x2fe023a49538c2aL,0x29ea71a0038da01L,
  36151. 0x385644f2a1c2615L,0x3b8281fdb0d2b2eL,0x063970aab85c012L,
  36152. 0x2943abdb5c6eb01L,0x3540695ab19307eL,0x0531aaf64771a92L },
  36153. { 0x279ef4906345730L,0x2aa93a11bcdf0a5L,0x26b01a7c3aab946L,
  36154. 0x28a059b7d3be05cL,0x24e04dc3ecb808dL,0x1bb066d3a7ecff0L,
  36155. 0x16d13e9e0b61db7L,0x14e11b9fd997bbbL,0x0e570ed8c0786a7L } },
  36156. /* 84 */
  36157. { { 0x2456e58108ce13fL,0x3f163438e5e04d9L,0x284bea3949e9b5bL,
  36158. 0x2f1d6bd99f412daL,0x0a891566bea9b66L,0x3d856569f2d35b7L,
  36159. 0x2e25201b3cecf0bL,0x297e90c4b1cf400L,0x14b81d768986135L },
  36160. { 0x047bc25841078ecL,0x2a72585e7115350L,0x06094851f8fc75aL,
  36161. 0x0fb38d0247da858L,0x088e54102998d4eL,0x36a2b17a6a7d9c1L,
  36162. 0x2c230cbf280f885L,0x2ddd71932b2823fL,0x02b0ac864b05094L } },
  36163. /* 85 */
  36164. { { 0x3606e398f5daf7fL,0x2152244249d419aL,0x1c5c08c58a72483L,
  36165. 0x343243cfb8e8895L,0x008795f022f362fL,0x1097d6ab258cebdL,
  36166. 0x06dbfb71710bd10L,0x2ef370805f817b0L,0x1c8d9c7dc82c1b8L },
  36167. { 0x1b41fdf18b8bed9L,0x20cc238e88c495fL,0x1de77291c4bbe94L,
  36168. 0x0ad05122abef3e4L,0x3c44da4629b0b97L,0x06fd428a577f18cL,
  36169. 0x1e313190b9c4630L,0x2ab6462d9bdde1aL,0x0f5a8a4e2fa121bL } },
  36170. /* 86 */
  36171. { { 0x0a55109ca0251eaL,0x3bb62c9e9b26c23L,0x0beb5620f528f2aL,
  36172. 0x3a2b84ff15a406aL,0x085993c079a8421L,0x346ac35c4d27c71L,
  36173. 0x35d90929e083590L,0x299be5b8a4a6ebaL,0x0ce96c2f1f8f599L },
  36174. { 0x0bc4b5112be8bd7L,0x11a83cf19fa66f9L,0x07d34d3a3864f48L,
  36175. 0x049cfd0e6076273L,0x026dce5671f6471L,0x00ac25af0caf0c9L,
  36176. 0x0682b7f7134ebffL,0x22d655813c02c34L,0x11cfd23d7eae3ceL } },
  36177. /* 87 */
  36178. { { 0x09646cca27689a6L,0x1f710d55905cafeL,0x248eb57cbfccd6aL,
  36179. 0x3ed6c6b7f94c2f6L,0x3711d8bf49b11ffL,0x1c39696e7cb6036L,
  36180. 0x118a1de879fdf0bL,0x354125d4d060dafL,0x114c8c526bd8cbfL },
  36181. { 0x1fe725bef7388bdL,0x0f6f7f9ffeba9f5L,0x1b897e6de2acf1cL,
  36182. 0x26a7afc6fede0e5L,0x36978514681a72cL,0x1499c2bd94995c1L,
  36183. 0x157d483925ecd9fL,0x32c090def374a0fL,0x1ceb5d732a7c80eL } },
  36184. /* 88 */
  36185. { { 0x3f9fccecfd376d7L,0x3aacfa99ac21369L,0x0d08d5b91bd86b4L,
  36186. 0x1fa2a8c1361ab24L,0x37f866a4faa3d5bL,0x2e04eb849fcf50aL,
  36187. 0x0a920695d19fa8bL,0x073774e1e635f8dL,0x073df7c0a69a32cL },
  36188. { 0x22c01bb38315b16L,0x29f226786323e6fL,0x3fb408b6b8531daL,
  36189. 0x231a024aa068f50L,0x2836faad4b159e4L,0x11a65cc1dfa4f67L,
  36190. 0x17e476d4ed6361aL,0x07e995a72cfd98aL,0x185b69d8183e781L } },
  36191. /* 89 */
  36192. { { 0x0f27eb3ab9cb764L,0x3bf0863af075b46L,0x0ddb0479aa79bbbL,
  36193. 0x09027950bd51dd8L,0x1bc699b96b4d16dL,0x3236322b8d70e34L,
  36194. 0x23a45d13b2ae258L,0x1301215e705499eL,0x0d9773b73576c55L },
  36195. { 0x220a4730218c299L,0x38a6ce67de28ce5L,0x2009484f414f69bL,
  36196. 0x0de68b293511a12L,0x268db7ab3b2c749L,0x0d70d5fc2701dcfL,
  36197. 0x3de3f26181f0599L,0x1b82024c4c0f62dL,0x060f3effcd0e0fbL } },
  36198. /* 90 */
  36199. { { 0x23c14beb25d6530L,0x056ce66a5f503dcL,0x3c4bfbf7f6225e0L,
  36200. 0x27052d3c3c48270L,0x23f7e8ecf83d8c5L,0x3ac7bc3f3c00bf7L,
  36201. 0x1f0c6035d353c91L,0x3b8d0e5310a9480L,0x1b5787128ab7be8L },
  36202. { 0x0937d3ab70110cdL,0x293bf11de446d68L,0x2f5bc53a4c19e0fL,
  36203. 0x3cce35427cb1ab2L,0x3e54ac1c6bd3010L,0x13ca8efcfb8aa0aL,
  36204. 0x09c7b931ea67c3eL,0x0d8bde93299bbc2L,0x0b05bda2c4f34a2L } },
  36205. /* 91 */
  36206. { { 0x024a071d1f575cdL,0x24ec06948dc60adL,0x36029a2c9d40156L,
  36207. 0x22e72452980504cL,0x1095b31c150c434L,0x0bf5258a40915cfL,
  36208. 0x10b2776f975fd22L,0x24dee85c1221b88L,0x1f6ac29b8136dbaL },
  36209. { 0x1edef55775da491L,0x14fe78adaab6082L,0x21061bb40d5b259L,
  36210. 0x04535449f619a5aL,0x181ead062cfc453L,0x3cedc48cbc8772aL,
  36211. 0x06f20d3f3e4f07aL,0x3d6ec4b341ae259L,0x15e241363696910L } },
  36212. /* 92 */
  36213. { { 0x0844fd03ecfc44eL,0x17cb21410ecf543L,0x27dbc9bd059a409L,
  36214. 0x3ebd96fb37e697fL,0x1a67961cd239328L,0x2ed77f778c4091cL,
  36215. 0x3dc5baea9e39bfbL,0x30de6008adb404cL,0x141bed7aa9b5f12L },
  36216. { 0x16f0059fd94d941L,0x3a7c01f53fc0602L,0x3598779f05e3fc6L,
  36217. 0x2cc0120f26798ebL,0x372a198704c40f0L,0x192929c4134bfbbL,
  36218. 0x367f1edb773b5b4L,0x2f4a802d9dc3d24L,0x1694f7e03012a9fL } },
  36219. /* 93 */
  36220. { { 0x1f5dd738a9095fdL,0x1e80874f3a15e83L,0x396be5edc767c4bL,
  36221. 0x3fc6028202242a9L,0x366f10aab56497eL,0x261e5d9ae615b87L,
  36222. 0x280601312988243L,0x2a4a585d233dceeL,0x01207d9076c555dL },
  36223. { 0x3049a011c44394dL,0x097bdc339279142L,0x09f0b1694265f5fL,
  36224. 0x3f8426ccfe078e8L,0x3a30932e42c5bd9L,0x1b3e2bc81fca90fL,
  36225. 0x366722736abfcacL,0x09ac2b7dfe813ccL,0x0e02f1e92fbfa9dL } },
  36226. /* 94 */
  36227. { { 0x124e4a663be4d4aL,0x15efb59bcf32465L,0x13fa7e7a7ccd1faL,
  36228. 0x1aa2317474f75f2L,0x23f251f1e70e8cfL,0x0d5533d6c95e65eL,
  36229. 0x1a71090a5ec58eeL,0x227a9a349a35c19L,0x04c7c23d4d20850L },
  36230. { 0x3ae575bbd52d132L,0x236a9ce32073158L,0x2e51e4e63b990fbL,
  36231. 0x19ac8e74e1c25a9L,0x0a5d49fed51d6b3L,0x0ea301ebb57e21dL,
  36232. 0x286ae2025091d94L,0x3bd68403e116b91L,0x1c21af59d747eb4L } },
  36233. /* 95 */
  36234. { { 0x37bc01edd441308L,0x0d251218c222417L,0x0a74759611cd0dcL,
  36235. 0x185308f3998abceL,0x1f8bafed211a712L,0x324f81e4dfcc5edL,
  36236. 0x0c52cf4efbb9ff4L,0x360aa203c3b763bL,0x028480cdd2cddc9L },
  36237. { 0x0f1ca0dc3f807acL,0x393f0af41c1527aL,0x0a1491f8bb6c6a3L,
  36238. 0x3f4f5b7eb36b4f4L,0x15fb46ffbe3ee1cL,0x37573ef3b91ac6eL,
  36239. 0x38e8b75207b3ac7L,0x3446b56030366c6L,0x08452c669f4c7bdL } },
  36240. /* 96 */
  36241. { { 0x02b4747c0ace6d5L,0x32d92ef9ca1eb69L,0x089989bc2614d5aL,
  36242. 0x0dbfc171c7bccc1L,0x2d35ac450817fe8L,0x1d6a70f1dcbac91L,
  36243. 0x00d6fd7f5fc2163L,0x25ccfedbe786b2fL,0x09a7643c315720eL },
  36244. { 0x32216b4f3845ccfL,0x1d3a0242f016f52L,0x0c74d60490379c1L,
  36245. 0x2858d632019e954L,0x1aa677b6dbd7220L,0x1b8b823a0e3e710L,
  36246. 0x2f6da537332c196L,0x18c36c0ca1d7925L,0x00c52b274cf9c30L } },
  36247. /* 97 */
  36248. { { 0x2c2e7828ea58bebL,0x013074d997e921bL,0x1fad20b40ff02b4L,
  36249. 0x2d8a74f9a9551b5L,0x166c81991fb5df7L,0x38b3f8fbc61a11bL,
  36250. 0x10d16bbe690bde6L,0x23a4a5ebae68050L,0x0cb59d81548baccL },
  36251. { 0x105d3adbaf66a23L,0x0dce1d037ec2076L,0x35de4b00f432c33L,
  36252. 0x3a01f4e80f9b554L,0x3066bca80e17fe8L,0x2b7fe954a5513fdL,
  36253. 0x226ea460c2b96cbL,0x13ff27c06365116L,0x11ed543816724a3L } },
  36254. /* 98 */
  36255. { { 0x2a873fbbd7f8a61L,0x2335c6ef9602ed8L,0x1eb3667f69805e1L,
  36256. 0x1855c74f703f572L,0x1783f9bc8ab8d4fL,0x10e62c538b91485L,
  36257. 0x1811b536c3774b2L,0x38f0cb6d28d8dd3L,0x1389f7f12972debL },
  36258. { 0x397f21c798fefb2L,0x1bf2d441eea9caeL,0x3760fadbb5689c7L,
  36259. 0x39f4cfa9b144befL,0x3236134a51a648bL,0x261624ed04a8a64L,
  36260. 0x26ada44a3d81698L,0x2d15d8512563cf9L,0x140b4dfc79b7687L } },
  36261. /* 99 */
  36262. { { 0x3b145707abe5bb9L,0x32ff63947606fa0L,0x1f49c9827affae0L,
  36263. 0x1229a1ed550836bL,0x3eeb41733c3a725L,0x0e09f18c20098feL,
  36264. 0x23b70e7014fdc3dL,0x1c5a1f4063e12d7L,0x0151d483e00fbcfL },
  36265. { 0x14e3c7c6b578aa3L,0x33a6d74c10f6b85L,0x1e9bb6008101511L,
  36266. 0x04bd016b1bd57e2L,0x02008ac7b4ec311L,0x1714be99f99a936L,
  36267. 0x0ac2eb73c00d392L,0x1d14fb86e66622bL,0x08fdfa31d9560b5L } },
  36268. /* 100 */
  36269. { { 0x074a0e0251cf8d8L,0x225274107caf4b3L,0x0a4933ebce52d4dL,
  36270. 0x145716f36b82dcdL,0x016200b93e1ac5fL,0x1e4dcdbb4fb37f3L,
  36271. 0x2e69402506a266aL,0x3e4d56168722fa9L,0x00e081cdd539190L },
  36272. { 0x15f995653e28412L,0x149bcb6c9c592c1L,0x25eb1df3adc70d1L,
  36273. 0x32b74d77b773558L,0x1a838ffe2d2c453L,0x30339627b510a12L,
  36274. 0x19b609ad20c1375L,0x3ec1cb57eea06f6L,0x1ad5be41dcc622eL } },
  36275. /* 101 */
  36276. { { 0x23af6678f850756L,0x0deab94bced65d5L,0x0a53796842f586dL,
  36277. 0x27fdd0fe65c434eL,0x193f1a8bacdaaf9L,0x027df364be9d579L,
  36278. 0x10650b1af04e154L,0x3f6698efe682b5bL,0x00e67b1cead55abL },
  36279. { 0x260a8e0b5f43178L,0x3504b6730d6cccdL,0x3a63880f680856bL,
  36280. 0x198b988b1c4f5efL,0x36ff824457f372dL,0x36c13946b5edef9L,
  36281. 0x115c8d0f2bde808L,0x00bcb879e07f92fL,0x1941f475bfbb8e5L } },
  36282. /* 102 */
  36283. { { 0x1482bf9d63543ecL,0x32d9f2845fbcf9eL,0x0638160ccc63985L,
  36284. 0x355ca6f707a2b14L,0x1a22686df556cbeL,0x207addf358bb65fL,
  36285. 0x3a2ed9b124cb5fcL,0x16e5935ed3d99cbL,0x17260b29aa77833L },
  36286. { 0x1bfc7b6a43df7c6L,0x32b08ef081c1b08L,0x37bc345d958085aL,
  36287. 0x34a8ca822f3adbcL,0x2d1953c5e9d8f20L,0x13da0343c22493dL,
  36288. 0x29912c7d25d7c6cL,0x19131939a88dcb7L,0x0ebda1c06c452ceL } },
  36289. /* 103 */
  36290. { { 0x2677c5c411dd110L,0x1e1ea8b26471289L,0x2a41a45666d60d6L,
  36291. 0x2ab057e7c554ef9L,0x30e0cc7b273e716L,0x29892ac2a4ee18fL,
  36292. 0x39c260a40571172L,0x3c4c3979d95b868L,0x046af8d78b52ef6L },
  36293. { 0x16214b170f38dffL,0x1760a048e84415eL,0x04d4957ed8123e3L,
  36294. 0x2e83698058411a9L,0x154f84413618fa9L,0x27aa56af9f374a9L,
  36295. 0x2a30b4f1c2563e1L,0x26aa7111678532cL,0x183c748add661ffL } },
  36296. /* 104 */
  36297. { { 0x2981f399de58cafL,0x2e03f61d4fa990cL,0x1f242d11948605bL,
  36298. 0x0180fbac02b20feL,0x17c73d79cf490cfL,0x0935186d00dfc94L,
  36299. 0x2420cf844209fd7L,0x23e89ac0fdb489cL,0x1526f4bd29eb343L },
  36300. { 0x24d034ac389e51cL,0x2957a5b6df663a5L,0x17dee913c583acdL,
  36301. 0x1effac0d102cabaL,0x09d461e29079307L,0x10efe2faa85b8deL,
  36302. 0x3d8c3fb0a675330L,0x0977275d2690ae9L,0x0ec7c41e6d66bb9L } },
  36303. /* 105 */
  36304. { { 0x29b345dc5da8398L,0x1a107eece310c0bL,0x05627c3bb47abc6L,
  36305. 0x0adce34b37738ebL,0x3687311858fbeb1L,0x2f53d3d352f0ab5L,
  36306. 0x0e1b0e9521db1cbL,0x2f8f8a9a432bbf9L,0x194375215eb7bfeL },
  36307. { 0x0b234f12edfd661L,0x26613bb54b07d13L,0x3260d8f8f98c014L,
  36308. 0x391ef8e1640cb49L,0x195e8b672fe76e4L,0x0ac03a0950d61cfL,
  36309. 0x161eb8916c397ffL,0x06ef8ee6fdc16ebL,0x0007ee90182ae13L } },
  36310. /* 106 */
  36311. { { 0x36fea9e93fbcb5cL,0x2f960e7ea14a6f4L,0x3125fd611ba0382L,
  36312. 0x1ff362898dc2c90L,0x23d8d4704a59ae3L,0x13106de6ade3183L,
  36313. 0x249cc51bac243d4L,0x1fa7f10007fabb6L,0x0f6988ea44a83dcL },
  36314. { 0x190caa4f077f79eL,0x05d807678964353L,0x3bb3d21b4b77f4dL,
  36315. 0x18240df86d8477aL,0x2135becf0031b3fL,0x0a40f76bc44fb60L,
  36316. 0x319296f6c01379fL,0x2b614daf79f2a9bL,0x06c57d3b6849dbbL } },
  36317. /* 107 */
  36318. { { 0x23fee389abfccb0L,0x38a892e59db98e5L,0x0f0284ba6d276c6L,
  36319. 0x2e919614f47e1daL,0x11b8ab9b6c38ba3L,0x1e81ccc5b8eacdbL,
  36320. 0x233f3201fc97424L,0x379ebf7505c6094L,0x0214dacfa81ac61L },
  36321. { 0x25a9f37eaa3198cL,0x228d17f22e6754dL,0x312ad4f5ecbccbeL,
  36322. 0x180308dd452909fL,0x228a27b05e841ffL,0x0a167fcd767a316L,
  36323. 0x0bde372d3774446L,0x16fe0701183ffaaL,0x1810a0e49a129cfL } },
  36324. /* 108 */
  36325. { { 0x08203af45843c3eL,0x078c0eaafaeb9daL,0x08f3624df62b460L,
  36326. 0x22b48796aa0e5ecL,0x39a242b0e568734L,0x0a9db1b4b3c4b1cL,
  36327. 0x2751a2c848ed013L,0x0b416dcaa870bd4L,0x0f3b63296c392c0L },
  36328. { 0x24b42adc6f3d1f0L,0x37314cbd4cae533L,0x333583443d9c2f0L,
  36329. 0x3bb7237672d5e04L,0x1ee87192fb50118L,0x15d06708c0e7869L,
  36330. 0x396b0c9977267d5L,0x30d6918bbe930c3L,0x1f7454fb7963cd3L } },
  36331. /* 109 */
  36332. { { 0x0f281949d153926L,0x0a32460ad5d5204L,0x3b30509e94c942eL,
  36333. 0x0ab7a75ad5d2d08L,0x18b3ca314c5acc5L,0x18f56f16a9d1b0eL,
  36334. 0x0cc9890f4ea307cL,0x2465109554e8b87L,0x08e271198bff76dL },
  36335. { 0x3900e463c8e672bL,0x19d734fcb7f09f1L,0x11f7af2163c9703L,
  36336. 0x021eb3aaac1c125L,0x17e8d236974d699L,0x04f7045520bc86aL,
  36337. 0x36cd13dcfbc1dc8L,0x2bfc8338af20013L,0x03f2a54662c82bfL } },
  36338. /* 110 */
  36339. { { 0x1cf41e61588a8bcL,0x23343884314b2c3L,0x22bd758e7a456f4L,
  36340. 0x12d22e6e55cce15L,0x3a6b89b9e1600d5L,0x263320bd1877e02L,
  36341. 0x177147f7fd4f170L,0x317e459fc073452L,0x048b13385116116L },
  36342. { 0x2b763335d2617f0L,0x295dc9bb2e181b7L,0x032d1b91fce93f9L,
  36343. 0x22db212e65ea4f0L,0x1823ca5bef7a438L,0x168cbdaeffa0089L,
  36344. 0x0b5c586f19c0283L,0x07767c9b356b78fL,0x1e77f5ddc776d0cL } },
  36345. /* 111 */
  36346. { { 0x09feec86ee764c9L,0x3b20dac1f20b30fL,0x32e6a005b142d1bL,
  36347. 0x28ca7a297a9afc6L,0x23ffe241c70ef51L,0x0a59b0a145f4a63L,
  36348. 0x3acc76bb389e287L,0x086d4e8b6a2a4b1L,0x04a902c9126732aL },
  36349. { 0x2c51b9c8f7ce110L,0x0cea1ebac0dbc65L,0x10980a6a59e2dccL,
  36350. 0x29f9e36d40209a5L,0x0c95bb030ceaf26L,0x1310bd0a0bcf0e1L,
  36351. 0x2c4a0a6dd6e9f72L,0x0bbf1da3778a5c2L,0x16f4aedce4b03d2L } },
  36352. /* 112 */
  36353. { { 0x37f032aeded03c0L,0x128149623775341L,0x3c4f9a85be0f268L,
  36354. 0x1ff82e6daedb426L,0x2f2fb5887bdda0cL,0x30f339f865a271fL,
  36355. 0x0d2ae5f8a96960eL,0x0866ac10f6755daL,0x06829c8081bdb21L },
  36356. { 0x3f872fade59f006L,0x27ff1b2e5fbd69aL,0x15db58ae7ef8c2bL,
  36357. 0x287d332a87cdc64L,0x289c27cc4c2e23cL,0x21af73186be3183L,
  36358. 0x18de43eee5d7e7cL,0x3c22e4896d1fe6fL,0x0b453e7f4634b24L } },
  36359. /* 113 */
  36360. { { 0x0c496d0e3048bdaL,0x19d2650f0f79395L,0x09f74c2d509ee2bL,
  36361. 0x07950f14226b081L,0x3105a365bb01f69L,0x22c5c1273665828L,
  36362. 0x2c946734d93ffe7L,0x29d540a7e66cfe0L,0x091785c5ea20161L },
  36363. { 0x055f978953dbdb6L,0x3a13665fb2867edL,0x102936d4d75aea9L,
  36364. 0x2a30549dbe91cefL,0x347c76356a9c17cL,0x0e5ce34a73d984cL,
  36365. 0x3336094a68360b0L,0x1fc874f90c2a1a5L,0x1b40ae532dee2b2L } },
  36366. /* 114 */
  36367. { { 0x0110e825164cb8bL,0x26bd3c954a99f5aL,0x2d0e8d185527697L,
  36368. 0x21fed93ab138435L,0x3ac424592cf6c57L,0x33836042102058eL,
  36369. 0x04c15c5d8fff37fL,0x0fb262ca139276aL,0x010ed8055673266L },
  36370. { 0x06f403051f3ee9eL,0x38fba6ce2b7c784L,0x3a6ea13d64492e8L,
  36371. 0x1160386aec74f21L,0x10bfd729827b49fL,0x3f1e8d7f0a0f45eL,
  36372. 0x23ad4f8fe50fa5aL,0x077c9dcf69516b7L,0x1f878bfaae4d9a2L } },
  36373. /* 115 */
  36374. { { 0x260d8e8abad5678L,0x29cb3b9803096ebL,0x20b44c288e210afL,
  36375. 0x1db49533e7ee753L,0x0959e2ba564447fL,0x25844cb07ecdaf1L,
  36376. 0x140f19393c44d72L,0x199235ea2207ff0L,0x09127a861288d09L },
  36377. { 0x136c0218a9e690cL,0x331487aad3e856dL,0x0423b00ee54c85dL,
  36378. 0x096bcea392026bdL,0x0b7731d85b37935L,0x1073ed5787cd8c2L,
  36379. 0x3c4529b5361d781L,0x098d3a907ca7bbfL,0x0e8cf5755b19f7dL } },
  36380. /* 116 */
  36381. { { 0x1edb80dd212b398L,0x25860754f74dcc0L,0x20478a52fa95d03L,
  36382. 0x0ca9e0979b43821L,0x1330ece4fad1e64L,0x01e24dbf80616f1L,
  36383. 0x3f6ea3508f7313bL,0x1ad8077260bf679L,0x0e8dbf3a602d555L },
  36384. { 0x3763234279e05bcL,0x3d03b3d1114f4f0L,0x1f4d7fa307937f5L,
  36385. 0x0d84235f888c431L,0x3c2a98bbc5cffadL,0x1f51fe03cbc07bcL,
  36386. 0x322e1c30ab1719dL,0x37e51ef27e462a6L,0x1f9f53dc52ae834L } },
  36387. /* 117 */
  36388. { { 0x266b49ec183f89bL,0x2d7c097d601b53cL,0x02b594ec3080d3fL,
  36389. 0x100dc73645f4c29L,0x3b7f7e26d4b6b19L,0x356ded93dd506aaL,
  36390. 0x0036c5e55269eb2L,0x099d4386a1705feL,0x1cea0ff0f22da5fL },
  36391. { 0x02bd56a3a8e11f8L,0x190087d7e6ad518L,0x2c5a0ccc92d7298L,
  36392. 0x39948fd942f19d0L,0x3f7fabfb4d64569L,0x0f279b2f2391a06L,
  36393. 0x35ff20b4275947cL,0x2ba88ace54b54e3L,0x1b0818f8e381f04L } },
  36394. /* 118 */
  36395. { { 0x3e5bffae50d90f0L,0x0ec46fd4047370eL,0x2711a691dfac4cbL,
  36396. 0x0753a869dcf8432L,0x3e586eeb662ec21L,0x030bc7f56a5e7aeL,
  36397. 0x3bbfea4df16ab1aL,0x09bdbfa78fdfb15L,0x15e1b05960e5ae5L },
  36398. { 0x08e04a58630e62eL,0x00c439911f86dc7L,0x2b6143b4447a3d0L,
  36399. 0x145d18b9e8f3c79L,0x00002724d92abb8L,0x114a5b7e0c27a82L,
  36400. 0x0ed8121d805d70eL,0x351383ce126ccf5L,0x0962d6bffbc6834L } },
  36401. /* 119 */
  36402. { { 0x13fe58d48e07711L,0x20d92349c28ecb4L,0x092d8cdff04c70fL,
  36403. 0x1e145047c50545eL,0x03e4f8a5515bb65L,0x104cd8bdb0c7364L,
  36404. 0x206d4d73f871520L,0x0c5fcbf8097bbb2L,0x0ad32a6e417954eL },
  36405. { 0x238c63f69d147dfL,0x2ec1b9c42fcdedfL,0x2bef28d514deb69L,
  36406. 0x3ee34470f66e537L,0x10385c6044b2307L,0x1e003a0cecda77eL,
  36407. 0x101c1c68ea2f49eL,0x1e063c0a2c961f5L,0x055970782215cefL } },
  36408. /* 120 */
  36409. { { 0x0c351db54c1d751L,0x114c06e83e54484L,0x334fbfdc8bed814L,
  36410. 0x0e33c8da02a9dfaL,0x0e04f2860498d81L,0x1a96db6a4a30529L,
  36411. 0x1a910396192dba1L,0x10409277aa56d7eL,0x08580dd45780172L },
  36412. { 0x10725000e09221cL,0x016c87c877815baL,0x2fa1e0e6095062eL,
  36413. 0x1edbddd44a51232L,0x1f1f34aca657fb9L,0x27fc575974a646fL,
  36414. 0x09ec79a66cd5ac4L,0x2baa37075a25f41L,0x067388fca84e72bL } },
  36415. /* 121 */
  36416. { { 0x120b49da6ef1dd3L,0x281178ee9b35d99L,0x180af33d5f48391L,
  36417. 0x2cbbc1d1d2a7212L,0x278bfb1eae53cf5L,0x36a41bea8d6cba6L,
  36418. 0x1f2cf4eca97fd6eL,0x21627c6a4de246eL,0x10d667533693ab2L },
  36419. { 0x351049673691fafL,0x0f4ea755fb18616L,0x21bb930a8525dc7L,
  36420. 0x07902c16da5f8a4L,0x3413bedca094f57L,0x3469ae617a5a805L,
  36421. 0x2de8b79e7d4f728L,0x115355450ff68faL,0x0fb859b8444d16eL } },
  36422. /* 122 */
  36423. { { 0x022083e7c667aafL,0x1172e52a4732e9fL,0x19318ca0e94a335L,
  36424. 0x08f93aa831f287aL,0x242f56844c3afffL,0x0354b42e886b10dL,
  36425. 0x1301d4fcc68a8b6L,0x2f3850069616daaL,0x0a3547f762c907aL },
  36426. { 0x3dd3ed3fbe260ceL,0x1dd4b6037007e98L,0x375d6f1da3e4271L,
  36427. 0x1294987c43b57eaL,0x3d20cd6bb5f1686L,0x086b195af9ec7d8L,
  36428. 0x3b918e9d638c102L,0x0bee0c4dee3d99cL,0x17423eb44384adaL } },
  36429. /* 123 */
  36430. { { 0x14e27c42a1fbcf4L,0x34a16d7eb357b86L,0x2bdd915e66074c0L,
  36431. 0x043bc29aa69d70bL,0x1067cf4581e6965L,0x2fb87ee84f16be8L,
  36432. 0x1279e72be013c17L,0x33d6616901b5b6bL,0x0310042951d5142L },
  36433. { 0x2735ec1a22bbc45L,0x14e469fd5bd361aL,0x39d0236001de4eeL,
  36434. 0x146a8be3494c16bL,0x0187db78aa8b218L,0x06a2230c38b0db6L,
  36435. 0x3e7d5bcfcc083faL,0x3408ee476adfef4L,0x0f462d85460f4fdL } },
  36436. /* 124 */
  36437. { { 0x168ba024972d703L,0x132874e426280fdL,0x2542ae28c855fc4L,
  36438. 0x1816c6d14dba6e3L,0x34c7f7e484fd4f3L,0x08c208f4b822c1eL,
  36439. 0x09fd13042f3b982L,0x20d6727ff4c4c62L,0x1bb56af0652c6c6L },
  36440. { 0x1bf05e206e0f16aL,0x2b0beb5d191297bL,0x0a980f92c71afc1L,
  36441. 0x35cdb2002879668L,0x2236178dc13ae37L,0x2d1bbc417c83bf1L,
  36442. 0x2509e4443a58b82L,0x366c32545f73d10L,0x1667d0bb415640eL } },
  36443. /* 125 */
  36444. { { 0x2a30a613d22842dL,0x3803d6cf13b380eL,0x0f876df82b798c6L,
  36445. 0x1b5e34823161d93L,0x1e788854ada92d8L,0x166c2650294b4e4L,
  36446. 0x05fc9a499b26fbaL,0x3c4d17704ceb413L,0x1dda5c0926934e3L },
  36447. { 0x30dcac2fad6d673L,0x3f7c1403cecff9bL,0x1941631756e96d8L,
  36448. 0x24c2936038fb39cL,0x231d130013990f4L,0x156058e3cab2a4dL,
  36449. 0x1d5679ee91966c7L,0x07369b7c3d5d39bL,0x111be124868ccd7L } },
  36450. /* 126 */
  36451. { { 0x244c726475cc1b4L,0x3f0be4adce5e33dL,0x26d10e3d7eb7915L,
  36452. 0x06bd030e381969fL,0x1e1ad24fcbb44e2L,0x0d581b9662198aeL,
  36453. 0x0f93f7270ba4ddcL,0x2935f0e0d28b069L,0x02193d0c9a23362L },
  36454. { 0x2cb7b8cf769fd7fL,0x176a5e26884ee78L,0x0c566b910fef181L,
  36455. 0x0249a4c50e1ed3eL,0x1925b37c02088b3L,0x1a9903951dedc6fL,
  36456. 0x21c6efa049a9212L,0x15acb4f77c6f7f4L,0x0649b5f9d7d232aL } },
  36457. /* 127 */
  36458. { { 0x240adf8679a9c35L,0x36638f2dd35e5b5L,0x0ebb5f8e9dafcdaL,
  36459. 0x13ab5281cf1192eL,0x22edde557473861L,0x1db382e6f61b03bL,
  36460. 0x15fb96773317385L,0x2bab66d74cc9d02L,0x13672f0aeb3ee09L },
  36461. { 0x388c76d64e54ba5L,0x39ebc7711d34868L,0x29d1b2a7708163fL,
  36462. 0x27b784902b5fe8fL,0x2c720303a0447b4L,0x1af4084f67d92d9L,
  36463. 0x203ea5b1c78029eL,0x174ac72bc71c02aL,0x103179180eb3bb8L } },
  36464. /* 128 */
  36465. { { 0x1bf4f9faf2ed12fL,0x346793ce03f62abL,0x3db5a39e81aece1L,
  36466. 0x08589bbdaf0255eL,0x20cf5b28df98333L,0x00e4b350442b97aL,
  36467. 0x067855ab1594502L,0x187199f12621dafL,0x04ace7e5938a3fdL },
  36468. { 0x1c5b9ef28c7dea9L,0x3e56e829a9c6116L,0x02578202769cd02L,
  36469. 0x0225375a2580d37L,0x3b5dea95a213b0bL,0x05f2a2240dcc2dfL,
  36470. 0x1ba052fe243ed06L,0x25b685b3d345fecL,0x1c0d8691d6b226fL } },
  36471. /* 129 */
  36472. { { 0x22edf3fbf8015c2L,0x208db712540b62aL,0x36e0a6a43157e7fL,
  36473. 0x0968b412c33a243L,0x1a809dbab318ef3L,0x299f288673019a3L,
  36474. 0x3ebc49dd26937adL,0x261123c9f04b20fL,0x02987b3db2f3c9bL },
  36475. { 0x3e7aed0fd2e3dc7L,0x3a2f6dd057f554dL,0x2c9a58a45f25498L,
  36476. 0x2e882721743f035L,0x2d579e1ee83d5baL,0x140affb4c7b2371L,
  36477. 0x01bef11f4cad0baL,0x3299710cb9b387dL,0x1913b10afaabbffL } },
  36478. /* 130 */
  36479. { { 0x19f7df053053af7L,0x011d96ca2873d2fL,0x38fc7ce90438603L,
  36480. 0x1bab2317775105dL,0x3fb59ec618fbed3L,0x06c6fb3c9ec4c4eL,
  36481. 0x1973a99d2656ffaL,0x2d654cd384d1651L,0x18c3261888cc362L },
  36482. { 0x013a414aa7f6ff8L,0x2bae20feadf1ebdL,0x086b7cc307ba092L,
  36483. 0x0948d18403be876L,0x302140c93dc81c1L,0x184120d64f5349cL,
  36484. 0x1795f3a1ed7e3ceL,0x3505b8ae47b3f7cL,0x191160dc11a369eL } },
  36485. /* 131 */
  36486. { { 0x272f46e8b57d7ccL,0x02c3952fc08e1a6L,0x396e05b3a91d314L,
  36487. 0x2a693b09b8221b0L,0x3c50f58e91b9ab3L,0x1789abc1d0bfabaL,
  36488. 0x1cd9f71592c6085L,0x0b22650f351daecL,0x17c3ed97fd4c7f0L },
  36489. { 0x3b02503e6d54964L,0x34458b1a8c63014L,0x2cf49cc28c22d9bL,
  36490. 0x1000d4d190063fdL,0x2b4cc0668a45c78L,0x10b6f80e3a8ccd7L,
  36491. 0x36c3cd7ad727f8fL,0x0b5dac55fa447f7L,0x1b3a7f894c9ec99L } },
  36492. /* 132 */
  36493. { { 0x1e6e397af09ea77L,0x1d82e5d77097164L,0x0c08b94a197b26aL,
  36494. 0x2a2da3398663010L,0x15bd23564041bacL,0x25deccfe8668345L,
  36495. 0x3bd02986ca5b94dL,0x07e67cc7e1fe397L,0x0b8f76c55a6b190L },
  36496. { 0x35bf8c33846ec9fL,0x08817277ab29185L,0x1ec0a3108df0f46L,
  36497. 0x20f3ebb64a24b2dL,0x065049fb2879db2L,0x1bb940c51df7001L,
  36498. 0x2dce4548d24bac9L,0x1a13e9f6dac595aL,0x0fc0110cdabab1cL } },
  36499. /* 133 */
  36500. { { 0x11b66d84d308bf2L,0x04f27f598e00105L,0x1f92fd383bf9990L,
  36501. 0x210fff23bf1a24bL,0x0313ea287a10efdL,0x2837dd0149f8c5bL,
  36502. 0x2bd2a18ef6e3cd3L,0x3933b2e5b90c3dbL,0x18cc1ebecf2a70eL },
  36503. { 0x0d14ad71a70404cL,0x087743e738a8c20L,0x3cde3aa3e0726adL,
  36504. 0x0458d8e9a42e532L,0x1c6b1e2b40ab596L,0x1b3bb16f9c2ffd1L,
  36505. 0x3757c01296dd0b6L,0x247a3532ca9d1d1L,0x0aa08988ca63d7dL } },
  36506. /* 134 */
  36507. { { 0x22dcfcaf8db0396L,0x3a3cded08b69daaL,0x034996485724e8aL,
  36508. 0x311efc524fd94beL,0x2b0247a4ef647c3L,0x2baf6a3a2d802d1L,
  36509. 0x158df0abf3e4397L,0x2eac8b8748c7e9eL,0x0ef38e692b1f881L },
  36510. { 0x33c168926cf3047L,0x053e51654e61607L,0x1d1c293f20b6dadL,
  36511. 0x1bbd5eaec5ff7a1L,0x01794de382ea543L,0x2ffb34bc346a3ffL,
  36512. 0x3860429ba508e22L,0x0c7e0443c29ff6dL,0x1962ade6f647cdeL } },
  36513. /* 135 */
  36514. { { 0x196a537fec78898L,0x2779cb783e9dff2L,0x36acd34cb08f0b3L,
  36515. 0x20b69e34d4fdb41L,0x3a0392cc1acd8bbL,0x160552757fa0134L,
  36516. 0x27c6d9ab7adedeeL,0x0fcde20e4068301L,0x1915855ffa24ed9L },
  36517. { 0x1570e36bf9ebef3L,0x011a977d2cc5dcaL,0x1a95a6816b5ce21L,
  36518. 0x204a2343847e6e2L,0x13979159aadf392L,0x323eaecb5aeaaf9L,
  36519. 0x07af10411afee05L,0x38defc64b0ebf97L,0x0f7aa72e81cd7dcL } },
  36520. /* 136 */
  36521. { { 0x0fa3c0f16c386eeL,0x2c11a7530260e48L,0x1722876a3136b33L,
  36522. 0x248f101b019e783L,0x24debe27d343c0aL,0x25bc03abbc8838fL,
  36523. 0x29dcff09d7b1e11L,0x34215283d776092L,0x1e253582ec599c1L },
  36524. { 0x08ef2625138c7edL,0x10c651951fe2373L,0x13addd0a9488decL,
  36525. 0x3ea095faf70adb9L,0x31f08c989eb9f1eL,0x0058dda3160f1baL,
  36526. 0x020e3df17369114L,0x145398a0bfe2f6fL,0x0d526b810059cbdL } },
  36527. /* 137 */
  36528. { { 0x049522fa0025949L,0x36223c2ef625149L,0x2f5fe637216fb26L,
  36529. 0x1911ca09fd8cd10L,0x399fc2681d8ec3bL,0x231dc4364762868L,
  36530. 0x1b27626d232ead6L,0x27e9e396ff8bf94L,0x0040f9f4fedfd10L },
  36531. { 0x152ea516b4a05e0L,0x3523bbc871e3ac6L,0x26191997dfdbcb0L,
  36532. 0x0122d3087f5934dL,0x2be92303a0d11b2L,0x2317a0269bd5a6dL,
  36533. 0x005d8e2b8f60967L,0x27289c89ad6acdaL,0x1bdd6cff180db34L } },
  36534. /* 138 */
  36535. { { 0x09f8576943cc612L,0x10c67a0cacc71e9L,0x2297cccadebdc91L,
  36536. 0x10ac18660864897L,0x025b1cc7c4918fbL,0x191b97c2b32cc21L,
  36537. 0x0e3e22751d3347aL,0x00023abed2ab964L,0x151821460382c4aL },
  36538. { 0x02481dbbf96a461L,0x048ba6d4a8ee90fL,0x058e464db08b51cL,
  36539. 0x1e1b5a82074870aL,0x0f533cef7b1014bL,0x05517df059f4fb5L,
  36540. 0x1b7b9f6cfb32948L,0x30a67a91b4c7112L,0x081cfad76139621L } },
  36541. /* 139 */
  36542. { { 0x3796327478a7f0eL,0x060f8b785dc177bL,0x26df572117e8914L,
  36543. 0x026df354b3f4928L,0x3ad83c1603cdb1bL,0x027be326790ae7eL,
  36544. 0x254ccd6971d2ea7L,0x083f06253f16e3bL,0x0fcf757b4e534a5L },
  36545. { 0x25518cc86b62347L,0x072749ef0aa4a16L,0x2b052966727fec5L,
  36546. 0x0e82b90f9bcbba8L,0x205ca066bbc8a8eL,0x20ce61b6014d6d7L,
  36547. 0x374cdd91ffcdb18L,0x0890cbd296ee8c8L,0x12408763a490d20L } },
  36548. /* 140 */
  36549. { { 0x098b9724efac14dL,0x12fe369e6a74f39L,0x0dbdd6e07c29b6fL,
  36550. 0x3f5c5dc54e03c7aL,0x271b03263fac30cL,0x26d157d53247b48L,
  36551. 0x3092bfbf9383351L,0x0ef65da979e2449L,0x128a97674e1b481L },
  36552. { 0x1b63c41583e5924L,0x26bfc63c5c7418aL,0x33cdab227a2861fL,
  36553. 0x36a2846adc0ad16L,0x0e8db6971939d5dL,0x3b042014afed1ecL,
  36554. 0x0e1801562379df0L,0x12aeabd69920493L,0x1508d98c43434f9L } },
  36555. /* 141 */
  36556. { { 0x2a9fe73cfffc80fL,0x38ba6f50d1cfdb7L,0x3ed3c9d37ba7e23L,
  36557. 0x349e8ff0d5c9fecL,0x38e04a03d733766L,0x2ef83d0f436d33cL,
  36558. 0x186f4f8ce017522L,0x2c0df61fadc676aL,0x1536d1b50ae2fe6L },
  36559. { 0x31f5defda40bab1L,0x1aa2be6caf698cdL,0x1c890d4aca8707dL,
  36560. 0x3fd90ffe2ad7a29L,0x14bf8ec2f4d72f0L,0x3ae4f88a7130436L,
  36561. 0x2dfd0136b0eaba0L,0x2820af12c3a3c74L,0x1429f252e5a9d34L } },
  36562. /* 142 */
  36563. { { 0x2ffd4c17d0e7020L,0x1a6aaad52085a12L,0x1708588f348f9b1L,
  36564. 0x3fe21661aef6f80L,0x115f9c381daebf6L,0x12a529eecce61fdL,
  36565. 0x2d68497e455f2c0L,0x1e630e690510a83L,0x1541c1ad4a61ef7L },
  36566. { 0x247b628072709c4L,0x035a2e204397f9dL,0x0874e92e0f63b33L,
  36567. 0x2e7e2faa6eb46f6L,0x08318981a144e4fL,0x1a31a81f056bf06L,
  36568. 0x200b66e19c5c82bL,0x1ebb216315e88dbL,0x0119b25511007cbL } },
  36569. /* 143 */
  36570. { { 0x21ced27c887027dL,0x03ccd4afeaca184L,0x3c1c19d511e2605L,
  36571. 0x2a5fd31a7d5b8dcL,0x325226bb402d4c3L,0x0f9eb0c39bcd5abL,
  36572. 0x18fdfb3b9011c38L,0x28d8d0ec308f4cfL,0x00ba8c390f7af2eL },
  36573. { 0x030c3d67e851bacL,0x070e2697d513f31L,0x3c6467fba061899L,
  36574. 0x13a5f2f6fd001aeL,0x17734adadd49d02L,0x232db4a914e6df7L,
  36575. 0x24b3ad90ba8f9f2L,0x1a4a1ea4860c137L,0x06ab28732efa7b9L } },
  36576. /* 144 */
  36577. { { 0x1dab52d22ed5986L,0x3989e9614cf819cL,0x237acf155fe3deeL,
  36578. 0x035eba2c4cba3fbL,0x134a08b94cd6149L,0x270570c09c1b861L,
  36579. 0x25ad46a85ffd52fL,0x002ef568893cd46L,0x1e644d1b6d554d7L },
  36580. { 0x2830686862e4e9cL,0x335db121d8ff925L,0x1679c0839caafe5L,
  36581. 0x3ae360f58b580c2L,0x211bc4ae2c0e4cbL,0x13f2818a4478953L,
  36582. 0x22704596a0d7c86L,0x104b3d5e17757a6L,0x1be2f4677d0f3e0L } },
  36583. /* 145 */
  36584. { { 0x00012ddab01a6dcL,0x2f5b06b86b6da53L,0x1aecb9b05079391L,
  36585. 0x2798a84187ceb9fL,0x3a96536b7c2714fL,0x385d952dc65e3b9L,
  36586. 0x2b3dd4eec11bd05L,0x2fd871c459b83beL,0x1d70f7aa57287edL },
  36587. { 0x2ea6f7d51eb5932L,0x3a82a97e20b2909L,0x20977739f7dc354L,
  36588. 0x0aa6f95e4d05d6dL,0x378545eccd33519L,0x2d90f2766007d08L,
  36589. 0x23abec32b8e2567L,0x19426e504775c8fL,0x0ee656dea68cf1cL } },
  36590. /* 146 */
  36591. { { 0x138e140a0890debL,0x2f61f6f3ae12f53L,0x3f72ba041decbf7L,
  36592. 0x02a9a082fa547c3L,0x38c486298afeec7L,0x1c043b11d546428L,
  36593. 0x3879b1ecdba558eL,0x085733b6476e231L,0x14c08de3e4cef5eL },
  36594. { 0x01534ed16266da2L,0x0c8baded3240267L,0x0aef699276889ceL,
  36595. 0x1fc170a1134df7bL,0x31ac519ab652509L,0x168f321b48edf84L,
  36596. 0x0c4575682ebb726L,0x14dcc314c76e58aL,0x0be2e00e8b87380L } },
  36597. /* 147 */
  36598. { { 0x007c80057ed32e9L,0x39033df009265ceL,0x2abbabb54830427L,
  36599. 0x1bf3a082fd16141L,0x3b2c43e81564977L,0x3fbd9922d4d4ca4L,
  36600. 0x3bdca5671e8353cL,0x3f5e49c85f4fe40L,0x1dc40a9c109a813L },
  36601. { 0x3eaa6c33db21a38L,0x088b875cfbdf91aL,0x04e7bd1d507fcaeL,
  36602. 0x19161e9deac7fdaL,0x20c64a4d6f5bac6L,0x29f0de29631d3d8L,
  36603. 0x02e4094ca837d96L,0x3853fd0f7d4c4f9L,0x13f8a9a4347fb49L } },
  36604. /* 148 */
  36605. { { 0x1ab4edf992f8923L,0x2a9781bf4827ce1L,0x1b871b1340eee24L,
  36606. 0x07e4782ed009efaL,0x2f3d4c62c2957d1L,0x1ffdeabd096beb4L,
  36607. 0x14cbe92d231286cL,0x0d4a65904acac04L,0x19f6706a231c3e2L },
  36608. { 0x2b3bbd2225c02afL,0x2f0598fe8fa6341L,0x2b75b84f482e53eL,
  36609. 0x084aff1577e9b7cL,0x0512a73da912b45L,0x354faa90c2f6f50L,
  36610. 0x27fd53ac0f43d93L,0x092d3f0d63f9030L,0x0a32cb183be9194L } },
  36611. /* 149 */
  36612. { { 0x39b0c2d3fa6a746L,0x29e488756892a38L,0x091478cdf2b5e84L,
  36613. 0x1f4c199b2cdc296L,0x2f6d71d068a8806L,0x01974612c269c27L,
  36614. 0x1c944850007a3e0L,0x24eb1c11abd2ee3L,0x1fd2b6a3129c654L },
  36615. { 0x3d5d5bde45f2771L,0x0ac22bd0cbb6574L,0x00fbf232a6bb854L,
  36616. 0x10fa2fb32c8bb35L,0x2bf8e247f0fcb61L,0x368c0e6f3b3144eL,
  36617. 0x02a0df955d56f78L,0x3f8aa455f18655bL,0x18ca6d35cbf3031L } },
  36618. /* 150 */
  36619. { { 0x1800b1bbe0c4923L,0x2b9d01a40a41ef7L,0x337f957bd0c7046L,
  36620. 0x2765957e2e08e62L,0x2500f4150aa8e1aL,0x00b9ebbb34a49feL,
  36621. 0x29692e826a9c6d2L,0x15df2d33d62ce7cL,0x11f3093868cbf41L },
  36622. { 0x1cb5e7a333ed442L,0x3238be41bfbdeebL,0x01233d98f228ae5L,
  36623. 0x369fff84970b66cL,0x1ba2318354632f2L,0x0b4b14496521dccL,
  36624. 0x17d9c4a0caae5b1L,0x003dafc03996261L,0x172c5d1008654f2L } },
  36625. /* 151 */
  36626. { { 0x09540462fc283e0L,0x0ce611fb8220396L,0x340eb7fd1622f76L,
  36627. 0x07bd66317b7ebc6L,0x37e00d9bbecf515L,0x2310ff51ad364bdL,
  36628. 0x11d1d27543e3b3aL,0x2db4ce65384b194L,0x0c6dd841a1daf05L },
  36629. { 0x3da17e023b991adL,0x0ac84dc7ee94508L,0x2c5a0ddc1879aabL,
  36630. 0x2b57d8eb372d05fL,0x01e2a7d50173bc8L,0x041b4020bf3d484L,
  36631. 0x3012cf63373fd06L,0x117bc7a084779f6L,0x18ca07766d95765L } },
  36632. /* 152 */
  36633. { { 0x24347b9af80dfafL,0x2d8c7e71199fce3L,0x1b266ddbc238a80L,
  36634. 0x196aa1c6281bfc7L,0x0af31c35f6161e3L,0x31a11ba39fdeb24L,
  36635. 0x0175b4c03831d1fL,0x1cc68799a7441a1L,0x0c76da9d620934bL },
  36636. { 0x01f597ba3e4e78bL,0x137b7154267e6a6L,0x399593088c612c1L,
  36637. 0x01e6c81d162fcdcL,0x3a22769007c5683L,0x1f9b6bcf1110311L,
  36638. 0x129103b6df23c8fL,0x1e58d3d98b0950aL,0x0f9f4ea6db18b3bL } },
  36639. /* 153 */
  36640. { { 0x269eb88ced36049L,0x13ff87d06e67e31L,0x35636a72e10887aL,
  36641. 0x2319682ee29a42dL,0x096e4295567dd6aL,0x2aaffeb50b3e316L,
  36642. 0x2f26a45286b5f31L,0x3940c7df7ebca3dL,0x120c5d9e0ac0e1aL },
  36643. { 0x3bee3ffacc10da7L,0x0b57e651251b96bL,0x3e863c4220ff67eL,
  36644. 0x052f5bd8cba3b05L,0x3c3fc9ef4fe6f74L,0x0efee1c12a78f03L,
  36645. 0x03342d25ff3cba0L,0x334b863f4d802ecL,0x1ac1e63e7530050L } },
  36646. /* 154 */
  36647. { { 0x183d07c8f3d6a02L,0x3050f1fbd343477L,0x0bf0d4c7af6171fL,
  36648. 0x26209f173c32a65L,0x32b697882c8a93eL,0x2957a2e92840b1eL,
  36649. 0x2d64f0633c87d58L,0x007f06ba208bf30L,0x1c12ce9b53f986dL },
  36650. { 0x19639fd95dc1b79L,0x23dd50fd3985aa1L,0x3c4cede2fb9f272L,
  36651. 0x203543eba79b9c0L,0x3c2d530ed042f76L,0x375662b0151af0eL,
  36652. 0x29491000a4006bcL,0x258a4fcca1b2784L,0x14677782255b6bfL } },
  36653. /* 155 */
  36654. { { 0x381421ee30c98feL,0x03fac3f0b35c16bL,0x0ca614df6ad2debL,
  36655. 0x37a6e8c53a26cb1L,0x04f04b16dd38134L,0x01fe32a2910f7aeL,
  36656. 0x0f3917fc556ee0fL,0x33504f0720eece9L,0x1998397dd24b1adL },
  36657. { 0x201e17edf4781e6L,0x1f0c651bc7e4072L,0x2613b53090da32dL,
  36658. 0x3729f23181e889eL,0x2ddc697092495b1L,0x1582026073cbefbL,
  36659. 0x1134d71d3d82bb4L,0x231073f37768c21L,0x0d23dd171b59679L } },
  36660. /* 156 */
  36661. { { 0x3a40f84d4dd7e96L,0x1323aa1027f0325L,0x29e6a9d11393711L,
  36662. 0x0863f631b5b15bcL,0x200269e7c3b6066L,0x164a757eb4eeaa1L,
  36663. 0x2e365b1413c6b00L,0x2abb306b5f90088L,0x1d36a82621a4798L },
  36664. { 0x2ac45c4c1003c81L,0x27bd6bd0f6180abL,0x1f5e60f774699efL,
  36665. 0x2aefd74a160da99L,0x1c84acef1f312e7L,0x34922d48bd4fb20L,
  36666. 0x265c6063e32ca29L,0x065cffa6a9f1607L,0x017e3686c9a5284L } },
  36667. /* 157 */
  36668. { { 0x32efe659e90de99L,0x1216f2b416ad8c2L,0x2a52e14e4892be4L,
  36669. 0x0c0898a1a1f1229L,0x15eb3db542ad854L,0x11796104987c3a5L,
  36670. 0x17573948e81863dL,0x2b7933f87383e3bL,0x03fbd6f1ff57d84L },
  36671. { 0x03711ddd1bf968cL,0x235f35237e91cb5L,0x1223e425a566d55L,
  36672. 0x0e1709b410527c2L,0x17c2c17430cf833L,0x050f6766f9ee07cL,
  36673. 0x3d3faee3bdc33e5L,0x2046bce16b0d653L,0x1137551cf429fd1L } },
  36674. /* 158 */
  36675. { { 0x128f55b20193bb2L,0x15e741cc42e1c92L,0x2309d345d27696eL,
  36676. 0x0caa1c61a297b81L,0x1110386839a43e4L,0x0ccbc420a3044f8L,
  36677. 0x05cbb48286ecf3aL,0x236bccd22a8dc0eL,0x0c6698ffcaaef15L },
  36678. { 0x044c54af6908745L,0x0cdb91a8cd4fee8L,0x2852d561e821a6bL,
  36679. 0x1c0d8d245fda530L,0x181f613151b2979L,0x3d1a97bdb8408eeL,
  36680. 0x114f7f6817dc2beL,0x316fe4f7a82be38L,0x136c3cf3cd5ed72L } },
  36681. /* 159 */
  36682. { { 0x38799ab7b080de4L,0x3de0775a760e5aeL,0x2aaa986f8f633b8L,
  36683. 0x0e2952f1729dad0L,0x1a9c2fbb95d74c0L,0x005e24c1dbf2d81L,
  36684. 0x286f0d8451b4408L,0x0c98d03c030e274L,0x14c3038e9520c54L },
  36685. { 0x14bc3816977aad9L,0x3f420b5c21ef8f2L,0x020c875fed08adbL,
  36686. 0x350d1595bf01b42L,0x00fd6dd4ee1ce84L,0x297ead01c713638L,
  36687. 0x2eeb6f23338b226L,0x309b351dfab042eL,0x078e4db08bb5f80L } },
  36688. /* 160 */
  36689. { { 0x111d12a1078342aL,0x11c979566841900L,0x1d590fd3ffdd053L,
  36690. 0x27c1bc2b07fa916L,0x33e19bc69cf694aL,0x27773403db492b6L,
  36691. 0x32dd4e3ce38f5ebL,0x07154e1003d9ad8L,0x085cab8fdfbe15eL },
  36692. { 0x2943f6b8d09422fL,0x0a5d583e6230ec2L,0x01fa2ef2e4d917dL,
  36693. 0x0ecd7df04fd5691L,0x3edaad3ff674352L,0x0d1c90b49d34d01L,
  36694. 0x38615d594114359L,0x2533472c9cc04eeL,0x07da0437004bd77L } },
  36695. /* 161 */
  36696. { { 0x24b99a62d712c44L,0x0da3e29a5895de0L,0x0432d65e2287148L,
  36697. 0x019bd6f17e23b5aL,0x14ec3479d140283L,0x0c9b6dc39b3cc48L,
  36698. 0x32936b96db6f449L,0x086bf296b026328L,0x04d69e248c72feaL },
  36699. { 0x2a89092a71269fbL,0x2f6ea061942d802L,0x02a39fb55db22f6L,
  36700. 0x37d8c47a7407673L,0x090ac2c1d0fceb0L,0x2c7cdca9bebade7L,
  36701. 0x0c41932393b222cL,0x399d18a9bcf7ef2L,0x0019dea30b22fe8L } },
  36702. /* 162 */
  36703. { { 0x1f689ac12b3118bL,0x3b8e75b2dba959fL,0x22c2187cd978d06L,
  36704. 0x206354df61f3f30L,0x2e9f56db2b985b6L,0x38263055d611454L,
  36705. 0x212cd20f8398715L,0x0711efa5a9720ecL,0x1fb3dda0338d9acL },
  36706. { 0x06b7fe0cfa0a9b8L,0x22eb1f88b73dd7cL,0x1e04136887c8947L,
  36707. 0x37a453152f3ce05L,0x00f51ea64ed811dL,0x321c15df2309058L,
  36708. 0x2bbcb463914d834L,0x3d4bbb493954aa2L,0x0019e5eb9e82644L } },
  36709. /* 163 */
  36710. { { 0x365a04e66d52313L,0x25151534fdcaf47L,0x1dafa6b7ae11fd6L,
  36711. 0x3615c6ac91caf03L,0x2ae5a8d68921f79L,0x3b17384f5317e59L,
  36712. 0x24bd39fde17716aL,0x19e0dc39bb692ddL,0x1efffe94085990dL },
  36713. { 0x3fa0e27d88f92e8L,0x3bc3f671dc48f3cL,0x174c89274dbaa21L,
  36714. 0x296e6e89d898966L,0x246ebcaf6d4cfa4L,0x3e38a1c04324274L,
  36715. 0x3aeea20317a10d8L,0x2c28ec1dc778514L,0x0eadf0c479168c6L } },
  36716. /* 164 */
  36717. { { 0x1bc1e484c854477L,0x3096d218e391f04L,0x202b869c54d92beL,
  36718. 0x0caf879fb490f53L,0x06b460c4ae318deL,0x2909abfbd51c7acL,
  36719. 0x052dc138ae7bf3aL,0x37a748eb89b7761L,0x1649d3fc1d55782L },
  36720. { 0x07cae310ade1979L,0x1c1074ed2f1ca36L,0x3c4056c3c9bea84L,
  36721. 0x0ab5d2b919ce248L,0x0ecbe49ae36fe18L,0x3107e7d64affdbdL,
  36722. 0x2307156680db80dL,0x1cc1cd6eb01bf91L,0x0c06d68b4c7d6d0L } },
  36723. /* 165 */
  36724. { { 0x3e22be7854dfcf2L,0x069f7e9ab8ef436L,0x3ad1a521ec46ee2L,
  36725. 0x1e906a52133d18cL,0x32aa123f3ee9452L,0x2b8f2a484517ae6L,
  36726. 0x05d9255634a82acL,0x0b63385dab283f2L,0x078504cf7fc1908L },
  36727. { 0x34ce7c43799793cL,0x375862d5467ed75L,0x1f9395ff980874dL,
  36728. 0x346e2fd8798b3dbL,0x3dcfcf54f00ea45L,0x0c00d6c09a18d84L,
  36729. 0x28a9cb67423b760L,0x01dfa7ef1d4d100L,0x0f47b52ce37051aL } },
  36730. /* 166 */
  36731. { { 0x3f7d8ad96bec962L,0x3207d85f8041ebaL,0x0509214e1058d1cL,
  36732. 0x10d08e5327d9311L,0x11a6605136c298cL,0x037e090f644014bL,
  36733. 0x1cdea4c36437549L,0x2dec48c4ef87bf9L,0x076249a60f7d27fL },
  36734. { 0x09758381cf593a0L,0x33bbee0d931679dL,0x1333e05c99910c9L,
  36735. 0x07d0860238cbd68L,0x34f5e8f4f30ea5eL,0x1b032d1d5bece93L,
  36736. 0x3dcc6a2cae6e2ebL,0x3045d82cc1ff422L,0x01aee17901c0ff8L } },
  36737. /* 167 */
  36738. { { 0x048336b89aa9e14L,0x0d09c7d9d9c03f0L,0x0433906b6980666L,
  36739. 0x387aedeac8d36a8L,0x3eb59a05330247eL,0x0003d3565a6d2a9L,
  36740. 0x026b5bd78ef8258L,0x15b13976ce3ad18L,0x03b06a43e5d7d68L },
  36741. { 0x20ae838ed2a0ee7L,0x2f94a3c5ba204eaL,0x1f5c4ea6413704bL,
  36742. 0x2d81b8a619e2adbL,0x2f459ed2b5be80cL,0x1d85486bc66c6dcL,
  36743. 0x116f3b7a9cce4d1L,0x1a494e6bfe652a9L,0x00797d92e86b341L } },
  36744. /* 168 */
  36745. { { 0x1aeede15af3a8caL,0x091e0a970d47b09L,0x23fbf93ec080339L,
  36746. 0x3139bd096d1079eL,0x081e76009b04f93L,0x0603ff1b93b04bbL,
  36747. 0x0aef3a797366d45L,0x076474a4f2ed438L,0x061a149694468d7L },
  36748. { 0x12c541c675a67a1L,0x0e34c23d7fa41bdL,0x3cccf6be988e67dL,
  36749. 0x2f861626218a9c2L,0x27067045bae03ecL,0x032a365bb340985L,
  36750. 0x00735d1facdd991L,0x3c871ea842a08c3L,0x0152a27e5543328L } },
  36751. /* 169 */
  36752. { { 0x1d609e0e6057e27L,0x22da9f1e915368fL,0x11451f32dd5b87eL,
  36753. 0x22343bd478bfd66L,0x125567546ea397aL,0x08a2d20312619a8L,
  36754. 0x01997aea45c8b13L,0x19f48f6f839df74L,0x1f80e2ea28fc518L },
  36755. { 0x295412d69d0820bL,0x1cc49c7a9968618L,0x0221eb06380d031L,
  36756. 0x3f1d7fa5c1b09f2L,0x35a71d2507ffd4eL,0x1f2dd50dece5a95L,
  36757. 0x0dbee361c80051cL,0x0b51781f6d35eb5L,0x1431c7481f49b19L } },
  36758. /* 170 */
  36759. { { 0x2ab2d0408e1cc4dL,0x1d634eb4b707b97L,0x3dfe5c9c7393e93L,
  36760. 0x2a74cde5a0c33adL,0x2e24f86d7530d86L,0x02c6ec2fbd4a0f2L,
  36761. 0x1b4e3cab5d1a64fL,0x031665aaaf07d53L,0x1443e3d87cc3bc0L },
  36762. { 0x10a82131d60e7b0L,0x2d8a6d74cf40639L,0x2e42fd05338dfc9L,
  36763. 0x303a0871bab152bL,0x306ac09cb0678f2L,0x0c0637db97275d7L,
  36764. 0x38c667833575135L,0x38b760729beb02fL,0x0e17fc8020e9d0aL } },
  36765. /* 171 */
  36766. { { 0x2dd47411baaa5ebL,0x2edd65e6f600da2L,0x0c40cdffed2202cL,
  36767. 0x3c13824450761a0L,0x120748b871c23a8L,0x167a4a25974507bL,
  36768. 0x06dbfe586a15756L,0x269d1f1a35f3540L,0x148da0ad0df2256L },
  36769. { 0x0fcc5db7f9069d7L,0x1f49157014c6932L,0x0899e9a2db3a248L,
  36770. 0x0e2d3fa5c8316adL,0x0d27f35e452bfd5L,0x38b6b24dce81329L,
  36771. 0x3ee7e27cbbc549eL,0x24d800a1c8a77fcL,0x0d03179878d28daL } },
  36772. /* 172 */
  36773. { { 0x1b7e9bb3b66c047L,0x1961a580a8f8762L,0x2297c8db9c0022eL,
  36774. 0x28f4229d28d13e0L,0x1fcd398de0e76acL,0x0c8399abefc69c7L,
  36775. 0x1c9fc52fbb6eaa8L,0x2cad2a0b43af05eL,0x00f4e00cf6f4e7aL },
  36776. { 0x24c0e9a4890c439L,0x1928aef0d69ac90L,0x079dd9b7497d375L,
  36777. 0x03584b7a50a5691L,0x0e60d0033a1ff3fL,0x08905f68d6189ffL,
  36778. 0x2b8385815da8c05L,0x25aa941841353bdL,0x120800728d2f16eL } },
  36779. /* 173 */
  36780. { { 0x36f2372ab039042L,0x1a5e327e8213b65L,0x1d2f58bec14310eL,
  36781. 0x007f881170f40ffL,0x2b0a5a9283200c1L,0x187ebfe39a1a3deL,
  36782. 0x31226526c95d1deL,0x3b45e8788049edeL,0x0898e63dd78c2a5L },
  36783. { 0x36533da22bba4eeL,0x3d8e5fd25a95d2eL,0x29f714f2a6b93efL,
  36784. 0x2f477f75cfd024cL,0x269bca1b1a08248L,0x28b80c9d8bccfcbL,
  36785. 0x1df7419a177e64bL,0x2f472f143a64dd7L,0x095b87a979f4a56L } },
  36786. /* 174 */
  36787. { { 0x03736a967c1f177L,0x34d4218004cf27aL,0x3b926eac9a5b1b6L,
  36788. 0x29b09fbcc725092L,0x1122b48707a9c01L,0x346b2616b64eee9L,
  36789. 0x3f175b9eb94e2a9L,0x364514470081b54L,0x0b1d13eb2525102L },
  36790. { 0x3e7dbeb675a1171L,0x20a5705b034ac73L,0x1b5a057c88cab22L,
  36791. 0x25b4c03a73e36c9L,0x3269552eb73ea9eL,0x383e637ec3800dfL,
  36792. 0x10480fea9d035c9L,0x2cc66183926e34aL,0x037a35e9512c036L } },
  36793. /* 175 */
  36794. { { 0x16729ee8f00df48L,0x329ed846b20c131L,0x17f98b3a8123b89L,
  36795. 0x06708728fa925e9L,0x3e2bb3ce7e0431bL,0x371de065169cf7aL,
  36796. 0x2b3df12f86cc2baL,0x373c17fc0179397L,0x05ef955dd7add27L },
  36797. { 0x0c22ffa00ee402fL,0x0d78a8ecc2ed338L,0x11d0643cb1015b3L,
  36798. 0x114f3465a215095L,0x2f0be54b4c6183fL,0x3083379319993c8L,
  36799. 0x24c475a5f4cfee4L,0x07b6772aa5cbe02L,0x19cde4af2005911L } },
  36800. /* 176 */
  36801. { { 0x29d0bc8d771f428L,0x07b36790f28e0a7L,0x2480eb93acf03acL,
  36802. 0x2041968a8fe357bL,0x22f0b8a7316232fL,0x0951d2887f013eaL,
  36803. 0x315f6f4a8df7e70L,0x0394946b13fc8eeL,0x06b66e21b73e095L },
  36804. { 0x1c9848067a41deeL,0x2a56b9ecf8acfd6L,0x0386891454e12cfL,
  36805. 0x37fbbf29a915366L,0x011e9cb75f0dddbL,0x3bc8230d7da46c9L,
  36806. 0x333cf6a9b9e766fL,0x1d2a7a37c400062L,0x1c4b8a55ac9d1c1L } },
  36807. /* 177 */
  36808. { { 0x19f58625c4cccb8L,0x3d4824bbd34fbeaL,0x257689efc87870bL,
  36809. 0x25b685081b8a3d3L,0x07c52107da2366fL,0x1283c3c240cc680L,
  36810. 0x2a47b0478d4ceadL,0x1d526ca267b891cL,0x110ae96534e6420L },
  36811. { 0x0c1d655cced05b0L,0x30fc2405d6550cbL,0x30a48e577cd7abaL,
  36812. 0x24d03a635b6ebadL,0x3603d24f184b008L,0x15c85cf49a60d94L,
  36813. 0x1141de6e1458832L,0x1fcd074d22c9984L,0x06be52257dcefa2L } },
  36814. /* 178 */
  36815. { { 0x2678f33c947e655L,0x3edda82248de564L,0x2745790239d1ff0L,
  36816. 0x248f36edf3acb7fL,0x105f6d41cea0874L,0x2771562084c9b6eL,
  36817. 0x0317025b1ae9ae7L,0x22a738514d033a7L,0x0c307502c29a2c3L },
  36818. { 0x0124f11c156ace2L,0x1c3f9de7fc94a43L,0x1a816e1171b22c1L,
  36819. 0x20d57789e5d837eL,0x27c6cc79da19bcaL,0x3587ddc06b649faL,
  36820. 0x1c06bb285901121L,0x10aeffa03209898L,0x15e4050d338aa26L } },
  36821. /* 179 */
  36822. { { 0x1397829eaad87bcL,0x324d9e07a132f72L,0x024d6ade4fdee0aL,
  36823. 0x295a435fd5ad5e7L,0x3d14fb0b950b9abL,0x16839edbc26ca74L,
  36824. 0x2f4ff3d0684f232L,0x1ccec1453a74d81L,0x077e63bdd26e8adL },
  36825. { 0x2fd06ece0d25c6dL,0x00086802e8b73c2L,0x17708c5bb398dd9L,
  36826. 0x360663fe3f06c09L,0x1b7e2cd68077f06L,0x18e8d5ca1f543fcL,
  36827. 0x125a9aef75e0572L,0x03a56fc95e24beaL,0x111847d3df0739dL } },
  36828. /* 180 */
  36829. { { 0x2ab9cc7fec82924L,0x1b75a69c8835a54L,0x27dea06ef0e21c7L,
  36830. 0x3089c60e41298d4L,0x2716807c8ab3e51L,0x123c491bd36cd7aL,
  36831. 0x1560958f3ede0a7L,0x0e37bc524d91104L,0x0f75f6583d1874bL },
  36832. { 0x39189e10b927eb7L,0x318d670b8bc49e8L,0x02337fe966f4a87L,
  36833. 0x208417956142dcbL,0x2e58c39f9102b83L,0x246d4ca58ffb801L,
  36834. 0x2ff97b3f052ee39L,0x14181fd6e15332eL,0x16a935e5f6c5f80L } },
  36835. /* 181 */
  36836. { { 0x19a0355dfd88d38L,0x33638f15277d03cL,0x29e304d006e1555L,
  36837. 0x1b3f42c3398c89cL,0x135f2ad31f16b70L,0x1e8f7e7fc55b702L,
  36838. 0x1e5fb5b30c5213fL,0x2368a7ca7324a95L,0x144a0ecfdd42b85L },
  36839. { 0x1c115df52658a92L,0x0fb45f10a0585adL,0x1f707fd92a91bceL,
  36840. 0x3f67357625a9565L,0x35a9472b1663c8bL,0x00cf86f41dd8d0fL,
  36841. 0x1c02fb14e44ca8bL,0x3ecc89e87261879L,0x1b5ece0f2c4cc4fL } },
  36842. /* 182 */
  36843. { { 0x3127bab31211943L,0x232b195a10c9705L,0x0b88d855fc3e44aL,
  36844. 0x0333a47ba974bf8L,0x078ec7d1247ababL,0x3367fbe9748f771L,
  36845. 0x255766a3986de70L,0x31fe8cb1ee19e09L,0x0873e54018beeaeL },
  36846. { 0x16e86f2b38d17c1L,0x3ef431c7e810372L,0x2b79f88499cb9cbL,
  36847. 0x33bdc7b202f8446L,0x146c896921d47c5L,0x34c58cc6b2a8ef0L,
  36848. 0x28765b5f921c0e3L,0x3c9c0c7e8207b9dL,0x0fed5dafd5f41efL } },
  36849. /* 183 */
  36850. { { 0x2f10b9d4cda1348L,0x1a7f48970c04ea2L,0x25b18957c22bb07L,
  36851. 0x31fd6b3c711142aL,0x09fef80295cafd6L,0x38227d773dc6850L,
  36852. 0x3d2ba8e12029f5eL,0x32d625d4aa3ec3eL,0x09061e2275f6f70L },
  36853. { 0x30a4ac51fbda16aL,0x0439e7c77e8a8adL,0x2132d9945f6f799L,
  36854. 0x2bbad2e93bee8b3L,0x34bf2d53d450d59L,0x18831ea1aa3826cL,
  36855. 0x13c6f476010204eL,0x3d5a98fe250f429L,0x13214c91d1987eaL } },
  36856. /* 184 */
  36857. { { 0x14fb120490d66c3L,0x35cca2837208139L,0x0c3804b4294deaeL,
  36858. 0x2acc777119ee805L,0x28342ed113f2fa2L,0x0c0d3839c3fd57aL,
  36859. 0x0ae3c1b18da72f2L,0x1680ab70c36faf6L,0x09c179bdf6f3e94L },
  36860. { 0x2c928ef7484c26fL,0x2df6c7bcab6ec51L,0x35483f58dda7206L,
  36861. 0x0312f1fb6d8221fL,0x1975cafdcfde4e2L,0x1afbb0812134487L,
  36862. 0x16db67c5b596708L,0x1d222d5e6aa229bL,0x01522c6d87e4118L } },
  36863. /* 185 */
  36864. { { 0x2890757c471d4aeL,0x12c6950e8769d82L,0x31826aa701a1fefL,
  36865. 0x14967197e4ee24aL,0x1d789df35bf4d4eL,0x2de70fca48ebe4aL,
  36866. 0x0cf1303ccb46c60L,0x03b125560b39f3dL,0x11c7da081b4257fL },
  36867. { 0x12c6ae59aeef274L,0x16fd3c50df020feL,0x3023e13c86afe6cL,
  36868. 0x398a8894d82a9d2L,0x022589fa5d21dacL,0x3e9d2c3ecf55caeL,
  36869. 0x2891a93d4a3916dL,0x33ef79db36372c4L,0x19aa0391a3f59f4L } },
  36870. /* 186 */
  36871. { { 0x14ba69e203fc3f1L,0x1a332d8841a8a41L,0x0540aad5fa9f091L,
  36872. 0x03affdfb5bec206L,0x0bef94afdecb8f2L,0x02af476cb202986L,
  36873. 0x0e0a7ce25d8ca0bL,0x16e69d799e9040aL,0x1b2dd7662ddd6e9L },
  36874. { 0x3dff279f289d7eeL,0x157567ba8881721L,0x3d54c18adac64d7L,
  36875. 0x33dfb004066bac3L,0x2b48d70a43a8c46L,0x02ce7be1bf2439fL,
  36876. 0x145a20965c53c11L,0x008f9155ddf30e1L,0x16ea33430f757ddL } },
  36877. /* 187 */
  36878. { { 0x29f39490ff53d2cL,0x24565ac00d26e7eL,0x1014d59979678dcL,
  36879. 0x2aea29ade2bc429L,0x08b517b104dd72dL,0x1b4e6f83bd77950L,
  36880. 0x217f70142b90bcaL,0x044632baa8fa7b6L,0x16da01689d606b3L },
  36881. { 0x26ca563f46afff7L,0x171ee8d29797cfaL,0x24c8aa998fd8394L,
  36882. 0x11ad8fd4d7b07ffL,0x0d1f509e542a601L,0x3e33436d4205a22L,
  36883. 0x236772d1918daa9L,0x3719994179aede2L,0x1ef4ab03a819cc6L } },
  36884. /* 188 */
  36885. { { 0x2089d14d376d986L,0x1381de8b70d6c01L,0x309a53ff2c86d0fL,
  36886. 0x11448f0ff207045L,0x31b656fc2fef4baL,0x3fbea2ee14b3569L,
  36887. 0x110b77b57c74891L,0x284a63c14e0f920L,0x04c4b55d3ad52c5L },
  36888. { 0x110cff3f3827633L,0x1e1357802bfa594L,0x38823ead32fa086L,
  36889. 0x058ae47361b2ce1L,0x0e6f3638a3dcf4dL,0x22dff5081e2da96L,
  36890. 0x1683e733792112eL,0x210cda5901137b9L,0x1223b84210f28e2L } },
  36891. /* 189 */
  36892. { { 0x028a9a9c3ebeb27L,0x3372d4fbd643e1bL,0x2e114dae7f37d7bL,
  36893. 0x391c9ba9f27a228L,0x28c141388033522L,0x058855d667540e1L,
  36894. 0x0564d859b1aeca6L,0x238d9c67f3faff3L,0x0433a577af11aebL },
  36895. { 0x3f26ce06feba922L,0x320fb91d695a4f0L,0x274028bf378e5f6L,
  36896. 0x1a2f70fdbc5fde5L,0x2a6ed90aed2a5e3L,0x291f2f54f40d282L,
  36897. 0x0e2bc83b1c3a4c4L,0x003ae93c2a9b937L,0x1c097c7af4374caL } },
  36898. /* 190 */
  36899. { { 0x037717879c28de7L,0x2a8aaaae70cc300L,0x182666bc61eb617L,
  36900. 0x33d35e2d4110c20L,0x19870fc72e0b5b5L,0x102def175da9d4bL,
  36901. 0x32d03a3b4689f5dL,0x182a6a5ff619e1fL,0x1c06ab7b5eefd60L },
  36902. { 0x19eadb1ffb71704L,0x3962ece43f8ec7aL,0x382cab4f19aa436L,
  36903. 0x3eb83cf6773bb2aL,0x16e20ad12da492dL,0x36ef4988a83d52fL,
  36904. 0x12eb54af89fa0f7L,0x01d637314286ba3L,0x0b79799f816ef7dL } },
  36905. /* 191 */
  36906. { { 0x2c46462104f98ccL,0x056489cabb7aba7L,0x3dd07e62186f451L,
  36907. 0x09a35b5a6d9eba4L,0x0fd43a8f3d17ce0L,0x302ade5ed4d1d82L,
  36908. 0x1f991de87f1c137L,0x38358efd65ea04eL,0x08de293a85be547L },
  36909. { 0x182add38ef668b1L,0x39acb584725d902L,0x2b121c1d4263c54L,
  36910. 0x23bbfd939ccf39dL,0x02871612a3134b2L,0x2824d652bdc6a6bL,
  36911. 0x1108e831c88af2bL,0x0df682d92444aeaL,0x1138febc5c55cf4L } },
  36912. /* 192 */
  36913. { { 0x29ca589c4a2daa2L,0x29c0f1003d8231fL,0x1058d517510318eL,
  36914. 0x1c92aedbca5be33L,0x194296ab4264934L,0x314595f42f954f8L,
  36915. 0x080ea89af9398faL,0x386c788cb7bb13eL,0x1372f81761e67b1L },
  36916. { 0x1014bc73a20f662L,0x1f9df127b654094L,0x096fb62b96521fbL,
  36917. 0x19e8ba34dfa27d4L,0x25804170e3a659cL,0x3b5428d03caca89L,
  36918. 0x03c00f1674fce69L,0x2764eaa914dfbf7L,0x198f3c3bfda4ce9L } },
  36919. /* 193 */
  36920. { { 0x2b1f5cd81614189L,0x15b11492c967deeL,0x24b245fb415ec7dL,
  36921. 0x371ebdafbe71eeaL,0x074b48e82302bc8L,0x2db46c7e46ddc38L,
  36922. 0x280c974a1336e09L,0x2d894a1704d5f99L,0x12d59bcb813c7ccL },
  36923. { 0x1ad83b47c019927L,0x3c999d8c37f56f7L,0x2c5a31e05d23e10L,
  36924. 0x3e915ab1180576fL,0x1243cac822aa6e5L,0x372327a51a5594aL,
  36925. 0x0a4065c69c9c7f4L,0x0c06eb6c9f82789L,0x1ccdfa7a34eae41L } },
  36926. /* 194 */
  36927. { { 0x36a864d59cb1a7dL,0x19328dabbee3b85L,0x3acb1c22b0d84d8L,
  36928. 0x3af66037c743ba0L,0x07f94ced97e80a6L,0x29cb0457d60ab31L,
  36929. 0x107bb7a29cd1233L,0x028c3384a8aa31cL,0x1500229ca564ed8L },
  36930. { 0x374bad52f1c180bL,0x2fa6635d26a8425L,0x08ab56dbd1bad08L,
  36931. 0x3902befaa6a5e31L,0x3153dc5fc6ed3e3L,0x2fa4fb422a2fa5eL,
  36932. 0x2e23bdadc7f0959L,0x0a77a3490a420b3L,0x016417523c6dc27L } },
  36933. /* 195 */
  36934. { { 0x0eeccf16c14a31eL,0x3894d2cb78f0b5dL,0x35997cec43c3488L,
  36935. 0x27645ab24dbe6ecL,0x29f7e4400421045L,0x1154d60dc745700L,
  36936. 0x14a4678c9c7c124L,0x2eb67325d5237b2L,0x14e4ca678183167L },
  36937. { 0x33af0558d0312bfL,0x2fd3d5505879980L,0x05a7fa41781dbd1L,
  36938. 0x2a003bbc7549665L,0x079c3b8d033494dL,0x327db9a5b1417b0L,
  36939. 0x030aaa70ae1ade1L,0x018300a23c305daL,0x00c7f4cfe3ba62aL } },
  36940. /* 196 */
  36941. { { 0x18b447d057d6006L,0x25db9bf5c722c03L,0x2029abcf40f538bL,
  36942. 0x21bc40e9e0d79dfL,0x05e472c4b13bee3L,0x07f2c650829ab08L,
  36943. 0x0abf4943b045f63L,0x1ade79770767f00L,0x1b528c0bc70a555L },
  36944. { 0x29d07ee8a8640b8L,0x04408f438d004aeL,0x255bbe24ae89256L,
  36945. 0x093e95e77371f39L,0x1377bbfe5e358e5L,0x30251f915f389c5L,
  36946. 0x29782664651c6c3L,0x305697ef63543d2L,0x08d6fcdd28fe2e1L } },
  36947. /* 197 */
  36948. { { 0x164a2f65c7202c8L,0x0d01496952c362dL,0x16721434fbf57d6L,
  36949. 0x1787660c28e1053L,0x15ef0fbe1811421L,0x1bd5fe7f1e9d635L,
  36950. 0x2269d35705dcf8eL,0x27e5d7752695b64L,0x0f18f015d7abdb4L },
  36951. { 0x3131110b4799ce6L,0x2fee64b2f2df6c1L,0x0c9ff7ba21e235bL,
  36952. 0x04ec63d27fb07c0L,0x1abcf959b009d69L,0x350851ba3698654L,
  36953. 0x1f23f10e6872130L,0x0e1ad560ca05eb9L,0x143c9b5bb689ae7L } },
  36954. /* 198 */
  36955. { { 0x23328db48c74424L,0x05b8474672cbad0L,0x192a40d6e217326L,
  36956. 0x13032f71d4b94d0L,0x0d733bb01dd83a9L,0x2de914817188c14L,
  36957. 0x0011c8cd0d631a5L,0x1f3573370289669L,0x1e622f112cc646eL },
  36958. { 0x3d6e29a3e1e4c4bL,0x2094e27ec552291L,0x05b54fd3e319d5fL,
  36959. 0x2682822e599f8dcL,0x3d8cbe8db8c4ce5L,0x3bb0f5d6f29d279L,
  36960. 0x1a313dcc4496eaaL,0x24d805f71c8ea28L,0x1a5250ff77a8cebL } },
  36961. /* 199 */
  36962. { { 0x15a0726fe29bd79L,0x12a0413e642cd29L,0x146daad56983657L,
  36963. 0x2e543507fbda41aL,0x06e6f7f450e580aL,0x03cdc62af1d6d45L,
  36964. 0x234087508cc97bfL,0x2244146e8b29295L,0x17275c39077e64dL },
  36965. { 0x37cccaff77ca6bdL,0x037d06f6c637d7cL,0x0ff8019e01f7e0aL,
  36966. 0x112a9975cae7d1bL,0x06e3663e9be4f3dL,0x3be76db5e08b62bL,
  36967. 0x24a9aa5f37f9223L,0x322e9fc2b4e76afL,0x098a0a57c70f69cL } },
  36968. /* 200 */
  36969. { { 0x1c50cf400fd5286L,0x16e755ca92c0f36L,0x0f9e051ae73e1eaL,
  36970. 0x10a546ce093d798L,0x09fb4d667fe9b51L,0x3714215ac0d2cb4L,
  36971. 0x30022e4b537a80eL,0x22bb9a7b8404a32L,0x0ed7c8b9e5c6a54L },
  36972. { 0x06007bcd933619bL,0x1d9a38ae77f865dL,0x15d3cc6e2a2e0ceL,
  36973. 0x17dfbafccbea7bbL,0x167cc4f6435a14fL,0x214305b1d72e263L,
  36974. 0x379c96cb2185fc7L,0x11d10261d29d917L,0x1397468f8ae27dbL } },
  36975. /* 201 */
  36976. { { 0x1de68adc88684f6L,0x3b6aad8669f6ff1L,0x1735b27a18f57c1L,
  36977. 0x1963b3627ac9634L,0x2d879f7eab27e7bL,0x1f56fbecf622271L,
  36978. 0x3ad73ca8fdc96d6L,0x15b5f21361ab8deL,0x1a4c7e91976ce8eL },
  36979. { 0x001a5406319ffa6L,0x3993b04d3b01314L,0x296cd541242c0caL,
  36980. 0x3bafcb2bbb87da6L,0x028bee8059da259L,0x23a24392239e5e3L,
  36981. 0x227fd9e9484bebbL,0x18c6039491b43ecL,0x1b78be2a54a625dL } },
  36982. /* 202 */
  36983. { { 0x223554af472f13aL,0x264edd5ccfa4728L,0x29f096c168a2facL,
  36984. 0x0752c49d4d49abfL,0x3e77070ca7cfe76L,0x1f9f37da10c061cL,
  36985. 0x162ed466b6aaadcL,0x3e36368b757aa85L,0x016a81a2e0039faL },
  36986. { 0x080759c4e3de3bfL,0x38b8454bcc222aaL,0x2d9aaa7eba5b0c1L,
  36987. 0x14e7e70472b2cb7L,0x3b0dc5c194c65d5L,0x28fd2d842ae6f61L,
  36988. 0x0b5f9fd32f8c96cL,0x0877d2610bf30a3L,0x0f431ae27ccb90eL } },
  36989. /* 203 */
  36990. { { 0x32a0a0d6a0ccd0aL,0x3bb209664ed554eL,0x06fd9de672a6a3eL,
  36991. 0x1203681773ec4d2L,0x16739874d8d9c51L,0x0a68d72712a9113L,
  36992. 0x177eadd9cf35b2eL,0x1c2875af66d7e24L,0x1d69af0f59d2a04L },
  36993. { 0x2f844c7ba7535fdL,0x3530f6a10bfce6cL,0x09ede951974b45bL,
  36994. 0x25ff5114fb17f85L,0x1e6c37c0e6982e9L,0x0b0fbdaa98fdc17L,
  36995. 0x36a8d609b0f6a9dL,0x06de2fb74d6185dL,0x1764048a46aede1L } },
  36996. /* 204 */
  36997. { { 0x07c6ee551a251d1L,0x12fc48349e77f69L,0x138cec518a28befL,
  36998. 0x21ce202f9b930b5L,0x21be9b20b1b2b78L,0x1e5a867b1a733e3L,
  36999. 0x10bdeae41dfeae3L,0x20300959dbf27edL,0x16a8b815a0503e1L },
  37000. { 0x0a085f653f5ef65L,0x3eefe5dec94414bL,0x07e3a3346fe661dL,
  37001. 0x3b86e57dfbe23aaL,0x15b65eaec25ddfdL,0x30b808ec881d39aL,
  37002. 0x283bb511869a154L,0x1f9f61806d5dd0bL,0x0151464652cfa87L } },
  37003. /* 205 */
  37004. { { 0x10853c857fa58f1L,0x2939a1329319c09L,0x2d0a1b81f40db58L,
  37005. 0x041563a32f41ee5L,0x242e388cfa4651eL,0x110d8220699011bL,
  37006. 0x2b8fd051b0d5394L,0x33f3b0afcd6cf89L,0x0fd4ae787095702L },
  37007. { 0x079bc29df53d498L,0x0c713844dfd890fL,0x056c17a3cedf4cfL,
  37008. 0x071b36445764edaL,0x39228cddb246113L,0x3480afc6acc2914L,
  37009. 0x108612e97757b68L,0x09ad2999b79f398L,0x051c200fe654f60L } },
  37010. /* 206 */
  37011. { { 0x296103cb1a2b4b5L,0x332ffa10f025a3aL,0x072d986ffb5b98dL,
  37012. 0x3c85a74eb09a8dcL,0x2771371f12fa07aL,0x1f0a67be2ee16e6L,
  37013. 0x372efceae10d34eL,0x15bc4f52f71a788L,0x039378df75d8dd8L },
  37014. { 0x1e902ffde7ff5d9L,0x2a1748c9682728cL,0x13a6f4192fcd0e9L,
  37015. 0x0dc56c1dacf5c6eL,0x26e711d1cf52a57L,0x30a4a0675c9aaa1L,
  37016. 0x015de60b61b1df2L,0x2791c89395d7320L,0x1dc68e893e118b7L } },
  37017. /* 207 */
  37018. { { 0x3924ff96ffeda73L,0x27d01a83688062dL,0x20eaf89584dfe70L,
  37019. 0x0ba0d568100da38L,0x0fd777d7c009511L,0x2fe3cb20967514aL,
  37020. 0x05311bb0c495652L,0x36755fd8c64a113L,0x0d5698d0e4f8466L },
  37021. { 0x10d64fa015d204dL,0x09afe9b744314f8L,0x0e63a7698c947b6L,
  37022. 0x11c14cde95821feL,0x0df5c782f525a65L,0x157eebfd5638891L,
  37023. 0x2e383048aa1e418L,0x18f4d23c886391fL,0x04df25239591384L } },
  37024. /* 208 */
  37025. { { 0x2f4fd69d8695310L,0x3ac27dfa1da3a9dL,0x1812e0d532a8e28L,
  37026. 0x11315cab1e40e70L,0x0785d6293dda677L,0x369daec87e60038L,
  37027. 0x3c72172bfe2a5a3L,0x22a39bb456e428aL,0x04cd80e61bfd178L },
  37028. { 0x1f4037016730056L,0x117fbf73b4f50eeL,0x363c1aa5074246fL,
  37029. 0x14bfe4ab9cc2bf5L,0x11bb2063f21e5c6L,0x0b489501bbc20c3L,
  37030. 0x15001c18306ecc1L,0x150913b766ce87cL,0x1f4e4eb25b8c0ccL } },
  37031. /* 209 */
  37032. { { 0x161a714a1db5c18L,0x139879d9dc1d33bL,0x3be57bf685de945L,
  37033. 0x14f48516f97a5c3L,0x3ee49a5f2221b0cL,0x12c4740ee4c6206L,
  37034. 0x02213700b91afa1L,0x002bf1abbf924fbL,0x13c50554e945262L },
  37035. { 0x02c45e77364c92eL,0x000995cd4863a35L,0x1a0284d3f3c5e05L,
  37036. 0x0936fdd91af4a07L,0x2485f304f312f84L,0x049e944f86a23caL,
  37037. 0x20e0bc583f56311L,0x1c293b5e5431c69L,0x0c692855e104b7bL } },
  37038. /* 210 */
  37039. { { 0x106185c644614e7L,0x01b2b91d2690923L,0x12ea2587e5282e9L,
  37040. 0x02b44a15f356150L,0x0ba5593b5376399L,0x3574a919dc31fdcL,
  37041. 0x29a1bac2cf6dc4dL,0x2576959369158edL,0x1c8639f7e141878L },
  37042. { 0x1c96b02f8589620L,0x11a28d079101501L,0x1a11096ad09c2feL,
  37043. 0x2627194abbafc8bL,0x3547e1b8fbc73c2L,0x1df6fdcf37be7e2L,
  37044. 0x13552d7073785a9L,0x0f4fc2a4a86a9f8L,0x15b227611403a39L } },
  37045. /* 211 */
  37046. { { 0x1a5a7b01fbfaf32L,0x298b42f99874862L,0x0f5ef5e3b44d5c5L,
  37047. 0x3b7d0eefd891e5cL,0x1260ae5a03ea001L,0x1a5f18b2a39d0a1L,
  37048. 0x1a7643eb899ebd2L,0x09698da800f99d4L,0x0eaef178c51ba07L },
  37049. { 0x2cf8e9f9bd51f28L,0x3aef6ea1c48112aL,0x2d3a5bfc836539fL,
  37050. 0x334439bc23e1e02L,0x08241ab0e408a34L,0x22998a860413284L,
  37051. 0x2048d6843e71ce9L,0x3461e773a14508cL,0x1fa5cba23be1cf3L } },
  37052. /* 212 */
  37053. { { 0x3e8c9d22973a15cL,0x3b237750a5e7ccbL,0x0a390b6afb3e66fL,
  37054. 0x0daad97bc88e6bdL,0x266c5fcdb0bb1e4L,0x2bd21c2e3c98807L,
  37055. 0x344e243cffe8a35L,0x05c8996b8a1bcaeL,0x114da2e283a51ddL },
  37056. { 0x29c9a56c1e3d708L,0x18b4fc72c3be992L,0x298497e875404feL,
  37057. 0x1acf3a91bebc1c0L,0x283886263138b7dL,0x070c24241e018d3L,
  37058. 0x03864727e842807L,0x2899fc2bde75f96L,0x104c1b86582b236L } },
  37059. /* 213 */
  37060. { { 0x2ff09eda526c894L,0x2fc48052b1f48ccL,0x0dcd3cd9293495aL,
  37061. 0x04a4b9ad55adbe5L,0x21036c31bffaaebL,0x01ffccb864de5baL,
  37062. 0x1d67b8a9d237e77L,0x0922f59696c360aL,0x1b348edb556db29L },
  37063. { 0x2e9f9b2ded46575L,0x32822bfe9a6b3dbL,0x33a1f16d37d1496L,
  37064. 0x2c5e279740756baL,0x1c827cc454a507dL,0x259399dc178b38aL,
  37065. 0x0e46f229b6e4a52L,0x19214158ec2e930L,0x0a3e75c24484bc4L } },
  37066. /* 214 */
  37067. { { 0x3cb476fd2f6615dL,0x3e6de36636a6a43L,0x1f1cd2bdf1074b7L,
  37068. 0x21a6e55bcc78bf7L,0x3b596eadf2bda30L,0x156c94e3cf328bdL,
  37069. 0x0846db91c09f8b3L,0x190b91bcfdbcf1bL,0x1ff9bb9398e2a14L },
  37070. { 0x118d4f5a17bd645L,0x0cfaaf6f5b55494L,0x06fc734d0957570L,
  37071. 0x17d7d4f10d401faL,0x3fd27dd1998ca06L,0x254b472a652766fL,
  37072. 0x2c101cddc4e3046L,0x2c01e132ad3ee06L,0x00346d079f94a56L } },
  37073. /* 215 */
  37074. { { 0x1eb8e4fa6bfdeddL,0x28a179e9d31be65L,0x14d13d09a252993L,
  37075. 0x3986697dd9e2f57L,0x20cebb340eaa10bL,0x36fdea0f4f6c20fL,
  37076. 0x0f23e1c633a78b1L,0x20de49992f0fb0cL,0x1c96630f8f107a0L },
  37077. { 0x3f4cb4bdef86a80L,0x13b1e0fe0966aeeL,0x3604609532c81faL,
  37078. 0x3322e427a4a92fdL,0x31788416071bb7aL,0x286ae4a32875cc5L,
  37079. 0x0455a57f7f14becL,0x3a266ffa805b97eL,0x02d7b8c76b9bf21L } },
  37080. /* 216 */
  37081. { { 0x28605634b9f8e7dL,0x05dadd8ff162a11L,0x1a7e2feed68a201L,
  37082. 0x0f99460c6439e97L,0x2e9377ad6cc6776L,0x1c0c8c85f5f4040L,
  37083. 0x0bb505ccfc47207L,0x09da55cfb80c54dL,0x0f31bf1ef8c0f1aL },
  37084. { 0x35f5c4b0c935667L,0x14b0e41834ae2d8L,0x2c2e37c3a574741L,
  37085. 0x1302dcb8337bfeaL,0x1f4f60247fd5fccL,0x2785bccedd0fe6eL,
  37086. 0x34ef9c05c2e3547L,0x2b38e888d311cc1L,0x1244092f279495aL } },
  37087. /* 217 */
  37088. { { 0x3fd7851b30f9170L,0x2a87a4dff396c56L,0x15e0928437b9715L,
  37089. 0x1670cbc49cf3ff5L,0x248be1e3488acd2L,0x296f18ad685173cL,
  37090. 0x156f463a3408607L,0x3870d8a5bac5460L,0x1e7397fad192774L },
  37091. { 0x22f99f49c8225b5L,0x3f39251addf134dL,0x35308541e91b33eL,
  37092. 0x0d0e3cf5a4d1477L,0x2e727b54e0bd2d9L,0x188b65002d778b5L,
  37093. 0x36a94b42d929c27L,0x3c814dab39c8d5bL,0x04464a18cd5fccaL } },
  37094. /* 218 */
  37095. { { 0x1be0aababa95d63L,0x203185ed2cd1b63L,0x38630e0d8142927L,
  37096. 0x0aad5bbc13190c3L,0x1785e3633875be0L,0x04b24f930a3fae5L,
  37097. 0x2f82a3d5401795cL,0x2bf5a27fd47078dL,0x16b3c48c89510eeL },
  37098. { 0x1287ebad4f064beL,0x1f555553af6a65eL,0x1ef2623727ea1a7L,
  37099. 0x24627cd9b1919d1L,0x1c59d6ebda911f5L,0x1493484df950d73L,
  37100. 0x15b38d3a84daea7L,0x0f1271ec774710eL,0x01cca13e7041a82L } },
  37101. /* 219 */
  37102. { { 0x399860c874d64b0L,0x16c248594f38318L,0x0000eaa11986337L,
  37103. 0x0258873457459c0L,0x277d70dcd62c679L,0x016f5336f875f75L,
  37104. 0x2f8f30eff0f2703L,0x16de01dbb1884d8L,0x1d8812048167e44L },
  37105. { 0x1749a0e161f9758L,0x2457fa8f13f38a0L,0x0e41911dd8afe60L,
  37106. 0x2b1e6946827d4dfL,0x02ca5cf8efe36a8L,0x12415fd59fed52dL,
  37107. 0x244b641bdcae07eL,0x1960edc7fc31690L,0x1064815a5364b60L } },
  37108. /* 220 */
  37109. { { 0x0c69c3eef39cc39L,0x011593e98d5b45eL,0x3542412fb990983L,
  37110. 0x34de76eca96f4f0L,0x0e7e75e3da1d531L,0x2c051ec52197c62L,
  37111. 0x129ab02dac4e220L,0x1d3bfd6794728cfL,0x0f1c964f7fe37b0L },
  37112. { 0x080c0a60e301262L,0x1601814e4288b5cL,0x3f9acc8a90299a4L,
  37113. 0x15c5303c70b699dL,0x26e66d9f7dfae90L,0x1e11a490d997fc5L,
  37114. 0x0c307cc866dd8c4L,0x1439316bfa63f13L,0x03960e3ba63e0bfL } },
  37115. /* 221 */
  37116. { { 0x2785136959ecdb3L,0x2bd85fe7a566f86L,0x32b8cde0dc88289L,
  37117. 0x2c1f01e78554516L,0x350e22415fe9070L,0x1635b50bddfc134L,
  37118. 0x3b629ab3ab73723L,0x3f49453f506e6e9L,0x1937b32d80e7400L },
  37119. { 0x1d80d4d7147886fL,0x33b5855db2072b9L,0x0692642717bbe08L,
  37120. 0x262aed2f487853aL,0x26530308b9dcdf1L,0x2674671d962f991L,
  37121. 0x0ab126fbf192dadL,0x378c5568f46ccc1L,0x00e943f4be5fa24L } },
  37122. /* 222 */
  37123. { { 0x14240587fe9ea48L,0x13e09586d5d21b1L,0x013c78719740af2L,
  37124. 0x1e5c3ae1d3674b1L,0x0b62ba3aa27a9beL,0x306fc2b10ffbe38L,
  37125. 0x3130e10a23f2862L,0x33afd4709dbcd2bL,0x185f6cd1e9aae55L },
  37126. { 0x0defa7f40369093L,0x076759616078289L,0x3f33e512ed9e11fL,
  37127. 0x167b448225a6402L,0x28b73c399bf8a84L,0x3dbd53fa0c91557L,
  37128. 0x25235554a305698L,0x0ecc4aa75b694f0L,0x16ae6a6f9042a09L } },
  37129. /* 223 */
  37130. { { 0x2e123c9152cdd35L,0x390ea21900bbc6cL,0x30dfb9ce5bd5ae6L,
  37131. 0x129d601245224afL,0x3f502eec2b4acb8L,0x28cfbd3a31fd57fL,
  37132. 0x1d20019c8a7b93aL,0x2f3ac1ac40d5ff6L,0x0273e319ff00ba3L },
  37133. { 0x02c2f77abe360a3L,0x3d7212b7fbf2986L,0x0ca6650b6fcc57eL,
  37134. 0x15aabc2c80a693cL,0x0a24ef1563f4f8eL,0x3a917c4d7214228L,
  37135. 0x036dbed8f62fd91L,0x040efcb248e80a0L,0x18a4a9ca4c01a4dL } },
  37136. /* 224 */
  37137. { { 0x23fb7985448e339L,0x1dc33c628e65d8aL,0x174d7a69170cde8L,
  37138. 0x164ad819eb04581L,0x0848138ab4bb05cL,0x24279e537834b6cL,
  37139. 0x0315f7149dab924L,0x289620e8cdad9e4L,0x13ccd9074d9a335L },
  37140. { 0x039c5e0ac1b784dL,0x17231bb949eb87aL,0x2146a1c88ec0ab6L,
  37141. 0x2411b06fd634f21L,0x33fda502a2201f7L,0x096e4195c73b189L,
  37142. 0x16dfcdff3f88eb2L,0x29731b07c326315L,0x0acaa3222aa484fL } },
  37143. /* 225 */
  37144. { { 0x3e74bc3c9b4dfd6L,0x2a014fe39d8a4c5L,0x1c059d8c352025bL,
  37145. 0x332e16882d00c1fL,0x2238713591c9036L,0x2a57ed3bcb18fc2L,
  37146. 0x10c6c61a99d9d8cL,0x259a0f5f13ce661L,0x169162969c96829L },
  37147. { 0x113c267cb63ee53L,0x04b985d7ab0d4dfL,0x1a11191abfca67bL,
  37148. 0x277b86bda7eccdaL,0x011dc11e75ad064L,0x2e7e5d9535e9bc0L,
  37149. 0x2b133280f030b8dL,0x3318a8800068fc2L,0x194e17c98d239d8L } },
  37150. /* 226 */
  37151. { { 0x20d80b41d8fe898L,0x28a2dcc86114d1cL,0x038504f217408d7L,
  37152. 0x35459aa9abfc7cfL,0x0cc560e355d381cL,0x39878b367379821L,
  37153. 0x34951acb041f0a5L,0x2b0b188445bd766L,0x0c4509e16d37ee2L },
  37154. { 0x02a20c42c6fd79eL,0x1fb938ebde2c3aeL,0x23c1bad819ca95bL,
  37155. 0x37a615495a4f66dL,0x2f9c19d0f10d674L,0x1f179aa45f7992cL,
  37156. 0x22db6fa03fabaf4L,0x3463a162f12b4b3L,0x0c976c2380a1fc9L } },
  37157. /* 227 */
  37158. { { 0x1171ef8b064f114L,0x2c55953cbc3d324L,0x185457b262b783cL,
  37159. 0x0043cd24db0c149L,0x299a41fed468c67L,0x1fdfdaa7bc9b4bfL,
  37160. 0x1bfc1bf6da2267aL,0x3b500958ee36e80L,0x00e14b36c85c340L },
  37161. { 0x257e26425db67e6L,0x3d3a25fcba417d7L,0x2514026c426885dL,
  37162. 0x188fa1d424de0cbL,0x03c538691312be2L,0x15cd3e7615ad6f6L,
  37163. 0x2a48615b1cae559L,0x2ed61681eff8b56L,0x1d07a4c96f0ce8aL } },
  37164. /* 228 */
  37165. { { 0x3f54d05523aa2e9L,0x107833b4f42181eL,0x36e27f9bfb69c88L,
  37166. 0x11058af7e155a0fL,0x107b0dcc9dcb07fL,0x15e94db98b45e0eL,
  37167. 0x347d3ca2cbb8ab6L,0x18dc262e68349f3L,0x1f2ff154d685eeaL },
  37168. { 0x28b768a56b232acL,0x35b8d8fca94aad5L,0x3a168837fc604e8L,
  37169. 0x20f4429da46eba1L,0x0f9455fbeebc58aL,0x359538bab5792bcL,
  37170. 0x3c82551a20d6c37L,0x2e4c63103f2e769L,0x0b26d7b3cd760d9L } },
  37171. /* 229 */
  37172. { { 0x3090c3ebb2eaf45L,0x1364718bfee4bdeL,0x3ea4a736f23ded2L,
  37173. 0x2f5bfc3f78efca8L,0x1ca1102f5b5b99eL,0x1f80caa2f28ad57L,
  37174. 0x3f17a8f6203cd80L,0x156c55042d122a2L,0x109b86660a7e1dcL },
  37175. { 0x148b1da02a2fbd8L,0x217a2cec8ba296cL,0x20e48712b509fedL,
  37176. 0x1231a8f94584de2L,0x01633b503685601L,0x15449c45c402487L,
  37177. 0x131047939251432L,0x382eded24c7481fL,0x0ea623e722b8542L } },
  37178. /* 230 */
  37179. { { 0x04823d324972688L,0x20f04800fd5d882L,0x26906d0d452858bL,
  37180. 0x210b1bdd1f86535L,0x10146d89a842195L,0x1146ef0b23e28baL,
  37181. 0x3284fa29ec1de77L,0x3913fd88adae3dfL,0x06083f1dbe97b71L },
  37182. { 0x1649333999dd56bL,0x2b02ea5e91f7a66L,0x18aebbe8fb202cfL,
  37183. 0x363d875ef299983L,0x185adc14d47c29dL,0x3e7f5071bd7ed47L,
  37184. 0x113e6ce65ac7884L,0x274f8739a7753fdL,0x0231ace591effe5L } },
  37185. /* 231 */
  37186. { { 0x267a438a9fda771L,0x3d94b2198c4038bL,0x1e48e133f23b626L,
  37187. 0x3c80d74b47f7ec6L,0x28d13e878599f88L,0x2d47381c5c8e844L,
  37188. 0x19ba82890aa292fL,0x052d397ce9c3aefL,0x155dde826733745L },
  37189. { 0x0b2b77ed6f59a95L,0x214f8c080810802L,0x2ac1ebac779793fL,
  37190. 0x266d5ad99d94894L,0x19722a5006ecdcbL,0x138aeb412af6e7eL,
  37191. 0x34dd4d26210f3f0L,0x2e034329683fcc0L,0x041333d8080dac0L } },
  37192. /* 232 */
  37193. { { 0x051070935a85a06L,0x19b9d90bbc6d13aL,0x0b71a07b3a6d4e1L,
  37194. 0x000c0ca79aa12a4L,0x13d555259d6dd6cL,0x3e2b41788312e99L,
  37195. 0x34cccdee3b26af6L,0x19090838f5504aaL,0x1bd79798934a940L },
  37196. { 0x2a1d1848e0c7ff0L,0x217bf2550ecd03cL,0x31aef51d318bbaeL,
  37197. 0x139d61e3e9ba590L,0x3c2895f52e5d3edL,0x3c4419f134a8a76L,
  37198. 0x3f4ee53af278771L,0x1d369b337a59279L,0x19235188da1a56dL } },
  37199. /* 233 */
  37200. { { 0x083212003d310edL,0x3ba33261ec0c46cL,0x1d2684c558a8d20L,
  37201. 0x33adc59fb227952L,0x04bf55bb55e25f3L,0x1872405eb3c453dL,
  37202. 0x3343c0819edc770L,0x2d7b5d669139b7aL,0x07858df9f7e04c9L },
  37203. { 0x3a47ebb3bf13222L,0x147737a81f68453L,0x3ac3c0d8242f1e4L,
  37204. 0x134dbae1c786fa7L,0x2bea3190d93257dL,0x3af8accfd279dd6L,
  37205. 0x110096406d191f4L,0x2b1e19eab14f030L,0x1f45215cf8bd381L } },
  37206. /* 234 */
  37207. { { 0x07e8a8efa493b79L,0x389c2d3ac70ab0eL,0x3fa09ff22320b20L,
  37208. 0x2baa470e4f67ce4L,0x2138a8d965ee1baL,0x1ef543937b6a586L,
  37209. 0x23c8e069ab238c9L,0x1305bfda352288dL,0x158af8e00e5ce4cL },
  37210. { 0x0cdcf06cfc509a1L,0x1047bf09b301d5bL,0x1fd64d9c57f060fL,
  37211. 0x14ccba672b1b433L,0x18b8e9510a95148L,0x04370ff563e6acfL,
  37212. 0x2f3509a7e98709bL,0x04b1e0e4210f5d7L,0x1b628ccc9d05a93L } },
  37213. /* 235 */
  37214. { { 0x1934f00e341463fL,0x229b3854369e807L,0x20fc4109553f14cL,
  37215. 0x16aa4fd2a476d21L,0x32cd58067c23bdeL,0x10cf72027d1f1e1L,
  37216. 0x232a7d1d3300548L,0x176a4302f9fe5d6L,0x12e08b777d588c7L },
  37217. { 0x3c1281761a10d37L,0x2d86057143d6977L,0x15db79477c60ed7L,
  37218. 0x1dccf14c42ca2beL,0x053118267a0aa2bL,0x2d06567e417eaaeL,
  37219. 0x337784f40e98166L,0x1ab32732d09485aL,0x0c56835d77c6986L } },
  37220. /* 236 */
  37221. { { 0x1d714cb2b450a66L,0x222171f6ff7053aL,0x0d85b466a0c0131L,
  37222. 0x2656f7f0699956aL,0x0e67792d102a21eL,0x15429e5de835f26L,
  37223. 0x34d3372a01bb57bL,0x352550b1188cd75L,0x08b7be4e1c088daL },
  37224. { 0x073b03f95812273L,0x1bb4cbb8fdd5fc6L,0x0eae6da6217a2e2L,
  37225. 0x1d098767d3cb1c4L,0x1b7c1da2d9b50b5L,0x12a1779d0e5c7eaL,
  37226. 0x22137b22c4fb87cL,0x0649bdcb0d147b0L,0x1731345668c77baL } },
  37227. /* 237 */
  37228. { { 0x23e8c7a8a3ba183L,0x33aeeff8e27e9cfL,0x06870f9ba60f4e8L,
  37229. 0x0d72d806a0e3a91L,0x212e52db455176eL,0x3dc4afc7e42f709L,
  37230. 0x2054cd95f9e4598L,0x3502e6f4c803efaL,0x17a2cf19bf6dd5fL },
  37231. { 0x1cf6ca266736febL,0x21bd2779f3f8bdcL,0x3ce8fc290563bdeL,
  37232. 0x339c9adb93f182aL,0x13f29235baae8a3L,0x143fe97b48e0911L,
  37233. 0x3ef744a4b557f56L,0x1b74a8514f95044L,0x1b07c676a533e42L } },
  37234. /* 238 */
  37235. { { 0x1e603f235d96872L,0x288f30fe96e32bdL,0x071be988dc5fab1L,
  37236. 0x22750c302f55166L,0x0764d9cc3e32e84L,0x0b031035fb09a78L,
  37237. 0x3b83b4f7238212fL,0x29044b651860e21L,0x010281fa6712f18L },
  37238. { 0x028048f64858b37L,0x0526bcd5f797660L,0x0791619ebb18e0eL,
  37239. 0x2ce7cac2e82c886L,0x21039cbae210200L,0x255e74756a1fab9L,
  37240. 0x08515e4efdcddb3L,0x1e2a86ce23aa89eL,0x02c1a552c3cc818L } },
  37241. /* 239 */
  37242. { { 0x2c7f5000ea723dcL,0x3c13d10ac548c5eL,0x1445be885c860a5L,
  37243. 0x0fffc465c098f52L,0x0c4c58cea61f999L,0x273580db0fee917L,
  37244. 0x3923bbe6d151e6bL,0x3f519d68eac555eL,0x1474ec07c52ceb2L },
  37245. { 0x06a3d32ed88239dL,0x2e2b9a0d6b9a531L,0x23259feeb2e70d1L,
  37246. 0x0710ef02ed7d3f7L,0x38f62a705223bf7L,0x3f9e6694f34882dL,
  37247. 0x2b7f932224860e9L,0x2562f61561c0c92L,0x10f8e0f7330b594L } },
  37248. /* 240 */
  37249. { { 0x335c7bb3c67d520L,0x12562c8ff2a7b2bL,0x31948bbaa808d8fL,
  37250. 0x33884d7a2b81de3L,0x1c888eff7418c30L,0x1cc512af376366aL,
  37251. 0x06a53472075df0fL,0x1ff16d527225514L,0x11c4ef389795fbbL },
  37252. { 0x3e2c9ac43f5e698L,0x1ff2f38e2978e8fL,0x090e3089c2e1ce7L,
  37253. 0x3feb0756005b417L,0x0381b9d2a5a74f3L,0x17ce582ebbb6888L,
  37254. 0x37abbed958b143fL,0x2dc6197ff414436L,0x0ce8e97e6807a05L } },
  37255. /* 241 */
  37256. { { 0x251e61b8ce86a83L,0x10567efdf9c5808L,0x3dd748f03377860L,
  37257. 0x0dd1414890bf049L,0x0934ea09b87cb2cL,0x119e5106f52543dL,
  37258. 0x3a416a5146c403cL,0x23ac7a2b51c408eL,0x1b389b81a60af63L },
  37259. { 0x299934ee8150c69L,0x1d642389f052f39L,0x28916a0194ff74fL,
  37260. 0x0c86f546dd97702L,0x21877963038f49dL,0x34ed29a1af0cc17L,
  37261. 0x0af189fe2f3fbffL,0x0426c5026cddf5fL,0x1b3029ea13b9b8fL } },
  37262. /* 242 */
  37263. { { 0x37938d225a2fd88L,0x3cbdf33ae8180fbL,0x1c80d7a6dff4890L,
  37264. 0x0d8a20fe61930f8L,0x2998e530500c78fL,0x097771cfb64ad64L,
  37265. 0x13708a018a8f1b3L,0x0a2edb7ff661f57L,0x059dcd3554f0d1fL },
  37266. { 0x3c6e41d23a74e7dL,0x187af976ccb7d85L,0x3fa79e7ffa0b94bL,
  37267. 0x2dcbaede834f0bfL,0x201adf9c3473662L,0x119e4992a19057bL,
  37268. 0x209c571502c3265L,0x242185a444d24beL,0x195897f34aa2474L } },
  37269. /* 243 */
  37270. { { 0x045d359abadc253L,0x12e4b31e5f25792L,0x35bd9a218212e05L,
  37271. 0x17a94ae209c8aa6L,0x22e61c6769bb80aL,0x22c3e2cfa8e39e3L,
  37272. 0x1d854cfb274b1a0L,0x0b5cedaa90b8f6eL,0x1638ba225235601L },
  37273. { 0x0ec0e6f75c8c576L,0x0839f392f1f749fL,0x20c869d80726abbL,
  37274. 0x1aa2808fadc2562L,0x276110b15a908c6L,0x21bd869b2a7d43aL,
  37275. 0x0a69d8668c99941L,0x2843e777c8bb4a8L,0x1e0bfee1897bbf8L } },
  37276. /* 244 */
  37277. { { 0x2d8681848319e4fL,0x1bdad56961be809L,0x1886267132656beL,
  37278. 0x316614a73eafbd7L,0x162b29cfbac252aL,0x0a98d6379f3117cL,
  37279. 0x00ac70ee050609aL,0x2c7c3df2e7290a5L,0x1adfb44aaeca885L },
  37280. { 0x2b7a936e798678eL,0x07840e655010e19L,0x1e37816860b7ca0L,
  37281. 0x20edd17615fc924L,0x0a4705ed6eeffd4L,0x0a9743dd76ecd8aL,
  37282. 0x09fee357d68d49bL,0x35a1b46a14a688eL,0x1addbbc25491a7fL } },
  37283. /* 245 */
  37284. { { 0x10cba20969686a3L,0x2c71578f014fd78L,0x313426f47102308L,
  37285. 0x2c5240cc0e05c4aL,0x32d01527b1f9165L,0x2a68d38916dc805L,
  37286. 0x3e35c86fcf6647aL,0x38e0947d52e52c2L,0x0e3fccb22a55a15L },
  37287. { 0x271e4ec5b4dc0beL,0x0d89236c735712aL,0x3f43046e1007bb1L,
  37288. 0x35f6a72668fcdafL,0x28349bc505a6806L,0x04f8214272ff1bbL,
  37289. 0x3448c126871e73eL,0x2ebe579aa889d9fL,0x1b9ba77787c2da7L } },
  37290. /* 246 */
  37291. { { 0x2be58eec5a73375L,0x37da75ea2b10e06L,0x150aceca835a175L,
  37292. 0x027d41f4c3cb3ccL,0x3c60b0424b87b06L,0x043e43b26b94e8aL,
  37293. 0x1689bb4931e1824L,0x06a3914b1f43eb7L,0x013ab4534914763L },
  37294. { 0x32dd8568c84f3afL,0x3702486eab8cfabL,0x2a858b96b070829L,
  37295. 0x103a2a094591950L,0x05c35322b42260dL,0x27b6834ae797b6bL,
  37296. 0x22b90abca795603L,0x14c0a1af41f1ae5L,0x10a2e22dac7b1ecL } },
  37297. /* 247 */
  37298. { { 0x25fc09d239d8f0aL,0x0b80f2ae2840859L,0x17680173477b92bL,
  37299. 0x27e38d8581390daL,0x19eb061beab38edL,0x3a1159c1e6c0247L,
  37300. 0x21a2e0cd4226543L,0x00c3e83ddfb1cbfL,0x0931d242162760aL },
  37301. { 0x29f834cf8646bc3L,0x25294902ba5be7eL,0x3890379177d17dfL,
  37302. 0x113ffad9b364070L,0x077b924659dfd06L,0x3660753e06bb0bbL,
  37303. 0x37b0932df3b7f2cL,0x2762f26f0fda7cdL,0x125daef34f3dd85L } },
  37304. /* 248 */
  37305. { { 0x008451ba2c123bcL,0x20e9a02063e952bL,0x170298957b8ad1eL,
  37306. 0x0d3c3c4bc595b75L,0x30a9fa14dcc7f2eL,0x0bf9e0b07daa70cL,
  37307. 0x1f54ddefc9a2bbbL,0x0294f4c671a5dc2L,0x1dc0b8238cbd646L },
  37308. { 0x249290144dfb6f6L,0x35f2d1b900749bdL,0x240e48537ad8270L,
  37309. 0x2d5c3636f6469c2L,0x2f170d58b84d661L,0x0d13874b289c88eL,
  37310. 0x1de1faeeb4cf146L,0x17a9c8957f256aeL,0x1f8cd6e110adbdcL } },
  37311. /* 249 */
  37312. { { 0x257c6b978b8a0a7L,0x12badba0cfb7a8aL,0x17c14bd13fe724bL,
  37313. 0x223f0ba3b927918L,0x1fb147eefc41868L,0x3998b3ee34e6292L,
  37314. 0x0ba2ece9f191f12L,0x35435861c8a2656L,0x02dbd6d0f1b00b8L },
  37315. { 0x15cfdfe24c93cc9L,0x35de02e79c639e2L,0x3a5838baf7eb29eL,
  37316. 0x1f93772fda40722L,0x3a180d6bb022538L,0x251f1f0992c942fL,
  37317. 0x23f3cd6d68e548cL,0x0f34a0a9ed8ca64L,0x00fb8f036132d10L } },
  37318. /* 250 */
  37319. { { 0x198b3f08cd9d494L,0x0196e653d3e7ce0L,0x22203c738fa99b2L,
  37320. 0x0536348a72dd992L,0x0c51c54b3199f4cL,0x084e8ccb76b5d71L,
  37321. 0x0c7b2f9a32ce0bdL,0x3c82bce88421622L,0x0d16defa3625b1fL },
  37322. { 0x0e0054819a296ebL,0x13fc5746a44c4d1L,0x2d2bfeaa454f1d9L,
  37323. 0x00d3502f5ff5f7aL,0x21801a4afae65a8L,0x178379dd813c51fL,
  37324. 0x172ca0983048f9aL,0x3445e8ec67297fdL,0x0e0a237dba71821L } },
  37325. /* 251 */
  37326. { { 0x1babf8491630ee8L,0x16270817ad4c07bL,0x2b2da051f47bde6L,
  37327. 0x25884aefa067df4L,0x294292124aeaa9fL,0x110d796f73b4f57L,
  37328. 0x11f66f691f5b89fL,0x3c368658130ce50L,0x0e6b7fc09ca4356L },
  37329. { 0x294e413f74f811cL,0x0b60c77e36376c4L,0x3217963418c91a4L,
  37330. 0x06223af37b09fd5L,0x2ea305bc95fde52L,0x319a2d87f75781bL,
  37331. 0x011861ed1e6088aL,0x33af0ccebc05baeL,0x1c95ecb192d15ddL } },
  37332. /* 252 */
  37333. { { 0x27b37a3e0bde442L,0x10ffa19bde9cfa4L,0x1d208ed10c2ee05L,
  37334. 0x1069985e8cb4c36L,0x0d1d5cf8baf79c3L,0x0eaf3e2f9cd9e1cL,
  37335. 0x2b5e7b02d0dce9eL,0x1c317f88f4b75dcL,0x10b29fceea01ffcL },
  37336. { 0x1bcae4d62d803ffL,0x3a44ff6f0c1aa4cL,0x27abd8c1066293eL,
  37337. 0x0ab9e9b5962bc77L,0x2102f4e06d48578L,0x0dbebf9a449964bL,
  37338. 0x37121391a3127f1L,0x058d11ae4d10220L,0x0ba53bb4380a31eL } },
  37339. /* 253 */
  37340. { { 0x2e517fcca5636b0L,0x1b8085aae8571d8L,0x3d7c212e7b2d429L,
  37341. 0x1b55c5eb6116aa3L,0x398b2f3579517ceL,0x3d66c1f39d8ae16L,
  37342. 0x3ef6f042f996b5dL,0x2d227cdccaaefcdL,0x15da5d145ea4542L },
  37343. { 0x277c55eaa7f6e3fL,0x36669ea92816f07L,0x3d77458282273f4L,
  37344. 0x3eddedd23ee95b5L,0x20629f5d1db0895L,0x16600fec7121333L,
  37345. 0x20b8d0f5b1c90a3L,0x04fc90eb13ca45cL,0x0e98c10bfe872acL } },
  37346. /* 254 */
  37347. { { 0x11c4785c06c4fd6L,0x2e40974970ae767L,0x1eb1d4982f24bf4L,
  37348. 0x30ae93fbcac104dL,0x398de07ab3ab3edL,0x25bd2df556948e7L,
  37349. 0x04c815d5fc49ab0L,0x1acaf1428a580e1L,0x047db1148d01567L },
  37350. { 0x09f9cc510f3bad9L,0x2223f008a407531L,0x15ebc47b44df490L,
  37351. 0x31bce7cada245e9L,0x304e9962a20b2ebL,0x1cf756dc31638ebL,
  37352. 0x29f76c52ab7c1b5L,0x328ecad52b75a8cL,0x10859dad1eb82f4L } },
  37353. /* 255 */
  37354. { { 0x22c4128a182d1adL,0x05e5b88245b1159L,0x0272ba681647775L,
  37355. 0x3eae4b217069dc1L,0x3aefb2e07fac8b0L,0x2186ccb481eacb7L,
  37356. 0x2ed145c73530a07L,0x292758f6fb59622L,0x0bd547bcdca0a53L },
  37357. { 0x3c1382f87056b51L,0x247b6c4c3e644a9L,0x1e46d3805b42c3dL,
  37358. 0x3aff4c6a657df1fL,0x0cd3fb8aa456101L,0x3ac5ef387bf48adL,
  37359. 0x2c0c32fe391df79L,0x3bbd2d353031985L,0x11219f023be711bL } },
  37360. };
  37361. /* Multiply the base point of P521 by the scalar and return the result.
  37362. * If map is true then convert result to affine coordinates.
  37363. *
  37364. * Stripe implementation.
  37365. * Pre-generated: 2^0, 2^65, ...
  37366. * Pre-generated: products of all combinations of above.
  37367. * 8 doubles and adds (with qz=1)
  37368. *
  37369. * r Resulting point.
  37370. * k Scalar to multiply by.
  37371. * map Indicates whether to convert result to affine.
  37372. * ct Constant time required.
  37373. * heap Heap to use for allocation.
  37374. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  37375. */
  37376. static int sp_521_ecc_mulmod_base_9(sp_point_521* r, const sp_digit* k,
  37377. int map, int ct, void* heap)
  37378. {
  37379. return sp_521_ecc_mulmod_stripe_9(r, &p521_base, p521_table,
  37380. k, map, ct, heap);
  37381. }
  37382. #endif
  37383. /* Multiply the base point of P521 by the scalar and return the result.
  37384. * If map is true then convert result to affine coordinates.
  37385. *
  37386. * km Scalar to multiply by.
  37387. * r Resulting point.
  37388. * map Indicates whether to convert result to affine.
  37389. * heap Heap to use for allocation.
  37390. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  37391. */
  37392. int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap)
  37393. {
  37394. #ifdef WOLFSSL_SP_SMALL_STACK
  37395. sp_point_521* point = NULL;
  37396. sp_digit* k = NULL;
  37397. #else
  37398. sp_point_521 point[1];
  37399. sp_digit k[9];
  37400. #endif
  37401. int err = MP_OKAY;
  37402. #ifdef WOLFSSL_SP_SMALL_STACK
  37403. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap,
  37404. DYNAMIC_TYPE_ECC);
  37405. if (point == NULL)
  37406. err = MEMORY_E;
  37407. if (err == MP_OKAY) {
  37408. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9, heap,
  37409. DYNAMIC_TYPE_ECC);
  37410. if (k == NULL)
  37411. err = MEMORY_E;
  37412. }
  37413. #endif
  37414. if (err == MP_OKAY) {
  37415. sp_521_from_mp(k, 9, km);
  37416. err = sp_521_ecc_mulmod_base_9(point, k, map, 1, heap);
  37417. }
  37418. if (err == MP_OKAY) {
  37419. err = sp_521_point_to_ecc_point_9(point, r);
  37420. }
  37421. #ifdef WOLFSSL_SP_SMALL_STACK
  37422. if (k != NULL)
  37423. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  37424. if (point != NULL)
  37425. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  37426. #endif
  37427. return err;
  37428. }
  37429. /* Multiply the base point of P521 by the scalar, add point a and return
  37430. * the result. If map is true then convert result to affine coordinates.
  37431. *
  37432. * km Scalar to multiply by.
  37433. * am Point to add to scalar multiply result.
  37434. * inMont Point to add is in montgomery form.
  37435. * r Resulting point.
  37436. * map Indicates whether to convert result to affine.
  37437. * heap Heap to use for allocation.
  37438. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  37439. */
  37440. int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am,
  37441. int inMont, ecc_point* r, int map, void* heap)
  37442. {
  37443. #ifdef WOLFSSL_SP_SMALL_STACK
  37444. sp_point_521* point = NULL;
  37445. sp_digit* k = NULL;
  37446. #else
  37447. sp_point_521 point[2];
  37448. sp_digit k[9 + 9 * 2 * 6];
  37449. #endif
  37450. sp_point_521* addP = NULL;
  37451. sp_digit* tmp = NULL;
  37452. int err = MP_OKAY;
  37453. #ifdef WOLFSSL_SP_SMALL_STACK
  37454. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap,
  37455. DYNAMIC_TYPE_ECC);
  37456. if (point == NULL)
  37457. err = MEMORY_E;
  37458. if (err == MP_OKAY) {
  37459. k = (sp_digit*)XMALLOC(
  37460. sizeof(sp_digit) * (9 + 9 * 2 * 6),
  37461. heap, DYNAMIC_TYPE_ECC);
  37462. if (k == NULL)
  37463. err = MEMORY_E;
  37464. }
  37465. #endif
  37466. if (err == MP_OKAY) {
  37467. addP = point + 1;
  37468. tmp = k + 9;
  37469. sp_521_from_mp(k, 9, km);
  37470. sp_521_point_from_ecc_point_9(addP, am);
  37471. }
  37472. if ((err == MP_OKAY) && (!inMont)) {
  37473. err = sp_521_mod_mul_norm_9(addP->x, addP->x, p521_mod);
  37474. }
  37475. if ((err == MP_OKAY) && (!inMont)) {
  37476. err = sp_521_mod_mul_norm_9(addP->y, addP->y, p521_mod);
  37477. }
  37478. if ((err == MP_OKAY) && (!inMont)) {
  37479. err = sp_521_mod_mul_norm_9(addP->z, addP->z, p521_mod);
  37480. }
  37481. if (err == MP_OKAY) {
  37482. err = sp_521_ecc_mulmod_base_9(point, k, 0, 0, heap);
  37483. }
  37484. if (err == MP_OKAY) {
  37485. sp_521_proj_point_add_9(point, point, addP, tmp);
  37486. if (map) {
  37487. sp_521_map_9(point, point, tmp);
  37488. }
  37489. err = sp_521_point_to_ecc_point_9(point, r);
  37490. }
  37491. #ifdef WOLFSSL_SP_SMALL_STACK
  37492. if (k != NULL)
  37493. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  37494. if (point)
  37495. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  37496. #endif
  37497. return err;
  37498. }
  37499. #if defined(WOLFSSL_VALIDATE_ECC_KEYGEN) || defined(HAVE_ECC_SIGN) || \
  37500. defined(HAVE_ECC_VERIFY)
  37501. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN | HAVE_ECC_SIGN | HAVE_ECC_VERIFY */
  37502. /* Add 1 to a. (a = a + 1)
  37503. *
  37504. * r A single precision integer.
  37505. * a A single precision integer.
  37506. */
  37507. SP_NOINLINE static void sp_521_add_one_9(sp_digit* a)
  37508. {
  37509. a[0]++;
  37510. sp_521_norm_9(a);
  37511. }
  37512. /* Read big endian unsigned byte array into r.
  37513. *
  37514. * r A single precision integer.
  37515. * size Maximum number of bytes to convert
  37516. * a Byte array.
  37517. * n Number of bytes in array to read.
  37518. */
  37519. static void sp_521_from_bin(sp_digit* r, int size, const byte* a, int n)
  37520. {
  37521. int i;
  37522. int j = 0;
  37523. word32 s = 0;
  37524. r[0] = 0;
  37525. for (i = n-1; i >= 0; i--) {
  37526. r[j] |= (((sp_digit)a[i]) << s);
  37527. if (s >= 50U) {
  37528. r[j] &= 0x3ffffffffffffffL;
  37529. s = 58U - s;
  37530. if (j + 1 >= size) {
  37531. break;
  37532. }
  37533. r[++j] = (sp_digit)a[i] >> s;
  37534. s = 8U - s;
  37535. }
  37536. else {
  37537. s += 8U;
  37538. }
  37539. }
  37540. for (j++; j < size; j++) {
  37541. r[j] = 0;
  37542. }
  37543. }
  37544. /* Generates a scalar that is in the range 1..order-1.
  37545. *
  37546. * rng Random number generator.
  37547. * k Scalar value.
  37548. * returns RNG failures, MEMORY_E when memory allocation fails and
  37549. * MP_OKAY on success.
  37550. */
  37551. static int sp_521_ecc_gen_k_9(WC_RNG* rng, sp_digit* k)
  37552. {
  37553. int err;
  37554. byte buf[66];
  37555. do {
  37556. err = wc_RNG_GenerateBlock(rng, buf, sizeof(buf));
  37557. if (err == 0) {
  37558. buf[0] &= 0x1;
  37559. sp_521_from_bin(k, 9, buf, (int)sizeof(buf));
  37560. if (sp_521_cmp_9(k, p521_order2) <= 0) {
  37561. sp_521_add_one_9(k);
  37562. break;
  37563. }
  37564. }
  37565. }
  37566. while (err == 0);
  37567. return err;
  37568. }
  37569. /* Makes a random EC key pair.
  37570. *
  37571. * rng Random number generator.
  37572. * priv Generated private value.
  37573. * pub Generated public point.
  37574. * heap Heap to use for allocation.
  37575. * returns ECC_INF_E when the point does not have the correct order, RNG
  37576. * failures, MEMORY_E when memory allocation fails and MP_OKAY on success.
  37577. */
  37578. int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
  37579. {
  37580. #ifdef WOLFSSL_SP_SMALL_STACK
  37581. sp_point_521* point = NULL;
  37582. sp_digit* k = NULL;
  37583. #else
  37584. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37585. sp_point_521 point[2];
  37586. #else
  37587. sp_point_521 point[1];
  37588. #endif
  37589. sp_digit k[9];
  37590. #endif
  37591. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37592. sp_point_521* infinity = NULL;
  37593. #endif
  37594. int err = MP_OKAY;
  37595. (void)heap;
  37596. #ifdef WOLFSSL_SP_SMALL_STACK
  37597. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37598. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC);
  37599. #else
  37600. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC);
  37601. #endif
  37602. if (point == NULL)
  37603. err = MEMORY_E;
  37604. if (err == MP_OKAY) {
  37605. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9, heap,
  37606. DYNAMIC_TYPE_ECC);
  37607. if (k == NULL)
  37608. err = MEMORY_E;
  37609. }
  37610. #endif
  37611. if (err == MP_OKAY) {
  37612. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37613. infinity = point + 1;
  37614. #endif
  37615. err = sp_521_ecc_gen_k_9(rng, k);
  37616. }
  37617. if (err == MP_OKAY) {
  37618. err = sp_521_ecc_mulmod_base_9(point, k, 1, 1, NULL);
  37619. }
  37620. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37621. if (err == MP_OKAY) {
  37622. err = sp_521_ecc_mulmod_9(infinity, point, p521_order, 1, 1, NULL);
  37623. }
  37624. if (err == MP_OKAY) {
  37625. if (sp_521_iszero_9(point->x) || sp_521_iszero_9(point->y)) {
  37626. err = ECC_INF_E;
  37627. }
  37628. }
  37629. #endif
  37630. if (err == MP_OKAY) {
  37631. err = sp_521_to_mp(k, priv);
  37632. }
  37633. if (err == MP_OKAY) {
  37634. err = sp_521_point_to_ecc_point_9(point, pub);
  37635. }
  37636. #ifdef WOLFSSL_SP_SMALL_STACK
  37637. if (k != NULL)
  37638. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  37639. if (point != NULL) {
  37640. /* point is not sensitive, so no need to zeroize */
  37641. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  37642. }
  37643. #endif
  37644. return err;
  37645. }
  37646. #ifdef WOLFSSL_SP_NONBLOCK
  37647. typedef struct sp_ecc_key_gen_521_ctx {
  37648. int state;
  37649. sp_521_ecc_mulmod_9_ctx mulmod_ctx;
  37650. sp_digit k[9];
  37651. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37652. sp_point_521 point[2];
  37653. #else
  37654. sp_point_521 point[1];
  37655. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  37656. } sp_ecc_key_gen_521_ctx;
  37657. int sp_ecc_make_key_521_nb(sp_ecc_ctx_t* sp_ctx, WC_RNG* rng, mp_int* priv,
  37658. ecc_point* pub, void* heap)
  37659. {
  37660. int err = FP_WOULDBLOCK;
  37661. sp_ecc_key_gen_521_ctx* ctx = (sp_ecc_key_gen_521_ctx*)sp_ctx->data;
  37662. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37663. sp_point_521* infinity = ctx->point + 1;
  37664. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  37665. typedef char ctx_size_test[sizeof(sp_ecc_key_gen_521_ctx)
  37666. >= sizeof(*sp_ctx) ? -1 : 1];
  37667. (void)sizeof(ctx_size_test);
  37668. switch (ctx->state) {
  37669. case 0:
  37670. err = sp_521_ecc_gen_k_9(rng, ctx->k);
  37671. if (err == MP_OKAY) {
  37672. err = FP_WOULDBLOCK;
  37673. ctx->state = 1;
  37674. }
  37675. break;
  37676. case 1:
  37677. err = sp_521_ecc_mulmod_base_9_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  37678. ctx->point, ctx->k, 1, 1, heap);
  37679. if (err == MP_OKAY) {
  37680. err = FP_WOULDBLOCK;
  37681. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37682. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  37683. ctx->state = 2;
  37684. #else
  37685. ctx->state = 3;
  37686. #endif
  37687. }
  37688. break;
  37689. #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN
  37690. case 2:
  37691. err = sp_521_ecc_mulmod_9_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  37692. infinity, ctx->point, p521_order, 1, 1);
  37693. if (err == MP_OKAY) {
  37694. if (sp_521_iszero_9(ctx->point->x) ||
  37695. sp_521_iszero_9(ctx->point->y)) {
  37696. err = ECC_INF_E;
  37697. }
  37698. else {
  37699. err = FP_WOULDBLOCK;
  37700. ctx->state = 3;
  37701. }
  37702. }
  37703. break;
  37704. #endif /* WOLFSSL_VALIDATE_ECC_KEYGEN */
  37705. case 3:
  37706. err = sp_521_to_mp(ctx->k, priv);
  37707. if (err == MP_OKAY) {
  37708. err = sp_521_point_to_ecc_point_9(ctx->point, pub);
  37709. }
  37710. break;
  37711. }
  37712. if (err != FP_WOULDBLOCK) {
  37713. XMEMSET(ctx, 0, sizeof(sp_ecc_key_gen_521_ctx));
  37714. }
  37715. return err;
  37716. }
  37717. #endif /* WOLFSSL_SP_NONBLOCK */
  37718. #ifdef HAVE_ECC_DHE
  37719. /* Write r as big endian to byte array.
  37720. * Fixed length number of bytes written: 66
  37721. *
  37722. * r A single precision integer.
  37723. * a Byte array.
  37724. */
  37725. static void sp_521_to_bin_9(sp_digit* r, byte* a)
  37726. {
  37727. int i;
  37728. int j;
  37729. int s = 0;
  37730. int b;
  37731. for (i=0; i<8; i++) {
  37732. r[i+1] += r[i] >> 58;
  37733. r[i] &= 0x3ffffffffffffffL;
  37734. }
  37735. j = 528 / 8 - 1;
  37736. a[j] = 0;
  37737. for (i=0; i<9 && j>=0; i++) {
  37738. b = 0;
  37739. /* lint allow cast of mismatch sp_digit and int */
  37740. a[j--] |= (byte)(r[i] << s); /*lint !e9033*/
  37741. b += 8 - s;
  37742. if (j < 0) {
  37743. break;
  37744. }
  37745. while (b < 58) {
  37746. a[j--] = (byte)(r[i] >> b);
  37747. b += 8;
  37748. if (j < 0) {
  37749. break;
  37750. }
  37751. }
  37752. s = 8 - (b - 58);
  37753. if (j >= 0) {
  37754. a[j] = 0;
  37755. }
  37756. if (s != 0) {
  37757. j++;
  37758. }
  37759. }
  37760. }
  37761. /* Multiply the point by the scalar and serialize the X ordinate.
  37762. * The number is 0 padded to maximum size on output.
  37763. *
  37764. * priv Scalar to multiply the point by.
  37765. * pub Point to multiply.
  37766. * out Buffer to hold X ordinate.
  37767. * outLen On entry, size of the buffer in bytes.
  37768. * On exit, length of data in buffer in bytes.
  37769. * heap Heap to use for allocation.
  37770. * returns BUFFER_E if the buffer is to small for output size,
  37771. * MEMORY_E when memory allocation fails and MP_OKAY on success.
  37772. */
  37773. int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out,
  37774. word32* outLen, void* heap)
  37775. {
  37776. #ifdef WOLFSSL_SP_SMALL_STACK
  37777. sp_point_521* point = NULL;
  37778. sp_digit* k = NULL;
  37779. #else
  37780. sp_point_521 point[1];
  37781. sp_digit k[9];
  37782. #endif
  37783. int err = MP_OKAY;
  37784. if (*outLen < 65U) {
  37785. err = BUFFER_E;
  37786. }
  37787. #ifdef WOLFSSL_SP_SMALL_STACK
  37788. if (err == MP_OKAY) {
  37789. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap,
  37790. DYNAMIC_TYPE_ECC);
  37791. if (point == NULL)
  37792. err = MEMORY_E;
  37793. }
  37794. if (err == MP_OKAY) {
  37795. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9, heap,
  37796. DYNAMIC_TYPE_ECC);
  37797. if (k == NULL)
  37798. err = MEMORY_E;
  37799. }
  37800. #endif
  37801. if (err == MP_OKAY) {
  37802. sp_521_from_mp(k, 9, priv);
  37803. sp_521_point_from_ecc_point_9(point, pub);
  37804. err = sp_521_ecc_mulmod_9(point, point, k, 1, 1, heap);
  37805. }
  37806. if (err == MP_OKAY) {
  37807. sp_521_to_bin_9(point->x, out);
  37808. *outLen = 66;
  37809. }
  37810. #ifdef WOLFSSL_SP_SMALL_STACK
  37811. if (k != NULL)
  37812. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  37813. if (point != NULL)
  37814. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  37815. #endif
  37816. return err;
  37817. }
  37818. #ifdef WOLFSSL_SP_NONBLOCK
  37819. typedef struct sp_ecc_sec_gen_521_ctx {
  37820. int state;
  37821. union {
  37822. sp_521_ecc_mulmod_9_ctx mulmod_ctx;
  37823. };
  37824. sp_digit k[9];
  37825. sp_point_521 point;
  37826. } sp_ecc_sec_gen_521_ctx;
  37827. int sp_ecc_secret_gen_521_nb(sp_ecc_ctx_t* sp_ctx, const mp_int* priv,
  37828. const ecc_point* pub, byte* out, word32* outLen, void* heap)
  37829. {
  37830. int err = FP_WOULDBLOCK;
  37831. sp_ecc_sec_gen_521_ctx* ctx = (sp_ecc_sec_gen_521_ctx*)sp_ctx->data;
  37832. typedef char ctx_size_test[sizeof(sp_ecc_sec_gen_521_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  37833. (void)sizeof(ctx_size_test);
  37834. if (*outLen < 32U) {
  37835. err = BUFFER_E;
  37836. }
  37837. switch (ctx->state) {
  37838. case 0:
  37839. sp_521_from_mp(ctx->k, 9, priv);
  37840. sp_521_point_from_ecc_point_9(&ctx->point, pub);
  37841. ctx->state = 1;
  37842. break;
  37843. case 1:
  37844. err = sp_521_ecc_mulmod_9_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  37845. &ctx->point, &ctx->point, ctx->k, 1, 1, heap);
  37846. if (err == MP_OKAY) {
  37847. sp_521_to_bin_9(ctx->point.x, out);
  37848. *outLen = 66;
  37849. }
  37850. break;
  37851. }
  37852. if (err == MP_OKAY && ctx->state != 1) {
  37853. err = FP_WOULDBLOCK;
  37854. }
  37855. if (err != FP_WOULDBLOCK) {
  37856. XMEMSET(ctx, 0, sizeof(sp_ecc_sec_gen_521_ctx));
  37857. }
  37858. return err;
  37859. }
  37860. #endif /* WOLFSSL_SP_NONBLOCK */
  37861. #endif /* HAVE_ECC_DHE */
  37862. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  37863. SP_NOINLINE static void sp_521_rshift_9(sp_digit* r, const sp_digit* a,
  37864. byte n)
  37865. {
  37866. int i;
  37867. #ifdef WOLFSSL_SP_SMALL
  37868. for (i=0; i<8; i++) {
  37869. r[i] = ((a[i] >> n) | (a[i + 1] << (58 - n))) & 0x3ffffffffffffffL;
  37870. }
  37871. #else
  37872. for (i=0; i<8; i += 8) {
  37873. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (58 - n)) & 0x3ffffffffffffffL);
  37874. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (58 - n)) & 0x3ffffffffffffffL);
  37875. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (58 - n)) & 0x3ffffffffffffffL);
  37876. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (58 - n)) & 0x3ffffffffffffffL);
  37877. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (58 - n)) & 0x3ffffffffffffffL);
  37878. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (58 - n)) & 0x3ffffffffffffffL);
  37879. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (58 - n)) & 0x3ffffffffffffffL);
  37880. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (58 - n)) & 0x3ffffffffffffffL);
  37881. }
  37882. #endif /* WOLFSSL_SP_SMALL */
  37883. r[8] = a[8] >> n;
  37884. }
  37885. #endif
  37886. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  37887. /* Multiply a by scalar b into r. (r = a * b)
  37888. *
  37889. * r A single precision integer.
  37890. * a A single precision integer.
  37891. * b A scalar.
  37892. */
  37893. SP_NOINLINE static void sp_521_mul_d_9(sp_digit* r, const sp_digit* a,
  37894. sp_digit b)
  37895. {
  37896. #ifdef WOLFSSL_SP_SMALL
  37897. sp_int128 tb = b;
  37898. sp_int128 t = 0;
  37899. int i;
  37900. for (i = 0; i < 9; i++) {
  37901. t += tb * a[i];
  37902. r[i] = (sp_digit)(t & 0x3ffffffffffffffL);
  37903. t >>= 58;
  37904. }
  37905. r[9] = (sp_digit)t;
  37906. #else
  37907. sp_int128 tb = b;
  37908. sp_int128 t[9];
  37909. t[ 0] = tb * a[ 0];
  37910. t[ 1] = tb * a[ 1];
  37911. t[ 2] = tb * a[ 2];
  37912. t[ 3] = tb * a[ 3];
  37913. t[ 4] = tb * a[ 4];
  37914. t[ 5] = tb * a[ 5];
  37915. t[ 6] = tb * a[ 6];
  37916. t[ 7] = tb * a[ 7];
  37917. t[ 8] = tb * a[ 8];
  37918. r[ 0] = (sp_digit) (t[ 0] & 0x3ffffffffffffffL);
  37919. r[ 1] = (sp_digit)((t[ 0] >> 58) + (t[ 1] & 0x3ffffffffffffffL));
  37920. r[ 2] = (sp_digit)((t[ 1] >> 58) + (t[ 2] & 0x3ffffffffffffffL));
  37921. r[ 3] = (sp_digit)((t[ 2] >> 58) + (t[ 3] & 0x3ffffffffffffffL));
  37922. r[ 4] = (sp_digit)((t[ 3] >> 58) + (t[ 4] & 0x3ffffffffffffffL));
  37923. r[ 5] = (sp_digit)((t[ 4] >> 58) + (t[ 5] & 0x3ffffffffffffffL));
  37924. r[ 6] = (sp_digit)((t[ 5] >> 58) + (t[ 6] & 0x3ffffffffffffffL));
  37925. r[ 7] = (sp_digit)((t[ 6] >> 58) + (t[ 7] & 0x3ffffffffffffffL));
  37926. r[ 8] = (sp_digit)((t[ 7] >> 58) + (t[ 8] & 0x3ffffffffffffffL));
  37927. r[ 9] = (sp_digit) (t[ 8] >> 58);
  37928. #endif /* WOLFSSL_SP_SMALL */
  37929. }
  37930. SP_NOINLINE static void sp_521_lshift_18(sp_digit* r, const sp_digit* a,
  37931. byte n)
  37932. {
  37933. #ifdef WOLFSSL_SP_SMALL
  37934. int i;
  37935. r[18] = a[17] >> (58 - n);
  37936. for (i=17; i>0; i--) {
  37937. r[i] = ((a[i] << n) | (a[i-1] >> (58 - n))) & 0x3ffffffffffffffL;
  37938. }
  37939. #else
  37940. sp_int_digit s;
  37941. sp_int_digit t;
  37942. s = (sp_int_digit)a[17];
  37943. r[18] = s >> (58U - n);
  37944. s = (sp_int_digit)(a[17]); t = (sp_int_digit)(a[16]);
  37945. r[17] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37946. s = (sp_int_digit)(a[16]); t = (sp_int_digit)(a[15]);
  37947. r[16] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37948. s = (sp_int_digit)(a[15]); t = (sp_int_digit)(a[14]);
  37949. r[15] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37950. s = (sp_int_digit)(a[14]); t = (sp_int_digit)(a[13]);
  37951. r[14] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37952. s = (sp_int_digit)(a[13]); t = (sp_int_digit)(a[12]);
  37953. r[13] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37954. s = (sp_int_digit)(a[12]); t = (sp_int_digit)(a[11]);
  37955. r[12] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37956. s = (sp_int_digit)(a[11]); t = (sp_int_digit)(a[10]);
  37957. r[11] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37958. s = (sp_int_digit)(a[10]); t = (sp_int_digit)(a[9]);
  37959. r[10] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37960. s = (sp_int_digit)(a[9]); t = (sp_int_digit)(a[8]);
  37961. r[9] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37962. s = (sp_int_digit)(a[8]); t = (sp_int_digit)(a[7]);
  37963. r[8] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37964. s = (sp_int_digit)(a[7]); t = (sp_int_digit)(a[6]);
  37965. r[7] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37966. s = (sp_int_digit)(a[6]); t = (sp_int_digit)(a[5]);
  37967. r[6] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37968. s = (sp_int_digit)(a[5]); t = (sp_int_digit)(a[4]);
  37969. r[5] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37970. s = (sp_int_digit)(a[4]); t = (sp_int_digit)(a[3]);
  37971. r[4] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37972. s = (sp_int_digit)(a[3]); t = (sp_int_digit)(a[2]);
  37973. r[3] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37974. s = (sp_int_digit)(a[2]); t = (sp_int_digit)(a[1]);
  37975. r[2] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37976. s = (sp_int_digit)(a[1]); t = (sp_int_digit)(a[0]);
  37977. r[1] = ((s << n) | (t >> (58U - n))) & 0x3ffffffffffffffUL;
  37978. #endif /* WOLFSSL_SP_SMALL */
  37979. r[0] = (a[0] << n) & 0x3ffffffffffffffL;
  37980. }
  37981. /* Divide d in a and put remainder into r (m*d + r = a)
  37982. * m is not calculated as it is not needed at this time.
  37983. *
  37984. * Simplified based on top word of divisor being (1 << 58) - 1
  37985. *
  37986. * a Number to be divided.
  37987. * d Number to divide with.
  37988. * m Multiplier result.
  37989. * r Remainder from the division.
  37990. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  37991. */
  37992. static int sp_521_div_9(const sp_digit* a, const sp_digit* d,
  37993. const sp_digit* m, sp_digit* r)
  37994. {
  37995. int i;
  37996. sp_digit r1;
  37997. sp_digit mask;
  37998. #ifdef WOLFSSL_SP_SMALL_STACK
  37999. sp_digit* t1 = NULL;
  38000. #else
  38001. sp_digit t1[4 * 9 + 3];
  38002. #endif
  38003. sp_digit* t2 = NULL;
  38004. sp_digit* sd = NULL;
  38005. int err = MP_OKAY;
  38006. (void)m;
  38007. #ifdef WOLFSSL_SP_SMALL_STACK
  38008. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 9 + 3), NULL,
  38009. DYNAMIC_TYPE_TMP_BUFFER);
  38010. if (t1 == NULL)
  38011. err = MEMORY_E;
  38012. #endif
  38013. (void)m;
  38014. if (err == MP_OKAY) {
  38015. t2 = t1 + 18 + 1;
  38016. sd = t2 + 9 + 1;
  38017. sp_521_mul_d_9(sd, d, (sp_digit)1 << 1);
  38018. sp_521_lshift_18(t1, a, 1);
  38019. t1[9 + 9] += t1[9 + 9 - 1] >> 58;
  38020. t1[9 + 9 - 1] &= 0x3ffffffffffffffL;
  38021. for (i=8; i>=0; i--) {
  38022. r1 = t1[9 + i];
  38023. sp_521_mul_d_9(t2, sd, r1);
  38024. (void)sp_521_sub_9(&t1[i], &t1[i], t2);
  38025. t1[9 + i] -= t2[9];
  38026. sp_521_norm_9(&t1[i + 1]);
  38027. mask = ~((t1[9 + i] - 1) >> 63);
  38028. sp_521_cond_sub_9(t1 + i, t1 + i, sd, mask);
  38029. sp_521_norm_9(&t1[i + 1]);
  38030. }
  38031. sp_521_norm_9(t1);
  38032. sp_521_rshift_9(r, t1, 1);
  38033. }
  38034. #ifdef WOLFSSL_SP_SMALL_STACK
  38035. if (t1 != NULL)
  38036. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  38037. #endif
  38038. return err;
  38039. }
  38040. /* Reduce a modulo m into r. (r = a mod m)
  38041. *
  38042. * r A single precision number that is the reduced result.
  38043. * a A single precision number that is to be reduced.
  38044. * m A single precision number that is the modulus to reduce with.
  38045. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  38046. */
  38047. static int sp_521_mod_9(sp_digit* r, const sp_digit* a, const sp_digit* m)
  38048. {
  38049. return sp_521_div_9(a, m, NULL, r);
  38050. }
  38051. #endif
  38052. #if defined(HAVE_ECC_SIGN) || defined(HAVE_ECC_VERIFY)
  38053. /* Multiply two number mod the order of P521 curve. (r = a * b mod order)
  38054. *
  38055. * r Result of the multiplication.
  38056. * a First operand of the multiplication.
  38057. * b Second operand of the multiplication.
  38058. */
  38059. static void sp_521_mont_mul_order_9(sp_digit* r, const sp_digit* a, const sp_digit* b)
  38060. {
  38061. sp_521_mul_9(r, a, b);
  38062. sp_521_mont_reduce_order_9(r, p521_order, p521_mp_order);
  38063. }
  38064. #if defined(HAVE_ECC_SIGN) || (defined(HAVE_ECC_VERIFY) && defined(WOLFSSL_SP_SMALL))
  38065. #ifdef WOLFSSL_SP_SMALL
  38066. /* Order-2 for the P521 curve. */
  38067. static const uint64_t p521_order_minus_2[9] = {
  38068. 0xbb6fb71e91386407U,0x3bb5c9b8899c47aeU,0x7fcc0148f709a5d0U,
  38069. 0x51868783bf2f966bU,0xfffffffffffffffaU,0xffffffffffffffffU,
  38070. 0xffffffffffffffffU,0xffffffffffffffffU,0x00000000000001ffU
  38071. };
  38072. #else
  38073. /* The low half of the order-2 of the P521 curve. */
  38074. static const uint64_t p521_order_low[5] = {
  38075. 0xbb6fb71e91386407U,0x3bb5c9b8899c47aeU,0x7fcc0148f709a5d0U,
  38076. 0x51868783bf2f966bU,0xfffffffffffffffaU
  38077. };
  38078. #endif /* WOLFSSL_SP_SMALL */
  38079. /* Square number mod the order of P521 curve. (r = a * a mod order)
  38080. *
  38081. * r Result of the squaring.
  38082. * a Number to square.
  38083. */
  38084. static void sp_521_mont_sqr_order_9(sp_digit* r, const sp_digit* a)
  38085. {
  38086. sp_521_sqr_9(r, a);
  38087. sp_521_mont_reduce_order_9(r, p521_order, p521_mp_order);
  38088. }
  38089. #ifndef WOLFSSL_SP_SMALL
  38090. /* Square number mod the order of P521 curve a number of times.
  38091. * (r = a ^ n mod order)
  38092. *
  38093. * r Result of the squaring.
  38094. * a Number to square.
  38095. */
  38096. static void sp_521_mont_sqr_n_order_9(sp_digit* r, const sp_digit* a, int n)
  38097. {
  38098. int i;
  38099. sp_521_mont_sqr_order_9(r, a);
  38100. for (i=1; i<n; i++) {
  38101. sp_521_mont_sqr_order_9(r, r);
  38102. }
  38103. }
  38104. #endif /* !WOLFSSL_SP_SMALL */
  38105. /* Invert the number, in Montgomery form, modulo the order of the P521 curve.
  38106. * (r = 1 / a mod order)
  38107. *
  38108. * r Inverse result.
  38109. * a Number to invert.
  38110. * td Temporary data.
  38111. */
  38112. #ifdef WOLFSSL_SP_NONBLOCK
  38113. typedef struct sp_521_mont_inv_order_9_ctx {
  38114. int state;
  38115. int i;
  38116. } sp_521_mont_inv_order_9_ctx;
  38117. static int sp_521_mont_inv_order_9_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const sp_digit* a,
  38118. sp_digit* t)
  38119. {
  38120. int err = FP_WOULDBLOCK;
  38121. sp_521_mont_inv_order_9_ctx* ctx = (sp_521_mont_inv_order_9_ctx*)sp_ctx;
  38122. typedef char ctx_size_test[sizeof(sp_521_mont_inv_order_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  38123. (void)sizeof(ctx_size_test);
  38124. switch (ctx->state) {
  38125. case 0:
  38126. XMEMCPY(t, a, sizeof(sp_digit) * 9);
  38127. ctx->i = 519;
  38128. ctx->state = 1;
  38129. break;
  38130. case 1:
  38131. sp_521_mont_sqr_order_9(t, t);
  38132. ctx->state = 2;
  38133. break;
  38134. case 2:
  38135. if ((p521_order_minus_2[ctx->i / 64] & ((sp_int_digit)1 << (ctx->i % 64))) != 0) {
  38136. sp_521_mont_mul_order_9(t, t, a);
  38137. }
  38138. ctx->i--;
  38139. ctx->state = (ctx->i == 0) ? 3 : 1;
  38140. break;
  38141. case 3:
  38142. XMEMCPY(r, t, sizeof(sp_digit) * 9U);
  38143. err = MP_OKAY;
  38144. break;
  38145. }
  38146. return err;
  38147. }
  38148. #endif /* WOLFSSL_SP_NONBLOCK */
  38149. static void sp_521_mont_inv_order_9(sp_digit* r, const sp_digit* a,
  38150. sp_digit* td)
  38151. {
  38152. #ifdef WOLFSSL_SP_SMALL
  38153. sp_digit* t = td;
  38154. int i;
  38155. XMEMCPY(t, a, sizeof(sp_digit) * 9);
  38156. for (i=519; i>=0; i--) {
  38157. sp_521_mont_sqr_order_9(t, t);
  38158. if ((p521_order_minus_2[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  38159. sp_521_mont_mul_order_9(t, t, a);
  38160. }
  38161. }
  38162. XMEMCPY(r, t, sizeof(sp_digit) * 9U);
  38163. #else
  38164. sp_digit* t = td;
  38165. sp_digit* t2 = td + 2 * 9;
  38166. sp_digit* t3 = td + 4 * 9;
  38167. int i;
  38168. /* t = a^2 */
  38169. sp_521_mont_sqr_order_9(t, a);
  38170. /* t = a^3 = t * a */
  38171. sp_521_mont_mul_order_9(t, t, a);
  38172. /* t= a^c = t ^ 2 ^ 2 */
  38173. sp_521_mont_sqr_n_order_9(t2, t, 2);
  38174. /* t = a^f = t2 * t */
  38175. sp_521_mont_mul_order_9(t, t2, t);
  38176. /* t3 = a^1e */
  38177. sp_521_mont_sqr_order_9(t3, t);
  38178. /* t3 = a^1f = t3 * a */
  38179. sp_521_mont_mul_order_9(t3, t3, a);
  38180. /* t2= a^f0 = t ^ 2 ^ 4 */
  38181. sp_521_mont_sqr_n_order_9(t2, t, 4);
  38182. /* t = a^ff = t2 * t */
  38183. sp_521_mont_mul_order_9(t, t2, t);
  38184. /* t2= a^ff00 = t ^ 2 ^ 8 */
  38185. sp_521_mont_sqr_n_order_9(t2, t, 8);
  38186. /* t3= a^ffff = t2 * t */
  38187. sp_521_mont_mul_order_9(t, t2, t);
  38188. /* t2= a^ffff0000 = t ^ 2 ^ 16 */
  38189. sp_521_mont_sqr_n_order_9(t2, t, 16);
  38190. /* t = a^ffffffff = t2 * t */
  38191. sp_521_mont_mul_order_9(t, t2, t);
  38192. /* t2= a^ffffffff00000000 = t ^ 2 ^ 32 */
  38193. sp_521_mont_sqr_n_order_9(t2, t, 32);
  38194. /* t = a^ffffffffffffffff = t2 * t */
  38195. sp_521_mont_mul_order_9(t, t2, t);
  38196. /* t2= a^ffffffffffffffff0000000000000000 = t ^ 2 ^ 64 */
  38197. sp_521_mont_sqr_n_order_9(t2, t, 64);
  38198. /* t = a^ffffffffffffffffffffffffffffffff = t2 * t */
  38199. sp_521_mont_mul_order_9(t, t2, t);
  38200. /* t2= a^ffffffffffffffffffffffffffffffff00000000000000000000000000000000 = t ^ 2 ^ 128 */
  38201. sp_521_mont_sqr_n_order_9(t2, t, 128);
  38202. /* t = a^ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff = t2 * t */
  38203. sp_521_mont_mul_order_9(t, t2, t);
  38204. /* t2 = a^1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0 */
  38205. sp_521_mont_sqr_n_order_9(t2, t, 5);
  38206. /* t2 = a^1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff = t * t3 */
  38207. sp_521_mont_mul_order_9(t2, t2, t3);
  38208. for (i=259; i>=1; i--) {
  38209. sp_521_mont_sqr_order_9(t2, t2);
  38210. if ((p521_order_low[i / 64] & ((sp_int_digit)1 << (i % 64))) != 0) {
  38211. sp_521_mont_mul_order_9(t2, t2, a);
  38212. }
  38213. }
  38214. sp_521_mont_sqr_order_9(t2, t2);
  38215. sp_521_mont_mul_order_9(r, t2, a);
  38216. #endif /* WOLFSSL_SP_SMALL */
  38217. }
  38218. #endif /* HAVE_ECC_SIGN || (HAVE_ECC_VERIFY && WOLFSSL_SP_SMALL) */
  38219. #endif /* HAVE_ECC_SIGN | HAVE_ECC_VERIFY */
  38220. #ifdef HAVE_ECC_SIGN
  38221. #ifndef SP_ECC_MAX_SIG_GEN
  38222. #define SP_ECC_MAX_SIG_GEN 64
  38223. #endif
  38224. /* Calculate second signature value S from R, k and private value.
  38225. *
  38226. * s = (r * x + e) / k
  38227. *
  38228. * s Signature value.
  38229. * r First signature value.
  38230. * k Ephemeral private key.
  38231. * x Private key as a number.
  38232. * e Hash of message as a number.
  38233. * tmp Temporary storage for intermediate numbers.
  38234. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  38235. */
  38236. static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k,
  38237. sp_digit* x, const sp_digit* e, sp_digit* tmp)
  38238. {
  38239. int err;
  38240. sp_digit carry;
  38241. sp_int64 c;
  38242. sp_digit* kInv = k;
  38243. /* Conv k to Montgomery form (mod order) */
  38244. sp_521_mul_9(k, k, p521_norm_order);
  38245. err = sp_521_mod_9(k, k, p521_order);
  38246. if (err == MP_OKAY) {
  38247. sp_521_norm_9(k);
  38248. /* kInv = 1/k mod order */
  38249. sp_521_mont_inv_order_9(kInv, k, tmp);
  38250. sp_521_norm_9(kInv);
  38251. /* s = r * x + e */
  38252. sp_521_mul_9(x, x, r);
  38253. err = sp_521_mod_9(x, x, p521_order);
  38254. }
  38255. if (err == MP_OKAY) {
  38256. sp_521_norm_9(x);
  38257. carry = sp_521_add_9(s, e, x);
  38258. sp_521_cond_sub_9(s, s, p521_order, 0 - carry);
  38259. sp_521_norm_9(s);
  38260. c = sp_521_cmp_9(s, p521_order);
  38261. sp_521_cond_sub_9(s, s, p521_order,
  38262. (sp_digit)0 - (sp_digit)(c >= 0));
  38263. sp_521_norm_9(s);
  38264. /* s = s * k^-1 mod order */
  38265. sp_521_mont_mul_order_9(s, s, kInv);
  38266. sp_521_norm_9(s);
  38267. }
  38268. return err;
  38269. }
  38270. /* Sign the hash using the private key.
  38271. * e = [hash, 521 bits] from binary
  38272. * r = (k.G)->x mod order
  38273. * s = (r * x + e) / k mod order
  38274. * The hash is truncated to the first 521 bits.
  38275. *
  38276. * hash Hash to sign.
  38277. * hashLen Length of the hash data.
  38278. * rng Random number generator.
  38279. * priv Private part of key - scalar.
  38280. * rm First part of result as an mp_int.
  38281. * sm Sirst part of result as an mp_int.
  38282. * heap Heap to use for allocation.
  38283. * returns RNG failures, MEMORY_E when memory allocation fails and
  38284. * MP_OKAY on success.
  38285. */
  38286. int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng,
  38287. const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap)
  38288. {
  38289. #ifdef WOLFSSL_SP_SMALL_STACK
  38290. sp_digit* e = NULL;
  38291. sp_point_521* point = NULL;
  38292. #else
  38293. sp_digit e[7 * 2 * 9];
  38294. sp_point_521 point[1];
  38295. #endif
  38296. sp_digit* x = NULL;
  38297. sp_digit* k = NULL;
  38298. sp_digit* r = NULL;
  38299. sp_digit* tmp = NULL;
  38300. sp_digit* s = NULL;
  38301. sp_int64 c;
  38302. int err = MP_OKAY;
  38303. int i;
  38304. (void)heap;
  38305. #ifdef WOLFSSL_SP_SMALL_STACK
  38306. if (err == MP_OKAY) {
  38307. point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap,
  38308. DYNAMIC_TYPE_ECC);
  38309. if (point == NULL)
  38310. err = MEMORY_E;
  38311. }
  38312. if (err == MP_OKAY) {
  38313. e = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7 * 2 * 9, heap,
  38314. DYNAMIC_TYPE_ECC);
  38315. if (e == NULL)
  38316. err = MEMORY_E;
  38317. }
  38318. #endif
  38319. if (err == MP_OKAY) {
  38320. x = e + 2 * 9;
  38321. k = e + 4 * 9;
  38322. r = e + 6 * 9;
  38323. tmp = e + 8 * 9;
  38324. s = e;
  38325. if (hashLen > 66U) {
  38326. hashLen = 66U;
  38327. }
  38328. }
  38329. for (i = SP_ECC_MAX_SIG_GEN; err == MP_OKAY && i > 0; i--) {
  38330. /* New random point. */
  38331. if (km == NULL || mp_iszero(km)) {
  38332. err = sp_521_ecc_gen_k_9(rng, k);
  38333. }
  38334. else {
  38335. sp_521_from_mp(k, 9, km);
  38336. mp_zero(km);
  38337. }
  38338. if (err == MP_OKAY) {
  38339. err = sp_521_ecc_mulmod_base_9(point, k, 1, 1, heap);
  38340. }
  38341. if (err == MP_OKAY) {
  38342. /* r = point->x mod order */
  38343. XMEMCPY(r, point->x, sizeof(sp_digit) * 9U);
  38344. sp_521_norm_9(r);
  38345. c = sp_521_cmp_9(r, p521_order);
  38346. sp_521_cond_sub_9(r, r, p521_order,
  38347. (sp_digit)0 - (sp_digit)(c >= 0));
  38348. sp_521_norm_9(r);
  38349. if (!sp_521_iszero_9(r)) {
  38350. /* x is modified in calculation of s. */
  38351. sp_521_from_mp(x, 9, priv);
  38352. /* s ptr == e ptr, e is modified in calculation of s. */
  38353. sp_521_from_bin(e, 9, hash, (int)hashLen);
  38354. /* Take 521 leftmost bits of hash. */
  38355. if (hashLen == 66U) {
  38356. sp_521_rshift_9(e, e, 7);
  38357. e[8] |= ((sp_digit)hash[0]) << 49;
  38358. }
  38359. err = sp_521_calc_s_9(s, r, k, x, e, tmp);
  38360. /* Check that signature is usable. */
  38361. if ((err == MP_OKAY) && (!sp_521_iszero_9(s))) {
  38362. break;
  38363. }
  38364. }
  38365. }
  38366. #ifdef WOLFSSL_ECDSA_SET_K_ONE_LOOP
  38367. i = 1;
  38368. #endif
  38369. }
  38370. if (i == 0) {
  38371. err = RNG_FAILURE_E;
  38372. }
  38373. if (err == MP_OKAY) {
  38374. err = sp_521_to_mp(r, rm);
  38375. }
  38376. if (err == MP_OKAY) {
  38377. err = sp_521_to_mp(s, sm);
  38378. }
  38379. #ifdef WOLFSSL_SP_SMALL_STACK
  38380. if (e != NULL)
  38381. #endif
  38382. {
  38383. ForceZero(e, sizeof(sp_digit) * 7 * 2 * 9);
  38384. #ifdef WOLFSSL_SP_SMALL_STACK
  38385. XFREE(e, heap, DYNAMIC_TYPE_ECC);
  38386. #endif
  38387. }
  38388. #ifdef WOLFSSL_SP_SMALL_STACK
  38389. if (point != NULL)
  38390. #endif
  38391. {
  38392. ForceZero(point, sizeof(sp_point_521));
  38393. #ifdef WOLFSSL_SP_SMALL_STACK
  38394. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  38395. #endif
  38396. }
  38397. return err;
  38398. }
  38399. #ifdef WOLFSSL_SP_NONBLOCK
  38400. typedef struct sp_ecc_sign_521_ctx {
  38401. int state;
  38402. union {
  38403. sp_521_ecc_mulmod_9_ctx mulmod_ctx;
  38404. sp_521_mont_inv_order_9_ctx mont_inv_order_ctx;
  38405. };
  38406. sp_digit e[2*9];
  38407. sp_digit x[2*9];
  38408. sp_digit k[2*9];
  38409. sp_digit r[2*9];
  38410. sp_digit tmp[3 * 2*9];
  38411. sp_point_521 point;
  38412. sp_digit* s;
  38413. sp_digit* kInv;
  38414. int i;
  38415. } sp_ecc_sign_521_ctx;
  38416. int sp_ecc_sign_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, WC_RNG* rng,
  38417. mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap)
  38418. {
  38419. int err = FP_WOULDBLOCK;
  38420. sp_ecc_sign_521_ctx* ctx = (sp_ecc_sign_521_ctx*)sp_ctx->data;
  38421. typedef char ctx_size_test[sizeof(sp_ecc_sign_521_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  38422. (void)sizeof(ctx_size_test);
  38423. switch (ctx->state) {
  38424. case 0: /* INIT */
  38425. ctx->s = ctx->e;
  38426. ctx->kInv = ctx->k;
  38427. ctx->i = SP_ECC_MAX_SIG_GEN;
  38428. ctx->state = 1;
  38429. break;
  38430. case 1: /* GEN */
  38431. /* New random point. */
  38432. if (km == NULL || mp_iszero(km)) {
  38433. err = sp_521_ecc_gen_k_9(rng, ctx->k);
  38434. }
  38435. else {
  38436. sp_521_from_mp(ctx->k, 9, km);
  38437. mp_zero(km);
  38438. }
  38439. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  38440. ctx->state = 2;
  38441. break;
  38442. case 2: /* MULMOD */
  38443. err = sp_521_ecc_mulmod_9_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
  38444. &ctx->point, &p521_base, ctx->k, 1, 1, heap);
  38445. if (err == MP_OKAY) {
  38446. ctx->state = 3;
  38447. }
  38448. break;
  38449. case 3: /* MODORDER */
  38450. {
  38451. sp_int64 c;
  38452. /* r = point->x mod order */
  38453. XMEMCPY(ctx->r, ctx->point.x, sizeof(sp_digit) * 9U);
  38454. sp_521_norm_9(ctx->r);
  38455. c = sp_521_cmp_9(ctx->r, p521_order);
  38456. sp_521_cond_sub_9(ctx->r, ctx->r, p521_order,
  38457. (sp_digit)0 - (sp_digit)(c >= 0));
  38458. sp_521_norm_9(ctx->r);
  38459. if (hashLen > 66U) {
  38460. hashLen = 66U;
  38461. }
  38462. sp_521_from_mp(ctx->x, 9, priv);
  38463. sp_521_from_bin(ctx->e, 9, hash, (int)hashLen);
  38464. if (hashLen == 66U) {
  38465. sp_521_rshift_9(ctx->e, ctx->e, 7);
  38466. ctx->e[8] |= ((sp_digit)hash[0]) << 49;
  38467. }
  38468. ctx->state = 4;
  38469. break;
  38470. }
  38471. case 4: /* KMODORDER */
  38472. /* Conv k to Montgomery form (mod order) */
  38473. sp_521_mul_9(ctx->k, ctx->k, p521_norm_order);
  38474. err = sp_521_mod_9(ctx->k, ctx->k, p521_order);
  38475. if (err == MP_OKAY) {
  38476. sp_521_norm_9(ctx->k);
  38477. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  38478. ctx->state = 5;
  38479. }
  38480. break;
  38481. case 5: /* KINV */
  38482. /* kInv = 1/k mod order */
  38483. err = sp_521_mont_inv_order_9_nb((sp_ecc_ctx_t*)&ctx->mont_inv_order_ctx, ctx->kInv, ctx->k, ctx->tmp);
  38484. if (err == MP_OKAY) {
  38485. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  38486. ctx->state = 6;
  38487. }
  38488. break;
  38489. case 6: /* KINVNORM */
  38490. sp_521_norm_9(ctx->kInv);
  38491. ctx->state = 7;
  38492. break;
  38493. case 7: /* R */
  38494. /* s = r * x + e */
  38495. sp_521_mul_9(ctx->x, ctx->x, ctx->r);
  38496. ctx->state = 8;
  38497. break;
  38498. case 8: /* S1 */
  38499. err = sp_521_mod_9(ctx->x, ctx->x, p521_order);
  38500. if (err == MP_OKAY)
  38501. ctx->state = 9;
  38502. break;
  38503. case 9: /* S2 */
  38504. {
  38505. sp_digit carry;
  38506. sp_int64 c;
  38507. sp_521_norm_9(ctx->x);
  38508. carry = sp_521_add_9(ctx->s, ctx->e, ctx->x);
  38509. sp_521_cond_sub_9(ctx->s, ctx->s,
  38510. p521_order, 0 - carry);
  38511. sp_521_norm_9(ctx->s);
  38512. c = sp_521_cmp_9(ctx->s, p521_order);
  38513. sp_521_cond_sub_9(ctx->s, ctx->s, p521_order,
  38514. (sp_digit)0 - (sp_digit)(c >= 0));
  38515. sp_521_norm_9(ctx->s);
  38516. /* s = s * k^-1 mod order */
  38517. sp_521_mont_mul_order_9(ctx->s, ctx->s, ctx->kInv);
  38518. sp_521_norm_9(ctx->s);
  38519. /* Check that signature is usable. */
  38520. if (sp_521_iszero_9(ctx->s) == 0) {
  38521. ctx->state = 10;
  38522. break;
  38523. }
  38524. #ifdef WOLFSSL_ECDSA_SET_K_ONE_LOOP
  38525. ctx->i = 1;
  38526. #endif
  38527. /* not usable gen, try again */
  38528. ctx->i--;
  38529. if (ctx->i == 0) {
  38530. err = RNG_FAILURE_E;
  38531. }
  38532. ctx->state = 1;
  38533. break;
  38534. }
  38535. case 10: /* RES */
  38536. err = sp_521_to_mp(ctx->r, rm);
  38537. if (err == MP_OKAY) {
  38538. err = sp_521_to_mp(ctx->s, sm);
  38539. }
  38540. break;
  38541. }
  38542. if (err == MP_OKAY && ctx->state != 10) {
  38543. err = FP_WOULDBLOCK;
  38544. }
  38545. if (err != FP_WOULDBLOCK) {
  38546. XMEMSET(ctx->e, 0, sizeof(sp_digit) * 2U * 9U);
  38547. XMEMSET(ctx->x, 0, sizeof(sp_digit) * 2U * 9U);
  38548. XMEMSET(ctx->k, 0, sizeof(sp_digit) * 2U * 9U);
  38549. XMEMSET(ctx->r, 0, sizeof(sp_digit) * 2U * 9U);
  38550. XMEMSET(ctx->tmp, 0, sizeof(sp_digit) * 3U * 2U * 9U);
  38551. }
  38552. return err;
  38553. }
  38554. #endif /* WOLFSSL_SP_NONBLOCK */
  38555. #endif /* HAVE_ECC_SIGN */
  38556. #ifndef WOLFSSL_SP_SMALL
  38557. static const char sp_521_tab64_9[64] = {
  38558. 64, 1, 59, 2, 60, 48, 54, 3,
  38559. 61, 40, 49, 28, 55, 34, 43, 4,
  38560. 62, 52, 38, 41, 50, 19, 29, 21,
  38561. 56, 31, 35, 12, 44, 15, 23, 5,
  38562. 63, 58, 47, 53, 39, 27, 33, 42,
  38563. 51, 37, 18, 20, 30, 11, 14, 22,
  38564. 57, 46, 26, 32, 36, 17, 10, 13,
  38565. 45, 25, 16, 9, 24, 8, 7, 6};
  38566. static int sp_521_num_bits_58_9(sp_digit v)
  38567. {
  38568. v |= v >> 1;
  38569. v |= v >> 2;
  38570. v |= v >> 4;
  38571. v |= v >> 8;
  38572. v |= v >> 16;
  38573. v |= v >> 32;
  38574. return sp_521_tab64_9[((uint64_t)((v - (v >> 1))*0x07EDD5E59A4E28C2)) >> 58];
  38575. }
  38576. static int sp_521_num_bits_9(const sp_digit* a)
  38577. {
  38578. int i;
  38579. int r = 0;
  38580. for (i = 8; i >= 0; i--) {
  38581. if (a[i] != 0) {
  38582. r = sp_521_num_bits_58_9(a[i]);
  38583. r += i * 58;
  38584. break;
  38585. }
  38586. }
  38587. return r;
  38588. }
  38589. /* Non-constant time modular inversion.
  38590. *
  38591. * @param [out] r Resulting number.
  38592. * @param [in] a Number to invert.
  38593. * @param [in] m Modulus.
  38594. * @return MP_OKAY on success.
  38595. * @return MEMEORY_E when dynamic memory allocation fails.
  38596. */
  38597. static int sp_521_mod_inv_9(sp_digit* r, const sp_digit* a, const sp_digit* m)
  38598. {
  38599. int err = MP_OKAY;
  38600. #ifdef WOLFSSL_SP_SMALL_STACK
  38601. sp_digit* u = NULL;
  38602. #else
  38603. sp_digit u[9 * 4];
  38604. #endif
  38605. sp_digit* v = NULL;
  38606. sp_digit* b = NULL;
  38607. sp_digit* d = NULL;
  38608. int ut;
  38609. int vt;
  38610. #ifdef WOLFSSL_SP_SMALL_STACK
  38611. u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, NULL,
  38612. DYNAMIC_TYPE_ECC);
  38613. if (u == NULL)
  38614. err = MEMORY_E;
  38615. #endif
  38616. if (err == MP_OKAY) {
  38617. v = u + 9;
  38618. b = u + 2 * 9;
  38619. d = u + 3 * 9;
  38620. XMEMCPY(u, m, sizeof(sp_digit) * 9);
  38621. XMEMCPY(v, a, sizeof(sp_digit) * 9);
  38622. ut = sp_521_num_bits_9(u);
  38623. vt = sp_521_num_bits_9(v);
  38624. XMEMSET(b, 0, sizeof(sp_digit) * 9);
  38625. if ((v[0] & 1) == 0) {
  38626. sp_521_rshift1_9(v, v);
  38627. XMEMCPY(d, m, sizeof(sp_digit) * 9);
  38628. d[0]++;
  38629. sp_521_rshift1_9(d, d);
  38630. vt--;
  38631. while ((v[0] & 1) == 0) {
  38632. sp_521_rshift1_9(v, v);
  38633. if (d[0] & 1)
  38634. sp_521_add_9(d, d, m);
  38635. sp_521_rshift1_9(d, d);
  38636. vt--;
  38637. }
  38638. }
  38639. else {
  38640. XMEMSET(d+1, 0, sizeof(sp_digit) * (9 - 1));
  38641. d[0] = 1;
  38642. }
  38643. while (ut > 1 && vt > 1) {
  38644. if ((ut > vt) || ((ut == vt) &&
  38645. (sp_521_cmp_9(u, v) >= 0))) {
  38646. sp_521_sub_9(u, u, v);
  38647. sp_521_norm_9(u);
  38648. sp_521_sub_9(b, b, d);
  38649. sp_521_norm_9(b);
  38650. if (b[8] < 0)
  38651. sp_521_add_9(b, b, m);
  38652. sp_521_norm_9(b);
  38653. ut = sp_521_num_bits_9(u);
  38654. do {
  38655. sp_521_rshift1_9(u, u);
  38656. if (b[0] & 1)
  38657. sp_521_add_9(b, b, m);
  38658. sp_521_rshift1_9(b, b);
  38659. ut--;
  38660. }
  38661. while (ut > 0 && (u[0] & 1) == 0);
  38662. }
  38663. else {
  38664. sp_521_sub_9(v, v, u);
  38665. sp_521_norm_9(v);
  38666. sp_521_sub_9(d, d, b);
  38667. sp_521_norm_9(d);
  38668. if (d[8] < 0)
  38669. sp_521_add_9(d, d, m);
  38670. sp_521_norm_9(d);
  38671. vt = sp_521_num_bits_9(v);
  38672. do {
  38673. sp_521_rshift1_9(v, v);
  38674. if (d[0] & 1)
  38675. sp_521_add_9(d, d, m);
  38676. sp_521_rshift1_9(d, d);
  38677. vt--;
  38678. }
  38679. while (vt > 0 && (v[0] & 1) == 0);
  38680. }
  38681. }
  38682. if (ut == 1)
  38683. XMEMCPY(r, b, sizeof(sp_digit) * 9);
  38684. else
  38685. XMEMCPY(r, d, sizeof(sp_digit) * 9);
  38686. }
  38687. #ifdef WOLFSSL_SP_SMALL_STACK
  38688. if (u != NULL)
  38689. XFREE(u, NULL, DYNAMIC_TYPE_ECC);
  38690. #endif
  38691. return err;
  38692. }
  38693. #endif /* WOLFSSL_SP_SMALL */
  38694. /* Add point p1 into point p2. Handles p1 == p2 and result at infinity.
  38695. *
  38696. * p1 First point to add and holds result.
  38697. * p2 Second point to add.
  38698. * tmp Temporary storage for intermediate numbers.
  38699. */
  38700. static void sp_521_add_points_9(sp_point_521* p1, const sp_point_521* p2,
  38701. sp_digit* tmp)
  38702. {
  38703. sp_521_proj_point_add_9(p1, p1, p2, tmp);
  38704. if (sp_521_iszero_9(p1->z)) {
  38705. if (sp_521_iszero_9(p1->x) && sp_521_iszero_9(p1->y)) {
  38706. sp_521_proj_point_dbl_9(p1, p2, tmp);
  38707. }
  38708. else {
  38709. /* Y ordinate is not used from here - don't set. */
  38710. p1->x[0] = 0;
  38711. p1->x[1] = 0;
  38712. p1->x[2] = 0;
  38713. p1->x[3] = 0;
  38714. p1->x[4] = 0;
  38715. p1->x[5] = 0;
  38716. p1->x[6] = 0;
  38717. p1->x[7] = 0;
  38718. p1->x[8] = 0;
  38719. XMEMCPY(p1->z, p521_norm_mod, sizeof(p521_norm_mod));
  38720. }
  38721. }
  38722. }
  38723. /* Calculate the verification point: [e/s]G + [r/s]Q
  38724. *
  38725. * p1 Calculated point.
  38726. * p2 Public point and temporary.
  38727. * s Second part of signature as a number.
  38728. * u1 Temporary number.
  38729. * u2 Temporary number.
  38730. * heap Heap to use for allocation.
  38731. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  38732. */
  38733. static int sp_521_calc_vfy_point_9(sp_point_521* p1, sp_point_521* p2,
  38734. sp_digit* s, sp_digit* u1, sp_digit* u2, sp_digit* tmp, void* heap)
  38735. {
  38736. int err;
  38737. #ifndef WOLFSSL_SP_SMALL
  38738. err = sp_521_mod_inv_9(s, s, p521_order);
  38739. if (err == MP_OKAY)
  38740. #endif /* !WOLFSSL_SP_SMALL */
  38741. {
  38742. sp_521_mul_9(s, s, p521_norm_order);
  38743. err = sp_521_mod_9(s, s, p521_order);
  38744. }
  38745. if (err == MP_OKAY) {
  38746. sp_521_norm_9(s);
  38747. #ifdef WOLFSSL_SP_SMALL
  38748. {
  38749. sp_521_mont_inv_order_9(s, s, tmp);
  38750. sp_521_mont_mul_order_9(u1, u1, s);
  38751. sp_521_mont_mul_order_9(u2, u2, s);
  38752. }
  38753. #else
  38754. {
  38755. sp_521_mont_mul_order_9(u1, u1, s);
  38756. sp_521_mont_mul_order_9(u2, u2, s);
  38757. }
  38758. #endif /* WOLFSSL_SP_SMALL */
  38759. {
  38760. err = sp_521_ecc_mulmod_base_9(p1, u1, 0, 0, heap);
  38761. }
  38762. }
  38763. if ((err == MP_OKAY) && sp_521_iszero_9(p1->z)) {
  38764. p1->infinity = 1;
  38765. }
  38766. if (err == MP_OKAY) {
  38767. err = sp_521_ecc_mulmod_9(p2, p2, u2, 0, 0, heap);
  38768. }
  38769. if ((err == MP_OKAY) && sp_521_iszero_9(p2->z)) {
  38770. p2->infinity = 1;
  38771. }
  38772. if (err == MP_OKAY) {
  38773. sp_521_add_points_9(p1, p2, tmp);
  38774. }
  38775. return err;
  38776. }
  38777. #ifdef HAVE_ECC_VERIFY
  38778. /* Verify the signature values with the hash and public key.
  38779. * e = Truncate(hash, 521)
  38780. * u1 = e/s mod order
  38781. * u2 = r/s mod order
  38782. * r == (u1.G + u2.Q)->x mod order
  38783. * Optimization: Leave point in projective form.
  38784. * (x, y, 1) == (x' / z'*z', y' / z'*z'*z', z' / z')
  38785. * (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x'
  38786. * The hash is truncated to the first 521 bits.
  38787. *
  38788. * hash Hash to sign.
  38789. * hashLen Length of the hash data.
  38790. * rng Random number generator.
  38791. * priv Private part of key - scalar.
  38792. * rm First part of result as an mp_int.
  38793. * sm Sirst part of result as an mp_int.
  38794. * heap Heap to use for allocation.
  38795. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  38796. */
  38797. int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX,
  38798. const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm,
  38799. int* res, void* heap)
  38800. {
  38801. #ifdef WOLFSSL_SP_SMALL_STACK
  38802. sp_digit* u1 = NULL;
  38803. sp_point_521* p1 = NULL;
  38804. #else
  38805. sp_digit u1[18 * 9];
  38806. sp_point_521 p1[2];
  38807. #endif
  38808. sp_digit* u2 = NULL;
  38809. sp_digit* s = NULL;
  38810. sp_digit* tmp = NULL;
  38811. sp_point_521* p2 = NULL;
  38812. sp_digit carry;
  38813. sp_int64 c = 0;
  38814. int err = MP_OKAY;
  38815. #ifdef WOLFSSL_SP_SMALL_STACK
  38816. if (err == MP_OKAY) {
  38817. p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap,
  38818. DYNAMIC_TYPE_ECC);
  38819. if (p1 == NULL)
  38820. err = MEMORY_E;
  38821. }
  38822. if (err == MP_OKAY) {
  38823. u1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 9, heap,
  38824. DYNAMIC_TYPE_ECC);
  38825. if (u1 == NULL)
  38826. err = MEMORY_E;
  38827. }
  38828. #endif
  38829. if (err == MP_OKAY) {
  38830. u2 = u1 + 2 * 9;
  38831. s = u1 + 4 * 9;
  38832. tmp = u1 + 6 * 9;
  38833. p2 = p1 + 1;
  38834. if (hashLen > 66U) {
  38835. hashLen = 66U;
  38836. }
  38837. sp_521_from_bin(u1, 9, hash, (int)hashLen);
  38838. sp_521_from_mp(u2, 9, rm);
  38839. sp_521_from_mp(s, 9, sm);
  38840. sp_521_from_mp(p2->x, 9, pX);
  38841. sp_521_from_mp(p2->y, 9, pY);
  38842. sp_521_from_mp(p2->z, 9, pZ);
  38843. if (hashLen == 66U) {
  38844. sp_521_rshift_9(u1, u1, 7);
  38845. u1[8] |= ((sp_digit)hash[0]) << 49;
  38846. }
  38847. err = sp_521_calc_vfy_point_9(p1, p2, s, u1, u2, tmp, heap);
  38848. }
  38849. if (err == MP_OKAY) {
  38850. /* (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x' */
  38851. /* Reload r and convert to Montgomery form. */
  38852. sp_521_from_mp(u2, 9, rm);
  38853. err = sp_521_mod_mul_norm_9(u2, u2, p521_mod);
  38854. }
  38855. if (err == MP_OKAY) {
  38856. /* u1 = r.z'.z' mod prime */
  38857. sp_521_mont_sqr_9(p1->z, p1->z, p521_mod, p521_mp_mod);
  38858. sp_521_mont_mul_9(u1, u2, p1->z, p521_mod, p521_mp_mod);
  38859. *res = (int)(sp_521_cmp_9(p1->x, u1) == 0);
  38860. if (*res == 0) {
  38861. /* Reload r and add order. */
  38862. sp_521_from_mp(u2, 9, rm);
  38863. carry = sp_521_add_9(u2, u2, p521_order);
  38864. /* Carry means result is greater than mod and is not valid. */
  38865. if (carry == 0) {
  38866. sp_521_norm_9(u2);
  38867. /* Compare with mod and if greater or equal then not valid. */
  38868. c = sp_521_cmp_9(u2, p521_mod);
  38869. }
  38870. }
  38871. if ((*res == 0) && (c < 0)) {
  38872. /* Convert to Montogomery form */
  38873. err = sp_521_mod_mul_norm_9(u2, u2, p521_mod);
  38874. if (err == MP_OKAY) {
  38875. /* u1 = (r + 1*order).z'.z' mod prime */
  38876. {
  38877. sp_521_mont_mul_9(u1, u2, p1->z, p521_mod, p521_mp_mod);
  38878. }
  38879. *res = (sp_521_cmp_9(p1->x, u1) == 0);
  38880. }
  38881. }
  38882. }
  38883. #ifdef WOLFSSL_SP_SMALL_STACK
  38884. if (u1 != NULL)
  38885. XFREE(u1, heap, DYNAMIC_TYPE_ECC);
  38886. if (p1 != NULL)
  38887. XFREE(p1, heap, DYNAMIC_TYPE_ECC);
  38888. #endif
  38889. return err;
  38890. }
  38891. #ifdef WOLFSSL_SP_NONBLOCK
  38892. typedef struct sp_ecc_verify_521_ctx {
  38893. int state;
  38894. union {
  38895. sp_521_ecc_mulmod_9_ctx mulmod_ctx;
  38896. sp_521_mont_inv_order_9_ctx mont_inv_order_ctx;
  38897. sp_521_proj_point_dbl_9_ctx dbl_ctx;
  38898. sp_521_proj_point_add_9_ctx add_ctx;
  38899. };
  38900. sp_digit u1[2*9];
  38901. sp_digit u2[2*9];
  38902. sp_digit s[2*9];
  38903. sp_digit tmp[2*9 * 6];
  38904. sp_point_521 p1;
  38905. sp_point_521 p2;
  38906. } sp_ecc_verify_521_ctx;
  38907. int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash,
  38908. word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ,
  38909. const mp_int* rm, const mp_int* sm, int* res, void* heap)
  38910. {
  38911. int err = FP_WOULDBLOCK;
  38912. sp_ecc_verify_521_ctx* ctx = (sp_ecc_verify_521_ctx*)sp_ctx->data;
  38913. typedef char ctx_size_test[sizeof(sp_ecc_verify_521_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  38914. (void)sizeof(ctx_size_test);
  38915. switch (ctx->state) {
  38916. case 0: /* INIT */
  38917. if (hashLen > 66U) {
  38918. hashLen = 66U;
  38919. }
  38920. sp_521_from_bin(ctx->u1, 9, hash, (int)hashLen);
  38921. sp_521_from_mp(ctx->u2, 9, rm);
  38922. sp_521_from_mp(ctx->s, 9, sm);
  38923. sp_521_from_mp(ctx->p2.x, 9, pX);
  38924. sp_521_from_mp(ctx->p2.y, 9, pY);
  38925. sp_521_from_mp(ctx->p2.z, 9, pZ);
  38926. if (hashLen == 66U) {
  38927. sp_521_rshift_9(ctx->u1, ctx->u1, 7);
  38928. ctx->u1[8] |= ((sp_digit)hash[0]) << 49;
  38929. }
  38930. ctx->state = 1;
  38931. break;
  38932. case 1: /* NORMS0 */
  38933. sp_521_mul_9(ctx->s, ctx->s, p521_norm_order);
  38934. err = sp_521_mod_9(ctx->s, ctx->s, p521_order);
  38935. if (err == MP_OKAY)
  38936. ctx->state = 2;
  38937. break;
  38938. case 2: /* NORMS1 */
  38939. sp_521_norm_9(ctx->s);
  38940. XMEMSET(&ctx->mont_inv_order_ctx, 0, sizeof(ctx->mont_inv_order_ctx));
  38941. ctx->state = 3;
  38942. break;
  38943. case 3: /* NORMS2 */
  38944. err = sp_521_mont_inv_order_9_nb((sp_ecc_ctx_t*)&ctx->mont_inv_order_ctx, ctx->s, ctx->s, ctx->tmp);
  38945. if (err == MP_OKAY) {
  38946. ctx->state = 4;
  38947. }
  38948. break;
  38949. case 4: /* NORMS3 */
  38950. sp_521_mont_mul_order_9(ctx->u1, ctx->u1, ctx->s);
  38951. ctx->state = 5;
  38952. break;
  38953. case 5: /* NORMS4 */
  38954. sp_521_mont_mul_order_9(ctx->u2, ctx->u2, ctx->s);
  38955. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  38956. ctx->state = 6;
  38957. break;
  38958. case 6: /* MULBASE */
  38959. err = sp_521_ecc_mulmod_9_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx, &ctx->p1, &p521_base, ctx->u1, 0, 0, heap);
  38960. if (err == MP_OKAY) {
  38961. if (sp_521_iszero_9(ctx->p1.z)) {
  38962. ctx->p1.infinity = 1;
  38963. }
  38964. XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
  38965. ctx->state = 7;
  38966. }
  38967. break;
  38968. case 7: /* MULMOD */
  38969. err = sp_521_ecc_mulmod_9_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx, &ctx->p2, &ctx->p2, ctx->u2, 0, 0, heap);
  38970. if (err == MP_OKAY) {
  38971. if (sp_521_iszero_9(ctx->p2.z)) {
  38972. ctx->p2.infinity = 1;
  38973. }
  38974. XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx));
  38975. ctx->state = 8;
  38976. }
  38977. break;
  38978. case 8: /* ADD */
  38979. err = sp_521_proj_point_add_9_nb((sp_ecc_ctx_t*)&ctx->add_ctx, &ctx->p1, &ctx->p1, &ctx->p2, ctx->tmp);
  38980. if (err == MP_OKAY)
  38981. ctx->state = 9;
  38982. break;
  38983. case 9: /* MONT */
  38984. /* (r + n*order).z'.z' mod prime == (u1.G + u2.Q)->x' */
  38985. /* Reload r and convert to Montgomery form. */
  38986. sp_521_from_mp(ctx->u2, 9, rm);
  38987. err = sp_521_mod_mul_norm_9(ctx->u2, ctx->u2, p521_mod);
  38988. if (err == MP_OKAY)
  38989. ctx->state = 10;
  38990. break;
  38991. case 10: /* SQR */
  38992. /* u1 = r.z'.z' mod prime */
  38993. sp_521_mont_sqr_9(ctx->p1.z, ctx->p1.z, p521_mod, p521_mp_mod);
  38994. ctx->state = 11;
  38995. break;
  38996. case 11: /* MUL */
  38997. sp_521_mont_mul_9(ctx->u1, ctx->u2, ctx->p1.z, p521_mod, p521_mp_mod);
  38998. ctx->state = 12;
  38999. break;
  39000. case 12: /* RES */
  39001. {
  39002. sp_int64 c = 0;
  39003. err = MP_OKAY; /* math okay, now check result */
  39004. *res = (int)(sp_521_cmp_9(ctx->p1.x, ctx->u1) == 0);
  39005. if (*res == 0) {
  39006. sp_digit carry;
  39007. /* Reload r and add order. */
  39008. sp_521_from_mp(ctx->u2, 9, rm);
  39009. carry = sp_521_add_9(ctx->u2, ctx->u2, p521_order);
  39010. /* Carry means result is greater than mod and is not valid. */
  39011. if (carry == 0) {
  39012. sp_521_norm_9(ctx->u2);
  39013. /* Compare with mod and if greater or equal then not valid. */
  39014. c = sp_521_cmp_9(ctx->u2, p521_mod);
  39015. }
  39016. }
  39017. if ((*res == 0) && (c < 0)) {
  39018. /* Convert to Montogomery form */
  39019. err = sp_521_mod_mul_norm_9(ctx->u2, ctx->u2, p521_mod);
  39020. if (err == MP_OKAY) {
  39021. /* u1 = (r + 1*order).z'.z' mod prime */
  39022. sp_521_mont_mul_9(ctx->u1, ctx->u2, ctx->p1.z, p521_mod,
  39023. p521_mp_mod);
  39024. *res = (int)(sp_521_cmp_9(ctx->p1.x, ctx->u1) == 0);
  39025. }
  39026. }
  39027. break;
  39028. }
  39029. } /* switch */
  39030. if (err == MP_OKAY && ctx->state != 12) {
  39031. err = FP_WOULDBLOCK;
  39032. }
  39033. return err;
  39034. }
  39035. #endif /* WOLFSSL_SP_NONBLOCK */
  39036. #endif /* HAVE_ECC_VERIFY */
  39037. #ifdef HAVE_ECC_CHECK_KEY
  39038. /* Check that the x and y oridinates are a valid point on the curve.
  39039. *
  39040. * point EC point.
  39041. * heap Heap to use if dynamically allocating.
  39042. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  39043. * not on the curve and MP_OKAY otherwise.
  39044. */
  39045. static int sp_521_ecc_is_point_9(const sp_point_521* point,
  39046. void* heap)
  39047. {
  39048. #ifdef WOLFSSL_SP_SMALL_STACK
  39049. sp_digit* t1 = NULL;
  39050. #else
  39051. sp_digit t1[9 * 4];
  39052. #endif
  39053. sp_digit* t2 = NULL;
  39054. int err = MP_OKAY;
  39055. #ifdef WOLFSSL_SP_SMALL_STACK
  39056. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, heap, DYNAMIC_TYPE_ECC);
  39057. if (t1 == NULL)
  39058. err = MEMORY_E;
  39059. #endif
  39060. (void)heap;
  39061. if (err == MP_OKAY) {
  39062. t2 = t1 + 2 * 9;
  39063. /* y^2 - x^3 - a.x = b */
  39064. sp_521_sqr_9(t1, point->y);
  39065. (void)sp_521_mod_9(t1, t1, p521_mod);
  39066. sp_521_sqr_9(t2, point->x);
  39067. (void)sp_521_mod_9(t2, t2, p521_mod);
  39068. sp_521_mul_9(t2, t2, point->x);
  39069. (void)sp_521_mod_9(t2, t2, p521_mod);
  39070. sp_521_mont_sub_9(t1, t1, t2, p521_mod);
  39071. /* y^2 - x^3 + 3.x = b, when a = -3 */
  39072. sp_521_mont_add_9(t1, t1, point->x, p521_mod);
  39073. sp_521_mont_add_9(t1, t1, point->x, p521_mod);
  39074. sp_521_mont_add_9(t1, t1, point->x, p521_mod);
  39075. if (sp_521_cmp_9(t1, p521_b) != 0) {
  39076. err = MP_VAL;
  39077. }
  39078. }
  39079. #ifdef WOLFSSL_SP_SMALL_STACK
  39080. if (t1 != NULL)
  39081. XFREE(t1, heap, DYNAMIC_TYPE_ECC);
  39082. #endif
  39083. return err;
  39084. }
  39085. /* Check that the x and y oridinates are a valid point on the curve.
  39086. *
  39087. * pX X ordinate of EC point.
  39088. * pY Y ordinate of EC point.
  39089. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  39090. * not on the curve and MP_OKAY otherwise.
  39091. */
  39092. int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY)
  39093. {
  39094. #ifdef WOLFSSL_SP_SMALL_STACK
  39095. sp_point_521* pub = NULL;
  39096. #else
  39097. sp_point_521 pub[1];
  39098. #endif
  39099. const byte one[1] = { 1 };
  39100. int err = MP_OKAY;
  39101. #ifdef WOLFSSL_SP_SMALL_STACK
  39102. pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL,
  39103. DYNAMIC_TYPE_ECC);
  39104. if (pub == NULL)
  39105. err = MEMORY_E;
  39106. #endif
  39107. if (err == MP_OKAY) {
  39108. sp_521_from_mp(pub->x, 9, pX);
  39109. sp_521_from_mp(pub->y, 9, pY);
  39110. sp_521_from_bin(pub->z, 9, one, (int)sizeof(one));
  39111. err = sp_521_ecc_is_point_9(pub, NULL);
  39112. }
  39113. #ifdef WOLFSSL_SP_SMALL_STACK
  39114. if (pub != NULL)
  39115. XFREE(pub, NULL, DYNAMIC_TYPE_ECC);
  39116. #endif
  39117. return err;
  39118. }
  39119. /* Check that the private scalar generates the EC point (px, py), the point is
  39120. * on the curve and the point has the correct order.
  39121. *
  39122. * pX X ordinate of EC point.
  39123. * pY Y ordinate of EC point.
  39124. * privm Private scalar that generates EC point.
  39125. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  39126. * not on the curve, ECC_INF_E if the point does not have the correct order,
  39127. * ECC_PRIV_KEY_E when the private scalar doesn't generate the EC point and
  39128. * MP_OKAY otherwise.
  39129. */
  39130. int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY,
  39131. const mp_int* privm, void* heap)
  39132. {
  39133. #ifdef WOLFSSL_SP_SMALL_STACK
  39134. sp_digit* priv = NULL;
  39135. sp_point_521* pub = NULL;
  39136. #else
  39137. sp_digit priv[9];
  39138. sp_point_521 pub[2];
  39139. #endif
  39140. sp_point_521* p = NULL;
  39141. const byte one[1] = { 1 };
  39142. int err = MP_OKAY;
  39143. /* Quick check the lengs of public key ordinates and private key are in
  39144. * range. Proper check later.
  39145. */
  39146. if (((mp_count_bits(pX) > 521) ||
  39147. (mp_count_bits(pY) > 521) ||
  39148. ((privm != NULL) && (mp_count_bits(privm) > 521)))) {
  39149. err = ECC_OUT_OF_RANGE_E;
  39150. }
  39151. #ifdef WOLFSSL_SP_SMALL_STACK
  39152. if (err == MP_OKAY) {
  39153. pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap,
  39154. DYNAMIC_TYPE_ECC);
  39155. if (pub == NULL)
  39156. err = MEMORY_E;
  39157. }
  39158. if (err == MP_OKAY && privm) {
  39159. priv = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9, heap,
  39160. DYNAMIC_TYPE_ECC);
  39161. if (priv == NULL)
  39162. err = MEMORY_E;
  39163. }
  39164. #endif
  39165. if (err == MP_OKAY) {
  39166. p = pub + 1;
  39167. sp_521_from_mp(pub->x, 9, pX);
  39168. sp_521_from_mp(pub->y, 9, pY);
  39169. sp_521_from_bin(pub->z, 9, one, (int)sizeof(one));
  39170. if (privm)
  39171. sp_521_from_mp(priv, 9, privm);
  39172. /* Check point at infinitiy. */
  39173. if ((sp_521_iszero_9(pub->x) != 0) &&
  39174. (sp_521_iszero_9(pub->y) != 0)) {
  39175. err = ECC_INF_E;
  39176. }
  39177. }
  39178. /* Check range of X and Y */
  39179. if ((err == MP_OKAY) &&
  39180. ((sp_521_cmp_9(pub->x, p521_mod) >= 0) ||
  39181. (sp_521_cmp_9(pub->y, p521_mod) >= 0))) {
  39182. err = ECC_OUT_OF_RANGE_E;
  39183. }
  39184. if (err == MP_OKAY) {
  39185. /* Check point is on curve */
  39186. err = sp_521_ecc_is_point_9(pub, heap);
  39187. }
  39188. if (err == MP_OKAY) {
  39189. /* Point * order = infinity */
  39190. err = sp_521_ecc_mulmod_9(p, pub, p521_order, 1, 1, heap);
  39191. }
  39192. /* Check result is infinity */
  39193. if ((err == MP_OKAY) && ((sp_521_iszero_9(p->x) == 0) ||
  39194. (sp_521_iszero_9(p->y) == 0))) {
  39195. err = ECC_INF_E;
  39196. }
  39197. if (privm) {
  39198. if (err == MP_OKAY) {
  39199. /* Base * private = point */
  39200. err = sp_521_ecc_mulmod_base_9(p, priv, 1, 1, heap);
  39201. }
  39202. /* Check result is public key */
  39203. if ((err == MP_OKAY) &&
  39204. ((sp_521_cmp_9(p->x, pub->x) != 0) ||
  39205. (sp_521_cmp_9(p->y, pub->y) != 0))) {
  39206. err = ECC_PRIV_KEY_E;
  39207. }
  39208. }
  39209. #ifdef WOLFSSL_SP_SMALL_STACK
  39210. if (pub != NULL)
  39211. XFREE(pub, heap, DYNAMIC_TYPE_ECC);
  39212. if (priv != NULL)
  39213. XFREE(priv, heap, DYNAMIC_TYPE_ECC);
  39214. #endif
  39215. return err;
  39216. }
  39217. #endif
  39218. #ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL
  39219. /* Add two projective EC points together.
  39220. * (pX, pY, pZ) + (qX, qY, qZ) = (rX, rY, rZ)
  39221. *
  39222. * pX First EC point's X ordinate.
  39223. * pY First EC point's Y ordinate.
  39224. * pZ First EC point's Z ordinate.
  39225. * qX Second EC point's X ordinate.
  39226. * qY Second EC point's Y ordinate.
  39227. * qZ Second EC point's Z ordinate.
  39228. * rX Resultant EC point's X ordinate.
  39229. * rY Resultant EC point's Y ordinate.
  39230. * rZ Resultant EC point's Z ordinate.
  39231. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  39232. */
  39233. int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ,
  39234. mp_int* qX, mp_int* qY, mp_int* qZ,
  39235. mp_int* rX, mp_int* rY, mp_int* rZ)
  39236. {
  39237. #ifdef WOLFSSL_SP_SMALL_STACK
  39238. sp_digit* tmp = NULL;
  39239. sp_point_521* p = NULL;
  39240. #else
  39241. sp_digit tmp[2 * 9 * 6];
  39242. sp_point_521 p[2];
  39243. #endif
  39244. sp_point_521* q = NULL;
  39245. int err = MP_OKAY;
  39246. #ifdef WOLFSSL_SP_SMALL_STACK
  39247. if (err == MP_OKAY) {
  39248. p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL,
  39249. DYNAMIC_TYPE_ECC);
  39250. if (p == NULL)
  39251. err = MEMORY_E;
  39252. }
  39253. if (err == MP_OKAY) {
  39254. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, NULL,
  39255. DYNAMIC_TYPE_ECC);
  39256. if (tmp == NULL) {
  39257. err = MEMORY_E;
  39258. }
  39259. }
  39260. #endif
  39261. if (err == MP_OKAY) {
  39262. q = p + 1;
  39263. sp_521_from_mp(p->x, 9, pX);
  39264. sp_521_from_mp(p->y, 9, pY);
  39265. sp_521_from_mp(p->z, 9, pZ);
  39266. sp_521_from_mp(q->x, 9, qX);
  39267. sp_521_from_mp(q->y, 9, qY);
  39268. sp_521_from_mp(q->z, 9, qZ);
  39269. p->infinity = sp_521_iszero_9(p->x) &
  39270. sp_521_iszero_9(p->y);
  39271. q->infinity = sp_521_iszero_9(q->x) &
  39272. sp_521_iszero_9(q->y);
  39273. sp_521_proj_point_add_9(p, p, q, tmp);
  39274. }
  39275. if (err == MP_OKAY) {
  39276. err = sp_521_to_mp(p->x, rX);
  39277. }
  39278. if (err == MP_OKAY) {
  39279. err = sp_521_to_mp(p->y, rY);
  39280. }
  39281. if (err == MP_OKAY) {
  39282. err = sp_521_to_mp(p->z, rZ);
  39283. }
  39284. #ifdef WOLFSSL_SP_SMALL_STACK
  39285. if (tmp != NULL)
  39286. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  39287. if (p != NULL)
  39288. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  39289. #endif
  39290. return err;
  39291. }
  39292. /* Double a projective EC point.
  39293. * (pX, pY, pZ) + (pX, pY, pZ) = (rX, rY, rZ)
  39294. *
  39295. * pX EC point's X ordinate.
  39296. * pY EC point's Y ordinate.
  39297. * pZ EC point's Z ordinate.
  39298. * rX Resultant EC point's X ordinate.
  39299. * rY Resultant EC point's Y ordinate.
  39300. * rZ Resultant EC point's Z ordinate.
  39301. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  39302. */
  39303. int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ,
  39304. mp_int* rX, mp_int* rY, mp_int* rZ)
  39305. {
  39306. #ifdef WOLFSSL_SP_SMALL_STACK
  39307. sp_digit* tmp = NULL;
  39308. sp_point_521* p = NULL;
  39309. #else
  39310. sp_digit tmp[2 * 9 * 2];
  39311. sp_point_521 p[1];
  39312. #endif
  39313. int err = MP_OKAY;
  39314. #ifdef WOLFSSL_SP_SMALL_STACK
  39315. if (err == MP_OKAY) {
  39316. p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL,
  39317. DYNAMIC_TYPE_ECC);
  39318. if (p == NULL)
  39319. err = MEMORY_E;
  39320. }
  39321. if (err == MP_OKAY) {
  39322. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 2, NULL,
  39323. DYNAMIC_TYPE_ECC);
  39324. if (tmp == NULL)
  39325. err = MEMORY_E;
  39326. }
  39327. #endif
  39328. if (err == MP_OKAY) {
  39329. sp_521_from_mp(p->x, 9, pX);
  39330. sp_521_from_mp(p->y, 9, pY);
  39331. sp_521_from_mp(p->z, 9, pZ);
  39332. p->infinity = sp_521_iszero_9(p->x) &
  39333. sp_521_iszero_9(p->y);
  39334. sp_521_proj_point_dbl_9(p, p, tmp);
  39335. }
  39336. if (err == MP_OKAY) {
  39337. err = sp_521_to_mp(p->x, rX);
  39338. }
  39339. if (err == MP_OKAY) {
  39340. err = sp_521_to_mp(p->y, rY);
  39341. }
  39342. if (err == MP_OKAY) {
  39343. err = sp_521_to_mp(p->z, rZ);
  39344. }
  39345. #ifdef WOLFSSL_SP_SMALL_STACK
  39346. if (tmp != NULL)
  39347. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  39348. if (p != NULL)
  39349. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  39350. #endif
  39351. return err;
  39352. }
  39353. /* Map a projective EC point to affine in place.
  39354. * pZ will be one.
  39355. *
  39356. * pX EC point's X ordinate.
  39357. * pY EC point's Y ordinate.
  39358. * pZ EC point's Z ordinate.
  39359. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  39360. */
  39361. int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ)
  39362. {
  39363. #ifdef WOLFSSL_SP_SMALL_STACK
  39364. sp_digit* tmp = NULL;
  39365. sp_point_521* p = NULL;
  39366. #else
  39367. sp_digit tmp[2 * 9 * 5];
  39368. sp_point_521 p[1];
  39369. #endif
  39370. int err = MP_OKAY;
  39371. #ifdef WOLFSSL_SP_SMALL_STACK
  39372. if (err == MP_OKAY) {
  39373. p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL,
  39374. DYNAMIC_TYPE_ECC);
  39375. if (p == NULL)
  39376. err = MEMORY_E;
  39377. }
  39378. if (err == MP_OKAY) {
  39379. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 5, NULL,
  39380. DYNAMIC_TYPE_ECC);
  39381. if (tmp == NULL)
  39382. err = MEMORY_E;
  39383. }
  39384. #endif
  39385. if (err == MP_OKAY) {
  39386. sp_521_from_mp(p->x, 9, pX);
  39387. sp_521_from_mp(p->y, 9, pY);
  39388. sp_521_from_mp(p->z, 9, pZ);
  39389. p->infinity = sp_521_iszero_9(p->x) &
  39390. sp_521_iszero_9(p->y);
  39391. sp_521_map_9(p, p, tmp);
  39392. }
  39393. if (err == MP_OKAY) {
  39394. err = sp_521_to_mp(p->x, pX);
  39395. }
  39396. if (err == MP_OKAY) {
  39397. err = sp_521_to_mp(p->y, pY);
  39398. }
  39399. if (err == MP_OKAY) {
  39400. err = sp_521_to_mp(p->z, pZ);
  39401. }
  39402. #ifdef WOLFSSL_SP_SMALL_STACK
  39403. if (tmp != NULL)
  39404. XFREE(tmp, NULL, DYNAMIC_TYPE_ECC);
  39405. if (p != NULL)
  39406. XFREE(p, NULL, DYNAMIC_TYPE_ECC);
  39407. #endif
  39408. return err;
  39409. }
  39410. #endif /* WOLFSSL_PUBLIC_ECC_ADD_DBL */
  39411. #ifdef HAVE_COMP_KEY
  39412. /* Square root power for the P521 curve. */
  39413. static const uint64_t p521_sqrt_power[9] = {
  39414. 0x0000000000000000,0x0000000000000000,0x0000000000000000,
  39415. 0x0000000000000000,0x0000000000000000,0x0000000000000000,0x0000000000000000,0x0000000000000000,
  39416. 0x0000000000000080
  39417. };
  39418. /* Find the square root of a number mod the prime of the curve.
  39419. *
  39420. * y The number to operate on and the result.
  39421. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  39422. */
  39423. static int sp_521_mont_sqrt_9(sp_digit* y)
  39424. {
  39425. #ifdef WOLFSSL_SP_SMALL_STACK
  39426. sp_digit* t = NULL;
  39427. #else
  39428. sp_digit t[2 * 9];
  39429. #endif
  39430. int err = MP_OKAY;
  39431. #ifdef WOLFSSL_SP_SMALL_STACK
  39432. t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9, NULL, DYNAMIC_TYPE_ECC);
  39433. if (t == NULL)
  39434. err = MEMORY_E;
  39435. #endif
  39436. if (err == MP_OKAY) {
  39437. {
  39438. int i;
  39439. XMEMCPY(t, y, sizeof(sp_digit) * 9);
  39440. for (i=518; i>=0; i--) {
  39441. sp_521_mont_sqr_9(t, t, p521_mod, p521_mp_mod);
  39442. if (p521_sqrt_power[i / 64] & ((sp_digit)1 << (i % 64)))
  39443. sp_521_mont_mul_9(t, t, y, p521_mod, p521_mp_mod);
  39444. }
  39445. XMEMCPY(y, t, sizeof(sp_digit) * 9);
  39446. }
  39447. }
  39448. #ifdef WOLFSSL_SP_SMALL_STACK
  39449. if (t != NULL)
  39450. XFREE(t, NULL, DYNAMIC_TYPE_ECC);
  39451. #endif
  39452. return err;
  39453. }
  39454. /* Uncompress the point given the X ordinate.
  39455. *
  39456. * xm X ordinate.
  39457. * odd Whether the Y ordinate is odd.
  39458. * ym Calculated Y ordinate.
  39459. * returns MEMORY_E if dynamic memory allocation fails and MP_OKAY otherwise.
  39460. */
  39461. int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym)
  39462. {
  39463. #ifdef WOLFSSL_SP_SMALL_STACK
  39464. sp_digit* x = NULL;
  39465. #else
  39466. sp_digit x[4 * 9];
  39467. #endif
  39468. sp_digit* y = NULL;
  39469. int err = MP_OKAY;
  39470. #ifdef WOLFSSL_SP_SMALL_STACK
  39471. x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 9, NULL, DYNAMIC_TYPE_ECC);
  39472. if (x == NULL)
  39473. err = MEMORY_E;
  39474. #endif
  39475. if (err == MP_OKAY) {
  39476. y = x + 2 * 9;
  39477. sp_521_from_mp(x, 9, xm);
  39478. err = sp_521_mod_mul_norm_9(x, x, p521_mod);
  39479. }
  39480. if (err == MP_OKAY) {
  39481. /* y = x^3 */
  39482. {
  39483. sp_521_mont_sqr_9(y, x, p521_mod, p521_mp_mod);
  39484. sp_521_mont_mul_9(y, y, x, p521_mod, p521_mp_mod);
  39485. }
  39486. /* y = x^3 - 3x */
  39487. sp_521_mont_sub_9(y, y, x, p521_mod);
  39488. sp_521_mont_sub_9(y, y, x, p521_mod);
  39489. sp_521_mont_sub_9(y, y, x, p521_mod);
  39490. /* y = x^3 - 3x + b */
  39491. err = sp_521_mod_mul_norm_9(x, p521_b, p521_mod);
  39492. }
  39493. if (err == MP_OKAY) {
  39494. sp_521_mont_add_9(y, y, x, p521_mod);
  39495. /* y = sqrt(x^3 - 3x + b) */
  39496. err = sp_521_mont_sqrt_9(y);
  39497. }
  39498. if (err == MP_OKAY) {
  39499. XMEMSET(y + 9, 0, 9U * sizeof(sp_digit));
  39500. sp_521_mont_reduce_9(y, p521_mod, p521_mp_mod);
  39501. if ((((word32)y[0] ^ (word32)odd) & 1U) != 0U) {
  39502. sp_521_mont_sub_9(y, p521_mod, y, p521_mod);
  39503. }
  39504. err = sp_521_to_mp(y, ym);
  39505. }
  39506. #ifdef WOLFSSL_SP_SMALL_STACK
  39507. if (x != NULL)
  39508. XFREE(x, NULL, DYNAMIC_TYPE_ECC);
  39509. #endif
  39510. return err;
  39511. }
  39512. #endif
  39513. #endif /* WOLFSSL_SP_521 */
  39514. #ifdef WOLFCRYPT_HAVE_SAKKE
  39515. #ifdef WOLFSSL_SP_1024
  39516. /* Point structure to use. */
  39517. typedef struct sp_point_1024 {
  39518. /* X ordinate of point. */
  39519. sp_digit x[2 * 18];
  39520. /* Y ordinate of point. */
  39521. sp_digit y[2 * 18];
  39522. /* Z ordinate of point. */
  39523. sp_digit z[2 * 18];
  39524. /* Indicates point is at infinity. */
  39525. int infinity;
  39526. } sp_point_1024;
  39527. #ifndef WOLFSSL_SP_SMALL
  39528. /* Multiply a and b into r. (r = a * b)
  39529. *
  39530. * r A single precision integer.
  39531. * a A single precision integer.
  39532. * b A single precision integer.
  39533. */
  39534. SP_NOINLINE static void sp_1024_mul_9(sp_digit* r, const sp_digit* a,
  39535. const sp_digit* b)
  39536. {
  39537. sp_int128 t0;
  39538. sp_int128 t1;
  39539. sp_digit t[9];
  39540. t0 = ((sp_int128)a[ 0]) * b[ 0];
  39541. t1 = ((sp_int128)a[ 0]) * b[ 1]
  39542. + ((sp_int128)a[ 1]) * b[ 0];
  39543. t[ 0] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39544. t0 = ((sp_int128)a[ 0]) * b[ 2]
  39545. + ((sp_int128)a[ 1]) * b[ 1]
  39546. + ((sp_int128)a[ 2]) * b[ 0];
  39547. t[ 1] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39548. t1 = ((sp_int128)a[ 0]) * b[ 3]
  39549. + ((sp_int128)a[ 1]) * b[ 2]
  39550. + ((sp_int128)a[ 2]) * b[ 1]
  39551. + ((sp_int128)a[ 3]) * b[ 0];
  39552. t[ 2] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39553. t0 = ((sp_int128)a[ 0]) * b[ 4]
  39554. + ((sp_int128)a[ 1]) * b[ 3]
  39555. + ((sp_int128)a[ 2]) * b[ 2]
  39556. + ((sp_int128)a[ 3]) * b[ 1]
  39557. + ((sp_int128)a[ 4]) * b[ 0];
  39558. t[ 3] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39559. t1 = ((sp_int128)a[ 0]) * b[ 5]
  39560. + ((sp_int128)a[ 1]) * b[ 4]
  39561. + ((sp_int128)a[ 2]) * b[ 3]
  39562. + ((sp_int128)a[ 3]) * b[ 2]
  39563. + ((sp_int128)a[ 4]) * b[ 1]
  39564. + ((sp_int128)a[ 5]) * b[ 0];
  39565. t[ 4] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39566. t0 = ((sp_int128)a[ 0]) * b[ 6]
  39567. + ((sp_int128)a[ 1]) * b[ 5]
  39568. + ((sp_int128)a[ 2]) * b[ 4]
  39569. + ((sp_int128)a[ 3]) * b[ 3]
  39570. + ((sp_int128)a[ 4]) * b[ 2]
  39571. + ((sp_int128)a[ 5]) * b[ 1]
  39572. + ((sp_int128)a[ 6]) * b[ 0];
  39573. t[ 5] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39574. t1 = ((sp_int128)a[ 0]) * b[ 7]
  39575. + ((sp_int128)a[ 1]) * b[ 6]
  39576. + ((sp_int128)a[ 2]) * b[ 5]
  39577. + ((sp_int128)a[ 3]) * b[ 4]
  39578. + ((sp_int128)a[ 4]) * b[ 3]
  39579. + ((sp_int128)a[ 5]) * b[ 2]
  39580. + ((sp_int128)a[ 6]) * b[ 1]
  39581. + ((sp_int128)a[ 7]) * b[ 0];
  39582. t[ 6] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39583. t0 = ((sp_int128)a[ 0]) * b[ 8]
  39584. + ((sp_int128)a[ 1]) * b[ 7]
  39585. + ((sp_int128)a[ 2]) * b[ 6]
  39586. + ((sp_int128)a[ 3]) * b[ 5]
  39587. + ((sp_int128)a[ 4]) * b[ 4]
  39588. + ((sp_int128)a[ 5]) * b[ 3]
  39589. + ((sp_int128)a[ 6]) * b[ 2]
  39590. + ((sp_int128)a[ 7]) * b[ 1]
  39591. + ((sp_int128)a[ 8]) * b[ 0];
  39592. t[ 7] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39593. t1 = ((sp_int128)a[ 1]) * b[ 8]
  39594. + ((sp_int128)a[ 2]) * b[ 7]
  39595. + ((sp_int128)a[ 3]) * b[ 6]
  39596. + ((sp_int128)a[ 4]) * b[ 5]
  39597. + ((sp_int128)a[ 5]) * b[ 4]
  39598. + ((sp_int128)a[ 6]) * b[ 3]
  39599. + ((sp_int128)a[ 7]) * b[ 2]
  39600. + ((sp_int128)a[ 8]) * b[ 1];
  39601. t[ 8] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39602. t0 = ((sp_int128)a[ 2]) * b[ 8]
  39603. + ((sp_int128)a[ 3]) * b[ 7]
  39604. + ((sp_int128)a[ 4]) * b[ 6]
  39605. + ((sp_int128)a[ 5]) * b[ 5]
  39606. + ((sp_int128)a[ 6]) * b[ 4]
  39607. + ((sp_int128)a[ 7]) * b[ 3]
  39608. + ((sp_int128)a[ 8]) * b[ 2];
  39609. r[ 9] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39610. t1 = ((sp_int128)a[ 3]) * b[ 8]
  39611. + ((sp_int128)a[ 4]) * b[ 7]
  39612. + ((sp_int128)a[ 5]) * b[ 6]
  39613. + ((sp_int128)a[ 6]) * b[ 5]
  39614. + ((sp_int128)a[ 7]) * b[ 4]
  39615. + ((sp_int128)a[ 8]) * b[ 3];
  39616. r[10] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39617. t0 = ((sp_int128)a[ 4]) * b[ 8]
  39618. + ((sp_int128)a[ 5]) * b[ 7]
  39619. + ((sp_int128)a[ 6]) * b[ 6]
  39620. + ((sp_int128)a[ 7]) * b[ 5]
  39621. + ((sp_int128)a[ 8]) * b[ 4];
  39622. r[11] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39623. t1 = ((sp_int128)a[ 5]) * b[ 8]
  39624. + ((sp_int128)a[ 6]) * b[ 7]
  39625. + ((sp_int128)a[ 7]) * b[ 6]
  39626. + ((sp_int128)a[ 8]) * b[ 5];
  39627. r[12] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39628. t0 = ((sp_int128)a[ 6]) * b[ 8]
  39629. + ((sp_int128)a[ 7]) * b[ 7]
  39630. + ((sp_int128)a[ 8]) * b[ 6];
  39631. r[13] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39632. t1 = ((sp_int128)a[ 7]) * b[ 8]
  39633. + ((sp_int128)a[ 8]) * b[ 7];
  39634. r[14] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39635. t0 = ((sp_int128)a[ 8]) * b[ 8];
  39636. r[15] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39637. r[16] = t0 & 0x1ffffffffffffffL;
  39638. r[17] = (sp_digit)(t0 >> 57);
  39639. XMEMCPY(r, t, sizeof(t));
  39640. }
  39641. /* Square a and put result in r. (r = a * a)
  39642. *
  39643. * r A single precision integer.
  39644. * a A single precision integer.
  39645. */
  39646. SP_NOINLINE static void sp_1024_sqr_9(sp_digit* r, const sp_digit* a)
  39647. {
  39648. sp_int128 t0;
  39649. sp_int128 t1;
  39650. sp_digit t[9];
  39651. t0 = ((sp_int128)a[ 0]) * a[ 0];
  39652. t1 = (((sp_int128)a[ 0]) * a[ 1]) * 2;
  39653. t[ 0] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39654. t0 = (((sp_int128)a[ 0]) * a[ 2]) * 2
  39655. + ((sp_int128)a[ 1]) * a[ 1];
  39656. t[ 1] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39657. t1 = (((sp_int128)a[ 0]) * a[ 3]
  39658. + ((sp_int128)a[ 1]) * a[ 2]) * 2;
  39659. t[ 2] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39660. t0 = (((sp_int128)a[ 0]) * a[ 4]
  39661. + ((sp_int128)a[ 1]) * a[ 3]) * 2
  39662. + ((sp_int128)a[ 2]) * a[ 2];
  39663. t[ 3] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39664. t1 = (((sp_int128)a[ 0]) * a[ 5]
  39665. + ((sp_int128)a[ 1]) * a[ 4]
  39666. + ((sp_int128)a[ 2]) * a[ 3]) * 2;
  39667. t[ 4] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39668. t0 = (((sp_int128)a[ 0]) * a[ 6]
  39669. + ((sp_int128)a[ 1]) * a[ 5]
  39670. + ((sp_int128)a[ 2]) * a[ 4]) * 2
  39671. + ((sp_int128)a[ 3]) * a[ 3];
  39672. t[ 5] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39673. t1 = (((sp_int128)a[ 0]) * a[ 7]
  39674. + ((sp_int128)a[ 1]) * a[ 6]
  39675. + ((sp_int128)a[ 2]) * a[ 5]
  39676. + ((sp_int128)a[ 3]) * a[ 4]) * 2;
  39677. t[ 6] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39678. t0 = (((sp_int128)a[ 0]) * a[ 8]
  39679. + ((sp_int128)a[ 1]) * a[ 7]
  39680. + ((sp_int128)a[ 2]) * a[ 6]
  39681. + ((sp_int128)a[ 3]) * a[ 5]) * 2
  39682. + ((sp_int128)a[ 4]) * a[ 4];
  39683. t[ 7] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39684. t1 = (((sp_int128)a[ 1]) * a[ 8]
  39685. + ((sp_int128)a[ 2]) * a[ 7]
  39686. + ((sp_int128)a[ 3]) * a[ 6]
  39687. + ((sp_int128)a[ 4]) * a[ 5]) * 2;
  39688. t[ 8] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39689. t0 = (((sp_int128)a[ 2]) * a[ 8]
  39690. + ((sp_int128)a[ 3]) * a[ 7]
  39691. + ((sp_int128)a[ 4]) * a[ 6]) * 2
  39692. + ((sp_int128)a[ 5]) * a[ 5];
  39693. r[ 9] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39694. t1 = (((sp_int128)a[ 3]) * a[ 8]
  39695. + ((sp_int128)a[ 4]) * a[ 7]
  39696. + ((sp_int128)a[ 5]) * a[ 6]) * 2;
  39697. r[10] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39698. t0 = (((sp_int128)a[ 4]) * a[ 8]
  39699. + ((sp_int128)a[ 5]) * a[ 7]) * 2
  39700. + ((sp_int128)a[ 6]) * a[ 6];
  39701. r[11] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39702. t1 = (((sp_int128)a[ 5]) * a[ 8]
  39703. + ((sp_int128)a[ 6]) * a[ 7]) * 2;
  39704. r[12] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39705. t0 = (((sp_int128)a[ 6]) * a[ 8]) * 2
  39706. + ((sp_int128)a[ 7]) * a[ 7];
  39707. r[13] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39708. t1 = (((sp_int128)a[ 7]) * a[ 8]) * 2;
  39709. r[14] = t0 & 0x1ffffffffffffffL; t1 += t0 >> 57;
  39710. t0 = ((sp_int128)a[ 8]) * a[ 8];
  39711. r[15] = t1 & 0x1ffffffffffffffL; t0 += t1 >> 57;
  39712. r[16] = t0 & 0x1ffffffffffffffL;
  39713. r[17] = (sp_digit)(t0 >> 57);
  39714. XMEMCPY(r, t, sizeof(t));
  39715. }
  39716. /* Add b to a into r. (r = a + b)
  39717. *
  39718. * r A single precision integer.
  39719. * a A single precision integer.
  39720. * b A single precision integer.
  39721. */
  39722. SP_NOINLINE static int sp_1024_add_9(sp_digit* r, const sp_digit* a,
  39723. const sp_digit* b)
  39724. {
  39725. r[ 0] = a[ 0] + b[ 0];
  39726. r[ 1] = a[ 1] + b[ 1];
  39727. r[ 2] = a[ 2] + b[ 2];
  39728. r[ 3] = a[ 3] + b[ 3];
  39729. r[ 4] = a[ 4] + b[ 4];
  39730. r[ 5] = a[ 5] + b[ 5];
  39731. r[ 6] = a[ 6] + b[ 6];
  39732. r[ 7] = a[ 7] + b[ 7];
  39733. r[ 8] = a[ 8] + b[ 8];
  39734. return 0;
  39735. }
  39736. /* Add b to a into r. (r = a + b)
  39737. *
  39738. * r A single precision integer.
  39739. * a A single precision integer.
  39740. * b A single precision integer.
  39741. */
  39742. SP_NOINLINE static int sp_1024_add_18(sp_digit* r, const sp_digit* a,
  39743. const sp_digit* b)
  39744. {
  39745. int i;
  39746. for (i = 0; i < 16; i += 8) {
  39747. r[i + 0] = a[i + 0] + b[i + 0];
  39748. r[i + 1] = a[i + 1] + b[i + 1];
  39749. r[i + 2] = a[i + 2] + b[i + 2];
  39750. r[i + 3] = a[i + 3] + b[i + 3];
  39751. r[i + 4] = a[i + 4] + b[i + 4];
  39752. r[i + 5] = a[i + 5] + b[i + 5];
  39753. r[i + 6] = a[i + 6] + b[i + 6];
  39754. r[i + 7] = a[i + 7] + b[i + 7];
  39755. }
  39756. r[16] = a[16] + b[16];
  39757. r[17] = a[17] + b[17];
  39758. return 0;
  39759. }
  39760. /* Sub b from a into r. (r = a - b)
  39761. *
  39762. * r A single precision integer.
  39763. * a A single precision integer.
  39764. * b A single precision integer.
  39765. */
  39766. SP_NOINLINE static int sp_1024_sub_18(sp_digit* r, const sp_digit* a,
  39767. const sp_digit* b)
  39768. {
  39769. int i;
  39770. for (i = 0; i < 16; i += 8) {
  39771. r[i + 0] = a[i + 0] - b[i + 0];
  39772. r[i + 1] = a[i + 1] - b[i + 1];
  39773. r[i + 2] = a[i + 2] - b[i + 2];
  39774. r[i + 3] = a[i + 3] - b[i + 3];
  39775. r[i + 4] = a[i + 4] - b[i + 4];
  39776. r[i + 5] = a[i + 5] - b[i + 5];
  39777. r[i + 6] = a[i + 6] - b[i + 6];
  39778. r[i + 7] = a[i + 7] - b[i + 7];
  39779. }
  39780. r[16] = a[16] - b[16];
  39781. r[17] = a[17] - b[17];
  39782. return 0;
  39783. }
  39784. /* Multiply a and b into r. (r = a * b)
  39785. *
  39786. * r A single precision integer.
  39787. * a A single precision integer.
  39788. * b A single precision integer.
  39789. */
  39790. SP_NOINLINE static void sp_1024_mul_18(sp_digit* r, const sp_digit* a,
  39791. const sp_digit* b)
  39792. {
  39793. sp_digit* z0 = r;
  39794. sp_digit z1[18];
  39795. sp_digit* a1 = z1;
  39796. sp_digit b1[9];
  39797. sp_digit* z2 = r + 18;
  39798. (void)sp_1024_add_9(a1, a, &a[9]);
  39799. (void)sp_1024_add_9(b1, b, &b[9]);
  39800. sp_1024_mul_9(z2, &a[9], &b[9]);
  39801. sp_1024_mul_9(z0, a, b);
  39802. sp_1024_mul_9(z1, a1, b1);
  39803. (void)sp_1024_sub_18(z1, z1, z2);
  39804. (void)sp_1024_sub_18(z1, z1, z0);
  39805. (void)sp_1024_add_18(r + 9, r + 9, z1);
  39806. }
  39807. /* Square a and put result in r. (r = a * a)
  39808. *
  39809. * r A single precision integer.
  39810. * a A single precision integer.
  39811. */
  39812. SP_NOINLINE static void sp_1024_sqr_18(sp_digit* r, const sp_digit* a)
  39813. {
  39814. sp_digit* z0 = r;
  39815. sp_digit z1[18];
  39816. sp_digit* a1 = z1;
  39817. sp_digit* z2 = r + 18;
  39818. (void)sp_1024_add_9(a1, a, &a[9]);
  39819. sp_1024_sqr_9(z2, &a[9]);
  39820. sp_1024_sqr_9(z0, a);
  39821. sp_1024_sqr_9(z1, a1);
  39822. (void)sp_1024_sub_18(z1, z1, z2);
  39823. (void)sp_1024_sub_18(z1, z1, z0);
  39824. (void)sp_1024_add_18(r + 9, r + 9, z1);
  39825. }
  39826. #else
  39827. /* Multiply a and b into r. (r = a * b)
  39828. *
  39829. * r A single precision integer.
  39830. * a A single precision integer.
  39831. * b A single precision integer.
  39832. */
  39833. SP_NOINLINE static void sp_1024_mul_18(sp_digit* r, const sp_digit* a,
  39834. const sp_digit* b)
  39835. {
  39836. int i;
  39837. int imax;
  39838. int k;
  39839. sp_uint128 c;
  39840. sp_uint128 lo;
  39841. c = ((sp_uint128)a[17]) * b[17];
  39842. r[35] = (sp_digit)(c >> 57);
  39843. c &= 0x1ffffffffffffffL;
  39844. for (k = 33; k >= 0; k--) {
  39845. if (k >= 18) {
  39846. i = k - 17;
  39847. imax = 17;
  39848. }
  39849. else {
  39850. i = 0;
  39851. imax = k;
  39852. }
  39853. lo = 0;
  39854. for (; i <= imax; i++) {
  39855. lo += ((sp_uint128)a[i]) * b[k - i];
  39856. }
  39857. c += lo >> 57;
  39858. r[k + 2] += (sp_digit)(c >> 57);
  39859. r[k + 1] = (sp_digit)(c & 0x1ffffffffffffffL);
  39860. c = lo & 0x1ffffffffffffffL;
  39861. }
  39862. r[0] = (sp_digit)c;
  39863. }
  39864. /* Square a and put result in r. (r = a * a)
  39865. *
  39866. * r A single precision integer.
  39867. * a A single precision integer.
  39868. */
  39869. SP_NOINLINE static void sp_1024_sqr_18(sp_digit* r, const sp_digit* a)
  39870. {
  39871. int i;
  39872. int imax;
  39873. int k;
  39874. sp_uint128 c;
  39875. sp_uint128 t;
  39876. c = ((sp_uint128)a[17]) * a[17];
  39877. r[35] = (sp_digit)(c >> 57);
  39878. c = (c & 0x1ffffffffffffffL) << 57;
  39879. for (k = 33; k >= 0; k--) {
  39880. i = (k + 1) / 2;
  39881. if ((k & 1) == 0) {
  39882. c += ((sp_uint128)a[i]) * a[i];
  39883. i++;
  39884. }
  39885. if (k < 17) {
  39886. imax = k;
  39887. }
  39888. else {
  39889. imax = 17;
  39890. }
  39891. t = 0;
  39892. for (; i <= imax; i++) {
  39893. t += ((sp_uint128)a[i]) * a[k - i];
  39894. }
  39895. c += t * 2;
  39896. r[k + 2] += (sp_digit) (c >> 114);
  39897. r[k + 1] = (sp_digit)((c >> 57) & 0x1ffffffffffffffL);
  39898. c = (c & 0x1ffffffffffffffL) << 57;
  39899. }
  39900. r[0] = (sp_digit)(c >> 57);
  39901. }
  39902. #endif /* !WOLFSSL_SP_SMALL */
  39903. /* The modulus (prime) of the curve P1024. */
  39904. static const sp_digit p1024_mod[18] = {
  39905. 0x06d807afea85febL,0x0ef88563d6743b3L,0x008e2615f6c2031L,0x1ead2e3e3ff9c7dL,
  39906. 0x1c3c09aa9f94d6aL,0x02954153e79e290L,0x07386dabfd2a0c6L,0x1a8a2558b9acad0L,
  39907. 0x0e26c6487326b4cL,0x0b693fa53335368L,0x06ce7fdf222864dL,0x01aa634b3961cf2L,
  39908. 0x07e2fc0f1b22873L,0x19f00d177a05559L,0x0d20986fa6b8d62L,0x0caf482d819c339L,
  39909. 0x1da65c61198dad0L,0x04cbd5d8f852b1fL
  39910. };
  39911. /* The Montgomery normalizer for modulus of the curve P1024. */
  39912. static const sp_digit p1024_norm_mod[18] = {
  39913. 0x1927f850157a015L,0x11077a9c298bc4cL,0x1f71d9ea093dfceL,0x0152d1c1c006382L,
  39914. 0x03c3f655606b295L,0x1d6abeac1861d6fL,0x18c7925402d5f39L,0x0575daa7465352fL,
  39915. 0x11d939b78cd94b3L,0x1496c05acccac97L,0x19318020ddd79b2L,0x1e559cb4c69e30dL,
  39916. 0x181d03f0e4dd78cL,0x060ff2e885faaa6L,0x12df6790594729dL,0x1350b7d27e63cc6L,
  39917. 0x0259a39ee67252fL,0x03342a2707ad4e0L
  39918. };
  39919. /* The Montgomery multiplier for modulus of the curve P1024. */
  39920. static sp_digit p1024_mp_mod = 0x10420077c8f2f3d;
  39921. #if defined(WOLFSSL_SP_SMALL) || defined(HAVE_ECC_CHECK_KEY)
  39922. /* The order of the curve P1024. */
  39923. static const sp_digit p1024_order[18] = {
  39924. 0x19b601ebfaa17fbL,0x0bbe2158f59d0ecL,0x082389857db080cL,0x17ab4b8f8ffe71fL,
  39925. 0x070f026aa7e535aL,0x10a55054f9e78a4L,0x01ce1b6aff4a831L,0x06a289562e6b2b4L,
  39926. 0x0389b1921cc9ad3L,0x0ada4fe94ccd4daL,0x11b39ff7c88a193L,0x186a98d2ce5873cL,
  39927. 0x09f8bf03c6c8a1cL,0x167c0345de81556L,0x0b48261be9ae358L,0x032bd20b60670ceL,
  39928. 0x1f69971846636b4L,0x0132f5763e14ac7L
  39929. };
  39930. #endif
  39931. /* The base point of curve P1024. */
  39932. static const sp_point_1024 p1024_base = {
  39933. /* X ordinate */
  39934. {
  39935. 0x00dc8abeae63895L,0x023624b3f04bcc4L,0x0e96d8fdcfb203bL,
  39936. 0x1900e51b0fdd22cL,0x1a66910dd5cfb4cL,0x106f3a53e0a8a6dL,
  39937. 0x1cb869c0b0ce5e9L,0x19666f90ca916e5L,0x09760af765dd5bcL,
  39938. 0x0c5ecf3a0367448L,0x17c8b36e77e955cL,0x172061613c2087aL,
  39939. 0x00f6ce2308ab10dL,0x1b7fbe5fdaf6db6L,0x1b1a71a62cbc812L,
  39940. 0x16a5456345fac15L,0x1ad0a7990053ed9L,0x029fe04f7199614L,
  39941. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39942. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39943. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39944. (sp_digit)0, (sp_digit)0, (sp_digit)0
  39945. },
  39946. /* Y ordinate */
  39947. {
  39948. 0x1573fd71bef16d7L,0x0dab83533ee6f3aL,0x156b56ed18dab6eL,
  39949. 0x0fd3973353017b5L,0x05a4d5f213515adL,0x0554c4a496cbcfeL,
  39950. 0x0bf82b1bc7a0059L,0x0d995ad2d6b6ecaL,0x170dae117ad547cL,
  39951. 0x0b67f8654f0195cL,0x06333e68502cb90L,0x0bcbe1bcabecd6bL,
  39952. 0x14654ec2b9e7f7fL,0x0f0a08bc7af534fL,0x0641a58f5de3608L,
  39953. 0x1426ba7d0402c05L,0x1f1f9f1f0533634L,0x0054124831fb004L,
  39954. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39955. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39956. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39957. (sp_digit)0, (sp_digit)0, (sp_digit)0
  39958. },
  39959. /* Z ordinate */
  39960. {
  39961. 0x000000000000001L,0x000000000000000L,0x000000000000000L,
  39962. 0x000000000000000L,0x000000000000000L,0x000000000000000L,
  39963. 0x000000000000000L,0x000000000000000L,0x000000000000000L,
  39964. 0x000000000000000L,0x000000000000000L,0x000000000000000L,
  39965. 0x000000000000000L,0x000000000000000L,0x000000000000000L,
  39966. 0x000000000000000L,0x000000000000000L,0x000000000000000L,
  39967. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39968. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39969. (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0, (sp_digit)0,
  39970. (sp_digit)0, (sp_digit)0, (sp_digit)0
  39971. },
  39972. /* infinity */
  39973. 0
  39974. };
  39975. /* Normalize the values in each word to 57 bits.
  39976. *
  39977. * a Array of sp_digit to normalize.
  39978. */
  39979. static void sp_1024_norm_18(sp_digit* a)
  39980. {
  39981. #ifdef WOLFSSL_SP_SMALL
  39982. int i;
  39983. for (i = 0; i < 17; i++) {
  39984. a[i+1] += a[i] >> 57;
  39985. a[i] &= 0x1ffffffffffffffL;
  39986. }
  39987. #else
  39988. int i;
  39989. for (i = 0; i < 16; i += 8) {
  39990. a[i+1] += a[i+0] >> 57; a[i+0] &= 0x1ffffffffffffffL;
  39991. a[i+2] += a[i+1] >> 57; a[i+1] &= 0x1ffffffffffffffL;
  39992. a[i+3] += a[i+2] >> 57; a[i+2] &= 0x1ffffffffffffffL;
  39993. a[i+4] += a[i+3] >> 57; a[i+3] &= 0x1ffffffffffffffL;
  39994. a[i+5] += a[i+4] >> 57; a[i+4] &= 0x1ffffffffffffffL;
  39995. a[i+6] += a[i+5] >> 57; a[i+5] &= 0x1ffffffffffffffL;
  39996. a[i+7] += a[i+6] >> 57; a[i+6] &= 0x1ffffffffffffffL;
  39997. a[i+8] += a[i+7] >> 57; a[i+7] &= 0x1ffffffffffffffL;
  39998. }
  39999. a[17] += a[16] >> 57; a[16] &= 0x1ffffffffffffffL;
  40000. #endif /* WOLFSSL_SP_SMALL */
  40001. }
  40002. /* Multiply a by scalar b into r. (r = a * b)
  40003. *
  40004. * r A single precision integer.
  40005. * a A single precision integer.
  40006. * b A scalar.
  40007. */
  40008. SP_NOINLINE static void sp_1024_mul_d_18(sp_digit* r, const sp_digit* a,
  40009. sp_digit b)
  40010. {
  40011. #ifdef WOLFSSL_SP_SMALL
  40012. sp_int128 tb = b;
  40013. sp_int128 t = 0;
  40014. int i;
  40015. for (i = 0; i < 18; i++) {
  40016. t += tb * a[i];
  40017. r[i] = (sp_digit)(t & 0x1ffffffffffffffL);
  40018. t >>= 57;
  40019. }
  40020. r[18] = (sp_digit)t;
  40021. #else
  40022. sp_int128 tb = b;
  40023. sp_int128 t = 0;
  40024. sp_digit t2;
  40025. sp_int128 p[4];
  40026. int i;
  40027. for (i = 0; i < 16; i += 4) {
  40028. p[0] = tb * a[i + 0];
  40029. p[1] = tb * a[i + 1];
  40030. p[2] = tb * a[i + 2];
  40031. p[3] = tb * a[i + 3];
  40032. t += p[0];
  40033. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40034. t >>= 57;
  40035. r[i + 0] = (sp_digit)t2;
  40036. t += p[1];
  40037. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40038. t >>= 57;
  40039. r[i + 1] = (sp_digit)t2;
  40040. t += p[2];
  40041. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40042. t >>= 57;
  40043. r[i + 2] = (sp_digit)t2;
  40044. t += p[3];
  40045. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40046. t >>= 57;
  40047. r[i + 3] = (sp_digit)t2;
  40048. }
  40049. t += tb * a[16];
  40050. r[16] = (sp_digit)(t & 0x1ffffffffffffffL);
  40051. t >>= 57;
  40052. t += tb * a[17];
  40053. r[17] = (sp_digit)(t & 0x1ffffffffffffffL);
  40054. t >>= 57;
  40055. r[18] = (sp_digit)(t & 0x1ffffffffffffffL);
  40056. #endif /* WOLFSSL_SP_SMALL */
  40057. }
  40058. /* Multiply a by scalar b into r. (r = a * b)
  40059. *
  40060. * r A single precision integer.
  40061. * a A single precision integer.
  40062. * b A scalar.
  40063. */
  40064. SP_NOINLINE static void sp_1024_mul_d_36(sp_digit* r, const sp_digit* a,
  40065. sp_digit b)
  40066. {
  40067. #ifdef WOLFSSL_SP_SMALL
  40068. sp_int128 tb = b;
  40069. sp_int128 t = 0;
  40070. int i;
  40071. for (i = 0; i < 36; i++) {
  40072. t += tb * a[i];
  40073. r[i] = (sp_digit)(t & 0x1ffffffffffffffL);
  40074. t >>= 57;
  40075. }
  40076. r[36] = (sp_digit)t;
  40077. #else
  40078. sp_int128 tb = b;
  40079. sp_int128 t = 0;
  40080. sp_digit t2;
  40081. sp_int128 p[4];
  40082. int i;
  40083. for (i = 0; i < 36; i += 4) {
  40084. p[0] = tb * a[i + 0];
  40085. p[1] = tb * a[i + 1];
  40086. p[2] = tb * a[i + 2];
  40087. p[3] = tb * a[i + 3];
  40088. t += p[0];
  40089. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40090. t >>= 57;
  40091. r[i + 0] = (sp_digit)t2;
  40092. t += p[1];
  40093. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40094. t >>= 57;
  40095. r[i + 1] = (sp_digit)t2;
  40096. t += p[2];
  40097. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40098. t >>= 57;
  40099. r[i + 2] = (sp_digit)t2;
  40100. t += p[3];
  40101. t2 = (sp_digit)(t & 0x1ffffffffffffffL);
  40102. t >>= 57;
  40103. r[i + 3] = (sp_digit)t2;
  40104. }
  40105. r[36] = (sp_digit)(t & 0x1ffffffffffffffL);
  40106. #endif /* WOLFSSL_SP_SMALL */
  40107. }
  40108. #ifdef WOLFSSL_SP_SMALL
  40109. /* Conditionally add a and b using the mask m.
  40110. * m is -1 to add and 0 when not.
  40111. *
  40112. * r A single precision number representing conditional add result.
  40113. * a A single precision number to add with.
  40114. * b A single precision number to add.
  40115. * m Mask value to apply.
  40116. */
  40117. static void sp_1024_cond_add_18(sp_digit* r, const sp_digit* a,
  40118. const sp_digit* b, const sp_digit m)
  40119. {
  40120. int i;
  40121. for (i = 0; i < 18; i++) {
  40122. r[i] = a[i] + (b[i] & m);
  40123. }
  40124. }
  40125. #endif /* WOLFSSL_SP_SMALL */
  40126. #ifndef WOLFSSL_SP_SMALL
  40127. /* Conditionally add a and b using the mask m.
  40128. * m is -1 to add and 0 when not.
  40129. *
  40130. * r A single precision number representing conditional add result.
  40131. * a A single precision number to add with.
  40132. * b A single precision number to add.
  40133. * m Mask value to apply.
  40134. */
  40135. static void sp_1024_cond_add_18(sp_digit* r, const sp_digit* a,
  40136. const sp_digit* b, const sp_digit m)
  40137. {
  40138. int i;
  40139. for (i = 0; i < 16; i += 8) {
  40140. r[i + 0] = a[i + 0] + (b[i + 0] & m);
  40141. r[i + 1] = a[i + 1] + (b[i + 1] & m);
  40142. r[i + 2] = a[i + 2] + (b[i + 2] & m);
  40143. r[i + 3] = a[i + 3] + (b[i + 3] & m);
  40144. r[i + 4] = a[i + 4] + (b[i + 4] & m);
  40145. r[i + 5] = a[i + 5] + (b[i + 5] & m);
  40146. r[i + 6] = a[i + 6] + (b[i + 6] & m);
  40147. r[i + 7] = a[i + 7] + (b[i + 7] & m);
  40148. }
  40149. r[16] = a[16] + (b[16] & m);
  40150. r[17] = a[17] + (b[17] & m);
  40151. }
  40152. #endif /* !WOLFSSL_SP_SMALL */
  40153. #ifdef WOLFSSL_SP_SMALL
  40154. /* Sub b from a into r. (r = a - b)
  40155. *
  40156. * r A single precision integer.
  40157. * a A single precision integer.
  40158. * b A single precision integer.
  40159. */
  40160. SP_NOINLINE static int sp_1024_sub_18(sp_digit* r, const sp_digit* a,
  40161. const sp_digit* b)
  40162. {
  40163. int i;
  40164. for (i = 0; i < 18; i++) {
  40165. r[i] = a[i] - b[i];
  40166. }
  40167. return 0;
  40168. }
  40169. #endif
  40170. #ifdef WOLFSSL_SP_SMALL
  40171. /* Add b to a into r. (r = a + b)
  40172. *
  40173. * r A single precision integer.
  40174. * a A single precision integer.
  40175. * b A single precision integer.
  40176. */
  40177. SP_NOINLINE static int sp_1024_add_18(sp_digit* r, const sp_digit* a,
  40178. const sp_digit* b)
  40179. {
  40180. int i;
  40181. for (i = 0; i < 18; i++) {
  40182. r[i] = a[i] + b[i];
  40183. }
  40184. return 0;
  40185. }
  40186. #endif /* WOLFSSL_SP_SMALL */
  40187. SP_NOINLINE static void sp_1024_rshift_18(sp_digit* r, const sp_digit* a,
  40188. byte n)
  40189. {
  40190. int i;
  40191. #ifdef WOLFSSL_SP_SMALL
  40192. for (i=0; i<17; i++) {
  40193. r[i] = ((a[i] >> n) | (a[i + 1] << (57 - n))) & 0x1ffffffffffffffL;
  40194. }
  40195. #else
  40196. for (i=0; i<16; i += 8) {
  40197. r[i+0] = (a[i+0] >> n) | ((a[i+1] << (57 - n)) & 0x1ffffffffffffffL);
  40198. r[i+1] = (a[i+1] >> n) | ((a[i+2] << (57 - n)) & 0x1ffffffffffffffL);
  40199. r[i+2] = (a[i+2] >> n) | ((a[i+3] << (57 - n)) & 0x1ffffffffffffffL);
  40200. r[i+3] = (a[i+3] >> n) | ((a[i+4] << (57 - n)) & 0x1ffffffffffffffL);
  40201. r[i+4] = (a[i+4] >> n) | ((a[i+5] << (57 - n)) & 0x1ffffffffffffffL);
  40202. r[i+5] = (a[i+5] >> n) | ((a[i+6] << (57 - n)) & 0x1ffffffffffffffL);
  40203. r[i+6] = (a[i+6] >> n) | ((a[i+7] << (57 - n)) & 0x1ffffffffffffffL);
  40204. r[i+7] = (a[i+7] >> n) | ((a[i+8] << (57 - n)) & 0x1ffffffffffffffL);
  40205. }
  40206. r[16] = (a[16] >> n) | ((a[17] << (57 - n)) & 0x1ffffffffffffffL);
  40207. #endif /* WOLFSSL_SP_SMALL */
  40208. r[17] = a[17] >> n;
  40209. }
  40210. static WC_INLINE sp_digit sp_1024_div_word_18(sp_digit d1, sp_digit d0,
  40211. sp_digit div)
  40212. {
  40213. #ifdef SP_USE_DIVTI3
  40214. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  40215. return d / div;
  40216. #elif defined(__x86_64__) || defined(__i386__)
  40217. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  40218. sp_uint64 lo = (sp_uint64)d;
  40219. sp_digit hi = (sp_digit)(d >> 64);
  40220. __asm__ __volatile__ (
  40221. "idiv %2"
  40222. : "+a" (lo)
  40223. : "d" (hi), "r" (div)
  40224. : "cc"
  40225. );
  40226. return (sp_digit)lo;
  40227. #elif !defined(__aarch64__) && !defined(SP_DIV_WORD_USE_DIV)
  40228. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  40229. sp_digit dv = (div >> 1) + 1;
  40230. sp_digit t1 = (sp_digit)(d >> 57);
  40231. sp_digit t0 = (sp_digit)(d & 0x1ffffffffffffffL);
  40232. sp_digit t2;
  40233. sp_digit sign;
  40234. sp_digit r;
  40235. int i;
  40236. sp_int128 m;
  40237. r = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  40238. t1 -= dv & (0 - r);
  40239. for (i = 55; i >= 1; i--) {
  40240. t1 += t1 + (((sp_uint64)t0 >> 56) & 1);
  40241. t0 <<= 1;
  40242. t2 = (sp_digit)(((sp_uint64)(dv - t1)) >> 63);
  40243. r += r + t2;
  40244. t1 -= dv & (0 - t2);
  40245. t1 += t2;
  40246. }
  40247. r += r + 1;
  40248. m = d - ((sp_int128)r * div);
  40249. r += (sp_digit)(m >> 57);
  40250. m = d - ((sp_int128)r * div);
  40251. r += (sp_digit)(m >> 114) - (sp_digit)(d >> 114);
  40252. m = d - ((sp_int128)r * div);
  40253. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  40254. m *= sign;
  40255. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  40256. r += sign * t2;
  40257. m = d - ((sp_int128)r * div);
  40258. sign = (sp_digit)(0 - ((sp_uint64)m >> 63)) * 2 + 1;
  40259. m *= sign;
  40260. t2 = (sp_digit)(((sp_uint64)(div - m)) >> 63);
  40261. r += sign * t2;
  40262. return r;
  40263. #else
  40264. sp_int128 d = ((sp_int128)d1 << 57) + d0;
  40265. sp_digit r = 0;
  40266. sp_digit t;
  40267. sp_digit dv = (div >> 26) + 1;
  40268. t = (sp_digit)(d >> 52);
  40269. t = (t / dv) << 26;
  40270. r += t;
  40271. d -= (sp_int128)t * div;
  40272. t = (sp_digit)(d >> 21);
  40273. t = t / (dv << 5);
  40274. r += t;
  40275. d -= (sp_int128)t * div;
  40276. t = (sp_digit)d;
  40277. t = t / div;
  40278. r += t;
  40279. d -= (sp_int128)t * div;
  40280. return r;
  40281. #endif
  40282. }
  40283. static WC_INLINE sp_digit sp_1024_word_div_word_18(sp_digit d, sp_digit div)
  40284. {
  40285. #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) || \
  40286. defined(SP_DIV_WORD_USE_DIV)
  40287. return d / div;
  40288. #else
  40289. return (sp_digit)((sp_uint64)(div - d) >> 63);
  40290. #endif
  40291. }
  40292. /* Divide d in a and put remainder into r (m*d + r = a)
  40293. * m is not calculated as it is not needed at this time.
  40294. *
  40295. * Full implementation.
  40296. *
  40297. * a Number to be divided.
  40298. * d Number to divide with.
  40299. * m Multiplier result.
  40300. * r Remainder from the division.
  40301. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  40302. */
  40303. static int sp_1024_div_18(const sp_digit* a, const sp_digit* d,
  40304. const sp_digit* m, sp_digit* r)
  40305. {
  40306. int i;
  40307. #ifndef WOLFSSL_SP_DIV_64
  40308. #endif
  40309. sp_digit dv;
  40310. sp_digit r1;
  40311. #ifdef WOLFSSL_SP_SMALL_STACK
  40312. sp_digit* t1 = NULL;
  40313. #else
  40314. sp_digit t1[4 * 18 + 3];
  40315. #endif
  40316. sp_digit* t2 = NULL;
  40317. sp_digit* sd = NULL;
  40318. int err = MP_OKAY;
  40319. (void)m;
  40320. #ifdef WOLFSSL_SP_SMALL_STACK
  40321. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 18 + 3), NULL,
  40322. DYNAMIC_TYPE_TMP_BUFFER);
  40323. if (t1 == NULL)
  40324. err = MEMORY_E;
  40325. #endif
  40326. (void)m;
  40327. if (err == MP_OKAY) {
  40328. t2 = t1 + 36 + 1;
  40329. sd = t2 + 18 + 1;
  40330. sp_1024_mul_d_18(sd, d, (sp_digit)1 << 2);
  40331. sp_1024_mul_d_36(t1, a, (sp_digit)1 << 2);
  40332. dv = sd[17];
  40333. t1[18 + 18] += t1[18 + 18 - 1] >> 57;
  40334. t1[18 + 18 - 1] &= 0x1ffffffffffffffL;
  40335. for (i=18; i>=0; i--) {
  40336. r1 = sp_1024_div_word_18(t1[18 + i], t1[18 + i - 1], dv);
  40337. sp_1024_mul_d_18(t2, sd, r1);
  40338. (void)sp_1024_sub_18(&t1[i], &t1[i], t2);
  40339. sp_1024_norm_18(&t1[i]);
  40340. t1[18 + i] -= t2[18];
  40341. t1[18 + i] += t1[18 + i - 1] >> 57;
  40342. t1[18 + i - 1] &= 0x1ffffffffffffffL;
  40343. r1 = sp_1024_div_word_18(-t1[18 + i], -t1[18 + i - 1], dv);
  40344. r1 -= t1[18 + i];
  40345. sp_1024_mul_d_18(t2, sd, r1);
  40346. (void)sp_1024_add_18(&t1[i], &t1[i], t2);
  40347. t1[18 + i] += t1[18 + i - 1] >> 57;
  40348. t1[18 + i - 1] &= 0x1ffffffffffffffL;
  40349. }
  40350. t1[18 - 1] += t1[18 - 2] >> 57;
  40351. t1[18 - 2] &= 0x1ffffffffffffffL;
  40352. r1 = sp_1024_word_div_word_18(t1[18 - 1], dv);
  40353. sp_1024_mul_d_18(t2, sd, r1);
  40354. sp_1024_sub_18(t1, t1, t2);
  40355. XMEMCPY(r, t1, sizeof(*r) * 36U);
  40356. for (i=0; i<17; i++) {
  40357. r[i+1] += r[i] >> 57;
  40358. r[i] &= 0x1ffffffffffffffL;
  40359. }
  40360. sp_1024_cond_add_18(r, r, sd, r[17] >> 63);
  40361. sp_1024_norm_18(r);
  40362. sp_1024_rshift_18(r, r, 2);
  40363. }
  40364. #ifdef WOLFSSL_SP_SMALL_STACK
  40365. if (t1 != NULL)
  40366. XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  40367. #endif
  40368. return err;
  40369. }
  40370. /* Reduce a modulo m into r. (r = a mod m)
  40371. *
  40372. * r A single precision number that is the reduced result.
  40373. * a A single precision number that is to be reduced.
  40374. * m A single precision number that is the modulus to reduce with.
  40375. * returns MEMORY_E when unable to allocate memory and MP_OKAY otherwise.
  40376. */
  40377. static int sp_1024_mod_18(sp_digit* r, const sp_digit* a, const sp_digit* m)
  40378. {
  40379. return sp_1024_div_18(a, m, NULL, r);
  40380. }
  40381. /* Multiply a number by Montgomery normalizer mod modulus (prime).
  40382. *
  40383. * r The resulting Montgomery form number.
  40384. * a The number to convert.
  40385. * m The modulus (prime).
  40386. * returns MEMORY_E when memory allocation fails and MP_OKAY otherwise.
  40387. */
  40388. static int sp_1024_mod_mul_norm_18(sp_digit* r, const sp_digit* a,
  40389. const sp_digit* m)
  40390. {
  40391. sp_1024_mul_18(r, a, p1024_norm_mod);
  40392. return sp_1024_mod_18(r, r, m);
  40393. }
  40394. #ifdef WOLFCRYPT_HAVE_SAKKE
  40395. /* Create a new point.
  40396. *
  40397. * heap [in] Buffer to allocate dynamic memory from.
  40398. * sp [in] Data for point - only if not allocating.
  40399. * p [out] New point.
  40400. * returns MEMORY_E when dynamic memory allocation fails and 0 otherwise.
  40401. */
  40402. static int sp_1024_point_new_ex_18(void* heap, sp_point_1024* sp,
  40403. sp_point_1024** p)
  40404. {
  40405. int ret = MP_OKAY;
  40406. (void)heap;
  40407. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  40408. defined(WOLFSSL_SP_SMALL_STACK)
  40409. (void)sp;
  40410. *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC);
  40411. #else
  40412. *p = sp;
  40413. #endif
  40414. if (*p == NULL) {
  40415. ret = MEMORY_E;
  40416. }
  40417. return ret;
  40418. }
  40419. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  40420. defined(WOLFSSL_SP_SMALL_STACK)
  40421. /* Allocate memory for point and return error. */
  40422. #define sp_1024_point_new_18(heap, sp, p) sp_1024_point_new_ex_18((heap), NULL, &(p))
  40423. #else
  40424. /* Set pointer to data and return no error. */
  40425. #define sp_1024_point_new_18(heap, sp, p) sp_1024_point_new_ex_18((heap), &(sp), &(p))
  40426. #endif
  40427. #endif /* WOLFCRYPT_HAVE_SAKKE */
  40428. #ifdef WOLFCRYPT_HAVE_SAKKE
  40429. /* Free the point.
  40430. *
  40431. * p [in,out] Point to free.
  40432. * clear [in] Indicates whether to zeroize point.
  40433. * heap [in] Buffer from which dynamic memory was allocate from.
  40434. */
  40435. static void sp_1024_point_free_18(sp_point_1024* p, int clear, void* heap)
  40436. {
  40437. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  40438. defined(WOLFSSL_SP_SMALL_STACK)
  40439. /* If valid pointer then clear point data if requested and free data. */
  40440. if (p != NULL) {
  40441. if (clear != 0) {
  40442. XMEMSET(p, 0, sizeof(*p));
  40443. }
  40444. XFREE(p, heap, DYNAMIC_TYPE_ECC);
  40445. }
  40446. #else
  40447. /* Clear point data if requested. */
  40448. if ((p != NULL) && (clear != 0)) {
  40449. XMEMSET(p, 0, sizeof(*p));
  40450. }
  40451. #endif
  40452. (void)heap;
  40453. }
  40454. #endif /* WOLFCRYPT_HAVE_SAKKE */
  40455. /* Convert an mp_int to an array of sp_digit.
  40456. *
  40457. * r A single precision integer.
  40458. * size Maximum number of bytes to convert
  40459. * a A multi-precision integer.
  40460. */
  40461. static void sp_1024_from_mp(sp_digit* r, int size, const mp_int* a)
  40462. {
  40463. #if DIGIT_BIT == 57
  40464. int i;
  40465. sp_digit j = (sp_digit)0 - (sp_digit)a->used;
  40466. int o = 0;
  40467. for (i = 0; i < size; i++) {
  40468. sp_digit mask = (sp_digit)0 - (j >> 56);
  40469. r[i] = a->dp[o] & mask;
  40470. j++;
  40471. o += (int)(j >> 56);
  40472. }
  40473. #elif DIGIT_BIT > 57
  40474. unsigned int i;
  40475. int j = 0;
  40476. word32 s = 0;
  40477. r[0] = 0;
  40478. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  40479. r[j] |= ((sp_digit)a->dp[i] << s);
  40480. r[j] &= 0x1ffffffffffffffL;
  40481. s = 57U - s;
  40482. if (j + 1 >= size) {
  40483. break;
  40484. }
  40485. /* lint allow cast of mismatch word32 and mp_digit */
  40486. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  40487. while ((s + 57U) <= (word32)DIGIT_BIT) {
  40488. s += 57U;
  40489. r[j] &= 0x1ffffffffffffffL;
  40490. if (j + 1 >= size) {
  40491. break;
  40492. }
  40493. if (s < (word32)DIGIT_BIT) {
  40494. /* lint allow cast of mismatch word32 and mp_digit */
  40495. r[++j] = (sp_digit)(a->dp[i] >> s); /*lint !e9033*/
  40496. }
  40497. else {
  40498. r[++j] = (sp_digit)0;
  40499. }
  40500. }
  40501. s = (word32)DIGIT_BIT - s;
  40502. }
  40503. for (j++; j < size; j++) {
  40504. r[j] = 0;
  40505. }
  40506. #else
  40507. unsigned int i;
  40508. int j = 0;
  40509. int s = 0;
  40510. r[0] = 0;
  40511. for (i = 0; i < (unsigned int)a->used && j < size; i++) {
  40512. r[j] |= ((sp_digit)a->dp[i]) << s;
  40513. if (s + DIGIT_BIT >= 57) {
  40514. r[j] &= 0x1ffffffffffffffL;
  40515. if (j + 1 >= size) {
  40516. break;
  40517. }
  40518. s = 57 - s;
  40519. if (s == DIGIT_BIT) {
  40520. r[++j] = 0;
  40521. s = 0;
  40522. }
  40523. else {
  40524. r[++j] = a->dp[i] >> s;
  40525. s = DIGIT_BIT - s;
  40526. }
  40527. }
  40528. else {
  40529. s += DIGIT_BIT;
  40530. }
  40531. }
  40532. for (j++; j < size; j++) {
  40533. r[j] = 0;
  40534. }
  40535. #endif
  40536. }
  40537. /* Convert a point of type ecc_point to type sp_point_1024.
  40538. *
  40539. * p Point of type sp_point_1024 (result).
  40540. * pm Point of type ecc_point.
  40541. */
  40542. static void sp_1024_point_from_ecc_point_18(sp_point_1024* p,
  40543. const ecc_point* pm)
  40544. {
  40545. XMEMSET(p->x, 0, sizeof(p->x));
  40546. XMEMSET(p->y, 0, sizeof(p->y));
  40547. XMEMSET(p->z, 0, sizeof(p->z));
  40548. sp_1024_from_mp(p->x, 18, pm->x);
  40549. sp_1024_from_mp(p->y, 18, pm->y);
  40550. sp_1024_from_mp(p->z, 18, pm->z);
  40551. p->infinity = 0;
  40552. }
  40553. /* Convert an array of sp_digit to an mp_int.
  40554. *
  40555. * a A single precision integer.
  40556. * r A multi-precision integer.
  40557. */
  40558. static int sp_1024_to_mp(const sp_digit* a, mp_int* r)
  40559. {
  40560. int err;
  40561. err = mp_grow(r, (1024 + DIGIT_BIT - 1) / DIGIT_BIT);
  40562. if (err == MP_OKAY) { /*lint !e774 case where err is always MP_OKAY*/
  40563. #if DIGIT_BIT == 57
  40564. XMEMCPY(r->dp, a, sizeof(sp_digit) * 18);
  40565. r->used = 18;
  40566. mp_clamp(r);
  40567. #elif DIGIT_BIT < 57
  40568. int i;
  40569. int j = 0;
  40570. int s = 0;
  40571. r->dp[0] = 0;
  40572. for (i = 0; i < 18; i++) {
  40573. r->dp[j] |= (mp_digit)(a[i] << s);
  40574. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  40575. s = DIGIT_BIT - s;
  40576. r->dp[++j] = (mp_digit)(a[i] >> s);
  40577. while (s + DIGIT_BIT <= 57) {
  40578. s += DIGIT_BIT;
  40579. r->dp[j++] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  40580. if (s == SP_WORD_SIZE) {
  40581. r->dp[j] = 0;
  40582. }
  40583. else {
  40584. r->dp[j] = (mp_digit)(a[i] >> s);
  40585. }
  40586. }
  40587. s = 57 - s;
  40588. }
  40589. r->used = (1024 + DIGIT_BIT - 1) / DIGIT_BIT;
  40590. mp_clamp(r);
  40591. #else
  40592. int i;
  40593. int j = 0;
  40594. int s = 0;
  40595. r->dp[0] = 0;
  40596. for (i = 0; i < 18; i++) {
  40597. r->dp[j] |= ((mp_digit)a[i]) << s;
  40598. if (s + 57 >= DIGIT_BIT) {
  40599. #if DIGIT_BIT != 32 && DIGIT_BIT != 64
  40600. r->dp[j] &= ((sp_digit)1 << DIGIT_BIT) - 1;
  40601. #endif
  40602. s = DIGIT_BIT - s;
  40603. r->dp[++j] = a[i] >> s;
  40604. s = 57 - s;
  40605. }
  40606. else {
  40607. s += 57;
  40608. }
  40609. }
  40610. r->used = (1024 + DIGIT_BIT - 1) / DIGIT_BIT;
  40611. mp_clamp(r);
  40612. #endif
  40613. }
  40614. return err;
  40615. }
  40616. /* Convert a point of type sp_point_1024 to type ecc_point.
  40617. *
  40618. * p Point of type sp_point_1024.
  40619. * pm Point of type ecc_point (result).
  40620. * returns MEMORY_E when allocation of memory in ecc_point fails otherwise
  40621. * MP_OKAY.
  40622. */
  40623. static int sp_1024_point_to_ecc_point_18(const sp_point_1024* p, ecc_point* pm)
  40624. {
  40625. int err;
  40626. err = sp_1024_to_mp(p->x, pm->x);
  40627. if (err == MP_OKAY) {
  40628. err = sp_1024_to_mp(p->y, pm->y);
  40629. }
  40630. if (err == MP_OKAY) {
  40631. err = sp_1024_to_mp(p->z, pm->z);
  40632. }
  40633. return err;
  40634. }
  40635. /* Compare a with b in constant time.
  40636. *
  40637. * a A single precision integer.
  40638. * b A single precision integer.
  40639. * return -ve, 0 or +ve if a is less than, equal to or greater than b
  40640. * respectively.
  40641. */
  40642. static sp_digit sp_1024_cmp_18(const sp_digit* a, const sp_digit* b)
  40643. {
  40644. sp_digit r = 0;
  40645. #ifdef WOLFSSL_SP_SMALL
  40646. int i;
  40647. for (i=17; i>=0; i--) {
  40648. r |= (a[i] - b[i]) & ~(((sp_digit)0 - r) >> 56);
  40649. }
  40650. #else
  40651. int i;
  40652. r |= (a[17] - b[17]) & (0 - (sp_digit)1);
  40653. r |= (a[16] - b[16]) & ~(((sp_digit)0 - r) >> 56);
  40654. for (i = 8; i >= 0; i -= 8) {
  40655. r |= (a[i + 7] - b[i + 7]) & ~(((sp_digit)0 - r) >> 56);
  40656. r |= (a[i + 6] - b[i + 6]) & ~(((sp_digit)0 - r) >> 56);
  40657. r |= (a[i + 5] - b[i + 5]) & ~(((sp_digit)0 - r) >> 56);
  40658. r |= (a[i + 4] - b[i + 4]) & ~(((sp_digit)0 - r) >> 56);
  40659. r |= (a[i + 3] - b[i + 3]) & ~(((sp_digit)0 - r) >> 56);
  40660. r |= (a[i + 2] - b[i + 2]) & ~(((sp_digit)0 - r) >> 56);
  40661. r |= (a[i + 1] - b[i + 1]) & ~(((sp_digit)0 - r) >> 56);
  40662. r |= (a[i + 0] - b[i + 0]) & ~(((sp_digit)0 - r) >> 56);
  40663. }
  40664. #endif /* WOLFSSL_SP_SMALL */
  40665. return r;
  40666. }
  40667. /* Conditionally subtract b from a using the mask m.
  40668. * m is -1 to subtract and 0 when not.
  40669. *
  40670. * r A single precision number representing condition subtract result.
  40671. * a A single precision number to subtract from.
  40672. * b A single precision number to subtract.
  40673. * m Mask value to apply.
  40674. */
  40675. static void sp_1024_cond_sub_18(sp_digit* r, const sp_digit* a,
  40676. const sp_digit* b, const sp_digit m)
  40677. {
  40678. #ifdef WOLFSSL_SP_SMALL
  40679. int i;
  40680. for (i = 0; i < 18; i++) {
  40681. r[i] = a[i] - (b[i] & m);
  40682. }
  40683. #else
  40684. int i;
  40685. for (i = 0; i < 16; i += 8) {
  40686. r[i + 0] = a[i + 0] - (b[i + 0] & m);
  40687. r[i + 1] = a[i + 1] - (b[i + 1] & m);
  40688. r[i + 2] = a[i + 2] - (b[i + 2] & m);
  40689. r[i + 3] = a[i + 3] - (b[i + 3] & m);
  40690. r[i + 4] = a[i + 4] - (b[i + 4] & m);
  40691. r[i + 5] = a[i + 5] - (b[i + 5] & m);
  40692. r[i + 6] = a[i + 6] - (b[i + 6] & m);
  40693. r[i + 7] = a[i + 7] - (b[i + 7] & m);
  40694. }
  40695. r[16] = a[16] - (b[16] & m);
  40696. r[17] = a[17] - (b[17] & m);
  40697. #endif /* WOLFSSL_SP_SMALL */
  40698. }
  40699. /* Mul a by scalar b and add into r. (r += a * b)
  40700. *
  40701. * r A single precision integer.
  40702. * a A single precision integer.
  40703. * b A scalar.
  40704. */
  40705. SP_NOINLINE static void sp_1024_mul_add_18(sp_digit* r, const sp_digit* a,
  40706. const sp_digit b)
  40707. {
  40708. #ifdef WOLFSSL_SP_SMALL
  40709. sp_int128 tb = b;
  40710. sp_int128 t[4];
  40711. int i;
  40712. t[0] = 0;
  40713. for (i = 0; i < 16; i += 4) {
  40714. t[0] += (tb * a[i+0]) + r[i+0];
  40715. t[1] = (tb * a[i+1]) + r[i+1];
  40716. t[2] = (tb * a[i+2]) + r[i+2];
  40717. t[3] = (tb * a[i+3]) + r[i+3];
  40718. r[i+0] = t[0] & 0x1ffffffffffffffL;
  40719. t[1] += t[0] >> 57;
  40720. r[i+1] = t[1] & 0x1ffffffffffffffL;
  40721. t[2] += t[1] >> 57;
  40722. r[i+2] = t[2] & 0x1ffffffffffffffL;
  40723. t[3] += t[2] >> 57;
  40724. r[i+3] = t[3] & 0x1ffffffffffffffL;
  40725. t[0] = t[3] >> 57;
  40726. }
  40727. t[0] += (tb * a[16]) + r[16];
  40728. t[1] = (tb * a[17]) + r[17];
  40729. r[16] = t[0] & 0x1ffffffffffffffL;
  40730. t[1] += t[0] >> 57;
  40731. r[17] = t[1] & 0x1ffffffffffffffL;
  40732. r[18] += (sp_digit)(t[1] >> 57);
  40733. #else
  40734. sp_int128 tb = b;
  40735. sp_int128 t[8];
  40736. int i;
  40737. t[0] = tb * a[0]; r[0] += (sp_digit)(t[0] & 0x1ffffffffffffffL);
  40738. for (i = 0; i < 16; i += 8) {
  40739. t[1] = tb * a[i+1];
  40740. r[i+1] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  40741. t[2] = tb * a[i+2];
  40742. r[i+2] += (sp_digit)((t[1] >> 57) + (t[2] & 0x1ffffffffffffffL));
  40743. t[3] = tb * a[i+3];
  40744. r[i+3] += (sp_digit)((t[2] >> 57) + (t[3] & 0x1ffffffffffffffL));
  40745. t[4] = tb * a[i+4];
  40746. r[i+4] += (sp_digit)((t[3] >> 57) + (t[4] & 0x1ffffffffffffffL));
  40747. t[5] = tb * a[i+5];
  40748. r[i+5] += (sp_digit)((t[4] >> 57) + (t[5] & 0x1ffffffffffffffL));
  40749. t[6] = tb * a[i+6];
  40750. r[i+6] += (sp_digit)((t[5] >> 57) + (t[6] & 0x1ffffffffffffffL));
  40751. t[7] = tb * a[i+7];
  40752. r[i+7] += (sp_digit)((t[6] >> 57) + (t[7] & 0x1ffffffffffffffL));
  40753. t[0] = tb * a[i+8];
  40754. r[i+8] += (sp_digit)((t[7] >> 57) + (t[0] & 0x1ffffffffffffffL));
  40755. }
  40756. t[1] = tb * a[17];
  40757. r[17] += (sp_digit)((t[0] >> 57) + (t[1] & 0x1ffffffffffffffL));
  40758. r[18] += (sp_digit)(t[1] >> 57);
  40759. #endif /* WOLFSSL_SP_SMALL */
  40760. }
  40761. /* Shift the result in the high 1024 bits down to the bottom.
  40762. *
  40763. * r A single precision number.
  40764. * a A single precision number.
  40765. */
  40766. static void sp_1024_mont_shift_18(sp_digit* r, const sp_digit* a)
  40767. {
  40768. #ifdef WOLFSSL_SP_SMALL
  40769. int i;
  40770. sp_uint64 n;
  40771. n = a[17] >> 55;
  40772. for (i = 0; i < 17; i++) {
  40773. n += (sp_uint64)a[18 + i] << 2;
  40774. r[i] = n & 0x1ffffffffffffffL;
  40775. n >>= 57;
  40776. }
  40777. n += (sp_uint64)a[35] << 2;
  40778. r[17] = n;
  40779. #else
  40780. sp_uint64 n;
  40781. int i;
  40782. n = (sp_uint64)a[17];
  40783. n = n >> 55U;
  40784. for (i = 0; i < 16; i += 8) {
  40785. n += (sp_uint64)a[i+18] << 2U; r[i+0] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40786. n += (sp_uint64)a[i+19] << 2U; r[i+1] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40787. n += (sp_uint64)a[i+20] << 2U; r[i+2] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40788. n += (sp_uint64)a[i+21] << 2U; r[i+3] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40789. n += (sp_uint64)a[i+22] << 2U; r[i+4] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40790. n += (sp_uint64)a[i+23] << 2U; r[i+5] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40791. n += (sp_uint64)a[i+24] << 2U; r[i+6] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40792. n += (sp_uint64)a[i+25] << 2U; r[i+7] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40793. }
  40794. n += (sp_uint64)a[34] << 2U; r[16] = n & 0x1ffffffffffffffUL; n >>= 57U;
  40795. n += (sp_uint64)a[35] << 2U; r[17] = n;
  40796. #endif /* WOLFSSL_SP_SMALL */
  40797. XMEMSET(&r[18], 0, sizeof(*r) * 18U);
  40798. }
  40799. /* Reduce the number back to 1024 bits using Montgomery reduction.
  40800. *
  40801. * a A single precision number to reduce in place.
  40802. * m The single precision number representing the modulus.
  40803. * mp The digit representing the negative inverse of m mod 2^n.
  40804. */
  40805. static void sp_1024_mont_reduce_18(sp_digit* a, const sp_digit* m, sp_digit mp)
  40806. {
  40807. int i;
  40808. sp_digit mu;
  40809. sp_digit over;
  40810. sp_1024_norm_18(a + 18);
  40811. if (mp != 1) {
  40812. for (i=0; i<17; i++) {
  40813. mu = (a[i] * mp) & 0x1ffffffffffffffL;
  40814. sp_1024_mul_add_18(a+i, m, mu);
  40815. a[i+1] += a[i] >> 57;
  40816. }
  40817. mu = (a[i] * mp) & 0x7fffffffffffffL;
  40818. sp_1024_mul_add_18(a+i, m, mu);
  40819. a[i+1] += a[i] >> 57;
  40820. a[i] &= 0x1ffffffffffffffL;
  40821. }
  40822. else {
  40823. for (i=0; i<17; i++) {
  40824. mu = a[i] & 0x1ffffffffffffffL;
  40825. sp_1024_mul_add_18(a+i, m, mu);
  40826. a[i+1] += a[i] >> 57;
  40827. }
  40828. mu = a[i] & 0x7fffffffffffffL;
  40829. sp_1024_mul_add_18(a+i, m, mu);
  40830. a[i+1] += a[i] >> 57;
  40831. a[i] &= 0x1ffffffffffffffL;
  40832. }
  40833. sp_1024_mont_shift_18(a, a);
  40834. over = a[17] - m[17];
  40835. sp_1024_cond_sub_18(a, a, m, ~((over - 1) >> 63));
  40836. sp_1024_norm_18(a);
  40837. }
  40838. /* Multiply two Montgomery form numbers mod the modulus (prime).
  40839. * (r = a * b mod m)
  40840. *
  40841. * r Result of multiplication.
  40842. * a First number to multiply in Montgomery form.
  40843. * b Second number to multiply in Montgomery form.
  40844. * m Modulus (prime).
  40845. * mp Montgomery multiplier.
  40846. */
  40847. SP_NOINLINE static void sp_1024_mont_mul_18(sp_digit* r, const sp_digit* a,
  40848. const sp_digit* b, const sp_digit* m, sp_digit mp)
  40849. {
  40850. sp_1024_mul_18(r, a, b);
  40851. sp_1024_mont_reduce_18(r, m, mp);
  40852. }
  40853. /* Square the Montgomery form number. (r = a * a mod m)
  40854. *
  40855. * r Result of squaring.
  40856. * a Number to square in Montgomery form.
  40857. * m Modulus (prime).
  40858. * mp Montgomery multiplier.
  40859. */
  40860. SP_NOINLINE static void sp_1024_mont_sqr_18(sp_digit* r, const sp_digit* a,
  40861. const sp_digit* m, sp_digit mp)
  40862. {
  40863. sp_1024_sqr_18(r, a);
  40864. sp_1024_mont_reduce_18(r, m, mp);
  40865. }
  40866. /* Mod-2 for the P1024 curve. */
  40867. static const uint8_t p1024_mod_minus_2[] = {
  40868. 6,0x06, 7,0x0f, 7,0x0b, 6,0x0c, 7,0x1e, 9,0x09, 7,0x0c, 7,0x1f,
  40869. 6,0x16, 6,0x06, 7,0x0e, 8,0x10, 6,0x03, 8,0x11, 6,0x0d, 7,0x14,
  40870. 9,0x12, 6,0x0f, 7,0x04, 9,0x0d, 6,0x00, 7,0x13, 6,0x01, 6,0x07,
  40871. 8,0x0d, 8,0x00, 6,0x06, 9,0x17, 6,0x14, 6,0x15, 6,0x11, 6,0x0b,
  40872. 9,0x0c, 6,0x1e, 13,0x14, 7,0x0e, 6,0x1d, 12,0x0a, 6,0x0b, 8,0x07,
  40873. 6,0x18, 6,0x0f, 6,0x10, 8,0x1c, 7,0x16, 7,0x02, 6,0x01, 6,0x13,
  40874. 10,0x15, 7,0x06, 8,0x14, 6,0x0c, 6,0x19, 7,0x10, 6,0x19, 6,0x19,
  40875. 9,0x16, 7,0x19, 6,0x1f, 6,0x17, 6,0x12, 8,0x02, 6,0x01, 6,0x04,
  40876. 6,0x15, 7,0x16, 6,0x04, 6,0x1f, 6,0x09, 7,0x06, 7,0x13, 7,0x09,
  40877. 6,0x0d, 10,0x18, 6,0x06, 6,0x11, 6,0x04, 6,0x01, 6,0x13, 8,0x06,
  40878. 6,0x0d, 8,0x13, 7,0x08, 6,0x08, 6,0x05, 7,0x0c, 7,0x0e, 7,0x15,
  40879. 6,0x05, 7,0x14, 10,0x19, 6,0x10, 6,0x16, 6,0x15, 7,0x1f, 6,0x14,
  40880. 6,0x0a, 10,0x11, 6,0x01, 7,0x05, 7,0x08, 8,0x0a, 7,0x1e, 7,0x1c,
  40881. 6,0x1c, 7,0x09, 10,0x18, 7,0x1c, 10,0x06, 6,0x0a, 6,0x07, 6,0x19,
  40882. 7,0x06, 6,0x0d, 7,0x0f, 7,0x0b, 7,0x05, 6,0x11, 6,0x1c, 7,0x1f,
  40883. 6,0x1e, 7,0x18, 6,0x1e, 6,0x00, 6,0x03, 6,0x02, 7,0x10, 6,0x0b,
  40884. 6,0x1b, 7,0x10, 6,0x00, 8,0x11, 7,0x1b, 6,0x18, 6,0x01, 7,0x0c,
  40885. 7,0x1d, 7,0x13, 6,0x08, 7,0x1b, 8,0x13, 7,0x16, 13,0x1d, 7,0x1f,
  40886. 6,0x0a, 6,0x01, 7,0x1f, 6,0x14, 1,0x01
  40887. };
  40888. /* Invert the number, in Montgomery form, modulo the modulus (prime) of the
  40889. * P1024 curve. (r = 1 / a mod m)
  40890. *
  40891. * r Inverse result.
  40892. * a Number to invert.
  40893. * td Temporary data.
  40894. */
  40895. static void sp_1024_mont_inv_18(sp_digit* r, const sp_digit* a,
  40896. sp_digit* td)
  40897. {
  40898. sp_digit* t = &td[32 * 2 * 18];
  40899. int i;
  40900. int j;
  40901. sp_digit* table[32];
  40902. for (i = 0; i < 32; i++) {
  40903. table[i] = &td[2 * 18 * i];
  40904. }
  40905. XMEMCPY(table[0], a, sizeof(sp_digit) * 18);
  40906. for (i = 1; i < 6; i++) {
  40907. sp_1024_mont_sqr_18(table[0], table[0], p1024_mod, p1024_mp_mod);
  40908. }
  40909. for (i = 1; i < 32; i++) {
  40910. sp_1024_mont_mul_18(table[i], table[i-1], a, p1024_mod, p1024_mp_mod);
  40911. }
  40912. XMEMCPY(t, table[p1024_mod_minus_2[1]], sizeof(sp_digit) * 18);
  40913. for (i = 2; i < (int)sizeof(p1024_mod_minus_2) - 2; i += 2) {
  40914. for (j = 0; j < p1024_mod_minus_2[i]; j++) {
  40915. sp_1024_mont_sqr_18(t, t, p1024_mod, p1024_mp_mod);
  40916. }
  40917. sp_1024_mont_mul_18(t, t, table[p1024_mod_minus_2[i+1]], p1024_mod,
  40918. p1024_mp_mod);
  40919. }
  40920. sp_1024_mont_sqr_18(t, t, p1024_mod, p1024_mp_mod);
  40921. sp_1024_mont_mul_18(r, t, a, p1024_mod, p1024_mp_mod);
  40922. }
  40923. /* Map the Montgomery form projective coordinate point to an affine point.
  40924. *
  40925. * r Resulting affine coordinate point.
  40926. * p Montgomery form projective coordinate point.
  40927. * t Temporary ordinate data.
  40928. */
  40929. static void sp_1024_map_18(sp_point_1024* r, const sp_point_1024* p,
  40930. sp_digit* t)
  40931. {
  40932. sp_digit* t1 = t;
  40933. sp_digit* t2 = t + 2*18;
  40934. sp_int64 n;
  40935. sp_1024_mont_inv_18(t1, p->z, t + 2*18);
  40936. sp_1024_mont_sqr_18(t2, t1, p1024_mod, p1024_mp_mod);
  40937. sp_1024_mont_mul_18(t1, t2, t1, p1024_mod, p1024_mp_mod);
  40938. /* x /= z^2 */
  40939. sp_1024_mont_mul_18(r->x, p->x, t2, p1024_mod, p1024_mp_mod);
  40940. XMEMSET(r->x + 18, 0, sizeof(sp_digit) * 18U);
  40941. sp_1024_mont_reduce_18(r->x, p1024_mod, p1024_mp_mod);
  40942. /* Reduce x to less than modulus */
  40943. n = sp_1024_cmp_18(r->x, p1024_mod);
  40944. sp_1024_cond_sub_18(r->x, r->x, p1024_mod, ~(n >> 56));
  40945. sp_1024_norm_18(r->x);
  40946. /* y /= z^3 */
  40947. sp_1024_mont_mul_18(r->y, p->y, t1, p1024_mod, p1024_mp_mod);
  40948. XMEMSET(r->y + 18, 0, sizeof(sp_digit) * 18U);
  40949. sp_1024_mont_reduce_18(r->y, p1024_mod, p1024_mp_mod);
  40950. /* Reduce y to less than modulus */
  40951. n = sp_1024_cmp_18(r->y, p1024_mod);
  40952. sp_1024_cond_sub_18(r->y, r->y, p1024_mod, ~(n >> 56));
  40953. sp_1024_norm_18(r->y);
  40954. XMEMSET(r->z, 0, sizeof(r->z) / 2);
  40955. r->z[0] = 1;
  40956. }
  40957. /* Add two Montgomery form numbers (r = a + b % m).
  40958. *
  40959. * r Result of addition.
  40960. * a First number to add in Montgomery form.
  40961. * b Second number to add in Montgomery form.
  40962. * m Modulus (prime).
  40963. */
  40964. static void sp_1024_mont_add_18(sp_digit* r, const sp_digit* a, const sp_digit* b,
  40965. const sp_digit* m)
  40966. {
  40967. sp_digit over;
  40968. (void)sp_1024_add_18(r, a, b);
  40969. sp_1024_norm_18(r);
  40970. over = r[17] - m[17];
  40971. sp_1024_cond_sub_18(r, r, m, ~((over - 1) >> 63));
  40972. sp_1024_norm_18(r);
  40973. }
  40974. /* Double a Montgomery form number (r = a + a % m).
  40975. *
  40976. * r Result of doubling.
  40977. * a Number to double in Montgomery form.
  40978. * m Modulus (prime).
  40979. */
  40980. static void sp_1024_mont_dbl_18(sp_digit* r, const sp_digit* a, const sp_digit* m)
  40981. {
  40982. sp_digit over;
  40983. (void)sp_1024_add_18(r, a, a);
  40984. sp_1024_norm_18(r);
  40985. over = r[17] - m[17];
  40986. sp_1024_cond_sub_18(r, r, m, ~((over - 1) >> 63));
  40987. sp_1024_norm_18(r);
  40988. }
  40989. /* Triple a Montgomery form number (r = a + a + a % m).
  40990. *
  40991. * r Result of Tripling.
  40992. * a Number to triple in Montgomery form.
  40993. * m Modulus (prime).
  40994. */
  40995. static void sp_1024_mont_tpl_18(sp_digit* r, const sp_digit* a, const sp_digit* m)
  40996. {
  40997. sp_digit over;
  40998. (void)sp_1024_add_18(r, a, a);
  40999. sp_1024_norm_18(r);
  41000. over = r[17] - m[17];
  41001. sp_1024_cond_sub_18(r, r, m, ~((over - 1) >> 63));
  41002. sp_1024_norm_18(r);
  41003. (void)sp_1024_add_18(r, r, a);
  41004. sp_1024_norm_18(r);
  41005. over = r[17] - m[17];
  41006. sp_1024_cond_sub_18(r, r, m, ~((over - 1) >> 63));
  41007. sp_1024_norm_18(r);
  41008. }
  41009. /* Subtract two Montgomery form numbers (r = a - b % m).
  41010. *
  41011. * r Result of subtration.
  41012. * a Number to subtract from in Montgomery form.
  41013. * b Number to subtract with in Montgomery form.
  41014. * m Modulus (prime).
  41015. */
  41016. static void sp_1024_mont_sub_18(sp_digit* r, const sp_digit* a, const sp_digit* b,
  41017. const sp_digit* m)
  41018. {
  41019. (void)sp_1024_sub_18(r, a, b);
  41020. sp_1024_norm_18(r);
  41021. sp_1024_cond_add_18(r, r, m, r[17] >> 55);
  41022. sp_1024_norm_18(r);
  41023. }
  41024. /* Shift number left one bit.
  41025. * Bottom bit is lost.
  41026. *
  41027. * r Result of shift.
  41028. * a Number to shift.
  41029. */
  41030. SP_NOINLINE static void sp_1024_rshift1_18(sp_digit* r, const sp_digit* a)
  41031. {
  41032. #ifdef WOLFSSL_SP_SMALL
  41033. int i;
  41034. for (i=0; i<17; i++) {
  41035. r[i] = (a[i] >> 1) + ((a[i + 1] << 56) & 0x1ffffffffffffffL);
  41036. }
  41037. #else
  41038. r[0] = (a[0] >> 1) + ((a[1] << 56) & 0x1ffffffffffffffL);
  41039. r[1] = (a[1] >> 1) + ((a[2] << 56) & 0x1ffffffffffffffL);
  41040. r[2] = (a[2] >> 1) + ((a[3] << 56) & 0x1ffffffffffffffL);
  41041. r[3] = (a[3] >> 1) + ((a[4] << 56) & 0x1ffffffffffffffL);
  41042. r[4] = (a[4] >> 1) + ((a[5] << 56) & 0x1ffffffffffffffL);
  41043. r[5] = (a[5] >> 1) + ((a[6] << 56) & 0x1ffffffffffffffL);
  41044. r[6] = (a[6] >> 1) + ((a[7] << 56) & 0x1ffffffffffffffL);
  41045. r[7] = (a[7] >> 1) + ((a[8] << 56) & 0x1ffffffffffffffL);
  41046. r[8] = (a[8] >> 1) + ((a[9] << 56) & 0x1ffffffffffffffL);
  41047. r[9] = (a[9] >> 1) + ((a[10] << 56) & 0x1ffffffffffffffL);
  41048. r[10] = (a[10] >> 1) + ((a[11] << 56) & 0x1ffffffffffffffL);
  41049. r[11] = (a[11] >> 1) + ((a[12] << 56) & 0x1ffffffffffffffL);
  41050. r[12] = (a[12] >> 1) + ((a[13] << 56) & 0x1ffffffffffffffL);
  41051. r[13] = (a[13] >> 1) + ((a[14] << 56) & 0x1ffffffffffffffL);
  41052. r[14] = (a[14] >> 1) + ((a[15] << 56) & 0x1ffffffffffffffL);
  41053. r[15] = (a[15] >> 1) + ((a[16] << 56) & 0x1ffffffffffffffL);
  41054. r[16] = (a[16] >> 1) + ((a[17] << 56) & 0x1ffffffffffffffL);
  41055. #endif
  41056. r[17] = a[17] >> 1;
  41057. }
  41058. /* Divide the number by 2 mod the modulus (prime). (r = a / 2 % m)
  41059. *
  41060. * r Result of division by 2.
  41061. * a Number to divide.
  41062. * m Modulus (prime).
  41063. */
  41064. static void sp_1024_mont_div2_18(sp_digit* r, const sp_digit* a,
  41065. const sp_digit* m)
  41066. {
  41067. sp_1024_cond_add_18(r, a, m, 0 - (a[0] & 1));
  41068. sp_1024_norm_18(r);
  41069. sp_1024_rshift1_18(r, r);
  41070. }
  41071. /* Double the Montgomery form projective point p.
  41072. *
  41073. * r Result of doubling point.
  41074. * p Point to double.
  41075. * t Temporary ordinate data.
  41076. */
  41077. static void sp_1024_proj_point_dbl_18(sp_point_1024* r, const sp_point_1024* p,
  41078. sp_digit* t)
  41079. {
  41080. sp_digit* t1 = t;
  41081. sp_digit* t2 = t + 2*18;
  41082. sp_digit* x;
  41083. sp_digit* y;
  41084. sp_digit* z;
  41085. x = r->x;
  41086. y = r->y;
  41087. z = r->z;
  41088. /* Put infinity into result. */
  41089. if (r != p) {
  41090. r->infinity = p->infinity;
  41091. }
  41092. /* T1 = Z * Z */
  41093. sp_1024_mont_sqr_18(t1, p->z, p1024_mod, p1024_mp_mod);
  41094. /* Z = Y * Z */
  41095. sp_1024_mont_mul_18(z, p->y, p->z, p1024_mod, p1024_mp_mod);
  41096. /* Z = 2Z */
  41097. sp_1024_mont_dbl_18(z, z, p1024_mod);
  41098. /* T2 = X - T1 */
  41099. sp_1024_mont_sub_18(t2, p->x, t1, p1024_mod);
  41100. /* T1 = X + T1 */
  41101. sp_1024_mont_add_18(t1, p->x, t1, p1024_mod);
  41102. /* T2 = T1 * T2 */
  41103. sp_1024_mont_mul_18(t2, t1, t2, p1024_mod, p1024_mp_mod);
  41104. /* T1 = 3T2 */
  41105. sp_1024_mont_tpl_18(t1, t2, p1024_mod);
  41106. /* Y = 2Y */
  41107. sp_1024_mont_dbl_18(y, p->y, p1024_mod);
  41108. /* Y = Y * Y */
  41109. sp_1024_mont_sqr_18(y, y, p1024_mod, p1024_mp_mod);
  41110. /* T2 = Y * Y */
  41111. sp_1024_mont_sqr_18(t2, y, p1024_mod, p1024_mp_mod);
  41112. /* T2 = T2/2 */
  41113. sp_1024_mont_div2_18(t2, t2, p1024_mod);
  41114. /* Y = Y * X */
  41115. sp_1024_mont_mul_18(y, y, p->x, p1024_mod, p1024_mp_mod);
  41116. /* X = T1 * T1 */
  41117. sp_1024_mont_sqr_18(x, t1, p1024_mod, p1024_mp_mod);
  41118. /* X = X - Y */
  41119. sp_1024_mont_sub_18(x, x, y, p1024_mod);
  41120. /* X = X - Y */
  41121. sp_1024_mont_sub_18(x, x, y, p1024_mod);
  41122. /* Y = Y - X */
  41123. sp_1024_mont_sub_18(y, y, x, p1024_mod);
  41124. /* Y = Y * T1 */
  41125. sp_1024_mont_mul_18(y, y, t1, p1024_mod, p1024_mp_mod);
  41126. /* Y = Y - T2 */
  41127. sp_1024_mont_sub_18(y, y, t2, p1024_mod);
  41128. }
  41129. #ifdef WOLFSSL_SP_NONBLOCK
  41130. typedef struct sp_1024_proj_point_dbl_18_ctx {
  41131. int state;
  41132. sp_digit* t1;
  41133. sp_digit* t2;
  41134. sp_digit* x;
  41135. sp_digit* y;
  41136. sp_digit* z;
  41137. } sp_1024_proj_point_dbl_18_ctx;
  41138. /* Double the Montgomery form projective point p.
  41139. *
  41140. * r Result of doubling point.
  41141. * p Point to double.
  41142. * t Temporary ordinate data.
  41143. */
  41144. static int sp_1024_proj_point_dbl_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
  41145. const sp_point_1024* p, sp_digit* t)
  41146. {
  41147. int err = FP_WOULDBLOCK;
  41148. sp_1024_proj_point_dbl_18_ctx* ctx = (sp_1024_proj_point_dbl_18_ctx*)sp_ctx->data;
  41149. typedef char ctx_size_test[sizeof(sp_1024_proj_point_dbl_18_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  41150. (void)sizeof(ctx_size_test);
  41151. switch (ctx->state) {
  41152. case 0:
  41153. ctx->t1 = t;
  41154. ctx->t2 = t + 2*18;
  41155. ctx->x = r->x;
  41156. ctx->y = r->y;
  41157. ctx->z = r->z;
  41158. /* Put infinity into result. */
  41159. if (r != p) {
  41160. r->infinity = p->infinity;
  41161. }
  41162. ctx->state = 1;
  41163. break;
  41164. case 1:
  41165. /* T1 = Z * Z */
  41166. sp_1024_mont_sqr_18(ctx->t1, p->z, p1024_mod, p1024_mp_mod);
  41167. ctx->state = 2;
  41168. break;
  41169. case 2:
  41170. /* Z = Y * Z */
  41171. sp_1024_mont_mul_18(ctx->z, p->y, p->z, p1024_mod, p1024_mp_mod);
  41172. ctx->state = 3;
  41173. break;
  41174. case 3:
  41175. /* Z = 2Z */
  41176. sp_1024_mont_dbl_18(ctx->z, ctx->z, p1024_mod);
  41177. ctx->state = 4;
  41178. break;
  41179. case 4:
  41180. /* T2 = X - T1 */
  41181. sp_1024_mont_sub_18(ctx->t2, p->x, ctx->t1, p1024_mod);
  41182. ctx->state = 5;
  41183. break;
  41184. case 5:
  41185. /* T1 = X + T1 */
  41186. sp_1024_mont_add_18(ctx->t1, p->x, ctx->t1, p1024_mod);
  41187. ctx->state = 6;
  41188. break;
  41189. case 6:
  41190. /* T2 = T1 * T2 */
  41191. sp_1024_mont_mul_18(ctx->t2, ctx->t1, ctx->t2, p1024_mod, p1024_mp_mod);
  41192. ctx->state = 7;
  41193. break;
  41194. case 7:
  41195. /* T1 = 3T2 */
  41196. sp_1024_mont_tpl_18(ctx->t1, ctx->t2, p1024_mod);
  41197. ctx->state = 8;
  41198. break;
  41199. case 8:
  41200. /* Y = 2Y */
  41201. sp_1024_mont_dbl_18(ctx->y, p->y, p1024_mod);
  41202. ctx->state = 9;
  41203. break;
  41204. case 9:
  41205. /* Y = Y * Y */
  41206. sp_1024_mont_sqr_18(ctx->y, ctx->y, p1024_mod, p1024_mp_mod);
  41207. ctx->state = 10;
  41208. break;
  41209. case 10:
  41210. /* T2 = Y * Y */
  41211. sp_1024_mont_sqr_18(ctx->t2, ctx->y, p1024_mod, p1024_mp_mod);
  41212. ctx->state = 11;
  41213. break;
  41214. case 11:
  41215. /* T2 = T2/2 */
  41216. sp_1024_mont_div2_18(ctx->t2, ctx->t2, p1024_mod);
  41217. ctx->state = 12;
  41218. break;
  41219. case 12:
  41220. /* Y = Y * X */
  41221. sp_1024_mont_mul_18(ctx->y, ctx->y, p->x, p1024_mod, p1024_mp_mod);
  41222. ctx->state = 13;
  41223. break;
  41224. case 13:
  41225. /* X = T1 * T1 */
  41226. sp_1024_mont_sqr_18(ctx->x, ctx->t1, p1024_mod, p1024_mp_mod);
  41227. ctx->state = 14;
  41228. break;
  41229. case 14:
  41230. /* X = X - Y */
  41231. sp_1024_mont_sub_18(ctx->x, ctx->x, ctx->y, p1024_mod);
  41232. ctx->state = 15;
  41233. break;
  41234. case 15:
  41235. /* X = X - Y */
  41236. sp_1024_mont_sub_18(ctx->x, ctx->x, ctx->y, p1024_mod);
  41237. ctx->state = 16;
  41238. break;
  41239. case 16:
  41240. /* Y = Y - X */
  41241. sp_1024_mont_sub_18(ctx->y, ctx->y, ctx->x, p1024_mod);
  41242. ctx->state = 17;
  41243. break;
  41244. case 17:
  41245. /* Y = Y * T1 */
  41246. sp_1024_mont_mul_18(ctx->y, ctx->y, ctx->t1, p1024_mod, p1024_mp_mod);
  41247. ctx->state = 18;
  41248. break;
  41249. case 18:
  41250. /* Y = Y - T2 */
  41251. sp_1024_mont_sub_18(ctx->y, ctx->y, ctx->t2, p1024_mod);
  41252. ctx->state = 19;
  41253. /* fall-through */
  41254. case 19:
  41255. err = MP_OKAY;
  41256. break;
  41257. }
  41258. if (err == MP_OKAY && ctx->state != 19) {
  41259. err = FP_WOULDBLOCK;
  41260. }
  41261. return err;
  41262. }
  41263. #endif /* WOLFSSL_SP_NONBLOCK */
  41264. /* Compare two numbers to determine if they are equal.
  41265. * Constant time implementation.
  41266. *
  41267. * a First number to compare.
  41268. * b Second number to compare.
  41269. * returns 1 when equal and 0 otherwise.
  41270. */
  41271. static int sp_1024_cmp_equal_18(const sp_digit* a, const sp_digit* b)
  41272. {
  41273. return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) |
  41274. (a[3] ^ b[3]) | (a[4] ^ b[4]) | (a[5] ^ b[5]) |
  41275. (a[6] ^ b[6]) | (a[7] ^ b[7]) | (a[8] ^ b[8]) |
  41276. (a[9] ^ b[9]) | (a[10] ^ b[10]) | (a[11] ^ b[11]) |
  41277. (a[12] ^ b[12]) | (a[13] ^ b[13]) | (a[14] ^ b[14]) |
  41278. (a[15] ^ b[15]) | (a[16] ^ b[16]) | (a[17] ^ b[17])) == 0;
  41279. }
  41280. /* Returns 1 if the number of zero.
  41281. * Implementation is constant time.
  41282. *
  41283. * a Number to check.
  41284. * returns 1 if the number is zero and 0 otherwise.
  41285. */
  41286. static int sp_1024_iszero_18(const sp_digit* a)
  41287. {
  41288. return (a[0] | a[1] | a[2] | a[3] | a[4] | a[5] | a[6] | a[7] |
  41289. a[8] | a[9] | a[10] | a[11] | a[12] | a[13] | a[14] | a[15] |
  41290. a[16] | a[17]) == 0;
  41291. }
  41292. /* Add two Montgomery form projective points.
  41293. *
  41294. * r Result of addition.
  41295. * p First point to add.
  41296. * q Second point to add.
  41297. * t Temporary ordinate data.
  41298. */
  41299. static void sp_1024_proj_point_add_18(sp_point_1024* r,
  41300. const sp_point_1024* p, const sp_point_1024* q, sp_digit* t)
  41301. {
  41302. sp_digit* t6 = t;
  41303. sp_digit* t1 = t + 2*18;
  41304. sp_digit* t2 = t + 4*18;
  41305. sp_digit* t3 = t + 6*18;
  41306. sp_digit* t4 = t + 8*18;
  41307. sp_digit* t5 = t + 10*18;
  41308. /* U1 = X1*Z2^2 */
  41309. sp_1024_mont_sqr_18(t1, q->z, p1024_mod, p1024_mp_mod);
  41310. sp_1024_mont_mul_18(t3, t1, q->z, p1024_mod, p1024_mp_mod);
  41311. sp_1024_mont_mul_18(t1, t1, p->x, p1024_mod, p1024_mp_mod);
  41312. /* U2 = X2*Z1^2 */
  41313. sp_1024_mont_sqr_18(t2, p->z, p1024_mod, p1024_mp_mod);
  41314. sp_1024_mont_mul_18(t4, t2, p->z, p1024_mod, p1024_mp_mod);
  41315. sp_1024_mont_mul_18(t2, t2, q->x, p1024_mod, p1024_mp_mod);
  41316. /* S1 = Y1*Z2^3 */
  41317. sp_1024_mont_mul_18(t3, t3, p->y, p1024_mod, p1024_mp_mod);
  41318. /* S2 = Y2*Z1^3 */
  41319. sp_1024_mont_mul_18(t4, t4, q->y, p1024_mod, p1024_mp_mod);
  41320. /* Check double */
  41321. if ((~p->infinity) & (~q->infinity) &
  41322. sp_1024_cmp_equal_18(t2, t1) &
  41323. sp_1024_cmp_equal_18(t4, t3)) {
  41324. sp_1024_proj_point_dbl_18(r, p, t);
  41325. }
  41326. else {
  41327. sp_digit* x = t6;
  41328. sp_digit* y = t1;
  41329. sp_digit* z = t2;
  41330. /* H = U2 - U1 */
  41331. sp_1024_mont_sub_18(t2, t2, t1, p1024_mod);
  41332. /* R = S2 - S1 */
  41333. sp_1024_mont_sub_18(t4, t4, t3, p1024_mod);
  41334. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  41335. sp_1024_mont_sqr_18(t5, t2, p1024_mod, p1024_mp_mod);
  41336. sp_1024_mont_mul_18(y, t1, t5, p1024_mod, p1024_mp_mod);
  41337. sp_1024_mont_mul_18(t5, t5, t2, p1024_mod, p1024_mp_mod);
  41338. /* Z3 = H*Z1*Z2 */
  41339. sp_1024_mont_mul_18(z, p->z, t2, p1024_mod, p1024_mp_mod);
  41340. sp_1024_mont_mul_18(z, z, q->z, p1024_mod, p1024_mp_mod);
  41341. sp_1024_mont_sqr_18(x, t4, p1024_mod, p1024_mp_mod);
  41342. sp_1024_mont_sub_18(x, x, t5, p1024_mod);
  41343. sp_1024_mont_mul_18(t5, t5, t3, p1024_mod, p1024_mp_mod);
  41344. sp_1024_mont_dbl_18(t3, y, p1024_mod);
  41345. sp_1024_mont_sub_18(x, x, t3, p1024_mod);
  41346. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  41347. sp_1024_mont_sub_18(y, y, x, p1024_mod);
  41348. sp_1024_mont_mul_18(y, y, t4, p1024_mod, p1024_mp_mod);
  41349. sp_1024_mont_sub_18(y, y, t5, p1024_mod);
  41350. {
  41351. int i;
  41352. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  41353. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  41354. sp_digit maskt = ~(maskp | maskq);
  41355. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  41356. for (i = 0; i < 18; i++) {
  41357. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  41358. (x[i] & maskt);
  41359. }
  41360. for (i = 0; i < 18; i++) {
  41361. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  41362. (y[i] & maskt);
  41363. }
  41364. for (i = 0; i < 18; i++) {
  41365. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  41366. (z[i] & maskt);
  41367. }
  41368. r->z[0] |= inf;
  41369. r->infinity = (word32)inf;
  41370. }
  41371. }
  41372. }
  41373. #ifdef WOLFSSL_SP_NONBLOCK
  41374. typedef struct sp_1024_proj_point_add_18_ctx {
  41375. int state;
  41376. sp_1024_proj_point_dbl_18_ctx dbl_ctx;
  41377. const sp_point_1024* ap[2];
  41378. sp_point_1024* rp[2];
  41379. sp_digit* t1;
  41380. sp_digit* t2;
  41381. sp_digit* t3;
  41382. sp_digit* t4;
  41383. sp_digit* t5;
  41384. sp_digit* t6;
  41385. sp_digit* x;
  41386. sp_digit* y;
  41387. sp_digit* z;
  41388. } sp_1024_proj_point_add_18_ctx;
  41389. /* Add two Montgomery form projective points.
  41390. *
  41391. * r Result of addition.
  41392. * p First point to add.
  41393. * q Second point to add.
  41394. * t Temporary ordinate data.
  41395. */
  41396. static int sp_1024_proj_point_add_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
  41397. const sp_point_1024* p, const sp_point_1024* q, sp_digit* t)
  41398. {
  41399. int err = FP_WOULDBLOCK;
  41400. sp_1024_proj_point_add_18_ctx* ctx = (sp_1024_proj_point_add_18_ctx*)sp_ctx->data;
  41401. /* Ensure only the first point is the same as the result. */
  41402. if (q == r) {
  41403. const sp_point_1024* a = p;
  41404. p = q;
  41405. q = a;
  41406. }
  41407. typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_18_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  41408. (void)sizeof(ctx_size_test);
  41409. switch (ctx->state) {
  41410. case 0: /* INIT */
  41411. ctx->t6 = t;
  41412. ctx->t1 = t + 2*18;
  41413. ctx->t2 = t + 4*18;
  41414. ctx->t3 = t + 6*18;
  41415. ctx->t4 = t + 8*18;
  41416. ctx->t5 = t + 10*18;
  41417. ctx->x = ctx->t6;
  41418. ctx->y = ctx->t1;
  41419. ctx->z = ctx->t2;
  41420. ctx->state = 1;
  41421. break;
  41422. case 1:
  41423. /* U1 = X1*Z2^2 */
  41424. sp_1024_mont_sqr_18(ctx->t1, q->z, p1024_mod, p1024_mp_mod);
  41425. ctx->state = 2;
  41426. break;
  41427. case 2:
  41428. sp_1024_mont_mul_18(ctx->t3, ctx->t1, q->z, p1024_mod, p1024_mp_mod);
  41429. ctx->state = 3;
  41430. break;
  41431. case 3:
  41432. sp_1024_mont_mul_18(ctx->t1, ctx->t1, p->x, p1024_mod, p1024_mp_mod);
  41433. ctx->state = 4;
  41434. break;
  41435. case 4:
  41436. /* U2 = X2*Z1^2 */
  41437. sp_1024_mont_sqr_18(ctx->t2, p->z, p1024_mod, p1024_mp_mod);
  41438. ctx->state = 5;
  41439. break;
  41440. case 5:
  41441. sp_1024_mont_mul_18(ctx->t4, ctx->t2, p->z, p1024_mod, p1024_mp_mod);
  41442. ctx->state = 6;
  41443. break;
  41444. case 6:
  41445. sp_1024_mont_mul_18(ctx->t2, ctx->t2, q->x, p1024_mod, p1024_mp_mod);
  41446. ctx->state = 7;
  41447. break;
  41448. case 7:
  41449. /* S1 = Y1*Z2^3 */
  41450. sp_1024_mont_mul_18(ctx->t3, ctx->t3, p->y, p1024_mod, p1024_mp_mod);
  41451. ctx->state = 8;
  41452. break;
  41453. case 8:
  41454. /* S2 = Y2*Z1^3 */
  41455. sp_1024_mont_mul_18(ctx->t4, ctx->t4, q->y, p1024_mod, p1024_mp_mod);
  41456. ctx->state = 9;
  41457. break;
  41458. case 9:
  41459. /* Check double */
  41460. if ((~p->infinity) & (~q->infinity) &
  41461. sp_1024_cmp_equal_18(ctx->t2, ctx->t1) &
  41462. sp_1024_cmp_equal_18(ctx->t4, ctx->t3)) {
  41463. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  41464. sp_1024_proj_point_dbl_18(r, p, t);
  41465. ctx->state = 25;
  41466. }
  41467. else {
  41468. ctx->state = 10;
  41469. }
  41470. break;
  41471. case 10:
  41472. /* H = U2 - U1 */
  41473. sp_1024_mont_sub_18(ctx->t2, ctx->t2, ctx->t1, p1024_mod);
  41474. ctx->state = 11;
  41475. break;
  41476. case 11:
  41477. /* R = S2 - S1 */
  41478. sp_1024_mont_sub_18(ctx->t4, ctx->t4, ctx->t3, p1024_mod);
  41479. ctx->state = 12;
  41480. break;
  41481. case 12:
  41482. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  41483. sp_1024_mont_sqr_18(ctx->t5, ctx->t2, p1024_mod, p1024_mp_mod);
  41484. ctx->state = 13;
  41485. break;
  41486. case 13:
  41487. sp_1024_mont_mul_18(ctx->y, ctx->t1, ctx->t5, p1024_mod, p1024_mp_mod);
  41488. ctx->state = 14;
  41489. break;
  41490. case 14:
  41491. sp_1024_mont_mul_18(ctx->t5, ctx->t5, ctx->t2, p1024_mod, p1024_mp_mod);
  41492. ctx->state = 15;
  41493. break;
  41494. case 15:
  41495. /* Z3 = H*Z1*Z2 */
  41496. sp_1024_mont_mul_18(ctx->z, p->z, ctx->t2, p1024_mod, p1024_mp_mod);
  41497. ctx->state = 16;
  41498. break;
  41499. case 16:
  41500. sp_1024_mont_mul_18(ctx->z, ctx->z, q->z, p1024_mod, p1024_mp_mod);
  41501. ctx->state = 17;
  41502. break;
  41503. case 17:
  41504. sp_1024_mont_sqr_18(ctx->x, ctx->t4, p1024_mod, p1024_mp_mod);
  41505. ctx->state = 18;
  41506. break;
  41507. case 18:
  41508. sp_1024_mont_sub_18(ctx->x, ctx->x, ctx->t5, p1024_mod);
  41509. ctx->state = 19;
  41510. break;
  41511. case 19:
  41512. sp_1024_mont_mul_18(ctx->t5, ctx->t5, ctx->t3, p1024_mod, p1024_mp_mod);
  41513. ctx->state = 20;
  41514. break;
  41515. case 20:
  41516. sp_1024_mont_dbl_18(ctx->t3, ctx->y, p1024_mod);
  41517. sp_1024_mont_sub_18(ctx->x, ctx->x, ctx->t3, p1024_mod);
  41518. ctx->state = 21;
  41519. break;
  41520. case 21:
  41521. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  41522. sp_1024_mont_sub_18(ctx->y, ctx->y, ctx->x, p1024_mod);
  41523. ctx->state = 22;
  41524. break;
  41525. case 22:
  41526. sp_1024_mont_mul_18(ctx->y, ctx->y, ctx->t4, p1024_mod, p1024_mp_mod);
  41527. ctx->state = 23;
  41528. break;
  41529. case 23:
  41530. sp_1024_mont_sub_18(ctx->y, ctx->y, ctx->t5, p1024_mod);
  41531. ctx->state = 24;
  41532. break;
  41533. case 24:
  41534. {
  41535. {
  41536. int i;
  41537. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  41538. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  41539. sp_digit maskt = ~(maskp | maskq);
  41540. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  41541. for (i = 0; i < 18; i++) {
  41542. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  41543. (ctx->x[i] & maskt);
  41544. }
  41545. for (i = 0; i < 18; i++) {
  41546. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  41547. (ctx->y[i] & maskt);
  41548. }
  41549. for (i = 0; i < 18; i++) {
  41550. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  41551. (ctx->z[i] & maskt);
  41552. }
  41553. r->z[0] |= inf;
  41554. r->infinity = (word32)inf;
  41555. }
  41556. ctx->state = 25;
  41557. break;
  41558. }
  41559. case 25:
  41560. err = MP_OKAY;
  41561. break;
  41562. }
  41563. if (err == MP_OKAY && ctx->state != 25) {
  41564. err = FP_WOULDBLOCK;
  41565. }
  41566. return err;
  41567. }
  41568. #endif /* WOLFSSL_SP_NONBLOCK */
  41569. #ifdef WOLFSSL_SP_SMALL
  41570. /* Multiply the point by the scalar and return the result.
  41571. * If map is true then convert result to affine coordinates.
  41572. *
  41573. * Small implementation using add and double that is cache attack resistant but
  41574. * allocates memory rather than use large stacks.
  41575. * 1024 adds and doubles.
  41576. *
  41577. * r Resulting point.
  41578. * g Point to multiply.
  41579. * k Scalar to multiply by.
  41580. * map Indicates whether to convert result to affine.
  41581. * ct Constant time required.
  41582. * heap Heap to use for allocation.
  41583. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  41584. */
  41585. static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g,
  41586. const sp_digit* k, int map, int ct, void* heap)
  41587. {
  41588. #ifdef WOLFSSL_SP_SMALL_STACK
  41589. sp_point_1024* t = NULL;
  41590. sp_digit* tmp = NULL;
  41591. #else
  41592. sp_point_1024 t[3];
  41593. sp_digit tmp[2 * 18 * 37];
  41594. #endif
  41595. sp_digit n;
  41596. int i;
  41597. int c;
  41598. int y;
  41599. int err = MP_OKAY;
  41600. /* Implementation is constant time. */
  41601. (void)ct;
  41602. (void)heap;
  41603. #ifdef WOLFSSL_SP_SMALL_STACK
  41604. t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap,
  41605. DYNAMIC_TYPE_ECC);
  41606. if (t == NULL)
  41607. err = MEMORY_E;
  41608. if (err == MP_OKAY) {
  41609. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 37, heap,
  41610. DYNAMIC_TYPE_ECC);
  41611. if (tmp == NULL)
  41612. err = MEMORY_E;
  41613. }
  41614. #endif
  41615. if (err == MP_OKAY) {
  41616. XMEMSET(t, 0, sizeof(sp_point_1024) * 3);
  41617. /* t[0] = {0, 0, 1} * norm */
  41618. t[0].infinity = 1;
  41619. /* t[1] = {g->x, g->y, g->z} * norm */
  41620. err = sp_1024_mod_mul_norm_18(t[1].x, g->x, p1024_mod);
  41621. }
  41622. if (err == MP_OKAY)
  41623. err = sp_1024_mod_mul_norm_18(t[1].y, g->y, p1024_mod);
  41624. if (err == MP_OKAY)
  41625. err = sp_1024_mod_mul_norm_18(t[1].z, g->z, p1024_mod);
  41626. if (err == MP_OKAY) {
  41627. i = 17;
  41628. c = 55;
  41629. n = k[i--] << (57 - c);
  41630. for (; ; c--) {
  41631. if (c == 0) {
  41632. if (i == -1)
  41633. break;
  41634. n = k[i--];
  41635. c = 57;
  41636. }
  41637. y = (n >> 56) & 1;
  41638. n <<= 1;
  41639. sp_1024_proj_point_add_18(&t[y^1], &t[0], &t[1], tmp);
  41640. XMEMCPY(&t[2], (void*)(((size_t)&t[0] & addr_mask[y^1]) +
  41641. ((size_t)&t[1] & addr_mask[y])),
  41642. sizeof(sp_point_1024));
  41643. sp_1024_proj_point_dbl_18(&t[2], &t[2], tmp);
  41644. XMEMCPY((void*)(((size_t)&t[0] & addr_mask[y^1]) +
  41645. ((size_t)&t[1] & addr_mask[y])), &t[2],
  41646. sizeof(sp_point_1024));
  41647. }
  41648. if (map != 0) {
  41649. sp_1024_map_18(r, &t[0], tmp);
  41650. }
  41651. else {
  41652. XMEMCPY(r, &t[0], sizeof(sp_point_1024));
  41653. }
  41654. }
  41655. #ifdef WOLFSSL_SP_SMALL_STACK
  41656. if (tmp != NULL)
  41657. #endif
  41658. {
  41659. ForceZero(tmp, sizeof(sp_digit) * 2 * 18 * 37);
  41660. #ifdef WOLFSSL_SP_SMALL_STACK
  41661. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  41662. #endif
  41663. }
  41664. #ifdef WOLFSSL_SP_SMALL_STACK
  41665. if (t != NULL)
  41666. #endif
  41667. {
  41668. ForceZero(t, sizeof(sp_point_1024) * 3);
  41669. #ifdef WOLFSSL_SP_SMALL_STACK
  41670. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  41671. #endif
  41672. }
  41673. return err;
  41674. }
  41675. #ifdef WOLFSSL_SP_NONBLOCK
  41676. typedef struct sp_1024_ecc_mulmod_18_ctx {
  41677. int state;
  41678. union {
  41679. sp_1024_proj_point_dbl_18_ctx dbl_ctx;
  41680. sp_1024_proj_point_add_18_ctx add_ctx;
  41681. };
  41682. sp_point_1024 t[3];
  41683. sp_digit tmp[2 * 18 * 37];
  41684. sp_digit n;
  41685. int i;
  41686. int c;
  41687. int y;
  41688. } sp_1024_ecc_mulmod_18_ctx;
  41689. static int sp_1024_ecc_mulmod_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
  41690. const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap)
  41691. {
  41692. int err = FP_WOULDBLOCK;
  41693. sp_1024_ecc_mulmod_18_ctx* ctx = (sp_1024_ecc_mulmod_18_ctx*)sp_ctx->data;
  41694. typedef char ctx_size_test[sizeof(sp_1024_ecc_mulmod_18_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
  41695. (void)sizeof(ctx_size_test);
  41696. /* Implementation is constant time. */
  41697. (void)ct;
  41698. switch (ctx->state) {
  41699. case 0: /* INIT */
  41700. XMEMSET(ctx->t, 0, sizeof(sp_point_1024) * 3);
  41701. ctx->i = 17;
  41702. ctx->c = 55;
  41703. ctx->n = k[ctx->i--] << (57 - ctx->c);
  41704. /* t[0] = {0, 0, 1} * norm */
  41705. ctx->t[0].infinity = 1;
  41706. ctx->state = 1;
  41707. break;
  41708. case 1: /* T1X */
  41709. /* t[1] = {g->x, g->y, g->z} * norm */
  41710. err = sp_1024_mod_mul_norm_18(ctx->t[1].x, g->x, p1024_mod);
  41711. ctx->state = 2;
  41712. break;
  41713. case 2: /* T1Y */
  41714. err = sp_1024_mod_mul_norm_18(ctx->t[1].y, g->y, p1024_mod);
  41715. ctx->state = 3;
  41716. break;
  41717. case 3: /* T1Z */
  41718. err = sp_1024_mod_mul_norm_18(ctx->t[1].z, g->z, p1024_mod);
  41719. ctx->state = 4;
  41720. break;
  41721. case 4: /* ADDPREP */
  41722. if (ctx->c == 0) {
  41723. if (ctx->i == -1) {
  41724. ctx->state = 7;
  41725. break;
  41726. }
  41727. ctx->n = k[ctx->i--];
  41728. ctx->c = 57;
  41729. }
  41730. ctx->y = (ctx->n >> 56) & 1;
  41731. ctx->n <<= 1;
  41732. XMEMSET(&ctx->add_ctx, 0, sizeof(ctx->add_ctx));
  41733. ctx->state = 5;
  41734. break;
  41735. case 5: /* ADD */
  41736. err = sp_1024_proj_point_add_18_nb((sp_ecc_ctx_t*)&ctx->add_ctx,
  41737. &ctx->t[ctx->y^1], &ctx->t[0], &ctx->t[1], ctx->tmp);
  41738. if (err == MP_OKAY) {
  41739. XMEMCPY(&ctx->t[2], (void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  41740. ((size_t)&ctx->t[1] & addr_mask[ctx->y])),
  41741. sizeof(sp_point_1024));
  41742. XMEMSET(&ctx->dbl_ctx, 0, sizeof(ctx->dbl_ctx));
  41743. ctx->state = 6;
  41744. }
  41745. break;
  41746. case 6: /* DBL */
  41747. err = sp_1024_proj_point_dbl_18_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->t[2],
  41748. &ctx->t[2], ctx->tmp);
  41749. if (err == MP_OKAY) {
  41750. XMEMCPY((void*)(((size_t)&ctx->t[0] & addr_mask[ctx->y^1]) +
  41751. ((size_t)&ctx->t[1] & addr_mask[ctx->y])), &ctx->t[2],
  41752. sizeof(sp_point_1024));
  41753. ctx->state = 4;
  41754. ctx->c--;
  41755. }
  41756. break;
  41757. case 7: /* MAP */
  41758. if (map != 0) {
  41759. sp_1024_map_18(r, &ctx->t[0], ctx->tmp);
  41760. }
  41761. else {
  41762. XMEMCPY(r, &ctx->t[0], sizeof(sp_point_1024));
  41763. }
  41764. err = MP_OKAY;
  41765. break;
  41766. }
  41767. if (err == MP_OKAY && ctx->state != 7) {
  41768. err = FP_WOULDBLOCK;
  41769. }
  41770. if (err != FP_WOULDBLOCK) {
  41771. ForceZero(ctx->tmp, sizeof(ctx->tmp));
  41772. ForceZero(ctx->t, sizeof(ctx->t));
  41773. }
  41774. (void)heap;
  41775. return err;
  41776. }
  41777. #endif /* WOLFSSL_SP_NONBLOCK */
  41778. #else
  41779. /* A table entry for pre-computed points. */
  41780. typedef struct sp_table_entry_1024 {
  41781. sp_digit x[18];
  41782. sp_digit y[18];
  41783. } sp_table_entry_1024;
  41784. /* Conditionally copy a into r using the mask m.
  41785. * m is -1 to copy and 0 when not.
  41786. *
  41787. * r A single precision number to copy over.
  41788. * a A single precision number to copy.
  41789. * m Mask value to apply.
  41790. */
  41791. static void sp_1024_cond_copy_18(sp_digit* r, const sp_digit* a, const sp_digit m)
  41792. {
  41793. sp_digit t[18];
  41794. #ifdef WOLFSSL_SP_SMALL
  41795. int i;
  41796. for (i = 0; i < 18; i++) {
  41797. t[i] = r[i] ^ a[i];
  41798. }
  41799. for (i = 0; i < 18; i++) {
  41800. r[i] ^= t[i] & m;
  41801. }
  41802. #else
  41803. t[ 0] = r[ 0] ^ a[ 0];
  41804. t[ 1] = r[ 1] ^ a[ 1];
  41805. t[ 2] = r[ 2] ^ a[ 2];
  41806. t[ 3] = r[ 3] ^ a[ 3];
  41807. t[ 4] = r[ 4] ^ a[ 4];
  41808. t[ 5] = r[ 5] ^ a[ 5];
  41809. t[ 6] = r[ 6] ^ a[ 6];
  41810. t[ 7] = r[ 7] ^ a[ 7];
  41811. t[ 8] = r[ 8] ^ a[ 8];
  41812. t[ 9] = r[ 9] ^ a[ 9];
  41813. t[10] = r[10] ^ a[10];
  41814. t[11] = r[11] ^ a[11];
  41815. t[12] = r[12] ^ a[12];
  41816. t[13] = r[13] ^ a[13];
  41817. t[14] = r[14] ^ a[14];
  41818. t[15] = r[15] ^ a[15];
  41819. t[16] = r[16] ^ a[16];
  41820. t[17] = r[17] ^ a[17];
  41821. r[ 0] ^= t[ 0] & m;
  41822. r[ 1] ^= t[ 1] & m;
  41823. r[ 2] ^= t[ 2] & m;
  41824. r[ 3] ^= t[ 3] & m;
  41825. r[ 4] ^= t[ 4] & m;
  41826. r[ 5] ^= t[ 5] & m;
  41827. r[ 6] ^= t[ 6] & m;
  41828. r[ 7] ^= t[ 7] & m;
  41829. r[ 8] ^= t[ 8] & m;
  41830. r[ 9] ^= t[ 9] & m;
  41831. r[10] ^= t[10] & m;
  41832. r[11] ^= t[11] & m;
  41833. r[12] ^= t[12] & m;
  41834. r[13] ^= t[13] & m;
  41835. r[14] ^= t[14] & m;
  41836. r[15] ^= t[15] & m;
  41837. r[16] ^= t[16] & m;
  41838. r[17] ^= t[17] & m;
  41839. #endif /* WOLFSSL_SP_SMALL */
  41840. }
  41841. /* Double the Montgomery form projective point p a number of times.
  41842. *
  41843. * r Result of repeated doubling of point.
  41844. * p Point to double.
  41845. * n Number of times to double
  41846. * t Temporary ordinate data.
  41847. */
  41848. static void sp_1024_proj_point_dbl_n_18(sp_point_1024* p, int i,
  41849. sp_digit* t)
  41850. {
  41851. sp_digit* w = t;
  41852. sp_digit* a = t + 2*18;
  41853. sp_digit* b = t + 4*18;
  41854. sp_digit* t1 = t + 6*18;
  41855. sp_digit* t2 = t + 8*18;
  41856. sp_digit* x;
  41857. sp_digit* y;
  41858. sp_digit* z;
  41859. volatile int n = i;
  41860. x = p->x;
  41861. y = p->y;
  41862. z = p->z;
  41863. /* Y = 2*Y */
  41864. sp_1024_mont_dbl_18(y, y, p1024_mod);
  41865. /* W = Z^4 */
  41866. sp_1024_mont_sqr_18(w, z, p1024_mod, p1024_mp_mod);
  41867. sp_1024_mont_sqr_18(w, w, p1024_mod, p1024_mp_mod);
  41868. #ifndef WOLFSSL_SP_SMALL
  41869. while (--n > 0)
  41870. #else
  41871. while (--n >= 0)
  41872. #endif
  41873. {
  41874. /* A = 3*(X^2 - W) */
  41875. sp_1024_mont_sqr_18(t1, x, p1024_mod, p1024_mp_mod);
  41876. sp_1024_mont_sub_18(t1, t1, w, p1024_mod);
  41877. sp_1024_mont_tpl_18(a, t1, p1024_mod);
  41878. /* B = X*Y^2 */
  41879. sp_1024_mont_sqr_18(t1, y, p1024_mod, p1024_mp_mod);
  41880. sp_1024_mont_mul_18(b, t1, x, p1024_mod, p1024_mp_mod);
  41881. /* X = A^2 - 2B */
  41882. sp_1024_mont_sqr_18(x, a, p1024_mod, p1024_mp_mod);
  41883. sp_1024_mont_dbl_18(t2, b, p1024_mod);
  41884. sp_1024_mont_sub_18(x, x, t2, p1024_mod);
  41885. /* B = 2.(B - X) */
  41886. sp_1024_mont_sub_18(t2, b, x, p1024_mod);
  41887. sp_1024_mont_dbl_18(b, t2, p1024_mod);
  41888. /* Z = Z*Y */
  41889. sp_1024_mont_mul_18(z, z, y, p1024_mod, p1024_mp_mod);
  41890. /* t1 = Y^4 */
  41891. sp_1024_mont_sqr_18(t1, t1, p1024_mod, p1024_mp_mod);
  41892. #ifdef WOLFSSL_SP_SMALL
  41893. if (n != 0)
  41894. #endif
  41895. {
  41896. /* W = W*Y^4 */
  41897. sp_1024_mont_mul_18(w, w, t1, p1024_mod, p1024_mp_mod);
  41898. }
  41899. /* y = 2*A*(B - X) - Y^4 */
  41900. sp_1024_mont_mul_18(y, b, a, p1024_mod, p1024_mp_mod);
  41901. sp_1024_mont_sub_18(y, y, t1, p1024_mod);
  41902. }
  41903. #ifndef WOLFSSL_SP_SMALL
  41904. /* A = 3*(X^2 - W) */
  41905. sp_1024_mont_sqr_18(t1, x, p1024_mod, p1024_mp_mod);
  41906. sp_1024_mont_sub_18(t1, t1, w, p1024_mod);
  41907. sp_1024_mont_tpl_18(a, t1, p1024_mod);
  41908. /* B = X*Y^2 */
  41909. sp_1024_mont_sqr_18(t1, y, p1024_mod, p1024_mp_mod);
  41910. sp_1024_mont_mul_18(b, t1, x, p1024_mod, p1024_mp_mod);
  41911. /* X = A^2 - 2B */
  41912. sp_1024_mont_sqr_18(x, a, p1024_mod, p1024_mp_mod);
  41913. sp_1024_mont_dbl_18(t2, b, p1024_mod);
  41914. sp_1024_mont_sub_18(x, x, t2, p1024_mod);
  41915. /* B = 2.(B - X) */
  41916. sp_1024_mont_sub_18(t2, b, x, p1024_mod);
  41917. sp_1024_mont_dbl_18(b, t2, p1024_mod);
  41918. /* Z = Z*Y */
  41919. sp_1024_mont_mul_18(z, z, y, p1024_mod, p1024_mp_mod);
  41920. /* t1 = Y^4 */
  41921. sp_1024_mont_sqr_18(t1, t1, p1024_mod, p1024_mp_mod);
  41922. /* y = 2*A*(B - X) - Y^4 */
  41923. sp_1024_mont_mul_18(y, b, a, p1024_mod, p1024_mp_mod);
  41924. sp_1024_mont_sub_18(y, y, t1, p1024_mod);
  41925. #endif /* WOLFSSL_SP_SMALL */
  41926. /* Y = Y/2 */
  41927. sp_1024_mont_div2_18(y, y, p1024_mod);
  41928. }
  41929. /* Double the Montgomery form projective point p a number of times.
  41930. *
  41931. * r Result of repeated doubling of point.
  41932. * p Point to double.
  41933. * n Number of times to double
  41934. * t Temporary ordinate data.
  41935. */
  41936. static void sp_1024_proj_point_dbl_n_store_18(sp_point_1024* r,
  41937. const sp_point_1024* p, int n, int m, sp_digit* t)
  41938. {
  41939. sp_digit* w = t;
  41940. sp_digit* a = t + 2*18;
  41941. sp_digit* b = t + 4*18;
  41942. sp_digit* t1 = t + 6*18;
  41943. sp_digit* t2 = t + 8*18;
  41944. sp_digit* x = r[2*m].x;
  41945. sp_digit* y = r[(1<<n)*m].y;
  41946. sp_digit* z = r[2*m].z;
  41947. int i;
  41948. int j;
  41949. for (i=0; i<18; i++) {
  41950. x[i] = p->x[i];
  41951. }
  41952. for (i=0; i<18; i++) {
  41953. y[i] = p->y[i];
  41954. }
  41955. for (i=0; i<18; i++) {
  41956. z[i] = p->z[i];
  41957. }
  41958. /* Y = 2*Y */
  41959. sp_1024_mont_dbl_18(y, y, p1024_mod);
  41960. /* W = Z^4 */
  41961. sp_1024_mont_sqr_18(w, z, p1024_mod, p1024_mp_mod);
  41962. sp_1024_mont_sqr_18(w, w, p1024_mod, p1024_mp_mod);
  41963. j = m;
  41964. for (i=1; i<=n; i++) {
  41965. j *= 2;
  41966. /* A = 3*(X^2 - W) */
  41967. sp_1024_mont_sqr_18(t1, x, p1024_mod, p1024_mp_mod);
  41968. sp_1024_mont_sub_18(t1, t1, w, p1024_mod);
  41969. sp_1024_mont_tpl_18(a, t1, p1024_mod);
  41970. /* B = X*Y^2 */
  41971. sp_1024_mont_sqr_18(t1, y, p1024_mod, p1024_mp_mod);
  41972. sp_1024_mont_mul_18(b, t1, x, p1024_mod, p1024_mp_mod);
  41973. x = r[j].x;
  41974. /* X = A^2 - 2B */
  41975. sp_1024_mont_sqr_18(x, a, p1024_mod, p1024_mp_mod);
  41976. sp_1024_mont_dbl_18(t2, b, p1024_mod);
  41977. sp_1024_mont_sub_18(x, x, t2, p1024_mod);
  41978. /* B = 2.(B - X) */
  41979. sp_1024_mont_sub_18(t2, b, x, p1024_mod);
  41980. sp_1024_mont_dbl_18(b, t2, p1024_mod);
  41981. /* Z = Z*Y */
  41982. sp_1024_mont_mul_18(r[j].z, z, y, p1024_mod, p1024_mp_mod);
  41983. z = r[j].z;
  41984. /* t1 = Y^4 */
  41985. sp_1024_mont_sqr_18(t1, t1, p1024_mod, p1024_mp_mod);
  41986. if (i != n) {
  41987. /* W = W*Y^4 */
  41988. sp_1024_mont_mul_18(w, w, t1, p1024_mod, p1024_mp_mod);
  41989. }
  41990. /* y = 2*A*(B - X) - Y^4 */
  41991. sp_1024_mont_mul_18(y, b, a, p1024_mod, p1024_mp_mod);
  41992. sp_1024_mont_sub_18(y, y, t1, p1024_mod);
  41993. /* Y = Y/2 */
  41994. sp_1024_mont_div2_18(r[j].y, y, p1024_mod);
  41995. r[j].infinity = 0;
  41996. }
  41997. }
  41998. /* Add two Montgomery form projective points.
  41999. *
  42000. * ra Result of addition.
  42001. * rs Result of subtraction.
  42002. * p First point to add.
  42003. * q Second point to add.
  42004. * t Temporary ordinate data.
  42005. */
  42006. static void sp_1024_proj_point_add_sub_18(sp_point_1024* ra,
  42007. sp_point_1024* rs, const sp_point_1024* p, const sp_point_1024* q,
  42008. sp_digit* t)
  42009. {
  42010. sp_digit* t1 = t;
  42011. sp_digit* t2 = t + 2*18;
  42012. sp_digit* t3 = t + 4*18;
  42013. sp_digit* t4 = t + 6*18;
  42014. sp_digit* t5 = t + 8*18;
  42015. sp_digit* t6 = t + 10*18;
  42016. sp_digit* xa = ra->x;
  42017. sp_digit* ya = ra->y;
  42018. sp_digit* za = ra->z;
  42019. sp_digit* xs = rs->x;
  42020. sp_digit* ys = rs->y;
  42021. sp_digit* zs = rs->z;
  42022. XMEMCPY(xa, p->x, sizeof(p->x) / 2);
  42023. XMEMCPY(ya, p->y, sizeof(p->y) / 2);
  42024. XMEMCPY(za, p->z, sizeof(p->z) / 2);
  42025. ra->infinity = 0;
  42026. rs->infinity = 0;
  42027. /* U1 = X1*Z2^2 */
  42028. sp_1024_mont_sqr_18(t1, q->z, p1024_mod, p1024_mp_mod);
  42029. sp_1024_mont_mul_18(t3, t1, q->z, p1024_mod, p1024_mp_mod);
  42030. sp_1024_mont_mul_18(t1, t1, xa, p1024_mod, p1024_mp_mod);
  42031. /* U2 = X2*Z1^2 */
  42032. sp_1024_mont_sqr_18(t2, za, p1024_mod, p1024_mp_mod);
  42033. sp_1024_mont_mul_18(t4, t2, za, p1024_mod, p1024_mp_mod);
  42034. sp_1024_mont_mul_18(t2, t2, q->x, p1024_mod, p1024_mp_mod);
  42035. /* S1 = Y1*Z2^3 */
  42036. sp_1024_mont_mul_18(t3, t3, ya, p1024_mod, p1024_mp_mod);
  42037. /* S2 = Y2*Z1^3 */
  42038. sp_1024_mont_mul_18(t4, t4, q->y, p1024_mod, p1024_mp_mod);
  42039. /* H = U2 - U1 */
  42040. sp_1024_mont_sub_18(t2, t2, t1, p1024_mod);
  42041. /* RS = S2 + S1 */
  42042. sp_1024_mont_add_18(t6, t4, t3, p1024_mod);
  42043. /* R = S2 - S1 */
  42044. sp_1024_mont_sub_18(t4, t4, t3, p1024_mod);
  42045. /* Z3 = H*Z1*Z2 */
  42046. /* ZS = H*Z1*Z2 */
  42047. sp_1024_mont_mul_18(za, za, q->z, p1024_mod, p1024_mp_mod);
  42048. sp_1024_mont_mul_18(za, za, t2, p1024_mod, p1024_mp_mod);
  42049. XMEMCPY(zs, za, sizeof(p->z)/2);
  42050. /* X3 = R^2 - H^3 - 2*U1*H^2 */
  42051. /* XS = RS^2 - H^3 - 2*U1*H^2 */
  42052. sp_1024_mont_sqr_18(xa, t4, p1024_mod, p1024_mp_mod);
  42053. sp_1024_mont_sqr_18(xs, t6, p1024_mod, p1024_mp_mod);
  42054. sp_1024_mont_sqr_18(t5, t2, p1024_mod, p1024_mp_mod);
  42055. sp_1024_mont_mul_18(ya, t1, t5, p1024_mod, p1024_mp_mod);
  42056. sp_1024_mont_mul_18(t5, t5, t2, p1024_mod, p1024_mp_mod);
  42057. sp_1024_mont_sub_18(xa, xa, t5, p1024_mod);
  42058. sp_1024_mont_sub_18(xs, xs, t5, p1024_mod);
  42059. sp_1024_mont_dbl_18(t1, ya, p1024_mod);
  42060. sp_1024_mont_sub_18(xa, xa, t1, p1024_mod);
  42061. sp_1024_mont_sub_18(xs, xs, t1, p1024_mod);
  42062. /* Y3 = R*(U1*H^2 - X3) - S1*H^3 */
  42063. /* YS = -RS*(U1*H^2 - XS) - S1*H^3 */
  42064. sp_1024_mont_sub_18(ys, ya, xs, p1024_mod);
  42065. sp_1024_mont_sub_18(ya, ya, xa, p1024_mod);
  42066. sp_1024_mont_mul_18(ya, ya, t4, p1024_mod, p1024_mp_mod);
  42067. sp_1024_mont_sub_18(t6, p1024_mod, t6, p1024_mod);
  42068. sp_1024_mont_mul_18(ys, ys, t6, p1024_mod, p1024_mp_mod);
  42069. sp_1024_mont_mul_18(t5, t5, t3, p1024_mod, p1024_mp_mod);
  42070. sp_1024_mont_sub_18(ya, ya, t5, p1024_mod);
  42071. sp_1024_mont_sub_18(ys, ys, t5, p1024_mod);
  42072. }
  42073. /* Structure used to describe recoding of scalar multiplication. */
  42074. typedef struct ecc_recode_1024 {
  42075. /* Index into pre-computation table. */
  42076. uint8_t i;
  42077. /* Use the negative of the point. */
  42078. uint8_t neg;
  42079. } ecc_recode_1024;
  42080. /* The index into pre-computation table to use. */
  42081. static const uint8_t recode_index_18_7[130] = {
  42082. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  42083. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  42084. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  42085. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  42086. 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49,
  42087. 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33,
  42088. 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
  42089. 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
  42090. 0, 1,
  42091. };
  42092. /* Whether to negate y-ordinate. */
  42093. static const uint8_t recode_neg_18_7[130] = {
  42094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  42095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  42096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  42097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  42098. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  42099. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  42100. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  42101. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  42102. 0, 0,
  42103. };
  42104. /* Recode the scalar for multiplication using pre-computed values and
  42105. * subtraction.
  42106. *
  42107. * k Scalar to multiply by.
  42108. * v Vector of operations to perform.
  42109. */
  42110. static void sp_1024_ecc_recode_7_18(const sp_digit* k, ecc_recode_1024* v)
  42111. {
  42112. int i;
  42113. int j;
  42114. uint8_t y;
  42115. int carry = 0;
  42116. int o;
  42117. sp_digit n;
  42118. j = 0;
  42119. n = k[j];
  42120. o = 0;
  42121. for (i=0; i<147; i++) {
  42122. y = (int8_t)n;
  42123. if (o + 7 < 57) {
  42124. y &= 0x7f;
  42125. n >>= 7;
  42126. o += 7;
  42127. }
  42128. else if (o + 7 == 57) {
  42129. n >>= 7;
  42130. if (++j < 18)
  42131. n = k[j];
  42132. o = 0;
  42133. }
  42134. else if (++j < 18) {
  42135. n = k[j];
  42136. y |= (uint8_t)((n << (57 - o)) & 0x7f);
  42137. o -= 50;
  42138. n >>= o;
  42139. }
  42140. y += (uint8_t)carry;
  42141. v[i].i = recode_index_18_7[y];
  42142. v[i].neg = recode_neg_18_7[y];
  42143. carry = (y >> 7) + v[i].neg;
  42144. }
  42145. }
  42146. /* Multiply the point by the scalar and return the result.
  42147. * If map is true then convert result to affine coordinates.
  42148. *
  42149. * Window technique of 7 bits. (Add-Sub variation.)
  42150. * Calculate 0..64 times the point. Use function that adds and
  42151. * subtracts the same two points.
  42152. * Recode to add or subtract one of the computed points.
  42153. * Double to push up.
  42154. * NOT a sliding window.
  42155. *
  42156. * r Resulting point.
  42157. * g Point to multiply.
  42158. * k Scalar to multiply by.
  42159. * map Indicates whether to convert result to affine.
  42160. * ct Constant time required.
  42161. * heap Heap to use for allocation.
  42162. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  42163. */
  42164. static int sp_1024_ecc_mulmod_win_add_sub_18(sp_point_1024* r, const sp_point_1024* g,
  42165. const sp_digit* k, int map, int ct, void* heap)
  42166. {
  42167. #ifdef WOLFSSL_SP_SMALL_STACK
  42168. sp_point_1024* t = NULL;
  42169. sp_digit* tmp = NULL;
  42170. #else
  42171. sp_point_1024 t[65+2];
  42172. sp_digit tmp[2 * 18 * 37];
  42173. #endif
  42174. sp_point_1024* rt = NULL;
  42175. sp_point_1024* p = NULL;
  42176. sp_digit* negy;
  42177. int i;
  42178. ecc_recode_1024 v[147];
  42179. int err = MP_OKAY;
  42180. /* Constant time used for cache attack resistance implementation. */
  42181. (void)ct;
  42182. (void)heap;
  42183. #ifdef WOLFSSL_SP_SMALL_STACK
  42184. t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) *
  42185. (65+2), heap, DYNAMIC_TYPE_ECC);
  42186. if (t == NULL)
  42187. err = MEMORY_E;
  42188. if (err == MP_OKAY) {
  42189. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 37,
  42190. heap, DYNAMIC_TYPE_ECC);
  42191. if (tmp == NULL)
  42192. err = MEMORY_E;
  42193. }
  42194. #endif
  42195. if (err == MP_OKAY) {
  42196. rt = t + 65;
  42197. p = t + 65+1;
  42198. /* t[0] = {0, 0, 1} * norm */
  42199. XMEMSET(&t[0], 0, sizeof(t[0]));
  42200. t[0].infinity = 1;
  42201. /* t[1] = {g->x, g->y, g->z} * norm */
  42202. err = sp_1024_mod_mul_norm_18(t[1].x, g->x, p1024_mod);
  42203. }
  42204. if (err == MP_OKAY) {
  42205. err = sp_1024_mod_mul_norm_18(t[1].y, g->y, p1024_mod);
  42206. }
  42207. if (err == MP_OKAY) {
  42208. err = sp_1024_mod_mul_norm_18(t[1].z, g->z, p1024_mod);
  42209. }
  42210. if (err == MP_OKAY) {
  42211. t[1].infinity = 0;
  42212. /* t[2] ... t[64] */
  42213. sp_1024_proj_point_dbl_n_store_18(t, &t[ 1], 6, 1, tmp);
  42214. sp_1024_proj_point_add_18(&t[ 3], &t[ 2], &t[ 1], tmp);
  42215. sp_1024_proj_point_dbl_18(&t[ 6], &t[ 3], tmp);
  42216. sp_1024_proj_point_add_sub_18(&t[ 7], &t[ 5], &t[ 6], &t[ 1], tmp);
  42217. sp_1024_proj_point_dbl_18(&t[10], &t[ 5], tmp);
  42218. sp_1024_proj_point_add_sub_18(&t[11], &t[ 9], &t[10], &t[ 1], tmp);
  42219. sp_1024_proj_point_dbl_18(&t[12], &t[ 6], tmp);
  42220. sp_1024_proj_point_dbl_18(&t[14], &t[ 7], tmp);
  42221. sp_1024_proj_point_add_sub_18(&t[15], &t[13], &t[14], &t[ 1], tmp);
  42222. sp_1024_proj_point_dbl_18(&t[18], &t[ 9], tmp);
  42223. sp_1024_proj_point_add_sub_18(&t[19], &t[17], &t[18], &t[ 1], tmp);
  42224. sp_1024_proj_point_dbl_18(&t[20], &t[10], tmp);
  42225. sp_1024_proj_point_dbl_18(&t[22], &t[11], tmp);
  42226. sp_1024_proj_point_add_sub_18(&t[23], &t[21], &t[22], &t[ 1], tmp);
  42227. sp_1024_proj_point_dbl_18(&t[24], &t[12], tmp);
  42228. sp_1024_proj_point_dbl_18(&t[26], &t[13], tmp);
  42229. sp_1024_proj_point_add_sub_18(&t[27], &t[25], &t[26], &t[ 1], tmp);
  42230. sp_1024_proj_point_dbl_18(&t[28], &t[14], tmp);
  42231. sp_1024_proj_point_dbl_18(&t[30], &t[15], tmp);
  42232. sp_1024_proj_point_add_sub_18(&t[31], &t[29], &t[30], &t[ 1], tmp);
  42233. sp_1024_proj_point_dbl_18(&t[34], &t[17], tmp);
  42234. sp_1024_proj_point_add_sub_18(&t[35], &t[33], &t[34], &t[ 1], tmp);
  42235. sp_1024_proj_point_dbl_18(&t[36], &t[18], tmp);
  42236. sp_1024_proj_point_dbl_18(&t[38], &t[19], tmp);
  42237. sp_1024_proj_point_add_sub_18(&t[39], &t[37], &t[38], &t[ 1], tmp);
  42238. sp_1024_proj_point_dbl_18(&t[40], &t[20], tmp);
  42239. sp_1024_proj_point_dbl_18(&t[42], &t[21], tmp);
  42240. sp_1024_proj_point_add_sub_18(&t[43], &t[41], &t[42], &t[ 1], tmp);
  42241. sp_1024_proj_point_dbl_18(&t[44], &t[22], tmp);
  42242. sp_1024_proj_point_dbl_18(&t[46], &t[23], tmp);
  42243. sp_1024_proj_point_add_sub_18(&t[47], &t[45], &t[46], &t[ 1], tmp);
  42244. sp_1024_proj_point_dbl_18(&t[48], &t[24], tmp);
  42245. sp_1024_proj_point_dbl_18(&t[50], &t[25], tmp);
  42246. sp_1024_proj_point_add_sub_18(&t[51], &t[49], &t[50], &t[ 1], tmp);
  42247. sp_1024_proj_point_dbl_18(&t[52], &t[26], tmp);
  42248. sp_1024_proj_point_dbl_18(&t[54], &t[27], tmp);
  42249. sp_1024_proj_point_add_sub_18(&t[55], &t[53], &t[54], &t[ 1], tmp);
  42250. sp_1024_proj_point_dbl_18(&t[56], &t[28], tmp);
  42251. sp_1024_proj_point_dbl_18(&t[58], &t[29], tmp);
  42252. sp_1024_proj_point_add_sub_18(&t[59], &t[57], &t[58], &t[ 1], tmp);
  42253. sp_1024_proj_point_dbl_18(&t[60], &t[30], tmp);
  42254. sp_1024_proj_point_dbl_18(&t[62], &t[31], tmp);
  42255. sp_1024_proj_point_add_sub_18(&t[63], &t[61], &t[62], &t[ 1], tmp);
  42256. negy = t[0].y;
  42257. sp_1024_ecc_recode_7_18(k, v);
  42258. i = 146;
  42259. XMEMCPY(rt, &t[v[i].i], sizeof(sp_point_1024));
  42260. for (--i; i>=0; i--) {
  42261. sp_1024_proj_point_dbl_n_18(rt, 7, tmp);
  42262. XMEMCPY(p, &t[v[i].i], sizeof(sp_point_1024));
  42263. sp_1024_mont_sub_18(negy, p1024_mod, p->y, p1024_mod);
  42264. sp_1024_norm_18(negy);
  42265. sp_1024_cond_copy_18(p->y, negy, (sp_digit)0 - v[i].neg);
  42266. sp_1024_proj_point_add_18(rt, rt, p, tmp);
  42267. }
  42268. if (map != 0) {
  42269. sp_1024_map_18(r, rt, tmp);
  42270. }
  42271. else {
  42272. XMEMCPY(r, rt, sizeof(sp_point_1024));
  42273. }
  42274. }
  42275. #ifdef WOLFSSL_SP_SMALL_STACK
  42276. if (t != NULL)
  42277. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  42278. if (tmp != NULL)
  42279. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  42280. #endif
  42281. return err;
  42282. }
  42283. #ifdef FP_ECC
  42284. #endif /* FP_ECC */
  42285. /* Add two Montgomery form projective points. The second point has a q value of
  42286. * one.
  42287. * Only the first point can be the same pointer as the result point.
  42288. *
  42289. * r Result of addition.
  42290. * p First point to add.
  42291. * q Second point to add.
  42292. * t Temporary ordinate data.
  42293. */
  42294. static void sp_1024_proj_point_add_qz1_18(sp_point_1024* r,
  42295. const sp_point_1024* p, const sp_point_1024* q, sp_digit* t)
  42296. {
  42297. sp_digit* t2 = t;
  42298. sp_digit* t3 = t + 2*18;
  42299. sp_digit* t6 = t + 4*18;
  42300. sp_digit* t1 = t + 6*18;
  42301. sp_digit* t4 = t + 8*18;
  42302. sp_digit* t5 = t + 10*18;
  42303. /* Calculate values to subtract from P->x and P->y. */
  42304. /* U2 = X2*Z1^2 */
  42305. sp_1024_mont_sqr_18(t2, p->z, p1024_mod, p1024_mp_mod);
  42306. sp_1024_mont_mul_18(t4, t2, p->z, p1024_mod, p1024_mp_mod);
  42307. sp_1024_mont_mul_18(t2, t2, q->x, p1024_mod, p1024_mp_mod);
  42308. /* S2 = Y2*Z1^3 */
  42309. sp_1024_mont_mul_18(t4, t4, q->y, p1024_mod, p1024_mp_mod);
  42310. if ((~p->infinity) & (~q->infinity) &
  42311. sp_1024_cmp_equal_18(p->x, t2) &
  42312. sp_1024_cmp_equal_18(p->y, t4)) {
  42313. sp_1024_proj_point_dbl_18(r, p, t);
  42314. }
  42315. else {
  42316. sp_digit* x = t2;
  42317. sp_digit* y = t3;
  42318. sp_digit* z = t6;
  42319. /* H = U2 - X1 */
  42320. sp_1024_mont_sub_18(t2, t2, p->x, p1024_mod);
  42321. /* R = S2 - Y1 */
  42322. sp_1024_mont_sub_18(t4, t4, p->y, p1024_mod);
  42323. /* Z3 = H*Z1 */
  42324. sp_1024_mont_mul_18(z, p->z, t2, p1024_mod, p1024_mp_mod);
  42325. /* X3 = R^2 - H^3 - 2*X1*H^2 */
  42326. sp_1024_mont_sqr_18(t1, t2, p1024_mod, p1024_mp_mod);
  42327. sp_1024_mont_mul_18(t3, p->x, t1, p1024_mod, p1024_mp_mod);
  42328. sp_1024_mont_mul_18(t1, t1, t2, p1024_mod, p1024_mp_mod);
  42329. sp_1024_mont_sqr_18(t2, t4, p1024_mod, p1024_mp_mod);
  42330. sp_1024_mont_sub_18(t2, t2, t1, p1024_mod);
  42331. sp_1024_mont_dbl_18(t5, t3, p1024_mod);
  42332. sp_1024_mont_sub_18(x, t2, t5, p1024_mod);
  42333. /* Y3 = R*(X1*H^2 - X3) - Y1*H^3 */
  42334. sp_1024_mont_sub_18(t3, t3, x, p1024_mod);
  42335. sp_1024_mont_mul_18(t3, t3, t4, p1024_mod, p1024_mp_mod);
  42336. sp_1024_mont_mul_18(t1, t1, p->y, p1024_mod, p1024_mp_mod);
  42337. sp_1024_mont_sub_18(y, t3, t1, p1024_mod);
  42338. {
  42339. int i;
  42340. sp_digit maskp = 0 - (q->infinity & (!p->infinity));
  42341. sp_digit maskq = 0 - (p->infinity & (!q->infinity));
  42342. sp_digit maskt = ~(maskp | maskq);
  42343. sp_digit inf = (sp_digit)(p->infinity & q->infinity);
  42344. for (i = 0; i < 18; i++) {
  42345. r->x[i] = (p->x[i] & maskp) | (q->x[i] & maskq) |
  42346. (x[i] & maskt);
  42347. }
  42348. for (i = 0; i < 18; i++) {
  42349. r->y[i] = (p->y[i] & maskp) | (q->y[i] & maskq) |
  42350. (y[i] & maskt);
  42351. }
  42352. for (i = 0; i < 18; i++) {
  42353. r->z[i] = (p->z[i] & maskp) | (q->z[i] & maskq) |
  42354. (z[i] & maskt);
  42355. }
  42356. r->z[0] |= inf;
  42357. r->infinity = (word32)inf;
  42358. }
  42359. }
  42360. }
  42361. #if defined(FP_ECC) || !defined(WOLFSSL_SP_SMALL)
  42362. /* Convert the projective point to affine.
  42363. * Ordinates are in Montgomery form.
  42364. *
  42365. * a Point to convert.
  42366. * t Temporary data.
  42367. */
  42368. static void sp_1024_proj_to_affine_18(sp_point_1024* a, sp_digit* t)
  42369. {
  42370. sp_digit* t1 = t;
  42371. sp_digit* t2 = t + 2 * 18;
  42372. sp_digit* tmp = t + 4 * 18;
  42373. sp_1024_mont_inv_18(t1, a->z, tmp);
  42374. sp_1024_mont_sqr_18(t2, t1, p1024_mod, p1024_mp_mod);
  42375. sp_1024_mont_mul_18(t1, t2, t1, p1024_mod, p1024_mp_mod);
  42376. sp_1024_mont_mul_18(a->x, a->x, t2, p1024_mod, p1024_mp_mod);
  42377. sp_1024_mont_mul_18(a->y, a->y, t1, p1024_mod, p1024_mp_mod);
  42378. XMEMCPY(a->z, p1024_norm_mod, sizeof(p1024_norm_mod));
  42379. }
  42380. /* Generate the pre-computed table of points for the base point.
  42381. *
  42382. * width = 8
  42383. * 256 entries
  42384. * 128 bits between
  42385. *
  42386. * a The base point.
  42387. * table Place to store generated point data.
  42388. * tmp Temporary data.
  42389. * heap Heap to use for allocation.
  42390. */
  42391. static int sp_1024_gen_stripe_table_18(const sp_point_1024* a,
  42392. sp_table_entry_1024* table, sp_digit* tmp, void* heap)
  42393. {
  42394. #ifdef WOLFSSL_SP_SMALL_STACK
  42395. sp_point_1024* t = NULL;
  42396. #else
  42397. sp_point_1024 t[3];
  42398. #endif
  42399. sp_point_1024* s1 = NULL;
  42400. sp_point_1024* s2 = NULL;
  42401. int i;
  42402. int j;
  42403. int err = MP_OKAY;
  42404. (void)heap;
  42405. #ifdef WOLFSSL_SP_SMALL_STACK
  42406. t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap,
  42407. DYNAMIC_TYPE_ECC);
  42408. if (t == NULL)
  42409. err = MEMORY_E;
  42410. #endif
  42411. if (err == MP_OKAY) {
  42412. s1 = t + 1;
  42413. s2 = t + 2;
  42414. err = sp_1024_mod_mul_norm_18(t->x, a->x, p1024_mod);
  42415. }
  42416. if (err == MP_OKAY) {
  42417. err = sp_1024_mod_mul_norm_18(t->y, a->y, p1024_mod);
  42418. }
  42419. if (err == MP_OKAY) {
  42420. err = sp_1024_mod_mul_norm_18(t->z, a->z, p1024_mod);
  42421. }
  42422. if (err == MP_OKAY) {
  42423. t->infinity = 0;
  42424. sp_1024_proj_to_affine_18(t, tmp);
  42425. XMEMCPY(s1->z, p1024_norm_mod, sizeof(p1024_norm_mod));
  42426. s1->infinity = 0;
  42427. XMEMCPY(s2->z, p1024_norm_mod, sizeof(p1024_norm_mod));
  42428. s2->infinity = 0;
  42429. /* table[0] = {0, 0, infinity} */
  42430. XMEMSET(&table[0], 0, sizeof(sp_table_entry_1024));
  42431. /* table[1] = Affine version of 'a' in Montgomery form */
  42432. XMEMCPY(table[1].x, t->x, sizeof(table->x));
  42433. XMEMCPY(table[1].y, t->y, sizeof(table->y));
  42434. for (i=1; i<8; i++) {
  42435. sp_1024_proj_point_dbl_n_18(t, 128, tmp);
  42436. sp_1024_proj_to_affine_18(t, tmp);
  42437. XMEMCPY(table[1<<i].x, t->x, sizeof(table->x));
  42438. XMEMCPY(table[1<<i].y, t->y, sizeof(table->y));
  42439. }
  42440. for (i=1; i<8; i++) {
  42441. XMEMCPY(s1->x, table[1<<i].x, sizeof(table->x));
  42442. XMEMCPY(s1->y, table[1<<i].y, sizeof(table->y));
  42443. for (j=(1<<i)+1; j<(1<<(i+1)); j++) {
  42444. XMEMCPY(s2->x, table[j-(1<<i)].x, sizeof(table->x));
  42445. XMEMCPY(s2->y, table[j-(1<<i)].y, sizeof(table->y));
  42446. sp_1024_proj_point_add_qz1_18(t, s1, s2, tmp);
  42447. sp_1024_proj_to_affine_18(t, tmp);
  42448. XMEMCPY(table[j].x, t->x, sizeof(table->x));
  42449. XMEMCPY(table[j].y, t->y, sizeof(table->y));
  42450. }
  42451. }
  42452. }
  42453. #ifdef WOLFSSL_SP_SMALL_STACK
  42454. if (t != NULL)
  42455. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  42456. #endif
  42457. return err;
  42458. }
  42459. #endif /* FP_ECC | !WOLFSSL_SP_SMALL */
  42460. /* Multiply the point by the scalar and return the result.
  42461. * If map is true then convert result to affine coordinates.
  42462. *
  42463. * Stripe implementation.
  42464. * Pre-generated: 2^0, 2^128, ...
  42465. * Pre-generated: products of all combinations of above.
  42466. * 8 doubles and adds (with qz=1)
  42467. *
  42468. * r Resulting point.
  42469. * k Scalar to multiply by.
  42470. * table Pre-computed table.
  42471. * map Indicates whether to convert result to affine.
  42472. * ct Constant time required.
  42473. * heap Heap to use for allocation.
  42474. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  42475. */
  42476. static int sp_1024_ecc_mulmod_stripe_18(sp_point_1024* r, const sp_point_1024* g,
  42477. const sp_table_entry_1024* table, const sp_digit* k, int map,
  42478. int ct, void* heap)
  42479. {
  42480. #ifdef WOLFSSL_SP_SMALL_STACK
  42481. sp_point_1024* rt = NULL;
  42482. sp_digit* t = NULL;
  42483. #else
  42484. sp_point_1024 rt[2];
  42485. sp_digit t[2 * 18 * 37];
  42486. #endif
  42487. sp_point_1024* p = NULL;
  42488. int i;
  42489. int j;
  42490. int y;
  42491. int x;
  42492. int err = MP_OKAY;
  42493. (void)g;
  42494. /* Constant time used for cache attack resistance implementation. */
  42495. (void)ct;
  42496. (void)heap;
  42497. #ifdef WOLFSSL_SP_SMALL_STACK
  42498. rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap,
  42499. DYNAMIC_TYPE_ECC);
  42500. if (rt == NULL)
  42501. err = MEMORY_E;
  42502. if (err == MP_OKAY) {
  42503. t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 37, heap,
  42504. DYNAMIC_TYPE_ECC);
  42505. if (t == NULL)
  42506. err = MEMORY_E;
  42507. }
  42508. #endif
  42509. if (err == MP_OKAY) {
  42510. p = rt + 1;
  42511. XMEMCPY(p->z, p1024_norm_mod, sizeof(p1024_norm_mod));
  42512. XMEMCPY(rt->z, p1024_norm_mod, sizeof(p1024_norm_mod));
  42513. y = 0;
  42514. x = 127;
  42515. for (j=0; j<8; j++) {
  42516. y |= (int)(((k[x / 57] >> (x % 57)) & 1) << j);
  42517. x += 128;
  42518. }
  42519. XMEMCPY(rt->x, table[y].x, sizeof(table[y].x));
  42520. XMEMCPY(rt->y, table[y].y, sizeof(table[y].y));
  42521. rt->infinity = !y;
  42522. for (i=126; i>=0; i--) {
  42523. y = 0;
  42524. x = i;
  42525. for (j=0; j<8; j++) {
  42526. y |= (int)(((k[x / 57] >> (x % 57)) & 1) << j);
  42527. x += 128;
  42528. }
  42529. sp_1024_proj_point_dbl_18(rt, rt, t);
  42530. XMEMCPY(p->x, table[y].x, sizeof(table[y].x));
  42531. XMEMCPY(p->y, table[y].y, sizeof(table[y].y));
  42532. p->infinity = !y;
  42533. sp_1024_proj_point_add_qz1_18(rt, rt, p, t);
  42534. }
  42535. if (map != 0) {
  42536. sp_1024_map_18(r, rt, t);
  42537. }
  42538. else {
  42539. XMEMCPY(r, rt, sizeof(sp_point_1024));
  42540. }
  42541. }
  42542. #ifdef WOLFSSL_SP_SMALL_STACK
  42543. if (t != NULL)
  42544. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  42545. if (rt != NULL)
  42546. XFREE(rt, heap, DYNAMIC_TYPE_ECC);
  42547. #endif
  42548. return err;
  42549. }
  42550. #ifdef FP_ECC
  42551. #ifndef FP_ENTRIES
  42552. #define FP_ENTRIES 16
  42553. #endif
  42554. /* Cache entry - holds precomputation tables for a point. */
  42555. typedef struct sp_cache_1024_t {
  42556. /* X ordinate of point that table was generated from. */
  42557. sp_digit x[18];
  42558. /* Y ordinate of point that table was generated from. */
  42559. sp_digit y[18];
  42560. /* Precomputation table for point. */
  42561. sp_table_entry_1024 table[256];
  42562. /* Count of entries in table. */
  42563. uint32_t cnt;
  42564. /* Point and table set in entry. */
  42565. int set;
  42566. } sp_cache_1024_t;
  42567. /* Cache of tables. */
  42568. static THREAD_LS_T sp_cache_1024_t sp_cache_1024[FP_ENTRIES];
  42569. /* Index of last entry in cache. */
  42570. static THREAD_LS_T int sp_cache_1024_last = -1;
  42571. /* Cache has been initialized. */
  42572. static THREAD_LS_T int sp_cache_1024_inited = 0;
  42573. #ifndef HAVE_THREAD_LS
  42574. static volatile int initCacheMutex_1024 = 0;
  42575. static wolfSSL_Mutex sp_cache_1024_lock;
  42576. #endif
  42577. /* Get the cache entry for the point.
  42578. *
  42579. * g [in] Point scalar multiplying.
  42580. * cache [out] Cache table to use.
  42581. */
  42582. static void sp_ecc_get_cache_1024(const sp_point_1024* g, sp_cache_1024_t** cache)
  42583. {
  42584. int i;
  42585. int j;
  42586. uint32_t least;
  42587. if (sp_cache_1024_inited == 0) {
  42588. for (i=0; i<FP_ENTRIES; i++) {
  42589. sp_cache_1024[i].set = 0;
  42590. }
  42591. sp_cache_1024_inited = 1;
  42592. }
  42593. /* Compare point with those in cache. */
  42594. for (i=0; i<FP_ENTRIES; i++) {
  42595. if (!sp_cache_1024[i].set)
  42596. continue;
  42597. if (sp_1024_cmp_equal_18(g->x, sp_cache_1024[i].x) &
  42598. sp_1024_cmp_equal_18(g->y, sp_cache_1024[i].y)) {
  42599. sp_cache_1024[i].cnt++;
  42600. break;
  42601. }
  42602. }
  42603. /* No match. */
  42604. if (i == FP_ENTRIES) {
  42605. /* Find empty entry. */
  42606. i = (sp_cache_1024_last + 1) % FP_ENTRIES;
  42607. for (; i != sp_cache_1024_last; i=(i+1)%FP_ENTRIES) {
  42608. if (!sp_cache_1024[i].set) {
  42609. break;
  42610. }
  42611. }
  42612. /* Evict least used. */
  42613. if (i == sp_cache_1024_last) {
  42614. least = sp_cache_1024[0].cnt;
  42615. for (j=1; j<FP_ENTRIES; j++) {
  42616. if (sp_cache_1024[j].cnt < least) {
  42617. i = j;
  42618. least = sp_cache_1024[i].cnt;
  42619. }
  42620. }
  42621. }
  42622. XMEMCPY(sp_cache_1024[i].x, g->x, sizeof(sp_cache_1024[i].x));
  42623. XMEMCPY(sp_cache_1024[i].y, g->y, sizeof(sp_cache_1024[i].y));
  42624. sp_cache_1024[i].set = 1;
  42625. sp_cache_1024[i].cnt = 1;
  42626. }
  42627. *cache = &sp_cache_1024[i];
  42628. sp_cache_1024_last = i;
  42629. }
  42630. #endif /* FP_ECC */
  42631. /* Multiply the base point of P1024 by the scalar and return the result.
  42632. * If map is true then convert result to affine coordinates.
  42633. *
  42634. * r Resulting point.
  42635. * g Point to multiply.
  42636. * k Scalar to multiply by.
  42637. * map Indicates whether to convert result to affine.
  42638. * ct Constant time required.
  42639. * heap Heap to use for allocation.
  42640. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  42641. */
  42642. static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g,
  42643. const sp_digit* k, int map, int ct, void* heap)
  42644. {
  42645. #ifndef FP_ECC
  42646. return sp_1024_ecc_mulmod_win_add_sub_18(r, g, k, map, ct, heap);
  42647. #else
  42648. #ifdef WOLFSSL_SP_SMALL_STACK
  42649. sp_digit* tmp;
  42650. #else
  42651. sp_digit tmp[2 * 18 * 38];
  42652. #endif
  42653. sp_cache_1024_t* cache;
  42654. int err = MP_OKAY;
  42655. #ifdef WOLFSSL_SP_SMALL_STACK
  42656. tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 38, heap, DYNAMIC_TYPE_ECC);
  42657. if (tmp == NULL) {
  42658. err = MEMORY_E;
  42659. }
  42660. #endif
  42661. #ifndef HAVE_THREAD_LS
  42662. if (err == MP_OKAY) {
  42663. if (initCacheMutex_1024 == 0) {
  42664. wc_InitMutex(&sp_cache_1024_lock);
  42665. initCacheMutex_1024 = 1;
  42666. }
  42667. if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
  42668. err = BAD_MUTEX_E;
  42669. }
  42670. }
  42671. #endif /* HAVE_THREAD_LS */
  42672. if (err == MP_OKAY) {
  42673. sp_ecc_get_cache_1024(g, &cache);
  42674. if (cache->cnt == 2)
  42675. sp_1024_gen_stripe_table_18(g, cache->table, tmp, heap);
  42676. #ifndef HAVE_THREAD_LS
  42677. wc_UnLockMutex(&sp_cache_1024_lock);
  42678. #endif /* HAVE_THREAD_LS */
  42679. if (cache->cnt < 2) {
  42680. err = sp_1024_ecc_mulmod_win_add_sub_18(r, g, k, map, ct, heap);
  42681. }
  42682. else {
  42683. err = sp_1024_ecc_mulmod_stripe_18(r, g, cache->table, k,
  42684. map, ct, heap);
  42685. }
  42686. }
  42687. #ifdef WOLFSSL_SP_SMALL_STACK
  42688. XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
  42689. #endif
  42690. return err;
  42691. #endif
  42692. }
  42693. #endif
  42694. /* Multiply the point by the scalar and return the result.
  42695. * If map is true then convert result to affine coordinates.
  42696. *
  42697. * km Scalar to multiply by.
  42698. * p Point to multiply.
  42699. * r Resulting point.
  42700. * map Indicates whether to convert result to affine.
  42701. * heap Heap to use for allocation.
  42702. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  42703. */
  42704. int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r,
  42705. int map, void* heap)
  42706. {
  42707. #ifdef WOLFSSL_SP_SMALL_STACK
  42708. sp_point_1024* point = NULL;
  42709. sp_digit* k = NULL;
  42710. #else
  42711. sp_point_1024 point[1];
  42712. sp_digit k[18];
  42713. #endif
  42714. int err = MP_OKAY;
  42715. #ifdef WOLFSSL_SP_SMALL_STACK
  42716. point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap,
  42717. DYNAMIC_TYPE_ECC);
  42718. if (point == NULL)
  42719. err = MEMORY_E;
  42720. if (err == MP_OKAY) {
  42721. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18, heap,
  42722. DYNAMIC_TYPE_ECC);
  42723. if (k == NULL)
  42724. err = MEMORY_E;
  42725. }
  42726. #endif
  42727. if (err == MP_OKAY) {
  42728. sp_1024_from_mp(k, 18, km);
  42729. sp_1024_point_from_ecc_point_18(point, gm);
  42730. err = sp_1024_ecc_mulmod_18(point, point, k, map, 1, heap);
  42731. }
  42732. if (err == MP_OKAY) {
  42733. err = sp_1024_point_to_ecc_point_18(point, r);
  42734. }
  42735. #ifdef WOLFSSL_SP_SMALL_STACK
  42736. if (k != NULL)
  42737. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  42738. if (point != NULL)
  42739. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  42740. #endif
  42741. return err;
  42742. }
  42743. #ifdef WOLFSSL_SP_SMALL
  42744. /* Multiply the base point of P1024 by the scalar and return the result.
  42745. * If map is true then convert result to affine coordinates.
  42746. *
  42747. * r Resulting point.
  42748. * k Scalar to multiply by.
  42749. * map Indicates whether to convert result to affine.
  42750. * heap Heap to use for allocation.
  42751. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  42752. */
  42753. static int sp_1024_ecc_mulmod_base_18(sp_point_1024* r, const sp_digit* k,
  42754. int map, int ct, void* heap)
  42755. {
  42756. /* No pre-computed values. */
  42757. return sp_1024_ecc_mulmod_18(r, &p1024_base, k, map, ct, heap);
  42758. }
  42759. #ifdef WOLFSSL_SP_NONBLOCK
  42760. static int sp_1024_ecc_mulmod_base_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
  42761. const sp_digit* k, int map, int ct, void* heap)
  42762. {
  42763. /* No pre-computed values. */
  42764. return sp_1024_ecc_mulmod_18_nb(sp_ctx, r, &p1024_base, k, map, ct, heap);
  42765. }
  42766. #endif /* WOLFSSL_SP_NONBLOCK */
  42767. #else
  42768. /* Striping precomputation table.
  42769. * 8 points combined into a table of 256 points.
  42770. * Distance of 128 between points.
  42771. */
  42772. static const sp_table_entry_1024 p1024_table[256] = {
  42773. /* 0 */
  42774. { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42775. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  42776. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42777. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
  42778. /* 1 */
  42779. { { 0x19c7ec6e0162bc2L,0x0637188544944dfL,0x17c27926760777bL,
  42780. 0x10da6b0430bab33L,0x10c5f8db9a96ea2L,0x1ae83300d763e9bL,
  42781. 0x15fe39cb9265633L,0x0b585ce52fa7d23L,0x18621db92da9f2fL,
  42782. 0x1936433ad2b3cf6L,0x0e177cb15aab052L,0x09a98d427f32466L,
  42783. 0x13ffa8ec11b88e7L,0x0f9fcff7890a58bL,0x19ed13a80e1a89cL,
  42784. 0x0692d7b36369d81L,0x00bafe528dceecdL,0x046fffcb50e24fcL },
  42785. { 0x0a4753ac03c0c83L,0x14e8c55e6e6badaL,0x0e23ddd6d925a39L,
  42786. 0x157eb1e6a5c7073L,0x1d0bc15c803f949L,0x194c612fb8133cdL,
  42787. 0x05dba16fd745a3fL,0x1687edd7b318d8fL,0x120618af445e3e1L,
  42788. 0x1eaacc72a732049L,0x1ca0ed413fb6799L,0x17fae1b0ea2f608L,
  42789. 0x1f3f5addbe450caL,0x1c65a66523eb145L,0x071242000dfbcc1L,
  42790. 0x1b06e9c291a78d6L,0x1f3e256d3294fcfL,0x01550903def1e00L } },
  42791. /* 2 */
  42792. { { 0x15b6dae01900955L,0x04e60e75a32b6d4L,0x041f9cbfa56e977L,
  42793. 0x0f40818668a18f1L,0x1952ea6ea1ae544L,0x04b982c88c89b83L,
  42794. 0x1443d53fdcd0db4L,0x0e149b600e97b49L,0x0fd5306f1916440L,
  42795. 0x05cff39c5922916L,0x036b59e127dd885L,0x143161b9a5c828dL,
  42796. 0x015e1ad49287b29L,0x0ddd150d56ebf8dL,0x088cde66b18ea07L,
  42797. 0x07790026f38b702L,0x161f402b2f0b0e5L,0x0461f593f85f89dL },
  42798. { 0x04ad3e1e513696fL,0x05d2e0c640ffd4dL,0x04d8f00cf44c0d4L,
  42799. 0x022f4a63783c5f8L,0x1aed610d53da6e7L,0x0ffab3a17632480L,
  42800. 0x144ab4cfa37dfa6L,0x1d7c955ae7c7bddL,0x0d983b465180f4dL,
  42801. 0x09b2934a817985aL,0x1e66aea24635fe6L,0x096ce01f8f34fc4L,
  42802. 0x1640bfd8c20ffe8L,0x0e9320debda2006L,0x098872f0e887485L,
  42803. 0x03d06f307288586L,0x110ace6500bb140L,0x03dfa0b1f128e21L } },
  42804. /* 3 */
  42805. { { 0x0174f88e3fd589eL,0x00bc86fcba5018eL,0x0f8cf9c1527f6d4L,
  42806. 0x1e2b249e69a12c4L,0x19b65ac58d091efL,0x14e167f77bce56fL,
  42807. 0x00af34b310988fdL,0x1bb02fb2064a59bL,0x1acf4f4d9a5f1ddL,
  42808. 0x030931aa808db5eL,0x112434bb4503274L,0x1d189b6d0da53eeL,
  42809. 0x16776b0fcc64092L,0x0f8b575b112f778L,0x0ef60a83a3007a7L,
  42810. 0x1c66ec506ce8309L,0x107757574e28956L,0x04c38f6e3382d3fL },
  42811. { 0x10b76d5776535f7L,0x06b01131ad9dc5eL,0x0b667485bd91485L,
  42812. 0x0eaa2b7eeb8184bL,0x1e9f1675fd4df3aL,0x1439f3925312de2L,
  42813. 0x17128f0d7bedd01L,0x115deb93467765cL,0x1a971b35e806b19L,
  42814. 0x1ae0652d1e34876L,0x17762638788d067L,0x199d2ab5b3c951aL,
  42815. 0x07248d34164cecbL,0x02e057b71767a20L,0x1e03ffc6aece045L,
  42816. 0x1daae7e97dd0438L,0x1add14df768c272L,0x01cbf68851b8b1bL } },
  42817. /* 4 */
  42818. { { 0x13e0bb2755c2a27L,0x1217cacac2e2267L,0x183c64a179834e3L,
  42819. 0x00ec4e7a1e8d627L,0x193c569ac3ecd0cL,0x08c0c53c0078428L,
  42820. 0x0d8efc139d2ad0dL,0x1fd24b15471092cL,0x08456617cb8c894L,
  42821. 0x1e31555157cb4d0L,0x08a02d6919a3662L,0x0b1d5325e9f4cd8L,
  42822. 0x193f401e99bc9dfL,0x0261c6072ed85beL,0x137dacf81853f87L,
  42823. 0x16c31aa622a3859L,0x0a41c7575ece143L,0x020123cc2efc9ccL },
  42824. { 0x1a251788f055746L,0x100200558f3707dL,0x13eeb0a49a5f16eL,
  42825. 0x12b69e8e81c3632L,0x1bb7ba547715211L,0x109cd2128048e84L,
  42826. 0x0a9f9e99d2186e6L,0x1dd75082767e6a7L,0x0afe771922443ceL,
  42827. 0x023469b1c23dde8L,0x1e7fd8f69250b45L,0x0383a84b68acc3eL,
  42828. 0x0d75ff46301563aL,0x159401649e1387eL,0x171c011081c8243L,
  42829. 0x05ce8d1e19b9790L,0x180ca4372fbfa03L,0x00d37e8f3645bceL } },
  42830. /* 5 */
  42831. { { 0x07a901a8d5116a3L,0x021ca597afa3fcbL,0x114983aebcec2e1L,
  42832. 0x0ec199f819c735aL,0x0c3f53f21e1be61L,0x088ddb5603f1e96L,
  42833. 0x0c30b760e38387bL,0x1708a8ea60e382bL,0x170dd4748920fe5L,
  42834. 0x1105f16f238c4b6L,0x1eb629649db1f06L,0x1987910ddc0e787L,
  42835. 0x176e831ac4026a1L,0x16280eb2cfedb79L,0x16a15d09a8d746aL,
  42836. 0x069ca15d3120a81L,0x15065dde0a4abd7L,0x014dbea6e0ab0a3L },
  42837. { 0x0b3c2cbcbf4e20bL,0x1aa47ac662262a2L,0x0d516c32b07c70fL,
  42838. 0x0a01f00c4273013L,0x066905e00c0f02bL,0x080c4673095c480L,
  42839. 0x1daca3c563b5e0dL,0x1c1803b88b07eaaL,0x129803272a45492L,
  42840. 0x1d2b11d07fc9221L,0x08ac00a7437105dL,0x08b24f01d0f5a25L,
  42841. 0x030d53f272b4125L,0x12180f468f5e7c8L,0x1f41e62eb9ba900L,
  42842. 0x024d83cbe7e5f46L,0x17e9342c31022b4L,0x02e84940129c124L } },
  42843. /* 6 */
  42844. { { 0x03a2b7eff2f780dL,0x134106bebb58eacL,0x011e1bdd2bb0d34L,
  42845. 0x0421047fd7c7865L,0x1b5e7bf40fd4221L,0x147c66913f20bf7L,
  42846. 0x0efb1443526da95L,0x16ea779cfac2f03L,0x19cfe3f222f3718L,
  42847. 0x1a2744fecef360fL,0x1154fcfeb26d55fL,0x108dcde60179e39L,
  42848. 0x029f0ae6b19d2d0L,0x125c5df04bb6415L,0x0e96a9f98f6fd78L,
  42849. 0x0678e9958fe8b2eL,0x05dc6eb623784ddL,0x00513721a0a17f7L },
  42850. { 0x081339facaa9a08L,0x18882a9237670c0L,0x05c184e4dd1d03cL,
  42851. 0x06485e05c312590L,0x1b5de98a8d8d410L,0x1df4a92415fe901L,
  42852. 0x0092627be51ad6aL,0x0f571a431726ed3L,0x1d5268e8966617cL,
  42853. 0x1173aa8c5be95c8L,0x11e5cffa359f0e5L,0x0a145602f8a258bL,
  42854. 0x1cc1a2946942e31L,0x098e3841b7a72f5L,0x1ee79428e644339L,
  42855. 0x015a15e9edd696eL,0x0ec68cbb175da12L,0x00ca4be30dc931bL } },
  42856. /* 7 */
  42857. { { 0x120b0c6417659a8L,0x15ce3c965947fb4L,0x0602da1de5ff1deL,
  42858. 0x03ceeb26c6ab6ceL,0x1561b1864caf58cL,0x07a4a328aadedb2L,
  42859. 0x02c80b9938d55e0L,0x0c1d615936e4535L,0x188594d782571bdL,
  42860. 0x0e6049cf1fd3c7cL,0x0d20c0ab0b4de57L,0x1ec1721e2888f71L,
  42861. 0x013ce4b3c1505fbL,0x0acdae0c5630874L,0x1a80888e693c9ebL,
  42862. 0x038f6bf4672e6f9L,0x1a6e578730b8dffL,0x04b5c8dc5a8bdfbL },
  42863. { 0x1a991f49aac087cL,0x17ba7367ed946e0L,0x1e697dd8035b398L,
  42864. 0x09f22ff39211adfL,0x1de52dbfd781cd0L,0x0b90c03bcb7afb1L,
  42865. 0x04df79f6d9380bbL,0x02c1e10edecdf48L,0x13271ee643ca1f7L,
  42866. 0x1cd902c3e255c51L,0x05c41ce520411f2L,0x121ab318b86f974L,
  42867. 0x0a6f20e125df9a1L,0x1a794816865b739L,0x18b73ee8c508813L,
  42868. 0x186a285a51972f9L,0x09ddf261b8aa3d3L,0x039f9e98ae7fe12L } },
  42869. /* 8 */
  42870. { { 0x186855be6fd3673L,0x1b857ce90a5bdaeL,0x1e437311b34cc26L,
  42871. 0x0ab2aa21bd1a665L,0x18c1251ce553c01L,0x060de4aba3504b1L,
  42872. 0x0ea3f35f3a96e17L,0x0f89ff428d0005dL,0x110a3cb7022fcd7L,
  42873. 0x14ccefde27502f1L,0x1683413be9d5badL,0x0f3db9dabfb066eL,
  42874. 0x03251fd56e4d902L,0x015262f8a40c920L,0x0d0416fa1d8ce92L,
  42875. 0x1caf062e1a26036L,0x1fa93998b0f7247L,0x04449a7b221b5d0L },
  42876. { 0x09f43b04713eabcL,0x1eec8d666e28bf8L,0x18efbc4f29f1329L,
  42877. 0x144b1030964fb54L,0x195dc2698b2e5a7L,0x1978a605465b096L,
  42878. 0x04d70d1a5d68b87L,0x1c63e5371dbc2e5L,0x0c3cbfd6ed40bc1L,
  42879. 0x1fa359f899311edL,0x16f9b7ec2dda074L,0x068aadb48689822L,
  42880. 0x18a8e43d985e31cL,0x05eeda7553e31f8L,0x153d631572c820dL,
  42881. 0x0d3b362d4187094L,0x0e174eacca246fdL,0x0068c4c5d8a9aa4L } },
  42882. /* 9 */
  42883. { { 0x0a73461e35ef043L,0x1b3ec9a4b5ab227L,0x1cef43e0e8f041eL,
  42884. 0x10a3a5386bac582L,0x11b1c1a4fad4b03L,0x1a1dcf1fa144153L,
  42885. 0x1d50d74af3d9952L,0x1838ef62b54557bL,0x15cb38a80dabe3dL,
  42886. 0x0fed0575240b39dL,0x05ad379ee43af85L,0x1c4a5791e7b10d3L,
  42887. 0x1637c4e42484f87L,0x0bd3d7ec56f681eL,0x132e4eb97b7999bL,
  42888. 0x1472301bb2b4543L,0x060a55cfd2546fbL,0x015ed58ee237c17L },
  42889. { 0x04de22bfa6fed61L,0x0c552e646eca73dL,0x17c41c488bd7291L,
  42890. 0x1fcb5fe6ee7c6e5L,0x0a738e6d06a4b44L,0x18f89b5e1685d3aL,
  42891. 0x0a444691c38757cL,0x10aefff2675c205L,0x08b380a50310c78L,
  42892. 0x19e01143c1fe2d6L,0x1a249511c9741a7L,0x1c2cb5908443d8cL,
  42893. 0x0fcfda6e8a878f0L,0x1c66955d4d1d78dL,0x1b43ab8060fb4ddL,
  42894. 0x0c82a659b7ac104L,0x120b3234661cbeeL,0x01a9f5c495ce080L } },
  42895. /* 10 */
  42896. { { 0x0fdcad610b5521eL,0x0da202973817864L,0x00363ff69270684L,
  42897. 0x1597e6d75ac604dL,0x0c10a2d7cdb9654L,0x1873f03dac6708aL,
  42898. 0x0a04c79747df798L,0x0ff197c7afacec1L,0x1eb35866b6480d7L,
  42899. 0x0394679bf81b10cL,0x0197b50aa29d5d6L,0x1e3b20d450e1babL,
  42900. 0x04a51f906b283f1L,0x0a1d90543cf11fdL,0x079dd53cab1ba0dL,
  42901. 0x02ddc9e16c6f370L,0x07d57fbc0d48400L,0x046d103b8f310dbL },
  42902. { 0x0855004ecce65ecL,0x0868fdba40c2f1eL,0x0f29e1e5eb49db4L,
  42903. 0x00efca955ac97cfL,0x1e0df0ff43444dbL,0x0843520bdb5864dL,
  42904. 0x1568e3f1095b015L,0x171f2a58877fae9L,0x0501e005a01c4edL,
  42905. 0x08b96fe252bf194L,0x0339394d75bb8f5L,0x1cb818ca1231b68L,
  42906. 0x07857561fcbaef1L,0x1a5112637428a2fL,0x103828b91a14da8L,
  42907. 0x007f8d351c44e1dL,0x15fb3f52247242bL,0x04317aaf161df5eL } },
  42908. /* 11 */
  42909. { { 0x16a390f226049feL,0x152bc6e5de4fd96L,0x12925d8d3edf324L,
  42910. 0x0c7bd4b1274a5fdL,0x0a49e9162b340cbL,0x0f20f9d1cf99c51L,
  42911. 0x1f9009acb7cf652L,0x1458e38f9b60cb4L,0x04a9b84a0468281L,
  42912. 0x1f75a81b98f7765L,0x0244d1db2edc958L,0x13537294cf19cdaL,
  42913. 0x1b808fd9f10cf97L,0x1057e2dcda26c61L,0x096f9a79836984fL,
  42914. 0x1ce9ea5b9cfbc7dL,0x1903a5d6864dc1eL,0x038d594489de403L },
  42915. { 0x1618fc43b5b60adL,0x1af18250618c267L,0x0732f100cc082beL,
  42916. 0x07b63818cda4470L,0x06112a8d33cf895L,0x0b3d434e4ca726dL,
  42917. 0x134a75eab8b0f46L,0x1f7851aa926b6f5L,0x18075bd136c9a57L,
  42918. 0x0e01b9f4e4213fcL,0x12863464c897d72L,0x1a2688580318597L,
  42919. 0x07fbb3a72773777L,0x0cb16e0c75f2f6aL,0x1022019c10df524L,
  42920. 0x1e6b9e7383c125bL,0x06503e9c6f715ffL,0x046843ddb2f1b05L } },
  42921. /* 12 */
  42922. { { 0x02123023fdc1844L,0x113f7882f562b5fL,0x181bc5a28d21bb2L,
  42923. 0x1bc3af499643074L,0x1ef5d43e295f807L,0x1812e3b92353193L,
  42924. 0x138fab850c8171dL,0x0ea97bf8f95e690L,0x0ec939895df52c0L,
  42925. 0x1732afb6bd4e560L,0x17f8822ebb76c20L,0x0fc8a4fbce6330bL,
  42926. 0x1c313de1ea79c81L,0x0627b65d986707dL,0x0ec833677e56e27L,
  42927. 0x1f603e55dbe3debL,0x1ecfc1e0a891a8cL,0x0112f69a531f6dbL },
  42928. { 0x013154dbabb1a85L,0x06d738f352b2d1fL,0x155aad2c403f4f6L,
  42929. 0x1dd78f1c35a642fL,0x08e73d37d44d934L,0x0f21e5810a990daL,
  42930. 0x02416ef242fe880L,0x1427847e3a04ea0L,0x02a2e5000c86691L,
  42931. 0x0595d693032c20eL,0x1072bcc009ad802L,0x05e8a4ed9cc22baL,
  42932. 0x0715932ffb1712cL,0x153a657900e261fL,0x014de91e25384f5L,
  42933. 0x192fc05adebbe18L,0x07ba8fb7602c2b1L,0x03095b072e8443eL } },
  42934. /* 13 */
  42935. { { 0x1d495cfba245d6bL,0x065dbd1671ffb77L,0x0b037fd7fbb973cL,
  42936. 0x119e518d4649b45L,0x0308a56b90c914fL,0x0b901a397eda86aL,
  42937. 0x127a40f6fdde44fL,0x1039f4bd9230455L,0x10dde73c83aea3eL,
  42938. 0x02dd4b13314489cL,0x1d922f29ab2f4d5L,0x0edd3140d0754a5L,
  42939. 0x0ca378ed52ff6f2L,0x042d60ec929b69dL,0x0f2129cd4f0b152L,
  42940. 0x082cf95fea5b401L,0x06e3971f81c3768L,0x007b99a70e96bccL },
  42941. { 0x1bb5c836596067eL,0x0a70c9c60cc0357L,0x059ce72c3730cf9L,
  42942. 0x1a84806bf3050bbL,0x1fef90952b53f43L,0x07ab8d1c6298fc6L,
  42943. 0x09e1e43efa3936cL,0x04134183da54739L,0x02fecc1d6606f26L,
  42944. 0x0e44858b95be5a5L,0x129bef32ede1a27L,0x0105fce7dc93867L,
  42945. 0x17fcb66c48d1b11L,0x0370a2b9ac85be8L,0x0fab6164d5ac29aL,
  42946. 0x061f6ebad05880aL,0x149b2ae55fac54dL,0x033b1b5397c5774L } },
  42947. /* 14 */
  42948. { { 0x18063bcb91d6beaL,0x11d17491f65cb31L,0x064b189eb29ab89L,
  42949. 0x14ef5f3cfd3af61L,0x04aafebbc6ed001L,0x02ad48490a56679L,
  42950. 0x126768d592e59e0L,0x14a01333639c04eL,0x1e413a4e1e46a06L,
  42951. 0x02e89fb1728f7f3L,0x01f4d26ea10efa8L,0x104a63062b3c6bdL,
  42952. 0x1a546019230a633L,0x1bfe8e793011f45L,0x1cbf54e6c41dc86L,
  42953. 0x15e708d6aa857fbL,0x165b314f4f81c18L,0x00437cc3b305644L },
  42954. { 0x07019548cbb9850L,0x05b98510696463bL,0x015d4cd59c31884L,
  42955. 0x0a064975d48109aL,0x076ee9b43ecdc59L,0x07fd32303fe2f96L,
  42956. 0x118f3ce4f403d10L,0x1cfc0222f2c5b82L,0x0f00b82519c7725L,
  42957. 0x0f3039b2de8e8c3L,0x015530b3dcaab0dL,0x1fbddf4692fbe7bL,
  42958. 0x0cf646ad11b4dd0L,0x0fbdc756eb89134L,0x01b7f941f082beeL,
  42959. 0x0a934c612d3a9f8L,0x01076b7df1c7245L,0x0340fca01f30d74L } },
  42960. /* 15 */
  42961. { { 0x0ad5163c9a0623bL,0x014abb3fd5c6a3eL,0x03b206bdf1f36feL,
  42962. 0x11d2cdab8459956L,0x10d4e41c469e38cL,0x159ace1a2186a97L,
  42963. 0x0049d0981d68a94L,0x082485ba7c6677aL,0x0cda3f6359fed23L,
  42964. 0x0f99b986bea97fdL,0x1d5bc1d9030fbd3L,0x0438377bcaf8bffL,
  42965. 0x0aeb8bb3364783cL,0x15684202ec3c251L,0x0d8af507b1f14cfL,
  42966. 0x1a95e96fe2847f3L,0x10a5543145c7075L,0x0064ef4a55d302cL },
  42967. { 0x0d7273595d5682bL,0x0214197613b76c7L,0x1b562cda8349c47L,
  42968. 0x090931511fa3e95L,0x0480f45162ab40cL,0x0e7ff12c647e312L,
  42969. 0x0d6762f23292edeL,0x0bb2156b078e034L,0x0aee31a733fd5d1L,
  42970. 0x152acbde489199eL,0x072b92db0f8f080L,0x085853270110203L,
  42971. 0x1df47c8199e5130L,0x195007490700141L,0x1d6b8ee435a3963L,
  42972. 0x06164d3c5be834eL,0x196b8d2eca5871cL,0x0399ee5075d8ef1L } },
  42973. /* 16 */
  42974. { { 0x1b495d04b59213aL,0x1901cc6b810077aL,0x0698ad9dc707299L,
  42975. 0x08573d619697961L,0x0cdba21226adeedL,0x044868f5aa23aa4L,
  42976. 0x11ad0386aff37c2L,0x070a4a132c6d31cL,0x1e1bff0b082e9c1L,
  42977. 0x0c4f266a884cd38L,0x0326f326e4731e8L,0x0fb826fd897c46cL,
  42978. 0x01d1519f6e9bd4dL,0x07c19281e81ab29L,0x1ba8ad2fd7db5e3L,
  42979. 0x06339c86020631bL,0x1d7c3132494ef4cL,0x01559dea3878fd3L },
  42980. { 0x153b680922c9fbbL,0x13ee4078b6368abL,0x04d6eb05bbf21a7L,
  42981. 0x0908da3b370688aL,0x12d62c214326a3bL,0x14956ada8bff71dL,
  42982. 0x0b04da416be882cL,0x11a54ae2634595bL,0x0cd904d8febdbcaL,
  42983. 0x1f6d4379f9b2fd9L,0x1ec82371faa8737L,0x150948bcef80e12L,
  42984. 0x0ccf5d118e89a35L,0x0fb74cf420bd031L,0x1e821f4f03012a0L,
  42985. 0x055a5888e096174L,0x0296f8a27d13ea2L,0x049d25a0b2613e9L } },
  42986. /* 17 */
  42987. { { 0x0271bc11f1efb7aL,0x1347319fe6606eaL,0x03c6c47d42a2b93L,
  42988. 0x1f5e0ec1133b379L,0x043d0e035430398L,0x11ea60a2f1217daL,
  42989. 0x0b425cfb09467dbL,0x01f56e1ef217537L,0x0de612ad5f9add1L,
  42990. 0x01bf2a70a74a15aL,0x095b4f76e2da2aeL,0x0678358548102ebL,
  42991. 0x10f0c80f94e85b2L,0x04c6da7cfc7fb61L,0x09f73752dfcfedeL,
  42992. 0x0712b458c089e8bL,0x163f3abb2f6fe3dL,0x01a16706b99773bL },
  42993. { 0x1261394cf491b1fL,0x1776b8c84f1caf5L,0x156a7f936fab72aL,
  42994. 0x1a927ac09bb9880L,0x1ce5ebef17a6611L,0x0c4e5add222d1d0L,
  42995. 0x0101ba0b8a1638eL,0x0ab72de850507ebL,0x099877b99a156cfL,
  42996. 0x1c83533270b3507L,0x074d4eca5db44ebL,0x1e4e6d8c34039d4L,
  42997. 0x13b0f55d86efc16L,0x0759a600ed82621L,0x1980a00f2d2c9a6L,
  42998. 0x07d8a71a0fef055L,0x12043ac3bcb43beL,0x022afa579f0ab7eL } },
  42999. /* 18 */
  43000. { { 0x057f262754ec21cL,0x06a64f1d0dd1c60L,0x034445b07fa4fabL,
  43001. 0x09d599156c74042L,0x0a6f32cae4ea4e9L,0x1cbae718e0064d7L,
  43002. 0x087a572d88e761aL,0x116ca9abb19429dL,0x1230d31f45067fcL,
  43003. 0x05dc865b1aaff65L,0x007b3b705cba392L,0x01519600ce6ef1fL,
  43004. 0x01e162d01228838L,0x02d78a2e0cd8170L,0x0b70d503821e81bL,
  43005. 0x180cde09b916f6eL,0x1b7f70ef2148de3L,0x0278a412189804fL },
  43006. { 0x0004fce6e2055e2L,0x123f543619033afL,0x16557e76aa8a278L,
  43007. 0x1f9d6fec769d797L,0x063784a0d15f212L,0x1b0128af662e0fcL,
  43008. 0x0a5514ece002dd5L,0x033d726038714d4L,0x00f16ba18a13cddL,
  43009. 0x189e928c43e1692L,0x08d6166a504fda0L,0x0bcdfc7faf8bf32L,
  43010. 0x1416e0ee0542340L,0x1fd6d55833c5759L,0x02111c47cef9eecL,
  43011. 0x05fecf203f45905L,0x10bc950db304d66L,0x03a6ae96a1e008bL } },
  43012. /* 19 */
  43013. { { 0x1002dc02b5bfe11L,0x1a086a96990f3d1L,0x1d9659e6ea241ccL,
  43014. 0x08d0b646dc2b241L,0x146f60400e248c1L,0x038bf8467d5aca1L,
  43015. 0x115da7d5ebedd03L,0x08e1b756518cc08L,0x10fa099689cdc32L,
  43016. 0x0f0157161187682L,0x185553916fbdd10L,0x13059c9af6de1b2L,
  43017. 0x075e62d22e9688aL,0x1e965d147d6f7d6L,0x1f1d27ebc544a9aL,
  43018. 0x0b4d6f10d1cc57cL,0x02988048d81ae9fL,0x0358d2a2162c2bdL },
  43019. { 0x15ab9ad43242066L,0x178da966651574fL,0x1b1e623b71382bfL,
  43020. 0x02068361ab63687L,0x150aab370d0c00fL,0x13254ca6b45c7bdL,
  43021. 0x1a13a6a3939bfceL,0x0b8330671f6fe34L,0x18bc0e748351a0fL,
  43022. 0x0567966ed62228aL,0x14e6657a7fddacbL,0x167e2c7260ab829L,
  43023. 0x05888d837654a01L,0x19193bd8b561f75L,0x076eefee1366a69L,
  43024. 0x0e2f132264d23c2L,0x0c8597717aeabb6L,0x026109a9345d8a5L } },
  43025. /* 20 */
  43026. { { 0x06fe0a695532833L,0x111476b13683397L,0x0f659279cef6af2L,
  43027. 0x15e0789818455deL,0x15169b452083a87L,0x083544f4aa73ae9L,
  43028. 0x13e415dd427b9d1L,0x12293964edc55d5L,0x108275d77fa409fL,
  43029. 0x0f5b79ef85deb5cL,0x080b2f904c9c118L,0x184363893163290L,
  43030. 0x08361fee5935f3fL,0x087028f9bb6345dL,0x039c10a8632ef65L,
  43031. 0x03d16470950f263L,0x134292abead80ddL,0x032b89e14ae1be1L },
  43032. { 0x0cca8e9ceb77b9aL,0x1f39391db4a34eeL,0x1b9a8075aca0be5L,
  43033. 0x1ab57d9bfd8ed57L,0x09290d703925203L,0x18a21c44a240411L,
  43034. 0x11f0fe64c5092c0L,0x04e08413be2f9a8L,0x17c6f2059c855c8L,
  43035. 0x0bebc312b607034L,0x16dbf904b653136L,0x0b23329883bab53L,
  43036. 0x01c89e21a319a64L,0x03501f87091a455L,0x05bfab35a412d43L,
  43037. 0x0d276ab82a2ad4cL,0x0384e36d1b57cc7L,0x035874cb61dd71eL } },
  43038. /* 21 */
  43039. { { 0x0789fabcceced00L,0x1f38d72dbd53319L,0x09a4b77af37cc8dL,
  43040. 0x016c3b5b1f0f65cL,0x135f803cb724512L,0x128786f08f2f246L,
  43041. 0x0ae4bed37d75e63L,0x07ac1dcd16979a5L,0x198ab2f5c1ce336L,
  43042. 0x0dd1ced3e6a1323L,0x15cbae0fd3ecfc5L,0x1d11cade11b634cL,
  43043. 0x1e172562c20f77dL,0x052c787a0ba1bb0L,0x1475b8af8d27fe2L,
  43044. 0x1e769c09b4e3709L,0x1f8368f03429e9fL,0x020115102b3c111L },
  43045. { 0x07bbd0583847375L,0x0b5b11fa28d7829L,0x09352cb1fc60eb9L,
  43046. 0x168a4b731ac331eL,0x0e0884b5ee323f5L,0x0963bb54ec69cd0L,
  43047. 0x1055340175fdbecL,0x179ae38907ce117L,0x18ca6fd28742541L,
  43048. 0x179ee66fc1cbeedL,0x14c494fb33c90c2L,0x0210b1b0371b701L,
  43049. 0x0171391f68c743aL,0x19ddb2bf9fa4759L,0x191f8c524ebfe20L,
  43050. 0x0f3ec3a2bdacc0fL,0x15610159b11e082L,0x01890bce5925354L } },
  43051. /* 22 */
  43052. { { 0x14cc3ca07615ac2L,0x12f32090d6ac0d4L,0x05be9e61ade6161L,
  43053. 0x173abc1e3b5c8ecL,0x1d9457ea395a40eL,0x1432ecd48a19321L,
  43054. 0x0ba32379b5a8fe8L,0x1960ee3b72c2029L,0x077a7cce6976a87L,
  43055. 0x1ef21708a1d07b0L,0x0f3027664f64d29L,0x0d2731d8987bc40L,
  43056. 0x183a25df4b92018L,0x115816b5ebbaa36L,0x169c6242b67ad1dL,
  43057. 0x04377f555e411a0L,0x1ea5238181f4312L,0x020beb63c399a88L },
  43058. { 0x0bd81b70e91e9a8L,0x0020c61b86b599eL,0x042a3aa88dcdccdL,
  43059. 0x08d8facead04bb6L,0x14c33ded8f2b09eL,0x0af1fdf144774dcL,
  43060. 0x1a22336109aec5aL,0x0c54c2ed90db9d3L,0x13f4c89226165e3L,
  43061. 0x0a7208fb031fd84L,0x1eb08323e781314L,0x0d39bfa55ac2d20L,
  43062. 0x048452199acef74L,0x09561a315d185d7L,0x0b520b4c1a04a4cL,
  43063. 0x0132a0237d0e792L,0x00aff4cbf89e833L,0x0010c4ea968a385L } },
  43064. /* 23 */
  43065. { { 0x1e419dd92599c69L,0x0110dbff6196539L,0x0f4826efeff56e5L,
  43066. 0x08c7db12b7657f3L,0x1f486f7961ea97aL,0x0a0d1cb3048a359L,
  43067. 0x104d6f471e817f4L,0x0f78f3d919f07acL,0x17f8fd42f988350L,
  43068. 0x1e5a9db8bd9e813L,0x1637359f296886bL,0x01599a292f0d0ccL,
  43069. 0x0e34b95067a6a6cL,0x0fa24ac60b79eb8L,0x0a00848dc48238fL,
  43070. 0x058e3a5bac9cdd8L,0x0fa33b2c4ab3078L,0x03ddfc55ea908bbL },
  43071. { 0x09e4aafa78b981aL,0x1a71b182764145fL,0x1ce4e5677a8de22L,
  43072. 0x064816738e188b9L,0x08383b7d70a9bddL,0x1d081324ce6bee9L,
  43073. 0x1c6ccc1a42cb8c1L,0x09044c5ab31dd25L,0x0c62d77deb4725aL,
  43074. 0x0b792de3de1d507L,0x162d97457bdfea8L,0x043a172dad1ec5bL,
  43075. 0x03a00f1906d9792L,0x15ba63a05c9442eL,0x15d888be91dae6fL,
  43076. 0x0a09e42fbb76b8eL,0x16bc2782c305788L,0x0430684b67c0938L } },
  43077. /* 24 */
  43078. { { 0x0bc337d4d79bbf9L,0x1f55c34fba7c07fL,0x0254cc41354d754L,
  43079. 0x1432df172ffe6d4L,0x15ce69092ab820dL,0x141baa4b0e9e8fbL,
  43080. 0x12e6ec65fb01011L,0x1474d19c37f274dL,0x1503456ffc5f021L,
  43081. 0x08516d8c4a07fedL,0x143e3fbc010826dL,0x02ee092cb0eaef8L,
  43082. 0x198bb8770ad635dL,0x103c729f392bb36L,0x1f20de23866c0a2L,
  43083. 0x073406c9a9995f3L,0x1201a3df411f0ddL,0x03f40722101d6fcL },
  43084. { 0x15f8a57539a1ddfL,0x073d7772432b125L,0x047605808787492L,
  43085. 0x17fa6da58838f69L,0x0aec00d92e7b871L,0x09f8d9ed1c5a820L,
  43086. 0x1e35bca09d84986L,0x066d387fd0df63eL,0x156c8b786e827acL,
  43087. 0x143fb639a43e47bL,0x1c885c677b96f05L,0x0e7ffe732831571L,
  43088. 0x14a9027c8004e84L,0x150e971479c2600L,0x197bbc6659efa6aL,
  43089. 0x106f90d2d0da7c0L,0x063737c6b08c7bdL,0x02ee55ae8cf45ecL } },
  43090. /* 25 */
  43091. { { 0x184283a9a7d772bL,0x0f292f2a04acd83L,0x002219052ad5ad2L,
  43092. 0x053ae96552a8d76L,0x003b0b1bd444816L,0x09fc35933c48569L,
  43093. 0x00f1c79ea0af323L,0x19e26a57f6bb0b5L,0x1f29f16e3fad07cL,
  43094. 0x01531dc20f0621fL,0x1c8b15acde7fbf0L,0x0ca762489e4d209L,
  43095. 0x1f3a28bdea19d8aL,0x1b6a2ae7331adb6L,0x1fcdcd462da2147L,
  43096. 0x17b56e958503139L,0x098ad40f9df8b2cL,0x0046616cf56e4eaL },
  43097. { 0x06a6866c170c84bL,0x04f45ad24d24217L,0x03834132264aee6L,
  43098. 0x10c3674846f61c0L,0x10d0189955ad347L,0x0806599e4a92285L,
  43099. 0x1db438e4885578cL,0x0a6324cb6dde064L,0x00fe8595a76d42bL,
  43100. 0x14b6f707e31a9dbL,0x18372091be24f82L,0x057de14e9974ec3L,
  43101. 0x043fdfad9b4ec90L,0x07edb4bab080434L,0x1dd642975a98391L,
  43102. 0x0146e7ea75590fdL,0x1b0d29e6be01287L,0x04c8fd6e0aad52aL } },
  43103. /* 26 */
  43104. { { 0x0bc4b0fb4844ffeL,0x1138a307c5c38c1L,0x0389338fc7cdce4L,
  43105. 0x082c6a33d915800L,0x08288b5ff0d548bL,0x0e4d383d57c215cL,
  43106. 0x1f59e7a2c3130afL,0x18740daa2a4974bL,0x0d0b1afa0f93cdeL,
  43107. 0x004aadd6fc4fc78L,0x0fa4b7ba8cb248aL,0x1f327fc0b7c90d9L,
  43108. 0x15fa6919aa0cae3L,0x17078dc5f930384L,0x1b3e6203d51d079L,
  43109. 0x123ae55da3ee861L,0x1e99296f76b7349L,0x03367c69412cf87L },
  43110. { 0x101905b226f5868L,0x174460b484f4f4dL,0x045928dfad53040L,
  43111. 0x119302c64657a11L,0x06bac53cf72253eL,0x15557b9bfc274ecL,
  43112. 0x011b8b8d49152bfL,0x05ccf90deee5940L,0x086bce50e666337L,
  43113. 0x151d4b05b4a8502L,0x06535ff06aea4fdL,0x02578264dcdcc3fL,
  43114. 0x042e56b0051957cL,0x02c93a064db2c7fL,0x1fc9a96734a5ff2L,
  43115. 0x05d76eca99d362eL,0x048aaa699dba79dL,0x02fe5062d0765b2L } },
  43116. /* 27 */
  43117. { { 0x06e25f3569a6663L,0x0bf73f3552653f1L,0x169a3462e030256L,
  43118. 0x0a4524ce604b499L,0x07387209450602bL,0x199d29cd7afb280L,
  43119. 0x0a547fbbb6cd099L,0x1341eb9ced10caeL,0x1872a360b8398aeL,
  43120. 0x01a3d4015987b61L,0x04ec8c685885618L,0x1f25dcd8dbd9a42L,
  43121. 0x085cbcf9e66fd9cL,0x15d1ff4242f852dL,0x1b35c9f5e969b90L,
  43122. 0x0342155fcce40a3L,0x0b4e09c6bb2a208L,0x032bd65f85cb9d8L },
  43123. { 0x130466fc274c8d4L,0x128bb1854ca6898L,0x0329c1e50d7d09dL,
  43124. 0x0dd712f40c42e4bL,0x161ee1304485040L,0x0bbc5df9c6ff772L,
  43125. 0x0e7a447d3eb3ea8L,0x064ecb8cc2f7357L,0x1b135499bd8f109L,
  43126. 0x075b19bd39dc8acL,0x0733c5bdfa2dab0L,0x007430fbdea7e58L,
  43127. 0x09830b9c625b32cL,0x1788729c44d68eaL,0x17d56f05cd7ab8cL,
  43128. 0x1b61b6397b3853aL,0x1bb42428c47e539L,0x01e96d209642959L } },
  43129. /* 28 */
  43130. { { 0x1702b6e871f2865L,0x1b1cf8a14906b4bL,0x0a8116d618455b2L,
  43131. 0x03e7627024650a4L,0x112206e8f3943adL,0x06acf5736110053L,
  43132. 0x1dd670a24396a8dL,0x0cf56a5fa81ed6fL,0x0f522c8de180bf5L,
  43133. 0x00f4bd9566771cbL,0x1d606713a972ec6L,0x0bd156a3a7dfc06L,
  43134. 0x0abcb50fd80d998L,0x0bf0e406f1364b6L,0x058d5f7ee75ac4eL,
  43135. 0x18ff6b0563029efL,0x06189a7822107f4L,0x001577796e01abfL },
  43136. { 0x1a7926f2c7ec9beL,0x1983f392c590095L,0x08431be9ad28a4bL,
  43137. 0x13c5798b56e9cc5L,0x1bb8c07380c0854L,0x0f8ca6da0b06dc3L,
  43138. 0x12a7357bc14a4caL,0x1a21d71b428dbb4L,0x00b5d43d215ea23L,
  43139. 0x075f7817e1a5fd7L,0x0d9342121d5e9dbL,0x06d05a69994759aL,
  43140. 0x021d2d95e2c1401L,0x1c37551404e533aL,0x0597fb30ff475b9L,
  43141. 0x124073d6226db45L,0x0b048871baac077L,0x035a23600a58ad7L } },
  43142. /* 29 */
  43143. { { 0x019eb2e25e8fe80L,0x1bc834c11c50be4L,0x065a07906124ad7L,
  43144. 0x0d31d4da8bade3dL,0x1fd02e4058ad8adL,0x0920b6add72d6a5L,
  43145. 0x1f28405b70c9ea0L,0x1231663530b4668L,0x10b4da61082a653L,
  43146. 0x05c8d96da461afdL,0x1a05f34aabe3107L,0x09079bfb9b813d2L,
  43147. 0x0112b692541a630L,0x1c51504bb82ac9bL,0x1314a057f735c4bL,
  43148. 0x0c12ab356c4746bL,0x12f30c8ebe0932bL,0x04309a125d84702L },
  43149. { 0x0902063b2231d8aL,0x11194ecd30b3394L,0x1f9c1c6a7c9ec3dL,
  43150. 0x00c07e08fd55f41L,0x1d92a1c36bcd896L,0x0a41db08c6653b7L,
  43151. 0x14988d05398adc7L,0x0b5424799bb74e0L,0x11a576437fd9b5cL,
  43152. 0x0980de1264687d1L,0x02b51040909f369L,0x0bc1a754d8052deL,
  43153. 0x00072a39960e6fbL,0x02069fd6e6c6244L,0x047550536bf284aL,
  43154. 0x0e69a53e9947bbdL,0x17c0037c5988441L,0x043199d4cce67f2L } },
  43155. /* 30 */
  43156. { { 0x013a751ecf53b40L,0x1637917bc52a169L,0x038bc4eb95b73fcL,
  43157. 0x1e1cc2e91c1eb3eL,0x172c414591f8ccbL,0x0e6e5b8556f65ceL,
  43158. 0x1f1c1acbb614932L,0x0051c016e583d5fL,0x089b24285aa7281L,
  43159. 0x13f53f05b3ce57dL,0x0e30993c29bdbeaL,0x02e61d00872eba5L,
  43160. 0x05c85730497ed7bL,0x04c3749f2d49f5aL,0x08302bf24afd750L,
  43161. 0x1875ea4d6b538d4L,0x0c90adf47c9b99dL,0x009592ff15d1016L },
  43162. { 0x1b8d78a33eea395L,0x09b0c7b19fe2e04L,0x18a49c3b3bbf1eaL,
  43163. 0x118c51da18fd042L,0x01d68939524779bL,0x176e4848edae50dL,
  43164. 0x1cefe189b863961L,0x039fc047d17fd67L,0x06279fde1025017L,
  43165. 0x09763ee2af0b96fL,0x1a1a571b5329179L,0x10f17b7821e288bL,
  43166. 0x086fc3835e42de3L,0x1f085b291588a6fL,0x039e3fa7eae9159L,
  43167. 0x015948223b05472L,0x174576b61c2aedfL,0x010b13cd4ba5665L } },
  43168. /* 31 */
  43169. { { 0x14cdabf4047f747L,0x1119ee098ad0f60L,0x0f4d0397429c0f2L,
  43170. 0x13768270d2b3cf9L,0x0f01fbd81fd0c4eL,0x15c11e8c4e84588L,
  43171. 0x002854112710a9dL,0x1c9038449427316L,0x108084e4f8e8179L,
  43172. 0x0c57cca34c720f4L,0x038df15842fcbbfL,0x087f4fa4f21e3c6L,
  43173. 0x0cb31953884e6a0L,0x01bccefececb730L,0x1fe40bf9d7e61b4L,
  43174. 0x082dc76951e23f1L,0x15efa9453787588L,0x010341f1fcc13a9L },
  43175. { 0x1582e26d0378878L,0x0a611d3ca2bc3e5L,0x02fe3d9a22ce788L,
  43176. 0x0a80a2a4e027a00L,0x00111f5d7548d4fL,0x1ffc813889e0aeaL,
  43177. 0x11730efd6949aa2L,0x00b7b4d60213692L,0x183dcc74ebc2f3aL,
  43178. 0x177b14221f7efd0L,0x183ba559716fd0aL,0x021ab25e4875a5cL,
  43179. 0x121bc3bf514f0faL,0x102bb53a3572c59L,0x1cc206a04ec21a1L,
  43180. 0x1dcb2178047f09aL,0x1959fd03aa032dcL,0x02f20b5fa93eb63L } },
  43181. /* 32 */
  43182. { { 0x0313760026cc23cL,0x0d5775ad9482c12L,0x0be3174bb85fe06L,
  43183. 0x17dcb988055244eL,0x17def07d8048e7cL,0x17c10f6de3eb773L,
  43184. 0x0ee25875a4913daL,0x148bef2cddb32d9L,0x0f81b17ea96a155L,
  43185. 0x16cf7b801f9f6abL,0x19641ba20a96cacL,0x00e55d28e300bcdL,
  43186. 0x11658c76f486fa1L,0x0581ad501a6cfe2L,0x0f992067d80f703L,
  43187. 0x153df6f673fd6ebL,0x1e3ca87554acf04L,0x027fb417643da7eL },
  43188. { 0x125627fd0a10ad5L,0x02e394b4737a298L,0x15ae01a8458dff5L,
  43189. 0x1bbca067c653037L,0x1f4f8988b92de1cL,0x13f0ee1da25a2f5L,
  43190. 0x161e3286e625b6bL,0x08ea42cdcb40ef1L,0x182d472bea51168L,
  43191. 0x1ee9c157944aa22L,0x14580975bb1327eL,0x16396caa560445dL,
  43192. 0x13a1e6210f3614eL,0x010d3a53b1e2efbL,0x172f537a4580a14L,
  43193. 0x1c533489948018cL,0x07c48cb187e0f15L,0x028f5c0c71a0128L } },
  43194. /* 33 */
  43195. { { 0x1c1d178b92100abL,0x11eb04b02dc1c8fL,0x0956dc7967437cbL,
  43196. 0x0a29f97c08254f8L,0x19fd06af3f8b667L,0x01068387451c9aaL,
  43197. 0x1ef9558c9940848L,0x0a8cd2df9a2a51cL,0x16588514b0c7b76L,
  43198. 0x06c07c62c8952daL,0x1fbc13cc932dfc3L,0x1d9f8db47aeb175L,
  43199. 0x1831d1df2f6b53eL,0x19c095b6f6f7a46L,0x18980c7ccdae595L,
  43200. 0x1e137905d5c95dcL,0x07f300abd32d244L,0x045857caa98ecb2L },
  43201. { 0x170180a2e603544L,0x19d61910d66cf5bL,0x19958901c0c8ad5L,
  43202. 0x1b7135787a742feL,0x1793225aad3e74aL,0x012b25c51e971d6L,
  43203. 0x14ad515eee813bcL,0x1d110eaca5ff85bL,0x0d2905d15e67143L,
  43204. 0x0c425a1017246b8L,0x0648671d8da95dbL,0x08426bc6f1be0dfL,
  43205. 0x1d10c64a02a8dc3L,0x060abd334ae0eb9L,0x0928d5335a93b3bL,
  43206. 0x0653b75b983911cL,0x0d08024f1b29839L,0x029b1f2a4a6d245L } },
  43207. /* 34 */
  43208. { { 0x15523b7e23fc641L,0x07397c33338318fL,0x17d6380274bff95L,
  43209. 0x1f18afebc252942L,0x116d64dcf203997L,0x1517fdd114b9265L,
  43210. 0x03b59a5ef93f52eL,0x06c7ea0fc8c14ddL,0x00afe3a5d785085L,
  43211. 0x177b66ecaa04104L,0x1f6227cb108df3bL,0x1074b870a4a6e03L,
  43212. 0x0d72a212f1496d8L,0x0ffbc7e6f12e33fL,0x1bd05192d059e0cL,
  43213. 0x00d2fd32ce00982L,0x0c3fa45c3a1c45bL,0x03199a00c1fde98L },
  43214. { 0x1c9a0cca2fbbbceL,0x1b72e55065ba21cL,0x0438d0e3b38e1dbL,
  43215. 0x1c27005b0539cc0L,0x1cd45a1b0aad148L,0x07e0f04e1f2e304L,
  43216. 0x137421d72e165efL,0x057633fef21b0b0L,0x12598b81ed81c2aL,
  43217. 0x0c5ef97815f03f1L,0x1f23bae5d973a44L,0x1b11649f2b5c0e9L,
  43218. 0x1c0c98f09d125e9L,0x105ba5939dd8966L,0x001df3929abb81eL,
  43219. 0x004de8e47a5f381L,0x173959447d6bea8L,0x049d383ae0b1405L } },
  43220. /* 35 */
  43221. { { 0x0bbefe2715b27f9L,0x0d2f11514049193L,0x0ebff56289aaa4dL,
  43222. 0x0cf8270d28bbbe4L,0x092a215354c83e1L,0x0684faa23ccde4cL,
  43223. 0x1a9a139b91c426eL,0x16d8c75ec2dab11L,0x05e896706883ab1L,
  43224. 0x009c9d01e90499bL,0x1ca4864b08f768fL,0x16f5b9edd487a05L,
  43225. 0x08791559e1ab70cL,0x16b87f858921a75L,0x0cae914101a036dL,
  43226. 0x1971e3421fca450L,0x1fdd69f9c08e5f0L,0x00d3a11562258a0L },
  43227. { 0x1a9dd2e9f40b675L,0x03301fe638f9ce1L,0x098465238d08a9fL,
  43228. 0x11da15690831273L,0x0e31ca6b8f3b615L,0x146db1d1d53ecbfL,
  43229. 0x18b92f07a197bdeL,0x01e62bf181258f8L,0x1a260788f9f5c6dL,
  43230. 0x0c19894a5b79f62L,0x16f358dad36126cL,0x112178d33536e75L,
  43231. 0x182a1175e766e14L,0x1e29e527df9bc86L,0x1fd8245fd0d816bL,
  43232. 0x1056caefed88f0fL,0x19c827c7552600cL,0x004a26b184e92acL } },
  43233. /* 36 */
  43234. { { 0x1deb63ee6ab9620L,0x07d36bc366c0467L,0x1609158c82cf7fdL,
  43235. 0x058928722a28bdbL,0x173b3f872ae5f86L,0x17cbd4ca847409dL,
  43236. 0x06d88ef6017cf94L,0x1f9ee36b8519305L,0x0b394c70e86e0ceL,
  43237. 0x1a7d8d491ded9b7L,0x1d618b6f89f9694L,0x1be70756c2d3ac9L,
  43238. 0x1127c828cbbae23L,0x1d183d456eb6f8dL,0x0777d986406267cL,
  43239. 0x076ee6d990cb302L,0x176a3cb77747994L,0x03ec4f9c1b7ec32L },
  43240. { 0x0564242c9f92b2bL,0x0353ae237195efcL,0x02ddfe669715c03L,
  43241. 0x1006292ad127cedL,0x02ce6709b6efe85L,0x176249ddff450ceL,
  43242. 0x10a35c868ec6fb9L,0x03a4ddddd5386e3L,0x1d798115e15177eL,
  43243. 0x1df9de7583452d2L,0x1688811b4ad2cb5L,0x12b6b37d3bf9bf1L,
  43244. 0x1c77640b793df09L,0x0d15e9e2e4b44bdL,0x0bf9d133833d309L,
  43245. 0x013762de8badd13L,0x0e6b53f3acb3a85L,0x0224d7c0fb1f953L } },
  43246. /* 37 */
  43247. { { 0x0fcf132a16d9377L,0x1bbd9bf0d17cf61L,0x04ba1b466b966acL,
  43248. 0x0da0277762e5c34L,0x0b5f66bad2b12e6L,0x0f55a804b9702aeL,
  43249. 0x17b0b44778700e6L,0x12783e629fb8cbeL,0x0fc3118418a9ff5L,
  43250. 0x1b9e0f670292373L,0x144d8c589415b77L,0x17aedf64bc33851L,
  43251. 0x04845cd2d730a9dL,0x09b74296824f692L,0x0322a0f1de6e0ffL,
  43252. 0x100670b46bf8fedL,0x0f5299bf1e1c95eL,0x007430be190448dL },
  43253. { 0x172060267c81b5cL,0x04ee6f39bc39e29L,0x02c2a0513f40beaL,
  43254. 0x0e4c41190654e86L,0x18ea40f53006c5aL,0x1209d2270333306L,
  43255. 0x0527e774097e625L,0x1857be701988d72L,0x1801566190a125cL,
  43256. 0x06b51dba93c9e1bL,0x004dd1ade98bc81L,0x04d0b0bab2f16c0L,
  43257. 0x188395fe66a9cfeL,0x035930fb6e56865L,0x0764862ead1a3f1L,
  43258. 0x04805941debdf3bL,0x087c507d4a85e45L,0x037a2027899367bL } },
  43259. /* 38 */
  43260. { { 0x1e1920b4febd3ffL,0x11a6c7efe95dd51L,0x1cab866a60a7298L,
  43261. 0x018deb78416fa35L,0x1aa39ca923de161L,0x063855f1026df9eL,
  43262. 0x0dc2ca8b7a6e1b6L,0x01c4e5c186ef93aL,0x080914c06e56551L,
  43263. 0x108f3d42be5db58L,0x1f1bbf6099a9badL,0x09dc612b00380edL,
  43264. 0x02b9e24063dfac3L,0x1c3d52e2b4ffa05L,0x11c334a9ee8c6a5L,
  43265. 0x1e0e81c9a3fbe67L,0x1e2903e31326895L,0x0482bb8fc3fdb38L },
  43266. { 0x199ba0da4062beeL,0x191c64a6becfca8L,0x06f078248b00639L,
  43267. 0x03625b0abfea7e5L,0x0d68ca29de9b2a8L,0x0604bfb24f9f76bL,
  43268. 0x0628192b7f0d314L,0x049032c95733b67L,0x000d59c477a5872L,
  43269. 0x0ff51cb3a62c81dL,0x1f63b85410f7402L,0x14dcbe3d9840d55L,
  43270. 0x030db9b7b4c5721L,0x13646a955b6b524L,0x120a89c1bff185dL,
  43271. 0x1ef507bc483ad59L,0x0cc0605f05227f2L,0x035114a9db2026fL } },
  43272. /* 39 */
  43273. { { 0x0452d8f74fce389L,0x11a60157d2ab249L,0x12efc3b5e094165L,
  43274. 0x166ee31c1b26ef9L,0x1fa69a4d89f4045L,0x0ad85d0883a73ecL,
  43275. 0x1b79975c2ec1dcaL,0x0f7645aa95be20fL,0x15c39a3d8a1a29cL,
  43276. 0x191b6016bcaf1d5L,0x00b400ad626544dL,0x0b7caf217dc5ee5L,
  43277. 0x11a8e65ea25e226L,0x1000e75ec8f0750L,0x071500839c69c21L,
  43278. 0x0d3022d201eb458L,0x027c3b2d5c0357fL,0x029464f5030cf1aL },
  43279. { 0x0dc86b45f26c577L,0x1a3844a1c5ea28fL,0x004de4960a9fe01L,
  43280. 0x01bc3cad3e5bfc2L,0x1a55a356e08eacaL,0x0bb10b2fca977d4L,
  43281. 0x1c7ca93602d4f92L,0x1e1a56cb0ab9abaL,0x0246704bf66cea3L,
  43282. 0x09fb20fa49191e5L,0x0615726b6c4c946L,0x059c5a33aca54d0L,
  43283. 0x105b82ed7b86d52L,0x070a8694a9b04f8L,0x04fa244ec3c0252L,
  43284. 0x16892475b17f616L,0x157cbb1556cf794L,0x01007c849b9c5e7L } },
  43285. /* 40 */
  43286. { { 0x1b22fc58388387fL,0x178b8147441e2fcL,0x0e4346de5cf33c9L,
  43287. 0x05edd922e288f95L,0x030cdbc08d5d4eaL,0x111e15970b7a4c6L,
  43288. 0x11517724a443121L,0x161d629236061b7L,0x0631deb2e14de21L,
  43289. 0x051083317f4187aL,0x1a5e70de707cfc1L,0x16d1f60d4f2b498L,
  43290. 0x1a1619dfa98a732L,0x06df164d9d22193L,0x0627faa468c1f4eL,
  43291. 0x0663f273791a407L,0x1dc3daabaf20f4aL,0x02e183f4c6e87aaL },
  43292. { 0x1c4e0c435b233daL,0x14842917b7cc2ddL,0x1486a2c091a38f4L,
  43293. 0x1352d22dcf33ba5L,0x014bcced978f40eL,0x083b160193ec363L,
  43294. 0x1cbb657a5540acaL,0x0661ffa432f50f3L,0x0c436513750e0bdL,
  43295. 0x1618a450413e262L,0x004aa0ff3f02c89L,0x02fc63250b138f3L,
  43296. 0x1e8830f42dc3d8dL,0x0583fc1fc5ab967L,0x144523df367fe49L,
  43297. 0x1f358663952a014L,0x185d0c539684c59L,0x00ef8b6fd60a1a3L } },
  43298. /* 41 */
  43299. { { 0x07bb4ac68bcacc3L,0x169a7a187ac67e6L,0x1d3f518615681b7L,
  43300. 0x088b93e1798b3f3L,0x0375c892f549199L,0x02cc1d6e2fbf632L,
  43301. 0x1421c6e1c23c4f2L,0x01f6654b98905f9L,0x1efdcdc352d6b4cL,
  43302. 0x1d9278245637d96L,0x0b53d4ce4191c52L,0x0a5f70747588b30L,
  43303. 0x082337a223162ebL,0x05e1ede9b8986f9L,0x19eb03b739ee00bL,
  43304. 0x0e2fd1672b2b248L,0x01721d3d2e81b56L,0x0394d3fa8232893L },
  43305. { 0x14ed1aa8420f90aL,0x070cf07f2642ac3L,0x0aaac2f9d2bd8daL,
  43306. 0x01194c19536c5a9L,0x1645a86776fcc48L,0x18d92679885ad2bL,
  43307. 0x16d104c6eb26f76L,0x09ddeefae3a5bd4L,0x04706d21072fcc6L,
  43308. 0x0dc9348b39ebbf8L,0x002fcfa278198caL,0x19a6e80efa8045cL,
  43309. 0x0d829232e2472d0L,0x1c6e42999f10820L,0x0e3d99cbe45b7ecL,
  43310. 0x1c33a91776b3629L,0x15c19de9f4ad44bL,0x03fb69b249196ceL } },
  43311. /* 42 */
  43312. { { 0x1d064de6e794819L,0x1b4a77c175ed09dL,0x1f82e478a01169aL,
  43313. 0x060f4879a43e02fL,0x030433e9190d31fL,0x1fee5a361379133L,
  43314. 0x04702e9222a9c2aL,0x100831b210b48c8L,0x11b934fe6bffb58L,
  43315. 0x0e8f11bf1007c24L,0x1358fe95504f6ddL,0x1aebc4767eefbe0L,
  43316. 0x0b0f91bd30e216eL,0x1b94e284d02c336L,0x0aacb5e130e5765L,
  43317. 0x1ad0dd92fc3108aL,0x06c8cb7c1f90093L,0x0168191cab14784L },
  43318. { 0x01c94074a44b4c5L,0x0343ce638164c54L,0x0a1f3ac3725ee61L,
  43319. 0x0cdc75464396a04L,0x04c256c23030112L,0x0da422e05643b1fL,
  43320. 0x1cd6d940d348395L,0x1b9552d4081e481L,0x0046d26d37cf7eeL,
  43321. 0x152d4709dc0832bL,0x112e5e0f5c30ad8L,0x1f10b3c9b51f0c0L,
  43322. 0x1a5457f5d12fbafL,0x1a98dbabc94ec80L,0x13a5ce74a787acaL,
  43323. 0x137b2429b57b93cL,0x19b5bd724fc4eaaL,0x039a609598f7cddL } },
  43324. /* 43 */
  43325. { { 0x0fe3c2e92f9b086L,0x0dc9f59fea2a24cL,0x022d700b1971190L,
  43326. 0x0389e064848f9c4L,0x079d29f68a52dcaL,0x037afa5af60becbL,
  43327. 0x0a044474bfb4250L,0x07e4c1ec7b81b37L,0x0de2b056f15472aL,
  43328. 0x18b86cf80394873L,0x08fa36dad723e46L,0x10739e6987dd45cL,
  43329. 0x011b973ee2345a2L,0x1d9268e2cdee2a3L,0x185068596f69b0aL,
  43330. 0x164032faa574678L,0x09f47bb16129d2eL,0x03e2ac54390fdf2L },
  43331. { 0x1485a523f350fecL,0x13c62b51c6a605cL,0x1a88356a9934059L,
  43332. 0x05b2db45c91de68L,0x0f647b3cb85daa0L,0x0f4a36422f62752L,
  43333. 0x1d2af03469b2835L,0x00683b1a3829f53L,0x143972cc59c8b13L,
  43334. 0x1f0fa46a1a7fdfdL,0x13a4ea06748c619L,0x0120dbbde47e6a1L,
  43335. 0x19200cf12c49f53L,0x1202197e1e17367L,0x125ad4909a47305L,
  43336. 0x12f7d7ffee968e4L,0x14844527c9f020aL,0x01a66bee53d9e21L } },
  43337. /* 44 */
  43338. { { 0x031761a59e7fe87L,0x1718d0023e6b978L,0x19a3eb8c3d8ac7aL,
  43339. 0x1b6e3b62864f205L,0x0e0038f4a666f48L,0x1eebb6baf7333c0L,
  43340. 0x13570ed16b19c0aL,0x0221a5f705141adL,0x027ce7f1d9d8c5bL,
  43341. 0x00ff0720905af4bL,0x06e612e499f0dc5L,0x0b13ac06259b2b4L,
  43342. 0x0eda5493565206eL,0x03863a560c339a1L,0x15ec2ccdd1482e4L,
  43343. 0x118284e07976b2aL,0x087f621f59ca6edL,0x03e758e6155fbdcL },
  43344. { 0x047a5bbdb7fd65bL,0x02e601b64a2be03L,0x076e7849c62b635L,
  43345. 0x09d274ff638db53L,0x1d1566a1ed1dbbfL,0x00648ca28964ae5L,
  43346. 0x149a52186e8036fL,0x15c78d985313cfeL,0x1671961500941aaL,
  43347. 0x1e7ae87e4629c71L,0x1a64a68969547efL,0x130a2f941e4d5adL,
  43348. 0x0afa89ef7e90710L,0x18d5a2a4ba1dbc7L,0x1470db4e757a8c5L,
  43349. 0x0ad1ae885e7e7cdL,0x15c25a683e0059dL,0x00fb14d4c913e76L } },
  43350. /* 45 */
  43351. { { 0x125ddace45a1c3eL,0x149b2a0fbaa2fc4L,0x1f2cdf9fe0a1cb4L,
  43352. 0x067c98f3a48ac45L,0x1c2645d68823451L,0x04015caeffd7c24L,
  43353. 0x07e80c1e3d37665L,0x198acd24fe13a67L,0x19a500a1e9fd91dL,
  43354. 0x10040c0055855ebL,0x04d68e0653977f3L,0x060f315be111b2eL,
  43355. 0x189a45a2a79e876L,0x1c45a1cc9dd780dL,0x1ea65f5bfb58551L,
  43356. 0x11ddb301cae45ceL,0x1a2aac90ffa2a37L,0x0253afed145ec02L },
  43357. { 0x09a8fbb55e74cbcL,0x19c677d58c792e8L,0x0b5a5d93b0e9cddL,
  43358. 0x17cfc15a621f847L,0x0481cc9bc5a7d35L,0x05761a73af03477L,
  43359. 0x18f13c30baa64f5L,0x059e2649fd01a94L,0x15dbb7c1699b059L,
  43360. 0x016b3a6d3f07a35L,0x159b1e8c03eba91L,0x104266675906b4bL,
  43361. 0x0e8c408496e83dcL,0x0cf7afe0b877c09L,0x0d3a18a5b8772daL,
  43362. 0x00fb0dc56ee362eL,0x19a04629cdc5835L,0x02c0cfcd711ec0bL } },
  43363. /* 46 */
  43364. { { 0x19691216aa78811L,0x1747a1081f3e1ecL,0x01c08ae79a63d93L,
  43365. 0x1c9eb059bdbbe02L,0x0ecfac1ae6001f9L,0x1c9804925304579L,
  43366. 0x0a445bbd31e1018L,0x140a4c5d5cdd7eeL,0x1ddbd0af58c4ee5L,
  43367. 0x1ad7fc8766c3de3L,0x16cd31bc93c4521L,0x0503d0cbe2e45fbL,
  43368. 0x06886c1b9a48104L,0x0f7a118fcab4921L,0x09fa0b9bd7cc822L,
  43369. 0x12b915eb0f59fa1L,0x150d65719179ac3L,0x03a2cb01e09b253L },
  43370. { 0x02475bff41ae519L,0x00fd8a57c79288eL,0x134abbecb0f4d10L,
  43371. 0x16a39b5e10e1bbfL,0x0208bb199b2d385L,0x19f9fb4298e12b4L,
  43372. 0x05da45b2277d930L,0x1758479f53248aeL,0x12339b51e86d010L,
  43373. 0x06d87469131c189L,0x0785e403fb7adc2L,0x1b9746d0fde3eedL,
  43374. 0x03914764753fd96L,0x0622e46ee682359L,0x0d0f5e3cffc8190L,
  43375. 0x1dd21dfa2cf7b70L,0x145493ccb6d4b77L,0x019812a89d9e7bdL } },
  43376. /* 47 */
  43377. { { 0x0f0046935eaaca1L,0x025bac488c8811bL,0x19979b4a553030eL,
  43378. 0x1363d3adaf966eaL,0x029c2757cb9199bL,0x139c683ac291a4eL,
  43379. 0x0909e272f46eae3L,0x113371b7d20b247L,0x1a237793e18fe18L,
  43380. 0x0138babd3a17041L,0x05e7493baf584e9L,0x00a9a9e59eef189L,
  43381. 0x11958705de40325L,0x19ecccdd51dc504L,0x03fb8786c646f64L,
  43382. 0x1be2975fdf74876L,0x01cb3bad1843facL,0x0499456d821c3abL },
  43383. { 0x1e84e80f906b872L,0x091d03c131332d5L,0x09f8ce6333ddc15L,
  43384. 0x1beab6a647b138dL,0x0554dea82fab551L,0x0ac4e6d02bc7650L,
  43385. 0x15d43bc9948f4ddL,0x1fdb1fac4850c95L,0x093f27fc5178fe1L,
  43386. 0x19f37984efc3a11L,0x0b9278dd434151eL,0x0d64bb80714250cL,
  43387. 0x0284db682b7d90cL,0x0c40c98560d0d71L,0x1cf82911fcf6adeL,
  43388. 0x04b8a61cd7aa575L,0x1e70680025bf62dL,0x00550f9e7d6e86aL } },
  43389. /* 48 */
  43390. { { 0x182219022a10453L,0x15c8e1501d085d4L,0x16565991bcef747L,
  43391. 0x09e716df8d5f76bL,0x18cfca1da58de34L,0x186d026723e1f2dL,
  43392. 0x0bb5bf36385b43dL,0x11d58886937b44cL,0x09320d87bc56e2fL,
  43393. 0x071f5040c89c72cL,0x18b7fe8ac8db027L,0x14b91cfdf61b4b0L,
  43394. 0x0b16ac78eb6b0f9L,0x184da8d7a5a9a19L,0x14658a1bfd0c415L,
  43395. 0x0075a11c46df11eL,0x05e1f93f176eed4L,0x02ac99bf04b1b2aL },
  43396. { 0x0ddf738d8fd807aL,0x0764ed589891118L,0x136d896bef0fd38L,
  43397. 0x093e25f12a2945eL,0x0c3044fdd5b7060L,0x000a47da379e11dL,
  43398. 0x195506c8cb47fd5L,0x0eac368b1ea7369L,0x1f694b24a0dd70bL,
  43399. 0x1e3214c944ac0ecL,0x1526fbb97f88b43L,0x08fed4317ec780bL,
  43400. 0x027f1929d67af34L,0x00aa8f4674b50eeL,0x1753e89abf980a3L,
  43401. 0x059684fb595e656L,0x0d34a1631bc545cL,0x04980387cd8648aL } },
  43402. /* 49 */
  43403. { { 0x0f32c5e69a9bc05L,0x00ce32c4e25b9e9L,0x197a51997e70297L,
  43404. 0x0779f6987212b93L,0x1ddb7c318ab0f29L,0x19c0245c83843b8L,
  43405. 0x166f6253a59619aL,0x0d3e335219ec0d7L,0x1cc1d58dfb6fd2dL,
  43406. 0x036e627230ec534L,0x1709dfe73920c62L,0x132cecbf150588aL,
  43407. 0x0cc3badc8d749a5L,0x088966d597fe334L,0x10f1f2ce0060e5aL,
  43408. 0x04449530f2b8764L,0x0148775f310010aL,0x0021d10a0ac3dafL },
  43409. { 0x1be9dbc3a873752L,0x049fa17a217f73dL,0x0b2306308607b85L,
  43410. 0x01c52ed3cf30394L,0x1e768c5f00ce309L,0x0bb3bf5a3135646L,
  43411. 0x05398cfa73918d3L,0x17ff138595bc1f5L,0x004f5cc1141f5b5L,
  43412. 0x0b2fb9b11146096L,0x1dc1a8301733949L,0x1fff7c90f89fe37L,
  43413. 0x09a499f1a45d07fL,0x0c6ca4001f621e0L,0x0fc4be13d39e6eeL,
  43414. 0x01adb1466b42c0eL,0x0e84bb5eaf70f97L,0x00c683a3df92685L } },
  43415. /* 50 */
  43416. { { 0x0d3c77c84601fafL,0x12df1578e0fb92cL,0x1e63445b601b251L,
  43417. 0x0dab61b279fec4cL,0x1ec6723a3996c0cL,0x1d29a497d0d6baaL,
  43418. 0x1362a59aa05100eL,0x0cbb89928445586L,0x1ddf471deed6758L,
  43419. 0x05652cbca9ea947L,0x118ed493afd9f76L,0x10e2fc4b69a765cL,
  43420. 0x1a43159daa25824L,0x019abaa011e2d6dL,0x0e2c6995163e71aL,
  43421. 0x1a4639ed0bb4ff2L,0x059981a4fdacefeL,0x0388849f6845dafL },
  43422. { 0x0aa3fc6401f161aL,0x0c2b04ba62f4389L,0x0bec5ed77e0bdcdL,
  43423. 0x0f491cc5329544aL,0x09dd847db0b82b0L,0x14e2d30011a0ab9L,
  43424. 0x1d4e3c795340114L,0x1979838a73cdb31L,0x136162b5328d3abL,
  43425. 0x0d1bc9c15427866L,0x1ea06d37b9d211dL,0x0bf698477e37ee2L,
  43426. 0x1f787e8b3e16cf3L,0x0cdbcd583fe8e14L,0x1db182edf69f9a1L,
  43427. 0x0916a0e4201410bL,0x1d431840159e7edL,0x00bc4c5ed26ce4bL } },
  43428. /* 51 */
  43429. { { 0x18483d8ae1b8cf8L,0x0a5a174d1442b66L,0x013c81292f08c8fL,
  43430. 0x1194f4d3f4ec66bL,0x1757bab24e0b222L,0x02fce5457ded45fL,
  43431. 0x0570e16c90221b3L,0x0d68ff69027a835L,0x13f1bc53cc2aabeL,
  43432. 0x1166d1f8d68acceL,0x1b02070c7aa6c7cL,0x009602c29582365L,
  43433. 0x09c6afa7ab048f3L,0x00a06e1ee718e77L,0x1a2aee956bdd8cdL,
  43434. 0x07dfd096f566fb9L,0x0b250de7648c7cfL,0x039d446e78a9ab5L },
  43435. { 0x186828806e83b39L,0x12209cfa201be9fL,0x0c3c5f6f21051deL,
  43436. 0x1ea9a2ea93f20b1L,0x12307ffe2db64f4L,0x093130d11e75357L,
  43437. 0x1fc98e4fbf5553cL,0x06a5e9ccb1421e6L,0x1a4437ce3f4ee1eL,
  43438. 0x077a153d49e6f45L,0x0f27d24e6aa4059L,0x1ad47af6b9a83bdL,
  43439. 0x11f88a3acc44223L,0x16304516bc4d350L,0x1d5b0195bee77e0L,
  43440. 0x14601cf3b71c777L,0x01e73c56af2668fL,0x02979958bd71cb5L } },
  43441. /* 52 */
  43442. { { 0x0f524c1e714f71aL,0x109314d6ec28cabL,0x0761972b6f8f06fL,
  43443. 0x10b41f6c935b231L,0x01d192d9d88bf5cL,0x1925b7cf7d35491L,
  43444. 0x046738ffa0e25bdL,0x181d87f5c4964a0L,0x14b6af9f62ae0d3L,
  43445. 0x1e75d05eb0cb126L,0x0c24acbf6db8ea3L,0x06ec64c79a52fb8L,
  43446. 0x1ef95c43bdc91daL,0x06f5a26c98603b0L,0x1034c76244d9003L,
  43447. 0x1133ffafb9d0887L,0x0c178fec3b19871L,0x03cf0a69477efacL },
  43448. { 0x18222359bb40c55L,0x1901687683d2171L,0x06a520e307d0289L,
  43449. 0x0fb0c94f1c91cd8L,0x0c6c55c92b5f24aL,0x096a843f3f8a050L,
  43450. 0x0784398b0412b38L,0x1ab361434fd8236L,0x0fd8a275fafbb3dL,
  43451. 0x1f9aa7f4d1db598L,0x0176791980a8077L,0x169b2776cbeeb42L,
  43452. 0x0b0f82fdeb3d371L,0x0f2342a2ed2e5f8L,0x0f545f918048a6fL,
  43453. 0x1e924a0bc21738eL,0x0e277cfa541672fL,0x006c761454cab36L } },
  43454. /* 53 */
  43455. { { 0x14cf73ecbeee995L,0x1c45e6a48f40600L,0x12b766ae9752cbaL,
  43456. 0x072609909ac2b4dL,0x0ab03c9a2f7d463L,0x1d5dca5d0280e94L,
  43457. 0x15dcb23dc8f7a46L,0x129910bf2eea080L,0x0b5e1d2b3c7fcb0L,
  43458. 0x0f73ccaefcb638dL,0x036aacd19126798L,0x1bbabec0f265719L,
  43459. 0x01b1243587db425L,0x0fe3a1a038128e5L,0x00ab2249b5f4efaL,
  43460. 0x14e9f182f262192L,0x0fc72522c154559L,0x043000f13e1b9a5L },
  43461. { 0x1b00ba5e7693947L,0x0320f0096031589L,0x0383a15242a191eL,
  43462. 0x1fb2ae9abdc3487L,0x1bd3ba615173dbbL,0x1f503aca9975c64L,
  43463. 0x04ae47d06f2e17cL,0x1695839848f1977L,0x00f34648e1ef901L,
  43464. 0x0c94e8f6959d977L,0x1c7aaf0f5d6ff37L,0x0dee2739e9a48e1L,
  43465. 0x0df04249535cdbcL,0x03fe59c1e6c322aL,0x17e4c30781e6049L,
  43466. 0x1780173e413682fL,0x0c14225fc31114eL,0x00102c8e59a3ca3L } },
  43467. /* 54 */
  43468. { { 0x1003721275e0af4L,0x0a0f7f3c52525f1L,0x13db45d5d215c84L,
  43469. 0x0e2d1ccb3cccd9fL,0x0e2842ee5fa1d73L,0x05eafb131f1f2a0L,
  43470. 0x0412ab7b30f5252L,0x030033bc07a48d6L,0x1f8a9e903f343d8L,
  43471. 0x1abdd252d860698L,0x1b14194789d97f2L,0x0a3eca337ecf048L,
  43472. 0x00f2119a0180c57L,0x1c10ea7a2f82e10L,0x070e819f9921ee1L,
  43473. 0x0c0a44c5f29544cL,0x1ef56cfe4897214L,0x0288ccc2fd0ef82L },
  43474. { 0x019497db18586c0L,0x00aeb637755312cL,0x1ada5f368a2c011L,
  43475. 0x10f8328b28f8d48L,0x0ed3a5069a149b2L,0x04a65a5ab1b4fd2L,
  43476. 0x1bb89c24aa9990fL,0x012ab79ce7553d3L,0x034bb2870778935L,
  43477. 0x17cafd80375a993L,0x140c8e58e3d2162L,0x04d0b74eb7f10f9L,
  43478. 0x1d9d42d58129376L,0x12e36b26f996b79L,0x137b506932b55d1L,
  43479. 0x140cf30bea1f765L,0x19acf34ce0e9006L,0x02cf57932ac52bfL } },
  43480. /* 55 */
  43481. { { 0x1407efb6ec3876fL,0x03091f87a43243dL,0x1bfefe24c0e5e03L,
  43482. 0x008b5235605576aL,0x18811b829592eaaL,0x0f9fe4e72dc26bbL,
  43483. 0x184ee1a9c68d07eL,0x10182ffbb0de1cfL,0x088ed8297655a08L,
  43484. 0x0eb6e3a40eaf333L,0x1277d8745c5e5ddL,0x191bc7ef3c3fdffL,
  43485. 0x1d2046192e36ad4L,0x13a7ed316d8a98bL,0x1766451e327e9e8L,
  43486. 0x12e3809d9249f05L,0x1fb059d1e383a64L,0x01da2287513105dL },
  43487. { 0x1b7a955c776dcdbL,0x052be40e45d239eL,0x000d415d83ecd71L,
  43488. 0x03675d86a75c50aL,0x07117be5e3e8069L,0x1667b09c019adf2L,
  43489. 0x1e45b8711f8e815L,0x1c24a79fbd6672eL,0x03decdfbaf5cb7eL,
  43490. 0x1e4bca7be7a5b82L,0x05a0327fe0518bcL,0x1c237c7b553e480L,
  43491. 0x1769f91d8a4e440L,0x05af4e2ee2e821bL,0x0df4935041b1ea3L,
  43492. 0x169443232134267L,0x014e893c8383764L,0x0253ff1866214dbL } },
  43493. /* 56 */
  43494. { { 0x18f3a702455c7c5L,0x11b74380abbaa73L,0x1491d88c98b16ddL,
  43495. 0x1c378f018fe6588L,0x115ed8772c98b11L,0x0932fa6a4757564L,
  43496. 0x0803eec134f0066L,0x1d0d6a563379f4aL,0x1c46a098193ea3fL,
  43497. 0x016399edd3ac02cL,0x12ef58625aab336L,0x05f99d1d9aa3a64L,
  43498. 0x1d02fc44b3ac09aL,0x1550bc25a94c8c7L,0x0882173c311792aL,
  43499. 0x0fac26ac4c681fcL,0x12353cbb676c50cL,0x041fd0f51b28935L },
  43500. { 0x0ac86da10ccc646L,0x031bfbd8228f4b0L,0x18c228221840b38L,
  43501. 0x12406933057779eL,0x1c0bcda023c1901L,0x0a7ebeb83fe1ce7L,
  43502. 0x0eeedfd347c546fL,0x0c1ad4c9ce888e2L,0x157bdc676c5ac9eL,
  43503. 0x0b629819bdb08b4L,0x144e5b73d028751L,0x184a932fa58fa68L,
  43504. 0x04c2c4a739f3edeL,0x1535697129a574dL,0x1a57e045004e5f9L,
  43505. 0x1f57e40ed3a9a47L,0x1e0cee007c6de98L,0x030a04bbcc98e28L } },
  43506. /* 57 */
  43507. { { 0x1db32db15156623L,0x1bfde55bd33e11eL,0x1d41bc678f09a04L,
  43508. 0x05132498c24c023L,0x06804c1c34218b0L,0x157353a4950587eL,
  43509. 0x0f987596f9c1abeL,0x0d27627a47c1a03L,0x144545b47f87f4cL,
  43510. 0x0111b71026e0d51L,0x149874f14587b35L,0x14c77b11780ec26L,
  43511. 0x161599d7201eb46L,0x14dd7879bc636c1L,0x01ca083da557f85L,
  43512. 0x068148cfdd7ac2eL,0x1882f1b8a2a3e3aL,0x031b6d63b1685afL },
  43513. { 0x0280db9b4c80af3L,0x04e68a71c4955caL,0x0b83451df772686L,
  43514. 0x10d1f3e29e4dce0L,0x00baa0b2e91aee3L,0x18a51494327b1d4L,
  43515. 0x1f2dab3607dce2dL,0x1fa61c370e18bfcL,0x1883ea1c3b10837L,
  43516. 0x0d13ca9b590244fL,0x0ca9a1628b697cbL,0x17e40751f42875dL,
  43517. 0x15dc70b1c4e2330L,0x14cb3c7a5ae2445L,0x17d9d7029e31364L,
  43518. 0x1a6d04677a1304bL,0x13f37b5c0767b67L,0x017b6deff2685f7L } },
  43519. /* 58 */
  43520. { { 0x18472fd2e4da7c7L,0x07e48d733bc9917L,0x0228f709a389c23L,
  43521. 0x00f33448486c95eL,0x11d58bff0f10dfeL,0x04b17377c896ac3L,
  43522. 0x1a829afcd77f262L,0x1825172df52be8fL,0x0734a79eaaad308L,
  43523. 0x0b9819bcfa1bdddL,0x12f639b3d53dd65L,0x1b9fcec65dd8005L,
  43524. 0x0b5319310447606L,0x0567b94ea025af6L,0x177c7782b8225f0L,
  43525. 0x0e89112c5170c77L,0x14eeced154ef87dL,0x02e5b70cba2c6aeL },
  43526. { 0x0cef197008c75edL,0x04e9f7b77557c4cL,0x180861d7a5b5f3dL,
  43527. 0x1dbb361b143adf3L,0x19576daafcec2cfL,0x13eddc1c530e7f5L,
  43528. 0x053d04000fce4daL,0x0a766f870d04770L,0x09fb66dcbb80e31L,
  43529. 0x13f175d02cc23d4L,0x118ff4d69c9dc27L,0x1b23f93c1da149dL,
  43530. 0x14d515baa4311f3L,0x10466a719e0ee04L,0x157baa9d681baf2L,
  43531. 0x0583f56c2e4705dL,0x0e52e82bbb0e1f5L,0x010a4eb1828baebL } },
  43532. /* 59 */
  43533. { { 0x01a8e6f5f9311f6L,0x11e4fdd5e0fc2f7L,0x14bad250826b25fL,
  43534. 0x1832ee9fc29f4f8L,0x0555844f04c2f51L,0x039d59ae77e8914L,
  43535. 0x067f2d4e18a8ed6L,0x134ed1dfbad97daL,0x0cdc12479ee5846L,
  43536. 0x091bf189ec0604eL,0x128a4301130a304L,0x02f57a8fc50fbaeL,
  43537. 0x08ad0ffeef9ee65L,0x00c6940fe121091L,0x1b0378509cc223eL,
  43538. 0x17ae7d78e897887L,0x06c5b26eccfb415L,0x00a7179a86583e1L },
  43539. { 0x08d2a104216946bL,0x00f83bd25ec96aaL,0x028d0da54581ba0L,
  43540. 0x1ec7432f92b32daL,0x061f77c90f1b5c2L,0x1fbd913ced1e278L,
  43541. 0x048fc707358d24fL,0x078bcc36ca14468L,0x0826b34c5f28403L,
  43542. 0x0c5c8746179a10aL,0x0d5882ba01bb15cL,0x068bc64953694beL,
  43543. 0x1e8b53cb51a2faeL,0x1ccb2bbc4605dcaL,0x077bccb253dab0bL,
  43544. 0x11e4e0fd8c0fad7L,0x04f63bf1dbad0edL,0x02c29bf016e5b0fL } },
  43545. /* 60 */
  43546. { { 0x164b06464f80ba2L,0x02af382acd22d8fL,0x0cd3c7d2d8d3a38L,
  43547. 0x1fbd190905864c5L,0x030c780aef4f7d5L,0x10f349ceaaef506L,
  43548. 0x10d2c5d02bee73eL,0x1dc59fcd4cce8c1L,0x0f66959411187c1L,
  43549. 0x1c1793bafcba6caL,0x02b390011527ac4L,0x167f757bda04394L,
  43550. 0x064e3653eaf8244L,0x02ae2fc1e1b7a68L,0x1af3a43aae7c373L,
  43551. 0x0284bb27739df59L,0x10d16658e721906L,0x0242bc1afc16bcbL },
  43552. { 0x0d525bcd2576210L,0x1c553ea8daa21eeL,0x1c5c6f60e6527cdL,
  43553. 0x07e7158c43fd2f7L,0x018408cc930d0f6L,0x07a9fb57c7960bcL,
  43554. 0x1d7909a4b21f898L,0x06e1dc8a80fb614L,0x10ec47ae5ffdb1bL,
  43555. 0x14894ee3d535225L,0x04cac8b902dd75dL,0x09a12bde76ef6dfL,
  43556. 0x1568bc63e8e0676L,0x0e000a60147ea3fL,0x065763b46041252L,
  43557. 0x10b5f21c5a7fbafL,0x128eb39a05d6c2aL,0x036013bded10f98L } },
  43558. /* 61 */
  43559. { { 0x01b7086b509e7efL,0x1763d9ebfcfc8f2L,0x1e51549ae22e210L,
  43560. 0x080a3ba1579a50bL,0x174f1ceb6e44e06L,0x1f330dc80cc6083L,
  43561. 0x11f65bb2afa6048L,0x1dc8902226c65ecL,0x11dd82b4526c52aL,
  43562. 0x128483fc9cee4eaL,0x1bbbcbf35156ff5L,0x09bb1a5cbaf97abL,
  43563. 0x1288bc9f2a7815aL,0x0bd1d9912d6a764L,0x0e72f6f1bc4342dL,
  43564. 0x09dd1d1a183ce41L,0x18f5a0b071a9b77L,0x01833de4d7917e7L },
  43565. { 0x0e589f2b7ca9326L,0x0837ed89127b1f0L,0x1485d1e95ef45e8L,
  43566. 0x1ac561105d646a8L,0x0391ffcf2614982L,0x072206bf9d7aa22L,
  43567. 0x0c1c46aa8cdeea1L,0x0a851d46f612837L,0x1a957dcb42e4a7fL,
  43568. 0x1d5b3160d356afdL,0x178e07df0da8839L,0x1019375416d7a26L,
  43569. 0x0c94e4671f42e79L,0x05849171a11b818L,0x169627c93318ffeL,
  43570. 0x1fed9a21aa4f288L,0x195bb99d316a870L,0x01c8641e554cb60L } },
  43571. /* 62 */
  43572. { { 0x0d3fa82ffc4a73fL,0x0eb1a9dea9981a8L,0x1e28992eddf4999L,
  43573. 0x1c45ae7b090140dL,0x0323b8aa81c04a6L,0x0626ad1204e7fa8L,
  43574. 0x07064c773885e31L,0x1706e95501c181fL,0x10b25a38700186bL,
  43575. 0x05bbd085578a43fL,0x0e6b56ad2637874L,0x1b4c3541822c2beL,
  43576. 0x1d96e25ce892e32L,0x0f43236891471edL,0x1ec71a2d5f22371L,
  43577. 0x1bd8ace5622c84cL,0x13a5d0d807f600bL,0x01f52003e911f2bL },
  43578. { 0x16debd0a595d0a3L,0x0bb65d7f859da6bL,0x153e6c6f6e5e9afL,
  43579. 0x0898e298e37e582L,0x021af66362b19abL,0x0a0f7b64df99dc9L,
  43580. 0x03db48f61f12632L,0x1824ab00987af3eL,0x16f1a10052a7acbL,
  43581. 0x0d5bcecaa829457L,0x1e9bc32345884d7L,0x16dbbcbc2053faeL,
  43582. 0x12f95da12b40508L,0x1ac545d0ecad607L,0x18323ee2182bdc5L,
  43583. 0x09a6816329906e2L,0x0a0a40e6c80ce00L,0x004fc150bb58a55L } },
  43584. /* 63 */
  43585. { { 0x0abe588c21366dcL,0x00527d7baed7cb0L,0x1f66b2e4fb51ca7L,
  43586. 0x1d0f42dae0e0a03L,0x18e7361bb97e744L,0x1aa679d217053d4L,
  43587. 0x041e06b36bfc8a2L,0x1cfe10f99776f7bL,0x1da6f3983663250L,
  43588. 0x16b49f75d783e04L,0x0bd30e32ebc55d9L,0x1c0fbf9533a0f37L,
  43589. 0x07f26d8dab5a984L,0x1f5d1b7cd5a6992L,0x0374859342f9c05L,
  43590. 0x09e066f773cca1dL,0x05a72aa4e24531cL,0x03be8f4c25ba9ecL },
  43591. { 0x1373239d8e62367L,0x0c245dcc10678ecL,0x0d116a725f10cd8L,
  43592. 0x1c29f2c1f8018fcL,0x140474b59a0ec9aL,0x1032eae7a0f867bL,
  43593. 0x0184297bb7a3fb3L,0x0bb63bcb49d3d01L,0x117c44ae4ae0cf7L,
  43594. 0x1d2b191b58a4685L,0x09d03f4a7fcb70bL,0x17151196425cc9fL,
  43595. 0x0d6a863016c605eL,0x103da60bf963b8dL,0x1525e15b5844b9dL,
  43596. 0x1c1cbfd21d80e81L,0x1b0599be18be256L,0x0273755f6652a56L } },
  43597. /* 64 */
  43598. { { 0x10323d3fb99cfe6L,0x0de136499a0bc4aL,0x1905f2f7edbdec2L,
  43599. 0x09134eaec0c8223L,0x10919cb09114174L,0x15fe97a6319efc8L,
  43600. 0x18b6dc57f1f1ce5L,0x15919432a251956L,0x0306724734db81aL,
  43601. 0x13d1235da6262a5L,0x1a83eafc8a591b9L,0x0be3f4b6bae1aefL,
  43602. 0x05c2f192f35bed1L,0x1fb34856d2b436dL,0x0942df77b2b1ca9L,
  43603. 0x15a5e1895e54595L,0x056f44631c16049L,0x0192e93cb027678L },
  43604. { 0x011fb554848c144L,0x11492db53d79977L,0x0384da783e69381L,
  43605. 0x0d94a7643c24b6dL,0x0e98ea1bad9bdaeL,0x17d1cafa86b02e1L,
  43606. 0x0cbd6f6e7854e7cL,0x1ae8ae1c65bd22aL,0x1810698ae46a250L,
  43607. 0x1ecaa3656cec8a2L,0x19dc8447a5e979fL,0x0faa493f05d357eL,
  43608. 0x099851df63ca29fL,0x18e871f2d4e29cdL,0x074ad5bf613552dL,
  43609. 0x012d5a3c08b3808L,0x1d3ceb3eb6efd80L,0x00cea42a371953cL } },
  43610. /* 65 */
  43611. { { 0x019ee8fb540f5e5L,0x152978273468bffL,0x16c2b6f721c61b4L,
  43612. 0x11a074ff91a4641L,0x08bcb916a83ad5aL,0x08f4202a5fc1e38L,
  43613. 0x1777c2484cfa8b9L,0x10779c7084996a5L,0x0d5c7be40310635L,
  43614. 0x0f5dcefa2c718bbL,0x0658e6f136aeff0L,0x1fc980ae4b515f6L,
  43615. 0x1484e1cd2436350L,0x00a2dc6f5625031L,0x120c8deb7dcc553L,
  43616. 0x04e40154dbb3d66L,0x1b0a3345c3dcbffL,0x00d9d67365a7229L },
  43617. { 0x143e5e990a8bdc5L,0x1dfceb183504481L,0x08d63921483a880L,
  43618. 0x1dbcfa3a0d30913L,0x1f795d3fbd17debL,0x1d851fc7d7d36baL,
  43619. 0x1abea933ad8c0e1L,0x005c02cd665ffbbL,0x0a2fe20547e764eL,
  43620. 0x0d5cc127438f982L,0x14daee54bb11795L,0x0909521a4195457L,
  43621. 0x0775bcfb537b4c1L,0x14c16272a98cf9cL,0x00a4874d08e2929L,
  43622. 0x162fd4576c38f42L,0x0141e061b64db3aL,0x029c7619f0c9785L } },
  43623. /* 66 */
  43624. { { 0x13496fea19b56cfL,0x0bbfa3ddccd668cL,0x1ea15f42a20598fL,
  43625. 0x0410506bfb1e095L,0x1d82cec7cced3daL,0x004e42bf10fd76aL,
  43626. 0x08c1db85d6e67e0L,0x105b38dc6365a0bL,0x196948d4a81487dL,
  43627. 0x175e9f96a37b32aL,0x146aa1dcf331261L,0x1e45162c814d0d0L,
  43628. 0x0841a20b753e220L,0x08560537cf8371dL,0x0facfecb3fff97aL,
  43629. 0x1c593eb5363b51dL,0x0012587d9976e08L,0x037eb014c01f4faL },
  43630. { 0x0709f8d8eb7516aL,0x0c53a5ee2cc55aaL,0x16621fa0073a0c1L,
  43631. 0x01a2f7152da469bL,0x0e90f6abfd0f9d9L,0x1f6aadd50f2a4fbL,
  43632. 0x13064925bfe0169L,0x0ea1b3ecaf4d84aL,0x03cdea49cb89625L,
  43633. 0x142d1f816ff93efL,0x039ff76e2f012edL,0x01ff30e46d6078aL,
  43634. 0x1dbb0d5055904ffL,0x10a5f46824a14c7L,0x0f4c358d2cce1b7L,
  43635. 0x1fbb2f5a69d38f8L,0x1c01f2b32bde159L,0x04267d11e63b0f2L } },
  43636. /* 67 */
  43637. { { 0x1bc11eb8b99b964L,0x006052c717e2389L,0x11275326952e38aL,
  43638. 0x057edc41f50e1f7L,0x17c88cfa37a334aL,0x0578ed772c1e86eL,
  43639. 0x1e2981780a6a3bdL,0x0c4daabc468185dL,0x161b6fdfe209e9bL,
  43640. 0x18ed6935dc70407L,0x0f058a4e4bf068eL,0x1fcc155c7e9cb5bL,
  43641. 0x1ac2bf4d5b02ac0L,0x01417f6946ccc00L,0x0b6ccfc8ccfe4ffL,
  43642. 0x0a5ce2db962196aL,0x18e09f90f84c557L,0x0143ea628e42506L },
  43643. { 0x1a582010e9867daL,0x0c4d98d43a66d2fL,0x1f17ef7b88b9851L,
  43644. 0x0bcc257b5000bc4L,0x0d3635f9e357fefL,0x092d432706df6f9L,
  43645. 0x08b958af9c391bcL,0x1a3413731081b29L,0x17eb99a1528b5e5L,
  43646. 0x0dca0b73a88145aL,0x0dff5f81b4b3108L,0x0a2ffd41308a362L,
  43647. 0x06ffcecbd76fa1fL,0x0197a29f1dd0f4bL,0x09a3e875322692aL,
  43648. 0x12b460f63c55fd9L,0x013d0fb44534bd3L,0x0009951ee6c77cfL } },
  43649. /* 68 */
  43650. { { 0x13c7785576374c2L,0x09368c239382072L,0x17208a328113981L,
  43651. 0x05e39c2627140cdL,0x0deb0c5d1fe1c1bL,0x1fc137957764196L,
  43652. 0x096269d659a6672L,0x0a99a311d03bcefL,0x0e5ce0fe0118d12L,
  43653. 0x0a154c203c85c35L,0x1c10fce6b0a33a8L,0x05210fbcb009c51L,
  43654. 0x12f639a8c54eef8L,0x0c43bca7c1e18d9L,0x0c6ce475c11529dL,
  43655. 0x18f2b94c6baa031L,0x025cefea07631d9L,0x009e5f73b5b7c55L },
  43656. { 0x1cabe0f8d3f34f3L,0x0e18e51b0bff1bcL,0x188f76509a86f6aL,
  43657. 0x0fe539220964dbdL,0x02c6cd3be9dd962L,0x1d10cb019f58b4fL,
  43658. 0x120f229cfd24bf2L,0x16f25c6fc1770b1L,0x0e4f2aca623b3fbL,
  43659. 0x080fd8f325f0051L,0x1e09aa523d91220L,0x0f6920e4c1cf234L,
  43660. 0x10e30bb83541406L,0x04cce0377bba552L,0x0821447e48b2a03L,
  43661. 0x009e0d70c6b7217L,0x167bf936b5c25faL,0x027050d6d701744L } },
  43662. /* 69 */
  43663. { { 0x0ca66708ba29c4dL,0x12067114c404a00L,0x099c5b769d4b020L,
  43664. 0x0b5777f468438b9L,0x1ed28b72689c0e4L,0x02b55a0ebaa2fe9L,
  43665. 0x075957c8846635fL,0x112967b1ee870ebL,0x093490dfb8fe50bL,
  43666. 0x120faebf4075d0bL,0x1697ade6b2d4dedL,0x092e183abcbcf61L,
  43667. 0x0da5da429aab6b1L,0x17b69792919c734L,0x0c3ce9f804310dcL,
  43668. 0x0117844de2da4caL,0x199efb0f7b6cbefL,0x0399f186ccfcce4L },
  43669. { 0x0fe1582a42a38f9L,0x16ac723985a8076L,0x0a9f7a5dacb2bb0L,
  43670. 0x0b52d383765dc5eL,0x1cecdb4af0539dbL,0x14748118caa0b47L,
  43671. 0x1507fcbdcd22b9eL,0x0a43ab1af986242L,0x15d25b75c2202aeL,
  43672. 0x154cb2d7a041ad3L,0x0da9054a6d391b7L,0x16df7a4f5b367fdL,
  43673. 0x00261f900b5c97fL,0x026ad8cf6c3aaa6L,0x0866e72d0c0c764L,
  43674. 0x0179e67abd37196L,0x00c7a43d4923ee0L,0x02b7d659cdbcd2eL } },
  43675. /* 70 */
  43676. { { 0x19165a2a3018bfaL,0x035924ffd6cc200L,0x07d954d06a6c403L,
  43677. 0x0e4bb8999377e36L,0x0bfffe60e6bd1d9L,0x0a84d5a942876a9L,
  43678. 0x167c493a64b31f9L,0x091fed8a05c99d6L,0x02f0b35731aa7d1L,
  43679. 0x0860eeef3f1d523L,0x127d174450a203aL,0x1a4ccb7cbbab75dL,
  43680. 0x0e1febce13475cfL,0x004a169841d5d8aL,0x1fa0b21aae920a6L,
  43681. 0x0431a3c3646ba52L,0x0bbb771cdbe50d8L,0x0442cc9336ca6b6L },
  43682. { 0x0847290155ccaf2L,0x0f5e3be2dbb9f04L,0x1746cb7423b619eL,
  43683. 0x1d0fa8ebb751165L,0x0694d02a960a180L,0x1fcf4b407edb5bbL,
  43684. 0x0db10fa1d6324fcL,0x0fb7b47edf495b0L,0x19400c58132fb38L,
  43685. 0x0d3c2a112a81007L,0x1f0d45ddbb3c609L,0x08dcacdb6b34552L,
  43686. 0x0026545eda03ebfL,0x07ba55a223a1d14L,0x12cfda7b45a7613L,
  43687. 0x0e32d7557263b11L,0x11970ae932cd825L,0x03cb9125350604bL } },
  43688. /* 71 */
  43689. { { 0x12923f8441f3567L,0x018b417125f8eb1L,0x09aedd9c7fff047L,
  43690. 0x0ef4bc3444972eeL,0x1addb417601746aL,0x0cdc2329eeef501L,
  43691. 0x1ffdd5e19e8f1fdL,0x1516025530ead9aL,0x01bd5fec9f19ba9L,
  43692. 0x081bcd17c1833a4L,0x0d1176ae301745dL,0x0836f207e854eecL,
  43693. 0x0da903e46d5d7f4L,0x16e89360e008b3aL,0x1156d006c74f136L,
  43694. 0x06add44ea5558c2L,0x12c4da42a68555cL,0x01ff84e0aec1042L },
  43695. { 0x00a1bcef9cb7784L,0x09cde12117982a6L,0x07f431052a9ebb1L,
  43696. 0x19ffa85788be81fL,0x0f358e15d3aa316L,0x113b41217ad2619L,
  43697. 0x1b3b802f7367b5bL,0x0ba0d3ef13ff14bL,0x18078018e05e14fL,
  43698. 0x1d9f249c5a063a0L,0x123075e45fdcb4aL,0x0cc998ae2a18bb7L,
  43699. 0x1ac3fa8920e0eeaL,0x0e3cb8b2512f662L,0x12b45acf086c3d4L,
  43700. 0x03b351e1345e4c6L,0x04c8e730fc55839L,0x023f78c02a7efd7L } },
  43701. /* 72 */
  43702. { { 0x165f3d13da285e4L,0x0a6dd1d00f1fa4cL,0x04e984852b42e9fL,
  43703. 0x0a4472ea928e708L,0x1a730b92d3b7d53L,0x168b2ed29edee7aL,
  43704. 0x1fbd0c4c364acccL,0x16c89450a8305f2L,0x1bf62221c44dce1L,
  43705. 0x1d09c2c3f150764L,0x0cb2372feb6662eL,0x1e7f6bfda89667eL,
  43706. 0x05c66217bb409e5L,0x1e6fb8d4ae19463L,0x0481e22c036da7fL,
  43707. 0x08c974478544371L,0x061f8ab28e63ae6L,0x00d35b74e5c6f04L },
  43708. { 0x16ec2b606af77aaL,0x07ae6d443f832d7L,0x10027d263158b98L,
  43709. 0x13f9755e970fa42L,0x071ab855db595b5L,0x1a4d8607dac9509L,
  43710. 0x032728338439750L,0x1b73ac30fb110fbL,0x103ee95f9154bd6L,
  43711. 0x1f29909ae8364ccL,0x1ef0c3eda993423L,0x1e1acd4996c1e94L,
  43712. 0x0f5d37367c3d22aL,0x0cbec72a8b4a967L,0x05ccb41bc3a9cd2L,
  43713. 0x07285688f8e1ee6L,0x1d000ab3034a9cbL,0x03cee80c0142887L } },
  43714. /* 73 */
  43715. { { 0x0e0033a3ac7424eL,0x15b44307ed26802L,0x1d9af2ddcbef6c1L,
  43716. 0x17e52f9b4846d52L,0x1b013c6e294a8e2L,0x11d1d6a58555c2eL,
  43717. 0x129acf4abb2621cL,0x13c195c659a2790L,0x021888f5e70ec16L,
  43718. 0x1cb19dea1544131L,0x11e4b9ed8366e1cL,0x0e4420ed3fc2d15L,
  43719. 0x06d24bed3489f2bL,0x11f59255479fe7fL,0x131c1af4d7bee22L,
  43720. 0x19c1bbbd9f47e90L,0x0367cc119a9929eL,0x043f2d6a2c6a02aL },
  43721. { 0x099aa9d7d1000a7L,0x057fe57411c19ddL,0x18a37ee0f7162e5L,
  43722. 0x0308b4831b90452L,0x1d4170542f59fe1L,0x1b8ac0d45cb87c2L,
  43723. 0x1745e24630995caL,0x181c9de8efb81a3L,0x1b50b4cf33afad7L,
  43724. 0x0dd753c80c3852dL,0x021fe6ece8a1a08L,0x063c2494b39b8eeL,
  43725. 0x0f57f4323978575L,0x00b264a576ba613L,0x052fdd357d6b894L,
  43726. 0x1d464cc116fc5e1L,0x045f4cdb5bafdceL,0x005b8928ccc8660L } },
  43727. /* 74 */
  43728. { { 0x0290ca188d5c64dL,0x16ba4d3a4929a2dL,0x14f4a803a494165L,
  43729. 0x1995ef6cd740961L,0x0cdded83082cd02L,0x18b2374895a8617L,
  43730. 0x1fe5604f3a77bfcL,0x02ac55ce18f8ebfL,0x16f6852e07e2a46L,
  43731. 0x107ebe801c027e8L,0x0a93760863a364cL,0x0df75f8c8baf634L,
  43732. 0x01e8d9fdbe4918aL,0x02385b777d8407dL,0x05d3bdccf534229L,
  43733. 0x1cba5a57440eedbL,0x16d8ecb95a769daL,0x03d1fa11d3eb4acL },
  43734. { 0x02d2ca69a929387L,0x1bac0e58e0fff9bL,0x127df946db2eaf6L,
  43735. 0x04749c263fb125dL,0x1bd87561ee8d863L,0x13f399234071f8aL,
  43736. 0x1fbfb8e965f8753L,0x016798e56f8ab03L,0x1f3e77f8aca8caeL,
  43737. 0x063ebee2f17ea57L,0x09154884d56de7fL,0x09e54580e2efba7L,
  43738. 0x0d0689621f546b2L,0x1fbc0b1f20ada99L,0x15fb484afa6bd44L,
  43739. 0x052864fac773667L,0x0f4ab019ef29680L,0x016d2fe2a8b11fdL } },
  43740. /* 75 */
  43741. { { 0x0429cf3c8a5c600L,0x006111ff19f3e31L,0x1d00295f772e9eaL,
  43742. 0x1b24b618e93ffb4L,0x0b100eb0d1ae156L,0x0a1e4084bd21fcbL,
  43743. 0x13c905a7a5173beL,0x06743ee69ca2251L,0x004387c4a419f01L,
  43744. 0x003c34580822012L,0x05aafe40d673cb0L,0x1fdc8f1aa9c7ca8L,
  43745. 0x0642a2173ef9c76L,0x0ff180a0b310cedL,0x1bc91f98780c55aL,
  43746. 0x0cb2541feb9c727L,0x0d3811792ba072bL,0x042af810cb8642aL },
  43747. { 0x1fbfb6c847314c4L,0x030aaf5a2dcb530L,0x0519ae8abeb25e4L,
  43748. 0x0b57292f02e205cL,0x0110c4feed51f97L,0x1abb33ce97ad8beL,
  43749. 0x1139deb2339c2bfL,0x18fce6cd442dd64L,0x0dd1bbcec551c65L,
  43750. 0x092830570d42cefL,0x1205d22e9f4b9edL,0x0a83571d5188f40L,
  43751. 0x036fdff078e1a2cL,0x0a43a582373c126L,0x0c7dccde6d27f1cL,
  43752. 0x1cd9e455c66fe0dL,0x1971c3521926f8fL,0x014911b67a92e83L } },
  43753. /* 76 */
  43754. { { 0x1b8d80a7d8b29dcL,0x110120475324566L,0x117aba4afa4745eL,
  43755. 0x11fb4e5f78fb625L,0x1e760c6f1f347d1L,0x11c6c8889ba5a04L,
  43756. 0x107d1cd87a3c763L,0x09cee297d3ae735L,0x1c1f9701cb4df5cL,
  43757. 0x089c76c37b96570L,0x1f87ddab4603136L,0x0b7d3c5b7f3838fL,
  43758. 0x097c70c44df8c18L,0x1868adafc1aed93L,0x199517be65f3faaL,
  43759. 0x09cbca20288b4c3L,0x1aa16b068842518L,0x03e7d61acba90f3L },
  43760. { 0x11821673c0bc53aL,0x0f6f1bf3a89b3c0L,0x17f68d95e86212dL,
  43761. 0x09743fbb307944aL,0x05da77d8096abbfL,0x19a162ce741b4feL,
  43762. 0x167c7c9ee6b9eaaL,0x1d20d9237ad2e40L,0x0ee0dab30914ecfL,
  43763. 0x1b23fddc9fa9f89L,0x0e29ebfe95f83aeL,0x0ddf3e55ac0e618L,
  43764. 0x07bb99dcc9517d0L,0x02304050a4b946cL,0x0e705f6c00d2bc5L,
  43765. 0x045419902187e25L,0x0bd7225f14f772aL,0x03671ee3f8eefc1L } },
  43766. /* 77 */
  43767. { { 0x07cd835a4397830L,0x094867a39998360L,0x0ea0a6627a31376L,
  43768. 0x12ac7b02a5ba6baL,0x087de61b7990255L,0x1271ae793c6c88fL,
  43769. 0x0396671cd031c40L,0x1425a8888c2941aL,0x163e7608ff32626L,
  43770. 0x13d1bf4e264dd54L,0x1b7145dbfff4958L,0x1f919de5439a18aL,
  43771. 0x16efc559d9cb6deL,0x020e5b4965e606aL,0x0587827917cff14L,
  43772. 0x0ab399a0b8473caL,0x16d2a731ee95c3bL,0x0428a889151e850L },
  43773. { 0x02d033586ff19e2L,0x106d50ed14301bcL,0x13f955f1fbb70b1L,
  43774. 0x083789d16165cf1L,0x1df35c67a8f6f98L,0x122315660fcda59L,
  43775. 0x182c25b84d80d1dL,0x0ad7f22172ef8f5L,0x127c7f305514359L,
  43776. 0x0a6d8ae7b18f572L,0x158509f9a6cd330L,0x10a2bf825fe54a3L,
  43777. 0x13fb887162dec82L,0x0f0a445efe67570L,0x18f9d3368ccab07L,
  43778. 0x00d394406e9c45dL,0x004597ea1a1f0aeL,0x04588acf93bdef6L } },
  43779. /* 78 */
  43780. { { 0x0f71a442f961d30L,0x0b4543d639247a5L,0x01f2c6a41b36f7eL,
  43781. 0x0c0957f24ba65bfL,0x19f04d4c00c10e2L,0x0b82ed5c388bacdL,
  43782. 0x02124035539824eL,0x0ebeeb0e86793f0L,0x02e9abade6a7a23L,
  43783. 0x13b6a3c4a560bd6L,0x01496f080b66715L,0x195b57f5ce7a994L,
  43784. 0x183405991b95b8bL,0x02c54ce191b8f69L,0x1e32198ada791e9L,
  43785. 0x058f8f958163056L,0x0596ceaa79be023L,0x005ec3219ac47baL },
  43786. { 0x0a1a8b47e734189L,0x0d64467f2fd0befL,0x1538450dd9914b1L,
  43787. 0x115f3d2ea088949L,0x130c6b3bc252230L,0x16fa3bbc58e861eL,
  43788. 0x0375cbb6b97c131L,0x068a6263b345dd1L,0x0c4e380eeacc93eL,
  43789. 0x04cd8d6546d8747L,0x123059fd75275f5L,0x04ae2aad99aeee6L,
  43790. 0x0c2611d13dc9663L,0x1ad17ee632e7074L,0x163ea84b257f99aL,
  43791. 0x059304cd310650cL,0x107da87d1f431c3L,0x0233282cc7e6c8cL } },
  43792. /* 79 */
  43793. { { 0x06c13cc6b4a5efaL,0x0cc4d8e83d932a6L,0x1b3a2f71a703120L,
  43794. 0x04584a63a82172cL,0x0ad0a100f54cfaaL,0x0ed224e5af8c046L,
  43795. 0x00f32fad494e3b9L,0x0f14c48010b7dbbL,0x1e792dacfd6255cL,
  43796. 0x01b8c83103102c7L,0x057a0fb45963062L,0x164efa51aa852ccL,
  43797. 0x1b83b75df34b549L,0x0bfddca1757893eL,0x1df24c13d837db4L,
  43798. 0x0f13fa10c63b7edL,0x00c17c38f986018L,0x00621aba55cd494L },
  43799. { 0x0eb324c1d20cad0L,0x16584c63088453bL,0x0e71bc1b4db6437L,
  43800. 0x15781b432f4dd3aL,0x107ac5ce6cd978bL,0x04bf5aaca458e02L,
  43801. 0x0538caf51c59315L,0x0785538981e9ab2L,0x0772c5046a759f0L,
  43802. 0x1eb994534d6423fL,0x15f430c122ccc39L,0x09c081ef759d51aL,
  43803. 0x13a85f1790e6003L,0x0e42cb9b411ec8cL,0x078408a9ba6d9b1L,
  43804. 0x07f48459458f4cfL,0x1b900e7a19c0902L,0x01924ccf893936aL } },
  43805. /* 80 */
  43806. { { 0x07eaed67c834915L,0x1d5355e2f5b26b3L,0x12d8975880467ddL,
  43807. 0x04d33fb384e53d7L,0x0b8d4f6c0aee24fL,0x04bb6b70f5ac3a1L,
  43808. 0x1a995fc49c43053L,0x0c92272066bedb3L,0x1668b704906b500L,
  43809. 0x0cb4d07043b7727L,0x06fcfcbe764d819L,0x0ca36933c79df20L,
  43810. 0x1bf2dbcaaafb1a8L,0x0b9d835b405ca9fL,0x1cdb190c4b3159aL,
  43811. 0x1b02a6a69b38675L,0x191e4463a5210ffL,0x02bf515a5f8c615L },
  43812. { 0x0f5e1628aa0f2f2L,0x13ae287235e5500L,0x1e6a928b10b631fL,
  43813. 0x14297544052f568L,0x0943cc2eb4f308eL,0x0ac4025480de8a3L,
  43814. 0x03df2ec497fbbbbL,0x038ca0591f33a30L,0x1e53539191580c6L,
  43815. 0x113c03493880f71L,0x090287ea9c9c5dfL,0x1c0498eb62a6f41L,
  43816. 0x0b538f1c2232edcL,0x1f183e976d11b30L,0x0bb82d135447a62L,
  43817. 0x1e60e484edc8137L,0x1c9a78c39277ff1L,0x0302405a3753c9aL } },
  43818. /* 81 */
  43819. { { 0x1087d663872ece3L,0x0df3ecaadb87c18L,0x1f1e73e56ee17caL,
  43820. 0x1bb7ff4c436a169L,0x0022ba5dbae3b58L,0x00a24e0730e9407L,
  43821. 0x15215e2b9445d06L,0x01c162650819eaaL,0x1800ed1b6b8ce0bL,
  43822. 0x0effeeabc6aef1eL,0x108dd1a695ad1cdL,0x06d31b2215cfefcL,
  43823. 0x006313c7c7d5e32L,0x1496f4f2db7fa95L,0x08442ed68bf8836L,
  43824. 0x0de4683668fa7a2L,0x0ccc5905edb40c1L,0x003ba5069cd47c4L },
  43825. { 0x0e181abe3b6c106L,0x10b1fc6f0a85b9dL,0x00bdbcd520d93afL,
  43826. 0x06758f582d9eeb7L,0x091722afaa0d206L,0x0a2aa9ae3403341L,
  43827. 0x18fddce50798445L,0x1b42e24fc717ebbL,0x132cfdf031afb41L,
  43828. 0x1449e48c3de4331L,0x119d1298b272671L,0x1c5b2c58328eea0L,
  43829. 0x1f378cdf4c96866L,0x1a03fd19244f646L,0x04a4344e981c26cL,
  43830. 0x044e7a6fa42b2aaL,0x14b9623d303bab9L,0x0040a8caa121900L } },
  43831. /* 82 */
  43832. { { 0x1236d89fb7b2108L,0x041e656bafcd57cL,0x0c56d3876844fb3L,
  43833. 0x1e062b86c5ef8e5L,0x1272fe3f552aeaeL,0x021f7408f0a076fL,
  43834. 0x0c96e675e6fda1eL,0x0e99cd6a9fa3b37L,0x1b20b0e215b1badL,
  43835. 0x05010a7adc26486L,0x0efd4bf29b3b255L,0x091b3c9beede8b3L,
  43836. 0x0ed64cf17ee363cL,0x1b156d241822fc2L,0x1d32806100a859fL,
  43837. 0x1885a593c37e6d4L,0x074e8cf9d41f691L,0x02d5f90bc61625cL },
  43838. { 0x177966bf3b3bccdL,0x1f0785f1f065523L,0x0ece31f5410c011L,
  43839. 0x1f28dfabf997070L,0x09ec0e87e77e3baL,0x10c692bcdd53c2fL,
  43840. 0x1f3fb60f155f322L,0x0c3372dcb5e4b7dL,0x14f05d15e98c71bL,
  43841. 0x00fcc8d3bf316d0L,0x1b1e072ea8e0842L,0x0cbbca9b37f638dL,
  43842. 0x1344ed14307522fL,0x0ae57eed7ae82abL,0x1e3d6fcc0d6cc7eL,
  43843. 0x173b28fccfe86c6L,0x048029f7cad5270L,0x00ad68ac3a6c8b5L } },
  43844. /* 83 */
  43845. { { 0x0de2eceaa588ae4L,0x15e2c51b8d11900L,0x04d1c48c111154bL,
  43846. 0x1bc963065ba01d5L,0x1689e843afbfa67L,0x1a71741490b1a0dL,
  43847. 0x077147e5aeef587L,0x1a32a840d080985L,0x0c7fe382742317fL,
  43848. 0x050576331a418b1L,0x0e53441c00613f8L,0x12e7fc3f7b0bf85L,
  43849. 0x11fb07435207219L,0x023729c93245b55L,0x1e95bfc8eef6ab7L,
  43850. 0x04bec1b71ba3e01L,0x163104815eb8667L,0x01fce266529740cL },
  43851. { 0x136b29732ce637eL,0x0af96fae92e6effL,0x14b62c0ab65e068L,
  43852. 0x199f7567d2343a0L,0x014eeb752e5f3bbL,0x0d3c9d306965ebbL,
  43853. 0x085135124610f35L,0x0cc44859eeb9b74L,0x0a20705e788b997L,
  43854. 0x0709660763bf099L,0x0537dad86a6c159L,0x1e08e904b6b5638L,
  43855. 0x013da312238fd97L,0x06986386cab0241L,0x04bb9a779219c9dL,
  43856. 0x1127b79571e2a38L,0x14b5dc638b4668dL,0x0323ced6b111fabL } },
  43857. /* 84 */
  43858. { { 0x09044f3b05f2b26L,0x114a5405cfbb62bL,0x18a10a43dabacd6L,
  43859. 0x0604d4b0ef1073fL,0x0e5ff9c3761cfb2L,0x08e2bb3b44935b1L,
  43860. 0x0fbfaeb9b34802cL,0x075b90aeeace540L,0x00cae074ae1bad6L,
  43861. 0x1f248d0eb84ecceL,0x177b5994076704fL,0x19438655dfeeed8L,
  43862. 0x15c57683e81da6eL,0x0fcc6c23a8424eaL,0x166959278e4ba73L,
  43863. 0x13165f5af305ec9L,0x097f7c3bdb7a37bL,0x00ff04fca784302L },
  43864. { 0x1a7eaae7648cc63L,0x11288b3e7d38a24L,0x08f194fd15644faL,
  43865. 0x170342dd0df9172L,0x1c864674d957619L,0x0b2ccd063f40259L,
  43866. 0x08ca3f2204d2858L,0x13c6cdd52d214caL,0x1415329604bc902L,
  43867. 0x1cf0cca57155695L,0x0a3149fc42fbd7bL,0x0b0d8cf7f0c13c5L,
  43868. 0x1a844cc25d73dcbL,0x1a759b29fb0d21fL,0x0903c0b5d39fba9L,
  43869. 0x17969e66ace0dbaL,0x06aeec7694cfd83L,0x026f4abc36db129L } },
  43870. /* 85 */
  43871. { { 0x067d3153deac2f7L,0x03bc55b0ecd4724L,0x1e582adecb56821L,
  43872. 0x0d9fbe9ef3e76edL,0x11ab8f4b00b3005L,0x1bce80e8380f0a9L,
  43873. 0x14dc41fe5235671L,0x180f9329d7904ceL,0x01104d4ee48bad4L,
  43874. 0x0c6705adfe4e82cL,0x0a2634c27ea02deL,0x044b59667d5f8f9L,
  43875. 0x1c5b2f31750244fL,0x126bdf1a6a8f46fL,0x080ad0cf926e9aeL,
  43876. 0x04eb42ec1e98f7bL,0x00c37e36a7e4435L,0x00e4a20c5f31b4cL },
  43877. { 0x1a2131309dc1414L,0x1b2fe21e49a9ba1L,0x01eb7d7de738181L,
  43878. 0x150ba99f94dfe64L,0x03e995ab6f18b1fL,0x1598017ae213973L,
  43879. 0x1fc5848682792a0L,0x04d056cba372e28L,0x04993c20c20a7feL,
  43880. 0x0e4e5cc7338b393L,0x0b59cffad102826L,0x13c24a36978ab40L,
  43881. 0x14a05338ea3f3faL,0x1d84fb65baede23L,0x10d1824f2d0112dL,
  43882. 0x1d584cecfb43100L,0x1ba97851422098cL,0x0308dfdd95aa91aL } },
  43883. /* 86 */
  43884. { { 0x1baa55ef00ad2a1L,0x1d42f0a51486bdeL,0x1da3a4ac5a50a7bL,
  43885. 0x1a23d9026076948L,0x08bd27b267111bcL,0x101e0307212b814L,
  43886. 0x0212bca33ca8f66L,0x04176f91a5be631L,0x1e2ea1462e3aaebL,
  43887. 0x1a9ac0221dc2ebbL,0x191209553ba6f4cL,0x1d3dcd54331f03dL,
  43888. 0x04c26c5944eb2eeL,0x01558b3e3d2d540L,0x1f8869683bcb696L,
  43889. 0x0531cb45568ec05L,0x08d169cb3b83370L,0x0437362a20759d5L },
  43890. { 0x1e033210b793d9bL,0x1d6f08eedaf6776L,0x0a49a24c2d93de7L,
  43891. 0x1bfc9fa365ee7fbL,0x12a4dc8806aad97L,0x0bb6ba839d2d8ecL,
  43892. 0x09b022be32f62f2L,0x00cc1695762c79cL,0x19c8300a9dcb1fbL,
  43893. 0x1ad2ca66d4ad9e9L,0x1f5f52cdfab21ccL,0x174441ddf5563f2L,
  43894. 0x06f3e828c8a3d2eL,0x02d5bbc0992c648L,0x0a2d85f20c985beL,
  43895. 0x1705ae4b2e32518L,0x06dcd7196bc3233L,0x041c33f5c8cfd09L } },
  43896. /* 87 */
  43897. { { 0x14fe73e22474edbL,0x131ca0d4270d73bL,0x06b671b75b8ca9dL,
  43898. 0x0a29f17eba4e065L,0x12267b9000c4a41L,0x0927d71e71751beL,
  43899. 0x06de049d4c05447L,0x00cf829b0a84c74L,0x020c8401b1ae0b2L,
  43900. 0x195008d840fa4feL,0x048fee5671b7e3cL,0x18f9001c3a0c3d0L,
  43901. 0x1824259a9aa328dL,0x1bf7b61bac3b51bL,0x0f5327c8eb6a2d6L,
  43902. 0x0713e047ed6dd52L,0x19e89f5414dffb6L,0x025935dd1731459L },
  43903. { 0x10b1cb45d318454L,0x1ba4feba1b65b69L,0x1c995a29d18448eL,
  43904. 0x063909fa3c62218L,0x08403d55c85de12L,0x0fd5fc52fc6b730L,
  43905. 0x17380e56db84e6cL,0x021fcdad18679fdL,0x11d90381f94b911L,
  43906. 0x054754096e6375bL,0x00104dfa4328afcL,0x180f9144b8b4b3dL,
  43907. 0x1a5d84663cbeb5fL,0x0885b53e004e129L,0x023e35402c541ceL,
  43908. 0x03ccb0c0fb49882L,0x1c602c3d9c3cb90L,0x026b4bde2964b0aL } },
  43909. /* 88 */
  43910. { { 0x0db1ef0efa8fb40L,0x10e2dadd1cc4e70L,0x0c560274677ca40L,
  43911. 0x06982433c351adfL,0x14ef05e26b787b7L,0x0bcb71320bf0b40L,
  43912. 0x1086d124d0b6e3eL,0x06c5f0f14bd7f08L,0x1e71916d7e94a45L,
  43913. 0x00c5dd1d708cb49L,0x1d2fa55da2013a6L,0x0e99f0849f15d8cL,
  43914. 0x1d466ce6ab0a260L,0x049003c5ede49dcL,0x1c3c68ecfc56a63L,
  43915. 0x10b4f3a21fa1a70L,0x180a61241d9e4e7L,0x03b6543d0f36466L },
  43916. { 0x157fb56e02e48b7L,0x0a589e604f4e321L,0x10d4901a73c3ef4L,
  43917. 0x1858760353b6be4L,0x06956dadf878165L,0x0b05b472a4f3e27L,
  43918. 0x1194fcbfa54e2efL,0x1372a5f0ad60b3bL,0x0d3f60225b377feL,
  43919. 0x10639945ff48462L,0x0a8b4ef23d7cb5aL,0x08864884a0a19cdL,
  43920. 0x0a3d3b3ce5f7213L,0x00b3ba890bf0933L,0x1ee2529d6d790ffL,
  43921. 0x1c6ea2b24e0c46fL,0x1be152607532be3L,0x013f3f96336d1dbL } },
  43922. /* 89 */
  43923. { { 0x18f65ade6a15883L,0x1f3463357ed99b1L,0x1aaf4fc4b797529L,
  43924. 0x006f70f020c40f6L,0x04acf6d31c6ff95L,0x1f3c61606a26593L,
  43925. 0x0603858eb1807caL,0x13638c798b42c6dL,0x03e92cfe895c934L,
  43926. 0x19c706c20f63910L,0x075d90b57ea585dL,0x0d8387c051d2c2dL,
  43927. 0x06b16d54092aa77L,0x1836fa6cc9ee2b2L,0x071ae5e82c9fed5L,
  43928. 0x0be813d3222e19dL,0x128ea8e42be53c8L,0x00174b21bc19232L },
  43929. { 0x1540addae78ea1fL,0x0dba6bdb3874b48L,0x1107dc01a099468L,
  43930. 0x14faea418ff326cL,0x09ce12e18f97d6eL,0x1041a107d535013L,
  43931. 0x110d89642b2a1e4L,0x11ef49070c6eac2L,0x007c6149ef38140L,
  43932. 0x19dfac26bc29a03L,0x06c0426aeedbddcL,0x093fea5141350ecL,
  43933. 0x182e00ae3ce4eb2L,0x10bc77fd043c0f6L,0x144e9fa19306c94L,
  43934. 0x00c5f983cc5453aL,0x07dedb8b94e1919L,0x039cfa9ed278b29L } },
  43935. /* 90 */
  43936. { { 0x05f4a88924adc5fL,0x0360b540c7ab6bdL,0x04a5de57e552559L,
  43937. 0x1ba338a8001d892L,0x005912b42b48753L,0x1d24a30b7d11b59L,
  43938. 0x14199acf597cfa1L,0x0814e2e940208bfL,0x1b635031312a5e1L,
  43939. 0x1ce25a254b5c311L,0x0e75966ac00f569L,0x018c704de634f46L,
  43940. 0x0c6f7090cdc72f3L,0x08375f125a739c8L,0x091416966b1b0daL,
  43941. 0x08274734fe0db77L,0x084839991e1c58cL,0x0010611ffd10707L },
  43942. { 0x00e4adaafc74661L,0x1e7b193bfe03289L,0x13dadb739e64deeL,
  43943. 0x06f62c374282093L,0x09610fb25b8d6b5L,0x0ef3b49110c218dL,
  43944. 0x018c37a7b27477fL,0x097a657f49a85b0L,0x13885702a6244dfL,
  43945. 0x0f6e8f6a2ac96fdL,0x17d16fed3806e33L,0x1da50dc42b601c3L,
  43946. 0x076a937e6a8f4bdL,0x00987b91c049aa4L,0x0a087e10549e2eaL,
  43947. 0x09f158db88d2471L,0x0ef2207b119fd8bL,0x03b73dfa9fc934eL } },
  43948. /* 91 */
  43949. { { 0x112842827ebd187L,0x19055db2d56ddafL,0x1969c8961a5634cL,
  43950. 0x131e130d576084eL,0x0ebff503da3f33fL,0x0fb8d2a08c03d3dL,
  43951. 0x1c92c971ddb2a09L,0x16981bcf7dbfefbL,0x1da8b0f42165f1fL,
  43952. 0x19ffb9bb98f9d71L,0x075f9c64f829497L,0x15476d67748c99aL,
  43953. 0x17aa1f37828df84L,0x13b99d63dd425c4L,0x0606885b9e58333L,
  43954. 0x101da9a8dad56a1L,0x1091ec12c257cbbL,0x03cf3d69395cb77L },
  43955. { 0x0d970dc8f30caaeL,0x15e7885375f7a1eL,0x18fb1c5185b6172L,
  43956. 0x16a33c7530c7830L,0x04cb13d61c50db0L,0x0a3db4f9cdc4b1bL,
  43957. 0x0c3337d9f607c89L,0x16ee2af5773acfbL,0x0ccca25ba889491L,
  43958. 0x144903e3d13f06eL,0x1a3ef83f50ca07dL,0x1ee6ae41d812695L,
  43959. 0x09cdfd7beda5d91L,0x0501cf19597b0c8L,0x0363f707b0408c9L,
  43960. 0x000bba787acbdb6L,0x09432c916c84fe5L,0x03fc61bd62605f5L } },
  43961. /* 92 */
  43962. { { 0x1ec1e5443ac05e5L,0x126d266c69c1299L,0x102e22fe78af692L,
  43963. 0x016a7023b90db11L,0x03c3aba434d71ddL,0x0b08df32a820695L,
  43964. 0x13e80af102526d8L,0x186385a84dc4f34L,0x0535a5aa23b065aL,
  43965. 0x1545197e2975448L,0x17b29e7f76b48b6L,0x0bfa556764deb4bL,
  43966. 0x1bf37cd81e911f0L,0x0868b5c62ed673eL,0x1d625383839139eL,
  43967. 0x14e9e2bcd15dbc9L,0x02fafe04999fc92L,0x00ebb81d54b873eL },
  43968. { 0x0a4c81d3f0062a9L,0x1595c6cb5105d54L,0x037e192f44078c7L,
  43969. 0x0488276c28cdbb3L,0x09a555f8ba05f59L,0x05a968a8d33d06fL,
  43970. 0x0ac8eb30bc25cb9L,0x03756bb55d8e309L,0x0ce08b43e7c7f69L,
  43971. 0x1072985bb6213faL,0x1481a7908faf714L,0x13d069be299cfa6L,
  43972. 0x15446305ac6b5e3L,0x1f1a66e09ee5f94L,0x07d6beda0b2cb87L,
  43973. 0x12df3a9588ba222L,0x071c5ef63cd47f2L,0x00516207649e104L } },
  43974. /* 93 */
  43975. { { 0x1bc384faf5747dbL,0x0b04360355c3584L,0x00ba79f0551ceebL,
  43976. 0x02ab2ef57f480d1L,0x1a81deb02d5326dL,0x05b088831d4d02eL,
  43977. 0x1ae426a1b929d49L,0x1742805f0f49565L,0x17d0721d4d5c600L,
  43978. 0x117ecd4f944fedfL,0x1399b7b379bc1c6L,0x04efb573f4e7ebbL,
  43979. 0x1f6c474bab62171L,0x1b776819b696e24L,0x0a0974f7005f87dL,
  43980. 0x0bc8772e2eb809bL,0x07e6c297e3d54b0L,0x0177da2a32b64e4L },
  43981. { 0x0712b008b21c064L,0x17f212538314f52L,0x0d026dd3c2bf461L,
  43982. 0x06fd93cc52c86b6L,0x04c60d086965aa4L,0x182bd56ed0a339eL,
  43983. 0x1bd802d9599c2fcL,0x02cfe0bd08079d0L,0x0c05073a904401aL,
  43984. 0x158f31c14a7303fL,0x00c949a73dc1185L,0x0837d19cfa7440fL,
  43985. 0x137577053d29411L,0x05533186e9c56c6L,0x1410d436e9a3ecfL,
  43986. 0x0ec17d97d5fe3d2L,0x1e49f5166d51d2dL,0x019ba9967231448L } },
  43987. /* 94 */
  43988. { { 0x11118533a00bb9bL,0x1fdd722fb33429fL,0x0a1752bb8934b4bL,
  43989. 0x1606830add35c23L,0x0731349f18ba1e1L,0x0b8adad4d640bc1L,
  43990. 0x14bab04f7f52951L,0x14f4bee8478bb55L,0x130a483b9535b76L,
  43991. 0x174d6d27fc39f4dL,0x18b611c8e841564L,0x12f71db589c02acL,
  43992. 0x1a39d8fa70b9354L,0x0068ac4fb0db220L,0x0817c2855075d59L,
  43993. 0x11210c532846fe1L,0x0bffd8b00346bb2L,0x00c9515aeea6699L },
  43994. { 0x1576628365ced07L,0x1997d82ef0e8fb1L,0x06f2fd029ea80a7L,
  43995. 0x11376a148eda2f7L,0x195a62781b1b2a0L,0x07e0cdc9c4d5ddbL,
  43996. 0x01ce54b3fd83ecdL,0x1ade757292470fbL,0x0a8f053e66920ccL,
  43997. 0x1796ea5b1d4da78L,0x03b78547a084a4fL,0x181610717f43356L,
  43998. 0x0c9ffc11beafba0L,0x0ae6043c15ead3dL,0x10bc318162ff656L,
  43999. 0x06374d0da9147f1L,0x068c33abaaf1d9bL,0x0319711449de061L } },
  44000. /* 95 */
  44001. { { 0x0851d2015a1cccaL,0x114863f2915e18eL,0x155463aac14d3bfL,
  44002. 0x0f790bc42e16e83L,0x01cf8b29ae65619L,0x0a423c57098a0f0L,
  44003. 0x162b8b8b2d64d9aL,0x111d6af761f8637L,0x0decef5d6c264e7L,
  44004. 0x1d42b664e5cb6c3L,0x05a04c9e460f69bL,0x1040707af2d45b6L,
  44005. 0x1f1d0c6fedf03f3L,0x05355ecdac522b7L,0x1e5bc6495626016L,
  44006. 0x13d4e673ea58b07L,0x145cf6ded8fda7eL,0x03461ece0ae8e66L },
  44007. { 0x1e26265e6b392b7L,0x0ecdfbbaeca84b3L,0x13535d9453df3b0L,
  44008. 0x041bce5c39c2d57L,0x1adfb033d86f59bL,0x122be6533721e68L,
  44009. 0x16a8b6cd10d0017L,0x0636cf4f22cad03L,0x1c32e7babf01147L,
  44010. 0x137f0b769d8f4b0L,0x18a63bd8f49b981L,0x1bb0a835badb249L,
  44011. 0x1f9982f9719bea0L,0x02f83b5677ca806L,0x0f4e5ad721db98fL,
  44012. 0x0e8f4abc255cb64L,0x0a509efbb362ec6L,0x047902af7119943L } },
  44013. /* 96 */
  44014. { { 0x04ab9e3b82c1af0L,0x0f4f3f965713225L,0x10298061f51bf19L,
  44015. 0x0bc72766c69fd55L,0x019bacce27d3f33L,0x153308ce4fbe004L,
  44016. 0x0ba54fdd062d6e2L,0x113ff528aae6e55L,0x0937d78048db385L,
  44017. 0x086436fb78fde0eL,0x1af6268bc2833b4L,0x1f446ce873d6915L,
  44018. 0x0b3f17d2d8ae5d5L,0x008ecc4a081d350L,0x02d9e8bc8cfda29L,
  44019. 0x17e0cffd9d16643L,0x02e0422540f2319L,0x0094964649a0699L },
  44020. { 0x1eb55870386463dL,0x1e15901b8ecbffaL,0x15c42e06716b52eL,
  44021. 0x0d9e095a82366c8L,0x06939ec10cbb42dL,0x0c23f3aec0ce3b3L,
  44022. 0x0cb921d16b04e80L,0x1009ee0960438e4L,0x12c9e58a0acb057L,
  44023. 0x091dc59dab0f14aL,0x137c01e7e6e8d65L,0x1f843d552c50670L,
  44024. 0x0f8aea2b9078231L,0x1868e131d17562aL,0x0ce400201d7b5dcL,
  44025. 0x0527559689dabf6L,0x16492546ac2f011L,0x03e3c3b15f5c10bL } },
  44026. /* 97 */
  44027. { { 0x0f7d6fb067902b6L,0x11d21e8b9acc05cL,0x0c4965d07776ca0L,
  44028. 0x0e8067f2b80c59fL,0x08589b8c6e391b0L,0x1148791c18e851bL,
  44029. 0x07ceb8d1d352548L,0x0729b5629ac445cL,0x18f00fcde53f08dL,
  44030. 0x0cc8bd7383f947aL,0x0a82e81a3981f15L,0x07cfafc3f0482cdL,
  44031. 0x004d6a328f60271L,0x0c4866953e12aaaL,0x082c82834b8c992L,
  44032. 0x1c139e440f289d9L,0x01d5c98dc0752f4L,0x034a01a826c26f4L },
  44033. { 0x0b7b366e5407206L,0x1aa6786c47d467cL,0x1523dc9cb9bc7b3L,
  44034. 0x05035688d0dfdfcL,0x0e474408d653137L,0x0839bfa965af872L,
  44035. 0x141c67909ace992L,0x15e4aed83369301L,0x191f346280f272cL,
  44036. 0x0730527a34798e4L,0x1a8ca642113625eL,0x001972a2b0570eeL,
  44037. 0x0514b1adbf8a557L,0x1de9a1f7d58d79bL,0x1607cd08baffe4bL,
  44038. 0x061c265f3f6036fL,0x146ad850e06ba6bL,0x036d4f013de2fcaL } },
  44039. /* 98 */
  44040. { { 0x1eee4c25c9490ceL,0x1625186fb41c090L,0x1f8292a4da3aa5bL,
  44041. 0x149784c5e7cd8c0L,0x060c34ffd8b0492L,0x0f99e6842351082L,
  44042. 0x1d84bdffde990a3L,0x002218aa0884304L,0x09d25fce9149bcdL,
  44043. 0x12b08e6e7e309eeL,0x1dfa225fd47395cL,0x1e629d18116a2b3L,
  44044. 0x1575e7538f3fa3bL,0x08e42010750ab08L,0x00ab42b4782a546L,
  44045. 0x11cbe1a44d1759eL,0x112a04c6ac4058bL,0x03b9da05cd9a8acL },
  44046. { 0x0ff2cdc3631cfd2L,0x06169c03b9bde00L,0x05a8ce2949c0531L,
  44047. 0x1b665957bdac00cL,0x070b17cad0e3306L,0x19a9f719b39c755L,
  44048. 0x0eb4fcbd2aa35e7L,0x1c0e25ed5b2aedeL,0x0e427985289b2bcL,
  44049. 0x0ec7ca6ed496518L,0x0751d76124b7641L,0x0b949a2bc97b312L,
  44050. 0x0b254eabbd3e06aL,0x0076a89e2392ea7L,0x1eab9b0c4e52b3bL,
  44051. 0x1a26efc1f30b377L,0x175dc125546833fL,0x0095a31c2e2b627L } },
  44052. /* 99 */
  44053. { { 0x10dbebd932951deL,0x0cea12d534e4a40L,0x1013b2cbc2365a5L,
  44054. 0x1844a17058bf893L,0x1aec4e1dac74f0cL,0x04cd66cb521cd29L,
  44055. 0x0cebf0cf2ae6a41L,0x1165f99bccca9b3L,0x0f4af285c3863aeL,
  44056. 0x1b99b9f237f5fc4L,0x159cb0f26adfb48L,0x0261fc240418ea3L,
  44057. 0x0f52f3e56ec1c51L,0x12532540d6c1201L,0x1c58fc8d226adeaL,
  44058. 0x0662e143f6cc3b3L,0x01717c69be10e55L,0x030e0c9af3ec46aL },
  44059. { 0x0722d9b3492ae43L,0x04eca829c782d17L,0x1620802aad8c7beL,
  44060. 0x01d749622f5cefcL,0x1a461cb82872c12L,0x09c7932e1219641L,
  44061. 0x1f700c56cd0d32eL,0x11a0b7e558b1898L,0x0d2e501dd596b37L,
  44062. 0x028364fe5c48618L,0x0bd185f0d87c32aL,0x0e30b46b975c7a1L,
  44063. 0x11f3fc013821f7bL,0x0592476fde881afL,0x1272b81d18a2bd6L,
  44064. 0x10ee71ac843a091L,0x19475e3da392ca1L,0x013d686f938e9edL } },
  44065. /* 100 */
  44066. { { 0x03bda79305b5aedL,0x1ea522ccc6b53cfL,0x074c3dfadc00b19L,
  44067. 0x1c28fa388990abcL,0x089540edc18a7e9L,0x15fe901f54cb0c6L,
  44068. 0x110de94ef8829f9L,0x18d9290fcc9d982L,0x17297920734ef85L,
  44069. 0x106a738eaf0f5eaL,0x0ac79935235adbeL,0x1c0acdc401a9fb4L,
  44070. 0x1a5a5366a1782a1L,0x0d239b9c151e386L,0x18083a3f8fef4acL,
  44071. 0x16ccbafdf180cffL,0x02fec686fdeeacfL,0x02ecdaf13b6e8aaL },
  44072. { 0x037c5a5cb3e472eL,0x1ec939850a02f1bL,0x0b96d1261560854L,
  44073. 0x1be73410a201332L,0x15c6c56018f00ccL,0x01aa071311be08dL,
  44074. 0x0c611063b50204dL,0x0d7fdef97e0fcfeL,0x0ecd92366bf4857L,
  44075. 0x1badf0d5e4a648dL,0x1de379285889d86L,0x0fa78b8d79711c2L,
  44076. 0x075ab71858c52e5L,0x1fb71cfcae61c16L,0x09cd7f384b0b0a0L,
  44077. 0x0b32c98fc1de5acL,0x166e071deb1835aL,0x0127c48e6e5dc63L } },
  44078. /* 101 */
  44079. { { 0x0ef60bf6778c1e2L,0x0e01e806adf2e12L,0x01b8bc06827ffd2L,
  44080. 0x095c12dcb1d8233L,0x1077984c59a728aL,0x0652d2d55de76dbL,
  44081. 0x038f7ed1cef4a1cL,0x195192518c29bc6L,0x13fae7f9a4f67abL,
  44082. 0x1e15975f610d4e7L,0x1c358a7366d77a0L,0x14b38c1631bf5f4L,
  44083. 0x1e4049b54cadeaeL,0x16e98871eaff7bdL,0x18c8733f3baf1d9L,
  44084. 0x115eaee91dfc71eL,0x012fe9c32b118eeL,0x0431d61e7ea16fbL },
  44085. { 0x036fca7b85a2fe2L,0x1868477214ee305L,0x08245070e513cf9L,
  44086. 0x0cce4e541519374L,0x1968bd06306a810L,0x1e301ef34d0aaafL,
  44087. 0x193eae1bdf91c54L,0x0992e0cc295deadL,0x1c0dc36b898780bL,
  44088. 0x1b2bff11d0e9931L,0x05ea190d548b250L,0x0feddbfdecf203fL,
  44089. 0x146daa17a0d9189L,0x02d667def5df18eL,0x07f0779bc5e4402L,
  44090. 0x02859c1b4dc651fL,0x05a1c9d53dbe1e7L,0x01f1f8d8f45c339L } },
  44091. /* 102 */
  44092. { { 0x1ea15c07b7fbf05L,0x188db0f8d1c415bL,0x056b477346f264bL,
  44093. 0x155a1efd1793bbbL,0x1ca7ab7931f5b7fL,0x12adf3149b72f5fL,
  44094. 0x19550c3d05f7066L,0x17e3ede9c86879bL,0x0971f5e6582f044L,
  44095. 0x1e1dc7221446204L,0x0b167ee01fd5d5cL,0x05bb0316b1e0c35L,
  44096. 0x0097a3b0d3a64eeL,0x01ca582c37bd053L,0x0cd45f62e17b320L,
  44097. 0x07e0d340b28e97fL,0x02589ad5977a79cL,0x04090476c380540L },
  44098. { 0x093509914c4ce37L,0x1dc21d0d5245308L,0x0091603563a3cd2L,
  44099. 0x1366eb71750c00eL,0x0d3bde836db42c4L,0x0919db561b2a927L,
  44100. 0x051bd548786d192L,0x15d78f98baac9bbL,0x19c14b035bfb5b6L,
  44101. 0x1915d0c00a360d1L,0x0beef21c8853d5fL,0x0fef69242ec816cL,
  44102. 0x01cb4d6df13acfdL,0x11300548aff886dL,0x16459fd98389881L,
  44103. 0x14332f58fb53b03L,0x1c26e8e260cb6e7L,0x0221c1fdc406f59L } },
  44104. /* 103 */
  44105. { { 0x107f01de44f9af6L,0x00d26c658fd0e70L,0x0fb3edf7524cd8eL,
  44106. 0x144d51073fccb7cL,0x1ec789d8d0b8435L,0x062f0ff7307c8a9L,
  44107. 0x0a073897fa940afL,0x17008ef818afc89L,0x1349e9f83230ba5L,
  44108. 0x0a17997ef0c06ecL,0x0e7abd928f44737L,0x109d7d6e1075160L,
  44109. 0x04f12742cb80ef8L,0x190501311447306L,0x14eddfd1055b315L,
  44110. 0x074b39aa8fbcce4L,0x0459829a6eca601L,0x04577384786aa42L },
  44111. { 0x0f22d9c32c54409L,0x1fd233af5d5620cL,0x04a218a12606a7aL,
  44112. 0x1ed6751c1921c5dL,0x1d77641ed0201f6L,0x0b82bae4b980b65L,
  44113. 0x13807e49bcbc1c0L,0x0089308091ffd81L,0x0bf696211f319d3L,
  44114. 0x05ae422648d4462L,0x03ef3b800c2a09dL,0x0a4bc9edaa42988L,
  44115. 0x0c29d67d1ebed67L,0x010e9a9b57bf23eL,0x0ca5017e8c1f6e3L,
  44116. 0x100bead6d88d577L,0x1a0f059a7e3033eL,0x04b87b0ff304b52L } },
  44117. /* 104 */
  44118. { { 0x1c53d231bec8e4aL,0x0d60a1ad301a60dL,0x076942791936202L,
  44119. 0x1b1491046a9dc10L,0x125864b6496ae1fL,0x06834fd0d74c319L,
  44120. 0x09ad2eb284fa5d3L,0x1486e7198b163b1L,0x15fa71f58e76b9dL,
  44121. 0x08cdf4463f58b7dL,0x03c4feb5390a772L,0x0ce24933f3dbeb9L,
  44122. 0x15a10d8bd74583bL,0x0bc85dbf5e71008L,0x0ade377d9b5d815L,
  44123. 0x0abf5262d5dbc90L,0x0a7e0d8fb2d75f8L,0x02025adca2d3ee6L },
  44124. { 0x1ee682a517a15c7L,0x067de77c401017cL,0x04e5441a8d52ab9L,
  44125. 0x042e1fd7cf9dc58L,0x13d0c54b5de6019L,0x08495bac4f1cfebL,
  44126. 0x1f97c6571c4d632L,0x0f396fdaa7e14f7L,0x12bd9242af61cc9L,
  44127. 0x09778b629cafbecL,0x0b0729c2ccbc263L,0x04daa5a30b821a9L,
  44128. 0x0a942d6195a5875L,0x128058561499582L,0x0bf48c3f896a5e6L,
  44129. 0x04a78bf43e95cacL,0x00260f55af220daL,0x03fd508dac18a30L } },
  44130. /* 105 */
  44131. { { 0x0ba4f0c6e402149L,0x0660ecb1e608cd8L,0x106a9949d1d8d61L,
  44132. 0x0b92ae2be4ee81bL,0x1f89fb0e3f77ff7L,0x0df1ffd9791a569L,
  44133. 0x1fa09545640cbbeL,0x127f93f643a0846L,0x1eb2eff38a153edL,
  44134. 0x0ea9d7008020e89L,0x19516dfc6f60a22L,0x0f9c872a7d4b9e5L,
  44135. 0x14d85e75c8dd4a2L,0x120df0e1806972eL,0x1080cb7ae4fb588L,
  44136. 0x1ce023ca7e4be04L,0x0bfb9957636c3a4L,0x00a5b1d2976cc7fL },
  44137. { 0x010b55371c43336L,0x1ea5311d24125bbL,0x0b800a18146c677L,
  44138. 0x191ebe3db6f72f4L,0x1b67daad86abbb9L,0x0ffd7db3d2bebbcL,
  44139. 0x0f18e2b3941b735L,0x0a10bb53f2b1358L,0x0081cbaa875a3d1L,
  44140. 0x19a9ec7f49a3769L,0x0d87c687e680b40L,0x126e74cb38e3655L,
  44141. 0x0b4f5df8a1b0cb0L,0x15bead0edbf0718L,0x03973c1df131d07L,
  44142. 0x0e3591e08d938e5L,0x05532dd0bc7f7c1L,0x001242c39c1b693L } },
  44143. /* 106 */
  44144. { { 0x140dd2375a4cd8dL,0x05219cbde5d3c66L,0x1610963587d44cbL,
  44145. 0x13b43d1cd0618b9L,0x1d65d40a0a7ec05L,0x1a86bb03d478b88L,
  44146. 0x0b90a1a79957bd0L,0x1a17319cde0b307L,0x17b61391d9d8bebL,
  44147. 0x1294f12d8dd2ea4L,0x1ccba47dacb3d8eL,0x18d47f476c528deL,
  44148. 0x0cc3ef0ed2bd66eL,0x0f845a3b1cbca87L,0x16838bbba40232dL,
  44149. 0x1790ffad7c84b2cL,0x1ae78ed513c1177L,0x033cc676fff2896L },
  44150. { 0x1e3f8fd1b97c5c6L,0x1d59f3c61d99fa4L,0x104903d656e8e7eL,
  44151. 0x12bafa86ec884e8L,0x19c44777174225bL,0x0b5922c4059fe63L,
  44152. 0x1861370eb2a0ccaL,0x0e4ab227bee2e69L,0x1a4db23d39c9344L,
  44153. 0x15d9b99e8a10508L,0x0833e7cd822f733L,0x19ec619fc27f73aL,
  44154. 0x115f30874ca618aL,0x0f8002d2baf8359L,0x0ff276d41bbf9feL,
  44155. 0x0f883155d4f1803L,0x195f9179255f78eL,0x01f53d7692974b1L } },
  44156. /* 107 */
  44157. { { 0x0617e045b06ae25L,0x00a46e5aba877ccL,0x1c398130ae8af2bL,
  44158. 0x16ed6f12eb23d45L,0x051da18100c19f6L,0x02b82dbcdcdb683L,
  44159. 0x16fc7cc896faf25L,0x0da61686be6b800L,0x1440b4482bc24d8L,
  44160. 0x1c784cb6b1b9bbbL,0x15b1587112d370aL,0x1dcc6120d332cbfL,
  44161. 0x0408aa1ec1e9405L,0x1e97944a8cff849L,0x1d19e5fbbcc91a8L,
  44162. 0x0befc02d86ecb78L,0x04462d2569fd070L,0x0354569ce029280L },
  44163. { 0x05f020d46be7282L,0x0d7f6909c078972L,0x16f75769ab42501L,
  44164. 0x08ff17cc3c99b94L,0x196b8178c2d6f18L,0x06fcaa100994a9aL,
  44165. 0x0ad3634ec79edeaL,0x0aceaf8c37672aeL,0x0d749b57b80cc3bL,
  44166. 0x0c87fc99bd9fff6L,0x0ed94c517725365L,0x0c0c466bcae6737L,
  44167. 0x17f763feba70c1cL,0x0630db994e17396L,0x1cfcb291da39093L,
  44168. 0x0b19aeefa5f4d54L,0x1aadee4dbaac5cbL,0x00d0c08bcce7d70L } },
  44169. /* 108 */
  44170. { { 0x16ff62f77575ed0L,0x0a7d4be8ed4cdb7L,0x1beda7bf5fd863cL,
  44171. 0x17bb850c665ce55L,0x186c5834c45ab4cL,0x1baeec587106a42L,
  44172. 0x112634e5c0468e5L,0x1b002619011e826L,0x12d408ebaf5115eL,
  44173. 0x083502e01306f6cL,0x0dcd88672ae4471L,0x118dd0d2750d3cbL,
  44174. 0x1fcc7736174cf50L,0x0aec4e51a738922L,0x1eef260bdc6a87eL,
  44175. 0x0ffa49774f8d4c0L,0x1a8f3a515e7212bL,0x03e96ee3ac9187aL },
  44176. { 0x105816d4ed2cae8L,0x15e3edce001bb9eL,0x039991ac235133dL,
  44177. 0x0297380301847d3L,0x0f9179c1f9ee6c6L,0x0cb445708e4d09fL,
  44178. 0x1c29e96d851fa3bL,0x0eaf5fd6c91a0ccL,0x0d670333c176852L,
  44179. 0x04eecb4bafcf479L,0x1c8a34de9a2b7aaL,0x1abc8a99630d76aL,
  44180. 0x0f063dd55021a05L,0x065b6579a4080acL,0x152af9e4b753c21L,
  44181. 0x13aece189b0a4f0L,0x0ba845969dc6e72L,0x02d297c3d58dfa0L } },
  44182. /* 109 */
  44183. { { 0x1019e9109ecacbdL,0x0011ebdc4def576L,0x1c2d5c1cdc79951L,
  44184. 0x082d91c42ef98a3L,0x01259ab514832b0L,0x11b0ea58d533414L,
  44185. 0x170a9b8403e488fL,0x04dcb27ddd3c752L,0x1699b6bbd16c10eL,
  44186. 0x0a43c39ca39d09fL,0x053716c9d261f2bL,0x00ea4ab3c5d3e38L,
  44187. 0x1dc3d47ad257dc0L,0x0ea93bc9c224c24L,0x1f56e660f7c9e2bL,
  44188. 0x00540ee1c7d91ddL,0x1fe2ae5844676bdL,0x00bf813b21f382fL },
  44189. { 0x1a4010d29abea1fL,0x1cb4a9203d6266eL,0x04a410cc862d8daL,
  44190. 0x162c7aa6952d4c0L,0x0cc20565f221fc3L,0x142abb82dd0adf6L,
  44191. 0x0134c48e3953658L,0x1c8362884af0f10L,0x196fbf304a89a9fL,
  44192. 0x053f83625f32158L,0x0883a1b8ac217b2L,0x0f85fe94b23bba3L,
  44193. 0x13a4a343b88f7f2L,0x1d8b9ea6e0bd83aL,0x101eef9a12c7a22L,
  44194. 0x03aee7599d4887bL,0x17edb15c88d4c44L,0x00778184d29f2caL } },
  44195. /* 110 */
  44196. { { 0x1c25721fa8e5b60L,0x09c56b48e05d927L,0x0dd82c28892191aL,
  44197. 0x04fbc2d0efc8da9L,0x0721c630863f9acL,0x13fd81281ddb779L,
  44198. 0x0f4e7e306677c2dL,0x1b4f183dae5c0f5L,0x1cf9deb7bb32f0dL,
  44199. 0x1fb9378361e44f9L,0x022cb465c8896abL,0x022e9e28beb96e0L,
  44200. 0x0c457c4f378f5a6L,0x0e229e32270737cL,0x1a4b2022ef6a910L,
  44201. 0x06ac2af7c64db4dL,0x12aa9bc3fd95d77L,0x01e9db6635d9bdbL },
  44202. { 0x06f12cc9722c880L,0x1b5739435b444b7L,0x026eb4bebfb0e86L,
  44203. 0x14877717df74398L,0x17c3f4c3ad64ad7L,0x09d48dd2d7b5004L,
  44204. 0x0fdacabf2c3670dL,0x1219427f956d399L,0x1699a1391f2abc1L,
  44205. 0x0deaaa111d123f2L,0x18603e55223668bL,0x17fe24899879c40L,
  44206. 0x1e87d3a365ba9e7L,0x1d2652f11494bd5L,0x0f86db10153e8e3L,
  44207. 0x034896720c47acfL,0x0e71fa67c5778f4L,0x0174a3721e3daa2L } },
  44208. /* 111 */
  44209. { { 0x180fddfc60934aeL,0x13f7f8b21036894L,0x1e5905bb5d68b0fL,
  44210. 0x06b9a165b9eebcfL,0x1faad87bfac60cfL,0x04f2eeeee25f670L,
  44211. 0x1c6b9d4fea1f261L,0x0978baa2d465837L,0x1565dbea814732bL,
  44212. 0x03f5f1d672434b5L,0x09d35b36e5da500L,0x04e0cbc9cf7c819L,
  44213. 0x013aac4ebc3f5cdL,0x01eb61d0ba423e0L,0x1e81da99d8b80d1L,
  44214. 0x0cefad21b192a8cL,0x0c2768d78d61edaL,0x004cbe72a80c0ecL },
  44215. { 0x097746c965a0b81L,0x0c5f372f096fd49L,0x0f11c57d0dfd22dL,
  44216. 0x0f6acb88b2aae76L,0x1582797ce425e90L,0x12a3a7a7a1fa890L,
  44217. 0x012b3976be9be3aL,0x10655d71f7c27bcL,0x0ed7f95f0e8a07cL,
  44218. 0x1009537331604ffL,0x1ba6e31d0b3c5cfL,0x0b35c514388b7f2L,
  44219. 0x145cf4e2f38ea57L,0x1c80d00ca3aca0dL,0x045acb9f74f00b7L,
  44220. 0x17311cf49bdd4e1L,0x1e650b272b52fa9L,0x04b7cf84fe848bfL } },
  44221. /* 112 */
  44222. { { 0x0e8aac42c310a96L,0x0c181fbd1539a3cL,0x00f48e58881ccaaL,
  44223. 0x1db2a8250188d95L,0x0cabe911ad131e6L,0x0db6342bc8fe2f1L,
  44224. 0x021e1432ddfae10L,0x19d5ff27bd47a79L,0x106541f1df1007bL,
  44225. 0x17394e12ae6f8feL,0x1c4c5cc8f8e5c93L,0x14835a9a1183c1eL,
  44226. 0x1fa35e22bfa2de7L,0x04d81992d4c8955L,0x145353a814048aeL,
  44227. 0x1c157173ca3e80cL,0x0a5423c7aad79d3L,0x038ccc713205c7fL },
  44228. { 0x0140fcdceb6ed78L,0x079bb8c29a28b20L,0x196ba358373194fL,
  44229. 0x0d3b58abf008a16L,0x0e05686cce6c1a7L,0x1892b1454b5496dL,
  44230. 0x05094bf911d8849L,0x184e8f796a149e7L,0x0f0ec6ff2fc531fL,
  44231. 0x0be1a23887f4ff8L,0x021e0e71e4b3ff2L,0x049004df6033f69L,
  44232. 0x1cd804c290552c5L,0x1ae46539a000d14L,0x1977e81d0ad6b60L,
  44233. 0x0956386f03e2eddL,0x0acca6b85f03dfaL,0x041c4ca0d058699L } },
  44234. /* 113 */
  44235. { { 0x0f062a2de067dffL,0x193485e5c00b160L,0x04341c1e8af753cL,
  44236. 0x11f5c94723319b3L,0x132ad8145afc63bL,0x0cefd8b4278dbddL,
  44237. 0x16122c28b738bc6L,0x0c444c1c2fe91e4L,0x17393db00c2d5e8L,
  44238. 0x1447c2a19c678b8L,0x1e50a40ab3d48a7L,0x1970d06b5e7a00cL,
  44239. 0x12b8a2614c19157L,0x09a7623617d537cL,0x1ea04d413fe57d4L,
  44240. 0x08e099e00c4ddf6L,0x025454b3d05b37aL,0x00fdfed18934a76L },
  44241. { 0x1ebb657c8f69c77L,0x013c5d1efc47d7eL,0x15c707ede2d24aaL,
  44242. 0x14238e34668c76aL,0x089958b0d2066a1L,0x0eb3d3086440a18L,
  44243. 0x1ee3ee5d71f833eL,0x0c3b54ba410e606L,0x15ee5005d40bf58L,
  44244. 0x0073673bedd34d4L,0x10f2cf258b31d0cL,0x0c5299f080ab127L,
  44245. 0x1a225c9d700ac98L,0x1c8f23f4053f7b1L,0x0be12fbf86121a6L,
  44246. 0x0f17e373afbd718L,0x19e67788915c0e2L,0x027ca4465621378L } },
  44247. /* 114 */
  44248. { { 0x10dfcd4dd51b8ceL,0x1c93c1b11874030L,0x1c70d9665588215L,
  44249. 0x17c595d0efdb8ffL,0x07967608905ead4L,0x1c493650e192ecfL,
  44250. 0x02938f8e7b776f4L,0x149b52590d0bedeL,0x1e16f800af47a0fL,
  44251. 0x05a6dadf2fb0555L,0x1504be60e14f4d4L,0x04a136f2f1386ccL,
  44252. 0x184e0e72b264b62L,0x12aae15df52b002L,0x0a4b846aef52407L,
  44253. 0x0431e6f08334e2eL,0x1926e0b5aaae174L,0x03447034247bcb5L },
  44254. { 0x1fef641313b8f64L,0x08dbdca163a3166L,0x0ddd70362af6bbcL,
  44255. 0x015e8083520cf9fL,0x0935210f608ea5fL,0x08bd0411eadec13L,
  44256. 0x0b4856ae413f09eL,0x13f0bb763fc8ba4L,0x0c3d5e5094d3615L,
  44257. 0x15da9470e9cdc79L,0x12a0a3d12b3bc2bL,0x15be418af4a9babL,
  44258. 0x1378f95f4424209L,0x1499be9baba15a1L,0x133f6df447e9f66L,
  44259. 0x02fd9acd418138cL,0x06556e55b8f9bb8L,0x00b91e3f1f26209L } },
  44260. /* 115 */
  44261. { { 0x06486d8dc8b43f3L,0x1073093204f344dL,0x10df66d1800ff0fL,
  44262. 0x0ac509d8f631138L,0x0a9dbaea3a85033L,0x1c499e2d1b32e23L,
  44263. 0x05241efda5077a5L,0x05a3dab4a20d268L,0x1664a7b7a8cb800L,
  44264. 0x01fbb723076852cL,0x01ae8c7d3afc9d8L,0x1a83e58714ff87cL,
  44265. 0x19cf1db08a296ceL,0x06f3d1db1560c7bL,0x1da2c1b2467a20bL,
  44266. 0x0f96a2bcefa53b7L,0x13a21978baa4e94L,0x0425faa15bb184cL },
  44267. { 0x1decda9e364f21eL,0x079a280972abf60L,0x0121623e438435bL,
  44268. 0x17c76209717448dL,0x03aef57a9f6dda4L,0x193f54b5fbd1a37L,
  44269. 0x19b1c840a67fba0L,0x08b5533e90fb52bL,0x024ff813ed2cdf6L,
  44270. 0x0edd96945ea0a5cL,0x0406bf2be869874L,0x173539bd7b480caL,
  44271. 0x15e41039e47d9f4L,0x02856fa157a0d9cL,0x07a79278fa79aebL,
  44272. 0x0fe469e42675c68L,0x1534968c0f3cb15L,0x01c1fc13ded0340L } },
  44273. /* 116 */
  44274. { { 0x0c46a216583ff4cL,0x02d14a56b84f397L,0x073f013284a9399L,
  44275. 0x0922c14fcbb8cddL,0x169c762e82f128fL,0x16dc73dfd913d8aL,
  44276. 0x1da23e031e58f0bL,0x1994fb5fc0c9341L,0x0b7e417542d14b8L,
  44277. 0x1062e29c36f205fL,0x014a1876de4cc4eL,0x1cd3f7fc0e37e1aL,
  44278. 0x16210e9903b902cL,0x1b81f5dc30f234aL,0x17de2dbebbe1d3bL,
  44279. 0x1d475ecd128fdbaL,0x0256fe865475af5L,0x01d890f8aa1fca3L },
  44280. { 0x126e847659275e9L,0x00e7eb687e7282dL,0x0ff62a8fc7bd1d6L,
  44281. 0x0bc909cc1cabeb9L,0x1e9698e41e7be31L,0x1823c26c78d107fL,
  44282. 0x16cf89751b6a5eaL,0x0134a4db6eb0699L,0x01fd408d98d08a0L,
  44283. 0x00025902dae540bL,0x18eecd9792efa3fL,0x024aeb376ddeb67L,
  44284. 0x17c2fac737f50ccL,0x0939ca8d782fd40L,0x12ccd9e7b840b4bL,
  44285. 0x0a2be551ca817fdL,0x083673446fb2a6aL,0x02a82f0e89b9486L } },
  44286. /* 117 */
  44287. { { 0x03014a1d15e68a6L,0x18593326e9af286L,0x10b40eb59fe5be7L,
  44288. 0x1da58289083186eL,0x0d41a3cb74818c0L,0x0f9f4f628c08b48L,
  44289. 0x04e19972320ff12L,0x139364c18c2584fL,0x0f6086faeced04eL,
  44290. 0x1d96675febe23acL,0x10c4ce40a5ff629L,0x09d012e03590967L,
  44291. 0x07508b3762ca826L,0x0c1d46ff4fcbb54L,0x15663a575609c52L,
  44292. 0x1a6906a1a4cd3b3L,0x17c85cb89cb0f6fL,0x030bec06a52ba18L },
  44293. { 0x0ef267e70022b67L,0x1b5da9bb45ca526L,0x159b49e1118a014L,
  44294. 0x087048723262a74L,0x1df78c4a49054d4L,0x10f1ad4688f0b92L,
  44295. 0x18c766c94a9c756L,0x01c0f0cd90102e3L,0x00a8501db1b38a0L,
  44296. 0x16c995c673b811bL,0x1dd8263b6bdf40bL,0x1b5772600dd345aL,
  44297. 0x04bbfeb0363aee5L,0x0710d9c5fd7fe46L,0x0a381a41dee59e1L,
  44298. 0x108e2923f8b3fb9L,0x00b3f624f550e93L,0x028ab7a843e68bcL } },
  44299. /* 118 */
  44300. { { 0x0234e220206e8d0L,0x17aea3f8ad7992cL,0x0a2758e2543fd7dL,
  44301. 0x12fa892be95f56eL,0x08da80a966ec4d0L,0x1c51b5d6c4862ebL,
  44302. 0x1717f92a8248193L,0x062f33c4afc1e9aL,0x044c677ae24495eL,
  44303. 0x101c3d9d2dc71a9L,0x1e43d1d68a1ee5cL,0x198b8783e5eee06L,
  44304. 0x1b41a7fa4154895L,0x18058045dc3407cL,0x191cf2ff351d162L,
  44305. 0x1c3342939907174L,0x1ba78ed5f7aac9bL,0x0292a2cce599bb2L },
  44306. { 0x0739679a21b54c4L,0x167155b24bece84L,0x0a4b212219000a7L,
  44307. 0x1fd3f4f3b3e29e3L,0x06c208dbae48dcfL,0x11fb4f0a5c88e12L,
  44308. 0x0e0e16ac3efcb6bL,0x176301590fda3dbL,0x0146fd718188586L,
  44309. 0x0875b2a2a33e5e8L,0x0e5020599f3fb88L,0x18356e7a34c1544L,
  44310. 0x00881c1cbedb125L,0x1be181196f34298L,0x0f23463f8d31c4cL,
  44311. 0x09d078d8c0e1cdeL,0x14507e365bab4afL,0x0117853f6ee7c15L } },
  44312. /* 119 */
  44313. { { 0x062791fea7f1b7fL,0x0c62eee7f84ea71L,0x070ce71f716270fL,
  44314. 0x0e84edd1810d855L,0x09fe1d564dad401L,0x1408648548c7acfL,
  44315. 0x13712e35e59c0aaL,0x05dd6f5106c954bL,0x0fc4c23bbe7afa7L,
  44316. 0x0ddae4f25643484L,0x0e404da831f9bd3L,0x0002938431a46fcL,
  44317. 0x0794b324a2855d7L,0x1143d038f23ade3L,0x0d0c8f3262a3719L,
  44318. 0x113d272b45336bfL,0x046e186c3ee0c03L,0x03cfc0f378b39a6L },
  44319. { 0x1f2c1f3364f3c4eL,0x1956289b3f0a5c1L,0x13f164cf90f54daL,
  44320. 0x0a21b2c3fc894dbL,0x1e3f2aae34e5947L,0x153f928411a7673L,
  44321. 0x084932e4b802af7L,0x0743df749e14f23L,0x0c2086fd21192d5L,
  44322. 0x160687e5a8e457bL,0x06cb2b703c6d7ffL,0x111f025b7c3291aL,
  44323. 0x0adedbdd45b07a3L,0x0b812c4d20439d3L,0x189ed92f0a849a3L,
  44324. 0x0dd0b77edc7502fL,0x00073ee56636d38L,0x02217669bcef3e0L } },
  44325. /* 120 */
  44326. { { 0x0cd1ae68a2f90a6L,0x1ea0eb7ad68665aL,0x031100752e3bc9dL,
  44327. 0x09b06ecc62d4705L,0x15e1124be817a13L,0x15caf20a15bac6fL,
  44328. 0x078f897ef1a77f5L,0x19d46193ebfae95L,0x15ac0f163d89663L,
  44329. 0x154f77b86731c36L,0x043a9763b55510cL,0x1fe1311284f4f4dL,
  44330. 0x05eaaced585de23L,0x09f0c232bad69b5L,0x024e440d4529b07L,
  44331. 0x0add07b22c586feL,0x11e5c10add9e33dL,0x0428bb5b9835534L },
  44332. { 0x12110fa28a21e38L,0x11bceabb9ea9c51L,0x0efcb40837125edL,
  44333. 0x072c30679ba6d2fL,0x05fa85165917759L,0x155ae936b822fd7L,
  44334. 0x16dc0ce43ca69e1L,0x18d5817b461b89eL,0x1cca0240adcc615L,
  44335. 0x10f8b81628a36c8L,0x11cb429cb3be1e3L,0x0e1016cd37439d6L,
  44336. 0x1d7e61aa0a84840L,0x0334ab05bcd847cL,0x03adc78e20582f9L,
  44337. 0x0b2184726b85b29L,0x0b3d7fd83c09431L,0x04558aa5db72bb4L } },
  44338. /* 121 */
  44339. { { 0x0686003353c4a96L,0x03074482e6c1a94L,0x0d923d9be331397L,
  44340. 0x113f599f3d7ab22L,0x032639e5b6b80b9L,0x0556f5de0e0fd77L,
  44341. 0x080b4bd8e5b489eL,0x06a014f2da03130L,0x018ab548f3a4748L,
  44342. 0x0682b61d98d871fL,0x09a374059144b6bL,0x0db29607e7782b7L,
  44343. 0x0bd8f206c520383L,0x0f8bbcdb6b27653L,0x0acd2a24c68d87aL,
  44344. 0x05c45b04d21f8a5L,0x0a9342bb8e09292L,0x00dfe6ec2700581L },
  44345. { 0x10b9a4375a365d9L,0x0f0af046c7d8198L,0x0f5f5d0b7e0f52bL,
  44346. 0x09bc630e85392eaL,0x1360ace0cf7309dL,0x134b21891471091L,
  44347. 0x1694c410f48e3ddL,0x12ff855b7dbf21eL,0x041d64cb77b5f93L,
  44348. 0x100598562236808L,0x0190b48c5c83f94L,0x045b735440eb879L,
  44349. 0x12041eae47fcc01L,0x14643b5242b71d8L,0x0d81ac516191155L,
  44350. 0x0af7e3438f08446L,0x0f19b766d1f2277L,0x012dbc51dfbdceaL } },
  44351. /* 122 */
  44352. { { 0x0835718156707ceL,0x011cc218a7c8548L,0x016a2f95f6f66f7L,
  44353. 0x0b5ac7497002f91L,0x15aacffdd4bba22L,0x0aa3912e738dc30L,
  44354. 0x14f757c9991d5caL,0x1ae1501e3ee9e15L,0x0010538a3fc352eL,
  44355. 0x0532022a101e365L,0x11ea20cc31ced3eL,0x1dcc05b95836565L,
  44356. 0x0fed2b17c7b3433L,0x1eb194e397024ceL,0x1eb70de7e1a0692L,
  44357. 0x112b6712f328c6dL,0x0f0dc5650c892b7L,0x03855cab832d28eL },
  44358. { 0x0778ec47b585d93L,0x09b085319ff2723L,0x15393a80c46b29bL,
  44359. 0x177ac8005e43b42L,0x191cb7a9af22190L,0x141bebcf319d63eL,
  44360. 0x1ba2bb44f0c7fb9L,0x02db4940fae2c2dL,0x0d78a27323afcd6L,
  44361. 0x0334b72dd0a6b4aL,0x1d535d37d610830L,0x009c4ef1c792e66L,
  44362. 0x0c55b5a5c2e85e5L,0x051d65ae182ad50L,0x0223b68c4f7d4e2L,
  44363. 0x0bbbcb12d596a54L,0x0befc8842a084c8L,0x02ff64fbca8eef3L } },
  44364. /* 123 */
  44365. { { 0x0bc2c7cfe519f99L,0x15ec072a081a9afL,0x100a28e623cf8e5L,
  44366. 0x0bac037b435bdb2L,0x14ce64ac1c03b73L,0x1201487e98101b0L,
  44367. 0x025f560dfafa404L,0x073955d43474aa8L,0x1dce73d25b0b881L,
  44368. 0x0f6a095f658485cL,0x0a7fdf58f6acf0dL,0x0fb20c5b60e3320L,
  44369. 0x1642a4c11d55543L,0x127e488493be97aL,0x06495351dfe9914L,
  44370. 0x0c318f625d36e4fL,0x1957ad2ae22d84cL,0x00546ab31e74768L },
  44371. { 0x1ac51630a21fde1L,0x1aeeb3481ec24a1L,0x07b97f758a073f3L,
  44372. 0x00ef493468da493L,0x0875c06f4dedc6fL,0x1dc023235ed1601L,
  44373. 0x00dbf438383d8d1L,0x08420b02d36bccfL,0x0c961912ade8a80L,
  44374. 0x19ff505549d9e99L,0x0e3b6c315daf177L,0x1addb1a6fc8f3e2L,
  44375. 0x19cce5e7cb7971aL,0x0e9015a0755c2b9L,0x087f49a2292d0d0L,
  44376. 0x0df22bb084aafc7L,0x09f872fabd5b3a8L,0x04adc9a49b55231L } },
  44377. /* 124 */
  44378. { { 0x198a70199f951deL,0x0f2cb782c6da2ccL,0x107bcf40f74e3ebL,
  44379. 0x1a676283a69a8f3L,0x0cfe8a406e928d5L,0x077d1ecd232c005L,
  44380. 0x1c9bb4422b4bf07L,0x13ec972d243c026L,0x0b9b6a6b68e83bbL,
  44381. 0x0f8f36e092172a2L,0x03d9d8bd9659acaL,0x012cbc20b683a7fL,
  44382. 0x1a16011e1ca34ddL,0x128aaa0dea7489cL,0x08859b7ba9371a0L,
  44383. 0x0c248df00615990L,0x07dbdc7ae1d31d1L,0x01712f7a8b10d7dL },
  44384. { 0x133cf8fdd8e7357L,0x1d10c75676edc12L,0x0c741e134ab0cceL,
  44385. 0x0de50095c4d1c7cL,0x17e7ad7e1c927f3L,0x1fbc5000a19e913L,
  44386. 0x09eb82d0073c161L,0x16b3bf9e06d5400L,0x0c9e46c8b1d9a46L,
  44387. 0x136f2430f944699L,0x1b68bc6e2810f6aL,0x01cbe5a176adbaaL,
  44388. 0x0419defb5634623L,0x10e9643a0cf85b7L,0x03916cd57b0df34L,
  44389. 0x1d0a47b7e072f6eL,0x1d6f0862a8dac7cL,0x043cbcf53f0a0f9L } },
  44390. /* 125 */
  44391. { { 0x17e7b3f7f1c747fL,0x1260ee37319b4cdL,0x1dc2cdcb6e80546L,
  44392. 0x09a7dca9fc84e7fL,0x133cae0fca6d223L,0x0b7886097e47066L,
  44393. 0x073e49cca14e177L,0x12390de7f7be035L,0x05322677fe36caeL,
  44394. 0x0d3801997f7f522L,0x128ca33a2bc85ceL,0x0eeded4e63e8593L,
  44395. 0x1f66a96813c0256L,0x06d976d46343d9eL,0x113faf4652aac4aL,
  44396. 0x08365bc61b8b5ddL,0x016c052236a9792L,0x01f64c401611ea6L },
  44397. { 0x19e760c4072f74dL,0x1586f55aca02c87L,0x090326c0270b9e3L,
  44398. 0x00716b35cbb67bdL,0x0b4daa0647e875fL,0x079bc47a075a1b1L,
  44399. 0x0be2e69a93e4824L,0x0addfd7d35fdb7fL,0x1f87f96a59867e2L,
  44400. 0x137f691bad5b575L,0x09e0a8ff6c4f2c7L,0x0e3ce1f44c422feL,
  44401. 0x0cfd4c0dbe5102cL,0x181a394bae95837L,0x19f9e014df309a0L,
  44402. 0x1b4651b7ebc5656L,0x1142f633f3aba25L,0x01f498af477d764L } },
  44403. /* 126 */
  44404. { { 0x055cfa5239a9ea9L,0x1e34805f19d3149L,0x0d2e72d90af483cL,
  44405. 0x0c0175ce30eb3ddL,0x13410f843316c54L,0x1894db43a53b6afL,
  44406. 0x07c7048ed40ba43L,0x1195b91f350250aL,0x1f57b764a1b6240L,
  44407. 0x0b7600f8d403bbdL,0x1b3bc87c3771704L,0x08f9cb4d4b4ee8dL,
  44408. 0x0706e955ba3c49dL,0x1a2ebcd80f0aedfL,0x034421d8a7031e6L,
  44409. 0x045ae224f0610efL,0x19122585dc78c6aL,0x017681506853413L },
  44410. { 0x10434164daa2682L,0x16995809acb12a9L,0x0d2af619c25c389L,
  44411. 0x17dcef5c5c89390L,0x1af6c16911a19d2L,0x0b082a1cdea94d1L,
  44412. 0x03f84db32970173L,0x06ac6e14b37b8d8L,0x0ca420d27b93d51L,
  44413. 0x03986a2aaa6228dL,0x0963265b37afcb6L,0x13214a1f340bd7aL,
  44414. 0x1a7b0f01510cb1bL,0x08e90bf0b4d464bL,0x0bdd7a0b30db4d0L,
  44415. 0x054c3e22ed114eaL,0x1dd1db01394a09bL,0x00a313c2254f7ebL } },
  44416. /* 127 */
  44417. { { 0x1ca3aed232803cfL,0x01cc5cd4b7f9a35L,0x15fdd2ade22f079L,
  44418. 0x00fcd1809b95eceL,0x1cb7cd20c3a53e0L,0x0345e52fcb4e0caL,
  44419. 0x0c0cbca2d969b70L,0x029c79403a63b0cL,0x09b733b8187808eL,
  44420. 0x0eb826cf7f30c5fL,0x1cd50ac06e51b6dL,0x033df7dbbb7e4edL,
  44421. 0x0b903275cee057eL,0x0407bde33e8c179L,0x11db050f3717ddeL,
  44422. 0x0a0e5ade07a7ef0L,0x028035f5557a9baL,0x03d65abdb5a014bL },
  44423. { 0x041356944e6b07cL,0x02664f0e39a2ee9L,0x136389cee7ed147L,
  44424. 0x13711c69f880e88L,0x1152776dfe49607L,0x0114ce3be8c267fL,
  44425. 0x0a25db440cee71dL,0x04053414d08ef7eL,0x059ffdf10ee8f04L,
  44426. 0x10b8a36225dab6bL,0x141b0bee6ba1553L,0x05b7b27cf9ab063L,
  44427. 0x063c96b607b2cb8L,0x1aa4f154419c0e2L,0x12887501abb4945L,
  44428. 0x1f7bbdf2f1238eeL,0x16cae9807c78675L,0x0352d02dcb1b1a8L } },
  44429. /* 128 */
  44430. { { 0x0e71ea66a8f4f33L,0x037e326f547a549L,0x14b3fba21187cbfL,
  44431. 0x1c112a9a11a6ac4L,0x068ab76659b0a83L,0x07c6822deb4611aL,
  44432. 0x19eb900a04d5e40L,0x08230383380a570L,0x0986a516918764cL,
  44433. 0x180efd709abae92L,0x1a6b9564d9dedf2L,0x004a8db936322e4L,
  44434. 0x19c40097c8f6d17L,0x12ce203dc6f3424L,0x14a762ddb7c00c8L,
  44435. 0x16bec812355b22fL,0x08ca7f46d214a7aL,0x034402a5a387672L },
  44436. { 0x0d168aa51a5b86cL,0x1f26c4abbb923f8L,0x01dbc5c80ca490dL,
  44437. 0x1b2c8f4a9d5d088L,0x0405622c0a7ac87L,0x13cf978f2cbd258L,
  44438. 0x055b7b7bf971bc2L,0x1ed5e7de1849aaaL,0x1917fb04eef047cL,
  44439. 0x1c93ccfaa5b109bL,0x1a8cbcc52f82e0dL,0x0cb6188cd6190ebL,
  44440. 0x0e7e218978e157cL,0x06f2c3d7e946486L,0x01defb6e43f0eebL,
  44441. 0x0219bba65ae3917L,0x0533b432200ca8eL,0x00010fa0ceca7b7L } },
  44442. /* 129 */
  44443. { { 0x191122c43519d26L,0x1d60ea0528c2290L,0x07a5522ee27ef6bL,
  44444. 0x182d0897f398deeL,0x178e8d559ef3375L,0x05f0e2f3bc4fbc8L,
  44445. 0x1790013d666d87eL,0x193011193345977L,0x18939a260893206L,
  44446. 0x0d725fffe698428L,0x12cffb823fabfa8L,0x0133fe295578cc9L,
  44447. 0x0c2a841ef961f38L,0x0bf80edb06c1ca6L,0x1aeddcdd7eb62b4L,
  44448. 0x04a24df868aecdbL,0x19f1e716b05a425L,0x03cc2ac4014f0f6L },
  44449. { 0x0cb3aaa95106473L,0x17d20ad30ed0251L,0x0d894e558f0257eL,
  44450. 0x032a62570ffa792L,0x1f885c76baa4809L,0x063c6ab63f3ac15L,
  44451. 0x11035c3db6ad88cL,0x10d19c60a38ee8eL,0x06dbebd14ffdb61L,
  44452. 0x07020fd0c87204bL,0x031199bb98b8aacL,0x1c54e9e667ad742L,
  44453. 0x04fe7b9b6693d57L,0x036941be803556eL,0x01d07abebdcbdb0L,
  44454. 0x048ee63198bcd22L,0x08d9c5026096569L,0x04aec11e18e87d8L } },
  44455. /* 130 */
  44456. { { 0x0eebd86140528a5L,0x0615d29cbcde435L,0x0e293b0512afc9aL,
  44457. 0x1b054fafdb63793L,0x0e0118d81efabb0L,0x00aac778963868aL,
  44458. 0x19cf8c581c5a287L,0x1ba67c8516fc96fL,0x06317663783aec9L,
  44459. 0x0b97fdf709561aeL,0x1c2feef05eca914L,0x10e0e83f02546fbL,
  44460. 0x1be2888f9c4212fL,0x1ab652ae9ee765eL,0x00a3906a77056a9L,
  44461. 0x1b607e63231d972L,0x1547ede02856aeaL,0x00713846abc32a7L },
  44462. { 0x070cc53cde20f88L,0x013962fad881c91L,0x0679772c76fe4ceL,
  44463. 0x136e5ae982a085cL,0x0aaaaa554b3de21L,0x1435d30b624d459L,
  44464. 0x05a5402110f96eeL,0x023dcd79ae4419eL,0x159ffac6ba89abdL,
  44465. 0x01890bdf88ab1ceL,0x0a2bcbcd32e948aL,0x07ce0e4f520dc9aL,
  44466. 0x1f69017766f27f0L,0x1d40891f342163cL,0x0a5cee32cd1a6f5L,
  44467. 0x01b7a9181e68d48L,0x078fc5784a62399L,0x0069ed59dfd94cbL } },
  44468. /* 131 */
  44469. { { 0x18376e6ce29c3ccL,0x083f6780b65e347L,0x065978e533872c1L,
  44470. 0x1ee78a1a83bd7ffL,0x0d16ce3d24fc526L,0x0098a0a76ead2a1L,
  44471. 0x0181aecdef76647L,0x151c6885de5c675L,0x12ae90337c0629dL,
  44472. 0x1fd76322c955998L,0x0e265f60ae15ed5L,0x1973466e62ec352L,
  44473. 0x029086751fad6c8L,0x0c60b8cb412caefL,0x1a5cd5ea07a5fecL,
  44474. 0x13ed3c9e914277eL,0x026a1387c2e5cb8L,0x02985a775ac3a5aL },
  44475. { 0x1f275a1bab7b5aeL,0x0ee2681d2bdfa74L,0x112a9171416eedaL,
  44476. 0x0682d5880592e9bL,0x0ed985dc726369fL,0x0a2350b9af273c5L,
  44477. 0x0c0a8152361e737L,0x14d099d60d33c2dL,0x0f73f6fa4789b11L,
  44478. 0x150620fd95273c2L,0x1da40a4ea6da5daL,0x1c01e075156563eL,
  44479. 0x1b844d66c1814ccL,0x184a9100b26592aL,0x08c89c6de539f58L,
  44480. 0x149b3c0a5a9c87bL,0x17f5278b2e708b6L,0x0484a12a940632bL } },
  44481. /* 132 */
  44482. { { 0x069a14d0d5b4c2fL,0x1e2cdae45324e69L,0x0ceac38df528ae3L,
  44483. 0x11222206fd2b7d9L,0x14e35322fda1a76L,0x1c7d7e2c08702d4L,
  44484. 0x1398a8937304a85L,0x088b858c7651c7bL,0x1995c3f179452c4L,
  44485. 0x0998761a16a28b0L,0x16982ad3be04a4dL,0x04a5175d3827404L,
  44486. 0x06e2e3caf885493L,0x1b24dfa392e8d30L,0x13b17c7510246acL,
  44487. 0x066678fa15f7ee0L,0x0f527bd1d62bd8bL,0x0282b8088e7f30bL },
  44488. { 0x0084acef534356bL,0x0ef02a5a587de68L,0x18173b81370677cL,
  44489. 0x106c36f1c20435fL,0x0f78d38b64bde68L,0x052f2751927e63fL,
  44490. 0x0665bfacdcb3bacL,0x09dde09f966cb02L,0x07dce5d505eb0abL,
  44491. 0x114dac411c62c37L,0x18c65ef36000dc7L,0x08a2900d739fbcbL,
  44492. 0x0bd18e67ab8bf5eL,0x1cfb1fd6a1984b4L,0x1062ed09a9f413bL,
  44493. 0x1c459438fe2476bL,0x19f485b848225dcL,0x047f859b7eaa073L } },
  44494. /* 133 */
  44495. { { 0x1f2e2f43ff42cffL,0x0cfce8e1a98be4cL,0x0e4aae86d5168f0L,
  44496. 0x0a95f53465b6e92L,0x17dcd43684232b0L,0x07cc8a85c2aea36L,
  44497. 0x088622b0d788117L,0x00baf9e458fe003L,0x1057d35aeed4083L,
  44498. 0x0d2528caa9e67e6L,0x195e4e4f8ae4e49L,0x05606845d84ebcaL,
  44499. 0x1e3ac53958a2033L,0x1cf4d8b1cd84802L,0x19863598a01468dL,
  44500. 0x1cf5f6941b813f8L,0x03e9e0e857f6748L,0x038d9477762bbebL },
  44501. { 0x142b0cd99726bf8L,0x051dc8e10479e24L,0x039ec1663aa84a4L,
  44502. 0x1f44b52251fae52L,0x0037d7dac6a7791L,0x1141bd9699ed926L,
  44503. 0x18a83087bfac1c3L,0x04f7ee1b2ddc7b5L,0x143ed8191850760L,
  44504. 0x175855426a56bf1L,0x14407fa316dd312L,0x14dd5a4dd7bb78eL,
  44505. 0x086b78aa4edbfb2L,0x108acc245d40903L,0x0e9713b252aa3cbL,
  44506. 0x052b41a21b3b67dL,0x05ace7fec476318L,0x0394a388d1986c9L } },
  44507. /* 134 */
  44508. { { 0x0e4590432bbd495L,0x1a6e8df2a4b9ffeL,0x18757670fd38cc3L,
  44509. 0x10b374e40800d7dL,0x02c2c76840ee607L,0x1f445f60ca7e9faL,
  44510. 0x00842839dac4ba7L,0x18e2f9bbbb7d856L,0x0689d436b00811eL,
  44511. 0x1535d1b9425f4f2L,0x0e56c801f504529L,0x13e61e23ce89578L,
  44512. 0x08e9396402f8cdfL,0x175a3142e2ff5f6L,0x18344de29d45d0fL,
  44513. 0x125c7337f0f058dL,0x15f3965e170beb2L,0x0000e1cec2c00feL },
  44514. { 0x0805cb9da4a0912L,0x05bb522085e527aL,0x0e3bb1c7596f49fL,
  44515. 0x16902d0935de7b9L,0x08b24635780fbb2L,0x02273477b538135L,
  44516. 0x1d2a0558972204bL,0x1c8c49846589af4L,0x081a770374b1631L,
  44517. 0x0727bf8edc8be17L,0x1197f47d87b6541L,0x009397bcdc7a3a0L,
  44518. 0x01d7131fcfb1048L,0x056d238ab1be706L,0x1a65c988b936f0aL,
  44519. 0x0e8a1eea618b959L,0x113a0160dccee28L,0x0489973385dc8d7L } },
  44520. /* 135 */
  44521. { { 0x057efe27996099dL,0x1a26dd037304640L,0x1d0342561622dc8L,
  44522. 0x0cf3cb5dd3d6950L,0x108a2fade53daf0L,0x1f383564ab054d4L,
  44523. 0x091a9fd2f84c441L,0x1ccdabe7b365060L,0x0a5f8e8da27cca3L,
  44524. 0x1a8ee5326147949L,0x08c43bcc77f5e3aL,0x0f845940e7ca99fL,
  44525. 0x14a40da68392e0cL,0x1a869c7e08178b4L,0x16b80d45aec1f31L,
  44526. 0x193bae07d07c575L,0x0d1ea93c066b4d3L,0x03e8581f2bcca07L },
  44527. { 0x1e7ea304dd94c63L,0x180e2b9c5859d2fL,0x1e328539ad2d5fbL,
  44528. 0x1d4a6a64ed2a694L,0x1c22d00607622cdL,0x035904d7b4b503bL,
  44529. 0x0ad29ccf06219f5L,0x0992ca99976c4d8L,0x0a098d3a1a84f3cL,
  44530. 0x0cb7cf696b9a5baL,0x0c086975547240dL,0x1a5e3d8a247fbfaL,
  44531. 0x05b2c1aa39e2ba7L,0x1c759493fcb9349L,0x064a9bf4b9d743bL,
  44532. 0x1ca1df574e25c32L,0x060a606b43a9b83L,0x018d8bc17ed5aefL } },
  44533. /* 136 */
  44534. { { 0x18dba454034db92L,0x1bc80c79a6e26c3L,0x1cbb7dd530ce8e5L,
  44535. 0x159aac75111a009L,0x1b5ffad1eaa5954L,0x0c5edc514eb644dL,
  44536. 0x16d1ea2b7d956c3L,0x0b7eff7085b19b7L,0x1b72e3a0380d320L,
  44537. 0x19ad8593e563e54L,0x182f2f62951d770L,0x0e33d749a4bfff8L,
  44538. 0x180c50fca6736f7L,0x00600c801ec80e1L,0x007e1347f6b3deeL,
  44539. 0x17782eb9ecb1eadL,0x11f57a7e6345cefL,0x037e07df29f03f6L },
  44540. { 0x16d116bb81b0e5fL,0x0e952956429dc24L,0x0b50c9ce1fc360bL,
  44541. 0x09752258b26afc4L,0x09d5dcc13e332a8L,0x06c2e9c5b8e321aL,
  44542. 0x135383260bba50eL,0x1c72172aa797effL,0x12cb39bbc38fed5L,
  44543. 0x1633e4e2d621481L,0x08485efc1f69568L,0x0b5b4173c9ddd7eL,
  44544. 0x028ee9e0c655ac0L,0x045db71f885d896L,0x011ba4573cebb95L,
  44545. 0x0aa7e95ce4d3916L,0x1c8cb266012aa0eL,0x0380c9ad0d4a647L } },
  44546. /* 137 */
  44547. { { 0x058d41da4626deaL,0x1b3650adc81cfefL,0x0290c593996c97bL,
  44548. 0x1ae919f99f33502L,0x0f142fa99fe6daaL,0x038bcb3d5cd35e9L,
  44549. 0x08e6e932e85a175L,0x0ec25a6166cd787L,0x01f46a5dc8bf450L,
  44550. 0x03472948a10d607L,0x01881966ee8712eL,0x0a5db4d31720f4dL,
  44551. 0x14e54537072b4b5L,0x0f480b2fa81cee6L,0x15177f10a81ea7aL,
  44552. 0x1d6615071ffe7afL,0x00041991e5a3b5cL,0x0364b0f644b4e53L },
  44553. { 0x03bdc1bc4e7eb46L,0x162abacb63da438L,0x1f359abf5d375aeL,
  44554. 0x0acad9cde69f322L,0x124971755635510L,0x17fd969e8fda861L,
  44555. 0x08af7f699e0f98fL,0x1ef7af3e3e7ddf5L,0x0a4efbe5417af9eL,
  44556. 0x077b2312d2adbd2L,0x1cc8e069c4cc11bL,0x14ff72ac4b4622dL,
  44557. 0x1a0b027e96db2a2L,0x041959de3505521L,0x17eab01163f9749L,
  44558. 0x0ff34a46831beb5L,0x153c05a89cbc49eL,0x0418441ec34f125L } },
  44559. /* 138 */
  44560. { { 0x19b1c6202557389L,0x0e74bd6f7e05e4aL,0x19fe0cc3ce0d7f9L,
  44561. 0x1e2d9f703d12777L,0x104428fd27e0c6aL,0x0f30c137b2732deL,
  44562. 0x047294f7a4916deL,0x1261146278290fcL,0x065cec3b9445bceL,
  44563. 0x1de018a6b3f6a4fL,0x0dac90c1e08d48cL,0x1b5f275a63a4d3eL,
  44564. 0x10c780890cd78e5L,0x0f22f7f4f93415bL,0x12ebfa9c0570d3eL,
  44565. 0x198d826ba9749cdL,0x18c43a378a47e3fL,0x011bb7cbfcb31c7L },
  44566. { 0x06e1ec0ae575b99L,0x065a7c0dcb86e05L,0x00934e9ce51df85L,
  44567. 0x03f646b53be0147L,0x1bf629440b4b9c8L,0x0b2ebd468a88afaL,
  44568. 0x0f8ef3f4d6d0c78L,0x0f6ba25fd4565dcL,0x0629984a6f5182eL,
  44569. 0x121f179e1b2e847L,0x09c244c3cdb9c93L,0x1401fa68a803326L,
  44570. 0x0ebaf96dce698b4L,0x11b3aaaa11e27e8L,0x0c95e12982e82b8L,
  44571. 0x0c942a37b585b60L,0x0968ab4190a2154L,0x046230b30b5f881L } },
  44572. /* 139 */
  44573. { { 0x1fca2582d1f36a5L,0x1695944a62f96f7L,0x16e10f3b613c3b7L,
  44574. 0x05b61c77366b4b9L,0x0719a112290f898L,0x11b16b667075780L,
  44575. 0x1f91f43995f90e6L,0x028aa2d4abac4d2L,0x0269e1f778e6365L,
  44576. 0x11ef6e5ea8134deL,0x108c0110715f157L,0x06398e0aaf1bd9dL,
  44577. 0x131e489eabdb83fL,0x1cafe6da0def7dbL,0x076c00482d9e33cL,
  44578. 0x059912119f239ffL,0x162cbebc6f455f5L,0x00aaf53115a6308L },
  44579. { 0x0be2f1f876fa42eL,0x143a4bfd6f773caL,0x03d4e32196bead7L,
  44580. 0x09bf00b360d25ceL,0x0b5a7ac916e99b8L,0x031e958675b0374L,
  44581. 0x026833b48cd5cb5L,0x1be5a1e4c465534L,0x12529998c3861fbL,
  44582. 0x08c4453e0df1885L,0x08a714362ab78dcL,0x16f07626a67b362L,
  44583. 0x18ff029708dbcf9L,0x0d41f7c41e53a37L,0x0ca111296804e87L,
  44584. 0x095751d209a3095L,0x0c32fe84b3dbcbdL,0x047ab879212c82cL } },
  44585. /* 140 */
  44586. { { 0x0b66c8a2ca9c508L,0x0df6134eb5bc06fL,0x099a23ab5800b71L,
  44587. 0x0e93ae4c282dac2L,0x0e472e6f61841b9L,0x13d43b20f207366L,
  44588. 0x05e82b68909907eL,0x1e88b73fa679873L,0x1b25e8fa97c15dcL,
  44589. 0x09267590974b14eL,0x11cb19f6cf65580L,0x1a56f834f088751L,
  44590. 0x066dd027ff8e2deL,0x1f3d15e34a5584eL,0x1c31d8fe26815f5L,
  44591. 0x0c4255b17e44d9eL,0x01d4cb268e7c8a2L,0x01e8b8f43d96226L },
  44592. { 0x02ac16e8ce49820L,0x122f1606226e49cL,0x0449cfa1631093bL,
  44593. 0x188c64f9f21d8cfL,0x06159c1f918cb25L,0x0a2e59a1f1c3b5eL,
  44594. 0x0d1fadadb8380ddL,0x082c9707356ba24L,0x172e09274a300d5L,
  44595. 0x1559473440e08b4L,0x003fffadd6a10c9L,0x05946b2241be94bL,
  44596. 0x103209f4a30a580L,0x073549c03ff7416L,0x1b8472ad46005aeL,
  44597. 0x09d8f7338d8e185L,0x00416105af1ab9dL,0x011a74c7c1a66c8L } },
  44598. /* 141 */
  44599. { { 0x143520814db9cdaL,0x1ee23cb56f6487fL,0x09bebd162db6673L,
  44600. 0x0ae87d546308755L,0x01735d813f1f741L,0x02caeac8af0c973L,
  44601. 0x0f234d10688b42bL,0x06ce0977ecf8089L,0x12f960471be23a2L,
  44602. 0x01931c40ae8eaabL,0x008c2ddac776533L,0x073e183914cf282L,
  44603. 0x0c833c910df2e54L,0x032dc26fab58a0dL,0x1c0aded19f2667eL,
  44604. 0x0d2a03604a3f443L,0x093de5b52609621L,0x035109871e71d0fL },
  44605. { 0x01b67a04b3ca1a7L,0x176a98060674069L,0x0da24cb3c1eabd0L,
  44606. 0x02b84b86b44599aL,0x0dd04d0636523a8L,0x1c9d1df66e9cac4L,
  44607. 0x0d4c1cf68d40acbL,0x0ee98bc1879abcbL,0x0ef9f5486132687L,
  44608. 0x0c3ff7e0f3a1149L,0x0b0a7a89397b7bbL,0x13e067093e34db3L,
  44609. 0x1240f2390508abcL,0x1fc9a1a9d84d914L,0x0bad5419e441cb1L,
  44610. 0x170e02054c703cdL,0x0303ee0740996feL,0x01a7837d54e2694L } },
  44611. /* 142 */
  44612. { { 0x09dc79f2348f005L,0x02eb8efa49058c3L,0x1f29b7b992926d7L,
  44613. 0x09d0549f69fa36aL,0x1957836621b7f73L,0x143ecb31be5c1a5L,
  44614. 0x1b2af24d0406df4L,0x1c62b21f1580725L,0x0280dc3737f75f4L,
  44615. 0x19b7a87b530d631L,0x160c129955a36a2L,0x0553b2610e14e9eL,
  44616. 0x12fc8895cc80d79L,0x048a49cfb68bd8cL,0x0756e79260e4be9L,
  44617. 0x1056b5e6c04fba8L,0x11a452d79e25caaL,0x03b26a3d8fa08aeL },
  44618. { 0x1f22303a2ee8b9cL,0x1b969c2efe6a42eL,0x060c4204e8dc6e7L,
  44619. 0x167bce83ead6857L,0x1303bb5be28c523L,0x0dfcd7842bb12d7L,
  44620. 0x16cd249bca66ab2L,0x01c437d58101a88L,0x06a523a02d6ba2cL,
  44621. 0x18150d8bfe71432L,0x1a88d78c0307ab8L,0x06d4f69526228a2L,
  44622. 0x08c0cc89f745437L,0x0076c46f69e05cfL,0x0dff1c01206413dL,
  44623. 0x12e709e4d36ac79L,0x01009a1d53a321bL,0x00e06ece191851cL } },
  44624. /* 143 */
  44625. { { 0x1aa1f67c46a7d9aL,0x0199a5f6fc8e67fL,0x09d11e90bcb991dL,
  44626. 0x02483ff5528b067L,0x135efe6b6798005L,0x059201b84bcd421L,
  44627. 0x047717c184fd7c2L,0x1f8d7645f9ac9e4L,0x0e1b8b2a3a0572cL,
  44628. 0x0f075a0bca850a5L,0x12eca4fadb35306L,0x164a8e144bffcc6L,
  44629. 0x09a3d15a0a31a04L,0x1f97f6f4d20fbd6L,0x0e52803bfb617b2L,
  44630. 0x142b83eb03ebf03L,0x1bcaa3996b09ef4L,0x0296c5f1cd83020L },
  44631. { 0x11536f6fd631a2fL,0x173f859a8d46e5eL,0x031e6c49884a47eL,
  44632. 0x1e57a1e86ba34b2L,0x12b0ea7052d4875L,0x1d5c4f4d76db69cL,
  44633. 0x064b02f42af72e0L,0x1b504f420c513fcL,0x06566a960102a0bL,
  44634. 0x104181be701b40aL,0x1b5e7d618e50176L,0x136db7951bf2617L,
  44635. 0x06efdaa3f597201L,0x091b5c494490094L,0x1f0b9ceccdee659L,
  44636. 0x11b4623a7c71c51L,0x05d70787f41880eL,0x0367fb1b3ed7252L } },
  44637. /* 144 */
  44638. { { 0x13d0433f89a8bb4L,0x02619c9dcc7b8deL,0x1b200d1c28b5085L,
  44639. 0x0fcbb4113d056c2L,0x1bf5fda698fcc75L,0x1e9a662a11aa77bL,
  44640. 0x174346217094e7aL,0x1945c41650b7d8bL,0x0e71bbbe1782a1bL,
  44641. 0x0cef6984dc2a778L,0x1265e6265fe9aa5L,0x1f51b03e788a2e4L,
  44642. 0x1760c1115250cf8L,0x167c22f554d1da8L,0x1fb446f26c3bdf7L,
  44643. 0x0c10192673c4773L,0x1e7c93e9c5c2825L,0x00e96410bb09f60L },
  44644. { 0x181347d987cfc93L,0x101ddf8c3fc0839L,0x1274494328c411dL,
  44645. 0x01760ab7e67f4d7L,0x1a3af87c480091eL,0x02a055defcaf8d1L,
  44646. 0x0116f89a1ddc050L,0x05b331bee61affcL,0x0b398135fb723bcL,
  44647. 0x01187c60af5f623L,0x1860c17d558702bL,0x1e99b4c148ffc11L,
  44648. 0x04e16d4bfc7c0fbL,0x1a30bf490374ae1L,0x1830839d058d255L,
  44649. 0x1c56c72e330d295L,0x122fe2693122131L,0x012a4371b0529bbL } },
  44650. /* 145 */
  44651. { { 0x18795ca53572806L,0x04a24b2b4b470b0L,0x125cfecc8ebacb2L,
  44652. 0x0c81378fac29385L,0x079121b3fb15de2L,0x0655ddd4866d396L,
  44653. 0x10495b4be853881L,0x08f979b4def22c0L,0x025086261b435f9L,
  44654. 0x1b4361c61417588L,0x05b58bc69e472f6L,0x1da2c3444cd8a20L,
  44655. 0x06271d74a66b1c7L,0x012143d2133c033L,0x193c3ced7ffb686L,
  44656. 0x054e997ca07ff77L,0x1f1d7f7f0beb948L,0x03a8d91ac044249L },
  44657. { 0x197b9d6e9c9be68L,0x05ae233e886366aL,0x10f5dd8acbd05e5L,
  44658. 0x1543689c235119bL,0x0aa8eca86d94a63L,0x11ec3ffd85dddcdL,
  44659. 0x01d77d2c3cb4325L,0x1136ea60c58bb8eL,0x0fed726ac499339L,
  44660. 0x0d3031c2bfce66fL,0x10e4a9d7e31d997L,0x1b2abb8ce594443L,
  44661. 0x02b66ecc8dcd264L,0x0c522c5d38027f9L,0x0af594fec6aa6b8L,
  44662. 0x1bcf9d52c89bf17L,0x075a9378e802ba0L,0x00a266096e51636L } },
  44663. /* 146 */
  44664. { { 0x13a0a1d2989aa3aL,0x19141acf37326acL,0x032f4cb9ccbb60fL,
  44665. 0x0a78796493d2716L,0x189ea6acf4c464cL,0x167e194ba852fc7L,
  44666. 0x0e02519f96efcd1L,0x0db937f573a6f65L,0x0f8eb74533b339cL,
  44667. 0x1f00fdf1dbb36f7L,0x150953bdaba89cfL,0x1be4f7cc3621662L,
  44668. 0x01dd818488555c3L,0x1df38a7cb87db6cL,0x063da4f686bce92L,
  44669. 0x17072aebe402f3aL,0x151dc08fc6b2465L,0x043a76799b5c254L },
  44670. { 0x04af83ebbb3f6beL,0x07ddc845da11eb1L,0x02eb5e1cd49fd5eL,
  44671. 0x114c5c0884ac476L,0x1e236f79c3659bdL,0x1f93531481d8b3fL,
  44672. 0x04b3d5690c31b94L,0x056444a8f5c75aeL,0x1b73890d776eb27L,
  44673. 0x0da7b859eb146fcL,0x184ec14fab92b25L,0x0271cfe42e9d3e1L,
  44674. 0x1998dbae175b4f5L,0x0228c2403aa4167L,0x1fbc570ada6ef79L,
  44675. 0x15e329e4f2ca595L,0x14fa0a3ef2bb6bcL,0x018fdc2c0e72631L } },
  44676. /* 147 */
  44677. { { 0x18306d1615cd607L,0x04fd5551961d31cL,0x016ddde44c75a03L,
  44678. 0x146ce11601d0f4eL,0x1445297f1031013L,0x13cdab40a7d070cL,
  44679. 0x0fb51c31560ea9aL,0x1a60607397e962dL,0x118a7ca8daaaaf8L,
  44680. 0x198acf3ae6db452L,0x039ce348e053ebcL,0x0e311a1e9f3fbd4L,
  44681. 0x09dcdff032eb352L,0x1ea419c5d85bb30L,0x17541e996ea3aa4L,
  44682. 0x0a16830089b04abL,0x054844a223e4a4aL,0x04c1918000c70cfL },
  44683. { 0x0a2102757f3d5a6L,0x12b24374656e694L,0x006c09547cefff3L,
  44684. 0x1f26bd7be32b207L,0x0083aa6eb26cc64L,0x1267a0b0308948eL,
  44685. 0x0c6d73662299a23L,0x03ab0387ee7baa7L,0x078c804a977fc62L,
  44686. 0x0c3a1987d6e517dL,0x02369320f33c08cL,0x143b4f348e0fee0L,
  44687. 0x1f4a915eb5c4122L,0x08091b304d47069L,0x1ab4a828b7855f7L,
  44688. 0x1650a8bde8764cbL,0x0aad0a22ade188dL,0x0455df1cf491706L } },
  44689. /* 148 */
  44690. { { 0x04469053a2d2f01L,0x018c9aee3342e5aL,0x0efc75d2809f49fL,
  44691. 0x1eb6a1d83ad5211L,0x1f3c2e2601da350L,0x1b77490e9eea2f1L,
  44692. 0x05e73d9b84742e0L,0x068fc07211e8e97L,0x119e7c5b998b878L,
  44693. 0x1a0e9ff5e9e8ef4L,0x1a3a347bd8166e9L,0x12726ce9c48ec78L,
  44694. 0x073e7e67f69b9ffL,0x1774f1240ebea9fL,0x0f66131a6370c9aL,
  44695. 0x1d14ea5e47db567L,0x095f95e31b06f8fL,0x0078ada6861e85dL },
  44696. { 0x12f6635790a8d85L,0x1fdd7712cad78c7L,0x1b1892d44a1d46fL,
  44697. 0x166468e2bba2b6fL,0x0bc5441d7639b6aL,0x082c19866ea94c9L,
  44698. 0x18d8152003a93dbL,0x02643dfaea5edadL,0x1c0b7ffe5192906L,
  44699. 0x1452c12f7544c66L,0x16ea488a60899adL,0x036177a0d765d9dL,
  44700. 0x004bb6b0cb678a9L,0x057c754c5921b6eL,0x0a816ef3dea679fL,
  44701. 0x07d63725a1cdce3L,0x1dbbf8d0471f599L,0x028aed9bc101c2eL } },
  44702. /* 149 */
  44703. { { 0x043eaaa6f5bef22L,0x0934c101a438977L,0x0139e8ebdb1a54bL,
  44704. 0x0d351928063c989L,0x1001899a18d434cL,0x07520631f2eba0aL,
  44705. 0x01c8548e36ef3faL,0x1d194d991a52cf3L,0x073db6aee04acbdL,
  44706. 0x1b49946dbfcc9e7L,0x1e6efeb5178cd2fL,0x1926f83e2c6147eL,
  44707. 0x1f9b00a6de8c51eL,0x096c15e1a483992L,0x1167f25279ab2d0L,
  44708. 0x09c76b20366da1dL,0x002cb09b7109cf3L,0x016f0243f0d5fa6L },
  44709. { 0x0b722f38dd9d484L,0x049c9be3bdd660cL,0x03c64f64ae2a0cdL,
  44710. 0x011c7f584ab1b77L,0x145f4a7d80d78d5L,0x1e614ef82804c0bL,
  44711. 0x027e341caffb61dL,0x1aecf57f1e58615L,0x092c567ea9a0820L,
  44712. 0x12d5897451d2b9cL,0x0bebafc155486d0L,0x1e4d729d4bd382cL,
  44713. 0x143d71e546ee1c4L,0x01f45f0e8f20a4cL,0x07ab82c96060ee1L,
  44714. 0x094608922f905dfL,0x06e6813a4577387L,0x037b56038e6217cL } },
  44715. /* 150 */
  44716. { { 0x18822ad4dd6e3b1L,0x070e656b10434e9L,0x0114b2b37a03f1eL,
  44717. 0x15508d3fc7cf087L,0x067e8ef2121cc14L,0x1a3a2447479ed3fL,
  44718. 0x0c7d36e0f45b934L,0x02e7743bb30f30cL,0x1dfab59770a4c4cL,
  44719. 0x18509831f6e380fL,0x075805b363fca07L,0x0617798ab7928c9L,
  44720. 0x005760412a22672L,0x1947d77b0150ce3L,0x1faab671c6757c4L,
  44721. 0x15f6a4f972d3decL,0x0cbf342530e719bL,0x0371612667fad41L },
  44722. { 0x113024badaf8793L,0x1e67881ae4a4731L,0x1ade54d402fe512L,
  44723. 0x0c3a22cecbd340cL,0x1fd93c787991a94L,0x172a4acad6ed974L,
  44724. 0x1973c174b00dfa4L,0x0e59628b6313e07L,0x181ae48ca95aa1fL,
  44725. 0x01f938109ad3727L,0x1bd68926ca9f548L,0x120005afe546579L,
  44726. 0x086c6745b00687aL,0x0328398297be991L,0x037163cf6a2a1d6L,
  44727. 0x0230b7c7171085dL,0x1916b48bf34dbf1L,0x02d7bfe86cbe047L } },
  44728. /* 151 */
  44729. { { 0x1f9b950f4a224a5L,0x022ba6628139d2aL,0x0cc190fc7f55064L,
  44730. 0x161ca1ef0669f02L,0x09581712996801bL,0x048e9b4336ba01cL,
  44731. 0x1bf9f6e69017690L,0x0d1e3c6f3be2d48L,0x08d04a93f83bf91L,
  44732. 0x126419a995905e5L,0x0cd2c7dca87042bL,0x12efb032bb6933aL,
  44733. 0x1ffba14b5d8fbc9L,0x1b6d7a3b65759efL,0x16dcbd183fbc089L,
  44734. 0x160c497291bfdb6L,0x0ae5185c925b6dfL,0x013d4e1c0cb04eaL },
  44735. { 0x1c37346f12a93afL,0x1b83e2a9b31a6b9L,0x035526064f440a2L,
  44736. 0x19de436d3b1df4bL,0x0788a0e24f83a5cL,0x189e4c02e5d851dL,
  44737. 0x1e130040c5e0596L,0x1e5fd441cb056e6L,0x1df9713a0e50361L,
  44738. 0x0a24d07e866116cL,0x1d4b9df178b86ccL,0x0d7b6ce0899e306L,
  44739. 0x15733e177a6e44dL,0x047716118096ef4L,0x17c6525a2d259a4L,
  44740. 0x110dfb3760a823eL,0x04495182c716acdL,0x00e34834a7def49L } },
  44741. /* 152 */
  44742. { { 0x1b67d173a880026L,0x07850092ecaf92eL,0x1544fdb2de92271L,
  44743. 0x02b977b94a520a0L,0x172bcbd33eb231dL,0x0ad01d7c67fe4ccL,
  44744. 0x1f0bf2d3bd352b5L,0x14b289a8f94450cL,0x196d885480ead1aL,
  44745. 0x152be7c65e45822L,0x16112c01795681dL,0x1c323a31412fbfcL,
  44746. 0x0852923c745e9e7L,0x1faed99ccabd137L,0x0fb43234219ede5L,
  44747. 0x1a4784aa6811cc7L,0x1391596e5d5689aL,0x03dc609eb528261L },
  44748. { 0x1c43aad52fb6901L,0x189fc8b65129d97L,0x0c29456ab718700L,
  44749. 0x0cfeaefb8428eb0L,0x1723c0ddc93d192L,0x1cfb6d137297477L,
  44750. 0x0ddb4bc783ae0faL,0x07332f3bd05e300L,0x143e28ecbb08349L,
  44751. 0x116a8ee51ce1c73L,0x018ea6a38fdad66L,0x1474973664e0dccL,
  44752. 0x02d2f8915d4cf1dL,0x08283c893729a45L,0x14e0fe979d78f81L,
  44753. 0x1f6535dff9cae41L,0x0d01d6d53cc8fd2L,0x0071e1f7b34b7a6L } },
  44754. /* 153 */
  44755. { { 0x1c337c121ee1d83L,0x047b6bc3dbbc41dL,0x1f304e3e933a5f8L,
  44756. 0x0f40691cb17ee13L,0x055e672dbaf7764L,0x0f62ee827c5d5e5L,
  44757. 0x048603b4a4675f5L,0x15f19cc97fe67d3L,0x0ac09fc5724b059L,
  44758. 0x03418fcee2f195dL,0x0899dd196bdaa54L,0x1ccd92fe3ff04d4L,
  44759. 0x16bc6087fd3c5efL,0x15476e358a8af06L,0x1e7b4a6c68e717aL,
  44760. 0x111707bb02d761cL,0x11c6cc13769bc37L,0x023184c71e04952L },
  44761. { 0x06408c7c8bd0fa7L,0x12188e735ef249dL,0x0420a0fbdefb45dL,
  44762. 0x0f336bb271c62bcL,0x05a49a6b8213cc7L,0x14f268d7bf8ac0aL,
  44763. 0x1275b403f6c3f94L,0x0a4aba71eef9ccdL,0x0b4f7ccc01bd4b9L,
  44764. 0x0cbada4d7b8fcc3L,0x167f2f3593402a3L,0x0a094b4775ae256L,
  44765. 0x042b5c89f11860eL,0x1d1f118fb6cbb02L,0x032ea4bfb431965L,
  44766. 0x1c23cb02298662fL,0x05ae2e74c066698L,0x03fc7e849d1a45cL } },
  44767. /* 154 */
  44768. { { 0x04592cac19428afL,0x10e409d184332f9L,0x004b8c2ef5fc64aL,
  44769. 0x0706d8d77284b13L,0x198e498710db072L,0x16b7a5ce3d20f4aL,
  44770. 0x0b1122bfc5e79baL,0x07ce1f1f372eb0cL,0x06b3b02376f2198L,
  44771. 0x0ec1f4dcc7328a9L,0x149aa35d4486289L,0x10353ade3b4c765L,
  44772. 0x05a5a81f7495082L,0x12343a38c6fbc68L,0x01f63335e7b9567L,
  44773. 0x0d92a40c194aecfL,0x131427a84ffa847L,0x043db2628f321a8L },
  44774. { 0x1f46f654b30d3c4L,0x0262e11da778a43L,0x1d998f2935a337bL,
  44775. 0x139e7f6adb676e8L,0x0fd7d46a1df3426L,0x14d45eea789ce20L,
  44776. 0x15f4a8edf1f1da9L,0x069dcad6993975bL,0x1b28ff342ac9423L,
  44777. 0x0237efd3c378ed1L,0x145272dc0320b80L,0x1f02a12ccb2f9cbL,
  44778. 0x09fcff4bddca30eL,0x024929342251030L,0x0087ce03cbd979dL,
  44779. 0x177a1cb6caa59a8L,0x0f577ea9c2a042dL,0x0464a933e6ce031L } },
  44780. /* 155 */
  44781. { { 0x055032e5fc1abb1L,0x0d7aa097f23a1b3L,0x1580a7c17bd4885L,
  44782. 0x0bb83237d3facaeL,0x008639b0b0e7332L,0x1f3339bd59e32f6L,
  44783. 0x155559d41fd4470L,0x15ac717df8790c2L,0x15d0188cf42f0c4L,
  44784. 0x01d180e6c4b0c36L,0x180fdecb19d07a1L,0x1819f479a3a008aL,
  44785. 0x1d4a40672ef7545L,0x02dcf46efb0957fL,0x048b5d15865f27dL,
  44786. 0x0b37f68a646fb0fL,0x016bf132e3a4b2dL,0x0457d0db9dc2535L },
  44787. { 0x13596eae793ac70L,0x077c7777b6e8835L,0x1e89c108b901325L,
  44788. 0x1dd3cbaec724d69L,0x1512aadfc8c71dcL,0x01cbaf9a97e5b87L,
  44789. 0x0ec4c6dee84e2a2L,0x1a2af3227200b18L,0x19692092a97740fL,
  44790. 0x0d6ca2d8b05834bL,0x0d0e20420deac86L,0x0389e2e976e378cL,
  44791. 0x01ab1b80eb76ee1L,0x187622c53088dfeL,0x0b4cc96f20aeb21L,
  44792. 0x15b91ddcc024e62L,0x13cb4118b1ab240L,0x0339088c895ad04L } },
  44793. /* 156 */
  44794. { { 0x1e99306f55cf9bfL,0x029845235cb6cc8L,0x187679e9977e6c1L,
  44795. 0x038e6379775c783L,0x04d58a61453cb15L,0x03a6610a5f2913dL,
  44796. 0x00358e76b248a5fL,0x1be9a1ef48b045cL,0x1afeb1d51c62b03L,
  44797. 0x18ee1d25d50c596L,0x11c5e37cadd3c2eL,0x114d12d6d466fe7L,
  44798. 0x141dce055ffcd32L,0x152715c3f4af6a2L,0x16773a65fef1dadL,
  44799. 0x0cf83cbd8cfe3f4L,0x1fe052368accc03L,0x03e431c8b2a7251L },
  44800. { 0x1e94b5eca7388cfL,0x005306019ae9c2aL,0x1e2d85be16e85f3L,
  44801. 0x1e2024530136d36L,0x1cfd0a79705d02eL,0x0f71a92b2d37400L,
  44802. 0x076b7add2a5b5f4L,0x01eb91065da84f7L,0x096ea8528e6d533L,
  44803. 0x06c43158c692774L,0x0e3b567fe4e7dccL,0x1344020c04a539aL,
  44804. 0x182303b3ff690fcL,0x0ea95a34e316c45L,0x0b4b64ff10b5e93L,
  44805. 0x008700df1bf4519L,0x1ad502360906092L,0x0192c13ac7e742aL } },
  44806. /* 157 */
  44807. { { 0x120e45f359e8c60L,0x1dc529b2650c375L,0x01c77fe384431c6L,
  44808. 0x069927caf00562aL,0x1829d0d8074e91dL,0x1541fd601937005L,
  44809. 0x08278f064896189L,0x10470f4c9abf653L,0x1caaa3d34e5ac5cL,
  44810. 0x16b42f2d6d16d14L,0x08099faca5943a3L,0x1632ec7005e724eL,
  44811. 0x0edf6b1aeaf7184L,0x12f3092e91faee8L,0x01ca86af87e8d1cL,
  44812. 0x1875fac50ff3a19L,0x05649aa93d2ac57L,0x00d273538aded3bL },
  44813. { 0x0126ede554d1267L,0x0a2998e6815a40dL,0x013338c7ec74dfeL,
  44814. 0x1612fb8025ae15eL,0x16c7b6c5cf410b0L,0x048842c9870e8b9L,
  44815. 0x18e3e40bfb9071aL,0x1be6937494ef3f6L,0x0a16c5821acd6f8L,
  44816. 0x19dc1e09703b567L,0x140cef94074537eL,0x08a441e5a5b4d71L,
  44817. 0x0d99df18800593dL,0x0ff599d31ba9293L,0x1bbd15b28c8d472L,
  44818. 0x1b915b22687783eL,0x032c74857db35b9L,0x042b53e49c2da74L } },
  44819. /* 158 */
  44820. { { 0x007d0020d0a5583L,0x180eef6d232c550L,0x0590d364e6f8bc4L,
  44821. 0x014e18106d2380fL,0x1e81e540a0cb678L,0x05645c605a6fcadL,
  44822. 0x188e5b2ef34d175L,0x16caf8a5da0a8eaL,0x1cac2dca41805ceL,
  44823. 0x0af7355bc9a212aL,0x17bcc493268a9a4L,0x0c5f18258ce86cdL,
  44824. 0x1b7dbb7c3bbd3b9L,0x1115dcadd55b278L,0x118edd0f039154fL,
  44825. 0x14c624811fd7589L,0x0403ca773122a4dL,0x031444842631b6dL },
  44826. { 0x057fd538cb8d208L,0x1c004aa1f836a52L,0x0553cbbfcaadea3L,
  44827. 0x17ee4a2fcf6cdbcL,0x19389d2cfddb28eL,0x0dc46700a4ff337L,
  44828. 0x10fdde7a1dcff61L,0x1808a5c1216174aL,0x1deb9b5cfb0b03fL,
  44829. 0x089a245362f6bbdL,0x07cf3e3ff00dc8cL,0x08dab83698946c1L,
  44830. 0x138fa59be92bc9cL,0x06d81348f3379dfL,0x07e23e44e5afd7fL,
  44831. 0x1bfc7e3d8b3a801L,0x158c29034562ad9L,0x03cec09162d6d26L } },
  44832. /* 159 */
  44833. { { 0x0d4e4ceaa529507L,0x1040a3a32ae800aL,0x08e13c3f11d015aL,
  44834. 0x146887971d81a61L,0x17f1728d8a8203eL,0x1077a919e317d84L,
  44835. 0x074fa28e373f6d4L,0x0a141f21abaf959L,0x128a7b0bf873ceaL,
  44836. 0x08ad71d363620e5L,0x05c76a84e04b074L,0x174ac49aa0fd46aL,
  44837. 0x097e98f42f25d4bL,0x0b5209b8c8ed694L,0x0796ddfff5ac7a6L,
  44838. 0x1ee0fa8d8424b6dL,0x17ac7d2b42420c4L,0x01559d7cac0a12aL },
  44839. { 0x0ca074c6a5372a6L,0x1dc1f2b1495d3c3L,0x1b71ddd073d5ca3L,
  44840. 0x02a41de93ae8ab2L,0x01e4647270b4ceaL,0x1c562e8a397f1a3L,
  44841. 0x101c7d35af598feL,0x0c28dca59938217L,0x128794efe371a34L,
  44842. 0x042838c13b7f43bL,0x155dce6fbd6ad29L,0x13fe7e2b902bdb5L,
  44843. 0x058f8395c324c2dL,0x005b542a8c44a87L,0x0200f86eb90265aL,
  44844. 0x04bdc9ea7c45915L,0x1caaf233f61039dL,0x003ed961a928204L } },
  44845. /* 160 */
  44846. { { 0x1f3b8db037d4703L,0x1846fe2fa445ce3L,0x0c3e11c7500ba0dL,
  44847. 0x04b45f55d23f750L,0x1404fc1ea55ee8dL,0x16ab28e172df882L,
  44848. 0x1d7e591f5409ea8L,0x17e6f4a7818fd75L,0x07adf0bb295b30aL,
  44849. 0x13170ff6b2649ddL,0x1063038bbd29e16L,0x13b29a59a09efffL,
  44850. 0x175ea0af02139ddL,0x07f7cd67929fdd5L,0x1856a9df20403a8L,
  44851. 0x040d2e98a709b90L,0x159cb28682d9fe5L,0x0045b6547e7beebL },
  44852. { 0x04e5bea036c3b5aL,0x130813fcf95a5f0L,0x15c0a5e5f03ce1cL,
  44853. 0x17050f3d4753f94L,0x007f0ddf1656180L,0x1870438a99c4ddbL,
  44854. 0x1ff1e668488f19eL,0x0321a3011d93b12L,0x09470711a916edfL,
  44855. 0x07a97958390b88cL,0x0ca7ff462222dbeL,0x058a998df200bb1L,
  44856. 0x05eb24877fef1e2L,0x1aa3ca92e201b0bL,0x1851a2bf6a548ccL,
  44857. 0x17411ac454842d0L,0x1d25d043b0774faL,0x01619bd810698d3L } },
  44858. /* 161 */
  44859. { { 0x12305bcea22fa65L,0x01f7a68acfb1d3dL,0x01f4fcd648fef86L,
  44860. 0x0d823aeea668e7bL,0x0a054cffb27fb30L,0x0c2b0cb8173f359L,
  44861. 0x14714f3a7e5f2bcL,0x0b706aa04869cfaL,0x1a63e3d82f356acL,
  44862. 0x13dbe556bb22898L,0x179abe99c7f2761L,0x1dbc560f9aefdd0L,
  44863. 0x10ffda51933b985L,0x14a16e1b03eacc5L,0x18862a6c43b28e6L,
  44864. 0x1ab942fe7b9dca0L,0x1c93d94e8d106b7L,0x0284d931a76c418L },
  44865. { 0x1b9414e48caed54L,0x1c63665fa8f4bd8L,0x123537a6c961de9L,
  44866. 0x1923dc7af148d11L,0x030ee64c0024137L,0x0c86bc5347c91a7L,
  44867. 0x1a42d5cc956f220L,0x09883d1c0bf7500L,0x050038d84ec354fL,
  44868. 0x0c7816b6fd2940bL,0x1e401f32d8ff6acL,0x01f7d315c8ab88fL,
  44869. 0x025d0e319d29d48L,0x0136db8ca5622e9L,0x0d61ee741bcd5d4L,
  44870. 0x0ee4ee6773c4058L,0x152224839922c31L,0x00ac96ad3aa5dc3L } },
  44871. /* 162 */
  44872. { { 0x178d9a2cf7453f0L,0x1c4cd76c1e0f82bL,0x1b4f82a0ae9ebfeL,
  44873. 0x15d47aa1035cca0L,0x010aa38b32c84e1L,0x1be820cd6a94604L,
  44874. 0x1907ec7f6c082f4L,0x1ecf1ad97c3a0d9L,0x0d287f0f02e74b7L,
  44875. 0x0e692bae21dd811L,0x03cbcfe069c6cfdL,0x03eb8c67cfe8da5L,
  44876. 0x1cc4fc580ee65bbL,0x1dbd83d29972fe0L,0x12abceb35554e7eL,
  44877. 0x05a5b6b5288e387L,0x17cb958bdf44cc2L,0x00b0a5edebbd13bL },
  44878. { 0x01f0230ed0ab04dL,0x03d803710417526L,0x118f10b16d7eb8dL,
  44879. 0x1fbc03326b3e217L,0x05dd0825b0539e6L,0x076d0b6c4dea73bL,
  44880. 0x128ca48983fbeefL,0x0bf1554eab9cc55L,0x0ed762fa95ec82cL,
  44881. 0x0f326008c3283b4L,0x15891724b8d2326L,0x14ee63d4dad0afbL,
  44882. 0x0b07b447360db88L,0x0b8eb87f7780095L,0x1e246c2e4d5ae50L,
  44883. 0x04145cd160c5007L,0x1283a54a53ab79cL,0x0244b2b63d80583L } },
  44884. /* 163 */
  44885. { { 0x03649ba71353c25L,0x193d089fb3f1272L,0x0ce8707ae78d45fL,
  44886. 0x18f1c537f2217a6L,0x0743f15d94e1c05L,0x0d16f8427f3ecbaL,
  44887. 0x0ef86721d242243L,0x16304807f4ea6ceL,0x17ebf5db41baea1L,
  44888. 0x1f0571a920c0756L,0x161cff0bd430ff3L,0x15ace0cc39b23a2L,
  44889. 0x19a51e8c2c16851L,0x100b084cc014b46L,0x09fa95b9f46a737L,
  44890. 0x18930562a791351L,0x1cb6d41b78906e3L,0x00415d974eb3b4eL },
  44891. { 0x180ef46c4d6615fL,0x14ee080dcc14e30L,0x1b003ec9932bf18L,
  44892. 0x0c21d98589bc445L,0x1eea2c4dc5457e0L,0x0e2d964ae72ccf8L,
  44893. 0x043e410cfe9ca3eL,0x0a7dc06a8c59ac6L,0x084c57c3bce2e22L,
  44894. 0x047618d4b6c3f22L,0x1f8e4e914b169dbL,0x0281408f646a617L,
  44895. 0x18c018545ec592bL,0x0e0bc6233dec5f0L,0x08c016de538041dL,
  44896. 0x0a9e6908e328c5cL,0x0422665e237622aL,0x01b228d23480e48L } },
  44897. /* 164 */
  44898. { { 0x1802d1819893e71L,0x12ec5a9cd10410bL,0x08048c0bb3f285dL,
  44899. 0x166cb7eb3bf8d5dL,0x0d232a808d4cf51L,0x140213c3ba0eb90L,
  44900. 0x0e7b2b0d0facc63L,0x194aa7d965fce8eL,0x0aeca79a81a8b07L,
  44901. 0x04ff9912b7a559dL,0x175ca4fe8747dc2L,0x135dec55342cbd2L,
  44902. 0x12aa08ddc226056L,0x0dbddaa52f3bb11L,0x0f55b9e4feafb0cL,
  44903. 0x17dfe914412ace8L,0x0f1749cdb12eb0eL,0x0382983d234dc7eL },
  44904. { 0x08e4c04e488310bL,0x137192992e6bdbdL,0x02c1260fbeb049cL,
  44905. 0x1805bb7226ba1fbL,0x17b9685c796e552L,0x0f9251877651fbbL,
  44906. 0x125e66dd9ba26c5L,0x0d8f84e6dac91dfL,0x03d619685a8021cL,
  44907. 0x119f13c505978f5L,0x1a61e6d9db5ac3fL,0x063235e9c17d2b8L,
  44908. 0x1136c4ee55a0747L,0x0cf2f9dcd17d5afL,0x12bf9b9a4e2e3fdL,
  44909. 0x1a2403c229b4873L,0x0ecc9595ec36a6aL,0x0407bcde82bf315L } },
  44910. /* 165 */
  44911. { { 0x0ef42a760af09b3L,0x0b75ec99eff0a1eL,0x0783b617aaa0f00L,
  44912. 0x1f9d547792e419eL,0x17106f97d4f5e99L,0x134569390b5ce95L,
  44913. 0x1947d97cd30db25L,0x1bd51f70578b618L,0x020f42f1cf2fda4L,
  44914. 0x198d596690fb2cfL,0x1ddb1e84f45863aL,0x004470cc57cb6f4L,
  44915. 0x10cad08e0bec441L,0x011600c06412ed3L,0x1be7ff664a641e4L,
  44916. 0x116a0ec477b4055L,0x119de84f4f3f5c5L,0x02fad2ed26c127fL },
  44917. { 0x137257e7e8311dcL,0x0a7a8a336789b2bL,0x1916c172886b7beL,
  44918. 0x1805c9566f4e7c2L,0x0579165b38ea9b3L,0x0580d23bb07564cL,
  44919. 0x156137ff7411f09L,0x1b4311a9fa27f72L,0x0faac38b825548bL,
  44920. 0x13cd3782cf4ee56L,0x1dc83c2689c03c6L,0x0aa9f714fc91307L,
  44921. 0x0847a1fad58cbbaL,0x0d5eb5af1c50ccbL,0x1c5bb084615951dL,
  44922. 0x120f6ea227a63e6L,0x0891391e7814212L,0x0298ce40086e0acL } },
  44923. /* 166 */
  44924. { { 0x120136e6b61c3afL,0x0796f03da5db411L,0x19fce0325fc0750L,
  44925. 0x00d5186274ca3bdL,0x0011ca10a978ba7L,0x0fa22d9162c3eb1L,
  44926. 0x1139922ee8862acL,0x1f318bd5e0fca08L,0x15549f02a442fccL,
  44927. 0x0b23a379ec0249eL,0x093d85e70116449L,0x143157b9110e85aL,
  44928. 0x0aded38f8f1600fL,0x091d75a32e5c300L,0x0715e2a92fe6e42L,
  44929. 0x1d429ac7fdc6a3cL,0x1f0f3c9c5acebb9L,0x01e8998a6f88d27L },
  44930. { 0x1cc662db4513d1eL,0x05462eaaca95ef2L,0x08ff9fe1b42b79eL,
  44931. 0x08f409e18bd146fL,0x0e25d06cca2d12aL,0x09b038a6334b721L,
  44932. 0x1872d49851a62c8L,0x0bde9a4e03713edL,0x1aafd617780efd9L,
  44933. 0x16b9d6262ddb483L,0x01d2b10836cd6b9L,0x1bc9e4ea3f4093dL,
  44934. 0x16a1fa2edd11631L,0x1bfebca6d94fb99L,0x0be4a993101a192L,
  44935. 0x198ece79643a7c4L,0x0adeae904e62043L,0x033f9454fd99163L } },
  44936. /* 167 */
  44937. { { 0x017b258ca148ab5L,0x0cbb7d9e30028beL,0x1a6323ca37e6e68L,
  44938. 0x09d1a8a02fd44c0L,0x0578a42287b2cc7L,0x1f63991b92b9948L,
  44939. 0x0ef120757b8945eL,0x1fdae823f9e3a91L,0x146217e6b487f5cL,
  44940. 0x1803d62a0f5c70dL,0x115e9b816803232L,0x1a57a5f3f533883L,
  44941. 0x1b40941cad1f954L,0x1c14a84e9b85eaeL,0x1b297bb921e1e70L,
  44942. 0x1f73c9826eaa4b9L,0x1b2e8ef7fa4fd3eL,0x02ff848ba0de8deL },
  44943. { 0x11912a4579c6632L,0x0d227dc51040abcL,0x0e114d58e74eec6L,
  44944. 0x177879379de9f2fL,0x119e6410e57e2bcL,0x0becd689159f95fL,
  44945. 0x1fd987c0627684dL,0x098ceaae776f3cbL,0x1444e5c98ef2f3cL,
  44946. 0x17b0f1002688398L,0x08d9beb1d758d75L,0x190c590a9e461bfL,
  44947. 0x1e0ad0850b9fc47L,0x17b906196025721L,0x14ef27573a53d90L,
  44948. 0x074c6cfdf5ccb4eL,0x046c27d30d3b037L,0x03340809d14b90bL } },
  44949. /* 168 */
  44950. { { 0x185d913e84509dfL,0x05f6ee799c9bb09L,0x174cd08e8523a5eL,
  44951. 0x07dd196af25be84L,0x11c4553c43fa0aeL,0x1f8ea4780a9b4e9L,
  44952. 0x09128173c22ef7eL,0x0675bfe97cd2888L,0x001635f81a35ddaL,
  44953. 0x02e44a4f3b7d5beL,0x1ff37859cdde0c2L,0x0a5944a9f1a497aL,
  44954. 0x06413ec985fd8cbL,0x1d481366310b453L,0x18786dfcb6e5d05L,
  44955. 0x1ffbc72c5dcaca1L,0x11fbee0a346d3beL,0x01d9adb9785efd5L },
  44956. { 0x1f8de9f535c3749L,0x0f907c56ece245fL,0x0def23e3d98c8f0L,
  44957. 0x0bd1e75c9352eb6L,0x1d5e26282529e47L,0x03178ee197886a8L,
  44958. 0x0f8d96b034a5d9eL,0x0c4278f26710a99L,0x148f004ef4b67e4L,
  44959. 0x11bd0a872e88770L,0x11de374a0a2283eL,0x14cd9f6e7e9a92eL,
  44960. 0x130780495296830L,0x0bb05b4a4fa2200L,0x0dd726608cf1c26L,
  44961. 0x1f3390681994a4bL,0x0853f62e40bc771L,0x023e850f5e6cae3L } },
  44962. /* 169 */
  44963. { { 0x06f4fff652811f1L,0x05549b177980113L,0x0955432e832baabL,
  44964. 0x1400fea8ced870fL,0x002f2673a350142L,0x0e3732e3fe88151L,
  44965. 0x18f6576bb95c0cfL,0x03cc0d05d860c94L,0x146cf0bb0462b25L,
  44966. 0x1018652aed49b73L,0x0983c90d0996d43L,0x0576d369d1eb90fL,
  44967. 0x0c7ad7770a9637bL,0x169d0ad3300fdacL,0x057a5847c851fdbL,
  44968. 0x0742c0b68fabc53L,0x05ccb0ca9b38321L,0x047a5b0a524cad4L },
  44969. { 0x0a8ec194b4eb3c1L,0x04d6210191d382dL,0x0c893db31aaa315L,
  44970. 0x168bf34b4601a92L,0x0897abbb0e53b9bL,0x166be8723778880L,
  44971. 0x0d623fa1cf95f5eL,0x1a2f9f99fca1ef9L,0x00ea53d65c85557L,
  44972. 0x0ecf5a239447971L,0x17b7eb03ada2a3fL,0x08e010c07419565L,
  44973. 0x0900feb06c58221L,0x12f2e55634a3234L,0x1246ba60133d6fcL,
  44974. 0x0bd5db0ab30b13fL,0x001ed9378b173c4L,0x047ca168129264cL } },
  44975. /* 170 */
  44976. { { 0x11ec3028e845808L,0x15ffd5bbd5fe28fL,0x12e7e365f71f0c0L,
  44977. 0x087558b2964d5faL,0x074d94dc3d3a83cL,0x12c88e71dba5e8bL,
  44978. 0x0b3491192dcdf2aL,0x1fcc524aee70e38L,0x1419f24853b4440L,
  44979. 0x0d35079f02956beL,0x0a035a11b21b037L,0x13f5f0649e84c8aL,
  44980. 0x0807cf117aa2568L,0x06ee4edbe3a568fL,0x1bf2175589b7a82L,
  44981. 0x1d6a6a4c406e72cL,0x0cbe0ad57c3f3b1L,0x01c1801294a4e0dL },
  44982. { 0x0ef5a405e744723L,0x1e7ba8d704240d0L,0x0333fb07ddbf6d6L,
  44983. 0x03f566ff8d57f5bL,0x08fedb78fba5d83L,0x09f9885f1cf1246L,
  44984. 0x17092973eb57eb6L,0x1eae8ffb63d227aL,0x1052a47c94518b7L,
  44985. 0x11046b63e7da193L,0x172e71c394e2fa7L,0x0eb2b762f22d626L,
  44986. 0x005b3106c736352L,0x0104dd8351603c4L,0x11412b74b50a81bL,
  44987. 0x1c0696a4b68e3a7L,0x1a5c9f4b368822cL,0x00af8c3cb75a0c2L } },
  44988. /* 171 */
  44989. { { 0x14dea060aee4684L,0x10f833e6dede404L,0x0526c64c4c650acL,
  44990. 0x03034fb74d4873cL,0x1c2ae80fea4bdd4L,0x011ee163109b831L,
  44991. 0x046c6d62c259c4aL,0x108e887aa2b064cL,0x02e16f83113c203L,
  44992. 0x071026b15ecc969L,0x16f35bd064e22c3L,0x1a3a3a6ef18e933L,
  44993. 0x0fc5ddae73492deL,0x0ca5b12cceadebaL,0x01b29a35204f54aL,
  44994. 0x18558323b39ec1dL,0x038562179eaf3e9L,0x030a378f9cff709L },
  44995. { 0x106d33e078e2aa6L,0x17bfbcef74932deL,0x1e076a903a11a4eL,
  44996. 0x11373480fdaadc1L,0x0de9951905fbbb8L,0x16dd1cee7a256e7L,
  44997. 0x1dd2dfdc7e34c24L,0x1d6ceb6bb4a8462L,0x07456a251a5f605L,
  44998. 0x018ea57c3d1cd4fL,0x0c001816d1d2f64L,0x17e56ccb5523b68L,
  44999. 0x156631eeb4bda5dL,0x111bbe2c2e8d1efL,0x1742ffc0a0527bdL,
  45000. 0x0cbbc5c35e9d2d0L,0x050e0ea087582a4L,0x04aaa1fcf035e80L } },
  45001. /* 172 */
  45002. { { 0x1cbc6f485d7c6efL,0x00426b1d8de127bL,0x1a22fe32e98b2b6L,
  45003. 0x0d68ab8325bf219L,0x174fc6ed98e4b68L,0x11003bb0a35c6abL,
  45004. 0x094a5c388e279ebL,0x1eaa48388f2c384L,0x17d2215103884e5L,
  45005. 0x16906710bf14139L,0x067d453c99d3e35L,0x00aae18023b7c62L,
  45006. 0x19fcfb760e85459L,0x0f46150cefd5baeL,0x1f52c9e5518d8aaL,
  45007. 0x0d31896da7f1494L,0x0ffa5c87104ee5dL,0x036da1a3c15d14bL },
  45008. { 0x04864935c3f0d95L,0x1edc1273a444a83L,0x1d89acbcf912245L,
  45009. 0x0856feae97ee7fbL,0x0f732723c60edc5L,0x1688a65f0e04d15L,
  45010. 0x0bfe5f4d19a75f2L,0x0392c8cc0146435L,0x0b94e2bbaed0cd6L,
  45011. 0x1370d20ef623a87L,0x1a6436c6a27d621L,0x1ad9e4eb2d27437L,
  45012. 0x00c0e0dddfc39e4L,0x0cce452088e7dbcL,0x070c143c2bf35ffL,
  45013. 0x18dc99d7ff5b6dcL,0x0944f3981b096d2L,0x003d3c8f395713dL } },
  45014. /* 173 */
  45015. { { 0x10e90471e9f0300L,0x09d6cde66fc8273L,0x0277fc14c1e3809L,
  45016. 0x1d5d1268c4a3805L,0x04846845f1ef092L,0x0d6a5a1648548d5L,
  45017. 0x19ec8651bb683c7L,0x029e0eca1e667beL,0x1c6e988db0b15a0L,
  45018. 0x17063375aa1787cL,0x0d8c478300de3dcL,0x1b555d0d2a1aba9L,
  45019. 0x0db35f1c8f548baL,0x0a268d6a3400b1cL,0x11c74c84a78c85aL,
  45020. 0x09bbd32a3759080L,0x0ac03cc29f385e9L,0x036b5661722a1f6L },
  45021. { 0x1999e9557b2d299L,0x1e6cdf1eb90e6f5L,0x013eed32d110e8aL,
  45022. 0x13b80c1f545cc07L,0x0c987cdeae17770L,0x1b7df6ba787369cL,
  45023. 0x1effe688df3e041L,0x108d35e2a26f307L,0x06c3f7a1d323f95L,
  45024. 0x110e567b6db21ccL,0x004d3e59c0f648fL,0x131f70727eecf9bL,
  45025. 0x1c2e82522207558L,0x1c92553e0dad945L,0x109ea2ade1e6705L,
  45026. 0x129243b66f1e502L,0x0eed5a451b1ff28L,0x03ce8c1091e9e23L } },
  45027. /* 174 */
  45028. { { 0x03edff9109d5589L,0x0975a014da24c8dL,0x14c2d2d52b7f7b5L,
  45029. 0x0344f7fece27d73L,0x07f0f4604f9214cL,0x1287142640bf73bL,
  45030. 0x188deeb7e360f0eL,0x1838bb807932804L,0x15f29581b966647L,
  45031. 0x05b5044c50343f9L,0x01f3b0c58d145c4L,0x174ac5cea3115cfL,
  45032. 0x0745e2c3fb2001dL,0x1b3e99caaaea70dL,0x1a10bbaff2b37aeL,
  45033. 0x0b01743415f3978L,0x1c850590a2b3e88L,0x039882248d3c266L },
  45034. { 0x0ca2cdf2648d676L,0x0f652a78d8958a2L,0x1250a60387ae6a1L,
  45035. 0x1235915512373b5L,0x0719e195f30d370L,0x181bcbb983955beL,
  45036. 0x19fdae9463208bdL,0x04f58121c295800L,0x10e6cfc708dcd29L,
  45037. 0x1ac44f110f3ed31L,0x0a902e0dc71f193L,0x17c51ef0f193695L,
  45038. 0x0bd84caf3f1f9daL,0x0f070ec97bc576bL,0x0909370f0e7741eL,
  45039. 0x00132d017cbf624L,0x14ff41b214d0bdcL,0x03547c7e4a8c062L } },
  45040. /* 175 */
  45041. { { 0x0a1ed6353235132L,0x119f8acedd445b1L,0x1148a47bf76076cL,
  45042. 0x0f64a2235d0ac4aL,0x1d701bd8c750529L,0x1a7a2edac90d7c8L,
  45043. 0x1cffed34175ca5dL,0x070dc7a98bde31cL,0x0897d985f899b30L,
  45044. 0x14e187de44d8aacL,0x0b468d344c60722L,0x0d744446641c792L,
  45045. 0x0201ceed02292e8L,0x0c1f984fe7922a6L,0x03f468c9e917dd1L,
  45046. 0x0ea70eb4c20595aL,0x1d7db4f45d2cb9cL,0x023a96c60ed941fL },
  45047. { 0x14d6cead5dff4d5L,0x0afeda2d413fa28L,0x18313f1c4d79d33L,
  45048. 0x1037caef1c20e14L,0x18dc6b08dec0bb7L,0x1e124b138f0966aL,
  45049. 0x062b2dd94226d52L,0x064dbbe58c6c321L,0x1fd6ebac6675288L,
  45050. 0x1516812e1284578L,0x0b36a1373f07c3aL,0x0d508aa217c0278L,
  45051. 0x0d1a8868011c783L,0x17d792a29c82344L,0x0c2a23590c4caaaL,
  45052. 0x168e092d0aaee50L,0x152569491ca8744L,0x01d328c79bafdc2L } },
  45053. /* 176 */
  45054. { { 0x0a8ed50224042a0L,0x071d8122978f355L,0x1d31da084761b2dL,
  45055. 0x13de9aba7fdb94bL,0x122d46e54e0fe3fL,0x0233ba99d471522L,
  45056. 0x1406d6663887fc5L,0x072292d8a1deb25L,0x069104c2f83a677L,
  45057. 0x03385e5a395df80L,0x020ec940c5def4aL,0x180afa4e25451d5L,
  45058. 0x17b439c994c5d8bL,0x0e6d0d7fa0f7c98L,0x0e3dbee60074ea3L,
  45059. 0x1f041ad0ddd6ae0L,0x017e80c5cd0fbfbL,0x02a0561b1f6e12cL },
  45060. { 0x11969a9fe7f43dfL,0x09c04160dcf2653L,0x1f621670a45f999L,
  45061. 0x0b2d5488095b2ceL,0x1f1297dabaca954L,0x1753ef074ec2affL,
  45062. 0x0fe387d8625ec8aL,0x1bf2ddb99fa6de2L,0x0627d307016e200L,
  45063. 0x14f839b64c4c452L,0x0979825fc8c749cL,0x0437ec090ea52bcL,
  45064. 0x094019b299af7f2L,0x135a58eceb34130L,0x1375e8c76677824L,
  45065. 0x02bd3d88f9ecc35L,0x14f4de9f2b36ebeL,0x00bed99767d0b4bL } },
  45066. /* 177 */
  45067. { { 0x1ef69196cf40599L,0x086fd806010753aL,0x19eff2abd9e5fa8L,
  45068. 0x0711bbacf07b4b5L,0x055bcfcd0d663caL,0x025e3f2d10fc7f1L,
  45069. 0x018cba70fd4e38dL,0x09a6bec563aa91cL,0x1654f242543c6e6L,
  45070. 0x1aad3d3134c9b13L,0x1f17dec3d04c931L,0x1ef2744301e7476L,
  45071. 0x111e81675b05697L,0x129a147ab67c2fdL,0x14a2c09b4f36cd7L,
  45072. 0x1f6f1c7542b22a5L,0x05da8470255f7a3L,0x02305e80dd0ca22L },
  45073. { 0x034dc23c24d8077L,0x05ac0263906965eL,0x0445bd747ffa0bdL,
  45074. 0x0124f079c5453b5L,0x15904af3578af52L,0x1508c8714fa8d5dL,
  45075. 0x177c11b15c35fdeL,0x0a294a45f74ae37L,0x1bf4e2a06ae89bbL,
  45076. 0x0cd9ae62cf9a226L,0x0a0d9c9b30955deL,0x130b5f9d82ef860L,
  45077. 0x0b7c36cbd094a4eL,0x1ae9c83bd6d7beeL,0x0f892f3b4c6de1dL,
  45078. 0x08436a5ad209e5aL,0x18dc5ca26691f95L,0x03e9a161e0b9a43L } },
  45079. /* 178 */
  45080. { { 0x1cf2c0a11fd127fL,0x1b5dc08cf262f72L,0x0949bbd5ab0d9b4L,
  45081. 0x1dca860ceac4356L,0x0c3e961930cfeaeL,0x1e7338976f13e95L,
  45082. 0x130f5904d44ebe3L,0x130c2b38c360ebeL,0x1d447efe959069dL,
  45083. 0x1c6b7b4753b5754L,0x17186c3d6f4592bL,0x08dc3d11773158bL,
  45084. 0x161ba92320dbab4L,0x1c4c4c32b0c5c58L,0x02dfa0a83abecf1L,
  45085. 0x0c17618f5798581L,0x1a710f09b6e20d1L,0x02df057d3472631L },
  45086. { 0x0ab6d381bbbf49cL,0x0e724c60381ff41L,0x0d77843d098cf82L,
  45087. 0x03b4b48a65d94b1L,0x1618f7b7d9cc658L,0x07bff383f0c43b7L,
  45088. 0x01af81066978c94L,0x0d376353d21bcd7L,0x0584a7deb373591L,
  45089. 0x0759a44a8a4ed96L,0x11a8cec3aeaee0eL,0x016185f1152428aL,
  45090. 0x070a2db0190067fL,0x031f379f5ef06ffL,0x081beb6e946c1b3L,
  45091. 0x1b81543224f73d2L,0x0aee4eb5e87fe80L,0x00f37e67aea6f18L } },
  45092. /* 179 */
  45093. { { 0x17dff66aa8ac924L,0x0d698e14c59f45aL,0x0ca597ec20301baL,
  45094. 0x1a3b2b927fa281cL,0x0a180caa7dab211L,0x06f6b4b6b46c214L,
  45095. 0x1187c6a4a502288L,0x065502a2ea671beL,0x1ff5604ae60eae9L,
  45096. 0x00dcf24bed72605L,0x0ea5ff7898ba264L,0x1349e21093068aeL,
  45097. 0x0f64724f1ded69dL,0x1542d0afc7fd011L,0x114de5357c70b93L,
  45098. 0x00fba98c4d9d202L,0x03780440cd6bf09L,0x022916a30aeed54L },
  45099. { 0x095f079ebfbe7c5L,0x10ef6c2779a2344L,0x1adb5286ae58c3aL,
  45100. 0x04a14618d0e2d53L,0x0043bbaa1a4a5d2L,0x0872faad0b318e0L,
  45101. 0x0155af441d40940L,0x0337ffc7d3a7b18L,0x131b30b18077724L,
  45102. 0x07fbf78425c114bL,0x0df5d7c868630e4L,0x0c6aacb771f0018L,
  45103. 0x0a45e3bceb18d0aL,0x11f85846dd60ed1L,0x0f16b1470e3a430L,
  45104. 0x03f8de3743544bfL,0x0ba09d5256bdda7L,0x01a3280d4b6bf20L } },
  45105. /* 180 */
  45106. { { 0x0be448ccc2b0f1dL,0x1a2e4d6261b81c3L,0x19767f25aeff8faL,
  45107. 0x12b5c4ffb4a70feL,0x1bc18089cef3c4eL,0x050c50d0047bbb0L,
  45108. 0x0cdc7cdd282108bL,0x0a9dd105084a76eL,0x1cb6fc6d87cc093L,
  45109. 0x044f60db0a4b6b5L,0x10a6e5278c97121L,0x14a4f7bd82cd525L,
  45110. 0x0edcea281315c6cL,0x1d108aa7caa2277L,0x041873cd1a0faccL,
  45111. 0x081771f64df31a7L,0x16dc3b08aa806c9L,0x03e0ea167f2aa64L },
  45112. { 0x06e703fdc110aa7L,0x1bcebf9b171bc3bL,0x1d756ab728f2adeL,
  45113. 0x12c17c66e7a4b38L,0x06c4e8ff2a6eca7L,0x1b82dffa3a25258L,
  45114. 0x12d4eca10b33bceL,0x1703475eb555c60L,0x17bbfa2011b2d31L,
  45115. 0x05d375d25f7446cL,0x1597395972e0e71L,0x0d2db5efd9d05a6L,
  45116. 0x07e695974524808L,0x14a7cc1b963e667L,0x0468c9bbf5bacf3L,
  45117. 0x1274c1467699e70L,0x19014203f43fffaL,0x0018f4c1439e18eL } },
  45118. /* 181 */
  45119. { { 0x1efecfc765a17ffL,0x19c4468948532a7L,0x111a4e3680e2827L,
  45120. 0x1b42d35a8d7e4cbL,0x03a62fe84bb6145L,0x04305299e7c10a1L,
  45121. 0x0e31158b7d5c6afL,0x0eb7e5521f502b8L,0x145ba1d6e17eda8L,
  45122. 0x0cec40d4a37d2f0L,0x0f9e12e43d68edeL,0x06f9621fea54d83L,
  45123. 0x04a4f4fd360910aL,0x07169dd061c60ffL,0x1e9861f0c603f16L,
  45124. 0x06b847c5fe0a162L,0x11c3a00059b943aL,0x024a69b22d14662L },
  45125. { 0x18426b64ba021f8L,0x04841bcb6f5b61cL,0x0e55f8db1d8b453L,
  45126. 0x14ea39e42cda5caL,0x19b24a198f556ecL,0x1061576d650f000L,
  45127. 0x09ccd1e21f6912cL,0x1af27da999bfe83L,0x18d717c445c7c0cL,
  45128. 0x02431a548dfb804L,0x051be4ed66eebf3L,0x1673cac49e2b43eL,
  45129. 0x0d303f8443dd38bL,0x05f8827e4b6a0d5L,0x1c19609ad9c3c0dL,
  45130. 0x001ea0a07f3da52L,0x0f3768e1f47b342L,0x01e7ee62f5dea63L } },
  45131. /* 182 */
  45132. { { 0x16c2a86b523e13dL,0x0522c1490685029L,0x11e39d5c4a58405L,
  45133. 0x0cfd6a37d47aa56L,0x07b0e9190574606L,0x144474384fbc30cL,
  45134. 0x1f3500a2bb621a1L,0x1e6f35013afb295L,0x050c6032fe2129aL,
  45135. 0x0f25f394c1e2041L,0x0c6eedeacefa39dL,0x06596c318e51306L,
  45136. 0x013f59c4a4d31a0L,0x16a7b0f11b6ec2dL,0x15c5c576fb38d17L,
  45137. 0x1d7af74f5599a3cL,0x0a1138c58da64a1L,0x04494b6879e8d77L },
  45138. { 0x165288fcca82c97L,0x160968a13f46e58L,0x1c1d30fb76a49b1L,
  45139. 0x1dd5403d7ccd529L,0x10f5e86d94600e1L,0x02b5188a55e73e1L,
  45140. 0x10b09d075c0832dL,0x0d1560b54264f3eL,0x070b60fafd42384L,
  45141. 0x0c77f6098c69cf3L,0x1fc6b22482cc628L,0x1751b0733c07d60L,
  45142. 0x0e3c81a30101e3cL,0x066333ec32fc499L,0x1a181f2ba2f29f7L,
  45143. 0x142599dc35cf344L,0x0543182e64ccac0L,0x04919d17b958d26L } },
  45144. /* 183 */
  45145. { { 0x17e8df60acbee17L,0x0ace12e127e6e38L,0x021f953ff2c03c2L,
  45146. 0x15a50a22d68de13L,0x1ba1fa51b993decL,0x190c1f05fd527c5L,
  45147. 0x1dde6724927bf43L,0x043f27966b12d08L,0x1284bfb7f2322d4L,
  45148. 0x066384d6a157804L,0x1c89d26ec758550L,0x1674e2f878d58d3L,
  45149. 0x05bb9c5eeb76f50L,0x123c1dafc590f4cL,0x1870f9d63ec66baL,
  45150. 0x035900990d736a5L,0x091aca59092f297L,0x015d9353490f6c1L },
  45151. { 0x0a3443515f81416L,0x13973d57fadda4cL,0x13780c5c987021bL,
  45152. 0x18b81439fc7a3ecL,0x1368340131c0786L,0x1cda66aa17526c5L,
  45153. 0x09fc4bddc9ce868L,0x1b829fcfdc397deL,0x1ee7fc09e16bb27L,
  45154. 0x06e660ba0872ee3L,0x199d08650ecf770L,0x16c07e63836f468L,
  45155. 0x19c22c107092934L,0x1ccfcb3580c36f6L,0x06c224e8dfba2e9L,
  45156. 0x1a9bc1e77f96849L,0x108bae614472e92L,0x049be59fc70cb75L } },
  45157. /* 184 */
  45158. { { 0x1c0e77c16fbfdceL,0x1a664e4c6a6602bL,0x15c9095cb483a80L,
  45159. 0x1800335079cec0dL,0x115971629861b55L,0x107ebdc05d1401fL,
  45160. 0x0aa883d05077416L,0x1d910cb2276961bL,0x0e6685746aa3848L,
  45161. 0x168ad2d1f0242e9L,0x031dd0eda417745L,0x16fb0315e575038L,
  45162. 0x14d2b74b78cec31L,0x0a1f1794406c78cL,0x0c1f073299676c9L,
  45163. 0x09180637074fb3fL,0x01186537fdc1f10L,0x026abdd83bc2c35L },
  45164. { 0x04b768a53b396b6L,0x1926249da8ed65eL,0x07ae8c2b86cef22L,
  45165. 0x0b28a28f8a67ca2L,0x179fe3ce893bbd9L,0x0905ea366430188L,
  45166. 0x18580d2c2859cfeL,0x107665225d6d64aL,0x0bc69a2a49d168dL,
  45167. 0x04a4f3d7786e894L,0x0d066a1c9a6786dL,0x08ef7e426ed64c2L,
  45168. 0x09a4f9714706c58L,0x1dcdba2ff2ad8c8L,0x17cf2158f5badd5L,
  45169. 0x1f5c76a6cb65211L,0x0a80e257e4355fcL,0x00833e08c4bcf95L } },
  45170. /* 185 */
  45171. { { 0x045508432bf8883L,0x0943537e83333e4L,0x1e3ddf08cd751d5L,
  45172. 0x145e945929ae161L,0x1118acf5678e60dL,0x0dc86cd2346c566L,
  45173. 0x044133a4e0c2efdL,0x149d49638e9da9dL,0x0ac67316d27776eL,
  45174. 0x0c56bae1b0dd589L,0x0f520a64489146eL,0x0440a614875d864L,
  45175. 0x0e3292d5a526440L,0x0ff678de1d22299L,0x19ee2e36d21a52dL,
  45176. 0x0d5bdc9c0a2dd8cL,0x125b3aa595fa430L,0x03f27b848f9a74bL },
  45177. { 0x13816e9b7f70919L,0x10b768b5801fa9fL,0x1fd1de326795d94L,
  45178. 0x10614a30208d8d9L,0x05e728dbe6a5abeL,0x0677eb77b7a4f32L,
  45179. 0x1cfddbf75cfab2bL,0x187d8729cdf186fL,0x173320802b6407fL,
  45180. 0x04747bd4b312e5eL,0x048d8df2afec026L,0x13be80fe6b35065L,
  45181. 0x05ccbfae50258baL,0x1f128c09ff80d77L,0x1c72e87efabab3bL,
  45182. 0x19b6b38d3e2c307L,0x0bd512c58ad9eadL,0x015724e6a366674L } },
  45183. /* 186 */
  45184. { { 0x039b0e3c40849f2L,0x15266d22084c609L,0x0a67951fd92544dL,
  45185. 0x08f537758cc2a6bL,0x13547af692e4bdcL,0x03d3a50cad0b232L,
  45186. 0x08aca17b2cc662dL,0x05a4f0aa7f93bcdL,0x1471c038a0e2ba5L,
  45187. 0x15d0dc41ade5d49L,0x1d4369bcc7b2884L,0x07ed0056658da97L,
  45188. 0x113c64c8c4d146eL,0x1769094b864e009L,0x1a14c3eb4c3c4b7L,
  45189. 0x1bca336eb7ff738L,0x1b723c0ad3e8918L,0x00c074ea9539bb8L },
  45190. { 0x116542f29ab77b0L,0x08ece7bd7731461L,0x1a14d4f0bd03750L,
  45191. 0x089615c99e08980L,0x15fc266f638dc7eL,0x17f5bed04920c2cL,
  45192. 0x05e618e7699c7f4L,0x054ad0b1daabd47L,0x17a694f3158f383L,
  45193. 0x0a119e3698b6c18L,0x0b2c98c28d69eeaL,0x0fbbe3fee2765f9L,
  45194. 0x0559eee2f3fef8fL,0x0ab6832545cda29L,0x173f3f346d3e46cL,
  45195. 0x1d6822ef0cd845eL,0x1b412bc25663777L,0x010e5379e6c55c2L } },
  45196. /* 187 */
  45197. { { 0x0162b13a3e66635L,0x10515954fbb5787L,0x08c11b6ccd587bcL,
  45198. 0x0ef005771b568e7L,0x0699b44c0840bd7L,0x1103f8adb5d7af5L,
  45199. 0x004171b8464006cL,0x009cbbc2d52f216L,0x122b12f15db67f0L,
  45200. 0x02fd6a2c5012e92L,0x1da54f7c2845086L,0x0537e8a06981799L,
  45201. 0x001c277bff4c421L,0x14054f0c07ba020L,0x0aa8ad1b9102d30L,
  45202. 0x1b29eecfbd1eb08L,0x0353de20ab805e8L,0x02d7fac2c90113bL },
  45203. { 0x05acd20a8458e40L,0x0abec0a4b995ec0L,0x04c57c729cb5695L,
  45204. 0x192a56a6478e0e8L,0x0494fadf7f2e269L,0x1e93332e2c92ab3L,
  45205. 0x0a19454edeb3469L,0x0d74dbe0c7b0dfcL,0x11e91db1357d53bL,
  45206. 0x0caddc4f49f5680L,0x0786bca58eff9a4L,0x1385104f110c7aeL,
  45207. 0x123b859b6ffab2bL,0x1b814ee8bbc1b34L,0x0611585b9a545d3L,
  45208. 0x1b0938f30f0ecf7L,0x17764fb4f1d5907L,0x01f55bf0e446c54L } },
  45209. /* 188 */
  45210. { { 0x13a94b652e5718bL,0x17d2a7a6770f4e3L,0x198d54fbb7ab8ebL,
  45211. 0x16be759434ca9d3L,0x0d083316f2541e1L,0x1fca876b894a448L,
  45212. 0x0f929e596bd8fedL,0x179b1f93c1b8e9cL,0x0b4ee48d2eaf79eL,
  45213. 0x02c543545bbc3f3L,0x1d887fdf33abc29L,0x1dffbecf301bb18L,
  45214. 0x02f91067278228eL,0x183f1b149086a3aL,0x1c78a7647d8d406L,
  45215. 0x1714a882ec38cf2L,0x144c0ccc65f03a3L,0x01a48ed279c704aL },
  45216. { 0x106d046cb062eaeL,0x0db9aae843bb6b3L,0x0148a48c574bb9fL,
  45217. 0x05880577b701bd0L,0x06ed33374078566L,0x0b4769afc9a92e1L,
  45218. 0x02c79b3a85359f5L,0x0eb22d42312cd11L,0x00fbd52055dc716L,
  45219. 0x19e883bf22baef9L,0x0c402bb0248cd60L,0x1a02d9b0a7129d2L,
  45220. 0x05432263682f9e1L,0x0dd267ebf75e9b9L,0x13160e100745cacL,
  45221. 0x02fbc6efb573aaeL,0x018aeaa695880d5L,0x006421efeb568adL } },
  45222. /* 189 */
  45223. { { 0x15811ffc9373300L,0x099954cfee18022L,0x0070d4f2d95470eL,
  45224. 0x152d507a4fc3377L,0x12ee3f1a774b924L,0x06ab63e5fe47e5dL,
  45225. 0x0bde6bc9e3b1004L,0x17edfbcd05fc157L,0x07566d0727339aeL,
  45226. 0x09ad6aeb8902edbL,0x0f9a51c1472742fL,0x0901a7460cf96b7L,
  45227. 0x14572d7530577dbL,0x1036c29e96387faL,0x0afed77a1856bb3L,
  45228. 0x11daee33339960bL,0x169eeefc96bea0aL,0x016e6234e9afb6fL },
  45229. { 0x0a6cd06c65f0e77L,0x03cc05eb8d8a566L,0x1e2cf24f3003773L,
  45230. 0x075d197eaf6c443L,0x16f8e63fddfcd5bL,0x10995bde494b9fbL,
  45231. 0x1278ba61228d01bL,0x034998b3407aa3dL,0x19c9d32bb3a3308L,
  45232. 0x009082940742335L,0x000ca86ef9ca540L,0x0ae449270891856L,
  45233. 0x0eb6bba0ffdbfc6L,0x0054a40174b9506L,0x0762f1fd830293fL,
  45234. 0x14171ec588398b3L,0x1fc820c96ee312dL,0x02d0d32ede6defcL } },
  45235. /* 190 */
  45236. { { 0x1ba691a42485684L,0x08b5c94e23864dfL,0x05c798a8146584cL,
  45237. 0x0cbfe933b569603L,0x05238efff3245aaL,0x0eaa8ae177c3fa5L,
  45238. 0x0b2b305b71aeb32L,0x196b4fe44fc5b7bL,0x18dedaac4a9bbaeL,
  45239. 0x1984536973e4c42L,0x1cbf0b9a25564ffL,0x050a2efc0c2298dL,
  45240. 0x06300b1bee3655fL,0x09e0bdaa531f468L,0x05d098afb4339e4L,
  45241. 0x0806f94957c6b89L,0x1d9f4b44a17bc4eL,0x02d74a84cf7f2fdL },
  45242. { 0x02e5ee7804f7455L,0x124cb9103334109L,0x10c5de578cccd06L,
  45243. 0x19c91df9db2fa49L,0x19fbc21c12f4123L,0x11d1d77439c6c90L,
  45244. 0x09b6eecef718419L,0x0ea6c07b1850b27L,0x1926227f2e3c1acL,
  45245. 0x15495602f55728cL,0x05bc2ff5a04ab3fL,0x1089f85505b8b6bL,
  45246. 0x1a63522b273ce7eL,0x09433c4a9c20240L,0x1621a220d8222c5L,
  45247. 0x0f95843ff6f984cL,0x0980ca331612f4aL,0x02088333f51f6e9L } },
  45248. /* 191 */
  45249. { { 0x1830357c2d04b63L,0x0d1a6fa494d0c40L,0x1b688b46577cff1L,
  45250. 0x13968648e78e77eL,0x0997f13814df2f8L,0x0b027a1a2d7f2e7L,
  45251. 0x02b97638fd7e62eL,0x1e75af285d2a182L,0x0cefd5447eed25fL,
  45252. 0x1b4728f0739e066L,0x0b5646ad53e932fL,0x020a256c3918b63L,
  45253. 0x13b5abf7608bbc1L,0x00f3cb24ddc9948L,0x0332f9f6c48c6f8L,
  45254. 0x0db73a1507d2208L,0x1ea3dde426f90a9L,0x00e675b229a6f88L },
  45255. { 0x1210c4f0c6d0f55L,0x0fb0dce339e4e96L,0x0466a738feedb2bL,
  45256. 0x192760c7c9baff3L,0x145a93be135f494L,0x0977be2c05ed9e0L,
  45257. 0x0eda9361c8cc83dL,0x1dce9b0edd11029L,0x14f6f723ac7a97dL,
  45258. 0x0f15c781f1e6c19L,0x0bc20ab9c809c1fL,0x05a9bbf490dcc2cL,
  45259. 0x198d3a17c6e88ecL,0x1cc00b8d6cb2e42L,0x1bdac898b967950L,
  45260. 0x16406156c50bb77L,0x0a33cf451954d48L,0x00f8ba919a7512fL } },
  45261. /* 192 */
  45262. { { 0x08a765b3467ea91L,0x119777e96ce22c0L,0x11b673caf1bcfd1L,
  45263. 0x006b30275cf6ebbL,0x044cbd8defc8d24L,0x092b1111f65904fL,
  45264. 0x1866966e8438c85L,0x1eff429b2687e3dL,0x1df97c21bfb0c48L,
  45265. 0x073144875186a1bL,0x1b8a919451d70b1L,0x03c824cce54b650L,
  45266. 0x1c31aab3b8291f0L,0x10be91764e37ed2L,0x13c2eb6dc9de96bL,
  45267. 0x125c37b11db0722L,0x02bd0b05d1b6a23L,0x0265c57c832c49eL },
  45268. { 0x0b02057bb4b1953L,0x045a27acbfb7751L,0x166d79904b21338L,
  45269. 0x1b679a92330a9ebL,0x0e42bb5d1913262L,0x073fb04813b1723L,
  45270. 0x105b20d57239b5eL,0x0311df55048716dL,0x0d0173790e550f6L,
  45271. 0x0c57a3172bebbc7L,0x0b57a1c56d1c504L,0x0d8683bd49f342dL,
  45272. 0x12280ca61090059L,0x1ba632d0954abe1L,0x0201050bebba000L,
  45273. 0x01f43b620a24ea0L,0x0fc8c1db931ff08L,0x024352e12ebcc3cL } },
  45274. /* 193 */
  45275. { { 0x121e213941b4f36L,0x07d8a7c01da7c82L,0x08b94a952ea2eabL,
  45276. 0x151fc8f2d9fbe3cL,0x18dbacb6acfabbbL,0x0efd28d703c46daL,
  45277. 0x05bbb7e635cdb06L,0x0362ab850d46b4eL,0x0be7d46769c8646L,
  45278. 0x05b1c07b1d3252fL,0x1064527d8249894L,0x0fa145bf8b66296L,
  45279. 0x15cef466ac0919aL,0x14c35576622a6d2L,0x09273b64fe92891L,
  45280. 0x0eb5aa12162e2e3L,0x054602f1d6cc1faL,0x02e934fc4bc7260L },
  45281. { 0x074030c14920419L,0x0ec34484b439c9dL,0x1313badc3e98211L,
  45282. 0x1bb3f8b79703732L,0x158f8f2dabcaa06L,0x0e29550329ca13fL,
  45283. 0x06ea8d7217d9ec7L,0x068b4fb1ae45922L,0x14041005caec2d8L,
  45284. 0x0c345223d4729a3L,0x18602e37944b0edL,0x0dca4222d1d609dL,
  45285. 0x0b2317cd8a4daa6L,0x108b26fb605eaedL,0x0eb5f2687506175L,
  45286. 0x04d0759db944c3bL,0x10f0fe4b5ac09b0L,0x04564ccad136caaL } },
  45287. /* 194 */
  45288. { { 0x0c8dc9b2640a39dL,0x1859c76f064fcd9L,0x06f687b2e82887fL,
  45289. 0x1a101a082ee9e8dL,0x149946048a902ccL,0x1b558af4ab7d197L,
  45290. 0x1d248d23e173e5dL,0x0cf843f8ddc00cdL,0x135b1ebfefeeef3L,
  45291. 0x0022c0e2309f2f6L,0x1fa39ba9ae81c5eL,0x14652a1ae7db97bL,
  45292. 0x161da48889ddfcaL,0x0dd7fde8e4ba3c9L,0x0ebab9f3a19f233L,
  45293. 0x02591a4ce863e39L,0x04d682550458979L,0x0063e0eee6bf50fL },
  45294. { 0x1aa30cc1ce963a7L,0x17b266262fd6f29L,0x0be0a0a2befdcd4L,
  45295. 0x0d9442420e57354L,0x05a576dc64273c5L,0x1ae3be556ebb2a4L,
  45296. 0x1ce6d865ab0fa42L,0x18841a87d3fa355L,0x1fc392062cd05cbL,
  45297. 0x00b1c392607f97eL,0x0ae360aba087985L,0x12867f4f47e19e6L,
  45298. 0x0df644ca925f58fL,0x0c8c53afd75f8e9L,0x01d84603018558cL,
  45299. 0x04882f3136bdad7L,0x1abbf342445ad41L,0x0127fe4d70efb19L } },
  45300. /* 195 */
  45301. { { 0x1fcdc0593c7cb2bL,0x01dcaac8029fdc4L,0x0f3d8608d0f3049L,
  45302. 0x1ecd8314c6c03bdL,0x0c913287364546eL,0x1c4618d2948380fL,
  45303. 0x1df5f0d6e009be5L,0x0510a570c5525a3L,0x11809cb050aa797L,
  45304. 0x0bea33e51e59002L,0x11df027bd6e51a2L,0x1885e4483309e41L,
  45305. 0x0df35bb206c3372L,0x14e0a05aed029f0L,0x15beccef09b1b42L,
  45306. 0x072d0c39f981996L,0x1a41c3cf9ef299bL,0x044f269e8a0310dL },
  45307. { 0x15e80e7a45a9be3L,0x152bc039ab7dee9L,0x18bae59ef0bf136L,
  45308. 0x1c8f9a2dc6030daL,0x1f30ce9ba702679L,0x0327a865178e012L,
  45309. 0x0759bc4816d187eL,0x13cffadaf2f0a0cL,0x047edc4f68a0880L,
  45310. 0x0d60224cd269d71L,0x119929b47e76a17L,0x1d09af5074e3f08L,
  45311. 0x0ceaac33f19f30cL,0x0a431155f49c15dL,0x1a07ac87c0ce0c6L,
  45312. 0x16b8f606f4975eeL,0x0fbd156a90899a1L,0x033ae9f37f378e8L } },
  45313. /* 196 */
  45314. { { 0x1767ffd707193e5L,0x05548c081ac72ecL,0x07fcca363bdf91eL,
  45315. 0x10db77b34eac69fL,0x1e215686913a0eeL,0x0ced1c1bcd94b43L,
  45316. 0x0d34a40fd042a27L,0x16bb3f1af723626L,0x09fe74229bd82efL,
  45317. 0x1ab45b11c01e3bcL,0x068d434f494d136L,0x0b60e4892fd127dL,
  45318. 0x16a169e23b559c3L,0x062da634e2396a1L,0x11fd4c4261918cbL,
  45319. 0x0f1113edaeb3b07L,0x04ba91cf1db1e49L,0x02fbfc97f30578dL },
  45320. { 0x18a1cc60545167eL,0x1170157fd447078L,0x1d450ca9ef3d57bL,
  45321. 0x054ea210cc499bfL,0x00511af77382da4L,0x178a11f44a608faL,
  45322. 0x14abaa93938c4aaL,0x06b187a6de1ec7bL,0x1fc5c9550d76606L,
  45323. 0x0929b989bf53f55L,0x135660e6e543d80L,0x0c0281cc688454bL,
  45324. 0x0ef2ac704595a0fL,0x023587b9c82f11cL,0x1215e2912eb3039L,
  45325. 0x0f00699a840dd88L,0x18d367b1aaaa5bdL,0x012df676c8515a2L } },
  45326. /* 197 */
  45327. { { 0x19a73820c33a8fbL,0x1b6688792ee0e83L,0x0fe31b520adb3efL,
  45328. 0x180f7f08949ff8eL,0x199162f03e51f18L,0x009c08d3b2891b2L,
  45329. 0x06282b1669d3850L,0x1632af4d0cbcaa0L,0x1e1ec51bde3ca09L,
  45330. 0x0063f59d4b0129fL,0x0ff451f780fe12fL,0x1da2a5f7b613d07L,
  45331. 0x1dcea15ec1c0540L,0x05930983b5d2976L,0x0e5c81bcf4c3b55L,
  45332. 0x0e75537af75d1d0L,0x163f20d86920963L,0x00530b525e1d85fL },
  45333. { 0x075f3ed6e1339c9L,0x150395fc5805310L,0x120af3366d1debeL,
  45334. 0x1e0194a98fbf5fdL,0x18bc31ae4713158L,0x06fe45224881789L,
  45335. 0x15352be63c560c4L,0x18993de40eab3d2L,0x1e8021af9c527a0L,
  45336. 0x140093bbd0c9011L,0x1d4e31fec08dddbL,0x0e9fd193d2a2c6bL,
  45337. 0x0d15cc90975df19L,0x1bd288ae0143fd7L,0x0b188f7e81ca3c3L,
  45338. 0x1741321b7f7cc1fL,0x04ca8d40fd40311L,0x043b68aa703e323L } },
  45339. /* 198 */
  45340. { { 0x1a4d6d2c2d3ea8aL,0x1340dd421300769L,0x0037901c19c8dafL,
  45341. 0x1cd4faf4f78a7e2L,0x1d5e1a83e3e5b6fL,0x04be153734ca7caL,
  45342. 0x040441f2b3489d8L,0x04825b31b754cf2L,0x0ddfc4461102e0eL,
  45343. 0x00aede16a499395L,0x03992ea50d9a592L,0x163465657f20fc7L,
  45344. 0x05d928e28b4960eL,0x1503be4f6d22ba9L,0x1587401cbdd6ce4L,
  45345. 0x028ac4eec1976ffL,0x100af235d1b0f4bL,0x01820611df3b68bL },
  45346. { 0x10dc55b4efa9a70L,0x120a7a9f4330858L,0x044c27e289ff537L,
  45347. 0x0a0ccc3a787b2b8L,0x00eb513e505109aL,0x1e99c5e5514ca53L,
  45348. 0x19c7cfb9054dc79L,0x1689fa28bf88ca3L,0x051bbf838cbc313L,
  45349. 0x01cf03c0f5c90a8L,0x05ad1052fd6b1ecL,0x031117c1a919d0dL,
  45350. 0x15dd8f2b6f2d667L,0x15c53fc55f49d97L,0x1dd4717077f479fL,
  45351. 0x0e97d0c567bb321L,0x1a21eb1ad58a32aL,0x02a436bcd0f5de4L } },
  45352. /* 199 */
  45353. { { 0x12e34ffa1359e13L,0x0c6df940cb028e5L,0x08f48d592d7880bL,
  45354. 0x0c85ed5825d2bc0L,0x1653725dfb1340bL,0x123356aa1dd4295L,
  45355. 0x1ca2e06bb735a34L,0x0cb7ef00448a8f8L,0x1559f8a119569fbL,
  45356. 0x02dbd316fd91764L,0x01d5027bb579494L,0x0510533ede220e2L,
  45357. 0x013db6f8c79c899L,0x19e53cd4d3eb493L,0x08582c0c3adfeceL,
  45358. 0x0813595733771f6L,0x18bd2012568d28bL,0x01c078d87ad622fL },
  45359. { 0x0b99e6be6a0068fL,0x1e79564539ba9e0L,0x1522cbebadf12d9L,
  45360. 0x126804c1874d934L,0x0c0f739e7f417f9L,0x04a4ed4772b42aeL,
  45361. 0x1bbffc22d443de0L,0x17762ee1f851ab8L,0x0b4f5abeefd96a7L,
  45362. 0x03d889b79332d15L,0x0e0292d80773e68L,0x0c282c57d98c5f6L,
  45363. 0x16ee6b83b3cc803L,0x1460bf759a4c7dcL,0x1dfbf0baa6c3f5aL,
  45364. 0x0167cb0696b7542L,0x05e929044f55b11L,0x0255f6ef6f5eb94L } },
  45365. /* 200 */
  45366. { { 0x155e1b9700ef376L,0x12ecd3366d5ff99L,0x15d51fa1d91b55bL,
  45367. 0x1401ef26d367b84L,0x00c52e2928f44b8L,0x14d9c90461958f5L,
  45368. 0x08e7569e37848dcL,0x0d68308a33564daL,0x123f6b4b7e0ce4aL,
  45369. 0x1afb7c5565954fcL,0x0f1153881929648L,0x006837e60c5d771L,
  45370. 0x1b94dff6f937efdL,0x0553fd0335d6341L,0x02cdd170cd92c7aL,
  45371. 0x1f61e0c2cee559cL,0x0d346f08d08d1e3L,0x0351055d98c7099L },
  45372. { 0x08310166a85cbc7L,0x084a349a7cd53f5L,0x02239de3c6cf426L,
  45373. 0x1e448f6f3384422L,0x054484ce7ea4ff8L,0x0c61b2598b8eb8aL,
  45374. 0x05160a500e5253eL,0x02cbb5223e72fbeL,0x0a6b58093094391L,
  45375. 0x0fca84d0ba11c5eL,0x1460860825d635dL,0x004348f24ba1fd6L,
  45376. 0x14af8a315eae0c6L,0x15d6825b874a334L,0x1c911f6b9ebe28dL,
  45377. 0x0dffc8982bcffe0L,0x1775184668aa545L,0x022f1a9d3df9b5cL } },
  45378. /* 201 */
  45379. { { 0x005676493092f71L,0x15b617adc96b8bbL,0x126f8b22db17ad9L,
  45380. 0x1441806c7d3b662L,0x03cd7097f62f583L,0x1c8b56344566998L,
  45381. 0x06c3a174303e3aeL,0x1a237ee8c590983L,0x1c76ed5f97c4a6aL,
  45382. 0x045c45d688cf9b4L,0x00dc6faf942e0fbL,0x0a110cce0d4cb37L,
  45383. 0x03f8373d2c0cc69L,0x152d017da98e3adL,0x0e6874138734e8cL,
  45384. 0x0667dd04e8ef1b4L,0x136edfc5bbb75daL,0x00aca0f92653cdeL },
  45385. { 0x0e8c0f8a77dd512L,0x1acd38ee1b2fb21L,0x133421d4e18aa46L,
  45386. 0x1ba4e5f595d01a2L,0x0027cb5a1624230L,0x17cf81f751f60b2L,
  45387. 0x0523705c02d6707L,0x1e3a823824e1b46L,0x1801ee448c4181aL,
  45388. 0x0f942accf1d4805L,0x1ec2f43426bff7bL,0x1f2d166e0048bacL,
  45389. 0x00e6f836b8d839dL,0x1e9900e49db183fL,0x0740aed4e0b9622L,
  45390. 0x083d2c6db14d6f4L,0x10370b7db769686L,0x0368be1a508c7d6L } },
  45391. /* 202 */
  45392. { { 0x1608841c181c99bL,0x0e480e43dee57e7L,0x111cdc836afad97L,
  45393. 0x0ca6eea2b768c16L,0x0a96c2774c79c39L,0x007a206a23f9170L,
  45394. 0x00eb4365484c0abL,0x141066164d7920bL,0x0e25e977a928904L,
  45395. 0x0f57fecc2e2858cL,0x16f2de96b57da87L,0x00339146fdab9e9L,
  45396. 0x101e9850b6cbcd0L,0x185c7302bc236ecL,0x04cbe406b20652aL,
  45397. 0x1c51772e50ae268L,0x14e4ce9f149f56eL,0x00d5cdad21f4f0eL },
  45398. { 0x06dab92314fa7a3L,0x1787823c7fcb190L,0x1c4e41367f6f312L,
  45399. 0x1625808bfc999c2L,0x1d8f6d7dac20a2eL,0x1db7fd227e2a3c7L,
  45400. 0x1dd6221b9cb1729L,0x1aaff48a536dfadL,0x14df1d1b192a820L,
  45401. 0x0c097cf93c4f8a4L,0x0bc20eaaed4f48fL,0x073654075665308L,
  45402. 0x10b151250226485L,0x198fb5eab18e704L,0x0db98d384a53455L,
  45403. 0x0cd5f64526c3b28L,0x1ed8c4281c43ca9L,0x01259a4ab610d59L } },
  45404. /* 203 */
  45405. { { 0x1bdcb86659824e2L,0x067242709f3a624L,0x0899aef87ba9b71L,
  45406. 0x0e3c7d88af49803L,0x0f5a8e4b47b2b8eL,0x19a986bf458af01L,
  45407. 0x1480ba07adb9b8cL,0x13f59746d3c2f48L,0x081241431d70e4cL,
  45408. 0x0c857a59f095f5cL,0x1c148c47d21bf70L,0x03c253f6579ca64L,
  45409. 0x0bb70f6c089f6c4L,0x1ff5a23bdf3143fL,0x13c62ec51e61428L,
  45410. 0x1a081f9fbf62337L,0x1f9925c292fda80L,0x01096b2f2bf1e2dL },
  45411. { 0x1adb386ca15cf08L,0x1256240f0b97591L,0x1e4d350b430137eL,
  45412. 0x06e8809b8f3a3b7L,0x0932bfcdd9cf607L,0x14154c30284220fL,
  45413. 0x073026ba4432871L,0x0612a51f8308358L,0x0e6a120aedbbed6L,
  45414. 0x07070f618667928L,0x12e953962efcbe5L,0x169f3f54882bfd0L,
  45415. 0x07ecee7ce5c66d0L,0x17d3439d062c78fL,0x07c4d21e8750fadL,
  45416. 0x0f56f2d8d8b4073L,0x047e6ef9aaae672L,0x03357d2aa4d2e12L } },
  45417. /* 204 */
  45418. { { 0x05aaba8c980e91dL,0x07a84b564c77d6dL,0x182a368c998aa4fL,
  45419. 0x0001028a7d61321L,0x1d71de8401d2153L,0x0cd00915d8699f1L,
  45420. 0x0e39d197db600f8L,0x118b205fe98f150L,0x174e2afb7193134L,
  45421. 0x04993abce7d82bdL,0x1a9908eb40fe3e9L,0x048ab1ff4814ec3L,
  45422. 0x1977a87e30b7d4cL,0x04e426935af4e06L,0x0658e834717b6ebL,
  45423. 0x17e1bd95107347aL,0x1dfbc6f2f35ebf6L,0x000f7831886ac55L },
  45424. { 0x1f903163ecdcbb0L,0x16b9413e0e4aa95L,0x00c255d724c0678L,
  45425. 0x132d3072613ca4eL,0x1cd082df0dc1c5aL,0x0bf028f7cfc07fbL,
  45426. 0x06d57364541d77eL,0x189e50dfffd398cL,0x1352db38f80f24cL,
  45427. 0x0cdccf61b291d71L,0x0a32a042c412a7bL,0x1fce60a4075a213L,
  45428. 0x0e769400f5c2700L,0x170622961517712L,0x1c0a90756574e67L,
  45429. 0x0616e156ebad5efL,0x002341080990db7L,0x00727affeaf4689L } },
  45430. /* 205 */
  45431. { { 0x11c64440ff14c38L,0x1acfd576708f95eL,0x169c8abd8cc2696L,
  45432. 0x15055e49dd548c0L,0x0b9a1159ddc9f65L,0x142757fa7725ff7L,
  45433. 0x0ab38918f41d9d3L,0x1971197c3c01c17L,0x17ca568ead5fabdL,
  45434. 0x0c06a9262bf5cceL,0x195cb3a6fa61cefL,0x1b9ae60170bd388L,
  45435. 0x1240f54176918a1L,0x1ad8a11b2491098L,0x0d3c5abdf8c93feL,
  45436. 0x1b2f881bb4a0248L,0x02008833421a133L,0x019ea08b0843b78L },
  45437. { 0x131a36b9878e5ecL,0x1f190a348c1193aL,0x08cf428c1191778L,
  45438. 0x0f542e6cb3a2bf3L,0x1925d4fe734c1b8L,0x11587a56104a517L,
  45439. 0x172f10f25968709L,0x000eb39207c88faL,0x092af215e052393L,
  45440. 0x1fdb6af8fac9f9aL,0x10ed2f0f376d7ffL,0x05397fbaa810cb2L,
  45441. 0x0b198d76c09d03aL,0x00793dacc7be6d3L,0x0d6333f01e4288bL,
  45442. 0x09fb974aaf50919L,0x0665922052d76c5L,0x0169ef3d523db5aL } },
  45443. /* 206 */
  45444. { { 0x0de746265add3b7L,0x0479ad5f9261555L,0x072b8695f64f962L,
  45445. 0x1c58edef7fa82a9L,0x1e3202b30e22e18L,0x0e878533f944755L,
  45446. 0x0b462de699ae874L,0x1d21c156e925103L,0x17d424086c7adb0L,
  45447. 0x186196294210997L,0x11dfc563e6827a1L,0x06e5d804ab130b0L,
  45448. 0x1ca5098777422a9L,0x0bb3002c5f21462L,0x1fcdf3d16de5591L,
  45449. 0x0c512d8ff8c632aL,0x0a68b7023ddd631L,0x023801ddb2d8e09L },
  45450. { 0x19401c1c91c1c96L,0x0e6fc93d094b86cL,0x185f0f0a441ea97L,
  45451. 0x0f47fc8e2075725L,0x0ee998ee26fce8fL,0x1d20fc58684eaf2L,
  45452. 0x0941abe98881238L,0x0a56380254b44d9L,0x12c6f734c99b572L,
  45453. 0x049ebcfa897bff0L,0x0241bab3b866984L,0x07020ada3d4c5e6L,
  45454. 0x16eff35f216bff8L,0x00d6911230e3ac2L,0x083f7a1b81fa5e3L,
  45455. 0x1d0365994d942d6L,0x0e6ab4d6d2d633fL,0x039effa82583516L } },
  45456. /* 207 */
  45457. { { 0x1615805d8e20fb8L,0x039f2415a99f845L,0x00055aa15329f1aL,
  45458. 0x19966d2422a40beL,0x07f092b787fec6aL,0x02ff260fd1e0766L,
  45459. 0x1c4496cd991fba1L,0x0dfa8f03d0bf163L,0x0c65268398b0f1aL,
  45460. 0x175c6366e5c75c9L,0x1c3ab6397db54b3L,0x1c4791b269b8267L,
  45461. 0x1d428ac45a31883L,0x0ddfe54290a76adL,0x196b84fddf2924bL,
  45462. 0x00bf7be8227fc0fL,0x13563e4a0d272abL,0x03aa2685bb8a47aL },
  45463. { 0x1e8d13480797aceL,0x0b55057c36cbf27L,0x1a23bd69a3f085bL,
  45464. 0x0b3f364d09b7e14L,0x0999d2fc18b26f4L,0x011caaa97f7e7d4L,
  45465. 0x0de0356be360989L,0x15f1e2468d3ec74L,0x12933454fdcd4feL,
  45466. 0x1400c5bd39dae84L,0x07c9db9554b062eL,0x0e7bfe4d763935eL,
  45467. 0x1006dd4f44c5d47L,0x0f9cdd24cf7a4a0L,0x1b293cab63c4be5L,
  45468. 0x1eb34aecfedb9ecL,0x149ba8773f17922L,0x0110040f560f216L } },
  45469. /* 208 */
  45470. { { 0x043d573ba37a0baL,0x018de6e8bb6fb18L,0x13f31081c3dc169L,
  45471. 0x1ccf85a21206645L,0x0bf8bcfa5cabd30L,0x03d8859b164aef6L,
  45472. 0x179935d9f49dddeL,0x01cc25922bcdd80L,0x19e669631ce69c3L,
  45473. 0x1e4eec7b417131aL,0x087c4a57ff30e09L,0x1cf31455b944f20L,
  45474. 0x044b5d500a06a8eL,0x06c06b62c70073cL,0x17c43321dd1bf1eL,
  45475. 0x0dfb048c0a77d22L,0x133844e328b219fL,0x03102a0d608de9bL },
  45476. { 0x17fd382509e5a29L,0x06be85a19298f07L,0x0d5334e20ee61d2L,
  45477. 0x0917f762f51ee92L,0x05f2d2c5c6b8ac7L,0x058dc1d230b5330L,
  45478. 0x0996acf6598946fL,0x0b19eea62085fdcL,0x0c70d73fbdb2250L,
  45479. 0x108ea1a78616aabL,0x01876152c966cc4L,0x00db88567efb0c4L,
  45480. 0x05e86a4949ffe46L,0x0b0776d6262e42cL,0x03890801377322cL,
  45481. 0x02cac30099cceadL,0x09791f3855a4214L,0x03f9bc0cc7c995fL } },
  45482. /* 209 */
  45483. { { 0x0374bdadfa6639aL,0x0a46a0155b9c8cdL,0x08d91c0c78b432fL,
  45484. 0x19a0b33a3eb8bdeL,0x00d38443b49ee2bL,0x09c9746942f5b07L,
  45485. 0x14e3f6efaa4bc9aL,0x0d1228abf7f7178L,0x0ae259ff1e469b7L,
  45486. 0x0e7658fa0ef2b41L,0x1bc1c6654b46bb0L,0x0303cf7ee88d90eL,
  45487. 0x06282ad2f11ce25L,0x15d277b3e5c9d6cL,0x01ea8fa3e8f34c5L,
  45488. 0x16c11f9cd1409caL,0x0d0ced74170a61bL,0x036f38b59fb5608L },
  45489. { 0x0e58d04172d6dc5L,0x166f331cbe32e6aL,0x1860327ad3a2fb4L,
  45490. 0x10ebf45db6f5cefL,0x091e67385627546L,0x0e4597259819275L,
  45491. 0x0a21d808ea1588dL,0x16b3bedad8551f2L,0x0ec2c185ff6f5e8L,
  45492. 0x04970959d6aba45L,0x0ed3cb552bbef1eL,0x0891dd0d1042f5dL,
  45493. 0x11b1d9bd5b14915L,0x17f806fbd1362fbL,0x16c77bb97334598L,
  45494. 0x1eee9d7933e2f72L,0x1b0909836163fe1L,0x028fc84185d9e92L } },
  45495. /* 210 */
  45496. { { 0x1376fa1f2922461L,0x0d8e18b286868a4L,0x10cc376182376ecL,
  45497. 0x166d71320d25723L,0x1f5600523e612c4L,0x1512a2f0cbbd85eL,
  45498. 0x0f63be2bffdc18dL,0x1759b4fa4f022e4L,0x00b0bc4bb81bde7L,
  45499. 0x058405976952bc7L,0x0834345c6cb808fL,0x119f2837735cb7bL,
  45500. 0x1bc14a65c5f6df3L,0x00ceecc742eec0eL,0x081be4dfe6320b7L,
  45501. 0x17cf18c26e8fea4L,0x1e79e13a2c25f5bL,0x02f7690c70551a5L },
  45502. { 0x156575401d4dc0bL,0x12f93fab35d83f0L,0x0faee088975686bL,
  45503. 0x182313d8d7d30bdL,0x0cce4d9d5f3ad21L,0x1b2dac8bed28c67L,
  45504. 0x1dc732128b4fb5aL,0x0f4ff3102eb1ff4L,0x150d6ae122ac69aL,
  45505. 0x1bf9858e3734236L,0x08e9816f42ec4f2L,0x1d9bae7e480f180L,
  45506. 0x0ce5f0a9969a10fL,0x1ec7ac034628ac6L,0x1691b8749afd856L,
  45507. 0x1a6115e65d50f22L,0x054eaf74e810287L,0x0460a5d03531321L } },
  45508. /* 211 */
  45509. { { 0x0877895b17ee201L,0x15238c472bd3b86L,0x1d8e5e08915b016L,
  45510. 0x019387743a3387cL,0x14389ebe0be6f8cL,0x13fddb7f42fa7fdL,
  45511. 0x1b1914e2f333833L,0x0850edd5654ca4cL,0x15c9ac690cf9a38L,
  45512. 0x1ae79d8e6647cc0L,0x1ef9aa73da1f7a7L,0x01f90706b82bf42L,
  45513. 0x1b150ef2ebfcfc1L,0x04252973043587eL,0x1347ae27e5fb366L,
  45514. 0x0077482dcdf4561L,0x05ee2bd15993eccL,0x0322e052ef55d8bL },
  45515. { 0x14c420550aa7e31L,0x06f8617c28ed2ecL,0x0424f1c9b9aabb2L,
  45516. 0x0c4c337f3532c8dL,0x0253fbd572dbdc3L,0x184f030da130707L,
  45517. 0x1b16e5f0967ee31L,0x1d3f57ef9779bb5L,0x1b4d5e8b1e4b703L,
  45518. 0x18372b7039a77eeL,0x1293e47d57e2946L,0x11747eacb91a05aL,
  45519. 0x12816d1d947f860L,0x0e73d89b4117a3eL,0x1410908330d8559L,
  45520. 0x0cfedc8ddcbde63L,0x091b2a65f706835L,0x013f4ffa0697d36L } },
  45521. /* 212 */
  45522. { { 0x1251893d7e952e7L,0x182c1e39adf8c3aL,0x064a5bf8124456cL,
  45523. 0x1100da5f94e656bL,0x1b885ed92745185L,0x0faaf638d5bb500L,
  45524. 0x0ea72f73a765db6L,0x0567b4c164091e5L,0x16977c086592b13L,
  45525. 0x16e54e584c828ebL,0x0aac8f4622b896dL,0x1e7fc4155e7bb38L,
  45526. 0x0f5aad74d09f469L,0x1154f59dede8fbeL,0x1c04310f57bf970L,
  45527. 0x004c118bdbf4426L,0x176ada2217b5787L,0x027f772b39ed64bL },
  45528. { 0x0e18d52b5d3d780L,0x0dae9838b33a218L,0x01b969d0855936bL,
  45529. 0x1d1ad7770c641a7L,0x0d263dd15d8c290L,0x0c231b4c0d21919L,
  45530. 0x0b2c4cf439f2a62L,0x1fea270f09b4a33L,0x0832e3fabdddc81L,
  45531. 0x013c2ca18ccd21dL,0x12af3cc9d0c58ffL,0x017ae9f29f4eb69L,
  45532. 0x1d5694a6279fa01L,0x05b2bd1261453a1L,0x1a897ab074aa223L,
  45533. 0x0c3fefdde4a07d0L,0x00eed11a5d304c5L,0x027f40c73ce4f6fL } },
  45534. /* 213 */
  45535. { { 0x0252c9d7fc1c7ffL,0x0a0cecfd44d6880L,0x09290193a732a6fL,
  45536. 0x1087285d9992742L,0x0749695b384cbcbL,0x08b2df802610fecL,
  45537. 0x04409a720767d08L,0x09bc464ac51bbc0L,0x1ec9374575a9b00L,
  45538. 0x199a35ffb6e7e10L,0x16992d34dcb1f7eL,0x15a7e40929c5589L,
  45539. 0x15e867c150cecb7L,0x015b91ec2b1620dL,0x194c8c4a64e573bL,
  45540. 0x0cb2f9235bf8afdL,0x1fce06f1161f10bL,0x040c8aa94dba69fL },
  45541. { 0x0c124316ed9d4eeL,0x1d0aa344d7f80c7L,0x127caa268fd0f7fL,
  45542. 0x05a8cfdf6495746L,0x039102e22db1e8eL,0x1784158c6f51aa0L,
  45543. 0x1751d08aae14f94L,0x1dce2614583da6dL,0x1ca60e86d0295d1L,
  45544. 0x15634043e3fad69L,0x0f3b3f7a1919639L,0x18428c3a24ca1f0L,
  45545. 0x10bd38509972e66L,0x13319144ff77a0aL,0x0b71e543c60fceaL,
  45546. 0x0ee044ea8a97cf2L,0x0f32744c11b1136L,0x03e835e63f47537L } },
  45547. /* 214 */
  45548. { { 0x12859427090212fL,0x1bea62a90f42244L,0x108af8b6ee49a46L,
  45549. 0x1b7b03f10098070L,0x0c89bc36317721eL,0x078026e09b65f75L,
  45550. 0x02ae13dc6d82deeL,0x09a4d2265a09c43L,0x1b0e2496ee6cc81L,
  45551. 0x196718bbafd6e0aL,0x0f02119b488f142L,0x154c98c25f1705cL,
  45552. 0x0ba4b653559721cL,0x03e9ece8acd3a8fL,0x0350918d0ceab57L,
  45553. 0x079543cc373a5d0L,0x192149f655ffc67L,0x0245a95cce87ce5L },
  45554. { 0x1915399efdc05beL,0x06d8c09f04af4d1L,0x0ba7376cff6b79cL,
  45555. 0x04340128a288f0cL,0x03920ea3a2b0316L,0x1dc7f5a593cc061L,
  45556. 0x05b52b14e53c688L,0x1342c7ee4ac7cacL,0x0aa0ff93fb71421L,
  45557. 0x137cb6949eb123aL,0x04baa1f73f89db4L,0x1e5e8e071a2bba4L,
  45558. 0x05f418168eab27bL,0x19954c4d72c6419L,0x127c4ef8dc1088aL,
  45559. 0x1095b46d287217fL,0x0ecf16e26060d06L,0x00be06f43cec63bL } },
  45560. /* 215 */
  45561. { { 0x0a5f453dcc01958L,0x02caa0e7441c9deL,0x0285587d6db5f65L,
  45562. 0x0cfc5a6d78bcc6aL,0x05ac3a6c291c3c8L,0x000366fb63f6c25L,
  45563. 0x1b0ede44f102f66L,0x153ef17610eace3L,0x11c928f6eb43e89L,
  45564. 0x0f946f9d70f50f6L,0x0e96c6e492cad7fL,0x0e0a3422dc0ac57L,
  45565. 0x17167ed3e3491d2L,0x0de058230476015L,0x175fd678a473dedL,
  45566. 0x1336e61ca02d318L,0x1d70c7c350df5c7L,0x034315cf1056370L },
  45567. { 0x0c6f4e79ffa1f64L,0x1548d50f121a4abL,0x183336dd48cbfb5L,
  45568. 0x0e0645ac0fd341dL,0x062fef87bfc90b3L,0x1fe79a14a405692L,
  45569. 0x18e3ff08525a70aL,0x138dca423c14a73L,0x02a59ec2612a514L,
  45570. 0x0aff1096b835a99L,0x1ec423a67210a46L,0x1d46bb900905eefL,
  45571. 0x0bbd92d29874ceaL,0x15750af752d3018L,0x01c4272b50b7296L,
  45572. 0x1ec93ad58778e93L,0x06cc64e1c40290aL,0x02849fd16a8fc6fL } },
  45573. /* 216 */
  45574. { { 0x0cf32804c2d553bL,0x15f111dcb3614e2L,0x12708a5a452b706L,
  45575. 0x0b3332ed92aad4aL,0x176e83f3d8c9f8bL,0x02f62be1162bdebL,
  45576. 0x187d53ca50aadf2L,0x091de680fcadc58L,0x1f005e8caf213dbL,
  45577. 0x186429ef9934c63L,0x12235f2b02952d1L,0x17dac16ea03dcdeL,
  45578. 0x06714a4bd9b6bd6L,0x1704c44a7808188L,0x1e4a8014a16f0edL,
  45579. 0x1e495d80ce835ebL,0x03832f16426ef7eL,0x0097ce226b63bd2L },
  45580. { 0x151e96483313a1cL,0x0e9ed19e2c59b8cL,0x1d4b1eb1011263bL,
  45581. 0x0e1b96bdd09db77L,0x0dd422f8866ca6fL,0x10f6177605747abL,
  45582. 0x148f041def15019L,0x07cda732275a844L,0x1d105e1e858e7cbL,
  45583. 0x1e49cbfe4bcdda2L,0x0752a4265ed6491L,0x1147d12a5fce644L,
  45584. 0x074e9462410ef62L,0x0cbc07a06846ac1L,0x18443b1932fb43dL,
  45585. 0x1634627af844e11L,0x118d186d8667679L,0x0017baf2713570eL } },
  45586. /* 217 */
  45587. { { 0x1637ebf47f307d7L,0x02535680a0a3b8dL,0x1594b816a031ad9L,
  45588. 0x07fda0f66305467L,0x1696e597c8f1a0fL,0x1fe00f604f73fc9L,
  45589. 0x1cee736a9fb0f1fL,0x112a93f11fdf1e6L,0x1c88d1961c3bb89L,
  45590. 0x09527f4efe553dbL,0x1e7b88eb92ac836L,0x0c83ebd9634a25fL,
  45591. 0x1fe32fb47df5aeaL,0x12e842e073b491bL,0x11d568a5a971080L,
  45592. 0x12e47b9224ab04dL,0x141580b985f9bceL,0x03958dab331cb0cL },
  45593. { 0x1708a08790e5558L,0x1b0208344d7c04eL,0x0e2908c4ed7e614L,
  45594. 0x04ab493a35d0bcfL,0x0c371b0be6ba129L,0x07370caf3b62585L,
  45595. 0x0688561413ce64eL,0x19d1ba82844c15dL,0x1d8b04e9b968485L,
  45596. 0x0a625d2c43f7f21L,0x1a399fc47179cfeL,0x1c519ed73388224L,
  45597. 0x087a0a966292623L,0x06501769f968555L,0x18ed546c999dca9L,
  45598. 0x16b6ad1dd1c9c5aL,0x1adcdebb2992e78L,0x02ef8c90b70b912L } },
  45599. /* 218 */
  45600. { { 0x0027e1e8df2e7e3L,0x1e6346c6d03ef10L,0x09a52d2b9a52c60L,
  45601. 0x1e794c5d119c6b7L,0x12efed2c896d97dL,0x1e84279ef2389daL,
  45602. 0x048ef401b10389aL,0x1603d36e377f903L,0x09991c7b61aacc6L,
  45603. 0x08649b247b2b420L,0x1587461fd1d4919L,0x16237ffa7944270L,
  45604. 0x0ffa191418610f2L,0x0aaf2984cb48afdL,0x01cb5e63c48db7aL,
  45605. 0x14916c2797dd543L,0x0327f7b44ea66a2L,0x0229132e170544eL },
  45606. { 0x0d5ec7925430010L,0x1c37ff5e8486025L,0x13fc82a74fd72b1L,
  45607. 0x0547db8cbf4bf3eL,0x0cf3eb11fcbf411L,0x12db80441241ce0L,
  45608. 0x02ae2e375b53a2aL,0x01dc44e3bfb6eadL,0x0e43ec373b74456L,
  45609. 0x0757c930e7ba94bL,0x06b838fea5b66deL,0x1a5bb84bbfaa301L,
  45610. 0x146bab77110b312L,0x1af678f235c7bc5L,0x07fb2a81a7bf236L,
  45611. 0x17bc3832a575cc1L,0x15543e302ed5f4dL,0x00a5815fc8f03c2L } },
  45612. /* 219 */
  45613. { { 0x071c768b87e5b57L,0x03c7bfa98d2ab96L,0x1e2fdd65f7202f3L,
  45614. 0x1a273c2ebe9ff27L,0x0b94ca6cb28e026L,0x1cfbfe35c1db93eL,
  45615. 0x145c0babf8ec801L,0x0d85594a9bd9e77L,0x017c4133c6af0dcL,
  45616. 0x150f332e67af1afL,0x046920d154171afL,0x17a1cc2017134cdL,
  45617. 0x06c17d03882633aL,0x0d067c864b36338L,0x0b75931ebbffef8L,
  45618. 0x1548c9b08f7cfa1L,0x0a5d49bcdfbaea2L,0x042f03f3a1663e8L },
  45619. { 0x1aae0a60bc25bcaL,0x12af8f227b27611L,0x1b62d81eddcdba3L,
  45620. 0x0da600b213c3cd2L,0x0cbc4990aa90a74L,0x0717ae83958e669L,
  45621. 0x03b24343f9b1b1aL,0x183241d8be0a7c5L,0x179b21fb4f0040cL,
  45622. 0x19bade9fe625163L,0x177be786eb1f769L,0x1af26b81f1a7ebeL,
  45623. 0x102cacd318dc315L,0x14937b8e388be0bL,0x00bce69bca08f13L,
  45624. 0x1264671b6b177daL,0x030e5b492317db6L,0x004b201cfc6a4faL } },
  45625. /* 220 */
  45626. { { 0x1774f1656999ebaL,0x17143d8ef318290L,0x1c9b782c99a4f63L,
  45627. 0x127f128543b035eL,0x0a03e13c3744693L,0x1139e7de7b5b0afL,
  45628. 0x1715b4c3030d653L,0x1449fa674ad8ce4L,0x1a57534ada8be97L,
  45629. 0x0c921533e115128L,0x06f6d674317125eL,0x0d998d484ed09caL,
  45630. 0x0cd426bf59d7cd7L,0x1374df5948a04bdL,0x05b8fa5650128b1L,
  45631. 0x0cda08e71fd30b9L,0x056bcbb3e0eaad6L,0x0313587e931de2fL },
  45632. { 0x1217dbae1a1ec42L,0x173edd5ad662823L,0x0c7a194cc746a9aL,
  45633. 0x007a6024df6fc35L,0x1ee61851b845307L,0x144aa2140324f06L,
  45634. 0x1d8ca201bd28fa9L,0x09e977c875b96adL,0x0036b9bdabcaff9L,
  45635. 0x0ca0f32de831bdfL,0x1e7511a1bceaec3L,0x025955ad5fad042L,
  45636. 0x1eff7e153414869L,0x15c37ecb4d1dc48L,0x1e4a30e23109b3bL,
  45637. 0x13c016adcd50222L,0x0c1933e71359639L,0x004ddeeecd0bdb5L } },
  45638. /* 221 */
  45639. { { 0x1e39c1de4fd3673L,0x06ce8d32e4703baL,0x0771ca271ffbe20L,
  45640. 0x1c6a53a4008e4b8L,0x1c747af35b6735eL,0x177efae0fc79769L,
  45641. 0x070e573ce663e44L,0x0bbdae44c30930bL,0x123793a2f0e6979L,
  45642. 0x1355c6b4358e953L,0x0057788aa20b922L,0x0df9f3b71afc019L,
  45643. 0x1202267547be77dL,0x04e0876e04437d9L,0x00fb532d89a1f51L,
  45644. 0x0cdd53e387c2ef9L,0x124e6d5d7f05af3L,0x0175500dc68f7d6L },
  45645. { 0x047fb701f357c74L,0x02e2554f1dbca2fL,0x1ccdba16a4164c2L,
  45646. 0x1f7c0489929e130L,0x03b5660df53808fL,0x1caf6b48eeefc9dL,
  45647. 0x083522dd8ddefceL,0x1e72372236f7672L,0x07ccf08bf86a13cL,
  45648. 0x1f6c7cbf500c72cL,0x090d0de31546514L,0x1bd3c1a5ab4d63dL,
  45649. 0x0f9b96259a8e6adL,0x1778beeefe15924L,0x1fe72165baf3abbL,
  45650. 0x17751ed296886aaL,0x06b48cd150f07d5L,0x001698ef4da60ccL } },
  45651. /* 222 */
  45652. { { 0x0bb9e1ede79499dL,0x147fc7e87e156d3L,0x03a069f64d5bdb2L,
  45653. 0x1fd1e0c64f7d81fL,0x1b300bebbc3d1c9L,0x1e0c0dc02e390b9L,
  45654. 0x074040108282104L,0x1ad3d342cfde195L,0x0076c909d1aeeddL,
  45655. 0x050ccbfc71d4539L,0x1fde9e9ded0a799L,0x17e8b929a7d279cL,
  45656. 0x07e6d48407aac0fL,0x148c90f3f9bb4a5L,0x076ef5bd599e78aL,
  45657. 0x1f533e47fc1e7dcL,0x165c7917566cbf9L,0x04b2c3079707a6bL },
  45658. { 0x134702b7fa5f79cL,0x1ea132d796936f3L,0x0e61b1cf833a4c2L,
  45659. 0x1a9dc8945a8b7b1L,0x156c8a1a7dbe7beL,0x06fc076094f0124L,
  45660. 0x0966dbf7016b1dfL,0x15ee14d7456b139L,0x0fc484021999825L,
  45661. 0x09425aa3d11f85bL,0x084290a282a2bc7L,0x16625655edb163bL,
  45662. 0x1a33935ee3b1eb1L,0x077fd3767828a21L,0x1899531e81fac9aL,
  45663. 0x1dc982ddc810dacL,0x0527a7bc5014549L,0x0328408190fd4c5L } },
  45664. /* 223 */
  45665. { { 0x1f0e460b67ed9b2L,0x107e861b6c9e924L,0x0fa6231d7870336L,
  45666. 0x06c297819376b2cL,0x1a768605757bbe9L,0x16e2a24d4dc400cL,
  45667. 0x16616a2df8abd23L,0x0993cefdb3d6a34L,0x0dd025274ebbf02L,
  45668. 0x0c5b1440aa2e31bL,0x16bb4120036e816L,0x027303c54474737L,
  45669. 0x1c550cb4f27fc20L,0x1a903463ee337eaL,0x1a7e856b49c0cbeL,
  45670. 0x151459341795d02L,0x12f60606f213a7cL,0x04c14a8234c3132L },
  45671. { 0x03746002e11c128L,0x1d72e8736e53f1fL,0x1b8b65548992037L,
  45672. 0x051016e287c8802L,0x126b881cf65f88fL,0x1c357f651e946a2L,
  45673. 0x1e563e71677477eL,0x09ea910c18498e9L,0x0d06ea43c9cb69fL,
  45674. 0x1a1e4d7399a7676L,0x0b3358d4ca5c4d4L,0x0806be74d818b98L,
  45675. 0x0cb372653ba95ffL,0x1128291e9700d0eL,0x089fac8c5443f7eL,
  45676. 0x19a21ddca71c54cL,0x14beadfc8a0ca23L,0x025bf370d9f3c7aL } },
  45677. /* 224 */
  45678. { { 0x1c9076fdb5f928bL,0x085db5b9a3e763cL,0x1e62b003b107989L,
  45679. 0x153b2c338ea96ceL,0x19e4343f900d20bL,0x0c9aebf6a160682L,
  45680. 0x00738f7ce7a1514L,0x1584c722304c9eeL,0x0ce8f2554e1f87aL,
  45681. 0x0eeb3c4b2fc8d55L,0x1458fe8c914e7ffL,0x1e589759d32b2d9L,
  45682. 0x0aa94f9ea55c815L,0x1792722aebc6461L,0x17709a9eacabfd3L,
  45683. 0x05045e1dac81239L,0x058954a420b00caL,0x00308e262e994bbL },
  45684. { 0x192001ca9e81829L,0x199900451416678L,0x17863e77b66f7b4L,
  45685. 0x1b6f11200617fafL,0x1577a5dd6793ac0L,0x169e15dd806c8e9L,
  45686. 0x0405385e88e9e00L,0x00fff2bf119f6a9L,0x17cd1bf4bc71b6eL,
  45687. 0x11d925011ac4645L,0x0cd6e2904481d8bL,0x00bd880ada6136aL,
  45688. 0x0ce916a1b52481cL,0x0280bcfa2ae3a08L,0x1344822ef80c9c6L,
  45689. 0x1fca02bcd82ef67L,0x166509a24c090cbL,0x04103ca948e0842L } },
  45690. /* 225 */
  45691. { { 0x12d3cff1c7d353eL,0x1f666bef0671daeL,0x1d7db2a1d8d7579L,
  45692. 0x004bf35a7d69620L,0x005cb5aeda8404eL,0x1910d0b5cb1f449L,
  45693. 0x0b292797b836027L,0x069ac990bb3d483L,0x06a46c4e934442aL,
  45694. 0x037fcbf1e7b2ad2L,0x19707b9505f5f2bL,0x1353dd7f3898ecaL,
  45695. 0x1988da638868100L,0x1b5a39634adb0e9L,0x1fc45c5900ad1abL,
  45696. 0x00bc63fbca2ca16L,0x0a794f8f273be0cL,0x03a43d81b5441a2L },
  45697. { 0x060e5759c3e2370L,0x0c0c9fc02438cd4L,0x1cf29b8be6a8675L,
  45698. 0x12c288e336741b7L,0x1effec21b6c7e95L,0x08675fd4824e3a6L,
  45699. 0x178562e8192c8fdL,0x1e5625045809343L,0x0b654b7d9b1d527L,
  45700. 0x03842ce87fe8218L,0x1d299d3c1511af1L,0x0a37475bb32a6f8L,
  45701. 0x0be33533b5e5532L,0x13f20ce7251f6b6L,0x146e5e4bcbd1340L,
  45702. 0x14d3e5b09dd054bL,0x1ddcc76b123db6fL,0x041a7c2e290fd1dL } },
  45703. /* 226 */
  45704. { { 0x09347c12ce9b31aL,0x029157f1fd9db99L,0x0d354bfe43f4762L,
  45705. 0x0c5634103a979dfL,0x0a411f0853b1738L,0x0db01d29c608dd1L,
  45706. 0x15d05e256e4f050L,0x10c532773556217L,0x1ccbbd046099129L,
  45707. 0x14fd7d8775055d2L,0x111888d598625d9L,0x11386cfff4a9a90L,
  45708. 0x1d1c3478da4a63bL,0x15301a7be5d6ae8L,0x06c4e4714ce489eL,
  45709. 0x1ea2a1cdae0bfccL,0x14cdd14b660f74fL,0x031cec58529995aL },
  45710. { 0x0423162162217cdL,0x12515408e14737dL,0x186085d9b700b83L,
  45711. 0x1208d40dded1b39L,0x1de921015126373L,0x014c69a2775118eL,
  45712. 0x15fa4181f23c845L,0x1c24fe4e574c7b2L,0x1e7ce80cca5e8caL,
  45713. 0x00b75f1127bd31fL,0x13969e259cf8d16L,0x1444a6d757a89bdL,
  45714. 0x0ee3bf77af13756L,0x15e7cc5e3226b0dL,0x1ea58b182cafdb8L,
  45715. 0x000467616b3e653L,0x02cb0769a1aabb5L,0x02048189b063aa0L } },
  45716. /* 227 */
  45717. { { 0x0d2873a1670433fL,0x0a6fb12a49efe42L,0x066a03f3e27b24eL,
  45718. 0x01b652ec2dd60b4L,0x19e63046e39e431L,0x14e54f283a16e4eL,
  45719. 0x07437cc6b632077L,0x1a30d557f29f6f6L,0x036cda27a1b3c82L,
  45720. 0x18d177a1cb816c2L,0x0ff77118204a67eL,0x091ba472c470501L,
  45721. 0x137b3c9353e4b2bL,0x097dc53496d9617L,0x06011d356d6cc5cL,
  45722. 0x04af1f370f47610L,0x1c8d85909861e95L,0x040334776f9bd15L },
  45723. { 0x0edcd35b39a0249L,0x1866a597c575771L,0x1791c88f7c16bc8L,
  45724. 0x15c1d26fe852b62L,0x0cbc9162bb66982L,0x04ee5080ce95b94L,
  45725. 0x01ed17144aba73dL,0x1d22369234ec61eL,0x148d4f34ca03874L,
  45726. 0x0fe87532265ba19L,0x1e6b87e56cc30f0L,0x1a9bdb16c15827eL,
  45727. 0x1f61ead81c40362L,0x04c61e944f418a7L,0x1485c0bb5803751L,
  45728. 0x03e66bf96383384L,0x0e9592329fc3a9cL,0x00233baa40def36L } },
  45729. /* 228 */
  45730. { { 0x03de56e39233c96L,0x0204e4039bf57f7L,0x06f4806af1a21a3L,
  45731. 0x165690c40b595c2L,0x0f19056c0f2cea9L,0x0e1520f191c3f0bL,
  45732. 0x0fa1ba9d4d96a97L,0x09aed8535982569L,0x0a01fcab78d6329L,
  45733. 0x0edf4458655cf92L,0x11b96fd05301520L,0x1127972d6f54eccL,
  45734. 0x117664e097fe111L,0x09fe7ad4db24fadL,0x1ffd8d2865908b9L,
  45735. 0x1312ab2f1937a16L,0x056b5feb38e3c22L,0x001c524fd8419e2L },
  45736. { 0x1e3818c13e93257L,0x15e4ed3093a0d9aL,0x0925f2ab01ac533L,
  45737. 0x067b54222c9edd2L,0x0de2034a82278e3L,0x0dd31873e62b2f2L,
  45738. 0x1bef6edf7257c28L,0x1ad03bb3e46cd2aL,0x1c63e6319bb132dL,
  45739. 0x11158117e12099bL,0x12064dfa2fac71bL,0x129bb1927158470L,
  45740. 0x0aa6bb564483b19L,0x037c8c03daa67d6L,0x1e367cc69f35138L,
  45741. 0x151cc3ba8737751L,0x060660c2a787f74L,0x025dbb711090dabL } },
  45742. /* 229 */
  45743. { { 0x0151e8ae6354817L,0x04a75781c5a1c3dL,0x1a2216562618cf5L,
  45744. 0x0e3b975824990d8L,0x00edad067215382L,0x0072eb7a43d7c66L,
  45745. 0x1fd56b4cc147f94L,0x1aa14e23637adc8L,0x0a68709a78c746aL,
  45746. 0x1f8b931320179afL,0x023bebecc304c09L,0x008380d8e92f8daL,
  45747. 0x0edcc3e2da9ef1cL,0x04970839e863a76L,0x084add0c317e5b8L,
  45748. 0x1d6041e27279e55L,0x18b245840162107L,0x04421e92fbdbb7cL },
  45749. { 0x01501dcedb2a83eL,0x147d815dc6b9227L,0x196764977d8af3fL,
  45750. 0x1e8556df8612040L,0x00f09dfd3c715dcL,0x0c857539e0282adL,
  45751. 0x1d278499d17638dL,0x0c6a705e9b0edfeL,0x0fc69feefa920c6L,
  45752. 0x10b0108cfeb88e5L,0x070ef641d713577L,0x17a27bdad7e4843L,
  45753. 0x0b6263a1163800cL,0x1e93261bc63f507L,0x1672630d6f5e561L,
  45754. 0x0e76aadc45c8ae2L,0x14971bf2a2dfa73L,0x00281fc9cc49ae4L } },
  45755. /* 230 */
  45756. { { 0x1addc6671dad4f6L,0x124448125f50db2L,0x038bd8174f748e3L,
  45757. 0x1d61b2d713f6ed9L,0x0601b2cb13d5f5dL,0x11e92a705add1abL,
  45758. 0x03a9f8df524760fL,0x175d10c08464819L,0x1374182f3e91c99L,
  45759. 0x161657cd43d6c8cL,0x0c102bd5d3ca549L,0x1da328800146962L,
  45760. 0x1e06df42e75b9bcL,0x05e8844ea6662bdL,0x16ed4008ba3b141L,
  45761. 0x1d5b618a62ef5bbL,0x0f9690d31d29ecfL,0x039abbc7f0bb334L },
  45762. { 0x186ee3e843c1137L,0x0217d1f85b9e687L,0x1e762ac838e8f07L,
  45763. 0x082c485f5c1ceacL,0x19b092e46f95f1fL,0x11b5603dc4708e1L,
  45764. 0x00b9858a500f930L,0x064cc20be825b58L,0x174dc28a7862e06L,
  45765. 0x08c7fd979d91e46L,0x0905f01d17fefc8L,0x1408980ae23c230L,
  45766. 0x14cefbe4de49b55L,0x0bdfb88396332dbL,0x13c19d873130076L,
  45767. 0x1a1f165940db58aL,0x0a1fc599daa7450L,0x029731bd30d18c1L } },
  45768. /* 231 */
  45769. { { 0x01700f16bebc6dbL,0x1a2edfca81ec924L,0x14f17454e46529aL,
  45770. 0x0bcb5a55798e2b9L,0x0b7b466f942a1c0L,0x09c8c59b541219dL,
  45771. 0x19b3ae904efb6e8L,0x194d314ac4921e9L,0x1bb720da6f3f1f3L,
  45772. 0x08b6a0eb1a38d59L,0x14889cc0f4d8248L,0x18008c774d3dc01L,
  45773. 0x0d62845fd17fd4cL,0x0056e4e3d6304f2L,0x1ebef298d80ecb2L,
  45774. 0x129577e2df9348bL,0x09841007f7fc4bcL,0x03e48b5a7d3a58bL },
  45775. { 0x1026f9178bac2d4L,0x1404c1300d43ae0L,0x1db801cf590228bL,
  45776. 0x09f983f7115a5e4L,0x0a6b291f443610cL,0x16307e2b93dc116L,
  45777. 0x1522c19154cb223L,0x006a3c91133db35L,0x1841b48b5f543f1L,
  45778. 0x16658df6ac8e775L,0x0b7c3e773d6a2e9L,0x0041668fbb69f89L,
  45779. 0x02cb44c5213a7caL,0x0293e062550d666L,0x08f3d41dceda0a0L,
  45780. 0x1924d546e9820e0L,0x07c733d10006b74L,0x00ff9c8b7bbd468L } },
  45781. /* 232 */
  45782. { { 0x0218fe4f997939dL,0x0fdddbc8ac1d9d5L,0x176a1fdd582cf53L,
  45783. 0x02bb525931674f6L,0x06666f4aa9c0280L,0x074eebf0f5a556aL,
  45784. 0x0c1d8bac5e94453L,0x0dde8d4cd49df1eL,0x1900b45c6810e54L,
  45785. 0x1d7912c25d7826eL,0x0721c9721350bfdL,0x044b1c9907bc798L,
  45786. 0x01170d88b23093fL,0x1603b722317d6f2L,0x174506f86584b92L,
  45787. 0x069b5e91ae68c65L,0x0c9c1b1f759925eL,0x00cf68d2b0395c8L },
  45788. { 0x0f7fcde6c735473L,0x04733b001de1f4eL,0x12f3ec666ee2aaeL,
  45789. 0x033599997a2430fL,0x10f65459bb73044L,0x09314110a57f9e5L,
  45790. 0x082e1abb2068dbeL,0x121550596653f3aL,0x182f3f90f5773ccL,
  45791. 0x17b0735fb112bf0L,0x0d12fef51d8b7d2L,0x0253b72e0ea7e31L,
  45792. 0x097c22c18e3948bL,0x0bdf4bd6e374907L,0x0d8dfe4e4f58821L,
  45793. 0x1a3abd1ae70588dL,0x199f6625ccbf1feL,0x03798f07cb4340aL } },
  45794. /* 233 */
  45795. { { 0x05afe5582b8f204L,0x020db69ac5aa562L,0x1efeb357d7b6b01L,
  45796. 0x1627379b26e427cL,0x16dbcbb01914c70L,0x09ae90b8a5a2c0cL,
  45797. 0x07c83a4a5f4d47bL,0x00b1ec8106ed47cL,0x1150a8a9d2f3cd7L,
  45798. 0x19b7400ee6ecfb6L,0x13ad9573d5b60beL,0x00192554b442b4aL,
  45799. 0x023b089f0376105L,0x0215b3746886857L,0x1ba3521246c81e7L,
  45800. 0x0de8a95e35c7a1dL,0x1e6137e4c284155L,0x043af198431ec53L },
  45801. { 0x080fddcaf6c0accL,0x08f335d8f3e046eL,0x0b860a1616b756bL,
  45802. 0x004eb8fb4db8e2fL,0x126b9e15bdc5434L,0x02fd287a5a64296L,
  45803. 0x12cc97c287efda8L,0x03b8df03c8f02f7L,0x02cbd432870ff2eL,
  45804. 0x112480b33e3fbfeL,0x16b2ded6169b122L,0x15a88ccd80afa08L,
  45805. 0x0fe6d7d63d2e972L,0x0713a0a263a6c3eL,0x09612bbdc19f61cL,
  45806. 0x1fbd765942af516L,0x009495c5bfb75f0L,0x02d5d82c0f9c370L } },
  45807. /* 234 */
  45808. { { 0x1e62d2bf0c97f57L,0x02438cb179463c5L,0x119d1ed42aec3f8L,
  45809. 0x0689f413db8a914L,0x0b05a96ef6b26e0L,0x1357417ea26371dL,
  45810. 0x02677b6c00cb1c3L,0x184517a8057afc9L,0x043f2e9639b7c11L,
  45811. 0x161fe0767489b8bL,0x0e2f240bf43e303L,0x0754f9578758ed3L,
  45812. 0x1206924cc99d9cbL,0x0130480a7445444L,0x0b9e782945186a9L,
  45813. 0x07d018fe955172cL,0x0bc4ef0210a8b1bL,0x0382a23400dff72L },
  45814. { 0x0b3d713121901c1L,0x11313ff56aa557dL,0x0a16f022e88fa42L,
  45815. 0x0a6dd844fcc9edaL,0x06c191ab8d99301L,0x04e7164cd0b55c8L,
  45816. 0x0ea021ac73d6fd9L,0x1e0b240ceb2cd7cL,0x018836279ccba2cL,
  45817. 0x00abdc3f7fa9a43L,0x1262592c88ebc8bL,0x09e0155cf4af7f5L,
  45818. 0x0063218a80cd0fdL,0x0fc478a76d6edcaL,0x07b67f4e112ede7L,
  45819. 0x0a06d8367c7a96eL,0x06b6c634a13d620L,0x037ab5767dc3405L } },
  45820. /* 235 */
  45821. { { 0x01dc803d9205c5dL,0x0afbeb3891c94d8L,0x1ff6766d9595a25L,
  45822. 0x1da76359fc7bd77L,0x0094eeffb844395L,0x0c8ff582194590bL,
  45823. 0x141d598c7fea08aL,0x00a1bbccdcc321bL,0x175b03c55e8577cL,
  45824. 0x048e72fc8b91203L,0x0229023aece8fdbL,0x1f140b14272d345L,
  45825. 0x179a6e06761d376L,0x1db8e94479d2ca2L,0x130c30040c0a715L,
  45826. 0x017381087e85168L,0x0add8e6aff8730eL,0x03db5f408a76b22L },
  45827. { 0x0c38e4a3d3aa54eL,0x19ca1ec1ea84d1fL,0x188490e55788408L,
  45828. 0x0fea3a7a89f0954L,0x1eca4e372910471L,0x1d2aef316922163L,
  45829. 0x086d6316948f617L,0x0d18deb99b50a3bL,0x0044bcaa8200014L,
  45830. 0x1a80f34700b8170L,0x064d679a82b3b3dL,0x0d5b581de165e10L,
  45831. 0x08fd964f0133ddaL,0x0985c86c4bd776eL,0x1048bad236b3439L,
  45832. 0x143bc98bf5adf70L,0x0742284ec1ed700L,0x0437cd41aede52aL } },
  45833. /* 236 */
  45834. { { 0x01d9055450cc69fL,0x18a5e64f6fcc787L,0x19dfb9fae80543aL,
  45835. 0x0f331f1ca637729L,0x1b16eef05f7a673L,0x0e2f0aac41c2718L,
  45836. 0x14aaaee4a1c8f61L,0x0e9fca3c68b97b2L,0x0c5d0ee287e2416L,
  45837. 0x0e0a3778800c178L,0x0e7a4b9fd6f8b3fL,0x075f6cad7a7c1eeL,
  45838. 0x1e5168e289501abL,0x1c77082558aa96eL,0x0c111d65037f8c6L,
  45839. 0x1522685246c0788L,0x1869306f114c460L,0x02dfd4fd781da8fL },
  45840. { 0x023f52c107b258eL,0x1415deb31a0ee15L,0x1b6208f3fc6a627L,
  45841. 0x08e336923ea9479L,0x0433dfb8f45b779L,0x09287744c6110c1L,
  45842. 0x1d9543e77647312L,0x08aa185455c9f42L,0x1f7aa1ce42c327fL,
  45843. 0x1d0ad6b2c1d8f20L,0x03569686feb6784L,0x14511c3f7b9b354L,
  45844. 0x16915f7f879b1caL,0x03f40d0f57c941dL,0x0034a5b04393832L,
  45845. 0x0b7b009fb94ac21L,0x0da6acc96161275L,0x00d8933554147f7L } },
  45846. /* 237 */
  45847. { { 0x0bc0a00774ee49cL,0x1b42965b11beba7L,0x12b177e4e28dddbL,
  45848. 0x116df7f77bf80a8L,0x145f2eaec3388ecL,0x16749bc25645e6bL,
  45849. 0x1e84ea7159826c7L,0x0e2cadf6d58fbd1L,0x15f8ded74a532b8L,
  45850. 0x186a145d5444f84L,0x09fca042debb0aaL,0x1c3dfdd96698876L,
  45851. 0x0b9e89c2db26426L,0x1c90884822218dbL,0x1604162ab12f174L,
  45852. 0x1ec1d24dee6d09fL,0x023452fa691471eL,0x019a8bfed90c6bdL },
  45853. { 0x1c33f46593c4a36L,0x0eb8c1b58d4f754L,0x107509defbb2b1aL,
  45854. 0x1cfc9e2f38ab441L,0x146d88a23e8ca24L,0x03817c2b9b99b4eL,
  45855. 0x155d1c73ac731ccL,0x18516309b2e6bddL,0x17f4517a20704ceL,
  45856. 0x1894e8c6b831529L,0x115c6ec75df871fL,0x061306a1b1640f4L,
  45857. 0x1f61fab8ef774acL,0x1aeec00d93d948cL,0x0d1647e9f13304eL,
  45858. 0x12567cfcc4ab628L,0x149349937b85a35L,0x018fd631e9863baL } },
  45859. /* 238 */
  45860. { { 0x0e8cf1b04913fb6L,0x009a80bb4d35997L,0x0dc5e0f987c1f90L,
  45861. 0x13c4fe5ffcf21d7L,0x0daf89bf1e5107fL,0x06f3468925d33ffL,
  45862. 0x0afb86248038796L,0x1552c4e6546dbebL,0x072cc37cfacbeb4L,
  45863. 0x062fd4b749e2d3bL,0x08c5f3798ce4eecL,0x1ccf06165ad8985L,
  45864. 0x041be5b96a97f65L,0x19867336a57e1a8L,0x103613c2fd02981L,
  45865. 0x0d6112d4374f326L,0x1f53ee182540762L,0x000ed9aedbd5865L },
  45866. { 0x00fbc2dac0efee2L,0x175e6eb8edda2b7L,0x18f866da6afa101L,
  45867. 0x026fc03045ce57bL,0x11458b4c49cb7e6L,0x1e2eb1e5dc600e0L,
  45868. 0x19dd9082d211da1L,0x030308fbf428a98L,0x0bede911dd1839dL,
  45869. 0x1cee4e493c6f823L,0x0f58ae2068cdb06L,0x10f327cef5b8529L,
  45870. 0x0543ce3ba77f096L,0x1bb2777e3d64833L,0x111973c521a57f5L,
  45871. 0x19b63c1841e1735L,0x01d636e8d28a6e2L,0x03db5d4c66baa9aL } },
  45872. /* 239 */
  45873. { { 0x11d9e03c1881ab4L,0x12eaad98b464465L,0x151ca08d9338670L,
  45874. 0x01e2c35449505a7L,0x01ebb2c99599439L,0x163d3abc1c5e007L,
  45875. 0x0882a3f577f32f7L,0x0909ba407849feeL,0x15ec173b30efeffL,
  45876. 0x0f8e9598b21459aL,0x0f679415ba04fe6L,0x0575816633e380dL,
  45877. 0x04fd223b1592917L,0x0c6848f6b57071cL,0x151923af404167aL,
  45878. 0x1cf30d662d1c94cL,0x1082211447f3375L,0x023f4080cb8f5a2L },
  45879. { 0x045d45abc8c290dL,0x089aac087d99d38L,0x02491beefcbe8cfL,
  45880. 0x1670b8f9b2575e0L,0x0161985cacff3f1L,0x0443a462d8a8767L,
  45881. 0x173231bb829fcaaL,0x0873b11191cbd11L,0x04dd735f2ccb864L,
  45882. 0x00f09db9e207b79L,0x0897ffcffb5a473L,0x162e4afdcb8ff87L,
  45883. 0x13f32db1354cb43L,0x016ff969d532a7cL,0x1298e5113d63428L,
  45884. 0x0cd2ef1c7e31151L,0x07b39646ccef3e8L,0x03c2d8c81706e74L } },
  45885. /* 240 */
  45886. { { 0x0ce2361a92f9a20L,0x0e543ceb22a077eL,0x0a1474035f16defL,
  45887. 0x185d2f924da8e73L,0x18da6a8b067ac8dL,0x028db495751fff3L,
  45888. 0x05069a0a2fd518fL,0x020ede388f2e2aaL,0x0f4bcbef63977d8L,
  45889. 0x0de24a4aa0de73dL,0x1d019b45c10695dL,0x0b7b0eeabd5fc03L,
  45890. 0x1d59e7ae80d282dL,0x1c1559b7b71083eL,0x14758d2a95b8598L,
  45891. 0x1b088cbdd1ded73L,0x02799a2160ace4eL,0x032abe1b3dbb896L },
  45892. { 0x01b0268d75b6e52L,0x09b2008c68744abL,0x0cc1a8bac6bac20L,
  45893. 0x0cda1211299fea6L,0x15fc1d484e46222L,0x118316dd9a8913dL,
  45894. 0x0b7164d97a81d5eL,0x10e995946f7acdcL,0x1220d7d23b90958L,
  45895. 0x007e9c9c62239dfL,0x1cdc299e1f693e7L,0x1799a0afe9715bfL,
  45896. 0x0c1173f33aef0aeL,0x092d135a102f3a2L,0x0beeff6e347c296L,
  45897. 0x1a509526c9e92e4L,0x0b4c891ae778227L,0x00ae20682507045L } },
  45898. /* 241 */
  45899. { { 0x1af169a2a0e18d1L,0x0e00ba60193e14dL,0x08fdef098b3a65cL,
  45900. 0x1b031fe6f3b0346L,0x0cd3c3302099db8L,0x0d02a9b31fb31eaL,
  45901. 0x091c3bd4c970c04L,0x0e139ae17b9f301L,0x1e64452d11c9ed0L,
  45902. 0x1dfa1fa5633b709L,0x1b029aba170a96bL,0x0aa08e0921892f7L,
  45903. 0x07491e6ba92faaeL,0x157d4c8a055cbd4L,0x1c9955d0157d4deL,
  45904. 0x1ad7ff92b5b766cL,0x037646343b9d119L,0x03c474a504e9a0fL },
  45905. { 0x13a6fe59c53461aL,0x044bf0471db7682L,0x0bcc1da364e5d7bL,
  45906. 0x0d98427a9f51ebaL,0x05b0147c9bd6bffL,0x1dc0b4ac863da08L,
  45907. 0x1e3a4828d8a2df1L,0x11f8cd410dcb79cL,0x13dd4d2824dec1dL,
  45908. 0x08567a260cee674L,0x0b61d7610d69fa2L,0x0f83d4c70364cc6L,
  45909. 0x17f0dcc12859016L,0x037c6a31d912cbcL,0x17be8e646984ad1L,
  45910. 0x0cf108430baf182L,0x093df55ec37119fL,0x048d8ce633c06f5L } },
  45911. /* 242 */
  45912. { { 0x1f2709dcb5d8b80L,0x0b0c17e1ab30775L,0x0644157be5a40eeL,
  45913. 0x1bc8f8868570e7bL,0x154f8867d1ea4b4L,0x06bbf7e625c9226L,
  45914. 0x1d58e4ec68b2bf6L,0x0ac0d1a49cfd183L,0x15f5fabb6499730L,
  45915. 0x192462802a11ba7L,0x178ad4fce3a44e0L,0x11d6f76d017d86dL,
  45916. 0x17d8f313b5ed07eL,0x17e969c94b2409eL,0x1228c69eeda81a6L,
  45917. 0x1864b80db091c10L,0x1af6867fb2fe4f0L,0x01e15d41a0339a1L },
  45918. { 0x162d7759d3ad63bL,0x055cbacf0758fd5L,0x098ce217845cfe7L,
  45919. 0x1dc4165f3ce0665L,0x09eca947f22cafcL,0x146c46da94dd3f2L,
  45920. 0x055849255085988L,0x08901d447d87247L,0x01b8907e7d43706L,
  45921. 0x1bfd22aab1f2722L,0x060a7aca92c3e92L,0x0148900c0f25995L,
  45922. 0x0c246991ced0a72L,0x1a468435c666ed0L,0x02bb84cde88c96cL,
  45923. 0x04a7eacddaa13ecL,0x1d83d30e091147fL,0x00fd313d2e0839dL } },
  45924. /* 243 */
  45925. { { 0x11222a242478fd4L,0x06378b385900050L,0x013e0d671b7ab3dL,
  45926. 0x12f7279b79ee376L,0x030db60b618e282L,0x0d9d94cb70dd719L,
  45927. 0x15777c5ff4ed259L,0x0ff4b0c738d78e0L,0x0c3ea92ed4b817dL,
  45928. 0x0415953691d8452L,0x048a2b705c043a4L,0x1c8c41d13b2f08eL,
  45929. 0x1703ff77c9753b9L,0x15df3072e7bf27cL,0x03805f5b0fe0914L,
  45930. 0x0bdb73c86597970L,0x03e150a5acdc0a4L,0x033dc5e82a3cc3aL },
  45931. { 0x06079b4f4797cf7L,0x04cc5681fef0173L,0x18e9532abbc78c7L,
  45932. 0x1deec92e22b546eL,0x0f29b1a764d9a1fL,0x136549be706e39dL,
  45933. 0x1a9e19986c20fedL,0x0c37e9ae9fc65f6L,0x125f6ef09df00a5L,
  45934. 0x1e21c1fc18e88acL,0x1304314daf78dcaL,0x1f3f10598cb6dabL,
  45935. 0x13451a99b8d4945L,0x15d608d240fa478L,0x029282850058735L,
  45936. 0x150493b29a9dbe3L,0x0df65363165a467L,0x03a14bd54d264d7L } },
  45937. /* 244 */
  45938. { { 0x09758a4e21124baL,0x0c0cc543ffde962L,0x1744f598e2a266fL,
  45939. 0x102bef7eec8bf79L,0x04e6d57e94645ffL,0x130edcafd339b7eL,
  45940. 0x051287ab991d64bL,0x0e8f2aeb81997bfL,0x0a3d1304725b31dL,
  45941. 0x040ef912655ad73L,0x1f4a6468a21fc9eL,0x0b2144d588b31b7L,
  45942. 0x12d8661d4a23d07L,0x0500a07b972c4c2L,0x0cde0a8ded704eeL,
  45943. 0x09d201f28333c7fL,0x112722aa0591bc1L,0x044d55bdd6aadddL },
  45944. { 0x1345a96d656bdc7L,0x0e457f0bb669dc5L,0x02d8cb59310d0efL,
  45945. 0x0ef3705683ad2a3L,0x1fb0cf82fcf364aL,0x00943dc83d9a277L,
  45946. 0x043bfcf4320f144L,0x0b9d3e4d4b2699bL,0x1e5f5aaf207082bL,
  45947. 0x15b963af673e0b2L,0x042a06fa61b3593L,0x131ffe2a6d55d2bL,
  45948. 0x03a8263d5efeef4L,0x0a574395822b012L,0x081da1a502f853dL,
  45949. 0x09af57dcf7993c6L,0x146d496a27dc1bcL,0x00016e14baca055L } },
  45950. /* 245 */
  45951. { { 0x0533937b69d60c3L,0x1f2a97f4b93aaf7L,0x1e37031c9698982L,
  45952. 0x1d9565cf85623f6L,0x0e2322cb6982c27L,0x13827ba5e776ecfL,
  45953. 0x1859654ac67b448L,0x10a5be9850b0a94L,0x0ba40b5bf7b1924L,
  45954. 0x05e54a8008cfa95L,0x1f472f96b761bffL,0x0df7b3a1e582e8cL,
  45955. 0x14b8d4ebc99bf53L,0x02d4098b9e14b71L,0x0cd7dd81257e3d0L,
  45956. 0x0424518b3d1ace6L,0x0730b53d324e054L,0x026ab229a9e1dedL },
  45957. { 0x122f8007e5c0877L,0x1a1f30654d3b239L,0x1d2e8b049c59206L,
  45958. 0x0fda626d84463e9L,0x18db30de0959685L,0x08475e574131911L,
  45959. 0x08c7994beb50266L,0x092171a30295e1aL,0x02680c54b09cbc3L,
  45960. 0x0a2b179a5f9dfc7L,0x14242c24ad657ffL,0x1948bc2bf868530L,
  45961. 0x11bc378168e6f39L,0x022d2543b80ba8cL,0x085506a41a512ceL,
  45962. 0x19169598dae9505L,0x062adc9bab3b155L,0x00f97c4e73b9836L } },
  45963. /* 246 */
  45964. { { 0x053ef419affefdfL,0x1f672a67c92b5c1L,0x0bcad113920c175L,
  45965. 0x1f974a8e3e6ee00L,0x15cbe015b189755L,0x05c214e44241e5eL,
  45966. 0x1d874953df1a5a8L,0x0ae310a17a8c3e7L,0x17ba210890a2471L,
  45967. 0x0d5de176c977586L,0x1b2afa5977b224dL,0x0e4978aad095f6aL,
  45968. 0x0f6a7a74929da23L,0x177a5d236c5d1cbL,0x026c9ebf2e436dcL,
  45969. 0x06cddba469fc132L,0x147bdf3c16476f4L,0x004e404bf8bf286L },
  45970. { 0x004b14060050c07L,0x1418c21d471bf35L,0x06caed57907f0a7L,
  45971. 0x1459cc1c7597285L,0x1b9d82f4ed2fea5L,0x1e9bfd6e3d8ff9eL,
  45972. 0x1d4e523afb30da1L,0x124f22a7c65d960L,0x06a60054f570756L,
  45973. 0x038e6864003acddL,0x1ce1bcc248b7c4eL,0x0b3d066af6f82f4L,
  45974. 0x09394151864e9fcL,0x09a6dc448e9359dL,0x1f36dc644a8088bL,
  45975. 0x0606ccce5f9e8b3L,0x16c5a3f268d44ffL,0x037889f69b488f0L } },
  45976. /* 247 */
  45977. { { 0x0a9df591836f1c9L,0x08cfaa119183ea9L,0x1c0577b4a16be99L,
  45978. 0x155ec4feeb080d8L,0x0ce0417d0a1545cL,0x089a21d70888f75L,
  45979. 0x12f2feca2f7da98L,0x0b1bd3de156a5b7L,0x1e9dc181b7813e6L,
  45980. 0x18ed5edcc893912L,0x16638c8a0531642L,0x0cddb269dcfcbe0L,
  45981. 0x1ab99ba4bf5c3b9L,0x1e0daaf3a75c276L,0x0aa183eca4668d0L,
  45982. 0x03fed535bb69329L,0x1e21b7220dff681L,0x0331b511de8d0c1L },
  45983. { 0x15d5a2d20587283L,0x01164f783fe2eefL,0x15543bdb78e02ceL,
  45984. 0x0e4ba2ce3a2f0d7L,0x1cdb1def163cf90L,0x017e253a5fcb8f8L,
  45985. 0x153dd5d27a0c021L,0x1961c5db78e4ff0L,0x1bb27bbdabce24aL,
  45986. 0x0d8ce7602df6846L,0x0848fbdf2412f30L,0x1e37b13305b755bL,
  45987. 0x0e65f6e63202429L,0x172cfe9924e9b0bL,0x07ca7d68de27ea3L,
  45988. 0x0f1402c174775fdL,0x0f80f2d3b61af53L,0x03d77663b39e153L } },
  45989. /* 248 */
  45990. { { 0x1a4757cdc43b0dbL,0x12742cc08ce56f9L,0x0fd9185b0558f62L,
  45991. 0x189ea67d2ff012bL,0x19cfc5ad3e2a07bL,0x14029654c121b39L,
  45992. 0x1b198629ae8eb35L,0x12b7ac1cb211439L,0x1ae3841a502b1b6L,
  45993. 0x036ff890c850cadL,0x0afab2b4c7f66e6L,0x044998e51ef65beL,
  45994. 0x180cf0a9927d893L,0x0c35227561c7539L,0x057c0f2a10e6a01L,
  45995. 0x1f10bdbcfefe02cL,0x0454824990827a1L,0x0147620035bc53bL },
  45996. { 0x1820c2ea2fe0009L,0x1d2e9789c3a74f0L,0x115314936d4b846L,
  45997. 0x0cffdbca532ea44L,0x1b2500d44d47742L,0x14922580e9a0cd4L,
  45998. 0x186e73822924861L,0x1c1742d2047ba37L,0x0242c3e5432a301L,
  45999. 0x1ab7bdd384833c4L,0x14a8271d2a33126L,0x1083aedf2873e15L,
  46000. 0x0b621fb60e99cd1L,0x1e1cbb1a76ed7f0L,0x1fc2a1015afb952L,
  46001. 0x1815e8ca7f0c1feL,0x1c36bd4876f2011L,0x009a7a663864a92L } },
  46002. /* 249 */
  46003. { { 0x021a3ece938dff4L,0x00d3da4353cd1cbL,0x1e5f7a5414ddf44L,
  46004. 0x13ccbb0fb7e589dL,0x173b8cfaf318409L,0x0148b75c4e3ffd9L,
  46005. 0x09d91a2ea9417a1L,0x0574f21fa129d7dL,0x1679df6d4e59289L,
  46006. 0x011998e7e7f6ba0L,0x13bf4a6203fc848L,0x1bbba0688a0217eL,
  46007. 0x0b342858c87ca78L,0x12baa43d16584f6L,0x12c1246797adb70L,
  46008. 0x1a8e2a0ceb42bd7L,0x0f409d2e74f7381L,0x03751bc14c1e9ebL },
  46009. { 0x05c094b4e5cc40aL,0x11fb50d79befde3L,0x1a77e409b911e8bL,
  46010. 0x0b27101ea7decefL,0x1f644aa9b7878c9L,0x10461e25518583bL,
  46011. 0x198ee83145a0cbcL,0x060f804ef5ccb1aL,0x0ef0b3c38ae1d91L,
  46012. 0x0179bd3b4ae1f52L,0x130715a8317834cL,0x0b8841979f3fc00L,
  46013. 0x1d568a0e7c9fd49L,0x0c94322a3836adcL,0x069c2722c8977fdL,
  46014. 0x11ad0a4fa88cb1bL,0x07d47c558da87c0L,0x0303773735da778L } },
  46015. /* 250 */
  46016. { { 0x0d99fc757c621f6L,0x12060bff41ea401L,0x1e867bc666c0a4bL,
  46017. 0x05cc58eccc37bf8L,0x0673875378a0410L,0x1d32d78b66d1b87L,
  46018. 0x18826f2065d3478L,0x18c32e84091ef1fL,0x1c83a058abf5981L,
  46019. 0x135921a4e44b816L,0x0cbc7a74699e2bcL,0x1361fe535c53311L,
  46020. 0x181d7cf5ec472bfL,0x19346eec50a1f1cL,0x113fdda7275f916L,
  46021. 0x0ece62cd9b4aabfL,0x1076044cdf0a4aaL,0x024edd37bf48a43L },
  46022. { 0x0e47fb2a758e37aL,0x198eb96c757b310L,0x17e5be708842bdaL,
  46023. 0x0f21df86566a55aL,0x01e4b2640093f72L,0x18abcaa1ae4cee2L,
  46024. 0x0d5d6fea1e38016L,0x0b3338a41481cceL,0x1ca68259487eea7L,
  46025. 0x14fbdc0f8951a45L,0x1f3060aa8b38d40L,0x0e97d5abc58b4a8L,
  46026. 0x1b55682cdfa11d8L,0x05df47334d781a4L,0x14e52afe1baffaaL,
  46027. 0x1d71e7b570f05eaL,0x18c458bf797ebc8L,0x0244853d24dbef3L } },
  46028. /* 251 */
  46029. { { 0x12996898da995f6L,0x15573f630ab77ebL,0x1030d5aa0b574e7L,
  46030. 0x03826b79fcd2b20L,0x0f595c78b2046b2L,0x02fda0753905b20L,
  46031. 0x0eff00a093beb9fL,0x17d2fb1fa981db6L,0x112f0290579f24eL,
  46032. 0x17e23e78c3f535cL,0x07f49de275708c5L,0x16d9124c7d99843L,
  46033. 0x128b6d30a6233a6L,0x04d99b40411b1a5L,0x11dd15b28d4b897L,
  46034. 0x00cb72711ad9481L,0x076f8e55b0b3c92L,0x02e0ba3a58121cdL },
  46035. { 0x088e7c28aaccab5L,0x13c1b5567682decL,0x1df733b03d94600L,
  46036. 0x1824b8510430b70L,0x07fdc54c93cadc1L,0x1c4519a2efaa053L,
  46037. 0x1e8b13cf21b8b09L,0x19e7d0e88d3c741L,0x1c59daa47273983L,
  46038. 0x031e245a54b6c52L,0x14af3f0b962454cL,0x170f09c85187871L,
  46039. 0x0cf0c4fd5390e78L,0x0a0f3002c805149L,0x094e872dfe4b6deL,
  46040. 0x01f4f2acf2482d9L,0x08c35f6f31db1abL,0x02eb3af5a3dac20L } },
  46041. /* 252 */
  46042. { { 0x0ee1a77870c6025L,0x111dbc8d16fe557L,0x0310e1ad9313f12L,
  46043. 0x1bcb5ce562f61ccL,0x1eefa212d5d5b17L,0x01c5cb36fe44564L,
  46044. 0x0bb313fabbefb50L,0x00e133586ad1c5aL,0x0548ea612012af2L,
  46045. 0x1ff6cedc4e1890cL,0x1a47138399ccc53L,0x0c9f5f0601c0383L,
  46046. 0x1c6773c3be009bbL,0x00410cfd43c0280L,0x06c1bff8335bb7bL,
  46047. 0x166def80abc0ff0L,0x0a382b63f9ce080L,0x0017e65d7854ff6L },
  46048. { 0x191d4d1b47cac61L,0x08b43d5c370964cL,0x17b0ae53c108ba7L,
  46049. 0x1291cc91cb18d0aL,0x0f89ac57ca40051L,0x13c966cdd48fd97L,
  46050. 0x078553d0648186fL,0x03305a443977a1eL,0x0062eb13bfc4440L,
  46051. 0x1d4be194cbc87eeL,0x05b651819e992fcL,0x0600da46eeb49cfL,
  46052. 0x15ed7f0f23c46ddL,0x1da7b1ebc339626L,0x189cfca08614770L,
  46053. 0x01edea1475c19a4L,0x145800e58fceac6L,0x02b78f22b09c22aL } },
  46054. /* 253 */
  46055. { { 0x1ccb3f632c24f3bL,0x18e3f836c0bf300L,0x02edaa899dda67aL,
  46056. 0x1c108babc11b8c8L,0x181a79a87838affL,0x140cd879a7f658fL,
  46057. 0x092e1a8b8a0b4f9L,0x0738972ef9d046fL,0x10f46b3db876364L,
  46058. 0x032faa04bcb824bL,0x021d8a1e46f90e9L,0x16d868331d8dafcL,
  46059. 0x17093d94bb00220L,0x14eb48592bd9c31L,0x0ab46921004b858L,
  46060. 0x069c605d93b6a41L,0x0f8afee2fc685dcL,0x0488e8c9b12a806L },
  46061. { 0x1b1bd58f5e5af5bL,0x1131dbdb5115389L,0x1137cebcab729f2L,
  46062. 0x134088417b56d7dL,0x0ba36c1116651e5L,0x0121881da2459daL,
  46063. 0x1b2ecf18aff37fdL,0x101bc2b894be352L,0x0be0ad8a1e4d1f9L,
  46064. 0x095e8a71b339d1dL,0x00ebda484ab3760L,0x1738aec12b9c806L,
  46065. 0x0a107f5ca58f6daL,0x044b51d83ef8c41L,0x18ecfc2e40f98f2L,
  46066. 0x10fbdea090a89b0L,0x0655e5019b9c098L,0x015f3a27f507a9cL } },
  46067. /* 254 */
  46068. { { 0x14cd05f5b50f324L,0x0f5920f51e3d102L,0x0971ffe39adee6cL,
  46069. 0x1dd8081104950b1L,0x10cba9bdd83902fL,0x0e4f0f3959324a6L,
  46070. 0x16e07405dbe42caL,0x1f80ba9d6059d75L,0x0874405b1372b8bL,
  46071. 0x0209440bcf568c8L,0x08f74fb0ad23357L,0x14ee7e9aa067a89L,
  46072. 0x0d564c3a0984499L,0x1a17401dd9bd9c6L,0x1d462ca03a6525fL,
  46073. 0x1fbc980f68f4171L,0x07ac710e3c53568L,0x039afaa17e75687L },
  46074. { 0x0a9a17138380039L,0x17f0bfba68ce465L,0x04fb32f06a2eb7eL,
  46075. 0x13fc052e0b25a87L,0x130e9b363c5dbf3L,0x1ea4a522a95ad5cL,
  46076. 0x0b10dfb98c0c8abL,0x13104d535ae7e05L,0x198c53562993562L,
  46077. 0x0434fc3b9a15d9cL,0x04008393e6de683L,0x0349a68f1353aeaL,
  46078. 0x1acfa856376361dL,0x045603f2786f6adL,0x1bc72f501fb9cfeL,
  46079. 0x0b75bf58fa07e13L,0x19e25d697cb4d47L,0x00f4c264e8a5e9cL } },
  46080. /* 255 */
  46081. { { 0x16d05614850c817L,0x12d8c9a44c096e3L,0x055179632efac22L,
  46082. 0x1497cc3cb4e4e7aL,0x17aeb8e18900b5fL,0x0d1ea5d5044348eL,
  46083. 0x1f4f799999abf4dL,0x0b871458332afd8L,0x0a0648e8f668d6fL,
  46084. 0x1cfe4963d6e0ba3L,0x045b0210c1970c7L,0x1440c3cd5cd2474L,
  46085. 0x162aa47e7336370L,0x0f7fb6c231361b9L,0x0fb4b51503097cbL,
  46086. 0x12925300904999bL,0x0014b5bfce0039aL,0x03623a52b3b4a17L },
  46087. { 0x0eb9a417d88e3a1L,0x09e4462423a151dL,0x0344ff9844c4417L,
  46088. 0x16350d3d17cb3bdL,0x0a75d90a148f5b6L,0x0a3009bd455e2cdL,
  46089. 0x13364bc326f1d88L,0x12487f54e8f8704L,0x081763a186a5d0bL,
  46090. 0x1e1a0de4de5d75eL,0x04c583dd174776eL,0x0a5b6eb9cbe9c30L,
  46091. 0x0cd50de4c2a53ceL,0x1aebb2b68af5733L,0x12954a97b6265b1L,
  46092. 0x00b69c9feae2389L,0x0ce215e985a3c53L,0x03592c4aa7d0dd1L } },
  46093. };
  46094. /* Multiply the base point of P1024 by the scalar and return the result.
  46095. * If map is true then convert result to affine coordinates.
  46096. *
  46097. * Stripe implementation.
  46098. * Pre-generated: 2^0, 2^128, ...
  46099. * Pre-generated: products of all combinations of above.
  46100. * 8 doubles and adds (with qz=1)
  46101. *
  46102. * r Resulting point.
  46103. * k Scalar to multiply by.
  46104. * map Indicates whether to convert result to affine.
  46105. * ct Constant time required.
  46106. * heap Heap to use for allocation.
  46107. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  46108. */
  46109. static int sp_1024_ecc_mulmod_base_18(sp_point_1024* r, const sp_digit* k,
  46110. int map, int ct, void* heap)
  46111. {
  46112. return sp_1024_ecc_mulmod_stripe_18(r, &p1024_base, p1024_table,
  46113. k, map, ct, heap);
  46114. }
  46115. #endif
  46116. /* Multiply the base point of P1024 by the scalar and return the result.
  46117. * If map is true then convert result to affine coordinates.
  46118. *
  46119. * km Scalar to multiply by.
  46120. * r Resulting point.
  46121. * map Indicates whether to convert result to affine.
  46122. * heap Heap to use for allocation.
  46123. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  46124. */
  46125. int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap)
  46126. {
  46127. #ifdef WOLFSSL_SP_SMALL_STACK
  46128. sp_point_1024* point = NULL;
  46129. sp_digit* k = NULL;
  46130. #else
  46131. sp_point_1024 point[1];
  46132. sp_digit k[18];
  46133. #endif
  46134. int err = MP_OKAY;
  46135. #ifdef WOLFSSL_SP_SMALL_STACK
  46136. point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap,
  46137. DYNAMIC_TYPE_ECC);
  46138. if (point == NULL)
  46139. err = MEMORY_E;
  46140. if (err == MP_OKAY) {
  46141. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18, heap,
  46142. DYNAMIC_TYPE_ECC);
  46143. if (k == NULL)
  46144. err = MEMORY_E;
  46145. }
  46146. #endif
  46147. if (err == MP_OKAY) {
  46148. sp_1024_from_mp(k, 18, km);
  46149. err = sp_1024_ecc_mulmod_base_18(point, k, map, 1, heap);
  46150. }
  46151. if (err == MP_OKAY) {
  46152. err = sp_1024_point_to_ecc_point_18(point, r);
  46153. }
  46154. #ifdef WOLFSSL_SP_SMALL_STACK
  46155. if (k != NULL)
  46156. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  46157. if (point != NULL)
  46158. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  46159. #endif
  46160. return err;
  46161. }
  46162. /* Multiply the base point of P1024 by the scalar, add point a and return
  46163. * the result. If map is true then convert result to affine coordinates.
  46164. *
  46165. * km Scalar to multiply by.
  46166. * am Point to add to scalar multiply result.
  46167. * inMont Point to add is in montgomery form.
  46168. * r Resulting point.
  46169. * map Indicates whether to convert result to affine.
  46170. * heap Heap to use for allocation.
  46171. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  46172. */
  46173. int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
  46174. int inMont, ecc_point* r, int map, void* heap)
  46175. {
  46176. #ifdef WOLFSSL_SP_SMALL_STACK
  46177. sp_point_1024* point = NULL;
  46178. sp_digit* k = NULL;
  46179. #else
  46180. sp_point_1024 point[2];
  46181. sp_digit k[18 + 18 * 2 * 37];
  46182. #endif
  46183. sp_point_1024* addP = NULL;
  46184. sp_digit* tmp = NULL;
  46185. int err = MP_OKAY;
  46186. #ifdef WOLFSSL_SP_SMALL_STACK
  46187. point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap,
  46188. DYNAMIC_TYPE_ECC);
  46189. if (point == NULL)
  46190. err = MEMORY_E;
  46191. if (err == MP_OKAY) {
  46192. k = (sp_digit*)XMALLOC(
  46193. sizeof(sp_digit) * (18 + 18 * 2 * 37),
  46194. heap, DYNAMIC_TYPE_ECC);
  46195. if (k == NULL)
  46196. err = MEMORY_E;
  46197. }
  46198. #endif
  46199. if (err == MP_OKAY) {
  46200. addP = point + 1;
  46201. tmp = k + 18;
  46202. sp_1024_from_mp(k, 18, km);
  46203. sp_1024_point_from_ecc_point_18(addP, am);
  46204. }
  46205. if ((err == MP_OKAY) && (!inMont)) {
  46206. err = sp_1024_mod_mul_norm_18(addP->x, addP->x, p1024_mod);
  46207. }
  46208. if ((err == MP_OKAY) && (!inMont)) {
  46209. err = sp_1024_mod_mul_norm_18(addP->y, addP->y, p1024_mod);
  46210. }
  46211. if ((err == MP_OKAY) && (!inMont)) {
  46212. err = sp_1024_mod_mul_norm_18(addP->z, addP->z, p1024_mod);
  46213. }
  46214. if (err == MP_OKAY) {
  46215. err = sp_1024_ecc_mulmod_base_18(point, k, 0, 0, heap);
  46216. }
  46217. if (err == MP_OKAY) {
  46218. sp_1024_proj_point_add_18(point, point, addP, tmp);
  46219. if (map) {
  46220. sp_1024_map_18(point, point, tmp);
  46221. }
  46222. err = sp_1024_point_to_ecc_point_18(point, r);
  46223. }
  46224. #ifdef WOLFSSL_SP_SMALL_STACK
  46225. if (k != NULL)
  46226. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  46227. if (point)
  46228. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  46229. #endif
  46230. return err;
  46231. }
  46232. #ifndef WOLFSSL_SP_SMALL
  46233. /* Generate a pre-computation table for the point.
  46234. *
  46235. * gm Point to generate table for.
  46236. * table Buffer to hold pre-computed points table.
  46237. * len Length of table.
  46238. * heap Heap to use for allocation.
  46239. * returns BAD_FUNC_ARG when gm or len is NULL, LENGTH_ONLY_E when table is
  46240. * NULL and length is returned, BUFFER_E if length is too small and 0 otherwise.
  46241. */
  46242. int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
  46243. void* heap)
  46244. {
  46245. #ifdef WOLFSSL_SP_SMALL_STACK
  46246. sp_point_1024* point = NULL;
  46247. sp_digit* t = NULL;
  46248. #else
  46249. sp_point_1024 point[1];
  46250. sp_digit t[38 * 2 * 18];
  46251. #endif
  46252. int err = MP_OKAY;
  46253. if ((gm == NULL) || (len == NULL)) {
  46254. err = BAD_FUNC_ARG;
  46255. }
  46256. if ((err == MP_OKAY) && (table == NULL)) {
  46257. *len = sizeof(sp_table_entry_1024) * 256;
  46258. err = LENGTH_ONLY_E;
  46259. }
  46260. if ((err == MP_OKAY) && (*len < (int)(sizeof(sp_table_entry_1024) * 256))) {
  46261. err = BUFFER_E;
  46262. }
  46263. #ifdef WOLFSSL_SP_SMALL_STACK
  46264. if (err == MP_OKAY) {
  46265. point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap,
  46266. DYNAMIC_TYPE_ECC);
  46267. if (point == NULL)
  46268. err = MEMORY_E;
  46269. }
  46270. if (err == MP_OKAY) {
  46271. t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 18, heap,
  46272. DYNAMIC_TYPE_ECC);
  46273. if (t == NULL)
  46274. err = MEMORY_E;
  46275. }
  46276. #endif
  46277. if (err == MP_OKAY) {
  46278. sp_1024_point_from_ecc_point_18(point, gm);
  46279. err = sp_1024_gen_stripe_table_18(point,
  46280. (sp_table_entry_1024*)table, t, heap);
  46281. }
  46282. if (err == 0) {
  46283. *len = sizeof(sp_table_entry_1024) * 256;
  46284. }
  46285. #ifdef WOLFSSL_SP_SMALL_STACK
  46286. if (t != NULL)
  46287. XFREE(t, heap, DYNAMIC_TYPE_ECC);
  46288. if (point != NULL)
  46289. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  46290. #endif
  46291. return err;
  46292. }
  46293. #else
  46294. /* Generate a pre-computation table for the point.
  46295. *
  46296. * gm Point to generate table for.
  46297. * table Buffer to hold pre-computed points table.
  46298. * len Length of table.
  46299. * heap Heap to use for allocation.
  46300. * returns BAD_FUNC_ARG when gm or len is NULL, LENGTH_ONLY_E when table is
  46301. * NULL and length is returned, BUFFER_E if length is too small and 0 otherwise.
  46302. */
  46303. int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
  46304. void* heap)
  46305. {
  46306. int err = 0;
  46307. if ((gm == NULL) || (len == NULL)) {
  46308. err = BAD_FUNC_ARG;
  46309. }
  46310. if ((err == 0) && (table == NULL)) {
  46311. *len = 0;
  46312. err = LENGTH_ONLY_E;
  46313. }
  46314. if ((err == 0) && (*len != 0)) {
  46315. err = BUFFER_E;
  46316. }
  46317. if (err == 0) {
  46318. *len = 0;
  46319. }
  46320. (void)heap;
  46321. return err;
  46322. }
  46323. #endif
  46324. /* Multiply the point by the scalar and return the result.
  46325. * If map is true then convert result to affine coordinates.
  46326. *
  46327. * km Scalar to multiply by.
  46328. * gm Point to multiply.
  46329. * table Pre-computed points.
  46330. * r Resulting point.
  46331. * map Indicates whether to convert result to affine.
  46332. * heap Heap to use for allocation.
  46333. * returns MEMORY_E when memory allocation fails and MP_OKAY on success.
  46334. */
  46335. int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table,
  46336. ecc_point* r, int map, void* heap)
  46337. {
  46338. #ifdef WOLFSSL_SP_SMALL_STACK
  46339. sp_point_1024* point = NULL;
  46340. sp_digit* k = NULL;
  46341. #else
  46342. sp_point_1024 point[1];
  46343. sp_digit k[18];
  46344. #endif
  46345. int err = MP_OKAY;
  46346. #ifdef WOLFSSL_SP_SMALL_STACK
  46347. point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap,
  46348. DYNAMIC_TYPE_ECC);
  46349. if (point == NULL) {
  46350. err = MEMORY_E;
  46351. }
  46352. if (err == MP_OKAY) {
  46353. k = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18, heap, DYNAMIC_TYPE_ECC);
  46354. if (k == NULL)
  46355. err = MEMORY_E;
  46356. }
  46357. #endif
  46358. if (err == MP_OKAY) {
  46359. sp_1024_from_mp(k, 18, km);
  46360. sp_1024_point_from_ecc_point_18(point, gm);
  46361. #ifndef WOLFSSL_SP_SMALL
  46362. err = sp_1024_ecc_mulmod_stripe_18(point, point,
  46363. (const sp_table_entry_1024*)table, k, map, 0, heap);
  46364. #else
  46365. (void)table;
  46366. err = sp_1024_ecc_mulmod_18(point, point, k, map, 0, heap);
  46367. #endif
  46368. }
  46369. if (err == MP_OKAY) {
  46370. err = sp_1024_point_to_ecc_point_18(point, r);
  46371. }
  46372. #ifdef WOLFSSL_SP_SMALL_STACK
  46373. if (k != NULL)
  46374. XFREE(k, heap, DYNAMIC_TYPE_ECC);
  46375. if (point != NULL)
  46376. XFREE(point, heap, DYNAMIC_TYPE_ECC);
  46377. #endif
  46378. return err;
  46379. }
  46380. /* Multiply p* in projective coordinates by q*.
  46381. *
  46382. * r.x = p.x - (p.y * q.y)
  46383. * r.y = (p.x * q.y) + p.y
  46384. *
  46385. * px [in,out] A single precision integer - X ordinate of number to multiply.
  46386. * py [in,out] A single precision integer - Y ordinate of number to multiply.
  46387. * q [in] A single precision integer - multiplier.
  46388. * t [in] Two single precision integers - temps.
  46389. */
  46390. static void sp_1024_proj_mul_qx1_18(sp_digit* px, sp_digit* py,
  46391. const sp_digit* q, sp_digit* t)
  46392. {
  46393. sp_digit* t1 = t;
  46394. sp_digit* t2 = t + 2 * 18;
  46395. /* t1 = p.x * q.y */
  46396. sp_1024_mont_mul_18(t1, px, q, p1024_mod, p1024_mp_mod);
  46397. /* t2 = p.y * q.y */
  46398. sp_1024_mont_mul_18(t2, py, q, p1024_mod, p1024_mp_mod);
  46399. /* r.x = p.x - (p.y * q.y) */
  46400. sp_1024_mont_sub_18(px, px, t2, p1024_mod);
  46401. /* r.y = (p.x * q.y) + p.y */
  46402. sp_1024_mont_add_18(py, t1, py, p1024_mod);
  46403. }
  46404. /* Square p* in projective coordinates.
  46405. *
  46406. * px' = (p.x + p.y) * (p.x - p.y) = p.x^2 - p.y^2
  46407. * py' = 2 * p.x * p.y
  46408. *
  46409. * px [in,out] A single precision integer - X ordinate of number to square.
  46410. * py [in,out] A single precision integer - Y ordinate of number to square.
  46411. * t [in] Two single precision integers - temps.
  46412. */
  46413. static void sp_1024_proj_sqr_18(sp_digit* px, sp_digit* py, sp_digit* t)
  46414. {
  46415. sp_digit* t1 = t;
  46416. sp_digit* t2 = t + 2 * 18;
  46417. /* t1 = p.x + p.y */
  46418. sp_1024_mont_add_18(t1, px, py, p1024_mod);
  46419. /* t2 = p.x - p.y */
  46420. sp_1024_mont_sub_18(t2, px, py, p1024_mod);
  46421. /* r.y = p.x * p.y */
  46422. sp_1024_mont_mul_18(py, px, py, p1024_mod, p1024_mp_mod);
  46423. /* r.x = (p.x + p.y) * (p.x - p.y) */
  46424. sp_1024_mont_mul_18(px, t1, t2, p1024_mod, p1024_mp_mod);
  46425. /* r.y = (p.x * p.y) * 2 */
  46426. sp_1024_mont_dbl_18(py, py, p1024_mod);
  46427. }
  46428. #ifdef WOLFSSL_SP_SMALL
  46429. /* Perform the modular exponentiation in Fp* for SAKKE.
  46430. *
  46431. * Simple square and multiply when expontent bit is one algorithm.
  46432. * Square and multiply performed in Fp*.
  46433. *
  46434. * base [in] Base. MP integer.
  46435. * exp [in] Exponent. MP integer.
  46436. * res [out] Result. MP integer.
  46437. * returns 0 on success and MEMORY_E if memory allocation fails.
  46438. */
  46439. int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
  46440. {
  46441. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  46442. defined(WOLFSSL_SP_SMALL_STACK)
  46443. sp_digit* td;
  46444. sp_digit* t;
  46445. sp_digit* tx;
  46446. sp_digit* ty;
  46447. sp_digit* b;
  46448. sp_digit* e;
  46449. #else
  46450. sp_digit t[36 * 2 * 18];
  46451. sp_digit tx[2 * 18];
  46452. sp_digit ty[2 * 18];
  46453. sp_digit b[2 * 18];
  46454. sp_digit e[2 * 18];
  46455. #endif
  46456. sp_digit* r;
  46457. int err = MP_OKAY;
  46458. int bits;
  46459. int i;
  46460. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  46461. defined(WOLFSSL_SP_SMALL_STACK)
  46462. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 18 * 2, NULL,
  46463. DYNAMIC_TYPE_TMP_BUFFER);
  46464. if (td == NULL) {
  46465. err = MEMORY_E;
  46466. }
  46467. #endif
  46468. if (err == MP_OKAY) {
  46469. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  46470. defined(WOLFSSL_SP_SMALL_STACK)
  46471. t = td;
  46472. tx = td + 36 * 18 * 2;
  46473. ty = td + 37 * 18 * 2;
  46474. b = td + 38 * 18 * 2;
  46475. e = td + 39 * 18 * 2;
  46476. #endif
  46477. r = ty;
  46478. bits = mp_count_bits(exp);
  46479. sp_1024_from_mp(b, 18, base);
  46480. sp_1024_from_mp(e, 18, exp);
  46481. XMEMCPY(tx, p1024_norm_mod, sizeof(sp_digit) * 18);
  46482. sp_1024_mul_18(b, b, p1024_norm_mod);
  46483. err = sp_1024_mod_18(b, b, p1024_mod);
  46484. }
  46485. if (err == MP_OKAY) {
  46486. XMEMCPY(ty, b, sizeof(sp_digit) * 18);
  46487. for (i = bits - 2; i >= 0; i--) {
  46488. sp_1024_proj_sqr_18(tx, ty, t);
  46489. if ((e[i / 57] >> (i % 57)) & 1) {
  46490. sp_1024_proj_mul_qx1_18(tx, ty, b, t);
  46491. }
  46492. }
  46493. }
  46494. if (err == MP_OKAY) {
  46495. sp_1024_mont_inv_18(tx, tx, t);
  46496. XMEMSET(tx + 18, 0, sizeof(sp_digit) * 18);
  46497. sp_1024_mont_reduce_18(tx, p1024_mod, p1024_mp_mod);
  46498. XMEMSET(ty + 18, 0, sizeof(sp_digit) * 18);
  46499. sp_1024_mont_reduce_18(ty, p1024_mod, p1024_mp_mod);
  46500. sp_1024_mul_18(r, tx, ty);
  46501. err = sp_1024_mod_18(r, r, p1024_mod);
  46502. }
  46503. if (err == MP_OKAY) {
  46504. err = sp_1024_to_mp(r, res);
  46505. }
  46506. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  46507. defined(WOLFSSL_SP_SMALL_STACK)
  46508. if (td != NULL) {
  46509. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  46510. }
  46511. #endif
  46512. return err;
  46513. }
  46514. #else
  46515. /* Pre-computed table for exponentiating g.
  46516. * Striping: 8 points at a distance of (128 combined for
  46517. * a total of 256 points.
  46518. */
  46519. static const sp_digit sp_1024_g_table[256][18] = {
  46520. { 0x000000000000000L, 0x000000000000000L, 0x000000000000000L,
  46521. 0x000000000000000L, 0x000000000000000L, 0x000000000000000L,
  46522. 0x000000000000000L, 0x000000000000000L, 0x000000000000000L,
  46523. 0x000000000000000L, 0x000000000000000L, 0x000000000000000L,
  46524. 0x000000000000000L, 0x000000000000000L, 0x000000000000000L,
  46525. 0x000000000000000L, 0x000000000000000L, 0x000000000000000L },
  46526. { 0x10a46d2335c1685L, 0x0f4b8f0803d2c0bL, 0x0f7d0f2929cfab2L,
  46527. 0x0b04c848ea81d1eL, 0x136576d12646f81L, 0x1f8d7d9d7a4dda5L,
  46528. 0x1479b6278b451caL, 0x0f84f7d10585fa2L, 0x1addedc858f8871L,
  46529. 0x16c2cdf8b563637L, 0x10686cb63ab9635L, 0x1400c383e61a1ceL,
  46530. 0x1a9b67e0966faf7L, 0x1e9da7beb36de84L, 0x09f263887c47019L,
  46531. 0x16442c2a574058eL, 0x0f4afd58891e86cL, 0x02cf49e3535e9ddL },
  46532. { 0x14dd36f71dd4594L, 0x0e64f805778f372L, 0x113a867d94c2ef2L,
  46533. 0x127ea412513d4b4L, 0x0f5c14188588aa9L, 0x09ccfd4ba9bca64L,
  46534. 0x1aad4462f5e4b04L, 0x0a5737a75fbeb96L, 0x1813d1cb22ecb96L,
  46535. 0x0a2b133a01c4c09L, 0x1c466d2b210c73fL, 0x152214301d6ca3eL,
  46536. 0x179f7bfa2edd9f6L, 0x0854e86c89ca368L, 0x00dcf4c5bc618c5L,
  46537. 0x0a572be33841adfL, 0x003be85ac6a9b6aL, 0x031f78c3dba7b17L },
  46538. { 0x0376b7f016f45e7L, 0x1edab95f6417c3eL, 0x1d07390a6d80706L,
  46539. 0x058f5fb03ae725eL, 0x1241098b6fdbf0aL, 0x107c67ded20d8fbL,
  46540. 0x0f1356d01d1d2edL, 0x17d267c1a836661L, 0x1ae182830733fa3L,
  46541. 0x07694cd87ae3668L, 0x0cd538fe6183228L, 0x130c2aab3882ffeL,
  46542. 0x1c129f85cbb1360L, 0x03b42fdf55865b1L, 0x06658cda0bb3125L,
  46543. 0x059b4a0bd1d85d6L, 0x02390dcc794ddacL, 0x027f33c8e78c96dL },
  46544. { 0x0a423d505e8733cL, 0x02f328eab8be0caL, 0x1a23a586cc8b321L,
  46545. 0x0db683039846f8fL, 0x113bd7210c4471cL, 0x00bd8480643af13L,
  46546. 0x1abda77f7a7b6cbL, 0x14c8614dbcbd119L, 0x1aaa7a61a7b81ceL,
  46547. 0x1296813119fcc6aL, 0x1bf74181a26a6baL, 0x0f9cb95895576abL,
  46548. 0x148e95076130cfaL, 0x074d0f297d26d88L, 0x01005c0c255c311L,
  46549. 0x1b3a431843ec234L, 0x097555d1ffebe78L, 0x00224150c2b0ed9L },
  46550. { 0x1758ac273d486d8L, 0x0fca330e6e0f3f3L, 0x07f08622ad3e05aL,
  46551. 0x05e66e6c60e4793L, 0x1d8c2260a0e54f0L, 0x18de302b05f712dL,
  46552. 0x1fad4a3f0c1f114L, 0x06fade43e34fc89L, 0x1c8e4499c57128dL,
  46553. 0x11d829f6bd97522L, 0x09e810ca8f488a5L, 0x0a9a6a8b2cd0818L,
  46554. 0x1fd73557e95b518L, 0x034903bd3370d24L, 0x0d09c083499ff66L,
  46555. 0x1b689f426a1a7ceL, 0x09f1a9c3f2568ccL, 0x0419d07fc6f6dfcL },
  46556. { 0x0c419c7ab376b76L, 0x14a7993e8786654L, 0x078aa4314534edcL,
  46557. 0x1d4c4aeb4dcad77L, 0x098c0a88931ba51L, 0x00b5152b7f703d8L,
  46558. 0x0982c12f96bbad3L, 0x0e1ca266a17cdd6L, 0x1339edad6a1d5c2L,
  46559. 0x1b376acf4edd6e8L, 0x0efa20b741bb03cL, 0x139196230fb6842L,
  46560. 0x01d8a1058a22d63L, 0x115ba2788ff64afL, 0x1c170300fdcfa9aL,
  46561. 0x02340e83faa35e9L, 0x05f2e2df95a85f8L, 0x034959e71f5924bL },
  46562. { 0x0e6cb72d2a127b4L, 0x03752c7c940b786L, 0x118d1e8dd8599a9L,
  46563. 0x03c1572ddc87d9eL, 0x12edbe8c163d9a0L, 0x127332e40a2e36dL,
  46564. 0x14be4bd09b2b937L, 0x0622e9a1680e9c4L, 0x054c240d77d2af8L,
  46565. 0x00fd1cb9eb2949bL, 0x05247282751a556L, 0x0a66a8a4c8780b7L,
  46566. 0x11d41283278c4e8L, 0x181b0f92996b219L, 0x1bc27c9911e40e1L,
  46567. 0x0bfc0ee83236313L, 0x0d6c0cf0aaf81deL, 0x0199f21857a0021L },
  46568. { 0x1f04de4cf26d3b7L, 0x1b9835a9fbcdf2eL, 0x117c6022d9915e9L,
  46569. 0x090a06e6c148027L, 0x0b061037ef291eaL, 0x0489dd8ffe4ebe8L,
  46570. 0x0161f6741376597L, 0x0ab29146f5fe277L, 0x0b5443483fe3ee7L,
  46571. 0x1e10f3a023189c3L, 0x041397377ad630fL, 0x10c4cae59aa5674L,
  46572. 0x0115aaa40894fe1L, 0x02cf523175cd38dL, 0x1ac0a8e2b71bf95L,
  46573. 0x123a37631a2ea95L, 0x108ae1276362f77L, 0x00874598eeb5debL },
  46574. { 0x07f03e53ed9f1afL, 0x0923bab33b0b35cL, 0x18c1d33856e00ebL,
  46575. 0x004d63d0b671b9aL, 0x1af99c151877e2bL, 0x012a3d58b2a68b8L,
  46576. 0x17bd65e0ba7924eL, 0x098db8ff8f84daaL, 0x19038f95d2fbeb5L,
  46577. 0x12c86ff01b601abL, 0x0dbab93f70fdfffL, 0x18a9e6bc35119f9L,
  46578. 0x12da0a5568cb1fbL, 0x0db7aaab9e470edL, 0x0b0281a6a1ce4fdL,
  46579. 0x12b5670c8d665cfL, 0x0bcfd261c832a84L, 0x03242a926066e62L },
  46580. { 0x0bfb3e2c4a6ff2aL, 0x01fdd1ad321450dL, 0x1fc226bfdd08aa8L,
  46581. 0x1574bb7b2710844L, 0x12a182cb2337883L, 0x100f829c0c3574eL,
  46582. 0x079eae7c1d93526L, 0x0b724823fd722f6L, 0x0700b1903570cbbL,
  46583. 0x0a8c0eadc8a5f3eL, 0x1110dc660460b57L, 0x1a48ae97332e26bL,
  46584. 0x15632d28b232758L, 0x1d1c1f84d328547L, 0x08cf600901e2eb3L,
  46585. 0x16892ca8d4c1801L, 0x03ca4061c7a2df8L, 0x00fbb79f9791a2bL },
  46586. { 0x0a2c14344c436b0L, 0x182ab0fb4e43d4dL, 0x05ed7db6cb7de41L,
  46587. 0x03daad75046be62L, 0x1d0afa4885761f4L, 0x0e738f7c18a327bL,
  46588. 0x1d222a67ca454ebL, 0x07564f7ed2622d6L, 0x0a98a5a8c9bb944L,
  46589. 0x1c3c0131772fef4L, 0x1e4f74604ab2ddfL, 0x0999b909792474dL,
  46590. 0x0ff1d4995aaf92aL, 0x0276c4ce9e12b15L, 0x14a94e3f67f0cf0L,
  46591. 0x14e4d805195289dL, 0x005d0f367bb049eL, 0x0024927fd9e8847L },
  46592. { 0x0548e3dc673562fL, 0x19812f175724603L, 0x0cad7871a5df4ecL,
  46593. 0x08dd7caaf7cc3faL, 0x01d6e18e424e206L, 0x0bf4adbb39c8e02L,
  46594. 0x06e312e3aee3853L, 0x1a695d16fa84132L, 0x0f8a0df66e01290L,
  46595. 0x0bf1251c92f2fa7L, 0x1ecb2c54209cab2L, 0x0e5c4a0e4cc2f34L,
  46596. 0x029062fa49b40b0L, 0x19e29de76d6cf0cL, 0x0509e661e029e13L,
  46597. 0x1084cb15056ed3eL, 0x03508cd849cc146L, 0x026fe7404e1c057L },
  46598. { 0x1069cb2d527b780L, 0x0d00acbbc986ea2L, 0x002f89f4098f54bL,
  46599. 0x0d765a36562198cL, 0x154adf3c34102c2L, 0x187fa3a6329311aL,
  46600. 0x1b9f35a244e0917L, 0x11507f5198b9522L, 0x11e10f139d15c8dL,
  46601. 0x0b9ee1740ee2b59L, 0x1b2c11713b66ebcL, 0x0fb08fa02450ff9L,
  46602. 0x139f3a532f307fdL, 0x110a9e111252b8aL, 0x0a2902167a7a077L,
  46603. 0x17a478ac4b2bbc8L, 0x002dc7daff89339L, 0x00683ac845c5034L },
  46604. { 0x10af2a7de085f2aL, 0x06927df4cd972c3L, 0x0985672904ee23fL,
  46605. 0x090ab3f0a31181aL, 0x1622da0d1f02a2eL, 0x051b0ac1dcb010fL,
  46606. 0x11a0970170bd5b7L, 0x17c02919e38f221L, 0x0392f2896272695L,
  46607. 0x01e85dad46b277bL, 0x14891073f2f14a2L, 0x19d8a4c22fcbde1L,
  46608. 0x19f04928e9f5dafL, 0x1c9f97155b43095L, 0x0304544a0fdd134L,
  46609. 0x01bfdf7ddafdae0L, 0x15af2cde215a436L, 0x0127d4b0e178429L },
  46610. { 0x167db3f616df7f6L, 0x02bec7dec819303L, 0x0a41ba0b551190cL,
  46611. 0x0ad12c87b62e9b5L, 0x0c89a0602284f34L, 0x013e890c58c8efeL,
  46612. 0x14516ead1abd35bL, 0x13cb4afe90d9312L, 0x0c03214e9cc942fL,
  46613. 0x19f0e47a0ca80acL, 0x0dd67ce6b50eac9L, 0x16ffca1dc2e719dL,
  46614. 0x1c8f4d7d4e5e1b8L, 0x1aab01f9fb1ad8fL, 0x14be9823bfddf8dL,
  46615. 0x16dc2403ec3a2eeL, 0x11494d7a03d4a6fL, 0x01b8e611efe2780L },
  46616. { 0x09b115dda90c351L, 0x0b75f9b26ce0314L, 0x080bd942cc6db46L,
  46617. 0x08deaec85eef512L, 0x08100127cc28c16L, 0x06403dee27bf1b0L,
  46618. 0x103ca20db342371L, 0x0a62501e2adc004L, 0x03f9a6d7899cb39L,
  46619. 0x0524a699d40101cL, 0x05fa47a1f4d1d10L, 0x1a0e4dbbc4948adL,
  46620. 0x0d7640c30e70d97L, 0x0dd37363037b52cL, 0x0f04fa00f0b03a1L,
  46621. 0x1af1e661ed4f5e3L, 0x17f3e602e4fc9f4L, 0x0495b5e5006407dL },
  46622. { 0x03d5c835f00822eL, 0x12b895c58b78917L, 0x07124ac28cc03a0L,
  46623. 0x1b4f9832a903865L, 0x1bb1413f6b4e32aL, 0x09651385f74e770L,
  46624. 0x0454fb7edeea92aL, 0x1f39a8e55f5d477L, 0x0e8f09e7e00f0c0L,
  46625. 0x070ec392e6f5db8L, 0x0eb8212a6d8eda9L, 0x03707fab1ecbfc5L,
  46626. 0x1aa3b62759f4014L, 0x1c8718446bf62f6L, 0x09df8c66abdb99dL,
  46627. 0x10e3842b5b0603eL, 0x09de7db4b98cf33L, 0x038ffb164a7817cL },
  46628. { 0x04c71022a4a84d9L, 0x12566af5e38f355L, 0x0297c73595e38bbL,
  46629. 0x1fffe2414a76235L, 0x09e6503383f5ef9L, 0x0220c05262cc708L,
  46630. 0x0a30787a7e64328L, 0x0d717065a8deb30L, 0x0753f28a033af53L,
  46631. 0x176e258db6a7b45L, 0x19a4a9cb3347c24L, 0x1efba444c865dbbL,
  46632. 0x1ea3d2661cd3aa0L, 0x1ee1beed1c6ddb1L, 0x1bdad33c7867f1bL,
  46633. 0x174d2d83166a109L, 0x073e6a83fe9df1bL, 0x0207ea3f3afcac1L },
  46634. { 0x188b746267140a4L, 0x1fe0f755b797dadL, 0x0239a6189521b6eL,
  46635. 0x025d6ddf85bb3d9L, 0x0ac8ff8869beebaL, 0x110ca867e110a54L,
  46636. 0x1eda6575725bad6L, 0x06f2671380a82e3L, 0x02d85d4521b4683L,
  46637. 0x06b45042089a12eL, 0x1004e7b1b085d05L, 0x172fee60109bca5L,
  46638. 0x061f578aa320cf0L, 0x1cdb57218d60b51L, 0x1529a5462e7eacfL,
  46639. 0x1c50cd1b04223b0L, 0x18c0b334d98dffbL, 0x02d8e08abf31c99L },
  46640. { 0x0edaab172b6bb8fL, 0x12769017e496148L, 0x0f17f9a531ce371L,
  46641. 0x1f96a9b9c9e8574L, 0x032420dc316dc65L, 0x16e7ca6596b351bL,
  46642. 0x0b2745b9c1b9c15L, 0x15050138ec949e6L, 0x1ab18d830ea6edcL,
  46643. 0x1e8d67340e32fabL, 0x059471f684b0413L, 0x1acd8ef234903f2L,
  46644. 0x14785e67a30ac3bL, 0x0d07eac8db568e7L, 0x0718d13934ff113L,
  46645. 0x015679c2c9002dcL, 0x0f484de9cb833e5L, 0x04b1d5c1d53ab77L },
  46646. { 0x04b47d8df4ea5a3L, 0x1440aae7f22ff4aL, 0x156228f0d592595L,
  46647. 0x1dcf933c2ba2dcfL, 0x155071bc84e55b3L, 0x02bee71ff71026fL,
  46648. 0x155c1c401bca410L, 0x159fd18721b774eL, 0x03645bcb63319adL,
  46649. 0x0c4f4583e105fecL, 0x1425a5f5f655e20L, 0x0643733e9c771caL,
  46650. 0x01a60cfb6a037d1L, 0x01b9c16d008d929L, 0x107701d99652aaaL,
  46651. 0x13109913723fb07L, 0x1586b82b899076bL, 0x0221a407e5f22e2L },
  46652. { 0x0ffffb49114221aL, 0x027971f42bd3d7cL, 0x03903e951e1d2bbL,
  46653. 0x03adf2c2a485c5aL, 0x1bfe9b77ef3e6b3L, 0x01d4355914b29bfL,
  46654. 0x0ab1b0aa743cbedL, 0x0f6482509da48aeL, 0x1a3868917e721baL,
  46655. 0x1f7be00608bd3c6L, 0x1241c74c5816b36L, 0x153c0cb51dd2702L,
  46656. 0x18c442be82c2dadL, 0x1b6b95ac6ad89c6L, 0x0c0f9b66db0892fL,
  46657. 0x006e373a6ab9f1dL, 0x1ebab6d1eb0a170L, 0x04b88c54467fd53L },
  46658. { 0x19c59a2cdecb5d8L, 0x1e40dd49d34335fL, 0x160411dd3efe020L,
  46659. 0x154040e16849c1bL, 0x0fbfb781e779a3cL, 0x1950e24e9a97dd8L,
  46660. 0x19406a2c36080fbL, 0x1e570b0c6f62967L, 0x15ba70a498a882fL,
  46661. 0x13980419d8377d2L, 0x100bd040bfb8aa8L, 0x05331404474b485L,
  46662. 0x0685c3fc72e4e76L, 0x1f297573edd15d1L, 0x03d17d9553f9d8fL,
  46663. 0x070f8616a80b44eL, 0x082d56a177aa573L, 0x00be03bc6a5b8fdL },
  46664. { 0x06dff1d2735e37bL, 0x0272b32b762b907L, 0x12767aeea5e3262L,
  46665. 0x117413e78945eb5L, 0x15b0437740fa451L, 0x1d1765461fd0bbfL,
  46666. 0x0f50286877b3659L, 0x094ed1794e00a51L, 0x1f224952b18691cL,
  46667. 0x1709622f436afeaL, 0x16455cde1669a85L, 0x061341ff9c1cf41L,
  46668. 0x1ba96cc9a3723f4L, 0x0d691d1c2d46dbcL, 0x0fd7611b744ab80L,
  46669. 0x1dacd3ffd8743c5L, 0x0c6d6ce84e1a452L, 0x0090ceae42b8ff2L },
  46670. { 0x1eaa67f262969ebL, 0x159ce9781f3b9a1L, 0x19455eec2424e8eL,
  46671. 0x1b1a2a04e9cc24fL, 0x0580bdbd0f82b0eL, 0x1a1f35ffffe56c7L,
  46672. 0x04759474f41d6a5L, 0x11029097b631758L, 0x095cd9990eb24c3L,
  46673. 0x0b530e83fd633e3L, 0x03dd8a8139ae1c8L, 0x1ac3974af990861L,
  46674. 0x0dd234a07a2865dL, 0x1d03c9fc9e14b58L, 0x18a7b39dbe4a0e4L,
  46675. 0x0de84e16afc3e17L, 0x0301314a82f7e62L, 0x01646bd596b2bf9L },
  46676. { 0x1cf58920825e4d6L, 0x0f552b77c1da233L, 0x17604c4042377d4L,
  46677. 0x0b1ba12c7ec7cccL, 0x1df6436a229f89fL, 0x0f5dd3c6258a6ecL,
  46678. 0x1ce06676b91a751L, 0x1d6231556eeb49bL, 0x1da8978bd29e37fL,
  46679. 0x0e76ad556516bf7L, 0x03417719f5aa29aL, 0x1e1aeff09468d93L,
  46680. 0x0eed8cd59a7474bL, 0x08e9cc7dea21459L, 0x0882c46c3f47357L,
  46681. 0x09888b2c027b729L, 0x15896eb705a1b40L, 0x0114ce93ba584ecL },
  46682. { 0x19cd58dc64397e6L, 0x0c78f5fb6e98f2dL, 0x0384fa7c76cab06L,
  46683. 0x0f1f9b8d18b0cdbL, 0x053c01fd405ae28L, 0x0edafb52594066fL,
  46684. 0x1e2837258fcb504L, 0x117dabaa3137d89L, 0x0336fd13d916ee9L,
  46685. 0x092d8d98216fa47L, 0x158a46b3801d39aL, 0x16904a62fd2a19eL,
  46686. 0x0b821c446be8d38L, 0x185b2c9a63d68e9L, 0x1283541c71104d7L,
  46687. 0x0d84d2e36e6dea5L, 0x18eaf9ffa5727b4L, 0x010d633bc8c9b30L },
  46688. { 0x1420e3f2d7fbcd2L, 0x11239cbdefe0c55L, 0x0fe137d752d049cL,
  46689. 0x0c700f6fa692406L, 0x133c36256fcd423L, 0x19140a6fe0cd84dL,
  46690. 0x066e04f5bcdd683L, 0x138e12f14b206f8L, 0x14f3989970ff27bL,
  46691. 0x0070d22b0ad21c4L, 0x0d25a8f980bdd3fL, 0x086364c39439ff4L,
  46692. 0x1bee0164cdc3f1cL, 0x13fbdf4fb09108eL, 0x10b86ecc118fb93L,
  46693. 0x074ac02befcf125L, 0x1d8663d88d62448L, 0x0074760f387316cL },
  46694. { 0x08ccc298a0878ddL, 0x00baeb320038d54L, 0x0082945cd85e66bL,
  46695. 0x1dbab1462b20689L, 0x08d221a1316d023L, 0x0e2471983c2dea4L,
  46696. 0x09dc6dd2cf79e56L, 0x0a685dc070498cfL, 0x159ef6cdde0b914L,
  46697. 0x01857144d91bf48L, 0x11e93125760c95eL, 0x02fda0ee6ccdc30L,
  46698. 0x06a294a32567b12L, 0x0326c1932c0c964L, 0x0c4f96ddaa83d5aL,
  46699. 0x0e7fbc5457a25e9L, 0x035d850c1c01b6bL, 0x0329d3cafae881bL },
  46700. { 0x1e2898550dcb199L, 0x1c72f3fd015b067L, 0x1f0f25d80f42cd6L,
  46701. 0x1a4fe2636b794faL, 0x02b12d52b0e5288L, 0x1b92e39d53826f7L,
  46702. 0x0c44f881ac76076L, 0x0c6162507358ba3L, 0x014f970cbdb45d7L,
  46703. 0x0cbfc9f59092f47L, 0x15ce73b9f6a89b2L, 0x1a7e3fde41d37aeL,
  46704. 0x147c6a42b146ecbL, 0x13fd87e8fcca508L, 0x103692f4a27ad3cL,
  46705. 0x0f2ec2230da6334L, 0x15e083f65a5fb9dL, 0x0186fe23dea2233L },
  46706. { 0x0fc5ae29eaadfe8L, 0x13f2a5a6a74095eL, 0x0b7e2d4cd584940L,
  46707. 0x08ad4d4429560e0L, 0x1059068ea2b9c20L, 0x018887d8d1efbd1L,
  46708. 0x038728d452c8662L, 0x1096f7c466d896fL, 0x017073ce63e2f69L,
  46709. 0x1708a5316efbd63L, 0x064afc1f5f0f221L, 0x1c17d635c5124ecL,
  46710. 0x15251849395da69L, 0x003d1d504c1d78bL, 0x03f88626b14a935L,
  46711. 0x04a022a6b8fb55cL, 0x0cfe16fe872397fL, 0x02b952c8faa6109L },
  46712. { 0x166841909a5553aL, 0x0a18c193b99de24L, 0x12c8fbbf5a40fc1L,
  46713. 0x17e4424da9f39d6L, 0x0fed9578bd3cbf9L, 0x01836c36cb38e01L,
  46714. 0x13f96ee965f3b28L, 0x0ed6e0bdac27aceL, 0x1f1d3622b67f33fL,
  46715. 0x0de79e308e5c618L, 0x119f7394f46aa45L, 0x1253f2115687470L,
  46716. 0x1d8d15767a902feL, 0x0857e83db71f24cL, 0x02c643a050b6d72L,
  46717. 0x1349c2418df78d9L, 0x03c80c865532491L, 0x032e165f0ec6416L },
  46718. { 0x04cda20a660bb63L, 0x01d8543743122b4L, 0x13d9ae83bb5c9f7L,
  46719. 0x0acf3ba2b0ec8e5L, 0x08452d4479c162eL, 0x1fabcf5b44213b8L,
  46720. 0x05dc20a6f1acd04L, 0x10725d42bd92a02L, 0x15e34e300477381L,
  46721. 0x01e51a4b9f0e978L, 0x13c7708a6f4f7a3L, 0x1e3729defda74b8L,
  46722. 0x0ddfae7a1a783efL, 0x0d04cc29236db9cL, 0x173d2ad0d4f5cb8L,
  46723. 0x111724a675ab141L, 0x166d80550160e78L, 0x0418a206a9dd3bfL },
  46724. { 0x03e2e32f611b2daL, 0x13714e87d23567aL, 0x0fa2082cf035741L,
  46725. 0x0c3a7c89e1d12feL, 0x1fd27a66c45c28eL, 0x0f428bc94ebfb36L,
  46726. 0x1e375cd6e182840L, 0x035d47f9d307bc0L, 0x1c9977db5638ce1L,
  46727. 0x0441c17a429b59dL, 0x11e8f1932b7f181L, 0x1eff0428f6e2fc1L,
  46728. 0x0c1b411e3e3cd17L, 0x0c2fda36f4ab31eL, 0x1c467295ce6b23eL,
  46729. 0x0502a70a7339b79L, 0x1664a985a70e15aL, 0x028261d4536afa2L },
  46730. { 0x0b55283b8fa53c7L, 0x07f9c284a3a7180L, 0x10710df3897e617L,
  46731. 0x01cb4253da469a4L, 0x0abcc6742983243L, 0x140f70b569c4ab5L,
  46732. 0x09c0a8b700075fbL, 0x17698478d6cce16L, 0x0b35e567ea6e8a3L,
  46733. 0x03859e7534b39f5L, 0x1ea70f9b8a3ab2fL, 0x09bcaa6f6fb50b4L,
  46734. 0x056de937dc2ae68L, 0x1c2182112f6561fL, 0x1f71482fcba9b27L,
  46735. 0x0d5ba7195efa0efL, 0x1d2c27af0b169f5L, 0x024b7234ce38e90L },
  46736. { 0x014fc829fa93467L, 0x1bb420759530a5dL, 0x1ebd20cf826f0b8L,
  46737. 0x046d0d7b98cb379L, 0x01f3216abc85975L, 0x0040dc205fe8404L,
  46738. 0x1e4ef118ef6985fL, 0x18b7a03f50d7608L, 0x05a21ece62cd640L,
  46739. 0x1dfb52a1101eae2L, 0x103b7254459ede5L, 0x195eecb744d19d6L,
  46740. 0x09aeab51f9d67aaL, 0x186b431d45d06cfL, 0x1c1a54b052c857aL,
  46741. 0x0896a6a99b9b7cbL, 0x1e84f2b5ccfcb37L, 0x0099c48b98981bfL },
  46742. { 0x068064045003cd1L, 0x00bde2257156377L, 0x067f7a394c53f6bL,
  46743. 0x138f9d52b8979a8L, 0x18f37e0181e34ebL, 0x04c8645dabbb169L,
  46744. 0x129efb3133ec098L, 0x1de178927f2a146L, 0x068074172543304L,
  46745. 0x1607e5935e45515L, 0x0a6d18ed17fa96bL, 0x0a5cabf7b7593cfL,
  46746. 0x060485dff44bb29L, 0x06f523cb2878605L, 0x178e8080b144135L,
  46747. 0x1e68ba59df412d2L, 0x1bd4c8102b46da1L, 0x021175ab9f9c19fL },
  46748. { 0x0592eb6a6ad3f47L, 0x10fb6cb8a5d0756L, 0x04641ca05166c21L,
  46749. 0x04c9d4b006af83dL, 0x14b12723cf7c94eL, 0x1db9b53929bb562L,
  46750. 0x0f373ca9ae9076bL, 0x15b913d12419740L, 0x0f2e20cb45b0fd3L,
  46751. 0x1752d2a6b302cffL, 0x0fea2e2277e2f09L, 0x0fc2cd47e57fdccL,
  46752. 0x1c747312e140f1cL, 0x193cccff84ff5e4L, 0x1f4ac15f466e709L,
  46753. 0x05b8d53f776996fL, 0x182cfba27d7a0daL, 0x01b42a0e7961292L },
  46754. { 0x10d3c9e22799d37L, 0x1bef2d67d199d28L, 0x063c203de56c6d9L,
  46755. 0x155f91bf849cd5cL, 0x0e842dc269b53c2L, 0x033ff43cbaa0db0L,
  46756. 0x161df569bcabeb0L, 0x1e5a04114077a0fL, 0x034b473f0654be2L,
  46757. 0x13e08157a8af11fL, 0x16fe74ab06bd239L, 0x14836d427a01601L,
  46758. 0x0a97e94c11e264fL, 0x0352c37a0b34bc3L, 0x1e49fa427633cb6L,
  46759. 0x14acc0e77f0d38fL, 0x134b89778802241L, 0x02cd2dfac911309L },
  46760. { 0x1d1c91e81347191L, 0x00d5e75cb4cb974L, 0x1d9ea751a9fc61bL,
  46761. 0x19b54fa72e0f110L, 0x191b9aa0da93cfcL, 0x0e9e36045f74f8eL,
  46762. 0x00402099ff5e3e3L, 0x1f7f270c1a12845L, 0x06a6a71aadadb47L,
  46763. 0x055035bd30ab7c5L, 0x0c1780e6122f267L, 0x046e5555226b543L,
  46764. 0x19b13f3bd136ddcL, 0x05662fa6bbf3f03L, 0x133f4da342d72f9L,
  46765. 0x1c1f009b48bf130L, 0x19cf14ef618d3d3L, 0x0233ab260a1f5bcL },
  46766. { 0x1725904b6fff5d7L, 0x199d7c96e23a946L, 0x15d5b482e2a80dfL,
  46767. 0x028775d873212baL, 0x08a2b9b032235fcL, 0x09ae30d17f5a57bL,
  46768. 0x1d21987140c6253L, 0x1e759256d45d50eL, 0x08eb48b15011bc6L,
  46769. 0x147f09463cf6e59L, 0x06f032974a801a8L, 0x0e645e2b70a13eeL,
  46770. 0x0c7a036218f3167L, 0x07c0f04f7f46b94L, 0x1f143641a3ce72dL,
  46771. 0x03c062ee7e02cf6L, 0x0d50d0f7adbed6aL, 0x04506f70b2774c2L },
  46772. { 0x04991bf47366e6fL, 0x026cff4361802a8L, 0x1d46903338dae02L,
  46773. 0x0c7e32c3c429898L, 0x00445e43bbb46aaL, 0x0f10afab53c2fcaL,
  46774. 0x002376e346d5f24L, 0x118d51c8a7d8fddL, 0x1c0367ef8bbaa1eL,
  46775. 0x086c8f8f1f0c084L, 0x13f439f8828b0ccL, 0x1908aa9984eff2fL,
  46776. 0x1d7b628403f1e80L, 0x1ff050be744dde0L, 0x1c001cddde2a598L,
  46777. 0x17da53d3b633f83L, 0x0232ce7fe7db6f6L, 0x03d825ae9774be7L },
  46778. { 0x1546bc782c5faf8L, 0x1a62f475c084badL, 0x01879de1478069cL,
  46779. 0x07d2adaa3e7aacdL, 0x03c3c37c833a101L, 0x00a476639a8b98eL,
  46780. 0x1bd0581dce3ef83L, 0x0ae5d8de177c377L, 0x00aa2ac6ecfa518L,
  46781. 0x194816bb371d6f8L, 0x154227188b5b8c1L, 0x16474dbb005f9a9L,
  46782. 0x15338863723ae21L, 0x146c0c1172a32d2L, 0x01a5deb61446682L,
  46783. 0x04e589e29a0646fL, 0x11c515b081c9c7bL, 0x00e354ad264cdf1L },
  46784. { 0x0b14ad5c2821363L, 0x00c11a68bef0e53L, 0x0b1332b7a1220a7L,
  46785. 0x1304913c4f5debaL, 0x1081d927f412ab3L, 0x05d68fc964e04c7L,
  46786. 0x07ec5be1ef7d1d7L, 0x0ede955b570343bL, 0x0475a7923b75f3bL,
  46787. 0x0ee856b6dddd47fL, 0x1d85912dc2ad166L, 0x1102697b35e306dL,
  46788. 0x0eba9abda32a464L, 0x132b12fdae48913L, 0x06392f933b21c27L,
  46789. 0x10f39a967233c10L, 0x0c9a5c09c8414f6L, 0x039384501185432L },
  46790. { 0x133c0b1f34a466cL, 0x1704e3fcea2dd27L, 0x1fb838a1e17286eL,
  46791. 0x0d21101103ae1e1L, 0x1b043da3824c714L, 0x037a197120b6155L,
  46792. 0x0f871ccf69c4f3bL, 0x0ca56b20c9392f2L, 0x0db62d5b0b35c93L,
  46793. 0x0af5b711f2e0d95L, 0x02d73aec5ad454dL, 0x10d3ee12d2399fdL,
  46794. 0x1b61a85bd59e081L, 0x1d7081fbe432fcfL, 0x119fa77c5a74f33L,
  46795. 0x0a2272a4b88e6e6L, 0x1217db55c0b4369L, 0x03a48e3a639932eL },
  46796. { 0x12ed5bf80d2b94dL, 0x16319dd25930598L, 0x1633588866846e2L,
  46797. 0x175d70591d590d8L, 0x19ef9ced317ccf6L, 0x15e6ad16fd94f72L,
  46798. 0x0c8076a9f626390L, 0x1b927c52b90b2e9L, 0x069e75784d9fc5aL,
  46799. 0x162384f809551ddL, 0x0a7cdf2174f2e75L, 0x1c4ba7ba957a3fbL,
  46800. 0x010b3ba22ee5487L, 0x03746e5d807ea58L, 0x19a19932d64524fL,
  46801. 0x0d6ed6e653f5779L, 0x0416829d1c26890L, 0x045e7e9f2ba0bb4L },
  46802. { 0x0882734d3c8c314L, 0x0597888c3841983L, 0x1f0f01a2e85a57cL,
  46803. 0x10ef248f0f726feL, 0x1f9922275365e0dL, 0x0ffea78aa93f2f0L,
  46804. 0x18e24281a59209fL, 0x15bab167be45eb0L, 0x183446b896af20eL,
  46805. 0x0ebcb85a83a312bL, 0x034819008a9a442L, 0x115ece3d86f3b3dL,
  46806. 0x09057fe91ed1e5fL, 0x0944820c37aa128L, 0x0e4cab7c5376a05L,
  46807. 0x126f17af0021c3bL, 0x1493e18d1e4905aL, 0x029e56e7bde9bd5L },
  46808. { 0x1b5edf75e53d0ffL, 0x1303644455fb38dL, 0x03e04881b457621L,
  46809. 0x0bc456d466c9236L, 0x1173b317b301834L, 0x04f2cad5d33ca5dL,
  46810. 0x093463079619df7L, 0x0a69c20c904472cL, 0x061752e59da55ddL,
  46811. 0x0c5a755cf2143ceL, 0x19e12d247cafb40L, 0x13a43cf2853d95eL,
  46812. 0x0510f262243dcdbL, 0x1328762e1b4a0a4L, 0x06a5d8041bc642aL,
  46813. 0x0208cea854b5d6dL, 0x0b169bd75e9c32dL, 0x048424cb25fc631L },
  46814. { 0x1390cf65a93c661L, 0x031324edaf82b58L, 0x0a7694685e20612L,
  46815. 0x1ecee5bd3525527L, 0x1c71487c1b0cbb8L, 0x11211f3733ff5ebL,
  46816. 0x10be3e6d0e0b539L, 0x1e52dfb4a1d76b4L, 0x0c921b3376089a4L,
  46817. 0x0e996bdc3af628bL, 0x1b4b2b1040492d2L, 0x04138843f6f57b0L,
  46818. 0x0bf6b7de33f6862L, 0x149e49341f0ca4dL, 0x171330337b863c3L,
  46819. 0x01a45a9db7abc11L, 0x1e8c2b75be47358L, 0x01ebfb7fd23466bL },
  46820. { 0x07b290cdffbd5d1L, 0x0ced34b819c6ff5L, 0x0c2243fbb72675dL,
  46821. 0x0a85b9cd1cacd01L, 0x12ae4d82bc690afL, 0x0cadb0428cef95dL,
  46822. 0x087d1584919fdfcL, 0x066cb346859b078L, 0x055771bf5556516L,
  46823. 0x1e3449aaa45d2b1L, 0x06480e524bc8e97L, 0x11c73938c02f6a8L,
  46824. 0x14511e601956752L, 0x0e8b52aa9f83276L, 0x152afb8c0fe7ae4L,
  46825. 0x09cf87c3189fa44L, 0x0e640994d6ffd43L, 0x047d8969fb6ef3aL },
  46826. { 0x06381a2293cb7a4L, 0x104f85c3dbf26b6L, 0x008c1e2b0fbd14fL,
  46827. 0x00af195d229e425L, 0x116ba4dde89ffadL, 0x1ac0502515b4b53L,
  46828. 0x04c1c51a06853dbL, 0x11226b1f2f6985eL, 0x1878969962932fbL,
  46829. 0x0eec28513452d7bL, 0x1c7db7f88e7e0caL, 0x1a5c9e8e933b5eeL,
  46830. 0x17867ca0e95f20fL, 0x1bacc0f64db21f3L, 0x0ac725f9e163b34L,
  46831. 0x068a77d28d4b233L, 0x1b14f9303a206ffL, 0x01fe63398bae91bL },
  46832. { 0x09debd5df21f920L, 0x1870fe0a00dc828L, 0x0ff656992abfebdL,
  46833. 0x0a586f424448539L, 0x1deb926bf212085L, 0x19f8ee0ea649fa3L,
  46834. 0x0f1184bcf93027eL, 0x1a4ac10b4b2b6a3L, 0x02a2f5d62f10fdbL,
  46835. 0x06eb167ef8659e1L, 0x10928dac3c952d8L, 0x00baac8c256e2a8L,
  46836. 0x0fa1f5249cc3a5aL, 0x1f3150c45f5f186L, 0x10a64e493b1a40dL,
  46837. 0x10d0aebe1f7595eL, 0x034d41345dcb3faL, 0x03228a37ee38a8eL },
  46838. { 0x0ec633aba1924f9L, 0x1789b00319370f6L, 0x1eb1f943f05eee9L,
  46839. 0x13de7b1c00406eaL, 0x11dc5a74ca53191L, 0x0a095c4aa2d3552L,
  46840. 0x14001b887563f4cL, 0x1860378600af763L, 0x0f1789c696ed1a9L,
  46841. 0x17969afcc2c7d24L, 0x1426e6065efa15eL, 0x0eaa53544cba869L,
  46842. 0x07c058fa801dc07L, 0x0a5d0a6765681dfL, 0x01429d24b5c2a7dL,
  46843. 0x0bbb4db8f0a0ad8L, 0x12e2a7ca4a94d00L, 0x022469eb955fdcfL },
  46844. { 0x056f14529b33989L, 0x1a8de54d740ad6eL, 0x184d2c1d10521a0L,
  46845. 0x1479b3e67767e8aL, 0x1ff6e4a3955ce42L, 0x07554889d6f2762L,
  46846. 0x1bf7f4eab1c5694L, 0x01418c3d932accdL, 0x1108a28b8f6a447L,
  46847. 0x0177ac272a42264L, 0x16c58b438bccdd0L, 0x063f68def979704L,
  46848. 0x0c96f2fd893dcd1L, 0x12c9463c1040bc7L, 0x18f11653631759cL,
  46849. 0x0613e50b467bf32L, 0x1a572497175d92aL, 0x03b440a3ce5b80cL },
  46850. { 0x043a11491767eedL, 0x0dcd6c95fb2edddL, 0x13800e978869784L,
  46851. 0x025466a82bd1445L, 0x0a9ead626360442L, 0x195772e162b1da2L,
  46852. 0x1875d2f01899282L, 0x0baeb71aaeb17e5L, 0x11cff0ee7d08a26L,
  46853. 0x1c8a70ed85b8953L, 0x0497412c61a4b45L, 0x1e98ad99d02b86bL,
  46854. 0x1c9fff0e3ade253L, 0x0ed5f68cd23c920L, 0x1eb941942e741bbL,
  46855. 0x1c300ce26a4c0b3L, 0x026f37600fb532cL, 0x03387580e2f2d43L },
  46856. { 0x173c0af73cdbb43L, 0x07662bf9218d6efL, 0x1504a868e1173c2L,
  46857. 0x052449bbe322f00L, 0x1eac7eff69a104fL, 0x16899121a979c6dL,
  46858. 0x0d1dbf0eced39f0L, 0x1e14d3d28616bc9L, 0x07d932340975a46L,
  46859. 0x049c4cf2eb27767L, 0x0849436c8d17a60L, 0x1264fe96f2d6f70L,
  46860. 0x154bb90b1f23552L, 0x08897beb1774e60L, 0x0eab8c87ea723d6L,
  46861. 0x02cd45a1e5f3039L, 0x127b77f03660075L, 0x028242973b1aeffL },
  46862. { 0x10f3ce5a2f392faL, 0x003b57636483c17L, 0x1a4a12eaabd8c9bL,
  46863. 0x0797d1d3275a03bL, 0x0d950908b01b16dL, 0x09d79c38982e121L,
  46864. 0x0a68319bf585ce1L, 0x04eee6a281da788L, 0x18a31b12a1fabf0L,
  46865. 0x029800102c598bbL, 0x1f67f2a71f7ae68L, 0x0d37d0ccfa6157fL,
  46866. 0x08e9a9e13fd05efL, 0x1c8f574e179d398L, 0x0339b10fd326866L,
  46867. 0x1f160a1a19dcec3L, 0x0c4fb24dc405240L, 0x04c97f0a8fbf486L },
  46868. { 0x054db3138f197aaL, 0x16b4ec3c397cc22L, 0x1ec113c2a0a2937L,
  46869. 0x1d463c918d2f684L, 0x1d98efec9821e1aL, 0x0659d771c6584feL,
  46870. 0x155cc82e13ea120L, 0x0d774b769508e8eL, 0x0a9be080acd50e9L,
  46871. 0x0228f4e77881aa8L, 0x1b9d7f1104c9731L, 0x1d30714bc67ac4dL,
  46872. 0x19a2b0abd26eea5L, 0x0db04154b990df5L, 0x0af30ab2a4b9212L,
  46873. 0x173f63b902d1532L, 0x1e0134ecf4b9c8eL, 0x02d345fd4262db8L },
  46874. { 0x0ff3b45ff0a2bfbL, 0x0fffcaa817c585aL, 0x02156c70309b441L,
  46875. 0x161a773a0829bcbL, 0x026d3917ed16865L, 0x0d9e0717ad12298L,
  46876. 0x03cb9a88bd24fd3L, 0x0c290e2a915c483L, 0x06ab363a8509befL,
  46877. 0x0e50f1d5c65ddf6L, 0x03726100468e5a4L, 0x1c141ab94aeee3cL,
  46878. 0x0581897bc1ff982L, 0x042d6af3f5a0582L, 0x0cdedf12f092918L,
  46879. 0x0c51fa2b91f414cL, 0x03956ce6ef7bef1L, 0x03c567efccfaf7aL },
  46880. { 0x1bf7f15f8520189L, 0x1015063bfb0e222L, 0x1ae77e88b86e550L,
  46881. 0x0e3e94690e73db8L, 0x0814cc52d2d6026L, 0x14f891e6c99c94aL,
  46882. 0x0dbdf79da849017L, 0x1c1c460dd415c6dL, 0x053815218b83a58L,
  46883. 0x0315dbb5020918dL, 0x0894f2fcc6f9c66L, 0x06646fbd0c3fd1bL,
  46884. 0x1690ae48902dfc5L, 0x05d53769792e49fL, 0x02d28a59af2e3c2L,
  46885. 0x19292de215c1f21L, 0x1668cb4b48cb061L, 0x0056c96b9e83ad1L },
  46886. { 0x1b95fedc2ca548aL, 0x063104066c4d5dfL, 0x152cd19b0a011deL,
  46887. 0x07a97d12057d322L, 0x13e681edea3be09L, 0x1a00b0c23dbcca8L,
  46888. 0x1ffa3c8aa3d2c0bL, 0x1ec7de5969a95d6L, 0x19adc5151b3aed5L,
  46889. 0x00e67e8cc6188b1L, 0x0b05ee8f5f623fbL, 0x09a68c84212fb85L,
  46890. 0x1794b90bcf08fa6L, 0x05a854f5af5fc05L, 0x06a99ac6de2d2e8L,
  46891. 0x079da349fd2684fL, 0x1ae8ef4dcaf075bL, 0x04addec50385374L },
  46892. { 0x1f92495e614bbd0L, 0x1d443dc11f1b1acL, 0x07b3f06f5a9dd59L,
  46893. 0x0f1d06b885c48f9L, 0x0ade066a2bfaaf4L, 0x0b699b18a77a705L,
  46894. 0x18e241caea98d70L, 0x01ff48538e3c5e1L, 0x0cac1e5d0bd07d9L,
  46895. 0x0ff9af528a7ae02L, 0x014ff301553b05aL, 0x0d6e546b28ff126L,
  46896. 0x002aebe487ab1d8L, 0x0fdce790f14fd83L, 0x037f3d6828435b7L,
  46897. 0x0f4555a28e0b3e4L, 0x119480dc66fb886L, 0x01bad4427e092d4L },
  46898. { 0x18cbe2e1217f7eaL, 0x10f1543ae36d58bL, 0x1b006f6c6950685L,
  46899. 0x01c9fae795eee0fL, 0x113a0d86678864aL, 0x0983345d75e3326L,
  46900. 0x1654100c97e6723L, 0x0cf727db3925e38L, 0x1fdf36763541e06L,
  46901. 0x0cbfdd85c8d33b1L, 0x09a7a981e72683fL, 0x19003d55188e4d5L,
  46902. 0x01afa63c55c7303L, 0x07e8956def63ae4L, 0x1a20e2807373789L,
  46903. 0x0a6f33fc1bb4e32L, 0x0ec66bb093b3841L, 0x01346c0c58465c2L },
  46904. { 0x1dae35841580555L, 0x19733a39e881db9L, 0x004efb3306ad3f0L,
  46905. 0x05649dd3bc48182L, 0x1fa8e066da4099fL, 0x1c6bf71bd865adcL,
  46906. 0x00502d6b8139190L, 0x0f0fefa62c856e4L, 0x186ef4edb339e4aL,
  46907. 0x0f3bf769d3ec1baL, 0x1eb4def5c1f0ba9L, 0x06741f2f2313107L,
  46908. 0x0a2e7a208e816b6L, 0x021aa8b57126014L, 0x17cafd445c7f8f1L,
  46909. 0x074ac7d7276669eL, 0x04b8419ed4b01b5L, 0x0458139ae02b652L },
  46910. { 0x09bb464e1019195L, 0x0601379fe1460dcL, 0x19b8aff0ec84779L,
  46911. 0x15237bf25f58241L, 0x0d995bc9ec71bc5L, 0x048fff242ebd5a0L,
  46912. 0x189965f19da3b99L, 0x185b2aa5a335f79L, 0x1bae6c7fe8e1b76L,
  46913. 0x13ec140ebf1d68dL, 0x126be57a625cd05L, 0x0499141903047c2L,
  46914. 0x1bc3006c0dd1f00L, 0x0c3b9ea67ab8ffeL, 0x0d50362ccbb3df9L,
  46915. 0x0a084b0454f05faL, 0x1fe5ab45c3f0436L, 0x020071d5025a6c2L },
  46916. { 0x13216495e46e4a2L, 0x176b21209b03a23L, 0x0ec7183b1df4de8L,
  46917. 0x07cbc1585ccb244L, 0x05107ab75e13aacL, 0x0129eded0be20deL,
  46918. 0x08a5996c8bb25cfL, 0x137fe70cf714a02L, 0x1fed660d50621a9L,
  46919. 0x1e14283644fe1faL, 0x0d42e7c591469e8L, 0x0064cf96b0de7daL,
  46920. 0x19967185b127c3eL, 0x0509804de403e3bL, 0x0bc7d3427055f51L,
  46921. 0x143306c5eec8f5bL, 0x0394a42b9acf3a6L, 0x0098e1ed146d370L },
  46922. { 0x0785ff1a7da83baL, 0x0da12e827a21b25L, 0x06f7b00fe04bd05L,
  46923. 0x1501ebe944f8113L, 0x1da251b9c58d411L, 0x1d97991e996b087L,
  46924. 0x020f266ed141334L, 0x1fa33188897e984L, 0x060c261af730e83L,
  46925. 0x106526fe5816dc8L, 0x1e0e2e77c79f201L, 0x1f2f898d21921feL,
  46926. 0x175d75f1546b79cL, 0x0e58747f898a8a6L, 0x105d8569f01d3c4L,
  46927. 0x01fe17241558365L, 0x0e9de8098ad44aaL, 0x038e8d2351a2a2eL },
  46928. { 0x0178f76fa1b382eL, 0x07661bb96ed06bbL, 0x0cab175344c2836L,
  46929. 0x091ae4c45954b55L, 0x0a3bed0627d38baL, 0x1e7667e2a086db6L,
  46930. 0x18f5fd8de9621e4L, 0x0823ecbb5fadccbL, 0x1c3b44a8560a456L,
  46931. 0x1a3d9d427bc2a05L, 0x1f6b75793583d83L, 0x12182fa76dab049L,
  46932. 0x1f325fc13ad8ccfL, 0x1b247d5c804755eL, 0x114b52cfa435c58L,
  46933. 0x0159672c9fe7449L, 0x121b95cc416533dL, 0x0366934cf88b3faL },
  46934. { 0x18c0b3b12f4f3acL, 0x0e7f14ce8defd96L, 0x13e0c3cdcc9ac0fL,
  46935. 0x06f8b51904a8006L, 0x0d8f144222dd689L, 0x0ba17975b849e86L,
  46936. 0x16b76249e569d61L, 0x0bdc2be505810f5L, 0x07bbdc74916ab7bL,
  46937. 0x187f205d2c565daL, 0x105faf8aeb0e6f4L, 0x134d8c3409781bcL,
  46938. 0x0df27355694b4b1L, 0x18558cb7c99c61aL, 0x0232597a3c0dd08L,
  46939. 0x1704df45df970d9L, 0x1c219eee274c7eeL, 0x0193e031fed1a2eL },
  46940. { 0x1399eff5b47cd53L, 0x0c34e8ca1d77f55L, 0x11ec500aa19aefaL,
  46941. 0x156384b42dcc9d9L, 0x022de271c3e7c2aL, 0x16b52fe210b5bc8L,
  46942. 0x0ccdb9637f320d9L, 0x0f9a2b2a13db502L, 0x0370400f2130bfbL,
  46943. 0x1f2702cc9da43c0L, 0x0e87f8e7cf34886L, 0x0565dd969f0e0c4L,
  46944. 0x166c27b83b72aa2L, 0x0d2fd2df8d7a624L, 0x0c06bc9e90aa52fL,
  46945. 0x0225935f7504491L, 0x056eb6b9d2a3670L, 0x001078ce8e06fb4L },
  46946. { 0x1051a86a4dbba20L, 0x075e36d8ef2e29bL, 0x086799496102d86L,
  46947. 0x1ba579989b34f01L, 0x10285a249440302L, 0x04313474ff811e8L,
  46948. 0x0451cee4dfb8ce9L, 0x19fc6fdc5e499acL, 0x079fbbfd3a3d057L,
  46949. 0x1dd0b69e66ef7e7L, 0x0163b16c8c5c9d7L, 0x1d7ce41875b722cL,
  46950. 0x068b4f6bba47699L, 0x18c503b81313a1cL, 0x128458152c024abL,
  46951. 0x11ec133a121d759L, 0x144f757e1ff0c88L, 0x03cf39390580282L },
  46952. { 0x12acf252820a239L, 0x1cba75573598831L, 0x1ae92302877ec68L,
  46953. 0x12b47dcf55ac3faL, 0x1980446dd2453c3L, 0x0b33b7aa422ad05L,
  46954. 0x1d6867ca765ef78L, 0x10be4a59418f126L, 0x1e961af3e7743a9L,
  46955. 0x063ce2b3366dec6L, 0x0e153b2f14e3e5cL, 0x0e75424d0a38294L,
  46956. 0x052a9f558c58daaL, 0x1de8af02f4daddaL, 0x0864e74debdfe0fL,
  46957. 0x140ad4890f24e71L, 0x06de428b2b59511L, 0x0000e9e71b80ac2L },
  46958. { 0x0be36b9e145b1d7L, 0x1c9c5004e2b326bL, 0x19f79f03db6fcf8L,
  46959. 0x0d8687ea725cac5L, 0x190897b1951044eL, 0x17bcbe52d5b15c6L,
  46960. 0x0a392c687dc2d44L, 0x0bb239baea8ea1eL, 0x1b4c80e2fffb816L,
  46961. 0x0f69ce3aca68159L, 0x0a92755a0cfb719L, 0x0979e6d27431982L,
  46962. 0x0afcd2c404e7369L, 0x08ea00ca1a6609aL, 0x16179181c6f57f0L,
  46963. 0x0f4080aeb208ff8L, 0x084b3280360790bL, 0x025dc637e2057e3L },
  46964. { 0x120e2ddfd0f8796L, 0x05206d899e4ef18L, 0x1b02a4da71b9a5aL,
  46965. 0x0cc00e4e77fd46cL, 0x0cb8143937e5b6dL, 0x15e0029cf276784L,
  46966. 0x0d4f121ffa7367fL, 0x1d7d715e8880333L, 0x02f124e3b293519L,
  46967. 0x10610c564164e0bL, 0x075bc9c27716421L, 0x0a8a6daa0a5359aL,
  46968. 0x1959120bfc5696dL, 0x087fd348601faefL, 0x10ca09e668fa234L,
  46969. 0x0bb13a9f39f4ad8L, 0x0782e8fea9e9a13L, 0x01b4cd440db53bfL },
  46970. { 0x1ca33721eb1c64dL, 0x19d16f8e940aa2dL, 0x06cd94dc41bfa73L,
  46971. 0x029ef97e9b6fc5dL, 0x0058b37f06c1715L, 0x1a74e2e5ef20b71L,
  46972. 0x0e9d60b14e9fa20L, 0x00529b7bfc5d358L, 0x1795ec6cbc5e67cL,
  46973. 0x011e12f8a135406L, 0x134835aa353e7e3L, 0x14a9a76f846bdc5L,
  46974. 0x003d7a4d52838daL, 0x1c0e5a39dcf0476L, 0x10c72ab2a51d7a5L,
  46975. 0x0a30ee4e3e73cbdL, 0x18b1df08e9f8253L, 0x0279d258190457fL },
  46976. { 0x17b81071ed095f8L, 0x1bfd36d1136a707L, 0x014abecdb4748f8L,
  46977. 0x1c0fb1c623161f3L, 0x03e0f16eb114634L, 0x0f761bdcb1a54bfL,
  46978. 0x087049152ee7108L, 0x0f969d9abb7ae56L, 0x0f96038686df20dL,
  46979. 0x1a9acfeefc37051L, 0x1553e96b1222aa7L, 0x0957a2093be9887L,
  46980. 0x1eb020607a56d71L, 0x1d01192f098a959L, 0x0ba136d26f87061L,
  46981. 0x0f70089e49e94a5L, 0x1fd9e525c030b5aL, 0x036c3a2235368bcL },
  46982. { 0x09d07aabe9a42f5L, 0x098b61bc0e66469L, 0x09b6771a7a847f5L,
  46983. 0x1f11fdd234e34ebL, 0x18d44f124e19e0dL, 0x174a724ce15a6e7L,
  46984. 0x1330817db7e48c6L, 0x1d64ff750ed9e51L, 0x06e1a0f01f57f7cL,
  46985. 0x01f8f9a79fe9dbaL, 0x17129d0b07484f8L, 0x04e0fbd70b0141dL,
  46986. 0x1faf0848bc5caacL, 0x03d63ace87aebc8L, 0x13f14c45fd452b4L,
  46987. 0x01e7b2b472e6920L, 0x00995a4aca97bb7L, 0x01e79c264ffce2bL },
  46988. { 0x00506bace1fc9e3L, 0x10ba133b581ccb8L, 0x0e379cafdecd25cL,
  46989. 0x10f36413ee56943L, 0x0e26a8e1ca8602aL, 0x1279cd482c05c86L,
  46990. 0x18b847bcce6dff8L, 0x1e96d8bb322c526L, 0x151174e1a577b24L,
  46991. 0x1c07e5a82f228f4L, 0x05ebec520c86f7cL, 0x0d76e8fcba55e9bL,
  46992. 0x05be99a60809980L, 0x0a2af41042a92ebL, 0x15829949920a367L,
  46993. 0x00ee11918a80bb0L, 0x1263c67e73c7103L, 0x0159244287739efL },
  46994. { 0x173cde68541159fL, 0x1260c27da085910L, 0x18647cb2871de08L,
  46995. 0x0d51647c800f450L, 0x06b2344a52c207dL, 0x1694a2838d01085L,
  46996. 0x131b36c3961f2d7L, 0x172d8ad71df021fL, 0x11248c58f62d843L,
  46997. 0x1c81b1eba6334baL, 0x03dfcb99b19bd92L, 0x0883824d797cc69L,
  46998. 0x0373ce49e8b2f9dL, 0x140d86f85603f95L, 0x118874549219d63L,
  46999. 0x0943942116a9a3aL, 0x01517261ece7441L, 0x049c59de6351d61L },
  47000. { 0x1e4a16be4ded340L, 0x0fd954074401b54L, 0x181b735ceb2e399L,
  47001. 0x09554caf532e112L, 0x09101b061c3a043L, 0x05db2679827e2c2L,
  47002. 0x0b7d7983ed86b68L, 0x0bf031855d9eaa8L, 0x17402057656f76dL,
  47003. 0x0b35bc849299ecbL, 0x195795d35bad7edL, 0x036b4ab6896f5c8L,
  47004. 0x1b93747ea560f7aL, 0x196d672b3cb80bcL, 0x1a0f01a2b9f83a3L,
  47005. 0x0e683308e8c0f09L, 0x16b24e8c9ed1530L, 0x0367fac52ecf44eL },
  47006. { 0x08c01b003e51f68L, 0x0f9128e97f3eb28L, 0x142c26f62017874L,
  47007. 0x1407c82b6fef331L, 0x007d9798255e907L, 0x029c4b68a4233ebL,
  47008. 0x143d01570ec7a6dL, 0x1b86a002027013eL, 0x0fbbb2fa6d0233fL,
  47009. 0x1b405857f8c105cL, 0x101370e34c5f802L, 0x088999918fbf63aL,
  47010. 0x066ec13f84133d5L, 0x023717243fd423fL, 0x18eceb30cfe0f60L,
  47011. 0x0d5ee78c4ff8a90L, 0x1275f67f8aaeb93L, 0x02ff2564798dbc9L },
  47012. { 0x01aa4bf8b6f401eL, 0x18951d6ae3f6a2cL, 0x1c99bec1ed28176L,
  47013. 0x09384579a8f6030L, 0x09371c95fdd11f0L, 0x123757aa2a53ea3L,
  47014. 0x05b4019b157ee66L, 0x0b830c6f8f8ffdfL, 0x0bafc1d346b83e9L,
  47015. 0x0e1c2c9805da16eL, 0x17b0acd39f9c495L, 0x1f6163099dd1bb1L,
  47016. 0x0249a2786469c9cL, 0x10087973c6e6062L, 0x1de9080a43657c8L,
  47017. 0x17b5b0dc4a992d2L, 0x14820931c89eb2aL, 0x0409bb8b2090e02L },
  47018. { 0x066b25e9c5a8edfL, 0x1c461083c53d6b1L, 0x0df521dbbb7db84L,
  47019. 0x12c4e88c2ebe04eL, 0x1385382a242fa7fL, 0x1b8df79f167decdL,
  47020. 0x02a4aeb6b5ec40bL, 0x068ac5579f4cefaL, 0x0573ebd1751fdffL,
  47021. 0x1fb2c293e12863cL, 0x1c5bbb11f2a25b5L, 0x1360cec4593dc19L,
  47022. 0x02f8f2c0758ccd7L, 0x1300428a98fe2c4L, 0x1a316ea48cacdfaL,
  47023. 0x08dfc9af766c305L, 0x198bf24735cd2f1L, 0x03ce140774e696dL },
  47024. { 0x1cc8203f2b48122L, 0x0248b582562475eL, 0x13727f12217aa30L,
  47025. 0x0f0582003959e0cL, 0x076de250ab83899L, 0x0d5c10399cf390bL,
  47026. 0x12cb85ea96baa38L, 0x06049a51940d782L, 0x0570c5bb7816b62L,
  47027. 0x02891ae67735b03L, 0x0fe27c60fab909bL, 0x078d38cc4e96365L,
  47028. 0x06b51e38bc3e3afL, 0x19f2071df058221L, 0x0f96f909b6f1639L,
  47029. 0x1e8107f3baaf16bL, 0x14f9fd9f79152c8L, 0x03ac039d254f1ffL },
  47030. { 0x127b0578691ca22L, 0x15feb09d150db3eL, 0x0e16b1e5504fc81L,
  47031. 0x14eaa6cc0fd097aL, 0x08a0e24cc5d18a2L, 0x03a6de970b36f3eL,
  47032. 0x010e95b55d430f1L, 0x065bde8898226cdL, 0x114646e53cf4b84L,
  47033. 0x1e0681854fecbc1L, 0x132090a5fb880d2L, 0x017ffaf7cd8f7b4L,
  47034. 0x1608c7f3ff3d0b1L, 0x1a7ea6229690b23L, 0x1a784101b949666L,
  47035. 0x1a65bf7573f4293L, 0x0a89342a7fa8661L, 0x01f9f1a2c7d7b35L },
  47036. { 0x1ec35af951597aaL, 0x1ea5624efb275a8L, 0x16726fd3bfd6d9dL,
  47037. 0x12a2b4526a04ed9L, 0x1d9bb9c3423eca4L, 0x10f84e4534b2a9fL,
  47038. 0x17e63e67ba77fb7L, 0x06571f452ac333cL, 0x1b763875835292cL,
  47039. 0x19a76ee7e20740dL, 0x157a7d9515f6561L, 0x047c618f1a57b05L,
  47040. 0x0cc1433d67c8ee3L, 0x1e418a5773bd972L, 0x038bd8d5b67e01cL,
  47041. 0x052bc883ddbc454L, 0x0ef1e9e17ed6c48L, 0x0320690621a614aL },
  47042. { 0x09a0b8e3284d513L, 0x01aa2f98a829d27L, 0x101d16b354a81d3L,
  47043. 0x183bca1b6f66dceL, 0x0549fc46d80bdcfL, 0x1f83d446cea3ee1L,
  47044. 0x15308a6dbbc4cc0L, 0x0e69c8c3594da95L, 0x1ca8e351dfc9f1bL,
  47045. 0x1e204a6aba30732L, 0x00accc3ccb4d9e2L, 0x096c50ae85d16c6L,
  47046. 0x11876c29c369a07L, 0x0895e8bd6ff2958L, 0x06a98e7ce791826L,
  47047. 0x00b831dc81acc69L, 0x016b968902ac72eL, 0x007ce0e54606c94L },
  47048. { 0x0bbaab367433df3L, 0x129a38ae9b1460fL, 0x03625fc31732daaL,
  47049. 0x16cbc811f227464L, 0x1537345172c918cL, 0x06e504a5b1c42a6L,
  47050. 0x04c99cc4e668c2dL, 0x1119e4ace601476L, 0x15ea60dfa6608b3L,
  47051. 0x056ba583d9486feL, 0x009e275da53e6d6L, 0x1b716cc61f63064L,
  47052. 0x10c65e3eaf48593L, 0x1f3931fc1eda3fbL, 0x19bfccd8e527244L,
  47053. 0x1048137359d8dcdL, 0x0c534bd9ba7098aL, 0x03f18e097a2e9b7L },
  47054. { 0x0281d680dfd2dd7L, 0x165801255b0ec5fL, 0x017e510c7e5c7beL,
  47055. 0x152b39677973860L, 0x0ffbb406660c8dfL, 0x14d086feeafe186L,
  47056. 0x1f46de918c6f9e5L, 0x0ec66dc613dbc27L, 0x176b3bfadfc9470L,
  47057. 0x148c92eee639111L, 0x1c35cc55b13b87eL, 0x1c821c566e8ee83L,
  47058. 0x13efc4d93c4f64eL, 0x1e27dd97435f496L, 0x1f286ef14edf80fL,
  47059. 0x174c15832d9ea66L, 0x1574de41a307e23L, 0x00d10ce229936a9L },
  47060. { 0x1cf7ef8aa4db0bcL, 0x18c033db64cb1feL, 0x019cf62864bcb88L,
  47061. 0x05ffb8eee384c72L, 0x02fc0edbc0cec2eL, 0x063021ccbe471adL,
  47062. 0x00481e3843b060bL, 0x11dfa1bc5965619L, 0x14d6c457f69e57fL,
  47063. 0x09f34d92da9f8e1L, 0x08cc2b13e272e25L, 0x06532aacd7cc845L,
  47064. 0x0d437442d192ff2L, 0x1f534a01b9e6a81L, 0x00c198bc1339642L,
  47065. 0x17f26d582a6fdf0L, 0x12fe02bcf77b6d0L, 0x00bd554ccde480cL },
  47066. { 0x13d56438e55db2eL, 0x0f7219dca342886L, 0x03956e2118be0d7L,
  47067. 0x0bd42fc4f834288L, 0x1d95f7a9a6ff3b3L, 0x0b396791fcce1b6L,
  47068. 0x11701c85ff766f7L, 0x04be801583dba40L, 0x094b55c874ff06bL,
  47069. 0x1225072872524dfL, 0x097a46d0eda04c2L, 0x1bc2429f2d8bd12L,
  47070. 0x0c0f97fa9778bedL, 0x12dfe93387a2b52L, 0x1d823be8a3f61aeL,
  47071. 0x0e97876965b1f7cL, 0x04afbd5ff8c2264L, 0x03594157852f9d9L },
  47072. { 0x0fc025f6341a595L, 0x01c6b5222f1463cL, 0x18f7ad11a109647L,
  47073. 0x06eaa8f066e57adL, 0x083e16c43f9466dL, 0x13d65a488a0a698L,
  47074. 0x1ed905176519a56L, 0x162205bbe131fa5L, 0x02a2b2d2d0bfd87L,
  47075. 0x0f4df2e2ca2a844L, 0x1e2fd2a0091779aL, 0x1ad16460d61ddc6L,
  47076. 0x06c2be9f3d80b0bL, 0x04016122bb52a2eL, 0x104b7ed0a7459edL,
  47077. 0x12ec427cc884e56L, 0x0bfb664f529ee8dL, 0x036a7ae91aa3837L },
  47078. { 0x1c8f2b600ba9f88L, 0x003f03ddb685f9aL, 0x150acee0796ff72L,
  47079. 0x1d4f58f03c1424dL, 0x137dcba6335ce6cL, 0x04b2439f184737fL,
  47080. 0x10d340a3729898fL, 0x04ce5d74afd1030L, 0x1a9e3d59f79b78aL,
  47081. 0x17853ee9783d751L, 0x1919e093417dd34L, 0x02e0022dbd6dc1fL,
  47082. 0x1258f37580b2085L, 0x1a0385d9ce152f4L, 0x05df6439e2f5e95L,
  47083. 0x10368aa3f90e573L, 0x0ad6eda93c440dbL, 0x0255785a7eb2e9aL },
  47084. { 0x1ef25063514c7afL, 0x13ed6de0c0f56cdL, 0x1a1e3e8fb162c27L,
  47085. 0x0a2e770d0bde795L, 0x121d32ddd8dbfabL, 0x0ce233592487e04L,
  47086. 0x16f6d3bbce1ae2fL, 0x1b7839baa5f40c3L, 0x064de989a25bc04L,
  47087. 0x17cc1b5c2b9431bL, 0x16a0122f912a801L, 0x1c9c12e0318e234L,
  47088. 0x17b2c11fb116dedL, 0x1390f66cb95762bL, 0x1afcea45136b786L,
  47089. 0x029aff338a4d7adL, 0x137a1d4165b1c2eL, 0x045965e9cc15e31L },
  47090. { 0x0ec1bf28a52e991L, 0x1017b67cea17614L, 0x04c318d3a9142e8L,
  47091. 0x078aec5739060faL, 0x087c2a2d3fc257bL, 0x0ca4455e994c68aL,
  47092. 0x01b4b2853c69e8cL, 0x1138e1952760d74L, 0x19aa3f4b3ee405eL,
  47093. 0x03277599aef7573L, 0x17d5e00efc75333L, 0x016a8ac2d7fba2aL,
  47094. 0x06086e33f6041ecL, 0x18121e7a91efc07L, 0x1333560e669e723L,
  47095. 0x190630d85049d0eL, 0x070220eeaec8fc5L, 0x02bf141823edf1bL },
  47096. { 0x060b698fbcdf666L, 0x0354cc5f5d8e937L, 0x16ea012610daf74L,
  47097. 0x1ca457911a80895L, 0x08423b20d76bf75L, 0x1cc53932ae25cd9L,
  47098. 0x1d8059703d2494cL, 0x0b4eda9e56e1946L, 0x1469899252030faL,
  47099. 0x159bf43db02a382L, 0x1bdcc54f786cbe5L, 0x19195aa9de0bdf2L,
  47100. 0x0aa93617b05ecbbL, 0x1e5d10bef5944e8L, 0x1528b5ceb03ef55L,
  47101. 0x0c0c7a1a796ac33L, 0x1a6e8bee9d4c91dL, 0x02789701bb4b7feL },
  47102. { 0x0cfa42215f1a610L, 0x12e2a9bc328cd26L, 0x1151ce0e04d2012L,
  47103. 0x0896509c54248d4L, 0x146d1320fa15b48L, 0x14507d1b2326328L,
  47104. 0x0013bedaea231c2L, 0x0d4e9cf9dcf2789L, 0x18c34d22cb95ae1L,
  47105. 0x0cf6c4ffce0ea6eL, 0x0219b4c8094dc67L, 0x056537ac8894c34L,
  47106. 0x0cf277bab145b23L, 0x14a245817c44749L, 0x1487b2dcf9a71baL,
  47107. 0x15f643492dd52b6L, 0x191a8f78ea75858L, 0x041e9199f589337L },
  47108. { 0x063328867b478d7L, 0x10d70a8517e4e0eL, 0x0cc06348906e87bL,
  47109. 0x111279ad2c0b6d5L, 0x08117a8769f1f28L, 0x139ebb8aceb3305L,
  47110. 0x17c2ba0480465c3L, 0x164a51fde0127eaL, 0x1b3978db8d854dfL,
  47111. 0x15a1f7b7a2ecfddL, 0x192ffb56fb8e5f5L, 0x1eb2d7eedb5a2fbL,
  47112. 0x0e3d40754ca01e0L, 0x1c7437799459140L, 0x147961a3b6d848bL,
  47113. 0x14ab7044d6d5f6fL, 0x021463532152f40L, 0x039b1789f62d18bL },
  47114. { 0x12eb27c73c0c430L, 0x0532fd28e1b2bbcL, 0x1b3b48653c6e330L,
  47115. 0x110296928ea14b9L, 0x0b6fbbf41894568L, 0x1543045df8540d2L,
  47116. 0x1e578ddbd3d63c2L, 0x1abb26c3ad0730eL, 0x1b6510cd8e3a8d0L,
  47117. 0x1f17edfdb60d22aL, 0x04553abb2247e58L, 0x0e2bfead1ec8592L,
  47118. 0x172f2b399e0eb1eL, 0x04f85f85f3d7ce6L, 0x060da547f0e6eb2L,
  47119. 0x04151e10c3b2521L, 0x0add9b16f02da0aL, 0x01788349fd1c607L },
  47120. { 0x1a6ce910c06ded2L, 0x0421797ec843d83L, 0x1f5aa7d8d69be5dL,
  47121. 0x023dac0c4dc8d17L, 0x169ee54804b6189L, 0x0b51008fd97c4f9L,
  47122. 0x0ceb272f4444f72L, 0x13cceb359fc21acL, 0x164ba66fc8faa62L,
  47123. 0x1435724a3f9c141L, 0x10e81756736a669L, 0x162811d45edd051L,
  47124. 0x04af3953c87c7afL, 0x0ed54f2792a8e47L, 0x1bc65016d4f49e6L,
  47125. 0x0f9b63dfed1a95aL, 0x0432775dbdd9643L, 0x04c2fc1f227f3d0L },
  47126. { 0x1603c16eaf45294L, 0x188b06125aba8c4L, 0x0060e75ad4b5c04L,
  47127. 0x05db28668098224L, 0x14f41b687079cf0L, 0x0560f0862d8145bL,
  47128. 0x13c38f70fc1da72L, 0x044b58bdd47f164L, 0x0ee6684bae34c5cL,
  47129. 0x092cf31cd5e2295L, 0x14b347a77d17329L, 0x1926348879f560fL,
  47130. 0x0992c003b307019L, 0x06c65e17347eed5L, 0x1e0729cb67c5e70L,
  47131. 0x18f3377e2b4de3cL, 0x0f154d779d550dcL, 0x0064472a007f4b1L },
  47132. { 0x0f71a6ae8f44357L, 0x1a5fb1d1e55b542L, 0x16796baf1a03dd6L,
  47133. 0x0914ea7de466993L, 0x075e3c8ececaf08L, 0x07c69d71400a608L,
  47134. 0x0cabaee7568e3ddL, 0x124eb3108c9701cL, 0x17b328e6ff2bc37L,
  47135. 0x1dd8fd7f76870cbL, 0x1ab25568cc196baL, 0x1b1f245b79d0ce9L,
  47136. 0x05987b907a8c19fL, 0x1d9d166bc60bd74L, 0x01ddcbe27ccd89cL,
  47137. 0x19dadd75d4033f5L, 0x1154e5de4993a25L, 0x04712b05c578883L },
  47138. { 0x0d3746c3141aba6L, 0x083cfdd5967cf2bL, 0x00c673749f1d168L,
  47139. 0x053bfb2a1d6c705L, 0x1a9408ff2223763L, 0x0b008c0f058ae69L,
  47140. 0x0ee9d26a00802c4L, 0x1aa4e33b6bb4707L, 0x16078340a651046L,
  47141. 0x094ea6f4ba91d8fL, 0x00d1723828a2ae2L, 0x158415be138e808L,
  47142. 0x052331d61161275L, 0x09c8e5285a0d593L, 0x0488c548c331df1L,
  47143. 0x13453117c19251fL, 0x0e5fef3d92b92fdL, 0x02c802f91419279L },
  47144. { 0x1b1750c3c4c1c74L, 0x1d56074b37dbcb5L, 0x16499b165cfef9cL,
  47145. 0x04750cad6d0b4ebL, 0x10446cde8c97f93L, 0x19c4bf95b821d8aL,
  47146. 0x1cac952245bdcffL, 0x1cd227ba0396316L, 0x0d0a751f1488c0dL,
  47147. 0x08bab8a42ac652cL, 0x050c0512998f686L, 0x015961c10c312eeL,
  47148. 0x0cf39ead9c2df19L, 0x0b9c16d080407e0L, 0x18a8ce00216b1b8L,
  47149. 0x15d1bd2f230a264L, 0x16ee4495936b43bL, 0x02bd3c7136bc1efL },
  47150. { 0x01b346f40dbddd8L, 0x0d493ca0861d60bL, 0x1e0c621b3cecad2L,
  47151. 0x0467727bd718a84L, 0x00df579d72df323L, 0x077a804e46acfaaL,
  47152. 0x0190f975e99f708L, 0x18788d67230cfe1L, 0x0ecfa2445ad96adL,
  47153. 0x0c7ac4d8622a268L, 0x124c0782105f5d9L, 0x1ed588a9c511cddL,
  47154. 0x0fac0f462d6ca5eL, 0x046c501b20c8824L, 0x14d6dfa14901f60L,
  47155. 0x1b50f698a674fedL, 0x0e83251e4128f6aL, 0x00e51b862c0e239L },
  47156. { 0x0bd5171a801b68aL, 0x143ce7e8ccc59caL, 0x0afd0458c809cc4L,
  47157. 0x09eb603fb6920b5L, 0x1cda128bb5fe87fL, 0x1e98fbbc6f291d4L,
  47158. 0x130d42fc586871eL, 0x05b6bbd9fa04720L, 0x0224b2882e188f1L,
  47159. 0x0e9400efcced73aL, 0x119ed4233473483L, 0x187b810cfc7395aL,
  47160. 0x002b4250726c311L, 0x177ec801b8d08b9L, 0x0f4ec0e0efd1938L,
  47161. 0x0b754a7a089143bL, 0x07932db52f4e626L, 0x012c259a62619d6L },
  47162. { 0x0b863892aeec688L, 0x1a05d22fdf2919eL, 0x07dff582d7e2979L,
  47163. 0x1890e9227a845ceL, 0x1a17d80d455d185L, 0x02a29202615d9b7L,
  47164. 0x0995cfc9c6152b0L, 0x190edba608b5173L, 0x02e42c3e162ee7cL,
  47165. 0x013338326fb63e8L, 0x1f754771f2d2200L, 0x157c30f12fc0b24L,
  47166. 0x0ef2d5737c6b3faL, 0x1fa8d4ffff35691L, 0x001eeaabed809a7L,
  47167. 0x14935c3906a8ad3L, 0x085acddb6ff951cL, 0x03f4089ba1fcd58L },
  47168. { 0x1722a8b830a88b1L, 0x0c75467088bf0d6L, 0x02e01026d1f6464L,
  47169. 0x06d88da3a67c05aL, 0x0589669cb53812dL, 0x1866af17e84ed87L,
  47170. 0x1114e6117341856L, 0x19618382ab4470dL, 0x1da774de5f5ff43L,
  47171. 0x183b5cc71c8e066L, 0x1c7bfd4013ca1aeL, 0x08d95dd817fd2faL,
  47172. 0x0732a1ad9423e0bL, 0x1cb6d2117229c33L, 0x16caffbf8327e04L,
  47173. 0x1f522c6ed8344c7L, 0x1a6001c7918ba56L, 0x021b5c6326fc242L },
  47174. { 0x0117e9d8ab764bcL, 0x10f4a503befc244L, 0x174c3063baf77e9L,
  47175. 0x1ff928a3b8b4eecL, 0x071a347a548916aL, 0x1da0ef80d297198L,
  47176. 0x10a198cee577ac8L, 0x0d1bafad1928791L, 0x1e4f9d41e18d970L,
  47177. 0x0c845c846493cceL, 0x10523b51ce528deL, 0x0a2f9aa3ca7fcc2L,
  47178. 0x1e0243dcb6e5018L, 0x0bcaa202a83003aL, 0x1f697ff97737988L,
  47179. 0x196ccdef921c2a6L, 0x1e11df7aae40768L, 0x02933654f36df4aL },
  47180. { 0x0ddee6d1386b3dbL, 0x057ad3e1c72a042L, 0x1103ac13d277e79L,
  47181. 0x11fbcb49fb66830L, 0x10257cfc2138a1eL, 0x1eb8609f3734921L,
  47182. 0x07fc0d4671b8c67L, 0x1d11e69c2e90d86L, 0x0f1e298fd940ce1L,
  47183. 0x1dc658e8a4b06beL, 0x104d1cacbceffdbL, 0x016828ddf1fe40fL,
  47184. 0x0b7bd3e220899a2L, 0x1135f513bef61b1L, 0x0d32d9ea5d41139L,
  47185. 0x0e0741e6568929fL, 0x02bc17a09201fc6L, 0x020f992dcce6c25L },
  47186. { 0x12ed513ce2843a4L, 0x024c70039457e18L, 0x0089361933979d2L,
  47187. 0x094c40107751de5L, 0x0bed338d3406470L, 0x1f3d9c2c82f0ecaL,
  47188. 0x1eee4a95e32d418L, 0x083304edb2c513cL, 0x0dfe2dc47f17b73L,
  47189. 0x091a90f8ed644a2L, 0x1b4a348d002a9d6L, 0x00bd4ec374867b6L,
  47190. 0x0d9bfd07ddc6477L, 0x1216547ec4a3dd3L, 0x030d1a003cb8eb0L,
  47191. 0x031fa93de8ce1d7L, 0x09e7db3d37bd9aaL, 0x02b5987db72c675L },
  47192. { 0x1ecdcaacd80a428L, 0x0916e4399644883L, 0x1e60eb69107debeL,
  47193. 0x092496011441b10L, 0x12e81c3a3bed9a4L, 0x1c03e99091a99e5L,
  47194. 0x0bb2f0d3901d597L, 0x11a17f5df4a3e5fL, 0x178b634a5ade8a8L,
  47195. 0x0705bfc4a1c9548L, 0x088dde42ec73631L, 0x09f5f0e4095c612L,
  47196. 0x1585d3cd83dea9bL, 0x03291d3c9f6fc0fL, 0x10365a563e23147L,
  47197. 0x0fe0fc8e5f7162fL, 0x146899081e5dccfL, 0x009a9e62bac5ee8L },
  47198. { 0x0a5649739bf6e18L, 0x05ad1324dc4e394L, 0x128373a2e39d67aL,
  47199. 0x02408e08191b286L, 0x0a7b8e82d935bf5L, 0x1c094a1559d0b23L,
  47200. 0x1ca5fc560fb589fL, 0x057082d4fc0e5acL, 0x149685d86cd39e4L,
  47201. 0x13cbfe3cac6edd6L, 0x03e4a055739b7a2L, 0x0ae1f146c46b4abL,
  47202. 0x0052877ae575f4eL, 0x1358b75ede34e7eL, 0x07307c63d064ea6L,
  47203. 0x1cf131a3be87976L, 0x158723a830e5a21L, 0x01f610c2efa28efL },
  47204. { 0x1d4c7d71f0bc2d7L, 0x163663728ea095cL, 0x164e827e03d9a60L,
  47205. 0x0a08f5c13925c05L, 0x17f351f9b7dd2d2L, 0x1c285f1a818a4f9L,
  47206. 0x14b21a75273871dL, 0x13ac048559625e1L, 0x0ba188c567bc28bL,
  47207. 0x1203090835e02a8L, 0x012c7e35f50ca63L, 0x15cfa712a3c161bL,
  47208. 0x1b8bc97607b4a67L, 0x0a4bd5395a93e2bL, 0x0f7599af24f17cdL,
  47209. 0x08f46be3bd19873L, 0x1e53087dc5ce9d4L, 0x044d9ab5b5108d5L },
  47210. { 0x16db0afdfdcc837L, 0x005d55438dbd4f6L, 0x1f2470752dc83eeL,
  47211. 0x0f5b593cb882757L, 0x0b8657a3f5b56bfL, 0x00eca72b32516d4L,
  47212. 0x0d96046c13dc839L, 0x1d4c7c23a4c6e86L, 0x0ee628ecef426daL,
  47213. 0x08b0ce4e58b16e1L, 0x1605fe1d92190c0L, 0x0e04ab09790d39eL,
  47214. 0x0f00bf7928e1bb9L, 0x0e30777296613e7L, 0x0b70be53bcea03bL,
  47215. 0x09ea4fc24057d0fL, 0x126656f18e08a0dL, 0x01ce27886abe2e8L },
  47216. { 0x1a9b68ce88aecd3L, 0x1848c528c554ed9L, 0x16b52f53b951556L,
  47217. 0x0e040d1b09db839L, 0x011ac72d79b68b6L, 0x0d053c3ed640684L,
  47218. 0x18a0db479b4d6a0L, 0x0899083d3d477a2L, 0x0a7bc1775894c44L,
  47219. 0x15b1b92f8d50901L, 0x1dd9fb1f53155bcL, 0x1767a8dfea377d8L,
  47220. 0x0d73f7e3392817eL, 0x0d7692627ef2df4L, 0x195e73d131b25ddL,
  47221. 0x1f79817342e0f6dL, 0x100cff164789069L, 0x020a5aa16a48a95L },
  47222. { 0x1c31e58606e173bL, 0x1a70dc873389d19L, 0x144b7aec82bd6dfL,
  47223. 0x0e0a241ce084bf6L, 0x1013e4ecc788c61L, 0x03736b9f782b014L,
  47224. 0x1a42a7e74d6b207L, 0x05dc263d11f28a0L, 0x1708f9b3244af08L,
  47225. 0x1726b360dd15754L, 0x1d29b9d036ca72cL, 0x0491a308600f5e3L,
  47226. 0x18ed556a6c74ab9L, 0x13868bd30999c77L, 0x023d6ffd23988f8L,
  47227. 0x10a2a78e6c5f52cL, 0x12a43977874444eL, 0x02933c6b57005c5L },
  47228. { 0x1ff1c59df36aeb4L, 0x1329e5495e055aeL, 0x125a49e97e054b5L,
  47229. 0x085bfa923e1c07eL, 0x0571f89b8509d41L, 0x19a24292c616295L,
  47230. 0x07824af5860124cL, 0x00c3467d29e7efbL, 0x0fab418d32c1bf9L,
  47231. 0x1ce24872d52b4aeL, 0x0465bbdb4b5fffcL, 0x00ea1ef291521c8L,
  47232. 0x12d3053b4f3ecd4L, 0x0eccba64a5ac7cdL, 0x08bda0ae3ba10a9L,
  47233. 0x19d4c474b383b7eL, 0x0dd045ac614c8efL, 0x038205d2de08677L },
  47234. { 0x0364f81515a1a96L, 0x11a818c2193f016L, 0x19406b64f53cc69L,
  47235. 0x024e76c2e61412cL, 0x12cda9d29d7694fL, 0x0a60bbc4436c3b6L,
  47236. 0x1a5ac78069d08a0L, 0x00c69244ed70cceL, 0x02fd4f0c65b25f0L,
  47237. 0x0939a4ffd94a625L, 0x18362b7874cdbd9L, 0x07d1cfc70c1d83fL,
  47238. 0x01b774c31eaf9a2L, 0x01b2bc254be95b9L, 0x1d3aa8feb0f9609L,
  47239. 0x06491fe5bfe9ce1L, 0x1c13d281e1afe87L, 0x04821d36b05e8e4L },
  47240. { 0x111a0fe766c7937L, 0x0f6ae55de1df18aL, 0x0333802222b06cbL,
  47241. 0x1ac2c401e65582cL, 0x14a2ea06928754bL, 0x1f0837dc00e41e9L,
  47242. 0x136522b5e80ea72L, 0x10132d610459dbfL, 0x1c3c3463ae40698L,
  47243. 0x1897526facbfb31L, 0x14e0d10324abe7eL, 0x0b8c9d1b42a8591L,
  47244. 0x02db4e801a79bc8L, 0x0f1abcd94abb8fdL, 0x0ab41e1ef4b04e0L,
  47245. 0x1588dc8b8ebbfffL, 0x135b0760a3cb73eL, 0x0131b15a41d092fL },
  47246. { 0x1c68d28eefc3e89L, 0x1743bb4f4f73892L, 0x0e1abd792dd4b43L,
  47247. 0x05970d6667160f7L, 0x1f552bacdb70907L, 0x06d0f4fe9e90757L,
  47248. 0x1c51697bacac530L, 0x10a723ed11489f2L, 0x121fbd3101e06d4L,
  47249. 0x0f27952df54e6a4L, 0x0351929efc87691L, 0x11900a9aa8e2f6cL,
  47250. 0x11bee0f2e9193f8L, 0x00a1c939ad6729eL, 0x11ad7ba4b09958fL,
  47251. 0x0b375390dc1652dL, 0x15e452fe23109ffL, 0x0174a95902aae49L },
  47252. { 0x0846bcad75f886eL, 0x12edf6a1efe2c15L, 0x16d801ec6e1b9a2L,
  47253. 0x126abfe56a207c8L, 0x0263ecc9580e2ecL, 0x0f2f19de3817935L,
  47254. 0x081d8a0d6ce1860L, 0x0da04a227d8d824L, 0x1a5c26e3a7fbd85L,
  47255. 0x17c1fd9ceb75e58L, 0x094fca9134bea23L, 0x1e66a763f52ef55L,
  47256. 0x1117559a307c14eL, 0x1849bbf07fb0250L, 0x0bc09ccaf365ac2L,
  47257. 0x1de0d4b82912db6L, 0x04b1c0a84c9eb53L, 0x0091b680b981bc7L },
  47258. { 0x1481c8fc084373bL, 0x123b432304bd76bL, 0x1e8184ef0d2ca6bL,
  47259. 0x19269785602601bL, 0x0e2be7e23712714L, 0x008400432923148L,
  47260. 0x115d9553eee7fb4L, 0x105e1d816708462L, 0x165baf594330a32L,
  47261. 0x1eef0d438377c0bL, 0x11c9f6e9d4c3a4eL, 0x1acce9992b96fa5L,
  47262. 0x052438906dbb0c5L, 0x08a32c79d9fe69bL, 0x05fc3a466206507L,
  47263. 0x18fd5cc2deaaad9L, 0x16e353c2d854b9eL, 0x00152400a31065aL },
  47264. { 0x1d6d23d506ccd38L, 0x10e2a482cdd5308L, 0x109da74047148a6L,
  47265. 0x0db05126fae2f93L, 0x03835083e87e1b4L, 0x0d612c7aeb1dddcL,
  47266. 0x1347fc29ed09eabL, 0x1fb33564d7b3e2aL, 0x0dec0ffbf8ec955L,
  47267. 0x14abe33a4fe5c40L, 0x0577b87804537bbL, 0x096e6d3e8d8e647L,
  47268. 0x0091eb2599192a6L, 0x117461ed2182233L, 0x155b462f8b6a21eL,
  47269. 0x0ebe7489c584b86L, 0x1e031390414b55fL, 0x00ec5ef37c790bfL },
  47270. { 0x1cd39f8a2028924L, 0x078ce583765cf81L, 0x12df5bc16119b95L,
  47271. 0x0cb40c0eed0c577L, 0x110fec10dbe0671L, 0x0ddb2e49cbe4bd5L,
  47272. 0x0e8e3d084e099bcL, 0x1cc829bd9974ce5L, 0x1594d4d43f88b05L,
  47273. 0x0c9fabd564a6a68L, 0x10a9aafec5d8e1eL, 0x16b76df8cab4e9fL,
  47274. 0x04ee8d2139d8196L, 0x1b069d136e1bae4L, 0x0e4ee1ee6c02808L,
  47275. 0x0413d66dda6b9bdL, 0x1c1f565b28bcc83L, 0x01a4e34a1e30809L },
  47276. { 0x1b394444de6c88aL, 0x16238a380103f68L, 0x0288870ade03570L,
  47277. 0x0810a1327d6de8bL, 0x1aef0c18749f756L, 0x1e38782005d2bcdL,
  47278. 0x1fafcb5d0a4e1cdL, 0x0a78b51c5d8428cL, 0x0243a666e5337f4L,
  47279. 0x0c8f8e3f685ea85L, 0x1cfa43d2f47e472L, 0x1d14be1c253674fL,
  47280. 0x170738963596089L, 0x138c1564e869d0bL, 0x05f170a73e10b54L,
  47281. 0x0aed24232a53210L, 0x0faa32f327e8725L, 0x002b2c3d5c4e16cL },
  47282. { 0x08562ed1ce4733dL, 0x1fbe5cc728a2200L, 0x087ea6ad1ae57ebL,
  47283. 0x1d6c351826be060L, 0x16b3597689494c5L, 0x01697b2be4a81b1L,
  47284. 0x1c0f9afa1323cabL, 0x1761cb669b137a4L, 0x1c4ad918f7e872aL,
  47285. 0x1544f4fe2029770L, 0x0bb8fcc642d47b0L, 0x086edffe4a9f859L,
  47286. 0x08883e097258fd1L, 0x07d8aa1c379e06bL, 0x12ab8018f4283a4L,
  47287. 0x01ed98870ec97edL, 0x1de815f15653f1dL, 0x00dc3f976dc366dL },
  47288. { 0x1792bbb2b0b15b1L, 0x05ad3e735d3bc9aL, 0x1f67763cdde68f9L,
  47289. 0x1b8531a3dff759fL, 0x047031c6005450bL, 0x0b4033071faaab6L,
  47290. 0x14b081dc3c1ea57L, 0x0a99c7d09c05a20L, 0x1b050791e7aa8ccL,
  47291. 0x0b10f39dd1911d1L, 0x06e534e58ca6413L, 0x168efd700adb0f7L,
  47292. 0x08edfca0cc8df9cL, 0x0b895065712186fL, 0x0122a64dd2fd05aL,
  47293. 0x1cb3d7c7e78ef11L, 0x023b22b87b1c4a3L, 0x0470113e21f4adeL },
  47294. { 0x00e22a83210964dL, 0x0aefaff82b77580L, 0x087f6bc7ab5f733L,
  47295. 0x00cf9b95c6042e7L, 0x0bdcc90cd02833eL, 0x125a7a8e62ba65cL,
  47296. 0x00a621bb29c50c8L, 0x1d7a01cc075767fL, 0x1b98ece1b0c1a8dL,
  47297. 0x14523721bc6130eL, 0x077436985979748L, 0x113296fde1c58dfL,
  47298. 0x13bda9f306b3ae3L, 0x1c50426d9d1e0b5L, 0x053a5417a689b4cL,
  47299. 0x00d78a51cb326a7L, 0x16e848ecb114ea2L, 0x00a58ad5aa02a2eL },
  47300. { 0x16d86c9664c59a2L, 0x115f0b07ebd5287L, 0x15a641cb2e38f7fL,
  47301. 0x1302ed4fc067f36L, 0x0587080b5f2325dL, 0x0ea702bcd06a73aL,
  47302. 0x0a38693b837bc35L, 0x1dd815b3ff590f6L, 0x1d6f18d2f3f09b4L,
  47303. 0x044b57394974ec3L, 0x0254f58251d8f33L, 0x0f5031f7f3f5951L,
  47304. 0x094b63d701dbee9L, 0x03f53917ef90707L, 0x0ad5c7f2ee9b8c1L,
  47305. 0x0abeb9cafc394c2L, 0x02e1e16ac76009aL, 0x03a15df6c621c4fL },
  47306. { 0x1ea86dcc1dc2c73L, 0x1feade0b21d5f91L, 0x087c9363287d2eeL,
  47307. 0x01196b958e0ff1fL, 0x14e66a7dde68a6eL, 0x1bd6bc3eaa6325aL,
  47308. 0x0ae51e276e88aa6L, 0x0229b11aa81c6c9L, 0x0c8c2e02d1f72e0L,
  47309. 0x041302ba371513cL, 0x0d6ecd2c61f1f53L, 0x1bfdd71fc193cd8L,
  47310. 0x087d11e415ed8b3L, 0x1c32e3fcdb5e1a7L, 0x1b305f2ce422efeL,
  47311. 0x1ad36e2fa39cdc3L, 0x124151e3308f7cdL, 0x04bdead0a5ae4a0L },
  47312. { 0x01c62fe81e82861L, 0x0a5b6eea1620770L, 0x156f997a4795c0fL,
  47313. 0x08b5777fbafca5cL, 0x072a45f4b8b4937L, 0x0794ec5a78afa96L,
  47314. 0x19d7f3a10d6a154L, 0x12d3beed736b05bL, 0x052e84c5fa20c8bL,
  47315. 0x1bbe9688545057aL, 0x06ef6329804f0ebL, 0x13744df060be071L,
  47316. 0x080cec8b9ab0d9bL, 0x1fd5ed0c7829f42L, 0x10930a9358cd9ebL,
  47317. 0x1745ca1ea77c94cL, 0x069f892c58c864fL, 0x018be3698a4662aL },
  47318. { 0x03525b02cb7d42bL, 0x005e49887d65706L, 0x008bfc81023d549L,
  47319. 0x1fc1821d411aba4L, 0x118eb23d6b01402L, 0x12950cbfdf7b453L,
  47320. 0x035ba8051ad6904L, 0x102b35f9c90221cL, 0x0e9a1d27f022de1L,
  47321. 0x0dcb68b6e1fa4edL, 0x0b8fd7bef90021bL, 0x0c83d9978239f83L,
  47322. 0x19525f8636f9d70L, 0x013b1e182481113L, 0x0418c2cdda5e5abL,
  47323. 0x07e2f398690783bL, 0x0fd451651f0ee3dL, 0x03572cb9cced05cL },
  47324. { 0x1b13bc7bff4d2eeL, 0x0a1149858b9ec2bL, 0x0f541e524db081dL,
  47325. 0x14bdfaab7d6c4a9L, 0x0e0c33891d5f232L, 0x10fca26037a542aL,
  47326. 0x01edf3cb16d6639L, 0x0998ac90c3ffabfL, 0x0ee261fb15a2afaL,
  47327. 0x07fb91316cbd3baL, 0x06b88b5b3c01eacL, 0x0a69a68de428351L,
  47328. 0x1f97b6497e28880L, 0x1d157ffe47f39dfL, 0x1469c9a2a1656cbL,
  47329. 0x170573df39e7de2L, 0x072a84ee5f1e744L, 0x033248246de31ffL },
  47330. { 0x1b7bb781e8b760dL, 0x185ec12d56d5048L, 0x167fead489bf51eL,
  47331. 0x0d7ff8291d02927L, 0x029be3db4a6dd22L, 0x185585ad0197c55L,
  47332. 0x121a0c636f1c0d2L, 0x08db9997f6afacaL, 0x08506ab379c581eL,
  47333. 0x089b53714187671L, 0x1e4d5b3db2031c2L, 0x06efded63d0c916L,
  47334. 0x0183f0f1c9fa176L, 0x0b55f6ee964e0e6L, 0x0ec37925bc149b4L,
  47335. 0x10e747c1d31c552L, 0x1ec6f2d7ada0f13L, 0x0275c9dae79fd24L },
  47336. { 0x189f7e5e11fae32L, 0x0ba7ae2011fa8deL, 0x137d2470fdbf44fL,
  47337. 0x0eaaa4f36e36002L, 0x05ba00681d849a5L, 0x1e51655dcf444b8L,
  47338. 0x19dbe0888906704L, 0x0555f776d0bfa66L, 0x1931c3f5275878aL,
  47339. 0x15777f7f79ea8b9L, 0x097322f629a1e04L, 0x1b67b33e182c313L,
  47340. 0x06a19d48b682cffL, 0x14e362705fab2a0L, 0x00105c95817888fL,
  47341. 0x03990a7cf03bd0dL, 0x168cdf5c90bc700L, 0x015ac16c9be021fL },
  47342. { 0x1165c8281abc2aeL, 0x1c07af15b4f6550L, 0x0f481fffd9be9ccL,
  47343. 0x0ca8eeca0d812f6L, 0x157fa21c5d60382L, 0x06deeaee5d64f9dL,
  47344. 0x1cca9e1d436d326L, 0x0390bc42207b3dfL, 0x1ceed172c2f11c4L,
  47345. 0x071c9324f1a4604L, 0x0e4dae0c7b77eeaL, 0x1a0dea10c946e39L,
  47346. 0x0de93acfcd915c3L, 0x19f97bd57f4719eL, 0x1f3ba692fb8435eL,
  47347. 0x095fb83b1d691d6L, 0x0c04fa49ce3fa57L, 0x03c30a884c316daL },
  47348. { 0x1e3f4807ae72c21L, 0x150a27e8786d29fL, 0x07a3e30e91518c6L,
  47349. 0x08a369e3578eddcL, 0x17cdbb24379ae09L, 0x1eafe6951d21cbeL,
  47350. 0x1bd69e8533ffa0aL, 0x19f77c9da25e84fL, 0x09b0a43ee284d3cL,
  47351. 0x1dbc5c9c776370fL, 0x1013919ee3a1ed5L, 0x180a686e984031aL,
  47352. 0x055428deb50c8adL, 0x01d7d167b21b9b0L, 0x0a55be6d3603b03L,
  47353. 0x038d0daa3f27875L, 0x0259f9a28ab8416L, 0x02a05b5dbb5e4e0L },
  47354. { 0x0e1734c321d315dL, 0x0b3096c3702e802L, 0x0516eea336053bdL,
  47355. 0x1359b8f135d5f5cL, 0x1877570f1fb07a4L, 0x1e29ef3510f4d6aL,
  47356. 0x063acb92a0dfae6L, 0x08a86db65263ac5L, 0x143afbc78ea362fL,
  47357. 0x14b9ecbd55fb2c2L, 0x1f6af832493580aL, 0x11e0f95be1d3b9cL,
  47358. 0x0175020538f69d9L, 0x0230e694f05a82dL, 0x083a060f6df468dL,
  47359. 0x0a1edc3850eecbcL, 0x08c2ca2586752ddL, 0x044be558a49701cL },
  47360. { 0x1ed38130d8bab8aL, 0x09b26521c10052cL, 0x1cb101605057047L,
  47361. 0x14f5912ce80d0f7L, 0x197411a086ad0d3L, 0x019b8e22494082dL,
  47362. 0x00c79d2612c47ceL, 0x1c0e1a5db081a35L, 0x0d883628b6c912fL,
  47363. 0x07c7bfd8a7d4469L, 0x1ca9373c2b24f91L, 0x13554d849f4cac9L,
  47364. 0x03bf6cd94982f62L, 0x10528c16d5c835dL, 0x1ae4e94b208b99cL,
  47365. 0x0e7545fe8fb5861L, 0x0c5dc62c4a4fff6L, 0x0325803b1a3b587L },
  47366. { 0x03f533eb3c9a404L, 0x1bfb9dbf7cca90fL, 0x18a5b094da4ec76L,
  47367. 0x080e71dda98fe27L, 0x0e26cad07ce7f4cL, 0x162e78e67e9d99eL,
  47368. 0x1380761e124d407L, 0x19e7f1f813bb810L, 0x0217cab32c39b5aL,
  47369. 0x16d785dcf7aaa8eL, 0x1dbd5b8485ea550L, 0x1625846e0055f78L,
  47370. 0x1fb070a29380178L, 0x0bb654b205a961cL, 0x15a38db8e49454dL,
  47371. 0x01d084aab284833L, 0x18c291fb82c09e5L, 0x03ee91753330c76L },
  47372. { 0x1fe844b49cbb3bfL, 0x063822ab17d92bfL, 0x14de7d6a116b783L,
  47373. 0x0dca24eff83cddcL, 0x10635718956d7f2L, 0x0abf9a163aea5c9L,
  47374. 0x1d0ace685224a5aL, 0x0e519e9d66505caL, 0x16b0d3ddd83247bL,
  47375. 0x1d4fb19900d211bL, 0x100f04505292159L, 0x088f6ded522c82cL,
  47376. 0x10dac6f79060afdL, 0x1e9dcec14afca49L, 0x12b7c3da17fe52eL,
  47377. 0x0e912b91f31f8a3L, 0x0c89559c88ab13bL, 0x0189bbe332f8c7eL },
  47378. { 0x1c5de097dcfb35fL, 0x0654f80e61b7c1aL, 0x0175d5db2d8cb73L,
  47379. 0x15ef6966eafd27dL, 0x109a19b50c2dd48L, 0x1ff303cecae6a7dL,
  47380. 0x16b49d4bb4565c6L, 0x0de8731019e4b2dL, 0x0e52efb5369e90aL,
  47381. 0x004bb3181e9f305L, 0x0d93eaa541c3811L, 0x076c0ac49ba5f9eL,
  47382. 0x0400d5e467d8f99L, 0x0647a29259ad4c1L, 0x02805e78a274090L,
  47383. 0x1b57bde8a8478c9L, 0x0713a5fd695587eL, 0x01ed66286508f29L },
  47384. { 0x13e4f946499ae4cL, 0x0e5f0b829e293e5L, 0x13a6f9e0ba2a91bL,
  47385. 0x11b0903c8b00febL, 0x0a286fd0b6c64d2L, 0x0e6da4f9af228c5L,
  47386. 0x0fabfdedee6eb7cL, 0x1f7e7f6c4215d84L, 0x00a9ba385b9bfd2L,
  47387. 0x08d06a9c403f9d0L, 0x091012c5eca10b9L, 0x0d0ff3bb3e14f56L,
  47388. 0x14f3e9df646fd57L, 0x106f8ca6e68f7edL, 0x1a77c15774b7de9L,
  47389. 0x114637da7e587c0L, 0x0f7469b75612324L, 0x04334a4f0b4a3a2L },
  47390. { 0x09a0da53f4ab07aL, 0x17999faa537df9dL, 0x0486c8f3ca40b35L,
  47391. 0x1d091c7ab01925dL, 0x13b218abc9581c3L, 0x165a6bc9d78fdeeL,
  47392. 0x00e80e1663a8419L, 0x16aa002729d3218L, 0x13b664b1e7d0877L,
  47393. 0x1ced8ddeba63848L, 0x1510d538b577435L, 0x08366653b7050a5L,
  47394. 0x107b96d4800d2b8L, 0x014aee237d42275L, 0x1dfb138de9415a7L,
  47395. 0x062ef85a706e729L, 0x198dc3884ff5b08L, 0x02ba1a95c458fd2L },
  47396. { 0x12193f70d5d7ce9L, 0x0fe9305a43f57f6L, 0x0d65ef997f40f06L,
  47397. 0x00f04e1aacf8895L, 0x1aa70198dd9da86L, 0x0cc2efc54276005L,
  47398. 0x0a360bb09f924a1L, 0x03b32d995e1bc40L, 0x14e7648c761c220L,
  47399. 0x0b19ade048e0cf5L, 0x08e9a7c359e0aeaL, 0x0681a528c9264a7L,
  47400. 0x01099f68733f204L, 0x14cb008d222290dL, 0x14ea5397f2f3025L,
  47401. 0x147427109abb1f0L, 0x04f2418c624d3b6L, 0x01f218d7903571eL },
  47402. { 0x167d93983d381f1L, 0x00d57686019e1fcL, 0x134151041da0d94L,
  47403. 0x10a1274da77e75eL, 0x192f2900a86d159L, 0x185baaa1d703a0eL,
  47404. 0x1b5bffacabe98dbL, 0x08da1214d47548aL, 0x1336a4fdaaefdb6L,
  47405. 0x08dff220d4a17beL, 0x0a8fb6147b907bfL, 0x0d0c23d26b8aff8L,
  47406. 0x0653bbb3434f1c9L, 0x16c4b61566abbb3L, 0x0efe907c9a4c6eaL,
  47407. 0x19de3141f77a30dL, 0x1351c3d7d82a203L, 0x036d69f8af13326L },
  47408. { 0x1940b7d12ec35a1L, 0x0e2db73efd89468L, 0x031bc4cc8755886L,
  47409. 0x14678b1d6c5984fL, 0x19903c435e76904L, 0x0cb50c8a8487aaeL,
  47410. 0x12e9c186f249b0fL, 0x0372e953e071815L, 0x17a4140217198b2L,
  47411. 0x034accefc4ac637L, 0x1cbc76faf404a6cL, 0x0c27be751b86a2fL,
  47412. 0x08672375c51109aL, 0x09c1e9698472c22L, 0x1fe0df159642e92L,
  47413. 0x1aabff87dcf8c17L, 0x03fc87a539027d2L, 0x0121c74ea2fa8bdL },
  47414. { 0x0a453088815af3cL, 0x18d1979e4df6ae2L, 0x17265ed9777f957L,
  47415. 0x0825ca3d6b5de39L, 0x063f249061c61d9L, 0x19f118de86d62a7L,
  47416. 0x18041bc510a7342L, 0x163ee6f8785e3b4L, 0x17150e04b6bbc4fL,
  47417. 0x02da6448df140e5L, 0x118cf35dc07d6c8L, 0x1e8c54a26921e36L,
  47418. 0x1368f1f7f28b33eL, 0x1ea0b5b3eeda3e3L, 0x1e56ecfd2b69446L,
  47419. 0x01ccf3a552f9bfeL, 0x00100a8b7b29620L, 0x009f9c808d7f187L },
  47420. { 0x1d296ef7bd0c827L, 0x08879a514ffa31eL, 0x01a072694569418L,
  47421. 0x0a4d1794eff0f26L, 0x198045dfde8d804L, 0x0072c265dc18124L,
  47422. 0x18188fe435c41a3L, 0x016550719504c76L, 0x0293bb5e7535c5dL,
  47423. 0x1754ceaab20a888L, 0x046b406ef680173L, 0x017f49b1a031fc6L,
  47424. 0x001cf2b8662497eL, 0x0c625d4599eebbdL, 0x0adef26f01d6dcfL,
  47425. 0x036165308cda8e4L, 0x1b617a7ce24cbdaL, 0x022c6a5b5b40381L },
  47426. { 0x026a20e4d54d8b2L, 0x0b4b726990506c5L, 0x0163e653dc00169L,
  47427. 0x185eca9350d316bL, 0x1694d00d7a4adc3L, 0x02015e8c09740c9L,
  47428. 0x190411ae6c001ccL, 0x041c21428934366L, 0x1eae95ea5992302L,
  47429. 0x17e174d8da41061L, 0x0d72d61727ae28fL, 0x06332f08e0c9fcbL,
  47430. 0x108f27d49f21ae0L, 0x17b92ab5b47785bL, 0x136c068c967bc60L,
  47431. 0x1f2b8015c08aec4L, 0x191628e3b065668L, 0x02f89fafd5b7ddfL },
  47432. { 0x06ed9ae3a9b0dc6L, 0x0def4b7c41f643eL, 0x1e23aa2cd9deba8L,
  47433. 0x1934cdc757d4cd7L, 0x08217ffddefa6abL, 0x06f82e626998bdbL,
  47434. 0x19d3bdd0723c8a4L, 0x1943e1fbe2efa22L, 0x1fdf0ece7c35989L,
  47435. 0x176c96fb5ce2416L, 0x04f99956fc729c3L, 0x05204b9d9338e6eL,
  47436. 0x02e803e69c90acbL, 0x0bb89d0d1be4f1dL, 0x1685d35f028f14cL,
  47437. 0x005ec6a1b8acadeL, 0x0a211625a4405f8L, 0x010cb24aed1bdd2L },
  47438. { 0x0cb2fd313142680L, 0x148ebb2e8a67a00L, 0x1aaf7f899a7aae7L,
  47439. 0x1015c4578b8d419L, 0x0b6ec250beefce5L, 0x1c78ff9e15bcc36L,
  47440. 0x123b212b6c68b5cL, 0x16b2e137850a2ddL, 0x1f36931298e8f7dL,
  47441. 0x0477e35cad8cbfcL, 0x04254a6aaa90131L, 0x197a2882a9613feL,
  47442. 0x03427f34352c3c8L, 0x090c4be099f7bdeL, 0x19522801285e503L,
  47443. 0x1f4c4b54188fad9L, 0x1082971cea73d56L, 0x049d687580223afL },
  47444. { 0x00b6967988a9963L, 0x03bfbb28af46ebdL, 0x0e18edad43c9879L,
  47445. 0x0ba67245bcc4e9cL, 0x087a5b3d63a9b8dL, 0x0171919e1c69fdbL,
  47446. 0x1333c63dbc2704cL, 0x1ee4a980b87c05fL, 0x1c04ed0b726e662L,
  47447. 0x0ab235c0a1ff03cL, 0x0a51232405b2307L, 0x1897f047af2fdf1L,
  47448. 0x0fbccde451e5674L, 0x020bf56f02c37b9L, 0x1b9623717f22355L,
  47449. 0x1a3f2572a4412aeL, 0x0344408dd425844L, 0x039fc61f87520e0L },
  47450. { 0x1534fc85df763ddL, 0x013f99d638c1b44L, 0x185dba3c5680ec5L,
  47451. 0x099641111c1b6b7L, 0x057caea61d39094L, 0x0fbdf9bc0264d6cL,
  47452. 0x0a33ea96110a146L, 0x02ac4ddd9e25275L, 0x1749e0d98ea36a0L,
  47453. 0x1ffb6d71990f6e6L, 0x17ba98a2de4733bL, 0x0aa45a2dc6c32c7L,
  47454. 0x1cb15ae206a14e0L, 0x1e5192f251702c7L, 0x0d06a283c9a1d17L,
  47455. 0x0a370f9f3a80e42L, 0x175dfed25d97caaL, 0x00084571cd6df6eL },
  47456. { 0x0d178f3a9e88f63L, 0x0d88f55863992aaL, 0x0f9b8987629aa81L,
  47457. 0x1d1a172390ee74aL, 0x09bb004d24db7daL, 0x118485ef085839fL,
  47458. 0x07227f22fbf9d53L, 0x0342d5e0b32198dL, 0x0ddc838039d5951L,
  47459. 0x1fb2dcca362ed7eL, 0x192fa07b8296670L, 0x1c6df675362ff77L,
  47460. 0x15445dad0088891L, 0x0a84bf0f864d56bL, 0x01693877ff11aafL,
  47461. 0x0a4671090113759L, 0x1df348bb42fa0c4L, 0x0403e036c7589e0L },
  47462. { 0x0a969ec98ee0ef6L, 0x0aa41c5dbdbd780L, 0x124a80be3f6eea7L,
  47463. 0x1516e0aaf848909L, 0x00ad1af27bdb201L, 0x064afdf2c9a1f23L,
  47464. 0x074ed4ea6a50a66L, 0x01d2e9b67bdb50cL, 0x1ce1525c9ed399cL,
  47465. 0x0dab440fb9084deL, 0x1df456660846922L, 0x1675de1e4eb411fL,
  47466. 0x17fa2f358b5df76L, 0x01cd831a49f8c07L, 0x160ed4eab13ff3fL,
  47467. 0x133f84d258c4c2eL, 0x061b2fdfa36b553L, 0x00b2126364cb03dL },
  47468. { 0x1d65c55dd2744a9L, 0x060e17f1d7a0c2eL, 0x1a67bfa2c224951L,
  47469. 0x0b53bed23465905L, 0x1be9967430b7ab2L, 0x1968914c1c22a84L,
  47470. 0x1c9caf3b349632bL, 0x019115c8131798eL, 0x0d43961414b8efaL,
  47471. 0x07fb3dcf6b26896L, 0x195790b9fcd0111L, 0x188a8b61d3d753cL,
  47472. 0x14f03ded283d16fL, 0x16665c2e23a51f0L, 0x14e946e8f26b7feL,
  47473. 0x063627bfcd782e4L, 0x18adddaf4b9fb58L, 0x02aa27301527a23L },
  47474. { 0x17c5313baa80b4fL, 0x138b7b1dee477c4L, 0x0b6ded0b16a0048L,
  47475. 0x12110661195c4e8L, 0x0d341ab1e9d9e1eL, 0x0a2c381a96461f9L,
  47476. 0x1676058f41403b6L, 0x0530693bae78521L, 0x02053c5e01f6c7dL,
  47477. 0x1883a2365a1019eL, 0x022f4827426bc60L, 0x1cdd64f28d02ed9L,
  47478. 0x1e19b1b540d0f70L, 0x114ca5a1b905aceL, 0x1b14f3e02dfb370L,
  47479. 0x01e8583499b9c5bL, 0x061dd7d3edd1ed6L, 0x02b9accae7120e9L },
  47480. { 0x04ba3fba0237056L, 0x160b219d599c46eL, 0x0ef49c7b1849a15L,
  47481. 0x07c60637d9803ddL, 0x0118a1f5abdeb03L, 0x100799a777220cbL,
  47482. 0x01dcfb125d0856dL, 0x1fa36e30b9e110dL, 0x17b0c46cd7c1b7dL,
  47483. 0x0a1d96d25262f44L, 0x096612ec7fe5374L, 0x09c9939e68cbb73L,
  47484. 0x00eace64c9ac390L, 0x1b456ccd7c394deL, 0x05503097308a085L,
  47485. 0x0d22f77a7610315L, 0x0f0e468ed5f049aL, 0x0442a436f9f622fL },
  47486. { 0x0942c934bdff464L, 0x138cf92d3da28b5L, 0x1c2cc96f8c90f6cL,
  47487. 0x1633fc667399600L, 0x041ee8ff2055a31L, 0x17c6f7d6534d741L,
  47488. 0x1cf19d81f742157L, 0x0213c492c1e3436L, 0x1bcb0e8a271d368L,
  47489. 0x0f08d513442f35cL, 0x1742ac617ab864aL, 0x0dc81f03f239316L,
  47490. 0x0f994fc5031a0b9L, 0x188ceb70268745eL, 0x0933830cf605a5fL,
  47491. 0x1f3ae5210650f55L, 0x02dc5dd4d3ec91fL, 0x018e767f46a55cbL },
  47492. { 0x17bfd9afc8b21e8L, 0x09959d8ca1b6fa1L, 0x0b524870da83977L,
  47493. 0x1b47a1f521fcb20L, 0x1bb523bd8e9de84L, 0x06b4bacb31f356aL,
  47494. 0x0d672600288febbL, 0x1e2201381b369f7L, 0x1839aa7bdc9d20fL,
  47495. 0x0817b36f66b7d1eL, 0x1b53ef1545b2a7dL, 0x0becd8e85588901L,
  47496. 0x05ff3252f865ffaL, 0x1aece59e95be3caL, 0x15bc749cbfbf015L,
  47497. 0x09d8623610c77adL, 0x1b35d8f3cf09a6aL, 0x034b0da356d12a3L },
  47498. { 0x07b587ecb35e2acL, 0x0aa35abd78a6ce8L, 0x096f6ca281307b5L,
  47499. 0x08e13aa9e1d942fL, 0x1c6f400ea1f91d4L, 0x0670c853738cfecL,
  47500. 0x0ff49392e23b7eeL, 0x0bbf2f03dba48dcL, 0x1d67120e6b655afL,
  47501. 0x13c168ec9a09e53L, 0x18828a5c1fe8876L, 0x1e64a9d08246d2fL,
  47502. 0x1e36051f9f1eb51L, 0x19e72df49712a6cL, 0x0fde53f76bb10adL,
  47503. 0x155b31353465d9aL, 0x0121964e22f0781L, 0x03531d48629baa9L },
  47504. { 0x0554e003d7acbbbL, 0x0b3455ba7b0843bL, 0x19c8e231466cb00L,
  47505. 0x087d729a9fc9452L, 0x0cd6d2f60166771L, 0x1b87bf84351e6f8L,
  47506. 0x0f9f3e1960085ecL, 0x142cb110182b49aL, 0x1d6ed58165ba3f4L,
  47507. 0x1e63c09ae5238eeL, 0x0fc1d3a11295daaL, 0x0366dd4a05d5013L,
  47508. 0x070e021ed3a53a8L, 0x030bf8b2e105c98L, 0x0d7342e309fe24aL,
  47509. 0x052c34a8ec88d04L, 0x10effc89ffd8255L, 0x028f6a51168a8ecL },
  47510. { 0x1d6963a449701b4L, 0x0c8d1dd93e5791bL, 0x1856d5ca597faa3L,
  47511. 0x0bb6a17efa7df37L, 0x0e643b9b75a7a05L, 0x15aeaf7eb3a4076L,
  47512. 0x1225fca9834b5b3L, 0x0bed1f86418bdafL, 0x041c53cf628ce68L,
  47513. 0x114b88fb88330afL, 0x1c84e08d403b303L, 0x04c0d853fc90f50L,
  47514. 0x0ae1ef9712af0a9L, 0x0968b4dfc9ef9f9L, 0x0a5e4f0357dbec7L,
  47515. 0x124add6f5fc4ce9L, 0x0e54173d94ae9f4L, 0x016b4a8de15c5aeL },
  47516. { 0x1007d9f904e222eL, 0x19247c37a7084eeL, 0x1a2e3d0a7bb8ccfL,
  47517. 0x0b9f8eea31a9329L, 0x0b0f42f12957341L, 0x1a1a8cb73ff51d0L,
  47518. 0x1c6831e572df709L, 0x0ab04151ecce23cL, 0x183d95d9c2b874fL,
  47519. 0x05b26bc73870b13L, 0x0d4fd62e4a9d0b5L, 0x116288f6bcdb248L,
  47520. 0x0cbcf931a032204L, 0x13d7913405d6b98L, 0x0ee4fe5d7134226L,
  47521. 0x075dc8c92098370L, 0x1f0a24eba02165bL, 0x032e2473c704662L },
  47522. { 0x01c73cede222c22L, 0x1ec66fe7511da0dL, 0x0c52c850ec195a0L,
  47523. 0x1eb3f9d8ee06039L, 0x11204cef284adf8L, 0x19a883fd8e2c0e1L,
  47524. 0x02303d534fbba51L, 0x025b7ecfe169a63L, 0x176a3f2d110f18dL,
  47525. 0x004fd1403e9f009L, 0x1c2918979fb380eL, 0x0fdb6512ba5de0dL,
  47526. 0x0908b0553ad8286L, 0x17922a22f0837a4L, 0x1668f2f88a03e9bL,
  47527. 0x1745a805aaf0b51L, 0x06ff63dd9ffd438L, 0x01b5ae6963d3591L },
  47528. { 0x1ff4e20545679a7L, 0x005a0a29063a843L, 0x1fea6d167361936L,
  47529. 0x1390b5e3472146aL, 0x0d935a5ea19eaf3L, 0x0d33c506a3aebccL,
  47530. 0x1a041d140660de0L, 0x088e9072ef21985L, 0x1c6a21d112f4122L,
  47531. 0x08742fc9b528d1bL, 0x00547baa9d37e23L, 0x054f279f3389feaL,
  47532. 0x11376a9ab614e18L, 0x0911c4ffa2ac9efL, 0x1117a2863dcf2bdL,
  47533. 0x03b91a4f992c1eeL, 0x1d80692f4c539a5L, 0x0046be0a26d9cdfL },
  47534. { 0x09c0d963ecca773L, 0x148c96a4610ab40L, 0x15d36daf59061faL,
  47535. 0x0854cf19bfe1d99L, 0x11587b7e7731237L, 0x1852633d4b36c5eL,
  47536. 0x05ef7cf06840584L, 0x148f98dd070bf9cL, 0x195e95bb8a8de7aL,
  47537. 0x1f0f45ac4c18471L, 0x1c90fb8d1da528fL, 0x18857619a57e032L,
  47538. 0x040f9b2b49f3fe9L, 0x039b3e8fdac8293L, 0x1b851ed30e17a2fL,
  47539. 0x095b23a60a15d6bL, 0x0028e2c38790400L, 0x02f9554775d5b81L },
  47540. { 0x008d4641266524bL, 0x19c406850cfb371L, 0x017b6841bafedefL,
  47541. 0x07cc85ba8d4b54dL, 0x0682e4d60a69e8dL, 0x05a9a6779a4e30eL,
  47542. 0x19ee09bdbb8ec3fL, 0x1ecfb57424e0bd6L, 0x12babb27e18be05L,
  47543. 0x0cd7e5d4716c2e8L, 0x1cb46b8b674e1a5L, 0x05cc3d4de0dddb9L,
  47544. 0x14866e5ae859dc5L, 0x015e69e3e1413c5L, 0x12fa0bf67fc0d00L,
  47545. 0x1e449d10958ecf0L, 0x149a316498083c9L, 0x031280d4c5a37fcL },
  47546. { 0x03f7d9aad264086L, 0x119edd2f0725eabL, 0x000a3234f59f29aL,
  47547. 0x108dcc9633d04a6L, 0x00aa4536a288dacL, 0x0a9f567d1e48cb9L,
  47548. 0x0af4e04c326c3b5L, 0x0eec4500dc05d51L, 0x052fbf54dceccfeL,
  47549. 0x0cd4718a7868db8L, 0x1484cf566c5d06fL, 0x003934dfd514a33L,
  47550. 0x00b5c4eb10fd741L, 0x08fced2f68d67bdL, 0x17a9619e1266dceL,
  47551. 0x0a6355754989381L, 0x065cc9c5f73a1f3L, 0x024bd8aff7e9fe3L },
  47552. { 0x056cbaaf45568e9L, 0x0d07f638c9537c5L, 0x174e6ac94e6bd24L,
  47553. 0x109586fb53b7607L, 0x02a0f5b4c86522fL, 0x0e29cfc6466dd10L,
  47554. 0x1c0ba0427f1d68aL, 0x17f39a0da639521L, 0x18f31f0443e216dL,
  47555. 0x0d534565d1f5ec8L, 0x0343490b001fd26L, 0x1f7f0d536f9c550L,
  47556. 0x04d6308edcdd8dfL, 0x03400965202e9f4L, 0x1a841c76be8cff8L,
  47557. 0x06fcd85dd7a27dbL, 0x0b7b7ae7e5c2ff6L, 0x00c6a35364f28a6L },
  47558. { 0x08cbb22a78b7802L, 0x0eed924be5d7a43L, 0x1cf90aba2b741d1L,
  47559. 0x15699d69c989d65L, 0x0325fd40ac0abcdL, 0x1639a29706c192dL,
  47560. 0x1c6e5b3f815c44eL, 0x056e80f4f116282L, 0x070eb06036da7a5L,
  47561. 0x1859b7cec28bb56L, 0x0274a5f0a553ceaL, 0x1391b9ae0b5a282L,
  47562. 0x0d7bb5e751370deL, 0x103738461f86daeL, 0x04c143517e4f506L,
  47563. 0x1fdf221aa9f14fdL, 0x04069e6f8e45a38L, 0x02a822300e9fb17L },
  47564. { 0x1c5c91006cb9cc9L, 0x03a6ba0e8000a68L, 0x18f8448dbee1508L,
  47565. 0x1c535abf04f9b0cL, 0x0951fc8339721ffL, 0x068a278e90fdfd1L,
  47566. 0x0b9ac73781b9d00L, 0x0cd2084b2d722f2L, 0x03365c8e529ad51L,
  47567. 0x1110742cd777f4cL, 0x14c625c30abb8f8L, 0x07b73fe20179796L,
  47568. 0x16f532973f477caL, 0x0d15e80d9383a0bL, 0x15e7e4e848462b2L,
  47569. 0x1afb7e684a4127bL, 0x04f563a8ff7c6f5L, 0x006d189fe6bd876L },
  47570. { 0x1125a8c15aa2557L, 0x0eb8600449f4e1bL, 0x06519ee2a08f288L,
  47571. 0x08f960085490e27L, 0x09e2ce180d3e9a7L, 0x0d75611695fa7feL,
  47572. 0x01983554c683412L, 0x0009a534c2de07aL, 0x0473d50d61f1b7fL,
  47573. 0x178765de51ef286L, 0x166fa8270a3c9ceL, 0x1d41f0e08cc9c52L,
  47574. 0x01731083ef6d7c2L, 0x0a0e12aa56fd727L, 0x058b40d4250309aL,
  47575. 0x0521c882ce82142L, 0x0cc620230d81e82L, 0x031b185f46da0a5L },
  47576. { 0x18d52228a7d2e41L, 0x1ac11f5b17c3cdfL, 0x0f75b100b625279L,
  47577. 0x0dbc58b35a369a6L, 0x09b9dc38883e04dL, 0x1b86265f9f9c7a2L,
  47578. 0x081167665f462d2L, 0x0da3ed36418279dL, 0x1ca3d702558e260L,
  47579. 0x0a7ecbb930e8dbcL, 0x1abea16850dbe8fL, 0x1d317688780ead5L,
  47580. 0x0ce558f6be369b3L, 0x1c5647c4fe728c3L, 0x196a9cbac3351e3L,
  47581. 0x09d60d00e9e6fabL, 0x0ed295845c06854L, 0x018354c38f8b344L },
  47582. { 0x0451e9d634ec136L, 0x193e50737b2c7deL, 0x054b036d04807b7L,
  47583. 0x018b7fdccf537c0L, 0x1a2d602387b6ef2L, 0x17dc4c9a94191c4L,
  47584. 0x10b79839593631eL, 0x05695e457801593L, 0x128e6f63182a9d2L,
  47585. 0x03ae380fa99380dL, 0x1063e2081d7e470L, 0x051a37d54a23edaL,
  47586. 0x176e72a13df9fa6L, 0x1bfa600e2a8f3d0L, 0x12756224c18856dL,
  47587. 0x0f9a8e3574e6327L, 0x0376443ebe058e5L, 0x01419d620f4081fL },
  47588. { 0x0564b868da5ec5cL, 0x0ced40e046d923fL, 0x1c2e315e9ca2b0fL,
  47589. 0x0f3a687b853af83L, 0x1dc603393512afeL, 0x1d0ca0da1c7267fL,
  47590. 0x01125f5689c0373L, 0x1cdabe647f04e64L, 0x11b87a58e1393c6L,
  47591. 0x05b45e8825d5218L, 0x1071691c8ad35fbL, 0x152e40d6bf55813L,
  47592. 0x169976327ef42faL, 0x043bc3ecf0ee5e6L, 0x1700645956ea790L,
  47593. 0x06a717ab38eafbcL, 0x103673020ed0bcfL, 0x009066a2a524eb1L },
  47594. { 0x1fdb8f4cab0f9eeL, 0x01f7816672c7775L, 0x01056a341996f00L,
  47595. 0x0d372aeee936d4dL, 0x0721ab5c642ed3aL, 0x1278699ef243f82L,
  47596. 0x17737bcbfce0086L, 0x1e57a2deab053b7L, 0x12ef05b4b0e93dfL,
  47597. 0x10fd50905e4d760L, 0x0b8b0b519fea4b7L, 0x1ec8bd667c68cdbL,
  47598. 0x168f0103cb758daL, 0x0df01218533d6cfL, 0x10152f0547da4eaL,
  47599. 0x066ddaad3092dd6L, 0x03e8ef1677e7019L, 0x0010e7e8b3fef75L },
  47600. { 0x073715fdf5c36f3L, 0x1ef1beb25692a2eL, 0x1443cb3ddc4dc0eL,
  47601. 0x0e1e732790aa6d1L, 0x104ae4ca1e5ec7bL, 0x1dd8c5fed8b3bb1L,
  47602. 0x0f568363dc5f8f4L, 0x16aa4ce0e7ecc68L, 0x1faeb52ef156008L,
  47603. 0x0bd6afc91252387L, 0x1b8e47b4aad46aeL, 0x1caf32e860595f0L,
  47604. 0x17fd0ae28adc0c7L, 0x1fc76ace6447d40L, 0x04a2eda01f08b7eL,
  47605. 0x12b46bbdb8463d6L, 0x18e71edcd9ca205L, 0x003932da3639e7bL },
  47606. { 0x1dd99f0bd66232fL, 0x157c4e2013b8b39L, 0x17e96e183f13166L,
  47607. 0x14f5287e775f04dL, 0x123c428d239ea8aL, 0x19dcad07070d8d2L,
  47608. 0x1d4ed57a838e9a5L, 0x03fd47339544aaeL, 0x0f8adf72f06957bL,
  47609. 0x1c4f9a09de9a181L, 0x1c9f43e290ea5c0L, 0x18115b5ef2de667L,
  47610. 0x1b49c12aa2cd9c0L, 0x1d056374b6e6524L, 0x110203b76237bb9L,
  47611. 0x1e97b1e8eaeba0cL, 0x16c6e9d667d0cc2L, 0x01b62baa598e8a4L },
  47612. { 0x120046ef323d84bL, 0x088913f3c4e27c8L, 0x1d3a486e01569a6L,
  47613. 0x1500f32e9c961d5L, 0x140f8c796339844L, 0x16f7a4e482a3353L,
  47614. 0x192e8706343df35L, 0x18aa52fb4d69647L, 0x11c09dff3c41800L,
  47615. 0x02483ad9bf7b3bbL, 0x10e9014144f7b5bL, 0x05d2d6162e0b529L,
  47616. 0x14c48af5ae3d674L, 0x04ac116f603c224L, 0x193653d030054cbL,
  47617. 0x0bd6b45bb5bcb82L, 0x04efc8a8ac9a297L, 0x0037dfc308ca34aL },
  47618. { 0x165338e3f45aa97L, 0x1ac640e8207f596L, 0x166c3f7be2e760eL,
  47619. 0x15c9ae82f80bfdeL, 0x130a1a237beb071L, 0x12de81cc15b0fadL,
  47620. 0x1afcd317ca8abedL, 0x14bc815793ab97eL, 0x0422c326df06612L,
  47621. 0x090f34ecab8d714L, 0x02c42c8f4d0d3b2L, 0x12af3b40f266f91L,
  47622. 0x013619cf4d96d2eL, 0x0caf77d0c19ea35L, 0x0fa3c3b6746594fL,
  47623. 0x0b56254fb082340L, 0x1ea5e64295304bbL, 0x02f4e507e8f87d4L },
  47624. { 0x1d54571197c5dc4L, 0x1205ff3c54ad12dL, 0x1bf3ff6c3acb8b6L,
  47625. 0x181a2e8cf8cbf73L, 0x0758c6a3e952dc2L, 0x01a54d60fe4e3deL,
  47626. 0x12d5bf1e558b350L, 0x1164dc6df7cc3ecL, 0x06adc4b9e1e8472L,
  47627. 0x18b2fe9d47cd645L, 0x04e9140f8f804dfL, 0x0a26cac8f1c6f79L,
  47628. 0x17064ddc77eacc5L, 0x1b49b48a699c8b8L, 0x0909299d6cc6371L,
  47629. 0x0be68d363e38e6cL, 0x0f88cc2045b4995L, 0x04a031159e341b5L },
  47630. { 0x110ccb70d997973L, 0x0b12ee9fc788aa3L, 0x13556e5eaf54ecaL,
  47631. 0x14ce7c294b19e18L, 0x1d262246c6321e0L, 0x041d8882a0d7ce9L,
  47632. 0x14a9379b61d51bfL, 0x16c8fd2fb51e02cL, 0x00f82b3a6ad9802L,
  47633. 0x0d5203ad74e2259L, 0x1d778b3b4afdddaL, 0x151492f481b55e7L,
  47634. 0x083c23ba9c1ef1eL, 0x18c851641707c30L, 0x178cda362a66293L,
  47635. 0x17ae3c56939199fL, 0x1b6b9f49824bde6L, 0x0405d8b323c2df6L },
  47636. { 0x1e575fefd145cb5L, 0x172b0d62f344182L, 0x033e1e4ec9cc557L,
  47637. 0x1c267646708c3ceL, 0x02a7ba079f1553dL, 0x18437d17dcf061dL,
  47638. 0x12e4f0eff5aa0f9L, 0x17b6d750a011769L, 0x10b66d78976f82dL,
  47639. 0x0ad37fb2a75a4ffL, 0x1748dc7c82cc89fL, 0x1384a9c539b99acL,
  47640. 0x03cb118ff979ea4L, 0x062c0005b24bacbL, 0x031de725a566377L,
  47641. 0x0b46b2a20f23022L, 0x150edfc154863b8L, 0x003bdd2f5209091L },
  47642. { 0x13a38d3cdd86f61L, 0x10a228281505585L, 0x171601b409c90c4L,
  47643. 0x111465e21e3225dL, 0x0e80c76001dc1f9L, 0x127459dd8e98e88L,
  47644. 0x127bb51bb1f97d1L, 0x0efaad35e6d357eL, 0x09d286ea72cdadeL,
  47645. 0x1f38106a2d6ac90L, 0x148db98a66b9fcaL, 0x137ba7eab80f57cL,
  47646. 0x1a52350e80c9317L, 0x17f83ac3409c4caL, 0x1ce594c24049972L,
  47647. 0x0fa42b6790365e8L, 0x0e2baf7581d9bc7L, 0x03590036fa2c8d1L },
  47648. { 0x0fe50a8965b1bc1L, 0x1a9b54b15da7ed9L, 0x14cc0039fe664c7L,
  47649. 0x0aa7aa24bdaae31L, 0x12125caf84728f2L, 0x1fb3cf27c530c26L,
  47650. 0x1016953c69c04d5L, 0x0eae153e8182a63L, 0x110d0cb976fa8b7L,
  47651. 0x03b7a0f4ee09674L, 0x15e9d49d57e252dL, 0x1c20c4ae8348b91L,
  47652. 0x18c917b16cd6c12L, 0x1c6b5850131537dL, 0x10e3a0c93445b98L,
  47653. 0x115f9092a818065L, 0x150855b911c6686L, 0x02990bf535e935aL },
  47654. { 0x0840473259f52b4L, 0x0d4e5f3108a367eL, 0x017b2b2f49ba5a3L,
  47655. 0x1bc94a86892c9d7L, 0x181a4ff7ab7daa2L, 0x040af7b6e1dc241L,
  47656. 0x0c78681ea5acd07L, 0x15189f5d3d187a9L, 0x10f938d1e42ce9eL,
  47657. 0x193ed661ae60297L, 0x180727a681bc1e9L, 0x1b9694dacb43903L,
  47658. 0x136044a9a6a9e08L, 0x195e94adfc7168bL, 0x1e06c4a6624f743L,
  47659. 0x01585411a66f3f2L, 0x0ef64bd60016183L, 0x001c3498f6cd6dfL },
  47660. { 0x0d7abb3d09885a5L, 0x095b3f1aadd83e8L, 0x033d4dbaebb7b67L,
  47661. 0x10d339c9ac77847L, 0x111594cd61ca2e7L, 0x18b5691aa7fa238L,
  47662. 0x1d711572f9c240cL, 0x080830cf3fa93ffL, 0x075bacd750f9c6cL,
  47663. 0x1bf6e4414b9390dL, 0x05a21f97bd40bd9L, 0x06cf7e641c1d04bL,
  47664. 0x0f8bbdccb2459e9L, 0x1bb3431ec0e71b7L, 0x031b6e06e825ff2L,
  47665. 0x0e9179a7443adabL, 0x0200e4967cdb4a8L, 0x016557ba48a820eL },
  47666. { 0x0f980066ed20424L, 0x0751191238aa2a2L, 0x0695e06a321acf9L,
  47667. 0x0af5cb6e164d1daL, 0x156d398248d0ab7L, 0x198fd2365459901L,
  47668. 0x173ca73a39a04b7L, 0x1bd7213a465b24bL, 0x1302c8f78f56723L,
  47669. 0x0b92eb4d5d64b7cL, 0x091f295f4685c04L, 0x0a23831457cecadL,
  47670. 0x11ad50d9d96bb5dL, 0x18582a8c5ab722fL, 0x163fe44dba21b89L,
  47671. 0x06c3d8f8e3e7a13L, 0x1d865a1bbe29350L, 0x0436bfa9922ff1dL },
  47672. { 0x1f16eb6b0bf719aL, 0x1a84c45e1ec89ccL, 0x19489b3406d2da5L,
  47673. 0x0921131a39f5ca1L, 0x087ec666d3e3ac5L, 0x1522dc26d1dcedcL,
  47674. 0x0c16160c01913efL, 0x0266d3e77b306abL, 0x10fb239a8579bccL,
  47675. 0x1ada29cb715ec08L, 0x1ceebc90663f493L, 0x0db7106faa3a00fL,
  47676. 0x02eae75b1668a67L, 0x1edb041e3477753L, 0x00db1697ff97e50L,
  47677. 0x1ff0aa5929a1efbL, 0x0dd5a4c3c6fcbc1L, 0x034152af1c3605aL },
  47678. { 0x0f235a4587495aaL, 0x101361a63922ee4L, 0x1316dd691b8c89dL,
  47679. 0x0bd987cbcfad5c1L, 0x14296629890d396L, 0x03b9138d899a178L,
  47680. 0x09a2f22649f9a2aL, 0x0342a87e4fc4649L, 0x06c44768449cdc2L,
  47681. 0x1e3fea78a296856L, 0x0c28c7fd2c11726L, 0x0d410a5eec22598L,
  47682. 0x12c6fdd7a6415d4L, 0x1da63e48d6b9b82L, 0x0235c3373b30eadL,
  47683. 0x0720ba59be036edL, 0x1cd054f2542e40dL, 0x001113fd37f7f26L },
  47684. { 0x005efd9b751948bL, 0x176a37efe912e8cL, 0x18253cb22c8a3bfL,
  47685. 0x1f2def8bcb96251L, 0x14cbeca09d1090bL, 0x04658204ace8225L,
  47686. 0x13f38872557e638L, 0x135783e4f3ad1f4L, 0x0b021e14e0710aeL,
  47687. 0x068b74fc408b3faL, 0x1708baef27c6959L, 0x0dbfc6841dd5eb4L,
  47688. 0x15d5c4e8435f371L, 0x147fdd40cb8f5c8L, 0x14dd5e193f157f0L,
  47689. 0x18fa0684fca9afbL, 0x178446e6a6215ebL, 0x02a3f124d14934bL },
  47690. { 0x106868aa1ffda27L, 0x166e63caae7a823L, 0x0784298fcf62d39L,
  47691. 0x153bcbce15eca2aL, 0x193428235b4127eL, 0x17bea89e9604dd7L,
  47692. 0x100946326760ea8L, 0x19d418b763bbbddL, 0x07ffddf8403dcf1L,
  47693. 0x0bf2694b0b7ef6dL, 0x1595a5e4ca87c39L, 0x01d06323a9c7a48L,
  47694. 0x01c220218b7475eL, 0x05e592829a3cdf5L, 0x184cb9bf3ad7242L,
  47695. 0x183d638d0b9d478L, 0x0eac42dc745bfe6L, 0x022d20e60695847L },
  47696. { 0x0a9b2c74dbbf0e1L, 0x1cb17d0be7b871fL, 0x1d617bad319907fL,
  47697. 0x05537d62fdb83d4L, 0x0285741a4f5412dL, 0x07e88f964f27a95L,
  47698. 0x0613a4f7df69261L, 0x0eb655f7bb81be6L, 0x096323d252421e3L,
  47699. 0x03df0f224efbc0fL, 0x1807b4f5626fab2L, 0x137a51ffedba28aL,
  47700. 0x148a0f298c0f0bdL, 0x0c4734a216992ceL, 0x0b0abd8d8b5e9dfL,
  47701. 0x1b40550980d6d6dL, 0x0c8ba850ac9d087L, 0x00943b1e4a17720L },
  47702. { 0x1a80f07acbac178L, 0x100221a5847b714L, 0x1451c3fb7b49f30L,
  47703. 0x070cc2aecfd2c63L, 0x0b088548b2115daL, 0x174701be3afae26L,
  47704. 0x05d496ca7484e68L, 0x179fd3fb4cd1710L, 0x13f1d8d88c1de7eL,
  47705. 0x03b2b2f0190c091L, 0x195586c72657cedL, 0x1631627d6e360e6L,
  47706. 0x1399b3a0eb2160cL, 0x1907e6ba3f46d28L, 0x049b5c97a3287e6L,
  47707. 0x0c6fed4fc00cf68L, 0x0d21e8204b768bbL, 0x03af4b5e67e27baL },
  47708. { 0x09d1fdc0d19716eL, 0x0282c3e1c22928cL, 0x1b47aa61f4ab7d6L,
  47709. 0x06d80e2a1ec9508L, 0x0d6fd5b712b6bf8L, 0x09faafc8ec2ea32L,
  47710. 0x044a6a5e220d93dL, 0x090c01077b102a1L, 0x1a7672683ea876fL,
  47711. 0x005973d60ad9244L, 0x1be3490b47664baL, 0x00539e7bc92530bL,
  47712. 0x1cb14876279c57bL, 0x0572db43ff017c1L, 0x1ae065abae93f92L,
  47713. 0x0a47b150de136baL, 0x149d88f566ba16eL, 0x0184d374d5d1344L },
  47714. { 0x127ee50bdfbe97aL, 0x1f387dc628626f7L, 0x0c05ff827d70697L,
  47715. 0x0b7da6d98b98f7dL, 0x1550ed3a8fa15a8L, 0x084340e061d66dbL,
  47716. 0x1732f1607be1faeL, 0x1d142b666c5893aL, 0x00fbb17141fa264L,
  47717. 0x13fc6c7c70f7744L, 0x133f58870ad8f49L, 0x1cfaa77cfdfba63L,
  47718. 0x1fdb2a358a924dbL, 0x1aeb4560ea1743bL, 0x13fa9573e59cf1dL,
  47719. 0x16405c6b2f1fae2L, 0x189eeb366535769L, 0x0022c12c56bac9bL },
  47720. { 0x1f71a74a042dbdfL, 0x02c2babbcefd12eL, 0x0e9c34b9995cb50L,
  47721. 0x0b945d125c1ccd9L, 0x0f0e6b5f285d674L, 0x03b3e1fab546f78L,
  47722. 0x1ae7383ba14768cL, 0x0853180acb08668L, 0x0b35fce26d6b3c7L,
  47723. 0x044adff9cbbbf00L, 0x03da9b9edb621b0L, 0x10869e052097079L,
  47724. 0x1b2e84ec34bee14L, 0x0b6884c8bfba48aL, 0x07eb302eabd98f2L,
  47725. 0x1805200970eafc8L, 0x158a2b880e56f86L, 0x029fa51f04adbb9L },
  47726. { 0x1bb08ce89fc48e7L, 0x062bbd7d5ad7588L, 0x0fe283072d6ae98L,
  47727. 0x14f2eaf96de0d79L, 0x163191607d2efaeL, 0x1bdbd4f136c858bL,
  47728. 0x1cafd0aa86ad8adL, 0x1e071dd819a50bbL, 0x1d35947f5f3a8f7L,
  47729. 0x1e46e077e0e5adaL, 0x0332831161173e5L, 0x1312493c4de5fd7L,
  47730. 0x0d483ed89a16e8dL, 0x08ec8839be13273L, 0x17a67c04e8fc515L,
  47731. 0x1aac70a02ac5c60L, 0x036aaf98d746908L, 0x0054cf329eb91e9L },
  47732. { 0x1536f46abbc0559L, 0x1833dcd50d0b011L, 0x08a4305a06d7058L,
  47733. 0x0226f1d20e453faL, 0x0b793a2d61254beL, 0x12a96de307fabd5L,
  47734. 0x028da9bcb7e2d19L, 0x13535a63127182eL, 0x1c5cd9abe29b74dL,
  47735. 0x1ba3939fbc24291L, 0x1aa4e83438c18f3L, 0x03c68491c7b1824L,
  47736. 0x0e8323ddfafe202L, 0x19931cf3ecb9a1fL, 0x0c955227dda1dd4L,
  47737. 0x1efd52ca1f862eaL, 0x1c0b595dbd13eebL, 0x01d4ae5a28087e5L },
  47738. { 0x14e68cb39d7ff2eL, 0x0e5a5e0eae247caL, 0x11ddc5a50e2a374L,
  47739. 0x012395b19c05525L, 0x12cd08d27965c0bL, 0x0815ed062bcc559L,
  47740. 0x14860696f0f0e9aL, 0x1b6a8ba124aa30dL, 0x0f0077cdbd27e64L,
  47741. 0x0abe5524668496dL, 0x1e8e80914caacc0L, 0x073683995746545L,
  47742. 0x014744aee6a5fb6L, 0x06dd49ed00b816eL, 0x05e13c5216ed0dbL,
  47743. 0x0e58726b2fecc65L, 0x0455d713c1ddad6L, 0x01b3691170185b9L },
  47744. { 0x10b4875573ea5b2L, 0x1200dd486d226eaL, 0x0995e8680c403f3L,
  47745. 0x0b9e2288c0f6a7fL, 0x0538bf49722a80aL, 0x15669085c75f82dL,
  47746. 0x141f6b850451f4cL, 0x00ecd24e258f6b5L, 0x06dc5fee73f48caL,
  47747. 0x0768a4c95c53c6cL, 0x0cc51774bc5d666L, 0x1bc2bf2e371c9d1L,
  47748. 0x1dadf1b36843408L, 0x12c995bf02af536L, 0x0224ff52eddb9cfL,
  47749. 0x17fb48850e2a7a6L, 0x125173dccd20661L, 0x048395d4cbcef7eL },
  47750. { 0x14de4dd9620ea39L, 0x0b24fe418e77423L, 0x0ec734ea710fefcL,
  47751. 0x1e7e7be3aa161d1L, 0x0f0ec9b36a38286L, 0x0e04f1a7683959cL,
  47752. 0x0890a9b93261dcaL, 0x175d47d158d15a2L, 0x06ae0e22bfbdfa5L,
  47753. 0x10b8f67d8507ac9L, 0x0a21b5ae1c7e355L, 0x1d526bc237b4676L,
  47754. 0x007f0f153f6b19bL, 0x1eb6017726c0ad2L, 0x0a23d19f982365dL,
  47755. 0x02ca8fd1e47b36dL, 0x02926ac9652439dL, 0x046c9635e9aaa36L },
  47756. { 0x1e0d7ceabeb0ff7L, 0x1a92a1f07217c59L, 0x089b7a021267ef8L,
  47757. 0x1e39a89786afa36L, 0x035cfee19ece2e1L, 0x1fac0e0922d6de2L,
  47758. 0x0e51e1d3ba103e4L, 0x01522d4ef397b41L, 0x0abcc815afa57aeL,
  47759. 0x1d6f616f85310d8L, 0x0940ae07e42f725L, 0x1bc2a77bcc7b7cdL,
  47760. 0x1f78884c2554bf9L, 0x05ddaa385447ed5L, 0x014fbd4c2a94ac7L,
  47761. 0x04fd5f00a72d852L, 0x1c08d43d8988dd8L, 0x02725f60bae0d72L },
  47762. { 0x18483a2fcc09676L, 0x0251f8cf54d4a5fL, 0x1bcf5c0a977515fL,
  47763. 0x05087fcfb14d0a5L, 0x16e35158e7915fdL, 0x0ba3783225dd4c0L,
  47764. 0x1c2d6346e57427bL, 0x0bc8ee08b037215L, 0x10bd4bc6bd4fd13L,
  47765. 0x16e7033da7419d2L, 0x1a3cc3fd5aa6869L, 0x1001d858c7fc581L,
  47766. 0x0598f508a8a9c80L, 0x1949409d224e105L, 0x1fa06880ae532ccL,
  47767. 0x0eceec8fc7a51d8L, 0x12472e67d1ab487L, 0x03d2551fab7cef6L },
  47768. { 0x19ef1bae27a0045L, 0x096a7d92165a82aL, 0x0390e73e3493720L,
  47769. 0x0b367f38a84748fL, 0x0ffa1fcf97544fcL, 0x11641dad6340995L,
  47770. 0x12eddd3e3fb80d2L, 0x14d2d98c81f9a7eL, 0x0775dce9db0512eL,
  47771. 0x1ee50cee6e71c0fL, 0x1acfcea74ff9559L, 0x1e8434324e9f83dL,
  47772. 0x1428d69b1238e0bL, 0x0fe84efc0acc97dL, 0x06ad77d23f3af7aL,
  47773. 0x0d38bb93bf49f68L, 0x1e10cbd7dc8c0a2L, 0x03014153dfbf856L },
  47774. { 0x007e538dceea2e7L, 0x191641e21030ebeL, 0x03e53c7d9458e28L,
  47775. 0x178eeed420ced05L, 0x15e6b405f21b69fL, 0x13db21631d1a0bdL,
  47776. 0x051013267c96246L, 0x19a70d25950595aL, 0x0f1e82ffe00869bL,
  47777. 0x185b8a70b7f2335L, 0x1d0be4640644e30L, 0x0da01f4a2d5cbf6L,
  47778. 0x0cd8c73a43e9016L, 0x1de2e1b92aa87bdL, 0x130e7b4b5a901f7L,
  47779. 0x17ce1c8f4ea72d1L, 0x1423fd286d94a5fL, 0x02fa574e391e35cL },
  47780. { 0x16a2dda53f4d561L, 0x0a2e80b6d0cc96cL, 0x07eff752c144a1bL,
  47781. 0x1b3e432bd489340L, 0x037661b325488a0L, 0x12f701620a8d855L,
  47782. 0x0205ee6311c7be7L, 0x015497950dd50cbL, 0x1bbcadb877a68fcL,
  47783. 0x059a324b5b9b354L, 0x1a6350559870b62L, 0x098d9202841865dL,
  47784. 0x152f2752aff5b3bL, 0x088726ce511a939L, 0x092aa00bd9339cdL,
  47785. 0x14a072734fe4d59L, 0x1d29cd3e291401aL, 0x049500a11ee2357L },
  47786. { 0x1f24be11c2f7dbdL, 0x04807dbea93fd74L, 0x16ee1923c4a36a3L,
  47787. 0x04902832832c7c4L, 0x1a6756fb9ab713eL, 0x06c85ef43fbe80bL,
  47788. 0x1aaf49d37617816L, 0x12b047fdcf504acL, 0x09f6230d7742401L,
  47789. 0x02bcf96565af237L, 0x09898c5a9321f81L, 0x1487b33610ae544L,
  47790. 0x03e488789e9ca19L, 0x0a0361dec36e15dL, 0x18255fbe582d6e6L,
  47791. 0x0a2b6de58851712L, 0x19b90748706161cL, 0x007e47f0f554465L },
  47792. { 0x0ae1bedfeb90f2dL, 0x1dd9e52458aacb4L, 0x1e73d93a58d7ce4L,
  47793. 0x01f17ceb8457cc5L, 0x1e6f7529354c241L, 0x165598debf5381aL,
  47794. 0x1cfff09921a3858L, 0x0fd62723ce190c1L, 0x1df367c751d8983L,
  47795. 0x0a85b5a15f994a0L, 0x03d1b9e304c63f8L, 0x1b57458962c12bdL,
  47796. 0x0e701afbf32b3f1L, 0x0f443a62e3667aeL, 0x11b72f8eb49d4c1L,
  47797. 0x125ba7250bca2bbL, 0x09f3c954d86d998L, 0x01685d4316fe9bcL },
  47798. { 0x0cd8ee8b472e1afL, 0x0a7575bb55de675L, 0x0fe34364fef7acdL,
  47799. 0x0ffcdf8e0d36a41L, 0x04ee2f39fccd60dL, 0x00f28f549a9eef5L,
  47800. 0x19ddd7ac2497a6aL, 0x0d3dc669b43a26cL, 0x0c1d28c9fd5354dL,
  47801. 0x0bb8baac952f6aaL, 0x18d9fedfdc3606eL, 0x1d9552675cf4ba7L,
  47802. 0x19e23cfbb77be7eL, 0x04a4bb40932678fL, 0x0d88d6c344a7d2aL,
  47803. 0x0edb4e0a6eb4813L, 0x1fcccf64c7548a3L, 0x04b1e438926a0edL },
  47804. { 0x0e290cbde36a814L, 0x180cab99d895addL, 0x019fddff83866f6L,
  47805. 0x1a52e419d41d75bL, 0x1029ec720a7d19fL, 0x08c88f21a6bb28cL,
  47806. 0x1fd8215abfc5eedL, 0x00da144bb35b014L, 0x0ffca86aff848c1L,
  47807. 0x1f45efca1d6ba4eL, 0x180a138f9a5aed4L, 0x0615dddc842bf73L,
  47808. 0x1e2ecf3c633eb66L, 0x070060604ec7ddcL, 0x15efab1c7693fe9L,
  47809. 0x18fdf652d7cb2baL, 0x1bd1751fbada8ceL, 0x01681f59e7faaebL },
  47810. { 0x116925f04f2ec1dL, 0x0793b068a3f7175L, 0x1812ab676782a1eL,
  47811. 0x167ee206b6885beL, 0x0cb95d5b891df44L, 0x147691e1413959cL,
  47812. 0x1cf8dbc53bed57bL, 0x0bde7888c1e2761L, 0x0889f9bd76bd733L,
  47813. 0x04f73b8fbaadd37L, 0x0613fbb4866db22L, 0x0e6fd85dc822c4dL,
  47814. 0x0263efcd372d44cL, 0x131bc135dca1c2dL, 0x19ade9f6424c86dL,
  47815. 0x0c36f849f14f27dL, 0x0d9a3ca8d24a7cfL, 0x042172060e2a5d6L },
  47816. { 0x0268ed6a661d843L, 0x1466527ad9866adL, 0x1b444c4785dc08cL,
  47817. 0x098cd2b2ce2dcdfL, 0x17b2e280690decbL, 0x1f21685ed62dfb2L,
  47818. 0x128be09fe0b287bL, 0x00d8aa9d81594bfL, 0x1ac5276c1dde455L,
  47819. 0x1fa65847183ba89L, 0x1db66b321e5f32dL, 0x10281b2665a5195L,
  47820. 0x17285a409fd5964L, 0x1111e849e635714L, 0x0a3f025ddcf0a95L,
  47821. 0x1fcd85aa4cd58a2L, 0x128a596b7cbbc31L, 0x0073198cd656489L },
  47822. { 0x1cd2fadf0360ac2L, 0x1306f142f302d5aL, 0x1c43896e6c521adL,
  47823. 0x1b55358aa9058d9L, 0x126c070e9d5fa38L, 0x0662969efe78dc2L,
  47824. 0x11fd40de6a5acffL, 0x143c6cb385217f9L, 0x15b1a3db569d3e6L,
  47825. 0x00a945acdbda16aL, 0x17be92708a801adL, 0x00313699c76d269L,
  47826. 0x04b3abaf3290f38L, 0x1fc1c4f15839de0L, 0x0968d6c9e96888bL,
  47827. 0x14f8416f53aa3ffL, 0x05a4939ecef28e1L, 0x04441ced10c3938L },
  47828. { 0x0b66c30701ce29aL, 0x178932c4c0ea82bL, 0x1030417e7c84eb2L,
  47829. 0x0c6e7c7a27a9b5fL, 0x1a2ee3cafee571eL, 0x101c2d73934e437L,
  47830. 0x1a6b3d732992b74L, 0x1de42fe4eae6001L, 0x0c934db470e7273L,
  47831. 0x14a7a7b9aadb3bbL, 0x08dae5bf0146010L, 0x03b760a432163f5L,
  47832. 0x10e9eaef528f88bL, 0x0db40dc81abc8dcL, 0x0570da7cdfecbafL,
  47833. 0x0439273a14a3a88L, 0x026fc59cca71d2eL, 0x03209467f50fa86L },
  47834. { 0x03678a2e8f5b0b5L, 0x1124e69a0782cf8L, 0x11064f29f3b171fL,
  47835. 0x0d79075f3082880L, 0x1aa8bbb0075ca34L, 0x01187bf9cf8019fL,
  47836. 0x1cd14f463c3b7ceL, 0x0eaf1bfe019a891L, 0x1849228c0d51aa4L,
  47837. 0x0a7138418649468L, 0x0e9a1a3c4b3f4f7L, 0x13b71167440d8cdL,
  47838. 0x19016dae0109104L, 0x1129f1beec32e82L, 0x1a61c6d1667a417L,
  47839. 0x0265c6459e184f9L, 0x1da014f54da174aL, 0x049b1a504ded5e5L },
  47840. { 0x0826b27a9a2e304L, 0x10c3360d2609231L, 0x00c888e05c4315fL,
  47841. 0x0b5308f9fd22757L, 0x0b5f46fd7e9b6b8L, 0x1c733694b2ae789L,
  47842. 0x17aadca555cae00L, 0x103c9974c02df52L, 0x0bbc11071b9dedaL,
  47843. 0x1f8004d1f8e7b0fL, 0x09ddecdcf833ee5L, 0x0139a273ac76a6eL,
  47844. 0x1a4f87d78e302f9L, 0x1a0243b18f6b396L, 0x1308ac8d881de8eL,
  47845. 0x1ddcf8811865b3bL, 0x17e4b4c5bf226deL, 0x013365a33de031aL },
  47846. { 0x1aa4154b56363e8L, 0x1e83c1e0d526db7L, 0x1778ae79965d2d3L,
  47847. 0x1df4009708286b1L, 0x119911a65b34ae3L, 0x1b5fbc67a259767L,
  47848. 0x17255572aa0ce94L, 0x03ac0dc3d7310e1L, 0x0e3c3287d09f351L,
  47849. 0x0597a75ceae79b2L, 0x13a2498eae3279aL, 0x051d86d56c2382aL,
  47850. 0x0ba1b7d12015488L, 0x098adc6b84995feL, 0x11ceb05fb9ed6f1L,
  47851. 0x055e6f05fa1a3eeL, 0x0e1bcb029a83c8fL, 0x0258ead0da922a7L },
  47852. { 0x0fe517463d52c0cL, 0x0a92f0c4604ce89L, 0x158cd838e558dcdL,
  47853. 0x1559f4b486b8c42L, 0x197e810788b3f1cL, 0x0f040548091d053L,
  47854. 0x16b6ae8c7dad6c5L, 0x191afbcbc25f947L, 0x03287361b0df511L,
  47855. 0x064006a32babea7L, 0x043cf5481fb245fL, 0x0de261dd41c6210L,
  47856. 0x133ea5a2ec0d4e5L, 0x1f355de85dfbf70L, 0x02fd865bf01dd8aL,
  47857. 0x1a8559063fb9c24L, 0x127e07439fab622L, 0x040c35c9fa84725L },
  47858. { 0x019d15409312867L, 0x01602dfd7beda63L, 0x19a07d7d7769f81L,
  47859. 0x0f49f87b05839e2L, 0x0e68b8fe50aa505L, 0x1a6b22769876b2eL,
  47860. 0x0125fb2c0702efaL, 0x038f6bb88890638L, 0x1351e6a009b7d9bL,
  47861. 0x1dc31dceca3be48L, 0x196244175044292L, 0x19e886b016f5574L,
  47862. 0x1690be357e30086L, 0x13da90a7589ce03L, 0x10ead5c4afffc68L,
  47863. 0x137f4f39f8dae45L, 0x12a4743de57f34aL, 0x005fcbf4be4f715L },
  47864. { 0x0ec4ec8dda19e96L, 0x10c7536183745cbL, 0x04ad97da4629533L,
  47865. 0x161b341b32fd06cL, 0x02fdcc091ac6f68L, 0x1e1f09cc534bd23L,
  47866. 0x05cc1973897c656L, 0x00c312dd9b56727L, 0x19eb81a0f32f128L,
  47867. 0x1eba0b70e96e3efL, 0x11e5dab51cd6674L, 0x15353ebde873c45L,
  47868. 0x0b9e69d94e3de37L, 0x054e85e435bd605L, 0x1dbc4839afea780L,
  47869. 0x1847eaed50e1aacL, 0x0bb3bd91bb4feaaL, 0x047f2a4161f2055L },
  47870. { 0x1ae67c2ce9a4d1eL, 0x15c01a78e901c42L, 0x1ce89741864930fL,
  47871. 0x1a611f6838b8d91L, 0x071c294e803de0aL, 0x17586d4cb0fade7L,
  47872. 0x1a2db71881e37c0L, 0x11f90fdea2b6c95L, 0x169679f1e50b4d1L,
  47873. 0x0e004d0a90ccfa1L, 0x1212f83d90297f1L, 0x176247b56acd4faL,
  47874. 0x0c64275d2c4c918L, 0x05696f6b533e08aL, 0x12d723656a44ee7L,
  47875. 0x077ec313da316d6L, 0x03f4aeb6206b42dL, 0x01c946334dde45eL },
  47876. { 0x04bea4adacb4b64L, 0x115227930bcd0efL, 0x0539ea444a900fdL,
  47877. 0x1ba6de663de7559L, 0x007b85c490448fbL, 0x10dbbda130215e2L,
  47878. 0x1a6116b62965884L, 0x01a62ce949ecf9dL, 0x17fae8bbe4e3b2fL,
  47879. 0x00efb6ed3e49875L, 0x1bea6309674351aL, 0x13cd7d4383fb5bdL,
  47880. 0x0b21d405d11b14dL, 0x19c493aa1dd56e4L, 0x1c73793c077fe4dL,
  47881. 0x1a1b30386b67de0L, 0x0f61704d2e19150L, 0x0366644479aa89aL },
  47882. { 0x0d36f0e7ad7504cL, 0x1932ffbcaceeefcL, 0x1b7bfb799eaaf28L,
  47883. 0x1d75d7e65e1b9a3L, 0x014edcfc1276f4cL, 0x16c75bb412d3730L,
  47884. 0x138782e306a0a66L, 0x034624049521371L, 0x0cb8fd98b9cbd35L,
  47885. 0x04209bc7d58f45fL, 0x143d74e5cf2b3e9L, 0x09084b3aa4a82fdL,
  47886. 0x0374b91393a17e1L, 0x0d651e74a9eadc2L, 0x103e0563de4ac84L,
  47887. 0x1af7a06bfe22191L, 0x0f96afa6357ad4eL, 0x0178a8cc05937d7L },
  47888. { 0x08631da29d2d439L, 0x1dde15e01ccaa86L, 0x1e49b016dd6c487L,
  47889. 0x016d9c8fd87cb52L, 0x1d88c6586d6cf4cL, 0x1aad0bdd550bb3cL,
  47890. 0x16a140c76e79fccL, 0x1bf0703c7b015deL, 0x1c71db29015a31bL,
  47891. 0x1c7b5ba4a4c7ebeL, 0x17cfe44efbbbd98L, 0x04e3e956cf6689dL,
  47892. 0x10fd22df11e6173L, 0x102e27491d10163L, 0x1ae6483def80e24L,
  47893. 0x095543843210b51L, 0x1656c805ce8beb5L, 0x01aa582db8562c6L },
  47894. { 0x171e2367a9170e9L, 0x16216a656a866b8L, 0x093cf37733ec07bL,
  47895. 0x074cd95c35ff7d0L, 0x165c7d01a73e8ceL, 0x1ecb8f5b89c53fcL,
  47896. 0x09cac001638fd70L, 0x0dea4b235865fe1L, 0x0a32fb5bcbbbce7L,
  47897. 0x1920d5c54fc0d0cL, 0x14cccbb29a18c3cL, 0x13f88905e277e63L,
  47898. 0x17a4681be2847afL, 0x12af7e7cb0cb710L, 0x0b31c1664e3e4cbL,
  47899. 0x1f5847cfb5970e1L, 0x1a1d41be893cf09L, 0x0246e2ae2571a91L },
  47900. { 0x0623826a5092193L, 0x161b1344c4b8647L, 0x1abc9727ad0791bL,
  47901. 0x01078fa48a5e26aL, 0x17d00e384178064L, 0x090a8e4c16f7b3cL,
  47902. 0x021a4e0badb9e94L, 0x0042a9c20ef15ebL, 0x0187070758a51cfL,
  47903. 0x0f5d4fbb8989e2cL, 0x1ee5cee85564133L, 0x1e963a1af674bacL,
  47904. 0x118b8af2cd851c9L, 0x0c35c6b10cf94ebL, 0x0ee70cf2e5333feL,
  47905. 0x118d10e4bc49772L, 0x021405ce4c566e3L, 0x02fb5476e85b6e0L },
  47906. { 0x1704ca58f9a8690L, 0x14bb317bb5203c1L, 0x1631a48040a0fcdL,
  47907. 0x0d79c7499ff7825L, 0x04aab26d4cd58f1L, 0x122bd43c0233250L,
  47908. 0x05e500173eee93aL, 0x072a6f2a367714bL, 0x14ca2b9e44fe1f7L,
  47909. 0x0214566ef992bcbL, 0x168d083a890f6f9L, 0x0c57e879c03cc91L,
  47910. 0x01f27db490cce65L, 0x05fdbe784207821L, 0x01e5f4c55b32dc2L,
  47911. 0x029773666901ab5L, 0x1ac2e12e07a9eb8L, 0x00e532839653fc3L },
  47912. { 0x1b321cf2b9d25a0L, 0x1fee52053a36dfdL, 0x0c39678da2d59abL,
  47913. 0x08fb000d1f8382aL, 0x1647dd6856ed1eaL, 0x1bc6d44dba6c7f2L,
  47914. 0x0ce44765ad41e26L, 0x0be736ea487177cL, 0x0ef8d443e0d858cL,
  47915. 0x0e96da4cb23551aL, 0x14ef47999d50f13L, 0x0180d130130aff5L,
  47916. 0x1249facabad0d71L, 0x0a7cd0c94fbd7f9L, 0x0cc1e841577b070L,
  47917. 0x1fec9594cc7323fL, 0x0eeac44fd9135ffL, 0x0231657db65d69eL },
  47918. { 0x060a647de3237ddL, 0x19ae6415c3a020bL, 0x1d6777e957e257dL,
  47919. 0x1ce4d72295ef0f3L, 0x1c93e29815ef043L, 0x18c1988c3a9c9e8L,
  47920. 0x084ae868af9d1bbL, 0x0fe9cfd1bf84b53L, 0x1dfefc97da9c391L,
  47921. 0x043ae8185175f20L, 0x1748d69ccb4732fL, 0x0ffdb3754da61eeL,
  47922. 0x0b65f4857606feeL, 0x089fc1e0553c27dL, 0x03e744c8c557889L,
  47923. 0x1d5fba5f6ee307dL, 0x0082a291503b546L, 0x00949e4c6366c9bL },
  47924. { 0x078125149d53b77L, 0x1a01ecb757d63b9L, 0x1f6d28dadc469aaL,
  47925. 0x110fcee3836faf8L, 0x13b375228238c70L, 0x03a986a4afb55f9L,
  47926. 0x0446ac2c0a27232L, 0x13d9507970dcef6L, 0x1be1c0fb8a1bd18L,
  47927. 0x067d97d8d74ebe3L, 0x108f1525030fa16L, 0x1c82e95b220fa0bL,
  47928. 0x05064e714216e79L, 0x1efeb0a7d0523f8L, 0x11a622f1a4a7353L,
  47929. 0x11f63db64b09872L, 0x0ba73e4b5f3e46fL, 0x029dbcd50b4754aL },
  47930. { 0x16fafce44bbb6a1L, 0x0ddd033c10b9410L, 0x0cc2a7764e6b4e9L,
  47931. 0x1be33df5fdde3c9L, 0x1b4ec014022eaf3L, 0x16339c7f6ad5e73L,
  47932. 0x02689925a3b9944L, 0x00a462330d253fdL, 0x00d539d8d47397cL,
  47933. 0x0005e2a11a2cb62L, 0x01fd614d1984759L, 0x120793abb41f725L,
  47934. 0x17c83af2a804099L, 0x1940a8f0f2f7a4cL, 0x10044132277006cL,
  47935. 0x0593a2a1f6952b0L, 0x03340a6f7d5f387L, 0x041486b68ab6174L },
  47936. { 0x04637c6d8546946L, 0x1a51cb4f62bfd7cL, 0x06935e2401fb684L,
  47937. 0x1c1b8f7013a846bL, 0x0d6784a9b42557fL, 0x056daff31572969L,
  47938. 0x1f29689c532982fL, 0x02398411bcc6755L, 0x02380ed5ced9678L,
  47939. 0x135aaf4ed990b30L, 0x0b40b299d48d69bL, 0x1df3667f41c237dL,
  47940. 0x06f06a2a0851cc6L, 0x1623d9e7fe911f1L, 0x0aa613803cccb87L,
  47941. 0x05c288b3e52f741L, 0x1b06fa1d969ee95L, 0x0283778d59827d5L },
  47942. { 0x1b4eb2735bff163L, 0x05cb7f54fd4c208L, 0x0cfe77ac9f39c4cL,
  47943. 0x0b3ba387aacd59dL, 0x073075aaa2daf1aL, 0x038dac7a84853f5L,
  47944. 0x0b670da9abce78cL, 0x02d451ac67bbee7L, 0x0dd354cacbdc89aL,
  47945. 0x1f51a11ea6e5e1eL, 0x11d348de764b477L, 0x0adf1ddacecadddL,
  47946. 0x03fa8feb1fe14a4L, 0x1cc7e5e3fd5f3baL, 0x069c1b8501333e2L,
  47947. 0x18cf0d99a5f7feeL, 0x144daaf3fdb4d85L, 0x020adbedf8a9001L },
  47948. { 0x10105867d8377a7L, 0x11eb465c019394bL, 0x0a27c0e930c81a2L,
  47949. 0x1b2791e521facfaL, 0x09e5a2b84bc7095L, 0x15cf9db897d09e7L,
  47950. 0x1530bf1ab1b183fL, 0x00219b46db2dc1cL, 0x14549975186320aL,
  47951. 0x098c648cbf80788L, 0x1130ff9a4d9423eL, 0x1df30be0d15403bL,
  47952. 0x10a2b5511c769a2L, 0x1a0917029a91677L, 0x1d750fc01a597b6L,
  47953. 0x03ab3f9c1f5f982L, 0x19d525dc9bdec83L, 0x00f618a78d7ac43L },
  47954. { 0x063feef2c8310c2L, 0x10a6d22bf1fba03L, 0x03f394d1a21ea9fL,
  47955. 0x1ec6fd858a72562L, 0x1542f8dfcde4a38L, 0x0f0b88a83b99905L,
  47956. 0x06f18d04c0be7dfL, 0x0de031638c75c97L, 0x0f001c46edd2f9eL,
  47957. 0x1dd854b937667d0L, 0x06e675dd1b831f4L, 0x0defeb0eb5d9526L,
  47958. 0x1c96939c82e0c8bL, 0x1ef2d3325d9978bL, 0x0afe9add944d748L,
  47959. 0x00bbce326d968a5L, 0x188ad5cc08f2dc1L, 0x00bf48e893fffabL },
  47960. { 0x092ced3b7e051caL, 0x06a7e8ce3bb6a5fL, 0x0d480219e12f191L,
  47961. 0x0f9d3ad66391569L, 0x1289e9c73ea6622L, 0x150cf71ca924d1eL,
  47962. 0x16bb15142799744L, 0x01d4f7a8d25186cL, 0x1354997e477963eL,
  47963. 0x0bb2cabdaccb996L, 0x012bae47528ed83L, 0x1d483bd67c5132bL,
  47964. 0x0d572571df6e653L, 0x18c570fce53e4c7L, 0x1dee5fbcc068e3eL,
  47965. 0x141aa2c53ef84c7L, 0x001df242282afc4L, 0x008c79da59eee86L },
  47966. { 0x0a0a0a87ad4762bL, 0x1c26d462c68babaL, 0x058133ddb6186bbL,
  47967. 0x0cfcc1b3162dfe9L, 0x1ecc1dbac0be878L, 0x0b0a3d41b1bffd9L,
  47968. 0x11b970912982577L, 0x00b47c2f068b610L, 0x1735eb686e77a4cL,
  47969. 0x1e0c5a7efbac34aL, 0x06342c6f7f94bd6L, 0x181a00e2b7422acL,
  47970. 0x1ac2dd617f878ecL, 0x10db0b880edede8L, 0x1d64f08874ad8c4L,
  47971. 0x0e048459d14f289L, 0x1273b9b536a44f1L, 0x000e8533e4681f3L },
  47972. { 0x19642361e46533cL, 0x1bcc87dc461573dL, 0x145a90b12863a51L,
  47973. 0x1bb078f48a0336bL, 0x0cb663e37135e81L, 0x1606b1ba534deeaL,
  47974. 0x03699ed9fb36f9dL, 0x01407aa8a4223cdL, 0x1596cceb5d2e865L,
  47975. 0x0ab96fe95781d9bL, 0x192e87eaf5654b3L, 0x08ad69db0ad2a46L,
  47976. 0x12c950d5d47f47dL, 0x043717c22d6c5abL, 0x1aec1132b74b7e9L,
  47977. 0x011cdbaa4f6878aL, 0x00fc9adba24997cL, 0x00db12d833ed319L },
  47978. { 0x0dfaa7b4fd8446dL, 0x19780d7b7f5f5a2L, 0x0e23fa20e2d7006L,
  47979. 0x1f7752eb177e888L, 0x07156bc9f33c434L, 0x0484c595cb8e5d4L,
  47980. 0x11775ac9179707dL, 0x1af0fb96a685683L, 0x0db1f80c634d852L,
  47981. 0x0b7192c1219ed1aL, 0x008194fdf7c309bL, 0x0cf86c1966cbecdL,
  47982. 0x029826656ac4ca5L, 0x1f834bb4190fd56L, 0x01d98e44fd729beL,
  47983. 0x0e6dc2a72f2434eL, 0x08dbdf143288400L, 0x0199f654b0cfe4aL },
  47984. { 0x1337948ac775d81L, 0x128c7ea0edde511L, 0x093ef3f3a520e30L,
  47985. 0x0ca8e07fcec478fL, 0x13fb3b5baad3623L, 0x0e00f8159d09d20L,
  47986. 0x0598576cd5969fdL, 0x123ae4811b8a46bL, 0x15a17f8e51d616eL,
  47987. 0x060b775e592dcccL, 0x1a33c4ce4dd0fa4L, 0x0e95ca96c94fe6bL,
  47988. 0x0a65cd449d987daL, 0x1bf3d8aeaabd991L, 0x1344d3dd9420a94L,
  47989. 0x00e8c9a4b8e85e5L, 0x135ae9d9c074ccfL, 0x0397e1088439468L },
  47990. { 0x106b203f96004c8L, 0x1cae7a2c02affd4L, 0x019d57cd642760fL,
  47991. 0x17caa191ddaefabL, 0x15a060814a9ea6fL, 0x14103148e46654aL,
  47992. 0x1e179287fb9e2f3L, 0x0cdd735bc0d347bL, 0x1fbbdcf0c7d3de6L,
  47993. 0x1451c8dae99b6a8L, 0x1e34a170bff0f08L, 0x1bc65ef62cb6ec1L,
  47994. 0x04561770401ee48L, 0x0ef7fcd001c01ecL, 0x1f8d69395cfd922L,
  47995. 0x14d8dc344e71d42L, 0x12d238ef17c8840L, 0x02404a37c588f6cL },
  47996. { 0x0c747a8fd71f119L, 0x12e2f29f59b4ac2L, 0x1e198a6161e8679L,
  47997. 0x135631ade81c5ecL, 0x0630b8c048a4889L, 0x157c4950d4c8126L,
  47998. 0x15892125d4258b2L, 0x1a9910d3575c41fL, 0x03b72b04d6c2b7dL,
  47999. 0x13baf5b04c97be8L, 0x0701b9f41b9a138L, 0x06c3c977a00e011L,
  48000. 0x0b4ba846e4cb3b4L, 0x032326cf50d7333L, 0x1e14e7f0070bac9L,
  48001. 0x15f8ff0de57cd83L, 0x10216e8e8aecf68L, 0x046d5b0fee39c34L },
  48002. { 0x0a5c903d54d1d45L, 0x014bf7fa7cdd121L, 0x1480d351e2d2b35L,
  48003. 0x161188c4345b116L, 0x1486540235b2ba2L, 0x0f997369e91cdd9L,
  48004. 0x1f708779dabb644L, 0x0050eff179e7e0dL, 0x1802714c19ec515L,
  48005. 0x0822275d2c83806L, 0x108a7cc773255e8L, 0x0f57702d3fdb0d2L,
  48006. 0x152caf080e5ece7L, 0x05ebe778aadf450L, 0x0e5fb84fac86c53L,
  48007. 0x0d2193bdef5a2cfL, 0x1e7e03ca879118fL, 0x037bbf316fccd94L },
  48008. { 0x071bdede40bbf59L, 0x1d229b200d56b51L, 0x00d5cd5073445deL,
  48009. 0x0c96e3605e2eabcL, 0x0813359f3465b46L, 0x1c75639175b889dL,
  48010. 0x1ced65e4aa3f5bcL, 0x17e2354025ffe77L, 0x099aafabff85c3fL,
  48011. 0x0f0517783606621L, 0x15755ddcedecea4L, 0x1cedacd30814629L,
  48012. 0x132e5a8be6ae5e2L, 0x00e7aac04309b03L, 0x0fb440bb9b5d5e3L,
  48013. 0x1e1d64689c01ed1L, 0x180799d78868184L, 0x031c0ce48e1e967L },
  48014. { 0x05392e17884b073L, 0x1d0fe758933f565L, 0x17c241c0e29e7b0L,
  48015. 0x19c988f6e07a0feL, 0x1bf96b91cb2ac07L, 0x1527dffcb332770L,
  48016. 0x19403afd5d624abL, 0x008b557e723f5bcL, 0x0c5b3376f171d12L,
  48017. 0x1fb0628d069ec0dL, 0x0b3f9e5daa112c7L, 0x19357b4c24b4216L,
  48018. 0x134ebd453ee131cL, 0x0825b5e0f07e0b6L, 0x0be32af0340c669L,
  48019. 0x1368fc87417ce14L, 0x1eec80afeec55e4L, 0x033ea46894132ebL },
  48020. { 0x08d59a7ea2d56d6L, 0x15e8713a4053183L, 0x16c2b9cd9b375c6L,
  48021. 0x140e409d78d7a23L, 0x177e6293fbb639cL, 0x1d461ec4d12173fL,
  48022. 0x1e6a37b9f28add6L, 0x0208e5bb87ac945L, 0x084229df47561a0L,
  48023. 0x0fb1642e2db24eaL, 0x15ac6d37249f365L, 0x0240bdcc0b2dfbaL,
  48024. 0x10abf29401fe8bbL, 0x0868e0c21f7e552L, 0x0c077d75240343cL,
  48025. 0x087ea59e2275251L, 0x1c7a3d7ebc31f0eL, 0x013ca871c741c26L },
  48026. { 0x0b21ff0e1d0fa79L, 0x1e8198245aef4f5L, 0x1a24bf8dd32d2e7L,
  48027. 0x149d643ed699268L, 0x0925e7e7bb4827fL, 0x0a6298a338b7bcdL,
  48028. 0x1b77c510afcd9f7L, 0x11240e72a99a5d2L, 0x14e0141ae8502aaL,
  48029. 0x170070d4777b664L, 0x1a1245620336be3L, 0x14b8d2c5008cab9L,
  48030. 0x185d15dfbfff3abL, 0x0fb4279299ae627L, 0x0796f629fc11032L,
  48031. 0x04b575d008a7f76L, 0x171a1c99813ff22L, 0x02a7fbc423cd92eL },
  48032. { 0x1c6ee30de40b068L, 0x1232df379d28f13L, 0x1813e8ec87da489L,
  48033. 0x1b8083022bc4948L, 0x0df90d2b50a5a5aL, 0x186007f1942a20cL,
  48034. 0x0238eedd3963f72L, 0x1938d1e36769458L, 0x1339df0810ccd9eL,
  48035. 0x0a9b16e5bc3754fL, 0x1178c72556bab64L, 0x003b16d4d8d6512L,
  48036. 0x1c3678a427d6a2cL, 0x14649816034f416L, 0x08407985e1d5400L,
  48037. 0x1650d159b52cb3fL, 0x0fe4e4e4573ee30L, 0x0456dd6c29f8c18L },
  48038. { 0x00ae11f0969d524L, 0x1ed7bf9cde63c83L, 0x1d99f307f30bd0bL,
  48039. 0x05c466da9e79d8cL, 0x0e1c0f7f456b9cfL, 0x027d873550faef4L,
  48040. 0x12ca336f0ab4826L, 0x1de81219f4c368cL, 0x140d86f301243f3L,
  48041. 0x0d8b66666af43f3L, 0x1c5a30c09b35065L, 0x0d9702d80e60807L,
  48042. 0x1358407a1ddbe38L, 0x0b8bf0d78a75c37L, 0x12f25b3d622d3e0L,
  48043. 0x0e3836eb8834ccdL, 0x05ff342c1aa027eL, 0x039c9801b604a2fL },
  48044. { 0x14f757d22cdaf42L, 0x1ac8efa0c0d55caL, 0x0067d5453c95e22L,
  48045. 0x11e31fab791730dL, 0x022ceb9169642e0L, 0x07b4c2c95982e88L,
  48046. 0x072b85c5640f9a9L, 0x15497afad3ac22fL, 0x0dacdfd5dd29c01L,
  48047. 0x02eeead6c888466L, 0x0b1ec592b23c55cL, 0x09c36a48c65e869L,
  48048. 0x1b731fc44761a51L, 0x104b0d98a2dcf30L, 0x1abc88f3d584d23L,
  48049. 0x133a7385152cee7L, 0x1e25bd10182aa7cL, 0x045e376257214b2L },
  48050. { 0x096e5c0e7f2a32bL, 0x04006049c451868L, 0x0df10078d833fd5L,
  48051. 0x1976c0a94c0dfc8L, 0x0457aa6e6655fc9L, 0x14d95ba8870c304L,
  48052. 0x1698682b3f288acL, 0x194e64907c6a36fL, 0x1e31471ee6be6c8L,
  48053. 0x0b2a18e45b2e4d0L, 0x0b0ee5235972ef9L, 0x18435d365551f93L,
  48054. 0x0daa60aa6ad308fL, 0x0c17e06a6b53ef8L, 0x11e935ca11365aaL,
  48055. 0x112ab56025858b0L, 0x0152b3c8f71dcebL, 0x04742a1bedf4e3fL },
  48056. };
  48057. /* Perform the modular exponentiation in Fp* for SAKKE.
  48058. *
  48059. * Base is fixed to be the g parameter - a precomputed table is used.
  48060. *
  48061. * Striping: 128 points at a distance of 8 combined.
  48062. * Total of 256 points in table.
  48063. * Square and multiply performed in Fp*.
  48064. *
  48065. * base [in] Base. MP integer.
  48066. * exp [in] Exponent. MP integer.
  48067. * res [out] Result. MP integer.
  48068. * returns 0 on success, MP_READ_E if there are too many bytes in an array
  48069. * and MEMORY_E if memory allocation fails.
  48070. */
  48071. int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
  48072. {
  48073. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48074. defined(WOLFSSL_SP_SMALL_STACK)
  48075. sp_digit* td;
  48076. sp_digit* t;
  48077. sp_digit* tx;
  48078. sp_digit* ty;
  48079. #else
  48080. sp_digit t[36 * 2 * 18];
  48081. sp_digit tx[2 * 18];
  48082. sp_digit ty[2 * 18];
  48083. #endif
  48084. sp_digit* r = NULL;
  48085. unsigned char e[128];
  48086. int err = MP_OKAY;
  48087. int i;
  48088. int y;
  48089. (void)base;
  48090. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48091. defined(WOLFSSL_SP_SMALL_STACK)
  48092. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 18 * 2, NULL,
  48093. DYNAMIC_TYPE_TMP_BUFFER);
  48094. if (td == NULL) {
  48095. err = MEMORY_E;
  48096. }
  48097. #endif
  48098. if (err == MP_OKAY) {
  48099. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48100. defined(WOLFSSL_SP_SMALL_STACK)
  48101. t = td;
  48102. tx = td + 36 * 18 * 2;
  48103. ty = td + 37 * 18 * 2;
  48104. #endif
  48105. r = ty;
  48106. (void)mp_to_unsigned_bin_len(exp, e, 128);
  48107. XMEMCPY(tx, p1024_norm_mod, sizeof(sp_digit) * 18);
  48108. y = e[112] >> 7;
  48109. y |= (e[96] >> 7) << 1;
  48110. y |= (e[80] >> 7) << 2;
  48111. y |= (e[64] >> 7) << 3;
  48112. y |= (e[48] >> 7) << 4;
  48113. y |= (e[32] >> 7) << 5;
  48114. y |= (e[16] >> 7) << 6;
  48115. y |= (e[0] >> 7) << 7;
  48116. XMEMCPY(ty, sp_1024_g_table[y], sizeof(sp_digit) * 18);
  48117. for (i = 126; i >= 0; i--) {
  48118. y = (e[127 - (i / 8)] >> (i & 0x7)) & 1;
  48119. y |= ((e[111 - (i / 8)] >> (i & 0x7)) & 1) << 1;
  48120. y |= ((e[95 - (i / 8)] >> (i & 0x7)) & 1) << 2;
  48121. y |= ((e[79 - (i / 8)] >> (i & 0x7)) & 1) << 3;
  48122. y |= ((e[63 - (i / 8)] >> (i & 0x7)) & 1) << 4;
  48123. y |= ((e[47 - (i / 8)] >> (i & 0x7)) & 1) << 5;
  48124. y |= ((e[31 - (i / 8)] >> (i & 0x7)) & 1) << 6;
  48125. y |= ((e[15 - (i / 8)] >> (i & 0x7)) & 1) << 7;
  48126. sp_1024_proj_sqr_18(tx, ty, t);
  48127. sp_1024_proj_mul_qx1_18(tx, ty, sp_1024_g_table[y], t);
  48128. }
  48129. }
  48130. if (err == MP_OKAY) {
  48131. sp_1024_mont_inv_18(tx, tx, t);
  48132. sp_1024_mont_mul_18(r, tx, ty, p1024_mod, p1024_mp_mod);
  48133. XMEMSET(r + 18, 0, sizeof(sp_digit) * 18);
  48134. sp_1024_mont_reduce_18(r, p1024_mod, p1024_mp_mod);
  48135. err = sp_1024_to_mp(r, res);
  48136. }
  48137. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48138. defined(WOLFSSL_SP_SMALL_STACK)
  48139. if (td != NULL) {
  48140. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48141. }
  48142. #endif
  48143. return err;
  48144. }
  48145. #endif /* WOLFSSL_SP_SMALL */
  48146. /* Multiply p* by q* in projective coordinates.
  48147. *
  48148. * p.x' = (p.x * q.x) - (p.y * q.y)
  48149. * p.y' = (p.x * q.y) + (p.y * q.x)
  48150. * But applying Karatsuba:
  48151. * v0 = p.x * q.x
  48152. * v1 = p.y * q.y
  48153. * p.x' = v0 - v1
  48154. * p.y' = (px + py) * (qx + qy) - v0 - v1
  48155. *
  48156. * px [in,out] A single precision integer - X ordinate of number to multiply.
  48157. * py [in,out] A single precision integer - Y ordinate of number to multiply.
  48158. * qx [in] A single precision integer - X ordinate of number of
  48159. * multiplier.
  48160. * qy [in] A single precision integer - Y ordinate of number of
  48161. * multiplier.
  48162. * t [in] Two single precision integers - temps.
  48163. */
  48164. static void sp_1024_proj_mul_18(sp_digit* px, sp_digit* py,
  48165. const sp_digit* qx, const sp_digit* qy, sp_digit* t)
  48166. {
  48167. sp_digit* t1 = t;
  48168. sp_digit* t2 = t + 2 * 18;
  48169. /* t1 = px + py */
  48170. sp_1024_mont_add_18(t1, px, py, p1024_mod);
  48171. /* t2 = qx + qy */
  48172. sp_1024_mont_add_18(t2, qx, qy, p1024_mod);
  48173. /* t2 = (px + py) * (qx + qy) */
  48174. sp_1024_mont_mul_18(t2, t1, t2, p1024_mod, p1024_mp_mod);
  48175. /* t1 = py * qy */
  48176. sp_1024_mont_mul_18(t1, py, qy, p1024_mod, p1024_mp_mod);
  48177. /* t2 = (px + py) * (qx + qy) - (py * qy) */
  48178. sp_1024_mont_sub_18(t2, t2, t1, p1024_mod);
  48179. /* px = px * qx */
  48180. sp_1024_mont_mul_18(px, px, qx, p1024_mod, p1024_mp_mod);
  48181. /* py = (px + py) * (qx + qy) - (py * qy) - (px * qx) */
  48182. sp_1024_mont_sub_18(py, t2, px, p1024_mod);
  48183. /* px = (px * qx) - (py * qy)*/
  48184. sp_1024_mont_sub_18(px, px, t1, p1024_mod);
  48185. }
  48186. #ifndef WOLFSSL_SP_SMALL
  48187. /*
  48188. * Convert point from projective to affine but keep in Montgomery form.
  48189. *
  48190. * p [in,out] Point to convert.
  48191. * t [in] Temporary numbers: 2.
  48192. */
  48193. static void sp_1024_mont_map_18(sp_point_1024* p, sp_digit* t)
  48194. {
  48195. sp_digit* t1 = t;
  48196. sp_digit* t2 = t + 2 * 18;
  48197. sp_1024_mont_inv_18(t1, p->z, t2);
  48198. sp_1024_mont_sqr_18(t2, t1, p1024_mod, p1024_mp_mod);
  48199. sp_1024_mont_mul_18(t1, t2, t1, p1024_mod, p1024_mp_mod);
  48200. sp_1024_mont_mul_18(p->x, p->x, t2, p1024_mod, p1024_mp_mod);
  48201. sp_1024_mont_mul_18(p->y, p->y, t1, p1024_mod, p1024_mp_mod);
  48202. XMEMCPY(p->z, p1024_norm_mod, sizeof(sp_digit) * 18);
  48203. }
  48204. #endif /* WOLFSSL_SP_SMALL */
  48205. /*
  48206. * Calculate gradient of line through P, P and [-2]P, accumulate line and
  48207. * double P.
  48208. *
  48209. * Calculations:
  48210. * l = 3 * (p.x^2 - p.z^4) = 3 * (p.x - p.z^2) * (p.x + p.z^2)
  48211. * r.x = l * (p.x + q.x * p.z^2) - 2 * p.y^2
  48212. * r.y = 2 * p.y * p.z^3 * q.y (= p'.z * p.z^2 * q.y)
  48213. * v* = v*^2 * r*
  48214. * p'.x = l^2 - 8 * p.y^2 * p.x
  48215. * p'.y = (4 * p.y^2 * p.x - p'.x) * l - 8 * p.y^4
  48216. * p'.z = 2 * p.y * p.z
  48217. *
  48218. * @param [in,out] vx X-ordinate of projective value in F*.
  48219. * @param [in,out] vy Y-ordinate of projective value in F*.
  48220. * @param [in,out] p ECC point - point on E(F_p^2) to double.
  48221. * @param [in] q ECC point - second point on E(F_P^2).
  48222. * @param [in] t SP temporaries (6 used).
  48223. */
  48224. static void sp_1024_accumulate_line_dbl_18(sp_digit* vx, sp_digit* vy,
  48225. sp_point_1024* p, const sp_point_1024* q, sp_digit* t)
  48226. {
  48227. sp_digit* t1 = t + 0 * 18;
  48228. sp_digit* pz2 = t + 2 * 18;
  48229. sp_digit* rx = t + 4 * 18;
  48230. sp_digit* ry = t + 6 * 18;
  48231. sp_digit* l = t + 8 * 18;
  48232. sp_digit* ty = t + 10 * 18;
  48233. /* v = v^2 */
  48234. sp_1024_proj_sqr_18(vx, vy, t);
  48235. /* pz2 = p.z^2 */
  48236. sp_1024_mont_sqr_18(pz2, p->z, p1024_mod, p1024_mp_mod);
  48237. /* t1 = p.x + p.z^2 */
  48238. sp_1024_mont_add_18(ty, p->x, pz2, p1024_mod);
  48239. /* l = p.x - p.z^2 */
  48240. sp_1024_mont_sub_18(l, p->x, pz2, p1024_mod);
  48241. /* t1 = (p.x + p.z^2) * (p.x - p.z^2) = p.x^2 - p.z^4 */
  48242. sp_1024_mont_mul_18(t1, l, ty, p1024_mod, p1024_mp_mod);
  48243. /* l = 3 * (p.x^2 - p.z^4) */
  48244. sp_1024_mont_tpl_18(l, t1, p1024_mod);
  48245. /* t1 = q.x * p.z^2 */
  48246. sp_1024_mont_mul_18(t1, q->x, pz2, p1024_mod, p1024_mp_mod);
  48247. /* t1 = p.x + q.x * p.z^2 */
  48248. sp_1024_mont_add_18(t1, p->x, t1, p1024_mod);
  48249. /* r.x = l * (p.x + q.x * p.z^2) */
  48250. sp_1024_mont_mul_18(rx, l, t1, p1024_mod, p1024_mp_mod);
  48251. /* r.y = 2 * p.y */
  48252. sp_1024_mont_dbl_18(ry, p->y, p1024_mod);
  48253. /* ty = 4 * p.y ^ 2 */
  48254. sp_1024_mont_sqr_18(ty, ry, p1024_mod, p1024_mp_mod);
  48255. /* t1 = 2 * p.y ^ 2 */
  48256. sp_1024_mont_div2_18(t1, ty, p1024_mod);
  48257. /* r.x -= 2 * (p.y ^ 2) */
  48258. sp_1024_mont_sub_18(rx, rx, t1, p1024_mod);
  48259. /* p'.z = p.y * 2 * p.z */
  48260. sp_1024_mont_mul_18(p->z, p->z, ry, p1024_mod, p1024_mp_mod);
  48261. /* r.y = p'.z * p.z^2 */
  48262. sp_1024_mont_mul_18(t1, p->z, pz2, p1024_mod, p1024_mp_mod);
  48263. /* r.y = p'.z * p.z^2 * q.y */
  48264. sp_1024_mont_mul_18(ry, t1, q->y, p1024_mod, p1024_mp_mod);
  48265. /* v = v^2 * r */
  48266. sp_1024_proj_mul_18(vx, vy, rx, ry, t);
  48267. /* Double point using previously calculated values
  48268. * l = 3 * (p.x - p.z^2).(p.x + p.z^2)
  48269. * ty = 4 * p.y^2
  48270. * p'.z = 2 * p.y * p.z
  48271. */
  48272. /* t1 = (4 * p.y^2) ^ 2 = 16 * p.y^4 */
  48273. sp_1024_mont_sqr_18(t1, ty, p1024_mod, p1024_mp_mod);
  48274. /* t1 = 16 * p.y^4 / 2 = 8 * p.y^4 */
  48275. sp_1024_mont_div2_18(t1, t1, p1024_mod);
  48276. /* p'.y = 4 * p.y^2 * p.x */
  48277. sp_1024_mont_mul_18(p->y, ty, p->x, p1024_mod, p1024_mp_mod);
  48278. /* p'.x = l^2 */
  48279. sp_1024_mont_sqr_18(p->x, l, p1024_mod, p1024_mp_mod);
  48280. /* p'.x = l^2 - 4 * p.y^2 * p.x */
  48281. sp_1024_mont_sub_18(p->x, p->x, p->y, p1024_mod);
  48282. /* p'.x = l^2 - 8 * p.y^2 * p.x */
  48283. sp_1024_mont_sub_18(p->x, p->x, p->y, p1024_mod);
  48284. /* p'.y = 4 * p.y^2 * p.x - p.x' */
  48285. sp_1024_mont_sub_18(ty, p->y, p->x, p1024_mod);
  48286. /* p'.y = (4 * p.y^2 * p.x - p'.x) * l */
  48287. sp_1024_mont_mul_18(p->y, ty, l, p1024_mod, p1024_mp_mod);
  48288. /* p'.y = (4 * p.y^2 * p.x - p'.x) * l - 8 * p.y^4 */
  48289. sp_1024_mont_sub_18(p->y, p->y, t1, p1024_mod);
  48290. }
  48291. #ifdef WOLFSSL_SP_SMALL
  48292. /*
  48293. * Calculate gradient of line through C, P and -C-P, accumulate line and
  48294. * add P to C.
  48295. *
  48296. * Calculations:
  48297. * r.x = (q.x + p.x) * c.y - (q.x * c.z^2 + c.x) * p.y * c.z
  48298. * r.y = (c.x - p.x * c.z^2) * q.y * c.z
  48299. * v* = v* * r*
  48300. * r = p.y * c.z^3 - c.y
  48301. * c'.x = r^2 + h^3 - 2 * c.x * h^2
  48302. * c'.y = r * (c'.x - c.x * h^2) - c.y * h^3
  48303. * c'.z = (c.x - p.x * c.z^2) * c.z
  48304. *
  48305. * @param [in,out] vx X-ordinate of projective value in F*.
  48306. * @param [in,out] vy Y-ordinate of projective value in F*.
  48307. * @param [in,out] c ECC point - current point on E(F_p^2) to be added
  48308. * to.
  48309. * @param [in] p ECC point - point on E(F_p^2) to add.
  48310. * @param [in] q ECC point - second point on E(F_P^2).
  48311. * @param [in] qx_px SP that is a constant value across adds.
  48312. * @param [in] t SP temporaries (6 used).
  48313. */
  48314. static void sp_1024_accumulate_line_add_one_18(sp_digit* vx, sp_digit* vy,
  48315. sp_point_1024* c, sp_point_1024* p, sp_point_1024* q, sp_digit* qx_px,
  48316. sp_digit* t)
  48317. {
  48318. sp_digit* t1 = t;
  48319. sp_digit* t2 = t + 2 * 18;
  48320. sp_digit* rx = t + 4 * 18;
  48321. sp_digit* ry = t + 6 * 18;
  48322. sp_digit* h = t + 8 * 18;
  48323. sp_digit* r = t + 10 * 18;
  48324. /* r.x = (q.x + p.x) * c.y */
  48325. sp_1024_mont_mul_18(rx, qx_px, c->y, p1024_mod, p1024_mp_mod);
  48326. /* t2 = c.z^2 */
  48327. sp_1024_mont_sqr_18(t2, c->z, p1024_mod, p1024_mp_mod);
  48328. /* t1 = q.x * c.z^2 */
  48329. sp_1024_mont_mul_18(t1, q->x, t2, p1024_mod, p1024_mp_mod);
  48330. /* t1 = q.x * c.z^2 + c.x */
  48331. sp_1024_mont_add_18(h, t1, c->x, p1024_mod);
  48332. /* r = p.y * c.z */
  48333. sp_1024_mont_mul_18(ry, p->y, c->z, p1024_mod, p1024_mp_mod);
  48334. /* t1 = (q.x * c.z^2 + c.x) * p.y * c.z */
  48335. sp_1024_mont_mul_18(t1, h, ry, p1024_mod, p1024_mp_mod);
  48336. /* r = p.y * c.z * c.z^2 = p.y * c.z^3 */
  48337. sp_1024_mont_mul_18(r, ry, t2, p1024_mod, p1024_mp_mod);
  48338. /* r.x -= (q.x * c.z^2 + c.x) * p.y * c.z */
  48339. sp_1024_mont_sub_18(rx, rx, t1, p1024_mod);
  48340. /* t1 = p.x * c.z^2 */
  48341. sp_1024_mont_mul_18(t1, p->x, t2, p1024_mod, p1024_mp_mod);
  48342. /* h = c.x - p.x * c.z^2 */
  48343. sp_1024_mont_sub_18(h, c->x, t1, p1024_mod);
  48344. /* c'.z = (c.x - p.x * c.z^2) * c.z */
  48345. sp_1024_mont_mul_18(c->z, h, c->z, p1024_mod, p1024_mp_mod);
  48346. /* r.y = (c.x - p.x * c.z^2) * c.z * q.y */
  48347. sp_1024_mont_mul_18(ry, c->z, q->y, p1024_mod, p1024_mp_mod);
  48348. /* v = v * r */
  48349. sp_1024_proj_mul_18(vx, vy, rx, ry, t);
  48350. /* Add p to c using previously calculated values.
  48351. * h = c.x - p.x * c.z^2
  48352. * r = p.y * c.z^3
  48353. * c'.z = (c.x - p.x * c.z^2) * c.z
  48354. */
  48355. /* r = p.y * c.z^3 - c.y */
  48356. sp_1024_mont_sub_18(r, r, c->y, p1024_mod);
  48357. /* t1 = r^2 */
  48358. sp_1024_mont_sqr_18(t1, r, p1024_mod, p1024_mp_mod);
  48359. /* t2 = h^2 */
  48360. sp_1024_mont_sqr_18(rx, h, p1024_mod, p1024_mp_mod);
  48361. /* ry = c.x * h^2 */
  48362. sp_1024_mont_mul_18(ry, c->x, rx, p1024_mod, p1024_mp_mod);
  48363. /* t2 = h^3 */
  48364. sp_1024_mont_mul_18(t2, rx, h, p1024_mod, p1024_mp_mod);
  48365. /* c->x = r^2 + h^3 */
  48366. sp_1024_mont_add_18(c->x, t1, t2, p1024_mod);
  48367. /* t1 = 2 * c.x * h^2 */
  48368. sp_1024_mont_dbl_18(t1, ry, p1024_mod);
  48369. /* c'.x = r^2 + h^3 - 2 * c.x * h^2 */
  48370. sp_1024_mont_sub_18(c->x, c->x, t1, p1024_mod);
  48371. /* ry = c'.x - c.x * h^2 */
  48372. sp_1024_mont_sub_18(t1, c->x, ry, p1024_mod);
  48373. /* ry = r * (c'.x - c.x * h^2) */
  48374. sp_1024_mont_mul_18(ry, t1, r, p1024_mod, p1024_mp_mod);
  48375. /* t2 = c.y * h^3 */
  48376. sp_1024_mont_mul_18(t1, t2, c->y, p1024_mod, p1024_mp_mod);
  48377. /* c'.y = r * (c'.x - c.x * h^2) - c.y * h^3 */
  48378. sp_1024_mont_sub_18(c->y, ry, t1, p1024_mod);
  48379. }
  48380. /*
  48381. * Calculate r = pairing <P, Q>.
  48382. *
  48383. * That is, multiply base in PF_p[q] by the scalar s, such that s.P = Q.
  48384. *
  48385. * @param [in] key SAKKE key.
  48386. * @param [in] p First point on E(F_p)[q].
  48387. * @param [in] q Second point on E(F_p)[q].
  48388. * @param [in] r Result of calculation.
  48389. * @return 0 on success.
  48390. * @return MEMORY_E when dynamic memory allocation fails.
  48391. * @return Other -ve value on internal failure.
  48392. */
  48393. int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
  48394. {
  48395. int err = MP_OKAY;
  48396. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48397. defined(WOLFSSL_SP_SMALL_STACK)
  48398. sp_digit* td = NULL;
  48399. sp_digit* t;
  48400. sp_digit* vx;
  48401. sp_digit* vy;
  48402. sp_digit* qx_px;
  48403. #else
  48404. sp_digit t[36 * 2 * 18];
  48405. sp_digit vx[2 * 18];
  48406. sp_digit vy[2 * 18];
  48407. sp_digit qx_px[2 * 18];
  48408. sp_point_1024 pd;
  48409. sp_point_1024 qd;
  48410. sp_point_1024 cd;
  48411. #endif
  48412. sp_point_1024* p = NULL;
  48413. sp_point_1024* q = NULL;
  48414. sp_point_1024* c = NULL;
  48415. sp_digit* r = NULL;
  48416. int i;
  48417. err = sp_1024_point_new_18(NULL, pd, p);
  48418. if (err == MP_OKAY) {
  48419. err = sp_1024_point_new_18(NULL, qd, q);
  48420. }
  48421. if (err == MP_OKAY) {
  48422. err = sp_1024_point_new_18(NULL, cd, c);
  48423. }
  48424. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48425. defined(WOLFSSL_SP_SMALL_STACK)
  48426. if (err == MP_OKAY) {
  48427. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 18 * 2, NULL,
  48428. DYNAMIC_TYPE_TMP_BUFFER);
  48429. if (td == NULL) {
  48430. err = MEMORY_E;
  48431. }
  48432. }
  48433. #endif
  48434. if (err == MP_OKAY) {
  48435. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48436. defined(WOLFSSL_SP_SMALL_STACK)
  48437. t = td;
  48438. vx = td + 36 * 18 * 2;
  48439. vy = td + 37 * 18 * 2;
  48440. qx_px = td + 38 * 18 * 2;
  48441. #endif
  48442. r = vy;
  48443. sp_1024_point_from_ecc_point_18(p, pm);
  48444. sp_1024_point_from_ecc_point_18(q, qm);
  48445. err = sp_1024_mod_mul_norm_18(p->x, p->x, p1024_mod);
  48446. }
  48447. if (err == MP_OKAY) {
  48448. err = sp_1024_mod_mul_norm_18(p->y, p->y, p1024_mod);
  48449. }
  48450. if (err == MP_OKAY) {
  48451. err = sp_1024_mod_mul_norm_18(p->z, p->z, p1024_mod);
  48452. }
  48453. if (err == MP_OKAY) {
  48454. err = sp_1024_mod_mul_norm_18(q->x, q->x, p1024_mod);
  48455. }
  48456. if (err == MP_OKAY) {
  48457. err = sp_1024_mod_mul_norm_18(q->y, q->y, p1024_mod);
  48458. }
  48459. if (err == MP_OKAY) {
  48460. XMEMCPY(c, p, sizeof(sp_point_1024));
  48461. XMEMSET(vx, 0, sizeof(sp_digit) * 2 * 18);
  48462. vx[0] = 1;
  48463. XMEMSET(vy, 0, sizeof(sp_digit) * 2 * 18);
  48464. sp_1024_mont_add_18(qx_px, q->x, p->x, p1024_mod);
  48465. for (i = 1020; i >= 0; i--) {
  48466. /* Accumulate line into v and double point. */
  48467. sp_1024_accumulate_line_dbl_18(vx, vy, c, q, t);
  48468. if ((i > 0) && ((p1024_order[i / 57] >> (i % 57)) & 1)) {
  48469. /* Accumulate line into v and add P into C. */
  48470. sp_1024_accumulate_line_add_one_18(vx, vy, c, p, q, qx_px, t);
  48471. }
  48472. }
  48473. /* Final exponentiation */
  48474. sp_1024_proj_sqr_18(vx, vy, t);
  48475. sp_1024_proj_sqr_18(vx, vy, t);
  48476. /* Convert from PF_p[q] to F_p */
  48477. sp_1024_mont_inv_18(vx, vx, t);
  48478. sp_1024_mont_mul_18(r, vx, vy, p1024_mod, p1024_mp_mod);
  48479. XMEMSET(r + 18, 0, sizeof(sp_digit) * 18);
  48480. sp_1024_mont_reduce_18(r, p1024_mod, p1024_mp_mod);
  48481. err = sp_1024_to_mp(r, res);
  48482. }
  48483. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48484. defined(WOLFSSL_SP_SMALL_STACK)
  48485. if (td != NULL) {
  48486. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48487. }
  48488. #endif
  48489. sp_1024_point_free_18(c, 1, NULL);
  48490. sp_1024_point_free_18(q, 1, NULL);
  48491. sp_1024_point_free_18(p, 1, NULL);
  48492. return err;
  48493. }
  48494. #else
  48495. /*
  48496. * Calculate gradient of line through C, P and -C-P, accumulate line and
  48497. * add P to C.
  48498. *
  48499. * Both C and P have z ordinates to use in the calculation.
  48500. *
  48501. * Calculations:
  48502. * r.x = (q.x * c.z^2 + c.x) * p.y * c.z - (q.x * p.z^2 + p.x) * c.y * p.z
  48503. * r.y = (p.x * c.z^2 - c.x * p.z^2) * q.y * p.z * c.z
  48504. * v* = v* * r*
  48505. * h = p.x * c.z^2 - c.x * p.z^2
  48506. * r = p.y * c.z^3 - c.y * p.z^3
  48507. * c'.x = r^2 - h^3 - 2 * c.x * p.z^2 * h^2
  48508. * c'.y = r * (c.x * p.z^2 * h^2 - c'.x) - c.y * p.z^3 * h^3
  48509. * c'.z = (p.x * c.z^2 - c.x * p.z^2) * c.z
  48510. *
  48511. * @param [in,out] vx X-ordinate of projective value in F*.
  48512. * @param [in,out] vy Y-ordinate of projective value in F*.
  48513. * @param [in,out] c ECC point - current point on E(F_p^2) to be added
  48514. * to.
  48515. * @param [in,out] p ECC point - point on E(F_p^2) to add.
  48516. * @param [in,out] q ECC point - second point on E(F_P^2).
  48517. * @param [in,out] t SP temporaries (6 used).
  48518. * @param [in,out] neg Indicates to use negative P.
  48519. * @return 0 on success.
  48520. * @return MEMORY_E when dynamic memory allocation fails.
  48521. * @return Other -ve value on internal failure.
  48522. */
  48523. static void sp_1024_accumulate_line_add_n_18(sp_digit* vx, sp_digit* vy,
  48524. const sp_point_1024* p, const sp_point_1024* q,
  48525. sp_point_1024* c, sp_digit* t, int neg)
  48526. {
  48527. sp_digit* t1 = t;
  48528. sp_digit* t2 = t + 2 * 18;
  48529. sp_digit* rx = t + 4 * 18;
  48530. sp_digit* ry = t + 6 * 18;
  48531. sp_digit* h = t + 8 * 18;
  48532. sp_digit* r = t + 10 * 18;
  48533. /* h = p.z^2 */
  48534. sp_1024_mont_sqr_18(h, p->z, p1024_mod, p1024_mp_mod);
  48535. /* rx = q.x * p.z^2 */
  48536. sp_1024_mont_mul_18(rx, q->x, h, p1024_mod, p1024_mp_mod);
  48537. /* rx = q.x * p.z^2 + p.x */
  48538. sp_1024_mont_add_18(t2, rx, p->x, p1024_mod);
  48539. /* c.y = c.y * p.z */
  48540. sp_1024_mont_mul_18(t1, c->y, p->z, p1024_mod, p1024_mp_mod);
  48541. /* r.x = (q.x * p.z^2 + p.x) * c.y * p.z */
  48542. sp_1024_mont_mul_18(rx, t2, t1, p1024_mod, p1024_mp_mod);
  48543. /* c.y = c.y * p.z^3 */
  48544. sp_1024_mont_mul_18(c->y, t1, h, p1024_mod, p1024_mp_mod);
  48545. /* t2 = c.z^2 */
  48546. sp_1024_mont_sqr_18(t2, c->z, p1024_mod, p1024_mp_mod);
  48547. /* t1 = q.x * c.z^2 */
  48548. sp_1024_mont_mul_18(t1, q->x, t2, p1024_mod, p1024_mp_mod);
  48549. /* t1 = q.x * c.z^2 + c.x */
  48550. sp_1024_mont_add_18(t1, t1, c->x, p1024_mod);
  48551. /* c.x = c.x * p.z^2 */
  48552. sp_1024_mont_mul_18(c->x, c->x, h, p1024_mod, p1024_mp_mod);
  48553. /* r = p.y * c.z */
  48554. sp_1024_mont_mul_18(r, p->y, c->z, p1024_mod, p1024_mp_mod);
  48555. if (neg) {
  48556. /* r = -p.y * c.z */
  48557. sp_1024_mont_sub_18(r, p1024_mod, r, p1024_mod);
  48558. }
  48559. /* t1 = (q.x * c.z^2 + c.x) * p.y * c.z */
  48560. sp_1024_mont_mul_18(ry, t1, r, p1024_mod, p1024_mp_mod);
  48561. /* r.x -= (q.x * c.z^2 + c.x) * p.y * c.z */
  48562. sp_1024_mont_sub_18(rx, ry, rx, p1024_mod);
  48563. /* t1 = p.x * c.z^2 */
  48564. sp_1024_mont_mul_18(t1, p->x, t2, p1024_mod, p1024_mp_mod);
  48565. /* h = p.x * c.z^2 - c.x * p.z^2 */
  48566. sp_1024_mont_sub_18(h, t1, c->x, p1024_mod);
  48567. /* c'.z = (p.x * c.z^2 - c.x * p.z^2) * c.z */
  48568. sp_1024_mont_mul_18(t1, h, c->z, p1024_mod, p1024_mp_mod);
  48569. /* c'.z = (p.x * c.z^2 - c.x * p.z^2) * c.z * p.z */
  48570. sp_1024_mont_mul_18(c->z, t1, p->z, p1024_mod, p1024_mp_mod);
  48571. /* r.y = (p.x * c.z^2 - c.x * p.z^2) * c.z * p.z * q.y */
  48572. sp_1024_mont_mul_18(ry, c->z, q->y, p1024_mod, p1024_mp_mod);
  48573. /* r = p.y * c.z^3 */
  48574. sp_1024_mont_mul_18(t1, r, t2, p1024_mod, p1024_mp_mod);
  48575. /* r = p.y * c.z^3 - c.y * p.z^3 */
  48576. sp_1024_mont_sub_18(r, t1, c->y, p1024_mod);
  48577. /* v = v * r */
  48578. sp_1024_proj_mul_18(vx, vy, rx, ry, t);
  48579. /* Add p to c using previously calculated values.
  48580. * h = p.x * c.z^2 - c.x * p.z^2
  48581. * r = p.y * c.z^3 - c.y * p.z^3
  48582. * c'.z = (p.x * c.z^2 - c.x * p.z^2) * c.z
  48583. */
  48584. /* t1 = r^2 */
  48585. sp_1024_mont_sqr_18(t1, r, p1024_mod, p1024_mp_mod);
  48586. /* t2 = h^2 */
  48587. sp_1024_mont_sqr_18(rx, h, p1024_mod, p1024_mp_mod);
  48588. /* ry = c.x * p.z^2 * h^2 */
  48589. sp_1024_mont_mul_18(ry, rx, c->x, p1024_mod, p1024_mp_mod);
  48590. /* t2 = h^3 */
  48591. sp_1024_mont_mul_18(t2, rx, h, p1024_mod, p1024_mp_mod);
  48592. /* c'.x = r^2 - h^3 */
  48593. sp_1024_mont_sub_18(c->x, t1, t2, p1024_mod);
  48594. /* t1 = 2 * c.x * p.z^2 * h^2 */
  48595. sp_1024_mont_dbl_18(t1, ry, p1024_mod);
  48596. /* c'.x = r^2 - h^3 - 2 * c.x * p.z^2 * h^2 */
  48597. sp_1024_mont_sub_18(c->x, c->x, t1, p1024_mod);
  48598. /* ry = c.x * p.z^2 * h^2 - c'.x */
  48599. sp_1024_mont_sub_18(t1, ry, c->x, p1024_mod);
  48600. /* ry = r * (c.x * p.z^2 * h^2 - c'.x) */
  48601. sp_1024_mont_mul_18(ry, t1, r, p1024_mod, p1024_mp_mod);
  48602. /* t2 = c.y * p.z^3 * h^3 */
  48603. sp_1024_mont_mul_18(t1, t2, c->y, p1024_mod, p1024_mp_mod);
  48604. /* c'.y = r * (c.x * p.z^2 * h^2 - c'.x) - c.y * p.z^3 * h^3 */
  48605. sp_1024_mont_sub_18(c->y, ry, t1, p1024_mod);
  48606. }
  48607. /*
  48608. * Perform n accumulate doubles and doubles of P.
  48609. *
  48610. * py = 2 * p.y
  48611. *
  48612. * For each double:
  48613. * Calculate gradient of line through P, P and [-2]P, accumulate line and
  48614. * double P.
  48615. *
  48616. * Calculations:
  48617. * l = 3 * (p.x^2 - p.z^4) = 3 * (p.x - p.z^2) * (p.x + p.z^2)
  48618. * r.x = l * (p.x + q.x * p.z^2) - py^2 / 2
  48619. * r.y = py * p.z^3 * q.y (= p'.z * p.z^2 * q.y)
  48620. * v* = v*^2 * r*
  48621. * p'.x = l^2 - 2 * py^2 * p.x
  48622. * py' = (py^2 * p.x - p'.x) * l - py^4 (= 2 * p'.y)
  48623. * p'.z = py * p.z
  48624. *
  48625. * Finally:
  48626. * p'.y = py' / 2
  48627. *
  48628. * @param [in,out] vx X-ordinate of projective value in F*.
  48629. * @param [in,out] vy Y-ordinate of projective value in F*.
  48630. * @param [in,out] p ECC point - point on E(F_p^2) to double.
  48631. * @param [in] q ECC point - second point on E(F_P^2).
  48632. * @param [in] n Number of times to double.
  48633. * @param [in] t SP temporaries (6 used).
  48634. */
  48635. static void sp_1024_accumulate_line_dbl_n_18(sp_digit* vx, sp_digit* vy,
  48636. sp_point_1024* p, const sp_point_1024* q, int n, sp_digit* t)
  48637. {
  48638. sp_digit* t1 = t + 0 * 18;
  48639. sp_digit* pz2 = t + 2 * 18;
  48640. sp_digit* rx = t + 4 * 18;
  48641. sp_digit* ry = t + 6 * 18;
  48642. sp_digit* l = t + 8 * 18;
  48643. sp_digit* ty = t + 10 * 18;
  48644. int i;
  48645. /* py = 2 * p.y */
  48646. sp_1024_mont_dbl_18(p->y, p->y, p1024_mod);
  48647. for (i = 0; i < n; i++) {
  48648. /* v = v^2 */
  48649. sp_1024_proj_sqr_18(vx, vy, t);
  48650. /* pz2 = p.z^2 */
  48651. sp_1024_mont_sqr_18(pz2, p->z, p1024_mod, p1024_mp_mod);
  48652. /* t1 = p.x + p.z^2 */
  48653. sp_1024_mont_add_18(t1, p->x, pz2, p1024_mod);
  48654. /* l = p.x - p.z^2 */
  48655. sp_1024_mont_sub_18(l, p->x, pz2, p1024_mod);
  48656. /* t1 = (p.x + p.z^2) * (p.x - p.z^2) = p.x^2 - p.z^4 */
  48657. sp_1024_mont_mul_18(ty, l, t1, p1024_mod, p1024_mp_mod);
  48658. /* l = 3 * (p.x^2 - p.z^4) */
  48659. sp_1024_mont_tpl_18(l, ty, p1024_mod);
  48660. /* t1 = q.x * p.z^2 */
  48661. sp_1024_mont_mul_18(t1, q->x, pz2, p1024_mod, p1024_mp_mod);
  48662. /* t1 = p.x + q.x * p.z^2 */
  48663. sp_1024_mont_add_18(t1, p->x, t1, p1024_mod);
  48664. /* r.x = l * (p.x + q.x * p.z^2) */
  48665. sp_1024_mont_mul_18(rx, l, t1, p1024_mod, p1024_mp_mod);
  48666. /* ty = py ^ 2 */
  48667. sp_1024_mont_sqr_18(ty, p->y, p1024_mod, p1024_mp_mod);
  48668. /* t1 = py ^ 2 / 2 */
  48669. sp_1024_mont_div2_18(t1, ty, p1024_mod);
  48670. /* r.x -= py ^ 2 / 2 */
  48671. sp_1024_mont_sub_18(rx, rx, t1, p1024_mod);
  48672. /* p'.z = py * pz */
  48673. sp_1024_mont_mul_18(p->z, p->z, p->y, p1024_mod, p1024_mp_mod);
  48674. /* r.y = p'.z * p.z^2 */
  48675. sp_1024_mont_mul_18(t1, p->z, pz2, p1024_mod, p1024_mp_mod);
  48676. /* r.y = p'.z * p.z^2 * q.y */
  48677. sp_1024_mont_mul_18(ry, t1, q->y, p1024_mod, p1024_mp_mod);
  48678. /* v = v^2 * r */
  48679. sp_1024_proj_mul_18(vx, vy, rx, ry, t);
  48680. /* Double point using previously calculated values
  48681. * l = 3 * (p.x - p.z^2).(p.x + p.z^2)
  48682. * ty = py^2
  48683. * p'.z = py * p.z
  48684. */
  48685. /* t1 = py^2 ^ 2 = py^4 */
  48686. sp_1024_mont_sqr_18(t1, ty, p1024_mod, p1024_mp_mod);
  48687. /* py' = py^2 * p. x */
  48688. sp_1024_mont_mul_18(p->y, ty, p->x, p1024_mod, p1024_mp_mod);
  48689. /* p'.x = l^2 */
  48690. sp_1024_mont_sqr_18(p->x, l, p1024_mod, p1024_mp_mod);
  48691. /* p'.x = l^2 - py^2 * p.x */
  48692. sp_1024_mont_sub_18(p->x, p->x, p->y, p1024_mod);
  48693. /* p'.x = l^2 - 2 * p.y^2 * p.x */
  48694. sp_1024_mont_sub_18(p->x, p->x, p->y, p1024_mod);
  48695. /* py' = py^2 * p.x - p.x' */
  48696. sp_1024_mont_sub_18(ty, p->y, p->x, p1024_mod);
  48697. /* py' = (p.y^2 * p.x - p'.x) * l */
  48698. sp_1024_mont_mul_18(p->y, ty, l, p1024_mod, p1024_mp_mod);
  48699. /* py' = (p.y^2 * p.x - p'.x) * l * 2 */
  48700. sp_1024_mont_dbl_18(p->y, p->y, p1024_mod);
  48701. /* py' = (p.y^2 * p.x - p'.x) * l * 2 - p.y^4 */
  48702. sp_1024_mont_sub_18(p->y, p->y, t1, p1024_mod);
  48703. }
  48704. /* p'.y = py' / 2 */
  48705. sp_1024_mont_div2_18(p->y, p->y, p1024_mod);
  48706. }
  48707. /* Operations to perform based on order - 1.
  48708. * Sliding window. Start at bottom and stop when bottom bit is one.
  48709. * Subtract if top bit in window is one.
  48710. * Width of 6 bits.
  48711. * Pairs: #dbls, add/subtract window value
  48712. */
  48713. static const signed char sp_1024_order_op[] = {
  48714. 5, 6, -13, 9, -21, 6, -5, 8, 31, 6, 3, 6, -27, 6, 25, 9,
  48715. -1, 6, -11, 6, -13, 6, -7, 6, -15, 6, -29, 7, 25, 6, -9, 6,
  48716. -19, 7, 3, 6, 11, 9, -23, 6, 1, 6, 27, 6, 1, 7, -25, 8,
  48717. 13, 7, -13, 7, -23, 10, 19, 7, 7, 7, -3, 7, 27, 6, -7, 7,
  48718. -21, 7, 11, 7, 31, 8, 1, 7, -23, 6, -17, 6, -3, 10, 11, 6,
  48719. -21, 7, -27, 11, -29, 6, -1, 10, 15, 8, 27, 7, 17, 6, 17, 7,
  48720. -13, 8, 13, 6, 21, 7, -29, 6, 19, 7, -25, 6, 11, 9, 29, 7,
  48721. -7, 8, 27, 7, 29, 10, -1, 8, -7, 8, 17, 6, 17, 7, -27, 7,
  48722. -21, 6, -9, 6, -27, 12, -23, 6, 19, 6, 13, 6, -11, 7, 27, 6,
  48723. 17, 6, -7, 6, -25, 7, -29, 6, 9, 7, 7, 6, 13, 6, -25, 6,
  48724. -19, 6, 13, 6, -11, 6, 5, 8, 19, 6, -21, 8, 23, 7, 27, 6,
  48725. -13, 6, -19, 11, 29, 7, -15, 6, -9, 7, -21, 10, -3, 7, 21, 10,
  48726. 25, 6, -15, 6, -23, 6, 21, 6, 1, 6, 21, 7, -3, 6, -3, 7,
  48727. -7, 6, -23, 7, 7, 8, 15, 9, 5, 6, -11, 6, 21, 11, -27, 7,
  48728. 27, 6, -11, 6, 31, 6, -21, 6, 19, 6, -7, 8, -7, 13, -3, 6,
  48729. -7, 7, -3, 6, 1, 6, 7, 8, 19, 8, 11, 9, -9, 7, -31, 12,
  48730. 25, 6, -17, 9, -15, 7, 5, 6, 25, 7, -5, 7, -25, 6, 17, 8,
  48731. -19, 6, -13, 6, 27, 8, 1, 7, -5, 7, -1, 6, 21, 6, 3, 10,
  48732. -3, 1,
  48733. };
  48734. /*
  48735. * Calculate r = pairing <P, Q>.
  48736. *
  48737. * That is, multiply base in PF_p[q] by the scalar s, such that s.P = Q.
  48738. *
  48739. * Sliding window. Start at bottom and stop when bottom bit is one.
  48740. * Subtract if top bit in window is one.
  48741. * Width of 6 bits.
  48742. *
  48743. * @param [in] pm First point on E(F_p)[q].
  48744. * @param [in] qm Second point on E(F_p)[q].
  48745. * @param [in] res Result of calculation.
  48746. * @return 0 on success.
  48747. * @return MEMORY_E when dynamic memory allocation fails.
  48748. */
  48749. int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
  48750. {
  48751. int err;
  48752. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48753. defined(WOLFSSL_SP_SMALL_STACK)
  48754. sp_digit* td = NULL;
  48755. sp_digit* t;
  48756. sp_digit* vx;
  48757. sp_digit* vy;
  48758. sp_digit (*pre_vx)[36];
  48759. sp_digit (*pre_vy)[36];
  48760. sp_digit (*pre_nvy)[36];
  48761. sp_point_1024* pre_p;
  48762. #else
  48763. sp_digit t[36 * 2 * 18];
  48764. sp_digit vx[2 * 18];
  48765. sp_digit vy[2 * 18];
  48766. sp_digit pre_vx[16][36];
  48767. sp_digit pre_vy[16][36];
  48768. sp_digit pre_nvy[16][36];
  48769. sp_point_1024 pre_p[16];
  48770. sp_point_1024 pd;
  48771. sp_point_1024 qd;
  48772. sp_point_1024 cd;
  48773. #endif
  48774. sp_point_1024* p = NULL;
  48775. sp_point_1024* q = NULL;
  48776. sp_point_1024* c = NULL;
  48777. sp_digit* r = NULL;
  48778. int i;
  48779. int j;
  48780. err = sp_1024_point_new_18(NULL, pd, p);
  48781. if (err == MP_OKAY) {
  48782. err = sp_1024_point_new_18(NULL, qd, q);
  48783. }
  48784. if (err == MP_OKAY) {
  48785. err = sp_1024_point_new_18(NULL, cd, c);
  48786. }
  48787. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48788. defined(WOLFSSL_SP_SMALL_STACK)
  48789. if (err == MP_OKAY) {
  48790. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL,
  48791. DYNAMIC_TYPE_TMP_BUFFER);
  48792. if (td == NULL) {
  48793. err = MEMORY_E;
  48794. }
  48795. }
  48796. #endif
  48797. if (err == MP_OKAY) {
  48798. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48799. defined(WOLFSSL_SP_SMALL_STACK)
  48800. t = td;
  48801. vx = td + 36 * 18 * 2;
  48802. vy = td + 37 * 18 * 2;
  48803. pre_vx = (sp_digit(*)[36])(td + 38 * 18 * 2);
  48804. pre_vy = (sp_digit(*)[36])(td + 54 * 18 * 2);
  48805. pre_nvy = (sp_digit(*)[36])(td + 70 * 18 * 2);
  48806. pre_p = (sp_point_1024*)(td + 86 * 18 * 2);
  48807. #endif
  48808. r = vy;
  48809. sp_1024_point_from_ecc_point_18(p, pm);
  48810. sp_1024_point_from_ecc_point_18(q, qm);
  48811. err = sp_1024_mod_mul_norm_18(p->x, p->x, p1024_mod);
  48812. }
  48813. if (err == MP_OKAY) {
  48814. err = sp_1024_mod_mul_norm_18(p->y, p->y, p1024_mod);
  48815. }
  48816. if (err == MP_OKAY) {
  48817. err = sp_1024_mod_mul_norm_18(p->z, p->z, p1024_mod);
  48818. }
  48819. if (err == MP_OKAY) {
  48820. err = sp_1024_mod_mul_norm_18(q->x, q->x, p1024_mod);
  48821. }
  48822. if (err == MP_OKAY) {
  48823. err = sp_1024_mod_mul_norm_18(q->y, q->y, p1024_mod);
  48824. }
  48825. if (err == MP_OKAY) {
  48826. /* Generate pre-computation table: 1, 3, ... , 31 */
  48827. XMEMCPY(&pre_p[0], p, sizeof(sp_point_1024));
  48828. XMEMSET(pre_vx[0], 0, sizeof(sp_digit) * 2 * 18);
  48829. pre_vx[0][0] = 1;
  48830. XMEMSET(pre_vy[0], 0, sizeof(sp_digit) * 2 * 18);
  48831. sp_1024_mont_sub_18(pre_nvy[0], p1024_mod, pre_vy[0], p1024_mod);
  48832. /* [2]P for adding */
  48833. XMEMCPY(c, p, sizeof(sp_point_1024));
  48834. XMEMSET(vx, 0, sizeof(sp_digit) * 2 * 18);
  48835. vx[0] = 1;
  48836. XMEMSET(vy, 0, sizeof(sp_digit) * 2 * 18);
  48837. sp_1024_accumulate_line_dbl_18(vx, vy, c, q, t);
  48838. /* 3, 5, ... */
  48839. for (i = 1; i < 16; i++) {
  48840. XMEMCPY(&pre_p[i], &pre_p[i-1], sizeof(sp_point_1024));
  48841. XMEMCPY(pre_vx[i], pre_vx[i-1], sizeof(sp_digit) * 2 * 18);
  48842. XMEMCPY(pre_vy[i], pre_vy[i-1], sizeof(sp_digit) * 2 * 18);
  48843. sp_1024_proj_mul_18(pre_vx[i], pre_vy[i], vx, vy, t);
  48844. sp_1024_accumulate_line_add_n_18(pre_vx[i], pre_vy[i], c,
  48845. q, &pre_p[i], t, 0);
  48846. sp_1024_mont_sub_18(pre_nvy[i], p1024_mod, pre_vy[i], p1024_mod);
  48847. }
  48848. j = sp_1024_order_op[0] / 2;
  48849. XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
  48850. XMEMCPY(vx, pre_vx[j], sizeof(sp_digit) * 2 * 18);
  48851. XMEMCPY(vy, pre_vy[j], sizeof(sp_digit) * 2 * 18);
  48852. /* Accumulate line into v and double point n times. */
  48853. sp_1024_accumulate_line_dbl_n_18(vx, vy, c, q,
  48854. sp_1024_order_op[1], t);
  48855. for (i = 2; i < 290; i += 2) {
  48856. j = sp_1024_order_op[i];
  48857. if (j > 0) {
  48858. j /= 2;
  48859. /* Accumulate line into v and add P into C. */
  48860. sp_1024_proj_mul_18(vx, vy, pre_vx[j], pre_vy[j], t);
  48861. sp_1024_accumulate_line_add_n_18(vx, vy, &pre_p[j], q, c,
  48862. t, 0);
  48863. }
  48864. else {
  48865. j = -j / 2;
  48866. /* Accumulate line into v and add P into C. */
  48867. sp_1024_proj_mul_18(vx, vy, pre_vx[j], pre_nvy[j], t);
  48868. sp_1024_accumulate_line_add_n_18(vx, vy, &pre_p[j], q, c,
  48869. t, 1);
  48870. }
  48871. /* Accumulate line into v and double point n times. */
  48872. sp_1024_accumulate_line_dbl_n_18(vx, vy, c, q,
  48873. sp_1024_order_op[i + 1], t);
  48874. }
  48875. /* Final exponentiation */
  48876. sp_1024_proj_sqr_18(vx, vy, t);
  48877. sp_1024_proj_sqr_18(vx, vy, t);
  48878. /* Convert from PF_p[q] to F_p */
  48879. sp_1024_mont_inv_18(vx, vx, t);
  48880. sp_1024_mont_mul_18(r, vx, vy, p1024_mod, p1024_mp_mod);
  48881. XMEMSET(r + 18, 0, sizeof(sp_digit) * 18);
  48882. sp_1024_mont_reduce_18(r, p1024_mod, p1024_mp_mod);
  48883. err = sp_1024_to_mp(r, res);
  48884. }
  48885. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  48886. defined(WOLFSSL_SP_SMALL_STACK)
  48887. if (td != NULL) {
  48888. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48889. }
  48890. #endif
  48891. sp_1024_point_free_18(c, 1, NULL);
  48892. sp_1024_point_free_18(q, 1, NULL);
  48893. sp_1024_point_free_18(p, 1, NULL);
  48894. return err;
  48895. }
  48896. #endif /* WOLFSSL_SP_SMALL */
  48897. #ifdef WOLFSSL_SP_SMALL
  48898. /*
  48899. * Generate table for pairing.
  48900. *
  48901. * Small implementation does not use a table - returns 0 length.
  48902. *
  48903. * pm [in] Point to generate table for.
  48904. * table [in] Generated table.
  48905. * len [in,out] On in, the size of the buffer.
  48906. * On out, length of table generated.
  48907. * @return 0 on success.
  48908. * LENGTH_ONLY_E when table is NULL and only length returned.
  48909. * BUFFER_E when len is too small.
  48910. */
  48911. int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
  48912. word32* len)
  48913. {
  48914. int err = 0;
  48915. if (table == NULL) {
  48916. *len = 0;
  48917. err = LENGTH_ONLY_E;
  48918. }
  48919. else if (*len != 0) {
  48920. err = BUFFER_E;
  48921. }
  48922. (void)*pm;
  48923. return err;
  48924. }
  48925. /*
  48926. * Calculate r = pairing <P, Q>.
  48927. *
  48928. * That is, multiply base in PF_p[q] by the scalar s, such that s.P = Q.
  48929. *
  48930. * Small implementation does not use a table - use the normal implementation.
  48931. *
  48932. * @param [in] pm First point on E(F_p)[q].
  48933. * @param [in] qm Second point on E(F_p)[q].
  48934. * @param [in] res Result of calculation.
  48935. * @param [in] table Precomputed table of values.
  48936. * @param [in] len Length of precomputed table of values in bytes.
  48937. * @return 0 on success.
  48938. * @return MEMORY_E when dynamic memory allocation fails.
  48939. */
  48940. int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
  48941. mp_int* res, const byte* table, word32 len)
  48942. {
  48943. (void)table;
  48944. (void)len;
  48945. return sp_Pairing_1024(pm, qm, res);
  48946. }
  48947. #else
  48948. /*
  48949. * Calc l and c for the point when doubling p.
  48950. *
  48951. * l = 3 * (p.x^2 - 1) / (2 * p.y)
  48952. * c = l * p.x - p.y
  48953. *
  48954. * @param [out] lr Gradient result - table entry.
  48955. * @param [out] cr Constant result - table entry.
  48956. * @param [in] px X-ordinate of point to double.
  48957. * @param [in] py Y-ordinate of point to double.
  48958. * @param [in] t SP temporaries (3 used).
  48959. */
  48960. static void sp_1024_accum_dbl_calc_lc_18(sp_digit* lr, sp_digit* cr,
  48961. const sp_digit* px, const sp_digit* py, sp_digit* t)
  48962. {
  48963. sp_digit* t1 = t + 33 * 2 * 18;
  48964. sp_digit* t2 = t + 34 * 2 * 18;
  48965. sp_digit* l = t + 35 * 2 * 18;
  48966. /* l = 1 / 2 * p.y */
  48967. sp_1024_mont_dbl_18(l, py, p1024_mod);
  48968. sp_1024_mont_inv_18(l, l, t);
  48969. /* t1 = p.x^2 */
  48970. sp_1024_mont_sqr_18(t1, px, p1024_mod, p1024_mp_mod);
  48971. /* t1 = p.x - 1 */
  48972. sp_1024_mont_sub_18(t1, t1, p1024_norm_mod, p1024_mod);
  48973. /* t1 = 3 * (p.x^2 - 1) */
  48974. sp_1024_mont_dbl_18(t2, t1, p1024_mod);
  48975. sp_1024_mont_add_18(t1, t1, t2, p1024_mod);
  48976. /* t1 = 3 * (p.x^2 - 1) / (2 * p.y) */
  48977. sp_1024_mont_mul_18(l, l, t1, p1024_mod, p1024_mp_mod);
  48978. /* t2 = l * p.x */
  48979. sp_1024_mont_mul_18(t2, l, px, p1024_mod, p1024_mp_mod);
  48980. /* c = t2 = l * p.x - p.y */
  48981. sp_1024_mont_sub_18(t2, t2, py, p1024_mod);
  48982. XMEMCPY(lr, l, sizeof(sp_digit) * 18);
  48983. XMEMCPY(cr, t2, sizeof(sp_digit) * 18);
  48984. }
  48985. /*
  48986. * Calc l and c when adding p and c.
  48987. *
  48988. * l = (c.y - p.y) / (c.x - p.x)
  48989. * c = (p.x * c.y - cx * p.y) / (cx - p.x)
  48990. *
  48991. * @param [out] lr Gradient result - table entry.
  48992. * @param [out] cr Constant result - table entry.
  48993. * @param [in] px X-ordinate of point to add.
  48994. * @param [in] py Y-ordinate of point to add.
  48995. * @param [in] cx X-ordinate of current point.
  48996. * @param [in] cy Y-ordinate of current point.
  48997. * @param [in] t SP temporaries (3 used).
  48998. */
  48999. static void sp_1024_accum_add_calc_lc_18(sp_digit* lr, sp_digit* cr,
  49000. const sp_digit* px, const sp_digit* py, const sp_digit* cx,
  49001. const sp_digit* cy, sp_digit* t)
  49002. {
  49003. sp_digit* t1 = t + 33 * 2 * 18;
  49004. sp_digit* c = t + 34 * 2 * 18;
  49005. sp_digit* l = t + 35 * 2 * 18;
  49006. /* l = 1 / (c.x - p.x) */
  49007. sp_1024_mont_sub_18(l, cx, px, p1024_mod);
  49008. sp_1024_mont_inv_18(l, l, t);
  49009. /* c = p.x * c.y */
  49010. sp_1024_mont_mul_18(c, px, cy, p1024_mod, p1024_mp_mod);
  49011. /* t1 = c.x * p.y */
  49012. sp_1024_mont_mul_18(t1, cx, py, p1024_mod, p1024_mp_mod);
  49013. /* c = (p.x * c.y) - (c.x * p.y) */
  49014. sp_1024_mont_sub_18(c, c, t1, p1024_mod);
  49015. /* c = ((p.x * c.y) - (c.x * p.y)) / (c.x - p.x) */
  49016. sp_1024_mont_mul_18(c, c, l, p1024_mod, p1024_mp_mod);
  49017. /* t1 = c.y - p.y */
  49018. sp_1024_mont_sub_18(t1, cy, py, p1024_mod);
  49019. /* l = (c.y - p.y) / (c.x - p.x) */
  49020. sp_1024_mont_mul_18(l, t1, l, p1024_mod, p1024_mp_mod);
  49021. XMEMCPY(lr, l, sizeof(sp_digit) * 18);
  49022. XMEMCPY(cr, c, sizeof(sp_digit) * 18);
  49023. }
  49024. /*
  49025. * Calculate vx and vy given gradient l and constant c and point q.
  49026. *
  49027. * l is a the gradient and is multiplied by q->x.
  49028. * c is a the constant that is added to the multiplicative result.
  49029. * q->y is the y-ordinate in result to multiply.
  49030. *
  49031. * if dbl
  49032. * v* = v*^2
  49033. * r.x = l * q.x + c
  49034. * r.y = q->y
  49035. * v* = v* * r*
  49036. *
  49037. * @param [in,out] vx X-ordinate of projective value in F*.
  49038. * @param [in,out] vy Y-ordinate of projective value in F*.
  49039. * @param [in] l Gradient to multiply with.
  49040. * @param [in] c Constant to add with.
  49041. * @param [in] q ECC point - second point on E(F_P^2).
  49042. * @param [in] t SP temporaries (3 used).
  49043. * @param [in] dbl Indicates whether this is for doubling. Otherwise
  49044. * adding.
  49045. */
  49046. static void sp_1024_accumulate_line_lc_18(sp_digit* vx, sp_digit* vy,
  49047. const sp_digit* l, const sp_digit* c, const sp_point_1024* q,
  49048. sp_digit* t, int dbl)
  49049. {
  49050. sp_digit* rx = t + 4 * 2 * 18;
  49051. /* v = v^2 */
  49052. if (dbl) {
  49053. sp_1024_proj_sqr_18(vx, vy, t);
  49054. }
  49055. /* rx = l * q.x + c */
  49056. sp_1024_mont_mul_18(rx, l, q->x, p1024_mod, p1024_mp_mod);
  49057. sp_1024_mont_add_18(rx, rx, c, p1024_mod);
  49058. /* v = v^2 * r */
  49059. sp_1024_proj_mul_18(vx, vy, rx, q->y, t);
  49060. }
  49061. /* Operations to perform based on order - 1.
  49062. * Sliding window. Start at bottom and stop when bottom bit is one.
  49063. * Subtract if top bit in window is one.
  49064. * Width of 6 bits.
  49065. * Pairs: #dbls, add/subtract window value
  49066. */
  49067. static const signed char sp_1024_order_op_pre[] = {
  49068. 5, 6, -13, 9, -21, 6, -5, 8, 31, 6, 3, 6, -27, 6, 25, 9,
  49069. -1, 6, -11, 6, -13, 6, -7, 6, -15, 6, -29, 7, 25, 6, -9, 6,
  49070. -19, 7, 3, 6, 11, 9, -23, 6, 1, 6, 27, 6, 1, 7, -25, 8,
  49071. 13, 7, -13, 7, -23, 10, 19, 7, 7, 7, -3, 7, 27, 6, -7, 7,
  49072. -21, 7, 11, 7, 31, 8, 1, 7, -23, 6, -17, 6, -3, 10, 11, 6,
  49073. -21, 7, -27, 11, -29, 6, -1, 10, 15, 8, 27, 7, 17, 6, 17, 7,
  49074. -13, 8, 13, 6, 21, 7, -29, 6, 19, 7, -25, 6, 11, 9, 29, 7,
  49075. -7, 8, 27, 7, 29, 10, -1, 8, -7, 8, 17, 6, 17, 7, -27, 7,
  49076. -21, 6, -9, 6, -27, 12, -23, 6, 19, 6, 13, 6, -11, 7, 27, 6,
  49077. 17, 6, -7, 6, -25, 7, -29, 6, 9, 7, 7, 6, 13, 6, -25, 6,
  49078. -19, 6, 13, 6, -11, 6, 5, 8, 19, 6, -21, 8, 23, 7, 27, 6,
  49079. -13, 6, -19, 11, 29, 7, -15, 6, -9, 7, -21, 10, -3, 7, 21, 10,
  49080. 25, 6, -15, 6, -23, 6, 21, 6, 1, 6, 21, 7, -3, 6, -3, 7,
  49081. -7, 6, -23, 7, 7, 8, 15, 9, 5, 6, -11, 6, 21, 11, -27, 7,
  49082. 27, 6, -11, 6, 31, 6, -21, 6, 19, 6, -7, 8, -7, 13, -3, 6,
  49083. -7, 7, -3, 6, 1, 6, 7, 8, 19, 8, 11, 9, -9, 7, -31, 12,
  49084. 25, 6, -17, 9, -15, 7, 5, 6, 25, 7, -5, 7, -25, 6, 17, 8,
  49085. -19, 6, -13, 6, 27, 8, 1, 7, -5, 7, -1, 6, 21, 6, 3, 10,
  49086. -3, 1,
  49087. };
  49088. /*
  49089. * Generate table for pairing.
  49090. *
  49091. * Calculate the graident (l) and constant (c) at each step of the way.
  49092. * Sliding window. Start at bottom and stop when bottom bit is one.
  49093. * Subtract if top bit in window is one.
  49094. * Width of 6 bits.
  49095. *
  49096. * pm [in] Point to generate table for.
  49097. * table [in] Generated table.
  49098. * len [in,out] On in, the size of the buffer.
  49099. * On out, length of table generated.
  49100. * @return 0 on success.
  49101. * LENGTH_ONLY_E when table is NULL and only length returned.
  49102. * BUFFER_E when len is too small.
  49103. * MEMORY_E when dynamic memory allocation fauls.
  49104. */
  49105. int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
  49106. word32* len)
  49107. {
  49108. int err = 0;
  49109. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49110. defined(WOLFSSL_SP_SMALL_STACK)
  49111. sp_digit* td = NULL;
  49112. sp_digit* t;
  49113. sp_point_1024* pre_p;
  49114. #else
  49115. sp_digit t[36 * 2 * 18];
  49116. sp_point_1024 pre_p[16];
  49117. sp_point_1024 pd;
  49118. sp_point_1024 cd;
  49119. sp_point_1024 negd;
  49120. #endif
  49121. sp_point_1024* p = NULL;
  49122. sp_point_1024* c = NULL;
  49123. sp_point_1024* neg = NULL;
  49124. int i;
  49125. int j;
  49126. int k;
  49127. sp_table_entry_1024* precomp = (sp_table_entry_1024*)table;
  49128. if (table == NULL) {
  49129. *len = sizeof(sp_table_entry_1024) * 1167;
  49130. err = LENGTH_ONLY_E;
  49131. }
  49132. if ((err == MP_OKAY) &&
  49133. (*len < (int)(sizeof(sp_table_entry_1024) * 1167))) {
  49134. err = BUFFER_E;
  49135. }
  49136. if (err == MP_OKAY) {
  49137. err = sp_1024_point_new_18(NULL, pd, p);
  49138. }
  49139. if (err == MP_OKAY) {
  49140. err = sp_1024_point_new_18(NULL, cd, c);
  49141. }
  49142. if (err == MP_OKAY) {
  49143. err = sp_1024_point_new_18(NULL, negd, neg);
  49144. }
  49145. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49146. defined(WOLFSSL_SP_SMALL_STACK)
  49147. if (err == MP_OKAY) {
  49148. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 18 * 2 + 16 *
  49149. sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49150. if (td == NULL) {
  49151. err = MEMORY_E;
  49152. }
  49153. }
  49154. #endif
  49155. if (err == MP_OKAY) {
  49156. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49157. defined(WOLFSSL_SP_SMALL_STACK)
  49158. t = td;
  49159. pre_p = (sp_point_1024*)(td + 36 * 18 * 2);
  49160. #endif
  49161. sp_1024_point_from_ecc_point_18(p, pm);
  49162. err = sp_1024_mod_mul_norm_18(p->x, p->x, p1024_mod);
  49163. }
  49164. if (err == MP_OKAY) {
  49165. err = sp_1024_mod_mul_norm_18(p->y, p->y, p1024_mod);
  49166. }
  49167. if (err == MP_OKAY) {
  49168. XMEMCPY(p->z, p1024_norm_mod, sizeof(p1024_norm_mod));
  49169. neg->infinity = 0;
  49170. c->infinity = 0;
  49171. /* Generate pre-computation table: 1, 3, ... , 31 */
  49172. XMEMCPY(&pre_p[0], p, sizeof(sp_point_1024));
  49173. /* [2]P for adding */
  49174. sp_1024_proj_point_dbl_18(c, p, t);
  49175. /* 1, 3, ... */
  49176. for (i = 1; i < 16; i++) {
  49177. sp_1024_proj_point_add_18(&pre_p[i], &pre_p[i-1], c, t);
  49178. sp_1024_mont_map_18(&pre_p[i], t);
  49179. }
  49180. k = 0;
  49181. j = sp_1024_order_op_pre[0] / 2;
  49182. XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
  49183. for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
  49184. sp_1024_accum_dbl_calc_lc_18(precomp[k].x, precomp[k].y, c->x,
  49185. c->y, t);
  49186. k++;
  49187. sp_1024_proj_point_dbl_18(c, c, t);
  49188. sp_1024_mont_map_18(c, t);
  49189. }
  49190. for (i = 2; i < 290; i += 2) {
  49191. j = sp_1024_order_op_pre[i];
  49192. if (j > 0) {
  49193. sp_1024_accum_add_calc_lc_18(precomp[k].x, precomp[k].y,
  49194. pre_p[j/2].x, pre_p[j/2].y, c->x, c->y, t);
  49195. k++;
  49196. sp_1024_proj_point_add_18(c, c, &pre_p[j/2], t);
  49197. sp_1024_mont_map_18(c, t);
  49198. }
  49199. else {
  49200. XMEMCPY(neg->x, pre_p[-j / 2].x, sizeof(pre_p->x));
  49201. sp_1024_mont_sub_18(neg->y, p1024_mod, pre_p[-j / 2].y,
  49202. p1024_mod);
  49203. XMEMCPY(neg->z, pre_p[-j / 2].z, sizeof(pre_p->z));
  49204. sp_1024_accum_add_calc_lc_18(precomp[k].x, precomp[k].y,
  49205. neg->x, neg->y, c->x, c->y, t);
  49206. k++;
  49207. sp_1024_proj_point_add_18(c, c, neg, t);
  49208. sp_1024_mont_map_18(c, t);
  49209. }
  49210. for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
  49211. sp_1024_accum_dbl_calc_lc_18(precomp[k].x, precomp[k].y, c->x,
  49212. c->y, t);
  49213. k++;
  49214. sp_1024_proj_point_dbl_18(c, c, t);
  49215. sp_1024_mont_map_18(c, t);
  49216. }
  49217. }
  49218. *len = sizeof(sp_table_entry_1024) * 1167;
  49219. }
  49220. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49221. defined(WOLFSSL_SP_SMALL_STACK)
  49222. if (td != NULL) {
  49223. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49224. }
  49225. #endif
  49226. sp_1024_point_free_18(neg, 1, NULL);
  49227. sp_1024_point_free_18(c, 1, NULL);
  49228. sp_1024_point_free_18(p, 1, NULL);
  49229. return err;
  49230. }
  49231. /*
  49232. * Calculate r = pairing <P, Q>.
  49233. *
  49234. * That is, multiply base in PF_p[q] by the scalar s, such that s.P = Q.
  49235. *
  49236. * Sliding window. Start at bottom and stop when bottom bit is one.
  49237. * Subtract if top bit in window is one.
  49238. * Width of 6 bits.
  49239. * Pre-generate values in window (1, 3, ...) - only V.
  49240. * Table contains all gradient l and a constant for each point on the path.
  49241. *
  49242. * @param [in] pm First point on E(F_p)[q].
  49243. * @param [in] qm Second point on E(F_p)[q].
  49244. * @param [in] res Result of calculation.
  49245. * @param [in] table Precomputed table of values.
  49246. * @param [in] len Length of precomputed table of values in bytes.
  49247. * @return 0 on success.
  49248. * @return MEMORY_E when dynamic memory allocation fails.
  49249. */
  49250. int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
  49251. mp_int* res, const byte* table, word32 len)
  49252. {
  49253. int err = 0;
  49254. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49255. defined(WOLFSSL_SP_SMALL_STACK)
  49256. sp_digit* td = NULL;
  49257. sp_digit* t;
  49258. sp_digit* vx;
  49259. sp_digit* vy;
  49260. sp_digit (*pre_vx)[36];
  49261. sp_digit (*pre_vy)[36];
  49262. sp_digit (*pre_nvy)[36];
  49263. #else
  49264. sp_digit t[36 * 2 * 18];
  49265. sp_digit vx[2 * 18];
  49266. sp_digit vy[2 * 18];
  49267. sp_digit pre_vx[16][36];
  49268. sp_digit pre_vy[16][36];
  49269. sp_digit pre_nvy[16][36];
  49270. sp_point_1024 pd;
  49271. sp_point_1024 qd;
  49272. sp_point_1024 cd;
  49273. #endif
  49274. sp_point_1024* p = NULL;
  49275. sp_point_1024* q = NULL;
  49276. sp_point_1024* c = NULL;
  49277. sp_digit* r = NULL;
  49278. int i;
  49279. int j;
  49280. int k;
  49281. const sp_table_entry_1024* precomp = (const sp_table_entry_1024*)table;
  49282. if (len < (int)(sizeof(sp_table_entry_1024) * 1167)) {
  49283. err = BUFFER_E;
  49284. }
  49285. if (err == MP_OKAY) {
  49286. err = sp_1024_point_new_18(NULL, pd, p);
  49287. }
  49288. if (err == MP_OKAY) {
  49289. err = sp_1024_point_new_18(NULL, qd, q);
  49290. }
  49291. if (err == MP_OKAY) {
  49292. err = sp_1024_point_new_18(NULL, cd, c);
  49293. }
  49294. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49295. defined(WOLFSSL_SP_SMALL_STACK)
  49296. if (err == MP_OKAY) {
  49297. td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 18 * 2, NULL,
  49298. DYNAMIC_TYPE_TMP_BUFFER);
  49299. if (td == NULL) {
  49300. err = MEMORY_E;
  49301. }
  49302. }
  49303. #endif
  49304. if (err == MP_OKAY) {
  49305. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49306. defined(WOLFSSL_SP_SMALL_STACK)
  49307. t = td;
  49308. vx = td + 36 * 18 * 2;
  49309. vy = td + 37 * 18 * 2;
  49310. pre_vx = (sp_digit(*)[36])(td + 38 * 18 * 2);
  49311. pre_vy = (sp_digit(*)[36])(td + 54 * 18 * 2);
  49312. pre_nvy = (sp_digit(*)[36])(td + 70 * 18 * 2);
  49313. #endif
  49314. r = vy;
  49315. sp_1024_point_from_ecc_point_18(p, pm);
  49316. sp_1024_point_from_ecc_point_18(q, qm);
  49317. err = sp_1024_mod_mul_norm_18(p->x, p->x, p1024_mod);
  49318. }
  49319. if (err == MP_OKAY) {
  49320. err = sp_1024_mod_mul_norm_18(p->y, p->y, p1024_mod);
  49321. }
  49322. if (err == MP_OKAY) {
  49323. err = sp_1024_mod_mul_norm_18(p->z, p->z, p1024_mod);
  49324. }
  49325. if (err == MP_OKAY) {
  49326. err = sp_1024_mod_mul_norm_18(q->x, q->x, p1024_mod);
  49327. }
  49328. if (err == MP_OKAY) {
  49329. err = sp_1024_mod_mul_norm_18(q->y, q->y, p1024_mod);
  49330. }
  49331. if (err == MP_OKAY) {
  49332. /* Generate pre-computation table: 1, 3, ... , 31 */
  49333. XMEMSET(pre_vx[0], 0, sizeof(sp_digit) * 2 * 18);
  49334. pre_vx[0][0] = 1;
  49335. XMEMSET(pre_vy[0], 0, sizeof(sp_digit) * 2 * 18);
  49336. sp_1024_mont_sub_18(pre_nvy[0], p1024_mod, pre_vy[0], p1024_mod);
  49337. /* [2]P for adding */
  49338. XMEMCPY(c, p, sizeof(sp_point_1024));
  49339. XMEMSET(vx, 0, sizeof(sp_digit) * 2 * 18);
  49340. vx[0] = 1;
  49341. XMEMSET(vy, 0, sizeof(sp_digit) * 2 * 18);
  49342. sp_1024_accumulate_line_dbl_18(vx, vy, c, q, t);
  49343. /* 3, 5, ... */
  49344. for (i = 1; i < 16; i++) {
  49345. XMEMCPY(pre_vx[i], pre_vx[i-1], sizeof(sp_digit) * 2 * 18);
  49346. XMEMCPY(pre_vy[i], pre_vy[i-1], sizeof(sp_digit) * 2 * 18);
  49347. sp_1024_proj_mul_18(pre_vx[i], pre_vy[i], vx, vy, t);
  49348. sp_1024_accumulate_line_add_n_18(pre_vx[i], pre_vy[i], c,
  49349. q, p, t, 0);
  49350. sp_1024_mont_sub_18(pre_nvy[i], p1024_mod, pre_vy[i],
  49351. p1024_mod);
  49352. }
  49353. XMEMCPY(c->z, p1024_norm_mod, sizeof(sp_digit) * 18);
  49354. c->infinity = 0;
  49355. j = sp_1024_order_op_pre[0] / 2;
  49356. XMEMCPY(vx, pre_vx[j], sizeof(sp_digit) * 2 * 18);
  49357. XMEMCPY(vy, pre_vy[j], sizeof(sp_digit) * 2 * 18);
  49358. k = 0;
  49359. for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
  49360. /* Accumulate line into v and double point. */
  49361. sp_1024_accumulate_line_lc_18(vx, vy, precomp[k].x,
  49362. precomp[k].y, q, t, 1);
  49363. k++;
  49364. }
  49365. for (i = 2; i < 290; i += 2) {
  49366. sp_1024_accumulate_line_lc_18(vx, vy, precomp[k].x,
  49367. precomp[k].y, q, t, 0);
  49368. k++;
  49369. j = sp_1024_order_op_pre[i];
  49370. if (j > 0) {
  49371. j /= 2;
  49372. /* Accumulate line into v. */
  49373. sp_1024_proj_mul_18(vx, vy, pre_vx[j], pre_vy[j], t);
  49374. }
  49375. else {
  49376. j = -j / 2;
  49377. /* Accumulate line into v. */
  49378. sp_1024_proj_mul_18(vx, vy, pre_vx[j], pre_nvy[j], t);
  49379. }
  49380. for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
  49381. /* Accumulate line into v and double point. */
  49382. sp_1024_accumulate_line_lc_18(vx, vy, precomp[k].x,
  49383. precomp[k].y, q, t, 1);
  49384. k++;
  49385. }
  49386. }
  49387. /* Final exponentiation */
  49388. sp_1024_proj_sqr_18(vx, vy, t);
  49389. sp_1024_proj_sqr_18(vx, vy, t);
  49390. /* Convert from PF_p[q] to F_p */
  49391. sp_1024_mont_inv_18(vx, vx, t);
  49392. sp_1024_mont_mul_18(r, vx, vy, p1024_mod, p1024_mp_mod);
  49393. XMEMSET(r + 18, 0, sizeof(sp_digit) * 18);
  49394. sp_1024_mont_reduce_18(r, p1024_mod, p1024_mp_mod);
  49395. err = sp_1024_to_mp(r, res);
  49396. }
  49397. #if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
  49398. defined(WOLFSSL_SP_SMALL_STACK)
  49399. if (td != NULL) {
  49400. XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49401. }
  49402. #endif
  49403. sp_1024_point_free_18(c, 1, NULL);
  49404. sp_1024_point_free_18(q, 1, NULL);
  49405. sp_1024_point_free_18(p, 1, NULL);
  49406. return err;
  49407. }
  49408. #endif /* WOLFSSL_SP_SMALL */
  49409. #ifdef HAVE_ECC_CHECK_KEY
  49410. /* Read big endian unsigned byte array into r.
  49411. *
  49412. * r A single precision integer.
  49413. * size Maximum number of bytes to convert
  49414. * a Byte array.
  49415. * n Number of bytes in array to read.
  49416. */
  49417. static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n)
  49418. {
  49419. int i;
  49420. int j = 0;
  49421. word32 s = 0;
  49422. r[0] = 0;
  49423. for (i = n-1; i >= 0; i--) {
  49424. r[j] |= (((sp_digit)a[i]) << s);
  49425. if (s >= 49U) {
  49426. r[j] &= 0x1ffffffffffffffL;
  49427. s = 57U - s;
  49428. if (j + 1 >= size) {
  49429. break;
  49430. }
  49431. r[++j] = (sp_digit)a[i] >> s;
  49432. s = 8U - s;
  49433. }
  49434. else {
  49435. s += 8U;
  49436. }
  49437. }
  49438. for (j++; j < size; j++) {
  49439. r[j] = 0;
  49440. }
  49441. }
  49442. /* Check that the x and y oridinates are a valid point on the curve.
  49443. *
  49444. * point EC point.
  49445. * heap Heap to use if dynamically allocating.
  49446. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  49447. * not on the curve and MP_OKAY otherwise.
  49448. */
  49449. static int sp_1024_ecc_is_point_18(const sp_point_1024* point,
  49450. void* heap)
  49451. {
  49452. #ifdef WOLFSSL_SP_SMALL_STACK
  49453. sp_digit* t1 = NULL;
  49454. #else
  49455. sp_digit t1[18 * 4];
  49456. #endif
  49457. sp_digit* t2 = NULL;
  49458. sp_int64 n;
  49459. int err = MP_OKAY;
  49460. #ifdef WOLFSSL_SP_SMALL_STACK
  49461. t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 4, heap, DYNAMIC_TYPE_ECC);
  49462. if (t1 == NULL)
  49463. err = MEMORY_E;
  49464. #endif
  49465. (void)heap;
  49466. if (err == MP_OKAY) {
  49467. t2 = t1 + 2 * 18;
  49468. /* y^2 - x^3 - a.x = b */
  49469. sp_1024_sqr_18(t1, point->y);
  49470. (void)sp_1024_mod_18(t1, t1, p1024_mod);
  49471. sp_1024_sqr_18(t2, point->x);
  49472. (void)sp_1024_mod_18(t2, t2, p1024_mod);
  49473. sp_1024_mul_18(t2, t2, point->x);
  49474. (void)sp_1024_mod_18(t2, t2, p1024_mod);
  49475. sp_1024_mont_sub_18(t1, t1, t2, p1024_mod);
  49476. /* y^2 - x^3 + 3.x = b, when a = -3 */
  49477. sp_1024_mont_add_18(t1, t1, point->x, p1024_mod);
  49478. sp_1024_mont_add_18(t1, t1, point->x, p1024_mod);
  49479. sp_1024_mont_add_18(t1, t1, point->x, p1024_mod);
  49480. n = sp_1024_cmp_18(t1, p1024_mod);
  49481. sp_1024_cond_sub_18(t1, t1, p1024_mod, ~(n >> 56));
  49482. sp_1024_norm_18(t1);
  49483. if (!sp_1024_iszero_18(t1)) {
  49484. err = MP_VAL;
  49485. }
  49486. }
  49487. #ifdef WOLFSSL_SP_SMALL_STACK
  49488. if (t1 != NULL)
  49489. XFREE(t1, heap, DYNAMIC_TYPE_ECC);
  49490. #endif
  49491. return err;
  49492. }
  49493. /* Check that the x and y oridinates are a valid point on the curve.
  49494. *
  49495. * pX X ordinate of EC point.
  49496. * pY Y ordinate of EC point.
  49497. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  49498. * not on the curve and MP_OKAY otherwise.
  49499. */
  49500. int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY)
  49501. {
  49502. #ifdef WOLFSSL_SP_SMALL_STACK
  49503. sp_point_1024* pub = NULL;
  49504. #else
  49505. sp_point_1024 pub[1];
  49506. #endif
  49507. const byte one[1] = { 1 };
  49508. int err = MP_OKAY;
  49509. #ifdef WOLFSSL_SP_SMALL_STACK
  49510. pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL,
  49511. DYNAMIC_TYPE_ECC);
  49512. if (pub == NULL)
  49513. err = MEMORY_E;
  49514. #endif
  49515. if (err == MP_OKAY) {
  49516. sp_1024_from_mp(pub->x, 18, pX);
  49517. sp_1024_from_mp(pub->y, 18, pY);
  49518. sp_1024_from_bin(pub->z, 18, one, (int)sizeof(one));
  49519. err = sp_1024_ecc_is_point_18(pub, NULL);
  49520. }
  49521. #ifdef WOLFSSL_SP_SMALL_STACK
  49522. if (pub != NULL)
  49523. XFREE(pub, NULL, DYNAMIC_TYPE_ECC);
  49524. #endif
  49525. return err;
  49526. }
  49527. /* Check that the private scalar generates the EC point (px, py), the point is
  49528. * on the curve and the point has the correct order.
  49529. *
  49530. * pX X ordinate of EC point.
  49531. * pY Y ordinate of EC point.
  49532. * privm Private scalar that generates EC point.
  49533. * returns MEMORY_E if dynamic memory allocation fails, MP_VAL if the point is
  49534. * not on the curve, ECC_INF_E if the point does not have the correct order,
  49535. * ECC_PRIV_KEY_E when the private scalar doesn't generate the EC point and
  49536. * MP_OKAY otherwise.
  49537. */
  49538. int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY,
  49539. const mp_int* privm, void* heap)
  49540. {
  49541. #ifdef WOLFSSL_SP_SMALL_STACK
  49542. sp_digit* priv = NULL;
  49543. sp_point_1024* pub = NULL;
  49544. #else
  49545. sp_digit priv[18];
  49546. sp_point_1024 pub[2];
  49547. #endif
  49548. sp_point_1024* p = NULL;
  49549. const byte one[1] = { 1 };
  49550. int err = MP_OKAY;
  49551. /* Quick check the lengs of public key ordinates and private key are in
  49552. * range. Proper check later.
  49553. */
  49554. if (((mp_count_bits(pX) > 1024) ||
  49555. (mp_count_bits(pY) > 1024) ||
  49556. ((privm != NULL) && (mp_count_bits(privm) > 1024)))) {
  49557. err = ECC_OUT_OF_RANGE_E;
  49558. }
  49559. #ifdef WOLFSSL_SP_SMALL_STACK
  49560. if (err == MP_OKAY) {
  49561. pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap,
  49562. DYNAMIC_TYPE_ECC);
  49563. if (pub == NULL)
  49564. err = MEMORY_E;
  49565. }
  49566. if (err == MP_OKAY && privm) {
  49567. priv = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18, heap,
  49568. DYNAMIC_TYPE_ECC);
  49569. if (priv == NULL)
  49570. err = MEMORY_E;
  49571. }
  49572. #endif
  49573. if (err == MP_OKAY) {
  49574. p = pub + 1;
  49575. sp_1024_from_mp(pub->x, 18, pX);
  49576. sp_1024_from_mp(pub->y, 18, pY);
  49577. sp_1024_from_bin(pub->z, 18, one, (int)sizeof(one));
  49578. if (privm)
  49579. sp_1024_from_mp(priv, 18, privm);
  49580. /* Check point at infinitiy. */
  49581. if ((sp_1024_iszero_18(pub->x) != 0) &&
  49582. (sp_1024_iszero_18(pub->y) != 0)) {
  49583. err = ECC_INF_E;
  49584. }
  49585. }
  49586. /* Check range of X and Y */
  49587. if ((err == MP_OKAY) &&
  49588. ((sp_1024_cmp_18(pub->x, p1024_mod) >= 0) ||
  49589. (sp_1024_cmp_18(pub->y, p1024_mod) >= 0))) {
  49590. err = ECC_OUT_OF_RANGE_E;
  49591. }
  49592. if (err == MP_OKAY) {
  49593. /* Check point is on curve */
  49594. err = sp_1024_ecc_is_point_18(pub, heap);
  49595. }
  49596. if (err == MP_OKAY) {
  49597. /* Point * order = infinity */
  49598. err = sp_1024_ecc_mulmod_18(p, pub, p1024_order, 1, 1, heap);
  49599. }
  49600. /* Check result is infinity */
  49601. if ((err == MP_OKAY) && ((sp_1024_iszero_18(p->x) == 0) ||
  49602. (sp_1024_iszero_18(p->y) == 0))) {
  49603. err = ECC_INF_E;
  49604. }
  49605. if (privm) {
  49606. if (err == MP_OKAY) {
  49607. /* Base * private = point */
  49608. err = sp_1024_ecc_mulmod_base_18(p, priv, 1, 1, heap);
  49609. }
  49610. /* Check result is public key */
  49611. if ((err == MP_OKAY) &&
  49612. ((sp_1024_cmp_18(p->x, pub->x) != 0) ||
  49613. (sp_1024_cmp_18(p->y, pub->y) != 0))) {
  49614. err = ECC_PRIV_KEY_E;
  49615. }
  49616. }
  49617. #ifdef WOLFSSL_SP_SMALL_STACK
  49618. if (pub != NULL)
  49619. XFREE(pub, heap, DYNAMIC_TYPE_ECC);
  49620. if (priv != NULL)
  49621. XFREE(priv, heap, DYNAMIC_TYPE_ECC);
  49622. #endif
  49623. return err;
  49624. }
  49625. #endif
  49626. #endif /* WOLFSSL_SP_1024 */
  49627. #endif /* WOLFCRYPT_HAVE_SAKKE */
  49628. #endif /* WOLFSSL_HAVE_SP_ECC */
  49629. #endif /* SP_WORD_SIZE == 64 */
  49630. #endif /* !WOLFSSL_SP_ASM */
  49631. #endif /* WOLFSSL_HAVE_SP_RSA | WOLFSSL_HAVE_SP_DH | WOLFSSL_HAVE_SP_ECC */