test.c 2.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000
  1. /* test.c
  2. *
  3. * Copyright (C) 2006-2024 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. /*
  22. * Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. *
  26. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  27. * WC_USE_DEVID=0x1234
  28. */
  29. #ifdef HAVE_CONFIG_H
  30. #include <config.h>
  31. #endif
  32. #ifndef WOLFSSL_USER_SETTINGS
  33. #include <wolfssl/options.h>
  34. #endif
  35. #include <wolfssl/wolfcrypt/settings.h>
  36. #ifdef WOLFSSL_DEBUG_TRACE_ERROR_CODES
  37. #define WOLFSSL_DEBUG_TRACE_ERROR_CODES_ALWAYS
  38. #endif
  39. #ifndef NO_CRYPT_TEST
  40. #include <wolfssl/version.h>
  41. #include <wolfssl/wolfcrypt/types.h>
  42. #include <wolfssl/wolfcrypt/wc_port.h>
  43. #include <wolfssl/wolfcrypt/mem_track.h>
  44. #if defined(HAVE_WOLFCRYPT_TEST_OPTIONS)
  45. #include <wolfssl/ssl.h>
  46. #define err_sys err_sys_remap /* remap err_sys */
  47. #include <wolfssl/test.h>
  48. #undef err_sys
  49. #endif
  50. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  51. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  52. #include <stdint.h>
  53. #endif
  54. #ifdef HAVE_STACK_SIZE_VERBOSE
  55. #ifdef WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES
  56. static WC_MAYBE_UNUSED ssize_t max_relative_stack =
  57. WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES;
  58. #else
  59. static WC_MAYBE_UNUSED ssize_t max_relative_stack = -1;
  60. #endif
  61. #endif
  62. const byte const_byte_array[] = "A+Gd\0\0\0";
  63. #define CBPTR_EXPECTED 'A'
  64. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  65. #ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS
  66. static ssize_t max_relative_heap_allocs = WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS;
  67. #else
  68. static ssize_t max_relative_heap_allocs = -1;
  69. #endif
  70. #ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_BYTES
  71. static ssize_t max_relative_heap_bytes = WOLFSSL_TEST_MAX_RELATIVE_HEAP_BYTES;
  72. #else
  73. static ssize_t max_relative_heap_bytes = -1;
  74. #endif
  75. #define PRINT_HEAP_CHECKPOINT() { \
  76. const ssize_t _rha = wolfCrypt_heap_peakAllocs_checkpoint() - heap_baselineAllocs; \
  77. const ssize_t _rhb = wolfCrypt_heap_peakBytes_checkpoint() - heap_baselineBytes; \
  78. printf(" relative heap peak usage: %ld alloc%s, %ld bytes\n", \
  79. (long int)_rha, \
  80. _rha == 1 ? "" : "s", \
  81. (long int)_rhb); \
  82. if ((max_relative_heap_allocs > 0) && (_rha > max_relative_heap_allocs)) \
  83. return err_sys("heap allocs exceed designated max.", \
  84. WC_TEST_RET_ENC_NC); \
  85. if ((max_relative_heap_bytes > 0) && (_rhb > max_relative_heap_bytes)) \
  86. return err_sys("heap bytes exceed designated max.", \
  87. WC_TEST_RET_ENC_NC); \
  88. heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint(); \
  89. heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint(); \
  90. }
  91. #else
  92. #define PRINT_HEAP_CHECKPOINT() WC_DO_NOTHING
  93. #endif /* WOLFSSL_TRACK_MEMORY_VERBOSE && !WOLFSSL_STATIC_MEMORY */
  94. #ifdef USE_FLAT_TEST_H
  95. #ifdef HAVE_CONFIG_H
  96. #include "test_paths.h"
  97. #endif
  98. #include "test.h"
  99. #else
  100. #ifdef HAVE_CONFIG_H
  101. #include "wolfcrypt/test/test_paths.h"
  102. #endif
  103. #include "wolfcrypt/test/test.h"
  104. #endif
  105. /* printf mappings */
  106. #ifndef WOLFSSL_LOG_PRINTF
  107. #if defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
  108. #include <mqx.h>
  109. #include <stdlib.h>
  110. /* see wc_port.h for fio.h and nio.h includes */
  111. #elif defined(FREESCALE_KSDK_BM)
  112. #include "fsl_debug_console.h"
  113. #undef printf
  114. #define printf PRINTF
  115. #elif defined(WOLFSSL_APACHE_MYNEWT)
  116. #include <assert.h>
  117. #include <string.h>
  118. #include "sysinit/sysinit.h"
  119. #include "os/os.h"
  120. #ifdef ARCH_sim
  121. #include "mcu/mcu_sim.h"
  122. #endif
  123. #include "os/os_time.h"
  124. #elif defined(WOLFSSL_ESPIDF)
  125. #include <time.h>
  126. #include <sys/time.h>
  127. #include <esp_log.h>
  128. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  129. #define ESPIDF_TAG "wc_test"
  130. #elif defined(WOLFSSL_ZEPHYR)
  131. #include <stdio.h>
  132. #define printf printk
  133. #elif defined(MICRIUM)
  134. #include <os.h>
  135. #if (OS_VERSION < 50000)
  136. #include <bsp_ser.h>
  137. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  138. #undef printf
  139. #define printf BSP_Ser_Printf
  140. #else
  141. #include <stdio.h>
  142. #endif
  143. #elif defined(WOLFSSL_PB)
  144. #include <stdarg.h>
  145. int wolfssl_pb_print(const char*, ...);
  146. #undef printf
  147. #define printf wolfssl_pb_print
  148. #elif defined(WOLFSSL_TELIT_M2MB)
  149. #include "wolfssl/wolfcrypt/wc_port.h" /* for m2mb headers */
  150. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  151. /* remap printf */
  152. #undef printf
  153. #define printf M2M_LOG_INFO
  154. /* OS requires occasional sleep() */
  155. #ifndef TEST_SLEEP_MS
  156. #define TEST_SLEEP_MS 50
  157. #endif
  158. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  159. /* don't use file system for these tests, since ./certs dir isn't loaded */
  160. #undef NO_FILESYSTEM
  161. #define NO_FILESYSTEM
  162. #elif defined(THREADX) && !defined(WOLFSSL_WICED) && \
  163. !defined(THREADX_NO_DC_PRINTF)
  164. #ifndef NETOS
  165. /* since just testing, use THREADX log printf instead (NETOS prototypes
  166. * this elsewhere) */
  167. int dc_log_printf(char*, ...);
  168. #endif
  169. #undef printf
  170. #define printf dc_log_printf
  171. #elif defined(ANDROID)
  172. #ifdef XMALLOC_USER
  173. #include <stdlib.h> /* we're using malloc / free direct here */
  174. #endif
  175. #ifndef STRING_USER
  176. #include <stdio.h>
  177. #endif
  178. #include <android/log.h>
  179. #ifdef ANDROID_V454 /* See fips/android/wolfCrypt_v454_android */
  180. #ifndef NO_FILESYSTEM
  181. #define NO_FILESYSTEM /* Turn off tests that want to call SaveDerAndPem() */
  182. #endif
  183. #else
  184. #define printf(...) \
  185. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  186. #define fprintf(fp, ...) \
  187. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  188. #endif
  189. #elif defined(WOLFSSL_DEOS)
  190. #include <printx.h>
  191. #undef printf
  192. #define printf printx
  193. #elif defined(WOLFSSL_RENESAS_RSIP)
  194. #ifndef TEST_SLEEP
  195. #define TEST_SLEEP() vTaskDelay(50)
  196. #endif
  197. #undef vprintf
  198. #define vprintf rsip_vprintf
  199. #include <stdarg.h> /* for var args */
  200. int rsip_vprintf(const char* restrict format, va_list args)
  201. {
  202. int ret;
  203. char tmpBuf[80];
  204. ret = XVSNPRINTF(tmpBuf, sizeof(tmpBuf), format, args);
  205. printf(tmpBuf);
  206. return ret;
  207. }
  208. #else
  209. #ifdef XMALLOC_USER
  210. #include <stdlib.h> /* we're using malloc / free direct here */
  211. #endif
  212. #if !defined(STRING_USER) && !defined(WOLFSSL_LINUXKM)
  213. #include <stdio.h>
  214. #endif
  215. #if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_LINUXKM_VERBOSE_DEBUG)
  216. #undef printf
  217. #define printf(...) ({})
  218. #endif
  219. /* enable way for customer to override test/bench printf */
  220. #ifdef XPRINTF
  221. #undef printf
  222. #define printf XPRINTF
  223. #elif !defined(printf)
  224. /* arrange for printf() to flush after every message -- this assures
  225. * redirected output (to a log file) records progress right up to the
  226. * moment of a crash/abort(); otherwise anything queued in stdout would
  227. * be lost.
  228. */
  229. #define printf(...) ( printf(__VA_ARGS__), fflush(stdout) )
  230. #endif
  231. #endif
  232. #endif /* !WOLFSSL_LOG_PRINTF */
  233. #include <wolfssl/wolfcrypt/memory.h>
  234. #include <wolfssl/wolfcrypt/wc_port.h>
  235. #include <wolfssl/wolfcrypt/logging.h>
  236. #include <wolfssl/wolfcrypt/types.h>
  237. #include <wolfssl/wolfcrypt/asn.h>
  238. #include <wolfssl/wolfcrypt/md2.h>
  239. #include <wolfssl/wolfcrypt/md5.h>
  240. #include <wolfssl/wolfcrypt/md4.h>
  241. #include <wolfssl/wolfcrypt/sha.h>
  242. #include <wolfssl/wolfcrypt/sha256.h>
  243. #include <wolfssl/wolfcrypt/sha512.h>
  244. #include <wolfssl/wolfcrypt/hash.h>
  245. #include <wolfssl/wolfcrypt/rc2.h>
  246. #include <wolfssl/wolfcrypt/arc4.h>
  247. #if !defined(WC_NO_RNG)
  248. #include <wolfssl/wolfcrypt/random.h>
  249. #endif
  250. #include <wolfssl/wolfcrypt/wolfmath.h>
  251. #include <wolfssl/wolfcrypt/coding.h>
  252. #include <wolfssl/wolfcrypt/signature.h>
  253. #include <wolfssl/wolfcrypt/rsa.h>
  254. #include <wolfssl/wolfcrypt/des3.h>
  255. #include <wolfssl/wolfcrypt/aes.h>
  256. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  257. #include <wolfssl/wolfcrypt/cmac.h>
  258. #include <wolfssl/wolfcrypt/siphash.h>
  259. #include <wolfssl/wolfcrypt/poly1305.h>
  260. #include <wolfssl/wolfcrypt/camellia.h>
  261. #include <wolfssl/wolfcrypt/hmac.h>
  262. #include <wolfssl/wolfcrypt/kdf.h>
  263. #include <wolfssl/wolfcrypt/dh.h>
  264. #include <wolfssl/wolfcrypt/dsa.h>
  265. #include <wolfssl/wolfcrypt/srp.h>
  266. #include <wolfssl/wolfcrypt/chacha.h>
  267. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  268. #include <wolfssl/wolfcrypt/pwdbased.h>
  269. #include <wolfssl/wolfcrypt/ripemd.h>
  270. #include <wolfssl/wolfcrypt/error-crypt.h>
  271. #ifdef HAVE_ECC
  272. #include <wolfssl/wolfcrypt/ecc.h>
  273. #endif
  274. #ifdef WOLFSSL_SM2
  275. #include <wolfssl/wolfcrypt/sm2.h>
  276. #endif
  277. #ifdef HAVE_HPKE
  278. #include <wolfssl/wolfcrypt/hpke.h>
  279. #endif
  280. #ifdef HAVE_CURVE25519
  281. #include <wolfssl/wolfcrypt/curve25519.h>
  282. #endif
  283. #ifdef HAVE_ED25519
  284. #include <wolfssl/wolfcrypt/ed25519.h>
  285. #endif
  286. #ifdef HAVE_CURVE448
  287. #include <wolfssl/wolfcrypt/curve448.h>
  288. #endif
  289. #ifdef HAVE_ED448
  290. #include <wolfssl/wolfcrypt/ed448.h>
  291. #endif
  292. #ifdef WOLFSSL_HAVE_KYBER
  293. #include <wolfssl/wolfcrypt/kyber.h>
  294. #ifdef WOLFSSL_WC_KYBER
  295. #include <wolfssl/wolfcrypt/wc_kyber.h>
  296. #endif
  297. #if defined(HAVE_LIBOQS)
  298. #include <wolfssl/wolfcrypt/ext_kyber.h>
  299. #endif
  300. #endif
  301. #ifdef HAVE_DILITHIUM
  302. #include <wolfssl/wolfcrypt/dilithium.h>
  303. #endif
  304. #if defined(WOLFSSL_HAVE_XMSS)
  305. #include <wolfssl/wolfcrypt/xmss.h>
  306. #ifdef HAVE_LIBXMSS
  307. #include <wolfssl/wolfcrypt/ext_xmss.h>
  308. #else
  309. #include <wolfssl/wolfcrypt/wc_xmss.h>
  310. #endif
  311. #endif
  312. #if defined(WOLFSSL_HAVE_LMS)
  313. #include <wolfssl/wolfcrypt/lms.h>
  314. #ifdef HAVE_LIBLMS
  315. #include <wolfssl/wolfcrypt/ext_lms.h>
  316. #else
  317. #include <wolfssl/wolfcrypt/wc_lms.h>
  318. #endif
  319. #endif
  320. #ifdef WOLFCRYPT_HAVE_ECCSI
  321. #include <wolfssl/wolfcrypt/eccsi.h>
  322. #endif
  323. #ifdef WOLFCRYPT_HAVE_SAKKE
  324. #include <wolfssl/wolfcrypt/sakke.h>
  325. #endif
  326. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  327. #include <wolfssl/wolfcrypt/blake2.h>
  328. #endif
  329. #ifdef WOLFSSL_SHA3
  330. #include <wolfssl/wolfcrypt/sha3.h>
  331. #endif
  332. #ifdef WOLFSSL_SM3
  333. #include <wolfssl/wolfcrypt/sm3.h>
  334. #endif
  335. #ifdef WOLFSSL_SM4
  336. #include <wolfssl/wolfcrypt/sm4.h>
  337. #endif
  338. #ifdef HAVE_LIBZ
  339. #include <wolfssl/wolfcrypt/compress.h>
  340. #endif
  341. #ifdef HAVE_PKCS7
  342. #include <wolfssl/wolfcrypt/pkcs7.h>
  343. #endif
  344. #ifdef HAVE_PKCS12
  345. #include <wolfssl/wolfcrypt/pkcs12.h>
  346. #endif
  347. #ifdef HAVE_FIPS
  348. #include <wolfssl/wolfcrypt/fips_test.h>
  349. #endif
  350. #ifdef HAVE_SELFTEST
  351. #include <wolfssl/wolfcrypt/selftest.h>
  352. #endif
  353. #ifdef WOLFSSL_ASYNC_CRYPT
  354. #include <wolfssl/wolfcrypt/async.h>
  355. #endif
  356. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  357. #include <wolfssl/wolfcrypt/logging.h>
  358. #endif
  359. #ifdef WOLFSSL_CAAM
  360. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  361. #endif
  362. #ifdef WOLF_CRYPTO_CB
  363. #include <wolfssl/wolfcrypt/cryptocb.h>
  364. #ifdef HAVE_INTEL_QA_SYNC
  365. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  366. #endif
  367. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  368. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  369. #endif
  370. #ifdef HAVE_RENESAS_SYNC
  371. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  372. #endif
  373. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  374. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  375. #endif
  376. #endif
  377. #ifdef _MSC_VER
  378. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  379. #pragma warning(disable: 4996)
  380. #endif
  381. #ifdef OPENSSL_EXTRA
  382. #ifndef WOLFCRYPT_ONLY
  383. #include <wolfssl/openssl/evp.h>
  384. #include <wolfssl/openssl/hmac.h>
  385. #endif
  386. #include <wolfssl/openssl/rand.h>
  387. #include <wolfssl/openssl/aes.h>
  388. #include <wolfssl/openssl/des.h>
  389. #endif
  390. #if defined(NO_FILESYSTEM) || defined(WC_NO_RNG)
  391. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  392. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  393. #define USE_CERT_BUFFERS_2048
  394. #endif
  395. #if !defined(USE_CERT_BUFFERS_256)
  396. #define USE_CERT_BUFFERS_256
  397. #endif
  398. #endif
  399. #if defined(WOLFSSL_CERT_GEN) && (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  400. #define ENABLE_ECC384_CERT_GEN_TEST
  401. #endif
  402. #include <wolfssl/certs_test.h>
  403. #ifdef DEVKITPRO
  404. #include <wiiuse/wpad.h>
  405. #endif
  406. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  407. /* FIPS build has replaced ecc.h. */
  408. #define wc_ecc_key_get_priv(key) (&((key)->k))
  409. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  410. #endif
  411. #ifdef WOLFSSL_STATIC_MEMORY
  412. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  413. #else
  414. #define HEAP_HINT NULL
  415. #endif /* WOLFSSL_STATIC_MEMORY */
  416. /* these cases do not have intermediate hashing support */
  417. #if (defined(WOLFSSL_AFALG_XILINX_SHA3) && !defined(WOLFSSL_AFALG_HASH_KEEP)) \
  418. && !defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  419. #define NO_INTM_HASH_TEST
  420. #endif
  421. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  422. defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY) || \
  423. defined(WOLFSSL_SECO_CAAM)
  424. #define HASH_SIZE_LIMIT
  425. #endif
  426. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  427. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  428. static void initDefaultName(void);
  429. #endif
  430. /* for async devices */
  431. #ifdef WOLFSSL_CAAM_DEVID
  432. static int devId = WOLFSSL_CAAM_DEVID;
  433. #else
  434. #ifdef WC_USE_DEVID
  435. static int devId = WC_USE_DEVID;
  436. #else
  437. static int devId = INVALID_DEVID;
  438. #endif
  439. #endif
  440. #ifdef HAVE_WNR
  441. const char* wnrConfigFile = "wnr-example.conf";
  442. #endif
  443. #define TEST_STRING "Everyone gets Friday off."
  444. #define TEST_STRING_SZ 25
  445. typedef struct testVector {
  446. const char* input;
  447. const char* output;
  448. size_t inLen;
  449. size_t outLen;
  450. } testVector;
  451. #ifndef WOLFSSL_TEST_SUBROUTINE
  452. #define WOLFSSL_TEST_SUBROUTINE
  453. #endif
  454. PRAGMA_GCC("GCC diagnostic ignored \"-Wunused-function\"")
  455. PRAGMA_CLANG("clang diagnostic ignored \"-Wunused-function\"")
  456. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void);
  457. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void);
  458. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void);
  459. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void);
  460. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void);
  461. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void);
  462. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void);
  463. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void);
  464. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void);
  465. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void);
  466. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void);
  467. #if !defined(WOLFSSL_NOSHA512_224) && \
  468. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  469. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void);
  470. #endif
  471. #if !defined(WOLFSSL_NOSHA512_256) && \
  472. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  473. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void);
  474. #endif
  475. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void);
  476. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void);
  477. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void);
  478. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void);
  479. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void);
  480. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void);
  481. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void);
  482. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void);
  483. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void);
  484. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void);
  485. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void);
  486. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void);
  487. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void);
  488. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  489. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  490. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  491. defined(WOLFSSL_AFALG_XILINX_RSA)
  492. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  493. static wc_test_ret_t hkdf_test(void);
  494. #else
  495. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void);
  496. #endif
  497. #endif /* HAVE_HKDF && ! NO_HMAC */
  498. #ifdef WOLFSSL_HAVE_PRF
  499. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  500. #ifdef WOLFSSL_BASE16
  501. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void);
  502. #endif /* WOLFSSL_BASE16 */
  503. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  504. #endif /* WOLFSSL_HAVE_PRF */
  505. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  506. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void);
  507. #endif
  508. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void);
  509. #ifdef WOLFSSL_TLS13
  510. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void);
  511. #endif
  512. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void);
  513. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void);
  514. #ifdef WC_SRTP_KDF
  515. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void);
  516. #endif
  517. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void);
  518. #ifdef WC_RC2
  519. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void);
  520. #endif
  521. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void);
  522. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void);
  523. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void);
  524. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void);
  525. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void);
  526. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void);
  527. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void);
  528. #if defined(WOLFSSL_AES_CFB)
  529. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void);
  530. #endif
  531. #ifdef WOLFSSL_AES_XTS
  532. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void);
  533. #endif
  534. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void);
  535. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void);
  536. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void);
  537. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void);
  538. #if defined(WOLFSSL_SIPHASH)
  539. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void);
  540. #endif
  541. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void);
  542. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void);
  543. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void);
  544. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void);
  545. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void);
  546. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void);
  547. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void);
  548. #ifdef WOLFSSL_SM4
  549. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void);
  550. #endif
  551. #ifdef WC_RSA_NO_PADDING
  552. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void);
  553. #endif
  554. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void);
  555. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void);
  556. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void);
  557. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void);
  558. #ifndef WC_NO_RNG
  559. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void);
  560. #endif /* WC_NO_RNG */
  561. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void);
  562. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void);
  563. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void);
  564. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  565. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void); /* test mini api */
  566. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void);
  567. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void);
  568. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void);
  569. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void);
  570. #endif
  571. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void);
  572. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void);
  573. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  574. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void);
  575. #endif
  576. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
  577. #ifdef HAVE_ECC
  578. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void);
  579. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  580. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  581. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void);
  582. #endif
  583. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  584. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  585. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  586. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  587. /* skip for ATECC508/608A, cannot import private key buffers */
  588. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void);
  589. #endif
  590. #endif
  591. #ifdef HAVE_CURVE25519
  592. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void);
  593. #endif
  594. #ifdef HAVE_ED25519
  595. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void);
  596. #endif
  597. #ifdef HAVE_CURVE448
  598. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void);
  599. #endif
  600. #ifdef HAVE_ED448
  601. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void);
  602. #endif
  603. #ifdef WOLFSSL_HAVE_KYBER
  604. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void);
  605. #endif
  606. #ifdef HAVE_DILITHIUM
  607. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void);
  608. #endif
  609. #if defined(WOLFSSL_HAVE_XMSS)
  610. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  611. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void);
  612. #endif
  613. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  614. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void);
  615. #endif
  616. #endif
  617. #if defined(WOLFSSL_HAVE_LMS)
  618. #if !defined(WOLFSSL_SMALL_STACK)
  619. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
  620. defined(HAVE_LIBLMS)
  621. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void);
  622. #endif
  623. #endif
  624. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  625. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void);
  626. #endif
  627. #endif
  628. #ifdef WOLFCRYPT_HAVE_ECCSI
  629. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void);
  630. #endif
  631. #ifdef WOLFCRYPT_HAVE_SAKKE
  632. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void);
  633. #endif
  634. #ifdef HAVE_BLAKE2
  635. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void);
  636. #endif
  637. #ifdef HAVE_BLAKE2S
  638. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void);
  639. #endif
  640. #ifdef HAVE_LIBZ
  641. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void);
  642. #endif
  643. #ifdef HAVE_PKCS7
  644. #ifndef NO_PKCS7_ENCRYPTED_DATA
  645. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void);
  646. #endif
  647. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  648. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void);
  649. #endif
  650. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void);
  651. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void);
  652. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  653. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void);
  654. #endif
  655. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  656. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key,
  657. word32 keySz);
  658. #endif
  659. #endif
  660. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  661. !defined(NO_FILESYSTEM)
  662. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void);
  663. #endif
  664. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  665. !defined(NO_FILESYSTEM) && defined(WOLFSSL_CERT_GEN)
  666. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void);
  667. #endif
  668. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  669. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  670. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void);
  671. #endif
  672. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void);
  673. #if defined(WOLFSSL_PUBLIC_MP) && \
  674. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  675. defined(USE_FAST_MATH))
  676. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void);
  677. #endif
  678. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  679. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void);
  680. #endif
  681. #ifdef ASN_BER_TO_DER
  682. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void);
  683. #endif
  684. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void);
  685. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  686. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void);
  687. #endif
  688. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  689. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void);
  690. #else
  691. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void);
  692. #endif
  693. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  694. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void);
  695. #endif
  696. #ifdef WOLFSSL_CAAM_BLOB
  697. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void);
  698. #endif
  699. #ifdef HAVE_ARIA
  700. #include "wolfssl/wolfcrypt/port/aria/aria-crypt.h"
  701. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz);
  702. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID);
  703. #endif
  704. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  705. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void);
  706. #endif
  707. #ifdef WOLFSSL_CERT_PIV
  708. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void);
  709. #endif
  710. #ifdef WOLFSSL_AES_SIV
  711. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void);
  712. #endif
  713. #if defined(WOLFSSL_AES_EAX) && \
  714. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  715. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void);
  716. #endif /* WOLFSSL_AES_EAX */
  717. /* General big buffer size for many tests. */
  718. #define FOURK_BUF 4096
  719. /* If not defined in user_settings, the ERROR_OUT pause is 120 seconds. */
  720. #ifndef WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION
  721. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION 120
  722. #endif
  723. #if defined(WOLFSSL_ESPIDF_ERROR_PAUSE)
  724. #if defined(CONFIG_FREERTOS_HZ)
  725. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  726. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * CONFIG_FREERTOS_HZ)
  727. #else
  728. /* If not defined, assume RTOS is 1000 ticks per second. */
  729. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  730. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * 1000)
  731. #endif
  732. /* When defined, pause at error condition rather than exit with error. */
  733. #define ERROR_OUT(err, eLabel) \
  734. do { \
  735. ret = (err); \
  736. ESP_LOGE(ESPIDF_TAG, "Failed: Error = %d during %s, line %d", \
  737. err, __FUNCTION__, __LINE__); \
  738. ESP_LOGI(ESPIDF_TAG, "Extended system info:"); \
  739. esp_ShowExtendedSystemInfo(); \
  740. ESP_LOGW(ESPIDF_TAG, "Paused for %d seconds! " \
  741. "WOLFSSL_ESPIDF_ERROR_PAUSE is enabled.", \
  742. WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION); \
  743. vTaskDelay(WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS); \
  744. goto eLabel; \
  745. } while (0)
  746. #else
  747. #define ERROR_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  748. #endif
  749. /* Not all unexpected conditions are actually errors .*/
  750. #define WARNING_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  751. static void render_error_message(const char* msg, wc_test_ret_t es)
  752. {
  753. (void)msg;
  754. (void)es;
  755. #ifdef WOLFSSL_LINUXKM
  756. #define err_sys_printf lkm_printf
  757. #else
  758. #define err_sys_printf printf
  759. #endif
  760. switch (WC_TEST_RET_DEC_TAG(es)) {
  761. case WC_TEST_RET_TAG_NC:
  762. err_sys_printf("%s error L=%d\n", msg, WC_TEST_RET_DEC_LN(es));
  763. break;
  764. case WC_TEST_RET_TAG_EC:
  765. #ifdef NO_ERROR_STRINGS
  766. err_sys_printf("%s error L=%d code=%d\n", msg,
  767. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es));
  768. #elif defined(WOLFCRYPT_ONLY) || !defined(WOLFSSL_TYPES_DEFINED)
  769. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  770. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  771. wc_GetErrorString(-WC_TEST_RET_DEC_I(es))
  772. );
  773. #else
  774. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  775. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  776. wolfSSL_ERR_reason_error_string(-WC_TEST_RET_DEC_I(es))
  777. );
  778. #endif
  779. break;
  780. case WC_TEST_RET_TAG_ERRNO:
  781. {
  782. /* strerror_r() comes in two mutually incompatible flavors, a native glibc
  783. * flavor that always returns a non-null char pointer that must be used
  784. * directly, and a POSIX flavor that returns an error int, and iff success,
  785. * stores an error string in the supplied buffer. this is all most
  786. * infelicitous...
  787. */
  788. #if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
  789. (defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
  790. ((defined(__GLIBC__) && (__GLIBC__ >= 2)) || \
  791. (defined(__USE_XOPEN2K) && \
  792. defined(_POSIX_C_SOURCE) && \
  793. (_POSIX_C_SOURCE >= 200112L)))
  794. char errno_buf[64], *errno_string;
  795. /* precisely mirror the gate used in glibc string.h */
  796. #if defined __USE_XOPEN2K && !defined __USE_GNU
  797. if (strerror_r(WC_TEST_RET_DEC_I(es),
  798. errno_buf, sizeof(errno_buf)) != 0)
  799. XSTRLCPY(errno_buf, "?", sizeof(errno_buf));
  800. errno_string = errno_buf;
  801. #else
  802. errno_string = strerror_r(WC_TEST_RET_DEC_I(es),
  803. errno_buf, sizeof(errno_buf));
  804. #endif
  805. err_sys_printf("%s error L=%d errno=%d (%s)\n", msg,
  806. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es),
  807. errno_string);
  808. #else /* can't figure out how to strerror_r(), or don't want error strings */
  809. err_sys_printf("%s error L=%d errno=%d\n", msg,
  810. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  811. #endif
  812. break;
  813. }
  814. case WC_TEST_RET_TAG_I:
  815. err_sys_printf("%s error L=%d i=%d\n", msg,
  816. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  817. break;
  818. }
  819. #undef err_sys_printf
  820. }
  821. static void print_fiducials(void);
  822. #ifdef HAVE_STACK_SIZE
  823. static THREAD_RETURN err_sys(const char* msg, int es)
  824. #else
  825. static wc_test_ret_t err_sys(const char* msg, wc_test_ret_t es)
  826. #endif
  827. {
  828. render_error_message(msg, es);
  829. print_fiducials();
  830. #ifdef WOLFSSL_LINUXKM
  831. EXIT_TEST(es);
  832. #else
  833. EXIT_TEST(-1);
  834. #endif
  835. }
  836. #ifndef HAVE_WOLFCRYPT_TEST_OPTIONS
  837. /* func_args from test.h, so don't have to pull in other stuff */
  838. typedef struct func_args {
  839. int argc;
  840. char** argv;
  841. wc_test_ret_t return_code;
  842. } func_args;
  843. #endif /* !HAVE_WOLFCRYPT_TEST_OPTIONS */
  844. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  845. static void myFipsCb(int ok, int err, const char* hash)
  846. {
  847. printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
  848. printf("message = %s\n", wc_GetErrorString(err));
  849. printf("hash = %s\n", hash);
  850. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  851. printf("In core integrity hash check failure, copy above hash\n");
  852. printf("into verifyCore[] in fips_test.c and rebuild\n");
  853. }
  854. }
  855. #endif /* HAVE_FIPS && !WOLFSSL_LINUXKM */
  856. #ifdef WOLFSSL_STATIC_MEMORY
  857. #if defined(WOLFSSL_STATIC_MEMORY_TEST_SZ)
  858. static byte gTestMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  859. #elif defined(BENCH_EMBEDDED)
  860. static byte gTestMemory[14000];
  861. #elif defined(WOLFSSL_CERT_EXT)
  862. static byte gTestMemory[140000];
  863. #elif (defined(WOLFSSL_SP_MATH_ALL) || defined(USE_FAST_MATH)) && \
  864. !defined(ALT_ECC_SIZE)
  865. static byte gTestMemory[160000];
  866. #else
  867. static byte gTestMemory[80000];
  868. #endif
  869. #endif
  870. #ifdef WOLFSSL_PB
  871. static int wolfssl_pb_print(const char* msg, ...)
  872. {
  873. int ret;
  874. va_list args;
  875. char tmpBuf[80];
  876. va_start(args, msg);
  877. ret = vsprint(tmpBuf, msg, args);
  878. va_end(args);
  879. fnDumpStringToSystemLog(tmpBuf);
  880. return ret;
  881. }
  882. #endif /* WOLFSSL_PB */
  883. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  884. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  885. /* Enable support for RNG with crypto callback */
  886. static int rng_crypto_cb(int thisDevId, wc_CryptoInfo* info, void* ctx)
  887. {
  888. int rc = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  889. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  890. rc = wc_GenerateSeed(&info->rng.rng->seed, info->rng.out, info->rng.sz);
  891. }
  892. (void)ctx;
  893. (void)thisDevId;
  894. return rc;
  895. }
  896. #endif
  897. #if defined(WC_KDF_NIST_SP_800_56C)
  898. #define INIT_SP80056C_TEST_VECTOR(_z, _fixedInfo, _derivedKey, _hashType) \
  899. { \
  900. .z = (const byte*)_z, .zSz = sizeof(_z) - 1, \
  901. .fixedInfo = (const byte*)_fixedInfo, \
  902. .fixedInfoSz = sizeof(_fixedInfo) - 1, \
  903. .derivedKey = (const byte*)_derivedKey, \
  904. .derivedKeySz = sizeof(_derivedKey) - 1, .hashType = _hashType, \
  905. }
  906. #define SP800_56C_MAX_OUT 128
  907. static WOLFSSL_TEST_SUBROUTINE wc_test_ret_t nist_sp80056c_kdf_test(void)
  908. {
  909. struct sp800_56c_test_vector {
  910. const byte* z;
  911. word32 zSz;
  912. const byte* fixedInfo;
  913. word32 fixedInfoSz;
  914. const byte* derivedKey;
  915. word32 derivedKeySz;
  916. enum wc_HashType hashType;
  917. };
  918. struct sp800_56c_test_vector* v;
  919. byte output[SP800_56C_MAX_OUT];
  920. word32 i;
  921. int ret;
  922. /* vectors from
  923. * https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
  924. *
  925. * (KeyManagement) */
  926. struct sp800_56c_test_vector vctors[] = {
  927. #if !defined(NO_SHA)
  928. /* SHA-1 */
  929. INIT_SP80056C_TEST_VECTOR(
  930. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  931. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  932. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  933. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  934. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  935. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  936. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  937. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  938. WC_HASH_TYPE_SHA),
  939. INIT_SP80056C_TEST_VECTOR(
  940. "\xae\x64\xab\x2b\x2b\x75\xa9\x4c\xf8\xef\x24\xda\x24\x56\xbd\x3a"
  941. "\xa3\x6d\xb6\x14\x29\xea\x55\x21",
  942. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  943. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  944. "\xcc\x96\x5a\x52\xd0\x5c\x94\x9e\x52\xc0\x35\xfd\x03\x53\x0d\xb7"
  945. "\xea\xa4\x08\x70\x2c\x9d\x35\x21\x1e\x67\x21\x54\x12\x45\x91\x51"
  946. "\xba\x22\x62\xbd\x1e\x28\xe5\x6b",
  947. WC_HASH_TYPE_SHA),
  948. INIT_SP80056C_TEST_VECTOR(
  949. "\x71\x5d\xc0\xea\x24\x6b\x46\x56\x63\xa8\x9c\xde\x04\x12\xc1\x92"
  950. "\xe1\x9e\x58\xd5\xb0\xb6\x36\x6d\xa7\x89\xad\xbf\x44\x9a\x38\xaa"
  951. "\x46\x69\xfe\x36\x30\xa2\x0f\x7f\xa3\x14\x9c\x9b\x4b\x0a\xb5\xcd"
  952. "\x3e\x14\x18\x2b\x75\x04\xd5\xd2\x75\x2b\xf6\x58\x7a\xab\xc9\xf4"
  953. "\xcb\x8f\xe5\x29\x23\x6a\xb8\x15\x36\xad\xd2\xbd\x25\xd6\xbf\x9d"
  954. "\x5f\x1d\xf5\x76\x16\x5a\xa5\x5c\x24\x99\x61\xd8\xf8\x75\x00\xed"
  955. "\x8d\xbf\xc5\xd2\x50\x53\x4c\x07\xd9\x9a\xc9\x17\xf9\x84\x60\x46"
  956. "\xac\x5c\xb8\xa2\x98\x74\x26\x22\xd3\xc9\x86\x18\x06\x92\x46\xe8"
  957. "\xad\x37\x11\x25\x57\xe0\xe6\x34\xb5\x81\x32\x7a\x4a\xd3\x2c\x7c"
  958. "\x76\x4b\xe8\xf8\x08\x0d\x37\x2c\x63\x20\x93\xa7\x67\xf1\x55\xbd"
  959. "\x22\xec\x00\x3c\xa6\x1c\x8b\x43\x32\x0f\x3a\xbe\xb5\xdd\xc4\xa3"
  960. "\xb1\x89\x82\xfd\xd6\x51\x0f\x88\x3c\x8d\xc1\xe0\xb1\x57\xff\xb9"
  961. "\xcf\xc0\xa5\x9c\xe2\xd4\x05\x5f\xfc\x73\xe7\x15\x2a\x6a\x95\x43"
  962. "\xb9\x19\xe7\x94\xe9\x49\x61\x33\xbe\x2a\x23\x18\xd9\x05\x6e\xfd"
  963. "\x74\x48\x2d\xc6\x3c\x0d\xb5\x8f\xe6\x42\x6b\x0f\xe7\x35\x45\x42"
  964. "\xc2\x19\x7a\xb6\xbd\x35\xf1\xa9\x2d\xce\x90\xb1\xc4\x6d\x32\xc1",
  965. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  966. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  967. "\x1b\x5f\xcc\x8d\x81\xa5\xd9\xa9\x36\x94\xe6\x47\x77\x88\xd8\x03"
  968. "\x15\x84\xc3\xf5\x2e\x9f\x11\x7a\xe8\x18\x4d\xba\x56\x47\x9d\x87"
  969. "\x66\x76\x92\xf1\x2d\x7b\xd3\x8b",
  970. WC_HASH_TYPE_SHA),
  971. INIT_SP80056C_TEST_VECTOR(
  972. "\x33\xe0\x50\xbd\x20\x9f\x2d\xf2\x77\x19\x78\xfc\xd1\xd4\xc8\x2e"
  973. "\x49\xd0\x1d\x65\xbb\x62\x03\x20\xd3\x0b\xfe\xa8\x7a\xa8\x69\xe1"
  974. "\x07\xa5\x17\xa4\xc8\x5b\x69\x28\x45\x21\xca\x54\xb7\x7f\x59\xe9"
  975. "\x4a\x85\x6d\xaa\x30\xa3\x85\xa5\x25\xd8\xa3\xf7\xe1\x5e\xe5\xe9"
  976. "\xaa\x12\x8d\x45\xef\x63\xf9\x0c\x10\xe0\x8f\xc5\x26\x36\x13\x77"
  977. "\x81\x54\x7a\x58\x9f\x97\x87\xf9\xd7\xdd\x61\x43\x41\x9a\x26\x16"
  978. "\x80\x16\x82\x40\xaa\xb2\x01\x3d\x80\x20\xdb\xe8\x4b\x7e\x2b\xed"
  979. "\xce\x67\x1b\x94\x03\xbd\x1f\x91\x71\xa2\x57\x90\xce\x66\x7d\xed",
  980. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  981. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  982. "\x35\x10\x85\x85\xfc\x55\x62\xb5\xf1\x8f\x20\x7b\xa8\x35\x63\xe4"
  983. "\x49\x28\x45\x6a\x5e\x53\x63\x7e\xae\x6b\xb5\xfc\x33\x88\xae\x02"
  984. "\x91\x79\x0a\x1d\xc8\x31\x4e\x28",
  985. WC_HASH_TYPE_SHA),
  986. INIT_SP80056C_TEST_VECTOR(
  987. "\x5c\x80\x4f\x45\x4d\x30\xd9\xc4\xdf\x85\x27\x1f\x93\x52\x8c\x91"
  988. "\xdf\x6b\x48\xab\x5f\x80\xb3\xb5\x9c\xaa\xc1\xb2\x8f\x8a\xcb\xa9"
  989. "\xcd\x3e\x39\xf3\xcb\x61\x45\x25\xd9\x52\x1d\x2e\x64\x4c\x53\xb8"
  990. "\x07\xb8\x10\xf3\x40\x06\x2f\x25\x7d\x7d\x6f\xbf\xe8\xd5\xe8\xf0"
  991. "\x72\xe9\xb6\xe9\xaf\xda\x94\x13\xea\xfb\x2e\x8b\x06\x99\xb1\xfb"
  992. "\x5a\x0c\xac\xed\xde\xae\xad\x7e\x9c\xfb\xb3\x6a\xe2\xb4\x20\x83"
  993. "\x5b\xd8\x3a\x19\xfb\x0b\x5e\x96\xbf\x8f\xa4\xd0\x9e\x34\x55\x25"
  994. "\x16\x7e\xcd\x91\x55\x41\x6f\x46\xf4\x08\xed\x31\xb6\x3c\x6e\x6d",
  995. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  996. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  997. "\xfa\xa0\x22\xce\x7f\xa9\xba\x95\xeb\xa3\x9f\x3f\x44\xf3\xee\x14"
  998. "\x96\x0a\x0b\x23\x9d\x01\x4b\x57\x70\xe4\x71\xd7\x5a\x99\xea\x87"
  999. "\x10\xe3\x8f\x0c\xef\x0f\xfc\x67",
  1000. WC_HASH_TYPE_SHA),
  1001. INIT_SP80056C_TEST_VECTOR(
  1002. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  1003. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  1004. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  1005. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1006. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1007. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  1008. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  1009. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  1010. WC_HASH_TYPE_SHA),
  1011. #endif
  1012. #if defined(WOLFSSL_SHA224)
  1013. /* SHA-224*/
  1014. INIT_SP80056C_TEST_VECTOR(
  1015. "\x8c\x5d\x6e\x5d\x36\x06\x83\xba\x55\xb0\x9d\xb1\x69\x6d\x7c\x64"
  1016. "\x02\xff\x87\x88\x5f\xf5\x07\x70\xf2\x76\x7b\x75\x54\x60\x20\x7e"
  1017. "\xd5\xc7\x43\xfd\x27\xe7\xeb\x1d\x0c\xa5\x91\xf8\x56\x38\x93\x11"
  1018. "\x73\x07\x44\xf2\x04\xd2\xe5\x5b\x8b\xd4\x46\xce\xca\x03\x1f\x7b"
  1019. "\xac\xcf\xf1\xa7\x1b\x68\x34\x59\xcc\x54\xd5\x01\xda\xbf\x4a\x84"
  1020. "\xcd\xb8\x6d\xfa\xda\xff\x31\x0f\xbd\xba\xf7\x4d\xd5\x1b\xa1\xe1"
  1021. "\xe1\x19\x1a\xf1\x4c\x9b\xf8\x94\x43\xbf\x58\x8e\x9c\xe3\x30\x34"
  1022. "\xaf\x5e\x89\xbf\x6f\xfc\x47\xd7\xd9\xca\x4a\x5e\x8f\xf8\xa0\x50"
  1023. "\x20\xbb\x0f\x95\xbc\xde\x01\x56\xd8\x7f\xb8\x60\xbd\x40\x83\xfa"
  1024. "\x5b\x53\x1a\x08\xa4\xfb\x7e\xe0\x20\x1a\xe8\xb3\xcc\xff\xe9\x9f"
  1025. "\x27\x0b\xc3\x53\x4b\xaa\xcf\xc0\x01\xcd\xd8\x0a\xd8\x7c\xce\x71"
  1026. "\xf0\x91\xe7\x66\xca\x5c\xc2\x75\xcb\x49\x14\x5a\x5e\xe6\x16\x2e"
  1027. "\xcc\xf5\x58\xce\xc4\xd3\xee\x53\x1e\x91\xe9\xa5\x29\x69\x63\x4d"
  1028. "\x3a\xf8\xd2\x6f\x8d\x15\xdc\x0d\x6f\x6e\x0a\x97\x4b\xe4\x34\x1b"
  1029. "\x68\xa0\x19\x90\xdb\xb8\x64\x95\x89\x1a\xd3\xaf\xc1\xe4\xce\xdf"
  1030. "\x4c\x6a\xe1\xf1\xcd\x60\x81\xcd\xee\xd8\xe6\xb3\x26\x4e\xc3\xbe"
  1031. "\x24\x58\xd1\xc0\xca\x24\x43\x41\x0c\xf3\xb4\x7c\x0c\x25\x4c\x7d"
  1032. "\xc8\xec\xb4\x3e\x6c\x23\x64\xe1\xc0\x62\x19\xcc\x7e\xfb\xff\xbb"
  1033. "\x63\xd7\xff\xfc\x74\x58\x12\xfd\x24\x0c\x33\xd4\x96\xb9\x99\x2f"
  1034. "\x96\x80\xa6\x3c\x07\x96\x3c\x0c\x49\xf3\xc1\xba\xef\xec\xaf\x32"
  1035. "\xe2\xaa\x8a\x2f\x7c\xd3\x0d\x8f\x05\x1e\xe2\xf5\x0f\xbf\x05\xab"
  1036. "\x13\x96\xa4\xea\x87\x44\x7d\x7b\x98\x1b\x5e\x46\x14\x28\x18\x71"
  1037. "\xa6\xf0\xf6\xbf\x1f\xe0\x02\x2f\x7e\xa1\x32\xbe\x0a\xe9\x19\x26"
  1038. "\xab\x12\xaf\x6d\xc4\x50\x64\xaa\xd5\x6b\x84\xb9\x0c\x70\x08\x37"
  1039. "\x09\xcf\xf7\xe3\x1b\x54\x8f\xb7\xfb\x2c\xf7\x5a\xbf\x96\xe0\x1c"
  1040. "\xcd\x3e\x94\x2e\xed\x91\x48\x0d\x4c\x24\xc6\xb7\xf9\x79\xfb\xbe"
  1041. "\x5d\xa2\x39\xb3\x76\x16\x7d\x68\x57\x35\x24\xff\xcb\x50\x99\x54"
  1042. "\xcc\x80\xa0\xe1\xa7\x1c\x40\xc4\xda\x17\xb8\xd1\x57\x2b\x21\x58"
  1043. "\x7a\x8d\x66\xcc\x62\x1c\x7c\xd1\x0f\x49\xab\xd5\xef\x86\x31\x13"
  1044. "\xe6\x19\x21\x08\x6f\xac\x25\x31\x2b\x74\x1c\x11\xa8\xfb\xc1\xe3"
  1045. "\x3c\x34\xd9\xda\x14\xa8\x22\x47\x7f\xcc\x36\x66\x70\x25\xc4\xf1"
  1046. "\x30\xae\x10\x0e\x36\xf1\x5d\xa0\x03\x74\xce\x87\x41\x67\x9f\x61",
  1047. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1048. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1049. "\x4b\x99\x6a\x60\xc0\x4a\x35\xc5\xe6\xd4\x74\xb1\x0a\x25\x8d\x56"
  1050. "\x2e\xa6\xdc\x52\xf6\xc6\x9b\xf3\x9e\xf8\x8c\x89\xe3\xcc\x8a\x54"
  1051. "\xda\x2f\x3c\x0b\x56\x1b\x53\xfe\x76\x55\x13\x63\xd6\x9c\x3c\xef"
  1052. "\x74\xe3\x4f\xe8\x8e\xb3\xac\x51",
  1053. WC_HASH_TYPE_SHA224),
  1054. INIT_SP80056C_TEST_VECTOR(
  1055. "\x52\x27\x2f\x50\xf4\x6f\x4e\xdc\x91\x51\x56\x90\x92\xf4\x6d\xf2"
  1056. "\xd9\x6e\xcc\x3b\x6d\xc1\x71\x4a\x4e\xa9\x49\xfa\x9f\x18\xff\x54"
  1057. "\xf8\x87\x23\x07\x3f\x64\xa6\x95\x3d\x04\x91\x4f\x45\xa2\x3e\xee"
  1058. "\x7c\xfc\x46\x67\x08\x0a\xa0\xf9",
  1059. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1060. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1061. "\x77\x56\xbc\xfd\xef\x3e\xe6\x9f\x6a\xc2\x3c\xd2\xdc\x60\x7d\x01"
  1062. "\xfa\x8c\xe1\xb2\x4f\x5c\xaa\xaa\x48\xe0\x4b\x81\x63\xe1\x73\x3a"
  1063. "\xed\x7a\x04\x0e\x73\xf2\xb5\x42\x36\x8f\x00\x54\x8b\x16\x3c\x3d"
  1064. "\xc9\x6d\x70\x09\x99\x16\xf1\x6b",
  1065. WC_HASH_TYPE_SHA224),
  1066. #endif
  1067. #if !defined(NO_SHA256)
  1068. /* SHA-256 */
  1069. INIT_SP80056C_TEST_VECTOR(
  1070. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1071. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1072. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1073. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  1074. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1075. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1076. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1077. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1078. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1079. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc\xa6",
  1080. WC_HASH_TYPE_SHA256),
  1081. INIT_SP80056C_TEST_VECTOR(
  1082. "\x44\xf4\x84\x09\xf3\x1b\xf3\x50\x94\x51\xdb\x4d\x30\x4b\xeb\xd8"
  1083. "\x3c\x2a\xd6\x50\x1c\x1b\x85\xe6\x32\xbc\x92\x58\x8e\x2d\x48\xb5"
  1084. "\xd2\xb8\x44\x44\x62\xad\x94\xe8\xa4\x44\x94\x1e\xd4\x97\x5c\x97"
  1085. "\x91\x17\xd7\x5a\x0a\x2b\xa8\x10\xdf\xa8\x80\x4a\x0f\xe9\x42\x6d"
  1086. "\xd7\xeb\x95\xf2\x9c\xa4\x30\xda\x37\xef\xa5\x2c\x42\xda\x1d\xe2"
  1087. "\x23\x76\x3b\xdd\xc9\x5e\x46\x6a\xa3\xb8\xd2\x06\xb8\x21\x8e\xdf"
  1088. "\x23\x97\x3d\x05\xf3\xc7\xc2\x2b\x22\x46\x53\xd4\xf9\x21\x85\x45"
  1089. "\x79\x83\x26\x2f\x27\xbc\x55\xa0\xa7\xae\xe5\x43\x54\x55\xd4\x3c"
  1090. "\x0e\x0c\x6d\x80\x67\xad\xaf\x90\x42\xb6\xb7\x77\x7e\x19\x8d\x67"
  1091. "\x60\x83\x0d\x96\xb2\x9a\x6a\xae\xf5\x74\xd7\x5e\x2d\x65\x43\x55"
  1092. "\x0f\x75\x55\xcf\x89\x82\xc8\x21\xc4\xec\x9b\x82\x66\x2b\x09\x36"
  1093. "\x69\xfd\x24\x6d\x4d\xcc\xbf\xf3\x1d\x98\x4e\xf6\x3c\x4f\x95\xd7"
  1094. "\x39\xc7\x7e\x66\xf6\x9b\x6d\xb0\xd9\xfc\x1a\x97\x3f\x52\x33\xd1"
  1095. "\x1f\xe7\x15\x4b\x8a\x6b\xe1\x50\x46\x7d\x92\xda\xf0\x91\x44\x34"
  1096. "\xf0\xcf\x17\x6e\x96\x1b\x31\x3f\xe3\xe2\x3b\xfe\x37\x8b\x87\xba"
  1097. "\xf2\x73\x93\x7f\xfa\xa6\x85\x65\x8b\x09\x78\x1d\x26\x97\x86\x4b"
  1098. "\x0d\x82\x48\x5c\xf7\xd6\x2f\xfc\xea\x34\x33\x88\xcf\xec\x15\x27"
  1099. "\x3a\x39\x4b\x84\x32\xee\xb6\x32\x1b\xe3\x1d\x4f\xcd\x16\x15\xc8"
  1100. "\x1c\x69\x37\xc0\x8d\x92\x41\x6e\xdb\xdd\x20\x10\xfa\x8b\x6e\x0a"
  1101. "\x8a\x60\x3d\xad\xe0\x10\xbc\x9c\xd7\x6b\x14\xe3\xe2\x19\x0e\x3b"
  1102. "\xa3\x00\xe7\x1a\xdd\xbf\x24\x4c\xf8\x06\x29\x49\x76\xea\xf0\x7d"
  1103. "\x02\x3b\xdb\x57\xfc\x5d\x19\x64\xc7\xd4\x20\x6e\x72\x06\x1b\xfe"
  1104. "\x1e\xe4\xee\xbc\x92\x00\xe1\x3a\x6c\xba\x32\x86\x9d\xbe\x80\x82"
  1105. "\xcd\xf3\x64\x5b\x5a\x72\x7d\xd2\x7c\xa5\x03\xf4\xed\xeb\x73\xe8"
  1106. "\x8a\x3a\x55\x2c\x7e\x00\xd4\xee\x72\x42\x13\x72\x36\xa0\x96\x5c"
  1107. "\x1e\xc3\xeb\xc0\xb4\x8c\x2b\x46\x7e\xb8\x42\x41\x5a\x28\x3f\x55"
  1108. "\xe2\x20\xff\xd1\x88\x19\x25\x6d\xa2\x47\x4d\x28\xfc\x3b\x04\xe0"
  1109. "\xc0\x7e\x4d\x25\xc1\x74\x93\x41\xd2\x22\x97\x01\x5c\xd8\x17\x8c"
  1110. "\x39\x18\xbe\x8c\x5c\xdf\x0f\xbf\xbb\x9a\x5a\xcc\xdd\x82\xaf\x07"
  1111. "\x83\xef\xe4\xdf\x64\xa8\xd8\x92\x82\x8f\x8d\xe5\x8c\x5d\x56\x9b"
  1112. "\x5b\x08\x45\x58\x96\xc4\xd3\xc3\x4f\xd3\xce\x93\xc4\x34\xc3\x8e"
  1113. "\xf5\x6c\xed\x30\x56\x1c\x37\x1a\xf9\xf2\xd8\x64\xfd\xc5\xb6\x2f",
  1114. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1115. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1116. "\x42\x35\xac\x89\xc9\xf3\x3e\x5d\xbb\x11\x60\x1a\x29\x83\xe3\x76"
  1117. "\xe2\x15\x39\x97\x87\xd8\x39\xa0\x38\x55\xfe\x04\x53\x3e\x1a\x67"
  1118. "\x66\x91\x5e\x67\xc2\x5e\xeb\x04\x08\x28\xe9\x6c\xd3\xd6\xef\x0a"
  1119. "\xb7\xd1\x7b\x43\x13\x43\xa7\xf3\xaa\xc6\x8f\x0c\x4a\x7e\x77\x9b",
  1120. WC_HASH_TYPE_SHA256),
  1121. /* slightly modified vector to test generation when derivedKeySz %
  1122. * hashOutSz != 0*/
  1123. INIT_SP80056C_TEST_VECTOR(
  1124. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1125. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1126. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1127. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  1128. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1129. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1130. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1131. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1132. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1133. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc",
  1134. WC_HASH_TYPE_SHA256),
  1135. #endif
  1136. #if defined(WOLFSSL_SHA384)
  1137. /* SHA-384 */
  1138. INIT_SP80056C_TEST_VECTOR(
  1139. "\x5e\xa1\xfc\x4a\xf7\x25\x6d\x20\x55\x98\x1b\x11\x05\x75\xe0\xa8"
  1140. "\xca\xe5\x31\x60\x13\x7d\x90\x4c\x59\xd9\x26\xeb\x1b\x84\x56\xe4"
  1141. "\x27\xaa\x8a\x45\x40\x88\x4c\x37\xde\x15\x9a\x58\x02\x8a\xbc\x0e"
  1142. "\x88\x76\x9c\xb7\x2f\xc5\xac\x45\x7c\xd5\x8e\x89\x08\x9b\x19\x6a"
  1143. "\x70\xbf\x53\x3c\x6d\xc9\x1c\x9c\x7e\x17\x41\xdb\x5e\x7a\xb6\xb0"
  1144. "\x84\x9f\x01\xde\xa6\x5f\xed\xd0\x6c\x77\x18\x7c\xd8\x8e\xd0\x30",
  1145. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1146. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1147. "\x8e\x6e\x26\x5f\x20\x82\xf1\x4d\x34\xda\x23\xe1\x03\x2c\x90\x24"
  1148. "\x83\x4a\xf0\x15\x72\xb6\x64\x77\x82\x41\x1b\xdd\xcb\x84\xa5\xda"
  1149. "\xee\x11\x7b\xa6\xfb\xa6\xd0\xeb\x28\x08\xef\x8a\xb0\x70\x05\xee"
  1150. "\xab\xe5\x2d\x2e\xfd\x31\x12\x1c\x7b\xf9\xd5\xfa\xfc\x40\xe0\x0c"
  1151. "\x6d\x6d\xbf\x39\xef\x43\xfe\x97\x15\xc7\x20\x2c\xdc\x2d\xb7\xe8"
  1152. "\x2b\x88\xd7\x48\xeb\x84\x25\x8b\xf8\x4d\x85\x82\xf2\xbf\xd9\x40",
  1153. WC_HASH_TYPE_SHA384),
  1154. #endif
  1155. #if defined(WOLFSSL_SHA512)
  1156. /* SHA-512 */
  1157. INIT_SP80056C_TEST_VECTOR(
  1158. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1159. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1160. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1161. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1162. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1163. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1164. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1165. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1166. "\xde\x34\x54\xe4",
  1167. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1168. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1169. "\x2d\x4a\x46\xa1\x70\x99\xba\xa8\x33\x0b\xc5\x9d\x4a\x1c\xf5\xae"
  1170. "\x3a\x30\x75\xb4\xc6\x2b\xb2\x6e\x7f\xc9\x89\x24\x72\x6d\x27\x4c"
  1171. "\x09\x64\x6f\x44\x08\xe6\x85\x8c\x43\xb4\x2d\xae\xd0\x15\xef\x26"
  1172. "\x17\x08\xd5\x5e\xf2\x4d\xaa\x7d\x3e\xa3\xd1\xc4\xa0\x8c\xfd\x24"
  1173. "\xdb\x60\x00\xa5\xb8\xa6\x7d\xe7\x46\xf3\xd3\xf4\xff\x34\x85\x15"
  1174. "\x8f\xd3\xb6\x91\x55\x79\x1d\xf4\x67\x47\xd4\xdb\xbe\x17\xc4\xb5"
  1175. "\x58\x46\x2e\x26\xbe\x5e\xd3\x5f\xe6\x80\xe2\x97\x14\x22\xc3\xb0"
  1176. "\x1b\x17\xe1\x67\xfc\x43\x7f\x84\x86\x9d\x85\x49\x53\x7b\x33\x38",
  1177. WC_HASH_TYPE_SHA512),
  1178. #endif
  1179. INIT_SP80056C_TEST_VECTOR(
  1180. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1181. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1182. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1183. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1184. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1185. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1186. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1187. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1188. "\xde\x34\x54\xe4",
  1189. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1190. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1191. "\x2d\x4a",
  1192. WC_HASH_TYPE_SHA512),
  1193. };
  1194. for (i = 0; i < sizeof(vctors) / sizeof(vctors[0]); i++) {
  1195. v = &vctors[i];
  1196. ret = wc_KDA_KDF_onestep(v->z, v->zSz, v->fixedInfo, v->fixedInfoSz,
  1197. v->derivedKeySz, v->hashType, output,
  1198. /* use derivedKeySz to force the function to use a temporary buff
  1199. for the last block */
  1200. v->derivedKeySz);
  1201. if (ret != 0)
  1202. return WC_TEST_RET_ENC_EC(ret);
  1203. if (XMEMCMP(output, v->derivedKey, v->derivedKeySz) != 0)
  1204. return WC_TEST_RET_ENC_NC;
  1205. }
  1206. /* negative tests */
  1207. ret = wc_KDA_KDF_onestep(NULL, 0, (byte*)"fixed_info",
  1208. sizeof("fixed_info"), 16, WC_HASH_TYPE_SHA256, output, 16);
  1209. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1210. return WC_TEST_RET_ENC_NC;
  1211. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 1, 16,
  1212. WC_HASH_TYPE_SHA256, output, 16);
  1213. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1214. return WC_TEST_RET_ENC_NC;
  1215. /* allow empty FixedInfo */
  1216. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 0, 16,
  1217. WC_HASH_TYPE_SHA256, output, 16);
  1218. if (ret != 0)
  1219. return WC_TEST_RET_ENC_EC(ret);
  1220. return 0;
  1221. }
  1222. #endif /* WC_KDF_NIST_SP_800_56C */
  1223. /* optional macro to add sleep between tests */
  1224. #ifndef TEST_SLEEP
  1225. #define TEST_SLEEP() WC_DO_NOTHING
  1226. #else
  1227. #define TEST_PASS test_pass
  1228. #include <stdarg.h> /* for var args */
  1229. static WC_INLINE void test_pass(const char* fmt, ...)
  1230. {
  1231. va_list args;
  1232. va_start(args, fmt);
  1233. STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK(max_relative_stack, vprintf(fmt, args));
  1234. va_end(args);
  1235. PRINT_HEAP_CHECKPOINT();
  1236. TEST_SLEEP();
  1237. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1););
  1238. }
  1239. #endif
  1240. /* set test pass output to printf if not overridden */
  1241. #ifndef TEST_PASS
  1242. /* redirect to printf */
  1243. #define TEST_PASS(...) { \
  1244. if (STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK \
  1245. (max_relative_stack, printf(__VA_ARGS__)) < 0) { \
  1246. return err_sys("post-test check failed", WC_TEST_RET_ENC_NC);\
  1247. } \
  1248. PRINT_HEAP_CHECKPOINT(); \
  1249. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); \
  1250. }
  1251. #endif
  1252. #ifdef TEST_ALWAYS_RUN_TO_END
  1253. #define TEST_FAIL(msg, retval) do { last_failed_test_ret = (retval); render_error_message(msg, retval); } while (0)
  1254. #elif !defined(TEST_FAIL)
  1255. #define TEST_FAIL(msg, retval) return err_sys(msg, retval)
  1256. #endif
  1257. #ifdef HAVE_STACK_SIZE
  1258. THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args)
  1259. #else
  1260. wc_test_ret_t wolfcrypt_test(void* args)
  1261. #endif
  1262. {
  1263. wc_test_ret_t ret;
  1264. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1265. long heap_baselineAllocs, heap_baselineBytes;
  1266. #endif
  1267. #ifdef TEST_ALWAYS_RUN_TO_END
  1268. int last_failed_test_ret = 0;
  1269. #endif
  1270. STACK_SIZE_INIT();
  1271. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1272. (void)wolfCrypt_heap_peakAllocs_checkpoint();
  1273. heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint();
  1274. (void)wolfCrypt_heap_peakBytes_checkpoint();
  1275. heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint();
  1276. #endif
  1277. #ifdef WC_RNG_SEED_CB
  1278. wc_SetSeed_Cb(wc_GenerateSeed);
  1279. #endif
  1280. printf("------------------------------------------------------------------------------\n");
  1281. printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING);
  1282. #ifdef WOLF_CRYPTO_CB
  1283. if (devId != INVALID_DEVID)
  1284. printf(" CryptoCB with DevID:%X\n", devId);
  1285. #endif
  1286. printf("------------------------------------------------------------------------------\n");
  1287. if (args) {
  1288. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1289. int ch;
  1290. #endif
  1291. ((func_args*)args)->return_code = -1; /* error state */
  1292. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1293. while ((ch = mygetopt(((func_args*)args)->argc, ((func_args*)args)->argv, "s:m:a:h")) != -1) {
  1294. switch(ch) {
  1295. case 's':
  1296. #ifdef HAVE_STACK_SIZE_VERBOSE
  1297. max_relative_stack = (ssize_t)atoi(myoptarg);
  1298. break;
  1299. #else
  1300. return err_sys("-s (max relative stack bytes) requires HAVE_STACK_SIZE_VERBOSE (--enable-stacksize=verbose).", WC_TEST_RET_ENC_NC);
  1301. #endif
  1302. case 'm':
  1303. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1304. max_relative_heap_bytes = (ssize_t)atoi(myoptarg);
  1305. break;
  1306. #else
  1307. return err_sys("-m (max relative heap memory bytes) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1308. #endif
  1309. case 'a':
  1310. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1311. max_relative_heap_allocs = (ssize_t)atoi(myoptarg);
  1312. break;
  1313. #else
  1314. return err_sys("-a (max relative heap allocs) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1315. #endif
  1316. case 'h':
  1317. return err_sys("\
  1318. options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
  1319. [-a max_relative_heap_allocs] [-h]\n", 0);
  1320. default:
  1321. return err_sys("unknown test option. try -h.", WC_TEST_RET_ENC_NC);
  1322. }
  1323. }
  1324. #endif
  1325. }
  1326. #ifdef WOLFSSL_STATIC_MEMORY
  1327. if (wc_LoadStaticMemory(&HEAP_HINT, gTestMemory, sizeof(gTestMemory),
  1328. WOLFMEM_GENERAL, 1) != 0) {
  1329. printf("unable to load static memory.\n");
  1330. return(EXIT_FAILURE);
  1331. }
  1332. #ifndef OPENSSL_EXTRA
  1333. wolfSSL_SetGlobalHeapHint(HEAP_HINT);
  1334. #endif
  1335. #endif
  1336. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  1337. wolfSSL_Debugging_ON();
  1338. #endif
  1339. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  1340. wc_SetLoggingHeap(HEAP_HINT);
  1341. #endif
  1342. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  1343. wolfCrypt_SetCb_fips(myFipsCb);
  1344. #if FIPS_VERSION3_GE(6,0,0)
  1345. printf("FIPS module version in use: %s\n",
  1346. wolfCrypt_GetVersion_fips());
  1347. #endif
  1348. #endif
  1349. #if !defined(NO_BIG_INT)
  1350. if (CheckCtcSettings() != 1) {
  1351. printf("Sizeof mismatch (build) %x != (run) %lx\n",
  1352. CTC_SETTINGS, (unsigned long)CheckRunTimeSettings());
  1353. return err_sys("Build vs runtime math mismatch\n", WC_TEST_RET_ENC_NC);
  1354. }
  1355. #if defined(USE_FAST_MATH) && \
  1356. (!defined(NO_RSA) || !defined(NO_DH) || defined(HAVE_ECC))
  1357. if (CheckFastMathSettings() != 1)
  1358. return err_sys("Build vs runtime fastmath FP_MAX_BITS mismatch\n",
  1359. WC_TEST_RET_ENC_NC);
  1360. #endif /* USE_FAST_MATH */
  1361. #endif /* !NO_BIG_INT */
  1362. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  1363. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  1364. initDefaultName();
  1365. #endif
  1366. #ifdef WOLFSSL_ASYNC_CRYPT
  1367. ret = wolfAsync_DevOpen(&devId);
  1368. if (ret < 0) {
  1369. printf("Async device open failed\nRunning without async\n");
  1370. }
  1371. #else
  1372. (void)devId;
  1373. #endif /* WOLFSSL_ASYNC_CRYPT */
  1374. #ifdef WOLF_CRYPTO_CB
  1375. #ifdef HAVE_INTEL_QA_SYNC
  1376. devId = wc_CryptoCb_InitIntelQa();
  1377. if (INVALID_DEVID == devId) {
  1378. printf("Couldn't init the Intel QA\n");
  1379. }
  1380. #endif
  1381. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  1382. devId = wc_CryptoCb_InitOcteon();
  1383. if (INVALID_DEVID == devId) {
  1384. printf("Couldn't init the Cavium Octeon\n");
  1385. }
  1386. #endif
  1387. #ifdef HAVE_RENESAS_SYNC
  1388. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  1389. if (devId == INVALID_DEVID) {
  1390. printf("Couldn't get the Renesas device ID\n");
  1391. }
  1392. #endif
  1393. #endif
  1394. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  1395. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  1396. if (devId == INVALID_DEVID) {
  1397. /* for testing RNG with crypto callback register function */
  1398. devId = 100; /* any value beside -2 (INVALID_DEVID) */
  1399. wc_CryptoCb_RegisterDevice(devId, rng_crypto_cb, NULL);
  1400. }
  1401. #endif
  1402. #ifdef HAVE_SELFTEST
  1403. if ( (ret = wolfCrypt_SelfTest()) != 0)
  1404. TEST_FAIL("CAVP selftest failed!\n", ret);
  1405. else
  1406. TEST_PASS("CAVP selftest passed!\n");
  1407. #endif
  1408. if ( (ret = error_test()) != 0)
  1409. TEST_FAIL("error test failed!\n", ret);
  1410. else
  1411. TEST_PASS("error test passed!\n");
  1412. if ( (ret = memory_test()) != 0)
  1413. TEST_FAIL("MEMORY test failed!\n", ret);
  1414. else
  1415. TEST_PASS("MEMORY test passed!\n");
  1416. #ifndef NO_CODING
  1417. if ( (ret = base64_test()) != 0)
  1418. TEST_FAIL("base64 test failed!\n", ret);
  1419. else
  1420. TEST_PASS("base64 test passed!\n");
  1421. #ifdef WOLFSSL_BASE16
  1422. if ( (ret = base16_test()) != 0)
  1423. TEST_FAIL("base16 test failed!\n", ret);
  1424. else
  1425. TEST_PASS("base16 test passed!\n");
  1426. #endif
  1427. #endif /* !NO_CODING */
  1428. #ifndef NO_ASN
  1429. if ( (ret = asn_test()) != 0)
  1430. TEST_FAIL("asn test failed!\n", ret);
  1431. else
  1432. TEST_PASS("asn test passed!\n");
  1433. #endif
  1434. #ifndef WC_NO_RNG
  1435. if ( (ret = random_test()) != 0)
  1436. TEST_FAIL("RANDOM test failed!\n", ret);
  1437. else
  1438. TEST_PASS("RANDOM test passed!\n");
  1439. #endif /* WC_NO_RNG */
  1440. #ifndef NO_MD5
  1441. if ( (ret = md5_test()) != 0)
  1442. TEST_FAIL("MD5 test failed!\n", ret);
  1443. else
  1444. TEST_PASS("MD5 test passed!\n");
  1445. #endif
  1446. #ifdef WOLFSSL_MD2
  1447. if ( (ret = md2_test()) != 0)
  1448. TEST_FAIL("MD2 test failed!\n", ret);
  1449. else
  1450. TEST_PASS("MD2 test passed!\n");
  1451. #endif
  1452. #ifndef NO_MD4
  1453. if ( (ret = md4_test()) != 0)
  1454. TEST_FAIL("MD4 test failed!\n", ret);
  1455. else
  1456. TEST_PASS("MD4 test passed!\n");
  1457. #endif
  1458. #ifndef NO_SHA
  1459. if ( (ret = sha_test()) != 0)
  1460. TEST_FAIL("SHA test failed!\n", ret);
  1461. else
  1462. TEST_PASS("SHA test passed!\n");
  1463. #endif
  1464. #ifdef WOLFSSL_SHA224
  1465. if ( (ret = sha224_test()) != 0)
  1466. TEST_FAIL("SHA-224 test failed!\n", ret);
  1467. else
  1468. TEST_PASS("SHA-224 test passed!\n");
  1469. #endif
  1470. #ifndef NO_SHA256
  1471. if ( (ret = sha256_test()) != 0)
  1472. TEST_FAIL("SHA-256 test failed!\n", ret);
  1473. else
  1474. TEST_PASS("SHA-256 test passed!\n");
  1475. #endif
  1476. #ifdef WOLFSSL_SHA384
  1477. if ( (ret = sha384_test()) != 0)
  1478. TEST_FAIL("SHA-384 test failed!\n", ret);
  1479. else
  1480. TEST_PASS("SHA-384 test passed!\n");
  1481. #endif
  1482. #ifdef WOLFSSL_SHA512
  1483. if ((ret = sha512_test()) != 0) {
  1484. TEST_FAIL("SHA-512 test failed!\n", ret);
  1485. }
  1486. else {
  1487. TEST_PASS("SHA-512 test passed!\n");
  1488. }
  1489. #if !defined(WOLFSSL_NOSHA512_224) && \
  1490. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1491. if ((ret = sha512_224_test()) != 0) {
  1492. TEST_FAIL("SHA-512/224 test failed!\n", ret);
  1493. }
  1494. else
  1495. TEST_PASS("SHA-512/224 test passed!\n");
  1496. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  1497. #if !defined(WOLFSSL_NOSHA512_256) && \
  1498. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1499. if ((ret = sha512_256_test()) != 0) {
  1500. TEST_FAIL("SHA-512/256 test failed!\n", ret);
  1501. }
  1502. else
  1503. TEST_PASS("SHA-512/256 test passed!\n");
  1504. #endif /* !defined(WOLFSSL_NOSHA512_256) & !FIPS ... */
  1505. #endif /* WOLFSSL_SHA512 */
  1506. #ifdef WOLFSSL_SHA3
  1507. if ( (ret = sha3_test()) != 0)
  1508. TEST_FAIL("SHA-3 test failed!\n", ret);
  1509. else
  1510. TEST_PASS("SHA-3 test passed!\n");
  1511. #endif
  1512. #ifdef WOLFSSL_SHAKE128
  1513. if ( (ret = shake128_test()) != 0)
  1514. TEST_FAIL("SHAKE128 test failed!\n", ret);
  1515. else
  1516. TEST_PASS("SHAKE128 test passed!\n");
  1517. #endif
  1518. #ifdef WOLFSSL_SHAKE256
  1519. if ( (ret = shake256_test()) != 0)
  1520. TEST_FAIL("SHAKE256 test failed!\n", ret);
  1521. else
  1522. TEST_PASS("SHAKE256 test passed!\n");
  1523. #endif
  1524. #ifdef WOLFSSL_SM3
  1525. if ( (ret = sm3_test()) != 0)
  1526. return err_sys("SM-3 test failed!\n", ret);
  1527. else
  1528. TEST_PASS("SM-3 test passed!\n");
  1529. #endif
  1530. #ifndef NO_HASH_WRAPPER
  1531. if ( (ret = hash_test()) != 0)
  1532. TEST_FAIL("Hash test failed!\n", ret);
  1533. else
  1534. TEST_PASS("Hash test passed!\n");
  1535. #endif
  1536. #ifdef WOLFSSL_RIPEMD
  1537. if ( (ret = ripemd_test()) != 0)
  1538. TEST_FAIL("RIPEMD test failed!\n", ret);
  1539. else
  1540. TEST_PASS("RIPEMD test passed!\n");
  1541. #endif
  1542. #ifdef HAVE_BLAKE2
  1543. if ( (ret = blake2b_test()) != 0)
  1544. TEST_FAIL("BLAKE2b test failed!\n", ret);
  1545. else
  1546. TEST_PASS("BLAKE2b test passed!\n");
  1547. #endif
  1548. #ifdef HAVE_BLAKE2S
  1549. if ( (ret = blake2s_test()) != 0)
  1550. TEST_FAIL("BLAKE2s test failed!\n", ret);
  1551. else
  1552. TEST_PASS("BLAKE2s test passed!\n");
  1553. #endif
  1554. #ifndef NO_HMAC
  1555. #if !defined(NO_MD5) && !(defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) \
  1556. && (HAVE_FIPS_VERSION >= 5))
  1557. if ( (ret = hmac_md5_test()) != 0)
  1558. TEST_FAIL("HMAC-MD5 test failed!\n", ret);
  1559. else
  1560. TEST_PASS("HMAC-MD5 test passed!\n");
  1561. #endif
  1562. #ifndef NO_SHA
  1563. if ( (ret = hmac_sha_test()) != 0)
  1564. TEST_FAIL("HMAC-SHA test failed!\n", ret);
  1565. else
  1566. TEST_PASS("HMAC-SHA test passed!\n");
  1567. #endif
  1568. #ifdef WOLFSSL_SHA224
  1569. if ( (ret = hmac_sha224_test()) != 0)
  1570. TEST_FAIL("HMAC-SHA224 test failed!\n", ret);
  1571. else
  1572. TEST_PASS("HMAC-SHA224 test passed!\n");
  1573. #endif
  1574. #ifndef NO_SHA256
  1575. if ( (ret = hmac_sha256_test()) != 0)
  1576. TEST_FAIL("HMAC-SHA256 test failed!\n", ret);
  1577. else
  1578. TEST_PASS("HMAC-SHA256 test passed!\n");
  1579. #endif
  1580. #ifdef WOLFSSL_SHA384
  1581. if ( (ret = hmac_sha384_test()) != 0)
  1582. TEST_FAIL("HMAC-SHA384 test failed!\n", ret);
  1583. else
  1584. TEST_PASS("HMAC-SHA384 test passed!\n");
  1585. #endif
  1586. #ifdef WOLFSSL_SHA512
  1587. if ( (ret = hmac_sha512_test()) != 0)
  1588. TEST_FAIL("HMAC-SHA512 test failed!\n", ret);
  1589. else
  1590. TEST_PASS("HMAC-SHA512 test passed!\n");
  1591. #endif
  1592. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  1593. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  1594. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  1595. if ( (ret = hmac_sha3_test()) != 0)
  1596. TEST_FAIL("HMAC-SHA3 test failed!\n", ret);
  1597. else
  1598. TEST_PASS("HMAC-SHA3 test passed!\n");
  1599. #endif
  1600. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  1601. PRIVATE_KEY_UNLOCK();
  1602. if ( (ret = hkdf_test()) != 0)
  1603. TEST_FAIL("HMAC-KDF test failed!\n", ret);
  1604. else
  1605. TEST_PASS("HMAC-KDF test passed!\n");
  1606. PRIVATE_KEY_LOCK();
  1607. #endif
  1608. #endif /* !NO_HMAC */
  1609. #ifdef WOLFSSL_WOLFSSH
  1610. PRIVATE_KEY_UNLOCK();
  1611. if ( (ret = sshkdf_test()) != 0)
  1612. TEST_FAIL("SSH-KDF test failed!\n", ret);
  1613. else
  1614. TEST_PASS("SSH-KDF test passed!\n");
  1615. PRIVATE_KEY_LOCK();
  1616. #endif /* WOLFSSL_WOLFSSH */
  1617. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  1618. PRIVATE_KEY_UNLOCK();
  1619. if ( (ret = prf_test()) != 0)
  1620. TEST_FAIL("PRF test failed!\n", ret);
  1621. else
  1622. TEST_PASS("PRF test passed!\n");
  1623. PRIVATE_KEY_LOCK();
  1624. #endif
  1625. #ifdef WOLFSSL_HAVE_PRF
  1626. #if defined (HAVE_HKDF) && !defined(NO_HMAC)
  1627. #ifdef WOLFSSL_BASE16
  1628. PRIVATE_KEY_UNLOCK();
  1629. if ( (ret = tls12_kdf_test()) != 0)
  1630. TEST_FAIL("TLSv1.2 KDF test failed!\n", ret);
  1631. else
  1632. TEST_PASS("TLSv1.2 KDF test passed!\n");
  1633. PRIVATE_KEY_LOCK();
  1634. #endif /* WOLFSSL_BASE16 */
  1635. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  1636. #endif /* WOLFSSL_HAVE_PRF */
  1637. #ifdef WOLFSSL_TLS13
  1638. PRIVATE_KEY_UNLOCK();
  1639. if ( (ret = tls13_kdf_test()) != 0)
  1640. TEST_FAIL("TLSv1.3 KDF test failed!\n", ret);
  1641. else
  1642. TEST_PASS("TLSv1.3 KDF test passed!\n");
  1643. PRIVATE_KEY_LOCK();
  1644. #endif /* WOLFSSL_TLS13 */
  1645. #if defined(HAVE_X963_KDF) && defined(HAVE_ECC)
  1646. if ( (ret = x963kdf_test()) != 0)
  1647. TEST_FAIL("X963-KDF test failed!\n", ret);
  1648. else
  1649. TEST_PASS("X963-KDF test passed!\n");
  1650. #endif
  1651. #if defined(HAVE_HPKE) && defined(HAVE_ECC) && defined(HAVE_AESGCM)
  1652. PRIVATE_KEY_UNLOCK();
  1653. if ( (ret = hpke_test()) != 0)
  1654. TEST_FAIL("HPKE test failed!\n", ret);
  1655. else
  1656. TEST_PASS("HPKE test passed!\n");
  1657. PRIVATE_KEY_LOCK();
  1658. #endif
  1659. #if defined(WC_SRTP_KDF)
  1660. PRIVATE_KEY_UNLOCK();
  1661. if ( (ret = srtpkdf_test()) != 0)
  1662. TEST_FAIL("SRTP KDF test failed!\n", ret);
  1663. else
  1664. TEST_PASS("SRTP KDF test passed!\n");
  1665. PRIVATE_KEY_LOCK();
  1666. #endif
  1667. #if defined(WC_KDF_NIST_SP_800_56C)
  1668. if ( (ret = nist_sp80056c_kdf_test()) != 0)
  1669. TEST_FAIL("NIST SP 800-56C KDF test failed!\n", ret);
  1670. else
  1671. TEST_PASS("NIST SP 800-56C KDF test passed!\n");
  1672. #endif
  1673. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
  1674. !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1675. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1676. if ( (ret = gmac_test()) != 0)
  1677. TEST_FAIL("GMAC test failed!\n", ret);
  1678. else
  1679. TEST_PASS("GMAC test passed!\n");
  1680. #endif
  1681. #ifdef WC_RC2
  1682. if ( (ret = rc2_test()) != 0)
  1683. TEST_FAIL("RC2 test failed!\n", ret);
  1684. else
  1685. TEST_PASS("RC2 test passed!\n");
  1686. #endif
  1687. #ifndef NO_RC4
  1688. if ( (ret = arc4_test()) != 0)
  1689. TEST_FAIL("ARC4 test failed!\n", ret);
  1690. else
  1691. TEST_PASS("ARC4 test passed!\n");
  1692. #endif
  1693. #ifdef HAVE_CHACHA
  1694. if ( (ret = chacha_test()) != 0)
  1695. TEST_FAIL("Chacha test failed!\n", ret);
  1696. else
  1697. TEST_PASS("Chacha test passed!\n");
  1698. #endif
  1699. #ifdef HAVE_XCHACHA
  1700. if ( (ret = XChaCha_test()) != 0)
  1701. TEST_FAIL("XChacha test failed!\n", ret);
  1702. else
  1703. TEST_PASS("XChacha test passed!\n");
  1704. #endif
  1705. #ifdef HAVE_POLY1305
  1706. if ( (ret = poly1305_test()) != 0)
  1707. TEST_FAIL("POLY1305 test failed!\n", ret);
  1708. else
  1709. TEST_PASS("POLY1305 test passed!\n");
  1710. #endif
  1711. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  1712. if ( (ret = chacha20_poly1305_aead_test()) != 0)
  1713. TEST_FAIL("ChaCha20-Poly1305 AEAD test failed!\n", ret);
  1714. else
  1715. TEST_PASS("ChaCha20-Poly1305 AEAD test passed!\n");
  1716. #endif
  1717. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  1718. if ( (ret = XChaCha20Poly1305_test()) != 0)
  1719. TEST_FAIL("XChaCha20-Poly1305 AEAD test failed!\n", ret);
  1720. else
  1721. TEST_PASS("XChaCha20-Poly1305 AEAD test passed!\n");
  1722. #endif
  1723. #ifndef NO_DES3
  1724. if ( (ret = des_test()) != 0)
  1725. TEST_FAIL("DES test failed!\n", ret);
  1726. else
  1727. TEST_PASS("DES test passed!\n");
  1728. #endif
  1729. #ifndef NO_DES3
  1730. if ( (ret = des3_test()) != 0)
  1731. TEST_FAIL("DES3 test failed!\n", ret);
  1732. else
  1733. TEST_PASS("DES3 test passed!\n");
  1734. #endif
  1735. #ifndef NO_AES
  1736. if ( (ret = aes_test()) != 0)
  1737. TEST_FAIL("AES test failed!\n", ret);
  1738. else
  1739. TEST_PASS("AES test passed!\n");
  1740. #if defined(WOLFSSL_AES_192) && \
  1741. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1742. if ( (ret = aes192_test()) != 0)
  1743. TEST_FAIL("AES192 test failed!\n", ret);
  1744. else
  1745. TEST_PASS("AES192 test passed!\n");
  1746. #endif
  1747. #if defined(WOLFSSL_AES_256)
  1748. if ( (ret = aes256_test()) != 0)
  1749. TEST_FAIL("AES256 test failed!\n", ret);
  1750. else
  1751. TEST_PASS("AES256 test passed!\n");
  1752. #endif
  1753. #ifdef WOLFSSL_AES_OFB
  1754. if ( (ret = aesofb_test()) != 0)
  1755. TEST_FAIL("AES-OFB test failed!\n", ret);
  1756. else
  1757. TEST_PASS("AES-OFB test passed!\n");
  1758. #endif
  1759. #ifdef HAVE_AESGCM
  1760. #if !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO)
  1761. if ( (ret = aesgcm_test()) != 0)
  1762. TEST_FAIL("AES-GCM test failed!\n", ret);
  1763. #endif
  1764. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1765. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY) && \
  1766. !defined(WOLFSSL_KCAPI_AES) && !(defined(WOLF_CRYPTO_CB) && \
  1767. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  1768. if ((ret = aesgcm_default_test()) != 0) {
  1769. TEST_FAIL("AES-GCM test failed!\n", ret);
  1770. }
  1771. #endif
  1772. if (ret == 0) {
  1773. TEST_PASS("AES-GCM test passed!\n");
  1774. }
  1775. #endif
  1776. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  1777. if ( (ret = aesccm_test()) != 0)
  1778. TEST_FAIL("AES-CCM test failed!\n", ret);
  1779. else
  1780. TEST_PASS("AES-CCM test passed!\n");
  1781. #endif
  1782. #ifdef WOLFSSL_AES_CFB
  1783. if ( (ret = aes_cfb_test()) != 0)
  1784. TEST_FAIL("AES-CFB test failed!\n", ret);
  1785. else
  1786. TEST_PASS("AES-CFB test passed!\n");
  1787. #endif
  1788. #ifdef WOLFSSL_AES_XTS
  1789. if ( (ret = aes_xts_test()) != 0)
  1790. TEST_FAIL("AES-XTS test failed!\n", ret);
  1791. else
  1792. TEST_PASS("AES-XTS test passed!\n");
  1793. #endif
  1794. #ifdef HAVE_AES_KEYWRAP
  1795. if ( (ret = aeskeywrap_test()) != 0)
  1796. TEST_FAIL("AES Key Wrap test failed!\n", ret);
  1797. else
  1798. TEST_PASS("AES Key Wrap test passed!\n");
  1799. #endif
  1800. #ifdef WOLFSSL_AES_SIV
  1801. if ( (ret = aes_siv_test()) != 0)
  1802. TEST_FAIL("AES-SIV test failed!\n", ret);
  1803. else
  1804. TEST_PASS("AES-SIV test passed!\n");
  1805. #endif
  1806. #endif
  1807. #if defined(WOLFSSL_AES_EAX) && \
  1808. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1809. if ( (ret = aes_eax_test()) != 0)
  1810. TEST_FAIL("AES-EAX test failed!\n", ret);
  1811. else
  1812. TEST_PASS("AES-EAX test passed!\n");
  1813. #endif /* WOLFSSL_AES_EAX */
  1814. #ifdef HAVE_ARIA
  1815. if ( (ret = ariagcm_test(MC_ALGID_ARIA_128BITKEY)) != 0)
  1816. TEST_FAIL("ARIA128 test failed!\n", ret);
  1817. else
  1818. TEST_PASS("ARIA128 test passed!\n");
  1819. if ( (ret = ariagcm_test(MC_ALGID_ARIA_192BITKEY)) != 0)
  1820. TEST_FAIL("ARIA192 test failed!\n", ret);
  1821. else
  1822. TEST_PASS("ARIA192 test passed!\n");
  1823. if ( (ret = ariagcm_test(MC_ALGID_ARIA_256BITKEY)) != 0)
  1824. TEST_FAIL("ARIA256 test failed!\n", ret);
  1825. else
  1826. TEST_PASS("ARIA256 test passed!\n");
  1827. #endif
  1828. #ifdef HAVE_CAMELLIA
  1829. if ( (ret = camellia_test()) != 0)
  1830. TEST_FAIL("CAMELLIA test failed!\n", ret);
  1831. else
  1832. TEST_PASS("CAMELLIA test passed!\n");
  1833. #endif
  1834. #ifdef WOLFSSL_SM4
  1835. if ( (ret = sm4_test()) != 0)
  1836. return err_sys("SM-4 test failed!\n", ret);
  1837. else
  1838. TEST_PASS("SM-4 test passed!\n");
  1839. #endif
  1840. #if !defined(NO_RSA) && !defined(HAVE_RENESAS_SYNC)
  1841. #ifdef WC_RSA_NO_PADDING
  1842. if ( (ret = rsa_no_pad_test()) != 0)
  1843. TEST_FAIL("RSA NOPAD test failed!\n", ret);
  1844. else
  1845. TEST_PASS("RSA NOPAD test passed!\n");
  1846. #endif
  1847. if ( (ret = rsa_test()) != 0)
  1848. TEST_FAIL("RSA test failed!\n", ret);
  1849. else
  1850. TEST_PASS("RSA test passed!\n");
  1851. #endif
  1852. #ifndef NO_DH
  1853. PRIVATE_KEY_UNLOCK();
  1854. if ( (ret = dh_test()) != 0)
  1855. TEST_FAIL("DH test failed!\n", ret);
  1856. else
  1857. TEST_PASS("DH test passed!\n");
  1858. PRIVATE_KEY_LOCK();
  1859. #endif
  1860. #ifndef NO_DSA
  1861. if ( (ret = dsa_test()) != 0)
  1862. TEST_FAIL("DSA test failed!\n", ret);
  1863. else
  1864. TEST_PASS("DSA test passed!\n");
  1865. #endif
  1866. #ifdef WOLFCRYPT_HAVE_SRP
  1867. if ( (ret = srp_test()) != 0)
  1868. TEST_FAIL("SRP test failed!\n", ret);
  1869. else
  1870. TEST_PASS("SRP test passed!\n");
  1871. #endif
  1872. #ifndef NO_PWDBASED
  1873. PRIVATE_KEY_UNLOCK();
  1874. if ( (ret = pwdbased_test()) != 0)
  1875. TEST_FAIL("PWDBASED test failed!\n", ret);
  1876. else
  1877. TEST_PASS("PWDBASED test passed!\n");
  1878. PRIVATE_KEY_LOCK();
  1879. #endif
  1880. #if defined(USE_CERT_BUFFERS_2048) && \
  1881. defined(HAVE_PKCS12) && \
  1882. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  1883. !defined(NO_CERTS) && !defined(NO_DES3)
  1884. if ( (ret = pkcs12_test()) != 0)
  1885. TEST_FAIL("PKCS12 test failed!\n", ret);
  1886. else
  1887. TEST_PASS("PKCS12 test passed!\n");
  1888. #endif
  1889. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  1890. if ( (ret = openssl_test()) != 0)
  1891. TEST_FAIL("OPENSSL test failed!\n", ret);
  1892. else
  1893. TEST_PASS("OPENSSL test passed!\n");
  1894. if ( (ret = openSSL_evpMD_test()) != 0)
  1895. TEST_FAIL("OPENSSL (EVP MD) test failed!\n", ret);
  1896. else
  1897. TEST_PASS("OPENSSL (EVP MD) passed!\n");
  1898. if ( (ret = openssl_pkey0_test()) != 0)
  1899. TEST_FAIL("OPENSSL (PKEY0) test failed!\n", ret);
  1900. else
  1901. TEST_PASS("OPENSSL (PKEY0) passed!\n");
  1902. if ( (ret = openssl_pkey1_test()) != 0)
  1903. TEST_FAIL("OPENSSL (PKEY1) test failed!\n", ret);
  1904. else
  1905. TEST_PASS("OPENSSL (PKEY1) passed!\n");
  1906. #if !defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  1907. if ( (ret = openssl_evpSig_test()) != 0)
  1908. TEST_FAIL("OPENSSL (EVP Sign/Verify) test failed!\n", ret);
  1909. else
  1910. TEST_PASS("OPENSSL (EVP Sign/Verify) passed!\n");
  1911. #endif
  1912. #endif
  1913. #if defined(HAVE_ECC)
  1914. PRIVATE_KEY_UNLOCK();
  1915. if ( (ret = ecc_test()) != 0)
  1916. TEST_FAIL("ECC test failed!\n", ret);
  1917. else
  1918. TEST_PASS("ECC test passed!\n");
  1919. PRIVATE_KEY_LOCK();
  1920. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  1921. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  1922. if ( (ret = ecc_encrypt_test()) != 0)
  1923. TEST_FAIL("ECC Enc test failed!\n", ret);
  1924. else
  1925. TEST_PASS("ECC Enc test passed!\n");
  1926. #endif
  1927. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  1928. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  1929. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  1930. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  1931. /* skip for ATECC508/608A, cannot import private key buffers */
  1932. if ( (ret = ecc_test_buffers()) != 0)
  1933. TEST_FAIL("ECC buffer test failed!\n", ret);
  1934. else
  1935. TEST_PASS("ECC buffer test passed!\n");
  1936. #endif
  1937. #endif
  1938. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  1939. !defined(NO_FILESYSTEM)
  1940. if ( (ret = cert_test()) != 0)
  1941. TEST_FAIL("CERT test failed!\n", ret);
  1942. else
  1943. TEST_PASS("CERT test passed!\n");
  1944. #endif
  1945. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  1946. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  1947. if ( (ret = certext_test()) != 0)
  1948. TEST_FAIL("CERT EXT test failed!\n", ret);
  1949. else
  1950. TEST_PASS("CERT EXT test passed!\n");
  1951. #endif
  1952. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  1953. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  1954. if ( (ret = decodedCertCache_test()) != 0)
  1955. TEST_FAIL("DECODED CERT CACHE test failed!\n", ret);
  1956. else
  1957. TEST_PASS("DECODED CERT CACHE test passed!\n");
  1958. #endif
  1959. #ifdef HAVE_CURVE25519
  1960. if ( (ret = curve25519_test()) != 0)
  1961. TEST_FAIL("CURVE25519 test failed!\n", ret);
  1962. else
  1963. TEST_PASS("CURVE25519 test passed!\n");
  1964. #endif
  1965. #ifdef HAVE_ED25519
  1966. PRIVATE_KEY_UNLOCK();
  1967. if ( (ret = ed25519_test()) != 0)
  1968. TEST_FAIL("ED25519 test failed!\n", ret);
  1969. else
  1970. TEST_PASS("ED25519 test passed!\n");
  1971. PRIVATE_KEY_LOCK();
  1972. #endif
  1973. #ifdef HAVE_CURVE448
  1974. if ( (ret = curve448_test()) != 0)
  1975. TEST_FAIL("CURVE448 test failed!\n", ret);
  1976. else
  1977. TEST_PASS("CURVE448 test passed!\n");
  1978. #endif
  1979. #ifdef HAVE_ED448
  1980. PRIVATE_KEY_UNLOCK();
  1981. if ( (ret = ed448_test()) != 0)
  1982. TEST_FAIL("ED448 test failed!\n", ret);
  1983. else
  1984. TEST_PASS("ED448 test passed!\n");
  1985. PRIVATE_KEY_LOCK();
  1986. #endif
  1987. #ifdef WOLFSSL_HAVE_KYBER
  1988. if ( (ret = kyber_test()) != 0)
  1989. TEST_FAIL("KYBER test failed!\n", ret);
  1990. else
  1991. TEST_PASS("KYBER test passed!\n");
  1992. #endif
  1993. #ifdef HAVE_DILITHIUM
  1994. if ( (ret = dilithium_test()) != 0)
  1995. TEST_FAIL("DILITHIUM test failed!\n", ret);
  1996. else
  1997. TEST_PASS("DILITHIUM test passed!\n");
  1998. #endif
  1999. #if defined(WOLFSSL_HAVE_XMSS)
  2000. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  2001. if ( (ret = xmss_test_verify_only()) != 0)
  2002. TEST_FAIL("XMSS Vfy test failed!\n", ret);
  2003. else
  2004. TEST_PASS("XMSS Vfy test passed!\n");
  2005. #endif
  2006. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  2007. if ( (ret = xmss_test()) != 0)
  2008. TEST_FAIL("XMSS test failed!\n", ret);
  2009. else
  2010. TEST_PASS("XMSS test passed!\n");
  2011. #endif
  2012. #endif /* if defined(WOLFSSL_HAVE_XMSS) */
  2013. #if defined(WOLFSSL_HAVE_LMS)
  2014. #if !defined(WOLFSSL_SMALL_STACK)
  2015. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
  2016. defined(HAVE_LIBLMS)
  2017. if ( (ret = lms_test_verify_only()) != 0)
  2018. TEST_FAIL("LMS Vfy test failed!\n", ret);
  2019. else
  2020. TEST_PASS("LMS Vfy test passed!\n");
  2021. #endif
  2022. #endif
  2023. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  2024. if ( (ret = lms_test()) != 0)
  2025. TEST_FAIL("LMS test failed!\n", ret);
  2026. else
  2027. TEST_PASS("LMS test passed!\n");
  2028. #endif
  2029. #endif /* if defined(WOLFSSL_HAVE_LMS) */
  2030. #ifdef WOLFCRYPT_HAVE_ECCSI
  2031. if ( (ret = eccsi_test()) != 0)
  2032. TEST_FAIL("ECCSI test failed!\n", ret);
  2033. else
  2034. TEST_PASS("ECCSI test passed!\n");
  2035. #endif
  2036. #ifdef WOLFCRYPT_HAVE_SAKKE
  2037. if ( (ret = sakke_test()) != 0)
  2038. TEST_FAIL("SAKKE test failed!\n", ret);
  2039. else
  2040. TEST_PASS("SAKKE test passed!\n");
  2041. #endif
  2042. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  2043. if ( (ret = cmac_test()) != 0)
  2044. TEST_FAIL("CMAC test failed!\n", ret);
  2045. else
  2046. TEST_PASS("CMAC test passed!\n");
  2047. #endif
  2048. #if defined(WOLFSSL_SIPHASH)
  2049. if ( (ret = siphash_test()) != 0)
  2050. TEST_FAIL("SipHash test failed!\n", ret);
  2051. else
  2052. TEST_PASS("SipHash test passed!\n");
  2053. #endif
  2054. #ifdef HAVE_LIBZ
  2055. if ( (ret = compress_test()) != 0)
  2056. TEST_FAIL("COMPRESS test failed!\n", ret);
  2057. else
  2058. TEST_PASS("COMPRESS test passed!\n");
  2059. #endif
  2060. #ifdef HAVE_PKCS7
  2061. #ifndef NO_PKCS7_ENCRYPTED_DATA
  2062. if ( (ret = pkcs7encrypted_test()) != 0)
  2063. TEST_FAIL("PKCS7encrypted test failed!\n", ret);
  2064. else
  2065. TEST_PASS("PKCS7encrypted test passed!\n");
  2066. #endif
  2067. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  2068. if ( (ret = pkcs7compressed_test()) != 0)
  2069. TEST_FAIL("PKCS7compressed test failed!\n", ret);
  2070. else
  2071. TEST_PASS("PKCS7compressed test passed!\n");
  2072. #endif
  2073. if ( (ret = pkcs7signed_test()) != 0)
  2074. TEST_FAIL("PKCS7signed test failed!\n", ret);
  2075. else
  2076. TEST_PASS("PKCS7signed test passed!\n");
  2077. if ( (ret = pkcs7enveloped_test()) != 0)
  2078. TEST_FAIL("PKCS7enveloped test failed!\n", ret);
  2079. else
  2080. TEST_PASS("PKCS7enveloped test passed!\n");
  2081. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  2082. if ( (ret = pkcs7authenveloped_test()) != 0)
  2083. TEST_FAIL("PKCS7authenveloped test failed!\n", ret);
  2084. else
  2085. TEST_PASS("PKCS7authenveloped test passed!\n");
  2086. #endif
  2087. #endif
  2088. #if defined(WOLFSSL_PUBLIC_MP) && \
  2089. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  2090. defined(USE_FAST_MATH))
  2091. if ( (ret = mp_test()) != 0)
  2092. TEST_FAIL("mp test failed!\n", ret);
  2093. else
  2094. TEST_PASS("mp test passed!\n");
  2095. #endif
  2096. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  2097. if ( (ret = prime_test()) != 0)
  2098. TEST_FAIL("prime test failed!\n", ret);
  2099. else
  2100. TEST_PASS("prime test passed!\n");
  2101. #endif
  2102. #if defined(ASN_BER_TO_DER) && \
  2103. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  2104. defined(OPENSSL_EXTRA_X509_SMALL))
  2105. if ( (ret = berder_test()) != 0)
  2106. TEST_FAIL("ber-der test failed!\n", ret);
  2107. else
  2108. TEST_PASS("ber-der test passed!\n");
  2109. #endif
  2110. if ( (ret = logging_test()) != 0)
  2111. TEST_FAIL("logging test failed!\n", ret);
  2112. else
  2113. TEST_PASS("logging test passed!\n");
  2114. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  2115. if ( (ret = time_test()) != 0)
  2116. TEST_FAIL("time test failed!\n", ret);
  2117. else
  2118. TEST_PASS("time test passed!\n");
  2119. #endif
  2120. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  2121. if ((ret = wolfcrypt_mutex_test()) != 0)
  2122. #else
  2123. if ((ret = mutex_test()) != 0)
  2124. #endif
  2125. TEST_FAIL("mutex test failed!\n", ret);
  2126. else
  2127. TEST_PASS("mutex test passed!\n");
  2128. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  2129. if ( (ret = memcb_test()) != 0)
  2130. TEST_FAIL("memcb test failed!\n", ret);
  2131. else
  2132. TEST_PASS("memcb test passed!\n");
  2133. #endif
  2134. #ifdef WOLFSSL_CAAM_BLOB
  2135. if ( (ret = blob_test()) != 0)
  2136. TEST_FAIL("blob test failed!\n", ret);
  2137. else
  2138. TEST_PASS("blob test passed!\n");
  2139. #endif
  2140. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST) && \
  2141. !(defined(HAVE_INTEL_QAT_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2142. defined(WOLFSSL_QNX_CAAM) || defined(HAVE_RENESAS_SYNC))
  2143. if ( (ret = cryptocb_test()) != 0)
  2144. TEST_FAIL("crypto callback test failed!\n", ret);
  2145. else
  2146. TEST_PASS("crypto callback test passed!\n");
  2147. #endif
  2148. #ifdef WOLFSSL_CERT_PIV
  2149. if ( (ret = certpiv_test()) != 0)
  2150. TEST_FAIL("cert piv test failed!\n", ret);
  2151. else
  2152. TEST_PASS("cert piv test passed!\n");
  2153. #endif
  2154. #ifdef WOLF_CRYPTO_CB
  2155. #ifdef HAVE_INTEL_QA_SYNC
  2156. wc_CryptoCb_CleanupIntelQa(&devId);
  2157. #endif
  2158. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2159. wc_CryptoCb_CleanupOcteon(&devId);
  2160. #endif
  2161. #endif
  2162. #ifdef WOLFSSL_ASYNC_CRYPT
  2163. wolfAsync_DevClose(&devId);
  2164. #endif
  2165. /* cleanup the thread if fixed point cache is enabled and have thread local */
  2166. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  2167. wc_ecc_fp_free();
  2168. #endif
  2169. #ifdef TEST_ALWAYS_RUN_TO_END
  2170. if (last_failed_test_ret != 0)
  2171. ret = last_failed_test_ret;
  2172. #endif
  2173. if (args)
  2174. ((func_args*)args)->return_code = ret;
  2175. /* If hardware acceleration and respective metrics tracked, show results: */
  2176. #ifdef WOLFSSL_HW_METRICS
  2177. #if defined(WOLFSSL_ESP32_CRYPT_RSA_PRI) && defined(WOLFSSL_HW_METRICS)
  2178. esp_hw_show_mp_metrics();
  2179. #endif
  2180. #endif
  2181. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(OPENSSL_EXTRA)
  2182. wolfSSL_SetGlobalHeapHint(NULL);
  2183. #endif
  2184. TEST_PASS("Test complete\n");
  2185. EXIT_TEST(ret);
  2186. } /* end of wolfcrypt_test() */
  2187. #ifndef NO_MAIN_DRIVER
  2188. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  2189. int myoptind = 0;
  2190. char* myoptarg = NULL;
  2191. #endif
  2192. /* so overall tests can pull in test function */
  2193. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  2194. wc_test_ret_t wolf_test_task(void)
  2195. #else
  2196. #ifndef NO_MAIN_FUNCTION
  2197. int main(int argc, char** argv)
  2198. {
  2199. return (int)wolfcrypt_test_main(argc, argv);
  2200. }
  2201. #endif
  2202. wc_test_ret_t wolfcrypt_test_main(int argc, char** argv)
  2203. #endif
  2204. {
  2205. wc_test_ret_t ret;
  2206. func_args args = { 0, 0, 0 };
  2207. #if defined(WOLFSSL_ESPIDF) || defined(WOLFSSL_SE050)
  2208. /* set dummy wallclock time. */
  2209. struct timeval utctime;
  2210. struct timezone tz;
  2211. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2212. utctime.tv_usec = 0;
  2213. tz.tz_minuteswest = 0;
  2214. tz.tz_dsttime = 0;
  2215. settimeofday(&utctime, &tz);
  2216. #endif
  2217. #ifdef WOLFSSL_APACHE_MYNEWT
  2218. #ifdef ARCH_sim
  2219. mcu_sim_parse_args(argc, argv);
  2220. #endif
  2221. sysinit();
  2222. /* set dummy wallclock time. */
  2223. struct os_timeval utctime;
  2224. struct os_timezone tz;
  2225. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2226. utctime.tv_usec = 0;
  2227. tz.tz_minuteswest = 0;
  2228. tz.tz_dsttime = 0;
  2229. os_settimeofday(&utctime, &tz);
  2230. #endif
  2231. #ifdef WOLFSSL_ZEPHYR
  2232. /* set dummy wallclock time. */
  2233. struct timespec utctime;
  2234. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2235. utctime.tv_nsec = 0;
  2236. clock_settime(CLOCK_REALTIME, &utctime);
  2237. #endif
  2238. #ifdef DEVKITPRO
  2239. void *framebuffer;
  2240. GXRModeObj *rmode = NULL;
  2241. VIDEO_Init();
  2242. WPAD_Init();
  2243. rmode = VIDEO_GetPreferredMode(NULL);
  2244. #pragma GCC diagnostic ignored "-Wbad-function-cast"
  2245. framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  2246. #pragma GCC diagnostic pop
  2247. console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  2248. VIDEO_Configure(rmode);
  2249. VIDEO_SetNextFramebuffer(framebuffer);
  2250. VIDEO_SetBlack(FALSE);
  2251. VIDEO_Flush();
  2252. VIDEO_WaitVSync();
  2253. if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  2254. #endif
  2255. #ifdef HAVE_WNR
  2256. if ((ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000)) != 0) {
  2257. err_sys("Whitewood netRandom global config failed",
  2258. WC_TEST_RET_ENC_EC(ret));
  2259. return WC_TEST_RET_ENC_EC(ret);
  2260. }
  2261. #endif
  2262. #ifndef WOLFSSL_ESPIDF
  2263. args.argc = argc;
  2264. args.argv = argv;
  2265. #endif
  2266. if ((ret = wolfCrypt_Init()) != 0) {
  2267. printf("wolfCrypt_Init failed %d\n", (int)ret);
  2268. err_sys("Error with wolfCrypt_Init!\n", WC_TEST_RET_ENC_EC(ret));
  2269. }
  2270. #ifdef HAVE_WC_INTROSPECTION
  2271. printf("Math: %s\n", wc_GetMathInfo());
  2272. #endif
  2273. #ifdef HAVE_STACK_SIZE
  2274. StackSizeCheck(&args, wolfcrypt_test);
  2275. #else
  2276. wolfcrypt_test(&args);
  2277. #endif
  2278. if ((ret = wolfCrypt_Cleanup()) != 0) {
  2279. printf("wolfCrypt_Cleanup failed %d\n", (int)ret);
  2280. err_sys("Error with wolfCrypt_Cleanup!\n", WC_TEST_RET_ENC_EC(ret));
  2281. }
  2282. #ifdef HAVE_WNR
  2283. if ((ret = wc_FreeNetRandom()) < 0)
  2284. err_sys("Failed to free netRandom context",
  2285. WC_TEST_RET_ENC_EC(ret));
  2286. #endif /* HAVE_WNR */
  2287. #ifdef DOLPHIN_EMULATOR
  2288. /* Returning from main panics the emulator. Just hang
  2289. * and let the user force quit the emulator window. */
  2290. printf("args.return_code: %d\n", args.return_code);
  2291. printf("Testing complete. You may close the window now\n");
  2292. while (1);
  2293. #endif
  2294. #if defined(WOLFSSL_ESPIDF)
  2295. /* ESP_LOGI to print takes up a lot less memory than printf */
  2296. ESP_LOGI(ESPIDF_TAG, "Exiting main with return code: % d\n",
  2297. args.return_code);
  2298. #else
  2299. /* gate this for target platforms wishing to avoid printf reference */
  2300. printf("Exiting main with return code: %ld\n", (long int)args.return_code);
  2301. #endif
  2302. return args.return_code;
  2303. } /* wolfcrypt_test_main or wolf_test_task */
  2304. #endif /* NO_MAIN_DRIVER */
  2305. /* helper to save DER, convert to PEM and save PEM */
  2306. #if !defined(NO_ASN) && (defined(HAVE_ECC) || !defined(NO_DSA) || \
  2307. (!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) \
  2308. && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  2309. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2310. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, fD, fP, pT, WC_TEST_RET_LN)
  2311. #else
  2312. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, NULL, NULL, pT, WC_TEST_RET_LN)
  2313. #endif
  2314. static wc_test_ret_t _SaveDerAndPem(const byte* der, int derSz,
  2315. const char* fileDer, const char* filePem, int pemType, int calling_line)
  2316. {
  2317. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2318. wc_test_ret_t ret;
  2319. XFILE derFile;
  2320. derFile = XFOPEN(fileDer, "wb");
  2321. if (!derFile) {
  2322. return WC_TEST_RET_ENC(calling_line, 0, WC_TEST_RET_TAG_I);
  2323. }
  2324. ret = (int)XFWRITE(der, 1, (size_t)derSz, derFile);
  2325. XFCLOSE(derFile);
  2326. if (ret != derSz) {
  2327. return WC_TEST_RET_ENC(calling_line, 1, WC_TEST_RET_TAG_I);
  2328. }
  2329. #endif
  2330. #ifdef WOLFSSL_DER_TO_PEM
  2331. if (filePem) {
  2332. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2333. XFILE pemFile;
  2334. #endif
  2335. #ifndef WOLFSSL_NO_MALLOC
  2336. byte* pem;
  2337. #else
  2338. byte pem[1024];
  2339. #endif
  2340. int pemSz;
  2341. /* calculate PEM size */
  2342. pemSz = wc_DerToPem(der, (word32)derSz, NULL, 0, pemType);
  2343. if (pemSz < 0) {
  2344. return WC_TEST_RET_ENC(calling_line, 2, WC_TEST_RET_TAG_I);
  2345. }
  2346. #ifndef WOLFSSL_NO_MALLOC
  2347. pem = (byte*)XMALLOC((word32)pemSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2348. if (pem == NULL) {
  2349. return WC_TEST_RET_ENC(calling_line, 3, WC_TEST_RET_TAG_I);
  2350. }
  2351. #else
  2352. if (pemSz > (int)sizeof(pem))
  2353. return BAD_FUNC_ARG;
  2354. #endif
  2355. /* Convert to PEM */
  2356. pemSz = wc_DerToPem(der, (word32)derSz, pem, (word32)pemSz, pemType);
  2357. if (pemSz < 0) {
  2358. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2359. return WC_TEST_RET_ENC(calling_line, 4, WC_TEST_RET_TAG_I);
  2360. }
  2361. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2362. pemFile = XFOPEN(filePem, "wb");
  2363. if (!pemFile) {
  2364. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2365. return WC_TEST_RET_ENC(calling_line, 5, WC_TEST_RET_TAG_I);
  2366. }
  2367. ret = (int)XFWRITE(pem, 1, (size_t)pemSz, pemFile);
  2368. XFCLOSE(pemFile);
  2369. if (ret != pemSz) {
  2370. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2371. return WC_TEST_RET_ENC(calling_line, 6, WC_TEST_RET_TAG_I);
  2372. }
  2373. #endif
  2374. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2375. }
  2376. #endif /* WOLFSSL_DER_TO_PEM */
  2377. /* suppress unused variable warnings */
  2378. (void)der;
  2379. (void)derSz;
  2380. (void)filePem;
  2381. (void)fileDer;
  2382. (void)pemType;
  2383. (void)calling_line;
  2384. return 0;
  2385. }
  2386. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  2387. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void)
  2388. {
  2389. const char* errStr;
  2390. char out[WOLFSSL_MAX_ERROR_SZ];
  2391. const char* unknownStr = wc_GetErrorString(0);
  2392. #ifdef NO_ERROR_STRINGS
  2393. /* Ensure a valid error code's string matches an invalid code's.
  2394. * The string is that error strings are not available.
  2395. */
  2396. WOLFSSL_ENTER("error_test NO_ERROR_STRINGS");
  2397. errStr = wc_GetErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E));
  2398. wc_ErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E), out);
  2399. if (XSTRCMP(errStr, unknownStr) != 0)
  2400. return WC_TEST_RET_ENC_NC;
  2401. if (XSTRCMP(out, unknownStr) != 0)
  2402. return WC_TEST_RET_ENC_NC;
  2403. #else
  2404. int i;
  2405. int j = 0;
  2406. /* Values that are not or no longer error codes. */
  2407. static const struct {
  2408. int first;
  2409. int last;
  2410. } missing[] = {
  2411. { -124, -124 },
  2412. { -166, -169 }
  2413. };
  2414. /* Check that all errors have a string and it's the same through the two
  2415. * APIs. Check that the values that are not errors map to the unknown
  2416. * string.
  2417. */
  2418. for (i = WC_FIRST_E; i >= WC_LAST_E; i--) {
  2419. int this_missing = 0;
  2420. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  2421. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  2422. this_missing = 1;
  2423. break;
  2424. }
  2425. }
  2426. errStr = wc_GetErrorString(i);
  2427. wc_ErrorString(i, out);
  2428. if (! this_missing) {
  2429. if (XSTRCMP(errStr, unknownStr) == 0) {
  2430. WOLFSSL_MSG("errStr unknown");
  2431. return WC_TEST_RET_ENC_I(-i);
  2432. }
  2433. if (XSTRCMP(out, unknownStr) == 0) {
  2434. WOLFSSL_MSG("out unknown");
  2435. return WC_TEST_RET_ENC_I(-i);
  2436. }
  2437. if (XSTRCMP(errStr, out) != 0) {
  2438. WOLFSSL_MSG("errStr does not match output");
  2439. return WC_TEST_RET_ENC_I(-i);
  2440. }
  2441. if (XSTRLEN(errStr) >= WOLFSSL_MAX_ERROR_SZ) {
  2442. WOLFSSL_MSG("errStr too long");
  2443. return WC_TEST_RET_ENC_I(-i);
  2444. }
  2445. }
  2446. else {
  2447. j++;
  2448. if (XSTRCMP(errStr, unknownStr) != 0)
  2449. return WC_TEST_RET_ENC_I(-i);
  2450. if (XSTRCMP(out, unknownStr) != 0)
  2451. return WC_TEST_RET_ENC_I(-i);
  2452. }
  2453. }
  2454. /* Check if the next possible value has been given a string. */
  2455. errStr = wc_GetErrorString(i);
  2456. wc_ErrorString(i, out);
  2457. if (XSTRCMP(errStr, unknownStr) != 0)
  2458. return WC_TEST_RET_ENC_NC;
  2459. if (XSTRCMP(out, unknownStr) != 0)
  2460. return WC_TEST_RET_ENC_NC;
  2461. #endif
  2462. return 0;
  2463. }
  2464. #ifndef NO_CODING
  2465. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void)
  2466. {
  2467. wc_test_ret_t ret;
  2468. WOLFSSL_SMALL_STACK_STATIC const byte good[] = "A+Gd\0\0\0";
  2469. WOLFSSL_SMALL_STACK_STATIC const byte goodEnd[] = "A+Gd \r\n";
  2470. WOLFSSL_SMALL_STACK_STATIC const byte good_spaces[] = " A + G d \0";
  2471. byte out[128];
  2472. word32 outLen;
  2473. #ifdef WOLFSSL_BASE64_ENCODE
  2474. byte data[3];
  2475. word32 dataLen;
  2476. byte longData[79] = { 0 };
  2477. WOLFSSL_SMALL_STACK_STATIC const byte symbols[] = "+/A=";
  2478. #endif
  2479. WOLFSSL_SMALL_STACK_STATIC const byte badSmall[] = "AAA!Gdj=";
  2480. WOLFSSL_SMALL_STACK_STATIC const byte badLarge[] = "AAA~Gdj=";
  2481. WOLFSSL_SMALL_STACK_STATIC const byte badEOL[] = "A+Gd!AA";
  2482. WOLFSSL_SMALL_STACK_STATIC const byte badPadding[] = "AA=A";
  2483. WOLFSSL_SMALL_STACK_STATIC const byte badChar[] = ",-.:;<=>?@[\\]^_`";
  2484. byte goodChar[] =
  2485. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2486. "abcdefghijklmnopqrstuvwxyz"
  2487. "0123456789+/;";
  2488. byte charTest[] = "A+Gd\0\0\0";
  2489. int i;
  2490. WOLFSSL_ENTER("base64_test");
  2491. /* Good Base64 encodings. */
  2492. outLen = sizeof(out);
  2493. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2494. if (ret != 0)
  2495. return WC_TEST_RET_ENC_EC(ret);
  2496. outLen = sizeof(out);
  2497. ret = Base64_Decode(goodEnd, sizeof(goodEnd), out, &outLen);
  2498. if (ret != 0)
  2499. return WC_TEST_RET_ENC_EC(ret);
  2500. outLen = sizeof(goodChar);
  2501. ret = Base64_Decode(goodChar, sizeof(goodChar), goodChar, &outLen);
  2502. if (ret != 0)
  2503. return WC_TEST_RET_ENC_EC(ret);
  2504. if (outLen != 64 / 4 * 3)
  2505. return WC_TEST_RET_ENC_NC;
  2506. outLen = sizeof(out);
  2507. ret = Base64_Decode(good_spaces, sizeof(good_spaces), out, &outLen);
  2508. if (ret != 0)
  2509. return WC_TEST_RET_ENC_EC(ret);
  2510. /* Bad parameters. */
  2511. outLen = 1;
  2512. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2513. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2514. return WC_TEST_RET_ENC_EC(ret);
  2515. outLen = sizeof(out);
  2516. ret = Base64_Decode(badEOL, sizeof(badEOL), out, &outLen);
  2517. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2518. return WC_TEST_RET_ENC_EC(ret);
  2519. outLen = sizeof(out);
  2520. ret = Base64_Decode(badPadding, sizeof(badPadding), out, &outLen);
  2521. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2522. return WC_TEST_RET_ENC_EC(ret);
  2523. /* Bad character at each offset 0-3. */
  2524. for (i = 0; i < 4; i++) {
  2525. outLen = sizeof(out);
  2526. ret = Base64_Decode(badSmall + i, 4, out, &outLen);
  2527. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2528. return WC_TEST_RET_ENC_I(i);
  2529. ret = Base64_Decode(badLarge + i, 4, out, &outLen);
  2530. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2531. return WC_TEST_RET_ENC_I(i);
  2532. }
  2533. /* Invalid character less than 0x2b */
  2534. for (i = 1; i < 0x2b; i++) {
  2535. outLen = sizeof(out);
  2536. charTest[0] = (byte)i;
  2537. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2538. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2539. return WC_TEST_RET_ENC_I(i);
  2540. }
  2541. /* Bad characters in range 0x2b - 0x7a. */
  2542. for (i = 0; i < (int)sizeof(badChar) - 1; i++) {
  2543. outLen = sizeof(out);
  2544. charTest[0] = badChar[i];
  2545. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2546. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2547. return WC_TEST_RET_ENC_I(i);
  2548. }
  2549. /* Invalid character greater than 0x7a */
  2550. for (i = 0x7b; i < 0x100; i++) {
  2551. outLen = sizeof(out);
  2552. charTest[0] = (byte)i;
  2553. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2554. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2555. return WC_TEST_RET_ENC_I(i);
  2556. }
  2557. #ifdef WOLFSSL_BASE64_ENCODE
  2558. /* Decode and encode all symbols - non-alphanumeric. */
  2559. dataLen = sizeof(data);
  2560. ret = Base64_Decode(symbols, sizeof(symbols), data, &dataLen);
  2561. if (ret != 0)
  2562. return WC_TEST_RET_ENC_EC(ret);
  2563. outLen = sizeof(out);
  2564. ret = Base64_Encode(data, dataLen, NULL, &outLen);
  2565. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2566. return WC_TEST_RET_ENC_EC(ret);
  2567. outLen = sizeof(out);
  2568. ret = Base64_Encode(data, dataLen, out, &outLen);
  2569. if (ret != 0)
  2570. return WC_TEST_RET_ENC_EC(ret);
  2571. outLen = 7;
  2572. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2573. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  2574. return WC_TEST_RET_ENC_EC(ret);
  2575. outLen = sizeof(out);
  2576. ret = Base64_EncodeEsc(data, dataLen, NULL, &outLen);
  2577. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2578. return WC_TEST_RET_ENC_EC(ret);
  2579. outLen = sizeof(out);
  2580. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2581. if (ret != 0)
  2582. return WC_TEST_RET_ENC_EC(ret);
  2583. outLen = sizeof(out);
  2584. ret = Base64_Encode_NoNl(data, dataLen, out, &outLen);
  2585. if (ret != 0)
  2586. return WC_TEST_RET_ENC_EC(ret);
  2587. /* Data that results in an encoding longer than one line. */
  2588. outLen = sizeof(out);
  2589. dataLen = sizeof(longData);
  2590. ret = Base64_Encode(longData, dataLen, out, &outLen);
  2591. if (ret != 0)
  2592. return WC_TEST_RET_ENC_EC(ret);
  2593. outLen = sizeof(out);
  2594. ret = Base64_EncodeEsc(longData, dataLen, out, &outLen);
  2595. if (ret != 0)
  2596. return WC_TEST_RET_ENC_EC(ret);
  2597. outLen = sizeof(out);
  2598. ret = Base64_Encode_NoNl(longData, dataLen, out, &outLen);
  2599. if (ret != 0)
  2600. return WC_TEST_RET_ENC_EC(ret);
  2601. #endif
  2602. return 0;
  2603. }
  2604. #ifdef WOLFSSL_BASE16
  2605. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void)
  2606. {
  2607. wc_test_ret_t ret;
  2608. WOLFSSL_SMALL_STACK_STATIC const byte testData[] = "SomeDataToEncode\n";
  2609. WOLFSSL_SMALL_STACK_STATIC const byte encodedTestData[] = "536F6D6544617461546F456E636F64650A00";
  2610. byte encoded[40];
  2611. word32 encodedLen;
  2612. byte plain[40];
  2613. word32 len;
  2614. WOLFSSL_ENTER("base16_test");
  2615. /* length returned includes null termination */
  2616. encodedLen = sizeof(encoded);
  2617. ret = Base16_Encode(testData, sizeof(testData), encoded, &encodedLen);
  2618. if (ret != 0)
  2619. return WC_TEST_RET_ENC_EC(ret);
  2620. len = (word32)XSTRLEN((char*)encoded);
  2621. if (len != encodedLen - 1)
  2622. return WC_TEST_RET_ENC_NC;
  2623. len = sizeof(plain);
  2624. ret = Base16_Decode(encoded, encodedLen - 1, plain, &len);
  2625. if (ret != 0)
  2626. return WC_TEST_RET_ENC_EC(ret);
  2627. if (len != sizeof(testData) || XMEMCMP(testData, plain, len) != 0)
  2628. return WC_TEST_RET_ENC_NC;
  2629. if (encodedLen != sizeof(encodedTestData) ||
  2630. XMEMCMP(encoded, encodedTestData, encodedLen) != 0) {
  2631. return WC_TEST_RET_ENC_NC;
  2632. }
  2633. return 0;
  2634. }
  2635. #endif /* WOLFSSL_BASE16 */
  2636. #endif /* !NO_CODING */
  2637. #ifndef NO_ASN
  2638. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void)
  2639. {
  2640. wc_test_ret_t ret;
  2641. /* ASN1 encoded date buffer */
  2642. WOLFSSL_SMALL_STACK_STATIC const byte dateBuf[] = {
  2643. 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x31,
  2644. 0x32, 0x30, 0x30, 0x37, 0x33, 0x37, 0x5a
  2645. };
  2646. byte format;
  2647. int length;
  2648. const byte* datePart;
  2649. #ifndef NO_ASN_TIME
  2650. struct tm timearg;
  2651. time_t now;
  2652. #endif
  2653. WOLFSSL_ENTER("asn_test");
  2654. ret = wc_GetDateInfo(dateBuf, (int)sizeof(dateBuf), &datePart, &format,
  2655. &length);
  2656. if (ret != 0)
  2657. return WC_TEST_RET_ENC_EC(ret);
  2658. #ifndef NO_ASN_TIME
  2659. /* Parameter Validation tests. */
  2660. if ((ret = wc_GetTime(NULL, sizeof(now))) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2661. return WC_TEST_RET_ENC_EC(ret);
  2662. if ((ret = wc_GetTime(&now, 0)) != WC_NO_ERR_TRACE(BUFFER_E))
  2663. return WC_TEST_RET_ENC_EC(ret);
  2664. now = 0;
  2665. if ((ret = wc_GetTime(&now, sizeof(now))) != 0) {
  2666. return WC_TEST_RET_ENC_EC(ret);
  2667. }
  2668. if (now == 0) {
  2669. printf("RTC/Time not set!\n");
  2670. return WC_TEST_RET_ENC_NC;
  2671. }
  2672. ret = wc_GetDateAsCalendarTime(datePart, length, format, &timearg);
  2673. if (ret != 0)
  2674. return WC_TEST_RET_ENC_EC(ret);
  2675. #endif /* !NO_ASN_TIME */
  2676. return 0;
  2677. }
  2678. #endif /* !NO_ASN */
  2679. #ifdef WOLFSSL_MD2
  2680. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void)
  2681. {
  2682. wc_test_ret_t ret = 0;
  2683. Md2 md2;
  2684. byte hash[MD2_DIGEST_SIZE];
  2685. testVector a, b, c, d, e, f, g;
  2686. testVector test_md2[7];
  2687. int times = sizeof(test_md2) / sizeof(testVector), i;
  2688. WOLFSSL_ENTER("md2_test");
  2689. a.input = "";
  2690. a.output = "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69"
  2691. "\x27\x73";
  2692. a.inLen = XSTRLEN(a.input);
  2693. a.outLen = MD2_DIGEST_SIZE;
  2694. b.input = "a";
  2695. b.output = "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0"
  2696. "\xb5\xd1";
  2697. b.inLen = XSTRLEN(b.input);
  2698. b.outLen = MD2_DIGEST_SIZE;
  2699. c.input = "abc";
  2700. c.output = "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde"
  2701. "\xd6\xbb";
  2702. c.inLen = XSTRLEN(c.input);
  2703. c.outLen = MD2_DIGEST_SIZE;
  2704. d.input = "message digest";
  2705. d.output = "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe"
  2706. "\x06\xb0";
  2707. d.inLen = XSTRLEN(d.input);
  2708. d.outLen = MD2_DIGEST_SIZE;
  2709. e.input = "abcdefghijklmnopqrstuvwxyz";
  2710. e.output = "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47"
  2711. "\x94\x0b";
  2712. e.inLen = XSTRLEN(e.input);
  2713. e.outLen = MD2_DIGEST_SIZE;
  2714. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2715. "6789";
  2716. f.output = "\xda\x33\xde\xf2\xa4\x2d\xf1\x39\x75\x35\x28\x46\xc3\x03"
  2717. "\x38\xcd";
  2718. f.inLen = XSTRLEN(f.input);
  2719. f.outLen = MD2_DIGEST_SIZE;
  2720. g.input = "1234567890123456789012345678901234567890123456789012345678"
  2721. "9012345678901234567890";
  2722. g.output = "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3"
  2723. "\xef\xd8";
  2724. g.inLen = XSTRLEN(g.input);
  2725. g.outLen = MD2_DIGEST_SIZE;
  2726. test_md2[0] = a;
  2727. test_md2[1] = b;
  2728. test_md2[2] = c;
  2729. test_md2[3] = d;
  2730. test_md2[4] = e;
  2731. test_md2[5] = f;
  2732. test_md2[6] = g;
  2733. wc_InitMd2(&md2);
  2734. for (i = 0; i < times; ++i) {
  2735. wc_Md2Update(&md2, (byte*)test_md2[i].input, (word32)test_md2[i].inLen);
  2736. wc_Md2Final(&md2, hash);
  2737. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0)
  2738. return WC_TEST_RET_ENC_I(i);
  2739. }
  2740. for (i = 0; i < times; ++i) {
  2741. ret = wc_Md2Hash((byte*)test_md2[i].input, (word32)test_md2[i].inLen, hash);
  2742. if (ret != 0) {
  2743. return WC_TEST_RET_ENC_I(i);
  2744. }
  2745. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) {
  2746. return WC_TEST_RET_ENC_I(i);
  2747. }
  2748. }
  2749. return 0;
  2750. }
  2751. #endif
  2752. #ifndef NO_MD5
  2753. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void)
  2754. {
  2755. wc_test_ret_t ret = 0;
  2756. wc_Md5 md5, md5Copy;
  2757. byte hash[WC_MD5_DIGEST_SIZE];
  2758. byte hashcopy[WC_MD5_DIGEST_SIZE];
  2759. testVector a, b, c, d, e, f;
  2760. testVector test_md5[6];
  2761. int times = sizeof(test_md5) / sizeof(testVector), i;
  2762. WOLFSSL_ENTER("md5_test");
  2763. a.input = "";
  2764. a.output = "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42"
  2765. "\x7e";
  2766. a.inLen = XSTRLEN(a.input);
  2767. a.outLen = WC_MD5_DIGEST_SIZE;
  2768. b.input = "abc";
  2769. b.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  2770. "\x72";
  2771. b.inLen = XSTRLEN(b.input);
  2772. b.outLen = WC_MD5_DIGEST_SIZE;
  2773. c.input = "message digest";
  2774. c.output = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
  2775. "\xd0";
  2776. c.inLen = XSTRLEN(c.input);
  2777. c.outLen = WC_MD5_DIGEST_SIZE;
  2778. d.input = "abcdefghijklmnopqrstuvwxyz";
  2779. d.output = "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
  2780. "\x3b";
  2781. d.inLen = XSTRLEN(d.input);
  2782. d.outLen = WC_MD5_DIGEST_SIZE;
  2783. e.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2784. "6789";
  2785. e.output = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
  2786. "\x9f";
  2787. e.inLen = XSTRLEN(e.input);
  2788. e.outLen = WC_MD5_DIGEST_SIZE;
  2789. f.input = "1234567890123456789012345678901234567890123456789012345678"
  2790. "9012345678901234567890";
  2791. f.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  2792. "\x7a";
  2793. f.inLen = XSTRLEN(f.input);
  2794. f.outLen = WC_MD5_DIGEST_SIZE;
  2795. test_md5[0] = a;
  2796. test_md5[1] = b;
  2797. test_md5[2] = c;
  2798. test_md5[3] = d;
  2799. test_md5[4] = e;
  2800. test_md5[5] = f;
  2801. ret = wc_InitMd5_ex(&md5, HEAP_HINT, devId);
  2802. if (ret != 0)
  2803. return WC_TEST_RET_ENC_EC(ret);
  2804. ret = wc_InitMd5_ex(&md5Copy, HEAP_HINT, devId);
  2805. if (ret != 0) {
  2806. wc_Md5Free(&md5);
  2807. return WC_TEST_RET_ENC_EC(ret);
  2808. }
  2809. for (i = 0; i < times; ++i) {
  2810. ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
  2811. (word32)test_md5[i].inLen);
  2812. if (ret != 0)
  2813. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2814. ret = wc_Md5GetHash(&md5, hashcopy);
  2815. if (ret != 0)
  2816. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2817. ret = wc_Md5Copy(&md5, &md5Copy);
  2818. if (ret != 0)
  2819. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2820. ret = wc_Md5Final(&md5, hash);
  2821. if (ret != 0)
  2822. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2823. wc_Md5Free(&md5Copy);
  2824. if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0)
  2825. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2826. if (XMEMCMP(hash, hashcopy, WC_MD5_DIGEST_SIZE) != 0)
  2827. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2828. }
  2829. #ifndef NO_LARGE_HASH_TEST
  2830. /* BEGIN LARGE HASH TEST */ {
  2831. byte large_input[1024];
  2832. const char* large_digest =
  2833. "\x44\xd0\x88\xce\xf1\x36\xd1\x78\xe9\xc8\xba\x84\xc3\xfd\xf6\xca";
  2834. for (i = 0; i < (int)sizeof(large_input); i++) {
  2835. large_input[i] = (byte)(i & 0xFF);
  2836. }
  2837. times = 100;
  2838. #ifdef WOLFSSL_PIC32MZ_HASH
  2839. wc_Md5SizeSet(&md5, times * sizeof(large_input));
  2840. #endif
  2841. for (i = 0; i < times; ++i) {
  2842. ret = wc_Md5Update(&md5, (byte*)large_input,
  2843. (word32)sizeof(large_input));
  2844. if (ret != 0)
  2845. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2846. }
  2847. ret = wc_Md5Final(&md5, hash);
  2848. if (ret != 0)
  2849. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2850. if (XMEMCMP(hash, large_digest, WC_MD5_DIGEST_SIZE) != 0)
  2851. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  2852. } /* END LARGE HASH TEST */
  2853. #endif /* NO_LARGE_HASH_TEST */
  2854. exit:
  2855. wc_Md5Free(&md5);
  2856. wc_Md5Free(&md5Copy);
  2857. return ret;
  2858. }
  2859. #endif /* NO_MD5 */
  2860. #ifndef NO_MD4
  2861. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void)
  2862. {
  2863. Md4 md4;
  2864. byte hash[MD4_DIGEST_SIZE];
  2865. testVector a, b, c, d, e, f, g;
  2866. testVector test_md4[7];
  2867. int times = sizeof(test_md4) / sizeof(testVector), i;
  2868. WOLFSSL_ENTER("md4_test");
  2869. a.input = "";
  2870. a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
  2871. "\xc0";
  2872. a.inLen = XSTRLEN(a.input);
  2873. a.outLen = MD4_DIGEST_SIZE;
  2874. b.input = "a";
  2875. b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
  2876. "\x24";
  2877. b.inLen = XSTRLEN(b.input);
  2878. b.outLen = MD4_DIGEST_SIZE;
  2879. c.input = "abc";
  2880. c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
  2881. "\x9d";
  2882. c.inLen = XSTRLEN(c.input);
  2883. c.outLen = MD4_DIGEST_SIZE;
  2884. d.input = "message digest";
  2885. d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
  2886. "\x4b";
  2887. d.inLen = XSTRLEN(d.input);
  2888. d.outLen = MD4_DIGEST_SIZE;
  2889. e.input = "abcdefghijklmnopqrstuvwxyz";
  2890. e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
  2891. "\xa9";
  2892. e.inLen = XSTRLEN(e.input);
  2893. e.outLen = MD4_DIGEST_SIZE;
  2894. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2895. "6789";
  2896. f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
  2897. "\xe4";
  2898. f.inLen = XSTRLEN(f.input);
  2899. f.outLen = MD4_DIGEST_SIZE;
  2900. g.input = "1234567890123456789012345678901234567890123456789012345678"
  2901. "9012345678901234567890";
  2902. g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
  2903. "\x36";
  2904. g.inLen = XSTRLEN(g.input);
  2905. g.outLen = MD4_DIGEST_SIZE;
  2906. test_md4[0] = a;
  2907. test_md4[1] = b;
  2908. test_md4[2] = c;
  2909. test_md4[3] = d;
  2910. test_md4[4] = e;
  2911. test_md4[5] = f;
  2912. test_md4[6] = g;
  2913. wc_InitMd4(&md4);
  2914. for (i = 0; i < times; ++i) {
  2915. wc_Md4Update(&md4, (byte*)test_md4[i].input, (word32)test_md4[i].inLen);
  2916. wc_Md4Final(&md4, hash);
  2917. if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0)
  2918. return WC_TEST_RET_ENC_I(i);
  2919. }
  2920. return 0;
  2921. }
  2922. #endif /* NO_MD4 */
  2923. #ifndef NO_SHA
  2924. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void)
  2925. {
  2926. wc_test_ret_t ret = 0;
  2927. wc_Sha sha, shaCopy;
  2928. byte hash[WC_SHA_DIGEST_SIZE];
  2929. byte hashcopy[WC_SHA_DIGEST_SIZE];
  2930. testVector a, b, c, d, e;
  2931. testVector test_sha[5];
  2932. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  2933. WOLFSSL_ENTER("sha_test");
  2934. a.input = "";
  2935. a.output = "\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18"
  2936. "\x90\xaf\xd8\x07\x09";
  2937. a.inLen = XSTRLEN(a.input);
  2938. a.outLen = WC_SHA_DIGEST_SIZE;
  2939. b.input = "abc";
  2940. b.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  2941. "\x6C\x9C\xD0\xD8\x9D";
  2942. b.inLen = XSTRLEN(b.input);
  2943. b.outLen = WC_SHA_DIGEST_SIZE;
  2944. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  2945. c.output = "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
  2946. "\xE5\xE5\x46\x70\xF1";
  2947. c.inLen = XSTRLEN(c.input);
  2948. c.outLen = WC_SHA_DIGEST_SIZE;
  2949. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  2950. "aaaaaa";
  2951. d.output = "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
  2952. "\x2A\x25\xEC\x64\x4D";
  2953. d.inLen = XSTRLEN(d.input);
  2954. d.outLen = WC_SHA_DIGEST_SIZE;
  2955. e.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  2956. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  2957. "aaaaaaaaaa";
  2958. e.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  2959. "\x53\x99\x5E\x26\xA0";
  2960. e.inLen = XSTRLEN(e.input);
  2961. e.outLen = WC_SHA_DIGEST_SIZE;
  2962. test_sha[0] = a;
  2963. test_sha[1] = b;
  2964. test_sha[2] = c;
  2965. test_sha[3] = d;
  2966. test_sha[4] = e;
  2967. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  2968. if (ret != 0)
  2969. return WC_TEST_RET_ENC_EC(ret);
  2970. ret = wc_InitSha_ex(&shaCopy, HEAP_HINT, devId);
  2971. if (ret != 0) {
  2972. wc_ShaFree(&sha);
  2973. return WC_TEST_RET_ENC_EC(ret);
  2974. }
  2975. for (i = 0; i < times; ++i) {
  2976. ret = wc_ShaUpdate(&sha, (byte*)test_sha[i].input,
  2977. (word32)test_sha[i].inLen);
  2978. if (ret != 0)
  2979. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2980. ret = wc_ShaGetHash(&sha, hashcopy);
  2981. if (ret != 0)
  2982. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2983. ret = wc_ShaCopy(&sha, &shaCopy);
  2984. if (ret != 0)
  2985. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2986. ret = wc_ShaFinal(&sha, hash);
  2987. if (ret != 0)
  2988. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2989. wc_ShaFree(&shaCopy);
  2990. if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0)
  2991. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2992. if (XMEMCMP(hash, hashcopy, WC_SHA_DIGEST_SIZE) != 0)
  2993. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2994. }
  2995. #ifndef NO_LARGE_HASH_TEST
  2996. /* BEGIN LARGE HASH TEST */ {
  2997. byte large_input[1024];
  2998. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  2999. defined(HASH_SIZE_LIMIT)
  3000. const char* large_digest =
  3001. "\x1d\x6a\x5a\xf6\xe5\x7c\x86\xce\x7f\x7c\xaf\xd5\xdb\x08\xcd\x59"
  3002. "\x15\x8c\x6d\xb6";
  3003. #else
  3004. const char* large_digest =
  3005. "\x8b\x77\x02\x48\x39\xe8\xdb\xd3\x9a\xf4\x05\x24\x66\x12\x2d\x9e"
  3006. "\xc5\xd9\x0a\xac";
  3007. #endif
  3008. for (i = 0; i < (int)sizeof(large_input); i++) {
  3009. large_input[i] = (byte)(i & 0xFF);
  3010. }
  3011. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3012. defined(HASH_SIZE_LIMIT)
  3013. times = 20;
  3014. #else
  3015. times = 100;
  3016. #endif
  3017. #ifdef WOLFSSL_PIC32MZ_HASH
  3018. wc_ShaSizeSet(&sha, times * sizeof(large_input));
  3019. #endif
  3020. for (i = 0; i < times; ++i) {
  3021. ret = wc_ShaUpdate(&sha, (byte*)large_input,
  3022. (word32)sizeof(large_input));
  3023. if (ret != 0)
  3024. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3025. }
  3026. ret = wc_ShaFinal(&sha, hash);
  3027. if (ret != 0)
  3028. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3029. if (XMEMCMP(hash, large_digest, WC_SHA_DIGEST_SIZE) != 0)
  3030. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3031. } /* END LARGE HASH TEST */
  3032. #endif /* NO_LARGE_HASH_TEST */
  3033. exit:
  3034. wc_ShaFree(&sha);
  3035. wc_ShaFree(&shaCopy);
  3036. return ret;
  3037. }
  3038. #endif /* NO_SHA */
  3039. #ifdef WOLFSSL_RIPEMD
  3040. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void)
  3041. {
  3042. RipeMd ripemd;
  3043. wc_test_ret_t ret;
  3044. byte hash[RIPEMD_DIGEST_SIZE];
  3045. testVector a, b, c, d;
  3046. testVector test_ripemd[4];
  3047. int times = sizeof(test_ripemd) / sizeof(struct testVector), i;
  3048. WOLFSSL_ENTER("ripemd_test");
  3049. a.input = "abc";
  3050. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  3051. "\xb0\x87\xf1\x5a\x0b\xfc";
  3052. a.inLen = XSTRLEN(a.input);
  3053. a.outLen = RIPEMD_DIGEST_SIZE;
  3054. b.input = "message digest";
  3055. b.output = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
  3056. "\x5f\xfa\x21\x59\x5f\x36";
  3057. b.inLen = XSTRLEN(b.input);
  3058. b.outLen = RIPEMD_DIGEST_SIZE;
  3059. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3060. c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
  3061. "\xf4\x9a\xda\x62\xeb\x2b";
  3062. c.inLen = XSTRLEN(c.input);
  3063. c.outLen = RIPEMD_DIGEST_SIZE;
  3064. d.input = "12345678901234567890123456789012345678901234567890123456"
  3065. "789012345678901234567890";
  3066. d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
  3067. "\x82\xbf\x63\x32\x6b\xfb";
  3068. d.inLen = XSTRLEN(d.input);
  3069. d.outLen = RIPEMD_DIGEST_SIZE;
  3070. test_ripemd[0] = a;
  3071. test_ripemd[1] = b;
  3072. test_ripemd[2] = c;
  3073. test_ripemd[3] = d;
  3074. ret = wc_InitRipeMd(&ripemd);
  3075. if (ret != 0) {
  3076. return WC_TEST_RET_ENC_EC(ret);
  3077. }
  3078. for (i = 0; i < times; ++i) {
  3079. ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
  3080. (word32)test_ripemd[i].inLen);
  3081. if (ret != 0) {
  3082. return WC_TEST_RET_ENC_I(i);
  3083. }
  3084. ret = wc_RipeMdFinal(&ripemd, hash);
  3085. if (ret != 0) {
  3086. return WC_TEST_RET_ENC_I(i);
  3087. }
  3088. if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
  3089. return WC_TEST_RET_ENC_I(i);
  3090. }
  3091. return 0;
  3092. }
  3093. #endif /* WOLFSSL_RIPEMD */
  3094. #ifdef HAVE_BLAKE2
  3095. #define BLAKE2B_TESTS 3
  3096. static const byte blake2b_vec[BLAKE2B_TESTS][BLAKE2B_OUTBYTES] =
  3097. {
  3098. {
  3099. 0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
  3100. 0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
  3101. 0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61,
  3102. 0x8A, 0x86, 0xE2, 0x17, 0xF7, 0x1F, 0x54, 0x19,
  3103. 0xD2, 0x5E, 0x10, 0x31, 0xAF, 0xEE, 0x58, 0x53,
  3104. 0x13, 0x89, 0x64, 0x44, 0x93, 0x4E, 0xB0, 0x4B,
  3105. 0x90, 0x3A, 0x68, 0x5B, 0x14, 0x48, 0xB7, 0x55,
  3106. 0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
  3107. },
  3108. {
  3109. 0x2F, 0xA3, 0xF6, 0x86, 0xDF, 0x87, 0x69, 0x95,
  3110. 0x16, 0x7E, 0x7C, 0x2E, 0x5D, 0x74, 0xC4, 0xC7,
  3111. 0xB6, 0xE4, 0x8F, 0x80, 0x68, 0xFE, 0x0E, 0x44,
  3112. 0x20, 0x83, 0x44, 0xD4, 0x80, 0xF7, 0x90, 0x4C,
  3113. 0x36, 0x96, 0x3E, 0x44, 0x11, 0x5F, 0xE3, 0xEB,
  3114. 0x2A, 0x3A, 0xC8, 0x69, 0x4C, 0x28, 0xBC, 0xB4,
  3115. 0xF5, 0xA0, 0xF3, 0x27, 0x6F, 0x2E, 0x79, 0x48,
  3116. 0x7D, 0x82, 0x19, 0x05, 0x7A, 0x50, 0x6E, 0x4B
  3117. },
  3118. {
  3119. 0x1C, 0x08, 0x79, 0x8D, 0xC6, 0x41, 0xAB, 0xA9,
  3120. 0xDE, 0xE4, 0x35, 0xE2, 0x25, 0x19, 0xA4, 0x72,
  3121. 0x9A, 0x09, 0xB2, 0xBF, 0xE0, 0xFF, 0x00, 0xEF,
  3122. 0x2D, 0xCD, 0x8E, 0xD6, 0xF8, 0xA0, 0x7D, 0x15,
  3123. 0xEA, 0xF4, 0xAE, 0xE5, 0x2B, 0xBF, 0x18, 0xAB,
  3124. 0x56, 0x08, 0xA6, 0x19, 0x0F, 0x70, 0xB9, 0x04,
  3125. 0x86, 0xC8, 0xA7, 0xD4, 0x87, 0x37, 0x10, 0xB1,
  3126. 0x11, 0x5D, 0x3D, 0xEB, 0xBB, 0x43, 0x27, 0xB5
  3127. }
  3128. };
  3129. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void)
  3130. {
  3131. Blake2b b2b;
  3132. byte digest[64];
  3133. byte input[64];
  3134. int i, ret;
  3135. WOLFSSL_ENTER("blake2b_test");
  3136. for (i = 0; i < (int)sizeof(input); i++)
  3137. input[i] = (byte)i;
  3138. for (i = 0; i < BLAKE2B_TESTS; i++) {
  3139. ret = wc_InitBlake2b(&b2b, 64);
  3140. if (ret != 0)
  3141. return WC_TEST_RET_ENC_I(i);
  3142. ret = wc_Blake2bUpdate(&b2b, input, (word32)i);
  3143. if (ret != 0)
  3144. return WC_TEST_RET_ENC_I(i);
  3145. ret = wc_Blake2bFinal(&b2b, digest, 64);
  3146. if (ret != 0)
  3147. return WC_TEST_RET_ENC_I(i);
  3148. if (XMEMCMP(digest, blake2b_vec[i], 64) != 0) {
  3149. return WC_TEST_RET_ENC_I(i);
  3150. }
  3151. }
  3152. return 0;
  3153. }
  3154. #endif /* HAVE_BLAKE2 */
  3155. #ifdef HAVE_BLAKE2S
  3156. #define BLAKE2S_TESTS 3
  3157. static const byte blake2s_vec[BLAKE2S_TESTS][BLAKE2S_OUTBYTES] =
  3158. {
  3159. {
  3160. 0x69, 0x21, 0x7a, 0x30, 0x79, 0x90, 0x80, 0x94,
  3161. 0xe1, 0x11, 0x21, 0xd0, 0x42, 0x35, 0x4a, 0x7c,
  3162. 0x1f, 0x55, 0xb6, 0x48, 0x2c, 0xa1, 0xa5, 0x1e,
  3163. 0x1b, 0x25, 0x0d, 0xfd, 0x1e, 0xd0, 0xee, 0xf9,
  3164. },
  3165. {
  3166. 0xe3, 0x4d, 0x74, 0xdb, 0xaf, 0x4f, 0xf4, 0xc6,
  3167. 0xab, 0xd8, 0x71, 0xcc, 0x22, 0x04, 0x51, 0xd2,
  3168. 0xea, 0x26, 0x48, 0x84, 0x6c, 0x77, 0x57, 0xfb,
  3169. 0xaa, 0xc8, 0x2f, 0xe5, 0x1a, 0xd6, 0x4b, 0xea,
  3170. },
  3171. {
  3172. 0xdd, 0xad, 0x9a, 0xb1, 0x5d, 0xac, 0x45, 0x49,
  3173. 0xba, 0x42, 0xf4, 0x9d, 0x26, 0x24, 0x96, 0xbe,
  3174. 0xf6, 0xc0, 0xba, 0xe1, 0xdd, 0x34, 0x2a, 0x88,
  3175. 0x08, 0xf8, 0xea, 0x26, 0x7c, 0x6e, 0x21, 0x0c,
  3176. }
  3177. };
  3178. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void)
  3179. {
  3180. Blake2s b2s;
  3181. byte digest[32];
  3182. byte input[64];
  3183. int i, ret;
  3184. WOLFSSL_ENTER("blake2s_test");
  3185. for (i = 0; i < (int)sizeof(input); i++)
  3186. input[i] = (byte)i;
  3187. for (i = 0; i < BLAKE2S_TESTS; i++) {
  3188. ret = wc_InitBlake2s(&b2s, 32);
  3189. if (ret != 0)
  3190. return WC_TEST_RET_ENC_I(i);
  3191. ret = wc_Blake2sUpdate(&b2s, input, (word32)i);
  3192. if (ret != 0)
  3193. return WC_TEST_RET_ENC_I(i);
  3194. ret = wc_Blake2sFinal(&b2s, digest, 32);
  3195. if (ret != 0)
  3196. return WC_TEST_RET_ENC_I(i);
  3197. if (XMEMCMP(digest, blake2s_vec[i], 32) != 0) {
  3198. return WC_TEST_RET_ENC_I(i);
  3199. }
  3200. }
  3201. return 0;
  3202. }
  3203. #endif /* HAVE_BLAKE2S */
  3204. #ifdef WOLFSSL_SHA224
  3205. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void)
  3206. {
  3207. wc_Sha224 sha, shaCopy;
  3208. byte hash[WC_SHA224_DIGEST_SIZE];
  3209. byte hashcopy[WC_SHA224_DIGEST_SIZE];
  3210. wc_test_ret_t ret = 0;
  3211. testVector a, b, c;
  3212. testVector test_sha[3];
  3213. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3214. WOLFSSL_ENTER("sha224_test");
  3215. a.input = "";
  3216. a.output = "\xd1\x4a\x02\x8c\x2a\x3a\x2b\xc9\x47\x61\x02\xbb\x28\x82\x34"
  3217. "\xc4\x15\xa2\xb0\x1f\x82\x8e\xa6\x2a\xc5\xb3\xe4\x2f";
  3218. a.inLen = XSTRLEN(a.input);
  3219. a.outLen = WC_SHA224_DIGEST_SIZE;
  3220. b.input = "abc";
  3221. b.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55"
  3222. "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  3223. b.inLen = XSTRLEN(b.input);
  3224. b.outLen = WC_SHA224_DIGEST_SIZE;
  3225. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3226. c.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  3227. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  3228. c.inLen = XSTRLEN(c.input);
  3229. c.outLen = WC_SHA224_DIGEST_SIZE;
  3230. test_sha[0] = a;
  3231. test_sha[1] = b;
  3232. test_sha[2] = c;
  3233. ret = wc_InitSha224_ex(&sha, HEAP_HINT, devId);
  3234. if (ret != 0)
  3235. return WC_TEST_RET_ENC_EC(ret);
  3236. ret = wc_InitSha224_ex(&shaCopy, HEAP_HINT, devId);
  3237. if (ret != 0) {
  3238. wc_Sha224Free(&sha);
  3239. return WC_TEST_RET_ENC_EC(ret);
  3240. }
  3241. for (i = 0; i < times; ++i) {
  3242. ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,
  3243. (word32)test_sha[i].inLen);
  3244. if (ret != 0)
  3245. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3246. ret = wc_Sha224GetHash(&sha, hashcopy);
  3247. if (ret != 0)
  3248. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3249. ret = wc_Sha224Copy(&sha, &shaCopy);
  3250. if (ret != 0)
  3251. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3252. ret = wc_Sha224Final(&sha, hash);
  3253. if (ret != 0)
  3254. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3255. wc_Sha224Free(&shaCopy);
  3256. if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  3257. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3258. if (XMEMCMP(hash, hashcopy, WC_SHA224_DIGEST_SIZE) != 0)
  3259. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3260. }
  3261. exit:
  3262. wc_Sha224Free(&sha);
  3263. wc_Sha224Free(&shaCopy);
  3264. return ret;
  3265. }
  3266. #endif
  3267. #ifndef NO_SHA256
  3268. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
  3269. {
  3270. wc_Sha256 sha, shaCopy;
  3271. byte hash[WC_SHA256_DIGEST_SIZE];
  3272. byte hashcopy[WC_SHA256_DIGEST_SIZE];
  3273. wc_test_ret_t ret = 0;
  3274. testVector a, b, c, d;
  3275. testVector test_sha[4];
  3276. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3277. byte i_hash[WC_SHA256_DIGEST_SIZE];
  3278. byte i_hashcopy[WC_SHA256_DIGEST_SIZE];
  3279. testVector interleave_test_sha[4];
  3280. wc_Sha256 i_sha, i_shaCopy;
  3281. #endif
  3282. #ifndef NO_LARGE_HASH_TEST
  3283. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3284. #ifdef WOLFSSL_SMALL_STACK
  3285. byte *large_input = NULL;
  3286. #else
  3287. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3288. #endif
  3289. #endif
  3290. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3291. WOLFSSL_ENTER("sha256_test");
  3292. a.input = "";
  3293. a.output = "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9"
  3294. "\x24\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52"
  3295. "\xb8\x55";
  3296. a.inLen = XSTRLEN(a.input);
  3297. a.outLen = WC_SHA256_DIGEST_SIZE;
  3298. b.input = "abc";
  3299. b.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  3300. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  3301. "\x15\xAD";
  3302. b.inLen = XSTRLEN(b.input);
  3303. b.outLen = WC_SHA256_DIGEST_SIZE;
  3304. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3305. c.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  3306. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  3307. "\x06\xC1";
  3308. c.inLen = XSTRLEN(c.input);
  3309. c.outLen = WC_SHA256_DIGEST_SIZE;
  3310. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3311. "aaaaaa"; /* this is BLOCKSIZE length */
  3312. d.output = "\xFF\xE0\x54\xFE\x7A\xE0\xCB\x6D\xC6\x5C\x3A\xF9\xB6\x1D\x52"
  3313. "\x09\xF4\x39\x85\x1D\xB4\x3D\x0B\xA5\x99\x73\x37\xDF\x15\x46"
  3314. "\x68\xEB";
  3315. d.inLen = XSTRLEN(d.input);
  3316. d.outLen = WC_SHA256_DIGEST_SIZE;
  3317. test_sha[0] = a;
  3318. test_sha[1] = b;
  3319. test_sha[2] = c;
  3320. test_sha[3] = d;
  3321. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3322. interleave_test_sha[0] = a;
  3323. interleave_test_sha[1] = b;
  3324. interleave_test_sha[2] = c;
  3325. interleave_test_sha[3] = d;
  3326. #endif
  3327. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  3328. if (ret != 0)
  3329. return WC_TEST_RET_ENC_EC(ret);
  3330. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3331. ret = wc_InitSha256_ex(&i_sha, HEAP_HINT, devId);
  3332. if (ret != 0)
  3333. return WC_TEST_RET_ENC_EC(ret);
  3334. #endif
  3335. ret = wc_InitSha256_ex(&shaCopy, HEAP_HINT, devId);
  3336. if (ret != 0) {
  3337. wc_Sha256Free(&sha);
  3338. return WC_TEST_RET_ENC_EC(ret);
  3339. }
  3340. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3341. ret = wc_InitSha256_ex(&i_shaCopy, HEAP_HINT, devId);
  3342. if (ret != 0) {
  3343. wc_Sha256Free(&sha);
  3344. wc_Sha256Free(&i_sha);
  3345. return WC_TEST_RET_ENC_EC(ret);
  3346. }
  3347. #endif
  3348. for (i = 0; i < times; ++i) {
  3349. ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input,
  3350. (word32)test_sha[i].inLen);
  3351. if (ret != 0) {
  3352. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3353. }
  3354. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3355. ret = wc_Sha256Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3356. (word32)interleave_test_sha[i].inLen);
  3357. if (ret != 0) {
  3358. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3359. }
  3360. #endif
  3361. ret = wc_Sha256GetHash(&sha, hashcopy);
  3362. if (ret != 0)
  3363. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3364. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3365. ret = wc_Sha256GetHash(&i_sha, i_hashcopy);
  3366. if (ret != 0)
  3367. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3368. #endif
  3369. ret = wc_Sha256Copy(&sha, &shaCopy);
  3370. if (ret != 0)
  3371. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3372. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3373. ret = wc_Sha256Copy(&i_sha, &i_shaCopy);
  3374. if (ret != 0)
  3375. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3376. #endif
  3377. ret = wc_Sha256Final(&sha, hash);
  3378. if (ret != 0)
  3379. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3380. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3381. ret = wc_Sha256Final(&i_sha, i_hash);
  3382. if (ret != 0)
  3383. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3384. #endif
  3385. wc_Sha256Free(&shaCopy);
  3386. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3387. wc_Sha256Free(&i_shaCopy);
  3388. #endif
  3389. if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3390. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3391. }
  3392. if (XMEMCMP(hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3393. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3394. }
  3395. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3396. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3397. WC_SHA256_DIGEST_SIZE) != 0) {
  3398. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3399. }
  3400. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3401. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3402. }
  3403. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3404. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3405. }
  3406. if (XMEMCMP(i_hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3407. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3408. }
  3409. #endif
  3410. }
  3411. #ifndef NO_LARGE_HASH_TEST
  3412. /* BEGIN LARGE HASH TEST */ {
  3413. #ifdef HASH_SIZE_LIMIT
  3414. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3415. "\xa4\x75\x9e\x7a\xa2\x03\x38\x32\x88\x66\xa2\xea\x17\xea\xf8\xc7"
  3416. "\xfe\x4e\xc6\xbb\xe3\xbb\x71\xce\xe7\xdf\x7c\x04\x61\xb3\xc2\x2f";
  3417. #else
  3418. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3419. "\x27\x78\x3e\x87\x96\x3a\x4e\xfb\x68\x29\xb5\x31\xc9\xba\x57\xb4"
  3420. "\x4f\x45\x79\x7f\x67\x70\xbd\x63\x7f\xbf\x0d\x80\x7c\xbd\xba\xe0";
  3421. #endif
  3422. #ifdef WOLFSSL_SMALL_STACK
  3423. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3424. DYNAMIC_TYPE_TMP_BUFFER);
  3425. if (large_input == NULL) {
  3426. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3427. }
  3428. #endif
  3429. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3430. large_input[i] = (byte)(i & 0xFF);
  3431. }
  3432. #ifdef HASH_SIZE_LIMIT
  3433. times = 20;
  3434. #else
  3435. times = 100;
  3436. #endif
  3437. #ifdef WOLFSSL_PIC32MZ_HASH
  3438. wc_Sha256SizeSet(&sha, times * LARGE_HASH_TEST_INPUT_SZ);
  3439. #endif
  3440. for (i = 0; i < times; ++i) {
  3441. ret = wc_Sha256Update(&sha, (byte*)large_input,
  3442. LARGE_HASH_TEST_INPUT_SZ);
  3443. if (ret != 0)
  3444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3445. }
  3446. ret = wc_Sha256Final(&sha, hash);
  3447. if (ret != 0)
  3448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3449. if (XMEMCMP(hash, large_digest, WC_SHA256_DIGEST_SIZE) != 0)
  3450. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3451. } /* END LARGE HASH TEST */
  3452. #undef LARGE_HASH_TEST_INPUT_SZ
  3453. #endif /* NO_LARGE_HASH_TEST */
  3454. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_FULL_HASH)
  3455. {
  3456. WOLFSSL_SMALL_STACK_STATIC const unsigned char
  3457. data_hb[WC_SHA256_BLOCK_SIZE] = {
  3458. 0x61, 0x62, 0x63, 0x80, 0x00, 0x00, 0x00, 0x00,
  3459. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3460. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3461. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3462. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3463. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3464. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3465. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18
  3466. };
  3467. ret = wc_Sha256HashBlock(&sha, data_hb, hash);
  3468. if (ret != 0) {
  3469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3470. }
  3471. if (XMEMCMP(hash, b.output, WC_SHA256_DIGEST_SIZE) != 0) {
  3472. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3473. }
  3474. }
  3475. #endif
  3476. exit:
  3477. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3478. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3479. #endif
  3480. wc_Sha256Free(&sha);
  3481. wc_Sha256Free(&shaCopy);
  3482. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3483. wc_Sha256Free(&i_sha);
  3484. wc_Sha256Free(&i_shaCopy);
  3485. #endif
  3486. return ret;
  3487. }
  3488. #endif
  3489. #ifdef WOLFSSL_SHA512
  3490. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
  3491. {
  3492. /*
  3493. ** See https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf
  3494. */
  3495. wc_Sha512 sha, shaCopy;
  3496. byte hash[WC_SHA512_DIGEST_SIZE];
  3497. byte hashcopy[WC_SHA512_DIGEST_SIZE];
  3498. wc_test_ret_t ret = 0;
  3499. testVector a, b, c;
  3500. testVector test_sha[3];
  3501. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3502. wc_Sha512 i_sha, i_shaCopy;
  3503. byte i_hash[WC_SHA512_DIGEST_SIZE];
  3504. byte i_hashcopy[WC_SHA512_DIGEST_SIZE];
  3505. testVector interleave_test_sha[3];
  3506. #endif
  3507. #ifndef NO_LARGE_HASH_TEST
  3508. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3509. #ifdef WOLFSSL_SMALL_STACK
  3510. byte *large_input = NULL;
  3511. #else
  3512. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3513. #endif
  3514. #endif
  3515. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3516. WOLFSSL_ENTER("sha512_test");
  3517. a.input = "";
  3518. a.output = "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80"
  3519. "\x07\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c"
  3520. "\xe9\xce\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87"
  3521. "\x7e\xec\x2f\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a"
  3522. "\xf9\x27\xda\x3e";
  3523. a.inLen = XSTRLEN(a.input);
  3524. a.outLen = WC_SHA512_DIGEST_SIZE;
  3525. b.input = "abc";
  3526. b.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  3527. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  3528. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  3529. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  3530. "\xa5\x4c\xa4\x9f";
  3531. b.inLen = XSTRLEN(b.input);
  3532. b.outLen = WC_SHA512_DIGEST_SIZE;
  3533. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3534. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3535. c.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  3536. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  3537. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  3538. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  3539. "\x87\x4b\xe9\x09";
  3540. c.inLen = XSTRLEN(c.input);
  3541. c.outLen = WC_SHA512_DIGEST_SIZE;
  3542. test_sha[0] = a;
  3543. test_sha[1] = b;
  3544. test_sha[2] = c;
  3545. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3546. interleave_test_sha[0] = a;
  3547. interleave_test_sha[1] = b;
  3548. interleave_test_sha[2] = c;
  3549. #endif
  3550. ret = wc_InitSha512_ex(&sha, HEAP_HINT, devId);
  3551. if (ret != 0)
  3552. return WC_TEST_RET_ENC_EC(ret);
  3553. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3554. ret = wc_InitSha512_ex(&i_sha, HEAP_HINT, devId);
  3555. if (ret != 0)
  3556. return WC_TEST_RET_ENC_EC(ret);
  3557. #endif
  3558. ret = wc_InitSha512_ex(&shaCopy, HEAP_HINT, devId);
  3559. if (ret != 0) {
  3560. wc_Sha512Free(&sha);
  3561. return WC_TEST_RET_ENC_EC(ret);
  3562. }
  3563. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3564. ret = wc_InitSha512_ex(&i_shaCopy, HEAP_HINT, devId);
  3565. if (ret != 0) {
  3566. wc_Sha512Free(&sha);
  3567. wc_Sha512Free(&i_sha);
  3568. return WC_TEST_RET_ENC_EC(ret);
  3569. }
  3570. #endif
  3571. for (i = 0; i < times; ++i) {
  3572. ret = wc_Sha512Update(&sha, (byte*)test_sha[i].input,
  3573. (word32)test_sha[i].inLen);
  3574. if (ret != 0)
  3575. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3576. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3577. ret = wc_Sha512Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3578. (word32)interleave_test_sha[i].inLen);
  3579. if (ret != 0)
  3580. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3581. #endif
  3582. ret = wc_Sha512GetHash(&sha, hashcopy);
  3583. if (ret != 0)
  3584. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3585. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3586. ret = wc_Sha512GetHash(&i_sha, i_hashcopy);
  3587. if (ret != 0)
  3588. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3589. #endif
  3590. ret = wc_Sha512Copy(&sha, &shaCopy);
  3591. if (ret != 0)
  3592. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3593. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3594. ret = wc_Sha512Copy(&i_sha, &i_shaCopy);
  3595. if (ret != 0)
  3596. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3597. #endif
  3598. ret = wc_Sha512Final(&sha, hash);
  3599. if (ret != 0)
  3600. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3601. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3602. ret = wc_Sha512Final(&i_sha, i_hash);
  3603. if (ret != 0)
  3604. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3605. #endif
  3606. wc_Sha512Free(&shaCopy);
  3607. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3608. wc_Sha512Free(&i_shaCopy);
  3609. #endif
  3610. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  3611. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3612. if (XMEMCMP(hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0)
  3613. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3614. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3615. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3616. WC_SHA512_DIGEST_SIZE) != 0) {
  3617. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3618. }
  3619. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3620. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3621. }
  3622. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0) {
  3623. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3624. }
  3625. if (XMEMCMP(i_hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3626. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3627. }
  3628. #endif
  3629. }
  3630. #ifndef NO_LARGE_HASH_TEST
  3631. /* BEGIN LARGE HASH TEST */ {
  3632. #ifdef HASH_SIZE_LIMIT
  3633. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3634. "\x30\x9B\x96\xA6\xE9\x43\x78\x30\xA3\x71\x51\x61\xC1\xEB\xE1\xBE"
  3635. "\xC8\xA5\xF9\x13\x5A\xD6\x6D\x9E\x46\x31\x31\x67\x8D\xE2\xC0\x0B"
  3636. "\x2A\x1A\x03\xE1\xF3\x48\xA7\x33\xBD\x49\xF8\xFF\xF1\xC2\xC2\x95"
  3637. "\xCB\xF0\xAF\x87\x61\x85\x58\x63\x6A\xCA\x70\x9C\x8B\x83\x3F\x5D";
  3638. #else
  3639. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3640. "\x5a\x1f\x73\x90\xbd\x8c\xe4\x63\x54\xce\xa0\x9b\xef\x32\x78\x2d"
  3641. "\x2e\xe7\x0d\x5e\x2f\x9d\x15\x1b\xdd\x2d\xde\x65\x0c\x7b\xfa\x83"
  3642. "\x5e\x80\x02\x13\x84\xb8\x3f\xff\x71\x62\xb5\x09\x89\x63\xe1\xdc"
  3643. "\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
  3644. #endif
  3645. #ifdef WOLFSSL_SMALL_STACK
  3646. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3647. DYNAMIC_TYPE_TMP_BUFFER);
  3648. if (large_input == NULL) {
  3649. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3650. }
  3651. #endif
  3652. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3653. large_input[i] = (byte)(i & 0xFF);
  3654. }
  3655. #ifdef HASH_SIZE_LIMIT
  3656. times = 20;
  3657. #else
  3658. times = 100;
  3659. #endif
  3660. for (i = 0; i < times; ++i) {
  3661. ret = wc_Sha512Update(&sha, (byte*)large_input,
  3662. LARGE_HASH_TEST_INPUT_SZ);
  3663. if (ret != 0)
  3664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3665. }
  3666. ret = wc_Sha512Final(&sha, hash);
  3667. if (ret != 0)
  3668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3669. if (XMEMCMP(hash, large_digest, WC_SHA512_DIGEST_SIZE) != 0)
  3670. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3671. #ifndef NO_UNALIGNED_MEMORY_TEST
  3672. /* Unaligned memory access test */
  3673. for (i = 1; i < 16; i++) {
  3674. ret = wc_Sha512Update(&sha, (byte*)large_input + i,
  3675. LARGE_HASH_TEST_INPUT_SZ - i);
  3676. if (ret != 0)
  3677. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3678. ret = wc_Sha512Final(&sha, hash);
  3679. }
  3680. #endif
  3681. } /* END LARGE HASH TEST */
  3682. #undef LARGE_HASH_TEST_INPUT_SZ
  3683. #endif /* NO_LARGE_HASH_TEST */
  3684. exit:
  3685. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3686. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3687. #endif
  3688. wc_Sha512Free(&sha);
  3689. wc_Sha512Free(&shaCopy);
  3690. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3691. wc_Sha512Free(&i_sha);
  3692. wc_Sha512Free(&i_shaCopy);
  3693. #endif
  3694. return ret;
  3695. }
  3696. #if !defined(WOLFSSL_NOSHA512_224) && \
  3697. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3698. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void)
  3699. {
  3700. /*
  3701. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3702. **
  3703. ** NIST SHA512/224 Document Example:
  3704. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_224.pdf
  3705. */
  3706. wc_Sha512 sha, shaCopy;
  3707. byte hash[WC_SHA512_224_DIGEST_SIZE];
  3708. byte hashcopy[WC_SHA512_224_DIGEST_SIZE];
  3709. wc_test_ret_t ret = 0;
  3710. testVector a, b, c;
  3711. testVector test_sha[3];
  3712. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3713. WOLFSSL_ENTER("sha512_224_test");
  3714. a.input = "";
  3715. a.output = "\x6e\xd0\xdd\x02"
  3716. "\x80\x6f\xa8\x9e" "\x25\xde\x06\x0c"
  3717. "\x19\xd3\xac\x86" "\xca\xbb\x87\xd6"
  3718. "\xa0\xdd\xd0\x5c" "\x33\x3b\x84\xf4";
  3719. a.inLen = XSTRLEN(a.input);
  3720. a.outLen = WC_SHA512_224_DIGEST_SIZE;
  3721. /*
  3722. ** See page 1 in above document for the SHA512/224 "abc" test:
  3723. */
  3724. b.input = "abc";
  3725. /*
  3726. ** See page 1 in above document for the SHA512/224 "abc" test digest:
  3727. */
  3728. b.output = "\x46\x34\x27\x0f"
  3729. "\x70\x7b\x6a\x54" "\xda\xae\x75\x30"
  3730. "\x46\x08\x42\xe2" "\x0e\x37\xed\x26"
  3731. "\x5c\xee\xe9\xa4" "\x3e\x89\x24\xaa";
  3732. b.inLen = XSTRLEN(b.input);
  3733. b.outLen = WC_SHA512_224_DIGEST_SIZE;
  3734. /*
  3735. ** See page 4 in above for the 2-block test:
  3736. */
  3737. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3738. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3739. /*
  3740. ** see page 9 in above document for the 2-block test message digest:
  3741. */
  3742. c.output = "\x23\xfe\xc5\xbb"
  3743. "\x94\xd6\x0b\x23" "\x30\x81\x92\x64"
  3744. "\x0b\x0c\x45\x33" "\x35\xd6\x64\x73"
  3745. "\x4f\xe4\x0e\x72" "\x68\x67\x4a\xf9";
  3746. c.inLen = XSTRLEN(c.input);
  3747. c.outLen = WC_SHA512_224_DIGEST_SIZE;
  3748. test_sha[0] = a;
  3749. test_sha[1] = b;
  3750. test_sha[2] = c;
  3751. ret = wc_InitSha512_224_ex(&sha, HEAP_HINT, devId);
  3752. if (ret != 0)
  3753. return WC_TEST_RET_ENC_EC(ret);
  3754. ret = wc_InitSha512_224_ex(&shaCopy, HEAP_HINT, devId);
  3755. if (ret != 0) {
  3756. wc_Sha512_224Free(&sha);
  3757. return WC_TEST_RET_ENC_EC(ret);
  3758. }
  3759. for (i = 0; i < times; ++i) {
  3760. ret = wc_Sha512_224Update(&sha, (byte*)test_sha[i].input,
  3761. (word32)test_sha[i].inLen);
  3762. if (ret != 0)
  3763. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3764. ret = wc_Sha512_224GetHash(&sha, hashcopy);
  3765. if (ret != 0)
  3766. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3767. ret = wc_Sha512_224Copy(&sha, &shaCopy);
  3768. if (ret != 0)
  3769. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3770. ret = wc_Sha512_224Final(&sha, hash);
  3771. if (ret != 0)
  3772. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3773. wc_Sha512_224Free(&shaCopy);
  3774. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_224_DIGEST_SIZE) != 0)
  3775. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3776. if (XMEMCMP(hash, hashcopy, WC_SHA512_224_DIGEST_SIZE) != 0)
  3777. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3778. }
  3779. #ifndef NO_LARGE_HASH_TEST
  3780. /* BEGIN LARGE HASH TEST */ {
  3781. byte large_input[1024];
  3782. #ifdef HASH_SIZE_LIMIT
  3783. const char* large_digest =
  3784. "\x98\x68\xc3\xd9\xb9\xef\x17\x53"
  3785. "\x43\x66\x0e\x60\xdf\x29\xf8\xef"
  3786. "\x96\xe3\x93\x34\x8c\x6f\xc0\xeb"
  3787. "\x14\x6c\xcf\x6a";
  3788. #else
  3789. const char* large_digest =
  3790. "\x26\x5f\x98\xd1\x76\x49\x71\x4e"
  3791. "\x82\xb7\x9d\x52\x32\x67\x9d\x56"
  3792. "\x91\xf5\x88\xc3\x05\xbb\x3f\x90"
  3793. "\xe2\x4e\x85\x05";
  3794. #endif
  3795. for (i = 0; i < (int)sizeof(large_input); i++) {
  3796. large_input[i] = (byte)(i & 0xFF);
  3797. }
  3798. #ifdef HASH_SIZE_LIMIT
  3799. times = 20;
  3800. #else
  3801. times = 100;
  3802. #endif
  3803. for (i = 0; i < times; ++i) {
  3804. ret = wc_Sha512_224Update(&sha, (byte*)large_input,
  3805. (word32)sizeof(large_input));
  3806. if (ret != 0)
  3807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3808. }
  3809. ret = wc_Sha512_224Final(&sha, hash);
  3810. if (ret != 0)
  3811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3812. if (XMEMCMP(hash, large_digest, WC_SHA512_224_DIGEST_SIZE) != 0)
  3813. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3814. #ifndef NO_UNALIGNED_MEMORY_TEST
  3815. /* Unaligned memory access test */
  3816. for (i = 1; i < 16; i++) {
  3817. ret = wc_Sha512_224Update(&sha, (byte*)large_input + i,
  3818. (word32)sizeof(large_input) - i);
  3819. if (ret != 0)
  3820. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3821. ret = wc_Sha512_224Final(&sha, hash);
  3822. }
  3823. #endif
  3824. } /* END LARGE HASH TEST */
  3825. #endif /* NO_LARGE_HASH_TEST */
  3826. exit:
  3827. wc_Sha512_224Free(&sha);
  3828. wc_Sha512_224Free(&shaCopy);
  3829. return ret;
  3830. } /* sha512_224_test */
  3831. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  3832. #if !defined(WOLFSSL_NOSHA512_256) && \
  3833. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3834. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void)
  3835. {
  3836. /*
  3837. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3838. ** NIST SHA512/256 Document Example:
  3839. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_256.pdf
  3840. */
  3841. wc_Sha512 sha, shaCopy;
  3842. byte hash[WC_SHA512_256_DIGEST_SIZE];
  3843. byte hashcopy[WC_SHA512_256_DIGEST_SIZE];
  3844. wc_test_ret_t ret = 0;
  3845. testVector a, b, c;
  3846. testVector test_sha[3];
  3847. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3848. WOLFSSL_ENTER("sha512_256_test");
  3849. a.input = "";
  3850. a.output = "\xc6\x72\xb8\xd1" "\xef\x56\xed\x28"
  3851. "\xab\x87\xc3\x62" "\x2c\x51\x14\x06"
  3852. "\x9b\xdd\x3a\xd7" "\xb8\xf9\x73\x74"
  3853. "\x98\xd0\xc0\x1e" "\xce\xf0\x96\x7a";
  3854. a.inLen = XSTRLEN(a.input);
  3855. a.outLen = WC_SHA512_256_DIGEST_SIZE;
  3856. /*
  3857. ** See page 1 of above document for "abc" example:
  3858. */
  3859. b.input = "abc";
  3860. /*
  3861. ** See page 4 of above document for "abc" example digest:
  3862. */
  3863. b.output = "\x53\x04\x8e\x26" "\x81\x94\x1e\xf9"
  3864. "\x9b\x2e\x29\xb7" "\x6b\x4c\x7d\xab"
  3865. "\xe4\xc2\xd0\xc6" "\x34\xfc\x6d\x46"
  3866. "\xe0\xe2\xf1\x31" "\x07\xe7\xaf\x23";
  3867. b.inLen = XSTRLEN(b.input);
  3868. b.outLen = WC_SHA512_256_DIGEST_SIZE;
  3869. /*
  3870. ** See page 4 of above document for Two Block Message Sample:
  3871. */
  3872. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3873. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3874. /*
  3875. ** See page 10 of above document for Two Block Message Sample digest:
  3876. */
  3877. c.output = "\x39\x28\xe1\x84" "\xfb\x86\x90\xf8"
  3878. "\x40\xda\x39\x88" "\x12\x1d\x31\xbe"
  3879. "\x65\xcb\x9d\x3e" "\xf8\x3e\xe6\x14"
  3880. "\x6f\xea\xc8\x61" "\xe1\x9b\x56\x3a";
  3881. c.inLen = XSTRLEN(c.input);
  3882. c.outLen = WC_SHA512_256_DIGEST_SIZE;
  3883. test_sha[0] = a;
  3884. test_sha[1] = b;
  3885. test_sha[2] = c;
  3886. ret = wc_InitSha512_256_ex(&sha, HEAP_HINT, devId);
  3887. if (ret != 0)
  3888. return WC_TEST_RET_ENC_EC(ret);
  3889. ret = wc_InitSha512_256_ex(&shaCopy, HEAP_HINT, devId);
  3890. if (ret != 0) {
  3891. wc_Sha512_256Free(&sha);
  3892. return WC_TEST_RET_ENC_EC(ret);
  3893. }
  3894. for (i = 0; i < times; ++i) {
  3895. ret = wc_Sha512_256Update(&sha, (byte*)test_sha[i].input,
  3896. (word32)test_sha[i].inLen);
  3897. if (ret != 0)
  3898. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3899. ret = wc_Sha512_256GetHash(&sha, hashcopy);
  3900. if (ret != 0)
  3901. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3902. ret = wc_Sha512_256Copy(&sha, &shaCopy);
  3903. if (ret != 0)
  3904. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3905. ret = wc_Sha512_256Final(&sha, hash);
  3906. if (ret != 0)
  3907. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3908. wc_Sha512_256Free(&shaCopy);
  3909. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_256_DIGEST_SIZE) != 0)
  3910. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3911. if (XMEMCMP(hash, hashcopy, WC_SHA512_256_DIGEST_SIZE) != 0)
  3912. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3913. }
  3914. #ifndef NO_LARGE_HASH_TEST
  3915. /* BEGIN LARGE HASH TEST */ {
  3916. byte large_input[1024];
  3917. #ifdef HASH_SIZE_LIMIT
  3918. const char* large_digest =
  3919. "\x49\xcc\xbc\x7a\x93\x0b\x02\xb8"
  3920. "\xad\x9a\x46\x51\x00\x1f\x13\x80"
  3921. "\x35\x84\x36\xf1\xf2\x3c\xeb\xd8"
  3922. "\x41\xd4\x06\x8b\x1d\x19\xad\x72";
  3923. #else
  3924. const char* large_digest =
  3925. "\x7a\xe3\x84\x05\xcb\x06\x22\x08"
  3926. "\x7e\x2c\x65\x89\x1f\x26\x45\xfd"
  3927. "\xad\xbc\x2e\x29\x83\x12\x84\x4b"
  3928. "\xf2\xa0\xde\xbe\x06\x11\xd7\x44";
  3929. #endif
  3930. for (i = 0; i < (int)sizeof(large_input); i++) {
  3931. large_input[i] = (byte)(i & 0xFF);
  3932. }
  3933. #ifdef HASH_SIZE_LIMIT
  3934. times = 20;
  3935. #else
  3936. times = 100;
  3937. #endif
  3938. for (i = 0; i < times; ++i) {
  3939. ret = wc_Sha512_256Update(&sha, (byte*)large_input,
  3940. (word32)sizeof(large_input));
  3941. if (ret != 0)
  3942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3943. }
  3944. ret = wc_Sha512_256Final(&sha, hash);
  3945. if (ret != 0)
  3946. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3947. if (XMEMCMP(hash, large_digest, WC_SHA512_256_DIGEST_SIZE) != 0)
  3948. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3949. #ifndef NO_UNALIGNED_MEMORY_TEST
  3950. /* Unaligned memory access test */
  3951. for (i = 1; i < 16; i++) {
  3952. ret = wc_Sha512_256Update(&sha, (byte*)large_input + i,
  3953. (word32)sizeof(large_input) - i);
  3954. if (ret != 0)
  3955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3956. ret = wc_Sha512_256Final(&sha, hash);
  3957. }
  3958. #endif
  3959. } /* END LARGE HASH TEST */
  3960. #endif /* NO_LARGE_HASH_TEST */
  3961. exit:
  3962. wc_Sha512_256Free(&sha);
  3963. wc_Sha512_256Free(&shaCopy);
  3964. return ret;
  3965. } /* sha512_256_test */
  3966. #endif /* !defined(WOLFSSL_NOSHA512_256) && !FIPS ... */
  3967. #endif /* WOLFSSL_SHA512 */
  3968. #ifdef WOLFSSL_SHA384
  3969. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void)
  3970. {
  3971. wc_Sha384 sha, shaCopy;
  3972. byte hash[WC_SHA384_DIGEST_SIZE];
  3973. byte hashcopy[WC_SHA384_DIGEST_SIZE];
  3974. wc_test_ret_t ret = 0;
  3975. testVector a, b, c;
  3976. testVector test_sha[3];
  3977. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3978. WOLFSSL_ENTER("sha384_test");
  3979. a.input = "";
  3980. a.output = "\x38\xb0\x60\xa7\x51\xac\x96\x38\x4c\xd9\x32\x7e\xb1\xb1\xe3"
  3981. "\x6a\x21\xfd\xb7\x11\x14\xbe\x07\x43\x4c\x0c\xc7\xbf\x63\xf6"
  3982. "\xe1\xda\x27\x4e\xde\xbf\xe7\x6f\x65\xfb\xd5\x1a\xd2\xf1\x48"
  3983. "\x98\xb9\x5b";
  3984. a.inLen = XSTRLEN(a.input);
  3985. a.outLen = WC_SHA384_DIGEST_SIZE;
  3986. b.input = "abc";
  3987. b.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  3988. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  3989. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  3990. "\xc8\x25\xa7";
  3991. b.inLen = XSTRLEN(b.input);
  3992. b.outLen = WC_SHA384_DIGEST_SIZE;
  3993. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3994. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3995. c.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  3996. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  3997. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  3998. "\x74\x60\x39";
  3999. c.inLen = XSTRLEN(c.input);
  4000. c.outLen = WC_SHA384_DIGEST_SIZE;
  4001. test_sha[0] = a;
  4002. test_sha[1] = b;
  4003. test_sha[2] = c;
  4004. ret = wc_InitSha384_ex(&sha, HEAP_HINT, devId);
  4005. if (ret != 0)
  4006. return WC_TEST_RET_ENC_EC(ret);
  4007. ret = wc_InitSha384_ex(&shaCopy, HEAP_HINT, devId);
  4008. if (ret != 0) {
  4009. wc_Sha384Free(&sha);
  4010. return WC_TEST_RET_ENC_EC(ret);
  4011. }
  4012. for (i = 0; i < times; ++i) {
  4013. ret = wc_Sha384Update(&sha, (byte*)test_sha[i].input,
  4014. (word32)test_sha[i].inLen);
  4015. if (ret != 0)
  4016. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4017. ret = wc_Sha384GetHash(&sha, hashcopy);
  4018. if (ret != 0)
  4019. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4020. ret = wc_Sha384Copy(&sha, &shaCopy);
  4021. if (ret != 0)
  4022. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4023. ret = wc_Sha384Final(&sha, hash);
  4024. if (ret != 0)
  4025. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4026. wc_Sha384Free(&shaCopy);
  4027. if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  4028. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4029. if (XMEMCMP(hash, hashcopy, WC_SHA384_DIGEST_SIZE) != 0)
  4030. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4031. }
  4032. #ifndef NO_LARGE_HASH_TEST
  4033. /* BEGIN LARGE HASH TEST */ {
  4034. byte large_input[1024];
  4035. #ifdef HASH_SIZE_LIMIT
  4036. const char* large_digest =
  4037. "\xB5\xAD\x66\x6F\xD9\x58\x5E\x68\xDD\x5E\x30\xD3\x95\x72\x33\xA4"
  4038. "\xE9\x4B\x99\x3A\xEF\xF8\xE1\xBF\x1F\x05\x32\xAA\x16\x00\x82\xEC"
  4039. "\x15\xDA\xF2\x75\xEE\xE9\x06\xAF\x52\x8A\x5C\xEF\x72\x81\x80\xD6";
  4040. #else
  4041. const char* large_digest =
  4042. "\x37\x01\xdb\xff\x1e\x40\x4f\xe1\xe2\xea\x0b\x40\xbb\x3b\x39\x9a"
  4043. "\xcc\xe8\x44\x8e\x7e\xe5\x64\xb5\x6b\x7f\x56\x64\xa7\x2b\x84\xe3"
  4044. "\xc5\xd7\x79\x03\x25\x90\xf7\xa4\x58\xcb\x97\xa8\x8b\xb1\xa4\x81";
  4045. #endif
  4046. for (i = 0; i < (int)sizeof(large_input); i++) {
  4047. large_input[i] = (byte)(i & 0xFF);
  4048. }
  4049. #ifdef HASH_SIZE_LIMIT
  4050. times = 20;
  4051. #else
  4052. times = 100;
  4053. #endif
  4054. for (i = 0; i < times; ++i) {
  4055. ret = wc_Sha384Update(&sha, (byte*)large_input,
  4056. (word32)sizeof(large_input));
  4057. if (ret != 0)
  4058. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4059. }
  4060. ret = wc_Sha384Final(&sha, hash);
  4061. if (ret != 0)
  4062. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4063. if (XMEMCMP(hash, large_digest, WC_SHA384_DIGEST_SIZE) != 0)
  4064. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4065. } /* END LARGE HASH TEST */
  4066. #endif /* NO_LARGE_HASH_TEST */
  4067. exit:
  4068. wc_Sha384Free(&sha);
  4069. wc_Sha384Free(&shaCopy);
  4070. return ret;
  4071. }
  4072. #endif /* WOLFSSL_SHA384 */
  4073. #ifdef WOLFSSL_SHA3
  4074. #ifndef WOLFSSL_NOSHA3_224
  4075. static wc_test_ret_t sha3_224_test(void)
  4076. {
  4077. wc_Sha3 sha;
  4078. byte hash[WC_SHA3_224_DIGEST_SIZE];
  4079. byte hashcopy[WC_SHA3_224_DIGEST_SIZE];
  4080. testVector a, b, c;
  4081. testVector test_sha[3];
  4082. wc_test_ret_t ret = 0;
  4083. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4084. a.input = "";
  4085. a.output = "\x6b\x4e\x03\x42\x36\x67\xdb\xb7\x3b\x6e\x15\x45\x4f\x0e\xb1"
  4086. "\xab\xd4\x59\x7f\x9a\x1b\x07\x8e\x3f\x5b\x5a\x6b\xc7";
  4087. a.inLen = XSTRLEN(a.input);
  4088. a.outLen = WC_SHA3_224_DIGEST_SIZE;
  4089. b.input = "abc";
  4090. b.output = "\xe6\x42\x82\x4c\x3f\x8c\xf2\x4a\xd0\x92\x34\xee\x7d\x3c\x76"
  4091. "\x6f\xc9\xa3\xa5\x16\x8d\x0c\x94\xad\x73\xb4\x6f\xdf";
  4092. b.inLen = XSTRLEN(b.input);
  4093. b.outLen = WC_SHA3_224_DIGEST_SIZE;
  4094. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4095. c.output = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55\x74\x49\x44\x79"
  4096. "\xba\x5c\x7e\x7a\xb7\x6e\xf2\x64\xea\xd0\xfc\xce\x33";
  4097. c.inLen = XSTRLEN(c.input);
  4098. c.outLen = WC_SHA3_224_DIGEST_SIZE;
  4099. test_sha[0] = a;
  4100. test_sha[1] = b;
  4101. test_sha[2] = c;
  4102. ret = wc_InitSha3_224(&sha, HEAP_HINT, devId);
  4103. if (ret != 0)
  4104. return WC_TEST_RET_ENC_EC(ret);
  4105. for (i = 0; i < times; ++i) {
  4106. ret = wc_Sha3_224_Update(&sha, (byte*)test_sha[i].input,
  4107. (word32)test_sha[i].inLen);
  4108. if (ret != 0)
  4109. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4110. ret = wc_Sha3_224_GetHash(&sha, hashcopy);
  4111. if (ret != 0)
  4112. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4113. ret = wc_Sha3_224_Final(&sha, hash);
  4114. if (ret != 0)
  4115. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4116. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_224_DIGEST_SIZE) != 0)
  4117. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4118. if (XMEMCMP(hash, hashcopy, WC_SHA3_224_DIGEST_SIZE) != 0)
  4119. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4120. }
  4121. #ifndef NO_LARGE_HASH_TEST
  4122. /* BEGIN LARGE HASH TEST */ {
  4123. byte large_input[1024];
  4124. const char* large_digest =
  4125. "\x13\xe5\xd3\x98\x7b\x94\xda\x41\x12\xc7\x1e\x92\x3a\x19"
  4126. "\x21\x20\x86\x6f\x24\xbf\x0a\x31\xbc\xfd\xd6\x70\x36\xf3";
  4127. for (i = 0; i < (int)sizeof(large_input); i++) {
  4128. large_input[i] = (byte)(i & 0xFF);
  4129. }
  4130. times = 100;
  4131. for (i = 0; i < times; ++i) {
  4132. ret = wc_Sha3_224_Update(&sha, (byte*)large_input,
  4133. (word32)sizeof(large_input));
  4134. if (ret != 0)
  4135. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4136. }
  4137. ret = wc_Sha3_224_Final(&sha, hash);
  4138. if (ret != 0)
  4139. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4140. if (XMEMCMP(hash, large_digest, WC_SHA3_224_DIGEST_SIZE) != 0)
  4141. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4142. } /* END LARGE HASH TEST */
  4143. #endif /* NO_LARGE_HASH_TEST */
  4144. exit:
  4145. wc_Sha3_224_Free(&sha);
  4146. return ret;
  4147. }
  4148. #endif /* WOLFSSL_NOSHA3_224 */
  4149. #ifndef WOLFSSL_NOSHA3_256
  4150. static wc_test_ret_t sha3_256_test(void)
  4151. {
  4152. wc_Sha3 sha;
  4153. byte hash[WC_SHA3_256_DIGEST_SIZE];
  4154. byte hashcopy[WC_SHA3_256_DIGEST_SIZE];
  4155. testVector a, b, c;
  4156. testVector test_sha[3];
  4157. wc_test_ret_t ret = 0;
  4158. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4159. byte large_input[1024];
  4160. const char* large_digest =
  4161. "\xdc\x90\xc0\xb1\x25\xdb\x2c\x34\x81\xa3\xff\xbc\x1e\x2e\x87\xeb"
  4162. "\x6d\x70\x85\x61\xe0\xe9\x63\x61\xff\xe5\x84\x4b\x1f\x68\x05\x15";
  4163. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4164. /* test vector with hash of empty string */
  4165. const char* Keccak256EmptyOut =
  4166. "\xc5\xd2\x46\x01\x86\xf7\x23\x3c\x92\x7e\x7d\xb2\xdc\xc7\x03\xc0"
  4167. "\xe5\x00\xb6\x53\xca\x82\x27\x3b\x7b\xfa\xd8\x04\x5d\x85\xa4\x70";
  4168. #endif
  4169. /*
  4170. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-256_Msg0.pdf
  4171. */
  4172. a.input = "";
  4173. a.output = "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66\x51\xc1\x47\x56\xa0\x61\xd6"
  4174. "\x62\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8"
  4175. "\x43\x4a";
  4176. a.inLen = XSTRLEN(a.input);
  4177. a.outLen = WC_SHA3_256_DIGEST_SIZE;
  4178. b.input = "abc";
  4179. b.output = "\x3a\x98\x5d\xa7\x4f\xe2\x25\xb2\x04\x5c\x17\x2d\x6b\xd3\x90"
  4180. "\xbd\x85\x5f\x08\x6e\x3e\x9d\x52\x5b\x46\xbf\xe2\x45\x11\x43"
  4181. "\x15\x32";
  4182. b.inLen = XSTRLEN(b.input);
  4183. b.outLen = WC_SHA3_256_DIGEST_SIZE;
  4184. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4185. c.output = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8\x23\x5e"
  4186. "\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32\xdd\x97\x49\x6d"
  4187. "\x33\x76";
  4188. c.inLen = XSTRLEN(c.input);
  4189. c.outLen = WC_SHA3_256_DIGEST_SIZE;
  4190. test_sha[0] = a;
  4191. test_sha[1] = b;
  4192. test_sha[2] = c;
  4193. ret = wc_InitSha3_256(&sha, HEAP_HINT, devId);
  4194. if (ret != 0)
  4195. return WC_TEST_RET_ENC_EC(ret);
  4196. for (i = 0; i < times; ++i) {
  4197. ret = wc_Sha3_256_Update(&sha, (byte*)test_sha[i].input,
  4198. (word32)test_sha[i].inLen);
  4199. if (ret != 0)
  4200. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4201. ret = wc_Sha3_256_GetHash(&sha, hashcopy);
  4202. if (ret != 0)
  4203. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4204. ret = wc_Sha3_256_Final(&sha, hash);
  4205. if (ret != 0)
  4206. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4207. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_256_DIGEST_SIZE) != 0)
  4208. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4209. if (XMEMCMP(hash, hashcopy, WC_SHA3_256_DIGEST_SIZE) != 0)
  4210. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4211. }
  4212. #ifndef NO_LARGE_HASH_TEST
  4213. /* BEGIN LARGE HASH TEST */ {
  4214. for (i = 0; i < (int)sizeof(large_input); i++) {
  4215. large_input[i] = (byte)(i & 0xFF);
  4216. }
  4217. times = 100;
  4218. for (i = 0; i < times; ++i) {
  4219. ret = wc_Sha3_256_Update(&sha, (byte*)large_input,
  4220. (word32)sizeof(large_input));
  4221. if (ret != 0)
  4222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4223. }
  4224. ret = wc_Sha3_256_Final(&sha, hash);
  4225. if (ret != 0)
  4226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4227. if (XMEMCMP(hash, large_digest, WC_SHA3_256_DIGEST_SIZE) != 0)
  4228. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4229. } /* END LARGE HASH TEST */
  4230. #endif /* NO_LARGE_HASH_TEST */
  4231. /* this is a software only variant of SHA3 not supported by external hardware devices */
  4232. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4233. /* Test for Keccak256 */
  4234. ret = wc_Sha3_SetFlags(&sha, WC_HASH_SHA3_KECCAK256);
  4235. if (ret != 0) {
  4236. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4237. }
  4238. ret = wc_Sha3_256_Update(&sha, (byte*)"", 0);
  4239. if (ret != 0) {
  4240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4241. }
  4242. ret = wc_Sha3_256_Final(&sha, hash);
  4243. if (ret != 0) {
  4244. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4245. }
  4246. if (XMEMCMP(hash, Keccak256EmptyOut, WC_SHA3_256_DIGEST_SIZE) != 0) {
  4247. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4248. }
  4249. #endif /* WOLFSSL_HASH_FLAGS && !WOLFSSL_ASYNC_CRYPT */
  4250. exit:
  4251. wc_Sha3_256_Free(&sha);
  4252. return ret;
  4253. }
  4254. #endif /* WOLFSSL_NOSHA3_256 */
  4255. #ifndef WOLFSSL_NOSHA3_384
  4256. static wc_test_ret_t sha3_384_test(void)
  4257. {
  4258. wc_Sha3 sha;
  4259. byte hash[WC_SHA3_384_DIGEST_SIZE];
  4260. byte buf[64];
  4261. #ifndef NO_INTM_HASH_TEST
  4262. byte hashcopy[WC_SHA3_384_DIGEST_SIZE];
  4263. #endif
  4264. testVector a, b, c;
  4265. testVector test_sha[3];
  4266. wc_test_ret_t ret;
  4267. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4268. /*
  4269. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-384_Msg0.pdf
  4270. */
  4271. a.input = "";
  4272. a.output = "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d\x01\x10\x7d\x85\x2e\x4c\x24"
  4273. "\x85\xc5\x1a\x50\xaa\xaa\x94\xfc\x61\x99\x5e\x71\xbb\xee\x98"
  4274. "\x3a\x2a\xc3\x71\x38\x31\x26\x4a\xdb\x47\xfb\x6b\xd1\xe0\x58"
  4275. "\xd5\xf0\x04";
  4276. a.inLen = XSTRLEN(a.input);
  4277. a.outLen = WC_SHA3_384_DIGEST_SIZE;
  4278. #if defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4279. /* NIST test vector with a length that is a multiple of 4 */
  4280. b.input = "\x7d\x80\xb1\x60\xc4\xb5\x36\xa3\xbe\xb7\x99\x80\x59\x93\x44"
  4281. "\x04\x7c\x5f\x82\xa1\xdf\xc3\xee\xd4";
  4282. b.output = "\x04\x1c\xc5\x86\x1b\xa3\x34\x56\x3c\x61\xd4\xef\x97\x10\xd4"
  4283. "\x89\x6c\x31\x1c\x92\xed\xbe\x0d\x7c\xd5\x3e\x80\x3b\xf2\xf4"
  4284. "\xeb\x60\x57\x23\x55\x70\x77\x0c\xe8\x7c\x55\x20\xd7\xec\x14"
  4285. "\x19\x87\x22";
  4286. b.inLen = XSTRLEN(b.input);
  4287. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4288. #else
  4289. b.input = "abc";
  4290. b.output = "\xec\x01\x49\x82\x88\x51\x6f\xc9\x26\x45\x9f\x58\xe2\xc6\xad"
  4291. "\x8d\xf9\xb4\x73\xcb\x0f\xc0\x8c\x25\x96\xda\x7c\xf0\xe4\x9b"
  4292. "\xe4\xb2\x98\xd8\x8c\xea\x92\x7a\xc7\xf5\x39\xf1\xed\xf2\x28"
  4293. "\x37\x6d\x25";
  4294. b.inLen = XSTRLEN(b.input);
  4295. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4296. #endif
  4297. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4298. c.output = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7\x8a\x49"
  4299. "\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd\xbc\x32\xb9\xd4"
  4300. "\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe\xa1\x9e\xef\x51\xac\xd0"
  4301. "\x65\x7c\x22";
  4302. c.inLen = XSTRLEN(c.input);
  4303. c.outLen = WC_SHA3_384_DIGEST_SIZE;
  4304. #if defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4305. test_sha[0] = b; /* hardware acc. pre-Versal can not handle "" string */
  4306. #else
  4307. test_sha[0] = a;
  4308. #endif
  4309. test_sha[1] = b;
  4310. test_sha[2] = c;
  4311. ret = wc_InitSha3_384(&sha, HEAP_HINT, devId);
  4312. if (ret != 0)
  4313. return WC_TEST_RET_ENC_EC(ret);
  4314. for (i = 0; i < times; ++i) {
  4315. XMEMCPY(buf, test_sha[i].input, test_sha[i].inLen);
  4316. ret = wc_Sha3_384_Update(&sha, buf,
  4317. (word32)test_sha[i].inLen);
  4318. if (ret != 0)
  4319. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4320. #ifndef NO_INTM_HASH_TEST
  4321. ret = wc_Sha3_384_GetHash(&sha, hashcopy);
  4322. if (ret != 0)
  4323. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4324. #endif
  4325. ret = wc_Sha3_384_Final(&sha, hash);
  4326. if (ret != 0)
  4327. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4328. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_384_DIGEST_SIZE) != 0)
  4329. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4330. #ifndef NO_INTM_HASH_TEST
  4331. if (XMEMCMP(hash, hashcopy, WC_SHA3_384_DIGEST_SIZE) != 0)
  4332. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4333. #endif
  4334. }
  4335. #ifndef NO_LARGE_HASH_TEST
  4336. /* BEGIN LARGE HASH TEST */ {
  4337. byte large_input[1024];
  4338. const char* large_digest =
  4339. "\x30\x44\xec\x17\xef\x47\x9f\x55\x36\x11\xd6\x3f\x8a\x31\x5a\x71"
  4340. "\x8a\x71\xa7\x1d\x8e\x84\xe8\x6c\x24\x02\x2f\x7a\x08\x4e\xea\xd7"
  4341. "\x42\x36\x5d\xa8\xc2\xb7\x42\xad\xec\x19\xfb\xca\xc6\x64\xb3\xa4";
  4342. for (i = 0; i < (int)sizeof(large_input); i++) {
  4343. large_input[i] = (byte)(i & 0xFF);
  4344. }
  4345. times = 100;
  4346. for (i = 0; i < times; ++i) {
  4347. ret = wc_Sha3_384_Update(&sha, (byte*)large_input,
  4348. (word32)sizeof(large_input));
  4349. if (ret != 0)
  4350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4351. }
  4352. ret = wc_Sha3_384_Final(&sha, hash);
  4353. if (ret != 0)
  4354. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4355. if (XMEMCMP(hash, large_digest, WC_SHA3_384_DIGEST_SIZE) != 0)
  4356. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4357. } /* END LARGE HASH TEST */
  4358. #endif /* NO_LARGE_HASH_TEST */
  4359. exit:
  4360. wc_Sha3_384_Free(&sha);
  4361. return ret;
  4362. }
  4363. #endif /* WOLFSSL_NOSHA3_384 */
  4364. #ifndef WOLFSSL_NOSHA3_512
  4365. static wc_test_ret_t sha3_512_test(void)
  4366. {
  4367. wc_Sha3 sha;
  4368. byte hash[WC_SHA3_512_DIGEST_SIZE];
  4369. byte hashcopy[WC_SHA3_512_DIGEST_SIZE];
  4370. testVector a, b, c;
  4371. testVector test_sha[3];
  4372. wc_test_ret_t ret;
  4373. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4374. /*
  4375. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-512_Msg0.pdf
  4376. */
  4377. a.input = "";
  4378. a.output = "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5\xc8\xb5\x67\xdc\x18\x5a\x75"
  4379. "\x6e\x97\xc9\x82\x16\x4f\xe2\x58\x59\xe0\xd1\xdc\xc1\x47\x5c"
  4380. "\x80\xa6\x15\xb2\x12\x3a\xf1\xf5\xf9\x4c\x11\xe3\xe9\x40\x2c"
  4381. "\x3a\xc5\x58\xf5\x00\x19\x9d\x95\xb6\xd3\xe3\x01\x75\x85\x86"
  4382. "\x28\x1d\xcd\x26";
  4383. a.inLen = XSTRLEN(a.input);
  4384. a.outLen = WC_SHA3_512_DIGEST_SIZE;
  4385. b.input = "abc";
  4386. b.output = "\xb7\x51\x85\x0b\x1a\x57\x16\x8a\x56\x93\xcd\x92\x4b\x6b\x09"
  4387. "\x6e\x08\xf6\x21\x82\x74\x44\xf7\x0d\x88\x4f\x5d\x02\x40\xd2"
  4388. "\x71\x2e\x10\xe1\x16\xe9\x19\x2a\xf3\xc9\x1a\x7e\xc5\x76\x47"
  4389. "\xe3\x93\x40\x57\x34\x0b\x4c\xf4\x08\xd5\xa5\x65\x92\xf8\x27"
  4390. "\x4e\xec\x53\xf0";
  4391. b.inLen = XSTRLEN(b.input);
  4392. b.outLen = WC_SHA3_512_DIGEST_SIZE;
  4393. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4394. c.output = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10\xfc\xa8"
  4395. "\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7\xec\x2f\x1e\x91"
  4396. "\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53\x02\xba\x1b\x0d\x8d\xc7"
  4397. "\x8c\x08\x63\x46\xb5\x33\xb4\x9c\x03\x0d\x99\xa2\x7d\xaf\x11"
  4398. "\x39\xd6\xe7\x5e";
  4399. c.inLen = XSTRLEN(c.input);
  4400. c.outLen = WC_SHA3_512_DIGEST_SIZE;
  4401. test_sha[0] = a;
  4402. test_sha[1] = b;
  4403. test_sha[2] = c;
  4404. ret = wc_InitSha3_512(&sha, HEAP_HINT, devId);
  4405. if (ret != 0)
  4406. return WC_TEST_RET_ENC_EC(ret);
  4407. for (i = 0; i < times; ++i) {
  4408. ret = wc_Sha3_512_Update(&sha, (byte*)test_sha[i].input,
  4409. (word32)test_sha[i].inLen);
  4410. if (ret != 0)
  4411. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4412. ret = wc_Sha3_512_GetHash(&sha, hashcopy);
  4413. if (ret != 0)
  4414. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4415. ret = wc_Sha3_512_Final(&sha, hash);
  4416. if (ret != 0)
  4417. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4418. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_512_DIGEST_SIZE) != 0)
  4419. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4420. if (XMEMCMP(hash, hashcopy, WC_SHA3_512_DIGEST_SIZE) != 0)
  4421. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4422. }
  4423. #ifndef NO_LARGE_HASH_TEST
  4424. /* BEGIN LARGE HASH TEST */ {
  4425. byte large_input[1024];
  4426. const char* large_digest =
  4427. "\x9c\x13\x26\xb6\x26\xb2\x94\x31\xbc\xf4\x34\xe9\x6f\xf2\xd6\x29"
  4428. "\x9a\xd0\x9b\x32\x63\x2f\x18\xa7\x5f\x23\xc9\x60\xc2\x32\x0c\xbc"
  4429. "\x57\x77\x33\xf1\x83\x81\x8a\xd3\x15\x7c\x93\xdc\x80\x9f\xed\x61"
  4430. "\x41\xa7\x5b\xfd\x32\x0e\x38\x15\xb0\x46\x3b\x7a\x4f\xfd\x44\x88";
  4431. for (i = 0; i < (int)sizeof(large_input); i++) {
  4432. large_input[i] = (byte)(i & 0xFF);
  4433. }
  4434. times = 100;
  4435. for (i = 0; i < times; ++i) {
  4436. ret = wc_Sha3_512_Update(&sha, (byte*)large_input,
  4437. (word32)sizeof(large_input));
  4438. if (ret != 0)
  4439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4440. }
  4441. ret = wc_Sha3_512_Final(&sha, hash);
  4442. if (ret != 0)
  4443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4444. if (XMEMCMP(hash, large_digest, WC_SHA3_512_DIGEST_SIZE) != 0)
  4445. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4446. } /* END LARGE HASH TEST */
  4447. #endif /* NO_LARGE_HASH_TEST */
  4448. exit:
  4449. wc_Sha3_512_Free(&sha);
  4450. return ret;
  4451. }
  4452. #endif /* WOLFSSL_NOSHA3_512 */
  4453. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void)
  4454. {
  4455. wc_test_ret_t ret;
  4456. (void)ret;
  4457. WOLFSSL_ENTER("sha3_test");
  4458. #ifndef WOLFSSL_NOSHA3_224
  4459. if ((ret = sha3_224_test()) != 0)
  4460. return ret;
  4461. #endif
  4462. #ifndef WOLFSSL_NOSHA3_256
  4463. if ((ret = sha3_256_test()) != 0)
  4464. return ret;
  4465. #endif
  4466. #ifndef WOLFSSL_NOSHA3_384
  4467. if ((ret = sha3_384_test()) != 0)
  4468. return ret;
  4469. #endif
  4470. #ifndef WOLFSSL_NOSHA3_512
  4471. if ((ret = sha3_512_test()) != 0)
  4472. return ret;
  4473. #endif
  4474. return 0;
  4475. }
  4476. #endif /* WOLFSSL_SHA3 */
  4477. #ifdef WOLFSSL_SHAKE128
  4478. static wc_test_ret_t shake128_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4479. size_t large_input_buf_size)
  4480. {
  4481. testVector a, b, c, d, e;
  4482. testVector test_sha[5];
  4483. wc_test_ret_t ret = 0;
  4484. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4485. static const char large_digest[] =
  4486. "\x2b\xd1\x69\x9f\xb3\x75\x40\x74\xb8\xb2\xd2\x0b\x92\x47\x9b\xfe"
  4487. "\xc9\x91\x48\xbe\xda\xa4\x09\xd7\x61\x35\x18\x05\x07\x71\xa5\x61"
  4488. "\x4d\xc4\x94\xad\xbe\x04\x7d\xad\x95\x2f\xeb\x2c\xc0\x10\x67\x43"
  4489. "\x40\xf1\x4a\x58\x1c\x54\xfa\x24\x1c\x1a\x4e\x8d\x9b\xbc\xea\xa7"
  4490. "\x32\xf2\x4c\xc7\x86\x05\x36\xdc\xb4\x42\xd8\x35\xd1\xb4\xa2\x79"
  4491. "\xa2\xe6\xee\x67\x4f\xbf\x2a\x93\x41\x88\x25\x56\x29\x90\x1a\x06"
  4492. "\xba\xfe\x9f\xa6\x1a\x74\xe8\x7e\x85\x4a\xc8\x58\x60\xb1\x7b\x18"
  4493. "\xdf\x77\x59\x46\x04\xc1\xff\x4b\x9b\xcb\xad\xfe\x91\x28\xf0\x01"
  4494. "\xc1\x33\xd0\x99\x99\x2e\x0c\x86\x84\x67\x4d\x37\xa4\x42\x45\x10"
  4495. "\xdc\x8f\xdb\x6f\xa6\x9b\xee\x8a\x60\xa5\x1f\x95\x3f\x8f\xf5\x31"
  4496. "\x4b\x1d\x48\x1e\x45\xff\x79\x5c\xbe\x72\xfc\x56\xed\x6d\x1a\x99"
  4497. "\x7f\x23\x7c\xd1\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b"
  4498. "\xa3\x60\x51\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41"
  4499. "\x77\x2c\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59"
  4500. "\x0d\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4501. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d\xa8"
  4502. "\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb\x67\x86"
  4503. "\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b\x3d\xca\x95"
  4504. "\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47\xcf\x56\xba\x71"
  4505. "\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a\xff\xb4\xbe\x72\x26"
  4506. "\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e\xd9\xe9\xe6\xf9\xff\xa5";
  4507. byte hash[sizeof(large_digest) - 1];
  4508. /*
  4509. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4510. */
  4511. a.input = "";
  4512. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4513. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4514. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4515. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4516. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4517. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4518. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4519. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a\x04\x30\x2e\x10\xc8\xbc"
  4520. "\x1c\xbf\x1a\x0b\x3a\x51\x20\xea\x17\xcd\xa7\xcf\xad\x76\x5f"
  4521. "\x56\x23\x47\x4d\x36\x8c\xcc\xa8\xaf\x00\x07\xcd\x9f\x5e\x4c"
  4522. "\x84\x9f\x16\x7a\x58\x0b\x14\xaa\xbd\xef\xae\xe7\xee\xf4\x7c"
  4523. "\xb0\xfc\xa9";
  4524. a.inLen = XSTRLEN(a.input);
  4525. a.outLen = WC_SHA3_128_BLOCK_SIZE;
  4526. b.input = "abc";
  4527. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4528. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4529. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4530. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4531. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4532. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4533. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4534. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3\x77\xcf\xb9\xcd\xe4\xc6"
  4535. "\x35\x99\xb2\x7f\x34\x62\xbb\xa4\xa0\xed\x29\x6c\x80\x1f\x9f"
  4536. "\xf7\xf5\x73\x02\xbb\x30\x76\xee\x14\x5f\x97\xa3\x2a\xe6\x8e"
  4537. "\x76\xab\x66\xc4\x8d\x51\x67\x5b\xd4\x9a\xcc\x29\x08\x2f\x56"
  4538. "\x47\x58\x4e";
  4539. b.inLen = XSTRLEN(b.input);
  4540. b.outLen = WC_SHA3_128_BLOCK_SIZE;
  4541. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4542. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4543. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4544. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4545. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4546. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4547. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4548. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4549. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa\x54\x56\x54\xf7\x0a\xe5"
  4550. "\x86\xff\x10\x13\x14\x20\x77\x14\x83\xec\x92\xed\xab\x40\x8c"
  4551. "\x76\x7b\xf4\xc5\xb4\xff\xfa\xa8\x0c\x8c\xa2\x14\xd8\x4c\x4d"
  4552. "\xc7\x00\xd0\xc5\x06\x30\xb2\xff\xc3\x79\x3e\xa4\xd8\x72\x58"
  4553. "\xb4\xc9\x54";
  4554. c.inLen = XSTRLEN(c.input);
  4555. c.outLen = WC_SHA3_128_BLOCK_SIZE;
  4556. /* Taken from NIST CAVP test vectors - full rate output. */
  4557. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4558. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4559. "\x85\xe0";
  4560. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4561. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4562. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4563. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4564. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4565. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4566. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4567. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4568. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4569. "\xa1\x41\x9b\xaf\x60\x52\xc0\xc1\xb4\x45\xf8\x35\x17\x57\xb0"
  4570. "\xd0\x22\x87\x21\x89\xe2\xc0\x27\x3f\x82\xd9\x69\x69\x66\x3e"
  4571. "\x55\x4d\x09";
  4572. d.inLen = 32;
  4573. d.outLen = WC_SHA3_128_BLOCK_SIZE;
  4574. /* Taken from NIST CAVP test vectors - more than one output block. */
  4575. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4576. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4577. "\x47\xe4";
  4578. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4579. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4580. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4581. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4582. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4583. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4584. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4585. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4586. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4587. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4588. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4589. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4590. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4591. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4592. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4593. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4594. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d"
  4595. "\xa8\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb"
  4596. "\x67\x86\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b"
  4597. "\x3d\xca\x95\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47"
  4598. "\xcf\x56\xba\x71\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a"
  4599. "\xff\xb4\xbe\x72\x26\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e"
  4600. "\xd9\xe9\xe6\xf9\xff\xa5";
  4601. e.inLen = 32;
  4602. e.outLen = 2 * WC_SHA3_128_BLOCK_SIZE;
  4603. test_sha[0] = a;
  4604. test_sha[1] = b;
  4605. test_sha[2] = c;
  4606. test_sha[3] = d;
  4607. test_sha[4] = e;
  4608. for (i = 0; i < times; ++i) {
  4609. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4610. if (ret != 0)
  4611. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4612. ret = wc_Shake128_Absorb(sha, (byte*)test_sha[i].input,
  4613. (word32)test_sha[i].inLen);
  4614. if (ret != 0)
  4615. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4616. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4617. (word32)test_sha[i].outLen / WC_SHA3_128_BLOCK_SIZE);
  4618. if (ret != 0)
  4619. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4620. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  4621. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4622. }
  4623. #ifndef NO_LARGE_HASH_TEST
  4624. /* BEGIN LARGE HASH TEST */ {
  4625. for (i = 0; i < (int)large_input_buf_size; i++) {
  4626. large_input_buf[i] = (byte)(i & 0xFF);
  4627. }
  4628. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4629. if (ret != 0)
  4630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4631. /* Absorb is non-incremental. */
  4632. ret = wc_Shake128_Absorb(sha, (byte*)large_input_buf,
  4633. (word32)large_input_buf_size);
  4634. if (ret != 0)
  4635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4636. /* Able to squeeze out blocks incrementally. */
  4637. ret = wc_Shake128_SqueezeBlocks(sha, hash, 1);
  4638. if (ret != 0)
  4639. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4640. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4641. ((word32)sizeof(hash) / WC_SHA3_128_BLOCK_SIZE) - 1);
  4642. if (ret != 0)
  4643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4644. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  4645. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4646. } /* END LARGE HASH TEST */
  4647. #endif /* NO_LARGE_HASH_TEST */
  4648. exit:
  4649. return ret;
  4650. }
  4651. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void)
  4652. {
  4653. wc_Shake sha;
  4654. byte hash[250];
  4655. testVector a, b, c, d, e;
  4656. testVector test_sha[5];
  4657. wc_test_ret_t ret = 0;
  4658. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4659. #define SHAKE128_LARGE_INPUT_BUFSIZ 1024
  4660. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4661. byte *large_input = NULL;
  4662. #else
  4663. byte large_input[SHAKE128_LARGE_INPUT_BUFSIZ];
  4664. #endif
  4665. static const char large_digest[] =
  4666. "\x88\xd7\x0e\x86\x46\x72\x6b\x3d\x7d\x22\xe1\xa9\x2d\x02\xdb\x35"
  4667. "\x92\x4f\x1b\x03\x90\xee\xa3\xce\xd1\x3a\x08\x3a\xd7\x4e\x10\xdf"
  4668. "\x09\x67\x33\x35\x4f\xdd\x38\x50\x5b\xcb\x75\xc7\xba\x65\xe5\xe8"
  4669. "\xb8\x76\xde\xc5\xee\xd7\xf1\x65\x93\x4e\x5e\xc4\xb1\xd7\x6b\xee"
  4670. "\x4b\x57\x48\xf5\x38\x49\x9e\x45\xa0\xf7\x32\xe9\x05\x26\x6a\x10"
  4671. "\x70\xd4\x7c\x19\x01\x1f\x6d\x37\xba\x7b\x74\xc2\xbc\xb6\xbc\x74"
  4672. "\xa3\x66\x6c\x9b\x11\x84\x9d\x4a\x36\xbc\x8a\x0d\x4c\xe3\x39\xfa"
  4673. "\xfa\x1b";
  4674. WOLFSSL_ENTER("shake128_test");
  4675. /*
  4676. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4677. */
  4678. a.input = "";
  4679. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4680. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4681. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4682. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4683. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4684. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4685. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4686. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a";
  4687. a.inLen = XSTRLEN(a.input);
  4688. a.outLen = 114;
  4689. b.input = "abc";
  4690. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4691. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4692. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4693. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4694. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4695. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4696. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4697. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3";
  4698. b.inLen = XSTRLEN(b.input);
  4699. b.outLen = 114;
  4700. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4701. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4702. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4703. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4704. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4705. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4706. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4707. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4708. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa";
  4709. c.inLen = XSTRLEN(c.input);
  4710. c.outLen = 114;
  4711. /* Taken from NIST CAVP test vectors - full rate output. */
  4712. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4713. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4714. "\x85\xe0";
  4715. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4716. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4717. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4718. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4719. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4720. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4721. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4722. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4723. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4724. "\xa1";
  4725. d.inLen = 32;
  4726. d.outLen = 136;
  4727. /* Taken from NIST CAVP test vectors - more than one output block. */
  4728. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4729. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4730. "\x47\xe4";
  4731. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4732. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4733. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4734. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4735. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4736. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4737. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4738. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4739. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4740. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4741. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4742. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4743. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4744. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4745. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4746. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4747. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4";
  4748. e.inLen = 32;
  4749. e.outLen = 250;
  4750. test_sha[0] = a;
  4751. test_sha[1] = b;
  4752. test_sha[2] = c;
  4753. test_sha[3] = d;
  4754. test_sha[4] = e;
  4755. ret = wc_InitShake128(&sha, HEAP_HINT, devId);
  4756. if (ret != 0)
  4757. return WC_TEST_RET_ENC_EC(ret);
  4758. for (i = 0; i < times; ++i) {
  4759. ret = wc_Shake128_Update(&sha, (byte*)test_sha[i].input,
  4760. (word32)test_sha[i].inLen);
  4761. if (ret != 0)
  4762. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4763. ret = wc_Shake128_Final(&sha, hash, (word32)test_sha[i].outLen);
  4764. if (ret != 0)
  4765. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4766. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  4767. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4768. }
  4769. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4770. large_input = (byte *)XMALLOC(SHAKE128_LARGE_INPUT_BUFSIZ, NULL,
  4771. DYNAMIC_TYPE_TMP_BUFFER);
  4772. if (large_input == NULL)
  4773. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  4774. #endif
  4775. #ifndef NO_LARGE_HASH_TEST
  4776. /* BEGIN LARGE HASH TEST */ {
  4777. for (i = 0; i < SHAKE128_LARGE_INPUT_BUFSIZ; i++) {
  4778. large_input[i] = (byte)(i & 0xFF);
  4779. }
  4780. times = 100;
  4781. for (i = 0; i < times; ++i) {
  4782. ret = wc_Shake128_Update(&sha, (byte*)large_input,
  4783. SHAKE128_LARGE_INPUT_BUFSIZ);
  4784. if (ret != 0)
  4785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4786. }
  4787. ret = wc_Shake128_Final(&sha, hash, (word32)sizeof(hash));
  4788. if (ret != 0)
  4789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4790. if (XMEMCMP(hash, large_digest, sizeof(large_digest) - 1) != 0)
  4791. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4792. } /* END LARGE HASH TEST */
  4793. #endif /* NO_LARGE_HASH_TEST */
  4794. ret = shake128_absorb_test(&sha, large_input, SHAKE128_LARGE_INPUT_BUFSIZ);
  4795. exit:
  4796. wc_Shake128_Free(&sha);
  4797. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4798. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4799. #endif
  4800. return ret;
  4801. }
  4802. #endif
  4803. #ifdef WOLFSSL_SHAKE256
  4804. static wc_test_ret_t shake256_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4805. size_t large_input_buf_size)
  4806. {
  4807. testVector a, b, c, d, e;
  4808. testVector test_sha[5];
  4809. wc_test_ret_t ret = 0;
  4810. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4811. static const char large_digest[] =
  4812. "\x21\x25\x8e\xae\x6e\x4f\xa7\xe1\xb9\x6d\xa7\xc9\x7d\x46\x03\x69"
  4813. "\x29\x0d\x81\x49\xba\x5d\xaf\x37\xfd\xeb\x25\x52\x1d\xd9\xbd\x65"
  4814. "\xfa\x99\xb9\xd1\x70\x6b\xeb\xd4\xc1\x2c\xea\x24\x20\x27\xa7\xcd"
  4815. "\xfa\xe1\x81\xd9\xd5\xc1\x1c\xc7\xe9\x70\xc3\xc7\x21\x6f\x32\x22"
  4816. "\xe3\x27\xdb\x58\x5e\xea\x18\x2d\x63\x4d\x14\x6c\x94\xcf\x2b\x7e"
  4817. "\x6e\x2a\x74\xf3\xe0\xac\xb3\xb2\xcc\xef\x38\xe9\xe7\x35\xb3\xc5"
  4818. "\x77\x9d\xff\xe3\x08\x8e\xf8\x2c\x89\xbb\x45\x22\x16\x99\x91\xc0"
  4819. "\xe7\x71\x57\x75\xc5\xb1\xc6\xaf\x27\xcb\x64\x8c\xc4\xee\x3d\x5f"
  4820. "\x4c\x35\xfb\x1c\xf3\xf8\x0e\xfd\x5e\xfc\x07\xd8\x4d\x55\x32\x49"
  4821. "\x45\x0d\xab\x4a\x49\xc4\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93"
  4822. "\x7a\xe6\x6b\xb4\x36\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43"
  4823. "\x2f\x3b\xfc\x09\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48"
  4824. "\x3d\x0e\xda\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08"
  4825. "\xd9\xdc\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a"
  4826. "\xb7\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  4827. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4\xe6"
  4828. "\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97\x68\x44";
  4829. byte hash[sizeof(large_digest) - 1];
  4830. /*
  4831. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  4832. */
  4833. a.input = "";
  4834. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  4835. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  4836. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  4837. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  4838. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  4839. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  4840. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  4841. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46\xc1\x85\xc1\x51\x11\xe5"
  4842. "\x95\x52\x2a\x6b\xcd\x16\xcf\x86\xf3\xd1\x22\x10\x9e\x3b\x1f"
  4843. "\xdd";
  4844. a.inLen = XSTRLEN(a.input);
  4845. a.outLen = WC_SHA3_256_BLOCK_SIZE;
  4846. b.input = "abc";
  4847. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  4848. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  4849. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  4850. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  4851. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  4852. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  4853. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  4854. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0\x9a\x3e\x6d\x51\xcb\xfc"
  4855. "\x62\x27\x20\xd7\xa7\x5c\x63\x34\xe8\xa2\xd7\xec\x71\xa7\xcc"
  4856. "\x29";
  4857. b.inLen = XSTRLEN(b.input);
  4858. b.outLen = WC_SHA3_256_BLOCK_SIZE;
  4859. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4860. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  4861. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  4862. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  4863. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  4864. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  4865. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  4866. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  4867. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4\x9d\xd3\xef\x7e\x18\x2b"
  4868. "\x15\x24\xdf\x82\xea\x1c\xef\xe1\xc6\xc3\x96\x61\x75\xf0\x22"
  4869. "\x8d";
  4870. c.inLen = XSTRLEN(c.input);
  4871. c.outLen = WC_SHA3_256_BLOCK_SIZE;
  4872. /* Taken from NIST CAVP test vectors - full rate output. */
  4873. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4874. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4875. "\x85\xe0";
  4876. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  4877. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  4878. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  4879. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  4880. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  4881. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  4882. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  4883. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  4884. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  4885. "\xc2";
  4886. d.inLen = 32;
  4887. d.outLen = WC_SHA3_256_BLOCK_SIZE;
  4888. /* Taken from NIST CAVP test vectors - more than one output block. */
  4889. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4890. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4891. "\x47\xe4";
  4892. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  4893. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  4894. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  4895. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  4896. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  4897. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  4898. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  4899. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  4900. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  4901. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  4902. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  4903. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  4904. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  4905. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  4906. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  4907. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  4908. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4"
  4909. "\xe6\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97"
  4910. "\x68\x44";
  4911. e.inLen = 32;
  4912. e.outLen = 2 * WC_SHA3_256_BLOCK_SIZE;
  4913. test_sha[0] = a;
  4914. test_sha[1] = b;
  4915. test_sha[2] = c;
  4916. test_sha[3] = d;
  4917. test_sha[4] = e;
  4918. for (i = 0; i < times; ++i) {
  4919. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  4920. if (ret != 0)
  4921. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4922. ret = wc_Shake256_Absorb(sha, (byte*)test_sha[i].input,
  4923. (word32)test_sha[i].inLen);
  4924. if (ret != 0)
  4925. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4926. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  4927. (word32)test_sha[i].outLen / WC_SHA3_256_BLOCK_SIZE);
  4928. if (ret != 0)
  4929. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4930. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  4931. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4932. }
  4933. #ifndef NO_LARGE_HASH_TEST
  4934. /* BEGIN LARGE HASH TEST */ {
  4935. for (i = 0; i < (int)large_input_buf_size; i++) {
  4936. large_input_buf[i] = (byte)(i & 0xFF);
  4937. }
  4938. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  4939. if (ret != 0)
  4940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4941. /* Absorb is non-incremental. */
  4942. ret = wc_Shake256_Absorb(sha, large_input_buf,
  4943. (word32)large_input_buf_size);
  4944. if (ret != 0)
  4945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4946. /* Able to squeeze out blocks incrementally. */
  4947. ret = wc_Shake256_SqueezeBlocks(sha, hash, 1);
  4948. if (ret != 0)
  4949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4950. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  4951. ((word32)sizeof(hash) / WC_SHA3_256_BLOCK_SIZE) - 1);
  4952. if (ret != 0)
  4953. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4954. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  4955. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4956. } /* END LARGE HASH TEST */
  4957. #endif /* NO_LARGE_HASH_TEST */
  4958. exit:
  4959. return ret;
  4960. }
  4961. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void)
  4962. {
  4963. wc_Shake sha;
  4964. byte hash[250];
  4965. testVector a, b, c, d, e;
  4966. testVector test_sha[5];
  4967. wc_test_ret_t ret = 0;
  4968. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4969. #define SHAKE256_LARGE_INPUT_BUFSIZ 1024
  4970. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4971. byte *large_input = NULL;
  4972. #else
  4973. byte large_input[SHAKE256_LARGE_INPUT_BUFSIZ];
  4974. #endif
  4975. const char* large_digest =
  4976. "\x90\x32\x4a\xcc\xd1\xdf\xb8\x0b\x79\x1f\xb8\xc8\x5b\x54\xc8\xe7"
  4977. "\x45\xf5\x60\x6b\x38\x26\xb2\x0a\xee\x38\x01\xf3\xd9\xfa\x96\x9f"
  4978. "\x6a\xd7\x15\xdf\xb6\xc2\xf4\x20\x33\x44\x55\xe8\x2a\x09\x2b\x68"
  4979. "\x2e\x18\x65\x5e\x65\x93\x28\xbc\xb1\x9e\xe2\xb1\x92\xea\x98\xac"
  4980. "\x21\xef\x4c\xe1\xb4\xb7\xbe\x81\x5c\x1d\xd3\xb7\x17\xe5\xbb\xc5"
  4981. "\x8c\x68\xb7\xfb\xac\x55\x8a\x9b\x4d\x91\xe4\x9f\x72\xbb\x6e\x38"
  4982. "\xaf\x21\x7d\x21\xaa\x98\x4e\x75\xc4\xb4\x1c\x7c\x50\x45\x54\xf9"
  4983. "\xea\x26";
  4984. WOLFSSL_ENTER("shake256_test");
  4985. /*
  4986. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  4987. */
  4988. a.input = "";
  4989. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  4990. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  4991. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  4992. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  4993. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  4994. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  4995. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  4996. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46";
  4997. a.inLen = XSTRLEN(a.input);
  4998. a.outLen = 114;
  4999. b.input = "abc";
  5000. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  5001. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  5002. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  5003. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  5004. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  5005. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  5006. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  5007. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0";
  5008. b.inLen = XSTRLEN(b.input);
  5009. b.outLen = 114;
  5010. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5011. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  5012. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  5013. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  5014. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  5015. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  5016. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  5017. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  5018. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  5019. c.inLen = XSTRLEN(c.input);
  5020. c.outLen = 114;
  5021. /* Taken from NIST CAVP test vectors - full rate output. */
  5022. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  5023. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  5024. "\x85\xe0";
  5025. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5026. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5027. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5028. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5029. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5030. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5031. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5032. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5033. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5034. "\xc2";
  5035. d.inLen = 32;
  5036. d.outLen = 136;
  5037. /* Taken from NIST CAVP test vectors - more than one output block. */
  5038. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5039. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5040. "\x47\xe4";
  5041. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5042. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5043. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5044. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5045. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5046. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5047. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5048. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5049. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5050. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5051. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5052. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5053. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5054. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5055. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5056. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5057. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c";
  5058. e.inLen = 32;
  5059. e.outLen = 250;
  5060. test_sha[0] = a;
  5061. test_sha[1] = b;
  5062. test_sha[2] = c;
  5063. test_sha[3] = d;
  5064. test_sha[4] = e;
  5065. ret = wc_InitShake256(&sha, HEAP_HINT, devId);
  5066. if (ret != 0)
  5067. return WC_TEST_RET_ENC_EC(ret);
  5068. for (i = 0; i < times; ++i) {
  5069. ret = wc_Shake256_Update(&sha, (byte*)test_sha[i].input,
  5070. (word32)test_sha[i].inLen);
  5071. if (ret != 0)
  5072. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5073. ret = wc_Shake256_Final(&sha, hash, (word32)test_sha[i].outLen);
  5074. if (ret != 0)
  5075. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5076. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  5077. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5078. }
  5079. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5080. large_input = (byte *)XMALLOC(SHAKE256_LARGE_INPUT_BUFSIZ, NULL,
  5081. DYNAMIC_TYPE_TMP_BUFFER);
  5082. if (large_input == NULL)
  5083. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  5084. #endif
  5085. #ifndef NO_LARGE_HASH_TEST
  5086. /* BEGIN LARGE HASH TEST */ {
  5087. for (i = 0; i < SHAKE256_LARGE_INPUT_BUFSIZ; i++) {
  5088. large_input[i] = (byte)(i & 0xFF);
  5089. }
  5090. times = 100;
  5091. for (i = 0; i < times; ++i) {
  5092. ret = wc_Shake256_Update(&sha, (byte*)large_input,
  5093. SHAKE256_LARGE_INPUT_BUFSIZ);
  5094. if (ret != 0)
  5095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5096. }
  5097. ret = wc_Shake256_Final(&sha, hash, (word32)sizeof(hash));
  5098. if (ret != 0)
  5099. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5100. if (XMEMCMP(hash, large_digest, 114) != 0)
  5101. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5102. } /* END LARGE HASH TEST */
  5103. #endif /* NO_LARGE_HASH_TEST */
  5104. ret = shake256_absorb_test(&sha, large_input, SHAKE256_LARGE_INPUT_BUFSIZ);
  5105. exit:
  5106. wc_Shake256_Free(&sha);
  5107. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5108. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5109. #endif
  5110. return ret;
  5111. }
  5112. #endif
  5113. #ifdef WOLFSSL_SM3
  5114. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void)
  5115. {
  5116. wc_Sm3 sm3, sm3Copy;
  5117. byte hash[WC_SM3_DIGEST_SIZE];
  5118. byte hashGet[WC_SM3_DIGEST_SIZE];
  5119. byte hashCopy[WC_SM3_DIGEST_SIZE];
  5120. wc_test_ret_t ret = 0;
  5121. WOLFSSL_ENTER("sm3_test");
  5122. testVector a, b, c;
  5123. testVector test_sm3[3];
  5124. int times = sizeof(test_sm3) / sizeof(struct testVector), i;
  5125. a.input = "";
  5126. a.output = "\x1a\xb2\x1d\x83\x55\xcf\xa1\x7f\x8e\x61\x19\x48\x31\xe8\x1a"
  5127. "\x8f\x22\xbe\xc8\xc7\x28\xfe\xfb\x74\x7e\xd0\x35\xeb\x50\x82"
  5128. "\xaa\x2b";
  5129. a.inLen = XSTRLEN(a.input);
  5130. a.outLen = WC_SM3_DIGEST_SIZE;
  5131. b.input = "abc";
  5132. b.output = "\x66\xc7\xf0\xf4\x62\xee\xed\xd9\xd1\xf2\xd4\x6b\xdc\x10\xe4"
  5133. "\xe2\x41\x67\xc4\x87\x5c\xf2\xf7\xa2\x29\x7d\xa0\x2b\x8f\x4b"
  5134. "\xa8\xe0";
  5135. b.inLen = XSTRLEN(b.input);
  5136. b.outLen = WC_SM3_DIGEST_SIZE;
  5137. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5138. c.output = "\x63\x9b\x6c\xc5\xe6\x4d\x9e\x37\xa3\x90\xb1\x92\xdf\x4f\xa1"
  5139. "\xea\x07\x20\xab\x74\x7f\xf6\x92\xb9\xf3\x8c\x4e\x66\xad\x7b"
  5140. "\x8c\x05";
  5141. c.inLen = XSTRLEN(c.input);
  5142. c.outLen = WC_SM3_DIGEST_SIZE;
  5143. test_sm3[0] = a;
  5144. test_sm3[1] = b;
  5145. test_sm3[2] = c;
  5146. ret = wc_InitSm3(&sm3, HEAP_HINT, devId);
  5147. if (ret != 0)
  5148. return WC_TEST_RET_ENC_EC(ret);
  5149. ret = wc_InitSm3(&sm3Copy, HEAP_HINT, devId);
  5150. if (ret != 0) {
  5151. wc_Sm3Free(&sm3);
  5152. return WC_TEST_RET_ENC_EC(ret);
  5153. }
  5154. /* Test all the KATs. */
  5155. for (i = 0; i < times; ++i) {
  5156. ret = wc_Sm3Update(&sm3, (byte*)test_sm3[i].input,
  5157. (word32)test_sm3[i].inLen);
  5158. if (ret != 0) {
  5159. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5160. }
  5161. /* Get the final hash but leave ready for more updates. */
  5162. ret = wc_Sm3GetHash(&sm3, hashGet);
  5163. if (ret != 0)
  5164. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5165. /* Make a copy of the hash. */
  5166. ret = wc_Sm3Copy(&sm3, &sm3Copy);
  5167. if (ret != 0)
  5168. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5169. /* Get the final hash with original. */
  5170. ret = wc_Sm3Final(&sm3, hash);
  5171. if (ret != 0)
  5172. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5173. /* Get the final hash with copy. */
  5174. ret = wc_Sm3Final(&sm3Copy, hashCopy);
  5175. if (ret != 0)
  5176. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5177. /* Dispose of copy. */
  5178. wc_Sm3Free(&sm3Copy);
  5179. /* Check hashes match expected. */
  5180. if (XMEMCMP(hash, test_sm3[i].output, WC_SM3_DIGEST_SIZE) != 0)
  5181. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5182. if (XMEMCMP(hash, hashGet, WC_SM3_DIGEST_SIZE) != 0)
  5183. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5184. if (XMEMCMP(hash, hashCopy, WC_SM3_DIGEST_SIZE) != 0)
  5185. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5186. }
  5187. #ifndef NO_LARGE_HASH_TEST
  5188. {
  5189. word32 sz;
  5190. byte large_input[1024];
  5191. #ifdef HASH_SIZE_LIMIT
  5192. const char* large_digest =
  5193. "\x6c\x42\x57\x64\x8e\x45\xf3\xb6\xc0\x83\xd3\x41\x83\x66\x51\xb4"
  5194. "\x50\xfe\x06\xb5\xb7\x1e\xd5\x0d\x41\xfc\x1e\xe5\xc6\x57\x95\x0f";
  5195. times = 20;
  5196. #else
  5197. const char* large_digest =
  5198. "\x34\x51\x3c\xde\x7c\x30\xb7\xc5\xaa\x97\x3b\xed\xb3\x16\xb9\x76"
  5199. "\x35\x46\x14\x80\x2a\x57\xca\xd9\x48\xf9\x93\xcc\x1f\xdd\xab\x79";
  5200. times = 100;
  5201. #endif
  5202. /* Set large input to something. */
  5203. for (i = 0; i < (int)sizeof(large_input); i++) {
  5204. large_input[i] = (byte)(i & 0xFF);
  5205. }
  5206. /* Hash a large number of times. */
  5207. for (i = 0; i < times; ++i) {
  5208. ret = wc_Sm3Update(&sm3, (byte*)large_input,
  5209. (word32)sizeof(large_input));
  5210. if (ret != 0)
  5211. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5212. }
  5213. /* Calculate hash and compare to expected. */
  5214. ret = wc_Sm3Final(&sm3, hash);
  5215. if (ret != 0)
  5216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5217. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5219. /* Check updating with various sizes works. */
  5220. for (sz = 1; sz <= 64; sz++) {
  5221. /* Hash a large number of times. */
  5222. for (i = 0; i < times; ++i) {
  5223. word32 o;
  5224. /* Update sz bytes at a time from large input buffer. */
  5225. for (o = 0; o + sz <= (word32)sizeof(large_input); o += sz) {
  5226. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o), sz);
  5227. if (ret != 0)
  5228. ERROR_OUT(WC_TEST_RET_ENC_I(o), exit);
  5229. }
  5230. /* Check for left-overs. */
  5231. if (o < (word32)sizeof(large_input)) {
  5232. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o),
  5233. (word32)sizeof(large_input) - o);
  5234. if (ret != 0)
  5235. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5236. }
  5237. }
  5238. /* Calculate hash and compare to expected. */
  5239. ret = wc_Sm3Final(&sm3, hash);
  5240. if (ret != 0)
  5241. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5242. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5243. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5244. }
  5245. }
  5246. #endif /* NO_LARGE_HASH_TEST */
  5247. exit:
  5248. wc_Sm3Free(&sm3);
  5249. wc_Sm3Free(&sm3Copy);
  5250. return ret;
  5251. }
  5252. #endif
  5253. #ifndef NO_HASH_WRAPPER
  5254. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void)
  5255. {
  5256. wc_HashAlg hash;
  5257. int ret, exp_ret;
  5258. int i, j;
  5259. int digestSz;
  5260. byte data[] = "0123456789abcdef0123456789abcdef0123456";
  5261. byte out[WC_MAX_DIGEST_SIZE];
  5262. byte hashOut[WC_MAX_DIGEST_SIZE];
  5263. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5264. enum wc_HashType hashType;
  5265. #endif
  5266. enum wc_HashType typesGood[] = { WC_HASH_TYPE_MD5, WC_HASH_TYPE_SHA,
  5267. WC_HASH_TYPE_SHA224, WC_HASH_TYPE_SHA256,
  5268. WC_HASH_TYPE_SHA384, WC_HASH_TYPE_SHA512,
  5269. WC_HASH_TYPE_SHA3_224,
  5270. WC_HASH_TYPE_SHA3_256,
  5271. WC_HASH_TYPE_SHA3_384,
  5272. WC_HASH_TYPE_SHA3_512 };
  5273. enum wc_HashType typesNoImpl[] = {
  5274. #ifdef NO_MD5
  5275. WC_HASH_TYPE_MD5,
  5276. #endif
  5277. #ifdef NO_SHA
  5278. WC_HASH_TYPE_SHA,
  5279. #endif
  5280. #ifndef WOLFSSL_SHA224
  5281. WC_HASH_TYPE_SHA224,
  5282. #endif
  5283. #ifdef NO_SHA256
  5284. WC_HASH_TYPE_SHA256,
  5285. #endif
  5286. #ifndef WOLFSSL_SHA384
  5287. WC_HASH_TYPE_SHA384,
  5288. #endif
  5289. #ifndef WOLFSSL_SHA512
  5290. WC_HASH_TYPE_SHA512,
  5291. #endif
  5292. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_224)
  5293. WC_HASH_TYPE_SHA3_224,
  5294. #endif
  5295. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_256)
  5296. WC_HASH_TYPE_SHA3_256,
  5297. #endif
  5298. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_384)
  5299. WC_HASH_TYPE_SHA3_384,
  5300. #endif
  5301. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_512)
  5302. WC_HASH_TYPE_SHA3_512,
  5303. #endif
  5304. WC_HASH_TYPE_NONE
  5305. };
  5306. enum wc_HashType typesBad[] = { WC_HASH_TYPE_NONE, WC_HASH_TYPE_MD5_SHA,
  5307. WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4 };
  5308. enum wc_HashType typesHashBad[] = { WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4,
  5309. WC_HASH_TYPE_BLAKE2B,
  5310. WC_HASH_TYPE_NONE };
  5311. WOLFSSL_ENTER("hash_test");
  5312. /* Parameter Validation testing. */
  5313. ret = wc_HashInit(NULL, WC_HASH_TYPE_SHA256);
  5314. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5315. return WC_TEST_RET_ENC_EC(ret);
  5316. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5317. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5318. return WC_TEST_RET_ENC_EC(ret);
  5319. ret = wc_HashUpdate(&hash, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5320. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5321. return WC_TEST_RET_ENC_EC(ret);
  5322. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, data, sizeof(data));
  5323. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5324. return WC_TEST_RET_ENC_EC(ret);
  5325. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, NULL);
  5326. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5327. return WC_TEST_RET_ENC_EC(ret);
  5328. ret = wc_HashFinal(&hash, WC_HASH_TYPE_SHA256, NULL);
  5329. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5330. return WC_TEST_RET_ENC_EC(ret);
  5331. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, out);
  5332. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5333. return WC_TEST_RET_ENC_EC(ret);
  5334. /* Try invalid hash algorithms. */
  5335. for (i = 0; i < (int)(sizeof(typesBad)/sizeof(*typesBad)); i++) {
  5336. ret = wc_HashInit(&hash, typesBad[i]);
  5337. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5338. return WC_TEST_RET_ENC_I(i);
  5339. ret = wc_HashUpdate(&hash, typesBad[i], data, sizeof(data));
  5340. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5341. return WC_TEST_RET_ENC_I(i);
  5342. ret = wc_HashFinal(&hash, typesBad[i], out);
  5343. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5344. return WC_TEST_RET_ENC_I(i);
  5345. wc_HashFree(&hash, typesBad[i]);
  5346. }
  5347. /* Try valid hash algorithms. */
  5348. for (i = 0, j = 0; i < (int)(sizeof(typesGood)/sizeof(*typesGood)); i++) {
  5349. exp_ret = 0;
  5350. if (typesGood[i] == typesNoImpl[j]) {
  5351. /* Recognized but no implementation compiled in. */
  5352. exp_ret = HASH_TYPE_E;
  5353. j++;
  5354. }
  5355. ret = wc_HashInit(&hash, typesGood[i]);
  5356. if (ret != exp_ret)
  5357. return WC_TEST_RET_ENC_I(i);
  5358. ret = wc_HashUpdate(&hash, typesGood[i], data, sizeof(data));
  5359. if (ret != exp_ret)
  5360. return WC_TEST_RET_ENC_I(i);
  5361. ret = wc_HashFinal(&hash, typesGood[i], out);
  5362. if (ret != exp_ret)
  5363. return WC_TEST_RET_ENC_I(i);
  5364. wc_HashFree(&hash, typesGood[i]);
  5365. digestSz = wc_HashGetDigestSize(typesGood[i]);
  5366. if (exp_ret < 0 && digestSz != exp_ret)
  5367. return WC_TEST_RET_ENC_I(i);
  5368. if (exp_ret == 0 && digestSz < 0)
  5369. return WC_TEST_RET_ENC_I(i);
  5370. if (exp_ret == 0) {
  5371. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut,
  5372. digestSz - 1);
  5373. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  5374. return WC_TEST_RET_ENC_I(i);
  5375. }
  5376. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, (word32)digestSz);
  5377. if (ret != exp_ret)
  5378. return WC_TEST_RET_ENC_I(i);
  5379. if (exp_ret == 0 && XMEMCMP(out, hashOut, digestSz) != 0)
  5380. return WC_TEST_RET_ENC_I(i);
  5381. ret = wc_HashGetBlockSize(typesGood[i]);
  5382. if (exp_ret < 0 && ret != exp_ret)
  5383. return WC_TEST_RET_ENC_I(i);
  5384. if (exp_ret == 0 && ret < 0)
  5385. return WC_TEST_RET_ENC_I(i);
  5386. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5387. ret = wc_HashGetOID(typesGood[i]);
  5388. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG) ||
  5389. (exp_ret == 0 && ret == WC_NO_ERR_TRACE(HASH_TYPE_E)) ||
  5390. (exp_ret != 0 && ret != WC_NO_ERR_TRACE(HASH_TYPE_E))) {
  5391. return WC_TEST_RET_ENC_I(i);
  5392. }
  5393. hashType = wc_OidGetHash(ret);
  5394. if (exp_ret == 0 && hashType != typesGood[i])
  5395. return WC_TEST_RET_ENC_I(i);
  5396. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5397. }
  5398. for (i = 0; i < (int)(sizeof(typesHashBad)/sizeof(*typesHashBad)); i++) {
  5399. ret = wc_Hash(typesHashBad[i], data, sizeof(data), out, sizeof(out));
  5400. if ((ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) &&
  5401. (ret != WC_NO_ERR_TRACE(BUFFER_E)) &&
  5402. (ret != WC_NO_ERR_TRACE(HASH_TYPE_E)))
  5403. {
  5404. return WC_TEST_RET_ENC_I(i);
  5405. }
  5406. }
  5407. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5408. ret = wc_HashGetOID(WC_HASH_TYPE_MD2);
  5409. #ifdef WOLFSSL_MD2
  5410. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5411. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5412. {
  5413. return WC_TEST_RET_ENC_EC(ret);
  5414. }
  5415. #else
  5416. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5417. return WC_TEST_RET_ENC_EC(ret);
  5418. #endif
  5419. hashType = wc_OidGetHash(646); /* Md2h */
  5420. #ifdef WOLFSSL_MD2
  5421. if (hashType != WC_HASH_TYPE_MD2)
  5422. return WC_TEST_RET_ENC_NC;
  5423. #else
  5424. if (hashType != WC_HASH_TYPE_NONE)
  5425. return WC_TEST_RET_ENC_NC;
  5426. #endif
  5427. ret = wc_HashGetOID(WC_HASH_TYPE_MD5_SHA);
  5428. #ifndef NO_MD5
  5429. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5430. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5431. {
  5432. return WC_TEST_RET_ENC_EC(ret);
  5433. }
  5434. #else
  5435. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5436. return WC_TEST_RET_ENC_EC(ret);
  5437. #endif
  5438. ret = wc_HashGetOID(WC_HASH_TYPE_MD4);
  5439. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5440. return WC_TEST_RET_ENC_EC(ret);
  5441. ret = wc_HashGetOID(WC_HASH_TYPE_NONE);
  5442. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5443. return WC_TEST_RET_ENC_EC(ret);
  5444. hashType = wc_OidGetHash(0);
  5445. if (hashType != WC_HASH_TYPE_NONE)
  5446. return WC_TEST_RET_ENC_NC;
  5447. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5448. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD2);
  5449. #ifdef WOLFSSL_MD2
  5450. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5451. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5452. {
  5453. return WC_TEST_RET_ENC_EC(ret);
  5454. }
  5455. #else
  5456. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5457. return WC_TEST_RET_ENC_EC(ret);
  5458. #endif
  5459. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD2);
  5460. #ifdef WOLFSSL_MD2
  5461. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5462. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5463. {
  5464. return WC_TEST_RET_ENC_EC(ret);
  5465. }
  5466. #else
  5467. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5468. return WC_TEST_RET_ENC_EC(ret);
  5469. #endif
  5470. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD4);
  5471. #ifndef NO_MD4
  5472. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5473. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5474. {
  5475. return WC_TEST_RET_ENC_EC(ret);
  5476. }
  5477. #else
  5478. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5479. return WC_TEST_RET_ENC_EC(ret);
  5480. #endif
  5481. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD4);
  5482. #ifndef NO_MD4
  5483. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5484. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5485. {
  5486. return WC_TEST_RET_ENC_EC(ret);
  5487. }
  5488. #else
  5489. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5490. return WC_TEST_RET_ENC_EC(ret);
  5491. #endif
  5492. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD5_SHA);
  5493. #if !defined(NO_MD5) && !defined(NO_SHA)
  5494. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5495. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5496. {
  5497. return WC_TEST_RET_ENC_EC(ret);
  5498. }
  5499. #else
  5500. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5501. return WC_TEST_RET_ENC_EC(ret);
  5502. #endif
  5503. ret = wc_HashGetBlockSize(WC_HASH_TYPE_BLAKE2B);
  5504. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5505. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5506. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5507. {
  5508. return WC_TEST_RET_ENC_EC(ret);
  5509. }
  5510. #else
  5511. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5512. return WC_TEST_RET_ENC_EC(ret);
  5513. #endif
  5514. ret = wc_HashGetDigestSize(WC_HASH_TYPE_BLAKE2B);
  5515. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5516. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5517. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5518. {
  5519. return WC_TEST_RET_ENC_EC(ret);
  5520. }
  5521. #else
  5522. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5523. return WC_TEST_RET_ENC_EC(ret);
  5524. #endif
  5525. ret = wc_HashGetBlockSize(WC_HASH_TYPE_NONE);
  5526. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5527. return WC_TEST_RET_ENC_EC(ret);
  5528. ret = wc_HashGetDigestSize(WC_HASH_TYPE_NONE);
  5529. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5530. return WC_TEST_RET_ENC_EC(ret);
  5531. #if !defined(NO_CERTS) && !defined(NO_ASN)
  5532. #if defined(WOLFSSL_MD2) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  5533. ret = wc_GetCTC_HashOID(MD2);
  5534. if (ret == 0)
  5535. return WC_TEST_RET_ENC_EC(ret);
  5536. #endif
  5537. #ifndef NO_MD5
  5538. ret = wc_GetCTC_HashOID(WC_MD5);
  5539. if (ret == 0)
  5540. return WC_TEST_RET_ENC_EC(ret);
  5541. #endif
  5542. #ifndef NO_SHA
  5543. ret = wc_GetCTC_HashOID(WC_SHA);
  5544. if (ret == 0)
  5545. return WC_TEST_RET_ENC_EC(ret);
  5546. #endif
  5547. #ifdef WOLFSSL_SHA224
  5548. ret = wc_GetCTC_HashOID(WC_SHA224);
  5549. if (ret == 0)
  5550. return WC_TEST_RET_ENC_EC(ret);
  5551. #endif
  5552. #ifndef NO_SHA256
  5553. ret = wc_GetCTC_HashOID(WC_SHA256);
  5554. if (ret == 0)
  5555. return WC_TEST_RET_ENC_EC(ret);
  5556. #endif
  5557. #ifdef WOLFSSL_SHA384
  5558. ret = wc_GetCTC_HashOID(WC_SHA384);
  5559. if (ret == 0)
  5560. return WC_TEST_RET_ENC_EC(ret);
  5561. #endif
  5562. #ifdef WOLFSSL_SHA512
  5563. ret = wc_GetCTC_HashOID(WC_SHA512);
  5564. if (ret == 0)
  5565. return WC_TEST_RET_ENC_EC(ret);
  5566. #endif
  5567. ret = wc_GetCTC_HashOID(-1);
  5568. if (ret != 0)
  5569. return WC_TEST_RET_ENC_EC(ret);
  5570. #endif
  5571. return 0;
  5572. }
  5573. #endif /* !NO_HASH_WRAPPER */
  5574. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS) && \
  5575. defined(HAVE_FIPS_VERSION) && \
  5576. (HAVE_FIPS_VERSION >= 5))
  5577. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void)
  5578. {
  5579. Hmac hmac;
  5580. byte hash[WC_MD5_DIGEST_SIZE];
  5581. const char* keys[]=
  5582. {
  5583. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  5584. "Jefe",
  5585. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA",
  5586. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5587. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5588. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5589. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5590. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5591. };
  5592. testVector a, b, c, d;
  5593. testVector test_hmac[4];
  5594. wc_test_ret_t ret;
  5595. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5596. WOLFSSL_ENTER("hmac_md5_test");
  5597. /* Following test vectors are from RFC 2202 section 2 */
  5598. a.input = "Hi There";
  5599. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  5600. "\x9d";
  5601. a.inLen = XSTRLEN(a.input);
  5602. a.outLen = WC_MD5_DIGEST_SIZE;
  5603. b.input = "what do ya want for nothing?";
  5604. b.output = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
  5605. "\x38";
  5606. b.inLen = XSTRLEN(b.input);
  5607. b.outLen = WC_MD5_DIGEST_SIZE;
  5608. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5609. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5610. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5611. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5612. c.output = "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
  5613. "\xf6";
  5614. c.inLen = XSTRLEN(c.input);
  5615. c.outLen = WC_MD5_DIGEST_SIZE;
  5616. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5617. d.output = "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0"
  5618. "\xcd";
  5619. d.inLen = XSTRLEN(d.input);
  5620. d.outLen = WC_MD5_DIGEST_SIZE;
  5621. test_hmac[0] = a;
  5622. test_hmac[1] = b;
  5623. test_hmac[2] = c;
  5624. test_hmac[3] = d;
  5625. for (i = 0; i < times; ++i) {
  5626. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5627. if (i == 1) {
  5628. continue; /* cavium can't handle short keys, fips not allowed */
  5629. }
  5630. #endif
  5631. ret = wc_HmacInit(&hmac, HEAP_HINT, devId);
  5632. if (ret != 0)
  5633. return WC_TEST_RET_ENC_EC(ret);
  5634. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i],
  5635. (word32)XSTRLEN(keys[i]));
  5636. if (ret != 0)
  5637. return WC_TEST_RET_ENC_EC(ret);
  5638. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5639. (word32)test_hmac[i].inLen);
  5640. if (ret != 0)
  5641. return WC_TEST_RET_ENC_EC(ret);
  5642. ret = wc_HmacFinal(&hmac, hash);
  5643. if (ret != 0)
  5644. return WC_TEST_RET_ENC_EC(ret);
  5645. if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0)
  5646. return WC_TEST_RET_ENC_I(i);
  5647. wc_HmacFree(&hmac);
  5648. }
  5649. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5650. if ((ret = wc_HmacSizeByType(WC_MD5)) != WC_MD5_DIGEST_SIZE)
  5651. return WC_TEST_RET_ENC_EC(ret);
  5652. #endif
  5653. return 0;
  5654. }
  5655. #endif /* !NO_HMAC && !NO_MD5 && (!HAVE_FIPS || (HAVE_FIPS_VERSION < 5)) */
  5656. #if !defined(NO_HMAC) && !defined(NO_SHA)
  5657. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void)
  5658. {
  5659. Hmac hmac;
  5660. byte hash[WC_SHA_DIGEST_SIZE];
  5661. const char* keys[]=
  5662. {
  5663. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5664. "\x0b\x0b\x0b",
  5665. "Jefe",
  5666. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5667. "\xAA\xAA\xAA",
  5668. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5669. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5670. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5671. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5672. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5673. };
  5674. testVector a, b, c, d;
  5675. testVector test_hmac[4];
  5676. wc_test_ret_t ret;
  5677. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5678. WOLFSSL_ENTER("hmac_sha_test");
  5679. /* Following test vectors are from RFC 2202 section 3 */
  5680. a.input = "Hi There";
  5681. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  5682. "\x8e\xf1\x46\xbe\x00";
  5683. a.inLen = XSTRLEN(a.input);
  5684. a.outLen = WC_SHA_DIGEST_SIZE;
  5685. b.input = "what do ya want for nothing?";
  5686. b.output = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf"
  5687. "\x9c\x25\x9a\x7c\x79";
  5688. b.inLen = XSTRLEN(b.input);
  5689. b.outLen = WC_SHA_DIGEST_SIZE;
  5690. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5691. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5692. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5693. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5694. c.output = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b"
  5695. "\x4f\x63\xf1\x75\xd3";
  5696. c.inLen = XSTRLEN(c.input);
  5697. c.outLen = WC_SHA_DIGEST_SIZE;
  5698. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5699. d.output = "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b"
  5700. "\x55\xed\x40\x21\x12";
  5701. d.inLen = XSTRLEN(d.input);
  5702. d.outLen = WC_SHA_DIGEST_SIZE;
  5703. test_hmac[0] = a;
  5704. test_hmac[1] = b;
  5705. test_hmac[2] = c;
  5706. test_hmac[3] = d;
  5707. #if FIPS_VERSION3_GE(6,0,0)
  5708. int allowShortKeyWithFips = 1;
  5709. #endif
  5710. for (i = 0; i < times; ++i) {
  5711. #if defined(HAVE_CAVIUM) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0))
  5712. if (i == 1)
  5713. continue; /* cavium can't handle short keys, fips not allowed */
  5714. #endif
  5715. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5716. return WC_TEST_RET_ENC_EC(ret);
  5717. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i],
  5718. (word32)XSTRLEN(keys[i]));
  5719. #if FIPS_VERSION3_GE(6,0,0)
  5720. if (i == 1) {
  5721. if (ret != WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E))
  5722. return WC_TEST_RET_ENC_EC(ret);
  5723. /* Now use the ex and allow short keys with FIPS option */
  5724. ret = wc_HmacSetKey_ex(&hmac, WC_SHA, (byte*) keys[i],
  5725. (word32)XSTRLEN(keys[i]), allowShortKeyWithFips);
  5726. }
  5727. #endif
  5728. if (ret != 0)
  5729. return WC_TEST_RET_ENC_EC(ret);
  5730. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5731. (word32)test_hmac[i].inLen);
  5732. if (ret != 0)
  5733. return WC_TEST_RET_ENC_EC(ret);
  5734. ret = wc_HmacFinal(&hmac, hash);
  5735. if (ret != 0)
  5736. return WC_TEST_RET_ENC_EC(ret);
  5737. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0)
  5738. return WC_TEST_RET_ENC_I(i);
  5739. wc_HmacFree(&hmac);
  5740. }
  5741. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5742. if ((ret = wc_HmacSizeByType(WC_SHA)) != WC_SHA_DIGEST_SIZE)
  5743. return WC_TEST_RET_ENC_EC(ret);
  5744. #endif
  5745. return 0;
  5746. }
  5747. #endif
  5748. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  5749. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void)
  5750. {
  5751. Hmac hmac;
  5752. byte hash[WC_SHA224_DIGEST_SIZE];
  5753. const char* keys[]=
  5754. {
  5755. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5756. "\x0b\x0b\x0b",
  5757. "Jefe",
  5758. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5759. "\xAA\xAA\xAA",
  5760. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5761. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5762. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5763. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5764. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5765. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5766. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5767. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5768. "\xAA\xAA\xAA"
  5769. };
  5770. testVector a, b, c, d;
  5771. testVector test_hmac[4];
  5772. wc_test_ret_t ret;
  5773. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5774. WOLFSSL_ENTER("hmac_sha224_test");
  5775. /* Following test vectors are from RFC 4231 section 4 */
  5776. a.input = "Hi There";
  5777. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  5778. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  5779. a.inLen = XSTRLEN(a.input);
  5780. a.outLen = WC_SHA224_DIGEST_SIZE;
  5781. b.input = "what do ya want for nothing?";
  5782. b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
  5783. "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
  5784. b.inLen = XSTRLEN(b.input);
  5785. b.outLen = WC_SHA224_DIGEST_SIZE;
  5786. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5787. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5788. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5789. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5790. c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
  5791. "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
  5792. c.inLen = XSTRLEN(c.input);
  5793. c.outLen = WC_SHA224_DIGEST_SIZE;
  5794. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5795. d.output = "\x95\xe9\xa0\xdb\x96\x20\x95\xad\xae\xbe\x9b\x2d\x6f\x0d\xbc\xe2\xd4\x99\xf1\x12\xf2\xd2\xb7\x27\x3f\xa6\x87\x0e";
  5796. d.inLen = XSTRLEN(d.input);
  5797. d.outLen = WC_SHA224_DIGEST_SIZE;
  5798. test_hmac[0] = a;
  5799. test_hmac[1] = b;
  5800. test_hmac[2] = c;
  5801. test_hmac[3] = d;
  5802. for (i = 0; i < times; ++i) {
  5803. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5804. if (i == 1)
  5805. continue; /* cavium can't handle short keys, fips not allowed */
  5806. #endif
  5807. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5808. return WC_TEST_RET_ENC_EC(ret);
  5809. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i],
  5810. (word32)XSTRLEN(keys[i]));
  5811. if (ret != 0)
  5812. return WC_TEST_RET_ENC_EC(ret);
  5813. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5814. (word32)test_hmac[i].inLen);
  5815. if (ret != 0)
  5816. return WC_TEST_RET_ENC_EC(ret);
  5817. ret = wc_HmacFinal(&hmac, hash);
  5818. if (ret != 0)
  5819. return WC_TEST_RET_ENC_EC(ret);
  5820. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  5821. return WC_TEST_RET_ENC_I(i);
  5822. wc_HmacFree(&hmac);
  5823. }
  5824. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5825. if ((ret = wc_HmacSizeByType(WC_SHA224)) != WC_SHA224_DIGEST_SIZE)
  5826. return WC_TEST_RET_ENC_EC(ret);
  5827. #endif
  5828. return 0;
  5829. }
  5830. #endif
  5831. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  5832. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void)
  5833. {
  5834. Hmac hmac;
  5835. byte hash[WC_SHA256_DIGEST_SIZE];
  5836. const char* keys[]=
  5837. {
  5838. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5839. "\x0b\x0b\x0b",
  5840. "Jefe",
  5841. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5842. "\xAA\xAA\xAA",
  5843. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5844. "\xAA\xAA\xAA",
  5845. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5846. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5847. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5848. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5849. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5850. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5851. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5852. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5853. "\xAA\xAA\xAA"
  5854. };
  5855. testVector a, b, c, d, e;
  5856. testVector test_hmac[5];
  5857. wc_test_ret_t ret;
  5858. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5859. WOLFSSL_ENTER("hmac_sha256_test");
  5860. /* Following test vectors are from RFC 4231 section 4 */
  5861. a.input = "Hi There";
  5862. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  5863. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  5864. "\xcf\xf7";
  5865. a.inLen = XSTRLEN(a.input);
  5866. a.outLen = WC_SHA256_DIGEST_SIZE;
  5867. b.input = "what do ya want for nothing?";
  5868. b.output = "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75"
  5869. "\xc7\x5a\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec"
  5870. "\x38\x43";
  5871. b.inLen = XSTRLEN(b.input);
  5872. b.outLen = WC_SHA256_DIGEST_SIZE;
  5873. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5874. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5875. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5876. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5877. c.output = "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81"
  5878. "\xa7\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5"
  5879. "\x65\xfe";
  5880. c.inLen = XSTRLEN(c.input);
  5881. c.outLen = WC_SHA256_DIGEST_SIZE;
  5882. d.input = 0;
  5883. d.output = "\x86\xe5\x4f\xd4\x48\x72\x5d\x7e\x5d\xcf\xe2\x23\x53\xc8\x28"
  5884. "\xaf\x48\x78\x1e\xb4\x8c\xae\x81\x06\xa7\xe1\xd4\x98\x94\x9f"
  5885. "\x3e\x46";
  5886. d.inLen = 0;
  5887. d.outLen = WC_SHA256_DIGEST_SIZE;
  5888. e.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5889. e.output = "\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7"
  5890. "\x7f\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3"
  5891. "\x7f\x54";
  5892. e.inLen = XSTRLEN(e.input);;
  5893. e.outLen = WC_SHA256_DIGEST_SIZE;
  5894. test_hmac[0] = a;
  5895. test_hmac[1] = b;
  5896. test_hmac[2] = c;
  5897. test_hmac[3] = d;
  5898. test_hmac[4] = e;
  5899. for (i = 0; i < times; ++i) {
  5900. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5901. if (i == 1)
  5902. continue; /* cavium can't handle short keys, fips not allowed */
  5903. #endif
  5904. #if defined(HAVE_INTEL_QA) || defined(HAVE_CAVIUM)
  5905. if (i == 3)
  5906. continue; /* QuickAssist can't handle empty HMAC */
  5907. #endif
  5908. if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0)
  5909. return WC_TEST_RET_ENC_I(i);
  5910. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i],
  5911. (word32)XSTRLEN(keys[i]));
  5912. if (ret != 0)
  5913. return WC_TEST_RET_ENC_I(i);
  5914. if (test_hmac[i].input != NULL) {
  5915. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5916. (word32)test_hmac[i].inLen);
  5917. if (ret != 0)
  5918. return WC_TEST_RET_ENC_I(i);
  5919. }
  5920. ret = wc_HmacFinal(&hmac, hash);
  5921. if (ret != 0)
  5922. return WC_TEST_RET_ENC_I(i);
  5923. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0)
  5924. return WC_TEST_RET_ENC_I(i);
  5925. wc_HmacFree(&hmac);
  5926. }
  5927. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5928. if ((ret = wc_HmacSizeByType(WC_SHA256)) != WC_SHA256_DIGEST_SIZE)
  5929. return WC_TEST_RET_ENC_EC(ret);
  5930. #if FIPS_VERSION3_GE(6,0,0)
  5931. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(HMAC_KAT_FIPS_E))
  5932. #else
  5933. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5934. #endif
  5935. {
  5936. return WC_TEST_RET_ENC_EC(ret);
  5937. }
  5938. #endif
  5939. if ((ret = wolfSSL_GetHmacMaxSize()) != WC_MAX_DIGEST_SIZE)
  5940. return WC_TEST_RET_ENC_EC(ret);
  5941. return 0;
  5942. }
  5943. #endif
  5944. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  5945. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void)
  5946. {
  5947. Hmac hmac;
  5948. byte hash[WC_SHA384_DIGEST_SIZE];
  5949. const char* keys[]=
  5950. {
  5951. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5952. "\x0b\x0b\x0b",
  5953. "Jefe",
  5954. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5955. "\xAA\xAA\xAA",
  5956. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5957. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5958. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5959. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5960. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5961. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5962. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5963. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5964. "\xAA\xAA\xAA"
  5965. };
  5966. testVector a, b, c, d;
  5967. testVector test_hmac[4];
  5968. wc_test_ret_t ret;
  5969. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5970. WOLFSSL_ENTER("hmac_sha384_test");
  5971. /* Following test vectors are from RFC 4231 section 4 */
  5972. a.input = "Hi There";
  5973. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  5974. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  5975. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  5976. "\xfa\x9c\xb6";
  5977. a.inLen = XSTRLEN(a.input);
  5978. a.outLen = WC_SHA384_DIGEST_SIZE;
  5979. b.input = "what do ya want for nothing?";
  5980. b.output = "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b"
  5981. "\x1b\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22"
  5982. "\x44\x5e\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa"
  5983. "\xb2\x16\x49";
  5984. b.inLen = XSTRLEN(b.input);
  5985. b.outLen = WC_SHA384_DIGEST_SIZE;
  5986. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5987. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5988. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5989. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5990. c.output = "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8"
  5991. "\x6f\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66"
  5992. "\x14\x4b\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01"
  5993. "\xa3\x4f\x27";
  5994. c.inLen = XSTRLEN(c.input);
  5995. c.outLen = WC_SHA384_DIGEST_SIZE;
  5996. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5997. d.output = "\x4e\xce\x08\x44\x85\x81\x3e\x90\x88\xd2\xc6\x3a\x04\x1b\xc5"
  5998. "\xb4\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f\x3c\xd1\x1f\x05\x03\x3a"
  5999. "\xc4\xc6\x0c\x2e\xf6\xab\x40\x30\xfe\x82\x96\x24\x8d\xf1\x63"
  6000. "\xf4\x49\x52";
  6001. d.inLen = XSTRLEN(d.input);
  6002. d.outLen = WC_SHA384_DIGEST_SIZE;
  6003. test_hmac[0] = a;
  6004. test_hmac[1] = b;
  6005. test_hmac[2] = c;
  6006. test_hmac[3] = d;
  6007. for (i = 0; i < times; ++i) {
  6008. #if defined(HAVE_FIPS)
  6009. if (i == 1)
  6010. continue; /* fips not allowed */
  6011. #endif
  6012. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6013. return WC_TEST_RET_ENC_EC(ret);
  6014. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i],
  6015. (word32)XSTRLEN(keys[i]));
  6016. if (ret != 0)
  6017. return WC_TEST_RET_ENC_EC(ret);
  6018. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6019. (word32)test_hmac[i].inLen);
  6020. if (ret != 0)
  6021. return WC_TEST_RET_ENC_EC(ret);
  6022. ret = wc_HmacFinal(&hmac, hash);
  6023. if (ret != 0)
  6024. return WC_TEST_RET_ENC_EC(ret);
  6025. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  6026. return WC_TEST_RET_ENC_I(i);
  6027. wc_HmacFree(&hmac);
  6028. }
  6029. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6030. if ((ret = wc_HmacSizeByType(WC_SHA384)) != WC_SHA384_DIGEST_SIZE)
  6031. return WC_TEST_RET_ENC_EC(ret);
  6032. #endif
  6033. return 0;
  6034. }
  6035. #endif
  6036. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA512)
  6037. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void)
  6038. {
  6039. Hmac hmac;
  6040. byte hash[WC_SHA512_DIGEST_SIZE];
  6041. const char* keys[]=
  6042. {
  6043. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6044. "\x0b\x0b\x0b",
  6045. "Jefe",
  6046. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6047. "\xAA\xAA\xAA",
  6048. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6049. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6050. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6051. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6052. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6053. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6054. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6055. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6056. "\xAA\xAA\xAA"
  6057. };
  6058. testVector a, b, c, d;
  6059. testVector test_hmac[4];
  6060. wc_test_ret_t ret;
  6061. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6062. WOLFSSL_ENTER("hmac_sha512_test");
  6063. /* Following test vectors are from RFC 4231 section 4 */
  6064. a.input = "Hi There";
  6065. a.output = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c"
  6066. "\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1"
  6067. "\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae"
  6068. "\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20"
  6069. "\x3a\x12\x68\x54";
  6070. a.inLen = XSTRLEN(a.input);
  6071. a.outLen = WC_SHA512_DIGEST_SIZE;
  6072. b.input = "what do ya want for nothing?";
  6073. b.output = "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2\xe3\x95\xfb\xe7\x3b\x56\xe0"
  6074. "\xa3\x87\xbd\x64\x22\x2e\x83\x1f\xd6\x10\x27\x0c\xd7\xea\x25"
  6075. "\x05\x54\x97\x58\xbf\x75\xc0\x5a\x99\x4a\x6d\x03\x4f\x65\xf8"
  6076. "\xf0\xe6\xfd\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b\x63\x6e\x07\x0a"
  6077. "\x38\xbc\xe7\x37";
  6078. b.inLen = XSTRLEN(b.input);
  6079. b.outLen = WC_SHA512_DIGEST_SIZE;
  6080. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6081. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6082. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6083. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6084. c.output = "\xfa\x73\xb0\x08\x9d\x56\xa2\x84\xef\xb0\xf0\x75\x6c\x89\x0b"
  6085. "\xe9\xb1\xb5\xdb\xdd\x8e\xe8\x1a\x36\x55\xf8\x3e\x33\xb2\x27"
  6086. "\x9d\x39\xbf\x3e\x84\x82\x79\xa7\x22\xc8\x06\xb4\x85\xa4\x7e"
  6087. "\x67\xc8\x07\xb9\x46\xa3\x37\xbe\xe8\x94\x26\x74\x27\x88\x59"
  6088. "\xe1\x32\x92\xfb";
  6089. c.inLen = XSTRLEN(c.input);
  6090. c.outLen = WC_SHA512_DIGEST_SIZE;
  6091. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6092. d.output = "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb\xb7\x14\x93\xc1\xdd\x7b\xe8"
  6093. "\xb4\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1\x12\x1b\x01\x37\x83\xf8"
  6094. "\xf3\x52\x6b\x56\xd0\x37\xe0\x5f\x25\x98\xbd\x0f\xd2\x21\x5d"
  6095. "\x6a\x1e\x52\x95\xe6\x4f\x73\xf6\x3f\x0a\xec\x8b\x91\x5a\x98"
  6096. "\x5d\x78\x65\x98";
  6097. d.inLen = XSTRLEN(d.input);
  6098. d.outLen = WC_SHA512_DIGEST_SIZE;
  6099. test_hmac[0] = a;
  6100. test_hmac[1] = b;
  6101. test_hmac[2] = c;
  6102. test_hmac[3] = d;
  6103. for (i = 0; i < times; ++i) {
  6104. #if defined(HAVE_FIPS)
  6105. if (i == 1)
  6106. continue; /* fips not allowed */
  6107. #endif
  6108. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6109. return WC_TEST_RET_ENC_EC(ret);
  6110. ret = wc_HmacSetKey(&hmac, WC_SHA512, (byte*)keys[i],
  6111. (word32)XSTRLEN(keys[i]));
  6112. if (ret != 0)
  6113. return WC_TEST_RET_ENC_EC(ret);
  6114. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6115. (word32)test_hmac[i].inLen);
  6116. if (ret != 0)
  6117. return WC_TEST_RET_ENC_EC(ret);
  6118. ret = wc_HmacFinal(&hmac, hash);
  6119. if (ret != 0)
  6120. return WC_TEST_RET_ENC_EC(ret);
  6121. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  6122. return WC_TEST_RET_ENC_I(i);
  6123. wc_HmacFree(&hmac);
  6124. }
  6125. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6126. if ((ret = wc_HmacSizeByType(WC_SHA512)) != WC_SHA512_DIGEST_SIZE)
  6127. return WC_TEST_RET_ENC_EC(ret);
  6128. #endif
  6129. return 0;
  6130. }
  6131. #endif
  6132. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  6133. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  6134. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  6135. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void)
  6136. {
  6137. Hmac hmac;
  6138. byte hash[WC_SHA3_512_DIGEST_SIZE];
  6139. const char* key[4] =
  6140. {
  6141. "Jefe",
  6142. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6143. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  6144. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
  6145. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
  6146. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6147. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6148. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6149. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6150. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6151. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6152. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6153. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6154. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6155. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6156. };
  6157. const char* input[4] =
  6158. {
  6159. "what do ya want for nothing?",
  6160. "Hi There",
  6161. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6162. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6163. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6164. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6165. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
  6166. "Big Key Input"
  6167. };
  6168. const int hashType[4] =
  6169. {
  6170. WC_SHA3_224, WC_SHA3_256, WC_SHA3_384, WC_SHA3_512
  6171. };
  6172. const int hashSz[4] =
  6173. {
  6174. WC_SHA3_224_DIGEST_SIZE, WC_SHA3_256_DIGEST_SIZE,
  6175. WC_SHA3_384_DIGEST_SIZE, WC_SHA3_512_DIGEST_SIZE
  6176. };
  6177. const char* output[16] =
  6178. {
  6179. /* key = jefe, input = what do ya want for nothing? */
  6180. /* HMAC-SHA3-224 */
  6181. "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11"
  6182. "\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66",
  6183. /* HMAC-SHA3-256 */
  6184. "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87"
  6185. "\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5",
  6186. /* HMAC-SHA3-384 */
  6187. "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21"
  6188. "\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce"
  6189. "\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a",
  6190. /* HMAC-SHA3-512 */
  6191. "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83"
  6192. "\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b"
  6193. "\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e"
  6194. "\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24",
  6195. /* key = 0b..., input = Hi There */
  6196. /* HMAC-SHA3-224 */
  6197. "\x3b\x16\x54\x6b\xbc\x7b\xe2\x70\x6a\x03\x1d\xca\xfd\x56\x37\x3d"
  6198. "\x98\x84\x36\x76\x41\xd8\xc5\x9a\xf3\xc8\x60\xf7",
  6199. /* HMAC-SHA3-256 */
  6200. "\xba\x85\x19\x23\x10\xdf\xfa\x96\xe2\xa3\xa4\x0e\x69\x77\x43\x51"
  6201. "\x14\x0b\xb7\x18\x5e\x12\x02\xcd\xcc\x91\x75\x89\xf9\x5e\x16\xbb",
  6202. /* HMAC-SHA3-384 */
  6203. "\x68\xd2\xdc\xf7\xfd\x4d\xdd\x0a\x22\x40\xc8\xa4\x37\x30\x5f\x61"
  6204. "\xfb\x73\x34\xcf\xb5\xd0\x22\x6e\x1b\xc2\x7d\xc1\x0a\x2e\x72\x3a"
  6205. "\x20\xd3\x70\xb4\x77\x43\x13\x0e\x26\xac\x7e\x3d\x53\x28\x86\xbd",
  6206. /* HMAC-SHA3-512 */
  6207. "\xeb\x3f\xbd\x4b\x2e\xaa\xb8\xf5\xc5\x04\xbd\x3a\x41\x46\x5a\xac"
  6208. "\xec\x15\x77\x0a\x7c\xab\xac\x53\x1e\x48\x2f\x86\x0b\x5e\xc7\xba"
  6209. "\x47\xcc\xb2\xc6\xf2\xaf\xce\x8f\x88\xd2\x2b\x6d\xc6\x13\x80\xf2"
  6210. "\x3a\x66\x8f\xd3\x88\x8b\xb8\x05\x37\xc0\xa0\xb8\x64\x07\x68\x9e",
  6211. /* key = aa..., output = dd... */
  6212. /* HMAC-SHA3-224 */
  6213. "\x67\x6c\xfc\x7d\x16\x15\x36\x38\x78\x03\x90\x69\x2b\xe1\x42\xd2"
  6214. "\xdf\x7c\xe9\x24\xb9\x09\xc0\xc0\x8d\xbf\xdc\x1a",
  6215. /* HMAC-SHA3-256 */
  6216. "\x84\xec\x79\x12\x4a\x27\x10\x78\x65\xce\xdd\x8b\xd8\x2d\xa9\x96"
  6217. "\x5e\x5e\xd8\xc3\x7b\x0a\xc9\x80\x05\xa7\xf3\x9e\xd5\x8a\x42\x07",
  6218. /* HMAC-SHA3-384 */
  6219. "\x27\x5c\xd0\xe6\x61\xbb\x8b\x15\x1c\x64\xd2\x88\xf1\xf7\x82\xfb"
  6220. "\x91\xa8\xab\xd5\x68\x58\xd7\x2b\xab\xb2\xd4\x76\xf0\x45\x83\x73"
  6221. "\xb4\x1b\x6a\xb5\xbf\x17\x4b\xec\x42\x2e\x53\xfc\x31\x35\xac\x6e",
  6222. /* HMAC-SHA3-512 */
  6223. "\x30\x9e\x99\xf9\xec\x07\x5e\xc6\xc6\xd4\x75\xed\xa1\x18\x06\x87"
  6224. "\xfc\xf1\x53\x11\x95\x80\x2a\x99\xb5\x67\x74\x49\xa8\x62\x51\x82"
  6225. "\x85\x1c\xb3\x32\xaf\xb6\xa8\x9c\x41\x13\x25\xfb\xcb\xcd\x42\xaf"
  6226. "\xcb\x7b\x6e\x5a\xab\x7e\xa4\x2c\x66\x0f\x97\xfd\x85\x84\xbf\x03",
  6227. /* key = big key, input = Big Key Input */
  6228. /* HMAC-SHA3-224 */
  6229. "\x29\xe0\x5e\x46\xc4\xa4\x5e\x46\x74\xbf\xd7\x2d\x1a\xd8\x66\xdb"
  6230. "\x2d\x0d\x10\x4e\x2b\xfa\xad\x53\x7d\x15\x69\x8b",
  6231. /* HMAC-SHA3-256 */
  6232. "\xb5\x5b\x8d\x64\xb6\x9c\x21\xd0\xbf\x20\x5c\xa2\xf7\xb9\xb1\x4e"
  6233. "\x88\x21\x61\x2c\x66\xc3\x91\xae\x6c\x95\x16\x85\x83\xe6\xf4\x9b",
  6234. /* HMAC-SHA3-384 */
  6235. "\xaa\x91\xb3\xa6\x2f\x56\xa1\xbe\x8c\x3e\x74\x38\xdb\x58\xd9\xd3"
  6236. "\x34\xde\xa0\x60\x6d\x8d\x46\xe0\xec\xa9\xf6\x06\x35\x14\xe6\xed"
  6237. "\x83\xe6\x7c\x77\x24\x6c\x11\xb5\x90\x82\xb5\x75\xda\x7b\x83\x2d",
  6238. /* HMAC-SHA3-512 */
  6239. "\x1c\xc3\xa9\x24\x4a\x4a\x3f\xbd\xc7\x20\x00\x16\x9b\x79\x47\x03"
  6240. "\x78\x75\x2c\xb5\xf1\x2e\x62\x7c\xbe\xef\x4e\x8f\x0b\x11\x2b\x32"
  6241. "\xa0\xee\xc9\xd0\x4d\x64\x64\x0b\x37\xf4\xdd\x66\xf7\x8b\xb3\xad"
  6242. "\x52\x52\x6b\x65\x12\xde\x0d\x7c\xc0\x8b\x60\x01\x6c\x37\xd7\xa8"
  6243. };
  6244. int i = 0, iMax = sizeof(input) / sizeof(input[0]),
  6245. j, jMax = sizeof(hashType) / sizeof(hashType[0]);
  6246. int ret;
  6247. WOLFSSL_ENTER("hmac_sha3_test");
  6248. #ifdef HAVE_FIPS
  6249. /* FIPS requires a minimum length for HMAC keys, and "Jefe" is too
  6250. * short. Skip it in FIPS builds. */
  6251. i = 1;
  6252. #endif
  6253. for (; i < iMax; i++) {
  6254. for (j = 0; j < jMax; j++) {
  6255. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6256. return WC_TEST_RET_ENC_EC(ret);
  6257. ret = wc_HmacSetKey(&hmac, hashType[j], (byte*)key[i],
  6258. (word32)XSTRLEN(key[i]));
  6259. if (ret != 0)
  6260. return WC_TEST_RET_ENC_EC(ret);
  6261. ret = wc_HmacUpdate(&hmac, (byte*)input[i],
  6262. (word32)XSTRLEN(input[i]));
  6263. if (ret != 0)
  6264. return WC_TEST_RET_ENC_EC(ret);
  6265. ret = wc_HmacFinal(&hmac, hash);
  6266. if (ret != 0)
  6267. return WC_TEST_RET_ENC_EC(ret);
  6268. if (XMEMCMP(hash, output[(i*jMax) + j], (size_t)hashSz[j]) != 0)
  6269. return WC_TEST_RET_ENC_NC;
  6270. wc_HmacFree(&hmac);
  6271. if (i > 0)
  6272. continue;
  6273. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6274. ret = wc_HmacSizeByType(hashType[j]);
  6275. if (ret != hashSz[j])
  6276. return WC_TEST_RET_ENC_EC(ret);
  6277. #endif
  6278. }
  6279. }
  6280. return 0;
  6281. }
  6282. #endif
  6283. #ifdef WC_RC2
  6284. typedef struct rc2TestVector {
  6285. const char* input;
  6286. const char* output;
  6287. const char* key; /* Key, variable up to 128 bytes */
  6288. const char* iv; /* IV, 8-bytes */
  6289. int inLen;
  6290. int outLen;
  6291. int keyLen;
  6292. int effectiveKeyBits; /* Up to 1024 bits supported */
  6293. } rc2TestVector;
  6294. static wc_test_ret_t rc2_ecb_test(void)
  6295. {
  6296. wc_test_ret_t ret = 0;
  6297. byte cipher[RC2_BLOCK_SIZE];
  6298. byte plain[RC2_BLOCK_SIZE];
  6299. rc2TestVector a, b, c, d, e, f, g, h;
  6300. rc2TestVector test_rc2[8];
  6301. int times = sizeof(test_rc2) / sizeof(rc2TestVector), i;
  6302. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6303. a.output = "\xeb\xb7\x73\xf9\x93\x27\x8e\xff";
  6304. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6305. a.inLen = RC2_BLOCK_SIZE;
  6306. a.outLen = RC2_BLOCK_SIZE;
  6307. a.keyLen = 8;
  6308. a.effectiveKeyBits = 63;
  6309. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6310. b.output = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49";
  6311. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6312. b.inLen = RC2_BLOCK_SIZE;
  6313. b.outLen = RC2_BLOCK_SIZE;
  6314. b.keyLen = 8;
  6315. b.effectiveKeyBits = 64;
  6316. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01";
  6317. c.output = "\x30\x64\x9e\xdf\x9b\xe7\xd2\xc2";
  6318. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6319. c.inLen = RC2_BLOCK_SIZE;
  6320. c.outLen = RC2_BLOCK_SIZE;
  6321. c.keyLen = 8;
  6322. c.effectiveKeyBits = 64;
  6323. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6324. d.output = "\x61\xa8\xa2\x44\xad\xac\xcc\xf0";
  6325. d.key = "\x88";
  6326. d.inLen = RC2_BLOCK_SIZE;
  6327. d.outLen = RC2_BLOCK_SIZE;
  6328. d.keyLen = 1;
  6329. d.effectiveKeyBits = 64;
  6330. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6331. e.output = "\x6c\xcf\x43\x08\x97\x4c\x26\x7f";
  6332. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6333. e.inLen = RC2_BLOCK_SIZE;
  6334. e.outLen = RC2_BLOCK_SIZE;
  6335. e.keyLen = 7;
  6336. e.effectiveKeyBits = 64;
  6337. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6338. f.output = "\x1a\x80\x7d\x27\x2b\xbe\x5d\xb1";
  6339. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6340. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6341. f.inLen = RC2_BLOCK_SIZE;
  6342. f.outLen = RC2_BLOCK_SIZE;
  6343. f.keyLen = 16;
  6344. f.effectiveKeyBits = 64;
  6345. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6346. g.output = "\x22\x69\x55\x2a\xb0\xf8\x5c\xa6";
  6347. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6348. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6349. g.inLen = RC2_BLOCK_SIZE;
  6350. g.outLen = RC2_BLOCK_SIZE;
  6351. g.keyLen = 16;
  6352. g.effectiveKeyBits = 128;
  6353. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6354. h.output = "\x5b\x78\xd3\xa4\x3d\xff\xf1\xf1";
  6355. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6356. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6357. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6358. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6359. "\x1e";
  6360. h.inLen = RC2_BLOCK_SIZE;
  6361. h.outLen = RC2_BLOCK_SIZE;
  6362. h.keyLen = 33;
  6363. h.effectiveKeyBits = 129;
  6364. a.iv = b.iv = c.iv = d.iv = e.iv = f.iv = g.iv = h.iv = NULL;
  6365. test_rc2[0] = a;
  6366. test_rc2[1] = b;
  6367. test_rc2[2] = c;
  6368. test_rc2[3] = d;
  6369. test_rc2[4] = e;
  6370. test_rc2[5] = f;
  6371. test_rc2[6] = g;
  6372. test_rc2[7] = h;
  6373. for (i = 0; i < times; ++i) {
  6374. Rc2 enc;
  6375. XMEMSET(cipher, 0, RC2_BLOCK_SIZE);
  6376. XMEMSET(plain, 0, RC2_BLOCK_SIZE);
  6377. ret = wc_Rc2SetKey(&enc, (byte*)test_rc2[i].key, test_rc2[i].keyLen,
  6378. NULL, test_rc2[i].effectiveKeyBits);
  6379. if (ret != 0) {
  6380. return WC_TEST_RET_ENC_EC(ret);
  6381. }
  6382. /* ECB encrypt */
  6383. ret = wc_Rc2EcbEncrypt(&enc, cipher, (byte*)test_rc2[i].input,
  6384. (word32)test_rc2[i].outLen);
  6385. if (ret != 0) {
  6386. return WC_TEST_RET_ENC_EC(ret);
  6387. }
  6388. if (XMEMCMP(cipher, test_rc2[i].output, test_rc2[i].outLen)) {
  6389. return WC_TEST_RET_ENC_NC;
  6390. }
  6391. /* ECB decrypt */
  6392. ret = wc_Rc2EcbDecrypt(&enc, plain, cipher, RC2_BLOCK_SIZE);
  6393. if (ret != 0) {
  6394. return WC_TEST_RET_ENC_EC(ret);
  6395. }
  6396. if (XMEMCMP(plain, test_rc2[i].input, RC2_BLOCK_SIZE)) {
  6397. return WC_TEST_RET_ENC_NC;
  6398. }
  6399. }
  6400. return 0;
  6401. }
  6402. static wc_test_ret_t rc2_cbc_test(void)
  6403. {
  6404. wc_test_ret_t ret = 0;
  6405. byte cipher[128];
  6406. byte plain[128];
  6407. rc2TestVector a, b, c, d, e, f, g, h, i;
  6408. rc2TestVector test_rc2[9];
  6409. int times = sizeof(test_rc2) / sizeof(rc2TestVector), j;
  6410. /* key length = 7, effective key bits = 63 */
  6411. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6412. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6413. a.output = "\xEB\xB7\x73\xF9\x93\x27\x8E\xFF"
  6414. "\xF0\x51\x77\x8B\x65\xDB\x13\x57";
  6415. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6416. a.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6417. a.inLen = RC2_BLOCK_SIZE*2;
  6418. a.outLen = RC2_BLOCK_SIZE*2;
  6419. a.keyLen = 8;
  6420. a.effectiveKeyBits = 63;
  6421. /* key length = 8, effective key bits = 64, all 0xFF */
  6422. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff"
  6423. "\xff\xff\xff\xff\xff\xff\xff\xff";
  6424. b.output = "\xA3\xA1\x12\x65\x4F\x81\xC5\xCD"
  6425. "\xB6\x94\x3E\xEA\x3E\x8B\x9D\x1F";
  6426. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6427. b.iv = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6428. b.inLen = RC2_BLOCK_SIZE*2;
  6429. b.outLen = RC2_BLOCK_SIZE*2;
  6430. b.keyLen = 8;
  6431. b.effectiveKeyBits = 64;
  6432. /* key length = 8, effective key bits = 64 */
  6433. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01"
  6434. "\x10\x00\x00\x00\x00\x00\x00\x01";
  6435. c.output = "\xB5\x70\x14\xA2\x5F\x40\xE3\x6D"
  6436. "\x81\x99\x8D\xE0\xB5\xD5\x3A\x05";
  6437. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6438. c.iv = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6439. c.inLen = RC2_BLOCK_SIZE*2;
  6440. c.outLen = RC2_BLOCK_SIZE*2;
  6441. c.keyLen = 8;
  6442. c.effectiveKeyBits = 64;
  6443. /* key length = 1, effective key bits = 64 */
  6444. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6445. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6446. d.output = "\x61\xA8\xA2\x44\xAD\xAC\xCC\xF0"
  6447. "\x6D\x19\xE8\xF1\xFC\xE7\x38\x87";
  6448. d.key = "\x88";
  6449. d.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6450. d.inLen = RC2_BLOCK_SIZE*2;
  6451. d.outLen = RC2_BLOCK_SIZE*2;
  6452. d.keyLen = 1;
  6453. d.effectiveKeyBits = 64;
  6454. /* key length = 7, effective key bits = 64 */
  6455. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6456. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6457. e.output = "\x6C\xCF\x43\x08\x97\x4C\x26\x7F"
  6458. "\xCC\x3C\x53\x57\x7C\xA1\xA4\x4B";
  6459. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6460. e.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6461. e.inLen = RC2_BLOCK_SIZE*2;
  6462. e.outLen = RC2_BLOCK_SIZE*2;
  6463. e.keyLen = 7;
  6464. e.effectiveKeyBits = 64;
  6465. /* key length = 16, effective key bits = 64 */
  6466. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6467. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6468. f.output = "\x1A\x80\x7D\x27\x2B\xBE\x5D\xB1"
  6469. "\x64\xEF\xE1\xC3\xB8\xAD\xFB\xBA";
  6470. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6471. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6472. f.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6473. f.inLen = RC2_BLOCK_SIZE*2;
  6474. f.outLen = RC2_BLOCK_SIZE*2;
  6475. f.keyLen = 16;
  6476. f.effectiveKeyBits = 64;
  6477. /* key length = 16, effective bits = 128 */
  6478. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6479. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6480. g.output = "\x22\x69\x55\x2A\xB0\xF8\x5C\xA6"
  6481. "\x53\x6E\xFD\x2D\x89\xE1\x2A\x73";
  6482. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6483. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6484. g.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6485. g.inLen = RC2_BLOCK_SIZE*2;
  6486. g.outLen = RC2_BLOCK_SIZE*2;
  6487. g.keyLen = 16;
  6488. g.effectiveKeyBits = 128;
  6489. /* key length = 33, effective bits = 129 */
  6490. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6491. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6492. h.output = "\x5B\x78\xD3\xA4\x3D\xFF\xF1\xF1"
  6493. "\x45\x30\xA8\xD5\xC7\x7C\x46\x19";
  6494. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6495. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6496. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6497. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6498. "\x1e";
  6499. h.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6500. h.inLen = RC2_BLOCK_SIZE*2;
  6501. h.outLen = RC2_BLOCK_SIZE*2;
  6502. h.keyLen = 33;
  6503. h.effectiveKeyBits = 129;
  6504. /* key length = 10, effective bits = 40 */
  6505. i.input = "\x11\x22\x33\x44\x55\x66\x77\x88"
  6506. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00"
  6507. "\x11\x22\x33\x44\x55\x66\x77\x88"
  6508. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00";
  6509. i.output = "\x71\x2D\x11\x99\xC9\xA0\x78\x4F"
  6510. "\xCD\xF1\x1E\x3D\xFD\x21\x7E\xDB"
  6511. "\xB2\x6E\x0D\xA4\x72\xBC\x31\x51"
  6512. "\x48\xEF\x4E\x68\x3B\xDC\xCD\x7D";
  6513. i.key = "\x26\x1E\x57\x8E\xC9\x62\xBF\xB8"
  6514. "\x3E\x96";
  6515. i.iv = "\x01\x02\x03\x04\x05\x06\x07\x08";
  6516. i.inLen = RC2_BLOCK_SIZE*4;
  6517. i.outLen = RC2_BLOCK_SIZE*4;
  6518. i.keyLen = 10;
  6519. i.effectiveKeyBits = 40;
  6520. test_rc2[0] = a;
  6521. test_rc2[1] = b;
  6522. test_rc2[2] = c;
  6523. test_rc2[3] = d;
  6524. test_rc2[4] = e;
  6525. test_rc2[5] = f;
  6526. test_rc2[6] = g;
  6527. test_rc2[7] = h;
  6528. test_rc2[8] = i;
  6529. for (j = 0; j < times; ++j) {
  6530. Rc2 rc2;
  6531. XMEMSET(cipher, 0, sizeof(cipher));
  6532. XMEMSET(plain, 0, sizeof(plain));
  6533. ret = wc_Rc2SetKey(&rc2, (byte*)test_rc2[j].key, test_rc2[j].keyLen,
  6534. (byte*)test_rc2[j].iv, test_rc2[j].effectiveKeyBits);
  6535. if (ret != 0) {
  6536. return WC_TEST_RET_ENC_EC(ret);
  6537. }
  6538. ret = wc_Rc2CbcEncrypt(&rc2, cipher, (byte*)test_rc2[j].input,
  6539. test_rc2[j].inLen);
  6540. if (ret != 0) {
  6541. return WC_TEST_RET_ENC_EC(ret);
  6542. }
  6543. if (XMEMCMP(cipher, (byte*)test_rc2[j].output, test_rc2[j].outLen)) {
  6544. return WC_TEST_RET_ENC_NC;
  6545. }
  6546. /* reset IV for decrypt, since overridden by encrypt operation */
  6547. ret = wc_Rc2SetIV(&rc2, (byte*)test_rc2[j].iv);
  6548. if (ret != 0) {
  6549. return WC_TEST_RET_ENC_EC(ret);
  6550. }
  6551. ret = wc_Rc2CbcDecrypt(&rc2, plain, cipher, test_rc2[j].outLen);
  6552. if (ret != 0) {
  6553. return WC_TEST_RET_ENC_EC(ret);
  6554. }
  6555. if (XMEMCMP(plain, (byte*)test_rc2[j].input, test_rc2[j].inLen)) {
  6556. return WC_TEST_RET_ENC_NC;
  6557. }
  6558. }
  6559. return 0;
  6560. }
  6561. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void)
  6562. {
  6563. wc_test_ret_t ret = 0;
  6564. WOLFSSL_ENTER("rc2_test");
  6565. ret = rc2_ecb_test();
  6566. if (ret != 0) {
  6567. return ret;
  6568. }
  6569. return rc2_cbc_test();
  6570. }
  6571. #endif
  6572. #ifndef NO_RC4
  6573. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void)
  6574. {
  6575. byte cipher[16];
  6576. byte plain[16];
  6577. wc_test_ret_t ret;
  6578. const char* keys[] =
  6579. {
  6580. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6581. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6582. "\x00\x00\x00\x00\x00\x00\x00\x00",
  6583. "\xef\x01\x23\x45"
  6584. };
  6585. testVector a, b, c, d;
  6586. testVector test_arc4[4];
  6587. int times = sizeof(test_arc4) / sizeof(testVector), i;
  6588. WOLFSSL_ENTER("arc4_test");
  6589. a.input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  6590. a.output = "\x75\xb7\x87\x80\x99\xe0\xc5\x96";
  6591. a.inLen = 8;
  6592. a.outLen = 8;
  6593. b.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6594. b.output = "\x74\x94\xc2\xe7\x10\x4b\x08\x79";
  6595. b.inLen = 8;
  6596. b.outLen = 8;
  6597. c.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6598. c.output = "\xde\x18\x89\x41\xa3\x37\x5d\x3a";
  6599. c.inLen = 8;
  6600. c.outLen = 8;
  6601. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  6602. d.output = "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61";
  6603. d.inLen = 10;
  6604. d.outLen = 10;
  6605. test_arc4[0] = a;
  6606. test_arc4[1] = b;
  6607. test_arc4[2] = c;
  6608. test_arc4[3] = d;
  6609. for (i = 0; i < times; ++i) {
  6610. Arc4 enc;
  6611. Arc4 dec;
  6612. int keylen = 8; /* XSTRLEN with key 0x00 not good */
  6613. if (i == 3)
  6614. keylen = 4;
  6615. ret = wc_Arc4Init(&enc, HEAP_HINT, devId);
  6616. if (ret != 0)
  6617. return WC_TEST_RET_ENC_EC(ret);
  6618. ret = wc_Arc4Init(&dec, HEAP_HINT, devId);
  6619. if (ret != 0)
  6620. return WC_TEST_RET_ENC_EC(ret);
  6621. ret = wc_Arc4SetKey(&enc, (byte*)keys[i], (word32)keylen);
  6622. if (ret != 0)
  6623. return WC_TEST_RET_ENC_EC(ret);
  6624. ret = wc_Arc4SetKey(&dec, (byte*)keys[i], (word32)keylen);
  6625. if (ret != 0)
  6626. return WC_TEST_RET_ENC_EC(ret);
  6627. ret = wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input,
  6628. (word32)test_arc4[i].outLen);
  6629. if (ret != 0)
  6630. return WC_TEST_RET_ENC_EC(ret);
  6631. ret = wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen);
  6632. if (ret != 0)
  6633. return WC_TEST_RET_ENC_EC(ret);
  6634. if (XMEMCMP(plain, test_arc4[i].input, test_arc4[i].outLen))
  6635. return WC_TEST_RET_ENC_I(i);
  6636. if (XMEMCMP(cipher, test_arc4[i].output, test_arc4[i].outLen))
  6637. return WC_TEST_RET_ENC_I(i);
  6638. wc_Arc4Free(&enc);
  6639. wc_Arc4Free(&dec);
  6640. }
  6641. return 0;
  6642. }
  6643. #endif
  6644. #ifdef HAVE_CHACHA
  6645. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void)
  6646. {
  6647. ChaCha enc;
  6648. ChaCha dec;
  6649. byte cipher[128];
  6650. byte plain[128];
  6651. byte sliver[64];
  6652. byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  6653. word32 keySz = 32;
  6654. wc_test_ret_t ret = 0;
  6655. int i;
  6656. int times = 4;
  6657. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  6658. {
  6659. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6660. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6661. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6662. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6663. };
  6664. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  6665. {
  6666. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6667. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6668. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6669. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  6670. };
  6671. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  6672. {
  6673. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6674. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6675. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6676. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6677. };
  6678. /* 128 bit key */
  6679. WOLFSSL_SMALL_STACK_STATIC const byte key4[] =
  6680. {
  6681. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6682. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6683. };
  6684. const byte* keys[] = {key1, key2, key3, key4};
  6685. WOLFSSL_SMALL_STACK_STATIC const byte ivs1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6686. WOLFSSL_SMALL_STACK_STATIC const byte ivs2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6687. WOLFSSL_SMALL_STACK_STATIC const byte ivs3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00};
  6688. WOLFSSL_SMALL_STACK_STATIC const byte ivs4[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6689. const byte* ivs[] = {ivs1, ivs2, ivs3, ivs4};
  6690. #ifndef BENCH_EMBEDDED
  6691. WOLFSSL_SMALL_STACK_STATIC const byte cipher_big_result[] = {
  6692. 0x06, 0xa6, 0x5d, 0x31, 0x21, 0x6c, 0xdb, 0x37, 0x48, 0x7c, 0x01, 0x9d,
  6693. 0x72, 0xdf, 0x0a, 0x5b, 0x64, 0x74, 0x20, 0xba, 0x9e, 0xe0, 0x26, 0x7a,
  6694. 0xbf, 0xdf, 0x83, 0x34, 0x3b, 0x4f, 0x94, 0x3f, 0x37, 0x89, 0xaf, 0x00,
  6695. 0xdf, 0x0f, 0x2e, 0x75, 0x16, 0x41, 0xf6, 0x7a, 0x86, 0x94, 0x9d, 0x32,
  6696. 0x56, 0xf0, 0x79, 0x71, 0x68, 0x6f, 0xa6, 0x6b, 0xc6, 0x59, 0x49, 0xf6,
  6697. 0x10, 0x34, 0x03, 0x03, 0x16, 0x53, 0x9a, 0x98, 0x2a, 0x46, 0xde, 0x17,
  6698. 0x06, 0x65, 0x70, 0xca, 0x0a, 0x1f, 0xab, 0x80, 0x26, 0x96, 0x3f, 0x3e,
  6699. 0x7a, 0x3c, 0xa8, 0x87, 0xbb, 0x65, 0xdd, 0x5e, 0x07, 0x7b, 0x34, 0xe0,
  6700. 0x56, 0xda, 0x32, 0x13, 0x30, 0xc9, 0x0c, 0xd7, 0xba, 0xe4, 0x1f, 0xa6,
  6701. 0x91, 0x4f, 0x72, 0x9f, 0xd9, 0x5c, 0x62, 0x7d, 0xa6, 0xc2, 0xbc, 0x87,
  6702. 0xae, 0x64, 0x11, 0x94, 0x3b, 0xbc, 0x6c, 0x23, 0xbd, 0x7d, 0x00, 0xb4,
  6703. 0x99, 0xf2, 0x68, 0xb5, 0x59, 0x70, 0x93, 0xad, 0x69, 0xd0, 0xb1, 0x28,
  6704. 0x70, 0x92, 0xeb, 0xec, 0x39, 0x80, 0x82, 0xde, 0x44, 0xe2, 0x8a, 0x26,
  6705. 0xb3, 0xe9, 0x45, 0xcf, 0x83, 0x76, 0x9f, 0x6a, 0xa0, 0x46, 0x4a, 0x3d,
  6706. 0x26, 0x56, 0xaf, 0x49, 0x41, 0x26, 0x1b, 0x6a, 0x41, 0x37, 0x65, 0x91,
  6707. 0x72, 0xc4, 0xe7, 0x3c, 0x17, 0x31, 0xae, 0x2e, 0x2b, 0x31, 0x45, 0xe4,
  6708. 0x93, 0xd3, 0x10, 0xaa, 0xc5, 0x62, 0xd5, 0x11, 0x4b, 0x57, 0x1d, 0xad,
  6709. 0x48, 0x06, 0xd0, 0x0d, 0x98, 0xa5, 0xc6, 0x5b, 0xd0, 0x9e, 0x22, 0xc0,
  6710. 0x00, 0x32, 0x5a, 0xf5, 0x1c, 0x89, 0x6d, 0x54, 0x97, 0x55, 0x6b, 0x46,
  6711. 0xc5, 0xc7, 0xc4, 0x48, 0x9c, 0xbf, 0x47, 0xdc, 0x03, 0xc4, 0x1b, 0xcb,
  6712. 0x65, 0xa6, 0x91, 0x9d, 0x6d, 0xf1, 0xb0, 0x7a, 0x4d, 0x3b, 0x03, 0x95,
  6713. 0xf4, 0x8b, 0x0b, 0xae, 0x39, 0xff, 0x3f, 0xf6, 0xc0, 0x14, 0x18, 0x8a,
  6714. 0xe5, 0x19, 0xbd, 0xc1, 0xb4, 0x05, 0x4e, 0x29, 0x2f, 0x0b, 0x33, 0x76,
  6715. 0x28, 0x16, 0xa4, 0xa6, 0x93, 0x04, 0xb5, 0x55, 0x6b, 0x89, 0x3d, 0xa5,
  6716. 0x0f, 0xd3, 0xad, 0xfa, 0xd9, 0xfd, 0x05, 0x5d, 0x48, 0x94, 0x25, 0x5a,
  6717. 0x2c, 0x9a, 0x94, 0x80, 0xb0, 0xe7, 0xcb, 0x4d, 0x77, 0xbf, 0xca, 0xd8,
  6718. 0x55, 0x48, 0xbd, 0x66, 0xb1, 0x85, 0x81, 0xb1, 0x37, 0x79, 0xab, 0x52,
  6719. 0x08, 0x14, 0x12, 0xac, 0xcd, 0x45, 0x4d, 0x53, 0x6b, 0xca, 0x96, 0xc7,
  6720. 0x3b, 0x2f, 0x73, 0xb1, 0x5a, 0x23, 0xbd, 0x65, 0xd5, 0xea, 0x17, 0xb3,
  6721. 0xdc, 0xa1, 0x17, 0x1b, 0x2d, 0xb3, 0x9c, 0xd0, 0xdb, 0x41, 0x77, 0xef,
  6722. 0x93, 0x20, 0x52, 0x3e, 0x9d, 0xf5, 0xbf, 0x33, 0xf7, 0x52, 0xc1, 0x90,
  6723. 0xa0, 0x15, 0x17, 0xce, 0xf7, 0xf7, 0xd0, 0x3a, 0x3b, 0xd1, 0x72, 0x56,
  6724. 0x31, 0x81, 0xae, 0x60, 0xab, 0x40, 0xc1, 0xd1, 0x28, 0x77, 0x53, 0xac,
  6725. 0x9f, 0x11, 0x0a, 0x88, 0x36, 0x4b, 0xda, 0x57, 0xa7, 0x28, 0x5c, 0x85,
  6726. 0xd3, 0x85, 0x9b, 0x79, 0xad, 0x05, 0x1c, 0x37, 0x14, 0x5e, 0x0d, 0xd0,
  6727. 0x23, 0x03, 0x42, 0x1d, 0x48, 0x5d, 0xc5, 0x3c, 0x5a, 0x08, 0xa9, 0x0d,
  6728. 0x6e, 0x82, 0x7c, 0x2e, 0x3c, 0x41, 0xcc, 0x96, 0x8e, 0xad, 0xee, 0x2a,
  6729. 0x61, 0x0b, 0x16, 0x0f, 0xa9, 0x24, 0x40, 0x85, 0xbc, 0x9f, 0x28, 0x8d,
  6730. 0xe6, 0x68, 0x4d, 0x8f, 0x30, 0x48, 0xd9, 0x73, 0x73, 0x6c, 0x9a, 0x7f,
  6731. 0x67, 0xf7, 0xde, 0x4c, 0x0a, 0x8b, 0xe4, 0xb3, 0x08, 0x2a, 0x52, 0xda,
  6732. 0x54, 0xee, 0xcd, 0xb5, 0x62, 0x4a, 0x26, 0x20, 0xfb, 0x40, 0xbb, 0x39,
  6733. 0x3a, 0x0f, 0x09, 0xe8, 0x00, 0xd1, 0x24, 0x97, 0x60, 0xe9, 0x83, 0x83,
  6734. 0xfe, 0x9f, 0x9c, 0x15, 0xcf, 0x69, 0x03, 0x9f, 0x03, 0xe1, 0xe8, 0x6e,
  6735. 0xbd, 0x87, 0x58, 0x68, 0xee, 0xec, 0xd8, 0x29, 0x46, 0x23, 0x49, 0x92,
  6736. 0x72, 0x95, 0x5b, 0x49, 0xca, 0xe0, 0x45, 0x59, 0xb2, 0xca, 0xf4, 0xfc,
  6737. 0xb7, 0x59, 0x37, 0x49, 0x28, 0xbc, 0xf3, 0xd7, 0x61, 0xbc, 0x4b, 0xf3,
  6738. 0xa9, 0x4b, 0x2f, 0x05, 0xa8, 0x01, 0xa5, 0xdc, 0x00, 0x6e, 0x01, 0xb6,
  6739. 0x45, 0x3c, 0xd5, 0x49, 0x7d, 0x5c, 0x25, 0xe8, 0x31, 0x87, 0xb2, 0xb9,
  6740. 0xbf, 0xb3, 0x01, 0x62, 0x0c, 0xd0, 0x48, 0x77, 0xa2, 0x34, 0x0f, 0x16,
  6741. 0x22, 0x28, 0xee, 0x54, 0x08, 0x93, 0x3b, 0xe4, 0xde, 0x7e, 0x63, 0xf7,
  6742. 0x97, 0x16, 0x5d, 0x71, 0x58, 0xc2, 0x2e, 0xf2, 0x36, 0xa6, 0x12, 0x65,
  6743. 0x94, 0x17, 0xac, 0x66, 0x23, 0x7e, 0xc6, 0x72, 0x79, 0x24, 0xce, 0x8f,
  6744. 0x55, 0x19, 0x97, 0x44, 0xfc, 0x55, 0xec, 0x85, 0x26, 0x27, 0xdb, 0x38,
  6745. 0xb1, 0x42, 0x0a, 0xdd, 0x05, 0x99, 0x28, 0xeb, 0x03, 0x6c, 0x9a, 0xe9,
  6746. 0x17, 0xf6, 0x2c, 0xb0, 0xfe, 0xe7, 0xa4, 0xa7, 0x31, 0xda, 0x4d, 0xb0,
  6747. 0x29, 0xdb, 0xdd, 0x8d, 0x12, 0x13, 0x9c, 0xb4, 0xcc, 0x83, 0x97, 0xfb,
  6748. 0x1a, 0xdc, 0x08, 0xd6, 0x30, 0x62, 0xe8, 0xeb, 0x8b, 0x61, 0xcb, 0x1d,
  6749. 0x06, 0xe3, 0xa5, 0x4d, 0x35, 0xdb, 0x59, 0xa8, 0x2d, 0x87, 0x27, 0x44,
  6750. 0x6f, 0xc0, 0x38, 0x97, 0xe4, 0x85, 0x00, 0x02, 0x09, 0xf6, 0x69, 0x3a,
  6751. 0xcf, 0x08, 0x1b, 0x21, 0xbb, 0x79, 0xb1, 0xa1, 0x34, 0x09, 0xe0, 0x80,
  6752. 0xca, 0xb0, 0x78, 0x8a, 0x11, 0x97, 0xd4, 0x07, 0xbe, 0x1b, 0x6a, 0x5d,
  6753. 0xdb, 0xd6, 0x1f, 0x76, 0x6b, 0x16, 0xf0, 0x58, 0x84, 0x5f, 0x59, 0xce,
  6754. 0x62, 0x34, 0xc3, 0xdf, 0x94, 0xb8, 0x2f, 0x84, 0x68, 0xf0, 0xb8, 0x51,
  6755. 0xd9, 0x6d, 0x8e, 0x4a, 0x1d, 0xe6, 0x5c, 0xd8, 0x86, 0x25, 0xe3, 0x24,
  6756. 0xfd, 0x21, 0x61, 0x13, 0x48, 0x3e, 0xf6, 0x7d, 0xa6, 0x71, 0x9b, 0xd2,
  6757. 0x6e, 0xe6, 0xd2, 0x08, 0x94, 0x62, 0x6c, 0x98, 0xfe, 0x2f, 0x9c, 0x88,
  6758. 0x7e, 0x78, 0x15, 0x02, 0x00, 0xf0, 0xba, 0x24, 0x91, 0xf2, 0xdc, 0x47,
  6759. 0x51, 0x4d, 0x15, 0x5e, 0x91, 0x5f, 0x57, 0x5b, 0x1d, 0x35, 0x24, 0x45,
  6760. 0x75, 0x9b, 0x88, 0x75, 0xf1, 0x2f, 0x85, 0xe7, 0x89, 0xd1, 0x01, 0xb4,
  6761. 0xc8, 0x18, 0xb7, 0x97, 0xef, 0x4b, 0x90, 0xf4, 0xbf, 0x10, 0x27, 0x3c,
  6762. 0x60, 0xff, 0xc4, 0x94, 0x20, 0x2f, 0x93, 0x4b, 0x4d, 0xe3, 0x80, 0xf7,
  6763. 0x2c, 0x71, 0xd9, 0xe3, 0x68, 0xb4, 0x77, 0x2b, 0xc7, 0x0d, 0x39, 0x92,
  6764. 0xef, 0x91, 0x0d, 0xb2, 0x11, 0x50, 0x0e, 0xe8, 0xad, 0x3b, 0xf6, 0xb5,
  6765. 0xc6, 0x14, 0x4d, 0x33, 0x53, 0xa7, 0x60, 0x15, 0xc7, 0x27, 0x51, 0xdc,
  6766. 0x54, 0x29, 0xa7, 0x0d, 0x6a, 0x7b, 0x72, 0x13, 0xad, 0x7d, 0x41, 0x19,
  6767. 0x4e, 0x42, 0x49, 0xcc, 0x42, 0xe4, 0xbd, 0x99, 0x13, 0xd9, 0x7f, 0xf3,
  6768. 0x38, 0xa4, 0xb6, 0x33, 0xed, 0x07, 0x48, 0x7e, 0x8e, 0x82, 0xfe, 0x3a,
  6769. 0x9d, 0x75, 0x93, 0xba, 0x25, 0x4e, 0x37, 0x3c, 0x0c, 0xd5, 0x69, 0xa9,
  6770. 0x2d, 0x9e, 0xfd, 0xe8, 0xbb, 0xf5, 0x0c, 0xe2, 0x86, 0xb9, 0x5e, 0x6f,
  6771. 0x28, 0xe4, 0x19, 0xb3, 0x0b, 0xa4, 0x86, 0xd7, 0x24, 0xd0, 0xb8, 0x89,
  6772. 0x7b, 0x76, 0xec, 0x05, 0x10, 0x5b, 0x68, 0xe9, 0x58, 0x66, 0xa3, 0xc5,
  6773. 0xb6, 0x63, 0x20, 0x0e, 0x0e, 0xea, 0x3d, 0x61, 0x5e, 0xda, 0x3d, 0x3c,
  6774. 0xf9, 0xfd, 0xed, 0xa9, 0xdb, 0x52, 0x94, 0x8a, 0x00, 0xca, 0x3c, 0x8d,
  6775. 0x66, 0x8f, 0xb0, 0xf0, 0x5a, 0xca, 0x3f, 0x63, 0x71, 0xbf, 0xca, 0x99,
  6776. 0x37, 0x9b, 0x75, 0x97, 0x89, 0x10, 0x6e, 0xcf, 0xf2, 0xf5, 0xe3, 0xd5,
  6777. 0x45, 0x9b, 0xad, 0x10, 0x71, 0x6c, 0x5f, 0x6f, 0x7f, 0x22, 0x77, 0x18,
  6778. 0x2f, 0xf9, 0x99, 0xc5, 0x69, 0x58, 0x03, 0x12, 0x86, 0x82, 0x3e, 0xbf,
  6779. 0xc2, 0x12, 0x35, 0x43, 0xa3, 0xd9, 0x18, 0x4f, 0x41, 0x11, 0x6b, 0xf3,
  6780. 0x67, 0xaf, 0x3d, 0x78, 0xe4, 0x22, 0x2d, 0xb3, 0x48, 0x43, 0x31, 0x1d,
  6781. 0xef, 0xa8, 0xba, 0x49, 0x8e, 0xa9, 0xa7, 0xb6, 0x18, 0x77, 0x84, 0xca,
  6782. 0xbd, 0xa2, 0x02, 0x1b, 0x6a, 0xf8, 0x5f, 0xda, 0xff, 0xcf, 0x01, 0x6a,
  6783. 0x86, 0x69, 0xa9, 0xe9, 0xcb, 0x60, 0x1e, 0x15, 0xdc, 0x8f, 0x5d, 0x39,
  6784. 0xb5, 0xce, 0x55, 0x5f, 0x47, 0x97, 0xb1, 0x19, 0x6e, 0x21, 0xd6, 0x13,
  6785. 0x39, 0xb2, 0x24, 0xe0, 0x62, 0x82, 0x9f, 0xed, 0x12, 0x81, 0xed, 0xee,
  6786. 0xab, 0xd0, 0x2f, 0x19, 0x89, 0x3f, 0x57, 0x2e, 0xc2, 0xe2, 0x67, 0xe8,
  6787. 0xae, 0x03, 0x56, 0xba, 0xd4, 0xd0, 0xa4, 0x89, 0x03, 0x06, 0x5b, 0xcc,
  6788. 0xf2, 0x22, 0xb8, 0x0e, 0x76, 0x79, 0x4a, 0x42, 0x1d, 0x37, 0x51, 0x5a,
  6789. 0xaa, 0x46, 0x6c, 0x2a, 0xdd, 0x66, 0xfe, 0xc6, 0x68, 0xc3, 0x38, 0xa2,
  6790. 0xae, 0x5b, 0x98, 0x24, 0x5d, 0x43, 0x05, 0x82, 0x38, 0x12, 0xd3, 0xd1,
  6791. 0x75, 0x2d, 0x4f, 0x61, 0xbd, 0xb9, 0x10, 0x87, 0x44, 0x2a, 0x78, 0x07,
  6792. 0xff, 0xf4, 0x0f, 0xa1, 0xf3, 0x68, 0x9f, 0xbe, 0xae, 0xa2, 0x91, 0xf0,
  6793. 0xc7, 0x55, 0x7a, 0x52, 0xd5, 0xa3, 0x8d, 0x6f, 0xe4, 0x90, 0x5c, 0xf3,
  6794. 0x5f, 0xce, 0x3d, 0x23, 0xf9, 0x8e, 0xae, 0x14, 0xfb, 0x82, 0x9a, 0xa3,
  6795. 0x04, 0x5f, 0xbf, 0xad, 0x3e, 0xf2, 0x97, 0x0a, 0x60, 0x40, 0x70, 0x19,
  6796. 0x72, 0xad, 0x66, 0xfb, 0x78, 0x1b, 0x84, 0x6c, 0x98, 0xbc, 0x8c, 0xf8,
  6797. 0x4f, 0xcb, 0xb5, 0xf6, 0xaf, 0x7a, 0xb7, 0x93, 0xef, 0x67, 0x48, 0x02,
  6798. 0x2c, 0xcb, 0xe6, 0x77, 0x0f, 0x7b, 0xc1, 0xee, 0xc5, 0xb6, 0x2d, 0x7e,
  6799. 0x62, 0xa0, 0xc0, 0xa7, 0xa5, 0x80, 0x31, 0x92, 0x50, 0xa1, 0x28, 0x22,
  6800. 0x95, 0x03, 0x17, 0xd1, 0x0f, 0xf6, 0x08, 0xe5, 0xec
  6801. };
  6802. #define CHACHA_BIG_TEST_SIZE 1305
  6803. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  6804. byte cipher_big[CHACHA_BIG_TEST_SIZE] = {0};
  6805. byte plain_big[CHACHA_BIG_TEST_SIZE] = {0};
  6806. byte input_big[CHACHA_BIG_TEST_SIZE] = {0};
  6807. #else
  6808. byte* cipher_big;
  6809. byte* plain_big;
  6810. byte* input_big;
  6811. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6812. int block_size;
  6813. #endif /* BENCH_EMBEDDED */
  6814. byte a[] = {0x76,0xb8,0xe0,0xad,0xa0,0xf1,0x3d,0x90};
  6815. byte b[] = {0x45,0x40,0xf0,0x5a,0x9f,0x1f,0xb2,0x96};
  6816. byte c[] = {0xde,0x9c,0xba,0x7b,0xf3,0xd6,0x9e,0xf5};
  6817. byte d[] = {0x89,0x67,0x09,0x52,0x60,0x83,0x64,0xfd};
  6818. byte* test_chacha[4];
  6819. test_chacha[0] = a;
  6820. test_chacha[1] = b;
  6821. test_chacha[2] = c;
  6822. test_chacha[3] = d;
  6823. WOLFSSL_ENTER("chacha_test");
  6824. #ifndef BENCH_EMBEDDED
  6825. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  6826. cipher_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6827. DYNAMIC_TYPE_TMP_BUFFER);
  6828. if (cipher_big == NULL) {
  6829. return MEMORY_E;
  6830. }
  6831. plain_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6832. DYNAMIC_TYPE_TMP_BUFFER);
  6833. if (plain_big == NULL) {
  6834. return MEMORY_E;
  6835. }
  6836. input_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6837. DYNAMIC_TYPE_TMP_BUFFER);
  6838. if (input_big == NULL) {
  6839. return MEMORY_E;
  6840. }
  6841. XMEMSET(cipher_big, 0, CHACHA_BIG_TEST_SIZE);
  6842. XMEMSET(plain_big, 0, CHACHA_BIG_TEST_SIZE);
  6843. XMEMSET(input_big, 0, CHACHA_BIG_TEST_SIZE);
  6844. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6845. #endif /* BENCH_EMBEDDED */
  6846. for (i = 0; i < times; ++i) {
  6847. if (i < 3) {
  6848. keySz = 32;
  6849. }
  6850. else {
  6851. keySz = 16;
  6852. }
  6853. XMEMCPY(plain, keys[i], keySz);
  6854. XMEMSET(cipher, 0, 32);
  6855. XMEMCPY(cipher + 4, ivs[i], 8);
  6856. ret |= wc_Chacha_SetKey(&enc, keys[i], keySz);
  6857. ret |= wc_Chacha_SetKey(&dec, keys[i], keySz);
  6858. if (ret != 0)
  6859. return ret;
  6860. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  6861. ret |= wc_Chacha_SetIV(&dec, cipher, 0);
  6862. if (ret != 0)
  6863. return ret;
  6864. XMEMCPY(plain, input, 8);
  6865. ret |= wc_Chacha_Process(&enc, cipher, plain, (word32)8);
  6866. ret |= wc_Chacha_Process(&dec, plain, cipher, (word32)8);
  6867. if (ret != 0)
  6868. return ret;
  6869. if (XMEMCMP(test_chacha[i], cipher, 8))
  6870. return WC_TEST_RET_ENC_I(i);
  6871. if (XMEMCMP(plain, input, 8))
  6872. return WC_TEST_RET_ENC_I(i);
  6873. }
  6874. /* test of starting at a different counter
  6875. encrypts all of the information and decrypts starting at 2nd chunk */
  6876. XMEMSET(plain, 0, sizeof(plain));
  6877. XMEMSET(sliver, 1, sizeof(sliver)); /* set as 1's to not match plain */
  6878. XMEMSET(cipher, 0, sizeof(cipher));
  6879. XMEMCPY(cipher + 4, ivs[0], 8);
  6880. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  6881. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  6882. if (ret != 0)
  6883. return ret;
  6884. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  6885. ret |= wc_Chacha_SetIV(&dec, cipher, 1);
  6886. if (ret != 0)
  6887. return ret;
  6888. ret |= wc_Chacha_Process(&enc, cipher, plain, sizeof(plain));
  6889. ret |= wc_Chacha_Process(&dec, sliver, cipher + 64, sizeof(sliver));
  6890. if (ret != 0)
  6891. return ret;
  6892. if (XMEMCMP(plain + 64, sliver, 64))
  6893. return WC_TEST_RET_ENC_NC;
  6894. #ifndef BENCH_EMBEDDED
  6895. /* test of encrypting more data */
  6896. keySz = 32;
  6897. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  6898. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  6899. if (ret != 0)
  6900. return ret;
  6901. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  6902. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  6903. if (ret != 0)
  6904. return ret;
  6905. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big, CHACHA_BIG_TEST_SIZE);
  6906. ret |= wc_Chacha_Process(&dec, plain_big, cipher_big,
  6907. CHACHA_BIG_TEST_SIZE);
  6908. if (ret != 0)
  6909. return ret;
  6910. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  6911. return WC_TEST_RET_ENC_NC;
  6912. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  6913. return WC_TEST_RET_ENC_NC;
  6914. for (i = 0; i < 18; ++i) {
  6915. /* this will test all paths
  6916. * block sizes: 1 3 7 15 31 63 127 255 511 (i = 0- 8)
  6917. * 2 4 8 16 32 64 128 256 512 (i = 9-17)
  6918. */
  6919. block_size = (2 << (i%9)) - (i<9?1:0);
  6920. keySz = 32;
  6921. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  6922. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  6923. if (ret != 0)
  6924. return ret;
  6925. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  6926. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  6927. if (ret != 0)
  6928. return ret;
  6929. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big , (word32)block_size);
  6930. ret |= wc_Chacha_Process(&dec, plain_big , cipher_big, (word32)block_size);
  6931. if (ret != 0)
  6932. return ret;
  6933. if (XMEMCMP(plain_big, input_big, block_size))
  6934. return WC_TEST_RET_ENC_I(i);
  6935. if (XMEMCMP(cipher_big, cipher_big_result, block_size))
  6936. return WC_TEST_RET_ENC_I(i);
  6937. }
  6938. /* Streaming test */
  6939. for (i = 1; i <= (int)CHACHA_CHUNK_BYTES + 1; i++) {
  6940. int j, rem;
  6941. ret = wc_Chacha_SetKey(&enc, keys[0], keySz);
  6942. if (ret != 0)
  6943. return WC_TEST_RET_ENC_EC(ret);
  6944. ret = wc_Chacha_SetKey(&dec, keys[0], keySz);
  6945. if (ret != 0)
  6946. return WC_TEST_RET_ENC_EC(ret);
  6947. ret = wc_Chacha_SetIV(&enc, ivs[2], 0);
  6948. if (ret != 0)
  6949. return WC_TEST_RET_ENC_EC(ret);
  6950. ret = wc_Chacha_SetIV(&dec, ivs[2], 0);
  6951. if (ret != 0)
  6952. return WC_TEST_RET_ENC_EC(ret);
  6953. for (j = 0; j < CHACHA_BIG_TEST_SIZE - i; j+= i) {
  6954. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)i);
  6955. if (ret != 0)
  6956. return WC_TEST_RET_ENC_EC(ret);
  6957. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)i);
  6958. if (ret != 0)
  6959. return WC_TEST_RET_ENC_EC(ret);
  6960. }
  6961. rem = CHACHA_BIG_TEST_SIZE - j;
  6962. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)rem);
  6963. if (ret != 0)
  6964. return WC_TEST_RET_ENC_EC(ret);
  6965. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)rem);
  6966. if (ret != 0)
  6967. return WC_TEST_RET_ENC_EC(ret);
  6968. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  6969. return WC_TEST_RET_ENC_I(i);
  6970. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  6971. return WC_TEST_RET_ENC_I(i);
  6972. }
  6973. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  6974. XFREE(cipher_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  6975. XFREE(plain_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  6976. XFREE(input_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  6977. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6978. #endif /* BENCH_EMBEDDED */
  6979. return 0;
  6980. }
  6981. #endif /* HAVE_CHACHA */
  6982. #ifdef HAVE_POLY1305
  6983. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void)
  6984. {
  6985. byte tag[16];
  6986. Poly1305 enc;
  6987. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {
  6988. 0x43,0x72,0x79,0x70,0x74,0x6f,0x67,0x72,
  6989. 0x61,0x70,0x68,0x69,0x63,0x20,0x46,0x6f,
  6990. 0x72,0x75,0x6d,0x20,0x52,0x65,0x73,0x65,
  6991. 0x61,0x72,0x63,0x68,0x20,0x47,0x72,0x6f,
  6992. 0x75,0x70
  6993. };
  6994. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {
  6995. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,
  6996. 0x6c,0x64,0x21
  6997. };
  6998. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {
  6999. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7000. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7001. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7002. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7003. };
  7004. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  7005. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7006. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7007. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7008. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7009. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7010. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7011. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7012. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7013. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7014. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7015. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7016. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7017. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7018. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7019. 0x61,0x16
  7020. };
  7021. WOLFSSL_SMALL_STACK_STATIC const byte msg5[] = {
  7022. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7023. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7024. };
  7025. WOLFSSL_SMALL_STACK_STATIC const byte msg6[] = {
  7026. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7027. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7028. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7029. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7030. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7031. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7032. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7033. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7034. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7035. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7036. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7037. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7038. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7039. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7040. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7041. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7042. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7043. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7044. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7045. 0x61,0x16
  7046. };
  7047. WOLFSSL_SMALL_STACK_STATIC const byte msg7[] = {
  7048. 0xe8,0x8c,0x85,0x03,0x43,0xaf,0xa7,0x85,
  7049. 0x21,0x6b,0xc3,0x45,0xc4,0x53,0x98,0xf8,
  7050. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7051. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7052. };
  7053. byte additional[] = {
  7054. 0x50,0x51,0x52,0x53,0xc0,0xc1,0xc2,0xc3,
  7055. 0xc4,0xc5,0xc6,0xc7
  7056. };
  7057. WOLFSSL_SMALL_STACK_STATIC const byte correct0[] = {
  7058. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7059. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7060. };
  7061. WOLFSSL_SMALL_STACK_STATIC const byte correct1[] = {
  7062. 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,
  7063. 0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9
  7064. };
  7065. WOLFSSL_SMALL_STACK_STATIC const byte correct2[] = {
  7066. 0xa6,0xf7,0x45,0x00,0x8f,0x81,0xc9,0x16,
  7067. 0xa2,0x0d,0xcc,0x74,0xee,0xf2,0xb2,0xf0
  7068. };
  7069. WOLFSSL_SMALL_STACK_STATIC const byte correct3[] = {
  7070. 0x49,0xec,0x78,0x09,0x0e,0x48,0x1e,0xc6,
  7071. 0xc2,0x6b,0x33,0xb9,0x1c,0xcc,0x03,0x07
  7072. };
  7073. WOLFSSL_SMALL_STACK_STATIC const byte correct4[] = {
  7074. 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,
  7075. 0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91
  7076. };
  7077. WOLFSSL_SMALL_STACK_STATIC const byte correct5[] = {
  7078. 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7079. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7080. };
  7081. WOLFSSL_SMALL_STACK_STATIC const byte correct6[] = {
  7082. 0xea,0x11,0x5c,0x4f,0xd0,0xc0,0x10,0xae,
  7083. 0xf7,0xdf,0xda,0x77,0xa2,0xe9,0xaf,0xca
  7084. };
  7085. WOLFSSL_SMALL_STACK_STATIC const byte correct7[] = {
  7086. 0x14,0x00,0x00,0x88,0x5c,0x00,0x00,0x88,
  7087. 0x5c,0x00,0x00,0x88,0x5c,0x00,0x00,0x88
  7088. };
  7089. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7090. 0x85,0xd6,0xbe,0x78,0x57,0x55,0x6d,0x33,
  7091. 0x7f,0x44,0x52,0xfe,0x42,0xd5,0x06,0xa8,
  7092. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7093. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7094. };
  7095. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7096. 0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,
  7097. 0x33,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,
  7098. 0x6b,0x65,0x79,0x20,0x66,0x6f,0x72,0x20,
  7099. 0x50,0x6f,0x6c,0x79,0x31,0x33,0x30,0x35
  7100. };
  7101. WOLFSSL_SMALL_STACK_STATIC const byte key4[] = {
  7102. 0x7b,0xac,0x2b,0x25,0x2d,0xb4,0x47,0xaf,
  7103. 0x09,0xb6,0x7a,0x55,0xa4,0xe9,0x55,0x84,
  7104. 0x0a,0xe1,0xd6,0x73,0x10,0x75,0xd9,0xeb,
  7105. 0x2a,0x93,0x75,0x78,0x3e,0xd5,0x53,0xff
  7106. };
  7107. WOLFSSL_SMALL_STACK_STATIC const byte key5[] = {
  7108. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7109. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7110. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7111. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7112. };
  7113. WOLFSSL_SMALL_STACK_STATIC const byte key7[] = {
  7114. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7115. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7116. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7117. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  7118. };
  7119. const byte* msgs[] = {NULL, msg1, msg2, msg3, msg5, msg6, msg7};
  7120. word32 szm[] = {0, sizeof(msg1), sizeof(msg2),
  7121. sizeof(msg3), sizeof(msg5), sizeof(msg6),
  7122. sizeof(msg7)};
  7123. const byte* keys[] = {key, key, key2, key2, key5, key, key7};
  7124. const byte* tests[] = {correct0, correct1, correct2, correct3, correct5,
  7125. correct6, correct7};
  7126. int i;
  7127. wc_test_ret_t ret = 0;
  7128. WOLFSSL_ENTER("poly1305_test");
  7129. for (i = 0; i < 7; i++) {
  7130. ret = wc_Poly1305SetKey(&enc, keys[i], 32);
  7131. if (ret != 0)
  7132. return WC_TEST_RET_ENC_I(i);
  7133. ret = wc_Poly1305Update(&enc, msgs[i], szm[i]);
  7134. if (ret != 0)
  7135. return WC_TEST_RET_ENC_I(i);
  7136. ret = wc_Poly1305Final(&enc, tag);
  7137. if (ret != 0)
  7138. return WC_TEST_RET_ENC_I(i);
  7139. if (XMEMCMP(tag, tests[i], sizeof(tag)))
  7140. return WC_TEST_RET_ENC_I(i);
  7141. }
  7142. /* Check TLS MAC function from 2.8.2 https://tools.ietf.org/html/rfc7539 */
  7143. XMEMSET(tag, 0, sizeof(tag));
  7144. ret = wc_Poly1305SetKey(&enc, key4, sizeof(key4));
  7145. if (ret != 0)
  7146. return WC_TEST_RET_ENC_EC(ret);
  7147. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7148. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7149. if (ret != 0)
  7150. return WC_TEST_RET_ENC_EC(ret);
  7151. if (XMEMCMP(tag, correct4, sizeof(tag)))
  7152. return WC_TEST_RET_ENC_NC;
  7153. /* Check fail of TLS MAC function if altering additional data */
  7154. XMEMSET(tag, 0, sizeof(tag));
  7155. additional[0]++;
  7156. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7157. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7158. if (ret != 0)
  7159. return WC_TEST_RET_ENC_EC(ret);
  7160. if (XMEMCMP(tag, correct4, sizeof(tag)) == 0)
  7161. return WC_TEST_RET_ENC_NC;
  7162. return 0;
  7163. }
  7164. #endif /* HAVE_POLY1305 */
  7165. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  7166. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void)
  7167. {
  7168. /* Test #1 from Section 2.8.2 of draft-irtf-cfrg-chacha20-poly1305-10 */
  7169. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7170. WOLFSSL_SMALL_STACK_STATIC const byte key1[] = {
  7171. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  7172. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  7173. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  7174. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  7175. };
  7176. WOLFSSL_SMALL_STACK_STATIC const byte plaintext1[] = {
  7177. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  7178. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  7179. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  7180. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  7181. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  7182. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  7183. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  7184. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  7185. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  7186. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  7187. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  7188. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  7189. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  7190. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  7191. 0x74, 0x2e
  7192. };
  7193. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] = {
  7194. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  7195. 0x44, 0x45, 0x46, 0x47
  7196. };
  7197. WOLFSSL_SMALL_STACK_STATIC const byte aad1[] = { /* additional data */
  7198. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  7199. 0xc4, 0xc5, 0xc6, 0xc7
  7200. };
  7201. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] = { /* expected output from operation */
  7202. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  7203. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  7204. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  7205. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  7206. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  7207. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  7208. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  7209. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  7210. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  7211. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  7212. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  7213. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  7214. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  7215. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  7216. 0x61, 0x16
  7217. };
  7218. WOLFSSL_SMALL_STACK_STATIC const byte authTag1[] = { /* expected output from operation */
  7219. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  7220. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  7221. };
  7222. /* Test #2 from Appendix A.2 in draft-irtf-cfrg-chacha20-poly1305-10 */
  7223. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7224. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7225. 0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
  7226. 0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
  7227. 0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
  7228. 0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0
  7229. };
  7230. WOLFSSL_SMALL_STACK_STATIC const byte plaintext2[] = {
  7231. 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
  7232. 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20,
  7233. 0x61, 0x72, 0x65, 0x20, 0x64, 0x72, 0x61, 0x66,
  7234. 0x74, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7235. 0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x6c, 0x69,
  7236. 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
  7237. 0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20,
  7238. 0x6f, 0x66, 0x20, 0x73, 0x69, 0x78, 0x20, 0x6d,
  7239. 0x6f, 0x6e, 0x74, 0x68, 0x73, 0x20, 0x61, 0x6e,
  7240. 0x64, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65,
  7241. 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
  7242. 0x2c, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63,
  7243. 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f,
  7244. 0x62, 0x73, 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x64,
  7245. 0x20, 0x62, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65,
  7246. 0x72, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7247. 0x6e, 0x74, 0x73, 0x20, 0x61, 0x74, 0x20, 0x61,
  7248. 0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x2e,
  7249. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69,
  7250. 0x6e, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72,
  7251. 0x69, 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20,
  7252. 0x75, 0x73, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65,
  7253. 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61,
  7254. 0x66, 0x74, 0x73, 0x20, 0x61, 0x73, 0x20, 0x72,
  7255. 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
  7256. 0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61,
  7257. 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x20,
  7258. 0x63, 0x69, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65,
  7259. 0x6d, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20,
  7260. 0x74, 0x68, 0x61, 0x6e, 0x20, 0x61, 0x73, 0x20,
  7261. 0x2f, 0xe2, 0x80, 0x9c, 0x77, 0x6f, 0x72, 0x6b,
  7262. 0x20, 0x69, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67,
  7263. 0x72, 0x65, 0x73, 0x73, 0x2e, 0x2f, 0xe2, 0x80,
  7264. 0x9d
  7265. };
  7266. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  7267. 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
  7268. 0x05, 0x06, 0x07, 0x08
  7269. };
  7270. WOLFSSL_SMALL_STACK_STATIC const byte aad2[] = { /* additional data */
  7271. 0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00,
  7272. 0x00, 0x00, 0x4e, 0x91
  7273. };
  7274. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] = { /* expected output from operation */
  7275. 0x64, 0xa0, 0x86, 0x15, 0x75, 0x86, 0x1a, 0xf4,
  7276. 0x60, 0xf0, 0x62, 0xc7, 0x9b, 0xe6, 0x43, 0xbd,
  7277. 0x5e, 0x80, 0x5c, 0xfd, 0x34, 0x5c, 0xf3, 0x89,
  7278. 0xf1, 0x08, 0x67, 0x0a, 0xc7, 0x6c, 0x8c, 0xb2,
  7279. 0x4c, 0x6c, 0xfc, 0x18, 0x75, 0x5d, 0x43, 0xee,
  7280. 0xa0, 0x9e, 0xe9, 0x4e, 0x38, 0x2d, 0x26, 0xb0,
  7281. 0xbd, 0xb7, 0xb7, 0x3c, 0x32, 0x1b, 0x01, 0x00,
  7282. 0xd4, 0xf0, 0x3b, 0x7f, 0x35, 0x58, 0x94, 0xcf,
  7283. 0x33, 0x2f, 0x83, 0x0e, 0x71, 0x0b, 0x97, 0xce,
  7284. 0x98, 0xc8, 0xa8, 0x4a, 0xbd, 0x0b, 0x94, 0x81,
  7285. 0x14, 0xad, 0x17, 0x6e, 0x00, 0x8d, 0x33, 0xbd,
  7286. 0x60, 0xf9, 0x82, 0xb1, 0xff, 0x37, 0xc8, 0x55,
  7287. 0x97, 0x97, 0xa0, 0x6e, 0xf4, 0xf0, 0xef, 0x61,
  7288. 0xc1, 0x86, 0x32, 0x4e, 0x2b, 0x35, 0x06, 0x38,
  7289. 0x36, 0x06, 0x90, 0x7b, 0x6a, 0x7c, 0x02, 0xb0,
  7290. 0xf9, 0xf6, 0x15, 0x7b, 0x53, 0xc8, 0x67, 0xe4,
  7291. 0xb9, 0x16, 0x6c, 0x76, 0x7b, 0x80, 0x4d, 0x46,
  7292. 0xa5, 0x9b, 0x52, 0x16, 0xcd, 0xe7, 0xa4, 0xe9,
  7293. 0x90, 0x40, 0xc5, 0xa4, 0x04, 0x33, 0x22, 0x5e,
  7294. 0xe2, 0x82, 0xa1, 0xb0, 0xa0, 0x6c, 0x52, 0x3e,
  7295. 0xaf, 0x45, 0x34, 0xd7, 0xf8, 0x3f, 0xa1, 0x15,
  7296. 0x5b, 0x00, 0x47, 0x71, 0x8c, 0xbc, 0x54, 0x6a,
  7297. 0x0d, 0x07, 0x2b, 0x04, 0xb3, 0x56, 0x4e, 0xea,
  7298. 0x1b, 0x42, 0x22, 0x73, 0xf5, 0x48, 0x27, 0x1a,
  7299. 0x0b, 0xb2, 0x31, 0x60, 0x53, 0xfa, 0x76, 0x99,
  7300. 0x19, 0x55, 0xeb, 0xd6, 0x31, 0x59, 0x43, 0x4e,
  7301. 0xce, 0xbb, 0x4e, 0x46, 0x6d, 0xae, 0x5a, 0x10,
  7302. 0x73, 0xa6, 0x72, 0x76, 0x27, 0x09, 0x7a, 0x10,
  7303. 0x49, 0xe6, 0x17, 0xd9, 0x1d, 0x36, 0x10, 0x94,
  7304. 0xfa, 0x68, 0xf0, 0xff, 0x77, 0x98, 0x71, 0x30,
  7305. 0x30, 0x5b, 0xea, 0xba, 0x2e, 0xda, 0x04, 0xdf,
  7306. 0x99, 0x7b, 0x71, 0x4d, 0x6c, 0x6f, 0x2c, 0x29,
  7307. 0xa6, 0xad, 0x5c, 0xb4, 0x02, 0x2b, 0x02, 0x70,
  7308. 0x9b
  7309. };
  7310. WOLFSSL_SMALL_STACK_STATIC const byte authTag2[] = { /* expected output from operation */
  7311. 0xee, 0xad, 0x9d, 0x67, 0x89, 0x0c, 0xbb, 0x22,
  7312. 0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38
  7313. };
  7314. byte generatedCiphertext[265]; /* max plaintext2/cipher2 */
  7315. byte generatedPlaintext[265]; /* max plaintext2/cipher2 */
  7316. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  7317. ChaChaPoly_Aead aead;
  7318. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  7319. #define TEST_SMALL_CHACHA_CHUNKS 32
  7320. #else
  7321. #define TEST_SMALL_CHACHA_CHUNKS 64
  7322. #endif
  7323. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7324. word32 testLen;
  7325. #endif
  7326. wc_test_ret_t err;
  7327. WOLFSSL_ENTER("chacha20_poly1305_aead_test");
  7328. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7329. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7330. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7331. /* Parameter Validation testing */
  7332. /* Encrypt */
  7333. err = wc_ChaCha20Poly1305_Encrypt(NULL, iv1, aad1, sizeof(aad1), plaintext1,
  7334. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7335. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7336. return WC_TEST_RET_ENC_EC(err);
  7337. err = wc_ChaCha20Poly1305_Encrypt(key1, NULL, aad1, sizeof(aad1),
  7338. plaintext1, sizeof(plaintext1), generatedCiphertext,
  7339. generatedAuthTag);
  7340. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7341. return WC_TEST_RET_ENC_EC(err);
  7342. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7343. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7344. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7345. return WC_TEST_RET_ENC_EC(err);
  7346. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7347. sizeof(plaintext1), NULL, generatedAuthTag);
  7348. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7349. return WC_TEST_RET_ENC_EC(err);
  7350. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7351. sizeof(plaintext1), generatedCiphertext, NULL);
  7352. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7353. return WC_TEST_RET_ENC_EC(err);
  7354. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7355. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7356. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7357. return WC_TEST_RET_ENC_EC(err);
  7358. /* Decrypt */
  7359. err = wc_ChaCha20Poly1305_Decrypt(NULL, iv2, aad2, sizeof(aad2), cipher2,
  7360. sizeof(cipher2), authTag2, generatedPlaintext);
  7361. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7362. return WC_TEST_RET_ENC_EC(err);
  7363. err = wc_ChaCha20Poly1305_Decrypt(key2, NULL, aad2, sizeof(aad2), cipher2,
  7364. sizeof(cipher2), authTag2, generatedPlaintext);
  7365. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7366. return WC_TEST_RET_ENC_EC(err);
  7367. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7368. sizeof(cipher2), authTag2, generatedPlaintext);
  7369. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7370. return WC_TEST_RET_ENC_EC(err);
  7371. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7372. sizeof(cipher2), NULL, generatedPlaintext);
  7373. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7374. return WC_TEST_RET_ENC_EC(err);
  7375. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7376. sizeof(cipher2), authTag2, NULL);
  7377. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7378. return WC_TEST_RET_ENC_EC(err);
  7379. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7380. sizeof(cipher2), authTag2, generatedPlaintext);
  7381. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7382. return WC_TEST_RET_ENC_EC(err);
  7383. /* Test #1 */
  7384. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1,
  7385. aad1, sizeof(aad1),
  7386. plaintext1, sizeof(plaintext1),
  7387. generatedCiphertext, generatedAuthTag);
  7388. if (err) {
  7389. return WC_TEST_RET_ENC_EC(err);
  7390. }
  7391. /* -- Check the ciphertext and authtag */
  7392. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7393. return WC_TEST_RET_ENC_NC;
  7394. }
  7395. if (XMEMCMP(generatedAuthTag, authTag1, sizeof(authTag1))) {
  7396. return WC_TEST_RET_ENC_NC;
  7397. }
  7398. /* -- Verify decryption works */
  7399. err = wc_ChaCha20Poly1305_Decrypt(key1, iv1,
  7400. aad1, sizeof(aad1),
  7401. cipher1, sizeof(cipher1),
  7402. authTag1, generatedPlaintext);
  7403. if (err) {
  7404. return err;
  7405. }
  7406. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7407. return WC_TEST_RET_ENC_NC;
  7408. }
  7409. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7410. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7411. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7412. /* Test #2 */
  7413. err = wc_ChaCha20Poly1305_Encrypt(key2, iv2,
  7414. aad2, sizeof(aad2),
  7415. plaintext2, sizeof(plaintext2),
  7416. generatedCiphertext, generatedAuthTag);
  7417. if (err) {
  7418. return err;
  7419. }
  7420. /* -- Check the ciphertext and authtag */
  7421. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7422. return WC_TEST_RET_ENC_NC;
  7423. }
  7424. if (XMEMCMP(generatedAuthTag, authTag2, sizeof(authTag2))) {
  7425. return WC_TEST_RET_ENC_NC;
  7426. }
  7427. /* -- Verify decryption works */
  7428. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2,
  7429. aad2, sizeof(aad2),
  7430. cipher2, sizeof(cipher2),
  7431. authTag2, generatedPlaintext);
  7432. if (err) {
  7433. return err;
  7434. }
  7435. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7436. return WC_TEST_RET_ENC_NC;
  7437. }
  7438. /* AEAD init/update/final - bad argument tests */
  7439. err = wc_ChaCha20Poly1305_Init(NULL, key1, iv1,
  7440. CHACHA20_POLY1305_AEAD_DECRYPT);
  7441. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7442. return WC_TEST_RET_ENC_EC(err);
  7443. err = wc_ChaCha20Poly1305_Init(&aead, NULL, iv1,
  7444. CHACHA20_POLY1305_AEAD_DECRYPT);
  7445. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7446. return WC_TEST_RET_ENC_EC(err);
  7447. err = wc_ChaCha20Poly1305_Init(&aead, key1, NULL,
  7448. CHACHA20_POLY1305_AEAD_DECRYPT);
  7449. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7450. return WC_TEST_RET_ENC_EC(err);
  7451. err = wc_ChaCha20Poly1305_UpdateAad(NULL, aad1, sizeof(aad1));
  7452. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7453. return WC_TEST_RET_ENC_EC(err);
  7454. err = wc_ChaCha20Poly1305_UpdateAad(&aead, NULL, sizeof(aad1));
  7455. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7456. return WC_TEST_RET_ENC_EC(err);
  7457. err = wc_ChaCha20Poly1305_UpdateData(NULL, generatedPlaintext,
  7458. generatedPlaintext, sizeof(plaintext1));
  7459. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7460. return WC_TEST_RET_ENC_EC(err);
  7461. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext, NULL,
  7462. sizeof(plaintext1));
  7463. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7464. return WC_TEST_RET_ENC_EC(err);
  7465. err = wc_ChaCha20Poly1305_UpdateData(&aead, NULL, generatedPlaintext,
  7466. sizeof(plaintext1));
  7467. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7468. return WC_TEST_RET_ENC_EC(err);
  7469. err = wc_ChaCha20Poly1305_Final(NULL, generatedAuthTag);
  7470. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7471. return WC_TEST_RET_ENC_EC(err);
  7472. err = wc_ChaCha20Poly1305_Final(&aead, NULL);
  7473. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7474. return WC_TEST_RET_ENC_EC(err);
  7475. /* AEAD init/update/final - bad state tests */
  7476. /* clear struct - make valgrind happy to resolve
  7477. "Conditional jump or move depends on uninitialised value(s)".
  7478. The enum is "int" size and aead.state is "byte" */
  7479. /* The wc_ChaCha20Poly1305_Init function does this normally */
  7480. XMEMSET(&aead, 0, sizeof(aead));
  7481. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7482. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7483. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7484. return WC_TEST_RET_ENC_EC(err);
  7485. aead.state = CHACHA20_POLY1305_STATE_DATA;
  7486. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7487. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7488. return WC_TEST_RET_ENC_EC(err);
  7489. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7490. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext,
  7491. generatedPlaintext, sizeof(plaintext1));
  7492. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7493. return WC_TEST_RET_ENC_EC(err);
  7494. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7495. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7496. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7497. return WC_TEST_RET_ENC_EC(err);
  7498. aead.state = CHACHA20_POLY1305_STATE_READY;
  7499. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7500. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7501. return WC_TEST_RET_ENC_EC(err);
  7502. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7503. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7504. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7505. /* Test 1 - Encrypt */
  7506. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7507. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7508. if (err != 0)
  7509. return WC_TEST_RET_ENC_EC(err);
  7510. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7511. if (err != 0)
  7512. return WC_TEST_RET_ENC_EC(err);
  7513. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7514. /* test doing data in smaller chunks */
  7515. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7516. word32 dataLen = sizeof(plaintext1) - testLen;
  7517. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7518. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7519. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext1[testLen],
  7520. &generatedCiphertext[testLen], dataLen);
  7521. if (err != 0)
  7522. return WC_TEST_RET_ENC_EC(err);
  7523. testLen += dataLen;
  7524. }
  7525. #else
  7526. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext1,
  7527. generatedCiphertext, sizeof(plaintext1));
  7528. #endif
  7529. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7530. if (err != 0)
  7531. return WC_TEST_RET_ENC_EC(err);
  7532. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7533. if (err != 0)
  7534. return WC_TEST_RET_ENC_EC(err);
  7535. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7536. return WC_TEST_RET_ENC_NC;
  7537. }
  7538. /* Test 1 - Decrypt */
  7539. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7540. CHACHA20_POLY1305_AEAD_DECRYPT);
  7541. if (err != 0)
  7542. return WC_TEST_RET_ENC_EC(err);
  7543. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7544. if (err != 0)
  7545. return WC_TEST_RET_ENC_EC(err);
  7546. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7547. /* test doing data in smaller chunks */
  7548. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7549. word32 dataLen = sizeof(plaintext1) - testLen;
  7550. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7551. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7552. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7553. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7554. dataLen);
  7555. if (err != 0)
  7556. return WC_TEST_RET_ENC_EC(err);
  7557. testLen += dataLen;
  7558. }
  7559. #else
  7560. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7561. generatedPlaintext, sizeof(cipher1));
  7562. #endif
  7563. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7564. if (err != 0)
  7565. return WC_TEST_RET_ENC_EC(err);
  7566. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7567. if (err != 0)
  7568. return WC_TEST_RET_ENC_EC(err);
  7569. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7570. return WC_TEST_RET_ENC_NC;
  7571. }
  7572. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7573. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7574. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7575. /* Test 2 - Encrypt */
  7576. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7577. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7578. if (err != 0)
  7579. return WC_TEST_RET_ENC_EC(err);
  7580. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7581. if (err != 0)
  7582. return WC_TEST_RET_ENC_EC(err);
  7583. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7584. /* test doing data in smaller chunks */
  7585. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7586. word32 dataLen = sizeof(plaintext2) - testLen;
  7587. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7588. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7589. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext2[testLen],
  7590. &generatedCiphertext[testLen], dataLen);
  7591. if (err != 0)
  7592. return WC_TEST_RET_ENC_EC(err);
  7593. testLen += dataLen;
  7594. }
  7595. #else
  7596. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext2, generatedCiphertext,
  7597. sizeof(plaintext2));
  7598. #endif
  7599. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7600. if (err != 0)
  7601. return WC_TEST_RET_ENC_EC(err);
  7602. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7603. if (err != 0)
  7604. return WC_TEST_RET_ENC_EC(err);
  7605. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7606. return WC_TEST_RET_ENC_NC;
  7607. }
  7608. /* Test 2 - Decrypt */
  7609. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7610. CHACHA20_POLY1305_AEAD_DECRYPT);
  7611. if (err != 0)
  7612. return WC_TEST_RET_ENC_EC(err);
  7613. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7614. if (err != 0)
  7615. return WC_TEST_RET_ENC_EC(err);
  7616. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7617. /* test doing data in smaller chunks */
  7618. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7619. word32 dataLen = sizeof(plaintext2) - testLen;
  7620. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7621. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7622. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7623. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7624. dataLen);
  7625. if (err != 0)
  7626. return WC_TEST_RET_ENC_EC(err);
  7627. testLen += dataLen;
  7628. }
  7629. #else
  7630. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7631. generatedPlaintext, sizeof(cipher2));
  7632. #endif
  7633. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7634. if (err != 0)
  7635. return WC_TEST_RET_ENC_EC(err);
  7636. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7637. if (err != 0)
  7638. return WC_TEST_RET_ENC_EC(err);
  7639. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7640. return WC_TEST_RET_ENC_NC;
  7641. }
  7642. return err;
  7643. }
  7644. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  7645. #ifndef NO_DES3
  7646. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void)
  7647. {
  7648. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  7649. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7650. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7651. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7652. };
  7653. byte plain[24];
  7654. byte cipher[24];
  7655. Des enc;
  7656. Des dec;
  7657. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  7658. {
  7659. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  7660. };
  7661. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  7662. {
  7663. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  7664. };
  7665. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  7666. {
  7667. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  7668. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  7669. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  7670. };
  7671. #ifdef WOLFSSL_DES_ECB
  7672. /* "Stay strong and move on!"" */
  7673. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7674. {
  7675. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7676. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7677. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7678. };
  7679. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb[] =
  7680. {
  7681. 0x70,0x4F,0x20,0xF6,0x72,0xB4,0xD0,0x2A,
  7682. 0xB5,0xA9,0x94,0x9F,0x11,0xCF,0x87,0xED,
  7683. 0x13,0x33,0x82,0xCB,0x8B,0xF1,0x82,0x56
  7684. };
  7685. /* "Lemmings" */
  7686. WOLFSSL_SMALL_STACK_STATIC const byte key_ecb[] =
  7687. {
  7688. 0x4C,0x65,0x6D,0x6D,0x69,0x6E,0x67,0x73
  7689. };
  7690. #endif /* WOLFSSL_DES_ECB */
  7691. wc_test_ret_t ret;
  7692. WOLFSSL_ENTER("des_test");
  7693. ret = wc_Des_SetKey(&enc, key, iv, DES_ENCRYPTION);
  7694. if (ret != 0)
  7695. return WC_TEST_RET_ENC_EC(ret);
  7696. ret = wc_Des_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7697. if (ret != 0)
  7698. return WC_TEST_RET_ENC_EC(ret);
  7699. ret = wc_Des_SetKey(&dec, key, iv, DES_DECRYPTION);
  7700. if (ret != 0)
  7701. return WC_TEST_RET_ENC_EC(ret);
  7702. ret = wc_Des_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7703. if (ret != 0)
  7704. return WC_TEST_RET_ENC_EC(ret);
  7705. if (XMEMCMP(plain, vector, sizeof(plain)))
  7706. return WC_TEST_RET_ENC_NC;
  7707. if (XMEMCMP(cipher, verify, sizeof(cipher)))
  7708. return WC_TEST_RET_ENC_NC;
  7709. ret = wc_Des_CbcEncryptWithKey(cipher, vector, sizeof(vector), key, iv);
  7710. if (ret != 0)
  7711. return WC_TEST_RET_ENC_EC(ret);
  7712. /* Test basic ECB Process for DES*/
  7713. #ifdef WOLFSSL_DES_ECB
  7714. ret = wc_Des_SetKey(&enc, key_ecb, iv, DES_ENCRYPTION);
  7715. if (ret != 0)
  7716. return WC_TEST_RET_ENC_EC(ret);
  7717. ret = wc_Des_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector));
  7718. if (ret != 0)
  7719. return WC_TEST_RET_ENC_EC(ret);
  7720. ret = wc_Des_SetKey(&dec, key_ecb, iv, DES_DECRYPTION);
  7721. if (ret != 0)
  7722. return WC_TEST_RET_ENC_EC(ret);
  7723. ret = wc_Des_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  7724. if (ret != 0)
  7725. return WC_TEST_RET_ENC_EC(ret);
  7726. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  7727. return WC_TEST_RET_ENC_NC;
  7728. if (XMEMCMP(cipher, verify_ecb, sizeof(cipher)))
  7729. return WC_TEST_RET_ENC_NC;
  7730. #endif /* WOLFSSL_DES_ECB */
  7731. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  7732. {
  7733. EncryptedInfo info;
  7734. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  7735. XMEMCPY(info.iv, iv, sizeof(iv));
  7736. info.ivSz = sizeof(iv);
  7737. info.keySz = sizeof(key);
  7738. info.cipherType = WC_CIPHER_DES;
  7739. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7740. sizeof(key), WC_HASH_TYPE_SHA);
  7741. if (ret != 0)
  7742. return WC_TEST_RET_ENC_EC(ret);
  7743. /* Test invalid info ptr */
  7744. ret = wc_BufferKeyEncrypt(NULL, cipher, sizeof(cipher), key,
  7745. sizeof(key), WC_HASH_TYPE_SHA);
  7746. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7747. return WC_TEST_RET_ENC_EC(ret);
  7748. #ifndef NO_PWDBASED
  7749. /* Test invalid hash type - only applies to wc_PBKDF1 call */
  7750. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7751. sizeof(key), WC_HASH_TYPE_NONE);
  7752. if (ret == 0)
  7753. return WC_TEST_RET_ENC_EC(ret);
  7754. #endif /* !NO_PWDBASED */
  7755. }
  7756. #endif
  7757. return 0;
  7758. }
  7759. #endif /* !NO_DES3 */
  7760. #ifndef NO_DES3
  7761. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void)
  7762. {
  7763. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  7764. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7765. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7766. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7767. };
  7768. byte plain[24];
  7769. byte cipher[24];
  7770. Des3 enc;
  7771. Des3 dec;
  7772. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  7773. {
  7774. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  7775. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  7776. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  7777. };
  7778. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  7779. {
  7780. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  7781. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  7782. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  7783. };
  7784. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] =
  7785. {
  7786. 0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
  7787. 0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
  7788. 0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
  7789. };
  7790. #ifdef WOLFSSL_DES_ECB
  7791. /* Stay strong and move on! */
  7792. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7793. {
  7794. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7795. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7796. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7797. };
  7798. WOLFSSL_SMALL_STACK_STATIC const byte verify3_ecb[] =
  7799. {
  7800. 0x45,0x7E,0xFA,0xA1,0x05,0xDD,0x48,0x86,
  7801. 0x4D,0xB2,0xAB,0xE4,0xF9,0x63,0xD6,0x54,
  7802. 0x7C,0x5A,0xB3,0x67,0x32,0x25,0x67,0x3D
  7803. };
  7804. /* "Life is what you make it" */
  7805. WOLFSSL_SMALL_STACK_STATIC const byte key3_ecb[] =
  7806. {
  7807. 0x4C,0x69,0x66,0x65,0x20,0x69,0x73,0x20,
  7808. 0x77,0x68,0x61,0x74,0x20,0x79,0x6F,0x75,
  7809. 0x20,0x6D,0x61,0x6B,0x65,0x20,0x69,0x74
  7810. };
  7811. #endif /* WOLFSSL_DES_ECB */
  7812. wc_test_ret_t ret;
  7813. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  7814. size_t i;
  7815. #endif
  7816. WOLFSSL_ENTER("des3_test");
  7817. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7818. if (ret != 0)
  7819. return WC_TEST_RET_ENC_EC(ret);
  7820. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7821. if (ret != 0)
  7822. return WC_TEST_RET_ENC_EC(ret);
  7823. ret = wc_Des3_SetKey(&enc, key3, iv3, DES_ENCRYPTION);
  7824. if (ret != 0)
  7825. return WC_TEST_RET_ENC_EC(ret);
  7826. ret = wc_Des3_SetKey(&dec, key3, iv3, DES_DECRYPTION);
  7827. if (ret != 0)
  7828. return WC_TEST_RET_ENC_EC(ret);
  7829. ret = wc_Des3_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7830. #if defined(WOLFSSL_ASYNC_CRYPT)
  7831. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  7832. #endif
  7833. if (ret != 0)
  7834. return WC_TEST_RET_ENC_EC(ret);
  7835. ret = wc_Des3_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7836. #if defined(WOLFSSL_ASYNC_CRYPT)
  7837. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  7838. #endif
  7839. if (ret != 0)
  7840. return WC_TEST_RET_ENC_EC(ret);
  7841. if (XMEMCMP(plain, vector, sizeof(plain)))
  7842. return WC_TEST_RET_ENC_NC;
  7843. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  7844. return WC_TEST_RET_ENC_NC;
  7845. /* Test basic ECB Process for DES3*/
  7846. #ifdef WOLFSSL_DES_ECB
  7847. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7848. if (ret != 0)
  7849. return WC_TEST_RET_ENC_EC(ret);
  7850. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7851. if (ret != 0)
  7852. return WC_TEST_RET_ENC_EC(ret);
  7853. ret = wc_Des3_SetKey(&enc, key3_ecb, NULL, DES_ENCRYPTION);
  7854. if (ret != 0)
  7855. return WC_TEST_RET_ENC_EC(ret);
  7856. ret = wc_Des3_SetKey(&dec, key3_ecb, NULL, DES_DECRYPTION);
  7857. if (ret != 0)
  7858. return WC_TEST_RET_ENC_EC(ret);
  7859. ret = wc_Des3_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector_ecb));
  7860. #if defined(WOLFSSL_ASYNC_CRYPT)
  7861. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  7862. #endif
  7863. if (ret != 0)
  7864. return WC_TEST_RET_ENC_EC(ret);
  7865. ret = wc_Des3_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  7866. #if defined(WOLFSSL_ASYNC_CRYPT)
  7867. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  7868. #endif
  7869. if (ret != 0)
  7870. return WC_TEST_RET_ENC_EC(ret);
  7871. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  7872. return WC_TEST_RET_ENC_NC;
  7873. if (XMEMCMP(cipher, verify3_ecb, sizeof(cipher)))
  7874. return WC_TEST_RET_ENC_NC;
  7875. #endif /* WOLFSSL_DES_ECB */
  7876. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  7877. /* test the same vectors with using compatibility layer */
  7878. for (i = 0; i < sizeof(vector); i += DES_BLOCK_SIZE){
  7879. DES_key_schedule ks1;
  7880. DES_key_schedule ks2;
  7881. DES_key_schedule ks3;
  7882. DES_cblock iv4;
  7883. byte tmp[sizeof(vector)];
  7884. XMEMCPY(ks1, key3, sizeof(DES_key_schedule));
  7885. XMEMCPY(ks2, key3 + 8, sizeof(DES_key_schedule));
  7886. XMEMCPY(ks3, key3 + 16, sizeof(DES_key_schedule));
  7887. XMEMSET(plain, 0, sizeof(plain));
  7888. XMEMSET(cipher, 0, sizeof(cipher));
  7889. /* Test in-place encrypt/decrypt */
  7890. XMEMCPY(tmp, vector, sizeof(vector));
  7891. /* Use i as the splitter */
  7892. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  7893. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  7894. &iv4, DES_ENCRYPT);
  7895. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i),
  7896. &ks1, &ks2, &ks3, &iv4, DES_ENCRYPT);
  7897. XMEMCPY(cipher, tmp, sizeof(cipher));
  7898. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  7899. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  7900. &iv4, DES_DECRYPT);
  7901. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i),
  7902. &ks1, &ks2, &ks3, &iv4, DES_DECRYPT);
  7903. XMEMCPY(plain, tmp, sizeof(plain));
  7904. if (XMEMCMP(plain, vector, sizeof(plain)))
  7905. return WC_TEST_RET_ENC_NC;
  7906. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  7907. return WC_TEST_RET_ENC_NC;
  7908. }
  7909. #endif /* OPENSSL_EXTRA */
  7910. wc_Des3Free(&enc);
  7911. wc_Des3Free(&dec);
  7912. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  7913. {
  7914. EncryptedInfo info;
  7915. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  7916. XMEMCPY(info.iv, iv3, sizeof(iv3));
  7917. info.ivSz = sizeof(iv3);
  7918. info.keySz = sizeof(key3);
  7919. info.cipherType = WC_CIPHER_DES3;
  7920. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key3,
  7921. sizeof(key3), WC_HASH_TYPE_SHA);
  7922. if (ret != 0)
  7923. return WC_TEST_RET_ENC_EC(ret);
  7924. }
  7925. #endif
  7926. return 0;
  7927. }
  7928. #endif /* NO_DES3 */
  7929. static const int fiducial1 = WC_TEST_RET_LN; /* source code reference point --
  7930. * see print_fiducials() below.
  7931. */
  7932. #ifndef NO_AES
  7933. #if defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_CFB) || \
  7934. defined(WOLFSSL_AES_XTS)
  7935. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  7936. && !defined(HAVE_SELFTEST)
  7937. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  7938. /* pass in the function, key, iv, plain text and expected and this function
  7939. * tests that the encryption and decryption is successful */
  7940. static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
  7941. const byte* iv, const byte* plain, int plainSz,
  7942. const byte* expected, int expectedSz)
  7943. {
  7944. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  7945. EVP_CIPHER_CTX *ctx = NULL;
  7946. #else
  7947. EVP_CIPHER_CTX ctx[1];
  7948. #endif
  7949. int ctx_inited = 0;
  7950. int idx, cipherSz;
  7951. wc_test_ret_t ret = 0;
  7952. byte* cipher;
  7953. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  7954. if ((ctx = wolfSSL_EVP_CIPHER_CTX_new()) == NULL)
  7955. return MEMORY_E;
  7956. #endif
  7957. cipher = (byte*)XMALLOC(plainSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7958. if (cipher == NULL) {
  7959. ret = WC_TEST_RET_ENC_ERRNO;
  7960. goto EVP_TEST_END;
  7961. }
  7962. /* test encrypt */
  7963. EVP_CIPHER_CTX_init(ctx);
  7964. ctx_inited = 1;
  7965. if (EVP_CipherInit(ctx, type, key, iv, 1) == 0) {
  7966. ret = WC_TEST_RET_ENC_NC;
  7967. goto EVP_TEST_END;
  7968. }
  7969. if (EVP_CipherUpdate(ctx, cipher, &idx, plain, expectedSz) == 0) {
  7970. ret = WC_TEST_RET_ENC_NC;
  7971. goto EVP_TEST_END;
  7972. }
  7973. cipherSz = idx;
  7974. if (EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  7975. ret = WC_TEST_RET_ENC_NC;
  7976. goto EVP_TEST_END;
  7977. }
  7978. cipherSz += idx;
  7979. if (XMEMCMP(cipher, expected, plainSz)) {
  7980. ret = WC_TEST_RET_ENC_NC;
  7981. goto EVP_TEST_END;
  7982. }
  7983. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  7984. ctx_inited = 0;
  7985. if (ret == WOLFSSL_SUCCESS)
  7986. ret = 0;
  7987. else {
  7988. ret = WC_TEST_RET_ENC_NC;
  7989. goto EVP_TEST_END;
  7990. }
  7991. /* test decrypt */
  7992. EVP_CIPHER_CTX_init(ctx);
  7993. ctx_inited = 1;
  7994. if (EVP_CipherInit(ctx, type, key, iv, 0) == 0) {
  7995. ret = WC_TEST_RET_ENC_NC;
  7996. goto EVP_TEST_END;
  7997. }
  7998. if (EVP_CipherUpdate(ctx, cipher, &idx, cipher, expectedSz) == 0) {
  7999. ret = WC_TEST_RET_ENC_NC;
  8000. goto EVP_TEST_END;
  8001. }
  8002. cipherSz = idx;
  8003. if (EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8004. ret = WC_TEST_RET_ENC_NC;
  8005. goto EVP_TEST_END;
  8006. }
  8007. cipherSz += idx;
  8008. if ((expectedSz != cipherSz) || XMEMCMP(plain, cipher, plainSz)) {
  8009. ret = WC_TEST_RET_ENC_NC;
  8010. goto EVP_TEST_END;
  8011. }
  8012. EVP_TEST_END:
  8013. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8014. (void)cipherSz;
  8015. if (ctx_inited) {
  8016. int cleanup_ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8017. if (cleanup_ret != WOLFSSL_SUCCESS)
  8018. ret = WC_TEST_RET_ENC_NC;
  8019. }
  8020. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8021. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  8022. #endif
  8023. return ret;
  8024. }
  8025. #endif /* !HAVE_FIPS || FIPS_VERSION3_GE(6,0,0) */
  8026. #endif /* OPENSSL_EXTRA && !WOLFCRYPT_ONLY && !HAVE_SELFTEST */
  8027. #endif /* WOLFSSL_AES_OFB || WOLFSSL_AES_CFB */
  8028. #ifdef WOLFSSL_AES_OFB
  8029. /* test vector from https://csrc.nist.gov/Projects/cryptographic-algorithm-validation-program/Block-Ciphers */
  8030. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void)
  8031. {
  8032. #ifdef WOLFSSL_AES_256
  8033. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8034. {
  8035. 0xc4,0xc7,0xfa,0xd6,0x53,0x5c,0xb8,0x71,
  8036. 0x4a,0x5c,0x40,0x77,0x9a,0x8b,0xa1,0xd2,
  8037. 0x53,0x3e,0x23,0xb4,0xb2,0x58,0x73,0x2a,
  8038. 0x5b,0x78,0x01,0xf4,0xe3,0x71,0xa7,0x94
  8039. };
  8040. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  8041. {
  8042. 0x5e,0xb9,0x33,0x13,0xb8,0x71,0xff,0x16,
  8043. 0xb9,0x8a,0x9b,0xcb,0x43,0x33,0x0d,0x6f
  8044. };
  8045. WOLFSSL_SMALL_STACK_STATIC const byte plain1[] =
  8046. {
  8047. 0x6d,0x0b,0xb0,0x79,0x63,0x84,0x71,0xe9,
  8048. 0x39,0xd4,0x53,0x14,0x86,0xc1,0x4c,0x25,
  8049. 0x9a,0xee,0xc6,0xf3,0xc0,0x0d,0xfd,0xd6,
  8050. 0xc0,0x50,0xa8,0xba,0xa8,0x20,0xdb,0x71,
  8051. 0xcc,0x12,0x2c,0x4e,0x0c,0x17,0x15,0xef,
  8052. 0x55,0xf3,0x99,0x5a,0x6b,0xf0,0x2a,0x4c
  8053. };
  8054. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8055. {
  8056. 0x0f,0x54,0x61,0x71,0x59,0xd0,0x3f,0xfc,
  8057. 0x1b,0xfa,0xfb,0x60,0x29,0x30,0xd7,0x00,
  8058. 0xf4,0xa4,0xa8,0xe6,0xdd,0x93,0x94,0x46,
  8059. 0x64,0xd2,0x19,0xc4,0xc5,0x4d,0xde,0x1b,
  8060. 0x04,0x53,0xe1,0x73,0xf5,0x18,0x74,0xae,
  8061. 0xfd,0x64,0xa2,0xe1,0xe2,0x76,0x13,0xb0
  8062. };
  8063. #endif /* WOLFSSL_AES_256 */
  8064. #ifdef WOLFSSL_AES_128
  8065. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8066. {
  8067. 0x10,0xa5,0x88,0x69,0xd7,0x4b,0xe5,0xa3,
  8068. 0x74,0xcf,0x86,0x7c,0xfb,0x47,0x38,0x59
  8069. };
  8070. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  8071. {
  8072. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8073. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8074. };
  8075. WOLFSSL_SMALL_STACK_STATIC const byte plain2[] =
  8076. {
  8077. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8078. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8079. };
  8080. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8081. {
  8082. 0x6d,0x25,0x1e,0x69,0x44,0xb0,0x51,0xe0,
  8083. 0x4e,0xaa,0x6f,0xb4,0xdb,0xf7,0x84,0x65
  8084. };
  8085. #endif /* WOLFSSL_AES_128 */
  8086. #ifdef WOLFSSL_AES_192
  8087. WOLFSSL_SMALL_STACK_STATIC const byte key3[] = {
  8088. 0xd0,0x77,0xa0,0x3b,0xd8,0xa3,0x89,0x73,
  8089. 0x92,0x8c,0xca,0xfe,0x4a,0x9d,0x2f,0x45,
  8090. 0x51,0x30,0xbd,0x0a,0xf5,0xae,0x46,0xa9
  8091. };
  8092. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  8093. {
  8094. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8095. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8096. };
  8097. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8098. {
  8099. 0xab,0xc7,0x86,0xfb,0x1e,0xdb,0x50,0x45,
  8100. 0x80,0xc4,0xd8,0x82,0xef,0x29,0xa0,0xc7
  8101. };
  8102. WOLFSSL_SMALL_STACK_STATIC const byte plain3[] =
  8103. {
  8104. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8105. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8106. };
  8107. #endif /* WOLFSSL_AES_192 */
  8108. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8109. Aes *enc = NULL;
  8110. #else
  8111. Aes enc[1];
  8112. #endif
  8113. byte cipher[AES_BLOCK_SIZE * 4];
  8114. #ifdef HAVE_AES_DECRYPT
  8115. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8116. Aes *dec = NULL;
  8117. #else
  8118. Aes dec[1];
  8119. #endif
  8120. byte plain [AES_BLOCK_SIZE * 4];
  8121. #endif
  8122. wc_test_ret_t ret = 0;
  8123. WOLFSSL_ENTER("aesofb_test");
  8124. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8125. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8126. ERROR_OUT(-1, out);
  8127. #ifdef HAVE_AES_DECRYPT
  8128. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8129. ERROR_OUT(-1, out);
  8130. #endif
  8131. #endif
  8132. XMEMSET(enc, 0, sizeof *enc);
  8133. #ifdef HAVE_AES_DECRYPT
  8134. XMEMSET(dec, 0, sizeof *dec);
  8135. #endif
  8136. #ifdef WOLFSSL_AES_128
  8137. /* 128 key size test */
  8138. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8139. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8140. ret = EVP_test(EVP_aes_128_ofb(), key2, iv2, plain2, sizeof(plain2),
  8141. cipher2, sizeof(cipher2));
  8142. if (ret != 0) {
  8143. goto out;
  8144. }
  8145. #endif
  8146. ret = wc_AesInit(enc, HEAP_HINT, INVALID_DEVID);
  8147. if (ret != 0)
  8148. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8149. #ifdef HAVE_AES_DECRYPT
  8150. ret = wc_AesInit(dec, HEAP_HINT, INVALID_DEVID);
  8151. if (ret != 0)
  8152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8153. #endif
  8154. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8155. if (ret != 0)
  8156. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8157. #ifdef HAVE_AES_DECRYPT
  8158. /* decrypt uses AES_ENCRYPTION */
  8159. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8160. if (ret != 0)
  8161. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8162. #endif
  8163. XMEMSET(cipher, 0, sizeof(cipher));
  8164. ret = wc_AesOfbEncrypt(enc, cipher, plain2, AES_BLOCK_SIZE);
  8165. if (ret != 0)
  8166. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8167. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE))
  8168. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8169. #ifdef HAVE_AES_DECRYPT
  8170. ret = wc_AesOfbDecrypt(dec, plain, cipher2, AES_BLOCK_SIZE);
  8171. if (ret != 0)
  8172. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8173. if (XMEMCMP(plain, plain2, AES_BLOCK_SIZE))
  8174. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8175. #endif /* HAVE_AES_DECRYPT */
  8176. #endif /* WOLFSSL_AES_128 */
  8177. #ifdef WOLFSSL_AES_192
  8178. /* 192 key size test */
  8179. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8180. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8181. ret = EVP_test(EVP_aes_192_ofb(), key3, iv3, plain3, sizeof(plain3),
  8182. cipher3, sizeof(cipher3));
  8183. if (ret != 0) {
  8184. goto out;
  8185. }
  8186. #endif
  8187. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8188. if (ret != 0)
  8189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8190. #ifdef HAVE_AES_DECRYPT
  8191. /* decrypt uses AES_ENCRYPTION */
  8192. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8193. if (ret != 0)
  8194. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8195. #endif
  8196. XMEMSET(cipher, 0, sizeof(cipher));
  8197. ret = wc_AesOfbEncrypt(enc, cipher, plain3, AES_BLOCK_SIZE);
  8198. if (ret != 0)
  8199. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8200. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE))
  8201. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8202. #ifdef HAVE_AES_DECRYPT
  8203. ret = wc_AesOfbDecrypt(dec, plain, cipher3, AES_BLOCK_SIZE);
  8204. if (ret != 0)
  8205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8206. if (XMEMCMP(plain, plain3, AES_BLOCK_SIZE))
  8207. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8208. #endif /* HAVE_AES_DECRYPT */
  8209. #endif /* WOLFSSL_AES_192 */
  8210. #ifdef WOLFSSL_AES_256
  8211. /* 256 key size test */
  8212. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8213. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8214. ret = EVP_test(EVP_aes_256_ofb(), key1, iv1, plain1, sizeof(plain1),
  8215. cipher1, sizeof(cipher1));
  8216. if (ret != 0) {
  8217. goto out;
  8218. }
  8219. #endif
  8220. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8221. if (ret != 0)
  8222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8223. #ifdef HAVE_AES_DECRYPT
  8224. /* decrypt uses AES_ENCRYPTION */
  8225. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8226. if (ret != 0)
  8227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8228. #endif
  8229. XMEMSET(cipher, 0, sizeof(cipher));
  8230. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE);
  8231. if (ret != 0)
  8232. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8233. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE))
  8234. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8235. ret = wc_AesOfbEncrypt(enc, cipher + AES_BLOCK_SIZE,
  8236. plain1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8237. if (ret != 0)
  8238. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8239. if (XMEMCMP(cipher + AES_BLOCK_SIZE, cipher1 + AES_BLOCK_SIZE,
  8240. AES_BLOCK_SIZE))
  8241. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8242. #ifdef HAVE_AES_DECRYPT
  8243. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE);
  8244. if (ret != 0)
  8245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8246. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE))
  8247. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8248. ret = wc_AesOfbDecrypt(dec, plain + AES_BLOCK_SIZE,
  8249. cipher1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8250. if (ret != 0)
  8251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8252. if (XMEMCMP(plain + AES_BLOCK_SIZE, plain1 + AES_BLOCK_SIZE,
  8253. AES_BLOCK_SIZE))
  8254. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8255. #endif /* HAVE_AES_DECRYPT */
  8256. /* multiple blocks at once */
  8257. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8258. if (ret != 0)
  8259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8260. #ifdef HAVE_AES_DECRYPT
  8261. /* decrypt uses AES_ENCRYPTION */
  8262. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8263. if (ret != 0)
  8264. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8265. #endif
  8266. XMEMSET(cipher, 0, sizeof(cipher));
  8267. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE * 3);
  8268. if (ret != 0)
  8269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8270. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 3))
  8271. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8272. #ifdef HAVE_AES_DECRYPT
  8273. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE * 3);
  8274. if (ret != 0)
  8275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8276. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE * 3))
  8277. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8278. #endif /* HAVE_AES_DECRYPT */
  8279. /* inline decrypt/encrypt*/
  8280. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8281. if (ret != 0)
  8282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8283. #ifdef HAVE_AES_DECRYPT
  8284. /* decrypt uses AES_ENCRYPTION */
  8285. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8286. if (ret != 0)
  8287. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8288. #endif
  8289. XMEMCPY(cipher, plain1, AES_BLOCK_SIZE * 2);
  8290. ret = wc_AesOfbEncrypt(enc, cipher, cipher, AES_BLOCK_SIZE * 2);
  8291. if (ret != 0)
  8292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8293. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8295. #ifdef HAVE_AES_DECRYPT
  8296. ret = wc_AesOfbDecrypt(dec, cipher, cipher, AES_BLOCK_SIZE * 2);
  8297. if (ret != 0)
  8298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8299. if (XMEMCMP(cipher, plain1, AES_BLOCK_SIZE * 2))
  8300. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8301. #endif /* HAVE_AES_DECRYPT */
  8302. /* 256 key size test leftover support */
  8303. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8304. if (ret != 0)
  8305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8306. #ifdef HAVE_AES_DECRYPT
  8307. /* decrypt uses AES_ENCRYPTION */
  8308. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8309. if (ret != 0)
  8310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8311. #endif
  8312. XMEMSET(cipher, 0, sizeof(cipher));
  8313. ret = wc_AesOfbEncrypt(enc, cipher, plain1, 3);
  8314. if (ret != 0)
  8315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8316. if (XMEMCMP(cipher, cipher1, 3))
  8317. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8318. ret = wc_AesOfbEncrypt(enc, cipher + 3, plain1 + 3, AES_BLOCK_SIZE);
  8319. if (ret != 0)
  8320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8321. if (XMEMCMP(cipher + 3, cipher1 + 3, AES_BLOCK_SIZE))
  8322. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8323. #ifdef HAVE_AES_DECRYPT
  8324. ret = wc_AesOfbDecrypt(dec, plain, cipher1, 6);
  8325. if (ret != 0)
  8326. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8327. if (XMEMCMP(plain, plain1, 6))
  8328. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8329. ret = wc_AesOfbDecrypt(dec, plain + 6, cipher1 + 6, AES_BLOCK_SIZE);
  8330. if (ret != 0)
  8331. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8332. if (XMEMCMP(plain + 6, plain1 + 6, AES_BLOCK_SIZE))
  8333. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8334. #endif /* HAVE_AES_DECRYPT */
  8335. out:
  8336. wc_AesFree(enc);
  8337. #ifdef HAVE_AES_DECRYPT
  8338. wc_AesFree(dec);
  8339. #endif
  8340. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8341. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  8342. #ifdef HAVE_AES_DECRYPT
  8343. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  8344. #endif
  8345. #endif
  8346. #endif /* WOLFSSL_AES_256 */
  8347. return ret;
  8348. }
  8349. #endif /* WOLFSSL_AES_OFB */
  8350. #if defined(WOLFSSL_AES_CFB)
  8351. /* Test cases from NIST SP 800-38A, Recommendation for Block Cipher Modes of
  8352. * Operation Methods and Techniques
  8353. */
  8354. static wc_test_ret_t aescfb_test_0(void)
  8355. {
  8356. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8357. Aes *enc = NULL;
  8358. #else
  8359. Aes enc[1];
  8360. #endif
  8361. int enc_inited = 0;
  8362. byte cipher[AES_BLOCK_SIZE * 4];
  8363. #ifdef HAVE_AES_DECRYPT
  8364. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8365. Aes *dec = NULL;
  8366. #else
  8367. Aes dec[1];
  8368. #endif
  8369. int dec_inited = 0;
  8370. byte plain [AES_BLOCK_SIZE * 4];
  8371. #endif
  8372. wc_test_ret_t ret = 0;
  8373. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8374. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  8375. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  8376. };
  8377. #ifdef WOLFSSL_AES_128
  8378. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8379. {
  8380. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  8381. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  8382. };
  8383. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8384. {
  8385. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  8386. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  8387. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  8388. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b,
  8389. 0x26,0x75,0x1f,0x67,0xa3,0xcb,0xb1,0x40,
  8390. 0xb1,0x80,0x8c,0xf1,0x87,0xa4,0xf4,0xdf
  8391. };
  8392. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8393. {
  8394. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8395. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8396. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8397. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8398. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8399. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef
  8400. };
  8401. #endif /* WOLFSSL_AES_128 */
  8402. #ifdef WOLFSSL_AES_192
  8403. /* 192 size key test */
  8404. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8405. {
  8406. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  8407. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  8408. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  8409. };
  8410. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8411. {
  8412. 0xcd,0xc8,0x0d,0x6f,0xdd,0xf1,0x8c,0xab,
  8413. 0x34,0xc2,0x59,0x09,0xc9,0x9a,0x41,0x74,
  8414. 0x67,0xce,0x7f,0x7f,0x81,0x17,0x36,0x21,
  8415. 0x96,0x1a,0x2b,0x70,0x17,0x1d,0x3d,0x7a,
  8416. 0x2e,0x1e,0x8a,0x1d,0xd5,0x9b,0x88,0xb1,
  8417. 0xc8,0xe6,0x0f,0xed,0x1e,0xfa,0xc4,0xc9,
  8418. 0xc0,0x5f,0x9f,0x9c,0xa9,0x83,0x4f,0xa0,
  8419. 0x42,0xae,0x8f,0xba,0x58,0x4b,0x09,0xff
  8420. };
  8421. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8422. {
  8423. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8424. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8425. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8426. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8427. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8428. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8429. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8430. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8431. };
  8432. #endif /* WOLFSSL_AES_192 */
  8433. #ifdef WOLFSSL_AES_256
  8434. /* 256 size key simple test */
  8435. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8436. {
  8437. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  8438. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  8439. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  8440. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  8441. };
  8442. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8443. {
  8444. 0xdc,0x7e,0x84,0xbf,0xda,0x79,0x16,0x4b,
  8445. 0x7e,0xcd,0x84,0x86,0x98,0x5d,0x38,0x60,
  8446. 0x39,0xff,0xed,0x14,0x3b,0x28,0xb1,0xc8,
  8447. 0x32,0x11,0x3c,0x63,0x31,0xe5,0x40,0x7b,
  8448. 0xdf,0x10,0x13,0x24,0x15,0xe5,0x4b,0x92,
  8449. 0xa1,0x3e,0xd0,0xa8,0x26,0x7a,0xe2,0xf9,
  8450. 0x75,0xa3,0x85,0x74,0x1a,0xb9,0xce,0xf8,
  8451. 0x20,0x31,0x62,0x3d,0x55,0xb1,0xe4,0x71
  8452. };
  8453. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8454. {
  8455. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8456. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8457. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8458. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8459. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8460. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8461. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8462. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8463. };
  8464. #endif /* WOLFSSL_AES_256 */
  8465. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8466. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8467. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8468. #ifdef HAVE_AES_DECRYPT
  8469. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8470. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8471. #endif
  8472. #endif
  8473. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8474. if (ret != 0)
  8475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8476. else
  8477. enc_inited = 1;
  8478. #ifdef HAVE_AES_DECRYPT
  8479. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8480. if (ret != 0)
  8481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8482. else
  8483. dec_inited = 1;
  8484. #endif
  8485. #ifdef WOLFSSL_AES_128
  8486. /* 128 key tests */
  8487. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8488. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8489. ret = EVP_test(EVP_aes_128_cfb128(), key1, iv, msg1, sizeof(msg1),
  8490. cipher1, sizeof(cipher1));
  8491. if (ret != 0) {
  8492. return ret;
  8493. }
  8494. #endif
  8495. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8496. if (ret != 0)
  8497. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8498. #ifdef HAVE_AES_DECRYPT
  8499. /* decrypt uses AES_ENCRYPTION */
  8500. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8501. if (ret != 0)
  8502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8503. #endif
  8504. XMEMSET(cipher, 0, sizeof(cipher));
  8505. ret = wc_AesCfbEncrypt(enc, cipher, msg1, AES_BLOCK_SIZE * 2);
  8506. if (ret != 0)
  8507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8508. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8509. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8510. /* test restarting encryption process */
  8511. ret = wc_AesCfbEncrypt(enc, cipher + (AES_BLOCK_SIZE * 2),
  8512. msg1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE);
  8513. if (ret != 0)
  8514. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8515. if (XMEMCMP(cipher + (AES_BLOCK_SIZE * 2),
  8516. cipher1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE))
  8517. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8518. #ifdef HAVE_AES_DECRYPT
  8519. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 3);
  8520. if (ret != 0)
  8521. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8522. if (XMEMCMP(plain, msg1, AES_BLOCK_SIZE * 3))
  8523. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8524. #endif /* HAVE_AES_DECRYPT */
  8525. #endif /* WOLFSSL_AES_128 */
  8526. #ifdef WOLFSSL_AES_192
  8527. /* 192 key size test */
  8528. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8529. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8530. ret = EVP_test(EVP_aes_192_cfb128(), key2, iv, msg2, sizeof(msg2),
  8531. cipher2, sizeof(cipher2));
  8532. if (ret != 0) {
  8533. return ret;
  8534. }
  8535. #endif
  8536. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8537. if (ret != 0)
  8538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8539. #ifdef HAVE_AES_DECRYPT
  8540. /* decrypt uses AES_ENCRYPTION */
  8541. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8542. if (ret != 0)
  8543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8544. #endif
  8545. XMEMSET(cipher, 0, sizeof(cipher));
  8546. ret = wc_AesCfbEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE * 4);
  8547. if (ret != 0)
  8548. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8549. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE * 4))
  8550. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8551. #ifdef HAVE_AES_DECRYPT
  8552. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 4);
  8553. if (ret != 0)
  8554. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8555. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE * 4))
  8556. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8557. #endif /* HAVE_AES_DECRYPT */
  8558. #endif /* WOLFSSL_AES_192 */
  8559. #ifdef WOLFSSL_AES_256
  8560. /* 256 key size test */
  8561. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8562. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8563. ret = EVP_test(EVP_aes_256_cfb128(), key3, iv, msg3, sizeof(msg3),
  8564. cipher3, sizeof(cipher3));
  8565. if (ret != 0) {
  8566. return ret;
  8567. }
  8568. #endif
  8569. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8570. if (ret != 0)
  8571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8572. #ifdef HAVE_AES_DECRYPT
  8573. /* decrypt uses AES_ENCRYPTION */
  8574. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8575. if (ret != 0)
  8576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8577. #endif
  8578. /* test with data left overs, magic lengths are checking near edges */
  8579. XMEMSET(cipher, 0, sizeof(cipher));
  8580. ret = wc_AesCfbEncrypt(enc, cipher, msg3, 4);
  8581. if (ret != 0)
  8582. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8583. if (XMEMCMP(cipher, cipher3, 4))
  8584. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8585. ret = wc_AesCfbEncrypt(enc, cipher + 4, msg3 + 4, 27);
  8586. if (ret != 0)
  8587. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8588. if (XMEMCMP(cipher + 4, cipher3 + 4, 27))
  8589. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8590. ret = wc_AesCfbEncrypt(enc, cipher + 31, msg3 + 31,
  8591. (AES_BLOCK_SIZE * 4) - 31);
  8592. if (ret != 0)
  8593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8594. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE * 4))
  8595. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8596. #ifdef HAVE_AES_DECRYPT
  8597. ret = wc_AesCfbDecrypt(dec, plain, cipher, 4);
  8598. if (ret != 0)
  8599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8600. if (XMEMCMP(plain, msg3, 4))
  8601. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8602. ret = wc_AesCfbDecrypt(dec, plain + 4, cipher + 4, 4);
  8603. if (ret != 0)
  8604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8605. ret = wc_AesCfbDecrypt(dec, plain + 8, cipher + 8, 23);
  8606. if (ret != 0)
  8607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8608. if (XMEMCMP(plain + 4, msg3 + 4, 27))
  8609. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8610. ret = wc_AesCfbDecrypt(dec, plain + 31, cipher + 31,
  8611. (AES_BLOCK_SIZE * 4) - 31);
  8612. if (ret != 0)
  8613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8614. if (XMEMCMP(plain, msg3, AES_BLOCK_SIZE * 4))
  8615. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8616. #endif /* HAVE_AES_DECRYPT */
  8617. #endif /* WOLFSSL_AES_256 */
  8618. out:
  8619. if (enc_inited)
  8620. wc_AesFree(enc);
  8621. #ifdef HAVE_AES_DECRYPT
  8622. if (dec_inited)
  8623. wc_AesFree(dec);
  8624. #endif
  8625. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8626. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  8627. #ifdef HAVE_AES_DECRYPT
  8628. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  8629. #endif
  8630. #endif
  8631. return ret;
  8632. }
  8633. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0))
  8634. static wc_test_ret_t aescfb1_test(void)
  8635. {
  8636. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8637. Aes *enc = NULL;
  8638. #else
  8639. Aes enc[1];
  8640. #endif
  8641. int enc_inited = 0;
  8642. byte cipher[AES_BLOCK_SIZE];
  8643. #ifdef HAVE_AES_DECRYPT
  8644. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8645. Aes *dec = NULL;
  8646. #else
  8647. Aes dec[1];
  8648. #endif
  8649. int dec_inited = 0;
  8650. byte plain [AES_BLOCK_SIZE];
  8651. #endif
  8652. wc_test_ret_t ret = 0;
  8653. #ifdef WOLFSSL_AES_128
  8654. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8655. 0x4d,0xbb,0xdc,0xaa,0x59,0xf3,0x63,0xc9,
  8656. 0x2a,0x3b,0x98,0x43,0xad,0x20,0xe2,0xb7
  8657. };
  8658. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8659. {
  8660. 0xcd,0xef,0x9d,0x06,0x61,0xba,0xe4,0x73,
  8661. 0x8d,0x1a,0x58,0xa2,0xa6,0x22,0x8b,0x66
  8662. };
  8663. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8664. {
  8665. 0x00
  8666. };
  8667. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8668. {
  8669. 0xC0
  8670. };
  8671. WOLFSSL_SMALL_STACK_STATIC const byte cipher1_7bit[] =
  8672. {
  8673. 0x1C
  8674. };
  8675. #endif /* WOLFSSL_AES_128 */
  8676. #ifdef WOLFSSL_AES_192
  8677. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  8678. 0x57,0xc6,0x89,0x7c,0x99,0x52,0x28,0x13,
  8679. 0xbf,0x67,0x9c,0xe1,0x13,0x70,0xaf,0x5e
  8680. };
  8681. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8682. {
  8683. 0xba,0xa1,0x58,0xa1,0x6b,0x50,0x4a,0x10,
  8684. 0x8e,0xd4,0x33,0x2e,0xe7,0xf2,0x9b,0xf6,
  8685. 0xd1,0xac,0x46,0xa8,0xde,0x5a,0xfe,0x7a
  8686. };
  8687. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8688. {
  8689. 0x30
  8690. };
  8691. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8692. {
  8693. 0x80
  8694. };
  8695. #endif /* WOLFSSL_AES_192 */
  8696. #ifdef WOLFSSL_AES_256
  8697. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  8698. 0x63,0x2e,0x9f,0x83,0x1f,0xa3,0x80,0x5e,
  8699. 0x52,0x02,0xbc,0xe0,0x6d,0x04,0xf9,0xa0
  8700. };
  8701. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8702. {
  8703. 0xf6,0xfa,0xe4,0xf1,0x5d,0x91,0xfc,0x50,
  8704. 0x88,0x78,0x4f,0x84,0xa5,0x37,0x12,0x7e,
  8705. 0x32,0x63,0x55,0x9c,0x62,0x73,0x88,0x20,
  8706. 0xc2,0xcf,0x3d,0xe1,0x1c,0x2a,0x30,0x40
  8707. };
  8708. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8709. {
  8710. 0xF7, 0x00
  8711. };
  8712. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8713. {
  8714. 0x41, 0xC0
  8715. };
  8716. #endif /* WOLFSSL_AES_256 */
  8717. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8718. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8719. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8720. #ifdef HAVE_AES_DECRYPT
  8721. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8722. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8723. #endif
  8724. #endif
  8725. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8726. if (ret != 0)
  8727. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8728. else
  8729. enc_inited = 1;
  8730. #ifdef HAVE_AES_DECRYPT
  8731. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8732. if (ret != 0)
  8733. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8734. else
  8735. dec_inited = 1;
  8736. #endif
  8737. #ifdef WOLFSSL_AES_128
  8738. /* 128 key tests */
  8739. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8740. if (ret != 0)
  8741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8742. #ifdef HAVE_AES_DECRYPT
  8743. /* decrypt uses AES_ENCRYPTION */
  8744. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8745. if (ret != 0)
  8746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8747. #endif
  8748. XMEMSET(cipher, 0, sizeof(cipher));
  8749. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 2);
  8750. if (ret != 0)
  8751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8752. if (cipher[0] != cipher1[0])
  8753. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8754. #ifdef HAVE_AES_DECRYPT
  8755. ret = wc_AesCfb1Decrypt(dec, plain, cipher, 2);
  8756. if (ret != 0)
  8757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8758. if (plain[0] != msg1[0])
  8759. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8760. #endif /* HAVE_AES_DECRYPT */
  8761. XMEMSET(cipher, 0, sizeof(cipher));
  8762. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 7);
  8763. if (ret != 0)
  8764. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8765. if (cipher[0] != cipher1_7bit[0])
  8766. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8767. #ifdef OPENSSL_EXTRA
  8768. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8769. if (ret != 0)
  8770. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8771. XMEMSET(cipher, 0, sizeof(cipher));
  8772. ret = wc_AesCfb1Encrypt(enc, cipher, msg1,
  8773. sizeof(msg1) * WOLFSSL_BIT_SIZE);
  8774. if (ret != 0)
  8775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8776. #ifndef WOLFCRYPT_ONLY
  8777. ret = EVP_test(EVP_aes_128_cfb1(), key1, iv, msg1, sizeof(msg1),
  8778. cipher, sizeof(msg1));
  8779. if (ret != 0) {
  8780. goto out;
  8781. }
  8782. #endif
  8783. #endif
  8784. #endif /* WOLFSSL_AES_128 */
  8785. #ifdef WOLFSSL_AES_192
  8786. /* 192 key tests */
  8787. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8788. if (ret != 0)
  8789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8790. XMEMSET(cipher, 0, sizeof(cipher));
  8791. ret = wc_AesCfb1Encrypt(enc, cipher, msg2, 4);
  8792. if (ret != 0)
  8793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8794. if (XMEMCMP(cipher, cipher2, sizeof(cipher2)) != 0)
  8795. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8796. #ifdef OPENSSL_EXTRA
  8797. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8798. if (ret != 0)
  8799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8800. XMEMSET(cipher, 0, sizeof(cipher));
  8801. ret = wc_AesCfb1Encrypt(enc, cipher, msg2,
  8802. sizeof(msg2) * WOLFSSL_BIT_SIZE);
  8803. if (ret != 0)
  8804. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8805. #ifndef WOLFCRYPT_ONLY
  8806. ret = EVP_test(EVP_aes_192_cfb1(), key2, iv2, msg2, sizeof(msg2),
  8807. cipher, sizeof(msg2));
  8808. if (ret != 0) {
  8809. goto out;
  8810. }
  8811. #endif
  8812. #endif
  8813. #endif /* WOLFSSL_AES_192 */
  8814. #ifdef WOLFSSL_AES_256
  8815. /* 256 key tests */
  8816. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8817. if (ret != 0)
  8818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8819. XMEMSET(cipher, 0, sizeof(cipher));
  8820. ret = wc_AesCfb1Encrypt(enc, cipher, msg3, 10);
  8821. if (ret != 0)
  8822. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8823. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  8824. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8825. #ifdef OPENSSL_EXTRA
  8826. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8827. if (ret != 0)
  8828. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8829. XMEMSET(cipher, 0, sizeof(cipher));
  8830. ret = wc_AesCfb1Encrypt(enc, cipher, msg3,
  8831. sizeof(msg3) * WOLFSSL_BIT_SIZE);
  8832. if (ret != 0)
  8833. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8834. #ifndef WOLFCRYPT_ONLY
  8835. ret = EVP_test(EVP_aes_256_cfb1(), key3, iv3, msg3, sizeof(msg3),
  8836. cipher, sizeof(msg3));
  8837. if (ret != 0) {
  8838. goto out;
  8839. }
  8840. #endif
  8841. #endif
  8842. #endif /* WOLFSSL_AES_256 */
  8843. out:
  8844. if (enc_inited)
  8845. wc_AesFree(enc);
  8846. #ifdef HAVE_AES_DECRYPT
  8847. if (dec_inited)
  8848. wc_AesFree(dec);
  8849. #endif
  8850. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8851. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  8852. #ifdef HAVE_AES_DECRYPT
  8853. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  8854. #endif
  8855. #endif
  8856. return ret;
  8857. }
  8858. static wc_test_ret_t aescfb8_test(void)
  8859. {
  8860. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8861. Aes *enc = NULL;
  8862. #else
  8863. Aes enc[1];
  8864. #endif
  8865. int enc_inited = 0;
  8866. byte cipher[AES_BLOCK_SIZE];
  8867. #ifdef HAVE_AES_DECRYPT
  8868. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8869. Aes *dec = NULL;
  8870. #else
  8871. Aes dec[1];
  8872. #endif
  8873. int dec_inited = 0;
  8874. byte plain [AES_BLOCK_SIZE];
  8875. #endif
  8876. wc_test_ret_t ret = 0;
  8877. #ifdef WOLFSSL_AES_128
  8878. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8879. 0xf4,0x75,0xc6,0x49,0x91,0xb2,0x0e,0xae,
  8880. 0xe1,0x83,0xa2,0x26,0x29,0xe2,0x1e,0x22
  8881. };
  8882. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8883. {
  8884. 0xc8,0xfe,0x9b,0xf7,0x7b,0x93,0x0f,0x46,
  8885. 0xd2,0x07,0x8b,0x8c,0x0e,0x65,0x7c,0xd4
  8886. };
  8887. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8888. {
  8889. 0xd2,0x76,0x91
  8890. };
  8891. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8892. {
  8893. 0xc9,0x06,0x35
  8894. };
  8895. #endif /* WOLFSSL_AES_128 */
  8896. #ifdef WOLFSSL_AES_192
  8897. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  8898. 0x0a,0x02,0x84,0x6b,0x62,0xab,0xb6,0x93,
  8899. 0xef,0x31,0xd7,0x54,0x84,0x2e,0xed,0x29
  8900. };
  8901. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8902. {
  8903. 0xba,0xf0,0x8b,0x76,0x31,0x7a,0x65,0xc5,
  8904. 0xf0,0x7a,0xe6,0xf5,0x7e,0xb0,0xe6,0x54,
  8905. 0x88,0x65,0x93,0x24,0xd2,0x97,0x09,0xe3
  8906. };
  8907. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8908. {
  8909. 0x72,0x9c,0x0b,0x6d,0xeb,0x75,0xfa,0x6e,
  8910. 0xb5,0xe8
  8911. };
  8912. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8913. {
  8914. 0x98,0x95,0x93,0x24,0x02,0x39,0x3d,0xc3,
  8915. 0x3a,0x60
  8916. };
  8917. #endif
  8918. #ifdef WOLFSSL_AES_256
  8919. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  8920. 0x33,0x8c,0x55,0x2f,0xf1,0xec,0xa1,0x44,
  8921. 0x08,0xe0,0x5d,0x8c,0xf9,0xf3,0xb3,0x1b
  8922. };
  8923. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8924. {
  8925. 0x06,0x48,0x74,0x09,0x2f,0x7a,0x13,0xcc,
  8926. 0x44,0x62,0x24,0x7a,0xd4,0x23,0xd0,0xe9,
  8927. 0x6e,0xdf,0x42,0xe8,0xb6,0x7a,0x5a,0x23,
  8928. 0xb7,0xa0,0xa6,0x47,0x7b,0x09,0x8e,0x66
  8929. };
  8930. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8931. {
  8932. 0x1c,0xff,0x95
  8933. };
  8934. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8935. {
  8936. 0xb9,0x74,0xfa
  8937. };
  8938. #endif
  8939. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8940. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8941. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8942. #ifdef HAVE_AES_DECRYPT
  8943. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8944. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8945. #endif
  8946. #endif
  8947. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8948. if (ret != 0)
  8949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8950. else
  8951. enc_inited = 1;
  8952. #ifdef HAVE_AES_DECRYPT
  8953. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8954. if (ret != 0)
  8955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8956. else
  8957. dec_inited = 1;
  8958. #endif
  8959. #ifdef WOLFSSL_AES_128
  8960. /* 128 key tests */
  8961. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  8962. ret = EVP_test(EVP_aes_128_cfb8(), key1, iv, msg1, sizeof(msg1),
  8963. cipher1, sizeof(cipher1));
  8964. if (ret != 0) {
  8965. return ret;
  8966. }
  8967. #endif
  8968. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8969. if (ret != 0)
  8970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8971. #ifdef HAVE_AES_DECRYPT
  8972. /* decrypt uses AES_ENCRYPTION */
  8973. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8974. if (ret != 0)
  8975. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8976. #endif
  8977. XMEMSET(cipher, 0, sizeof(cipher));
  8978. ret = wc_AesCfb8Encrypt(enc, cipher, msg1, sizeof(msg1));
  8979. if (ret != 0)
  8980. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8981. if (XMEMCMP(cipher, cipher1, sizeof(cipher1)) != 0)
  8982. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8983. #ifdef HAVE_AES_DECRYPT
  8984. ret = wc_AesCfb8Decrypt(dec, plain, cipher, sizeof(msg1));
  8985. if (ret != 0)
  8986. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8987. if (XMEMCMP(plain, msg1, sizeof(msg1)) != 0)
  8988. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8989. #endif /* HAVE_AES_DECRYPT */
  8990. #endif /* WOLFSSL_AES_128 */
  8991. #ifdef WOLFSSL_AES_192
  8992. /* 192 key tests */
  8993. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8994. if (ret != 0)
  8995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8996. XMEMSET(cipher, 0, sizeof(cipher));
  8997. ret = wc_AesCfb8Encrypt(enc, cipher, msg2, sizeof(msg2));
  8998. if (ret != 0)
  8999. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9000. if (XMEMCMP(cipher, cipher2, sizeof(msg2)) != 0)
  9001. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9002. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9003. ret = EVP_test(EVP_aes_192_cfb8(), key2, iv2, msg2, sizeof(msg2),
  9004. cipher2, sizeof(msg2));
  9005. if (ret != 0) {
  9006. return ret;
  9007. }
  9008. #endif
  9009. #endif /* WOLFSSL_AES_192 */
  9010. #ifdef WOLFSSL_AES_256
  9011. /* 256 key tests */
  9012. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  9013. if (ret != 0)
  9014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9015. XMEMSET(cipher, 0, sizeof(cipher));
  9016. ret = wc_AesCfb8Encrypt(enc, cipher, msg3, sizeof(msg3));
  9017. if (ret != 0)
  9018. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9019. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  9020. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9021. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9022. ret = EVP_test(EVP_aes_256_cfb8(), key3, iv3, msg3, sizeof(msg3),
  9023. cipher3, sizeof(msg3));
  9024. if (ret != 0) {
  9025. goto out;
  9026. }
  9027. #endif
  9028. #endif /* WOLFSSL_AES_256 */
  9029. out:
  9030. if (enc_inited)
  9031. wc_AesFree(enc);
  9032. #ifdef HAVE_AES_DECRYPT
  9033. if (dec_inited)
  9034. wc_AesFree(dec);
  9035. #endif
  9036. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9037. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  9038. #ifdef HAVE_AES_DECRYPT
  9039. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  9040. #endif
  9041. #endif
  9042. return ret;
  9043. }
  9044. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  9045. #endif /* WOLFSSL_AES_CFB */
  9046. static wc_test_ret_t aes_key_size_test(void)
  9047. {
  9048. wc_test_ret_t ret;
  9049. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9050. Aes *aes;
  9051. #else
  9052. Aes aes[1];
  9053. #endif
  9054. byte key16[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9055. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9056. #ifndef WOLFSSL_CRYPTOCELL
  9057. byte key24[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9058. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9059. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
  9060. #endif
  9061. byte key32[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9062. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9063. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9064. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9065. byte iv[] = "1234567890abcdef";
  9066. #ifndef HAVE_FIPS
  9067. word32 keySize;
  9068. #endif
  9069. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9070. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9071. return WC_TEST_RET_ENC_ERRNO;
  9072. #endif
  9073. #if !defined(HAVE_FIPS) || \
  9074. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  9075. /* w/ FIPS v1 (cert 2425) wc_AesInit just returns 0 always as it's not
  9076. * supported with that FIPS version */
  9077. ret = wc_AesInit(NULL, HEAP_HINT, devId);
  9078. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9080. #endif
  9081. ret = wc_AesInit(aes, HEAP_HINT, devId);
  9082. /* 0 check OK for FIPSv1 */
  9083. if (ret != 0)
  9084. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9085. #ifndef HAVE_FIPS
  9086. /* Parameter Validation testing. */
  9087. ret = wc_AesGetKeySize(NULL, NULL);
  9088. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9089. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9090. ret = wc_AesGetKeySize(aes, NULL);
  9091. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9093. ret = wc_AesGetKeySize(NULL, &keySize);
  9094. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9096. /* Crashes in FIPS */
  9097. ret = wc_AesSetKey(NULL, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9098. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9099. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9100. #endif
  9101. /* NULL IV indicates to use all zeros IV. */
  9102. ret = wc_AesSetKey(aes, key16, sizeof(key16), NULL, AES_ENCRYPTION);
  9103. #ifdef WOLFSSL_AES_128
  9104. if (ret != 0)
  9105. #else
  9106. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9107. #endif
  9108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9109. ret = wc_AesSetKey(aes, key32, sizeof(key32) - 1, iv, AES_ENCRYPTION);
  9110. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9111. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9112. /* CryptoCell handles rounds internally */
  9113. #if !defined(HAVE_FIPS) && !defined(WOLFSSL_CRYPTOCELL)
  9114. /* PSA don't use aes->rounds */
  9115. #if !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_AES)
  9116. /* Force invalid rounds */
  9117. aes->rounds = 16;
  9118. ret = wc_AesGetKeySize(aes, &keySize);
  9119. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9120. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9121. #endif
  9122. #endif
  9123. ret = wc_AesSetKey(aes, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9124. #ifdef WOLFSSL_AES_128
  9125. if (ret != 0)
  9126. #else
  9127. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9128. #endif
  9129. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9130. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128)
  9131. ret = wc_AesGetKeySize(aes, &keySize);
  9132. if (ret != 0 || keySize != sizeof(key16))
  9133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9134. #endif
  9135. #ifndef WOLFSSL_CRYPTOCELL
  9136. /* Cryptocell only supports AES-128 key size */
  9137. ret = wc_AesSetKey(aes, key24, sizeof(key24), iv, AES_ENCRYPTION);
  9138. #ifdef WOLFSSL_AES_192
  9139. if (ret != 0)
  9140. #else
  9141. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9142. #endif
  9143. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9144. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192)
  9145. ret = wc_AesGetKeySize(aes, &keySize);
  9146. if (ret != 0 || keySize != sizeof(key24))
  9147. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9148. #endif
  9149. ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION);
  9150. #ifdef WOLFSSL_AES_256
  9151. if (ret != 0)
  9152. #else
  9153. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9154. #endif
  9155. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9156. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256)
  9157. ret = wc_AesGetKeySize(aes, &keySize);
  9158. if (ret != 0 || keySize != sizeof(key32))
  9159. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9160. #endif
  9161. #endif /* !WOLFSSL_CRYPTOCELL */
  9162. ret = 0; /* success */
  9163. out:
  9164. wc_AesFree(aes);
  9165. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9166. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9167. #endif
  9168. return ret;
  9169. }
  9170. #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  9171. /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */
  9172. #ifdef WOLFSSL_AES_128
  9173. static wc_test_ret_t aes_xts_128_test(void)
  9174. {
  9175. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9176. XtsAes *aes = NULL;
  9177. #else
  9178. XtsAes aes[1];
  9179. #endif
  9180. int aes_inited = 0;
  9181. wc_test_ret_t ret = 0;
  9182. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9183. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9184. #ifdef WOLFSSL_AESXTS_STREAM
  9185. struct XtsAesStreamData stream;
  9186. #endif
  9187. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9188. !defined(WOLFSSL_AFALG)
  9189. #define LARGE_XTS_SZ 1024
  9190. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9191. byte* large_input = NULL;
  9192. #else
  9193. byte large_input[LARGE_XTS_SZ];
  9194. #endif
  9195. #endif
  9196. /* 128 key tests */
  9197. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9198. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  9199. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  9200. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  9201. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  9202. };
  9203. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9204. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9205. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9206. };
  9207. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9208. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9209. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9210. };
  9211. /* plain text test of partial block is not from NIST test vector list */
  9212. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9213. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9214. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9215. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9216. };
  9217. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9218. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a,
  9219. 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63
  9220. };
  9221. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9222. 0x39, 0x25, 0x79, 0x05, 0xdf, 0xcc, 0x77, 0x76,
  9223. 0x6c, 0x87, 0x0a, 0x80, 0x6a, 0x60, 0xe3, 0xc0,
  9224. 0x93, 0xd1, 0x2a, 0xcf, 0xcb, 0x51, 0x42, 0xfa,
  9225. 0x09, 0x69, 0x89, 0x62, 0x5b, 0x60, 0xdb, 0x16
  9226. };
  9227. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9228. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9229. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9230. };
  9231. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9232. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9233. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9234. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9235. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9236. };
  9237. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9238. 0xd6, 0xbe, 0x04, 0x6d, 0x41, 0xf2, 0x3b, 0x5e,
  9239. 0xd7, 0x0b, 0x6b, 0x3d, 0x5c, 0x8e, 0x66, 0x23,
  9240. 0x2b, 0xe6, 0xb8, 0x07, 0xd4, 0xdc, 0xc6, 0x0e,
  9241. 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22
  9242. };
  9243. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9244. 0x2b, 0xf7, 0x2c, 0xf3, 0xeb, 0x85, 0xef, 0x7b,
  9245. 0x0b, 0x76, 0xa0, 0xaa, 0xf3, 0x3f, 0x25, 0x8b,
  9246. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
  9247. };
  9248. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9249. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9250. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9251. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9252. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9253. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9254. };
  9255. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9256. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9257. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9258. };
  9259. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9260. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9261. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9262. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9263. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9264. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9265. };
  9266. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9267. 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23,
  9268. 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12,
  9269. 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36,
  9270. 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF,
  9271. 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD
  9272. };
  9273. #endif /* HAVE_FIPS */
  9274. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9275. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9276. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9277. #endif
  9278. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  9279. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  9280. ret = EVP_test(EVP_aes_128_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  9281. if (ret != 0) {
  9282. printf("EVP_aes_128_xts failed!\n");
  9283. goto out;
  9284. }
  9285. #endif
  9286. XMEMSET(buf, 0, sizeof(buf));
  9287. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9288. if (ret != 0)
  9289. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9290. else
  9291. aes_inited = 1;
  9292. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9293. if (ret != 0)
  9294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9295. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9296. #if defined(WOLFSSL_ASYNC_CRYPT)
  9297. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9298. #endif
  9299. if (ret != 0)
  9300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9301. if (XMEMCMP(c2, buf, sizeof(c2)))
  9302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9303. #ifdef WOLFSSL_AESXTS_STREAM
  9304. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9305. #if defined(WOLFSSL_ASYNC_CRYPT)
  9306. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9307. #endif
  9308. if (ret != 0)
  9309. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9310. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  9311. #if defined(WOLFSSL_ASYNC_CRYPT)
  9312. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9313. #endif
  9314. if (ret != 0)
  9315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9316. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  9317. #if defined(WOLFSSL_ASYNC_CRYPT)
  9318. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9319. #endif
  9320. if (ret != 0)
  9321. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9322. if (XMEMCMP(c2, buf, sizeof(c2)))
  9323. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9324. #endif /* WOLFSSL_AESXTS_STREAM */
  9325. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9326. defined(WC_C_DYNAMIC_FALLBACK)
  9327. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9328. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9329. #if defined(WOLFSSL_ASYNC_CRYPT)
  9330. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9331. #endif
  9332. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9333. if (ret != 0)
  9334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9335. if (XMEMCMP(c2, buf, sizeof(c2)))
  9336. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9337. #endif
  9338. XMEMSET(buf, 0, sizeof(buf));
  9339. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9340. if (ret != 0)
  9341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9342. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9343. #if defined(WOLFSSL_ASYNC_CRYPT)
  9344. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9345. #endif
  9346. if (ret != 0)
  9347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9348. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9349. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9350. #ifdef WOLFSSL_AESXTS_STREAM
  9351. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i2), &stream);
  9352. #if defined(WOLFSSL_ASYNC_CRYPT)
  9353. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9354. #endif
  9355. if (ret != 0)
  9356. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9357. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9358. #if defined(WOLFSSL_ASYNC_CRYPT)
  9359. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9360. #endif
  9361. if (ret != 0)
  9362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9363. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9364. #if defined(WOLFSSL_ASYNC_CRYPT)
  9365. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9366. #endif
  9367. if (ret != 0)
  9368. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9369. if (XMEMCMP(c1, buf, sizeof(c1)))
  9370. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9371. #endif /* WOLFSSL_AESXTS_STREAM */
  9372. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9373. defined(WC_C_DYNAMIC_FALLBACK)
  9374. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9375. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9376. #if defined(WOLFSSL_ASYNC_CRYPT)
  9377. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9378. #endif
  9379. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9380. if (ret != 0)
  9381. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9382. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9383. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9384. #endif
  9385. /* partial block encryption test */
  9386. XMEMSET(cipher, 0, sizeof(cipher));
  9387. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9388. #if defined(WOLFSSL_ASYNC_CRYPT)
  9389. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9390. #endif
  9391. if (ret != 0)
  9392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9393. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9394. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9395. #ifdef WOLFSSL_AESXTS_STREAM
  9396. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9397. #if defined(WOLFSSL_ASYNC_CRYPT)
  9398. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9399. #endif
  9400. if (ret != 0)
  9401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9402. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  9403. #if defined(WOLFSSL_ASYNC_CRYPT)
  9404. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9405. #endif
  9406. if (ret != 0)
  9407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9408. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9409. #if defined(WOLFSSL_ASYNC_CRYPT)
  9410. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9411. #endif
  9412. if (ret != 0)
  9413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9414. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  9415. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9416. #endif /* WOLFSSL_AESXTS_STREAM */
  9417. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9418. defined(WC_C_DYNAMIC_FALLBACK)
  9419. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9420. XMEMSET(cipher, 0, sizeof(cipher));
  9421. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9422. #if defined(WOLFSSL_ASYNC_CRYPT)
  9423. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9424. #endif
  9425. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9426. if (ret != 0)
  9427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9428. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9429. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9430. #endif
  9431. /* partial block decrypt test */
  9432. XMEMSET(buf, 0, sizeof(buf));
  9433. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9434. if (ret != 0)
  9435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9436. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9437. #if defined(WOLFSSL_ASYNC_CRYPT)
  9438. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9439. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9440. #else
  9441. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9442. #endif
  9443. #endif
  9444. if (ret != 0)
  9445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9446. if (XMEMCMP(pp, buf, sizeof(pp)))
  9447. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9448. #ifdef WOLFSSL_AESXTS_STREAM
  9449. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9450. #if defined(WOLFSSL_ASYNC_CRYPT)
  9451. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9452. #endif
  9453. if (ret != 0)
  9454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9455. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  9456. #if defined(WOLFSSL_ASYNC_CRYPT)
  9457. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9458. #endif
  9459. if (ret != 0)
  9460. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9461. if (XMEMCMP(pp, buf, sizeof(pp)))
  9462. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9463. #endif /* WOLFSSL_AESXTS_STREAM */
  9464. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9465. defined(WC_C_DYNAMIC_FALLBACK)
  9466. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9467. XMEMSET(buf, 0, sizeof(buf));
  9468. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9469. #if defined(WOLFSSL_ASYNC_CRYPT)
  9470. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9471. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9472. #else
  9473. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9474. #endif
  9475. #endif
  9476. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9477. if (ret != 0)
  9478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9479. if (XMEMCMP(pp, buf, sizeof(pp)))
  9480. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9481. #endif
  9482. /* NIST decrypt test vector */
  9483. XMEMSET(buf, 0, sizeof(buf));
  9484. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9485. #if defined(WOLFSSL_ASYNC_CRYPT)
  9486. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9487. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9488. #else
  9489. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9490. #endif
  9491. #endif
  9492. if (ret != 0)
  9493. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9494. if (XMEMCMP(p1, buf, sizeof(p1)))
  9495. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9496. #ifdef WOLFSSL_AESXTS_STREAM
  9497. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9498. #if defined(WOLFSSL_ASYNC_CRYPT)
  9499. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9500. #endif
  9501. if (ret != 0)
  9502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9503. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  9504. #if defined(WOLFSSL_ASYNC_CRYPT)
  9505. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9506. #endif
  9507. if (ret != 0)
  9508. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9509. if (XMEMCMP(p1, buf, sizeof(p1)))
  9510. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9511. #endif /* WOLFSSL_AESXTS_STREAM */
  9512. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9513. defined(WC_C_DYNAMIC_FALLBACK)
  9514. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9515. XMEMSET(buf, 0, sizeof(buf));
  9516. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9517. #if defined(WOLFSSL_ASYNC_CRYPT)
  9518. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9519. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9520. #else
  9521. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9522. #endif
  9523. #endif
  9524. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9525. if (ret != 0)
  9526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9527. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  9528. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9529. #endif
  9530. /* fail case with decrypting using wrong key */
  9531. XMEMSET(buf, 0, sizeof(buf));
  9532. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9533. #if defined(WOLFSSL_ASYNC_CRYPT)
  9534. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9535. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9536. #else
  9537. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9538. #endif
  9539. #endif
  9540. if (ret != 0)
  9541. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9542. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  9543. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9544. /* set correct key and retest */
  9545. XMEMSET(buf, 0, sizeof(buf));
  9546. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  9547. if (ret != 0)
  9548. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9549. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9550. #if defined(WOLFSSL_ASYNC_CRYPT)
  9551. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9552. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9553. #else
  9554. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9555. #endif
  9556. #endif
  9557. if (ret != 0)
  9558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9559. if (XMEMCMP(p2, buf, sizeof(p2)))
  9560. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9561. #ifndef HAVE_FIPS
  9562. /* Test ciphertext stealing in-place. */
  9563. XMEMCPY(buf, p3, sizeof(p3));
  9564. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  9565. if (ret != 0)
  9566. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9567. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  9568. #if defined(WOLFSSL_ASYNC_CRYPT)
  9569. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9570. #endif
  9571. if (ret != 0)
  9572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9573. if (XMEMCMP(c3, buf, sizeof(c3)))
  9574. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9575. #ifdef WOLFSSL_AESXTS_STREAM
  9576. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  9577. #if defined(WOLFSSL_ASYNC_CRYPT)
  9578. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9579. #endif
  9580. if (ret != 0)
  9581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9582. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  9583. #if defined(WOLFSSL_ASYNC_CRYPT)
  9584. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9585. #endif
  9586. if (ret != 0)
  9587. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9588. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  9589. #if defined(WOLFSSL_ASYNC_CRYPT)
  9590. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9591. #endif
  9592. if (ret != 0)
  9593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9594. if (XMEMCMP(c3, buf, sizeof(c3)))
  9595. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9596. #endif /* WOLFSSL_AESXTS_STREAM */
  9597. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  9598. if (ret != 0)
  9599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9600. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  9601. #if defined(WOLFSSL_ASYNC_CRYPT)
  9602. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9603. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9604. #else
  9605. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9606. #endif
  9607. #endif
  9608. if (ret != 0)
  9609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9610. if (XMEMCMP(p3, buf, sizeof(p3)))
  9611. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9612. #ifdef WOLFSSL_AESXTS_STREAM
  9613. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  9614. #if defined(WOLFSSL_ASYNC_CRYPT)
  9615. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9616. #endif
  9617. if (ret != 0)
  9618. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9619. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  9620. #if defined(WOLFSSL_ASYNC_CRYPT)
  9621. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9622. #endif
  9623. if (ret != 0)
  9624. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9625. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  9626. #if defined(WOLFSSL_ASYNC_CRYPT)
  9627. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9628. #endif
  9629. if (ret != 0)
  9630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9631. if (XMEMCMP(p3, buf, sizeof(p3)))
  9632. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9633. #endif /* WOLFSSL_AESXTS_STREAM */
  9634. #endif /* !HAVE_FIPS */
  9635. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9636. !defined(WOLFSSL_AFALG)
  9637. {
  9638. int i;
  9639. int j;
  9640. #ifdef WOLFSSL_AESXTS_STREAM
  9641. int k;
  9642. #endif
  9643. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9644. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  9645. DYNAMIC_TYPE_TMP_BUFFER);
  9646. if (large_input == NULL)
  9647. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  9648. #endif
  9649. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9650. large_input[i] = (byte)i;
  9651. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9652. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9653. if (ret != 0)
  9654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9655. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9656. sizeof(i1));
  9657. #if defined(WOLFSSL_ASYNC_CRYPT)
  9658. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9659. #endif
  9660. if (ret != 0)
  9661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9662. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9663. if (ret != 0)
  9664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9665. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9666. sizeof(i1));
  9667. #if defined(WOLFSSL_ASYNC_CRYPT)
  9668. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9669. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9670. WC_ASYNC_FLAG_NONE);
  9671. #else
  9672. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9673. #endif
  9674. #endif
  9675. if (ret != 0)
  9676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9677. for (i = 0; i < j; i++) {
  9678. if (large_input[i] != (byte)i) {
  9679. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9680. }
  9681. }
  9682. }
  9683. #ifdef WOLFSSL_AESXTS_STREAM
  9684. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9685. large_input[i] = (byte)i;
  9686. /* first, encrypt block by block then decrypt with a one-shot call. */
  9687. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9688. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9689. if (ret != 0)
  9690. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9691. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9692. #if defined(WOLFSSL_ASYNC_CRYPT)
  9693. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9694. #endif
  9695. if (ret != 0)
  9696. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9697. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9698. if ((j - k) < AES_BLOCK_SIZE*2)
  9699. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9700. else
  9701. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9702. #if defined(WOLFSSL_ASYNC_CRYPT)
  9703. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9704. #endif
  9705. if (ret != 0)
  9706. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9707. if ((j - k) < AES_BLOCK_SIZE*2)
  9708. break;
  9709. }
  9710. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9711. if (ret != 0)
  9712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9713. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9714. sizeof(i1));
  9715. #if defined(WOLFSSL_ASYNC_CRYPT)
  9716. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9717. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9718. WC_ASYNC_FLAG_NONE);
  9719. #else
  9720. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9721. #endif
  9722. #endif
  9723. if (ret != 0)
  9724. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9725. for (i = 0; i < j; i++) {
  9726. if (large_input[i] != (byte)i) {
  9727. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9728. }
  9729. }
  9730. }
  9731. /* second, encrypt with a one-shot call then decrypt block by block. */
  9732. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9733. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9734. if (ret != 0)
  9735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9736. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9737. sizeof(i1));
  9738. #if defined(WOLFSSL_ASYNC_CRYPT)
  9739. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9740. #endif
  9741. if (ret != 0)
  9742. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9743. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9744. if (ret != 0)
  9745. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9746. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9747. #if defined(WOLFSSL_ASYNC_CRYPT)
  9748. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9749. #endif
  9750. if (ret != 0)
  9751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9752. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9753. if ((j - k) < AES_BLOCK_SIZE*2)
  9754. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9755. else
  9756. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9757. #if defined(WOLFSSL_ASYNC_CRYPT)
  9758. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9759. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9760. WC_ASYNC_FLAG_NONE);
  9761. #else
  9762. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9763. #endif
  9764. #endif
  9765. if (ret != 0)
  9766. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9767. if ((j - k) < AES_BLOCK_SIZE*2)
  9768. break;
  9769. }
  9770. for (i = 0; i < j; i++) {
  9771. if (large_input[i] != (byte)i) {
  9772. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9773. }
  9774. }
  9775. }
  9776. #endif /* WOLFSSL_AESXTS_STREAM */
  9777. }
  9778. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  9779. * !WOLFSSL_AFALG
  9780. */
  9781. out:
  9782. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9783. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  9784. !defined(WOLFSSL_NO_MALLOC)
  9785. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9786. #endif
  9787. if (aes_inited)
  9788. wc_AesXtsFree(aes);
  9789. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9790. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9791. #endif
  9792. return ret;
  9793. }
  9794. #endif /* WOLFSSL_AES_128 */
  9795. #ifdef WOLFSSL_AES_192
  9796. static wc_test_ret_t aes_xts_192_test(void)
  9797. {
  9798. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9799. XtsAes *aes = NULL;
  9800. #else
  9801. XtsAes aes[1];
  9802. #endif
  9803. int aes_inited = 0;
  9804. wc_test_ret_t ret = 0;
  9805. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9806. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9807. #ifdef WOLFSSL_AESXTS_STREAM
  9808. struct XtsAesStreamData stream;
  9809. #endif
  9810. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9811. !defined(WOLFSSL_AFALG)
  9812. #define LARGE_XTS_SZ 1024
  9813. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9814. byte* large_input = NULL;
  9815. #else
  9816. byte large_input[LARGE_XTS_SZ];
  9817. #endif
  9818. #endif
  9819. /* 192 bit key tests */
  9820. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9821. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  9822. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  9823. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  9824. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  9825. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  9826. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3
  9827. };
  9828. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9829. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9830. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9831. };
  9832. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9833. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9834. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9835. };
  9836. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9837. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9838. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9839. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9840. };
  9841. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9842. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4,
  9843. 0xdb, 0x4e, 0xd3, 0x69, 0xdf, 0x8e, 0x3a, 0xe0
  9844. };
  9845. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9846. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  9847. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  9848. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  9849. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  9850. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  9851. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a
  9852. };
  9853. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9854. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9855. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9856. };
  9857. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9858. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9859. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9860. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9861. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9862. };
  9863. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9864. 0x6c, 0xa6, 0xb5, 0x73, 0x48, 0xf1, 0x89, 0xfa,
  9865. 0xdd, 0x80, 0x72, 0x1f, 0xb8, 0x56, 0x0c, 0xa2,
  9866. 0x35, 0xd4, 0x08, 0xbf, 0x24, 0xcb, 0xec, 0xdb,
  9867. 0x81, 0xe0, 0xe6, 0x4f, 0x3d, 0x1c, 0x5c, 0x46
  9868. };
  9869. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9870. 0xe9, 0x58, 0xfe, 0xab, 0x66, 0xb4, 0xf1, 0x79,
  9871. 0x91, 0x3f, 0x91, 0xdc, 0x6f, 0xdf, 0xd6, 0xac,
  9872. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4
  9873. };
  9874. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9875. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9876. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9877. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9878. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9879. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9880. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9881. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9882. };
  9883. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9884. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9885. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9886. };
  9887. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9888. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9889. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9890. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9891. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9892. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9893. };
  9894. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9895. 0xa4, 0xf2, 0x71, 0x5d, 0x80, 0x60, 0x68, 0xa0,
  9896. 0x80, 0x61, 0xd7, 0xc1, 0x55, 0xc8, 0x3a, 0x2e,
  9897. 0xd7, 0xf4, 0x62, 0xaf, 0xbd, 0x2d, 0xf9, 0x5f,
  9898. 0xe8, 0xc5, 0x99, 0x3d, 0x58, 0x3c, 0xeb, 0xba,
  9899. 0x86, 0xea, 0x2c, 0x7e, 0x1f, 0xba, 0x81, 0xde
  9900. };
  9901. #endif /* HAVE_FIPS */
  9902. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9903. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9904. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9905. #endif
  9906. XMEMSET(buf, 0, sizeof(buf));
  9907. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9908. if (ret != 0)
  9909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9910. else
  9911. aes_inited = 1;
  9912. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9913. if (ret != 0)
  9914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9915. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9916. #if defined(WOLFSSL_ASYNC_CRYPT)
  9917. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9918. #endif
  9919. if (ret != 0)
  9920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9921. if (XMEMCMP(c2, buf, sizeof(c2)))
  9922. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9923. #ifdef WOLFSSL_AESXTS_STREAM
  9924. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9925. #if defined(WOLFSSL_ASYNC_CRYPT)
  9926. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9927. #endif
  9928. if (ret != 0)
  9929. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9930. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  9931. #if defined(WOLFSSL_ASYNC_CRYPT)
  9932. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9933. #endif
  9934. if (ret != 0)
  9935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9936. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  9937. #if defined(WOLFSSL_ASYNC_CRYPT)
  9938. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9939. #endif
  9940. if (ret != 0)
  9941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9942. if (XMEMCMP(c2, buf, sizeof(c2)))
  9943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9944. #endif /* WOLFSSL_AESXTS_STREAM */
  9945. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9946. defined(WC_C_DYNAMIC_FALLBACK)
  9947. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9948. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9949. #if defined(WOLFSSL_ASYNC_CRYPT)
  9950. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9951. #endif
  9952. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9953. if (ret != 0)
  9954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9955. if (XMEMCMP(c2, buf, sizeof(c2)))
  9956. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9957. #endif
  9958. XMEMSET(buf, 0, sizeof(buf));
  9959. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9960. if (ret != 0)
  9961. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9962. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9963. #if defined(WOLFSSL_ASYNC_CRYPT)
  9964. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9965. #endif
  9966. if (ret != 0)
  9967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9968. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9969. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9970. #ifdef WOLFSSL_AESXTS_STREAM
  9971. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9972. #if defined(WOLFSSL_ASYNC_CRYPT)
  9973. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9974. #endif
  9975. if (ret != 0)
  9976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9977. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9978. #if defined(WOLFSSL_ASYNC_CRYPT)
  9979. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9980. #endif
  9981. if (ret != 0)
  9982. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9983. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9984. #if defined(WOLFSSL_ASYNC_CRYPT)
  9985. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9986. #endif
  9987. if (ret != 0)
  9988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9989. if (XMEMCMP(c1, buf, sizeof(c1)))
  9990. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9991. #endif /* WOLFSSL_AESXTS_STREAM */
  9992. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9993. defined(WC_C_DYNAMIC_FALLBACK)
  9994. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9995. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9996. #if defined(WOLFSSL_ASYNC_CRYPT)
  9997. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9998. #endif
  9999. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10000. if (ret != 0)
  10001. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10002. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10003. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10004. #endif
  10005. /* partial block encryption test */
  10006. XMEMSET(cipher, 0, sizeof(cipher));
  10007. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10008. #if defined(WOLFSSL_ASYNC_CRYPT)
  10009. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10010. #endif
  10011. if (ret != 0)
  10012. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10013. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10014. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10015. #ifdef WOLFSSL_AESXTS_STREAM
  10016. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10017. #if defined(WOLFSSL_ASYNC_CRYPT)
  10018. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10019. #endif
  10020. if (ret != 0)
  10021. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10022. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  10023. #if defined(WOLFSSL_ASYNC_CRYPT)
  10024. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10025. #endif
  10026. if (ret != 0)
  10027. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10028. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10029. #if defined(WOLFSSL_ASYNC_CRYPT)
  10030. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10031. #endif
  10032. if (ret != 0)
  10033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10034. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  10035. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10036. #endif /* WOLFSSL_AESXTS_STREAM */
  10037. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10038. defined(WC_C_DYNAMIC_FALLBACK)
  10039. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10040. XMEMSET(cipher, 0, sizeof(cipher));
  10041. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10042. #if defined(WOLFSSL_ASYNC_CRYPT)
  10043. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10044. #endif
  10045. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10046. if (ret != 0)
  10047. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10048. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10049. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10050. #endif
  10051. /* partial block decrypt test */
  10052. XMEMSET(buf, 0, sizeof(buf));
  10053. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10054. if (ret != 0)
  10055. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10056. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10057. #if defined(WOLFSSL_ASYNC_CRYPT)
  10058. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10059. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10060. #else
  10061. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10062. #endif
  10063. #endif
  10064. if (ret != 0)
  10065. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10066. if (XMEMCMP(pp, buf, sizeof(pp)))
  10067. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10068. #ifdef WOLFSSL_AESXTS_STREAM
  10069. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10070. #if defined(WOLFSSL_ASYNC_CRYPT)
  10071. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10072. #endif
  10073. if (ret != 0)
  10074. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10075. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  10076. #if defined(WOLFSSL_ASYNC_CRYPT)
  10077. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10078. #endif
  10079. if (ret != 0)
  10080. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10081. if (XMEMCMP(pp, buf, sizeof(pp)))
  10082. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10083. #endif /* WOLFSSL_AESXTS_STREAM */
  10084. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10085. defined(WC_C_DYNAMIC_FALLBACK)
  10086. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10087. XMEMSET(buf, 0, sizeof(buf));
  10088. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10089. #if defined(WOLFSSL_ASYNC_CRYPT)
  10090. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10091. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10092. #else
  10093. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10094. #endif
  10095. #endif
  10096. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10097. if (ret != 0)
  10098. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10099. if (XMEMCMP(pp, buf, sizeof(pp)))
  10100. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10101. #endif
  10102. /* NIST decrypt test vector */
  10103. XMEMSET(buf, 0, sizeof(buf));
  10104. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10105. #if defined(WOLFSSL_ASYNC_CRYPT)
  10106. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10107. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10108. #else
  10109. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10110. #endif
  10111. #endif
  10112. if (ret != 0)
  10113. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10114. if (XMEMCMP(p1, buf, sizeof(p1)))
  10115. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10116. #ifdef WOLFSSL_AESXTS_STREAM
  10117. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10118. #if defined(WOLFSSL_ASYNC_CRYPT)
  10119. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10120. #endif
  10121. if (ret != 0)
  10122. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10123. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10124. #if defined(WOLFSSL_ASYNC_CRYPT)
  10125. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10126. #endif
  10127. if (ret != 0)
  10128. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10129. if (XMEMCMP(p1, buf, sizeof(p1)))
  10130. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10131. #endif /* WOLFSSL_AESXTS_STREAM */
  10132. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10133. defined(WC_C_DYNAMIC_FALLBACK)
  10134. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10135. XMEMSET(buf, 0, sizeof(buf));
  10136. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10137. #if defined(WOLFSSL_ASYNC_CRYPT)
  10138. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10139. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10140. #else
  10141. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10142. #endif
  10143. #endif
  10144. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10145. if (ret != 0)
  10146. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10147. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  10148. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10149. #endif
  10150. /* fail case with decrypting using wrong key */
  10151. XMEMSET(buf, 0, sizeof(buf));
  10152. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10153. #if defined(WOLFSSL_ASYNC_CRYPT)
  10154. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10155. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10156. #else
  10157. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10158. #endif
  10159. #endif
  10160. if (ret != 0)
  10161. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10162. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  10163. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10164. /* set correct key and retest */
  10165. XMEMSET(buf, 0, sizeof(buf));
  10166. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10167. if (ret != 0)
  10168. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10169. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10170. #if defined(WOLFSSL_ASYNC_CRYPT)
  10171. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10172. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10173. #else
  10174. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10175. #endif
  10176. #endif
  10177. if (ret != 0)
  10178. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10179. if (XMEMCMP(p2, buf, sizeof(p2)))
  10180. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10181. #ifndef HAVE_FIPS
  10182. /* Test ciphertext stealing in-place. */
  10183. XMEMCPY(buf, p3, sizeof(p3));
  10184. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  10185. if (ret != 0)
  10186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10187. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  10188. #if defined(WOLFSSL_ASYNC_CRYPT)
  10189. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10190. #endif
  10191. if (ret != 0)
  10192. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10193. if (XMEMCMP(c3, buf, sizeof(c3)))
  10194. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10195. #ifdef WOLFSSL_AESXTS_STREAM
  10196. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  10197. #if defined(WOLFSSL_ASYNC_CRYPT)
  10198. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10199. #endif
  10200. if (ret != 0)
  10201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10202. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  10203. #if defined(WOLFSSL_ASYNC_CRYPT)
  10204. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10205. #endif
  10206. if (ret != 0)
  10207. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10208. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  10209. #if defined(WOLFSSL_ASYNC_CRYPT)
  10210. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10211. #endif
  10212. if (ret != 0)
  10213. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10214. if (XMEMCMP(c3, buf, sizeof(c3)))
  10215. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10216. #endif /* WOLFSSL_AESXTS_STREAM */
  10217. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  10218. if (ret != 0)
  10219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10220. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  10221. #if defined(WOLFSSL_ASYNC_CRYPT)
  10222. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10223. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10224. #else
  10225. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10226. #endif
  10227. #endif
  10228. if (ret != 0)
  10229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10230. if (XMEMCMP(p3, buf, sizeof(p3)))
  10231. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10232. #ifdef WOLFSSL_AESXTS_STREAM
  10233. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  10234. #if defined(WOLFSSL_ASYNC_CRYPT)
  10235. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10236. #endif
  10237. if (ret != 0)
  10238. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10239. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  10240. #if defined(WOLFSSL_ASYNC_CRYPT)
  10241. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10242. #endif
  10243. if (ret != 0)
  10244. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10245. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  10246. #if defined(WOLFSSL_ASYNC_CRYPT)
  10247. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10248. #endif
  10249. if (ret != 0)
  10250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10251. if (XMEMCMP(p3, buf, sizeof(p3)))
  10252. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10253. #endif /* WOLFSSL_AESXTS_STREAM */
  10254. #endif /* !HAVE_FIPS */
  10255. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10256. !defined(WOLFSSL_AFALG)
  10257. {
  10258. int i;
  10259. int j;
  10260. #ifdef WOLFSSL_AESXTS_STREAM
  10261. int k;
  10262. #endif
  10263. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10264. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10265. DYNAMIC_TYPE_TMP_BUFFER);
  10266. if (large_input == NULL)
  10267. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10268. #endif
  10269. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10270. large_input[i] = (byte)i;
  10271. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10272. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10273. if (ret != 0)
  10274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10275. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10276. sizeof(i1));
  10277. #if defined(WOLFSSL_ASYNC_CRYPT)
  10278. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10279. #endif
  10280. if (ret != 0)
  10281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10282. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10283. if (ret != 0)
  10284. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10285. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10286. sizeof(i1));
  10287. #if defined(WOLFSSL_ASYNC_CRYPT)
  10288. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10289. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10290. WC_ASYNC_FLAG_NONE);
  10291. #else
  10292. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10293. #endif
  10294. #endif
  10295. if (ret != 0)
  10296. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10297. for (i = 0; i < j; i++) {
  10298. if (large_input[i] != (byte)i) {
  10299. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10300. }
  10301. }
  10302. }
  10303. #ifdef WOLFSSL_AESXTS_STREAM
  10304. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10305. large_input[i] = (byte)i;
  10306. /* first, encrypt block by block then decrypt with a one-shot call. */
  10307. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10308. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10309. if (ret != 0)
  10310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10311. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10312. #if defined(WOLFSSL_ASYNC_CRYPT)
  10313. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10314. #endif
  10315. if (ret != 0)
  10316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10317. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10318. if ((j - k) < AES_BLOCK_SIZE*2)
  10319. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10320. else
  10321. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10322. #if defined(WOLFSSL_ASYNC_CRYPT)
  10323. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10324. #endif
  10325. if (ret != 0)
  10326. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10327. if ((j - k) < AES_BLOCK_SIZE*2)
  10328. break;
  10329. }
  10330. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10331. if (ret != 0)
  10332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10333. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10334. sizeof(i1));
  10335. #if defined(WOLFSSL_ASYNC_CRYPT)
  10336. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10337. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10338. WC_ASYNC_FLAG_NONE);
  10339. #else
  10340. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10341. #endif
  10342. #endif
  10343. if (ret != 0)
  10344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10345. for (i = 0; i < j; i++) {
  10346. if (large_input[i] != (byte)i) {
  10347. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10348. }
  10349. }
  10350. }
  10351. /* second, encrypt with a one-shot call then decrypt block by block. */
  10352. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10353. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10354. if (ret != 0)
  10355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10356. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10357. sizeof(i1));
  10358. #if defined(WOLFSSL_ASYNC_CRYPT)
  10359. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10360. #endif
  10361. if (ret != 0)
  10362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10363. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10364. if (ret != 0)
  10365. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10366. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10367. #if defined(WOLFSSL_ASYNC_CRYPT)
  10368. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10369. #endif
  10370. if (ret != 0)
  10371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10372. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10373. if ((j - k) < AES_BLOCK_SIZE*2)
  10374. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10375. else
  10376. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10377. #if defined(WOLFSSL_ASYNC_CRYPT)
  10378. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10379. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10380. WC_ASYNC_FLAG_NONE);
  10381. #else
  10382. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10383. #endif
  10384. #endif
  10385. if (ret != 0)
  10386. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10387. if ((j - k) < AES_BLOCK_SIZE*2)
  10388. break;
  10389. }
  10390. for (i = 0; i < j; i++) {
  10391. if (large_input[i] != (byte)i) {
  10392. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10393. }
  10394. }
  10395. }
  10396. #endif /* WOLFSSL_AESXTS_STREAM */
  10397. }
  10398. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10399. * !WOLFSSL_AFALG
  10400. */
  10401. out:
  10402. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10403. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10404. !defined(WOLFSSL_NO_MALLOC)
  10405. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10406. #endif
  10407. if (aes_inited)
  10408. wc_AesXtsFree(aes);
  10409. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10410. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10411. #endif
  10412. return ret;
  10413. }
  10414. #endif /* WOLFSSL_AES_192 */
  10415. #ifdef WOLFSSL_AES_256
  10416. static wc_test_ret_t aes_xts_256_test(void)
  10417. {
  10418. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10419. XtsAes *aes = NULL;
  10420. #else
  10421. XtsAes aes[1];
  10422. #endif
  10423. int aes_inited = 0;
  10424. wc_test_ret_t ret = 0;
  10425. unsigned char buf[AES_BLOCK_SIZE * 3];
  10426. unsigned char cipher[AES_BLOCK_SIZE * 3];
  10427. #ifdef WOLFSSL_AESXTS_STREAM
  10428. struct XtsAesStreamData stream;
  10429. #endif
  10430. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10431. !defined(WOLFSSL_AFALG)
  10432. #define LARGE_XTS_SZ 1024
  10433. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10434. byte* large_input = NULL;
  10435. #else
  10436. byte large_input[LARGE_XTS_SZ];
  10437. #endif
  10438. #endif
  10439. /* 256 key tests */
  10440. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10441. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  10442. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  10443. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  10444. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  10445. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  10446. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3,
  10447. 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58,
  10448. 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08
  10449. };
  10450. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  10451. 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2,
  10452. 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64
  10453. };
  10454. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10455. 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1,
  10456. 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64,
  10457. 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3,
  10458. 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e
  10459. };
  10460. /* plain text test of partial block is not from NIST test vector list */
  10461. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  10462. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  10463. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  10464. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  10465. };
  10466. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10467. 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5,
  10468. 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13,
  10469. 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a,
  10470. 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb
  10471. };
  10472. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10473. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10474. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10475. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10476. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10477. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10478. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a,
  10479. 0xb5, 0xb0, 0xc7, 0xe5, 0x2d, 0xb5, 0x06, 0x12,
  10480. 0xd2, 0xb5, 0x3a, 0xcb, 0x47, 0x8a, 0x53, 0xb4
  10481. };
  10482. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10483. 0xe6, 0x42, 0x19, 0xed, 0xe0, 0xe1, 0xc2, 0xa0,
  10484. 0x0e, 0xf5, 0x58, 0x6a, 0xc4, 0x9b, 0xeb, 0x6f
  10485. };
  10486. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10487. 0x24, 0xcb, 0x76, 0x22, 0x55, 0xb5, 0xa8, 0x00,
  10488. 0xf4, 0x6e, 0x80, 0x60, 0x56, 0x9e, 0x05, 0x53,
  10489. 0xbc, 0xfe, 0x86, 0x55, 0x3b, 0xca, 0xd5, 0x89,
  10490. 0xc7, 0x54, 0x1a, 0x73, 0xac, 0xc3, 0x9a, 0xbd,
  10491. 0x53, 0xc4, 0x07, 0x76, 0xd8, 0xe8, 0x22, 0x61,
  10492. 0x9e, 0xa9, 0xad, 0x77, 0xa0, 0x13, 0x4c, 0xfc
  10493. };
  10494. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10495. 0xa3, 0xc6, 0xf3, 0xf3, 0x82, 0x79, 0x5b, 0x10,
  10496. 0x87, 0xd7, 0x02, 0x50, 0xdb, 0x2c, 0xd3, 0xb1,
  10497. 0xa1, 0x62, 0xa8, 0xb6, 0xdc, 0x12, 0x60, 0x61,
  10498. 0xc1, 0x0a, 0x84, 0xa5, 0x85, 0x3f, 0x3a, 0x89,
  10499. 0xe6, 0x6c, 0xdb, 0xb7, 0x9a, 0xb4, 0x28, 0x9b,
  10500. 0xc3, 0xea, 0xd8, 0x10, 0xe9, 0xc0, 0xaf, 0x92
  10501. };
  10502. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10503. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10504. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10505. #endif
  10506. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  10507. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  10508. ret = EVP_test(EVP_aes_256_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  10509. if (ret != 0) {
  10510. printf("EVP_aes_256_xts failed\n");
  10511. goto out;
  10512. }
  10513. #endif
  10514. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10515. if (ret != 0)
  10516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10517. else
  10518. aes_inited = 1;
  10519. XMEMSET(buf, 0, sizeof(buf));
  10520. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10521. if (ret != 0)
  10522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10523. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10524. #if defined(WOLFSSL_ASYNC_CRYPT)
  10525. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10526. #endif
  10527. if (ret != 0)
  10528. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10529. if (XMEMCMP(c2, buf, sizeof(c2)))
  10530. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10531. #ifdef WOLFSSL_AESXTS_STREAM
  10532. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10533. #if defined(WOLFSSL_ASYNC_CRYPT)
  10534. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10535. #endif
  10536. if (ret != 0)
  10537. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10538. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10539. #if defined(WOLFSSL_ASYNC_CRYPT)
  10540. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10541. #endif
  10542. if (ret != 0)
  10543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10544. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10545. #if defined(WOLFSSL_ASYNC_CRYPT)
  10546. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10547. #endif
  10548. if (ret != 0)
  10549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10550. if (XMEMCMP(c2, buf, sizeof(c2)))
  10551. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10552. #endif /* WOLFSSL_AESXTS_STREAM */
  10553. XMEMSET(buf, 0, sizeof(buf));
  10554. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10555. if (ret != 0)
  10556. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10557. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10558. #if defined(WOLFSSL_ASYNC_CRYPT)
  10559. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10560. #endif
  10561. if (ret != 0)
  10562. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10563. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10564. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10565. #ifdef WOLFSSL_AESXTS_STREAM
  10566. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10567. #if defined(WOLFSSL_ASYNC_CRYPT)
  10568. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10569. #endif
  10570. if (ret != 0)
  10571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10572. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10573. #if defined(WOLFSSL_ASYNC_CRYPT)
  10574. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10575. #endif
  10576. if (ret != 0)
  10577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10578. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10579. #if defined(WOLFSSL_ASYNC_CRYPT)
  10580. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10581. #endif
  10582. if (ret != 0)
  10583. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10584. if (XMEMCMP(c1, buf, sizeof(c1)))
  10585. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10586. #endif /* WOLFSSL_AESXTS_STREAM */
  10587. /* partial block encryption test */
  10588. XMEMSET(cipher, 0, sizeof(cipher));
  10589. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10590. #if defined(WOLFSSL_ASYNC_CRYPT)
  10591. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10592. #endif
  10593. if (ret != 0)
  10594. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10595. /* partial block decrypt test */
  10596. XMEMSET(buf, 0, sizeof(buf));
  10597. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10598. if (ret != 0)
  10599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10600. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10601. #if defined(WOLFSSL_ASYNC_CRYPT)
  10602. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10603. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10604. #else
  10605. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10606. #endif
  10607. #endif
  10608. if (ret != 0)
  10609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10610. if (XMEMCMP(pp, buf, sizeof(pp)))
  10611. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10612. /* NIST decrypt test vector */
  10613. XMEMSET(buf, 0, sizeof(buf));
  10614. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10615. #if defined(WOLFSSL_ASYNC_CRYPT)
  10616. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10617. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10618. #else
  10619. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10620. #endif
  10621. #endif
  10622. if (ret != 0)
  10623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10624. if (XMEMCMP(p1, buf, sizeof(p1)))
  10625. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10626. #ifdef WOLFSSL_AESXTS_STREAM
  10627. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10628. #if defined(WOLFSSL_ASYNC_CRYPT)
  10629. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10630. #endif
  10631. if (ret != 0)
  10632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10633. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10634. #if defined(WOLFSSL_ASYNC_CRYPT)
  10635. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10636. #endif
  10637. if (ret != 0)
  10638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10639. if (XMEMCMP(p1, buf, sizeof(p1)))
  10640. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10641. #endif /* WOLFSSL_AESXTS_STREAM */
  10642. XMEMSET(buf, 0, sizeof(buf));
  10643. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10644. if (ret != 0)
  10645. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10646. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10647. #if defined(WOLFSSL_ASYNC_CRYPT)
  10648. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10649. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10650. #else
  10651. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10652. #endif
  10653. #endif
  10654. if (ret != 0)
  10655. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10656. if (XMEMCMP(p2, buf, sizeof(p2)))
  10657. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10658. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10659. !defined(WOLFSSL_AFALG)
  10660. {
  10661. int i;
  10662. int j;
  10663. #ifdef WOLFSSL_AESXTS_STREAM
  10664. int k;
  10665. #endif
  10666. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10667. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10668. DYNAMIC_TYPE_TMP_BUFFER);
  10669. if (large_input == NULL)
  10670. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10671. #endif
  10672. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10673. large_input[i] = (byte)i;
  10674. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10675. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10676. if (ret != 0)
  10677. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10678. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10679. sizeof(i1));
  10680. #if defined(WOLFSSL_ASYNC_CRYPT)
  10681. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10682. #endif
  10683. if (ret != 0)
  10684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10685. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10686. if (ret != 0)
  10687. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10688. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10689. sizeof(i1));
  10690. #if defined(WOLFSSL_ASYNC_CRYPT)
  10691. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10692. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10693. WC_ASYNC_FLAG_NONE);
  10694. #else
  10695. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10696. #endif
  10697. #endif
  10698. if (ret != 0)
  10699. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10700. for (i = 0; i < j; i++) {
  10701. if (large_input[i] != (byte)i) {
  10702. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10703. }
  10704. }
  10705. }
  10706. #ifdef WOLFSSL_AESXTS_STREAM
  10707. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10708. large_input[i] = (byte)i;
  10709. /* first, encrypt block by block then decrypt with a one-shot call. */
  10710. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10711. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10712. if (ret != 0)
  10713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10714. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10715. #if defined(WOLFSSL_ASYNC_CRYPT)
  10716. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10717. #endif
  10718. if (ret != 0)
  10719. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10720. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10721. if ((j - k) < AES_BLOCK_SIZE*2)
  10722. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10723. else
  10724. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10725. #if defined(WOLFSSL_ASYNC_CRYPT)
  10726. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10727. #endif
  10728. if (ret != 0)
  10729. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10730. if ((j - k) < AES_BLOCK_SIZE*2)
  10731. break;
  10732. }
  10733. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10734. if (ret != 0)
  10735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10736. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10737. sizeof(i1));
  10738. #if defined(WOLFSSL_ASYNC_CRYPT)
  10739. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10740. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10741. WC_ASYNC_FLAG_NONE);
  10742. #else
  10743. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10744. #endif
  10745. #endif
  10746. if (ret != 0)
  10747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10748. for (i = 0; i < j; i++) {
  10749. if (large_input[i] != (byte)i) {
  10750. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10751. }
  10752. }
  10753. }
  10754. /* second, encrypt with a one-shot call then decrypt block by block. */
  10755. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10756. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10757. if (ret != 0)
  10758. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10759. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10760. sizeof(i1));
  10761. #if defined(WOLFSSL_ASYNC_CRYPT)
  10762. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10763. #endif
  10764. if (ret != 0)
  10765. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10766. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10767. if (ret != 0)
  10768. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10769. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10770. #if defined(WOLFSSL_ASYNC_CRYPT)
  10771. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10772. #endif
  10773. if (ret != 0)
  10774. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10775. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10776. if ((j - k) < AES_BLOCK_SIZE*2)
  10777. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10778. else
  10779. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10780. #if defined(WOLFSSL_ASYNC_CRYPT)
  10781. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10782. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10783. WC_ASYNC_FLAG_NONE);
  10784. #else
  10785. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10786. #endif
  10787. #endif
  10788. if (ret != 0)
  10789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10790. if ((j - k) < AES_BLOCK_SIZE*2)
  10791. break;
  10792. }
  10793. for (i = 0; i < j; i++) {
  10794. if (large_input[i] != (byte)i) {
  10795. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10796. }
  10797. }
  10798. }
  10799. #endif /* WOLFSSL_AESXTS_STREAM */
  10800. }
  10801. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10802. * !WOLFSSL_AFALG
  10803. */
  10804. out:
  10805. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10806. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10807. !defined(WOLFSSL_NO_MALLOC)
  10808. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10809. #endif
  10810. if (aes_inited)
  10811. wc_AesXtsFree(aes);
  10812. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10813. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10814. #endif
  10815. return ret;
  10816. }
  10817. #endif /* WOLFSSL_AES_256 */
  10818. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  10819. /* both 128 and 256 bit key test */
  10820. static wc_test_ret_t aes_xts_sector_test(void)
  10821. {
  10822. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10823. XtsAes *aes = NULL;
  10824. #else
  10825. XtsAes aes[1];
  10826. #endif
  10827. int aes_inited = 0;
  10828. wc_test_ret_t ret = 0;
  10829. unsigned char buf[AES_BLOCK_SIZE * 2];
  10830. /* 128 key tests */
  10831. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10832. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  10833. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  10834. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  10835. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  10836. };
  10837. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10838. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  10839. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  10840. };
  10841. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10842. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  10843. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  10844. };
  10845. word64 s1 = 141;
  10846. /* 256 key tests */
  10847. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10848. 0xef, 0x01, 0x0c, 0xa1, 0xa3, 0x66, 0x3e, 0x32,
  10849. 0x53, 0x43, 0x49, 0xbc, 0x0b, 0xae, 0x62, 0x23,
  10850. 0x2a, 0x15, 0x73, 0x34, 0x85, 0x68, 0xfb, 0x9e,
  10851. 0xf4, 0x17, 0x68, 0xa7, 0x67, 0x4f, 0x50, 0x7a,
  10852. 0x72, 0x7f, 0x98, 0x75, 0x53, 0x97, 0xd0, 0xe0,
  10853. 0xaa, 0x32, 0xf8, 0x30, 0x33, 0x8c, 0xc7, 0xa9,
  10854. 0x26, 0xc7, 0x73, 0xf0, 0x9e, 0x57, 0xb3, 0x57,
  10855. 0xcd, 0x15, 0x6a, 0xfb, 0xca, 0x46, 0xe1, 0xa0
  10856. };
  10857. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10858. 0xed, 0x98, 0xe0, 0x17, 0x70, 0xa8, 0x53, 0xb4,
  10859. 0x9d, 0xb9, 0xe6, 0xaa, 0xf8, 0x8f, 0x0a, 0x41,
  10860. 0xb9, 0xb5, 0x6e, 0x91, 0xa5, 0xa2, 0xb1, 0x1d,
  10861. 0x40, 0x52, 0x92, 0x54, 0xf5, 0x52, 0x3e, 0x75
  10862. };
  10863. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10864. 0xca, 0x20, 0xc5, 0x5e, 0x8d, 0xc1, 0x49, 0x68,
  10865. 0x7d, 0x25, 0x41, 0xde, 0x39, 0xc3, 0xdf, 0x63,
  10866. 0x00, 0xbb, 0x5a, 0x16, 0x3c, 0x10, 0xce, 0xd3,
  10867. 0x66, 0x6b, 0x13, 0x57, 0xdb, 0x8b, 0xd3, 0x9d
  10868. };
  10869. word64 s2 = 187;
  10870. #if !defined(BENCH_EMBEDDED) && \
  10871. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  10872. /* Sector size for encrypt/decrypt consecutive sectors testcase */
  10873. word32 sectorSz = 512;
  10874. unsigned char data[550];
  10875. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  10876. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  10877. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  10878. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  10879. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  10880. };
  10881. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  10882. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  10883. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  10884. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  10885. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  10886. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  10887. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  10888. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  10889. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  10890. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  10891. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  10892. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  10893. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  10894. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  10895. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  10896. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  10897. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  10898. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  10899. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  10900. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  10901. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  10902. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  10903. 0xfc, 0xfd, 0xfe, 0xff,
  10904. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  10905. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  10906. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  10907. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  10908. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  10909. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  10910. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  10911. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  10912. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  10913. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  10914. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  10915. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  10916. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  10917. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  10918. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  10919. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  10920. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  10921. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  10922. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  10923. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  10924. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  10925. 0xfc, 0xfd, 0xfe, 0xff,
  10926. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  10927. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  10928. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  10929. };
  10930. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  10931. 0xb9, 0x6b, 0x2b, 0xfd, 0x61, 0x87, 0x84, 0xd5, 0x26, 0xd2, 0x8c, 0x62,
  10932. 0x63, 0x01, 0xca, 0x46, 0xb1, 0x82, 0xfa, 0xdc, 0xbc, 0x32, 0x18, 0xe9,
  10933. 0xda, 0xe6, 0xda, 0xd1, 0x1a, 0x52, 0x77, 0xca, 0xdb, 0x0e, 0xbe, 0x37,
  10934. 0x88, 0x36, 0x1c, 0x87, 0x16, 0x60, 0xfe, 0xa8, 0x9e, 0xf6, 0x48, 0x64,
  10935. 0x94, 0x34, 0x64, 0xed, 0xf6, 0x9a, 0xc5, 0x28, 0xc9, 0xed, 0x64, 0x80,
  10936. 0x85, 0xd8, 0x93, 0xa7, 0x50, 0xb1, 0x9d, 0x2f, 0x1e, 0x34, 0xcc, 0xb4,
  10937. 0x03, 0xfb, 0x6b, 0x43, 0x21, 0xa8, 0x5b, 0xc6, 0x59, 0x13, 0xd2, 0xb5,
  10938. 0xf5, 0x7b, 0xf6, 0xb2, 0xa4, 0x7a, 0xd2, 0x50, 0x26, 0xcb, 0xa4, 0x83,
  10939. 0xc3, 0x56, 0xb0, 0xb1, 0x14, 0x34, 0x12, 0x1b, 0xea, 0x26, 0x97, 0x24,
  10940. 0x54, 0xcc, 0x32, 0x4c, 0xa4, 0xc2, 0xa3, 0x07, 0xfa, 0x30, 0xa9, 0xf0,
  10941. 0x91, 0x17, 0x60, 0x68, 0x88, 0x7f, 0x34, 0x7e, 0xbd, 0x20, 0x33, 0x95,
  10942. 0x6e, 0xc0, 0xb6, 0x2b, 0xff, 0x7e, 0x61, 0x35, 0x9a, 0x88, 0xff, 0xd9,
  10943. 0x69, 0x21, 0xe7, 0x8f, 0x45, 0x02, 0xf9, 0xd7, 0xeb, 0xa6, 0x53, 0xf1,
  10944. 0x73, 0x04, 0xf1, 0x0b, 0x85, 0xc6, 0x1f, 0x4a, 0x51, 0x2f, 0x95, 0x87,
  10945. 0x5a, 0x67, 0x37, 0xb2, 0x87, 0xf7, 0xbe, 0x2a, 0x17, 0x57, 0xca, 0xfc,
  10946. 0xdd, 0x5f, 0x37, 0x48, 0x78, 0xbd, 0xfa, 0x75, 0xc9, 0xfa, 0x86, 0x7e,
  10947. 0xc4, 0x0f, 0x60, 0x85, 0xce, 0x12, 0x44, 0x7c, 0xd9, 0xb2, 0x50, 0xd9,
  10948. 0x57, 0x85, 0xa5, 0xd7, 0x68, 0x59, 0x03, 0x09, 0x97, 0x2e, 0x8e, 0xa5,
  10949. 0xe3, 0x98, 0xac, 0x16, 0xfb, 0x6d, 0x54, 0xc5, 0x5d, 0x7a, 0x33, 0x44,
  10950. 0x0a, 0x39, 0x91, 0xcc, 0x9f, 0x67, 0xf9, 0x89, 0xbb, 0x62, 0x02, 0xc4,
  10951. 0x22, 0xec, 0xcf, 0x97, 0x69, 0x81, 0x3d, 0x00, 0xfd, 0xeb, 0x55, 0x08,
  10952. 0xa2, 0xff, 0x97, 0xaa, 0x79, 0xde, 0x3c, 0x8a, 0x78, 0x71, 0x73, 0xa2,
  10953. 0x98, 0x2f, 0xd8, 0x5c, 0x62, 0x1c, 0x5c, 0x23, 0x0a, 0xd1, 0xf1, 0x81,
  10954. 0x8a, 0x12, 0xe7, 0x4d, 0xdd, 0x4f, 0xd4, 0xf1, 0xe8, 0x0f, 0x25, 0x79,
  10955. 0x45, 0x4a, 0x49, 0x49, 0x7e, 0x56, 0x91, 0x4e, 0xaa, 0xba, 0x18, 0xe1,
  10956. 0xe4, 0xbe, 0x21, 0xdc, 0x58, 0x60, 0x6f, 0x6a, 0x7f, 0xdc, 0x5e, 0x74,
  10957. 0x47, 0xbf, 0xeb, 0x84, 0xc4, 0x1e, 0x5a, 0x61, 0x64, 0xc8, 0x63, 0x68,
  10958. 0xfa, 0x17, 0x9c, 0xac, 0x60, 0x1c, 0xa5, 0x6e, 0x00, 0x21, 0x93, 0x3c,
  10959. 0xd7, 0xbb, 0x73, 0x45, 0xf7, 0x34, 0x81, 0x6c, 0xfa, 0xf2, 0x33, 0xfd,
  10960. 0xb1, 0x40, 0x30, 0x6b, 0x30, 0xd1, 0x83, 0x5e, 0x2e, 0x7a, 0xce, 0xa6,
  10961. 0x12, 0x2a, 0x15, 0x03, 0x78, 0x29, 0xb9, 0x07, 0xae, 0xe7, 0xc2, 0x78,
  10962. 0x74, 0x72, 0xa5, 0x0e, 0x6b, 0x1f, 0x78, 0xf2, 0x5a, 0x69, 0xb6, 0x2b,
  10963. 0x99, 0x94, 0x1f, 0x89, 0xd1, 0x21, 0x14, 0x4a, 0x54, 0xab, 0x5a, 0x9f,
  10964. 0xaa, 0xa7, 0x96, 0x0a, 0x21, 0xce, 0x30, 0xb6, 0x70, 0x81, 0xe9, 0xd3,
  10965. 0x71, 0xc0, 0xf1, 0x15, 0xe2, 0xf6, 0xd3, 0xcc, 0x41, 0x15, 0x9d, 0xd5,
  10966. 0xa3, 0xa4, 0xe0, 0xf8, 0x62, 0xc4, 0x76, 0x65, 0x63, 0x89, 0xa7, 0xe2,
  10967. 0xfb, 0xf5, 0xc9, 0x80, 0x15, 0x5b, 0xc1, 0x59, 0xb2, 0xd0, 0x01, 0x3a,
  10968. 0xf9, 0xab, 0x5b, 0x79, 0x54, 0xed, 0x6b, 0xf9, 0x1d, 0x9d, 0x87, 0x63,
  10969. 0x80, 0x4f, 0xec, 0x9c, 0x4f, 0xad, 0x97, 0x04, 0xff, 0x62, 0x4a, 0x17,
  10970. 0xc0, 0x09, 0x2a, 0x2c, 0x23, 0x4b, 0xc3, 0xb6, 0x6d, 0xed, 0xdb, 0x1a,
  10971. 0x6f, 0x56, 0x2b, 0x78, 0x92, 0x3a, 0x5c, 0x7f, 0xb2, 0x63, 0xd3, 0xd5,
  10972. 0x1a, 0xbe, 0xc2, 0x34, 0xc8, 0xad, 0x36, 0xb7, 0x12, 0xb8, 0xe1, 0xb7,
  10973. 0x52, 0x7f, 0x16, 0x84, 0x2c, 0x47, 0x7e, 0xf2, 0xa5, 0x36, 0x2e, 0xad,
  10974. 0xe7, 0xbb, 0xc0, 0x6f, 0x27, 0x8e, 0x41, 0x08, 0x75, 0xe5, 0xff, 0xde,
  10975. 0x08, 0x9f, 0x8c, 0x91, 0xba, 0xc9, 0x9d, 0x9f, 0x27, 0x90, 0x50, 0x44,
  10976. 0x24, 0xe7, 0x3d, 0x6f
  10977. };
  10978. word64 s3 = 0x000000ffffffffff;
  10979. #endif
  10980. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10981. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10982. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10983. #endif
  10984. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10985. if (ret != 0)
  10986. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10987. else
  10988. aes_inited = 1;
  10989. XMEMSET(buf, 0, sizeof(buf));
  10990. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10991. if (ret != 0)
  10992. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10993. ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1);
  10994. #if defined(WOLFSSL_ASYNC_CRYPT)
  10995. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10996. #endif
  10997. if (ret != 0)
  10998. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10999. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  11000. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11001. /* decrypt test */
  11002. XMEMSET(buf, 0, sizeof(buf));
  11003. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11004. if (ret != 0)
  11005. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11006. ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1);
  11007. #if defined(WOLFSSL_ASYNC_CRYPT)
  11008. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11009. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11010. #else
  11011. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11012. #endif
  11013. #endif
  11014. if (ret != 0)
  11015. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11016. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  11017. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11018. /* 256 bit key tests */
  11019. XMEMSET(buf, 0, sizeof(buf));
  11020. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  11021. if (ret != 0)
  11022. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11023. ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2);
  11024. #if defined(WOLFSSL_ASYNC_CRYPT)
  11025. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11026. #endif
  11027. if (ret != 0)
  11028. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11029. if (XMEMCMP(c2, buf, sizeof(c2)))
  11030. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11031. /* decrypt test */
  11032. XMEMSET(buf, 0, sizeof(buf));
  11033. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  11034. if (ret != 0)
  11035. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11036. ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2);
  11037. #if defined(WOLFSSL_ASYNC_CRYPT)
  11038. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11039. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11040. #else
  11041. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11042. #endif
  11043. #endif
  11044. if (ret != 0)
  11045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11046. if (XMEMCMP(p2, buf, sizeof(p2)))
  11047. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11048. #if !defined(BENCH_EMBEDDED) && \
  11049. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11050. /* encrypt consecutive sectors test */
  11051. XMEMSET(data, 0, sizeof(buf));
  11052. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  11053. if (ret != 0)
  11054. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11055. ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3,
  11056. sizeof(p3), s3, sectorSz);
  11057. #if defined(WOLFSSL_ASYNC_CRYPT)
  11058. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11059. #endif
  11060. if (ret != 0)
  11061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11062. if (XMEMCMP(c3, data, sizeof(c3)))
  11063. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11064. /* decrypt consecutive sectors test */
  11065. XMEMSET(data, 0, sizeof(buf));
  11066. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  11067. if (ret != 0)
  11068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11069. ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3,
  11070. sizeof(c3), s3, sectorSz);
  11071. #if defined(WOLFSSL_ASYNC_CRYPT)
  11072. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11073. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11074. #else
  11075. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11076. #endif
  11077. #endif
  11078. if (ret != 0)
  11079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11080. if (XMEMCMP(p3, data, sizeof(p3)))
  11081. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11082. #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
  11083. out:
  11084. if (aes_inited)
  11085. wc_AesXtsFree(aes);
  11086. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11087. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11088. #endif
  11089. return ret;
  11090. }
  11091. #endif /* WOLFSSL_AES_128 && WOLFSSL_AES_256 */
  11092. #ifdef WOLFSSL_AES_128
  11093. /* testing of bad arguments */
  11094. static wc_test_ret_t aes_xts_args_test(void)
  11095. {
  11096. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11097. XtsAes *aes = NULL;
  11098. #else
  11099. XtsAes aes[1];
  11100. #endif
  11101. int aes_inited = 0;
  11102. wc_test_ret_t ret;
  11103. unsigned char buf[AES_BLOCK_SIZE * 2];
  11104. /* 128 key tests */
  11105. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  11106. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  11107. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  11108. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  11109. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  11110. };
  11111. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  11112. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  11113. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  11114. };
  11115. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  11116. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11117. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11118. };
  11119. word64 s1 = 141;
  11120. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11121. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11122. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11123. #endif
  11124. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11125. if (ret != 0)
  11126. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11127. else
  11128. aes_inited = 1;
  11129. if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0)
  11130. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11131. if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0)
  11132. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11133. /* encryption operations */
  11134. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11135. if (ret != 0)
  11136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11137. ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
  11138. #if defined(WOLFSSL_ASYNC_CRYPT)
  11139. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11140. #endif
  11141. if (ret == 0)
  11142. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11143. ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1);
  11144. #if defined(WOLFSSL_ASYNC_CRYPT)
  11145. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11146. #endif
  11147. if (ret == 0)
  11148. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11149. /* decryption operations */
  11150. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11151. if (ret != 0)
  11152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11153. ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
  11154. #if defined(WOLFSSL_ASYNC_CRYPT)
  11155. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11156. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11157. #else
  11158. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11159. #endif
  11160. #endif
  11161. if (ret == 0)
  11162. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11163. ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1);
  11164. #if defined(WOLFSSL_ASYNC_CRYPT)
  11165. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11166. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11167. #else
  11168. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11169. #endif
  11170. #endif
  11171. if (ret == 0)
  11172. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11173. ret = 0;
  11174. out:
  11175. if (aes_inited)
  11176. wc_AesXtsFree(aes);
  11177. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11178. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11179. #endif
  11180. return ret;
  11181. }
  11182. #endif /* WOLFSSL_AES_128 */
  11183. #endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  11184. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  11185. static wc_test_ret_t aes_cbc_test(void)
  11186. {
  11187. byte cipher[AES_BLOCK_SIZE];
  11188. byte plain[AES_BLOCK_SIZE];
  11189. wc_test_ret_t ret;
  11190. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  11191. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  11192. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  11193. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  11194. };
  11195. byte key[] = "0123456789abcdef "; /* align */
  11196. byte iv[] = "1234567890abcdef "; /* align */
  11197. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11198. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11199. /* Parameter Validation testing. */
  11200. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL);
  11201. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11202. return WC_TEST_RET_ENC_EC(ret);
  11203. #ifdef HAVE_AES_DECRYPT
  11204. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL);
  11205. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11206. return WC_TEST_RET_ENC_EC(ret);
  11207. #endif
  11208. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key,
  11209. AES_BLOCK_SIZE, iv);
  11210. if (ret != 0)
  11211. return WC_TEST_RET_ENC_EC(ret);
  11212. #ifdef HAVE_AES_DECRYPT
  11213. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key,
  11214. AES_BLOCK_SIZE, iv);
  11215. if (ret != 0)
  11216. return WC_TEST_RET_ENC_EC(ret);
  11217. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
  11218. return WC_TEST_RET_ENC_NC;
  11219. #endif /* HAVE_AES_DECRYPT */
  11220. (void)plain;
  11221. return 0;
  11222. }
  11223. #endif
  11224. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  11225. static wc_test_ret_t aesecb_test(void)
  11226. {
  11227. wc_test_ret_t ret = 0;
  11228. #if defined(WOLFSSL_AES_256)
  11229. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11230. Aes *enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  11231. #else
  11232. Aes enc[1];
  11233. #endif
  11234. int enc_inited = 0;
  11235. byte cipher[AES_BLOCK_SIZE * 4];
  11236. #ifdef HAVE_AES_DECRYPT
  11237. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11238. Aes *dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  11239. #else
  11240. Aes dec[1];
  11241. #endif
  11242. int dec_inited = 0;
  11243. byte plain[AES_BLOCK_SIZE * 4];
  11244. #endif /* HAVE_AES_DECRYPT */
  11245. {
  11246. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  11247. {
  11248. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11249. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  11250. };
  11251. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  11252. {
  11253. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  11254. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  11255. };
  11256. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  11257. {
  11258. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11259. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11260. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11261. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11262. };
  11263. ret = wc_AesInit(enc, HEAP_HINT, devId);
  11264. if (ret != 0)
  11265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11266. enc_inited = 1;
  11267. #if defined(HAVE_AES_DECRYPT)
  11268. ret = wc_AesInit(dec, HEAP_HINT, devId);
  11269. if (ret != 0)
  11270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11271. dec_inited = 1;
  11272. #endif
  11273. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11274. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  11275. if (ret != 0)
  11276. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11277. if (wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE) != 0)
  11278. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11279. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11280. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11281. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11282. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11283. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11284. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  11285. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11286. if (ret != 0)
  11287. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11288. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11289. ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE);
  11290. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11291. if (ret != 0)
  11292. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11293. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11295. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11296. ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE);
  11297. if (ret != 0)
  11298. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11299. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11300. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11301. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11302. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  11303. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11304. ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE);
  11305. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11306. if (ret != 0)
  11307. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11308. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11309. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11310. #endif
  11311. #ifdef HAVE_AES_DECRYPT
  11312. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11313. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  11314. if (ret != 0)
  11315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11316. if (wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE) != 0)
  11317. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11318. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11319. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11320. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11321. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11322. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11323. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  11324. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11325. if (ret != 0)
  11326. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11327. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11328. ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE);
  11329. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11330. if (ret != 0)
  11331. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11332. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11333. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11334. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11335. ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE);
  11336. if (ret != 0)
  11337. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11338. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11339. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11340. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11341. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  11342. if (ret != 0)
  11343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11344. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11345. ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE);
  11346. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11347. if (ret != 0)
  11348. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11349. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11350. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11351. #endif
  11352. #endif /* HAVE_AES_DECRYPT */
  11353. }
  11354. out:
  11355. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11356. if (enc) {
  11357. if (enc_inited)
  11358. wc_AesFree(enc);
  11359. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  11360. }
  11361. #ifdef HAVE_AES_DECRYPT
  11362. if (dec) {
  11363. if (dec_inited)
  11364. wc_AesFree(dec);
  11365. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  11366. }
  11367. #endif
  11368. #else
  11369. if (enc_inited)
  11370. wc_AesFree(enc);
  11371. #ifdef HAVE_AES_DECRYPT
  11372. if (dec_inited)
  11373. wc_AesFree(dec);
  11374. #endif
  11375. #endif
  11376. #endif /* WOLFSSL_AES_256 */
  11377. return ret;
  11378. }
  11379. #endif /* HAVE_AES_ECB */
  11380. #ifdef WOLFSSL_AES_COUNTER
  11381. static wc_test_ret_t aesctr_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  11382. {
  11383. wc_test_ret_t ret = 0;
  11384. /* test vectors from "Recommendation for Block Cipher Modes of
  11385. * Operation" NIST Special Publication 800-38A */
  11386. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  11387. {
  11388. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  11389. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  11390. };
  11391. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  11392. {
  11393. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11394. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  11395. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  11396. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  11397. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  11398. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  11399. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  11400. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  11401. };
  11402. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11403. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32[] =
  11404. {
  11405. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
  11406. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11407. };
  11408. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32_2[] =
  11409. {
  11410. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11411. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xfe
  11412. };
  11413. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64[] =
  11414. {
  11415. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11416. 0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11417. };
  11418. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64_2[] =
  11419. {
  11420. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
  11421. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11422. };
  11423. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96[] =
  11424. {
  11425. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11426. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff
  11427. };
  11428. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96_2[] =
  11429. {
  11430. 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,
  11431. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11432. };
  11433. #endif
  11434. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
  11435. {
  11436. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11437. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11438. };
  11439. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11440. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128_2[] =
  11441. {
  11442. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11443. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11444. };
  11445. #endif
  11446. #ifdef WOLFSSL_AES_128
  11447. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  11448. {
  11449. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  11450. 0xc2
  11451. };
  11452. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
  11453. {
  11454. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  11455. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  11456. };
  11457. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
  11458. {
  11459. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  11460. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  11461. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  11462. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  11463. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  11464. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  11465. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  11466. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  11467. };
  11468. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11469. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32Cipher[] =
  11470. {
  11471. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11472. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11473. 0x7e,0xad,0xea,0x5c,0xd1
  11474. };
  11475. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32CipherLong[] =
  11476. {
  11477. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11478. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11479. 0x7e,0xad,0xea,0x5c,0xd1,0xb7,0x98,0xf0,
  11480. 0x22,0x20,0xfe,0x67,0xb0,0x02,0x23,0x50
  11481. };
  11482. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32_2CipherLong[] =
  11483. {
  11484. 0x6e,0xa1,0x27,0x4d,0xea,0x20,0x5f,0x39,
  11485. 0x68,0xc8,0xb6,0x78,0xde,0xfc,0x53,0x5c,
  11486. 0x90,0xc8,0xf6,0xc6,0xfa,0xe0,0x7b,0x09,
  11487. 0x7c,0xf8,0x9c,0x6a,0x5a,0xa5,0x17,0x7f,
  11488. 0x03,0x92,0x5f,0x4e,0x85,0xea,0x26,0xc9,
  11489. 0x5a,0xc2,0x74,0xe2,0xbf,0xe4,0x1b,0xd4
  11490. };
  11491. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64Cipher[] =
  11492. {
  11493. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11494. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11495. 0xae,0x74,0x94,0x72,0x8e
  11496. };
  11497. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64CipherLong[] =
  11498. {
  11499. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11500. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11501. 0xae,0x74,0x94,0x72,0x8e,0xd0,0x71,0xc0,
  11502. 0x89,0x8a,0xa1,0xb0,0x29,0xa0,0x10,0x9e
  11503. };
  11504. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64_2CipherLong[] =
  11505. {
  11506. 0x3f,0xe7,0xd5,0xf3,0xfa,0x09,0xfe,0x40,
  11507. 0xa6,0xa1,0x32,0x8b,0x57,0x12,0xb9,0xfa,
  11508. 0xf2,0x2d,0xe4,0x3c,0x66,0x1d,0x0a,0x8e,
  11509. 0x46,0xf8,0x2e,0x33,0xce,0x8d,0x4e,0x3b,
  11510. 0x17,0x67,0x9e,0x9f,0x76,0x9e,0xc2,0x99,
  11511. 0xd5,0xd4,0x71,0xed,0xb4,0x33,0xb2,0xcd
  11512. };
  11513. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96Cipher[] =
  11514. {
  11515. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11516. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11517. 0x9d,0x77,0xc9,0x5f,0x38
  11518. };
  11519. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96CipherLong[] =
  11520. {
  11521. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11522. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11523. 0x9d,0x77,0xc9,0x5f,0x38,0xb5,0x6e,0x44,
  11524. 0x21,0x8e,0xda,0x57,0xe0,0x41,0xc7,0x6a
  11525. };
  11526. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96_2CipherLong[] =
  11527. {
  11528. 0xc8,0x81,0x1a,0xbe,0xc7,0x5b,0x93,0x6f,
  11529. 0xe6,0x52,0xe4,0xb1,0x2d,0x1c,0x39,0xbc,
  11530. 0xeb,0x82,0x27,0x0a,0x7e,0xa5,0x0e,0x2d,
  11531. 0x32,0xda,0xbe,0x10,0x7a,0x10,0xcc,0xd3,
  11532. 0x6f,0xc6,0x83,0x28,0x05,0x57,0x8a,0x24,
  11533. 0x44,0x76,0x17,0x81,0xb9,0x5c,0x94,0x81
  11534. };
  11535. #endif
  11536. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
  11537. {
  11538. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11539. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11540. 0xd3,0xda,0xe1,0x5b,0x04
  11541. };
  11542. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
  11543. {
  11544. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11545. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11546. 0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
  11547. 0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
  11548. };
  11549. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11550. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128_2CipherLong[] =
  11551. {
  11552. 0xba,0x76,0xaa,0x54,0xd5,0xb5,0x60,0x67,
  11553. 0xc1,0xa7,0x90,0x3b,0x3f,0xdd,0xfa,0x89,
  11554. 0x24,0xdf,0x0c,0x56,0x5c,0xf4,0x2a,0x68,
  11555. 0x97,0x87,0x13,0xb6,0x7a,0xd1,0x24,0xfd,
  11556. 0x4d,0x3f,0x77,0x4a,0xb9,0xe4,0x7d,0xa2,
  11557. 0xdb,0xb9,0x31,0x5e,0xa3,0x11,0x06,0x80
  11558. };
  11559. #endif
  11560. #endif /* WOLFSSL_AES_128 */
  11561. #ifdef WOLFSSL_AES_192
  11562. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  11563. {
  11564. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  11565. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  11566. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  11567. };
  11568. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  11569. {
  11570. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  11571. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b,
  11572. 0x09,0x03,0x39,0xec,0x0a,0xa6,0xfa,0xef,
  11573. 0xd5,0xcc,0xc2,0xc6,0xf4,0xce,0x8e,0x94,
  11574. 0x1e,0x36,0xb2,0x6b,0xd1,0xeb,0xc6,0x70,
  11575. 0xd1,0xbd,0x1d,0x66,0x56,0x20,0xab,0xf7,
  11576. 0x4f,0x78,0xa7,0xf6,0xd2,0x98,0x09,0x58,
  11577. 0x5a,0x97,0xda,0xec,0x58,0xc6,0xb0,0x50
  11578. };
  11579. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11580. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32Cipher[] =
  11581. {
  11582. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11583. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11584. 0x0c,0x33,0x97,0x06,0xc0
  11585. };
  11586. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32CipherLong[] =
  11587. {
  11588. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11589. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11590. 0x0c,0x33,0x97,0x06,0xc0,0xbe,0x83,0x87,
  11591. 0xdd,0xd3,0xff,0xd8,0xe4,0x6a,0x5b,0x84
  11592. };
  11593. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32_2CipherLong[] =
  11594. {
  11595. 0xf5,0x00,0xa2,0x91,0x54,0xa3,0x76,0xa2,
  11596. 0xdd,0xad,0x16,0x89,0xe5,0xf0,0x1d,0x40,
  11597. 0x84,0xcd,0x74,0x84,0xcb,0x8b,0x9e,0x29,
  11598. 0xa9,0x8a,0x12,0x65,0xa0,0x79,0x5e,0xce,
  11599. 0xd9,0x50,0x65,0x21,0x86,0xb0,0x85,0x0d,
  11600. 0x98,0x2d,0x9a,0x5a,0x11,0xbe,0xa5,0x7f
  11601. };
  11602. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64Cipher[] =
  11603. {
  11604. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11605. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11606. 0x3d,0xf7,0xb4,0xfd,0x8c
  11607. };
  11608. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64CipherLong[] =
  11609. {
  11610. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11611. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11612. 0x3d,0xf7,0xb4,0xfd,0x8c,0x55,0x47,0x10,
  11613. 0xd5,0x91,0x35,0xbe,0xd8,0x0d,0xa5,0x9e
  11614. };
  11615. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64_2CipherLong[] =
  11616. {
  11617. 0x59,0xf1,0xed,0x70,0x62,0x42,0xa8,0x06,
  11618. 0x07,0x36,0xe1,0xc5,0x04,0x79,0xc3,0x9b,
  11619. 0xd1,0x14,0x5c,0xcc,0x6f,0x81,0x5f,0x2f,
  11620. 0xa0,0xde,0xcf,0x61,0x55,0x18,0x7a,0xac,
  11621. 0xb0,0x59,0x37,0x90,0x53,0xb3,0x00,0x88,
  11622. 0xb4,0x49,0x90,0x7b,0x96,0xcd,0xcc,0xc3
  11623. };
  11624. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96Cipher[] =
  11625. {
  11626. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11627. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11628. 0x47,0xb5,0xf3,0x30,0x3b
  11629. };
  11630. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96CipherLong[] =
  11631. {
  11632. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11633. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11634. 0x47,0xb5,0xf3,0x30,0x3b,0xef,0xcd,0x80,
  11635. 0xe3,0x61,0x34,0xef,0x4e,0x1b,0x79,0xc1
  11636. };
  11637. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96_2CipherLong[] =
  11638. {
  11639. 0x3c,0xb2,0xff,0xc0,0x24,0xe1,0xf5,0xc4,
  11640. 0x0f,0xd1,0x0a,0x1b,0xbe,0x1f,0x23,0xa1,
  11641. 0x8e,0xbf,0x2b,0x96,0xb6,0x37,0xc8,0x25,
  11642. 0x06,0x90,0xe2,0xca,0x71,0x24,0x52,0x95,
  11643. 0xaa,0x8c,0x80,0xdf,0xb7,0xd7,0x30,0xb0,
  11644. 0xcc,0x06,0x4f,0x28,0xa2,0x74,0x27,0xf8
  11645. };
  11646. #endif
  11647. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128Cipher[] =
  11648. {
  11649. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11650. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11651. 0x8c,0x68,0xa7,0xd9,0x57
  11652. };
  11653. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128CipherLong[] =
  11654. {
  11655. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11656. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11657. 0x8c,0x68,0xa7,0xd9,0x57,0xab,0x09,0x0f,
  11658. 0x01,0xc4,0x4e,0x62,0xaf,0xc2,0xdf,0x1a
  11659. };
  11660. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11661. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128_2CipherLong[] =
  11662. {
  11663. 0x88,0x0a,0x26,0x4e,0xa8,0x26,0x21,0xe0,
  11664. 0xfc,0xbc,0x63,0xdc,0xd9,0x60,0x52,0xb2,
  11665. 0x99,0x2f,0xbb,0x1e,0x00,0xf5,0x9f,0x6d,
  11666. 0xab,0x48,0x0f,0xc6,0x37,0x12,0x56,0xe3,
  11667. 0x12,0x8d,0x31,0xc8,0xea,0xf4,0x41,0x82,
  11668. 0x7a,0x88,0xe0,0xd7,0xf0,0x67,0x03,0xa4
  11669. };
  11670. #endif
  11671. #endif
  11672. #ifdef WOLFSSL_AES_256
  11673. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  11674. {
  11675. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11676. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11677. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11678. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11679. };
  11680. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  11681. {
  11682. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  11683. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
  11684. 0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
  11685. 0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
  11686. 0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
  11687. 0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
  11688. 0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
  11689. 0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
  11690. };
  11691. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11692. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32Cipher[] =
  11693. {
  11694. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11695. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11696. 0xa2,0x13,0x47,0x74,0xda
  11697. };
  11698. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32CipherLong[] =
  11699. {
  11700. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11701. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11702. 0xa2,0x13,0x47,0x74,0xda,0x89,0x77,0x40,
  11703. 0x28,0x9c,0xe8,0x19,0x26,0x32,0xd8,0x1f
  11704. };
  11705. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32_2CipherLong[] =
  11706. {
  11707. 0xf6,0xd9,0x22,0xc6,0x80,0x29,0xaf,0x14,
  11708. 0x54,0x6c,0x0a,0xce,0x42,0xea,0x3c,0xa1,
  11709. 0x7c,0xeb,0x36,0x0d,0x8e,0xd7,0x8c,0x59,
  11710. 0xa8,0x09,0x9f,0x9e,0xba,0x5b,0x95,0xfa,
  11711. 0x26,0x8c,0x37,0x59,0xf8,0xae,0x8e,0xaa,
  11712. 0x4d,0xe4,0x1c,0xfe,0x51,0xc7,0xb7,0xcc
  11713. };
  11714. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64Cipher[] =
  11715. {
  11716. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11717. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11718. 0xd4,0x94,0x4c,0xcd,0x4d
  11719. };
  11720. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64CipherLong[] =
  11721. {
  11722. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11723. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11724. 0xd4,0x94,0x4c,0xcd,0x4d,0x47,0x5a,0x92,
  11725. 0x26,0x49,0x81,0x7a,0xda,0x36,0x27,0x01
  11726. };
  11727. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64_2CipherLong[] =
  11728. {
  11729. 0xf7,0x9c,0xbf,0xf6,0xa2,0xaa,0x8a,0x0a,
  11730. 0x63,0x8a,0x20,0x2f,0x12,0xf1,0x8e,0x49,
  11731. 0x30,0xc0,0x8d,0x5c,0x5f,0x8b,0xbc,0x16,
  11732. 0xdd,0x71,0xee,0x13,0x14,0x7b,0xe1,0x25,
  11733. 0xcb,0x87,0x8a,0xc6,0xdc,0x1d,0x54,0x7a,
  11734. 0xe1,0xe4,0x6f,0x0d,0x95,0x1b,0xd1,0x8b
  11735. };
  11736. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96Cipher[] =
  11737. {
  11738. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11739. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11740. 0xb8,0x69,0xa1,0x48,0x45
  11741. };
  11742. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96CipherLong[] =
  11743. {
  11744. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11745. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11746. 0xb8,0x69,0xa1,0x48,0x45,0xf1,0xc6,0x27,
  11747. 0x36,0xa8,0xb2,0x4b,0x0e,0x62,0x6b,0x72
  11748. };
  11749. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96_2CipherLong[] =
  11750. {
  11751. 0xd5,0x56,0x73,0xaa,0xb8,0xe4,0x06,0xf6,
  11752. 0x83,0x45,0x3a,0xb4,0xb9,0x63,0xec,0xad,
  11753. 0x73,0xc5,0xab,0x78,0xb1,0x21,0xab,0xef,
  11754. 0x69,0x15,0xb7,0x0c,0xe9,0xb4,0x3a,0xe7,
  11755. 0xbc,0xc4,0x22,0xbd,0x93,0xba,0x52,0xe0,
  11756. 0x91,0x2f,0x5e,0x8d,0x6d,0x59,0xf7,0xc2
  11757. };
  11758. #endif
  11759. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
  11760. {
  11761. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11762. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11763. 0x4b,0x45,0x7c,0xd6,0x8a
  11764. };
  11765. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
  11766. {
  11767. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11768. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11769. 0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
  11770. 0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
  11771. };
  11772. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11773. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128_2CipherLong[] =
  11774. {
  11775. 0x24,0x5c,0x09,0xa0,0x3b,0x1a,0x5a,0x94,
  11776. 0x2b,0x93,0x56,0x13,0x48,0xa0,0x21,0xce,
  11777. 0x95,0x11,0xa3,0x76,0xd6,0x59,0x88,0x42,
  11778. 0x04,0x71,0x69,0x62,0x28,0xb2,0xee,0x9d,
  11779. 0xd5,0xa0,0xea,0xc7,0x37,0x93,0x92,0xc7,
  11780. 0xf2,0xb6,0x8d,0xd9,0x59,0x1a,0xfa,0xbb
  11781. };
  11782. #endif
  11783. #endif
  11784. int i;
  11785. struct {
  11786. const byte* key;
  11787. int keySz;
  11788. const byte* iv;
  11789. const byte* plain;
  11790. int len;
  11791. const byte* cipher;
  11792. } testVec[] = {
  11793. #ifdef WOLFSSL_AES_128
  11794. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11795. ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
  11796. /* let's try with just 9 bytes, non block size test */
  11797. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11798. ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
  11799. /* and an additional 9 bytes to reuse tmp left buffer */
  11800. { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
  11801. /* Counter wrapping */
  11802. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11803. ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
  11804. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11805. ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
  11806. ctr128Wrap128CipherLong },
  11807. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11808. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128_2,
  11809. ctrPlain, (int)sizeof(ctr128Wrap128_2CipherLong),
  11810. ctr128Wrap128_2CipherLong },
  11811. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11812. ctrPlain, (int)sizeof(ctr128Wrap96Cipher), ctr128Wrap96Cipher },
  11813. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11814. ctrPlain, (int)sizeof(ctr128Wrap96CipherLong),
  11815. ctr128Wrap96CipherLong },
  11816. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96_2,
  11817. ctrPlain, (int)sizeof(ctr128Wrap96_2CipherLong),
  11818. ctr128Wrap96_2CipherLong },
  11819. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11820. ctrPlain, (int)sizeof(ctr128Wrap64Cipher), ctr128Wrap64Cipher },
  11821. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11822. ctrPlain, (int)sizeof(ctr128Wrap64CipherLong),
  11823. ctr128Wrap64CipherLong },
  11824. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64_2,
  11825. ctrPlain, (int)sizeof(ctr128Wrap64_2CipherLong),
  11826. ctr128Wrap64_2CipherLong },
  11827. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11828. ctrPlain, (int)sizeof(ctr128Wrap32Cipher), ctr128Wrap32Cipher },
  11829. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11830. ctrPlain, (int)sizeof(ctr128Wrap32CipherLong),
  11831. ctr128Wrap32CipherLong },
  11832. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32_2,
  11833. ctrPlain, (int)sizeof(ctr128Wrap32_2CipherLong),
  11834. ctr128Wrap32_2CipherLong },
  11835. #endif
  11836. #endif
  11837. #ifdef WOLFSSL_AES_192
  11838. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11839. ctrPlain, (int)sizeof(ctrPlain), ctr192Cipher },
  11840. /* let's try with just 9 bytes, non block size test */
  11841. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11842. ctrPlain, (int)sizeof(oddCipher), ctr192Cipher },
  11843. /* Counter wrapping */
  11844. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11845. ctrPlain, (int)sizeof(ctr192Wrap128Cipher), ctr192Wrap128Cipher },
  11846. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11847. ctrPlain, (int)sizeof(ctr192Wrap128CipherLong),
  11848. ctr192Wrap128CipherLong },
  11849. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11850. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128_2,
  11851. ctrPlain, (int)sizeof(ctr192Wrap128_2CipherLong),
  11852. ctr192Wrap128_2CipherLong },
  11853. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11854. ctrPlain, (int)sizeof(ctr192Wrap96Cipher), ctr192Wrap96Cipher },
  11855. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11856. ctrPlain, (int)sizeof(ctr192Wrap96CipherLong),
  11857. ctr192Wrap96CipherLong },
  11858. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96_2,
  11859. ctrPlain, (int)sizeof(ctr192Wrap96_2CipherLong),
  11860. ctr192Wrap96_2CipherLong },
  11861. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11862. ctrPlain, (int)sizeof(ctr192Wrap64Cipher), ctr192Wrap64Cipher },
  11863. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11864. ctrPlain, (int)sizeof(ctr192Wrap64CipherLong),
  11865. ctr192Wrap64CipherLong },
  11866. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64_2,
  11867. ctrPlain, (int)sizeof(ctr192Wrap64_2CipherLong),
  11868. ctr192Wrap64_2CipherLong },
  11869. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11870. ctrPlain, (int)sizeof(ctr192Wrap32Cipher), ctr192Wrap32Cipher },
  11871. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11872. ctrPlain, (int)sizeof(ctr192Wrap32CipherLong),
  11873. ctr192Wrap32CipherLong },
  11874. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32_2,
  11875. ctrPlain, (int)sizeof(ctr192Wrap32_2CipherLong),
  11876. ctr192Wrap32_2CipherLong },
  11877. #endif
  11878. #endif
  11879. #ifdef WOLFSSL_AES_256
  11880. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11881. ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
  11882. /* let's try with just 9 bytes, non block size test */
  11883. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11884. ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
  11885. /* Counter wrapping */
  11886. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11887. ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
  11888. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11889. ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
  11890. ctr256Wrap128CipherLong },
  11891. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11892. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128_2,
  11893. ctrPlain, (int)sizeof(ctr256Wrap128_2CipherLong),
  11894. ctr256Wrap128_2CipherLong },
  11895. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11896. ctrPlain, (int)sizeof(ctr256Wrap96Cipher), ctr256Wrap96Cipher },
  11897. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11898. ctrPlain, (int)sizeof(ctr256Wrap96CipherLong),
  11899. ctr256Wrap96CipherLong },
  11900. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96_2,
  11901. ctrPlain, (int)sizeof(ctr256Wrap96_2CipherLong),
  11902. ctr256Wrap96_2CipherLong },
  11903. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11904. ctrPlain, (int)sizeof(ctr256Wrap64Cipher), ctr256Wrap64Cipher },
  11905. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11906. ctrPlain, (int)sizeof(ctr256Wrap64CipherLong),
  11907. ctr256Wrap64CipherLong },
  11908. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64_2,
  11909. ctrPlain, (int)sizeof(ctr256Wrap64_2CipherLong),
  11910. ctr256Wrap64_2CipherLong },
  11911. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11912. ctrPlain, (int)sizeof(ctr256Wrap32Cipher), ctr256Wrap32Cipher },
  11913. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11914. ctrPlain, (int)sizeof(ctr256Wrap32CipherLong),
  11915. ctr256Wrap32CipherLong },
  11916. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32_2,
  11917. ctrPlain, (int)sizeof(ctr256Wrap32_2CipherLong),
  11918. ctr256Wrap32_2CipherLong },
  11919. #endif
  11920. #endif
  11921. };
  11922. #define AES_CTR_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  11923. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11924. if (testVec[i].key != NULL) {
  11925. ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
  11926. testVec[i].iv, AES_ENCRYPTION);
  11927. if (ret != 0) {
  11928. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11929. }
  11930. /* Ctr only uses encrypt, even on key setup */
  11931. ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
  11932. testVec[i].iv, AES_ENCRYPTION);
  11933. if (ret != 0) {
  11934. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11935. }
  11936. }
  11937. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
  11938. if (ret != 0) {
  11939. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11940. }
  11941. ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
  11942. if (ret != 0) {
  11943. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11944. }
  11945. if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
  11946. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11947. }
  11948. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11949. if (XMEMCMP(cipher, testVec[i].cipher, (size_t)testVec[i].len)) {
  11950. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11951. }
  11952. #endif
  11953. }
  11954. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11955. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11956. if (testVec[i].key != NULL) {
  11957. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11958. testVec[i].iv, AES_ENCRYPTION);
  11959. if (ret != 0) {
  11960. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11961. }
  11962. /* Ctr only uses encrypt, even on key setup */
  11963. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  11964. testVec[i].iv, AES_ENCRYPTION);
  11965. if (ret != 0) {
  11966. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11967. }
  11968. }
  11969. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11970. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  11971. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11972. if (ret != 0) {
  11973. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11974. }
  11975. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11976. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  11977. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11978. if (ret != 0) {
  11979. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11980. }
  11981. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  11982. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11983. }
  11984. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11985. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  11986. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11987. }
  11988. #endif
  11989. }
  11990. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11991. if (testVec[i].key != NULL) {
  11992. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11993. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11994. testVec[i].iv, AES_ENCRYPTION);
  11995. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11996. if (ret != 0) {
  11997. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11998. }
  11999. /* Ctr only uses encrypt, even on key setup */
  12000. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12001. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  12002. testVec[i].iv, AES_ENCRYPTION);
  12003. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12004. if (ret != 0) {
  12005. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12006. }
  12007. }
  12008. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12009. if (ret != 0) {
  12010. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12011. }
  12012. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12013. if (ret != 0) {
  12014. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12015. }
  12016. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12017. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12018. }
  12019. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12020. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12021. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12022. }
  12023. #endif
  12024. }
  12025. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12026. out:
  12027. return ret;
  12028. }
  12029. #endif /* WOLFSSL_AES_COUNTER */
  12030. #ifdef HAVE_AES_ECB
  12031. static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12032. {
  12033. wc_test_ret_t ret = 0;
  12034. WOLFSSL_SMALL_STACK_STATIC const byte key_128[] = "0123456789abcdef ";
  12035. WOLFSSL_SMALL_STACK_STATIC const byte key_192[] =
  12036. "0123456789abcdef01234567 ";
  12037. WOLFSSL_SMALL_STACK_STATIC const byte key_256[] =
  12038. "0123456789abcdef0123456789abcdef ";
  12039. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12040. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12041. 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  12042. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20
  12043. };
  12044. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[AES_BLOCK_SIZE] = {
  12045. 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
  12046. 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
  12047. };
  12048. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[AES_BLOCK_SIZE] = {
  12049. 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1,
  12050. 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab
  12051. };
  12052. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[AES_BLOCK_SIZE] = {
  12053. 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33,
  12054. 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82
  12055. };
  12056. int i;
  12057. struct {
  12058. const byte* key;
  12059. int keySz;
  12060. const byte* iv;
  12061. const byte* verify;
  12062. } testVec[] = {
  12063. { key_128, 16, iv, verify_ecb_128 },
  12064. { key_192, 24, iv, verify_ecb_192 },
  12065. { key_256, 32, iv, verify_ecb_256 },
  12066. };
  12067. #define AES_ECB_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  12068. for (i = 0; i < AES_ECB_TEST_LEN; i++) {
  12069. ret = wc_AesSetKey(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12070. AES_ENCRYPTION);
  12071. if (ret != 0)
  12072. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12073. #ifdef HAVE_AES_DECRYPT
  12074. ret = wc_AesSetKey(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12075. AES_DECRYPTION);
  12076. if (ret != 0)
  12077. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12078. #endif
  12079. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4);
  12080. ret = wc_AesEcbEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
  12081. #if defined(WOLFSSL_ASYNC_CRYPT)
  12082. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12083. #endif
  12084. if (ret != 0)
  12085. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12086. if (XMEMCMP(cipher, testVec[i].verify, AES_BLOCK_SIZE)) {
  12087. WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!");
  12088. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12089. }
  12090. #ifdef HAVE_AES_DECRYPT
  12091. XMEMSET(plain, 0, AES_BLOCK_SIZE * 4);
  12092. ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12093. #if defined(WOLFSSL_ASYNC_CRYPT)
  12094. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12095. #endif
  12096. if (ret != 0)
  12097. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12098. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  12099. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12100. #endif /* HAVE_AES_DECRYPT */
  12101. (void)dec;
  12102. (void)plain;
  12103. }
  12104. out:
  12105. return ret;
  12106. }
  12107. #endif
  12108. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
  12109. {
  12110. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_DIRECT)
  12111. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12112. Aes *enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12113. #else
  12114. Aes enc[1];
  12115. #endif
  12116. int enc_inited = 0;
  12117. byte cipher[AES_BLOCK_SIZE * 4];
  12118. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12119. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12120. Aes *dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12121. #else
  12122. Aes dec[1];
  12123. #endif
  12124. int dec_inited = 0;
  12125. byte plain [AES_BLOCK_SIZE * 4];
  12126. #endif /* HAVE_AES_DECRYPT || WOLFSSL_AES_COUNTER */
  12127. #endif /* HAVE_AES_CBC || WOLFSSL_AES_COUNTER || WOLFSSL_AES_DIRECT */
  12128. wc_test_ret_t ret = 0;
  12129. #ifdef HAVE_AES_CBC
  12130. #ifdef WOLFSSL_AES_128
  12131. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  12132. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  12133. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  12134. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  12135. };
  12136. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12137. {
  12138. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  12139. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  12140. };
  12141. #ifdef HAVE_RENESAS_SYNC
  12142. const byte *key =
  12143. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  12144. #else
  12145. WOLFSSL_SMALL_STACK_STATIC const
  12146. byte key[] = "0123456789abcdef "; /* align */
  12147. #endif
  12148. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef "; /* align */
  12149. WOLFSSL_ENTER("aes_test");
  12150. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12151. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || \
  12152. defined(WOLFSSL_AES_DIRECT)
  12153. if (enc == NULL)
  12154. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12155. #endif
  12156. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12157. if (dec == NULL)
  12158. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12159. #endif
  12160. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12161. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12162. if (ret != 0)
  12163. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12164. enc_inited = 1;
  12165. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12166. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12167. if (ret != 0)
  12168. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12169. dec_inited = 1;
  12170. #endif
  12171. #ifdef HAVE_AES_ECB
  12172. ret = aes_ecb_test(enc, dec, cipher, plain);
  12173. if (ret != 0)
  12174. return ret;
  12175. #endif
  12176. ret = wc_AesSetKey(enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  12177. if (ret != 0)
  12178. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12179. #ifdef HAVE_AES_DECRYPT
  12180. ret = wc_AesSetKey(dec, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
  12181. if (ret != 0)
  12182. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12183. #endif
  12184. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4);
  12185. ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
  12186. #if defined(WOLFSSL_ASYNC_CRYPT)
  12187. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12188. #endif
  12189. if (ret != 0)
  12190. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12191. #ifdef HAVE_AES_DECRYPT
  12192. XMEMSET(plain, 0, AES_BLOCK_SIZE * 4);
  12193. ret = wc_AesCbcDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12194. #if defined(WOLFSSL_ASYNC_CRYPT)
  12195. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12196. #endif
  12197. if (ret != 0) {
  12198. WOLFSSL_MSG("failed wc_AesCbcDecrypt");
  12199. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12200. }
  12201. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) {
  12202. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare");
  12203. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12204. }
  12205. #endif /* HAVE_AES_DECRYPT */
  12206. /* skipped because wrapped key use in case of renesas sm */
  12207. #ifndef HAVE_RENESAS_SYNC
  12208. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) {
  12209. WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare");
  12210. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12211. }
  12212. #endif
  12213. #endif /* WOLFSSL_AES_128 */
  12214. #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT)
  12215. {
  12216. WOLFSSL_SMALL_STACK_STATIC const byte bigMsg[] = {
  12217. /* "All work and no play makes Jack a dull boy. " */
  12218. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12219. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12220. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12221. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12222. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12223. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12224. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12225. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12226. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12227. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12228. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12229. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12230. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12231. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12232. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12233. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12234. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12235. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12236. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12237. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12238. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12239. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12240. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12241. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12242. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12243. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12244. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12245. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12246. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12247. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12248. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12249. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12250. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12251. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12252. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12253. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12254. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12255. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12256. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12257. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12258. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12259. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12260. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12261. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12262. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12263. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12264. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12265. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20
  12266. };
  12267. WOLFSSL_SMALL_STACK_STATIC const byte bigKey[] = "0123456789abcdeffedcba9876543210";
  12268. word32 keySz, msgSz;
  12269. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12270. byte *bigCipher = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12271. byte *bigPlain = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12272. if ((bigCipher == NULL) ||
  12273. (bigPlain == NULL)) {
  12274. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12275. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12276. }
  12277. #else
  12278. byte bigCipher[sizeof(bigMsg)];
  12279. byte bigPlain[sizeof(bigMsg)];
  12280. #endif
  12281. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12282. * message by AES_BLOCK_SIZE for each size of AES key. */
  12283. for (keySz = 16; keySz <= 32; keySz += 8) {
  12284. for (msgSz = AES_BLOCK_SIZE;
  12285. msgSz <= sizeof(bigMsg);
  12286. msgSz += AES_BLOCK_SIZE) {
  12287. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12288. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12289. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12290. if (ret != 0) {
  12291. ret = WC_TEST_RET_ENC_EC(ret);
  12292. break;
  12293. }
  12294. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12295. if (ret != 0) {
  12296. ret = WC_TEST_RET_ENC_EC(ret);
  12297. break;
  12298. }
  12299. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12300. #if defined(WOLFSSL_ASYNC_CRYPT)
  12301. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12302. #endif
  12303. if (ret != 0) {
  12304. ret = WC_TEST_RET_ENC_EC(ret);
  12305. break;
  12306. }
  12307. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12308. #if defined(WOLFSSL_ASYNC_CRYPT)
  12309. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12310. #endif
  12311. if (ret != 0) {
  12312. ret = WC_TEST_RET_ENC_EC(ret);
  12313. break;
  12314. }
  12315. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12316. ret = WC_TEST_RET_ENC_NC;
  12317. break;
  12318. }
  12319. }
  12320. if (ret != 0)
  12321. break;
  12322. }
  12323. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12324. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12325. * message by AES_BLOCK_SIZE for each size of AES key. */
  12326. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12327. for (keySz = 16; keySz <= 32; keySz += 8) {
  12328. for (msgSz = AES_BLOCK_SIZE;
  12329. msgSz <= sizeof(bigMsg);
  12330. msgSz += AES_BLOCK_SIZE) {
  12331. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12332. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12333. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12334. if (ret != 0) {
  12335. ret = WC_TEST_RET_ENC_EC(ret);
  12336. break;
  12337. }
  12338. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12339. if (ret != 0) {
  12340. ret = WC_TEST_RET_ENC_EC(ret);
  12341. break;
  12342. }
  12343. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12344. #if defined(WOLFSSL_ASYNC_CRYPT)
  12345. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12346. #endif
  12347. if (ret != 0) {
  12348. ret = WC_TEST_RET_ENC_EC(ret);
  12349. break;
  12350. }
  12351. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12352. #if defined(WOLFSSL_ASYNC_CRYPT)
  12353. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12354. #endif
  12355. if (ret != 0) {
  12356. ret = WC_TEST_RET_ENC_EC(ret);
  12357. break;
  12358. }
  12359. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12360. ret = WC_TEST_RET_ENC_NC;
  12361. break;
  12362. }
  12363. }
  12364. if (ret != 0)
  12365. break;
  12366. }
  12367. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12368. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12369. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12370. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12371. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12372. #endif
  12373. if (ret != 0)
  12374. goto out;
  12375. }
  12376. #endif /* WOLFSSL_AESNI && HAVE_AES_DECRYPT */
  12377. /* Test of AES IV state with encrypt/decrypt */
  12378. #if defined(WOLFSSL_AES_128) && !defined(HAVE_RENESAS_SYNC)
  12379. {
  12380. /* Test Vector from "NIST Special Publication 800-38A, 2001 Edition"
  12381. * https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf
  12382. */
  12383. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  12384. {
  12385. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  12386. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  12387. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  12388. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
  12389. };
  12390. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] =
  12391. {
  12392. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  12393. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  12394. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  12395. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2
  12396. };
  12397. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  12398. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  12399. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  12400. };
  12401. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  12402. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  12403. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  12404. };
  12405. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  12406. if (ret != 0)
  12407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12408. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 2);
  12409. ret = wc_AesCbcEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE);
  12410. #if defined(WOLFSSL_ASYNC_CRYPT)
  12411. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12412. #endif
  12413. if (ret != 0)
  12414. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12415. #ifndef HAVE_RENESAS_SYNC
  12416. if (XMEMCMP(cipher, verify2, AES_BLOCK_SIZE))
  12417. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12418. #endif
  12419. ret = wc_AesCbcEncrypt(enc, cipher + AES_BLOCK_SIZE,
  12420. msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12421. #if defined(WOLFSSL_ASYNC_CRYPT)
  12422. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12423. #endif
  12424. if (ret != 0)
  12425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12426. if (XMEMCMP(cipher + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE,
  12427. AES_BLOCK_SIZE))
  12428. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12429. #if defined(HAVE_AES_DECRYPT)
  12430. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION);
  12431. if (ret != 0)
  12432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12433. XMEMSET(plain, 0, AES_BLOCK_SIZE * 2);
  12434. ret = wc_AesCbcDecrypt(dec, plain, verify2, AES_BLOCK_SIZE);
  12435. #if defined(WOLFSSL_ASYNC_CRYPT)
  12436. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12437. #endif
  12438. if (ret != 0)
  12439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12440. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE))
  12441. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12442. ret = wc_AesCbcDecrypt(dec, plain + AES_BLOCK_SIZE,
  12443. verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12444. #if defined(WOLFSSL_ASYNC_CRYPT)
  12445. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12446. #endif
  12447. if (ret != 0)
  12448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12449. if (XMEMCMP(plain + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE,
  12450. AES_BLOCK_SIZE)) {
  12451. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare");
  12452. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12453. }
  12454. #endif /* HAVE_AES_DECRYPT */
  12455. }
  12456. #endif /* WOLFSSL_AES_128 && !HAVE_RENESAS_SYNC */
  12457. #endif /* HAVE_AES_CBC */
  12458. #ifdef WOLFSSL_AES_COUNTER
  12459. ret = aesctr_test(enc, dec, cipher, plain);
  12460. if (ret != 0)
  12461. return ret;
  12462. #endif
  12463. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  12464. {
  12465. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  12466. {
  12467. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12468. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12469. };
  12470. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  12471. {
  12472. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12473. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12474. };
  12475. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  12476. {
  12477. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12478. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12479. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12480. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12481. };
  12482. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12483. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  12484. if (ret != 0)
  12485. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12486. #if !defined(HAVE_SELFTEST) && \
  12487. (defined(WOLFSSL_LINUXKM) || \
  12488. !defined(HAVE_FIPS) || \
  12489. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12490. ret = wc_AesEncryptDirect(enc, cipher, niPlain);
  12491. if (ret != 0)
  12492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12493. #else
  12494. wc_AesEncryptDirect(enc, cipher, niPlain);
  12495. #endif
  12496. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  12497. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12498. #ifdef HAVE_AES_DECRYPT
  12499. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12500. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  12501. if (ret != 0)
  12502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12503. #if !defined(HAVE_SELFTEST) && \
  12504. (defined(WOLFSSL_LINUXKM) || \
  12505. !defined(HAVE_FIPS) || \
  12506. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12507. ret = wc_AesDecryptDirect(dec, plain, niCipher);
  12508. if (ret != 0)
  12509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12510. #else
  12511. wc_AesDecryptDirect(dec, plain, niCipher);
  12512. #endif
  12513. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  12514. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12515. #endif /* HAVE_AES_DECRYPT */
  12516. }
  12517. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  12518. #ifndef HAVE_RENESAS_SYNC
  12519. ret = aes_key_size_test();
  12520. if (ret != 0)
  12521. goto out;
  12522. #endif
  12523. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  12524. !defined(HAVE_RENESAS_SYNC)
  12525. ret = aes_cbc_test();
  12526. if (ret != 0)
  12527. goto out;
  12528. #endif
  12529. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12530. ret = aesecb_test();
  12531. if (ret != 0)
  12532. goto out;
  12533. #endif
  12534. out:
  12535. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_DIRECT)
  12536. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12537. if (enc) {
  12538. if (enc_inited)
  12539. wc_AesFree(enc);
  12540. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12541. }
  12542. #else
  12543. if (enc_inited)
  12544. wc_AesFree(enc);
  12545. #endif
  12546. (void)cipher;
  12547. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12548. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12549. if (dec) {
  12550. if (dec_inited)
  12551. wc_AesFree(dec);
  12552. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12553. }
  12554. #else
  12555. if (dec_inited)
  12556. wc_AesFree(dec);
  12557. #endif
  12558. (void)plain;
  12559. #endif /* HAVE_AES_DECRYPT || WOLFSSL_AES_COUNTER */
  12560. #endif /* HAVE_AES_CBC || WOLFSSL_AES_COUNTER || WOLFSSL_AES_DIRECT */
  12561. return ret;
  12562. }
  12563. #if defined(WOLFSSL_AES_CFB)
  12564. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
  12565. {
  12566. int ret;
  12567. WOLFSSL_ENTER("aes_cfb_test");
  12568. ret = aescfb_test_0();
  12569. if (ret != 0)
  12570. return ret;
  12571. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  12572. ret = aescfb1_test();
  12573. if (ret != 0)
  12574. return ret;
  12575. ret = aescfb8_test();
  12576. if (ret != 0)
  12577. return ret;
  12578. #endif
  12579. return 0;
  12580. }
  12581. #endif
  12582. #if defined(WOLFSSL_AES_XTS)
  12583. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void)
  12584. {
  12585. int ret = 0;
  12586. WOLFSSL_ENTER("aes_xts_test");
  12587. #ifdef WOLFSSL_AES_128
  12588. ret = aes_xts_128_test();
  12589. if (ret != 0)
  12590. return ret;
  12591. #endif
  12592. #ifdef WOLFSSL_AES_192
  12593. ret = aes_xts_192_test();
  12594. if (ret != 0)
  12595. return ret;
  12596. #endif
  12597. #ifdef WOLFSSL_AES_256
  12598. ret = aes_xts_256_test();
  12599. if (ret != 0)
  12600. return ret;
  12601. #endif
  12602. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  12603. ret = aes_xts_sector_test();
  12604. if (ret != 0)
  12605. return ret;
  12606. #endif
  12607. #ifdef WOLFSSL_AES_128
  12608. ret = aes_xts_args_test();
  12609. if (ret != 0)
  12610. return ret;
  12611. #endif
  12612. return 0;
  12613. }
  12614. #endif
  12615. #ifdef WOLFSSL_AES_192
  12616. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
  12617. {
  12618. wc_test_ret_t ret = 0;
  12619. #ifdef HAVE_AES_CBC
  12620. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12621. Aes *enc = NULL;
  12622. #else
  12623. Aes enc[1];
  12624. #endif
  12625. int enc_inited = 0;
  12626. byte cipher[AES_BLOCK_SIZE];
  12627. #ifdef HAVE_AES_DECRYPT
  12628. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12629. Aes *dec = NULL;
  12630. #else
  12631. Aes dec[1];
  12632. #endif
  12633. byte plain[AES_BLOCK_SIZE];
  12634. #endif
  12635. #ifdef HAVE_AES_DECRYPT
  12636. int dec_inited = 0;
  12637. #endif
  12638. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  12639. * Appendix F.2.3 */
  12640. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12641. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12642. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12643. };
  12644. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12645. {
  12646. 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  12647. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8
  12648. };
  12649. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12650. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  12651. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  12652. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  12653. };
  12654. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12655. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12656. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12657. };
  12658. WOLFSSL_ENTER("aes192_test");
  12659. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12660. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12661. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12662. #ifdef HAVE_AES_DECRYPT
  12663. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12664. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12665. #endif
  12666. #endif
  12667. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12668. if (ret != 0)
  12669. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12670. enc_inited = 1;
  12671. #ifdef HAVE_AES_DECRYPT
  12672. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12673. if (ret != 0)
  12674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12675. dec_inited = 1;
  12676. #endif
  12677. ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
  12678. if (ret != 0)
  12679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12680. #ifdef HAVE_AES_DECRYPT
  12681. ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
  12682. if (ret != 0)
  12683. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12684. #endif
  12685. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12686. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12687. #if defined(WOLFSSL_ASYNC_CRYPT)
  12688. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12689. #endif
  12690. if (ret != 0)
  12691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12692. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12693. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12694. #ifdef HAVE_AES_DECRYPT
  12695. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12696. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12697. #if defined(WOLFSSL_ASYNC_CRYPT)
  12698. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12699. #endif
  12700. if (ret != 0)
  12701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12702. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12703. WOLFSSL_MSG("failed wc_AesCbcDecrypt plain-msg compare");
  12704. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12705. }
  12706. #endif
  12707. out:
  12708. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12709. if (enc) {
  12710. if (enc_inited)
  12711. wc_AesFree(enc);
  12712. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12713. }
  12714. #ifdef HAVE_AES_DECRYPT
  12715. if (dec) {
  12716. if (dec_inited)
  12717. wc_AesFree(dec);
  12718. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12719. }
  12720. #endif
  12721. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  12722. if (enc_inited)
  12723. wc_AesFree(enc);
  12724. #ifdef HAVE_AES_DECRYPT
  12725. if (dec_inited)
  12726. wc_AesFree(dec);
  12727. #endif
  12728. #endif
  12729. #endif /* HAVE_AES_CBC */
  12730. return ret;
  12731. }
  12732. #endif /* WOLFSSL_AES_192 */
  12733. #ifdef WOLFSSL_AES_256
  12734. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
  12735. {
  12736. #ifdef HAVE_AES_CBC
  12737. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12738. Aes *enc = NULL;
  12739. #else
  12740. Aes enc[1];
  12741. #endif
  12742. int enc_inited = 0;
  12743. byte cipher[AES_BLOCK_SIZE];
  12744. #ifdef HAVE_AES_DECRYPT
  12745. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12746. Aes *dec = NULL;
  12747. #else
  12748. Aes dec[1];
  12749. #endif
  12750. int dec_inited = 0;
  12751. byte plain[AES_BLOCK_SIZE];
  12752. #endif
  12753. #endif /* HAVE_AES_CBC */
  12754. wc_test_ret_t ret = 0;
  12755. #ifdef HAVE_AES_CBC
  12756. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  12757. * Appendix F.2.5 */
  12758. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12759. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12760. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12761. };
  12762. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12763. {
  12764. 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  12765. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6
  12766. };
  12767. #ifdef HAVE_RENESAS_SYNC
  12768. byte *key =
  12769. (byte*)guser_PKCbInfo.wrapped_key_aes256;
  12770. int keySz = (256/8);
  12771. #else
  12772. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12773. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12774. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12775. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12776. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12777. };
  12778. int keySz = (int)sizeof(key);
  12779. #endif
  12780. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12781. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12782. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12783. };
  12784. WOLFSSL_ENTER("aes256_test");
  12785. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12786. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12787. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12788. #ifdef HAVE_AES_DECRYPT
  12789. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12790. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12791. #endif
  12792. #endif
  12793. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12794. if (ret != 0)
  12795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12796. enc_inited = 1;
  12797. #ifdef HAVE_AES_DECRYPT
  12798. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12799. if (ret != 0)
  12800. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12801. dec_inited = 1;
  12802. #endif
  12803. ret = wc_AesSetKey(enc, key, (word32)keySz, iv, AES_ENCRYPTION);
  12804. if (ret != 0)
  12805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12806. #ifdef HAVE_AES_DECRYPT
  12807. ret = wc_AesSetKey(dec, key, (word32)keySz, iv, AES_DECRYPTION);
  12808. if (ret != 0)
  12809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12810. #endif
  12811. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12812. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12813. #if defined(WOLFSSL_ASYNC_CRYPT)
  12814. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12815. #endif
  12816. if (ret != 0)
  12817. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12818. #ifdef HAVE_AES_DECRYPT
  12819. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12820. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12821. #if defined(WOLFSSL_ASYNC_CRYPT)
  12822. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12823. #endif
  12824. if (ret != 0)
  12825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12826. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12827. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12828. }
  12829. #endif
  12830. #ifndef HAVE_RENESAS_SYNC
  12831. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12832. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12833. #endif
  12834. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12835. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12836. if (ret != 0)
  12837. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12838. #ifdef HAVE_AES_DECRYPT
  12839. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12840. if (ret != 0)
  12841. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12842. #endif
  12843. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12844. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12845. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12846. #if defined(WOLFSSL_ASYNC_CRYPT)
  12847. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12848. #endif
  12849. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12850. if (ret != 0)
  12851. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12852. #ifdef HAVE_AES_DECRYPT
  12853. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12854. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12855. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12856. #if defined(WOLFSSL_ASYNC_CRYPT)
  12857. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12858. #endif
  12859. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12860. if (ret != 0)
  12861. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12862. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12863. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12864. }
  12865. #endif
  12866. #ifndef HAVE_RENESAS_SYNC
  12867. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12868. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12869. #endif
  12870. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12871. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12872. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12873. if (ret != 0)
  12874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12875. #ifdef HAVE_AES_DECRYPT
  12876. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12877. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12878. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12879. if (ret != 0)
  12880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12881. #endif
  12882. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12883. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12884. #if defined(WOLFSSL_ASYNC_CRYPT)
  12885. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12886. #endif
  12887. if (ret != 0)
  12888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12889. #ifdef HAVE_AES_DECRYPT
  12890. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12891. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12892. #if defined(WOLFSSL_ASYNC_CRYPT)
  12893. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12894. #endif
  12895. if (ret != 0)
  12896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12897. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12898. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12899. }
  12900. #endif
  12901. #ifndef HAVE_RENESAS_SYNC
  12902. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12903. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12904. #endif
  12905. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12906. out:
  12907. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12908. if (enc) {
  12909. if (enc_inited)
  12910. wc_AesFree(enc);
  12911. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12912. }
  12913. #ifdef HAVE_AES_DECRYPT
  12914. if (dec) {
  12915. if (dec_inited)
  12916. wc_AesFree(dec);
  12917. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12918. }
  12919. #endif
  12920. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  12921. if (enc_inited)
  12922. wc_AesFree(enc);
  12923. #ifdef HAVE_AES_DECRYPT
  12924. if (dec_inited)
  12925. wc_AesFree(dec);
  12926. #endif /* HAVE_AES_DECRYPT */
  12927. #endif /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  12928. #endif /* HAVE_AES_CBC */
  12929. return ret;
  12930. }
  12931. #endif /* WOLFSSL_AES_256 */
  12932. #ifdef HAVE_AESGCM
  12933. #ifdef WOLFSSL_AES_128
  12934. static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
  12935. byte* plain, int plainSz, byte* cipher, int cipherSz,
  12936. byte* aad, int aadSz, byte* tag, int tagSz)
  12937. {
  12938. wc_test_ret_t ret;
  12939. int enc_inited = 0, dec_inited = 0;
  12940. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12941. Aes *enc = NULL;
  12942. Aes *dec = NULL;
  12943. #else
  12944. Aes enc[1];
  12945. Aes dec[1];
  12946. #endif
  12947. byte resultT[AES_BLOCK_SIZE];
  12948. byte resultP[AES_BLOCK_SIZE * 3];
  12949. byte resultC[AES_BLOCK_SIZE * 3];
  12950. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12951. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12952. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12953. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12954. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12955. #endif
  12956. XMEMSET(resultT, 0, sizeof(resultT));
  12957. XMEMSET(resultC, 0, sizeof(resultC));
  12958. XMEMSET(resultP, 0, sizeof(resultP));
  12959. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12960. if (ret != 0)
  12961. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12962. else
  12963. enc_inited = 1;
  12964. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12965. if (ret != 0)
  12966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12967. else
  12968. dec_inited = 1;
  12969. ret = wc_AesGcmSetKey(enc, key, (word32)keySz);
  12970. if (ret != 0)
  12971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12972. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  12973. ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, ivSz,
  12974. resultT, (word32)tagSz, aad, aadSz);
  12975. #if defined(WOLFSSL_ASYNC_CRYPT)
  12976. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12977. #endif
  12978. if (ret != 0)
  12979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12980. if (cipher != NULL) {
  12981. if (XMEMCMP(cipher, resultC, cipherSz))
  12982. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12983. }
  12984. if (XMEMCMP(tag, resultT, tagSz))
  12985. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12986. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12987. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12988. ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz,
  12989. resultT, tagSz, aad, aadSz);
  12990. #if defined(WOLFSSL_ASYNC_CRYPT)
  12991. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12992. #endif
  12993. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12994. if (ret != 0)
  12995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12996. if (cipher != NULL) {
  12997. if (XMEMCMP(cipher, resultC, cipherSz))
  12998. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12999. }
  13000. if (XMEMCMP(tag, resultT, tagSz))
  13001. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13002. #endif
  13003. #ifdef HAVE_AES_DECRYPT
  13004. ret = wc_AesGcmSetKey(dec, key, (word32)keySz);
  13005. if (ret != 0)
  13006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13007. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz,
  13008. iv, (word32)ivSz, resultT, tagSz, aad, aadSz);
  13009. #if defined(WOLFSSL_ASYNC_CRYPT)
  13010. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13011. #endif
  13012. if (ret != 0)
  13013. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13014. if (plain != NULL) {
  13015. if (XMEMCMP(plain, resultP, plainSz))
  13016. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13017. }
  13018. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13019. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13020. ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz,
  13021. iv, ivSz, resultT, tagSz, aad, aadSz);
  13022. #if defined(WOLFSSL_ASYNC_CRYPT)
  13023. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13024. #endif
  13025. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13026. if (ret != 0)
  13027. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13028. if (plain != NULL) {
  13029. if (XMEMCMP(plain, resultP, plainSz))
  13030. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13031. }
  13032. #endif
  13033. #endif /* HAVE_AES_DECRYPT */
  13034. ret = 0;
  13035. out:
  13036. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13037. if (enc) {
  13038. if (enc_inited)
  13039. wc_AesFree(enc);
  13040. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  13041. }
  13042. if (dec) {
  13043. if (dec_inited)
  13044. wc_AesFree(dec);
  13045. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  13046. }
  13047. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  13048. if (enc_inited)
  13049. wc_AesFree(enc);
  13050. if (dec_inited)
  13051. wc_AesFree(dec);
  13052. #endif
  13053. return ret;
  13054. }
  13055. #endif
  13056. /* tests that only use 12 byte IV and 16 or less byte AAD
  13057. * test vectors are from NIST SP 800-38D
  13058. * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES*/
  13059. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void)
  13060. {
  13061. #ifdef WOLFSSL_AES_128
  13062. byte key1[] = {
  13063. 0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62,
  13064. 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc
  13065. };
  13066. byte iv1[] = {
  13067. 0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa,
  13068. 0xe4, 0xed, 0x2f, 0x6d
  13069. };
  13070. ALIGN64 byte plain1[] = {
  13071. 0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad,
  13072. 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01,
  13073. 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac,
  13074. 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01
  13075. };
  13076. byte aad1[] = {
  13077. 0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73,
  13078. 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1
  13079. };
  13080. ALIGN64 byte cipher1[] = {
  13081. 0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d,
  13082. 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d,
  13083. 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46,
  13084. 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb
  13085. };
  13086. byte tag1[] = {
  13087. 0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7,
  13088. 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2
  13089. };
  13090. byte key2[] = {
  13091. 0x01, 0x6d, 0xbb, 0x38, 0xda, 0xa7, 0x6d, 0xfe,
  13092. 0x7d, 0xa3, 0x84, 0xeb, 0xf1, 0x24, 0x03, 0x64
  13093. };
  13094. byte iv2[] = {
  13095. 0x07, 0x93, 0xef, 0x3a, 0xda, 0x78, 0x2f, 0x78,
  13096. 0xc9, 0x8a, 0xff, 0xe3
  13097. };
  13098. ALIGN64 byte plain2[] = {
  13099. 0x4b, 0x34, 0xa9, 0xec, 0x57, 0x63, 0x52, 0x4b,
  13100. 0x19, 0x1d, 0x56, 0x16, 0xc5, 0x47, 0xf6, 0xb7
  13101. };
  13102. ALIGN64 byte cipher2[] = {
  13103. 0x60, 0x9a, 0xa3, 0xf4, 0x54, 0x1b, 0xc0, 0xfe,
  13104. 0x99, 0x31, 0xda, 0xad, 0x2e, 0xe1, 0x5d, 0x0c
  13105. };
  13106. byte tag2[] = {
  13107. 0x33, 0xaf, 0xec, 0x59, 0xc4, 0x5b, 0xaf, 0x68,
  13108. 0x9a, 0x5e, 0x1b, 0x13, 0xae, 0x42, 0x36, 0x19
  13109. };
  13110. byte key3[] = {
  13111. 0xb0, 0x1e, 0x45, 0xcc, 0x30, 0x88, 0xaa, 0xba,
  13112. 0x9f, 0xa4, 0x3d, 0x81, 0xd4, 0x81, 0x82, 0x3f
  13113. };
  13114. byte iv3[] = {
  13115. 0x5a, 0x2c, 0x4a, 0x66, 0x46, 0x87, 0x13, 0x45,
  13116. 0x6a, 0x4b, 0xd5, 0xe1
  13117. };
  13118. byte tag3[] = {
  13119. 0x01, 0x42, 0x80, 0xf9, 0x44, 0xf5, 0x3c, 0x68,
  13120. 0x11, 0x64, 0xb2, 0xff
  13121. };
  13122. wc_test_ret_t ret;
  13123. WOLFSSL_ENTER("aesgcm_default_test");
  13124. ret = aesgcm_default_test_helper(key1, sizeof(key1), iv1, sizeof(iv1),
  13125. plain1, sizeof(plain1), cipher1, sizeof(cipher1),
  13126. aad1, sizeof(aad1), tag1, sizeof(tag1));
  13127. if (ret != 0) {
  13128. return ret;
  13129. }
  13130. ret = aesgcm_default_test_helper(key2, sizeof(key2), iv2, sizeof(iv2),
  13131. plain2, sizeof(plain2), cipher2, sizeof(cipher2),
  13132. NULL, 0, tag2, sizeof(tag2));
  13133. if (ret != 0) {
  13134. return ret;
  13135. }
  13136. ret = aesgcm_default_test_helper(key3, sizeof(key3), iv3, sizeof(iv3),
  13137. NULL, 0, NULL, 0,
  13138. NULL, 0, tag3, sizeof(tag3));
  13139. if (ret != 0) {
  13140. return ret;
  13141. }
  13142. #endif
  13143. return 0;
  13144. }
  13145. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
  13146. {
  13147. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13148. Aes *enc = NULL;
  13149. Aes *dec = NULL;
  13150. #else
  13151. Aes enc[1];
  13152. Aes dec[1];
  13153. #endif
  13154. /*
  13155. * This is Test Case 16 from the document Galois/
  13156. * Counter Mode of Operation (GCM) by McGrew and
  13157. * Viega.
  13158. */
  13159. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  13160. {
  13161. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  13162. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  13163. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  13164. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  13165. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  13166. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  13167. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  13168. 0xba, 0x63, 0x7b, 0x39
  13169. };
  13170. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  13171. {
  13172. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13173. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13174. 0xab, 0xad, 0xda, 0xd2
  13175. };
  13176. #ifdef WOLFSSL_AES_256
  13177. #ifdef HAVE_RENESAS_SYNC
  13178. const byte *k1 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  13179. int k1Sz = (int)(256/8);
  13180. #else
  13181. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13182. {
  13183. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13184. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13185. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13186. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  13187. };
  13188. int k1Sz = (int)sizeof(k1);
  13189. #endif
  13190. #endif /* WOLFSSL_AES_256 */
  13191. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13192. {
  13193. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  13194. 0xde, 0xca, 0xf8, 0x88
  13195. };
  13196. #if defined(WOLFSSL_AES_256) || defined(WOLFSSL_AES_192)
  13197. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  13198. {
  13199. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  13200. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  13201. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  13202. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  13203. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  13204. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  13205. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  13206. 0xbc, 0xc9, 0xf6, 0x62
  13207. };
  13208. #endif /* WOLFSSL_AES_256 || WOLFSSL_AES_192 */
  13209. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13210. {
  13211. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  13212. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  13213. };
  13214. /* FIPS, QAT and PIC32MZ HW Crypto only support 12-byte IV */
  13215. #if !defined(HAVE_FIPS) && \
  13216. !defined(WOLFSSL_PIC32MZ_CRYPT) && \
  13217. !defined(FREESCALE_LTC) && !defined(FREESCALE_MMCAU) && \
  13218. !defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13219. !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_AES) && \
  13220. !(defined(WOLF_CRYPTO_CB) && \
  13221. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  13222. #define ENABLE_NON_12BYTE_IV_TEST
  13223. #ifdef WOLFSSL_AES_192
  13224. /* Test Case 12, uses same plaintext and AAD data. */
  13225. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13226. {
  13227. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13228. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13229. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  13230. };
  13231. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13232. {
  13233. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  13234. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  13235. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  13236. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  13237. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  13238. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  13239. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  13240. 0xa6, 0x37, 0xb3, 0x9b
  13241. };
  13242. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  13243. {
  13244. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  13245. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  13246. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  13247. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  13248. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  13249. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  13250. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  13251. 0xe9, 0xb7, 0x37, 0x3b
  13252. };
  13253. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13254. {
  13255. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  13256. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  13257. };
  13258. #endif /* WOLFSSL_AES_192 */
  13259. #ifdef WOLFSSL_AES_128
  13260. /* The following is an interesting test case from the example
  13261. * FIPS test vectors for AES-GCM. IVlen = 1 byte */
  13262. WOLFSSL_SMALL_STACK_STATIC const byte p3[] =
  13263. {
  13264. 0x57, 0xce, 0x45, 0x1f, 0xa5, 0xe2, 0x35, 0xa5,
  13265. 0x8e, 0x1a, 0xa2, 0x3b, 0x77, 0xcb, 0xaf, 0xe2
  13266. };
  13267. #ifdef HAVE_RENESAS_SYNC
  13268. const byte *k3 =
  13269. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  13270. int k3Sz = (int)(128/8);
  13271. #else
  13272. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  13273. {
  13274. 0xbb, 0x01, 0xd7, 0x03, 0x81, 0x1c, 0x10, 0x1a,
  13275. 0x35, 0xe0, 0xff, 0xd2, 0x91, 0xba, 0xf2, 0x4b
  13276. };
  13277. int k3Sz = (int)sizeof(k3);
  13278. #endif
  13279. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  13280. {
  13281. 0xca
  13282. };
  13283. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  13284. {
  13285. 0x6b, 0x5f, 0xb3, 0x9d, 0xc1, 0xc5, 0x7a, 0x4f,
  13286. 0xf3, 0x51, 0x4d, 0xc2, 0xd5, 0xf0, 0xd0, 0x07
  13287. };
  13288. WOLFSSL_SMALL_STACK_STATIC const byte a3[] =
  13289. {
  13290. 0x40, 0xfc, 0xdc, 0xd7, 0x4a, 0xd7, 0x8b, 0xf1,
  13291. 0x3e, 0x7c, 0x60, 0x55, 0x50, 0x51, 0xdd, 0x54
  13292. };
  13293. WOLFSSL_SMALL_STACK_STATIC const byte t3[] =
  13294. {
  13295. 0x06, 0x90, 0xed, 0x01, 0x34, 0xdd, 0xc6, 0x95,
  13296. 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
  13297. };
  13298. #endif /* WOLFSSL_AES_128 */
  13299. #ifdef WOLFSSL_AES_256
  13300. int ivlen;
  13301. #endif
  13302. #endif
  13303. byte resultT[sizeof(t1) + AES_BLOCK_SIZE];
  13304. byte resultP[sizeof(p) + AES_BLOCK_SIZE];
  13305. byte resultC[sizeof(p) + AES_BLOCK_SIZE];
  13306. wc_test_ret_t ret = 0;
  13307. int alen;
  13308. int plen;
  13309. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13310. byte buf[sizeof(p) + AES_BLOCK_SIZE];
  13311. byte bufA[sizeof(a) + 1];
  13312. byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13313. #endif
  13314. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM)
  13315. #if !defined(BENCH_AESGCM_LARGE)
  13316. #define BENCH_AESGCM_LARGE 1024
  13317. #endif
  13318. #ifndef WOLFSSL_NO_MALLOC
  13319. byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13320. byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13321. byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13322. (void)alen;
  13323. (void)plen;
  13324. if ((! large_input) || (! large_output) || (! large_outdec))
  13325. ERROR_OUT(MEMORY_E, out);
  13326. #else
  13327. byte large_input[BENCH_AESGCM_LARGE];
  13328. byte large_output[BENCH_AESGCM_LARGE + AES_BLOCK_SIZE];
  13329. byte large_outdec[BENCH_AESGCM_LARGE];
  13330. #endif
  13331. XMEMSET(large_input, 0, BENCH_AESGCM_LARGE);
  13332. XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + AES_BLOCK_SIZE);
  13333. XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE);
  13334. #endif
  13335. WOLFSSL_ENTER("aesgcm_test");
  13336. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13337. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  13338. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  13339. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  13340. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  13341. #endif
  13342. XMEMSET(resultT, 0, sizeof(resultT));
  13343. XMEMSET(resultC, 0, sizeof(resultC));
  13344. XMEMSET(resultP, 0, sizeof(resultP));
  13345. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13346. if (ret != 0)
  13347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13348. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13349. if (ret != 0)
  13350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13351. #ifdef WOLFSSL_AES_256
  13352. ret = wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13353. if (ret != 0)
  13354. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13355. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13356. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13357. resultT, sizeof(t1), a, sizeof(a));
  13358. #if defined(WOLFSSL_ASYNC_CRYPT)
  13359. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13360. #endif
  13361. if (ret != 0)
  13362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13363. #ifndef HAVE_RENESAS_SYNC
  13364. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13365. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13366. if (XMEMCMP(t1, resultT, sizeof(t1)))
  13367. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13368. #endif
  13369. #ifdef HAVE_AES_DECRYPT
  13370. ret = wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13371. if (ret != 0)
  13372. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13373. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
  13374. iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13375. #if defined(WOLFSSL_ASYNC_CRYPT)
  13376. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13377. #endif
  13378. if (ret != 0)
  13379. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13380. if (XMEMCMP(p, resultP, sizeof(p)))
  13381. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13382. #endif /* HAVE_AES_DECRYPT */
  13383. /* Large buffer test */
  13384. #ifdef BENCH_AESGCM_LARGE
  13385. /* setup test buffer */
  13386. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13387. large_input[alen] = (byte)alen;
  13388. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13389. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13390. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13391. resultT, sizeof(t1), a, sizeof(a));
  13392. #if defined(WOLFSSL_ASYNC_CRYPT)
  13393. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13394. #endif
  13395. if (ret != 0)
  13396. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13397. #ifdef HAVE_AES_DECRYPT
  13398. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13399. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13400. sizeof(t1), a, sizeof(a));
  13401. #if defined(WOLFSSL_ASYNC_CRYPT)
  13402. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13403. #endif
  13404. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13405. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13406. if (ret != 0)
  13407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13408. #endif /* HAVE_AES_DECRYPT */
  13409. #endif /* BENCH_AESGCM_LARGE */
  13410. #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256)
  13411. /* Variable IV length test */
  13412. for (ivlen=1; ivlen<k1Sz; ivlen++) {
  13413. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13414. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1,
  13415. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13416. #if defined(WOLFSSL_ASYNC_CRYPT)
  13417. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13418. #endif
  13419. if (ret != 0)
  13420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13421. #ifdef HAVE_AES_DECRYPT
  13422. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1,
  13423. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13424. #if defined(WOLFSSL_ASYNC_CRYPT)
  13425. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13426. #endif
  13427. if (ret != 0)
  13428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13429. #endif /* HAVE_AES_DECRYPT */
  13430. }
  13431. #endif
  13432. #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC))
  13433. /* Variable authenticated data length test */
  13434. for (alen=0; alen<(int)sizeof(p); alen++) {
  13435. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13436. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13437. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13438. #if defined(WOLFSSL_ASYNC_CRYPT)
  13439. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13440. #endif
  13441. if (ret != 0)
  13442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13443. #ifdef HAVE_AES_DECRYPT
  13444. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13445. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13446. #if defined(WOLFSSL_ASYNC_CRYPT)
  13447. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13448. #endif
  13449. if (ret != 0)
  13450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13451. #endif /* HAVE_AES_DECRYPT */
  13452. }
  13453. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13454. if (! large_aad)
  13455. ERROR_OUT(MEMORY_E, out);
  13456. XMEMSET(large_aad, 0, 1024+16);
  13457. /* Variable authenticated data length test */
  13458. for (alen=0; alen<=1024; alen+=16) {
  13459. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13460. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13461. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13462. if (ret != 0)
  13463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13464. #ifdef HAVE_AES_DECRYPT
  13465. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13466. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13467. if (ret != 0)
  13468. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13469. #endif /* HAVE_AES_DECRYPT */
  13470. }
  13471. /* Test unaligned memory of all potential arguments */
  13472. ret = wc_AesGcmSetKey(enc, k1, k1Sz);
  13473. if (ret != 0)
  13474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13475. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13476. XMEMCPY(&buf[1], p, sizeof(p));
  13477. XMEMCPY(&bufA[1], a, sizeof(a));
  13478. ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1),
  13479. &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13480. if (ret != 0)
  13481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13482. if (XMEMCMP(c1, &resultC[1], sizeof(c1)))
  13483. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13484. if (XMEMCMP(t1, &resultT[1], sizeof(t1)))
  13485. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13486. #ifdef HAVE_AES_DECRYPT
  13487. ret = wc_AesGcmSetKey(dec, k1, k1Sz);
  13488. if (ret != 0)
  13489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13490. ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1),
  13491. iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13492. if (ret != 0)
  13493. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13494. if (XMEMCMP(p, &resultP[1], sizeof(p)))
  13495. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13496. #endif /* HAVE_AES_DECRYPT */
  13497. #endif /* Xilinx Versal */
  13498. #endif
  13499. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13500. #ifdef BENCH_AESGCM_LARGE
  13501. /* Variable plain text length test */
  13502. for (plen=1; plen<BENCH_AESGCM_LARGE; plen++) {
  13503. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13504. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13505. (word32)plen, iv1, sizeof(iv1), resultT,
  13506. sizeof(t1), a, sizeof(a));
  13507. #if defined(WOLFSSL_ASYNC_CRYPT)
  13508. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13509. #endif
  13510. if (ret != 0)
  13511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13512. #ifdef HAVE_AES_DECRYPT
  13513. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13514. (word32)plen, iv1, sizeof(iv1), resultT,
  13515. sizeof(t1), a, sizeof(a));
  13516. #if defined(WOLFSSL_ASYNC_CRYPT)
  13517. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13518. #endif
  13519. if (ret != 0)
  13520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13521. #endif /* HAVE_AES_DECRYPT */
  13522. }
  13523. #else /* BENCH_AESGCM_LARGE */
  13524. /* Variable plain text length test */
  13525. for (plen=1; plen<(int)sizeof(p); plen++) {
  13526. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13527. ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1,
  13528. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13529. #if defined(WOLFSSL_ASYNC_CRYPT)
  13530. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13531. #endif
  13532. if (ret != 0)
  13533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13534. #ifdef HAVE_AES_DECRYPT
  13535. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1,
  13536. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13537. #if defined(WOLFSSL_ASYNC_CRYPT)
  13538. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13539. #endif
  13540. if (ret != 0)
  13541. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13542. #endif /* HAVE_AES_DECRYPT */
  13543. }
  13544. #endif /* BENCH_AESGCM_LARGE */
  13545. #endif
  13546. #endif /* WOLFSSL_AES_256 */
  13547. /* test with IV != 12 bytes */
  13548. #ifdef ENABLE_NON_12BYTE_IV_TEST
  13549. XMEMSET(resultT, 0, sizeof(resultT));
  13550. XMEMSET(resultC, 0, sizeof(resultC));
  13551. XMEMSET(resultP, 0, sizeof(resultP));
  13552. #ifdef WOLFSSL_AES_192
  13553. wc_AesGcmSetKey(enc, k2, sizeof(k2));
  13554. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13555. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2),
  13556. resultT, sizeof(t1), a, sizeof(a));
  13557. #if defined(WOLFSSL_ASYNC_CRYPT)
  13558. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13559. #endif
  13560. if (ret != 0)
  13561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13562. if (XMEMCMP(c2, resultC, sizeof(c2)))
  13563. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13564. if (XMEMCMP(t2, resultT, sizeof(t1)))
  13565. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13566. #ifdef HAVE_AES_DECRYPT
  13567. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1),
  13568. iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a));
  13569. #if defined(WOLFSSL_ASYNC_CRYPT)
  13570. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13571. #endif
  13572. if (ret != 0)
  13573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13574. if (XMEMCMP(p, resultP, sizeof(p)))
  13575. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13576. #endif /* HAVE_AES_DECRYPT */
  13577. /* Large buffer test */
  13578. #ifdef BENCH_AESGCM_LARGE
  13579. wc_AesGcmSetKey(enc, k2, (word32)sizeof(k2));
  13580. wc_AesGcmSetKey(dec, k2, (word32)sizeof(k2));
  13581. /* setup test buffer */
  13582. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13583. large_input[alen] = (byte)alen;
  13584. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13585. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13586. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13587. resultT, sizeof(t1), a, sizeof(a));
  13588. #if defined(WOLFSSL_ASYNC_CRYPT)
  13589. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13590. #endif
  13591. if (ret != 0)
  13592. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13593. #ifdef HAVE_AES_DECRYPT
  13594. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13595. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13596. sizeof(t1), a, sizeof(a));
  13597. #if defined(WOLFSSL_ASYNC_CRYPT)
  13598. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13599. #endif
  13600. if (ret != 0)
  13601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13602. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13603. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13604. #endif /* HAVE_AES_DECRYPT */
  13605. #endif /* BENCH_AESGCM_LARGE */
  13606. XMEMSET(resultT, 0, sizeof(resultT));
  13607. XMEMSET(resultC, 0, sizeof(resultC));
  13608. XMEMSET(resultP, 0, sizeof(resultP));
  13609. #endif /* WOLFSSL_AES_192 */
  13610. #ifdef WOLFSSL_AES_128
  13611. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13612. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13613. ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3),
  13614. resultT, sizeof(t3), a3, sizeof(a3));
  13615. #if defined(WOLFSSL_ASYNC_CRYPT)
  13616. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13617. #endif
  13618. if (ret != 0)
  13619. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13620. #ifndef HAVE_RENESAS_SYNC
  13621. if (XMEMCMP(c3, resultC, sizeof(c3)))
  13622. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13623. if (XMEMCMP(t3, resultT, sizeof(t3)))
  13624. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13625. #endif
  13626. #ifdef HAVE_AES_DECRYPT
  13627. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
  13628. iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3));
  13629. #if defined(WOLFSSL_ASYNC_CRYPT)
  13630. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13631. #endif
  13632. if (ret != 0)
  13633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13634. if (XMEMCMP(p3, resultP, sizeof(p3)))
  13635. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13636. #endif /* HAVE_AES_DECRYPT */
  13637. /* Large buffer test */
  13638. #ifdef BENCH_AESGCM_LARGE
  13639. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13640. wc_AesGcmSetKey(dec, k3, (word32)k3Sz);
  13641. /* setup test buffer */
  13642. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13643. large_input[alen] = (byte)alen;
  13644. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13645. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13646. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13647. resultT, sizeof(t1), a, sizeof(a));
  13648. #if defined(WOLFSSL_ASYNC_CRYPT)
  13649. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13650. #endif
  13651. if (ret != 0)
  13652. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13653. #ifdef HAVE_AES_DECRYPT
  13654. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13655. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13656. sizeof(t1), a, sizeof(a));
  13657. #if defined(WOLFSSL_ASYNC_CRYPT)
  13658. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13659. #endif
  13660. if (ret != 0)
  13661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13662. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13663. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13664. #endif /* HAVE_AES_DECRYPT */
  13665. #endif /* BENCH_AESGCM_LARGE */
  13666. #endif /* WOLFSSL_AES_128 */
  13667. #endif /* ENABLE_NON_12BYTE_IV_TEST */
  13668. #if defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13669. !defined(WOLFSSL_XILINX_CRYPT) && \
  13670. !(defined(WOLF_CRYPTO_CB) && \
  13671. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC))
  13672. XMEMSET(resultT, 0, sizeof(resultT));
  13673. XMEMSET(resultC, 0, sizeof(resultC));
  13674. XMEMSET(resultP, 0, sizeof(resultP));
  13675. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13676. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13677. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13678. resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13679. #if defined(WOLFSSL_ASYNC_CRYPT)
  13680. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13681. #endif
  13682. if (ret != 0)
  13683. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13684. #ifndef HAVE_RENESAS_SYNC
  13685. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13686. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13687. if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1))
  13688. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13689. #endif
  13690. #ifdef HAVE_AES_DECRYPT
  13691. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
  13692. iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13693. #if defined(WOLFSSL_ASYNC_CRYPT)
  13694. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13695. #endif
  13696. if (ret != 0)
  13697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13698. if (XMEMCMP(p, resultP, sizeof(p)))
  13699. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13700. #endif /* HAVE_AES_DECRYPT */
  13701. #endif /* WOLFSSL_AES_256 */
  13702. #if !defined(HAVE_FIPS) || \
  13703. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  13704. /* Test encrypt with internally generated IV */
  13705. #if defined(WOLFSSL_AES_256) && !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST)) \
  13706. && !(defined(WOLF_CRYPTO_CB) && defined(HAVE_CAVIUM_OCTEON_SYNC))
  13707. {
  13708. WC_RNG rng;
  13709. byte randIV[12];
  13710. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13711. if (ret != 0)
  13712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13713. XMEMSET(randIV, 0, sizeof(randIV));
  13714. XMEMSET(resultT, 0, sizeof(resultT));
  13715. XMEMSET(resultC, 0, sizeof(resultC));
  13716. XMEMSET(resultP, 0, sizeof(resultP));
  13717. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13718. ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng);
  13719. if (ret != 0)
  13720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13721. ret = wc_AesGcmEncrypt_ex(enc,
  13722. resultC, p, sizeof(p),
  13723. randIV, sizeof(randIV),
  13724. resultT, sizeof(t1),
  13725. a, sizeof(a));
  13726. #if defined(WOLFSSL_ASYNC_CRYPT)
  13727. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13728. #endif
  13729. if (ret != 0)
  13730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13731. /* Check the IV has been set. */
  13732. {
  13733. word32 i, ivSum = 0;
  13734. for (i = 0; i < sizeof(randIV); i++)
  13735. ivSum += randIV[i];
  13736. if (ivSum == 0)
  13737. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13738. }
  13739. #ifdef HAVE_AES_DECRYPT
  13740. wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13741. ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng);
  13742. if (ret != 0)
  13743. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13744. ret = wc_AesGcmDecrypt(dec,
  13745. resultP, resultC, sizeof(c1),
  13746. randIV, sizeof(randIV),
  13747. resultT, sizeof(t1),
  13748. a, sizeof(a));
  13749. #if defined(WOLFSSL_ASYNC_CRYPT)
  13750. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13751. #endif
  13752. if (ret != 0)
  13753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13754. if (XMEMCMP(p, resultP, sizeof(p)))
  13755. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13756. #endif /* HAVE_AES_DECRYPT */
  13757. wc_FreeRng(&rng);
  13758. }
  13759. #endif /* WOLFSSL_AES_256 && !(WC_NO_RNG || HAVE_SELFTEST) */
  13760. #endif /* HAVE_FIPS_VERSION >= 2 */
  13761. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13762. #ifdef WOLFSSL_AES_256
  13763. #ifdef WOLFSSL_AESGCM_STREAM
  13764. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13765. if (ret != 0)
  13766. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13767. ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a));
  13768. if (ret != 0)
  13769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13770. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13771. if (ret != 0)
  13772. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13773. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13774. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13775. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13776. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13777. #ifdef HAVE_AES_DECRYPT
  13778. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13779. if (ret != 0)
  13780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13781. ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
  13782. if (ret != 0)
  13783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13784. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13785. if (ret != 0)
  13786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13787. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13788. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13789. #endif
  13790. /* alen is the size to pass in with each update. */
  13791. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13792. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13793. if (ret != 0)
  13794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13795. /* plen is the offset into AAD to update with. */
  13796. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13797. int len = sizeof(a) - plen;
  13798. if (len > alen) len = alen;
  13799. ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13800. if (ret != 0)
  13801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13802. }
  13803. /* plen is the offset into plaintext to update with. */
  13804. for (plen = 0; plen < (int)sizeof(p); plen += alen) {
  13805. int len = sizeof(p) - plen;
  13806. if (len > alen) len = alen;
  13807. ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, (word32)len,
  13808. NULL, 0);
  13809. if (ret != 0)
  13810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13811. }
  13812. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13813. if (ret != 0)
  13814. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13815. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13816. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13817. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13818. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13819. }
  13820. #ifdef HAVE_AES_DECRYPT
  13821. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13822. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13823. if (ret != 0)
  13824. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13825. /* plen is the offset into AAD to update with. */
  13826. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13827. int len = sizeof(a) - plen;
  13828. if (len > alen) len = alen;
  13829. ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13830. if (ret != 0)
  13831. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13832. }
  13833. /* plen is the offset into cipher text to update with. */
  13834. for (plen = 0; plen < (int)sizeof(c1); plen += alen) {
  13835. int len = sizeof(c1) - plen;
  13836. if (len > alen) len = alen;
  13837. ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, (word32)len,
  13838. NULL, 0);
  13839. if (ret != 0)
  13840. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13841. }
  13842. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13843. if (ret != 0)
  13844. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13845. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13846. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13847. }
  13848. #endif /* HAVE_AES_DECRYPT */
  13849. #ifdef BENCH_AESGCM_LARGE
  13850. /* setup test buffer */
  13851. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13852. if (ret != 0)
  13853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13854. ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input,
  13855. BENCH_AESGCM_LARGE, a, sizeof(a));
  13856. if (ret != 0)
  13857. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13858. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13859. if (ret != 0)
  13860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13861. #ifdef HAVE_AES_DECRYPT
  13862. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13863. if (ret != 0)
  13864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13865. ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output,
  13866. BENCH_AESGCM_LARGE, a, sizeof(a));
  13867. if (ret != 0)
  13868. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13869. ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1));
  13870. if (ret != 0)
  13871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13872. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13873. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13874. #endif /* HAVE_AES_DECRYPT */
  13875. #endif /* BENCH_AESGCM_LARGE */
  13876. #endif /* WOLFSSL_AESGCM_STREAM */
  13877. #endif /* WOLFSSL_AES_256 */
  13878. #endif /* !WOLFSSL_AFALG_XILINX_AES && !WOLFSSL_XILINX_CRYPT */
  13879. wc_AesFree(enc);
  13880. wc_AesFree(dec);
  13881. ret = 0;
  13882. out:
  13883. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  13884. !defined(WOLFSSL_NO_MALLOC)
  13885. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13886. XFREE(large_output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13887. XFREE(large_outdec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13888. #endif
  13889. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13890. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  13891. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  13892. #endif
  13893. return ret;
  13894. }
  13895. #ifdef WOLFSSL_AES_128
  13896. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void)
  13897. {
  13898. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13899. Gmac *gmac;
  13900. #else
  13901. Gmac gmac[1];
  13902. #endif
  13903. wc_test_ret_t ret;
  13904. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13905. {
  13906. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  13907. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  13908. };
  13909. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13910. {
  13911. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  13912. 0xe2, 0x8c, 0x8f, 0x16
  13913. };
  13914. WOLFSSL_SMALL_STACK_STATIC const byte a1[] =
  13915. {
  13916. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  13917. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  13918. };
  13919. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13920. {
  13921. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  13922. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  13923. };
  13924. #if (!defined(HAVE_FIPS) || \
  13925. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
  13926. /* FIPS builds only allow 16-byte auth tags. */
  13927. /* This sample uses a 15-byte auth tag. */
  13928. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13929. {
  13930. 0x40, 0xf7, 0xec, 0xb2, 0x52, 0x6d, 0xaa, 0xd4,
  13931. 0x74, 0x25, 0x1d, 0xf4, 0x88, 0x9e, 0xf6, 0x5b
  13932. };
  13933. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13934. {
  13935. 0xee, 0x9c, 0x6e, 0x06, 0x15, 0x45, 0x45, 0x03,
  13936. 0x1a, 0x60, 0x24, 0xa7
  13937. };
  13938. WOLFSSL_SMALL_STACK_STATIC const byte a2[] =
  13939. {
  13940. 0x94, 0x81, 0x2c, 0x87, 0x07, 0x4e, 0x15, 0x18,
  13941. 0x34, 0xb8, 0x35, 0xaf, 0x1c, 0xa5, 0x7e, 0x56
  13942. };
  13943. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13944. {
  13945. 0xc6, 0x81, 0x79, 0x8e, 0x3d, 0xda, 0xb0, 0x9f,
  13946. 0x8d, 0x83, 0xb0, 0xbb, 0x14, 0xb6, 0x91
  13947. };
  13948. #endif
  13949. byte tag[16];
  13950. WOLFSSL_ENTER("gmac_test");
  13951. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13952. if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  13953. return WC_TEST_RET_ENC_ERRNO;
  13954. #endif
  13955. XMEMSET(gmac, 0, sizeof *gmac); /* clear context */
  13956. (void)wc_AesInit(&gmac->aes, HEAP_HINT, INVALID_DEVID); /* Make sure devId updated */
  13957. XMEMSET(tag, 0, sizeof(tag));
  13958. wc_GmacSetKey(gmac, k1, sizeof(k1));
  13959. wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1));
  13960. if (XMEMCMP(t1, tag, sizeof(t1)) != 0)
  13961. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13962. #if (!defined(HAVE_FIPS) || \
  13963. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) )
  13964. XMEMSET(tag, 0, sizeof(tag));
  13965. wc_GmacSetKey(gmac, k2, sizeof(k2));
  13966. wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2));
  13967. if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
  13968. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13969. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
  13970. {
  13971. WOLFSSL_SMALL_STACK_STATIC const byte badT[] =
  13972. {
  13973. 0xde, 0xad, 0xbe, 0xef, 0x17, 0x2e, 0xd0, 0x43,
  13974. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  13975. };
  13976. WC_RNG rng;
  13977. byte iv[12];
  13978. #ifndef HAVE_FIPS
  13979. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13980. if (ret != 0)
  13981. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13982. #else
  13983. ret = wc_InitRng(&rng);
  13984. if (ret != 0)
  13985. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13986. #endif
  13987. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  13988. t1, sizeof(t1));
  13989. if (ret != 0)
  13990. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13991. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  13992. badT, sizeof(badT));
  13993. if (ret != WC_NO_ERR_TRACE(AES_GCM_AUTH_E))
  13994. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13995. ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2),
  13996. t2, sizeof(t2));
  13997. if (ret != 0)
  13998. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13999. XMEMSET(tag, 0, sizeof(tag));
  14000. XMEMSET(iv, 0, sizeof(iv));
  14001. ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14002. tag, sizeof(tag), &rng);
  14003. if (ret != 0)
  14004. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14005. ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14006. tag, sizeof(tag));
  14007. if (ret != 0)
  14008. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14009. wc_FreeRng(&rng);
  14010. }
  14011. #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
  14012. #endif /* HAVE_FIPS */
  14013. ret = 0;
  14014. out:
  14015. wc_AesFree(&gmac->aes);
  14016. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14017. XFREE(gmac, HEAP_HINT, DYNAMIC_TYPE_AES);
  14018. #endif
  14019. return ret;
  14020. }
  14021. #endif /* WOLFSSL_AES_128 */
  14022. #endif /* HAVE_AESGCM */
  14023. #if defined(HAVE_AESCCM)
  14024. #if defined(WOLFSSL_AES_256)
  14025. static wc_test_ret_t aesccm_256_test(void)
  14026. {
  14027. wc_test_ret_t ret;
  14028. /* Test vectors from NIST AES CCM 256-bit CAST Example #1 */
  14029. WOLFSSL_SMALL_STACK_STATIC const byte in_key[32] = {
  14030. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14031. 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  14032. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14033. 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  14034. };
  14035. WOLFSSL_SMALL_STACK_STATIC const byte in_nonce[7] = {
  14036. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
  14037. WOLFSSL_SMALL_STACK_STATIC const byte in_auth[8] = {
  14038. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  14039. WOLFSSL_SMALL_STACK_STATIC const byte in_plaintext[4] = {
  14040. 0x20, 0x21, 0x22, 0x23};
  14041. WOLFSSL_SMALL_STACK_STATIC const byte exp_ciphertext[4] = {
  14042. 0x8A, 0xB1, 0xA8, 0x74};
  14043. WOLFSSL_SMALL_STACK_STATIC const byte exp_tag[4] = {
  14044. 0x95, 0xFC, 0x08, 0x20};
  14045. byte output[sizeof(in_plaintext)];
  14046. byte atag[sizeof(exp_tag)];
  14047. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14048. Aes* aes = (Aes*)XMALLOC(sizeof(Aes), HEAP_HINT, DYNAMIC_TYPE_AES);
  14049. if (aes == NULL) {
  14050. return MEMORY_E;
  14051. }
  14052. #else
  14053. Aes aes[1];
  14054. #endif
  14055. ret = wc_AesInit(aes, HEAP_HINT, devId);
  14056. if (ret == 0) {
  14057. ret = wc_AesCcmSetKey(aes, in_key, sizeof(in_key));
  14058. }
  14059. if (ret == 0) {
  14060. ret = wc_AesCcmEncrypt(aes, output, in_plaintext, sizeof(in_plaintext),
  14061. in_nonce, sizeof(in_nonce),
  14062. atag, sizeof(atag),
  14063. in_auth, sizeof(in_auth));
  14064. }
  14065. /* Verify we produce the proper ciphertext and tag */
  14066. if (ret == 0 &&
  14067. (XMEMCMP(output, exp_ciphertext, sizeof(output)) ||
  14068. XMEMCMP(atag, exp_tag, sizeof(atag)))) {
  14069. ret = WC_TEST_RET_ENC_NC;
  14070. }
  14071. #ifdef HAVE_AES_DECRYPT
  14072. if (ret == 0) {
  14073. /* decrypt inline */
  14074. ret = wc_AesCcmDecrypt(aes, output, output, sizeof(output),
  14075. in_nonce, sizeof(in_nonce),
  14076. atag, sizeof(atag),
  14077. in_auth, sizeof(in_auth));
  14078. }
  14079. /* Verify decryption was successful */
  14080. if (ret == 0 &&
  14081. XMEMCMP(output, in_plaintext, sizeof(output))) {
  14082. ret = WC_TEST_RET_ENC_NC;
  14083. }
  14084. #endif
  14085. wc_AesFree(aes);
  14086. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14087. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  14088. #endif
  14089. return ret;
  14090. }
  14091. #endif /* WOLFSSL_AES_256 */
  14092. #if defined(WOLFSSL_AES_128)
  14093. static wc_test_ret_t aesccm_128_test(void)
  14094. {
  14095. wc_test_ret_t ret;
  14096. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14097. Aes *enc;
  14098. #else
  14099. Aes enc[1];
  14100. #endif
  14101. /* key */
  14102. WOLFSSL_SMALL_STACK_STATIC const byte k[] =
  14103. {
  14104. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  14105. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  14106. };
  14107. /* nonce */
  14108. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  14109. {
  14110. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  14111. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  14112. };
  14113. /* plaintext */
  14114. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  14115. {
  14116. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14117. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14118. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  14119. };
  14120. /* plaintext - long */
  14121. WOLFSSL_SMALL_STACK_STATIC const byte pl[] =
  14122. {
  14123. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14124. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14125. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  14126. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14127. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  14128. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  14129. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  14130. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14131. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  14132. 0x50
  14133. };
  14134. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  14135. {
  14136. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14137. };
  14138. /* ciphertext */
  14139. WOLFSSL_SMALL_STACK_STATIC const byte c[] =
  14140. {
  14141. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14142. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14143. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  14144. };
  14145. /* tag - authentication */
  14146. WOLFSSL_SMALL_STACK_STATIC const byte t[] =
  14147. {
  14148. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  14149. };
  14150. /* ciphertext - long */
  14151. WOLFSSL_SMALL_STACK_STATIC const byte cl[] =
  14152. {
  14153. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14154. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14155. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0xe0,
  14156. 0x44, 0x2d, 0xbe, 0x25, 0xfa, 0x48, 0x2b, 0xa8,
  14157. 0x36, 0x0b, 0xbf, 0x01, 0xc0, 0x12, 0x45, 0xa4,
  14158. 0x82, 0x9f, 0x20, 0x6c, 0xc3, 0xd6, 0xae, 0x5b,
  14159. 0x54, 0x8d, 0xd0, 0xb1, 0x69, 0x2c, 0xec, 0x5e,
  14160. 0x95, 0xa5, 0x6b, 0x48, 0xc3, 0xc6, 0xc8, 0x9e,
  14161. 0xc7, 0x92, 0x98, 0x9d, 0x26, 0x7d, 0x2a, 0x10,
  14162. 0x0b
  14163. };
  14164. /* tag - authentication - long */
  14165. WOLFSSL_SMALL_STACK_STATIC const byte tl[] =
  14166. {
  14167. 0x89, 0xd8, 0xd2, 0x02, 0xc5, 0xcf, 0xae, 0xf4
  14168. };
  14169. /* tag - authentication - empty plaintext */
  14170. WOLFSSL_SMALL_STACK_STATIC const byte t_empty[] =
  14171. {
  14172. 0xe4, 0x28, 0x8a, 0xc3, 0x78, 0x00, 0x0f, 0xf5
  14173. };
  14174. byte t2[sizeof(t)];
  14175. byte p2[sizeof(p)];
  14176. byte c2[sizeof(c)];
  14177. byte iv2[sizeof(iv)];
  14178. byte pl2[sizeof(pl)];
  14179. byte cl2[sizeof(cl)];
  14180. byte tl2[sizeof(tl)];
  14181. byte t_empty2[sizeof(t_empty)];
  14182. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14183. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  14184. return WC_TEST_RET_ENC_ERRNO;
  14185. #endif
  14186. XMEMSET(enc, 0, sizeof *enc); /* clear context */
  14187. XMEMSET(t2, 0, sizeof(t2));
  14188. XMEMSET(c2, 0, sizeof(c2));
  14189. XMEMSET(p2, 0, sizeof(p2));
  14190. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14191. if (ret != 0)
  14192. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14193. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14194. if (ret != 0)
  14195. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14196. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14197. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14198. t2, sizeof(t2), a, sizeof(a));
  14199. if (ret != 0)
  14200. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14201. if (XMEMCMP(c, c2, sizeof(c2)))
  14202. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14203. if (XMEMCMP(t, t2, sizeof(t2)))
  14204. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14205. #ifdef HAVE_AES_DECRYPT
  14206. ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv),
  14207. t2, sizeof(t2), a, sizeof(a));
  14208. if (ret != 0)
  14209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14210. if (XMEMCMP(p, p2, sizeof(p2)))
  14211. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14212. /* Test the authentication failure */
  14213. t2[0]++; /* Corrupt the authentication tag. */
  14214. ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv),
  14215. t2, sizeof(t2), a, sizeof(a));
  14216. if (ret == 0)
  14217. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14218. /* Clear c2 to compare against p2. p2 should be set to zero in case of
  14219. * authentication fail. */
  14220. XMEMSET(c2, 0, sizeof(c2));
  14221. if (XMEMCMP(p2, c2, sizeof(p2)))
  14222. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14223. #endif
  14224. wc_AesFree(enc);
  14225. XMEMSET(enc, 0, sizeof(Aes)); /* clear context */
  14226. XMEMSET(t2, 0, sizeof(t2));
  14227. XMEMSET(c2, 0, sizeof(c2));
  14228. XMEMSET(p2, 0, sizeof(p2));
  14229. XMEMSET(iv2, 0, sizeof(iv2));
  14230. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14231. if (ret != 0)
  14232. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14233. #ifndef HAVE_SELFTEST
  14234. /* selftest build does not have wc_AesCcmSetNonce() or
  14235. * wc_AesCcmEncrypt_ex() */
  14236. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14237. if (ret != 0)
  14238. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14239. ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv));
  14240. if (ret != 0)
  14241. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14242. ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2),
  14243. t2, sizeof(t2), a, sizeof(a));
  14244. if (ret != 0)
  14245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14246. if (XMEMCMP(iv, iv2, sizeof(iv2)))
  14247. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14248. if (XMEMCMP(c, c2, sizeof(c2)))
  14249. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14250. if (XMEMCMP(t, t2, sizeof(t2)))
  14251. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14252. #endif
  14253. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  14254. /* test fail on invalid IV sizes */
  14255. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14256. if (ret != 0)
  14257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14258. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14259. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14260. t2, 1, a, sizeof(a));
  14261. if (ret == 0) {
  14262. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14263. }
  14264. #endif
  14265. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14266. ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv),
  14267. tl2, sizeof(tl2), a, sizeof(a));
  14268. if (ret != 0)
  14269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14270. if (XMEMCMP(cl, cl2, sizeof(cl2)))
  14271. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14272. if (XMEMCMP(tl, tl2, sizeof(tl2)))
  14273. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14274. #ifdef HAVE_AES_DECRYPT
  14275. ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv),
  14276. tl2, sizeof(tl2), a, sizeof(a));
  14277. if (ret != 0)
  14278. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14279. if (XMEMCMP(pl, pl2, sizeof(pl2)))
  14280. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14281. #endif
  14282. /* test empty message as null input or output with nonzero inSz. */
  14283. ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */,
  14284. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14285. a, sizeof(a));
  14286. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14287. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14288. ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14289. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14290. a, sizeof(a));
  14291. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14293. #ifdef HAVE_AES_DECRYPT
  14294. ret = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */,
  14295. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14296. sizeof(a));
  14297. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14299. ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14300. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14301. sizeof(a));
  14302. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14304. #endif
  14305. /* test empty message as null input and output with zero inSz --
  14306. * must either succeed, or fail early with BAD_FUNC_ARG.
  14307. */
  14308. ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */,
  14309. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14310. a, sizeof(a));
  14311. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  14312. if (ret != 0)
  14313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14314. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14315. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14316. #ifdef HAVE_AES_DECRYPT
  14317. ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */,
  14318. 0 /* inSz */, iv, sizeof(iv), t_empty2,
  14319. sizeof(t_empty2), a, sizeof(a));
  14320. if (ret != 0)
  14321. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14322. #endif
  14323. }
  14324. /* test empty message as zero-length string -- must work. */
  14325. ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv,
  14326. sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14327. sizeof(a));
  14328. if (ret != 0)
  14329. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14330. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14331. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14332. #ifdef HAVE_AES_DECRYPT
  14333. ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */,
  14334. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14335. sizeof(a));
  14336. if (ret != 0)
  14337. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14338. #endif
  14339. wc_AesFree(enc);
  14340. ret = 0;
  14341. out:
  14342. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14343. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  14344. #endif
  14345. return ret;
  14346. }
  14347. #endif /* WOLFSSL_AES_128 */
  14348. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void)
  14349. {
  14350. wc_test_ret_t ret = 0;
  14351. WOLFSSL_ENTER("aesccm_test");
  14352. #ifdef WOLFSSL_AES_128
  14353. if (ret == 0)
  14354. ret = aesccm_128_test();
  14355. #endif
  14356. #ifdef WOLFSSL_AES_256
  14357. if (ret == 0)
  14358. ret = aesccm_256_test();
  14359. #endif
  14360. return ret;
  14361. }
  14362. #endif /* HAVE_AESCCM */
  14363. #if defined(WOLFSSL_AES_EAX) && \
  14364. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14365. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
  14366. {
  14367. typedef struct {
  14368. byte key[AES_256_KEY_SIZE];
  14369. int key_length;
  14370. byte iv[AES_BLOCK_SIZE];
  14371. int iv_length;
  14372. byte aad[AES_BLOCK_SIZE * 2];
  14373. int aad_length;
  14374. byte msg[AES_BLOCK_SIZE * 2];
  14375. int msg_length;
  14376. byte ct[AES_BLOCK_SIZE * 2];
  14377. int ct_length;
  14378. byte tag[AES_BLOCK_SIZE];
  14379. int tag_length;
  14380. int valid;
  14381. } AadVector;
  14382. /* A small selection of Google wycheproof vectors that use vectors
  14383. * from the original paper: eprint.iacr.org/2003/069
  14384. * https://github.com/google/wycheproof/blob/master/testvectors/aes_eax_test.json
  14385. */
  14386. WOLFSSL_SMALL_STACK_STATIC const AadVector vectors[] = {
  14387. /* Vector from paper - empty message with auth data */
  14388. {
  14389. /* key, key length */
  14390. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  14391. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  14392. /* iv, iv length */
  14393. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  14394. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  14395. /* aad, aad length */
  14396. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  14397. /* msg, msg length */
  14398. {0}, 0,
  14399. /* ct, ct length */
  14400. {0}, 0,
  14401. /* tag, tag length */
  14402. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2,
  14403. 0x7b, 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  14404. /* valid */
  14405. 1,
  14406. },
  14407. /* Vector from paper - no auth data, valid auth tag */
  14408. {
  14409. /* key, key length */
  14410. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14411. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14412. /* iv , iv length */
  14413. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  14414. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  14415. /* aad, aad length */
  14416. {0}, 0,
  14417. /* msg, msg length */
  14418. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14419. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14420. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  14421. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  14422. /* ct, ct length */
  14423. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  14424. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  14425. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  14426. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  14427. /* tag, tag length */
  14428. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  14429. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  14430. /* valid */
  14431. 1,
  14432. },
  14433. /* Vector from paper - no auth data with invalid auth tag */
  14434. {
  14435. /* key, key length */
  14436. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14437. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14438. /* iv, iv length */
  14439. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14440. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  14441. /* aad, aad length */
  14442. {0}, 0,
  14443. /* msg, msg length */
  14444. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14445. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  14446. /* ct , ct length */
  14447. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  14448. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  14449. /* tag, tag length */
  14450. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  14451. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  14452. /* valid */
  14453. 0,
  14454. },
  14455. };
  14456. WOLFSSL_SMALL_STACK_STATIC byte ciphertext[sizeof(vectors[0].ct)];
  14457. WOLFSSL_SMALL_STACK_STATIC byte authtag[sizeof(vectors[0].tag)];
  14458. int i;
  14459. int len;
  14460. wc_test_ret_t ret;
  14461. WOLFSSL_ENTER("aes_eax_test");
  14462. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  14463. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14464. len = sizeof(authtag);
  14465. ret = wc_AesEaxEncryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14466. ciphertext,
  14467. vectors[i].msg, (word32)vectors[i].msg_length,
  14468. vectors[i].iv, (word32)vectors[i].iv_length,
  14469. authtag, (word32)len,
  14470. vectors[i].aad, (word32)vectors[i].aad_length);
  14471. if (ret != 0) {
  14472. return WC_TEST_RET_ENC_EC(ret);
  14473. }
  14474. /* check ciphertext matches vector */
  14475. if (XMEMCMP(ciphertext, vectors[i].ct, (size_t)vectors[i].ct_length)) {
  14476. return WC_TEST_RET_ENC_NC;
  14477. }
  14478. /* check that tag matches vector only for vectors marked as valid */
  14479. ret = XMEMCMP(authtag, vectors[i].tag, len);
  14480. if (vectors[i].valid == 1 && ret != 0 ) {
  14481. return WC_TEST_RET_ENC_NC;
  14482. }
  14483. else if (vectors[i].valid == 0 && ret == 0) {
  14484. return WC_TEST_RET_ENC_NC;
  14485. }
  14486. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14487. ret = wc_AesEaxDecryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14488. ciphertext,
  14489. vectors[i].ct, (word32)vectors[i].ct_length,
  14490. vectors[i].iv, (word32)vectors[i].iv_length,
  14491. authtag, (word32)len,
  14492. vectors[i].aad, (word32)vectors[i].aad_length);
  14493. if (ret != 0) {
  14494. return WC_TEST_RET_ENC_EC(ret);
  14495. }
  14496. /* check decrypted ciphertext matches vector plaintext */
  14497. if (XMEMCMP(ciphertext, vectors[i].msg, (size_t)vectors[i].msg_length)) {
  14498. return WC_TEST_RET_ENC_NC;
  14499. }
  14500. }
  14501. return 0;
  14502. }
  14503. #endif /* WOLFSSL_AES_EAX */
  14504. #ifdef HAVE_AES_KEYWRAP
  14505. #define MAX_KEYWRAP_TEST_OUTLEN 40
  14506. #define MAX_KEYWRAP_TEST_PLAINLEN 32
  14507. typedef struct keywrapVector {
  14508. const byte* kek;
  14509. const byte* data;
  14510. const byte* verify;
  14511. word32 kekLen;
  14512. word32 dataLen;
  14513. word32 verifyLen;
  14514. } keywrapVector;
  14515. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void)
  14516. {
  14517. int wrapSz, plainSz, testSz, i;
  14518. /* test vectors from RFC 3394 (kek, data, verify) */
  14519. #ifdef WOLFSSL_AES_128
  14520. /* Wrap 128 bits of Key Data with a 128-bit KEK */
  14521. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14522. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14523. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14524. };
  14525. WOLFSSL_SMALL_STACK_STATIC const byte d1[] = {
  14526. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14527. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14528. };
  14529. WOLFSSL_SMALL_STACK_STATIC const byte v1[] = {
  14530. 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
  14531. 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
  14532. 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
  14533. };
  14534. #endif /* WOLFSSL_AES_128 */
  14535. #ifdef WOLFSSL_AES_192
  14536. /* Wrap 128 bits of Key Data with a 192-bit KEK */
  14537. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  14538. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14539. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14540. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14541. };
  14542. WOLFSSL_SMALL_STACK_STATIC const byte d2[] = {
  14543. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14544. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14545. };
  14546. WOLFSSL_SMALL_STACK_STATIC const byte v2[] = {
  14547. 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
  14548. 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
  14549. 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
  14550. };
  14551. #endif
  14552. #ifdef WOLFSSL_AES_256
  14553. /* Wrap 128 bits of Key Data with a 256-bit KEK */
  14554. WOLFSSL_SMALL_STACK_STATIC const byte k3[] = {
  14555. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14556. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14557. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14558. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14559. };
  14560. WOLFSSL_SMALL_STACK_STATIC const byte d3[] = {
  14561. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14562. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14563. };
  14564. WOLFSSL_SMALL_STACK_STATIC const byte v3[] = {
  14565. 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
  14566. 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
  14567. 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7
  14568. };
  14569. #endif
  14570. #ifdef WOLFSSL_AES_192
  14571. /* Wrap 192 bits of Key Data with a 192-bit KEK */
  14572. WOLFSSL_SMALL_STACK_STATIC const byte k4[] = {
  14573. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14574. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14575. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14576. };
  14577. WOLFSSL_SMALL_STACK_STATIC const byte d4[] = {
  14578. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14579. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14580. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14581. };
  14582. WOLFSSL_SMALL_STACK_STATIC const byte v4[] = {
  14583. 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
  14584. 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
  14585. 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
  14586. 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
  14587. };
  14588. #endif
  14589. #ifdef WOLFSSL_AES_256
  14590. /* Wrap 192 bits of Key Data with a 256-bit KEK */
  14591. WOLFSSL_SMALL_STACK_STATIC const byte k5[] = {
  14592. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14593. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14594. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14595. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14596. };
  14597. WOLFSSL_SMALL_STACK_STATIC const byte d5[] = {
  14598. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14599. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14600. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14601. };
  14602. WOLFSSL_SMALL_STACK_STATIC const byte v5[] = {
  14603. 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
  14604. 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
  14605. 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
  14606. 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1
  14607. };
  14608. /* Wrap 256 bits of Key Data with a 256-bit KEK */
  14609. WOLFSSL_SMALL_STACK_STATIC const byte k6[] = {
  14610. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14611. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14612. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14613. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14614. };
  14615. WOLFSSL_SMALL_STACK_STATIC const byte d6[] = {
  14616. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14617. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14618. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14619. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14620. };
  14621. WOLFSSL_SMALL_STACK_STATIC const byte v6[] = {
  14622. 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
  14623. 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
  14624. 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
  14625. 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
  14626. 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
  14627. };
  14628. #endif /* WOLFSSL_AES_256 */
  14629. byte output[MAX_KEYWRAP_TEST_OUTLEN];
  14630. byte plain [MAX_KEYWRAP_TEST_PLAINLEN];
  14631. const keywrapVector test_wrap[] =
  14632. {
  14633. #ifdef WOLFSSL_AES_128
  14634. {k1, d1, v1, sizeof(k1), sizeof(d1), sizeof(v1)},
  14635. #endif
  14636. #ifdef WOLFSSL_AES_192
  14637. {k2, d2, v2, sizeof(k2), sizeof(d2), sizeof(v2)},
  14638. #endif
  14639. #ifdef WOLFSSL_AES_256
  14640. {k3, d3, v3, sizeof(k3), sizeof(d3), sizeof(v3)},
  14641. #endif
  14642. #ifdef WOLFSSL_AES_192
  14643. {k4, d4, v4, sizeof(k4), sizeof(d4), sizeof(v4)},
  14644. #endif
  14645. #ifdef WOLFSSL_AES_256
  14646. {k5, d5, v5, sizeof(k5), sizeof(d5), sizeof(v5)},
  14647. {k6, d6, v6, sizeof(k6), sizeof(d6), sizeof(v6)}
  14648. #endif
  14649. };
  14650. WOLFSSL_ENTER("aeskeywrap_test");
  14651. testSz = sizeof(test_wrap) / sizeof(keywrapVector);
  14652. XMEMSET(output, 0, sizeof(output));
  14653. XMEMSET(plain, 0, sizeof(plain));
  14654. for (i = 0; i < testSz; i++) {
  14655. wrapSz = wc_AesKeyWrap(test_wrap[i].kek, test_wrap[i].kekLen,
  14656. test_wrap[i].data, test_wrap[i].dataLen,
  14657. output, sizeof(output), NULL);
  14658. if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) )
  14659. return WC_TEST_RET_ENC_NC;
  14660. if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0)
  14661. return WC_TEST_RET_ENC_NC;
  14662. plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen,
  14663. output, (word32)wrapSz,
  14664. plain, sizeof(plain), NULL);
  14665. if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) )
  14666. return WC_TEST_RET_ENC_NC;
  14667. if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0)
  14668. return WC_TEST_RET_ENC_I(i);
  14669. }
  14670. return 0;
  14671. }
  14672. #endif /* HAVE_AES_KEYWRAP */
  14673. #endif /* NO_AES */
  14674. #ifdef HAVE_ARIA
  14675. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz)
  14676. {
  14677. #ifndef DEBUG_WOLFSSL
  14678. (void)strName;
  14679. (void)data;
  14680. (void)dataSz;
  14681. #else
  14682. WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
  14683. WOLFSSL_BUFFER(data,dataSz);
  14684. #endif
  14685. }
  14686. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo)
  14687. {
  14688. byte data[] = TEST_STRING;
  14689. word32 dataSz = TEST_STRING_SZ;
  14690. /* Arbitrarily random long key that we will truncate to the right size */
  14691. byte key[] = { 0x1E, 0xCC, 0x95, 0xCB, 0xD3, 0x74, 0x58, 0x4F,
  14692. 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6,
  14693. 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF,
  14694. 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B };
  14695. byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[AES_BLOCK_SIZE];
  14696. word32 keySz, adSz = 256, authTagSz = sizeof(authTag);
  14697. wc_Aria aria;
  14698. int ret = 0;
  14699. WOLFSSL_ENTER("ariagcm_test");
  14700. XMEMSET((void *)&aria, 0, sizeof(aria));
  14701. ret = wc_AriaInitCrypt(&aria, algo);
  14702. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14703. ret = wc_AriaSetKey(&aria, key);
  14704. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14705. MC_GetObjectValue(aria.hSession, aria.hKey, key, &keySz);
  14706. printOutput("Key", key, keySz);
  14707. WC_RNG rng;
  14708. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14709. if (ret != 0)
  14710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14711. ret = wc_AriaGcmSetIV(&aria, GCM_NONCE_MID_SZ, NULL, 0, &rng);
  14712. if (ret != 0)
  14713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14714. wc_FreeRng(&rng);
  14715. printOutput("Plaintext", data, sizeof(data));
  14716. XMEMSET(cipher, 0, sizeof(cipher));
  14717. ret = wc_AriaEncrypt(&aria, cipher, data, dataSz,
  14718. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14719. authTag, authTagSz);
  14720. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14721. printOutput("Ciphertext", cipher, sizeof(cipher));
  14722. printOutput("AuthTag", authTag, sizeof(authTag));
  14723. XMEMSET(plain, 0, sizeof(plain));
  14724. ret = wc_AriaDecrypt(&aria, plain, cipher, dataSz,
  14725. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14726. authTag, authTagSz);
  14727. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14728. printOutput("Plaintext", plain, sizeof(plain));
  14729. if (XMEMCMP(plain, data, dataSz) != 0)
  14730. ERROR_OUT(WC_TEST_RET_ENC_NC,out);
  14731. out:
  14732. if (ret != 0) { wc_AriaFreeCrypt(&aria); }
  14733. else { ret = wc_AriaFreeCrypt(&aria); }
  14734. return ret;
  14735. }
  14736. #endif /* HAVE_ARIA */
  14737. #ifdef HAVE_CAMELLIA
  14738. enum {
  14739. CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
  14740. };
  14741. typedef struct {
  14742. int type;
  14743. const byte* plaintext;
  14744. const byte* iv;
  14745. const byte* ciphertext;
  14746. const byte* key;
  14747. word32 keySz;
  14748. int errorCode;
  14749. } test_vector_t;
  14750. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void)
  14751. {
  14752. /* Camellia ECB Test Plaintext */
  14753. WOLFSSL_SMALL_STACK_STATIC const byte pte[] =
  14754. {
  14755. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14756. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14757. };
  14758. /* Camellia ECB Test Initialization Vector */
  14759. WOLFSSL_SMALL_STACK_STATIC const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  14760. /* Test 1: Camellia ECB 128-bit key */
  14761. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14762. {
  14763. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14764. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14765. };
  14766. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  14767. {
  14768. 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
  14769. 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
  14770. };
  14771. /* Test 2: Camellia ECB 192-bit key */
  14772. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14773. {
  14774. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14775. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14776. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  14777. };
  14778. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  14779. {
  14780. 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
  14781. 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
  14782. };
  14783. /* Test 3: Camellia ECB 256-bit key */
  14784. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  14785. {
  14786. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14787. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14788. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14789. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  14790. };
  14791. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  14792. {
  14793. 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
  14794. 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
  14795. };
  14796. /* Camellia CBC Test Plaintext */
  14797. WOLFSSL_SMALL_STACK_STATIC const byte ptc[] =
  14798. {
  14799. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  14800. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  14801. };
  14802. /* Camellia CBC Test Initialization Vector */
  14803. WOLFSSL_SMALL_STACK_STATIC const byte ivc[] =
  14804. {
  14805. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14806. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14807. };
  14808. /* Test 4: Camellia-CBC 128-bit key */
  14809. WOLFSSL_SMALL_STACK_STATIC const byte k4[] =
  14810. {
  14811. 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
  14812. 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
  14813. };
  14814. WOLFSSL_SMALL_STACK_STATIC const byte c4[] =
  14815. {
  14816. 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
  14817. 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
  14818. };
  14819. /* Test 5: Camellia-CBC 192-bit key */
  14820. WOLFSSL_SMALL_STACK_STATIC const byte k5[] =
  14821. {
  14822. 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
  14823. 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
  14824. 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
  14825. };
  14826. WOLFSSL_SMALL_STACK_STATIC const byte c5[] =
  14827. {
  14828. 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
  14829. 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
  14830. };
  14831. /* Test 6: CBC 256-bit key */
  14832. WOLFSSL_SMALL_STACK_STATIC const byte k6[] =
  14833. {
  14834. 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
  14835. 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
  14836. 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
  14837. 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
  14838. };
  14839. WOLFSSL_SMALL_STACK_STATIC const byte c6[] =
  14840. {
  14841. 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
  14842. 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
  14843. };
  14844. byte out[CAMELLIA_BLOCK_SIZE];
  14845. Camellia cam;
  14846. WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] =
  14847. {
  14848. {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
  14849. {CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
  14850. {CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
  14851. {CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
  14852. {CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
  14853. {CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
  14854. {CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
  14855. {CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
  14856. {CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
  14857. {CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
  14858. {CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
  14859. {CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
  14860. };
  14861. int i, testsSz;
  14862. int ret;
  14863. WOLFSSL_ENTER("camellia_test");
  14864. testsSz = sizeof(testVectors)/sizeof(test_vector_t);
  14865. for (i = 0; i < testsSz; i++) {
  14866. if (wc_CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
  14867. testVectors[i].iv) != 0)
  14868. return testVectors[i].errorCode;
  14869. switch (testVectors[i].type) {
  14870. case CAM_ECB_ENC:
  14871. ret = wc_CamelliaEncryptDirect(&cam, out,
  14872. testVectors[i].plaintext);
  14873. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14874. CAMELLIA_BLOCK_SIZE))
  14875. return testVectors[i].errorCode;
  14876. break;
  14877. case CAM_ECB_DEC:
  14878. ret = wc_CamelliaDecryptDirect(&cam, out,
  14879. testVectors[i].ciphertext);
  14880. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14881. CAMELLIA_BLOCK_SIZE))
  14882. return testVectors[i].errorCode;
  14883. break;
  14884. case CAM_CBC_ENC:
  14885. ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
  14886. CAMELLIA_BLOCK_SIZE);
  14887. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14888. CAMELLIA_BLOCK_SIZE))
  14889. return testVectors[i].errorCode;
  14890. break;
  14891. case CAM_CBC_DEC:
  14892. ret = wc_CamelliaCbcDecrypt(&cam, out,
  14893. testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE);
  14894. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14895. CAMELLIA_BLOCK_SIZE))
  14896. return testVectors[i].errorCode;
  14897. break;
  14898. default:
  14899. break;
  14900. }
  14901. }
  14902. /* Setting the IV and checking it was actually set. */
  14903. ret = wc_CamelliaSetIV(&cam, ivc);
  14904. if (ret != 0)
  14905. return WC_TEST_RET_ENC_EC(ret);
  14906. if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE) != 0)
  14907. return WC_TEST_RET_ENC_NC;
  14908. /* Setting the IV to NULL should be same as all zeros IV */
  14909. ret = wc_CamelliaSetIV(&cam, NULL);
  14910. if (ret != 0)
  14911. return WC_TEST_RET_ENC_EC(ret);
  14912. if (XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE) != 0)
  14913. return WC_TEST_RET_ENC_NC;
  14914. /* First parameter should never be null */
  14915. if (wc_CamelliaSetIV(NULL, NULL) == 0)
  14916. return WC_TEST_RET_ENC_NC;
  14917. /* First parameter should never be null, check it fails */
  14918. if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
  14919. return WC_TEST_RET_ENC_NC;
  14920. /* Key should have a size of 16, 24, or 32 */
  14921. if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0)
  14922. return WC_TEST_RET_ENC_NC;
  14923. return 0;
  14924. }
  14925. #endif /* HAVE_CAMELLIA */
  14926. #ifdef WOLFSSL_SM4
  14927. #ifdef WOLFSSL_SM4_ECB
  14928. static int sm4_ecb_test(void)
  14929. {
  14930. /* draft-ribose-cfrg-sm4-10 A.2.1.1 */
  14931. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14932. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  14933. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  14934. };
  14935. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  14936. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  14937. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  14938. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  14939. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  14940. };
  14941. WOLFSSL_SMALL_STACK_STATIC const byte c1_ecb[] = {
  14942. 0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
  14943. 0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
  14944. 0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
  14945. 0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04
  14946. };
  14947. wc_Sm4 sm4;
  14948. byte enc[SM4_BLOCK_SIZE * 4];
  14949. byte dec[SM4_BLOCK_SIZE * 4];
  14950. int ret;
  14951. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  14952. if (ret != 0)
  14953. return WC_TEST_RET_ENC_EC(ret);
  14954. /* Encrypt and decrypt with ECB. */
  14955. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  14956. if (ret != 0)
  14957. return WC_TEST_RET_ENC_EC(ret);
  14958. ret = wc_Sm4EcbEncrypt(&sm4, enc, p1, sizeof(p1));
  14959. if (ret != 0)
  14960. return WC_TEST_RET_ENC_EC(ret);
  14961. if (XMEMCMP(enc, c1_ecb, sizeof(c1_ecb)) != 0)
  14962. return WC_TEST_RET_ENC_NC;
  14963. ret = wc_Sm4EcbDecrypt(&sm4, dec, enc, sizeof(c1_ecb));
  14964. if (ret != 0)
  14965. return WC_TEST_RET_ENC_EC(ret);
  14966. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  14967. return WC_TEST_RET_ENC_NC;
  14968. wc_Sm4Free(&sm4);
  14969. return 0;
  14970. }
  14971. #endif
  14972. #ifdef WOLFSSL_SM4_CBC
  14973. static int sm4_cbc_test(void)
  14974. {
  14975. /* draft-ribose-cfrg-sm4-10 A.2.2.1 */
  14976. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14977. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  14978. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  14979. };
  14980. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  14981. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  14982. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  14983. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  14984. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  14985. };
  14986. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  14987. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14988. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14989. };
  14990. WOLFSSL_SMALL_STACK_STATIC const byte c1_cbc[] = {
  14991. 0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
  14992. 0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
  14993. 0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
  14994. 0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D
  14995. };
  14996. wc_Sm4 sm4;
  14997. byte enc[SM4_BLOCK_SIZE * 4];
  14998. byte dec[SM4_BLOCK_SIZE * 4];
  14999. int ret;
  15000. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15001. if (ret != 0)
  15002. return WC_TEST_RET_ENC_EC(ret);
  15003. /* Encrypt and decrypt with CBC. */
  15004. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15005. if (ret != 0)
  15006. return WC_TEST_RET_ENC_EC(ret);
  15007. ret = wc_Sm4SetIV(&sm4, i1);
  15008. if (ret != 0)
  15009. return WC_TEST_RET_ENC_EC(ret);
  15010. ret = wc_Sm4CbcEncrypt(&sm4, enc, p1, sizeof(p1));
  15011. if (ret != 0)
  15012. return WC_TEST_RET_ENC_EC(ret);
  15013. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15014. return WC_TEST_RET_ENC_NC;
  15015. ret = wc_Sm4SetIV(&sm4, i1);
  15016. if (ret != 0)
  15017. return WC_TEST_RET_ENC_EC(ret);
  15018. ret = wc_Sm4CbcDecrypt(&sm4, dec, enc, sizeof(c1_cbc));
  15019. if (ret != 0)
  15020. return WC_TEST_RET_ENC_EC(ret);
  15021. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15022. return WC_TEST_RET_ENC_NC;
  15023. /* Encrypt and decrypt in-place with CBC. */
  15024. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15025. if (ret != 0)
  15026. return WC_TEST_RET_ENC_EC(ret);
  15027. ret = wc_Sm4SetIV(&sm4, i1);
  15028. if (ret != 0)
  15029. return WC_TEST_RET_ENC_EC(ret);
  15030. XMEMCPY(enc, p1, sizeof(p1));
  15031. ret = wc_Sm4CbcEncrypt(&sm4, enc, enc, sizeof(p1));
  15032. if (ret != 0)
  15033. return WC_TEST_RET_ENC_EC(ret);
  15034. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15035. return WC_TEST_RET_ENC_NC;
  15036. ret = wc_Sm4SetIV(&sm4, i1);
  15037. if (ret != 0)
  15038. return WC_TEST_RET_ENC_EC(ret);
  15039. ret = wc_Sm4CbcDecrypt(&sm4, enc, enc, sizeof(c1_cbc));
  15040. if (ret != 0)
  15041. return WC_TEST_RET_ENC_EC(ret);
  15042. if (XMEMCMP(enc, p1, sizeof(p1)) != 0)
  15043. return WC_TEST_RET_ENC_NC;
  15044. wc_Sm4Free(&sm4);
  15045. return 0;
  15046. }
  15047. #endif
  15048. #ifdef WOLFSSL_SM4_CTR
  15049. static int sm4_ctr_test(void)
  15050. {
  15051. /* draft-ribose-cfrg-sm4-10 A.2.5.1 */
  15052. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15053. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15054. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15055. };
  15056. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15057. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15058. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15059. };
  15060. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15061. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15062. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15063. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15064. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15065. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15066. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15067. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15068. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB
  15069. };
  15070. WOLFSSL_SMALL_STACK_STATIC const byte c2_ctr[] = {
  15071. 0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
  15072. 0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
  15073. 0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
  15074. 0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
  15075. 0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
  15076. 0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
  15077. 0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
  15078. 0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14
  15079. };
  15080. wc_Sm4 sm4;
  15081. byte enc[SM4_BLOCK_SIZE * 4];
  15082. byte dec[SM4_BLOCK_SIZE * 4];
  15083. int chunk;
  15084. int i;
  15085. int ret;
  15086. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15087. if (ret != 0)
  15088. return WC_TEST_RET_ENC_EC(ret);
  15089. /* Encrypt and decrypt using encrypt with CTR. */
  15090. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15091. if (ret != 0)
  15092. return WC_TEST_RET_ENC_EC(ret);
  15093. ret = wc_Sm4SetIV(&sm4, i1);
  15094. if (ret != 0)
  15095. return WC_TEST_RET_ENC_EC(ret);
  15096. ret = wc_Sm4CtrEncrypt(&sm4, enc, p2, sizeof(p2));
  15097. if (ret != 0)
  15098. return WC_TEST_RET_ENC_EC(ret);
  15099. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15100. return WC_TEST_RET_ENC_NC;
  15101. ret = wc_Sm4SetIV(&sm4, i1);
  15102. if (ret != 0)
  15103. return WC_TEST_RET_ENC_EC(ret);
  15104. ret = wc_Sm4CtrEncrypt(&sm4, dec, enc, sizeof(c2_ctr));
  15105. if (ret != 0)
  15106. return WC_TEST_RET_ENC_EC(ret);
  15107. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15108. return WC_TEST_RET_ENC_NC;
  15109. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15110. ret = wc_Sm4SetIV(&sm4, i1);
  15111. if (ret != 0)
  15112. return WC_TEST_RET_ENC_I(chunk);
  15113. XMEMSET(enc, 0, sizeof(enc));
  15114. for (i = 0; i + chunk <= (int)sizeof(p2); i += chunk) {
  15115. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, chunk);
  15116. if (ret != 0)
  15117. return WC_TEST_RET_ENC_I(i);
  15118. }
  15119. if (i < (int)sizeof(p2)) {
  15120. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, sizeof(p2) - i);
  15121. if (ret != 0)
  15122. return WC_TEST_RET_ENC_I(chunk);
  15123. }
  15124. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15125. return WC_TEST_RET_ENC_I(chunk);
  15126. }
  15127. wc_Sm4Free(&sm4);
  15128. return 0;
  15129. }
  15130. #endif
  15131. #ifdef WOLFSSL_SM4_GCM
  15132. static int sm4_gcm_test(void)
  15133. {
  15134. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15135. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15136. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15137. };
  15138. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15139. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15140. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15141. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15142. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15143. };
  15144. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15145. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15146. 0x08, 0x09, 0x0A, 0x0B
  15147. };
  15148. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15149. 0xFF, 0xEE, 0xDD
  15150. };
  15151. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15152. 0x83, 0xb2, 0x91, 0xcf, 0x22, 0xc9, 0x5f, 0x89,
  15153. 0xde, 0x3d, 0x52, 0x8d, 0xd7, 0x13, 0x50, 0x89
  15154. };
  15155. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15156. 0xff, 0x8b, 0xb2, 0x3b, 0x0a, 0x0a, 0x12, 0xa4,
  15157. 0xa8, 0x4c, 0x4f, 0x67, 0x06, 0x81, 0xbb, 0x88,
  15158. 0x66, 0x17, 0xc7, 0x43, 0xbf, 0xae, 0x41, 0x40,
  15159. 0xec, 0x1e, 0x03, 0x85, 0x2b, 0x56, 0xa8, 0xc0
  15160. };
  15161. /* RFC8998 A.1. */
  15162. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15163. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15164. 0x00, 0x00, 0xAB, 0xCD
  15165. };
  15166. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15167. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15168. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15169. };
  15170. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15171. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15172. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15173. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15174. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15175. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15176. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15177. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15178. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15179. };
  15180. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15181. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15182. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15183. 0xAB, 0xAD, 0xDA, 0xD2
  15184. };
  15185. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15186. 0x17, 0xF3, 0x99, 0xF0, 0x8C, 0x67, 0xD5, 0xEE,
  15187. 0x19, 0xD0, 0xDC, 0x99, 0x69, 0xC4, 0xBB, 0x7D,
  15188. 0x5F, 0xD4, 0x6F, 0xD3, 0x75, 0x64, 0x89, 0x06,
  15189. 0x91, 0x57, 0xB2, 0x82, 0xBB, 0x20, 0x07, 0x35,
  15190. 0xD8, 0x27, 0x10, 0xCA, 0x5C, 0x22, 0xF0, 0xCC,
  15191. 0xFA, 0x7C, 0xBF, 0x93, 0xD4, 0x96, 0xAC, 0x15,
  15192. 0xA5, 0x68, 0x34, 0xCB, 0xCF, 0x98, 0xC3, 0x97,
  15193. 0xB4, 0x02, 0x4A, 0x26, 0x91, 0x23, 0x3B, 0x8D
  15194. };
  15195. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15196. 0x83, 0xDE, 0x35, 0x41, 0xE4, 0xC2, 0xB5, 0x81,
  15197. 0x77, 0xE0, 0x65, 0xA9, 0xBF, 0x7B, 0x62, 0xEC
  15198. };
  15199. wc_Sm4 sm4;
  15200. byte enc[SM4_BLOCK_SIZE * 4];
  15201. byte dec[SM4_BLOCK_SIZE * 4];
  15202. byte tag[SM4_BLOCK_SIZE];
  15203. int ret;
  15204. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15205. if (ret != 0)
  15206. return WC_TEST_RET_ENC_EC(ret);
  15207. /* Encrypt and decrypt using encrypt with GCM. */
  15208. ret = wc_Sm4GcmSetKey(&sm4, k1, sizeof(k1));
  15209. if (ret != 0)
  15210. return WC_TEST_RET_ENC_EC(ret);
  15211. ret = wc_Sm4GcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15212. sizeof(tag), a1, sizeof(a1));
  15213. if (ret != 0)
  15214. return WC_TEST_RET_ENC_EC(ret);
  15215. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15216. return WC_TEST_RET_ENC_NC;
  15217. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15218. return WC_TEST_RET_ENC_NC;
  15219. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15220. sizeof(tag), a1, sizeof(a1));
  15221. if (ret != 0)
  15222. return WC_TEST_RET_ENC_EC(ret);
  15223. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15224. return WC_TEST_RET_ENC_NC;
  15225. /* RFC8998 test vector. */
  15226. ret = wc_Sm4GcmSetKey(&sm4, k2, sizeof(k2));
  15227. if (ret != 0)
  15228. return WC_TEST_RET_ENC_EC(ret);
  15229. ret = wc_Sm4GcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15230. sizeof(tag), a2, sizeof(a2));
  15231. if (ret != 0)
  15232. return WC_TEST_RET_ENC_EC(ret);
  15233. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15234. return WC_TEST_RET_ENC_NC;
  15235. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15236. return WC_TEST_RET_ENC_NC;
  15237. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15238. sizeof(tag), a2, sizeof(a2));
  15239. if (ret != 0)
  15240. return WC_TEST_RET_ENC_EC(ret);
  15241. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15242. return WC_TEST_RET_ENC_NC;
  15243. wc_Sm4Free(&sm4);
  15244. return 0;
  15245. }
  15246. #endif
  15247. #ifdef WOLFSSL_SM4_CCM
  15248. static int sm4_ccm_test(void)
  15249. {
  15250. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15251. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15252. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15253. };
  15254. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15255. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15256. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15257. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15258. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15259. };
  15260. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15261. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15262. 0x08, 0x09, 0x0A, 0x0B
  15263. };
  15264. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15265. 0xFF, 0xEE, 0xDD
  15266. };
  15267. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15268. 0x9a, 0x98, 0x04, 0xb6, 0x0f, 0x19, 0x4a, 0x46,
  15269. 0xba, 0xed, 0xe6, 0x89, 0x69, 0x34, 0xad, 0x61
  15270. };
  15271. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15272. 0xbd, 0xc0, 0x72, 0x60, 0xda, 0x2d, 0x11, 0xdc,
  15273. 0x66, 0x33, 0xcc, 0xec, 0xb2, 0xf4, 0x53, 0x59,
  15274. 0x9e, 0xb1, 0xb3, 0x6b, 0x1f, 0x1c, 0xfb, 0x29,
  15275. 0xf5, 0x37, 0xfc, 0x00, 0xf2, 0x4e, 0x70, 0x6f
  15276. };
  15277. /* RFC8998 A.1. */
  15278. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15279. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15280. 0x00, 0x00, 0xAB, 0xCD
  15281. };
  15282. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15283. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15284. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15285. };
  15286. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15287. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15288. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15289. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15290. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15291. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15292. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15293. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15294. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15295. };
  15296. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15297. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15298. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15299. 0xAB, 0xAD, 0xDA, 0xD2
  15300. };
  15301. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15302. 0x48, 0xAF, 0x93, 0x50, 0x1F, 0xA6, 0x2A, 0xDB,
  15303. 0xCD, 0x41, 0x4C, 0xCE, 0x60, 0x34, 0xD8, 0x95,
  15304. 0xDD, 0xA1, 0xBF, 0x8F, 0x13, 0x2F, 0x04, 0x20,
  15305. 0x98, 0x66, 0x15, 0x72, 0xE7, 0x48, 0x30, 0x94,
  15306. 0xFD, 0x12, 0xE5, 0x18, 0xCE, 0x06, 0x2C, 0x98,
  15307. 0xAC, 0xEE, 0x28, 0xD9, 0x5D, 0xF4, 0x41, 0x6B,
  15308. 0xED, 0x31, 0xA2, 0xF0, 0x44, 0x76, 0xC1, 0x8B,
  15309. 0xB4, 0x0C, 0x84, 0xA7, 0x4B, 0x97, 0xDC, 0x5B
  15310. };
  15311. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15312. 0x16, 0x84, 0x2D, 0x4F, 0xA1, 0x86, 0xF5, 0x6A,
  15313. 0xB3, 0x32, 0x56, 0x97, 0x1F, 0xA1, 0x10, 0xF4
  15314. };
  15315. wc_Sm4 sm4;
  15316. byte enc[SM4_BLOCK_SIZE * 4];
  15317. byte dec[SM4_BLOCK_SIZE * 4];
  15318. byte tag[SM4_BLOCK_SIZE];
  15319. int ret;
  15320. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15321. if (ret != 0)
  15322. return WC_TEST_RET_ENC_EC(ret);
  15323. /* Encrypt and decrypt using encrypt with CCM. */
  15324. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15325. if (ret != 0)
  15326. return WC_TEST_RET_ENC_EC(ret);
  15327. ret = wc_Sm4CcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15328. sizeof(tag), a1, sizeof(a1));
  15329. if (ret != 0)
  15330. return WC_TEST_RET_ENC_EC(ret);
  15331. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15332. return WC_TEST_RET_ENC_NC;
  15333. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15334. return WC_TEST_RET_ENC_NC;
  15335. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15336. sizeof(tag), a1, sizeof(a1));
  15337. if (ret != 0)
  15338. return WC_TEST_RET_ENC_EC(ret);
  15339. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15340. return WC_TEST_RET_ENC_NC;
  15341. /* RFC8998 test vector. */
  15342. ret = wc_Sm4SetKey(&sm4, k2, sizeof(k2));
  15343. if (ret != 0)
  15344. return WC_TEST_RET_ENC_EC(ret);
  15345. ret = wc_Sm4CcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15346. sizeof(tag), a2, sizeof(a2));
  15347. if (ret != 0)
  15348. return WC_TEST_RET_ENC_EC(ret);
  15349. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15350. return WC_TEST_RET_ENC_NC;
  15351. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15352. return WC_TEST_RET_ENC_NC;
  15353. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15354. sizeof(tag), a2, sizeof(a2));
  15355. if (ret != 0)
  15356. return WC_TEST_RET_ENC_EC(ret);
  15357. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15358. return WC_TEST_RET_ENC_NC;
  15359. wc_Sm4Free(&sm4);
  15360. return 0;
  15361. }
  15362. #endif
  15363. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void)
  15364. {
  15365. wc_test_ret_t ret;
  15366. WOLFSSL_ENTER("sm4_test");
  15367. #ifdef WOLFSSL_SM4_ECB
  15368. ret = sm4_ecb_test();
  15369. if (ret != 0)
  15370. return ret;
  15371. #endif
  15372. #ifdef WOLFSSL_SM4_CBC
  15373. ret = sm4_cbc_test();
  15374. if (ret != 0)
  15375. return ret;
  15376. #endif
  15377. #ifdef WOLFSSL_SM4_CTR
  15378. ret = sm4_ctr_test();
  15379. if (ret != 0)
  15380. return ret;
  15381. #endif
  15382. #ifdef WOLFSSL_SM4_GCM
  15383. ret = sm4_gcm_test();
  15384. if (ret != 0)
  15385. return ret;
  15386. #endif
  15387. #ifdef WOLFSSL_SM4_CCM
  15388. ret = sm4_ccm_test();
  15389. if (ret != 0)
  15390. return ret;
  15391. #endif
  15392. return 0;
  15393. }
  15394. #endif
  15395. #ifdef HAVE_XCHACHA
  15396. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void) {
  15397. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15398. 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */
  15399. 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, /* unced "dole") is */
  15400. 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, /* also known as t */
  15401. 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, /* he Asiatic wild */
  15402. 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, /* dog, red dog, an */
  15403. 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, /* d whistling dog. */
  15404. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, /* It is about the */
  15405. 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, /* size of a Germa */
  15406. 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, /* n shepherd but l */
  15407. 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, /* ooks more like a */
  15408. 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, /* long-legged fox */
  15409. 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, /* . This highly el */
  15410. 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, /* usive and skille */
  15411. 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, /* d jumper is clas */
  15412. 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, /* sified with wolv */
  15413. 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, /* es, coyotes, jac */
  15414. 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, /* kals, and foxes */
  15415. 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, /* in the taxonomic */
  15416. 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e /* family Canidae. */
  15417. };
  15418. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15419. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15420. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15421. };
  15422. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15423. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15424. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 }; /* PQRSTUVW */
  15425. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15426. 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f,
  15427. 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9,
  15428. 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa,
  15429. 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d,
  15430. 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a,
  15431. 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda,
  15432. 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31,
  15433. 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44,
  15434. 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b,
  15435. 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40,
  15436. 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e,
  15437. 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c,
  15438. 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41,
  15439. 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae,
  15440. 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa,
  15441. 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c,
  15442. 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20,
  15443. 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63,
  15444. 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5
  15445. };
  15446. wc_test_ret_t ret;
  15447. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15448. struct ChaCha *chacha = (struct ChaCha *)XMALLOC(sizeof *chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15449. byte *buf1 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15450. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15451. WOLFSSL_ENTER("XChaCha_test");
  15452. if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL))
  15453. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15454. #else
  15455. struct ChaCha chacha[1];
  15456. byte buf1[sizeof Plaintext];
  15457. byte buf2[sizeof Plaintext];
  15458. WOLFSSL_ENTER("XChaCha_test");
  15459. #endif
  15460. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15461. if (ret < 0)
  15462. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15463. ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext);
  15464. if (ret < 0)
  15465. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15466. if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext))
  15467. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15468. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15469. if (ret < 0)
  15470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15471. ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext);
  15472. if (ret < 0)
  15473. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15474. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15475. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15476. out:
  15477. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15478. XFREE(chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15479. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15480. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15481. #endif
  15482. return ret;
  15483. }
  15484. #endif /* HAVE_XCHACHA */
  15485. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  15486. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void) {
  15487. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15488. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, /* Ladies and Gentl */
  15489. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, /* emen of the clas */
  15490. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, /* s of '99: If I c */
  15491. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, /* ould offer you o */
  15492. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, /* nly one tip for */
  15493. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, /* the future, suns */
  15494. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, /* creen would be i */
  15495. 0x74, 0x2e }; /* t. */
  15496. WOLFSSL_SMALL_STACK_STATIC const byte AAD[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; /* PQRS........ */
  15497. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15498. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15499. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15500. };
  15501. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15502. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15503. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }; /* PQRSTUVW */
  15504. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15505. 0xbd, 0x6d, 0x17, 0x9d, 0x3e, 0x83, 0xd4, 0x3b, 0x95, 0x76, 0x57, 0x94, 0x93, 0xc0, 0xe9, 0x39,
  15506. 0x57, 0x2a, 0x17, 0x00, 0x25, 0x2b, 0xfa, 0xcc, 0xbe, 0xd2, 0x90, 0x2c, 0x21, 0x39, 0x6c, 0xbb,
  15507. 0x73, 0x1c, 0x7f, 0x1b, 0x0b, 0x4a, 0xa6, 0x44, 0x0b, 0xf3, 0xa8, 0x2f, 0x4e, 0xda, 0x7e, 0x39,
  15508. 0xae, 0x64, 0xc6, 0x70, 0x8c, 0x54, 0xc2, 0x16, 0xcb, 0x96, 0xb7, 0x2e, 0x12, 0x13, 0xb4, 0x52,
  15509. 0x2f, 0x8c, 0x9b, 0xa4, 0x0d, 0xb5, 0xd9, 0x45, 0xb1, 0x1b, 0x69, 0xb9, 0x82, 0xc1, 0xbb, 0x9e,
  15510. 0x3f, 0x3f, 0xac, 0x2b, 0xc3, 0x69, 0x48, 0x8f, 0x76, 0xb2, 0x38, 0x35, 0x65, 0xd3, 0xff, 0xf9,
  15511. 0x21, 0xf9, 0x66, 0x4c, 0x97, 0x63, 0x7d, 0xa9, 0x76, 0x88, 0x12, 0xf6, 0x15, 0xc6, 0x8b, 0x13,
  15512. 0xb5, 0x2e };
  15513. WOLFSSL_SMALL_STACK_STATIC const byte Tag[] = {
  15514. 0xc0, 0x87, 0x59, 0x24, 0xc1, 0xc7, 0x98, 0x79, 0x47, 0xde, 0xaf, 0xd8, 0x78, 0x0a, 0xcf, 0x49
  15515. };
  15516. wc_test_ret_t ret;
  15517. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15518. byte *buf1 = (byte *)XMALLOC(sizeof Ciphertext + sizeof Tag, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15519. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15520. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15521. if ((buf1 == NULL) || (buf2 == NULL))
  15522. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15523. #else
  15524. byte buf1[sizeof Ciphertext + sizeof Tag];
  15525. byte buf2[sizeof Plaintext];
  15526. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15527. #endif
  15528. ret = wc_XChaCha20Poly1305_Encrypt(buf1, sizeof Ciphertext + sizeof Tag,
  15529. Plaintext, sizeof Plaintext,
  15530. AAD, sizeof AAD,
  15531. IV, sizeof IV,
  15532. Key, sizeof Key);
  15533. if (ret < 0)
  15534. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15535. if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext))
  15536. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15537. if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE))
  15538. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15539. ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext,
  15540. buf1, sizeof Ciphertext + sizeof Tag,
  15541. AAD, sizeof AAD,
  15542. IV, sizeof IV,
  15543. Key, sizeof Key);
  15544. if (ret < 0)
  15545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15546. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15547. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15548. out:
  15549. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15550. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15551. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15552. #endif
  15553. return ret;
  15554. }
  15555. #endif /* defined(HAVE_XCHACHA) && defined(HAVE_POLY1305) */
  15556. #ifndef WC_NO_RNG
  15557. static wc_test_ret_t _rng_test(WC_RNG* rng)
  15558. {
  15559. byte block[32];
  15560. wc_test_ret_t ret;
  15561. int i;
  15562. XMEMSET(block, 0, sizeof(block));
  15563. ret = wc_RNG_GenerateBlock(rng, block, sizeof(block));
  15564. if (ret != 0) {
  15565. return WC_TEST_RET_ENC_EC(ret);
  15566. }
  15567. /* Check for 0's */
  15568. for (i=0; i<(int)sizeof(block); i++) {
  15569. if (block[i] == 0) {
  15570. ret++;
  15571. }
  15572. }
  15573. /* All zeros count check */
  15574. if (ret >= (int)sizeof(block)) {
  15575. return WC_TEST_RET_ENC_NC;
  15576. }
  15577. ret = wc_RNG_GenerateByte(rng, block);
  15578. if (ret != 0) {
  15579. return WC_TEST_RET_ENC_EC(ret);
  15580. }
  15581. /* Parameter validation testing. */
  15582. ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block));
  15583. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15584. return WC_TEST_RET_ENC_EC(ret);
  15585. }
  15586. ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block));
  15587. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15588. return WC_TEST_RET_ENC_EC(ret);
  15589. }
  15590. ret = wc_RNG_GenerateByte(NULL, block);
  15591. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15592. return WC_TEST_RET_ENC_EC(ret);
  15593. }
  15594. ret = wc_RNG_GenerateByte(rng, NULL);
  15595. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15596. return WC_TEST_RET_ENC_EC(ret);
  15597. }
  15598. return 0;
  15599. }
  15600. static wc_test_ret_t random_rng_test(void)
  15601. {
  15602. WC_RNG localRng;
  15603. WC_RNG* rng;
  15604. wc_test_ret_t ret;
  15605. rng = &localRng;
  15606. /* Test stack based RNG. */
  15607. #ifndef HAVE_FIPS
  15608. ret = wc_InitRng_ex(rng, HEAP_HINT, devId);
  15609. #else
  15610. ret = wc_InitRng(rng);
  15611. #endif
  15612. if (ret != 0)
  15613. return WC_TEST_RET_ENC_EC(ret);
  15614. ret = _rng_test(rng);
  15615. /* Make sure and free RNG */
  15616. wc_FreeRng(rng);
  15617. if (ret != 0)
  15618. return ret;
  15619. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
  15620. {
  15621. byte nonce[8] = { 0 };
  15622. /* Test dynamic RNG */
  15623. rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
  15624. if (rng == NULL)
  15625. return WC_TEST_RET_ENC_ERRNO;
  15626. ret = _rng_test(rng);
  15627. wc_rng_free(rng);
  15628. rng = NULL;
  15629. if (ret != 0)
  15630. return ret;
  15631. /* Test dynamic RNG using extended API */
  15632. ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
  15633. HEAP_HINT, devId);
  15634. if (ret != 0)
  15635. return WC_TEST_RET_ENC_EC(ret);
  15636. ret = _rng_test(rng);
  15637. wc_rng_free(rng);
  15638. if (ret != 0)
  15639. return ret;
  15640. }
  15641. #endif
  15642. return ret;
  15643. }
  15644. #if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  15645. #ifdef WC_RNG_SEED_CB
  15646. static int seed_cb(OS_Seed* os, byte* output, word32 sz)
  15647. {
  15648. word32 i;
  15649. (void)os;
  15650. /* Known answer test. Set the seed to the same value every time. */
  15651. for (i = 0; i < sz; i++)
  15652. output[i] = (byte)i;
  15653. return 0;
  15654. }
  15655. static wc_test_ret_t rng_seed_test(void)
  15656. {
  15657. #ifndef HAVE_FIPS
  15658. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15659. {
  15660. 0x83, 0x46, 0x65, 0x2f, 0x5c, 0x44, 0x16, 0x5f,
  15661. 0xb3, 0x89, 0x26, 0xde, 0x0b, 0x6b, 0xa2, 0x06,
  15662. 0x7e, 0xa7, 0x9a, 0x55, 0x22, 0x01, 0xb0, 0x22,
  15663. 0xf4, 0x7e, 0xa2, 0x66, 0xc4, 0x08, 0x6f, 0xba
  15664. };
  15665. #else
  15666. /* FIPS uses a longer seed, so different check value. */
  15667. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15668. {
  15669. 0xaf, 0x31, 0xcc, 0xef, 0xa9, 0x29, 0x4c, 0x24,
  15670. 0xbd, 0xa5, 0xa3, 0x52, 0x69, 0xf3, 0xb9, 0xb2,
  15671. 0x1e, 0xd4, 0x52, 0x3b, 0x9a, 0x96, 0x06, 0x20,
  15672. 0xc0, 0x5f, 0x44, 0x06, 0x1f, 0x80, 0xdf, 0xe0
  15673. };
  15674. #endif
  15675. byte output[WC_SHA256_DIGEST_SIZE];
  15676. WC_RNG rng;
  15677. wc_test_ret_t ret;
  15678. ret = wc_SetSeed_Cb(seed_cb);
  15679. if (ret != 0) {
  15680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15681. }
  15682. ret = wc_InitRng(&rng);
  15683. if (ret != 0) {
  15684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15685. }
  15686. ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output));
  15687. if (ret != 0) {
  15688. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15689. }
  15690. ret = XMEMCMP(output, check, sizeof(output));
  15691. if (ret != 0) {
  15692. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15693. }
  15694. ret = wc_FreeRng(&rng);
  15695. if (ret != 0) {
  15696. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15697. }
  15698. ret = wc_SetSeed_Cb(wc_GenerateSeed);
  15699. if (ret != 0) {
  15700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15701. }
  15702. out:
  15703. return ret;
  15704. }
  15705. #endif
  15706. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15707. {
  15708. WOLFSSL_SMALL_STACK_STATIC const byte test1Entropy[] =
  15709. {
  15710. 0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e, 0xff, 0xe8, 0x75, 0xc3,
  15711. 0xa2, 0xe7, 0x1f, 0x42, 0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
  15712. 0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb, 0x85, 0x81, 0xf9, 0x31,
  15713. 0x75, 0x17, 0x27, 0x6e, 0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
  15714. };
  15715. WOLFSSL_SMALL_STACK_STATIC const byte test1Output[] =
  15716. {
  15717. 0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40, 0xb2, 0x62, 0x82, 0x64,
  15718. 0xd1, 0x75, 0x10, 0x60, 0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
  15719. 0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d, 0xaa, 0xf6, 0xa6, 0xc3,
  15720. 0x5a, 0x91, 0xbb, 0x45, 0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
  15721. 0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed, 0x52, 0x8f, 0x01, 0x81,
  15722. 0x21, 0xb3, 0xfe, 0xbd, 0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
  15723. 0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1, 0x77, 0xcf, 0xa6, 0xb7,
  15724. 0x1f, 0xe8, 0xab, 0x1d, 0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
  15725. 0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99, 0x0e, 0xea, 0xeb, 0x91,
  15726. 0x12, 0x04, 0x15, 0x52, 0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
  15727. 0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
  15728. };
  15729. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyA[] =
  15730. {
  15731. 0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46, 0x8d, 0xeb, 0x0a, 0xb4,
  15732. 0xa8, 0xed, 0x68, 0x3f, 0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
  15733. 0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69, 0x80, 0x8a, 0xa3, 0x8f,
  15734. 0x2a, 0x72, 0xa6, 0x23, 0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
  15735. };
  15736. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyB[] =
  15737. {
  15738. 0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6, 0x98, 0x05, 0x66, 0xe3,
  15739. 0xbf, 0xe3, 0xc0, 0x49, 0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
  15740. 0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
  15741. };
  15742. WOLFSSL_SMALL_STACK_STATIC const byte test2Output[] =
  15743. {
  15744. 0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c, 0x63, 0x0a, 0x1a, 0xfb,
  15745. 0xe7, 0x24, 0x94, 0x9d, 0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
  15746. 0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62, 0x1c, 0x18, 0xbd, 0xdc,
  15747. 0xdd, 0x8d, 0x99, 0xfc, 0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
  15748. 0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1, 0xdd, 0xd6, 0xc0, 0x71,
  15749. 0x31, 0x8a, 0x60, 0x18, 0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
  15750. 0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10, 0x5d, 0x92, 0x99, 0xb8,
  15751. 0xaf, 0x99, 0xaa, 0x07, 0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
  15752. 0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09, 0x88, 0x96, 0xff, 0x22,
  15753. 0x82, 0xc9, 0x55, 0xa8, 0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
  15754. 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
  15755. };
  15756. byte output[WC_SHA256_DIGEST_SIZE * 4];
  15757. wc_test_ret_t ret;
  15758. WOLFSSL_ENTER("random_test");
  15759. ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
  15760. output, sizeof(output));
  15761. if (ret != 0)
  15762. return WC_TEST_RET_ENC_EC(ret);
  15763. if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
  15764. return WC_TEST_RET_ENC_NC;
  15765. ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
  15766. test2EntropyB, sizeof(test2EntropyB),
  15767. output, sizeof(output));
  15768. if (ret != 0)
  15769. return WC_TEST_RET_ENC_EC(ret);
  15770. if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
  15771. return WC_TEST_RET_ENC_NC;
  15772. /* Basic RNG generate block test */
  15773. if ((ret = random_rng_test()) != 0)
  15774. return ret;
  15775. /* Test the seed check function. */
  15776. #if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
  15777. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  15778. {
  15779. word32 i, outputSz;
  15780. /* Repeat the same byte over and over. Should fail. */
  15781. outputSz = sizeof(output);
  15782. XMEMSET(output, 1, outputSz);
  15783. ret = wc_RNG_TestSeed(output, outputSz);
  15784. if (ret == 0)
  15785. return WC_TEST_RET_ENC_NC;
  15786. /* Every byte of the entropy scratch is different,
  15787. * entropy is a single byte that shouldn't match. */
  15788. outputSz = (sizeof(output) / 2) + 1;
  15789. for (i = 0; i < outputSz; i++)
  15790. output[i] = (byte)i;
  15791. ret = wc_RNG_TestSeed(output, outputSz);
  15792. if (ret != 0)
  15793. return WC_TEST_RET_ENC_EC(ret);
  15794. outputSz = sizeof(output);
  15795. for (i = 0; i < outputSz; i++)
  15796. output[i] = (byte)i;
  15797. ret = wc_RNG_TestSeed(output, outputSz);
  15798. if (ret != 0)
  15799. return WC_TEST_RET_ENC_EC(ret);
  15800. }
  15801. #endif
  15802. /* Test the seed callback. */
  15803. #ifdef WC_RNG_SEED_CB
  15804. if ((ret = rng_seed_test()) != 0)
  15805. return ret;
  15806. #endif
  15807. return 0;
  15808. }
  15809. #else
  15810. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15811. {
  15812. WOLFSSL_ENTER("random_test");
  15813. /* Basic RNG generate block test */
  15814. return random_rng_test();
  15815. }
  15816. #endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
  15817. #endif /* WC_NO_RNG */
  15818. #ifndef MEM_TEST_SZ
  15819. #define MEM_TEST_SZ 1024
  15820. #endif
  15821. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15822. static int simple_mem_test(int sz)
  15823. {
  15824. int ret = 0;
  15825. byte* b;
  15826. int i;
  15827. b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15828. if (b == NULL) {
  15829. return WC_TEST_RET_ENC_NC;
  15830. }
  15831. /* utilize memory */
  15832. for (i = 0; i < sz; i++) {
  15833. b[i] = (byte)i;
  15834. }
  15835. /* read back and verify */
  15836. for (i = 0; i < sz; i++) {
  15837. if (b[i] != (byte)i) {
  15838. ret = WC_TEST_RET_ENC_NC;
  15839. break;
  15840. }
  15841. }
  15842. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15843. return ret;
  15844. }
  15845. #endif
  15846. /* If successful, returns the first letter of the byte array `in`.
  15847. **
  15848. ** This is a deceptively simple test of a read-only embedded Linux file system.
  15849. ** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
  15850. ** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
  15851. ** Const is on read-only memory-mapped file system, *not* loaded in app memory.
  15852. **
  15853. ** Edit with caution. See PR #6523. */
  15854. static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
  15855. {
  15856. wc_test_ret_t ret = 0;
  15857. volatile word32 j = (word32)-1; /* must be volatile to properly detect error */
  15858. ret = (wc_test_ret_t)*in; /* accessed *in value. */
  15859. (void)ret;
  15860. j = *outJ; /* Found index to use in const array. */
  15861. if (j == 0) {
  15862. #ifdef WOLFSSL_DEBUG
  15863. printf("Testing const byte ptr reference...\n");
  15864. #endif
  15865. /* although j is zero, in[0] does not detect the Illegal instruction */
  15866. ret = in[j]; /* The big test: can we actually access the `in` data? */
  15867. }
  15868. else {
  15869. ret = WC_TEST_RET_ENC_I(j);
  15870. }
  15871. return ret;
  15872. }
  15873. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
  15874. {
  15875. wc_test_ret_t ret = 0;
  15876. word32 j = 0; /* used in embedded const pointer test */
  15877. WOLFSSL_ENTER("memory_test");
  15878. #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
  15879. int i;
  15880. #endif
  15881. #ifdef WOLFSSL_STATIC_MEMORY
  15882. word32 size[] = { WOLFMEM_BUCKETS };
  15883. word32 dist[] = { WOLFMEM_DIST };
  15884. byte buffer[30000]; /* make large enough to involve many bucket sizes */
  15885. int pad = -(int)((wc_ptr_t)buffer) & (WOLFSSL_STATIC_ALIGN - 1);
  15886. /* pad to account for if head of buffer is not at set memory
  15887. * alignment when tests are ran */
  15888. #endif
  15889. #ifdef WOLFSSL_STATIC_MEMORY
  15890. /* check macro settings */
  15891. if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15892. return WC_TEST_RET_ENC_NC;
  15893. }
  15894. if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15895. return WC_TEST_RET_ENC_NC;
  15896. }
  15897. if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
  15898. return WC_TEST_RET_ENC_NC;
  15899. }
  15900. for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
  15901. if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
  15902. /* each element in array should be divisible by alignment size */
  15903. return WC_TEST_RET_ENC_NC;
  15904. }
  15905. }
  15906. for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
  15907. if (size[i - 1] >= size[i]) {
  15908. return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
  15909. }
  15910. }
  15911. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  15912. /* check that padding size returned is possible */
  15913. if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) {
  15914. return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */
  15915. }
  15916. ret = wolfSSL_MemoryPaddingSz();
  15917. if (ret < 0) {
  15918. return WC_TEST_RET_ENC_EC(ret);
  15919. }
  15920. if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) {
  15921. return WC_TEST_RET_ENC_NC; /* not aligned! */
  15922. }
  15923. /* check function to return optimum buffer size (rounded down) */
  15924. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL);
  15925. if (ret < 0) {
  15926. return WC_TEST_RET_ENC_EC(ret);
  15927. }
  15928. if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) {
  15929. return WC_TEST_RET_ENC_NC; /* not aligned! */
  15930. }
  15931. if ((unsigned int)ret > sizeof(buffer)) {
  15932. return WC_TEST_RET_ENC_NC; /* did not round down as expected */
  15933. }
  15934. if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) {
  15935. return WC_TEST_RET_ENC_NC; /* return value changed when using suggested
  15936. * value
  15937. */
  15938. }
  15939. ret = wolfSSL_MemoryPaddingSz();
  15940. ret += pad; /* add space that is going to be needed if buffer not aligned */
  15941. if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) !=
  15942. (ret + (int)size[0])) {
  15943. return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket
  15944. * value
  15945. */
  15946. }
  15947. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL);
  15948. if ((ret - pad) < 0) {
  15949. return WC_TEST_RET_ENC_NC;
  15950. }
  15951. if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) {
  15952. return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */
  15953. }
  15954. if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) {
  15955. return WC_TEST_RET_ENC_NC; /* memory not aligned */
  15956. }
  15957. /* check for passing bad or unknown arguments to functions */
  15958. if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) {
  15959. return WC_TEST_RET_ENC_NC;
  15960. }
  15961. if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) {
  15962. return WC_TEST_RET_ENC_NC; /* should round to 0
  15963. since struct + bucket will not fit */
  15964. }
  15965. #endif
  15966. (void)pad;
  15967. (void)dist; /* avoid static analysis warning of variable not used */
  15968. #endif
  15969. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15970. /* simple test */
  15971. ret = simple_mem_test(MEM_TEST_SZ);
  15972. if (ret != 0)
  15973. return ret;
  15974. #endif
  15975. #ifdef COMPLEX_MEM_TEST
  15976. /* test various size blocks */
  15977. for (i = 1; i < MEM_TEST_SZ; i*=2) {
  15978. ret = simple_mem_test(i);
  15979. if (ret != 0)
  15980. return ret;
  15981. }
  15982. #endif
  15983. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC)
  15984. /* realloc test */
  15985. {
  15986. byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT,
  15987. DYNAMIC_TYPE_TMP_BUFFER);
  15988. #ifndef WOLFSSL_NO_REALLOC
  15989. byte *c = NULL;
  15990. if (b) {
  15991. c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT,
  15992. DYNAMIC_TYPE_TMP_BUFFER);
  15993. if (c)
  15994. b = c;
  15995. }
  15996. #endif
  15997. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15998. if (b == NULL
  15999. #ifndef WOLFSSL_NO_REALLOC
  16000. || c == NULL
  16001. #endif
  16002. ) {
  16003. return WC_TEST_RET_ENC_ERRNO;
  16004. }
  16005. }
  16006. #endif
  16007. if (ret == 0) {
  16008. /* This test is only interesting on embedded R/O Flash systems */
  16009. if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
  16010. ret = 1;
  16011. }
  16012. }
  16013. return ret;
  16014. }
  16015. #ifndef NO_FILESYSTEM
  16016. /* Cert Paths */
  16017. #ifdef FREESCALE_MQX
  16018. #define CERT_PREFIX "a:\\"
  16019. #define CERT_PATH_SEP "\\"
  16020. #elif defined(WOLFSSL_uTKERNEL2)
  16021. #define CERT_PREFIX "/uda/"
  16022. #define CERT_PATH_SEP "/"
  16023. #elif defined(_WIN32_WCE)
  16024. #define CERT_PREFIX "\\windows\\"
  16025. #define CERT_PATH_SEP "\\"
  16026. #endif
  16027. #ifndef CERT_PREFIX
  16028. #define CERT_PREFIX "./"
  16029. #endif
  16030. #ifndef CERT_PATH_SEP
  16031. #define CERT_PATH_SEP "/"
  16032. #endif
  16033. #ifndef CERT_WRITE_TEMP_DIR
  16034. #define CERT_WRITE_TEMP_DIR CERT_PREFIX
  16035. #endif
  16036. #define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
  16037. /* Generated Test Certs */
  16038. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16039. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16040. #if !defined(NO_RSA) && !defined(NO_ASN)
  16041. static const char* clientKey = CERT_ROOT "client-key.der";
  16042. static const char* clientCert = CERT_ROOT "client-cert.der";
  16043. #ifdef WOLFSSL_CERT_EXT
  16044. static const char* clientKeyPub = CERT_ROOT "client-keyPub.der";
  16045. #endif
  16046. #endif /* !NO_RSA && !NO_ASN */
  16047. #endif
  16048. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16049. #if !defined(NO_RSA) && !defined(NO_ASN)
  16050. #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_PKCS7)
  16051. static const char* rsaCaKeyFile = CERT_ROOT "ca-key.der";
  16052. #ifdef WOLFSSL_CERT_GEN
  16053. static const char* rsaCaCertFile = CERT_ROOT "ca-cert.pem";
  16054. #endif
  16055. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  16056. static const char* rsaCaCertDerFile = CERT_ROOT "ca-cert.der";
  16057. #endif
  16058. #ifdef HAVE_PKCS7
  16059. static const char* rsaServerCertDerFile =
  16060. CERT_ROOT "server-cert.der";
  16061. static const char* rsaServerKeyDerFile =
  16062. CERT_ROOT "server-key.der";
  16063. #endif
  16064. #endif
  16065. #endif /* !NO_RSA && !NO_ASN */
  16066. #endif /* !USE_CERT_BUFFER_* */
  16067. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16068. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16069. #if !defined(NO_ASN) && !defined(NO_DH)
  16070. static const char* dhParamsFile = CERT_ROOT "dh2048.der";
  16071. #endif
  16072. #endif
  16073. #if !defined(NO_ASN) && !defined(NO_DH)
  16074. #if defined(WOLFSSL_DH_EXTRA) && (!defined(HAVE_FIPS) || \
  16075. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  16076. #if !defined(USE_CERT_BUFFERS_2048)
  16077. static const char* dhKeyFile = CERT_ROOT "statickeys/dh-ffdhe2048.der";
  16078. static const char* dhKeyPubFile = CERT_ROOT "statickeys/dh-ffdhe2048-pub.der";
  16079. #endif
  16080. #endif
  16081. #endif
  16082. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16083. #ifndef NO_DSA
  16084. static const char* dsaKey = CERT_ROOT "dsa2048.der";
  16085. #endif
  16086. #endif /* !USE_CERT_BUFFER_* */
  16087. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ECC256)
  16088. #ifdef HAVE_ECC
  16089. /* cert files to be used in rsa cert gen test, check if RSA enabled */
  16090. #ifdef HAVE_ECC_KEY_IMPORT
  16091. static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der";
  16092. #endif
  16093. #endif
  16094. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN)
  16095. #if defined(HAVE_ECC) && defined(WOLFSSL_CERT_GEN) && \
  16096. !defined(NO_ECC_SECP)
  16097. #ifndef NO_RSA
  16098. static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der";
  16099. #endif
  16100. #ifndef NO_ASN_TIME
  16101. static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der";
  16102. static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem";
  16103. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16104. static const char* eccCaKey384File =
  16105. CERT_ROOT "ca-ecc384-key.der";
  16106. static const char* eccCaCert384File =
  16107. CERT_ROOT "ca-ecc384-cert.pem";
  16108. #endif
  16109. #endif
  16110. #endif
  16111. #if defined(HAVE_PKCS7) && defined(HAVE_ECC)
  16112. static const char* eccClientKey = CERT_ROOT "ecc-client-key.der";
  16113. static const char* eccClientCert = CERT_ROOT "client-ecc-cert.der";
  16114. #endif
  16115. #endif /* HAVE_ECC */
  16116. #ifdef HAVE_ED25519
  16117. #ifdef WOLFSSL_TEST_CERT
  16118. static const char* serverEd25519Cert =
  16119. CERT_ROOT "ed25519/server-ed25519.der";
  16120. static const char* caEd25519Cert =
  16121. CERT_ROOT "ed25519/ca-ed25519.der";
  16122. #endif
  16123. #endif
  16124. #ifdef HAVE_ED448
  16125. #ifdef WOLFSSL_TEST_CERT
  16126. static const char* serverEd448Cert =
  16127. CERT_ROOT "ed448/server-ed448.der";
  16128. static const char* caEd448Cert = CERT_ROOT "ed448/ca-ed448.der";
  16129. #endif
  16130. #endif
  16131. #endif /* !USE_CERT_BUFFER_* */
  16132. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16133. !defined(NO_FILESYSTEM)
  16134. static const char* certExtNc =
  16135. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nc.der";
  16136. static const char* certExtIa =
  16137. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-ia.der";
  16138. static const char* certExtNct =
  16139. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nct.der";
  16140. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16141. static const char* certBadNegInt =
  16142. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-neg-int.der";
  16143. #endif
  16144. static const char* certBadOid =
  16145. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-oid.der";
  16146. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16147. static const char* certBadUtf8 =
  16148. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-utf8.der";
  16149. #endif
  16150. #endif
  16151. #ifndef NO_WRITE_TEMP_FILES
  16152. #ifdef HAVE_ECC
  16153. #ifndef NO_ECC_SECP
  16154. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  16155. static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem";
  16156. static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
  16157. #endif
  16158. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  16159. static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
  16160. static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
  16161. #endif
  16162. #endif
  16163. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  16164. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT)
  16165. static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem";
  16166. static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
  16167. static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
  16168. #if defined(HAVE_PKCS8) && !defined(WC_NO_RNG) && \
  16169. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  16170. static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
  16171. #endif
  16172. #endif /* HAVE_ECC_KEY_EXPORT */
  16173. #endif /* HAVE_ECC */
  16174. #ifndef NO_RSA
  16175. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  16176. static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
  16177. static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
  16178. static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
  16179. static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
  16180. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  16181. static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
  16182. static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
  16183. #endif
  16184. #endif
  16185. #endif /* !NO_RSA */
  16186. #if !defined(NO_RSA) || !defined(NO_DSA)
  16187. #ifdef WOLFSSL_KEY_GEN
  16188. static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
  16189. static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
  16190. #endif
  16191. #endif
  16192. #endif /* !NO_WRITE_TEMP_FILES */
  16193. #endif /* !NO_FILESYSTEM */
  16194. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  16195. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  16196. static CertName certDefaultName;
  16197. static void initDefaultName(void)
  16198. {
  16199. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16200. NameAttrib* n;
  16201. #endif
  16202. XMEMCPY(certDefaultName.country, "US", sizeof("US"));
  16203. certDefaultName.countryEnc = CTC_PRINTABLE;
  16204. XMEMCPY(certDefaultName.state, "Oregon", sizeof("Oregon"));
  16205. certDefaultName.stateEnc = CTC_UTF8;
  16206. XMEMCPY(certDefaultName.street, "Main St", sizeof("Main St"));
  16207. certDefaultName.streetEnc = CTC_UTF8;
  16208. XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
  16209. certDefaultName.localityEnc = CTC_UTF8;
  16210. XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
  16211. certDefaultName.surEnc = CTC_UTF8;
  16212. XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
  16213. certDefaultName.orgEnc = CTC_UTF8;
  16214. XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
  16215. certDefaultName.unitEnc = CTC_UTF8;
  16216. XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  16217. certDefaultName.commonNameEnc = CTC_UTF8;
  16218. XMEMCPY(certDefaultName.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  16219. certDefaultName.serialDevEnc = CTC_PRINTABLE;
  16220. XMEMCPY(certDefaultName.postalCode, "12-456", sizeof("12-456"));
  16221. certDefaultName.postalCodeEnc = CTC_PRINTABLE;
  16222. #ifdef WOLFSSL_CERT_EXT
  16223. XMEMCPY(certDefaultName.busCat, "Private Organization", sizeof("Private Organization"));
  16224. certDefaultName.busCatEnc = CTC_UTF8;
  16225. XMEMCPY(certDefaultName.joiSt, "US", sizeof("US"));
  16226. certDefaultName.joiStEnc = CTC_PRINTABLE;
  16227. XMEMCPY(certDefaultName.joiC, "Oregon", sizeof("Oregon"));
  16228. certDefaultName.joiCEnc = CTC_PRINTABLE;
  16229. #endif
  16230. XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
  16231. XMEMCPY(certDefaultName.userId, "TestUserID", sizeof("TestUserID"));
  16232. certDefaultName.userIdEnc = CTC_PRINTABLE;
  16233. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16234. /* test having additional OUs and setting DC */
  16235. n = &certDefaultName.name[0];
  16236. n->id = ASN_ORGUNIT_NAME;
  16237. n->type = CTC_UTF8;
  16238. n->sz = XSTRLEN("Development-2");
  16239. XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
  16240. #if CTC_MAX_ATTRIB > 3
  16241. n = &certDefaultName.name[1];
  16242. n->id = ASN_DOMAIN_COMPONENT;
  16243. n->type = CTC_UTF8;
  16244. n->sz = XSTRLEN("com");
  16245. XMEMCPY(n->value, "com", sizeof("com"));
  16246. n = &certDefaultName.name[2];
  16247. n->id = ASN_DOMAIN_COMPONENT;
  16248. n->type = CTC_UTF8;
  16249. n->sz = XSTRLEN("wolfssl");
  16250. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  16251. #endif
  16252. #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */
  16253. #ifdef WOLFSSL_CUSTOM_OID
  16254. /* TODO: Add test case for custom OID's */
  16255. #endif
  16256. }
  16257. #ifdef WOLFSSL_CERT_EXT
  16258. #if ((defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  16259. defined(WOLFSSL_TEST_CERT)) || defined(HAVE_ECC)
  16260. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] =
  16261. "digitalSignature,nonRepudiation";
  16262. #endif
  16263. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME)
  16264. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] =
  16265. "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement";
  16266. #endif
  16267. #endif /* WOLFSSL_CERT_EXT */
  16268. #endif /* WOLFSSL_CERT_GEN */
  16269. #ifndef NO_RSA
  16270. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16271. !defined(NO_FILESYSTEM)
  16272. static const byte minSerial[] = { 0x02, 0x01, 0x01 };
  16273. static const byte minName[] = { 0x30, 0x00 };
  16274. static const byte nameBad[] = {
  16275. 0x30, 0x08,
  16276. 0x31, 0x06,
  16277. 0x30, 0x04,
  16278. 0x06, 0x02,
  16279. 0x55, 0x04,
  16280. };
  16281. static const byte minDates[] = {
  16282. 0x30, 0x1e,
  16283. 0x17, 0x0d,
  16284. 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35,
  16285. 0x32, 0x33, 0x31, 0x30, 0x5a,
  16286. 0x17, 0x0d,
  16287. 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35,
  16288. 0x32, 0x33, 0x31, 0x30, 0x5a
  16289. };
  16290. static const byte minPubKey[] = {
  16291. 0x30, 0x1c,
  16292. 0x30, 0x0d,
  16293. 0x06, 0x09,
  16294. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16295. 0x01,
  16296. 0x05, 0x00,
  16297. 0x03, 0x0b,
  16298. 0x00, 0x30, 0x08,
  16299. 0x02, 0x01,
  16300. 0x03,
  16301. 0x02, 0x03,
  16302. 0x01, 0x00, 0x01
  16303. };
  16304. static const byte minSigAlg[] = {
  16305. 0x30, 0x0d,
  16306. 0x06, 0x09,
  16307. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16308. 0x0b,
  16309. 0x05, 0x00
  16310. };
  16311. static const byte minSig[] = {
  16312. 0x03, 0x01,
  16313. 0x00
  16314. };
  16315. static int add_seq(byte* certData, int offset, byte* data, byte length)
  16316. {
  16317. XMEMMOVE(certData + offset + 2, data, length);
  16318. certData[offset++] = 0x30;
  16319. certData[offset++] = length;
  16320. return offset + length;
  16321. }
  16322. static int add_data(byte* certData, int offset, const byte* data, byte length)
  16323. {
  16324. XMEMCPY(certData + offset, data, length);
  16325. return offset + length;
  16326. }
  16327. static wc_test_ret_t cert_asn1_test(void)
  16328. {
  16329. wc_test_ret_t ret;
  16330. int len[3];
  16331. DecodedCert cert;
  16332. byte certData[114];
  16333. byte* badCert = NULL;
  16334. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16335. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16336. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16337. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16338. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16339. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16340. len[1] = add_seq(certData, 0, certData, len[2]);
  16341. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16342. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16343. len[0] = add_seq(certData, 0, certData, len[1]);
  16344. /* Minimal good certificate */
  16345. InitDecodedCert(&cert, certData, len[0], 0);
  16346. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16347. FreeDecodedCert(&cert);
  16348. if (ret != 0)
  16349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16350. /* Bad issuer name */
  16351. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16352. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16353. len[2] = add_data(certData, len[2], nameBad, (byte)sizeof(nameBad));
  16354. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16355. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16356. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16357. len[1] = add_seq(certData, 0, certData, len[2]);
  16358. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16359. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16360. len[0] = add_seq(certData, 0, certData, len[1]);
  16361. /* Put data into allocated buffer to allow access error checking. */
  16362. badCert = (byte*)XMALLOC(len[0], HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16363. XMEMCPY(badCert, certData, len[0]);
  16364. InitDecodedCert(&cert, badCert, len[0], 0);
  16365. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16366. FreeDecodedCert(&cert);
  16367. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  16368. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16369. }
  16370. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16371. badCert = NULL;
  16372. ret = 0;
  16373. done:
  16374. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16375. return ret;
  16376. }
  16377. static wc_test_ret_t cert_load_bad(const char* fname, byte* tmp, int err)
  16378. {
  16379. wc_test_ret_t ret;
  16380. DecodedCert cert;
  16381. XFILE file;
  16382. size_t bytes;
  16383. if ((fname == NULL) || (tmp == NULL)) {
  16384. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  16385. }
  16386. file = XFOPEN(fname, "rb");
  16387. if (!file) {
  16388. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16389. }
  16390. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16391. XFCLOSE(file);
  16392. if (bytes == 0) {
  16393. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16394. }
  16395. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16396. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16397. FreeDecodedCert(&cert);
  16398. if (ret != err) {
  16399. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16400. }
  16401. ret = 0;
  16402. done:
  16403. return ret;
  16404. }
  16405. static wc_test_ret_t cert_bad_asn1_test(void)
  16406. {
  16407. wc_test_ret_t ret = 0;
  16408. byte* tmp;
  16409. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16410. if (tmp == NULL) {
  16411. ret = WC_TEST_RET_ENC_ERRNO;
  16412. }
  16413. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16414. if (ret == 0) {
  16415. /* Serial number: 0xff 0xa8. 0xff and top bit set on next byte invalid.
  16416. */
  16417. ret = cert_load_bad(certBadNegInt, tmp, ASN_EXPECT_0_E);
  16418. }
  16419. #endif
  16420. if (ret == 0) {
  16421. /* Subject name OID: 55 04 f4. Last byte with top bit set invalid. */
  16422. ret = cert_load_bad(certBadOid, tmp, ASN_PARSE_E);
  16423. }
  16424. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16425. if (ret == 0) {
  16426. /* Issuer name UTF8STRING: df 52 4e 44. Top bit of second byte not set.
  16427. */
  16428. ret = cert_load_bad(certBadUtf8, tmp, ASN_PARSE_E);
  16429. }
  16430. #endif
  16431. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16432. return ret;
  16433. }
  16434. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void)
  16435. {
  16436. #if !defined(NO_FILESYSTEM)
  16437. DecodedCert cert;
  16438. byte* tmp;
  16439. size_t bytes;
  16440. XFILE file;
  16441. wc_test_ret_t ret;
  16442. WOLFSSL_ENTER("cert_test");
  16443. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16444. if (tmp == NULL)
  16445. return WC_TEST_RET_ENC_ERRNO;
  16446. /* Certificate with Name Constraints extension. */
  16447. file = XFOPEN(certExtNc, "rb");
  16448. if (!file) {
  16449. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16450. }
  16451. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16452. XFCLOSE(file);
  16453. if (bytes == 0)
  16454. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16455. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16456. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16457. if (ret != 0)
  16458. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16459. FreeDecodedCert(&cert);
  16460. /* Certificate with Inhibit Any Policy extension. */
  16461. file = XFOPEN(certExtIa, "rb");
  16462. if (!file) {
  16463. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16464. }
  16465. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16466. XFCLOSE(file);
  16467. if (bytes == 0)
  16468. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16469. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16470. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16471. if (ret != 0)
  16472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16473. FreeDecodedCert(&cert);
  16474. /* Certificate with Netscape Certificate Type extension. */
  16475. file = XFOPEN(certExtNct, "rb");
  16476. if (!file) {
  16477. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16478. }
  16479. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16480. XFCLOSE(file);
  16481. if (bytes == 0)
  16482. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16483. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16484. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16485. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  16486. if (ret != 0)
  16487. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16488. #else
  16489. if (ret != WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
  16490. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16491. }
  16492. ret = 0;
  16493. #endif
  16494. done:
  16495. FreeDecodedCert(&cert);
  16496. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16497. #endif /* !NO_FILESYSTEM */
  16498. if (ret == 0)
  16499. ret = cert_asn1_test();
  16500. if (ret == 0)
  16501. ret = cert_bad_asn1_test();
  16502. return ret;
  16503. }
  16504. #endif /* WOLFSSL_TEST_CERT */
  16505. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  16506. !defined(NO_FILESYSTEM) && defined(WOLFSSL_CERT_GEN)
  16507. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void)
  16508. {
  16509. DecodedCert cert;
  16510. byte* tmp;
  16511. size_t bytes;
  16512. XFILE file;
  16513. wc_test_ret_t ret;
  16514. /* created from rsa_test : othercert.der */
  16515. byte skid_rsa[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16516. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16517. /* created from rsa_test : othercert.der */
  16518. byte akid_rsa[] = "\x27\x8E\x67\x11\x74\xC3\x26\x1D\x3F\xED"
  16519. "\x33\x63\xB3\xA4\xD8\x1D\x30\xE5\xE8\xD5";
  16520. #ifdef HAVE_ECC
  16521. /* created from ecc_test_cert_gen : certecc.der */
  16522. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16523. /* Authority key id from ./certs/ca-ecc384-cert.pem */
  16524. byte akid_ecc[] = "\xAB\xE0\xC3\x26\x4C\x18\xD4\x72\xBB\xD2"
  16525. "\x84\x8C\x9C\x0A\x05\x92\x80\x12\x53\x52";
  16526. #else
  16527. /* Authority key id from ./certs/ca-ecc-cert.pem */
  16528. byte akid_ecc[] = "\x56\x8E\x9A\xC3\xF0\x42\xDE\x18\xB9\x45"
  16529. "\x55\x6E\xF9\x93\xCF\xEA\xC3\xF3\xA5\x21";
  16530. #endif
  16531. #endif /* HAVE_ECC */
  16532. /* created from rsa_test : cert.der */
  16533. byte kid_ca[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16534. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16535. WOLFSSL_ENTER("certext_test");
  16536. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16537. if (tmp == NULL)
  16538. return WC_TEST_RET_ENC_ERRNO;
  16539. /* load othercert.der (Cert signed by an authority) */
  16540. file = XFOPEN(otherCertDerFile, "rb");
  16541. if (!file) {
  16542. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16543. return WC_TEST_RET_ENC_ERRNO;
  16544. }
  16545. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16546. XFCLOSE(file);
  16547. if (bytes == 0)
  16548. return WC_TEST_RET_ENC_ERRNO;
  16549. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16550. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16551. if (ret != 0)
  16552. return WC_TEST_RET_ENC_EC(ret);
  16553. /* check the SKID from a RSA certificate */
  16554. if ((sizeof(skid_rsa) - 1 != cert.extSubjKeyIdSz) ||
  16555. (XMEMCMP(skid_rsa, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16556. return WC_TEST_RET_ENC_NC;
  16557. /* check the AKID from an RSA certificate */
  16558. if ((sizeof(akid_rsa) - 1 != cert.extAuthKeyIdSz) ||
  16559. (XMEMCMP(akid_rsa, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16560. return WC_TEST_RET_ENC_NC;
  16561. /* check the Key Usage from an RSA certificate */
  16562. if (!cert.extKeyUsageSet)
  16563. return WC_TEST_RET_ENC_NC;
  16564. if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE))
  16565. return WC_TEST_RET_ENC_NC;
  16566. /* check the CA Basic Constraints from an RSA certificate */
  16567. if (cert.isCA)
  16568. return WC_TEST_RET_ENC_NC;
  16569. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16570. /* check the Certificate Policies Id */
  16571. if (cert.extCertPoliciesNb != 1)
  16572. return WC_TEST_RET_ENC_NC;
  16573. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16574. return WC_TEST_RET_ENC_NC;
  16575. #endif
  16576. FreeDecodedCert(&cert);
  16577. #ifdef HAVE_ECC
  16578. /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */
  16579. file = XFOPEN(certEccDerFile, "rb");
  16580. if (!file) {
  16581. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16582. return WC_TEST_RET_ENC_ERRNO;
  16583. }
  16584. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16585. XFCLOSE(file);
  16586. if (bytes == 0)
  16587. return WC_TEST_RET_ENC_ERRNO;
  16588. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16589. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16590. if (ret != 0)
  16591. return WC_TEST_RET_ENC_EC(ret);
  16592. /* check the SKID from a ECC certificate - generated dynamically */
  16593. /* check the AKID from an ECC certificate */
  16594. if ((sizeof(akid_ecc) - 1 != cert.extAuthKeyIdSz) ||
  16595. (XMEMCMP(akid_ecc, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16596. return WC_TEST_RET_ENC_NC;
  16597. /* check the Key Usage from an ECC certificate */
  16598. if (!cert.extKeyUsageSet)
  16599. return WC_TEST_RET_ENC_NC;
  16600. if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT))
  16601. return WC_TEST_RET_ENC_NC;
  16602. /* check the CA Basic Constraints from an ECC certificate */
  16603. if (cert.isCA)
  16604. return WC_TEST_RET_ENC_NC;
  16605. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16606. /* check the Certificate Policies Id */
  16607. if (cert.extCertPoliciesNb != 2)
  16608. return WC_TEST_RET_ENC_NC;
  16609. if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32))
  16610. return WC_TEST_RET_ENC_NC;
  16611. if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22))
  16612. return WC_TEST_RET_ENC_NC;
  16613. #endif
  16614. FreeDecodedCert(&cert);
  16615. #endif /* HAVE_ECC */
  16616. /* load cert.der (self signed certificate) */
  16617. file = XFOPEN(certDerFile, "rb");
  16618. if (!file) {
  16619. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16620. return WC_TEST_RET_ENC_ERRNO;
  16621. }
  16622. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16623. XFCLOSE(file);
  16624. if (bytes == 0)
  16625. return WC_TEST_RET_ENC_ERRNO;
  16626. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16627. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16628. if (ret != 0)
  16629. return WC_TEST_RET_ENC_EC(ret);
  16630. /* check the SKID from a CA certificate */
  16631. if ((sizeof(kid_ca) - 1 != cert.extSubjKeyIdSz) ||
  16632. (XMEMCMP(kid_ca, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16633. return WC_TEST_RET_ENC_NC;
  16634. /* check the AKID from an CA certificate */
  16635. if ((sizeof(kid_ca) - 1 != cert.extAuthKeyIdSz) ||
  16636. (XMEMCMP(kid_ca, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16637. return WC_TEST_RET_ENC_NC;
  16638. /* check the Key Usage from CA certificate */
  16639. if (!cert.extKeyUsageSet)
  16640. return WC_TEST_RET_ENC_NC;
  16641. if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN))
  16642. return WC_TEST_RET_ENC_NC;
  16643. /* check the CA Basic Constraints CA certificate */
  16644. if (!cert.isCA)
  16645. return WC_TEST_RET_ENC_NC;
  16646. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16647. /* check the Certificate Policies Id */
  16648. if (cert.extCertPoliciesNb != 2)
  16649. return WC_TEST_RET_ENC_NC;
  16650. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16651. return WC_TEST_RET_ENC_NC;
  16652. if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25))
  16653. return WC_TEST_RET_ENC_NC;
  16654. #endif
  16655. FreeDecodedCert(&cert);
  16656. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16657. return 0;
  16658. }
  16659. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_TEST_CERT &&
  16660. !NO_FILESYSTEM && WOLFSSL_CERT_GEN */
  16661. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  16662. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  16663. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void)
  16664. {
  16665. wc_test_ret_t ret = 0;
  16666. Cert cert;
  16667. FILE* file;
  16668. byte* der;
  16669. word32 derSz;
  16670. WOLFSSL_ENTER("decodedCertCache_test");
  16671. derSz = FOURK_BUF;
  16672. der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16673. if (der == NULL)
  16674. ret = WC_TEST_RET_ENC_NC;
  16675. if (ret == 0) {
  16676. /* load cert.der */
  16677. file = XFOPEN(certDerFile, "rb");
  16678. if (file != NULL) {
  16679. derSz = (word32)XFREAD(der, 1, FOURK_BUF, file);
  16680. XFCLOSE(file);
  16681. if (derSz == 0)
  16682. ret = WC_TEST_RET_ENC_ERRNO;
  16683. }
  16684. else
  16685. ret = WC_TEST_RET_ENC_ERRNO;
  16686. }
  16687. if (ret == 0) {
  16688. ret = wc_InitCert_ex(&cert, HEAP_HINT, devId);
  16689. if (ret != 0)
  16690. ret = WC_TEST_RET_ENC_EC(ret);
  16691. }
  16692. if (ret == 0) {
  16693. ret = wc_SetSubjectBuffer(&cert, der, derSz);
  16694. if (ret != 0)
  16695. ret = WC_TEST_RET_ENC_EC(ret);
  16696. }
  16697. if (ret == 0) {
  16698. ret = wc_SetSubjectBuffer(NULL, der, derSz);
  16699. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16700. ret = 0;
  16701. else
  16702. ret = WC_TEST_RET_ENC_EC(ret);
  16703. }
  16704. if (ret == 0) {
  16705. ret = wc_SetSubjectRaw(&cert, der, derSz);
  16706. if (ret != 0)
  16707. ret = WC_TEST_RET_ENC_EC(ret);
  16708. }
  16709. if (ret == 0) {
  16710. ret = wc_SetSubjectRaw(NULL, der, derSz);
  16711. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16712. ret = 0;
  16713. else
  16714. ret = WC_TEST_RET_ENC_EC(ret);
  16715. }
  16716. if (ret == 0) {
  16717. ret = wc_SetIssuerBuffer(&cert, der, derSz);
  16718. if (ret != 0)
  16719. ret = WC_TEST_RET_ENC_EC(ret);
  16720. }
  16721. if (ret == 0) {
  16722. ret = wc_SetIssuerBuffer(NULL, der, derSz);
  16723. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16724. ret = 0;
  16725. else
  16726. ret = WC_TEST_RET_ENC_EC(ret);
  16727. }
  16728. if (ret == 0) {
  16729. ret = wc_SetIssuerRaw(&cert, der, derSz);
  16730. if (ret != 0)
  16731. ret = WC_TEST_RET_ENC_EC(ret);
  16732. }
  16733. if (ret == 0) {
  16734. ret = wc_SetIssuerRaw(NULL, der, derSz);
  16735. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16736. ret = 0;
  16737. else
  16738. ret = WC_TEST_RET_ENC_EC(ret);
  16739. }
  16740. #ifdef WOLFSSL_ALT_NAMES
  16741. if (ret == 0) {
  16742. ret = wc_SetAltNamesBuffer(&cert, der, derSz);
  16743. if (ret != 0)
  16744. ret = WC_TEST_RET_ENC_EC(ret);
  16745. }
  16746. if (ret == 0) {
  16747. ret = wc_SetAltNamesBuffer(NULL, der, derSz);
  16748. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16749. ret = 0;
  16750. else
  16751. ret = WC_TEST_RET_ENC_EC(ret);
  16752. }
  16753. if (ret == 0) {
  16754. ret = wc_SetDatesBuffer(&cert, der, derSz);
  16755. if (ret != 0)
  16756. ret = WC_TEST_RET_ENC_EC(ret);
  16757. }
  16758. if (ret == 0) {
  16759. ret = wc_SetDatesBuffer(NULL, der, derSz);
  16760. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16761. ret = 0;
  16762. else
  16763. ret = WC_TEST_RET_ENC_EC(ret);
  16764. }
  16765. #endif
  16766. if (ret == 0) {
  16767. ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz);
  16768. if (ret != 0)
  16769. ret = WC_TEST_RET_ENC_EC(ret);
  16770. }
  16771. if (ret == 0) {
  16772. ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz);
  16773. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16774. ret = 0;
  16775. else
  16776. ret = WC_TEST_RET_ENC_NC;
  16777. }
  16778. wc_SetCert_Free(&cert);
  16779. if (ret == 0) {
  16780. if(cert.decodedCert != NULL)
  16781. ret = WC_TEST_RET_ENC_NC;
  16782. }
  16783. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16784. return ret;
  16785. }
  16786. #endif /* defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) &&
  16787. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) */
  16788. #define RSA_TEST_BYTES 512 /* up to 4096-bit key */
  16789. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  16790. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16791. static wc_test_ret_t rsa_flatten_test(RsaKey* key)
  16792. {
  16793. wc_test_ret_t ret;
  16794. byte e[RSA_TEST_BYTES];
  16795. byte n[RSA_TEST_BYTES];
  16796. word32 eSz = sizeof(e);
  16797. word32 nSz = sizeof(n);
  16798. /* Parameter Validation testing. */
  16799. ret = wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz);
  16800. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16801. return WC_TEST_RET_ENC_EC(ret);
  16802. ret = wc_RsaFlattenPublicKey(key, NULL, &eSz, n, &nSz);
  16803. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16804. return WC_TEST_RET_ENC_EC(ret);
  16805. ret = wc_RsaFlattenPublicKey(key, e, NULL, n, &nSz);
  16806. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16807. return WC_TEST_RET_ENC_EC(ret);
  16808. ret = wc_RsaFlattenPublicKey(key, e, &eSz, NULL, &nSz);
  16809. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16810. return WC_TEST_RET_ENC_EC(ret);
  16811. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, NULL);
  16812. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16813. return WC_TEST_RET_ENC_EC(ret);
  16814. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16815. if (ret != 0)
  16816. return WC_TEST_RET_ENC_EC(ret);
  16817. eSz = 0;
  16818. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16819. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16820. return WC_TEST_RET_ENC_EC(ret);
  16821. eSz = sizeof(e);
  16822. nSz = 0;
  16823. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16824. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16825. return WC_TEST_RET_ENC_EC(ret);
  16826. return 0;
  16827. }
  16828. #endif /* NO_ASN */
  16829. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  16830. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16831. static wc_test_ret_t rsa_export_key_test(RsaKey* key)
  16832. {
  16833. wc_test_ret_t ret;
  16834. byte e[3];
  16835. word32 eSz = sizeof(e);
  16836. byte n[RSA_TEST_BYTES];
  16837. word32 nSz = sizeof(n);
  16838. byte d[RSA_TEST_BYTES];
  16839. word32 dSz = sizeof(d);
  16840. byte p[RSA_TEST_BYTES/2];
  16841. word32 pSz = sizeof(p);
  16842. byte q[RSA_TEST_BYTES/2];
  16843. word32 qSz = sizeof(q);
  16844. word32 zero = 0;
  16845. ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16846. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16847. return WC_TEST_RET_ENC_EC(ret);
  16848. ret = wc_RsaExportKey(key, NULL, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16849. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16850. return WC_TEST_RET_ENC_EC(ret);
  16851. ret = wc_RsaExportKey(key, e, NULL, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16852. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16853. return WC_TEST_RET_ENC_EC(ret);
  16854. ret = wc_RsaExportKey(key, e, &eSz, NULL, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16855. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16856. return WC_TEST_RET_ENC_EC(ret);
  16857. ret = wc_RsaExportKey(key, e, &eSz, n, NULL, d, &dSz, p, &pSz, q, &qSz);
  16858. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16859. return WC_TEST_RET_ENC_EC(ret);
  16860. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, NULL, &dSz, p, &pSz, q, &qSz);
  16861. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16862. return WC_TEST_RET_ENC_EC(ret);
  16863. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, NULL, p, &pSz, q, &qSz);
  16864. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16865. return WC_TEST_RET_ENC_EC(ret);
  16866. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, NULL, &pSz, q, &qSz);
  16867. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16868. return WC_TEST_RET_ENC_EC(ret);
  16869. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, NULL, q, &qSz);
  16870. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16871. return WC_TEST_RET_ENC_EC(ret);
  16872. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, NULL, &qSz);
  16873. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16874. return WC_TEST_RET_ENC_EC(ret);
  16875. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, NULL);
  16876. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16877. return WC_TEST_RET_ENC_EC(ret);
  16878. ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16879. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16880. return WC_TEST_RET_ENC_EC(ret);
  16881. ret = wc_RsaExportKey(key, e, &eSz, n, &zero, d, &dSz, p, &pSz, q, &qSz);
  16882. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16883. return WC_TEST_RET_ENC_EC(ret);
  16884. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  16885. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz);
  16886. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16887. return WC_TEST_RET_ENC_EC(ret);
  16888. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, q, &qSz);
  16889. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16890. return WC_TEST_RET_ENC_EC(ret);
  16891. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &zero);
  16892. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16893. return WC_TEST_RET_ENC_EC(ret);
  16894. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  16895. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16896. if (ret != 0)
  16897. return WC_TEST_RET_ENC_EC(ret);
  16898. return 0;
  16899. }
  16900. #endif /* !HAVE_FIPS && !NO_ASN && !WOLFSSL_RSA_VERIFY_ONLY */
  16901. #ifndef NO_SIG_WRAPPER
  16902. static wc_test_ret_t rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
  16903. {
  16904. wc_test_ret_t ret;
  16905. word32 sigSz;
  16906. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  16907. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  16908. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  16909. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  16910. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  16911. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  16912. };
  16913. WOLFSSL_SMALL_STACK_STATIC const byte hashEnc[] = {
  16914. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  16915. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  16916. 0x00, 0x04, 0x20,
  16917. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  16918. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  16919. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  16920. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  16921. };
  16922. word32 inLen = (word32)XSTRLEN((char*)in);
  16923. byte out[RSA_TEST_BYTES];
  16924. /* Parameter Validation testing. */
  16925. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen);
  16926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16927. return WC_TEST_RET_ENC_EC(ret);
  16928. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0);
  16929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16930. return WC_TEST_RET_ENC_EC(ret);
  16931. sigSz = (word32)modLen;
  16932. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  16933. inLen, out, &sigSz, key, keyLen, rng);
  16934. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16935. return WC_TEST_RET_ENC_EC(ret);
  16936. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16937. 0, out, &sigSz, key, keyLen, rng);
  16938. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16939. return WC_TEST_RET_ENC_EC(ret);
  16940. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16941. inLen, NULL, &sigSz, key, keyLen, rng);
  16942. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16943. return WC_TEST_RET_ENC_EC(ret);
  16944. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16945. inLen, out, NULL, key, keyLen, rng);
  16946. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16947. return WC_TEST_RET_ENC_EC(ret);
  16948. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16949. inLen, out, &sigSz, NULL, keyLen, rng);
  16950. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16951. return WC_TEST_RET_ENC_EC(ret);
  16952. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16953. inLen, out, &sigSz, key, 0, rng);
  16954. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16955. return WC_TEST_RET_ENC_EC(ret);
  16956. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16957. inLen, out, &sigSz, key, keyLen, NULL);
  16958. #if defined(WOLFSSL_AFALG_XILINX_RSA) || defined(WOLFSSL_XILINX_CRYPT)
  16959. /* blinding / rng handled with hardware acceleration */
  16960. if (ret != 0)
  16961. #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
  16962. /* async may not require RNG */
  16963. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  16964. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID))
  16965. #else
  16966. if (ret != 0 && ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  16967. #endif
  16968. #elif defined(HAVE_FIPS) || !defined(WC_RSA_BLINDING)
  16969. /* FIPS140 implementation does not do blinding */
  16970. if (ret != 0)
  16971. #elif defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
  16972. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  16973. #elif defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050)
  16974. /* RNG is handled by hardware */
  16975. if (ret != 0)
  16976. #else
  16977. if (ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  16978. #endif
  16979. return WC_TEST_RET_ENC_EC(ret);
  16980. sigSz = 0;
  16981. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16982. inLen, out, &sigSz, key, keyLen, rng);
  16983. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16984. return WC_TEST_RET_ENC_EC(ret);
  16985. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  16986. inLen, out, (word32)modLen, key, keyLen);
  16987. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16988. return WC_TEST_RET_ENC_EC(ret);
  16989. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16990. 0, out, (word32)modLen, key, keyLen);
  16991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16992. return WC_TEST_RET_ENC_EC(ret);
  16993. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16994. inLen, NULL, (word32)modLen, key, keyLen);
  16995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16996. return WC_TEST_RET_ENC_EC(ret);
  16997. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16998. inLen, out, 0, key, keyLen);
  16999. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17000. return WC_TEST_RET_ENC_EC(ret);
  17001. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17002. inLen, out, (word32)modLen, NULL, keyLen);
  17003. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17004. return WC_TEST_RET_ENC_EC(ret);
  17005. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17006. inLen, out, (word32)modLen, key, 0);
  17007. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17008. return WC_TEST_RET_ENC_EC(ret);
  17009. #ifndef HAVE_ECC
  17010. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen);
  17011. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17012. return WC_TEST_RET_ENC_EC(ret);
  17013. #endif
  17014. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17015. return 0;
  17016. #endif
  17017. /* Use APIs. */
  17018. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen);
  17019. if (ret != modLen)
  17020. return WC_TEST_RET_ENC_EC(ret);
  17021. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen);
  17022. if (ret != modLen)
  17023. return WC_TEST_RET_ENC_EC(ret);
  17024. sigSz = (word32)ret;
  17025. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  17026. XMEMSET(out, 0, sizeof(out));
  17027. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17028. inLen, out, &sigSz, key, keyLen, rng);
  17029. if (ret != 0)
  17030. return WC_TEST_RET_ENC_EC(ret);
  17031. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17032. inLen, out, (word32)modLen, key, keyLen);
  17033. if (ret != 0)
  17034. return WC_TEST_RET_ENC_EC(ret);
  17035. sigSz = (word32)sizeof(out);
  17036. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17037. in, inLen, out, &sigSz, key, keyLen, rng);
  17038. if (ret != 0)
  17039. return WC_TEST_RET_ENC_EC(ret);
  17040. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17041. in, inLen, out, (word32)modLen, key, keyLen);
  17042. if (ret != 0)
  17043. return WC_TEST_RET_ENC_EC(ret);
  17044. /* Wrong signature type. */
  17045. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17046. inLen, out, (word32)modLen, key, keyLen);
  17047. if (ret == 0)
  17048. return WC_TEST_RET_ENC_EC(ret);
  17049. /* check hash functions */
  17050. sigSz = (word32)sizeof(out);
  17051. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17052. hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng);
  17053. if (ret != 0)
  17054. return WC_TEST_RET_ENC_EC(ret);
  17055. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17056. hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen);
  17057. if (ret != 0)
  17058. return WC_TEST_RET_ENC_EC(ret);
  17059. sigSz = (word32)sizeof(out);
  17060. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17061. hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng);
  17062. if (ret != 0)
  17063. return WC_TEST_RET_ENC_EC(ret);
  17064. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17065. hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen);
  17066. if (ret != 0)
  17067. return WC_TEST_RET_ENC_EC(ret);
  17068. #else
  17069. (void)hash;
  17070. (void)hashEnc;
  17071. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  17072. return 0;
  17073. }
  17074. #endif /* !NO_SIG_WRAPPER */
  17075. #ifdef WC_RSA_NONBLOCK
  17076. static wc_test_ret_t rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out,
  17077. word32 outSz, byte* plain, word32 plainSz, WC_RNG* rng)
  17078. {
  17079. wc_test_ret_t ret = 0;
  17080. int count;
  17081. int signSz = 0;
  17082. RsaNb nb;
  17083. byte* inlinePlain = NULL;
  17084. /* Enable non-blocking RSA mode - provide context */
  17085. ret = wc_RsaSetNonBlock(key, &nb);
  17086. if (ret != 0)
  17087. return ret;
  17088. #ifdef WC_RSA_NONBLOCK_TIME
  17089. /* Enable time based RSA blocking. 8 microseconds max (3.1GHz) */
  17090. ret = wc_RsaSetNonBlockTime(key, 8, 3100);
  17091. if (ret != 0)
  17092. return ret;
  17093. #endif
  17094. count = 0;
  17095. do {
  17096. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, rng);
  17097. count++; /* track number of would blocks */
  17098. if (ret == FP_WOULDBLOCK) {
  17099. /* do "other" work here */
  17100. }
  17101. } while (ret == FP_WOULDBLOCK);
  17102. if (ret < 0) {
  17103. return ret;
  17104. }
  17105. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17106. printf("RSA non-block sign: %d times\n", count);
  17107. #endif
  17108. signSz = ret;
  17109. /* Test non-blocking verify */
  17110. XMEMSET(plain, 0, plainSz);
  17111. count = 0;
  17112. do {
  17113. ret = wc_RsaSSL_Verify(out, (word32)signSz, plain, plainSz, key);
  17114. count++; /* track number of would blocks */
  17115. if (ret == FP_WOULDBLOCK) {
  17116. /* do "other" work here */
  17117. }
  17118. } while (ret == FP_WOULDBLOCK);
  17119. if (ret < 0) {
  17120. return ret;
  17121. }
  17122. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17123. printf("RSA non-block verify: %d times\n", count);
  17124. #endif
  17125. if (signSz == ret && XMEMCMP(plain, in, (size_t)ret)) {
  17126. return SIG_VERIFY_E;
  17127. }
  17128. /* Test inline non-blocking verify */
  17129. count = 0;
  17130. do {
  17131. ret = wc_RsaSSL_VerifyInline(out, (word32)signSz, &inlinePlain, key);
  17132. count++; /* track number of would blocks */
  17133. if (ret == FP_WOULDBLOCK) {
  17134. /* do "other" work here */
  17135. }
  17136. } while (ret == FP_WOULDBLOCK);
  17137. if (ret < 0) {
  17138. return ret;
  17139. }
  17140. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17141. printf("RSA non-block inline verify: %d times\n", count);
  17142. #endif
  17143. if (signSz == ret && XMEMCMP(inlinePlain, in, (size_t)ret)) {
  17144. return SIG_VERIFY_E;
  17145. }
  17146. /* Disabling non-block RSA mode */
  17147. ret = wc_RsaSetNonBlock(key, NULL);
  17148. (void)count;
  17149. return 0;
  17150. }
  17151. #endif
  17152. #if !defined(NO_ASN)
  17153. static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
  17154. {
  17155. wc_test_ret_t ret;
  17156. word32 inSz;
  17157. word32 inOutIdx;
  17158. WOLFSSL_SMALL_STACK_STATIC const byte n[2] = { 0x00, 0x23 };
  17159. WOLFSSL_SMALL_STACK_STATIC const byte e[2] = { 0x00, 0x03 };
  17160. WOLFSSL_SMALL_STACK_STATIC const byte good[] = { 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1,
  17161. 0x03 };
  17162. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgId[] = {
  17163. 0x30, 0x18, 0x30, 0x16,
  17164. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17165. 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17166. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgIdNull[] = {
  17167. 0x30, 0x1a, 0x30, 0x18,
  17168. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17169. 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17170. 0x02, 0x1, 0x03 };
  17171. WOLFSSL_SMALL_STACK_STATIC const byte badAlgIdNull[] = {
  17172. 0x30, 0x1b, 0x30, 0x19,
  17173. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17174. 0x05, 0x01, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17175. 0x02, 0x1, 0x03 };
  17176. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitString[] = {
  17177. 0x30, 0x18, 0x30, 0x16,
  17178. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17179. 0x04, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17180. WOLFSSL_SMALL_STACK_STATIC const byte badBitStringLen[] = {
  17181. 0x30, 0x18, 0x30, 0x16,
  17182. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17183. 0x03, 0x0a, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17184. WOLFSSL_SMALL_STACK_STATIC const byte badNoSeq[] = {
  17185. 0x30, 0x16, 0x30, 0x14,
  17186. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17187. 0x07, 0x00, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17188. WOLFSSL_SMALL_STACK_STATIC const byte badNoObj[] = {
  17189. 0x30, 0x0f, 0x30, 0x0d, 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06,
  17190. 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17191. WOLFSSL_SMALL_STACK_STATIC const byte badIntN[] = {
  17192. 0x30, 0x06, 0x02, 0x05, 0x23, 0x02, 0x1, 0x03 };
  17193. WOLFSSL_SMALL_STACK_STATIC const byte badNotIntE[] = {
  17194. 0x30, 0x06, 0x02, 0x01, 0x23, 0x04, 0x1, 0x03 };
  17195. WOLFSSL_SMALL_STACK_STATIC const byte badLength[] = {
  17196. 0x30, 0x04, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17197. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrNoZero[] = {
  17198. 0x30, 0x17, 0x30, 0x15,
  17199. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17200. 0x03, 0x08, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17201. ret = wc_InitRsaKey(keyPub, NULL);
  17202. if (ret != 0)
  17203. return WC_TEST_RET_ENC_EC(ret);
  17204. /* Parameter Validation testing. */
  17205. ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, sizeof(e), keyPub);
  17206. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17207. ret = WC_TEST_RET_ENC_EC(ret);
  17208. goto done;
  17209. }
  17210. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), NULL, sizeof(e), keyPub);
  17211. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17212. ret = WC_TEST_RET_ENC_EC(ret);
  17213. goto done;
  17214. }
  17215. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), NULL);
  17216. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17217. ret = WC_TEST_RET_ENC_EC(ret);
  17218. goto done;
  17219. }
  17220. ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
  17221. #if defined(USE_INTEGER_HEAP_MATH)
  17222. if (ret != 0)
  17223. #else
  17224. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17225. #endif
  17226. {
  17227. ret = WC_TEST_RET_ENC_EC(ret);
  17228. goto done;
  17229. }
  17230. wc_FreeRsaKey(keyPub);
  17231. ret = wc_InitRsaKey(keyPub, NULL);
  17232. if (ret != 0)
  17233. return WC_TEST_RET_ENC_EC(ret);
  17234. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
  17235. #if defined(USE_INTEGER_HEAP_MATH)
  17236. if (ret != 0)
  17237. #else
  17238. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17239. #endif
  17240. {
  17241. ret = WC_TEST_RET_ENC_EC(ret);
  17242. goto done;
  17243. }
  17244. wc_FreeRsaKey(keyPub);
  17245. ret = wc_InitRsaKey(keyPub, NULL);
  17246. if (ret != 0)
  17247. return WC_TEST_RET_ENC_EC(ret);
  17248. /* Use API. */
  17249. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub);
  17250. if (ret != 0) {
  17251. ret = WC_TEST_RET_ENC_EC(ret);
  17252. goto done;
  17253. }
  17254. wc_FreeRsaKey(keyPub);
  17255. ret = wc_InitRsaKey(keyPub, NULL);
  17256. if (ret != 0)
  17257. return WC_TEST_RET_ENC_EC(ret);
  17258. /* Parameter Validation testing. */
  17259. inSz = sizeof(good);
  17260. ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, keyPub, inSz);
  17261. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17262. ret = WC_TEST_RET_ENC_EC(ret);
  17263. goto done;
  17264. }
  17265. ret = wc_RsaPublicKeyDecode(good, NULL, keyPub, inSz);
  17266. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17267. ret = WC_TEST_RET_ENC_EC(ret);
  17268. goto done;
  17269. }
  17270. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  17271. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17272. ret = WC_TEST_RET_ENC_EC(ret);
  17273. goto done;
  17274. }
  17275. /* Use good data and offset to bad data. */
  17276. inOutIdx = 2;
  17277. inSz = sizeof(good) - inOutIdx;
  17278. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17279. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17280. ret = WC_TEST_RET_ENC_EC(ret);
  17281. goto done;
  17282. }
  17283. inOutIdx = 2;
  17284. inSz = sizeof(goodAlgId) - inOutIdx;
  17285. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17286. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17287. ret = WC_TEST_RET_ENC_EC(ret);
  17288. goto done;
  17289. }
  17290. inOutIdx = 2;
  17291. inSz = sizeof(goodAlgId);
  17292. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17293. #ifndef WOLFSSL_NO_DECODE_EXTRA
  17294. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17295. #else
  17296. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E))
  17297. #endif
  17298. {
  17299. ret = WC_TEST_RET_ENC_EC(ret);
  17300. goto done;
  17301. }
  17302. /* Try different bad data. */
  17303. inSz = sizeof(badAlgIdNull);
  17304. inOutIdx = 0;
  17305. ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz);
  17306. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E)) {
  17307. ret = WC_TEST_RET_ENC_EC(ret);
  17308. goto done;
  17309. }
  17310. inSz = sizeof(badNotBitString);
  17311. inOutIdx = 0;
  17312. ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz);
  17313. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E)) {
  17314. ret = WC_TEST_RET_ENC_EC(ret);
  17315. goto done;
  17316. }
  17317. inSz = sizeof(badBitStringLen);
  17318. inOutIdx = 0;
  17319. ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz);
  17320. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17321. ret = WC_TEST_RET_ENC_EC(ret);
  17322. goto done;
  17323. }
  17324. inSz = sizeof(badNoSeq);
  17325. inOutIdx = 0;
  17326. ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz);
  17327. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17328. ret = WC_TEST_RET_ENC_EC(ret);
  17329. goto done;
  17330. }
  17331. inSz = sizeof(badNoObj);
  17332. inOutIdx = 0;
  17333. ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz);
  17334. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E) &&
  17335. ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E))
  17336. {
  17337. ret = WC_TEST_RET_ENC_EC(ret);
  17338. goto done;
  17339. }
  17340. inSz = sizeof(badIntN);
  17341. inOutIdx = 0;
  17342. ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz);
  17343. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17344. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17345. {
  17346. ret = WC_TEST_RET_ENC_EC(ret);
  17347. goto done;
  17348. }
  17349. inSz = sizeof(badNotIntE);
  17350. inOutIdx = 0;
  17351. ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz);
  17352. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17353. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17354. {
  17355. ret = WC_TEST_RET_ENC_EC(ret);
  17356. goto done;
  17357. }
  17358. /* TODO: Shouldn't pass as the sequence length is too small. */
  17359. inSz = sizeof(badLength);
  17360. inOutIdx = 0;
  17361. ret = wc_RsaPublicKeyDecode(badLength, &inOutIdx, keyPub, inSz);
  17362. #ifndef WOLFSSL_ASN_TEMPLATE
  17363. if (ret != 0)
  17364. #else
  17365. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17366. #endif
  17367. {
  17368. ret = WC_TEST_RET_ENC_EC(ret);
  17369. goto done;
  17370. }
  17371. /* TODO: Shouldn't ignore object id's data. */
  17372. wc_FreeRsaKey(keyPub);
  17373. ret = wc_InitRsaKey(keyPub, NULL);
  17374. if (ret != 0)
  17375. return WC_TEST_RET_ENC_EC(ret);
  17376. inSz = sizeof(badBitStrNoZero);
  17377. inOutIdx = 0;
  17378. ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz);
  17379. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  17380. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17381. {
  17382. ret = WC_TEST_RET_ENC_EC(ret);
  17383. goto done;
  17384. }
  17385. wc_FreeRsaKey(keyPub);
  17386. ret = wc_InitRsaKey(keyPub, NULL);
  17387. if (ret != 0)
  17388. return WC_TEST_RET_ENC_EC(ret);
  17389. /* Valid data cases. */
  17390. inSz = sizeof(good);
  17391. inOutIdx = 0;
  17392. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17393. if (ret != 0) {
  17394. ret = WC_TEST_RET_ENC_EC(ret);
  17395. goto done;
  17396. }
  17397. if (inOutIdx != inSz) {
  17398. ret = WC_TEST_RET_ENC_NC;
  17399. goto done;
  17400. }
  17401. wc_FreeRsaKey(keyPub);
  17402. ret = wc_InitRsaKey(keyPub, NULL);
  17403. if (ret != 0)
  17404. return WC_TEST_RET_ENC_EC(ret);
  17405. inSz = sizeof(goodAlgId);
  17406. inOutIdx = 0;
  17407. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17408. if (ret != 0) {
  17409. ret = WC_TEST_RET_ENC_EC(ret);
  17410. goto done;
  17411. }
  17412. if (inOutIdx != inSz) {
  17413. ret = WC_TEST_RET_ENC_NC;
  17414. goto done;
  17415. }
  17416. wc_FreeRsaKey(keyPub);
  17417. ret = wc_InitRsaKey(keyPub, NULL);
  17418. if (ret != 0)
  17419. return WC_TEST_RET_ENC_EC(ret);
  17420. inSz = sizeof(goodAlgIdNull);
  17421. inOutIdx = 0;
  17422. ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz);
  17423. if (ret != 0) {
  17424. ret = WC_TEST_RET_ENC_EC(ret);
  17425. goto done;
  17426. }
  17427. if (inOutIdx != inSz) {
  17428. ret = WC_TEST_RET_ENC_NC;
  17429. goto done;
  17430. }
  17431. done:
  17432. wc_FreeRsaKey(keyPub);
  17433. return ret;
  17434. }
  17435. #endif
  17436. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  17437. /* Need to create known good signatures to test with this. */
  17438. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  17439. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17440. static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key)
  17441. {
  17442. byte digest[WC_MAX_DIGEST_SIZE];
  17443. wc_test_ret_t ret = 0;
  17444. const char inStr[] = TEST_STRING;
  17445. word32 inLen = (word32)TEST_STRING_SZ;
  17446. word32 outSz;
  17447. word32 plainSz;
  17448. word32 digestSz;
  17449. int i, j;
  17450. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17451. int k, l;
  17452. #endif
  17453. #ifndef WOLFSSL_SE050
  17454. int len;
  17455. #endif
  17456. byte* plain;
  17457. int mgf[] = {
  17458. #ifndef NO_SHA
  17459. WC_MGF1SHA1,
  17460. #endif
  17461. #ifdef WOLFSSL_SHA224
  17462. WC_MGF1SHA224,
  17463. #endif
  17464. WC_MGF1SHA256,
  17465. #ifdef WOLFSSL_SHA384
  17466. WC_MGF1SHA384,
  17467. #endif
  17468. #ifdef WOLFSSL_SHA512
  17469. WC_MGF1SHA512
  17470. #endif
  17471. };
  17472. enum wc_HashType hash[] = {
  17473. #ifndef NO_SHA
  17474. WC_HASH_TYPE_SHA,
  17475. #endif
  17476. #ifdef WOLFSSL_SHA224
  17477. WC_HASH_TYPE_SHA224,
  17478. #endif
  17479. WC_HASH_TYPE_SHA256,
  17480. #ifdef WOLFSSL_SHA384
  17481. WC_HASH_TYPE_SHA384,
  17482. #endif
  17483. #ifdef WOLFSSL_SHA512
  17484. WC_HASH_TYPE_SHA512,
  17485. #endif
  17486. };
  17487. WC_DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17488. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17489. WC_DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17490. WC_ALLOC_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17491. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17492. WC_ALLOC_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17493. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17494. if (in == NULL || out == NULL || sig == NULL)
  17495. ERROR_OUT(MEMORY_E, exit_rsa_pss);
  17496. #endif
  17497. XMEMCPY(in, inStr, inLen);
  17498. /* Test all combinations of hash and MGF. */
  17499. for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) {
  17500. /* Calculate hash of message. */
  17501. ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest));
  17502. if (ret != 0)
  17503. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17504. digestSz = (word32)wc_HashGetDigestSize(hash[j]);
  17505. #ifdef WOLFSSL_SE050
  17506. /* SE050 only supports MGF matched to same hash type */
  17507. i = j;
  17508. #else
  17509. for (i = 0; i < (int)(sizeof(mgf)/sizeof(*mgf)); i++) {
  17510. #endif
  17511. outSz = RSA_TEST_BYTES;
  17512. do {
  17513. #if defined(WOLFSSL_ASYNC_CRYPT)
  17514. ret = wc_AsyncWait(ret, &key->asyncDev,
  17515. WC_ASYNC_FLAG_CALL_AGAIN);
  17516. #endif
  17517. if (ret >= 0) {
  17518. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz,
  17519. hash[j], mgf[i], -1, key, rng);
  17520. }
  17521. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17522. if (ret <= 0)
  17523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17524. outSz = (word32)ret;
  17525. XMEMCPY(sig, out, outSz);
  17526. plain = NULL;
  17527. TEST_SLEEP();
  17528. do {
  17529. #if defined(WOLFSSL_ASYNC_CRYPT)
  17530. ret = wc_AsyncWait(ret, &key->asyncDev,
  17531. WC_ASYNC_FLAG_CALL_AGAIN);
  17532. #endif
  17533. if (ret >= 0) {
  17534. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[j],
  17535. mgf[i], -1, key);
  17536. }
  17537. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17538. if (ret <= 0)
  17539. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17540. plainSz = (word32)ret;
  17541. TEST_SLEEP();
  17542. #if defined(HAVE_SELFTEST) && \
  17543. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17544. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17545. hash[j], -1);
  17546. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17547. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17548. hash[j], -1, 0);
  17549. #else
  17550. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz,
  17551. hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT);
  17552. #endif
  17553. if (ret != 0)
  17554. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17555. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17556. for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) {
  17557. for (l = 0; l < (int)(sizeof(hash)/sizeof(*hash)); l++) {
  17558. if (i == k && j == l)
  17559. continue;
  17560. XMEMCPY(sig, out, outSz);
  17561. do {
  17562. #if defined(WOLFSSL_ASYNC_CRYPT)
  17563. ret = wc_AsyncWait(ret, &key->asyncDev,
  17564. WC_ASYNC_FLAG_CALL_AGAIN);
  17565. #endif
  17566. if (ret >= 0) {
  17567. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz,
  17568. (byte**)&plain, hash[l], mgf[k], -1, key);
  17569. }
  17570. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17571. if (ret >= 0)
  17572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17573. }
  17574. }
  17575. #endif
  17576. #ifndef WOLFSSL_SE050
  17577. } /* end mgf for loop */
  17578. #endif
  17579. }
  17580. /* SE050 generates salts internally only of hash length */
  17581. #ifndef WOLFSSL_SE050
  17582. /* Test that a salt length of zero works. */
  17583. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17584. outSz = RSA_TEST_BYTES;
  17585. do {
  17586. #if defined(WOLFSSL_ASYNC_CRYPT)
  17587. ret = wc_AsyncWait(ret, &key->asyncDev,
  17588. WC_ASYNC_FLAG_CALL_AGAIN);
  17589. #endif
  17590. if (ret >= 0) {
  17591. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17592. mgf[0], 0, key, rng);
  17593. }
  17594. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17595. if (ret <= 0)
  17596. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17597. outSz = (word32)ret;
  17598. TEST_SLEEP();
  17599. do {
  17600. #if defined(WOLFSSL_ASYNC_CRYPT)
  17601. ret = wc_AsyncWait(ret, &key->asyncDev,
  17602. WC_ASYNC_FLAG_CALL_AGAIN);
  17603. #endif
  17604. if (ret >= 0) {
  17605. ret = wc_RsaPSS_Verify_ex(out, outSz, sig, outSz, hash[0], mgf[0],
  17606. 0, key);
  17607. }
  17608. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17609. if (ret <= 0)
  17610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17611. plainSz = (word32)ret;
  17612. TEST_SLEEP();
  17613. do {
  17614. #if defined(WOLFSSL_ASYNC_CRYPT)
  17615. ret = wc_AsyncWait(ret, &key->asyncDev,
  17616. WC_ASYNC_FLAG_CALL_AGAIN);
  17617. #endif
  17618. if (ret >= 0) {
  17619. #if defined(HAVE_SELFTEST) && \
  17620. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17621. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17622. hash[0], 0);
  17623. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17624. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17625. hash[0], 0, 0);
  17626. #else
  17627. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, sig, plainSz,
  17628. hash[0], 0, 0, HEAP_HINT);
  17629. #endif
  17630. }
  17631. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17632. if (ret != 0)
  17633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17634. XMEMCPY(sig, out, outSz);
  17635. plain = NULL;
  17636. do {
  17637. #if defined(WOLFSSL_ASYNC_CRYPT)
  17638. ret = wc_AsyncWait(ret, &key->asyncDev,
  17639. WC_ASYNC_FLAG_CALL_AGAIN);
  17640. #endif
  17641. if (ret >= 0) {
  17642. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17643. 0, key);
  17644. }
  17645. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17646. if (ret <= 0)
  17647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17648. plainSz = (word32)ret;
  17649. TEST_SLEEP();
  17650. #if defined(HAVE_SELFTEST) && \
  17651. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17652. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17653. hash[0], 0);
  17654. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17655. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17656. hash[0], 0, 0);
  17657. #else
  17658. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17659. 0, 0, HEAP_HINT);
  17660. #endif
  17661. if (ret != 0)
  17662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17663. /* Test bad salt lengths in various APIs. */
  17664. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17665. outSz = RSA_TEST_BYTES;
  17666. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17667. len = -2;
  17668. #else
  17669. len = -3;
  17670. #endif
  17671. do {
  17672. #if defined(WOLFSSL_ASYNC_CRYPT)
  17673. ret = wc_AsyncWait(ret, &key->asyncDev,
  17674. WC_ASYNC_FLAG_CALL_AGAIN);
  17675. #endif
  17676. if (ret >= 0) {
  17677. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17678. mgf[0], len, key, rng);
  17679. }
  17680. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17681. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17683. do {
  17684. #if defined(WOLFSSL_ASYNC_CRYPT)
  17685. ret = wc_AsyncWait(ret, &key->asyncDev,
  17686. WC_ASYNC_FLAG_CALL_AGAIN);
  17687. #endif
  17688. if (ret >= 0) {
  17689. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17690. mgf[0], digestSz + 1, key, rng);
  17691. }
  17692. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17693. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17694. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17695. TEST_SLEEP();
  17696. do {
  17697. #if defined(WOLFSSL_ASYNC_CRYPT)
  17698. ret = wc_AsyncWait(ret, &key->asyncDev,
  17699. WC_ASYNC_FLAG_CALL_AGAIN);
  17700. #endif
  17701. if (ret >= 0) {
  17702. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0],
  17703. mgf[0], -2, key);
  17704. }
  17705. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17706. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17708. TEST_SLEEP();
  17709. do {
  17710. #if defined(WOLFSSL_ASYNC_CRYPT)
  17711. ret = wc_AsyncWait(ret, &key->asyncDev,
  17712. WC_ASYNC_FLAG_CALL_AGAIN);
  17713. #endif
  17714. if (ret >= 0) {
  17715. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17716. digestSz + 1, key);
  17717. }
  17718. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17719. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17721. TEST_SLEEP();
  17722. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17723. len = -2;
  17724. #else
  17725. len = -3;
  17726. #endif
  17727. #if defined(HAVE_SELFTEST) && \
  17728. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17729. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17730. hash[0], len);
  17731. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17732. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17733. hash[0], len, 0);
  17734. #else
  17735. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17736. len, 0, HEAP_HINT);
  17737. #endif
  17738. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17739. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17740. #ifndef WOLFSSL_PSS_LONG_SALT
  17741. len = (int)(digestSz + 1);
  17742. #else
  17743. len = (int)(plainSz - digestSz - 1);
  17744. #endif
  17745. #if defined(HAVE_SELFTEST) && \
  17746. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17747. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17748. hash[0], len);
  17749. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17750. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17751. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17752. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17753. hash[0], len, 0);
  17754. if (ret != WC_NO_ERR_TRACE(BAD_PADDING_E))
  17755. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17756. #else
  17757. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17758. len, 0, HEAP_HINT);
  17759. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17760. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17761. #endif
  17762. ret = 0;
  17763. #endif /* WOLFSSL_SE050 */
  17764. exit_rsa_pss:
  17765. WC_FREE_VAR(sig, HEAP_HINT);
  17766. WC_FREE_VAR(in, HEAP_HINT);
  17767. WC_FREE_VAR(out, HEAP_HINT);
  17768. return ret;
  17769. }
  17770. #endif /* !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY */
  17771. #endif
  17772. #ifdef WC_RSA_NO_PADDING
  17773. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
  17774. {
  17775. WC_RNG rng;
  17776. byte* tmp = NULL;
  17777. size_t bytes;
  17778. wc_test_ret_t ret;
  17779. word32 inLen = 0;
  17780. word32 idx = 0;
  17781. word32 outSz = RSA_TEST_BYTES;
  17782. word32 plainSz = RSA_TEST_BYTES;
  17783. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  17784. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  17785. !defined(NO_FILESYSTEM)
  17786. XFILE file;
  17787. #endif
  17788. WC_DECLARE_VAR(key, RsaKey, 1, HEAP_HINT);
  17789. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17790. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17791. WC_ALLOC_VAR(key, RsaKey, 1, HEAP_HINT);
  17792. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17793. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17794. WOLFSSL_ENTER("rsa_no_pad_test");
  17795. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17796. if (key == NULL || out == NULL || plain == NULL)
  17797. ERROR_OUT(MEMORY_E, exit_rsa_nopadding);
  17798. #endif
  17799. /* initialize stack structures */
  17800. XMEMSET(&rng, 0, sizeof(rng));
  17801. XMEMSET(key, 0, sizeof(RsaKey));
  17802. #ifdef USE_CERT_BUFFERS_1024
  17803. bytes = (size_t)sizeof_client_key_der_1024;
  17804. if (bytes < (size_t)sizeof_client_cert_der_1024)
  17805. bytes = (size_t)sizeof_client_cert_der_1024;
  17806. #elif defined(USE_CERT_BUFFERS_2048)
  17807. bytes = (size_t)sizeof_client_key_der_2048;
  17808. if (bytes < (size_t)sizeof_client_cert_der_2048)
  17809. bytes = (size_t)sizeof_client_cert_der_2048;
  17810. #else
  17811. bytes = FOURK_BUF;
  17812. #endif
  17813. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17814. if (tmp == NULL
  17815. #ifdef WOLFSSL_ASYNC_CRYPT
  17816. || out == NULL || plain == NULL
  17817. #endif
  17818. ) {
  17819. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17820. }
  17821. #ifdef USE_CERT_BUFFERS_1024
  17822. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  17823. #elif defined(USE_CERT_BUFFERS_2048)
  17824. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  17825. #elif defined(USE_CERT_BUFFERS_3072)
  17826. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  17827. #elif defined(USE_CERT_BUFFERS_4096)
  17828. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  17829. #elif !defined(NO_FILESYSTEM)
  17830. file = XFOPEN(clientKey, "rb");
  17831. if (!file) {
  17832. err_sys("can't open clientKey, Please run from wolfSSL home dir",
  17833. WC_TEST_RET_ENC_ERRNO);
  17834. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17835. }
  17836. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  17837. XFCLOSE(file);
  17838. if (bytes == 0)
  17839. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17840. #else
  17841. /* No key to use. */
  17842. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17843. #endif /* USE_CERT_BUFFERS */
  17844. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  17845. if (ret != 0) {
  17846. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17847. }
  17848. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  17849. if (ret != 0) {
  17850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17851. }
  17852. /* after loading in key use tmp as the test buffer */
  17853. #ifndef HAVE_FIPS
  17854. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  17855. #else
  17856. ret = wc_InitRng(&rng);
  17857. #endif
  17858. if (ret != 0) {
  17859. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17860. }
  17861. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17862. inLen = (word32)wc_RsaEncryptSize(key);
  17863. outSz = inLen;
  17864. plainSz = inLen;
  17865. XMEMSET(tmp, 7, inLen);
  17866. do {
  17867. #if defined(WOLFSSL_ASYNC_CRYPT)
  17868. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17869. #endif
  17870. if (ret >= 0) {
  17871. ret = wc_RsaDirect(tmp, inLen, out, &outSz, key,
  17872. RSA_PRIVATE_ENCRYPT, &rng);
  17873. }
  17874. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17875. if (ret <= 0) {
  17876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17877. }
  17878. /* encrypted result should not be the same as input */
  17879. if (XMEMCMP(out, tmp, inLen) == 0) {
  17880. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17881. }
  17882. TEST_SLEEP();
  17883. /* decrypt with public key and compare result */
  17884. do {
  17885. #if defined(WOLFSSL_ASYNC_CRYPT)
  17886. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17887. #endif
  17888. if (ret >= 0) {
  17889. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key,
  17890. RSA_PUBLIC_DECRYPT, &rng);
  17891. }
  17892. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17893. if (ret <= 0) {
  17894. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17895. }
  17896. if (XMEMCMP(plain, tmp, inLen) != 0) {
  17897. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17898. }
  17899. TEST_SLEEP();
  17900. #endif
  17901. #ifdef WC_RSA_BLINDING
  17902. ret = wc_RsaSetRNG(NULL, &rng);
  17903. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17905. }
  17906. ret = wc_RsaSetRNG(key, &rng);
  17907. if (ret < 0) {
  17908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17909. }
  17910. #endif
  17911. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  17912. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17913. do {
  17914. #if defined(WOLFSSL_ASYNC_CRYPT)
  17915. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17916. #endif
  17917. if (ret >= 0) {
  17918. ret = wc_RsaPublicEncrypt_ex(tmp, inLen, out, outSz, key, &rng,
  17919. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  17920. }
  17921. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17922. if (ret < 0) {
  17923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17924. }
  17925. TEST_SLEEP();
  17926. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  17927. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  17928. do {
  17929. #if defined(WOLFSSL_ASYNC_CRYPT)
  17930. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17931. #endif
  17932. if (ret >= 0) {
  17933. ret = wc_RsaPrivateDecrypt_ex(out, outSz, plain, plainSz, key,
  17934. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  17935. }
  17936. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17937. if (ret < 0) {
  17938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17939. }
  17940. if (XMEMCMP(plain, tmp, inLen) != 0) {
  17941. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17942. }
  17943. TEST_SLEEP();
  17944. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  17945. /* test some bad arguments */
  17946. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1,
  17947. &rng);
  17948. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17950. }
  17951. ret = wc_RsaDirect(out, outSz, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT,
  17952. &rng);
  17953. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17955. }
  17956. ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT,
  17957. &rng);
  17958. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || plainSz != inLen) {
  17959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17960. }
  17961. ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key,
  17962. RSA_PUBLIC_DECRYPT, &rng);
  17963. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17965. }
  17966. /* if making it to this point of code without hitting an ERROR_OUT then
  17967. * all tests have passed */
  17968. ret = 0;
  17969. exit_rsa_nopadding:
  17970. wc_FreeRsaKey(key);
  17971. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17972. WC_FREE_VAR(key, HEAP_HINT);
  17973. WC_FREE_VAR(out, HEAP_HINT);
  17974. WC_FREE_VAR(plain, HEAP_HINT);
  17975. wc_FreeRng(&rng);
  17976. return ret;
  17977. }
  17978. #endif /* WC_RSA_NO_PADDING */
  17979. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  17980. static wc_test_ret_t rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
  17981. {
  17982. byte* tmp = NULL;
  17983. size_t bytes;
  17984. wc_test_ret_t ret;
  17985. word32 inLen = 0;
  17986. #ifndef NO_ASN
  17987. word32 idx = 0;
  17988. #endif
  17989. word32 outSz = RSA_TEST_BYTES;
  17990. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  17991. word32 plainSz = RSA_TEST_BYTES;
  17992. #endif
  17993. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_3072) && \
  17994. !defined(USE_CERT_BUFFERS_4096) && !defined(NO_FILESYSTEM)
  17995. XFILE file;
  17996. #endif
  17997. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17998. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  17999. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18000. #endif
  18001. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18002. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18003. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18004. #endif
  18005. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18006. if (out == NULL
  18007. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18008. || plain == NULL
  18009. #endif
  18010. ) {
  18011. ERROR_OUT(MEMORY_E, exit_rsa_even_mod);
  18012. }
  18013. #endif
  18014. #if defined(USE_CERT_BUFFERS_2048)
  18015. bytes = (size_t)sizeof_client_key_der_2048;
  18016. if (bytes < (size_t)sizeof_client_cert_der_2048)
  18017. bytes = (size_t)sizeof_client_cert_der_2048;
  18018. #else
  18019. bytes = FOURK_BUF;
  18020. #endif
  18021. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18022. if (tmp == NULL
  18023. #ifdef WOLFSSL_ASYNC_CRYPT
  18024. || out == NULL || plain == NULL
  18025. #endif
  18026. ) {
  18027. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18028. }
  18029. #if defined(USE_CERT_BUFFERS_2048)
  18030. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  18031. #elif defined(USE_CERT_BUFFERS_3072)
  18032. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  18033. #elif defined(USE_CERT_BUFFERS_4096)
  18034. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  18035. #elif !defined(NO_FILESYSTEM)
  18036. file = XFOPEN(clientKey, "rb");
  18037. if (!file) {
  18038. err_sys("can't open ./certs/client-key.der, "
  18039. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  18040. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18041. }
  18042. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  18043. XFCLOSE(file);
  18044. if (bytes == 0)
  18045. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18046. #else
  18047. /* No key to use. */
  18048. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18049. #endif /* USE_CERT_BUFFERS */
  18050. #ifndef NO_ASN
  18051. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  18052. if (ret != 0) {
  18053. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18054. }
  18055. #else
  18056. #ifdef USE_CERT_BUFFERS_2048
  18057. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  18058. if (ret != 0) {
  18059. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18060. }
  18061. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  18062. if (ret != 0) {
  18063. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18064. }
  18065. #ifndef NO_SIG_WRAPPER
  18066. modLen = 2048;
  18067. #endif
  18068. #else
  18069. #error Not supported yet!
  18070. #endif
  18071. #endif
  18072. key->n.dp[0] &= (mp_digit)-2;
  18073. if (ret != 0) {
  18074. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18075. }
  18076. /* after loading in key use tmp as the test buffer */
  18077. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  18078. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM))) && \
  18079. !defined(WOLFSSL_XILINX_CRYPT)
  18080. /* The ARM64_ASM code that was FIPS validated did not return these expected
  18081. * failure codes. These tests cases were added after the assembly was
  18082. * in-lined in the module and validated, these tests will be available in
  18083. * the 140-3 module */
  18084. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18085. inLen = 32;
  18086. outSz = wc_RsaEncryptSize(key);
  18087. XMEMSET(tmp, 7, plainSz);
  18088. ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
  18089. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18090. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18091. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18092. {
  18093. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18094. }
  18095. ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
  18096. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18097. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18098. {
  18099. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18100. }
  18101. #endif
  18102. #ifdef WC_RSA_BLINDING
  18103. ret = wc_RsaSetRNG(key, rng);
  18104. if (ret < 0) {
  18105. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18106. }
  18107. #endif
  18108. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18109. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18110. ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
  18111. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18112. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18113. {
  18114. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18115. }
  18116. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18117. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18118. ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
  18119. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18120. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18121. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18122. {
  18123. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18124. }
  18125. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18126. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  18127. /* if making it to this point of code without hitting an ERROR_OUT then
  18128. * all tests have passed */
  18129. ret = 0;
  18130. exit_rsa_even_mod:
  18131. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18132. WC_FREE_VAR(out, HEAP_HINT);
  18133. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18134. WC_FREE_VAR(plain, HEAP_HINT);
  18135. #endif
  18136. (void)out;
  18137. (void)outSz;
  18138. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18139. (void)plain;
  18140. (void)plainSz;
  18141. #endif
  18142. (void)inLen;
  18143. (void)rng;
  18144. return ret;
  18145. }
  18146. #endif /* WOLFSSL_HAVE_SP_RSA */
  18147. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  18148. static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp)
  18149. {
  18150. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18151. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18152. #ifdef WOLFSSL_TEST_CERT
  18153. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18154. #endif
  18155. #else
  18156. RsaKey caKey[1];
  18157. #ifdef WOLFSSL_TEST_CERT
  18158. DecodedCert decode[1];
  18159. #endif
  18160. #endif
  18161. byte* der = NULL;
  18162. wc_test_ret_t ret;
  18163. Cert* myCert = NULL;
  18164. int certSz;
  18165. size_t bytes3;
  18166. word32 idx3 = 0;
  18167. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  18168. XFILE file3;
  18169. #endif
  18170. #if defined(WOLFSSL_ALT_NAMES) && !defined(NO_ASN_TIME)
  18171. struct tm beforeTime;
  18172. struct tm afterTime;
  18173. #endif
  18174. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  18175. (void)keypub;
  18176. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18177. if (caKey == NULL)
  18178. ERROR_OUT(MEMORY_E, exit_rsa);
  18179. #ifdef WOLFSSL_TEST_CERT
  18180. if (decode == NULL)
  18181. ERROR_OUT(MEMORY_E, exit_rsa);
  18182. #endif
  18183. #endif
  18184. XMEMSET(caKey, 0, sizeof *caKey);
  18185. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18186. if (der == NULL) {
  18187. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18188. }
  18189. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18190. if (myCert == NULL) {
  18191. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18192. }
  18193. /* self signed */
  18194. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18195. if (ret != 0) {
  18196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18197. }
  18198. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18199. XMEMCPY(myCert->serial, mySerial, sizeof(mySerial));
  18200. myCert->serialSz = (int)sizeof(mySerial);
  18201. myCert->isCA = 1;
  18202. #ifndef NO_SHA256
  18203. myCert->sigType = CTC_SHA256wRSA;
  18204. #else
  18205. myCert->sigType = CTC_SHAwRSA;
  18206. #endif
  18207. #ifdef WOLFSSL_CERT_EXT
  18208. /* add Policies */
  18209. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18210. CTC_MAX_CERTPOL_SZ);
  18211. XSTRNCPY(myCert->certPolicies[1], "1.2.840.113549.1.9.16.6.5",
  18212. CTC_MAX_CERTPOL_SZ);
  18213. myCert->certPoliciesNb = 2;
  18214. /* add SKID from the Public Key */
  18215. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL);
  18216. if (ret != 0) {
  18217. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18218. }
  18219. /* add AKID from the Public Key */
  18220. ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL);
  18221. if (ret != 0) {
  18222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18223. }
  18224. /* add Key Usage */
  18225. ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign");
  18226. if (ret != 0) {
  18227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18228. }
  18229. #ifdef WOLFSSL_EKU_OID
  18230. {
  18231. const char unique[] = "2.16.840.1.111111.100.1.10.1";
  18232. ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0,
  18233. HEAP_HINT);
  18234. if (ret != 0) {
  18235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18236. }
  18237. }
  18238. #endif /* WOLFSSL_EKU_OID */
  18239. #endif /* WOLFSSL_CERT_EXT */
  18240. do {
  18241. #if defined(WOLFSSL_ASYNC_CRYPT)
  18242. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18243. #endif
  18244. if (ret >= 0) {
  18245. ret = wc_MakeSelfCert(myCert, der, FOURK_BUF, key, rng);
  18246. }
  18247. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18248. if (ret < 0) {
  18249. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18250. }
  18251. certSz = (int)ret;
  18252. #ifdef WOLFSSL_TEST_CERT
  18253. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18254. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18255. if (ret != 0) {
  18256. FreeDecodedCert(decode);
  18257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18258. }
  18259. FreeDecodedCert(decode);
  18260. #endif
  18261. ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile,
  18262. CERT_TYPE);
  18263. if (ret != 0) {
  18264. goto exit_rsa;
  18265. }
  18266. /* Setup Certificate */
  18267. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18268. if (ret < 0) {
  18269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18270. }
  18271. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  18272. /* Get CA Cert for testing */
  18273. #ifdef USE_CERT_BUFFERS_1024
  18274. XMEMCPY(tmp, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  18275. bytes3 = sizeof_ca_cert_der_1024;
  18276. #elif defined(USE_CERT_BUFFERS_2048)
  18277. XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  18278. bytes3 = sizeof_ca_cert_der_2048;
  18279. #else
  18280. file3 = XFOPEN(rsaCaCertDerFile, "rb");
  18281. if (!file3) {
  18282. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18283. }
  18284. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18285. XFCLOSE(file3);
  18286. if (bytes3 == 0)
  18287. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18288. #endif /* USE_CERT_BUFFERS */
  18289. #if defined(WOLFSSL_ALT_NAMES)
  18290. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \
  18291. !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  18292. ret = wc_SetAltNames(myCert, rsaCaCertFile);
  18293. if (ret != 0)
  18294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18295. #endif
  18296. /* get alt names from der */
  18297. ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3);
  18298. if (ret != 0)
  18299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18300. /* get dates from der */
  18301. ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3);
  18302. if (ret != 0)
  18303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18304. #ifndef NO_ASN_TIME
  18305. ret = wc_GetCertDates(myCert, &beforeTime, &afterTime);
  18306. if (ret < 0)
  18307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18308. #endif
  18309. #endif /* WOLFSSL_ALT_NAMES */
  18310. #endif /* WOLFSSL_ALT_NAMES || HAVE_PKCS7 */
  18311. /* Get CA Key */
  18312. #ifdef USE_CERT_BUFFERS_1024
  18313. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18314. bytes3 = sizeof_ca_key_der_1024;
  18315. #elif defined(USE_CERT_BUFFERS_2048)
  18316. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18317. bytes3 = sizeof_ca_key_der_2048;
  18318. #else
  18319. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18320. if (!file3) {
  18321. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18322. }
  18323. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18324. XFCLOSE(file3);
  18325. if (bytes3 == 0)
  18326. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18327. #endif /* USE_CERT_BUFFERS */
  18328. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18329. if (ret != 0)
  18330. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18331. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18332. if (ret != 0)
  18333. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18334. #ifndef NO_SHA256
  18335. myCert->sigType = CTC_SHA256wRSA;
  18336. #else
  18337. myCert->sigType = CTC_SHAwRSA;
  18338. #endif
  18339. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18340. #ifdef WOLFSSL_CERT_EXT
  18341. /* add Policies */
  18342. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18343. CTC_MAX_CERTPOL_SZ);
  18344. myCert->certPoliciesNb =1;
  18345. /* add SKID from the Public Key */
  18346. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL);
  18347. if (ret != 0)
  18348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18349. /* add AKID from the CA certificate */
  18350. #if defined(USE_CERT_BUFFERS_2048)
  18351. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18352. sizeof_ca_cert_der_2048);
  18353. #elif defined(USE_CERT_BUFFERS_1024)
  18354. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18355. sizeof_ca_cert_der_1024);
  18356. #else
  18357. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18358. #endif
  18359. if (ret != 0)
  18360. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18361. /* add Key Usage */
  18362. ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement");
  18363. if (ret != 0)
  18364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18365. #endif /* WOLFSSL_CERT_EXT */
  18366. #if defined(USE_CERT_BUFFERS_2048)
  18367. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18368. sizeof_ca_cert_der_2048);
  18369. #elif defined(USE_CERT_BUFFERS_1024)
  18370. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18371. sizeof_ca_cert_der_1024);
  18372. #else
  18373. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18374. #endif
  18375. if (ret < 0)
  18376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18377. certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng);
  18378. if (certSz < 0) {
  18379. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18380. }
  18381. ret = 0;
  18382. do {
  18383. #if defined(WOLFSSL_ASYNC_CRYPT)
  18384. ret = wc_AsyncWait(ret, &caKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18385. #endif
  18386. if (ret >= 0) {
  18387. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der, FOURK_BUF,
  18388. caKey, NULL, rng);
  18389. }
  18390. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18391. if (ret < 0)
  18392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18393. certSz = (int)ret;
  18394. #ifdef WOLFSSL_TEST_CERT
  18395. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18396. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18397. if (ret != 0) {
  18398. FreeDecodedCert(decode);
  18399. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18400. }
  18401. FreeDecodedCert(decode);
  18402. #endif
  18403. ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile,
  18404. CERT_TYPE);
  18405. if (ret != 0) {
  18406. goto exit_rsa;
  18407. }
  18408. exit_rsa:
  18409. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18410. if (caKey != NULL) {
  18411. wc_FreeRsaKey(caKey);
  18412. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18413. }
  18414. #ifdef WOLFSSL_TEST_CERT
  18415. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18416. #endif
  18417. #else
  18418. wc_FreeRsaKey(caKey);
  18419. #endif
  18420. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18421. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18422. return ret;
  18423. }
  18424. #endif
  18425. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
  18426. defined(WOLFSSL_CERT_GEN)
  18427. /* Make Cert / Sign example for ECC cert and RSA CA */
  18428. static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
  18429. {
  18430. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18431. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18432. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18433. ecc_key *caEccKeyPub = (ecc_key *)XMALLOC(sizeof *caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18434. #ifdef WOLFSSL_TEST_CERT
  18435. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18436. #endif
  18437. #else
  18438. RsaKey caKey[1];
  18439. ecc_key caEccKey[1];
  18440. ecc_key caEccKeyPub[1];
  18441. #ifdef WOLFSSL_TEST_CERT
  18442. DecodedCert decode[1];
  18443. #endif
  18444. #endif
  18445. byte* der = NULL;
  18446. Cert* myCert = NULL;
  18447. int certSz;
  18448. size_t bytes3;
  18449. word32 idx3 = 0;
  18450. #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
  18451. || !defined(USE_CERT_BUFFERS_256)
  18452. #ifndef NO_FILESYSTEM
  18453. XFILE file3;
  18454. #endif
  18455. #endif
  18456. wc_test_ret_t ret;
  18457. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18458. if ((caKey == NULL) || (caEccKey == NULL) || (caEccKeyPub == NULL)
  18459. #ifdef WOLFSSL_TEST_CERT
  18460. || (decode == NULL)
  18461. #endif
  18462. )
  18463. ERROR_OUT(MEMORY_E, exit_rsa);
  18464. #endif
  18465. XMEMSET(caKey, 0, sizeof *caKey);
  18466. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  18467. XMEMSET(caEccKeyPub, 0, sizeof *caEccKeyPub);
  18468. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18469. if (der == NULL) {
  18470. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18471. }
  18472. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18473. if (myCert == NULL) {
  18474. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18475. }
  18476. /* Get CA Key */
  18477. #ifdef USE_CERT_BUFFERS_1024
  18478. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18479. bytes3 = sizeof_ca_key_der_1024;
  18480. #elif defined(USE_CERT_BUFFERS_2048)
  18481. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18482. bytes3 = sizeof_ca_key_der_2048;
  18483. #else
  18484. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18485. if (!file3) {
  18486. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18487. }
  18488. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18489. XFCLOSE(file3);
  18490. if (bytes3 == 0)
  18491. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18492. #endif /* USE_CERT_BUFFERS */
  18493. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18494. if (ret != 0)
  18495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18496. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18497. if (ret != 0)
  18498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18499. /* Get Cert Key */
  18500. #if defined(USE_CERT_BUFFERS_256)
  18501. {
  18502. XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
  18503. bytes3 = sizeof_ecc_key_pub_der_256;
  18504. }
  18505. #elif !defined(NO_FILESYSTEM)
  18506. {
  18507. file3 = XFOPEN(eccKeyPubFileDer, "rb");
  18508. if (!file3) {
  18509. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18510. }
  18511. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18512. XFCLOSE(file3);
  18513. if (bytes3 == 0)
  18514. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18515. }
  18516. #else
  18517. {
  18518. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
  18519. ERROR_OUT(ASN_PARSE_E, exit_rsa);
  18520. }
  18521. #endif
  18522. ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
  18523. if (ret != 0)
  18524. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18525. idx3 = 0;
  18526. ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3);
  18527. if (ret != 0)
  18528. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18529. /* Setup Certificate */
  18530. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18531. if (ret != 0)
  18532. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18533. #ifndef NO_SHA256
  18534. myCert->sigType = CTC_SHA256wRSA;
  18535. #else
  18536. myCert->sigType = CTC_SHAwRSA;
  18537. #endif
  18538. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18539. #ifdef WOLFSSL_CERT_EXT
  18540. /* add Policies */
  18541. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  18542. CTC_MAX_CERTPOL_SZ);
  18543. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  18544. CTC_MAX_CERTPOL_SZ);
  18545. myCert->certPoliciesNb = 2;
  18546. /* add SKID from the Public Key */
  18547. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub);
  18548. if (ret != 0)
  18549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18550. /* add AKID from the CA certificate */
  18551. #if defined(USE_CERT_BUFFERS_2048)
  18552. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18553. sizeof_ca_cert_der_2048);
  18554. #elif defined(USE_CERT_BUFFERS_1024)
  18555. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18556. sizeof_ca_cert_der_1024);
  18557. #else
  18558. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18559. #endif
  18560. if (ret != 0)
  18561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18562. /* add Key Usage */
  18563. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  18564. if (ret != 0)
  18565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18566. #endif /* WOLFSSL_CERT_EXT */
  18567. #if defined(USE_CERT_BUFFERS_2048)
  18568. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18569. sizeof_ca_cert_der_2048);
  18570. #elif defined(USE_CERT_BUFFERS_1024)
  18571. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18572. sizeof_ca_cert_der_1024);
  18573. #else
  18574. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18575. #endif
  18576. if (ret < 0)
  18577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18578. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng);
  18579. if (certSz < 0) {
  18580. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18581. }
  18582. ret = 0;
  18583. do {
  18584. #if defined(WOLFSSL_ASYNC_CRYPT)
  18585. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18586. #endif
  18587. if (ret >= 0) {
  18588. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  18589. FOURK_BUF, caKey, NULL, rng);
  18590. }
  18591. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18592. if (ret < 0)
  18593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18594. certSz = (int)ret;
  18595. #ifdef WOLFSSL_TEST_CERT
  18596. InitDecodedCert(decode, der, certSz, 0);
  18597. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18598. if (ret != 0) {
  18599. FreeDecodedCert(decode);
  18600. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18601. }
  18602. FreeDecodedCert(decode);
  18603. #endif
  18604. ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile,
  18605. CERT_TYPE);
  18606. if (ret != 0) {
  18607. goto exit_rsa;
  18608. }
  18609. exit_rsa:
  18610. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18611. if (caKey != NULL) {
  18612. wc_FreeRsaKey(caKey);
  18613. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18614. }
  18615. if (caEccKey != NULL) {
  18616. wc_ecc_free(caEccKey);
  18617. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18618. }
  18619. if (caEccKeyPub != NULL) {
  18620. wc_ecc_free(caEccKeyPub);
  18621. XFREE(caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18622. }
  18623. #ifdef WOLFSSL_TEST_CERT
  18624. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18625. #endif
  18626. #else
  18627. wc_FreeRsaKey(caKey);
  18628. wc_ecc_free(caEccKey);
  18629. wc_ecc_free(caEccKeyPub);
  18630. #endif
  18631. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18632. myCert = NULL;
  18633. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18634. der = NULL;
  18635. if (ret >= 0)
  18636. ret = 0;
  18637. return ret;
  18638. }
  18639. #endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
  18640. #ifdef WOLFSSL_KEY_GEN
  18641. static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
  18642. {
  18643. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18644. RsaKey *genKey = (RsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18645. #else
  18646. RsaKey genKey[1];
  18647. #endif
  18648. wc_test_ret_t ret;
  18649. #ifndef WOLFSSL_NO_MALLOC
  18650. byte* der = NULL;
  18651. #else
  18652. byte der[1280];
  18653. #endif
  18654. #ifndef WOLFSSL_CRYPTOCELL
  18655. word32 idx = 0;
  18656. #endif
  18657. int derSz = 0;
  18658. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FIPS) && \
  18659. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18660. int keySz = 1024;
  18661. #else
  18662. int keySz = 2048;
  18663. #endif
  18664. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18665. if (! genKey)
  18666. ERROR_OUT(MEMORY_E, exit_rsa);
  18667. #endif
  18668. XMEMSET(genKey, 0, sizeof *genKey);
  18669. ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId);
  18670. if (ret != 0)
  18671. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18672. #ifdef HAVE_FIPS
  18673. for (;;) {
  18674. #endif
  18675. ret = wc_MakeRsaKey(genKey, keySz, WC_RSA_EXPONENT, rng);
  18676. #if defined(WOLFSSL_ASYNC_CRYPT)
  18677. ret = wc_AsyncWait(ret, &genKey->asyncDev, WC_ASYNC_FLAG_NONE);
  18678. #endif
  18679. #ifdef HAVE_FIPS
  18680. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  18681. continue;
  18682. break;
  18683. }
  18684. #endif
  18685. if (ret != 0)
  18686. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18687. TEST_SLEEP();
  18688. #ifdef WOLFSSL_RSA_KEY_CHECK
  18689. ret = wc_CheckRsaKey(genKey);
  18690. if (ret != 0)
  18691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18692. #endif
  18693. #ifndef WOLFSSL_NO_MALLOC
  18694. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18695. if (der == NULL) {
  18696. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18697. }
  18698. derSz = FOURK_BUF;
  18699. #else
  18700. derSz = sizeof(der);
  18701. #endif
  18702. derSz = wc_RsaKeyToDer(genKey, der, derSz);
  18703. if (derSz < 0) {
  18704. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  18705. }
  18706. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  18707. PRIVATEKEY_TYPE);
  18708. if (ret != 0) {
  18709. goto exit_rsa;
  18710. }
  18711. wc_FreeRsaKey(genKey);
  18712. ret = wc_InitRsaKey(genKey, HEAP_HINT);
  18713. if (ret != 0)
  18714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18715. #ifndef WOLFSSL_CRYPTOCELL
  18716. idx = 0;
  18717. /* The private key part of the key gen pairs from cryptocell can't be exported */
  18718. ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, (word32)derSz);
  18719. if (ret != 0)
  18720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18721. #endif /* WOLFSSL_CRYPTOCELL */
  18722. exit_rsa:
  18723. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18724. if (genKey) {
  18725. wc_FreeRsaKey(genKey);
  18726. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18727. }
  18728. #else
  18729. wc_FreeRsaKey(genKey);
  18730. #endif
  18731. #ifndef WOLFSSL_NO_MALLOC
  18732. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18733. der = NULL;
  18734. #endif
  18735. return ret;
  18736. }
  18737. #endif
  18738. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18739. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) && \
  18740. (!defined(HAVE_FIPS) || \
  18741. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  18742. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  18743. static wc_test_ret_t rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng)
  18744. {
  18745. wc_test_ret_t ret = 0;
  18746. word32 idx = 0;
  18747. const char inStr[] = TEST_STRING;
  18748. const word32 inLen = (word32)TEST_STRING_SZ;
  18749. const word32 outSz = RSA_TEST_BYTES;
  18750. const word32 plainSz = RSA_TEST_BYTES;
  18751. byte* res = NULL;
  18752. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18753. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18754. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18755. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18756. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18757. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18758. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18759. if (in == NULL || out == NULL || plain == NULL)
  18760. ERROR_OUT(MEMORY_E, exit_rsa);
  18761. #endif
  18762. XMEMCPY(in, inStr, inLen);
  18763. #ifndef NO_SHA
  18764. do {
  18765. #if defined(WOLFSSL_ASYNC_CRYPT)
  18766. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18767. #endif
  18768. if (ret >= 0) {
  18769. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18770. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18771. }
  18772. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18773. if (ret < 0)
  18774. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18775. TEST_SLEEP();
  18776. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18777. idx = (word32)ret;
  18778. do {
  18779. #if defined(WOLFSSL_ASYNC_CRYPT)
  18780. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18781. #endif
  18782. if (ret >= 0) {
  18783. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18784. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18785. }
  18786. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18787. if (ret < 0)
  18788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18789. if (XMEMCMP(plain, in, inLen)) {
  18790. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18791. }
  18792. TEST_SLEEP();
  18793. #endif /* NO_SHA */
  18794. #endif
  18795. #ifndef NO_SHA256
  18796. XMEMSET(plain, 0, plainSz);
  18797. do {
  18798. #if defined(WOLFSSL_ASYNC_CRYPT)
  18799. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18800. #endif
  18801. if (ret >= 0) {
  18802. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18803. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18804. }
  18805. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18806. if (ret < 0)
  18807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18808. TEST_SLEEP();
  18809. idx = (word32)ret;
  18810. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18811. do {
  18812. #if defined(WOLFSSL_ASYNC_CRYPT)
  18813. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18814. #endif
  18815. if (ret >= 0) {
  18816. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18817. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18818. }
  18819. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18820. if (ret < 0)
  18821. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18822. if (XMEMCMP(plain, in, inLen)) {
  18823. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18824. }
  18825. TEST_SLEEP();
  18826. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18827. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18828. do {
  18829. #if defined(WOLFSSL_ASYNC_CRYPT)
  18830. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18831. #endif
  18832. if (ret >= 0) {
  18833. ret = wc_RsaPrivateDecryptInline_ex(out, idx, &res, key,
  18834. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18835. }
  18836. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18837. if (ret < 0)
  18838. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18839. if (ret != (int)inLen) {
  18840. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18841. }
  18842. if (XMEMCMP(res, in, inLen)) {
  18843. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18844. }
  18845. TEST_SLEEP();
  18846. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18847. /* check fails if not using the same optional label */
  18848. XMEMSET(plain, 0, plainSz);
  18849. do {
  18850. #if defined(WOLFSSL_ASYNC_CRYPT)
  18851. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18852. #endif
  18853. if (ret >= 0) {
  18854. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18855. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18856. }
  18857. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18858. if (ret < 0)
  18859. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18860. TEST_SLEEP();
  18861. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18862. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18863. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18864. /* label is unused in cryptocell and SE050 so it won't detect decrypt error
  18865. * due to label */
  18866. idx = (word32)ret;
  18867. do {
  18868. #if defined(WOLFSSL_ASYNC_CRYPT)
  18869. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18870. #endif
  18871. if (ret >= 0) {
  18872. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18873. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18874. }
  18875. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18876. if (ret > 0) { /* in this case decrypt should fail */
  18877. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18878. }
  18879. ret = 0;
  18880. TEST_SLEEP();
  18881. #endif /* !HAVE_CAVIUM */
  18882. /* check using optional label with encrypt/decrypt */
  18883. XMEMSET(plain, 0, plainSz);
  18884. do {
  18885. #if defined(WOLFSSL_ASYNC_CRYPT)
  18886. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18887. #endif
  18888. if (ret >= 0) {
  18889. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18890. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18891. }
  18892. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18893. if (ret < 0)
  18894. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18895. TEST_SLEEP();
  18896. idx = (word32)ret;
  18897. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18898. do {
  18899. #if defined(WOLFSSL_ASYNC_CRYPT)
  18900. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18901. #endif
  18902. if (ret >= 0) {
  18903. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18904. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18905. }
  18906. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18907. if (ret < 0)
  18908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18909. if (XMEMCMP(plain, in, inLen)) {
  18910. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18911. }
  18912. TEST_SLEEP();
  18913. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18914. #ifndef NO_SHA
  18915. /* check fail using mismatch hash algorithms */
  18916. XMEMSET(plain, 0, plainSz);
  18917. do {
  18918. #if defined(WOLFSSL_ASYNC_CRYPT)
  18919. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18920. #endif
  18921. if (ret >= 0) {
  18922. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18923. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen);
  18924. }
  18925. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18926. if (ret < 0)
  18927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18928. TEST_SLEEP();
  18929. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18930. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18931. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18932. idx = (word32)ret;
  18933. do {
  18934. #if defined(WOLFSSL_ASYNC_CRYPT)
  18935. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18936. #endif
  18937. if (ret >= 0) {
  18938. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18939. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256,
  18940. in, inLen);
  18941. }
  18942. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18943. if (ret > 0) { /* should fail */
  18944. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18945. }
  18946. ret = 0;
  18947. TEST_SLEEP();
  18948. #endif /* !HAVE_CAVIUM */
  18949. #endif /* NO_SHA */
  18950. #endif /* NO_SHA256 */
  18951. #ifdef WOLFSSL_SHA512
  18952. /* Check valid RSA key size is used while using hash length of SHA512
  18953. If key size is less than (hash length * 2) + 2 then is invalid use
  18954. and test, since OAEP padding requires this.
  18955. BAD_FUNC_ARG is returned when this case is not met */
  18956. if (wc_RsaEncryptSize(key) > ((int)WC_SHA512_DIGEST_SIZE * 2) + 2) {
  18957. XMEMSET(plain, 0, plainSz);
  18958. do {
  18959. #if defined(WOLFSSL_ASYNC_CRYPT)
  18960. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18961. #endif
  18962. if (ret >= 0) {
  18963. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18964. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  18965. }
  18966. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18967. if (ret < 0)
  18968. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18969. TEST_SLEEP();
  18970. idx = (word32)ret;
  18971. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18972. do {
  18973. #if defined(WOLFSSL_ASYNC_CRYPT)
  18974. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18975. #endif
  18976. if (ret >= 0) {
  18977. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18978. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  18979. }
  18980. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18981. if (ret < 0)
  18982. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18983. if (XMEMCMP(plain, in, inLen)) {
  18984. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18985. }
  18986. TEST_SLEEP();
  18987. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18988. }
  18989. #endif /* WOLFSSL_SHA512 */
  18990. /* check using pkcsv15 padding with _ex API */
  18991. XMEMSET(plain, 0, plainSz);
  18992. do {
  18993. #if defined(WOLFSSL_ASYNC_CRYPT)
  18994. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18995. #endif
  18996. if (ret >= 0) {
  18997. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18998. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  18999. }
  19000. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19001. if (ret < 0)
  19002. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19003. TEST_SLEEP();
  19004. idx = (word32)ret;
  19005. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19006. do {
  19007. #if defined(WOLFSSL_ASYNC_CRYPT)
  19008. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19009. #endif
  19010. if (ret >= 0) {
  19011. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19012. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19013. }
  19014. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19015. if (ret < 0)
  19016. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19017. if (XMEMCMP(plain, in, inLen)) {
  19018. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19019. }
  19020. TEST_SLEEP();
  19021. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19022. exit_rsa:
  19023. WC_FREE_VAR(in, HEAP_HINT);
  19024. WC_FREE_VAR(out, HEAP_HINT);
  19025. WC_FREE_VAR(plain, HEAP_HINT);
  19026. (void)idx;
  19027. (void)inStr;
  19028. (void)res;
  19029. if (ret >= 0)
  19030. ret = 0;
  19031. return ret;
  19032. }
  19033. #endif
  19034. #endif
  19035. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
  19036. {
  19037. wc_test_ret_t ret;
  19038. size_t bytes;
  19039. WC_RNG rng;
  19040. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19041. byte* tmp = NULL;
  19042. byte* der = NULL;
  19043. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19044. #else
  19045. RsaKey key[1];
  19046. byte tmp[FOURK_BUF];
  19047. #endif
  19048. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19049. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19050. RsaKey *keypub = (RsaKey *)XMALLOC(sizeof *keypub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19051. #else
  19052. RsaKey keypub[1];
  19053. #endif
  19054. #endif
  19055. word32 idx = 0;
  19056. const char inStr[] = TEST_STRING;
  19057. const word32 inLen = (word32)TEST_STRING_SZ;
  19058. const word32 outSz = RSA_TEST_BYTES;
  19059. const word32 plainSz = RSA_TEST_BYTES;
  19060. byte* res = NULL;
  19061. #ifndef NO_SIG_WRAPPER
  19062. int modLen;
  19063. #endif
  19064. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19065. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  19066. !defined(NO_FILESYSTEM)
  19067. XFILE file;
  19068. #ifdef WOLFSSL_TEST_CERT
  19069. XFILE file2;
  19070. #endif
  19071. #endif
  19072. #ifdef WOLFSSL_TEST_CERT
  19073. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19074. DecodedCert *cert = (DecodedCert *)XMALLOC(sizeof *cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19075. #else
  19076. DecodedCert cert[1];
  19077. #endif
  19078. #ifndef NO_ASN_TIME
  19079. struct tm timearg;
  19080. const byte* date;
  19081. byte dateFormat;
  19082. int dateLength;
  19083. #endif
  19084. #endif
  19085. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19086. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19087. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19088. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19089. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19090. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19091. WOLFSSL_ENTER("rsa_test");
  19092. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  19093. if (in == NULL || out == NULL || plain == NULL)
  19094. ERROR_OUT(MEMORY_E, exit_rsa);
  19095. #endif
  19096. XMEMCPY(in, inStr, inLen);
  19097. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19098. if (key == NULL)
  19099. ERROR_OUT(MEMORY_E, exit_rsa);
  19100. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19101. if (keypub == NULL)
  19102. ERROR_OUT(MEMORY_E, exit_rsa);
  19103. #endif
  19104. #ifdef WOLFSSL_TEST_CERT
  19105. if (cert == NULL)
  19106. ERROR_OUT(MEMORY_E, exit_rsa);
  19107. #endif
  19108. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19109. /* initialize stack structures */
  19110. XMEMSET(&rng, 0, sizeof(rng));
  19111. XMEMSET(key, 0, sizeof *key);
  19112. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19113. XMEMSET(keypub, 0, sizeof *keypub);
  19114. #endif
  19115. #if !defined(NO_ASN)
  19116. ret = rsa_decode_test(key);
  19117. if (ret != 0)
  19118. ERROR_OUT(ret, exit_rsa);
  19119. #endif
  19120. #ifdef USE_CERT_BUFFERS_1024
  19121. bytes = (size_t)sizeof_client_key_der_1024;
  19122. if (bytes < (size_t)sizeof_client_cert_der_1024)
  19123. bytes = (size_t)sizeof_client_cert_der_1024;
  19124. #elif defined(USE_CERT_BUFFERS_2048)
  19125. bytes = (size_t)sizeof_client_key_der_2048;
  19126. if (bytes < (size_t)sizeof_client_cert_der_2048)
  19127. bytes = (size_t)sizeof_client_cert_der_2048;
  19128. #elif defined(USE_CERT_BUFFERS_3072)
  19129. bytes = (size_t)sizeof_client_key_der_3072;
  19130. if (bytes < (size_t)sizeof_client_cert_der_3072)
  19131. bytes = (size_t)sizeof_client_cert_der_3072;
  19132. #elif defined(USE_CERT_BUFFERS_4096)
  19133. bytes = (size_t)sizeof_client_key_der_4096;
  19134. if (bytes < (size_t)sizeof_client_cert_der_4096)
  19135. bytes = (size_t)sizeof_client_cert_der_4096;
  19136. #else
  19137. bytes = FOURK_BUF;
  19138. #endif
  19139. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19140. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19141. if (tmp == NULL)
  19142. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19143. #endif
  19144. #ifdef USE_CERT_BUFFERS_1024
  19145. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  19146. #elif defined(USE_CERT_BUFFERS_2048)
  19147. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  19148. #elif defined(USE_CERT_BUFFERS_3072)
  19149. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  19150. #elif defined(USE_CERT_BUFFERS_4096)
  19151. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  19152. #elif !defined(NO_FILESYSTEM)
  19153. file = XFOPEN(clientKey, "rb");
  19154. if (!file) {
  19155. err_sys("can't open ./certs/client-key.der, "
  19156. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19157. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19158. }
  19159. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19160. XFCLOSE(file);
  19161. if (bytes == 0)
  19162. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19163. #else
  19164. /* No key to use. */
  19165. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19166. #endif /* USE_CERT_BUFFERS */
  19167. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19168. if (ret != 0)
  19169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19170. #ifndef NO_ASN
  19171. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  19172. if (ret != 0)
  19173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19174. #ifndef NO_SIG_WRAPPER
  19175. modLen = wc_RsaEncryptSize(key);
  19176. #endif
  19177. #else
  19178. #ifdef USE_CERT_BUFFERS_2048
  19179. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  19180. if (ret != 0)
  19181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19182. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  19183. if (ret != 0)
  19184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19185. #ifndef NO_SIG_WRAPPER
  19186. modLen = 2048;
  19187. #endif
  19188. #else
  19189. #error Not supported yet!
  19190. #endif
  19191. #endif
  19192. #ifndef WC_NO_RNG
  19193. #ifndef HAVE_FIPS
  19194. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  19195. #else
  19196. ret = wc_InitRng(&rng);
  19197. #endif
  19198. if (ret != 0)
  19199. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19200. #endif
  19201. #ifndef NO_SIG_WRAPPER
  19202. ret = rsa_sig_test(key, sizeof *key, modLen, &rng);
  19203. if (ret != 0)
  19204. goto exit_rsa;
  19205. #endif
  19206. #ifdef WC_RSA_NONBLOCK
  19207. ret = rsa_nb_test(key, in, inLen, out, outSz, plain, plainSz, &rng);
  19208. if (ret != 0)
  19209. goto exit_rsa;
  19210. #endif
  19211. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19212. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19213. do {
  19214. #if defined(WOLFSSL_ASYNC_CRYPT)
  19215. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19216. #endif
  19217. if (ret >= 0) {
  19218. ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng);
  19219. }
  19220. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19221. if (ret < 0)
  19222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19223. TEST_SLEEP();
  19224. #ifdef WC_RSA_BLINDING
  19225. {
  19226. wc_test_ret_t tmpret = ret;
  19227. ret = wc_RsaSetRNG(key, &rng);
  19228. if (ret < 0)
  19229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19230. ret = tmpret;
  19231. }
  19232. #endif
  19233. idx = (word32)ret; /* save off encrypted length */
  19234. do {
  19235. #if defined(WOLFSSL_ASYNC_CRYPT)
  19236. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19237. #endif
  19238. if (ret >= 0) {
  19239. ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key);
  19240. }
  19241. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19242. if (ret < 0)
  19243. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19244. if (XMEMCMP(plain, in, inLen)) {
  19245. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19246. }
  19247. TEST_SLEEP();
  19248. do {
  19249. #if defined(WOLFSSL_ASYNC_CRYPT)
  19250. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19251. #endif
  19252. if (ret >= 0) {
  19253. ret = wc_RsaPrivateDecryptInline(out, idx, &res, key);
  19254. }
  19255. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19256. if (ret < 0)
  19257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19258. if (ret != (int)inLen) {
  19259. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19260. }
  19261. if (XMEMCMP(res, in, inLen)) {
  19262. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19263. }
  19264. TEST_SLEEP();
  19265. do {
  19266. #if defined(WOLFSSL_ASYNC_CRYPT)
  19267. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19268. #endif
  19269. if (ret >= 0) {
  19270. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
  19271. }
  19272. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19273. if (ret < 0)
  19274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19275. TEST_SLEEP();
  19276. #elif defined(WOLFSSL_PUBLIC_MP)
  19277. {
  19278. static const byte signature_2048[] = {
  19279. 0x07, 0x6f, 0xc9, 0x85, 0x73, 0x9e, 0x21, 0x79,
  19280. 0x47, 0xf1, 0xa3, 0xd7, 0xf4, 0x27, 0x29, 0xbe,
  19281. 0x99, 0x5d, 0xac, 0xb2, 0x10, 0x3f, 0x95, 0xda,
  19282. 0x89, 0x23, 0xb8, 0x96, 0x13, 0x57, 0x72, 0x30,
  19283. 0xa1, 0xfe, 0x5a, 0x68, 0x9c, 0x99, 0x9d, 0x1e,
  19284. 0x05, 0xa4, 0x80, 0xb0, 0xbb, 0xd9, 0xd9, 0xa1,
  19285. 0x69, 0x97, 0x74, 0xb3, 0x41, 0x21, 0x3b, 0x47,
  19286. 0xf5, 0x51, 0xb1, 0xfb, 0xc7, 0xaa, 0xcc, 0xdc,
  19287. 0xcd, 0x76, 0xa0, 0x28, 0x4d, 0x27, 0x14, 0xa4,
  19288. 0xb9, 0x41, 0x68, 0x7c, 0xb3, 0x66, 0xe6, 0x6f,
  19289. 0x40, 0x76, 0xe4, 0x12, 0xfd, 0xae, 0x29, 0xb5,
  19290. 0x63, 0x60, 0x87, 0xce, 0x49, 0x6b, 0xf3, 0x05,
  19291. 0x9a, 0x14, 0xb5, 0xcc, 0xcd, 0xf7, 0x30, 0x95,
  19292. 0xd2, 0x72, 0x52, 0x1d, 0x5b, 0x7e, 0xef, 0x4a,
  19293. 0x02, 0x96, 0x21, 0x6c, 0x55, 0xa5, 0x15, 0xb1,
  19294. 0x57, 0x63, 0x2c, 0xa3, 0x8e, 0x9d, 0x3d, 0x45,
  19295. 0xcc, 0xb8, 0xe6, 0xa1, 0xc8, 0x59, 0xcd, 0xf5,
  19296. 0xdc, 0x0a, 0x51, 0xb6, 0x9d, 0xfb, 0xf4, 0x6b,
  19297. 0xfd, 0x32, 0x71, 0x6e, 0xcf, 0xcb, 0xb3, 0xd9,
  19298. 0xe0, 0x4a, 0x77, 0x34, 0xd6, 0x61, 0xf5, 0x7c,
  19299. 0xf9, 0xa9, 0xa4, 0xb0, 0x8e, 0x3b, 0xd6, 0x04,
  19300. 0xe0, 0xde, 0x2b, 0x5b, 0x5a, 0xbf, 0xd9, 0xef,
  19301. 0x8d, 0xa3, 0xf5, 0xb1, 0x67, 0xf3, 0xb9, 0x72,
  19302. 0x0a, 0x37, 0x12, 0x35, 0x6c, 0x8e, 0x10, 0x8b,
  19303. 0x38, 0x06, 0x16, 0x4b, 0x20, 0x20, 0x13, 0x00,
  19304. 0x2e, 0x6d, 0xc2, 0x59, 0x23, 0x67, 0x4a, 0x6d,
  19305. 0xa1, 0x46, 0x8b, 0xee, 0xcf, 0x44, 0xb4, 0x3e,
  19306. 0x56, 0x75, 0x00, 0x68, 0xb5, 0x7d, 0x0f, 0x20,
  19307. 0x79, 0x5d, 0x7f, 0x12, 0x15, 0x32, 0x89, 0x61,
  19308. 0x6b, 0x29, 0xb7, 0x52, 0xf5, 0x25, 0xd8, 0x98,
  19309. 0xe8, 0x6f, 0xf9, 0x22, 0xb4, 0xbb, 0xe5, 0xff,
  19310. 0xd0, 0x92, 0x86, 0x9a, 0x88, 0xa2, 0xaf, 0x6b
  19311. };
  19312. ret = sizeof(signature_2048);
  19313. XMEMCPY(out, signature_2048, ret);
  19314. }
  19315. #endif
  19316. #if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
  19317. ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  19318. defined(WOLFSSL_PUBLIC_MP)) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19319. idx = (word32)ret;
  19320. XMEMSET(plain, 0, plainSz);
  19321. do {
  19322. #if defined(WOLFSSL_ASYNC_CRYPT)
  19323. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19324. #endif
  19325. if (ret >= 0) {
  19326. #ifndef WOLFSSL_RSA_VERIFY_INLINE
  19327. #if defined(WOLFSSL_CRYPTOCELL)
  19328. /*
  19329. Cryptocell requires the input data and signature byte array to verify.
  19330. first argument must be the input data
  19331. second argument must be the length of input data
  19332. third argument must be the signature byte array or the output from
  19333. wc_RsaSSL_Sign()
  19334. fourth argument must be the length of the signature byte array
  19335. */
  19336. ret = wc_RsaSSL_Verify(in, inLen, out, outSz, key);
  19337. #else
  19338. ret = wc_RsaSSL_Verify(out, idx, plain, plainSz, key);
  19339. #endif /* WOLFSSL_CRYPTOCELL */
  19340. #else
  19341. byte* dec = NULL;
  19342. ret = wc_RsaSSL_VerifyInline(out, idx, &dec, key);
  19343. if (ret > 0) {
  19344. XMEMCPY(plain, dec, ret);
  19345. }
  19346. #endif
  19347. }
  19348. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19349. if (ret < 0)
  19350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19351. if (XMEMCMP(plain, in, (size_t)ret)) {
  19352. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19353. }
  19354. TEST_SLEEP();
  19355. #endif
  19356. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  19357. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG)
  19358. #if (!defined(HAVE_FIPS) || \
  19359. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  19360. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19361. ret = rsa_oaep_padding_test(key, &rng);
  19362. if (ret != 0)
  19363. return ret;
  19364. #endif /* !HAVE_FIPS */
  19365. #endif /* WC_NO_RSA_OAEP && !WC_NO_RNG */
  19366. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  19367. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  19368. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19369. ret = rsa_export_key_test(key);
  19370. if (ret != 0)
  19371. return ret;
  19372. #endif
  19373. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19374. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19375. ret = rsa_flatten_test(key);
  19376. if (ret != 0)
  19377. return ret;
  19378. #endif
  19379. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_ASN) && \
  19380. !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19381. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  19382. (void)clientCert;
  19383. #endif
  19384. #ifdef WOLFSSL_TEST_CERT
  19385. #if defined(WOLFSSL_MDK_ARM)
  19386. #define sizeof(s) XSTRLEN((char *)(s))
  19387. #endif
  19388. #ifdef USE_CERT_BUFFERS_1024
  19389. XMEMCPY(tmp, client_cert_der_1024, (size_t)sizeof_client_cert_der_1024);
  19390. bytes = (size_t)sizeof_client_cert_der_1024;
  19391. #elif defined(USE_CERT_BUFFERS_2048)
  19392. XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048);
  19393. bytes = (size_t)sizeof_client_cert_der_2048;
  19394. #elif defined(USE_CERT_BUFFERS_3072)
  19395. XMEMCPY(tmp, client_cert_der_3072, (size_t)sizeof_client_cert_der_3072);
  19396. bytes = (size_t)sizeof_client_cert_der_3072;
  19397. #elif defined(USE_CERT_BUFFERS_4096)
  19398. XMEMCPY(tmp, client_cert_der_4096, (size_t)sizeof_client_cert_der_4096);
  19399. bytes = (size_t)sizeof_client_cert_der_4096;
  19400. #elif !defined(NO_FILESYSTEM)
  19401. file2 = XFOPEN(clientCert, "rb");
  19402. if (!file2) {
  19403. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19404. }
  19405. bytes = XFREAD(tmp, 1, FOURK_BUF, file2);
  19406. XFCLOSE(file2);
  19407. if (bytes == 0)
  19408. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19409. #else
  19410. /* No certificate to use. */
  19411. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19412. #endif
  19413. #ifdef sizeof
  19414. #undef sizeof
  19415. #endif
  19416. InitDecodedCert(cert, tmp, (word32)bytes, NULL);
  19417. ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
  19418. if (ret != 0) {
  19419. FreeDecodedCert(cert);
  19420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19421. }
  19422. #ifndef NO_ASN_TIME
  19423. ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
  19424. &dateFormat, &dateLength);
  19425. if (ret != 0) {
  19426. FreeDecodedCert(cert);
  19427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19428. }
  19429. ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
  19430. if (ret != 0) {
  19431. FreeDecodedCert(cert);
  19432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19433. }
  19434. #endif
  19435. FreeDecodedCert(cert);
  19436. #endif /* WOLFSSL_TEST_CERT */
  19437. #ifdef WOLFSSL_CERT_EXT
  19438. #ifdef USE_CERT_BUFFERS_1024
  19439. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  19440. bytes = sizeof_client_keypub_der_1024;
  19441. #elif defined(USE_CERT_BUFFERS_2048)
  19442. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  19443. bytes = sizeof_client_keypub_der_2048;
  19444. #elif defined(USE_CERT_BUFFERS_3072)
  19445. XMEMCPY(tmp, client_keypub_der_3072, sizeof_client_keypub_der_3072);
  19446. bytes = sizeof_client_keypub_der_3072;
  19447. #elif defined(USE_CERT_BUFFERS_4096)
  19448. XMEMCPY(tmp, client_keypub_der_4096, sizeof_client_keypub_der_4096);
  19449. bytes = sizeof_client_keypub_der_4096;
  19450. #else
  19451. file = XFOPEN(clientKeyPub, "rb");
  19452. if (!file) {
  19453. err_sys("can't open ./certs/client-keyPub.der, "
  19454. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19455. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19456. }
  19457. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19458. XFCLOSE(file);
  19459. if (bytes == 0)
  19460. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19461. #endif /* USE_CERT_BUFFERS */
  19462. ret = wc_InitRsaKey(keypub, HEAP_HINT);
  19463. if (ret != 0)
  19464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19465. idx = 0;
  19466. ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
  19467. if (ret != 0)
  19468. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19469. #endif /* WOLFSSL_CERT_EXT */
  19470. #ifdef WOLFSSL_KEY_GEN
  19471. ret = rsa_keygen_test(&rng);
  19472. if (ret != 0)
  19473. goto exit_rsa;
  19474. #endif
  19475. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  19476. /* Make Cert / Sign example for RSA cert and RSA CA */
  19477. ret = rsa_certgen_test(key, keypub, &rng, tmp);
  19478. if (ret != 0)
  19479. goto exit_rsa;
  19480. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP)
  19481. ret = rsa_ecc_certgen_test(&rng, tmp);
  19482. if (ret != 0)
  19483. goto exit_rsa;
  19484. #endif
  19485. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  19486. {
  19487. Cert *req;
  19488. int derSz;
  19489. #ifndef WOLFSSL_SMALL_STACK
  19490. byte* der = NULL;
  19491. #endif
  19492. req = (Cert *)XMALLOC(sizeof *req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19493. if (! req)
  19494. ERROR_OUT(MEMORY_E, exit_rsa);
  19495. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER);
  19496. if (der == NULL) {
  19497. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19498. }
  19499. ret = wc_InitCert_ex(req, HEAP_HINT, devId);
  19500. if (ret != 0)
  19501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19502. req->version = 0;
  19503. req->isCA = 1;
  19504. XSTRNCPY(req->challengePw, "wolf123", CTC_NAME_SIZE);
  19505. XMEMCPY(&req->subject, &certDefaultName, sizeof(CertName));
  19506. #ifndef NO_SHA256
  19507. req->sigType = CTC_SHA256wRSA;
  19508. #else
  19509. req->sigType = CTC_SHAwRSA;
  19510. #endif
  19511. #ifdef WOLFSSL_CERT_EXT
  19512. /* add SKID from the Public Key */
  19513. ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL);
  19514. if (ret != 0)
  19515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19516. /* add Key Usage */
  19517. ret = wc_SetKeyUsage(req, certKeyUsage2);
  19518. if (ret != 0)
  19519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19520. /* add Extended Key Usage */
  19521. ret = wc_SetExtKeyUsage(req,
  19522. "serverAuth,clientAuth,codeSigning,"
  19523. "emailProtection,timeStamping,OCSPSigning");
  19524. if (ret != 0)
  19525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19526. #ifdef WOLFSSL_EKU_OID
  19527. {
  19528. WOLFSSL_SMALL_STACK_STATIC const char unique[] =
  19529. "2.16.840.1.111111.100.1.10.1";
  19530. ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0,
  19531. HEAP_HINT);
  19532. if (ret != 0)
  19533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19534. }
  19535. #endif /* WOLFSSL_EKU_OID */
  19536. #endif /* WOLFSSL_CERT_EXT */
  19537. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19538. if (derSz < 0) {
  19539. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19540. }
  19541. #ifdef WOLFSSL_CERT_EXT
  19542. /* Try again with "any" flag set, will override all others */
  19543. ret = wc_SetExtKeyUsage(req, "any");
  19544. if (ret != 0)
  19545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19546. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19547. if (derSz < 0) {
  19548. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19549. }
  19550. #endif /* WOLFSSL_CERT_EXT */
  19551. ret = 0;
  19552. do {
  19553. #if defined(WOLFSSL_ASYNC_CRYPT)
  19554. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19555. #endif
  19556. if (ret >= 0) {
  19557. ret = wc_SignCert(req->bodySz, req->sigType, der, FOURK_BUF,
  19558. key, NULL, &rng);
  19559. }
  19560. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19561. if (ret < 0)
  19562. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19563. derSz = (int)ret;
  19564. ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile,
  19565. CERTREQ_TYPE);
  19566. if (ret != 0) {
  19567. goto exit_rsa;
  19568. }
  19569. derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key);
  19570. if (derSz < 0) {
  19571. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19572. }
  19573. /* Test getting the size of the buffer without providing the buffer.
  19574. * derSz is set to the "largest buffer" we are willing to allocate. */
  19575. derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL);
  19576. if (derSz < 0) {
  19577. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19578. }
  19579. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19580. XFREE(req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19581. der = NULL;
  19582. }
  19583. #endif /* WOLFSSL_CERT_REQ */
  19584. #endif /* WOLFSSL_CERT_GEN */
  19585. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  19586. /* Need to create known good signatures to test with this. */
  19587. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19588. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19589. ret = rsa_pss_test(&rng, key);
  19590. if (ret != 0)
  19591. goto exit_rsa;
  19592. #endif
  19593. #endif
  19594. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  19595. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19596. /* New key to be loaded in rsa_even_mod_test(). */
  19597. if (key != NULL)
  19598. #endif
  19599. wc_FreeRsaKey(key);
  19600. /* New key to be loaded in rsa_even_mod_test(). */
  19601. ret = rsa_even_mod_test(&rng, key);
  19602. #endif
  19603. exit_rsa:
  19604. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19605. if (key != NULL) {
  19606. wc_FreeRsaKey(key);
  19607. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19608. }
  19609. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19610. if (keypub != NULL) {
  19611. wc_FreeRsaKey(keypub);
  19612. XFREE(keypub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19613. }
  19614. #endif
  19615. #ifdef WOLFSSL_TEST_CERT
  19616. XFREE(cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19617. #endif
  19618. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19619. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19620. #else
  19621. wc_FreeRsaKey(key);
  19622. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19623. wc_FreeRsaKey(keypub);
  19624. #endif
  19625. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19626. wc_FreeRng(&rng);
  19627. WC_FREE_VAR(in, HEAP_HINT);
  19628. WC_FREE_VAR(out, HEAP_HINT);
  19629. WC_FREE_VAR(plain, HEAP_HINT);
  19630. (void)res;
  19631. (void)bytes;
  19632. (void)idx;
  19633. (void)in;
  19634. (void)out;
  19635. (void)plain;
  19636. (void)idx;
  19637. (void)inStr;
  19638. (void)inLen;
  19639. (void)outSz;
  19640. (void)plainSz;
  19641. /* ret can be greater then 0 with certgen but all negative values should
  19642. * be returned and treated as an error */
  19643. if (ret >= 0) {
  19644. return 0;
  19645. }
  19646. else {
  19647. return ret;
  19648. }
  19649. }
  19650. #endif /* !NO_RSA */
  19651. #ifndef NO_DH
  19652. static wc_test_ret_t dh_fips_generate_test(WC_RNG *rng)
  19653. {
  19654. wc_test_ret_t ret = 0;
  19655. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19656. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19657. #else
  19658. DhKey key[1];
  19659. #endif
  19660. WOLFSSL_SMALL_STACK_STATIC const byte p[] = {
  19661. 0xc5, 0x7c, 0xa2, 0x4f, 0x4b, 0xd6, 0x8c, 0x3c,
  19662. 0xda, 0xc7, 0xba, 0xaa, 0xea, 0x2e, 0x5c, 0x1e,
  19663. 0x18, 0xb2, 0x7b, 0x8c, 0x55, 0x65, 0x9f, 0xea,
  19664. 0xe0, 0xa1, 0x36, 0x53, 0x2b, 0x36, 0xe0, 0x4e,
  19665. 0x3e, 0x64, 0xa9, 0xe4, 0xfc, 0x8f, 0x32, 0x62,
  19666. 0x97, 0xe4, 0xbe, 0xf7, 0xc1, 0xde, 0x07, 0x5a,
  19667. 0x89, 0x28, 0xf3, 0xfe, 0x4f, 0xfe, 0x68, 0xbc,
  19668. 0xfb, 0x0a, 0x7c, 0xa4, 0xb3, 0x14, 0x48, 0x89,
  19669. 0x9f, 0xaf, 0xb8, 0x43, 0xe2, 0xa0, 0x62, 0x5c,
  19670. 0xb4, 0x88, 0x3f, 0x06, 0x50, 0x11, 0xfe, 0x65,
  19671. 0x8d, 0x49, 0xd2, 0xf5, 0x4b, 0x74, 0x79, 0xdb,
  19672. 0x06, 0x62, 0x92, 0x89, 0xed, 0xda, 0xcb, 0x87,
  19673. 0x37, 0x16, 0xd2, 0xa1, 0x7a, 0xe8, 0xde, 0x92,
  19674. 0xee, 0x3e, 0x41, 0x4a, 0x91, 0x5e, 0xed, 0xf3,
  19675. 0x6c, 0x6b, 0x7e, 0xfd, 0x15, 0x92, 0x18, 0xfc,
  19676. 0xa7, 0xac, 0x42, 0x85, 0x57, 0xe9, 0xdc, 0xda,
  19677. 0x55, 0xc9, 0x8b, 0x28, 0x9e, 0xc1, 0xc4, 0x46,
  19678. 0x4d, 0x88, 0xed, 0x62, 0x8e, 0xdb, 0x3f, 0xb9,
  19679. 0xd7, 0xc8, 0xe3, 0xcf, 0xb8, 0x34, 0x2c, 0xd2,
  19680. 0x6f, 0x28, 0x06, 0x41, 0xe3, 0x66, 0x8c, 0xfc,
  19681. 0x72, 0xff, 0x26, 0x3b, 0x6b, 0x6c, 0x6f, 0x73,
  19682. 0xde, 0xf2, 0x90, 0x29, 0xe0, 0x61, 0x32, 0xc4,
  19683. 0x12, 0x74, 0x09, 0x52, 0xec, 0xf3, 0x1b, 0xa6,
  19684. 0x45, 0x98, 0xac, 0xf9, 0x1c, 0x65, 0x8e, 0x3a,
  19685. 0x91, 0x84, 0x4b, 0x23, 0x8a, 0xb2, 0x3c, 0xc9,
  19686. 0xfa, 0xea, 0xf1, 0x38, 0xce, 0xd8, 0x05, 0xe0,
  19687. 0xfa, 0x44, 0x68, 0x1f, 0xeb, 0xd9, 0x57, 0xb8,
  19688. 0x4a, 0x97, 0x5b, 0x88, 0xc5, 0xf1, 0xbb, 0xb0,
  19689. 0x49, 0xc3, 0x91, 0x7c, 0xd3, 0x13, 0xb9, 0x47,
  19690. 0xbb, 0x91, 0x8f, 0xe5, 0x26, 0x07, 0xab, 0xa9,
  19691. 0xc5, 0xd0, 0x3d, 0x95, 0x41, 0x26, 0x92, 0x9d,
  19692. 0x13, 0x67, 0xf2, 0x7e, 0x11, 0x88, 0xdc, 0x2d
  19693. };
  19694. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  19695. 0x4a, 0x1a, 0xf3, 0xa4, 0x92, 0xe9, 0xee, 0x74,
  19696. 0x6e, 0x57, 0xd5, 0x8c, 0x2c, 0x5b, 0x41, 0x41,
  19697. 0x5e, 0xd4, 0x55, 0x19, 0xdc, 0xd9, 0x32, 0x91,
  19698. 0xf7, 0xfd, 0xc2, 0x57, 0xff, 0x03, 0x14, 0xdb,
  19699. 0xf1, 0xb7, 0x60, 0x0c, 0x43, 0x59, 0x3f, 0xff,
  19700. 0xac, 0xf1, 0x80, 0x9a, 0x15, 0x6f, 0xd8, 0x6e,
  19701. 0xb7, 0x85, 0x18, 0xc8, 0xec, 0x4e, 0x59, 0x4a,
  19702. 0xe2, 0x91, 0x43, 0x4c, 0xeb, 0x95, 0xb6, 0x2e,
  19703. 0x9a, 0xea, 0x53, 0x68, 0x80, 0x64, 0x69, 0x40,
  19704. 0xf9, 0xec, 0xbd, 0x85, 0x89, 0x26, 0x97, 0x67,
  19705. 0xaf, 0xb0, 0xad, 0x00, 0x1b, 0xd4, 0xfd, 0x94,
  19706. 0xd3, 0xe9, 0x92, 0xb1, 0xb4, 0xbc, 0x5a, 0xaa,
  19707. 0x92, 0x80, 0x89, 0x3b, 0x39, 0x05, 0x6c, 0x22,
  19708. 0x26, 0xfe, 0x5a, 0x28, 0x6c, 0x37, 0x50, 0x5a,
  19709. 0x38, 0x99, 0xcf, 0xf3, 0xc1, 0x96, 0x45, 0xdc,
  19710. 0x01, 0xcb, 0x20, 0x87, 0xa5, 0x00, 0x8c, 0xf5,
  19711. 0x4d, 0xc2, 0xef, 0xb8, 0x9b, 0xd1, 0x87, 0xbe,
  19712. 0xed, 0xd5, 0x0a, 0x29, 0x15, 0x34, 0x59, 0x4c,
  19713. 0x3a, 0x05, 0x22, 0x05, 0x44, 0x4f, 0x9f, 0xc8,
  19714. 0x47, 0x12, 0x24, 0x8e, 0xa8, 0x79, 0xe4, 0x67,
  19715. 0xba, 0x4d, 0x5b, 0x75, 0x56, 0x95, 0xeb, 0xe8,
  19716. 0x8a, 0xfa, 0x8e, 0x01, 0x8c, 0x1b, 0x74, 0x63,
  19717. 0xd9, 0x2f, 0xf7, 0xd3, 0x44, 0x8f, 0xa8, 0xf5,
  19718. 0xaf, 0x6c, 0x4f, 0xdb, 0xe7, 0xc9, 0x6c, 0x71,
  19719. 0x22, 0xa3, 0x1d, 0xf1, 0x40, 0xb2, 0xe0, 0x9a,
  19720. 0xb6, 0x72, 0xc9, 0xc0, 0x13, 0x16, 0xa2, 0x4a,
  19721. 0xe1, 0x92, 0xc7, 0x54, 0x23, 0xab, 0x9d, 0xa1,
  19722. 0xa1, 0xe5, 0x0b, 0xed, 0xba, 0xe8, 0x84, 0x37,
  19723. 0xb2, 0xe7, 0xfe, 0x32, 0x8d, 0xfa, 0x1c, 0x53,
  19724. 0x77, 0x97, 0xc7, 0xf3, 0x48, 0xc9, 0xdb, 0x2d,
  19725. 0x75, 0x52, 0x9d, 0x42, 0x51, 0x78, 0x62, 0x68,
  19726. 0x05, 0x45, 0x15, 0xf8, 0xa2, 0x4e, 0xf3, 0x0b
  19727. };
  19728. WOLFSSL_SMALL_STACK_STATIC const byte q[] = {
  19729. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19730. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19731. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19732. 0x40, 0x52, 0xed, 0x41
  19733. };
  19734. WOLFSSL_SMALL_STACK_STATIC const byte q0[] = {
  19735. 0x00,
  19736. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19737. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19738. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19739. 0x40, 0x52, 0xed, 0x41
  19740. };
  19741. byte priv[256];
  19742. byte pub[256];
  19743. word32 privSz = sizeof(priv);
  19744. word32 pubSz = sizeof(pub);
  19745. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19746. if (key == NULL)
  19747. ERROR_OUT(MEMORY_E, exit_gen_test);
  19748. #endif
  19749. /* Parameter Validation testing. */
  19750. ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz);
  19751. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19752. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19753. ret = wc_DhGenerateKeyPair(key, NULL, priv, &privSz, pub, &pubSz);
  19754. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19755. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19756. ret = wc_DhGenerateKeyPair(key, rng, NULL, &privSz, pub, &pubSz);
  19757. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19758. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19759. ret = wc_DhGenerateKeyPair(key, rng, priv, NULL, pub, &pubSz);
  19760. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19762. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, NULL, &pubSz);
  19763. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19764. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19765. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, NULL);
  19766. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19767. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19768. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19769. if (ret != 0)
  19770. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19771. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0));
  19772. if (ret != 0)
  19773. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19774. wc_FreeDhKey(key);
  19775. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19776. if (ret != 0)
  19777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19778. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q));
  19779. if (ret != 0)
  19780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19781. /* Use API. */
  19782. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19783. #if defined(WOLFSSL_ASYNC_CRYPT)
  19784. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19785. #endif
  19786. if (ret != 0)
  19787. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19788. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0));
  19789. if (ret != 0)
  19790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19791. wc_FreeDhKey(key);
  19792. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19793. if (ret != 0)
  19794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19795. ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
  19796. if (ret != 0)
  19797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19798. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q));
  19799. if (ret != 0)
  19800. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19801. #ifndef HAVE_SELFTEST
  19802. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19803. if (ret != 0)
  19804. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19805. /* Taint the public key so the check fails. */
  19806. pub[0]++;
  19807. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19808. if (ret != WC_NO_ERR_TRACE(MP_CMP_E)) {
  19809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19810. }
  19811. #ifdef WOLFSSL_KEY_GEN
  19812. wc_FreeDhKey(key);
  19813. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19814. if (ret != 0)
  19815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19816. ret = wc_DhGenerateParams(rng, 2048, key);
  19817. if (ret != 0)
  19818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19819. privSz = sizeof(priv);
  19820. pubSz = sizeof(pub);
  19821. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19822. #if defined(WOLFSSL_ASYNC_CRYPT)
  19823. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19824. #endif
  19825. if (ret != 0)
  19826. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19827. #endif /* WOLFSSL_KEY_GEN */
  19828. #endif /* HAVE_SELFTEST */
  19829. ret = 0;
  19830. exit_gen_test:
  19831. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19832. if (key) {
  19833. wc_FreeDhKey(key);
  19834. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19835. }
  19836. #else
  19837. wc_FreeDhKey(key);
  19838. #endif
  19839. return ret;
  19840. }
  19841. static wc_test_ret_t dh_generate_test(WC_RNG *rng)
  19842. {
  19843. wc_test_ret_t ret = 0;
  19844. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19845. DhKey *smallKey = NULL;
  19846. #else
  19847. DhKey smallKey[1];
  19848. #endif
  19849. byte p[2] = { 1, 7 }; /* 263 in decimal */
  19850. byte g[2] = { 0, 2 };
  19851. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19852. #ifdef WOLFSSL_DH_CONST
  19853. /* the table for constant DH lookup will round to the lowest byte size 21 */
  19854. byte priv[21];
  19855. byte pub[21];
  19856. #else
  19857. byte priv[2];
  19858. byte pub[2];
  19859. #endif
  19860. word32 privSz = sizeof(priv);
  19861. word32 pubSz = sizeof(pub);
  19862. #endif
  19863. int smallKey_inited = 0;
  19864. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19865. if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  19866. return WC_TEST_RET_ENC_ERRNO;
  19867. #endif
  19868. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19869. if (ret != 0)
  19870. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19871. smallKey_inited = 1;
  19872. /* Parameter Validation testing. */
  19873. ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId);
  19874. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19875. return WC_TEST_RET_ENC_EC(ret);
  19876. wc_FreeDhKey(NULL);
  19877. ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g));
  19878. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19879. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19880. }
  19881. ret = wc_DhSetKey(smallKey, NULL, sizeof(p), g, sizeof(g));
  19882. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19884. }
  19885. ret = wc_DhSetKey(smallKey, p, 0, g, sizeof(g));
  19886. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19888. }
  19889. ret = wc_DhSetKey(smallKey, p, sizeof(p), NULL, sizeof(g));
  19890. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19892. }
  19893. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, 0);
  19894. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19896. }
  19897. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, sizeof(g));
  19898. if (ret != 0)
  19899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19900. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19901. /* Use API. */
  19902. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  19903. #if defined(WOLFSSL_ASYNC_CRYPT)
  19904. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  19905. #endif
  19906. if (ret != 0) {
  19907. ret = WC_TEST_RET_ENC_EC(ret);
  19908. }
  19909. #else
  19910. (void)rng;
  19911. #if defined(HAVE_FIPS) || !defined(WOLFSSL_NO_DH186)
  19912. ret = 0;
  19913. #endif
  19914. #endif
  19915. #if !defined(HAVE_FIPS) && defined(WOLFSSL_NO_DH186)
  19916. {
  19917. byte priv[260];
  19918. byte pub[260];
  19919. word32 privSz = sizeof(priv);
  19920. word32 pubSz = sizeof(pub);
  19921. /* test odd ball param generation with DH */
  19922. wc_FreeDhKey(smallKey);
  19923. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19924. if (ret != 0)
  19925. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19926. /* should fail since modSz is 16 and group size is 20 */
  19927. ret = wc_DhGenerateParams(rng, 128, smallKey);
  19928. if (ret == 0)
  19929. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19930. ret = wc_DhGenerateParams(rng, 2056, smallKey);
  19931. if (ret != 0)
  19932. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19933. privSz = sizeof(priv);
  19934. pubSz = sizeof(pub);
  19935. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  19936. #if defined(WOLFSSL_ASYNC_CRYPT)
  19937. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  19938. #endif
  19939. if (ret != 0)
  19940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19941. }
  19942. #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */
  19943. exit_gen_test:
  19944. if (smallKey_inited)
  19945. wc_FreeDhKey(smallKey);
  19946. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19947. XFREE(smallKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19948. #endif
  19949. return ret;
  19950. }
  19951. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  19952. typedef struct dh_pubvalue_test {
  19953. const byte* data;
  19954. word32 len;
  19955. } dh_pubvalue_test;
  19956. static wc_test_ret_t dh_test_check_pubvalue(void)
  19957. {
  19958. wc_test_ret_t ret;
  19959. word32 i;
  19960. WOLFSSL_SMALL_STACK_STATIC const byte prime[] = {0x01, 0x00, 0x01};
  19961. WOLFSSL_SMALL_STACK_STATIC const byte pubValZero[] = { 0x00 };
  19962. WOLFSSL_SMALL_STACK_STATIC const byte pubValZeroLong[] = { 0x00, 0x00, 0x00 };
  19963. WOLFSSL_SMALL_STACK_STATIC const byte pubValOne[] = { 0x01 };
  19964. WOLFSSL_SMALL_STACK_STATIC const byte pubValOneLong[] = { 0x00, 0x00, 0x01 };
  19965. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeMinusOne[] = { 0x01, 0x00, 0x00 };
  19966. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeLong[] = {0x00, 0x01, 0x00, 0x01};
  19967. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimePlusOne[] = { 0x01, 0x00, 0x02 };
  19968. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig0[] = { 0x02, 0x00, 0x01 };
  19969. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig1[] = { 0x01, 0x01, 0x01 };
  19970. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooLong[] = { 0x01, 0x00, 0x00, 0x01 };
  19971. const dh_pubvalue_test dh_pubval_fail[] = {
  19972. { prime, sizeof(prime) },
  19973. { pubValZero, sizeof(pubValZero) },
  19974. { pubValZeroLong, sizeof(pubValZeroLong) },
  19975. { pubValOne, sizeof(pubValOne) },
  19976. { pubValOneLong, sizeof(pubValOneLong) },
  19977. { pubValPrimeMinusOne, sizeof(pubValPrimeMinusOne) },
  19978. { pubValPrimeLong, sizeof(pubValPrimeLong) },
  19979. { pubValPrimePlusOne, sizeof(pubValPrimePlusOne) },
  19980. { pubValTooBig0, sizeof(pubValTooBig0) },
  19981. { pubValTooBig1, sizeof(pubValTooBig1) },
  19982. { pubValTooLong, sizeof(pubValTooLong) },
  19983. };
  19984. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwo[] = { 0x02 };
  19985. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwoLong[] = { 0x00, 0x00, 0x02 };
  19986. WOLFSSL_SMALL_STACK_STATIC const byte pubValGood[] = { 0x12, 0x34 };
  19987. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLen[] = { 0x00, 0x12, 0x34 };
  19988. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLong[] = { 0x00, 0x00, 0x12, 0x34 };
  19989. const dh_pubvalue_test dh_pubval_pass[] = {
  19990. { pubValTwo, sizeof(pubValTwo) },
  19991. { pubValTwoLong, sizeof(pubValTwoLong) },
  19992. { pubValGood, sizeof(pubValGood) },
  19993. { pubValGoodLen, sizeof(pubValGoodLen) },
  19994. { pubValGoodLong, sizeof(pubValGoodLong) },
  19995. };
  19996. for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) {
  19997. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data,
  19998. dh_pubval_fail[i].len);
  19999. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  20000. return WC_TEST_RET_ENC_I(i);
  20001. }
  20002. for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) {
  20003. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data,
  20004. dh_pubval_pass[i].len);
  20005. if (ret != 0)
  20006. return WC_TEST_RET_ENC_I(i);
  20007. }
  20008. return 0;
  20009. }
  20010. #endif
  20011. #if defined(HAVE_FFDHE)
  20012. #if defined(HAVE_FFDHE_4096)
  20013. #define MAX_DH_PRIV_SZ 39
  20014. #define MAX_DH_KEY_SZ 512
  20015. #elif defined(HAVE_FFDHE_3072)
  20016. #define MAX_DH_PRIV_SZ 34
  20017. #define MAX_DH_KEY_SZ 384
  20018. #else
  20019. #define MAX_DH_PRIV_SZ 29
  20020. #define MAX_DH_KEY_SZ 256
  20021. #endif
  20022. #ifndef WC_NO_RNG
  20023. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20024. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20025. #ifdef HAVE_PUBLIC_FFDHE
  20026. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
  20027. #else
  20028. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, int name)
  20029. #endif
  20030. {
  20031. wc_test_ret_t ret;
  20032. word32 privSz, pubSz, privSz2, pubSz2;
  20033. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20034. byte *priv = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20035. byte *pub = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20036. byte *priv2 = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20037. byte *pub2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20038. byte *agree = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20039. byte *agree2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20040. DhKey *key = (DhKey*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20041. DhKey *key2 = (DhKey*)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20042. #else
  20043. byte priv[MAX_DH_PRIV_SZ];
  20044. byte pub[MAX_DH_KEY_SZ];
  20045. byte priv2[MAX_DH_PRIV_SZ];
  20046. byte pub2[MAX_DH_KEY_SZ];
  20047. byte agree[MAX_DH_KEY_SZ];
  20048. byte agree2[MAX_DH_KEY_SZ];
  20049. DhKey key[1];
  20050. DhKey key2[1];
  20051. #endif
  20052. word32 agreeSz = MAX_DH_KEY_SZ;
  20053. word32 agreeSz2 = MAX_DH_KEY_SZ;
  20054. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20055. if ((priv == NULL) ||
  20056. (pub == NULL) ||
  20057. (priv2 == NULL) ||
  20058. (pub2 == NULL) ||
  20059. (agree == NULL) ||
  20060. (agree2 == NULL) ||
  20061. (key == NULL) ||
  20062. (key2 == NULL))
  20063. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20064. #endif
  20065. pubSz = MAX_DH_KEY_SZ;
  20066. pubSz2 = MAX_DH_KEY_SZ;
  20067. #ifdef HAVE_PUBLIC_FFDHE
  20068. privSz = MAX_DH_PRIV_SZ;
  20069. privSz2 = MAX_DH_PRIV_SZ;
  20070. #else
  20071. privSz = wc_DhGetNamedKeyMinSize(name);
  20072. privSz2 = privSz;
  20073. #endif
  20074. XMEMSET(key, 0, sizeof(*key));
  20075. XMEMSET(key2, 0, sizeof(*key2));
  20076. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20077. if (ret != 0)
  20078. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20079. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20080. if (ret != 0)
  20081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20082. #ifdef HAVE_PUBLIC_FFDHE
  20083. ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len);
  20084. #else
  20085. ret = wc_DhSetNamedKey(key, name);
  20086. #endif
  20087. if (ret != 0)
  20088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20089. #ifdef HAVE_PUBLIC_FFDHE
  20090. ret = wc_DhSetKey(key2, params->p, params->p_len, params->g,
  20091. params->g_len);
  20092. #else
  20093. ret = wc_DhSetNamedKey(key2, name);
  20094. #endif
  20095. if (ret != 0)
  20096. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20097. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20098. #if defined(WOLFSSL_ASYNC_CRYPT)
  20099. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20100. #endif
  20101. if (ret != 0)
  20102. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20103. ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2);
  20104. #if defined(WOLFSSL_ASYNC_CRYPT)
  20105. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20106. #endif
  20107. if (ret != 0)
  20108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20109. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20110. #if defined(WOLFSSL_ASYNC_CRYPT)
  20111. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20112. #endif
  20113. if (ret != 0)
  20114. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20115. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20116. #if defined(WOLFSSL_ASYNC_CRYPT)
  20117. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20118. #endif
  20119. if (ret != 0)
  20120. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20121. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20122. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20123. }
  20124. #if (defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH)) && \
  20125. !defined(HAVE_INTEL_QA)
  20126. /* Make p even */
  20127. key->p.dp[0] &= (mp_digit)-2;
  20128. if (ret != 0)
  20129. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20130. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20131. #if defined(WOLFSSL_ASYNC_CRYPT)
  20132. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20133. #endif
  20134. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20135. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  20136. {
  20137. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20138. }
  20139. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20140. #if defined(WOLFSSL_ASYNC_CRYPT)
  20141. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20142. #endif
  20143. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20144. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20145. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20146. {
  20147. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20148. }
  20149. #ifndef HAVE_SELFTEST
  20150. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  20151. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20152. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20153. ret != WC_NO_ERR_TRACE(MP_CMP_E) &&
  20154. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20155. {
  20156. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20157. }
  20158. #endif
  20159. /* Getting here means success - set ret to 0. */
  20160. ret = 0;
  20161. #endif /* (SP DH or Fast Math) and not Intel QuickAssist */
  20162. done:
  20163. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) && \
  20164. !defined(WC_NO_RNG)
  20165. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20166. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20167. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20168. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20169. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20170. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20171. if (key) {
  20172. wc_FreeDhKey(key);
  20173. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20174. }
  20175. if (key2) {
  20176. wc_FreeDhKey(key2);
  20177. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20178. }
  20179. #else
  20180. wc_FreeDhKey(key);
  20181. wc_FreeDhKey(key2);
  20182. #endif
  20183. return ret;
  20184. }
  20185. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  20186. #endif /* !WC_NO_RNG */
  20187. #endif /* HAVE_FFDHE */
  20188. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void)
  20189. {
  20190. wc_test_ret_t ret;
  20191. word32 bytes;
  20192. word32 idx = 0, privSz, pubSz, privSz2, pubSz2;
  20193. #ifndef WC_NO_RNG
  20194. WC_RNG rng;
  20195. int rngInit = 0;
  20196. #endif
  20197. int keyInit = 0, key2Init = 0;
  20198. #define DH_TEST_TMP_SIZE 1024
  20199. #if !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  20200. #define DH_TEST_BUF_SIZE 256
  20201. #else
  20202. #define DH_TEST_BUF_SIZE 512
  20203. #endif
  20204. #ifndef WC_NO_RNG
  20205. word32 agreeSz = DH_TEST_BUF_SIZE;
  20206. word32 agreeSz2 = DH_TEST_BUF_SIZE;
  20207. #endif
  20208. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20209. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20210. DhKey *key2 = (DhKey *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20211. byte *tmp = (byte *)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20212. #else
  20213. DhKey key[1];
  20214. DhKey key2[1];
  20215. byte tmp[DH_TEST_TMP_SIZE];
  20216. #endif
  20217. #ifndef WC_NO_RNG
  20218. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20219. byte *priv = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20220. byte *pub = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20221. byte *priv2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20222. byte *pub2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20223. byte *agree = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20224. byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20225. if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL ||
  20226. agree == NULL || agree2 == NULL) {
  20227. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20228. }
  20229. #else
  20230. byte priv[DH_TEST_BUF_SIZE];
  20231. byte pub[DH_TEST_BUF_SIZE];
  20232. byte priv2[DH_TEST_BUF_SIZE];
  20233. byte pub2[DH_TEST_BUF_SIZE];
  20234. byte agree[DH_TEST_BUF_SIZE];
  20235. byte agree2[DH_TEST_BUF_SIZE];
  20236. #endif
  20237. #endif /* !WC_NO_RNG */
  20238. WOLFSSL_ENTER("dh_test");
  20239. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20240. if (key == NULL || key2 == NULL || tmp == NULL) {
  20241. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20242. }
  20243. #endif
  20244. #ifdef USE_CERT_BUFFERS_1024
  20245. XMEMCPY(tmp, dh_key_der_1024, (size_t)sizeof_dh_key_der_1024);
  20246. bytes = (size_t)sizeof_dh_key_der_1024;
  20247. #elif defined(USE_CERT_BUFFERS_2048)
  20248. XMEMCPY(tmp, dh_key_der_2048, (size_t)sizeof_dh_key_der_2048);
  20249. bytes = (size_t)sizeof_dh_key_der_2048;
  20250. #elif defined(USE_CERT_BUFFERS_3072)
  20251. XMEMCPY(tmp, dh_key_der_3072, (size_t)sizeof_dh_key_der_3072);
  20252. bytes = (size_t)sizeof_dh_key_der_3072;
  20253. #elif defined(USE_CERT_BUFFERS_4096)
  20254. XMEMCPY(tmp, dh_key_der_4096, (size_t)sizeof_dh_key_der_4096);
  20255. bytes = (size_t)sizeof_dh_key_der_4096;
  20256. #elif defined(NO_ASN)
  20257. /* don't use file, no DER parsing */
  20258. #elif !defined(NO_FILESYSTEM)
  20259. {
  20260. XFILE file = XFOPEN(dhParamsFile, "rb");
  20261. if (! file)
  20262. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20263. bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20264. XFCLOSE(file);
  20265. if (bytes == 0)
  20266. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20267. }
  20268. #else
  20269. /* No DH key to use. */
  20270. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20271. #endif /* USE_CERT_BUFFERS */
  20272. (void)idx;
  20273. (void)tmp;
  20274. (void)bytes;
  20275. pubSz = DH_TEST_BUF_SIZE;
  20276. pubSz2 = DH_TEST_BUF_SIZE;
  20277. privSz = DH_TEST_BUF_SIZE;
  20278. privSz2 = DH_TEST_BUF_SIZE;
  20279. #ifndef WC_NO_RNG
  20280. XMEMSET(&rng, 0, sizeof(rng));
  20281. #endif
  20282. /* Use API for coverage. */
  20283. ret = wc_InitDhKey(key);
  20284. if (ret != 0)
  20285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20286. wc_FreeDhKey(key);
  20287. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20288. if (ret != 0)
  20289. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20290. keyInit = 1;
  20291. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20292. if (ret != 0)
  20293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20294. key2Init = 1;
  20295. #ifdef NO_ASN
  20296. #ifndef WOLFSSL_SP_MATH
  20297. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20298. if (ret != 0)
  20299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20300. ret = wc_DhSetKey(key2, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20301. if (ret != 0)
  20302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20303. #else
  20304. ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20305. sizeof(dh2048_g));
  20306. if (ret != 0)
  20307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20308. ret = wc_DhSetKey(key2, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20309. sizeof(dh2048_g));
  20310. if (ret != 0)
  20311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20312. #endif
  20313. #else
  20314. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20315. if (ret != 0)
  20316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20317. idx = 0;
  20318. ret = wc_DhKeyDecode(tmp, &idx, key2, bytes);
  20319. if (ret != 0)
  20320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20321. #endif
  20322. #ifndef WC_NO_RNG
  20323. #ifndef HAVE_FIPS
  20324. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20325. #else
  20326. ret = wc_InitRng(&rng);
  20327. #endif
  20328. if (ret != 0)
  20329. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20330. rngInit = 1;
  20331. ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz);
  20332. #if defined(WOLFSSL_ASYNC_CRYPT)
  20333. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20334. #endif
  20335. if (ret != 0)
  20336. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20337. ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2);
  20338. #if defined(WOLFSSL_ASYNC_CRYPT)
  20339. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20340. #endif
  20341. if (ret != 0)
  20342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20343. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20344. #if defined(WOLFSSL_ASYNC_CRYPT)
  20345. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20346. #endif
  20347. if (ret != 0)
  20348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20349. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20350. #if defined(WOLFSSL_ASYNC_CRYPT)
  20351. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20352. #endif
  20353. if (ret != 0)
  20354. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20355. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20356. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20357. }
  20358. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) && \
  20359. !defined(HAVE_SELFTEST)
  20360. agreeSz = DH_TEST_BUF_SIZE;
  20361. agreeSz2 = DH_TEST_BUF_SIZE;
  20362. ret = wc_DhAgree_ct(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20363. if (ret != 0)
  20364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20365. ret = wc_DhAgree_ct(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20366. if (ret != 0)
  20367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20368. #ifdef WOLFSSL_PUBLIC_MP
  20369. if (agreeSz != (word32)mp_unsigned_bin_size(&key->p))
  20370. {
  20371. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20372. }
  20373. #endif
  20374. if (agreeSz != agreeSz2)
  20375. {
  20376. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20377. }
  20378. if (XMEMCMP(agree, agree2, agreeSz) != 0)
  20379. {
  20380. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20381. }
  20382. #endif /* (!HAVE_FIPS || FIPS_VERSION_GE(7,0)) && !HAVE_SELFTEST */
  20383. #endif /* !WC_NO_RNG */
  20384. #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20385. ret = wc_DhCheckPrivKey(NULL, NULL, 0);
  20386. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20387. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20388. ret = wc_DhCheckPrivKey(key, priv, privSz);
  20389. if (ret != 0)
  20390. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20391. ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  20392. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20393. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20394. {
  20395. word32 pSz, qSz, gSz;
  20396. ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz);
  20397. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  20398. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20399. }
  20400. #endif
  20401. /* Test DH key import / export */
  20402. #if defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM) && \
  20403. (!defined(HAVE_FIPS) || \
  20404. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  20405. wc_FreeDhKey(key);
  20406. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20407. if (ret != 0)
  20408. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20409. #ifndef NO_ASN
  20410. {
  20411. /* DH Private - Key Export / Import */
  20412. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20413. byte *tmp2;
  20414. #else
  20415. byte tmp2[DH_TEST_TMP_SIZE];
  20416. #endif
  20417. #if defined(USE_CERT_BUFFERS_2048)
  20418. XMEMCPY(tmp, dh_ffdhe_statickey_der_2048, sizeof_dh_ffdhe_statickey_der_2048);
  20419. bytes = sizeof_dh_ffdhe_statickey_der_2048;
  20420. #else
  20421. XFILE file = XFOPEN(dhKeyFile, "rb");
  20422. if (!file)
  20423. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20424. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20425. XFCLOSE(file);
  20426. if (bytes == 0)
  20427. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20428. #endif
  20429. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20430. tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20431. if (tmp2 == NULL)
  20432. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20433. #endif
  20434. idx = 0;
  20435. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20436. /* Import DH Private key as DER */
  20437. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20438. if (ret == 0) {
  20439. /* Export as DER */
  20440. idx = DH_TEST_TMP_SIZE;
  20441. ret = wc_DhPrivKeyToDer(key, tmp2, &idx);
  20442. }
  20443. /* Verify export matches original */
  20444. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20445. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20446. }
  20447. /* DH Public Key - Export / Import */
  20448. #if defined(USE_CERT_BUFFERS_2048)
  20449. XMEMCPY(tmp, dh_ffdhe_pub_statickey_der_2048, sizeof_dh_ffdhe_pub_statickey_der_2048);
  20450. bytes = sizeof_dh_ffdhe_pub_statickey_der_2048;
  20451. #else
  20452. file = XFOPEN(dhKeyPubFile, "rb");
  20453. if (!file)
  20454. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20455. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20456. XFCLOSE(file);
  20457. if (bytes == 0)
  20458. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20459. #endif
  20460. /* for HAVE_WOLF_BIGINT prevent leak */
  20461. wc_FreeDhKey(key);
  20462. (void)wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20463. idx = 0;
  20464. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20465. /* Import DH Public key as DER */
  20466. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20467. if (ret == 0) {
  20468. /* Export as DER */
  20469. idx = DH_TEST_TMP_SIZE;
  20470. ret = wc_DhPubKeyToDer(key, tmp2, &idx);
  20471. }
  20472. /* Verify export matches original */
  20473. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20474. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20475. }
  20476. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20477. XFREE(tmp2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20478. #endif
  20479. }
  20480. #else
  20481. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20482. if (ret != 0)
  20483. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20484. #endif /* !NO_ASN */
  20485. privSz = DH_TEST_BUF_SIZE;
  20486. pubSz = DH_TEST_BUF_SIZE;
  20487. ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz);
  20488. if (ret != 0)
  20489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20490. ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz);
  20491. if (ret != 0)
  20492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20493. #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */
  20494. #ifndef WC_NO_RNG
  20495. ret = dh_generate_test(&rng);
  20496. if (ret != 0)
  20497. ERROR_OUT(ret, done);
  20498. ret = dh_fips_generate_test(&rng);
  20499. if (ret != 0)
  20500. ERROR_OUT(ret, done);
  20501. #endif /* !WC_NO_RNG */
  20502. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20503. ret = dh_test_check_pubvalue();
  20504. if (ret != 0)
  20505. ERROR_OUT(ret, done);
  20506. #endif
  20507. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20508. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20509. /* RNG with DH and SP_ASM code not supported in the in-lined FIPS ASM code,
  20510. * this will be available for testing in the 140-3 module */
  20511. #ifndef WC_NO_RNG
  20512. /* Specialized code for key gen when using FFDHE-2048, FFDHE-3072 and FFDHE-4096 */
  20513. #ifdef HAVE_FFDHE_2048
  20514. #ifdef HAVE_PUBLIC_FFDHE
  20515. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe2048_Get());
  20516. #else
  20517. ret = dh_ffdhe_test(&rng, WC_FFDHE_2048);
  20518. #endif
  20519. if (ret != 0)
  20520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20521. #endif
  20522. #ifdef HAVE_FFDHE_3072
  20523. #ifdef HAVE_PUBLIC_FFDHE
  20524. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe3072_Get());
  20525. #else
  20526. ret = dh_ffdhe_test(&rng, WC_FFDHE_3072);
  20527. #endif
  20528. if (ret != 0)
  20529. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20530. #endif
  20531. #ifdef HAVE_FFDHE_4096
  20532. #ifdef HAVE_PUBLIC_FFDHE
  20533. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe4096_Get());
  20534. #else
  20535. ret = dh_ffdhe_test(&rng, WC_FFDHE_4096);
  20536. #endif
  20537. if (ret != 0)
  20538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20539. #endif
  20540. #endif /* !WC_NO_RNG */
  20541. #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */
  20542. wc_FreeDhKey(key);
  20543. keyInit = 0;
  20544. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  20545. !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(WC_NO_RNG)
  20546. /* Test Check Key */
  20547. ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g),
  20548. NULL, 0, 0, &rng);
  20549. if (ret != 0)
  20550. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20551. keyInit = 1; /* DhSetCheckKey also initializes the key, free it */
  20552. #endif
  20553. done:
  20554. #ifndef WC_NO_RNG
  20555. if (rngInit)
  20556. wc_FreeRng(&rng);
  20557. #endif
  20558. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20559. if (key) {
  20560. if (keyInit)
  20561. wc_FreeDhKey(key);
  20562. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20563. }
  20564. if (key2) {
  20565. if (key2Init)
  20566. wc_FreeDhKey(key2);
  20567. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20568. }
  20569. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20570. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20571. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20572. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20573. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20574. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20575. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20576. #else
  20577. if (keyInit)
  20578. wc_FreeDhKey(key);
  20579. if (key2Init)
  20580. wc_FreeDhKey(key2);
  20581. #endif
  20582. (void)privSz;
  20583. (void)pubSz;
  20584. (void)pubSz2;
  20585. (void)privSz2;
  20586. return ret;
  20587. #undef DH_TEST_BUF_SIZE
  20588. #undef DH_TEST_TMP_SIZE
  20589. }
  20590. #endif /* NO_DH */
  20591. #ifndef NO_DSA
  20592. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
  20593. {
  20594. wc_test_ret_t ret = 0;
  20595. int answer;
  20596. word32 bytes;
  20597. word32 idx = 0;
  20598. WC_RNG rng;
  20599. int rng_inited = 0;
  20600. wc_Sha sha;
  20601. byte hash[WC_SHA_DIGEST_SIZE];
  20602. byte signature[40];
  20603. int key_inited = 0;
  20604. #ifdef WOLFSSL_KEY_GEN
  20605. byte* der = 0;
  20606. int derIn_inited = 0;
  20607. int genKey_inited = 0;
  20608. #endif
  20609. #define DSA_TEST_TMP_SIZE 1024
  20610. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20611. byte *tmp = (byte *)XMALLOC(DSA_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20612. DsaKey *key = (DsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20613. #ifdef WOLFSSL_KEY_GEN
  20614. DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20615. DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20616. #endif
  20617. WOLFSSL_ENTER("dsa_test");
  20618. if ((tmp == NULL) ||
  20619. (key == NULL)
  20620. #ifdef WOLFSSL_KEY_GEN
  20621. || (derIn == NULL)
  20622. || (genKey == NULL)
  20623. #endif
  20624. ) {
  20625. ret = WC_TEST_RET_ENC_NC;
  20626. goto out;
  20627. }
  20628. #else
  20629. byte tmp[1024];
  20630. DsaKey key[1];
  20631. #ifdef WOLFSSL_KEY_GEN
  20632. DsaKey derIn[1];
  20633. DsaKey genKey[1];
  20634. #endif
  20635. #endif
  20636. #ifdef USE_CERT_BUFFERS_1024
  20637. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20638. bytes = sizeof_dsa_key_der_1024;
  20639. #elif defined(USE_CERT_BUFFERS_2048)
  20640. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20641. bytes = sizeof_dsa_key_der_2048;
  20642. #else
  20643. {
  20644. XFILE file = XFOPEN(dsaKey, "rb");
  20645. if (!file)
  20646. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20647. bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file);
  20648. XFCLOSE(file);
  20649. if (bytes == 0)
  20650. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20651. }
  20652. #endif /* USE_CERT_BUFFERS */
  20653. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  20654. if (ret != 0)
  20655. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20656. wc_ShaUpdate(&sha, tmp, bytes);
  20657. wc_ShaFinal(&sha, hash);
  20658. wc_ShaFree(&sha);
  20659. ret = wc_InitDsaKey(key);
  20660. if (ret != 0)
  20661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20662. key_inited = 1;
  20663. ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes);
  20664. if (ret != 0)
  20665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20666. #ifndef HAVE_FIPS
  20667. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20668. #else
  20669. ret = wc_InitRng(&rng);
  20670. #endif
  20671. if (ret != 0)
  20672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20673. rng_inited = 1;
  20674. ret = wc_DsaSign(hash, signature, key, &rng);
  20675. if (ret != 0)
  20676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20677. ret = wc_DsaVerify(hash, signature, key, &answer);
  20678. if (ret != 0)
  20679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20680. if (answer != 1)
  20681. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20682. wc_FreeDsaKey(key);
  20683. key_inited = 0;
  20684. ret = wc_InitDsaKey_h(key, NULL);
  20685. if (ret != 0)
  20686. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20687. key_inited = 1;
  20688. #ifdef WOLFSSL_KEY_GEN
  20689. {
  20690. int derSz = 0;
  20691. ret = wc_InitDsaKey(genKey);
  20692. if (ret != 0)
  20693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20694. genKey_inited = 1;
  20695. ret = wc_MakeDsaParameters(&rng, 1024, genKey);
  20696. if (ret != 0)
  20697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20698. ret = wc_MakeDsaKey(&rng, genKey);
  20699. if (ret != 0)
  20700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20701. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20702. if (der == NULL)
  20703. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20704. derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF);
  20705. if (derSz < 0)
  20706. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out);
  20707. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  20708. DSA_PRIVATEKEY_TYPE);
  20709. if (ret != 0)
  20710. goto out;
  20711. ret = wc_InitDsaKey(derIn);
  20712. if (ret != 0)
  20713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20714. derIn_inited = 1;
  20715. idx = 0;
  20716. ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, (word32)derSz);
  20717. if (ret != 0)
  20718. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20719. }
  20720. #endif /* WOLFSSL_KEY_GEN */
  20721. out:
  20722. #ifdef WOLFSSL_KEY_GEN
  20723. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20724. #endif
  20725. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20726. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20727. if (key) {
  20728. if (key_inited)
  20729. wc_FreeDsaKey(key);
  20730. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20731. }
  20732. #ifdef WOLFSSL_KEY_GEN
  20733. if (derIn) {
  20734. if (derIn_inited)
  20735. wc_FreeDsaKey(derIn);
  20736. XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20737. }
  20738. if (genKey) {
  20739. if (genKey_inited)
  20740. wc_FreeDsaKey(genKey);
  20741. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20742. }
  20743. #endif
  20744. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  20745. if (key_inited)
  20746. wc_FreeDsaKey(key);
  20747. #ifdef WOLFSSL_KEY_GEN
  20748. if (derIn_inited)
  20749. wc_FreeDsaKey(derIn);
  20750. if (genKey_inited)
  20751. wc_FreeDsaKey(genKey);
  20752. #endif
  20753. #endif
  20754. if (rng_inited)
  20755. wc_FreeRng(&rng);
  20756. return ret;
  20757. }
  20758. #endif /* NO_DSA */
  20759. #ifdef WOLFCRYPT_HAVE_SRP
  20760. static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
  20761. {
  20762. wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
  20763. WC_RNG rng;
  20764. if(NULL == buf || !size)
  20765. return WC_TEST_RET_ENC_NC;
  20766. if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) {
  20767. ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size);
  20768. wc_FreeRng(&rng);
  20769. }
  20770. return ret;
  20771. }
  20772. static wc_test_ret_t srp_test_digest(SrpType dgstType)
  20773. {
  20774. wc_test_ret_t r;
  20775. byte clientPubKey[192]; /* A */
  20776. byte serverPubKey[192]; /* B */
  20777. word32 clientPubKeySz = 192;
  20778. word32 serverPubKeySz = 192;
  20779. byte username[] = "user";
  20780. word32 usernameSz = 4;
  20781. byte password[] = "password";
  20782. word32 passwordSz = 8;
  20783. WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
  20784. 0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
  20785. 0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
  20786. 0x7a, 0xe9, 0x1f, 0x85, 0x36, 0x18, 0xc4, 0x35,
  20787. 0x3f, 0xf8, 0x8a, 0x8f, 0x8c, 0x10, 0x2e, 0x01,
  20788. 0x58, 0x1d, 0x41, 0xcb, 0xc4, 0x47, 0xa8, 0xaf,
  20789. 0x9a, 0x6f, 0x58, 0x14, 0xa4, 0x68, 0xf0, 0x9c,
  20790. 0xa6, 0xe7, 0xbf, 0x0d, 0xe9, 0x62, 0x0b, 0xd7,
  20791. 0x26, 0x46, 0x5b, 0x27, 0xcb, 0x4c, 0xf9, 0x7e,
  20792. 0x1e, 0x8b, 0xe6, 0xdd, 0x29, 0xb7, 0xb7, 0x15,
  20793. 0x2e, 0xcf, 0x23, 0xa6, 0x4b, 0x97, 0x9f, 0x89,
  20794. 0xd4, 0x86, 0xc4, 0x90, 0x63, 0x92, 0xf4, 0x30,
  20795. 0x26, 0x69, 0x48, 0x9d, 0x7a, 0x4f, 0xad, 0xb5,
  20796. 0x6a, 0x51, 0xad, 0xeb, 0xf9, 0x90, 0x31, 0x77,
  20797. 0x53, 0x30, 0x2a, 0x85, 0xf7, 0x11, 0x21, 0x0c,
  20798. 0xb8, 0x4b, 0x56, 0x03, 0x5e, 0xbb, 0x25, 0x33,
  20799. 0x7c, 0xd9, 0x5a, 0xd1, 0x5c, 0xb2, 0xd4, 0x53,
  20800. 0xc5, 0x16, 0x68, 0xf0, 0xdf, 0x48, 0x55, 0x3e,
  20801. 0xd4, 0x59, 0x87, 0x64, 0x59, 0xaa, 0x39, 0x01,
  20802. 0x45, 0x89, 0x9c, 0x72, 0xff, 0xdd, 0x8f, 0x6d,
  20803. 0xa0, 0x42, 0xbc, 0x6f, 0x6e, 0x62, 0x18, 0x2d,
  20804. 0x50, 0xe8, 0x18, 0x97, 0x87, 0xfc, 0xef, 0x1f,
  20805. 0xf5, 0x53, 0x68, 0xe8, 0x49, 0xd1, 0xa2, 0xe8,
  20806. 0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
  20807. 0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
  20808. };
  20809. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  20810. 0x02
  20811. };
  20812. byte salt[10];
  20813. byte verifier[192];
  20814. word32 v_size = sizeof(verifier);
  20815. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  20816. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  20817. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20818. Srp *cli = (Srp *)XMALLOC(sizeof *cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20819. Srp *srv = (Srp *)XMALLOC(sizeof *srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20820. byte *clientProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20821. DYNAMIC_TYPE_TMP_BUFFER); /* M1 */
  20822. byte *serverProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20823. DYNAMIC_TYPE_TMP_BUFFER); /* M2 */
  20824. if ((cli == NULL) ||
  20825. (srv == NULL) ||
  20826. (clientProof == NULL) ||
  20827. (serverProof == NULL)) {
  20828. r = WC_TEST_RET_ENC_NC;
  20829. goto out;
  20830. }
  20831. #else
  20832. Srp cli[1], srv[1];
  20833. byte clientProof[SRP_MAX_DIGEST_SIZE]; /* M1 */
  20834. byte serverProof[SRP_MAX_DIGEST_SIZE]; /* M2 */
  20835. #endif
  20836. /* set as 0's so if second init on srv not called SrpTerm is not on
  20837. * garbage values */
  20838. XMEMSET(srv, 0, sizeof *srv);
  20839. XMEMSET(cli, 0, sizeof *cli);
  20840. /* generating random salt */
  20841. r = generate_random_salt(salt, sizeof(salt));
  20842. /* client knows username and password. */
  20843. /* server knows N, g, salt and verifier. */
  20844. if (!r) r = wc_SrpInit_ex(cli, dgstType, SRP_CLIENT_SIDE, HEAP_HINT, devId);
  20845. if (!r) r = wc_SrpSetUsername(cli, username, usernameSz);
  20846. /* loading N, g and salt in advance to generate the verifier. */
  20847. if (!r) r = wc_SrpSetParams(cli, N, sizeof(N),
  20848. g, sizeof(g),
  20849. salt, sizeof(salt));
  20850. if (!r) r = wc_SrpSetPassword(cli, password, passwordSz);
  20851. if (!r) r = wc_SrpGetVerifier(cli, verifier, &v_size);
  20852. /* client sends username to server */
  20853. if (!r) r = wc_SrpInit_ex(srv, dgstType, SRP_SERVER_SIDE, HEAP_HINT, devId);
  20854. if (!r) r = wc_SrpSetUsername(srv, username, usernameSz);
  20855. if (!r) r = wc_SrpSetParams(srv, N, sizeof(N),
  20856. g, sizeof(g),
  20857. salt, sizeof(salt));
  20858. if (!r) r = wc_SrpSetVerifier(srv, verifier, v_size);
  20859. if (!r) r = wc_SrpGetPublic(srv, serverPubKey, &serverPubKeySz);
  20860. /* server sends N, g, salt and B to client */
  20861. if (!r) r = wc_SrpGetPublic(cli, clientPubKey, &clientPubKeySz);
  20862. if (!r) r = wc_SrpComputeKey(cli, clientPubKey, clientPubKeySz,
  20863. serverPubKey, serverPubKeySz);
  20864. if (!r) r = wc_SrpGetProof(cli, clientProof, &clientProofSz);
  20865. /* client sends A and M1 to server */
  20866. if (!r) r = wc_SrpComputeKey(srv, clientPubKey, clientPubKeySz,
  20867. serverPubKey, serverPubKeySz);
  20868. if (!r) r = wc_SrpVerifyPeersProof(srv, clientProof, clientProofSz);
  20869. if (!r) r = wc_SrpGetProof(srv, serverProof, &serverProofSz);
  20870. /* server sends M2 to client */
  20871. if (!r) r = wc_SrpVerifyPeersProof(cli, serverProof, serverProofSz);
  20872. wc_SrpTerm(cli);
  20873. wc_SrpTerm(srv);
  20874. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20875. out:
  20876. XFREE(cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20877. XFREE(srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20878. XFREE(clientProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20879. XFREE(serverProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20880. #endif
  20881. return r;
  20882. }
  20883. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
  20884. {
  20885. wc_test_ret_t ret;
  20886. WOLFSSL_ENTER("srp_test");
  20887. #ifndef NO_SHA
  20888. ret = srp_test_digest(SRP_TYPE_SHA);
  20889. if (ret != 0)
  20890. return ret;
  20891. #endif
  20892. #ifndef NO_SHA256
  20893. ret = srp_test_digest(SRP_TYPE_SHA256);
  20894. if (ret != 0)
  20895. return ret;
  20896. #endif
  20897. #ifdef WOLFSSL_SHA384
  20898. ret = srp_test_digest(SRP_TYPE_SHA384);
  20899. if (ret != 0)
  20900. return ret;
  20901. #endif
  20902. #ifdef WOLFSSL_SHA512
  20903. ret = srp_test_digest(SRP_TYPE_SHA512);
  20904. if (ret != 0)
  20905. return ret;
  20906. #endif
  20907. return ret;
  20908. }
  20909. #endif /* WOLFCRYPT_HAVE_SRP */
  20910. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  20911. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  20912. static wc_test_ret_t openssl_aes_test(void)
  20913. {
  20914. #ifdef HAVE_AES_CBC
  20915. #ifdef WOLFSSL_AES_128
  20916. {
  20917. /* EVP_CipherUpdate test */
  20918. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  20919. {
  20920. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  20921. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  20922. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  20923. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  20924. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  20925. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  20926. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  20927. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  20928. };
  20929. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  20930. "0123456789abcdef "; /* align */
  20931. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  20932. "1234567890abcdef "; /* align */
  20933. byte cipher[AES_BLOCK_SIZE * 4];
  20934. byte plain [AES_BLOCK_SIZE * 4];
  20935. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20936. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  20937. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  20938. #else
  20939. EVP_CIPHER_CTX en[1];
  20940. EVP_CIPHER_CTX de[1];
  20941. #endif
  20942. int outlen ;
  20943. int total = 0;
  20944. int i;
  20945. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20946. if ((en == NULL) || (de == NULL))
  20947. return MEMORY_E;
  20948. #endif
  20949. EVP_CIPHER_CTX_init(en);
  20950. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  20951. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  20952. return WC_TEST_RET_ENC_NC;
  20953. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  20954. (byte*)cbcPlain, 9) == 0)
  20955. return WC_TEST_RET_ENC_NC;
  20956. if (outlen != 0)
  20957. return WC_TEST_RET_ENC_NC;
  20958. total += outlen;
  20959. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  20960. (byte*)&cbcPlain[9] , 9) == 0)
  20961. return WC_TEST_RET_ENC_NC;
  20962. if (outlen != 16)
  20963. return WC_TEST_RET_ENC_NC;
  20964. total += outlen;
  20965. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  20966. return WC_TEST_RET_ENC_NC;
  20967. if (outlen != 16)
  20968. return WC_TEST_RET_ENC_NC;
  20969. total += outlen;
  20970. if (total != 32)
  20971. return 3408;
  20972. EVP_CIPHER_CTX_cleanup(en);
  20973. total = 0;
  20974. EVP_CIPHER_CTX_init(de);
  20975. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  20976. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  20977. return WC_TEST_RET_ENC_NC;
  20978. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  20979. return WC_TEST_RET_ENC_NC;
  20980. if (outlen != 0)
  20981. return WC_TEST_RET_ENC_NC;
  20982. total += outlen;
  20983. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  20984. (byte*)&cipher[6], 12) == 0)
  20985. return WC_TEST_RET_ENC_NC;
  20986. if (outlen != 0)
  20987. total += outlen;
  20988. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  20989. (byte*)&cipher[6+12], 14) == 0)
  20990. return WC_TEST_RET_ENC_NC;
  20991. if (outlen != 16)
  20992. return WC_TEST_RET_ENC_NC;
  20993. total += outlen;
  20994. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  20995. return WC_TEST_RET_ENC_NC;
  20996. if (outlen != 2)
  20997. return WC_TEST_RET_ENC_NC;
  20998. total += outlen;
  20999. if (total != 18)
  21000. return 3427;
  21001. if (XMEMCMP(plain, cbcPlain, 18))
  21002. return WC_TEST_RET_ENC_NC;
  21003. EVP_CIPHER_CTX_cleanup(de);
  21004. /* test with encrypting/decrypting more than 16 bytes at once */
  21005. total = 0;
  21006. EVP_CIPHER_CTX_init(en);
  21007. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21008. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21009. return WC_TEST_RET_ENC_NC;
  21010. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21011. (byte*)cbcPlain, 17) == 0)
  21012. return WC_TEST_RET_ENC_NC;
  21013. if (outlen != 16)
  21014. return WC_TEST_RET_ENC_NC;
  21015. total += outlen;
  21016. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21017. (byte*)&cbcPlain[17] , 1) == 0)
  21018. return WC_TEST_RET_ENC_NC;
  21019. if (outlen != 0)
  21020. return WC_TEST_RET_ENC_NC;
  21021. total += outlen;
  21022. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21023. return WC_TEST_RET_ENC_NC;
  21024. if (outlen != 16)
  21025. return WC_TEST_RET_ENC_NC;
  21026. total += outlen;
  21027. if (total != 32)
  21028. return WC_TEST_RET_ENC_NC;
  21029. EVP_CIPHER_CTX_cleanup(en);
  21030. total = 0;
  21031. EVP_CIPHER_CTX_init(de);
  21032. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21033. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21034. return WC_TEST_RET_ENC_NC;
  21035. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0)
  21036. return WC_TEST_RET_ENC_NC;
  21037. if (outlen != 16)
  21038. return WC_TEST_RET_ENC_NC;
  21039. total += outlen;
  21040. /* final call on non block size should fail */
  21041. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21042. return WC_TEST_RET_ENC_NC;
  21043. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21044. (byte*)&cipher[17], 1) == 0)
  21045. return WC_TEST_RET_ENC_NC;
  21046. if (outlen != 0)
  21047. total += outlen;
  21048. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21049. (byte*)&cipher[17+1], 14) == 0)
  21050. return WC_TEST_RET_ENC_NC;
  21051. if (outlen != 0)
  21052. return WC_TEST_RET_ENC_NC;
  21053. total += outlen;
  21054. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21055. return WC_TEST_RET_ENC_NC;
  21056. if (outlen != 2)
  21057. return WC_TEST_RET_ENC_NC;
  21058. total += outlen;
  21059. if (total != 18)
  21060. return WC_TEST_RET_ENC_NC;
  21061. if (XMEMCMP(plain, cbcPlain, 18))
  21062. return WC_TEST_RET_ENC_NC;
  21063. /* test byte by byte decrypt */
  21064. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21065. plain[i] = i;
  21066. }
  21067. EVP_CIPHER_CTX_cleanup(de);
  21068. total = 0;
  21069. EVP_CIPHER_CTX_init(en);
  21070. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21071. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21072. return WC_TEST_RET_ENC_NC;
  21073. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21074. (byte*)plain, AES_BLOCK_SIZE * 3) == 0)
  21075. return WC_TEST_RET_ENC_NC;
  21076. if (outlen != AES_BLOCK_SIZE * 3)
  21077. return WC_TEST_RET_ENC_NC;
  21078. total += outlen;
  21079. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21080. return WC_TEST_RET_ENC_NC;
  21081. if (outlen != AES_BLOCK_SIZE)
  21082. return WC_TEST_RET_ENC_NC;
  21083. total += outlen;
  21084. if (total != sizeof(plain))
  21085. return WC_TEST_RET_ENC_NC;
  21086. EVP_CIPHER_CTX_cleanup(en);
  21087. total = 0;
  21088. EVP_CIPHER_CTX_init(de);
  21089. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21090. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21091. return WC_TEST_RET_ENC_NC;
  21092. for (i = 0; i < AES_BLOCK_SIZE * 4; i++) {
  21093. if (EVP_CipherUpdate(de, (byte*)plain + total, &outlen,
  21094. (byte*)cipher + i, 1) == 0)
  21095. return WC_TEST_RET_ENC_NC;
  21096. if (outlen > 0) {
  21097. int j;
  21098. total += outlen;
  21099. for (j = 0; j < total; j++) {
  21100. if (plain[j] != j) {
  21101. return WC_TEST_RET_ENC_NC;
  21102. }
  21103. }
  21104. }
  21105. }
  21106. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21107. return WC_TEST_RET_ENC_NC;
  21108. total += outlen;
  21109. if (total != AES_BLOCK_SIZE * 3) {
  21110. return WC_TEST_RET_ENC_NC;
  21111. }
  21112. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21113. if (plain[i] != i) {
  21114. return WC_TEST_RET_ENC_NC;
  21115. }
  21116. }
  21117. EVP_CIPHER_CTX_cleanup(de);
  21118. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21119. wolfSSL_EVP_CIPHER_CTX_free(en);
  21120. wolfSSL_EVP_CIPHER_CTX_free(de);
  21121. #endif
  21122. }
  21123. /* set buffers to be exact size to catch potential over read/write */
  21124. {
  21125. /* EVP_CipherUpdate test */
  21126. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21127. {
  21128. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21129. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21130. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21131. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21132. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21133. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21134. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21135. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21136. };
  21137. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21138. "0123456789abcdef "; /* align */
  21139. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21140. "1234567890abcdef "; /* align */
  21141. #define EVP_TEST_BUF_SZ 18
  21142. #define EVP_TEST_BUF_PAD 32
  21143. byte cipher[EVP_TEST_BUF_SZ];
  21144. byte plain [EVP_TEST_BUF_SZ];
  21145. byte padded[EVP_TEST_BUF_PAD];
  21146. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21147. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21148. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21149. #else
  21150. EVP_CIPHER_CTX en[1];
  21151. EVP_CIPHER_CTX de[1];
  21152. #endif
  21153. int outlen ;
  21154. int total = 0;
  21155. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21156. if ((en == NULL) || (de == NULL))
  21157. return MEMORY_E;
  21158. #endif
  21159. EVP_CIPHER_CTX_init(en);
  21160. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21161. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21162. return WC_TEST_RET_ENC_NC;
  21163. if (EVP_CIPHER_CTX_set_padding(en, 0) != 1)
  21164. return WC_TEST_RET_ENC_NC;
  21165. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21166. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21167. return WC_TEST_RET_ENC_NC;
  21168. if (outlen != 16)
  21169. return WC_TEST_RET_ENC_NC;
  21170. total += outlen;
  21171. /* should fail here */
  21172. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0)
  21173. return WC_TEST_RET_ENC_NC;
  21174. EVP_CIPHER_CTX_cleanup(en);
  21175. /* turn padding back on and do successful encrypt */
  21176. total = 0;
  21177. EVP_CIPHER_CTX_init(en);
  21178. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21179. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21180. return WC_TEST_RET_ENC_NC;
  21181. if (EVP_CIPHER_CTX_set_padding(en, 1) != 1)
  21182. return WC_TEST_RET_ENC_NC;
  21183. if (EVP_CipherUpdate(en, (byte*)padded, &outlen,
  21184. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21185. return WC_TEST_RET_ENC_NC;
  21186. if (outlen != 16)
  21187. return WC_TEST_RET_ENC_NC;
  21188. total += outlen;
  21189. if (EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0)
  21190. return WC_TEST_RET_ENC_NC;
  21191. total += outlen;
  21192. if (total != 32)
  21193. return WC_TEST_RET_ENC_NC;
  21194. XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ);
  21195. EVP_CIPHER_CTX_cleanup(en);
  21196. /* test out of bounds read on buffers w/o padding during decryption */
  21197. total = 0;
  21198. EVP_CIPHER_CTX_init(de);
  21199. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21200. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21201. return WC_TEST_RET_ENC_NC;
  21202. if (EVP_CIPHER_CTX_set_padding(de, 0) != 1)
  21203. return WC_TEST_RET_ENC_NC;
  21204. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher,
  21205. EVP_TEST_BUF_SZ) == 0)
  21206. return WC_TEST_RET_ENC_NC;
  21207. if (outlen != 16)
  21208. return WC_TEST_RET_ENC_NC;
  21209. total += outlen;
  21210. /* should fail since not using padding */
  21211. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21212. return WC_TEST_RET_ENC_NC;
  21213. EVP_CIPHER_CTX_cleanup(de);
  21214. total = 0;
  21215. EVP_CIPHER_CTX_init(de);
  21216. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21217. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21218. return WC_TEST_RET_ENC_NC;
  21219. if (EVP_CIPHER_CTX_set_padding(de, 1) != 1)
  21220. return WC_TEST_RET_ENC_NC;
  21221. if (EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded,
  21222. EVP_TEST_BUF_PAD) == 0)
  21223. return WC_TEST_RET_ENC_NC;
  21224. if (outlen != 16)
  21225. return WC_TEST_RET_ENC_NC;
  21226. total += outlen;
  21227. if (EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0)
  21228. return WC_TEST_RET_ENC_NC;
  21229. if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ))
  21230. return WC_TEST_RET_ENC_NC;
  21231. EVP_CIPHER_CTX_cleanup(de);
  21232. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21233. wolfSSL_EVP_CIPHER_CTX_free(en);
  21234. wolfSSL_EVP_CIPHER_CTX_free(de);
  21235. #endif
  21236. }
  21237. { /* evp_cipher test: EVP_aes_128_cbc */
  21238. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21239. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21240. #else
  21241. EVP_CIPHER_CTX ctx[1];
  21242. #endif
  21243. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  21244. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  21245. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  21246. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  21247. };
  21248. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21249. {
  21250. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  21251. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  21252. };
  21253. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21254. "0123456789abcdef "; /* align */
  21255. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21256. "1234567890abcdef "; /* align */
  21257. byte cipher[AES_BLOCK_SIZE * 4];
  21258. byte plain [AES_BLOCK_SIZE * 4];
  21259. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21260. if (ctx == NULL)
  21261. return MEMORY_E;
  21262. #endif
  21263. EVP_CIPHER_CTX_init(ctx);
  21264. if (EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 1) == 0)
  21265. return WC_TEST_RET_ENC_NC;
  21266. if (EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21267. return WC_TEST_RET_ENC_NC;
  21268. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21269. return WC_TEST_RET_ENC_NC;
  21270. EVP_CIPHER_CTX_cleanup(ctx);
  21271. EVP_CIPHER_CTX_init(ctx);
  21272. if (EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0) == 0)
  21273. return WC_TEST_RET_ENC_NC;
  21274. if (EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21275. return WC_TEST_RET_ENC_NC;
  21276. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21277. return WC_TEST_RET_ENC_NC;
  21278. EVP_CIPHER_CTX_cleanup(ctx);
  21279. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21280. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21281. #endif
  21282. } /* end evp_cipher test: EVP_aes_128_cbc*/
  21283. #endif /* WOLFSSL_AES_128 */
  21284. #endif /* HAVE_AES_CBC */
  21285. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21286. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  21287. { /* evp_cipher test: EVP_aes_256_ecb*/
  21288. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21289. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21290. #else
  21291. EVP_CIPHER_CTX ctx[1];
  21292. #endif
  21293. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21294. {
  21295. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21296. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21297. };
  21298. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21299. {
  21300. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21301. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21302. };
  21303. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21304. {
  21305. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21306. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21307. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21308. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21309. };
  21310. byte cipher[AES_BLOCK_SIZE * 4];
  21311. byte plain [AES_BLOCK_SIZE * 4];
  21312. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21313. if (ctx == NULL)
  21314. return MEMORY_E;
  21315. #endif
  21316. EVP_CIPHER_CTX_init(ctx);
  21317. if (EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0)
  21318. return WC_TEST_RET_ENC_NC;
  21319. if (EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21320. return WC_TEST_RET_ENC_NC;
  21321. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21322. return WC_TEST_RET_ENC_NC;
  21323. EVP_CIPHER_CTX_init(ctx);
  21324. if (EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0)
  21325. return WC_TEST_RET_ENC_NC;
  21326. if (EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21327. return WC_TEST_RET_ENC_NC;
  21328. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21329. return WC_TEST_RET_ENC_NC;
  21330. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21331. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21332. #endif
  21333. } /* end evp_cipher test */
  21334. #endif /* HAVE_AES_ECB && WOLFSSL_AES_256 */
  21335. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  21336. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  21337. {
  21338. /* Test: AES_encrypt/decrypt/set Key */
  21339. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21340. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21341. #ifdef HAVE_AES_DECRYPT
  21342. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21343. #endif
  21344. #else
  21345. AES_KEY enc[1];
  21346. #ifdef HAVE_AES_DECRYPT
  21347. AES_KEY dec[1];
  21348. #endif
  21349. #endif
  21350. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21351. {
  21352. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21353. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21354. };
  21355. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21356. {
  21357. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21358. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21359. };
  21360. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21361. {
  21362. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21363. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21364. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21365. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21366. };
  21367. byte plain[sizeof(msg)];
  21368. byte cipher[sizeof(msg)];
  21369. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21370. if (enc == NULL)
  21371. return MEMORY_E;
  21372. #ifdef HAVE_AES_DECRYPT
  21373. if (dec == NULL)
  21374. return MEMORY_E;
  21375. #endif
  21376. #endif
  21377. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  21378. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  21379. AES_encrypt(msg, cipher, enc);
  21380. #ifdef HAVE_AES_DECRYPT
  21381. AES_decrypt(cipher, plain, dec);
  21382. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21383. return WC_TEST_RET_ENC_NC;
  21384. #endif /* HAVE_AES_DECRYPT */
  21385. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21386. return WC_TEST_RET_ENC_NC;
  21387. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21388. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21389. #ifdef HAVE_AES_DECRYPT
  21390. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21391. #endif
  21392. #endif
  21393. }
  21394. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  21395. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21396. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  21397. #ifdef WOLFSSL_AES_COUNTER
  21398. {
  21399. byte plainBuff [64];
  21400. byte cipherBuff[64];
  21401. #ifdef WOLFSSL_AES_128
  21402. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  21403. {
  21404. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21405. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21406. };
  21407. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  21408. {
  21409. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21410. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21411. };
  21412. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  21413. {
  21414. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21415. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21416. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21417. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21418. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21419. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21420. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21421. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21422. };
  21423. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  21424. {
  21425. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  21426. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  21427. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  21428. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  21429. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  21430. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  21431. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  21432. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  21433. };
  21434. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  21435. {
  21436. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  21437. 0xc2
  21438. };
  21439. #endif
  21440. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21441. * NIST Special Publication 800-38A */
  21442. #ifdef WOLFSSL_AES_192
  21443. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  21444. {
  21445. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  21446. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  21447. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  21448. };
  21449. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  21450. {
  21451. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21452. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21453. };
  21454. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  21455. {
  21456. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21457. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21458. };
  21459. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  21460. {
  21461. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  21462. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  21463. };
  21464. #endif /* WOLFSSL_AES_192 */
  21465. #ifdef WOLFSSL_AES_256
  21466. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21467. * NIST Special Publication 800-38A */
  21468. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  21469. {
  21470. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21471. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21472. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21473. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21474. };
  21475. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  21476. {
  21477. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21478. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21479. };
  21480. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  21481. {
  21482. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21483. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21484. };
  21485. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  21486. {
  21487. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  21488. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  21489. };
  21490. #endif /* WOLFSSL_AES_256 */
  21491. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21492. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21493. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21494. #else
  21495. EVP_CIPHER_CTX en[1];
  21496. EVP_CIPHER_CTX de[1];
  21497. #endif
  21498. #ifdef WOLFSSL_AES_128
  21499. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21500. EVP_CIPHER_CTX *p_en;
  21501. EVP_CIPHER_CTX *p_de;
  21502. #endif
  21503. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21504. if ((en == NULL) || (de == NULL))
  21505. return MEMORY_E;
  21506. #endif
  21507. EVP_CIPHER_CTX_init(en);
  21508. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  21509. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21510. return WC_TEST_RET_ENC_NC;
  21511. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  21512. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21513. return WC_TEST_RET_ENC_NC;
  21514. EVP_CIPHER_CTX_init(de);
  21515. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  21516. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21517. return WC_TEST_RET_ENC_NC;
  21518. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21519. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21520. return WC_TEST_RET_ENC_NC;
  21521. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21522. return WC_TEST_RET_ENC_NC;
  21523. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21524. return WC_TEST_RET_ENC_NC;
  21525. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21526. return WC_TEST_RET_ENC_NC;
  21527. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21528. return WC_TEST_RET_ENC_NC;
  21529. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21530. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  21531. if (p_en == NULL)
  21532. return WC_TEST_RET_ENC_ERRNO;
  21533. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  21534. if (p_de == NULL)
  21535. return WC_TEST_RET_ENC_ERRNO;
  21536. if (EVP_CipherInit(p_en, EVP_aes_128_ctr(),
  21537. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21538. return WC_TEST_RET_ENC_NC;
  21539. if (EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  21540. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21541. return WC_TEST_RET_ENC_NC;
  21542. if (EVP_CipherInit(p_de, EVP_aes_128_ctr(),
  21543. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21544. return WC_TEST_RET_ENC_NC;
  21545. if (EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  21546. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21547. return WC_TEST_RET_ENC_NC;
  21548. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21549. return WC_TEST_RET_ENC_NC;
  21550. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21551. return WC_TEST_RET_ENC_NC;
  21552. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  21553. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  21554. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  21555. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21556. return WC_TEST_RET_ENC_NC;
  21557. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21558. return WC_TEST_RET_ENC_NC;
  21559. EVP_CIPHER_CTX_init(en);
  21560. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  21561. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21562. return WC_TEST_RET_ENC_NC;
  21563. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21564. return WC_TEST_RET_ENC_NC;
  21565. EVP_CIPHER_CTX_init(de);
  21566. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  21567. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21568. return WC_TEST_RET_ENC_NC;
  21569. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21570. return WC_TEST_RET_ENC_NC;
  21571. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21572. return WC_TEST_RET_ENC_NC;
  21573. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  21574. return WC_TEST_RET_ENC_NC;
  21575. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21576. return WC_TEST_RET_ENC_NC;
  21577. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21578. return WC_TEST_RET_ENC_NC;
  21579. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21580. return WC_TEST_RET_ENC_NC;
  21581. if (XMEMCMP(cipherBuff, oddCipher, 9))
  21582. return WC_TEST_RET_ENC_NC;
  21583. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21584. return WC_TEST_RET_ENC_NC;
  21585. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21586. return WC_TEST_RET_ENC_NC;
  21587. #endif /* WOLFSSL_AES_128 */
  21588. #ifdef WOLFSSL_AES_192
  21589. EVP_CIPHER_CTX_init(en);
  21590. if (EVP_CipherInit(en, EVP_aes_192_ctr(),
  21591. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21592. return WC_TEST_RET_ENC_NC;
  21593. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  21594. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21595. return WC_TEST_RET_ENC_NC;
  21596. EVP_CIPHER_CTX_init(de);
  21597. if (EVP_CipherInit(de, EVP_aes_192_ctr(),
  21598. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21599. return WC_TEST_RET_ENC_NC;
  21600. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21601. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21602. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21603. return WC_TEST_RET_ENC_NC;
  21604. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  21605. return WC_TEST_RET_ENC_NC;
  21606. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  21607. return WC_TEST_RET_ENC_NC;
  21608. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21609. return WC_TEST_RET_ENC_NC;
  21610. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21611. return WC_TEST_RET_ENC_NC;
  21612. #endif /* WOLFSSL_AES_192 */
  21613. #ifdef WOLFSSL_AES_256
  21614. EVP_CIPHER_CTX_init(en);
  21615. if (EVP_CipherInit(en, EVP_aes_256_ctr(),
  21616. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21617. return WC_TEST_RET_ENC_NC;
  21618. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  21619. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21620. return WC_TEST_RET_ENC_NC;
  21621. EVP_CIPHER_CTX_init(de);
  21622. if (EVP_CipherInit(de, EVP_aes_256_ctr(),
  21623. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21624. return WC_TEST_RET_ENC_NC;
  21625. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21626. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21627. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21628. return WC_TEST_RET_ENC_NC;
  21629. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  21630. return WC_TEST_RET_ENC_NC;
  21631. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  21632. return WC_TEST_RET_ENC_NC;
  21633. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21634. return WC_TEST_RET_ENC_NC;
  21635. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21636. return WC_TEST_RET_ENC_NC;
  21637. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21638. wolfSSL_EVP_CIPHER_CTX_free(en);
  21639. wolfSSL_EVP_CIPHER_CTX_free(de);
  21640. #endif
  21641. #endif /* WOLFSSL_AES_256 */
  21642. }
  21643. #endif /* HAVE_AES_COUNTER */
  21644. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21645. #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128)
  21646. {
  21647. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21648. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21649. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21650. #else
  21651. AES_KEY enc[1];
  21652. AES_KEY dec[1];
  21653. #endif
  21654. WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = {
  21655. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  21656. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  21657. };
  21658. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21659. {
  21660. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21661. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21662. };
  21663. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  21664. {
  21665. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  21666. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  21667. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  21668. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b
  21669. };
  21670. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21671. {
  21672. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21673. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21674. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21675. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51
  21676. };
  21677. byte cipher[AES_BLOCK_SIZE * 2];
  21678. byte iv[AES_BLOCK_SIZE]; /* iv buffer is updeated by API */
  21679. int num = 0;
  21680. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21681. if ((enc == NULL) || (dec == NULL))
  21682. return MEMORY_E;
  21683. #endif
  21684. XMEMCPY(iv, setIv, sizeof(setIv));
  21685. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc);
  21686. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec);
  21687. wolfSSL_AES_cfb128_encrypt(msg, cipher, AES_BLOCK_SIZE - 1, enc, iv,
  21688. &num, AES_ENCRYPT);
  21689. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE - 1))
  21690. return WC_TEST_RET_ENC_NC;
  21691. if (num != 15) /* should have used 15 of the 16 bytes */
  21692. return WC_TEST_RET_ENC_NC;
  21693. wolfSSL_AES_cfb128_encrypt(msg + AES_BLOCK_SIZE - 1,
  21694. cipher + AES_BLOCK_SIZE - 1, AES_BLOCK_SIZE + 1, enc, iv,
  21695. &num, AES_ENCRYPT);
  21696. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  21697. return WC_TEST_RET_ENC_NC;
  21698. if (num != 0)
  21699. return WC_TEST_RET_ENC_NC;
  21700. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21701. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21702. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21703. #endif
  21704. }
  21705. #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */
  21706. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21707. return 0;
  21708. }
  21709. #endif /* !defined(NO_AES) && !defined(WOLFCRYPT_ONLY) */
  21710. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void)
  21711. {
  21712. wc_test_ret_t ret;
  21713. #ifdef WOLFSSL_SMALL_STACK
  21714. EVP_MD_CTX *md_ctx = (EVP_MD_CTX *)XMALLOC(sizeof(EVP_MD_CTX), NULL, DYNAMIC_TYPE_OPENSSL);
  21715. #else
  21716. EVP_MD_CTX md_ctx[1];
  21717. #endif
  21718. testVector a, b, c, d, e, f;
  21719. byte hash[WC_SHA256_DIGEST_SIZE*2]; /* max size */
  21720. #ifdef WOLFSSL_SMALL_STACK
  21721. if (md_ctx == NULL)
  21722. return WC_TEST_RET_ENC_EC(MEMORY_E);
  21723. #endif
  21724. WOLFSSL_ENTER("openssl_test");
  21725. a.inLen = 0;
  21726. b.inLen = c.inLen = d.inLen = e.inLen = f.inLen = a.inLen;
  21727. (void)a;
  21728. (void)b;
  21729. (void)c;
  21730. (void)d;
  21731. (void)e;
  21732. (void)f;
  21733. /* test malloc / free , 10 is an arbitrary amount of memory chosen */
  21734. {
  21735. byte* p;
  21736. p = (byte*)CRYPTO_malloc(10, "", 0);
  21737. if (p == NULL) {
  21738. return WC_TEST_RET_ENC_NC;
  21739. }
  21740. XMEMSET(p, 0, 10);
  21741. CRYPTO_free(p, "", 0);
  21742. }
  21743. #ifndef NO_MD5
  21744. a.input = "1234567890123456789012345678901234567890123456789012345678"
  21745. "9012345678901234567890";
  21746. a.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  21747. "\x7a";
  21748. a.inLen = XSTRLEN(a.input);
  21749. a.outLen = WC_MD5_DIGEST_SIZE;
  21750. EVP_MD_CTX_init(md_ctx);
  21751. ret = EVP_DigestInit(md_ctx, EVP_md5());
  21752. if (ret == WOLFSSL_SUCCESS) {
  21753. ret = EVP_DigestUpdate(md_ctx, a.input, (unsigned long)a.inLen);
  21754. }
  21755. if (ret == WOLFSSL_SUCCESS) {
  21756. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21757. }
  21758. EVP_MD_CTX_cleanup(md_ctx);
  21759. if (ret != WOLFSSL_SUCCESS)
  21760. return WC_TEST_RET_ENC_NC;
  21761. if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0)
  21762. return WC_TEST_RET_ENC_NC;
  21763. #endif /* NO_MD5 */
  21764. #ifndef NO_SHA
  21765. b.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21766. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21767. "aaaaaaaaaa";
  21768. b.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  21769. "\x53\x99\x5E\x26\xA0";
  21770. b.inLen = XSTRLEN(b.input);
  21771. b.outLen = WC_SHA_DIGEST_SIZE;
  21772. EVP_MD_CTX_init(md_ctx);
  21773. ret = EVP_DigestInit(md_ctx, EVP_sha1());
  21774. if (ret == WOLFSSL_SUCCESS) {
  21775. ret = EVP_DigestUpdate(md_ctx, b.input, (unsigned long)b.inLen);
  21776. if (ret == WOLFSSL_SUCCESS)
  21777. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21778. }
  21779. EVP_MD_CTX_cleanup(md_ctx);
  21780. if (ret != WOLFSSL_SUCCESS)
  21781. return WC_TEST_RET_ENC_NC;
  21782. if (XMEMCMP(hash, b.output, b.outLen) != 0)
  21783. return WC_TEST_RET_ENC_NC;
  21784. #endif /* NO_SHA */
  21785. #ifdef WOLFSSL_SHA224
  21786. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21787. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21788. e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
  21789. "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
  21790. e.inLen = XSTRLEN(e.input);
  21791. e.outLen = WC_SHA224_DIGEST_SIZE;
  21792. EVP_MD_CTX_init(md_ctx);
  21793. ret = EVP_DigestInit(md_ctx, EVP_sha224());
  21794. if (ret == WOLFSSL_SUCCESS) {
  21795. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21796. if (ret == WOLFSSL_SUCCESS)
  21797. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21798. }
  21799. EVP_MD_CTX_cleanup(md_ctx);
  21800. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21801. return WC_TEST_RET_ENC_NC;
  21802. }
  21803. #endif /* WOLFSSL_SHA224 */
  21804. #ifndef NO_SHA256
  21805. d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  21806. d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  21807. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  21808. "\x06\xC1";
  21809. d.inLen = XSTRLEN(d.input);
  21810. d.outLen = WC_SHA256_DIGEST_SIZE;
  21811. EVP_MD_CTX_init(md_ctx);
  21812. ret = EVP_DigestInit(md_ctx, EVP_sha256());
  21813. if (ret == WOLFSSL_SUCCESS) {
  21814. ret = EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21815. if (ret == WOLFSSL_SUCCESS)
  21816. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21817. }
  21818. EVP_MD_CTX_cleanup(md_ctx);
  21819. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21820. return WC_TEST_RET_ENC_NC;
  21821. }
  21822. #endif /* !NO_SHA256 */
  21823. #ifdef WOLFSSL_SHA384
  21824. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21825. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21826. e.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  21827. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  21828. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  21829. "\x74\x60\x39";
  21830. e.inLen = XSTRLEN(e.input);
  21831. e.outLen = WC_SHA384_DIGEST_SIZE;
  21832. EVP_MD_CTX_init(md_ctx);
  21833. ret = EVP_DigestInit(md_ctx, EVP_sha384());
  21834. if (ret == WOLFSSL_SUCCESS) {
  21835. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21836. if (ret == WOLFSSL_SUCCESS)
  21837. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21838. }
  21839. EVP_MD_CTX_cleanup(md_ctx);
  21840. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21841. return WC_TEST_RET_ENC_NC;
  21842. }
  21843. #endif /* WOLFSSL_SHA384 */
  21844. #ifdef WOLFSSL_SHA512
  21845. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21846. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21847. f.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  21848. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  21849. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  21850. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  21851. "\x87\x4b\xe9\x09";
  21852. f.inLen = XSTRLEN(f.input);
  21853. f.outLen = WC_SHA512_DIGEST_SIZE;
  21854. EVP_MD_CTX_init(md_ctx);
  21855. ret = EVP_DigestInit(md_ctx, EVP_sha512());
  21856. if (ret == WOLFSSL_SUCCESS) {
  21857. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21858. if (ret == WOLFSSL_SUCCESS)
  21859. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21860. }
  21861. EVP_MD_CTX_cleanup(md_ctx);
  21862. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21863. return WC_TEST_RET_ENC_NC;
  21864. }
  21865. #if !defined(WOLFSSL_NOSHA512_224) && \
  21866. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21867. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21868. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21869. f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45"
  21870. "\x33\x35\xd6\x64\x73\x4f\xe4\x0e\x72\x68\x67\x4a\xf9";
  21871. f.inLen = XSTRLEN(f.input);
  21872. f.outLen = WC_SHA512_224_DIGEST_SIZE;
  21873. EVP_MD_CTX_init(md_ctx);
  21874. ret = EVP_DigestInit(md_ctx, EVP_sha512_224());
  21875. if (ret == WOLFSSL_SUCCESS) {
  21876. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21877. if (ret == WOLFSSL_SUCCESS)
  21878. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21879. }
  21880. EVP_MD_CTX_cleanup(md_ctx);
  21881. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21882. return WC_TEST_RET_ENC_NC;
  21883. }
  21884. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  21885. #if !defined(WOLFSSL_NOSHA512_256) && \
  21886. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21887. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21888. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21889. f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31"
  21890. "\xbe\x65\xcb\x9d\x3e\xf8\x3e\xe6\x14\x6f\xea\xc8\x61\xe1\x9b"
  21891. "\x56\x3a";
  21892. f.inLen = XSTRLEN(f.input);
  21893. f.outLen = WC_SHA512_256_DIGEST_SIZE;
  21894. EVP_MD_CTX_init(md_ctx);
  21895. ret = EVP_DigestInit(md_ctx, EVP_sha512_256());
  21896. if (ret == WOLFSSL_SUCCESS) {
  21897. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21898. if (ret == WOLFSSL_SUCCESS)
  21899. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21900. }
  21901. EVP_MD_CTX_cleanup(md_ctx);
  21902. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21903. return WC_TEST_RET_ENC_NC;
  21904. }
  21905. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  21906. #endif /* WOLFSSL_SHA512 */
  21907. #ifdef WOLFSSL_SHA3
  21908. #ifndef WOLFSSL_NOSHA3_224
  21909. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21910. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21911. e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a"
  21912. "\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
  21913. e.inLen = XSTRLEN(e.input);
  21914. e.outLen = WC_SHA3_224_DIGEST_SIZE;
  21915. EVP_MD_CTX_init(md_ctx);
  21916. ret = EVP_DigestInit(md_ctx, EVP_sha3_224());
  21917. if (ret == WOLFSSL_SUCCESS) {
  21918. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21919. if (ret == WOLFSSL_SUCCESS)
  21920. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21921. }
  21922. EVP_MD_CTX_cleanup(md_ctx);
  21923. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21924. return WC_TEST_RET_ENC_NC;
  21925. }
  21926. #endif /* WOLFSSL_NOSHA3_224 */
  21927. #ifndef WOLFSSL_NOSHA3_256
  21928. d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21929. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21930. d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
  21931. "\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
  21932. "\x1d\x18";
  21933. d.inLen = XSTRLEN(d.input);
  21934. d.outLen = WC_SHA3_256_DIGEST_SIZE;
  21935. EVP_MD_CTX_init(md_ctx);
  21936. ret = EVP_DigestInit(md_ctx, EVP_sha3_256());
  21937. if (ret == WOLFSSL_SUCCESS) {
  21938. ret = EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21939. if (ret == WOLFSSL_SUCCESS)
  21940. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21941. }
  21942. EVP_MD_CTX_cleanup(md_ctx);
  21943. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21944. return WC_TEST_RET_ENC_NC;
  21945. }
  21946. #endif /* WOLFSSL_NOSHA3_256 */
  21947. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21948. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21949. e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47"
  21950. "\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6"
  21951. "\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79"
  21952. "\xaa\x7f\xc7";
  21953. e.inLen = XSTRLEN(e.input);
  21954. e.outLen = WC_SHA3_384_DIGEST_SIZE;
  21955. EVP_MD_CTX_init(md_ctx);
  21956. ret = EVP_DigestInit(md_ctx, EVP_sha3_384());
  21957. if (ret == WOLFSSL_SUCCESS) {
  21958. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21959. if (ret == WOLFSSL_SUCCESS)
  21960. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21961. }
  21962. EVP_MD_CTX_cleanup(md_ctx);
  21963. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21964. return WC_TEST_RET_ENC_NC;
  21965. }
  21966. #ifndef WOLFSSL_NOSHA3_512
  21967. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21968. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21969. f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78"
  21970. "\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18"
  21971. "\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8"
  21972. "\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55"
  21973. "\xf2\x1d\xd1\x85";
  21974. f.inLen = XSTRLEN(f.input);
  21975. f.outLen = WC_SHA3_512_DIGEST_SIZE;
  21976. EVP_MD_CTX_init(md_ctx);
  21977. ret = EVP_DigestInit(md_ctx, EVP_sha3_512());
  21978. if (ret == WOLFSSL_SUCCESS) {
  21979. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21980. if (ret == WOLFSSL_SUCCESS)
  21981. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21982. }
  21983. EVP_MD_CTX_cleanup(md_ctx);
  21984. if (ret != WOLFSSL_SUCCESS ||
  21985. XMEMCMP(hash, f.output, f.outLen) != 0) {
  21986. return WC_TEST_RET_ENC_NC;
  21987. }
  21988. #endif /* WOLFSSL_NOSHA3_512 */
  21989. #endif /* WOLFSSL_SHA3 */
  21990. #ifdef WOLFSSL_SMALL_STACK
  21991. XFREE(md_ctx, NULL, DYNAMIC_TYPE_OPENSSL);
  21992. md_ctx = NULL;
  21993. #endif
  21994. #ifndef WC_NO_RNG
  21995. if (RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS)
  21996. return WC_TEST_RET_ENC_NC;
  21997. #endif
  21998. #ifndef NO_MD5
  21999. c.input = "what do ya want for nothing?";
  22000. c.output = "\x55\x78\xe8\x48\x4b\xcc\x93\x80\x93\xec\x53\xaf\x22\xd6\x14"
  22001. "\x76";
  22002. c.inLen = XSTRLEN(c.input);
  22003. c.outLen = WC_MD5_DIGEST_SIZE;
  22004. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)
  22005. /* Expect failure with MD5 + HMAC when using FIPS 140-3. */
  22006. if (HMAC(EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22007. hash, 0) != NULL)
  22008. #else
  22009. if (HMAC(EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22010. hash, 0) == NULL ||
  22011. XMEMCMP(hash, c.output, c.outLen) != 0)
  22012. #endif
  22013. {
  22014. return WC_TEST_RET_ENC_NC;
  22015. }
  22016. #endif /* NO_MD5 */
  22017. #ifndef NO_DES3
  22018. { /* des test */
  22019. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  22020. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22021. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22022. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22023. };
  22024. byte plain[24];
  22025. byte cipher[24];
  22026. const_DES_cblock key = {
  22027. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  22028. };
  22029. DES_cblock iv = {
  22030. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  22031. };
  22032. DES_key_schedule sched;
  22033. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22034. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  22035. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  22036. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  22037. };
  22038. DES_key_sched(&key, &sched);
  22039. DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, DES_ENCRYPT);
  22040. DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, DES_DECRYPT);
  22041. if (XMEMCMP(plain, vector, sizeof(vector)) != 0)
  22042. return WC_TEST_RET_ENC_NC;
  22043. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22044. return WC_TEST_RET_ENC_NC;
  22045. /* test changing iv */
  22046. DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, DES_ENCRYPT);
  22047. DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, DES_ENCRYPT);
  22048. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22049. return WC_TEST_RET_ENC_NC;
  22050. } /* end des test */
  22051. #endif /* NO_DES3 */
  22052. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  22053. if ((ret = openssl_aes_test()) != 0) {
  22054. return ret;
  22055. }
  22056. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  22057. { /* evp_cipher test: EVP_aes_128_cbc */
  22058. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22059. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22060. #else
  22061. EVP_CIPHER_CTX ctx[1];
  22062. #endif
  22063. int idx, cipherSz, plainSz;
  22064. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  22065. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22066. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22067. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22068. };
  22069. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22070. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22071. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22072. 0x3b,0x5d,0x41,0x97,0x94,0x25,0xa4,0xb4,
  22073. 0xae,0x7b,0x34,0xd0,0x3f,0x0c,0xbc,0x06
  22074. };
  22075. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  22076. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22077. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22078. 0x7d,0x37,0x7b,0x0b,0x44,0xaa,0xb5,0xf0,
  22079. 0x5f,0x34,0xb4,0xde,0xb5,0xbd,0x2a,0xbb
  22080. };
  22081. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22082. "0123456789abcdef "; /* align */
  22083. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  22084. "1234567890abcdef "; /* align */
  22085. byte cipher[AES_BLOCK_SIZE * 4];
  22086. byte plain [AES_BLOCK_SIZE * 4];
  22087. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22088. if (ctx == NULL)
  22089. return MEMORY_E;
  22090. #endif
  22091. cipherSz = 0;
  22092. EVP_CIPHER_CTX_init(ctx);
  22093. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 1);
  22094. if (ret == WOLFSSL_SUCCESS) {
  22095. ret = EVP_CipherUpdate(ctx, cipher, &idx, (byte*)msg, sizeof(msg));
  22096. if (ret == WOLFSSL_SUCCESS)
  22097. cipherSz += idx;
  22098. }
  22099. if (ret == WOLFSSL_SUCCESS) {
  22100. ret = EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22101. if (ret == WOLFSSL_SUCCESS)
  22102. cipherSz += idx;
  22103. }
  22104. EVP_CIPHER_CTX_cleanup(ctx);
  22105. if (ret != WOLFSSL_SUCCESS)
  22106. return WC_TEST_RET_ENC_NC;
  22107. if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz))
  22108. return WC_TEST_RET_ENC_NC;
  22109. /* check partial decrypt (not enough padding for full block) */
  22110. plainSz = 0;
  22111. EVP_CIPHER_CTX_init(ctx);
  22112. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0);
  22113. if (ret == WOLFSSL_SUCCESS) {
  22114. ret = EVP_CipherUpdate(ctx, plain, &idx, cipher, 1);
  22115. if (ret == WOLFSSL_SUCCESS)
  22116. plainSz += idx;
  22117. }
  22118. if (ret == WOLFSSL_SUCCESS) {
  22119. /* this test should fail... not enough padding for full block */
  22120. ret = EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22121. if (plainSz == 0 && ret != WOLFSSL_SUCCESS)
  22122. ret = WOLFSSL_SUCCESS;
  22123. else
  22124. ret = WC_TEST_RET_ENC_NC;
  22125. }
  22126. else
  22127. ret = WC_TEST_RET_ENC_NC;
  22128. EVP_CIPHER_CTX_cleanup(ctx);
  22129. if (ret != WOLFSSL_SUCCESS)
  22130. return ret;
  22131. plainSz = 0;
  22132. EVP_CIPHER_CTX_init(ctx);
  22133. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0);
  22134. if (ret == WOLFSSL_SUCCESS) {
  22135. ret = EVP_CipherUpdate(ctx, plain, &idx, cipher, cipherSz);
  22136. if (ret == WOLFSSL_SUCCESS)
  22137. plainSz += idx;
  22138. }
  22139. if (ret == WOLFSSL_SUCCESS) {
  22140. ret = EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22141. if (ret == WOLFSSL_SUCCESS)
  22142. plainSz += idx;
  22143. }
  22144. EVP_CIPHER_CTX_cleanup(ctx);
  22145. if (ret != WOLFSSL_SUCCESS)
  22146. return WC_TEST_RET_ENC_NC;
  22147. if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg)))
  22148. return WC_TEST_RET_ENC_NC;
  22149. cipherSz = 0;
  22150. EVP_CIPHER_CTX_init(ctx);
  22151. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 1);
  22152. if (ret == WOLFSSL_SUCCESS) {
  22153. ret = EVP_CipherUpdate(ctx, cipher, &idx, msg, AES_BLOCK_SIZE);
  22154. if (ret == WOLFSSL_SUCCESS)
  22155. cipherSz += idx;
  22156. }
  22157. if (ret == WOLFSSL_SUCCESS) {
  22158. ret = EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22159. if (ret == WOLFSSL_SUCCESS)
  22160. cipherSz += idx;
  22161. }
  22162. EVP_CIPHER_CTX_cleanup(ctx);
  22163. if (ret != WOLFSSL_SUCCESS)
  22164. return WC_TEST_RET_ENC_NC;
  22165. if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz))
  22166. return WC_TEST_RET_ENC_NC;
  22167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22168. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22169. #endif
  22170. } /* end evp_cipher test: EVP_aes_128_cbc*/
  22171. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22172. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  22173. { /* evp_cipher test: EVP_aes_256_ecb*/
  22174. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22175. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22176. #else
  22177. EVP_CIPHER_CTX ctx[1];
  22178. #endif
  22179. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  22180. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22181. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22182. };
  22183. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22184. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22185. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22186. };
  22187. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  22188. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22189. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22190. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22191. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22192. };
  22193. byte cipher[AES_BLOCK_SIZE * 4];
  22194. byte plain [AES_BLOCK_SIZE * 4];
  22195. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22196. if (ctx == NULL)
  22197. return MEMORY_E;
  22198. #endif
  22199. EVP_CIPHER_CTX_init(ctx);
  22200. ret = EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1);
  22201. if (ret == WOLFSSL_SUCCESS)
  22202. ret = EVP_Cipher(ctx, cipher, (byte*)msg, 16);
  22203. EVP_CIPHER_CTX_cleanup(ctx);
  22204. if (ret != 16)
  22205. return WC_TEST_RET_ENC_NC;
  22206. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22207. return WC_TEST_RET_ENC_NC;
  22208. EVP_CIPHER_CTX_init(ctx);
  22209. ret = EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0);
  22210. if (ret == WOLFSSL_SUCCESS)
  22211. ret = EVP_Cipher(ctx, plain, cipher, 16);
  22212. EVP_CIPHER_CTX_cleanup(ctx);
  22213. if (ret != 16)
  22214. return WC_TEST_RET_ENC_NC;
  22215. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22216. return WC_TEST_RET_ENC_NC;
  22217. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22218. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22219. #endif
  22220. } /* end evp_cipher test */
  22221. #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */
  22222. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  22223. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  22224. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  22225. {
  22226. /* Test: AES_encrypt/decrypt/set Key */
  22227. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22228. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22229. #ifdef HAVE_AES_DECRYPT
  22230. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22231. #endif
  22232. #else
  22233. AES_KEY enc[1];
  22234. #ifdef HAVE_AES_DECRYPT
  22235. AES_KEY dec[1];
  22236. #endif
  22237. #endif
  22238. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  22239. {
  22240. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22241. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22242. };
  22243. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  22244. {
  22245. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22246. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22247. };
  22248. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22249. {
  22250. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22251. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22252. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22253. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22254. };
  22255. byte plain[sizeof(msg)];
  22256. byte cipher[sizeof(msg)];
  22257. printf("openSSL extra test\n") ;
  22258. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22259. if (enc == NULL)
  22260. return MEMORY_E;
  22261. #ifdef HAVE_AES_DECRYPT
  22262. if (dec == NULL)
  22263. return MEMORY_E;
  22264. #endif
  22265. #endif
  22266. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  22267. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  22268. AES_encrypt(msg, cipher, enc);
  22269. #ifdef HAVE_AES_DECRYPT
  22270. AES_decrypt(cipher, plain, dec);
  22271. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22272. return WC_TEST_RET_ENC_NC;
  22273. #endif /* HAVE_AES_DECRYPT */
  22274. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22275. return WC_TEST_RET_ENC_NC;
  22276. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22277. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22278. #ifdef HAVE_AES_DECRYPT
  22279. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22280. #endif
  22281. #endif
  22282. }
  22283. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  22284. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  22285. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  22286. #ifdef WOLFSSL_AES_COUNTER
  22287. {
  22288. byte plainBuff [64];
  22289. byte cipherBuff[64];
  22290. #ifdef WOLFSSL_AES_128
  22291. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  22292. {
  22293. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  22294. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  22295. };
  22296. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  22297. {
  22298. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22299. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22300. };
  22301. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  22302. {
  22303. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22304. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22305. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22306. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22307. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22308. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22309. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22310. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22311. };
  22312. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  22313. {
  22314. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  22315. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  22316. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  22317. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  22318. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  22319. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  22320. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  22321. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  22322. };
  22323. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  22324. {
  22325. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  22326. 0xc2
  22327. };
  22328. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22329. EVP_CIPHER_CTX *p_en;
  22330. EVP_CIPHER_CTX *p_de;
  22331. #endif
  22332. #endif /* WOLFSSL_AES_128 */
  22333. #ifdef WOLFSSL_AES_192
  22334. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22335. * NIST Special Publication 800-38A */
  22336. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  22337. {
  22338. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  22339. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  22340. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  22341. };
  22342. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  22343. {
  22344. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22345. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22346. };
  22347. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  22348. {
  22349. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22350. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22351. };
  22352. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  22353. {
  22354. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  22355. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  22356. };
  22357. #endif /* WOLFSSL_AES_192 */
  22358. #ifdef WOLFSSL_AES_256
  22359. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22360. * NIST Special Publication 800-38A */
  22361. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  22362. {
  22363. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22364. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22365. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22366. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22367. };
  22368. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  22369. {
  22370. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22371. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22372. };
  22373. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  22374. {
  22375. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22376. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22377. };
  22378. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  22379. {
  22380. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  22381. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  22382. };
  22383. #endif /* WOLFSSL_AES_256 */
  22384. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22385. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22386. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22387. if ((en == NULL) || (de == NULL))
  22388. return MEMORY_E;
  22389. #else
  22390. EVP_CIPHER_CTX en[1];
  22391. EVP_CIPHER_CTX de[1];
  22392. #endif
  22393. #ifdef WOLFSSL_AES_128
  22394. EVP_CIPHER_CTX_init(en);
  22395. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  22396. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22397. return WC_TEST_RET_ENC_NC;
  22398. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  22399. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22400. return WC_TEST_RET_ENC_NC;
  22401. EVP_CIPHER_CTX_init(de);
  22402. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  22403. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22404. return WC_TEST_RET_ENC_NC;
  22405. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22406. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22407. return WC_TEST_RET_ENC_NC;
  22408. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22409. return WC_TEST_RET_ENC_NC;
  22410. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22411. return WC_TEST_RET_ENC_NC;
  22412. EVP_CIPHER_CTX_cleanup(en);
  22413. EVP_CIPHER_CTX_cleanup(de);
  22414. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22415. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  22416. if (p_en == NULL)
  22417. return WC_TEST_RET_ENC_ERRNO;
  22418. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  22419. if (p_de == NULL)
  22420. return WC_TEST_RET_ENC_ERRNO;
  22421. if (EVP_CipherInit(p_en, EVP_aes_128_ctr(),
  22422. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22423. return WC_TEST_RET_ENC_NC;
  22424. if (EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  22425. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22426. return WC_TEST_RET_ENC_NC;
  22427. if (EVP_CipherInit(p_de, EVP_aes_128_ctr(),
  22428. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22429. return WC_TEST_RET_ENC_NC;
  22430. if (EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  22431. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22432. return WC_TEST_RET_ENC_NC;
  22433. EVP_CIPHER_CTX_cleanup(p_en);
  22434. EVP_CIPHER_CTX_cleanup(p_de);
  22435. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  22436. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  22437. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  22438. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22439. return WC_TEST_RET_ENC_NC;
  22440. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22441. return WC_TEST_RET_ENC_NC;
  22442. EVP_CIPHER_CTX_init(en);
  22443. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  22444. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22445. return WC_TEST_RET_ENC_NC;
  22446. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22447. return WC_TEST_RET_ENC_NC;
  22448. EVP_CIPHER_CTX_init(de);
  22449. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  22450. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22451. return WC_TEST_RET_ENC_NC;
  22452. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22453. return WC_TEST_RET_ENC_NC;
  22454. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22455. return WC_TEST_RET_ENC_NC;
  22456. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  22457. return WC_TEST_RET_ENC_NC;
  22458. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22459. return WC_TEST_RET_ENC_NC;
  22460. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22461. return WC_TEST_RET_ENC_NC;
  22462. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22463. return WC_TEST_RET_ENC_NC;
  22464. if (XMEMCMP(cipherBuff, oddCipher, 9))
  22465. return WC_TEST_RET_ENC_NC;
  22466. EVP_CIPHER_CTX_cleanup(en);
  22467. EVP_CIPHER_CTX_cleanup(de);
  22468. #endif /* WOLFSSL_AES_128 */
  22469. #ifdef WOLFSSL_AES_192
  22470. EVP_CIPHER_CTX_init(en);
  22471. if (EVP_CipherInit(en, EVP_aes_192_ctr(),
  22472. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22473. return WC_TEST_RET_ENC_NC;
  22474. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  22475. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22476. return WC_TEST_RET_ENC_NC;
  22477. EVP_CIPHER_CTX_init(de);
  22478. if (EVP_CipherInit(de, EVP_aes_192_ctr(),
  22479. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22480. return WC_TEST_RET_ENC_NC;
  22481. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22482. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22483. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22484. return WC_TEST_RET_ENC_NC;
  22485. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  22486. return WC_TEST_RET_ENC_NC;
  22487. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  22488. return WC_TEST_RET_ENC_NC;
  22489. EVP_CIPHER_CTX_cleanup(en);
  22490. EVP_CIPHER_CTX_cleanup(de);
  22491. #endif /* WOLFSSL_AES_192 */
  22492. #ifdef WOLFSSL_AES_256
  22493. EVP_CIPHER_CTX_init(en);
  22494. if (EVP_CipherInit(en, EVP_aes_256_ctr(),
  22495. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22496. return WC_TEST_RET_ENC_NC;
  22497. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  22498. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22499. return WC_TEST_RET_ENC_NC;
  22500. EVP_CIPHER_CTX_init(de);
  22501. if (EVP_CipherInit(de, EVP_aes_256_ctr(),
  22502. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22503. return WC_TEST_RET_ENC_NC;
  22504. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22505. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22506. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22507. return WC_TEST_RET_ENC_NC;
  22508. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  22509. return WC_TEST_RET_ENC_NC;
  22510. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  22511. return WC_TEST_RET_ENC_NC;
  22512. EVP_CIPHER_CTX_cleanup(en);
  22513. EVP_CIPHER_CTX_cleanup(de);
  22514. #endif /* WOLFSSL_AES_256 */
  22515. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22516. wolfSSL_EVP_CIPHER_CTX_free(en);
  22517. wolfSSL_EVP_CIPHER_CTX_free(de);
  22518. #endif
  22519. }
  22520. #endif /* HAVE_AES_COUNTER */
  22521. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22522. {
  22523. /* EVP_CipherUpdate test */
  22524. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  22525. {
  22526. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22527. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22528. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22529. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22530. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22531. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22532. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22533. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22534. };
  22535. byte key[] = "0123456789abcdef "; /* align */
  22536. byte iv[] = "1234567890abcdef "; /* align */
  22537. byte cipher[AES_BLOCK_SIZE * 4];
  22538. byte plain [AES_BLOCK_SIZE * 4];
  22539. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22540. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22541. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22542. #else
  22543. EVP_CIPHER_CTX en[1];
  22544. EVP_CIPHER_CTX de[1];
  22545. #endif
  22546. int outlen ;
  22547. int total = 0;
  22548. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22549. if ((en == NULL) || (de == NULL))
  22550. return MEMORY_E;
  22551. #endif
  22552. EVP_CIPHER_CTX_init(en);
  22553. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  22554. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22555. return WC_TEST_RET_ENC_NC;
  22556. /* openSSL compatibility, if(inlen == 0)return 1; */
  22557. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22558. (byte*)cbcPlain, 0) != 1)
  22559. return WC_TEST_RET_ENC_NC;
  22560. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22561. return WC_TEST_RET_ENC_NC;
  22562. EVP_CIPHER_CTX_init(en);
  22563. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  22564. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22565. return WC_TEST_RET_ENC_NC;
  22566. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22567. (byte*)cbcPlain, 9) == 0)
  22568. return WC_TEST_RET_ENC_NC;
  22569. if(outlen != 0)
  22570. return WC_TEST_RET_ENC_NC;
  22571. total += outlen;
  22572. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  22573. (byte*)&cbcPlain[9] , 9) == 0)
  22574. return WC_TEST_RET_ENC_NC;
  22575. if(outlen != 16)
  22576. return WC_TEST_RET_ENC_NC;
  22577. total += outlen;
  22578. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22579. return WC_TEST_RET_ENC_NC;
  22580. if(outlen != 16)
  22581. return WC_TEST_RET_ENC_NC;
  22582. total += outlen;
  22583. if(total != 32)
  22584. return WC_TEST_RET_ENC_NC;
  22585. total = 0;
  22586. EVP_CIPHER_CTX_init(de);
  22587. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  22588. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22589. return WC_TEST_RET_ENC_NC;
  22590. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22591. return WC_TEST_RET_ENC_NC;
  22592. if(outlen != 0)
  22593. return WC_TEST_RET_ENC_NC;
  22594. total += outlen;
  22595. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22596. (byte*)&cipher[6], 12) == 0)
  22597. return WC_TEST_RET_ENC_NC;
  22598. if(outlen != 0)
  22599. total += outlen;
  22600. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22601. (byte*)&cipher[6+12], 14) == 0)
  22602. return WC_TEST_RET_ENC_NC;
  22603. if(outlen != 16)
  22604. return WC_TEST_RET_ENC_NC;
  22605. total += outlen;
  22606. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  22607. return WC_TEST_RET_ENC_NC;
  22608. if(outlen != 2)
  22609. return WC_TEST_RET_ENC_NC;
  22610. total += outlen;
  22611. if(total != 18)
  22612. return WC_TEST_RET_ENC_NC;
  22613. if (XMEMCMP(plain, cbcPlain, 18))
  22614. return WC_TEST_RET_ENC_NC;
  22615. total = 0;
  22616. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22617. return WC_TEST_RET_ENC_NC;
  22618. EVP_CIPHER_CTX_init(en);
  22619. if (EVP_EncryptInit(en, EVP_aes_128_cbc(),
  22620. (unsigned char*)key, (unsigned char*)iv) == 0)
  22621. return WC_TEST_RET_ENC_NC;
  22622. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0)
  22623. return WC_TEST_RET_ENC_NC;
  22624. if(outlen != 0)
  22625. return WC_TEST_RET_ENC_NC;
  22626. total += outlen;
  22627. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0)
  22628. return WC_TEST_RET_ENC_NC;
  22629. if(outlen != 16)
  22630. return WC_TEST_RET_ENC_NC;
  22631. total += outlen;
  22632. if (EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22633. return WC_TEST_RET_ENC_NC;
  22634. if(outlen != 16)
  22635. return WC_TEST_RET_ENC_NC;
  22636. total += outlen;
  22637. if(total != 32)
  22638. return 3438;
  22639. total = 0;
  22640. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22641. return WC_TEST_RET_ENC_NC;
  22642. EVP_CIPHER_CTX_init(de);
  22643. if (EVP_DecryptInit(de, EVP_aes_128_cbc(),
  22644. (unsigned char*)key, (unsigned char*)iv) == 0)
  22645. return WC_TEST_RET_ENC_NC;
  22646. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22647. return WC_TEST_RET_ENC_NC;
  22648. if(outlen != 0)
  22649. return WC_TEST_RET_ENC_NC;
  22650. total += outlen;
  22651. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0)
  22652. return WC_TEST_RET_ENC_NC;
  22653. if(outlen != 0)
  22654. total += outlen;
  22655. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0)
  22656. return WC_TEST_RET_ENC_NC;
  22657. if(outlen != 16)
  22658. return WC_TEST_RET_ENC_NC;
  22659. total += outlen;
  22660. if (EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0)
  22661. return WC_TEST_RET_ENC_NC;
  22662. if(outlen != 2)
  22663. return WC_TEST_RET_ENC_NC;
  22664. total += outlen;
  22665. if(total != 18)
  22666. return 3447;
  22667. if (XMEMCMP(plain, cbcPlain, 18))
  22668. return WC_TEST_RET_ENC_NC;
  22669. if (EVP_CIPHER_key_length(NULL) != 0)
  22670. return WC_TEST_RET_ENC_NC;
  22671. if (EVP_CIPHER_key_length(EVP_aes_128_cbc()) != 16)
  22672. return WC_TEST_RET_ENC_NC;
  22673. if (EVP_CIPHER_CTX_mode(NULL) != 0)
  22674. return WC_TEST_RET_ENC_NC;
  22675. if (EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE))
  22676. return WC_TEST_RET_ENC_NC;
  22677. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22678. return WC_TEST_RET_ENC_NC;
  22679. EVP_CIPHER_CTX_init(en);
  22680. if (EVP_CipherInit_ex(en, EVP_aes_128_cbc(), NULL,
  22681. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22682. return WC_TEST_RET_ENC_NC;
  22683. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22684. return WC_TEST_RET_ENC_NC;
  22685. EVP_CIPHER_CTX_init(en);
  22686. if (EVP_EncryptInit_ex(en, EVP_aes_128_cbc(), NULL,
  22687. (unsigned char*)key, (unsigned char*)iv) == 0)
  22688. return WC_TEST_RET_ENC_NC;
  22689. if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL)
  22690. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22691. {
  22692. return WC_TEST_RET_ENC_NC;
  22693. }
  22694. if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL)
  22695. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22696. {
  22697. return WC_TEST_RET_ENC_NC;
  22698. }
  22699. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22700. return WC_TEST_RET_ENC_NC;
  22701. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22702. return WC_TEST_RET_ENC_NC;
  22703. EVP_CIPHER_CTX_init(de);
  22704. if (EVP_DecryptInit_ex(de, EVP_aes_128_cbc(), NULL,
  22705. (unsigned char*)key, (unsigned char*)iv) == 0)
  22706. return WC_TEST_RET_ENC_NC;
  22707. if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL)
  22708. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22709. {
  22710. return WC_TEST_RET_ENC_NC;
  22711. }
  22712. if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL)
  22713. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22714. {
  22715. return WC_TEST_RET_ENC_NC;
  22716. }
  22717. if (EVP_CIPHER_CTX_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22718. return WC_TEST_RET_ENC_NC;
  22719. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22720. return WC_TEST_RET_ENC_NC;
  22721. EVP_CIPHER_CTX_init(en);
  22722. EVP_EncryptInit_ex(en, EVP_aes_128_cbc(), NULL,
  22723. (unsigned char*)key, (unsigned char*)iv);
  22724. if (EVP_CIPHER_CTX_block_size(en) != en->block_size)
  22725. return WC_TEST_RET_ENC_NC;
  22726. if (EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22727. return WC_TEST_RET_ENC_NC;
  22728. if (EVP_CIPHER_block_size(EVP_aes_128_cbc()) != AES_BLOCK_SIZE)
  22729. return WC_TEST_RET_ENC_NC;
  22730. if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0)
  22731. return WC_TEST_RET_ENC_NC;
  22732. if (EVP_CIPHER_flags(EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE)
  22733. return WC_TEST_RET_ENC_NC;
  22734. EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF);
  22735. EVP_CIPHER_CTX_set_flags(en, 42);
  22736. if (en->flags != 42)
  22737. return WC_TEST_RET_ENC_NC;
  22738. if (EVP_CIPHER_CTX_set_padding(NULL, 0) !=
  22739. WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22740. return WC_TEST_RET_ENC_NC;
  22741. if (EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS)
  22742. return WC_TEST_RET_ENC_NC;
  22743. if (EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS)
  22744. return WC_TEST_RET_ENC_NC;
  22745. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22746. return WC_TEST_RET_ENC_NC;
  22747. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22748. return WC_TEST_RET_ENC_NC;
  22749. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22750. wolfSSL_EVP_CIPHER_CTX_free(en);
  22751. wolfSSL_EVP_CIPHER_CTX_free(de);
  22752. #endif
  22753. }
  22754. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22755. #endif /* ifndef NO_AES */
  22756. return 0;
  22757. }
  22758. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void)
  22759. {
  22760. wc_test_ret_t ret = 0;
  22761. #if !defined(NO_SHA256) && !defined(NO_SHA)
  22762. WOLFSSL_EVP_MD_CTX* ctx;
  22763. WOLFSSL_EVP_MD_CTX* ctx2;
  22764. WOLFSSL_ENTER("openSSL_evpMD_test");
  22765. ctx = EVP_MD_CTX_create();
  22766. ctx2 = EVP_MD_CTX_create();
  22767. ret = EVP_DigestInit(ctx, EVP_sha256());
  22768. if (ret != SSL_SUCCESS) {
  22769. ret = WC_TEST_RET_ENC_NC;
  22770. goto openSSL_evpMD_test_done;
  22771. }
  22772. ret = EVP_MD_CTX_copy(ctx2, ctx);
  22773. if (ret != SSL_SUCCESS) {
  22774. ret = WC_TEST_RET_ENC_NC;
  22775. goto openSSL_evpMD_test_done;
  22776. }
  22777. if (EVP_MD_type(EVP_sha256()) != EVP_MD_CTX_type(ctx2)) {
  22778. ret = WC_TEST_RET_ENC_NC;
  22779. goto openSSL_evpMD_test_done;
  22780. }
  22781. ret = EVP_DigestInit(ctx, EVP_sha1());
  22782. if (ret != SSL_SUCCESS) {
  22783. ret = WC_TEST_RET_ENC_NC;
  22784. goto openSSL_evpMD_test_done;
  22785. }
  22786. if (EVP_MD_type(EVP_sha256()) != EVP_MD_CTX_type(ctx2)) {
  22787. ret = WC_TEST_RET_ENC_NC;
  22788. goto openSSL_evpMD_test_done;
  22789. }
  22790. ret = EVP_MD_CTX_copy_ex(ctx2, ctx);
  22791. if (ret != SSL_SUCCESS) {
  22792. ret = WC_TEST_RET_ENC_NC;
  22793. goto openSSL_evpMD_test_done;
  22794. }
  22795. if (EVP_MD_type(EVP_sha256()) == EVP_MD_CTX_type(ctx2)) {
  22796. ret = WC_TEST_RET_ENC_NC;
  22797. goto openSSL_evpMD_test_done;
  22798. }
  22799. if (EVP_MD_type(EVP_sha1()) != EVP_MD_CTX_type(ctx2)) {
  22800. ret = WC_TEST_RET_ENC_NC;
  22801. goto openSSL_evpMD_test_done;
  22802. }
  22803. if (EVP_DigestInit_ex(ctx, EVP_sha1(), NULL) != SSL_SUCCESS) {
  22804. ret = WC_TEST_RET_ENC_NC;
  22805. goto openSSL_evpMD_test_done;
  22806. }
  22807. if (EVP_add_digest(NULL) != 0) {
  22808. ret = WC_TEST_RET_ENC_NC;
  22809. goto openSSL_evpMD_test_done;
  22810. }
  22811. if (wolfSSL_EVP_add_cipher(NULL) != 0) {
  22812. ret = WC_TEST_RET_ENC_NC;
  22813. goto openSSL_evpMD_test_done;
  22814. }
  22815. ret = 0; /* got to success state without jumping to end with a fail */
  22816. openSSL_evpMD_test_done:
  22817. EVP_MD_CTX_destroy(ctx);
  22818. EVP_MD_CTX_destroy(ctx2);
  22819. #endif /* NO_SHA256 */
  22820. return ret;
  22821. }
  22822. #ifdef DEBUG_SIGN
  22823. static void show(const char *title, const char *p, unsigned int s) {
  22824. char* i;
  22825. printf("%s: ", title);
  22826. for (i = p;
  22827. i < p + s;
  22828. printf("%c", *i), i++);
  22829. printf("\n");
  22830. }
  22831. #else
  22832. #define show(a,b,c) WC_DO_NOTHING
  22833. #endif
  22834. #define FOURK_BUFF 4096
  22835. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void)
  22836. {
  22837. wc_test_ret_t ret = 0;
  22838. #if !defined(NO_RSA) && !defined(NO_SHA)
  22839. byte* prvTmp;
  22840. byte* pubTmp;
  22841. int prvBytes;
  22842. int pubBytes;
  22843. RSA *prvRsa = NULL;
  22844. RSA *pubRsa = NULL;
  22845. EVP_PKEY *prvPkey = NULL;
  22846. EVP_PKEY *pubPkey = NULL;
  22847. EVP_PKEY_CTX *enc = NULL;
  22848. EVP_PKEY_CTX *dec = NULL;
  22849. byte in[] = TEST_STRING;
  22850. byte out[256];
  22851. size_t outlen;
  22852. size_t keySz;
  22853. byte plain[256];
  22854. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  22855. XFILE keyFile;
  22856. XFILE keypubFile;
  22857. char cliKey[] = "./certs/client-key.der";
  22858. char cliKeypub[] = "./certs/client-keyPub.der";
  22859. #endif
  22860. WOLFSSL_ENTER("openssl_pkey0_test");
  22861. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22862. if (prvTmp == NULL)
  22863. return WC_TEST_RET_ENC_ERRNO;
  22864. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22865. if (pubTmp == NULL) {
  22866. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22867. return WC_TEST_RET_ENC_NC;
  22868. }
  22869. #ifdef USE_CERT_BUFFERS_1024
  22870. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  22871. prvBytes = sizeof_client_key_der_1024;
  22872. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  22873. pubBytes = sizeof_client_keypub_der_1024;
  22874. #elif defined(USE_CERT_BUFFERS_2048)
  22875. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  22876. prvBytes = sizeof_client_key_der_2048;
  22877. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  22878. pubBytes = sizeof_client_keypub_der_2048;
  22879. #else
  22880. keyFile = XFOPEN(cliKey, "rb");
  22881. if (!keyFile) {
  22882. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22883. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22884. err_sys("can't open ./certs/client-key.der, "
  22885. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  22886. return WC_TEST_RET_ENC_ERRNO;
  22887. }
  22888. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  22889. XFCLOSE(keyFile);
  22890. if (prvBytes == 0) {
  22891. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22892. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22893. return WC_TEST_RET_ENC_ERRNO;
  22894. }
  22895. keypubFile = XFOPEN(cliKeypub, "rb");
  22896. if (!keypubFile) {
  22897. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22898. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22899. err_sys("can't open ./certs/client-cert.der, "
  22900. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  22901. return WC_TEST_RET_ENC_ERRNO;
  22902. }
  22903. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  22904. XFCLOSE(keypubFile);
  22905. if (pubBytes == 0) {
  22906. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22907. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22908. return WC_TEST_RET_ENC_ERRNO;
  22909. }
  22910. #endif /* USE_CERT_BUFFERS */
  22911. prvRsa = wolfSSL_RSA_new();
  22912. pubRsa = wolfSSL_RSA_new();
  22913. if((prvRsa == NULL) || (pubRsa == NULL)){
  22914. printf("error with RSA_new\n");
  22915. ret = WC_TEST_RET_ENC_ERRNO;
  22916. goto openssl_pkey0_test_done;
  22917. }
  22918. ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  22919. if(ret != SSL_SUCCESS){
  22920. printf("error with RSA_LoadDer_ex\n");
  22921. ret = WC_TEST_RET_ENC_EC(ret);
  22922. goto openssl_pkey0_test_done;
  22923. }
  22924. ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  22925. if(ret != SSL_SUCCESS){
  22926. printf("error with RSA_LoadDer_ex\n");
  22927. ret = WC_TEST_RET_ENC_EC(ret);
  22928. goto openssl_pkey0_test_done;
  22929. }
  22930. keySz = (size_t)RSA_size(pubRsa);
  22931. prvPkey = wolfSSL_EVP_PKEY_new();
  22932. pubPkey = wolfSSL_EVP_PKEY_new();
  22933. if((prvPkey == NULL) || (pubPkey == NULL)){
  22934. printf("error with PKEY_new\n");
  22935. ret = WC_TEST_RET_ENC_NC;
  22936. goto openssl_pkey0_test_done;
  22937. }
  22938. ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  22939. ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  22940. if(ret != 2){
  22941. printf("error with PKEY_set1_RSA\n");
  22942. ret = WC_TEST_RET_ENC_I(ret);
  22943. goto openssl_pkey0_test_done;
  22944. }
  22945. dec = EVP_PKEY_CTX_new(prvPkey, NULL);
  22946. enc = EVP_PKEY_CTX_new(pubPkey, NULL);
  22947. if((dec == NULL)||(enc==NULL)){
  22948. printf("error with EVP_PKEY_CTX_new\n");
  22949. ret = WC_TEST_RET_ENC_NC;
  22950. goto openssl_pkey0_test_done;
  22951. }
  22952. ret = EVP_PKEY_decrypt_init(dec);
  22953. if (ret != 1) {
  22954. printf("error with decrypt init\n");
  22955. ret = WC_TEST_RET_ENC_NC;
  22956. goto openssl_pkey0_test_done;
  22957. }
  22958. ret = EVP_PKEY_encrypt_init(enc);
  22959. if (ret != 1) {
  22960. printf("error with encrypt init\n");
  22961. ret = WC_TEST_RET_ENC_NC;
  22962. goto openssl_pkey0_test_done;
  22963. }
  22964. XMEMSET(out, 0, sizeof(out));
  22965. ret = EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  22966. if (ret != 1) {
  22967. printf("error encrypting msg\n");
  22968. ret = WC_TEST_RET_ENC_NC;
  22969. goto openssl_pkey0_test_done;
  22970. }
  22971. show("encrypted msg", out, outlen);
  22972. XMEMSET(plain, 0, sizeof(plain));
  22973. ret = EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  22974. if (ret != 1) {
  22975. printf("error decrypting msg\n");
  22976. ret = WC_TEST_RET_ENC_NC;
  22977. goto openssl_pkey0_test_done;
  22978. }
  22979. show("decrypted msg", plain, outlen);
  22980. /* RSA_PKCS1_OAEP_PADDING test */
  22981. ret = EVP_PKEY_decrypt_init(dec);
  22982. if (ret != 1) {
  22983. printf("error with decrypt init\n");
  22984. ret = WC_TEST_RET_ENC_NC;
  22985. goto openssl_pkey0_test_done;
  22986. }
  22987. ret = EVP_PKEY_encrypt_init(enc);
  22988. if (ret != 1) {
  22989. printf("error with encrypt init\n");
  22990. ret = WC_TEST_RET_ENC_NC;
  22991. goto openssl_pkey0_test_done;
  22992. }
  22993. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_PADDING) <= 0) {
  22994. printf("first set rsa padding error\n");
  22995. ret = WC_TEST_RET_ENC_EC(ret);
  22996. goto openssl_pkey0_test_done;
  22997. }
  22998. #ifndef HAVE_FIPS
  22999. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_OAEP_PADDING) <= 0){
  23000. printf("second set rsa padding error\n");
  23001. ret = WC_TEST_RET_ENC_EC(ret);
  23002. goto openssl_pkey0_test_done;
  23003. }
  23004. if (EVP_PKEY_CTX_set_rsa_padding(enc, RSA_PKCS1_OAEP_PADDING) <= 0) {
  23005. printf("third set rsa padding error\n");
  23006. ret = WC_TEST_RET_ENC_EC(ret);
  23007. goto openssl_pkey0_test_done;
  23008. }
  23009. #endif
  23010. XMEMSET(out, 0, sizeof(out));
  23011. ret = EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23012. if (ret != 1) {
  23013. printf("error encrypting msg\n");
  23014. ret = WC_TEST_RET_ENC_NC;
  23015. goto openssl_pkey0_test_done;
  23016. }
  23017. show("encrypted msg", out, outlen);
  23018. XMEMSET(plain, 0, sizeof(plain));
  23019. ret = EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23020. if (ret != 1) {
  23021. printf("error decrypting msg\n");
  23022. ret = WC_TEST_RET_ENC_NC;
  23023. goto openssl_pkey0_test_done;
  23024. }
  23025. show("decrypted msg", plain, outlen);
  23026. ret = 0; /* made it to this point without error then set success */
  23027. openssl_pkey0_test_done:
  23028. wolfSSL_RSA_free(prvRsa);
  23029. wolfSSL_RSA_free(pubRsa);
  23030. EVP_PKEY_free(pubPkey);
  23031. EVP_PKEY_free(prvPkey);
  23032. EVP_PKEY_CTX_free(dec);
  23033. EVP_PKEY_CTX_free(enc);
  23034. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23035. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23036. #endif /* NO_RSA */
  23037. return ret;
  23038. }
  23039. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void)
  23040. {
  23041. wc_test_ret_t ret = 0;
  23042. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_SHA)
  23043. EVP_PKEY_CTX* dec = NULL;
  23044. EVP_PKEY_CTX* enc = NULL;
  23045. EVP_PKEY* pubKey = NULL;
  23046. EVP_PKEY* prvKey = NULL;
  23047. X509* x509 = NULL;
  23048. WOLFSSL_SMALL_STACK_STATIC const unsigned char msg[] = "sugar slapped";
  23049. const unsigned char* clikey;
  23050. long cliKeySz;
  23051. size_t outlen;
  23052. int keyLenBits = 2048;
  23053. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23054. unsigned char *tmp = (unsigned char *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23055. unsigned char *cipher = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23056. unsigned char *plain = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23057. if ((tmp == NULL) ||
  23058. (cipher == NULL) ||
  23059. (plain == NULL)) {
  23060. ret = WC_TEST_RET_ENC_NC;
  23061. goto openssl_pkey1_test_done;
  23062. }
  23063. #else
  23064. unsigned char tmp[FOURK_BUF];
  23065. unsigned char cipher[RSA_TEST_BYTES];
  23066. unsigned char plain[RSA_TEST_BYTES];
  23067. #endif
  23068. WOLFSSL_ENTER("openssl_pkey1_test");
  23069. #if defined(USE_CERT_BUFFERS_1024)
  23070. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  23071. cliKeySz = (long)sizeof_client_key_der_1024;
  23072. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_1024,
  23073. sizeof_client_cert_der_1024, SSL_FILETYPE_ASN1);
  23074. keyLenBits = 1024;
  23075. #elif defined(USE_CERT_BUFFERS_2048)
  23076. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  23077. cliKeySz = (long)sizeof_client_key_der_2048;
  23078. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048,
  23079. sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1);
  23080. #elif defined(USE_CERT_BUFFERS_3072)
  23081. XMEMCPY(tmp, client_key_der_3072, sizeof_client_key_der_3072);
  23082. cliKeySz = (long)sizeof_client_key_der_3072;
  23083. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_3072,
  23084. sizeof_client_cert_der_3072, SSL_FILETYPE_ASN1);
  23085. keyLenBits = 3072;
  23086. #elif defined(USE_CERT_BUFFERS_4096)
  23087. XMEMCPY(tmp, client_key_der_4096, sizeof_client_key_der_4096);
  23088. cliKeySz = (long)sizeof_client_key_der_4096;
  23089. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_4096,
  23090. sizeof_client_cert_der_4096, SSL_FILETYPE_ASN1);
  23091. keyLenBits = 4096;
  23092. #else
  23093. {
  23094. XFILE f;
  23095. f = XFOPEN(clientKey, "rb");
  23096. if (!f) {
  23097. err_sys("can't open ./certs/client-key.der, "
  23098. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23099. ret = WC_TEST_RET_ENC_ERRNO;
  23100. goto openssl_pkey1_test_done;
  23101. }
  23102. cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f);
  23103. XFCLOSE(f);
  23104. if (cliKeySz == 0)
  23105. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done);
  23106. }
  23107. /* using existing wolfSSL api to get public and private key */
  23108. x509 = wolfSSL_X509_load_certificate_file(clientCert, SSL_FILETYPE_ASN1);
  23109. #endif /* USE_CERT_BUFFERS */
  23110. clikey = tmp;
  23111. if ((prvKey = EVP_PKEY_new()) == NULL) {
  23112. ret = WC_TEST_RET_ENC_ERRNO;
  23113. goto openssl_pkey1_test_done;
  23114. }
  23115. EVP_PKEY_free(prvKey);
  23116. prvKey = NULL;
  23117. if (x509 == NULL) {
  23118. ret = WC_TEST_RET_ENC_NC;
  23119. goto openssl_pkey1_test_done;
  23120. }
  23121. pubKey = X509_get_pubkey(x509);
  23122. if (pubKey == NULL) {
  23123. ret = WC_TEST_RET_ENC_NC;
  23124. goto openssl_pkey1_test_done;
  23125. }
  23126. prvKey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &clikey, cliKeySz);
  23127. if (prvKey == NULL) {
  23128. ret = WC_TEST_RET_ENC_NC;
  23129. goto openssl_pkey1_test_done;
  23130. }
  23131. /* phase 2 API to create EVP_PKEY_CTX and encrypt/decrypt */
  23132. if (EVP_PKEY_bits(prvKey) != keyLenBits) {
  23133. ret = WC_TEST_RET_ENC_NC;
  23134. goto openssl_pkey1_test_done;
  23135. }
  23136. if (EVP_PKEY_size(prvKey) != keyLenBits/8) {
  23137. ret = WC_TEST_RET_ENC_NC;
  23138. goto openssl_pkey1_test_done;
  23139. }
  23140. dec = EVP_PKEY_CTX_new(prvKey, NULL);
  23141. enc = EVP_PKEY_CTX_new(pubKey, NULL);
  23142. if (dec == NULL || enc == NULL) {
  23143. ret = WC_TEST_RET_ENC_ERRNO;
  23144. goto openssl_pkey1_test_done;
  23145. }
  23146. if (EVP_PKEY_decrypt_init(dec) != 1) {
  23147. ret = WC_TEST_RET_ENC_NC;
  23148. goto openssl_pkey1_test_done;
  23149. }
  23150. if (EVP_PKEY_encrypt_init(enc) != 1) {
  23151. ret = WC_TEST_RET_ENC_NC;
  23152. goto openssl_pkey1_test_done;
  23153. }
  23154. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_PADDING) <= 0) {
  23155. ret = WC_TEST_RET_ENC_NC;
  23156. goto openssl_pkey1_test_done;
  23157. }
  23158. #ifndef HAVE_FIPS
  23159. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_OAEP_PADDING) <= 0){
  23160. ret = WC_TEST_RET_ENC_EC(ret);
  23161. goto openssl_pkey1_test_done;
  23162. }
  23163. if (EVP_PKEY_CTX_set_rsa_padding(enc, RSA_PKCS1_OAEP_PADDING) <= 0) {
  23164. ret = WC_TEST_RET_ENC_EC(ret);
  23165. goto openssl_pkey1_test_done;
  23166. }
  23167. #endif
  23168. XMEMSET(cipher, 0, RSA_TEST_BYTES);
  23169. outlen = (size_t)(keyLenBits/8);
  23170. if (EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) {
  23171. ret = WC_TEST_RET_ENC_EC(ret);
  23172. goto openssl_pkey1_test_done;
  23173. }
  23174. XMEMSET(plain, 0, RSA_TEST_BYTES);
  23175. if (EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) {
  23176. ret = WC_TEST_RET_ENC_NC;
  23177. goto openssl_pkey1_test_done;
  23178. }
  23179. openssl_pkey1_test_done:
  23180. if (pubKey != NULL) {
  23181. EVP_PKEY_free(pubKey);
  23182. }
  23183. if (prvKey != NULL) {
  23184. EVP_PKEY_free(prvKey);
  23185. }
  23186. if (dec != NULL) {
  23187. EVP_PKEY_CTX_free(dec);
  23188. }
  23189. if (enc != NULL) {
  23190. EVP_PKEY_CTX_free(enc);
  23191. }
  23192. if (x509 != NULL) {
  23193. X509_free(x509);
  23194. }
  23195. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23196. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23197. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23198. XFREE(plain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23199. #endif
  23200. #endif
  23201. return ret;
  23202. }
  23203. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void)
  23204. {
  23205. #if !defined(NO_RSA) && !defined(NO_SHA)
  23206. byte* prvTmp;
  23207. byte* pubTmp;
  23208. int prvBytes;
  23209. int pubBytes;
  23210. RSA *prvRsa;
  23211. RSA *pubRsa;
  23212. EVP_PKEY *prvPkey;
  23213. EVP_PKEY *pubPkey;
  23214. EVP_MD_CTX* sign;
  23215. EVP_MD_CTX* verf;
  23216. char msg[] = "see spot run";
  23217. unsigned char sig[256];
  23218. unsigned int sigSz;
  23219. const void* pt;
  23220. unsigned int count;
  23221. wc_test_ret_t ret, ret1, ret2;
  23222. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  23223. XFILE keyFile;
  23224. XFILE keypubFile;
  23225. char cliKey[] = "./certs/client-key.der";
  23226. char cliKeypub[] = "./certs/client-keyPub.der";
  23227. #endif
  23228. WOLFSSL_ENTER("openssl_evpSig_test");
  23229. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23230. if (prvTmp == NULL)
  23231. return WC_TEST_RET_ENC_ERRNO;
  23232. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23233. if (pubTmp == NULL) {
  23234. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23235. return WC_TEST_RET_ENC_NC;
  23236. }
  23237. #ifdef USE_CERT_BUFFERS_1024
  23238. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  23239. prvBytes = sizeof_client_key_der_1024;
  23240. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  23241. pubBytes = sizeof_client_keypub_der_1024;
  23242. #elif defined(USE_CERT_BUFFERS_2048)
  23243. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  23244. prvBytes = sizeof_client_key_der_2048;
  23245. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  23246. pubBytes = sizeof_client_keypub_der_2048;
  23247. #else
  23248. keyFile = XFOPEN(cliKey, "rb");
  23249. if (!keyFile) {
  23250. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23251. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23252. err_sys("can't open ./certs/client-key.der, "
  23253. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23254. return WC_TEST_RET_ENC_ERRNO;
  23255. }
  23256. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23257. XFCLOSE(keyFile);
  23258. if (prvBytes == 0) {
  23259. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23260. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23261. return WC_TEST_RET_ENC_ERRNO;
  23262. }
  23263. keypubFile = XFOPEN(cliKeypub, "rb");
  23264. if (!keypubFile) {
  23265. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23266. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23267. err_sys("can't open ./certs/client-cert.der, "
  23268. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23269. return WC_TEST_RET_ENC_ERRNO;
  23270. }
  23271. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23272. XFCLOSE(keypubFile);
  23273. if (pubBytes == 0) {
  23274. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23275. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23276. return WC_TEST_RET_ENC_ERRNO;
  23277. }
  23278. #endif /* USE_CERT_BUFFERS */
  23279. prvRsa = wolfSSL_RSA_new();
  23280. pubRsa = wolfSSL_RSA_new();
  23281. if((prvRsa == NULL) || (pubRsa == NULL)){
  23282. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23283. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23284. err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC);
  23285. return WC_TEST_RET_ENC_NC;
  23286. }
  23287. ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23288. ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23289. if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){
  23290. printf("error with RSA_LoadDer_ex\n");
  23291. return WC_TEST_RET_ENC_NC;
  23292. }
  23293. prvPkey = wolfSSL_EVP_PKEY_new();
  23294. pubPkey = wolfSSL_EVP_PKEY_new();
  23295. if((prvPkey == NULL) || (pubPkey == NULL)){
  23296. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23297. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23298. printf("error with KEY_new\n");
  23299. return WC_TEST_RET_ENC_NC;
  23300. }
  23301. ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23302. ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23303. if((ret1 != 1) || (ret2 != 1)){
  23304. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23305. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23306. printf("error with EVP_PKEY_set1_RSA\n");
  23307. return WC_TEST_RET_ENC_NC;
  23308. }
  23309. /****************** sign and verify *******************/
  23310. sign = EVP_MD_CTX_create();
  23311. verf = EVP_MD_CTX_create();
  23312. if((sign == NULL)||(verf == NULL)){
  23313. printf("error with EVP_MD_CTX_create\n");
  23314. EVP_MD_CTX_destroy(sign);
  23315. EVP_MD_CTX_destroy(verf);
  23316. return WC_TEST_RET_ENC_NC;
  23317. }
  23318. ret = EVP_SignInit(sign, EVP_sha1());
  23319. if (ret != SSL_SUCCESS){
  23320. printf("error with EVP_SignInit\n");
  23321. EVP_MD_CTX_destroy(sign);
  23322. EVP_MD_CTX_destroy(verf);
  23323. return WC_TEST_RET_ENC_NC;
  23324. }
  23325. count = sizeof(msg);
  23326. show("message = ", (char *)msg, count);
  23327. /* sign */
  23328. XMEMSET(sig, 0, sizeof(sig));
  23329. pt = (const void*)msg;
  23330. ret1 = EVP_SignUpdate(sign, pt, count);
  23331. ret2 = EVP_SignFinal(sign, sig, &sigSz, prvPkey);
  23332. if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){
  23333. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23334. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23335. EVP_MD_CTX_destroy(sign);
  23336. EVP_MD_CTX_destroy(verf);
  23337. printf("error with EVP_MD_CTX_create\n");
  23338. return WC_TEST_RET_ENC_NC;
  23339. }
  23340. show("signature = ", (char *)sig, sigSz);
  23341. /* verify */
  23342. pt = (const void*)msg;
  23343. ret1 = EVP_VerifyInit(verf, EVP_sha1());
  23344. ret2 = EVP_VerifyUpdate(verf, pt, count);
  23345. if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){
  23346. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23347. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23348. EVP_MD_CTX_destroy(sign);
  23349. EVP_MD_CTX_destroy(verf);
  23350. printf("error with EVP_Verify\n");
  23351. return WC_TEST_RET_ENC_NC;
  23352. }
  23353. if (EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) {
  23354. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23355. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23356. EVP_MD_CTX_destroy(sign);
  23357. EVP_MD_CTX_destroy(verf);
  23358. printf("error with EVP_VerifyFinal\n");
  23359. return WC_TEST_RET_ENC_NC;
  23360. }
  23361. /* expect fail without update */
  23362. EVP_VerifyInit(verf, EVP_sha1());
  23363. if (EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) {
  23364. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23365. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23366. EVP_MD_CTX_destroy(sign);
  23367. EVP_MD_CTX_destroy(verf);
  23368. printf("EVP_VerifyInit without update not detected\n");
  23369. return WC_TEST_RET_ENC_NC;
  23370. }
  23371. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23372. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23373. EVP_MD_CTX_destroy(sign);
  23374. EVP_MD_CTX_destroy(verf);
  23375. wolfSSL_RSA_free(prvRsa);
  23376. wolfSSL_RSA_free(pubRsa);
  23377. EVP_PKEY_free(pubPkey);
  23378. EVP_PKEY_free(prvPkey);
  23379. #endif /* NO_RSA */
  23380. return 0;
  23381. }
  23382. #endif /* OPENSSL_EXTRA */
  23383. #ifndef NO_PWDBASED
  23384. #ifdef HAVE_SCRYPT
  23385. /* Test vectors taken from RFC 7914: scrypt PBKDF - Section 12. */
  23386. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
  23387. {
  23388. #ifdef HAVE_FIPS
  23389. /* RFC 7914 test vector keys are too short for FIPS. */
  23390. #else
  23391. wc_test_ret_t ret;
  23392. byte derived[64];
  23393. WOLFSSL_SMALL_STACK_STATIC const byte verify1[] = {
  23394. 0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20,
  23395. 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97,
  23396. 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8,
  23397. 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42,
  23398. 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8,
  23399. 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17,
  23400. 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28,
  23401. 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06
  23402. };
  23403. #if !defined(BENCH_EMBEDDED)
  23404. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23405. 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00,
  23406. 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe,
  23407. 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30,
  23408. 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62,
  23409. 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88,
  23410. 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda,
  23411. 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d,
  23412. 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40
  23413. };
  23414. #endif
  23415. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23416. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  23417. 0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48,
  23418. 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb,
  23419. 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e,
  23420. 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2,
  23421. 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf,
  23422. 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9,
  23423. 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40,
  23424. 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87
  23425. };
  23426. #endif
  23427. #ifdef SCRYPT_TEST_ALL
  23428. /* Test case is very slow.
  23429. * Use for confirmation after code change or new platform.
  23430. */
  23431. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  23432. 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae,
  23433. 0xad, 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81,
  23434. 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d,
  23435. 0xab, 0xe5, 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47,
  23436. 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, 0x9f,
  23437. 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3,
  23438. 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, 0x52, 0xfb,
  23439. 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4
  23440. };
  23441. #endif
  23442. WOLFSSL_ENTER("scrypt_test");
  23443. ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1));
  23444. if (ret != 0)
  23445. return WC_TEST_RET_ENC_EC(ret);
  23446. if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0)
  23447. return WC_TEST_RET_ENC_NC;
  23448. #if !defined(BENCH_EMBEDDED)
  23449. ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16,
  23450. sizeof(verify2));
  23451. if (ret != 0)
  23452. return WC_TEST_RET_ENC_EC(ret);
  23453. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23454. return WC_TEST_RET_ENC_NC;
  23455. #endif
  23456. /* Test case with parallel overflowing */
  23457. ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608,
  23458. sizeof(verify1));
  23459. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  23460. return WC_TEST_RET_ENC_EC(ret);
  23461. /* Don't run these test on embedded, since they use large mallocs */
  23462. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23463. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23464. (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3));
  23465. if (ret != 0)
  23466. return WC_TEST_RET_ENC_EC(ret);
  23467. if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0)
  23468. return WC_TEST_RET_ENC_NC;
  23469. #ifdef SCRYPT_TEST_ALL
  23470. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23471. (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4));
  23472. if (ret != 0)
  23473. return WC_TEST_RET_ENC_EC(ret);
  23474. if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0)
  23475. return WC_TEST_RET_ENC_NC;
  23476. #endif
  23477. #else
  23478. #ifdef SCRYPT_TEST_ALL
  23479. (void)verify4;
  23480. #endif
  23481. #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
  23482. #if !defined(BENCH_EMBEDDED)
  23483. ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10,
  23484. 8, 16, sizeof(verify2));
  23485. if (ret != 0)
  23486. return WC_TEST_RET_ENC_EC(ret);
  23487. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23488. return WC_TEST_RET_ENC_NC;
  23489. #endif
  23490. #endif /* !HAVE_FIPS */
  23491. return 0;
  23492. }
  23493. #endif
  23494. #ifdef HAVE_PKCS12
  23495. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void)
  23496. {
  23497. WOLFSSL_SMALL_STACK_STATIC const byte passwd[] = { 0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
  23498. 0x00, 0x00 };
  23499. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f };
  23500. WOLFSSL_SMALL_STACK_STATIC const byte passwd2[] = { 0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
  23501. 0x00, 0x67, 0x00, 0x00 };
  23502. WOLFSSL_SMALL_STACK_STATIC const byte salt2[] = { 0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5 };
  23503. byte derived[64];
  23504. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23505. 0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
  23506. 0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
  23507. 0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
  23508. };
  23509. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23510. 0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
  23511. 0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
  23512. 0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
  23513. };
  23514. int id = 1;
  23515. int kLen = 24;
  23516. int iterations = 1;
  23517. wc_test_ret_t ret;
  23518. WOLFSSL_ENTER("pkcs12_pbkdf_test");
  23519. ret = wc_PKCS12_PBKDF(derived, passwd, sizeof(passwd), salt, 8,
  23520. iterations, kLen, WC_SHA256, id);
  23521. if (ret < 0)
  23522. return WC_TEST_RET_ENC_EC(ret);
  23523. if (XMEMCMP(derived, verify, kLen) != 0)
  23524. return WC_TEST_RET_ENC_NC;
  23525. iterations = 1000;
  23526. ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8,
  23527. iterations, kLen, WC_SHA256, id);
  23528. if (ret < 0)
  23529. return WC_TEST_RET_ENC_EC(ret);
  23530. ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8,
  23531. iterations, kLen, WC_SHA256, id, HEAP_HINT);
  23532. if (ret < 0)
  23533. return WC_TEST_RET_ENC_EC(ret);
  23534. if (XMEMCMP(derived, verify2, 24) != 0)
  23535. return WC_TEST_RET_ENC_NC;
  23536. return 0;
  23537. }
  23538. #endif /* HAVE_PKCS12 */
  23539. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23540. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
  23541. {
  23542. char passwd[] = "passwordpassword";
  23543. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a,
  23544. 0x5d, 0x63, 0xcb, 0x06 };
  23545. int iterations = 2048;
  23546. int kLen = 24;
  23547. byte derived[64];
  23548. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23549. 0x43, 0x6d, 0xb5, 0xe8, 0xd0, 0xfb, 0x3f, 0x35, 0x42, 0x48, 0x39, 0xbc,
  23550. 0x2d, 0xd4, 0xf9, 0x37, 0xd4, 0x95, 0x16, 0xa7, 0x2a, 0x9a, 0x21, 0xd1
  23551. };
  23552. wc_test_ret_t ret;
  23553. WOLFSSL_ENTER("pbkdf2_test");
  23554. ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
  23555. salt, (int)sizeof(salt), iterations,
  23556. kLen, WC_SHA256, HEAP_HINT, devId);
  23557. if (ret != 0)
  23558. return WC_TEST_RET_ENC_EC(ret);
  23559. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23560. return WC_TEST_RET_ENC_NC;
  23561. return 0;
  23562. }
  23563. #endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
  23564. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23565. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void)
  23566. {
  23567. char passwd[] = "password";
  23568. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  23569. int iterations = 1000;
  23570. int kLen = 16;
  23571. byte derived[16];
  23572. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23573. 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F,
  23574. 0xAF, 0x10, 0xEB, 0xFB, 0x4A, 0x3D, 0x2A, 0x20
  23575. };
  23576. wc_test_ret_t ret;
  23577. WOLFSSL_ENTER("pbkdf1_test");
  23578. ret = wc_PBKDF1_ex(derived, kLen, NULL, 0, (byte*)passwd,
  23579. (int)XSTRLEN(passwd), salt, (int)sizeof(salt), iterations, WC_SHA,
  23580. HEAP_HINT);
  23581. if (ret != 0)
  23582. return ret;
  23583. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23584. return WC_TEST_RET_ENC_NC;
  23585. return 0;
  23586. }
  23587. #endif /* HAVE_PBKDF2 && !NO_SHA */
  23588. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void)
  23589. {
  23590. wc_test_ret_t ret = 0;
  23591. WOLFSSL_ENTER("pwdbased_test");
  23592. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23593. ret = pbkdf1_test();
  23594. if (ret != 0)
  23595. return ret;
  23596. #endif
  23597. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23598. ret = pbkdf2_test();
  23599. if (ret != 0)
  23600. return ret;
  23601. #endif
  23602. #ifdef HAVE_PKCS12
  23603. ret = pkcs12_pbkdf_test();
  23604. if (ret != 0)
  23605. return ret;
  23606. #endif
  23607. #ifdef HAVE_SCRYPT
  23608. ret = scrypt_test();
  23609. if (ret != 0)
  23610. return ret;
  23611. #endif
  23612. return ret;
  23613. }
  23614. #endif /* NO_PWDBASED */
  23615. #if defined(USE_CERT_BUFFERS_2048) && \
  23616. defined(HAVE_PKCS12) && \
  23617. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  23618. !defined(NO_CERTS) && !defined(NO_DES3)
  23619. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
  23620. {
  23621. wc_test_ret_t ret = 0;
  23622. WC_PKCS12* pkcs12 = NULL;
  23623. /* Gen vars */
  23624. byte* pkcs12der = NULL;
  23625. int pkcs12derSz = 0;
  23626. WC_DerCertList derCaList = {
  23627. (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
  23628. };
  23629. char* pass = (char*)"wolfSSL test";
  23630. /* Parsing vars */
  23631. WC_DerCertList* derCaListOut = NULL;
  23632. byte* keyDer = NULL;
  23633. byte* certDer = NULL;
  23634. word32 keySz;
  23635. word32 certSz;
  23636. WOLFSSL_ENTER("pkcs12_test");
  23637. pkcs12 = wc_PKCS12_create(pass, (word32)XSTRLEN(pass),
  23638. (char*)"friendlyName" /* not used currently */,
  23639. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  23640. (byte*)server_cert_der_2048, sizeof_server_cert_der_2048,
  23641. &derCaList, PBE_SHA1_DES3, PBE_SHA1_DES3, 100, 100,
  23642. 0 /* not used currently */, HEAP_HINT);
  23643. if (pkcs12 == NULL) {
  23644. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23645. goto out;
  23646. }
  23647. ret = wc_i2d_PKCS12(pkcs12, NULL, &pkcs12derSz);
  23648. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  23649. if (ret == 0)
  23650. ret = WC_TEST_RET_ENC_NC;
  23651. else
  23652. ret = WC_TEST_RET_ENC_I(ret);
  23653. goto out;
  23654. }
  23655. pkcs12der = (byte*)XMALLOC(pkcs12derSz, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23656. if (pkcs12der == NULL) {
  23657. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23658. goto out;
  23659. }
  23660. {
  23661. /* Use tmp pointer to avoid advancing pkcs12der */
  23662. byte* tmp = pkcs12der;
  23663. ret = wc_i2d_PKCS12(pkcs12, &tmp, &pkcs12derSz);
  23664. if (ret <= 0) {
  23665. if (ret == 0)
  23666. ret = WC_TEST_RET_ENC_NC;
  23667. else
  23668. ret = WC_TEST_RET_ENC_I(ret);
  23669. goto out;
  23670. }
  23671. }
  23672. wc_PKCS12_free(pkcs12);
  23673. pkcs12 = wc_PKCS12_new_ex(HEAP_HINT);
  23674. if (pkcs12 == NULL) {
  23675. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23676. goto out;
  23677. }
  23678. /* convert the DER file into an internal structure */
  23679. ret = wc_d2i_PKCS12(pkcs12der, pkcs12derSz, pkcs12);
  23680. if (ret != 0) {
  23681. ret = WC_TEST_RET_ENC_EC(ret);
  23682. goto out;
  23683. }
  23684. /* parse the internal structure into its parts */
  23685. ret = wc_PKCS12_parse(pkcs12, "wolfSSL test", &keyDer, &keySz,
  23686. &certDer, &certSz, &derCaListOut);
  23687. if (ret != 0) {
  23688. ret = WC_TEST_RET_ENC_EC(ret);
  23689. goto out;
  23690. }
  23691. if (keyDer == NULL || certDer == NULL || derCaListOut == NULL) {
  23692. ret = WC_TEST_RET_ENC_NC;
  23693. goto out;
  23694. }
  23695. out:
  23696. if (derCaListOut)
  23697. wc_FreeCertList(derCaListOut, HEAP_HINT);
  23698. XFREE(keyDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23699. XFREE(certDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23700. if (pkcs12)
  23701. wc_PKCS12_free(pkcs12);
  23702. XFREE(pkcs12der, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23703. return ret;
  23704. }
  23705. #endif
  23706. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  23707. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  23708. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  23709. defined(WOLFSSL_AFALG_XILINX_RSA)
  23710. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  23711. static wc_test_ret_t hkdf_test(void)
  23712. #else
  23713. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void)
  23714. #endif
  23715. {
  23716. wc_test_ret_t ret = 0;
  23717. #if !defined(NO_SHA) || !defined(NO_SHA256)
  23718. int L;
  23719. byte okm1[42];
  23720. byte ikm1[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23721. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23722. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  23723. #ifndef HAVE_FIPS
  23724. byte salt1[13] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  23725. 0x08, 0x09, 0x0a, 0x0b, 0x0c };
  23726. byte info1[10] ={ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  23727. 0xf8, 0xf9 };
  23728. #endif
  23729. #ifndef NO_SHA
  23730. byte res1[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
  23731. 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
  23732. 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
  23733. 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
  23734. 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
  23735. 0x49, 0x18 };
  23736. #ifndef HAVE_FIPS
  23737. byte res2[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
  23738. 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
  23739. 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
  23740. 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
  23741. 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
  23742. 0xf8, 0x96 };
  23743. #endif
  23744. #endif /* !NO_SHA */
  23745. #ifndef NO_SHA256
  23746. byte res3[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
  23747. 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
  23748. 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
  23749. 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
  23750. 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
  23751. 0x96, 0xc8 };
  23752. #ifndef HAVE_FIPS
  23753. byte res4[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
  23754. 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
  23755. 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
  23756. 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
  23757. 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
  23758. 0x58, 0x65 };
  23759. #endif
  23760. #endif /* !NO_SHA256 */
  23761. WOLFSSL_ENTER("hkdf_test");
  23762. XMEMSET(okm1, 0, sizeof(okm1));
  23763. L = (int)sizeof(okm1);
  23764. #ifndef NO_SHA
  23765. ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23766. okm1, (word32)L);
  23767. if (ret != 0)
  23768. return WC_TEST_RET_ENC_EC(ret);
  23769. if (XMEMCMP(okm1, res1, L) != 0)
  23770. return WC_TEST_RET_ENC_NC;
  23771. #ifndef HAVE_FIPS
  23772. /* fips can't have key size under 14 bytes, salt is key too */
  23773. L = (int)sizeof(okm1);
  23774. ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1),
  23775. info1, (word32)sizeof(info1), okm1, (word32)L);
  23776. if (ret != 0)
  23777. return WC_TEST_RET_ENC_EC(ret);
  23778. if (XMEMCMP(okm1, res2, L) != 0)
  23779. return WC_TEST_RET_ENC_NC;
  23780. #endif /* HAVE_FIPS */
  23781. #endif /* !NO_SHA */
  23782. #ifndef NO_SHA256
  23783. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23784. okm1, (word32)L);
  23785. if (ret != 0)
  23786. return WC_TEST_RET_ENC_EC(ret);
  23787. if (XMEMCMP(okm1, res3, L) != 0)
  23788. return WC_TEST_RET_ENC_NC;
  23789. #ifndef HAVE_FIPS
  23790. /* fips can't have key size under 14 bytes, salt is key too */
  23791. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1),
  23792. salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, (word32)L);
  23793. if (ret != 0)
  23794. return WC_TEST_RET_ENC_EC(ret);
  23795. if (XMEMCMP(okm1, res4, L) != 0)
  23796. return WC_TEST_RET_ENC_NC;
  23797. #endif /* HAVE_FIPS */
  23798. #endif /* !NO_SHA256 */
  23799. #endif /* !NO_SHA || !NO_SHA256 */
  23800. return ret;
  23801. }
  23802. #endif /* HAVE_HKDF */
  23803. #ifdef WOLFSSL_WOLFSSH
  23804. typedef struct {
  23805. byte hashId;
  23806. byte keyId;
  23807. const byte* k;
  23808. word32 kSz;
  23809. const byte* h;
  23810. word32 hSz;
  23811. const byte* sessionId;
  23812. word32 sessionIdSz;
  23813. const byte* expectedKey;
  23814. word32 expectedKeySz;
  23815. } SshKdfTestVector;
  23816. /** Test Vector Set #3: SHA-256 **/
  23817. static const byte sshKdfTvSet3k[] = {
  23818. 0x6A, 0xC3, 0x82, 0xEA, 0xAC, 0xA0, 0x93, 0xE1,
  23819. 0x25, 0xE2, 0x5C, 0x24, 0xBE, 0xBC, 0x84, 0x64,
  23820. 0x0C, 0x11, 0x98, 0x75, 0x07, 0x34, 0x4B, 0x5C,
  23821. 0x73, 0x9C, 0xEB, 0x84, 0xA9, 0xE0, 0xB2, 0x22,
  23822. 0xB9, 0xA8, 0xB5, 0x1C, 0x83, 0x9E, 0x5E, 0xBE,
  23823. 0x49, 0xCF, 0xAD, 0xBF, 0xB3, 0x95, 0x99, 0x76,
  23824. 0x4E, 0xD5, 0x22, 0x09, 0x9D, 0xC9, 0x12, 0x75,
  23825. 0x19, 0x50, 0xDC, 0x7D, 0xC9, 0x7F, 0xBD, 0xC0,
  23826. 0x63, 0x28, 0xB6, 0x8F, 0x22, 0x78, 0x1F, 0xD3,
  23827. 0x15, 0xAF, 0x56, 0x80, 0x09, 0xA5, 0x50, 0x9E,
  23828. 0x5B, 0x87, 0xA1, 0x1B, 0xF5, 0x27, 0xC0, 0x56,
  23829. 0xDA, 0xFF, 0xD8, 0x2A, 0xB6, 0xCB, 0xC2, 0x5C,
  23830. 0xCA, 0x37, 0x14, 0x34, 0x59, 0xE7, 0xBC, 0x63,
  23831. 0xBC, 0xDE, 0x52, 0x75, 0x7A, 0xDE, 0xB7, 0xDF,
  23832. 0x01, 0xCF, 0x12, 0x17, 0x3F, 0x1F, 0xEF, 0x81,
  23833. 0x02, 0xEC, 0x5A, 0xB1, 0x42, 0xC2, 0x13, 0xDD,
  23834. 0x9D, 0x30, 0x69, 0x62, 0x78, 0xA8, 0xD8, 0xBC,
  23835. 0x32, 0xDD, 0xE9, 0x59, 0x2D, 0x28, 0xC0, 0x78,
  23836. 0xC6, 0xD9, 0x2B, 0x94, 0x7D, 0x82, 0x5A, 0xCA,
  23837. 0xAB, 0x64, 0x94, 0x84, 0x6A, 0x49, 0xDE, 0x24,
  23838. 0xB9, 0x62, 0x3F, 0x48, 0x89, 0xE8, 0xAD, 0xC3,
  23839. 0x8E, 0x8C, 0x66, 0x9E, 0xFF, 0xEF, 0x17, 0x60,
  23840. 0x40, 0xAD, 0x94, 0x5E, 0x90, 0xA7, 0xD3, 0xEE,
  23841. 0xC1, 0x5E, 0xFE, 0xEE, 0x78, 0xAE, 0x71, 0x04,
  23842. 0x3C, 0x96, 0x51, 0x11, 0x03, 0xA1, 0x6B, 0xA7,
  23843. 0xCA, 0xF0, 0xAC, 0xD0, 0x64, 0x2E, 0xFD, 0xBE,
  23844. 0x80, 0x99, 0x34, 0xFA, 0xA1, 0xA5, 0xF1, 0xBD,
  23845. 0x11, 0x04, 0x36, 0x49, 0xB2, 0x5C, 0xCD, 0x1F,
  23846. 0xEE, 0x2E, 0x38, 0x81, 0x5D, 0x4D, 0x5F, 0x5F,
  23847. 0xC6, 0xB4, 0x10, 0x29, 0x69, 0xF2, 0x1C, 0x22,
  23848. 0xAE, 0x1B, 0x0E, 0x7D, 0x36, 0x03, 0xA5, 0x56,
  23849. 0xA1, 0x32, 0x62, 0xFF, 0x62, 0x8D, 0xE2, 0x22
  23850. };
  23851. static const byte sshKdfTvSet3h[] = {
  23852. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23853. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23854. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23855. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23856. };
  23857. static const byte sshKdfTvSet3sid[] = {
  23858. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23859. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23860. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23861. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23862. };
  23863. static const byte sshKdfTvSet3a[] = {
  23864. 0x81, 0xF0, 0x33, 0x0E, 0xF6, 0xF0, 0x53, 0x61,
  23865. 0xB3, 0x82, 0x3B, 0xFD, 0xED, 0x6E, 0x1D, 0xE9
  23866. };
  23867. static const byte sshKdfTvSet3b[] = {
  23868. 0x3F, 0x6F, 0xD2, 0x06, 0x5E, 0xEB, 0x2B, 0x0B,
  23869. 0x1D, 0x93, 0x19, 0x5A, 0x1F, 0xED, 0x48, 0xA5
  23870. };
  23871. static const byte sshKdfTvSet3c[] = {
  23872. 0xC3, 0x54, 0x71, 0x03, 0x4E, 0x6F, 0xD6, 0x54,
  23873. 0x76, 0x13, 0x17, 0x8E, 0x23, 0x43, 0x5F, 0x21
  23874. };
  23875. static const byte sshKdfTvSet3d[] = {
  23876. 0x7E, 0x9D, 0x79, 0x03, 0x20, 0x90, 0xD9, 0x9F,
  23877. 0x98, 0xB0, 0x15, 0x63, 0x4D, 0xD9, 0xF4, 0x62
  23878. };
  23879. static const byte sshKdfTvSet3e[] = {
  23880. 0x24, 0xEE, 0x55, 0x9A, 0xD7, 0xCE, 0x71, 0x2B,
  23881. 0x68, 0x5D, 0x0B, 0x22, 0x71, 0xE4, 0x43, 0xC1,
  23882. 0x7A, 0xB1, 0xD1, 0xDC, 0xEB, 0x5A, 0x36, 0x05,
  23883. 0x69, 0xD2, 0x5D, 0x5D, 0xC2, 0x43, 0x00, 0x2F
  23884. };
  23885. static const byte sshKdfTvSet3f[] = {
  23886. 0xC3, 0x41, 0x9C, 0x2B, 0x96, 0x62, 0x35, 0x86,
  23887. 0x9D, 0x71, 0x4B, 0xA5, 0xAC, 0x48, 0xDD, 0xB7,
  23888. 0xD9, 0xE3, 0x5C, 0x8C, 0x19, 0xAA, 0xC7, 0x34,
  23889. 0x22, 0x33, 0x7A, 0x37, 0x34, 0x53, 0x60, 0x7E
  23890. };
  23891. static const SshKdfTestVector sshKdfTestVectors[] = {
  23892. {WC_HASH_TYPE_SHA256, 'A',
  23893. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23894. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23895. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23896. sshKdfTvSet3a, sizeof(sshKdfTvSet3a)},
  23897. {WC_HASH_TYPE_SHA256, 'B',
  23898. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23899. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23900. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23901. sshKdfTvSet3b, sizeof(sshKdfTvSet3b)},
  23902. {WC_HASH_TYPE_SHA256, 'C',
  23903. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23904. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23905. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23906. sshKdfTvSet3c, sizeof(sshKdfTvSet3c)},
  23907. {WC_HASH_TYPE_SHA256, 'D',
  23908. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23909. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23910. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23911. sshKdfTvSet3d, sizeof(sshKdfTvSet3d)},
  23912. {WC_HASH_TYPE_SHA256, 'E',
  23913. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23914. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23915. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23916. sshKdfTvSet3e, sizeof(sshKdfTvSet3e)},
  23917. {WC_HASH_TYPE_SHA256, 'F',
  23918. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23919. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23920. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23921. sshKdfTvSet3f, sizeof(sshKdfTvSet3f)},
  23922. };
  23923. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
  23924. {
  23925. byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and AES_BLOCK_SIZE */
  23926. word32 i;
  23927. word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector);
  23928. const SshKdfTestVector* tv = NULL;
  23929. wc_test_ret_t result = 0;
  23930. WOLFSSL_ENTER("sshkdf_test");
  23931. /* sId - Session ID, eKey - Expected Key, cKey - Calculated Key */
  23932. for (i = 0, tv = sshKdfTestVectors; i < tc; i++, tv++) {
  23933. result = wc_SSH_KDF(tv->hashId, tv->keyId,
  23934. cKey, tv->expectedKeySz,
  23935. tv->k, tv->kSz, tv->h, tv->hSz,
  23936. tv->sessionId, tv->sessionIdSz);
  23937. if (result != 0) {
  23938. printf("KDF: Could not derive key.\n");
  23939. result = WC_TEST_RET_ENC_EC(result);
  23940. }
  23941. else {
  23942. if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) {
  23943. printf("KDF: Calculated Key does not match Expected Key.\n");
  23944. result = WC_TEST_RET_ENC_EC(result);
  23945. }
  23946. }
  23947. if (result != 0) break;
  23948. }
  23949. return result;
  23950. }
  23951. #endif /* WOLFSSL_WOLFSSH */
  23952. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  23953. #define DIGL 12
  23954. #define SECL 48
  23955. #define LBSL 63
  23956. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
  23957. {
  23958. int ret;
  23959. byte dig[DIGL] = {0};
  23960. byte secret[SECL] = {
  23961. 0x10, 0xbc, 0xb4, 0xa2, 0xe8, 0xdc, 0xf1, 0x9b, 0x4c,
  23962. 0x51, 0x9c, 0xed, 0x31, 0x1b, 0x51, 0x57, 0x02, 0x3f,
  23963. 0xa1, 0x7d, 0xfb, 0x0e, 0xf3, 0x4e, 0x8f, 0x6f, 0x71,
  23964. 0xa3, 0x67, 0x76, 0x6b, 0xfa, 0x5d, 0x46, 0x4a, 0xe8,
  23965. 0x61, 0x18, 0x81, 0xc4, 0x66, 0xcc, 0x6f, 0x09, 0x99,
  23966. 0x9d, 0xfc, 0x47
  23967. };
  23968. byte lablSd[LBSL] = {
  23969. 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69,
  23970. 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x0b, 0x46, 0xba,
  23971. 0x56, 0xbf, 0x1f, 0x5d, 0x99, 0xff, 0xe9, 0xbb, 0x43,
  23972. 0x01, 0xe7, 0xca, 0x2c, 0x00, 0xdf, 0x9a, 0x39, 0x6e,
  23973. 0xcf, 0x6d, 0x15, 0x27, 0x4d, 0xf2, 0x93, 0x96, 0x4a,
  23974. 0x91, 0xde, 0x5c, 0xc0, 0x47, 0x7c, 0xa8, 0xae, 0xcf,
  23975. 0x5d, 0x93, 0x5f, 0x4c, 0x92, 0xcc, 0x98, 0x5b, 0x43
  23976. };
  23977. byte expected[DIGL] = {
  23978. 0xee, 0xcb, 0xb1, 0x30, 0xf2, 0xcd, 0xb3, 0x4a,
  23979. 0xbe, 0xda, 0xc1, 0xf6
  23980. };
  23981. int digL = DIGL;
  23982. int secL = SECL;
  23983. int lblsdL = LBSL;
  23984. int hash_type = sha384_mac;
  23985. ret = wc_PRF(dig, (word32)digL, secret, secL, lablSd, lblsdL, hash_type,
  23986. HEAP_HINT, INVALID_DEVID);
  23987. if (ret != 0) {
  23988. printf("Failed w/ code: %d\n", ret);
  23989. return WC_TEST_RET_ENC_EC(ret);
  23990. }
  23991. if (XMEMCMP(expected, dig, DIGL) != 0) {
  23992. printf("Got unexpected digest\n");
  23993. return WC_TEST_RET_ENC_NC;
  23994. }
  23995. return 0;
  23996. }
  23997. #endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
  23998. #ifdef WOLFSSL_HAVE_PRF
  23999. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  24000. #ifdef WOLFSSL_BASE16
  24001. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
  24002. {
  24003. const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
  24004. "4E6C2E6C34A165B24540E2970875D641"
  24005. "2AA6515871B389B4C199BB8389C71CED";
  24006. const char* helloRandom = "162B81EDFBEAE4F25240320B87E7651C"
  24007. "865564191DD782DB0B9ECA275FBA1BB9"
  24008. "5A1DA3DF436D68DA86C5E7B4B4A36E46"
  24009. "B977C61767983A31BE270D74517BD0F6";
  24010. const char* masterSecret = "EB38B8D89B98B1C266DE44BB3CA14E83"
  24011. "C32F009F9955B1D994E61D3C51EE8760"
  24012. "90B4EF89CC7AF42F46E72201BFCC7977";
  24013. const char* label = "master secret";
  24014. byte pms[48] = {0};
  24015. byte seed[64] = {0};
  24016. byte ms[48] = {0};
  24017. byte result[48] = {0};
  24018. word32 pmsSz = (word32)sizeof(pms);
  24019. word32 seedSz = (word32)sizeof(seed);
  24020. word32 msSz = (word32)sizeof(ms);
  24021. int ret;
  24022. ret = Base16_Decode((const byte*)preMasterSecret,
  24023. (word32)XSTRLEN(preMasterSecret), pms, &pmsSz);
  24024. if (ret != 0)
  24025. return ret;
  24026. ret = Base16_Decode((const byte*)helloRandom,
  24027. (word32)XSTRLEN(helloRandom), seed, &seedSz);
  24028. if (ret != 0)
  24029. return ret;
  24030. ret = Base16_Decode((const byte*)masterSecret,
  24031. (word32)XSTRLEN(masterSecret), ms, &msSz);
  24032. if (ret != 0)
  24033. return ret;
  24034. ret = wc_PRF_TLS(result, msSz, pms, pmsSz,
  24035. (const byte*)label, (word32)XSTRLEN(label), seed, seedSz,
  24036. 1, sha256_mac, NULL, INVALID_DEVID);
  24037. if (ret != 0) {
  24038. if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
  24039. printf(" wc_PRF_TLSv12: Private key locked.\n");
  24040. }
  24041. return WC_TEST_RET_ENC_NC;
  24042. }
  24043. if (XMEMCMP(result, ms, msSz) != 0)
  24044. return WC_TEST_RET_ENC_NC;
  24045. return 0;
  24046. }
  24047. #endif /* WOLFSSL_BASE16 */
  24048. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  24049. #endif /* WOLFSSL_HAVE_PRF */
  24050. #ifdef WOLFSSL_TLS13
  24051. #define TLSV13_PSK_DHE_SZ 40
  24052. typedef struct {
  24053. enum wc_HashType hashAlg;
  24054. word32 pskSz;
  24055. word32 dheSz;
  24056. byte psk[TLSV13_PSK_DHE_SZ];
  24057. byte dhe[TLSV13_PSK_DHE_SZ];
  24058. byte hashHello1[WC_MAX_DIGEST_SIZE];
  24059. byte hashHello2[WC_MAX_DIGEST_SIZE];
  24060. byte hashFinished1[WC_MAX_DIGEST_SIZE];
  24061. byte hashFinished2[WC_MAX_DIGEST_SIZE];
  24062. /* Expected */
  24063. byte clientEarlyTrafficSecret[WC_MAX_DIGEST_SIZE];
  24064. byte earlyExporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24065. byte clientHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24066. byte serverHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24067. byte clientApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24068. byte serverApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24069. byte exporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24070. byte resumptionMasterSecret[WC_MAX_DIGEST_SIZE];
  24071. } Tls13KdfTestVector;
  24072. /* The following tests come from the CAVP test vectors we used for
  24073. * our FIPS validation. The hash values used are the components from
  24074. * the test hashed together. hashHello1 is the hash of the
  24075. * clientHelloRandom value of the test vector. hashHello2 is the hash
  24076. * of the clientHelloRandom and serverHelloRandom values from the test
  24077. * vector. hashFinished1 is clientHelloRandom, serverHelloRandom, and
  24078. * serverFinishedRandom. hashFinished2 is clientHelloRandom,
  24079. * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom
  24080. * hashed together. */
  24081. static const Tls13KdfTestVector tls13KdfTestVectors[] = {
  24082. { /* 1 */
  24083. WC_HASH_TYPE_SHA256, 35, 35,
  24084. { /* PSK */
  24085. 0x7b, 0xf1, 0x05, 0x31, 0x36, 0xfa, 0x03, 0xdc,
  24086. 0x31, 0x97, 0x88, 0x04, 0x9c, 0xbc, 0xee, 0xf7,
  24087. 0x8d, 0x84, 0x95, 0x26, 0xaf, 0x1d, 0x68, 0xb0,
  24088. 0x60, 0x7a, 0xcc, 0x4f, 0xc1, 0xd3, 0xa1, 0x68,
  24089. 0x7f, 0x6d, 0xbe
  24090. },
  24091. { /* DHE */
  24092. 0x6e, 0xa1, 0x77, 0xab, 0x2f, 0x43, 0xd2, 0x4b,
  24093. 0xe5, 0xa1, 0x09, 0xe0, 0x7a, 0xd0, 0x01, 0x35,
  24094. 0x8d, 0xf8, 0xf2, 0x5c, 0x91, 0x02, 0xb0, 0x6c,
  24095. 0x3f, 0xeb, 0xee, 0xa4, 0x42, 0x19, 0xce, 0xdc,
  24096. 0x81, 0x26, 0x40
  24097. },
  24098. { /* Hello 1 */
  24099. 0xd9, 0x4b, 0xe4, 0x17, 0xef, 0x58, 0x73, 0x7d,
  24100. 0x28, 0x3d, 0xf0, 0xcc, 0x05, 0x03, 0xaf, 0xac,
  24101. 0x3d, 0x92, 0x79, 0x48, 0xe8, 0x8c, 0xdb, 0xce,
  24102. 0x95, 0x82, 0x21, 0x31, 0x7b, 0x61, 0xd7, 0xc6
  24103. },
  24104. { /* Hello 2 */
  24105. 0xb7, 0x7f, 0x29, 0x91, 0xa4, 0x8b, 0x34, 0xdb,
  24106. 0xbd, 0xc7, 0x54, 0x1c, 0x3b, 0x86, 0xa3, 0x69,
  24107. 0xfe, 0x26, 0xe4, 0x7b, 0xac, 0x57, 0x71, 0xb3,
  24108. 0x32, 0x97, 0xed, 0xd2, 0x0e, 0x95, 0xb8, 0x63
  24109. },
  24110. { /* Finished 1 */
  24111. 0x65, 0xdb, 0x6d, 0x71, 0x71, 0xd0, 0xd8, 0x49,
  24112. 0xd0, 0x3c, 0x8e, 0x2b, 0x24, 0xdf, 0xc2, 0xe9,
  24113. 0xd6, 0xfd, 0xea, 0x04, 0x95, 0x7c, 0xf0, 0x7e,
  24114. 0x57, 0x74, 0x7c, 0xdd, 0xa3, 0x0b, 0x2b, 0x36
  24115. },
  24116. { /* Finished 2 */
  24117. 0x28, 0xf2, 0xf2, 0x79, 0xcf, 0x20, 0x52, 0x90,
  24118. 0x1d, 0x91, 0x05, 0xad, 0x44, 0x26, 0x23, 0x96,
  24119. 0x32, 0xce, 0xec, 0x61, 0xd1, 0xbf, 0x00, 0x48,
  24120. 0x4a, 0xa5, 0x60, 0xcc, 0x28, 0xb5, 0x8d, 0x98
  24121. },
  24122. { /* Client Early Traffic Secret */
  24123. 0x07, 0x14, 0x6a, 0x26, 0x5b, 0x6c, 0x7f, 0x4d, 0x6b, 0x47, 0x3f, 0xd5,
  24124. 0x03, 0x1d, 0xd2, 0x23, 0x3d, 0x89, 0x3e, 0xc6, 0x51, 0xd1, 0xac, 0xf8,
  24125. 0x28, 0xae, 0x4b, 0x76, 0xc8, 0x10, 0x7e, 0xdd
  24126. },
  24127. { /* Early Exporter Master Secret */
  24128. 0xb8, 0xd3, 0x25, 0x7e, 0x2d, 0x41, 0x7b, 0xcb, 0x5e, 0x82, 0x49, 0xf5,
  24129. 0x51, 0x3d, 0xb7, 0x59, 0x32, 0xb3, 0xdf, 0x99, 0x4e, 0x04, 0x69, 0xc6,
  24130. 0x96, 0x8e, 0xe6, 0x3d, 0x91, 0xe4, 0x81, 0x11
  24131. },
  24132. { /* Client Handshake Traffic Secret */
  24133. 0xd9, 0x3b, 0x54, 0xe2, 0xb0, 0xd1, 0x85, 0xf0, 0xfd, 0xf3, 0x48, 0x4a,
  24134. 0xf8, 0x0b, 0xa5, 0xdc, 0x4c, 0x37, 0xcb, 0xd4, 0x20, 0xaf, 0x60, 0xc7,
  24135. 0xd5, 0x50, 0x5d, 0x0c, 0x77, 0x3b, 0x6f, 0xd2
  24136. },
  24137. { /* Server Handshake Traffic Secret */
  24138. 0x4d, 0x40, 0x2b, 0xd2, 0x8c, 0x33, 0x90, 0x39, 0x67, 0x67, 0x05, 0xf7,
  24139. 0x5d, 0x37, 0x1e, 0xdc, 0x4a, 0x70, 0x6b, 0x9e, 0xf8, 0x06, 0x61, 0x89,
  24140. 0x70, 0xe1, 0x3d, 0x36, 0xad, 0x88, 0x7e, 0x5b
  24141. },
  24142. { /* Client Application Traffic Secret */
  24143. 0x74, 0x6e, 0xa0, 0x13, 0x18, 0x34, 0x48, 0x4d, 0x23, 0x31, 0xf1, 0xf9,
  24144. 0xee, 0x44, 0x6d, 0xad, 0xc1, 0xad, 0x92, 0x73, 0xca, 0x27, 0x16, 0x91,
  24145. 0xa2, 0x50, 0x9a, 0xfc, 0xec, 0xf0, 0x6b, 0x24
  24146. },
  24147. { /* Server Application Traffic Secret */
  24148. 0x89, 0x18, 0x7e, 0x34, 0x8d, 0xfc, 0x14, 0xb1, 0x4f, 0x21, 0xd8, 0x29,
  24149. 0xdb, 0x9b, 0xfb, 0x55, 0xcf, 0xa1, 0x4f, 0x95, 0xf8, 0xe0, 0xb0, 0x83,
  24150. 0xd5, 0x34, 0x9e, 0x0b, 0x83, 0x37, 0x42, 0x93
  24151. },
  24152. { /* Exporter Master Secret */
  24153. 0x7d, 0xc8, 0x88, 0x46, 0xd5, 0x57, 0x15, 0xb6, 0x24, 0x25, 0x92, 0x61,
  24154. 0xb1, 0x18, 0x86, 0x2a, 0x6d, 0xa5, 0x84, 0xeb, 0x59, 0xdf, 0x13, 0xbd,
  24155. 0x73, 0xaa, 0x5d, 0x65, 0xab, 0xd9, 0xb4, 0x56
  24156. },
  24157. { /* Resumption Master Secret */
  24158. 0x20, 0xb7, 0xd0, 0xe3, 0x82, 0x01, 0xa1, 0x04, 0xb8, 0x13, 0x29, 0xed,
  24159. 0x35, 0xe4, 0x2f, 0xbf, 0x58, 0x23, 0x7f, 0x21, 0xdb, 0x9f, 0xf8, 0xe0,
  24160. 0xe8, 0xe4, 0xab, 0xc4, 0xa1, 0x61, 0xb9, 0xbb
  24161. }
  24162. },
  24163. { /* 6 */
  24164. WC_HASH_TYPE_SHA256, 0, 33,
  24165. { 0 }, /* PSK */
  24166. { /* DHE */
  24167. 0x7a, 0x46, 0x8c, 0x5a, 0xd1, 0x8e, 0x95, 0xba,
  24168. 0x61, 0xe6, 0x6f, 0xe6, 0x76, 0x0c, 0x20, 0x43,
  24169. 0x16, 0x82, 0x15, 0xfe, 0x54, 0xa3, 0xc7, 0xfd,
  24170. 0x3b, 0x2c, 0x88, 0xb4, 0xd3, 0x42, 0x70, 0x12,
  24171. 0x18
  24172. },
  24173. { /* Hello 1 */
  24174. 0x63, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
  24175. 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
  24176. 0x7d, 0x5b, 0x42, 0xdc, 0xa8, 0xaa, 0x06, 0xfb,
  24177. 0x20, 0xa5, 0xbb, 0x85, 0xdb, 0x54, 0xd8, 0x8b
  24178. },
  24179. { /* Hello 2 */
  24180. 0xea, 0xfe, 0x9e, 0x8e, 0xff, 0x1f, 0x6f, 0x43,
  24181. 0xf9, 0x5d, 0xfd, 0xbf, 0xe2, 0x5f, 0x02, 0x2f,
  24182. 0x6d, 0x47, 0x60, 0x9a, 0x48, 0x9a, 0x75, 0xfb,
  24183. 0xb5, 0x4a, 0xbf, 0x9c, 0x4e, 0xff, 0xbf, 0x0b
  24184. },
  24185. { /* Finished 1 */
  24186. 0xca, 0x25, 0xb3, 0x53, 0x8e, 0x6d, 0xc3, 0x36,
  24187. 0x17, 0x30, 0x07, 0xdf, 0x0d, 0xd7, 0x79, 0xb0,
  24188. 0x7f, 0xcb, 0xbe, 0x7a, 0xbc, 0x2d, 0x9f, 0x2d,
  24189. 0x94, 0x44, 0x94, 0xe6, 0xa4, 0xf3, 0xe8, 0x53
  24190. },
  24191. { /* Finished 2 */
  24192. 0x2e, 0xa6, 0x5a, 0xaf, 0xb5, 0xba, 0x9f, 0x2f,
  24193. 0x74, 0x83, 0x5d, 0xbf, 0x86, 0xa4, 0xa6, 0xf6,
  24194. 0xb9, 0x89, 0xdf, 0x17, 0xe1, 0xa8, 0x14, 0xc0,
  24195. 0xe1, 0x50, 0xfa, 0xec, 0xfa, 0xae, 0x8b, 0x7b
  24196. },
  24197. {
  24198. 0x20, 0x18, 0x72, 0x7c, 0xde, 0x3a, 0x85, 0x17, 0x72, 0xdc, 0xd7, 0x72,
  24199. 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
  24200. 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
  24201. },
  24202. {
  24203. 0x68, 0x10, 0x20, 0xd1, 0x5e, 0xfc, 0x0c, 0x53, 0x85, 0xbb, 0xdb, 0x18,
  24204. 0xa8, 0x78, 0xf1, 0x2b, 0x13, 0xba, 0x64, 0x1d, 0xe7, 0x09, 0xbe, 0x13,
  24205. 0x49, 0x26, 0xf9, 0x98, 0x56, 0xf1, 0x43, 0xfb
  24206. },
  24207. {
  24208. 0x24, 0x35, 0x3e, 0x10, 0x6f, 0x39, 0x50, 0xd6, 0xa2, 0x12, 0x99, 0xf2,
  24209. 0xd5, 0xf5, 0x19, 0xf5, 0x84, 0xed, 0xee, 0x78, 0x2a, 0xa6, 0xfa, 0x3d,
  24210. 0x06, 0xa8, 0xa7, 0x5d, 0x97, 0x78, 0xd6, 0x58
  24211. },
  24212. {
  24213. 0xf4, 0x57, 0xac, 0x24, 0x7a, 0xfb, 0x7c, 0x3b, 0xb6, 0x39, 0x17, 0x14,
  24214. 0xd9, 0xd4, 0x58, 0x4d, 0x46, 0xd5, 0x1b, 0xde, 0xf7, 0x9d, 0x06, 0xee,
  24215. 0x8d, 0x1a, 0x2c, 0x25, 0x6d, 0x64, 0xde, 0x89
  24216. },
  24217. {
  24218. 0xb6, 0x00, 0xce, 0x63, 0xed, 0x65, 0x8b, 0x66, 0x66, 0x42, 0xc6, 0xbd,
  24219. 0x89, 0xc4, 0x71, 0x6f, 0xce, 0x28, 0xb2, 0xac, 0x97, 0x07, 0x5b, 0xea,
  24220. 0xb8, 0x1d, 0x4c, 0xeb, 0x9e, 0x71, 0x07, 0x8f
  24221. },
  24222. {
  24223. 0xf8, 0x92, 0xc8, 0xba, 0xe7, 0x83, 0xfe, 0x68, 0xe4, 0xd6, 0x5e, 0xcb,
  24224. 0xb3, 0xef, 0x49, 0xd0, 0xe7, 0xb1, 0xac, 0xcb, 0x39, 0x19, 0xfd, 0xa7,
  24225. 0xf7, 0xca, 0xab, 0x1e, 0x42, 0x14, 0xd8, 0xe7
  24226. },
  24227. {
  24228. 0x32, 0x4a, 0x1a, 0xad, 0xe2, 0xbb, 0x55, 0x8a, 0xdd, 0xe9, 0xa5, 0x2a,
  24229. 0x46, 0x5e, 0x6c, 0x83, 0x66, 0x27, 0x27, 0x94, 0xdd, 0x68, 0x59, 0xa0,
  24230. 0xbb, 0xe8, 0x31, 0x7c, 0x39, 0xd7, 0xfd, 0x6d
  24231. },
  24232. {
  24233. 0x58, 0xbc, 0x6c, 0x5b, 0x24, 0xad, 0x82, 0xb3, 0xcc, 0xc7, 0xd1, 0xa1,
  24234. 0xaa, 0x2b, 0x98, 0x9f, 0x2f, 0x7e, 0xa9, 0x63, 0xc2, 0x8e, 0xb6, 0x06,
  24235. 0xc2, 0x2b, 0x74, 0x4b, 0x79, 0x19, 0x7e, 0x2e
  24236. }
  24237. },
  24238. { /* 11 */
  24239. WC_HASH_TYPE_SHA256, 33, 0,
  24240. { /* PSK */
  24241. 0x3d, 0x39, 0x49, 0x36, 0x98, 0xc5, 0xfd, 0xcd,
  24242. 0xa0, 0x17, 0xbd, 0x65, 0x0a, 0xdb, 0xd4, 0x07,
  24243. 0x56, 0xa2, 0x7b, 0xb8, 0x2a, 0x7e, 0xfb, 0x26,
  24244. 0x74, 0xe1, 0xbc, 0x08, 0x4b, 0xf0, 0x30, 0x14,
  24245. 0x12
  24246. },
  24247. { 0 }, /* DHE */
  24248. { /* Hello 1 */
  24249. 0xb7, 0x44, 0x74, 0x6c, 0x57, 0x1f, 0xf3, 0x84,
  24250. 0x8f, 0x63, 0xfb, 0x8c, 0x94, 0x6c, 0x16, 0x68,
  24251. 0x4b, 0xe1, 0xb5, 0xb5, 0x2a, 0x4e, 0x5f, 0xdf,
  24252. 0x4b, 0x53, 0xb2, 0x35, 0xfc, 0x30, 0xf1, 0x36
  24253. },
  24254. { /* Hello 2 */
  24255. 0xe6, 0x4f, 0x3a, 0x4f, 0xd7, 0xe0, 0x64, 0xd4,
  24256. 0x69, 0x50, 0xe4, 0x8b, 0xba, 0xbc, 0x47, 0x74,
  24257. 0xa7, 0x9b, 0x40, 0x91, 0x8f, 0xa8, 0x72, 0x22,
  24258. 0x97, 0xad, 0x43, 0xa7, 0x11, 0x86, 0xb5, 0x72
  24259. },
  24260. { /* Finished 1 */
  24261. 0x5f, 0xa6, 0x10, 0xe2, 0xa3, 0x99, 0x0b, 0x5e,
  24262. 0x57, 0xee, 0xc3, 0x3a, 0x8e, 0x04, 0xf3, 0x0e,
  24263. 0x58, 0x02, 0x09, 0xb2, 0x7e, 0x2d, 0xc6, 0xd2,
  24264. 0x08, 0xae, 0x68, 0x0a, 0x55, 0xa5, 0xda, 0x51
  24265. },
  24266. { /* Finished 2 */
  24267. 0xfc, 0x5b, 0xc0, 0x7e, 0x1b, 0xaa, 0xc0, 0xb4,
  24268. 0x34, 0x85, 0x49, 0x8e, 0x16, 0x31, 0x98, 0xdf,
  24269. 0x10, 0x54, 0x22, 0xda, 0x1e, 0x6b, 0x51, 0xf6,
  24270. 0x97, 0x57, 0xa0, 0x7a, 0x92, 0xe7, 0x47, 0x52
  24271. },
  24272. {
  24273. 0x80, 0xfa, 0x36, 0x30, 0xb8, 0x65, 0xb3, 0x2a, 0x1d, 0x68, 0x91, 0x06,
  24274. 0x98, 0xa0, 0x17, 0x8f, 0xee, 0xb7, 0x9e, 0x3d, 0xd8, 0x84, 0x99, 0x30,
  24275. 0xb9, 0xd6, 0x09, 0x25, 0x5e, 0xfb, 0x8f, 0xd3 },
  24276. {
  24277. 0xa9, 0x89, 0x29, 0x70, 0xe4, 0x55, 0xec, 0x97, 0xfb, 0x24, 0x5b, 0xf9,
  24278. 0xf1, 0xa3, 0x19, 0x3d, 0xf1, 0x31, 0x14, 0xcd, 0x2a, 0xed, 0x21, 0xc8,
  24279. 0xb1, 0x53, 0xad, 0x11, 0x0b, 0x9e, 0x5a, 0xee },
  24280. {
  24281. 0x72, 0xad, 0x8d, 0x7f, 0xfc, 0xb7, 0x68, 0xda, 0x27, 0x60, 0x37, 0xa3,
  24282. 0x4a, 0x63, 0xe8, 0xa5, 0xc8, 0xcd, 0x36, 0x6a, 0x77, 0x99, 0x0d, 0xa9,
  24283. 0xb1, 0x5b, 0x2f, 0x47, 0x2e, 0x22, 0xa7, 0x5e },
  24284. {
  24285. 0x95, 0x6e, 0x85, 0x09, 0xe5, 0x04, 0x88, 0x14, 0x28, 0x8d, 0xdf, 0xe6,
  24286. 0x0d, 0x0f, 0x0d, 0x6b, 0x4e, 0x66, 0x1c, 0x03, 0xb9, 0xaa, 0x2d, 0x45,
  24287. 0x56, 0x67, 0x5c, 0x55, 0x29, 0xd6, 0x89, 0xd0 },
  24288. {
  24289. 0xe8, 0xf2, 0x14, 0xf9, 0x9b, 0x2b, 0x9f, 0x24, 0x2b, 0x37, 0xbe, 0x86,
  24290. 0xdb, 0x23, 0x4b, 0xbe, 0x39, 0x57, 0xe8, 0xa9, 0xa5, 0xee, 0x08, 0xf2,
  24291. 0x75, 0x58, 0xdb, 0xd9, 0x51, 0xc1, 0x46, 0x02 },
  24292. {
  24293. 0x3d, 0x19, 0xaf, 0xa3, 0x0b, 0x21, 0xf7, 0x3d, 0xe7, 0x37, 0x6e, 0x32,
  24294. 0x13, 0x48, 0x9d, 0xea, 0xe0, 0x90, 0xbf, 0x64, 0x48, 0xf7, 0x1e, 0xcc,
  24295. 0xf0, 0xbc, 0x92, 0xd7, 0x8a, 0x4a, 0xa8, 0xc1 },
  24296. {
  24297. 0x16, 0x35, 0xb1, 0x66, 0x28, 0xa3, 0x3e, 0x19, 0xf5, 0x2d, 0x92, 0x22,
  24298. 0x95, 0x48, 0xe8, 0x34, 0x7b, 0x30, 0x50, 0xa2, 0xa0, 0xd9, 0xc2, 0x59,
  24299. 0x39, 0xf9, 0x8c, 0x69, 0xf2, 0x2a, 0xb9, 0xff },
  24300. {
  24301. 0x32, 0x71, 0xa6, 0x87, 0x0c, 0x97, 0x42, 0x07, 0xdd, 0x5f, 0xc9, 0x44,
  24302. 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b,
  24303. 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 }
  24304. },
  24305. #ifdef WOLFSSL_SHA384
  24306. { /* 26 */
  24307. WC_HASH_TYPE_SHA384, 35, 35,
  24308. { /* PSK */
  24309. 0x62, 0x83, 0x25, 0xc7, 0xcc, 0x08, 0x5e, 0x63,
  24310. 0x64, 0x56, 0xf0, 0xc6, 0x88, 0x27, 0x5a, 0x5b,
  24311. 0x68, 0x59, 0x0b, 0x14, 0x55, 0x13, 0x2e, 0xfd,
  24312. 0x8f, 0x28, 0x5b, 0x3d, 0xe3, 0xad, 0x67, 0xe4,
  24313. 0x68, 0xba, 0xf9
  24314. },
  24315. { /* DHE */
  24316. 0xa8, 0xb1, 0xab, 0xd8, 0xc8, 0x5b, 0x52, 0xdf,
  24317. 0x7f, 0x49, 0x10, 0xf4, 0xa1, 0x31, 0xd1, 0x91,
  24318. 0x36, 0xc1, 0x87, 0x5d, 0x42, 0x2a, 0xe7, 0x1d,
  24319. 0x2c, 0x29, 0x3d, 0x40, 0x64, 0x61, 0x63, 0x76,
  24320. 0xd8, 0x66, 0xac
  24321. },
  24322. { /* Hello 1 */
  24323. 0x6f, 0xc6, 0x4c, 0xe1, 0xc6, 0x68, 0x34, 0x8c,
  24324. 0x0a, 0xe1, 0xf8, 0xb8, 0x3e, 0xd4, 0xf8, 0x0b,
  24325. 0x54, 0x50, 0xe4, 0xc5, 0x4a, 0x33, 0x7d, 0xbd,
  24326. 0x90, 0xd2, 0xa2, 0xb9, 0xb7, 0x92, 0xed, 0xab,
  24327. 0x14, 0xf1, 0xe4, 0x86, 0x22, 0x67, 0xd7, 0x44,
  24328. 0x03, 0x21, 0xdc, 0x51, 0x52, 0x7f, 0x35, 0x80
  24329. },
  24330. { /* Hello 2 */
  24331. 0x3e, 0xcf, 0x2f, 0xc3, 0x87, 0xba, 0xc5, 0xbd,
  24332. 0x7c, 0xe8, 0x35, 0x5b, 0x95, 0x51, 0x30, 0x3b,
  24333. 0x08, 0xcc, 0x2a, 0x7d, 0xb5, 0x74, 0x7c, 0x16,
  24334. 0xb3, 0x0b, 0xe7, 0x61, 0xa3, 0x7c, 0x6c, 0xbd,
  24335. 0x39, 0x74, 0xfd, 0x1e, 0x4c, 0xff, 0xc8, 0xcc,
  24336. 0xa0, 0xef, 0x29, 0x4d, 0x94, 0xaa, 0x55, 0x6f,
  24337. },
  24338. { /* Finished 1 */
  24339. 0x06, 0xc1, 0x47, 0x78, 0x66, 0x53, 0x6f, 0x24,
  24340. 0x94, 0x61, 0x69, 0xec, 0xd8, 0x60, 0x31, 0x2f,
  24341. 0xbf, 0xd6, 0x8a, 0x29, 0x17, 0xff, 0xa3, 0x88,
  24342. 0x13, 0x09, 0x8c, 0x9d, 0x6c, 0x64, 0x84, 0x48,
  24343. 0x44, 0xdd, 0x2d, 0x29, 0x4d, 0xe6, 0x98, 0x2b,
  24344. 0x45, 0x3b, 0x84, 0x33, 0x79, 0xb2, 0x75, 0x68
  24345. },
  24346. { /* Finished 2 */
  24347. 0x28, 0x1e, 0x18, 0xf7, 0x9c, 0x32, 0xa9, 0xbf,
  24348. 0x0c, 0x24, 0x58, 0x21, 0xce, 0xbc, 0xf2, 0x44,
  24349. 0xb1, 0x18, 0xaf, 0x9d, 0xd9, 0x20, 0xf9, 0xf4,
  24350. 0xed, 0xcc, 0x53, 0x82, 0x66, 0x5c, 0x46, 0x94,
  24351. 0x8c, 0x36, 0x5e, 0xca, 0x9f, 0xd8, 0x9a, 0xd3,
  24352. 0xf0, 0xe1, 0x53, 0x71, 0xdd, 0x19, 0x1e, 0x59
  24353. },
  24354. {
  24355. 0xd0, 0xef, 0xa8, 0xcb, 0x5b, 0x14, 0x0f, 0x0a, 0x62, 0xba, 0x5a, 0xb1,
  24356. 0xc5, 0xb5, 0x3f, 0x11, 0xda, 0xa1, 0x0c, 0x9c, 0xb4, 0x32, 0x48, 0x4e,
  24357. 0xfa, 0x84, 0x4f, 0xe4, 0xe7, 0x91, 0x8f, 0x42, 0x3f, 0xc7, 0x4e, 0xd3,
  24358. 0x83, 0x3d, 0x7f, 0x70, 0x12, 0xee, 0x9a, 0x37, 0x01, 0xbb, 0x14, 0xd3
  24359. },
  24360. {
  24361. 0x48, 0x6f, 0x77, 0x1d, 0x39, 0x1b, 0xa5, 0x9a, 0x76, 0xd9, 0x1d, 0x7d,
  24362. 0xb3, 0xd9, 0xb9, 0x78, 0x35, 0x0f, 0xd0, 0xe1, 0x07, 0x1f, 0x8d, 0xe5,
  24363. 0x75, 0x00, 0xda, 0xc0, 0x19, 0x01, 0xfb, 0x08, 0x35, 0xe7, 0x18, 0x8f,
  24364. 0xf0, 0x19, 0xfb, 0x46, 0xf6, 0xa5, 0x77, 0x0e, 0x90, 0x38, 0x8b, 0x15
  24365. },
  24366. {
  24367. 0x80, 0x8c, 0xa7, 0x24, 0x97, 0xf9, 0xd3, 0x52, 0xb0, 0x69, 0x9d, 0x4b,
  24368. 0xa4, 0x19, 0x4a, 0xb1, 0x46, 0x53, 0x3a, 0xc8, 0xe4, 0x02, 0x69, 0xf2,
  24369. 0xe7, 0xb6, 0x1d, 0x33, 0x51, 0xcc, 0x14, 0x40, 0x4a, 0xb0, 0xe7, 0x58,
  24370. 0x84, 0xba, 0xc2, 0x14, 0x58, 0x6b, 0xb9, 0xdc, 0x50, 0x98, 0x67, 0x01
  24371. },
  24372. {
  24373. 0xb1, 0xa8, 0xc0, 0x06, 0xb3, 0x2e, 0xa7, 0x8a, 0x6a, 0x12, 0x88, 0x00,
  24374. 0x65, 0x88, 0x9c, 0x5d, 0x35, 0xee, 0xe5, 0x51, 0x0b, 0x62, 0xf8, 0x67,
  24375. 0xe5, 0xef, 0x15, 0x1f, 0x23, 0x02, 0x74, 0x08, 0x9c, 0xc8, 0xba, 0x27,
  24376. 0x5d, 0x32, 0x19, 0x6f, 0x6d, 0x5d, 0x72, 0x5e, 0x15, 0xde, 0x30, 0xc3
  24377. },
  24378. {
  24379. 0xfd, 0xce, 0xf5, 0x65, 0x45, 0x84, 0xfb, 0x8c, 0x79, 0xa4, 0x6c, 0x1b,
  24380. 0x0e, 0x1b, 0xfd, 0x26, 0xa2, 0x53, 0xf4, 0x4e, 0x00, 0x4d, 0x4b, 0x0b,
  24381. 0x24, 0x6d, 0x35, 0x35, 0xd9, 0x97, 0x70, 0xc5, 0xf4, 0xee, 0xe3, 0xba,
  24382. 0x31, 0x1e, 0x2a, 0x42, 0xcb, 0xdf, 0x40, 0xb1, 0x14, 0xb8, 0x53, 0xce
  24383. },
  24384. {
  24385. 0xbb, 0xb3, 0x26, 0x7c, 0x22, 0x21, 0x9b, 0x72, 0x32, 0xa1, 0x97, 0xfb,
  24386. 0x78, 0x8c, 0xbe, 0x3d, 0x71, 0x45, 0xb8, 0xf5, 0x24, 0x8f, 0x0f, 0xac,
  24387. 0x42, 0x5b, 0x81, 0xe8, 0xd0, 0x71, 0x4a, 0xcb, 0x32, 0x3f, 0x03, 0xfb,
  24388. 0xec, 0x6a, 0x1f, 0x76, 0x80, 0x65, 0x01, 0x7a, 0x3d, 0xce, 0xc4, 0xdf
  24389. },
  24390. {
  24391. 0x3f, 0xcf, 0x2f, 0x63, 0x94, 0x94, 0x99, 0xfd, 0x04, 0x3a, 0x89, 0x83,
  24392. 0xcf, 0x06, 0x05, 0xec, 0x20, 0x3e, 0x5f, 0x51, 0x9d, 0x6e, 0x4a, 0xc6,
  24393. 0xf1, 0x2b, 0x37, 0x17, 0x34, 0x72, 0x6e, 0x1d, 0x2a, 0xfd, 0xc7, 0x73,
  24394. 0xb5, 0x07, 0x22, 0x81, 0x32, 0x2e, 0x21, 0x85, 0xaf, 0x10, 0xb2, 0x73
  24395. },
  24396. {
  24397. 0x52, 0x0c, 0x3d, 0x2e, 0x2d, 0x4a, 0x11, 0xae, 0x96, 0x78, 0xe9, 0x5b,
  24398. 0xd8, 0x0f, 0x6c, 0xf4, 0xbd, 0x96, 0x13, 0x55, 0x88, 0xdd, 0xa3, 0x67,
  24399. 0x36, 0x86, 0x1e, 0x0b, 0x36, 0x41, 0xec, 0xf6, 0x04, 0xb2, 0xc4, 0x16,
  24400. 0xbc, 0x2c, 0xdb, 0x30, 0x02, 0x94, 0xd4, 0x42, 0xbf, 0x38, 0xee, 0x9d
  24401. }
  24402. },
  24403. { /* 36 */
  24404. WC_HASH_TYPE_SHA384, 0, 33,
  24405. { 0 }, /* PSK */
  24406. { /* DHE */
  24407. 0xd3, 0x00, 0x72, 0x9a, 0xa8, 0xc5, 0xf3, 0xc4,
  24408. 0xf1, 0xa0, 0x26, 0x89, 0x65, 0x70, 0xc7, 0x0b,
  24409. 0x77, 0xbb, 0xe1, 0x4b, 0x2b, 0xa8, 0x4f, 0xa6,
  24410. 0x09, 0x4b, 0xba, 0x45, 0x36, 0x15, 0xee, 0x68,
  24411. 0xfd
  24412. },
  24413. { /* Hello 1 */
  24414. 0x10, 0x9d, 0x8b, 0xa2, 0x93, 0xe7, 0xd3, 0xb9,
  24415. 0xb4, 0x0f, 0xeb, 0x6a, 0xb9, 0x69, 0xcb, 0x39,
  24416. 0x16, 0x29, 0xcc, 0xd3, 0xcc, 0x1a, 0x4c, 0x1b,
  24417. 0x53, 0x7c, 0x33, 0x88, 0x06, 0xbc, 0x0a, 0x02,
  24418. 0xa0, 0xbe, 0x62, 0xc0, 0xe6, 0x5e, 0x97, 0x5b,
  24419. 0x6a, 0xa1, 0x98, 0xf3, 0xd2, 0x1e, 0xcd, 0xc5
  24420. },
  24421. { /* Hello 2 */
  24422. 0x74, 0xc0, 0x07, 0x2c, 0xc1, 0x63, 0xcc, 0x11,
  24423. 0xad, 0x1a, 0x55, 0x63, 0xbc, 0x20, 0x77, 0x96,
  24424. 0x30, 0x1c, 0x68, 0x45, 0x1e, 0x9b, 0xa7, 0xb4,
  24425. 0xf3, 0x04, 0x45, 0x16, 0x76, 0x55, 0xf9, 0xdf,
  24426. 0x4b, 0x2f, 0x1a, 0xdf, 0x5a, 0xb0, 0x93, 0xc9,
  24427. 0xab, 0xf5, 0x32, 0x47, 0x79, 0x9c, 0x01, 0xeb
  24428. },
  24429. { /* Finished 1 */
  24430. 0x27, 0x08, 0x8e, 0xa5, 0xf1, 0x30, 0xe1, 0xd6,
  24431. 0x4f, 0xa2, 0x9e, 0x3b, 0x03, 0x2d, 0x2e, 0xa3,
  24432. 0x84, 0x75, 0x51, 0x3a, 0xc3, 0xf6, 0xee, 0x2e,
  24433. 0x37, 0x0c, 0xe3, 0x28, 0x46, 0xa5, 0x2d, 0xc7,
  24434. 0xf0, 0x64, 0x78, 0x53, 0x66, 0x43, 0x02, 0xa4,
  24435. 0x7a, 0x43, 0x66, 0x4b, 0xa7, 0xcb, 0x97, 0x16
  24436. },
  24437. { /* Finished 2 */
  24438. 0x1d, 0x0d, 0xf8, 0xe1, 0x81, 0xa5, 0xbd, 0xa8,
  24439. 0x6f, 0x9d, 0x01, 0xa4, 0x9a, 0x92, 0xe2, 0xef,
  24440. 0x08, 0xab, 0xef, 0x3e, 0x2d, 0xd4, 0x82, 0xac,
  24441. 0x68, 0x9d, 0xe0, 0x54, 0x17, 0xde, 0x1a, 0xed,
  24442. 0x57, 0xcb, 0xd9, 0x2d, 0xc8, 0xbc, 0x93, 0xe6,
  24443. 0xa3, 0xec, 0xde, 0xee, 0xa1, 0x1c, 0x41, 0x85
  24444. },
  24445. {
  24446. 0x7f, 0x1f, 0xe6, 0x7b, 0xd8, 0xf5, 0x2b, 0x37, 0xbe, 0xb7, 0xd0, 0x37,
  24447. 0xce, 0x46, 0xad, 0x04, 0x2f, 0xc7, 0xdb, 0xc9, 0x9a, 0xb6, 0x00, 0x3f,
  24448. 0xc1, 0x97, 0xe9, 0x5c, 0x5e, 0x14, 0xd1, 0x38, 0x4d, 0x55, 0xe1, 0x07,
  24449. 0xb5, 0x85, 0x6d, 0xfa, 0xa7, 0x66, 0xad, 0xfa, 0xb6, 0xad, 0x29, 0x44
  24450. },
  24451. {
  24452. 0x4e, 0x6b, 0x20, 0x99, 0x55, 0x1b, 0x21, 0x89, 0xb6, 0x70, 0xdb, 0xe8,
  24453. 0xa7, 0x16, 0x55, 0xf2, 0x93, 0x13, 0x90, 0x7d, 0xfa, 0x62, 0x65, 0x53,
  24454. 0xa0, 0x97, 0xe9, 0xb4, 0xc0, 0xf1, 0xc9, 0x1a, 0x67, 0xdd, 0xca, 0x57,
  24455. 0xbc, 0xca, 0x39, 0xe6, 0x39, 0x6b, 0x63, 0x47, 0x25, 0x08, 0x3a, 0xd7
  24456. },
  24457. {
  24458. 0x35, 0x0d, 0xac, 0xd8, 0x10, 0x6a, 0x46, 0x50, 0x66, 0xae, 0x02, 0xc9,
  24459. 0xde, 0x13, 0x48, 0xce, 0x53, 0xd4, 0x92, 0x62, 0xc5, 0x65, 0x10, 0x08,
  24460. 0xc2, 0xc2, 0x82, 0xed, 0x9d, 0xc9, 0x6f, 0xa8, 0xc3, 0xc1, 0x0b, 0x7c,
  24461. 0xe1, 0x97, 0x85, 0xd6, 0x46, 0x29, 0x0e, 0x42, 0x51, 0xc1, 0x35, 0xcf
  24462. },
  24463. {
  24464. 0x3d, 0x5d, 0x84, 0xbd, 0x16, 0x46, 0x34, 0xb3, 0xf6, 0x31, 0x49, 0x3e,
  24465. 0x8d, 0xdc, 0xcb, 0x8c, 0x6a, 0x42, 0xf4, 0x88, 0xfc, 0x19, 0xfa, 0xa2,
  24466. 0x25, 0xc7, 0xa0, 0xa4, 0xca, 0xf0, 0xea, 0x2d, 0xe8, 0xc4, 0x02, 0x14,
  24467. 0x63, 0xfb, 0xd3, 0x7b, 0x51, 0x1c, 0xce, 0xca, 0xa3, 0xc3, 0xe4, 0xa5
  24468. },
  24469. {
  24470. 0x7c, 0x3a, 0x55, 0x92, 0x2e, 0xdd, 0x75, 0xdd, 0x76, 0x54, 0x4a, 0x9f,
  24471. 0xd0, 0xa2, 0x88, 0x83, 0xe9, 0x27, 0xda, 0x30, 0xe9, 0x96, 0x58, 0xc5,
  24472. 0xb7, 0x56, 0xfc, 0x4b, 0xb8, 0x5d, 0xee, 0x46, 0x70, 0x4e, 0x1b, 0x06,
  24473. 0x86, 0xaf, 0x48, 0x5c, 0x17, 0x35, 0xfa, 0x69, 0xc2, 0x4d, 0xfb, 0x09
  24474. },
  24475. {
  24476. 0x00, 0x0e, 0x28, 0x51, 0xc1, 0x7f, 0x41, 0x89, 0x6f, 0x9a, 0xca, 0x15,
  24477. 0xee, 0xed, 0x43, 0xca, 0x6d, 0x65, 0x6f, 0x51, 0x18, 0x6c, 0x08, 0x4b,
  24478. 0x77, 0xca, 0x75, 0xc4, 0xc3, 0xde, 0x29, 0x41, 0x8b, 0xaf, 0xa7, 0x1c,
  24479. 0x28, 0x37, 0xa0, 0xa0, 0x74, 0x8e, 0x09, 0x42, 0x7a, 0x1b, 0x68, 0xdb
  24480. },
  24481. {
  24482. 0x14, 0x8f, 0xab, 0x28, 0x64, 0xea, 0x45, 0x88, 0xdb, 0xc1, 0xc6, 0xa0,
  24483. 0x48, 0xdf, 0x15, 0xd0, 0x28, 0x07, 0x2d, 0x6c, 0xb8, 0x42, 0xbb, 0x60,
  24484. 0x02, 0x08, 0x9e, 0x29, 0x9b, 0x8d, 0xd6, 0x1c, 0xaf, 0xf2, 0x1a, 0xdc,
  24485. 0xf0, 0x78, 0x0b, 0x4d, 0x90, 0xa1, 0x0c, 0xb3, 0x13, 0xde, 0xca, 0x5a
  24486. },
  24487. {
  24488. 0x4d, 0x80, 0x7d, 0x0b, 0xb9, 0x00, 0x6f, 0x65, 0x51, 0x65, 0x23, 0xde,
  24489. 0x72, 0xdc, 0x4f, 0x04, 0xa5, 0xa2, 0x90, 0x45, 0x51, 0x9e, 0xd0, 0x3a,
  24490. 0xe4, 0xd7, 0x78, 0xa3, 0x0f, 0x2d, 0x65, 0x12, 0xad, 0xc8, 0x92, 0x30,
  24491. 0x79, 0x9d, 0x9d, 0x08, 0x7a, 0x9c, 0x9f, 0x83, 0xb1, 0xca, 0x59, 0x56
  24492. }
  24493. },
  24494. { /* 41 */
  24495. WC_HASH_TYPE_SHA384, 33, 0,
  24496. { /* PSK */
  24497. 0xa4, 0x8b, 0x1b, 0x5f, 0xd0, 0xea, 0x75, 0x62,
  24498. 0x06, 0x4d, 0x68, 0x40, 0x85, 0x20, 0x45, 0x95,
  24499. 0x4a, 0x00, 0xca, 0x05, 0xeb, 0xd4, 0x1d, 0x48,
  24500. 0x81, 0x89, 0xe8, 0x86, 0x43, 0xfa, 0x28, 0x17,
  24501. 0x12
  24502. },
  24503. { 0 }, /* DHE */
  24504. { /* Hello 1 */
  24505. 0x03, 0x7c, 0x33, 0x75, 0xdc, 0xc5, 0x46, 0x3a,
  24506. 0x0d, 0x56, 0xc6, 0xfb, 0xab, 0x1e, 0x1d, 0xda,
  24507. 0x59, 0xc2, 0xb2, 0xb1, 0x7c, 0x48, 0x9b, 0x06,
  24508. 0x0a, 0x5a, 0xbb, 0xf8, 0x98, 0x53, 0x78, 0x2d,
  24509. 0xd2, 0xcc, 0x87, 0x68, 0x25, 0xdd, 0x88, 0x22,
  24510. 0xcd, 0xb7, 0x74, 0x55, 0x21, 0xf9, 0x34, 0x98
  24511. },
  24512. { /* Hello 2 */
  24513. 0x03, 0xb4, 0xfb, 0xcc, 0x28, 0x2c, 0xc1, 0x70,
  24514. 0x42, 0x73, 0x57, 0xac, 0xdb, 0x47, 0x71, 0xf6,
  24515. 0x2e, 0x11, 0x8a, 0x5b, 0x47, 0x2f, 0x02, 0x54,
  24516. 0x95, 0x34, 0xed, 0x5f, 0x19, 0xc1, 0x75, 0xe0,
  24517. 0x76, 0xad, 0xb0, 0x90, 0x57, 0xcd, 0xfd, 0xd7,
  24518. 0x58, 0x1f, 0x0d, 0x6b, 0x9e, 0x51, 0x3c, 0x08
  24519. },
  24520. { /* Finished 1 */
  24521. 0x2b, 0x50, 0xd9, 0xa7, 0x43, 0x24, 0xda, 0x2c,
  24522. 0x7a, 0xaa, 0x0e, 0x37, 0xd7, 0x6b, 0x2c, 0xab,
  24523. 0x8e, 0xb2, 0xfe, 0x31, 0x1b, 0xa8, 0x12, 0x59,
  24524. 0x5b, 0x7b, 0xdc, 0x3e, 0xa7, 0x86, 0xa5, 0x48,
  24525. 0xe4, 0x46, 0x2b, 0x4c, 0xc1, 0x66, 0x4b, 0xf3,
  24526. 0x2a, 0x99, 0x93, 0x08, 0xbc, 0x3d, 0x08, 0x76
  24527. },
  24528. { /* Finished 2 */
  24529. 0x7c, 0x34, 0xc8, 0x56, 0x17, 0xf1, 0x62, 0x1c,
  24530. 0x9f, 0x0b, 0xeb, 0xfd, 0x69, 0x72, 0x51, 0xc5,
  24531. 0xfa, 0x74, 0x87, 0xc9, 0xbd, 0x50, 0xe9, 0x48,
  24532. 0xa7, 0x3c, 0x94, 0x3e, 0x06, 0x7d, 0xe8, 0x8e,
  24533. 0xc1, 0xd1, 0x08, 0x1f, 0x5d, 0x48, 0x8a, 0x25,
  24534. 0xfc, 0xea, 0xe7, 0xd9, 0xd4, 0xd0, 0xf9, 0xad
  24535. },
  24536. {
  24537. 0x4b, 0x0b, 0xed, 0xb9, 0xc8, 0xb8, 0xa8, 0x1e, 0xb0, 0x81, 0x76, 0xd5,
  24538. 0x33, 0x22, 0x71, 0x33, 0x3a, 0x85, 0x19, 0x67, 0x7e, 0x91, 0x37, 0xf2,
  24539. 0xa6, 0x11, 0x22, 0xdf, 0x41, 0x04, 0x3d, 0xa9, 0x13, 0xb9, 0xb2, 0xb1,
  24540. 0xbb, 0xd8, 0xef, 0x23, 0x7c, 0xc2, 0xab, 0x70, 0x1b, 0x51, 0x9f, 0xc9
  24541. },
  24542. {
  24543. 0xeb, 0x96, 0x10, 0x8c, 0x7d, 0x92, 0xea, 0x80, 0x86, 0xb2, 0xf8, 0x27,
  24544. 0xf2, 0x9a, 0x09, 0xc1, 0x7c, 0x09, 0x43, 0xbc, 0xfe, 0xc8, 0x75, 0xe0,
  24545. 0x97, 0xe7, 0x6d, 0xd5, 0xb2, 0x3c, 0xed, 0x12, 0xb7, 0x74, 0x0e, 0xe3,
  24546. 0xb6, 0xe0, 0xba, 0xe1, 0x8d, 0x89, 0xcf, 0x4f, 0x57, 0xf6, 0x6d, 0x90
  24547. },
  24548. {
  24549. 0x22, 0xb0, 0x39, 0x34, 0xb6, 0x6c, 0x2d, 0x7a, 0x97, 0x1c, 0x5d, 0xcc,
  24550. 0x78, 0x84, 0x71, 0xbb, 0xc6, 0x7b, 0xb6, 0xbc, 0xcc, 0x0b, 0xf8, 0xac,
  24551. 0x8e, 0xd7, 0x20, 0xbd, 0xbe, 0x32, 0xf0, 0xd6, 0xe9, 0x69, 0x13, 0xf2,
  24552. 0x9a, 0xce, 0xfe, 0x86, 0xd3, 0xee, 0xba, 0x69, 0x51, 0xb6, 0x77, 0x56
  24553. },
  24554. {
  24555. 0x16, 0xfd, 0xda, 0xf3, 0x5e, 0xb9, 0xa6, 0x17, 0x24, 0xb2, 0x16, 0x9f,
  24556. 0xb6, 0x59, 0x13, 0x0f, 0x25, 0x5a, 0xf1, 0x5b, 0x5f, 0xe4, 0x54, 0x2a,
  24557. 0xa7, 0xbf, 0x29, 0xaf, 0x5a, 0x77, 0xf4, 0x4f, 0x25, 0xba, 0x94, 0xad,
  24558. 0x6b, 0x91, 0x3b, 0xe7, 0xd5, 0x73, 0x0d, 0xff, 0xaa, 0xe3, 0x72, 0x2c
  24559. },
  24560. {
  24561. 0x22, 0xb4, 0x94, 0xc0, 0x53, 0xd7, 0x82, 0x06, 0x38, 0x9d, 0x4a, 0xa0,
  24562. 0x3f, 0xf1, 0x5f, 0x6e, 0x23, 0x8d, 0x09, 0x62, 0xbf, 0x6f, 0x7c, 0x84,
  24563. 0xc6, 0x3e, 0x15, 0xad, 0x18, 0x37, 0x76, 0x29, 0xc7, 0xd6, 0x68, 0x0c,
  24564. 0x1e, 0xc6, 0x93, 0x31, 0xef, 0x85, 0x69, 0x30, 0x68, 0xf0, 0x1e, 0x37
  24565. },
  24566. {
  24567. 0x6d, 0x4d, 0x20, 0xaf, 0x47, 0xe8, 0x1b, 0xfa, 0xd0, 0xb6, 0xc8, 0x97,
  24568. 0xd1, 0x03, 0xfc, 0x9d, 0x59, 0xa0, 0x68, 0x9d, 0xe9, 0x17, 0x8b, 0xce,
  24569. 0x48, 0x2c, 0x77, 0x8a, 0x22, 0x4b, 0x5c, 0x54, 0x22, 0xa1, 0x15, 0x12,
  24570. 0xe1, 0x07, 0x8e, 0x15, 0xd8, 0x7b, 0x16, 0x65, 0x99, 0x6b, 0xcb, 0x71
  24571. },
  24572. {
  24573. 0x79, 0x64, 0x79, 0xdd, 0x75, 0x5c, 0x6f, 0x98, 0xac, 0x03, 0xe0, 0xcd,
  24574. 0x92, 0xba, 0x0e, 0x2d, 0xb4, 0xd1, 0x8b, 0x97, 0xd0, 0x85, 0xbb, 0x2e,
  24575. 0x4f, 0x26, 0x93, 0xf5, 0x1d, 0xf3, 0xd2, 0x43, 0x4f, 0xd2, 0x47, 0xaa,
  24576. 0x91, 0x1e, 0xf3, 0x67, 0x10, 0x18, 0x2c, 0xb9, 0x01, 0xba, 0x10, 0x9f
  24577. },
  24578. {
  24579. 0x79, 0xb6, 0x9c, 0xbe, 0xf1, 0x6a, 0xb0, 0x92, 0xa0, 0x29, 0x52, 0x61,
  24580. 0xf1, 0xcd, 0x3a, 0x67, 0xe1, 0x6b, 0xb8, 0x9d, 0x0d, 0x95, 0xb6, 0x03,
  24581. 0x80, 0x1f, 0xd5, 0x75, 0xb6, 0x1d, 0x79, 0x02, 0x93, 0x43, 0x77, 0xa7,
  24582. 0x9d, 0x2f, 0xc3, 0x84, 0xc6, 0x83, 0x76, 0x16, 0x06, 0x98, 0x7b, 0x79
  24583. }
  24584. },
  24585. #endif /* WOLFSSL_SHA384 */
  24586. };
  24587. static const char protocolLabel[] = "tls13 ";
  24588. static const char ceTrafficLabel[] = "c e traffic";
  24589. static const char eExpMasterLabel[] = "e exp master";
  24590. static const char cHsTrafficLabel[] = "c hs traffic";
  24591. static const char sHsTrafficLabel[] = "s hs traffic";
  24592. static const char cAppTrafficLabel[] = "c ap traffic";
  24593. static const char sAppTrafficLabel[] = "s ap traffic";
  24594. static const char expMasterLabel[] = "exp master";
  24595. static const char resMasterLabel[] = "res master";
  24596. static const char derivedLabel[] = "derived";
  24597. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void)
  24598. {
  24599. wc_test_ret_t ret = 0;
  24600. word32 i;
  24601. word32 tc = sizeof(tls13KdfTestVectors)/sizeof(Tls13KdfTestVector);
  24602. const Tls13KdfTestVector* tv = NULL;
  24603. WOLFSSL_ENTER("tls13_kdf_test");
  24604. for (i = 0, tv = tls13KdfTestVectors; i < tc; i++, tv++) {
  24605. byte output[WC_MAX_DIGEST_SIZE];
  24606. byte secret[WC_MAX_DIGEST_SIZE];
  24607. byte salt[WC_MAX_DIGEST_SIZE];
  24608. byte zeroes[WC_MAX_DIGEST_SIZE];
  24609. byte hashZero[WC_MAX_DIGEST_SIZE];
  24610. int hashAlgSz;
  24611. XMEMSET(zeroes, 0, sizeof zeroes);
  24612. hashAlgSz = wc_HashGetDigestSize(tv->hashAlg);
  24613. if (hashAlgSz == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) break;
  24614. ret = wc_Hash(tv->hashAlg, NULL, 0, hashZero, (word32)hashAlgSz);
  24615. if (ret != 0) break;
  24616. ret = wc_Tls13_HKDF_Extract(secret, NULL, 0,
  24617. (tv->pskSz == 0) ? zeroes : (byte*)tv->psk,
  24618. tv->pskSz, tv->hashAlg);
  24619. if (ret != 0) break;
  24620. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24621. secret, (word32)hashAlgSz,
  24622. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24623. (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel),
  24624. tv->hashHello1, (word32)hashAlgSz, tv->hashAlg);
  24625. if (ret != 0) break;
  24626. ret = XMEMCMP(tv->clientEarlyTrafficSecret, output, hashAlgSz);
  24627. if (ret != 0) break;
  24628. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24629. secret, (word32)hashAlgSz,
  24630. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24631. (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel),
  24632. tv->hashHello1, (word32)hashAlgSz, tv->hashAlg);
  24633. if (ret != 0) break;
  24634. ret = XMEMCMP(tv->earlyExporterMasterSecret, output, hashAlgSz);
  24635. if (ret != 0) break;
  24636. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24637. secret, (word32)hashAlgSz,
  24638. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24639. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24640. hashZero, (word32)hashAlgSz, tv->hashAlg);
  24641. if (ret != 0) break;
  24642. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24643. (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe,
  24644. tv->dheSz, tv->hashAlg);
  24645. if (ret != 0) break;
  24646. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24647. secret, (word32)hashAlgSz,
  24648. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24649. (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel),
  24650. tv->hashHello2, (word32)hashAlgSz, tv->hashAlg);
  24651. if (ret != 0) break;
  24652. ret = XMEMCMP(tv->clientHandshakeTrafficSecret,
  24653. output, hashAlgSz);
  24654. if (ret != 0) break;
  24655. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24656. secret, (word32)hashAlgSz,
  24657. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24658. (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel),
  24659. tv->hashHello2, (word32)hashAlgSz, tv->hashAlg);
  24660. if (ret != 0) break;
  24661. ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output, hashAlgSz);
  24662. if (ret != 0) break;
  24663. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24664. secret, (word32)hashAlgSz,
  24665. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24666. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24667. hashZero, (word32)hashAlgSz, tv->hashAlg);
  24668. if (ret != 0) break;
  24669. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24670. zeroes, (word32)(word32)hashAlgSz, tv->hashAlg);
  24671. if (ret != 0) break;
  24672. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24673. secret, (word32)hashAlgSz,
  24674. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24675. (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel),
  24676. tv->hashFinished1, (word32)hashAlgSz, tv->hashAlg);
  24677. if (ret != 0) break;
  24678. ret = XMEMCMP(tv->clientApplicationTrafficSecret, output, hashAlgSz);
  24679. if (ret != 0) break;
  24680. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24681. secret, (word32)hashAlgSz,
  24682. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24683. (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel),
  24684. tv->hashFinished1, (word32)hashAlgSz, tv->hashAlg);
  24685. if (ret != 0) break;
  24686. ret = XMEMCMP(tv->serverApplicationTrafficSecret, output, hashAlgSz);
  24687. if (ret != 0) break;
  24688. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24689. secret, (word32)hashAlgSz,
  24690. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24691. (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel),
  24692. tv->hashFinished1, (word32)hashAlgSz, tv->hashAlg);
  24693. if (ret != 0) break;
  24694. ret = XMEMCMP(tv->exporterMasterSecret, output, hashAlgSz);
  24695. if (ret != 0) break;
  24696. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24697. secret, (word32)hashAlgSz,
  24698. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24699. (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel),
  24700. tv->hashFinished2, (word32)hashAlgSz, tv->hashAlg);
  24701. if (ret != 0) break;
  24702. ret = XMEMCMP(tv->resumptionMasterSecret, output, hashAlgSz);
  24703. if (ret != 0) break;
  24704. }
  24705. return ret;
  24706. }
  24707. #endif /* WOLFSSL_TLS13 */
  24708. static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point --
  24709. * see print_fiducials() below.
  24710. */
  24711. #if defined(HAVE_ECC) && defined(HAVE_X963_KDF)
  24712. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void)
  24713. {
  24714. wc_test_ret_t ret;
  24715. byte kek[128];
  24716. #ifndef NO_SHA
  24717. /* SHA-1, COUNT = 0
  24718. * shared secret length: 192
  24719. * SharedInfo length: 0
  24720. * key data length: 128
  24721. */
  24722. WOLFSSL_SMALL_STACK_STATIC const byte Z[] = {
  24723. 0x1c, 0x7d, 0x7b, 0x5f, 0x05, 0x97, 0xb0, 0x3d,
  24724. 0x06, 0xa0, 0x18, 0x46, 0x6e, 0xd1, 0xa9, 0x3e,
  24725. 0x30, 0xed, 0x4b, 0x04, 0xdc, 0x64, 0xcc, 0xdd
  24726. };
  24727. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  24728. 0xbf, 0x71, 0xdf, 0xfd, 0x8f, 0x4d, 0x99, 0x22,
  24729. 0x39, 0x36, 0xbe, 0xb4, 0x6f, 0xee, 0x8c, 0xcc
  24730. };
  24731. #endif
  24732. #ifndef NO_SHA256
  24733. /* SHA-256, COUNT = 3
  24734. * shared secret length: 192
  24735. * SharedInfo length: 0
  24736. * key data length: 128
  24737. */
  24738. WOLFSSL_SMALL_STACK_STATIC const byte Z2[] = {
  24739. 0xd3, 0x8b, 0xdb, 0xe5, 0xc4, 0xfc, 0x16, 0x4c,
  24740. 0xdd, 0x96, 0x7f, 0x63, 0xc0, 0x4f, 0xe0, 0x7b,
  24741. 0x60, 0xcd, 0xe8, 0x81, 0xc2, 0x46, 0x43, 0x8c
  24742. };
  24743. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  24744. 0x5e, 0x67, 0x4d, 0xb9, 0x71, 0xba, 0xc2, 0x0a,
  24745. 0x80, 0xba, 0xd0, 0xd4, 0x51, 0x4d, 0xc4, 0x84
  24746. };
  24747. #endif
  24748. #ifdef WOLFSSL_SHA512
  24749. /* SHA-512, COUNT = 0
  24750. * shared secret length: 192
  24751. * SharedInfo length: 0
  24752. * key data length: 128
  24753. */
  24754. WOLFSSL_SMALL_STACK_STATIC const byte Z3[] = {
  24755. 0x87, 0xfc, 0x0d, 0x8c, 0x44, 0x77, 0x48, 0x5b,
  24756. 0xb5, 0x74, 0xf5, 0xfc, 0xea, 0x26, 0x4b, 0x30,
  24757. 0x88, 0x5d, 0xc8, 0xd9, 0x0a, 0xd8, 0x27, 0x82
  24758. };
  24759. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  24760. 0x94, 0x76, 0x65, 0xfb, 0xb9, 0x15, 0x21, 0x53,
  24761. 0xef, 0x46, 0x02, 0x38, 0x50, 0x6a, 0x02, 0x45
  24762. };
  24763. /* SHA-512, COUNT = 0
  24764. * shared secret length: 521
  24765. * SharedInfo length: 128
  24766. * key data length: 1024
  24767. */
  24768. WOLFSSL_SMALL_STACK_STATIC const byte Z4[] = {
  24769. 0x00, 0xaa, 0x5b, 0xb7, 0x9b, 0x33, 0xe3, 0x89,
  24770. 0xfa, 0x58, 0xce, 0xad, 0xc0, 0x47, 0x19, 0x7f,
  24771. 0x14, 0xe7, 0x37, 0x12, 0xf4, 0x52, 0xca, 0xa9,
  24772. 0xfc, 0x4c, 0x9a, 0xdb, 0x36, 0x93, 0x48, 0xb8,
  24773. 0x15, 0x07, 0x39, 0x2f, 0x1a, 0x86, 0xdd, 0xfd,
  24774. 0xb7, 0xc4, 0xff, 0x82, 0x31, 0xc4, 0xbd, 0x0f,
  24775. 0x44, 0xe4, 0x4a, 0x1b, 0x55, 0xb1, 0x40, 0x47,
  24776. 0x47, 0xa9, 0xe2, 0xe7, 0x53, 0xf5, 0x5e, 0xf0,
  24777. 0x5a, 0x2d
  24778. };
  24779. WOLFSSL_SMALL_STACK_STATIC const byte info4[] = {
  24780. 0xe3, 0xb5, 0xb4, 0xc1, 0xb0, 0xd5, 0xcf, 0x1d,
  24781. 0x2b, 0x3a, 0x2f, 0x99, 0x37, 0x89, 0x5d, 0x31
  24782. };
  24783. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  24784. 0x44, 0x63, 0xf8, 0x69, 0xf3, 0xcc, 0x18, 0x76,
  24785. 0x9b, 0x52, 0x26, 0x4b, 0x01, 0x12, 0xb5, 0x85,
  24786. 0x8f, 0x7a, 0xd3, 0x2a, 0x5a, 0x2d, 0x96, 0xd8,
  24787. 0xcf, 0xfa, 0xbf, 0x7f, 0xa7, 0x33, 0x63, 0x3d,
  24788. 0x6e, 0x4d, 0xd2, 0xa5, 0x99, 0xac, 0xce, 0xb3,
  24789. 0xea, 0x54, 0xa6, 0x21, 0x7c, 0xe0, 0xb5, 0x0e,
  24790. 0xef, 0x4f, 0x6b, 0x40, 0xa5, 0xc3, 0x02, 0x50,
  24791. 0xa5, 0xa8, 0xee, 0xee, 0x20, 0x80, 0x02, 0x26,
  24792. 0x70, 0x89, 0xdb, 0xf3, 0x51, 0xf3, 0xf5, 0x02,
  24793. 0x2a, 0xa9, 0x63, 0x8b, 0xf1, 0xee, 0x41, 0x9d,
  24794. 0xea, 0x9c, 0x4f, 0xf7, 0x45, 0xa2, 0x5a, 0xc2,
  24795. 0x7b, 0xda, 0x33, 0xca, 0x08, 0xbd, 0x56, 0xdd,
  24796. 0x1a, 0x59, 0xb4, 0x10, 0x6c, 0xf2, 0xdb, 0xbc,
  24797. 0x0a, 0xb2, 0xaa, 0x8e, 0x2e, 0xfa, 0x7b, 0x17,
  24798. 0x90, 0x2d, 0x34, 0x27, 0x69, 0x51, 0xce, 0xcc,
  24799. 0xab, 0x87, 0xf9, 0x66, 0x1c, 0x3e, 0x88, 0x16
  24800. };
  24801. #endif
  24802. WOLFSSL_ENTER("x963kdf_test");
  24803. #ifndef NO_SHA
  24804. ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0,
  24805. kek, sizeof(verify));
  24806. if (ret != 0)
  24807. return WC_TEST_RET_ENC_EC(ret);
  24808. if (XMEMCMP(verify, kek, sizeof(verify)) != 0)
  24809. return WC_TEST_RET_ENC_NC;
  24810. #endif
  24811. #ifndef NO_SHA256
  24812. ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0,
  24813. kek, sizeof(verify2));
  24814. if (ret != 0)
  24815. return WC_TEST_RET_ENC_EC(ret);
  24816. if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0)
  24817. return WC_TEST_RET_ENC_NC;
  24818. #endif
  24819. #ifdef WOLFSSL_SHA512
  24820. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0,
  24821. kek, sizeof(verify3));
  24822. if (ret != 0)
  24823. return WC_TEST_RET_ENC_EC(ret);
  24824. if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0)
  24825. return WC_TEST_RET_ENC_NC;
  24826. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4,
  24827. sizeof(info4), kek, sizeof(verify4));
  24828. if (ret != 0)
  24829. return WC_TEST_RET_ENC_EC(ret);
  24830. if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0)
  24831. return WC_TEST_RET_ENC_NC;
  24832. #endif
  24833. return 0;
  24834. }
  24835. #endif /* HAVE_X963_KDF */
  24836. #if defined(HAVE_HPKE) && \
  24837. (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) && \
  24838. defined(HAVE_AESGCM)
  24839. static wc_test_ret_t hpke_test_single(Hpke* hpke)
  24840. {
  24841. wc_test_ret_t ret = 0;
  24842. int rngRet = 0;
  24843. WC_RNG rng[1];
  24844. const char* start_text = "this is a test";
  24845. const char* info_text = "info";
  24846. const char* aad_text = "aad";
  24847. byte ciphertext[MAX_HPKE_LABEL_SZ];
  24848. byte plaintext[MAX_HPKE_LABEL_SZ];
  24849. void* receiverKey = NULL;
  24850. void* ephemeralKey = NULL;
  24851. #ifdef WOLFSSL_SMALL_STACK
  24852. byte *pubKey = NULL; /* public key */
  24853. word16 pubKeySz = (word16)HPKE_Npk_MAX;
  24854. #else
  24855. byte pubKey[HPKE_Npk_MAX]; /* public key */
  24856. word16 pubKeySz = (word16)sizeof(pubKey);
  24857. #endif
  24858. rngRet = ret = wc_InitRng(rng);
  24859. if (ret != 0)
  24860. return WC_TEST_RET_ENC_EC(ret);
  24861. #ifdef WOLFSSL_SMALL_STACK
  24862. if (ret == 0) {
  24863. pubKey = (byte *)XMALLOC(pubKeySz, HEAP_HINT,
  24864. DYNAMIC_TYPE_TMP_BUFFER);
  24865. if (pubKey == NULL)
  24866. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  24867. }
  24868. #endif
  24869. /* generate the keys */
  24870. if (ret == 0) {
  24871. ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng);
  24872. if (ret != 0)
  24873. ret = WC_TEST_RET_ENC_EC(ret);
  24874. }
  24875. if (ret == 0) {
  24876. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng);
  24877. if (ret != 0)
  24878. ret = WC_TEST_RET_ENC_EC(ret);
  24879. }
  24880. /* seal */
  24881. if (ret == 0) {
  24882. ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey,
  24883. (byte*)info_text, (word32)XSTRLEN(info_text),
  24884. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  24885. (byte*)start_text, (word32)XSTRLEN(start_text),
  24886. ciphertext);
  24887. if (ret != 0)
  24888. ret = WC_TEST_RET_ENC_EC(ret);
  24889. }
  24890. /* export ephemeral key */
  24891. if (ret == 0) {
  24892. ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz);
  24893. if (ret != 0)
  24894. ret = WC_TEST_RET_ENC_EC(ret);
  24895. }
  24896. /* open with exported ephemeral key */
  24897. if (ret == 0) {
  24898. ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz,
  24899. (byte*)info_text, (word32)XSTRLEN(info_text),
  24900. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  24901. ciphertext, (word32)XSTRLEN(start_text),
  24902. plaintext);
  24903. if (ret != 0)
  24904. ret = WC_TEST_RET_ENC_EC(ret);
  24905. }
  24906. if (ret == 0) {
  24907. ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text));
  24908. if (ret != 0)
  24909. ret = WC_TEST_RET_ENC_NC;
  24910. }
  24911. /* Negative test case with NULL argument */
  24912. if (ret == 0) {
  24913. ret = wc_HpkeGenerateKeyPair(NULL, &receiverKey, rng);
  24914. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  24915. ret = WC_TEST_RET_ENC_EC(ret);
  24916. else
  24917. ret = 0;
  24918. }
  24919. if (ret == 0) {
  24920. ret = wc_HpkeGenerateKeyPair(hpke, NULL, rng);
  24921. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  24922. ret = WC_TEST_RET_ENC_EC(ret);
  24923. else
  24924. ret = 0;
  24925. }
  24926. if (ret == 0) {
  24927. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, NULL);
  24928. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  24929. ret = WC_TEST_RET_ENC_EC(ret);
  24930. else
  24931. ret = 0;
  24932. }
  24933. if (ephemeralKey != NULL)
  24934. wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
  24935. if (receiverKey != NULL)
  24936. wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
  24937. #ifdef WOLFSSL_SMALL_STACK
  24938. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  24939. #endif
  24940. if (rngRet == 0)
  24941. wc_FreeRng(rng);
  24942. return ret;
  24943. }
  24944. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void)
  24945. {
  24946. wc_test_ret_t ret = 0;
  24947. Hpke hpke[1];
  24948. WOLFSSL_ENTER("hpke_test");
  24949. #if defined(HAVE_ECC)
  24950. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
  24951. /* p256 */
  24952. ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256,
  24953. HPKE_AES_128_GCM, NULL);
  24954. if (ret != 0)
  24955. return WC_TEST_RET_ENC_EC(ret);
  24956. ret = hpke_test_single(hpke);
  24957. if (ret != 0)
  24958. return ret;
  24959. #endif
  24960. #if defined(WOLFSSL_SHA384) && \
  24961. (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  24962. /* p384 */
  24963. ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384,
  24964. HPKE_AES_128_GCM, NULL);
  24965. if (ret != 0)
  24966. return WC_TEST_RET_ENC_EC(ret);
  24967. ret = hpke_test_single(hpke);
  24968. if (ret != 0)
  24969. return ret;
  24970. #endif
  24971. #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \
  24972. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  24973. /* p521 */
  24974. ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512,
  24975. HPKE_AES_128_GCM, NULL);
  24976. if (ret != 0)
  24977. return WC_TEST_RET_ENC_EC(ret);
  24978. ret = hpke_test_single(hpke);
  24979. if (ret != 0)
  24980. return ret;
  24981. #endif
  24982. #endif
  24983. #if defined(HAVE_CURVE25519)
  24984. /* test with curve25519 and aes256 */
  24985. ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256,
  24986. HPKE_AES_256_GCM, NULL);
  24987. if (ret != 0)
  24988. return WC_TEST_RET_ENC_EC(ret);
  24989. ret = hpke_test_single(hpke);
  24990. if (ret != 0)
  24991. return ret;
  24992. #endif
  24993. #if defined(HAVE_CURVE448) && \
  24994. (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512))
  24995. /* test with curve448 and aes256 */
  24996. ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512,
  24997. HPKE_AES_256_GCM, NULL);
  24998. /* HPKE does not support X448 yet, so expect failure */
  24999. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25000. return WC_TEST_RET_ENC_EC(ret);
  25001. ret = hpke_test_single(hpke);
  25002. /* HPKE does not support X448 yet, so expect failure */
  25003. if (WC_TEST_RET_DEC_EC(ret) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25004. return ret;
  25005. ret = 0; /* reset error code */
  25006. #endif
  25007. /* TODO: HPKE chacha20 is not implemented */
  25008. return ret;
  25009. }
  25010. #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */
  25011. #if defined(WC_SRTP_KDF)
  25012. typedef struct Srtp_Kdf_Tv {
  25013. const unsigned char* key;
  25014. word32 keySz;
  25015. const unsigned char* salt;
  25016. word32 saltSz;
  25017. int kdfIdx;
  25018. const unsigned char* index;
  25019. const unsigned char* ke;
  25020. const unsigned char* ka;
  25021. const unsigned char* ks;
  25022. const unsigned char* index_c;
  25023. const unsigned char* ke_c;
  25024. const unsigned char* ka_c;
  25025. const unsigned char* ks_c;
  25026. word32 keSz;
  25027. word32 kaSz;
  25028. word32 ksSz;
  25029. } Srtp_Kdf_Tv;
  25030. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
  25031. {
  25032. wc_test_ret_t ret = 0;
  25033. /* 128-bit key, kdrIdx = -1 */
  25034. WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = {
  25035. 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72,
  25036. 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90
  25037. };
  25038. WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = {
  25039. 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56,
  25040. 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6
  25041. };
  25042. WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = {
  25043. 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca
  25044. };
  25045. WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = {
  25046. 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a,
  25047. 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f
  25048. };
  25049. WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = {
  25050. 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee,
  25051. 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3,
  25052. 0xbd, 0x32, 0x6e, 0xe4
  25053. };
  25054. WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = {
  25055. 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6,
  25056. 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c
  25057. };
  25058. WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = {
  25059. 0x56, 0xf3, 0xf1, 0x97
  25060. };
  25061. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = {
  25062. 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf,
  25063. 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38
  25064. };
  25065. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = {
  25066. 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba,
  25067. 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7,
  25068. 0xc3, 0xd8, 0x77, 0x0e
  25069. };
  25070. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = {
  25071. 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96,
  25072. 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8
  25073. };
  25074. /* 192-bit key, kdrIdx = 0 */
  25075. WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = {
  25076. 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c,
  25077. 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70,
  25078. 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2
  25079. };
  25080. WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = {
  25081. 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6,
  25082. 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52
  25083. };
  25084. WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = {
  25085. 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76
  25086. };
  25087. WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = {
  25088. 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3,
  25089. 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93,
  25090. 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60
  25091. };
  25092. WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = {
  25093. 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d,
  25094. 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78,
  25095. 0xd1, 0xd1, 0x47, 0x08
  25096. };
  25097. WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = {
  25098. 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe,
  25099. 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea
  25100. };
  25101. WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = {
  25102. 0x40, 0xbf, 0xd4, 0xa9
  25103. };
  25104. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = {
  25105. 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65,
  25106. 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11,
  25107. 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84
  25108. };
  25109. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = {
  25110. 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef,
  25111. 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2,
  25112. 0xf3, 0x3b, 0x8e, 0x29
  25113. };
  25114. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = {
  25115. 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4,
  25116. 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0
  25117. };
  25118. /* 256-bit key, kdrIdx = 1 */
  25119. WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = {
  25120. 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee,
  25121. 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02,
  25122. 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50,
  25123. 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb
  25124. };
  25125. WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = {
  25126. 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74,
  25127. 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a
  25128. };
  25129. WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = {
  25130. 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42
  25131. };
  25132. WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = {
  25133. 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98,
  25134. 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f,
  25135. 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb,
  25136. 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb
  25137. };
  25138. WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = {
  25139. 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84,
  25140. 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57,
  25141. 0x65, 0xc7, 0x50, 0xc1
  25142. };
  25143. WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = {
  25144. 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c,
  25145. 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a
  25146. };
  25147. WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = {
  25148. 0x31, 0x2d, 0x58, 0x15
  25149. };
  25150. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = {
  25151. 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1,
  25152. 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4,
  25153. 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa,
  25154. 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd
  25155. };
  25156. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = {
  25157. 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13,
  25158. 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6,
  25159. 0x35, 0x78, 0xdf, 0xa4
  25160. };
  25161. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = {
  25162. 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f,
  25163. 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff
  25164. };
  25165. /* 128-bit key, kdrIdx = 8 */
  25166. WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = {
  25167. 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76,
  25168. 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04
  25169. };
  25170. WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = {
  25171. 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3,
  25172. 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76
  25173. };
  25174. WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = {
  25175. 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60
  25176. };
  25177. WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = {
  25178. 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2,
  25179. 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74
  25180. };
  25181. WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = {
  25182. 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6,
  25183. 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66,
  25184. 0xea, 0x31, 0x24, 0xe6
  25185. };
  25186. WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = {
  25187. 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a,
  25188. 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f
  25189. };
  25190. WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = {
  25191. 0x4a, 0x7d, 0xaa, 0x85
  25192. };
  25193. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = {
  25194. 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c,
  25195. 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88
  25196. };
  25197. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = {
  25198. 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13,
  25199. 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17,
  25200. 0x05, 0x18, 0xe3, 0xed
  25201. };
  25202. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = {
  25203. 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46,
  25204. 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6
  25205. };
  25206. /* SRTCP w/ 48-bit idx - KDR 0 (-1) */
  25207. WOLFSSL_SMALL_STACK_STATIC const byte mk48_1[] = {
  25208. 0xFF, 0xB6, 0xCB, 0x09, 0x71, 0x3F, 0x63, 0x4D,
  25209. 0x7F, 0x42, 0xED, 0xA8, 0x12, 0x81, 0x50, 0xE6
  25210. };
  25211. WOLFSSL_SMALL_STACK_STATIC const byte ms48_1[] = {
  25212. 0x1F, 0x04, 0x76, 0xC8, 0x7F, 0x58, 0x23, 0xEF,
  25213. 0xD3, 0x57, 0xB2, 0xBD, 0xF1, 0x32
  25214. };
  25215. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_1[] = {
  25216. 0x00, 0x00, 0x08, 0x56, 0xBC, 0x39
  25217. };
  25218. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_1[] = {
  25219. 0xD2, 0xC3, 0xF3, 0x49, 0x00, 0x1A, 0x18, 0x0F,
  25220. 0xB6, 0x05, 0x5A, 0x5A, 0x67, 0x8E, 0xE5, 0xB2
  25221. };
  25222. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_1[] = {
  25223. 0x8D, 0x54, 0xBE, 0xB5, 0x7B, 0x7F, 0x7A, 0xAB,
  25224. 0xF5, 0x46, 0xCE, 0x5B, 0x45, 0x69, 0x4A, 0x75,
  25225. 0x81, 0x2A, 0xE2, 0xCB
  25226. };
  25227. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_1[] = {
  25228. 0x76, 0x3C, 0x97, 0x6A, 0x45, 0x31, 0xA7, 0x79,
  25229. 0x3C, 0x28, 0x4A, 0xA6, 0x82, 0x03
  25230. };
  25231. /* SRTCP w/ 48-bit idx - KDR 19 */
  25232. WOLFSSL_SMALL_STACK_STATIC const byte mk48_2[] = {
  25233. 0xBD, 0x1D, 0x71, 0x6B, 0xDA, 0x28, 0xE3, 0xFC,
  25234. 0xA5, 0xA0, 0x66, 0x3F, 0x2E, 0x34, 0xA8, 0x58
  25235. };
  25236. WOLFSSL_SMALL_STACK_STATIC const byte ms48_2[] = {
  25237. 0x79, 0x06, 0xE5, 0xAB, 0x5C, 0x2B, 0x1B, 0x69,
  25238. 0xFA, 0xEE, 0xD2, 0x29, 0x57, 0x3C
  25239. };
  25240. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_2[] = {
  25241. 0x00, 0x00, 0x59, 0xD0, 0xC2, 0xE8
  25242. };
  25243. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_2[] = {
  25244. 0xB9, 0xD7, 0xAD, 0xD8, 0x90, 0x94, 0xC2, 0x92,
  25245. 0xA5, 0x04, 0x87, 0xC4, 0x8C, 0xEF, 0xE2, 0xA3
  25246. };
  25247. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_2[] = {
  25248. 0x07, 0xD5, 0xC4, 0xD2, 0x06, 0xFB, 0x63, 0x15,
  25249. 0xC2, 0x9C, 0x7F, 0x55, 0xD1, 0x16, 0x5C, 0xB5,
  25250. 0xB7, 0x44, 0x54, 0xBD
  25251. };
  25252. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_2[] = {
  25253. 0x0C, 0x5E, 0x53, 0xC1, 0xD0, 0x75, 0xAD, 0x65,
  25254. 0xBF, 0x51, 0x74, 0x50, 0x89, 0xD7
  25255. };
  25256. int kdr_48_1 = -1;
  25257. int kdr_48_2 = 19;
  25258. #define SRTP_TV_CNT 4
  25259. Srtp_Kdf_Tv tv[SRTP_TV_CNT] = {
  25260. { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1,
  25261. index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0,
  25262. 16, 20, 14 },
  25263. { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0,
  25264. index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1,
  25265. 24, 20, 14 },
  25266. { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1,
  25267. index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2,
  25268. 32, 20, 14 },
  25269. { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8,
  25270. index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3,
  25271. 16, 20, 14 },
  25272. };
  25273. int i;
  25274. int idx;
  25275. unsigned char keyE[32];
  25276. unsigned char keyA[20];
  25277. unsigned char keyS[14];
  25278. WOLFSSL_ENTER("srtpkdf_test");
  25279. for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) {
  25280. #ifndef WOLFSSL_AES_128
  25281. if (tv[i].keySz == AES_128_KEY_SIZE) {
  25282. continue;
  25283. }
  25284. #endif
  25285. #ifndef WOLFSSL_AES_192
  25286. if (tv[i].keySz == AES_192_KEY_SIZE) {
  25287. continue;
  25288. }
  25289. #endif
  25290. #ifndef WOLFSSL_AES_256
  25291. if (tv[i].keySz == AES_256_KEY_SIZE) {
  25292. continue;
  25293. }
  25294. #endif
  25295. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25296. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25297. keyS, tv[i].ksSz);
  25298. if (ret != 0)
  25299. return WC_TEST_RET_ENC_EC(ret);
  25300. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25301. return WC_TEST_RET_ENC_NC;
  25302. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25303. return WC_TEST_RET_ENC_NC;
  25304. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25305. return WC_TEST_RET_ENC_NC;
  25306. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25307. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION,
  25308. keyE, tv[i].keSz);
  25309. if (ret != 0)
  25310. return WC_TEST_RET_ENC_EC(ret);
  25311. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25312. return WC_TEST_RET_ENC_NC;
  25313. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25314. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH,
  25315. keyA, tv[i].kaSz);
  25316. if (ret != 0)
  25317. return WC_TEST_RET_ENC_EC(ret);
  25318. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25319. return WC_TEST_RET_ENC_NC;
  25320. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25321. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS,
  25322. tv[i].ksSz);
  25323. if (ret != 0)
  25324. return WC_TEST_RET_ENC_EC(ret);
  25325. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25326. return WC_TEST_RET_ENC_NC;
  25327. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25328. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25329. keyS, tv[i].ksSz);
  25330. if (ret != 0)
  25331. return WC_TEST_RET_ENC_EC(ret);
  25332. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25333. return WC_TEST_RET_ENC_NC;
  25334. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25335. return WC_TEST_RET_ENC_NC;
  25336. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25337. return WC_TEST_RET_ENC_NC;
  25338. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25339. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c,
  25340. WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz);
  25341. if (ret != 0)
  25342. return WC_TEST_RET_ENC_EC(ret);
  25343. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25344. return WC_TEST_RET_ENC_NC;
  25345. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25346. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH,
  25347. keyA, tv[i].kaSz);
  25348. if (ret != 0)
  25349. return WC_TEST_RET_ENC_EC(ret);
  25350. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25351. return WC_TEST_RET_ENC_NC;
  25352. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25353. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
  25354. keyS, tv[i].ksSz);
  25355. if (ret != 0)
  25356. return WC_TEST_RET_ENC_EC(ret);
  25357. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25358. return WC_TEST_RET_ENC_NC;
  25359. }
  25360. #ifdef WOLFSSL_AES_128
  25361. i = 0;
  25362. #elif defined(WOLFSSL_AES_192)
  25363. i = 1;
  25364. #else
  25365. i = 2;
  25366. #endif
  25367. ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25368. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25369. keyS, tv[i].ksSz);
  25370. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25371. return WC_TEST_RET_ENC_EC(ret);
  25372. ret = wc_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25373. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25374. keyS, tv[i].ksSz);
  25375. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25376. return WC_TEST_RET_ENC_EC(ret);
  25377. ret = wc_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25378. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25379. keyS, tv[i].ksSz);
  25380. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25381. return WC_TEST_RET_ENC_EC(ret);
  25382. ret = wc_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25383. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25384. keyS, tv[i].ksSz);
  25385. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25386. return WC_TEST_RET_ENC_EC(ret);
  25387. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25388. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25389. keyS, tv[i].ksSz);
  25390. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25391. return WC_TEST_RET_ENC_EC(ret);
  25392. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25393. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25394. keyS, tv[i].ksSz);
  25395. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25396. return WC_TEST_RET_ENC_EC(ret);
  25397. ret = wc_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25398. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25399. keyS, tv[i].ksSz);
  25400. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25401. return WC_TEST_RET_ENC_EC(ret);
  25402. ret = wc_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25403. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25404. keyS, tv[i].ksSz);
  25405. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25406. return WC_TEST_RET_ENC_EC(ret);
  25407. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25408. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25409. keyS, tv[i].ksSz);
  25410. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25411. return WC_TEST_RET_ENC_EC(ret);
  25412. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25413. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25414. keyS, tv[i].ksSz);
  25415. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25416. return WC_TEST_RET_ENC_EC(ret);
  25417. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25418. 25, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25419. keyS, tv[i].ksSz);
  25420. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25421. return WC_TEST_RET_ENC_EC(ret);
  25422. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25423. 25, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25424. keyS, tv[i].ksSz);
  25425. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25426. return WC_TEST_RET_ENC_EC(ret);
  25427. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25428. -2, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25429. keyS, tv[i].ksSz);
  25430. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25431. return WC_TEST_RET_ENC_EC(ret);
  25432. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25433. -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25434. keyS, tv[i].ksSz);
  25435. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25436. return WC_TEST_RET_ENC_EC(ret);
  25437. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25438. tv[i].kdfIdx, tv[i].index, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25439. keyS, tv[i].ksSz);
  25440. if (ret != 0)
  25441. return WC_TEST_RET_ENC_EC(ret);
  25442. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25443. tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25444. keyS, tv[i].ksSz);
  25445. if (ret != 0)
  25446. return WC_TEST_RET_ENC_EC(ret);
  25447. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25448. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25449. keyS, tv[i].ksSz);
  25450. if (ret != 0)
  25451. return WC_TEST_RET_ENC_EC(ret);
  25452. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25453. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25454. keyS, tv[i].ksSz);
  25455. if (ret != 0)
  25456. return WC_TEST_RET_ENC_EC(ret);
  25457. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25458. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25459. NULL, tv[i].ksSz);
  25460. if (ret != 0)
  25461. return WC_TEST_RET_ENC_EC(ret);
  25462. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25463. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25464. NULL, tv[i].ksSz);
  25465. if (ret != 0)
  25466. return WC_TEST_RET_ENC_EC(ret);
  25467. idx = wc_SRTP_KDF_kdr_to_idx(0);
  25468. if (idx != -1)
  25469. return WC_TEST_RET_ENC_NC;
  25470. for (i = 0; i < 32; i++) {
  25471. word32 kdr = 1U << i;
  25472. /* SRTCP w/ 48-bit IDX, 128-bit key test */
  25473. if (i == 0) {
  25474. ret = wc_SRTCP_KDF_ex(mk48_1, (word32)sizeof(mk48_1),
  25475. ms48_1, (word32)sizeof(ms48_1),
  25476. kdr_48_1, srtcp48idx_1, keyE, tv[i].keSz,
  25477. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25478. WC_SRTCP_48BIT_IDX);
  25479. if (ret != 0)
  25480. return WC_TEST_RET_ENC_EC(ret);
  25481. if (XMEMCMP(keyE, srtcpKe_48_1, tv[i].keSz) != 0)
  25482. return WC_TEST_RET_ENC_NC;
  25483. if (XMEMCMP(keyA, srtcpKa_48_1, tv[i].kaSz) != 0)
  25484. return WC_TEST_RET_ENC_NC;
  25485. if (XMEMCMP(keyS, srtcpKs_48_1, tv[i].ksSz) != 0)
  25486. return WC_TEST_RET_ENC_NC;
  25487. ret = wc_SRTCP_KDF_ex(mk48_2, (word32)sizeof(mk48_2),
  25488. ms48_2, (word32)sizeof(ms48_2),
  25489. kdr_48_2, srtcp48idx_2, keyE, tv[i].keSz,
  25490. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25491. WC_SRTCP_48BIT_IDX);
  25492. if (ret != 0)
  25493. return WC_TEST_RET_ENC_EC(ret);
  25494. if (XMEMCMP(keyE, srtcpKe_48_2, tv[i].keSz) != 0)
  25495. return WC_TEST_RET_ENC_NC;
  25496. if (XMEMCMP(keyA, srtcpKa_48_2, tv[i].kaSz) != 0)
  25497. return WC_TEST_RET_ENC_NC;
  25498. if (XMEMCMP(keyS, srtcpKs_48_2, tv[i].ksSz) != 0)
  25499. return WC_TEST_RET_ENC_NC;
  25500. }
  25501. idx = wc_SRTP_KDF_kdr_to_idx(kdr);
  25502. if (idx != i)
  25503. return WC_TEST_RET_ENC_NC;
  25504. }
  25505. return 0;
  25506. }
  25507. #endif
  25508. #ifdef HAVE_ECC
  25509. /* size to use for ECC key gen tests */
  25510. #ifndef ECC_KEYGEN_SIZE
  25511. #if !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  25512. #define ECC_KEYGEN_SIZE 32
  25513. #elif defined(HAVE_ECC384)
  25514. #define ECC_KEYGEN_SIZE 48
  25515. #elif defined(HAVE_ECC224)
  25516. #define ECC_KEYGEN_SIZE 28
  25517. #elif defined(HAVE_ECC521)
  25518. #define ECC_KEYGEN_SIZE 66
  25519. #else
  25520. #error No ECC keygen size defined for test
  25521. #endif
  25522. #endif
  25523. #ifdef BENCH_EMBEDDED
  25524. #define ECC_SHARED_SIZE 128
  25525. #else
  25526. #define ECC_SHARED_SIZE MAX_ECC_BYTES
  25527. #endif
  25528. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  25529. #define HAVE_ECC_DETERMINISTIC_K
  25530. #define ECC_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  25531. #else
  25532. #define ECC_DIGEST_SIZE MAX_ECC_BYTES
  25533. #endif
  25534. #define ECC_SIG_SIZE ECC_MAX_SIG_SIZE
  25535. #ifdef NO_ECC_SECP
  25536. #define NO_ECC_VECTOR_TEST
  25537. #endif
  25538. #ifndef NO_ECC_VECTOR_TEST
  25539. #if (defined(HAVE_ECC192) || defined(HAVE_ECC224) ||\
  25540. !defined(NO_ECC256) || defined(HAVE_ECC384) ||\
  25541. defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25542. #define HAVE_ECC_VECTOR_TEST
  25543. #endif
  25544. #endif
  25545. #ifdef HAVE_ECC_VECTOR_TEST
  25546. typedef struct eccVector {
  25547. const char* msg; /* SHA-1 Encoded Message */
  25548. const char* Qx;
  25549. const char* Qy;
  25550. const char* d; /* Private Key */
  25551. const char* R;
  25552. const char* S;
  25553. const char* curveName;
  25554. word32 msgLen;
  25555. word32 keySize;
  25556. const byte* r;
  25557. word32 rSz;
  25558. const byte* s;
  25559. word32 sSz;
  25560. } eccVector;
  25561. #if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  25562. static wc_test_ret_t ecc_test_vector_item(const eccVector* vector)
  25563. {
  25564. wc_test_ret_t ret = 0;
  25565. int verify = 0;
  25566. word32 sigSz;
  25567. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25568. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25569. #else
  25570. ecc_key userA[1];
  25571. #endif
  25572. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25573. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25574. word32 sigRawSz, rSz = MAX_ECC_BYTES, sSz = MAX_ECC_BYTES;
  25575. WC_DECLARE_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25576. WC_DECLARE_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25577. WC_DECLARE_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25578. #endif
  25579. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25580. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25581. WC_ALLOC_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25582. WC_ALLOC_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25583. WC_ALLOC_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25584. #endif
  25585. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  25586. if (sig == NULL)
  25587. ERROR_OUT(MEMORY_E, done);
  25588. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25589. if (sigRaw == NULL || r == NULL || s == NULL)
  25590. ERROR_OUT(MEMORY_E, done);
  25591. #endif
  25592. #endif
  25593. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25594. if (userA == NULL)
  25595. ERROR_OUT(MEMORY_E, done);
  25596. #endif
  25597. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  25598. if (ret != 0)
  25599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25600. ret = wc_ecc_import_raw(userA, vector->Qx, vector->Qy,
  25601. vector->d, vector->curveName);
  25602. if (ret != 0)
  25603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25604. #if !defined(NO_ASN)
  25605. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25606. sigSz = ECC_SIG_SIZE;
  25607. ret = wc_ecc_rs_to_sig(vector->R, vector->S, sig, &sigSz);
  25608. if (ret != 0)
  25609. goto done;
  25610. #if !defined(HAVE_SELFTEST)
  25611. XMEMSET(sigRaw, 0, ECC_SIG_SIZE);
  25612. sigRawSz = ECC_SIG_SIZE;
  25613. ret = wc_ecc_rs_raw_to_sig(vector->r, vector->rSz, vector->s, vector->sSz,
  25614. sigRaw, &sigRawSz);
  25615. if (ret != 0)
  25616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25617. if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) {
  25618. ret = WC_TEST_RET_ENC_NC;
  25619. goto done;
  25620. }
  25621. ret = wc_ecc_sig_to_rs(sig, sigSz, r, &rSz, s, &sSz);
  25622. if (ret != 0)
  25623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25624. if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 ||
  25625. sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) {
  25626. ret = WC_TEST_RET_ENC_NC;
  25627. goto done;
  25628. }
  25629. #endif /* !HAVE_SELFTEST */
  25630. #else
  25631. /* Signature will be R+S directly */
  25632. /* Make sure and zero pad if r or s is less than key size */
  25633. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25634. sigSz = vector->keySize * 2;
  25635. XMEMCPY(sig + (vector->keySize - vector->rSz),
  25636. vector->r, vector->rSz);
  25637. XMEMCPY(sig + vector->keySize + (vector->keySize - vector->sSz),
  25638. vector->s, vector->sSz);
  25639. #endif /* !NO_ASN */
  25640. #ifdef HAVE_ECC_VERIFY
  25641. do {
  25642. #if defined(WOLFSSL_ASYNC_CRYPT)
  25643. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25644. #endif
  25645. if (ret == 0)
  25646. ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg,
  25647. vector->msgLen, &verify, userA);
  25648. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25649. if (ret != 0)
  25650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25651. TEST_SLEEP();
  25652. if (verify != 1)
  25653. ret = WC_TEST_RET_ENC_NC;
  25654. #endif
  25655. done:
  25656. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25657. if (userA != NULL) {
  25658. wc_ecc_free(userA);
  25659. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25660. }
  25661. #else
  25662. wc_ecc_free(userA);
  25663. #endif
  25664. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25665. WC_FREE_VAR(sigRaw, HEAP_HINT);
  25666. WC_FREE_VAR(r, HEAP_HINT);
  25667. WC_FREE_VAR(s, HEAP_HINT);
  25668. #endif
  25669. WC_FREE_VAR(sig, HEAP_HINT);
  25670. return ret;
  25671. }
  25672. static wc_test_ret_t ecc_test_vector(int keySize)
  25673. {
  25674. wc_test_ret_t ret;
  25675. eccVector vec;
  25676. XMEMSET(&vec, 0, sizeof(vec));
  25677. vec.keySize = (word32)keySize;
  25678. switch(keySize) {
  25679. #if defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)
  25680. case 14:
  25681. return 0;
  25682. #endif /* HAVE_ECC112 */
  25683. #if defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)
  25684. case 16:
  25685. return 0;
  25686. #endif /* HAVE_ECC128 */
  25687. #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)
  25688. case 20:
  25689. return 0;
  25690. #endif /* HAVE_ECC160 */
  25691. #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
  25692. case 24:
  25693. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  25694. #if 1
  25695. vec.msg = "\x60\x80\x79\x42\x3f\x12\x42\x1d\xe6\x16\xb7\x49\x3e\xbe\x55\x1c\xf4\xd6\x5b\x92";
  25696. vec.msgLen = 20;
  25697. #else
  25698. /* This is the raw message prior to SHA-1 */
  25699. vec.msg =
  25700. "\xeb\xf7\x48\xd7\x48\xeb\xbc\xa7\xd2\x9f\xb4\x73\x69\x8a\x6e\x6b"
  25701. "\x4f\xb1\x0c\x86\x5d\x4a\xf0\x24\xcc\x39\xae\x3d\xf3\x46\x4b\xa4"
  25702. "\xf1\xd6\xd4\x0f\x32\xbf\x96\x18\xa9\x1b\xb5\x98\x6f\xa1\xa2\xaf"
  25703. "\x04\x8a\x0e\x14\xdc\x51\xe5\x26\x7e\xb0\x5e\x12\x7d\x68\x9d\x0a"
  25704. "\xc6\xf1\xa7\xf1\x56\xce\x06\x63\x16\xb9\x71\xcc\x7a\x11\xd0\xfd"
  25705. "\x7a\x20\x93\xe2\x7c\xf2\xd0\x87\x27\xa4\xe6\x74\x8c\xc3\x2f\xd5"
  25706. "\x9c\x78\x10\xc5\xb9\x01\x9d\xf2\x1c\xdc\xc0\xbc\xa4\x32\xc0\xa3"
  25707. "\xee\xd0\x78\x53\x87\x50\x88\x77\x11\x43\x59\xce\xe4\xa0\x71\xcf";
  25708. vec.msgLen = 128;
  25709. #endif
  25710. vec.Qx = "07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6";
  25711. vec.Qy = "76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477";
  25712. vec.d = "e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3";
  25713. vec.R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  25714. vec.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  25715. vec.curveName = "SECP192R1";
  25716. vec.r = (byte*)"\x69\x94\xd9\x62\xbd\xd0\xd7\x93\xff\xdd\xf8\x55"
  25717. "\xec\x5b\xf2\xf9\x1a\x96\x98\xb4\x62\x58\xa6\x3e";
  25718. vec.rSz = 24;
  25719. vec.s = (byte*)"\x02\xba\x64\x65\xa2\x34\x90\x37\x44\xab\x02\xbc"
  25720. "\x85\x21\x40\x5b\x73\xcf\x5f\xc0\x0e\x1a\x9f\x41";
  25721. vec.sSz = 24;
  25722. break;
  25723. #endif /* HAVE_ECC192 */
  25724. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  25725. case 28:
  25726. /* first [P-224,SHA-1] vector from FIPS 186-3 NIST vectors */
  25727. #if 1
  25728. vec.msg = "\xb9\xa3\xb8\x6d\xb0\xba\x99\xfd\xc6\xd2\x94\x6b\xfe\xbe\x9c\xe8\x3f\x10\x74\xfc";
  25729. vec.msgLen = 20;
  25730. #else
  25731. /* This is the raw message prior to SHA-1 */
  25732. vec.msg =
  25733. "\x36\xc8\xb2\x29\x86\x48\x7f\x67\x7c\x18\xd0\x97\x2a\x9e\x20\x47"
  25734. "\xb3\xaf\xa5\x9e\xc1\x62\x76\x4e\xc3\x0b\x5b\x69\xe0\x63\x0f\x99"
  25735. "\x0d\x4e\x05\xc2\x73\xb0\xe5\xa9\xd4\x28\x27\xb6\x95\xfc\x2d\x64"
  25736. "\xd9\x13\x8b\x1c\xf4\xc1\x21\x55\x89\x4c\x42\x13\x21\xa7\xbb\x97"
  25737. "\x0b\xdc\xe0\xfb\xf0\xd2\xae\x85\x61\xaa\xd8\x71\x7f\x2e\x46\xdf"
  25738. "\xe3\xff\x8d\xea\xb4\xd7\x93\x23\x56\x03\x2c\x15\x13\x0d\x59\x9e"
  25739. "\x26\xc1\x0f\x2f\xec\x96\x30\x31\xac\x69\x38\xa1\x8d\x66\x45\x38"
  25740. "\xb9\x4d\xac\x55\x34\xef\x7b\x59\x94\x24\xd6\x9b\xe1\xf7\x1c\x20";
  25741. vec.msgLen = 128;
  25742. #endif
  25743. vec.Qx = "8a4dca35136c4b70e588e23554637ae251077d1365a6ba5db9585de7";
  25744. vec.Qy = "ad3dee06de0be8279d4af435d7245f14f3b4f82eb578e519ee0057b1";
  25745. vec.d = "97c4b796e1639dd1035b708fc00dc7ba1682cec44a1002a1a820619f";
  25746. vec.R = "147b33758321e722a0360a4719738af848449e2c1d08defebc1671a7";
  25747. vec.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b";
  25748. vec.curveName = "SECP224R1";
  25749. vec.r = (byte*)"\x14\x7b\x33\x75\x83\x21\xe7\x22\xa0\x36\x0a\x47"
  25750. "\x19\x73\x8a\xf8\x48\x44\x9e\x2c\x1d\x08\xde\xfe"
  25751. "\xbc\x16\x71\xa7";
  25752. vec.rSz = 28;
  25753. vec.s = (byte*)"\x24\xfc\x7e\xd7\xf1\x35\x2c\xa3\x87\x2a\xa0\x91"
  25754. "\x61\x91\x28\x9e\x2e\x04\xd4\x54\x93\x5d\x50\xfe"
  25755. "\x6a\xf3\xad\x5b";
  25756. vec.sSz = 28;
  25757. break;
  25758. #endif /* HAVE_ECC224 */
  25759. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  25760. case 30:
  25761. return 0;
  25762. #endif /* HAVE_ECC239 */
  25763. #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
  25764. case 32:
  25765. /* first [P-256,SHA-1] vector from FIPS 186-3 NIST vectors */
  25766. #if 1
  25767. vec.msg = "\xa3\xf9\x1a\xe2\x1b\xa6\xb3\x03\x98\x64\x47\x2f\x18\x41\x44\xc6\xaf\x62\xcd\x0e";
  25768. vec.msgLen = 20;
  25769. #else
  25770. /* This is the raw message prior to SHA-1 */
  25771. vec.msg =
  25772. "\xa2\x4b\x21\x76\x2e\x6e\xdb\x15\x3c\xc1\x14\x38\xdb\x0e\x92\xcd"
  25773. "\xf5\x2b\x86\xb0\x6c\xa9\x70\x16\x06\x27\x59\xc7\x0d\x36\xd1\x56"
  25774. "\x2c\xc9\x63\x0d\x7f\xc7\xc7\x74\xb2\x8b\x54\xe3\x1e\xf5\x58\x72"
  25775. "\xb2\xa6\x5d\xf1\xd7\xec\x26\xde\xbb\x33\xe7\xd9\x27\xef\xcc\xf4"
  25776. "\x6b\x63\xde\x52\xa4\xf4\x31\xea\xca\x59\xb0\x5d\x2e\xde\xc4\x84"
  25777. "\x5f\xff\xc0\xee\x15\x03\x94\xd6\x1f\x3d\xfe\xcb\xcd\xbf\x6f\x5a"
  25778. "\x73\x38\xd0\xbe\x3f\x2a\x77\x34\x51\x98\x3e\xba\xeb\x48\xf6\x73"
  25779. "\x8f\xc8\x95\xdf\x35\x7e\x1a\x48\xa6\x53\xbb\x35\x5a\x31\xa1\xb4"
  25780. vec.msgLen = 128;
  25781. #endif
  25782. vec.Qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  25783. vec.Qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  25784. vec.d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  25785. vec.R = "2b826f5d44e2d0b6de531ad96b51e8f0c56fdfead3c236892e4d84eacfc3b75c";
  25786. vec.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248";
  25787. vec.r = (byte*)"\x2b\x82\x6f\x5d\x44\xe2\xd0\xb6\xde\x53\x1a\xd9"
  25788. "\x6b\x51\xe8\xf0\xc5\x6f\xdf\xea\xd3\xc2\x36\x89"
  25789. "\x2e\x4d\x84\xea\xcf\xc3\xb7\x5c";
  25790. vec.rSz = 32;
  25791. vec.s = (byte*)"\xa2\x24\x8b\x62\xc0\x3d\xb3\x5a\x7c\xd6\x3e\x8a"
  25792. "\x12\x0a\x35\x21\xa8\x9d\x3d\x2f\x61\xff\x99\x03"
  25793. "\x5a\x21\x48\xae\x32\xe3\xa2\x48";
  25794. vec.sSz = 32;
  25795. vec.curveName = "SECP256R1";
  25796. break;
  25797. #endif /* !NO_ECC256 */
  25798. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  25799. case 40:
  25800. return 0;
  25801. #endif /* HAVE_ECC320 */
  25802. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  25803. case 48:
  25804. /* first [P-384,SHA-1] vector from FIPS 186-3 NIST vectors */
  25805. #if 1
  25806. vec.msg = "\x9b\x9f\x8c\x95\x35\xa5\xca\x26\x60\x5d\xb7\xf2\xfa\x57\x3b\xdf\xc3\x2e\xab\x8b";
  25807. vec.msgLen = 20;
  25808. #else
  25809. /* This is the raw message prior to SHA-1 */
  25810. vec.msg =
  25811. "\xab\xe1\x0a\xce\x13\xe7\xe1\xd9\x18\x6c\x48\xf7\x88\x9d\x51\x47"
  25812. "\x3d\x3a\x09\x61\x98\x4b\xc8\x72\xdf\x70\x8e\xcc\x3e\xd3\xb8\x16"
  25813. "\x9d\x01\xe3\xd9\x6f\xc4\xf1\xd5\xea\x00\xa0\x36\x92\xbc\xc5\xcf"
  25814. "\xfd\x53\x78\x7c\x88\xb9\x34\xaf\x40\x4c\x03\x9d\x32\x89\xb5\xba"
  25815. "\xc5\xae\x7d\xb1\x49\x68\x75\xb5\xdc\x73\xc3\x09\xf9\x25\xc1\x3d"
  25816. "\x1c\x01\xab\xda\xaf\xeb\xcd\xac\x2c\xee\x43\x39\x39\xce\x8d\x4a"
  25817. "\x0a\x5d\x57\xbb\x70\x5f\x3b\xf6\xec\x08\x47\x95\x11\xd4\xb4\xa3"
  25818. "\x21\x1f\x61\x64\x9a\xd6\x27\x43\x14\xbf\x0d\x43\x8a\x81\xe0\x60"
  25819. vec.msgLen = 128;
  25820. #endif
  25821. vec.Qx = "e55fee6c49d8d523f5ce7bf9c0425ce4ff650708b7de5cfb095901523979a7f042602db30854735369813b5c3f5ef868";
  25822. vec.Qy = "28f59cc5dc509892a988d38a8e2519de3d0c4fd0fbdb0993e38f18506c17606c5e24249246f1ce94983a5361c5be983e";
  25823. vec.d = "a492ce8fa90084c227e1a32f7974d39e9ff67a7e8705ec3419b35fb607582bebd461e0b1520ac76ec2dd4e9b63ebae71";
  25824. vec.R = "6820b8585204648aed63bdff47f6d9acebdea62944774a7d14f0e14aa0b9a5b99545b2daee6b3c74ebf606667a3f39b7";
  25825. vec.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907";
  25826. vec.curveName = "SECP384R1";
  25827. vec.r = (byte*)"\x68\x20\xb8\x58\x52\x04\x64\x8a\xed\x63\xbd\xff"
  25828. "\x47\xf6\xd9\xac\xeb\xde\xa6\x29\x44\x77\x4a\x7d"
  25829. "\x14\xf0\xe1\x4a\xa0\xb9\xa5\xb9\x95\x45\xb2\xda"
  25830. "\xee\x6b\x3c\x74\xeb\xf6\x06\x66\x7a\x3f\x39\xb7";
  25831. vec.rSz = 48;
  25832. vec.s = (byte*)"\x49\x1a\xf1\xd0\xcc\xcd\x56\xdd\xd5\x20\xb2\x33"
  25833. "\x77\x5d\x0b\xc6\xb4\x0a\x62\x55\xcc\x55\x20\x7d"
  25834. "\x8e\x93\x56\x74\x1f\x23\xc9\x6c\x14\x71\x42\x21"
  25835. "\x07\x8d\xbd\x5c\x17\xf4\xfd\xd8\x9b\x32\xa9\x07";
  25836. vec.sSz = 48;
  25837. break;
  25838. #endif /* HAVE_ECC384 */
  25839. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  25840. case 64:
  25841. return 0;
  25842. #endif /* HAVE_ECC512 */
  25843. #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  25844. case 66:
  25845. /* first [P-521,SHA-1] vector from FIPS 186-3 NIST vectors */
  25846. #if 1
  25847. vec.msg = "\x1b\xf7\x03\x9c\xca\x23\x94\x27\x3f\x11\xa1\xd4\x8d\xcc\xb4\x46\x6f\x31\x61\xdf";
  25848. vec.msgLen = 20;
  25849. #else
  25850. /* This is the raw message prior to SHA-1 */
  25851. vec.msg =
  25852. "\x50\x3f\x79\x39\x34\x0a\xc7\x23\xcd\x4a\x2f\x4e\x6c\xcc\x27\x33"
  25853. "\x38\x3a\xca\x2f\xba\x90\x02\x19\x9d\x9e\x1f\x94\x8b\xe0\x41\x21"
  25854. "\x07\xa3\xfd\xd5\x14\xd9\x0c\xd4\xf3\x7c\xc3\xac\x62\xef\x00\x3a"
  25855. "\x2d\xb1\xd9\x65\x7a\xb7\x7f\xe7\x55\xbf\x71\xfa\x59\xe4\xd9\x6e"
  25856. "\xa7\x2a\xe7\xbf\x9d\xe8\x7d\x79\x34\x3b\xc1\xa4\xbb\x14\x4d\x16"
  25857. "\x28\xd1\xe9\xe9\xc8\xed\x80\x8b\x96\x2c\x54\xe5\xf9\x6d\x53\xda"
  25858. "\x14\x7a\x96\x38\xf9\x4a\x91\x75\xd8\xed\x61\x05\x5f\x0b\xa5\x73"
  25859. "\xa8\x2b\xb7\xe0\x18\xee\xda\xc4\xea\x7b\x36\x2e\xc8\x9c\x38\x2b"
  25860. vec.msgLen = 128;
  25861. #endif
  25862. vec.Qx = "12fbcaeffa6a51f3ee4d3d2b51c5dec6d7c726ca353fc014ea2bf7cfbb9b910d32cbfa6a00fe39b6cdb8946f22775398b2e233c0cf144d78c8a7742b5c7a3bb5d23";
  25863. vec.Qy = "09cdef823dd7bf9a79e8cceacd2e4527c231d0ae5967af0958e931d7ddccf2805a3e618dc3039fec9febbd33052fe4c0fee98f033106064982d88f4e03549d4a64d";
  25864. vec.d = "1bd56bd106118eda246155bd43b42b8e13f0a6e25dd3bb376026fab4dc92b6157bc6dfec2d15dd3d0cf2a39aa68494042af48ba9601118da82c6f2108a3a203ad74";
  25865. vec.R = "0bd117b4807710898f9dd7778056485777668f0e78e6ddf5b000356121eb7a220e9493c7f9a57c077947f89ac45d5acb6661bbcd17abb3faea149ba0aa3bb1521be";
  25866. vec.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c";
  25867. vec.curveName = "SECP521R1";
  25868. vec.r = (byte*)"\xbd\x11\x7b\x48\x07\x71\x08\x98\xf9\xdd\x77\x78"
  25869. "\x05\x64\x85\x77\x76\x68\xf0\xe7\x8e\x6d\xdf\x5b"
  25870. "\x00\x03\x56\x12\x1e\xb7\xa2\x20\xe9\x49\x3c\x7f"
  25871. "\x9a\x57\xc0\x77\x94\x7f\x89\xac\x45\xd5\xac\xb6"
  25872. "\x66\x1b\xbc\xd1\x7a\xbb\x3f\xae\xa1\x49\xba\x0a"
  25873. "\xa3\xbb\x15\x21\xbe";
  25874. vec.rSz = 65;
  25875. vec.s = (byte*)"\x19\xcd\x2c\x5c\x3f\x98\x70\xec\xde\xb9\xb3\x23"
  25876. "\xab\xdf\x3a\x98\xcd\x5e\x23\x1d\x85\xc6\xdd\xc5"
  25877. "\xb7\x1a\xb1\x90\x73\x9f\x7f\x22\x6e\x6b\x13\x4b"
  25878. "\xa1\xd5\x88\x9d\xde\xb2\x75\x1d\xab\xd9\x79\x11"
  25879. "\xdf\xf9\x0c\x34\x68\x4c\xdb\xe7\xbb\x66\x9b\x6c"
  25880. "\x3d\x22\xf2\x48\x0c";
  25881. vec.sSz = 65;
  25882. break;
  25883. #endif /* HAVE_ECC521 */
  25884. default:
  25885. return WC_TEST_RET_ENC_EC(NOT_COMPILED_IN); /* Invalid key size /
  25886. * Not supported
  25887. */
  25888. }; /* Switch */
  25889. ret = ecc_test_vector_item(&vec);
  25890. if (ret < 0) {
  25891. return ret;
  25892. }
  25893. return 0;
  25894. }
  25895. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  25896. #if defined(HAVE_ECC_SIGN) && \
  25897. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  25898. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  25899. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  25900. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  25901. static wc_test_ret_t ecdsa_test_deterministic_k_sig(ecc_key *key,
  25902. enum wc_HashType hashType, const char* msg, WC_RNG* rng, const byte* expSig,
  25903. size_t expSigSz)
  25904. {
  25905. wc_test_ret_t ret;
  25906. int verify;
  25907. byte sig[ECC_MAX_SIG_SIZE];
  25908. word32 sigSz;
  25909. unsigned char hash[WC_MAX_DIGEST_SIZE];
  25910. ret = wc_Hash(hashType,
  25911. (byte*)msg, (word32)XSTRLEN(msg),
  25912. hash, sizeof(hash));
  25913. if (ret != 0)
  25914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25915. /* Sign test */
  25916. sigSz = sizeof(sig);
  25917. do {
  25918. #if defined(WOLFSSL_ASYNC_CRYPT)
  25919. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25920. #endif
  25921. if (ret == 0)
  25922. ret = wc_ecc_sign_hash(hash, wc_HashGetDigestSize(hashType),
  25923. sig, &sigSz, rng, key);
  25924. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25925. if (ret != 0)
  25926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25927. TEST_SLEEP();
  25928. /* Compare test vector */
  25929. if (sigSz != expSigSz) {
  25930. ret = WC_TEST_RET_ENC_NC;
  25931. goto done;
  25932. }
  25933. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  25934. ret = WC_TEST_RET_ENC_NC;
  25935. goto done;
  25936. }
  25937. /* Verificiation */
  25938. verify = 0;
  25939. do {
  25940. #if defined(WOLFSSL_ASYNC_CRYPT)
  25941. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25942. #endif
  25943. if (ret == 0)
  25944. ret = wc_ecc_verify_hash(sig, sigSz,
  25945. hash, wc_HashGetDigestSize(hashType), &verify, key);
  25946. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25947. if (ret != 0)
  25948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25949. if (verify != 1) {
  25950. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  25951. }
  25952. done:
  25953. return ret;
  25954. }
  25955. static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
  25956. {
  25957. wc_test_ret_t ret;
  25958. #ifdef WOLFSSL_SMALL_STACK
  25959. ecc_key *key = NULL;
  25960. #else
  25961. ecc_key key[1];
  25962. #endif
  25963. int key_inited = 0;
  25964. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  25965. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  25966. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721";
  25967. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  25968. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6";
  25969. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  25970. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299";
  25971. #ifndef NO_SHA256
  25972. WOLFSSL_SMALL_STACK_STATIC const byte expSig256[] = {
  25973. 0x30, 0x46, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  25974. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  25975. 0x00, 0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8,
  25976. 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81,
  25977. 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9,
  25978. 0x91, 0xC3, 0x4D, 0x0E, 0xA8, 0x4E, 0xAF, 0x37,
  25979. 0x16,
  25980. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  25981. 0x00, 0xF7, 0xCB, 0x1C, 0x94, 0x2D, 0x65, 0x7C,
  25982. 0x41, 0xD4, 0x36, 0xC7, 0xA1, 0xB6, 0xE2, 0x9F,
  25983. 0x65, 0xF3, 0xE9, 0x00, 0xDB, 0xB9, 0xAF, 0xF4,
  25984. 0x06, 0x4D, 0xC4, 0xAB, 0x2F, 0x84, 0x3A, 0xCD,
  25985. 0xA8
  25986. };
  25987. #endif
  25988. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  25989. WOLFSSL_SMALL_STACK_STATIC const byte expSig384[] = {
  25990. 0x30, 0x44, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  25991. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  25992. 0x0e, 0xaf, 0xea, 0x03, 0x9b, 0x20, 0xe9, 0xb4,
  25993. 0x23, 0x09, 0xfb, 0x1d, 0x89, 0xe2, 0x13, 0x05,
  25994. 0x7c, 0xbf, 0x97, 0x3d, 0xc0, 0xcf, 0xc8, 0xf1,
  25995. 0x29, 0xed, 0xdd, 0xc8, 0x00, 0xef, 0x77, 0x19,
  25996. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  25997. 0x48, 0x61, 0xf0, 0x49, 0x1e, 0x69, 0x98, 0xb9,
  25998. 0x45, 0x51, 0x93, 0xe3, 0x4e, 0x7b, 0x0d, 0x28,
  25999. 0x4d, 0xdd, 0x71, 0x49, 0xa7, 0x4b, 0x95, 0xb9,
  26000. 0x26, 0x1f, 0x13, 0xab, 0xde, 0x94, 0x09, 0x54
  26001. };
  26002. #endif
  26003. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26004. WOLFSSL_SMALL_STACK_STATIC const byte expSig512[] = {
  26005. 0x30, 0x45, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26006. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26007. 0x00, 0x84, 0x96, 0xa6, 0x0b, 0x5e, 0x9b, 0x47,
  26008. 0xc8, 0x25, 0x48, 0x88, 0x27, 0xe0, 0x49, 0x5b,
  26009. 0x0e, 0x3f, 0xa1, 0x09, 0xec, 0x45, 0x68, 0xfd,
  26010. 0x3f, 0x8d, 0x10, 0x97, 0x67, 0x8e, 0xb9, 0x7f,
  26011. 0x00,
  26012. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26013. 0x23, 0x62, 0xab, 0x1a, 0xdb, 0xe2, 0xb8, 0xad,
  26014. 0xf9, 0xcb, 0x9e, 0xda, 0xb7, 0x40, 0xea, 0x60,
  26015. 0x49, 0xc0, 0x28, 0x11, 0x4f, 0x24, 0x60, 0xf9,
  26016. 0x65, 0x54, 0xf6, 0x1f, 0xae, 0x33, 0x02, 0xfe
  26017. };
  26018. #endif
  26019. #ifdef WOLFSSL_SMALL_STACK
  26020. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26021. if (key == NULL)
  26022. return MEMORY_E;
  26023. #endif
  26024. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26025. if (ret != 0)
  26026. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26027. key_inited = 1;
  26028. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26029. if (ret != 0)
  26030. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26031. ret = wc_ecc_set_deterministic(key, 1);
  26032. if (ret != 0)
  26033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26034. #ifndef NO_SHA256
  26035. /* Test for SHA2-256 */
  26036. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA256, msg, rng,
  26037. expSig256, sizeof(expSig256));
  26038. if (ret != 0)
  26039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26040. #endif /* !NO_SHA256 */
  26041. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26042. /* Test for SHA2-384 */
  26043. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA384, msg, rng,
  26044. expSig384, sizeof(expSig384));
  26045. if (ret != 0)
  26046. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26047. #endif /* WOLFSSL_SHA384 */
  26048. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26049. /* Test for SHA2-512 */
  26050. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA512, msg, rng,
  26051. expSig512, sizeof(expSig512));
  26052. if (ret != 0)
  26053. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26054. #endif /* WOLFSSL_SHA512 */
  26055. done:
  26056. if (key_inited)
  26057. wc_ecc_free(key);
  26058. #ifdef WOLFSSL_SMALL_STACK
  26059. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26060. #endif
  26061. return ret;
  26062. }
  26063. #endif /* NO_ECC256 || HAVE_ALL_CURVES */
  26064. #ifdef WOLFSSL_PUBLIC_MP
  26065. static wc_test_ret_t ecdsa_test_deterministic_k_rs(ecc_key *key,
  26066. enum wc_HashType hashType, const char* msg, WC_RNG* rng,
  26067. mp_int* r, mp_int* s,
  26068. mp_int* expR, mp_int* expS)
  26069. {
  26070. wc_test_ret_t ret;
  26071. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26072. int verify;
  26073. ret = wc_Hash(hashType,
  26074. (byte*)msg, (word32)XSTRLEN(msg),
  26075. hash, sizeof(hash));
  26076. if (ret != 0)
  26077. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26078. ret = wc_ecc_sign_hash_ex(hash, wc_HashGetDigestSize(hashType), rng, key,
  26079. r, s);
  26080. #if defined(WOLFSSL_ASYNC_CRYPT)
  26081. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26082. #endif
  26083. if (ret != 0)
  26084. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26085. TEST_SLEEP();
  26086. if (mp_cmp(r, expR) != MP_EQ && mp_cmp(s, expS) != MP_EQ) {
  26087. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26088. }
  26089. /* Verificiation */
  26090. verify = 0;
  26091. ret = wc_ecc_verify_hash_ex(r, s, hash, wc_HashGetDigestSize(hashType),
  26092. &verify, key);
  26093. #if defined(WOLFSSL_ASYNC_CRYPT)
  26094. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26095. #endif
  26096. if (ret != 0)
  26097. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26098. if (verify != 1) {
  26099. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26100. }
  26101. done:
  26102. return ret;
  26103. }
  26104. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  26105. /* KAT from RFC6979 */
  26106. static wc_test_ret_t ecc384_test_deterministic_k(WC_RNG* rng)
  26107. {
  26108. wc_test_ret_t ret;
  26109. #ifdef WOLFSSL_SMALL_STACK
  26110. ecc_key *key;
  26111. mp_int *r, *s, *expR, *expS;
  26112. #else
  26113. ecc_key key[1];
  26114. mp_int r[1], s[1], expR[1], expS[1];
  26115. #endif
  26116. int key_inited = 0,
  26117. tmp_mp_ints_inited = 0;
  26118. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26119. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26120. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8"
  26121. "96D5724E4C70A825F872C9EA60D2EDF5";
  26122. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26123. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64"
  26124. "DEF8F0EA9055866064A254515480BC13";
  26125. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26126. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1"
  26127. "288B231C3AE0D4FE7344FD2533264720";
  26128. #ifndef NO_SHA256
  26129. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26130. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33"
  26131. "BDE1E888E63355D92FA2B3C36D8FB2CD";
  26132. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26133. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB"
  26134. "EFDC63ECCD1AC42EC0CB8668A4FA0AB0";
  26135. #endif
  26136. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26137. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26138. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C"
  26139. "81A648152E44ACF96E36DD1E80FABE46";
  26140. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26141. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F"
  26142. "A329C145786E679E7B82C71A38628AC8";
  26143. #endif
  26144. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26145. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26146. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C"
  26147. "FE30F35CC900056D7C99CD7882433709";
  26148. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26149. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112"
  26150. "DC7CC3EF3446DEFCEB01A45C2667FDD5";
  26151. #endif
  26152. #ifdef WOLFSSL_SMALL_STACK
  26153. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26154. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26155. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26156. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26157. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26158. if ((key == NULL) ||
  26159. (r == NULL) ||
  26160. (s == NULL) ||
  26161. (expR == NULL) ||
  26162. (expS == NULL))
  26163. {
  26164. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26165. }
  26166. #endif
  26167. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26168. if (ret != MP_OKAY)
  26169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26170. tmp_mp_ints_inited = 1;
  26171. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26172. if (ret != 0)
  26173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26174. key_inited = 1;
  26175. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP384R1");
  26176. if (ret != 0)
  26177. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26178. ret = wc_ecc_set_deterministic(key, 1);
  26179. if (ret != 0)
  26180. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26181. #ifndef NO_SHA256
  26182. /* Test for SHA2-256 */
  26183. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26184. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26185. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26186. r, s, expR, expS);
  26187. if (ret != 0)
  26188. ERROR_OUT(ret, done);
  26189. #endif /* NO_SHA256 */
  26190. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26191. /* Test for SHA2-384 */
  26192. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26193. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26194. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26195. r, s, expR, expS);
  26196. if (ret != 0)
  26197. ERROR_OUT(ret, done);
  26198. #endif /* WOLFSSL_SHA384 */
  26199. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26200. /* Test for SHA2-512 */
  26201. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26202. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26203. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26204. r, s, expR, expS);
  26205. if (ret != 0)
  26206. ERROR_OUT(ret, done);
  26207. #endif /* WOLFSSL_SHA512 */
  26208. done:
  26209. if (key_inited)
  26210. wc_ecc_free(key);
  26211. if (tmp_mp_ints_inited) {
  26212. mp_free(r);
  26213. mp_free(s);
  26214. mp_free(expR);
  26215. mp_free(expS);
  26216. }
  26217. #ifdef WOLFSSL_SMALL_STACK
  26218. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26219. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26220. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26221. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26222. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26223. #endif
  26224. return ret;
  26225. }
  26226. #endif /* HAVE_ECC384 */
  26227. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  26228. /* KAT from RFC6979 */
  26229. static wc_test_ret_t ecc521_test_deterministic_k(WC_RNG* rng)
  26230. {
  26231. wc_test_ret_t ret;
  26232. #ifdef WOLFSSL_SMALL_STACK
  26233. ecc_key *key;
  26234. mp_int *r, *s, *expR, *expS;
  26235. #else
  26236. ecc_key key[1];
  26237. mp_int r[1], s[1], expR[1], expS[1];
  26238. #endif
  26239. int key_inited = 0,
  26240. tmp_mp_ints_inited = 0;
  26241. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26242. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26243. "0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C"
  26244. "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83"
  26245. "538";
  26246. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26247. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD3"
  26248. "71123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F502"
  26249. "3A4";
  26250. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26251. "0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A2"
  26252. "8A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDF"
  26253. "CF5";
  26254. #ifndef NO_SHA256
  26255. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26256. "1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659"
  26257. "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E"
  26258. "1A7";
  26259. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26260. "04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916"
  26261. "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E"
  26262. "CFC";
  26263. #endif
  26264. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26265. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26266. "1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4"
  26267. "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67"
  26268. "451";
  26269. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26270. "1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5"
  26271. "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65"
  26272. "D61";
  26273. #endif
  26274. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26275. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26276. "0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1"
  26277. "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37"
  26278. "7FA";
  26279. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26280. "0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2"
  26281. "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A"
  26282. "67A";
  26283. #endif
  26284. #ifdef WOLFSSL_SMALL_STACK
  26285. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26286. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26287. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26288. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26289. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26290. if ((key == NULL) ||
  26291. (r == NULL) ||
  26292. (s == NULL) ||
  26293. (expR == NULL) ||
  26294. (expS == NULL))
  26295. {
  26296. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26297. goto done;
  26298. }
  26299. #endif
  26300. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26301. if (ret != MP_OKAY)
  26302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26303. tmp_mp_ints_inited = 1;
  26304. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26305. if (ret != 0)
  26306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26307. key_inited = 1;
  26308. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP521R1");
  26309. if (ret != 0)
  26310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26311. ret = wc_ecc_set_deterministic(key, 1);
  26312. if (ret != 0)
  26313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26314. #ifndef NO_SHA256
  26315. /* Test for SHA2-256 */
  26316. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26317. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26318. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26319. r, s, expR, expS);
  26320. if (ret != 0)
  26321. ERROR_OUT(ret, done);
  26322. #endif /* NO_SHA256 */
  26323. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26324. /* Test for SHA2-384 */
  26325. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26326. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26327. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26328. r, s, expR, expS);
  26329. if (ret != 0)
  26330. ERROR_OUT(ret, done);
  26331. #endif /* WOLFSSL_SHA384 */
  26332. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26333. /* Test for SHA2-512 */
  26334. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26335. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26336. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26337. r, s, expR, expS);
  26338. if (ret != 0)
  26339. ERROR_OUT(ret, done);
  26340. #endif /* WOLFSSL_SHA512 */
  26341. done:
  26342. if (key_inited)
  26343. wc_ecc_free(key);
  26344. if (tmp_mp_ints_inited) {
  26345. mp_free(r);
  26346. mp_free(s);
  26347. mp_free(expR);
  26348. mp_free(expS);
  26349. }
  26350. #ifdef WOLFSSL_SMALL_STACK
  26351. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26352. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26353. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26354. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26355. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26356. #endif
  26357. return ret;
  26358. }
  26359. #endif /* HAVE_ECC521 */
  26360. #endif /* WOLFSSL_PUBLIC_MP */
  26361. #endif /* HAVE_ECC_SIGN && (WOLFSSL_ECDSA_DETERMINISTIC_K ||
  26362. WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  26363. && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  26364. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  26365. !defined(WOLFSSL_KCAPI_ECC)
  26366. static wc_test_ret_t ecc_test_sign_vectors(WC_RNG* rng)
  26367. {
  26368. wc_test_ret_t ret;
  26369. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26370. ecc_key *key = NULL;
  26371. #else
  26372. ecc_key key[1];
  26373. #endif
  26374. int key_inited = 0;
  26375. byte sig[72];
  26376. word32 sigSz;
  26377. WOLFSSL_SMALL_STACK_STATIC const unsigned char hash[32] = "test wolfSSL deterministic sign";
  26378. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26379. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26380. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26381. WOLFSSL_SMALL_STACK_STATIC const byte k[1] = { 0x02 };
  26382. WOLFSSL_SMALL_STACK_STATIC const byte expSig[71] = {
  26383. 0x30, 0x45, 0x02, 0x20, 0x7c, 0xf2, 0x7b, 0x18,
  26384. 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03,
  26385. 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2,
  26386. 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc,
  26387. 0x47, 0x66, 0x99, 0x78, 0x02, 0x21, 0x00, 0xa8,
  26388. 0x43, 0xa0, 0xce, 0x6c, 0x5e, 0x17, 0x8a, 0x53,
  26389. 0x4d, 0xaf, 0xd2, 0x95, 0x78, 0x9f, 0x84, 0x4f,
  26390. 0x94, 0xb8, 0x75, 0xa3, 0x19, 0xa5, 0xd4, 0xdf,
  26391. 0xe1, 0xd4, 0x5e, 0x9d, 0x97, 0xfe, 0x81
  26392. };
  26393. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26394. if ((key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  26395. return MEMORY_E;
  26396. #endif
  26397. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26398. if (ret != 0)
  26399. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26400. key_inited = 1;
  26401. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26402. if (ret != 0)
  26403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26404. #if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \
  26405. && (HAVE_FIPS_VERSION > 2)))
  26406. wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN);
  26407. #endif
  26408. ret = wc_ecc_sign_set_k(k, sizeof(k), key);
  26409. if (ret != 0)
  26410. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26411. sigSz = sizeof(sig);
  26412. do {
  26413. #if defined(WOLFSSL_ASYNC_CRYPT)
  26414. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26415. #endif
  26416. if (ret == 0)
  26417. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26418. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26419. if (ret != 0)
  26420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26421. TEST_SLEEP();
  26422. if (sigSz != sizeof(expSig)) {
  26423. ret = WC_TEST_RET_ENC_NC;
  26424. goto done;
  26425. }
  26426. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26427. ret = WC_TEST_RET_ENC_NC;
  26428. goto done;
  26429. }
  26430. sigSz = sizeof(sig);
  26431. do {
  26432. #if defined(WOLFSSL_ASYNC_CRYPT)
  26433. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26434. #endif
  26435. if (ret == 0)
  26436. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26437. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26438. if (ret != 0)
  26439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26440. TEST_SLEEP();
  26441. done:
  26442. if (key_inited)
  26443. wc_ecc_free(key);
  26444. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26445. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26446. #endif
  26447. return ret;
  26448. }
  26449. #endif
  26450. #if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE)
  26451. static wc_test_ret_t ecc_test_cdh_vectors(WC_RNG* rng)
  26452. {
  26453. wc_test_ret_t ret;
  26454. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26455. ecc_key *pub_key = (ecc_key *)XMALLOC(sizeof *pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26456. ecc_key *priv_key = (ecc_key *)XMALLOC(sizeof *priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26457. #else
  26458. ecc_key pub_key[1], priv_key[1];
  26459. #endif
  26460. byte sharedA[32] = {0}, sharedB[32] = {0};
  26461. word32 x, z;
  26462. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
  26463. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
  26464. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26465. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26466. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26467. WOLFSSL_SMALL_STACK_STATIC const char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b";
  26468. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26469. if ((pub_key == NULL) ||
  26470. (priv_key == NULL)) {
  26471. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26472. goto done;
  26473. }
  26474. #endif
  26475. XMEMSET(pub_key, 0, sizeof *pub_key);
  26476. XMEMSET(priv_key, 0, sizeof *priv_key);
  26477. /* setup private and public keys */
  26478. ret = wc_ecc_init_ex(pub_key, HEAP_HINT, devId);
  26479. if (ret != 0)
  26480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26481. ret = wc_ecc_init_ex(priv_key, HEAP_HINT, devId);
  26482. if (ret != 0)
  26483. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26484. wc_ecc_set_flags(pub_key, WC_ECC_FLAG_COFACTOR);
  26485. wc_ecc_set_flags(priv_key, WC_ECC_FLAG_COFACTOR);
  26486. ret = wc_ecc_import_raw(pub_key, QCAVSx, QCAVSy, NULL, "SECP256R1");
  26487. if (ret != 0)
  26488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26489. ret = wc_ecc_import_raw(priv_key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26490. if (ret != 0)
  26491. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26492. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26493. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26494. !defined(HAVE_SELFTEST)
  26495. ret = wc_ecc_set_rng(priv_key, rng);
  26496. if (ret != 0)
  26497. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26498. #else
  26499. (void)rng;
  26500. #endif
  26501. /* compute ECC Cofactor shared secret */
  26502. x = sizeof(sharedA);
  26503. do {
  26504. #if defined(WOLFSSL_ASYNC_CRYPT)
  26505. ret = wc_AsyncWait(ret, &priv_key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26506. #endif
  26507. if (ret == 0)
  26508. ret = wc_ecc_shared_secret(priv_key, pub_key, sharedA, &x);
  26509. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26510. if (ret != 0)
  26511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26512. TEST_SLEEP();
  26513. /* read in expected Z */
  26514. z = sizeof(sharedB);
  26515. ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
  26516. if (ret != 0)
  26517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26518. /* compare results */
  26519. if (x != z || XMEMCMP(sharedA, sharedB, x)) {
  26520. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26521. }
  26522. done:
  26523. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26524. if (priv_key) {
  26525. wc_ecc_free(priv_key);
  26526. XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26527. }
  26528. if (pub_key) {
  26529. wc_ecc_free(pub_key);
  26530. XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26531. }
  26532. #else
  26533. wc_ecc_free(priv_key);
  26534. wc_ecc_free(pub_key);
  26535. #endif
  26536. return ret;
  26537. }
  26538. #endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */
  26539. #endif /* HAVE_ECC_VECTOR_TEST */
  26540. #ifdef HAVE_ECC_KEY_IMPORT
  26541. /* returns 0 on success */
  26542. static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
  26543. {
  26544. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26545. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26546. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26547. ecc_key *pub = (ecc_key *)XMALLOC(sizeof *pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26548. #endif
  26549. byte *exportBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26550. byte *tmp = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26551. #else
  26552. ecc_key key[1];
  26553. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  26554. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26555. ecc_key pub[1];
  26556. #endif
  26557. byte exportBuf[ECC_BUFSIZE];
  26558. byte tmp[ECC_BUFSIZE];
  26559. #endif
  26560. const byte* msg = (const byte*)"test wolfSSL ECC public gen";
  26561. word32 x;
  26562. word32 tmpSz;
  26563. wc_test_ret_t ret = 0;
  26564. ecc_point* pubPoint = NULL;
  26565. #ifdef HAVE_ECC_VERIFY
  26566. int verify = 0;
  26567. #endif
  26568. #ifdef NO_ASN
  26569. /* private d for eccKeyDerFile / ecc_key_der_256 */
  26570. const byte keyPriv[] = {
  26571. 0x45, 0xB6, 0x69, 0x02, 0x73, 0x9C, 0x6C, 0x85,
  26572. 0xA1, 0x38, 0x5B, 0x72, 0xE8, 0xE8, 0xC7, 0xAC,
  26573. 0xC4, 0x03, 0x8D, 0x53, 0x35, 0x04, 0xFA, 0x6C,
  26574. 0x28, 0xDC, 0x34, 0x8D, 0xE1, 0xA8, 0x09, 0x8C
  26575. };
  26576. #endif
  26577. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26578. if ((key == NULL) ||
  26579. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26580. (pub == NULL) ||
  26581. #endif
  26582. (exportBuf == NULL) ||
  26583. (tmp == NULL))
  26584. ERROR_OUT(MEMORY_E, done);
  26585. #endif
  26586. (void)msg;
  26587. (void)verify;
  26588. (void)exportBuf;
  26589. (void)rng;
  26590. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26591. #ifndef NO_ECC256
  26592. #if defined(USE_CERT_BUFFERS_256)
  26593. {
  26594. XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
  26595. tmpSz = (size_t)sizeof_ecc_key_der_256;
  26596. }
  26597. #elif !defined(NO_FILESYSTEM)
  26598. {
  26599. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  26600. if (!file) {
  26601. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26602. }
  26603. tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file);
  26604. XFCLOSE(file);
  26605. if (tmpSz == 0)
  26606. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26607. }
  26608. #else
  26609. {
  26610. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
  26611. ERROR_OUT(ASN_PARSE_E, done);
  26612. }
  26613. #endif /* USE_CERT_BUFFERS_256 */
  26614. /* import private only then test with */
  26615. ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL);
  26616. if (ret == 0) {
  26617. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26618. }
  26619. ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key);
  26620. if (ret == 0) {
  26621. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26622. }
  26623. #ifndef NO_ASN
  26624. x = 0;
  26625. ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz);
  26626. if (ret != 0)
  26627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26628. #ifdef HAVE_ECC_KEY_EXPORT
  26629. x = ECC_BUFSIZE;
  26630. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26631. if (ret != 0)
  26632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26633. /* make private only key */
  26634. wc_ecc_free(key);
  26635. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26636. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26637. if (ret != 0)
  26638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26639. x = ECC_BUFSIZE;
  26640. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26641. if (ret == 0) {
  26642. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26643. }
  26644. #endif /* HAVE_ECC_KEY_EXPORT */
  26645. #else
  26646. /* Load raw private d directly */
  26647. ret = wc_ecc_import_private_key(keyPriv, sizeof(keyPriv), NULL, 0, key);
  26648. #endif /* !NO_ASN */
  26649. ret = wc_ecc_make_pub(NULL, NULL);
  26650. if (ret == 0) {
  26651. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26652. }
  26653. TEST_SLEEP();
  26654. #ifndef WOLFSSL_NO_MALLOC
  26655. pubPoint = wc_ecc_new_point_h(HEAP_HINT);
  26656. if (pubPoint == NULL) {
  26657. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26658. }
  26659. #if !defined(WOLFSSL_CRYPTOCELL)
  26660. ret = wc_ecc_make_pub(key, pubPoint);
  26661. #if defined(WOLFSSL_ASYNC_CRYPT)
  26662. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26663. #endif
  26664. if (ret != 0)
  26665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26666. #endif /* !WOLFSSL_CRYPTOCELL */
  26667. TEST_SLEEP();
  26668. #ifdef HAVE_ECC_KEY_EXPORT
  26669. /* export should still fail, is private only key */
  26670. x = ECC_BUFSIZE;
  26671. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26672. if (ret == 0) {
  26673. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26674. }
  26675. #endif /* HAVE_ECC_KEY_EXPORT */
  26676. #endif /* !WOLFSSL_NO_MALLOC */
  26677. #endif /* !NO_ECC256 */
  26678. /* create a new key since above test for loading key is not supported */
  26679. #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \
  26680. defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \
  26681. defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM)
  26682. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  26683. if (ret != 0)
  26684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26685. #endif
  26686. #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \
  26687. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG))) && \
  26688. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(HAVE_ECC_DETERMINISTIC_K)
  26689. tmpSz = ECC_BUFSIZE;
  26690. ret = 0;
  26691. do {
  26692. #if defined(WOLFSSL_ASYNC_CRYPT)
  26693. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26694. #endif
  26695. if (ret == 0) {
  26696. ret = wc_ecc_sign_hash(msg, (word32)XSTRLEN((const char* )msg), tmp,
  26697. &tmpSz, rng, key);
  26698. }
  26699. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26700. if (ret != 0)
  26701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26702. TEST_SLEEP();
  26703. #ifdef HAVE_ECC_VERIFY
  26704. /* try verify with private only key */
  26705. ret = 0;
  26706. do {
  26707. #if defined(WOLFSSL_ASYNC_CRYPT)
  26708. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26709. #endif
  26710. if (ret == 0) {
  26711. ret = wc_ecc_verify_hash(tmp, tmpSz, msg,
  26712. (word32)XSTRLEN((const char*)msg), &verify, key);
  26713. }
  26714. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26715. if (ret != 0)
  26716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26717. if (verify != 1) {
  26718. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26719. }
  26720. TEST_SLEEP();
  26721. #ifdef HAVE_ECC_KEY_EXPORT
  26722. /* exporting the public part should now work */
  26723. x = ECC_BUFSIZE;
  26724. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26725. if (ret != 0)
  26726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26727. #endif /* HAVE_ECC_KEY_EXPORT */
  26728. #endif /* HAVE_ECC_VERIFY */
  26729. #endif /* HAVE_ECC_SIGN */
  26730. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  26731. /* now test private only key with creating a shared secret */
  26732. x = ECC_BUFSIZE;
  26733. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26734. if (ret != 0)
  26735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26736. #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050)
  26737. /* make private only key */
  26738. wc_ecc_free(key);
  26739. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26740. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26741. if (ret != 0)
  26742. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26743. /* check that public export fails with private only key */
  26744. x = ECC_BUFSIZE;
  26745. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26746. if (ret == 0) {
  26747. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26748. }
  26749. #endif /* WOLFSSL_QNX_CAAM */
  26750. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  26751. /* make public key for shared secret */
  26752. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  26753. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, pub);
  26754. #ifdef HAVE_ECC_CDH
  26755. wc_ecc_set_flags(key, WC_ECC_FLAG_COFACTOR);
  26756. #endif
  26757. #if defined(WOLFSSL_ASYNC_CRYPT)
  26758. ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE);
  26759. #endif
  26760. if (ret != 0)
  26761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26762. TEST_SLEEP();
  26763. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26764. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26765. !defined(HAVE_SELFTEST)
  26766. ret = wc_ecc_set_rng(key, rng);
  26767. if (ret != 0)
  26768. goto done;
  26769. #endif
  26770. x = ECC_BUFSIZE;
  26771. do {
  26772. #if defined(WOLFSSL_ASYNC_CRYPT)
  26773. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26774. #endif
  26775. if (ret == 0) {
  26776. ret = wc_ecc_shared_secret(key, pub, exportBuf, &x);
  26777. }
  26778. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26779. wc_ecc_free(pub);
  26780. if (ret != 0)
  26781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26782. TEST_SLEEP();
  26783. #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */
  26784. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26785. ret = 0;
  26786. done:
  26787. wc_ecc_del_point_h(pubPoint, HEAP_HINT);
  26788. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26789. if (key != NULL) {
  26790. wc_ecc_free(key);
  26791. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26792. }
  26793. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26794. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26795. #endif
  26796. XFREE(exportBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26797. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26798. #else
  26799. wc_ecc_free(key);
  26800. #endif
  26801. return ret;
  26802. }
  26803. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26804. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26805. static wc_test_ret_t ecc_test_key_decode(WC_RNG* rng, int keySize)
  26806. {
  26807. wc_test_ret_t ret;
  26808. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26809. ecc_key *eccKey = (ecc_key *)XMALLOC(sizeof *eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26810. byte *tmpBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26811. #else
  26812. ecc_key eccKey[1];
  26813. byte tmpBuf[ECC_BUFSIZE];
  26814. #endif
  26815. word32 tmpSz;
  26816. word32 idx;
  26817. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26818. if ((eccKey == NULL) || (tmpBuf == NULL))
  26819. ERROR_OUT(MEMORY_E, done);
  26820. #endif
  26821. ret = wc_ecc_init(eccKey);
  26822. if (ret != 0) {
  26823. goto done;
  26824. }
  26825. ret = wc_ecc_make_key(rng, keySize, eccKey);
  26826. #if defined(WOLFSSL_ASYNC_CRYPT)
  26827. ret = wc_AsyncWait(ret, &eccKey->asyncDev, WC_ASYNC_FLAG_NONE);
  26828. #endif
  26829. if (ret != 0) {
  26830. goto done;
  26831. }
  26832. tmpSz = ECC_BUFSIZE;
  26833. ret = wc_EccKeyToDer(eccKey, tmpBuf, tmpSz);
  26834. wc_ecc_free(eccKey);
  26835. if (ret < 0) {
  26836. goto done;
  26837. }
  26838. tmpSz = (word32)ret;
  26839. ret = wc_ecc_init(eccKey);
  26840. if (ret != 0) {
  26841. goto done;
  26842. }
  26843. idx = 0;
  26844. ret = wc_EccPrivateKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26845. if (ret != 0) {
  26846. goto done;
  26847. }
  26848. wc_ecc_free(eccKey);
  26849. ret = wc_ecc_init(eccKey);
  26850. if (ret != 0) {
  26851. goto done;
  26852. }
  26853. idx = 0;
  26854. ret = wc_EccPublicKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26855. if (ret != 0) {
  26856. goto done;
  26857. }
  26858. ret = 0;
  26859. done:
  26860. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26861. if (eccKey != NULL) {
  26862. wc_ecc_free(eccKey);
  26863. XFREE(eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26864. }
  26865. XFREE(tmpBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26866. #else
  26867. wc_ecc_free(eccKey);
  26868. #endif
  26869. return ret;
  26870. }
  26871. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26872. #endif /* HAVE_ECC_KEY_IMPORT */
  26873. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26874. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26875. static wc_test_ret_t ecc_test_key_gen(WC_RNG* rng, int keySize)
  26876. {
  26877. wc_test_ret_t ret = 0;
  26878. int derSz;
  26879. #ifdef HAVE_PKCS8
  26880. word32 pkcs8Sz;
  26881. #endif
  26882. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26883. byte *der = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26884. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26885. #else
  26886. byte der[ECC_BUFSIZE];
  26887. ecc_key userA[1];
  26888. #endif
  26889. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26890. if ((der == NULL) || (userA == NULL))
  26891. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26892. #endif
  26893. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  26894. if (ret != 0)
  26895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26896. ret = wc_ecc_make_key(rng, keySize, userA);
  26897. #if defined(WOLFSSL_ASYNC_CRYPT)
  26898. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  26899. #endif
  26900. if (ret != 0)
  26901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26902. TEST_SLEEP();
  26903. ret = wc_ecc_check_key(userA);
  26904. if (ret != 0)
  26905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26906. TEST_SLEEP();
  26907. derSz = wc_EccKeyToDer(userA, der, ECC_BUFSIZE);
  26908. if (derSz < 0) {
  26909. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26910. }
  26911. ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile,
  26912. ECC_PRIVATEKEY_TYPE);
  26913. if (ret != 0)
  26914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26915. /* test export of public key */
  26916. derSz = wc_EccPublicKeyToDer(userA, der, ECC_BUFSIZE, 1);
  26917. if (derSz < 0) {
  26918. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26919. }
  26920. if (derSz == 0) {
  26921. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26922. }
  26923. #ifdef HAVE_COMP_KEY
  26924. /* test export of compressed public key */
  26925. derSz = wc_EccPublicKeyToDer_ex(userA, der, ECC_BUFSIZE, 1, 1);
  26926. if (derSz < 0) {
  26927. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26928. }
  26929. if (derSz == 0) {
  26930. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26931. }
  26932. #endif
  26933. ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0);
  26934. if (ret != 0)
  26935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26936. #ifdef HAVE_PKCS8
  26937. /* test export of PKCS#8 unencrypted private key */
  26938. pkcs8Sz = FOURK_BUF;
  26939. derSz = wc_EccPrivateKeyToPKCS8(userA, der, &pkcs8Sz);
  26940. if (derSz < 0) {
  26941. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26942. }
  26943. if (derSz == 0) {
  26944. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26945. }
  26946. ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0);
  26947. if (ret != 0) {
  26948. goto done;
  26949. }
  26950. #endif /* HAVE_PKCS8 */
  26951. done:
  26952. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26953. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26954. if (userA != NULL) {
  26955. wc_ecc_free(userA);
  26956. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26957. }
  26958. #else
  26959. wc_ecc_free(userA);
  26960. #endif
  26961. return ret;
  26962. }
  26963. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26964. static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
  26965. int curve_id, const ecc_set_type* dp)
  26966. {
  26967. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  26968. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  26969. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  26970. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  26971. word32 y;
  26972. #endif
  26973. #ifdef HAVE_ECC_KEY_EXPORT
  26974. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  26975. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  26976. #endif
  26977. word32 x = 0;
  26978. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  26979. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  26980. defined(HAVE_ECC_SIGN)
  26981. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  26982. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  26983. int i;
  26984. #ifdef HAVE_ECC_VERIFY
  26985. int verify;
  26986. #endif /* HAVE_ECC_VERIFY */
  26987. #endif /* HAVE_ECC_SIGN */
  26988. wc_test_ret_t ret;
  26989. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26990. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26991. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26992. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26993. #else
  26994. ecc_key userA[1];
  26995. ecc_key userB[1];
  26996. ecc_key pubKey[1];
  26997. #endif
  26998. #ifndef WC_NO_RNG
  26999. int curveSize;
  27000. #endif
  27001. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27002. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27003. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27004. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27005. #endif
  27006. #ifdef HAVE_ECC_KEY_EXPORT
  27007. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27008. #endif
  27009. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27010. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27011. defined(HAVE_ECC_SIGN)
  27012. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27013. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27014. #endif
  27015. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  27016. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \
  27017. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27018. if (sharedA == NULL || sharedB == NULL)
  27019. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27020. #endif
  27021. #ifdef HAVE_ECC_KEY_EXPORT
  27022. if (exportBuf == NULL)
  27023. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27024. #endif
  27025. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27026. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27027. defined(HAVE_ECC_SIGN)
  27028. if (sig == NULL || digest == NULL)
  27029. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27030. #endif
  27031. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  27032. (void)testVerifyCount;
  27033. (void)dp;
  27034. (void)x;
  27035. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27036. if ((userA == NULL) ||
  27037. (userB == NULL) ||
  27038. (pubKey == NULL))
  27039. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27040. #endif
  27041. XMEMSET(userA, 0, sizeof *userA);
  27042. XMEMSET(userB, 0, sizeof *userB);
  27043. XMEMSET(pubKey, 0, sizeof *pubKey);
  27044. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27045. if (ret != 0)
  27046. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27047. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  27048. if (ret != 0)
  27049. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27050. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27051. if (ret != 0)
  27052. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27053. #ifdef WOLFSSL_CUSTOM_CURVES
  27054. if (dp != NULL) {
  27055. ret = wc_ecc_set_custom_curve(userA, dp);
  27056. if (ret != 0)
  27057. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27058. ret = wc_ecc_set_custom_curve(userB, dp);
  27059. if (ret != 0)
  27060. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27061. }
  27062. #endif
  27063. #ifndef WC_NO_RNG
  27064. ret = wc_ecc_make_key_ex(rng, keySize, userA, curve_id);
  27065. #if defined(WOLFSSL_ASYNC_CRYPT)
  27066. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27067. #endif
  27068. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  27069. if (ret == WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  27070. ret = 0;
  27071. goto done; /* no software case */
  27072. }
  27073. #endif
  27074. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  27075. goto done; /* catch case, where curve is not supported */
  27076. if (ret != 0)
  27077. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27078. TEST_SLEEP();
  27079. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  27080. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  27081. if (curveSize != userA->dp->size)
  27082. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27083. }
  27084. ret = wc_ecc_check_key(userA);
  27085. if (ret != 0)
  27086. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27087. TEST_SLEEP();
  27088. /* ATECC508/608 configuration may not support more than one ECDH key */
  27089. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27090. ret = wc_ecc_make_key_ex(rng, keySize, userB, curve_id);
  27091. #if defined(WOLFSSL_ASYNC_CRYPT)
  27092. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  27093. #endif
  27094. if (ret != 0)
  27095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27096. TEST_SLEEP();
  27097. /* only perform the below tests if the key size matches */
  27098. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  27099. /* Not an error, just not a key size match */
  27100. WARNING_OUT(ECC_CURVE_OID_E, done);
  27101. #ifdef HAVE_ECC_DHE
  27102. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27103. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27104. !defined(HAVE_SELFTEST)
  27105. ret = wc_ecc_set_rng(userA, rng);
  27106. if (ret != 0)
  27107. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27108. ret = wc_ecc_set_rng(userB, rng);
  27109. if (ret != 0)
  27110. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27111. #endif
  27112. x = ECC_SHARED_SIZE;
  27113. do {
  27114. #if defined(WOLFSSL_ASYNC_CRYPT)
  27115. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27116. #endif
  27117. if (ret == 0)
  27118. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27119. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27120. if (ret != 0)
  27121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27122. TEST_SLEEP();
  27123. y = ECC_SHARED_SIZE;
  27124. do {
  27125. #if defined(WOLFSSL_ASYNC_CRYPT)
  27126. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27127. #endif
  27128. if (ret == 0)
  27129. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27130. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27131. if (ret != 0)
  27132. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27133. if (y != x)
  27134. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27135. if (XMEMCMP(sharedA, sharedB, x))
  27136. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27137. TEST_SLEEP();
  27138. #ifdef HAVE_ECC_CDH
  27139. /* add cofactor flag */
  27140. wc_ecc_set_flags(userA, WC_ECC_FLAG_COFACTOR);
  27141. wc_ecc_set_flags(userB, WC_ECC_FLAG_COFACTOR);
  27142. x = ECC_SHARED_SIZE;
  27143. do {
  27144. #if defined(WOLFSSL_ASYNC_CRYPT)
  27145. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27146. #endif
  27147. if (ret == 0)
  27148. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27149. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27150. if (ret != 0)
  27151. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27152. TEST_SLEEP();
  27153. y = ECC_SHARED_SIZE;
  27154. do {
  27155. #if defined(WOLFSSL_ASYNC_CRYPT)
  27156. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27157. #endif
  27158. if (ret == 0)
  27159. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27160. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27161. if (ret != 0)
  27162. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27163. if (y != x)
  27164. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27165. if (XMEMCMP(sharedA, sharedB, x))
  27166. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27167. TEST_SLEEP();
  27168. /* remove cofactor flag */
  27169. wc_ecc_set_flags(userA, 0);
  27170. wc_ecc_set_flags(userB, 0);
  27171. #endif /* HAVE_ECC_CDH */
  27172. #endif /* HAVE_ECC_DHE */
  27173. #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
  27174. #ifdef HAVE_ECC_KEY_EXPORT
  27175. x = ECC_KEY_EXPORT_BUF_SIZE;
  27176. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  27177. if (ret != 0)
  27178. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27179. #ifdef HAVE_ECC_KEY_IMPORT
  27180. #ifdef WOLFSSL_CUSTOM_CURVES
  27181. if (dp != NULL) {
  27182. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27183. if (ret != 0)
  27184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27185. }
  27186. #endif
  27187. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27188. if (ret != 0)
  27189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27190. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27191. #ifdef HAVE_ECC_DHE
  27192. y = ECC_SHARED_SIZE;
  27193. do {
  27194. #if defined(WOLFSSL_ASYNC_CRYPT)
  27195. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27196. #endif
  27197. if (ret == 0)
  27198. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27199. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27200. if (ret != 0)
  27201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27202. if (XMEMCMP(sharedA, sharedB, y))
  27203. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27204. TEST_SLEEP();
  27205. #endif /* HAVE_ECC_DHE */
  27206. #ifdef HAVE_COMP_KEY
  27207. /* try compressed export / import too */
  27208. x = ECC_KEY_EXPORT_BUF_SIZE;
  27209. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  27210. if (ret != 0)
  27211. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27212. wc_ecc_free(pubKey);
  27213. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27214. if (ret != 0)
  27215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27216. #ifdef WOLFSSL_CUSTOM_CURVES
  27217. if (dp != NULL) {
  27218. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27219. if (ret != 0)
  27220. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27221. }
  27222. #endif
  27223. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27224. if (ret != 0)
  27225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27226. #ifdef HAVE_ECC_DHE
  27227. y = ECC_SHARED_SIZE;
  27228. do {
  27229. #if defined(WOLFSSL_ASYNC_CRYPT)
  27230. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27231. #endif
  27232. if (ret == 0)
  27233. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27234. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27235. if (ret != 0)
  27236. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27237. if (XMEMCMP(sharedA, sharedB, y))
  27238. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27239. TEST_SLEEP();
  27240. #endif /* HAVE_ECC_DHE */
  27241. #endif /* HAVE_COMP_KEY */
  27242. #endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A */
  27243. #endif /* !WC_NO_RNG */
  27244. #endif /* HAVE_ECC_KEY_IMPORT */
  27245. #endif /* HAVE_ECC_KEY_EXPORT */
  27246. /* For KCAPI cannot sign using generated ECDH key */
  27247. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27248. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
  27249. #ifdef HAVE_ECC_SIGN
  27250. /* ECC w/out Shamir has issue with all 0 digest */
  27251. /* WC_BIGINT doesn't have 0 len well on hardware */
  27252. /* Cryptocell has issues with all 0 digest */
  27253. #if defined(ECC_SHAMIR) && !defined(WOLFSSL_ASYNC_CRYPT) && \
  27254. !defined(WOLFSSL_CRYPTOCELL)
  27255. /* test DSA sign hash with zeros */
  27256. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27257. digest[i] = 0;
  27258. }
  27259. x = ECC_SIG_SIZE;
  27260. do {
  27261. #if defined(WOLFSSL_ASYNC_CRYPT)
  27262. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27263. #endif
  27264. if (ret == 0)
  27265. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
  27266. userA);
  27267. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27268. if (ret != 0)
  27269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27270. TEST_SLEEP();
  27271. #ifdef HAVE_ECC_VERIFY
  27272. for (i=0; i<testVerifyCount; i++) {
  27273. verify = 0;
  27274. do {
  27275. #if defined(WOLFSSL_ASYNC_CRYPT)
  27276. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27277. #endif
  27278. if (ret == 0)
  27279. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
  27280. &verify, userA);
  27281. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27282. if (ret != 0)
  27283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27284. if (verify != 1)
  27285. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27286. TEST_SLEEP();
  27287. }
  27288. #endif /* HAVE_ECC_VERIFY */
  27289. #endif /* ECC_SHAMIR && !WOLFSSL_ASYNC_CRYPT && !WOLFSSL_CRYPTOCELL */
  27290. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  27291. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27292. digest[i] = (byte)i;
  27293. }
  27294. x = ECC_SIG_SIZE;
  27295. do {
  27296. #if defined(WOLFSSL_ASYNC_CRYPT)
  27297. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27298. #endif
  27299. if (ret == 0)
  27300. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  27301. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27302. if (ret != 0)
  27303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27304. TEST_SLEEP();
  27305. #ifdef HAVE_ECC_VERIFY
  27306. for (i=0; i<testVerifyCount; i++) {
  27307. verify = 0;
  27308. do {
  27309. #if defined(WOLFSSL_ASYNC_CRYPT)
  27310. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27311. #endif
  27312. if (ret == 0)
  27313. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA);
  27314. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27315. if (ret != 0)
  27316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27317. if (verify != 1)
  27318. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27319. TEST_SLEEP();
  27320. }
  27321. #endif /* HAVE_ECC_VERIFY */
  27322. #endif /* HAVE_ECC_SIGN */
  27323. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT &&
  27324. * !WC_NO_RNG && !WOLFSSL_KCAPI_ECC) */
  27325. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  27326. !defined(WOLFSSL_ATECC508) && !defined(WOLFSSL_ATECC608A) && \
  27327. !defined(WOLFSSL_KCAPI_ECC)
  27328. x = ECC_KEY_EXPORT_BUF_SIZE;
  27329. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  27330. if (ret != 0)
  27331. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27332. #elif defined(HAVE_ECC_KEY_EXPORT)
  27333. (void)exportBuf;
  27334. #endif /* HAVE_ECC_KEY_EXPORT */
  27335. done:
  27336. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27337. if (userA != NULL) {
  27338. wc_ecc_free(userA);
  27339. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27340. }
  27341. if (userB != NULL) {
  27342. wc_ecc_free(userB);
  27343. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27344. }
  27345. if (pubKey != NULL) {
  27346. wc_ecc_free(pubKey);
  27347. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27348. }
  27349. #else
  27350. wc_ecc_free(pubKey);
  27351. wc_ecc_free(userB);
  27352. wc_ecc_free(userA);
  27353. #endif
  27354. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  27355. WC_FREE_VAR(sharedA, HEAP_HINT);
  27356. WC_FREE_VAR(sharedB, HEAP_HINT);
  27357. #endif
  27358. #ifdef HAVE_ECC_KEY_EXPORT
  27359. WC_FREE_VAR(exportBuf, HEAP_HINT);
  27360. #endif
  27361. #ifdef HAVE_ECC_SIGN
  27362. WC_FREE_VAR(sig, HEAP_HINT);
  27363. WC_FREE_VAR(digest, HEAP_HINT);
  27364. #endif
  27365. (void)keySize;
  27366. (void)curve_id;
  27367. (void)rng;
  27368. return ret;
  27369. }
  27370. #undef ECC_TEST_VERIFY_COUNT
  27371. #define ECC_TEST_VERIFY_COUNT 2
  27372. static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
  27373. {
  27374. wc_test_ret_t ret;
  27375. WOLFSSL_MSG_EX("ecc_test_curve keySize = %d", keySize);
  27376. #if FIPS_VERSION3_GE(6,0,0)
  27377. #ifdef DEBUG_WOLFSSL
  27378. printf("keySize is %d\n", keySize);
  27379. #endif
  27380. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27381. goto skip_A;
  27382. }
  27383. #endif
  27384. ret = ecc_test_curve_size(rng, keySize, ECC_TEST_VERIFY_COUNT, curve_id,
  27385. NULL);
  27386. if (ret < 0) {
  27387. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27388. /* ignore error for curves not found */
  27389. /* some curve sizes are only available with:
  27390. HAVE_ECC_SECPR2, HAVE_ECC_SECPR3, HAVE_ECC_BRAINPOOL
  27391. and HAVE_ECC_KOBLITZ */
  27392. }
  27393. else {
  27394. printf("ecc_test_curve_size %d failed!\n", keySize);
  27395. return ret;
  27396. }
  27397. }
  27398. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27399. #if FIPS_VERSION3_GE(6,0,0)
  27400. skip_A:
  27401. #endif
  27402. #ifdef HAVE_ECC_VECTOR_TEST
  27403. ret = ecc_test_vector(keySize);
  27404. if (ret < 0) {
  27405. printf("ecc_test_vector %d failed!\n", keySize);
  27406. return ret;
  27407. }
  27408. #endif
  27409. #if FIPS_VERSION3_GE(6,0,0)
  27410. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27411. goto skip_B;
  27412. }
  27413. #endif
  27414. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27415. !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27416. ret = ecc_test_key_decode(rng, keySize);
  27417. if (ret < 0) {
  27418. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27419. /* ignore error for curves not found */
  27420. }
  27421. else {
  27422. printf("ecc_test_key_decode %d failed!\n", keySize);
  27423. return ret;
  27424. }
  27425. }
  27426. #endif
  27427. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27428. ret = ecc_test_key_gen(rng, keySize);
  27429. if (ret < 0) {
  27430. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27431. /* ignore error for curves not found */
  27432. }
  27433. else {
  27434. printf("ecc_test_key_gen %d failed!\n", keySize);
  27435. return ret;
  27436. }
  27437. }
  27438. #endif
  27439. #if FIPS_VERSION3_GE(6,0,0)
  27440. skip_B:
  27441. #endif
  27442. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  27443. return 0;
  27444. }
  27445. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  27446. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  27447. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27448. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27449. static wc_test_ret_t ecc_point_test(void)
  27450. {
  27451. wc_test_ret_t ret;
  27452. ecc_point* point;
  27453. ecc_point* point2;
  27454. #ifdef HAVE_COMP_KEY
  27455. ecc_point* point3;
  27456. ecc_point* point4;
  27457. #endif
  27458. word32 outLen;
  27459. byte out[65];
  27460. byte der[] = { 0x04, /* = Uncompressed */
  27461. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27462. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27463. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27464. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27465. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27466. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27467. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27468. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27469. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27470. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27471. byte derComp0[] = { 0x02, /* = Compressed, y even */
  27472. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27473. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27474. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27475. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27476. byte derComp1[] = { 0x03, /* = Compressed, y odd */
  27477. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27478. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27479. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27480. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27481. #endif
  27482. byte altDer[] = { 0x04, /* = Uncompressed */
  27483. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27484. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27485. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27486. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27487. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27488. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27489. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27490. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  27491. int curve_idx = wc_ecc_get_curve_idx(ECC_SECP256R1);
  27492. /* if curve P256 is not enabled then test should not fail */
  27493. if (curve_idx == ECC_CURVE_INVALID)
  27494. return 0;
  27495. outLen = sizeof(out);
  27496. point = wc_ecc_new_point();
  27497. if (point == NULL)
  27498. return WC_TEST_RET_ENC_ERRNO;
  27499. point2 = wc_ecc_new_point();
  27500. if (point2 == NULL) {
  27501. wc_ecc_del_point(point);
  27502. return WC_TEST_RET_ENC_NC;
  27503. }
  27504. #ifdef HAVE_COMP_KEY
  27505. point3 = wc_ecc_new_point();
  27506. if (point3 == NULL) {
  27507. wc_ecc_del_point(point2);
  27508. wc_ecc_del_point(point);
  27509. return WC_TEST_RET_ENC_NC;
  27510. }
  27511. point4 = wc_ecc_new_point();
  27512. if (point4 == NULL) {
  27513. wc_ecc_del_point(point3);
  27514. wc_ecc_del_point(point2);
  27515. wc_ecc_del_point(point);
  27516. return WC_TEST_RET_ENC_NC;
  27517. }
  27518. #endif
  27519. /* Parameter Validation testing. */
  27520. wc_ecc_del_point(NULL);
  27521. ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, point);
  27522. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27523. ret = WC_TEST_RET_ENC_EC(ret);
  27524. goto done;
  27525. }
  27526. ret = wc_ecc_import_point_der(der, sizeof(der), ECC_CURVE_INVALID, point);
  27527. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27528. ret = WC_TEST_RET_ENC_EC(ret);
  27529. goto done;
  27530. }
  27531. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, NULL);
  27532. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27533. ret = WC_TEST_RET_ENC_EC(ret);
  27534. goto done;
  27535. }
  27536. ret = wc_ecc_export_point_der(-1, point, out, &outLen);
  27537. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27538. ret = WC_TEST_RET_ENC_EC(ret);
  27539. goto done;
  27540. }
  27541. ret = wc_ecc_export_point_der(curve_idx, NULL, out, &outLen);
  27542. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27543. ret = WC_TEST_RET_ENC_EC(ret);
  27544. goto done;
  27545. }
  27546. ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen);
  27547. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || outLen != sizeof(out)) {
  27548. ret = WC_TEST_RET_ENC_EC(ret);
  27549. goto done;
  27550. }
  27551. ret = wc_ecc_export_point_der(curve_idx, point, out, NULL);
  27552. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27553. ret = WC_TEST_RET_ENC_EC(ret);
  27554. goto done;
  27555. }
  27556. outLen = 0;
  27557. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27558. if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
  27559. ret = WC_TEST_RET_ENC_EC(ret);
  27560. goto done;
  27561. }
  27562. ret = wc_ecc_copy_point(NULL, NULL);
  27563. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27564. ret = WC_TEST_RET_ENC_EC(ret);
  27565. goto done;
  27566. }
  27567. ret = wc_ecc_copy_point(NULL, point2);
  27568. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27569. ret = WC_TEST_RET_ENC_EC(ret);
  27570. goto done;
  27571. }
  27572. ret = wc_ecc_copy_point(point, NULL);
  27573. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27574. ret = WC_TEST_RET_ENC_EC(ret);
  27575. goto done;
  27576. }
  27577. ret = wc_ecc_cmp_point(NULL, NULL);
  27578. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27579. ret = WC_TEST_RET_ENC_EC(ret);
  27580. goto done;
  27581. }
  27582. ret = wc_ecc_cmp_point(NULL, point2);
  27583. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27584. ret = WC_TEST_RET_ENC_EC(ret);
  27585. goto done;
  27586. }
  27587. ret = wc_ecc_cmp_point(point, NULL);
  27588. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27589. ret = WC_TEST_RET_ENC_EC(ret);
  27590. goto done;
  27591. }
  27592. /* Use API. */
  27593. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point);
  27594. if (ret != 0)
  27595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27596. outLen = sizeof(out);
  27597. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27598. if (ret != 0)
  27599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27600. if (outLen != sizeof(der)) {
  27601. ret = WC_TEST_RET_ENC_NC;
  27602. goto done;
  27603. }
  27604. if (XMEMCMP(out, der, outLen) != 0) {
  27605. ret = WC_TEST_RET_ENC_NC;
  27606. goto done;
  27607. }
  27608. ret = wc_ecc_copy_point(point2, point);
  27609. if (ret != MP_OKAY) {
  27610. ret = WC_TEST_RET_ENC_EC(ret);
  27611. goto done;
  27612. }
  27613. ret = wc_ecc_cmp_point(point2, point);
  27614. if (ret != MP_EQ) {
  27615. ret = WC_TEST_RET_ENC_EC(ret);
  27616. goto done;
  27617. }
  27618. ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2);
  27619. if (ret != 0)
  27620. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27621. ret = wc_ecc_cmp_point(point2, point);
  27622. if (ret != MP_GT) {
  27623. ret = WC_TEST_RET_ENC_EC(ret);
  27624. goto done;
  27625. }
  27626. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27627. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27628. ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3);
  27629. if (ret != 0)
  27630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27631. ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0);
  27632. if (ret != 0)
  27633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27634. ret = wc_ecc_cmp_point(point3, point4);
  27635. if (ret != MP_EQ) {
  27636. ret = WC_TEST_RET_ENC_EC(ret);
  27637. goto done;
  27638. }
  27639. ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3);
  27640. if (ret != 0)
  27641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27642. ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0);
  27643. if (ret != 0)
  27644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27645. ret = wc_ecc_cmp_point(point3, point4);
  27646. if (ret != MP_EQ) {
  27647. ret = WC_TEST_RET_ENC_EC(ret);
  27648. goto done;
  27649. }
  27650. #endif
  27651. done:
  27652. #ifdef HAVE_COMP_KEY
  27653. wc_ecc_del_point(point4);
  27654. wc_ecc_del_point(point3);
  27655. #endif
  27656. wc_ecc_del_point(point2);
  27657. wc_ecc_del_point(point);
  27658. return ret;
  27659. }
  27660. #endif /* !WOLFSSL_ATECC508A && HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27661. #if !defined(NO_SIG_WRAPPER) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27662. static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key)
  27663. {
  27664. wc_test_ret_t ret;
  27665. word32 sigSz;
  27666. int size;
  27667. byte out[ECC_MAX_SIG_SIZE];
  27668. byte in[] = TEST_STRING;
  27669. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  27670. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  27671. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  27672. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  27673. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  27674. };
  27675. word32 inLen = (word32)XSTRLEN((char*)in);
  27676. size = wc_ecc_sig_size(key);
  27677. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key));
  27678. if (ret != size)
  27679. return WC_TEST_RET_ENC_NC;
  27680. sigSz = (word32)ret;
  27681. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27682. inLen, out, &sigSz, key, sizeof(*key), rng);
  27683. if (ret != 0)
  27684. return WC_TEST_RET_ENC_EC(ret);
  27685. TEST_SLEEP();
  27686. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27687. inLen, out, sigSz, key, sizeof(*key));
  27688. if (ret != 0)
  27689. return WC_TEST_RET_ENC_EC(ret);
  27690. TEST_SLEEP();
  27691. sigSz = (word32)sizeof(out);
  27692. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27693. hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng);
  27694. if (ret != 0)
  27695. return WC_TEST_RET_ENC_EC(ret);
  27696. TEST_SLEEP();
  27697. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27698. hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key));
  27699. if (ret != 0)
  27700. return WC_TEST_RET_ENC_EC(ret);
  27701. TEST_SLEEP();
  27702. return 0;
  27703. }
  27704. #endif
  27705. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27706. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27707. static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
  27708. {
  27709. wc_test_ret_t ret;
  27710. int curve_id;
  27711. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27712. ecc_key *keyImp = (ecc_key *)XMALLOC(sizeof *keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27713. #else
  27714. ecc_key keyImp[1];
  27715. #endif
  27716. byte priv[32];
  27717. word32 privLen;
  27718. byte pub[65*2];
  27719. word32 pubLen, pubLenX, pubLenY;
  27720. const char qx[] = "7a4e287890a1a47ad3457e52f2f76a83"
  27721. "ce46cbc947616d0cbaa82323818a793d";
  27722. const char qy[] = "eec4084f5b29ebf29c44cce3b3059610"
  27723. "922f8b30ea6e8811742ac7238fe87308";
  27724. const char d[] = "8c14b793cb19137e323a6d2e2a870bca"
  27725. "2e7a493ec1153b3a95feb8a4873f8d08";
  27726. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27727. if (keyImp == NULL)
  27728. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27729. #endif
  27730. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27731. privLen = sizeof(priv);
  27732. ret = wc_ecc_export_private_only(key, priv, &privLen);
  27733. if (ret != 0)
  27734. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27735. pubLen = sizeof(pub);
  27736. ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen);
  27737. if (ret != 0)
  27738. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27739. ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp);
  27740. if (ret != 0)
  27741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27742. wc_ecc_free(keyImp);
  27743. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27744. ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1);
  27745. if (ret != 0)
  27746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27747. wc_ecc_free(keyImp);
  27748. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27749. curve_id = wc_ecc_get_curve_id(key->idx);
  27750. if (curve_id < 0) {
  27751. ret = WC_TEST_RET_ENC_EC(curve_id);
  27752. goto done;
  27753. }
  27754. /* test import private only */
  27755. ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp,
  27756. curve_id);
  27757. if (ret != 0)
  27758. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27759. wc_ecc_free(keyImp);
  27760. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27761. /* test export public raw */
  27762. pubLenX = pubLenY = 32;
  27763. ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY);
  27764. if (ret != 0)
  27765. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27766. #ifndef HAVE_SELFTEST
  27767. /* test import of public */
  27768. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1);
  27769. if (ret != 0)
  27770. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27771. #endif
  27772. wc_ecc_free(keyImp);
  27773. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27774. /* test export private and public raw */
  27775. pubLenX = pubLenY = privLen = 32;
  27776. ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY,
  27777. priv, &privLen);
  27778. if (ret != 0)
  27779. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27780. #ifndef HAVE_SELFTEST
  27781. /* test import of private and public */
  27782. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1);
  27783. if (ret != 0)
  27784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27785. #endif
  27786. done:
  27787. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27788. if (keyImp != NULL) {
  27789. wc_ecc_free(keyImp);
  27790. XFREE(keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27791. }
  27792. #else
  27793. wc_ecc_free(keyImp);
  27794. #endif
  27795. return ret;
  27796. }
  27797. #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27798. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  27799. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27800. static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
  27801. {
  27802. wc_test_ret_t ret;
  27803. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27804. ecc_key *key2 = (ecc_key *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27805. ecc_key *key3 = (ecc_key *)XMALLOC(sizeof *key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27806. #else
  27807. ecc_key key2[1];
  27808. ecc_key key3[1];
  27809. #endif
  27810. #ifdef WOLFSSL_PUBLIC_MP
  27811. mp_int* priv;
  27812. #endif
  27813. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27814. if ((key2 == NULL) || (key3 == NULL))
  27815. ERROR_OUT(MEMORY_E, done);
  27816. #endif
  27817. wc_ecc_init_ex(key2, HEAP_HINT, devId);
  27818. wc_ecc_init_ex(key3, HEAP_HINT, devId);
  27819. /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */
  27820. /* Need base point (Gx,Gy) and parameter A - load them as the public and
  27821. * private key in key2.
  27822. */
  27823. ret = wc_ecc_import_raw_ex(key2, key1->dp->Gx, key1->dp->Gy, key1->dp->Af,
  27824. ECC_SECP256R1);
  27825. if (ret != 0)
  27826. goto done;
  27827. /* Need a point (Gx,Gy) and prime - load them as the public and private key
  27828. * in key3.
  27829. */
  27830. ret = wc_ecc_import_raw_ex(key3, key1->dp->Gx, key1->dp->Gy,
  27831. key1->dp->prime, ECC_SECP256R1);
  27832. if (ret != 0)
  27833. goto done;
  27834. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27835. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27836. 1);
  27837. if (ret != 0)
  27838. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27839. #ifdef WOLFSSL_PUBLIC_MP
  27840. priv = wc_ecc_key_get_priv(key1);
  27841. mp_zero(priv);
  27842. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27843. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27844. 1);
  27845. if (ret != 0)
  27846. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27847. if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
  27848. ret = WC_TEST_RET_ENC_EC(ret);
  27849. goto done;
  27850. }
  27851. if (mp_cmp_d(key3->pubkey.z, 1) != MP_EQ) {
  27852. ret = WC_TEST_RET_ENC_EC(ret);
  27853. goto done;
  27854. }
  27855. #endif
  27856. done:
  27857. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27858. if (key2 != NULL) {
  27859. wc_ecc_free(key2);
  27860. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27861. }
  27862. if (key3 != NULL) {
  27863. wc_ecc_free(key3);
  27864. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27865. }
  27866. #else
  27867. wc_ecc_free(key3);
  27868. wc_ecc_free(key2);
  27869. #endif
  27870. return ret;
  27871. }
  27872. #endif
  27873. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27874. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
  27875. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  27876. !defined(WOLFSSL_CRYPTOCELL)
  27877. static wc_test_ret_t ecc_ssh_test(ecc_key* key, WC_RNG* rng)
  27878. {
  27879. wc_test_ret_t ret;
  27880. byte out[128];
  27881. word32 outLen = sizeof(out);
  27882. /* Parameter Validation testing. */
  27883. ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen);
  27884. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27885. return WC_TEST_RET_ENC_EC(ret);
  27886. ret = wc_ecc_shared_secret_ssh(key, NULL, out, &outLen);
  27887. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27888. return WC_TEST_RET_ENC_EC(ret);
  27889. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, NULL, &outLen);
  27890. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27891. return WC_TEST_RET_ENC_EC(ret);
  27892. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, NULL);
  27893. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27894. return WC_TEST_RET_ENC_EC(ret);
  27895. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27896. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27897. !defined(HAVE_SELFTEST)
  27898. ret = wc_ecc_set_rng(key, rng);
  27899. if (ret != 0)
  27900. return WC_TEST_RET_ENC_EC(ret);
  27901. #else
  27902. (void)rng;
  27903. #endif
  27904. /* Use API. */
  27905. ret = 0;
  27906. do {
  27907. #if defined(WOLFSSL_ASYNC_CRYPT)
  27908. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27909. #endif
  27910. if (ret == 0)
  27911. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen);
  27912. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27913. if (ret != 0)
  27914. return WC_TEST_RET_ENC_EC(ret);
  27915. TEST_SLEEP();
  27916. return 0;
  27917. }
  27918. #endif /* HAVE_ECC_DHE && !WC_NO_RNG */
  27919. static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
  27920. {
  27921. wc_test_ret_t ret;
  27922. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27923. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27924. #else
  27925. ecc_key key[1];
  27926. #endif
  27927. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  27928. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  27929. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  27930. word32 idx = 0;
  27931. #endif
  27932. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27933. if (key == NULL)
  27934. ERROR_OUT(MEMORY_E, done);
  27935. #endif
  27936. wc_ecc_init_ex(key, HEAP_HINT, devId);
  27937. /* Use API */
  27938. ret = wc_ecc_set_flags(NULL, 0);
  27939. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27940. ret = WC_TEST_RET_ENC_EC(ret);
  27941. goto done;
  27942. }
  27943. ret = wc_ecc_set_flags(key, 0);
  27944. if (ret != 0)
  27945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27946. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27947. #ifndef WC_NO_RNG
  27948. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  27949. #if defined(WOLFSSL_ASYNC_CRYPT)
  27950. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  27951. #endif
  27952. if (ret != 0) {
  27953. goto done;
  27954. }
  27955. #ifndef NO_SIG_WRAPPER
  27956. ret = ecc_sig_test(rng, key);
  27957. if (ret < 0)
  27958. goto done;
  27959. #endif
  27960. TEST_SLEEP();
  27961. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
  27962. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27963. ret = ecc_ssh_test(key, rng);
  27964. if (ret < 0)
  27965. goto done;
  27966. #endif
  27967. wc_ecc_free(key);
  27968. #else
  27969. (void)rng;
  27970. #endif /* !WC_NO_RNG */
  27971. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  27972. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  27973. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  27974. /* Use test ECC key - ensure real private "d" exists */
  27975. #if defined(USE_CERT_BUFFERS_256)
  27976. {
  27977. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  27978. sizeof_ecc_key_der_256);
  27979. }
  27980. #elif !defined(NO_FILESYSTEM)
  27981. {
  27982. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  27983. byte der[128];
  27984. word32 derSz;
  27985. if (!file) {
  27986. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27987. }
  27988. derSz = (word32)XFREAD(der, 1, sizeof(der), file);
  27989. XFCLOSE(file);
  27990. if (derSz == 0)
  27991. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27992. ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
  27993. }
  27994. #else
  27995. {
  27996. (void)idx;
  27997. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
  27998. ERROR_OUT(ASN_PARSE_E, done);
  27999. }
  28000. #endif
  28001. if (ret != 0) {
  28002. goto done;
  28003. }
  28004. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
  28005. ret = ecc_exp_imp_test(key);
  28006. if (ret < 0)
  28007. goto done;
  28008. #endif
  28009. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  28010. !defined(WOLFSSL_CRYPTOCELL)
  28011. ret = ecc_mulmod_test(key);
  28012. if (ret < 0)
  28013. goto done;
  28014. #endif
  28015. #endif
  28016. #else
  28017. (void)rng;
  28018. (void)idx;
  28019. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  28020. done:
  28021. wc_ecc_free(key);
  28022. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28023. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28024. #endif
  28025. return ret;
  28026. }
  28027. #endif /* !NO_ECC256 || HAVE_ALL_CURVES */
  28028. #if defined(WOLFSSL_CERT_EXT) && \
  28029. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  28030. static wc_test_ret_t ecc_decode_test(void)
  28031. {
  28032. wc_test_ret_t ret;
  28033. word32 inSz;
  28034. word32 inOutIdx;
  28035. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28036. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28037. #else
  28038. ecc_key key[1];
  28039. #endif
  28040. /* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
  28041. /* This is ecc_clikeypub_der_256. */
  28042. WOLFSSL_SMALL_STACK_STATIC const byte good[] = {
  28043. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  28044. 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  28045. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xbf, 0xf4,
  28046. 0x0f, 0x44, 0x50, 0x9a, 0x3d, 0xce, 0x9b, 0xb7, 0xf0, 0xc5,
  28047. 0x4d, 0xf5, 0x70, 0x7b, 0xd4, 0xec, 0x24, 0x8e, 0x19, 0x80,
  28048. 0xec, 0x5a, 0x4c, 0xa2, 0x24, 0x03, 0x62, 0x2c, 0x9b, 0xda,
  28049. 0xef, 0xa2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xc6, 0x56,
  28050. 0x95, 0x06, 0xcc, 0x01, 0xa9, 0xbd, 0xf6, 0x75, 0x1a, 0x42,
  28051. 0xf7, 0xbd, 0xa9, 0xb2, 0x36, 0x22, 0x5f, 0xc7, 0x5d, 0x7f,
  28052. 0xb4 };
  28053. WOLFSSL_SMALL_STACK_STATIC const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
  28054. 0x00, 0x04, 0x01, 0x01 };
  28055. WOLFSSL_SMALL_STACK_STATIC const byte badOneObjId[] = { 0x30, 0x0a, 0x30, 0x08, 0x06, 0x00,
  28056. 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28057. WOLFSSL_SMALL_STACK_STATIC const byte badObjId1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x09,
  28058. 0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28059. WOLFSSL_SMALL_STACK_STATIC const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
  28060. 0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28061. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28062. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28063. 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28064. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28065. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28066. 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
  28067. WOLFSSL_SMALL_STACK_STATIC const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
  28068. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28069. 0x03, 0x03, 0x04, 0x01, 0x01 };
  28070. WOLFSSL_SMALL_STACK_STATIC const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
  28071. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28072. 0x03, 0x03, 0x00, 0x04, 0x01 };
  28073. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28074. if (key == NULL)
  28075. ERROR_OUT(MEMORY_E, done);
  28076. #endif
  28077. XMEMSET(key, 0, sizeof *key);
  28078. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28079. inSz = sizeof(good);
  28080. ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, key, inSz);
  28081. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28082. ret = WC_TEST_RET_ENC_EC(ret);
  28083. goto done;
  28084. }
  28085. ret = wc_EccPublicKeyDecode(good, NULL, key, inSz);
  28086. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28087. ret = WC_TEST_RET_ENC_EC(ret);
  28088. goto done;
  28089. }
  28090. ret = wc_EccPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  28091. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28092. ret = WC_TEST_RET_ENC_EC(ret);
  28093. goto done;
  28094. }
  28095. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0);
  28096. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28097. ret = WC_TEST_RET_ENC_EC(ret);
  28098. goto done;
  28099. }
  28100. /* Change offset to produce bad input data. */
  28101. inOutIdx = 2;
  28102. inSz = sizeof(good) - inOutIdx;
  28103. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28104. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28105. ret = WC_TEST_RET_ENC_EC(ret);
  28106. goto done;
  28107. }
  28108. inOutIdx = 4;
  28109. inSz = sizeof(good) - inOutIdx;
  28110. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28111. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28112. ret = WC_TEST_RET_ENC_EC(ret);
  28113. goto done;
  28114. }
  28115. /* Bad data. */
  28116. inSz = sizeof(badNoObjId);
  28117. inOutIdx = 0;
  28118. ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz);
  28119. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28120. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28121. {
  28122. ret = WC_TEST_RET_ENC_EC(ret);
  28123. goto done;
  28124. }
  28125. inSz = sizeof(badOneObjId);
  28126. inOutIdx = 0;
  28127. ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz);
  28128. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28129. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28130. {
  28131. ret = WC_TEST_RET_ENC_EC(ret);
  28132. goto done;
  28133. }
  28134. inSz = sizeof(badObjId1Len);
  28135. inOutIdx = 0;
  28136. ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz);
  28137. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28138. ret = WC_TEST_RET_ENC_EC(ret);
  28139. goto done;
  28140. }
  28141. inSz = sizeof(badObj2d1Len);
  28142. inOutIdx = 0;
  28143. ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz);
  28144. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28145. ret = WC_TEST_RET_ENC_EC(ret);
  28146. goto done;
  28147. }
  28148. inSz = sizeof(badNotBitStr);
  28149. inOutIdx = 0;
  28150. ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz);
  28151. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E) &&
  28152. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28153. {
  28154. ret = WC_TEST_RET_ENC_EC(ret);
  28155. goto done;
  28156. }
  28157. inSz = sizeof(badBitStrLen);
  28158. inOutIdx = 0;
  28159. ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz);
  28160. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28161. ret = WC_TEST_RET_ENC_EC(ret);
  28162. goto done;
  28163. }
  28164. inSz = sizeof(badNoBitStrZero);
  28165. inOutIdx = 0;
  28166. ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz);
  28167. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  28168. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28169. {
  28170. ret = WC_TEST_RET_ENC_EC(ret);
  28171. goto done;
  28172. }
  28173. inSz = sizeof(badPoint);
  28174. inOutIdx = 0;
  28175. ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz);
  28176. if (ret != WC_NO_ERR_TRACE(ASN_ECC_KEY_E) &&
  28177. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28178. {
  28179. ret = WC_TEST_RET_ENC_EC(ret);
  28180. goto done;
  28181. }
  28182. inSz = sizeof(good);
  28183. inOutIdx = 0;
  28184. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28185. if (ret != 0)
  28186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28187. done:
  28188. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28189. if (key != NULL) {
  28190. wc_ecc_free(key);
  28191. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28192. }
  28193. #else
  28194. wc_ecc_free(key);
  28195. #endif
  28196. return ret;
  28197. }
  28198. #endif /* WOLFSSL_CERT_EXT */
  28199. #ifdef WOLFSSL_CUSTOM_CURVES
  28200. static const byte eccKeyExplicitCurve[] = {
  28201. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  28202. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  28203. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  28204. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  28205. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  28206. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28207. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28208. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  28209. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  28210. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  28211. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  28212. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  28213. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  28214. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  28215. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  28216. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  28217. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  28218. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  28219. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28220. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28221. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  28222. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  28223. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  28224. 0x3c, 0x4c, 0xc9, 0x5e, 0x2e, 0xa2, 0x3d, 0x49,
  28225. 0xcc, 0x5b, 0xff, 0x4f, 0xc9, 0x2e, 0x1d, 0x4a,
  28226. 0xc6, 0x21, 0xf6, 0xf3, 0xe6, 0x0b, 0x4f, 0xa9,
  28227. 0x9d, 0x74, 0x99, 0xdd, 0x97, 0xc7, 0x6e, 0xbe,
  28228. 0x14, 0x2b, 0x39, 0x9d, 0x63, 0xc7, 0x97, 0x0d,
  28229. 0x45, 0x25, 0x40, 0x30, 0x77, 0x05, 0x76, 0x88,
  28230. 0x38, 0x96, 0x29, 0x7d, 0x9c, 0xe1, 0x50, 0xbe,
  28231. 0xac, 0xf0, 0x1d, 0x86, 0xf4, 0x2f, 0x65, 0x0b
  28232. };
  28233. static wc_test_ret_t ecc_test_custom_curves(WC_RNG* rng)
  28234. {
  28235. wc_test_ret_t ret;
  28236. word32 inOutIdx;
  28237. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28238. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28239. #else
  28240. ecc_key key[1];
  28241. #endif
  28242. /* test use of custom curve - using BRAINPOOLP256R1 for test */
  28243. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28244. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28245. WOLFSSL_SMALL_STACK_STATIC const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
  28246. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
  28247. };
  28248. #define ecc_oid_brainpoolp256r1_sz \
  28249. (sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t))
  28250. #else
  28251. #define ecc_oid_brainpoolp256r1 { \
  28252. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 \
  28253. }
  28254. #define ecc_oid_brainpoolp256r1_sz 9
  28255. #endif
  28256. #define ecc_oid_brainpoolp256r1_sum 104
  28257. WOLFSSL_SMALL_STACK_STATIC const ecc_set_type ecc_dp_brainpool256r1 = {
  28258. 32, /* size/bytes */
  28259. ECC_CURVE_CUSTOM, /* ID */
  28260. "BRAINPOOLP256R1", /* curve name */
  28261. "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
  28262. "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
  28263. "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", /* B */
  28264. "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", /* order */
  28265. "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", /* Gx */
  28266. "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
  28267. ecc_oid_brainpoolp256r1, /* oid/oidSz */
  28268. ecc_oid_brainpoolp256r1_sz,
  28269. ecc_oid_brainpoolp256r1_sum, /* oid sum */
  28270. 1, /* cofactor */
  28271. };
  28272. #endif /* HAVE_ECC_BRAINPOOL */
  28273. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28274. if (! key) {
  28275. ret = MEMORY_E;
  28276. goto done;
  28277. }
  28278. #endif
  28279. XMEMSET(key, 0, sizeof *key);
  28280. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28281. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, ECC_CURVE_DEF,
  28282. &ecc_dp_brainpool256r1);
  28283. if (ret != 0) {
  28284. printf("ECC test for custom curve failed!\n");
  28285. goto done;
  28286. }
  28287. #endif
  28288. #if defined(HAVE_ECC_BRAINPOOL) || defined(HAVE_ECC_KOBLITZ)
  28289. {
  28290. int curve_id;
  28291. #ifdef HAVE_ECC_BRAINPOOL
  28292. curve_id = ECC_BRAINPOOLP256R1;
  28293. #else
  28294. curve_id = ECC_SECP256K1;
  28295. #endif
  28296. /* Test and demonstrate use of non-SECP curve */
  28297. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, curve_id, NULL);
  28298. if (ret < 0) {
  28299. printf("ECC test for curve_id %d failed!\n", curve_id);
  28300. goto done;
  28301. }
  28302. }
  28303. #endif
  28304. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  28305. if (ret != 0)
  28306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28307. inOutIdx = 0;
  28308. ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key,
  28309. sizeof(eccKeyExplicitCurve));
  28310. if (ret != 0)
  28311. ret = WC_TEST_RET_ENC_EC(ret);
  28312. done:
  28313. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28314. if (key) {
  28315. wc_ecc_free(key);
  28316. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28317. }
  28318. #else
  28319. wc_ecc_free(key);
  28320. #endif
  28321. (void)rng;
  28322. return ret;
  28323. }
  28324. #endif /* WOLFSSL_CUSTOM_CURVES */
  28325. #ifdef WOLFSSL_SM2
  28326. #ifdef HAVE_ECC_VERIFY
  28327. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28328. #ifdef HAVE_OID_ENCODING
  28329. #define CODED_SM2P256V1 {1,2,156,10197,1,301}
  28330. #define CODED_SM2P256V1_SZ 6
  28331. #else
  28332. #define CODED_SM2P256V1 {0x06,0x08,0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D}
  28333. #define CODED_SM2P256V1_SZ 10
  28334. #endif
  28335. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28336. static const ecc_oid_t ecc_oid_sm2p256v1[] = CODED_SM2P256V1;
  28337. #else
  28338. #define ecc_oid_sm2p256v1 CODED_SM2P256V1
  28339. #endif
  28340. #define ecc_oid_sm2p256v1_sz CODED_SM2P256V1_SZ
  28341. #define ECC_SM2P256V1_TEST 102
  28342. static int test_sm2_verify_caseA2(void)
  28343. {
  28344. ecc_key key;
  28345. int ret, res;
  28346. mp_int r,s;
  28347. /* test key values */
  28348. const char qx[] = "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A";
  28349. const char qy[] = "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857";
  28350. const char d[] = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
  28351. const ecc_set_type ecc_sm2_A2 = {
  28352. 32, /* size/bytes */
  28353. ECC_SM2P256V1_TEST, /* ID */
  28354. "SM2P256V1_TEST", /* curve name */
  28355. /* from test case A.2 in draft-shen-sm2-ecdsa-02 */
  28356. "8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", /* prime */
  28357. "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", /* A */
  28358. "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", /* B */
  28359. "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", /* order n */
  28360. "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", /* Gx */
  28361. "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", /* Gy */
  28362. ecc_oid_sm2p256v1, /* oid/oidSz */
  28363. ecc_oid_sm2p256v1_sz,
  28364. ECC_SM2P256V1_OID, /* oid sum */
  28365. 1, /* cofactor */
  28366. };
  28367. /* use canned hash value hash = H(ZA||M) */
  28368. const byte hash[] = {
  28369. 0xB5,0x24,0xF5,0x52,0xCD,0x82,0xB8,0xB0,
  28370. 0x28,0x47,0x6E,0x00,0x5C,0x37,0x7F,0xB1,
  28371. 0x9A,0x87,0xE6,0xFC,0x68,0x2D,0x48,0xBB,
  28372. 0x5D,0x42,0xE3,0xD9,0xB9,0xEF,0xFE,0x76
  28373. };
  28374. /* canned r and s */
  28375. const byte rCan[] = {
  28376. 0x40,0xF1,0xEC,0x59,0xF7,0x93,0xD9,0xF4,
  28377. 0x9E,0x09,0xDC,0xEF,0x49,0x13,0x0D,0x41,
  28378. 0x94,0xF7,0x9F,0xB1,0xEE,0xD2,0xCA,0xA5,
  28379. 0x5B,0xAC,0xDB,0x49,0xC4,0xE7,0x55,0xD1
  28380. };
  28381. const byte sCan[] = {
  28382. 0x6F,0xC6,0xDA,0xC3,0x2C,0x5D,0x5C,0xF1,
  28383. 0x0C,0x77,0xDF,0xB2,0x0F,0x7C,0x2E,0xB6,
  28384. 0x67,0xA4,0x57,0x87,0x2F,0xB0,0x9E,0xC5,
  28385. 0x63,0x27,0xA6,0x7E,0xC7,0xDE,0xEB,0xE7
  28386. };
  28387. mp_init(&r);
  28388. mp_init(&s);
  28389. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28390. if (ret != 0)
  28391. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28392. ret = wc_ecc_set_custom_curve(&key, &ecc_sm2_A2);
  28393. if (ret != 0)
  28394. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28395. ret = wc_ecc_import_raw_ex(&key, qx, qy, d, ECC_SM2P256V1_TEST);
  28396. if (ret != 0)
  28397. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28398. mp_read_unsigned_bin(&r, rCan, sizeof(rCan));
  28399. mp_read_unsigned_bin(&s, sCan, sizeof(sCan));
  28400. ret = wc_ecc_sm2_verify_hash_ex(&r, &s, hash, sizeof(hash), &res, &key);
  28401. if (ret != 0)
  28402. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28403. if (res != 1)
  28404. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28405. done:
  28406. mp_free(&r);
  28407. mp_free(&s);
  28408. wc_ecc_free(&key);
  28409. return ret;
  28410. }
  28411. #endif /* WOLFSSL_PUBLIC_MP && WOLFSSL_CUSTOM_CURVES */
  28412. static int test_sm2_verify_case(void)
  28413. {
  28414. ecc_key key;
  28415. int ret, res;
  28416. /* test key values */
  28417. const char qx[] = "637F1B135036C933DC3F7A8EBB1B7B2FD1DFBD268D4F894B5AD47DBDBECD558F";
  28418. const char qy[] = "E88101D08048E36CCBF61CA38DDF7ABA542B4486E99E49F3A7470A857A096433";
  28419. /* use canned hash value hash = H(ZA||M) */
  28420. const byte hash[] = {
  28421. 0x3B,0xFA,0x5F,0xFB,0xC4,0x27,0x8C,0x9D,
  28422. 0x02,0x3A,0x19,0xCB,0x1E,0xAA,0xD2,0xF1,
  28423. 0x50,0x69,0x5B,0x20
  28424. };
  28425. const byte sig[] = {
  28426. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28427. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28428. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28429. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28430. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28431. 0xB5,0xB5,0xD9,0xD8,0xF1,0x20,0xDD,0x97,
  28432. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28433. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28434. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28435. };
  28436. const byte badSig[] = {
  28437. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28438. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28439. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28440. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28441. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28442. 0xB5,0xB5,0xE9,0xD8,0xF1,0x20,0xDD,0x97,
  28443. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28444. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28445. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28446. };
  28447. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28448. if (ret != 0)
  28449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28450. ret = wc_ecc_import_raw(&key, qx, qy, NULL, "SM2P256V1");
  28451. if (ret != 0)
  28452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28453. ret = wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash), &res,
  28454. &key);
  28455. if (ret != 0)
  28456. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28457. if (res != 1)
  28458. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28459. /* now test a case that should fail */
  28460. ret = wc_ecc_sm2_verify_hash(badSig, sizeof(badSig), hash, sizeof(hash),
  28461. &res, &key);
  28462. if (ret != 0)
  28463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28464. if (res == 1)
  28465. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28466. done:
  28467. wc_ecc_free(&key);
  28468. return ret;
  28469. }
  28470. static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
  28471. {
  28472. const ecc_set_type* dp = wc_ecc_get_curve_params(
  28473. wc_ecc_get_curve_idx(ECC_SM2P256V1));
  28474. int keySize = 32;
  28475. int curve_id = ECC_SM2P256V1;
  28476. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28477. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28478. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28479. #endif
  28480. #ifdef HAVE_ECC_KEY_EXPORT
  28481. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  28482. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28483. #endif
  28484. word32 x = 0;
  28485. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28486. word32 y;
  28487. #endif
  28488. #ifdef HAVE_ECC_SIGN
  28489. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28490. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28491. int i;
  28492. int verify;
  28493. #endif /* HAVE_ECC_SIGN */
  28494. int ret;
  28495. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28496. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28497. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28498. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28499. #else
  28500. ecc_key userA[1];
  28501. ecc_key userB[1];
  28502. ecc_key pubKey[1];
  28503. #endif
  28504. #ifndef WC_NO_RNG
  28505. int curveSize;
  28506. #endif
  28507. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28508. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28509. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28510. #endif
  28511. #ifdef HAVE_ECC_KEY_EXPORT
  28512. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28513. #endif
  28514. #ifdef HAVE_ECC_SIGN
  28515. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28516. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28517. #endif
  28518. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  28519. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28520. if (sharedA == NULL || sharedB == NULL)
  28521. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28522. #endif
  28523. #ifdef HAVE_ECC_KEY_EXPORT
  28524. if (exportBuf == NULL)
  28525. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28526. #endif
  28527. #ifdef HAVE_ECC_SIGN
  28528. if (sig == NULL || digest == NULL)
  28529. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28530. #endif
  28531. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  28532. (void)testVerifyCount;
  28533. (void)dp;
  28534. (void)x;
  28535. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28536. if ((userA == NULL) ||
  28537. (userB == NULL) ||
  28538. (pubKey == NULL))
  28539. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28540. #endif
  28541. XMEMSET(userA, 0, sizeof *userA);
  28542. XMEMSET(userB, 0, sizeof *userB);
  28543. XMEMSET(pubKey, 0, sizeof *pubKey);
  28544. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  28545. if (ret != 0)
  28546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28547. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  28548. if (ret != 0)
  28549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28550. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28551. if (ret != 0)
  28552. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28553. #ifndef WC_NO_RNG
  28554. ret = wc_ecc_sm2_make_key(rng, userA, WC_ECC_FLAG_NONE);
  28555. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  28556. goto done; /* catch case, where curve is not supported */
  28557. if (ret != 0)
  28558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28559. TEST_SLEEP();
  28560. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  28561. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  28562. if (curveSize != userA->dp->size) {
  28563. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28564. }
  28565. }
  28566. ret = wc_ecc_check_key(userA);
  28567. if (ret != 0)
  28568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28569. TEST_SLEEP();
  28570. ret = wc_ecc_sm2_make_key(rng, userB, WC_ECC_FLAG_NONE);
  28571. if (ret != 0)
  28572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28573. /* only perform the below tests if the key size matches */
  28574. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  28575. if (ret != 0) {
  28576. ret = ECC_CURVE_OID_E;
  28577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28578. }
  28579. #ifdef HAVE_ECC_DHE
  28580. #if defined(ECC_TIMING_RESISTANT)
  28581. ret = wc_ecc_set_rng(userA, rng);
  28582. if (ret != 0)
  28583. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28584. ret = wc_ecc_set_rng(userB, rng);
  28585. if (ret != 0)
  28586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28587. #endif
  28588. x = ECC_SHARED_SIZE;
  28589. ret = wc_ecc_sm2_shared_secret(userA, userB, sharedA, &x);
  28590. if (ret != 0)
  28591. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28592. y = ECC_SHARED_SIZE;
  28593. ret = wc_ecc_sm2_shared_secret(userB, userA, sharedB, &y);
  28594. if (ret != 0)
  28595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28596. if (y != x)
  28597. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28598. if (XMEMCMP(sharedA, sharedB, x))
  28599. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28600. #endif /* HAVE_ECC_DHE */
  28601. #ifdef HAVE_ECC_KEY_EXPORT
  28602. x = ECC_KEY_EXPORT_BUF_SIZE;
  28603. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  28604. if (ret != 0)
  28605. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28606. #ifdef HAVE_ECC_KEY_IMPORT
  28607. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28608. if (ret != 0)
  28609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28610. #ifdef HAVE_ECC_DHE
  28611. y = ECC_SHARED_SIZE;
  28612. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28613. if (ret != 0)
  28614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28615. if (XMEMCMP(sharedA, sharedB, y))
  28616. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28617. #endif /* HAVE_ECC_DHE */
  28618. #ifdef HAVE_COMP_KEY
  28619. /* try compressed export / import too */
  28620. x = ECC_KEY_EXPORT_BUF_SIZE;
  28621. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  28622. if (ret != 0)
  28623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28624. wc_ecc_free(pubKey);
  28625. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28626. if (ret != 0)
  28627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28628. #endif
  28629. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28630. if (ret != 0)
  28631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28632. #ifdef HAVE_ECC_DHE
  28633. y = ECC_SHARED_SIZE;
  28634. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28635. if (ret != 0)
  28636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28637. if (XMEMCMP(sharedA, sharedB, y))
  28638. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28639. #endif /* HAVE_ECC_DHE */
  28640. #endif /* HAVE_ECC_KEY_IMPORT */
  28641. #endif /* HAVE_ECC_KEY_EXPORT */
  28642. #endif /* !WC_NO_RNG */
  28643. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  28644. !defined(WC_NO_RNG))
  28645. #ifdef HAVE_ECC_SIGN
  28646. /* ECC w/out Shamir has issue with all 0 digest */
  28647. /* WC_BIGINT doesn't have 0 len well on hardware */
  28648. /* Cryptocell has issues with all 0 digest */
  28649. #if defined(ECC_SHAMIR)
  28650. /* test DSA sign hash with zeros */
  28651. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28652. digest[i] = 0;
  28653. }
  28654. x = ECC_SIG_SIZE;
  28655. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28656. if (ret != 0)
  28657. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28658. for (i = 0; i < testVerifyCount; i++) {
  28659. verify = 0;
  28660. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28661. userA);
  28662. if (ret != 0)
  28663. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28664. if (verify != 1)
  28665. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28666. }
  28667. #endif /* ECC_SHAMIR */
  28668. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  28669. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28670. digest[i] = (byte)i;
  28671. }
  28672. x = ECC_SIG_SIZE;
  28673. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28674. if (ret != 0)
  28675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28676. for (i = 0; i < testVerifyCount; i++) {
  28677. verify = 0;
  28678. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28679. userA);
  28680. if (ret != 0)
  28681. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28682. if (verify != 1)
  28683. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28684. }
  28685. #endif /* HAVE_ECC_SIGN */
  28686. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT && !WC_NO_RNG) */
  28687. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  28688. x = ECC_KEY_EXPORT_BUF_SIZE;
  28689. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  28690. if (ret != 0)
  28691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28692. #elif defined(HAVE_ECC_KEY_EXPORT)
  28693. (void)exportBuf;
  28694. #endif /* HAVE_ECC_KEY_EXPORT */
  28695. done:
  28696. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28697. if (userA != NULL) {
  28698. wc_ecc_free(userA);
  28699. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28700. }
  28701. if (userB != NULL) {
  28702. wc_ecc_free(userB);
  28703. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28704. }
  28705. if (pubKey != NULL) {
  28706. wc_ecc_free(pubKey);
  28707. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28708. }
  28709. #else
  28710. wc_ecc_free(pubKey);
  28711. wc_ecc_free(userB);
  28712. wc_ecc_free(userA);
  28713. #endif
  28714. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  28715. WC_FREE_VAR(sharedA, HEAP_HINT);
  28716. WC_FREE_VAR(sharedB, HEAP_HINT);
  28717. #endif
  28718. #ifdef HAVE_ECC_KEY_EXPORT
  28719. WC_FREE_VAR(exportBuf, HEAP_HINT);
  28720. #endif
  28721. #ifdef HAVE_ECC_SIGN
  28722. WC_FREE_VAR(sig, HEAP_HINT);
  28723. WC_FREE_VAR(digest, HEAP_HINT);
  28724. #endif
  28725. (void)keySize;
  28726. (void)curve_id;
  28727. (void)rng;
  28728. return ret;
  28729. }
  28730. #endif /* HAVE_ECC_VERIFY */
  28731. static int test_sm2_create_digest(void)
  28732. {
  28733. #ifndef WOLFSSL_SM3
  28734. const byte msg[] = "message to sign";
  28735. const byte id[] = "0123456789";
  28736. const byte badId[] = "0123556789";
  28737. byte expected[] = {
  28738. 0xdd, 0x4d, 0x65, 0x49, 0xa3, 0x64, 0x76, 0xc0,
  28739. 0x73, 0x05, 0xdc, 0x05, 0x16, 0xb5, 0xee, 0x9f,
  28740. 0x82, 0xf9, 0xe9, 0x7d, 0x01, 0x1a, 0xdc, 0x88,
  28741. 0x5a, 0x59, 0x9c, 0x44, 0xcc, 0x47, 0xa4, 0x78
  28742. };
  28743. ecc_key key;
  28744. int ret;
  28745. /* test key values */
  28746. const char qx[] =
  28747. "af178b7b8740cc9d5b493fbd22049c12621bc27dcc5802e75ff4d045a4158baf";
  28748. const char qy[] =
  28749. "89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
  28750. const char d[] =
  28751. "b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
  28752. int hash_type = WC_HASH_TYPE_SHA256;
  28753. byte digest[WC_SHA256_DIGEST_SIZE];
  28754. #else
  28755. ecc_key key;
  28756. int ret;
  28757. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
  28758. 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
  28759. const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28760. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28761. 0x00 };
  28762. const byte badId[] = "0123556789";
  28763. const char qx[] =
  28764. "09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
  28765. const char qy[] =
  28766. "CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
  28767. const char d[] =
  28768. "3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
  28769. byte expected[] = {
  28770. 0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
  28771. 0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
  28772. 0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
  28773. 0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
  28774. };
  28775. int hash_type = WC_HASH_TYPE_SM3;
  28776. byte digest[WC_SM3_DIGEST_SIZE];
  28777. #endif
  28778. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28779. if (ret != 0)
  28780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28781. ret = wc_ecc_import_raw(&key, qx, qy, d, "SM2P256V1");
  28782. if (ret != 0)
  28783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28784. ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
  28785. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28786. &key);
  28787. if (ret != 0)
  28788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28789. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
  28790. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28791. ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
  28792. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28793. &key);
  28794. if (ret != 0)
  28795. goto done;
  28796. /* should be different than the previous ID used */
  28797. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) == 0)
  28798. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28799. done:
  28800. wc_ecc_free(&key);
  28801. return ret;
  28802. }
  28803. static int test_sm2_verify(void)
  28804. {
  28805. int ret = 0;
  28806. #ifdef HAVE_ECC_VERIFY
  28807. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28808. ret = test_sm2_verify_caseA2();
  28809. if (ret != 0)
  28810. return ret;
  28811. #endif
  28812. ret = test_sm2_verify_case();
  28813. if (ret != 0)
  28814. return ret;
  28815. #endif /* HAVE_ECC_VERIFY */
  28816. ret = test_sm2_create_digest();
  28817. return ret;
  28818. }
  28819. #endif /* WOLFSSL_SM2 */
  28820. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && !defined(NO_ASN_TIME)
  28821. /* Make Cert / Sign example for ECC cert and ECC CA */
  28822. static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
  28823. {
  28824. wc_test_ret_t ret;
  28825. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28826. Cert *myCert = (Cert *)XMALLOC(sizeof *myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28827. #ifdef WOLFSSL_TEST_CERT
  28828. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28829. #endif
  28830. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28831. ecc_key *certPubKey = (ecc_key *)XMALLOC(sizeof *certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28832. #else
  28833. Cert myCert[1];
  28834. #ifdef WOLFSSL_TEST_CERT
  28835. DecodedCert decode[1];
  28836. #endif
  28837. ecc_key caEccKey[1];
  28838. ecc_key certPubKey[1];
  28839. #endif
  28840. int certSz;
  28841. size_t bytes = 0;
  28842. word32 idx = 0;
  28843. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
  28844. XFILE file;
  28845. #endif
  28846. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28847. byte* der = NULL;
  28848. #else
  28849. byte der[FOURK_BUF];
  28850. #endif
  28851. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28852. if ((myCert == NULL)
  28853. #ifdef WOLFSSL_TEST_CERT
  28854. || (decode == NULL)
  28855. #endif
  28856. || (caEccKey == NULL) || (certPubKey == NULL))
  28857. ERROR_OUT(MEMORY_E, exit);
  28858. #endif
  28859. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  28860. XMEMSET(certPubKey, 0, sizeof *certPubKey);
  28861. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28862. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28863. if (der == NULL) {
  28864. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28865. }
  28866. #endif
  28867. /* Get cert private key */
  28868. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28869. /* Get Cert Key 384 */
  28870. #ifdef USE_CERT_BUFFERS_256
  28871. XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
  28872. bytes = sizeof_ca_ecc_key_der_384;
  28873. #elif !defined(NO_FILESYSTEM)
  28874. file = XFOPEN(eccCaKey384File, "rb");
  28875. if (!file) {
  28876. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28877. }
  28878. bytes = XFREAD(der, 1, FOURK_BUF, file);
  28879. XFCLOSE(file);
  28880. if (bytes == 0)
  28881. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28882. (void)eccCaKeyFile;
  28883. #else
  28884. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
  28885. ERROR_OUT(ASN_PARSE_E, exit);
  28886. #endif /* USE_CERT_BUFFERS_256 */
  28887. /* end if ENABLE_ECC384_CERT_GEN_TEST */
  28888. #else
  28889. /* !ENABLE_ECC384_CERT_GEN_TEST */
  28890. #ifdef USE_CERT_BUFFERS_256
  28891. XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
  28892. bytes = sizeof_ca_ecc_key_der_256;
  28893. #else
  28894. file = XFOPEN(eccCaKeyFile, "rb");
  28895. if (!file) {
  28896. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28897. }
  28898. bytes = XFREAD(der, 1, FOURK_BUF, file);
  28899. XFCLOSE(file);
  28900. if (bytes == 0)
  28901. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28902. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28903. (void)eccCaKey384File;
  28904. #endif
  28905. #endif /* USE_CERT_BUFFERS_256 */
  28906. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  28907. /* Get CA Key */
  28908. ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId);
  28909. if (ret != 0)
  28910. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28911. ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes);
  28912. if (ret != 0)
  28913. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28914. /* Make a public key */
  28915. ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId);
  28916. if (ret != 0)
  28917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28918. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey);
  28919. #if defined(WOLFSSL_ASYNC_CRYPT)
  28920. ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE);
  28921. #endif
  28922. if (ret != 0)
  28923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28924. TEST_SLEEP();
  28925. /* Setup Certificate */
  28926. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  28927. if (ret != 0)
  28928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28929. #ifndef NO_SHA256
  28930. myCert->sigType = CTC_SHA256wECDSA;
  28931. #else
  28932. myCert->sigType = CTC_SHAwECDSA;
  28933. #endif
  28934. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  28935. #ifdef WOLFSSL_CERT_EXT
  28936. /* add Policies */
  28937. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  28938. CTC_MAX_CERTPOL_SZ);
  28939. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  28940. CTC_MAX_CERTPOL_SZ);
  28941. myCert->certPoliciesNb = 2;
  28942. /* add SKID from the Public Key */
  28943. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey);
  28944. if (ret != 0)
  28945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28946. /* add AKID from the Public Key */
  28947. ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey);
  28948. if (ret != 0)
  28949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28950. /* add Key Usage */
  28951. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  28952. if (ret != 0)
  28953. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28954. #endif /* WOLFSSL_CERT_EXT */
  28955. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28956. #if defined(USE_CERT_BUFFERS_256)
  28957. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
  28958. sizeof_ca_ecc_cert_der_384);
  28959. #elif !defined(NO_FILESYSTEM)
  28960. ret = wc_SetIssuer(myCert, eccCaCert384File);
  28961. (void)eccCaCertFile;
  28962. #else
  28963. /* not testing with embedded, no file system target */
  28964. ERROR_OUT(ASN_PARSE_E, exit);
  28965. #endif /* USE_CERT_BUFFERS_256 */
  28966. #else
  28967. /* not ENABLE_ECC384_CERT_GEN_TEST */
  28968. #if defined(USE_CERT_BUFFERS_256)
  28969. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
  28970. sizeof_ca_ecc_cert_der_256);
  28971. #else
  28972. ret = wc_SetIssuer(myCert, eccCaCertFile);
  28973. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28974. (void)eccCaCert384File;
  28975. #endif
  28976. #endif
  28977. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  28978. if (ret < 0)
  28979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28980. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng);
  28981. if (certSz < 0) {
  28982. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit);
  28983. }
  28984. ret = 0;
  28985. do {
  28986. #if defined(WOLFSSL_ASYNC_CRYPT)
  28987. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  28988. #endif
  28989. if (ret >= 0) {
  28990. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  28991. FOURK_BUF, NULL, caEccKey, rng);
  28992. }
  28993. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  28994. if (ret < 0)
  28995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28996. certSz = (int)ret;
  28997. TEST_SLEEP();
  28998. #ifdef WOLFSSL_TEST_CERT
  28999. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  29000. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  29001. if (ret != 0) {
  29002. FreeDecodedCert(decode);
  29003. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29004. }
  29005. FreeDecodedCert(decode);
  29006. #endif
  29007. ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile,
  29008. CERT_TYPE);
  29009. if (ret != 0) {
  29010. goto exit;
  29011. }
  29012. exit:
  29013. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29014. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29015. #endif
  29016. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29017. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29018. #ifdef WOLFSSL_TEST_CERT
  29019. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29020. #endif
  29021. if (caEccKey != NULL) {
  29022. wc_ecc_free(caEccKey);
  29023. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29024. }
  29025. if (certPubKey != NULL) {
  29026. wc_ecc_free(certPubKey);
  29027. XFREE(certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29028. }
  29029. #else
  29030. wc_ecc_free(certPubKey);
  29031. wc_ecc_free(caEccKey);
  29032. #endif
  29033. return ret;
  29034. }
  29035. #endif /* WOLFSSL_CERT_GEN */
  29036. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  29037. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
  29038. (!defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES))
  29039. /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */
  29040. static wc_test_ret_t ecc_test_allocator(WC_RNG* rng)
  29041. {
  29042. wc_test_ret_t ret = 0;
  29043. ecc_key* key;
  29044. #ifdef WC_NO_RNG
  29045. word32 idx = 0;
  29046. #endif
  29047. key = wc_ecc_key_new(HEAP_HINT);
  29048. if (key == NULL) {
  29049. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29050. }
  29051. #ifndef WC_NO_RNG
  29052. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  29053. #if defined(WOLFSSL_ASYNC_CRYPT)
  29054. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  29055. #endif
  29056. if (ret != 0)
  29057. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29058. #else
  29059. /* use test ECC key */
  29060. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  29061. (word32)sizeof_ecc_key_der_256);
  29062. (void)rng;
  29063. #endif
  29064. exit:
  29065. wc_ecc_key_free(key);
  29066. return ret;
  29067. }
  29068. #endif
  29069. /* ECC Non-blocking tests for Sign and Verify */
  29070. /* Requires SP math and supports P384 or P256 */
  29071. /* ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" */
  29072. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_HAVE_SP_ECC) && \
  29073. defined(WOLFSSL_PUBLIC_MP)
  29074. /* ECC Private Key "d" */
  29075. static const byte p256PrivKey[] = {
  29076. /* SECP256R1 */
  29077. /* d */
  29078. 0x1e, 0xe7, 0x70, 0x07, 0xd3, 0x30, 0x94, 0x39,
  29079. 0x28, 0x90, 0xdf, 0x23, 0x88, 0x2c, 0x4a, 0x34,
  29080. 0x15, 0xdb, 0x4c, 0x43, 0xcd, 0xfa, 0xe5, 0x1f,
  29081. 0x3d, 0x4c, 0x37, 0xfe, 0x59, 0x3b, 0x96, 0xd8
  29082. };
  29083. #ifdef HAVE_ECC384
  29084. static const byte p384PrivKey[] = {
  29085. /* SECP384R1 */
  29086. /* d */
  29087. 0xa4, 0xe5, 0x06, 0xe8, 0x06, 0x16, 0x3e, 0xab,
  29088. 0x89, 0xf8, 0x60, 0x43, 0xc0, 0x60, 0x25, 0xdb,
  29089. 0xba, 0x7b, 0xfe, 0x19, 0x35, 0x08, 0x55, 0x65,
  29090. 0x76, 0xe2, 0xdc, 0xe0, 0x01, 0x8b, 0x6b, 0x68,
  29091. 0xdf, 0xcf, 0x6f, 0x80, 0x12, 0xce, 0x79, 0x37,
  29092. 0xeb, 0x2b, 0x9c, 0x7b, 0xc4, 0x68, 0x1c, 0x74
  29093. };
  29094. #endif /* HAVE_ECC384 */
  29095. #ifdef HAVE_ECC521
  29096. static const byte p521PrivKey[] = {
  29097. /* SECP521R1 */
  29098. /* d */
  29099. 0x01, 0x68, 0x91, 0x33, 0x53, 0xe2, 0x90, 0x68,
  29100. 0x11, 0x8f, 0xaa, 0xa8, 0x76, 0x0c, 0xf7, 0x2a,
  29101. 0x07, 0x1b, 0x92, 0x2a, 0xa7, 0x82, 0x3d, 0xfa,
  29102. 0x83, 0xce, 0x70, 0xc8, 0xc2, 0x60, 0x82, 0xfe,
  29103. 0x18, 0x88, 0x68, 0xda, 0x6a, 0x83, 0x46, 0x78,
  29104. 0xe4, 0xe9, 0xe9, 0xcc, 0x51, 0x7f, 0xed, 0x81,
  29105. 0x02, 0x32, 0xee, 0x26, 0x87, 0xcc, 0xed, 0x63,
  29106. 0x3f, 0x39, 0x27, 0xf0, 0xd7, 0x17, 0x77, 0xa1,
  29107. 0xa4, 0x36
  29108. };
  29109. #endif /* HAVE_ECC521 */
  29110. /* ECC public key Qx/Qy */
  29111. static const byte p256PubKey[] = {
  29112. /* SECP256R1 */
  29113. /* Qx */
  29114. 0x96, 0x93, 0x1c, 0x53, 0x0b, 0x43, 0x6c, 0x42,
  29115. 0x0c, 0x52, 0x90, 0xe4, 0xa7, 0xec, 0x98, 0xb1,
  29116. 0xaf, 0xd4, 0x14, 0x49, 0xd8, 0xc1, 0x42, 0x82,
  29117. 0x04, 0x78, 0xd1, 0x90, 0xae, 0xa0, 0x6c, 0x07,
  29118. /* Qy */
  29119. 0xf2, 0x3a, 0xb5, 0x10, 0x32, 0x8d, 0xce, 0x9e,
  29120. 0x76, 0xa0, 0xd2, 0x8c, 0xf3, 0xfc, 0xa9, 0x94,
  29121. 0x43, 0x24, 0xe6, 0x82, 0x00, 0x40, 0xc6, 0xdb,
  29122. 0x1c, 0x2f, 0xcd, 0x38, 0x4b, 0x60, 0xdd, 0x61
  29123. };
  29124. #ifdef HAVE_ECC384
  29125. static const byte p384PubKey[] = {
  29126. /* SECP384R1 */
  29127. /* Qx */
  29128. 0xea, 0xcf, 0x93, 0x4f, 0x2c, 0x09, 0xbb, 0x39,
  29129. 0x14, 0x0f, 0x56, 0x64, 0xc3, 0x40, 0xb4, 0xdf,
  29130. 0x0e, 0x63, 0xae, 0xe5, 0x71, 0x4b, 0x00, 0xcc,
  29131. 0x04, 0x97, 0xff, 0xe1, 0xe9, 0x38, 0x96, 0xbb,
  29132. 0x5f, 0x91, 0xb2, 0x6a, 0xcc, 0xb5, 0x39, 0x5f,
  29133. 0x8f, 0x70, 0x59, 0xf1, 0x01, 0xf6, 0x5a, 0x2b,
  29134. /* Qy */
  29135. 0x01, 0x6c, 0x68, 0x0b, 0xcf, 0x55, 0x25, 0xaf,
  29136. 0x6d, 0x98, 0x48, 0x0a, 0xa8, 0x74, 0xc9, 0xa9,
  29137. 0x17, 0xa0, 0x0c, 0xc3, 0xfb, 0xd3, 0x23, 0x68,
  29138. 0xfe, 0x04, 0x3c, 0x63, 0x50, 0x88, 0x3b, 0xb9,
  29139. 0x4f, 0x7c, 0x67, 0x34, 0xf7, 0x3b, 0xa9, 0x73,
  29140. 0xe7, 0x1b, 0xc3, 0x51, 0x5e, 0x22, 0x18, 0xec
  29141. };
  29142. #endif
  29143. #ifdef HAVE_ECC521
  29144. static const byte p521PubKey[] = {
  29145. /* SECP521R1 */
  29146. /* Qx */
  29147. 0x01, 0x62, 0x6e, 0xf1, 0x00, 0xec, 0xd8, 0x99,
  29148. 0x58, 0x9b, 0x80, 0x6b, 0xfe, 0x2c, 0xf1, 0xb2,
  29149. 0xf0, 0xc8, 0x48, 0xdf, 0xac, 0xd2, 0x3b, 0x71,
  29150. 0x29, 0xab, 0xf0, 0x66, 0x63, 0xd8, 0x8e, 0xb5,
  29151. 0xc8, 0xc2, 0xfc, 0x99, 0x44, 0xe2, 0x45, 0xb1,
  29152. 0x5a, 0x7b, 0xb9, 0x73, 0x01, 0xda, 0x79, 0xec,
  29153. 0x9c, 0x26, 0x27, 0x34, 0x45, 0x26, 0xd5, 0x89,
  29154. 0x4b, 0x44, 0xfe, 0x69, 0x4e, 0x72, 0x14, 0xe3,
  29155. 0x8b, 0xbc,
  29156. /* Qy */
  29157. 0x00, 0x0f, 0x09, 0xa2, 0x03, 0xc3, 0x5a, 0xdc,
  29158. 0x95, 0x82, 0xf6, 0xf9, 0xf6, 0x9c, 0xff, 0xb5,
  29159. 0x6b, 0x75, 0x95, 0x4b, 0xa4, 0x28, 0x5d, 0x9e,
  29160. 0x90, 0x04, 0xd1, 0xc0, 0x1e, 0xd5, 0xfd, 0x43,
  29161. 0x9e, 0x1e, 0x83, 0xc0, 0x11, 0x2b, 0x2b, 0x07,
  29162. 0x6d, 0xa9, 0x7a, 0x10, 0xd7, 0x67, 0xe7, 0x51,
  29163. 0x37, 0x24, 0xd8, 0xbf, 0x03, 0x0d, 0x8b, 0xb5,
  29164. 0x40, 0x5c, 0x4f, 0xd6, 0x13, 0x73, 0x42, 0xbc,
  29165. 0x91, 0xd9
  29166. };
  29167. /* perform verify of signature and hash using public key */
  29168. /* key is public Qx + public Qy */
  29169. /* sig is r + s */
  29170. static wc_test_ret_t crypto_ecc_verify(const byte *key, uint32_t keySz,
  29171. const byte *hash, uint32_t hashSz, const byte *sig, uint32_t sigSz,
  29172. uint32_t curveSz, int curveId)
  29173. {
  29174. wc_test_ret_t ret;
  29175. int verify_res = 0, count = 0;
  29176. mp_int r, s;
  29177. ecc_key ecc;
  29178. ecc_nb_ctx_t nb_ctx;
  29179. /* validate arguments */
  29180. if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 ||
  29181. hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2))
  29182. {
  29183. return WC_TEST_RET_ENC_NC;
  29184. }
  29185. /* Setup the ECC key */
  29186. ret = wc_ecc_init(&ecc);
  29187. if (ret < 0) {
  29188. return WC_TEST_RET_ENC_EC(ret);
  29189. }
  29190. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29191. if (ret != MP_OKAY) {
  29192. wc_ecc_free(&ecc);
  29193. return WC_TEST_RET_ENC_EC(ret);
  29194. }
  29195. /* Setup the signature r/s variables */
  29196. ret = mp_init(&r);
  29197. if (ret != MP_OKAY) {
  29198. wc_ecc_free(&ecc);
  29199. return WC_TEST_RET_ENC_EC(ret);
  29200. }
  29201. ret = mp_init(&s);
  29202. if (ret != MP_OKAY) {
  29203. mp_clear(&r);
  29204. wc_ecc_free(&ecc);
  29205. return WC_TEST_RET_ENC_EC(ret);
  29206. }
  29207. /* Import public key x/y */
  29208. ret = wc_ecc_import_unsigned(
  29209. &ecc,
  29210. (byte*)key, /* Public "x" Coordinate */
  29211. (byte*)(key + curveSz), /* Public "y" Coordinate */
  29212. NULL, /* Private "d" (optional) */
  29213. curveId /* ECC Curve Id */
  29214. );
  29215. /* Make sure it was a public key imported */
  29216. if (ret == 0 && ecc.type != ECC_PUBLICKEY) {
  29217. ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */
  29218. }
  29219. /* Import signature r/s */
  29220. if (ret == 0) {
  29221. ret = mp_read_unsigned_bin(&r, sig, curveSz);
  29222. if (ret < 0)
  29223. ret = WC_TEST_RET_ENC_EC(ret);
  29224. }
  29225. if (ret == 0) {
  29226. ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz);
  29227. if (ret < 0)
  29228. ret = WC_TEST_RET_ENC_EC(ret);
  29229. }
  29230. /* Verify ECC Signature */
  29231. if (ret == 0) {
  29232. do {
  29233. ret = wc_ecc_verify_hash_ex(
  29234. &r, &s, /* r/s as mp_int */
  29235. hash, hashSz, /* computed hash digest */
  29236. &verify_res, /* verification result 1=success */
  29237. &ecc
  29238. );
  29239. count++;
  29240. /* This is where real-time work could be called */
  29241. } while (ret == FP_WOULDBLOCK);
  29242. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29243. printf("ECC non-block verify: %d times\n", count);
  29244. #endif
  29245. if (ret < 0)
  29246. ret = WC_TEST_RET_ENC_EC(ret);
  29247. }
  29248. /* check verify result */
  29249. if (ret == 0 && verify_res == 0) {
  29250. ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */;
  29251. }
  29252. mp_clear(&r);
  29253. mp_clear(&s);
  29254. wc_ecc_free(&ecc);
  29255. (void)count;
  29256. return ret;
  29257. }
  29258. /* perform signature operation against hash using private key */
  29259. static wc_test_ret_t crypto_ecc_sign(const byte *key, uint32_t keySz,
  29260. const byte *hash, uint32_t hashSz, byte *sig, uint32_t* sigSz,
  29261. uint32_t curveSz, int curveId, WC_RNG* rng)
  29262. {
  29263. wc_test_ret_t ret;
  29264. int count = 0;
  29265. mp_int r, s;
  29266. ecc_key ecc;
  29267. ecc_nb_ctx_t nb_ctx;
  29268. /* validate arguments */
  29269. if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL ||
  29270. curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2))
  29271. {
  29272. return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */;
  29273. }
  29274. /* Initialize signature result */
  29275. memset(sig, 0, curveSz*2);
  29276. /* Setup the ECC key */
  29277. ret = wc_ecc_init(&ecc);
  29278. if (ret < 0) {
  29279. return WC_TEST_RET_ENC_EC(ret);
  29280. }
  29281. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29282. if (ret != MP_OKAY) {
  29283. wc_ecc_free(&ecc);
  29284. return WC_TEST_RET_ENC_EC(ret);
  29285. }
  29286. /* Setup the signature r/s variables */
  29287. ret = mp_init(&r);
  29288. if (ret != MP_OKAY) {
  29289. wc_ecc_free(&ecc);
  29290. return WC_TEST_RET_ENC_EC(ret);
  29291. }
  29292. ret = mp_init(&s);
  29293. if (ret != MP_OKAY) {
  29294. mp_clear(&r);
  29295. wc_ecc_free(&ecc);
  29296. return WC_TEST_RET_ENC_EC(ret);
  29297. }
  29298. /* Import private key "k" */
  29299. ret = wc_ecc_import_private_key_ex(
  29300. key, keySz, /* private key "d" */
  29301. NULL, 0, /* public (optional) */
  29302. &ecc,
  29303. curveId /* ECC Curve Id */
  29304. );
  29305. if (ret < 0)
  29306. ret = WC_TEST_RET_ENC_EC(ret);
  29307. if (ret == 0) {
  29308. do {
  29309. /* Verify ECC Signature */
  29310. ret = wc_ecc_sign_hash_ex(
  29311. hash, hashSz, /* computed hash digest */
  29312. rng, &ecc, /* random and key context */
  29313. &r, &s /* r/s as mp_int */
  29314. );
  29315. count++;
  29316. /* This is where real-time work could be called */
  29317. } while (ret == FP_WOULDBLOCK);
  29318. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29319. printf("ECC non-block sign: %d times\n", count);
  29320. #endif
  29321. if (ret < 0)
  29322. ret = WC_TEST_RET_ENC_EC(ret);
  29323. }
  29324. if (ret == 0) {
  29325. /* export r/s */
  29326. mp_to_unsigned_bin_len(&r, sig, curveSz);
  29327. mp_to_unsigned_bin_len(&s, sig + curveSz, curveSz);
  29328. }
  29329. mp_clear(&r);
  29330. mp_clear(&s);
  29331. wc_ecc_free(&ecc);
  29332. (void)count;
  29333. return ret;
  29334. }
  29335. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29336. /*
  29337. * This test doesn't work with WOLFSSL_VALIDATE_ECC_KEYGEN defined because we
  29338. * don't have non-blocking versions of the key checking functions, yet.
  29339. */
  29340. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29341. static wc_test_ret_t ecc_test_nonblock_dhe(int curveId, word32 curveSz,
  29342. const byte* privKey, const byte* pubKey, WC_RNG* rng)
  29343. {
  29344. wc_test_ret_t ret;
  29345. ecc_key keyA;
  29346. ecc_key keyB;
  29347. ecc_nb_ctx_t nbCtxA;
  29348. ecc_nb_ctx_t nbCtxB;
  29349. byte secretA[ECC_SHARED_SIZE];
  29350. byte secretB[ECC_SHARED_SIZE];
  29351. word32 secretSzA = ECC_SHARED_SIZE;
  29352. word32 secretSzB = ECC_SHARED_SIZE;
  29353. int count = 0;
  29354. ret = wc_ecc_init(&keyA);
  29355. if (ret == 0) {
  29356. ret = wc_ecc_init(&keyB);
  29357. if (ret < 0)
  29358. ret = WC_TEST_RET_ENC_EC(ret);
  29359. }
  29360. if (ret == 0) {
  29361. ret = wc_ecc_set_nonblock(&keyA, &nbCtxA);
  29362. if (ret < 0)
  29363. ret = WC_TEST_RET_ENC_EC(ret);
  29364. }
  29365. if (ret == 0) {
  29366. ret = wc_ecc_set_nonblock(&keyB, &nbCtxB);
  29367. if (ret < 0)
  29368. ret = WC_TEST_RET_ENC_EC(ret);
  29369. }
  29370. if (ret == 0) {
  29371. do {
  29372. ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId);
  29373. count++;
  29374. } while (ret == FP_WOULDBLOCK);
  29375. if (ret < 0)
  29376. ret = WC_TEST_RET_ENC_EC(ret);
  29377. }
  29378. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29379. fprintf(stderr, "ECC non-block key gen: %d times\n", count);
  29380. #endif
  29381. if (ret == 0) {
  29382. ret = wc_ecc_check_key(&keyA);
  29383. if (ret < 0)
  29384. ret = WC_TEST_RET_ENC_EC(ret);
  29385. }
  29386. if (ret == 0) {
  29387. ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz,
  29388. privKey, curveId);
  29389. if (ret < 0)
  29390. ret = WC_TEST_RET_ENC_EC(ret);
  29391. }
  29392. count = 0;
  29393. if (ret == 0) {
  29394. do {
  29395. ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA);
  29396. count++;
  29397. } while (ret == FP_WOULDBLOCK);
  29398. if (ret < 0)
  29399. ret = WC_TEST_RET_ENC_EC(ret);
  29400. }
  29401. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29402. fprintf(stderr, "ECC non-block shared secret: %d times\n", count);
  29403. #endif
  29404. if (ret == 0) {
  29405. do {
  29406. ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB);
  29407. } while (ret == FP_WOULDBLOCK);
  29408. if (ret < 0)
  29409. ret = WC_TEST_RET_ENC_EC(ret);
  29410. }
  29411. if (ret == 0) {
  29412. if (secretSzA != secretSzB ||
  29413. XMEMCMP(secretA, secretB, secretSzA) != 0) {
  29414. ret = WC_TEST_RET_ENC_NC;
  29415. }
  29416. }
  29417. wc_ecc_free(&keyA);
  29418. wc_ecc_free(&keyB);
  29419. return ret;
  29420. }
  29421. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29422. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29423. static wc_test_ret_t ecc_test_nonblock_ecdsa(int curveId, word32 curveSz,
  29424. const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz,
  29425. WC_RNG* rng)
  29426. {
  29427. wc_test_ret_t ret = 0;
  29428. byte* sig = NULL;
  29429. word32 sigSz = curveSz * 2;
  29430. static const byte hash[] = {
  29431. 0x8d, 0x28, 0xa3, 0x8b, 0x0b, 0xa9, 0xfe, 0xd4, 0x0e, 0x54, 0xc4, 0x17,
  29432. 0x3d, 0x54, 0x66, 0x34, 0xbf, 0x5d, 0x6f, 0x46, 0xc2, 0x20, 0xcb, 0xc3,
  29433. 0x22, 0xe9, 0xb0, 0xdf, 0xe7, 0x64, 0x3f, 0xd9
  29434. };
  29435. sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29436. if (sig == NULL) {
  29437. ret = WC_TEST_RET_ENC_ERRNO;
  29438. }
  29439. if (ret == 0) {
  29440. /* Sign hash using private key */
  29441. /* Note: result of an ECC sign varies for each call even with same
  29442. private key and hash. This is because a new random public key is
  29443. used for each operation. */
  29444. ret = crypto_ecc_sign(privKey, privKeySz, hash, sizeof(hash), sig,
  29445. &sigSz, curveSz, curveId, rng);
  29446. }
  29447. if (ret == 0) {
  29448. /* Verify generated signature is valid */
  29449. ret = crypto_ecc_verify(pubKey, pubKeySz, hash, sizeof(hash), sig,
  29450. sigSz, curveSz, curveId);
  29451. }
  29452. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29453. return ret;
  29454. }
  29455. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29456. static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng)
  29457. {
  29458. wc_test_ret_t ret = 0;
  29459. word32 i;
  29460. int curveIds[3] = {0, 0, 0};
  29461. word32 curveSzs[3] = {0, 0, 0};
  29462. const byte* privKeys[3] = {NULL, NULL, NULL};
  29463. word32 privKeySzs[3] = {0, 0, 0};
  29464. const byte* pubKeys[3] = {NULL, NULL, NULL};
  29465. word32 pubKeySzs[3] = {0, 0, 0};
  29466. curveIds[0] = ECC_SECP256R1;
  29467. curveSzs[0] = 32;
  29468. privKeys[0] = p256PrivKey;
  29469. privKeySzs[0] = sizeof(p256PrivKey);
  29470. pubKeys[0] = p256PubKey;
  29471. pubKeySzs[0] = sizeof(p256PubKey);
  29472. #ifdef HAVE_ECC384
  29473. curveIds[1] = ECC_SECP384R1;
  29474. curveSzs[1] = 48;
  29475. privKeys[1] = p384PrivKey;
  29476. privKeySzs[1] = sizeof(p384PrivKey);
  29477. pubKeys[1] = p384PubKey;
  29478. pubKeySzs[1] = sizeof(p384PubKey);
  29479. #endif
  29480. #ifdef HAVE_ECC521
  29481. curveIds[2] = ECC_SECP521R1;
  29482. curveSzs[2] = 66;
  29483. privKeys[2] = p521PrivKey;
  29484. privKeySzs[2] = sizeof(p521PrivKey);
  29485. pubKeys[2] = p521PubKey;
  29486. pubKeySzs[2] = sizeof(p521PubKey);
  29487. #endif
  29488. for (i = 0; ret == 0 && i < sizeof(curveIds) / sizeof(curveIds[0]); ++i) {
  29489. if (curveIds[i] == 0) {
  29490. continue;
  29491. }
  29492. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29493. ret = ecc_test_nonblock_ecdsa(curveIds[i], curveSzs[i], privKeys[i],
  29494. privKeySzs[i], pubKeys[i], pubKeySzs[i], rng);
  29495. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29496. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29497. if (ret == 0) {
  29498. ret = ecc_test_nonblock_dhe(curveIds[i], curveSzs[i], privKeys[i],
  29499. pubKeys[i], rng);
  29500. }
  29501. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29502. }
  29503. return ret;
  29504. }
  29505. #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */
  29506. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29507. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29508. (HAVE_FIPS_VERSION > 2)))
  29509. static int ecc_test_raw_enc_dec(void)
  29510. {
  29511. int ret;
  29512. unsigned char r[1];
  29513. word32 rSz;
  29514. unsigned char s[1];
  29515. word32 sSz;
  29516. unsigned char rZero[] = { 0, 0, 0, 0 };
  29517. unsigned char sOne[] = { 0, 0, 1 };
  29518. unsigned char sigRaw[32];
  29519. word32 sigRawSz;
  29520. unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 };
  29521. sigRawSz = sizeof(sigRaw);
  29522. ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne),
  29523. sigRaw, &sigRawSz);
  29524. if (ret != 0) {
  29525. return WC_TEST_RET_ENC_EC(ret);
  29526. }
  29527. if (sigRawSz != sizeof(expSig)) {
  29528. return WC_TEST_RET_ENC_EC((int)sigRawSz);
  29529. }
  29530. if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) {
  29531. return WC_TEST_RET_ENC_NC;
  29532. }
  29533. rSz = sizeof(r);
  29534. sSz = sizeof(s);
  29535. ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz);
  29536. if (ret != 0) {
  29537. return WC_TEST_RET_ENC_EC(ret);
  29538. }
  29539. if (rSz != 1) {
  29540. return WC_TEST_RET_ENC_EC((int)rSz);
  29541. }
  29542. if (sSz != 1) {
  29543. return WC_TEST_RET_ENC_EC((int)sSz);
  29544. }
  29545. if (r[0] != 0) {
  29546. return WC_TEST_RET_ENC_EC(r[0]);
  29547. }
  29548. if (s[0] != 1) {
  29549. return WC_TEST_RET_ENC_EC(s[0]);
  29550. }
  29551. return ret;
  29552. }
  29553. #endif
  29554. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void)
  29555. {
  29556. wc_test_ret_t ret;
  29557. WC_RNG rng;
  29558. WOLFSSL_ENTER("ecc_test");
  29559. #if defined(ECC_MIN_KEY_SZ)
  29560. WOLFSSL_MSG_EX("ecc_test ECC_MIN_KEY_SZ = %d\n", ECC_MIN_KEY_SZ);
  29561. #else
  29562. WOLFSSL_MSG("ecc_test ECC_MIN_KEY_SZ not defined.");
  29563. #endif
  29564. #if defined(WOLFSSL_CERT_EXT) && \
  29565. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29566. ret = ecc_decode_test();
  29567. if (ret < 0)
  29568. return ret;
  29569. #endif
  29570. #ifndef HAVE_FIPS
  29571. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  29572. #else
  29573. ret = wc_InitRng(&rng);
  29574. #endif
  29575. #ifndef WC_NO_RNG
  29576. if (ret != 0)
  29577. return WC_TEST_RET_ENC_EC(ret);
  29578. #else
  29579. (void)ret;
  29580. #endif
  29581. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  29582. ret = ecc_test_curve(&rng, 14, ECC_CURVE_DEF);
  29583. if (ret < 0) {
  29584. printf("keySize=14, Default\n");
  29585. goto done;
  29586. }
  29587. #endif /* HAVE_ECC112 */
  29588. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  29589. ret = ecc_test_curve(&rng, 16, ECC_CURVE_DEF);
  29590. if (ret < 0) {
  29591. printf("keySize=16, Default\n");
  29592. goto done;
  29593. }
  29594. #endif /* HAVE_ECC128 */
  29595. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  29596. ret = ecc_test_curve(&rng, 20, ECC_CURVE_DEF);
  29597. if (ret < 0) {
  29598. printf("keySize=20, Default\n");
  29599. goto done;
  29600. }
  29601. #endif /* HAVE_ECC160 */
  29602. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  29603. #if !FIPS_VERSION3_GE(6,0,0)
  29604. ret = ecc_test_curve(&rng, 24, ECC_CURVE_DEF);
  29605. if (ret < 0) {
  29606. printf("keySize=24, Default\n");
  29607. goto done;
  29608. }
  29609. #endif
  29610. #endif /* HAVE_ECC192 */
  29611. #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224
  29612. ret = ecc_test_curve(&rng, 28, ECC_CURVE_DEF);
  29613. if (ret < 0) {
  29614. printf("keySize=28, Default\n");
  29615. goto done;
  29616. }
  29617. #endif /* HAVE_ECC224 */
  29618. #if (defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 239
  29619. ret = ecc_test_curve(&rng, 30, ECC_CURVE_DEF);
  29620. if (ret < 0) {
  29621. printf("keySize=30, Default\n");
  29622. goto done;
  29623. }
  29624. #endif /* HAVE_ECC239 */
  29625. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29626. ret = ecc_test_curve(&rng, 32, ECC_CURVE_DEF);
  29627. if (ret < 0) {
  29628. printf("keySize=32, Default\n");
  29629. goto done;
  29630. }
  29631. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29632. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  29633. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  29634. ret = ecc_point_test();
  29635. if (ret < 0) {
  29636. goto done;
  29637. }
  29638. #endif
  29639. #if !defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES)
  29640. ret = ecc_def_curve_test(&rng);
  29641. if (ret < 0) {
  29642. printf("Default\n");
  29643. goto done;
  29644. }
  29645. #endif
  29646. #endif /* !NO_ECC256 */
  29647. #if (defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 320
  29648. ret = ecc_test_curve(&rng, 40, ECC_CURVE_DEF);
  29649. if (ret < 0) {
  29650. printf("keySize=40, Default\n");
  29651. goto done;
  29652. }
  29653. #endif /* HAVE_ECC320 */
  29654. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  29655. ret = ecc_test_curve(&rng, 48, ECC_CURVE_DEF);
  29656. if (ret < 0) {
  29657. printf("keySize=48, Default\n");
  29658. goto done;
  29659. }
  29660. #endif /* HAVE_ECC384 */
  29661. #if (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 512
  29662. ret = ecc_test_curve(&rng, 64, ECC_CURVE_DEF);
  29663. if (ret < 0) {
  29664. printf("keySize=64, Default\n");
  29665. goto done;
  29666. }
  29667. #endif /* HAVE_ECC512 */
  29668. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  29669. ret = ecc_test_curve(&rng, 66, ECC_CURVE_DEF);
  29670. if (ret < 0) {
  29671. printf("keySize=66, Default\n");
  29672. goto done;
  29673. }
  29674. #endif /* HAVE_ECC521 */
  29675. #ifdef WOLFSSL_SM2
  29676. ret = ecc_test_curve(&rng, 32, ECC_SM2P256V1);
  29677. if (ret < 0) {
  29678. printf("SM2\n");
  29679. goto done;
  29680. }
  29681. #endif
  29682. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29683. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29684. (HAVE_FIPS_VERSION > 2)))
  29685. ret = ecc_test_raw_enc_dec();
  29686. if (ret != 0) {
  29687. printf("raw sig encode/decode\n");
  29688. goto done;
  29689. }
  29690. #endif
  29691. #if defined(WOLFSSL_CUSTOM_CURVES)
  29692. ret = ecc_test_custom_curves(&rng);
  29693. if (ret != 0) {
  29694. printf("Custom\n");
  29695. goto done;
  29696. }
  29697. #endif
  29698. #if defined(WOLFSSL_SM2)
  29699. ret = test_sm2_verify();
  29700. if (ret != 0) {
  29701. printf("SM2 Verify\n");
  29702. goto done;
  29703. }
  29704. ret = ecc_sm2_test_curve(&rng, ECC_TEST_VERIFY_COUNT);
  29705. if (ret != 0) {
  29706. printf("SM2 test\n");
  29707. goto done;
  29708. }
  29709. #endif
  29710. #if defined(HAVE_ECC_SIGN) && \
  29711. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  29712. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  29713. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  29714. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29715. ret = ecc_test_deterministic_k(&rng);
  29716. if (ret != 0) {
  29717. printf("ecc_test_deterministic_k failed!\n");
  29718. goto done;
  29719. }
  29720. #endif
  29721. #ifdef WOLFSSL_PUBLIC_MP
  29722. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  29723. ECC_MIN_KEY_SZ <= 384
  29724. ret = ecc384_test_deterministic_k(&rng);
  29725. if (ret != 0) {
  29726. printf("ecc384_test_deterministic_k failed!\n");
  29727. goto done;
  29728. }
  29729. #endif
  29730. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && \
  29731. ECC_MIN_KEY_SZ <= 521
  29732. ret = ecc521_test_deterministic_k(&rng);
  29733. if (ret != 0) {
  29734. printf("ecc512_test_deterministic_k failed!\n");
  29735. goto done;
  29736. }
  29737. #endif
  29738. #endif
  29739. #endif
  29740. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  29741. !defined(WOLFSSL_KCAPI_ECC)
  29742. ret = ecc_test_sign_vectors(&rng);
  29743. if (ret != 0) {
  29744. printf("ecc_test_sign_vectors failed!\n");
  29745. goto done;
  29746. }
  29747. #endif
  29748. #if defined(HAVE_ECC_VECTOR_TEST) && defined(HAVE_ECC_CDH) && \
  29749. defined(HAVE_ECC_DHE)
  29750. ret = ecc_test_cdh_vectors(&rng);
  29751. if (ret != 0) {
  29752. printf("ecc_test_cdh_vectors failed!\n");
  29753. goto done;
  29754. }
  29755. #endif
  29756. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29757. !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
  29758. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  29759. ret = ecc_test_make_pub(&rng);
  29760. if (ret != 0) {
  29761. printf("ecc_test_make_pub failed!\n");
  29762. goto done;
  29763. }
  29764. #elif defined(HAVE_ECC_KEY_IMPORT)
  29765. (void)ecc_test_make_pub; /* for compiler warning */
  29766. #endif
  29767. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && !defined(NO_ASN_TIME)
  29768. ret = ecc_test_cert_gen(&rng);
  29769. if (ret != 0) {
  29770. printf("ecc_test_cert_gen failed!\n");
  29771. goto done;
  29772. }
  29773. #endif
  29774. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) && \
  29775. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && (!defined(NO_ECC_SECP) || \
  29776. defined(WOLFSSL_CUSTOM_CURVES))
  29777. ret = ecc_test_allocator(&rng);
  29778. if (ret != 0) {
  29779. printf("ecc_test_allocator failed!\n");
  29780. goto done;
  29781. }
  29782. #endif
  29783. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  29784. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29785. ret = ecc_test_nonblock(&rng);
  29786. if (ret != 0) {
  29787. printf("ecc_test_nonblock failed!\n");
  29788. goto done;
  29789. }
  29790. #endif
  29791. done:
  29792. wc_FreeRng(&rng);
  29793. return ret;
  29794. }
  29795. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  29796. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  29797. #if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3))
  29798. static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
  29799. {
  29800. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29801. byte* plaintext;
  29802. byte* encrypted;
  29803. byte* decrypted;
  29804. #else
  29805. byte plaintext[128];
  29806. byte encrypted[128];
  29807. byte decrypted[128];
  29808. #endif
  29809. ecEncCtx* aCtx = NULL;
  29810. ecEncCtx* bCtx = NULL;
  29811. static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  29812. 14, 15};
  29813. wc_test_ret_t ret = 0;
  29814. static const char message[] = "Hello wolfSSL!";
  29815. word32 plaintextLen;
  29816. word32 encryptLen = 128;
  29817. word32 decryptLen = 128;
  29818. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29819. plaintext = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29820. encrypted = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29821. decrypted = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29822. #endif
  29823. wc_ecc_free(a);
  29824. wc_ecc_free(b);
  29825. ret = wc_ecc_init(a);
  29826. if (ret != 0)
  29827. ret = WC_TEST_RET_ENC_EC(ret);
  29828. if (ret == 0) {
  29829. ret = wc_ecc_init(b);
  29830. if (ret != 0)
  29831. ret = WC_TEST_RET_ENC_EC(ret);
  29832. }
  29833. if (ret == 0)
  29834. ret = wc_ecc_make_key(rng, 32, a);
  29835. if (ret == 0)
  29836. ret = wc_ecc_make_key(rng, 32, b);
  29837. /* create context */
  29838. if (ret == 0) {
  29839. aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  29840. if (aCtx == NULL)
  29841. ret = WC_TEST_RET_ENC_NC;
  29842. }
  29843. if (ret == 0) {
  29844. bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  29845. if (bCtx == NULL)
  29846. ret = WC_TEST_RET_ENC_NC;
  29847. }
  29848. /* set salt */
  29849. if (ret == 0) {
  29850. ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt));
  29851. if (ret != 0)
  29852. ret = 10472;
  29853. }
  29854. if (ret == 0) {
  29855. ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt));
  29856. if (ret != 0)
  29857. ret = 10473;
  29858. }
  29859. XMEMSET(plaintext, 0, 128);
  29860. XSTRLCPY((char *)plaintext, message, sizeof plaintext);
  29861. plaintextLen = (((word32)XSTRLEN(message) + AES_BLOCK_SIZE - 1) /
  29862. AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
  29863. /* encrypt */
  29864. if (ret == 0) {
  29865. ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted,
  29866. &encryptLen, aCtx);
  29867. if (ret != 0)
  29868. ret = WC_TEST_RET_ENC_EC(ret);
  29869. }
  29870. /* decrypt */
  29871. if (ret == 0) {
  29872. ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted,
  29873. &decryptLen, bCtx);
  29874. if (ret != 0)
  29875. ret = WC_TEST_RET_ENC_EC(ret);
  29876. }
  29877. /* compare */
  29878. if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
  29879. ret = WC_TEST_RET_ENC_NC;
  29880. wc_ecc_free(a);
  29881. wc_ecc_free(b);
  29882. wc_ecc_ctx_free(aCtx);
  29883. wc_ecc_ctx_free(bCtx);
  29884. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29885. XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29886. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29887. XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29888. #endif
  29889. return ret;
  29890. }
  29891. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  29892. /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in
  29893. * wolfFIPS 5.3.
  29894. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test().
  29895. */
  29896. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  29897. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  29898. ECC_MIN_KEY_SZ <= 256 && defined(WOLFSSL_AES_128)
  29899. static wc_test_ret_t ecc_encrypt_kat(WC_RNG *rng)
  29900. {
  29901. wc_test_ret_t ret = 0;
  29902. #ifdef WOLFSSL_ECIES_OLD
  29903. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29904. ecc_key* userA = NULL;
  29905. #else
  29906. ecc_key userA[1];
  29907. #endif
  29908. int userAInit = 0;
  29909. #endif
  29910. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29911. ecc_key* userB = NULL;
  29912. #else
  29913. ecc_key userB[1];
  29914. #endif
  29915. int userBInit = 0;
  29916. ecc_key* tmpKey;
  29917. byte plain[48];
  29918. word32 plainSz = sizeof(plain);
  29919. WOLFSSL_SMALL_STACK_STATIC const byte privKey[] = {
  29920. 0x04, 0x80, 0xef, 0x1d, 0xbe, 0x02, 0x0c, 0x20,
  29921. 0x5b, 0xab, 0x80, 0x35, 0x5b, 0x2a, 0x0f, 0x6d,
  29922. 0xd3, 0xb0, 0x7f, 0x7e, 0x7f, 0x86, 0x8a, 0x49,
  29923. 0xee, 0xb4, 0xaa, 0x09, 0x2d, 0x1e, 0x1d, 0x02
  29924. };
  29925. #if defined(WOLFSSL_ECIES_OLD) || defined(WOLFSSL_QNX_CAAM)
  29926. WOLFSSL_SMALL_STACK_STATIC const byte pubKey[] = {
  29927. 0x04,
  29928. /* X */
  29929. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  29930. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  29931. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  29932. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  29933. /* X */
  29934. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  29935. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  29936. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  29937. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28
  29938. };
  29939. #endif
  29940. WOLFSSL_SMALL_STACK_STATIC const byte enc_msg[] = {
  29941. #ifdef WOLFSSL_ECIES_OLD
  29942. 0x42, 0x70, 0xbf, 0xf9, 0xf4, 0x7e, 0x4b, 0x9b,
  29943. 0xb5, 0x4c, 0xcc, 0xc5, 0x94, 0xa7, 0xef, 0xaa,
  29944. 0xc3, 0x7c, 0x85, 0xa6, 0x51, 0x6e, 0xd3, 0xfa,
  29945. 0x56, 0xc9, 0x10, 0x4d, 0x14, 0x32, 0x61, 0xb8,
  29946. 0xbb, 0x66, 0x7a, 0xb5, 0xbc, 0x95, 0xf8, 0xca,
  29947. 0xd1, 0x2a, 0x19, 0x51, 0x44, 0xd8, 0x0e, 0x57,
  29948. 0x34, 0xed, 0x45, 0x89, 0x2e, 0x57, 0xbe, 0xd5,
  29949. 0x06, 0x22, 0xd7, 0x13, 0x0a, 0x0e, 0x40, 0x36,
  29950. 0x0d, 0x05, 0x0d, 0xb6, 0xae, 0x61, 0x37, 0x18,
  29951. 0x83, 0x90, 0x0a, 0x27, 0x95, 0x41, 0x8c, 0x45
  29952. #elif defined(WOLFSSL_ECIES_ISO18033)
  29953. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  29954. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  29955. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  29956. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  29957. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  29958. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  29959. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  29960. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  29961. 0x28, 0xbb, 0x9f, 0xa8, 0x2d, 0xe1, 0xf1, 0x67,
  29962. 0x45, 0x02, 0x19, 0xdc, 0xc8, 0x24, 0x8b, 0x20,
  29963. 0x02, 0xa0, 0x8f, 0x95, 0x12, 0x55, 0x51, 0xf8,
  29964. 0x03, 0xc4, 0x54, 0x13, 0x98, 0x2d, 0xf0, 0x31,
  29965. 0x51, 0x80, 0x45, 0x24, 0xcb, 0x8b, 0x48, 0xa6,
  29966. 0x8b, 0x8e, 0x97, 0x9c, 0x56, 0x4d, 0x70, 0x00,
  29967. 0x53, 0xd3, 0x47, 0x00, 0x5a, 0x23, 0x8c, 0xf9,
  29968. 0xfd, 0xd2, 0x33, 0x2c, 0x43, 0x6e, 0x9e, 0xb2,
  29969. 0xf4, 0x95, 0xd4, 0xcf, 0x30, 0xd6, 0xa2, 0xc5,
  29970. 0x35, 0x96, 0x6a, 0xd4, 0x36, 0x15, 0xa9, 0xbd,
  29971. 0x7f
  29972. #elif defined(WOLFSSL_ECIES_GEN_IV)
  29973. /* EC P-256 point */
  29974. 0x04,
  29975. /* X */
  29976. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  29977. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  29978. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  29979. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  29980. /* Y */
  29981. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  29982. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  29983. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  29984. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28,
  29985. /* IV */
  29986. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  29987. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  29988. /* Encrypted Msg */
  29989. 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d, 0x50,
  29990. 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c, 0x1f,
  29991. 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc, 0x44,
  29992. 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca, 0x65,
  29993. 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61, 0xbd,
  29994. 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1, 0xde,
  29995. /* HMAC */
  29996. 0x5a, 0x22, 0xc1, 0x5d, 0x99, 0x66, 0x3f, 0x24,
  29997. 0x35, 0x96, 0xac, 0xf7, 0xf6, 0x28, 0x45, 0x16,
  29998. 0x52, 0x19, 0x0d, 0xe4, 0xb2, 0xca, 0x5b, 0x28,
  29999. 0x4e, 0xbb, 0xf3, 0x98, 0x57, 0xd7, 0x3b, 0xe2
  30000. #else
  30001. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30002. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30003. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30004. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30005. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30006. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30007. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30008. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30009. 0x28, 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d,
  30010. 0x50, 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c,
  30011. 0x1f, 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc,
  30012. 0x44, 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca,
  30013. 0x65, 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61,
  30014. 0xbd, 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1,
  30015. 0xde, 0xc7, 0x3f, 0x6f, 0xce, 0xbe, 0x49, 0x61,
  30016. 0x48, 0x01, 0x77, 0x41, 0xd0, 0xd8, 0x5b, 0x48,
  30017. 0xca, 0x4e, 0x47, 0x3e, 0x47, 0xbf, 0x1d, 0x28,
  30018. 0x4c, 0x18, 0x1a, 0xfb, 0x96, 0x95, 0xda, 0xde,
  30019. 0x55
  30020. #endif
  30021. };
  30022. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  30023. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  30024. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  30025. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  30026. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  30027. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  30028. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  30029. };
  30030. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30031. userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT,
  30032. DYNAMIC_TYPE_TMP_BUFFER);
  30033. if (userB == NULL) {
  30034. ret = WC_TEST_RET_ENC_ERRNO;
  30035. }
  30036. #ifdef WOLFSSL_ECIES_OLD
  30037. if (ret == 0) {
  30038. userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT,
  30039. DYNAMIC_TYPE_TMP_BUFFER);
  30040. if (userA == NULL) {
  30041. ret = WC_TEST_RET_ENC_ERRNO;
  30042. }
  30043. }
  30044. #endif
  30045. #endif
  30046. if (ret == 0) {
  30047. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30048. if (ret != 0)
  30049. ret = WC_TEST_RET_ENC_EC(ret);
  30050. }
  30051. if (ret == 0) {
  30052. userBInit = 1;
  30053. #ifdef WOLFSSL_ECIES_OLD
  30054. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30055. if (ret != 0)
  30056. ret = WC_TEST_RET_ENC_EC(ret);
  30057. }
  30058. if (ret == 0) {
  30059. userAInit = 1;
  30060. tmpKey = userA;
  30061. #else
  30062. tmpKey = NULL;
  30063. #endif
  30064. }
  30065. if (ret == 0) {
  30066. #ifdef WOLFSSL_QNX_CAAM
  30067. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), pubKey,
  30068. sizeof(pubKey), userB, ECC_SECP256R1);
  30069. #else
  30070. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), NULL, 0,
  30071. userB, ECC_SECP256R1);
  30072. #endif
  30073. if (ret != 0)
  30074. ret = WC_TEST_RET_ENC_EC(ret);
  30075. }
  30076. #ifdef WOLFSSL_ECIES_OLD
  30077. if (ret == 0) {
  30078. ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA,
  30079. ECC_SECP256R1);
  30080. if (ret != 0)
  30081. ret = WC_TEST_RET_ENC_EC(ret);
  30082. }
  30083. #endif
  30084. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30085. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30086. !defined(HAVE_SELFTEST)
  30087. if (ret == 0) {
  30088. ret = wc_ecc_set_rng(userB, rng);
  30089. if (ret != 0) {
  30090. ret = WC_TEST_RET_ENC_EC(ret);
  30091. }
  30092. }
  30093. #else
  30094. (void)rng;
  30095. #endif
  30096. if (ret == 0) {
  30097. ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain,
  30098. &plainSz, NULL);
  30099. if (ret != 0)
  30100. ret = WC_TEST_RET_ENC_EC(ret);
  30101. }
  30102. if (ret == 0) {
  30103. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30104. ret = WC_TEST_RET_ENC_NC;
  30105. }
  30106. }
  30107. if (userBInit)
  30108. wc_ecc_free(userB);
  30109. #ifdef WOLFSSL_ECIES_OLD
  30110. if (userAInit)
  30111. wc_ecc_free(userA);
  30112. #endif
  30113. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30114. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30115. #ifdef WOLFSSL_ECIES_OLD
  30116. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30117. #endif
  30118. #endif
  30119. return ret;
  30120. }
  30121. #endif
  30122. static wc_test_ret_t ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB,
  30123. byte encAlgo, byte kdfAlgo, byte macAlgo)
  30124. {
  30125. wc_test_ret_t ret = 0;
  30126. byte msg[48];
  30127. byte plain[48];
  30128. #ifdef WOLFSSL_ECIES_OLD
  30129. byte out[80];
  30130. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30131. byte out[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30132. #else
  30133. byte out[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30134. #endif
  30135. word32 outSz = sizeof(out);
  30136. word32 plainSz = sizeof(plain);
  30137. int i;
  30138. ecEncCtx* cliCtx = NULL;
  30139. ecEncCtx* srvCtx = NULL;
  30140. byte cliSalt[EXCHANGE_SALT_SZ];
  30141. byte srvSalt[EXCHANGE_SALT_SZ];
  30142. const byte* tmpSalt;
  30143. byte msg2[48];
  30144. byte plain2[48];
  30145. #ifdef WOLFSSL_ECIES_OLD
  30146. byte out2[80];
  30147. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30148. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30149. #else
  30150. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30151. #endif
  30152. word32 outSz2 = sizeof(out2);
  30153. word32 plainSz2 = sizeof(plain2);
  30154. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30155. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof(ecc_key), HEAP_HINT,
  30156. DYNAMIC_TYPE_TMP_BUFFER);
  30157. #else
  30158. ecc_key tmpKey[1];
  30159. #endif
  30160. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30161. if (tmpKey == NULL) {
  30162. ERROR_OUT(MEMORY_E, done);
  30163. }
  30164. #endif
  30165. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30166. if (ret != 0)
  30167. goto done;
  30168. /* set message to incrementing 0,1,2,etc... */
  30169. for (i = 0; i < (int)sizeof(msg); i++)
  30170. msg[i] = i;
  30171. /* encrypt msg to B */
  30172. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL);
  30173. if (ret != 0) {
  30174. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30175. }
  30176. #ifdef WOLFSSL_ECIES_OLD
  30177. tmpKey->dp = userA->dp;
  30178. ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey);
  30179. if (ret != 0) {
  30180. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30181. }
  30182. #endif
  30183. /* decrypt msg from A */
  30184. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL);
  30185. if (ret != 0) {
  30186. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30187. }
  30188. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30189. ret = WC_TEST_RET_ENC_NC; goto done;
  30190. }
  30191. #ifndef WOLFSSL_ECIES_OLD
  30192. /* A decrypts msg (response) from B */
  30193. ret = wc_ecc_decrypt(userB, NULL, out, outSz, plain2, &plainSz2, NULL);
  30194. if (ret != 0)
  30195. goto done;
  30196. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30197. ret = WC_TEST_RET_ENC_NC; goto done;
  30198. }
  30199. #endif
  30200. /* let's verify message exchange works, A is client, B is server */
  30201. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30202. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30203. if (cliCtx == NULL || srvCtx == NULL) {
  30204. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30205. }
  30206. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30207. if (ret != 0)
  30208. goto done;
  30209. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30210. if (ret != 0)
  30211. goto done;
  30212. /* get salt to send to peer */
  30213. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30214. if (tmpSalt == NULL) {
  30215. ret = WC_TEST_RET_ENC_NC; goto done;
  30216. }
  30217. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30218. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30219. if (tmpSalt == NULL) {
  30220. ret = WC_TEST_RET_ENC_NC; goto done;
  30221. }
  30222. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30223. /* in actual use, we'd get the peer's salt over the transport */
  30224. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30225. if (ret != 0)
  30226. goto done;
  30227. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30228. if (ret != 0)
  30229. goto done;
  30230. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 11);
  30231. if (ret != 0)
  30232. goto done;
  30233. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 11);
  30234. if (ret != 0)
  30235. goto done;
  30236. /* get encrypted msg (request) to send to B */
  30237. outSz = sizeof(out);
  30238. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz,cliCtx);
  30239. if (ret != 0)
  30240. goto done;
  30241. #ifndef WOLFSSL_ECIES_OLD
  30242. wc_ecc_free(tmpKey);
  30243. #endif
  30244. /* B decrypts msg (request) from A */
  30245. plainSz = sizeof(plain);
  30246. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30247. if (ret != 0)
  30248. goto done;
  30249. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30250. ret = WC_TEST_RET_ENC_NC; goto done;
  30251. }
  30252. /* msg2 (response) from B to A */
  30253. for (i = 0; i < (int)sizeof(msg2); i++)
  30254. msg2[i] = i + sizeof(msg2);
  30255. /* get encrypted msg (response) to send to B */
  30256. ret = wc_ecc_encrypt(userB, userA, msg2, sizeof(msg2), out2,
  30257. &outSz2, srvCtx);
  30258. if (ret != 0)
  30259. goto done;
  30260. #ifdef WOLFSSL_ECIES_OLD
  30261. tmpKey->dp = userB->dp;
  30262. ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey);
  30263. if (ret != 0) {
  30264. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30265. }
  30266. #else
  30267. wc_ecc_free(tmpKey);
  30268. #endif
  30269. /* A decrypts msg (response) from B */
  30270. ret = wc_ecc_decrypt(userA, tmpKey, out2, outSz2, plain2, &plainSz2,
  30271. cliCtx);
  30272. if (ret != 0)
  30273. goto done;
  30274. if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) {
  30275. ret = WC_TEST_RET_ENC_NC; goto done;
  30276. }
  30277. #if defined(HAVE_COMP_KEY) && \
  30278. (! defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  30279. /* Create new client and server contexts. */
  30280. wc_ecc_ctx_free(srvCtx);
  30281. wc_ecc_ctx_free(cliCtx);
  30282. /* let's verify message exchange works, A is client, B is server */
  30283. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30284. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30285. if (cliCtx == NULL || srvCtx == NULL) {
  30286. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30287. }
  30288. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30289. if (ret != 0)
  30290. goto done;
  30291. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30292. if (ret != 0)
  30293. goto done;
  30294. /* get salt to send to peer */
  30295. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30296. if (tmpSalt == NULL) {
  30297. ret = WC_TEST_RET_ENC_NC; goto done;
  30298. }
  30299. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30300. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30301. if (tmpSalt == NULL) {
  30302. ret = WC_TEST_RET_ENC_NC; goto done;
  30303. }
  30304. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30305. /* in actual use, we'd get the peer's salt over the transport */
  30306. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30307. if (ret != 0)
  30308. goto done;
  30309. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30310. if (ret != 0)
  30311. goto done;
  30312. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 12);
  30313. if (ret != 0)
  30314. goto done;
  30315. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 12);
  30316. if (ret != 0)
  30317. goto done;
  30318. /* get encrypted msg (request) to send to B - compressed public key */
  30319. outSz = sizeof(out);
  30320. ret = wc_ecc_encrypt_ex(userA, userB, msg, sizeof(msg), out, &outSz, cliCtx,
  30321. 1);
  30322. if (ret != 0)
  30323. goto done;
  30324. #ifndef WOLFSSL_ECIES_OLD
  30325. wc_ecc_free(tmpKey);
  30326. #endif
  30327. /* B decrypts msg (request) from A - out has a compressed public key */
  30328. plainSz = sizeof(plain);
  30329. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30330. if (ret != 0)
  30331. goto done;
  30332. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30333. ret = WC_TEST_RET_ENC_NC; goto done;
  30334. }
  30335. #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */
  30336. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30337. (ECC_MIN_KEY_SZ <= 256) && defined(WOLFSSL_AES_128)
  30338. ret = ecc_encrypt_kat(rng);
  30339. #endif
  30340. done:
  30341. /* cleanup */
  30342. wc_ecc_ctx_free(srvCtx);
  30343. wc_ecc_ctx_free(cliCtx);
  30344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30345. if (tmpKey != NULL) {
  30346. wc_ecc_free(tmpKey);
  30347. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30348. }
  30349. #else
  30350. wc_ecc_free(tmpKey);
  30351. #endif
  30352. return ret;
  30353. }
  30354. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30355. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void)
  30356. {
  30357. WC_RNG rng;
  30358. wc_test_ret_t ret;
  30359. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30360. ecc_key *userA;
  30361. ecc_key *userB;
  30362. #else
  30363. ecc_key userA[1];
  30364. ecc_key userB[1];
  30365. #endif
  30366. WOLFSSL_ENTER("ecc_encrypt_test");
  30367. #ifndef HAVE_FIPS
  30368. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30369. #else
  30370. ret = wc_InitRng(&rng);
  30371. #endif
  30372. if (ret != 0)
  30373. return WC_TEST_RET_ENC_EC(ret);
  30374. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30375. userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT,
  30376. DYNAMIC_TYPE_TMP_BUFFER);
  30377. userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT,
  30378. DYNAMIC_TYPE_TMP_BUFFER);
  30379. if ((userA == NULL) || (userB == NULL)) {
  30380. ERROR_OUT(MEMORY_E, done);
  30381. }
  30382. #endif
  30383. XMEMSET(userA, 0, sizeof *userA);
  30384. XMEMSET(userB, 0, sizeof *userB);
  30385. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30386. if (ret != 0)
  30387. goto done;
  30388. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30389. if (ret != 0)
  30390. goto done;
  30391. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userA);
  30392. #if defined(WOLFSSL_ASYNC_CRYPT)
  30393. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  30394. #endif
  30395. if (ret != 0){
  30396. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30397. }
  30398. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB);
  30399. #if defined(WOLFSSL_ASYNC_CRYPT)
  30400. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  30401. #endif
  30402. if (ret != 0){
  30403. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30404. }
  30405. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30406. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30407. !defined(HAVE_SELFTEST)
  30408. ret = wc_ecc_set_rng(userA, &rng);
  30409. if (ret != 0) {
  30410. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30411. }
  30412. ret = wc_ecc_set_rng(userB, &rng);
  30413. if (ret != 0) {
  30414. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30415. }
  30416. #endif
  30417. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30418. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  30419. #ifdef WOLFSSL_AES_128
  30420. if (ret == 0) {
  30421. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30422. ecHKDF_SHA256, ecHMAC_SHA256);
  30423. if (ret != 0) {
  30424. printf("ECIES: AES_128_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30425. }
  30426. }
  30427. #ifdef HAVE_X963_KDF
  30428. if (ret == 0) {
  30429. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30430. ecKDF_X963_SHA256, ecHMAC_SHA256);
  30431. if (ret != 0) {
  30432. printf("ECIES: AES_128_CBC, KDF_X963_SHA256, HMAC_SHA256\n");
  30433. }
  30434. }
  30435. if (ret == 0) {
  30436. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30437. ecKDF_SHA256, ecHMAC_SHA256);
  30438. if (ret != 0) {
  30439. printf("ECIES: AES_128_CBC, KDF_SHA256, HMAC_SHA256\n");
  30440. }
  30441. }
  30442. #endif
  30443. #endif
  30444. #ifdef WOLFSSL_AES_256
  30445. if (ret == 0) {
  30446. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CBC,
  30447. ecHKDF_SHA256, ecHMAC_SHA256);
  30448. if (ret != 0) {
  30449. printf("ECIES: AES_256_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30450. }
  30451. }
  30452. #endif
  30453. #endif
  30454. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
  30455. #ifdef WOLFSSL_AES_128
  30456. if (ret == 0) {
  30457. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CTR,
  30458. ecHKDF_SHA256, ecHMAC_SHA256);
  30459. if (ret != 0) {
  30460. printf("ECIES: AES_128_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30461. }
  30462. }
  30463. #endif
  30464. #ifdef WOLFSSL_AES_256
  30465. if (ret == 0) {
  30466. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CTR,
  30467. ecHKDF_SHA256, ecHMAC_SHA256);
  30468. if (ret != 0) {
  30469. printf("ECIES: AES_256_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30470. }
  30471. }
  30472. #endif
  30473. #endif /* !NO_AES && WOLFSSL_AES_COUNTER */
  30474. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  30475. if (ret == 0) {
  30476. ret = ecc_ctx_kdf_salt_test(&rng, userA, userB);
  30477. }
  30478. #endif
  30479. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30480. done:
  30481. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30482. if (userA != NULL) {
  30483. wc_ecc_free(userA);
  30484. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30485. }
  30486. if (userB != NULL) {
  30487. wc_ecc_free(userB);
  30488. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30489. }
  30490. #else
  30491. wc_ecc_free(userB);
  30492. wc_ecc_free(userA);
  30493. #endif
  30494. wc_FreeRng(&rng);
  30495. return ret;
  30496. }
  30497. #endif /* HAVE_ECC_ENCRYPT && HAVE_AES_CBC && WOLFSSL_AES_128 */
  30498. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  30499. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  30500. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  30501. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  30502. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void)
  30503. {
  30504. size_t bytes;
  30505. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30506. ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30507. ecc_key *servKey = (ecc_key *)XMALLOC(sizeof *servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30508. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof *tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30509. #else
  30510. ecc_key cliKey[1];
  30511. ecc_key servKey[1];
  30512. ecc_key tmpKey[1];
  30513. #endif
  30514. WC_RNG rng;
  30515. word32 idx = 0;
  30516. wc_test_ret_t ret;
  30517. /* pad our test message to 32 bytes so evenly divisible by AES_BLOCK_SZ */
  30518. byte in[] = "Everyone gets Friday off. ecc p";
  30519. word32 inLen = (word32)XSTRLEN((char*)in);
  30520. byte out[256];
  30521. byte plain[256];
  30522. int verify = 0;
  30523. word32 x;
  30524. WOLFSSL_ENTER("ecc_test_buffers");
  30525. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30526. if ((cliKey == NULL) || (servKey == NULL) || (tmpKey == NULL))
  30527. ERROR_OUT(MEMORY_E, done);
  30528. #endif
  30529. ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId);
  30530. if (ret != 0)
  30531. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30532. ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId);
  30533. if (ret != 0)
  30534. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30535. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30536. if (ret != 0)
  30537. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30538. bytes = (size_t)sizeof_ecc_clikey_der_256;
  30539. /* place client key into ecc_key struct cliKey */
  30540. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey,
  30541. (word32)bytes);
  30542. if (ret != 0)
  30543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30544. idx = 0;
  30545. bytes = (size_t)sizeof_ecc_key_der_256;
  30546. /* place server key into ecc_key struct servKey */
  30547. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey,
  30548. (word32)bytes);
  30549. if (ret != 0)
  30550. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30551. #ifndef WC_NO_RNG
  30552. #ifndef HAVE_FIPS
  30553. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30554. #else
  30555. ret = wc_InitRng(&rng);
  30556. #endif
  30557. if (ret != 0)
  30558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30559. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30560. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30561. !defined(HAVE_SELFTEST)
  30562. ret = wc_ecc_set_rng(cliKey, &rng);
  30563. if (ret != 0)
  30564. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30565. ret = wc_ecc_set_rng(servKey, &rng);
  30566. if (ret != 0)
  30567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30568. #endif
  30569. #endif /* !WC_NO_RNG */
  30570. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_HKDF) && \
  30571. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  30572. {
  30573. word32 y;
  30574. /* test encrypt and decrypt if they're available */
  30575. x = sizeof(out);
  30576. ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL);
  30577. if (ret < 0)
  30578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30579. #ifdef WOLFSSL_ECIES_OLD
  30580. tmpKey->dp = cliKey->dp;
  30581. ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey);
  30582. if (ret != 0) {
  30583. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30584. }
  30585. #endif
  30586. y = sizeof(plain);
  30587. ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL);
  30588. if (ret < 0)
  30589. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30590. if (XMEMCMP(plain, in, inLen))
  30591. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30592. }
  30593. #endif
  30594. x = sizeof(out);
  30595. do {
  30596. #if defined(WOLFSSL_ASYNC_CRYPT)
  30597. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30598. #endif
  30599. if (ret == 0)
  30600. ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey);
  30601. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30602. if (ret < 0)
  30603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30604. TEST_SLEEP();
  30605. XMEMSET(plain, 0, sizeof(plain));
  30606. do {
  30607. #if defined(WOLFSSL_ASYNC_CRYPT)
  30608. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30609. #endif
  30610. if (ret == 0)
  30611. ret = wc_ecc_verify_hash(out, x, in, inLen, &verify,
  30612. cliKey);
  30613. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30614. if (ret < 0)
  30615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30616. if (verify != 1)
  30617. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30618. TEST_SLEEP();
  30619. #ifdef WOLFSSL_CERT_EXT
  30620. idx = 0;
  30621. bytes = sizeof_ecc_clikeypub_der_256;
  30622. ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey,
  30623. (word32) bytes);
  30624. if (ret != 0)
  30625. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30626. #endif
  30627. ret = 0;
  30628. done:
  30629. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30630. if (cliKey != NULL) {
  30631. wc_ecc_free(cliKey);
  30632. XFREE(cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30633. }
  30634. if (servKey != NULL) {
  30635. wc_ecc_free(servKey);
  30636. XFREE(servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30637. }
  30638. if (tmpKey != NULL) {
  30639. wc_ecc_free(tmpKey);
  30640. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30641. }
  30642. #else
  30643. wc_ecc_free(cliKey);
  30644. wc_ecc_free(servKey);
  30645. wc_ecc_free(tmpKey);
  30646. #endif
  30647. wc_FreeRng(&rng);
  30648. return ret;
  30649. }
  30650. #endif /* USE_CERT_BUFFERS_256 && !WOLFSSL_ATECCX08A && !NO_ECC256 */
  30651. #endif /* HAVE_ECC */
  30652. #ifdef HAVE_CURVE25519
  30653. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30654. defined(HAVE_CURVE25519_KEY_IMPORT)
  30655. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30656. #define X25519_TEST_CNT 5
  30657. #else
  30658. #define X25519_TEST_CNT 1
  30659. #endif
  30660. static wc_test_ret_t curve25519_overflow_test(void)
  30661. {
  30662. /* secret key for party a */
  30663. byte sa[X25519_TEST_CNT][32] = {
  30664. {
  30665. 0x8d,0xaf,0x6e,0x7a,0xc1,0xeb,0x8d,0x30,
  30666. 0x99,0x86,0xd3,0x90,0x47,0x96,0x21,0x3c,
  30667. 0x3a,0x75,0xc0,0x7b,0x75,0x01,0x75,0xa3,
  30668. 0x81,0x4b,0xff,0x5a,0xbc,0x96,0x87,0x28
  30669. },
  30670. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30671. {
  30672. 0x9d,0x63,0x5f,0xce,0xe2,0xe8,0xd7,0xfb,
  30673. 0x68,0x77,0x0e,0x44,0xd1,0xad,0x87,0x2b,
  30674. 0xf4,0x65,0x06,0xb7,0xbb,0xdb,0xbe,0x6e,
  30675. 0x02,0x43,0x24,0xc7,0x3d,0x7b,0x88,0x60
  30676. },
  30677. {
  30678. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30679. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30680. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30681. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30682. },
  30683. {
  30684. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30685. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30686. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30687. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30688. },
  30689. {
  30690. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30691. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30692. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30693. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30694. }
  30695. #endif
  30696. };
  30697. /* public key for party b */
  30698. byte pb[X25519_TEST_CNT][32] = {
  30699. {
  30700. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30701. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30702. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30703. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30704. },
  30705. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30706. {
  30707. /* 0xff first byte in original - invalid! */
  30708. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30709. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30710. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30711. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30712. },
  30713. {
  30714. 0x36,0x1a,0x74,0x87,0x28,0x59,0xe0,0xb6,
  30715. 0xe4,0x2b,0x17,0x9b,0x16,0xb0,0x3b,0xf8,
  30716. 0xb8,0x9f,0x2a,0x8f,0xc5,0x33,0x68,0x4f,
  30717. 0xde,0x4d,0xd8,0x80,0x63,0xe7,0xb4,0x0a
  30718. },
  30719. {
  30720. 0x00,0x80,0x38,0x59,0x19,0x3a,0x66,0x12,
  30721. 0xfd,0xa1,0xec,0x1c,0x40,0x84,0x40,0xbd,
  30722. 0x64,0x10,0x8b,0x53,0x81,0x21,0x03,0x2d,
  30723. 0x7d,0x33,0xb4,0x01,0x57,0x0d,0xe1,0x89
  30724. },
  30725. {
  30726. 0x1d,0xf8,0xf8,0x33,0x89,0x6c,0xb7,0xba,
  30727. 0x94,0x73,0xfa,0xc2,0x36,0xac,0xbe,0x49,
  30728. 0xaf,0x85,0x3e,0x93,0x5f,0xae,0xb2,0xc0,
  30729. 0xc8,0x80,0x8f,0x4a,0xaa,0xd3,0x55,0x2b
  30730. }
  30731. #endif
  30732. };
  30733. /* expected shared key */
  30734. byte ss[X25519_TEST_CNT][32] = {
  30735. {
  30736. 0x5c,0x4c,0x85,0x5f,0xfb,0x20,0x38,0xcc,
  30737. 0x55,0x16,0x5b,0x8a,0xa7,0xed,0x57,0x6e,
  30738. 0x35,0xaa,0x71,0x67,0x85,0x1f,0xb6,0x28,
  30739. 0x17,0x07,0x7b,0xda,0x76,0xdd,0xe0,0xb4
  30740. },
  30741. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30742. {
  30743. 0x33,0xf6,0xc1,0x34,0x62,0x92,0x06,0x02,
  30744. 0x95,0xdb,0x91,0x4c,0x5d,0x52,0x54,0xc7,
  30745. 0xd2,0x5b,0x24,0xb5,0x4f,0x33,0x59,0x79,
  30746. 0x9f,0x6d,0x7e,0x4a,0x4c,0x30,0xd6,0x38
  30747. },
  30748. {
  30749. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30750. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30751. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30752. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02
  30753. },
  30754. {
  30755. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30756. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30757. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30758. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
  30759. },
  30760. {
  30761. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30762. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30763. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30764. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10
  30765. }
  30766. #endif
  30767. };
  30768. wc_test_ret_t ret = 0;
  30769. int i;
  30770. word32 y;
  30771. byte shared[32];
  30772. curve25519_key userA;
  30773. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  30774. for (i = 0; i < X25519_TEST_CNT; i++) {
  30775. if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i],
  30776. sizeof(pb[i]), &userA) != 0) {
  30777. ret = WC_TEST_RET_ENC_I(i); break;
  30778. }
  30779. /* test against known test vector */
  30780. XMEMSET(shared, 0, sizeof(shared));
  30781. y = sizeof(shared);
  30782. if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
  30783. ret = WC_TEST_RET_ENC_I(i); break;
  30784. }
  30785. if (XMEMCMP(ss[i], shared, y)) {
  30786. ret = WC_TEST_RET_ENC_I(i); break;
  30787. }
  30788. }
  30789. wc_curve25519_free(&userA);
  30790. return ret;
  30791. }
  30792. /* Test the wc_curve25519_check_public API.
  30793. *
  30794. * returns 0 on success and -ve on failure.
  30795. */
  30796. static wc_test_ret_t curve25519_check_public_test(void)
  30797. {
  30798. wc_test_ret_t ret;
  30799. /* Little-endian values that will fail */
  30800. byte fail_le[][CURVE25519_KEYSIZE] = {
  30801. {
  30802. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30803. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30804. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30805. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30806. },
  30807. {
  30808. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30809. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30810. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30811. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30812. },
  30813. {
  30814. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30815. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30816. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30817. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81
  30818. },
  30819. };
  30820. /* Big-endian values that will fail */
  30821. byte fail_be[][CURVE25519_KEYSIZE] = {
  30822. {
  30823. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30824. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30825. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30826. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30827. },
  30828. {
  30829. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30830. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30831. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30832. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30833. },
  30834. {
  30835. 0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30836. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30837. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30838. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30839. },
  30840. };
  30841. /* Good or valid public value */
  30842. byte good[CURVE25519_KEYSIZE] = {
  30843. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30844. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30845. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30846. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30847. };
  30848. int i;
  30849. /* Parameter checks */
  30850. /* NULL pointer */
  30851. ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN);
  30852. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30853. return WC_TEST_RET_ENC_EC(ret);
  30854. }
  30855. ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN);
  30856. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30857. return WC_TEST_RET_ENC_EC(ret);
  30858. }
  30859. /* Length of 0 treated differently to other invalid lengths for TLS */
  30860. ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN);
  30861. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  30862. return WC_TEST_RET_ENC_EC(ret);
  30863. ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN);
  30864. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  30865. return WC_TEST_RET_ENC_EC(ret);
  30866. /* Length not CURVE25519_KEYSIZE */
  30867. for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) {
  30868. if (i == CURVE25519_KEYSIZE)
  30869. continue;
  30870. if (wc_curve25519_check_public(good, (word32)i, EC25519_LITTLE_ENDIAN) !=
  30871. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  30872. return WC_TEST_RET_ENC_I(i);
  30873. }
  30874. if (wc_curve25519_check_public(good, (word32)i, EC25519_BIG_ENDIAN) !=
  30875. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  30876. return WC_TEST_RET_ENC_I(i);
  30877. }
  30878. }
  30879. /* Little-endian fail cases */
  30880. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  30881. if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE,
  30882. EC25519_LITTLE_ENDIAN) == 0) {
  30883. return WC_TEST_RET_ENC_I(i);
  30884. }
  30885. }
  30886. /* Big-endian fail cases */
  30887. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  30888. if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE,
  30889. EC25519_BIG_ENDIAN) == 0) {
  30890. return WC_TEST_RET_ENC_I(i);
  30891. }
  30892. }
  30893. /* Check a valid public value works! */
  30894. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  30895. EC25519_LITTLE_ENDIAN);
  30896. if (ret != 0) {
  30897. return WC_TEST_RET_ENC_EC(ret);
  30898. }
  30899. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  30900. EC25519_BIG_ENDIAN);
  30901. if (ret != 0) {
  30902. return WC_TEST_RET_ENC_EC(ret);
  30903. }
  30904. return 0;
  30905. }
  30906. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  30907. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  30908. defined(HAVE_CURVE25519_KEY_IMPORT)
  30909. static wc_test_ret_t curve255519_der_test(void)
  30910. {
  30911. wc_test_ret_t ret = 0;
  30912. /* certs/statickeys/x25519.der */
  30913. const byte kCurve25519PrivDer[] = {
  30914. 0x30, 0x2E, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E,
  30915. 0x04, 0x22, 0x04, 0x20, 0x78, 0x8E, 0x31, 0x5C, 0x33, 0xA9, 0x19, 0xC0,
  30916. 0x5E, 0x36, 0x70, 0x1B, 0xA4, 0xE8, 0xEF, 0xC1, 0x89, 0x8C, 0xB3, 0x15,
  30917. 0xC6, 0x79, 0xD3, 0xAC, 0x22, 0x00, 0xAE, 0xFA, 0xB3, 0xB7, 0x0F, 0x78
  30918. };
  30919. /* certs/statickeys/x25519-pub.der */
  30920. const byte kCurve25519PubDer[] = {
  30921. 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00,
  30922. 0x09, 0xBC, 0x8C, 0xC7, 0x45, 0x0D, 0xC1, 0xC2, 0x02, 0x57, 0x9A, 0x68,
  30923. 0x3A, 0xFD, 0x7A, 0xA8, 0xA5, 0x2F, 0xF0, 0x99, 0x39, 0x98, 0xEA, 0x26,
  30924. 0xA2, 0x5B, 0x38, 0xFD, 0x96, 0xDB, 0x2A, 0x26
  30925. };
  30926. curve25519_key key;
  30927. byte output[128];
  30928. word32 outputSz = 128;
  30929. word32 idx;
  30930. ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId);
  30931. if (ret != 0)
  30932. return WC_TEST_RET_ENC_EC(ret);
  30933. /* Test decode / encode of Curve25519 private key only */
  30934. if (ret == 0) {
  30935. idx = 0;
  30936. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key,
  30937. (word32)sizeof(kCurve25519PrivDer));
  30938. if (ret < 0)
  30939. ret = WC_TEST_RET_ENC_EC(ret);
  30940. }
  30941. if (ret == 0) {
  30942. outputSz = (word32)sizeof(output);
  30943. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  30944. if (ret >= 0) {
  30945. outputSz = (word32)ret;
  30946. ret = 0;
  30947. }
  30948. else {
  30949. ret = WC_TEST_RET_ENC_EC(ret);
  30950. }
  30951. }
  30952. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  30953. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  30954. ret = WC_TEST_RET_ENC_NC;
  30955. }
  30956. /* Test decode / encode of Curve25519 public key only */
  30957. if (ret == 0) {
  30958. idx = 0;
  30959. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key,
  30960. (word32)sizeof(kCurve25519PubDer));
  30961. if (ret < 0)
  30962. ret = WC_TEST_RET_ENC_EC(ret);
  30963. }
  30964. if (ret == 0) {
  30965. outputSz = (word32)sizeof(output);
  30966. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  30967. if (ret >= 0) {
  30968. outputSz = (word32)ret;
  30969. ret = 0;
  30970. }
  30971. else {
  30972. ret = WC_TEST_RET_ENC_EC(ret);
  30973. }
  30974. }
  30975. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  30976. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  30977. ret = WC_TEST_RET_ENC_NC;
  30978. }
  30979. wc_curve25519_free(&key);
  30980. return ret;
  30981. }
  30982. #endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
  30983. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
  30984. {
  30985. WC_RNG rng;
  30986. wc_test_ret_t ret;
  30987. #ifdef HAVE_CURVE25519_SHARED_SECRET
  30988. byte sharedA[32];
  30989. byte sharedB[32];
  30990. word32 y;
  30991. #endif
  30992. #ifdef HAVE_CURVE25519_KEY_EXPORT
  30993. byte exportBuf[32];
  30994. #endif
  30995. word32 x = 0;
  30996. curve25519_key userA, userB, pubKey;
  30997. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30998. defined(HAVE_CURVE25519_KEY_IMPORT)
  30999. /* test vectors from
  31000. https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
  31001. */
  31002. /* secret key for party a */
  31003. byte sa[] = {
  31004. 0x5A,0xC9,0x9F,0x33,0x63,0x2E,0x5A,0x76,
  31005. 0x8D,0xE7,0xE8,0x1B,0xF8,0x54,0xC2,0x7C,
  31006. 0x46,0xE3,0xFB,0xF2,0xAB,0xBA,0xCD,0x29,
  31007. 0xEC,0x4A,0xFF,0x51,0x73,0x69,0xC6,0x60
  31008. };
  31009. /* public key for party a */
  31010. byte pa[] = {
  31011. 0x05,0x7E,0x23,0xEA,0x9F,0x1C,0xBE,0x8A,
  31012. 0x27,0x16,0x8F,0x6E,0x69,0x6A,0x79,0x1D,
  31013. 0xE6,0x1D,0xD3,0xAF,0x7A,0xCD,0x4E,0xEA,
  31014. 0xCC,0x6E,0x7B,0xA5,0x14,0xFD,0xA8,0x63
  31015. };
  31016. /* secret key for party b */
  31017. byte sb[] = {
  31018. 0x47,0xDC,0x3D,0x21,0x41,0x74,0x82,0x0E,
  31019. 0x11,0x54,0xB4,0x9B,0xC6,0xCD,0xB2,0xAB,
  31020. 0xD4,0x5E,0xE9,0x58,0x17,0x05,0x5D,0x25,
  31021. 0x5A,0xA3,0x58,0x31,0xB7,0x0D,0x32,0x60
  31022. };
  31023. /* public key for party b */
  31024. byte pb[] = {
  31025. 0x6E,0xB8,0x9D,0xA9,0x19,0x89,0xAE,0x37,
  31026. 0xC7,0xEA,0xC7,0x61,0x8D,0x9E,0x5C,0x49,
  31027. 0x51,0xDB,0xA1,0xD7,0x3C,0x28,0x5A,0xE1,
  31028. 0xCD,0x26,0xA8,0x55,0x02,0x0E,0xEF,0x04
  31029. };
  31030. /* expected shared key */
  31031. byte ss[] = {
  31032. 0x61,0x45,0x0C,0xD9,0x8E,0x36,0x01,0x6B,
  31033. 0x58,0x77,0x6A,0x89,0x7A,0x9F,0x0A,0xEF,
  31034. 0x73,0x8B,0x99,0xF0,0x94,0x68,0xB8,0xD6,
  31035. 0xB8,0x51,0x11,0x84,0xD5,0x34,0x94,0xAB
  31036. };
  31037. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  31038. (void)x;
  31039. WOLFSSL_ENTER("curve25519_test");
  31040. #ifndef HAVE_FIPS
  31041. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31042. #else
  31043. ret = wc_InitRng(&rng);
  31044. #endif
  31045. if (ret != 0)
  31046. return WC_TEST_RET_ENC_EC(ret);
  31047. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  31048. wc_curve25519_init_ex(&userB, HEAP_HINT, devId);
  31049. wc_curve25519_init_ex(&pubKey, HEAP_HINT, devId);
  31050. /* make curve25519 keys */
  31051. ret = wc_curve25519_make_key(&rng, 32, &userA);
  31052. if (ret != 0)
  31053. return WC_TEST_RET_ENC_EC(ret);
  31054. ret = wc_curve25519_make_key(&rng, 32, &userB);
  31055. if (ret != 0)
  31056. return WC_TEST_RET_ENC_EC(ret);
  31057. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31058. /* find shared secret key */
  31059. x = sizeof(sharedA);
  31060. if ((ret = wc_curve25519_shared_secret(&userA, &userB, sharedA, &x)) != 0) {
  31061. printf("wc_curve25519_shared_secret 1 failed\n");
  31062. return WC_TEST_RET_ENC_EC(ret);
  31063. }
  31064. y = sizeof(sharedB);
  31065. if ((ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y)) != 0) {
  31066. printf("wc_curve25519_shared_secret 2 failed\n");
  31067. return WC_TEST_RET_ENC_EC(ret);
  31068. }
  31069. /* compare shared secret keys to test they are the same */
  31070. if (y != x)
  31071. return WC_TEST_RET_ENC_NC;
  31072. if (XMEMCMP(sharedA, sharedB, x))
  31073. return WC_TEST_RET_ENC_NC;
  31074. #endif
  31075. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31076. /* export a public key and import it for another user */
  31077. x = sizeof(exportBuf);
  31078. ret = wc_curve25519_export_public(&userA, exportBuf, &x);
  31079. if (ret != 0)
  31080. return WC_TEST_RET_ENC_EC(ret);
  31081. #ifdef HAVE_CURVE25519_KEY_IMPORT
  31082. ret = wc_curve25519_import_public(exportBuf, x, &pubKey);
  31083. if (ret != 0)
  31084. return WC_TEST_RET_ENC_EC(ret);
  31085. #endif
  31086. #endif
  31087. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31088. defined(HAVE_CURVE25519_KEY_IMPORT)
  31089. /* test shared key after importing a public key */
  31090. XMEMSET(sharedB, 0, sizeof(sharedB));
  31091. y = sizeof(sharedB);
  31092. if (wc_curve25519_shared_secret(&userB, &pubKey, sharedB, &y) != 0) {
  31093. return WC_TEST_RET_ENC_NC;
  31094. }
  31095. if (XMEMCMP(sharedA, sharedB, y))
  31096. return WC_TEST_RET_ENC_NC;
  31097. /* import RFC test vectors and compare shared key */
  31098. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31099. &userA);
  31100. if (ret != 0)
  31101. return WC_TEST_RET_ENC_EC(ret);
  31102. ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb),
  31103. &userB);
  31104. if (ret != 0)
  31105. return WC_TEST_RET_ENC_EC(ret);
  31106. /* test against known test vector */
  31107. XMEMSET(sharedB, 0, sizeof(sharedB));
  31108. y = sizeof(sharedB);
  31109. ret = wc_curve25519_shared_secret(&userA, &userB, sharedB, &y);
  31110. if (ret != 0)
  31111. return WC_TEST_RET_ENC_EC(ret);
  31112. if (XMEMCMP(ss, sharedB, y))
  31113. return WC_TEST_RET_ENC_NC;
  31114. /* test swapping roles of keys and generating same shared key */
  31115. XMEMSET(sharedB, 0, sizeof(sharedB));
  31116. y = sizeof(sharedB);
  31117. ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y);
  31118. if (ret != 0)
  31119. return WC_TEST_RET_ENC_EC(ret);
  31120. if (XMEMCMP(ss, sharedB, y))
  31121. return WC_TEST_RET_ENC_NC;
  31122. /* test with 1 generated key and 1 from known test vector */
  31123. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31124. &userA);
  31125. if (ret != 0)
  31126. return WC_TEST_RET_ENC_EC(ret);
  31127. wc_curve25519_free(&userB);
  31128. wc_curve25519_init_ex(&userB, HEAP_HINT, devId);
  31129. ret = wc_curve25519_make_key(&rng, 32, &userB);
  31130. if (ret != 0)
  31131. return WC_TEST_RET_ENC_EC(ret);
  31132. x = sizeof(sharedA);
  31133. ret = wc_curve25519_shared_secret(&userA, &userB, sharedA, &x);
  31134. if (ret != 0)
  31135. return WC_TEST_RET_ENC_EC(ret);
  31136. y = sizeof(sharedB);
  31137. ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y);
  31138. if (ret != 0)
  31139. return WC_TEST_RET_ENC_EC(ret);
  31140. /* compare shared secret keys to test they are the same */
  31141. if (y != x)
  31142. return WC_TEST_RET_ENC_NC;
  31143. if (XMEMCMP(sharedA, sharedB, x))
  31144. return WC_TEST_RET_ENC_NC;
  31145. ret = curve25519_overflow_test();
  31146. if (ret != 0)
  31147. return ret;
  31148. ret = curve25519_check_public_test();
  31149. if (ret != 0)
  31150. return ret;
  31151. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31152. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31153. defined(HAVE_CURVE25519_KEY_IMPORT)
  31154. ret = curve255519_der_test();
  31155. if (ret != 0)
  31156. return ret;
  31157. #endif
  31158. /* clean up keys when done */
  31159. wc_curve25519_free(&pubKey);
  31160. wc_curve25519_free(&userB);
  31161. wc_curve25519_free(&userA);
  31162. wc_FreeRng(&rng);
  31163. return 0;
  31164. }
  31165. #endif /* HAVE_CURVE25519 */
  31166. #ifdef HAVE_ED25519
  31167. #ifdef WOLFSSL_TEST_CERT
  31168. static wc_test_ret_t ed25519_test_cert(void)
  31169. {
  31170. DecodedCert cert[2];
  31171. DecodedCert* serverCert = NULL;
  31172. DecodedCert* caCert = NULL;
  31173. #ifdef HAVE_ED25519_VERIFY
  31174. ed25519_key key;
  31175. ed25519_key* pubKey = NULL;
  31176. int verify;
  31177. #endif /* HAVE_ED25519_VERIFY */
  31178. wc_test_ret_t ret;
  31179. byte* tmp;
  31180. size_t bytes;
  31181. XFILE file;
  31182. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31183. if (tmp == NULL) {
  31184. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31185. }
  31186. #ifdef USE_CERT_BUFFERS_256
  31187. XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert);
  31188. bytes = sizeof_ca_ed25519_cert;
  31189. #elif !defined(NO_FILESYSTEM)
  31190. file = XFOPEN(caEd25519Cert, "rb");
  31191. if (file == NULL) {
  31192. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31193. }
  31194. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31195. XFCLOSE(file);
  31196. if (bytes == 0)
  31197. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31198. #else
  31199. /* No certificate to use. */
  31200. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31201. #endif
  31202. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  31203. caCert = &cert[0];
  31204. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  31205. if (ret != 0)
  31206. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31207. #ifdef USE_CERT_BUFFERS_256
  31208. XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert);
  31209. bytes = sizeof_server_ed25519_cert;
  31210. #elif !defined(NO_FILESYSTEM)
  31211. file = XFOPEN(serverEd25519Cert, "rb");
  31212. if (file == NULL) {
  31213. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31214. }
  31215. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31216. XFCLOSE(file);
  31217. if (bytes == 0)
  31218. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31219. #else
  31220. /* No certificate to use. */
  31221. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31222. #endif
  31223. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  31224. serverCert = &cert[1];
  31225. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  31226. if (ret != 0)
  31227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31228. #ifdef HAVE_ED25519_VERIFY
  31229. ret = wc_ed25519_init(&key);
  31230. if (ret < 0)
  31231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31232. pubKey = &key;
  31233. ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize,
  31234. pubKey);
  31235. if (ret < 0)
  31236. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31237. ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength,
  31238. serverCert->source + serverCert->certBegin,
  31239. serverCert->sigIndex - serverCert->certBegin,
  31240. &verify, pubKey);
  31241. if (ret < 0 || verify != 1)
  31242. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31243. #endif /* HAVE_ED25519_VERIFY */
  31244. done:
  31245. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31246. #ifdef HAVE_ED25519_VERIFY
  31247. wc_ed25519_free(pubKey);
  31248. #endif /* HAVE_ED25519_VERIFY */
  31249. if (caCert != NULL)
  31250. FreeDecodedCert(caCert);
  31251. if (serverCert != NULL)
  31252. FreeDecodedCert(serverCert);
  31253. return ret;
  31254. }
  31255. static wc_test_ret_t ed25519_test_make_cert(void)
  31256. {
  31257. WC_RNG rng;
  31258. Cert cert;
  31259. DecodedCert decode;
  31260. ed25519_key key;
  31261. ed25519_key* privKey = NULL;
  31262. wc_test_ret_t ret = 0;
  31263. byte* tmp = NULL;
  31264. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  31265. #ifndef HAVE_FIPS
  31266. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31267. #else
  31268. ret = wc_InitRng(&rng);
  31269. #endif
  31270. if (ret != 0)
  31271. return WC_TEST_RET_ENC_EC(ret);
  31272. wc_ed25519_init(&key);
  31273. privKey = &key;
  31274. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, privKey);
  31275. cert.daysValid = 365 * 2;
  31276. cert.selfSigned = 1;
  31277. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  31278. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  31279. cert.isCA = 0;
  31280. #ifdef WOLFSSL_CERT_EXT
  31281. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  31282. if (ret < 0)
  31283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31284. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31285. if (ret < 0)
  31286. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31287. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31288. if (ret < 0)
  31289. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31290. #endif
  31291. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31292. if (tmp == NULL) {
  31293. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31294. }
  31295. cert.sigType = CTC_ED25519;
  31296. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng);
  31297. if (ret < 0)
  31298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31299. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF,
  31300. ED25519_TYPE, privKey, &rng);
  31301. if (ret < 0)
  31302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31303. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  31304. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  31305. FreeDecodedCert(&decode);
  31306. if (ret != 0)
  31307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31308. done:
  31309. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31310. wc_ed25519_free(privKey);
  31311. wc_FreeRng(&rng);
  31312. return ret;
  31313. }
  31314. #endif /* WOLFSSL_TEST_CERT */
  31315. #if defined(HAVE_ED25519_KEY_IMPORT)
  31316. static wc_test_ret_t ed25519_test_check_key(void)
  31317. {
  31318. /* Fails to find x-ordinate from this y-ordinate. */
  31319. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  31320. 0x40,
  31321. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31322. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31323. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31324. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31325. };
  31326. /* Y-ordinate value larger than prime. */
  31327. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  31328. 0x40,
  31329. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31330. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31331. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31332. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31333. };
  31334. /* Y-ordinate value equal to prime. */
  31335. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  31336. 0x40,
  31337. 0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31338. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31339. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31340. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31341. };
  31342. /* Y-ordinate value equal to prime - 1. */
  31343. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  31344. 0x40,
  31345. 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31346. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31347. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31348. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31349. };
  31350. ed25519_key key;
  31351. int ret;
  31352. int res = 0;
  31353. /* Initialize key for use. */
  31354. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31355. if (ret != 0) {
  31356. return WC_TEST_RET_ENC_NC;
  31357. }
  31358. /* Load bad public key only and perform checks. */
  31359. ret = wc_ed25519_import_public(key_bad_y, ED25519_PUB_KEY_SIZE + 1, &key);
  31360. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31361. res = WC_TEST_RET_ENC_NC;
  31362. }
  31363. if (res == 0) {
  31364. /* Load bad public key only and perform checks. */
  31365. ret = wc_ed25519_import_public(key_bad_y_max, ED25519_PUB_KEY_SIZE + 1,
  31366. &key);
  31367. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31368. res = WC_TEST_RET_ENC_NC;
  31369. }
  31370. }
  31371. if (res == 0) {
  31372. /* Load bad public key only and perform checks. */
  31373. ret = wc_ed25519_import_public(key_bad_y_is_p, ED25519_PUB_KEY_SIZE + 1,
  31374. &key);
  31375. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31376. res = WC_TEST_RET_ENC_NC;
  31377. }
  31378. }
  31379. if (res == 0) {
  31380. /* Load good public key only and perform checks. */
  31381. ret = wc_ed25519_import_public(key_y_is_p_minus_1,
  31382. ED25519_PUB_KEY_SIZE + 1, &key);
  31383. if (ret != 0) {
  31384. res = WC_TEST_RET_ENC_NC;
  31385. }
  31386. }
  31387. /* Dispose of key. */
  31388. wc_ed25519_free(&key);
  31389. return res;
  31390. }
  31391. #endif
  31392. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31393. defined(HAVE_ED25519_KEY_IMPORT)
  31394. static wc_test_ret_t ed25519ctx_test(void)
  31395. {
  31396. wc_test_ret_t ret;
  31397. byte out[ED25519_SIG_SIZE];
  31398. word32 outlen;
  31399. #ifdef HAVE_ED25519_VERIFY
  31400. int verify = 0;
  31401. #endif /* HAVE_ED25519_VERIFY */
  31402. ed25519_key key;
  31403. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  31404. 0x03,0x05,0x33,0x4e,0x38,0x1a,0xf7,0x8f,
  31405. 0x14,0x1c,0xb6,0x66,0xf6,0x19,0x9f,0x57,
  31406. 0xbc,0x34,0x95,0x33,0x5a,0x25,0x6a,0x95,
  31407. 0xbd,0x2a,0x55,0xbf,0x54,0x66,0x63,0xf6
  31408. };
  31409. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  31410. 0xdf,0xc9,0x42,0x5e,0x4f,0x96,0x8f,0x7f,
  31411. 0x0c,0x29,0xf0,0x25,0x9c,0xf5,0xf9,0xae,
  31412. 0xd6,0x85,0x1c,0x2b,0xb4,0xad,0x8b,0xfb,
  31413. 0x86,0x0c,0xfe,0xe0,0xab,0x24,0x82,0x92
  31414. };
  31415. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx1[] = {
  31416. 0x55,0xa4,0xcc,0x2f,0x70,0xa5,0x4e,0x04,
  31417. 0x28,0x8c,0x5f,0x4c,0xd1,0xe4,0x5a,0x7b,
  31418. 0xb5,0x20,0xb3,0x62,0x92,0x91,0x18,0x76,
  31419. 0xca,0xda,0x73,0x23,0x19,0x8d,0xd8,0x7a,
  31420. 0x8b,0x36,0x95,0x0b,0x95,0x13,0x00,0x22,
  31421. 0x90,0x7a,0x7f,0xb7,0xc4,0xe9,0xb2,0xd5,
  31422. 0xf6,0xcc,0xa6,0x85,0xa5,0x87,0xb4,0xb2,
  31423. 0x1f,0x4b,0x88,0x8e,0x4e,0x7e,0xdb,0x0d
  31424. };
  31425. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx2[] = {
  31426. 0xcc,0x5e,0x63,0xa2,0x7e,0x94,0xaf,0xd3,
  31427. 0x41,0x83,0x38,0xd2,0x48,0x6f,0xa9,0x2a,
  31428. 0xf9,0x91,0x7c,0x2d,0x98,0x9e,0x06,0xe5,
  31429. 0x02,0x77,0x72,0x1c,0x34,0x38,0x18,0xb4,
  31430. 0x21,0x96,0xbc,0x29,0x2e,0x68,0xf3,0x4d,
  31431. 0x85,0x9b,0xbe,0xad,0x17,0x9f,0x54,0x54,
  31432. 0x2d,0x4b,0x04,0xdc,0xfb,0xfa,0x4a,0x68,
  31433. 0x4e,0x39,0x50,0xfb,0x1c,0xcd,0x8d,0x0d
  31434. };
  31435. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  31436. 0xf7,0x26,0x93,0x6d,0x19,0xc8,0x00,0x49,
  31437. 0x4e,0x3f,0xda,0xff,0x20,0xb2,0x76,0xa8
  31438. };
  31439. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  31440. 0x66,0x6f,0x6f
  31441. };
  31442. outlen = sizeof(out);
  31443. XMEMSET(out, 0, sizeof(out));
  31444. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31445. if (ret != 0)
  31446. return 10800;
  31447. ret = wc_ed25519_import_private_key(sKeyCtx, ED25519_KEY_SIZE, pKeyCtx,
  31448. sizeof(pKeyCtx), &key);
  31449. if (ret == 0)
  31450. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31451. contextCtx, sizeof(contextCtx));
  31452. if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0)
  31453. ret = WC_TEST_RET_ENC_NC;
  31454. #if defined(HAVE_ED25519_VERIFY)
  31455. /* test verify on good msg */
  31456. if (ret == 0)
  31457. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31458. &verify, &key, contextCtx, sizeof(contextCtx));
  31459. if (ret == 0 && verify != 1)
  31460. ret = WC_TEST_RET_ENC_NC;
  31461. #endif
  31462. if (ret == 0)
  31463. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31464. NULL, 0);
  31465. if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0)
  31466. ret = WC_TEST_RET_ENC_NC;
  31467. #if defined(HAVE_ED25519_VERIFY)
  31468. /* test verify on good msg */
  31469. if (ret == 0)
  31470. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31471. &verify, &key, NULL, 0);
  31472. if (ret == 0 && verify != 1)
  31473. ret = WC_TEST_RET_ENC_NC;
  31474. #endif
  31475. wc_ed25519_free(&key);
  31476. return ret;
  31477. }
  31478. static wc_test_ret_t ed25519ph_test(void)
  31479. {
  31480. wc_test_ret_t ret = 0;
  31481. byte out[ED25519_SIG_SIZE];
  31482. word32 outlen;
  31483. #ifdef HAVE_ED25519_VERIFY
  31484. int verify = 0;
  31485. #endif /* HAVE_ED25519_VERIFY */
  31486. ed25519_key key;
  31487. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  31488. 0x83,0x3f,0xe6,0x24,0x09,0x23,0x7b,0x9d,
  31489. 0x62,0xec,0x77,0x58,0x75,0x20,0x91,0x1e,
  31490. 0x9a,0x75,0x9c,0xec,0x1d,0x19,0x75,0x5b,
  31491. 0x7d,0xa9,0x01,0xb9,0x6d,0xca,0x3d,0x42
  31492. };
  31493. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  31494. 0xec,0x17,0x2b,0x93,0xad,0x5e,0x56,0x3b,
  31495. 0xf4,0x93,0x2c,0x70,0xe1,0x24,0x50,0x34,
  31496. 0xc3,0x54,0x67,0xef,0x2e,0xfd,0x4d,0x64,
  31497. 0xeb,0xf8,0x19,0x68,0x34,0x67,0xe2,0xbf
  31498. };
  31499. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  31500. 0x98,0xa7,0x02,0x22,0xf0,0xb8,0x12,0x1a,
  31501. 0xa9,0xd3,0x0f,0x81,0x3d,0x68,0x3f,0x80,
  31502. 0x9e,0x46,0x2b,0x46,0x9c,0x7f,0xf8,0x76,
  31503. 0x39,0x49,0x9b,0xb9,0x4e,0x6d,0xae,0x41,
  31504. 0x31,0xf8,0x50,0x42,0x46,0x3c,0x2a,0x35,
  31505. 0x5a,0x20,0x03,0xd0,0x62,0xad,0xf5,0xaa,
  31506. 0xa1,0x0b,0x8c,0x61,0xe6,0x36,0x06,0x2a,
  31507. 0xaa,0xd1,0x1c,0x2a,0x26,0x08,0x34,0x06
  31508. };
  31509. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  31510. 0xe0,0x39,0x70,0x2b,0x4c,0x25,0x95,0xa6,
  31511. 0xa5,0x41,0xac,0x85,0x09,0x23,0x6e,0x29,
  31512. 0x90,0x47,0x47,0x95,0x33,0x0c,0x9b,0x34,
  31513. 0xa7,0x5f,0x58,0xa6,0x60,0x12,0x9e,0x08,
  31514. 0xfd,0x73,0x69,0x43,0xfb,0x19,0x43,0xa5,
  31515. 0x57,0x20,0xb9,0xe0,0x95,0x7b,0x1e,0xd6,
  31516. 0x73,0x48,0x16,0x61,0x9f,0x13,0x88,0xf4,
  31517. 0x3f,0x73,0xe6,0xe3,0xba,0xa8,0x1c,0x0e
  31518. };
  31519. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  31520. 0x61,0x62,0x63
  31521. };
  31522. /* SHA-512 hash of msgPh */
  31523. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  31524. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  31525. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  31526. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  31527. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  31528. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  31529. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  31530. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  31531. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f
  31532. };
  31533. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  31534. 0x66,0x6f,0x6f
  31535. };
  31536. outlen = sizeof(out);
  31537. XMEMSET(out, 0, sizeof(out));
  31538. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31539. if (ret != 0)
  31540. return WC_TEST_RET_ENC_EC(ret);
  31541. ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh,
  31542. sizeof(pKeyPh), &key);
  31543. if (ret == 0)
  31544. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31545. NULL, 0);
  31546. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31547. ret = WC_TEST_RET_ENC_NC;
  31548. #if defined(HAVE_ED25519_VERIFY)
  31549. /* test verify on good msg */
  31550. if (ret == 0)
  31551. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh),
  31552. &verify, &key, NULL, 0);
  31553. if (ret == 0 && verify != 1)
  31554. ret = WC_TEST_RET_ENC_NC;
  31555. #endif
  31556. if (ret == 0)
  31557. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31558. contextPh2, sizeof(contextPh2));
  31559. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31560. ret = WC_TEST_RET_ENC_NC;
  31561. #if defined(HAVE_ED25519_VERIFY)
  31562. /* test verify on good msg */
  31563. if (ret == 0)
  31564. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify,
  31565. &key, contextPh2, sizeof(contextPh2));
  31566. if (ret == 0 && verify != 1)
  31567. ret = WC_TEST_RET_ENC_NC;
  31568. #endif
  31569. if (ret == 0)
  31570. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31571. NULL, 0);
  31572. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31573. ret = WC_TEST_RET_ENC_NC;
  31574. #if defined(HAVE_ED25519_VERIFY)
  31575. if (ret == 0)
  31576. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh),
  31577. &verify, &key, NULL, 0);
  31578. if (ret == 0 && verify != 1)
  31579. ret = WC_TEST_RET_ENC_NC;
  31580. #endif
  31581. if (ret == 0)
  31582. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31583. contextPh2, sizeof(contextPh2));
  31584. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31585. ret = WC_TEST_RET_ENC_NC;
  31586. #if defined(HAVE_ED25519_VERIFY)
  31587. if (ret == 0)
  31588. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  31589. &key, contextPh2, sizeof(contextPh2));
  31590. if (ret == 0 && verify != 1)
  31591. ret = WC_TEST_RET_ENC_NC;
  31592. #endif
  31593. wc_ed25519_free(&key);
  31594. return ret;
  31595. }
  31596. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31597. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
  31598. {
  31599. wc_test_ret_t ret;
  31600. WC_RNG rng;
  31601. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31602. defined(HAVE_ED25519_KEY_IMPORT)
  31603. byte out[ED25519_SIG_SIZE];
  31604. byte exportPKey[ED25519_KEY_SIZE];
  31605. byte exportSKey[ED25519_KEY_SIZE];
  31606. word32 exportPSz;
  31607. word32 exportSSz;
  31608. int i;
  31609. word32 outlen;
  31610. #ifdef HAVE_ED25519_VERIFY
  31611. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  31612. int j;
  31613. #endif
  31614. int verify;
  31615. #endif /* HAVE_ED25519_VERIFY */
  31616. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31617. word32 keySz, sigSz;
  31618. ed25519_key key;
  31619. ed25519_key key2;
  31620. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31621. defined(HAVE_ED25519_KEY_IMPORT)
  31622. /* test vectors from
  31623. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02
  31624. */
  31625. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  31626. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31627. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31628. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31629. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31630. };
  31631. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  31632. 0x4c,0xcd,0x08,0x9b,0x28,0xff,0x96,0xda,
  31633. 0x9d,0xb6,0xc3,0x46,0xec,0x11,0x4e,0x0f,
  31634. 0x5b,0x8a,0x31,0x9f,0x35,0xab,0xa6,0x24,
  31635. 0xda,0x8c,0xf6,0xed,0x4f,0xb8,0xa6,0xfb
  31636. };
  31637. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  31638. 0xc5,0xaa,0x8d,0xf4,0x3f,0x9f,0x83,0x7b,
  31639. 0xed,0xb7,0x44,0x2f,0x31,0xdc,0xb7,0xb1,
  31640. 0x66,0xd3,0x85,0x35,0x07,0x6f,0x09,0x4b,
  31641. 0x85,0xce,0x3a,0x2e,0x0b,0x44,0x58,0xf7
  31642. };
  31643. /* uncompressed test */
  31644. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  31645. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31646. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31647. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31648. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31649. };
  31650. /* compressed prefix test */
  31651. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  31652. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31653. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31654. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31655. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31656. };
  31657. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  31658. 0xf5,0xe5,0x76,0x7c,0xf1,0x53,0x31,0x95,
  31659. 0x17,0x63,0x0f,0x22,0x68,0x76,0xb8,0x6c,
  31660. 0x81,0x60,0xcc,0x58,0x3b,0xc0,0x13,0x74,
  31661. 0x4c,0x6b,0xf2,0x55,0xf5,0xcc,0x0e,0xe5
  31662. };
  31663. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  31664. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  31665. 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31666. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31667. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31668. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31669. };
  31670. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  31671. 0x3d,0x40,0x17,0xc3,0xe8,0x43,0x89,0x5a,
  31672. 0x92,0xb7,0x0a,0xa7,0x4d,0x1b,0x7e,0xbc,
  31673. 0x9c,0x98,0x2c,0xcf,0x2e,0xc4,0x96,0x8c,
  31674. 0xc0,0xcd,0x55,0xf1,0x2a,0xf4,0x66,0x0c
  31675. };
  31676. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  31677. 0xfc,0x51,0xcd,0x8e,0x62,0x18,0xa1,0xa3,
  31678. 0x8d,0xa4,0x7e,0xd0,0x02,0x30,0xf0,0x58,
  31679. 0x08,0x16,0xed,0x13,0xba,0x33,0x03,0xac,
  31680. 0x5d,0xeb,0x91,0x15,0x48,0x90,0x80,0x25
  31681. };
  31682. /* uncompressed test */
  31683. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  31684. 0x04,0x55,0xd0,0xe0,0x9a,0x2b,0x9d,0x34,
  31685. 0x29,0x22,0x97,0xe0,0x8d,0x60,0xd0,0xf6,
  31686. 0x20,0xc5,0x13,0xd4,0x72,0x53,0x18,0x7c,
  31687. 0x24,0xb1,0x27,0x86,0xbd,0x77,0x76,0x45,
  31688. 0xce,0x1a,0x51,0x07,0xf7,0x68,0x1a,0x02,
  31689. 0xaf,0x25,0x23,0xa6,0xda,0xf3,0x72,0xe1,
  31690. 0x0e,0x3a,0x07,0x64,0xc9,0xd3,0xfe,0x4b,
  31691. 0xd5,0xb7,0x0a,0xb1,0x82,0x01,0x98,0x5a,
  31692. 0xd7
  31693. };
  31694. /* compressed prefix */
  31695. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  31696. 0x40,0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31697. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31698. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31699. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31700. };
  31701. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  31702. 0x27,0x81,0x17,0xfc,0x14,0x4c,0x72,0x34,
  31703. 0x0f,0x67,0xd0,0xf2,0x31,0x6e,0x83,0x86,
  31704. 0xce,0xff,0xbf,0x2b,0x24,0x28,0xc9,0xc5,
  31705. 0x1f,0xef,0x7c,0x59,0x7f,0x1d,0x42,0x6e
  31706. };
  31707. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  31708. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  31709. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  31710. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  31711. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  31712. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  31713. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  31714. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  31715. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  31716. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  31717. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  31718. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  31719. };
  31720. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  31721. 0x92,0xa0,0x09,0xa9,0xf0,0xd4,0xca,0xb8,
  31722. 0x72,0x0e,0x82,0x0b,0x5f,0x64,0x25,0x40,
  31723. 0xa2,0xb2,0x7b,0x54,0x16,0x50,0x3f,0x8f,
  31724. 0xb3,0x76,0x22,0x23,0xeb,0xdb,0x69,0xda,
  31725. 0x08,0x5a,0xc1,0xe4,0x3e,0x15,0x99,0x6e,
  31726. 0x45,0x8f,0x36,0x13,0xd0,0xf1,0x1d,0x8c,
  31727. 0x38,0x7b,0x2e,0xae,0xb4,0x30,0x2a,0xee,
  31728. 0xb0,0x0d,0x29,0x16,0x12,0xbb,0x0c,0x00
  31729. };
  31730. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  31731. 0x62,0x91,0xd6,0x57,0xde,0xec,0x24,0x02,
  31732. 0x48,0x27,0xe6,0x9c,0x3a,0xbe,0x01,0xa3,
  31733. 0x0c,0xe5,0x48,0xa2,0x84,0x74,0x3a,0x44,
  31734. 0x5e,0x36,0x80,0xd7,0xdb,0x5a,0xc3,0xac,
  31735. 0x18,0xff,0x9b,0x53,0x8d,0x16,0xf2,0x90,
  31736. 0xae,0x67,0xf7,0x60,0x98,0x4d,0xc6,0x59,
  31737. 0x4a,0x7c,0x15,0xe9,0x71,0x6e,0xd2,0x8d,
  31738. 0xc0,0x27,0xbe,0xce,0xea,0x1e,0xc4,0x0a
  31739. };
  31740. /* uncompressed test */
  31741. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  31742. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  31743. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  31744. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  31745. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  31746. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  31747. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  31748. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  31749. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  31750. };
  31751. /* compressed prefix */
  31752. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  31753. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  31754. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  31755. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  31756. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  31757. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  31758. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  31759. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  31760. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  31761. };
  31762. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  31763. 0x0a,0xab,0x4c,0x90,0x05,0x01,0xb3,0xe2,
  31764. 0x4d,0x7c,0xdf,0x46,0x63,0x32,0x6a,0x3a,
  31765. 0x87,0xdf,0x5e,0x48,0x43,0xb2,0xcb,0xdb,
  31766. 0x67,0xcb,0xf6,0xe4,0x60,0xfe,0xc3,0x50,
  31767. 0xaa,0x53,0x71,0xb1,0x50,0x8f,0x9f,0x45,
  31768. 0x28,0xec,0xea,0x23,0xc4,0x36,0xd9,0x4b,
  31769. 0x5e,0x8f,0xcd,0x4f,0x68,0x1e,0x30,0xa6,
  31770. 0xac,0x00,0xa9,0x70,0x4a,0x18,0x8a,0x03
  31771. };
  31772. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  31773. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {0x0 };
  31774. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {0x72};
  31775. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {0xAF,0x82};
  31776. /* test of a 1024 byte long message */
  31777. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  31778. 0x08,0xb8,0xb2,0xb7,0x33,0x42,0x42,0x43,
  31779. 0x76,0x0f,0xe4,0x26,0xa4,0xb5,0x49,0x08,
  31780. 0x63,0x21,0x10,0xa6,0x6c,0x2f,0x65,0x91,
  31781. 0xea,0xbd,0x33,0x45,0xe3,0xe4,0xeb,0x98,
  31782. 0xfa,0x6e,0x26,0x4b,0xf0,0x9e,0xfe,0x12,
  31783. 0xee,0x50,0xf8,0xf5,0x4e,0x9f,0x77,0xb1,
  31784. 0xe3,0x55,0xf6,0xc5,0x05,0x44,0xe2,0x3f,
  31785. 0xb1,0x43,0x3d,0xdf,0x73,0xbe,0x84,0xd8,
  31786. 0x79,0xde,0x7c,0x00,0x46,0xdc,0x49,0x96,
  31787. 0xd9,0xe7,0x73,0xf4,0xbc,0x9e,0xfe,0x57,
  31788. 0x38,0x82,0x9a,0xdb,0x26,0xc8,0x1b,0x37,
  31789. 0xc9,0x3a,0x1b,0x27,0x0b,0x20,0x32,0x9d,
  31790. 0x65,0x86,0x75,0xfc,0x6e,0xa5,0x34,0xe0,
  31791. 0x81,0x0a,0x44,0x32,0x82,0x6b,0xf5,0x8c,
  31792. 0x94,0x1e,0xfb,0x65,0xd5,0x7a,0x33,0x8b,
  31793. 0xbd,0x2e,0x26,0x64,0x0f,0x89,0xff,0xbc,
  31794. 0x1a,0x85,0x8e,0xfc,0xb8,0x55,0x0e,0xe3,
  31795. 0xa5,0xe1,0x99,0x8b,0xd1,0x77,0xe9,0x3a,
  31796. 0x73,0x63,0xc3,0x44,0xfe,0x6b,0x19,0x9e,
  31797. 0xe5,0xd0,0x2e,0x82,0xd5,0x22,0xc4,0xfe,
  31798. 0xba,0x15,0x45,0x2f,0x80,0x28,0x8a,0x82,
  31799. 0x1a,0x57,0x91,0x16,0xec,0x6d,0xad,0x2b,
  31800. 0x3b,0x31,0x0d,0xa9,0x03,0x40,0x1a,0xa6,
  31801. 0x21,0x00,0xab,0x5d,0x1a,0x36,0x55,0x3e,
  31802. 0x06,0x20,0x3b,0x33,0x89,0x0c,0xc9,0xb8,
  31803. 0x32,0xf7,0x9e,0xf8,0x05,0x60,0xcc,0xb9,
  31804. 0xa3,0x9c,0xe7,0x67,0x96,0x7e,0xd6,0x28,
  31805. 0xc6,0xad,0x57,0x3c,0xb1,0x16,0xdb,0xef,
  31806. 0xef,0xd7,0x54,0x99,0xda,0x96,0xbd,0x68,
  31807. 0xa8,0xa9,0x7b,0x92,0x8a,0x8b,0xbc,0x10,
  31808. 0x3b,0x66,0x21,0xfc,0xde,0x2b,0xec,0xa1,
  31809. 0x23,0x1d,0x20,0x6b,0xe6,0xcd,0x9e,0xc7,
  31810. 0xaf,0xf6,0xf6,0xc9,0x4f,0xcd,0x72,0x04,
  31811. 0xed,0x34,0x55,0xc6,0x8c,0x83,0xf4,0xa4,
  31812. 0x1d,0xa4,0xaf,0x2b,0x74,0xef,0x5c,0x53,
  31813. 0xf1,0xd8,0xac,0x70,0xbd,0xcb,0x7e,0xd1,
  31814. 0x85,0xce,0x81,0xbd,0x84,0x35,0x9d,0x44,
  31815. 0x25,0x4d,0x95,0x62,0x9e,0x98,0x55,0xa9,
  31816. 0x4a,0x7c,0x19,0x58,0xd1,0xf8,0xad,0xa5,
  31817. 0xd0,0x53,0x2e,0xd8,0xa5,0xaa,0x3f,0xb2,
  31818. 0xd1,0x7b,0xa7,0x0e,0xb6,0x24,0x8e,0x59,
  31819. 0x4e,0x1a,0x22,0x97,0xac,0xbb,0xb3,0x9d,
  31820. 0x50,0x2f,0x1a,0x8c,0x6e,0xb6,0xf1,0xce,
  31821. 0x22,0xb3,0xde,0x1a,0x1f,0x40,0xcc,0x24,
  31822. 0x55,0x41,0x19,0xa8,0x31,0xa9,0xaa,0xd6,
  31823. 0x07,0x9c,0xad,0x88,0x42,0x5d,0xe6,0xbd,
  31824. 0xe1,0xa9,0x18,0x7e,0xbb,0x60,0x92,0xcf,
  31825. 0x67,0xbf,0x2b,0x13,0xfd,0x65,0xf2,0x70,
  31826. 0x88,0xd7,0x8b,0x7e,0x88,0x3c,0x87,0x59,
  31827. 0xd2,0xc4,0xf5,0xc6,0x5a,0xdb,0x75,0x53,
  31828. 0x87,0x8a,0xd5,0x75,0xf9,0xfa,0xd8,0x78,
  31829. 0xe8,0x0a,0x0c,0x9b,0xa6,0x3b,0xcb,0xcc,
  31830. 0x27,0x32,0xe6,0x94,0x85,0xbb,0xc9,0xc9,
  31831. 0x0b,0xfb,0xd6,0x24,0x81,0xd9,0x08,0x9b,
  31832. 0xec,0xcf,0x80,0xcf,0xe2,0xdf,0x16,0xa2,
  31833. 0xcf,0x65,0xbd,0x92,0xdd,0x59,0x7b,0x07,
  31834. 0x07,0xe0,0x91,0x7a,0xf4,0x8b,0xbb,0x75,
  31835. 0xfe,0xd4,0x13,0xd2,0x38,0xf5,0x55,0x5a,
  31836. 0x7a,0x56,0x9d,0x80,0xc3,0x41,0x4a,0x8d,
  31837. 0x08,0x59,0xdc,0x65,0xa4,0x61,0x28,0xba,
  31838. 0xb2,0x7a,0xf8,0x7a,0x71,0x31,0x4f,0x31,
  31839. 0x8c,0x78,0x2b,0x23,0xeb,0xfe,0x80,0x8b,
  31840. 0x82,0xb0,0xce,0x26,0x40,0x1d,0x2e,0x22,
  31841. 0xf0,0x4d,0x83,0xd1,0x25,0x5d,0xc5,0x1a,
  31842. 0xdd,0xd3,0xb7,0x5a,0x2b,0x1a,0xe0,0x78,
  31843. 0x45,0x04,0xdf,0x54,0x3a,0xf8,0x96,0x9b,
  31844. 0xe3,0xea,0x70,0x82,0xff,0x7f,0xc9,0x88,
  31845. 0x8c,0x14,0x4d,0xa2,0xaf,0x58,0x42,0x9e,
  31846. 0xc9,0x60,0x31,0xdb,0xca,0xd3,0xda,0xd9,
  31847. 0xaf,0x0d,0xcb,0xaa,0xaf,0x26,0x8c,0xb8,
  31848. 0xfc,0xff,0xea,0xd9,0x4f,0x3c,0x7c,0xa4,
  31849. 0x95,0xe0,0x56,0xa9,0xb4,0x7a,0xcd,0xb7,
  31850. 0x51,0xfb,0x73,0xe6,0x66,0xc6,0xc6,0x55,
  31851. 0xad,0xe8,0x29,0x72,0x97,0xd0,0x7a,0xd1,
  31852. 0xba,0x5e,0x43,0xf1,0xbc,0xa3,0x23,0x01,
  31853. 0x65,0x13,0x39,0xe2,0x29,0x04,0xcc,0x8c,
  31854. 0x42,0xf5,0x8c,0x30,0xc0,0x4a,0xaf,0xdb,
  31855. 0x03,0x8d,0xda,0x08,0x47,0xdd,0x98,0x8d,
  31856. 0xcd,0xa6,0xf3,0xbf,0xd1,0x5c,0x4b,0x4c,
  31857. 0x45,0x25,0x00,0x4a,0xa0,0x6e,0xef,0xf8,
  31858. 0xca,0x61,0x78,0x3a,0xac,0xec,0x57,0xfb,
  31859. 0x3d,0x1f,0x92,0xb0,0xfe,0x2f,0xd1,0xa8,
  31860. 0x5f,0x67,0x24,0x51,0x7b,0x65,0xe6,0x14,
  31861. 0xad,0x68,0x08,0xd6,0xf6,0xee,0x34,0xdf,
  31862. 0xf7,0x31,0x0f,0xdc,0x82,0xae,0xbf,0xd9,
  31863. 0x04,0xb0,0x1e,0x1d,0xc5,0x4b,0x29,0x27,
  31864. 0x09,0x4b,0x2d,0xb6,0x8d,0x6f,0x90,0x3b,
  31865. 0x68,0x40,0x1a,0xde,0xbf,0x5a,0x7e,0x08,
  31866. 0xd7,0x8f,0xf4,0xef,0x5d,0x63,0x65,0x3a,
  31867. 0x65,0x04,0x0c,0xf9,0xbf,0xd4,0xac,0xa7,
  31868. 0x98,0x4a,0x74,0xd3,0x71,0x45,0x98,0x67,
  31869. 0x80,0xfc,0x0b,0x16,0xac,0x45,0x16,0x49,
  31870. 0xde,0x61,0x88,0xa7,0xdb,0xdf,0x19,0x1f,
  31871. 0x64,0xb5,0xfc,0x5e,0x2a,0xb4,0x7b,0x57,
  31872. 0xf7,0xf7,0x27,0x6c,0xd4,0x19,0xc1,0x7a,
  31873. 0x3c,0xa8,0xe1,0xb9,0x39,0xae,0x49,0xe4,
  31874. 0x88,0xac,0xba,0x6b,0x96,0x56,0x10,0xb5,
  31875. 0x48,0x01,0x09,0xc8,0xb1,0x7b,0x80,0xe1,
  31876. 0xb7,0xb7,0x50,0xdf,0xc7,0x59,0x8d,0x5d,
  31877. 0x50,0x11,0xfd,0x2d,0xcc,0x56,0x00,0xa3,
  31878. 0x2e,0xf5,0xb5,0x2a,0x1e,0xcc,0x82,0x0e,
  31879. 0x30,0x8a,0xa3,0x42,0x72,0x1a,0xac,0x09,
  31880. 0x43,0xbf,0x66,0x86,0xb6,0x4b,0x25,0x79,
  31881. 0x37,0x65,0x04,0xcc,0xc4,0x93,0xd9,0x7e,
  31882. 0x6a,0xed,0x3f,0xb0,0xf9,0xcd,0x71,0xa4,
  31883. 0x3d,0xd4,0x97,0xf0,0x1f,0x17,0xc0,0xe2,
  31884. 0xcb,0x37,0x97,0xaa,0x2a,0x2f,0x25,0x66,
  31885. 0x56,0x16,0x8e,0x6c,0x49,0x6a,0xfc,0x5f,
  31886. 0xb9,0x32,0x46,0xf6,0xb1,0x11,0x63,0x98,
  31887. 0xa3,0x46,0xf1,0xa6,0x41,0xf3,0xb0,0x41,
  31888. 0xe9,0x89,0xf7,0x91,0x4f,0x90,0xcc,0x2c,
  31889. 0x7f,0xff,0x35,0x78,0x76,0xe5,0x06,0xb5,
  31890. 0x0d,0x33,0x4b,0xa7,0x7c,0x22,0x5b,0xc3,
  31891. 0x07,0xba,0x53,0x71,0x52,0xf3,0xf1,0x61,
  31892. 0x0e,0x4e,0xaf,0xe5,0x95,0xf6,0xd9,0xd9,
  31893. 0x0d,0x11,0xfa,0xa9,0x33,0xa1,0x5e,0xf1,
  31894. 0x36,0x95,0x46,0x86,0x8a,0x7f,0x3a,0x45,
  31895. 0xa9,0x67,0x68,0xd4,0x0f,0xd9,0xd0,0x34,
  31896. 0x12,0xc0,0x91,0xc6,0x31,0x5c,0xf4,0xfd,
  31897. 0xe7,0xcb,0x68,0x60,0x69,0x37,0x38,0x0d,
  31898. 0xb2,0xea,0xaa,0x70,0x7b,0x4c,0x41,0x85,
  31899. 0xc3,0x2e,0xdd,0xcd,0xd3,0x06,0x70,0x5e,
  31900. 0x4d,0xc1,0xff,0xc8,0x72,0xee,0xee,0x47,
  31901. 0x5a,0x64,0xdf,0xac,0x86,0xab,0xa4,0x1c,
  31902. 0x06,0x18,0x98,0x3f,0x87,0x41,0xc5,0xef,
  31903. 0x68,0xd3,0xa1,0x01,0xe8,0xa3,0xb8,0xca,
  31904. 0xc6,0x0c,0x90,0x5c,0x15,0xfc,0x91,0x08,
  31905. 0x40,0xb9,0x4c,0x00,0xa0,0xb9,0xd0
  31906. };
  31907. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  31908. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  31909. sizeof(msg2),
  31910. sizeof(msg3),
  31911. 0 /*sizeof(msg1)*/,
  31912. 0 /*sizeof(msg1)*/,
  31913. sizeof(msg4)
  31914. };
  31915. #ifndef NO_ASN
  31916. static const byte privateEd25519[] = {
  31917. 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
  31918. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  31919. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31920. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31921. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31922. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31923. };
  31924. static const byte badPrivateEd25519[] = {
  31925. 0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
  31926. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  31927. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31928. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31929. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31930. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  31931. 0xa1,0x22,0x04,0x21,0xd7,0x5a,0x98,0x01, /* octet len 0x20 -> 0x21 */
  31932. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  31933. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  31934. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  31935. 0xf7,0x07,0x51,0x1a,
  31936. 0x00 /* add additional bytes to make the pubkey bigger */
  31937. };
  31938. static const byte publicEd25519[] = {
  31939. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  31940. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  31941. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  31942. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  31943. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  31944. 0xf7,0x07,0x51,0x1a
  31945. };
  31946. /* size has been altered to catch if sanity check is done */
  31947. static const byte badPublicEd25519[] = {
  31948. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  31949. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  31950. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  31951. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  31952. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  31953. 0xf7,0x07,0x51,0x1a,
  31954. 0x00 /* add an additional byte to make the pubkey appear bigger */
  31955. };
  31956. static const byte privPubEd25519[] = {
  31957. 0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
  31958. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  31959. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31960. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31961. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31962. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  31963. 0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
  31964. 0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
  31965. 0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
  31966. 0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
  31967. 0x51,0x1a
  31968. };
  31969. word32 idx;
  31970. #endif /* NO_ASN */
  31971. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31972. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  31973. ed25519_key key3;
  31974. #endif
  31975. WOLFSSL_ENTER("ed25519_test");
  31976. /* create ed25519 keys */
  31977. #ifndef HAVE_FIPS
  31978. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31979. #else
  31980. ret = wc_InitRng(&rng);
  31981. #endif
  31982. if (ret != 0)
  31983. return WC_TEST_RET_ENC_EC(ret);
  31984. wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31985. wc_ed25519_init_ex(&key2, HEAP_HINT, devId);
  31986. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  31987. wc_ed25519_init_ex(&key3, HEAP_HINT, devId);
  31988. #endif
  31989. #ifdef HAVE_ED25519_MAKE_KEY
  31990. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key);
  31991. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key2);
  31992. #endif
  31993. /* helper functions for signature and key size */
  31994. keySz = (word32)wc_ed25519_size(&key);
  31995. sigSz = (word32)wc_ed25519_sig_size(&key);
  31996. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31997. defined(HAVE_ED25519_KEY_IMPORT)
  31998. for (i = 0; i < 6; i++) {
  31999. outlen = sizeof(out);
  32000. XMEMSET(out, 0, sizeof(out));
  32001. if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i],
  32002. pKeySz[i], &key) != 0)
  32003. return WC_TEST_RET_ENC_I(i);
  32004. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, &key) != 0)
  32005. return WC_TEST_RET_ENC_I(i);
  32006. if (XMEMCMP(out, sigs[i], 64))
  32007. return WC_TEST_RET_ENC_I(i);
  32008. #if defined(HAVE_ED25519_VERIFY)
  32009. /* test verify on good msg */
  32010. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32011. &key) != 0 || verify != 1)
  32012. return WC_TEST_RET_ENC_I(i);
  32013. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  32014. /* test verify on good msg using streaming interface directly */
  32015. if (wc_ed25519_verify_msg_init(out, outlen,
  32016. &key, (byte)Ed25519, NULL, 0) != 0)
  32017. return WC_TEST_RET_ENC_I(i);
  32018. for (j = 0; j < msgSz[i]; j += i) {
  32019. if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), &key) != 0)
  32020. return WC_TEST_RET_ENC_I(i);
  32021. }
  32022. if (wc_ed25519_verify_msg_final(out, outlen, &verify,
  32023. &key) != 0 || verify != 1)
  32024. return WC_TEST_RET_ENC_I(i);
  32025. #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */
  32026. /* test verify on bad msg */
  32027. out[outlen-1] = out[outlen-1] + 1;
  32028. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32029. &key) == 0 || verify == 1)
  32030. return WC_TEST_RET_ENC_I(i);
  32031. #endif /* HAVE_ED25519_VERIFY */
  32032. /* test api for import/exporting keys */
  32033. exportPSz = sizeof(exportPKey);
  32034. exportSSz = sizeof(exportSKey);
  32035. if (wc_ed25519_export_public(&key, exportPKey, &exportPSz) != 0)
  32036. return WC_TEST_RET_ENC_I(i);
  32037. if (wc_ed25519_import_public_ex(exportPKey, exportPSz, &key2, 1) != 0)
  32038. return WC_TEST_RET_ENC_I(i);
  32039. if (wc_ed25519_export_private_only(&key, exportSKey, &exportSSz) != 0)
  32040. return WC_TEST_RET_ENC_I(i);
  32041. if (wc_ed25519_import_private_key(exportSKey, exportSSz,
  32042. exportPKey, exportPSz, &key2) != 0)
  32043. return WC_TEST_RET_ENC_I(i);
  32044. /* clear "out" buffer and test sign with imported keys */
  32045. outlen = sizeof(out);
  32046. XMEMSET(out, 0, sizeof(out));
  32047. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, &key2) != 0)
  32048. return WC_TEST_RET_ENC_I(i);
  32049. #if defined(HAVE_ED25519_VERIFY)
  32050. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32051. &key2) != 0 || verify != 1)
  32052. return WC_TEST_RET_ENC_I(i);
  32053. if (XMEMCMP(out, sigs[i], 64))
  32054. return WC_TEST_RET_ENC_I(i);
  32055. #endif /* HAVE_ED25519_VERIFY */
  32056. }
  32057. {
  32058. /* Run tests for some rare code paths */
  32059. /* sig is exactly equal to the order */
  32060. static const byte rareEd1[] = {
  32061. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32062. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32063. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32064. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32065. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32066. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32067. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32068. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32069. };
  32070. /* sig is larger than the order before we get to the low part */
  32071. static const byte rareEd2[] = {
  32072. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32073. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32074. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32075. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32076. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32077. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32078. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32079. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10
  32080. };
  32081. /* sig is larger than the order in the low part */
  32082. static const byte rareEd3[] = {
  32083. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32084. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32085. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32086. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32087. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32088. 0xd6, 0x9c, 0xf9, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32089. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32090. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32091. };
  32092. /* sig is smaller than the order */
  32093. static const byte rareEd4[] = {
  32094. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32095. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32096. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32097. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32098. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32099. 0xd6, 0x9c, 0xf1, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32100. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32101. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32102. };
  32103. ret = wc_ed25519_import_private_key(sKeys[0], ED25519_KEY_SIZE,
  32104. pKeys[0], pKeySz[0], &key);
  32105. if (ret != 0)
  32106. return ret;
  32107. ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
  32108. &verify, &key);
  32109. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32110. return ret;
  32111. ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), msgs[0], msgSz[0],
  32112. &verify, &key);
  32113. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32114. return ret;
  32115. ret = wc_ed25519_verify_msg(rareEd3, sizeof(rareEd3), msgs[0], msgSz[0],
  32116. &verify, &key);
  32117. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32118. return ret;
  32119. ret = wc_ed25519_verify_msg(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
  32120. &verify, &key);
  32121. if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
  32122. return ret;
  32123. }
  32124. ret = ed25519ctx_test();
  32125. if (ret != 0)
  32126. return ret;
  32127. ret = ed25519ph_test();
  32128. if (ret != 0)
  32129. return ret;
  32130. #ifndef NO_ASN
  32131. /* Try ASN.1 encoded private-only key and public key. */
  32132. idx = 0;
  32133. ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, &key3,
  32134. sizeof(privateEd25519));
  32135. if (ret != 0)
  32136. return WC_TEST_RET_ENC_EC(ret);
  32137. idx = 0;
  32138. if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, &key3,
  32139. sizeof(badPrivateEd25519)) == 0)
  32140. return WC_TEST_RET_ENC_NC;
  32141. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3);
  32142. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32143. return WC_TEST_RET_ENC_EC(ret);
  32144. /* try with a buffer size that is too large */
  32145. idx = 0;
  32146. if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, &key3,
  32147. sizeof(badPublicEd25519)) == 0)
  32148. return WC_TEST_RET_ENC_NC;
  32149. idx = 0;
  32150. ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, &key3,
  32151. sizeof(publicEd25519));
  32152. if (ret != 0)
  32153. return WC_TEST_RET_ENC_EC(ret);
  32154. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3);
  32155. if (ret != 0)
  32156. return WC_TEST_RET_ENC_EC(ret);
  32157. if (XMEMCMP(out, sigs[0], 64))
  32158. return WC_TEST_RET_ENC_NC;
  32159. #if defined(HAVE_ED25519_VERIFY)
  32160. /* test verify on good msg */
  32161. ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, &key3);
  32162. if (ret != 0 || verify != 1)
  32163. return WC_TEST_RET_ENC_EC(ret);
  32164. #endif /* HAVE_ED25519_VERIFY */
  32165. wc_ed25519_free(&key3);
  32166. wc_ed25519_init(&key3);
  32167. idx = 0;
  32168. ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, &key3,
  32169. sizeof(privPubEd25519));
  32170. if (ret != 0)
  32171. return WC_TEST_RET_ENC_EC(ret);
  32172. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3);
  32173. if (ret != 0)
  32174. return WC_TEST_RET_ENC_EC(ret);
  32175. if (XMEMCMP(out, sigs[0], 64))
  32176. return WC_TEST_RET_ENC_NC;
  32177. wc_ed25519_free(&key3);
  32178. #endif /* NO_ASN */
  32179. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32180. /* clean up keys when done */
  32181. wc_ed25519_free(&key);
  32182. wc_ed25519_free(&key2);
  32183. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  32184. wc_FreeRng(&rng);
  32185. #endif
  32186. /* hush warnings of unused keySz and sigSz */
  32187. (void)keySz;
  32188. (void)sigSz;
  32189. ret = ed25519_test_check_key();
  32190. if (ret < 0)
  32191. return ret;
  32192. #ifdef WOLFSSL_TEST_CERT
  32193. ret = ed25519_test_cert();
  32194. if (ret < 0)
  32195. return ret;
  32196. #if defined(WOLFSSL_CERT_GEN) && defined(HAVE_ED25519_MAKE_KEY)
  32197. ret = ed25519_test_make_cert();
  32198. if (ret < 0)
  32199. return ret;
  32200. #endif /* WOLFSSL_CERT_GEN */
  32201. #endif /* WOLFSSL_TEST_CERT */
  32202. return 0;
  32203. }
  32204. #endif /* HAVE_ED25519 */
  32205. #ifdef HAVE_CURVE448
  32206. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32207. defined(HAVE_CURVE448_KEY_IMPORT)
  32208. /* Test the wc_curve448_check_public API.
  32209. *
  32210. * returns 0 on success and -ve on failure.
  32211. */
  32212. static wc_test_ret_t curve448_check_public_test(void)
  32213. {
  32214. /* Little-endian values that will fail */
  32215. byte fail_le[][CURVE448_KEY_SIZE] = {
  32216. {
  32217. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32218. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32219. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32220. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32221. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32222. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32223. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32224. },
  32225. {
  32226. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32227. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32228. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32229. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32230. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32231. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32232. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32233. },
  32234. };
  32235. /* Big-endian values that will fail */
  32236. byte fail_be[][CURVE448_KEY_SIZE] = {
  32237. {
  32238. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32239. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32240. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32241. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32242. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32243. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32244. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32245. },
  32246. {
  32247. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32248. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32249. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32250. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32251. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32252. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32253. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32254. },
  32255. };
  32256. /* Good or valid public value */
  32257. byte good[CURVE448_KEY_SIZE] = {
  32258. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32259. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32260. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32261. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32262. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32263. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32264. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32265. };
  32266. int i;
  32267. wc_test_ret_t ret;
  32268. /* Parameter checks */
  32269. /* NULL pointer */
  32270. ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN);
  32271. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32272. return WC_TEST_RET_ENC_EC(ret);
  32273. ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN);
  32274. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32275. return WC_TEST_RET_ENC_EC(ret);
  32276. /* Length of 0 treated differently to other invalid lengths for TLS */
  32277. ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN);
  32278. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32279. return WC_TEST_RET_ENC_EC(ret);
  32280. ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN);
  32281. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32282. return WC_TEST_RET_ENC_EC(ret);
  32283. /* Length not CURVE448_KEY_SIZE */
  32284. for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) {
  32285. if (i == CURVE448_KEY_SIZE)
  32286. continue;
  32287. if (wc_curve448_check_public(good, (word32)i, EC448_LITTLE_ENDIAN) !=
  32288. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32289. return WC_TEST_RET_ENC_I(i);
  32290. }
  32291. if (wc_curve448_check_public(good, (word32)i, EC448_BIG_ENDIAN) !=
  32292. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32293. return WC_TEST_RET_ENC_I(i);
  32294. }
  32295. }
  32296. /* Little-endian fail cases */
  32297. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  32298. if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE,
  32299. EC448_LITTLE_ENDIAN) == 0) {
  32300. return WC_TEST_RET_ENC_I(i);
  32301. }
  32302. }
  32303. /* Big-endian fail cases */
  32304. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  32305. if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE,
  32306. EC448_BIG_ENDIAN) == 0) {
  32307. return WC_TEST_RET_ENC_I(i);
  32308. }
  32309. }
  32310. /* Check a valid public value works! */
  32311. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE,
  32312. EC448_LITTLE_ENDIAN);
  32313. if (ret != 0)
  32314. return WC_TEST_RET_ENC_EC(ret);
  32315. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN);
  32316. if (ret != 0)
  32317. return WC_TEST_RET_ENC_EC(ret);
  32318. return 0;
  32319. }
  32320. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32321. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
  32322. {
  32323. WC_RNG rng;
  32324. wc_test_ret_t ret;
  32325. #ifdef HAVE_CURVE448_SHARED_SECRET
  32326. byte sharedA[CURVE448_KEY_SIZE];
  32327. byte sharedB[CURVE448_KEY_SIZE];
  32328. word32 y;
  32329. #endif
  32330. #ifdef HAVE_CURVE448_KEY_EXPORT
  32331. byte exportBuf[CURVE448_KEY_SIZE];
  32332. #endif
  32333. word32 x = 0;
  32334. curve448_key userA, userB, pubKey;
  32335. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32336. defined(HAVE_CURVE448_KEY_IMPORT)
  32337. /* test vectors from
  32338. https://www.rfc-editor.org/rfc/rfc7748.html
  32339. */
  32340. /* secret key for party a */
  32341. byte sa[] = {
  32342. 0x6b, 0x72, 0x98, 0xa5, 0xc0, 0xd8, 0xc2, 0x9a,
  32343. 0x1d, 0xab, 0x27, 0xf1, 0xa6, 0x82, 0x63, 0x00,
  32344. 0x91, 0x73, 0x89, 0x44, 0x97, 0x41, 0xa9, 0x74,
  32345. 0xf5, 0xba, 0xc9, 0xd9, 0x8d, 0xc2, 0x98, 0xd4,
  32346. 0x65, 0x55, 0xbc, 0xe8, 0xba, 0xe8, 0x9e, 0xee,
  32347. 0xd4, 0x00, 0x58, 0x4b, 0xb0, 0x46, 0xcf, 0x75,
  32348. 0x57, 0x9f, 0x51, 0xd1, 0x25, 0x49, 0x8f, 0x9a,
  32349. };
  32350. /* public key for party a */
  32351. byte pa[] = {
  32352. 0xa0, 0x1f, 0xc4, 0x32, 0xe5, 0x80, 0x7f, 0x17,
  32353. 0x53, 0x0d, 0x12, 0x88, 0xda, 0x12, 0x5b, 0x0c,
  32354. 0xd4, 0x53, 0xd9, 0x41, 0x72, 0x64, 0x36, 0xc8,
  32355. 0xbb, 0xd9, 0xc5, 0x22, 0x2c, 0x3d, 0xa7, 0xfa,
  32356. 0x63, 0x9c, 0xe0, 0x3d, 0xb8, 0xd2, 0x3b, 0x27,
  32357. 0x4a, 0x07, 0x21, 0xa1, 0xae, 0xd5, 0x22, 0x7d,
  32358. 0xe6, 0xe3, 0xb7, 0x31, 0xcc, 0xf7, 0x08, 0x9b,
  32359. };
  32360. /* secret key for party b */
  32361. byte sb[] = {
  32362. 0x2d, 0x99, 0x73, 0x51, 0xb6, 0x10, 0x6f, 0x36,
  32363. 0xb0, 0xd1, 0x09, 0x1b, 0x92, 0x9c, 0x4c, 0x37,
  32364. 0x21, 0x3e, 0x0d, 0x2b, 0x97, 0xe8, 0x5e, 0xbb,
  32365. 0x20, 0xc1, 0x27, 0x69, 0x1d, 0x0d, 0xad, 0x8f,
  32366. 0x1d, 0x81, 0x75, 0xb0, 0x72, 0x37, 0x45, 0xe6,
  32367. 0x39, 0xa3, 0xcb, 0x70, 0x44, 0x29, 0x0b, 0x99,
  32368. 0xe0, 0xe2, 0xa0, 0xc2, 0x7a, 0x6a, 0x30, 0x1c,
  32369. };
  32370. /* public key for party b */
  32371. byte pb[] = {
  32372. 0x09, 0x36, 0xf3, 0x7b, 0xc6, 0xc1, 0xbd, 0x07,
  32373. 0xae, 0x3d, 0xec, 0x7a, 0xb5, 0xdc, 0x06, 0xa7,
  32374. 0x3c, 0xa1, 0x32, 0x42, 0xfb, 0x34, 0x3e, 0xfc,
  32375. 0x72, 0xb9, 0xd8, 0x27, 0x30, 0xb4, 0x45, 0xf3,
  32376. 0xd4, 0xb0, 0xbd, 0x07, 0x71, 0x62, 0xa4, 0x6d,
  32377. 0xcf, 0xec, 0x6f, 0x9b, 0x59, 0x0b, 0xfc, 0xbc,
  32378. 0xf5, 0x20, 0xcd, 0xb0, 0x29, 0xa8, 0xb7, 0x3e,
  32379. };
  32380. /* expected shared key */
  32381. byte ss[] = {
  32382. 0x9d, 0x87, 0x4a, 0x51, 0x37, 0x50, 0x9a, 0x44,
  32383. 0x9a, 0xd5, 0x85, 0x30, 0x40, 0x24, 0x1c, 0x52,
  32384. 0x36, 0x39, 0x54, 0x35, 0xc3, 0x64, 0x24, 0xfd,
  32385. 0x56, 0x0b, 0x0c, 0xb6, 0x2b, 0x28, 0x1d, 0x28,
  32386. 0x52, 0x75, 0xa7, 0x40, 0xce, 0x32, 0xa2, 0x2d,
  32387. 0xd1, 0x74, 0x0f, 0x4a, 0xa9, 0x16, 0x1c, 0xec,
  32388. 0x95, 0xcc, 0xc6, 0x1a, 0x18, 0xf4, 0xff, 0x07,
  32389. };
  32390. #endif /* HAVE_CURVE448_SHARED_SECRET */
  32391. (void)x;
  32392. WOLFSSL_ENTER("curve448_test");
  32393. #ifndef HAVE_FIPS
  32394. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32395. #else
  32396. ret = wc_InitRng(&rng);
  32397. #endif
  32398. if (ret != 0)
  32399. return WC_TEST_RET_ENC_EC(ret);
  32400. wc_curve448_init(&userA);
  32401. wc_curve448_init(&userB);
  32402. wc_curve448_init(&pubKey);
  32403. /* make curve448 keys */
  32404. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA);
  32405. if (ret != 0)
  32406. return WC_TEST_RET_ENC_EC(ret);
  32407. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB);
  32408. if (ret != 0)
  32409. return WC_TEST_RET_ENC_EC(ret);
  32410. #ifdef HAVE_CURVE448_SHARED_SECRET
  32411. /* find shared secret key */
  32412. x = sizeof(sharedA);
  32413. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32414. if (ret != 0)
  32415. return WC_TEST_RET_ENC_EC(ret);
  32416. y = sizeof(sharedB);
  32417. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32418. if (ret != 0)
  32419. return WC_TEST_RET_ENC_EC(ret);
  32420. /* compare shared secret keys to test they are the same */
  32421. if (y != x)
  32422. return WC_TEST_RET_ENC_NC;
  32423. if (XMEMCMP(sharedA, sharedB, x))
  32424. return WC_TEST_RET_ENC_NC;
  32425. #endif
  32426. #ifdef HAVE_CURVE448_KEY_EXPORT
  32427. /* export a public key and import it for another user */
  32428. x = sizeof(exportBuf);
  32429. ret = wc_curve448_export_public(&userA, exportBuf, &x);
  32430. if (ret != 0)
  32431. return WC_TEST_RET_ENC_EC(ret);
  32432. #ifdef HAVE_CURVE448_KEY_IMPORT
  32433. ret = wc_curve448_import_public(exportBuf, x, &pubKey);
  32434. if (ret != 0)
  32435. return WC_TEST_RET_ENC_EC(ret);
  32436. #endif
  32437. #endif
  32438. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32439. defined(HAVE_CURVE448_KEY_IMPORT)
  32440. /* test shared key after importing a public key */
  32441. XMEMSET(sharedB, 0, sizeof(sharedB));
  32442. y = sizeof(sharedB);
  32443. ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y);
  32444. if (ret != 0)
  32445. return WC_TEST_RET_ENC_EC(ret);
  32446. if (XMEMCMP(sharedA, sharedB, y))
  32447. return WC_TEST_RET_ENC_NC;
  32448. /* import RFC test vectors and compare shared key */
  32449. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32450. if (ret != 0)
  32451. return WC_TEST_RET_ENC_EC(ret);
  32452. ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB);
  32453. if (ret != 0)
  32454. return WC_TEST_RET_ENC_EC(ret);
  32455. /* test against known test vector */
  32456. XMEMSET(sharedB, 0, sizeof(sharedB));
  32457. y = sizeof(sharedB);
  32458. ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y);
  32459. if (ret != 0)
  32460. return WC_TEST_RET_ENC_EC(ret);
  32461. if (XMEMCMP(ss, sharedB, y))
  32462. return WC_TEST_RET_ENC_NC;
  32463. /* test swapping roles of keys and generating same shared key */
  32464. XMEMSET(sharedB, 0, sizeof(sharedB));
  32465. y = sizeof(sharedB);
  32466. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32467. if (ret != 0)
  32468. return WC_TEST_RET_ENC_EC(ret);
  32469. if (XMEMCMP(ss, sharedB, y))
  32470. return WC_TEST_RET_ENC_NC;
  32471. /* test with 1 generated key and 1 from known test vector */
  32472. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32473. if (ret != 0)
  32474. return WC_TEST_RET_ENC_EC(ret);
  32475. ret = wc_curve448_make_key(&rng, 56, &userB);
  32476. if (ret != 0)
  32477. return WC_TEST_RET_ENC_EC(ret);
  32478. x = sizeof(sharedA);
  32479. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32480. if (ret != 0)
  32481. return WC_TEST_RET_ENC_EC(ret);
  32482. y = sizeof(sharedB);
  32483. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32484. if (ret != 0)
  32485. return WC_TEST_RET_ENC_EC(ret);
  32486. /* compare shared secret keys to test they are the same */
  32487. if (y != x)
  32488. return WC_TEST_RET_ENC_NC;
  32489. if (XMEMCMP(sharedA, sharedB, x))
  32490. return WC_TEST_RET_ENC_NC;
  32491. ret = curve448_check_public_test();
  32492. if (ret != 0)
  32493. return ret;
  32494. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32495. /* clean up keys when done */
  32496. wc_curve448_free(&pubKey);
  32497. wc_curve448_free(&userB);
  32498. wc_curve448_free(&userA);
  32499. wc_FreeRng(&rng);
  32500. return 0;
  32501. }
  32502. #endif /* HAVE_CURVE448 */
  32503. #ifdef HAVE_ED448
  32504. #ifdef WOLFSSL_TEST_CERT
  32505. static wc_test_ret_t ed448_test_cert(void)
  32506. {
  32507. DecodedCert cert[2];
  32508. DecodedCert* serverCert = NULL;
  32509. DecodedCert* caCert = NULL;
  32510. #ifdef HAVE_ED448_VERIFY
  32511. ed448_key key;
  32512. ed448_key* pubKey = NULL;
  32513. int verify;
  32514. #endif /* HAVE_ED448_VERIFY */
  32515. wc_test_ret_t ret;
  32516. byte* tmp;
  32517. size_t bytes;
  32518. XFILE file;
  32519. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32520. if (tmp == NULL) {
  32521. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32522. }
  32523. #ifdef USE_CERT_BUFFERS_256
  32524. XMEMCPY(tmp, ca_ed448_cert, sizeof_ca_ed448_cert);
  32525. bytes = sizeof_ca_ed448_cert;
  32526. #elif !defined(NO_FILESYSTEM)
  32527. file = XFOPEN(caEd448Cert, "rb");
  32528. if (file == NULL) {
  32529. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32530. }
  32531. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32532. XFCLOSE(file);
  32533. if (bytes == 0)
  32534. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32535. #else
  32536. /* No certificate to use. */
  32537. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32538. #endif
  32539. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  32540. caCert = &cert[0];
  32541. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  32542. if (ret != 0)
  32543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32544. #ifdef USE_CERT_BUFFERS_256
  32545. XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert);
  32546. bytes = sizeof_server_ed448_cert;
  32547. #elif !defined(NO_FILESYSTEM)
  32548. file = XFOPEN(serverEd448Cert, "rb");
  32549. if (file == NULL) {
  32550. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32551. }
  32552. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32553. XFCLOSE(file);
  32554. if (bytes == 0)
  32555. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32556. #else
  32557. /* No certificate to use. */
  32558. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32559. #endif
  32560. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  32561. serverCert = &cert[1];
  32562. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  32563. if (ret != 0)
  32564. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32565. #ifdef HAVE_ED448_VERIFY
  32566. ret = wc_ed448_init(&key);
  32567. if (ret < 0)
  32568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32569. pubKey = &key;
  32570. ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey);
  32571. if (ret < 0)
  32572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32573. ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength,
  32574. serverCert->source + serverCert->certBegin,
  32575. serverCert->sigIndex - serverCert->certBegin,
  32576. &verify, pubKey, NULL, 0);
  32577. if (ret < 0 || verify != 1) {
  32578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32579. }
  32580. #endif /* HAVE_ED448_VERIFY */
  32581. done:
  32582. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32583. #ifdef HAVE_ED448_VERIFY
  32584. wc_ed448_free(pubKey);
  32585. #endif /* HAVE_ED448_VERIFY */
  32586. if (caCert != NULL)
  32587. FreeDecodedCert(caCert);
  32588. if (serverCert != NULL)
  32589. FreeDecodedCert(serverCert);
  32590. return ret;
  32591. }
  32592. static wc_test_ret_t ed448_test_make_cert(void)
  32593. {
  32594. WC_RNG rng;
  32595. Cert cert;
  32596. DecodedCert decode;
  32597. ed448_key key;
  32598. ed448_key* privKey = NULL;
  32599. wc_test_ret_t ret = 0;
  32600. byte* tmp = NULL;
  32601. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  32602. #ifndef HAVE_FIPS
  32603. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32604. #else
  32605. ret = wc_InitRng(&rng);
  32606. #endif
  32607. if (ret != 0)
  32608. return WC_TEST_RET_ENC_EC(ret);
  32609. wc_ed448_init(&key);
  32610. privKey = &key;
  32611. wc_ed448_make_key(&rng, ED448_KEY_SIZE, privKey);
  32612. cert.daysValid = 365 * 2;
  32613. cert.selfSigned = 1;
  32614. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  32615. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  32616. cert.isCA = 0;
  32617. #ifdef WOLFSSL_CERT_EXT
  32618. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  32619. if (ret < 0)
  32620. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32621. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32622. if (ret < 0)
  32623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32624. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32625. if (ret < 0)
  32626. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32627. #endif
  32628. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32629. if (tmp == NULL) {
  32630. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32631. }
  32632. cert.sigType = CTC_ED448;
  32633. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng);
  32634. if (ret < 0)
  32635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32636. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE,
  32637. privKey, &rng);
  32638. if (ret < 0)
  32639. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32640. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  32641. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  32642. FreeDecodedCert(&decode);
  32643. if (ret != 0)
  32644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32645. done:
  32646. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32647. wc_ed448_free(privKey);
  32648. wc_FreeRng(&rng);
  32649. return ret;
  32650. }
  32651. #endif /* WOLFSSL_TEST_CERT */
  32652. #if defined(HAVE_ED448_KEY_IMPORT)
  32653. static wc_test_ret_t ed448_test_check_key(void)
  32654. {
  32655. /* Fails to find x-ordinate from this y-ordinate. */
  32656. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  32657. 0x40,
  32658. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32659. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32660. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32661. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32662. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32663. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32664. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32665. 0x00
  32666. };
  32667. /* Y-ordinate value larger than prime. */
  32668. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  32669. 0x40,
  32670. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32671. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32672. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32673. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32674. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32675. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32676. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32677. 0xff
  32678. };
  32679. /* Y-ordinate value equal to prime. */
  32680. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  32681. 0x40,
  32682. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32683. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32684. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32685. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  32686. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32687. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32688. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32689. 0xff
  32690. };
  32691. /* Y-ordinate value equal to prime - 1. */
  32692. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  32693. 0x40,
  32694. 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32695. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32696. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32697. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  32698. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32699. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32700. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32701. 0xff
  32702. };
  32703. ed448_key key;
  32704. int ret;
  32705. int res = 0;
  32706. /* Initialize key for use. */
  32707. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  32708. if (ret != 0) {
  32709. return WC_TEST_RET_ENC_NC;
  32710. }
  32711. /* Load bad public key only and perform checks. */
  32712. ret = wc_ed448_import_public(key_bad_y, ED448_PUB_KEY_SIZE + 1, &key);
  32713. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  32714. res = WC_TEST_RET_ENC_NC;
  32715. }
  32716. if (ret == 0) {
  32717. /* Load bad public key only and perform checks. */
  32718. ret = wc_ed448_import_public(key_bad_y_max, ED448_PUB_KEY_SIZE + 1,
  32719. &key);
  32720. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  32721. res = WC_TEST_RET_ENC_NC;
  32722. }
  32723. }
  32724. if (res == 0) {
  32725. /* Load bad public key only and perform checks. */
  32726. ret = wc_ed448_import_public(key_bad_y_is_p, ED448_PUB_KEY_SIZE + 1,
  32727. &key);
  32728. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  32729. res = WC_TEST_RET_ENC_NC;
  32730. }
  32731. }
  32732. if (res == 0) {
  32733. /* Load good public key only and perform checks. */
  32734. ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1,
  32735. &key);
  32736. if (ret != 0) {
  32737. res = WC_TEST_RET_ENC_NC;
  32738. }
  32739. }
  32740. /* Dispose of key. */
  32741. wc_ed448_free(&key);
  32742. return res;
  32743. }
  32744. #endif
  32745. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  32746. defined(HAVE_ED448_KEY_IMPORT)
  32747. static wc_test_ret_t ed448_ctx_test(void)
  32748. {
  32749. wc_test_ret_t ret;
  32750. byte out[ED448_SIG_SIZE];
  32751. word32 outlen;
  32752. #ifdef HAVE_ED448_VERIFY
  32753. int verify;
  32754. #endif /* HAVE_ED448_VERIFY */
  32755. ed448_key key;
  32756. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  32757. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  32758. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  32759. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  32760. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  32761. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  32762. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  32763. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  32764. 0x4e
  32765. };
  32766. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  32767. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  32768. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  32769. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  32770. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  32771. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  32772. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  32773. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  32774. 0x80
  32775. };
  32776. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx[] = {
  32777. 0xd4, 0xf8, 0xf6, 0x13, 0x17, 0x70, 0xdd, 0x46,
  32778. 0xf4, 0x08, 0x67, 0xd6, 0xfd, 0x5d, 0x50, 0x55,
  32779. 0xde, 0x43, 0x54, 0x1f, 0x8c, 0x5e, 0x35, 0xab,
  32780. 0xbc, 0xd0, 0x01, 0xb3, 0x2a, 0x89, 0xf7, 0xd2,
  32781. 0x15, 0x1f, 0x76, 0x47, 0xf1, 0x1d, 0x8c, 0xa2,
  32782. 0xae, 0x27, 0x9f, 0xb8, 0x42, 0xd6, 0x07, 0x21,
  32783. 0x7f, 0xce, 0x6e, 0x04, 0x2f, 0x68, 0x15, 0xea,
  32784. 0x00, 0x0c, 0x85, 0x74, 0x1d, 0xe5, 0xc8, 0xda,
  32785. 0x11, 0x44, 0xa6, 0xa1, 0xab, 0xa7, 0xf9, 0x6d,
  32786. 0xe4, 0x25, 0x05, 0xd7, 0xa7, 0x29, 0x85, 0x24,
  32787. 0xfd, 0xa5, 0x38, 0xfc, 0xcb, 0xbb, 0x75, 0x4f,
  32788. 0x57, 0x8c, 0x1c, 0xad, 0x10, 0xd5, 0x4d, 0x0d,
  32789. 0x54, 0x28, 0x40, 0x7e, 0x85, 0xdc, 0xbc, 0x98,
  32790. 0xa4, 0x91, 0x55, 0xc1, 0x37, 0x64, 0xe6, 0x6c,
  32791. 0x3c, 0x00
  32792. };
  32793. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  32794. 0x03
  32795. };
  32796. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  32797. 0x66,0x6f,0x6f
  32798. };
  32799. outlen = sizeof(out);
  32800. XMEMSET(out, 0, sizeof(out));
  32801. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  32802. if (ret != 0)
  32803. return WC_TEST_RET_ENC_EC(ret);
  32804. ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx,
  32805. sizeof(pKeyCtx), &key);
  32806. if (ret != 0)
  32807. return WC_TEST_RET_ENC_EC(ret);
  32808. ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  32809. contextCtx, sizeof(contextCtx));
  32810. if (ret != 0)
  32811. return WC_TEST_RET_ENC_EC(ret);
  32812. if (XMEMCMP(out, sigCtx, sizeof(sigCtx)))
  32813. return WC_TEST_RET_ENC_NC;
  32814. #if defined(HAVE_ED448_VERIFY)
  32815. /* test verify on good msg */
  32816. ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key,
  32817. contextCtx, sizeof(contextCtx));
  32818. if (ret != 0 || verify != 1)
  32819. return WC_TEST_RET_ENC_EC(ret);
  32820. #endif
  32821. wc_ed448_free(&key);
  32822. return 0;
  32823. }
  32824. static wc_test_ret_t ed448ph_test(void)
  32825. {
  32826. wc_test_ret_t ret;
  32827. byte out[ED448_SIG_SIZE];
  32828. word32 outlen;
  32829. #ifdef HAVE_ED448_VERIFY
  32830. int verify;
  32831. #endif /* HAVE_ED448_VERIFY */
  32832. ed448_key key;
  32833. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  32834. 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
  32835. 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
  32836. 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
  32837. 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42,
  32838. 0xef, 0x78, 0x22, 0xe0, 0xd5, 0x10, 0x41, 0x27,
  32839. 0xdc, 0x05, 0xd6, 0xdb, 0xef, 0xde, 0x69, 0xe3,
  32840. 0xab, 0x2c, 0xec, 0x7c, 0x86, 0x7c, 0x6e, 0x2c,
  32841. 0x49
  32842. };
  32843. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  32844. 0x25, 0x9b, 0x71, 0xc1, 0x9f, 0x83, 0xef, 0x77,
  32845. 0xa7, 0xab, 0xd2, 0x65, 0x24, 0xcb, 0xdb, 0x31,
  32846. 0x61, 0xb5, 0x90, 0xa4, 0x8f, 0x7d, 0x17, 0xde,
  32847. 0x3e, 0xe0, 0xba, 0x9c, 0x52, 0xbe, 0xb7, 0x43,
  32848. 0xc0, 0x94, 0x28, 0xa1, 0x31, 0xd6, 0xb1, 0xb5,
  32849. 0x73, 0x03, 0xd9, 0x0d, 0x81, 0x32, 0xc2, 0x76,
  32850. 0xd5, 0xed, 0x3d, 0x5d, 0x01, 0xc0, 0xf5, 0x38,
  32851. 0x80
  32852. };
  32853. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  32854. 0x82, 0x2f, 0x69, 0x01, 0xf7, 0x48, 0x0f, 0x3d,
  32855. 0x5f, 0x56, 0x2c, 0x59, 0x29, 0x94, 0xd9, 0x69,
  32856. 0x36, 0x02, 0x87, 0x56, 0x14, 0x48, 0x32, 0x56,
  32857. 0x50, 0x56, 0x00, 0xbb, 0xc2, 0x81, 0xae, 0x38,
  32858. 0x1f, 0x54, 0xd6, 0xbc, 0xe2, 0xea, 0x91, 0x15,
  32859. 0x74, 0x93, 0x2f, 0x52, 0xa4, 0xe6, 0xca, 0xdd,
  32860. 0x78, 0x76, 0x93, 0x75, 0xec, 0x3f, 0xfd, 0x1b,
  32861. 0x80, 0x1a, 0x0d, 0x9b, 0x3f, 0x40, 0x30, 0xcd,
  32862. 0x43, 0x39, 0x64, 0xb6, 0x45, 0x7e, 0xa3, 0x94,
  32863. 0x76, 0x51, 0x12, 0x14, 0xf9, 0x74, 0x69, 0xb5,
  32864. 0x7d, 0xd3, 0x2d, 0xbc, 0x56, 0x0a, 0x9a, 0x94,
  32865. 0xd0, 0x0b, 0xff, 0x07, 0x62, 0x04, 0x64, 0xa3,
  32866. 0xad, 0x20, 0x3d, 0xf7, 0xdc, 0x7c, 0xe3, 0x60,
  32867. 0xc3, 0xcd, 0x36, 0x96, 0xd9, 0xd9, 0xfa, 0xb9,
  32868. 0x0f, 0x00
  32869. };
  32870. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  32871. 0xc3, 0x22, 0x99, 0xd4, 0x6e, 0xc8, 0xff, 0x02,
  32872. 0xb5, 0x45, 0x40, 0x98, 0x28, 0x14, 0xdc, 0xe9,
  32873. 0xa0, 0x58, 0x12, 0xf8, 0x19, 0x62, 0xb6, 0x49,
  32874. 0xd5, 0x28, 0x09, 0x59, 0x16, 0xa2, 0xaa, 0x48,
  32875. 0x10, 0x65, 0xb1, 0x58, 0x04, 0x23, 0xef, 0x92,
  32876. 0x7e, 0xcf, 0x0a, 0xf5, 0x88, 0x8f, 0x90, 0xda,
  32877. 0x0f, 0x6a, 0x9a, 0x85, 0xad, 0x5d, 0xc3, 0xf2,
  32878. 0x80, 0xd9, 0x12, 0x24, 0xba, 0x99, 0x11, 0xa3,
  32879. 0x65, 0x3d, 0x00, 0xe4, 0x84, 0xe2, 0xce, 0x23,
  32880. 0x25, 0x21, 0x48, 0x1c, 0x86, 0x58, 0xdf, 0x30,
  32881. 0x4b, 0xb7, 0x74, 0x5a, 0x73, 0x51, 0x4c, 0xdb,
  32882. 0x9b, 0xf3, 0xe1, 0x57, 0x84, 0xab, 0x71, 0x28,
  32883. 0x4f, 0x8d, 0x07, 0x04, 0xa6, 0x08, 0xc5, 0x4a,
  32884. 0x6b, 0x62, 0xd9, 0x7b, 0xeb, 0x51, 0x1d, 0x13,
  32885. 0x21, 0x00
  32886. };
  32887. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  32888. 0x61,0x62,0x63
  32889. };
  32890. /* SHA-512 hash of msgPh */
  32891. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  32892. 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
  32893. 0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
  32894. 0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
  32895. 0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39,
  32896. 0xd5, 0xa1, 0x5b, 0xef, 0x18, 0x6a, 0x53, 0x86,
  32897. 0xc7, 0x57, 0x44, 0xc0, 0x52, 0x7e, 0x1f, 0xaa,
  32898. 0x9f, 0x87, 0x26, 0xe4, 0x62, 0xa1, 0x2a, 0x4f,
  32899. 0xeb, 0x06, 0xbd, 0x88, 0x01, 0xe7, 0x51, 0xe4
  32900. };
  32901. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  32902. 0x66,0x6f,0x6f
  32903. };
  32904. outlen = sizeof(out);
  32905. XMEMSET(out, 0, sizeof(out));
  32906. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  32907. if (ret != 0)
  32908. return WC_TEST_RET_ENC_EC(ret);
  32909. ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh,
  32910. sizeof(pKeyPh), &key);
  32911. if (ret != 0)
  32912. return WC_TEST_RET_ENC_EC(ret);
  32913. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL,
  32914. 0);
  32915. if (ret != 0)
  32916. return WC_TEST_RET_ENC_EC(ret);
  32917. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  32918. return WC_TEST_RET_ENC_NC;
  32919. #if defined(HAVE_ED448_VERIFY)
  32920. /* test verify on good msg */
  32921. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  32922. NULL, 0);
  32923. if (ret != 0 || verify != 1) {
  32924. return WC_TEST_RET_ENC_EC(ret);
  32925. }
  32926. #endif
  32927. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  32928. contextPh2, sizeof(contextPh2));
  32929. if (ret != 0)
  32930. return WC_TEST_RET_ENC_EC(ret);
  32931. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  32932. return WC_TEST_RET_ENC_NC;
  32933. #if defined(HAVE_ED448_VERIFY)
  32934. /* test verify on good msg */
  32935. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  32936. contextPh2, sizeof(contextPh2));
  32937. if (ret != 0 || verify != 1) {
  32938. return WC_TEST_RET_ENC_EC(ret);
  32939. }
  32940. #endif
  32941. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL,
  32942. 0);
  32943. if (ret != 0)
  32944. return WC_TEST_RET_ENC_EC(ret);
  32945. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  32946. return WC_TEST_RET_ENC_NC;
  32947. #if defined(HAVE_ED448_VERIFY)
  32948. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  32949. &key, NULL, 0);
  32950. if (ret != 0 || verify != 1) {
  32951. return WC_TEST_RET_ENC_EC(ret);
  32952. }
  32953. #endif
  32954. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  32955. contextPh2, sizeof(contextPh2));
  32956. if (ret != 0)
  32957. return WC_TEST_RET_ENC_EC(ret);
  32958. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  32959. return WC_TEST_RET_ENC_NC;
  32960. #if defined(HAVE_ED448_VERIFY)
  32961. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  32962. &key, contextPh2, sizeof(contextPh2));
  32963. if (ret != 0 || verify != 1) {
  32964. return WC_TEST_RET_ENC_EC(ret);
  32965. }
  32966. #endif
  32967. wc_ed448_free(&key);
  32968. return 0;
  32969. }
  32970. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  32971. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
  32972. {
  32973. wc_test_ret_t ret;
  32974. WC_RNG rng;
  32975. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  32976. defined(HAVE_ED448_KEY_IMPORT)
  32977. byte out[ED448_SIG_SIZE];
  32978. int i;
  32979. word32 outlen;
  32980. #ifdef HAVE_ED448_VERIFY
  32981. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  32982. int j;
  32983. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  32984. int verify;
  32985. #endif /* HAVE_ED448_VERIFY */
  32986. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  32987. word32 keySz, sigSz;
  32988. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32989. ed448_key *key = NULL;
  32990. ed448_key *key2 = NULL;
  32991. #else
  32992. ed448_key key[1];
  32993. ed448_key key2[1];
  32994. #endif
  32995. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  32996. defined(HAVE_ED448_KEY_IMPORT)
  32997. /* test vectors from
  32998. https://tools.ietf.org/html/rfc8032
  32999. */
  33000. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  33001. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33002. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33003. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33004. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33005. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33006. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33007. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33008. 0x5b
  33009. };
  33010. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  33011. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33012. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33013. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33014. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33015. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33016. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33017. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33018. 0x4e
  33019. };
  33020. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  33021. 0x25, 0x8c, 0xdd, 0x4a, 0xda, 0x32, 0xed, 0x9c,
  33022. 0x9f, 0xf5, 0x4e, 0x63, 0x75, 0x6a, 0xe5, 0x82,
  33023. 0xfb, 0x8f, 0xab, 0x2a, 0xc7, 0x21, 0xf2, 0xc8,
  33024. 0xe6, 0x76, 0xa7, 0x27, 0x68, 0x51, 0x3d, 0x93,
  33025. 0x9f, 0x63, 0xdd, 0xdb, 0x55, 0x60, 0x91, 0x33,
  33026. 0xf2, 0x9a, 0xdf, 0x86, 0xec, 0x99, 0x29, 0xdc,
  33027. 0xcb, 0x52, 0xc1, 0xc5, 0xfd, 0x2f, 0xf7, 0xe2,
  33028. 0x1b
  33029. };
  33030. /* uncompressed test */
  33031. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  33032. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33033. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33034. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33035. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33036. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33037. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33038. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33039. 0x5b
  33040. };
  33041. /* compressed prefix test */
  33042. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  33043. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33044. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33045. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33046. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33047. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33048. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33049. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33050. 0x5b
  33051. };
  33052. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  33053. 0x87, 0x2d, 0x09, 0x37, 0x80, 0xf5, 0xd3, 0x73,
  33054. 0x0d, 0xf7, 0xc2, 0x12, 0x66, 0x4b, 0x37, 0xb8,
  33055. 0xa0, 0xf2, 0x4f, 0x56, 0x81, 0x0d, 0xaa, 0x83,
  33056. 0x82, 0xcd, 0x4f, 0xa3, 0xf7, 0x76, 0x34, 0xec,
  33057. 0x44, 0xdc, 0x54, 0xf1, 0xc2, 0xed, 0x9b, 0xea,
  33058. 0x86, 0xfa, 0xfb, 0x76, 0x32, 0xd8, 0xbe, 0x19,
  33059. 0x9e, 0xa1, 0x65, 0xf5, 0xad, 0x55, 0xdd, 0x9c,
  33060. 0xe8
  33061. };
  33062. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  33063. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  33064. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33065. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33066. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33067. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33068. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33069. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33070. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33071. 0x80
  33072. };
  33073. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  33074. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33075. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33076. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33077. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33078. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33079. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33080. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33081. 0x80
  33082. };
  33083. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  33084. 0x3b, 0xa1, 0x6d, 0xa0, 0xc6, 0xf2, 0xcc, 0x1f,
  33085. 0x30, 0x18, 0x77, 0x40, 0x75, 0x6f, 0x5e, 0x79,
  33086. 0x8d, 0x6b, 0xc5, 0xfc, 0x01, 0x5d, 0x7c, 0x63,
  33087. 0xcc, 0x95, 0x10, 0xee, 0x3f, 0xd4, 0x4a, 0xdc,
  33088. 0x24, 0xd8, 0xe9, 0x68, 0xb6, 0xe4, 0x6e, 0x6f,
  33089. 0x94, 0xd1, 0x9b, 0x94, 0x53, 0x61, 0x72, 0x6b,
  33090. 0xd7, 0x5e, 0x14, 0x9e, 0xf0, 0x98, 0x17, 0xf5,
  33091. 0x80
  33092. };
  33093. /* uncompressed test */
  33094. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  33095. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33096. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33097. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33098. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33099. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33100. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33101. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33102. 0x80
  33103. };
  33104. /* compressed prefix */
  33105. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  33106. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33107. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33108. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33109. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33110. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33111. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33112. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33113. 0x80
  33114. };
  33115. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  33116. 0xa8, 0x1b, 0x2e, 0x8a, 0x70, 0xa5, 0xac, 0x94,
  33117. 0xff, 0xdb, 0xcc, 0x9b, 0xad, 0xfc, 0x3f, 0xeb,
  33118. 0x08, 0x01, 0xf2, 0x58, 0x57, 0x8b, 0xb1, 0x14,
  33119. 0xad, 0x44, 0xec, 0xe1, 0xec, 0x0e, 0x79, 0x9d,
  33120. 0xa0, 0x8e, 0xff, 0xb8, 0x1c, 0x5d, 0x68, 0x5c,
  33121. 0x0c, 0x56, 0xf6, 0x4e, 0xec, 0xae, 0xf8, 0xcd,
  33122. 0xf1, 0x1c, 0xc3, 0x87, 0x37, 0x83, 0x8c, 0xf4,
  33123. 0x00
  33124. };
  33125. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  33126. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  33127. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  33128. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  33129. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33130. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33131. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33132. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33133. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33134. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33135. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33136. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33137. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33138. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33139. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33140. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33141. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33142. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33143. 0x26, 0x00
  33144. };
  33145. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  33146. 0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89,
  33147. 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3, 0x77,
  33148. 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35,
  33149. 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10, 0xf4, 0x35,
  33150. 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7,
  33151. 0xe1, 0x8f, 0x62, 0xde, 0x8c, 0xcd, 0xf6, 0x33,
  33152. 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79,
  33153. 0x80, 0x5e, 0x0d, 0xbc, 0xc0, 0xaa, 0xe1, 0xcb,
  33154. 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36,
  33155. 0xbc, 0x04, 0xdc, 0xec, 0xbf, 0x15, 0x43, 0x36,
  33156. 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29,
  33157. 0x05, 0xe7, 0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f,
  33158. 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf,
  33159. 0xd1, 0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0,
  33160. 0x3a, 0x00
  33161. };
  33162. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  33163. 0x7e, 0xee, 0xab, 0x7c, 0x4e, 0x50, 0xfb, 0x79,
  33164. 0x9b, 0x41, 0x8e, 0xe5, 0xe3, 0x19, 0x7f, 0xf6,
  33165. 0xbf, 0x15, 0xd4, 0x3a, 0x14, 0xc3, 0x43, 0x89,
  33166. 0xb5, 0x9d, 0xd1, 0xa7, 0xb1, 0xb8, 0x5b, 0x4a,
  33167. 0xe9, 0x04, 0x38, 0xac, 0xa6, 0x34, 0xbe, 0xa4,
  33168. 0x5e, 0x3a, 0x26, 0x95, 0xf1, 0x27, 0x0f, 0x07,
  33169. 0xfd, 0xcd, 0xf7, 0xc6, 0x2b, 0x8e, 0xfe, 0xaf,
  33170. 0x00, 0xb4, 0x5c, 0x2c, 0x96, 0xba, 0x45, 0x7e,
  33171. 0xb1, 0xa8, 0xbf, 0x07, 0x5a, 0x3d, 0xb2, 0x8e,
  33172. 0x5c, 0x24, 0xf6, 0xb9, 0x23, 0xed, 0x4a, 0xd7,
  33173. 0x47, 0xc3, 0xc9, 0xe0, 0x3c, 0x70, 0x79, 0xef,
  33174. 0xb8, 0x7c, 0xb1, 0x10, 0xd3, 0xa9, 0x98, 0x61,
  33175. 0xe7, 0x20, 0x03, 0xcb, 0xae, 0x6d, 0x6b, 0x8b,
  33176. 0x82, 0x7e, 0x4e, 0x6c, 0x14, 0x30, 0x64, 0xff,
  33177. 0x3c, 0x00
  33178. };
  33179. /* uncompressed test */
  33180. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  33181. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33182. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33183. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33184. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33185. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33186. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33187. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33188. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33189. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33190. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33191. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33192. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33193. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33194. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33195. 0x26, 0x00
  33196. };
  33197. /* compressed prefix */
  33198. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  33199. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33200. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33201. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33202. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33203. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33204. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33205. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33206. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33207. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33208. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33209. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33210. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33211. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33212. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33213. 0x26, 0x00
  33214. };
  33215. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  33216. 0xe3, 0x01, 0x34, 0x5a, 0x41, 0xa3, 0x9a, 0x4d,
  33217. 0x72, 0xff, 0xf8, 0xdf, 0x69, 0xc9, 0x80, 0x75,
  33218. 0xa0, 0xcc, 0x08, 0x2b, 0x80, 0x2f, 0xc9, 0xb2,
  33219. 0xb6, 0xbc, 0x50, 0x3f, 0x92, 0x6b, 0x65, 0xbd,
  33220. 0xdf, 0x7f, 0x4c, 0x8f, 0x1c, 0xb4, 0x9f, 0x63,
  33221. 0x96, 0xaf, 0xc8, 0xa7, 0x0a, 0xbe, 0x6d, 0x8a,
  33222. 0xef, 0x0d, 0xb4, 0x78, 0xd4, 0xc6, 0xb2, 0x97,
  33223. 0x00, 0x76, 0xc6, 0xa0, 0x48, 0x4f, 0xe7, 0x6d,
  33224. 0x76, 0xb3, 0xa9, 0x76, 0x25, 0xd7, 0x9f, 0x1c,
  33225. 0xe2, 0x40, 0xe7, 0xc5, 0x76, 0x75, 0x0d, 0x29,
  33226. 0x55, 0x28, 0x28, 0x6f, 0x71, 0x9b, 0x41, 0x3d,
  33227. 0xe9, 0xad, 0xa3, 0xe8, 0xeb, 0x78, 0xed, 0x57,
  33228. 0x36, 0x03, 0xce, 0x30, 0xd8, 0xbb, 0x76, 0x17,
  33229. 0x85, 0xdc, 0x30, 0xdb, 0xc3, 0x20, 0x86, 0x9e,
  33230. 0x1a, 0x00
  33231. };
  33232. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  33233. #define SIGSZ sizeof(sig1)
  33234. PEDANTIC_EXTENSION WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = { 0 };
  33235. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = { 0x03 };
  33236. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = { 0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd,
  33237. 0x66, 0x81, 0x1e, 0x29, 0x15 };
  33238. /* test of a 1023 byte long message */
  33239. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  33240. 0x6d, 0xdf, 0x80, 0x2e, 0x1a, 0xae, 0x49, 0x86,
  33241. 0x93, 0x5f, 0x7f, 0x98, 0x1b, 0xa3, 0xf0, 0x35,
  33242. 0x1d, 0x62, 0x73, 0xc0, 0xa0, 0xc2, 0x2c, 0x9c,
  33243. 0x0e, 0x83, 0x39, 0x16, 0x8e, 0x67, 0x54, 0x12,
  33244. 0xa3, 0xde, 0xbf, 0xaf, 0x43, 0x5e, 0xd6, 0x51,
  33245. 0x55, 0x80, 0x07, 0xdb, 0x43, 0x84, 0xb6, 0x50,
  33246. 0xfc, 0xc0, 0x7e, 0x3b, 0x58, 0x6a, 0x27, 0xa4,
  33247. 0xf7, 0xa0, 0x0a, 0xc8, 0xa6, 0xfe, 0xc2, 0xcd,
  33248. 0x86, 0xae, 0x4b, 0xf1, 0x57, 0x0c, 0x41, 0xe6,
  33249. 0xa4, 0x0c, 0x93, 0x1d, 0xb2, 0x7b, 0x2f, 0xaa,
  33250. 0x15, 0xa8, 0xce, 0xdd, 0x52, 0xcf, 0xf7, 0x36,
  33251. 0x2c, 0x4e, 0x6e, 0x23, 0xda, 0xec, 0x0f, 0xbc,
  33252. 0x3a, 0x79, 0xb6, 0x80, 0x6e, 0x31, 0x6e, 0xfc,
  33253. 0xc7, 0xb6, 0x81, 0x19, 0xbf, 0x46, 0xbc, 0x76,
  33254. 0xa2, 0x60, 0x67, 0xa5, 0x3f, 0x29, 0x6d, 0xaf,
  33255. 0xdb, 0xdc, 0x11, 0xc7, 0x7f, 0x77, 0x77, 0xe9,
  33256. 0x72, 0x66, 0x0c, 0xf4, 0xb6, 0xa9, 0xb3, 0x69,
  33257. 0xa6, 0x66, 0x5f, 0x02, 0xe0, 0xcc, 0x9b, 0x6e,
  33258. 0xdf, 0xad, 0x13, 0x6b, 0x4f, 0xab, 0xe7, 0x23,
  33259. 0xd2, 0x81, 0x3d, 0xb3, 0x13, 0x6c, 0xfd, 0xe9,
  33260. 0xb6, 0xd0, 0x44, 0x32, 0x2f, 0xee, 0x29, 0x47,
  33261. 0x95, 0x2e, 0x03, 0x1b, 0x73, 0xab, 0x5c, 0x60,
  33262. 0x33, 0x49, 0xb3, 0x07, 0xbd, 0xc2, 0x7b, 0xc6,
  33263. 0xcb, 0x8b, 0x8b, 0xbd, 0x7b, 0xd3, 0x23, 0x21,
  33264. 0x9b, 0x80, 0x33, 0xa5, 0x81, 0xb5, 0x9e, 0xad,
  33265. 0xeb, 0xb0, 0x9b, 0x3c, 0x4f, 0x3d, 0x22, 0x77,
  33266. 0xd4, 0xf0, 0x34, 0x36, 0x24, 0xac, 0xc8, 0x17,
  33267. 0x80, 0x47, 0x28, 0xb2, 0x5a, 0xb7, 0x97, 0x17,
  33268. 0x2b, 0x4c, 0x5c, 0x21, 0xa2, 0x2f, 0x9c, 0x78,
  33269. 0x39, 0xd6, 0x43, 0x00, 0x23, 0x2e, 0xb6, 0x6e,
  33270. 0x53, 0xf3, 0x1c, 0x72, 0x3f, 0xa3, 0x7f, 0xe3,
  33271. 0x87, 0xc7, 0xd3, 0xe5, 0x0b, 0xdf, 0x98, 0x13,
  33272. 0xa3, 0x0e, 0x5b, 0xb1, 0x2c, 0xf4, 0xcd, 0x93,
  33273. 0x0c, 0x40, 0xcf, 0xb4, 0xe1, 0xfc, 0x62, 0x25,
  33274. 0x92, 0xa4, 0x95, 0x88, 0x79, 0x44, 0x94, 0xd5,
  33275. 0x6d, 0x24, 0xea, 0x4b, 0x40, 0xc8, 0x9f, 0xc0,
  33276. 0x59, 0x6c, 0xc9, 0xeb, 0xb9, 0x61, 0xc8, 0xcb,
  33277. 0x10, 0xad, 0xde, 0x97, 0x6a, 0x5d, 0x60, 0x2b,
  33278. 0x1c, 0x3f, 0x85, 0xb9, 0xb9, 0xa0, 0x01, 0xed,
  33279. 0x3c, 0x6a, 0x4d, 0x3b, 0x14, 0x37, 0xf5, 0x20,
  33280. 0x96, 0xcd, 0x19, 0x56, 0xd0, 0x42, 0xa5, 0x97,
  33281. 0xd5, 0x61, 0xa5, 0x96, 0xec, 0xd3, 0xd1, 0x73,
  33282. 0x5a, 0x8d, 0x57, 0x0e, 0xa0, 0xec, 0x27, 0x22,
  33283. 0x5a, 0x2c, 0x4a, 0xaf, 0xf2, 0x63, 0x06, 0xd1,
  33284. 0x52, 0x6c, 0x1a, 0xf3, 0xca, 0x6d, 0x9c, 0xf5,
  33285. 0xa2, 0xc9, 0x8f, 0x47, 0xe1, 0xc4, 0x6d, 0xb9,
  33286. 0xa3, 0x32, 0x34, 0xcf, 0xd4, 0xd8, 0x1f, 0x2c,
  33287. 0x98, 0x53, 0x8a, 0x09, 0xeb, 0xe7, 0x69, 0x98,
  33288. 0xd0, 0xd8, 0xfd, 0x25, 0x99, 0x7c, 0x7d, 0x25,
  33289. 0x5c, 0x6d, 0x66, 0xec, 0xe6, 0xfa, 0x56, 0xf1,
  33290. 0x11, 0x44, 0x95, 0x0f, 0x02, 0x77, 0x95, 0xe6,
  33291. 0x53, 0x00, 0x8f, 0x4b, 0xd7, 0xca, 0x2d, 0xee,
  33292. 0x85, 0xd8, 0xe9, 0x0f, 0x3d, 0xc3, 0x15, 0x13,
  33293. 0x0c, 0xe2, 0xa0, 0x03, 0x75, 0xa3, 0x18, 0xc7,
  33294. 0xc3, 0xd9, 0x7b, 0xe2, 0xc8, 0xce, 0x5b, 0x6d,
  33295. 0xb4, 0x1a, 0x62, 0x54, 0xff, 0x26, 0x4f, 0xa6,
  33296. 0x15, 0x5b, 0xae, 0xe3, 0xb0, 0x77, 0x3c, 0x0f,
  33297. 0x49, 0x7c, 0x57, 0x3f, 0x19, 0xbb, 0x4f, 0x42,
  33298. 0x40, 0x28, 0x1f, 0x0b, 0x1f, 0x4f, 0x7b, 0xe8,
  33299. 0x57, 0xa4, 0xe5, 0x9d, 0x41, 0x6c, 0x06, 0xb4,
  33300. 0xc5, 0x0f, 0xa0, 0x9e, 0x18, 0x10, 0xdd, 0xc6,
  33301. 0xb1, 0x46, 0x7b, 0xae, 0xac, 0x5a, 0x36, 0x68,
  33302. 0xd1, 0x1b, 0x6e, 0xca, 0xa9, 0x01, 0x44, 0x00,
  33303. 0x16, 0xf3, 0x89, 0xf8, 0x0a, 0xcc, 0x4d, 0xb9,
  33304. 0x77, 0x02, 0x5e, 0x7f, 0x59, 0x24, 0x38, 0x8c,
  33305. 0x7e, 0x34, 0x0a, 0x73, 0x2e, 0x55, 0x44, 0x40,
  33306. 0xe7, 0x65, 0x70, 0xf8, 0xdd, 0x71, 0xb7, 0xd6,
  33307. 0x40, 0xb3, 0x45, 0x0d, 0x1f, 0xd5, 0xf0, 0x41,
  33308. 0x0a, 0x18, 0xf9, 0xa3, 0x49, 0x4f, 0x70, 0x7c,
  33309. 0x71, 0x7b, 0x79, 0xb4, 0xbf, 0x75, 0xc9, 0x84,
  33310. 0x00, 0xb0, 0x96, 0xb2, 0x16, 0x53, 0xb5, 0xd2,
  33311. 0x17, 0xcf, 0x35, 0x65, 0xc9, 0x59, 0x74, 0x56,
  33312. 0xf7, 0x07, 0x03, 0x49, 0x7a, 0x07, 0x87, 0x63,
  33313. 0x82, 0x9b, 0xc0, 0x1b, 0xb1, 0xcb, 0xc8, 0xfa,
  33314. 0x04, 0xea, 0xdc, 0x9a, 0x6e, 0x3f, 0x66, 0x99,
  33315. 0x58, 0x7a, 0x9e, 0x75, 0xc9, 0x4e, 0x5b, 0xab,
  33316. 0x00, 0x36, 0xe0, 0xb2, 0xe7, 0x11, 0x39, 0x2c,
  33317. 0xff, 0x00, 0x47, 0xd0, 0xd6, 0xb0, 0x5b, 0xd2,
  33318. 0xa5, 0x88, 0xbc, 0x10, 0x97, 0x18, 0x95, 0x42,
  33319. 0x59, 0xf1, 0xd8, 0x66, 0x78, 0xa5, 0x79, 0xa3,
  33320. 0x12, 0x0f, 0x19, 0xcf, 0xb2, 0x96, 0x3f, 0x17,
  33321. 0x7a, 0xeb, 0x70, 0xf2, 0xd4, 0x84, 0x48, 0x26,
  33322. 0x26, 0x2e, 0x51, 0xb8, 0x02, 0x71, 0x27, 0x20,
  33323. 0x68, 0xef, 0x5b, 0x38, 0x56, 0xfa, 0x85, 0x35,
  33324. 0xaa, 0x2a, 0x88, 0xb2, 0xd4, 0x1f, 0x2a, 0x0e,
  33325. 0x2f, 0xda, 0x76, 0x24, 0xc2, 0x85, 0x02, 0x72,
  33326. 0xac, 0x4a, 0x2f, 0x56, 0x1f, 0x8f, 0x2f, 0x7a,
  33327. 0x31, 0x8b, 0xfd, 0x5c, 0xaf, 0x96, 0x96, 0x14,
  33328. 0x9e, 0x4a, 0xc8, 0x24, 0xad, 0x34, 0x60, 0x53,
  33329. 0x8f, 0xdc, 0x25, 0x42, 0x1b, 0xee, 0xc2, 0xcc,
  33330. 0x68, 0x18, 0x16, 0x2d, 0x06, 0xbb, 0xed, 0x0c,
  33331. 0x40, 0xa3, 0x87, 0x19, 0x23, 0x49, 0xdb, 0x67,
  33332. 0xa1, 0x18, 0xba, 0xda, 0x6c, 0xd5, 0xab, 0x01,
  33333. 0x40, 0xee, 0x27, 0x32, 0x04, 0xf6, 0x28, 0xaa,
  33334. 0xd1, 0xc1, 0x35, 0xf7, 0x70, 0x27, 0x9a, 0x65,
  33335. 0x1e, 0x24, 0xd8, 0xc1, 0x4d, 0x75, 0xa6, 0x05,
  33336. 0x9d, 0x76, 0xb9, 0x6a, 0x6f, 0xd8, 0x57, 0xde,
  33337. 0xf5, 0xe0, 0xb3, 0x54, 0xb2, 0x7a, 0xb9, 0x37,
  33338. 0xa5, 0x81, 0x5d, 0x16, 0xb5, 0xfa, 0xe4, 0x07,
  33339. 0xff, 0x18, 0x22, 0x2c, 0x6d, 0x1e, 0xd2, 0x63,
  33340. 0xbe, 0x68, 0xc9, 0x5f, 0x32, 0xd9, 0x08, 0xbd,
  33341. 0x89, 0x5c, 0xd7, 0x62, 0x07, 0xae, 0x72, 0x64,
  33342. 0x87, 0x56, 0x7f, 0x9a, 0x67, 0xda, 0xd7, 0x9a,
  33343. 0xbe, 0xc3, 0x16, 0xf6, 0x83, 0xb1, 0x7f, 0x2d,
  33344. 0x02, 0xbf, 0x07, 0xe0, 0xac, 0x8b, 0x5b, 0xc6,
  33345. 0x16, 0x2c, 0xf9, 0x46, 0x97, 0xb3, 0xc2, 0x7c,
  33346. 0xd1, 0xfe, 0xa4, 0x9b, 0x27, 0xf2, 0x3b, 0xa2,
  33347. 0x90, 0x18, 0x71, 0x96, 0x25, 0x06, 0x52, 0x0c,
  33348. 0x39, 0x2d, 0xa8, 0xb6, 0xad, 0x0d, 0x99, 0xf7,
  33349. 0x01, 0x3f, 0xbc, 0x06, 0xc2, 0xc1, 0x7a, 0x56,
  33350. 0x95, 0x00, 0xc8, 0xa7, 0x69, 0x64, 0x81, 0xc1,
  33351. 0xcd, 0x33, 0xe9, 0xb1, 0x4e, 0x40, 0xb8, 0x2e,
  33352. 0x79, 0xa5, 0xf5, 0xdb, 0x82, 0x57, 0x1b, 0xa9,
  33353. 0x7b, 0xae, 0x3a, 0xd3, 0xe0, 0x47, 0x95, 0x15,
  33354. 0xbb, 0x0e, 0x2b, 0x0f, 0x3b, 0xfc, 0xd1, 0xfd,
  33355. 0x33, 0x03, 0x4e, 0xfc, 0x62, 0x45, 0xed, 0xdd,
  33356. 0x7e, 0xe2, 0x08, 0x6d, 0xda, 0xe2, 0x60, 0x0d,
  33357. 0x8c, 0xa7, 0x3e, 0x21, 0x4e, 0x8c, 0x2b, 0x0b,
  33358. 0xdb, 0x2b, 0x04, 0x7c, 0x6a, 0x46, 0x4a, 0x56,
  33359. 0x2e, 0xd7, 0x7b, 0x73, 0xd2, 0xd8, 0x41, 0xc4,
  33360. 0xb3, 0x49, 0x73, 0x55, 0x12, 0x57, 0x71, 0x3b,
  33361. 0x75, 0x36, 0x32, 0xef, 0xba, 0x34, 0x81, 0x69,
  33362. 0xab, 0xc9, 0x0a, 0x68, 0xf4, 0x26, 0x11, 0xa4,
  33363. 0x01, 0x26, 0xd7, 0xcb, 0x21, 0xb5, 0x86, 0x95,
  33364. 0x56, 0x81, 0x86, 0xf7, 0xe5, 0x69, 0xd2, 0xff,
  33365. 0x0f, 0x9e, 0x74, 0x5d, 0x04, 0x87, 0xdd, 0x2e,
  33366. 0xb9, 0x97, 0xca, 0xfc, 0x5a, 0xbf, 0x9d, 0xd1,
  33367. 0x02, 0xe6, 0x2f, 0xf6, 0x6c, 0xba, 0x87
  33368. };
  33369. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  33370. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  33371. sizeof(msg2),
  33372. sizeof(msg3),
  33373. 0 /*sizeof(msg1)*/,
  33374. 0 /*sizeof(msg1)*/,
  33375. sizeof(msg4)
  33376. };
  33377. #ifndef NO_ASN
  33378. static const byte privateEd448[] = {
  33379. 0x30, 0x47, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
  33380. 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04, 0x39,
  33381. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33382. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33383. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33384. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33385. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33386. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33387. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33388. 0x5b
  33389. };
  33390. static const byte publicEd448[] = {
  33391. 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
  33392. 0x71, 0x03, 0x3a, 0x00, 0x5f, 0xd7, 0x44, 0x9b,
  33393. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33394. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33395. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33396. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33397. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33398. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33399. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33400. };
  33401. static const byte privPubEd448[] = {
  33402. 0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
  33403. 0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
  33404. 0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
  33405. 0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
  33406. 0xbf, 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c,
  33407. 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48,
  33408. 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
  33409. 0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
  33410. 0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
  33411. 0xf9, 0x5b, 0x81, 0x39, 0x5f, 0xd7, 0x44, 0x9b,
  33412. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33413. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33414. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33415. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33416. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33417. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33418. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33419. };
  33420. word32 idx;
  33421. #endif /* NO_ASN */
  33422. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33423. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33424. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33425. ed448_key *key3 = NULL;
  33426. #else
  33427. ed448_key key3[1];
  33428. #endif
  33429. #endif
  33430. WOLFSSL_ENTER("ed448_test");
  33431. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33432. key = (ed448_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33433. key2 = (ed448_key *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33434. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33435. key3 = (ed448_key *)XMALLOC(sizeof(*key3), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33436. #endif
  33437. #endif
  33438. /* create ed448 keys */
  33439. #ifndef HAVE_FIPS
  33440. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  33441. #else
  33442. ret = wc_InitRng(&rng);
  33443. #endif
  33444. if (ret != 0) {
  33445. XMEMSET(&rng, 0, sizeof(rng));
  33446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33447. }
  33448. ret = wc_ed448_init(key);
  33449. if (ret < 0)
  33450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33451. ret = wc_ed448_init(key2);
  33452. if (ret < 0)
  33453. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33454. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33455. ret = wc_ed448_init(key3);
  33456. if (ret < 0)
  33457. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33458. #endif
  33459. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key);
  33460. if (ret < 0)
  33461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33462. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2);
  33463. if (ret < 0)
  33464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33465. /* helper functions for signature and key size */
  33466. keySz = (word32)wc_ed448_size(key);
  33467. sigSz = (word32)wc_ed448_sig_size(key);
  33468. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33469. defined(HAVE_ED448_KEY_IMPORT)
  33470. for (i = 0; i < 6; i++) {
  33471. outlen = sizeof(out);
  33472. XMEMSET(out, 0, sizeof(out));
  33473. if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i],
  33474. pKeySz[i], key) != 0)
  33475. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33476. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL,
  33477. 0) != 0)
  33478. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33479. if (XMEMCMP(out, sigs[i], 114))
  33480. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33481. #if defined(HAVE_ED448_VERIFY)
  33482. /* test verify on good msg */
  33483. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33484. NULL, 0) != 0 || verify != 1)
  33485. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33486. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33487. /* test verify on good msg using streaming interface directly */
  33488. if (wc_ed448_verify_msg_init(out, outlen,
  33489. key, (byte)Ed448, NULL, 0) != 0)
  33490. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33491. for (j = 0; j < msgSz[i]; j += i) {
  33492. if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  33493. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33494. }
  33495. if (wc_ed448_verify_msg_final(out, outlen, &verify,
  33496. key) != 0 || verify != 1)
  33497. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33498. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33499. /* test verify on bad msg */
  33500. out[outlen-2] = out[outlen-2] + 1;
  33501. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33502. NULL, 0) == 0 || verify == 1)
  33503. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33504. #endif /* HAVE_ED448_VERIFY */
  33505. /* test api for import/exporting keys */
  33506. {
  33507. byte *exportPKey = NULL;
  33508. byte *exportSKey = NULL;
  33509. word32 exportPSz = ED448_KEY_SIZE;
  33510. word32 exportSSz = ED448_KEY_SIZE;
  33511. exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33512. exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33513. if ((exportPKey == NULL) || (exportSKey == NULL))
  33514. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33515. ret = 0;
  33516. do {
  33517. if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) {
  33518. ret = WC_TEST_RET_ENC_I(i);
  33519. break;
  33520. }
  33521. if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) {
  33522. ret = WC_TEST_RET_ENC_I(i);
  33523. break;
  33524. }
  33525. if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) {
  33526. ret = WC_TEST_RET_ENC_I(i);
  33527. break;
  33528. }
  33529. if (wc_ed448_import_private_key(exportSKey, exportSSz,
  33530. exportPKey, exportPSz, key2) != 0) {
  33531. ret = WC_TEST_RET_ENC_I(i);
  33532. break;
  33533. }
  33534. /* clear "out" buffer and test sign with imported keys */
  33535. outlen = sizeof(out);
  33536. XMEMSET(out, 0, sizeof(out));
  33537. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL,
  33538. 0) != 0) {
  33539. ret = WC_TEST_RET_ENC_I(i);
  33540. break;
  33541. }
  33542. } while(0);
  33543. XFREE(exportPKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33544. XFREE(exportSKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33545. if (ret != 0)
  33546. goto out;
  33547. }
  33548. #if defined(HAVE_ED448_VERIFY)
  33549. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2,
  33550. NULL, 0) != 0 || verify != 1)
  33551. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33552. if (XMEMCMP(out, sigs[i], SIGSZ))
  33553. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33554. #endif /* HAVE_ED448_VERIFY */
  33555. }
  33556. ret = ed448_ctx_test();
  33557. if (ret != 0)
  33558. goto out;
  33559. ret = ed448ph_test();
  33560. if (ret != 0)
  33561. goto out;
  33562. #ifndef NO_ASN
  33563. /* Try ASN.1 encoded private-only key and public key. */
  33564. idx = 0;
  33565. ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3,
  33566. sizeof(privateEd448));
  33567. if (ret != 0)
  33568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33569. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33570. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  33571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33572. idx = 0;
  33573. ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448));
  33574. if (ret != 0)
  33575. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33576. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33577. if (ret != 0)
  33578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33579. if (XMEMCMP(out, sigs[0], SIGSZ))
  33580. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33581. #if defined(HAVE_ED448_VERIFY)
  33582. /* test verify on good msg */
  33583. ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3,
  33584. NULL, 0);
  33585. if (ret != 0 || verify != 1)
  33586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33587. #endif /* HAVE_ED448_VERIFY */
  33588. wc_ed448_free(key3);
  33589. ret = wc_ed448_init(key3);
  33590. if (ret < 0)
  33591. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33592. idx = 0;
  33593. ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3,
  33594. sizeof(privPubEd448));
  33595. if (ret != 0)
  33596. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33597. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33598. if (ret != 0)
  33599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33600. if (XMEMCMP(out, sigs[0], SIGSZ))
  33601. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33602. #endif /* NO_ASN */
  33603. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33604. ret = 0;
  33605. out:
  33606. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33607. if (key) {
  33608. wc_ed448_free(key);
  33609. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33610. }
  33611. if (key2) {
  33612. wc_ed448_free(key2);
  33613. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33614. }
  33615. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33616. if (key3) {
  33617. wc_ed448_free(key3);
  33618. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33619. }
  33620. #endif
  33621. #else
  33622. wc_ed448_free(key);
  33623. wc_ed448_free(key2);
  33624. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33625. wc_ed448_free(key3);
  33626. #endif
  33627. #endif
  33628. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  33629. wc_FreeRng(&rng);
  33630. #endif
  33631. if (ret < 0)
  33632. return ret;
  33633. /* hush warnings of unused keySz and sigSz */
  33634. (void)keySz;
  33635. (void)sigSz;
  33636. ret = ed448_test_check_key();
  33637. if (ret < 0)
  33638. return ret;
  33639. #ifdef WOLFSSL_TEST_CERT
  33640. ret = ed448_test_cert();
  33641. if (ret < 0)
  33642. return ret;
  33643. #ifdef WOLFSSL_CERT_GEN
  33644. ret = ed448_test_make_cert();
  33645. if (ret < 0)
  33646. return ret;
  33647. #endif /* WOLFSSL_CERT_GEN */
  33648. #endif /* WOLFSSL_TEST_CERT */
  33649. return 0;
  33650. }
  33651. #endif /* HAVE_ED448 */
  33652. #ifdef WOLFSSL_HAVE_KYBER
  33653. #ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
  33654. #ifdef WOLFSSL_KYBER512
  33655. static wc_test_ret_t kyber512_kat(void)
  33656. {
  33657. wc_test_ret_t ret;
  33658. #ifdef WOLFSSL_SMALL_STACK
  33659. KyberKey *key = NULL;
  33660. byte *priv = NULL;
  33661. byte *pub = NULL;
  33662. byte *ct = NULL;
  33663. byte *ss = NULL;
  33664. byte *ss_dec = NULL;
  33665. #else
  33666. KyberKey key[1];
  33667. byte priv[KYBER512_PRIVATE_KEY_SIZE];
  33668. byte pub[KYBER512_PUBLIC_KEY_SIZE];
  33669. byte ct[KYBER512_CIPHER_TEXT_SIZE];
  33670. byte ss[KYBER_SS_SZ];
  33671. byte ss_dec[KYBER_SS_SZ];
  33672. #endif
  33673. int key_inited = 0;
  33674. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_rand[] = {
  33675. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  33676. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  33677. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  33678. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  33679. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  33680. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  33681. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  33682. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  33683. };
  33684. WOLFSSL_SMALL_STACK_STATIC const byte kyber512enc_rand[] = {
  33685. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  33686. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  33687. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  33688. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  33689. };
  33690. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_pk[] = {
  33691. #ifdef WOLFSSL_KYBER_ORIGINAL
  33692. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  33693. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  33694. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  33695. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  33696. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  33697. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  33698. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  33699. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  33700. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  33701. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  33702. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  33703. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  33704. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  33705. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  33706. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  33707. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  33708. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  33709. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  33710. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  33711. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  33712. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  33713. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  33714. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  33715. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  33716. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  33717. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  33718. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  33719. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  33720. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  33721. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  33722. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  33723. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  33724. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  33725. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  33726. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  33727. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  33728. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  33729. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  33730. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  33731. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  33732. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  33733. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  33734. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  33735. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  33736. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  33737. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  33738. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  33739. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  33740. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  33741. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  33742. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  33743. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  33744. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  33745. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  33746. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  33747. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  33748. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  33749. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  33750. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  33751. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  33752. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  33753. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  33754. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  33755. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  33756. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  33757. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  33758. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  33759. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  33760. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  33761. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  33762. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  33763. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  33764. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  33765. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  33766. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  33767. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  33768. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  33769. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  33770. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  33771. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  33772. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  33773. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  33774. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  33775. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  33776. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  33777. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  33778. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  33779. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  33780. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  33781. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  33782. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  33783. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  33784. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  33785. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  33786. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  33787. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  33788. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  33789. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  33790. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  33791. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  33792. #else
  33793. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  33794. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  33795. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  33796. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  33797. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  33798. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  33799. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  33800. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  33801. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  33802. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  33803. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  33804. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  33805. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  33806. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  33807. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  33808. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  33809. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  33810. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  33811. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  33812. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  33813. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  33814. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  33815. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  33816. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  33817. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  33818. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  33819. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  33820. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  33821. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  33822. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  33823. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  33824. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  33825. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  33826. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  33827. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  33828. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  33829. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  33830. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  33831. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  33832. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  33833. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  33834. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  33835. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  33836. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  33837. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  33838. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  33839. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  33840. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  33841. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  33842. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  33843. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  33844. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  33845. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  33846. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  33847. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  33848. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  33849. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  33850. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  33851. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  33852. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  33853. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  33854. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  33855. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  33856. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  33857. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  33858. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  33859. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  33860. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  33861. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  33862. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  33863. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  33864. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  33865. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  33866. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  33867. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  33868. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  33869. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  33870. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  33871. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  33872. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  33873. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  33874. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  33875. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  33876. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  33877. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  33878. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  33879. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  33880. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  33881. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  33882. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  33883. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  33884. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  33885. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  33886. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  33887. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  33888. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  33889. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  33890. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  33891. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  33892. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39
  33893. #endif
  33894. };
  33895. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_sk[] = {
  33896. #ifdef WOLFSSL_KYBER_ORIGINAL
  33897. 0x6C, 0x89, 0x2B, 0x02, 0x97, 0xA9, 0xC7, 0x64,
  33898. 0x14, 0x93, 0xF8, 0x7D, 0xAF, 0x35, 0x33, 0xEE,
  33899. 0xD6, 0x1F, 0x07, 0xF4, 0x65, 0x20, 0x66, 0x33,
  33900. 0x7E, 0xD7, 0x40, 0x46, 0xDC, 0xC7, 0x1B, 0xA0,
  33901. 0x3F, 0x30, 0x96, 0x01, 0x03, 0x16, 0x1F, 0x7D,
  33902. 0xEB, 0x53, 0xA7, 0x1B, 0x11, 0x61, 0x72, 0x63,
  33903. 0xFE, 0x2A, 0x80, 0x97, 0x69, 0xCE, 0x6D, 0x70,
  33904. 0xA8, 0x5F, 0xE6, 0x00, 0xEC, 0xE2, 0x9D, 0x7F,
  33905. 0x36, 0xA1, 0x6D, 0x33, 0x1B, 0x8B, 0x2A, 0x9E,
  33906. 0x1D, 0xB8, 0xC0, 0x90, 0x74, 0x2D, 0xF0, 0x73,
  33907. 0x9F, 0xF0, 0x60, 0xCE, 0xB4, 0xEC, 0xC5, 0xAB,
  33908. 0x1C, 0x5E, 0x55, 0xAC, 0x97, 0xBB, 0x66, 0xA7,
  33909. 0xF8, 0x95, 0x10, 0x5D, 0x57, 0x78, 0x2B, 0x22,
  33910. 0x95, 0x38, 0xE3, 0x42, 0x15, 0x44, 0xA3, 0x42,
  33911. 0x14, 0x08, 0xDB, 0xF4, 0x49, 0x10, 0x93, 0x4C,
  33912. 0xC4, 0x23, 0x77, 0x4F, 0x16, 0x76, 0xFF, 0x1C,
  33913. 0x30, 0x6F, 0x97, 0x55, 0x5F, 0x57, 0xB4, 0xAE,
  33914. 0xD7, 0xA6, 0xBA, 0xB9, 0x50, 0xA8, 0x16, 0x3C,
  33915. 0x8D, 0x31, 0x8D, 0xEA, 0x62, 0x75, 0x1B, 0xD6,
  33916. 0xAB, 0xC5, 0x06, 0x9C, 0x06, 0xC8, 0x8F, 0x33,
  33917. 0x00, 0x26, 0xA1, 0x98, 0x06, 0xA0, 0x3B, 0x97,
  33918. 0xA7, 0x69, 0x6B, 0x56, 0xDA, 0x21, 0x82, 0x7B,
  33919. 0xB4, 0xE8, 0xDC, 0x03, 0x11, 0x52, 0xB4, 0x1B,
  33920. 0x89, 0x2A, 0x9E, 0x99, 0xAD, 0xF6, 0xE1, 0x96,
  33921. 0x3E, 0x96, 0x57, 0x88, 0x28, 0x15, 0x4F, 0x46,
  33922. 0x70, 0x33, 0x84, 0x69, 0x20, 0xFB, 0xB4, 0xB8,
  33923. 0x05, 0x44, 0xE7, 0xE8, 0xA8, 0x1A, 0xE9, 0x63,
  33924. 0xCF, 0x36, 0x8C, 0x9B, 0xA0, 0x37, 0xA8, 0xC2,
  33925. 0xAD, 0x62, 0xE3, 0x2B, 0x6E, 0x61, 0xC9, 0x1D,
  33926. 0x75, 0xCE, 0x00, 0x5A, 0xB3, 0x0F, 0x80, 0x99,
  33927. 0xA1, 0xF2, 0x9D, 0x7B, 0x63, 0x05, 0xB4, 0xDC,
  33928. 0x06, 0xE2, 0x56, 0x80, 0xBB, 0x00, 0x99, 0x2F,
  33929. 0x71, 0x7F, 0xE6, 0xC1, 0x15, 0xA8, 0x08, 0x42,
  33930. 0x31, 0xCC, 0x79, 0xDD, 0x70, 0x0E, 0xA6, 0x91,
  33931. 0x2A, 0xC7, 0xFA, 0x0D, 0x93, 0x7B, 0xB6, 0xA7,
  33932. 0x56, 0x66, 0x22, 0x30, 0x47, 0x0C, 0x18, 0x9B,
  33933. 0x5A, 0xA1, 0x65, 0x3D, 0xEB, 0x93, 0x7D, 0x5A,
  33934. 0x9C, 0x25, 0xA2, 0x1D, 0x93, 0xB1, 0x90, 0x74,
  33935. 0xFC, 0x23, 0x9D, 0x81, 0x53, 0x53, 0x97, 0x97,
  33936. 0xC7, 0xD4, 0xAB, 0x62, 0x64, 0x9D, 0x76, 0xAA,
  33937. 0x55, 0x37, 0x36, 0xA9, 0x49, 0x02, 0x2C, 0x22,
  33938. 0xC5, 0x2B, 0xAE, 0xEC, 0x60, 0x5B, 0x32, 0xCE,
  33939. 0x9E, 0x5B, 0x93, 0x84, 0x90, 0x35, 0x58, 0xCA,
  33940. 0x9D, 0x6A, 0x3A, 0xBA, 0x90, 0x42, 0x3E, 0xED,
  33941. 0xA0, 0x1C, 0x94, 0x19, 0x8B, 0x19, 0x2A, 0x8B,
  33942. 0xA9, 0x06, 0x34, 0x97, 0xA0, 0xC5, 0x01, 0x33,
  33943. 0x07, 0xDD, 0xD8, 0x63, 0x52, 0x64, 0x71, 0xA4,
  33944. 0xD9, 0x95, 0x23, 0xEB, 0x41, 0x7F, 0x29, 0x1A,
  33945. 0xAC, 0x0C, 0x3A, 0x58, 0x1B, 0x6D, 0xA0, 0x07,
  33946. 0x32, 0xE5, 0xE8, 0x1B, 0x1F, 0x7C, 0x87, 0x9B,
  33947. 0x16, 0x93, 0xC1, 0x3B, 0x6F, 0x9F, 0x79, 0x31,
  33948. 0x62, 0x24, 0x29, 0xE5, 0x42, 0xAF, 0x40, 0x69,
  33949. 0x22, 0x2F, 0x04, 0x55, 0x44, 0xE0, 0xCC, 0x4F,
  33950. 0xB2, 0x4D, 0x44, 0x48, 0xCF, 0x2C, 0x65, 0x96,
  33951. 0xF5, 0xCB, 0x08, 0x62, 0x4B, 0x11, 0x85, 0x01,
  33952. 0x3B, 0x6B, 0x02, 0x08, 0x92, 0xF9, 0x6B, 0xDF,
  33953. 0xD4, 0xAD, 0xA9, 0x17, 0x9D, 0xE7, 0x27, 0xB8,
  33954. 0xD9, 0x42, 0x6E, 0x09, 0x96, 0xB5, 0xD3, 0x49,
  33955. 0x48, 0xCE, 0x02, 0xD0, 0xC3, 0x69, 0xB3, 0x7C,
  33956. 0xBB, 0x54, 0xD3, 0x47, 0x9E, 0xD8, 0xB5, 0x82,
  33957. 0xE9, 0xE7, 0x28, 0x92, 0x9B, 0x4C, 0x71, 0xC9,
  33958. 0xBE, 0x11, 0xD4, 0x5B, 0x20, 0xC4, 0xBD, 0xC3,
  33959. 0xC7, 0x43, 0x13, 0x22, 0x3F, 0x58, 0x27, 0x4E,
  33960. 0x8B, 0xA5, 0x24, 0x44, 0x47, 0xC4, 0x95, 0x95,
  33961. 0x0B, 0x84, 0xCB, 0x0C, 0x3C, 0x27, 0x36, 0x40,
  33962. 0x10, 0x8A, 0x33, 0x97, 0x94, 0x45, 0x73, 0x27,
  33963. 0x93, 0x28, 0x99, 0x6C, 0xDC, 0x0C, 0x91, 0x3C,
  33964. 0x95, 0x8A, 0xD6, 0x20, 0xBA, 0x8B, 0x5E, 0x5E,
  33965. 0xCB, 0xBB, 0x7E, 0x13, 0xCB, 0x9C, 0x70, 0xBD,
  33966. 0x5A, 0xB3, 0x0E, 0xB7, 0x48, 0x8C, 0x97, 0x00,
  33967. 0x1C, 0x20, 0x49, 0x8F, 0x1D, 0x7C, 0xC0, 0x6D,
  33968. 0xA7, 0x6B, 0xF5, 0x20, 0xC6, 0x58, 0xCC, 0xAD,
  33969. 0xFA, 0x29, 0x56, 0x42, 0x45, 0x57, 0xAB, 0xEA,
  33970. 0x8A, 0xB8, 0x92, 0x39, 0xC1, 0x78, 0x33, 0xDC,
  33971. 0x3A, 0x49, 0xB3, 0x6A, 0x9A, 0xE9, 0xA4, 0x86,
  33972. 0x94, 0x05, 0x40, 0xEB, 0x44, 0x4F, 0x97, 0x15,
  33973. 0x23, 0x57, 0xE0, 0x20, 0x35, 0x93, 0x9D, 0x75,
  33974. 0xA3, 0xC0, 0x25, 0xF4, 0x1A, 0x40, 0x08, 0x23,
  33975. 0x82, 0xA0, 0x73, 0x3C, 0x39, 0xB0, 0x62, 0x2B,
  33976. 0x74, 0x0E, 0x40, 0x75, 0x92, 0xC6, 0x2E, 0xCA,
  33977. 0xEB, 0x14, 0x32, 0xC4, 0x45, 0xB3, 0x70, 0x3A,
  33978. 0x86, 0xF6, 0x98, 0x1A, 0x27, 0x81, 0x57, 0xEA,
  33979. 0x95, 0xA6, 0xE9, 0x2D, 0x55, 0xE4, 0xB9, 0x72,
  33980. 0xF9, 0x36, 0xC2, 0xF0, 0xA6, 0x58, 0x28, 0x0E,
  33981. 0xA2, 0xB0, 0x7A, 0x48, 0x99, 0x2D, 0xF8, 0x93,
  33982. 0x7E, 0x0A, 0x2A, 0xC1, 0xDC, 0xC9, 0x74, 0xFE,
  33983. 0x00, 0xAA, 0xE1, 0xF5, 0x61, 0xFA, 0x25, 0x8E,
  33984. 0x2D, 0x25, 0x9C, 0x3E, 0x86, 0x1D, 0xCE, 0x23,
  33985. 0x60, 0x39, 0x12, 0x76, 0x06, 0xFC, 0x1C, 0xE0,
  33986. 0x09, 0x00, 0x3A, 0x7B, 0xAC, 0x94, 0x21, 0x01,
  33987. 0xDC, 0xB8, 0x22, 0xB1, 0xF3, 0xC1, 0x2B, 0xF7,
  33988. 0x32, 0x38, 0xF5, 0x46, 0xE0, 0x1C, 0x36, 0xB5,
  33989. 0xA6, 0x93, 0x61, 0x92, 0x99, 0x5C, 0xC6, 0x9C,
  33990. 0x63, 0x23, 0x74, 0x09, 0xCB, 0x53, 0xC2, 0xE3,
  33991. 0x5D, 0x74, 0x89, 0x0D, 0x18, 0x88, 0x53, 0x76,
  33992. 0xFA, 0x55, 0x03, 0xB1, 0x07, 0xA2, 0xA3, 0x92,
  33993. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  33994. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  33995. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  33996. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  33997. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  33998. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  33999. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34000. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34001. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34002. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34003. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34004. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34005. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34006. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34007. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34008. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34009. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34010. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34011. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34012. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34013. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34014. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34015. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34016. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34017. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34018. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34019. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34020. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34021. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34022. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34023. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34024. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34025. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34026. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34027. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34028. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34029. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34030. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34031. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34032. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34033. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34034. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34035. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34036. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34037. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34038. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34039. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34040. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34041. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34042. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34043. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34044. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34045. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34046. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34047. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34048. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34049. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34050. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34051. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34052. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34053. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34054. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34055. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34056. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34057. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34058. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34059. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34060. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34061. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34062. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34063. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34064. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34065. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34066. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34067. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34068. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34069. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34070. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34071. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34072. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34073. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34074. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34075. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34076. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34077. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34078. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34079. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34080. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34081. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34082. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34083. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34084. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34085. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34086. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34087. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34088. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34089. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34090. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34091. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34092. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  34093. 0x7F, 0xFA, 0xD1, 0xBC, 0x8A, 0xF7, 0x3B, 0x7E,
  34094. 0x87, 0x49, 0x56, 0xB8, 0x1C, 0x2A, 0x2E, 0xF0,
  34095. 0xBF, 0xAB, 0xE8, 0xDC, 0x93, 0xD7, 0x7B, 0x2F,
  34096. 0xBC, 0x9E, 0x0C, 0x64, 0xEF, 0xA0, 0x1E, 0x84,
  34097. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34098. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34099. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34100. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34101. #else
  34102. 0x9c, 0xda, 0x16, 0x86, 0xa3, 0x39, 0x6a, 0x7c,
  34103. 0x10, 0x9b, 0x41, 0x52, 0x89, 0xf5, 0x6a, 0x9e,
  34104. 0xc4, 0x4c, 0xd5, 0xb9, 0xb6, 0x74, 0xc3, 0x8a,
  34105. 0x3b, 0xba, 0xb3, 0x0a, 0x2c, 0x90, 0xf0, 0x04,
  34106. 0x37, 0xa2, 0x64, 0xb0, 0xbe, 0x9a, 0x1e, 0x8b,
  34107. 0xa8, 0x87, 0xd3, 0xc3, 0xb1, 0x00, 0x89, 0x80,
  34108. 0x54, 0x27, 0x2f, 0x94, 0x1c, 0x88, 0xa1, 0xf2,
  34109. 0x08, 0xf1, 0xc9, 0x14, 0xf9, 0x64, 0xc1, 0xaa,
  34110. 0xd6, 0x13, 0xa6, 0xa8, 0x4f, 0x88, 0xe4, 0x2d,
  34111. 0x35, 0x56, 0x83, 0x5f, 0xb1, 0x61, 0xfd, 0xc5,
  34112. 0xcd, 0x15, 0xa3, 0xbc, 0x7e, 0x74, 0xb6, 0xf2,
  34113. 0x61, 0x2f, 0xa8, 0x27, 0x1c, 0x7e, 0xa1, 0x12,
  34114. 0xb0, 0x5c, 0x2a, 0x36, 0xcc, 0x70, 0x7c, 0xe3,
  34115. 0x8d, 0x5d, 0x1a, 0xcc, 0x51, 0x15, 0x46, 0x2a,
  34116. 0x8c, 0x1a, 0xab, 0xf0, 0x72, 0x76, 0xc7, 0x23,
  34117. 0x18, 0x33, 0x7f, 0x74, 0xb5, 0xcb, 0xef, 0xea,
  34118. 0x7a, 0x80, 0x37, 0x90, 0xbc, 0x03, 0x93, 0xf3,
  34119. 0xa5, 0x4c, 0x72, 0x4a, 0x57, 0x65, 0xa4, 0x8f,
  34120. 0x29, 0x6b, 0x03, 0xf4, 0x84, 0x37, 0x60, 0x23,
  34121. 0x62, 0x69, 0x30, 0x22, 0x27, 0x04, 0xc0, 0x8f,
  34122. 0xd3, 0xbc, 0x72, 0x93, 0x15, 0xd1, 0xfc, 0x70,
  34123. 0xeb, 0x79, 0x75, 0xa9, 0x7b, 0x9d, 0xee, 0xd1,
  34124. 0x62, 0xf4, 0x86, 0xbb, 0xc6, 0x4a, 0x09, 0x71,
  34125. 0x11, 0x95, 0x2d, 0x89, 0xb5, 0x7d, 0x76, 0x5e,
  34126. 0x8a, 0x99, 0x1a, 0x2e, 0x56, 0x42, 0x06, 0xea,
  34127. 0x7b, 0xf5, 0xe4, 0x00, 0x7a, 0x66, 0x35, 0x88,
  34128. 0x31, 0xca, 0x0e, 0x34, 0xb2, 0xf6, 0xa8, 0x4d,
  34129. 0x10, 0xf7, 0x9c, 0x47, 0x7c, 0xb6, 0x6a, 0x8a,
  34130. 0x95, 0x25, 0x69, 0x36, 0x73, 0x88, 0x13, 0x0d,
  34131. 0x7b, 0x97, 0x4a, 0x63, 0xaa, 0x51, 0x99, 0x6c,
  34132. 0x97, 0x70, 0x9b, 0xb8, 0xea, 0xbc, 0x94, 0xe6,
  34133. 0xa5, 0x35, 0xd7, 0x92, 0xd2, 0x90, 0x54, 0x74,
  34134. 0x95, 0x2d, 0x6b, 0x8c, 0x22, 0x22, 0xb2, 0xae,
  34135. 0x56, 0xdc, 0x66, 0xfb, 0x04, 0x61, 0x19, 0x20,
  34136. 0x66, 0xcd, 0xdb, 0x43, 0xec, 0x05, 0x98, 0x4f,
  34137. 0xb4, 0x98, 0x26, 0x49, 0x77, 0x13, 0x97, 0xc6,
  34138. 0xa8, 0x37, 0x9f, 0x3b, 0x56, 0x43, 0x06, 0x98,
  34139. 0x48, 0x87, 0x59, 0x19, 0xe8, 0x9c, 0xc4, 0x39,
  34140. 0xa3, 0xbe, 0x2f, 0x08, 0x14, 0x90, 0xf3, 0x41,
  34141. 0xbd, 0x12, 0x40, 0xad, 0xd8, 0x0d, 0xdb, 0x8c,
  34142. 0x99, 0x63, 0xb4, 0x7a, 0x2a, 0x09, 0x92, 0x29,
  34143. 0x03, 0x38, 0xda, 0x9c, 0x3b, 0x72, 0x5c, 0x6d,
  34144. 0xa4, 0x47, 0x18, 0xc0, 0x10, 0x46, 0x81, 0x25,
  34145. 0x62, 0xaf, 0xb0, 0x84, 0x83, 0x7a, 0xcb, 0x3c,
  34146. 0x57, 0x5e, 0x4f, 0x93, 0x93, 0x6c, 0x35, 0x2a,
  34147. 0xc0, 0xe7, 0x0a, 0xa3, 0x84, 0x5e, 0xe4, 0x85,
  34148. 0x29, 0x6e, 0x6b, 0x02, 0xde, 0x0b, 0x47, 0xb5,
  34149. 0xc4, 0xc9, 0x6b, 0x0b, 0x7c, 0xf9, 0x4c, 0x4a,
  34150. 0xbe, 0x95, 0x48, 0x61, 0x53, 0x11, 0x8e, 0x43,
  34151. 0xc2, 0xb9, 0xc8, 0x4d, 0x9d, 0xa9, 0x1c, 0x6c,
  34152. 0x5a, 0xcd, 0x5a, 0x57, 0x00, 0x2d, 0x05, 0x84,
  34153. 0x97, 0x99, 0x27, 0x99, 0xe5, 0xba, 0x1c, 0xe6,
  34154. 0xc2, 0x5e, 0xb2, 0x98, 0x44, 0xd8, 0x58, 0xba,
  34155. 0x1c, 0x37, 0x85, 0x0c, 0x0c, 0x2f, 0x57, 0xc6,
  34156. 0x0d, 0xe3, 0x7f, 0x77, 0xc0, 0x82, 0xec, 0x14,
  34157. 0x49, 0x4e, 0xba, 0x28, 0x8a, 0x65, 0x91, 0x51,
  34158. 0x16, 0xc2, 0x0a, 0x32, 0x5d, 0xe3, 0x1a, 0xaa,
  34159. 0xdd, 0x68, 0x0d, 0xb1, 0x9c, 0x0c, 0xfc, 0xc3,
  34160. 0x46, 0x0f, 0x0a, 0xa0, 0x1a, 0x87, 0xa6, 0xa5,
  34161. 0x80, 0xc6, 0xca, 0x29, 0x1f, 0xae, 0xf0, 0xcc,
  34162. 0xc4, 0x9b, 0x76, 0xa8, 0xda, 0xc4, 0xf9, 0xd4,
  34163. 0x16, 0x40, 0x50, 0x9d, 0xbd, 0x0b, 0x40, 0x45,
  34164. 0xc1, 0x53, 0x0e, 0xd3, 0x47, 0x55, 0xd4, 0x74,
  34165. 0x62, 0x70, 0x0f, 0x2a, 0x8c, 0xaf, 0x96, 0x80,
  34166. 0xa6, 0xd7, 0xe3, 0x8a, 0x7e, 0x2a, 0x63, 0xe9,
  34167. 0x37, 0x65, 0x0a, 0x23, 0x30, 0x6d, 0x85, 0x5d,
  34168. 0xa2, 0xa2, 0xb7, 0xef, 0x50, 0x5c, 0xa5, 0x96,
  34169. 0xab, 0x04, 0x85, 0x01, 0x3e, 0xa9, 0x27, 0xc7,
  34170. 0x34, 0x23, 0x43, 0x61, 0x36, 0x43, 0xba, 0x40,
  34171. 0x07, 0xd6, 0xc8, 0x74, 0xb9, 0x80, 0xc7, 0x9c,
  34172. 0x3a, 0xa1, 0xc7, 0x4f, 0x85, 0x81, 0xc3, 0x48,
  34173. 0x49, 0xb3, 0x6e, 0xa7, 0x98, 0x15, 0xfb, 0xb4,
  34174. 0xcc, 0xf9, 0x61, 0x05, 0x83, 0x08, 0x1d, 0x7c,
  34175. 0x5b, 0x44, 0x09, 0xb8, 0xd0, 0x53, 0x1c, 0x04,
  34176. 0xbc, 0xaf, 0x7c, 0xc7, 0x51, 0x10, 0x3a, 0x5f,
  34177. 0xd1, 0xba, 0x44, 0x70, 0x83, 0x3e, 0x89, 0x77,
  34178. 0x5a, 0xde, 0xd9, 0x70, 0xb5, 0x47, 0x18, 0x59,
  34179. 0x25, 0x0f, 0xe7, 0x26, 0x71, 0x05, 0x83, 0x5f,
  34180. 0x39, 0x00, 0x30, 0xc5, 0xe7, 0xcd, 0x3f, 0x96,
  34181. 0x10, 0x19, 0xea, 0xae, 0xa2, 0x37, 0x77, 0xd3,
  34182. 0x47, 0xbb, 0x2a, 0xdc, 0xb6, 0x73, 0xc0, 0x20,
  34183. 0x34, 0xf3, 0x94, 0x34, 0x22, 0x71, 0xbc, 0xea,
  34184. 0x64, 0x14, 0xe5, 0x46, 0xc3, 0xb2, 0x0b, 0xd5,
  34185. 0x74, 0x81, 0xc7, 0xea, 0x14, 0xc7, 0x7c, 0x38,
  34186. 0x8c, 0xc8, 0x62, 0x51, 0xc1, 0x25, 0x58, 0xb1,
  34187. 0x00, 0xf8, 0xc5, 0xb3, 0xd0, 0x3c, 0xa2, 0xc7,
  34188. 0x07, 0x13, 0x90, 0x96, 0x59, 0xc8, 0xba, 0x26,
  34189. 0xd0, 0xd1, 0x76, 0x5e, 0x0b, 0xc8, 0x23, 0xd6,
  34190. 0x8c, 0xa5, 0x57, 0x0d, 0xe6, 0x00, 0xcd, 0x09,
  34191. 0x41, 0x72, 0x5d, 0x38, 0x6e, 0x14, 0xc1, 0x01,
  34192. 0x2d, 0xf5, 0x95, 0x1b, 0xeb, 0x8d, 0x82, 0x81,
  34193. 0xa4, 0xf6, 0x81, 0x5d, 0x37, 0x60, 0xb7, 0x64,
  34194. 0x29, 0x5a, 0xd0, 0x40, 0x6c, 0x2b, 0xf7, 0x92,
  34195. 0x8a, 0xd6, 0x50, 0x32, 0xb6, 0x5f, 0x14, 0xb7,
  34196. 0x7c, 0xcb, 0x89, 0x17, 0xc9, 0x3a, 0x29, 0xd6,
  34197. 0x28, 0x7d, 0x8a, 0x60, 0x62, 0x39, 0x9c, 0xb6,
  34198. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34199. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34200. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34201. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34202. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34203. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34204. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34205. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34206. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34207. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34208. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34209. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34210. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34211. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34212. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34213. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34214. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34215. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34216. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34217. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34218. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34219. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34220. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34221. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34222. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34223. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34224. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34225. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34226. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34227. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34228. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34229. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34230. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34231. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34232. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34233. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34234. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34235. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34236. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34237. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34238. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34239. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34240. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34241. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34242. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34243. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34244. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34245. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34246. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34247. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34248. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34249. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34250. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34251. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34252. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34253. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34254. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34255. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34256. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34257. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34258. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34259. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34260. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34261. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34262. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34263. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34264. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34265. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34266. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34267. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34268. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34269. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34270. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34271. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34272. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34273. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34274. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34275. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34276. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34277. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34278. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34279. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34280. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34281. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34282. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34283. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34284. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34285. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34286. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34287. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34288. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34289. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34290. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34291. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34292. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34293. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34294. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34295. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34296. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34297. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39,
  34298. 0x50, 0xc8, 0xdd, 0x15, 0x2a, 0x45, 0x31, 0xaa,
  34299. 0xb5, 0x60, 0xd2, 0xfc, 0x7c, 0xa9, 0xa4, 0x0a,
  34300. 0xd8, 0xaf, 0x25, 0xad, 0x1d, 0xd0, 0x8c, 0x6d,
  34301. 0x79, 0xaf, 0xe4, 0xdd, 0x4d, 0x1e, 0xee, 0x5a,
  34302. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  34303. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  34304. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  34305. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  34306. #endif
  34307. };
  34308. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ct[] = {
  34309. #ifdef WOLFSSL_KYBER_ORIGINAL
  34310. 0xED, 0xF2, 0x41, 0x45, 0xE4, 0x3B, 0x4F, 0x6D,
  34311. 0xC6, 0xBF, 0x83, 0x32, 0xF5, 0x4E, 0x02, 0xCA,
  34312. 0xB0, 0x2D, 0xBF, 0x3B, 0x56, 0x05, 0xDD, 0xC9,
  34313. 0x0A, 0x15, 0xC8, 0x86, 0xAD, 0x3E, 0xD4, 0x89,
  34314. 0x46, 0x26, 0x99, 0xE4, 0xAB, 0xED, 0x44, 0x35,
  34315. 0x0B, 0xC3, 0x75, 0x7E, 0x26, 0x96, 0xFB, 0xFB,
  34316. 0x25, 0x34, 0x41, 0x2E, 0x8D, 0xD2, 0x01, 0xF1,
  34317. 0xE4, 0x54, 0x0A, 0x39, 0x70, 0xB0, 0x55, 0xFE,
  34318. 0x3B, 0x0B, 0xEC, 0x3A, 0x71, 0xF9, 0xE1, 0x15,
  34319. 0xB3, 0xF9, 0xF3, 0x91, 0x02, 0x06, 0x5B, 0x1C,
  34320. 0xCA, 0x83, 0x14, 0xDC, 0xC7, 0x95, 0xE3, 0xC0,
  34321. 0xE8, 0xFA, 0x98, 0xEE, 0x83, 0xCA, 0x66, 0x28,
  34322. 0x45, 0x70, 0x28, 0xA4, 0xD0, 0x9E, 0x83, 0x9E,
  34323. 0x55, 0x48, 0x62, 0xCF, 0x0B, 0x7B, 0xF5, 0x6C,
  34324. 0x5C, 0x0A, 0x82, 0x9E, 0x86, 0x57, 0x94, 0x79,
  34325. 0x45, 0xFE, 0x9C, 0x22, 0x56, 0x4F, 0xBA, 0xEB,
  34326. 0xC1, 0xB3, 0xAF, 0x35, 0x0D, 0x79, 0x55, 0x50,
  34327. 0x8A, 0x26, 0xD8, 0xA8, 0xEB, 0x54, 0x7B, 0x8B,
  34328. 0x1A, 0x2C, 0xF0, 0x3C, 0xCA, 0x1A, 0xAB, 0xCE,
  34329. 0x6C, 0x34, 0x97, 0x78, 0x3B, 0x64, 0x65, 0xBA,
  34330. 0x0B, 0x6E, 0x7A, 0xCB, 0xA8, 0x21, 0x19, 0x51,
  34331. 0x24, 0xAE, 0xF0, 0x9E, 0x62, 0x83, 0x82, 0xA1,
  34332. 0xF9, 0x14, 0x04, 0x3B, 0xE7, 0x09, 0x6E, 0x95,
  34333. 0x2C, 0xBC, 0x4F, 0xB4, 0xAF, 0xED, 0x13, 0x60,
  34334. 0x90, 0x46, 0x11, 0x7C, 0x01, 0x1F, 0xD7, 0x41,
  34335. 0xEE, 0x28, 0x6C, 0x83, 0x77, 0x16, 0x90, 0xF0,
  34336. 0xAE, 0xB5, 0x0D, 0xA0, 0xD7, 0x12, 0x85, 0xA1,
  34337. 0x79, 0xB2, 0x15, 0xC6, 0x03, 0x6D, 0xEB, 0x78,
  34338. 0x0F, 0x4D, 0x16, 0x76, 0x9F, 0x72, 0xDE, 0x16,
  34339. 0xFD, 0xAD, 0xAC, 0x73, 0xBE, 0xFA, 0x5B, 0xEF,
  34340. 0x89, 0x43, 0x19, 0x7F, 0x44, 0xC5, 0x95, 0x89,
  34341. 0xDC, 0x9F, 0x49, 0x73, 0xDE, 0x14, 0x50, 0xBA,
  34342. 0x1D, 0x0C, 0x32, 0x90, 0xD6, 0xB1, 0xD6, 0x83,
  34343. 0xF2, 0x94, 0xE7, 0x59, 0xC9, 0x54, 0xAB, 0xE8,
  34344. 0xA7, 0xDA, 0x5B, 0x10, 0x54, 0xFD, 0x6D, 0x21,
  34345. 0x32, 0x9B, 0x8E, 0x73, 0xD3, 0x75, 0x6A, 0xFD,
  34346. 0xA0, 0xDC, 0xB1, 0xFC, 0x8B, 0x15, 0x82, 0xD1,
  34347. 0xF9, 0x0C, 0xF2, 0x75, 0xA1, 0x02, 0xAB, 0xC6,
  34348. 0xAC, 0x69, 0x9D, 0xF0, 0xC5, 0x87, 0x0E, 0x50,
  34349. 0xA1, 0xF9, 0x89, 0xE4, 0xE6, 0x24, 0x1B, 0x60,
  34350. 0xAA, 0xA2, 0xEC, 0xF9, 0xE8, 0xE3, 0x3E, 0x0F,
  34351. 0xFC, 0xF4, 0x0F, 0xE8, 0x31, 0xE8, 0xFD, 0xC2,
  34352. 0xE8, 0x3B, 0x52, 0xCA, 0x7A, 0xB6, 0xD9, 0x3F,
  34353. 0x14, 0x6D, 0x29, 0xDC, 0xA5, 0x3C, 0x7D, 0xA1,
  34354. 0xDB, 0x4A, 0xC4, 0xF2, 0xDB, 0x39, 0xEA, 0x12,
  34355. 0x0D, 0x90, 0xFA, 0x60, 0xF4, 0xD4, 0x37, 0xC6,
  34356. 0xD0, 0x0E, 0xF4, 0x83, 0xBC, 0x94, 0xA3, 0x17,
  34357. 0x5C, 0xDA, 0x16, 0x3F, 0xC1, 0xC2, 0x82, 0x8B,
  34358. 0xE4, 0xDB, 0xD6, 0x43, 0x05, 0x07, 0xB5, 0x84,
  34359. 0xBB, 0x51, 0x77, 0xE1, 0x71, 0xB8, 0xDD, 0xA9,
  34360. 0xA4, 0x29, 0x3C, 0x32, 0x00, 0x29, 0x5C, 0x80,
  34361. 0x3A, 0x86, 0x5D, 0x6D, 0x21, 0x66, 0xF6, 0x6B,
  34362. 0xA5, 0x40, 0x1F, 0xB7, 0xA0, 0xE8, 0x53, 0x16,
  34363. 0x86, 0x00, 0xA2, 0x94, 0x84, 0x37, 0xE0, 0x36,
  34364. 0xE3, 0xBF, 0x19, 0xE1, 0x2F, 0xD3, 0xF2, 0xA2,
  34365. 0xB8, 0xB3, 0x43, 0xF7, 0x84, 0x24, 0x8E, 0x8D,
  34366. 0x68, 0x5E, 0xB0, 0xAF, 0xDE, 0x63, 0x15, 0x33,
  34367. 0x87, 0x30, 0xE7, 0xA1, 0x00, 0x1C, 0x27, 0xD8,
  34368. 0xD2, 0xA7, 0x6F, 0xA6, 0x9D, 0x15, 0x7B, 0xA1,
  34369. 0xAC, 0x7A, 0xD5, 0x6D, 0xA5, 0xA8, 0xC7, 0x0F,
  34370. 0xE4, 0xB5, 0xB8, 0xD7, 0x86, 0xDC, 0x6F, 0xC0,
  34371. 0x56, 0x6B, 0xA8, 0xE1, 0xB8, 0x81, 0x63, 0x34,
  34372. 0xD3, 0x2A, 0x3F, 0xB1, 0xCE, 0x7D, 0x4D, 0x5E,
  34373. 0x4C, 0x33, 0x2A, 0xF7, 0xB0, 0x03, 0xD0, 0x91,
  34374. 0x74, 0x1A, 0x3D, 0x5C, 0x96, 0x52, 0x92, 0x25,
  34375. 0x5D, 0xFF, 0x8E, 0xD2, 0xBB, 0xF1, 0xF9, 0x11,
  34376. 0x6B, 0xE5, 0x0C, 0x17, 0xB8, 0xE5, 0x48, 0x74,
  34377. 0x8A, 0xD4, 0xB2, 0xE9, 0x57, 0xBB, 0xD1, 0x95,
  34378. 0x34, 0x82, 0xA2, 0xE1, 0x71, 0x8C, 0xEC, 0x66,
  34379. 0xCD, 0x2C, 0x81, 0xF5, 0x72, 0xD5, 0x52, 0xB7,
  34380. 0x18, 0x78, 0x85, 0xE6, 0xB8, 0x94, 0x3D, 0x64,
  34381. 0x31, 0x41, 0x3C, 0x59, 0xEB, 0xB7, 0xE0, 0x36,
  34382. 0x04, 0x84, 0x90, 0xBE, 0x52, 0x89, 0xE9, 0x5B,
  34383. 0x20, 0xA8, 0x9E, 0x8B, 0x15, 0x9F, 0x61, 0xA9,
  34384. 0xA9, 0x88, 0x6E, 0x14, 0x75, 0x68, 0xF4, 0xC9,
  34385. 0x02, 0x1F, 0x36, 0x2F, 0x02, 0x68, 0x8A, 0x1C,
  34386. 0x8C, 0x3B, 0xB0, 0xD2, 0x40, 0x86, 0x88, 0x0E,
  34387. 0x55, 0xB6, 0xED, 0xB4, 0x3F, 0x37, 0x45, 0xD2,
  34388. 0xC1, 0x66, 0xDC, 0x1C, 0xB7, 0x43, 0xC7, 0x6F,
  34389. 0xE6, 0xBE, 0x52, 0x3A, 0x89, 0x3C, 0xC7, 0x64,
  34390. 0xD1, 0x64, 0x35, 0xC3, 0x78, 0x51, 0x25, 0x2A,
  34391. 0x81, 0xE2, 0xFF, 0xBA, 0x0F, 0x18, 0x97, 0x1A,
  34392. 0x3D, 0xEE, 0x37, 0xD4, 0x87, 0x7C, 0xB9, 0x28,
  34393. 0xE3, 0x6E, 0x52, 0x35, 0x03, 0x7A, 0x6B, 0x20,
  34394. 0x57, 0x89, 0x7D, 0x51, 0x8A, 0x5F, 0x0E, 0x34,
  34395. 0x8E, 0x3A, 0xB6, 0xD5, 0xB5, 0x2D, 0xFC, 0x60,
  34396. 0x75, 0x7F, 0x3B, 0x41, 0xA4, 0xFE, 0xC7, 0x82,
  34397. 0x8F, 0x1D, 0xEE, 0xAF, 0x45, 0x87, 0xCC, 0xC8,
  34398. 0xEA, 0xDF, 0x64, 0x7F, 0x4D, 0x20, 0x3B, 0x2F,
  34399. 0xAA, 0x05, 0xA6, 0x49, 0xB5, 0x82, 0x34, 0x0C,
  34400. 0xB4, 0xCA, 0xCE, 0x57, 0xA3, 0x07, 0x11, 0xBE,
  34401. 0x75, 0x2F, 0xAC, 0xF0, 0x22, 0x7D, 0x0A, 0x80,
  34402. 0xC4, 0x12, 0x84, 0x42, 0xDD, 0xC5, 0x44, 0xBE,
  34403. 0x80, 0x5B, 0x9C, 0xFE, 0x8F, 0xE9, 0xB1, 0x23,
  34404. 0x7C, 0x80, 0xF9, 0x67, 0x87, 0xCD, 0x92, 0x81,
  34405. 0xCC, 0xF2, 0x70, 0xC1, 0xAF, 0xC0, 0x67, 0x0D
  34406. #else
  34407. 0x11, 0x3d, 0xb2, 0xdd, 0x06, 0x87, 0x12, 0x35,
  34408. 0xe7, 0xbc, 0x36, 0xc9, 0xdc, 0xaa, 0x52, 0x8f,
  34409. 0xc2, 0x6c, 0xe5, 0xdb, 0x9e, 0xcc, 0x1d, 0xc3,
  34410. 0x2e, 0x95, 0x7d, 0x7f, 0xfb, 0x3c, 0x74, 0x29,
  34411. 0xd5, 0x0c, 0x3c, 0x35, 0x77, 0xa5, 0x15, 0xd3,
  34412. 0x18, 0x3a, 0x1b, 0x9d, 0x26, 0x7b, 0x93, 0x6b,
  34413. 0x7e, 0xb8, 0xf5, 0x43, 0xa3, 0xaf, 0xb7, 0x77,
  34414. 0x65, 0xca, 0x79, 0x38, 0xf7, 0x8a, 0xa6, 0x43,
  34415. 0x8c, 0xe8, 0x0a, 0x06, 0xa6, 0x96, 0x6d, 0x0d,
  34416. 0x06, 0xaf, 0x75, 0xba, 0x3e, 0x0d, 0x4f, 0x37,
  34417. 0xba, 0xc7, 0x33, 0x69, 0xf5, 0xa7, 0x29, 0xf7,
  34418. 0x3e, 0x85, 0x72, 0x9e, 0xdd, 0x97, 0xc8, 0xc2,
  34419. 0xa8, 0xcc, 0x26, 0x19, 0xe4, 0xcf, 0x7b, 0x60,
  34420. 0x91, 0x86, 0x9e, 0x90, 0x9f, 0xd4, 0x7d, 0x97,
  34421. 0x09, 0x14, 0x92, 0x04, 0xb0, 0x83, 0x7d, 0x8d,
  34422. 0x6f, 0x25, 0xd2, 0x67, 0x97, 0x2b, 0xe6, 0x3b,
  34423. 0xad, 0x34, 0xb5, 0x44, 0x52, 0x3c, 0x01, 0xc0,
  34424. 0x9d, 0xe3, 0xb1, 0xfa, 0x1d, 0x6b, 0x7b, 0x05,
  34425. 0x9e, 0xee, 0x9e, 0x65, 0x20, 0x62, 0xfe, 0x87,
  34426. 0x0f, 0x68, 0xc6, 0x80, 0x05, 0x33, 0x9e, 0xa1,
  34427. 0x81, 0xe1, 0xd0, 0x76, 0x7c, 0x15, 0x2a, 0xeb,
  34428. 0x38, 0xfa, 0xf0, 0xf9, 0x24, 0x5a, 0xe5, 0x9d,
  34429. 0x5c, 0xb0, 0xd2, 0xb7, 0xf2, 0x01, 0x22, 0x9e,
  34430. 0xd9, 0x70, 0x20, 0xd0, 0x62, 0x3a, 0x46, 0x10,
  34431. 0x0d, 0x09, 0x7b, 0x0c, 0xe1, 0x15, 0x4e, 0x02,
  34432. 0x8a, 0xe6, 0x19, 0x4d, 0xe0, 0x5d, 0xe9, 0x7d,
  34433. 0xd9, 0xae, 0x2e, 0x85, 0xff, 0xd2, 0x5d, 0x95,
  34434. 0xeb, 0x22, 0xef, 0xfe, 0x5b, 0xa1, 0x9c, 0xd8,
  34435. 0x07, 0xc5, 0x30, 0xeb, 0xaa, 0x9f, 0xe9, 0xf6,
  34436. 0x42, 0xcc, 0xac, 0xff, 0x47, 0xed, 0x15, 0xc2,
  34437. 0x2b, 0xfe, 0x30, 0x36, 0xeb, 0xf8, 0xad, 0x9c,
  34438. 0x8e, 0xd2, 0x32, 0x40, 0xae, 0xeb, 0xaa, 0x24,
  34439. 0xd1, 0x35, 0x75, 0x51, 0x00, 0xb8, 0x5e, 0xce,
  34440. 0xe3, 0x17, 0x49, 0x06, 0xe4, 0x63, 0x12, 0x06,
  34441. 0x2c, 0xee, 0xca, 0xc7, 0x5d, 0xe5, 0x27, 0x52,
  34442. 0x56, 0xc2, 0xc1, 0xa6, 0x53, 0xfd, 0x69, 0x15,
  34443. 0xb1, 0xb3, 0x0c, 0x8e, 0xcb, 0xb6, 0xfd, 0x42,
  34444. 0x80, 0x43, 0x74, 0x53, 0x17, 0x3a, 0x96, 0x23,
  34445. 0x8b, 0xc7, 0xd1, 0x08, 0x89, 0x23, 0x43, 0xe0,
  34446. 0x33, 0xbc, 0xd9, 0x8e, 0x43, 0x7e, 0x78, 0x9f,
  34447. 0xc5, 0xbe, 0xba, 0xa1, 0x2b, 0x26, 0x34, 0xb5,
  34448. 0x1e, 0xd0, 0xd5, 0x89, 0xf1, 0x11, 0x43, 0xa0,
  34449. 0x21, 0xd8, 0xec, 0xce, 0x59, 0x4f, 0xdd, 0x48,
  34450. 0xda, 0xe8, 0x4c, 0x80, 0x63, 0xef, 0x35, 0x81,
  34451. 0xbc, 0x37, 0x8a, 0x48, 0xda, 0x4e, 0x51, 0xbb,
  34452. 0x17, 0x5b, 0x0d, 0xb4, 0x7f, 0x9d, 0xcf, 0x99,
  34453. 0x31, 0x8c, 0x30, 0x22, 0x5c, 0xa7, 0xfa, 0x79,
  34454. 0xc8, 0x79, 0xbf, 0x1c, 0x93, 0x97, 0xb5, 0xcc,
  34455. 0xc5, 0xef, 0xad, 0x94, 0xc5, 0x00, 0xed, 0x7f,
  34456. 0x9f, 0x38, 0x5d, 0x08, 0x8e, 0x34, 0x93, 0x22,
  34457. 0x21, 0xfc, 0x0f, 0xc9, 0xaf, 0xe5, 0x1f, 0x68,
  34458. 0x75, 0x54, 0x81, 0x31, 0x69, 0x76, 0x95, 0x47,
  34459. 0x8a, 0xbd, 0xc8, 0x73, 0x6f, 0x10, 0x09, 0x5a,
  34460. 0x6b, 0x92, 0xec, 0x67, 0x9f, 0xe0, 0xe2, 0xae,
  34461. 0x5d, 0x8b, 0x33, 0x53, 0x55, 0xd5, 0x8d, 0xae,
  34462. 0x4d, 0x4f, 0x0b, 0x17, 0xaa, 0x5d, 0x1e, 0x52,
  34463. 0xf1, 0xd4, 0x55, 0x84, 0xa8, 0x92, 0xc3, 0x4c,
  34464. 0xe4, 0xb0, 0x4f, 0xcd, 0x00, 0x98, 0x1d, 0x51,
  34465. 0xca, 0xa1, 0x60, 0x64, 0xba, 0xd9, 0x2d, 0x01,
  34466. 0x9d, 0xc3, 0xad, 0xed, 0x91, 0x96, 0x84, 0x11,
  34467. 0x2b, 0x29, 0xda, 0xa2, 0x8b, 0x9d, 0xae, 0x09,
  34468. 0xb8, 0x6b, 0x21, 0xa9, 0x33, 0x10, 0xd5, 0xfb,
  34469. 0xc6, 0x52, 0x7b, 0x22, 0x4b, 0x9c, 0xe8, 0x7d,
  34470. 0x27, 0x82, 0xbb, 0x29, 0x46, 0x73, 0xf0, 0xec,
  34471. 0x06, 0xf2, 0x6b, 0x08, 0x76, 0x52, 0xa1, 0x8d,
  34472. 0x6a, 0xd7, 0xb1, 0xc9, 0x33, 0x03, 0xef, 0x05,
  34473. 0x61, 0xc0, 0xfc, 0x9c, 0xd4, 0xf6, 0x78, 0xf6,
  34474. 0x06, 0xf1, 0x92, 0xcf, 0x5d, 0xf9, 0x2b, 0x15,
  34475. 0x48, 0xf5, 0xdd, 0x26, 0x87, 0xed, 0xbe, 0xcc,
  34476. 0xfc, 0x6d, 0x4e, 0x9d, 0xe4, 0xbd, 0x50, 0xd3,
  34477. 0xc7, 0x4f, 0xb2, 0x75, 0xab, 0xd9, 0xb3, 0xe9,
  34478. 0x02, 0x77, 0xdb, 0x4a, 0x00, 0x69, 0xc0, 0xa2,
  34479. 0xa7, 0x13, 0x6f, 0x50, 0xce, 0xad, 0x4b, 0x2f,
  34480. 0x19, 0x95, 0xfa, 0xaf, 0x16, 0x80, 0x40, 0xe9,
  34481. 0xe4, 0xbe, 0xb7, 0xc5, 0x72, 0x20, 0x49, 0xd6,
  34482. 0xda, 0x64, 0x02, 0x99, 0x2f, 0xce, 0xa4, 0x50,
  34483. 0x97, 0xdf, 0x7c, 0x1c, 0x20, 0xfb, 0x06, 0x82,
  34484. 0x22, 0x00, 0x05, 0x76, 0x93, 0x5a, 0x08, 0x06,
  34485. 0x77, 0x34, 0x51, 0x92, 0x1f, 0x54, 0xc5, 0x5f,
  34486. 0xbf, 0x59, 0x3a, 0x4f, 0x14, 0x7c, 0x1f, 0xef,
  34487. 0x3a, 0xca, 0xf0, 0xcf, 0xa9, 0x07, 0xae, 0x48,
  34488. 0xc8, 0xc0, 0x63, 0x12, 0xcf, 0xdf, 0x51, 0x86,
  34489. 0x90, 0x4b, 0xec, 0x7f, 0xed, 0x4e, 0xd9, 0x33,
  34490. 0xc9, 0x25, 0x6a, 0xb0, 0x4c, 0xbf, 0xa0, 0x3a,
  34491. 0x96, 0x7c, 0x1f, 0x7e, 0xad, 0x4a, 0xb4, 0x0d,
  34492. 0xf1, 0x16, 0xbe, 0x66, 0x0e, 0x27, 0xca, 0x2b,
  34493. 0x54, 0x35, 0x26, 0xd4, 0xb9, 0x68, 0x4c, 0x31,
  34494. 0xe1, 0xe4, 0x23, 0x83, 0xb9, 0x69, 0xf8, 0x96,
  34495. 0x29, 0x9d, 0x71, 0x39, 0x0c, 0xc8, 0x5b, 0x70,
  34496. 0x32, 0x02, 0xac, 0xad, 0xec, 0xfa, 0x8c, 0x40,
  34497. 0x96, 0x5c, 0x08, 0xc5, 0x3b, 0x56, 0x71, 0xe0,
  34498. 0xd5, 0x94, 0x55, 0xbc, 0x5a, 0x85, 0x86, 0xc6,
  34499. 0x55, 0xdb, 0x8c, 0x2a, 0xde, 0x4b, 0xa8, 0x87,
  34500. 0x7f, 0x19, 0xb6, 0x00, 0x0e, 0x18, 0xf8, 0xfe,
  34501. 0xad, 0xda, 0x7e, 0xde, 0x8f, 0xe8, 0x0a, 0xa6,
  34502. 0x62, 0xd6, 0x94, 0xc6, 0xd8, 0xc3, 0x3b, 0x52
  34503. #endif
  34504. };
  34505. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ss[] = {
  34506. #ifdef WOLFSSL_KYBER_ORIGINAL
  34507. 0x0A, 0x69, 0x25, 0x67, 0x6F, 0x24, 0xB2, 0x2C,
  34508. 0x28, 0x6F, 0x4C, 0x81, 0xA4, 0x22, 0x4C, 0xEC,
  34509. 0x50, 0x6C, 0x9B, 0x25, 0x7D, 0x48, 0x0E, 0x02,
  34510. 0xE3, 0xB4, 0x9F, 0x44, 0xCA, 0xA3, 0x23, 0x7F
  34511. #else
  34512. 0x31, 0x98, 0x39, 0xe8, 0x2a, 0xb6, 0xb2, 0x22,
  34513. 0xde, 0x7b, 0x61, 0x9e, 0x80, 0xda, 0x83, 0x91,
  34514. 0x52, 0x2b, 0xbb, 0x37, 0x67, 0x70, 0x18, 0x49,
  34515. 0x4a, 0x47, 0x42, 0xc5, 0x3f, 0x9a, 0xbf, 0xdf
  34516. #endif
  34517. };
  34518. #ifdef WOLFSSL_SMALL_STACK
  34519. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  34520. DYNAMIC_TYPE_TMP_BUFFER);
  34521. priv = (byte *)XMALLOC(KYBER512_PRIVATE_KEY_SIZE, HEAP_HINT,
  34522. DYNAMIC_TYPE_TMP_BUFFER);
  34523. pub = (byte *)XMALLOC(KYBER512_PUBLIC_KEY_SIZE, HEAP_HINT,
  34524. DYNAMIC_TYPE_TMP_BUFFER);
  34525. ct = (byte *)XMALLOC(KYBER512_CIPHER_TEXT_SIZE, HEAP_HINT,
  34526. DYNAMIC_TYPE_TMP_BUFFER);
  34527. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34528. DYNAMIC_TYPE_TMP_BUFFER);
  34529. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34530. DYNAMIC_TYPE_TMP_BUFFER);
  34531. if (! (key && priv && pub && ct && ss && ss_dec))
  34532. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  34533. #endif
  34534. ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
  34535. if (ret != 0)
  34536. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34537. else
  34538. key_inited = 1;
  34539. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34540. sizeof(kyber512_rand));
  34541. if (ret != 0)
  34542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34543. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
  34544. if (ret != 0)
  34545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34546. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
  34547. if (ret != 0)
  34548. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34549. if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0)
  34550. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34551. if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
  34552. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34553. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34554. sizeof(kyber512enc_rand));
  34555. if (ret != 0)
  34556. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34557. if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0)
  34558. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34559. if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34560. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34561. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
  34562. if (ret != 0)
  34563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34564. if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34565. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34566. out:
  34567. if (key_inited)
  34568. wc_KyberKey_Free(key);
  34569. #ifdef WOLFSSL_SMALL_STACK
  34570. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34571. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34572. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34573. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34574. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34575. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34576. #endif
  34577. return ret;
  34578. }
  34579. #endif /* WOLFSSL_KYBER512 */
  34580. #ifdef WOLFSSL_KYBER768
  34581. static wc_test_ret_t kyber768_kat(void)
  34582. {
  34583. wc_test_ret_t ret;
  34584. #ifdef WOLFSSL_SMALL_STACK
  34585. KyberKey *key = NULL;
  34586. byte *priv = NULL;
  34587. byte *pub = NULL;
  34588. byte *ct = NULL;
  34589. byte *ss = NULL;
  34590. byte *ss_dec = NULL;
  34591. #else
  34592. KyberKey key[1];
  34593. byte priv[KYBER768_PRIVATE_KEY_SIZE];
  34594. byte pub[KYBER768_PUBLIC_KEY_SIZE];
  34595. byte ct[KYBER768_CIPHER_TEXT_SIZE];
  34596. byte ss[KYBER_SS_SZ];
  34597. byte ss_dec[KYBER_SS_SZ];
  34598. #endif
  34599. int key_inited = 0;
  34600. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_rand[] = {
  34601. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34602. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34603. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34604. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34605. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34606. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34607. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34608. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34609. };
  34610. WOLFSSL_SMALL_STACK_STATIC const byte kyber768enc_rand[] = {
  34611. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34612. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34613. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34614. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34615. };
  34616. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_pk[] = {
  34617. #ifdef WOLFSSL_KYBER_ORIGINAL
  34618. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  34619. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  34620. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  34621. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  34622. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  34623. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  34624. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  34625. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  34626. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  34627. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  34628. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  34629. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  34630. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  34631. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  34632. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  34633. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  34634. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  34635. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  34636. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  34637. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  34638. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  34639. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  34640. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  34641. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  34642. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  34643. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  34644. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  34645. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  34646. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  34647. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  34648. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  34649. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  34650. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  34651. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  34652. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  34653. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  34654. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  34655. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  34656. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  34657. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  34658. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  34659. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  34660. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  34661. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  34662. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  34663. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  34664. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  34665. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  34666. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  34667. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  34668. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  34669. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  34670. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  34671. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  34672. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  34673. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  34674. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  34675. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  34676. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  34677. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  34678. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  34679. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  34680. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  34681. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  34682. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  34683. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  34684. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  34685. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  34686. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  34687. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  34688. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  34689. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  34690. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  34691. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  34692. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  34693. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  34694. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  34695. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  34696. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  34697. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  34698. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  34699. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  34700. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  34701. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  34702. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  34703. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  34704. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  34705. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  34706. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  34707. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  34708. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  34709. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  34710. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  34711. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  34712. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  34713. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  34714. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  34715. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  34716. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  34717. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  34718. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  34719. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  34720. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  34721. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  34722. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  34723. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  34724. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  34725. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  34726. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  34727. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  34728. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  34729. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  34730. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  34731. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  34732. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  34733. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  34734. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  34735. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  34736. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  34737. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  34738. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  34739. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  34740. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  34741. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  34742. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  34743. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  34744. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  34745. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  34746. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  34747. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  34748. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  34749. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  34750. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  34751. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  34752. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  34753. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  34754. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  34755. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  34756. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  34757. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  34758. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  34759. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  34760. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  34761. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  34762. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34763. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34764. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34765. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  34766. #else
  34767. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  34768. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  34769. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  34770. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  34771. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  34772. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  34773. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  34774. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  34775. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  34776. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  34777. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  34778. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  34779. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  34780. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  34781. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  34782. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  34783. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  34784. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  34785. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  34786. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  34787. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  34788. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  34789. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  34790. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  34791. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  34792. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  34793. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  34794. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  34795. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  34796. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  34797. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  34798. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  34799. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  34800. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  34801. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  34802. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  34803. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  34804. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  34805. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  34806. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  34807. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  34808. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  34809. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  34810. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  34811. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  34812. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  34813. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  34814. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  34815. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  34816. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  34817. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  34818. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  34819. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  34820. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  34821. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  34822. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  34823. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  34824. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  34825. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  34826. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  34827. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  34828. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  34829. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  34830. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  34831. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  34832. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  34833. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  34834. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  34835. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  34836. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  34837. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  34838. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  34839. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  34840. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  34841. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  34842. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  34843. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  34844. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  34845. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  34846. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  34847. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  34848. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  34849. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  34850. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  34851. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  34852. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  34853. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  34854. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  34855. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  34856. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  34857. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  34858. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  34859. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  34860. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  34861. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  34862. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  34863. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  34864. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  34865. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  34866. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  34867. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  34868. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  34869. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  34870. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  34871. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  34872. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  34873. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  34874. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  34875. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  34876. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  34877. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  34878. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  34879. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  34880. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  34881. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  34882. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  34883. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  34884. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  34885. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  34886. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  34887. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  34888. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  34889. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  34890. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  34891. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  34892. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  34893. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  34894. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  34895. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  34896. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  34897. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  34898. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  34899. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  34900. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  34901. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  34902. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  34903. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  34904. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  34905. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  34906. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  34907. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  34908. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  34909. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  34910. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  34911. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  34912. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  34913. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  34914. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28
  34915. #endif
  34916. };
  34917. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_sk[] = {
  34918. #ifdef WOLFSSL_KYBER_ORIGINAL
  34919. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  34920. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  34921. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  34922. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  34923. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  34924. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  34925. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  34926. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  34927. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  34928. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  34929. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  34930. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  34931. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  34932. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  34933. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  34934. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  34935. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  34936. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  34937. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  34938. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  34939. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  34940. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  34941. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  34942. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  34943. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  34944. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  34945. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  34946. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  34947. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  34948. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  34949. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  34950. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  34951. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  34952. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  34953. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  34954. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  34955. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  34956. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  34957. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  34958. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  34959. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  34960. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  34961. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  34962. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  34963. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  34964. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  34965. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  34966. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  34967. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  34968. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  34969. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  34970. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  34971. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  34972. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  34973. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  34974. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  34975. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  34976. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  34977. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  34978. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  34979. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  34980. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  34981. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  34982. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  34983. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  34984. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  34985. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  34986. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  34987. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  34988. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  34989. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  34990. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  34991. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  34992. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  34993. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  34994. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  34995. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  34996. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  34997. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  34998. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  34999. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  35000. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  35001. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  35002. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  35003. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  35004. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  35005. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  35006. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  35007. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  35008. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  35009. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  35010. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  35011. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  35012. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  35013. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  35014. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  35015. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  35016. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  35017. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  35018. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  35019. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  35020. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  35021. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  35022. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  35023. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  35024. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  35025. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  35026. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  35027. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  35028. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  35029. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  35030. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  35031. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  35032. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  35033. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  35034. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  35035. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  35036. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  35037. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  35038. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  35039. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  35040. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  35041. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  35042. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  35043. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  35044. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  35045. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  35046. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  35047. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  35048. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  35049. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  35050. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  35051. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  35052. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  35053. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  35054. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  35055. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  35056. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  35057. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  35058. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  35059. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  35060. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  35061. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  35062. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  35063. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35064. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35065. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35066. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35067. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35068. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35069. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35070. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35071. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35072. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35073. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35074. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35075. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35076. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35077. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35078. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35079. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35080. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35081. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35082. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35083. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35084. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35085. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35086. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35087. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35088. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35089. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35090. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35091. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35092. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35093. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35094. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35095. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35096. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35097. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35098. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35099. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35100. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35101. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35102. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35103. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35104. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35105. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35106. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35107. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35108. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35109. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35110. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35111. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35112. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35113. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35114. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35115. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35116. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35117. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35118. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35119. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35120. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35121. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35122. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35123. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35124. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35125. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35126. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35127. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35128. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35129. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35130. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35131. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35132. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35133. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35134. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35135. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35136. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35137. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35138. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35139. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35140. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35141. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35142. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35143. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35144. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35145. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35146. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35147. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35148. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35149. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35150. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35151. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35152. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35153. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35154. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35155. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35156. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35157. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35158. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35159. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35160. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35161. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35162. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35163. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35164. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35165. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35166. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35167. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35168. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35169. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35170. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35171. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35172. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35173. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35174. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35175. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35176. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35177. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35178. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35179. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35180. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35181. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35182. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35183. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35184. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35185. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35186. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35187. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35188. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35189. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35190. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35191. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35192. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35193. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35194. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35195. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35196. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35197. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35198. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35199. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35200. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35201. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35202. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35203. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35204. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35205. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35206. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35207. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35208. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35209. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35210. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  35211. 0xD4, 0xEC, 0x14, 0x3B, 0x50, 0xF0, 0x14, 0x23,
  35212. 0xB1, 0x77, 0x89, 0x5E, 0xDE, 0xE2, 0x2B, 0xB7,
  35213. 0x39, 0xF6, 0x47, 0xEC, 0xF8, 0x5F, 0x50, 0xBC,
  35214. 0x25, 0xEF, 0x7B, 0x5A, 0x72, 0x5D, 0xEE, 0x86,
  35215. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35216. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35217. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35218. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35219. #else
  35220. 0xda, 0x0a, 0xc7, 0xb6, 0x60, 0x40, 0x4e, 0x61,
  35221. 0x3a, 0xa1, 0xf9, 0x80, 0x38, 0x0c, 0xb3, 0x6d,
  35222. 0xba, 0x18, 0xd2, 0x32, 0x56, 0xc7, 0x26, 0x7a,
  35223. 0x00, 0xa6, 0x7b, 0xa6, 0xc2, 0xa2, 0xb1, 0x4c,
  35224. 0x41, 0x42, 0x39, 0x66, 0x2f, 0x68, 0xbd, 0x44,
  35225. 0x6c, 0x8e, 0xfd, 0xf3, 0x66, 0x56, 0xa0, 0x89,
  35226. 0x1a, 0x3c, 0xc6, 0x23, 0xfc, 0x68, 0xb6, 0x57,
  35227. 0x2f, 0x7b, 0x29, 0xa6, 0xde, 0x12, 0x80, 0x14,
  35228. 0x41, 0x1e, 0xe4, 0x19, 0x06, 0xd0, 0x80, 0x71,
  35229. 0xf9, 0x48, 0x56, 0xe3, 0x6a, 0x83, 0x2b, 0x40,
  35230. 0x33, 0x8d, 0x74, 0x35, 0x16, 0x65, 0x9b, 0xd2,
  35231. 0x58, 0x79, 0xc0, 0x07, 0xa5, 0x2b, 0xc9, 0x58,
  35232. 0x6f, 0x79, 0x87, 0x6a, 0xfa, 0xc6, 0xc9, 0xa3,
  35233. 0x0d, 0x8f, 0xac, 0x24, 0x3b, 0xd2, 0x24, 0x25,
  35234. 0xd6, 0xad, 0xce, 0x42, 0xab, 0x7e, 0xd3, 0x90,
  35235. 0x14, 0x75, 0x7a, 0x95, 0x8b, 0xc8, 0xa7, 0x45,
  35236. 0x65, 0xf0, 0x19, 0x23, 0x4f, 0xf0, 0x4b, 0x34,
  35237. 0x89, 0x3e, 0xd6, 0xd0, 0x55, 0x01, 0xc3, 0x72,
  35238. 0x55, 0x23, 0x9a, 0xae, 0x2a, 0xc1, 0x9f, 0x8c,
  35239. 0x75, 0xac, 0x59, 0x00, 0xda, 0xe8, 0x30, 0x0d,
  35240. 0xbb, 0xa7, 0x10, 0xdc, 0x2c, 0xaa, 0xe1, 0xbc,
  35241. 0xa3, 0xa3, 0x8c, 0x58, 0x34, 0x2b, 0x28, 0x6b,
  35242. 0x85, 0x18, 0xf1, 0x36, 0xad, 0x15, 0xb9, 0xf7,
  35243. 0xbc, 0xbb, 0x06, 0xa5, 0x60, 0x7d, 0xb3, 0x75,
  35244. 0xdb, 0xe9, 0x76, 0x45, 0x7c, 0x26, 0xc6, 0x59,
  35245. 0x82, 0x57, 0x53, 0x1b, 0x2c, 0xfb, 0x6e, 0xe7,
  35246. 0xf5, 0x15, 0x91, 0x84, 0x08, 0x04, 0xc3, 0x83,
  35247. 0x88, 0x37, 0x6c, 0x27, 0x14, 0x84, 0x13, 0xda,
  35248. 0x9e, 0x92, 0x92, 0x0b, 0xfd, 0x9a, 0x06, 0x9e,
  35249. 0x01, 0x8b, 0xd2, 0x72, 0x05, 0x3d, 0xa8, 0x77,
  35250. 0x5c, 0x0b, 0x73, 0x9f, 0x76, 0x1d, 0xb2, 0x10,
  35251. 0x7c, 0xf3, 0x5a, 0x43, 0x4d, 0x69, 0xb0, 0x7e,
  35252. 0x5b, 0xcd, 0xb8, 0x74, 0x34, 0x13, 0x8b, 0x0c,
  35253. 0xb5, 0x56, 0x76, 0x1b, 0xa5, 0x22, 0xa5, 0x74,
  35254. 0x7b, 0x28, 0x74, 0x7d, 0x80, 0xeb, 0x9d, 0x6c,
  35255. 0xc6, 0x73, 0xbe, 0xe5, 0x76, 0x93, 0x77, 0xb9,
  35256. 0x96, 0xd3, 0x6c, 0xeb, 0x0c, 0x0c, 0x7e, 0xd9,
  35257. 0xa6, 0x58, 0x53, 0x33, 0x24, 0x86, 0x9c, 0x18,
  35258. 0xa1, 0xa3, 0x6f, 0x31, 0x47, 0x0f, 0x14, 0xc5,
  35259. 0xae, 0x49, 0xab, 0x07, 0x05, 0x07, 0xf8, 0x24,
  35260. 0x9c, 0xe4, 0x04, 0xb4, 0x9c, 0x0a, 0x8c, 0x3e,
  35261. 0xe4, 0x2f, 0xea, 0x96, 0x31, 0xfa, 0x1a, 0x0d,
  35262. 0x10, 0xd8, 0x6b, 0x93, 0xf9, 0x86, 0xe0, 0xe3,
  35263. 0xa8, 0x2e, 0x70, 0x3b, 0x74, 0xe5, 0xae, 0x61,
  35264. 0x01, 0x24, 0x24, 0x21, 0xa8, 0x9a, 0xa0, 0x7f,
  35265. 0xe6, 0x85, 0x88, 0x46, 0x0b, 0xaa, 0x36, 0x87,
  35266. 0x86, 0x48, 0x6a, 0x72, 0xe4, 0xf2, 0x4d, 0x2d,
  35267. 0xd7, 0x6c, 0xfc, 0x03, 0xb6, 0x94, 0xa5, 0xba,
  35268. 0x91, 0xa7, 0x55, 0xa0, 0xb9, 0x8f, 0x3b, 0xf9,
  35269. 0x33, 0x07, 0xc0, 0xab, 0x64, 0x63, 0x9a, 0xea,
  35270. 0x7a, 0x64, 0x98, 0xa3, 0xc3, 0xdd, 0xc5, 0x71,
  35271. 0x14, 0x1a, 0xbc, 0xa4, 0x67, 0x8c, 0xd2, 0xe2,
  35272. 0xb8, 0x57, 0xfb, 0x88, 0xf6, 0x00, 0xca, 0xa5,
  35273. 0x96, 0xb4, 0x4b, 0xc4, 0x22, 0x25, 0x0b, 0x28,
  35274. 0x19, 0xe0, 0x51, 0x5f, 0x04, 0x72, 0x39, 0x18,
  35275. 0x53, 0x70, 0x0b, 0x01, 0xef, 0xf9, 0x45, 0x3f,
  35276. 0xd1, 0x18, 0x76, 0xb7, 0xc7, 0x59, 0xa0, 0x7d,
  35277. 0xd8, 0x45, 0xca, 0xba, 0x45, 0x55, 0x26, 0x4a,
  35278. 0x82, 0x76, 0x51, 0x93, 0xfd, 0xf8, 0x1b, 0x62,
  35279. 0x0a, 0x1e, 0x1f, 0x92, 0x3f, 0xb2, 0x44, 0x42,
  35280. 0xcd, 0x1c, 0xbe, 0x94, 0x17, 0x50, 0x03, 0xec,
  35281. 0x06, 0xce, 0x77, 0xa3, 0xc6, 0x44, 0x93, 0xc1,
  35282. 0x99, 0x98, 0x7a, 0x30, 0x0c, 0x95, 0xc5, 0x3c,
  35283. 0x00, 0x89, 0xb5, 0xd6, 0x5c, 0x92, 0xea, 0x97,
  35284. 0x1b, 0x2f, 0xfa, 0x93, 0xb5, 0x2a, 0x46, 0x1e,
  35285. 0xa2, 0xac, 0x8c, 0x19, 0x9c, 0x2f, 0x4c, 0x2b,
  35286. 0x70, 0x42, 0x97, 0xce, 0x3c, 0x39, 0x49, 0xe0,
  35287. 0x73, 0x5e, 0xa8, 0xa1, 0x4a, 0xa5, 0x9e, 0x8d,
  35288. 0xec, 0x0c, 0x87, 0x83, 0x99, 0xff, 0x70, 0x74,
  35289. 0x7a, 0xb2, 0x44, 0xce, 0x46, 0xb5, 0xf2, 0x23,
  35290. 0x04, 0x73, 0x32, 0x3d, 0x25, 0xc6, 0x6f, 0xe6,
  35291. 0xb4, 0x19, 0xb1, 0xf4, 0xa1, 0x12, 0xe5, 0x21,
  35292. 0x40, 0x35, 0x25, 0x6b, 0xc4, 0x3f, 0xfd, 0x2b,
  35293. 0x6b, 0x7b, 0x37, 0x87, 0x69, 0xa6, 0xb4, 0x70,
  35294. 0x00, 0xbf, 0xb6, 0x35, 0x7d, 0x45, 0x81, 0x4b,
  35295. 0xae, 0xf3, 0x85, 0x7d, 0x37, 0x9e, 0x2f, 0xb8,
  35296. 0xb5, 0xe5, 0x20, 0x1a, 0xb2, 0x62, 0x74, 0xbb,
  35297. 0x1b, 0x70, 0xad, 0x32, 0x2c, 0xd0, 0x43, 0x9b,
  35298. 0x2d, 0xb1, 0x09, 0xcf, 0xf0, 0xa2, 0xf8, 0xe6,
  35299. 0x00, 0x99, 0x55, 0x71, 0xff, 0xc3, 0x8c, 0x59,
  35300. 0x0b, 0xc4, 0xc7, 0x61, 0x5c, 0x69, 0xd0, 0xc9,
  35301. 0x8e, 0xf4, 0x30, 0xf3, 0x08, 0x61, 0xa7, 0x72,
  35302. 0x38, 0xff, 0xc0, 0x70, 0x61, 0xe4, 0x75, 0xd6,
  35303. 0xa3, 0x0a, 0xd1, 0xb4, 0x7f, 0xd0, 0x39, 0xc3,
  35304. 0xa4, 0x47, 0x76, 0x2d, 0xb2, 0x21, 0x1d, 0xc3,
  35305. 0x1d, 0x0a, 0xca, 0xcf, 0xd5, 0x58, 0x90, 0xa5,
  35306. 0x82, 0x47, 0x98, 0xf9, 0xae, 0xad, 0x74, 0x13,
  35307. 0xdf, 0xe0, 0x28, 0xb1, 0x01, 0x2b, 0xe8, 0xb6,
  35308. 0xca, 0x10, 0x26, 0x66, 0x6a, 0xc6, 0xbc, 0x94,
  35309. 0x40, 0xa4, 0x49, 0xb5, 0x1a, 0xd8, 0xbb, 0xa7,
  35310. 0xb0, 0x92, 0x1d, 0xd4, 0xd8, 0xb4, 0xa5, 0x78,
  35311. 0x13, 0x6d, 0x1a, 0x05, 0xdb, 0x38, 0xcc, 0x85,
  35312. 0x84, 0x37, 0xb2, 0x51, 0x61, 0xd1, 0xc3, 0xc2,
  35313. 0x8e, 0xe0, 0x7b, 0xbc, 0xf2, 0xb2, 0x49, 0x11,
  35314. 0x0d, 0x22, 0x78, 0x1d, 0xc3, 0x05, 0x0d, 0x8c,
  35315. 0xc0, 0x09, 0x00, 0x96, 0xb3, 0x8a, 0x85, 0x06,
  35316. 0x96, 0xf8, 0x6e, 0x9e, 0x6b, 0xab, 0x32, 0x52,
  35317. 0x71, 0xb2, 0x24, 0x86, 0x75, 0x01, 0x19, 0x68,
  35318. 0x50, 0x28, 0x81, 0x09, 0x04, 0x97, 0xfa, 0xc0,
  35319. 0xaf, 0x84, 0x3c, 0x1a, 0xea, 0x76, 0xdd, 0x81,
  35320. 0xcf, 0x29, 0xc0, 0x12, 0xc6, 0x62, 0x27, 0xb7,
  35321. 0xf0, 0x6d, 0x99, 0x61, 0x30, 0x9b, 0x02, 0x62,
  35322. 0xf7, 0x32, 0xc9, 0xa4, 0xd0, 0xbb, 0xd0, 0x67,
  35323. 0x27, 0xab, 0xb8, 0x37, 0x1f, 0xf2, 0xc1, 0x18,
  35324. 0x99, 0xa0, 0x98, 0x37, 0x5c, 0x46, 0x05, 0x16,
  35325. 0xb2, 0xcc, 0x88, 0xbc, 0xf6, 0x28, 0xed, 0xe3,
  35326. 0x7d, 0x8f, 0x3b, 0x33, 0x42, 0xe4, 0x49, 0x0a,
  35327. 0x85, 0x60, 0x6e, 0xc0, 0x3d, 0xa2, 0x9b, 0x02,
  35328. 0x56, 0x27, 0x53, 0x82, 0xa3, 0x31, 0x3d, 0xc0,
  35329. 0x41, 0x11, 0x48, 0x01, 0x03, 0x2c, 0x51, 0x9f,
  35330. 0x35, 0x0c, 0x3e, 0x6a, 0xba, 0xc3, 0xe3, 0x3b,
  35331. 0x93, 0xb4, 0xa1, 0x9f, 0x7c, 0x54, 0x66, 0xe5,
  35332. 0x8c, 0xb1, 0xdc, 0x14, 0xb4, 0xa9, 0x6c, 0x47,
  35333. 0x57, 0x29, 0xf9, 0x71, 0xbd, 0xf1, 0x73, 0xcd,
  35334. 0xf3, 0x54, 0x82, 0x4d, 0x01, 0x94, 0x27, 0xf9,
  35335. 0x5b, 0x3b, 0x4a, 0x4a, 0x4a, 0x95, 0x8e, 0x47,
  35336. 0x6a, 0x6e, 0x69, 0x91, 0xce, 0x6f, 0x06, 0xcb,
  35337. 0x5d, 0xfc, 0xa7, 0xd4, 0x38, 0x0c, 0x3d, 0x92,
  35338. 0x0b, 0x57, 0x11, 0xac, 0x1f, 0xcb, 0xaf, 0x4b,
  35339. 0x9a, 0xc8, 0x00, 0xb9, 0x76, 0xd1, 0xec, 0x76,
  35340. 0x6a, 0x62, 0x6c, 0xc1, 0x90, 0x0b, 0x66, 0xb3,
  35341. 0xa9, 0xdc, 0x62, 0xc5, 0xc1, 0x44, 0x52, 0x7a,
  35342. 0x29, 0x6b, 0xaf, 0x70, 0x43, 0x3b, 0xf6, 0x57,
  35343. 0xc0, 0x43, 0x7f, 0x87, 0x59, 0x7b, 0xd7, 0xc8,
  35344. 0xbb, 0xbe, 0x9a, 0xbc, 0x37, 0x05, 0x09, 0x31,
  35345. 0xa4, 0xa8, 0x69, 0x82, 0xa2, 0x02, 0x8a, 0x74,
  35346. 0x45, 0x4c, 0x9b, 0x81, 0x0c, 0x88, 0xd1, 0x70,
  35347. 0x1c, 0x8c, 0xc9, 0x8a, 0x1d, 0x4c, 0xa1, 0x07,
  35348. 0xa6, 0xb2, 0x5e, 0x96, 0x2f, 0xe4, 0xb6, 0xb0,
  35349. 0x3c, 0x95, 0x45, 0x32, 0x60, 0xb8, 0x07, 0x22,
  35350. 0x86, 0x37, 0xcc, 0x9e, 0xb1, 0x2a, 0xcc, 0x09,
  35351. 0x54, 0x95, 0x9a, 0x52, 0xae, 0x54, 0xd1, 0x97,
  35352. 0x73, 0x00, 0xab, 0xa0, 0xba, 0x2c, 0x14, 0x60,
  35353. 0x9b, 0xb2, 0x8c, 0x11, 0xd5, 0xfa, 0xc5, 0xca,
  35354. 0xc8, 0x82, 0x97, 0x60, 0x32, 0x83, 0xe8, 0x67,
  35355. 0xa3, 0x64, 0x83, 0x66, 0xc7, 0x24, 0xd9, 0x35,
  35356. 0x4c, 0xd7, 0xa1, 0x96, 0xdb, 0xd9, 0x80, 0x2f,
  35357. 0x7b, 0x88, 0xd3, 0xfa, 0x00, 0x1f, 0x9c, 0x97,
  35358. 0x73, 0x22, 0x54, 0x62, 0x23, 0x5e, 0x91, 0x35,
  35359. 0x2a, 0x20, 0x79, 0x1f, 0xd8, 0xb8, 0x7f, 0xe3,
  35360. 0x37, 0x7e, 0xc6, 0xa3, 0x94, 0x0b, 0x11, 0x30,
  35361. 0xa0, 0xbb, 0x04, 0xe7, 0x41, 0x0a, 0x34, 0xe2,
  35362. 0x58, 0x0d, 0x07, 0x1d, 0x6c, 0x56, 0x20, 0x20,
  35363. 0x86, 0x78, 0x7a, 0x65, 0x90, 0xf8, 0x43, 0x93,
  35364. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35365. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35366. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35367. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35368. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35369. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35370. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35371. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35372. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35373. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35374. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35375. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35376. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35377. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35378. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35379. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35380. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35381. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35382. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35383. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35384. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35385. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35386. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35387. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35388. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35389. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35390. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35391. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35392. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35393. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35394. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35395. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35396. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35397. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35398. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35399. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35400. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35401. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35402. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35403. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35404. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35405. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35406. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35407. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35408. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35409. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35410. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35411. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35412. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35413. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35414. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35415. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35416. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35417. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35418. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35419. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35420. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35421. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35422. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35423. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35424. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35425. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35426. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35427. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35428. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35429. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35430. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35431. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35432. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35433. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35434. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35435. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35436. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35437. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35438. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35439. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35440. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35441. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35442. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35443. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35444. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35445. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35446. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35447. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35448. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35449. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35450. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35451. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35452. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35453. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35454. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35455. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35456. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35457. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35458. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35459. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35460. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35461. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35462. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35463. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35464. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35465. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35466. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35467. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35468. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35469. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35470. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35471. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35472. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35473. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35474. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35475. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35476. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35477. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35478. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35479. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35480. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35481. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35482. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35483. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35484. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35485. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35486. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35487. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35488. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35489. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35490. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35491. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35492. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35493. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35494. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35495. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35496. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35497. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35498. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35499. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35500. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35501. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35502. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35503. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35504. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35505. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35506. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35507. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35508. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35509. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35510. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35511. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28,
  35512. 0xf5, 0x72, 0x62, 0x66, 0x13, 0x58, 0xcd, 0xe8,
  35513. 0xd3, 0xeb, 0xf9, 0x90, 0xe5, 0xfd, 0x1d, 0x5b,
  35514. 0x89, 0x6c, 0x99, 0x2c, 0xcf, 0xaa, 0xdb, 0x52,
  35515. 0x56, 0xb6, 0x8b, 0xbf, 0x59, 0x43, 0xb1, 0x32,
  35516. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  35517. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  35518. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  35519. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  35520. #endif
  35521. };
  35522. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ct[] = {
  35523. #ifdef WOLFSSL_KYBER_ORIGINAL
  35524. 0xB5, 0x2C, 0x56, 0xB9, 0x2A, 0x4B, 0x7C, 0xE9,
  35525. 0xE4, 0xCB, 0x7C, 0x5B, 0x1B, 0x16, 0x31, 0x67,
  35526. 0xA8, 0xA1, 0x67, 0x5B, 0x2F, 0xDE, 0xF8, 0x4A,
  35527. 0x5B, 0x67, 0xCA, 0x15, 0xDB, 0x69, 0x4C, 0x9F,
  35528. 0x11, 0xBD, 0x02, 0x7C, 0x30, 0xAE, 0x22, 0xEC,
  35529. 0x92, 0x1A, 0x1D, 0x91, 0x15, 0x99, 0xAF, 0x05,
  35530. 0x85, 0xE4, 0x8D, 0x20, 0xDA, 0x70, 0xDF, 0x9F,
  35531. 0x39, 0xE3, 0x2E, 0xF9, 0x5D, 0x4C, 0x8F, 0x44,
  35532. 0xBF, 0xEF, 0xDA, 0xA5, 0xDA, 0x64, 0xF1, 0x05,
  35533. 0x46, 0x31, 0xD0, 0x4D, 0x6D, 0x3C, 0xFD, 0x0A,
  35534. 0x54, 0x0D, 0xD7, 0xBA, 0x38, 0x86, 0xE4, 0xB5,
  35535. 0xF1, 0x3E, 0x87, 0x87, 0x88, 0x60, 0x4C, 0x95,
  35536. 0xC0, 0x96, 0xEA, 0xB3, 0x91, 0x9F, 0x42, 0x75,
  35537. 0x21, 0x41, 0x9A, 0x94, 0x6C, 0x26, 0xCC, 0x04,
  35538. 0x14, 0x75, 0xD7, 0x12, 0x4C, 0xDC, 0x01, 0xD0,
  35539. 0x37, 0x3E, 0x5B, 0x09, 0xC7, 0xA7, 0x06, 0x03,
  35540. 0xCF, 0xDB, 0x4F, 0xB3, 0x40, 0x50, 0x23, 0xF2,
  35541. 0x26, 0x4D, 0xC3, 0xF9, 0x83, 0xC4, 0xFC, 0x02,
  35542. 0xA2, 0xD1, 0xB2, 0x68, 0xF2, 0x20, 0x8A, 0x1F,
  35543. 0x6E, 0x2A, 0x62, 0x09, 0xBF, 0xF1, 0x2F, 0x6F,
  35544. 0x46, 0x5F, 0x0B, 0x06, 0x9C, 0x3A, 0x7F, 0x84,
  35545. 0xF6, 0x06, 0xD8, 0xA9, 0x40, 0x64, 0x00, 0x3D,
  35546. 0x6E, 0xC1, 0x14, 0xC8, 0xE8, 0x08, 0xD3, 0x05,
  35547. 0x38, 0x84, 0xC1, 0xD5, 0xA1, 0x42, 0xFB, 0xF2,
  35548. 0x01, 0x12, 0xEB, 0x36, 0x0F, 0xDA, 0x3F, 0x0F,
  35549. 0x28, 0xB1, 0x72, 0xAE, 0x50, 0xF5, 0xE7, 0xD8,
  35550. 0x38, 0x01, 0xFB, 0x3F, 0x00, 0x64, 0xB6, 0x87,
  35551. 0x18, 0x70, 0x74, 0xBD, 0x7F, 0xE3, 0x0E, 0xDD,
  35552. 0xAA, 0x33, 0x4C, 0xF8, 0xFC, 0x04, 0xFA, 0x8C,
  35553. 0xED, 0x89, 0x9C, 0xEA, 0xDE, 0x4B, 0x4F, 0x28,
  35554. 0xB6, 0x83, 0x72, 0xBA, 0xF9, 0x8F, 0xF4, 0x82,
  35555. 0xA4, 0x15, 0xB7, 0x31, 0x15, 0x5B, 0x75, 0xCE,
  35556. 0xB9, 0x76, 0xBE, 0x0E, 0xA0, 0x28, 0x5B, 0xA0,
  35557. 0x1A, 0x27, 0xF1, 0x85, 0x7A, 0x8F, 0xB3, 0x77,
  35558. 0xA3, 0xAE, 0x0C, 0x23, 0xB2, 0xAA, 0x9A, 0x07,
  35559. 0x9B, 0xFA, 0xBF, 0xF0, 0xD5, 0xB2, 0xF1, 0xCD,
  35560. 0x9B, 0x71, 0x8B, 0xEA, 0x03, 0xC4, 0x2F, 0x34,
  35561. 0x3A, 0x39, 0xB4, 0xF1, 0x42, 0xD0, 0x1A, 0xD8,
  35562. 0xAC, 0xBB, 0x50, 0xE3, 0x88, 0x53, 0xCF, 0x9A,
  35563. 0x50, 0xC8, 0xB4, 0x4C, 0x3C, 0xF6, 0x71, 0xA4,
  35564. 0xA9, 0x04, 0x3B, 0x26, 0xDD, 0xBB, 0x24, 0x95,
  35565. 0x9A, 0xD6, 0x71, 0x5C, 0x08, 0x52, 0x18, 0x55,
  35566. 0xC7, 0x9A, 0x23, 0xB9, 0xC3, 0xD6, 0x47, 0x17,
  35567. 0x49, 0xC4, 0x07, 0x25, 0xBD, 0xD5, 0xC2, 0x77,
  35568. 0x6D, 0x43, 0xAE, 0xD2, 0x02, 0x04, 0xBA, 0xA1,
  35569. 0x41, 0xEF, 0xB3, 0x30, 0x49, 0x17, 0x47, 0x4B,
  35570. 0x7F, 0x9F, 0x7A, 0x4B, 0x08, 0xB1, 0xA9, 0x3D,
  35571. 0xAE, 0xD9, 0x8C, 0x67, 0x49, 0x53, 0x59, 0xD3,
  35572. 0x7D, 0x67, 0xF7, 0x43, 0x8B, 0xEE, 0x5E, 0x43,
  35573. 0x58, 0x56, 0x34, 0xB2, 0x6C, 0x6B, 0x38, 0x10,
  35574. 0xD7, 0xCD, 0xCB, 0xC0, 0xF6, 0xEB, 0x87, 0x7A,
  35575. 0x60, 0x87, 0xE6, 0x8A, 0xCB, 0x84, 0x80, 0xD3,
  35576. 0xA8, 0xCF, 0x69, 0x00, 0x44, 0x7E, 0x49, 0xB4,
  35577. 0x17, 0xF1, 0x5A, 0x53, 0xB6, 0x07, 0xA0, 0xE2,
  35578. 0x16, 0xB8, 0x55, 0x97, 0x0D, 0x37, 0x40, 0x68,
  35579. 0x70, 0xB4, 0x56, 0x87, 0x22, 0xDA, 0x77, 0xA4,
  35580. 0x08, 0x47, 0x03, 0x81, 0x67, 0x84, 0xE2, 0xF1,
  35581. 0x6B, 0xED, 0x18, 0x99, 0x65, 0x32, 0xC5, 0xD8,
  35582. 0xB7, 0xF5, 0xD2, 0x14, 0x46, 0x4E, 0x5F, 0x3F,
  35583. 0x6E, 0x90, 0x58, 0x67, 0xB0, 0xCE, 0x11, 0x9E,
  35584. 0x25, 0x2A, 0x66, 0x71, 0x32, 0x53, 0x54, 0x46,
  35585. 0x85, 0xD2, 0x08, 0xE1, 0x72, 0x39, 0x08, 0xA0,
  35586. 0xCE, 0x97, 0x83, 0x46, 0x52, 0xE0, 0x8A, 0xE7,
  35587. 0xBD, 0xC8, 0x81, 0xA1, 0x31, 0xB7, 0x3C, 0x71,
  35588. 0xE8, 0x4D, 0x20, 0xD6, 0x8F, 0xDE, 0xFF, 0x4F,
  35589. 0x5D, 0x70, 0xCD, 0x1A, 0xF5, 0x7B, 0x78, 0xE3,
  35590. 0x49, 0x1A, 0x98, 0x65, 0x94, 0x23, 0x21, 0x80,
  35591. 0x0A, 0x20, 0x3C, 0x05, 0xED, 0x1F, 0xEE, 0xB5,
  35592. 0xA2, 0x8E, 0x58, 0x4E, 0x19, 0xF6, 0x53, 0x5E,
  35593. 0x7F, 0x84, 0xE4, 0xA2, 0x4F, 0x84, 0xA7, 0x2D,
  35594. 0xCA, 0xF5, 0x64, 0x8B, 0x4A, 0x42, 0x35, 0xDD,
  35595. 0x66, 0x44, 0x64, 0x48, 0x2F, 0x03, 0x17, 0x6E,
  35596. 0x88, 0x8C, 0x28, 0xBF, 0xC6, 0xC1, 0xCB, 0x23,
  35597. 0x8C, 0xFF, 0xA3, 0x5A, 0x32, 0x1E, 0x71, 0x79,
  35598. 0x1D, 0x9E, 0xA8, 0xED, 0x08, 0x78, 0xC6, 0x11,
  35599. 0x21, 0xBF, 0x8D, 0x2A, 0x4A, 0xB2, 0xC1, 0xA5,
  35600. 0xE1, 0x20, 0xBC, 0x40, 0xAB, 0xB1, 0x89, 0x2D,
  35601. 0x17, 0x15, 0x09, 0x0A, 0x0E, 0xE4, 0x82, 0x52,
  35602. 0xCA, 0x29, 0x7A, 0x99, 0xAA, 0x0E, 0x51, 0x0C,
  35603. 0xF2, 0x6B, 0x1A, 0xDD, 0x06, 0xCA, 0x54, 0x3E,
  35604. 0x1C, 0x5D, 0x6B, 0xDC, 0xD3, 0xB9, 0xC5, 0x85,
  35605. 0xC8, 0x53, 0x80, 0x45, 0xDB, 0x5C, 0x25, 0x2E,
  35606. 0xC3, 0xC8, 0xC3, 0xC9, 0x54, 0xD9, 0xBE, 0x59,
  35607. 0x07, 0x09, 0x4A, 0x89, 0x4E, 0x60, 0xEA, 0xB4,
  35608. 0x35, 0x38, 0xCF, 0xEE, 0x82, 0xE8, 0xFF, 0xC0,
  35609. 0x79, 0x1B, 0x0D, 0x0F, 0x43, 0xAC, 0x16, 0x27,
  35610. 0x83, 0x0A, 0x61, 0xD5, 0x6D, 0xAD, 0x96, 0xC6,
  35611. 0x29, 0x58, 0xB0, 0xDE, 0x78, 0x0B, 0x78, 0xBD,
  35612. 0x47, 0xA6, 0x04, 0x55, 0x0D, 0xAB, 0x83, 0xFF,
  35613. 0xF2, 0x27, 0xC3, 0x24, 0x04, 0x94, 0x71, 0xF3,
  35614. 0x52, 0x48, 0xCF, 0xB8, 0x49, 0xB2, 0x57, 0x24,
  35615. 0xFF, 0x70, 0x4D, 0x52, 0x77, 0xAA, 0x35, 0x2D,
  35616. 0x55, 0x09, 0x58, 0xBE, 0x3B, 0x23, 0x7D, 0xFF,
  35617. 0x47, 0x3E, 0xC2, 0xAD, 0xBA, 0xEA, 0x48, 0xCA,
  35618. 0x26, 0x58, 0xAE, 0xFC, 0xC7, 0x7B, 0xBD, 0x42,
  35619. 0x64, 0xAB, 0x37, 0x4D, 0x70, 0xEA, 0xE5, 0xB9,
  35620. 0x64, 0x41, 0x6C, 0xE8, 0x22, 0x6A, 0x7E, 0x32,
  35621. 0x55, 0xA0, 0xF8, 0xD7, 0xE2, 0xAD, 0xCA, 0x06,
  35622. 0x2B, 0xCD, 0x6D, 0x78, 0xD6, 0x0D, 0x1B, 0x32,
  35623. 0xE1, 0x14, 0x05, 0xBE, 0x54, 0xB6, 0x6E, 0xF0,
  35624. 0xFD, 0xDD, 0x56, 0x77, 0x02, 0xA3, 0xBC, 0xCF,
  35625. 0xED, 0xE3, 0xC5, 0x84, 0x70, 0x12, 0x69, 0xED,
  35626. 0x14, 0x80, 0x9F, 0x06, 0xF8, 0x96, 0x83, 0x56,
  35627. 0xBB, 0x92, 0x67, 0xFE, 0x86, 0xE5, 0x14, 0x25,
  35628. 0x2E, 0x88, 0xBB, 0x5C, 0x30, 0xA7, 0xEC, 0xB3,
  35629. 0xD0, 0xE6, 0x21, 0x02, 0x1E, 0xE0, 0xFB, 0xF7,
  35630. 0x87, 0x1B, 0x09, 0x34, 0x2B, 0xF8, 0x4F, 0x55,
  35631. 0xC9, 0x7E, 0xAF, 0x86, 0xC4, 0x81, 0x89, 0xC7,
  35632. 0xFF, 0x4D, 0xF3, 0x89, 0xF0, 0x77, 0xE2, 0x80,
  35633. 0x6E, 0x5F, 0xA7, 0x3B, 0x3E, 0x94, 0x58, 0xA1,
  35634. 0x6C, 0x7E, 0x27, 0x5F, 0x4F, 0x60, 0x22, 0x75,
  35635. 0x58, 0x0E, 0xB7, 0xB7, 0x13, 0x5F, 0xB5, 0x37,
  35636. 0xFA, 0x0C, 0xD9, 0x5D, 0x6E, 0xA5, 0x8C, 0x10,
  35637. 0x8C, 0xD8, 0x94, 0x3D, 0x70, 0xC1, 0x64, 0x31,
  35638. 0x11, 0xF4, 0xF0, 0x1C, 0xA8, 0xA8, 0x27, 0x6A,
  35639. 0x90, 0x26, 0x66, 0xED, 0x81, 0xB7, 0x8D, 0x16,
  35640. 0x8B, 0x00, 0x6F, 0x16, 0xAA, 0xA3, 0xD8, 0xE4,
  35641. 0xCE, 0x4F, 0x4D, 0x0F, 0xB0, 0x99, 0x7E, 0x41,
  35642. 0xAE, 0xFF, 0xB5, 0xB3, 0xDA, 0xA8, 0x38, 0x73,
  35643. 0x2F, 0x35, 0x73, 0x49, 0x44, 0x7F, 0x38, 0x77,
  35644. 0x76, 0xC7, 0x93, 0xC0, 0x47, 0x9D, 0xE9, 0xE9,
  35645. 0x94, 0x98, 0xCC, 0x35, 0x6F, 0xDB, 0x00, 0x75,
  35646. 0xA7, 0x03, 0xF2, 0x3C, 0x55, 0xD4, 0x7B, 0x55,
  35647. 0x0E, 0xC8, 0x9B, 0x02, 0xAD, 0xE8, 0x93, 0x29,
  35648. 0x08, 0x6A, 0x50, 0x84, 0x34, 0x56, 0xFE, 0xDC,
  35649. 0x37, 0x88, 0xAC, 0x8D, 0x97, 0x23, 0x3C, 0x54,
  35650. 0x56, 0x04, 0x67, 0xEE, 0x1D, 0x0F, 0x02, 0x4B,
  35651. 0x18, 0x42, 0x8F, 0x0D, 0x73, 0xB3, 0x0E, 0x19,
  35652. 0xF5, 0xC6, 0x3B, 0x9A, 0xBF, 0x11, 0x41, 0x5B,
  35653. 0xEA, 0x4D, 0x01, 0x70, 0x13, 0x0B, 0xAA, 0xBD,
  35654. 0x33, 0xC0, 0x5E, 0x65, 0x24, 0xE5, 0xFB, 0x55,
  35655. 0x81, 0xB2, 0x2B, 0x04, 0x33, 0x34, 0x22, 0x48,
  35656. 0x26, 0x6D, 0x0F, 0x10, 0x53, 0xB2, 0x45, 0xCC,
  35657. 0x24, 0x62, 0xDC, 0x44, 0xD3, 0x49, 0x65, 0x10,
  35658. 0x24, 0x82, 0xA8, 0xED, 0x9E, 0x4E, 0x96, 0x4D,
  35659. 0x56, 0x83, 0xE5, 0xD4, 0x5D, 0x0C, 0x82, 0x69
  35660. #else
  35661. 0xc8, 0x39, 0x10, 0x85, 0xb8, 0xd3, 0xea, 0x97,
  35662. 0x94, 0x21, 0x25, 0x41, 0xb2, 0x91, 0x4f, 0x08,
  35663. 0x96, 0x4d, 0x33, 0x52, 0x1d, 0x3f, 0x67, 0xad,
  35664. 0x66, 0x09, 0x6e, 0xbf, 0xb1, 0xf7, 0x06, 0x42,
  35665. 0x4b, 0x49, 0x55, 0x8f, 0x75, 0x5b, 0x56, 0x25,
  35666. 0xba, 0xe2, 0x36, 0xf2, 0xe0, 0x07, 0x96, 0x01,
  35667. 0xc7, 0x66, 0xf7, 0xd9, 0x60, 0x80, 0x8f, 0x7e,
  35668. 0x2b, 0xb0, 0xc7, 0xa5, 0xe0, 0x66, 0xed, 0x34,
  35669. 0x6d, 0xe6, 0x28, 0xf8, 0xc5, 0x7e, 0xeb, 0xab,
  35670. 0xbb, 0x0c, 0x22, 0xd9, 0x11, 0x54, 0x84, 0x63,
  35671. 0x69, 0x3e, 0xf3, 0xce, 0x52, 0xa5, 0x3f, 0x7f,
  35672. 0xf4, 0x15, 0xf0, 0x0e, 0x65, 0x7a, 0xe1, 0xc5,
  35673. 0xa4, 0x8f, 0xa5, 0xec, 0x6e, 0x4b, 0xe5, 0xcf,
  35674. 0x46, 0x2d, 0xaf, 0xfc, 0x84, 0xd2, 0xf6, 0xd5,
  35675. 0xff, 0x55, 0xdc, 0x9b, 0xbe, 0x8b, 0xb0, 0xd7,
  35676. 0x25, 0xec, 0x64, 0xfd, 0x4c, 0xd4, 0xbd, 0x8d,
  35677. 0xba, 0x0a, 0x84, 0x4e, 0x8b, 0x5c, 0xe4, 0xb6,
  35678. 0xa2, 0x89, 0x34, 0xd7, 0xf7, 0xa0, 0x50, 0x99,
  35679. 0x1f, 0xe1, 0x85, 0xb5, 0x06, 0xb4, 0x51, 0xda,
  35680. 0xbf, 0xad, 0x52, 0xd5, 0x2c, 0xb2, 0x11, 0x4c,
  35681. 0xa7, 0xd9, 0xa5, 0xcf, 0x98, 0x6c, 0x8f, 0xdc,
  35682. 0x1b, 0xc1, 0x0e, 0xc0, 0xc1, 0x86, 0x9e, 0x50,
  35683. 0xc0, 0x3c, 0x55, 0xa7, 0x61, 0x92, 0xa1, 0x04,
  35684. 0x9a, 0xca, 0x63, 0x6b, 0xa9, 0x02, 0x0b, 0xda,
  35685. 0xa8, 0xd0, 0xf5, 0x8c, 0x76, 0x3b, 0x0b, 0x89,
  35686. 0x84, 0x5c, 0xa0, 0x6d, 0x4c, 0x4d, 0xdc, 0x21,
  35687. 0x43, 0x3e, 0x16, 0xb9, 0xc6, 0x2e, 0x44, 0x87,
  35688. 0x1f, 0xdb, 0xc0, 0x5b, 0xa2, 0x18, 0xaf, 0x87,
  35689. 0x1f, 0xdd, 0x7d, 0xcf, 0xa4, 0x64, 0xe6, 0x0f,
  35690. 0xaa, 0x52, 0x65, 0x26, 0x4c, 0xe1, 0x39, 0x1b,
  35691. 0xd9, 0xa8, 0xc5, 0xfa, 0xa7, 0x62, 0x6d, 0x5f,
  35692. 0x15, 0x9b, 0x98, 0x05, 0xb9, 0x75, 0x71, 0x0a,
  35693. 0x35, 0x03, 0xa0, 0xb8, 0x58, 0xa1, 0x1c, 0x6a,
  35694. 0x64, 0x7c, 0xc0, 0xe1, 0x9a, 0xc8, 0x8b, 0x1b,
  35695. 0xe9, 0x05, 0x6c, 0x95, 0xb4, 0xd2, 0x08, 0x7d,
  35696. 0x09, 0x51, 0xd1, 0xd2, 0xf4, 0x99, 0x24, 0x91,
  35697. 0x11, 0x7e, 0x63, 0x47, 0x79, 0x4b, 0xa5, 0x45,
  35698. 0x71, 0xec, 0x49, 0xbb, 0xa7, 0x1a, 0xf3, 0x41,
  35699. 0x3d, 0x38, 0xa3, 0x0b, 0xf5, 0x87, 0x22, 0x48,
  35700. 0xd1, 0xf6, 0xd0, 0x7c, 0x86, 0xba, 0xf7, 0x82,
  35701. 0xe7, 0x3d, 0x26, 0x37, 0xf0, 0x43, 0xd3, 0x41,
  35702. 0xa0, 0x09, 0x21, 0x85, 0x7d, 0x8b, 0x21, 0xdd,
  35703. 0xf3, 0xe1, 0xd6, 0x31, 0x00, 0x36, 0xed, 0x27,
  35704. 0xaf, 0x49, 0xe5, 0xde, 0x1b, 0x90, 0x0f, 0xe4,
  35705. 0xde, 0x79, 0x80, 0x8f, 0xf2, 0x9f, 0x95, 0x70,
  35706. 0x85, 0x96, 0x12, 0xb1, 0x5a, 0xdc, 0x01, 0xfb,
  35707. 0xb2, 0x65, 0xb3, 0x05, 0xb1, 0xe3, 0xa1, 0x2a,
  35708. 0xe4, 0x19, 0xda, 0x5b, 0x74, 0x26, 0x1f, 0xa2,
  35709. 0x84, 0xc1, 0x01, 0xda, 0x3d, 0x8d, 0xca, 0x8b,
  35710. 0x2e, 0x45, 0x21, 0xac, 0xa5, 0x71, 0xef, 0x44,
  35711. 0xa0, 0x58, 0xe8, 0x44, 0xff, 0x32, 0xb1, 0x6d,
  35712. 0x5a, 0xae, 0xa0, 0x5f, 0x7f, 0x3a, 0xf8, 0xe2,
  35713. 0xab, 0x16, 0x22, 0x2e, 0x34, 0x76, 0x62, 0xed,
  35714. 0xdf, 0xb8, 0x91, 0xd0, 0xec, 0xc2, 0xa5, 0x5c,
  35715. 0x56, 0x38, 0xf9, 0xdd, 0xe9, 0x2d, 0x9a, 0x3d,
  35716. 0x54, 0x4a, 0x5f, 0x90, 0x1a, 0xc5, 0x01, 0xac,
  35717. 0xd1, 0xea, 0x6a, 0x01, 0x02, 0x01, 0xfc, 0xb1,
  35718. 0x0a, 0xd7, 0x02, 0xc4, 0x25, 0xa9, 0x4b, 0xdf,
  35719. 0x58, 0x90, 0xd5, 0x00, 0xa2, 0xa1, 0x47, 0xee,
  35720. 0xe1, 0xd1, 0xfc, 0xba, 0x8c, 0x3a, 0xbe, 0x7c,
  35721. 0x2d, 0xfe, 0x70, 0xf3, 0x46, 0xf0, 0x33, 0xd8,
  35722. 0x16, 0xa0, 0xb2, 0x79, 0x1b, 0x4f, 0x0b, 0x2d,
  35723. 0x95, 0x6d, 0x9e, 0xe5, 0x97, 0x17, 0x15, 0x39,
  35724. 0x9a, 0x56, 0x88, 0x30, 0x24, 0x95, 0xe2, 0xe0,
  35725. 0x7c, 0x1c, 0x8c, 0x01, 0x52, 0x71, 0x84, 0xbc,
  35726. 0xd0, 0xc2, 0x08, 0xbc, 0x15, 0x9f, 0x2e, 0x13,
  35727. 0x31, 0x8c, 0x0b, 0xb3, 0xdd, 0x24, 0xa6, 0xa7,
  35728. 0xfc, 0x84, 0x9f, 0x83, 0x38, 0x5e, 0xd4, 0xdb,
  35729. 0xa0, 0x7f, 0xe1, 0xd7, 0xbd, 0x56, 0x40, 0xcc,
  35730. 0x9e, 0xd5, 0xcc, 0xfd, 0xd6, 0x87, 0x63, 0xcb,
  35731. 0x0d, 0x0e, 0xdf, 0x61, 0xb2, 0x92, 0x17, 0x7f,
  35732. 0xc1, 0xd2, 0xd3, 0xc1, 0x1d, 0xd0, 0x49, 0x50,
  35733. 0x56, 0xbc, 0xb1, 0x25, 0x58, 0xae, 0xbc, 0xfd,
  35734. 0xde, 0xf9, 0xfe, 0xb4, 0xae, 0xbc, 0x57, 0xaf,
  35735. 0xd9, 0x02, 0x3c, 0x65, 0xcf, 0xe6, 0x5a, 0x24,
  35736. 0xe3, 0x3f, 0x1b, 0x00, 0x11, 0x1e, 0x92, 0xe6,
  35737. 0x3e, 0x01, 0x1e, 0xaf, 0x0b, 0x21, 0x2c, 0xf9,
  35738. 0x57, 0x43, 0xcd, 0x07, 0xf5, 0x18, 0x9e, 0xce,
  35739. 0x1f, 0x20, 0x5b, 0x7f, 0x6f, 0xcb, 0x2e, 0x6b,
  35740. 0x19, 0x61, 0xb5, 0x40, 0x4c, 0xeb, 0xe4, 0x7c,
  35741. 0x8c, 0xd1, 0x3b, 0x85, 0x99, 0xd5, 0xb4, 0x9e,
  35742. 0x6d, 0x87, 0xee, 0xda, 0x36, 0xe9, 0xb8, 0xfc,
  35743. 0x4c, 0x00, 0x63, 0x58, 0x96, 0xaa, 0x2b, 0x75,
  35744. 0x89, 0x6e, 0x33, 0x6d, 0x1b, 0x61, 0x2e, 0xe1,
  35745. 0x3d, 0xb8, 0x11, 0xe1, 0xf0, 0x7e, 0x61, 0x74,
  35746. 0x8d, 0x92, 0x0f, 0x48, 0x65, 0xf3, 0xf1, 0x17,
  35747. 0x41, 0x39, 0x9d, 0xc6, 0x16, 0x2c, 0x91, 0xca,
  35748. 0x16, 0x8a, 0x02, 0x32, 0x9d, 0xff, 0x82, 0x1d,
  35749. 0x58, 0x19, 0x87, 0x12, 0xdd, 0x55, 0x8a, 0xbb,
  35750. 0x09, 0x9b, 0x3a, 0x0b, 0xaf, 0x9d, 0xa1, 0xb7,
  35751. 0x30, 0xb2, 0xaa, 0x73, 0xbc, 0xf5, 0x8d, 0x74,
  35752. 0xf3, 0x57, 0xb0, 0x6f, 0x72, 0x11, 0xc8, 0x04,
  35753. 0xb6, 0xc8, 0xaf, 0x16, 0xff, 0x35, 0x09, 0xfa,
  35754. 0xd1, 0xd3, 0x5b, 0x14, 0xbf, 0xdc, 0xed, 0x7d,
  35755. 0xb8, 0xa6, 0xa2, 0x5c, 0x48, 0xe5, 0x95, 0x64,
  35756. 0x80, 0x72, 0x4d, 0xaa, 0x05, 0x7c, 0xd6, 0x60,
  35757. 0xb6, 0x7e, 0xe3, 0xe4, 0x72, 0x57, 0x41, 0x82,
  35758. 0x67, 0x9d, 0x48, 0x58, 0x38, 0xa6, 0x47, 0x6e,
  35759. 0xac, 0x02, 0x14, 0x10, 0x75, 0xc8, 0x12, 0xaf,
  35760. 0x79, 0x67, 0xba, 0x7c, 0x91, 0x85, 0xcc, 0x2a,
  35761. 0xbd, 0x2a, 0x45, 0x45, 0xb8, 0x0f, 0x3d, 0x31,
  35762. 0x04, 0xd5, 0x8d, 0x65, 0x4a, 0x57, 0x79, 0x2d,
  35763. 0xcf, 0xab, 0xbe, 0x9c, 0x07, 0x15, 0xe8, 0xde,
  35764. 0x2e, 0xf8, 0x1e, 0xf4, 0x04, 0xc8, 0x16, 0x8f,
  35765. 0xd7, 0xa4, 0x3e, 0xfa, 0xb3, 0xd4, 0x48, 0xe6,
  35766. 0x86, 0xa0, 0x88, 0xef, 0xd2, 0x6a, 0x26, 0x15,
  35767. 0x99, 0x48, 0x92, 0x67, 0x23, 0xd7, 0xec, 0xcc,
  35768. 0x39, 0xe3, 0xc1, 0xb7, 0x19, 0xcf, 0x8b, 0xec,
  35769. 0xb7, 0xbe, 0x7e, 0x96, 0x4f, 0x22, 0xcd, 0x8c,
  35770. 0xb1, 0xb7, 0xe2, 0x5e, 0x80, 0x0e, 0xa9, 0x7d,
  35771. 0x60, 0xa6, 0x4c, 0xc0, 0xbb, 0xd9, 0xcb, 0x40,
  35772. 0x7a, 0x3a, 0xb9, 0xf8, 0x8f, 0x5e, 0x29, 0x16,
  35773. 0x9e, 0xea, 0xfd, 0x4e, 0x03, 0x22, 0xfd, 0xe6,
  35774. 0x59, 0x0a, 0xe0, 0x93, 0xce, 0x8f, 0xee, 0xae,
  35775. 0x98, 0xb6, 0x22, 0xca, 0xa7, 0x55, 0x6f, 0xf4,
  35776. 0x26, 0xc9, 0xe7, 0xa4, 0x04, 0xce, 0x69, 0x35,
  35777. 0x58, 0x30, 0xa7, 0xa6, 0x77, 0x67, 0xa7, 0x6c,
  35778. 0x7d, 0x9a, 0x97, 0xb8, 0x4b, 0xfc, 0xf5, 0x0a,
  35779. 0x02, 0xf7, 0x5c, 0x23, 0x5d, 0x2f, 0x9c, 0x67,
  35780. 0x11, 0x38, 0x04, 0x9f, 0xfc, 0x7c, 0x80, 0x55,
  35781. 0x92, 0x6c, 0x03, 0xeb, 0x3f, 0xb8, 0x7f, 0x96,
  35782. 0x95, 0x18, 0x5a, 0x42, 0xec, 0xa9, 0xa4, 0x16,
  35783. 0x55, 0x87, 0x3d, 0x30, 0xa6, 0xb3, 0xbf, 0x42,
  35784. 0x8b, 0x24, 0x62, 0x23, 0x48, 0x4a, 0x8f, 0xf6,
  35785. 0x1e, 0xe3, 0xee, 0xaf, 0xff, 0x10, 0xe9, 0x9c,
  35786. 0x2c, 0x13, 0xa7, 0x62, 0x84, 0xd0, 0x63, 0xe5,
  35787. 0x6a, 0xb7, 0x11, 0xa3, 0x5a, 0x85, 0xb5, 0x38,
  35788. 0x3d, 0xf8, 0x1d, 0xa2, 0x34, 0x90, 0xf6, 0x6e,
  35789. 0x8e, 0xa3, 0xfc, 0xba, 0x06, 0x7f, 0x55, 0x30,
  35790. 0xc6, 0x54, 0x1c, 0x2b, 0x8f, 0x74, 0x71, 0x7c,
  35791. 0x35, 0x02, 0x3e, 0x7b, 0x9b, 0x39, 0x56, 0xc3,
  35792. 0xee, 0x2f, 0xf8, 0x4b, 0xa0, 0x3c, 0xcf, 0x4b,
  35793. 0x4b, 0x53, 0x21, 0xb9, 0x24, 0x08, 0x95, 0x48,
  35794. 0x1b, 0xc6, 0xd6, 0x3c, 0x16, 0x93, 0xc1, 0x84,
  35795. 0x78, 0x52, 0xf8, 0xe9, 0x7f, 0x50, 0xa1, 0x33,
  35796. 0x53, 0x2a, 0xc3, 0xee, 0x1e, 0x52, 0xd4, 0x64
  35797. #endif
  35798. };
  35799. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ss[] = {
  35800. #ifdef WOLFSSL_KYBER_ORIGINAL
  35801. 0x91, 0x4C, 0xB6, 0x7F, 0xE5, 0xC3, 0x8E, 0x73,
  35802. 0xBF, 0x74, 0x18, 0x1C, 0x0A, 0xC5, 0x04, 0x28,
  35803. 0xDE, 0xDF, 0x77, 0x50, 0xA9, 0x80, 0x58, 0xF7,
  35804. 0xD5, 0x36, 0x70, 0x87, 0x74, 0x53, 0x5B, 0x29
  35805. #else
  35806. 0xe7, 0x18, 0x4a, 0x09, 0x75, 0xee, 0x34, 0x70,
  35807. 0x87, 0x8d, 0x2d, 0x15, 0x9e, 0xc8, 0x31, 0x29,
  35808. 0xc8, 0xae, 0xc2, 0x53, 0xd4, 0xee, 0x17, 0xb4,
  35809. 0x81, 0x03, 0x11, 0xd1, 0x98, 0xcd, 0x03, 0x68
  35810. #endif
  35811. };
  35812. #ifdef WOLFSSL_SMALL_STACK
  35813. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  35814. DYNAMIC_TYPE_TMP_BUFFER);
  35815. priv = (byte *)XMALLOC(KYBER768_PRIVATE_KEY_SIZE, HEAP_HINT,
  35816. DYNAMIC_TYPE_TMP_BUFFER);
  35817. pub = (byte *)XMALLOC(KYBER768_PUBLIC_KEY_SIZE, HEAP_HINT,
  35818. DYNAMIC_TYPE_TMP_BUFFER);
  35819. ct = (byte *)XMALLOC(KYBER768_CIPHER_TEXT_SIZE, HEAP_HINT,
  35820. DYNAMIC_TYPE_TMP_BUFFER);
  35821. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  35822. DYNAMIC_TYPE_TMP_BUFFER);
  35823. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  35824. DYNAMIC_TYPE_TMP_BUFFER);
  35825. if (! (key && priv && pub && ct && ss && ss_dec))
  35826. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  35827. #endif
  35828. ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
  35829. if (ret != 0)
  35830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35831. else
  35832. key_inited = 1;
  35833. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  35834. sizeof(kyber768_rand));
  35835. if (ret != 0)
  35836. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35837. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
  35838. if (ret != 0)
  35839. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35840. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
  35841. if (ret != 0)
  35842. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35843. if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0)
  35844. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35845. if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
  35846. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35847. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  35848. sizeof(kyber768enc_rand));
  35849. if (ret != 0)
  35850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35851. if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0)
  35852. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35853. if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
  35854. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35855. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
  35856. if (ret != 0)
  35857. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35858. if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0)
  35859. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35860. out:
  35861. if (key_inited)
  35862. wc_KyberKey_Free(key);
  35863. #ifdef WOLFSSL_SMALL_STACK
  35864. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35865. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35866. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35867. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35868. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35869. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35870. #endif
  35871. return ret;
  35872. }
  35873. #endif /* WOLFSSL_KYBER768 */
  35874. #ifdef WOLFSSL_KYBER1024
  35875. static wc_test_ret_t kyber1024_kat(void)
  35876. {
  35877. wc_test_ret_t ret;
  35878. #ifdef WOLFSSL_SMALL_STACK
  35879. KyberKey *key = NULL;
  35880. byte *priv = NULL;
  35881. byte *pub = NULL;
  35882. byte *ct = NULL;
  35883. byte *ss = NULL;
  35884. byte *ss_dec = NULL;
  35885. #else
  35886. KyberKey key[1];
  35887. byte priv[KYBER1024_PRIVATE_KEY_SIZE];
  35888. byte pub[KYBER1024_PUBLIC_KEY_SIZE];
  35889. byte ct[KYBER1024_CIPHER_TEXT_SIZE];
  35890. byte ss[KYBER_SS_SZ];
  35891. byte ss_dec[KYBER_SS_SZ];
  35892. #endif
  35893. int key_inited = 0;
  35894. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_rand[] = {
  35895. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  35896. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  35897. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  35898. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  35899. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35900. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35901. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35902. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35903. };
  35904. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024enc_rand[] = {
  35905. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  35906. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  35907. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  35908. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  35909. };
  35910. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_pk[] = {
  35911. #ifdef WOLFSSL_KYBER_ORIGINAL
  35912. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  35913. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  35914. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  35915. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  35916. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  35917. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  35918. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  35919. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  35920. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  35921. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  35922. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  35923. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  35924. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  35925. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  35926. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  35927. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  35928. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  35929. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  35930. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  35931. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  35932. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  35933. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  35934. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  35935. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  35936. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  35937. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  35938. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  35939. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  35940. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  35941. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  35942. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  35943. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  35944. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  35945. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  35946. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  35947. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  35948. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  35949. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  35950. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  35951. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  35952. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  35953. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  35954. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  35955. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  35956. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  35957. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  35958. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  35959. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  35960. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  35961. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  35962. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  35963. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  35964. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  35965. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  35966. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  35967. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  35968. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  35969. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  35970. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  35971. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  35972. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  35973. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  35974. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  35975. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  35976. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  35977. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  35978. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  35979. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  35980. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  35981. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  35982. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  35983. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  35984. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  35985. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  35986. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  35987. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  35988. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  35989. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  35990. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  35991. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  35992. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  35993. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  35994. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  35995. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  35996. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  35997. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  35998. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  35999. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36000. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36001. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36002. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36003. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36004. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36005. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36006. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36007. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36008. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36009. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36010. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36011. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36012. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36013. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36014. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36015. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36016. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36017. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36018. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36019. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36020. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36021. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36022. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36023. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36024. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36025. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36026. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36027. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36028. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36029. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36030. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36031. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36032. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36033. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36034. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36035. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36036. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36037. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36038. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36039. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36040. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36041. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36042. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36043. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36044. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36045. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36046. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36047. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36048. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36049. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36050. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36051. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36052. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36053. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36054. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36055. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36056. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36057. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36058. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36059. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36060. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36061. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36062. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36063. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36064. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36065. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36066. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36067. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36068. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36069. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36070. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36071. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36072. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36073. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36074. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36075. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36076. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36077. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36078. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36079. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36080. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36081. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36082. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36083. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36084. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36085. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36086. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36087. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36088. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36089. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36090. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36091. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36092. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36093. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36094. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36095. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36096. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36097. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36098. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36099. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36100. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36101. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36102. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36103. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36104. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36105. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36106. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36107. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  36108. #else
  36109. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36110. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36111. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36112. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36113. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36114. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36115. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36116. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36117. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36118. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36119. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36120. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36121. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36122. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36123. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36124. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36125. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36126. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36127. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36128. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36129. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36130. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36131. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36132. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36133. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36134. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36135. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36136. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36137. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36138. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36139. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36140. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36141. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36142. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36143. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36144. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36145. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36146. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36147. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36148. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36149. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36150. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36151. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36152. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36153. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36154. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36155. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36156. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36157. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36158. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36159. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36160. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36161. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36162. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36163. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36164. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36165. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36166. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36167. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36168. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36169. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36170. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36171. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36172. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36173. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36174. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36175. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36176. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36177. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36178. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36179. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36180. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36181. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36182. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36183. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36184. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36185. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36186. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36187. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36188. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36189. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36190. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36191. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36192. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36193. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36194. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36195. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36196. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36197. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36198. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36199. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36200. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36201. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36202. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36203. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36204. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36205. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36206. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36207. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36208. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36209. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36210. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  36211. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  36212. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  36213. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  36214. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  36215. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  36216. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  36217. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  36218. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  36219. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  36220. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  36221. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  36222. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  36223. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  36224. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  36225. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  36226. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  36227. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  36228. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  36229. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  36230. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  36231. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  36232. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  36233. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  36234. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  36235. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  36236. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  36237. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  36238. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  36239. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  36240. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  36241. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  36242. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  36243. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  36244. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  36245. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  36246. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  36247. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  36248. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  36249. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  36250. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  36251. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  36252. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  36253. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  36254. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  36255. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  36256. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  36257. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  36258. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  36259. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  36260. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  36261. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  36262. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  36263. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  36264. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  36265. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  36266. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  36267. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  36268. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  36269. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  36270. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  36271. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  36272. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  36273. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  36274. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  36275. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  36276. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  36277. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  36278. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  36279. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  36280. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  36281. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  36282. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  36283. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  36284. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  36285. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  36286. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  36287. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  36288. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  36289. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  36290. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  36291. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  36292. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  36293. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  36294. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  36295. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  36296. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  36297. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  36298. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  36299. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  36300. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  36301. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  36302. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  36303. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  36304. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb
  36305. #endif
  36306. };
  36307. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_sk[] = {
  36308. #ifdef WOLFSSL_KYBER_ORIGINAL
  36309. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  36310. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  36311. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  36312. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  36313. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  36314. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  36315. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  36316. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  36317. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  36318. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  36319. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  36320. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  36321. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  36322. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  36323. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  36324. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  36325. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  36326. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  36327. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  36328. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  36329. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  36330. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  36331. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  36332. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  36333. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  36334. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  36335. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  36336. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  36337. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  36338. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  36339. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  36340. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  36341. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  36342. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  36343. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  36344. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  36345. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  36346. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  36347. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  36348. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  36349. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  36350. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  36351. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  36352. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  36353. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  36354. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  36355. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  36356. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  36357. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  36358. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  36359. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  36360. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  36361. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  36362. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  36363. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  36364. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  36365. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  36366. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  36367. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  36368. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  36369. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  36370. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  36371. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  36372. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  36373. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  36374. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  36375. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  36376. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  36377. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  36378. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  36379. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  36380. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  36381. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  36382. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  36383. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  36384. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  36385. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  36386. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  36387. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  36388. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  36389. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  36390. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  36391. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  36392. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  36393. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  36394. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  36395. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  36396. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  36397. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  36398. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  36399. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  36400. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  36401. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  36402. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  36403. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  36404. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  36405. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  36406. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  36407. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  36408. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  36409. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  36410. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  36411. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  36412. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  36413. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  36414. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  36415. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  36416. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  36417. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  36418. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  36419. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  36420. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  36421. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  36422. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  36423. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  36424. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  36425. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  36426. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  36427. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  36428. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  36429. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  36430. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  36431. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  36432. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  36433. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  36434. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  36435. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  36436. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  36437. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  36438. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  36439. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  36440. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  36441. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  36442. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  36443. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  36444. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  36445. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  36446. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  36447. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  36448. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  36449. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  36450. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  36451. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  36452. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  36453. 0x85, 0xA4, 0xC1, 0xA1, 0xAB, 0x9B, 0x6A, 0xEB,
  36454. 0x49, 0xCC, 0xE1, 0xC2, 0xF8, 0xA9, 0x7C, 0x35,
  36455. 0x16, 0xC7, 0x2A, 0x00, 0xA4, 0x62, 0x63, 0xBA,
  36456. 0xA6, 0x96, 0xBF, 0x25, 0x72, 0x77, 0x19, 0xC3,
  36457. 0x21, 0x64, 0x23, 0x61, 0x8F, 0xF3, 0x33, 0x80,
  36458. 0x93, 0x4A, 0x6C, 0x10, 0x54, 0x5C, 0x4C, 0x5C,
  36459. 0x51, 0x55, 0xB1, 0x24, 0x86, 0x18, 0x1F, 0xC7,
  36460. 0xA2, 0x31, 0x98, 0x73, 0x97, 0x8B, 0x6A, 0x2A,
  36461. 0x67, 0x49, 0x0F, 0x82, 0x56, 0xBD, 0x21, 0x96,
  36462. 0xFE, 0x17, 0x92, 0xA4, 0xC0, 0x00, 0x77, 0xB8,
  36463. 0x12, 0xEA, 0xE8, 0xBE, 0xD3, 0x57, 0x24, 0x99,
  36464. 0x68, 0x4A, 0xB3, 0x37, 0x18, 0x76, 0x76, 0x1E,
  36465. 0x45, 0x0C, 0x9F, 0x9D, 0x27, 0x68, 0xA3, 0x68,
  36466. 0x06, 0xD7, 0xAB, 0x20, 0x46, 0xC9, 0x1F, 0x17,
  36467. 0x59, 0x9E, 0x9A, 0xC5, 0x92, 0x99, 0x08, 0x08,
  36468. 0xDC, 0xD7, 0xB4, 0xD0, 0x91, 0x90, 0x72, 0xF1,
  36469. 0x4E, 0xC3, 0x61, 0x77, 0x3B, 0x72, 0x52, 0x44,
  36470. 0x4C, 0x32, 0x3C, 0x30, 0x83, 0x26, 0xF4, 0xA3,
  36471. 0x0F, 0x86, 0x80, 0xD2, 0xF7, 0x48, 0xF5, 0x6A,
  36472. 0x13, 0x2B, 0x82, 0x67, 0x4E, 0xD0, 0x18, 0x46,
  36473. 0x20, 0xB8, 0x2A, 0xD2, 0xCB, 0x18, 0x2C, 0x97,
  36474. 0xB4, 0x81, 0x62, 0x66, 0x47, 0x49, 0x12, 0x90,
  36475. 0xA0, 0x11, 0xCC, 0x73, 0x82, 0x86, 0x85, 0xA8,
  36476. 0xC3, 0x67, 0xA5, 0xB9, 0xCF, 0x8D, 0x62, 0x1B,
  36477. 0x0D, 0x5C, 0x1E, 0xFF, 0x03, 0x17, 0x27, 0x58,
  36478. 0xBD, 0x00, 0x49, 0x78, 0xC2, 0x51, 0xCD, 0x51,
  36479. 0x34, 0x22, 0x28, 0x98, 0x9C, 0xAE, 0x63, 0x32,
  36480. 0xAC, 0x48, 0x64, 0x37, 0xCB, 0x5C, 0x57, 0xD4,
  36481. 0x30, 0x74, 0x62, 0x86, 0x52, 0x53, 0xBE, 0x21,
  36482. 0x7B, 0x35, 0x15, 0xC7, 0x3D, 0xF4, 0x05, 0xB7,
  36483. 0xF2, 0x82, 0x17, 0xAD, 0x0B, 0x8C, 0xF6, 0x0C,
  36484. 0x2F, 0xFF, 0xAA, 0x0A, 0x00, 0x48, 0xB1, 0xFB,
  36485. 0x4A, 0xCD, 0xCD, 0xC3, 0x8B, 0x52, 0x50, 0xCF,
  36486. 0xEC, 0x35, 0x6A, 0x6D, 0xE2, 0x6C, 0xFA, 0x7A,
  36487. 0x58, 0x8F, 0xDC, 0x86, 0xF9, 0x8C, 0x85, 0x4A,
  36488. 0xC6, 0x4C, 0x7B, 0xFA, 0xA9, 0x6F, 0x5A, 0x32,
  36489. 0xCC, 0x06, 0x10, 0x93, 0x4B, 0xAA, 0x6A, 0x58,
  36490. 0x6B, 0x9A, 0x20, 0x54, 0xF1, 0x3B, 0xA2, 0x74,
  36491. 0x17, 0x4A, 0xA0, 0xD2, 0xB3, 0xA8, 0x1B, 0x96,
  36492. 0xA9, 0x40, 0x66, 0x6F, 0x78, 0x9B, 0x5A, 0x6B,
  36493. 0xCD, 0xC0, 0xA6, 0xA0, 0x17, 0x8A, 0x0C, 0x9A,
  36494. 0x02, 0x57, 0x8A, 0x49, 0x3F, 0x6E, 0xEA, 0x0D,
  36495. 0x2E, 0x6C, 0x13, 0x95, 0x1C, 0x9F, 0x24, 0x9A,
  36496. 0x5E, 0x8D, 0xD7, 0x1D, 0xD4, 0x9A, 0x74, 0x2D,
  36497. 0x45, 0x1F, 0x1A, 0xBB, 0xA1, 0x9A, 0xF8, 0xC5,
  36498. 0x47, 0x85, 0x5E, 0x0A, 0xFC, 0x72, 0x8E, 0x90,
  36499. 0xAB, 0xB4, 0x99, 0xC9, 0xBE, 0xEB, 0x76, 0x6F,
  36500. 0x47, 0x29, 0xCD, 0xA2, 0x22, 0x63, 0xE3, 0x24,
  36501. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36502. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36503. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36504. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36505. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36506. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36507. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36508. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36509. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36510. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36511. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36512. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36513. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36514. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36515. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36516. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36517. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36518. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36519. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36520. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36521. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36522. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36523. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36524. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36525. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36526. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36527. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36528. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36529. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36530. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36531. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36532. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36533. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36534. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36535. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36536. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36537. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36538. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36539. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36540. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36541. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36542. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36543. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36544. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36545. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36546. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36547. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36548. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36549. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36550. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36551. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36552. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36553. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36554. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36555. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36556. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36557. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36558. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36559. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36560. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36561. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36562. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36563. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36564. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36565. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36566. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36567. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36568. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36569. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36570. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36571. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36572. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36573. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36574. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36575. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36576. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36577. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36578. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36579. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36580. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36581. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36582. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36583. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36584. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36585. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36586. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36587. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36588. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36589. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36590. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36591. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36592. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36593. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36594. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36595. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36596. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36597. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36598. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36599. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36600. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36601. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36602. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36603. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36604. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36605. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36606. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36607. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36608. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36609. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36610. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36611. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36612. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36613. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36614. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36615. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36616. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36617. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36618. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36619. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36620. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36621. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36622. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36623. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36624. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36625. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36626. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36627. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36628. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36629. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36630. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36631. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36632. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36633. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36634. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36635. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36636. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36637. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36638. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36639. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36640. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36641. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36642. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36643. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36644. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36645. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36646. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36647. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36648. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36649. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36650. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36651. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36652. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36653. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36654. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36655. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36656. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36657. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36658. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36659. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36660. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36661. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36662. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36663. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36664. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36665. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36666. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36667. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36668. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36669. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36670. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36671. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36672. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36673. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36674. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36675. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36676. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36677. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36678. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36679. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36680. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36681. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36682. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36683. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36684. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36685. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36686. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36687. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36688. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36689. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36690. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36691. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36692. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36693. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36694. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36695. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36696. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  36697. 0x8A, 0x39, 0xE8, 0x7D, 0x53, 0x1F, 0x35, 0x27,
  36698. 0xC2, 0x07, 0xED, 0xCC, 0x1D, 0xB7, 0xFA, 0xDD,
  36699. 0xCF, 0x96, 0x28, 0x39, 0x18, 0x79, 0xB3, 0x35,
  36700. 0xC7, 0x07, 0x83, 0x9A, 0x0D, 0xB0, 0x51, 0xA8,
  36701. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  36702. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  36703. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  36704. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  36705. #else
  36706. 0x43, 0x3a, 0x70, 0xee, 0x69, 0x50, 0xf9, 0x88,
  36707. 0x2a, 0xcd, 0xd5, 0xa4, 0x78, 0x20, 0xa6, 0xa8,
  36708. 0x16, 0x37, 0x08, 0xf0, 0x4d, 0x45, 0x7c, 0x77,
  36709. 0x99, 0x79, 0xb8, 0x3f, 0xe1, 0x17, 0x22, 0x47,
  36710. 0x01, 0x49, 0x08, 0x30, 0x38, 0x66, 0x37, 0xda,
  36711. 0x33, 0x2e, 0x74, 0xb1, 0xae, 0xda, 0x0b, 0x2f,
  36712. 0x81, 0xca, 0x4f, 0x9b, 0xb2, 0xc2, 0xb0, 0x2b,
  36713. 0x0c, 0xfd, 0x68, 0x0c, 0x11, 0x48, 0x2f, 0x33,
  36714. 0x5a, 0xcf, 0x7b, 0x91, 0x39, 0xb5, 0xb8, 0x8a,
  36715. 0x34, 0xe3, 0x54, 0x2c, 0x68, 0x61, 0x37, 0x75,
  36716. 0x45, 0x98, 0x33, 0x43, 0xcd, 0x82, 0x94, 0x14,
  36717. 0xe4, 0x78, 0x64, 0x21, 0x2e, 0x78, 0xf8, 0x55,
  36718. 0xf5, 0x23, 0x90, 0x37, 0x9a, 0xcc, 0x3a, 0x62,
  36719. 0x95, 0x31, 0x31, 0xb6, 0x3e, 0xe8, 0x32, 0xad,
  36720. 0xb3, 0xbf, 0x4b, 0xf5, 0x8e, 0x24, 0x73, 0x49,
  36721. 0xb5, 0xe0, 0x97, 0xe5, 0x5a, 0xbe, 0x49, 0x7b,
  36722. 0x15, 0x98, 0x23, 0x73, 0xae, 0x73, 0x2e, 0x04,
  36723. 0x39, 0xac, 0x67, 0xd0, 0x5c, 0x7f, 0x03, 0x7c,
  36724. 0x8a, 0x73, 0x9b, 0x18, 0x14, 0x0e, 0x14, 0x4c,
  36725. 0x85, 0x1d, 0xc9, 0x61, 0x1f, 0x4b, 0xcf, 0x04,
  36726. 0xf3, 0xa2, 0x09, 0x3c, 0x19, 0x7b, 0xd6, 0x3b,
  36727. 0xb5, 0xe6, 0x19, 0x01, 0x00, 0x54, 0x5f, 0xf8,
  36728. 0x1d, 0xb7, 0xfc, 0xcd, 0xdd, 0x9a, 0x32, 0x4b,
  36729. 0x0b, 0xac, 0x3c, 0x2c, 0x23, 0x82, 0x28, 0x40,
  36730. 0x58, 0xf0, 0x8b, 0x96, 0x19, 0x52, 0xc0, 0x94,
  36731. 0x01, 0x9c, 0x10, 0xbe, 0x37, 0xa5, 0x3d, 0x5a,
  36732. 0xc7, 0x94, 0xc0, 0x10, 0xa9, 0xd0, 0x82, 0x1f,
  36733. 0x15, 0x02, 0x7a, 0x1c, 0x41, 0x9c, 0x3c, 0x71,
  36734. 0xc9, 0xa1, 0xd2, 0x8a, 0xed, 0x02, 0x59, 0x7a,
  36735. 0xb7, 0x9b, 0x87, 0x53, 0x94, 0x62, 0x6b, 0xa3,
  36736. 0x9a, 0xdc, 0x09, 0x0c, 0x3a, 0x90, 0xcf, 0x75,
  36737. 0x87, 0x1a, 0x65, 0x27, 0x5e, 0xb1, 0xc5, 0xb0,
  36738. 0x33, 0x72, 0xe1, 0x3a, 0x1a, 0x23, 0xd0, 0xcf,
  36739. 0x93, 0x74, 0x11, 0x1f, 0x80, 0xcc, 0x83, 0xa9,
  36740. 0x05, 0x62, 0x2b, 0x83, 0xfc, 0x51, 0x39, 0x71,
  36741. 0xec, 0x84, 0x19, 0xf0, 0x88, 0x0c, 0x30, 0x67,
  36742. 0x63, 0x36, 0x71, 0xb0, 0x9b, 0x54, 0x56, 0xab,
  36743. 0x60, 0x57, 0x93, 0x6d, 0x19, 0xa4, 0xa2, 0xa2,
  36744. 0x67, 0x91, 0x1b, 0x00, 0x0a, 0x13, 0x95, 0x6f,
  36745. 0xbd, 0x49, 0x38, 0x21, 0xda, 0x07, 0x2c, 0x04,
  36746. 0x64, 0x2b, 0x0c, 0x20, 0xda, 0x6c, 0xc0, 0xd9,
  36747. 0xd8, 0x64, 0xa3, 0x93, 0x65, 0xdf, 0xd6, 0x4f,
  36748. 0x10, 0x18, 0x78, 0x25, 0xfa, 0x33, 0x25, 0x07,
  36749. 0x49, 0xcb, 0xc0, 0xc9, 0x05, 0xd7, 0xb1, 0xff,
  36750. 0x3c, 0xae, 0x24, 0x12, 0xbf, 0x86, 0xb8, 0x1a,
  36751. 0x81, 0x7b, 0x86, 0xba, 0xa3, 0x0e, 0xdf, 0x78,
  36752. 0x62, 0xe5, 0xf6, 0xba, 0xc9, 0x87, 0x26, 0xe5,
  36753. 0x6b, 0x3c, 0xec, 0x60, 0x66, 0x4c, 0xaa, 0x2a,
  36754. 0x7d, 0xf6, 0x70, 0xc5, 0xe2, 0x07, 0xdf, 0xac,
  36755. 0x03, 0x82, 0x4c, 0x89, 0x89, 0x7c, 0xb4, 0x90,
  36756. 0xea, 0xa7, 0x65, 0x21, 0x22, 0x2c, 0x86, 0x20,
  36757. 0x51, 0x69, 0xc9, 0x1c, 0x32, 0x9c, 0x4a, 0x18,
  36758. 0x4d, 0x78, 0x72, 0x1a, 0xf8, 0x36, 0xad, 0x4d,
  36759. 0xb0, 0xca, 0x78, 0x46, 0x4d, 0x41, 0x71, 0x47,
  36760. 0x30, 0x12, 0xb7, 0xd1, 0x83, 0xba, 0xfa, 0x62,
  36761. 0x75, 0x85, 0xc6, 0x4b, 0xe3, 0x80, 0x9d, 0x7e,
  36762. 0x60, 0x04, 0xcb, 0xdc, 0x79, 0xa5, 0x46, 0x0f,
  36763. 0x0a, 0xd6, 0x77, 0xcb, 0x71, 0x65, 0x12, 0x40,
  36764. 0x7d, 0x3a, 0x61, 0x9a, 0xd0, 0x95, 0x43, 0xb7,
  36765. 0x39, 0x54, 0x74, 0x72, 0xa7, 0x06, 0xb3, 0x17,
  36766. 0xa5, 0x09, 0xbe, 0x5d, 0x86, 0x1f, 0xd6, 0x6c,
  36767. 0x7d, 0x0e, 0xd9, 0x4c, 0xd5, 0x00, 0x47, 0x95,
  36768. 0xc1, 0x81, 0x59, 0xe3, 0xa3, 0x3d, 0x79, 0x87,
  36769. 0x11, 0x52, 0x5f, 0x16, 0x35, 0xa6, 0x84, 0x28,
  36770. 0x17, 0x29, 0x23, 0x24, 0x96, 0x35, 0xaa, 0xd0,
  36771. 0x32, 0xb9, 0xe5, 0x66, 0x64, 0xbd, 0xd4, 0x8e,
  36772. 0xd2, 0x4a, 0xc7, 0x5c, 0x64, 0x68, 0xd1, 0x90,
  36773. 0x3e, 0x47, 0x10, 0x86, 0xc5, 0xf1, 0x56, 0x7e,
  36774. 0x83, 0x1a, 0x05, 0x08, 0xc5, 0x39, 0x63, 0x25,
  36775. 0x91, 0xab, 0x57, 0x7d, 0x32, 0x4a, 0x82, 0x42,
  36776. 0x97, 0x25, 0x80, 0x99, 0x50, 0x76, 0x1d, 0x84,
  36777. 0x34, 0x28, 0x8c, 0x14, 0x03, 0x4f, 0x1c, 0x06,
  36778. 0xc1, 0xd0, 0xaa, 0xe0, 0x9a, 0x71, 0xc7, 0x40,
  36779. 0xa5, 0x57, 0x01, 0xc2, 0x8f, 0xf8, 0x44, 0x99,
  36780. 0xf2, 0xbb, 0x18, 0xb6, 0x62, 0x8c, 0xaa, 0xa3,
  36781. 0xfe, 0x75, 0xac, 0x4d, 0xe0, 0x4c, 0x6f, 0x91,
  36782. 0x39, 0x00, 0xd8, 0x6c, 0x88, 0x12, 0x62, 0x52,
  36783. 0xa1, 0x7c, 0x4d, 0x30, 0x39, 0x91, 0xdb, 0x02,
  36784. 0x87, 0x12, 0x08, 0x81, 0xbb, 0x88, 0x47, 0x8a,
  36785. 0xaa, 0x9a, 0xf9, 0xbc, 0x53, 0xd3, 0x72, 0x98,
  36786. 0x43, 0x85, 0x8f, 0xdb, 0x46, 0x48, 0x05, 0x9c,
  36787. 0xac, 0x82, 0xc1, 0xa1, 0x08, 0x78, 0xba, 0x39,
  36788. 0x82, 0x3b, 0x04, 0x1b, 0xd0, 0xe2, 0x58, 0x48,
  36789. 0x7b, 0x56, 0xcc, 0x8a, 0x32, 0x20, 0xc1, 0xa5,
  36790. 0x8b, 0xf6, 0x6a, 0x17, 0x2b, 0x5b, 0x9a, 0x0c,
  36791. 0x63, 0x2d, 0x67, 0x4e, 0xae, 0x88, 0x5a, 0x01,
  36792. 0x5c, 0x4e, 0x37, 0xba, 0x07, 0x36, 0x80, 0xbe,
  36793. 0xde, 0x75, 0x34, 0xf3, 0xe3, 0x4b, 0x60, 0x50,
  36794. 0xc8, 0x6b, 0x21, 0xc3, 0xc0, 0x90, 0x94, 0x1f,
  36795. 0x23, 0xb7, 0xf6, 0x73, 0x1e, 0x2b, 0xda, 0x0e,
  36796. 0x6e, 0xa4, 0x64, 0x67, 0x71, 0xce, 0xc5, 0x72,
  36797. 0xb9, 0x8c, 0xa0, 0xa1, 0x58, 0x91, 0x9a, 0xdb,
  36798. 0xeb, 0x84, 0xce, 0x58, 0x5f, 0xf9, 0xf2, 0x5e,
  36799. 0xbd, 0xda, 0x6c, 0xb6, 0xf0, 0x7a, 0x8f, 0x81,
  36800. 0x12, 0x32, 0x60, 0x7e, 0x72, 0x17, 0xbb, 0x03,
  36801. 0x9b, 0xab, 0xd0, 0xd9, 0x19, 0x34, 0xa8, 0x59,
  36802. 0x40, 0x59, 0xc9, 0x68, 0x77, 0x23, 0xc0, 0x43,
  36803. 0x81, 0xbf, 0xd6, 0x27, 0xa1, 0x05, 0x17, 0xf5,
  36804. 0xf4, 0xbf, 0xc7, 0x77, 0x77, 0xaa, 0x26, 0x71,
  36805. 0xae, 0x12, 0x4f, 0x2b, 0x7a, 0x5f, 0x4d, 0x56,
  36806. 0x14, 0x02, 0x91, 0x97, 0xe6, 0x58, 0x6f, 0xa8,
  36807. 0xc1, 0x7e, 0x0a, 0xd9, 0x07, 0x81, 0xbc, 0x7b,
  36808. 0xb1, 0x9a, 0x77, 0x2d, 0x5a, 0x4e, 0xfe, 0x32,
  36809. 0xca, 0xc8, 0x9b, 0x76, 0xc4, 0x2a, 0x5e, 0xde,
  36810. 0x9b, 0xcc, 0x20, 0xc1, 0x89, 0x8c, 0x08, 0xa5,
  36811. 0xb0, 0xc0, 0x7e, 0x47, 0x8b, 0x1b, 0xbc, 0x22,
  36812. 0x6e, 0xfa, 0xd1, 0x5f, 0x2a, 0xc7, 0x37, 0x51,
  36813. 0x4b, 0x8c, 0x61, 0x49, 0x81, 0x07, 0x79, 0x22,
  36814. 0x24, 0x16, 0x53, 0x7e, 0xd0, 0x0d, 0xae, 0xab,
  36815. 0x17, 0x7e, 0x90, 0x3e, 0xad, 0x6b, 0x4a, 0xc4,
  36816. 0x23, 0x70, 0xaf, 0x1b, 0x1f, 0x50, 0xeb, 0xaf,
  36817. 0xaa, 0x1c, 0x6e, 0x64, 0x7b, 0xba, 0xcc, 0xe7,
  36818. 0x2c, 0x7d, 0x0b, 0x88, 0xae, 0xb0, 0xb0, 0x6f,
  36819. 0xc1, 0xa4, 0x54, 0x57, 0xa9, 0xc1, 0x87, 0x57,
  36820. 0x9b, 0xf1, 0x84, 0x57, 0x9c, 0xc3, 0x51, 0xc4,
  36821. 0x3d, 0xff, 0x94, 0x26, 0x05, 0xaa, 0x56, 0x04,
  36822. 0xfc, 0x85, 0xfc, 0x55, 0x83, 0xf6, 0xf1, 0x49,
  36823. 0x6f, 0xe6, 0x1d, 0x70, 0xd6, 0xcd, 0xe2, 0x32,
  36824. 0x7f, 0xee, 0x71, 0x3d, 0x86, 0xf2, 0x9b, 0x3a,
  36825. 0xfc, 0xbb, 0x54, 0xe9, 0xa9, 0x2a, 0x33, 0xa6,
  36826. 0xc1, 0xea, 0x6f, 0xfa, 0x30, 0x95, 0x66, 0xb0,
  36827. 0x68, 0x62, 0x33, 0xc0, 0xf3, 0xb1, 0xc3, 0x14,
  36828. 0x48, 0x90, 0xe4, 0xf0, 0x82, 0x9a, 0x60, 0x99,
  36829. 0xc5, 0x74, 0x9c, 0xde, 0xc8, 0x43, 0x28, 0xec,
  36830. 0x2c, 0xb6, 0x4a, 0x73, 0x85, 0xa7, 0x61, 0xd6,
  36831. 0x4b, 0x3a, 0x23, 0xc4, 0x89, 0x34, 0x33, 0x43,
  36832. 0xb9, 0x77, 0x23, 0xae, 0x78, 0xc7, 0xd8, 0x05,
  36833. 0x45, 0x8e, 0x16, 0x20, 0xf0, 0x29, 0x28, 0x97,
  36834. 0x69, 0x17, 0x04, 0xcb, 0x76, 0xe3, 0xb0, 0xb2,
  36835. 0x81, 0xa8, 0x3c, 0xf6, 0x44, 0x90, 0x49, 0x8c,
  36836. 0xbc, 0xaf, 0x04, 0x80, 0x24, 0x16, 0xb3, 0x3c,
  36837. 0x56, 0x51, 0x71, 0xd7, 0x72, 0xd3, 0xb9, 0x35,
  36838. 0x40, 0x37, 0x58, 0x76, 0x29, 0xae, 0x14, 0xa5,
  36839. 0xc5, 0x03, 0x1a, 0xc3, 0x66, 0x71, 0xa0, 0xd0,
  36840. 0xc9, 0x1c, 0xc0, 0xb4, 0xcd, 0x69, 0xd8, 0x40,
  36841. 0x2e, 0x33, 0xb9, 0xbc, 0xc2, 0xbb, 0xaf, 0x6b,
  36842. 0x97, 0x1e, 0x30, 0x3f, 0xa1, 0x37, 0xbe, 0x23,
  36843. 0x25, 0x98, 0xa4, 0x99, 0x9b, 0xc0, 0x12, 0x57,
  36844. 0x4c, 0x81, 0x65, 0x1b, 0x38, 0xb3, 0x83, 0x96,
  36845. 0xc1, 0xc3, 0x65, 0x30, 0x3a, 0xd2, 0x5d, 0x49,
  36846. 0xfc, 0x6b, 0x68, 0x99, 0x51, 0xa1, 0xcc, 0x4c,
  36847. 0x60, 0x07, 0x61, 0x30, 0x65, 0x49, 0x5f, 0x97,
  36848. 0x91, 0x0f, 0x97, 0x35, 0xd4, 0xea, 0x4e, 0x44,
  36849. 0x2a, 0xcb, 0x2f, 0xab, 0xae, 0xcf, 0xe1, 0xad,
  36850. 0xef, 0x06, 0x67, 0xba, 0x42, 0x2c, 0x95, 0x4a,
  36851. 0x05, 0xd1, 0xb6, 0x16, 0x7a, 0x26, 0x3e, 0x12,
  36852. 0x75, 0xc6, 0xad, 0xa8, 0x38, 0x59, 0x65, 0x30,
  36853. 0x4b, 0x30, 0x32, 0x40, 0x40, 0x54, 0x2c, 0xf5,
  36854. 0xa4, 0x51, 0xbc, 0xaf, 0xc7, 0x47, 0x88, 0xbe,
  36855. 0x3b, 0x9b, 0x9f, 0xcc, 0x45, 0xd4, 0x79, 0x0e,
  36856. 0x2d, 0x73, 0x35, 0xc6, 0x0a, 0x14, 0xf0, 0xa4,
  36857. 0x9d, 0x13, 0x05, 0x3f, 0x26, 0x26, 0xa6, 0x27,
  36858. 0xca, 0x19, 0x55, 0x3c, 0xb3, 0x36, 0xa2, 0xcb,
  36859. 0x4a, 0x45, 0x5d, 0x8e, 0xf3, 0x98, 0x94, 0x91,
  36860. 0x47, 0x2b, 0xa0, 0x05, 0x1e, 0xf7, 0x41, 0x6e,
  36861. 0x0b, 0xbf, 0x1a, 0x61, 0x08, 0xfa, 0x07, 0xc1,
  36862. 0x61, 0x54, 0x8e, 0x7c, 0x62, 0x33, 0x1a, 0xe5,
  36863. 0xa2, 0xb4, 0xe4, 0xa1, 0x08, 0xa5, 0x10, 0x93,
  36864. 0xd3, 0x15, 0x08, 0x21, 0xa2, 0xfb, 0x54, 0x71,
  36865. 0x70, 0xa1, 0xb7, 0x3c, 0x43, 0xc5, 0x50, 0xc6,
  36866. 0x55, 0x7a, 0x40, 0x48, 0xa5, 0x8a, 0x2c, 0xd7,
  36867. 0x7a, 0x24, 0x42, 0x34, 0xb2, 0x23, 0x51, 0x75,
  36868. 0xa0, 0x89, 0x7d, 0x50, 0x61, 0xb4, 0x61, 0x34,
  36869. 0x82, 0xdc, 0x13, 0x64, 0x14, 0x04, 0x8c, 0x11,
  36870. 0xdb, 0x37, 0xea, 0xe0, 0xa5, 0xdf, 0x87, 0xc1,
  36871. 0x93, 0x14, 0xb0, 0xe8, 0x23, 0x97, 0xa0, 0xd3,
  36872. 0x38, 0xdc, 0x21, 0x53, 0x8a, 0xf3, 0x61, 0x49,
  36873. 0xd9, 0x3f, 0x8b, 0x1a, 0x11, 0xc5, 0x3b, 0xb5,
  36874. 0xde, 0xf8, 0xb7, 0xa2, 0xcc, 0xa3, 0x36, 0x2b,
  36875. 0x7f, 0xe3, 0xa1, 0x40, 0x8a, 0x25, 0x47, 0xe2,
  36876. 0x09, 0x05, 0x8c, 0x67, 0x3a, 0x75, 0x66, 0xc2,
  36877. 0x61, 0x23, 0xa6, 0xd8, 0xb6, 0x92, 0xa5, 0xf3,
  36878. 0x3e, 0xbd, 0xcb, 0x26, 0x24, 0xb7, 0x9d, 0x87,
  36879. 0x7b, 0xce, 0x5f, 0xa1, 0x4e, 0x42, 0xe8, 0x3f,
  36880. 0xaa, 0xd8, 0x2e, 0x99, 0x00, 0x55, 0x3a, 0x3c,
  36881. 0x60, 0x45, 0xca, 0x32, 0x9f, 0xea, 0x4a, 0x50,
  36882. 0x65, 0x58, 0xc4, 0x91, 0xb6, 0xa6, 0x16, 0xc6,
  36883. 0xfd, 0x40, 0x0b, 0x42, 0x13, 0x6f, 0x44, 0xcb,
  36884. 0x0d, 0x02, 0x57, 0x65, 0x08, 0x19, 0x01, 0x8d,
  36885. 0x3c, 0x56, 0x8e, 0xf6, 0xc6, 0x0c, 0x6c, 0x40,
  36886. 0x9e, 0x70, 0xa8, 0x29, 0x28, 0x71, 0x08, 0xc1,
  36887. 0xb6, 0xa4, 0xd3, 0x2f, 0x76, 0xe5, 0xcc, 0x4d,
  36888. 0x10, 0x4b, 0x02, 0x43, 0x8e, 0xf7, 0xa4, 0x67,
  36889. 0x91, 0x23, 0x98, 0xea, 0x9c, 0x7c, 0xbd, 0x99,
  36890. 0x81, 0x58, 0x9a, 0x34, 0x18, 0x97, 0x68, 0x7b,
  36891. 0x51, 0x6a, 0x13, 0x30, 0x7d, 0x66, 0xc0, 0x68,
  36892. 0xc4, 0x44, 0xb4, 0xb9, 0x49, 0xa1, 0x74, 0x12,
  36893. 0x41, 0x33, 0x15, 0xcc, 0xf4, 0x9b, 0x99, 0x98,
  36894. 0x00, 0x34, 0xb5, 0xb8, 0xcf, 0xde, 0xc4, 0xa6,
  36895. 0x0b, 0x9c, 0x1e, 0x74, 0x55, 0xaa, 0xfb, 0xf3,
  36896. 0xa7, 0x57, 0x34, 0x69, 0x90, 0xcc, 0x32, 0xb0,
  36897. 0x59, 0x9b, 0xa2, 0x17, 0xa6, 0xc5, 0xfc, 0x39,
  36898. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36899. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36900. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36901. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36902. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36903. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36904. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36905. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36906. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36907. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36908. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36909. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36910. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36911. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36912. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36913. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36914. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36915. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36916. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36917. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36918. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36919. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36920. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36921. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36922. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36923. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36924. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36925. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36926. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36927. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36928. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36929. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36930. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36931. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36932. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36933. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36934. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36935. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36936. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36937. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36938. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36939. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36940. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36941. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36942. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36943. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36944. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36945. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36946. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36947. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36948. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36949. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36950. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36951. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36952. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36953. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36954. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36955. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36956. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36957. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36958. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36959. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36960. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36961. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36962. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36963. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36964. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36965. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36966. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36967. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36968. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36969. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36970. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36971. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36972. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36973. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36974. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36975. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36976. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36977. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36978. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36979. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36980. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36981. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36982. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36983. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36984. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36985. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36986. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36987. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36988. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36989. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36990. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36991. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36992. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36993. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36994. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36995. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36996. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36997. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36998. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36999. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  37000. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  37001. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  37002. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  37003. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  37004. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  37005. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  37006. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  37007. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  37008. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  37009. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  37010. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  37011. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  37012. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  37013. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  37014. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  37015. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  37016. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  37017. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  37018. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  37019. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  37020. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  37021. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  37022. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  37023. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  37024. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  37025. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  37026. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  37027. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  37028. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  37029. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  37030. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  37031. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  37032. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  37033. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  37034. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  37035. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  37036. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  37037. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  37038. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  37039. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  37040. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  37041. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  37042. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  37043. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  37044. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  37045. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  37046. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  37047. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  37048. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  37049. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  37050. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  37051. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  37052. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  37053. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  37054. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  37055. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  37056. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  37057. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  37058. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  37059. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  37060. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  37061. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  37062. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  37063. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  37064. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  37065. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  37066. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  37067. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  37068. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  37069. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  37070. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  37071. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  37072. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  37073. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  37074. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  37075. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  37076. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  37077. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  37078. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  37079. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  37080. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  37081. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  37082. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  37083. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  37084. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  37085. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  37086. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  37087. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  37088. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  37089. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  37090. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  37091. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  37092. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  37093. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb,
  37094. 0xeb, 0xbe, 0x41, 0xcd, 0x4d, 0xea, 0x48, 0x9d,
  37095. 0xed, 0xd0, 0x0e, 0x76, 0xae, 0x0b, 0xcf, 0x54,
  37096. 0xaa, 0x85, 0x50, 0x20, 0x29, 0x20, 0xeb, 0x64,
  37097. 0xd5, 0x89, 0x2a, 0xd0, 0x2b, 0x13, 0xf2, 0xe5,
  37098. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  37099. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  37100. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  37101. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  37102. #endif
  37103. };
  37104. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ct[] = {
  37105. #ifdef WOLFSSL_KYBER_ORIGINAL
  37106. 0xA6, 0xAF, 0x29, 0xD5, 0xF5, 0xB8, 0x0B, 0xD1,
  37107. 0x30, 0xF5, 0x18, 0xBA, 0xDD, 0xD6, 0xC8, 0xF1,
  37108. 0x75, 0x45, 0x41, 0x3D, 0x86, 0x0F, 0xB3, 0xDE,
  37109. 0x45, 0x19, 0x79, 0xEB, 0xFA, 0x5E, 0x4E, 0x31,
  37110. 0x12, 0xC7, 0xC0, 0xAD, 0xF9, 0x98, 0x24, 0xBB,
  37111. 0x52, 0x6F, 0x2C, 0x35, 0x50, 0x74, 0x8E, 0xD0,
  37112. 0xE1, 0x34, 0xF0, 0x45, 0x7A, 0x7C, 0x61, 0xF9,
  37113. 0xF5, 0x26, 0xF0, 0x02, 0xBA, 0xAD, 0xC0, 0x3F,
  37114. 0xC1, 0x3E, 0x38, 0x13, 0x12, 0x19, 0x51, 0x3C,
  37115. 0x3E, 0xDE, 0x06, 0x16, 0x61, 0xE7, 0x4F, 0x60,
  37116. 0x3C, 0x4F, 0xCF, 0x79, 0x51, 0xC8, 0xE5, 0x2C,
  37117. 0x9C, 0x21, 0x3B, 0x0D, 0x22, 0xD9, 0x29, 0x36,
  37118. 0x63, 0xD6, 0x69, 0xA6, 0xB5, 0x8E, 0xD8, 0xFC,
  37119. 0xEF, 0xCF, 0x82, 0x49, 0xD7, 0xBB, 0x52, 0x98,
  37120. 0xF5, 0x57, 0x61, 0x44, 0x5B, 0x2B, 0x83, 0xCE,
  37121. 0x7F, 0x00, 0x5C, 0xB0, 0x42, 0x48, 0xAE, 0xC8,
  37122. 0xBD, 0xA2, 0x2F, 0xD2, 0xD4, 0x2A, 0xA7, 0x66,
  37123. 0x32, 0x20, 0x14, 0xEA, 0x03, 0x8C, 0xC3, 0x2C,
  37124. 0x55, 0xC8, 0xE4, 0xB9, 0xE2, 0x8E, 0xC9, 0x11,
  37125. 0x9F, 0x52, 0x73, 0x41, 0xE4, 0xF6, 0x6A, 0x03,
  37126. 0x51, 0x21, 0x07, 0x3B, 0x85, 0xDE, 0x67, 0x06,
  37127. 0xDA, 0x19, 0xE0, 0x83, 0x8A, 0x9F, 0x33, 0xB7,
  37128. 0x19, 0xA6, 0x8F, 0x03, 0x9B, 0x66, 0x4D, 0xC0,
  37129. 0x02, 0x65, 0x9E, 0xAB, 0xFC, 0x39, 0x86, 0x79,
  37130. 0xAA, 0x70, 0x09, 0xCE, 0x0C, 0xD0, 0x1C, 0xDA,
  37131. 0xFB, 0x6C, 0xD2, 0xA2, 0x6F, 0xE4, 0x10, 0x16,
  37132. 0x72, 0xC9, 0x8F, 0xF5, 0x8F, 0x7C, 0x47, 0xD5,
  37133. 0xBD, 0xA2, 0x90, 0x66, 0x53, 0xB3, 0xA6, 0xF9,
  37134. 0x65, 0x1F, 0x7A, 0x12, 0x1E, 0xA7, 0x7E, 0xA7,
  37135. 0x47, 0x23, 0xFA, 0xE5, 0xB8, 0x73, 0xF9, 0xBB,
  37136. 0x7B, 0x66, 0x4F, 0x0C, 0x8A, 0x93, 0x83, 0x1E,
  37137. 0xF9, 0xD5, 0x1C, 0x7C, 0xC1, 0xEF, 0x44, 0xAC,
  37138. 0x0E, 0x55, 0xA5, 0x5C, 0xA7, 0x6D, 0x13, 0x7F,
  37139. 0xE9, 0xB7, 0x5F, 0x40, 0x50, 0x9C, 0xEF, 0x15,
  37140. 0x6E, 0x5A, 0xD1, 0x8F, 0x9F, 0xB9, 0x99, 0x68,
  37141. 0x00, 0x08, 0xE5, 0x47, 0xD5, 0x5E, 0xEC, 0xD5,
  37142. 0xB4, 0xD1, 0xCB, 0x1D, 0x9F, 0x07, 0x6C, 0xEC,
  37143. 0x21, 0x50, 0x1C, 0x74, 0x02, 0x50, 0x9E, 0xCB,
  37144. 0x77, 0xAF, 0xB2, 0xCB, 0x9A, 0x61, 0x34, 0x0A,
  37145. 0x8B, 0xD1, 0x51, 0x4C, 0x6E, 0x71, 0xB4, 0xAA,
  37146. 0x45, 0xE4, 0x7E, 0xC3, 0x75, 0x12, 0x27, 0x1B,
  37147. 0x91, 0x1F, 0x8F, 0xB4, 0x6C, 0x90, 0x82, 0xC9,
  37148. 0xDF, 0x07, 0x20, 0x4A, 0xBB, 0x5A, 0x50, 0xE6,
  37149. 0xE3, 0x64, 0x7A, 0x8A, 0xD4, 0xD8, 0xD5, 0xD7,
  37150. 0xBF, 0xF1, 0x9C, 0x8A, 0x50, 0x93, 0x08, 0xBC,
  37151. 0xFB, 0x89, 0x55, 0x36, 0xD0, 0x45, 0xCA, 0x2B,
  37152. 0x97, 0xCB, 0x16, 0xA2, 0x9B, 0xB7, 0x18, 0x1C,
  37153. 0xAD, 0x05, 0x09, 0xDD, 0xB9, 0x17, 0x35, 0x02,
  37154. 0x8E, 0xBA, 0x8C, 0x31, 0xD7, 0x4B, 0xD2, 0x75,
  37155. 0xEA, 0xA6, 0x5B, 0x53, 0x40, 0xB3, 0xA4, 0x3F,
  37156. 0xBF, 0xE0, 0xB3, 0x06, 0x1D, 0x6B, 0xAE, 0x7E,
  37157. 0x75, 0xB7, 0x09, 0x8C, 0xDA, 0xBE, 0x91, 0xD4,
  37158. 0xB3, 0x1E, 0x36, 0xC9, 0xAA, 0x7A, 0x82, 0x98,
  37159. 0x86, 0x2A, 0xD6, 0x3C, 0x8F, 0xD2, 0x82, 0xE0,
  37160. 0x3B, 0x46, 0x0B, 0x3A, 0xB4, 0x64, 0xCE, 0x0F,
  37161. 0x27, 0xB1, 0xC3, 0xD1, 0x11, 0x55, 0xAC, 0xAA,
  37162. 0x01, 0x1E, 0xB9, 0xE2, 0xAE, 0x3E, 0x6D, 0xDA,
  37163. 0x07, 0xD6, 0xF4, 0x91, 0x73, 0x7C, 0xBC, 0xE9,
  37164. 0xB0, 0x5F, 0x9B, 0xC5, 0x6B, 0xE2, 0x0E, 0x8D,
  37165. 0x32, 0x6B, 0xA1, 0x32, 0xC5, 0x7F, 0xB2, 0x35,
  37166. 0x16, 0x11, 0x44, 0x51, 0x9C, 0xDF, 0x40, 0x56,
  37167. 0x0F, 0xBE, 0x27, 0x9B, 0xDE, 0x41, 0x1E, 0x11,
  37168. 0x25, 0x31, 0xF8, 0x26, 0xD6, 0xAB, 0x10, 0xD4,
  37169. 0x54, 0x73, 0x50, 0xAD, 0xD2, 0xA9, 0xDE, 0x8D,
  37170. 0x62, 0xC2, 0xAC, 0x82, 0xCA, 0xBE, 0x68, 0x15,
  37171. 0x64, 0x6F, 0x4D, 0xC9, 0x74, 0x2B, 0xB0, 0xC2,
  37172. 0xA3, 0xF7, 0x7E, 0xC7, 0xB4, 0x6C, 0x6B, 0x53,
  37173. 0x76, 0x05, 0xFA, 0x31, 0x79, 0x8C, 0xD8, 0x92,
  37174. 0x81, 0x22, 0x1A, 0x33, 0xDF, 0xB9, 0x79, 0x6E,
  37175. 0x64, 0x43, 0x05, 0x63, 0x03, 0x32, 0xC2, 0xCB,
  37176. 0x93, 0x14, 0x08, 0xAB, 0x48, 0x1A, 0x16, 0xD9,
  37177. 0x53, 0xF6, 0xBE, 0xAE, 0x38, 0x91, 0xD6, 0xD9,
  37178. 0xAC, 0x1F, 0xAB, 0x38, 0x22, 0x2D, 0x92, 0x71,
  37179. 0x87, 0x2D, 0x9D, 0x0C, 0xAD, 0xB9, 0x1A, 0xBE,
  37180. 0x9B, 0x4E, 0x26, 0x5F, 0x75, 0xC6, 0xE5, 0xE8,
  37181. 0x29, 0xE1, 0x46, 0xC3, 0xD8, 0xCE, 0x1E, 0x9D,
  37182. 0x12, 0xE0, 0xD1, 0x29, 0x80, 0x19, 0x57, 0xF4,
  37183. 0x6B, 0x0D, 0x2D, 0xBE, 0x1F, 0x74, 0x9B, 0x1D,
  37184. 0x08, 0xE2, 0x34, 0x5F, 0x62, 0x39, 0xA7, 0x31,
  37185. 0x34, 0x2E, 0xB7, 0x5B, 0x0C, 0xF1, 0xBF, 0x41,
  37186. 0x17, 0x49, 0xBC, 0x2C, 0xAF, 0x28, 0x10, 0xB7,
  37187. 0x88, 0xC6, 0xB7, 0x23, 0x8B, 0x4D, 0x3D, 0xA2,
  37188. 0xD6, 0x31, 0x5C, 0xE9, 0x54, 0x2E, 0x24, 0x40,
  37189. 0x4F, 0x14, 0x57, 0x55, 0xA3, 0x0A, 0xB8, 0x51,
  37190. 0xE4, 0x44, 0x58, 0x41, 0xBD, 0x33, 0xF7, 0x16,
  37191. 0xA5, 0x86, 0x88, 0x48, 0x88, 0xEC, 0xC6, 0xBC,
  37192. 0x64, 0x98, 0xAA, 0x32, 0x91, 0x9A, 0xE8, 0x1D,
  37193. 0x20, 0xC2, 0x69, 0x73, 0xC2, 0xBD, 0x54, 0x58,
  37194. 0x2A, 0x0F, 0x6A, 0xD9, 0x8A, 0xBF, 0xD2, 0x62,
  37195. 0x7E, 0x15, 0x69, 0x0A, 0x72, 0x7E, 0x69, 0xF5,
  37196. 0x81, 0xDD, 0x2A, 0x71, 0x27, 0x98, 0x2A, 0x90,
  37197. 0xE3, 0x3E, 0x2D, 0x4A, 0x03, 0xFE, 0x33, 0x91,
  37198. 0x42, 0xC7, 0xE4, 0x4C, 0x32, 0x6A, 0xC4, 0x6E,
  37199. 0xD3, 0x95, 0xA2, 0x25, 0xD3, 0x03, 0x33, 0x89,
  37200. 0x91, 0x73, 0x28, 0xB4, 0x53, 0x16, 0xB1, 0x58,
  37201. 0x5A, 0x01, 0xB2, 0xC3, 0x04, 0xB2, 0x94, 0x4E,
  37202. 0x90, 0x3A, 0xBB, 0xB3, 0xEC, 0x56, 0x19, 0x44,
  37203. 0x1C, 0xFC, 0x89, 0x65, 0xA4, 0x46, 0xDF, 0x75,
  37204. 0xDE, 0xFA, 0x80, 0xC6, 0xE1, 0x5A, 0xDB, 0xD5,
  37205. 0x06, 0xB7, 0xAB, 0x2D, 0xE1, 0x2D, 0xDA, 0x9B,
  37206. 0xC8, 0x14, 0x41, 0xCF, 0xC8, 0x90, 0x52, 0xE2,
  37207. 0xE5, 0x80, 0x8F, 0x71, 0x26, 0xC6, 0xFD, 0x3A,
  37208. 0xC6, 0xAC, 0x80, 0x81, 0x25, 0x8A, 0x84, 0xA0,
  37209. 0x9A, 0xE5, 0x0F, 0x6C, 0xD7, 0xCC, 0x0F, 0x4A,
  37210. 0xF3, 0x36, 0xFD, 0x1D, 0x64, 0x3E, 0x99, 0x07,
  37211. 0x99, 0x96, 0x26, 0x8C, 0x2D, 0x32, 0xD9, 0x09,
  37212. 0xF2, 0x2E, 0x35, 0x04, 0xF0, 0x7F, 0xBB, 0x56,
  37213. 0x31, 0x96, 0xD4, 0x31, 0x2F, 0xDD, 0xB9, 0x33,
  37214. 0x5D, 0x5C, 0x1D, 0x36, 0xE8, 0xC5, 0xEE, 0xA2,
  37215. 0x27, 0x8D, 0xBA, 0x23, 0xB9, 0x4D, 0x19, 0x3C,
  37216. 0x94, 0x7C, 0xC4, 0x1C, 0xA9, 0x93, 0xDC, 0x7D,
  37217. 0xB1, 0x39, 0x63, 0x40, 0xAD, 0x9C, 0x4F, 0xE6,
  37218. 0x87, 0xDD, 0x7B, 0x8D, 0x0C, 0x7A, 0x51, 0x20,
  37219. 0xAE, 0x02, 0x04, 0xF2, 0xC6, 0x65, 0xBD, 0x5F,
  37220. 0x47, 0x3D, 0x64, 0x4C, 0x7F, 0xF2, 0x6B, 0xFF,
  37221. 0xBA, 0x7A, 0x36, 0x98, 0x08, 0x30, 0x70, 0x21,
  37222. 0x28, 0xA7, 0xE6, 0x61, 0xD6, 0x77, 0xA0, 0x92,
  37223. 0xA3, 0x6E, 0x74, 0x28, 0xA4, 0x13, 0x9F, 0xB2,
  37224. 0x9B, 0x00, 0x95, 0xCC, 0x11, 0x08, 0x6F, 0x44,
  37225. 0x7D, 0x2A, 0x9E, 0xF6, 0xC9, 0xB1, 0x61, 0xF1,
  37226. 0x89, 0xC6, 0x29, 0x9E, 0x08, 0x4C, 0xB7, 0xAA,
  37227. 0x00, 0xFA, 0xF7, 0x87, 0x79, 0x7B, 0xFB, 0x06,
  37228. 0x9F, 0xBC, 0x08, 0x7F, 0xDE, 0x26, 0x25, 0x2A,
  37229. 0x16, 0x64, 0xF1, 0x9C, 0x5A, 0x8A, 0x22, 0xEC,
  37230. 0x5E, 0xE1, 0xAE, 0xB0, 0x76, 0x35, 0x7B, 0x7D,
  37231. 0xC3, 0x7E, 0x6B, 0x0F, 0x15, 0x20, 0xF9, 0x58,
  37232. 0xF7, 0x85, 0x1B, 0xAC, 0xB9, 0x2C, 0x89, 0xFD,
  37233. 0x11, 0x4A, 0x72, 0xFE, 0xAC, 0x54, 0x65, 0x2D,
  37234. 0x45, 0xB0, 0x9E, 0x1A, 0xE7, 0x65, 0x1A, 0xBD,
  37235. 0x16, 0x4B, 0xCD, 0x53, 0x7D, 0x58, 0xFA, 0x39,
  37236. 0xD3, 0xEC, 0x8A, 0xCD, 0xCD, 0xF9, 0x84, 0x25,
  37237. 0x00, 0x58, 0x62, 0xFA, 0x59, 0x69, 0x2D, 0xE1,
  37238. 0x62, 0xB7, 0x7E, 0x62, 0x97, 0xC6, 0x62, 0x33,
  37239. 0x34, 0x84, 0x08, 0xA8, 0xAB, 0x69, 0x5C, 0xE2,
  37240. 0xF2, 0x72, 0x8D, 0xB9, 0xFB, 0xE2, 0x7E, 0x95,
  37241. 0x89, 0x67, 0xEC, 0x59, 0x74, 0x76, 0x7C, 0x5A,
  37242. 0x66, 0x02, 0x30, 0x74, 0xB4, 0xA7, 0x1A, 0xFD,
  37243. 0x26, 0x4A, 0xD2, 0x89, 0x0E, 0x97, 0x0A, 0x1F,
  37244. 0x31, 0xD6, 0xE3, 0x31, 0x1B, 0x73, 0x6F, 0x9F,
  37245. 0x94, 0x88, 0x79, 0x3D, 0xDC, 0x88, 0xF2, 0x34,
  37246. 0x58, 0x06, 0x42, 0x54, 0xC8, 0x2A, 0x1D, 0x9E,
  37247. 0x59, 0xEA, 0xD2, 0xFC, 0xEC, 0x40, 0xB4, 0x30,
  37248. 0x68, 0x7C, 0x4B, 0x7E, 0x28, 0x96, 0x09, 0x26,
  37249. 0xAF, 0xCA, 0xCC, 0x9B, 0xD7, 0x56, 0xA7, 0x10,
  37250. 0x88, 0xC7, 0x84, 0x50, 0xE2, 0x0A, 0x2E, 0x98,
  37251. 0x0A, 0xED, 0xE9, 0xEB, 0xED, 0xFE, 0x7F, 0xAB,
  37252. 0xD6, 0xAB, 0xFE, 0x96, 0xF9, 0x34, 0xC4, 0xB0,
  37253. 0x2C, 0x01, 0xCA, 0x19, 0x4D, 0x01, 0xB7, 0x3C,
  37254. 0x25, 0xD5, 0x99, 0x70, 0x39, 0xD3, 0xFC, 0xD0,
  37255. 0xF0, 0x99, 0x52, 0x1F, 0x70, 0xCA, 0xEE, 0x69,
  37256. 0x11, 0x0A, 0xC1, 0xFC, 0x5A, 0x99, 0x91, 0x7A,
  37257. 0xD7, 0x52, 0xFC, 0x96, 0xAD, 0xFA, 0xD7, 0x18,
  37258. 0x6D, 0x0A, 0x7C, 0x9C, 0xFE, 0x56, 0x01, 0xC0,
  37259. 0x75, 0x14, 0xEA, 0x64, 0x48, 0xD6, 0x61, 0xC5,
  37260. 0x7A, 0xA2, 0x02, 0x42, 0x10, 0x3C, 0x42, 0x76,
  37261. 0xA0, 0x70, 0xA4, 0x89, 0xA4, 0xCB, 0x6B, 0xCA,
  37262. 0x0F, 0x9E, 0xCC, 0x43, 0x79, 0xFB, 0x22, 0x02,
  37263. 0x15, 0xFD, 0x91, 0xF8, 0x10, 0x19, 0xD5, 0xB0,
  37264. 0xAE, 0x61, 0x93, 0x58, 0xB5, 0x24, 0x68, 0xF2,
  37265. 0x72, 0xC1, 0x78, 0xE3, 0xA7, 0x4C, 0xF6, 0x77,
  37266. 0x5A, 0xA9, 0x24, 0xFE, 0x32, 0x9C, 0x31, 0x75,
  37267. 0xD9, 0xE4, 0xC3, 0xE2, 0x1A, 0xB9, 0xEC, 0x83,
  37268. 0x6E, 0xDC, 0x3A, 0xCA, 0xB2, 0xE3, 0x89, 0x1E,
  37269. 0xE8, 0xDE, 0xDA, 0x51, 0x5D, 0x39, 0xAF, 0x9B,
  37270. 0x8D, 0xDD, 0x0E, 0xE7, 0xB0, 0x16, 0x4F, 0x80,
  37271. 0x5C, 0x38, 0x35, 0xF6, 0xD2, 0xBA, 0xBD, 0xB3,
  37272. 0x0E, 0xAB, 0x47, 0x56, 0xE7, 0xEC, 0x7F, 0x82,
  37273. 0x9E, 0xCE, 0x01, 0xE8, 0xEA, 0xDF, 0xBB, 0xED,
  37274. 0x12, 0xFC, 0x28, 0x3B, 0x3D, 0x4C, 0x69, 0xF5,
  37275. 0x75, 0xE7, 0xF8, 0x04, 0x17, 0x68, 0x9F, 0xDF,
  37276. 0xCF, 0xC7, 0xBE, 0x27, 0xEE, 0x3B, 0x8C, 0xDF,
  37277. 0x57, 0xAA, 0xEB, 0xEC, 0x4A, 0x95, 0xB7, 0xE5,
  37278. 0xBB, 0x58, 0x5B, 0x85, 0x22, 0x7F, 0x7C, 0x32,
  37279. 0xBE, 0x30, 0xDB, 0x3E, 0x65, 0xE4, 0x2E, 0x30,
  37280. 0xDC, 0xF5, 0xA5, 0xFA, 0x07, 0x3D, 0xBA, 0x39,
  37281. 0x9D, 0x94, 0x2F, 0x22, 0x22, 0xAD, 0xB9, 0xB9,
  37282. 0x89, 0x81, 0x02, 0xAF, 0xE5, 0x43, 0x2E, 0xDC,
  37283. 0x7F, 0x04, 0xAE, 0x34, 0xA8, 0xFE, 0xC2, 0xD8,
  37284. 0x1C, 0xB4, 0x9A, 0x9A, 0x9B, 0x43, 0x81, 0x4C,
  37285. 0xE7, 0x1D, 0x97, 0xF7, 0x26, 0xE2, 0xB1, 0xE8,
  37286. 0xF6, 0x4B, 0x50, 0xE6, 0x5D, 0xFB, 0x48, 0x16,
  37287. 0xE1, 0x2E, 0x82, 0xA3, 0x19, 0x74, 0x84, 0xA4,
  37288. 0xE9, 0xBB, 0xA4, 0xD2, 0xD6, 0x9E, 0x3F, 0x19,
  37289. 0xD0, 0xB7, 0x5C, 0x21, 0xE2, 0xBF, 0xFE, 0x9F,
  37290. 0xC0, 0xC9, 0x8C, 0xF4, 0x8A, 0x3A, 0xAF, 0x08,
  37291. 0xD4, 0x67, 0xF7, 0x26, 0x87, 0xDF, 0x01, 0x78,
  37292. 0x17, 0x4B, 0x78, 0x97, 0xF7, 0x34, 0x34, 0x9B,
  37293. 0x18, 0x1E, 0xCA, 0x86, 0xA5, 0x98, 0xA0, 0xC5,
  37294. 0xE8, 0xC2, 0x59, 0x46, 0xF2, 0x4D, 0xC5, 0x57,
  37295. 0x2B, 0xD3, 0x24, 0xA4, 0x04, 0x58, 0xA7, 0x88,
  37296. 0xE5, 0x13, 0x7F, 0x3C, 0x7A, 0x7C, 0x97, 0xFC,
  37297. 0x9F, 0x12, 0xA3, 0xC4, 0x63, 0xA8, 0xFE, 0x94,
  37298. 0x49, 0x10, 0x1C, 0xCE, 0x96, 0x6D, 0x7C, 0x00,
  37299. 0x93, 0x23, 0x93, 0x29, 0x98, 0xD5, 0x6E, 0xF4,
  37300. 0x30, 0xC7, 0x3B, 0xC2, 0x4F, 0x5D, 0x95, 0xF7,
  37301. 0x37, 0x85, 0x8D, 0xDC, 0x4F, 0x32, 0xC0, 0x13
  37302. #else
  37303. 0xc9, 0xbe, 0xad, 0x6b, 0x0c, 0x11, 0x14, 0x38,
  37304. 0x9b, 0xd4, 0x76, 0x1c, 0x73, 0xab, 0x90, 0x95,
  37305. 0xb5, 0x80, 0x9d, 0xaa, 0xc9, 0xf6, 0x59, 0xbb,
  37306. 0x56, 0x4a, 0xf2, 0x26, 0x17, 0x30, 0x52, 0xa4,
  37307. 0xa3, 0xe7, 0xf2, 0xe5, 0xfd, 0x47, 0xd2, 0xb0,
  37308. 0x2a, 0xae, 0xb5, 0x18, 0x9e, 0x06, 0xb9, 0xf4,
  37309. 0xae, 0x98, 0xb6, 0x19, 0xcb, 0x63, 0xef, 0xbd,
  37310. 0xf3, 0x98, 0x9a, 0x94, 0xb3, 0x6e, 0x8e, 0xa0,
  37311. 0xd7, 0x00, 0x63, 0x3b, 0x95, 0x0a, 0x0a, 0xe2,
  37312. 0xa7, 0x8e, 0xd9, 0x2e, 0x85, 0xc8, 0x5c, 0x70,
  37313. 0xe1, 0x3e, 0x62, 0x6f, 0xb2, 0x63, 0xfa, 0xc9,
  37314. 0x68, 0x15, 0x21, 0xc3, 0xab, 0x22, 0xfd, 0xab,
  37315. 0x29, 0x17, 0x3c, 0x96, 0x16, 0xa2, 0xb0, 0x37,
  37316. 0x08, 0x3f, 0xf7, 0xb2, 0xe0, 0x19, 0xb5, 0xbc,
  37317. 0xde, 0x06, 0x8f, 0xac, 0x25, 0x7e, 0xf8, 0xf1,
  37318. 0x27, 0x98, 0x41, 0x16, 0x93, 0xc1, 0xbd, 0xcc,
  37319. 0x65, 0x42, 0x09, 0x97, 0xa5, 0x13, 0xa8, 0xa6,
  37320. 0x95, 0x02, 0x62, 0x0b, 0xe8, 0xe4, 0xce, 0x73,
  37321. 0x62, 0xe4, 0x12, 0xa7, 0x6c, 0xf5, 0x1c, 0x1f,
  37322. 0x24, 0x33, 0xf1, 0xab, 0x64, 0xce, 0x0e, 0x5d,
  37323. 0x2f, 0x56, 0xd7, 0xc9, 0xad, 0xe9, 0x94, 0xd0,
  37324. 0xe3, 0x5d, 0x0a, 0xee, 0xf3, 0xac, 0x51, 0x5b,
  37325. 0x48, 0x24, 0x37, 0x66, 0x4d, 0x8c, 0x1d, 0x25,
  37326. 0xe5, 0xa5, 0x50, 0x7c, 0xf8, 0x0f, 0x97, 0x0d,
  37327. 0x3e, 0xa7, 0x22, 0x6a, 0xac, 0xdc, 0x45, 0x7c,
  37328. 0xbf, 0x88, 0xa0, 0x56, 0x0a, 0xa3, 0x5b, 0xb2,
  37329. 0xc5, 0xc4, 0x55, 0x86, 0x7e, 0x21, 0x59, 0x91,
  37330. 0x0a, 0x35, 0x81, 0x0b, 0xef, 0xe3, 0xaa, 0x10,
  37331. 0xeb, 0x04, 0xd8, 0xd5, 0x71, 0x47, 0xcb, 0x8f,
  37332. 0x66, 0xd2, 0xb0, 0x70, 0xba, 0xc4, 0x3d, 0x1f,
  37333. 0x1f, 0xfd, 0xd5, 0x7a, 0x93, 0x99, 0x95, 0x1f,
  37334. 0x64, 0x96, 0x57, 0x27, 0xbc, 0xb9, 0xf6, 0x6a,
  37335. 0xd4, 0x23, 0x09, 0xda, 0xfc, 0x79, 0x9c, 0x1c,
  37336. 0x54, 0x0a, 0xf1, 0xaf, 0x93, 0xef, 0xf6, 0x8a,
  37337. 0x86, 0xd6, 0x1f, 0x51, 0x15, 0xdb, 0x66, 0x2d,
  37338. 0xee, 0x7a, 0xc9, 0xa3, 0x62, 0x67, 0x77, 0x62,
  37339. 0xb6, 0xa1, 0x64, 0xa0, 0xfa, 0x0a, 0x4d, 0x85,
  37340. 0x9e, 0x4b, 0x8c, 0x8d, 0xbd, 0xb4, 0xe1, 0x83,
  37341. 0xf5, 0xe6, 0x80, 0x8f, 0xc5, 0x22, 0x29, 0x65,
  37342. 0x0c, 0xaf, 0x7c, 0xf3, 0xe1, 0x6d, 0xe3, 0xd8,
  37343. 0x95, 0xd1, 0x48, 0xc3, 0x54, 0x48, 0xab, 0x8c,
  37344. 0x27, 0x53, 0xc9, 0x83, 0x1b, 0x24, 0xbd, 0x49,
  37345. 0x21, 0x49, 0x7e, 0xaa, 0x19, 0x25, 0x65, 0xca,
  37346. 0xbf, 0xd8, 0x3c, 0x0c, 0x68, 0xdf, 0xe7, 0xd3,
  37347. 0x92, 0xab, 0xf5, 0xe5, 0xe6, 0xf8, 0x4b, 0xb9,
  37348. 0xf5, 0xaf, 0x4b, 0x71, 0x18, 0xc0, 0xb5, 0x58,
  37349. 0x10, 0x5f, 0x9c, 0x10, 0xc9, 0xb6, 0xd7, 0x06,
  37350. 0x82, 0xe1, 0xde, 0x6e, 0x06, 0x89, 0xd7, 0x10,
  37351. 0x6a, 0x63, 0x74, 0xbd, 0x34, 0xae, 0xd7, 0x22,
  37352. 0x9e, 0x6c, 0xb3, 0x56, 0xf2, 0xea, 0x65, 0xe6,
  37353. 0x80, 0xce, 0x7b, 0x1e, 0x2c, 0x37, 0x04, 0xe1,
  37354. 0x16, 0xa3, 0x85, 0x42, 0x82, 0x6e, 0x8a, 0x00,
  37355. 0x11, 0x41, 0xba, 0xf2, 0xe3, 0x4d, 0xe3, 0x7a,
  37356. 0x03, 0x04, 0x09, 0x86, 0xd4, 0xc0, 0xcd, 0x5d,
  37357. 0x57, 0xf0, 0x70, 0x1c, 0xe9, 0x30, 0x98, 0x6f,
  37358. 0xd9, 0x52, 0x5b, 0x58, 0xe2, 0xe5, 0x9f, 0x45,
  37359. 0xb8, 0xdd, 0x04, 0xc0, 0xf3, 0x5b, 0x0f, 0x47,
  37360. 0x97, 0x0c, 0xc6, 0x70, 0x79, 0x61, 0x8e, 0xb9,
  37361. 0xe6, 0xd9, 0x1e, 0x9b, 0x0f, 0x8c, 0x6d, 0x2e,
  37362. 0x16, 0x5c, 0xf4, 0x48, 0xa2, 0xc1, 0xeb, 0xf7,
  37363. 0x1b, 0x65, 0x37, 0xe0, 0xf3, 0x75, 0x18, 0x5d,
  37364. 0xfa, 0xfe, 0xf6, 0x98, 0xb6, 0x23, 0x9b, 0xb3,
  37365. 0x55, 0x80, 0xb3, 0x15, 0xbc, 0xb5, 0xed, 0x40,
  37366. 0x8c, 0x35, 0x7f, 0x19, 0x2d, 0xef, 0x89, 0xbc,
  37367. 0x1b, 0x75, 0xcd, 0xd6, 0xaa, 0xe8, 0xb5, 0xfa,
  37368. 0xf0, 0xc3, 0xe1, 0x38, 0x03, 0xf6, 0xbd, 0xfa,
  37369. 0x76, 0xfb, 0x40, 0x7f, 0xcb, 0xda, 0x79, 0x0c,
  37370. 0x32, 0x9b, 0x3e, 0xe4, 0x2f, 0xd3, 0xd3, 0xb0,
  37371. 0x3b, 0xd5, 0x00, 0x3f, 0x0b, 0xc4, 0x32, 0xf7,
  37372. 0xba, 0x39, 0x63, 0x11, 0x12, 0x45, 0x2d, 0xfd,
  37373. 0x12, 0x14, 0x04, 0x33, 0xff, 0x89, 0x80, 0xeb,
  37374. 0x6a, 0x52, 0x6b, 0xa8, 0x5e, 0xf9, 0x94, 0x77,
  37375. 0x37, 0x8b, 0x4d, 0xc7, 0x66, 0x35, 0xa5, 0xcd,
  37376. 0x50, 0x40, 0xe4, 0x3b, 0x8c, 0x1f, 0xe4, 0xee,
  37377. 0x5e, 0x15, 0x8e, 0x42, 0x3b, 0xfc, 0x0c, 0x89,
  37378. 0x3c, 0x1d, 0x56, 0x13, 0xbe, 0xd0, 0x8d, 0xa7,
  37379. 0x19, 0xc9, 0x07, 0x31, 0x84, 0xee, 0xb3, 0x6f,
  37380. 0xd3, 0x57, 0x38, 0x0f, 0xb1, 0x87, 0x3d, 0x8c,
  37381. 0xbd, 0x36, 0xe2, 0x25, 0x5e, 0x98, 0x5b, 0x1b,
  37382. 0x76, 0x81, 0x97, 0x43, 0xa6, 0x58, 0x4a, 0x9b,
  37383. 0x3a, 0x58, 0x09, 0x96, 0xc9, 0xc2, 0xee, 0xd9,
  37384. 0xbb, 0xbf, 0xff, 0x78, 0xa6, 0x20, 0x4b, 0x5e,
  37385. 0x5e, 0xea, 0xe5, 0xf4, 0xef, 0xd2, 0x66, 0x00,
  37386. 0x78, 0xb3, 0x7f, 0x07, 0x54, 0xab, 0x5d, 0xa8,
  37387. 0x62, 0xe6, 0x66, 0xb1, 0x45, 0xb5, 0xf2, 0x3f,
  37388. 0x3d, 0x09, 0x77, 0x79, 0x99, 0x29, 0xdf, 0xa2,
  37389. 0xae, 0xdd, 0xa5, 0x3d, 0x15, 0x2e, 0xda, 0x1d,
  37390. 0x0d, 0x0e, 0x4e, 0xa4, 0x3f, 0x6e, 0xd8, 0x89,
  37391. 0xbb, 0x96, 0x5e, 0xef, 0xe0, 0xa7, 0xc6, 0x85,
  37392. 0xbb, 0x36, 0x77, 0x0e, 0xaa, 0x87, 0x42, 0x42,
  37393. 0xc0, 0xe2, 0x29, 0xcf, 0x6c, 0xe5, 0x6d, 0xef,
  37394. 0xa5, 0xae, 0xae, 0x64, 0xd0, 0xc4, 0x0d, 0xda,
  37395. 0x8a, 0xa2, 0x6e, 0xae, 0xb3, 0x14, 0x58, 0xf0,
  37396. 0x70, 0xa3, 0xbc, 0x72, 0xe1, 0x61, 0x9e, 0xe9,
  37397. 0xb5, 0xf6, 0x42, 0x29, 0x1c, 0x56, 0xdf, 0x5b,
  37398. 0x7e, 0x43, 0xdb, 0x6c, 0x80, 0x2f, 0xc7, 0x4f,
  37399. 0x4f, 0x3f, 0x9b, 0x5c, 0x0d, 0x35, 0x5c, 0x3a,
  37400. 0xae, 0x52, 0x0a, 0xa3, 0x12, 0x29, 0xd1, 0x2f,
  37401. 0x3e, 0x7c, 0xc5, 0xd4, 0x8e, 0x69, 0x11, 0x91,
  37402. 0xa3, 0x6b, 0x28, 0x37, 0x65, 0xf4, 0x13, 0x3f,
  37403. 0x0f, 0xf1, 0xfe, 0x2f, 0x01, 0xc6, 0x64, 0x8b,
  37404. 0x27, 0x98, 0xa7, 0x4e, 0xb5, 0xd8, 0x42, 0xa2,
  37405. 0x48, 0xf5, 0x24, 0xa7, 0xe7, 0xf8, 0x97, 0x42,
  37406. 0x11, 0x29, 0x7b, 0x44, 0xf0, 0xdd, 0x19, 0xf3,
  37407. 0x86, 0xe8, 0x6b, 0xe6, 0xba, 0x78, 0x2d, 0xe7,
  37408. 0x7f, 0xde, 0x88, 0x72, 0x26, 0xf3, 0x7a, 0x1c,
  37409. 0x77, 0xbc, 0x5e, 0xdd, 0xee, 0xe5, 0xbf, 0x46,
  37410. 0xb6, 0x7f, 0xb7, 0x47, 0x8d, 0x55, 0x98, 0x65,
  37411. 0xf2, 0x62, 0xca, 0xa8, 0x4d, 0x64, 0xa8, 0xce,
  37412. 0x59, 0xe4, 0xdf, 0x08, 0x18, 0xe1, 0x48, 0x61,
  37413. 0x52, 0x6a, 0xcd, 0x34, 0x83, 0x60, 0x0f, 0x3d,
  37414. 0xae, 0x79, 0x59, 0xd3, 0x5d, 0x81, 0x81, 0xca,
  37415. 0x6a, 0x81, 0xce, 0x79, 0x1b, 0xe0, 0x07, 0x52,
  37416. 0xda, 0x77, 0x59, 0x44, 0x6a, 0x2c, 0xfb, 0xe0,
  37417. 0x0b, 0x82, 0x48, 0xb9, 0x34, 0x91, 0xde, 0xbd,
  37418. 0x52, 0x02, 0x20, 0xb7, 0x55, 0x41, 0x6d, 0x2f,
  37419. 0xc6, 0xb7, 0xc8, 0xaf, 0x2f, 0xf7, 0x5e, 0x5b,
  37420. 0xcb, 0xb8, 0xe7, 0x53, 0x73, 0x80, 0xa5, 0x72,
  37421. 0x1c, 0x77, 0x48, 0x49, 0x57, 0xa6, 0x92, 0x71,
  37422. 0xd8, 0xba, 0xfc, 0xe0, 0xf1, 0x66, 0x73, 0x5f,
  37423. 0xf8, 0x69, 0x23, 0x2d, 0xe5, 0xd3, 0x81, 0xaf,
  37424. 0xbf, 0x0e, 0x44, 0xd6, 0x91, 0x72, 0xb7, 0x9a,
  37425. 0x35, 0x19, 0x19, 0x49, 0xde, 0x09, 0x70, 0x3b,
  37426. 0x94, 0x22, 0x2b, 0x13, 0xc3, 0x85, 0xc6, 0x08,
  37427. 0x1e, 0x6d, 0x2e, 0xde, 0x1e, 0x57, 0xfe, 0x18,
  37428. 0x4e, 0xf8, 0xf6, 0x01, 0x96, 0xb9, 0xa3, 0xa7,
  37429. 0xb7, 0xef, 0xf7, 0x49, 0x71, 0x91, 0xca, 0x87,
  37430. 0x41, 0xb5, 0xa0, 0x1e, 0x79, 0xcb, 0x69, 0xa6,
  37431. 0x11, 0x42, 0xe6, 0xf5, 0xd0, 0x80, 0xfb, 0xb3,
  37432. 0xe5, 0x66, 0xf7, 0x9e, 0x14, 0x6f, 0x75, 0xc8,
  37433. 0xa1, 0x09, 0x78, 0x60, 0x84, 0x1b, 0x47, 0x47,
  37434. 0xdf, 0x60, 0x4d, 0xba, 0x95, 0x4e, 0x4a, 0x8d,
  37435. 0x9e, 0x0d, 0xcc, 0xc1, 0xf6, 0x09, 0xd0, 0x5c,
  37436. 0xf8, 0xd3, 0x12, 0x19, 0xec, 0xd6, 0x0c, 0x31,
  37437. 0x2d, 0xe6, 0x84, 0x55, 0x2f, 0x09, 0x22, 0x7c,
  37438. 0xb8, 0x29, 0x29, 0x1c, 0x64, 0x57, 0x32, 0xc5,
  37439. 0xf5, 0xd4, 0xd7, 0x11, 0x63, 0x9f, 0x42, 0xa2,
  37440. 0x30, 0x80, 0xaa, 0x34, 0xfe, 0x14, 0x20, 0xf2,
  37441. 0x19, 0xbd, 0x6b, 0xcf, 0x4e, 0x3b, 0x29, 0xb9,
  37442. 0xd0, 0x22, 0x93, 0xb2, 0xda, 0x81, 0x38, 0x3e,
  37443. 0x0a, 0x51, 0xd2, 0xbb, 0x18, 0x6c, 0x7b, 0x0a,
  37444. 0x21, 0x1a, 0x0c, 0xd6, 0x3a, 0xcb, 0xfc, 0x02,
  37445. 0x10, 0x40, 0x1e, 0x98, 0x5d, 0x43, 0x6b, 0x38,
  37446. 0x03, 0xd5, 0x60, 0x1c, 0x24, 0x13, 0x6a, 0xfd,
  37447. 0x15, 0x62, 0x52, 0x2e, 0x45, 0xb4, 0x57, 0xcb,
  37448. 0x43, 0x91, 0x78, 0xbe, 0x4a, 0x87, 0xcc, 0xe4,
  37449. 0x03, 0x46, 0xd3, 0x4a, 0xe0, 0xf3, 0xc3, 0x91,
  37450. 0x03, 0xc8, 0xa3, 0xeb, 0xc9, 0xc8, 0x6c, 0x8d,
  37451. 0xb8, 0xfc, 0x55, 0x61, 0xeb, 0x0f, 0x3a, 0x14,
  37452. 0x3d, 0x4e, 0x9f, 0xe9, 0x3a, 0x5c, 0xba, 0x6f,
  37453. 0x6f, 0xca, 0xe5, 0x65, 0x0d, 0x3f, 0x43, 0xd2,
  37454. 0x66, 0x8a, 0x59, 0x56, 0xc9, 0x22, 0x89, 0x3b,
  37455. 0x81, 0x66, 0x47, 0xde, 0xd0, 0xaf, 0xc0, 0x52,
  37456. 0xa6, 0xc3, 0xd9, 0xd0, 0x1a, 0x3d, 0x3a, 0xf0,
  37457. 0xf1, 0xba, 0x80, 0x7f, 0xf1, 0x04, 0x91, 0xe1,
  37458. 0x31, 0xdc, 0x15, 0xe1, 0x65, 0xcf, 0xd0, 0x65,
  37459. 0x0a, 0x1f, 0x2c, 0x31, 0x3d, 0x79, 0x56, 0x14,
  37460. 0x1e, 0xdc, 0xc6, 0x1c, 0xb9, 0x0e, 0x9e, 0x7a,
  37461. 0xbf, 0x2f, 0xe3, 0x5f, 0xc9, 0xdc, 0x1b, 0xde,
  37462. 0x88, 0x93, 0x9f, 0xa1, 0x1f, 0x7b, 0xbe, 0x3e,
  37463. 0xb4, 0xd8, 0xff, 0xa6, 0x43, 0xb0, 0x74, 0xd7,
  37464. 0x4f, 0x45, 0x11, 0x35, 0x86, 0xe9, 0xbb, 0x12,
  37465. 0x06, 0x00, 0x03, 0xd7, 0x19, 0x41, 0xf2, 0xda,
  37466. 0x09, 0x8d, 0xc0, 0xe9, 0x6c, 0xad, 0x32, 0x55,
  37467. 0xcf, 0x32, 0x8e, 0xa2, 0xd3, 0x30, 0x8c, 0x1f,
  37468. 0x45, 0x85, 0xe8, 0x9c, 0x61, 0x3c, 0x42, 0x6b,
  37469. 0x7e, 0x79, 0x8e, 0x1e, 0xc4, 0xe9, 0x8f, 0xe6,
  37470. 0xc7, 0x1e, 0x74, 0x91, 0xf5, 0xec, 0xa0, 0xcd,
  37471. 0x05, 0x11, 0x58, 0x61, 0xbd, 0x16, 0x0e, 0x3f,
  37472. 0xe7, 0x3a, 0x58, 0xa0, 0x26, 0xba, 0x53, 0x8e,
  37473. 0x0e, 0x25, 0x6b, 0x92, 0xf1, 0xd7, 0xa2, 0x49,
  37474. 0x75, 0x70, 0x59, 0x48, 0x56, 0x86, 0x0f, 0xfd,
  37475. 0x06, 0xb6, 0x01, 0xac, 0x57, 0x55, 0x92, 0xf4,
  37476. 0xac, 0x61, 0x2b, 0x5d, 0xe7, 0x86, 0x60, 0x42,
  37477. 0x12, 0x3e, 0xbc, 0x60, 0xc5, 0x57, 0x68, 0xe3,
  37478. 0xa7, 0x60, 0x0a, 0x32, 0x60, 0x55, 0x1f, 0x2b,
  37479. 0xea, 0x22, 0xbb, 0xf6, 0xb6, 0xc8, 0x24, 0x6e,
  37480. 0x80, 0xf9, 0x12, 0x5c, 0x4b, 0xb9, 0xdb, 0x35,
  37481. 0x4d, 0xd6, 0x4a, 0xe6, 0x95, 0xc1, 0x5f, 0x50,
  37482. 0x71, 0xf4, 0xab, 0xb9, 0x63, 0x92, 0x07, 0xca,
  37483. 0xc7, 0x33, 0x1b, 0x31, 0x0f, 0x69, 0xa0, 0x5f,
  37484. 0x54, 0xb9, 0x95, 0xde, 0x52, 0x9a, 0x02, 0x3f,
  37485. 0x03, 0x3b, 0x05, 0x5d, 0xb9, 0x52, 0x87, 0xa1,
  37486. 0x4b, 0xa3, 0x0a, 0x7c, 0xc5, 0x26, 0xbb, 0x72,
  37487. 0x4c, 0x41, 0x7f, 0xba, 0x29, 0x06, 0x36, 0xa9,
  37488. 0x96, 0xf2, 0x86, 0xe3, 0xe9, 0xe9, 0x39, 0xe4,
  37489. 0xfe, 0x1c, 0x39, 0x8b, 0x5c, 0x65, 0x99, 0x95,
  37490. 0x9d, 0x0b, 0x44, 0x45, 0xa3, 0x27, 0xec, 0x46,
  37491. 0x9a, 0x16, 0x53, 0xcf, 0xae, 0xa7, 0x55, 0x2c,
  37492. 0xec, 0xec, 0x08, 0x5c, 0xca, 0xa6, 0x89, 0x38,
  37493. 0xae, 0x4a, 0xc3, 0xc4, 0x24, 0xf7, 0xe4, 0x80,
  37494. 0x43, 0x9e, 0xbd, 0x2c, 0x99, 0x2b, 0x5f, 0x6f,
  37495. 0x95, 0xec, 0x24, 0x4b, 0x65, 0x7d, 0xbd, 0xea,
  37496. 0xa9, 0xae, 0x11, 0x0a, 0xaf, 0x4d, 0x68, 0xbf,
  37497. 0x4e, 0x27, 0x41, 0x0d, 0x43, 0xce, 0xef, 0x3e,
  37498. 0x88, 0xe9, 0xc7, 0x17, 0xdd, 0x44, 0xc9, 0xee
  37499. #endif
  37500. };
  37501. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ss[] = {
  37502. #ifdef WOLFSSL_KYBER_ORIGINAL
  37503. 0xB1, 0x0F, 0x73, 0x94, 0x92, 0x6A, 0xD3, 0xB4,
  37504. 0x9C, 0x5D, 0x62, 0xD5, 0xAE, 0xB5, 0x31, 0xD5,
  37505. 0x75, 0x75, 0x38, 0xBC, 0xC0, 0xDA, 0x9E, 0x55,
  37506. 0x0D, 0x43, 0x8F, 0x1B, 0x61, 0xBD, 0x74, 0x19
  37507. #else
  37508. 0x48, 0x9d, 0xd1, 0xe9, 0xc2, 0xbe, 0x4a, 0xf3,
  37509. 0x48, 0x2b, 0xdb, 0x35, 0xbb, 0x26, 0xce, 0x76,
  37510. 0x0e, 0x6e, 0x41, 0x4d, 0xa6, 0xec, 0xbe, 0x48,
  37511. 0x99, 0x85, 0x74, 0x8a, 0x82, 0x5f, 0x1c, 0xd6
  37512. #endif
  37513. };
  37514. #ifdef WOLFSSL_SMALL_STACK
  37515. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37516. DYNAMIC_TYPE_TMP_BUFFER);
  37517. priv = (byte *)XMALLOC(KYBER1024_PRIVATE_KEY_SIZE, HEAP_HINT,
  37518. DYNAMIC_TYPE_TMP_BUFFER);
  37519. pub = (byte *)XMALLOC(KYBER1024_PUBLIC_KEY_SIZE, HEAP_HINT,
  37520. DYNAMIC_TYPE_TMP_BUFFER);
  37521. ct = (byte *)XMALLOC(KYBER1024_CIPHER_TEXT_SIZE, HEAP_HINT,
  37522. DYNAMIC_TYPE_TMP_BUFFER);
  37523. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37524. DYNAMIC_TYPE_TMP_BUFFER);
  37525. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37526. DYNAMIC_TYPE_TMP_BUFFER);
  37527. if (! (key && priv && pub && ct && ss && ss_dec))
  37528. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37529. #endif
  37530. ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
  37531. if (ret != 0)
  37532. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37533. else
  37534. key_inited = 1;
  37535. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  37536. sizeof(kyber1024_rand));
  37537. if (ret != 0)
  37538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37539. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
  37540. if (ret != 0)
  37541. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37542. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
  37543. if (ret != 0)
  37544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37545. if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0)
  37546. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37547. if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
  37548. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37549. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  37550. sizeof(kyber1024enc_rand));
  37551. if (ret != 0)
  37552. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37553. if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0)
  37554. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37555. if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  37556. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37557. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
  37558. if (ret != 0)
  37559. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37560. if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  37561. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37562. out:
  37563. if (key_inited)
  37564. wc_KyberKey_Free(key);
  37565. #ifdef WOLFSSL_SMALL_STACK
  37566. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37567. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37568. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37569. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37570. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37571. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37572. #endif
  37573. return ret;
  37574. }
  37575. #endif /* WOLFSSL_KYBER1024 */
  37576. #endif /* WOLFSSL_WC_KYBER */
  37577. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
  37578. {
  37579. wc_test_ret_t ret;
  37580. WC_RNG rng;
  37581. int i;
  37582. #ifdef WOLFSSL_SMALL_STACK
  37583. KyberKey *key = NULL;
  37584. byte *priv = NULL;
  37585. byte *pub = NULL;
  37586. byte *priv2 = NULL;
  37587. byte *pub2 = NULL;
  37588. byte *ct = NULL;
  37589. byte *ss = NULL;
  37590. byte *ss_dec = NULL;
  37591. #else
  37592. KyberKey key[1];
  37593. byte priv[KYBER_MAX_PRIVATE_KEY_SIZE];
  37594. byte pub[KYBER_MAX_PUBLIC_KEY_SIZE];
  37595. byte priv2[KYBER_MAX_PRIVATE_KEY_SIZE];
  37596. byte pub2[KYBER_MAX_PUBLIC_KEY_SIZE];
  37597. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  37598. byte ss[KYBER_SS_SZ];
  37599. byte ss_dec[KYBER_SS_SZ];
  37600. #endif
  37601. int key_inited = 0;
  37602. static const int testData[][4] = {
  37603. #ifdef WOLFSSL_KYBER512
  37604. { KYBER512, KYBER512_PRIVATE_KEY_SIZE, KYBER512_PUBLIC_KEY_SIZE,
  37605. KYBER512_CIPHER_TEXT_SIZE },
  37606. #endif
  37607. #ifdef WOLFSSL_KYBER768
  37608. { KYBER768, KYBER768_PRIVATE_KEY_SIZE, KYBER768_PUBLIC_KEY_SIZE,
  37609. KYBER768_CIPHER_TEXT_SIZE },
  37610. #endif
  37611. #ifdef WOLFSSL_KYBER1024
  37612. { KYBER1024, KYBER1024_PRIVATE_KEY_SIZE, KYBER1024_PUBLIC_KEY_SIZE,
  37613. KYBER1024_CIPHER_TEXT_SIZE },
  37614. #endif
  37615. };
  37616. WOLFSSL_ENTER("kyber_test");
  37617. #ifdef WOLFSSL_SMALL_STACK
  37618. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37619. DYNAMIC_TYPE_TMP_BUFFER);
  37620. priv = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  37621. DYNAMIC_TYPE_TMP_BUFFER);
  37622. pub = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  37623. DYNAMIC_TYPE_TMP_BUFFER);
  37624. priv2 = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  37625. DYNAMIC_TYPE_TMP_BUFFER);
  37626. pub2 = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  37627. DYNAMIC_TYPE_TMP_BUFFER);
  37628. ct = (byte *)XMALLOC(KYBER_MAX_CIPHER_TEXT_SIZE, HEAP_HINT,
  37629. DYNAMIC_TYPE_TMP_BUFFER);
  37630. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37631. DYNAMIC_TYPE_TMP_BUFFER);
  37632. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37633. DYNAMIC_TYPE_TMP_BUFFER);
  37634. if (! (key && priv && pub && priv2 && pub2 && ct && ss && ss_dec))
  37635. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37636. #endif
  37637. #ifndef HAVE_FIPS
  37638. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  37639. #else
  37640. ret = wc_InitRng(&rng);
  37641. #endif
  37642. if (ret != 0)
  37643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37644. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  37645. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  37646. if (ret != 0)
  37647. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37648. else
  37649. key_inited = 1;
  37650. ret = wc_KyberKey_MakeKey(key, &rng);
  37651. if (ret != 0)
  37652. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37653. ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
  37654. if (ret != 0)
  37655. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37656. ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
  37657. if (ret != 0)
  37658. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37659. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  37660. if (ret != 0)
  37661. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37662. ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
  37663. if (ret != 0)
  37664. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37665. ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
  37666. if (ret != 0)
  37667. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37668. ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
  37669. if (ret != 0)
  37670. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37671. if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
  37672. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37673. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  37674. if (ret != 0)
  37675. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37676. ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
  37677. if (ret != 0)
  37678. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37679. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
  37680. if (ret != 0)
  37681. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37682. if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
  37683. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37684. ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
  37685. if (ret != 0)
  37686. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37687. if (XMEMCMP(priv, priv2, testData[i][2]) != 0)
  37688. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37689. }
  37690. wc_FreeRng(&rng);
  37691. #ifdef WOLFSSL_WC_KYBER
  37692. #ifdef WOLFSSL_KYBER512
  37693. ret = kyber512_kat();
  37694. if (ret != 0)
  37695. goto out;
  37696. #endif
  37697. #ifdef WOLFSSL_KYBER768
  37698. ret = kyber768_kat();
  37699. if (ret != 0)
  37700. goto out;
  37701. #endif
  37702. #ifdef WOLFSSL_KYBER1024
  37703. ret = kyber1024_kat();
  37704. if (ret != 0)
  37705. goto out;
  37706. #endif
  37707. #endif /* WOLFSSL_WC_KYBER */
  37708. out:
  37709. if (key_inited)
  37710. wc_KyberKey_Free(key);
  37711. #ifdef WOLFSSL_SMALL_STACK
  37712. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37713. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37714. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37715. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37716. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37717. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37718. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37719. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37720. #endif
  37721. return ret;
  37722. }
  37723. #endif /* WOLFSSL_HAVE_KYBER */
  37724. #ifdef HAVE_DILITHIUM
  37725. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  37726. static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
  37727. word32 pubKeyLen, const byte* sig, word32 sigLen)
  37728. {
  37729. byte msg[512];
  37730. dilithium_key* key;
  37731. wc_test_ret_t ret;
  37732. int i;
  37733. int res = 0;
  37734. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  37735. DYNAMIC_TYPE_TMP_BUFFER);
  37736. if (key == NULL) {
  37737. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37738. }
  37739. /* make dummy msg */
  37740. for (i = 0; i < (int)sizeof(msg); i++) {
  37741. msg[i] = (byte)i;
  37742. }
  37743. ret = wc_dilithium_init(key);
  37744. if (ret != 0) {
  37745. ret = WC_TEST_RET_ENC_EC(ret);
  37746. return ret;
  37747. }
  37748. ret = wc_dilithium_set_level(key, param);
  37749. if (ret != 0)
  37750. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37751. ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
  37752. if (ret != 0)
  37753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37754. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  37755. ret = wc_dilithium_verify_ctx_msg(sig, sigLen, NULL, 0, msg,
  37756. (word32)sizeof(msg), &res, key);
  37757. #else
  37758. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  37759. key);
  37760. #endif
  37761. if (ret != 0)
  37762. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37763. if (res != 1)
  37764. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  37765. out:
  37766. wc_dilithium_free(key);
  37767. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37768. return ret;
  37769. }
  37770. #ifndef WOLFSSL_NO_ML_DSA_44
  37771. static wc_test_ret_t dilithium_param_44_vfy_test(void)
  37772. {
  37773. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_pub_key[] = {
  37774. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  37775. 0xd8, 0xac, 0xaf, 0xd8, 0x2e, 0x14, 0x23, 0x78, 0xf7, 0x0d, 0x9a, 0x04,
  37776. 0x2b, 0x92, 0x48, 0x67, 0x60, 0x55, 0x34, 0xd9, 0xac, 0x0b, 0xc4, 0x1f,
  37777. 0x46, 0xe8, 0x85, 0xb9, 0x2e, 0x1b, 0x10, 0x3a, 0x75, 0x7a, 0xc2, 0xbc,
  37778. 0x76, 0xf0, 0x6d, 0x05, 0xa4, 0x78, 0x48, 0x84, 0x26, 0x69, 0xbd, 0x26,
  37779. 0x1d, 0x73, 0x60, 0xaa, 0x57, 0x9d, 0x8c, 0x66, 0xb1, 0x19, 0xea, 0x11,
  37780. 0xff, 0xbb, 0xf6, 0xeb, 0x26, 0x26, 0xac, 0x78, 0x74, 0x46, 0x6d, 0x51,
  37781. 0x6e, 0x92, 0xdf, 0x6a, 0x98, 0x41, 0xe9, 0x10, 0xf2, 0xcc, 0xa8, 0x7a,
  37782. 0x50, 0xdb, 0x1f, 0x4c, 0x42, 0x19, 0xd5, 0xbc, 0x76, 0x20, 0x6f, 0x2f,
  37783. 0xbf, 0xc2, 0xc9, 0x1b, 0x02, 0xb5, 0xb1, 0x09, 0x46, 0x06, 0x87, 0x02,
  37784. 0xac, 0x3d, 0xcf, 0xc3, 0xa5, 0x1b, 0xf0, 0xce, 0xd4, 0x9e, 0x84, 0x34,
  37785. 0x3c, 0x24, 0x7d, 0x89, 0xf3, 0xbf, 0x9c, 0x18, 0x9d, 0x1b, 0x1d, 0xd4,
  37786. 0xf6, 0xda, 0xc9, 0xa4, 0x14, 0xc4, 0x6b, 0xd7, 0x05, 0x6d, 0xed, 0x54,
  37787. 0x42, 0x6b, 0x5f, 0x6d, 0x1e, 0xda, 0x6b, 0x47, 0x70, 0xe5, 0x4e, 0xe7,
  37788. 0x25, 0x06, 0xf8, 0x28, 0x24, 0x34, 0xd6, 0xe5, 0xbe, 0xc5, 0x4f, 0x9e,
  37789. 0x5d, 0x33, 0xfc, 0xef, 0xe4, 0xe9, 0x55, 0x67, 0x93, 0x1f, 0x2e, 0x11,
  37790. 0x3a, 0x2e, 0xf2, 0xbb, 0x82, 0x09, 0x8d, 0xb2, 0x09, 0xf3, 0x2f, 0xef,
  37791. 0x6f, 0x38, 0xc6, 0x56, 0xf2, 0x23, 0x08, 0x63, 0x99, 0x7f, 0x4e, 0xc0,
  37792. 0x9d, 0x08, 0x9d, 0xa1, 0x59, 0x6e, 0xe1, 0x00, 0x2c, 0x99, 0xec, 0x83,
  37793. 0x2f, 0x12, 0x97, 0x2f, 0x75, 0x04, 0x67, 0x44, 0xb5, 0x95, 0xce, 0xc6,
  37794. 0x3e, 0x7a, 0x10, 0x77, 0x5e, 0xbe, 0x9c, 0x0f, 0xb3, 0xc7, 0x38, 0xbf,
  37795. 0x9e, 0x35, 0x8f, 0xe4, 0x8d, 0x19, 0xc3, 0x41, 0xb1, 0x0b, 0x8c, 0x10,
  37796. 0x9a, 0x58, 0xec, 0x4f, 0xb3, 0xe9, 0x5b, 0x72, 0x4b, 0xb8, 0x99, 0x34,
  37797. 0x9a, 0xcd, 0xb0, 0x69, 0xd0, 0x67, 0xef, 0x96, 0xb9, 0xe5, 0x54, 0x92,
  37798. 0xb7, 0x1a, 0x52, 0xf6, 0x0a, 0xc2, 0x23, 0x8d, 0x4f, 0xad, 0x00, 0xae,
  37799. 0x0f, 0x97, 0xfa, 0xce, 0x96, 0xba, 0xe7, 0x74, 0x55, 0xd4, 0xaf, 0xbf,
  37800. 0xa1, 0x32, 0x91, 0x2d, 0x03, 0x9f, 0xe3, 0x10, 0x8c, 0x77, 0x5d, 0x26,
  37801. 0x76, 0xf1, 0x87, 0x90, 0xf0, 0x20, 0xd1, 0xea, 0xf7, 0xa4, 0xe8, 0x2c,
  37802. 0x32, 0x1c, 0x55, 0xc0, 0x5d, 0xc9, 0xcd, 0x4e, 0x8f, 0x0d, 0xef, 0x0a,
  37803. 0x27, 0xb6, 0x4f, 0xa4, 0xd3, 0xa4, 0xed, 0x33, 0x22, 0xa1, 0xd3, 0x15,
  37804. 0xac, 0x1a, 0x20, 0x4e, 0x28, 0x8c, 0x8c, 0xd0, 0x71, 0xd1, 0xf2, 0xdb,
  37805. 0x33, 0x63, 0xb6, 0xa4, 0xf2, 0x17, 0x3c, 0x12, 0xb0, 0xad, 0xef, 0x31,
  37806. 0x91, 0xfe, 0xe5, 0x53, 0x99, 0xb6, 0x85, 0x63, 0xfa, 0xe6, 0xcd, 0xf6,
  37807. 0xb9, 0xce, 0x4a, 0x7d, 0x4a, 0x49, 0x29, 0xd2, 0xd9, 0xc9, 0x47, 0x4a,
  37808. 0x8a, 0x5c, 0x14, 0x5e, 0x0f, 0x7c, 0xc3, 0x91, 0xb0, 0xab, 0x37, 0xf5,
  37809. 0x26, 0x8d, 0x46, 0x74, 0x49, 0xad, 0x51, 0xc3, 0x11, 0xfa, 0x85, 0x15,
  37810. 0xa5, 0x84, 0xc1, 0xe0, 0x3c, 0x13, 0x6d, 0x13, 0xa3, 0xe6, 0xa8, 0x3c,
  37811. 0x22, 0xac, 0x17, 0x48, 0x57, 0x7c, 0x81, 0xe2, 0x4e, 0xd8, 0x33, 0x5d,
  37812. 0x4d, 0x65, 0xf7, 0xe1, 0xb8, 0x00, 0x78, 0x09, 0x16, 0xb0, 0x0b, 0xca,
  37813. 0x15, 0x0d, 0xcd, 0x9a, 0xd8, 0x47, 0x4c, 0x9b, 0x69, 0xb2, 0xa0, 0x9d,
  37814. 0x96, 0x96, 0x52, 0x6d, 0x89, 0xad, 0xff, 0x55, 0xde, 0x7b, 0xd6, 0x3d,
  37815. 0x1d, 0x5e, 0x8d, 0xf1, 0xfc, 0x48, 0x1c, 0x50, 0x59, 0x55, 0xb9, 0x07,
  37816. 0xfd, 0x6b, 0xcb, 0x95, 0xa6, 0x14, 0x73, 0xdb, 0x40, 0x40, 0x1c, 0x44,
  37817. 0xe6, 0x79, 0x30, 0x88, 0xbd, 0xa0, 0xde, 0x9b, 0xb8, 0x76, 0xf8, 0x98,
  37818. 0x56, 0x4b, 0xb9, 0x7a, 0xf6, 0xd4, 0x73, 0x89, 0x6b, 0xf7, 0x7d, 0x05,
  37819. 0x33, 0xbe, 0xb6, 0x1c, 0x4d, 0xa7, 0x12, 0x3b, 0x3f, 0xed, 0x4a, 0x0f,
  37820. 0xae, 0xa7, 0x6a, 0x26, 0x0d, 0x01, 0x84, 0x84, 0xa8, 0x0e, 0xc1, 0xc1,
  37821. 0xfd, 0xe4, 0xa9, 0xe2, 0x3f, 0xab, 0xce, 0x20, 0x90, 0x86, 0x79, 0xa2,
  37822. 0x40, 0xd0, 0xef, 0x79, 0x34, 0x2b, 0xe8, 0xc9, 0x54, 0xa7, 0x19, 0x62,
  37823. 0xcc, 0x20, 0x79, 0x3f, 0x5b, 0x9c, 0x61, 0xc2, 0xc1, 0xd2, 0x36, 0x7c,
  37824. 0x8e, 0xe3, 0x01, 0xbe, 0xc4, 0xb2, 0xb8, 0x07, 0x51, 0x23, 0x5b, 0x5d,
  37825. 0x00, 0xe6, 0x7f, 0xd6, 0xbb, 0x32, 0xa9, 0x7e, 0xb4, 0x30, 0xeb, 0x5e,
  37826. 0x6d, 0xed, 0xb2, 0xc3, 0x88, 0x81, 0xa3, 0x3b, 0x1f, 0x1e, 0xf9, 0x48,
  37827. 0x10, 0xd6, 0x01, 0x65, 0x5f, 0x6d, 0xc5, 0xeb, 0x76, 0x5f, 0x10, 0x79,
  37828. 0xaa, 0xc0, 0x86, 0xe7, 0x44, 0x95, 0x44, 0x4b, 0x54, 0x0c, 0x46, 0x2a,
  37829. 0x98, 0x01, 0x6e, 0xc0, 0xb9, 0x59, 0x2a, 0xff, 0x8f, 0xb3, 0x80, 0x15,
  37830. 0xec, 0xcd, 0x39, 0x36, 0xd7, 0x2f, 0x20, 0x9e, 0x3a, 0xc1, 0x90, 0xe5,
  37831. 0x99, 0x27, 0x16, 0xd7, 0x6c, 0x30, 0x10, 0x12, 0x03, 0x3e, 0xdc, 0xb9,
  37832. 0x03, 0x25, 0xb0, 0x8a, 0x27, 0x4d, 0x1a, 0x32, 0x36, 0x54, 0xc0, 0xba,
  37833. 0x22, 0xb2, 0xe2, 0xf6, 0x39, 0x23, 0x03, 0xc4, 0xc9, 0xe4, 0x0d, 0x99,
  37834. 0xfb, 0x98, 0xa5, 0x9b, 0x12, 0x9b, 0x58, 0x44, 0x74, 0x9f, 0x65, 0x61,
  37835. 0x51, 0xba, 0x31, 0x60, 0x9c, 0xec, 0xf8, 0x4d, 0x36, 0x61, 0xd1, 0x33,
  37836. 0x6d, 0xa6, 0x28, 0x75, 0xba, 0x7c, 0x82, 0xcb, 0x7e, 0xbe, 0x8f, 0x2d,
  37837. 0x21, 0x84, 0xb9, 0xf2, 0x4e, 0x7b, 0x95, 0x99, 0x11, 0xf3, 0xe1, 0xc0,
  37838. 0x6a, 0x44, 0xae, 0x11, 0xcb, 0x04, 0xa0, 0xf2, 0x3e, 0x17, 0xdf, 0xb2,
  37839. 0x6a, 0xdf, 0x5c, 0xf3, 0x8a, 0xf8, 0x90, 0x86, 0x64, 0xea, 0x0a, 0x32,
  37840. 0x7f, 0x9f, 0x90, 0xa8, 0x9d, 0x33, 0x12, 0xa6, 0xa4, 0xe7, 0x74, 0xa0,
  37841. 0x75, 0xa9, 0x65, 0xf8, 0x39, 0xae, 0x14, 0x32, 0x79, 0xcc, 0xaa, 0x34,
  37842. 0x86, 0x55, 0xcc, 0x99, 0xb7, 0x00, 0x05, 0x8b, 0xe3, 0x76, 0x28, 0x12,
  37843. 0xb6, 0x2a, 0x3e, 0x44, 0x8d, 0xf4, 0xba, 0xef, 0xf6, 0xdc, 0x29, 0x08,
  37844. 0x29, 0x7d, 0xd1, 0x1d, 0x17, 0x15, 0xb6, 0xb6, 0x58, 0x67, 0xd5, 0xd3,
  37845. 0x12, 0x05, 0x4e, 0xb0, 0xc3, 0x83, 0xe0, 0x35, 0x30, 0x60, 0x59, 0xa0,
  37846. 0xc5, 0x97, 0x5b, 0x81, 0xd3, 0x68, 0x6c, 0x8c, 0x17, 0x28, 0xa9, 0x24,
  37847. 0x4f, 0x80, 0x20, 0xa5, 0x21, 0x9f, 0x8f, 0x15, 0x89, 0x2d, 0x87, 0xae,
  37848. 0x2e, 0xcc, 0x73, 0x3e, 0x06, 0x43, 0xbc, 0xb3, 0x1b, 0xa6, 0x72, 0xaa,
  37849. 0xa3, 0xaa, 0xbb, 0x6f, 0x2d, 0x68, 0x60, 0xcf, 0x05, 0x94, 0x25, 0x3e,
  37850. 0x59, 0xf3, 0x64, 0x61, 0x5e, 0x78, 0x9a, 0x7e, 0x0d, 0x50, 0x45, 0x78,
  37851. 0x51, 0xab, 0x11, 0xb1, 0xc6, 0x95, 0xfc, 0x29, 0x28, 0x10, 0x9c, 0x1a,
  37852. 0x8c, 0x37, 0xb5, 0x4f, 0x0e, 0xed, 0x4a, 0x28, 0x6c, 0xaa, 0xb7, 0x0d,
  37853. 0x12, 0xfa, 0x87, 0x5d, 0xd4, 0x9a, 0xb7, 0x2b, 0x46, 0x90, 0x58, 0x4e,
  37854. 0xd7, 0x8b, 0x41, 0x1b, 0xf8, 0xc4, 0xc2, 0xde, 0xda, 0xec, 0x61, 0xe7,
  37855. 0xbf, 0x11, 0xdd, 0x6e, 0x4e, 0x6a, 0xd4, 0x87, 0x01, 0xe4, 0xac, 0xe8,
  37856. 0xaf, 0x2b, 0x01, 0xe1, 0x09, 0x20, 0xe0, 0xbd, 0x7d, 0x03, 0x73, 0x23,
  37857. 0xdf, 0x77, 0x71, 0xa4, 0x25, 0x8b, 0x0a, 0x93, 0x49, 0x32, 0x45, 0x1a,
  37858. 0xa4, 0x94, 0x31, 0x61, 0x2e, 0x17, 0x39, 0x8a, 0x66, 0xc9, 0xf9, 0x20,
  37859. 0x2d, 0x6a, 0x97, 0x2f, 0xe7, 0x26, 0xd8, 0x01, 0x42, 0x65, 0xcf, 0xce,
  37860. 0xd4, 0x24, 0x41, 0xfb, 0x9b, 0x6f, 0xf1, 0xc2, 0x9e, 0xd5, 0x08, 0x0c,
  37861. 0xdc, 0x4d, 0x8e, 0xae, 0xcb, 0x5f, 0xd4, 0xcd, 0x7c, 0xf6, 0x82, 0xc6,
  37862. 0xee, 0xf9, 0x88, 0x3a, 0x34, 0x07, 0x04, 0xb4, 0x84, 0x69, 0xb3, 0xa4,
  37863. 0x67, 0xab, 0x09, 0xc0, 0x83, 0xfe, 0x59, 0xaf, 0x18, 0x2c, 0xc8, 0x09,
  37864. 0xc1, 0xbb, 0x13, 0x7c, 0xce, 0x01, 0x5d, 0x85, 0xaa, 0x10, 0x28, 0xa2,
  37865. 0x96, 0x98, 0x69, 0x23, 0xa3, 0xe7, 0x67, 0xbc, 0x7c, 0x7e, 0xde, 0x4b,
  37866. 0x36, 0xab, 0x94, 0xd2, 0xb8, 0xf9, 0xdf, 0xee, 0xa1, 0x69, 0xa1, 0xc8,
  37867. 0xe9, 0x83, 0x21, 0xac, 0x1b, 0x39, 0xf7, 0x6d, 0xbf, 0x8c, 0xdb, 0xd6,
  37868. 0x2f, 0xc9, 0x3c, 0x3d, 0x50, 0xcf, 0x7f, 0xbe, 0x4a, 0x8d, 0xd8, 0x14,
  37869. 0xad, 0x69, 0xb0, 0x3e, 0x8a, 0xaf, 0xeb, 0xd9, 0x1a, 0x15, 0x4a, 0xe4,
  37870. 0xdd, 0xd9, 0xb2, 0xf8, 0x6b, 0xe2, 0x42, 0x9e, 0x29, 0x16, 0xfc, 0x85,
  37871. 0x9c, 0x47, 0x4b, 0x1f, 0x3d, 0x7b, 0x8c, 0xe1, 0x6d, 0xa3, 0xb8, 0x0a,
  37872. 0xe6, 0xfa, 0x27, 0xfe, 0x52, 0x72, 0xab, 0x3a, 0xa6, 0x58, 0xd7, 0x53,
  37873. 0xaf, 0x9f, 0xee, 0x03, 0x85, 0xfc, 0xa4, 0x7a, 0x72, 0x29, 0x7e, 0x62,
  37874. 0x28, 0x08, 0x79, 0xa8, 0xb8, 0xc7, 0x51, 0x8d, 0xaa, 0x40, 0x2d, 0x4a,
  37875. 0xd9, 0x47, 0xb4, 0xa8, 0xa2, 0x0a, 0x43, 0xd0, 0xe0, 0x4a, 0x39, 0xa3,
  37876. 0x06, 0x08, 0x9a, 0xe2, 0xf3, 0xf2, 0xf8, 0xb9, 0x9f, 0x63, 0x32, 0xa0,
  37877. 0x65, 0x0b, 0xb0, 0x50, 0x96, 0xa6, 0xa8, 0x7a, 0x18, 0xdd, 0x6c, 0xd1,
  37878. 0x9b, 0xd9, 0x4e, 0x76, 0x8f, 0xfb, 0x22, 0xa6, 0x1d, 0x29, 0xfc, 0xb8,
  37879. 0x47, 0x29, 0xb6, 0xd1, 0xb1, 0x63, 0x4a, 0x36, 0x1b, 0x10, 0xe6, 0x4c,
  37880. 0x65, 0x68, 0x1f, 0xad, 0x4f, 0x7d, 0x6b, 0x01, 0x41, 0x18, 0x5f, 0xba,
  37881. 0x3d, 0xa6, 0x54, 0x28, 0x58, 0xd5, 0x81, 0x60, 0xdf, 0x84, 0x76, 0x00,
  37882. 0x21, 0x53, 0xeb, 0xd3, 0xa6, 0xec, 0x7d, 0x3c, 0xb8, 0xcd, 0x91, 0x4c,
  37883. 0x2f, 0x4b, 0x2e, 0x23, 0x4c, 0x0f, 0x0f, 0xe0, 0x14, 0xa5, 0xe7, 0xe5,
  37884. 0x70, 0x8d, 0x8b, 0x9c
  37885. #else
  37886. 0xea, 0x05, 0x24, 0x0d, 0x80, 0x72, 0x25, 0x55, 0xf4, 0x5b,
  37887. 0xc2, 0x13, 0x8b, 0x87, 0x5d, 0x31, 0x99, 0x2f, 0x1d, 0xa9,
  37888. 0x41, 0x09, 0x05, 0x76, 0xa7, 0xb7, 0x5e, 0x8c, 0x44, 0xe2,
  37889. 0x64, 0x79, 0xa0, 0xec, 0x1f, 0x24, 0xb6, 0xc8, 0x05, 0x5b,
  37890. 0xc1, 0x18, 0xb0, 0xb7, 0xcf, 0x8c, 0x60, 0x67, 0x6b, 0x81,
  37891. 0x44, 0x27, 0xb6, 0x0e, 0xfd, 0x9b, 0xc3, 0xcb, 0x52, 0x31,
  37892. 0xfa, 0xc9, 0x34, 0x8d, 0x22, 0x1e, 0x07, 0x9d, 0x96, 0x6a,
  37893. 0x63, 0x83, 0x5c, 0xd7, 0x83, 0x2d, 0x7f, 0x48, 0x64, 0x79,
  37894. 0xca, 0xb4, 0x9f, 0xa2, 0x02, 0xb7, 0x86, 0x1d, 0x0e, 0xc7,
  37895. 0xf9, 0x6c, 0x07, 0xc0, 0x35, 0x6a, 0x34, 0x79, 0x7c, 0xb8,
  37896. 0x0f, 0xed, 0x98, 0x50, 0xfb, 0x51, 0xe0, 0x36, 0x44, 0x4c,
  37897. 0xc6, 0x35, 0xa2, 0xbb, 0x55, 0xb0, 0x5c, 0x39, 0x08, 0x02,
  37898. 0x20, 0x35, 0x5c, 0x56, 0x6d, 0x2e, 0xb9, 0xef, 0x21, 0x26,
  37899. 0x87, 0x87, 0x85, 0x8a, 0x32, 0xb5, 0xa7, 0x68, 0x70, 0x3a,
  37900. 0xfd, 0x0d, 0x21, 0x48, 0x91, 0xa3, 0x29, 0xc1, 0x2a, 0x38,
  37901. 0xe5, 0x26, 0x31, 0x1f, 0x42, 0xde, 0x0b, 0x25, 0xff, 0x1d,
  37902. 0x6b, 0xb4, 0xe0, 0x5d, 0x2d, 0xcf, 0x44, 0xd5, 0x7d, 0xc4,
  37903. 0xf6, 0x95, 0xf2, 0x06, 0x4f, 0x83, 0x88, 0x9d, 0x1e, 0xeb,
  37904. 0x1c, 0x09, 0x45, 0x62, 0x67, 0x3d, 0xff, 0x51, 0x47, 0xe8,
  37905. 0xbc, 0x9b, 0x03, 0x1f, 0xc7, 0x72, 0x65, 0xce, 0xa8, 0x8c,
  37906. 0xc2, 0xa0, 0xc2, 0xbd, 0x5b, 0x7c, 0x17, 0x16, 0x8b, 0x72,
  37907. 0xfa, 0xb1, 0xbd, 0xdf, 0x49, 0xd6, 0xa1, 0x00, 0x65, 0xbe,
  37908. 0x82, 0xe7, 0x68, 0xc7, 0xe7, 0xbc, 0xc2, 0xa4, 0xdb, 0xaa,
  37909. 0xcc, 0xea, 0x41, 0x52, 0x7f, 0x56, 0xb4, 0x68, 0x1f, 0x92,
  37910. 0x96, 0x0f, 0xce, 0xd4, 0xd0, 0x87, 0x4c, 0x4a, 0x73, 0xb5,
  37911. 0x6c, 0xd4, 0x69, 0x55, 0x15, 0x47, 0xdc, 0x94, 0x7f, 0xd2,
  37912. 0x54, 0x5e, 0xb2, 0x90, 0xc2, 0x47, 0xe4, 0xf5, 0xde, 0x8b,
  37913. 0x9b, 0xc6, 0x5d, 0x50, 0x95, 0x60, 0xe0, 0xf0, 0xa7, 0x4e,
  37914. 0xe0, 0xcd, 0x41, 0x09, 0xef, 0xb3, 0x3d, 0x90, 0x5c, 0x77,
  37915. 0x54, 0xec, 0x9e, 0x5d, 0x8a, 0xe7, 0x09, 0x5c, 0xc9, 0x58,
  37916. 0x0c, 0xd0, 0x42, 0x35, 0xd2, 0x14, 0x59, 0x38, 0x69, 0xad,
  37917. 0xf9, 0xb5, 0xbf, 0x8a, 0x8e, 0x33, 0xd8, 0x5e, 0x7a, 0x55,
  37918. 0xd0, 0x53, 0x15, 0x40, 0x4e, 0xc5, 0x86, 0xd7, 0x8f, 0x5f,
  37919. 0x2f, 0x55, 0x82, 0xc2, 0x4f, 0x16, 0xe5, 0xea, 0x1c, 0xbc,
  37920. 0xff, 0x5e, 0x1f, 0x39, 0x46, 0x70, 0x54, 0x7a, 0x3a, 0x27,
  37921. 0x16, 0x1a, 0x2b, 0x6c, 0xd2, 0xb7, 0x80, 0xd3, 0xd1, 0x9d,
  37922. 0x25, 0x59, 0xed, 0xe6, 0x51, 0xb1, 0xf2, 0xad, 0x7e, 0x51,
  37923. 0x78, 0x14, 0x2b, 0x19, 0xae, 0x64, 0x72, 0x0f, 0xd8, 0x18,
  37924. 0x79, 0x8e, 0x66, 0x88, 0xd3, 0xa4, 0xa3, 0xc3, 0x76, 0x21,
  37925. 0xcb, 0xe4, 0x79, 0x5e, 0x95, 0x74, 0xe3, 0x31, 0x18, 0x79,
  37926. 0xed, 0xc7, 0xe7, 0xfb, 0x86, 0x48, 0x1b, 0x7b, 0x75, 0x5b,
  37927. 0x7f, 0x7c, 0x82, 0xc5, 0xab, 0x11, 0xb4, 0x5d, 0x59, 0x6f,
  37928. 0x78, 0xb2, 0xa5, 0x39, 0xc6, 0x63, 0x38, 0x6c, 0xeb, 0x50,
  37929. 0x06, 0x14, 0x76, 0xf0, 0xe8, 0xfb, 0x11, 0x95, 0x1f, 0x9d,
  37930. 0x9c, 0xa6, 0xe1, 0xe2, 0x0d, 0xa3, 0x66, 0xfc, 0x20, 0x83,
  37931. 0x50, 0x0e, 0x53, 0x75, 0xb5, 0x12, 0xf4, 0xdf, 0x31, 0x46,
  37932. 0x83, 0xac, 0x5b, 0xf3, 0x99, 0xa6, 0xd1, 0x7b, 0x2b, 0xc5,
  37933. 0xdc, 0x71, 0x07, 0x27, 0x33, 0x35, 0x34, 0xf5, 0x30, 0x19,
  37934. 0xc1, 0x3b, 0xba, 0x8a, 0xaf, 0x7e, 0x49, 0x93, 0x48, 0x5b,
  37935. 0x38, 0xc0, 0xbc, 0x2e, 0xc7, 0x59, 0x1b, 0xd9, 0xf5, 0xcc,
  37936. 0x86, 0xf5, 0x7b, 0x4d, 0xd7, 0x39, 0xa7, 0xa2, 0x56, 0x20,
  37937. 0x48, 0x98, 0x7d, 0x4f, 0x75, 0x56, 0x9b, 0xb8, 0x95, 0x45,
  37938. 0x17, 0xf3, 0x86, 0x3d, 0x97, 0x0a, 0x49, 0x1b, 0xca, 0xff,
  37939. 0x20, 0xc0, 0x24, 0x2c, 0x51, 0xc2, 0x0a, 0x3c, 0xbf, 0x07,
  37940. 0x60, 0x1c, 0x88, 0x85, 0x9b, 0x85, 0x2d, 0x4a, 0xfe, 0x5a,
  37941. 0x1c, 0x90, 0xf5, 0x90, 0x12, 0xd3, 0x03, 0x3c, 0x8c, 0x2e,
  37942. 0x95, 0x4a, 0x47, 0x76, 0x0f, 0x1f, 0x5d, 0x9e, 0xed, 0xc5,
  37943. 0x64, 0xc4, 0x9b, 0xbf, 0x86, 0xc5, 0x63, 0x84, 0x33, 0x00,
  37944. 0xf1, 0x26, 0x18, 0x21, 0xf3, 0x88, 0x1a, 0x08, 0x18, 0x6d,
  37945. 0x2f, 0xef, 0xd5, 0xeb, 0x2f, 0x69, 0xc8, 0x6e, 0x92, 0x34,
  37946. 0xfc, 0x72, 0x3d, 0x9a, 0xa7, 0x9e, 0x51, 0xfb, 0x56, 0xe3,
  37947. 0xdc, 0xf4, 0x8f, 0x9b, 0x6d, 0x0d, 0x2a, 0xec, 0x66, 0x12,
  37948. 0x26, 0x35, 0xbd, 0x61, 0xc2, 0x67, 0x19, 0xf5, 0x7e, 0xa1,
  37949. 0x67, 0xa2, 0x9c, 0x3b, 0x67, 0xb0, 0xc2, 0x51, 0x6a, 0x37,
  37950. 0x7c, 0x48, 0xe9, 0x4b, 0xb9, 0xa3, 0x38, 0x2f, 0xfc, 0xde,
  37951. 0xb4, 0x7c, 0xda, 0x52, 0x84, 0x0b, 0xb0, 0xd9, 0x08, 0xe9,
  37952. 0x7a, 0x4a, 0x6f, 0x79, 0x29, 0x3d, 0xc4, 0x5c, 0x78, 0xee,
  37953. 0x63, 0xb6, 0x96, 0x68, 0xd9, 0x82, 0x4e, 0xc1, 0x1b, 0x6f,
  37954. 0x52, 0xf5, 0xb3, 0xfb, 0xe8, 0xc4, 0x2a, 0x07, 0xc6, 0x3b,
  37955. 0x85, 0x0d, 0xf4, 0xbf, 0xb0, 0x6b, 0xfb, 0xce, 0x1d, 0xb4,
  37956. 0xbf, 0x63, 0x0b, 0x91, 0x67, 0xc4, 0xa3, 0x06, 0xa4, 0xaf,
  37957. 0x6c, 0xd3, 0xe5, 0x8b, 0x87, 0x4e, 0x64, 0x9c, 0xb1, 0xf3,
  37958. 0x70, 0x7c, 0x68, 0x43, 0x46, 0x13, 0x46, 0xee, 0x27, 0x75,
  37959. 0x12, 0x45, 0x42, 0xde, 0xa5, 0x8d, 0xcf, 0xf7, 0x09, 0x87,
  37960. 0xa8, 0x80, 0x3d, 0xb6, 0x45, 0xee, 0x41, 0x2d, 0x7c, 0x45,
  37961. 0x01, 0x9d, 0xaa, 0x78, 0xa8, 0x10, 0xa4, 0xfd, 0xb5, 0x5f,
  37962. 0xee, 0x0f, 0x77, 0xba, 0x73, 0xff, 0x49, 0xdc, 0xfa, 0x39,
  37963. 0xd6, 0xa3, 0x6f, 0x25, 0xb9, 0x63, 0x2c, 0x92, 0xc5, 0xdf,
  37964. 0xfb, 0xba, 0x89, 0xf9, 0xfa, 0x94, 0x5b, 0x6f, 0x5a, 0x4d,
  37965. 0x1c, 0xe4, 0xc9, 0x10, 0xf9, 0xa0, 0xe8, 0xc4, 0xcb, 0x55,
  37966. 0x1a, 0xdb, 0x56, 0x5f, 0x8e, 0x91, 0x03, 0x23, 0xca, 0xb0,
  37967. 0x1f, 0xef, 0xb8, 0x6c, 0x13, 0x5a, 0x99, 0x25, 0xf0, 0x49,
  37968. 0xa9, 0x5a, 0x45, 0xf7, 0xfd, 0x1a, 0xc2, 0x71, 0x06, 0xe3,
  37969. 0x2d, 0x25, 0x64, 0xb0, 0x52, 0x12, 0x03, 0x62, 0xc7, 0xb6,
  37970. 0xf9, 0xdc, 0x1f, 0x78, 0xff, 0x8b, 0xfa, 0xde, 0x7f, 0x71,
  37971. 0xa6, 0x35, 0x3e, 0xac, 0x20, 0x54, 0x94, 0xa7, 0x2e, 0x9d,
  37972. 0x47, 0x17, 0x4b, 0xad, 0x92, 0xb3, 0x14, 0x26, 0x8c, 0x5a,
  37973. 0xd0, 0x16, 0x4b, 0x22, 0xe9, 0x0c, 0x79, 0x6b, 0x8e, 0xac,
  37974. 0x0d, 0x12, 0xf5, 0x66, 0x8e, 0x82, 0x1a, 0x44, 0xf3, 0xe9,
  37975. 0x56, 0x5a, 0xcd, 0x1c, 0x1b, 0x81, 0x7b, 0x63, 0x59, 0xfe,
  37976. 0xc8, 0xc0, 0xe3, 0xda, 0x16, 0x6b, 0x6f, 0x0d, 0xba, 0x0e,
  37977. 0x47, 0x12, 0x86, 0x9e, 0xf0, 0x3b, 0x4d, 0x87, 0x3b, 0xf2,
  37978. 0x75, 0x73, 0x2d, 0xdf, 0xca, 0x76, 0x0b, 0xbd, 0xe7, 0xb7,
  37979. 0x74, 0x24, 0xf3, 0xc6, 0xe6, 0x75, 0x3f, 0x8b, 0x6a, 0xd9,
  37980. 0xad, 0xed, 0xc0, 0x70, 0x04, 0x1e, 0x0b, 0x8e, 0x8b, 0x7f,
  37981. 0xea, 0xbc, 0x39, 0x6b, 0x8a, 0x44, 0xa6, 0x9a, 0x2d, 0x0d,
  37982. 0x8c, 0x21, 0x60, 0x09, 0xd2, 0x4a, 0xe0, 0x62, 0xcf, 0xfa,
  37983. 0xe8, 0x9b, 0x35, 0x6f, 0x23, 0x2f, 0xb5, 0x65, 0x08, 0x60,
  37984. 0x92, 0x15, 0xd0, 0x5b, 0x63, 0xcc, 0x65, 0x05, 0xd1, 0xef,
  37985. 0x0f, 0x7e, 0x1b, 0xb3, 0x8e, 0xc6, 0x12, 0x85, 0xc9, 0x82,
  37986. 0x53, 0x79, 0x2e, 0x80, 0x5f, 0x0c, 0x7b, 0xc7, 0x1c, 0x83,
  37987. 0x41, 0x06, 0xd8, 0x41, 0xc9, 0xe7, 0xb9, 0x4b, 0xa1, 0x61,
  37988. 0xc6, 0x86, 0x67, 0xf5, 0x10, 0xf7, 0x34, 0x0d, 0x39, 0x9e,
  37989. 0x2b, 0x5f, 0x19, 0x06, 0x02, 0xa5, 0x02, 0x23, 0x71, 0xc2,
  37990. 0x12, 0x65, 0xcc, 0x81, 0x06, 0xfd, 0x8d, 0x09, 0x68, 0x37,
  37991. 0x06, 0x3b, 0xff, 0xc4, 0x24, 0xb3, 0x1f, 0xd6, 0xe6, 0x8f,
  37992. 0x9c, 0x74, 0x2c, 0x5e, 0xc5, 0xf4, 0xe9, 0xeb, 0xca, 0xd3,
  37993. 0x04, 0x5b, 0x92, 0x9e, 0x5c, 0x1a, 0x1d, 0xa1, 0xa7, 0x34,
  37994. 0xd2, 0x05, 0xae, 0xdb, 0x3d, 0x71, 0x10, 0x6e, 0x30, 0xd9,
  37995. 0xa3, 0x44, 0xa0, 0xbd, 0x9e, 0x7b, 0xb5, 0x12, 0x8a, 0x12,
  37996. 0x07, 0x60, 0xd7, 0x1f, 0x92, 0xe6, 0xfe, 0x04, 0xa9, 0x3e,
  37997. 0x62, 0x64, 0x00, 0x5f, 0x7c, 0x7b, 0x34, 0x09, 0xeb, 0x4a,
  37998. 0x18, 0x9e, 0x77, 0x72, 0x3a, 0x31, 0x1a, 0x62, 0x2a, 0xb5,
  37999. 0xcb, 0x4e, 0x53, 0xce, 0xad, 0x8b, 0x5a, 0x20, 0x4f, 0xd7,
  38000. 0x3e, 0x16, 0xf8, 0x10, 0xe2, 0xae, 0xbd, 0x3f, 0x02, 0xa9,
  38001. 0x18, 0xa0, 0x01, 0x18, 0x84, 0x95, 0x22, 0x2e, 0x93, 0x76,
  38002. 0x44, 0x4e, 0x11, 0x7b, 0x03, 0x51, 0x50, 0x19, 0x79, 0xe7,
  38003. 0xbb, 0x5c, 0x7b, 0xca, 0x74, 0xb4, 0x25, 0x26, 0xdb, 0x66,
  38004. 0xaa, 0x0b, 0x21, 0x07, 0xfb, 0x7a, 0x96, 0x10, 0x7d, 0x99,
  38005. 0xa9, 0x16, 0xcb, 0x0e, 0xba, 0x63, 0xab, 0x95, 0xfc, 0x5a,
  38006. 0xbe, 0xa6, 0x7f, 0xd8, 0xb4, 0xcd, 0x7c, 0xc5, 0xd0, 0xb1,
  38007. 0x1b, 0x48, 0x40, 0xfb, 0xe6, 0x2f, 0x2b, 0x94, 0xfe, 0x68,
  38008. 0xa2, 0xc4, 0x36, 0xd9, 0xcd, 0xc1, 0x93, 0x6d, 0xef, 0x39,
  38009. 0x5e, 0x43, 0x30, 0x5a, 0x2e, 0x66, 0xb6, 0xf2, 0xed, 0x9a,
  38010. 0x8d, 0x12, 0xdf, 0x5c, 0xae, 0xad, 0x16, 0x12, 0x7e, 0x81,
  38011. 0x82, 0x91, 0x7d, 0x2b, 0x12, 0xe9, 0x96, 0xb8, 0xb7, 0x42,
  38012. 0xcb, 0x1f, 0xf8, 0xd1, 0xfd, 0x83, 0x7a, 0xe4, 0x36, 0x1d,
  38013. 0x04, 0x27, 0x4c, 0xe5, 0xbd, 0x75, 0x24, 0xf7, 0xbd, 0xb6,
  38014. 0x6a, 0x68, 0x4e, 0x2c, 0x1b, 0x56, 0x3e, 0x60, 0xa4, 0x42,
  38015. 0xca, 0x7a, 0x54, 0xe5, 0x06, 0xe3, 0xda, 0x05, 0xf7, 0x77,
  38016. 0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
  38017. 0xfe, 0x4b
  38018. #endif
  38019. };
  38020. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_sig[] = {
  38021. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38022. 0x27, 0x3b, 0x58, 0xa0, 0xcf, 0x00, 0x29, 0x5e, 0x1a, 0x63, 0xbf, 0xb4,
  38023. 0x97, 0x16, 0xa1, 0x9c, 0x78, 0xd1, 0x33, 0xdc, 0x72, 0xde, 0xa3, 0xfc,
  38024. 0xf4, 0x09, 0xb1, 0x09, 0x16, 0x3f, 0x80, 0x72, 0x22, 0x68, 0x65, 0x68,
  38025. 0xb9, 0x80, 0x5a, 0x4a, 0x0d, 0x73, 0x49, 0xe1, 0xc6, 0xde, 0xca, 0x08,
  38026. 0x4f, 0xca, 0xf8, 0xb2, 0xf8, 0x45, 0x3b, 0x6b, 0x8c, 0x6c, 0xfd, 0x3a,
  38027. 0xf4, 0xde, 0xde, 0x82, 0xd8, 0x04, 0xbe, 0x4f, 0x4a, 0xdb, 0x92, 0x47,
  38028. 0x83, 0x2d, 0xc4, 0x55, 0xed, 0x20, 0x4f, 0x71, 0xb1, 0x58, 0xd9, 0x70,
  38029. 0x73, 0xbd, 0xb0, 0x3a, 0xb4, 0x8f, 0xd6, 0x9e, 0x32, 0x98, 0x2b, 0x9e,
  38030. 0xff, 0x2a, 0x7c, 0xcb, 0x05, 0x1b, 0x8e, 0xe6, 0x3a, 0x45, 0xc6, 0x7a,
  38031. 0xc8, 0xaf, 0x62, 0xd3, 0x04, 0xfa, 0x69, 0x4f, 0xda, 0x1b, 0x74, 0x16,
  38032. 0x0d, 0xb3, 0x1a, 0xee, 0x71, 0xd7, 0xb0, 0xef, 0x69, 0xf5, 0xe2, 0xe9,
  38033. 0xc2, 0xcc, 0x15, 0x66, 0x28, 0x0a, 0xac, 0xe2, 0x63, 0x06, 0xb7, 0x21,
  38034. 0x0d, 0xd8, 0x5c, 0x94, 0x63, 0xfd, 0x51, 0x18, 0x9f, 0x07, 0x19, 0x3d,
  38035. 0xa2, 0x50, 0x40, 0xd3, 0xe9, 0x05, 0xd4, 0x11, 0x13, 0x15, 0xaa, 0x46,
  38036. 0xda, 0x3e, 0x5f, 0xcd, 0x3c, 0xfa, 0x42, 0xba, 0x79, 0x4a, 0xb7, 0x43,
  38037. 0x91, 0xa5, 0xcb, 0xbc, 0xeb, 0x37, 0x94, 0xf1, 0x9c, 0xb9, 0xdb, 0x41,
  38038. 0x06, 0xd8, 0x7b, 0x5e, 0x90, 0xe3, 0x3c, 0x8a, 0x10, 0x62, 0x9a, 0x15,
  38039. 0x27, 0x78, 0xed, 0x69, 0x11, 0x2c, 0xb5, 0xb4, 0xdb, 0xc8, 0x70, 0x50,
  38040. 0x62, 0x47, 0x96, 0xcb, 0xd9, 0xb2, 0x3e, 0x59, 0x2f, 0x1c, 0xac, 0xcb,
  38041. 0xcf, 0x22, 0xc2, 0x9b, 0xc7, 0x92, 0xe9, 0x4d, 0x8d, 0x5d, 0xcf, 0x06,
  38042. 0x53, 0x7e, 0xf4, 0x4e, 0xfe, 0x9e, 0x41, 0x5d, 0x00, 0x8c, 0x08, 0xf4,
  38043. 0x02, 0x79, 0x33, 0x1c, 0x27, 0x1d, 0xe3, 0x94, 0xac, 0xe6, 0x87, 0xa0,
  38044. 0x08, 0xb4, 0x60, 0x0c, 0xff, 0x47, 0xdc, 0x16, 0x3a, 0x1d, 0x89, 0xc0,
  38045. 0x6a, 0xa4, 0x3d, 0x71, 0x33, 0xdd, 0x1e, 0x70, 0xfe, 0xd4, 0x8b, 0xed,
  38046. 0x7c, 0x91, 0xe4, 0xe2, 0x15, 0x06, 0xc1, 0x83, 0x24, 0x55, 0xa7, 0x2a,
  38047. 0x9f, 0x4e, 0xd9, 0x56, 0x7a, 0x95, 0xa8, 0xdd, 0xc4, 0xf0, 0x71, 0x3a,
  38048. 0x99, 0x65, 0x31, 0x4b, 0xb7, 0x96, 0x2c, 0x53, 0x54, 0x83, 0xec, 0xc9,
  38049. 0x97, 0x2f, 0x0c, 0xa4, 0x8f, 0xbb, 0x93, 0x9d, 0xea, 0xae, 0xf9, 0xcb,
  38050. 0xb2, 0xb9, 0xa3, 0x61, 0x5f, 0x77, 0x8c, 0xb6, 0x5a, 0x56, 0xbe, 0x5f,
  38051. 0x85, 0xd1, 0xb5, 0x0a, 0x53, 0xe2, 0xc7, 0xbf, 0x76, 0x8b, 0x97, 0x6f,
  38052. 0x10, 0xdd, 0x1f, 0x44, 0x69, 0x66, 0x03, 0xc4, 0x6b, 0x59, 0xf7, 0xb4,
  38053. 0xc1, 0x12, 0xcc, 0x00, 0x70, 0xe8, 0xbd, 0x44, 0x28, 0xf5, 0xfa, 0x96,
  38054. 0xf3, 0x59, 0xed, 0x81, 0x67, 0xe0, 0xbe, 0x47, 0x75, 0xb3, 0xa8, 0x9f,
  38055. 0x21, 0x70, 0x2e, 0x6f, 0xef, 0x54, 0x11, 0x3f, 0x34, 0xaf, 0x0d, 0x73,
  38056. 0x5b, 0x9e, 0x6d, 0x86, 0x58, 0xb7, 0x34, 0xc2, 0xc2, 0xb3, 0x64, 0xd5,
  38057. 0x9b, 0x6e, 0xb9, 0x99, 0x6a, 0xe4, 0xfd, 0xc3, 0x17, 0xf3, 0x10, 0xfc,
  38058. 0x6e, 0xf5, 0x65, 0xe1, 0x9c, 0x59, 0x15, 0x11, 0x00, 0xea, 0x96, 0x81,
  38059. 0x69, 0x9b, 0x05, 0x4d, 0xf3, 0xce, 0xf3, 0xf0, 0xa9, 0x01, 0x3f, 0x13,
  38060. 0xbb, 0xb0, 0xac, 0xc3, 0x92, 0x1c, 0x2b, 0x61, 0xe3, 0x01, 0x22, 0x45,
  38061. 0x4a, 0x23, 0x19, 0x80, 0xca, 0xb9, 0xef, 0x4e, 0x76, 0x52, 0xc5, 0x9d,
  38062. 0x91, 0x33, 0x17, 0xc4, 0x28, 0x83, 0x55, 0x61, 0x49, 0x72, 0x04, 0xaa,
  38063. 0xf8, 0xe3, 0x4b, 0x20, 0xf7, 0x6a, 0x74, 0x56, 0x64, 0xf9, 0xb3, 0xc9,
  38064. 0x67, 0x5b, 0x55, 0x29, 0x9a, 0x89, 0xa5, 0x14, 0x67, 0xea, 0x6d, 0x6a,
  38065. 0xde, 0x98, 0x58, 0x73, 0x25, 0xa3, 0xdb, 0xed, 0x3d, 0x62, 0xaa, 0xe0,
  38066. 0x79, 0x7f, 0xa3, 0xd9, 0xb5, 0x4c, 0xe9, 0xa8, 0xdf, 0xfd, 0x59, 0x31,
  38067. 0x42, 0x81, 0x9e, 0xb7, 0x81, 0x3f, 0x0e, 0xfb, 0xef, 0x80, 0x71, 0x9d,
  38068. 0xb7, 0xa5, 0xfc, 0xb1, 0x80, 0xc9, 0x7e, 0x31, 0xd9, 0x47, 0xe2, 0xca,
  38069. 0x10, 0x7b, 0xd1, 0xa1, 0x1c, 0x28, 0xc7, 0x7f, 0x51, 0x26, 0xb1, 0x4e,
  38070. 0x57, 0xdd, 0x7d, 0x76, 0x5c, 0x5a, 0x85, 0xa7, 0x7b, 0x8c, 0xc5, 0x6e,
  38071. 0xac, 0x20, 0xf8, 0x49, 0x16, 0xd6, 0x64, 0xf5, 0xf4, 0x2c, 0x32, 0xa1,
  38072. 0x5d, 0xfb, 0x87, 0xb6, 0x14, 0xfe, 0x68, 0x7c, 0x4d, 0xce, 0xd7, 0x94,
  38073. 0xf9, 0x8b, 0xf0, 0x61, 0xfd, 0xe0, 0x83, 0x7f, 0x13, 0xec, 0x7a, 0xb7,
  38074. 0x41, 0x04, 0x51, 0x6e, 0x30, 0xa2, 0x01, 0xf7, 0x30, 0x12, 0xec, 0xd2,
  38075. 0x8f, 0x73, 0xe7, 0x8e, 0x12, 0xb4, 0xe5, 0xc1, 0xff, 0xdf, 0x67, 0x14,
  38076. 0xb1, 0xe9, 0xba, 0x36, 0x19, 0x18, 0xf4, 0xaa, 0xe0, 0xe4, 0x9d, 0xcd,
  38077. 0xe8, 0xe7, 0x2b, 0x33, 0xb3, 0xdc, 0xb9, 0x19, 0xd7, 0xad, 0xa4, 0x68,
  38078. 0xcd, 0x83, 0x77, 0x98, 0x36, 0x49, 0xd9, 0x32, 0x20, 0xfd, 0xfc, 0x34,
  38079. 0xe7, 0x54, 0xd9, 0xb5, 0x05, 0xab, 0x0e, 0x08, 0x0e, 0x16, 0x8a, 0x7d,
  38080. 0x91, 0x4c, 0xaa, 0x19, 0x04, 0x37, 0x35, 0xa5, 0xab, 0x6c, 0xee, 0xc4,
  38081. 0x90, 0xf0, 0x5f, 0xc7, 0xae, 0x82, 0xfd, 0x59, 0x53, 0xe5, 0x36, 0x5a,
  38082. 0x56, 0x37, 0x61, 0x69, 0xda, 0xe5, 0x8f, 0xfd, 0x2e, 0xd4, 0x9c, 0x7f,
  38083. 0xb6, 0x39, 0xa4, 0x8d, 0x0a, 0xab, 0x82, 0x0f, 0xfe, 0x84, 0x69, 0x44,
  38084. 0x8a, 0xa6, 0xd0, 0x39, 0xf9, 0x72, 0x68, 0xe7, 0x97, 0xd8, 0x6c, 0x7b,
  38085. 0xec, 0x85, 0x8c, 0x52, 0xc9, 0x97, 0xbb, 0xc4, 0x7a, 0x67, 0x22, 0x60,
  38086. 0x46, 0x9f, 0x16, 0xf1, 0x67, 0x0e, 0x1b, 0x50, 0x7c, 0xc4, 0x29, 0x15,
  38087. 0xbc, 0x55, 0x6a, 0x67, 0xf6, 0xa8, 0x85, 0x66, 0x89, 0x9f, 0xff, 0x38,
  38088. 0x28, 0xaa, 0x87, 0x91, 0xce, 0xde, 0x8d, 0x45, 0x5c, 0xa1, 0x25, 0x95,
  38089. 0xe2, 0x86, 0xdd, 0xa1, 0x87, 0x6a, 0x0a, 0xa8, 0x3e, 0x63, 0x0e, 0x21,
  38090. 0xa5, 0x6e, 0x08, 0x4d, 0x07, 0xb6, 0x26, 0xa8, 0x92, 0xdb, 0xed, 0x13,
  38091. 0x01, 0xc3, 0xba, 0xcf, 0xad, 0x01, 0xbc, 0xe5, 0xc0, 0xba, 0xbe, 0x7c,
  38092. 0x75, 0xf1, 0xb9, 0xfe, 0xd3, 0xf0, 0xa5, 0x2c, 0x8e, 0x10, 0xff, 0x99,
  38093. 0xcb, 0xe2, 0x2d, 0xdc, 0x2f, 0x76, 0x00, 0xf8, 0x51, 0x7c, 0xcc, 0x52,
  38094. 0x16, 0x0f, 0x18, 0x98, 0xea, 0x34, 0x06, 0x7f, 0xb7, 0x2e, 0xe9, 0x40,
  38095. 0xf0, 0x2d, 0x30, 0x3d, 0xc0, 0x67, 0x4c, 0xe6, 0x63, 0x40, 0x41, 0x42,
  38096. 0x96, 0xbb, 0x0b, 0xd6, 0xc9, 0x1c, 0x22, 0x7a, 0xa9, 0x4d, 0xcc, 0x5b,
  38097. 0xaa, 0x03, 0xc6, 0x3b, 0x1e, 0x2f, 0x11, 0xae, 0x34, 0x6f, 0x0c, 0xe9,
  38098. 0x16, 0x9c, 0x82, 0x3b, 0x90, 0x4c, 0x0e, 0xf0, 0xf9, 0x7f, 0x02, 0xca,
  38099. 0xb9, 0xa9, 0x49, 0x6d, 0x27, 0x73, 0xd0, 0xbf, 0x15, 0x61, 0x52, 0xbc,
  38100. 0xd6, 0x31, 0x59, 0x2b, 0x52, 0x5b, 0xaf, 0x3c, 0xc0, 0x8f, 0xdc, 0xd5,
  38101. 0x2c, 0x1d, 0xe4, 0xe9, 0x41, 0xe8, 0xd3, 0x35, 0xd6, 0xb1, 0xf3, 0x32,
  38102. 0xe0, 0x52, 0x08, 0x73, 0x99, 0xb6, 0x6b, 0xbc, 0x26, 0xfb, 0x2e, 0xa7,
  38103. 0xb7, 0xcd, 0x14, 0xf0, 0xf9, 0xe5, 0x3a, 0xd0, 0x05, 0x5b, 0x2b, 0x38,
  38104. 0xbd, 0x7c, 0xda, 0xd4, 0x15, 0x45, 0xfa, 0x3b, 0x6f, 0x94, 0x8e, 0x22,
  38105. 0xce, 0xfa, 0x53, 0xe0, 0x5f, 0xa6, 0x9d, 0x1c, 0x26, 0x91, 0x8a, 0xab,
  38106. 0x72, 0x5b, 0x18, 0x78, 0x69, 0x98, 0x3f, 0x8d, 0x33, 0x7c, 0x21, 0x93,
  38107. 0x9e, 0xf0, 0xaf, 0xb7, 0x30, 0xc8, 0xac, 0xbc, 0xdb, 0x9c, 0x29, 0x17,
  38108. 0x6b, 0x9d, 0x0f, 0x16, 0xd6, 0xc0, 0xcc, 0x3b, 0xce, 0x11, 0xe9, 0x64,
  38109. 0xc8, 0xd4, 0x4c, 0x98, 0x7c, 0x8f, 0xf1, 0x5e, 0x84, 0xe4, 0x72, 0xf9,
  38110. 0x69, 0xf5, 0x9d, 0xad, 0x95, 0x3b, 0xfb, 0x6d, 0x30, 0x7e, 0x0a, 0x47,
  38111. 0x5b, 0x26, 0xb2, 0x4e, 0xeb, 0x1a, 0xc3, 0x37, 0x16, 0x28, 0x79, 0x62,
  38112. 0xb4, 0x36, 0x85, 0x4a, 0x15, 0x5a, 0xc3, 0x6e, 0xbe, 0x7e, 0x00, 0xe9,
  38113. 0x4a, 0xa5, 0xd7, 0x90, 0xcf, 0x59, 0x63, 0x2d, 0x2b, 0xc2, 0xc6, 0x47,
  38114. 0xe6, 0x77, 0xb7, 0x6e, 0x9b, 0xc8, 0x0d, 0x18, 0x2b, 0x45, 0x2b, 0xc9,
  38115. 0x5a, 0x6e, 0xb4, 0x50, 0xa5, 0x23, 0x7d, 0x17, 0xcc, 0x49, 0xe2, 0xb3,
  38116. 0xf4, 0x6d, 0xb4, 0xb7, 0xbb, 0x9e, 0xdd, 0x20, 0x99, 0x19, 0xf5, 0x53,
  38117. 0x1f, 0xd0, 0xff, 0x67, 0xf3, 0x8e, 0x6a, 0xcd, 0x2a, 0x6e, 0x2b, 0x0a,
  38118. 0x90, 0xd7, 0xdb, 0xe1, 0xff, 0x1c, 0x40, 0xa1, 0xb0, 0x5d, 0x94, 0x4d,
  38119. 0x20, 0x14, 0x01, 0xa1, 0xa8, 0xd1, 0x15, 0xd2, 0xd9, 0x1b, 0xbf, 0xc2,
  38120. 0x8a, 0xd0, 0x02, 0xf6, 0x16, 0xa1, 0xb7, 0x40, 0xe0, 0x36, 0x88, 0xc8,
  38121. 0x17, 0x0a, 0xf0, 0xb6, 0x0d, 0x3c, 0x53, 0xb9, 0x51, 0xed, 0xef, 0x20,
  38122. 0x6f, 0xf3, 0x0c, 0xb5, 0xce, 0x0e, 0x9e, 0xfd, 0x0f, 0x5e, 0x3f, 0x8f,
  38123. 0x3c, 0xb7, 0x2a, 0xdb, 0xc6, 0xa7, 0xf2, 0x11, 0x6e, 0xdc, 0x05, 0x33,
  38124. 0xd4, 0xd8, 0xb0, 0x2d, 0x8a, 0xe5, 0x39, 0x82, 0x00, 0x49, 0x7d, 0xfd,
  38125. 0x32, 0x29, 0xbb, 0x79, 0x5d, 0xcb, 0x21, 0x7b, 0x2d, 0x36, 0x58, 0x73,
  38126. 0x52, 0x57, 0x52, 0x96, 0x4d, 0x89, 0x61, 0xf4, 0xad, 0x1f, 0x48, 0xd5,
  38127. 0x7a, 0x4a, 0xaa, 0x1c, 0xa1, 0xf4, 0xb4, 0x9c, 0x43, 0x3b, 0x95, 0x72,
  38128. 0xd0, 0x0e, 0x35, 0x82, 0x26, 0xd4, 0x2e, 0xe3, 0x83, 0x96, 0x97, 0x5a,
  38129. 0x7b, 0xfc, 0x48, 0x17, 0x3c, 0xba, 0x9e, 0x5f, 0x46, 0x1a, 0x53, 0xe3,
  38130. 0x2e, 0x78, 0x79, 0x80, 0xf6, 0x2d, 0x24, 0xcf, 0x62, 0xb6, 0x86, 0xeb,
  38131. 0xee, 0xec, 0xf2, 0x1d, 0x00, 0xc8, 0x28, 0x9d, 0x93, 0x16, 0xa7, 0xd9,
  38132. 0x11, 0x47, 0xe3, 0xc4, 0xb6, 0xc4, 0xa0, 0x99, 0x83, 0xc1, 0x17, 0xd8,
  38133. 0x8e, 0xde, 0x69, 0x1d, 0xcb, 0xdd, 0xe7, 0x86, 0x6f, 0xf2, 0x36, 0x07,
  38134. 0x23, 0x86, 0x0d, 0xe9, 0xad, 0x87, 0xae, 0x76, 0x98, 0x95, 0x51, 0xf2,
  38135. 0xb3, 0x11, 0xc5, 0x34, 0xf0, 0x0c, 0xf8, 0x29, 0x9c, 0x84, 0x4f, 0x81,
  38136. 0x49, 0x85, 0x63, 0x25, 0x16, 0xb0, 0xc3, 0xaa, 0xd7, 0x8a, 0x2e, 0x4b,
  38137. 0x97, 0x60, 0x74, 0xf8, 0xa7, 0x39, 0xec, 0x6c, 0x2c, 0x9b, 0x33, 0x3a,
  38138. 0x11, 0xbd, 0xa6, 0x90, 0x48, 0x65, 0xb1, 0xe7, 0x38, 0x53, 0x47, 0x1b,
  38139. 0x62, 0xd5, 0xb7, 0xa8, 0xd4, 0xae, 0xf5, 0x12, 0x06, 0x12, 0x54, 0xa2,
  38140. 0xce, 0xf1, 0x6b, 0x3a, 0xda, 0x63, 0x2e, 0x37, 0x2a, 0x25, 0x89, 0x30,
  38141. 0x98, 0x77, 0x1d, 0x4b, 0x5a, 0x1e, 0xb7, 0x3d, 0xed, 0x19, 0xec, 0x9f,
  38142. 0x64, 0x46, 0xa8, 0x2a, 0x79, 0xf3, 0x70, 0x39, 0x9f, 0x8c, 0xc3, 0x28,
  38143. 0xcc, 0x2a, 0xc0, 0xd0, 0xe6, 0x80, 0xf5, 0x01, 0x78, 0x72, 0x7f, 0xe7,
  38144. 0x2e, 0x7b, 0x5f, 0x05, 0xc3, 0x41, 0x33, 0x07, 0xdb, 0x9c, 0xa8, 0x96,
  38145. 0xa7, 0x21, 0x20, 0x23, 0xd0, 0x59, 0x39, 0x06, 0x19, 0xa4, 0x29, 0xe5,
  38146. 0x72, 0x39, 0x69, 0x23, 0xe3, 0xfa, 0x28, 0x63, 0xf5, 0x42, 0x3b, 0xca,
  38147. 0x88, 0x5d, 0x7e, 0x47, 0x93, 0xa8, 0x8c, 0x75, 0xf2, 0x19, 0x44, 0x43,
  38148. 0x15, 0x39, 0x03, 0x42, 0xd8, 0x1d, 0x81, 0x30, 0x8e, 0x84, 0x31, 0x24,
  38149. 0x75, 0x67, 0x4e, 0xbe, 0xfe, 0x0a, 0xd8, 0xc3, 0xe7, 0x5b, 0xe1, 0xd5,
  38150. 0x12, 0x6a, 0x69, 0x99, 0xcd, 0x35, 0xca, 0x22, 0x02, 0x65, 0xb3, 0x0f,
  38151. 0x50, 0xb6, 0xaa, 0xc6, 0x91, 0x5c, 0x4d, 0xd4, 0x07, 0x93, 0x46, 0xf0,
  38152. 0xcc, 0xe1, 0x92, 0x14, 0x91, 0x21, 0x43, 0xc4, 0xba, 0x45, 0x1c, 0x47,
  38153. 0x29, 0xdf, 0xff, 0x89, 0x60, 0xee, 0x89, 0x1e, 0xc3, 0xb4, 0xb9, 0x0b,
  38154. 0xc9, 0x7e, 0xd9, 0x15, 0xb0, 0x80, 0x91, 0xbe, 0xb9, 0x43, 0x48, 0x12,
  38155. 0x86, 0x8e, 0x79, 0x38, 0x4d, 0xce, 0x36, 0x7f, 0xc3, 0xe8, 0xb7, 0xb9,
  38156. 0x92, 0xbf, 0x27, 0x20, 0x54, 0xc8, 0x05, 0x63, 0x3b, 0xf5, 0x48, 0x1a,
  38157. 0xa9, 0x04, 0x6c, 0xb6, 0x0e, 0x11, 0xea, 0xf3, 0x59, 0xb9, 0xa6, 0xf6,
  38158. 0xf8, 0x0b, 0x15, 0xed, 0x30, 0xf9, 0xe4, 0xe5, 0x26, 0x2d, 0xbb, 0xc6,
  38159. 0x5b, 0x36, 0xbb, 0x73, 0xa6, 0x4f, 0xf5, 0x43, 0x9f, 0xd7, 0xb9, 0x0f,
  38160. 0xbc, 0x4f, 0x8d, 0xb8, 0xec, 0x1d, 0x42, 0x19, 0x56, 0x37, 0xc4, 0xcb,
  38161. 0xd0, 0x16, 0x85, 0xff, 0xd3, 0x9b, 0xef, 0xc8, 0x75, 0x37, 0xd1, 0x92,
  38162. 0xad, 0x21, 0x94, 0x1e, 0x9a, 0xf6, 0x2f, 0x6d, 0x30, 0xba, 0x37, 0xc3,
  38163. 0xdc, 0x11, 0xe0, 0x79, 0xa4, 0x92, 0x1f, 0xe4, 0xaa, 0x7a, 0x6b, 0x2a,
  38164. 0xe4, 0x04, 0xb7, 0xf9, 0x86, 0x95, 0xdb, 0xa8, 0xfc, 0x8a, 0x53, 0x21,
  38165. 0x31, 0x14, 0xf7, 0x40, 0x01, 0x78, 0x4e, 0x73, 0x18, 0xb3, 0x54, 0xd7,
  38166. 0xa6, 0x93, 0xf0, 0x70, 0x04, 0x1c, 0xe0, 0x2b, 0xef, 0xee, 0xd4, 0x64,
  38167. 0xa7, 0xd9, 0x9f, 0x81, 0x4f, 0xe5, 0x1e, 0xbe, 0x6e, 0xd2, 0xf6, 0x3a,
  38168. 0xba, 0xcf, 0x8c, 0x96, 0x2a, 0x3d, 0xf7, 0xe5, 0x5c, 0x59, 0x40, 0x9c,
  38169. 0xe3, 0xf9, 0x2b, 0x6d, 0x3d, 0xf2, 0x6f, 0x81, 0xd6, 0xab, 0x9c, 0xab,
  38170. 0xc6, 0xf7, 0x8f, 0xaa, 0xe5, 0x71, 0xe3, 0xc9, 0x8c, 0x1a, 0xeb, 0xc5,
  38171. 0x87, 0xe7, 0xb0, 0xde, 0x18, 0xba, 0xaa, 0x1e, 0xda, 0x12, 0x32, 0x16,
  38172. 0x94, 0x3a, 0x6e, 0x4f, 0x84, 0x06, 0x8e, 0x33, 0xf7, 0xfa, 0x35, 0xb8,
  38173. 0x45, 0xe4, 0x5e, 0x9e, 0x46, 0x05, 0x7a, 0xf7, 0xf4, 0x99, 0xad, 0xb9,
  38174. 0xdd, 0x55, 0xd9, 0x52, 0x3b, 0x93, 0xe3, 0x9b, 0x54, 0x1b, 0xe6, 0xa9,
  38175. 0x70, 0xd3, 0x48, 0xf9, 0x3d, 0xdb, 0x88, 0x63, 0x66, 0xa0, 0xab, 0x72,
  38176. 0x83, 0x6e, 0x8f, 0x78, 0x9d, 0x55, 0x46, 0x21, 0xca, 0x7c, 0xb7, 0x5d,
  38177. 0x16, 0xe8, 0x66, 0x3b, 0x7b, 0xaa, 0xfe, 0x9c, 0x9c, 0x33, 0xc9, 0xc2,
  38178. 0xa4, 0x3c, 0x78, 0x97, 0xf3, 0x5b, 0xc2, 0x29, 0x36, 0x98, 0x68, 0x28,
  38179. 0xfe, 0x0a, 0xae, 0x6f, 0xe5, 0xf7, 0xfb, 0x9d, 0xf8, 0x8c, 0xd9, 0xd0,
  38180. 0x4d, 0xfe, 0xc7, 0xd0, 0xb0, 0xe3, 0x9c, 0xdb, 0xac, 0x9e, 0x1b, 0x55,
  38181. 0x7e, 0x24, 0xfe, 0xc4, 0x12, 0xcb, 0xc2, 0xdd, 0x0a, 0xda, 0x31, 0x40,
  38182. 0x41, 0xb7, 0xfc, 0x3f, 0x6d, 0xe2, 0xd3, 0x8a, 0x0f, 0x21, 0x33, 0x3a,
  38183. 0xbc, 0xa7, 0x62, 0x18, 0xb3, 0xaf, 0x48, 0xc6, 0xe2, 0xa3, 0xdd, 0x1d,
  38184. 0x20, 0x62, 0xe4, 0x4b, 0x81, 0x6b, 0x3a, 0xc5, 0xb1, 0x07, 0xe1, 0xf1,
  38185. 0xe1, 0xba, 0xf6, 0x01, 0xc6, 0xf2, 0xea, 0xc0, 0x97, 0x73, 0x79, 0x19,
  38186. 0x06, 0xaa, 0x62, 0x42, 0xcb, 0x21, 0x5f, 0x08, 0x97, 0x7d, 0x72, 0xb5,
  38187. 0x39, 0x4d, 0x99, 0xe3, 0xa2, 0x3f, 0xb9, 0xb4, 0xed, 0xf4, 0x61, 0x35,
  38188. 0xe1, 0x50, 0xfb, 0x56, 0x7c, 0x35, 0xfd, 0x44, 0x8a, 0x57, 0x22, 0xed,
  38189. 0x30, 0x33, 0xc3, 0x0b, 0xf1, 0x88, 0xe4, 0x44, 0x46, 0xf5, 0x73, 0x6d,
  38190. 0x9b, 0x98, 0x88, 0x92, 0xf5, 0x34, 0x85, 0x18, 0x66, 0xef, 0x70, 0xbe,
  38191. 0x7b, 0xc1, 0x0f, 0x1c, 0x78, 0x2d, 0x42, 0x13, 0x2d, 0x2f, 0x4d, 0x40,
  38192. 0x8e, 0xe2, 0x6f, 0xe0, 0x04, 0xdb, 0x58, 0xbc, 0x65, 0x80, 0xba, 0xfc,
  38193. 0x89, 0xee, 0xf3, 0x78, 0xb2, 0xd9, 0x78, 0x93, 0x6d, 0xbf, 0xd4, 0x74,
  38194. 0x24, 0xf4, 0x5c, 0x37, 0x89, 0x0c, 0x14, 0xd5, 0xbd, 0xc5, 0xfc, 0x37,
  38195. 0xe8, 0x8b, 0xe0, 0xc5, 0x89, 0xc9, 0x70, 0xb3, 0x76, 0x46, 0xce, 0x0d,
  38196. 0x7c, 0x3d, 0xa4, 0x5d, 0x02, 0x95, 0x03, 0xba, 0x24, 0xaa, 0xf7, 0xd0,
  38197. 0x75, 0x35, 0x78, 0x27, 0x9c, 0x6d, 0x2a, 0xef, 0xaa, 0xac, 0x85, 0xef,
  38198. 0x8d, 0xfc, 0xc0, 0xfc, 0x72, 0x02, 0xf4, 0xa3, 0xd3, 0x87, 0xfc, 0x4d,
  38199. 0xce, 0x3d, 0xcb, 0xc2, 0x74, 0x5b, 0xb0, 0x83, 0xc5, 0x72, 0x72, 0xd6,
  38200. 0xa1, 0x67, 0x4d, 0xa1, 0xd6, 0xaa, 0xe7, 0x9b, 0xe7, 0xc0, 0xfd, 0x86,
  38201. 0x91, 0x08, 0xfa, 0x48, 0x2f, 0x50, 0xce, 0x17, 0xea, 0x1c, 0xe3, 0x90,
  38202. 0x35, 0xe6, 0x6c, 0xc9, 0x66, 0x7d, 0x51, 0x32, 0x20, 0x0c, 0x2d, 0x4b,
  38203. 0xa1, 0xbf, 0x78, 0x87, 0xe1, 0x5a, 0x28, 0x0e, 0x9a, 0x85, 0xf6, 0x7e,
  38204. 0x39, 0x60, 0xbc, 0x64, 0x42, 0x5d, 0xf0, 0x0a, 0xd7, 0x3e, 0xbb, 0xa0,
  38205. 0x6d, 0x7c, 0xfa, 0x75, 0xee, 0x34, 0x39, 0x23, 0x0e, 0xbd, 0x50, 0x19,
  38206. 0x7a, 0x2a, 0xb7, 0x17, 0x3a, 0x8b, 0xb7, 0xb6, 0xf4, 0xd8, 0x47, 0x71,
  38207. 0x6b, 0x21, 0x1b, 0x56, 0xcc, 0xfb, 0x7b, 0x81, 0x99, 0x46, 0x88, 0x23,
  38208. 0x40, 0x49, 0x66, 0x8b, 0xac, 0x84, 0x16, 0x8a, 0x86, 0xae, 0x38, 0xc4,
  38209. 0x5b, 0x1f, 0x2b, 0xfa, 0xf2, 0x8b, 0x81, 0xc1, 0x22, 0x61, 0x61, 0x6c,
  38210. 0x43, 0x16, 0x8c, 0x1d, 0x37, 0xb2, 0xaf, 0x3c, 0x3a, 0x90, 0x33, 0xed,
  38211. 0xf5, 0x08, 0x78, 0xfd, 0x5a, 0xde, 0xd3, 0x38, 0x6d, 0xd7, 0x1c, 0x23,
  38212. 0xeb, 0xb4, 0x9b, 0x8e, 0xc2, 0x48, 0x47, 0x8e, 0x84, 0xbb, 0xc4, 0xd0,
  38213. 0xcc, 0xf9, 0x55, 0x5a, 0x57, 0xb9, 0x99, 0x52, 0x82, 0x21, 0x3b, 0x83,
  38214. 0xda, 0x8f, 0xa3, 0x88, 0x9c, 0x57, 0xe0, 0x4b, 0xc1, 0xce, 0xbe, 0xd3,
  38215. 0xea, 0xdd, 0xf2, 0x07, 0xc1, 0x73, 0x6f, 0xc0, 0x5e, 0x8e, 0x85, 0x72,
  38216. 0xab, 0x2f, 0xa9, 0xac, 0x39, 0xee, 0x05, 0x34, 0x13, 0x16, 0x1b, 0x1c,
  38217. 0x21, 0x24, 0x41, 0x49, 0x78, 0x87, 0x8b, 0x97, 0x9c, 0x9f, 0xa3, 0xa8,
  38218. 0xb9, 0xbc, 0xc6, 0xcc, 0xf2, 0xfd, 0x18, 0x2a, 0x46, 0x58, 0x5a, 0x88,
  38219. 0xa2, 0xb5, 0xcc, 0xd2, 0xda, 0xe1, 0xe3, 0x0d, 0x20, 0x23, 0x2b, 0x2f,
  38220. 0x47, 0x57, 0x5e, 0x64, 0x87, 0x97, 0x9c, 0xa7, 0xaa, 0xbc, 0xc1, 0xe4,
  38221. 0xe5, 0xea, 0x0b, 0x16, 0x3b, 0x3c, 0x3e, 0x45, 0x58, 0x63, 0x6a, 0x6f,
  38222. 0x7c, 0x8c, 0x8d, 0x92, 0x99, 0x9c, 0xad, 0xb5, 0xb7, 0xce, 0x00, 0x00,
  38223. 0x00, 0x00, 0x00, 0x00, 0x16, 0x23, 0x36, 0x4a
  38224. #else
  38225. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  38226. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  38227. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  38228. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  38229. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  38230. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  38231. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  38232. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  38233. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  38234. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  38235. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  38236. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  38237. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  38238. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  38239. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  38240. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  38241. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  38242. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  38243. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  38244. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  38245. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  38246. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  38247. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  38248. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  38249. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  38250. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  38251. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  38252. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  38253. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  38254. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  38255. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  38256. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  38257. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  38258. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  38259. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  38260. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  38261. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  38262. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  38263. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  38264. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  38265. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  38266. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  38267. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  38268. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  38269. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  38270. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  38271. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  38272. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  38273. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  38274. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  38275. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  38276. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  38277. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  38278. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  38279. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  38280. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  38281. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  38282. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  38283. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  38284. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  38285. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  38286. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  38287. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  38288. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  38289. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  38290. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  38291. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  38292. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  38293. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  38294. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  38295. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  38296. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  38297. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  38298. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  38299. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  38300. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  38301. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  38302. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  38303. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  38304. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  38305. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  38306. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  38307. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  38308. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  38309. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  38310. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  38311. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  38312. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  38313. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  38314. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  38315. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  38316. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  38317. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  38318. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  38319. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  38320. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  38321. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  38322. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  38323. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  38324. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  38325. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  38326. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  38327. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  38328. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  38329. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  38330. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  38331. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  38332. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  38333. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  38334. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  38335. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  38336. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  38337. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  38338. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  38339. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  38340. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  38341. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  38342. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  38343. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  38344. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  38345. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  38346. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  38347. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  38348. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  38349. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  38350. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  38351. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  38352. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  38353. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  38354. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  38355. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  38356. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  38357. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  38358. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  38359. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  38360. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  38361. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  38362. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  38363. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  38364. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  38365. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  38366. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  38367. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  38368. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  38369. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  38370. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  38371. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  38372. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  38373. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  38374. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  38375. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  38376. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  38377. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  38378. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  38379. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  38380. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  38381. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  38382. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  38383. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  38384. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  38385. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  38386. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  38387. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  38388. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  38389. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  38390. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  38391. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  38392. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  38393. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  38394. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  38395. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  38396. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  38397. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  38398. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  38399. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  38400. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  38401. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  38402. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  38403. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  38404. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  38405. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  38406. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  38407. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  38408. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  38409. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  38410. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  38411. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  38412. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  38413. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  38414. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  38415. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  38416. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  38417. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  38418. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  38419. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  38420. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  38421. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  38422. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  38423. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  38424. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  38425. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  38426. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  38427. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  38428. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  38429. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  38430. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  38431. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  38432. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  38433. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  38434. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  38435. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  38436. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  38437. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  38438. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  38439. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  38440. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  38441. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  38442. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  38443. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  38444. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  38445. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  38446. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  38447. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  38448. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  38449. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  38450. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  38451. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  38452. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  38453. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  38454. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  38455. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  38456. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  38457. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  38458. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  38459. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  38460. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  38461. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  38462. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  38463. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  38464. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  38465. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  38466. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46
  38467. #endif
  38468. };
  38469. return dilithium_param_vfy_test(WC_ML_DSA_44, ml_dsa_44_pub_key,
  38470. (word32)sizeof(ml_dsa_44_pub_key), ml_dsa_44_sig,
  38471. (word32)sizeof(ml_dsa_44_sig));
  38472. }
  38473. #endif
  38474. #ifndef WOLFSSL_NO_ML_DSA_65
  38475. static wc_test_ret_t dilithium_param_65_vfy_test(void)
  38476. {
  38477. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_pub_key[] = {
  38478. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38479. 0x2c, 0x32, 0xfa, 0x59, 0x71, 0x16, 0x4a, 0x0e, 0x45, 0x0f, 0x21, 0xfd,
  38480. 0x65, 0xee, 0x50, 0xb0, 0xbf, 0xea, 0x8e, 0x4e, 0xa2, 0x55, 0x71, 0xa6,
  38481. 0x65, 0x48, 0x56, 0x20, 0x8a, 0x48, 0x9d, 0xd7, 0xc9, 0x2c, 0x80, 0x62,
  38482. 0x88, 0x68, 0x4d, 0x5f, 0xbe, 0x5f, 0xe5, 0xf5, 0xa4, 0x75, 0xb6, 0x88,
  38483. 0x26, 0xae, 0x7d, 0x11, 0x43, 0x89, 0xcd, 0xe9, 0x67, 0x0c, 0x91, 0x0b,
  38484. 0xd1, 0xd8, 0x8b, 0x7b, 0x73, 0x75, 0x94, 0xc1, 0xc9, 0x61, 0xc7, 0x35,
  38485. 0x21, 0x99, 0x2e, 0xab, 0xe0, 0xdf, 0x4d, 0xac, 0x0d, 0xd0, 0xa2, 0x61,
  38486. 0x5f, 0x04, 0x08, 0x83, 0x66, 0x5c, 0x67, 0x47, 0x0c, 0xab, 0x2c, 0xb7,
  38487. 0x6d, 0x0e, 0x32, 0x4c, 0x8c, 0x25, 0x80, 0xf5, 0xe5, 0x7e, 0x3b, 0xa1,
  38488. 0xc6, 0xc5, 0x87, 0xd8, 0x68, 0xb2, 0xd5, 0x67, 0xf9, 0x5a, 0x8b, 0x88,
  38489. 0xf8, 0xcd, 0x0c, 0xda, 0x4f, 0xfc, 0xd2, 0xaf, 0xb2, 0xa2, 0x38, 0x21,
  38490. 0xf9, 0xd8, 0xf1, 0x1c, 0x8d, 0xb4, 0xe8, 0xfb, 0x76, 0x36, 0x87, 0xf4,
  38491. 0x7d, 0x03, 0xc4, 0x06, 0xab, 0x87, 0xac, 0x52, 0xe8, 0xd5, 0xf7, 0x63,
  38492. 0xf0, 0xa8, 0x0b, 0x95, 0xbd, 0x07, 0xf1, 0x1d, 0x33, 0x7b, 0x8a, 0x2c,
  38493. 0xef, 0x85, 0xbe, 0xf8, 0xc1, 0x4b, 0xa2, 0xb0, 0xe0, 0x7a, 0x85, 0xfa,
  38494. 0x52, 0x36, 0x05, 0xa7, 0x65, 0x4a, 0x0c, 0x21, 0x5c, 0xc0, 0x4f, 0x18,
  38495. 0xb8, 0x66, 0x02, 0xe6, 0xd0, 0x45, 0x60, 0x56, 0xfc, 0x40, 0x94, 0xb5,
  38496. 0xa5, 0x2b, 0xc7, 0x57, 0xc3, 0xc5, 0x30, 0x72, 0x1c, 0x4c, 0x2a, 0xd5,
  38497. 0x75, 0xae, 0x43, 0x9f, 0x01, 0x71, 0xac, 0x5c, 0xdf, 0x9c, 0x0a, 0x3c,
  38498. 0xb5, 0x89, 0x07, 0x9b, 0x28, 0x25, 0x31, 0x31, 0xc5, 0xb7, 0x24, 0x53,
  38499. 0x2c, 0x3c, 0x2a, 0x96, 0xe5, 0x0d, 0xa2, 0x97, 0xa7, 0x08, 0x9d, 0x31,
  38500. 0xc0, 0xcd, 0x53, 0xd5, 0xa8, 0x58, 0xa6, 0xac, 0x43, 0x2d, 0xac, 0x39,
  38501. 0x01, 0x2c, 0x60, 0xf6, 0x82, 0x86, 0xd0, 0xaf, 0xad, 0x61, 0x3f, 0x82,
  38502. 0x80, 0xa1, 0xe1, 0x12, 0x83, 0x6e, 0x1d, 0x5e, 0xfe, 0xc6, 0x1e, 0x2a,
  38503. 0x7a, 0x44, 0xcd, 0xc2, 0x0a, 0xf5, 0xc8, 0x72, 0x3e, 0x29, 0xc7, 0x0a,
  38504. 0xd1, 0x4c, 0x17, 0xdd, 0x1f, 0xb6, 0x95, 0x34, 0xc2, 0x6c, 0xdc, 0x63,
  38505. 0xd1, 0x7e, 0xb0, 0x52, 0x06, 0x18, 0x6c, 0xb1, 0x99, 0x6a, 0xbe, 0x42,
  38506. 0xa9, 0xc0, 0x22, 0xcc, 0x09, 0x11, 0x84, 0x1f, 0x16, 0x9a, 0x0e, 0xdd,
  38507. 0x18, 0x7a, 0x39, 0x34, 0xb0, 0x49, 0x44, 0xcb, 0x88, 0x1f, 0x91, 0x93,
  38508. 0x49, 0x3f, 0xcc, 0x62, 0x56, 0x33, 0x15, 0xcb, 0x02, 0x9b, 0x33, 0xe8,
  38509. 0xd7, 0xab, 0x51, 0xc0, 0x91, 0xe0, 0x9c, 0xd2, 0xf9, 0x52, 0x05, 0x0c,
  38510. 0xbf, 0xf1, 0x97, 0x42, 0xfe, 0xd0, 0x32, 0x27, 0x34, 0xf8, 0x82, 0x2d,
  38511. 0x65, 0x3a, 0x36, 0xce, 0xd1, 0x07, 0x82, 0x3a, 0x6a, 0xaa, 0x56, 0xf1,
  38512. 0x9b, 0x98, 0xca, 0x8e, 0x55, 0xff, 0xa0, 0x74, 0xd6, 0x6a, 0x42, 0xaa,
  38513. 0x0a, 0xd4, 0x59, 0x74, 0xfb, 0xd4, 0xdb, 0x14, 0x10, 0xee, 0xca, 0x78,
  38514. 0x83, 0x83, 0x95, 0x9b, 0x77, 0xf1, 0x9a, 0x48, 0xe0, 0x8f, 0xa4, 0x5a,
  38515. 0x4d, 0xa9, 0x3f, 0x32, 0x78, 0x4a, 0x25, 0x96, 0x9c, 0x20, 0x0a, 0xcc,
  38516. 0x5b, 0xd8, 0xca, 0x19, 0x47, 0x77, 0xb8, 0x7c, 0x51, 0x3e, 0xd6, 0x30,
  38517. 0xdb, 0x45, 0xb0, 0xe6, 0x9d, 0x6f, 0xc5, 0x0a, 0x5d, 0x5f, 0x55, 0xcd,
  38518. 0x0f, 0x20, 0x22, 0x7e, 0x09, 0x99, 0xac, 0xb8, 0x9c, 0x9d, 0xf7, 0x3e,
  38519. 0x7e, 0x07, 0xd7, 0xbc, 0x21, 0x76, 0x8c, 0x27, 0x81, 0x94, 0xab, 0x57,
  38520. 0x4a, 0xe2, 0x91, 0x1c, 0xa4, 0x77, 0x4a, 0xd2, 0x96, 0x52, 0x9d, 0x33,
  38521. 0xb5, 0x58, 0x70, 0xd7, 0xff, 0x22, 0xe8, 0x14, 0xea, 0xd0, 0x8c, 0xd4,
  38522. 0x06, 0x08, 0xd8, 0x73, 0x66, 0x4b, 0x93, 0x41, 0xc9, 0x73, 0x5b, 0x07,
  38523. 0x5f, 0x31, 0xc5, 0x25, 0x98, 0x7b, 0x7b, 0xa5, 0x26, 0x83, 0x94, 0x22,
  38524. 0x42, 0x1c, 0x51, 0xe6, 0x80, 0x48, 0xca, 0xd4, 0x53, 0x40, 0x3a, 0xee,
  38525. 0x2c, 0x29, 0x07, 0xed, 0xdf, 0x97, 0x44, 0x19, 0xe5, 0xe5, 0x35, 0x66,
  38526. 0x1f, 0xbd, 0x29, 0x77, 0x0c, 0x15, 0x6c, 0x95, 0x08, 0x81, 0xe0, 0x76,
  38527. 0x86, 0x5e, 0x6d, 0x77, 0x78, 0x76, 0x07, 0xdd, 0x21, 0x97, 0x59, 0xdb,
  38528. 0xd4, 0xbd, 0xb6, 0x4c, 0x3f, 0x07, 0x93, 0xb6, 0x4a, 0xce, 0xf7, 0x08,
  38529. 0x86, 0xfd, 0x9c, 0x03, 0x08, 0x94, 0x00, 0xea, 0x4b, 0xd6, 0x1e, 0x17,
  38530. 0xfb, 0xb5, 0xba, 0xde, 0x25, 0x95, 0xe7, 0xf8, 0x97, 0x9e, 0x99, 0xae,
  38531. 0x5d, 0xdd, 0xf6, 0x32, 0x1a, 0xf2, 0x4f, 0xcf, 0x0c, 0x17, 0x55, 0xb8,
  38532. 0xfb, 0xae, 0xc8, 0x46, 0xb0, 0x3e, 0x86, 0x2b, 0x5e, 0xef, 0x36, 0xca,
  38533. 0x24, 0xed, 0x32, 0x5b, 0xc8, 0xfb, 0x88, 0x35, 0x6a, 0x26, 0xfe, 0x06,
  38534. 0x54, 0x0c, 0x3e, 0x2c, 0x71, 0xdf, 0x98, 0xf0, 0xbb, 0xb2, 0xe0, 0x9d,
  38535. 0xf7, 0xeb, 0xce, 0x07, 0xfa, 0xc4, 0xab, 0x88, 0xc3, 0x14, 0x33, 0x60,
  38536. 0x48, 0xcf, 0x39, 0x26, 0x90, 0xac, 0xfa, 0x39, 0x6f, 0x2d, 0x9d, 0x6d,
  38537. 0x15, 0x7f, 0x84, 0x6b, 0x0a, 0x1c, 0xf4, 0x6c, 0x78, 0x62, 0x52, 0x93,
  38538. 0x2c, 0x7e, 0x9f, 0x4a, 0x51, 0x7a, 0x2e, 0xad, 0xea, 0xe4, 0xe5, 0x9c,
  38539. 0x15, 0x15, 0x28, 0x4d, 0x3e, 0x5e, 0xb4, 0x3b, 0xff, 0x81, 0xe0, 0x56,
  38540. 0x44, 0x33, 0x33, 0xd9, 0x4b, 0xb2, 0x23, 0x60, 0xed, 0x0d, 0xa5, 0x4e,
  38541. 0x9f, 0x7d, 0xbc, 0x6e, 0x3a, 0xf9, 0x7e, 0x16, 0x47, 0x66, 0xb1, 0x6c,
  38542. 0xc7, 0x26, 0x62, 0x9b, 0x3c, 0x53, 0xb3, 0xa1, 0x16, 0x62, 0x31, 0x64,
  38543. 0xd2, 0xbb, 0x28, 0x5c, 0xe8, 0x21, 0xc3, 0xfc, 0xc3, 0x6d, 0xa7, 0x35,
  38544. 0x4d, 0x57, 0xe0, 0xbd, 0x54, 0x1a, 0x84, 0xf7, 0x9c, 0x8a, 0x54, 0x3d,
  38545. 0x59, 0xb3, 0xa2, 0x46, 0x3b, 0x16, 0x48, 0x3b, 0x3a, 0x3c, 0x5e, 0x88,
  38546. 0xc3, 0x60, 0x63, 0x7e, 0xca, 0x68, 0xb7, 0x2f, 0x2b, 0xb5, 0x62, 0x2e,
  38547. 0x51, 0x89, 0xbe, 0x78, 0xf7, 0xfa, 0x19, 0xcc, 0xca, 0x87, 0x9a, 0xf5,
  38548. 0xef, 0x0d, 0x21, 0x08, 0x3b, 0xd6, 0x9a, 0x94, 0xc5, 0xd1, 0x1b, 0xa9,
  38549. 0x7c, 0xc8, 0x9f, 0x9a, 0xb0, 0xb8, 0xf7, 0x02, 0x12, 0x31, 0x70, 0x52,
  38550. 0x52, 0xda, 0xb5, 0x9a, 0x08, 0x20, 0xc3, 0xc4, 0x0c, 0x6a, 0x34, 0x58,
  38551. 0x75, 0x9b, 0xdc, 0x1a, 0x6a, 0x37, 0x42, 0x9f, 0x16, 0x70, 0xbb, 0x39,
  38552. 0x86, 0xbd, 0x09, 0x9c, 0x04, 0x44, 0xbe, 0x1a, 0xe5, 0xe9, 0x50, 0x9b,
  38553. 0x14, 0x50, 0x4f, 0x00, 0xba, 0xb0, 0xf6, 0x36, 0x4d, 0x69, 0x16, 0x11,
  38554. 0x40, 0x5a, 0x4e, 0x8b, 0x39, 0xb4, 0xf1, 0xb2, 0x11, 0x36, 0x2f, 0x02,
  38555. 0x15, 0xca, 0x78, 0xde, 0x75, 0x07, 0x64, 0x72, 0xfd, 0xd4, 0x48, 0xdd,
  38556. 0xfb, 0xf5, 0x8a, 0x3d, 0xa8, 0x8e, 0x14, 0xd1, 0x69, 0xe3, 0x21, 0x50,
  38557. 0x39, 0xfd, 0xd0, 0x3b, 0xa0, 0x22, 0x61, 0x5c, 0x7e, 0x88, 0x91, 0xe1,
  38558. 0xf0, 0xf6, 0x16, 0x23, 0xdb, 0xdb, 0x50, 0x0e, 0x39, 0xcc, 0x86, 0xf1,
  38559. 0xab, 0x89, 0x60, 0xb0, 0xac, 0x28, 0xc6, 0x57, 0xe4, 0xee, 0xa9, 0x1b,
  38560. 0xae, 0x78, 0xc5, 0x67, 0x1a, 0xeb, 0xb3, 0x43, 0xbc, 0xea, 0x11, 0x0c,
  38561. 0x64, 0xf6, 0xd2, 0x52, 0xa0, 0x7e, 0xcd, 0x6d, 0x84, 0x8c, 0xf8, 0x80,
  38562. 0xb7, 0xdb, 0x26, 0x91, 0x4a, 0xa0, 0x61, 0x69, 0x2f, 0x6f, 0x1c, 0x9d,
  38563. 0x2a, 0x20, 0x44, 0xdc, 0x58, 0xaf, 0x7d, 0xfe, 0x4d, 0xa2, 0x10, 0x21,
  38564. 0x88, 0xef, 0x42, 0x2e, 0x8e, 0xfb, 0x63, 0xbc, 0xc8, 0x26, 0xe7, 0x80,
  38565. 0xa5, 0xbf, 0xe0, 0x7a, 0xcb, 0xf3, 0x31, 0x1c, 0xd9, 0xa3, 0x12, 0x00,
  38566. 0x2f, 0x20, 0xc6, 0xc1, 0x15, 0xfd, 0x5b, 0x0d, 0x8a, 0x4d, 0xfb, 0x84,
  38567. 0x4d, 0xb4, 0x64, 0xeb, 0x12, 0xf3, 0x78, 0x6b, 0x4d, 0xc6, 0x98, 0x46,
  38568. 0x4c, 0xb3, 0xb4, 0x59, 0xdc, 0xb7, 0xdc, 0xbb, 0x56, 0x0f, 0x09, 0x14,
  38569. 0x28, 0x43, 0x9f, 0xb8, 0x75, 0xed, 0xcb, 0x97, 0x25, 0xaf, 0xa5, 0xeb,
  38570. 0x46, 0x14, 0xa6, 0x38, 0x68, 0x06, 0xe0, 0x6e, 0x55, 0x68, 0x6b, 0xf3,
  38571. 0xd8, 0x6d, 0x59, 0x65, 0x65, 0xff, 0x48, 0xfd, 0xdb, 0x3d, 0xe2, 0x21,
  38572. 0xb4, 0x7b, 0x78, 0x6a, 0x2e, 0x28, 0xb8, 0x21, 0xc4, 0x72, 0xf4, 0xef,
  38573. 0xfb, 0x74, 0x43, 0x29, 0xf2, 0x30, 0xc9, 0xca, 0x78, 0x93, 0x72, 0xfd,
  38574. 0x84, 0xa4, 0x95, 0xe0, 0xcd, 0xb1, 0x48, 0x29, 0xe7, 0xd1, 0x27, 0xf7,
  38575. 0xdc, 0x31, 0x6e, 0x00, 0x04, 0xd7, 0x7c, 0xfd, 0x2d, 0x25, 0xe9, 0xdb,
  38576. 0xc2, 0xb8, 0x14, 0x26, 0xed, 0x63, 0xb1, 0x50, 0x0a, 0x3c, 0xb2, 0x79,
  38577. 0x98, 0x79, 0x81, 0x2d, 0xdb, 0x60, 0x97, 0x99, 0xc0, 0x0a, 0x89, 0x9f,
  38578. 0x90, 0x19, 0x0b, 0xb3, 0x97, 0xd2, 0xf7, 0x50, 0xa5, 0x1d, 0x7d, 0x71,
  38579. 0x75, 0xe6, 0x58, 0x62, 0x53, 0x95, 0x40, 0x9e, 0xc7, 0xd3, 0x72, 0xa1,
  38580. 0xae, 0x07, 0xb3, 0x8a, 0x56, 0x61, 0x99, 0x81, 0x3e, 0xe4, 0x5e, 0x78,
  38581. 0x57, 0xd1, 0x8a, 0xc4, 0x04, 0x38, 0x13, 0xa0, 0x5d, 0x68, 0x6d, 0x22,
  38582. 0xae, 0xda, 0xfc, 0x67, 0xbb, 0xfb, 0x8e, 0x1a, 0xdc, 0x24, 0xf7, 0xc8,
  38583. 0xf9, 0x92, 0x6f, 0x4e, 0xb5, 0xe7, 0x6d, 0x13, 0x88, 0x05, 0x5c, 0xbb,
  38584. 0xe0, 0x24, 0x2a, 0x96, 0xc6, 0x70, 0x52, 0x14, 0xd0, 0xd9, 0xd8, 0xb2,
  38585. 0x5b, 0xdc, 0x85, 0xcf, 0x62, 0xb4, 0xcf, 0x77, 0xf1, 0xe5, 0x51, 0xeb,
  38586. 0xef, 0xe9, 0x3e, 0xf0, 0x16, 0xd2, 0xcc, 0x38, 0x0a, 0x47, 0x91, 0xc0,
  38587. 0xe0, 0x14, 0x1a, 0xf9, 0x74, 0xd1, 0x32, 0x8b, 0x02, 0x36, 0x05, 0x55,
  38588. 0x62, 0xa7, 0xae, 0x77, 0xb0, 0x01, 0x3d, 0x2c, 0x91, 0xbe, 0xfa, 0xdd,
  38589. 0x9c, 0x17, 0x42, 0xc1, 0x01, 0x4d, 0xd8, 0x27, 0x3c, 0x10, 0x82, 0x66,
  38590. 0x11, 0x91, 0x8b, 0xc8, 0x52, 0xd5, 0xc1, 0x1d, 0xee, 0xb2, 0x90, 0x17,
  38591. 0xed, 0xf3, 0xad, 0xa5, 0xd5, 0xeb, 0xf2, 0x9b, 0x78, 0xbf, 0x2d, 0x5a,
  38592. 0xad, 0xe5, 0x53, 0xe6, 0xc1, 0x3b, 0xd8, 0xf3, 0x6b, 0xc5, 0x4c, 0x87,
  38593. 0x0a, 0xe3, 0xc8, 0xc7, 0xe5, 0x42, 0x2c, 0xe2, 0x13, 0x1a, 0xe7, 0x27,
  38594. 0x20, 0x3e, 0x95, 0x13, 0x1e, 0xbb, 0x03, 0xae, 0xc0, 0x84, 0x14, 0x6d,
  38595. 0x7b, 0xf7, 0x98, 0x08, 0x18, 0x12, 0xb4, 0x4f, 0x99, 0x4a, 0xcf, 0xd0,
  38596. 0x4a, 0x5d, 0x21, 0x16, 0xf6, 0xdf, 0x10, 0xc7, 0xbe, 0xe6, 0x79, 0x3b,
  38597. 0x35, 0x2a, 0xa6, 0xd6, 0x19, 0x9c, 0xde, 0xbd, 0xaf, 0x72, 0xd2, 0x25,
  38598. 0xe0, 0xa4, 0xde, 0x99, 0x44, 0x18, 0x66, 0x41, 0xc7, 0x56, 0xf7, 0xdc,
  38599. 0x32, 0x56, 0x57, 0x39, 0x18, 0x31, 0xc8, 0x75, 0x01, 0xc3, 0xf3, 0x46,
  38600. 0xcf, 0xbf, 0xc6, 0x10, 0xb5, 0x1c, 0x38, 0xf9, 0xa4, 0xa5, 0x44, 0xa1,
  38601. 0x0b, 0x25, 0x48, 0x9c, 0xd3, 0x1c, 0x55, 0x54, 0x15, 0x9f, 0xe3, 0x74,
  38602. 0x5b, 0xb1, 0x92, 0xb6, 0x52, 0x61, 0xba, 0x2f, 0x53, 0x91, 0x17, 0x44,
  38603. 0x94, 0x00, 0xe4, 0x43, 0xa0, 0xe7, 0x0d, 0xaa, 0x8a, 0x5b, 0x81, 0x43,
  38604. 0xad, 0xfb, 0x50, 0xfe, 0xcf, 0x85, 0x2d, 0xfa, 0xc8, 0x1d, 0xad, 0xc8,
  38605. 0x7a, 0x7c, 0x5e, 0xf3, 0x90, 0x35, 0x5e, 0x67, 0xce, 0x57, 0x4d, 0xa0,
  38606. 0x22, 0x9e, 0x07, 0x4a, 0xf5, 0x9e, 0x5f, 0x91, 0x45, 0xd8, 0x62, 0xe0,
  38607. 0xf3, 0x87, 0x3b, 0xb7, 0x89, 0x2f, 0xdf, 0x8b, 0x82, 0xb1, 0x86, 0xc3,
  38608. 0xa4, 0xa3, 0x68, 0xc7, 0x73, 0x9e, 0x68, 0x8d, 0x24, 0x6a, 0x29, 0x94,
  38609. 0x58, 0x57, 0x4b, 0x81, 0x00, 0xe2, 0x2b, 0x94, 0x0a, 0xf5, 0x96, 0xa3,
  38610. 0x23, 0x9a, 0x7b, 0xd0, 0x2d, 0xcb, 0x6a, 0x8e, 0xae, 0x1b, 0x1c, 0x34,
  38611. 0xed, 0x30, 0x4e, 0xca, 0x29, 0x21, 0xfc, 0x3d, 0x70, 0x11, 0xc1, 0x5f,
  38612. 0x3e, 0xc2, 0x9e, 0x88, 0x71, 0x29, 0xa3, 0x8f, 0x92, 0xf5, 0x46, 0x77,
  38613. 0xd5, 0x47, 0x2d, 0x2b, 0x66, 0x1c, 0x07, 0xf0, 0xfc, 0x7b, 0xa0, 0x13,
  38614. 0x00, 0xae, 0xa5, 0x61, 0x92, 0x36, 0xeb, 0x7e, 0x43, 0x91, 0x20, 0x72,
  38615. 0xe5, 0xba, 0x7f, 0x79, 0x23, 0x12, 0x3e, 0xb2, 0x4b, 0x13, 0xa1, 0x8c,
  38616. 0x84, 0x72, 0x3b, 0x45, 0x62, 0xcf, 0x2e, 0x78, 0xc4, 0x9c, 0x22, 0x09,
  38617. 0xfa, 0x59, 0x9d, 0xdf, 0x13, 0x54, 0x66, 0xe2, 0x6f, 0xfa, 0xb5, 0x2a,
  38618. 0x27, 0x3e, 0x17, 0x82, 0xf3, 0x2a, 0x4d, 0x36, 0xd3, 0xf0, 0x8d, 0x43,
  38619. 0x40, 0x2c, 0x84, 0x68, 0xbe, 0x40, 0x50, 0x7d, 0xa3, 0x27, 0x5e, 0xde,
  38620. 0x4d, 0x04, 0x6f, 0xe8, 0x96, 0x9c, 0x7a, 0x1d, 0xb8, 0x2b, 0x8a, 0xb1,
  38621. 0x6e, 0xe2, 0x36, 0x07, 0x22, 0x50, 0xd9, 0x71, 0x93, 0x48, 0xb5, 0x51,
  38622. 0xce, 0x2a, 0x64, 0x6b, 0x11, 0xa6, 0xb9, 0x40, 0x2d, 0x6c, 0xd2, 0x76,
  38623. 0x52, 0xc6, 0xe3, 0xa6, 0x6b, 0xd2, 0x3f, 0x39, 0xd2, 0x13, 0x28, 0xa4,
  38624. 0xa9, 0x58, 0x99, 0xe8, 0x3d, 0x08, 0xfa, 0x3c, 0x34, 0x39, 0x4d, 0x7d,
  38625. 0x5e, 0x10, 0x72, 0x51, 0x96, 0x1d, 0x4b, 0xd9, 0x3e, 0xc9, 0x22, 0x4c,
  38626. 0x72, 0x63, 0xf8, 0x87, 0x4b, 0xe7, 0x41, 0xac, 0xcd, 0xd6, 0x34, 0xa2,
  38627. 0xe1, 0xe8, 0x66, 0x81, 0x04, 0x7d, 0x70, 0x95, 0xba, 0x37, 0x86, 0x9e,
  38628. 0x1f, 0x9a, 0x1b, 0xe4, 0x35, 0xac, 0xe6, 0xcf, 0x48, 0x55, 0x6e, 0xbb,
  38629. 0x9d, 0x40, 0x79, 0x96, 0xdd, 0xac, 0xf8, 0xf5, 0x99, 0xad, 0x43, 0x0d,
  38630. 0xad, 0xa9, 0x62, 0xc0, 0x70, 0x8b, 0x50, 0x9b, 0xca, 0x0d, 0x3e, 0x54,
  38631. 0x9c, 0x27, 0xd5, 0x9e, 0x20, 0xe2, 0xe0, 0xb0, 0xb0, 0xbe, 0x8e, 0x56,
  38632. 0x43, 0x95, 0x9b, 0x34, 0xd1, 0x05, 0x28, 0xa0, 0xee, 0xd9, 0xab, 0x6a,
  38633. 0xa7, 0xbb, 0xb7, 0x1b, 0x3a, 0x5d, 0x33, 0x97, 0x25, 0x54, 0xe4, 0x0e,
  38634. 0x64, 0x79, 0xed, 0x16, 0x62, 0x89, 0x70, 0x4a, 0xa6, 0x47, 0x40, 0xd7,
  38635. 0xa3, 0xd2, 0x6f, 0x28, 0xdd, 0xc5, 0x04, 0xab, 0x7e, 0x7e, 0x1e, 0xb0,
  38636. 0x19, 0x02, 0x48, 0xb5, 0x88, 0x82, 0x75, 0xaf, 0x66, 0x74, 0xca, 0xf6,
  38637. 0xd7, 0xe8, 0x6d, 0xfa, 0x5e, 0xfa, 0xaf, 0xa8, 0x04, 0xaa, 0x2c, 0x09,
  38638. 0xf1, 0x4c, 0x36, 0x75, 0xb5, 0xdc, 0xe8, 0x04, 0x80, 0xd3, 0x14, 0x78,
  38639. 0x09, 0x5b, 0xfd, 0x52, 0x6f, 0xd9, 0x3c, 0x1c, 0x02, 0x3b, 0x77, 0xb8,
  38640. 0xa1, 0xe9, 0xa4, 0xb7, 0x42, 0x62, 0xee, 0xea, 0x43, 0xf3, 0xd8, 0xd0,
  38641. 0x7a, 0x53, 0x91, 0x34, 0x7f, 0xe7, 0x9a, 0xc6
  38642. #else
  38643. 0x15, 0xc9, 0xe5, 0x53, 0x2f, 0xd8, 0x1f, 0xb4, 0xa3, 0x9f,
  38644. 0xae, 0xad, 0xb3, 0x10, 0xd0, 0x72, 0x69, 0xd3, 0x02, 0xf3,
  38645. 0xdf, 0x67, 0x5a, 0x31, 0x52, 0x19, 0xca, 0x39, 0x27, 0x77,
  38646. 0x61, 0x6d, 0x0f, 0xc1, 0x33, 0x26, 0x09, 0xf0, 0xf9, 0x4d,
  38647. 0x12, 0x7a, 0xef, 0xf7, 0x21, 0x26, 0x2c, 0xe0, 0xe2, 0x92,
  38648. 0x1f, 0x9d, 0xd1, 0xaa, 0xaf, 0x08, 0x14, 0xf2, 0xaa, 0x24,
  38649. 0x99, 0x0f, 0x20, 0x57, 0x35, 0x04, 0x32, 0x96, 0x8e, 0x6e,
  38650. 0x10, 0x64, 0xe3, 0xe3, 0x57, 0x26, 0x33, 0x32, 0x7b, 0xe4,
  38651. 0x18, 0x41, 0x77, 0xd3, 0x24, 0x63, 0x3d, 0x11, 0xea, 0xdc,
  38652. 0xbe, 0x59, 0xff, 0x8d, 0xc2, 0xe4, 0xc7, 0x04, 0xf3, 0xd4,
  38653. 0xe0, 0x1d, 0x5e, 0x09, 0x46, 0xbf, 0x02, 0x05, 0xc7, 0xa6,
  38654. 0xb7, 0x82, 0x40, 0x1f, 0x55, 0xe9, 0x77, 0x82, 0xc0, 0xcc,
  38655. 0x86, 0x99, 0x19, 0x99, 0xa2, 0xc9, 0x1b, 0x4f, 0xdd, 0x49,
  38656. 0x4c, 0x78, 0x0a, 0x58, 0xb8, 0xf0, 0x23, 0xac, 0x1a, 0x71,
  38657. 0x57, 0x6d, 0xd6, 0x3a, 0x3a, 0x6f, 0x93, 0xb3, 0x2b, 0x09,
  38658. 0xbe, 0xec, 0x7b, 0x5b, 0xf7, 0x3a, 0xed, 0xf9, 0xd0, 0xb1,
  38659. 0xfe, 0x9f, 0x9b, 0xec, 0x11, 0xb6, 0x6b, 0xd1, 0xb6, 0x00,
  38660. 0x72, 0x7f, 0x68, 0x9a, 0x61, 0xa5, 0xf5, 0x6e, 0xe9, 0x46,
  38661. 0xa4, 0x82, 0x08, 0x9f, 0x50, 0x4c, 0x75, 0xc3, 0x48, 0x85,
  38662. 0x76, 0x39, 0xea, 0x0c, 0xf2, 0xe8, 0x7e, 0x48, 0x69, 0xd9,
  38663. 0x6f, 0x9a, 0x89, 0x7d, 0x98, 0xc1, 0x16, 0xdc, 0x2f, 0xc7,
  38664. 0x0a, 0x11, 0xa8, 0xbb, 0xe7, 0x91, 0xb1, 0x0f, 0x0e, 0xf0,
  38665. 0xb4, 0xc8, 0x41, 0x7e, 0x62, 0x9e, 0x3c, 0x30, 0x4c, 0xbc,
  38666. 0x4c, 0xeb, 0x37, 0xaf, 0x48, 0x72, 0x59, 0x64, 0x8e, 0xfb,
  38667. 0x77, 0x11, 0x28, 0xdd, 0x30, 0x52, 0x8e, 0x69, 0x8c, 0x9f,
  38668. 0x3d, 0xec, 0xdf, 0xa7, 0x5f, 0x42, 0x18, 0xda, 0xba, 0x1a,
  38669. 0x96, 0x91, 0x7d, 0x62, 0xd5, 0x52, 0xff, 0x44, 0xc9, 0x1d,
  38670. 0x29, 0xa6, 0xb9, 0x03, 0x9a, 0x26, 0x26, 0xcf, 0x57, 0x40,
  38671. 0x70, 0x7e, 0x2b, 0xbd, 0xf0, 0x81, 0x71, 0x0f, 0x0b, 0x2e,
  38672. 0x9b, 0x03, 0xba, 0x31, 0x41, 0x68, 0x37, 0xc8, 0xff, 0xea,
  38673. 0xc4, 0x73, 0xa5, 0xf9, 0xc2, 0x92, 0x78, 0x0c, 0xe7, 0xfd,
  38674. 0x5d, 0xb2, 0x01, 0xb5, 0x8d, 0xeb, 0x64, 0xd4, 0x14, 0xea,
  38675. 0x7a, 0xd1, 0x42, 0xc8, 0x99, 0xe4, 0x7d, 0x5b, 0x7e, 0x3b,
  38676. 0x8f, 0xab, 0x82, 0x12, 0xdf, 0xbb, 0xa1, 0x45, 0x30, 0xc9,
  38677. 0x0f, 0xb9, 0xe5, 0xba, 0xe6, 0x8a, 0xf3, 0x78, 0x61, 0xcc,
  38678. 0x9f, 0xe1, 0x46, 0x2a, 0x9a, 0x18, 0x0e, 0x2a, 0x57, 0xf3,
  38679. 0xe5, 0x56, 0xd1, 0x42, 0x48, 0xe1, 0x5a, 0x8e, 0x33, 0xce,
  38680. 0x19, 0xe5, 0x3e, 0x7f, 0x00, 0x70, 0x9c, 0x4c, 0xd3, 0xe1,
  38681. 0x0c, 0xa1, 0x7e, 0xd4, 0xa9, 0x9e, 0x8b, 0xe2, 0xf0, 0xac,
  38682. 0xdb, 0xa6, 0x72, 0x75, 0x67, 0xa6, 0x57, 0xed, 0x79, 0x2e,
  38683. 0xca, 0x8d, 0xeb, 0x9b, 0x9e, 0xb7, 0xbf, 0x30, 0x02, 0x2b,
  38684. 0xb3, 0x43, 0x89, 0x9b, 0xa8, 0x88, 0xa5, 0xbb, 0x33, 0xd9,
  38685. 0x99, 0x30, 0x7c, 0xc7, 0xd4, 0x28, 0x5e, 0x5e, 0x3f, 0x9d,
  38686. 0x6d, 0x35, 0x75, 0x33, 0x8e, 0xff, 0x84, 0x2e, 0x2d, 0xda,
  38687. 0xf0, 0xff, 0x70, 0xe5, 0xb5, 0x62, 0x96, 0x33, 0x3a, 0xd9,
  38688. 0xb5, 0x82, 0x25, 0x81, 0x81, 0x40, 0x5d, 0x4f, 0x11, 0x86,
  38689. 0x63, 0x1a, 0x06, 0xc1, 0x67, 0xc7, 0x49, 0x03, 0xc7, 0xe4,
  38690. 0x6f, 0xb4, 0x13, 0x3e, 0x57, 0x62, 0xfd, 0x8a, 0xc6, 0x2b,
  38691. 0x65, 0x5b, 0xa4, 0x29, 0x57, 0x8d, 0xde, 0xa5, 0xee, 0x32,
  38692. 0xc2, 0x76, 0x03, 0xca, 0xce, 0xc1, 0x48, 0xec, 0x45, 0xcf,
  38693. 0x30, 0x21, 0x28, 0x7f, 0x10, 0x47, 0xd2, 0xdb, 0xee, 0xca,
  38694. 0x5b, 0x0f, 0xd5, 0x39, 0x3a, 0xc3, 0xa6, 0x78, 0xb2, 0x15,
  38695. 0xaf, 0x82, 0x3c, 0x2f, 0xc4, 0x51, 0x5c, 0x52, 0xad, 0xf2,
  38696. 0x89, 0x92, 0x8e, 0xf3, 0x50, 0x38, 0xed, 0xf8, 0xc9, 0x14,
  38697. 0x4c, 0xe4, 0xa3, 0x9a, 0xaf, 0xc4, 0x5c, 0xf3, 0x9f, 0xc3,
  38698. 0xa3, 0xc0, 0xbe, 0x45, 0x1b, 0x21, 0x63, 0xfa, 0xe0, 0xe0,
  38699. 0x91, 0x2b, 0x42, 0xca, 0x91, 0xfb, 0x5e, 0x97, 0x9a, 0x0a,
  38700. 0xd4, 0x88, 0xba, 0xb8, 0x22, 0xc6, 0xbf, 0x56, 0x58, 0x1e,
  38701. 0x92, 0xa9, 0x9d, 0xa7, 0xed, 0xc9, 0xab, 0x54, 0x4f, 0x75,
  38702. 0x8d, 0x42, 0xc1, 0xe1, 0x61, 0xd0, 0x91, 0x9a, 0x3a, 0x40,
  38703. 0x9a, 0xa3, 0xfb, 0x7b, 0x4e, 0xf0, 0x85, 0xf0, 0xdc, 0x40,
  38704. 0x72, 0x9f, 0x05, 0xa8, 0xbe, 0x95, 0x5a, 0x7f, 0xba, 0x75,
  38705. 0x00, 0x6e, 0x95, 0x76, 0xbd, 0xb2, 0x40, 0xf5, 0xb0, 0x64,
  38706. 0x0a, 0x2f, 0x06, 0x3d, 0x9f, 0xac, 0x6a, 0xa5, 0x46, 0x5a,
  38707. 0x85, 0xa4, 0x6f, 0xee, 0x27, 0xa0, 0xeb, 0x5f, 0x1f, 0x91,
  38708. 0xbd, 0x2b, 0x02, 0x16, 0xdf, 0x74, 0x97, 0x2c, 0xd0, 0xa8,
  38709. 0x9f, 0x3a, 0x7b, 0xdf, 0x3e, 0x98, 0x4a, 0x91, 0xdc, 0x19,
  38710. 0x96, 0x88, 0x75, 0x21, 0x1a, 0x6a, 0xa8, 0x4b, 0x1f, 0x35,
  38711. 0xd1, 0x92, 0xf5, 0x76, 0xf4, 0x72, 0x55, 0x13, 0xdb, 0x5d,
  38712. 0x07, 0x8d, 0xd9, 0x72, 0xe4, 0x75, 0xde, 0x80, 0xbc, 0xe9,
  38713. 0x9c, 0xf0, 0x5c, 0x6a, 0x8a, 0x0e, 0x34, 0xf6, 0x3f, 0x5c,
  38714. 0xef, 0x0e, 0xcc, 0x52, 0x38, 0x2d, 0x7b, 0xc2, 0x1b, 0x69,
  38715. 0x9f, 0xe5, 0xed, 0x14, 0xb0, 0x91, 0x0b, 0xe9, 0x4d, 0x34,
  38716. 0xd5, 0xaa, 0xd4, 0xd2, 0x46, 0x39, 0x45, 0x7e, 0x85, 0x2f,
  38717. 0xdb, 0x89, 0xf4, 0xff, 0x05, 0x74, 0x51, 0xba, 0xdd, 0xee,
  38718. 0xf6, 0xc2, 0xc1, 0x0a, 0x8f, 0xd9, 0xeb, 0xc7, 0x61, 0x30,
  38719. 0x8f, 0x86, 0x8b, 0x1f, 0x82, 0xc1, 0x22, 0xfd, 0x83, 0xf4,
  38720. 0x5d, 0xc5, 0x94, 0xf5, 0xd7, 0x17, 0xc7, 0x7b, 0x71, 0xf5,
  38721. 0x5e, 0x15, 0x49, 0x70, 0xb2, 0x57, 0xa0, 0xc0, 0x57, 0x63,
  38722. 0x53, 0x35, 0xb6, 0x52, 0x20, 0x7b, 0x83, 0xd4, 0x57, 0x63,
  38723. 0x25, 0x8e, 0x83, 0xb3, 0x8e, 0x26, 0x1f, 0x09, 0xde, 0x14,
  38724. 0xd6, 0xa6, 0xfc, 0xe5, 0x93, 0x3c, 0x88, 0x8e, 0xf5, 0x10,
  38725. 0x57, 0xb9, 0xc9, 0x9b, 0xff, 0x72, 0x9d, 0x3d, 0x3f, 0x97,
  38726. 0xd9, 0x3c, 0x20, 0xe2, 0x57, 0xfd, 0x2a, 0x5c, 0x17, 0x12,
  38727. 0xe6, 0x08, 0xaf, 0xe4, 0x26, 0x96, 0xb9, 0x6d, 0xc3, 0xac,
  38728. 0x22, 0xf3, 0x8b, 0x89, 0xde, 0xc7, 0x8a, 0x93, 0x06, 0xf7,
  38729. 0x1d, 0x08, 0x21, 0x36, 0x16, 0x74, 0x2b, 0x97, 0x23, 0xe4,
  38730. 0x79, 0x31, 0x08, 0x23, 0x62, 0x30, 0x67, 0xe2, 0xed, 0x30,
  38731. 0x9b, 0x0c, 0xf9, 0x08, 0x7a, 0x29, 0x73, 0xc6, 0x77, 0x8a,
  38732. 0xbb, 0x2a, 0x1c, 0x66, 0xd0, 0xdd, 0x9e, 0xa3, 0xe9, 0x62,
  38733. 0xcc, 0xb7, 0x88, 0x25, 0x4a, 0x5f, 0xbc, 0xaa, 0xe3, 0xe4,
  38734. 0x4f, 0xec, 0xa6, 0x8e, 0xa6, 0xa4, 0x1b, 0x22, 0x2b, 0x2c,
  38735. 0x8f, 0x57, 0x7f, 0xb7, 0x33, 0xfe, 0x16, 0x43, 0x85, 0xc5,
  38736. 0xd2, 0x95, 0xe6, 0xb9, 0x21, 0x68, 0x88, 0x98, 0x33, 0x8c,
  38737. 0x1d, 0x15, 0x9c, 0x4d, 0x62, 0x1f, 0x6b, 0xe8, 0x7a, 0x2d,
  38738. 0x6b, 0x0e, 0xc3, 0xde, 0x1a, 0xa8, 0xed, 0x67, 0xb3, 0xb3,
  38739. 0x36, 0x5b, 0x4b, 0xcb, 0xe8, 0xa8, 0x5c, 0x0b, 0x2f, 0xca,
  38740. 0xd7, 0x71, 0xe8, 0x85, 0xe7, 0x4d, 0xe5, 0x7b, 0x45, 0xed,
  38741. 0xb2, 0x4c, 0x69, 0x04, 0x7e, 0x4f, 0xc0, 0xef, 0x1a, 0xca,
  38742. 0x0d, 0xa6, 0xc4, 0x79, 0x15, 0x78, 0x9c, 0xd2, 0x91, 0x3c,
  38743. 0x32, 0x55, 0x40, 0xe7, 0xcb, 0x7e, 0xde, 0x07, 0xa6, 0x97,
  38744. 0x00, 0x2d, 0x70, 0xf6, 0x3d, 0x15, 0xdf, 0x29, 0x8e, 0xa3,
  38745. 0x96, 0x6d, 0xf2, 0xbb, 0xa5, 0x1b, 0x7b, 0x58, 0x30, 0xf6,
  38746. 0x17, 0xbd, 0xda, 0x13, 0xf7, 0x33, 0xc2, 0x62, 0x32, 0xd4,
  38747. 0x1c, 0x2e, 0x31, 0x74, 0x92, 0xad, 0x99, 0x8c, 0x0e, 0x7c,
  38748. 0x50, 0x21, 0xcd, 0xff, 0x41, 0xeb, 0xd1, 0xca, 0x14, 0xb7,
  38749. 0xb2, 0x31, 0x2f, 0xbe, 0x16, 0xce, 0x4f, 0x26, 0x16, 0x04,
  38750. 0xc2, 0xaf, 0xbe, 0x0d, 0x24, 0xab, 0x9a, 0x21, 0x37, 0x06,
  38751. 0xac, 0x50, 0x23, 0xf1, 0xbe, 0x5c, 0xbb, 0x64, 0xf3, 0xd3,
  38752. 0x66, 0xa3, 0xb8, 0xbe, 0x8b, 0x49, 0x8d, 0xf6, 0xc7, 0xb9,
  38753. 0x8f, 0x4e, 0x31, 0x06, 0x51, 0xe5, 0xf3, 0x0e, 0x56, 0xc4,
  38754. 0x24, 0x30, 0xf5, 0xe9, 0x36, 0x71, 0xbc, 0xc9, 0x70, 0x2c,
  38755. 0x6c, 0x4c, 0x15, 0x43, 0x44, 0xa4, 0xfc, 0xf1, 0xd2, 0x71,
  38756. 0x6c, 0x4c, 0xce, 0x30, 0x6c, 0x05, 0x7d, 0x2e, 0xb7, 0xbc,
  38757. 0xe4, 0x65, 0x76, 0x24, 0x75, 0x36, 0xdf, 0x28, 0xfc, 0xcd,
  38758. 0x9a, 0xba, 0xc2, 0xcd, 0xb0, 0x30, 0xdb, 0xe7, 0x2e, 0x3c,
  38759. 0x92, 0x63, 0x1d, 0x30, 0x23, 0x74, 0xb1, 0xb8, 0xcc, 0xd7,
  38760. 0xb6, 0x90, 0x65, 0x73, 0xa2, 0x2a, 0x6e, 0x49, 0x95, 0x0d,
  38761. 0xab, 0x24, 0xdf, 0x2d, 0xbf, 0x76, 0x46, 0x01, 0x44, 0xe4,
  38762. 0x18, 0x8e, 0xd5, 0x9a, 0x76, 0xc9, 0xc6, 0xbc, 0xdb, 0x7f,
  38763. 0x80, 0x52, 0xc6, 0x40, 0x41, 0x12, 0x36, 0x7c, 0x80, 0x69,
  38764. 0xce, 0x7b, 0xe1, 0xa0, 0x53, 0xa2, 0xd6, 0x8f, 0x3f, 0xf7,
  38765. 0xd7, 0x61, 0x09, 0x70, 0xa2, 0xa0, 0xc6, 0xaf, 0xa0, 0xd0,
  38766. 0xfa, 0x13, 0xbf, 0xc0, 0x69, 0x15, 0xce, 0x15, 0xec, 0x24,
  38767. 0x4b, 0x6b, 0xdc, 0x93, 0x51, 0xc6, 0x82, 0x19, 0x92, 0x84,
  38768. 0x5d, 0x99, 0xb0, 0x90, 0x2c, 0xcc, 0x2a, 0x81, 0x6b, 0x22,
  38769. 0x64, 0x0a, 0xcb, 0x51, 0x25, 0x82, 0x50, 0x02, 0x2d, 0x3e,
  38770. 0xd4, 0x72, 0xb3, 0x0c, 0x15, 0x77, 0xd2, 0xca, 0x98, 0x2f,
  38771. 0x41, 0x93, 0x14, 0xb2, 0x7f, 0xa1, 0x97, 0xa3, 0xb8, 0x8a,
  38772. 0x56, 0x24, 0x38, 0xa7, 0x36, 0xc5, 0x01, 0xc0, 0x9f, 0x3f,
  38773. 0x3e, 0x9a, 0xf6, 0xe9, 0x16, 0x82, 0x01, 0x58, 0x70, 0x0e,
  38774. 0x0d, 0xbc, 0xfa, 0x03, 0x57, 0x65, 0xa8, 0x5a, 0x3d, 0x57,
  38775. 0x81, 0x23, 0xbe, 0x6e, 0xa9, 0xe8, 0x22, 0xdf, 0x2f, 0x70,
  38776. 0xeb, 0x0a, 0x03, 0x96, 0x6b, 0xef, 0x20, 0x9f, 0xf2, 0x62,
  38777. 0xe7, 0xb2, 0x6e, 0x3a, 0x1e, 0x40, 0x1f, 0xd2, 0x97, 0x48,
  38778. 0xd1, 0x18, 0xf0, 0xeb, 0x52, 0x58, 0x02, 0x26, 0xce, 0x75,
  38779. 0xb1, 0x3a, 0x9d, 0x5b, 0x52, 0x94, 0xb2, 0x6e, 0x0e, 0x3f,
  38780. 0x39, 0xb6, 0xd9, 0x8a, 0x9d, 0xe8, 0x7c, 0x83, 0x32, 0xcc,
  38781. 0x43, 0x35, 0x9b, 0x7a, 0xed, 0xb2, 0x1e, 0x51, 0x37, 0x6c,
  38782. 0x14, 0xd8, 0xb8, 0x55, 0xb3, 0x91, 0xef, 0x0c, 0x3a, 0xe5,
  38783. 0x77, 0xd0, 0xbd, 0xb0, 0x7d, 0x38, 0x84, 0x2a, 0x47, 0xb2,
  38784. 0xb6, 0xda, 0xd7, 0x75, 0xd6, 0x2e, 0x60, 0xc7, 0x10, 0x52,
  38785. 0xf7, 0xdd, 0x09, 0x15, 0x6f, 0x04, 0x31, 0xc3, 0x5a, 0x6b,
  38786. 0x0c, 0x60, 0x10, 0xa8, 0x6e, 0x20, 0xa9, 0xdd, 0xb7, 0x72,
  38787. 0xc3, 0x9e, 0x85, 0xd2, 0x8f, 0x16, 0x7e, 0x3d, 0xe0, 0x63,
  38788. 0x81, 0x32, 0xfd, 0xca, 0xbc, 0x0f, 0xef, 0x3e, 0x74, 0x6a,
  38789. 0xb1, 0x60, 0xc1, 0x10, 0x50, 0x7c, 0x67, 0xa4, 0x19, 0xa7,
  38790. 0xb8, 0xed, 0xe6, 0xf5, 0x4e, 0x41, 0x53, 0xa6, 0x72, 0x1b,
  38791. 0x2c, 0x33, 0x6a, 0x37, 0xf1, 0xb5, 0x1c, 0x01, 0x7d, 0xa2,
  38792. 0x1f, 0x2c, 0x4e, 0x0a, 0xbf, 0xd4, 0x2c, 0x24, 0x91, 0x58,
  38793. 0x62, 0xfb, 0xf8, 0x63, 0xd9, 0xf8, 0x78, 0xf5, 0xc7, 0x78,
  38794. 0x32, 0xda, 0x99, 0xeb, 0x58, 0x20, 0x25, 0x19, 0xb1, 0x06,
  38795. 0x7f, 0x6a, 0x29, 0x20, 0xdb, 0xc8, 0x22, 0x48, 0xa9, 0x7f,
  38796. 0x24, 0x54, 0x8d, 0x7d, 0x8d, 0xb1, 0x69, 0xb2, 0xa3, 0x98,
  38797. 0x14, 0x0f, 0xba, 0xfa, 0xb6, 0x15, 0xe8, 0x28, 0x99, 0x3f,
  38798. 0x30, 0x04, 0x50, 0xab, 0x5a, 0x3c, 0xf1, 0x97, 0xe1, 0xc8,
  38799. 0x0f, 0x0e, 0xb4, 0x11, 0x63, 0x5a, 0x79, 0x08, 0x48, 0x75,
  38800. 0xaf, 0x9b, 0xca, 0xd9, 0x13, 0x18, 0xcc, 0xb1, 0xb3, 0xee,
  38801. 0xdd, 0x63, 0xdd, 0xf4, 0x21, 0x98, 0x76, 0xe2, 0x3e, 0xd5,
  38802. 0x86, 0x23, 0x33, 0x7e, 0xc7, 0xb4, 0x35, 0x4b, 0xc2, 0x2d,
  38803. 0xe1, 0xe2, 0xb0, 0x6c, 0x8b, 0x9b, 0x20, 0x3d, 0x48, 0x24,
  38804. 0x7c, 0xea, 0xa1, 0x75, 0x27, 0xe5, 0xf4, 0x70, 0xeb, 0x3b,
  38805. 0xc7, 0x26, 0x37, 0x04, 0xff, 0x8a, 0x7a, 0xd0, 0xc2, 0xb7,
  38806. 0x84, 0xb7, 0x29, 0xfb, 0x0e, 0xa3, 0xa8, 0x71, 0xcd, 0x58,
  38807. 0x06, 0x36, 0xe2, 0xf2, 0x77, 0xcc, 0x0f, 0x78, 0x08, 0x2b,
  38808. 0xbb, 0xe3, 0x53, 0x05, 0x71, 0xdc, 0x6c, 0x37, 0x32, 0x91,
  38809. 0x46, 0x42, 0x4f, 0x21, 0xe0, 0x34, 0xad, 0x3f, 0x30, 0x5a,
  38810. 0xc7, 0x0d, 0x17, 0x19, 0x39, 0x31, 0x58, 0x69, 0x3c, 0x8c,
  38811. 0xbe, 0xe7, 0xa6, 0x3b, 0xad, 0xfb, 0x46, 0x89, 0x06, 0xc1,
  38812. 0x8c, 0x16, 0x9a, 0x06, 0x3a, 0xd0, 0x7e, 0xd6, 0xb0, 0x7b,
  38813. 0x7d, 0xf8, 0x91, 0x7c, 0xfa, 0xd9, 0x66, 0x39, 0xfa, 0xbc,
  38814. 0x57, 0xa7, 0x78, 0x8b, 0x36, 0x78, 0xc0, 0x1c, 0x0e, 0x23,
  38815. 0x05, 0x0e, 0x04, 0x61, 0x16, 0x34, 0xf9, 0xc6, 0x63, 0x58,
  38816. 0xdf, 0xf4, 0x52, 0xce, 0xd0, 0x0f, 0x0c, 0xec, 0xb1, 0x82,
  38817. 0xf4, 0x72, 0x73, 0x72, 0x3f, 0x02, 0xbe, 0xe3, 0x9c, 0x63,
  38818. 0x73, 0xc8, 0x21, 0x65, 0xba, 0x57, 0x52, 0xa9, 0x19, 0xac,
  38819. 0x68, 0x50, 0xbd, 0x2d, 0x72, 0x5b, 0x93, 0x0f, 0x1c, 0x81,
  38820. 0x77, 0xd7, 0x2e, 0xc3, 0x93, 0x52, 0x6e, 0xdc, 0x79, 0x52,
  38821. 0x9f, 0xe3, 0xde, 0xe1, 0xba, 0x58, 0x55, 0xab, 0x8a, 0xf2,
  38822. 0x35, 0x6a, 0xcf, 0x94, 0x1f, 0x17, 0xa4, 0x23, 0x2e, 0x8e,
  38823. 0x18, 0x21, 0xbe, 0x14, 0xfa, 0xe7, 0x59, 0xc5, 0x44, 0x34,
  38824. 0xce, 0x03, 0xf4, 0xb7, 0x75, 0xd3, 0x51, 0x55, 0xdf, 0xff,
  38825. 0xcf, 0x4f, 0x44, 0xee, 0x13, 0x9b, 0xcb, 0x12, 0xae, 0xe5,
  38826. 0x5b, 0x44, 0x65, 0x28, 0xcb, 0x6a, 0x9c, 0x24, 0x1d, 0xea,
  38827. 0x2d, 0x5e, 0xa5, 0xc3, 0x78, 0xad, 0xed, 0x0c, 0x05, 0xa6,
  38828. 0xaf, 0x95, 0x04, 0xd2, 0xb5, 0x91, 0x0e, 0xa0, 0x06, 0x77,
  38829. 0xc5, 0x82, 0xf6, 0xdd, 0x72, 0x83, 0x04, 0xcc, 0xb0, 0xab,
  38830. 0x7a, 0xf0, 0xb4, 0x4d, 0x36, 0x71, 0x72, 0x1a, 0x9a, 0x0d,
  38831. 0xcd, 0xa3, 0x11, 0xa8, 0x0d, 0x7d, 0x49, 0xce, 0x9c, 0x09,
  38832. 0x1d, 0x08, 0xa4, 0x39, 0x2e, 0x03, 0xdf, 0x3a, 0xc8, 0xfe,
  38833. 0x6a, 0x2b, 0x0b, 0x07, 0x80, 0x55, 0x8a, 0xa8, 0xe6, 0x0e,
  38834. 0xc9, 0x7e, 0x83, 0xce, 0x3a, 0x98, 0x98, 0x4e, 0x3e, 0x08,
  38835. 0x20, 0x8f, 0x10, 0xfc, 0xc1, 0xc4, 0xcf, 0x37, 0x8d, 0x69,
  38836. 0xd8, 0x57, 0x9d, 0x48, 0x80, 0x6a, 0xef, 0x0c, 0xdd, 0x27,
  38837. 0x99, 0xf9, 0xe7, 0xd0, 0xd2, 0x36, 0xd8, 0xed, 0x41, 0x14,
  38838. 0x1b, 0x10
  38839. #endif
  38840. };
  38841. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_sig[] = {
  38842. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38843. 0xb1, 0xd1, 0x8e, 0x83, 0x0b, 0x0d, 0xd2, 0x71, 0xb2, 0xaa, 0x31, 0x38,
  38844. 0x16, 0xf0, 0xb4, 0xbc, 0x64, 0x2b, 0x97, 0xa1, 0x08, 0x19, 0x4f, 0x52,
  38845. 0xfe, 0x99, 0x1a, 0xa9, 0xd4, 0x08, 0x93, 0x99, 0x88, 0xfd, 0x6a, 0xd6,
  38846. 0xd8, 0xdb, 0xf0, 0x71, 0x2a, 0xc9, 0x04, 0x83, 0xc9, 0x45, 0x59, 0x5d,
  38847. 0xe0, 0x36, 0x59, 0x53, 0x1b, 0xb8, 0x5a, 0xa6, 0x1f, 0xb4, 0x1b, 0x0a,
  38848. 0xfb, 0x3a, 0xba, 0xe3, 0xb7, 0x5e, 0x04, 0x14, 0x59, 0x09, 0x9a, 0x8e,
  38849. 0xc2, 0x77, 0x5a, 0x3d, 0xf1, 0x43, 0x67, 0x74, 0x78, 0xfc, 0xcd, 0x34,
  38850. 0xed, 0x35, 0x16, 0x38, 0x04, 0xe6, 0xe7, 0xd6, 0xd2, 0x90, 0x1b, 0x28,
  38851. 0xb6, 0x66, 0x1b, 0x57, 0x85, 0x5e, 0xa7, 0x9f, 0x86, 0x1a, 0x0d, 0xc3,
  38852. 0x7e, 0xed, 0xbd, 0x32, 0x8a, 0x35, 0xe1, 0xb3, 0x01, 0xdc, 0x9b, 0x44,
  38853. 0x88, 0xa1, 0x0b, 0x87, 0x6e, 0x55, 0x31, 0xb1, 0x27, 0xcb, 0x85, 0xa4,
  38854. 0x27, 0x56, 0x33, 0xb0, 0x39, 0x0d, 0xd3, 0x4b, 0xd1, 0xa2, 0x47, 0x07,
  38855. 0xc6, 0xf4, 0xe6, 0x1f, 0x88, 0x70, 0x70, 0x13, 0x7e, 0x2e, 0x17, 0x32,
  38856. 0x0a, 0x6b, 0x38, 0x34, 0xcf, 0x2f, 0x00, 0x36, 0x58, 0x8d, 0xe1, 0xdd,
  38857. 0xa7, 0x94, 0x2a, 0x8f, 0x87, 0x99, 0x67, 0x02, 0x4d, 0x5b, 0x56, 0xaf,
  38858. 0xef, 0xc4, 0x3c, 0xff, 0x72, 0x53, 0x95, 0x27, 0x03, 0x49, 0x94, 0x4f,
  38859. 0x94, 0x87, 0x1f, 0x52, 0x33, 0xed, 0xb9, 0x14, 0x7b, 0xe5, 0x6c, 0xef,
  38860. 0x7a, 0x17, 0x5a, 0xa4, 0x89, 0x2a, 0xfe, 0x68, 0xda, 0xdd, 0x48, 0xc2,
  38861. 0xf0, 0x92, 0xf4, 0xe4, 0xd6, 0xa6, 0x48, 0x08, 0x2c, 0xe8, 0xcd, 0x72,
  38862. 0xf6, 0x94, 0x3e, 0xc1, 0x82, 0xb8, 0x01, 0x58, 0xb2, 0xef, 0xef, 0xf4,
  38863. 0xcb, 0x93, 0x63, 0x2e, 0x33, 0x5b, 0xc9, 0xd6, 0x6a, 0xde, 0xad, 0xe8,
  38864. 0x1e, 0x3f, 0xa3, 0xf2, 0x35, 0x87, 0xc1, 0xc9, 0x48, 0x2f, 0x1b, 0x00,
  38865. 0xea, 0x3d, 0x04, 0x29, 0xd5, 0xc0, 0xe9, 0x1a, 0xc5, 0xce, 0x5e, 0xdb,
  38866. 0xd1, 0xee, 0x16, 0x9c, 0x05, 0x40, 0xf9, 0x21, 0x13, 0x72, 0x08, 0x39,
  38867. 0x6b, 0x63, 0x19, 0xcd, 0x6f, 0x64, 0xa0, 0xc3, 0x77, 0xb7, 0x50, 0xed,
  38868. 0xe9, 0x2d, 0xd5, 0x72, 0xea, 0xa6, 0xc1, 0x97, 0xb9, 0x6b, 0xe5, 0x81,
  38869. 0x91, 0x8e, 0xd1, 0x36, 0x11, 0xee, 0xfb, 0x2b, 0x66, 0xba, 0xe4, 0x3e,
  38870. 0xd0, 0xdd, 0x17, 0xc5, 0x24, 0x3b, 0xc3, 0x5b, 0x75, 0xfc, 0xd5, 0xb6,
  38871. 0x8c, 0xba, 0x8c, 0x66, 0xb2, 0xee, 0x40, 0x45, 0x8c, 0x23, 0xbb, 0xe0,
  38872. 0xc8, 0xd6, 0x05, 0xfd, 0x71, 0x5b, 0x24, 0xbb, 0x37, 0x65, 0x5f, 0x57,
  38873. 0x92, 0x22, 0x13, 0xb2, 0x9a, 0x70, 0x22, 0x4b, 0xbe, 0x03, 0xd1, 0x54,
  38874. 0xb0, 0x3a, 0x30, 0x50, 0x71, 0x24, 0xf7, 0x81, 0x8c, 0x20, 0x67, 0x74,
  38875. 0x5a, 0xef, 0xa1, 0x6a, 0xe3, 0xd0, 0x04, 0xd6, 0xa5, 0x6e, 0xad, 0xa7,
  38876. 0x15, 0x41, 0xf3, 0x21, 0xe8, 0xd9, 0xe6, 0xe5, 0x97, 0xbd, 0xc2, 0x1b,
  38877. 0xbb, 0xd1, 0x4e, 0x7e, 0x5a, 0xd6, 0xe4, 0x19, 0xa5, 0xe4, 0x76, 0xf4,
  38878. 0xce, 0x00, 0x94, 0x76, 0xef, 0x1b, 0xb3, 0x47, 0xb9, 0xa3, 0x32, 0xf7,
  38879. 0x45, 0x6d, 0x32, 0x73, 0x06, 0xc0, 0xb9, 0xaf, 0x9c, 0x46, 0x99, 0xbe,
  38880. 0x14, 0x06, 0xcd, 0x35, 0x7c, 0x90, 0x7c, 0xe7, 0x97, 0x0a, 0x9f, 0xb4,
  38881. 0x21, 0xff, 0xf0, 0xea, 0x83, 0xc0, 0x86, 0x68, 0x9f, 0x36, 0xb0, 0xad,
  38882. 0xe1, 0x8d, 0xc5, 0x76, 0x55, 0xb5, 0xb6, 0x7e, 0x1f, 0xa7, 0x5b, 0x26,
  38883. 0x6c, 0xb5, 0xf9, 0x54, 0x1f, 0x76, 0xc1, 0x9c, 0xfc, 0x57, 0xc8, 0x86,
  38884. 0xc1, 0x7d, 0x59, 0x55, 0x92, 0xa5, 0xb8, 0x03, 0xfa, 0xa5, 0x72, 0xd1,
  38885. 0x5c, 0x8d, 0x9b, 0x2e, 0x84, 0x07, 0x18, 0xee, 0x49, 0xc5, 0x99, 0x8e,
  38886. 0x15, 0x7c, 0xbf, 0xad, 0x8b, 0x13, 0xcd, 0x97, 0xf9, 0x3c, 0xa2, 0x89,
  38887. 0x9c, 0x9c, 0x89, 0xc9, 0x7a, 0x46, 0xb3, 0x42, 0x7b, 0xd4, 0x28, 0x0d,
  38888. 0x55, 0x63, 0x28, 0xd6, 0xc1, 0x65, 0xf5, 0x34, 0x6e, 0x38, 0x2a, 0xb4,
  38889. 0x35, 0x40, 0xed, 0x7e, 0x80, 0x61, 0x9d, 0x8f, 0x68, 0x4f, 0x74, 0x0c,
  38890. 0x30, 0x35, 0x0e, 0xb3, 0x07, 0xf4, 0x92, 0xed, 0x9c, 0x7f, 0xf5, 0xed,
  38891. 0x3e, 0x17, 0x5b, 0x6e, 0x91, 0x46, 0xa1, 0x25, 0x1d, 0x83, 0x50, 0x93,
  38892. 0x35, 0x06, 0x6c, 0x2f, 0x99, 0x8b, 0x21, 0x4c, 0x5c, 0x34, 0xb1, 0xa7,
  38893. 0x82, 0xbc, 0x70, 0x28, 0x56, 0x61, 0x29, 0x35, 0x89, 0x0b, 0x41, 0x21,
  38894. 0xf0, 0xf7, 0xff, 0x69, 0x3d, 0xa4, 0x28, 0x1e, 0x0d, 0x5d, 0xa7, 0x0e,
  38895. 0xaa, 0xd3, 0x4a, 0x95, 0x49, 0xfe, 0x35, 0x5f, 0xa9, 0xc0, 0xe4, 0xe1,
  38896. 0x9a, 0x03, 0xd4, 0xac, 0x96, 0xe3, 0xea, 0x7e, 0xa6, 0x85, 0x7e, 0xb0,
  38897. 0xb8, 0xc2, 0xe8, 0x07, 0xd6, 0xd3, 0x1a, 0x84, 0x90, 0x24, 0x04, 0xef,
  38898. 0x7c, 0x93, 0x15, 0x83, 0xea, 0xe2, 0x42, 0xc6, 0xe7, 0x13, 0x45, 0xbf,
  38899. 0x35, 0xae, 0x5d, 0x50, 0x79, 0x16, 0xbb, 0x11, 0x17, 0x1b, 0xf4, 0x08,
  38900. 0x88, 0x9d, 0x66, 0x14, 0x6a, 0xa0, 0x71, 0x76, 0x80, 0x51, 0x73, 0x7c,
  38901. 0x1d, 0xb0, 0xc1, 0xad, 0x58, 0xfb, 0xbe, 0xcf, 0x73, 0xe0, 0xd9, 0xf8,
  38902. 0xd5, 0xac, 0xd7, 0x49, 0xd9, 0xc9, 0x59, 0xbf, 0xfa, 0xf5, 0xb1, 0xd2,
  38903. 0x5a, 0x01, 0xcd, 0x8b, 0x07, 0x8b, 0x59, 0x37, 0xc0, 0x8c, 0x7d, 0xa9,
  38904. 0x71, 0x83, 0xf9, 0x7c, 0x58, 0xa9, 0x77, 0x01, 0x3d, 0x39, 0x56, 0x5c,
  38905. 0x93, 0xfe, 0x40, 0x87, 0x5a, 0x31, 0x81, 0x53, 0x8e, 0x0d, 0x99, 0x7e,
  38906. 0xdf, 0x37, 0xd9, 0xe3, 0x91, 0xb8, 0x60, 0x3a, 0x5b, 0xca, 0xe8, 0x91,
  38907. 0x56, 0x89, 0x59, 0x61, 0xc6, 0x31, 0xe2, 0x6c, 0x81, 0xda, 0xc7, 0x5c,
  38908. 0x04, 0x9d, 0xe4, 0x23, 0x12, 0x73, 0xfc, 0x48, 0xfb, 0xa5, 0xce, 0x87,
  38909. 0x37, 0x47, 0x71, 0x5c, 0xd1, 0x2a, 0x63, 0x89, 0xdc, 0x07, 0xe7, 0x7f,
  38910. 0x5d, 0x48, 0xe6, 0xd2, 0x96, 0xc6, 0x6f, 0xed, 0xee, 0x8c, 0xed, 0x5e,
  38911. 0x41, 0x38, 0xbd, 0xdf, 0x21, 0xaa, 0x9e, 0x51, 0x16, 0x22, 0x4a, 0xdc,
  38912. 0xd8, 0x12, 0xdf, 0x5a, 0x83, 0xd6, 0xd0, 0x07, 0xa4, 0x42, 0x41, 0x13,
  38913. 0xe1, 0x08, 0xc9, 0x00, 0x0f, 0x37, 0xc0, 0x7d, 0xda, 0xb2, 0x25, 0xfc,
  38914. 0xc9, 0xbc, 0xa8, 0x86, 0xcc, 0x38, 0x0e, 0x06, 0x51, 0x1b, 0x37, 0xc1,
  38915. 0x0e, 0x2a, 0x58, 0x49, 0xbc, 0x7c, 0xa7, 0xf0, 0xda, 0xd7, 0x74, 0x34,
  38916. 0xf5, 0xd8, 0x99, 0x8c, 0x94, 0x86, 0xe3, 0x1e, 0x6b, 0xf5, 0x68, 0xfa,
  38917. 0xa6, 0x69, 0x63, 0x22, 0x5a, 0x3c, 0x6f, 0x29, 0xc9, 0x40, 0xc0, 0xbe,
  38918. 0x8d, 0xb5, 0xcc, 0x82, 0x6e, 0x9d, 0xd1, 0x1f, 0x13, 0x63, 0xd8, 0x24,
  38919. 0x63, 0x38, 0x59, 0xf0, 0x4a, 0x8c, 0x0f, 0x28, 0x8a, 0x77, 0x81, 0xa2,
  38920. 0xa0, 0x23, 0x11, 0x59, 0xa9, 0x5a, 0x2d, 0x71, 0x8f, 0x82, 0xa7, 0xbd,
  38921. 0x85, 0x26, 0x4d, 0xc2, 0x2f, 0x11, 0xe8, 0xff, 0x96, 0xa1, 0x2d, 0xf2,
  38922. 0xd5, 0xf3, 0x1d, 0x54, 0xd0, 0x5f, 0x71, 0x07, 0xaf, 0x22, 0xa0, 0xcd,
  38923. 0x78, 0xb3, 0x47, 0xb1, 0x40, 0x3d, 0x6b, 0xfd, 0x10, 0x1b, 0xc6, 0x60,
  38924. 0xef, 0x5c, 0x24, 0xa3, 0x1f, 0xee, 0xc0, 0x0b, 0xed, 0x1d, 0x38, 0xc8,
  38925. 0xf2, 0x8c, 0xec, 0x5e, 0xd9, 0x70, 0x1a, 0x2b, 0x25, 0xe6, 0xed, 0xa9,
  38926. 0x0c, 0xb3, 0x78, 0xe1, 0x91, 0x01, 0x41, 0x2e, 0xfe, 0x7d, 0xbd, 0xfe,
  38927. 0xcf, 0x48, 0x6d, 0x2e, 0x05, 0x31, 0x89, 0x24, 0xc4, 0xd7, 0xc4, 0x26,
  38928. 0x2f, 0x64, 0x43, 0xa3, 0xdd, 0x56, 0x11, 0x5c, 0x65, 0x76, 0x96, 0xcc,
  38929. 0x3c, 0x12, 0x42, 0xf2, 0x6b, 0x20, 0xc2, 0xe6, 0xc3, 0x5c, 0xfa, 0x91,
  38930. 0xb1, 0xbd, 0x3b, 0xd3, 0x99, 0xde, 0x59, 0x7a, 0x34, 0x40, 0x56, 0xb0,
  38931. 0x88, 0x02, 0x19, 0xc8, 0xf9, 0xf9, 0x8f, 0xe7, 0x60, 0xfb, 0x42, 0x87,
  38932. 0x57, 0xb4, 0x42, 0xb4, 0x65, 0x94, 0x0a, 0x5f, 0xdb, 0xf5, 0x32, 0xe9,
  38933. 0x49, 0x28, 0xbe, 0xa6, 0x64, 0x0d, 0x6d, 0x08, 0x43, 0x91, 0x16, 0x7a,
  38934. 0x6c, 0xa9, 0x02, 0xe4, 0x84, 0x03, 0x39, 0x48, 0x08, 0xcc, 0xcb, 0x56,
  38935. 0xad, 0x52, 0x95, 0x9e, 0x9a, 0x2b, 0xf1, 0x6d, 0x3f, 0x4b, 0x02, 0xc6,
  38936. 0x52, 0xc7, 0x09, 0x6b, 0x3f, 0xa9, 0x60, 0xe2, 0x19, 0x5d, 0x0a, 0x61,
  38937. 0xcd, 0xc8, 0x36, 0xdb, 0x8e, 0x57, 0xd2, 0x11, 0x49, 0x1c, 0x26, 0x58,
  38938. 0x04, 0x07, 0x32, 0x2a, 0x34, 0xf0, 0x6a, 0x88, 0xcf, 0x63, 0xb7, 0xef,
  38939. 0x7e, 0x93, 0xcc, 0x64, 0x07, 0x14, 0xfa, 0x63, 0x38, 0xdd, 0xc0, 0xf0,
  38940. 0xaa, 0x56, 0xa1, 0xed, 0x16, 0xaa, 0x53, 0x8c, 0x99, 0xc0, 0xd4, 0xda,
  38941. 0x94, 0x58, 0x13, 0xd9, 0x5f, 0x98, 0x9a, 0xa1, 0x57, 0xbd, 0x89, 0xca,
  38942. 0x9d, 0x3e, 0xdf, 0x75, 0x26, 0x29, 0x0f, 0xb2, 0x33, 0x4b, 0x83, 0xb3,
  38943. 0x99, 0x1f, 0x06, 0x5d, 0x10, 0xf5, 0x1c, 0x75, 0x97, 0xec, 0x5b, 0x87,
  38944. 0xc7, 0xf1, 0xd8, 0xbd, 0x0e, 0x4c, 0x1a, 0xb0, 0x59, 0x3b, 0x27, 0x73,
  38945. 0xdc, 0xde, 0xca, 0x0c, 0x2e, 0x1f, 0x42, 0x7f, 0xd8, 0x0f, 0x9b, 0x3f,
  38946. 0x49, 0x3f, 0x63, 0x7d, 0x71, 0xe3, 0x77, 0x79, 0xcc, 0x9c, 0xbf, 0xff,
  38947. 0x23, 0xa9, 0x74, 0xa2, 0xda, 0xb7, 0xca, 0x86, 0x7f, 0x12, 0xc1, 0x1b,
  38948. 0x41, 0x35, 0xb5, 0xc7, 0x10, 0x09, 0xc0, 0xa2, 0x1b, 0x41, 0x31, 0x5e,
  38949. 0x6c, 0x35, 0xb5, 0x63, 0x13, 0x19, 0x61, 0x8e, 0xbd, 0x89, 0xf6, 0x0a,
  38950. 0xbd, 0x16, 0x15, 0xd8, 0xfa, 0xcc, 0x9f, 0x97, 0x02, 0x8f, 0x1b, 0x34,
  38951. 0x40, 0xbc, 0x4a, 0xb1, 0x39, 0x12, 0xf8, 0x66, 0xda, 0x34, 0x03, 0xf2,
  38952. 0x5c, 0x33, 0x9c, 0x63, 0x0b, 0xb6, 0x8f, 0xca, 0x81, 0xa2, 0x4a, 0x43,
  38953. 0xe7, 0xe7, 0x66, 0x41, 0x45, 0x6b, 0x7c, 0xd1, 0x1d, 0xbc, 0x4f, 0x91,
  38954. 0xab, 0x24, 0x0b, 0x9f, 0x60, 0x47, 0x36, 0x04, 0x8b, 0x72, 0xb6, 0x65,
  38955. 0x35, 0xfc, 0xbf, 0xc9, 0x26, 0xaf, 0x84, 0x04, 0x30, 0x32, 0x02, 0xc0,
  38956. 0x94, 0x98, 0xbc, 0x17, 0x33, 0x99, 0xac, 0xb1, 0x4e, 0xdd, 0xf0, 0x46,
  38957. 0x68, 0x6a, 0xac, 0x6d, 0xdb, 0x85, 0xfd, 0xc6, 0x3b, 0xc8, 0x93, 0x89,
  38958. 0xbf, 0xd7, 0xd9, 0x94, 0xe4, 0xa4, 0x37, 0xb9, 0x67, 0x52, 0x84, 0xcf,
  38959. 0x88, 0xba, 0x01, 0x8b, 0xe4, 0xd4, 0x3e, 0xde, 0x94, 0xa1, 0xa9, 0xd8,
  38960. 0x15, 0xb5, 0x6e, 0xa0, 0x62, 0x92, 0x5c, 0xb1, 0x1b, 0xbf, 0x4f, 0xaf,
  38961. 0xf5, 0x99, 0x35, 0xce, 0x7d, 0xa9, 0x4b, 0xa8, 0x60, 0x31, 0xf5, 0x0a,
  38962. 0x83, 0x58, 0xf5, 0x83, 0xde, 0xb2, 0xfe, 0xf3, 0x12, 0x08, 0x3d, 0xe3,
  38963. 0x14, 0x89, 0x17, 0x93, 0x5c, 0x87, 0xe4, 0x89, 0xcb, 0xb7, 0x67, 0x3e,
  38964. 0xea, 0x0e, 0x08, 0x57, 0xf1, 0xca, 0xe0, 0x18, 0xd7, 0xae, 0x5f, 0x9e,
  38965. 0x62, 0x5c, 0xd7, 0x6a, 0x2f, 0xd6, 0x30, 0x67, 0xfb, 0x5e, 0xed, 0xcf,
  38966. 0xa9, 0x88, 0x04, 0x0a, 0xf2, 0x62, 0x50, 0xc5, 0x39, 0xc6, 0xa1, 0x3c,
  38967. 0xe4, 0x9a, 0x81, 0x55, 0x96, 0xca, 0x60, 0xb2, 0x53, 0x62, 0xee, 0xa1,
  38968. 0x1d, 0xfc, 0xd9, 0x5c, 0x51, 0xbf, 0x55, 0x65, 0x1d, 0x13, 0x2a, 0x13,
  38969. 0x58, 0xa3, 0x18, 0x52, 0x6b, 0xb4, 0xae, 0x60, 0x1c, 0x26, 0x3e, 0xb1,
  38970. 0x4c, 0xb1, 0x72, 0x1b, 0x8a, 0x4c, 0xaa, 0xb5, 0x5b, 0x8a, 0x3b, 0x2f,
  38971. 0x1f, 0xc3, 0x29, 0x41, 0xe6, 0x6d, 0xd7, 0x96, 0x26, 0xdd, 0x37, 0x67,
  38972. 0x4f, 0x9d, 0x31, 0xc6, 0x54, 0x51, 0xaa, 0xba, 0x73, 0xae, 0xd2, 0x00,
  38973. 0x0b, 0x05, 0x98, 0x73, 0xd6, 0x9c, 0xb4, 0x2e, 0x23, 0xd0, 0xc3, 0xac,
  38974. 0x46, 0x6f, 0x3e, 0x05, 0x43, 0xf8, 0x96, 0xa0, 0xe0, 0xfe, 0x17, 0x3f,
  38975. 0xfa, 0xc2, 0xc3, 0xf6, 0x1a, 0x46, 0xd0, 0x05, 0x53, 0x0e, 0xea, 0xd8,
  38976. 0xba, 0xa3, 0xab, 0xb6, 0x58, 0xd1, 0x40, 0x1c, 0x97, 0x38, 0xd4, 0x77,
  38977. 0x58, 0x03, 0xf5, 0x8a, 0xc7, 0x48, 0x19, 0x71, 0x71, 0xb5, 0x4b, 0x08,
  38978. 0x85, 0x35, 0x1c, 0xdf, 0xbd, 0xa9, 0xc9, 0xd1, 0x40, 0x62, 0xa3, 0xd6,
  38979. 0x3b, 0xa1, 0xf7, 0x4e, 0xc6, 0xfe, 0xc4, 0x07, 0x2f, 0xf5, 0xc9, 0x0c,
  38980. 0xb6, 0xa0, 0xb3, 0x25, 0x3e, 0x2a, 0x07, 0xe3, 0x63, 0xe3, 0x9e, 0x8d,
  38981. 0x0d, 0x7a, 0x70, 0x1e, 0x65, 0x95, 0x47, 0x37, 0xa8, 0xd2, 0x35, 0x09,
  38982. 0x09, 0x70, 0xf5, 0xc9, 0xc9, 0x30, 0x95, 0xd9, 0xf2, 0x5d, 0x10, 0x3c,
  38983. 0xc3, 0x66, 0x66, 0xb6, 0xdc, 0x14, 0xf6, 0x91, 0xc2, 0x7b, 0x4b, 0x71,
  38984. 0x42, 0xf9, 0x35, 0xe7, 0x08, 0x1e, 0xb6, 0x9a, 0x5c, 0x0e, 0x8b, 0x41,
  38985. 0x44, 0x7f, 0xad, 0xca, 0x8a, 0x4b, 0x6a, 0x02, 0x81, 0x96, 0xe7, 0xe1,
  38986. 0xb0, 0x5b, 0xaf, 0xf2, 0x17, 0x44, 0x7f, 0xd1, 0x49, 0x77, 0xfd, 0x07,
  38987. 0x59, 0x53, 0x8e, 0x51, 0xac, 0x0f, 0x0c, 0xb4, 0xa3, 0xf6, 0x24, 0x16,
  38988. 0x47, 0xf3, 0xa4, 0x36, 0x17, 0x3e, 0x01, 0x1e, 0xf1, 0xec, 0x78, 0x4a,
  38989. 0xcb, 0xbd, 0x2a, 0xfd, 0x01, 0xdd, 0xa5, 0xad, 0x7b, 0xef, 0x5e, 0x56,
  38990. 0xb2, 0x60, 0xb4, 0xf2, 0x27, 0xc8, 0x9b, 0x5b, 0x31, 0x49, 0x54, 0xbc,
  38991. 0x69, 0x9b, 0xc6, 0x1a, 0x79, 0xe7, 0xd4, 0x46, 0xc8, 0x50, 0xc3, 0xaa,
  38992. 0xfc, 0xb5, 0x28, 0x87, 0x1e, 0xa0, 0x0c, 0xc6, 0x1a, 0xa7, 0x34, 0xd6,
  38993. 0xbb, 0x9d, 0x9c, 0x0d, 0x90, 0x6f, 0x1a, 0x3c, 0xdc, 0x3b, 0x95, 0xc4,
  38994. 0x38, 0x25, 0x7a, 0xc6, 0x46, 0x82, 0x9f, 0x68, 0xca, 0x6a, 0x63, 0xa7,
  38995. 0x99, 0xfe, 0x64, 0xe6, 0x6f, 0x11, 0xcd, 0x2c, 0x76, 0x1e, 0xe6, 0x08,
  38996. 0xb8, 0x33, 0x64, 0x43, 0x51, 0xbd, 0x52, 0xf7, 0x05, 0x06, 0xd5, 0xcc,
  38997. 0x6a, 0xde, 0x1a, 0xa2, 0xbe, 0xf8, 0x8c, 0x44, 0x5e, 0x2d, 0xc2, 0x28,
  38998. 0xcd, 0x9a, 0x53, 0x04, 0x96, 0xcc, 0x1e, 0xbb, 0x96, 0x07, 0xc9, 0x17,
  38999. 0x04, 0xf8, 0xd8, 0xd9, 0xdd, 0x35, 0x35, 0x3d, 0x53, 0x30, 0x60, 0xb3,
  39000. 0x87, 0x5d, 0xf3, 0xe5, 0xa7, 0x20, 0x30, 0x9d, 0xb0, 0x5b, 0xc4, 0x36,
  39001. 0xf7, 0xd7, 0xb6, 0x3e, 0x44, 0x98, 0x99, 0xe7, 0xc3, 0x29, 0xcb, 0x70,
  39002. 0xc4, 0x91, 0x8b, 0xfc, 0x63, 0x60, 0x29, 0x95, 0xeb, 0x61, 0x7f, 0xdf,
  39003. 0xf7, 0x3a, 0x69, 0x3a, 0xeb, 0xa1, 0x73, 0x1d, 0x13, 0x18, 0x29, 0x2c,
  39004. 0x89, 0x82, 0x56, 0x42, 0xe7, 0xa3, 0xba, 0xe9, 0x59, 0x2e, 0xfd, 0xff,
  39005. 0xb6, 0xf7, 0xbd, 0x2a, 0xc9, 0xff, 0x4c, 0x63, 0xef, 0x54, 0x63, 0x82,
  39006. 0x7c, 0xa5, 0x11, 0x44, 0xc7, 0x68, 0xf5, 0x7b, 0x44, 0x2c, 0xee, 0xab,
  39007. 0xa3, 0x84, 0x5a, 0x99, 0x28, 0x98, 0x97, 0x2e, 0x8b, 0x07, 0x09, 0x6c,
  39008. 0xea, 0xc1, 0x81, 0x0b, 0xe0, 0xc4, 0xb7, 0xc2, 0x73, 0xbe, 0x8b, 0x72,
  39009. 0xf8, 0xc9, 0x8d, 0x50, 0x28, 0xf2, 0x95, 0x54, 0x8a, 0x3b, 0x23, 0x86,
  39010. 0xc4, 0xe8, 0xe8, 0xe5, 0x45, 0x0d, 0xdf, 0xa3, 0xe6, 0x00, 0x71, 0xe8,
  39011. 0x20, 0xd2, 0x6d, 0x22, 0x23, 0xaf, 0x37, 0x04, 0x55, 0x05, 0x8d, 0xc9,
  39012. 0x38, 0x38, 0x12, 0x4c, 0x9f, 0x28, 0x56, 0x14, 0x76, 0xe5, 0x10, 0x54,
  39013. 0xd9, 0x68, 0xca, 0xc3, 0x97, 0x9f, 0xd2, 0x25, 0x2c, 0x0d, 0xa0, 0xff,
  39014. 0xea, 0xab, 0x61, 0xd2, 0xb2, 0x06, 0xc2, 0x93, 0xfd, 0x5a, 0xfe, 0xe3,
  39015. 0x98, 0xbf, 0x37, 0x2e, 0xa5, 0x74, 0x56, 0xd0, 0x7a, 0x5a, 0x23, 0x3b,
  39016. 0xd2, 0xa0, 0x1f, 0x4b, 0xeb, 0x7f, 0x5a, 0xc5, 0x51, 0x79, 0xf6, 0x95,
  39017. 0x19, 0x50, 0xb1, 0x6a, 0x80, 0xcb, 0xcf, 0x19, 0xa4, 0x67, 0xf4, 0x08,
  39018. 0x0f, 0x6a, 0xd9, 0x3f, 0x15, 0x96, 0x2c, 0x6d, 0xd5, 0x69, 0x7a, 0x56,
  39019. 0x4d, 0x17, 0xc8, 0xcb, 0xba, 0x9b, 0x6e, 0x65, 0xa2, 0x3d, 0x66, 0xed,
  39020. 0xea, 0xe2, 0x54, 0x88, 0x6c, 0xc1, 0x1a, 0x11, 0xde, 0x4e, 0x0c, 0x8a,
  39021. 0x42, 0x04, 0xe1, 0x77, 0xc3, 0x0c, 0xff, 0x10, 0x7d, 0x4a, 0x45, 0x3f,
  39022. 0xb8, 0x40, 0xf9, 0x75, 0x76, 0x9f, 0x65, 0x42, 0x2f, 0x78, 0x5b, 0x0b,
  39023. 0x32, 0xbc, 0x45, 0xfc, 0xd4, 0x29, 0x49, 0x34, 0x76, 0xda, 0x5f, 0xe8,
  39024. 0x39, 0x35, 0x9e, 0xba, 0x7f, 0x19, 0x7e, 0x14, 0xe6, 0x71, 0x9c, 0x72,
  39025. 0x6a, 0xce, 0xcc, 0xa6, 0x72, 0x73, 0x3f, 0x4e, 0x9b, 0x9e, 0x94, 0x0c,
  39026. 0xce, 0x00, 0x15, 0xb4, 0x50, 0xff, 0xcf, 0xcd, 0x78, 0xd3, 0x08, 0x0e,
  39027. 0x95, 0x48, 0x24, 0x13, 0x16, 0x54, 0xb4, 0xe0, 0xa9, 0x29, 0xa3, 0x05,
  39028. 0x77, 0x2f, 0x5d, 0x47, 0x6a, 0xa5, 0xb0, 0x4e, 0xf3, 0xa9, 0x4a, 0x82,
  39029. 0xb9, 0x2c, 0x26, 0x07, 0x9c, 0x33, 0xc6, 0x68, 0xc2, 0xe0, 0xc0, 0x7d,
  39030. 0x70, 0x48, 0x74, 0xb9, 0xf5, 0x1e, 0x6c, 0x15, 0x7f, 0xba, 0xe5, 0xa1,
  39031. 0xb4, 0x36, 0x41, 0x20, 0xf4, 0x2d, 0x97, 0x27, 0x0b, 0x10, 0x30, 0x57,
  39032. 0x7f, 0x38, 0x66, 0xe1, 0xc4, 0xf6, 0xa4, 0xc9, 0x8d, 0xbc, 0x2b, 0x4f,
  39033. 0x14, 0xb3, 0xf0, 0x1e, 0x80, 0x70, 0xc0, 0x0f, 0x69, 0x06, 0xe7, 0x95,
  39034. 0xd1, 0x53, 0x65, 0x49, 0x1c, 0xa8, 0xfa, 0x9e, 0x2b, 0xcc, 0x33, 0x71,
  39035. 0x76, 0xa4, 0x0b, 0x4a, 0xc7, 0xea, 0xa0, 0xfa, 0x1b, 0x2b, 0xfb, 0xa5,
  39036. 0x59, 0x06, 0x2a, 0xef, 0x4b, 0xbf, 0x05, 0x4b, 0x87, 0x70, 0x3c, 0xde,
  39037. 0xc7, 0xb2, 0x4f, 0xf2, 0x5b, 0x1a, 0xbe, 0xda, 0x04, 0x31, 0x57, 0xff,
  39038. 0xf2, 0xa5, 0x43, 0x12, 0xff, 0x8d, 0xf4, 0x99, 0x05, 0xe1, 0x34, 0xa9,
  39039. 0xb9, 0x0a, 0xb3, 0x1f, 0x3d, 0x6d, 0x0d, 0xb7, 0xd3, 0x35, 0x0b, 0x04,
  39040. 0x44, 0x77, 0x60, 0xc0, 0x96, 0x99, 0x7b, 0xa8, 0x8e, 0x79, 0x4a, 0x96,
  39041. 0x24, 0xef, 0xb1, 0xf4, 0x8a, 0x2f, 0x3e, 0x08, 0xf3, 0x3d, 0xf2, 0xfe,
  39042. 0x5f, 0x0a, 0xf7, 0x0a, 0xf5, 0xd8, 0xf2, 0xa0, 0x1b, 0xe7, 0x9e, 0xc9,
  39043. 0x0b, 0xcf, 0x58, 0x97, 0x92, 0x90, 0xad, 0x3d, 0xfc, 0x42, 0xc1, 0x7f,
  39044. 0x39, 0xe8, 0xd1, 0x35, 0x14, 0x8a, 0xb3, 0x77, 0xb1, 0xa9, 0xdb, 0xb4,
  39045. 0x3a, 0x3d, 0xeb, 0x59, 0x0b, 0x5b, 0x3a, 0x63, 0x54, 0x70, 0xda, 0xf0,
  39046. 0xf0, 0xb9, 0xe6, 0x07, 0x69, 0x27, 0x9d, 0xc6, 0xb6, 0x00, 0x2d, 0xd6,
  39047. 0xc7, 0xd7, 0x2e, 0xf8, 0x9c, 0xfe, 0x4c, 0xfb, 0xc0, 0x7b, 0xbf, 0xa2,
  39048. 0x25, 0xb8, 0x2a, 0x5c, 0x06, 0xca, 0x12, 0x2c, 0x96, 0xa4, 0x27, 0xa6,
  39049. 0x73, 0x0b, 0xb8, 0x42, 0x93, 0x51, 0x87, 0xfe, 0xe6, 0x8f, 0xca, 0x00,
  39050. 0x53, 0xdc, 0xc0, 0x38, 0x03, 0x9e, 0x66, 0x13, 0x84, 0x68, 0xe7, 0x04,
  39051. 0x93, 0x79, 0x0c, 0x3e, 0x4c, 0x90, 0xe2, 0xf7, 0x81, 0x15, 0x49, 0x05,
  39052. 0xe1, 0x8f, 0xe6, 0xfc, 0xc8, 0x40, 0xae, 0x3d, 0x7a, 0x16, 0xec, 0xc6,
  39053. 0x39, 0xa5, 0x04, 0x95, 0x35, 0xac, 0xdd, 0x0d, 0x19, 0xd6, 0xa9, 0xd9,
  39054. 0xd2, 0x53, 0x71, 0x31, 0x38, 0xa2, 0xf1, 0x9c, 0x13, 0x2c, 0x8c, 0x21,
  39055. 0x9c, 0x3a, 0x1b, 0xf2, 0xd8, 0x4c, 0xeb, 0xe9, 0x8b, 0x27, 0x52, 0xd3,
  39056. 0x6c, 0x01, 0xc0, 0x60, 0x32, 0x8c, 0x6e, 0xfb, 0xd6, 0xd6, 0x1b, 0xc6,
  39057. 0x93, 0xff, 0xdc, 0xdb, 0x38, 0xf5, 0x0e, 0xd5, 0x15, 0xcd, 0x65, 0x76,
  39058. 0x78, 0x42, 0x13, 0x37, 0x6b, 0x2e, 0xe8, 0xe2, 0x54, 0x4d, 0x45, 0x34,
  39059. 0x73, 0x1b, 0x61, 0x35, 0x2c, 0xf7, 0x20, 0x3e, 0xe9, 0x7c, 0xf0, 0xf3,
  39060. 0xba, 0x41, 0xfc, 0x49, 0xe4, 0x5d, 0xd4, 0xb8, 0x07, 0x15, 0x7b, 0x16,
  39061. 0xc7, 0x7f, 0x78, 0xef, 0xd6, 0x53, 0x3f, 0xe4, 0xa6, 0x33, 0xcf, 0xcc,
  39062. 0x78, 0x53, 0x0c, 0x59, 0xf7, 0x28, 0xa5, 0x83, 0x2b, 0x5a, 0xd3, 0xd6,
  39063. 0xb7, 0xb2, 0xd1, 0x73, 0x63, 0xa9, 0xad, 0x16, 0xf2, 0xed, 0x48, 0x6e,
  39064. 0x88, 0x22, 0xbd, 0x16, 0x9d, 0x6a, 0xc2, 0x48, 0x83, 0xdf, 0x40, 0xb7,
  39065. 0x0a, 0x50, 0x23, 0x3d, 0x58, 0x50, 0x00, 0x02, 0x04, 0xd2, 0x31, 0x72,
  39066. 0x28, 0x7b, 0x10, 0x96, 0xe0, 0xe7, 0x3f, 0xe0, 0xd0, 0x61, 0x70, 0x5c,
  39067. 0x0a, 0xdb, 0xc0, 0x7b, 0xea, 0xef, 0xba, 0xc0, 0x90, 0xe0, 0xf9, 0x0e,
  39068. 0x83, 0x8c, 0x3b, 0x05, 0x2b, 0xb6, 0xcb, 0xbb, 0x37, 0xa1, 0xd3, 0x28,
  39069. 0x02, 0x40, 0xe3, 0x76, 0xbf, 0x27, 0x0b, 0x4f, 0x82, 0xb9, 0x22, 0xee,
  39070. 0x0b, 0x3a, 0xcb, 0xcc, 0x56, 0x13, 0x51, 0xb8, 0xb6, 0x2d, 0xd3, 0x6c,
  39071. 0x96, 0x10, 0xd9, 0x51, 0x24, 0x7b, 0x2b, 0xb8, 0x7b, 0xbd, 0x8d, 0xd9,
  39072. 0xf2, 0x50, 0x61, 0xbb, 0x0c, 0xb7, 0x71, 0x65, 0x3a, 0x25, 0x18, 0x09,
  39073. 0x1a, 0x9d, 0x41, 0xf4, 0xdb, 0x5a, 0x1c, 0x61, 0x0a, 0xbb, 0x43, 0x27,
  39074. 0x8a, 0xa8, 0x83, 0x60, 0x8c, 0x5d, 0x4c, 0x9b, 0xa9, 0xe5, 0xa7, 0x67,
  39075. 0x99, 0x98, 0xdc, 0x7a, 0x3a, 0x55, 0x0d, 0x25, 0x69, 0x47, 0x21, 0xb1,
  39076. 0xd7, 0x0c, 0x0c, 0x43, 0x58, 0xc9, 0xbf, 0x74, 0x91, 0x1b, 0x2b, 0xf3,
  39077. 0x29, 0x8d, 0x10, 0x41, 0xaf, 0xdd, 0x42, 0x0a, 0x71, 0xe3, 0xb8, 0x4d,
  39078. 0x3a, 0xf3, 0x9c, 0x5a, 0x46, 0x4e, 0x70, 0xbe, 0xdb, 0x0d, 0x03, 0xee,
  39079. 0xcb, 0xfb, 0x61, 0x45, 0xbd, 0x25, 0xb4, 0x72, 0xd1, 0x51, 0x03, 0x19,
  39080. 0x82, 0x53, 0x83, 0x18, 0xab, 0xa3, 0x6c, 0x9e, 0xa2, 0xe9, 0x15, 0xb1,
  39081. 0x74, 0x61, 0xa1, 0xaf, 0x09, 0x4b, 0x4a, 0x34, 0x9b, 0xd0, 0xd2, 0x80,
  39082. 0x43, 0xd9, 0x90, 0x53, 0x71, 0x38, 0xb9, 0x80, 0x58, 0x1b, 0x9f, 0x9e,
  39083. 0xfe, 0x07, 0x1b, 0x33, 0x24, 0xb2, 0x58, 0x7f, 0x01, 0xbe, 0xe8, 0x25,
  39084. 0x53, 0x08, 0x06, 0x77, 0x7d, 0x5a, 0x16, 0x83, 0x67, 0x91, 0x0b, 0xa2,
  39085. 0xd2, 0x1e, 0x5f, 0x9c, 0x39, 0xda, 0x57, 0xbc, 0x67, 0xc5, 0x39, 0xbe,
  39086. 0xb9, 0x73, 0x03, 0x19, 0x97, 0x34, 0x4f, 0x1e, 0x6b, 0x4d, 0x87, 0xef,
  39087. 0x79, 0x4f, 0xd1, 0xdd, 0x80, 0x13, 0xbe, 0x3b, 0x0f, 0xea, 0x77, 0x9a,
  39088. 0x1a, 0x46, 0x63, 0xc5, 0x2f, 0x93, 0xfe, 0x18, 0x71, 0xfb, 0x70, 0xbf,
  39089. 0x85, 0x3b, 0x3e, 0x54, 0xe6, 0xf8, 0xe0, 0xb9, 0xd0, 0x9d, 0xf5, 0x2b,
  39090. 0x12, 0x22, 0x39, 0x6a, 0x8d, 0x13, 0xa1, 0x3a, 0x95, 0xd0, 0xe7, 0x07,
  39091. 0xa4, 0x2c, 0x33, 0xba, 0x43, 0x1d, 0xd8, 0xb5, 0xd0, 0x8e, 0x6c, 0x85,
  39092. 0x6f, 0xf8, 0x8f, 0xd3, 0x72, 0x65, 0xc1, 0xff, 0x8f, 0xf6, 0xb5, 0x19,
  39093. 0x59, 0x34, 0xf9, 0xe8, 0xdb, 0xf3, 0x10, 0x68, 0xbd, 0xd5, 0x59, 0xf7,
  39094. 0xe5, 0xf2, 0x84, 0x98, 0x8d, 0xd6, 0x6f, 0xcc, 0xde, 0xc5, 0xee, 0xf7,
  39095. 0x16, 0xca, 0xec, 0xc4, 0x00, 0x89, 0x2e, 0x0d, 0x0d, 0xb6, 0xa8, 0xe0,
  39096. 0x9a, 0xb0, 0xe5, 0x8e, 0xb6, 0x64, 0x47, 0x7d, 0x01, 0x59, 0x8a, 0x90,
  39097. 0xa6, 0x9b, 0x2b, 0x63, 0xad, 0x70, 0xc8, 0x07, 0x36, 0x3e, 0xa9, 0x8f,
  39098. 0xd9, 0xc2, 0xf7, 0x4b, 0xec, 0x95, 0x53, 0xec, 0x6b, 0x2d, 0x1f, 0xb5,
  39099. 0x91, 0xbf, 0x9f, 0xc5, 0x85, 0x61, 0x3a, 0xc7, 0x5c, 0x15, 0x2a, 0x0b,
  39100. 0x4b, 0x3c, 0x38, 0x6d, 0xc9, 0x2c, 0x91, 0x11, 0xc6, 0x6b, 0x44, 0x71,
  39101. 0x9f, 0x89, 0xd5, 0xde, 0x27, 0x99, 0x81, 0xa2, 0x59, 0x8b, 0x57, 0x97,
  39102. 0x83, 0x46, 0x33, 0xe1, 0x8c, 0xdf, 0xcf, 0x5b, 0x6b, 0xb3, 0x0e, 0x17,
  39103. 0x1a, 0xb8, 0x7d, 0x6e, 0x71, 0xe5, 0xc8, 0x4c, 0xa9, 0xe2, 0x52, 0x81,
  39104. 0xf6, 0x2f, 0x3a, 0xef, 0x5a, 0x1b, 0x6b, 0x7b, 0x61, 0x51, 0xcb, 0xd5,
  39105. 0x7b, 0x5f, 0xf0, 0x1c, 0xb8, 0xeb, 0x9a, 0xe4, 0x0a, 0x6e, 0x53, 0x59,
  39106. 0x2e, 0x2d, 0x78, 0x27, 0xb7, 0x47, 0x35, 0x1a, 0x01, 0x25, 0x0a, 0xcc,
  39107. 0x67, 0xae, 0xda, 0xaf, 0xfe, 0x22, 0x63, 0xe8, 0xa2, 0x1c, 0x34, 0xe6,
  39108. 0x6b, 0x73, 0xcf, 0x6f, 0x3e, 0x0a, 0x4a, 0x36, 0xbc, 0xda, 0x43, 0xbc,
  39109. 0x5e, 0x9c, 0x91, 0xe4, 0x8b, 0x34, 0x2e, 0x09, 0x87, 0x69, 0x96, 0x93,
  39110. 0xb4, 0xff, 0x97, 0xbc, 0x4e, 0xd6, 0xa2, 0xb4, 0x16, 0x78, 0x7c, 0x62,
  39111. 0xd0, 0x78, 0x3f, 0x37, 0xdb, 0xf2, 0x92, 0xad, 0x9b, 0x51, 0x77, 0x08,
  39112. 0x19, 0xd2, 0x09, 0x12, 0xf7, 0x52, 0xe8, 0xc8, 0xb2, 0xfb, 0x6f, 0xcd,
  39113. 0x05, 0x5b, 0xd2, 0x8e, 0x0d, 0x6e, 0x0c, 0x16, 0x5b, 0x8a, 0xc2, 0x09,
  39114. 0x13, 0x3b, 0x69, 0x85, 0xbd, 0xc0, 0xcc, 0x2b, 0x48, 0x65, 0xa7, 0xc1,
  39115. 0xc3, 0xe0, 0xea, 0x14, 0x67, 0x6f, 0xa4, 0xb8, 0xc6, 0xf0, 0x12, 0x3e,
  39116. 0x96, 0x0d, 0x23, 0x2b, 0x37, 0x87, 0x8d, 0xc8, 0xf7, 0x00, 0x00, 0x00,
  39117. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39118. 0x00, 0x00, 0x00, 0x03, 0x0b, 0x13, 0x1a, 0x1d, 0x25
  39119. #else
  39120. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  39121. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  39122. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  39123. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  39124. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  39125. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  39126. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  39127. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  39128. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  39129. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  39130. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  39131. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  39132. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  39133. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  39134. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  39135. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  39136. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  39137. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  39138. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  39139. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  39140. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  39141. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  39142. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  39143. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  39144. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  39145. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  39146. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  39147. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  39148. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  39149. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  39150. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  39151. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  39152. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  39153. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  39154. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  39155. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  39156. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  39157. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  39158. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  39159. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  39160. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  39161. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  39162. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  39163. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  39164. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  39165. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  39166. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  39167. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  39168. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  39169. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  39170. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  39171. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  39172. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  39173. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  39174. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  39175. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  39176. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  39177. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  39178. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  39179. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  39180. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  39181. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  39182. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  39183. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  39184. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  39185. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  39186. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  39187. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  39188. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  39189. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  39190. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  39191. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  39192. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  39193. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  39194. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  39195. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  39196. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  39197. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  39198. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  39199. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  39200. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  39201. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  39202. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  39203. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  39204. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  39205. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  39206. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  39207. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  39208. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  39209. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  39210. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  39211. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  39212. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  39213. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  39214. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  39215. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  39216. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  39217. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  39218. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  39219. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  39220. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  39221. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  39222. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  39223. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  39224. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  39225. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  39226. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  39227. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  39228. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  39229. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  39230. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  39231. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  39232. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  39233. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  39234. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  39235. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  39236. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  39237. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  39238. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  39239. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  39240. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  39241. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  39242. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  39243. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  39244. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  39245. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  39246. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  39247. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  39248. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  39249. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  39250. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  39251. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  39252. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  39253. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  39254. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  39255. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  39256. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  39257. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  39258. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  39259. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  39260. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  39261. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  39262. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  39263. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  39264. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  39265. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  39266. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  39267. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  39268. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  39269. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  39270. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  39271. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  39272. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  39273. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  39274. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  39275. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  39276. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  39277. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  39278. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  39279. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  39280. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  39281. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  39282. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  39283. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  39284. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  39285. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  39286. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  39287. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  39288. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  39289. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  39290. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  39291. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  39292. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  39293. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  39294. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  39295. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  39296. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  39297. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  39298. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  39299. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  39300. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  39301. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  39302. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  39303. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  39304. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  39305. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  39306. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  39307. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  39308. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  39309. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  39310. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  39311. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  39312. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  39313. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  39314. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  39315. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  39316. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  39317. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  39318. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  39319. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  39320. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  39321. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  39322. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  39323. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  39324. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  39325. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  39326. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  39327. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  39328. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  39329. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  39330. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  39331. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  39332. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  39333. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  39334. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  39335. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  39336. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  39337. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  39338. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  39339. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  39340. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  39341. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  39342. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  39343. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  39344. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  39345. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  39346. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  39347. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  39348. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  39349. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  39350. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  39351. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  39352. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  39353. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  39354. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  39355. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  39356. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  39357. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  39358. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  39359. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  39360. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  39361. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  39362. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  39363. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  39364. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  39365. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  39366. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  39367. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  39368. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  39369. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  39370. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  39371. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  39372. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  39373. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  39374. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  39375. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  39376. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  39377. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  39378. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  39379. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  39380. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  39381. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  39382. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  39383. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  39384. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  39385. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  39386. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  39387. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  39388. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  39389. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  39390. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  39391. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  39392. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  39393. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  39394. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  39395. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  39396. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  39397. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  39398. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  39399. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  39400. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  39401. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  39402. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  39403. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  39404. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  39405. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  39406. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  39407. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  39408. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  39409. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  39410. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  39411. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  39412. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  39413. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  39414. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  39415. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  39416. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  39417. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  39418. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  39419. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  39420. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  39421. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  39422. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  39423. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  39424. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  39425. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  39426. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  39427. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  39428. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  39429. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  39430. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  39431. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  39432. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  39433. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  39434. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  39435. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  39436. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  39437. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  39438. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  39439. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  39440. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  39441. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  39442. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  39443. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  39444. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  39445. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  39446. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  39447. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  39448. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  39449. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39450. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28
  39451. #endif
  39452. };
  39453. return dilithium_param_vfy_test(WC_ML_DSA_65, ml_dsa_65_pub_key,
  39454. (word32)sizeof(ml_dsa_65_pub_key), ml_dsa_65_sig,
  39455. (word32)sizeof(ml_dsa_65_sig));
  39456. }
  39457. #endif
  39458. #ifndef WOLFSSL_NO_ML_DSA_87
  39459. static wc_test_ret_t dilithium_param_87_vfy_test(void)
  39460. {
  39461. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_pub_key[] = {
  39462. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39463. 0x8a, 0x66, 0xe3, 0x6e, 0x3c, 0x11, 0x70, 0x9f, 0x82, 0xdd, 0xeb, 0x9e,
  39464. 0xc0, 0xd7, 0x25, 0x87, 0x0c, 0x65, 0x07, 0x9d, 0x47, 0x39, 0x5d, 0x04,
  39465. 0x42, 0x5c, 0xd6, 0x0a, 0xdc, 0x39, 0x44, 0x04, 0xd9, 0x79, 0x43, 0x87,
  39466. 0x98, 0x64, 0x88, 0x82, 0x3a, 0x31, 0xbd, 0xec, 0x66, 0xcb, 0x01, 0x90,
  39467. 0xf9, 0x85, 0xcc, 0xde, 0x54, 0x69, 0x7d, 0x84, 0xb3, 0x84, 0x3c, 0x42,
  39468. 0x0d, 0x09, 0x63, 0xdb, 0xe6, 0x5d, 0xc2, 0x8a, 0xcf, 0xe1, 0xf4, 0x86,
  39469. 0x13, 0x05, 0x09, 0x9a, 0x4d, 0x05, 0xd4, 0x31, 0xe7, 0x27, 0x39, 0xfd,
  39470. 0x3a, 0xdb, 0x63, 0x9f, 0x1c, 0x67, 0x0b, 0x01, 0xec, 0xf9, 0xff, 0xf3,
  39471. 0xda, 0xa9, 0xf4, 0x9a, 0x59, 0x52, 0x76, 0xc2, 0xd2, 0xd5, 0xdd, 0x8d,
  39472. 0xb1, 0xa2, 0xef, 0xb3, 0x73, 0x99, 0xe3, 0xcd, 0x1c, 0xf5, 0xca, 0x6e,
  39473. 0x39, 0xfa, 0x26, 0x83, 0x45, 0xe7, 0xd0, 0x9c, 0x1b, 0xf7, 0xb2, 0x64,
  39474. 0xf1, 0x70, 0x00, 0x10, 0xc0, 0x7c, 0x7f, 0xb2, 0x32, 0xce, 0x6d, 0x71,
  39475. 0xa5, 0x43, 0x7c, 0x40, 0x71, 0x09, 0x54, 0x74, 0xac, 0xb5, 0xeb, 0xe0,
  39476. 0x04, 0x02, 0xe5, 0x82, 0x4d, 0x5a, 0x85, 0x1e, 0x19, 0x86, 0x39, 0x33,
  39477. 0x92, 0x2f, 0xa9, 0xa8, 0x10, 0xd2, 0x31, 0x60, 0x16, 0x08, 0x99, 0xe3,
  39478. 0x2c, 0x93, 0x13, 0xc4, 0x4b, 0x10, 0xe0, 0x42, 0xca, 0x3f, 0x32, 0xa7,
  39479. 0xa4, 0xd2, 0xfc, 0x9c, 0x93, 0xb6, 0x5f, 0xe2, 0x5b, 0x6e, 0x40, 0x0c,
  39480. 0x63, 0xf8, 0xf8, 0xe1, 0x2d, 0xcd, 0x86, 0x07, 0x79, 0xdb, 0x61, 0xad,
  39481. 0x24, 0xfd, 0x1e, 0x66, 0x3e, 0x8d, 0x76, 0xba, 0x98, 0x8e, 0x94, 0xc7,
  39482. 0x57, 0xb1, 0x65, 0xce, 0x4f, 0x97, 0xfa, 0x34, 0x7c, 0x97, 0x6b, 0xcd,
  39483. 0x3c, 0x42, 0x81, 0xa4, 0xd1, 0x75, 0xeb, 0x6d, 0x0c, 0x31, 0x0e, 0x6f,
  39484. 0xd5, 0x75, 0xe7, 0xff, 0x83, 0xdd, 0x7a, 0x4d, 0x83, 0x67, 0xa7, 0x4b,
  39485. 0xc1, 0x74, 0xad, 0x37, 0x38, 0x99, 0xe0, 0xf5, 0x5a, 0x44, 0x36, 0xa2,
  39486. 0x20, 0x2b, 0xfc, 0xc9, 0xfa, 0x68, 0xcb, 0xf0, 0x6f, 0x0a, 0x46, 0x1d,
  39487. 0xb5, 0xca, 0x5b, 0x96, 0x1b, 0x3a, 0xaf, 0x7d, 0x01, 0x7a, 0xd2, 0x09,
  39488. 0xcc, 0xd4, 0xe4, 0xb1, 0x49, 0x34, 0x56, 0x68, 0x9c, 0x0f, 0x23, 0xe9,
  39489. 0xb3, 0x4b, 0xed, 0x3d, 0xe7, 0x8d, 0x19, 0x6e, 0xe6, 0xfa, 0x06, 0x55,
  39490. 0xb8, 0x06, 0x4d, 0xa8, 0x45, 0x20, 0x91, 0xf7, 0xfa, 0x0b, 0x6b, 0xce,
  39491. 0x55, 0xa7, 0x14, 0x1b, 0xf9, 0xea, 0xc5, 0x79, 0x78, 0xf7, 0x3a, 0xd9,
  39492. 0xfc, 0x07, 0x43, 0x06, 0x90, 0x94, 0x5e, 0xc9, 0x48, 0x51, 0xe5, 0x96,
  39493. 0x68, 0x78, 0xc8, 0xcb, 0xd1, 0xf3, 0x65, 0xef, 0x14, 0x91, 0xa3, 0xca,
  39494. 0x8b, 0x77, 0x40, 0x84, 0xf4, 0x2e, 0xe7, 0x56, 0xe3, 0xab, 0xa0, 0xa8,
  39495. 0x61, 0x93, 0x17, 0x95, 0x9e, 0xff, 0x3a, 0xd4, 0x12, 0xea, 0x13, 0xe6,
  39496. 0x82, 0x16, 0xed, 0x14, 0x70, 0x91, 0xcc, 0x72, 0x58, 0x99, 0xa1, 0x7f,
  39497. 0xf3, 0x84, 0x10, 0xf4, 0x01, 0x0d, 0x05, 0x45, 0x4d, 0xca, 0x05, 0x03,
  39498. 0x75, 0x7e, 0xbb, 0x44, 0x2e, 0xf5, 0xee, 0xed, 0x64, 0x9b, 0xd3, 0xde,
  39499. 0x3e, 0xfc, 0x31, 0x8c, 0xca, 0x23, 0x66, 0x25, 0xac, 0x5f, 0x0f, 0x33,
  39500. 0x0f, 0xd2, 0xe9, 0xc9, 0x96, 0x2a, 0xe2, 0xb8, 0xed, 0x93, 0xd3, 0x78,
  39501. 0xd8, 0x81, 0xe4, 0x52, 0x9a, 0xc6, 0x64, 0x1d, 0x2d, 0x5f, 0x93, 0x9a,
  39502. 0x2e, 0x73, 0xc4, 0x17, 0xae, 0xc6, 0x08, 0x0d, 0x2d, 0xe9, 0x4b, 0x10,
  39503. 0x29, 0xa8, 0x4e, 0x8c, 0x08, 0x59, 0x87, 0x10, 0x0d, 0x5d, 0xfa, 0xec,
  39504. 0xd6, 0x42, 0xf6, 0x5c, 0xa4, 0x0d, 0xaa, 0x64, 0x8e, 0x20, 0xa5, 0x50,
  39505. 0x9f, 0x0b, 0x85, 0x37, 0x57, 0x15, 0x7c, 0xb1, 0xe4, 0xdd, 0xd5, 0x19,
  39506. 0x3b, 0x10, 0x7d, 0x22, 0xdb, 0x53, 0x8b, 0x7b, 0x32, 0xf7, 0xf2, 0x24,
  39507. 0x92, 0xb2, 0x05, 0xd1, 0xfd, 0xfc, 0x11, 0xd6, 0xfd, 0x3c, 0x8d, 0xd7,
  39508. 0xb0, 0x58, 0x50, 0x06, 0x84, 0x61, 0xa6, 0x78, 0x04, 0x1d, 0x7f, 0x92,
  39509. 0x0e, 0x8b, 0xb3, 0x63, 0x43, 0xc5, 0x30, 0x4c, 0xce, 0x2b, 0x44, 0x70,
  39510. 0x53, 0x7c, 0xb5, 0xbd, 0x30, 0xcb, 0x41, 0x19, 0x27, 0x69, 0xfe, 0x41,
  39511. 0x92, 0xae, 0xf0, 0x37, 0x33, 0xf0, 0x95, 0xe4, 0xe8, 0x4f, 0x75, 0x41,
  39512. 0x64, 0x87, 0xc5, 0x68, 0xd3, 0xce, 0xfa, 0xaa, 0xe8, 0x59, 0x88, 0xfe,
  39513. 0x24, 0x46, 0x27, 0x60, 0x71, 0x36, 0x78, 0x66, 0x3c, 0x36, 0x8e, 0xdb,
  39514. 0x90, 0x67, 0xa5, 0x6a, 0xfe, 0xd3, 0x23, 0x28, 0x91, 0x34, 0x24, 0x67,
  39515. 0x4b, 0x01, 0x6a, 0x0e, 0x02, 0xb7, 0xf0, 0xa8, 0xd4, 0x76, 0xd5, 0xa8,
  39516. 0x1c, 0xd3, 0xb3, 0x7d, 0x74, 0xc6, 0x17, 0x96, 0xa7, 0xf9, 0xad, 0x24,
  39517. 0x36, 0xd2, 0xeb, 0x34, 0x5a, 0xcc, 0x9c, 0x01, 0x99, 0xbe, 0x21, 0x4f,
  39518. 0x27, 0x9d, 0x6b, 0xca, 0x27, 0x1b, 0x60, 0x51, 0x41, 0x23, 0xe1, 0xcb,
  39519. 0xfc, 0x17, 0x2e, 0x1a, 0x4d, 0x3d, 0x51, 0xb3, 0x91, 0x8c, 0x53, 0x4d,
  39520. 0xd7, 0xbc, 0xa4, 0x07, 0xd7, 0x17, 0x19, 0x18, 0x61, 0x38, 0x4e, 0x05,
  39521. 0x81, 0x3f, 0x43, 0x8a, 0x00, 0x60, 0xdc, 0x30, 0xf4, 0x38, 0x3f, 0x93,
  39522. 0x82, 0x10, 0x29, 0x73, 0xa9, 0xbd, 0x63, 0x15, 0x7d, 0xac, 0x2e, 0xc9,
  39523. 0x05, 0xc1, 0x01, 0x41, 0x18, 0x5a, 0xc0, 0xc8, 0xc7, 0x81, 0x69, 0xe7,
  39524. 0x24, 0x21, 0x57, 0xaf, 0x88, 0x73, 0x7c, 0x53, 0x29, 0xae, 0x5a, 0xdf,
  39525. 0x76, 0x37, 0x56, 0x4f, 0x1f, 0x6b, 0xfd, 0x71, 0xbb, 0x80, 0x4a, 0xd7,
  39526. 0x53, 0x50, 0x10, 0x2d, 0xfc, 0x1a, 0xaf, 0x7c, 0x1f, 0xe8, 0xd0, 0x6c,
  39527. 0xa6, 0x45, 0x3d, 0xb5, 0x3d, 0xb2, 0xfc, 0x97, 0xa9, 0xbf, 0x7c, 0x0f,
  39528. 0x32, 0x7a, 0xcc, 0xa9, 0x2f, 0xd0, 0xc6, 0xe6, 0xcd, 0x04, 0x1d, 0x71,
  39529. 0x91, 0xb9, 0x59, 0x4b, 0xad, 0xa0, 0xde, 0x9e, 0xdc, 0x9c, 0x10, 0xeb,
  39530. 0x8d, 0xd6, 0x65, 0x57, 0xbc, 0x96, 0xfd, 0x0f, 0xcc, 0x73, 0xbe, 0x39,
  39531. 0x27, 0x99, 0x94, 0xf5, 0xe1, 0xbb, 0x32, 0xcd, 0x27, 0x7e, 0x08, 0xa0,
  39532. 0xd2, 0x92, 0x39, 0xeb, 0x71, 0xc8, 0xe8, 0x34, 0x57, 0x34, 0x4b, 0x20,
  39533. 0x3f, 0xe2, 0x68, 0xec, 0xc0, 0x8a, 0x71, 0xa3, 0x16, 0xa2, 0x91, 0x77,
  39534. 0xde, 0x41, 0x12, 0xa5, 0xf5, 0x2a, 0x63, 0x60, 0x55, 0xd0, 0x33, 0xa4,
  39535. 0xa7, 0x2e, 0xcb, 0x80, 0x08, 0xe5, 0x76, 0x16, 0x75, 0x04, 0x57, 0xe3,
  39536. 0x14, 0x71, 0x4e, 0x57, 0x29, 0x23, 0x0e, 0xc0, 0xcc, 0xad, 0xba, 0xdc,
  39537. 0x96, 0x5d, 0x23, 0x49, 0x42, 0xd8, 0x91, 0x08, 0x0d, 0x52, 0xf4, 0x5f,
  39538. 0xcd, 0xb7, 0x03, 0xaa, 0x73, 0x26, 0xa8, 0xd5, 0x5b, 0x0c, 0x85, 0xc8,
  39539. 0x84, 0x50, 0x9e, 0x70, 0x18, 0x45, 0x27, 0x82, 0x20, 0x75, 0xad, 0x52,
  39540. 0x5c, 0x80, 0x4b, 0xb1, 0x0b, 0x3b, 0x30, 0x39, 0x02, 0x54, 0x18, 0x5d,
  39541. 0x02, 0x9e, 0x85, 0x31, 0x4a, 0x07, 0x9c, 0x59, 0x5d, 0xab, 0x13, 0x4f,
  39542. 0x8f, 0x6e, 0x39, 0x20, 0xb2, 0xc5, 0x31, 0x93, 0xc6, 0xcc, 0xfb, 0xdc,
  39543. 0x15, 0xba, 0x3d, 0xcc, 0xbb, 0xd2, 0x6f, 0x04, 0x21, 0xdf, 0x0b, 0x27,
  39544. 0x5c, 0xd2, 0x6e, 0xfa, 0xda, 0x86, 0x5d, 0xe4, 0xca, 0xa4, 0x90, 0x22,
  39545. 0xa2, 0x80, 0xb5, 0x33, 0x17, 0xdb, 0x9b, 0x7b, 0x0a, 0xcc, 0x0f, 0x9b,
  39546. 0x38, 0x06, 0xdf, 0x10, 0x11, 0xa1, 0xd7, 0x2c, 0x24, 0xf0, 0xa8, 0x34,
  39547. 0x24, 0xfb, 0x99, 0xba, 0x0a, 0xb5, 0xa1, 0x94, 0x6c, 0x2d, 0xf8, 0xda,
  39548. 0x74, 0xaf, 0x19, 0x59, 0x84, 0xb2, 0x68, 0x1c, 0xef, 0xa1, 0xf5, 0x18,
  39549. 0x8f, 0x10, 0xf6, 0xb3, 0x6d, 0x33, 0x87, 0xe0, 0x25, 0xc8, 0x65, 0x5c,
  39550. 0x2f, 0x51, 0x07, 0x83, 0x69, 0x1b, 0xce, 0xa8, 0xe6, 0xe4, 0x27, 0x62,
  39551. 0x5d, 0x9b, 0x7f, 0xa7, 0x07, 0xc8, 0x54, 0x86, 0x90, 0xa5, 0x06, 0x6a,
  39552. 0x94, 0x80, 0x84, 0x97, 0xaa, 0x2a, 0xb9, 0x79, 0xe5, 0x19, 0x7a, 0x91,
  39553. 0xef, 0x8b, 0x58, 0xdc, 0xf9, 0x90, 0x94, 0xa2, 0x25, 0x4c, 0x69, 0xd8,
  39554. 0x6e, 0x9e, 0xad, 0xf8, 0x82, 0x17, 0x37, 0xc9, 0x20, 0x15, 0x24, 0x40,
  39555. 0xe5, 0xc6, 0xc1, 0xc7, 0xbd, 0xd4, 0x62, 0xff, 0x16, 0x6d, 0xa5, 0xec,
  39556. 0xe9, 0x67, 0x41, 0x9d, 0x3e, 0xfb, 0x22, 0x81, 0x80, 0x61, 0x37, 0x45,
  39557. 0xa5, 0x9f, 0x70, 0xff, 0xd4, 0x99, 0x3d, 0x79, 0x45, 0xd0, 0x27, 0xc2,
  39558. 0x32, 0xbe, 0xd4, 0xe2, 0x53, 0xa8, 0x8c, 0x94, 0x8b, 0xbe, 0x8a, 0x43,
  39559. 0xf7, 0x2a, 0x28, 0x49, 0xf4, 0xce, 0x2e, 0x0b, 0x98, 0xc7, 0xaf, 0x7d,
  39560. 0x51, 0x2e, 0xda, 0xd0, 0x7a, 0xfa, 0x91, 0x3a, 0xe6, 0xe7, 0x64, 0xd6,
  39561. 0x09, 0xd8, 0x5d, 0x6a, 0x97, 0xcf, 0x89, 0x96, 0x72, 0x21, 0x97, 0x61,
  39562. 0xc5, 0x1b, 0xd8, 0xa1, 0xf0, 0xcd, 0x9d, 0xe4, 0xe9, 0x13, 0xd0, 0x16,
  39563. 0x41, 0x20, 0xa4, 0x2c, 0x33, 0xf5, 0x3d, 0xfe, 0x80, 0xe8, 0xb2, 0x52,
  39564. 0x0e, 0x18, 0x31, 0x19, 0x50, 0xeb, 0xc6, 0x99, 0x43, 0xab, 0x9a, 0x59,
  39565. 0x5d, 0x6c, 0x84, 0x00, 0x88, 0x45, 0x7c, 0x73, 0xdf, 0x56, 0x61, 0x3a,
  39566. 0xe1, 0x55, 0xb8, 0x59, 0x13, 0xcc, 0x0e, 0x53, 0xe9, 0xf4, 0x74, 0xa0,
  39567. 0xf2, 0x15, 0xd2, 0xa8, 0xf9, 0xd4, 0x0d, 0x3d, 0xe7, 0x3d, 0x7d, 0x5b,
  39568. 0x19, 0x89, 0x8b, 0x2c, 0x4d, 0x8a, 0xeb, 0xc3, 0x43, 0x31, 0x9a, 0x45,
  39569. 0x72, 0x5b, 0x25, 0xb6, 0xa2, 0xc1, 0x98, 0xe3, 0x8a, 0xd4, 0x90, 0xd0,
  39570. 0x3e, 0x13, 0xf0, 0xd7, 0x90, 0x34, 0x94, 0xcc, 0xf1, 0x0a, 0xa9, 0x30,
  39571. 0xd1, 0x95, 0x43, 0x07, 0xcd, 0xd2, 0xca, 0xb0, 0xe5, 0xd4, 0xf1, 0xa1,
  39572. 0xc5, 0x9b, 0xf4, 0x98, 0x28, 0xba, 0xde, 0x40, 0xd6, 0x98, 0x98, 0x20,
  39573. 0x9c, 0x84, 0x9e, 0xc6, 0x57, 0xd8, 0x84, 0xc4, 0xa2, 0x9b, 0x53, 0x50,
  39574. 0xa5, 0xa6, 0x0b, 0x47, 0xe8, 0x08, 0x7d, 0xd7, 0x09, 0xa4, 0x0c, 0x2b,
  39575. 0x27, 0xde, 0xf9, 0x78, 0xbc, 0xa4, 0xb6, 0xc6, 0x1b, 0xda, 0xce, 0x6a,
  39576. 0xf8, 0x1a, 0xf5, 0xfe, 0x7b, 0xab, 0x58, 0x7c, 0xdc, 0x72, 0x02, 0x94,
  39577. 0x99, 0xf0, 0x3c, 0x37, 0x87, 0x5b, 0xd2, 0x4b, 0x5a, 0x80, 0x83, 0xd7,
  39578. 0xfc, 0x9d, 0xa7, 0x51, 0x81, 0xb8, 0x62, 0xff, 0x4b, 0xb3, 0x9f, 0x07,
  39579. 0xc3, 0x54, 0xfb, 0x41, 0x85, 0x42, 0x9d, 0xac, 0x27, 0x81, 0x2e, 0xaf,
  39580. 0x98, 0x67, 0x8c, 0x23, 0xad, 0x45, 0xfe, 0x6a, 0x57, 0x9f, 0x18, 0xc5,
  39581. 0x71, 0x8c, 0xad, 0x3f, 0x30, 0x3c, 0xaa, 0x47, 0x8d, 0xba, 0xc8, 0x7f,
  39582. 0x03, 0x1c, 0x86, 0xee, 0xba, 0x3f, 0x59, 0x45, 0xd4, 0xd0, 0xf5, 0x54,
  39583. 0x9e, 0xcb, 0x08, 0xcf, 0xca, 0x40, 0x0a, 0x06, 0xc0, 0x1e, 0x60, 0x1f,
  39584. 0x33, 0xbf, 0x2c, 0xa8, 0x5f, 0xce, 0x23, 0xa0, 0xe2, 0x1c, 0x2d, 0x56,
  39585. 0x2a, 0x44, 0x61, 0x58, 0xf1, 0x84, 0x63, 0x4f, 0x0d, 0x5e, 0xfb, 0x83,
  39586. 0x0f, 0x36, 0x1b, 0xf4, 0x8f, 0x17, 0x82, 0x2e, 0x04, 0x2c, 0x77, 0x9d,
  39587. 0x32, 0x58, 0xb8, 0xb0, 0xf9, 0x44, 0xd2, 0xf6, 0x84, 0xa4, 0x8b, 0x28,
  39588. 0x53, 0xd6, 0x99, 0x81, 0x84, 0x43, 0xf0, 0xc1, 0x15, 0xc6, 0x74, 0x4f,
  39589. 0xab, 0x05, 0xcc, 0x80, 0xdf, 0xef, 0xcf, 0xaf, 0x14, 0x82, 0xdf, 0x51,
  39590. 0x7c, 0x28, 0x5e, 0x5b, 0x27, 0x5e, 0x91, 0x8b, 0x54, 0x3d, 0x54, 0x26,
  39591. 0xb0, 0x3f, 0xd7, 0xc5, 0xce, 0xf3, 0x6d, 0x2c, 0x12, 0xc6, 0xb4, 0x48,
  39592. 0x60, 0x11, 0x9c, 0xef, 0x29, 0x98, 0x9c, 0x76, 0x4e, 0x73, 0x2b, 0xd2,
  39593. 0x23, 0x53, 0x7d, 0x03, 0xc2, 0x2f, 0x8a, 0xa1, 0xe2, 0x84, 0x54, 0x2d,
  39594. 0xd8, 0xc6, 0x55, 0x77, 0x9d, 0x07, 0x67, 0x1f, 0x1a, 0xd3, 0x57, 0x4c,
  39595. 0x25, 0x79, 0x8f, 0xd8, 0x82, 0xc2, 0x4d, 0x87, 0x84, 0x33, 0xdc, 0x47,
  39596. 0xed, 0x9e, 0xfb, 0xd2, 0x62, 0xc8, 0x50, 0x76, 0xda, 0x3c, 0x3c, 0x05,
  39597. 0x0e, 0x2d, 0x30, 0x56, 0xca, 0x4d, 0x6a, 0xe2, 0x17, 0x24, 0x26, 0x9c,
  39598. 0xff, 0x09, 0xec, 0xb3, 0x94, 0xec, 0xab, 0x69, 0xb2, 0xf0, 0xa5, 0x66,
  39599. 0x18, 0x92, 0x49, 0x6b, 0x90, 0xf5, 0x77, 0x5a, 0x18, 0xe5, 0x51, 0x36,
  39600. 0x4a, 0x35, 0x54, 0x98, 0x48, 0x04, 0xa9, 0x0f, 0xcb, 0x55, 0xf1, 0x71,
  39601. 0xad, 0x1a, 0x4a, 0x2c, 0x0e, 0x5d, 0x5e, 0x77, 0x47, 0xf5, 0x46, 0x17,
  39602. 0x6b, 0x94, 0x2a, 0xbc, 0x40, 0xe5, 0xa7, 0xa6, 0x88, 0x41, 0x76, 0x22,
  39603. 0x47, 0xd1, 0xe8, 0x2b, 0x18, 0x48, 0x21, 0xc0, 0xe8, 0x4f, 0xe2, 0xb2,
  39604. 0x7e, 0x03, 0xbb, 0x25, 0x9c, 0xc8, 0x68, 0x66, 0x48, 0x25, 0x6a, 0xf2,
  39605. 0x64, 0x29, 0xec, 0x79, 0xba, 0xdb, 0x34, 0xe1, 0xd4, 0xf9, 0x52, 0x0e,
  39606. 0xfd, 0x8d, 0x86, 0x94, 0x71, 0xd8, 0xe0, 0x86, 0x02, 0x9b, 0xd4, 0x65,
  39607. 0x69, 0x5e, 0x01, 0x32, 0x87, 0x59, 0xd8, 0x6c, 0xbc, 0x8a, 0x9f, 0x58,
  39608. 0x28, 0x8c, 0x97, 0xef, 0x33, 0xb2, 0xda, 0x45, 0xa0, 0xec, 0xe5, 0x5b,
  39609. 0xac, 0xc6, 0x65, 0xc1, 0xb6, 0xcb, 0xf7, 0x85, 0x0e, 0xfa, 0x78, 0x36,
  39610. 0x30, 0x84, 0x90, 0xa8, 0xf8, 0x42, 0x25, 0xa5, 0xdd, 0xdc, 0xdc, 0x89,
  39611. 0xd3, 0xf0, 0x73, 0x9a, 0xd8, 0x95, 0x8f, 0x04, 0xbf, 0xc1, 0xfd, 0x94,
  39612. 0xff, 0xe6, 0xf8, 0x4e, 0xc6, 0x43, 0xc9, 0x60, 0x30, 0xe9, 0x68, 0xa8,
  39613. 0x76, 0xfb, 0xfa, 0xdf, 0xc0, 0x9b, 0xbc, 0xbc, 0x34, 0xe4, 0x38, 0xfd,
  39614. 0x93, 0xb0, 0x47, 0xb2, 0x3e, 0x83, 0x6c, 0xef, 0xe1, 0xaf, 0x35, 0xb4,
  39615. 0x90, 0x2a, 0x32, 0xaf, 0x25, 0x3f, 0x3e, 0x72, 0x61, 0xc0, 0x0f, 0x29,
  39616. 0xbb, 0x46, 0x6e, 0x2e, 0x94, 0x7d, 0xdd, 0xb7, 0x67, 0x1f, 0x7b, 0x64,
  39617. 0xcb, 0xa5, 0x9a, 0x58, 0x63, 0x20, 0xa7, 0xc0, 0x94, 0xa9, 0xad, 0x90,
  39618. 0x7d, 0xf3, 0x2b, 0x61, 0x2b, 0x64, 0x3d, 0x8a, 0xc3, 0xd1, 0xcb, 0xad,
  39619. 0x36, 0x44, 0xe6, 0x29, 0x8b, 0x3d, 0x95, 0x7c, 0xa7, 0xa2, 0xfa, 0x1b,
  39620. 0x16, 0x8d, 0x9e, 0xc4, 0xf8, 0x4c, 0x76, 0x20, 0x00, 0x68, 0x07, 0x99,
  39621. 0x9c, 0x60, 0xe6, 0x16, 0x6a, 0x6f, 0x8a, 0xbe, 0x71, 0x95, 0xa1, 0xcb,
  39622. 0xfe, 0x7c, 0x41, 0x59, 0x61, 0x20, 0xf9, 0x54, 0x3c, 0xb1, 0x19, 0x5c,
  39623. 0x42, 0x67, 0x3f, 0xff, 0xf3, 0x32, 0x21, 0x9c, 0x9e, 0x88, 0xf9, 0x97,
  39624. 0x00, 0x43, 0x73, 0x4a, 0xfc, 0x54, 0xeb, 0x27, 0x79, 0x14, 0x85, 0xd3,
  39625. 0xdc, 0x47, 0xb3, 0x6d, 0x24, 0xd3, 0xf7, 0x7a, 0xfb, 0x90, 0x7c, 0x6e,
  39626. 0xcd, 0x4e, 0xbf, 0x26, 0x76, 0xd2, 0xe8, 0xcc, 0x67, 0xd1, 0x23, 0x3c,
  39627. 0x94, 0x16, 0x1e, 0x07, 0x36, 0x7c, 0x96, 0xf6, 0xe8, 0x50, 0x72, 0x26,
  39628. 0x56, 0x67, 0x89, 0xa9, 0x11, 0xfb, 0x1d, 0xb8, 0xb9, 0x2a, 0x55, 0xb7,
  39629. 0x85, 0xf7, 0x40, 0xa2, 0xfc, 0x9f, 0x30, 0xec, 0x8f, 0x9a, 0x1c, 0xc8,
  39630. 0xe4, 0xc5, 0x1f, 0xcb, 0x0a, 0x60, 0x80, 0x41, 0xec, 0x88, 0x8a, 0xda,
  39631. 0x7c, 0x7a, 0xa1, 0x96, 0x51, 0x62, 0x16, 0x63, 0x75, 0x36, 0x28, 0x7c,
  39632. 0xc9, 0xd0, 0x27, 0x0c, 0x9e, 0x18, 0x4a, 0x82, 0xf7, 0x02, 0xb9, 0x40,
  39633. 0x8f, 0xd5, 0x97, 0x7a, 0x35, 0xa9, 0x3a, 0xb3, 0x8b, 0x6b, 0xf1, 0x9a,
  39634. 0xd1, 0xe7, 0x14, 0x38, 0x5e, 0xba, 0x8c, 0xbf, 0x32, 0xaa, 0x34, 0x30,
  39635. 0x7c, 0x1e, 0x11, 0xcd, 0x1f, 0x9f, 0xcf, 0x4d, 0x14, 0xce, 0x67, 0xf9,
  39636. 0x9c, 0x89, 0x07, 0x92, 0x44, 0x6e, 0x9a, 0x16, 0xe4, 0xfb, 0x67, 0x01,
  39637. 0x3f, 0x4c, 0x14, 0x89, 0x33, 0x87, 0x46, 0xc6, 0xe4, 0x66, 0x94, 0xd4,
  39638. 0x87, 0x4f, 0x2c, 0x92, 0x1b, 0xae, 0x82, 0xe7, 0x99, 0xaa, 0xb4, 0x99,
  39639. 0x81, 0x26, 0xa6, 0x6f, 0x1d, 0xc1, 0x95, 0x80, 0xe9, 0xea, 0xe3, 0x44,
  39640. 0x6a, 0x2b, 0xd2, 0xe0, 0x0d, 0x69, 0x42, 0xf7, 0x27, 0x6b, 0x4f, 0x02,
  39641. 0x7a, 0x33, 0x7b, 0x43, 0x3d, 0xef, 0x10, 0xaa, 0xab, 0xc5, 0xa2, 0xf0,
  39642. 0xbb, 0x07, 0x4b, 0x26, 0x0c, 0x58, 0xcd, 0x3b, 0xd2, 0x6d, 0xa5, 0x32,
  39643. 0x37, 0x88, 0x4e, 0x8b, 0xe3, 0x75, 0xb0, 0xbb, 0x87, 0xea, 0xa4, 0x53,
  39644. 0xf3, 0xff, 0x39, 0x92, 0x44, 0xab, 0x7b, 0x71, 0x62, 0x31, 0x6b, 0x31,
  39645. 0xca, 0x97, 0xba, 0xd7, 0x41, 0xe0, 0x47, 0x47, 0x4f, 0x77, 0xa2, 0x35,
  39646. 0x62, 0x7a, 0xc1, 0xb6, 0x69, 0x10, 0x09, 0xce, 0xfc, 0x92, 0xcc, 0xc5,
  39647. 0x7a, 0x11, 0xf1, 0xc1, 0xa0, 0x80, 0xe5, 0x42, 0x17, 0xb6, 0x3f, 0xab,
  39648. 0xc1, 0xa2, 0x41, 0xfb, 0xe3, 0x98, 0x2d, 0x7a, 0xe4, 0x1b, 0x1f, 0x7e,
  39649. 0x71, 0x3c, 0x3e, 0x90, 0x8c, 0x60, 0x30, 0xb7, 0x73, 0x06, 0x1f, 0x8a,
  39650. 0xce, 0x50, 0x20, 0x7c, 0xfa, 0x8c, 0xf2, 0x14, 0xd9, 0x00, 0xa2, 0x21,
  39651. 0xea, 0x10, 0x36, 0x21, 0x6f, 0x7f, 0x13, 0xe3, 0x6c, 0xb2, 0xd6, 0xa5,
  39652. 0xa6, 0x6e, 0xa9, 0xe7, 0x1d, 0xdf, 0xc9, 0x97, 0x60, 0x75, 0xa3, 0x55,
  39653. 0xa1, 0x2c, 0x94, 0xd7, 0x85, 0x4b, 0x44, 0xc6, 0x9c, 0x17, 0xc2, 0xad,
  39654. 0xe6, 0x56, 0x72, 0x1d, 0xb9, 0x13, 0x54, 0xfe, 0x8c, 0xec, 0xf4, 0xa3,
  39655. 0x54, 0x6b, 0x31, 0xbc, 0x55, 0x9e, 0x01, 0xd4, 0x9b, 0x24, 0x9e, 0x51,
  39656. 0xaf, 0x67, 0x76, 0x02, 0xf7, 0x34, 0x6a, 0xaa, 0xb0, 0x3c, 0x70, 0x2e,
  39657. 0xc8, 0x86, 0xfa, 0x40, 0x89, 0x12, 0xb7, 0x49, 0x38, 0x0b, 0xf7, 0x66,
  39658. 0xd2, 0x2e, 0x58, 0xf1, 0x22, 0x3b, 0xb3, 0x40, 0x6b, 0x7a, 0x68, 0x4d,
  39659. 0x42, 0xfd, 0xbf, 0xa0, 0xf7, 0x2f, 0x63, 0x4a, 0x87, 0xe7, 0x99, 0x52,
  39660. 0x6e, 0xe7, 0xdd, 0xca, 0x19, 0x71, 0xee, 0x92, 0xe2, 0x68, 0x0e, 0xe1,
  39661. 0xb7, 0x90, 0x1f, 0xc4, 0xef, 0xf8, 0xf6, 0x85, 0x53, 0x18, 0x33, 0x86,
  39662. 0x15, 0xc8, 0x29, 0x58, 0x6f, 0xf0, 0x1c, 0x14, 0x73, 0xa9, 0x8e, 0x88,
  39663. 0x74, 0xd4, 0x21, 0xf5, 0xc6, 0x7c, 0xd8, 0x96, 0x0f, 0xb0, 0xa6, 0x7b,
  39664. 0xf7, 0x72, 0x15, 0xd7, 0x30, 0x6b, 0x15, 0x1d, 0x3f, 0xb7, 0x4e, 0xaa,
  39665. 0xc0, 0x52, 0x1d, 0x84, 0xbf, 0x98, 0xbd, 0x33, 0x02, 0xab, 0x8b, 0xd0,
  39666. 0x9c, 0x85, 0x2f, 0xa3, 0xfb, 0x46, 0x8d, 0x4d, 0x97, 0x1a, 0x8a, 0x3c,
  39667. 0x73, 0x5b, 0x3b, 0x58, 0x26, 0xba, 0x6b, 0x45, 0x2e, 0x24, 0x66, 0x79,
  39668. 0x7d, 0xc4, 0xf8, 0x8c, 0x05, 0x7d, 0x5c, 0x23, 0xb9, 0xe8, 0x5d, 0xfe,
  39669. 0xc9, 0x84, 0xe5, 0x58, 0x40, 0xa4, 0xb7, 0x55, 0x74, 0x69, 0x92, 0x9c,
  39670. 0x3e, 0x19, 0xb1, 0xb6, 0x51, 0xe9, 0x71, 0xcc, 0x96, 0x2b, 0x01, 0x71,
  39671. 0xf5, 0xb9, 0xde, 0x77, 0xfe, 0x2e, 0x74, 0x9c, 0x6a, 0x52, 0x17, 0x1e,
  39672. 0xea, 0xd9, 0xc8, 0x14, 0xbe, 0x61, 0xdf, 0xe9, 0x96, 0x24, 0x5a, 0x9a,
  39673. 0xd8, 0xd7, 0xad, 0x71, 0xe0, 0xf4, 0xbb, 0x9e, 0xae, 0x95, 0xcd, 0x58,
  39674. 0x94, 0x81, 0xee, 0x46, 0x84, 0x65, 0x39, 0xb1, 0x1b, 0x1e, 0xf5, 0x50,
  39675. 0xad, 0x56, 0x58, 0xb7, 0x53, 0x9b, 0x2a, 0x2f, 0x09, 0x61, 0x57, 0xda,
  39676. 0xf5, 0xdc, 0x9f, 0x3c, 0x6c, 0x69, 0x0d, 0x61, 0x49, 0xb2, 0xe0, 0xb2,
  39677. 0xe5, 0xef, 0x19, 0xbe, 0x04, 0xf6, 0x6b, 0xad, 0x41, 0x4c, 0x5a, 0x50,
  39678. 0xf6, 0xac, 0x1b, 0x25, 0x8a, 0xdd, 0xe3, 0x57, 0xab, 0x7c, 0x92, 0xe4
  39679. #else
  39680. 0xef, 0x49, 0x79, 0x47, 0x15, 0xc4, 0x8a, 0xa9, 0x74, 0x2a,
  39681. 0xf0, 0x36, 0x94, 0x5c, 0x91, 0x1c, 0x5d, 0xff, 0x2c, 0x83,
  39682. 0xf2, 0x8b, 0x04, 0xfc, 0x5d, 0x64, 0xbd, 0x49, 0x73, 0xcd,
  39683. 0xcc, 0x99, 0x50, 0x5f, 0x2b, 0x16, 0x3a, 0xbb, 0x98, 0xc0,
  39684. 0xa7, 0x69, 0x0e, 0x95, 0x99, 0x0b, 0xa2, 0x6c, 0xfe, 0x6c,
  39685. 0xdb, 0xc8, 0xa7, 0x09, 0x46, 0x6c, 0x90, 0x50, 0xa4, 0x75,
  39686. 0x30, 0xf7, 0x90, 0xac, 0x31, 0xb6, 0xdd, 0x21, 0xaf, 0xc6,
  39687. 0xf9, 0xfe, 0xee, 0xc6, 0x5b, 0xa8, 0x8f, 0x0a, 0x2e, 0xd0,
  39688. 0x42, 0xab, 0xa8, 0x3c, 0x8d, 0xbf, 0xf7, 0x44, 0xbd, 0x0d,
  39689. 0xcf, 0xf4, 0x68, 0xfc, 0x16, 0x67, 0xf7, 0x39, 0x48, 0x5f,
  39690. 0x56, 0xd1, 0xe7, 0x1f, 0x49, 0x80, 0x50, 0xbe, 0x54, 0xd1,
  39691. 0xb7, 0xc9, 0xd2, 0x32, 0xc7, 0x08, 0x8c, 0xde, 0x2c, 0x31,
  39692. 0xf6, 0x1d, 0xc7, 0xac, 0xb3, 0x79, 0xd7, 0x4b, 0x1b, 0x23,
  39693. 0x89, 0x0a, 0xdc, 0x8e, 0x44, 0x41, 0x14, 0x28, 0x99, 0x13,
  39694. 0xb3, 0x26, 0xa6, 0x0e, 0x83, 0x60, 0xaa, 0x8d, 0x7c, 0x23,
  39695. 0x13, 0xba, 0x6c, 0x28, 0x90, 0x56, 0x84, 0xa1, 0x23, 0x8b,
  39696. 0x81, 0x20, 0x97, 0x7c, 0x66, 0x3f, 0xed, 0x5d, 0xd0, 0xe4,
  39697. 0x5d, 0xee, 0x46, 0xbc, 0x4b, 0x3c, 0x03, 0xb5, 0xbc, 0x4d,
  39698. 0x8d, 0x37, 0xa3, 0x56, 0x4b, 0x33, 0xad, 0xef, 0xd4, 0xb6,
  39699. 0xec, 0xdb, 0x04, 0x9a, 0x19, 0x58, 0x57, 0xd8, 0x00, 0x3a,
  39700. 0x92, 0x61, 0x0c, 0x0b, 0xc8, 0x52, 0xe5, 0x04, 0x02, 0x9a,
  39701. 0x00, 0x7e, 0xec, 0x7e, 0x94, 0xaa, 0xef, 0x2d, 0x7f, 0xb6,
  39702. 0x2e, 0x7c, 0xb0, 0x73, 0xa2, 0x20, 0xc0, 0x07, 0x30, 0x41,
  39703. 0x50, 0x20, 0x14, 0x18, 0x21, 0x5e, 0x2a, 0x6f, 0x70, 0x21,
  39704. 0xd6, 0x97, 0x13, 0xb9, 0xc1, 0x9e, 0x90, 0x67, 0xcc, 0x55,
  39705. 0x8a, 0xec, 0xec, 0x0a, 0x1e, 0x90, 0xdc, 0x3f, 0xb0, 0x4d,
  39706. 0xd1, 0x18, 0xea, 0x4f, 0xcb, 0x5d, 0x15, 0x4c, 0xb8, 0x35,
  39707. 0x9b, 0x34, 0x24, 0x30, 0x06, 0x53, 0x17, 0xf0, 0xbe, 0x27,
  39708. 0x36, 0xb3, 0x04, 0x6a, 0xbd, 0xbf, 0xa7, 0x39, 0xee, 0xa9,
  39709. 0x8f, 0x0e, 0x98, 0xc5, 0xf5, 0x9f, 0x46, 0x25, 0x93, 0xc9,
  39710. 0xf2, 0xf6, 0x2b, 0x8e, 0x92, 0x06, 0x01, 0x3d, 0x81, 0x18,
  39711. 0xf2, 0xec, 0xf1, 0x05, 0x4c, 0xad, 0x4b, 0xcb, 0x98, 0xa4,
  39712. 0xb5, 0x61, 0x20, 0xda, 0x81, 0xa1, 0xfb, 0x92, 0x4c, 0xaf,
  39713. 0x87, 0x6f, 0x6e, 0xd2, 0x57, 0xec, 0xcd, 0x94, 0xb3, 0x79,
  39714. 0xbf, 0x59, 0x88, 0x17, 0x81, 0xce, 0x8a, 0x57, 0xce, 0x57,
  39715. 0xae, 0x3e, 0x82, 0x81, 0x2f, 0x83, 0x61, 0xd8, 0xf9, 0x68,
  39716. 0x21, 0xe7, 0x72, 0x5b, 0xd6, 0x80, 0x55, 0x68, 0x5d, 0x67,
  39717. 0x15, 0x0c, 0x8b, 0xdc, 0x4f, 0xc3, 0x89, 0x36, 0x3c, 0xac,
  39718. 0xaf, 0x16, 0x5e, 0x1c, 0xfa, 0x68, 0x74, 0x6a, 0xab, 0x68,
  39719. 0xd8, 0x59, 0x96, 0x2d, 0x33, 0x62, 0xe4, 0xbd, 0xb3, 0xb7,
  39720. 0x4d, 0x88, 0x35, 0xb8, 0xed, 0xb2, 0x16, 0x85, 0x97, 0x08,
  39721. 0x71, 0x71, 0x39, 0x7e, 0x0c, 0x53, 0x16, 0xda, 0x38, 0xe5,
  39722. 0x28, 0x09, 0x9c, 0xd9, 0x46, 0xec, 0x68, 0xda, 0x8d, 0xd0,
  39723. 0xad, 0xb2, 0x79, 0x28, 0x3b, 0x1e, 0x12, 0xc9, 0xdf, 0xa9,
  39724. 0x6d, 0x3d, 0x29, 0x99, 0x2f, 0x53, 0xc2, 0xd0, 0xf9, 0x88,
  39725. 0x26, 0x94, 0x47, 0xaf, 0xf6, 0x96, 0xf3, 0xe1, 0x11, 0xa6,
  39726. 0x82, 0x3d, 0x43, 0x3f, 0x1f, 0xbc, 0xf6, 0x98, 0xbe, 0xff,
  39727. 0x06, 0x86, 0x61, 0x27, 0xdc, 0x91, 0x54, 0xd4, 0xfc, 0x68,
  39728. 0x83, 0xe8, 0x35, 0x3e, 0xee, 0x94, 0x59, 0x28, 0x2f, 0xde,
  39729. 0xdd, 0x03, 0x60, 0x66, 0xc1, 0x49, 0x57, 0xdd, 0xbc, 0xd5,
  39730. 0x0a, 0x67, 0x34, 0xf1, 0xa6, 0x0a, 0x57, 0x94, 0x65, 0x02,
  39731. 0x2c, 0x52, 0x43, 0x70, 0x3b, 0xc1, 0x9a, 0xff, 0xda, 0x6f,
  39732. 0xb9, 0x54, 0x47, 0x01, 0xda, 0x27, 0xe4, 0x48, 0x4a, 0x90,
  39733. 0x9f, 0xb5, 0xc3, 0xee, 0x0e, 0x09, 0x57, 0xfe, 0x48, 0x51,
  39734. 0x08, 0x34, 0x5e, 0x8f, 0x16, 0xc9, 0x0b, 0x74, 0xd9, 0x7d,
  39735. 0x22, 0x3f, 0xd6, 0xb7, 0x5d, 0xd6, 0x76, 0x00, 0x8d, 0x4e,
  39736. 0x78, 0x73, 0x86, 0xd6, 0xdb, 0x2a, 0x65, 0xab, 0xdf, 0xb0,
  39737. 0xea, 0x11, 0xad, 0xdf, 0xba, 0x43, 0xdb, 0xa8, 0x0a, 0xfb,
  39738. 0x04, 0x38, 0x81, 0x2b, 0xa3, 0x29, 0xfc, 0x95, 0x73, 0x9a,
  39739. 0x0c, 0x6c, 0x9e, 0xcd, 0xdc, 0xcf, 0x0a, 0x0c, 0x18, 0x41,
  39740. 0x6f, 0x1d, 0xa3, 0xf6, 0x12, 0x4c, 0x13, 0xf2, 0x02, 0xc6,
  39741. 0x50, 0x99, 0x86, 0x73, 0xa7, 0xf9, 0x7e, 0x84, 0x7f, 0x4c,
  39742. 0x00, 0xce, 0x2e, 0x21, 0x76, 0x8e, 0x17, 0x7a, 0x87, 0x6f,
  39743. 0x81, 0xe6, 0xc0, 0x52, 0xa5, 0xa0, 0x3c, 0x54, 0x3c, 0xec,
  39744. 0xb0, 0x9d, 0x1c, 0x3b, 0xec, 0xe5, 0x4e, 0x4a, 0x37, 0xe7,
  39745. 0xd5, 0xa9, 0x07, 0x87, 0x23, 0x28, 0x5d, 0x3d, 0x22, 0x02,
  39746. 0x79, 0x40, 0x3f, 0x2d, 0x40, 0xc9, 0xe5, 0xa6, 0x9b, 0xa8,
  39747. 0xb8, 0x76, 0xf6, 0x77, 0x5b, 0x8d, 0x72, 0x96, 0x3e, 0x13,
  39748. 0xbf, 0x76, 0xfa, 0x7b, 0xb7, 0x82, 0x5f, 0xe7, 0x9d, 0x54,
  39749. 0x0e, 0x05, 0x1a, 0x9f, 0xa4, 0x42, 0xa5, 0xb4, 0x93, 0x23,
  39750. 0x06, 0x59, 0x43, 0xa8, 0xe8, 0x5c, 0xfc, 0x18, 0x97, 0xdb,
  39751. 0xad, 0x9a, 0x80, 0x0a, 0xf2, 0x20, 0x50, 0xac, 0xc1, 0x13,
  39752. 0x3e, 0x98, 0x09, 0xde, 0xf2, 0x70, 0x9e, 0x14, 0xc2, 0x5c,
  39753. 0xec, 0x65, 0x07, 0x0b, 0xfa, 0x02, 0x5c, 0xf8, 0x71, 0xaa,
  39754. 0x9b, 0x45, 0x62, 0xe2, 0x27, 0xaf, 0x77, 0xf8, 0xe3, 0xeb,
  39755. 0x7b, 0x24, 0x7b, 0x3c, 0x67, 0xc2, 0x6d, 0x6e, 0x17, 0xae,
  39756. 0x6e, 0x86, 0x6f, 0x98, 0xc9, 0xac, 0x13, 0x9f, 0x87, 0x64,
  39757. 0x3d, 0x4d, 0x6f, 0xa0, 0xb3, 0x39, 0xc6, 0x68, 0x1b, 0xa7,
  39758. 0xeb, 0x3e, 0x0f, 0x6b, 0xc7, 0xa4, 0xe2, 0x20, 0x27, 0x75,
  39759. 0x3f, 0x09, 0x16, 0xff, 0x1a, 0xcc, 0xa7, 0xc4, 0x6d, 0xc2,
  39760. 0xfc, 0xc3, 0x0b, 0x37, 0x63, 0xff, 0x9b, 0x10, 0xe6, 0x00,
  39761. 0xf7, 0x18, 0x43, 0x9f, 0x07, 0x50, 0x31, 0x51, 0xd4, 0xfd,
  39762. 0xad, 0xa2, 0x0f, 0x77, 0xda, 0x41, 0xc1, 0x0a, 0x6f, 0x86,
  39763. 0xd7, 0xdc, 0x8a, 0x52, 0xd6, 0xa1, 0x27, 0xdb, 0x14, 0x67,
  39764. 0x26, 0x91, 0xb3, 0xcd, 0x01, 0x5f, 0x60, 0xa1, 0x7f, 0x43,
  39765. 0x15, 0x1a, 0x82, 0x0f, 0xd3, 0x66, 0x5f, 0x60, 0x57, 0x2f,
  39766. 0xb2, 0x8c, 0x27, 0x2a, 0x9d, 0x1b, 0xf9, 0xf2, 0x59, 0x20,
  39767. 0x39, 0xd9, 0xc5, 0xaf, 0xf2, 0x36, 0x8c, 0x58, 0x00, 0x1b,
  39768. 0xd0, 0xc5, 0x8e, 0x1a, 0x49, 0xa8, 0x60, 0xbe, 0xd1, 0xd7,
  39769. 0x2a, 0xb0, 0xc2, 0xab, 0x58, 0x8a, 0x7a, 0xa9, 0x41, 0x68,
  39770. 0x70, 0xbd, 0xea, 0x73, 0xa5, 0x03, 0x11, 0xb2, 0x27, 0xd9,
  39771. 0xcd, 0xf5, 0x09, 0xe8, 0x1c, 0xe2, 0x4f, 0x50, 0x6a, 0x84,
  39772. 0x34, 0x62, 0x2e, 0x36, 0xaa, 0x4c, 0xc1, 0x83, 0x78, 0x98,
  39773. 0x35, 0x7a, 0x27, 0x7e, 0xfe, 0xf1, 0x6f, 0x59, 0x27, 0x35,
  39774. 0x73, 0xce, 0x74, 0xaa, 0xb4, 0x72, 0x82, 0xa8, 0xe2, 0x81,
  39775. 0x7a, 0x6b, 0xca, 0x33, 0xa5, 0xda, 0xa2, 0x63, 0xca, 0x2e,
  39776. 0x90, 0x03, 0x32, 0xec, 0x63, 0xdb, 0x52, 0x7b, 0x16, 0xfc,
  39777. 0x01, 0x2d, 0x30, 0x12, 0x1e, 0xf9, 0xa3, 0x72, 0x21, 0x3c,
  39778. 0x75, 0x0c, 0x61, 0x9c, 0x7e, 0x73, 0x04, 0x71, 0x41, 0x45,
  39779. 0x5d, 0x7f, 0x49, 0x1c, 0x09, 0x08, 0xa4, 0xec, 0x2f, 0xfd,
  39780. 0xc4, 0xfb, 0x59, 0x6a, 0x27, 0x7a, 0xd4, 0xfc, 0x5f, 0x20,
  39781. 0x04, 0x34, 0x7d, 0x08, 0xed, 0x82, 0x5a, 0x90, 0xe1, 0xab,
  39782. 0xfd, 0x35, 0x3a, 0x8d, 0xbb, 0x0a, 0x9d, 0x73, 0xff, 0x69,
  39783. 0xe5, 0xe9, 0x09, 0x55, 0x14, 0xd9, 0x7b, 0x6f, 0x0d, 0x99,
  39784. 0xd2, 0x7e, 0x71, 0xf8, 0x4f, 0x72, 0x2f, 0xbb, 0xc6, 0xc4,
  39785. 0x36, 0xc9, 0x01, 0xd3, 0x9b, 0x94, 0xab, 0x41, 0x0f, 0x4a,
  39786. 0x61, 0x5c, 0x68, 0xe5, 0xd7, 0x0d, 0x94, 0xaa, 0xee, 0xba,
  39787. 0x95, 0xcb, 0x8c, 0x0e, 0x85, 0x3a, 0x02, 0x6b, 0x95, 0x50,
  39788. 0xfd, 0x02, 0xfd, 0xa4, 0x58, 0x29, 0x78, 0x4f, 0xd0, 0xae,
  39789. 0x66, 0xd6, 0x5c, 0xe7, 0x45, 0xfe, 0x98, 0xb0, 0xa3, 0xe2,
  39790. 0x87, 0xc0, 0xd2, 0x81, 0x08, 0xf1, 0xf1, 0xe7, 0xda, 0x62,
  39791. 0x9e, 0xa0, 0x34, 0x86, 0xeb, 0xa1, 0x6e, 0x4a, 0x26, 0x8e,
  39792. 0x39, 0x0c, 0x51, 0x10, 0x33, 0x11, 0x87, 0xf8, 0x79, 0x3c,
  39793. 0x49, 0x7a, 0x8b, 0xce, 0xc1, 0x0a, 0x0e, 0xe1, 0xd5, 0x2a,
  39794. 0xac, 0xf0, 0x3a, 0x1d, 0x6a, 0x6a, 0xe5, 0xe1, 0x81, 0x70,
  39795. 0xad, 0xaf, 0x15, 0x4c, 0x2a, 0x70, 0x2a, 0x6b, 0x22, 0x0d,
  39796. 0x30, 0xe7, 0x56, 0xed, 0x2d, 0x4b, 0x85, 0x17, 0x49, 0x72,
  39797. 0x3a, 0x1b, 0x6f, 0x57, 0x1c, 0xf7, 0x72, 0x9e, 0x20, 0xdb,
  39798. 0x57, 0x1c, 0xfb, 0x36, 0x50, 0x52, 0xec, 0x5b, 0xd6, 0x6a,
  39799. 0x1b, 0xf8, 0x74, 0xad, 0xe6, 0x00, 0x74, 0x04, 0xc5, 0x99,
  39800. 0x83, 0xe4, 0x5a, 0x0c, 0xc3, 0xe8, 0x6d, 0x3a, 0xd7, 0x3c,
  39801. 0x3c, 0xc0, 0x1a, 0x28, 0xb3, 0x29, 0x7a, 0x10, 0x9e, 0x39,
  39802. 0x66, 0x5b, 0xc1, 0x38, 0xac, 0x21, 0x4e, 0xcd, 0x01, 0xf2,
  39803. 0xf6, 0x30, 0x2c, 0x2b, 0xb6, 0xbf, 0xf5, 0xea, 0x61, 0xaf,
  39804. 0x0c, 0xa6, 0x01, 0x11, 0x15, 0x19, 0x09, 0x8c, 0x7e, 0x69,
  39805. 0xdf, 0x3b, 0xea, 0xd3, 0x0a, 0x3a, 0xd7, 0xbd, 0xe1, 0x17,
  39806. 0xaf, 0x92, 0x3c, 0xf5, 0xfe, 0x35, 0xd6, 0xcf, 0x07, 0xa6,
  39807. 0xf7, 0xe9, 0xc1, 0x99, 0xed, 0x80, 0xe3, 0x12, 0xd5, 0x4b,
  39808. 0xb9, 0xdf, 0xaf, 0x4e, 0x52, 0xad, 0x8e, 0x66, 0x87, 0xe5,
  39809. 0x2c, 0xd0, 0x45, 0x70, 0xd9, 0x78, 0x8f, 0x4b, 0xf4, 0xe1,
  39810. 0xf1, 0x22, 0xf2, 0xe3, 0xed, 0x1f, 0xeb, 0xe9, 0x70, 0x31,
  39811. 0x4c, 0x65, 0x5f, 0x55, 0xee, 0x5d, 0xaa, 0x83, 0x87, 0x76,
  39812. 0xbe, 0x11, 0xae, 0xd7, 0xf2, 0xfb, 0x43, 0xe7, 0x17, 0x81,
  39813. 0x33, 0x15, 0x47, 0xa0, 0xf3, 0x8e, 0x84, 0x57, 0xff, 0x35,
  39814. 0x9e, 0x4a, 0x8a, 0xab, 0x50, 0x3a, 0x45, 0xe0, 0xc3, 0x73,
  39815. 0xca, 0x77, 0x61, 0x68, 0x38, 0xd0, 0xa3, 0x5f, 0x03, 0x8d,
  39816. 0x41, 0xc2, 0xd3, 0x4a, 0x17, 0xe0, 0xa8, 0xaa, 0x00, 0xf3,
  39817. 0xf2, 0x5b, 0xa8, 0xe1, 0x06, 0xa6, 0x2b, 0xdb, 0xe1, 0x74,
  39818. 0xbd, 0xc4, 0xd2, 0x2b, 0x55, 0x9a, 0xb0, 0xf8, 0x35, 0xd8,
  39819. 0x6b, 0xec, 0xdb, 0xc5, 0xf4, 0x6c, 0x40, 0x90, 0x6a, 0x68,
  39820. 0xc9, 0xb5, 0xcb, 0xbb, 0xd0, 0xb0, 0xbc, 0x9f, 0xb9, 0xaa,
  39821. 0x50, 0x14, 0x93, 0x3b, 0x9f, 0x25, 0xcb, 0x40, 0xb8, 0x08,
  39822. 0xcc, 0x13, 0xe5, 0xdc, 0x3f, 0x84, 0x96, 0xe0, 0x73, 0x7b,
  39823. 0x7d, 0x9e, 0x41, 0x92, 0x5d, 0xcc, 0xa4, 0xea, 0x4f, 0x93,
  39824. 0x0c, 0x40, 0x2e, 0x42, 0x8a, 0xe9, 0xb9, 0x12, 0x74, 0xbb,
  39825. 0x79, 0x7c, 0xb0, 0x37, 0x20, 0xb6, 0xaf, 0x43, 0x3a, 0x88,
  39826. 0x59, 0x7c, 0x68, 0x28, 0x5f, 0x98, 0xc2, 0xf0, 0x2a, 0xbc,
  39827. 0xa1, 0x61, 0x88, 0x1f, 0x43, 0xbc, 0x42, 0x8f, 0x43, 0xf3,
  39828. 0x7e, 0x16, 0x96, 0xfa, 0x92, 0x70, 0xaf, 0x3c, 0x9f, 0x4b,
  39829. 0xd9, 0x60, 0xe9, 0xf6, 0x2e, 0x84, 0xda, 0x88, 0x31, 0x34,
  39830. 0xa6, 0x85, 0x10, 0x05, 0xef, 0x40, 0xa8, 0xa5, 0x4f, 0x92,
  39831. 0x59, 0xf7, 0xe0, 0xc4, 0x2b, 0x12, 0x17, 0x71, 0xbe, 0x8c,
  39832. 0x4a, 0x02, 0xfe, 0x12, 0xb6, 0x3b, 0x85, 0x75, 0x37, 0xf3,
  39833. 0x73, 0x2d, 0x9c, 0x00, 0x5d, 0x80, 0xad, 0x20, 0x2f, 0x5a,
  39834. 0x0b, 0x17, 0x7e, 0x67, 0x72, 0x24, 0x5a, 0xb9, 0xf3, 0xb1,
  39835. 0x33, 0xa4, 0x57, 0x1d, 0x49, 0x72, 0x2c, 0x7f, 0x47, 0x15,
  39836. 0x07, 0xe0, 0x45, 0x14, 0xdd, 0x77, 0x86, 0x6d, 0x03, 0xbe,
  39837. 0x57, 0xd0, 0xaa, 0x18, 0xa6, 0xdd, 0x94, 0x18, 0x3f, 0x8a,
  39838. 0xf3, 0xb5, 0xd7, 0x5a, 0xec, 0xc8, 0x79, 0x7f, 0x51, 0x61,
  39839. 0x3c, 0x9b, 0xb2, 0x9b, 0xf3, 0xb4, 0x35, 0xd1, 0x38, 0xbf,
  39840. 0x37, 0xce, 0x54, 0xd1, 0xf8, 0xb6, 0x45, 0xeb, 0x52, 0x0d,
  39841. 0x9a, 0x09, 0x58, 0x0d, 0x2c, 0x0b, 0xb1, 0xf2, 0x30, 0x3a,
  39842. 0x95, 0xc1, 0x13, 0x91, 0xd2, 0x9f, 0x8d, 0x8d, 0xd0, 0x38,
  39843. 0x3e, 0x4c, 0xae, 0x4a, 0x55, 0xa7, 0x42, 0x11, 0x83, 0xc4,
  39844. 0x70, 0xf0, 0x2b, 0x68, 0x9e, 0x07, 0xad, 0xb7, 0x83, 0xc6,
  39845. 0x53, 0x3c, 0xfb, 0x0a, 0x5d, 0x24, 0xdc, 0xe1, 0x55, 0x72,
  39846. 0xcf, 0xce, 0x3e, 0xc8, 0xd0, 0x57, 0x8a, 0x82, 0x5e, 0x78,
  39847. 0x2b, 0x80, 0xc5, 0xb9, 0x09, 0x46, 0xf8, 0x90, 0x39, 0x52,
  39848. 0xa9, 0xce, 0x3f, 0x3d, 0x41, 0x3b, 0x28, 0x45, 0xa3, 0xb3,
  39849. 0x21, 0xc2, 0xcd, 0x14, 0x49, 0x41, 0x6c, 0x38, 0xda, 0x1b,
  39850. 0x5f, 0x16, 0x49, 0xf9, 0x65, 0x00, 0x4e, 0xb4, 0x20, 0x55,
  39851. 0x70, 0xe8, 0x58, 0x1a, 0x18, 0xbf, 0x41, 0xef, 0x31, 0xb1,
  39852. 0xe7, 0x8d, 0x89, 0xc1, 0x48, 0xe8, 0xf5, 0x57, 0x35, 0xfa,
  39853. 0xc1, 0x79, 0xee, 0x2c, 0xe8, 0x7d, 0xb6, 0x03, 0xcc, 0x66,
  39854. 0x09, 0x6f, 0x52, 0x84, 0x0a, 0x34, 0x18, 0x2c, 0x01, 0x45,
  39855. 0x81, 0x00, 0xe5, 0x5e, 0x8d, 0xae, 0x1c, 0x96, 0x8b, 0x45,
  39856. 0x73, 0x00, 0x0a, 0xb5, 0xcf, 0x8d, 0x0e, 0x35, 0x5d, 0x1a,
  39857. 0x0e, 0xbf, 0x64, 0x9a, 0x52, 0x20, 0x48, 0xc6, 0xb9, 0x40,
  39858. 0xd3, 0x2c, 0x52, 0xca, 0x93, 0xcf, 0xbb, 0x94, 0x06, 0xf3,
  39859. 0x97, 0xee, 0xcc, 0x5d, 0xa3, 0xea, 0xf8, 0x5a, 0x39, 0x77,
  39860. 0x34, 0xd7, 0xf6, 0x4e, 0xbe, 0x8a, 0x07, 0x5f, 0x51, 0x53,
  39861. 0xc5, 0x1b, 0x8c, 0x47, 0x8f, 0x34, 0x0e, 0x60, 0x0a, 0x90,
  39862. 0xe2, 0xda, 0x7b, 0xef, 0xd6, 0xf5, 0x5d, 0xe5, 0x32, 0x37,
  39863. 0x75, 0x99, 0x81, 0x4a, 0x2a, 0x78, 0x71, 0xdc, 0xf4, 0xe5,
  39864. 0xca, 0xd8, 0x6b, 0x3b, 0x90, 0x68, 0x2e, 0x93, 0xc5, 0x10,
  39865. 0x42, 0x5d, 0x38, 0x90, 0x32, 0x46, 0xea, 0x87, 0xe0, 0xbc,
  39866. 0xb8, 0x9a, 0x18, 0x20, 0x68, 0x85, 0x6d, 0x9b, 0xc9, 0x8f,
  39867. 0x9b, 0xd2, 0xbe, 0x15, 0x12, 0x68, 0xd0, 0xb0, 0x16, 0x5f,
  39868. 0xe2, 0x69, 0x1d, 0x04, 0x00, 0xfc, 0x63, 0x33, 0xcd, 0x1f,
  39869. 0x89, 0xcd, 0x52, 0xff, 0xec, 0x19, 0x69, 0x74, 0xa3, 0xce,
  39870. 0x4d, 0xab, 0x93, 0xe4, 0xc6, 0x13, 0x56, 0x27, 0xc9, 0x25,
  39871. 0x5a, 0x01, 0xb2, 0x36, 0x8b, 0x61, 0xe5, 0x8b, 0x98, 0xac,
  39872. 0xe4, 0x2a, 0xb6, 0x40, 0x9f, 0x42, 0xe4, 0x1b, 0x52, 0xf7,
  39873. 0xfd, 0xd8, 0x30, 0x07, 0x33, 0xf9, 0x47, 0xcb, 0x3c, 0xad,
  39874. 0x12, 0xc1, 0xcc, 0x29, 0x62, 0x49, 0x04, 0x0c, 0x23, 0x97,
  39875. 0x5a, 0xa4, 0x84, 0x67, 0xde, 0x5a, 0xe5, 0x36, 0xd2, 0x88,
  39876. 0xf1, 0xd4, 0xeb, 0x13, 0x81, 0x54, 0x51, 0x11, 0xe3, 0xba,
  39877. 0xbc, 0xee, 0xdd, 0x6c, 0xcd, 0xe6, 0xb4, 0xa1, 0x8b, 0x0b,
  39878. 0x66, 0xfb, 0x8e, 0x50, 0xa0, 0xda, 0x69, 0x8d, 0xcc, 0x2d,
  39879. 0xe4, 0x2c, 0xc4, 0x37, 0xdf, 0x61, 0xc0, 0x03, 0xbd, 0x8b,
  39880. 0x28, 0xca, 0xd2, 0x8c, 0x1c, 0xf1, 0xa4, 0x26, 0x69, 0xe5,
  39881. 0xcf, 0x45, 0xdb, 0x5a, 0x47, 0x79, 0xed, 0x9f, 0xf7, 0xd2,
  39882. 0xdb, 0xba, 0x46, 0x53, 0x4f, 0xce, 0xa8, 0xbe, 0x8f, 0x4a,
  39883. 0xd6, 0xdf, 0x2e, 0x06, 0xe6, 0x4c, 0x9a, 0xc1, 0xb6, 0x49,
  39884. 0xed, 0xc4, 0xeb, 0xaa, 0xa4, 0x29, 0x6d, 0xd4, 0xcc, 0x8c,
  39885. 0xb6, 0x40, 0x11, 0x39, 0x69, 0xf7, 0x75, 0xcd, 0xb1, 0x99,
  39886. 0x46, 0x4e, 0xde, 0xcb, 0xf6, 0x9d, 0x32, 0xf3, 0xc9, 0x47,
  39887. 0x47, 0x7a, 0xcb, 0xfb, 0xa3, 0x0c, 0x3b, 0xdf, 0xb7, 0xde,
  39888. 0xec, 0x99, 0xde, 0xb0, 0x26, 0x04, 0x34, 0xae, 0x6b, 0xfc,
  39889. 0x99, 0xbc, 0xde, 0xd5, 0xbe, 0xe7, 0xeb, 0xf9, 0xe7, 0xa6,
  39890. 0x01, 0x9a, 0x0c, 0x5e, 0x66, 0xe6, 0x53, 0xe4, 0xd1, 0x58,
  39891. 0xac, 0xda, 0x69, 0x77, 0x7b, 0x68, 0xd6, 0x30, 0x2a, 0x9c,
  39892. 0x6b, 0xbe, 0x9f, 0x3d, 0x71, 0xd6, 0x54, 0xcd, 0x59, 0x4e,
  39893. 0x1f, 0xe3, 0x83, 0x4e, 0xd1, 0x8e, 0xaf, 0x97, 0xa8, 0xe5,
  39894. 0xb6, 0x59, 0x77, 0xa8, 0x02, 0x20, 0xe4, 0xeb, 0x44, 0x71,
  39895. 0xbc, 0x07, 0x14, 0x79, 0x4f, 0x0c, 0x27, 0x06, 0x39, 0xcf,
  39896. 0x7c, 0xef, 0x2b, 0x9b, 0x5e, 0xc4, 0x6d, 0x79, 0x13, 0x00,
  39897. 0x43, 0x6f, 0x51, 0x77, 0xb5, 0xc3, 0x72, 0xad, 0x13, 0xa9,
  39898. 0xe5, 0x9a, 0x5b, 0x1a, 0x99, 0x74, 0xc0, 0x7a, 0xf9, 0xc5,
  39899. 0xb0, 0x58, 0x35, 0x1c, 0xa5, 0x51, 0xdb, 0xa1, 0x14, 0xcd,
  39900. 0x26, 0x71, 0xb1, 0xe7, 0xaa, 0x14, 0xa7, 0x46, 0x93, 0xd3,
  39901. 0x5c, 0x8c, 0x1a, 0x91, 0x77, 0x46, 0x2e, 0x15, 0xaa, 0x9e,
  39902. 0xf7, 0x2b, 0x79, 0x41, 0x76, 0xf7, 0x22, 0x53, 0x7d, 0x51,
  39903. 0xdb, 0x98, 0x3d, 0x5b, 0x78, 0x5f, 0xc3, 0xc9, 0x29, 0xa3,
  39904. 0xff, 0x75, 0x82, 0x06, 0x9a, 0x16, 0x5e, 0xa4, 0x79, 0x0d,
  39905. 0xd1, 0x6d, 0x08, 0xff, 0x43, 0xef, 0x9c, 0xf3, 0x1b, 0x7a,
  39906. 0x3f, 0x34, 0xbe, 0x19, 0x15, 0x06, 0x33, 0xdb, 0xa5, 0x71,
  39907. 0xcb, 0x5f, 0x6b, 0x8d, 0xbd, 0x5b, 0x32, 0x91, 0xb2, 0x37,
  39908. 0x3d, 0xb4, 0x40, 0x9e, 0x02, 0x9b, 0xb7, 0x68, 0x20, 0x58,
  39909. 0x5c, 0xab, 0xcb, 0xc8, 0x23, 0x2d, 0x77, 0xcc, 0x0b, 0xf6,
  39910. 0x78, 0x6b, 0x80, 0x06, 0x91, 0xa9, 0xfd, 0x7e, 0xfa, 0x25,
  39911. 0x98, 0x9f, 0xcc, 0x79, 0x0a, 0x1a, 0x54, 0x83, 0xac, 0x64,
  39912. 0x16, 0x90, 0xe5, 0xd9, 0xa7, 0xd7, 0x1b, 0x86, 0x0d, 0xe6,
  39913. 0xe6, 0x22, 0x2b, 0x1f, 0x44, 0x49, 0x98, 0x9c, 0x51, 0x6f,
  39914. 0xcf, 0x58, 0x4a, 0xfa, 0xfa, 0x84, 0x12, 0xa5, 0x10, 0xf4,
  39915. 0xca, 0xf0, 0x98, 0x2b, 0xc9, 0x03, 0x71, 0x37, 0xe7, 0xdc,
  39916. 0xc2, 0xb1, 0x4e, 0x64, 0xde, 0x4f, 0x46, 0x0d, 0x6b, 0x25,
  39917. 0x88, 0x5d, 0xd6, 0xff, 0x23, 0x46, 0x57, 0x36, 0x14, 0x18,
  39918. 0xa7, 0xcb, 0xb8, 0xbd, 0xf0, 0xc5, 0x37, 0x36, 0xee, 0xe1,
  39919. 0xed, 0x9f, 0x4d, 0xd4, 0x39, 0xe5, 0x92, 0xcf, 0x95, 0x4d,
  39920. 0x66, 0x36, 0x5d, 0xd0, 0xcc, 0x07, 0xcf, 0x15, 0x5a, 0xce,
  39921. 0x14, 0xb8, 0xda, 0x0d, 0x3d, 0x1b, 0x45, 0xc5, 0x2e, 0x34,
  39922. 0x43, 0x25, 0x02, 0x3a, 0xcd, 0x14, 0x45, 0xfb, 0x3e, 0xf9,
  39923. 0x88, 0x5d, 0x0d, 0x29, 0x31, 0xb9, 0xa1, 0xe6, 0x31, 0x18,
  39924. 0x52, 0x46, 0x3f, 0x22, 0x4f, 0x9f, 0x7a, 0x65, 0x36, 0x88,
  39925. 0xa3, 0x1c, 0x3e, 0x6f, 0x50, 0x7a, 0x36, 0xbe, 0x56, 0x7e,
  39926. 0x50, 0xcb, 0x7a, 0x10, 0xa0, 0xec, 0xf6, 0x82, 0xd6, 0x30,
  39927. 0x1c, 0xe8, 0x4c, 0x50, 0xf9, 0x3e, 0xdb, 0xac, 0xbe, 0x4f,
  39928. 0x90, 0xb1, 0xd5, 0x1b, 0x12, 0x95, 0xfb, 0xe8, 0x08, 0x64,
  39929. 0x56, 0x7c, 0x96, 0xcc, 0x90, 0xb1, 0xbc, 0xa0, 0xf5, 0x32,
  39930. 0x69, 0xb3, 0x5f, 0x27, 0x0f, 0xbe, 0xc9, 0xbd, 0xeb, 0xfa,
  39931. 0x4b, 0x5c, 0xc5, 0x99, 0x9e, 0x5a, 0x04, 0xcc, 0xd0, 0x4d,
  39932. 0x29, 0xe8, 0x84, 0x55, 0x8c, 0xd7, 0xc4, 0x06, 0x13, 0x4d,
  39933. 0x92, 0xe5, 0x98, 0x9c, 0x4c, 0xc1, 0xf7, 0xaf, 0x7b, 0xd5,
  39934. 0x2b, 0x92, 0x68, 0x68, 0x19, 0x70, 0x4c, 0x9e, 0x46, 0xb8,
  39935. 0x34, 0xeb, 0x01, 0x47, 0xbe, 0x59, 0xab, 0x0b, 0x22, 0x25,
  39936. 0xe7, 0x56, 0xa8, 0xb4, 0x93, 0x3c, 0xd5, 0x98, 0x9f, 0x61,
  39937. 0x2e, 0xfa, 0xcb, 0x5f, 0x5b, 0xd8, 0x09, 0x83, 0xe9, 0x40,
  39938. 0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
  39939. 0x0a, 0x93
  39940. #endif
  39941. };
  39942. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_sig[] = {
  39943. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39944. 0x20, 0xff, 0x12, 0xe1, 0x87, 0xf6, 0x11, 0x38, 0xff, 0x41, 0xd0, 0x8f,
  39945. 0xcd, 0x7e, 0xd1, 0xf6, 0x21, 0x17, 0xd0, 0x46, 0xe9, 0x86, 0x83, 0x1b,
  39946. 0xaf, 0xe5, 0x2b, 0x59, 0x21, 0xd1, 0x6b, 0xc9, 0xdb, 0x34, 0xdc, 0xba,
  39947. 0xfd, 0xd3, 0xf8, 0x71, 0x49, 0xd8, 0x31, 0xbc, 0x48, 0x83, 0x22, 0x7b,
  39948. 0xfd, 0x6a, 0x93, 0xa6, 0x39, 0x4c, 0xda, 0xdb, 0x15, 0xe7, 0x41, 0x14,
  39949. 0xb4, 0xb8, 0xfe, 0xb0, 0x1f, 0xf9, 0x0a, 0x2c, 0x0b, 0xc0, 0xac, 0x09,
  39950. 0x84, 0x69, 0x5e, 0x64, 0x8c, 0xa8, 0xee, 0xa1, 0x52, 0x22, 0xde, 0x0d,
  39951. 0xc7, 0x25, 0xef, 0xa8, 0xfd, 0x8c, 0xb9, 0x45, 0x4f, 0xa4, 0x9c, 0xbc,
  39952. 0x70, 0xf2, 0x88, 0xea, 0x79, 0x13, 0xb0, 0xfc, 0xe6, 0x41, 0x48, 0x1c,
  39953. 0x33, 0x48, 0xa2, 0x77, 0x75, 0x37, 0x9f, 0xc1, 0x86, 0x94, 0xcd, 0x69,
  39954. 0x98, 0x87, 0x47, 0x49, 0x75, 0x93, 0xf1, 0xa4, 0x2d, 0x8e, 0xa8, 0x7e,
  39955. 0x0f, 0x95, 0xf5, 0x3e, 0x5d, 0x31, 0x2d, 0xc9, 0x58, 0x1c, 0x42, 0xfd,
  39956. 0x79, 0x6a, 0x49, 0xa3, 0x84, 0xc5, 0x2e, 0x8d, 0x96, 0x9c, 0xc8, 0x05,
  39957. 0x93, 0xdb, 0x6d, 0xbf, 0x83, 0x34, 0xc2, 0x81, 0x47, 0x90, 0xc9, 0xa9,
  39958. 0x82, 0xbd, 0xe1, 0xc8, 0x89, 0xa2, 0x36, 0x47, 0xed, 0xfb, 0x47, 0x57,
  39959. 0x01, 0x1a, 0x75, 0x8c, 0x6b, 0x83, 0xcf, 0x56, 0xae, 0x52, 0x66, 0x8b,
  39960. 0xab, 0x7f, 0x0c, 0xec, 0xde, 0x5c, 0x13, 0xbe, 0xbd, 0x5b, 0x74, 0x28,
  39961. 0xb5, 0xd7, 0x68, 0xd5, 0xd2, 0xe9, 0x96, 0x3b, 0x55, 0xda, 0x3a, 0x93,
  39962. 0x3c, 0xd9, 0x9f, 0x53, 0x2a, 0x31, 0x84, 0x45, 0x3f, 0xee, 0x2b, 0xfc,
  39963. 0x92, 0xb0, 0x9c, 0xc6, 0x16, 0x16, 0x4f, 0x33, 0x41, 0x17, 0x58, 0xbe,
  39964. 0x5d, 0x57, 0x4b, 0x04, 0x82, 0xe3, 0xb3, 0x68, 0xdf, 0x7c, 0x93, 0xce,
  39965. 0x9d, 0xf6, 0x7e, 0x21, 0x3d, 0x28, 0x1c, 0xf0, 0x37, 0x46, 0xf2, 0xc2,
  39966. 0x73, 0x7c, 0xbe, 0x98, 0x0e, 0x09, 0x75, 0xa7, 0x21, 0x11, 0xa9, 0xd6,
  39967. 0xd1, 0x47, 0xac, 0xd0, 0x19, 0x48, 0x3b, 0x74, 0xc1, 0x3c, 0x37, 0x43,
  39968. 0x49, 0x12, 0x62, 0xee, 0xaf, 0x5c, 0x38, 0xf7, 0x8a, 0xce, 0xb3, 0x7a,
  39969. 0x05, 0x16, 0xd4, 0x71, 0x8b, 0xbe, 0x1a, 0xe0, 0x1e, 0xbc, 0x4b, 0x54,
  39970. 0x0f, 0xb5, 0x73, 0x2b, 0xb8, 0x3a, 0x75, 0xf0, 0x26, 0xcd, 0xf9, 0xca,
  39971. 0x32, 0xf9, 0x7e, 0x15, 0x38, 0x75, 0x9c, 0x4d, 0xbc, 0x11, 0xf8, 0xea,
  39972. 0x8e, 0xe8, 0x38, 0x17, 0xc5, 0x62, 0xf4, 0x34, 0xfb, 0xd6, 0xf5, 0x76,
  39973. 0xfc, 0xa3, 0xf3, 0x44, 0xf9, 0xab, 0x2e, 0x9a, 0x68, 0xcd, 0xa1, 0x29,
  39974. 0xff, 0xda, 0xe8, 0xb5, 0xb0, 0x20, 0x5d, 0x02, 0x01, 0x62, 0x26, 0x44,
  39975. 0x32, 0xc8, 0x94, 0xf8, 0xf1, 0xaa, 0xf9, 0xc2, 0x86, 0xcb, 0x55, 0x7f,
  39976. 0x8d, 0xb3, 0xf6, 0x63, 0xb1, 0xa4, 0x95, 0x57, 0xb8, 0x1d, 0xc3, 0x42,
  39977. 0xd2, 0x4b, 0x69, 0xcd, 0x7a, 0x10, 0x5b, 0x6a, 0x13, 0xd1, 0x02, 0x98,
  39978. 0x38, 0x87, 0x9b, 0x9a, 0x5a, 0x66, 0x73, 0xcb, 0x75, 0xd0, 0x7a, 0x4b,
  39979. 0xad, 0x23, 0x06, 0x1c, 0xc8, 0x6b, 0x0c, 0xa8, 0xfe, 0x7b, 0x8f, 0x65,
  39980. 0x50, 0xd7, 0xf7, 0x76, 0x88, 0x42, 0xe0, 0x5e, 0x18, 0x91, 0x8b, 0x99,
  39981. 0x37, 0x56, 0x08, 0x91, 0xe7, 0x01, 0xe7, 0x05, 0xd5, 0xed, 0x43, 0x25,
  39982. 0x71, 0x7e, 0x3e, 0xfc, 0xc4, 0xfd, 0xed, 0x8b, 0x85, 0x16, 0x8c, 0xe3,
  39983. 0x05, 0xee, 0x51, 0x02, 0xa4, 0x4b, 0xd8, 0x3c, 0xcf, 0x4d, 0x2f, 0x2d,
  39984. 0x68, 0x6e, 0xc1, 0xd5, 0xfa, 0x91, 0xfd, 0x6a, 0xe0, 0x64, 0x85, 0x35,
  39985. 0x9c, 0x75, 0xe6, 0x0d, 0xb8, 0xec, 0x97, 0x88, 0x62, 0x98, 0x78, 0x75,
  39986. 0xc7, 0x1e, 0x68, 0xa7, 0xb9, 0x7b, 0xab, 0x75, 0x7a, 0x72, 0x3c, 0x7b,
  39987. 0xab, 0x60, 0x03, 0xb7, 0x38, 0x13, 0xe4, 0x96, 0x6e, 0xcb, 0x95, 0xcc,
  39988. 0xdc, 0x6a, 0x47, 0x67, 0x77, 0xd7, 0x95, 0xc4, 0x87, 0x66, 0xc2, 0x7e,
  39989. 0x42, 0x90, 0x59, 0x4f, 0xd6, 0xf3, 0xf4, 0xa7, 0xd0, 0x29, 0xf9, 0x5d,
  39990. 0x4b, 0x06, 0x06, 0xf7, 0x6e, 0xb2, 0xab, 0xb0, 0x8e, 0x21, 0xa6, 0xff,
  39991. 0x5e, 0x7b, 0x47, 0xb6, 0x3a, 0xa6, 0x9e, 0x19, 0xf6, 0xdf, 0x9b, 0x3b,
  39992. 0x3d, 0x07, 0x37, 0xd1, 0x0b, 0xa8, 0xf3, 0x9c, 0x43, 0x89, 0xee, 0xba,
  39993. 0x03, 0xee, 0x38, 0x74, 0x13, 0x09, 0x8e, 0x47, 0x4e, 0xa9, 0x14, 0xf5,
  39994. 0xb0, 0x55, 0xe0, 0x03, 0xe5, 0xb9, 0x53, 0xef, 0x03, 0x15, 0x60, 0xb3,
  39995. 0x4a, 0x71, 0x31, 0x4b, 0xf1, 0xc8, 0xe4, 0x63, 0x9b, 0x8b, 0x78, 0x3c,
  39996. 0x1f, 0xac, 0x27, 0x20, 0xa8, 0x53, 0x7d, 0xdd, 0x72, 0xd3, 0x90, 0x8f,
  39997. 0x71, 0xa6, 0xa7, 0xeb, 0xb0, 0xeb, 0x42, 0x96, 0xa4, 0xc3, 0xba, 0xc6,
  39998. 0x3c, 0xe7, 0x7b, 0x15, 0x1e, 0xfa, 0x15, 0x23, 0x37, 0xf3, 0xc8, 0xb2,
  39999. 0xf9, 0x46, 0x04, 0xd1, 0x5e, 0x44, 0xd7, 0x8f, 0x70, 0xb1, 0x0a, 0xde,
  40000. 0x6a, 0xe3, 0xaf, 0x9e, 0x49, 0x55, 0x78, 0x79, 0x11, 0x22, 0x87, 0xa9,
  40001. 0x54, 0x7c, 0xb4, 0x83, 0xe1, 0x25, 0xcd, 0x89, 0xa6, 0x91, 0x21, 0x7b,
  40002. 0xbe, 0x3d, 0x2f, 0x46, 0xb5, 0x5b, 0x50, 0x1a, 0xc8, 0x8d, 0x32, 0xf3,
  40003. 0x62, 0x1f, 0x24, 0x64, 0xe8, 0xb6, 0x02, 0x4f, 0x1f, 0x52, 0x3c, 0x40,
  40004. 0xfc, 0x72, 0x38, 0xd4, 0xba, 0x40, 0x8e, 0xb7, 0xc0, 0x97, 0x06, 0x16,
  40005. 0xd5, 0xe3, 0x39, 0x45, 0xd7, 0x7c, 0x0e, 0xed, 0x6b, 0x19, 0x19, 0x0a,
  40006. 0x8e, 0xcb, 0x2b, 0xee, 0x4d, 0xa1, 0x5e, 0x84, 0x22, 0x66, 0xcd, 0x4f,
  40007. 0xb9, 0x1a, 0x25, 0x85, 0x02, 0xc0, 0x67, 0xc4, 0xd5, 0x1a, 0xcb, 0xbb,
  40008. 0xde, 0x4d, 0x3c, 0x3c, 0x62, 0x9f, 0x76, 0x8f, 0x15, 0x29, 0xa5, 0xbb,
  40009. 0x5a, 0x48, 0x38, 0x66, 0xfa, 0x56, 0x0a, 0x09, 0xbd, 0xdf, 0xdf, 0x4a,
  40010. 0xe7, 0x0e, 0xa6, 0xb1, 0xb5, 0x7c, 0xe1, 0xed, 0x8d, 0x63, 0x07, 0x42,
  40011. 0xf3, 0xf8, 0x15, 0x28, 0x7c, 0x09, 0xf5, 0x02, 0x69, 0x1b, 0x88, 0x1e,
  40012. 0x3d, 0xad, 0x5f, 0x46, 0xed, 0xab, 0x2b, 0x11, 0x96, 0x73, 0xa8, 0xe8,
  40013. 0xe6, 0x64, 0x7d, 0xae, 0x13, 0xa1, 0x7d, 0x54, 0xae, 0xc0, 0x82, 0xeb,
  40014. 0x2a, 0xd1, 0x76, 0xb7, 0x9f, 0xbd, 0x33, 0x8f, 0xe7, 0xe6, 0x79, 0x92,
  40015. 0xa6, 0xaf, 0x61, 0x91, 0x49, 0xbc, 0xd2, 0x3c, 0x6f, 0x8b, 0xbe, 0x8f,
  40016. 0x5f, 0x1f, 0x00, 0x2c, 0x2e, 0x2c, 0xa0, 0x14, 0xcf, 0x34, 0x42, 0x44,
  40017. 0x41, 0x11, 0xd7, 0x37, 0xd3, 0x99, 0x44, 0x36, 0x43, 0x03, 0xb9, 0x50,
  40018. 0x4f, 0xab, 0xfe, 0x48, 0xe2, 0x4b, 0xed, 0x51, 0x8b, 0xe0, 0x04, 0x3c,
  40019. 0x93, 0x28, 0x55, 0xc8, 0x5a, 0xb3, 0x52, 0x2c, 0x56, 0xbd, 0x43, 0xb9,
  40020. 0x4a, 0x6c, 0x4c, 0xcc, 0xda, 0xba, 0x9c, 0xe6, 0x3e, 0x50, 0x8b, 0x1a,
  40021. 0xe5, 0x83, 0xc1, 0x60, 0x55, 0xb2, 0x02, 0x16, 0x54, 0x33, 0x62, 0x69,
  40022. 0x7c, 0x7d, 0x94, 0xf2, 0xb0, 0x3a, 0x22, 0xf0, 0x21, 0x46, 0xd7, 0x94,
  40023. 0x53, 0xec, 0x63, 0x4c, 0x3e, 0xc3, 0x71, 0xd1, 0xb9, 0x2e, 0x16, 0xe8,
  40024. 0x17, 0x63, 0x7e, 0x0c, 0x83, 0x05, 0x72, 0xe6, 0x20, 0x60, 0x34, 0xae,
  40025. 0x0e, 0x54, 0xa0, 0x57, 0x75, 0x93, 0x2e, 0xb8, 0x6c, 0xec, 0xda, 0x44,
  40026. 0x1b, 0xac, 0xd6, 0x75, 0xc5, 0x79, 0x3c, 0xc2, 0xa6, 0xa2, 0x7f, 0x3a,
  40027. 0xb0, 0xec, 0xeb, 0xc1, 0xe6, 0xd6, 0xae, 0xac, 0x2e, 0x55, 0x30, 0x1c,
  40028. 0x81, 0xa4, 0x4c, 0x35, 0x0e, 0xd8, 0xa6, 0x4e, 0xea, 0x0e, 0xbf, 0x79,
  40029. 0xf7, 0xdf, 0x55, 0xfc, 0xf9, 0x24, 0xb0, 0xa6, 0xba, 0xc3, 0x72, 0x42,
  40030. 0x60, 0x06, 0x44, 0x03, 0xe3, 0x40, 0x3c, 0x2a, 0x13, 0xf7, 0xdf, 0x3d,
  40031. 0xb7, 0x0d, 0x86, 0x6c, 0xb0, 0x0f, 0x2e, 0x72, 0x91, 0x16, 0x4f, 0x5f,
  40032. 0xd0, 0x3e, 0x8c, 0x36, 0xed, 0xa8, 0x6f, 0xbc, 0x65, 0xb0, 0x65, 0x99,
  40033. 0x47, 0x50, 0xa5, 0x9c, 0xea, 0xee, 0x8a, 0x44, 0x70, 0xf5, 0x31, 0x1a,
  40034. 0xe9, 0x11, 0xc1, 0xce, 0xe0, 0x21, 0x52, 0x70, 0x89, 0xf7, 0xc3, 0x35,
  40035. 0xfa, 0x55, 0x5a, 0xc5, 0x10, 0x02, 0xc4, 0xc7, 0xf7, 0xe1, 0xaf, 0x49,
  40036. 0x48, 0x61, 0xe7, 0x0d, 0xa1, 0x2d, 0x7d, 0x03, 0x00, 0x38, 0xa7, 0xd5,
  40037. 0xd3, 0xbf, 0x95, 0x29, 0xed, 0xcc, 0x70, 0x3e, 0xbe, 0x95, 0x8a, 0xdf,
  40038. 0xaf, 0xbf, 0xec, 0xf8, 0x6a, 0x4f, 0x9e, 0x69, 0xee, 0x4e, 0x3d, 0x8b,
  40039. 0x58, 0xa0, 0x2e, 0xb5, 0x83, 0x6a, 0x0e, 0x04, 0xa4, 0xa9, 0x74, 0xcb,
  40040. 0x4f, 0xb0, 0x39, 0x37, 0x8f, 0xcf, 0xbf, 0x77, 0xe4, 0x1a, 0x74, 0xcf,
  40041. 0x0e, 0x0d, 0x2d, 0x6e, 0x1d, 0xba, 0xc1, 0xf5, 0x7c, 0x54, 0x6e, 0x92,
  40042. 0xec, 0x4b, 0x03, 0xc3, 0xa4, 0x44, 0xad, 0x3e, 0x4f, 0xa4, 0xd9, 0xe9,
  40043. 0x71, 0x3c, 0xe6, 0xb6, 0xbe, 0xe7, 0xfc, 0x72, 0x76, 0x86, 0x9a, 0x73,
  40044. 0xb1, 0xb3, 0xf3, 0x84, 0xb6, 0x2a, 0x40, 0x0b, 0x8c, 0xae, 0xb3, 0xc4,
  40045. 0xdc, 0xb5, 0x21, 0x85, 0x87, 0xdc, 0x19, 0x18, 0xd5, 0xba, 0xa4, 0x5e,
  40046. 0x88, 0x89, 0xa4, 0xf4, 0x88, 0x75, 0xc2, 0x7a, 0xb4, 0xee, 0x9d, 0x54,
  40047. 0x66, 0x97, 0x70, 0x08, 0x8f, 0x99, 0x84, 0x5d, 0x5e, 0xa7, 0x6f, 0x92,
  40048. 0xe8, 0xa3, 0x65, 0xfa, 0x0e, 0x87, 0xfb, 0x3c, 0xe9, 0x17, 0x2d, 0xc7,
  40049. 0x2d, 0x30, 0x8f, 0x41, 0x82, 0x68, 0x2b, 0xf1, 0x67, 0x8e, 0xf7, 0x05,
  40050. 0x78, 0xfa, 0xc3, 0x61, 0xba, 0x35, 0xe7, 0x2f, 0x19, 0xef, 0x71, 0x36,
  40051. 0xac, 0x5b, 0xf0, 0x45, 0x30, 0x70, 0xdc, 0xc7, 0xab, 0x7b, 0x62, 0x17,
  40052. 0x9d, 0xc4, 0x43, 0x6f, 0xfc, 0x02, 0x56, 0x5f, 0x65, 0xaa, 0x68, 0x3b,
  40053. 0x5c, 0xfa, 0x71, 0x28, 0x89, 0xe9, 0x28, 0x2f, 0x95, 0x4b, 0xfc, 0xe6,
  40054. 0xe7, 0xc8, 0x44, 0x28, 0x5c, 0x3c, 0x08, 0x5f, 0x9c, 0xbc, 0x41, 0x68,
  40055. 0x91, 0x98, 0x7a, 0x00, 0x63, 0xc9, 0x5c, 0x75, 0x8f, 0xcc, 0x33, 0x77,
  40056. 0x7b, 0xd0, 0x2d, 0xe8, 0xa2, 0x98, 0xa4, 0x1b, 0xfa, 0x09, 0x67, 0x7b,
  40057. 0x25, 0x96, 0x19, 0xf4, 0x77, 0x33, 0x20, 0x4f, 0x19, 0xf6, 0x9c, 0x6c,
  40058. 0x2e, 0xd9, 0x68, 0x95, 0xb0, 0xe2, 0x18, 0x06, 0xe5, 0x84, 0x8e, 0xf7,
  40059. 0xbf, 0x6c, 0x96, 0xa8, 0x9d, 0x37, 0xc7, 0x28, 0xa1, 0x3d, 0x90, 0x8c,
  40060. 0x40, 0x3d, 0xe2, 0x51, 0xfd, 0x55, 0x09, 0xf8, 0x83, 0x43, 0x44, 0x4d,
  40061. 0x1c, 0x8a, 0x8d, 0x36, 0x84, 0x64, 0xc4, 0xfa, 0x1d, 0x72, 0x04, 0x0b,
  40062. 0x1d, 0x49, 0x13, 0x88, 0x78, 0x5f, 0x07, 0x9b, 0xc8, 0x01, 0x9c, 0x3c,
  40063. 0xfc, 0xff, 0x0f, 0xd5, 0x13, 0xcd, 0x15, 0x98, 0xcc, 0xe6, 0x59, 0x1e,
  40064. 0x83, 0x38, 0x8f, 0x6c, 0x75, 0xbe, 0xdf, 0xe9, 0x1b, 0xc5, 0xb9, 0x6b,
  40065. 0xa4, 0x5a, 0x0c, 0xae, 0x98, 0x8d, 0x93, 0xfa, 0x76, 0x7f, 0x0d, 0x0b,
  40066. 0xe8, 0xa0, 0x3b, 0x9e, 0x5e, 0xc8, 0xa8, 0xcc, 0x02, 0xc9, 0x86, 0x9c,
  40067. 0x78, 0xaf, 0x6e, 0x6a, 0xf4, 0xfe, 0x49, 0xad, 0xc5, 0x93, 0xae, 0x62,
  40068. 0xbd, 0xe3, 0x3a, 0xa8, 0xf2, 0x60, 0xb5, 0x29, 0xde, 0x5f, 0x12, 0x02,
  40069. 0x2d, 0x43, 0x90, 0xf5, 0x9d, 0x9d, 0x97, 0x29, 0xfa, 0xdd, 0x60, 0x41,
  40070. 0x64, 0xb7, 0xa5, 0x03, 0x72, 0x10, 0x2b, 0xdd, 0x5b, 0x60, 0xe6, 0xf0,
  40071. 0xe1, 0xd7, 0xa5, 0x97, 0xec, 0xb4, 0x9a, 0x4c, 0x3e, 0x16, 0xa2, 0x82,
  40072. 0xb3, 0xc3, 0x3f, 0x3e, 0x5d, 0x32, 0xac, 0x5a, 0x40, 0xb4, 0x00, 0xfa,
  40073. 0xd9, 0x47, 0xe8, 0x77, 0xa8, 0x96, 0x5c, 0x60, 0x04, 0x9c, 0x5c, 0xdf,
  40074. 0x24, 0x3b, 0xa7, 0x4a, 0x58, 0x25, 0x12, 0x9a, 0xa8, 0x7b, 0x3e, 0x14,
  40075. 0xc8, 0x06, 0x79, 0x23, 0xea, 0x91, 0x7f, 0xe1, 0x78, 0x41, 0x6c, 0xdb,
  40076. 0x8c, 0xeb, 0x66, 0x35, 0x87, 0x87, 0x81, 0x65, 0x2c, 0xef, 0x3a, 0x6e,
  40077. 0xae, 0xb3, 0x6c, 0xe9, 0x86, 0x50, 0x6d, 0x89, 0xd6, 0x27, 0x0a, 0xdb,
  40078. 0xf8, 0xd4, 0xb8, 0x85, 0x8e, 0x37, 0xa6, 0x56, 0xf7, 0x58, 0x18, 0x4c,
  40079. 0x44, 0xcf, 0xeb, 0xc4, 0x79, 0x19, 0xfc, 0x2e, 0x53, 0x18, 0x0e, 0x7b,
  40080. 0x51, 0x86, 0xf3, 0x59, 0x13, 0xb2, 0xaf, 0xd3, 0xee, 0xf4, 0xd5, 0xbf,
  40081. 0x2c, 0xb8, 0x6d, 0x71, 0x74, 0x7c, 0x67, 0x54, 0xa7, 0x4b, 0x03, 0xa9,
  40082. 0x1b, 0x62, 0x95, 0x9f, 0xc3, 0xf0, 0x71, 0x39, 0x2d, 0x26, 0xaf, 0xaf,
  40083. 0xa7, 0xa5, 0x58, 0xf8, 0xf8, 0x8a, 0xe0, 0x62, 0x90, 0x3f, 0x72, 0x9d,
  40084. 0x21, 0x82, 0x76, 0x3e, 0x4c, 0x5d, 0xe0, 0xb5, 0x67, 0x23, 0xe3, 0x13,
  40085. 0x1a, 0x29, 0xa3, 0xda, 0xa4, 0xb4, 0x5c, 0x1d, 0x47, 0xdf, 0xdf, 0xc9,
  40086. 0x93, 0x6c, 0xb2, 0xb5, 0x22, 0xb3, 0x47, 0x2b, 0xcf, 0xf0, 0x36, 0x87,
  40087. 0x51, 0x3c, 0x79, 0x41, 0x70, 0xbd, 0xea, 0x70, 0xa2, 0x29, 0x90, 0x55,
  40088. 0x30, 0x6f, 0x3e, 0x50, 0xc8, 0x38, 0xd6, 0xfa, 0x6f, 0xe3, 0x39, 0x67,
  40089. 0x88, 0x52, 0x1f, 0xd3, 0x52, 0xbf, 0x3e, 0x7b, 0x2a, 0xe5, 0x1e, 0xcd,
  40090. 0xf9, 0xf1, 0x91, 0x1d, 0x04, 0x61, 0x25, 0xbb, 0xe1, 0x33, 0xe3, 0x66,
  40091. 0x46, 0xed, 0x06, 0x8d, 0xc3, 0x4f, 0x20, 0xc6, 0x24, 0xa7, 0xb5, 0x49,
  40092. 0x3b, 0xc7, 0xe6, 0xa0, 0x77, 0x58, 0xd9, 0x70, 0xb1, 0xf5, 0xec, 0x94,
  40093. 0x19, 0xf3, 0x5b, 0x0f, 0x9a, 0xe4, 0xad, 0x37, 0x81, 0xaf, 0x68, 0x7b,
  40094. 0xe5, 0x67, 0xb5, 0xae, 0x7f, 0x2d, 0x64, 0x78, 0x68, 0x5a, 0xd1, 0x8f,
  40095. 0x1c, 0xc0, 0xc3, 0x5b, 0x21, 0x77, 0xe4, 0xa8, 0x5d, 0x05, 0x50, 0xc1,
  40096. 0x92, 0xee, 0x36, 0x2d, 0xd2, 0xff, 0xee, 0xc2, 0x11, 0x99, 0xee, 0xd7,
  40097. 0x48, 0xfb, 0x6a, 0xa3, 0xc9, 0xb7, 0x0c, 0xc1, 0xe5, 0x12, 0xbf, 0x6f,
  40098. 0x58, 0x66, 0x35, 0x34, 0x26, 0xaa, 0xbe, 0xc3, 0x33, 0x86, 0xfd, 0xc0,
  40099. 0x1c, 0xa5, 0xe4, 0x1e, 0x91, 0xc4, 0x55, 0x4e, 0xf1, 0xcb, 0xd2, 0x0b,
  40100. 0xe8, 0x0d, 0x89, 0x6a, 0x00, 0xbd, 0x7b, 0xf5, 0x3d, 0x1a, 0x4a, 0x48,
  40101. 0xfc, 0xf0, 0x5b, 0xcd, 0xdb, 0xb2, 0xa0, 0x27, 0x4b, 0x8f, 0xf7, 0x87,
  40102. 0x78, 0x13, 0xdb, 0x3f, 0xfb, 0x0b, 0xda, 0x22, 0xb3, 0x2b, 0x3a, 0x38,
  40103. 0xd2, 0x29, 0x73, 0x77, 0xb8, 0xd6, 0xec, 0xab, 0xb4, 0xfe, 0xbe, 0xbb,
  40104. 0x6e, 0xe2, 0xc8, 0x45, 0x7b, 0x0d, 0x36, 0x28, 0x0f, 0x45, 0x72, 0xea,
  40105. 0x6d, 0x38, 0x02, 0x5e, 0x48, 0x89, 0x12, 0x24, 0x1b, 0x33, 0x0f, 0xe9,
  40106. 0xf4, 0xce, 0xf8, 0x27, 0x16, 0x37, 0x29, 0xae, 0xe8, 0x22, 0x03, 0x31,
  40107. 0xa9, 0xa0, 0x73, 0x0c, 0x40, 0xe4, 0xfc, 0x6b, 0xe2, 0x1c, 0x8d, 0x7c,
  40108. 0x40, 0x82, 0x72, 0x28, 0xd0, 0x7d, 0xe5, 0xef, 0x05, 0x14, 0x80, 0x28,
  40109. 0x11, 0x32, 0x0d, 0x63, 0x8a, 0xc3, 0x7c, 0xfe, 0xf5, 0x06, 0x0e, 0xb0,
  40110. 0x78, 0x5c, 0x3a, 0xb6, 0x54, 0x37, 0x46, 0xa7, 0x43, 0x4f, 0x05, 0xec,
  40111. 0xe4, 0x9f, 0xd8, 0x55, 0x1f, 0x70, 0xb3, 0xe6, 0xbc, 0x46, 0x34, 0x9e,
  40112. 0xfc, 0xa4, 0x57, 0x8f, 0x0f, 0x25, 0x6f, 0x9f, 0xb3, 0x80, 0x21, 0x0b,
  40113. 0xa1, 0xca, 0x59, 0xcd, 0x37, 0xf7, 0xc9, 0xcb, 0xbe, 0x91, 0xad, 0x07,
  40114. 0x4f, 0xc7, 0x4e, 0x04, 0xbd, 0x38, 0x8b, 0x63, 0xb5, 0x51, 0xac, 0xc8,
  40115. 0x83, 0x3a, 0xa7, 0xe1, 0x77, 0xbc, 0xa4, 0x0c, 0x6c, 0x50, 0xeb, 0x46,
  40116. 0xe1, 0x45, 0x9a, 0x7b, 0x01, 0xca, 0x54, 0xf0, 0x0f, 0xa0, 0x1f, 0x43,
  40117. 0x9a, 0x19, 0x70, 0x2e, 0x70, 0x5a, 0xcf, 0x3b, 0x1b, 0x41, 0xfd, 0xd3,
  40118. 0x9a, 0xa2, 0x36, 0x14, 0xf0, 0xdd, 0xb0, 0x12, 0x6d, 0xcf, 0x55, 0x3f,
  40119. 0xef, 0x0a, 0xc1, 0x80, 0xa9, 0x68, 0xc3, 0x98, 0x03, 0x46, 0x34, 0xce,
  40120. 0x91, 0xb2, 0x7a, 0x94, 0xd2, 0xe7, 0xb9, 0x9c, 0x56, 0xb8, 0xf8, 0xd6,
  40121. 0xff, 0xbf, 0x8b, 0x39, 0x45, 0x04, 0x45, 0xc9, 0xa2, 0xe2, 0xbb, 0x50,
  40122. 0x68, 0x13, 0x32, 0x1e, 0x09, 0x51, 0xb7, 0xb9, 0xcf, 0x5f, 0xcc, 0x54,
  40123. 0xd2, 0xf3, 0xc1, 0x9d, 0xa0, 0x8d, 0x22, 0xc8, 0x7e, 0x1b, 0xc6, 0x14,
  40124. 0xde, 0x5f, 0x52, 0xb4, 0x69, 0x71, 0xca, 0x58, 0x1d, 0x1e, 0x89, 0xcb,
  40125. 0x56, 0x78, 0x7a, 0x85, 0xee, 0xfd, 0xf6, 0x7e, 0xbe, 0x49, 0x9b, 0xb1,
  40126. 0x05, 0x95, 0x12, 0xe9, 0x63, 0xbd, 0x61, 0x9a, 0x26, 0xf9, 0x0b, 0x9f,
  40127. 0x23, 0x0a, 0x59, 0x55, 0x93, 0xd3, 0x2d, 0xca, 0x66, 0x45, 0x03, 0xb7,
  40128. 0xf0, 0x88, 0x9e, 0xc1, 0x11, 0xbb, 0x62, 0x2c, 0x6f, 0xac, 0x3e, 0x87,
  40129. 0xd7, 0xe6, 0x4a, 0x44, 0x83, 0x04, 0x5d, 0x5d, 0xbc, 0x3c, 0xce, 0x83,
  40130. 0x2b, 0x11, 0x42, 0x02, 0x73, 0x1c, 0x24, 0x90, 0xd9, 0x1a, 0x7d, 0x96,
  40131. 0x82, 0x33, 0x75, 0x1e, 0x59, 0xea, 0xa7, 0x99, 0xe1, 0x5b, 0xdc, 0xe4,
  40132. 0x07, 0xc5, 0x48, 0x07, 0xb4, 0xbc, 0x80, 0x0e, 0xbd, 0x63, 0x6e, 0x66,
  40133. 0xf1, 0x12, 0xb6, 0x67, 0xe0, 0x14, 0x74, 0x9f, 0xbb, 0xb3, 0xb8, 0x16,
  40134. 0xd0, 0x25, 0xe9, 0x21, 0x80, 0x1a, 0x32, 0xb0, 0x58, 0x9a, 0x62, 0x17,
  40135. 0x18, 0x9d, 0x64, 0x2d, 0x47, 0x89, 0x82, 0x3b, 0x8c, 0x5d, 0x60, 0xc4,
  40136. 0x54, 0x69, 0xaa, 0xb4, 0x6a, 0x1d, 0x16, 0xb0, 0xe2, 0x5d, 0x7d, 0xeb,
  40137. 0xb9, 0x80, 0x37, 0xcd, 0x5b, 0xf0, 0xa1, 0xa8, 0x39, 0xb2, 0xd6, 0x3a,
  40138. 0xc8, 0xcd, 0xca, 0xaf, 0xcb, 0x3b, 0x54, 0xc2, 0x67, 0x49, 0xf3, 0xf1,
  40139. 0x11, 0x4d, 0x53, 0x7c, 0x46, 0x8d, 0x22, 0xf6, 0x9a, 0x0d, 0x9e, 0xda,
  40140. 0x37, 0xc6, 0x06, 0x00, 0xca, 0xb6, 0xb6, 0x99, 0xc5, 0xb6, 0x81, 0x7e,
  40141. 0x87, 0x62, 0xcf, 0x07, 0x76, 0xc1, 0x5f, 0xfe, 0x86, 0xfc, 0x5b, 0xa0,
  40142. 0xac, 0xca, 0xcb, 0x7d, 0xf5, 0x5a, 0xc2, 0x5e, 0x41, 0x48, 0x35, 0xc4,
  40143. 0x71, 0x9d, 0xc4, 0x0a, 0x79, 0x6f, 0xe3, 0x6d, 0x47, 0xd4, 0xaa, 0xfd,
  40144. 0x97, 0xe7, 0xb0, 0x7e, 0x61, 0xf1, 0x7d, 0x7e, 0xf8, 0x78, 0x4c, 0x2e,
  40145. 0x65, 0x51, 0xeb, 0x99, 0xd0, 0x3e, 0x24, 0x4c, 0xe0, 0x40, 0x7e, 0x2d,
  40146. 0xf7, 0x00, 0x9d, 0x50, 0x87, 0xce, 0x1f, 0x9a, 0xd2, 0x76, 0x00, 0x09,
  40147. 0xeb, 0x10, 0x1b, 0x4c, 0xf1, 0x43, 0x0e, 0x35, 0xbb, 0x23, 0x2e, 0x26,
  40148. 0x3d, 0x66, 0xa3, 0x0f, 0xf6, 0x10, 0x8b, 0x67, 0xce, 0x66, 0xfd, 0xb5,
  40149. 0x07, 0xdc, 0x04, 0x69, 0xad, 0xe0, 0x4d, 0xdf, 0xdb, 0x2f, 0x87, 0xf7,
  40150. 0xde, 0xc3, 0x77, 0x89, 0x71, 0xfd, 0x70, 0x38, 0xed, 0xe6, 0x27, 0xb1,
  40151. 0xbd, 0x94, 0x5f, 0x39, 0x20, 0x72, 0x59, 0xc4, 0x39, 0xd0, 0x20, 0x5d,
  40152. 0xe2, 0xe7, 0xe0, 0x00, 0x61, 0xc7, 0x65, 0xbd, 0xef, 0x05, 0xb3, 0xc7,
  40153. 0x7e, 0xae, 0xc5, 0x83, 0x7f, 0xc1, 0x32, 0x4e, 0x2a, 0x17, 0x64, 0x4e,
  40154. 0x2a, 0x9a, 0x2d, 0x26, 0x99, 0xa2, 0xd7, 0x37, 0x3a, 0x10, 0x6a, 0x89,
  40155. 0x72, 0x43, 0x0e, 0x3a, 0x03, 0x4c, 0xf9, 0xfe, 0xe8, 0xfc, 0x87, 0x71,
  40156. 0x37, 0x71, 0x5a, 0x05, 0xbc, 0x4e, 0x20, 0x4c, 0xd7, 0xf9, 0x8d, 0x4e,
  40157. 0xb8, 0xb8, 0x56, 0x07, 0xc8, 0x6e, 0x34, 0x6d, 0x45, 0x83, 0x34, 0xf0,
  40158. 0x77, 0xfb, 0x18, 0xec, 0x72, 0xf6, 0x4c, 0xfb, 0xba, 0x84, 0xe9, 0x89,
  40159. 0x3d, 0xfd, 0xb7, 0x0d, 0x70, 0xae, 0xa4, 0x48, 0x6b, 0x39, 0xf8, 0x62,
  40160. 0xc0, 0x7f, 0x0c, 0xf2, 0xa3, 0xfa, 0x7a, 0x64, 0x83, 0x57, 0x7d, 0x4c,
  40161. 0x04, 0x96, 0xd7, 0x9d, 0x10, 0x8b, 0x34, 0x48, 0x17, 0xff, 0x74, 0x5c,
  40162. 0x9c, 0xbe, 0xeb, 0xe5, 0x52, 0x94, 0x6a, 0x34, 0x6f, 0xf7, 0x95, 0x32,
  40163. 0x38, 0x5a, 0x9b, 0x08, 0xf6, 0xda, 0x8c, 0x0f, 0x9c, 0x5d, 0x04, 0x45,
  40164. 0xd4, 0xe9, 0xa4, 0x7a, 0xc4, 0xfd, 0x70, 0xfe, 0xa1, 0x3d, 0x21, 0xa0,
  40165. 0x01, 0xe5, 0x21, 0xca, 0xa7, 0xd9, 0xf1, 0x9f, 0x45, 0xe1, 0xe8, 0x2d,
  40166. 0x27, 0xe6, 0x87, 0xc8, 0x0d, 0xad, 0x13, 0xdb, 0xfe, 0x2f, 0xaa, 0x2b,
  40167. 0xdc, 0xa6, 0x1a, 0xc9, 0x19, 0x78, 0x1a, 0x1f, 0x10, 0xcf, 0x31, 0xe1,
  40168. 0x06, 0x28, 0x66, 0xb3, 0xa7, 0xa2, 0xa6, 0xf1, 0x3b, 0x2d, 0xd3, 0x81,
  40169. 0xaf, 0x6f, 0xc9, 0x88, 0x76, 0xe9, 0x83, 0x6c, 0x52, 0xb9, 0x70, 0x51,
  40170. 0x87, 0x6b, 0x8b, 0xbd, 0x5b, 0x9c, 0xa9, 0xf3, 0xcb, 0x55, 0xd1, 0x76,
  40171. 0x40, 0xe1, 0x90, 0xb9, 0x4c, 0xbd, 0xab, 0x1d, 0xa0, 0x5b, 0x5b, 0x34,
  40172. 0x14, 0x2f, 0x87, 0x8f, 0x63, 0xa0, 0x2d, 0x29, 0x4e, 0x50, 0x4b, 0x18,
  40173. 0x5f, 0x86, 0xac, 0x1b, 0x93, 0xe9, 0x59, 0x38, 0xa1, 0x2a, 0x36, 0x21,
  40174. 0xb2, 0xa4, 0xc0, 0x79, 0xc1, 0x60, 0xfc, 0x0f, 0xbf, 0x99, 0x04, 0x9d,
  40175. 0x4b, 0x17, 0x60, 0x5b, 0xcd, 0x78, 0x03, 0xd7, 0x7c, 0x4b, 0x9b, 0x17,
  40176. 0x58, 0x24, 0x60, 0xb8, 0x08, 0x92, 0x48, 0x4f, 0x66, 0x42, 0x9a, 0x98,
  40177. 0x2a, 0x99, 0x9a, 0x8f, 0xdd, 0xd7, 0x09, 0xf3, 0x22, 0x66, 0x62, 0xef,
  40178. 0xe5, 0x64, 0xd3, 0xdf, 0x31, 0xaa, 0x84, 0x4c, 0xa5, 0x3f, 0x4e, 0x27,
  40179. 0x48, 0x37, 0x96, 0x63, 0xbf, 0x8d, 0xe1, 0xf0, 0xd1, 0xef, 0x95, 0x1a,
  40180. 0xe6, 0xf4, 0x02, 0x61, 0xbf, 0xe3, 0xbc, 0x8b, 0x3d, 0x0b, 0x77, 0x91,
  40181. 0xc0, 0x5d, 0xfb, 0xe6, 0x7e, 0xab, 0x5e, 0xc5, 0x1c, 0x5b, 0x16, 0xfd,
  40182. 0x88, 0xa4, 0x78, 0x4c, 0x06, 0x77, 0xc3, 0x6e, 0x84, 0x0c, 0xda, 0xbf,
  40183. 0xf3, 0x8e, 0xd3, 0x61, 0x65, 0xac, 0xf2, 0x18, 0x70, 0x68, 0x84, 0x6f,
  40184. 0x9f, 0x3a, 0x94, 0x81, 0xa6, 0xc7, 0xc3, 0x92, 0xee, 0x4b, 0x20, 0x15,
  40185. 0x4e, 0x03, 0x76, 0x51, 0x5b, 0x4e, 0xe1, 0x5c, 0x51, 0x5e, 0x1b, 0x9c,
  40186. 0x30, 0x25, 0x79, 0xdd, 0x70, 0x12, 0xec, 0xdc, 0x45, 0x95, 0x45, 0x43,
  40187. 0xcd, 0xbb, 0xae, 0xa0, 0x0d, 0x43, 0xb4, 0xc9, 0x8c, 0x62, 0xfd, 0x7b,
  40188. 0xed, 0x50, 0x78, 0xb7, 0xa6, 0x94, 0xcb, 0x98, 0xb0, 0xbe, 0x09, 0xd9,
  40189. 0x0c, 0xb2, 0xc4, 0x8b, 0x96, 0x93, 0xd9, 0x26, 0xc6, 0x6d, 0x26, 0x93,
  40190. 0x32, 0x4e, 0x86, 0x72, 0x74, 0x92, 0x00, 0x72, 0x0b, 0x20, 0xa3, 0x2b,
  40191. 0x94, 0xe6, 0x10, 0x56, 0x5a, 0x41, 0x71, 0x92, 0x08, 0xce, 0x6c, 0xc4,
  40192. 0x1d, 0x9e, 0x71, 0x82, 0x64, 0x23, 0xe5, 0x15, 0xef, 0x4a, 0x7c, 0x4d,
  40193. 0xe3, 0x92, 0xbc, 0xa3, 0xa2, 0x29, 0xb7, 0x46, 0xfa, 0x8f, 0x9f, 0xc2,
  40194. 0x5d, 0xe4, 0xc0, 0x9c, 0x3f, 0x40, 0x17, 0xae, 0x44, 0xf3, 0x28, 0x10,
  40195. 0x29, 0x24, 0xa9, 0x1c, 0x9e, 0xd2, 0x55, 0x4c, 0xee, 0x45, 0xfe, 0x4a,
  40196. 0x45, 0x12, 0xf5, 0xde, 0xc7, 0x64, 0x15, 0xc3, 0x4a, 0x77, 0x63, 0x05,
  40197. 0x8d, 0xa6, 0x31, 0xa0, 0xad, 0x64, 0xaf, 0x3c, 0x69, 0x2c, 0x25, 0x78,
  40198. 0xae, 0xa0, 0x88, 0x96, 0x8a, 0xc2, 0x9b, 0x8d, 0xee, 0x6f, 0x2e, 0x79,
  40199. 0x1f, 0xec, 0x32, 0x35, 0x75, 0x83, 0x19, 0x8b, 0xda, 0xca, 0xd0, 0xaf,
  40200. 0x6a, 0x6c, 0x42, 0xe8, 0x81, 0xb5, 0x69, 0x31, 0x0b, 0x7d, 0xbc, 0xd8,
  40201. 0xd2, 0xb7, 0x7a, 0x8f, 0xfa, 0xcf, 0x91, 0x07, 0x1f, 0xda, 0xa9, 0x1f,
  40202. 0xb7, 0x2d, 0xff, 0x50, 0x15, 0x2a, 0xef, 0x8c, 0xa1, 0xe3, 0x7f, 0x08,
  40203. 0x95, 0xf2, 0x99, 0x83, 0x1f, 0x97, 0x71, 0x3e, 0x35, 0x3c, 0x8c, 0xe7,
  40204. 0x08, 0xd8, 0xa6, 0x1f, 0x0c, 0xa6, 0x52, 0xdc, 0x73, 0xa0, 0xfc, 0xd2,
  40205. 0x73, 0xe9, 0x27, 0x9d, 0xfd, 0x7a, 0x4a, 0x29, 0xd3, 0x12, 0x26, 0x13,
  40206. 0x0f, 0xce, 0xea, 0x56, 0x99, 0x61, 0x78, 0x47, 0x2c, 0xa0, 0x16, 0xa0,
  40207. 0xe2, 0x64, 0x97, 0x57, 0x31, 0xf0, 0x32, 0x5b, 0x44, 0x93, 0x76, 0x8b,
  40208. 0x59, 0x63, 0x5c, 0x5b, 0x0f, 0xe1, 0xe7, 0x74, 0x98, 0x11, 0x2d, 0x90,
  40209. 0xe4, 0xde, 0xd4, 0x3a, 0xc2, 0xfd, 0x24, 0xe3, 0x1f, 0x7a, 0xf4, 0x40,
  40210. 0xbb, 0x51, 0x92, 0x8f, 0x68, 0x9c, 0x51, 0xab, 0xdc, 0xf6, 0x1e, 0x96,
  40211. 0xca, 0x56, 0x5c, 0x92, 0xca, 0xb2, 0x1b, 0x2e, 0x6d, 0x20, 0x28, 0xb3,
  40212. 0x0a, 0x8e, 0xfd, 0xa9, 0xa2, 0x38, 0x74, 0x60, 0x37, 0xa6, 0x96, 0x02,
  40213. 0x20, 0x8a, 0x9a, 0x2b, 0x8c, 0xb9, 0x6d, 0xec, 0xff, 0xbf, 0x88, 0xbd,
  40214. 0x6c, 0xb4, 0x10, 0xbd, 0xfa, 0x5a, 0xeb, 0xb2, 0x6b, 0x74, 0x13, 0x2d,
  40215. 0xa5, 0xdb, 0x60, 0x93, 0xc6, 0xed, 0x39, 0x4f, 0xc5, 0x63, 0xe1, 0x9e,
  40216. 0x57, 0x1f, 0xe7, 0x47, 0xa4, 0xfb, 0x7f, 0xfa, 0x3a, 0x46, 0x50, 0x3a,
  40217. 0xd8, 0xd3, 0x83, 0xf5, 0xe6, 0x5e, 0xf8, 0x09, 0x0d, 0xfa, 0x33, 0xe1,
  40218. 0x50, 0xe4, 0x36, 0x3e, 0x0a, 0x5d, 0xe6, 0xf8, 0x2e, 0x17, 0x87, 0x8f,
  40219. 0xe1, 0x8c, 0x82, 0x73, 0xbd, 0xdd, 0x3b, 0x77, 0x47, 0x9f, 0x42, 0xd7,
  40220. 0xf4, 0x2d, 0x6c, 0xef, 0xcc, 0x22, 0x15, 0x3c, 0xe9, 0x26, 0xea, 0xbc,
  40221. 0xee, 0x09, 0xd3, 0xea, 0x84, 0x0f, 0x46, 0xa8, 0xe0, 0xda, 0xc5, 0x57,
  40222. 0x02, 0x54, 0xb6, 0x88, 0x2b, 0x37, 0xe5, 0x96, 0xc5, 0x33, 0xb7, 0x45,
  40223. 0x5d, 0xb7, 0xc7, 0xfd, 0xa0, 0xfa, 0x85, 0x1b, 0x2f, 0xe1, 0xec, 0x89,
  40224. 0xc6, 0xb2, 0x51, 0x71, 0xcb, 0x08, 0x82, 0x3e, 0xc9, 0xed, 0x80, 0x9d,
  40225. 0x37, 0x31, 0x9d, 0x15, 0xde, 0x24, 0x6f, 0xbd, 0x0e, 0x73, 0xa2, 0xb8,
  40226. 0x7e, 0x29, 0x7e, 0x96, 0xe4, 0xbb, 0xd6, 0x23, 0x17, 0xff, 0x33, 0x97,
  40227. 0x9c, 0x87, 0xe0, 0xe5, 0x0f, 0xb9, 0xb6, 0x31, 0x33, 0xad, 0xf8, 0xd8,
  40228. 0xdb, 0xa0, 0x71, 0x13, 0xe4, 0x1c, 0xce, 0xd0, 0x7e, 0x65, 0x7b, 0xa0,
  40229. 0x38, 0x17, 0x53, 0x4f, 0x71, 0x75, 0x6d, 0x02, 0x61, 0xc4, 0x52, 0xf8,
  40230. 0xe4, 0x2e, 0xbc, 0x52, 0xc1, 0xb1, 0x7e, 0x83, 0x0a, 0xa1, 0xd1, 0xcd,
  40231. 0x2f, 0xa0, 0x30, 0xfd, 0x41, 0x86, 0x7f, 0x26, 0xd1, 0xe7, 0xfc, 0xd7,
  40232. 0xc7, 0x37, 0xe5, 0x11, 0xa6, 0xc0, 0x9a, 0x75, 0x18, 0x04, 0x36, 0xca,
  40233. 0x8e, 0x26, 0x7d, 0xcf, 0xa2, 0x6a, 0x94, 0x9b, 0xc4, 0xf7, 0xc7, 0xeb,
  40234. 0x51, 0x13, 0xa3, 0x6f, 0x8c, 0x80, 0x5f, 0xae, 0xf0, 0x18, 0xa0, 0x88,
  40235. 0xe0, 0x8d, 0xb7, 0x80, 0x4e, 0x8c, 0xec, 0xc8, 0x7b, 0xeb, 0xac, 0x29,
  40236. 0xb7, 0x4a, 0x0f, 0x33, 0xdd, 0x9d, 0x89, 0x0a, 0x10, 0xb0, 0xce, 0x74,
  40237. 0x59, 0xa2, 0x62, 0x91, 0xc9, 0xac, 0x56, 0xcd, 0x69, 0xd3, 0x01, 0x6d,
  40238. 0x51, 0xe7, 0x04, 0xc3, 0xfb, 0xe9, 0x79, 0x1b, 0x72, 0x72, 0x1a, 0x90,
  40239. 0x0a, 0x20, 0x55, 0x85, 0xc1, 0x8b, 0xeb, 0x1e, 0x9f, 0x9f, 0x4a, 0x81,
  40240. 0x47, 0x97, 0x96, 0xbc, 0xc2, 0xe4, 0xc2, 0xfe, 0xa0, 0x20, 0xda, 0x70,
  40241. 0x0c, 0x2b, 0xe2, 0xd4, 0xc8, 0xcb, 0x46, 0x00, 0xb6, 0x7c, 0xfb, 0xbd,
  40242. 0x56, 0x94, 0x3d, 0x7f, 0x64, 0xf7, 0x88, 0xb5, 0xa7, 0xfe, 0xbe, 0x64,
  40243. 0x8a, 0xe4, 0x00, 0x08, 0x82, 0x5b, 0x8f, 0x98, 0x77, 0x87, 0xda, 0xaf,
  40244. 0x16, 0x25, 0x4a, 0x9a, 0xed, 0xfb, 0x50, 0x18, 0x45, 0x46, 0x2b, 0x73,
  40245. 0xff, 0xb9, 0xb9, 0xab, 0xa2, 0x8f, 0x3a, 0xaf, 0xc5, 0x0a, 0x14, 0x91,
  40246. 0xb2, 0x3f, 0xa6, 0x93, 0xf4, 0x81, 0x20, 0x77, 0xfa, 0x51, 0x79, 0x62,
  40247. 0xe8, 0xe6, 0x89, 0x52, 0x39, 0xd5, 0x01, 0xa2, 0x87, 0xa3, 0x53, 0x74,
  40248. 0x3c, 0x36, 0x8a, 0xc3, 0xb4, 0x44, 0x3b, 0x15, 0x21, 0xf6, 0xdc, 0x18,
  40249. 0x02, 0xd2, 0x57, 0xe5, 0x10, 0xf0, 0x3d, 0x61, 0xa7, 0x16, 0x85, 0x6f,
  40250. 0x71, 0x07, 0x75, 0x50, 0x4b, 0x21, 0x53, 0x47, 0x38, 0x35, 0x9e, 0xa7,
  40251. 0xd8, 0xfd, 0x74, 0x59, 0x15, 0x32, 0x7b, 0x89, 0xd0, 0x2c, 0xd9, 0xf6,
  40252. 0x40, 0x49, 0x79, 0xdc, 0xfb, 0x0a, 0x64, 0x59, 0x9b, 0x17, 0x47, 0x36,
  40253. 0xcb, 0xf0, 0xc3, 0xcc, 0x14, 0x8e, 0x1f, 0xa8, 0x12, 0xaa, 0xb7, 0x6a,
  40254. 0xba, 0x45, 0xf9, 0xc4, 0x44, 0xe7, 0xb5, 0x7c, 0xdd, 0xbe, 0x16, 0x76,
  40255. 0x52, 0x92, 0x3d, 0x78, 0xb7, 0xec, 0x81, 0x96, 0xd8, 0x7f, 0x34, 0x2a,
  40256. 0xa2, 0x64, 0x5f, 0xfd, 0xb1, 0x42, 0x4c, 0x79, 0x98, 0xc9, 0x17, 0x48,
  40257. 0x74, 0x12, 0x72, 0x2c, 0xde, 0x91, 0x7e, 0xa9, 0x49, 0x2a, 0xcc, 0x5c,
  40258. 0x60, 0x05, 0x25, 0x09, 0x72, 0x20, 0x80, 0x42, 0x7b, 0x18, 0xc2, 0xfc,
  40259. 0x2a, 0x5e, 0x3e, 0x2d, 0x61, 0xa6, 0xf6, 0x82, 0x42, 0x83, 0x81, 0x66,
  40260. 0x4d, 0xa6, 0xe1, 0xf9, 0xf6, 0x48, 0xd4, 0xc8, 0x69, 0xed, 0xee, 0xb5,
  40261. 0x7a, 0xcb, 0xf6, 0x0a, 0x76, 0x0e, 0x61, 0x8b, 0xf2, 0x1a, 0x8a, 0xa7,
  40262. 0x88, 0xb0, 0x90, 0xd5, 0x23, 0xaa, 0xe0, 0x2b, 0xd6, 0xd0, 0xef, 0x49,
  40263. 0x13, 0x88, 0xc7, 0x50, 0xf0, 0x9e, 0xd5, 0x28, 0xe1, 0xaa, 0x1d, 0xaf,
  40264. 0xd9, 0x73, 0xb3, 0x9e, 0xa7, 0xd8, 0xfc, 0xb9, 0x22, 0x97, 0x0e, 0x21,
  40265. 0xa0, 0xb9, 0xf9, 0xea, 0x1e, 0x95, 0x88, 0xda, 0x85, 0x7c, 0x32, 0x7c,
  40266. 0xbd, 0xef, 0xf8, 0x44, 0x25, 0x5f, 0x23, 0xfd, 0x14, 0x78, 0xc6, 0xdb,
  40267. 0x86, 0xee, 0xf8, 0xda, 0xc0, 0xae, 0x92, 0x6a, 0x03, 0xa9, 0x0a, 0xee,
  40268. 0x4a, 0x22, 0x5a, 0x6c, 0x39, 0xd3, 0x91, 0x7d, 0x91, 0x43, 0xac, 0x79,
  40269. 0xad, 0xab, 0xb7, 0x91, 0xb1, 0x20, 0x84, 0x7f, 0x0a, 0xd7, 0xa8, 0x62,
  40270. 0x95, 0xab, 0x04, 0xb6, 0xb2, 0xf1, 0xd4, 0xb0, 0xac, 0x52, 0x89, 0xb0,
  40271. 0x93, 0xdf, 0xdf, 0x80, 0x26, 0x0c, 0x32, 0x31, 0xb3, 0xba, 0xa1, 0xba,
  40272. 0x6f, 0xa3, 0x14, 0x5c, 0xfa, 0x37, 0x3b, 0x6a, 0xf2, 0xc4, 0x34, 0x27,
  40273. 0x08, 0x1a, 0xe4, 0xfc, 0x89, 0x58, 0x79, 0x34, 0x36, 0xe4, 0xad, 0x4b,
  40274. 0x3f, 0x57, 0x7b, 0xc1, 0x59, 0x2d, 0xb6, 0x54, 0x44, 0xbe, 0x4e, 0x5d,
  40275. 0x0d, 0x6a, 0xf3, 0xcd, 0xbf, 0xcd, 0x4d, 0x9f, 0x9a, 0x50, 0x09, 0xa4,
  40276. 0x6b, 0x8b, 0xb3, 0x01, 0x69, 0x6c, 0x69, 0x5d, 0x28, 0x73, 0x9e, 0xb5,
  40277. 0xc2, 0xc7, 0x6e, 0xff, 0x4c, 0x5c, 0x6b, 0x93, 0x22, 0xc1, 0x9f, 0xa6,
  40278. 0x71, 0xbf, 0x4d, 0x2d, 0x4e, 0x4e, 0x98, 0xa3, 0x6d, 0xab, 0x05, 0xa0,
  40279. 0xde, 0x34, 0x41, 0x28, 0xa4, 0x38, 0x75, 0x4e, 0xdf, 0x7f, 0xc9, 0xdd,
  40280. 0xbf, 0x5a, 0xd4, 0xcd, 0x38, 0x0c, 0x89, 0xe7, 0x0e, 0xfc, 0x0f, 0x27,
  40281. 0x39, 0x21, 0xa4, 0xa6, 0x07, 0x7b, 0x2a, 0x13, 0x56, 0xe7, 0x4e, 0x55,
  40282. 0x57, 0x71, 0x98, 0xb9, 0x3d, 0x59, 0xb5, 0xa8, 0x24, 0x18, 0x08, 0xa2,
  40283. 0x6e, 0x9a, 0xe5, 0x97, 0xa7, 0x38, 0xd9, 0x43, 0x9b, 0x19, 0x17, 0x34,
  40284. 0x03, 0xd6, 0xba, 0xe9, 0x71, 0x38, 0x26, 0x90, 0x78, 0x9e, 0x1c, 0x41,
  40285. 0x8d, 0x60, 0xdd, 0x0e, 0x12, 0x46, 0x37, 0xb4, 0x79, 0x87, 0x33, 0x12,
  40286. 0x24, 0xc4, 0x5a, 0x6c, 0x70, 0xa2, 0xb2, 0x58, 0xbb, 0xe7, 0xd6, 0x88,
  40287. 0x42, 0x2d, 0x49, 0xc8, 0x67, 0x1e, 0xc5, 0xed, 0x16, 0xa8, 0x1f, 0x36,
  40288. 0x2b, 0xfb, 0x0d, 0x51, 0x96, 0xc8, 0x78, 0xf2, 0xab, 0x82, 0xa1, 0xe2,
  40289. 0xaf, 0x8c, 0xa4, 0x13, 0x54, 0x90, 0xf1, 0xe7, 0xbb, 0xd1, 0x09, 0x23,
  40290. 0x76, 0x0e, 0x50, 0x32, 0xc5, 0x54, 0xbb, 0x1e, 0x12, 0x5d, 0x59, 0xf3,
  40291. 0xe9, 0xc9, 0xa4, 0xaa, 0xbc, 0x13, 0x1d, 0xf0, 0x79, 0x54, 0xae, 0x70,
  40292. 0xc0, 0xea, 0xcb, 0x21, 0x32, 0xe6, 0xe6, 0x8e, 0xaa, 0x51, 0x46, 0x25,
  40293. 0x1e, 0xf1, 0x3f, 0x9f, 0xf6, 0xff, 0x19, 0x53, 0x97, 0xbc, 0xa2, 0xb6,
  40294. 0x91, 0x59, 0x27, 0x1e, 0x39, 0x76, 0x76, 0x02, 0x0b, 0x03, 0x25, 0x6b,
  40295. 0x00, 0x02, 0xfa, 0x7d, 0x69, 0x5e, 0xde, 0x64, 0x33, 0xbf, 0xab, 0x3e,
  40296. 0x3f, 0x24, 0x32, 0x68, 0xbf, 0x90, 0x8f, 0x0f, 0xc5, 0x36, 0x58, 0x9e,
  40297. 0x9b, 0x11, 0xd1, 0x2a, 0x8a, 0x0d, 0xac, 0x3a, 0x23, 0xe2, 0x8e, 0xd6,
  40298. 0x0d, 0x4a, 0x8b, 0x45, 0x04, 0x47, 0xd9, 0x5a, 0x46, 0x6c, 0x70, 0x82,
  40299. 0xc7, 0x81, 0x67, 0xdc, 0xa6, 0xfa, 0x6a, 0x86, 0xfd, 0x01, 0xed, 0x90,
  40300. 0xf6, 0xe6, 0x26, 0x6d, 0xac, 0x52, 0x03, 0x4a, 0x91, 0x08, 0x7b, 0xa5,
  40301. 0x9c, 0xca, 0xd3, 0x2d, 0x79, 0xf1, 0xed, 0xcb, 0xaa, 0x8f, 0x77, 0xc8,
  40302. 0x17, 0xa8, 0xfb, 0x6c, 0x15, 0x62, 0xab, 0x34, 0xd1, 0xdd, 0x94, 0x3e,
  40303. 0xd4, 0x0c, 0x47, 0xed, 0x04, 0x91, 0xd2, 0xd7, 0x98, 0xb4, 0x43, 0x57,
  40304. 0xd1, 0x54, 0xef, 0x63, 0xba, 0xe3, 0x8a, 0x72, 0xc5, 0xb9, 0xf4, 0x30,
  40305. 0xfa, 0x16, 0x3c, 0xe1, 0xbb, 0xbe, 0x57, 0x90, 0xb9, 0xa1, 0xa0, 0x23,
  40306. 0xfa, 0xdd, 0xbe, 0x2f, 0xb3, 0xec, 0x41, 0x8b, 0x64, 0xeb, 0xc5, 0x41,
  40307. 0xea, 0xa8, 0x16, 0x76, 0x6f, 0x28, 0xda, 0x2b, 0x5f, 0x03, 0x0b, 0xe8,
  40308. 0x1c, 0x29, 0x71, 0xd8, 0x4e, 0x41, 0xdf, 0x39, 0x8e, 0x6a, 0x95, 0x79,
  40309. 0x85, 0x9c, 0xa9, 0x79, 0xd9, 0x8f, 0x33, 0xaf, 0x15, 0x3b, 0x5a, 0x82,
  40310. 0x56, 0x32, 0x98, 0x0c, 0xf6, 0xf6, 0x64, 0x42, 0xd4, 0x6a, 0x15, 0x0f,
  40311. 0xb9, 0x75, 0x22, 0xbd, 0x9a, 0x58, 0xa6, 0x01, 0x3a, 0x63, 0xf0, 0x80,
  40312. 0x78, 0x22, 0x80, 0xa0, 0x14, 0xe1, 0x37, 0x6b, 0xd4, 0x99, 0x3f, 0xc2,
  40313. 0xba, 0x2b, 0x8f, 0xf3, 0x56, 0xc8, 0x1b, 0xe4, 0x7a, 0x5e, 0x96, 0x60,
  40314. 0xee, 0x74, 0x54, 0xb6, 0x6d, 0x5c, 0x3d, 0x3e, 0x05, 0xf0, 0x9a, 0xf6,
  40315. 0xcd, 0xdd, 0x06, 0xdb, 0x8c, 0x21, 0xb9, 0xf5, 0x28, 0x57, 0x9c, 0x4f,
  40316. 0xb4, 0x08, 0xcf, 0xac, 0x6c, 0xfe, 0x30, 0xaf, 0xa2, 0xef, 0xcf, 0x93,
  40317. 0x15, 0xdd, 0x12, 0x16, 0x19, 0x7d, 0xbc, 0x57, 0xd9, 0xce, 0xbe, 0x0e,
  40318. 0xfc, 0xe1, 0xf0, 0x4a, 0x7c, 0xaa, 0xbf, 0x20, 0x64, 0x00, 0x34, 0x59,
  40319. 0xed, 0xea, 0x12, 0x58, 0x46, 0x4c, 0xc6, 0x2f, 0x77, 0x62, 0x1d, 0x82,
  40320. 0x5c, 0xe8, 0x98, 0x0d, 0xef, 0x5c, 0x0e, 0xec, 0x5d, 0x2e, 0x5f, 0xd2,
  40321. 0x22, 0x43, 0x2d, 0xe1, 0x02, 0xd5, 0x4a, 0x0a, 0x79, 0x6f, 0xa5, 0xec,
  40322. 0x48, 0xaa, 0xee, 0xf8, 0xe3, 0x5f, 0xdd, 0xe7, 0x26, 0x87, 0xb5, 0xc4,
  40323. 0xcf, 0xd9, 0x7f, 0xa8, 0xaa, 0xb6, 0xbe, 0xe9, 0x02, 0x49, 0x5d, 0x5f,
  40324. 0x81, 0x8b, 0xb9, 0xbd, 0xc0, 0xc9, 0xd5, 0xfe, 0x36, 0x3e, 0x49, 0x56,
  40325. 0x63, 0x8b, 0xce, 0xef, 0x48, 0x6e, 0xc0, 0xd4, 0x04, 0x0c, 0x33, 0x45,
  40326. 0x6e, 0x97, 0x9e, 0xa3, 0xae, 0xbc, 0xc2, 0xce, 0xdc, 0xe3, 0xff, 0x48,
  40327. 0x51, 0x68, 0x89, 0xad, 0xae, 0xc7, 0xd1, 0xde, 0xe2, 0xf9, 0xfe, 0x00,
  40328. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40329. 0x0c, 0x18, 0x20, 0x24, 0x2f, 0x33, 0x3f
  40330. #else
  40331. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  40332. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  40333. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  40334. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  40335. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  40336. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  40337. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  40338. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  40339. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  40340. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  40341. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  40342. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  40343. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  40344. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  40345. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  40346. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  40347. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  40348. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  40349. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  40350. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  40351. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  40352. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  40353. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  40354. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  40355. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  40356. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  40357. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  40358. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  40359. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  40360. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  40361. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  40362. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  40363. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  40364. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  40365. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  40366. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  40367. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  40368. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  40369. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  40370. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  40371. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  40372. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  40373. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  40374. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  40375. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  40376. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  40377. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  40378. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  40379. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  40380. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  40381. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  40382. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  40383. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  40384. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  40385. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  40386. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  40387. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  40388. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  40389. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  40390. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  40391. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  40392. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  40393. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  40394. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  40395. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  40396. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  40397. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  40398. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  40399. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  40400. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  40401. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  40402. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  40403. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  40404. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  40405. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  40406. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  40407. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  40408. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  40409. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  40410. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  40411. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  40412. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  40413. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  40414. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  40415. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  40416. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  40417. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  40418. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  40419. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  40420. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  40421. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  40422. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  40423. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  40424. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  40425. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  40426. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  40427. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  40428. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  40429. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  40430. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  40431. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  40432. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  40433. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  40434. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  40435. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  40436. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  40437. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  40438. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  40439. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  40440. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  40441. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  40442. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  40443. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  40444. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  40445. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  40446. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  40447. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  40448. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  40449. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  40450. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  40451. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  40452. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  40453. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  40454. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  40455. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  40456. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  40457. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  40458. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  40459. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  40460. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  40461. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  40462. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  40463. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  40464. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  40465. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  40466. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  40467. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  40468. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  40469. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  40470. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  40471. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  40472. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  40473. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  40474. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  40475. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  40476. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  40477. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  40478. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  40479. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  40480. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  40481. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  40482. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  40483. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  40484. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  40485. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  40486. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  40487. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  40488. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  40489. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  40490. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  40491. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  40492. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  40493. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  40494. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  40495. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  40496. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  40497. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  40498. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  40499. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  40500. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  40501. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  40502. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  40503. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  40504. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  40505. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  40506. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  40507. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  40508. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  40509. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  40510. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  40511. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  40512. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  40513. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  40514. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  40515. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  40516. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  40517. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  40518. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  40519. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  40520. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  40521. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  40522. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  40523. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  40524. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  40525. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  40526. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  40527. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  40528. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  40529. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  40530. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  40531. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  40532. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  40533. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  40534. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  40535. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  40536. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  40537. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  40538. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  40539. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  40540. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  40541. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  40542. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  40543. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  40544. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  40545. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  40546. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  40547. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  40548. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  40549. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  40550. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  40551. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  40552. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  40553. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  40554. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  40555. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  40556. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  40557. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  40558. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  40559. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  40560. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  40561. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  40562. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  40563. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  40564. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  40565. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  40566. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  40567. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  40568. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  40569. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  40570. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  40571. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  40572. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  40573. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  40574. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  40575. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  40576. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  40577. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  40578. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  40579. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  40580. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  40581. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  40582. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  40583. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  40584. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  40585. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  40586. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  40587. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  40588. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  40589. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  40590. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  40591. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  40592. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  40593. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  40594. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  40595. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  40596. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  40597. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  40598. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  40599. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  40600. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  40601. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  40602. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  40603. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  40604. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  40605. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  40606. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  40607. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  40608. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  40609. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  40610. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  40611. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  40612. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  40613. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  40614. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  40615. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  40616. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  40617. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  40618. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  40619. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  40620. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  40621. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  40622. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  40623. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  40624. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  40625. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  40626. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  40627. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  40628. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  40629. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  40630. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  40631. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  40632. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  40633. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  40634. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  40635. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  40636. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  40637. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  40638. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  40639. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  40640. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  40641. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  40642. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  40643. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  40644. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  40645. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  40646. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  40647. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  40648. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  40649. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  40650. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  40651. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  40652. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  40653. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  40654. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  40655. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  40656. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  40657. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  40658. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  40659. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  40660. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  40661. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  40662. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  40663. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  40664. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  40665. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  40666. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  40667. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  40668. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  40669. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  40670. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  40671. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  40672. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  40673. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  40674. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  40675. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  40676. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  40677. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  40678. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  40679. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  40680. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  40681. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  40682. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  40683. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  40684. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  40685. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  40686. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  40687. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  40688. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  40689. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  40690. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  40691. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  40692. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  40693. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  40694. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  40695. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  40696. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  40697. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  40698. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  40699. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  40700. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  40701. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  40702. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  40703. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  40704. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  40705. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  40706. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  40707. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  40708. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  40709. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  40710. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  40711. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  40712. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  40713. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  40714. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  40715. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  40716. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  40717. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  40718. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  40719. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  40720. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  40721. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  40722. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  40723. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  40724. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  40725. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  40726. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  40727. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  40728. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  40729. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  40730. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  40731. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  40732. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  40733. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  40734. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  40735. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  40736. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  40737. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  40738. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  40739. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  40740. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  40741. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  40742. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  40743. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  40744. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  40745. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  40746. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  40747. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  40748. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  40749. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  40750. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  40751. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  40752. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  40753. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  40754. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  40755. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  40756. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  40757. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  40758. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  40759. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  40760. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  40761. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  40762. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  40763. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  40764. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  40765. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  40766. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  40767. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  40768. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  40769. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  40770. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  40771. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  40772. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  40773. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  40774. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  40775. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  40776. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  40777. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  40778. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  40779. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  40780. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  40781. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  40782. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  40783. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  40784. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  40785. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  40786. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  40787. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  40788. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  40789. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  40790. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  40791. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  40792. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  40793. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f
  40794. #endif
  40795. };
  40796. return dilithium_param_vfy_test(WC_ML_DSA_87, ml_dsa_87_pub_key,
  40797. (word32)sizeof(ml_dsa_87_pub_key), ml_dsa_87_sig,
  40798. (word32)sizeof(ml_dsa_87_sig));
  40799. }
  40800. #endif
  40801. #endif
  40802. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40803. static wc_test_ret_t dilithium_param_test(int param, WC_RNG* rng)
  40804. {
  40805. wc_test_ret_t ret;
  40806. dilithium_key* key;
  40807. byte* sig = NULL;
  40808. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  40809. word32 sigLen;
  40810. byte msg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  40811. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40812. int res = 0;
  40813. #endif
  40814. #endif
  40815. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  40816. DYNAMIC_TYPE_TMP_BUFFER);
  40817. if (key == NULL) {
  40818. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  40819. }
  40820. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
  40821. DYNAMIC_TYPE_TMP_BUFFER);
  40822. if (sig == NULL) {
  40823. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  40824. }
  40825. ret = wc_dilithium_init(key);
  40826. if (ret != 0) {
  40827. ret = WC_TEST_RET_ENC_EC(ret);
  40828. return ret;
  40829. }
  40830. ret = wc_dilithium_set_level(key, param);
  40831. if (ret != 0)
  40832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40833. ret = wc_dilithium_make_key(key, rng);
  40834. if (ret != 0)
  40835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40836. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  40837. sigLen = wc_dilithium_sig_size(key);
  40838. if (sigLen <= 0)
  40839. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40840. ret = wc_dilithium_sign_msg(msg, (word32)sizeof(msg), sig, &sigLen, key,
  40841. rng);
  40842. if (ret != 0)
  40843. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40844. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40845. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  40846. key);
  40847. if (ret != 0)
  40848. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40849. if (res != 1)
  40850. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  40851. #endif
  40852. #endif
  40853. out:
  40854. wc_dilithium_free(key);
  40855. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  40856. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  40857. return ret;
  40858. }
  40859. #endif
  40860. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
  40861. {
  40862. wc_test_ret_t ret;
  40863. WC_RNG rng;
  40864. #ifndef HAVE_FIPS
  40865. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  40866. #else
  40867. ret = wc_InitRng(&rng);
  40868. #endif
  40869. if (ret != 0) {
  40870. ret = WC_TEST_RET_ENC_EC(ret);
  40871. return ret;
  40872. }
  40873. #ifndef WOLFSSL_NO_ML_DSA_44
  40874. #ifdef WOLFSSL_WC_DILITHIUM
  40875. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40876. ret = dilithium_param_44_vfy_test();
  40877. if (ret != 0)
  40878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40879. #endif
  40880. #endif
  40881. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40882. ret = dilithium_param_test(WC_ML_DSA_44, &rng);
  40883. if (ret != 0)
  40884. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40885. #endif
  40886. #endif
  40887. #ifndef WOLFSSL_NO_ML_DSA_65
  40888. #ifdef WOLFSSL_WC_DILITHIUM
  40889. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40890. ret = dilithium_param_65_vfy_test();
  40891. if (ret != 0)
  40892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40893. #endif
  40894. #endif
  40895. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40896. ret = dilithium_param_test(WC_ML_DSA_65, &rng);
  40897. if (ret != 0)
  40898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40899. #endif
  40900. #endif
  40901. #ifndef WOLFSSL_NO_ML_DSA_87
  40902. #ifdef WOLFSSL_WC_DILITHIUM
  40903. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40904. ret = dilithium_param_87_vfy_test();
  40905. if (ret != 0)
  40906. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40907. #endif
  40908. #endif
  40909. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40910. ret = dilithium_param_test(WC_ML_DSA_87, &rng);
  40911. if (ret != 0)
  40912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40913. #endif
  40914. #endif
  40915. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  40916. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  40917. out:
  40918. #endif
  40919. wc_FreeRng(&rng);
  40920. return ret;
  40921. }
  40922. #endif /* HAVE_DILITHIUM */
  40923. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  40924. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  40925. void *context)
  40926. {
  40927. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  40928. * BE USED FOR TESTING PURPOSES! Production applications should
  40929. * write only to non-volatile storage. */
  40930. XMEMCPY(context, priv, privSz);
  40931. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  40932. }
  40933. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  40934. void *context)
  40935. {
  40936. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  40937. * BE USED FOR TESTING PURPOSES! */
  40938. XMEMCPY(priv, context, privSz);
  40939. return WC_XMSS_RC_READ_TO_MEMORY;
  40940. }
  40941. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
  40942. {
  40943. int i = 0;
  40944. int j = 0;
  40945. XmssKey signingKey;
  40946. XmssKey verifyKey;
  40947. WC_RNG rng;
  40948. word32 pkSz = 0;
  40949. word32 skSz = 0;
  40950. word32 sigSz = 0;
  40951. word32 bufSz = 0;
  40952. unsigned char * sk = NULL;
  40953. unsigned char * old_sk = NULL;
  40954. const char * msg = "XMSS post quantum signature test";
  40955. word32 msgSz = (word32) XSTRLEN(msg);
  40956. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10
  40957. const char * param = "XMSS-SHA2_10_256";
  40958. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 20
  40959. const char * param = "XMSSMT-SHA2_20/4_256";
  40960. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 40
  40961. const char * param = "XMSSMT-SHA2_40/8_256";
  40962. #else
  40963. const char * param = "XMSSMT-SHA2_60/12_256";
  40964. #endif
  40965. byte * sig = NULL;
  40966. int ret2 = -1;
  40967. int ret = WC_TEST_RET_ENC_NC;
  40968. WOLFSSL_ENTER("xmss_test");
  40969. #ifndef HAVE_FIPS
  40970. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  40971. #else
  40972. ret = wc_InitRng(&rng);
  40973. #endif
  40974. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  40975. ret = wc_XmssKey_Init(&signingKey, NULL, INVALID_DEVID);
  40976. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  40977. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  40978. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  40979. /* Set the parameter string to the signing key, and
  40980. * get sizes for secret key, pub key, and signature. */
  40981. ret = wc_XmssKey_SetParamStr(&signingKey, param);
  40982. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  40983. ret = wc_XmssKey_GetPubLen(&signingKey, &pkSz);
  40984. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  40985. if (pkSz != XMSS_SHA256_PUBLEN) {
  40986. return WC_TEST_RET_ENC_EC(pkSz);
  40987. }
  40988. ret = wc_XmssKey_GetPrivLen(&signingKey, &skSz);
  40989. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  40990. ret = wc_XmssKey_GetSigLen(&signingKey, &sigSz);
  40991. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  40992. /* Allocate signature array. */
  40993. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  40994. if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  40995. bufSz = sigSz;
  40996. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  40997. fprintf(stderr, "param: %s\n", param);
  40998. fprintf(stderr, "pkSz: %d\n", pkSz);
  40999. fprintf(stderr, "skSz: %d\n", skSz);
  41000. fprintf(stderr, "sigSz: %d\n", sigSz);
  41001. #endif
  41002. /* Allocate current and old secret keys.*/
  41003. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41004. if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41005. old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41006. if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41007. XMEMSET(sk, 0, skSz);
  41008. XMEMSET(old_sk, 0, skSz);
  41009. XMEMSET(sig, 0, sigSz);
  41010. ret = wc_XmssKey_SetWriteCb(&signingKey, xmss_write_key_mem);
  41011. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41012. ret = wc_XmssKey_SetReadCb(&signingKey, xmss_read_key_mem);
  41013. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41014. ret = wc_XmssKey_SetContext(&signingKey, (void *) sk);
  41015. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41016. ret = wc_XmssKey_MakeKey(&signingKey, &rng);
  41017. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41018. /* Export the pub to a verify key. */
  41019. ret = wc_XmssKey_ExportPub(&verifyKey, &signingKey);
  41020. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41021. /* Repeat a few times to check that:
  41022. * 1. The secret key is mutated on each sign.
  41023. * 2. We can verify each new signature.
  41024. * Only do a few times, because the full signature space
  41025. * for this parameter set is huge. */
  41026. for (i = 0; i < 10; ++i) {
  41027. XMEMCPY(old_sk, sk, skSz);
  41028. ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41029. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41030. if (sigSz != bufSz) { return WC_TEST_RET_ENC_I(i); }
  41031. /* Old secret key and current secret key should not match. */
  41032. ret = XMEMCMP(old_sk, sk, skSz);
  41033. if (ret == 0) { return WC_TEST_RET_ENC_I(i); }
  41034. ret = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41035. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41036. /* Flip bits in a few places throughout the signature, stepping in multiple
  41037. * of hash size. These should all fail with -1. */
  41038. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41039. sig[j] ^= 1;
  41040. ret2 = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41041. msgSz);
  41042. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41043. /* Verify passed when it should have failed. */
  41044. return WC_TEST_RET_ENC_I(j);
  41045. }
  41046. /* Flip this spot back. */
  41047. sig[j] ^= 1;
  41048. }
  41049. }
  41050. /* Cleanup everything. */
  41051. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41052. sig = NULL;
  41053. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41054. sk = NULL;
  41055. XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41056. old_sk = NULL;
  41057. wc_XmssKey_Free(&signingKey);
  41058. wc_FreeRng(&rng);
  41059. return ret;
  41060. }
  41061. #endif /*if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)*/
  41062. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_SMALL_STACK) && \
  41063. WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41064. /* A simple xmss verify only test using:
  41065. * XMSS-SHA2_10_256
  41066. * pub len: 68
  41067. * msg len: 32
  41068. * sig len: 2500
  41069. *
  41070. * These were generated with the test xmss_fast, from the unpatched
  41071. * xmss-reference repository:
  41072. * https://github.com/XMSS/xmss-reference
  41073. * */
  41074. static const byte xmss_pub[XMSS_SHA256_PUBLEN] =
  41075. {
  41076. 0x00,0x00,0x00,0x01,0xA5,0x41,0x31,0x96,
  41077. 0x0A,0xF9,0xF3,0xB2,0x4B,0x2E,0x5B,0x3E,
  41078. 0xCA,0x74,0xAD,0x6C,0xA5,0x89,0xAD,0x2C,
  41079. 0x0E,0x96,0xB3,0x54,0xFB,0x5B,0x63,0x50,
  41080. 0x96,0x81,0xE2,0x59,0x72,0x10,0x09,0x54,
  41081. 0xBB,0x39,0xAC,0xEE,0x78,0xEF,0x95,0xEC,
  41082. 0x01,0x1D,0xF0,0x36,0x68,0xE2,0xC4,0xA5,
  41083. 0x2F,0x60,0x42,0x7E,0xD3,0x8E,0xAA,0x27,
  41084. 0xC9,0xB7,0x39,0x4E
  41085. };
  41086. static /* not const */ byte xmss_msg[32] =
  41087. {
  41088. 0x07,0x9F,0x80,0x86,0xDB,0x76,0x27,0xDF,
  41089. 0xED,0x5B,0x2A,0x81,0x60,0x60,0x7D,0xB4,
  41090. 0xE8,0x7A,0x69,0x45,0x20,0x6B,0xA2,0x96,
  41091. 0xC0,0x21,0xA5,0x46,0x29,0x63,0x9B,0x37
  41092. };
  41093. /* This was actually the 5th signature produced from
  41094. * xmss_fast test in xmss-reference. */
  41095. static /* not const */ byte xmss_sig[2500] =
  41096. {
  41097. 0x00,0x00,0x00,0x05,0xF0,0x15,0x34,0xBA,
  41098. 0x92,0x03,0x6A,0xB9,0xA5,0x23,0x86,0x11,
  41099. 0xAE,0x65,0x0A,0x5C,0x78,0x2C,0xC9,0xBE,
  41100. 0x7E,0xA6,0xDC,0xA2,0x8B,0xA9,0x9C,0x50,
  41101. 0xF6,0x61,0x8D,0x9D,0xD7,0xE9,0xC0,0xF8,
  41102. 0x67,0xCD,0x8A,0xC4,0x9B,0x74,0x96,0x07,
  41103. 0x5D,0xF2,0xC9,0xCC,0x28,0x05,0xB1,0xBE,
  41104. 0x5E,0xA4,0xBA,0xBE,0xAB,0xD8,0x21,0x6B,
  41105. 0x21,0x5F,0xAB,0xB7,0x6C,0xEC,0x2F,0xC8,
  41106. 0xC6,0x74,0x3E,0x97,0x1B,0xC3,0x45,0x57,
  41107. 0xAF,0xAA,0x1E,0xA8,0xF2,0x86,0xA8,0xAA,
  41108. 0x43,0x6D,0x66,0xE9,0x81,0x14,0xDE,0x09,
  41109. 0x39,0xD2,0xAF,0xD1,0x4C,0xE7,0x75,0x18,
  41110. 0x0D,0xAA,0x29,0xA1,0x92,0x53,0xCC,0xE9,
  41111. 0xF3,0x0B,0x1E,0x3B,0xE2,0xAE,0x80,0x0C,
  41112. 0xE7,0x7A,0x7C,0x13,0x8A,0x28,0xC6,0x5F,
  41113. 0x0A,0xA4,0xA3,0x73,0x0A,0x3A,0xC2,0xA6,
  41114. 0x3B,0xB4,0x30,0x67,0xC0,0x36,0x18,0xA1,
  41115. 0x58,0xCD,0xAD,0x54,0x36,0x64,0xCE,0xFD,
  41116. 0x52,0xFF,0x70,0x7E,0x09,0xFB,0x13,0xA2,
  41117. 0xEA,0xDF,0x67,0x8D,0x6C,0x42,0xB2,0x78,
  41118. 0xF5,0x7D,0x5C,0x4B,0xF7,0x8E,0xCF,0x3E,
  41119. 0xB7,0xC6,0xC1,0x23,0xFA,0x65,0xDE,0xD2,
  41120. 0xFA,0x40,0x51,0x97,0x0D,0x52,0x32,0x76,
  41121. 0x7E,0x82,0x8D,0xD0,0xB9,0x1E,0x62,0xD9,
  41122. 0x1E,0xC1,0xDB,0x40,0x43,0x37,0x4A,0x23,
  41123. 0x8A,0x1D,0x35,0xFA,0xF4,0x53,0x11,0x5A,
  41124. 0xB5,0x6D,0x1E,0x8B,0x22,0xC8,0x7D,0x2A,
  41125. 0xE4,0x94,0xAA,0x25,0x20,0x40,0x96,0xDB,
  41126. 0x82,0x62,0xBA,0x8F,0x8B,0x45,0xCB,0x4F,
  41127. 0x35,0x88,0x33,0xEB,0xEF,0xB3,0xBA,0xA7,
  41128. 0x09,0x72,0xB3,0x4C,0xEC,0xF2,0xC3,0xC7,
  41129. 0x5E,0x02,0x6C,0x41,0x93,0xCB,0x3C,0x89,
  41130. 0x12,0x09,0x68,0x54,0x8E,0xEC,0x6A,0x7E,
  41131. 0x20,0xE1,0x70,0x3D,0x8C,0xEB,0xB4,0x36,
  41132. 0xBE,0x91,0xBE,0x97,0xB5,0xA6,0x34,0x16,
  41133. 0x95,0x0F,0x10,0x26,0xA9,0x13,0x80,0x88,
  41134. 0x9C,0xAA,0x68,0xEC,0x34,0x70,0x4A,0x15,
  41135. 0x9B,0x5E,0x57,0x05,0x87,0x1C,0xF8,0x35,
  41136. 0x45,0x29,0xE9,0x6E,0xF2,0x70,0x13,0x42,
  41137. 0x89,0x4E,0x77,0xC0,0x18,0xC7,0x55,0x6D,
  41138. 0xE7,0xFA,0x0D,0x63,0x83,0x16,0x19,0x01,
  41139. 0x2D,0xFD,0x31,0x14,0x94,0xCA,0x3E,0x0E,
  41140. 0xD6,0x11,0x34,0x81,0x57,0x58,0xEC,0x24,
  41141. 0xA4,0x17,0x63,0xD3,0x25,0x00,0xBF,0x7D,
  41142. 0x78,0x5D,0xC5,0xD8,0xC6,0xC1,0xBD,0x8C,
  41143. 0xD0,0x94,0x0A,0xB1,0x33,0xA5,0x4B,0x31,
  41144. 0x25,0xF5,0xAF,0xE7,0x84,0x26,0xAA,0x05,
  41145. 0xBB,0xF3,0x9A,0xAF,0x58,0x36,0x40,0xEF,
  41146. 0x3D,0xA2,0xBD,0xCA,0xA1,0x8D,0x2F,0x6D,
  41147. 0x54,0xD2,0x62,0x33,0x09,0xAE,0xE6,0x73,
  41148. 0xD6,0x44,0xE8,0x7C,0x5C,0x39,0x2B,0x78,
  41149. 0x94,0x14,0xC7,0xC9,0xAF,0xEC,0x77,0x36,
  41150. 0xA1,0x61,0x61,0xF1,0xD0,0x09,0xA2,0xEE,
  41151. 0xE7,0x55,0xD7,0x35,0x89,0x89,0x9B,0xCF,
  41152. 0xFA,0xA6,0x09,0x1E,0x3B,0xBD,0x5D,0xD9,
  41153. 0x25,0xE7,0xED,0xDD,0x7C,0xF0,0x1C,0x57,
  41154. 0xE0,0x06,0xBB,0x08,0x39,0x59,0xDF,0xD7,
  41155. 0xAF,0x4B,0x88,0x0D,0x87,0x8F,0x4A,0xF3,
  41156. 0x1C,0xD4,0x4B,0xB3,0xE2,0xF3,0x1B,0x86,
  41157. 0x4F,0xCD,0x35,0x75,0xE2,0x03,0xF9,0x1D,
  41158. 0xBF,0x3E,0xD1,0x7B,0xC7,0x23,0x11,0x75,
  41159. 0x5F,0x92,0x0D,0x98,0xEE,0x14,0xE1,0xDA,
  41160. 0x7A,0x02,0x17,0x47,0x6B,0x41,0xEA,0x47,
  41161. 0xA1,0xAF,0x06,0x79,0x1A,0x52,0x6F,0x19,
  41162. 0x31,0x70,0x71,0xBD,0xC2,0x61,0x8D,0xB7,
  41163. 0xEE,0x6B,0x69,0x2A,0xE8,0x21,0x7A,0x95,
  41164. 0xBE,0x86,0x2A,0xA1,0xF4,0xE2,0x2F,0x17,
  41165. 0x02,0xFD,0xAD,0x17,0x9F,0x0A,0x0A,0x78,
  41166. 0xA9,0x92,0x30,0x21,0x72,0x2B,0x28,0xF8,
  41167. 0xF2,0x3E,0x05,0xD5,0xAC,0xC0,0x82,0xF8,
  41168. 0xD2,0xDA,0xD0,0xA3,0xBC,0x93,0xDB,0xA5,
  41169. 0x46,0xDE,0x14,0x1E,0xD4,0x3A,0x5D,0x79,
  41170. 0x3D,0x31,0x4B,0x06,0xCE,0x22,0x29,0x3C,
  41171. 0x98,0xB6,0x18,0x8A,0xAE,0xF7,0xBA,0x22,
  41172. 0x88,0xA1,0xEE,0xC0,0x14,0x4C,0x4A,0xA0,
  41173. 0x57,0x0A,0xD3,0x18,0xA2,0x3D,0xDD,0xC7,
  41174. 0x83,0x73,0xFC,0x38,0x9B,0x31,0xA3,0xE1,
  41175. 0x17,0x76,0xA1,0xA2,0x69,0xFC,0xAB,0x08,
  41176. 0x80,0x72,0x8D,0xF5,0xE4,0x14,0xB7,0x6B,
  41177. 0x03,0xFF,0xE8,0x11,0x4B,0x06,0x55,0x7E,
  41178. 0x36,0x21,0x2F,0xD7,0x54,0x82,0xC9,0x31,
  41179. 0xB4,0x85,0x68,0x41,0xEF,0x75,0xB0,0x3A,
  41180. 0xEA,0x4F,0xE0,0xEC,0x72,0xCC,0x33,0x96,
  41181. 0xCE,0x7D,0xAD,0xDD,0x0D,0x27,0x05,0x6E,
  41182. 0xA2,0xD4,0x11,0x07,0xD8,0x7D,0x27,0xD4,
  41183. 0x80,0x8F,0x00,0x22,0xE4,0xFC,0x2C,0x9D,
  41184. 0xD5,0xD8,0x18,0x7F,0x4E,0xF4,0xB9,0x7F,
  41185. 0xEF,0xD6,0x00,0x08,0x5C,0x05,0x04,0x1E,
  41186. 0x9A,0xC6,0x8D,0xCC,0x19,0xD9,0x0B,0x06,
  41187. 0xCC,0x6A,0x17,0xE2,0x03,0x23,0xDB,0x1C,
  41188. 0xBC,0xA2,0xB9,0xA2,0x95,0x3C,0x73,0xD8,
  41189. 0xFF,0xE6,0x0E,0xAE,0x04,0xB2,0xFC,0x91,
  41190. 0x4F,0xEF,0x8A,0x58,0xB7,0x31,0x68,0x4C,
  41191. 0x1E,0xD0,0x5B,0x85,0xCC,0x03,0xDC,0xF4,
  41192. 0xAC,0xDB,0x03,0x9B,0x35,0x33,0x08,0x71,
  41193. 0xD0,0x50,0x8D,0xDC,0xE3,0x3A,0x98,0x40,
  41194. 0x41,0x80,0xDD,0x35,0xE1,0xA2,0xAF,0x14,
  41195. 0x9A,0xDB,0xD3,0x68,0x14,0xE2,0x50,0x7A,
  41196. 0x76,0x3F,0xE4,0xA4,0x1B,0xAA,0xC1,0x06,
  41197. 0x87,0x9A,0x92,0xF9,0xBE,0x9E,0x86,0x8C,
  41198. 0x92,0x1D,0x74,0xB1,0x7F,0x27,0x43,0xC0,
  41199. 0xEE,0x2E,0xC2,0x6C,0x6D,0xAA,0x0C,0x0E,
  41200. 0x71,0xC9,0x56,0xD6,0x3A,0x56,0xCB,0x90,
  41201. 0xD1,0x7E,0x6E,0x1C,0x6A,0x00,0x2D,0x02,
  41202. 0x2C,0x96,0xF0,0x2A,0x37,0x37,0x18,0x07,
  41203. 0x0B,0xF4,0xB4,0x8C,0x30,0xF2,0xA4,0xAB,
  41204. 0x66,0xFB,0x8B,0x22,0xC0,0x00,0x7E,0x05,
  41205. 0xB6,0xF9,0x95,0x49,0x33,0xA1,0xDC,0x97,
  41206. 0x0C,0x5C,0x61,0x46,0xE2,0xD7,0x87,0x4B,
  41207. 0xC4,0xC7,0x5F,0x26,0x06,0x84,0xD7,0x47,
  41208. 0x05,0xF1,0x33,0xFF,0x85,0x85,0xB2,0xBD,
  41209. 0x1F,0x44,0xC6,0xC2,0x7D,0x51,0xBE,0x0E,
  41210. 0xB5,0xC4,0x44,0x2F,0xFE,0x73,0x5F,0xF4,
  41211. 0xA4,0xEF,0xE2,0xF1,0x73,0x0B,0xEF,0x3E,
  41212. 0x2B,0xD7,0xCC,0x9F,0xDA,0x1A,0x7E,0x92,
  41213. 0x39,0xA1,0x55,0xBF,0x60,0x0A,0xDB,0x23,
  41214. 0x74,0xFE,0xE7,0x05,0x63,0xA9,0x85,0x52,
  41215. 0x9F,0xCC,0xC3,0xFF,0xF6,0x6C,0x1B,0x4E,
  41216. 0x4F,0x01,0xBD,0xC3,0xEB,0x37,0xEC,0x29,
  41217. 0x21,0x3B,0x2C,0xC9,0x2E,0x93,0x20,0x3E,
  41218. 0x19,0xC0,0x8B,0xE8,0x33,0xCD,0xC6,0x6A,
  41219. 0x6E,0x72,0x13,0x15,0xA1,0x90,0x20,0x0C,
  41220. 0x14,0x66,0xED,0xCC,0xA4,0xDD,0x7F,0x58,
  41221. 0x53,0xBC,0x4A,0x68,0xFC,0x86,0x3E,0xAA,
  41222. 0xF1,0x17,0x0F,0x3E,0x20,0x54,0x93,0xF4,
  41223. 0x98,0xBF,0xB4,0x07,0x05,0xBD,0x70,0xE7,
  41224. 0xD7,0x34,0xFD,0xE3,0x69,0xDF,0xCD,0xF5,
  41225. 0x1A,0x73,0x6E,0xC9,0x2B,0x21,0xFB,0xB8,
  41226. 0x7E,0x44,0x10,0x83,0x56,0xCE,0xD5,0x15,
  41227. 0x9A,0x75,0xFC,0x91,0x8E,0x6B,0x9E,0x1A,
  41228. 0x3A,0x33,0x39,0x35,0xB4,0x0D,0x74,0xF4,
  41229. 0xFB,0x4C,0x0E,0x37,0xFE,0x82,0x95,0x46,
  41230. 0x6B,0xD2,0x6E,0xEE,0xCD,0x4D,0x38,0xAF,
  41231. 0x0A,0xAA,0xF1,0xD5,0xA4,0x7C,0x04,0xD8,
  41232. 0xB9,0xDB,0x11,0x68,0x88,0x35,0x41,0xDE,
  41233. 0x31,0x33,0x0C,0xDC,0x2D,0x4C,0xA8,0x20,
  41234. 0xCC,0x2C,0x4C,0x63,0xAB,0xBA,0xDF,0x48,
  41235. 0x84,0xD5,0x25,0xBC,0x70,0xE3,0x49,0xAA,
  41236. 0x43,0xCA,0x8B,0xE7,0x9F,0xDD,0x20,0x76,
  41237. 0x9B,0x38,0xF4,0xBA,0x4D,0x4E,0x34,0x4A,
  41238. 0xAF,0x81,0xE7,0x0B,0xEC,0xE9,0x59,0xC1,
  41239. 0x35,0x22,0x7F,0x69,0x46,0x62,0xD2,0x18,
  41240. 0x6E,0x1F,0x79,0xD1,0xAD,0xC3,0x84,0x95,
  41241. 0x96,0xB2,0x18,0x58,0x5E,0x7E,0x0C,0x25,
  41242. 0x0A,0x0F,0x69,0xA3,0x1D,0xEC,0x29,0xCB,
  41243. 0xDA,0xA2,0xD1,0x1A,0x10,0xA5,0x52,0xC3,
  41244. 0x62,0x1E,0xC5,0x83,0xFF,0xA3,0x56,0xC2,
  41245. 0xFD,0x87,0x3B,0x57,0x52,0x98,0x36,0x95,
  41246. 0x77,0x6B,0xE5,0x49,0x10,0x8E,0x39,0xDD,
  41247. 0xCA,0x4B,0xB3,0x9F,0x4C,0x0C,0x11,0x62,
  41248. 0xF3,0x22,0x78,0xDB,0x48,0xEB,0x68,0xFE,
  41249. 0xE4,0x2A,0xE9,0xAA,0x8F,0x7A,0x2F,0x69,
  41250. 0xA5,0xC5,0x03,0x2D,0xEF,0x62,0xA8,0x71,
  41251. 0x65,0x06,0x40,0x84,0x10,0x0F,0xF2,0xED,
  41252. 0xBC,0x70,0x71,0x69,0x24,0xA2,0xBF,0x83,
  41253. 0x39,0xDD,0xFA,0xA2,0x7B,0xE5,0xEC,0x3D,
  41254. 0xFE,0x3B,0x52,0x6E,0x3D,0x82,0xA6,0x2A,
  41255. 0x86,0x01,0x61,0x51,0x63,0xBF,0xF9,0x0A,
  41256. 0x06,0x72,0xF1,0xD5,0x39,0x0C,0xBA,0xC9,
  41257. 0x78,0xC6,0x77,0x22,0xE4,0x96,0x6E,0xB1,
  41258. 0x48,0x62,0x84,0x62,0x2D,0xEA,0x49,0x56,
  41259. 0x50,0x86,0x3F,0x90,0xC3,0x01,0x42,0x45,
  41260. 0xED,0xE6,0x9A,0x65,0x19,0x93,0x7F,0x48,
  41261. 0x16,0xF2,0x50,0xA7,0x70,0xB3,0xF5,0xDB,
  41262. 0x0E,0x5E,0x22,0x9E,0x64,0x04,0x26,0x69,
  41263. 0xC1,0x16,0xEE,0x65,0x08,0x82,0x27,0x65,
  41264. 0xEC,0x3D,0xDF,0x51,0x5E,0x2D,0xE8,0x76,
  41265. 0xF2,0xE3,0xE4,0x24,0x04,0x88,0x06,0x0F,
  41266. 0xB2,0x7B,0x9B,0x72,0x3D,0x4C,0x7D,0x6A,
  41267. 0x1F,0xB2,0xA2,0xD2,0x35,0xD6,0x40,0x25,
  41268. 0xC2,0x0B,0x25,0xF9,0xDF,0x26,0xE4,0xDC,
  41269. 0xFB,0xB1,0x84,0x84,0x77,0x1B,0x45,0x51,
  41270. 0x60,0xD5,0xF0,0xB6,0x09,0xE6,0xBC,0xE3,
  41271. 0x1C,0x70,0x96,0x2C,0xD3,0x9D,0x7D,0x7F,
  41272. 0xB1,0x70,0xDA,0x79,0xB8,0x74,0x99,0xBF,
  41273. 0x84,0x95,0xCC,0x93,0xD7,0x51,0xDD,0x66,
  41274. 0xD3,0x70,0x0C,0x75,0x86,0x09,0x06,0xFD,
  41275. 0x66,0x14,0x80,0xCD,0xF3,0x59,0xB4,0x92,
  41276. 0x5F,0xE4,0xEE,0x00,0xA8,0xB0,0x8B,0x5C,
  41277. 0x3E,0xDB,0x8A,0x9C,0x0B,0xB5,0x99,0xC2,
  41278. 0x0D,0x81,0x09,0x06,0x6C,0x28,0xC0,0x7E,
  41279. 0xA5,0x07,0x70,0x64,0xD7,0x41,0xF4,0xC3,
  41280. 0x66,0x61,0x1C,0xA8,0x51,0xF6,0x3C,0xBA,
  41281. 0xE0,0x94,0xA3,0x11,0x8C,0x2E,0xBA,0x13,
  41282. 0xB2,0x47,0x48,0x93,0xB4,0x1A,0x2C,0x9A,
  41283. 0x6E,0x8E,0x30,0x66,0x7B,0xD3,0xBB,0x3B,
  41284. 0x5D,0x97,0x0D,0xE4,0xEA,0x24,0x28,0x9E,
  41285. 0xB4,0x88,0xCE,0x1D,0x7D,0x6F,0x39,0xB3,
  41286. 0x87,0x21,0xE5,0x08,0x93,0xF0,0xD4,0x9D,
  41287. 0x2D,0x91,0xC9,0xFD,0x0C,0x74,0x34,0xB4,
  41288. 0x1F,0xFE,0xDA,0xDC,0x10,0x5B,0x8D,0x2B,
  41289. 0x87,0xD3,0x42,0xB4,0xAE,0x32,0x9C,0xAE,
  41290. 0x4C,0x99,0xD8,0xED,0x44,0x41,0x07,0xE0,
  41291. 0x8F,0xBD,0xA5,0x7C,0x5A,0xDF,0x91,0x29,
  41292. 0x00,0xB5,0x4B,0xC3,0x3A,0x40,0x6C,0x48,
  41293. 0xAB,0x2A,0xF3,0x02,0xCB,0xB3,0x69,0xDA,
  41294. 0x06,0x0C,0x4D,0x5C,0x45,0xC3,0x28,0xAC,
  41295. 0x7A,0x01,0xD4,0xF8,0xCB,0x07,0x63,0x89,
  41296. 0x09,0x34,0x78,0xA7,0x14,0x39,0xCF,0x2D,
  41297. 0x94,0x8D,0x7A,0x4E,0x4E,0xBD,0xC4,0x32,
  41298. 0xAB,0x21,0xC9,0xDA,0x3F,0x5F,0x04,0x6B,
  41299. 0x14,0x40,0x18,0x18,0x2F,0xF9,0x46,0x17,
  41300. 0x57,0x54,0x9B,0x28,0x7B,0xBD,0xF9,0xA2,
  41301. 0x13,0xAC,0x69,0x24,0xB1,0x31,0x39,0xBF,
  41302. 0x8D,0x75,0xC3,0xFD,0x03,0x54,0x5A,0xFD,
  41303. 0xD4,0x7A,0xB7,0x56,0x4F,0x66,0x43,0x57,
  41304. 0x1B,0xFB,0xF9,0x92,0x7A,0x83,0xE6,0xFF,
  41305. 0xB4,0xBA,0x83,0xD2,0x61,0x8E,0x4A,0x82,
  41306. 0x82,0xA8,0xF5,0x0C,0xD2,0x43,0x53,0xA8,
  41307. 0x85,0x0A,0xD4,0x69,0x7B,0x04,0x71,0x3B,
  41308. 0x80,0x49,0x27,0x47,0x12,0xB6,0xB0,0xEA,
  41309. 0x90,0x0A,0xFA,0xA8,0xC8,0x78,0x61,0xDE,
  41310. 0x30,0x12,0xBB,0xDC,0xA6,0x57,0x56,0x30,
  41311. 0x6E,0xF1,0xA8,0x3B,0xF6,0x09,0x07,0xEA,
  41312. 0x31,0xE2,0x08,0x23,0x31,0x0F,0xD4,0x34,
  41313. 0xE3,0x60,0xC2,0x2B,0xDB,0x5A,0x99,0xCF,
  41314. 0xD4,0x6B,0x4E,0x75,0x65,0x35,0xE8,0x8B,
  41315. 0x93,0x7D,0xCA,0x11,0x47,0xF0,0x3E,0x11,
  41316. 0x5C,0xD1,0xEE,0x4B,0x11,0xB4,0x65,0x2B,
  41317. 0x6B,0x79,0xC0,0x86,0x60,0xA4,0x4B,0x24,
  41318. 0xA0,0x5C,0x70,0x34,0xC3,0x7C,0xE7,0x4F,
  41319. 0x97,0x89,0x4D,0xFE,0x22,0x89,0x3A,0xE9,
  41320. 0x07,0xB9,0x1A,0x86,0xB8,0x7A,0x12,0x38,
  41321. 0xE1,0x24,0x46,0xBC,0x9B,0x21,0xCD,0xAC,
  41322. 0x30,0xAB,0x98,0x21,0x31,0xC5,0x17,0x3F,
  41323. 0x1E,0x56,0xC3,0x18,0xCE,0xF0,0xA1,0xCC,
  41324. 0xFF,0x9D,0xA8,0x53,0xAF,0x74,0x77,0x54,
  41325. 0x02,0x9A,0x8F,0xA4,0xD4,0xBD,0xB2,0x1A,
  41326. 0xBA,0x52,0x2E,0x19,0xBE,0x49,0x11,0x45,
  41327. 0x02,0x01,0x7A,0xBF,0x28,0xD6,0x18,0xED,
  41328. 0xBD,0xCE,0xE4,0xDE,0xB5,0xF1,0x53,0x5D,
  41329. 0x65,0xF9,0x5F,0x83,0x8F,0x2D,0xF2,0x82,
  41330. 0xA0,0x2D,0x28,0xD3,0x0A,0x9E,0x0F,0x7F,
  41331. 0xC7,0xC4,0x43,0x7F,0xC3,0x0E,0x06,0xEB,
  41332. 0x4E,0xB4,0x2D,0xFA,0xDD,0x48,0xAB,0xF4,
  41333. 0x7D,0x41,0x48,0x33,0x5A,0xE6,0x70,0x02,
  41334. 0xE7,0x71,0x8D,0xD9,0x6B,0x0C,0x5A,0x8F,
  41335. 0xA4,0xC1,0xB7,0x4E,0x96,0x83,0xD6,0xA7,
  41336. 0x1D,0xF1,0x88,0xB3,0x6E,0xF4,0x12,0xA9,
  41337. 0xF6,0x31,0x69,0x66,0xFE,0xFE,0x02,0xF2,
  41338. 0x86,0x6D,0xBB,0x57,0x51,0x8C,0x4C,0xE9,
  41339. 0x7C,0x92,0x3E,0x3A,0xD3,0x2D,0xA8,0x82,
  41340. 0x53,0x84,0x26,0x89,0xBB,0xCC,0x13,0x12,
  41341. 0x3D,0x94,0xBB,0xDF,0x3D,0x4C,0xDF,0x27,
  41342. 0x9B,0x1F,0xB8,0xB6,0xE4,0xEA,0xA2,0x07,
  41343. 0xF8,0x4D,0x42,0x8F,0x29,0x90,0xFE,0x21,
  41344. 0x20,0xE9,0x55,0x02,0xAD,0x90,0xA7,0x77,
  41345. 0x4E,0x29,0xB6,0xD9,0x14,0x94,0xB2,0x25,
  41346. 0xA4,0xB2,0x0E,0x96,0x31,0xAB,0x9E,0x93,
  41347. 0x49,0xAC,0xA9,0xCB,0x68,0x22,0xBA,0xB8,
  41348. 0x57,0x5C,0x9D,0x65,0xC1,0xF1,0xFC,0x99,
  41349. 0x7C,0x3C,0xE9,0xEA,0x4B,0x29,0x22,0x2F,
  41350. 0xDB,0x17,0x21,0x8D,0xB0,0x13,0xBF,0xEE,
  41351. 0x7D,0xE4,0x8B,0x6D,0x17,0xE0,0x53,0x92,
  41352. 0x0B,0x32,0x6B,0xB1,0x65,0x2E,0xA7,0x83,
  41353. 0xFD,0x62,0x62,0xE3,0xAA,0x81,0xE8,0xD6,
  41354. 0xF7,0xB1,0x30,0x65,0x80,0x9F,0x77,0x1E,
  41355. 0x4A,0xEA,0xE8,0x45,0x32,0x12,0x3A,0xFB,
  41356. 0x22,0xE9,0xA9,0xF6,0xCB,0xAB,0xA8,0x0C,
  41357. 0x20,0xA8,0x7C,0xF9,0xF7,0x53,0xC1,0xB4,
  41358. 0xC0,0x5D,0x06,0x45,0xDD,0x7E,0xA7,0x34,
  41359. 0xA1,0x21,0xC2,0x62,0xAB,0x22,0x45,0x3D,
  41360. 0x73,0x4C,0x26,0xD1,0x1A,0xB2,0xF0,0xB2,
  41361. 0x6D,0x11,0x70,0x58,0xAA,0xF5,0xA4,0xF5,
  41362. 0xF8,0x0B,0x3D,0xC1,0xF6,0x17,0x70,0x15,
  41363. 0xCD,0x72,0x02,0x7E,0x4E,0x94,0x96,0x0A,
  41364. 0x56,0xCC,0xA5,0xA3,0xB3,0x7E,0xDD,0x5A,
  41365. 0x72,0xD2,0xFB,0xAC,0x3D,0x0E,0x66,0x65,
  41366. 0xE9,0x08,0x6C,0xB0,0x1C,0xE2,0x1A,0x82,
  41367. 0xF6,0xF3,0x34,0x89,0x73,0x02,0x5B,0x42,
  41368. 0x6D,0x40,0x61,0xB6,0xE0,0xE6,0x53,0x32,
  41369. 0xA5,0x72,0x17,0x4F,0x3B,0x51,0x4F,0xBC,
  41370. 0x00,0xE0,0x69,0x26,0xA9,0xAE,0x83,0xE3,
  41371. 0x73,0x7F,0x71,0x97,0xE0,0xDC,0x7C,0x63,
  41372. 0x9C,0x85,0x5F,0xDF,0x7D,0xE4,0x6C,0xD8,
  41373. 0xA9,0x3A,0x6F,0x5E,0x4A,0x2E,0xB0,0xE7,
  41374. 0x8B,0x45,0xE2,0x90,0x05,0x37,0xE8,0xAB,
  41375. 0x49,0x48,0x4C,0xC0,0x59,0x1D,0x8C,0x46,
  41376. 0x5B,0x84,0xE0,0x83,0xCE,0xEA,0x4B,0xF9,
  41377. 0xD4,0xDC,0x63,0xDF,0x79,0xB7,0x5C,0x11,
  41378. 0x25,0x7F,0x90,0x2E,0x0A,0x38,0x03,0xEA,
  41379. 0xEA,0xA1,0x26,0x52,0x20,0x19,0xA3,0xBE,
  41380. 0xFC,0x9D,0xB7,0x6E,0xA6,0x58,0x8E,0x6D,
  41381. 0xC5,0x58,0xE9,0xED,0x2F,0x55,0x43,0x8B,
  41382. 0x03,0x8B,0xE6,0xA4,0xC2,0x25,0x4B,0x36,
  41383. 0xBA,0xD3,0x27,0x48,0x40,0x2E,0x87,0xA2,
  41384. 0xD4,0x12,0xC6,0x05,0x36,0x03,0x11,0x51,
  41385. 0xD1,0xF2,0xAC,0x71,0x2C,0xB6,0xC3,0xA5,
  41386. 0x57,0x0F,0xAF,0x4B,0xBD,0xCD,0x47,0x4C,
  41387. 0x3A,0x52,0x6F,0x47,0xE7,0x0B,0xB7,0xD5,
  41388. 0xF7,0xA6,0x39,0x63,0x82,0x08,0x4C,0x41,
  41389. 0x0E,0x2A,0x52,0x42,0x5A,0xEA,0x59,0xC7,
  41390. 0x94,0xFB,0xD0,0x88,0x47,0x27,0xF6,0x97,
  41391. 0x03,0x9E,0x29,0xB8,0x3A,0x67,0xE6,0xF3,
  41392. 0x95,0xA7,0x42,0xC1,0x96,0xD1,0x9A,0xA6,
  41393. 0xF0,0x09,0x0C,0xEA,0xE0,0xAB,0x0F,0x15,
  41394. 0xE9,0xC3,0xEB,0xA5,0x89,0x86,0x98,0x32,
  41395. 0x83,0xAB,0x30,0x33,0xAE,0x90,0x8D,0x2E,
  41396. 0xB3,0xAA,0x91,0xA6,0xD9,0xA4,0x4A,0x54,
  41397. 0xE0,0xD3,0x08,0xCC,0x79,0xCE,0xE4,0x15,
  41398. 0x31,0xA6,0xCE,0x61,0xCF,0x03,0x06,0xEE,
  41399. 0x8E,0xE2,0x64,0x29,0xD1,0x54,0x9B,0xD0,
  41400. 0x5F,0x09,0x2B,0x8B,0xD5,0xF8,0xD4,0x7D,
  41401. 0xF1,0x97,0x32,0xD9,0xEA,0x5A,0x0E,0x10,
  41402. 0x8C,0x4D,0xFB,0x55,0xE6,0x27,0x0C,0xBA,
  41403. 0xC1,0x73,0xC1,0x73,0xE3,0x1C,0x09,0xB3,
  41404. 0x6F,0xB4,0x12,0xFA,0xF3,0x29,0xDC,0x23,
  41405. 0x32,0xED,0x80,0x87,0x83,0xC2,0xF6,0x07,
  41406. 0xB5,0xA9,0x22,0xDE,0x66,0x1A,0xA7,0x4A,
  41407. 0x86,0xF1,0x39,0x9B,0xF4,0xE7,0x50,0x15,
  41408. 0x4A,0x55,0x3C,0x93,0xB9,0xF9,0xFD,0xDC,
  41409. 0xB3,0x5D,0x73,0x52
  41410. };
  41411. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void)
  41412. {
  41413. XmssKey verifyKey;
  41414. unsigned char pub_raw[XMSS_SHA256_PUBLEN];
  41415. word32 pub_len = sizeof(pub_raw);
  41416. word32 pkSz = 0;
  41417. word32 sigSz = 0;
  41418. const char * param = "XMSS-SHA2_10_256";
  41419. int j = 0;
  41420. int ret2 = WC_TEST_RET_ENC_NC;
  41421. int ret = WC_TEST_RET_ENC_NC;
  41422. int n_diff = 0;
  41423. WOLFSSL_ENTER("xmss_test_verify_only");
  41424. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  41425. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41426. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41427. ret = wc_XmssKey_SetParamStr(&verifyKey, param);
  41428. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41429. ret = wc_XmssKey_GetPubLen(&verifyKey, &pkSz);
  41430. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41431. if (pkSz != XMSS_SHA256_PUBLEN) {
  41432. return WC_TEST_RET_ENC_EC(pkSz);
  41433. }
  41434. ret = wc_XmssKey_GetSigLen(&verifyKey, &sigSz);
  41435. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41436. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41437. fprintf(stderr, "param: %s\n", param);
  41438. fprintf(stderr, "pkSz: %d\n", pkSz);
  41439. fprintf(stderr, "sigSz: %d\n", sigSz);
  41440. #endif
  41441. if (sigSz != sizeof(xmss_sig)) {
  41442. return WC_TEST_RET_ENC_EC(sigSz);
  41443. }
  41444. ret = wc_XmssKey_ImportPubRaw(&verifyKey, xmss_pub, XMSS_SHA256_PUBLEN);
  41445. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41446. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41447. (byte *) xmss_msg, sizeof(xmss_msg));
  41448. if (ret != 0) {
  41449. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  41450. return WC_TEST_RET_ENC_EC(ret);
  41451. }
  41452. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  41453. ret = wc_XmssKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  41454. if (ret != 0) {
  41455. printf("error: wc_XmssKey_ExportPubRaw returned %d, expected 0\n", ret);
  41456. return WC_TEST_RET_ENC_EC(ret);
  41457. }
  41458. if (pub_len != XMSS_SHA256_PUBLEN) {
  41459. printf("error: xmss pub len %u, expected %d\n", pub_len,
  41460. XMSS_SHA256_PUBLEN);
  41461. return WC_TEST_RET_ENC_EC(pub_len);
  41462. }
  41463. n_diff = XMEMCMP(pub_raw, xmss_pub, sizeof(xmss_pub));
  41464. if (n_diff != 0) {
  41465. printf("error: exported and imported pub raw do not match: %d\n",
  41466. n_diff);
  41467. return WC_TEST_RET_ENC_EC(n_diff);
  41468. }
  41469. /* Flip bits in message. This should fail. */
  41470. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  41471. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41472. (byte *) xmss_msg, sizeof(xmss_msg));
  41473. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41474. printf("error: wc_XmssKey_Verify returned %d, expected -1\n", ret2);
  41475. return WC_TEST_RET_ENC_EC(ret2);
  41476. }
  41477. /* Flip it back. This should pass again. */
  41478. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  41479. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41480. (byte *) xmss_msg, sizeof(xmss_msg));
  41481. if (ret != 0) {
  41482. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  41483. return WC_TEST_RET_ENC_EC(ret);
  41484. }
  41485. /* Flip bits in a few places throughout the signature, stepping in multiple
  41486. * of hash size. These should all fail with -1. */
  41487. for (j = 0; j < (int) sizeof(xmss_sig); j+= 4 * 32) {
  41488. xmss_sig[j] ^= 1;
  41489. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41490. (byte *) xmss_msg, sizeof(xmss_msg));
  41491. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41492. /* Verify passed when it should have failed. */
  41493. return WC_TEST_RET_ENC_I(j);
  41494. }
  41495. /* Flip this spot back. */
  41496. xmss_sig[j] ^= 1;
  41497. }
  41498. /* Cleanup everything. */
  41499. wc_XmssKey_Free(&verifyKey);
  41500. return ret;
  41501. }
  41502. #endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_SMALL_STACK &&
  41503. * WOLFSSL_XMSS_MIN_HEIGHT <= 10 */
  41504. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  41505. static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
  41506. {
  41507. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41508. * BE USED FOR TESTING PURPOSES! Production applications should
  41509. * write only to non-volatile storage. */
  41510. XMEMCPY(context, priv, privSz);
  41511. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  41512. }
  41513. static int lms_read_key_mem(byte * priv, word32 privSz, void *context)
  41514. {
  41515. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41516. * BE USED FOR TESTING PURPOSES! */
  41517. XMEMCPY(priv, context, privSz);
  41518. return WC_LMS_RC_READ_TO_MEMORY;
  41519. }
  41520. /* LMS signature sizes are a function of their parameters. This
  41521. * test has a signature of 8688 bytes. */
  41522. #define WC_TEST_LMS_SIG_LEN (8688)
  41523. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
  41524. {
  41525. int i = 0;
  41526. int j = 0;
  41527. int ret = WC_TEST_RET_ENC_NC;
  41528. int ret2 = WC_TEST_RET_ENC_NC;
  41529. int sigsLeft = 0;
  41530. LmsKey signingKey;
  41531. LmsKey verifyKey;
  41532. WC_RNG rng;
  41533. word32 sigSz = 0;
  41534. const char * msg = "LMS HSS post quantum signature test";
  41535. word32 msgSz = (word32) XSTRLEN(msg);
  41536. unsigned char priv[HSS_MAX_PRIVATE_KEY_LEN];
  41537. unsigned char old_priv[HSS_MAX_PRIVATE_KEY_LEN];
  41538. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  41539. byte * sig = XMALLOC(WC_TEST_LMS_SIG_LEN, HEAP_HINT,
  41540. DYNAMIC_TYPE_TMP_BUFFER);
  41541. if (sig == NULL) {
  41542. return WC_TEST_RET_ENC_ERRNO;
  41543. }
  41544. #else
  41545. byte sig[WC_TEST_LMS_SIG_LEN];
  41546. #endif
  41547. WOLFSSL_ENTER("lms_test");
  41548. XMEMSET(priv, 0, sizeof(priv));
  41549. XMEMSET(old_priv, 0, sizeof(old_priv));
  41550. XMEMSET(sig, 0, WC_TEST_LMS_SIG_LEN);
  41551. #ifndef HAVE_FIPS
  41552. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41553. #else
  41554. ret = wc_InitRng(&rng);
  41555. #endif
  41556. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41557. /* This test:
  41558. * levels: 1
  41559. * height: 5
  41560. * winternitz: 1
  41561. *
  41562. * max sigs: 2 ** (1 * 5) = 32
  41563. * signature length: 8688
  41564. */
  41565. ret = wc_LmsKey_Init(&signingKey, NULL, INVALID_DEVID);
  41566. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41567. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41568. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41569. ret = wc_LmsKey_SetParameters(&signingKey, 1, 5, 1);
  41570. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41571. ret = wc_LmsKey_SetWriteCb(&signingKey, lms_write_key_mem);
  41572. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41573. ret = wc_LmsKey_SetReadCb(&signingKey, lms_read_key_mem);
  41574. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41575. ret = wc_LmsKey_SetContext(&signingKey, (void *) priv);
  41576. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41577. ret = wc_LmsKey_MakeKey(&signingKey, &rng);
  41578. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41579. XMEMCPY(old_priv, priv, sizeof(priv));
  41580. ret = wc_LmsKey_ExportPub(&verifyKey, &signingKey);
  41581. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41582. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  41583. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41584. if (sigSz != WC_TEST_LMS_SIG_LEN) {
  41585. printf("error: got %u, expected %d\n", sigSz, WC_TEST_LMS_SIG_LEN);
  41586. return WC_TEST_RET_ENC_EC(sigSz);
  41587. }
  41588. /* 2 ** 5 should be the max number of signatures */
  41589. for (i = 0; i < 32; ++i) {
  41590. /* We should have remaining signstures. */
  41591. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  41592. if (sigsLeft == 0) {
  41593. return WC_TEST_RET_ENC_EC(sigsLeft);
  41594. }
  41595. /* Sign with key. The private key will be updated on every signature. */
  41596. ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41597. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41598. /* The updated private key should not match the old one. */
  41599. if (XMEMCMP(old_priv, priv, sizeof(priv)) == 0) {
  41600. printf("error: current priv key should not match old: %d\n", i);
  41601. return WC_TEST_RET_ENC_I(i);
  41602. }
  41603. XMEMCPY(old_priv, priv, sizeof(priv));
  41604. ret = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41605. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41606. /* Flip bits in a few places throughout the signature, stepping in multiple
  41607. * of hash size. These should all fail with -1. */
  41608. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41609. sig[j] ^= 1;
  41610. ret2 = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41611. msgSz);
  41612. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41613. /* Verify passed when it should have failed. */
  41614. return WC_TEST_RET_ENC_I(j);
  41615. }
  41616. /* Flip this spot back. */
  41617. sig[j] ^= 1;
  41618. }
  41619. }
  41620. /* This should be the last signature. */
  41621. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  41622. if (sigsLeft != 0) {
  41623. return WC_TEST_RET_ENC_EC(sigsLeft);
  41624. }
  41625. wc_LmsKey_Free(&signingKey);
  41626. wc_LmsKey_Free(&verifyKey);
  41627. wc_FreeRng(&rng);
  41628. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  41629. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41630. #endif
  41631. return ret;
  41632. }
  41633. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  41634. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
  41635. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
  41636. defined(HAVE_LIBLMS)
  41637. /* A simple LMS verify only test.
  41638. *
  41639. * Note: LMS signature sizes are a function of their parameters. This
  41640. * test has a signature of 1456 bytes:
  41641. * levels: 1
  41642. * height: 10
  41643. * winternitz: 8
  41644. * max sigs: 2 ** (1 * 10) = 1024
  41645. * signature length: 1456
  41646. * */
  41647. /* "wolfSSL LMS example message!" without null terminator. */
  41648. static byte lms_msg[28] =
  41649. {
  41650. 0x77,0x6F,0x6C,0x66,0x53,0x53,0x4C,0x20,
  41651. 0x4C,0x4D,0x53,0x20,0x65,0x78,0x61,0x6D,
  41652. 0x70,0x6C,0x65,0x20,0x6D,0x65,0x73,0x73,
  41653. 0x61,0x67,0x65,0x21
  41654. };
  41655. static const byte lms_L1H10W8_pub[HSS_MAX_PUBLIC_KEY_LEN] =
  41656. {
  41657. 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,
  41658. 0x00,0x00,0x00,0x04,0xA1,0x26,0x76,0xF8,
  41659. 0xBB,0x0B,0xC0,0x82,0x21,0x71,0x0B,0x2E,
  41660. 0x8C,0xA6,0xEF,0x12,0xED,0x41,0x0E,0x8C,
  41661. 0xAF,0x11,0x93,0x34,0x7B,0x49,0x79,0xB7,
  41662. 0xDE,0x63,0x1C,0xFE,0x1F,0xD1,0x17,0x49,
  41663. 0xCD,0x5C,0xD4,0x26,0xA0,0x53,0x26,0x1A,
  41664. 0xC5,0xB4,0x8F,0x23
  41665. };
  41666. #define LMS_L1H10W8_SIGLEN (1456)
  41667. static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
  41668. {
  41669. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  41670. 0x00,0x00,0x00,0x04,0x18,0x70,0x09,0x2E,
  41671. 0x21,0xC9,0x6A,0xC9,0x5C,0xB6,0xB0,0xAA,
  41672. 0xC3,0xED,0x6E,0x66,0x2F,0xCC,0x45,0x81,
  41673. 0xBC,0xBA,0x44,0x96,0x1C,0xBF,0x4E,0xFB,
  41674. 0x7A,0x46,0xFB,0xBE,0x9A,0x0C,0xE4,0x50,
  41675. 0x90,0xC7,0x92,0xAC,0x53,0xAE,0x53,0x76,
  41676. 0x29,0xA6,0x65,0xF1,0x09,0xED,0x1A,0x8E,
  41677. 0x03,0x2E,0x5A,0x06,0x51,0xE3,0x1E,0xE6,
  41678. 0xF6,0xFE,0x3A,0x6E,0xD1,0x92,0x31,0x1D,
  41679. 0xA1,0x6A,0x5C,0x30,0x3A,0xC7,0xFD,0x5B,
  41680. 0xFE,0x71,0x2C,0x5C,0x2F,0x5B,0x5B,0xCF,
  41681. 0xBC,0x7F,0xBF,0x6C,0xAF,0x44,0x8A,0xAE,
  41682. 0x14,0x60,0xAB,0x88,0xED,0x0E,0x4F,0xF8,
  41683. 0xC7,0x1B,0x74,0x28,0x72,0xB3,0x96,0xA6,
  41684. 0xE6,0x46,0x22,0x82,0xCF,0x1F,0x4D,0xA6,
  41685. 0xEA,0x22,0x06,0x07,0x52,0xF5,0x26,0x16,
  41686. 0x0B,0x90,0xE3,0xFF,0x64,0xA9,0xE4,0x61,
  41687. 0x1E,0x9C,0x12,0x9C,0xF6,0xD4,0x63,0x29,
  41688. 0xEA,0x02,0xF7,0x18,0x52,0x79,0x6C,0x43,
  41689. 0xDC,0xCF,0x43,0x23,0xB9,0xCC,0x4A,0x25,
  41690. 0x9D,0x10,0xAF,0xA3,0xE6,0x47,0x5A,0x1C,
  41691. 0xFE,0x68,0x89,0xAF,0x1B,0x2D,0x88,0x3E,
  41692. 0xCA,0xDC,0x70,0xEA,0xAC,0x11,0x00,0x8A,
  41693. 0x6E,0xE0,0xC7,0xD0,0xD2,0x1A,0x36,0x18,
  41694. 0x97,0xB3,0x5F,0x0E,0x75,0x48,0x28,0xF8,
  41695. 0xA8,0xF5,0x90,0xD1,0xA1,0x84,0xFB,0xA4,
  41696. 0xAD,0x50,0xBE,0xE9,0x39,0x8C,0xC5,0xA1,
  41697. 0x67,0x51,0xA1,0x8C,0xD6,0x6B,0x97,0x1F,
  41698. 0x47,0x99,0xEE,0xE0,0x70,0x01,0xC7,0x07,
  41699. 0x50,0xF3,0x5E,0x3F,0xE7,0x06,0xD6,0x8D,
  41700. 0x26,0xD6,0x5A,0x59,0x18,0x72,0x6B,0x12,
  41701. 0xD2,0xAF,0x9B,0xB4,0x2B,0xD0,0xB2,0xF2,
  41702. 0x96,0x2F,0x40,0xEA,0xBE,0xE6,0xAC,0x1F,
  41703. 0xB8,0x33,0xC2,0x76,0xDC,0x8C,0xAC,0xC1,
  41704. 0x46,0x5E,0x04,0x84,0x1B,0xC8,0xB9,0x65,
  41705. 0x8D,0xAD,0x96,0xB5,0xB1,0xF6,0x17,0x4A,
  41706. 0x19,0x87,0xE7,0xBF,0x29,0xC7,0x9B,0xB9,
  41707. 0xD6,0x11,0x2C,0x92,0x2F,0xB7,0x24,0xD5,
  41708. 0x01,0x1D,0x80,0x37,0x54,0xED,0x33,0x32,
  41709. 0xAB,0x7A,0x12,0xD4,0x02,0x1D,0x27,0x52,
  41710. 0x89,0xDB,0x32,0xBF,0x61,0xD4,0xBB,0xB4,
  41711. 0x46,0x78,0x1B,0x64,0x17,0x84,0x4B,0x8A,
  41712. 0xBA,0xC6,0xC1,0xCF,0xC7,0x5D,0x8F,0x93,
  41713. 0xC5,0x9A,0x27,0x90,0xAC,0x17,0x98,0xFF,
  41714. 0xC8,0x22,0x59,0x55,0x90,0xB2,0x29,0x39,
  41715. 0xA0,0xBE,0x00,0x23,0x55,0x6B,0xDA,0x83,
  41716. 0xD8,0x5B,0x57,0x7C,0x67,0x1B,0xC3,0x6B,
  41717. 0x6D,0xC7,0x9B,0x2B,0x9E,0xB7,0x95,0xB3,
  41718. 0xF0,0x1B,0x89,0x5A,0xD7,0x4B,0x67,0xAF,
  41719. 0xDC,0x9E,0xCF,0x7E,0x1A,0xBA,0x1B,0xB9,
  41720. 0x3B,0x7A,0xDD,0x3F,0x0D,0xEE,0x4C,0x0B,
  41721. 0xD1,0x4F,0x34,0xF2,0x93,0xF7,0x21,0x64,
  41722. 0x2C,0x07,0x00,0x15,0x4F,0xE3,0x6A,0x9F,
  41723. 0x08,0x52,0xC2,0x65,0x47,0x1F,0x34,0x64,
  41724. 0x66,0x07,0xBC,0xEA,0xAF,0x9B,0xAA,0x39,
  41725. 0x15,0x8B,0x08,0x8C,0x24,0x41,0x9B,0x46,
  41726. 0x1B,0x5B,0x91,0x11,0xC4,0xFD,0xA9,0x88,
  41727. 0x35,0x0E,0x7D,0xAF,0xFD,0xB7,0x90,0x7E,
  41728. 0xD7,0x29,0x02,0x0A,0xDC,0xC8,0x3F,0xC0,
  41729. 0xFD,0x97,0xAF,0x50,0x49,0xA6,0x5E,0x12,
  41730. 0xC1,0xCD,0xEC,0x52,0xC5,0x51,0xF2,0x80,
  41731. 0x17,0x61,0xC7,0x7E,0xBE,0xD1,0x1B,0x65,
  41732. 0xA4,0xAB,0x92,0x8D,0x89,0xB2,0xC5,0x8F,
  41733. 0xFF,0xA5,0x6F,0xFA,0x62,0x75,0xE4,0xA1,
  41734. 0xD4,0x22,0xA8,0x9E,0x40,0x04,0x27,0x1F,
  41735. 0xCC,0x81,0xBA,0x28,0x67,0xA0,0x1C,0x80,
  41736. 0xEB,0xCA,0xB0,0x61,0xA5,0x48,0xD0,0x8A,
  41737. 0x25,0xEB,0x9E,0x67,0x8C,0x8E,0x9B,0xD1,
  41738. 0xAD,0xBB,0xC3,0xEA,0xD3,0xD4,0xC5,0x12,
  41739. 0x7B,0xDD,0x00,0x57,0x7F,0xF6,0xF7,0xF6,
  41740. 0x3C,0x05,0xCF,0xFC,0x12,0xE1,0x93,0x05,
  41741. 0xE5,0x9B,0x79,0x87,0x69,0xD8,0x82,0xD9,
  41742. 0xD7,0x1D,0x41,0x73,0xE4,0x52,0x1D,0x3E,
  41743. 0xE5,0x8C,0x8D,0x34,0xE1,0x75,0xA9,0xF1,
  41744. 0x9D,0x09,0xA2,0x5B,0xEF,0xDA,0x96,0x6E,
  41745. 0x76,0x3D,0xEA,0x50,0xD9,0xCF,0x4F,0xAC,
  41746. 0xAD,0x1D,0x35,0x72,0x1B,0x88,0x8B,0xCD,
  41747. 0x8C,0x8A,0x8A,0xE0,0x96,0x04,0xD8,0xBB,
  41748. 0x28,0x43,0x16,0x77,0x60,0x98,0x63,0xF9,
  41749. 0xB9,0x71,0x46,0xB7,0xE1,0xA7,0xA9,0x84,
  41750. 0xC3,0x65,0x82,0xE1,0x1B,0x67,0x04,0x2D,
  41751. 0x55,0x6B,0xF9,0xC0,0x79,0x09,0x09,0xE7,
  41752. 0xFD,0x06,0x4D,0x09,0x9B,0x1A,0xCE,0x35,
  41753. 0xFA,0x27,0x6F,0x2F,0x01,0x65,0x0D,0xA0,
  41754. 0x97,0x59,0x11,0xF0,0x48,0xD2,0xE7,0x46,
  41755. 0xBE,0xB4,0x0A,0xA3,0xE2,0x75,0x0E,0x09,
  41756. 0x94,0xD9,0x69,0x28,0xD4,0xDA,0x64,0xBA,
  41757. 0xFE,0xA4,0xB9,0xF0,0xBA,0xEB,0xBA,0xAC,
  41758. 0xA8,0xF9,0xD3,0x82,0x4C,0x36,0x80,0xFA,
  41759. 0xE5,0xF6,0x76,0xC3,0x80,0xFA,0x90,0x29,
  41760. 0xF4,0x85,0xA4,0xC6,0x25,0x22,0x79,0x7E,
  41761. 0x39,0x1E,0x30,0xB8,0x65,0x72,0xCF,0xE1,
  41762. 0x99,0xF0,0x75,0xE8,0x09,0xB4,0x92,0x96,
  41763. 0x1B,0x68,0x50,0x88,0xF1,0x2C,0x97,0xE3,
  41764. 0x2D,0x26,0x8F,0xC5,0x30,0xCF,0x24,0xCB,
  41765. 0xB2,0x60,0x77,0xDC,0x02,0x72,0x0D,0xD9,
  41766. 0x2E,0xF2,0x52,0xEA,0x00,0xF6,0x32,0x65,
  41767. 0xA5,0xC6,0x43,0x29,0x29,0x69,0xAB,0x27,
  41768. 0x0C,0x39,0xDF,0x76,0x3E,0x93,0x95,0xB1,
  41769. 0x2C,0xA2,0x0D,0x18,0xCE,0xA0,0x97,0x10,
  41770. 0x3C,0x90,0xC0,0xEF,0x0E,0x04,0xA6,0xC8,
  41771. 0xA0,0x21,0x3C,0x0B,0x22,0x77,0x7A,0x66,
  41772. 0xA5,0x90,0x25,0xA4,0x09,0x3E,0xD5,0x27,
  41773. 0x1F,0x6C,0x99,0x85,0x5C,0xA2,0x99,0x7A,
  41774. 0x25,0xEE,0x8D,0x32,0x3D,0xD3,0xDC,0xF5,
  41775. 0x00,0x5A,0x34,0x61,0xB6,0xCD,0x4E,0xBC,
  41776. 0x26,0x36,0xFB,0x44,0x97,0x35,0xBD,0x06,
  41777. 0x7D,0x2E,0x4A,0xA2,0xDC,0x24,0xFE,0x70,
  41778. 0x0A,0xF9,0x57,0xE3,0xEE,0xAB,0xD1,0x17,
  41779. 0xF3,0x7C,0xD6,0x37,0x26,0xFA,0x83,0x9F,
  41780. 0xDD,0xB2,0xE1,0xD7,0xF9,0xC7,0x0E,0x15,
  41781. 0x01,0xA6,0x58,0x32,0x98,0x04,0x32,0xD4,
  41782. 0xDE,0xB9,0xEF,0x09,0xFA,0xE4,0x5A,0xD7,
  41783. 0xDD,0x09,0x1C,0xC9,0xAC,0xB8,0x6A,0xF5,
  41784. 0x00,0x5D,0x6B,0x95,0x12,0x8C,0x2F,0xCC,
  41785. 0xD8,0xB9,0x50,0x3A,0xEB,0x74,0x86,0xD2,
  41786. 0x3F,0xA1,0x05,0x8F,0x6E,0xEF,0xF5,0xA4,
  41787. 0xD6,0x6E,0x53,0xFA,0x9E,0xFA,0xCE,0xDB,
  41788. 0x99,0x46,0xE7,0xC5,0xDA,0x92,0x51,0x4F,
  41789. 0x22,0x07,0xF3,0xA5,0x38,0x26,0xD3,0xEC,
  41790. 0xD6,0x01,0xDD,0x31,0x3A,0x48,0x93,0xF6,
  41791. 0x69,0x4F,0xD8,0xF6,0xC2,0x91,0xA5,0x7C,
  41792. 0xDF,0x51,0x64,0xF1,0x3B,0x79,0xBC,0x0A,
  41793. 0x2C,0xDC,0x33,0x5A,0x29,0xF6,0xB2,0x09,
  41794. 0x66,0xCA,0x24,0x9F,0x1A,0x18,0xF3,0x76,
  41795. 0x4C,0x5E,0x0B,0x81,0x7F,0x29,0x84,0xD8,
  41796. 0x7A,0xA8,0xD6,0x11,0xAC,0xEC,0xD9,0x07,
  41797. 0x91,0xEC,0xB6,0x6D,0xEC,0xDB,0xBE,0x6F,
  41798. 0x9F,0xC5,0x19,0x5E,0x56,0x87,0x20,0x80,
  41799. 0x75,0xD5,0x64,0xE9,0x80,0xBF,0x2D,0xD5,
  41800. 0x94,0x9F,0x8C,0xA4,0x54,0x41,0xAB,0xB1,
  41801. 0x8E,0xAD,0x51,0xE4,0x3C,0x24,0xF7,0x1D,
  41802. 0xFE,0x02,0x48,0x7C,0x6D,0xED,0xF1,0xAC,
  41803. 0xD9,0x79,0x42,0xE5,0x3A,0xCF,0x6A,0x4C,
  41804. 0x6D,0xE2,0x13,0xD2,0x2B,0x9D,0xAB,0x1F,
  41805. 0x70,0xD3,0xC0,0x6F,0x81,0xE9,0x9A,0x86,
  41806. 0x33,0x39,0x60,0xE7,0x6A,0x00,0x1F,0x97,
  41807. 0xEB,0xE5,0x1D,0x0D,0x66,0x15,0xC9,0xA2,
  41808. 0xB1,0xC0,0xF0,0x2E,0xF4,0x07,0xA2,0x2E,
  41809. 0x49,0x92,0x95,0x13,0xA3,0x18,0x46,0x25,
  41810. 0xB9,0x3C,0xA1,0x4B,0x00,0x00,0x00,0x06,
  41811. 0xAB,0xAA,0xF9,0x3F,0x7E,0x21,0xF4,0x0E,
  41812. 0xCE,0xFD,0xE0,0x44,0xAC,0xC7,0x1A,0x30,
  41813. 0x22,0x9D,0x0A,0xD7,0x96,0x2D,0x8F,0x9A,
  41814. 0x99,0x1F,0x40,0x75,0x7F,0x62,0xF9,0xC1,
  41815. 0x81,0x7B,0x4A,0x1B,0xFA,0xD6,0x87,0xB9,
  41816. 0xEF,0x58,0x48,0xE4,0x5C,0x79,0xE5,0xB1,
  41817. 0x2C,0x59,0xA4,0x42,0xDB,0xA6,0x53,0x70,
  41818. 0x80,0x61,0x17,0xD4,0xD3,0x77,0xBD,0x53,
  41819. 0x26,0x7C,0x0E,0x0E,0xFF,0x30,0x4B,0xD0,
  41820. 0x86,0xFC,0x02,0x20,0x24,0x46,0x5B,0xF5,
  41821. 0xE3,0x99,0x73,0x85,0x60,0x00,0x36,0x47,
  41822. 0x17,0xEE,0x0C,0xD2,0x80,0x71,0x46,0x0E,
  41823. 0x2B,0xB0,0xEF,0x7F,0xFE,0x3B,0xE5,0xE1,
  41824. 0x87,0xC2,0xAF,0x1A,0x6F,0x63,0xF4,0x5A,
  41825. 0xC4,0x16,0xF7,0xAD,0x07,0x70,0x71,0x85,
  41826. 0x7D,0x3D,0x67,0x08,0xB8,0xD8,0xE2,0xF0,
  41827. 0xA1,0xAC,0xD2,0x94,0x7D,0x93,0x03,0xDD,
  41828. 0x54,0xF9,0x64,0x19,0xB3,0xED,0x24,0x22,
  41829. 0x01,0xD7,0x12,0x5E,0xC1,0x2B,0x39,0x10,
  41830. 0x13,0xE2,0x56,0x1C,0xEE,0xF4,0x2A,0x49,
  41831. 0x7B,0xFB,0x36,0x8D,0xF8,0xAF,0x60,0xDF,
  41832. 0x10,0xF0,0x72,0xA2,0xED,0xB6,0x53,0x88,
  41833. 0xA9,0x0C,0xED,0x9C,0x18,0x33,0x7D,0x65,
  41834. 0x9B,0xB2,0x9C,0x3E,0xE9,0x1E,0x43,0x51,
  41835. 0x7E,0xBE,0x01,0x95,0xF6,0x60,0x65,0xBE,
  41836. 0xD1,0xF4,0xE2,0x83,0x6B,0xCA,0x7A,0x70,
  41837. 0x41,0x83,0x72,0xC0,0x23,0x51,0x13,0x11,
  41838. 0x2D,0xF9,0xC0,0x0D,0x7D,0x73,0x76,0xA5,
  41839. 0x30,0x83,0x68,0x10,0x35,0xA2,0x18,0x22,
  41840. 0x4E,0x21,0x93,0x27,0x6A,0x19,0x28,0x83,
  41841. 0x7F,0xDD,0xDD,0xFF,0xC3,0x8A,0x64,0x00,
  41842. 0x5F,0x1C,0x0D,0xF8,0xBB,0xD7,0x15,0xB9,
  41843. 0xEF,0xE0,0x07,0x62,0x05,0x9E,0xCF,0xFC,
  41844. 0x08,0x52,0x1E,0x65,0x41,0x56,0x6A,0xEB,
  41845. 0x81,0x53,0x30,0x7B,0xF2,0xFD,0x65,0xFF,
  41846. 0xA2,0x14,0xF5,0x62,0x1E,0x24,0x48,0x47,
  41847. 0xA5,0x41,0x80,0xB4,0xC5,0xDC,0xB2,0xB4,
  41848. 0x2D,0x17,0xE7,0xBE,0x49,0x53,0x7A,0x25,
  41849. 0xC5,0x0D,0x19,0x59,0xF4,0x88,0x59,0xED,
  41850. 0x92,0x13,0xEE,0x7A,0x4F,0x12,0x98,0x4C
  41851. };
  41852. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
  41853. {
  41854. LmsKey verifyKey;
  41855. unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
  41856. word32 pub_len = sizeof(pub_raw);
  41857. word32 sigSz = 0;
  41858. word32 msgSz = sizeof(lms_msg);
  41859. word32 pubSz = 0;
  41860. int levels = 0;
  41861. int height = 0;
  41862. int winternitz = 0;
  41863. int ret = WC_TEST_RET_ENC_NC;
  41864. int ret2 = WC_TEST_RET_ENC_NC;
  41865. int j = 0;
  41866. int n_diff = 0;
  41867. WOLFSSL_ENTER("lms_test_verify_only");
  41868. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  41869. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41870. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41871. ret = wc_LmsKey_SetParameters(&verifyKey, 1, 10, 8);
  41872. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41873. ret = wc_LmsKey_ImportPubRaw(&verifyKey, lms_L1H10W8_pub,
  41874. HSS_MAX_PUBLIC_KEY_LEN);
  41875. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41876. /* Verify parameters, pub length, and sig length are correct. */
  41877. ret = wc_LmsKey_GetParameters(&verifyKey, &levels, &height, &winternitz);
  41878. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41879. if (levels != 1 || height != 10 || winternitz != 8) {
  41880. printf("error: invalid LMS parameters: L%d-H%d-W%d\n", levels, height,
  41881. winternitz);
  41882. return WC_TEST_RET_ENC_NC;
  41883. }
  41884. ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
  41885. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41886. if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
  41887. printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
  41888. return WC_TEST_RET_ENC_EC(pubSz);
  41889. }
  41890. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  41891. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41892. if (sigSz != LMS_L1H10W8_SIGLEN) {
  41893. printf("error: got %u, expected %d\n", sigSz, LMS_L1H10W8_SIGLEN);
  41894. return WC_TEST_RET_ENC_EC(sigSz);
  41895. }
  41896. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  41897. (byte *) lms_msg, msgSz);
  41898. if (ret != 0) {
  41899. printf("error: wc_LmsKey_Verify returned %d\n", ret);
  41900. return WC_TEST_RET_ENC_EC(ret);
  41901. }
  41902. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  41903. ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  41904. if (ret != 0) {
  41905. printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
  41906. return WC_TEST_RET_ENC_EC(ret);
  41907. }
  41908. if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
  41909. printf("error: LMS pub len %u, expected %d\n", pub_len,
  41910. HSS_MAX_PUBLIC_KEY_LEN);
  41911. return WC_TEST_RET_ENC_EC(pub_len);
  41912. }
  41913. n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
  41914. if (n_diff != 0) {
  41915. printf("error: exported and imported pub raw do not match: %d\n",
  41916. n_diff);
  41917. return WC_TEST_RET_ENC_EC(n_diff);
  41918. }
  41919. /* Flip bits in message. This should fail. */
  41920. lms_msg[msgSz / 2] ^= 1;
  41921. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  41922. (byte *) lms_msg, msgSz);
  41923. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41924. printf("error: wc_LmsKey_Verify returned %d, expected -1\n", ret2);
  41925. return WC_TEST_RET_ENC_EC(ret);
  41926. }
  41927. /* Flip it back. This should pass again. */
  41928. lms_msg[msgSz / 2] ^= 1;
  41929. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  41930. (byte *) lms_msg, msgSz);
  41931. if (ret != 0) {
  41932. printf("error: wc_LmsKey_Verify returned %d, expected 0\n", ret);
  41933. return WC_TEST_RET_ENC_EC(ret);
  41934. }
  41935. /* Flip bits in a few places throughout the signature, stepping in multiple
  41936. * of hash size. These should all fail with -1. */
  41937. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41938. lms_L1H10W8_sig[j] ^= 1;
  41939. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig,
  41940. LMS_L1H10W8_SIGLEN,
  41941. (byte *) lms_msg, msgSz);
  41942. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41943. /* Verify passed when it should have failed. */
  41944. return WC_TEST_RET_ENC_I(j);
  41945. }
  41946. /* Flip this spot back. */
  41947. lms_L1H10W8_sig[j] ^= 1;
  41948. }
  41949. wc_LmsKey_Free(&verifyKey);
  41950. return ret;
  41951. }
  41952. #endif
  41953. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK) */
  41954. static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --
  41955. * see print_fiducials() below.
  41956. */
  41957. #ifdef WOLFCRYPT_HAVE_ECCSI
  41958. static wc_test_ret_t eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk,
  41959. ecc_point* pvt)
  41960. {
  41961. wc_test_ret_t ret;
  41962. byte id[1] = { 0x00 };
  41963. int valid;
  41964. word32 sz;
  41965. byte data[256];
  41966. byte hash[WC_MAX_DIGEST_SIZE];
  41967. byte hashSz;
  41968. byte sig[257];
  41969. word32 sigSz;
  41970. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  41971. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41972. return WC_TEST_RET_ENC_EC(ret);
  41973. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  41974. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41975. return WC_TEST_RET_ENC_EC(ret);
  41976. ret = wc_InitEccsiKey(NULL, NULL, INVALID_DEVID);
  41977. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41978. return WC_TEST_RET_ENC_EC(ret);
  41979. ret = wc_InitEccsiKey(NULL, HEAP_HINT, INVALID_DEVID);
  41980. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41981. return WC_TEST_RET_ENC_EC(ret);
  41982. wc_FreeEccsiKey(NULL);
  41983. /* Create a valid key. */
  41984. ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID);
  41985. if (ret != 0)
  41986. return WC_TEST_RET_ENC_EC(ret);
  41987. ret = wc_MakeEccsiKey(NULL, NULL);
  41988. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41989. return WC_TEST_RET_ENC_EC(ret);
  41990. ret = wc_MakeEccsiKey(key, NULL);
  41991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41992. return WC_TEST_RET_ENC_EC(ret);
  41993. ret = wc_MakeEccsiKey(NULL, rng);
  41994. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41995. return WC_TEST_RET_ENC_EC(ret);
  41996. ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL,
  41997. NULL);
  41998. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  41999. return WC_TEST_RET_ENC_EC(ret);
  42000. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL);
  42001. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42002. return WC_TEST_RET_ENC_EC(ret);
  42003. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt);
  42004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42005. return WC_TEST_RET_ENC_EC(ret);
  42006. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt);
  42007. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42008. return WC_TEST_RET_ENC_EC(ret);
  42009. ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42010. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42011. return WC_TEST_RET_ENC_EC(ret);
  42012. ret = wc_MakeEccsiPair(NULL, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42013. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42014. return WC_TEST_RET_ENC_EC(ret);
  42015. /* No key set */
  42016. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42017. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42018. return WC_TEST_RET_ENC_EC(ret);
  42019. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL,
  42020. NULL);
  42021. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42022. return WC_TEST_RET_ENC_EC(ret);
  42023. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42024. NULL);
  42025. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42026. return WC_TEST_RET_ENC_EC(ret);
  42027. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL,
  42028. &valid);
  42029. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42030. return WC_TEST_RET_ENC_EC(ret);
  42031. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt,
  42032. &valid);
  42033. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42034. return WC_TEST_RET_ENC_EC(ret);
  42035. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt,
  42036. &valid);
  42037. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42038. return WC_TEST_RET_ENC_EC(ret);
  42039. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42040. &valid);
  42041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42042. return WC_TEST_RET_ENC_EC(ret);
  42043. /* No key set */
  42044. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42045. &valid);
  42046. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42047. return WC_TEST_RET_ENC_EC(ret);
  42048. ret = wc_ValidateEccsiPvt(NULL, NULL, NULL);
  42049. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42050. return WC_TEST_RET_ENC_EC(ret);
  42051. ret = wc_ValidateEccsiPvt(key, NULL, NULL);
  42052. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42053. return WC_TEST_RET_ENC_EC(ret);
  42054. ret = wc_ValidateEccsiPvt(NULL, pvt, NULL);
  42055. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42056. return WC_TEST_RET_ENC_EC(ret);
  42057. ret = wc_ValidateEccsiPvt(NULL, NULL, &valid);
  42058. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42059. return WC_TEST_RET_ENC_EC(ret);
  42060. ret = wc_ValidateEccsiPvt(key, pvt, NULL);
  42061. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42062. return WC_TEST_RET_ENC_EC(ret);
  42063. ret = wc_ValidateEccsiPvt(key, NULL, &valid);
  42064. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42065. return WC_TEST_RET_ENC_EC(ret);
  42066. ret = wc_ValidateEccsiPvt(NULL, pvt, &valid);
  42067. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42068. return WC_TEST_RET_ENC_EC(ret);
  42069. ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL);
  42070. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42071. return WC_TEST_RET_ENC_EC(ret);
  42072. ret = wc_EncodeEccsiPair(key, ssk, pvt, data, NULL);
  42073. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42074. return WC_TEST_RET_ENC_EC(ret);
  42075. ret = wc_EncodeEccsiPair(key, ssk, NULL, data, &sz);
  42076. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42077. return WC_TEST_RET_ENC_EC(ret);
  42078. ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz);
  42079. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42080. return WC_TEST_RET_ENC_EC(ret);
  42081. ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz);
  42082. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42083. return WC_TEST_RET_ENC_EC(ret);
  42084. /* No key created so no curve information. */
  42085. ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz);
  42086. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42087. return WC_TEST_RET_ENC_EC(ret);
  42088. ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL);
  42089. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42090. return WC_TEST_RET_ENC_EC(ret);
  42091. ret = wc_EncodeEccsiSsk(key, ssk, data, NULL);
  42092. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42093. return WC_TEST_RET_ENC_EC(ret);
  42094. ret = wc_EncodeEccsiSsk(key, NULL, data, &sz);
  42095. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42096. return WC_TEST_RET_ENC_EC(ret);
  42097. ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz);
  42098. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42099. return WC_TEST_RET_ENC_EC(ret);
  42100. ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1);
  42101. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42102. return WC_TEST_RET_ENC_EC(ret);
  42103. ret = wc_EncodeEccsiPvt(key, pvt, data, NULL, 1);
  42104. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42105. return WC_TEST_RET_ENC_EC(ret);
  42106. ret = wc_EncodeEccsiPvt(key, NULL, data, &sz, 1);
  42107. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42108. return WC_TEST_RET_ENC_EC(ret);
  42109. ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1);
  42110. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42111. return WC_TEST_RET_ENC_EC(ret);
  42112. ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL);
  42113. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42114. return WC_TEST_RET_ENC_EC(ret);
  42115. ret = wc_DecodeEccsiPair(key, data, 0, ssk, NULL);
  42116. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42117. return WC_TEST_RET_ENC_EC(ret);
  42118. ret = wc_DecodeEccsiPair(key, data, 0, NULL, pvt);
  42119. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42120. return WC_TEST_RET_ENC_EC(ret);
  42121. ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt);
  42122. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42123. return WC_TEST_RET_ENC_EC(ret);
  42124. ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt);
  42125. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42126. return WC_TEST_RET_ENC_EC(ret);
  42127. ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL);
  42128. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42129. return WC_TEST_RET_ENC_EC(ret);
  42130. ret = wc_DecodeEccsiSsk(key, data, 0, NULL);
  42131. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42132. return WC_TEST_RET_ENC_EC(ret);
  42133. ret = wc_DecodeEccsiSsk(key, NULL, 0, ssk);
  42134. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42135. return WC_TEST_RET_ENC_EC(ret);
  42136. ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk);
  42137. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42138. return WC_TEST_RET_ENC_EC(ret);
  42139. ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL);
  42140. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42141. return WC_TEST_RET_ENC_EC(ret);
  42142. ret = wc_DecodeEccsiPvt(key, data, 0, NULL);
  42143. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42144. return WC_TEST_RET_ENC_EC(ret);
  42145. ret = wc_DecodeEccsiPvt(key, NULL, 0, pvt);
  42146. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42147. return WC_TEST_RET_ENC_EC(ret);
  42148. ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt);
  42149. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42150. return WC_TEST_RET_ENC_EC(ret);
  42151. ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL);
  42152. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42153. return WC_TEST_RET_ENC_EC(ret);
  42154. ret = wc_DecodeEccsiPvtFromSig(key, data, 0, NULL);
  42155. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42156. return WC_TEST_RET_ENC_EC(ret);
  42157. ret = wc_DecodeEccsiPvtFromSig(key, NULL, 0, pvt);
  42158. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42159. return WC_TEST_RET_ENC_EC(ret);
  42160. ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt);
  42161. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42162. return WC_TEST_RET_ENC_EC(ret);
  42163. ret = wc_ExportEccsiKey(NULL, data, NULL);
  42164. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42165. return WC_TEST_RET_ENC_EC(ret);
  42166. ret = wc_ExportEccsiKey(key, data, NULL);
  42167. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42168. return WC_TEST_RET_ENC_EC(ret);
  42169. ret = wc_ExportEccsiKey(NULL, data, &sz);
  42170. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42171. return WC_TEST_RET_ENC_EC(ret);
  42172. /* No key to export */
  42173. ret = wc_ExportEccsiKey(key, NULL, &sz);
  42174. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42175. return WC_TEST_RET_ENC_EC(ret);
  42176. ret = wc_ImportEccsiKey(NULL, NULL, 0);
  42177. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42178. return WC_TEST_RET_ENC_EC(ret);
  42179. ret = wc_ImportEccsiKey(key, NULL, 0);
  42180. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42181. return WC_TEST_RET_ENC_EC(ret);
  42182. ret = wc_ImportEccsiKey(NULL, data, 0);
  42183. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42184. return WC_TEST_RET_ENC_EC(ret);
  42185. ret = wc_ExportEccsiPrivateKey(NULL, data, NULL);
  42186. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42187. return WC_TEST_RET_ENC_EC(ret);
  42188. ret = wc_ExportEccsiPrivateKey(key, data, NULL);
  42189. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42190. return WC_TEST_RET_ENC_EC(ret);
  42191. ret = wc_ExportEccsiPrivateKey(NULL, data, &sz);
  42192. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42193. return WC_TEST_RET_ENC_EC(ret);
  42194. /* No key to export */
  42195. ret = wc_ExportEccsiPrivateKey(key, NULL, &sz);
  42196. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42197. return WC_TEST_RET_ENC_EC(ret);
  42198. ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0);
  42199. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42200. return WC_TEST_RET_ENC_EC(ret);
  42201. ret = wc_ImportEccsiPrivateKey(key, NULL, 0);
  42202. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42203. return WC_TEST_RET_ENC_EC(ret);
  42204. ret = wc_ImportEccsiPrivateKey(NULL, data, 0);
  42205. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42206. return WC_TEST_RET_ENC_EC(ret);
  42207. ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1);
  42208. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42209. return WC_TEST_RET_ENC_EC(ret);
  42210. ret = wc_ExportEccsiPublicKey(key, data, NULL, 1);
  42211. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42212. return WC_TEST_RET_ENC_EC(ret);
  42213. ret = wc_ExportEccsiPublicKey(NULL, data, &sz, 1);
  42214. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42215. return WC_TEST_RET_ENC_EC(ret);
  42216. /* No key to export */
  42217. ret = wc_ExportEccsiPublicKey(key, data, &sz, 1);
  42218. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42219. return WC_TEST_RET_ENC_EC(ret);
  42220. ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1);
  42221. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42222. return WC_TEST_RET_ENC_EC(ret);
  42223. ret = wc_ImportEccsiPublicKey(key, NULL, 0, 1);
  42224. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42225. return WC_TEST_RET_ENC_EC(ret);
  42226. ret = wc_ImportEccsiPublicKey(NULL, data, 0, 1);
  42227. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42228. return WC_TEST_RET_ENC_EC(ret);
  42229. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL);
  42230. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42231. return WC_TEST_RET_ENC_EC(ret);
  42232. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, NULL);
  42233. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42234. return WC_TEST_RET_ENC_EC(ret);
  42235. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, NULL, &hashSz);
  42236. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42237. return WC_TEST_RET_ENC_EC(ret);
  42238. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, NULL, hash, &hashSz);
  42239. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42240. return WC_TEST_RET_ENC_EC(ret);
  42241. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, NULL, 1, pvt, hash,
  42242. &hashSz);
  42243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42244. return WC_TEST_RET_ENC_EC(ret);
  42245. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  42246. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42247. return WC_TEST_RET_ENC_EC(ret);
  42248. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  42249. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42250. return WC_TEST_RET_ENC_EC(ret);
  42251. ret = wc_SetEccsiHash(NULL, NULL, 1);
  42252. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42253. return WC_TEST_RET_ENC_EC(ret);
  42254. ret = wc_SetEccsiHash(key, NULL, 1);
  42255. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42256. return WC_TEST_RET_ENC_EC(ret);
  42257. ret = wc_SetEccsiHash(NULL, hash, 1);
  42258. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42259. return WC_TEST_RET_ENC_EC(ret);
  42260. ret = wc_SetEccsiPair(NULL, NULL, NULL);
  42261. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42262. return WC_TEST_RET_ENC_EC(ret);
  42263. ret = wc_SetEccsiPair(key, NULL, NULL);
  42264. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42265. return WC_TEST_RET_ENC_EC(ret);
  42266. ret = wc_SetEccsiPair(NULL, ssk, NULL);
  42267. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42268. return WC_TEST_RET_ENC_EC(ret);
  42269. ret = wc_SetEccsiPair(NULL, NULL, pvt);
  42270. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42271. return WC_TEST_RET_ENC_EC(ret);
  42272. ret = wc_SetEccsiPair(key, ssk, NULL);
  42273. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42274. return WC_TEST_RET_ENC_EC(ret);
  42275. ret = wc_SetEccsiPair(key, NULL, pvt);
  42276. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42277. return WC_TEST_RET_ENC_EC(ret);
  42278. ret = wc_SetEccsiPair(NULL, ssk, pvt);
  42279. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42280. return WC_TEST_RET_ENC_EC(ret);
  42281. ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL);
  42282. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42283. return WC_TEST_RET_ENC_EC(ret);
  42284. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, sig, NULL);
  42285. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42286. return WC_TEST_RET_ENC_EC(ret);
  42287. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, NULL, 0, sig,
  42288. &sigSz);
  42289. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42290. return WC_TEST_RET_ENC_EC(ret);
  42291. ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig,
  42292. &sigSz);
  42293. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42294. return WC_TEST_RET_ENC_EC(ret);
  42295. ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig,
  42296. &sigSz);
  42297. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42298. return WC_TEST_RET_ENC_EC(ret);
  42299. /* Key not set. */
  42300. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  42301. &sigSz);
  42302. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42303. return WC_TEST_RET_ENC_EC(ret);
  42304. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  42305. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42306. return WC_TEST_RET_ENC_EC(ret);
  42307. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  42308. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42309. return WC_TEST_RET_ENC_EC(ret);
  42310. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, NULL, 0, NULL);
  42311. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42312. return WC_TEST_RET_ENC_EC(ret);
  42313. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, NULL);
  42314. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42315. return WC_TEST_RET_ENC_EC(ret);
  42316. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0,
  42317. &valid);
  42318. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42319. return WC_TEST_RET_ENC_EC(ret);
  42320. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL);
  42321. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42322. return WC_TEST_RET_ENC_EC(ret);
  42323. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, NULL, 0,
  42324. &valid);
  42325. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42326. return WC_TEST_RET_ENC_EC(ret);
  42327. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0,
  42328. &valid);
  42329. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42330. return WC_TEST_RET_ENC_EC(ret);
  42331. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  42332. &valid);
  42333. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42334. return WC_TEST_RET_ENC_EC(ret);
  42335. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  42336. &valid);
  42337. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42338. return WC_TEST_RET_ENC_EC(ret);
  42339. ret = wc_SetEccsiPair(key, ssk, pvt);
  42340. if (ret != 0)
  42341. return WC_TEST_RET_ENC_EC(ret);
  42342. /* Identity hash not set. */
  42343. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  42344. &sigSz);
  42345. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42346. return WC_TEST_RET_ENC_EC(ret);
  42347. wc_FreeEccsiKey(key);
  42348. return 0;
  42349. }
  42350. /* RFC 6507: Appendix A */
  42351. static wc_test_ret_t eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt)
  42352. {
  42353. wc_test_ret_t ret;
  42354. int verified;
  42355. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00 };
  42356. word32 msgSz = sizeof(msg);
  42357. byte hash[WC_SHA256_DIGEST_SIZE];
  42358. byte hashSz = WC_SHA256_DIGEST_SIZE;
  42359. static const byte id[] = {
  42360. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  42361. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  42362. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  42363. 0x33, 0x00
  42364. };
  42365. word32 idSz = sizeof(id);
  42366. static const byte sig[] = {
  42367. 0x26, 0x9D, 0x4C, 0x8F, 0xDE, 0xB6, 0x6A, 0x74,
  42368. 0xE4, 0xEF, 0x8C, 0x0D, 0x5D, 0xCC, 0x59, 0x7D,
  42369. 0xDF, 0xE6, 0x02, 0x9C, 0x2A, 0xFF, 0xC4, 0x93,
  42370. 0x60, 0x08, 0xCD, 0x2C, 0xC1, 0x04, 0x5D, 0x81,
  42371. 0xE0, 0x9B, 0x52, 0x8D, 0x0E, 0xF8, 0xD6, 0xDF,
  42372. 0x1A, 0xA3, 0xEC, 0xBF, 0x80, 0x11, 0x0C, 0xFC,
  42373. 0xEC, 0x9F, 0xC6, 0x82, 0x52, 0xCE, 0xBB, 0x67,
  42374. 0x9F, 0x41, 0x34, 0x84, 0x69, 0x40, 0xCC, 0xFD,
  42375. 0x04,
  42376. 0x75, 0x8A, 0x14, 0x27, 0x79, 0xBE, 0x89, 0xE8,
  42377. 0x29, 0xE7, 0x19, 0x84, 0xCB, 0x40, 0xEF, 0x75,
  42378. 0x8C, 0xC4, 0xAD, 0x77, 0x5F, 0xC5, 0xB9, 0xA3,
  42379. 0xE1, 0xC8, 0xED, 0x52, 0xF6, 0xFA, 0x36, 0xD9,
  42380. 0xA7, 0x9D, 0x24, 0x76, 0x92, 0xF4, 0xED, 0xA3,
  42381. 0xA6, 0xBD, 0xAB, 0x77, 0xD6, 0xAA, 0x64, 0x74,
  42382. 0xA4, 0x64, 0xAE, 0x49, 0x34, 0x66, 0x3C, 0x52,
  42383. 0x65, 0xBA, 0x70, 0x18, 0xBA, 0x09, 0x1F, 0x79
  42384. };
  42385. word32 sigSz = sizeof(sig);
  42386. static const byte pubData[] = {
  42387. 0x50, 0xD4, 0x67, 0x0B, 0xDE, 0x75, 0x24, 0x4F,
  42388. 0x28, 0xD2, 0x83, 0x8A, 0x0D, 0x25, 0x55, 0x8A,
  42389. 0x7A, 0x72, 0x68, 0x6D, 0x45, 0x22, 0xD4, 0xC8,
  42390. 0x27, 0x3F, 0xB6, 0x44, 0x2A, 0xEB, 0xFA, 0x93,
  42391. 0xDB, 0xDD, 0x37, 0x55, 0x1A, 0xFD, 0x26, 0x3B,
  42392. 0x5D, 0xFD, 0x61, 0x7F, 0x39, 0x60, 0xC6, 0x5A,
  42393. 0x8C, 0x29, 0x88, 0x50, 0xFF, 0x99, 0xF2, 0x03,
  42394. 0x66, 0xDC, 0xE7, 0xD4, 0x36, 0x72, 0x17, 0xF4
  42395. };
  42396. static const byte expHash[] = {
  42397. 0x49, 0x0f, 0x3f, 0xeb, 0xbc, 0x1c, 0x90, 0x2f,
  42398. 0x62, 0x89, 0x72, 0x3d, 0x7f, 0x8c, 0xbf, 0x79,
  42399. 0xdb, 0x88, 0x93, 0x08, 0x49, 0xd1, 0x9f, 0x38,
  42400. 0xf0, 0x29, 0x5b, 0x5c, 0x27, 0x6c, 0x14, 0xd1
  42401. };
  42402. ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0);
  42403. if (ret != 0)
  42404. return WC_TEST_RET_ENC_EC(ret);
  42405. ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt);
  42406. if (ret != 0)
  42407. return WC_TEST_RET_ENC_EC(ret);
  42408. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash,
  42409. &hashSz);
  42410. if (ret != 0)
  42411. return WC_TEST_RET_ENC_EC(ret);
  42412. if (hashSz != sizeof(expHash))
  42413. return WC_TEST_RET_ENC_NC;
  42414. if (XMEMCMP(hash, expHash, hashSz) != 0)
  42415. return WC_TEST_RET_ENC_NC;
  42416. ret = wc_SetEccsiHash(key, hash, hashSz);
  42417. if (ret != 0)
  42418. return WC_TEST_RET_ENC_EC(ret);
  42419. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42420. &verified);
  42421. if (ret != 0)
  42422. return WC_TEST_RET_ENC_EC(ret);
  42423. if (!verified)
  42424. return WC_TEST_RET_ENC_NC;
  42425. return 0;
  42426. }
  42427. static wc_test_ret_t eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt)
  42428. {
  42429. wc_test_ret_t ret;
  42430. byte data[32 * 3];
  42431. word32 sz;
  42432. ecc_point* decPvt = NULL;
  42433. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42434. mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT,
  42435. DYNAMIC_TYPE_TMP_BUFFER);
  42436. if (decSsk == NULL)
  42437. return WC_TEST_RET_ENC_ERRNO;
  42438. #else
  42439. mp_int decSsk[1];
  42440. #endif
  42441. ret = mp_init(decSsk);
  42442. if (ret != 0)
  42443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42444. decPvt = wc_ecc_new_point();
  42445. if (decPvt == NULL)
  42446. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  42447. ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz);
  42448. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42450. if (sz != 32 * 3)
  42451. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42452. ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz);
  42453. if (ret != 0)
  42454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42455. if (sz != 32* 3)
  42456. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42457. ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt);
  42458. if (ret != 0)
  42459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42460. ret = mp_cmp(ssk, decSsk);
  42461. if (ret != MP_EQ)
  42462. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42463. ret = wc_ecc_cmp_point(pvt, decPvt);
  42464. if (ret != MP_EQ)
  42465. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42466. ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz);
  42467. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42468. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42469. if (sz != 32)
  42470. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42471. ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz);
  42472. if (ret != 0)
  42473. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42474. if (sz != 32)
  42475. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42476. ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk);
  42477. if (ret != 0)
  42478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42479. ret = mp_cmp(ssk, decSsk);
  42480. if (ret != MP_EQ)
  42481. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42482. ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1);
  42483. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42484. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42485. if (sz != 32 * 2)
  42486. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42487. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1);
  42488. if (ret != 0)
  42489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42490. if (sz != 32 * 2)
  42491. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42492. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  42493. if (ret != 0)
  42494. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42495. ret = wc_ecc_cmp_point(pvt, decPvt);
  42496. if (ret != MP_EQ)
  42497. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42498. sz = sizeof(data);
  42499. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0);
  42500. if (ret != 0)
  42501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42502. if (sz != 32 * 2 + 1)
  42503. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42504. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  42505. if (ret != 0)
  42506. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42507. ret = wc_ecc_cmp_point(pvt, decPvt);
  42508. if (ret != MP_EQ)
  42509. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42510. wc_ecc_del_point(decPvt);
  42511. out:
  42512. mp_free(decSsk);
  42513. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42514. XFREE(decSsk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42515. #endif
  42516. return ret;
  42517. }
  42518. static wc_test_ret_t eccsi_imp_exp_key_test(EccsiKey* priv)
  42519. {
  42520. wc_test_ret_t ret;
  42521. byte data[32 * 3];
  42522. byte out[32 * 3];
  42523. word32 sz;
  42524. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  42525. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42526. return WC_TEST_RET_ENC_EC(ret);
  42527. if (sz != 32 * 3)
  42528. return WC_TEST_RET_ENC_NC;
  42529. ret = wc_ExportEccsiKey(priv, data, &sz);
  42530. if (ret != 0)
  42531. return WC_TEST_RET_ENC_EC(ret);
  42532. ret = wc_ImportEccsiKey(priv, data, sz);
  42533. if (ret != 0)
  42534. return WC_TEST_RET_ENC_EC(ret);
  42535. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  42536. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42537. return WC_TEST_RET_ENC_EC(ret);
  42538. if (sz != 32 * 3)
  42539. return WC_TEST_RET_ENC_NC;
  42540. ret = wc_ExportEccsiKey(priv, out, &sz);
  42541. if (ret != 0)
  42542. return WC_TEST_RET_ENC_EC(ret);
  42543. if (sz != 32 * 3)
  42544. return WC_TEST_RET_ENC_NC;
  42545. if (XMEMCMP(data, out, sz) != 0)
  42546. return WC_TEST_RET_ENC_NC;
  42547. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  42548. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42549. return WC_TEST_RET_ENC_EC(ret);
  42550. if (sz != 32)
  42551. return WC_TEST_RET_ENC_NC;
  42552. ret = wc_ExportEccsiPrivateKey(priv, data, &sz);
  42553. if (ret != 0)
  42554. return WC_TEST_RET_ENC_EC(ret);
  42555. ret = wc_ImportEccsiPrivateKey(priv, data, sz);
  42556. if (ret != 0)
  42557. return WC_TEST_RET_ENC_EC(ret);
  42558. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  42559. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42560. return WC_TEST_RET_ENC_EC(ret);
  42561. if (sz != 32)
  42562. return WC_TEST_RET_ENC_NC;
  42563. ret = wc_ExportEccsiPrivateKey(priv, out, &sz);
  42564. if (ret != 0)
  42565. return WC_TEST_RET_ENC_EC(ret);
  42566. if (sz != 32)
  42567. return WC_TEST_RET_ENC_NC;
  42568. if (XMEMCMP(data, out, sz) != 0)
  42569. return WC_TEST_RET_ENC_NC;
  42570. return 0;
  42571. }
  42572. static wc_test_ret_t eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2)
  42573. {
  42574. wc_test_ret_t ret;
  42575. byte data[32 * 2 + 1];
  42576. byte pubData[32 * 2 + 1];
  42577. word32 sz;
  42578. ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1);
  42579. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42580. return WC_TEST_RET_ENC_EC(ret);
  42581. if (sz != 32 * 2)
  42582. return WC_TEST_RET_ENC_NC;
  42583. ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1);
  42584. if (ret != 0)
  42585. return WC_TEST_RET_ENC_EC(ret);
  42586. ret = wc_ImportEccsiPublicKey(key2, data, sz, 1);
  42587. if (ret != 0)
  42588. return WC_TEST_RET_ENC_EC(ret);
  42589. sz = sizeof(pubData);
  42590. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1);
  42591. if (ret != 0)
  42592. return WC_TEST_RET_ENC_EC(ret);
  42593. if (sz != 32 * 2)
  42594. return WC_TEST_RET_ENC_NC;
  42595. if (XMEMCMP(data, pubData, sz) != 0)
  42596. return WC_TEST_RET_ENC_NC;
  42597. sz = sizeof(pubData);
  42598. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0);
  42599. if (ret != 0)
  42600. return WC_TEST_RET_ENC_EC(ret);
  42601. if (sz != 32 * 2 + 1)
  42602. return WC_TEST_RET_ENC_NC;
  42603. if (pubData[0] != 0x04)
  42604. return WC_TEST_RET_ENC_NC;
  42605. if (XMEMCMP(pubData + 1, data, sz - 1) != 0)
  42606. return WC_TEST_RET_ENC_NC;
  42607. ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0);
  42608. if (ret != 0)
  42609. return WC_TEST_RET_ENC_EC(ret);
  42610. return 0;
  42611. }
  42612. static wc_test_ret_t eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  42613. mp_int* ssk, ecc_point* pvt)
  42614. {
  42615. wc_test_ret_t ret;
  42616. char mail[] = "test@wolfssl.com";
  42617. byte* id = (byte*)mail;
  42618. word32 idSz = (word32) XSTRLEN(mail);
  42619. int valid;
  42620. ret = wc_MakeEccsiKey(priv, rng);
  42621. if (ret != 0)
  42622. return WC_TEST_RET_ENC_EC(ret);
  42623. ret = eccsi_imp_exp_key_test(priv);
  42624. if (ret < 0)
  42625. return ret;
  42626. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  42627. if (ret < 0)
  42628. return ret;
  42629. ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt);
  42630. if (ret != 0)
  42631. return WC_TEST_RET_ENC_EC(ret);
  42632. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  42633. &valid);
  42634. if (ret != 0)
  42635. return WC_TEST_RET_ENC_EC(ret);
  42636. if (!valid)
  42637. return WC_TEST_RET_ENC_NC;
  42638. ret = eccsi_enc_dec_pair_test(priv, ssk, pvt);
  42639. if (ret != 0)
  42640. return ret;
  42641. return 0;
  42642. }
  42643. static wc_test_ret_t eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  42644. mp_int* ssk, ecc_point* pvt)
  42645. {
  42646. wc_test_ret_t ret;
  42647. byte hashPriv[WC_MAX_DIGEST_SIZE];
  42648. byte hashPub[WC_MAX_DIGEST_SIZE];
  42649. byte hashSz;
  42650. byte sig[144];
  42651. word32 sigSz;
  42652. int verified, valid;
  42653. char mail[] = "test@wolfssl.com";
  42654. byte* id = (byte*)mail;
  42655. word32 idSz = (word32) XSTRLEN(mail);
  42656. byte msg[] = { 0x00 };
  42657. word32 msgSz = sizeof(msg);
  42658. #ifdef WOLFSSL_SHA384
  42659. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv,
  42660. &hashSz);
  42661. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42662. return WC_TEST_RET_ENC_EC(ret);
  42663. #endif
  42664. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv,
  42665. &hashSz);
  42666. if (ret != 0)
  42667. return WC_TEST_RET_ENC_EC(ret);
  42668. if (hashSz != 32)
  42669. return WC_TEST_RET_ENC_NC;
  42670. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub,
  42671. &hashSz);
  42672. if (ret != 0)
  42673. return WC_TEST_RET_ENC_EC(ret);
  42674. if (hashSz != 32)
  42675. return WC_TEST_RET_ENC_NC;
  42676. if (XMEMCMP(hashPriv, hashPub, hashSz) != 0)
  42677. return WC_TEST_RET_ENC_NC;
  42678. ret = wc_SetEccsiHash(priv, hashPriv, hashSz);
  42679. if (ret != 0)
  42680. return WC_TEST_RET_ENC_EC(ret);
  42681. ret = wc_SetEccsiPair(priv, ssk, pvt);
  42682. if (ret != 0)
  42683. return WC_TEST_RET_ENC_EC(ret);
  42684. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL,
  42685. &sigSz);
  42686. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42687. return WC_TEST_RET_ENC_EC(ret);
  42688. if (sigSz != 129)
  42689. return WC_TEST_RET_ENC_NC;
  42690. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig,
  42691. &sigSz);
  42692. if (ret != 0)
  42693. return WC_TEST_RET_ENC_EC(ret);
  42694. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  42695. if (ret != 0)
  42696. return WC_TEST_RET_ENC_EC(ret);
  42697. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42698. &verified);
  42699. if (ret != 0)
  42700. return WC_TEST_RET_ENC_EC(ret);
  42701. if (!verified)
  42702. return WC_TEST_RET_ENC_NC;
  42703. /* Check that changing HS results in verification failure. */
  42704. hashPub[0] ^= 0x80;
  42705. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  42706. if (ret != 0)
  42707. return WC_TEST_RET_ENC_EC(ret);
  42708. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42709. &verified);
  42710. if (ret != 0)
  42711. return WC_TEST_RET_ENC_EC(ret);
  42712. if (verified)
  42713. return WC_TEST_RET_ENC_NC;
  42714. hashPub[0] ^= 0x80;
  42715. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  42716. if (ret != 0)
  42717. return WC_TEST_RET_ENC_EC(ret);
  42718. /* Check that changing msg results in verification failure. */
  42719. msg[0] ^= 0x80;
  42720. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42721. &verified);
  42722. if (ret != 0)
  42723. return WC_TEST_RET_ENC_EC(ret);
  42724. if (verified)
  42725. return WC_TEST_RET_ENC_NC;
  42726. msg[0] ^= 0x80;
  42727. /* Check that changing signature results in verification failure. */
  42728. sig[0] ^= 0x80;
  42729. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42730. &verified);
  42731. if (ret != 0)
  42732. return WC_TEST_RET_ENC_EC(ret);
  42733. if (verified)
  42734. return WC_TEST_RET_ENC_NC;
  42735. sig[0] ^= 0x80;
  42736. /* Check that key state hasn't been invalidated. */
  42737. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42738. &verified);
  42739. if (ret != 0)
  42740. return WC_TEST_RET_ENC_EC(ret);
  42741. if (!verified)
  42742. return WC_TEST_RET_ENC_NC;
  42743. /* Check that verifying with the private key works. */
  42744. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42745. &verified);
  42746. if (ret != 0)
  42747. return WC_TEST_RET_ENC_EC(ret);
  42748. if (!verified)
  42749. return WC_TEST_RET_ENC_NC;
  42750. /* Check that the KPAK is converted from montgomery form. */
  42751. ret = eccsi_imp_exp_key_test(priv);
  42752. if (ret != 0)
  42753. return ret;
  42754. /* Check that KPAK can converted to Montgomery form again. */
  42755. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42756. &verified);
  42757. if (ret != 0)
  42758. return WC_TEST_RET_ENC_EC(ret);
  42759. if (!verified)
  42760. return WC_TEST_RET_ENC_NC;
  42761. /* Check that the KPAK is converted from montgomery form. */
  42762. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  42763. &valid);
  42764. if (ret != 0)
  42765. return WC_TEST_RET_ENC_EC(ret);
  42766. if (!valid)
  42767. return WC_TEST_RET_ENC_NC;
  42768. /* Check that KPAK can converted to Montgomery form again. */
  42769. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42770. &verified);
  42771. if (ret != 0)
  42772. return WC_TEST_RET_ENC_EC(ret);
  42773. if (!verified)
  42774. return WC_TEST_RET_ENC_NC;
  42775. /* Check that the KPAK is converted from montgomery form. */
  42776. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  42777. if (ret != 0)
  42778. return ret;
  42779. return 0;
  42780. }
  42781. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void)
  42782. {
  42783. wc_test_ret_t ret = 0;
  42784. WC_RNG rng;
  42785. int rng_inited = 0;
  42786. EccsiKey* priv = NULL;
  42787. EccsiKey* pub = NULL;
  42788. mp_int* ssk = NULL;
  42789. ecc_point* pvt = NULL;
  42790. WOLFSSL_ENTER("eccsi_test");
  42791. priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  42792. DYNAMIC_TYPE_TMP_BUFFER);
  42793. if (priv == NULL)
  42794. ret = WC_TEST_RET_ENC_NC;
  42795. else
  42796. XMEMSET(priv, 0, sizeof(*priv));
  42797. if (ret == 0) {
  42798. pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  42799. DYNAMIC_TYPE_TMP_BUFFER);
  42800. if (pub == NULL)
  42801. ret = WC_TEST_RET_ENC_NC;
  42802. else
  42803. XMEMSET(pub, 0, sizeof(*pub));
  42804. }
  42805. if (ret == 0) {
  42806. ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT,
  42807. DYNAMIC_TYPE_TMP_BUFFER);
  42808. if (ssk == NULL)
  42809. ret = WC_TEST_RET_ENC_NC;
  42810. else
  42811. XMEMSET(ssk, 0, sizeof(*ssk));
  42812. }
  42813. if (ret == 0) {
  42814. #ifndef HAVE_FIPS
  42815. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  42816. #else
  42817. ret = wc_InitRng(&rng);
  42818. #endif
  42819. if (ret != 0)
  42820. ret = WC_TEST_RET_ENC_EC(ret);
  42821. else
  42822. rng_inited = 1;
  42823. }
  42824. if (ret == 0) {
  42825. pvt = wc_ecc_new_point();
  42826. if (pvt == NULL)
  42827. ret = WC_TEST_RET_ENC_NC;
  42828. }
  42829. if (ret == 0) {
  42830. ret = mp_init(ssk);
  42831. if (ret != 0)
  42832. ret = WC_TEST_RET_ENC_EC(ret);
  42833. }
  42834. if (ret == 0) {
  42835. ret = eccsi_api_test(&rng, priv, ssk, pvt);
  42836. }
  42837. if (ret == 0) {
  42838. ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID);
  42839. if (ret != 0)
  42840. ret = WC_TEST_RET_ENC_EC(ret);
  42841. }
  42842. if (ret == 0) {
  42843. ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID);
  42844. if (ret != 0)
  42845. ret = WC_TEST_RET_ENC_EC(ret);
  42846. }
  42847. if (ret == 0) {
  42848. ret = eccsi_kat_verify_test(pub, pvt);
  42849. }
  42850. if (ret == 0) {
  42851. ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt);
  42852. }
  42853. if (ret == 0) {
  42854. ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt);
  42855. }
  42856. if (pvt != NULL)
  42857. wc_ecc_del_point(pvt);
  42858. if (rng_inited)
  42859. wc_FreeRng(&rng);
  42860. if (ssk != NULL) {
  42861. mp_free(ssk);
  42862. XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42863. }
  42864. if (pub != NULL) {
  42865. wc_FreeEccsiKey(pub);
  42866. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42867. }
  42868. if (priv != NULL) {
  42869. wc_FreeEccsiKey(priv);
  42870. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42871. }
  42872. return ret;
  42873. }
  42874. #endif /* WOLFCRYPT_HAVE_ECCSI */
  42875. #ifdef WOLFCRYPT_HAVE_SAKKE
  42876. static wc_test_ret_t sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk)
  42877. {
  42878. wc_test_ret_t ret;
  42879. byte id[1] = { 0x00 };
  42880. int valid;
  42881. byte data[256];
  42882. word32 sz;
  42883. byte auth[257];
  42884. word16 authSz;
  42885. byte ssv[256];
  42886. word16 ssvSz;
  42887. word32 len;
  42888. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  42889. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42890. return WC_TEST_RET_ENC_EC(ret);
  42891. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  42892. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42893. return WC_TEST_RET_ENC_EC(ret);
  42894. wc_FreeSakkeKey(NULL);
  42895. XMEMSET(key, 0, sizeof(*key));
  42896. wc_FreeSakkeKey(key);
  42897. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  42898. if (ret != 0)
  42899. return WC_TEST_RET_ENC_EC(ret);
  42900. ret = wc_MakeSakkeKey(NULL, NULL);
  42901. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42902. return WC_TEST_RET_ENC_EC(ret);
  42903. ret = wc_MakeSakkeKey(key, NULL);
  42904. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42905. return WC_TEST_RET_ENC_EC(ret);
  42906. ret = wc_MakeSakkeKey(NULL, rng);
  42907. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42908. return WC_TEST_RET_ENC_EC(ret);
  42909. ret = wc_MakeSakkePublicKey(NULL, NULL);
  42910. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42911. return WC_TEST_RET_ENC_EC(ret);
  42912. ret = wc_MakeSakkePublicKey(key, NULL);
  42913. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42914. return WC_TEST_RET_ENC_EC(ret);
  42915. ret = wc_MakeSakkePublicKey(NULL, rsk);
  42916. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42917. return WC_TEST_RET_ENC_EC(ret);
  42918. ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL);
  42919. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42920. return WC_TEST_RET_ENC_EC(ret);
  42921. ret = wc_MakeSakkeRsk(key, id, 1, NULL);
  42922. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42923. return WC_TEST_RET_ENC_EC(ret);
  42924. ret = wc_MakeSakkeRsk(key, NULL, 1, rsk);
  42925. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42926. return WC_TEST_RET_ENC_EC(ret);
  42927. ret = wc_MakeSakkeRsk(NULL, id, 1, rsk);
  42928. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42929. return WC_TEST_RET_ENC_EC(ret);
  42930. ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL);
  42931. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42932. return WC_TEST_RET_ENC_EC(ret);
  42933. ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL);
  42934. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42935. return WC_TEST_RET_ENC_EC(ret);
  42936. ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid);
  42937. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42938. return WC_TEST_RET_ENC_EC(ret);
  42939. ret = wc_ExportSakkeKey(NULL, NULL, NULL);
  42940. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42941. return WC_TEST_RET_ENC_EC(ret);
  42942. ret = wc_ExportSakkeKey(key, data, NULL);
  42943. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42944. return WC_TEST_RET_ENC_EC(ret);
  42945. ret = wc_ExportSakkeKey(NULL, data, &sz);
  42946. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42947. return WC_TEST_RET_ENC_EC(ret);
  42948. ret = wc_ImportSakkeKey(NULL, NULL, 1);
  42949. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42950. return WC_TEST_RET_ENC_EC(ret);
  42951. ret = wc_ImportSakkeKey(key, NULL, 1);
  42952. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42953. return WC_TEST_RET_ENC_EC(ret);
  42954. ret = wc_ImportSakkeKey(NULL, data, 1);
  42955. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42956. return WC_TEST_RET_ENC_EC(ret);
  42957. ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL);
  42958. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42959. return WC_TEST_RET_ENC_EC(ret);
  42960. ret = wc_ExportSakkePrivateKey(key, data, NULL);
  42961. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42962. return WC_TEST_RET_ENC_EC(ret);
  42963. ret = wc_ExportSakkePrivateKey(NULL, data, &sz);
  42964. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42965. return WC_TEST_RET_ENC_EC(ret);
  42966. ret = wc_ImportSakkePrivateKey(NULL, NULL, 1);
  42967. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42968. return WC_TEST_RET_ENC_EC(ret);
  42969. ret = wc_ImportSakkePrivateKey(key, NULL, 1);
  42970. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42971. return WC_TEST_RET_ENC_EC(ret);
  42972. ret = wc_ImportSakkePrivateKey(NULL, data, 1);
  42973. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42974. return WC_TEST_RET_ENC_EC(ret);
  42975. sz = sizeof(data);
  42976. ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1);
  42977. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42978. return WC_TEST_RET_ENC_EC(ret);
  42979. ret = wc_EncodeSakkeRsk(key, rsk, data, NULL, 1);
  42980. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42981. return WC_TEST_RET_ENC_EC(ret);
  42982. ret = wc_EncodeSakkeRsk(key, NULL, data, &sz, 1);
  42983. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42984. return WC_TEST_RET_ENC_EC(ret);
  42985. ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1);
  42986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42987. return WC_TEST_RET_ENC_EC(ret);
  42988. ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL);
  42989. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42990. return WC_TEST_RET_ENC_EC(ret);
  42991. ret = wc_DecodeSakkeRsk(key, data, sz, NULL);
  42992. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42993. return WC_TEST_RET_ENC_EC(ret);
  42994. ret = wc_DecodeSakkeRsk(key, NULL, sz, rsk);
  42995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42996. return WC_TEST_RET_ENC_EC(ret);
  42997. ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk);
  42998. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42999. return WC_TEST_RET_ENC_EC(ret);
  43000. ret = wc_ImportSakkeRsk(NULL, NULL, sz);
  43001. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43002. return WC_TEST_RET_ENC_EC(ret);
  43003. ret = wc_ImportSakkeRsk(key, NULL, sz);
  43004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43005. return WC_TEST_RET_ENC_EC(ret);
  43006. ret = wc_ImportSakkeRsk(NULL, data, sz);
  43007. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43008. return WC_TEST_RET_ENC_EC(ret);
  43009. ret = wc_ImportSakkeRsk(key, data, 1);
  43010. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43011. return WC_TEST_RET_ENC_EC(ret);
  43012. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL);
  43013. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43014. return WC_TEST_RET_ENC_EC(ret);
  43015. ret = wc_GenerateSakkeRskTable(key, NULL, data, NULL);
  43016. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43017. return WC_TEST_RET_ENC_EC(ret);
  43018. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, NULL);
  43019. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43020. return WC_TEST_RET_ENC_EC(ret);
  43021. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, &len);
  43022. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43023. return WC_TEST_RET_ENC_EC(ret);
  43024. ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL);
  43025. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43026. return WC_TEST_RET_ENC_EC(ret);
  43027. ret = wc_GenerateSakkeRskTable(key, NULL, data, &len);
  43028. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43029. return WC_TEST_RET_ENC_EC(ret);
  43030. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len);
  43031. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43032. return WC_TEST_RET_ENC_EC(ret);
  43033. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43034. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43035. return WC_TEST_RET_ENC_EC(ret);
  43036. len--;
  43037. ret = wc_GenerateSakkeRskTable(key, rsk, data, &len);
  43038. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43039. return WC_TEST_RET_ENC_EC(ret);
  43040. ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1);
  43041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43042. return WC_TEST_RET_ENC_EC(ret);
  43043. ret = wc_ExportSakkePublicKey(key, data, NULL, 1);
  43044. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43045. return WC_TEST_RET_ENC_EC(ret);
  43046. ret = wc_ExportSakkePublicKey(NULL, data, &sz, 1);
  43047. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43048. return WC_TEST_RET_ENC_EC(ret);
  43049. ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1);
  43050. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43051. return WC_TEST_RET_ENC_EC(ret);
  43052. ret = wc_ImportSakkePublicKey(key, NULL, sz, 1);
  43053. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43054. return WC_TEST_RET_ENC_EC(ret);
  43055. ret = wc_ImportSakkePublicKey(NULL, data, sz, 1);
  43056. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43057. return WC_TEST_RET_ENC_EC(ret);
  43058. ret = wc_GetSakkeAuthSize(NULL, NULL);
  43059. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43060. return WC_TEST_RET_ENC_EC(ret);
  43061. ret = wc_GetSakkeAuthSize(key, NULL);
  43062. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43063. return WC_TEST_RET_ENC_EC(ret);
  43064. ret = wc_GetSakkeAuthSize(NULL, &authSz);
  43065. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43066. return WC_TEST_RET_ENC_EC(ret);
  43067. ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1);
  43068. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43069. return WC_TEST_RET_ENC_EC(ret);
  43070. ret = wc_MakeSakkePointI(key, NULL, SAKKE_ID_MAX_SIZE + 1);
  43071. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43072. return WC_TEST_RET_ENC_EC(ret);
  43073. ret = wc_MakeSakkePointI(NULL, id, 1);
  43074. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43075. return WC_TEST_RET_ENC_EC(ret);
  43076. ret = wc_MakeSakkePointI(NULL, NULL, 1);
  43077. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43078. return WC_TEST_RET_ENC_EC(ret);
  43079. ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1);
  43080. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43081. return WC_TEST_RET_ENC_EC(ret);
  43082. ret = wc_MakeSakkePointI(key, NULL, 1);
  43083. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43084. return WC_TEST_RET_ENC_EC(ret);
  43085. ret = wc_MakeSakkePointI(NULL, id, 1);
  43086. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43087. return WC_TEST_RET_ENC_EC(ret);
  43088. ret = wc_GenerateSakkePointITable(NULL, data, NULL);
  43089. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43090. return WC_TEST_RET_ENC_EC(ret);
  43091. ret = wc_GenerateSakkePointITable(key, data, NULL);
  43092. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43093. return WC_TEST_RET_ENC_EC(ret);
  43094. ret = wc_GenerateSakkePointITable(NULL, data, &len);
  43095. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43096. return WC_TEST_RET_ENC_EC(ret);
  43097. ret = wc_GenerateSakkePointITable(key, NULL, &len);
  43098. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43099. return WC_TEST_RET_ENC_EC(ret);
  43100. len--;
  43101. ret = wc_GenerateSakkePointITable(key, data, &len);
  43102. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43103. return WC_TEST_RET_ENC_EC(ret);
  43104. ret = wc_SetSakkePointITable(NULL, NULL, 1);
  43105. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43106. return WC_TEST_RET_ENC_EC(ret);
  43107. ret = wc_SetSakkePointITable(key, NULL, 1);
  43108. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43109. return WC_TEST_RET_ENC_EC(ret);
  43110. ret = wc_SetSakkePointITable(NULL, data, 1);
  43111. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43112. return WC_TEST_RET_ENC_EC(ret);
  43113. ret = wc_SetSakkePointITable(key, data, 1);
  43114. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43115. return WC_TEST_RET_ENC_EC(ret);
  43116. ret = wc_ClearSakkePointITable(NULL);
  43117. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43118. return WC_TEST_RET_ENC_EC(ret);
  43119. ret = wc_GetSakkePointI(NULL, data, NULL);
  43120. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43121. return WC_TEST_RET_ENC_EC(ret);
  43122. ret = wc_GetSakkePointI(key, data, NULL);
  43123. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43124. return WC_TEST_RET_ENC_EC(ret);
  43125. ret = wc_GetSakkePointI(NULL, data, &sz);
  43126. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43127. return WC_TEST_RET_ENC_EC(ret);
  43128. sz = 1;
  43129. ret = wc_GetSakkePointI(key, data, &sz);
  43130. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43131. return WC_TEST_RET_ENC_EC(ret);
  43132. sz = 256;
  43133. ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz);
  43134. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43135. return WC_TEST_RET_ENC_EC(ret);
  43136. ret = wc_SetSakkePointI(key, NULL, 1, NULL, sz);
  43137. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43138. return WC_TEST_RET_ENC_EC(ret);
  43139. ret = wc_SetSakkePointI(NULL, id, 1, NULL, sz);
  43140. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43141. return WC_TEST_RET_ENC_EC(ret);
  43142. ret = wc_SetSakkePointI(NULL, NULL, 1, data, sz);
  43143. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43144. return WC_TEST_RET_ENC_EC(ret);
  43145. ret = wc_SetSakkePointI(key, id, 1, NULL, sz);
  43146. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43147. return WC_TEST_RET_ENC_EC(ret);
  43148. ret = wc_SetSakkePointI(key, NULL, 1, data, sz);
  43149. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43150. return WC_TEST_RET_ENC_EC(ret);
  43151. ret = wc_SetSakkePointI(NULL, id, 1, data, sz);
  43152. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43153. return WC_TEST_RET_ENC_EC(ret);
  43154. ret = wc_SetSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz);
  43155. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43156. return WC_TEST_RET_ENC_EC(ret);
  43157. ret = wc_SetSakkePointI(key, id, 1, data, sz - 1);
  43158. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43159. return WC_TEST_RET_ENC_EC(ret);
  43160. ret = wc_SetSakkeIdentity(NULL, NULL, 1);
  43161. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43162. return WC_TEST_RET_ENC_EC(ret);
  43163. ret = wc_SetSakkeIdentity(key, NULL, 1);
  43164. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43165. return WC_TEST_RET_ENC_EC(ret);
  43166. ret = wc_SetSakkeIdentity(NULL, id, 1);
  43167. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43168. return WC_TEST_RET_ENC_EC(ret);
  43169. ssvSz = sizeof(ssv);
  43170. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43171. auth, NULL);
  43172. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43173. return WC_TEST_RET_ENC_EC(ret);
  43174. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43175. auth, NULL);
  43176. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43177. return WC_TEST_RET_ENC_EC(ret);
  43178. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43179. auth, NULL);
  43180. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43181. return WC_TEST_RET_ENC_EC(ret);
  43182. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43183. auth, &authSz);
  43184. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43185. return WC_TEST_RET_ENC_EC(ret);
  43186. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43187. auth, NULL);
  43188. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43189. return WC_TEST_RET_ENC_EC(ret);
  43190. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43191. auth, &authSz);
  43192. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43193. return WC_TEST_RET_ENC_EC(ret);
  43194. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43195. auth, &authSz);
  43196. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43197. return WC_TEST_RET_ENC_EC(ret);
  43198. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43199. auth, &authSz);
  43200. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43201. return WC_TEST_RET_ENC_EC(ret);
  43202. ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL);
  43203. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43204. return WC_TEST_RET_ENC_EC(ret);
  43205. ret = wc_GenerateSakkeSSV(key, rng, data, NULL);
  43206. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43207. return WC_TEST_RET_ENC_EC(ret);
  43208. ret = wc_GenerateSakkeSSV(key, NULL, data, &ssvSz);
  43209. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43210. return WC_TEST_RET_ENC_EC(ret);
  43211. ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz);
  43212. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43213. return WC_TEST_RET_ENC_EC(ret);
  43214. ret = wc_SetSakkeRsk(NULL, NULL, data, 1);
  43215. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43216. return WC_TEST_RET_ENC_EC(ret);
  43217. ret = wc_SetSakkeRsk(key, NULL, data, 1);
  43218. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43219. return WC_TEST_RET_ENC_EC(ret);
  43220. ret = wc_SetSakkeRsk(NULL, rsk, data, 1);
  43221. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43222. return WC_TEST_RET_ENC_EC(ret);
  43223. ssvSz = sizeof(ssv);
  43224. authSz = sizeof(auth);
  43225. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43226. authSz);
  43227. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43228. return WC_TEST_RET_ENC_EC(ret);
  43229. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43230. authSz);
  43231. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43232. return WC_TEST_RET_ENC_EC(ret);
  43233. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  43234. authSz);
  43235. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43236. return WC_TEST_RET_ENC_EC(ret);
  43237. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  43238. authSz);
  43239. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43240. return WC_TEST_RET_ENC_EC(ret);
  43241. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  43242. authSz);
  43243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43244. return WC_TEST_RET_ENC_EC(ret);
  43245. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  43246. authSz);
  43247. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43248. return WC_TEST_RET_ENC_EC(ret);
  43249. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43250. authSz);
  43251. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43252. return WC_TEST_RET_ENC_EC(ret);
  43253. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43254. authSz);
  43255. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43256. return WC_TEST_RET_ENC_EC(ret);
  43257. ret = wc_SetSakkeIdentity(key, id, 1);
  43258. if (ret != 0)
  43259. return WC_TEST_RET_ENC_EC(ret);
  43260. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43261. authSz);
  43262. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43263. return WC_TEST_RET_ENC_EC(ret);
  43264. ret = wc_SetSakkeIdentity(key, id, 0);
  43265. if (ret != 0)
  43266. return WC_TEST_RET_ENC_EC(ret);
  43267. ret = wc_SetSakkeRsk(key, rsk, data, 1);
  43268. if (ret != 0)
  43269. return WC_TEST_RET_ENC_EC(ret);
  43270. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43271. authSz);
  43272. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43273. return WC_TEST_RET_ENC_EC(ret);
  43274. wc_FreeSakkeKey(key);
  43275. return 0;
  43276. }
  43277. static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
  43278. {
  43279. WOLFSSL_SMALL_STACK_STATIC const byte pubData[] = {
  43280. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  43281. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  43282. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  43283. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  43284. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  43285. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  43286. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  43287. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  43288. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  43289. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  43290. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  43291. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  43292. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  43293. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  43294. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  43295. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  43296. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  43297. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  43298. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  43299. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  43300. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  43301. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  43302. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  43303. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  43304. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  43305. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  43306. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  43307. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  43308. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  43309. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  43310. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  43311. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  43312. };
  43313. WOLFSSL_SMALL_STACK_STATIC const byte rskData[] = {
  43314. 0x93, 0xAF, 0x67, 0xE5, 0x00, 0x7B, 0xA6, 0xE6,
  43315. 0xA8, 0x0D, 0xA7, 0x93, 0xDA, 0x30, 0x0F, 0xA4,
  43316. 0xB5, 0x2D, 0x0A, 0x74, 0xE2, 0x5E, 0x6E, 0x7B,
  43317. 0x2B, 0x3D, 0x6E, 0xE9, 0xD1, 0x8A, 0x9B, 0x5C,
  43318. 0x50, 0x23, 0x59, 0x7B, 0xD8, 0x2D, 0x80, 0x62,
  43319. 0xD3, 0x40, 0x19, 0x56, 0x3B, 0xA1, 0xD2, 0x5C,
  43320. 0x0D, 0xC5, 0x6B, 0x7B, 0x97, 0x9D, 0x74, 0xAA,
  43321. 0x50, 0xF2, 0x9F, 0xBF, 0x11, 0xCC, 0x2C, 0x93,
  43322. 0xF5, 0xDF, 0xCA, 0x61, 0x5E, 0x60, 0x92, 0x79,
  43323. 0xF6, 0x17, 0x5C, 0xEA, 0xDB, 0x00, 0xB5, 0x8C,
  43324. 0x6B, 0xEE, 0x1E, 0x7A, 0x2A, 0x47, 0xC4, 0xF0,
  43325. 0xC4, 0x56, 0xF0, 0x52, 0x59, 0xA6, 0xFA, 0x94,
  43326. 0xA6, 0x34, 0xA4, 0x0D, 0xAE, 0x1D, 0xF5, 0x93,
  43327. 0xD4, 0xFE, 0xCF, 0x68, 0x8D, 0x5F, 0xC6, 0x78,
  43328. 0xBE, 0x7E, 0xFC, 0x6D, 0xF3, 0xD6, 0x83, 0x53,
  43329. 0x25, 0xB8, 0x3B, 0x2C, 0x6E, 0x69, 0x03, 0x6B,
  43330. 0x15, 0x5F, 0x0A, 0x27, 0x24, 0x10, 0x94, 0xB0,
  43331. 0x4B, 0xFB, 0x0B, 0xDF, 0xAC, 0x6C, 0x67, 0x0A,
  43332. 0x65, 0xC3, 0x25, 0xD3, 0x9A, 0x06, 0x9F, 0x03,
  43333. 0x65, 0x9D, 0x44, 0xCA, 0x27, 0xD3, 0xBE, 0x8D,
  43334. 0xF3, 0x11, 0x17, 0x2B, 0x55, 0x41, 0x60, 0x18,
  43335. 0x1C, 0xBE, 0x94, 0xA2, 0xA7, 0x83, 0x32, 0x0C,
  43336. 0xED, 0x59, 0x0B, 0xC4, 0x26, 0x44, 0x70, 0x2C,
  43337. 0xF3, 0x71, 0x27, 0x1E, 0x49, 0x6B, 0xF2, 0x0F,
  43338. 0x58, 0x8B, 0x78, 0xA1, 0xBC, 0x01, 0xEC, 0xBB,
  43339. 0x65, 0x59, 0x93, 0x4B, 0xDD, 0x2F, 0xB6, 0x5D,
  43340. 0x28, 0x84, 0x31, 0x8A, 0x33, 0xD1, 0xA4, 0x2A,
  43341. 0xDF, 0x5E, 0x33, 0xCC, 0x58, 0x00, 0x28, 0x0B,
  43342. 0x28, 0x35, 0x64, 0x97, 0xF8, 0x71, 0x35, 0xBA,
  43343. 0xB9, 0x61, 0x2A, 0x17, 0x26, 0x04, 0x24, 0x40,
  43344. 0x9A, 0xC1, 0x5F, 0xEE, 0x99, 0x6B, 0x74, 0x4C,
  43345. 0x33, 0x21, 0x51, 0x23, 0x5D, 0xEC, 0xB0, 0xF5
  43346. };
  43347. WOLFSSL_SMALL_STACK_STATIC const byte id[] = {
  43348. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43349. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43350. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43351. 0x33, 0x00
  43352. };
  43353. WOLFSSL_SMALL_STACK_STATIC const byte ssv[] = {
  43354. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  43355. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  43356. };
  43357. WOLFSSL_SMALL_STACK_STATIC const byte auth[] = {
  43358. 0x04,
  43359. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  43360. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  43361. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  43362. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  43363. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  43364. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  43365. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  43366. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  43367. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  43368. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  43369. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  43370. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  43371. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  43372. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  43373. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  43374. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  43375. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  43376. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  43377. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  43378. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  43379. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  43380. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  43381. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  43382. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  43383. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  43384. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  43385. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  43386. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  43387. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  43388. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  43389. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  43390. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  43391. };
  43392. WOLFSSL_SMALL_STACK_STATIC const byte encSsv[] = {
  43393. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  43394. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  43395. };
  43396. wc_test_ret_t ret;
  43397. int valid;
  43398. byte pubKey[sizeof(pubData) + 1];
  43399. word32 sz = sizeof(pubKey);
  43400. byte tmpSsv[sizeof(encSsv)];
  43401. byte* iTable = NULL;
  43402. word32 iTableLen;
  43403. byte* table = NULL;
  43404. word32 len;
  43405. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  43406. if (ret != 0)
  43407. return WC_TEST_RET_ENC_EC(ret);
  43408. ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk);
  43409. if (ret != 0)
  43410. return WC_TEST_RET_ENC_EC(ret);
  43411. ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid);
  43412. if (ret != 0)
  43413. return WC_TEST_RET_ENC_EC(ret);
  43414. if (valid != 1)
  43415. return WC_TEST_RET_ENC_NC;
  43416. ret = wc_SetSakkeRsk(key, rsk, NULL, 0);
  43417. if (ret != 0)
  43418. return WC_TEST_RET_ENC_EC(ret);
  43419. ret = wc_SetSakkeIdentity(key, id, sizeof(id));
  43420. if (ret != 0)
  43421. return WC_TEST_RET_ENC_EC(ret);
  43422. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  43423. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  43424. auth, sizeof(auth));
  43425. if (ret != 0)
  43426. return WC_TEST_RET_ENC_EC(ret);
  43427. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  43428. return WC_TEST_RET_ENC_NC;
  43429. ret = wc_MakeSakkePointI(key, id, sizeof(id));
  43430. if (ret != 0)
  43431. return WC_TEST_RET_ENC_EC(ret);
  43432. iTableLen = 0;
  43433. ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen);
  43434. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43435. return WC_TEST_RET_ENC_EC(ret);
  43436. if (iTableLen != 0) {
  43437. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43438. if (iTable == NULL)
  43439. return WC_TEST_RET_ENC_ERRNO;
  43440. ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
  43441. if (ret != 0)
  43442. return WC_TEST_RET_ENC_EC(ret);
  43443. }
  43444. len = 0;
  43445. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43446. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43447. return WC_TEST_RET_ENC_EC(ret);
  43448. if (len > 0) {
  43449. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43450. if (table == NULL)
  43451. return WC_TEST_RET_ENC_ERRNO;
  43452. ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
  43453. if (ret != 0)
  43454. return WC_TEST_RET_ENC_EC(ret);
  43455. }
  43456. ret = wc_SetSakkeRsk(key, rsk, table, len);
  43457. if (ret != 0)
  43458. return WC_TEST_RET_ENC_EC(ret);
  43459. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  43460. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  43461. auth, sizeof(auth));
  43462. if (ret != 0)
  43463. return WC_TEST_RET_ENC_EC(ret);
  43464. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  43465. return WC_TEST_RET_ENC_NC;
  43466. /* Don't reference table that is about to be freed. */
  43467. ret = wc_ClearSakkePointITable(key);
  43468. if (ret != 0)
  43469. return WC_TEST_RET_ENC_EC(ret);
  43470. /* Dispose of tables */
  43471. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43472. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43473. /* Make sure the key public key is exportable - convert to Montgomery form
  43474. * in Validation.
  43475. */
  43476. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1);
  43477. if (ret != 0)
  43478. return WC_TEST_RET_ENC_EC(ret);
  43479. if (sz != sizeof(pubData))
  43480. return WC_TEST_RET_ENC_NC;
  43481. if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0)
  43482. return WC_TEST_RET_ENC_NC;
  43483. sz = sizeof(pubData) + 1;
  43484. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0);
  43485. if (ret != 0)
  43486. return WC_TEST_RET_ENC_EC(ret);
  43487. if (sz != sizeof(pubData) + 1)
  43488. return WC_TEST_RET_ENC_NC;
  43489. if (pubKey[0] != 0x04)
  43490. return WC_TEST_RET_ENC_NC;
  43491. if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0)
  43492. return WC_TEST_RET_ENC_NC;
  43493. return 0;
  43494. }
  43495. static wc_test_ret_t sakke_kat_encapsulate_test(SakkeKey* key)
  43496. {
  43497. static const byte pubData[] = {
  43498. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  43499. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  43500. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  43501. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  43502. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  43503. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  43504. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  43505. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  43506. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  43507. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  43508. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  43509. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  43510. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  43511. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  43512. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  43513. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  43514. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  43515. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  43516. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  43517. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  43518. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  43519. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  43520. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  43521. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  43522. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  43523. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  43524. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  43525. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  43526. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  43527. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  43528. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  43529. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  43530. };
  43531. static const byte id[] = {
  43532. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43533. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43534. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43535. 0x33, 0x00
  43536. };
  43537. static const word32 idSz = sizeof(id);
  43538. byte ssv[] = {
  43539. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  43540. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  43541. };
  43542. static const word16 ssvSz = sizeof(ssv);
  43543. static const byte expAuth[] = {
  43544. 0x04,
  43545. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  43546. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  43547. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  43548. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  43549. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  43550. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  43551. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  43552. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  43553. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  43554. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  43555. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  43556. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  43557. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  43558. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  43559. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  43560. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  43561. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  43562. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  43563. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  43564. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  43565. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  43566. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  43567. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  43568. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  43569. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  43570. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  43571. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  43572. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  43573. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  43574. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  43575. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  43576. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  43577. };
  43578. static const byte encSsv[] = {
  43579. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  43580. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  43581. };
  43582. wc_test_ret_t ret;
  43583. byte auth[257];
  43584. word16 authSz = sizeof(auth);
  43585. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  43586. if (ret != 0)
  43587. return WC_TEST_RET_ENC_EC(ret);
  43588. ret = wc_SetSakkeIdentity(key, id, idSz);
  43589. if (ret != 0)
  43590. return WC_TEST_RET_ENC_EC(ret);
  43591. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43592. auth, &authSz);
  43593. if (ret != 0)
  43594. return WC_TEST_RET_ENC_EC(ret);
  43595. if (authSz != 257)
  43596. return WC_TEST_RET_ENC_NC;
  43597. if (XMEMCMP(ssv, encSsv, ssvSz) != 0)
  43598. return WC_TEST_RET_ENC_NC;
  43599. if (XMEMCMP(auth, expAuth, authSz) != 0)
  43600. return WC_TEST_RET_ENC_NC;
  43601. return 0;
  43602. }
  43603. static wc_test_ret_t sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key,
  43604. WC_RNG* rng, ecc_point* rsk)
  43605. {
  43606. wc_test_ret_t ret;
  43607. byte data[440];
  43608. byte pubData[257];
  43609. word32 sz;
  43610. char mail[] = "test@wolfssl.com";
  43611. byte* id = (byte*)mail;
  43612. word32 idSz = (word32)XSTRLEN(mail);
  43613. int valid;
  43614. ecc_point* pubKey = rsk;
  43615. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43616. if (ret != 0)
  43617. return WC_TEST_RET_ENC_EC(ret);
  43618. ret = wc_MakeSakkeKey(priv, rng);
  43619. if (ret != 0)
  43620. return WC_TEST_RET_ENC_EC(ret);
  43621. ret = wc_ExportSakkeKey(priv, NULL, &sz);
  43622. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43623. return WC_TEST_RET_ENC_EC(ret);
  43624. if (sz != 384)
  43625. return WC_TEST_RET_ENC_NC;
  43626. sz--;
  43627. ret = wc_ExportSakkeKey(priv, data, &sz);
  43628. if (ret == 0)
  43629. return WC_TEST_RET_ENC_NC;
  43630. sz++;
  43631. ret = wc_ExportSakkeKey(priv, data, &sz);
  43632. if (ret != 0)
  43633. return WC_TEST_RET_ENC_EC(ret);
  43634. if (sz != 384)
  43635. return WC_TEST_RET_ENC_NC;
  43636. ret = wc_ImportSakkeKey(key, data, sz - 1);
  43637. if (ret == 0)
  43638. return WC_TEST_RET_ENC_NC;
  43639. ret = wc_ImportSakkeKey(key, data, sz);
  43640. if (ret != 0)
  43641. return WC_TEST_RET_ENC_EC(ret);
  43642. wc_FreeSakkeKey(key);
  43643. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43644. if (ret != 0)
  43645. return WC_TEST_RET_ENC_EC(ret);
  43646. ret = wc_ExportSakkePrivateKey(priv, NULL, &sz);
  43647. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43648. return WC_TEST_RET_ENC_EC(ret);
  43649. if (sz != 128)
  43650. return WC_TEST_RET_ENC_NC;
  43651. sz--;
  43652. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  43653. if (ret == 0)
  43654. return WC_TEST_RET_ENC_NC;
  43655. sz++;
  43656. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  43657. if (ret != 0)
  43658. return WC_TEST_RET_ENC_EC(ret);
  43659. if (sz != 128)
  43660. return WC_TEST_RET_ENC_NC;
  43661. ret = wc_ImportSakkePrivateKey(key, data, sz - 1);
  43662. if (ret == 0)
  43663. return WC_TEST_RET_ENC_NC;
  43664. ret = wc_ImportSakkePrivateKey(key, data, sz);
  43665. if (ret != 0)
  43666. return WC_TEST_RET_ENC_EC(ret);
  43667. ret = wc_MakeSakkePublicKey(key, pubKey);
  43668. if (ret != 0)
  43669. return WC_TEST_RET_ENC_EC(ret);
  43670. ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1);
  43671. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43672. return WC_TEST_RET_ENC_EC(ret);
  43673. if (sz != 256)
  43674. return WC_TEST_RET_ENC_NC;
  43675. sz--;
  43676. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  43677. if (ret == 0)
  43678. return WC_TEST_RET_ENC_NC;
  43679. sz++;
  43680. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  43681. if (ret != 0)
  43682. return WC_TEST_RET_ENC_EC(ret);
  43683. if (sz != 256)
  43684. return WC_TEST_RET_ENC_NC;
  43685. ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1);
  43686. if (ret == 0)
  43687. return WC_TEST_RET_ENC_NC;
  43688. ret = wc_ImportSakkePublicKey(pub, data, sz, 1);
  43689. if (ret != 0)
  43690. return WC_TEST_RET_ENC_EC(ret);
  43691. ret = wc_ExportSakkePublicKey(pub, pubData, &sz, 1);
  43692. if (ret != 0)
  43693. return WC_TEST_RET_ENC_EC(ret);
  43694. if (sz != 256)
  43695. return WC_TEST_RET_ENC_NC;
  43696. if (XMEMCMP(data, pubData, sz) != 0)
  43697. return WC_TEST_RET_ENC_NC;
  43698. ret = wc_MakeSakkeRsk(priv, id, idSz, rsk);
  43699. if (ret != 0)
  43700. return WC_TEST_RET_ENC_EC(ret);
  43701. ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid);
  43702. if (ret != 0)
  43703. return WC_TEST_RET_ENC_EC(ret);
  43704. if (valid != 1)
  43705. return WC_TEST_RET_ENC_NC;
  43706. ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid);
  43707. if (ret != 0)
  43708. return WC_TEST_RET_ENC_EC(ret);
  43709. if (valid != 1)
  43710. return WC_TEST_RET_ENC_NC;
  43711. sz = sizeof(data);
  43712. ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1);
  43713. if (ret != 0)
  43714. return WC_TEST_RET_ENC_EC(ret);
  43715. if (sz != 256)
  43716. return WC_TEST_RET_ENC_NC;
  43717. ret = wc_DecodeSakkeRsk(priv, data, sz, rsk);
  43718. if (ret != 0)
  43719. return WC_TEST_RET_ENC_EC(ret);
  43720. sz = sizeof(pubData);
  43721. ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0);
  43722. if (ret != 0)
  43723. return WC_TEST_RET_ENC_EC(ret);
  43724. if (sz != sizeof(pubData))
  43725. return WC_TEST_RET_ENC_NC;
  43726. ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk);
  43727. if (ret != 0)
  43728. return WC_TEST_RET_ENC_EC(ret);
  43729. wc_FreeSakkeKey(key);
  43730. return 0;
  43731. }
  43732. static wc_test_ret_t sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng,
  43733. ecc_point* rsk)
  43734. {
  43735. wc_test_ret_t ret;
  43736. byte ssv[16];
  43737. word16 ssvSz;
  43738. byte auth[257];
  43739. word16 authSz;
  43740. char mail[] = "test@wolfssl.com";
  43741. byte* id = (byte*)mail;
  43742. word32 idSz = (word32)XSTRLEN(mail);
  43743. byte pointI[256];
  43744. word32 sz;
  43745. ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz);
  43746. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43747. return WC_TEST_RET_ENC_EC(ret);
  43748. if (ssvSz != 16)
  43749. return WC_TEST_RET_ENC_NC;
  43750. ssvSz += 128;
  43751. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  43752. if (ret == 0)
  43753. return WC_TEST_RET_ENC_NC;
  43754. ssvSz -= 128;
  43755. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  43756. if (ret != 0)
  43757. return WC_TEST_RET_ENC_EC(ret);
  43758. if (ssvSz != 16)
  43759. return WC_TEST_RET_ENC_NC;
  43760. ret = wc_GetSakkeAuthSize(pub, &authSz);
  43761. if (ret != 0)
  43762. return WC_TEST_RET_ENC_EC(ret);
  43763. ret = wc_SetSakkeIdentity(pub, id, idSz);
  43764. if (ret != 0)
  43765. return WC_TEST_RET_ENC_EC(ret);
  43766. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43767. NULL, &authSz);
  43768. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43769. return WC_TEST_RET_ENC_EC(ret);
  43770. if (authSz != 257)
  43771. return WC_TEST_RET_ENC_NC;
  43772. authSz--;
  43773. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43774. auth, &authSz);
  43775. if (ret == 0)
  43776. return WC_TEST_RET_ENC_NC;
  43777. authSz++;
  43778. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43779. auth, &authSz);
  43780. if (ret != 0)
  43781. return WC_TEST_RET_ENC_EC(ret);
  43782. if (authSz != 257)
  43783. return WC_TEST_RET_ENC_NC;
  43784. ret = wc_GetSakkePointI(pub, NULL, &sz);
  43785. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43786. return WC_TEST_RET_ENC_EC(ret);
  43787. if (sz != 256)
  43788. return WC_TEST_RET_ENC_NC;
  43789. ret = wc_GetSakkePointI(pub, pointI, &sz);
  43790. if (ret != 0)
  43791. return WC_TEST_RET_ENC_EC(ret);
  43792. if (sz != 256)
  43793. return WC_TEST_RET_ENC_NC;
  43794. /* Bogus identity - make it check and regenerate I. */
  43795. ret = wc_MakeSakkePointI(pub, ssv, ssvSz);
  43796. if (ret != 0)
  43797. return WC_TEST_RET_ENC_EC(ret);
  43798. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43799. auth, &authSz);
  43800. if (ret != 0)
  43801. return WC_TEST_RET_ENC_EC(ret);
  43802. if (authSz != 257)
  43803. return WC_TEST_RET_ENC_NC;
  43804. ret = wc_SetSakkeRsk(priv, rsk, NULL, 0);
  43805. if (ret != 0)
  43806. return WC_TEST_RET_ENC_EC(ret);
  43807. ret = wc_SetSakkeIdentity(priv, id, idSz);
  43808. if (ret != 0)
  43809. return WC_TEST_RET_ENC_EC(ret);
  43810. authSz--;
  43811. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43812. authSz);
  43813. if (ret == 0)
  43814. return WC_TEST_RET_ENC_NC;
  43815. authSz++;
  43816. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43817. authSz);
  43818. if (ret != 0)
  43819. return WC_TEST_RET_ENC_EC(ret);
  43820. ssv[0] ^= 0x80;
  43821. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43822. authSz);
  43823. if (ret != WC_NO_ERR_TRACE(SAKKE_VERIFY_FAIL_E))
  43824. return WC_TEST_RET_ENC_EC(ret);
  43825. ssv[0] ^= 0x80;
  43826. /* Bogus identity - make it check and regenerate I. */
  43827. ret = wc_MakeSakkePointI(pub, ssv, idSz);
  43828. if (ret != 0)
  43829. return WC_TEST_RET_ENC_EC(ret);
  43830. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43831. authSz);
  43832. if (ret != 0)
  43833. return WC_TEST_RET_ENC_EC(ret);
  43834. return 0;
  43835. }
  43836. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void)
  43837. {
  43838. wc_test_ret_t ret = 0;
  43839. WC_RNG rng;
  43840. int rng_inited = 0;
  43841. SakkeKey* priv = NULL;
  43842. SakkeKey* pub = NULL;
  43843. SakkeKey* key = NULL;
  43844. ecc_point* rsk = NULL;
  43845. WOLFSSL_ENTER("sakke_test");
  43846. priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  43847. DYNAMIC_TYPE_TMP_BUFFER);
  43848. if (priv == NULL)
  43849. ret = WC_TEST_RET_ENC_NC;
  43850. else
  43851. XMEMSET(priv, 0, sizeof(*priv));
  43852. if (ret == 0) {
  43853. pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  43854. DYNAMIC_TYPE_TMP_BUFFER);
  43855. if (pub == NULL)
  43856. ret = WC_TEST_RET_ENC_NC;
  43857. else
  43858. XMEMSET(pub, 0, sizeof(*pub));
  43859. }
  43860. if (ret == 0) {
  43861. key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  43862. DYNAMIC_TYPE_TMP_BUFFER);
  43863. if (key == NULL)
  43864. ret = WC_TEST_RET_ENC_NC;
  43865. else
  43866. XMEMSET(key, 0, sizeof(*key));
  43867. }
  43868. if (ret == 0) {
  43869. #ifndef HAVE_FIPS
  43870. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  43871. #else
  43872. ret = wc_InitRng(&rng);
  43873. #endif
  43874. if (ret == 0)
  43875. rng_inited = 1;
  43876. else
  43877. ret = WC_TEST_RET_ENC_EC(ret);
  43878. }
  43879. if (ret == 0) {
  43880. rsk = wc_ecc_new_point();
  43881. if (rsk == NULL)
  43882. ret = WC_TEST_RET_ENC_NC;
  43883. }
  43884. if (ret == 0) {
  43885. ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID);
  43886. if (ret != 0)
  43887. ret = WC_TEST_RET_ENC_EC(ret);
  43888. }
  43889. if (ret == 0) {
  43890. ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID);
  43891. if (ret != 0)
  43892. ret = WC_TEST_RET_ENC_EC(ret);
  43893. }
  43894. if (ret == 0) {
  43895. ret = sakke_api_test(&rng, key, rsk);
  43896. }
  43897. if (ret == 0) {
  43898. ret = sakke_kat_derive_test(pub, rsk);
  43899. }
  43900. if (ret == 0) {
  43901. ret = sakke_kat_encapsulate_test(pub);
  43902. }
  43903. if (ret == 0) {
  43904. ret = sakke_make_key_test(priv, pub, key, &rng, rsk);
  43905. }
  43906. if (ret == 0) {
  43907. ret = sakke_op_test(priv, pub, &rng, rsk);
  43908. }
  43909. if (rsk != NULL) {
  43910. wc_ecc_forcezero_point(rsk);
  43911. wc_ecc_del_point(rsk);
  43912. }
  43913. if (rng_inited)
  43914. wc_FreeRng(&rng);
  43915. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43916. if (pub != NULL) {
  43917. wc_FreeSakkeKey(pub);
  43918. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43919. }
  43920. if (priv != NULL) {
  43921. wc_FreeSakkeKey(priv);
  43922. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43923. }
  43924. return ret;
  43925. }
  43926. #endif /* WOLFCRYPT_HAVE_SAKKE */
  43927. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  43928. typedef struct CMAC_Test_Case {
  43929. int type;
  43930. int partial;
  43931. const byte* m;
  43932. word32 mSz;
  43933. const byte* k;
  43934. word32 kSz;
  43935. const byte* t;
  43936. word32 tSz;
  43937. } CMAC_Test_Case;
  43938. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void)
  43939. {
  43940. #ifdef WOLFSSL_AES_128
  43941. WOLFSSL_SMALL_STACK_STATIC const byte k128[] =
  43942. {
  43943. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  43944. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  43945. };
  43946. #define KLEN_128 (sizeof(k128))
  43947. #endif
  43948. #ifdef WOLFSSL_AES_192
  43949. WOLFSSL_SMALL_STACK_STATIC const byte k192[] =
  43950. {
  43951. 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
  43952. 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
  43953. 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
  43954. };
  43955. #define KLEN_192 (sizeof(k192))
  43956. #endif
  43957. #ifdef WOLFSSL_AES_256
  43958. WOLFSSL_SMALL_STACK_STATIC const byte k256[] =
  43959. {
  43960. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  43961. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  43962. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  43963. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  43964. };
  43965. #define KLEN_256 (sizeof(k256))
  43966. #endif
  43967. WOLFSSL_SMALL_STACK_STATIC const byte m[] =
  43968. {
  43969. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  43970. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  43971. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  43972. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  43973. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  43974. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  43975. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  43976. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  43977. };
  43978. #define MLEN_0 (0)
  43979. #define MLEN_128 (128/8)
  43980. #define MLEN_320 (320/8)
  43981. #define MLEN_319 (MLEN_320 - 1)
  43982. #define MLEN_512 (512/8)
  43983. #ifdef WOLFSSL_AES_128
  43984. WOLFSSL_SMALL_STACK_STATIC const byte t128_0[] =
  43985. {
  43986. 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
  43987. 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
  43988. };
  43989. WOLFSSL_SMALL_STACK_STATIC const byte t128_128[] =
  43990. {
  43991. 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
  43992. 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
  43993. };
  43994. WOLFSSL_SMALL_STACK_STATIC const byte t128_319[] =
  43995. {
  43996. 0x2c, 0x17, 0x84, 0x4c, 0x93, 0x1c, 0x07, 0x95,
  43997. 0x15, 0x92, 0x73, 0x0a, 0x34, 0xd0, 0xd9, 0xd2
  43998. };
  43999. WOLFSSL_SMALL_STACK_STATIC const byte t128_320[] =
  44000. {
  44001. 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
  44002. 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
  44003. };
  44004. WOLFSSL_SMALL_STACK_STATIC const byte t128_512[] =
  44005. {
  44006. 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
  44007. 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
  44008. };
  44009. #endif
  44010. #ifdef WOLFSSL_AES_192
  44011. WOLFSSL_SMALL_STACK_STATIC const byte t192_0[] =
  44012. {
  44013. 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
  44014. 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
  44015. };
  44016. WOLFSSL_SMALL_STACK_STATIC const byte t192_128[] =
  44017. {
  44018. 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
  44019. 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
  44020. };
  44021. WOLFSSL_SMALL_STACK_STATIC const byte t192_320[] =
  44022. {
  44023. 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
  44024. 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
  44025. };
  44026. WOLFSSL_SMALL_STACK_STATIC const byte t192_512[] =
  44027. {
  44028. 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
  44029. 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
  44030. };
  44031. #endif
  44032. #ifdef WOLFSSL_AES_256
  44033. WOLFSSL_SMALL_STACK_STATIC const byte t256_0[] =
  44034. {
  44035. 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
  44036. 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
  44037. };
  44038. WOLFSSL_SMALL_STACK_STATIC const byte t256_128[] =
  44039. {
  44040. 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
  44041. 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
  44042. };
  44043. WOLFSSL_SMALL_STACK_STATIC const byte t256_320[] =
  44044. {
  44045. 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
  44046. 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
  44047. };
  44048. WOLFSSL_SMALL_STACK_STATIC const byte t256_512[] =
  44049. {
  44050. 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
  44051. 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
  44052. };
  44053. #endif
  44054. const CMAC_Test_Case testCases[] =
  44055. {
  44056. #ifdef WOLFSSL_AES_128
  44057. {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, AES_BLOCK_SIZE},
  44058. {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, AES_BLOCK_SIZE},
  44059. {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, AES_BLOCK_SIZE},
  44060. {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44061. {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44062. #endif
  44063. #ifdef WOLFSSL_AES_192
  44064. {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, AES_BLOCK_SIZE},
  44065. {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, AES_BLOCK_SIZE},
  44066. {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, AES_BLOCK_SIZE},
  44067. {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, AES_BLOCK_SIZE},
  44068. #endif
  44069. #ifdef WOLFSSL_AES_256
  44070. {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, AES_BLOCK_SIZE},
  44071. {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, AES_BLOCK_SIZE},
  44072. {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, AES_BLOCK_SIZE},
  44073. {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, AES_BLOCK_SIZE},
  44074. #endif
  44075. #ifdef WOLFSSL_AES_128
  44076. {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, AES_BLOCK_SIZE}
  44077. #endif
  44078. };
  44079. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44080. Cmac *cmac;
  44081. #else
  44082. Cmac cmac[1];
  44083. #endif
  44084. byte tag[AES_BLOCK_SIZE];
  44085. const CMAC_Test_Case* tc;
  44086. word32 i, tagSz;
  44087. wc_test_ret_t ret;
  44088. WOLFSSL_ENTER("cmac_test");
  44089. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44090. if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL)
  44091. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  44092. #endif
  44093. for (i = 0, tc = testCases;
  44094. i < sizeof(testCases)/sizeof(CMAC_Test_Case);
  44095. i++, tc++) {
  44096. XMEMSET(tag, 0, sizeof(tag));
  44097. tagSz = AES_BLOCK_SIZE;
  44098. #if !defined(HAVE_FIPS) || \
  44099. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)
  44100. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44101. #else
  44102. ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL);
  44103. #endif
  44104. if (ret != 0)
  44105. {
  44106. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44107. }
  44108. if (tc->partial) {
  44109. ret = wc_CmacUpdate(cmac, tc->m,
  44110. tc->mSz/2 - tc->partial);
  44111. if (ret != 0)
  44112. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44113. ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial,
  44114. tc->mSz/2 + tc->partial);
  44115. if (ret != 0)
  44116. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44117. }
  44118. else {
  44119. ret = wc_CmacUpdate(cmac, tc->m, tc->mSz);
  44120. if (ret != 0)
  44121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44122. }
  44123. ret = wc_CmacFinal(cmac, tag, &tagSz);
  44124. if (ret != 0)
  44125. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44126. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44127. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44128. XMEMSET(tag, 0, sizeof(tag));
  44129. tagSz = sizeof(tag);
  44130. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44131. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44132. tc->k, tc->kSz, NULL, devId);
  44133. #else
  44134. ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz,
  44135. tc->k, tc->kSz);
  44136. #endif
  44137. if (ret != 0)
  44138. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44139. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44140. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44141. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44142. ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz,
  44143. tc->k, tc->kSz, HEAP_HINT, devId);
  44144. #else
  44145. ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz,
  44146. tc->k, tc->kSz);
  44147. #endif
  44148. if (ret != 0)
  44149. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44150. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44151. /* Test that keyless generate with init is the same */
  44152. XMEMSET(tag, 0, sizeof(tag));
  44153. tagSz = sizeof(tag);
  44154. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44155. if (ret != 0) {
  44156. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44157. }
  44158. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44159. NULL, 0, HEAP_HINT, devId);
  44160. if (ret != 0) {
  44161. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44162. }
  44163. #endif
  44164. }
  44165. ret = 0;
  44166. out:
  44167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44168. XFREE(cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC);
  44169. #endif
  44170. return ret;
  44171. }
  44172. #endif /* NO_AES && WOLFSSL_CMAC */
  44173. #if defined(WOLFSSL_SIPHASH)
  44174. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44175. /* Test vectors from:
  44176. * https://github.com/veorq/SipHash/blob/master/vectors.h
  44177. */
  44178. static const unsigned char siphash_key[SIPHASH_KEY_SIZE] = {
  44179. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44180. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  44181. };
  44182. static const unsigned char siphash_msg[64] = {
  44183. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44184. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44185. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  44186. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  44187. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  44188. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  44189. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  44190. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  44191. };
  44192. static const unsigned char siphash_r8[64][SIPHASH_MAC_SIZE_8] = {
  44193. { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
  44194. { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
  44195. { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, },
  44196. { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, },
  44197. { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, },
  44198. { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, },
  44199. { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, },
  44200. { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, },
  44201. { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, },
  44202. { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, },
  44203. { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, },
  44204. { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, },
  44205. { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, },
  44206. { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, },
  44207. { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, },
  44208. { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, },
  44209. { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, },
  44210. { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, },
  44211. { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, },
  44212. { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, },
  44213. { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, },
  44214. { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, },
  44215. { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, },
  44216. { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, },
  44217. { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, },
  44218. { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, },
  44219. { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, },
  44220. { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, },
  44221. { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, },
  44222. { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, },
  44223. { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, },
  44224. { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, },
  44225. { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, },
  44226. { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, },
  44227. { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, },
  44228. { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, },
  44229. { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, },
  44230. { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, },
  44231. { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, },
  44232. { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, },
  44233. { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, },
  44234. { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, },
  44235. { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, },
  44236. { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, },
  44237. { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, },
  44238. { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
  44239. { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
  44240. { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
  44241. { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
  44242. { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
  44243. { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
  44244. { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
  44245. { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
  44246. { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
  44247. { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
  44248. { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
  44249. { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
  44250. { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
  44251. { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
  44252. { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
  44253. { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
  44254. { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
  44255. { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
  44256. { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, },
  44257. };
  44258. static const unsigned char siphash_r16[64][SIPHASH_MAC_SIZE_16] = {
  44259. { 0xa3, 0x81, 0x7f, 0x04, 0xba, 0x25, 0xa8, 0xe6,
  44260. 0x6d, 0xf6, 0x72, 0x14, 0xc7, 0x55, 0x02, 0x93, },
  44261. { 0xda, 0x87, 0xc1, 0xd8, 0x6b, 0x99, 0xaf, 0x44,
  44262. 0x34, 0x76, 0x59, 0x11, 0x9b, 0x22, 0xfc, 0x45, },
  44263. { 0x81, 0x77, 0x22, 0x8d, 0xa4, 0xa4, 0x5d, 0xc7,
  44264. 0xfc, 0xa3, 0x8b, 0xde, 0xf6, 0x0a, 0xff, 0xe4, },
  44265. { 0x9c, 0x70, 0xb6, 0x0c, 0x52, 0x67, 0xa9, 0x4e,
  44266. 0x5f, 0x33, 0xb6, 0xb0, 0x29, 0x85, 0xed, 0x51, },
  44267. { 0xf8, 0x81, 0x64, 0xc1, 0x2d, 0x9c, 0x8f, 0xaf,
  44268. 0x7d, 0x0f, 0x6e, 0x7c, 0x7b, 0xcd, 0x55, 0x79, },
  44269. { 0x13, 0x68, 0x87, 0x59, 0x80, 0x77, 0x6f, 0x88,
  44270. 0x54, 0x52, 0x7a, 0x07, 0x69, 0x0e, 0x96, 0x27, },
  44271. { 0x14, 0xee, 0xca, 0x33, 0x8b, 0x20, 0x86, 0x13,
  44272. 0x48, 0x5e, 0xa0, 0x30, 0x8f, 0xd7, 0xa1, 0x5e, },
  44273. { 0xa1, 0xf1, 0xeb, 0xbe, 0xd8, 0xdb, 0xc1, 0x53,
  44274. 0xc0, 0xb8, 0x4a, 0xa6, 0x1f, 0xf0, 0x82, 0x39, },
  44275. { 0x3b, 0x62, 0xa9, 0xba, 0x62, 0x58, 0xf5, 0x61,
  44276. 0x0f, 0x83, 0xe2, 0x64, 0xf3, 0x14, 0x97, 0xb4, },
  44277. { 0x26, 0x44, 0x99, 0x06, 0x0a, 0xd9, 0xba, 0xab,
  44278. 0xc4, 0x7f, 0x8b, 0x02, 0xbb, 0x6d, 0x71, 0xed, },
  44279. { 0x00, 0x11, 0x0d, 0xc3, 0x78, 0x14, 0x69, 0x56,
  44280. 0xc9, 0x54, 0x47, 0xd3, 0xf3, 0xd0, 0xfb, 0xba, },
  44281. { 0x01, 0x51, 0xc5, 0x68, 0x38, 0x6b, 0x66, 0x77,
  44282. 0xa2, 0xb4, 0xdc, 0x6f, 0x81, 0xe5, 0xdc, 0x18, },
  44283. { 0xd6, 0x26, 0xb2, 0x66, 0x90, 0x5e, 0xf3, 0x58,
  44284. 0x82, 0x63, 0x4d, 0xf6, 0x85, 0x32, 0xc1, 0x25, },
  44285. { 0x98, 0x69, 0xe2, 0x47, 0xe9, 0xc0, 0x8b, 0x10,
  44286. 0xd0, 0x29, 0x93, 0x4f, 0xc4, 0xb9, 0x52, 0xf7, },
  44287. { 0x31, 0xfc, 0xef, 0xac, 0x66, 0xd7, 0xde, 0x9c,
  44288. 0x7e, 0xc7, 0x48, 0x5f, 0xe4, 0x49, 0x49, 0x02, },
  44289. { 0x54, 0x93, 0xe9, 0x99, 0x33, 0xb0, 0xa8, 0x11,
  44290. 0x7e, 0x08, 0xec, 0x0f, 0x97, 0xcf, 0xc3, 0xd9, },
  44291. { 0x6e, 0xe2, 0xa4, 0xca, 0x67, 0xb0, 0x54, 0xbb,
  44292. 0xfd, 0x33, 0x15, 0xbf, 0x85, 0x23, 0x05, 0x77, },
  44293. { 0x47, 0x3d, 0x06, 0xe8, 0x73, 0x8d, 0xb8, 0x98,
  44294. 0x54, 0xc0, 0x66, 0xc4, 0x7a, 0xe4, 0x77, 0x40, },
  44295. { 0xa4, 0x26, 0xe5, 0xe4, 0x23, 0xbf, 0x48, 0x85,
  44296. 0x29, 0x4d, 0xa4, 0x81, 0xfe, 0xae, 0xf7, 0x23, },
  44297. { 0x78, 0x01, 0x77, 0x31, 0xcf, 0x65, 0xfa, 0xb0,
  44298. 0x74, 0xd5, 0x20, 0x89, 0x52, 0x51, 0x2e, 0xb1, },
  44299. { 0x9e, 0x25, 0xfc, 0x83, 0x3f, 0x22, 0x90, 0x73,
  44300. 0x3e, 0x93, 0x44, 0xa5, 0xe8, 0x38, 0x39, 0xeb, },
  44301. { 0x56, 0x8e, 0x49, 0x5a, 0xbe, 0x52, 0x5a, 0x21,
  44302. 0x8a, 0x22, 0x14, 0xcd, 0x3e, 0x07, 0x1d, 0x12, },
  44303. { 0x4a, 0x29, 0xb5, 0x45, 0x52, 0xd1, 0x6b, 0x9a,
  44304. 0x46, 0x9c, 0x10, 0x52, 0x8e, 0xff, 0x0a, 0xae, },
  44305. { 0xc9, 0xd1, 0x84, 0xdd, 0xd5, 0xa9, 0xf5, 0xe0,
  44306. 0xcf, 0x8c, 0xe2, 0x9a, 0x9a, 0xbf, 0x69, 0x1c, },
  44307. { 0x2d, 0xb4, 0x79, 0xae, 0x78, 0xbd, 0x50, 0xd8,
  44308. 0x88, 0x2a, 0x8a, 0x17, 0x8a, 0x61, 0x32, 0xad, },
  44309. { 0x8e, 0xce, 0x5f, 0x04, 0x2d, 0x5e, 0x44, 0x7b,
  44310. 0x50, 0x51, 0xb9, 0xea, 0xcb, 0x8d, 0x8f, 0x6f, },
  44311. { 0x9c, 0x0b, 0x53, 0xb4, 0xb3, 0xc3, 0x07, 0xe8,
  44312. 0x7e, 0xae, 0xe0, 0x86, 0x78, 0x14, 0x1f, 0x66, },
  44313. { 0xab, 0xf2, 0x48, 0xaf, 0x69, 0xa6, 0xea, 0xe4,
  44314. 0xbf, 0xd3, 0xeb, 0x2f, 0x12, 0x9e, 0xeb, 0x94, },
  44315. { 0x06, 0x64, 0xda, 0x16, 0x68, 0x57, 0x4b, 0x88,
  44316. 0xb9, 0x35, 0xf3, 0x02, 0x73, 0x58, 0xae, 0xf4, },
  44317. { 0xaa, 0x4b, 0x9d, 0xc4, 0xbf, 0x33, 0x7d, 0xe9,
  44318. 0x0c, 0xd4, 0xfd, 0x3c, 0x46, 0x7c, 0x6a, 0xb7, },
  44319. { 0xea, 0x5c, 0x7f, 0x47, 0x1f, 0xaf, 0x6b, 0xde,
  44320. 0x2b, 0x1a, 0xd7, 0xd4, 0x68, 0x6d, 0x22, 0x87, },
  44321. { 0x29, 0x39, 0xb0, 0x18, 0x32, 0x23, 0xfa, 0xfc,
  44322. 0x17, 0x23, 0xde, 0x4f, 0x52, 0xc4, 0x3d, 0x35, },
  44323. { 0x7c, 0x39, 0x56, 0xca, 0x5e, 0xea, 0xfc, 0x3e,
  44324. 0x36, 0x3e, 0x9d, 0x55, 0x65, 0x46, 0xeb, 0x68, },
  44325. { 0x77, 0xc6, 0x07, 0x71, 0x46, 0xf0, 0x1c, 0x32,
  44326. 0xb6, 0xb6, 0x9d, 0x5f, 0x4e, 0xa9, 0xff, 0xcf, },
  44327. { 0x37, 0xa6, 0x98, 0x6c, 0xb8, 0x84, 0x7e, 0xdf,
  44328. 0x09, 0x25, 0xf0, 0xf1, 0x30, 0x9b, 0x54, 0xde, },
  44329. { 0xa7, 0x05, 0xf0, 0xe6, 0x9d, 0xa9, 0xa8, 0xf9,
  44330. 0x07, 0x24, 0x1a, 0x2e, 0x92, 0x3c, 0x8c, 0xc8, },
  44331. { 0x3d, 0xc4, 0x7d, 0x1f, 0x29, 0xc4, 0x48, 0x46,
  44332. 0x1e, 0x9e, 0x76, 0xed, 0x90, 0x4f, 0x67, 0x11, },
  44333. { 0x0d, 0x62, 0xbf, 0x01, 0xe6, 0xfc, 0x0e, 0x1a,
  44334. 0x0d, 0x3c, 0x47, 0x51, 0xc5, 0xd3, 0x69, 0x2b, },
  44335. { 0x8c, 0x03, 0x46, 0x8b, 0xca, 0x7c, 0x66, 0x9e,
  44336. 0xe4, 0xfd, 0x5e, 0x08, 0x4b, 0xbe, 0xe7, 0xb5, },
  44337. { 0x52, 0x8a, 0x5b, 0xb9, 0x3b, 0xaf, 0x2c, 0x9c,
  44338. 0x44, 0x73, 0xcc, 0xe5, 0xd0, 0xd2, 0x2b, 0xd9, },
  44339. { 0xdf, 0x6a, 0x30, 0x1e, 0x95, 0xc9, 0x5d, 0xad,
  44340. 0x97, 0xae, 0x0c, 0xc8, 0xc6, 0x91, 0x3b, 0xd8, },
  44341. { 0x80, 0x11, 0x89, 0x90, 0x2c, 0x85, 0x7f, 0x39,
  44342. 0xe7, 0x35, 0x91, 0x28, 0x5e, 0x70, 0xb6, 0xdb, },
  44343. { 0xe6, 0x17, 0x34, 0x6a, 0xc9, 0xc2, 0x31, 0xbb,
  44344. 0x36, 0x50, 0xae, 0x34, 0xcc, 0xca, 0x0c, 0x5b, },
  44345. { 0x27, 0xd9, 0x34, 0x37, 0xef, 0xb7, 0x21, 0xaa,
  44346. 0x40, 0x18, 0x21, 0xdc, 0xec, 0x5a, 0xdf, 0x89, },
  44347. { 0x89, 0x23, 0x7d, 0x9d, 0xed, 0x9c, 0x5e, 0x78,
  44348. 0xd8, 0xb1, 0xc9, 0xb1, 0x66, 0xcc, 0x73, 0x42, },
  44349. { 0x4a, 0x6d, 0x80, 0x91, 0xbf, 0x5e, 0x7d, 0x65,
  44350. 0x11, 0x89, 0xfa, 0x94, 0xa2, 0x50, 0xb1, 0x4c, },
  44351. { 0x0e, 0x33, 0xf9, 0x60, 0x55, 0xe7, 0xae, 0x89,
  44352. 0x3f, 0xfc, 0x0e, 0x3d, 0xcf, 0x49, 0x29, 0x02, },
  44353. { 0xe6, 0x1c, 0x43, 0x2b, 0x72, 0x0b, 0x19, 0xd1,
  44354. 0x8e, 0xc8, 0xd8, 0x4b, 0xdc, 0x63, 0x15, 0x1b, },
  44355. { 0xf7, 0xe5, 0xae, 0xf5, 0x49, 0xf7, 0x82, 0xcf,
  44356. 0x37, 0x90, 0x55, 0xa6, 0x08, 0x26, 0x9b, 0x16, },
  44357. { 0x43, 0x8d, 0x03, 0x0f, 0xd0, 0xb7, 0xa5, 0x4f,
  44358. 0xa8, 0x37, 0xf2, 0xad, 0x20, 0x1a, 0x64, 0x03, },
  44359. { 0xa5, 0x90, 0xd3, 0xee, 0x4f, 0xbf, 0x04, 0xe3,
  44360. 0x24, 0x7e, 0x0d, 0x27, 0xf2, 0x86, 0x42, 0x3f, },
  44361. { 0x5f, 0xe2, 0xc1, 0xa1, 0x72, 0xfe, 0x93, 0xc4,
  44362. 0xb1, 0x5c, 0xd3, 0x7c, 0xae, 0xf9, 0xf5, 0x38, },
  44363. { 0x2c, 0x97, 0x32, 0x5c, 0xbd, 0x06, 0xb3, 0x6e,
  44364. 0xb2, 0x13, 0x3d, 0xd0, 0x8b, 0x3a, 0x01, 0x7c, },
  44365. { 0x92, 0xc8, 0x14, 0x22, 0x7a, 0x6b, 0xca, 0x94,
  44366. 0x9f, 0xf0, 0x65, 0x9f, 0x00, 0x2a, 0xd3, 0x9e, },
  44367. { 0xdc, 0xe8, 0x50, 0x11, 0x0b, 0xd8, 0x32, 0x8c,
  44368. 0xfb, 0xd5, 0x08, 0x41, 0xd6, 0x91, 0x1d, 0x87, },
  44369. { 0x67, 0xf1, 0x49, 0x84, 0xc7, 0xda, 0x79, 0x12,
  44370. 0x48, 0xe3, 0x2b, 0xb5, 0x92, 0x25, 0x83, 0xda, },
  44371. { 0x19, 0x38, 0xf2, 0xcf, 0x72, 0xd5, 0x4e, 0xe9,
  44372. 0x7e, 0x94, 0x16, 0x6f, 0xa9, 0x1d, 0x2a, 0x36, },
  44373. { 0x74, 0x48, 0x1e, 0x96, 0x46, 0xed, 0x49, 0xfe,
  44374. 0x0f, 0x62, 0x24, 0x30, 0x16, 0x04, 0x69, 0x8e, },
  44375. { 0x57, 0xfc, 0xa5, 0xde, 0x98, 0xa9, 0xd6, 0xd8,
  44376. 0x00, 0x64, 0x38, 0xd0, 0x58, 0x3d, 0x8a, 0x1d, },
  44377. { 0x9f, 0xec, 0xde, 0x1c, 0xef, 0xdc, 0x1c, 0xbe,
  44378. 0xd4, 0x76, 0x36, 0x74, 0xd9, 0x57, 0x53, 0x59, },
  44379. { 0xe3, 0x04, 0x0c, 0x00, 0xeb, 0x28, 0xf1, 0x53,
  44380. 0x66, 0xca, 0x73, 0xcb, 0xd8, 0x72, 0xe7, 0x40, },
  44381. { 0x76, 0x97, 0x00, 0x9a, 0x6a, 0x83, 0x1d, 0xfe,
  44382. 0xcc, 0xa9, 0x1c, 0x59, 0x93, 0x67, 0x0f, 0x7a, },
  44383. { 0x58, 0x53, 0x54, 0x23, 0x21, 0xf5, 0x67, 0xa0,
  44384. 0x05, 0xd5, 0x47, 0xa4, 0xf0, 0x47, 0x59, 0xbd, },
  44385. { 0x51, 0x50, 0xd1, 0x77, 0x2f, 0x50, 0x83, 0x4a,
  44386. 0x50, 0x3e, 0x06, 0x9a, 0x97, 0x3f, 0xbd, 0x7c, },
  44387. };
  44388. #endif
  44389. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void)
  44390. {
  44391. wc_test_ret_t ret = 0;
  44392. int i;
  44393. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44394. unsigned char res[SIPHASH_MAC_SIZE_16];
  44395. unsigned char tmp[SIPHASH_MAC_SIZE_8];
  44396. SipHash siphash;
  44397. WOLFSSL_ENTER("siphash_test (1)");
  44398. for (i = 0; i < 64; i++) {
  44399. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44400. if (ret != 0)
  44401. return WC_TEST_RET_ENC_I(i);
  44402. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  44403. if (ret != 0)
  44404. return WC_TEST_RET_ENC_I(i);
  44405. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  44406. if (ret != 0)
  44407. return WC_TEST_RET_ENC_I(i);
  44408. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  44409. return WC_TEST_RET_ENC_I(i);
  44410. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_8);
  44411. if (ret != 0)
  44412. return WC_TEST_RET_ENC_I(i);
  44413. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  44414. return WC_TEST_RET_ENC_I(i);
  44415. }
  44416. for (i = 0; i < 64; i++) {
  44417. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16);
  44418. if (ret != 0)
  44419. return WC_TEST_RET_ENC_I(i);
  44420. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  44421. if (ret != 0)
  44422. return WC_TEST_RET_ENC_I(i);
  44423. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  44424. if (ret != 0)
  44425. return WC_TEST_RET_ENC_I(i);
  44426. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  44427. return WC_TEST_RET_ENC_I(i);
  44428. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_16);
  44429. if (ret != 0)
  44430. return WC_TEST_RET_ENC_I(i);
  44431. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  44432. return WC_TEST_RET_ENC_I(i);
  44433. }
  44434. #else
  44435. WOLFSSL_ENTER("siphash_test (1)");
  44436. #endif
  44437. /* Testing bad parameters. */
  44438. ret = wc_InitSipHash(NULL, NULL, SIPHASH_MAC_SIZE_8);
  44439. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44440. return WC_TEST_RET_ENC_EC(ret);
  44441. ret = wc_InitSipHash(NULL, siphash_key, SIPHASH_MAC_SIZE_8);
  44442. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44443. return WC_TEST_RET_ENC_EC(ret);
  44444. ret = wc_InitSipHash(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  44445. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44446. return WC_TEST_RET_ENC_EC(ret);
  44447. ret = wc_InitSipHash(&siphash, siphash_key, 7);
  44448. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44449. return WC_TEST_RET_ENC_EC(ret);
  44450. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44451. if (ret != 0)
  44452. return WC_TEST_RET_ENC_EC(ret);
  44453. ret = wc_SipHashUpdate(NULL, NULL, 0);
  44454. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44455. return WC_TEST_RET_ENC_EC(ret);
  44456. ret = wc_SipHashUpdate(&siphash, NULL, 1);
  44457. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44458. return WC_TEST_RET_ENC_EC(ret);
  44459. ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8);
  44460. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44461. return WC_TEST_RET_ENC_EC(ret);
  44462. ret = wc_SipHashFinal(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  44463. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44464. return WC_TEST_RET_ENC_EC(ret);
  44465. ret = wc_SipHashFinal(NULL, res, SIPHASH_MAC_SIZE_8);
  44466. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44467. return WC_TEST_RET_ENC_EC(ret);
  44468. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  44469. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44470. return WC_TEST_RET_ENC_EC(ret);
  44471. ret = wc_SipHash(NULL, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  44472. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44473. return WC_TEST_RET_ENC_EC(ret);
  44474. ret = wc_SipHash(siphash_key, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  44475. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44476. return WC_TEST_RET_ENC_EC(ret);
  44477. ret = wc_SipHash(NULL, NULL, 0, res, SIPHASH_MAC_SIZE_16);
  44478. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44479. return WC_TEST_RET_ENC_EC(ret);
  44480. ret = wc_SipHash(siphash_key, NULL, 0, res, 15);
  44481. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44482. return WC_TEST_RET_ENC_EC(ret);
  44483. ret = wc_SipHash(siphash_key, NULL, 1, res, SIPHASH_MAC_SIZE_16);
  44484. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44485. return WC_TEST_RET_ENC_EC(ret);
  44486. /* Test cache with multiple non blocksize bytes */
  44487. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44488. if (ret != 0)
  44489. return WC_TEST_RET_ENC_EC(ret);
  44490. ret = wc_SipHashUpdate(&siphash, siphash_msg, 5);
  44491. if (ret != 0)
  44492. return WC_TEST_RET_ENC_EC(ret);
  44493. ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4);
  44494. if (ret != 0)
  44495. return WC_TEST_RET_ENC_EC(ret);
  44496. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  44497. if (ret != 0)
  44498. return WC_TEST_RET_ENC_EC(ret);
  44499. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44500. if (ret != 0)
  44501. return WC_TEST_RET_ENC_EC(ret);
  44502. ret = wc_SipHashUpdate(&siphash, siphash_msg, 9);
  44503. if (ret != 0)
  44504. return WC_TEST_RET_ENC_EC(ret);
  44505. ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8);
  44506. if (ret != 0)
  44507. return WC_TEST_RET_ENC_EC(ret);
  44508. if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0)
  44509. return WC_TEST_RET_ENC_NC;
  44510. return 0;
  44511. }
  44512. #endif /* WOLFSSL_SIPHASH */
  44513. #ifdef HAVE_LIBZ
  44514. static const byte sample_text[] =
  44515. "Biodiesel cupidatat marfa, cliche aute put a bird on it incididunt elit\n"
  44516. "polaroid. Sunt tattooed bespoke reprehenderit. Sint twee organic id\n"
  44517. "marfa. Commodo veniam ad esse gastropub. 3 wolf moon sartorial vero,\n"
  44518. "plaid delectus biodiesel squid +1 vice. Post-ironic keffiyeh leggings\n"
  44519. "selfies cray fap hoodie, forage anim. Carles cupidatat shoreditch, VHS\n"
  44520. "small batch meggings kogi dolore food truck bespoke gastropub.\n"
  44521. "\n"
  44522. "Terry richardson adipisicing actually typewriter tumblr, twee whatever\n"
  44523. "four loko you probably haven't heard of them high life. Messenger bag\n"
  44524. "whatever tattooed deep v mlkshk. Brooklyn pinterest assumenda chillwave\n"
  44525. "et, banksy ullamco messenger bag umami pariatur direct trade forage.\n"
  44526. "Typewriter culpa try-hard, pariatur sint brooklyn meggings. Gentrify\n"
  44527. "food truck next level, tousled irony non semiotics PBR ethical anim cred\n"
  44528. "readymade. Mumblecore brunch lomo odd future, portland organic terry\n"
  44529. "richardson elit leggings adipisicing ennui raw denim banjo hella. Godard\n"
  44530. "mixtape polaroid, pork belly readymade organic cray typewriter helvetica\n"
  44531. "four loko whatever street art yr farm-to-table.\n"
  44532. "\n"
  44533. "Vinyl keytar vice tofu. Locavore you probably haven't heard of them pug\n"
  44534. "pickled, hella tonx labore truffaut DIY mlkshk elit cosby sweater sint\n"
  44535. "et mumblecore. Elit swag semiotics, reprehenderit DIY sartorial nisi ugh\n"
  44536. "nesciunt pug pork belly wayfarers selfies delectus. Ethical hoodie\n"
  44537. "seitan fingerstache kale chips. Terry richardson artisan williamsburg,\n"
  44538. "eiusmod fanny pack irony tonx ennui lo-fi incididunt tofu YOLO\n"
  44539. "readymade. 8-bit sed ethnic beard officia. Pour-over iphone DIY butcher,\n"
  44540. "ethnic art party qui letterpress nisi proident jean shorts mlkshk\n"
  44541. "locavore.\n"
  44542. "\n"
  44543. "Narwhal flexitarian letterpress, do gluten-free voluptate next level\n"
  44544. "banh mi tonx incididunt carles DIY. Odd future nulla 8-bit beard ut\n"
  44545. "cillum pickled velit, YOLO officia you probably haven't heard of them\n"
  44546. "trust fund gastropub. Nisi adipisicing tattooed, Austin mlkshk 90's\n"
  44547. "small batch american apparel. Put a bird on it cosby sweater before they\n"
  44548. "sold out pork belly kogi hella. Street art mollit sustainable polaroid,\n"
  44549. "DIY ethnic ea pug beard dreamcatcher cosby sweater magna scenester nisi.\n"
  44550. "Sed pork belly skateboard mollit, labore proident eiusmod. Sriracha\n"
  44551. "excepteur cosby sweater, anim deserunt laborum eu aliquip ethical et\n"
  44552. "neutra PBR selvage.\n"
  44553. "\n"
  44554. "Raw denim pork belly truffaut, irony plaid sustainable put a bird on it\n"
  44555. "next level jean shorts exercitation. Hashtag keytar whatever, nihil\n"
  44556. "authentic aliquip disrupt laborum. Tattooed selfies deserunt trust fund\n"
  44557. "wayfarers. 3 wolf moon synth church-key sartorial, gastropub leggings\n"
  44558. "tattooed. Labore high life commodo, meggings raw denim fingerstache pug\n"
  44559. "trust fund leggings seitan forage. Nostrud ullamco duis, reprehenderit\n"
  44560. "incididunt flannel sustainable helvetica pork belly pug banksy you\n"
  44561. "probably haven't heard of them nesciunt farm-to-table. Disrupt nostrud\n"
  44562. "mollit magna, sriracha sartorial helvetica.\n"
  44563. "\n"
  44564. "Nulla kogi reprehenderit, skateboard sustainable duis adipisicing viral\n"
  44565. "ad fanny pack salvia. Fanny pack trust fund you probably haven't heard\n"
  44566. "of them YOLO vice nihil. Keffiyeh cray lo-fi pinterest cardigan aliqua,\n"
  44567. "reprehenderit aute. Culpa tousled williamsburg, marfa lomo actually anim\n"
  44568. "skateboard. Iphone aliqua ugh, semiotics pariatur vero readymade\n"
  44569. "organic. Marfa squid nulla, in laborum disrupt laboris irure gastropub.\n"
  44570. "Veniam sunt food truck leggings, sint vinyl fap.\n"
  44571. "\n"
  44572. "Hella dolore pork belly, truffaut carles you probably haven't heard of\n"
  44573. "them PBR helvetica in sapiente. Fashion axe ugh bushwick american\n"
  44574. "apparel. Fingerstache sed iphone, jean shorts blue bottle nisi bushwick\n"
  44575. "flexitarian officia veniam plaid bespoke fap YOLO lo-fi. Blog\n"
  44576. "letterpress mumblecore, food truck id cray brooklyn cillum ad sed.\n"
  44577. "Assumenda chambray wayfarers vinyl mixtape sustainable. VHS vinyl\n"
  44578. "delectus, culpa williamsburg polaroid cliche swag church-key synth kogi\n"
  44579. "magna pop-up literally. Swag thundercats ennui shoreditch vegan\n"
  44580. "pitchfork neutra truffaut etsy, sed single-origin coffee craft beer.\n"
  44581. "\n"
  44582. "Odio letterpress brooklyn elit. Nulla single-origin coffee in occaecat\n"
  44583. "meggings. Irony meggings 8-bit, chillwave lo-fi adipisicing cred\n"
  44584. "dreamcatcher veniam. Put a bird on it irony umami, trust fund bushwick\n"
  44585. "locavore kale chips. Sriracha swag thundercats, chillwave disrupt\n"
  44586. "tousled beard mollit mustache leggings portland next level. Nihil esse\n"
  44587. "est, skateboard art party etsy thundercats sed dreamcatcher ut iphone\n"
  44588. "swag consectetur et. Irure skateboard banjo, nulla deserunt messenger\n"
  44589. "bag dolor terry richardson sapiente.\n";
  44590. static const byte sample_text_gz[] = {
  44591. 0x1F, 0x8B, 0x08, 0x08, 0xC5, 0x49, 0xB5, 0x5B, 0x00, 0x03, 0x63, 0x69, 0x70,
  44592. 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x8D,
  44593. 0x58, 0xCB, 0x92, 0xE4, 0xB6, 0x11, 0xBC, 0xE3, 0x2B, 0xEA, 0xA6, 0x83, 0xD9,
  44594. 0x1D, 0x72, 0xF8, 0x22, 0x1F, 0xB5, 0x96, 0xA5, 0xDD, 0x90, 0xBC, 0xAB, 0xD0,
  44595. 0x28, 0x36, 0x42, 0x47, 0x90, 0x2C, 0x36, 0xA1, 0x06, 0x09, 0x0A, 0x8F, 0xEE,
  44596. 0xE1, 0xDF, 0x3B, 0x0B, 0xE0, 0x73, 0x2C, 0x4B, 0xBA, 0xCD, 0xCE, 0x80, 0x78,
  44597. 0x64, 0x65, 0x65, 0x66, 0xED, 0x3B, 0xE3, 0x5A, 0xC3, 0x81, 0x2D, 0x35, 0x69,
  44598. 0x32, 0xAD, 0x8E, 0x3A, 0xD2, 0xA0, 0x7D, 0xA7, 0x2B, 0x6A, 0xAC, 0x69, 0x7A,
  44599. 0x26, 0x9D, 0x22, 0xD3, 0x94, 0x22, 0x69, 0xAA, 0x8D, 0x6F, 0xC9, 0x8D, 0x64,
  44600. 0x22, 0x99, 0xB1, 0x31, 0xAD, 0x69, 0xD3, 0x18, 0x89, 0xAD, 0x89, 0x6A, 0x72,
  44601. 0x56, 0x7B, 0x67, 0xDA, 0x2B, 0xBD, 0xC8, 0xEF, 0xB0, 0x4D, 0x74, 0x8E, 0x5B,
  44602. 0xAA, 0x39, 0x4C, 0xEE, 0xCE, 0xE4, 0x79, 0xF2, 0xDC, 0xF3, 0xD8, 0xB2, 0x37,
  44603. 0x11, 0x8B, 0x8C, 0x2C, 0x7A, 0x32, 0x93, 0xF3, 0x37, 0x3D, 0x9A, 0x86, 0x4C,
  44604. 0xAB, 0xF2, 0xB9, 0x57, 0xFA, 0x97, 0x1B, 0x06, 0xD7, 0x3A, 0x7A, 0xF0, 0x68,
  44605. 0xF4, 0x40, 0xBA, 0x25, 0x0E, 0x81, 0xE9, 0xA6, 0x43, 0xF4, 0x6E, 0x4A, 0xF5,
  44606. 0x95, 0xFE, 0x41, 0x4F, 0x67, 0x3B, 0x1A, 0x1C, 0xEE, 0x12, 0xB4, 0x8F, 0xCE,
  44607. 0x1B, 0x6D, 0xB1, 0xDE, 0xBB, 0x4A, 0x4D, 0x56, 0x9B, 0x96, 0x5A, 0xB6, 0xDC,
  44608. 0xC4, 0x14, 0x70, 0xE5, 0xF5, 0x7D, 0xE1, 0xB7, 0x84, 0x3F, 0xFC, 0xED, 0xEF,
  44609. 0xF4, 0x30, 0x0D, 0x5F, 0xE9, 0x47, 0x17, 0xE2, 0xC5, 0x78, 0x27, 0x67, 0xDF,
  44610. 0xB9, 0xEB, 0xCC, 0xCC, 0x3D, 0x59, 0xBE, 0xDD, 0xCC, 0x78, 0x0B, 0x0A, 0x1F,
  44611. 0x74, 0xF8, 0x8C, 0x1A, 0xAF, 0x67, 0xEA, 0xF4, 0x44, 0xBD, 0x93, 0x7D, 0x2A,
  44612. 0xEA, 0x9C, 0xD7, 0x37, 0x80, 0x32, 0x9A, 0x01, 0x37, 0xD5, 0xDE, 0xCA, 0xA2,
  44613. 0x0D, 0xB9, 0xD0, 0x3B, 0xCF, 0xAD, 0x89, 0x4D, 0x5F, 0xD1, 0xE7, 0xF7, 0x2F,
  44614. 0x2A, 0x0C, 0xDA, 0x5A, 0xAA, 0x35, 0x7E, 0x41, 0xC3, 0xB2, 0x37, 0xDD, 0xDD,
  44615. 0xCD, 0x50, 0xEB, 0x2C, 0x96, 0x62, 0x3B, 0xD7, 0x52, 0xF4, 0xA9, 0xB9, 0x6F,
  44616. 0x48, 0xED, 0xEF, 0x54, 0xEA, 0x67, 0xF6, 0x7E, 0x26, 0x8F, 0x3A, 0x68, 0xDF,
  44617. 0x06, 0xBC, 0x56, 0xB7, 0x66, 0x32, 0xC1, 0x34, 0xD8, 0x88, 0x34, 0x1E, 0x88,
  44618. 0xED, 0x67, 0x8A, 0xF3, 0xC4, 0x4F, 0xC0, 0xCA, 0x9E, 0x62, 0x1A, 0x6A, 0xEB,
  44619. 0xAB, 0x02, 0xED, 0xB3, 0xD7, 0x91, 0x81, 0x8A, 0xEA, 0x5C, 0xF2, 0x64, 0xDD,
  44620. 0xDD, 0xD1, 0xEC, 0x12, 0x4D, 0xDE, 0xD5, 0xBA, 0xC6, 0x77, 0xBD, 0x06, 0xC4,
  44621. 0x5F, 0x44, 0xEA, 0x59, 0x4B, 0x5D, 0x3B, 0x8A, 0x3D, 0x0F, 0xD4, 0x9B, 0x1B,
  44622. 0x80, 0x30, 0x1D, 0x30, 0xFA, 0x8F, 0x00, 0x3F, 0xDE, 0xB0, 0x6F, 0xAD, 0x6F,
  44623. 0x6A, 0xDD, 0x6E, 0x2F, 0x6E, 0xCB, 0x3C, 0xD1, 0x83, 0x06, 0x7B, 0x0F, 0xFD,
  44624. 0xFD, 0x4A, 0xEF, 0xBC, 0x73, 0x77, 0x3B, 0x8F, 0x34, 0xA1, 0xBA, 0xEC, 0x39,
  44625. 0x80, 0x33, 0x21, 0xA4, 0x01, 0x55, 0xD7, 0xD4, 0xF4, 0xC6, 0xDA, 0x27, 0x4E,
  44626. 0x54, 0x1C, 0x2B, 0xEC, 0x37, 0xDE, 0xC3, 0x4C, 0xC9, 0x5A, 0x3D, 0x34, 0x0E,
  44627. 0xD8, 0x1C, 0x0E, 0xA2, 0x34, 0xE8, 0xC1, 0xD0, 0xA4, 0x51, 0xD5, 0x88, 0x8B,
  44628. 0xB7, 0xC6, 0xA3, 0x96, 0x40, 0x49, 0xB7, 0xBC, 0xE0, 0x7F, 0x55, 0x3F, 0xEF,
  44629. 0x6F, 0x6E, 0x92, 0x9D, 0x34, 0xFE, 0x3C, 0x5F, 0x04, 0xA5, 0x6A, 0xFF, 0x30,
  44630. 0x08, 0xC9, 0xEA, 0xF5, 0x52, 0x2B, 0xFE, 0x57, 0xFA, 0x8E, 0xC7, 0xE8, 0x4D,
  44631. 0x37, 0xAB, 0x03, 0xFA, 0x23, 0xBF, 0x46, 0x94, 0xFF, 0xC1, 0x16, 0xE0, 0xB9,
  44632. 0x14, 0x2C, 0x9E, 0x27, 0xEC, 0x98, 0x69, 0x14, 0x92, 0xF1, 0x60, 0x5C, 0x34,
  44633. 0x4D, 0xA0, 0x1F, 0xDF, 0xFD, 0x44, 0x1C, 0x7B, 0xD3, 0x80, 0x70, 0x42, 0x02,
  44634. 0x30, 0x84, 0x5B, 0xE5, 0x59, 0xB7, 0xF3, 0x80, 0xFB, 0x01, 0x33, 0xA9, 0x00,
  44635. 0x37, 0x52, 0xDC, 0xDA, 0xA7, 0x11, 0x85, 0xB7, 0x6E, 0x70, 0xE4, 0xDA, 0x96,
  44636. 0xBA, 0x84, 0x5B, 0x81, 0x43, 0x93, 0xF3, 0xD1, 0xEA, 0xB1, 0xDD, 0xB8, 0x1F,
  44637. 0xA5, 0xCC, 0xEA, 0x50, 0x66, 0x69, 0xA9, 0x8D, 0x8C, 0xA7, 0xA2, 0xF3, 0x38,
  44638. 0x26, 0x43, 0x5E, 0x3F, 0x01, 0xBE, 0x1C, 0x0F, 0x20, 0x7F, 0x75, 0xA8, 0x20,
  44639. 0x80, 0xC4, 0xC3, 0x5C, 0x8B, 0x0D, 0xD4, 0x60, 0x5E, 0xA3, 0x9E, 0xD0, 0xB4,
  44640. 0x4B, 0x4F, 0xE6, 0x13, 0x85, 0x60, 0x42, 0x96, 0xED, 0xAA, 0xDB, 0xE9, 0x99,
  44641. 0xE3, 0x07, 0x0E, 0x61, 0xB3, 0x07, 0xE3, 0xB1, 0xFA, 0xC0, 0x9B, 0xAD, 0xF6,
  44642. 0xE0, 0x26, 0x33, 0xEA, 0xEA, 0x23, 0xCD, 0x1E, 0x9D, 0xE1, 0x87, 0x4B, 0x74,
  44643. 0x97, 0x08, 0x3E, 0xA1, 0x28, 0xEA, 0xB3, 0x19, 0x67, 0x8B, 0x76, 0x9A, 0xA3,
  44644. 0xF6, 0xB9, 0xCF, 0x80, 0x65, 0x97, 0xAE, 0xF4, 0x83, 0x6B, 0xF4, 0x43, 0x20,
  44645. 0xF9, 0x0B, 0xFC, 0x9B, 0xD2, 0x4D, 0x4D, 0xA6, 0xB9, 0xA3, 0x02, 0x55, 0x79,
  44646. 0x18, 0x36, 0x19, 0x5F, 0xC9, 0xEA, 0x5A, 0x76, 0x40, 0xB9, 0xBA, 0x0E, 0x9A,
  44647. 0x44, 0xDF, 0x7C, 0xF8, 0x65, 0x61, 0x5E, 0x81, 0xAB, 0x71, 0xA1, 0x9E, 0x29,
  44648. 0x3C, 0x59, 0xCB, 0x23, 0xA4, 0xF6, 0x60, 0x1A, 0x0D, 0x5B, 0x39, 0xAE, 0xF4,
  44649. 0x6F, 0x59, 0x16, 0x9E, 0x60, 0xD8, 0x56, 0xCF, 0xEA, 0x2C, 0x4C, 0x79, 0xD3,
  44650. 0x5D, 0x51, 0x46, 0xA0, 0x4E, 0xE9, 0xD6, 0xAB, 0x91, 0x43, 0x63, 0x44, 0xD7,
  44651. 0x70, 0xB9, 0x23, 0x98, 0x4F, 0x3D, 0x03, 0x02, 0xF6, 0x81, 0x56, 0xC1, 0x58,
  44652. 0x85, 0x07, 0xA7, 0x2D, 0x2C, 0x29, 0xCA, 0x01, 0x45, 0x31, 0x51, 0x8F, 0xD4,
  44653. 0x19, 0xA1, 0x79, 0x88, 0x5A, 0xA4, 0xF5, 0xAE, 0x2D, 0x4B, 0x63, 0x4C, 0x58,
  44654. 0xFE, 0xBF, 0xAD, 0xEE, 0xA3, 0x09, 0xF8, 0xE2, 0x89, 0xBE, 0x81, 0x0E, 0x86,
  44655. 0x3A, 0xF9, 0x5B, 0xA5, 0xD8, 0xA4, 0x00, 0x75, 0x04, 0xF2, 0x23, 0xB8, 0x39,
  44656. 0x69, 0x50, 0xB7, 0xD0, 0x34, 0x63, 0x54, 0xD8, 0x61, 0xDD, 0xA5, 0x33, 0x47,
  44657. 0x85, 0x96, 0x22, 0xD0, 0x2F, 0x9F, 0x7E, 0xF8, 0x74, 0x24, 0xEA, 0x57, 0x97,
  44658. 0x5A, 0xE0, 0x00, 0xCF, 0xC1, 0x67, 0xE1, 0x41, 0xBD, 0x94, 0xA1, 0x03, 0xD3,
  44659. 0xB4, 0x08, 0x64, 0xF2, 0x17, 0x27, 0x35, 0x37, 0x53, 0xEF, 0x46, 0xCE, 0xD8,
  44660. 0xD4, 0x09, 0x52, 0xC6, 0x1E, 0xF7, 0x28, 0xDF, 0x08, 0x0F, 0xD0, 0x6F, 0x71,
  44661. 0xA6, 0xDF, 0xE4, 0x60, 0x8E, 0xC0, 0x1E, 0x78, 0x86, 0x50, 0xB0, 0x9B, 0x84,
  44662. 0x7E, 0xE8, 0x36, 0xFA, 0x95, 0xF1, 0x12, 0x51, 0xC7, 0x18, 0x96, 0xA2, 0x29,
  44663. 0xBB, 0x70, 0x02, 0xB4, 0xF9, 0xA8, 0x3D, 0x08, 0x66, 0xA9, 0xB3, 0xFC, 0x0A,
  44664. 0x94, 0x80, 0xFD, 0x78, 0xDC, 0xAB, 0x82, 0x5A, 0xD2, 0xCD, 0xC2, 0x87, 0xC6,
  44665. 0x4B, 0x07, 0xFA, 0xD1, 0xC3, 0xD9, 0x34, 0x41, 0x85, 0xF8, 0xD0, 0xB6, 0x0A,
  44666. 0x9D, 0x00, 0x91, 0x35, 0x05, 0x88, 0xC3, 0xE3, 0x9B, 0x22, 0xD2, 0xB8, 0xFD,
  44667. 0x95, 0x3E, 0x6D, 0x5D, 0x48, 0xA3, 0x68, 0xCF, 0x02, 0x42, 0x79, 0x79, 0x8A,
  44668. 0xAA, 0x01, 0xD6, 0x09, 0x14, 0x2C, 0xF4, 0x83, 0xA3, 0x80, 0x31, 0x55, 0x46,
  44669. 0x6E, 0xC5, 0xE5, 0x2F, 0x30, 0x58, 0x81, 0xA2, 0x90, 0xBE, 0x2E, 0xA1, 0xC3,
  44670. 0x0F, 0xA6, 0xF5, 0x51, 0x00, 0x39, 0xB6, 0xF2, 0x2A, 0xA3, 0x15, 0x7D, 0x8D,
  44671. 0xF5, 0x66, 0x5C, 0xD9, 0xFC, 0xCF, 0x2F, 0xBF, 0x08, 0x27, 0xE7, 0xD0, 0x03,
  44672. 0xB8, 0xD9, 0x00, 0x13, 0x3D, 0x01, 0x6B, 0xB6, 0xA8, 0xCD, 0x5B, 0x3B, 0x3E,
  44673. 0x93, 0xBF, 0xE6, 0x2E, 0xB7, 0x4A, 0xCF, 0xB3, 0x0A, 0xCE, 0x62, 0x11, 0xD6,
  44674. 0x1F, 0x68, 0x9B, 0x1D, 0x68, 0xD1, 0x8C, 0x97, 0xBD, 0xA1, 0x07, 0x67, 0x73,
  44675. 0x87, 0xE0, 0x36, 0xDA, 0x8C, 0xD2, 0xD2, 0xBB, 0x84, 0x28, 0xA9, 0xFE, 0x52,
  44676. 0x74, 0xD6, 0xB9, 0x0F, 0x0A, 0x6A, 0x2D, 0x28, 0x35, 0x34, 0x3A, 0xD3, 0xE2,
  44677. 0xCD, 0x35, 0x06, 0x7D, 0x1B, 0x35, 0x85, 0x86, 0xD1, 0x3E, 0xF2, 0x6F, 0xA1,
  44678. 0xC4, 0x55, 0xBD, 0x00, 0xD8, 0xC3, 0x5D, 0xC2, 0x1D, 0x6B, 0x6B, 0x27, 0x5B,
  44679. 0x95, 0xF3, 0xAB, 0xB5, 0xD3, 0x37, 0xF2, 0x2C, 0x9C, 0xC7, 0x5D, 0xBD, 0xF1,
  44680. 0x68, 0x1C, 0xAD, 0xF8, 0xB5, 0xE1, 0x29, 0x72, 0x7A, 0x73, 0x62, 0x55, 0x24,
  44681. 0xB9, 0x85, 0xDF, 0x7B, 0x29, 0x7D, 0xDE, 0x08, 0xF5, 0xE4, 0x44, 0xDA, 0x1A,
  44682. 0x30, 0x74, 0xDA, 0xB4, 0x9B, 0x23, 0x9A, 0x3A, 0xC1, 0x53, 0xB2, 0xA2, 0xA3,
  44683. 0x7B, 0x1F, 0xD9, 0x56, 0xD4, 0x4F, 0x9B, 0xB2, 0x1E, 0xEE, 0xB8, 0x6A, 0x4E,
  44684. 0xB5, 0xF4, 0x5A, 0xC9, 0x18, 0x27, 0x9C, 0xDE, 0x14, 0x44, 0xED, 0xC4, 0x3C,
  44685. 0x71, 0x9F, 0x5F, 0xD9, 0x37, 0xA0, 0x78, 0x34, 0x6E, 0xBC, 0xD2, 0x7B, 0x1D,
  44686. 0xFA, 0x08, 0x39, 0x5A, 0x04, 0x73, 0x15, 0xD9, 0x0A, 0x48, 0xC1, 0x2D, 0x15,
  44687. 0x4E, 0x84, 0x30, 0x45, 0x69, 0xB3, 0xE5, 0xF6, 0xAD, 0x09, 0x1E, 0xCC, 0x5F,
  44688. 0x1F, 0x06, 0xD5, 0x58, 0xAD, 0x78, 0xD7, 0x9F, 0xE5, 0xED, 0x3B, 0x09, 0xD5,
  44689. 0xA6, 0x52, 0x6F, 0x92, 0xD3, 0x3C, 0xC6, 0x1E, 0xF2, 0x93, 0x7C, 0xD3, 0x5F,
  44690. 0x70, 0x85, 0x5D, 0xF8, 0xAA, 0x9D, 0xB7, 0x7B, 0x24, 0x5A, 0xE9, 0x0A, 0x35,
  44691. 0x2F, 0xF5, 0xD9, 0x82, 0x02, 0x8A, 0x90, 0x13, 0x5B, 0xB5, 0x67, 0x9C, 0xDD,
  44692. 0xA0, 0x4E, 0x82, 0x27, 0xDA, 0x7E, 0xE8, 0x8E, 0xCD, 0xE1, 0x56, 0x71, 0x2C,
  44693. 0xE6, 0x4E, 0x1F, 0x91, 0xCD, 0x7C, 0x6A, 0xB7, 0x78, 0xD0, 0x26, 0xF3, 0x56,
  44694. 0xA9, 0xD5, 0xA1, 0xC3, 0x3B, 0x98, 0xE9, 0x28, 0x09, 0xEF, 0x50, 0x90, 0xCD,
  44695. 0xC4, 0x8E, 0x75, 0xCC, 0xAC, 0x2D, 0xC9, 0x03, 0x6D, 0xAC, 0xFE, 0xC4, 0x88,
  44696. 0x36, 0xD1, 0x3F, 0xBB, 0x1C, 0x7D, 0xB3, 0x14, 0x61, 0x2C, 0xB7, 0x54, 0x4B,
  44697. 0xDB, 0x64, 0xB6, 0x57, 0x14, 0x16, 0x8E, 0x1E, 0x6C, 0x64, 0xBB, 0x8B, 0x48,
  44698. 0x5D, 0x96, 0x9D, 0xDC, 0x80, 0xA7, 0xF7, 0x54, 0xC7, 0x46, 0x38, 0x3E, 0x44,
  44699. 0xDE, 0x7E, 0x92, 0x8D, 0x07, 0xF6, 0x07, 0x37, 0x4E, 0x16, 0x10, 0xB4, 0x7D,
  44700. 0x88, 0x66, 0x7F, 0xBB, 0xFF, 0xEA, 0x00, 0xF3, 0xFF, 0x97, 0x2C, 0xB5, 0xBE,
  44701. 0x35, 0x4B, 0x5C, 0x36, 0xEC, 0x4C, 0xBD, 0x2B, 0x7D, 0xBF, 0x46, 0xE2, 0x9C,
  44702. 0x0E, 0x8A, 0xA3, 0xEC, 0xB1, 0x0E, 0x9A, 0xDA, 0x9A, 0x9B, 0x28, 0x92, 0x10,
  44703. 0x53, 0x57, 0xEA, 0xEC, 0xA2, 0x32, 0x32, 0x20, 0x1D, 0x97, 0x5C, 0xB6, 0x84,
  44704. 0xA9, 0x93, 0x8D, 0x95, 0x11, 0xA3, 0x24, 0xA3, 0x2D, 0xC6, 0x4A, 0xEF, 0xAA,
  44705. 0x1D, 0x85, 0x2B, 0x7D, 0x28, 0xBE, 0x53, 0xCE, 0x10, 0x1F, 0xAE, 0x0E, 0x41,
  44706. 0x6C, 0x4B, 0x79, 0x12, 0xFB, 0xF7, 0x54, 0xA3, 0x96, 0x54, 0x83, 0x20, 0x96,
  44707. 0x8F, 0x28, 0xA9, 0x3F, 0x8B, 0x3D, 0xBA, 0x77, 0xDC, 0x24, 0xE1, 0xD4, 0x49,
  44708. 0x40, 0xD8, 0x78, 0x31, 0x85, 0x43, 0xF6, 0xFE, 0x5C, 0xA6, 0x8F, 0x90, 0x09,
  44709. 0xB0, 0xE7, 0xC4, 0x95, 0xB2, 0x55, 0x49, 0x97, 0x8F, 0x1C, 0x78, 0x30, 0x20,
  44710. 0xA0, 0xB4, 0xEF, 0x73, 0x56, 0x59, 0x82, 0xFD, 0xCE, 0xBA, 0x6A, 0x8F, 0x2C,
  44711. 0x8B, 0x15, 0xFD, 0xA1, 0x85, 0xA8, 0x5C, 0x0F, 0x11, 0xA5, 0x9D, 0xC2, 0x46,
  44712. 0xC6, 0x9C, 0xC9, 0x40, 0x0B, 0x58, 0x6A, 0x1C, 0x7A, 0x23, 0xF9, 0xE0, 0x95,
  44713. 0x05, 0x13, 0x58, 0x72, 0xE8, 0x9F, 0x30, 0xAC, 0xCD, 0x26, 0xD4, 0x66, 0x13,
  44714. 0xDF, 0x1E, 0x7B, 0x4F, 0x9C, 0xBE, 0x38, 0x79, 0x75, 0x92, 0xA4, 0xDA, 0x26,
  44715. 0x44, 0x55, 0x17, 0xA3, 0xE5, 0x62, 0xDA, 0xEB, 0x86, 0xEA, 0x68, 0xC7, 0xAB,
  44716. 0xFD, 0x2D, 0x43, 0x59, 0x51, 0xC0, 0x75, 0x64, 0x91, 0x01, 0x29, 0x33, 0x28,
  44717. 0xF3, 0x04, 0x83, 0x80, 0x75, 0x37, 0x75, 0x0C, 0x03, 0x7B, 0x0A, 0xAB, 0x8E,
  44718. 0x60, 0x62, 0x8B, 0x4C, 0xAF, 0x2D, 0xA3, 0x2F, 0xFE, 0xAB, 0x45, 0xCF, 0xDA,
  44719. 0xAB, 0xFA, 0xFA, 0x30, 0x3D, 0xE8, 0xA1, 0x96, 0xA5, 0x7B, 0xE2, 0x2A, 0xD0,
  44720. 0xAF, 0x59, 0xF7, 0xD0, 0x32, 0x57, 0x19, 0xBD, 0xCA, 0x9F, 0xD5, 0x1A, 0xC7,
  44721. 0xAA, 0x65, 0x4A, 0x38, 0xB2, 0x70, 0x33, 0xB7, 0x75, 0xD2, 0xCD, 0xD1, 0xF0,
  44722. 0xA8, 0x87, 0x59, 0x20, 0xA5, 0x57, 0x55, 0xB1, 0xB2, 0xC9, 0x4D, 0x97, 0x34,
  44723. 0x41, 0xF3, 0xF0, 0x30, 0xA1, 0x2C, 0x1C, 0x49, 0x3E, 0x89, 0x7D, 0x12, 0xE2,
  44724. 0xC3, 0x04, 0xC3, 0x92, 0xC0, 0xF6, 0x39, 0x10, 0x80, 0x81, 0x8F, 0x08, 0xB4,
  44725. 0xF8, 0xB9, 0x13, 0x4E, 0x2C, 0xAE, 0xB3, 0x71, 0x82, 0x63, 0x98, 0xAB, 0x5C,
  44726. 0x1C, 0x10, 0xEA, 0x66, 0xF9, 0x02, 0x3A, 0x82, 0x61, 0xD0, 0xD4, 0xAE, 0x43,
  44727. 0xD4, 0x01, 0x3E, 0x9D, 0x04, 0x14, 0xF6, 0x60, 0xD8, 0xA7, 0xD6, 0xB8, 0x53,
  44728. 0xC8, 0xDA, 0x80, 0x93, 0xA0, 0x02, 0xDD, 0xCC, 0xE2, 0xF2, 0xBB, 0xFB, 0xE0,
  44729. 0x27, 0xD7, 0x34, 0x9A, 0x71, 0x49, 0xB5, 0x4F, 0x42, 0x1F, 0xB2, 0x9D, 0x6D,
  44730. 0xAA, 0x9D, 0xD3, 0x50, 0xB5, 0x8F, 0x6A, 0x4B, 0xDF, 0x1F, 0xD5, 0x27, 0x8F,
  44731. 0x3B, 0x27, 0xCF, 0x2F, 0x8C, 0xF8, 0x9D, 0x4C, 0x52, 0xBC, 0x32, 0x0F, 0x73,
  44732. 0xD5, 0x51, 0x8E, 0x36, 0x7E, 0xAD, 0x09, 0xF0, 0x94, 0x83, 0x5F, 0x36, 0xFD,
  44733. 0x7C, 0x03, 0xED, 0xF1, 0x5E, 0x4B, 0xF7, 0xAA, 0x55, 0x5C, 0x4A, 0x14, 0x59,
  44734. 0x85, 0x38, 0x2D, 0x8C, 0xDF, 0xEC, 0x65, 0x1B, 0xB8, 0x76, 0x57, 0x96, 0x3C,
  44735. 0x86, 0xED, 0xF2, 0x7F, 0x2D, 0x28, 0x48, 0xDA, 0x49, 0x7F, 0xF7, 0x54, 0x2B,
  44736. 0xD5, 0x39, 0xD5, 0x57, 0x0A, 0x75, 0x7A, 0x3E, 0x5E, 0x5D, 0xBA, 0x4A, 0x15,
  44737. 0xFA, 0xB8, 0x31, 0x80, 0x71, 0x2C, 0xCA, 0xC4, 0x51, 0x10, 0x16, 0x5D, 0x39,
  44738. 0xEC, 0x9D, 0x07, 0xB6, 0x6A, 0x89, 0x9F, 0x9B, 0x5B, 0x6F, 0x03, 0xB0, 0x92,
  44739. 0x01, 0x38, 0x6B, 0x48, 0x99, 0x0A, 0x8F, 0x13, 0xC1, 0xA6, 0x01, 0xEA, 0xBF,
  44740. 0x6F, 0x86, 0x43, 0x51, 0xB6, 0x11, 0x00, 0x00
  44741. };
  44742. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void)
  44743. {
  44744. wc_test_ret_t ret = 0;
  44745. word32 dSz = sizeof(sample_text);
  44746. word32 cSz = (dSz + (word32)(dSz * 0.001) + 12);
  44747. byte *c;
  44748. byte *d;
  44749. WOLFSSL_ENTER("compress_test");
  44750. c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44751. d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44752. if (c == NULL || d == NULL) {
  44753. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  44754. }
  44755. /* follow calloc and initialize to 0 */
  44756. XMEMSET(c, 0, cSz);
  44757. XMEMSET(d, 0, dSz);
  44758. if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) {
  44759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44760. }
  44761. cSz = (word32)ret;
  44762. if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) {
  44763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44764. }
  44765. dSz = (word32)ret;
  44766. if (XMEMCMP(d, sample_text, dSz) != 0) {
  44767. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  44768. }
  44769. /* GZIP tests */
  44770. cSz = (dSz + (word32)(dSz * 0.001) + 12); /* reset cSz */
  44771. XMEMSET(c, 0, cSz);
  44772. XMEMSET(d, 0, dSz);
  44773. ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP);
  44774. if (ret < 0)
  44775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44776. cSz = (word32)ret;
  44777. ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP);
  44778. if (ret < 0)
  44779. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44780. if (XMEMCMP(d, sample_text, dSz) != 0) {
  44781. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  44782. }
  44783. /* Try with gzip generated output */
  44784. XMEMSET(d, 0, dSz);
  44785. ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz),
  44786. LIBZ_WINBITS_GZIP);
  44787. if (ret < 0)
  44788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44789. dSz = (word32)ret;
  44790. if (XMEMCMP(d, sample_text, dSz) != 0) {
  44791. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  44792. }
  44793. ret = 0; /* success */
  44794. exit:
  44795. XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44796. XFREE(d, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44797. return ret;
  44798. }
  44799. #endif /* HAVE_LIBZ */
  44800. #ifdef HAVE_PKCS7
  44801. /* External Debugging/Testing Note:
  44802. *
  44803. * PKCS#7 test functions can output generated PKCS#7/CMS bundles for
  44804. * additional testing. To dump bundles to files DER encoded files, please
  44805. * define:
  44806. *
  44807. * #define PKCS7_OUTPUT_TEST_BUNDLES
  44808. */
  44809. /* Loads certs and keys for use with PKCS7 tests, from either files
  44810. * or buffers.
  44811. *
  44812. * rsaClientCertBuf - output buffer for RSA client cert
  44813. * rsaClientCertBufSz - IN/OUT size of output buffer, size of RSA client cert
  44814. * rsaClientPrivKeyBuf - output buffer for RSA client private key
  44815. * rsaClientPrivKeyBufSz - IN/OUT size of output buffer, size of RSA client key
  44816. *
  44817. * rsaServerCertBuf - output buffer for RSA server cert
  44818. * rsaServerCertBufSz - IN/OUT size of output buffer, size of RSA server cert
  44819. * rsaServerPrivKeyBuf - output buffer for RSA server private key
  44820. * rsaServerPrivKeyBufSz - IN/OUT size of output buffer, size of RSA server key
  44821. *
  44822. * rsaCaCertBuf - output buffer for RSA CA cert
  44823. * rsaCaCertBufSz - IN/OUT size of output buffer, size of RSA ca cert
  44824. * rsaCaPrivKeyBuf - output buffer for RSA CA private key
  44825. * rsaCaPrivKeyBufSz - IN/OUT size of output buffer, size of RSA CA key
  44826. *
  44827. * eccClientCertBuf - output buffer for ECC cert
  44828. * eccClientCertBufSz - IN/OUT size of output buffer, size of ECC cert
  44829. * eccClientPrivKeyBuf - output buffer for ECC private key
  44830. * eccClientPrivKeyBufSz - IN/OUT size of output buffer, size of ECC private key
  44831. *
  44832. * Returns 0 on success, negative on error
  44833. */
  44834. static wc_test_ret_t pkcs7_load_certs_keys(
  44835. byte* rsaClientCertBuf, word32* rsaClientCertBufSz,
  44836. byte* rsaClientPrivKeyBuf, word32* rsaClientPrivKeyBufSz,
  44837. byte* rsaServerCertBuf, word32* rsaServerCertBufSz,
  44838. byte* rsaServerPrivKeyBuf, word32* rsaServerPrivKeyBufSz,
  44839. byte* rsaCaCertBuf, word32* rsaCaCertBufSz,
  44840. byte* rsaCaPrivKeyBuf, word32* rsaCaPrivKeyBufSz,
  44841. byte* eccClientCertBuf, word32* eccClientCertBufSz,
  44842. byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz)
  44843. {
  44844. #ifndef NO_FILESYSTEM
  44845. XFILE certFile;
  44846. XFILE keyFile;
  44847. (void)certFile;
  44848. (void)keyFile;
  44849. #endif
  44850. #ifndef NO_RSA
  44851. if (rsaClientCertBuf == NULL || rsaClientCertBufSz == NULL ||
  44852. rsaClientPrivKeyBuf == NULL || rsaClientPrivKeyBufSz == NULL)
  44853. return BAD_FUNC_ARG;
  44854. #endif
  44855. #ifdef HAVE_ECC
  44856. if (eccClientCertBuf == NULL || eccClientCertBufSz == NULL ||
  44857. eccClientPrivKeyBuf == NULL || eccClientPrivKeyBufSz == NULL)
  44858. return BAD_FUNC_ARG;
  44859. #endif
  44860. /* RSA */
  44861. #ifndef NO_RSA
  44862. #ifdef USE_CERT_BUFFERS_1024
  44863. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024)
  44864. return WC_TEST_RET_ENC_NC;
  44865. XMEMCPY(rsaClientCertBuf, client_cert_der_1024,
  44866. sizeof_client_cert_der_1024);
  44867. *rsaClientCertBufSz = sizeof_client_cert_der_1024;
  44868. if (rsaServerCertBuf != NULL) {
  44869. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024)
  44870. return WC_TEST_RET_ENC_NC;
  44871. XMEMCPY(rsaServerCertBuf, server_cert_der_1024,
  44872. sizeof_server_cert_der_1024);
  44873. *rsaServerCertBufSz = sizeof_server_cert_der_1024;
  44874. }
  44875. if (rsaCaCertBuf != NULL) {
  44876. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024)
  44877. return WC_TEST_RET_ENC_NC;
  44878. XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  44879. *rsaCaCertBufSz = sizeof_ca_cert_der_1024;
  44880. }
  44881. #elif defined(USE_CERT_BUFFERS_2048)
  44882. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048)
  44883. return WC_TEST_RET_ENC_NC;
  44884. XMEMCPY(rsaClientCertBuf, client_cert_der_2048,
  44885. sizeof_client_cert_der_2048);
  44886. *rsaClientCertBufSz = sizeof_client_cert_der_2048;
  44887. if (rsaServerCertBuf != NULL) {
  44888. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048)
  44889. return WC_TEST_RET_ENC_NC;
  44890. XMEMCPY(rsaServerCertBuf, server_cert_der_2048,
  44891. sizeof_server_cert_der_2048);
  44892. *rsaServerCertBufSz = sizeof_server_cert_der_2048;
  44893. }
  44894. if (rsaCaCertBuf != NULL) {
  44895. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048)
  44896. return WC_TEST_RET_ENC_NC;
  44897. XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  44898. *rsaCaCertBufSz = sizeof_ca_cert_der_2048;
  44899. }
  44900. #else
  44901. certFile = XFOPEN(clientCert, "rb");
  44902. if (!certFile)
  44903. return WC_TEST_RET_ENC_ERRNO;
  44904. *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1,
  44905. *rsaClientCertBufSz, certFile);
  44906. XFCLOSE(certFile);
  44907. if (*rsaClientCertBufSz == 0)
  44908. return WC_TEST_RET_ENC_ERRNO;
  44909. if (rsaServerCertBuf != NULL) {
  44910. certFile = XFOPEN(rsaServerCertDerFile, "rb");
  44911. if (!certFile)
  44912. return WC_TEST_RET_ENC_ERRNO;
  44913. *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1,
  44914. *rsaServerCertBufSz, certFile);
  44915. XFCLOSE(certFile);
  44916. if (*rsaServerCertBufSz == 0)
  44917. return WC_TEST_RET_ENC_ERRNO;
  44918. }
  44919. if (rsaCaCertBuf != NULL) {
  44920. certFile = XFOPEN(rsaCaCertDerFile, "rb");
  44921. if (!certFile)
  44922. return WC_TEST_RET_ENC_ERRNO;
  44923. *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz,
  44924. certFile);
  44925. XFCLOSE(certFile);
  44926. if (*rsaCaCertBufSz == 0)
  44927. return WC_TEST_RET_ENC_ERRNO;
  44928. }
  44929. #endif
  44930. #ifdef USE_CERT_BUFFERS_1024
  44931. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024)
  44932. return WC_TEST_RET_ENC_NC;
  44933. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024,
  44934. sizeof_client_key_der_1024);
  44935. *rsaClientPrivKeyBufSz = sizeof_client_key_der_1024;
  44936. if (rsaServerPrivKeyBuf != NULL) {
  44937. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024)
  44938. return WC_TEST_RET_ENC_NC;
  44939. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024,
  44940. sizeof_server_key_der_1024);
  44941. *rsaServerPrivKeyBufSz = sizeof_server_key_der_1024;
  44942. }
  44943. if (rsaCaPrivKeyBuf != NULL) {
  44944. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024)
  44945. return WC_TEST_RET_ENC_NC;
  44946. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024);
  44947. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024;
  44948. }
  44949. #elif defined(USE_CERT_BUFFERS_2048)
  44950. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048)
  44951. return WC_TEST_RET_ENC_NC;
  44952. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048,
  44953. sizeof_client_key_der_2048);
  44954. *rsaClientPrivKeyBufSz = sizeof_client_key_der_2048;
  44955. if (rsaServerPrivKeyBuf != NULL) {
  44956. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048)
  44957. return WC_TEST_RET_ENC_NC;
  44958. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048,
  44959. sizeof_server_key_der_2048);
  44960. *rsaServerPrivKeyBufSz = sizeof_server_key_der_2048;
  44961. }
  44962. if (rsaCaPrivKeyBuf != NULL) {
  44963. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048)
  44964. return WC_TEST_RET_ENC_NC;
  44965. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048);
  44966. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048;
  44967. }
  44968. #else
  44969. keyFile = XFOPEN(clientKey, "rb");
  44970. if (!keyFile)
  44971. return WC_TEST_RET_ENC_ERRNO;
  44972. *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1,
  44973. *rsaClientPrivKeyBufSz, keyFile);
  44974. XFCLOSE(keyFile);
  44975. if (*rsaClientPrivKeyBufSz == 0)
  44976. return WC_TEST_RET_ENC_ERRNO;
  44977. if (rsaServerPrivKeyBuf != NULL) {
  44978. keyFile = XFOPEN(rsaServerKeyDerFile, "rb");
  44979. if (!keyFile)
  44980. return WC_TEST_RET_ENC_ERRNO;
  44981. *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1,
  44982. *rsaServerPrivKeyBufSz, keyFile);
  44983. XFCLOSE(keyFile);
  44984. if (*rsaServerPrivKeyBufSz == 0)
  44985. return WC_TEST_RET_ENC_ERRNO;
  44986. }
  44987. if (rsaCaPrivKeyBuf != NULL) {
  44988. keyFile = XFOPEN(rsaCaKeyFile, "rb");
  44989. if (!keyFile)
  44990. return WC_TEST_RET_ENC_ERRNO;
  44991. *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1,
  44992. *rsaCaPrivKeyBufSz, keyFile);
  44993. XFCLOSE(keyFile);
  44994. if (*rsaCaPrivKeyBufSz == 0)
  44995. return WC_TEST_RET_ENC_ERRNO;
  44996. }
  44997. #endif /* USE_CERT_BUFFERS */
  44998. #endif /* NO_RSA */
  44999. /* ECC */
  45000. #ifdef HAVE_ECC
  45001. #ifdef USE_CERT_BUFFERS_256
  45002. if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256)
  45003. return WC_TEST_RET_ENC_NC;
  45004. XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45005. *eccClientCertBufSz = sizeof_cliecc_cert_der_256;
  45006. #else
  45007. certFile = XFOPEN(eccClientCert, "rb");
  45008. if (!certFile)
  45009. return WC_TEST_RET_ENC_ERRNO;
  45010. *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1,
  45011. *eccClientCertBufSz, certFile);
  45012. XFCLOSE(certFile);
  45013. if (*eccClientCertBufSz == 0)
  45014. return WC_TEST_RET_ENC_ERRNO;
  45015. #endif /* USE_CERT_BUFFERS_256 */
  45016. #ifdef USE_CERT_BUFFERS_256
  45017. if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256)
  45018. return WC_TEST_RET_ENC_NC;
  45019. XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45020. *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256;
  45021. #else
  45022. keyFile = XFOPEN(eccClientKey, "rb");
  45023. if (!keyFile)
  45024. return WC_TEST_RET_ENC_ERRNO;
  45025. *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1,
  45026. *eccClientPrivKeyBufSz, keyFile);
  45027. XFCLOSE(keyFile);
  45028. if (*eccClientPrivKeyBufSz == 0)
  45029. return WC_TEST_RET_ENC_ERRNO;
  45030. #endif /* USE_CERT_BUFFERS_256 */
  45031. #endif /* HAVE_ECC */
  45032. #ifdef NO_RSA
  45033. (void)rsaClientCertBuf;
  45034. (void)rsaClientCertBufSz;
  45035. (void)rsaClientPrivKeyBuf;
  45036. (void)rsaClientPrivKeyBufSz;
  45037. (void)rsaServerCertBuf;
  45038. (void)rsaServerCertBufSz;
  45039. (void)rsaServerPrivKeyBuf;
  45040. (void)rsaServerPrivKeyBufSz;
  45041. (void)rsaCaCertBuf;
  45042. (void)rsaCaCertBufSz;
  45043. (void)rsaCaPrivKeyBuf;
  45044. (void)rsaCaPrivKeyBufSz;
  45045. #endif
  45046. #ifndef HAVE_ECC
  45047. (void)eccClientCertBuf;
  45048. (void)eccClientCertBufSz;
  45049. (void)eccClientPrivKeyBuf;
  45050. (void)eccClientPrivKeyBufSz;
  45051. #endif
  45052. #ifndef NO_FILESYSTEM
  45053. (void)certFile;
  45054. (void)keyFile;
  45055. #endif
  45056. return 0;
  45057. }
  45058. typedef struct {
  45059. const byte* content;
  45060. word32 contentSz;
  45061. int contentOID;
  45062. int encryptOID;
  45063. int keyWrapOID;
  45064. int keyAgreeOID;
  45065. byte* cert;
  45066. size_t certSz;
  45067. byte* privateKey;
  45068. word32 privateKeySz;
  45069. byte* optionalUkm;
  45070. word32 optionalUkmSz;
  45071. int ktriOptions; /* KTRI options flags */
  45072. int kariOptions; /* KARI options flags */
  45073. /* KEKRI specific */
  45074. const byte* secretKey; /* key, only for kekri RecipientInfo types */
  45075. word32 secretKeySz; /* size of secretKey, bytes */
  45076. const byte* secretKeyId; /* key identifier */
  45077. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45078. void* timePtr; /* time_t pointer */
  45079. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45080. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45081. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45082. word32 otherAttrSz; /* size of otherAttr, bytes */
  45083. int kekriOptions; /* KEKRI options flags */
  45084. /* PWRI specific */
  45085. const char* password;
  45086. word32 passwordSz;
  45087. const byte* salt;
  45088. word32 saltSz;
  45089. int kdfOID;
  45090. int hashOID;
  45091. int kdfIterations;
  45092. int pwriOptions; /* PWRI options flags */
  45093. /* ORI specific */
  45094. int isOri;
  45095. int oriOptions; /* ORI options flags */
  45096. const char* outFileName;
  45097. } pkcs7EnvelopedVector;
  45098. static const byte asnDataOid[] = {
  45099. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
  45100. };
  45101. /* ORI encrypt callback, responsible for encrypting content-encryption key (CEK)
  45102. * and giving wolfCrypt the value for oriOID and oriValue to place in
  45103. * OtherRecipientInfo.
  45104. *
  45105. * Returns 0 on success, negative upon error. */
  45106. static int myOriEncryptCb(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType,
  45107. word32* oriTypeSz, byte* oriValue, word32* oriValueSz,
  45108. void* ctx)
  45109. {
  45110. int i;
  45111. /* make sure buffers are large enough */
  45112. if (*oriValueSz < (2 + cekSz))
  45113. return WC_TEST_RET_ENC_NC;
  45114. if (*oriTypeSz < sizeof(asnDataOid))
  45115. return WC_TEST_RET_ENC_NC;
  45116. /* our simple encryption algorithm will be take the bitwise complement */
  45117. oriValue[0] = 0x04; /*ASN OCTET STRING */
  45118. oriValue[1] = (byte)cekSz; /* length */
  45119. for (i = 0; i < (int)cekSz; i++) {
  45120. oriValue[2 + i] = ~cek[i];
  45121. }
  45122. *oriValueSz = 2 + cekSz;
  45123. /* set oriType to ASN.1 encoded data OID */
  45124. XMEMCPY(oriType, asnDataOid, sizeof(asnDataOid));
  45125. *oriTypeSz = sizeof(asnDataOid);
  45126. (void)pkcs7;
  45127. (void)ctx;
  45128. return 0;
  45129. }
  45130. /* ORI decrypt callback, responsible for providing a decrypted content
  45131. * encryption key (CEK) placed into decryptedKey and size placed into
  45132. * decryptedKeySz. oriOID and oriValue are given to the callback to help
  45133. * in decrypting the encrypted CEK.
  45134. *
  45135. * Returns 0 on success, negative upon error. */
  45136. static int myOriDecryptCb(PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  45137. byte* oriValue, word32 oriValueSz, byte* decryptedKey,
  45138. word32* decryptedKeySz, void* ctx)
  45139. {
  45140. int i;
  45141. /* make sure oriType matches what we expect */
  45142. if (oriTypeSz != sizeof(asnDataOid))
  45143. return WC_TEST_RET_ENC_NC;
  45144. if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0)
  45145. return WC_TEST_RET_ENC_NC;
  45146. /* make sure decrypted buffer is large enough */
  45147. if (*decryptedKeySz < oriValueSz)
  45148. return WC_TEST_RET_ENC_NC;
  45149. /* decrypt encrypted CEK using simple bitwise complement,
  45150. only for example */
  45151. for (i = 0; i < (int)oriValueSz - 2; i++) {
  45152. decryptedKey[i] = ~oriValue[2 + i];
  45153. }
  45154. *decryptedKeySz = oriValueSz - 2;
  45155. (void)pkcs7;
  45156. (void)ctx;
  45157. return 0;
  45158. }
  45159. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45160. /* returns 0 on success */
  45161. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45162. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45163. byte* in, int inSz, byte* out, void* usrCtx)
  45164. {
  45165. wc_test_ret_t ret;
  45166. int keyId = -1, keySz;
  45167. word32 keyIdSz = 8;
  45168. const byte* key;
  45169. byte keyIdRaw[8];
  45170. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45171. Aes *aes;
  45172. #else
  45173. Aes aes[1];
  45174. #endif
  45175. /* looking for KEY ID
  45176. * fwDecryptKeyID OID "1.2.840.113549.1.9.16.2.37
  45177. */
  45178. WOLFSSL_SMALL_STACK_STATIC const unsigned char OID[] = {
  45179. /* 0x06, 0x0B do not pass in tag and length */
  45180. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  45181. 0x01, 0x09, 0x10, 0x02, 0x25
  45182. };
  45183. WOLFSSL_SMALL_STACK_STATIC const byte defKey[] = {
  45184. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45185. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45186. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45187. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45188. };
  45189. WOLFSSL_SMALL_STACK_STATIC const byte altKey[] = {
  45190. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45191. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45192. };
  45193. /* test user context passed in */
  45194. if (usrCtx == NULL || *(int*)usrCtx != 1) {
  45195. return WC_TEST_RET_ENC_NC;
  45196. }
  45197. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45198. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  45199. return WC_TEST_RET_ENC_ERRNO;
  45200. #endif
  45201. /* if needing to find keyIdSz can call with NULL */
  45202. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), NULL,
  45203. &keyIdSz);
  45204. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  45205. printf("Unexpected error %d when getting keyIdSz\n", ret);
  45206. printf("Possibly no KEY ID attribute set\n");
  45207. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45208. }
  45209. else {
  45210. XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw));
  45211. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw,
  45212. &keyIdSz);
  45213. if (ret < 0) {
  45214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45215. }
  45216. if (keyIdSz < 3) {
  45217. printf("keyIdSz is smaller than expected\n");
  45218. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45219. }
  45220. if (keyIdSz > 2 + sizeof(int)) {
  45221. printf("example case was only expecting a keyId of int size\n");
  45222. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45223. }
  45224. /* keyIdRaw[0] OCTET TAG */
  45225. /* keyIdRaw[1] Length */
  45226. #ifdef BIG_ENDIAN_ORDER
  45227. if (keyIdRaw[1] == 0x01) {
  45228. keyId = 1;
  45229. }
  45230. #else
  45231. XMEMCPY(&keyId, keyIdRaw + 2, sizeof(keyId));
  45232. #endif
  45233. }
  45234. /* Use keyID here if found to select key and decrypt in HSM or in this
  45235. * example just select key and do software decryption */
  45236. if (keyId == 1) {
  45237. key = altKey;
  45238. keySz = sizeof(altKey);
  45239. }
  45240. else {
  45241. key = defKey;
  45242. keySz = sizeof(defKey);
  45243. }
  45244. switch (encryptOID) {
  45245. #ifdef WOLFSSL_AES_256
  45246. case AES256CBCb:
  45247. if ((keySz != 32 ) || (ivSz != AES_BLOCK_SIZE))
  45248. WARNING_OUT(BAD_FUNC_ARG, out);
  45249. break;
  45250. #endif
  45251. #ifdef WOLFSSL_AES_128
  45252. case AES128CBCb:
  45253. if ((keySz != 16 ) || (ivSz != AES_BLOCK_SIZE))
  45254. ERROR_OUT(BAD_FUNC_ARG, out);
  45255. break;
  45256. #endif
  45257. default:
  45258. printf("Unsupported content cipher type for example");
  45259. ERROR_OUT(ALGO_ID_E, out);
  45260. };
  45261. ret = wc_AesInit(aes, HEAP_HINT, INVALID_DEVID);
  45262. if (ret == 0) {
  45263. ret = wc_AesSetKey(aes, key, (word32)keySz, iv, AES_DECRYPTION);
  45264. if (ret == 0)
  45265. ret = wc_AesCbcDecrypt(aes, out, in, (word32)inSz);
  45266. wc_AesFree(aes);
  45267. }
  45268. out:
  45269. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45270. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45271. #endif
  45272. (void)aad;
  45273. (void)aadSz;
  45274. (void)authTag;
  45275. (void)authTagSz;
  45276. return (int)ret;
  45277. }
  45278. #endif /* !NO_AES && HAVE_AES_CBC */
  45279. #define PKCS7_BUF_SIZE 2048
  45280. static wc_test_ret_t pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  45281. byte* rsaPrivKey, word32 rsaPrivKeySz,
  45282. byte* eccCert, word32 eccCertSz,
  45283. byte* eccPrivKey, word32 eccPrivKeySz)
  45284. {
  45285. wc_test_ret_t ret = 0;
  45286. int testSz = 0, i;
  45287. int envelopedSz, decodedSz;
  45288. byte *enveloped = NULL;
  45289. byte *decoded = NULL;
  45290. PKCS7* pkcs7 = NULL;
  45291. #ifdef ECC_TIMING_RESISTANT
  45292. WC_RNG rng;
  45293. #endif
  45294. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  45295. XFILE pkcs7File;
  45296. #endif
  45297. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  45298. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  45299. 0x72,0x6c,0x64
  45300. };
  45301. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256) && \
  45302. defined(HAVE_ECC) && defined(WOLFSSL_SHA512)
  45303. byte optionalUkm[] = {
  45304. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45305. };
  45306. #endif /* NO_AES */
  45307. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  45308. !defined(NO_SHA)
  45309. /* encryption key for kekri recipient types */
  45310. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  45311. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  45312. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45313. };
  45314. /* encryption key identifier */
  45315. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  45316. 0x02,0x02,0x03,0x04
  45317. };
  45318. #endif
  45319. #if !defined(NO_PWDBASED) && !defined(NO_SHA) && \
  45320. !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  45321. #ifndef HAVE_FIPS
  45322. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password"; /* NOTE: Password is too short for FIPS */
  45323. #else
  45324. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  45325. #endif
  45326. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  45327. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  45328. };
  45329. #endif
  45330. #define MAX_TESTVECTORS_LEN 13
  45331. #define ADD_PKCS7ENVELOPEDVECTOR(...) { \
  45332. pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \
  45333. if (testSz == MAX_TESTVECTORS_LEN) { \
  45334. ret = WC_TEST_RET_ENC_NC; \
  45335. goto out; \
  45336. } \
  45337. XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\
  45338. }
  45339. pkcs7EnvelopedVector *testVectors = NULL;
  45340. #ifdef ECC_TIMING_RESISTANT
  45341. XMEMSET(&rng, 0, sizeof(rng));
  45342. #endif
  45343. testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  45344. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45345. if (testVectors == NULL) {
  45346. ret = WC_TEST_RET_ENC_ERRNO;
  45347. goto out;
  45348. }
  45349. {
  45350. /* key transport key encryption technique */
  45351. #ifndef NO_RSA
  45352. #ifndef NO_DES3
  45353. ADD_PKCS7ENVELOPEDVECTOR(
  45354. data, (word32)sizeof(data), DATA, DES3b, 0, 0, rsaCert, rsaCertSz,
  45355. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45356. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45357. "pkcs7envelopedDataDES3.der");
  45358. #endif
  45359. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45360. #ifdef WOLFSSL_AES_128
  45361. ADD_PKCS7ENVELOPEDVECTOR(
  45362. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, rsaCert, rsaCertSz,
  45363. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45364. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45365. "pkcs7envelopedDataAES128CBC.der");
  45366. #endif
  45367. #ifdef WOLFSSL_AES_192
  45368. ADD_PKCS7ENVELOPEDVECTOR(
  45369. data, (word32)sizeof(data), DATA, AES192CBCb, 0, 0, rsaCert, rsaCertSz,
  45370. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45371. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45372. "pkcs7envelopedDataAES192CBC.der");
  45373. #endif
  45374. #ifdef WOLFSSL_AES_256
  45375. ADD_PKCS7ENVELOPEDVECTOR(
  45376. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45377. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45378. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45379. "pkcs7envelopedDataAES256CBC.der");
  45380. /* explicitly using SKID for SubjectKeyIdentifier */
  45381. ADD_PKCS7ENVELOPEDVECTOR(
  45382. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45383. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_SKID, 0, NULL, 0, NULL, 0, NULL,
  45384. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45385. "pkcs7envelopedDataAES256CBC_SKID.der");
  45386. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  45387. ADD_PKCS7ENVELOPEDVECTOR(
  45388. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45389. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_ISSUER_AND_SERIAL_NUMBER, 0,
  45390. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  45391. 0, 0, 0, 0, "pkcs7envelopedDataAES256CBC_IANDS.der");
  45392. #endif
  45393. #endif /* !NO_AES && HAVE_AES_CBC */
  45394. #endif
  45395. /* key agreement key encryption technique*/
  45396. #ifdef HAVE_ECC
  45397. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45398. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45399. ADD_PKCS7ENVELOPEDVECTOR(
  45400. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP,
  45401. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45402. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45403. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45404. "pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der");
  45405. #endif
  45406. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  45407. ADD_PKCS7ENVELOPEDVECTOR(
  45408. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45409. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45410. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45411. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45412. "pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der");
  45413. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  45414. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  45415. ADD_PKCS7ENVELOPEDVECTOR(
  45416. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45417. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45418. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45419. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45420. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der");
  45421. /* with optional user keying material (ukm) */
  45422. ADD_PKCS7ENVELOPEDVECTOR(
  45423. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45424. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45425. eccPrivKeySz, optionalUkm, sizeof(optionalUkm), 0, 0, NULL, 0,
  45426. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45427. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF_ukm.der");
  45428. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  45429. #endif /* !NO_AES && HAVE_AES_CBC */
  45430. #endif
  45431. /* kekri (KEKRecipientInfo) recipient types */
  45432. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45433. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45434. ADD_PKCS7ENVELOPEDVECTOR(
  45435. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP, 0,
  45436. NULL, 0, NULL, 0, NULL, 0, 0, 0, secretKey, sizeof(secretKey),
  45437. secretKeyId, sizeof(secretKeyId), NULL, NULL, 0, NULL, 0,
  45438. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45439. "pkcs7envelopedDataAES128CBC_KEKRI.der");
  45440. #endif
  45441. #endif /* !NO_AES && HAVE_AES_CBC */
  45442. /* pwri (PasswordRecipientInfo) recipient types */
  45443. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  45444. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45445. ADD_PKCS7ENVELOPEDVECTOR(
  45446. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0,
  45447. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45448. NULL, 0, NULL, NULL, 0, NULL, 0, 0, password,
  45449. (word32)XSTRLEN(password), salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  45450. 0, 0, 0, "pkcs7envelopedDataAES128CBC_PWRI.der");
  45451. #endif
  45452. #endif
  45453. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_128)
  45454. /* ori (OtherRecipientInfo) recipient types */
  45455. ADD_PKCS7ENVELOPEDVECTOR(
  45456. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, NULL, 0, NULL, 0,
  45457. NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0,
  45458. NULL, 0, 0, 0, 0, 0, 1, 0, "pkcs7envelopedDataAES128CBC_ORI.der");
  45459. #endif
  45460. };
  45461. #undef MAX_TESTVECTORS_LEN
  45462. #undef ADD_PKCS7ENVELOPEDVECTOR
  45463. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45464. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45465. if ((! enveloped) || (! decoded)) {
  45466. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45467. }
  45468. #ifdef ECC_TIMING_RESISTANT
  45469. #ifndef HAVE_FIPS
  45470. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  45471. #else
  45472. ret = wc_InitRng(&rng);
  45473. #endif
  45474. if (ret != 0)
  45475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45476. #endif
  45477. for (i = 0; i < testSz; i++) {
  45478. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  45479. #ifdef WOLFSSL_ASYNC_CRYPT
  45480. INVALID_DEVID /* async PKCS7 is not supported */
  45481. #else
  45482. devId
  45483. #endif
  45484. );
  45485. if (pkcs7 == NULL) {
  45486. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  45487. }
  45488. if (testVectors[i].secretKey != NULL) {
  45489. /* KEKRI recipient type */
  45490. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45491. if (ret != 0)
  45492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45493. pkcs7->content = (byte*)testVectors[i].content;
  45494. pkcs7->contentSz = testVectors[i].contentSz;
  45495. pkcs7->contentOID = testVectors[i].contentOID;
  45496. pkcs7->encryptOID = testVectors[i].encryptOID;
  45497. pkcs7->ukm = testVectors[i].optionalUkm;
  45498. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45499. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  45500. (byte *)testVectors[i].secretKey, testVectors[i].secretKeySz,
  45501. (byte *)testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  45502. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  45503. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  45504. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  45505. if (ret < 0) {
  45506. wc_PKCS7_Free(pkcs7);
  45507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45508. }
  45509. /* set key, for decryption */
  45510. ret = wc_PKCS7_SetKey(pkcs7, (byte *)testVectors[i].secretKey,
  45511. testVectors[i].secretKeySz);
  45512. if (ret != 0) {
  45513. wc_PKCS7_Free(pkcs7);
  45514. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45515. }
  45516. } else if (testVectors[i].password != NULL) {
  45517. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  45518. /* PWRI recipient type */
  45519. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45520. if (ret != 0)
  45521. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45522. pkcs7->content = (byte*)testVectors[i].content;
  45523. pkcs7->contentSz = testVectors[i].contentSz;
  45524. pkcs7->contentOID = testVectors[i].contentOID;
  45525. pkcs7->encryptOID = testVectors[i].encryptOID;
  45526. pkcs7->ukm = testVectors[i].optionalUkm;
  45527. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45528. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  45529. (byte *)testVectors[i].password, testVectors[i].passwordSz,
  45530. (byte *)testVectors[i].salt, testVectors[i].saltSz,
  45531. testVectors[i].kdfOID,
  45532. testVectors[i].hashOID, testVectors[i].kdfIterations,
  45533. testVectors[i].encryptOID, testVectors[i].pwriOptions);
  45534. if (ret < 0) {
  45535. wc_PKCS7_Free(pkcs7);
  45536. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45537. }
  45538. /* set password, for decryption */
  45539. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  45540. testVectors[i].passwordSz);
  45541. if (ret < 0) {
  45542. wc_PKCS7_Free(pkcs7);
  45543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45544. }
  45545. #endif /* ! NO_PWDBASED && ! NO_SHA */
  45546. } else if (testVectors[i].isOri == 1) {
  45547. /* ORI recipient type */
  45548. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45549. if (ret != 0)
  45550. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45551. pkcs7->content = (byte*)testVectors[i].content;
  45552. pkcs7->contentSz = testVectors[i].contentSz;
  45553. pkcs7->contentOID = testVectors[i].contentOID;
  45554. pkcs7->encryptOID = testVectors[i].encryptOID;
  45555. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  45556. testVectors[i].oriOptions);
  45557. if (ret < 0) {
  45558. wc_PKCS7_Free(pkcs7);
  45559. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45560. }
  45561. /* set decrypt callback for decryption */
  45562. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  45563. if (ret < 0) {
  45564. wc_PKCS7_Free(pkcs7);
  45565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45566. }
  45567. } else {
  45568. /* KTRI or KARI recipient types */
  45569. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45570. if (ret != 0)
  45571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45572. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  45573. (word32)testVectors[i].certSz);
  45574. if (ret != 0) {
  45575. wc_PKCS7_Free(pkcs7);
  45576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45577. }
  45578. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  45579. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  45580. pkcs7->privateKey = testVectors[i].privateKey;
  45581. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  45582. pkcs7->content = (byte*)testVectors[i].content;
  45583. pkcs7->contentSz = testVectors[i].contentSz;
  45584. pkcs7->contentOID = testVectors[i].contentOID;
  45585. pkcs7->encryptOID = testVectors[i].encryptOID;
  45586. pkcs7->ukm = testVectors[i].optionalUkm;
  45587. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45588. /* set SubjectIdentifier type for KTRI types */
  45589. if (testVectors[i].ktriOptions & CMS_SKID) {
  45590. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  45591. if (ret != 0) {
  45592. wc_PKCS7_Free(pkcs7);
  45593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45594. }
  45595. } else if (testVectors[i].ktriOptions &
  45596. CMS_ISSUER_AND_SERIAL_NUMBER) {
  45597. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  45598. CMS_ISSUER_AND_SERIAL_NUMBER);
  45599. if (ret != 0) {
  45600. wc_PKCS7_Free(pkcs7);
  45601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45602. }
  45603. }
  45604. }
  45605. #ifdef ECC_TIMING_RESISTANT
  45606. pkcs7->rng = &rng;
  45607. #endif
  45608. /* encode envelopedData */
  45609. envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, enveloped,
  45610. PKCS7_BUF_SIZE);
  45611. if (envelopedSz <= 0) {
  45612. wc_PKCS7_Free(pkcs7);
  45613. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  45614. }
  45615. /* decode envelopedData */
  45616. pkcs7->contentOID = 0;
  45617. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, (word32)envelopedSz,
  45618. decoded, PKCS7_BUF_SIZE);
  45619. if (pkcs7->contentOID != testVectors[i].contentOID ||
  45620. decodedSz <= 0) {
  45621. wc_PKCS7_Free(pkcs7);
  45622. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  45623. }
  45624. /* test decode result */
  45625. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  45626. wc_PKCS7_Free(pkcs7);
  45627. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45628. }
  45629. #ifndef NO_PKCS7_STREAM
  45630. { /* test reading byte by byte */
  45631. int z;
  45632. for (z = 0; z < envelopedSz; z++) {
  45633. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped + z, 1,
  45634. decoded, PKCS7_BUF_SIZE);
  45635. if (decodedSz <= 0 &&
  45636. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  45637. {
  45638. printf("unexpected error %d\n", decodedSz);
  45639. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  45640. }
  45641. }
  45642. /* test decode result */
  45643. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  45644. printf("stream read compare failed\n");
  45645. wc_PKCS7_Free(pkcs7);
  45646. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45647. }
  45648. }
  45649. #endif
  45650. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  45651. /* output pkcs7 envelopedData for external testing */
  45652. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  45653. if (!pkcs7File) {
  45654. wc_PKCS7_Free(pkcs7);
  45655. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  45656. }
  45657. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  45658. XFCLOSE(pkcs7File);
  45659. if (ret != envelopedSz) {
  45660. wc_PKCS7_Free(pkcs7);
  45661. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  45662. } else {
  45663. /* reset ret to 0 for success */
  45664. ret = 0;
  45665. }
  45666. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  45667. wc_PKCS7_Free(pkcs7);
  45668. pkcs7 = NULL;
  45669. }
  45670. #ifdef ECC_TIMING_RESISTANT
  45671. wc_FreeRng(&rng);
  45672. #endif
  45673. (void)eccCert;
  45674. (void)eccCertSz;
  45675. (void)eccPrivKey;
  45676. (void)eccPrivKeySz;
  45677. (void)rsaCert;
  45678. (void)rsaCertSz;
  45679. (void)rsaPrivKey;
  45680. (void)rsaPrivKeySz;
  45681. out:
  45682. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45683. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45684. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45685. return ret;
  45686. }
  45687. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void)
  45688. {
  45689. wc_test_ret_t ret = 0;
  45690. byte* rsaCert = NULL;
  45691. byte* rsaPrivKey = NULL;
  45692. word32 rsaCertSz = 0;
  45693. word32 rsaPrivKeySz = 0;
  45694. byte* eccCert = NULL;
  45695. byte* eccPrivKey = NULL;
  45696. word32 eccCertSz = 0;
  45697. word32 eccPrivKeySz = 0;
  45698. WOLFSSL_ENTER("pkcs7enveloped_test");
  45699. #ifndef NO_RSA
  45700. /* read client RSA cert and key in DER format */
  45701. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45702. if (rsaCert == NULL)
  45703. return WC_TEST_RET_ENC_ERRNO;
  45704. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45705. if (rsaPrivKey == NULL) {
  45706. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45707. return WC_TEST_RET_ENC_NC;
  45708. }
  45709. rsaCertSz = FOURK_BUF;
  45710. rsaPrivKeySz = FOURK_BUF;
  45711. #endif /* NO_RSA */
  45712. #ifdef HAVE_ECC
  45713. /* read client ECC cert and key in DER format */
  45714. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45715. if (eccCert == NULL) {
  45716. #ifndef NO_RSA
  45717. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45718. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45719. #endif
  45720. return WC_TEST_RET_ENC_NC;
  45721. }
  45722. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45723. if (eccPrivKey == NULL) {
  45724. #ifndef NO_RSA
  45725. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45726. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45727. #endif
  45728. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45729. return WC_TEST_RET_ENC_NC;
  45730. }
  45731. eccCertSz = FOURK_BUF;
  45732. eccPrivKeySz = FOURK_BUF;
  45733. #endif /* HAVE_ECC */
  45734. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  45735. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  45736. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  45737. eccPrivKey, &eccPrivKeySz);
  45738. if (ret < 0) {
  45739. #ifndef NO_RSA
  45740. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45741. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45742. #endif
  45743. #ifdef HAVE_ECC
  45744. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45745. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45746. #endif
  45747. return WC_TEST_RET_ENC_EC(ret);
  45748. }
  45749. ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  45750. rsaPrivKey, (word32)rsaPrivKeySz,
  45751. eccCert, (word32)eccCertSz,
  45752. eccPrivKey, (word32)eccPrivKeySz);
  45753. #ifndef NO_RSA
  45754. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45755. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45756. #endif
  45757. #ifdef HAVE_ECC
  45758. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45759. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45760. #endif
  45761. return ret;
  45762. }
  45763. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  45764. typedef struct {
  45765. const byte* content;
  45766. word32 contentSz;
  45767. int contentOID;
  45768. int encryptOID;
  45769. int keyWrapOID;
  45770. int keyAgreeOID;
  45771. byte* cert;
  45772. size_t certSz;
  45773. byte* privateKey;
  45774. word32 privateKeySz;
  45775. PKCS7Attrib* authAttribs;
  45776. word32 authAttribsSz;
  45777. PKCS7Attrib* unauthAttribs;
  45778. word32 unauthAttribsSz;
  45779. /* KARI / KTRI specific */
  45780. byte* optionalUkm;
  45781. word32 optionalUkmSz;
  45782. int ktriOptions; /* KTRI options flags */
  45783. int kariOptions; /* KARI options flags */
  45784. /* KEKRI specific */
  45785. byte* secretKey; /* key, only for kekri RecipientInfo types */
  45786. word32 secretKeySz; /* size of secretKey, bytes */
  45787. byte* secretKeyId; /* key identifier */
  45788. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45789. void* timePtr; /* time_t pointer */
  45790. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45791. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45792. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45793. word32 otherAttrSz; /* size of otherAttr, bytes */
  45794. int kekriOptions; /* KEKRI options flags */
  45795. /* PWRI specific */
  45796. char* password; /* password */
  45797. word32 passwordSz; /* password size, bytes */
  45798. byte* salt; /* KDF salt */
  45799. word32 saltSz; /* KDF salt size, bytes */
  45800. int kdfOID; /* KDF OID */
  45801. int hashOID; /* KDF hash algorithm OID */
  45802. int kdfIterations; /* KDF iterations */
  45803. int kekEncryptOID; /* KEK encryption algorithm OID */
  45804. int pwriOptions; /* PWRI options flags */
  45805. /* ORI specific */
  45806. int isOri;
  45807. int oriOptions; /* ORI options flags */
  45808. const char* outFileName;
  45809. } pkcs7AuthEnvelopedVector;
  45810. static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  45811. byte* rsaPrivKey, word32 rsaPrivKeySz,
  45812. byte* eccCert, word32 eccCertSz,
  45813. byte* eccPrivKey, word32 eccPrivKeySz)
  45814. {
  45815. wc_test_ret_t ret = 0;
  45816. int testSz = 0, i;
  45817. int envelopedSz, decodedSz;
  45818. byte *enveloped = NULL;
  45819. byte *decoded = NULL;
  45820. WC_RNG rng;
  45821. PKCS7* pkcs7;
  45822. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  45823. XFILE pkcs7File;
  45824. #endif
  45825. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  45826. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  45827. 0x72,0x6c,0x64
  45828. };
  45829. byte senderNonce[PKCS7_NONCE_SZ + 2];
  45830. #ifdef HAVE_ECC
  45831. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  45832. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  45833. WOLFSSL_SMALL_STACK_STATIC const byte senderNonceOid[] =
  45834. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  45835. 0x09, 0x05 };
  45836. PKCS7Attrib attribs[] =
  45837. {
  45838. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  45839. sizeof(senderNonce) }
  45840. };
  45841. #endif
  45842. #endif
  45843. #endif
  45844. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \
  45845. defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM)
  45846. WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = {
  45847. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45848. };
  45849. #endif /* NO_AES */
  45850. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45851. /* encryption key for kekri recipient types */
  45852. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  45853. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  45854. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45855. };
  45856. /* encryption key identifier */
  45857. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  45858. 0x02,0x02,0x03,0x04
  45859. };
  45860. #endif
  45861. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  45862. !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  45863. #ifndef HAVE_FIPS
  45864. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password";
  45865. #else
  45866. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  45867. #endif
  45868. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  45869. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  45870. };
  45871. #endif
  45872. #define MAX_TESTVECTORS_LEN 20
  45873. #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \
  45874. pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \
  45875. if (testSz == MAX_TESTVECTORS_LEN) { \
  45876. ret = WC_TEST_RET_ENC_NC; \
  45877. goto out; \
  45878. } \
  45879. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  45880. sizeof _this_vector); \
  45881. }
  45882. pkcs7AuthEnvelopedVector *testVectors = NULL;
  45883. XMEMSET(&rng, 0, sizeof(rng));
  45884. testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  45885. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45886. if (testVectors == NULL) {
  45887. ret = WC_TEST_RET_ENC_ERRNO;
  45888. goto out;
  45889. }
  45890. {
  45891. /* key transport key encryption technique */
  45892. #ifndef NO_RSA
  45893. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  45894. #ifdef WOLFSSL_AES_128
  45895. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45896. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, rsaCert, rsaCertSz,
  45897. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45898. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  45899. 0, 0, "pkcs7authEnvelopedDataAES128GCM.der");
  45900. #endif
  45901. #ifdef WOLFSSL_AES_192
  45902. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45903. data, (word32)sizeof(data), DATA, AES192GCMb, 0, 0, rsaCert, rsaCertSz,
  45904. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45905. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  45906. 0, 0, "pkcs7authEnvelopedDataAES192GCM.der");
  45907. #endif
  45908. #ifdef WOLFSSL_AES_256
  45909. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45910. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  45911. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45912. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  45913. 0, 0, "pkcs7authEnvelopedDataAES256GCM.der");
  45914. /* test with contentType set to FirmwarePkgData */
  45915. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45916. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, 0, 0,
  45917. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL,
  45918. 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL,
  45919. 0, 0, 0, 0, 0, 0, 0, 0,
  45920. "pkcs7authEnvelopedDataAES256GCM_firmwarePkgData.der");
  45921. /* explicitly using SKID for SubjectKeyIdentifier */
  45922. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45923. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  45924. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, CMS_SKID, 0,
  45925. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  45926. 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_SKID.der");
  45927. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  45928. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45929. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  45930. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0,
  45931. CMS_ISSUER_AND_SERIAL_NUMBER, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  45932. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  45933. "pkcs7authEnvelopedDataAES256GCM_IANDS.der");
  45934. #endif
  45935. #else /* NO_AES || !HAVE_AESGCM */
  45936. (void)rsaCert;
  45937. (void)rsaCertSz;
  45938. (void)rsaPrivKey;
  45939. (void)rsaPrivKeySz;
  45940. #endif /* NO_AES || !HAVE_AESGCM */
  45941. #endif
  45942. /* key agreement key encryption technique*/
  45943. #ifdef HAVE_ECC
  45944. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  45945. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45946. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45947. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP,
  45948. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45949. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  45950. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  45951. "pkcs7authEnvelopedDataAES128GCM_ECDH_SHA1KDF.der");
  45952. #endif
  45953. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  45954. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45955. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  45956. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45957. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  45958. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  45959. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF.der");
  45960. /* with authenticated attributes */
  45961. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45962. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  45963. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45964. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  45965. NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45966. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  45967. 0, 0, 0,
  45968. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_authAttribs.der");
  45969. /* with unauthenticated attributes */
  45970. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45971. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  45972. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45973. eccPrivKeySz, NULL, 0, attribs,
  45974. (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0, NULL, 0,
  45975. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  45976. 0, 0, 0,
  45977. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_unauthAttribs.der");
  45978. /* with authenticated AND unauthenticated attributes */
  45979. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45980. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  45981. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45982. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  45983. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  45984. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  45985. 0, 0, 0, 0, 0, 0,
  45986. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_bothAttribs.der");
  45987. /* with authenticated AND unauthenticated attributes AND
  45988. * contentType of FirmwarePkgData */
  45989. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45990. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, AES256_WRAP,
  45991. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45992. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  45993. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  45994. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  45995. 0, 0, 0, 0, 0, 0,
  45996. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_fw_bothAttribs.der");
  45997. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  45998. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  45999. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46000. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46001. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46002. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL,
  46003. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46004. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF.der");
  46005. /* with optional user keying material (ukm) */
  46006. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46007. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46008. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46009. eccPrivKeySz, NULL, 0, NULL, 0, (byte *)optionalUkm, sizeof(optionalUkm), 0,
  46010. 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46011. 0, 0, 0, 0, 0, 0,
  46012. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF_ukm.der");
  46013. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46014. #endif /* NO_AES */
  46015. #endif
  46016. /* kekri (KEKRecipientInfo) recipient types */
  46017. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46018. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46019. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46020. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP, 0,
  46021. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0,
  46022. (byte *)secretKey, sizeof(secretKey), (byte *)secretKeyId, sizeof(secretKeyId),
  46023. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46024. "pkcs7authEnvelopedDataAES128GCM_KEKRI.der");
  46025. #endif
  46026. #endif
  46027. /* pwri (PasswordRecipientInfo) recipient types */
  46028. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM)
  46029. #if !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46030. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46031. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0,
  46032. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46033. NULL, 0, NULL, NULL, 0, NULL, 0, 0, (char *)password,
  46034. (word32)XSTRLEN(password), (byte *)salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46035. AES128CBCb, 0, 0, 0, "pkcs7authEnvelopedDataAES128GCM_PWRI.der");
  46036. #endif
  46037. #endif
  46038. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46039. #ifdef WOLFSSL_AES_128
  46040. /* ori (OtherRecipientInfo) recipient types */
  46041. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46042. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, NULL, 0, NULL, 0,
  46043. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46044. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0,
  46045. "pkcs7authEnvelopedDataAES128GCM_ORI.der");
  46046. #endif
  46047. #endif
  46048. }
  46049. #undef MAX_TESTVECTORS_LEN
  46050. #undef ADD_PKCS7AUTHENVELOPEDVECTOR
  46051. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46052. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46053. if ((! enveloped) || (! decoded)) {
  46054. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46055. }
  46056. /* generate senderNonce */
  46057. {
  46058. #ifndef HAVE_FIPS
  46059. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46060. #else
  46061. ret = wc_InitRng(&rng);
  46062. #endif
  46063. if (ret != 0)
  46064. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46065. senderNonce[0] = 0x04;
  46066. senderNonce[1] = PKCS7_NONCE_SZ;
  46067. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  46068. if (ret != 0) {
  46069. wc_FreeRng(&rng);
  46070. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46071. }
  46072. }
  46073. for (i = 0; i < testSz; i++) {
  46074. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46075. #ifdef WOLFSSL_ASYNC_CRYPT
  46076. INVALID_DEVID /* async PKCS7 is not supported */
  46077. #else
  46078. devId
  46079. #endif
  46080. );
  46081. if (pkcs7 == NULL) {
  46082. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46083. }
  46084. if (testVectors[i].secretKey != NULL) {
  46085. /* KEKRI recipient type */
  46086. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46087. if (ret != 0)
  46088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46089. pkcs7->content = (byte*)testVectors[i].content;
  46090. pkcs7->contentSz = testVectors[i].contentSz;
  46091. pkcs7->contentOID = testVectors[i].contentOID;
  46092. pkcs7->encryptOID = testVectors[i].encryptOID;
  46093. pkcs7->ukm = testVectors[i].optionalUkm;
  46094. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46095. pkcs7->authAttribs = testVectors[i].authAttribs;
  46096. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46097. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46098. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46099. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46100. testVectors[i].secretKey, testVectors[i].secretKeySz,
  46101. testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46102. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46103. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46104. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46105. if (ret < 0) {
  46106. wc_PKCS7_Free(pkcs7);
  46107. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46108. }
  46109. /* set key, for decryption */
  46110. ret = wc_PKCS7_SetKey(pkcs7, testVectors[i].secretKey,
  46111. testVectors[i].secretKeySz);
  46112. if (ret != 0) {
  46113. wc_PKCS7_Free(pkcs7);
  46114. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46115. }
  46116. } else if (testVectors[i].password != NULL) {
  46117. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46118. /* PWRI recipient type */
  46119. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46120. if (ret != 0)
  46121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46122. pkcs7->content = (byte*)testVectors[i].content;
  46123. pkcs7->contentSz = testVectors[i].contentSz;
  46124. pkcs7->contentOID = testVectors[i].contentOID;
  46125. pkcs7->encryptOID = testVectors[i].encryptOID;
  46126. pkcs7->ukm = testVectors[i].optionalUkm;
  46127. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46128. pkcs7->authAttribs = testVectors[i].authAttribs;
  46129. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46130. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46131. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46132. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46133. (byte*)testVectors[i].password,
  46134. testVectors[i].passwordSz, testVectors[i].salt,
  46135. testVectors[i].saltSz, testVectors[i].kdfOID,
  46136. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46137. testVectors[i].kekEncryptOID, testVectors[i].pwriOptions);
  46138. if (ret < 0) {
  46139. wc_PKCS7_Free(pkcs7);
  46140. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46141. }
  46142. /* set password, for decryption */
  46143. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46144. testVectors[i].passwordSz);
  46145. if (ret < 0) {
  46146. wc_PKCS7_Free(pkcs7);
  46147. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46148. }
  46149. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46150. } else if (testVectors[i].isOri == 1) {
  46151. /* ORI recipient type */
  46152. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46153. if (ret != 0)
  46154. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46155. pkcs7->content = (byte*)testVectors[i].content;
  46156. pkcs7->contentSz = testVectors[i].contentSz;
  46157. pkcs7->contentOID = testVectors[i].contentOID;
  46158. pkcs7->encryptOID = testVectors[i].encryptOID;
  46159. pkcs7->authAttribs = testVectors[i].authAttribs;
  46160. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46161. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46162. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46163. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46164. testVectors[i].oriOptions);
  46165. if (ret < 0) {
  46166. wc_PKCS7_Free(pkcs7);
  46167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46168. }
  46169. /* set decrypt callback for decryption */
  46170. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46171. if (ret < 0) {
  46172. wc_PKCS7_Free(pkcs7);
  46173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46174. }
  46175. } else {
  46176. /* KTRI or KARI recipient types */
  46177. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46178. (word32)testVectors[i].certSz);
  46179. if (ret != 0) {
  46180. wc_PKCS7_Free(pkcs7);
  46181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46182. }
  46183. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46184. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46185. pkcs7->privateKey = testVectors[i].privateKey;
  46186. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46187. pkcs7->content = (byte*)testVectors[i].content;
  46188. pkcs7->contentSz = testVectors[i].contentSz;
  46189. pkcs7->contentOID = testVectors[i].contentOID;
  46190. pkcs7->encryptOID = testVectors[i].encryptOID;
  46191. pkcs7->ukm = testVectors[i].optionalUkm;
  46192. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46193. pkcs7->authAttribs = testVectors[i].authAttribs;
  46194. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46195. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46196. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46197. /* set SubjectIdentifier type for KTRI types */
  46198. if (testVectors[i].ktriOptions & CMS_SKID) {
  46199. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46200. if (ret != 0) {
  46201. wc_PKCS7_Free(pkcs7);
  46202. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46203. }
  46204. } else if (testVectors[i].ktriOptions &
  46205. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46206. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46207. CMS_ISSUER_AND_SERIAL_NUMBER);
  46208. if (ret != 0) {
  46209. wc_PKCS7_Free(pkcs7);
  46210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46211. }
  46212. }
  46213. }
  46214. #ifdef ECC_TIMING_RESISTANT
  46215. pkcs7->rng = &rng;
  46216. #endif
  46217. /* encode envelopedData */
  46218. envelopedSz = wc_PKCS7_EncodeAuthEnvelopedData(pkcs7, enveloped,
  46219. PKCS7_BUF_SIZE);
  46220. if (envelopedSz <= 0) {
  46221. wc_PKCS7_Free(pkcs7);
  46222. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46223. }
  46224. #ifndef NO_PKCS7_STREAM
  46225. { /* test reading byte by byte */
  46226. int z;
  46227. for (z = 0; z < envelopedSz; z++) {
  46228. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7,
  46229. enveloped + z, 1, decoded, PKCS7_BUF_SIZE);
  46230. if (decodedSz <= 0 &&
  46231. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46232. {
  46233. printf("unexpected error %d\n", decodedSz);
  46234. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46235. }
  46236. }
  46237. /* test decode result */
  46238. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46239. printf("stream read compare failed\n");
  46240. wc_PKCS7_Free(pkcs7);
  46241. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46242. }
  46243. }
  46244. #endif
  46245. /* decode envelopedData */
  46246. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, enveloped,
  46247. (word32)envelopedSz, decoded,
  46248. PKCS7_BUF_SIZE);
  46249. if (decodedSz <= 0) {
  46250. wc_PKCS7_Free(pkcs7);
  46251. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46252. }
  46253. /* test decode result */
  46254. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46255. wc_PKCS7_Free(pkcs7);
  46256. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46257. }
  46258. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46259. /* output pkcs7 envelopedData for external testing */
  46260. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46261. if (!pkcs7File) {
  46262. wc_PKCS7_Free(pkcs7);
  46263. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46264. }
  46265. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46266. XFCLOSE(pkcs7File);
  46267. if (ret != envelopedSz) {
  46268. wc_PKCS7_Free(pkcs7);
  46269. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46270. } else {
  46271. /* reset ret to 0 for success */
  46272. ret = 0;
  46273. }
  46274. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46275. wc_PKCS7_Free(pkcs7);
  46276. pkcs7 = NULL;
  46277. }
  46278. wc_FreeRng(&rng);
  46279. (void)eccCert;
  46280. (void)eccCertSz;
  46281. (void)eccPrivKey;
  46282. (void)eccPrivKeySz;
  46283. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46284. (void)secretKey;
  46285. (void)secretKeyId;
  46286. #endif
  46287. #ifdef NO_RSA
  46288. (void)rsaCert;
  46289. (void)rsaCertSz;
  46290. (void)rsaPrivKey;
  46291. (void)rsaPrivKeySz;
  46292. #endif
  46293. out:
  46294. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46295. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46296. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46297. return ret;
  46298. }
  46299. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void)
  46300. {
  46301. wc_test_ret_t ret = 0;
  46302. byte* rsaCert = NULL;
  46303. byte* rsaPrivKey = NULL;
  46304. word32 rsaCertSz = 0;
  46305. word32 rsaPrivKeySz = 0;
  46306. byte* eccCert = NULL;
  46307. byte* eccPrivKey = NULL;
  46308. word32 eccCertSz = 0;
  46309. word32 eccPrivKeySz = 0;
  46310. WOLFSSL_ENTER("pkcs7authenveloped_test");
  46311. #ifndef NO_RSA
  46312. /* read client RSA cert and key in DER format */
  46313. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46314. if (rsaCert == NULL)
  46315. return WC_TEST_RET_ENC_ERRNO;
  46316. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46317. if (rsaPrivKey == NULL) {
  46318. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46319. return WC_TEST_RET_ENC_NC;
  46320. }
  46321. rsaCertSz = FOURK_BUF;
  46322. rsaPrivKeySz = FOURK_BUF;
  46323. #endif /* NO_RSA */
  46324. #ifdef HAVE_ECC
  46325. /* read client ECC cert and key in DER format */
  46326. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46327. if (eccCert == NULL) {
  46328. #ifndef NO_RSA
  46329. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46330. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46331. #endif
  46332. return WC_TEST_RET_ENC_NC;
  46333. }
  46334. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46335. if (eccPrivKey == NULL) {
  46336. #ifndef NO_RSA
  46337. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46338. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46339. #endif
  46340. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46341. return WC_TEST_RET_ENC_NC;
  46342. }
  46343. eccCertSz = FOURK_BUF;
  46344. eccPrivKeySz = FOURK_BUF;
  46345. #endif /* HAVE_ECC */
  46346. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46347. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46348. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46349. eccPrivKey, &eccPrivKeySz);
  46350. if (ret < 0) {
  46351. #ifndef NO_RSA
  46352. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46353. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46354. #endif
  46355. #ifdef HAVE_ECC
  46356. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46357. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46358. #endif
  46359. return WC_TEST_RET_ENC_EC(ret);
  46360. }
  46361. ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46362. rsaPrivKey, (word32)rsaPrivKeySz,
  46363. eccCert, (word32)eccCertSz,
  46364. eccPrivKey, (word32)eccPrivKeySz);
  46365. #ifndef NO_RSA
  46366. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46367. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46368. #endif
  46369. #ifdef HAVE_ECC
  46370. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46371. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46372. #endif
  46373. return ret;
  46374. }
  46375. #endif /* HAVE_AESGCM || HAVE_AESCCM */
  46376. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46377. static const byte p7DefKey[] = {
  46378. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46379. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46380. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46381. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46382. };
  46383. static const byte p7AltKey[] = {
  46384. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46385. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46386. };
  46387. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  46388. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  46389. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  46390. {
  46391. wc_test_ret_t ret;
  46392. if (cek == NULL || out == NULL)
  46393. return BAD_FUNC_ARG;
  46394. /* test case sanity checks */
  46395. if (keyIdSz != 1) {
  46396. return WC_TEST_RET_ENC_NC;
  46397. }
  46398. if (keyId[0] != 0x00) {
  46399. return WC_TEST_RET_ENC_NC;
  46400. }
  46401. if (type != (int)PKCS7_KEKRI) {
  46402. return WC_TEST_RET_ENC_NC;
  46403. }
  46404. switch (keyWrapAlgo) {
  46405. case AES256_WRAP:
  46406. ret = wc_AesKeyUnWrap(p7DefKey, sizeof(p7DefKey), cek, cekSz,
  46407. out, outSz, NULL);
  46408. if (ret <= 0)
  46409. return (int)ret;
  46410. break;
  46411. default:
  46412. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  46413. return BAD_KEYWRAP_ALG_E;
  46414. };
  46415. (void)pkcs7;
  46416. (void)direction;
  46417. (void)orginKey; /* used with KAKRI */
  46418. (void)orginKeySz;
  46419. return (int)ret;
  46420. }
  46421. /* returns key size on success */
  46422. static wc_test_ret_t getFirmwareKey(PKCS7* pkcs7, byte* key, word32 keySz)
  46423. {
  46424. wc_test_ret_t ret;
  46425. word32 atrSz;
  46426. byte atr[256];
  46427. /* Additionally can look for fwWrappedFirmwareKey
  46428. * 1.2.840.113529.1.9.16.1.16 */
  46429. const unsigned char fwWrappedFirmwareKey[] = {
  46430. /* 0x06, 0x0B */
  46431. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46432. 0x01, 0x09, 0x10, 0x02, 0x27
  46433. };
  46434. /* find keyID in fwWrappedFirmwareKey */
  46435. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  46436. sizeof(fwWrappedFirmwareKey), NULL, &atrSz);
  46437. if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  46438. XMEMSET(atr, 0, sizeof(atr));
  46439. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  46440. sizeof(fwWrappedFirmwareKey), atr, &atrSz);
  46441. /* keyIdRaw[0] OCTET TAG */
  46442. /* keyIdRaw[1] Length */
  46443. if (ret > 0) {
  46444. PKCS7* envPkcs7;
  46445. envPkcs7 = wc_PKCS7_New(NULL, 0);
  46446. if (envPkcs7 == NULL) {
  46447. return MEMORY_E;
  46448. }
  46449. wc_PKCS7_Init(envPkcs7, NULL, 0);
  46450. ret = wc_PKCS7_SetWrapCEKCb(envPkcs7, myCEKwrapFunc);
  46451. if (ret == 0) {
  46452. /* expecting FIRMWARE_PKG_DATA content */
  46453. envPkcs7->contentOID = FIRMWARE_PKG_DATA;
  46454. ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
  46455. key, keySz);
  46456. if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
  46457. /* the contentOID should have been set to the inner
  46458. * FIRMWARE_PKG_DATA content */
  46459. ret = BAD_STATE_E;
  46460. }
  46461. }
  46462. wc_PKCS7_Free(envPkcs7);
  46463. }
  46464. }
  46465. return ret;
  46466. }
  46467. /* create a KEKRI enveloped data
  46468. * return size on success */
  46469. static wc_test_ret_t envelopedData_encrypt(byte* in, word32 inSz, byte* out,
  46470. word32 outSz)
  46471. {
  46472. wc_test_ret_t ret;
  46473. PKCS7* pkcs7;
  46474. WOLFSSL_SMALL_STACK_STATIC const byte keyId[] = { 0x00 };
  46475. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  46476. if (pkcs7 == NULL)
  46477. return WC_TEST_RET_ENC_ERRNO;
  46478. pkcs7->content = in;
  46479. pkcs7->contentSz = inSz;
  46480. pkcs7->contentOID = FIRMWARE_PKG_DATA;
  46481. pkcs7->encryptOID = AES256CBCb;
  46482. pkcs7->ukm = NULL;
  46483. pkcs7->ukmSz = 0;
  46484. /* add recipient (KEKRI type) */
  46485. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP, (byte*)p7DefKey,
  46486. sizeof(p7DefKey), (byte*)keyId,
  46487. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0);
  46488. if (ret < 0) {
  46489. printf("wc_PKCS7_AddRecipient_KEKRI() failed\n");
  46490. wc_PKCS7_Free(pkcs7);
  46491. return WC_TEST_RET_ENC_EC(ret);
  46492. }
  46493. /* encode envelopedData, returns size */
  46494. ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
  46495. if (ret <= 0) {
  46496. printf("wc_PKCS7_EncodeEnvelopedData() failed\n");
  46497. wc_PKCS7_Free(pkcs7);
  46498. return WC_TEST_RET_ENC_EC(ret);
  46499. }
  46500. wc_PKCS7_Free(pkcs7);
  46501. return ret;
  46502. }
  46503. /*
  46504. * keyHint is the KeyID to be set in the fwDecryptKeyID attribute
  46505. * returns size of buffer output on success
  46506. */
  46507. static wc_test_ret_t generateBundle(byte* out, word32 *outSz, const byte* encryptKey,
  46508. word32 encryptKeySz, byte keyHint, byte* cert, word32 certSz,
  46509. byte* key, word32 keySz)
  46510. {
  46511. wc_test_ret_t ret;
  46512. int attribNum = 1;
  46513. PKCS7* pkcs7;
  46514. /* KEY ID
  46515. * fwDecryptKeyID OID 1.2.840.113549.1.9.16.2.37
  46516. */
  46517. const unsigned char fwDecryptKeyID[] = {
  46518. 0x06, 0x0B,
  46519. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46520. 0x01, 0x09, 0x10, 0x02, 0x25
  46521. };
  46522. /* fwWrappedFirmwareKey 1.2.840.113529.1.9.16.1.16 */
  46523. const unsigned char fwWrappedFirmwareKey[] = {
  46524. 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46525. 0x01, 0x09, 0x10, 0x02, 0x27
  46526. };
  46527. byte keyID[] = { 0x04, 0x01, 0x00 };
  46528. byte env[256];
  46529. char data[] = "Test of wolfSSL PKCS7 decrypt callback";
  46530. PKCS7Attrib attribs[] =
  46531. {
  46532. { fwDecryptKeyID, sizeof(fwDecryptKeyID), keyID, sizeof(keyID) },
  46533. { fwWrappedFirmwareKey, sizeof(fwWrappedFirmwareKey), env, 0 }
  46534. };
  46535. keyID[2] = keyHint;
  46536. /* If using keyHint 0 then create a bundle with fwWrappedFirmwareKey */
  46537. if (keyHint == 0) {
  46538. ret = envelopedData_encrypt((byte*)p7DefKey, sizeof(p7DefKey), env,
  46539. sizeof(env));
  46540. if (ret <= 0) {
  46541. return ret;
  46542. }
  46543. attribs[1].valueSz = (word32)ret;
  46544. attribNum++;
  46545. }
  46546. /* init PKCS7 */
  46547. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  46548. if (pkcs7 == NULL)
  46549. return WC_TEST_RET_ENC_ERRNO;
  46550. ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
  46551. if (ret != 0) {
  46552. printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret);
  46553. wc_PKCS7_Free(pkcs7);
  46554. return WC_TEST_RET_ENC_EC(ret);
  46555. }
  46556. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46557. if (ret != 0) {
  46558. wc_PKCS7_Free(pkcs7);
  46559. return WC_TEST_RET_ENC_EC(ret);
  46560. }
  46561. /* encode Signed Encrypted FirmwarePkgData */
  46562. if (encryptKeySz == 16) {
  46563. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  46564. encryptKeySz, key, keySz, AES128CBCb, RSAk, SHA256h,
  46565. (byte*)data, sizeof(data), NULL, 0,
  46566. attribs, (word32)attribNum, out, *outSz);
  46567. }
  46568. else {
  46569. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  46570. encryptKeySz, key, keySz, AES256CBCb, RSAk, SHA256h,
  46571. (byte*)data, sizeof(data), NULL, 0,
  46572. attribs, (word32)attribNum, out, *outSz);
  46573. }
  46574. if (ret <= 0) {
  46575. printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, "
  46576. "ret = %d\n", ret);
  46577. wc_PKCS7_Free(pkcs7);
  46578. return WC_TEST_RET_ENC_EC(ret);
  46579. } else {
  46580. *outSz = (word32)ret;
  46581. }
  46582. wc_PKCS7_Free(pkcs7);
  46583. return ret;
  46584. }
  46585. /* test verification and decryption of PKCS7 bundle
  46586. * return 0 on success
  46587. */
  46588. static wc_test_ret_t verifyBundle(byte* derBuf, word32 derSz, int keyHint)
  46589. {
  46590. wc_test_ret_t ret = 0;
  46591. int usrCtx = 1; /* test value to pass as user context to callback */
  46592. PKCS7* pkcs7 = NULL;
  46593. byte* sid = NULL;
  46594. word32 sidSz;
  46595. byte key[256];
  46596. word32 keySz = sizeof(key);
  46597. byte *decoded = NULL;
  46598. int decodedSz = FOURK_BUF/2;
  46599. WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = {
  46600. #ifdef NO_SHA
  46601. #ifdef USE_CERT_BUFFERS_1024
  46602. 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9,
  46603. 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2,
  46604. 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06,
  46605. 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9
  46606. #else
  46607. 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36,
  46608. 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e,
  46609. 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4,
  46610. 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71
  46611. #endif
  46612. #else /* !NO_SHA */
  46613. #ifdef USE_CERT_BUFFERS_1024
  46614. 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34,
  46615. 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75,
  46616. 0x10, 0x69, 0x59, 0xec,
  46617. #else
  46618. 0x33, 0xD8, 0x45, 0x66, 0xD7, 0x68, 0x87, 0x18,
  46619. 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26,
  46620. 0xD7, 0x85, 0x65, 0xC0
  46621. #endif
  46622. #endif /* !NO_SHA */
  46623. };
  46624. decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46625. if (decoded == NULL) {
  46626. ret = MEMORY_E;
  46627. goto out;
  46628. }
  46629. pkcs7 = wc_PKCS7_New(HEAP_HINT, INVALID_DEVID);
  46630. if (pkcs7 == NULL) {
  46631. ret = MEMORY_E;
  46632. goto out;
  46633. }
  46634. /* Test verify */
  46635. ret = wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID);
  46636. if (ret != 0)
  46637. goto out;
  46638. ret = wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  46639. if (ret != 0)
  46640. goto out;
  46641. ret = wc_PKCS7_VerifySignedData(pkcs7, derBuf, derSz);
  46642. if (ret != 0)
  46643. goto out;
  46644. /* Get size of SID and print it out */
  46645. ret = wc_PKCS7_GetSignerSID(pkcs7, NULL, &sidSz);
  46646. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  46647. goto out;
  46648. sid = (byte*)XMALLOC(sidSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46649. if (sid == NULL) {
  46650. ret = MEMORY_E;
  46651. goto out;
  46652. }
  46653. ret = wc_PKCS7_GetSignerSID(pkcs7, sid, &sidSz);
  46654. if (ret != 0)
  46655. goto out;
  46656. ret = XMEMCMP(sid, expectedSid, sidSz);
  46657. if (ret != 0) {
  46658. ret = PKCS7_NO_SIGNER_E; /* close enough */
  46659. goto out;
  46660. }
  46661. /* get expected fwWrappedFirmwareKey */
  46662. if (keyHint == 0) {
  46663. ret = getFirmwareKey(pkcs7, key, keySz);
  46664. if (ret < 0)
  46665. goto out;
  46666. pkcs7->encryptionKey = key;
  46667. pkcs7->encryptionKeySz = (word32)ret;
  46668. }
  46669. else {
  46670. decodedSz = PKCS7_BUF_SIZE;
  46671. ret = wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc);
  46672. if (ret != 0)
  46673. goto out;
  46674. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)&usrCtx);
  46675. if (ret != 0)
  46676. goto out;
  46677. }
  46678. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  46679. pkcs7->contentSz, decoded, (word32)decodedSz);
  46680. if (decodedSz < 0) {
  46681. ret = decodedSz;
  46682. goto out;
  46683. }
  46684. ret = 0;
  46685. out:
  46686. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46687. if (pkcs7)
  46688. wc_PKCS7_Free(pkcs7);
  46689. XFREE(sid, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46690. return ret;
  46691. }
  46692. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key, word32 keySz)
  46693. {
  46694. wc_test_ret_t ret = 0;
  46695. word32 derSz;
  46696. byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46697. WOLFSSL_ENTER("pkcs7callback_test");
  46698. if (! derBuf)
  46699. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46700. /* Doing default generation and verify */
  46701. derSz = FOURK_BUF;
  46702. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert,
  46703. certSz, key, keySz);
  46704. if (ret <= 0) {
  46705. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46706. }
  46707. ret = verifyBundle(derBuf, derSz, 0);
  46708. if (ret != 0)
  46709. ERROR_OUT(ret, out);
  46710. /* test choosing other key with keyID */
  46711. derSz = FOURK_BUF;
  46712. ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1,
  46713. cert, certSz, key, keySz);
  46714. if (ret <= 0) {
  46715. ERROR_OUT(ret, out);
  46716. }
  46717. ret = verifyBundle(derBuf, derSz, 1);
  46718. if (ret != 0)
  46719. ERROR_OUT(ret, out);
  46720. /* test fail case with wrong keyID */
  46721. derSz = FOURK_BUF;
  46722. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1,
  46723. cert, certSz, key, keySz);
  46724. if (ret <= 0) {
  46725. ERROR_OUT(ret, out);
  46726. }
  46727. ret = verifyBundle(derBuf, derSz, 1);
  46728. if (ret == 0) {
  46729. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46730. }
  46731. ret = 0;
  46732. out:
  46733. XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46734. return ret;
  46735. }
  46736. #endif /* !NO_AES && HAVE_AES_CBC */
  46737. #ifndef NO_PKCS7_ENCRYPTED_DATA
  46738. typedef struct {
  46739. const byte* content;
  46740. word32 contentSz;
  46741. int contentOID;
  46742. int encryptOID;
  46743. byte* encryptionKey;
  46744. word32 encryptionKeySz;
  46745. PKCS7Attrib* attribs;
  46746. word32 attribsSz;
  46747. const char* outFileName;
  46748. } pkcs7EncryptedVector;
  46749. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void)
  46750. {
  46751. wc_test_ret_t ret = 0;
  46752. int i, testSz;
  46753. int encryptedSz, decodedSz, attribIdx;
  46754. PKCS7* pkcs7;
  46755. byte *encrypted;
  46756. byte *decoded;
  46757. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46758. XFILE pkcs7File;
  46759. #endif
  46760. PKCS7Attrib* expectedAttrib;
  46761. PKCS7DecodedAttrib* decodedAttrib;
  46762. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46763. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46764. 0x72,0x6c,0x64
  46765. };
  46766. #ifndef NO_DES3
  46767. byte desKey[] = {
  46768. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  46769. };
  46770. byte des3Key[] = {
  46771. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  46772. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  46773. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  46774. };
  46775. #endif
  46776. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46777. #ifdef WOLFSSL_AES_128
  46778. byte aes128Key[] = {
  46779. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46780. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46781. };
  46782. #endif
  46783. #ifdef WOLFSSL_AES_192
  46784. byte aes192Key[] = {
  46785. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46786. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46787. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46788. };
  46789. #endif
  46790. #ifdef WOLFSSL_AES_256
  46791. byte aes256Key[] = {
  46792. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46793. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46794. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46795. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46796. };
  46797. #endif
  46798. #ifdef WOLFSSL_AES_256
  46799. /* Attribute example from RFC 4134, Section 7.2
  46800. * OID = 1.2.5555
  46801. * OCTET STRING = 'This is a test General ASN Attribute, number 1.' */
  46802. static const byte genAttrOid[] = { 0x06, 0x03, 0x2a, 0xab, 0x33 };
  46803. static const byte genAttr[] = { 0x04, 47,
  46804. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  46805. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  46806. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  46807. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  46808. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  46809. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x31, 0x2e };
  46810. static const byte genAttrOid2[] = { 0x06, 0x03, 0x2a, 0xab, 0x34 };
  46811. static const byte genAttr2[] = { 0x04, 47,
  46812. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  46813. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  46814. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  46815. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  46816. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  46817. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x32, 0x2e };
  46818. PKCS7Attrib attribs[] =
  46819. {
  46820. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }
  46821. };
  46822. PKCS7Attrib multiAttribs[] =
  46823. {
  46824. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) },
  46825. { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) }
  46826. };
  46827. #endif
  46828. #endif /* NO_AES */
  46829. const pkcs7EncryptedVector testVectors[] =
  46830. {
  46831. #ifndef NO_DES3
  46832. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key),
  46833. NULL, 0, "pkcs7encryptedDataDES3.der"},
  46834. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey),
  46835. NULL, 0, "pkcs7encryptedDataDES.der"},
  46836. #endif /* NO_DES3 */
  46837. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46838. #ifdef WOLFSSL_AES_128
  46839. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  46840. sizeof(aes128Key), NULL, 0, "pkcs7encryptedDataAES128CBC.der"},
  46841. #endif
  46842. #ifdef WOLFSSL_AES_192
  46843. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  46844. sizeof(aes192Key), NULL, 0, "pkcs7encryptedDataAES192CBC.der"},
  46845. #endif
  46846. #ifdef WOLFSSL_AES_256
  46847. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46848. sizeof(aes256Key), NULL, 0, "pkcs7encryptedDataAES256CBC.der"},
  46849. /* test with optional unprotected attributes */
  46850. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46851. sizeof(aes256Key), attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  46852. "pkcs7encryptedDataAES256CBC_attribs.der"},
  46853. /* test with multiple optional unprotected attributes */
  46854. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46855. sizeof(aes256Key), multiAttribs,
  46856. (sizeof(multiAttribs)/sizeof(PKCS7Attrib)),
  46857. "pkcs7encryptedDataAES256CBC_multi_attribs.der"},
  46858. /* test with contentType set to FirmwarePkgData */
  46859. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256CBCb, aes256Key,
  46860. sizeof(aes256Key), NULL, 0,
  46861. "pkcs7encryptedDataAES256CBC_firmwarePkgData.der"},
  46862. #endif
  46863. #endif /* !NO_AES && HAVE_AES_CBC */
  46864. };
  46865. WOLFSSL_ENTER("pkcs7encrypted_test");
  46866. encrypted = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46867. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46868. if ((! encrypted) || (! decoded)) {
  46869. ERROR_OUT(MEMORY_E, out);
  46870. }
  46871. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  46872. for (i = 0; i < testSz; i++) {
  46873. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  46874. if (pkcs7 == NULL) {
  46875. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46876. }
  46877. pkcs7->content = (byte*)testVectors[i].content;
  46878. pkcs7->contentSz = testVectors[i].contentSz;
  46879. pkcs7->contentOID = testVectors[i].contentOID;
  46880. pkcs7->encryptOID = testVectors[i].encryptOID;
  46881. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  46882. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  46883. pkcs7->unprotectedAttribs = testVectors[i].attribs;
  46884. pkcs7->unprotectedAttribsSz = testVectors[i].attribsSz;
  46885. /* encode encryptedData */
  46886. encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46887. PKCS7_BUF_SIZE);
  46888. if (encryptedSz <= 0) {
  46889. wc_PKCS7_Free(pkcs7);
  46890. ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out);
  46891. }
  46892. /* decode encryptedData */
  46893. #ifndef NO_PKCS7_STREAM
  46894. { /* test reading byte by byte */
  46895. int z;
  46896. for (z = 0; z < encryptedSz; z++) {
  46897. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted + z, 1,
  46898. decoded, PKCS7_BUF_SIZE);
  46899. if (decodedSz <= 0 &&
  46900. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46901. {
  46902. printf("unexpected error %d\n", decodedSz);
  46903. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46904. }
  46905. }
  46906. /* test decode result */
  46907. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46908. printf("stream read failed\n");
  46909. wc_PKCS7_Free(pkcs7);
  46910. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46911. }
  46912. }
  46913. #endif
  46914. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46915. decoded, PKCS7_BUF_SIZE);
  46916. if (decodedSz <= 0){
  46917. wc_PKCS7_Free(pkcs7);
  46918. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46919. }
  46920. /* test decode result */
  46921. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46922. wc_PKCS7_Free(pkcs7);
  46923. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46924. }
  46925. /* verify decoded unprotected attributes */
  46926. if (pkcs7->decodedAttrib != NULL) {
  46927. decodedAttrib = pkcs7->decodedAttrib;
  46928. attribIdx = 1;
  46929. while (decodedAttrib != NULL) {
  46930. /* expected attribute, stored list is reversed */
  46931. expectedAttrib = &(pkcs7->unprotectedAttribs
  46932. [pkcs7->unprotectedAttribsSz - attribIdx]);
  46933. /* verify oid */
  46934. if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid,
  46935. decodedAttrib->oidSz) != 0) {
  46936. wc_PKCS7_Free(pkcs7);
  46937. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46938. }
  46939. /* verify value */
  46940. if (XMEMCMP(decodedAttrib->value, expectedAttrib->value,
  46941. decodedAttrib->valueSz) != 0) {
  46942. wc_PKCS7_Free(pkcs7);
  46943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46944. }
  46945. decodedAttrib = decodedAttrib->next;
  46946. attribIdx++;
  46947. }
  46948. }
  46949. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46950. /* output pkcs7 envelopedData for external testing */
  46951. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46952. if (!pkcs7File) {
  46953. wc_PKCS7_Free(pkcs7);
  46954. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46955. }
  46956. ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File);
  46957. if (ret < 0)
  46958. ret = WC_TEST_RET_ENC_ERRNO;
  46959. else
  46960. ret = 0;
  46961. XFCLOSE(pkcs7File);
  46962. #endif
  46963. wc_PKCS7_Free(pkcs7);
  46964. }
  46965. out:
  46966. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46967. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46968. return ret;
  46969. }
  46970. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  46971. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  46972. typedef struct {
  46973. const byte* content;
  46974. word32 contentSz;
  46975. int contentOID;
  46976. const char* outFileName;
  46977. } pkcs7CompressedVector;
  46978. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void)
  46979. {
  46980. wc_test_ret_t ret = 0;
  46981. int i, testSz;
  46982. int compressedSz, decodedSz;
  46983. PKCS7* pkcs7;
  46984. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  46985. byte *compressed;
  46986. byte *decoded;
  46987. #else
  46988. byte compressed[PKCS7_BUF_SIZE];
  46989. byte decoded[PKCS7_BUF_SIZE];
  46990. #endif
  46991. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46992. XFILE pkcs7File;
  46993. #endif
  46994. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46995. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46996. 0x72,0x6c,0x64
  46997. };
  46998. const pkcs7CompressedVector testVectors[] =
  46999. {
  47000. {data, (word32)sizeof(data), DATA,
  47001. "pkcs7compressedData_data_zlib.der"},
  47002. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA,
  47003. "pkcs7compressedData_firmwarePkgData_zlib.der"},
  47004. };
  47005. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47006. compressed = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47007. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47008. if ((! compressed) || (! decoded)) {
  47009. ERROR_OUT(MEMORY_E, out);
  47010. }
  47011. #endif
  47012. WOLFSSL_ENTER("pkcs7compressed_test");
  47013. testSz = sizeof(testVectors) / sizeof(pkcs7CompressedVector);
  47014. for (i = 0; i < testSz; i++) {
  47015. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47016. if (pkcs7 == NULL) {
  47017. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47018. }
  47019. pkcs7->content = (byte*)testVectors[i].content;
  47020. pkcs7->contentSz = testVectors[i].contentSz;
  47021. pkcs7->contentOID = testVectors[i].contentOID;
  47022. /* encode compressedData */
  47023. compressedSz = wc_PKCS7_EncodeCompressedData(pkcs7, compressed,
  47024. PKCS7_BUF_SIZE);
  47025. if (compressedSz <= 0) {
  47026. wc_PKCS7_Free(pkcs7);
  47027. ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out);
  47028. }
  47029. /* decode compressedData */
  47030. decodedSz = wc_PKCS7_DecodeCompressedData(pkcs7, compressed,
  47031. compressedSz, decoded,
  47032. PKCS7_BUF_SIZE);
  47033. if (decodedSz <= 0){
  47034. wc_PKCS7_Free(pkcs7);
  47035. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47036. }
  47037. /* test decode result */
  47038. if (XMEMCMP(decoded, testVectors[i].content,
  47039. testVectors[i].contentSz) != 0) {
  47040. wc_PKCS7_Free(pkcs7);
  47041. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47042. }
  47043. /* make sure content type is the same */
  47044. if (testVectors[i].contentOID != pkcs7->contentOID) {
  47045. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47046. }
  47047. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47048. /* output pkcs7 compressedData for external testing */
  47049. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47050. if (!pkcs7File) {
  47051. wc_PKCS7_Free(pkcs7);
  47052. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47053. }
  47054. ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File);
  47055. if (ret < 0)
  47056. ret = WC_TEST_RET_ENC_ERRNO;
  47057. else
  47058. ret = 0;
  47059. XFCLOSE(pkcs7File);
  47060. #endif
  47061. wc_PKCS7_Free(pkcs7);
  47062. }
  47063. out:
  47064. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47065. XFREE(compressed, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47066. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47067. #endif
  47068. return ret;
  47069. } /* pkcs7compressed_test() */
  47070. #undef PKCS7_BUF_SIZE
  47071. #endif /* HAVE_LIBZ */
  47072. typedef struct {
  47073. const byte* content;
  47074. word32 contentSz;
  47075. int hashOID;
  47076. int signOID;
  47077. byte* privateKey;
  47078. word32 privateKeySz;
  47079. byte* cert;
  47080. size_t certSz;
  47081. byte* caCert;
  47082. size_t caCertSz;
  47083. PKCS7Attrib* signedAttribs;
  47084. word32 signedAttribsSz;
  47085. const char* outFileName;
  47086. int contentOID;
  47087. const byte* contentType;
  47088. word32 contentTypeSz;
  47089. int sidType;
  47090. int encryptOID; /* for single-shot encrypt alg OID */
  47091. int encCompFlag; /* for single-shot. 1 = enc, 2 = comp, 3 = both*/
  47092. const byte* encryptKey; /* for single-shot, encryptedData */
  47093. word32 encryptKeySz; /* for single-shot, encryptedData */
  47094. PKCS7Attrib* unprotectedAttribs; /* for single-shot, encryptedData */
  47095. word32 unprotectedAttribsSz; /* for single-shot, encryptedData */
  47096. word16 detachedSignature; /* generate detached signature (0:1) */
  47097. } pkcs7SignedVector;
  47098. static wc_test_ret_t pkcs7signed_run_vectors(
  47099. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47100. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47101. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47102. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47103. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47104. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47105. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47106. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47107. {
  47108. wc_test_ret_t ret;
  47109. int testSz = 0, i;
  47110. int encodedSz;
  47111. byte* out = NULL;
  47112. word32 outSz;
  47113. WC_RNG rng;
  47114. PKCS7* pkcs7 = NULL;
  47115. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47116. XFILE file;
  47117. #endif
  47118. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47119. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47120. 0x72,0x6c,0x64
  47121. };
  47122. static const byte transIdOid[] =
  47123. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47124. 0x09, 0x07 };
  47125. static const byte messageTypeOid[] =
  47126. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47127. 0x09, 0x02 };
  47128. static const byte senderNonceOid[] =
  47129. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47130. 0x09, 0x05 };
  47131. #ifndef NO_SHA
  47132. byte transId[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47133. #else
  47134. byte transId[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47135. #endif
  47136. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47137. byte senderNonce[PKCS7_NONCE_SZ + 2];
  47138. PKCS7Attrib attribs[] =
  47139. {
  47140. { transIdOid, sizeof(transIdOid), transId,
  47141. sizeof(transId) - 1 }, /* take off the null */
  47142. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47143. sizeof(messageType) },
  47144. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  47145. sizeof(senderNonce) }
  47146. };
  47147. /* for testing custom contentType, FirmwarePkgData */
  47148. static const byte customContentType[] = { 0x06, 0x0B, 0x2A, 0x86,
  47149. 0x48, 0x86, 0xF7, 0x0D,
  47150. 0x01, 0x09, 0x10, 0x01, 0x10 };
  47151. #define MAX_TESTVECTORS_LEN 20
  47152. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47153. const pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47154. if (testSz == MAX_TESTVECTORS_LEN) { \
  47155. ret = WC_TEST_RET_ENC_NC; \
  47156. goto out; \
  47157. } \
  47158. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47159. sizeof _this_vector); \
  47160. }
  47161. pkcs7SignedVector *testVectors = NULL;
  47162. XMEMSET(&rng, 0, sizeof(rng));
  47163. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47164. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47165. if (testVectors == NULL) {
  47166. ret = WC_TEST_RET_ENC_ERRNO;
  47167. goto out;
  47168. }
  47169. {
  47170. #ifndef NO_RSA
  47171. #ifndef NO_SHA
  47172. /* RSA with SHA */
  47173. ADD_PKCS7SIGNEDVECTOR(
  47174. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47175. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47176. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47177. "pkcs7signedData_RSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0, NULL,
  47178. 0, 0);
  47179. /* RSA with SHA, no signed attributes */
  47180. ADD_PKCS7SIGNEDVECTOR(
  47181. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47182. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz,
  47183. NULL, 0, NULL, 0,
  47184. "pkcs7signedData_RSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47185. NULL, 0, 0);
  47186. #endif
  47187. #ifdef WOLFSSL_SHA224
  47188. /* RSA with SHA224 */
  47189. ADD_PKCS7SIGNEDVECTOR(
  47190. data, (word32)sizeof(data), SHA224h, RSAk, rsaClientPrivKeyBuf,
  47191. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47192. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47193. "pkcs7signedData_RSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47194. NULL, 0, 0);
  47195. #endif
  47196. #ifndef NO_SHA256
  47197. /* RSA with SHA256 */
  47198. ADD_PKCS7SIGNEDVECTOR(
  47199. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47200. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47201. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47202. "pkcs7signedData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47203. NULL, 0, 0);
  47204. /* RSA with SHA256, detached signature */
  47205. ADD_PKCS7SIGNEDVECTOR(
  47206. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47207. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47208. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47209. "pkcs7signedData_RSA_SHA256_detachedSig.der", 0, NULL, 0, 0, 0, 0,
  47210. NULL, 0, NULL, 0, 1);
  47211. /* RSA with SHA256 and SubjectKeyIdentifier in SignerIdentifier */
  47212. ADD_PKCS7SIGNEDVECTOR(
  47213. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47214. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47215. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47216. "pkcs7signedData_RSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47217. NULL, 0, NULL, 0, 0);
  47218. /* RSA with SHA256 and custom contentType */
  47219. ADD_PKCS7SIGNEDVECTOR(
  47220. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47221. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47222. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47223. "pkcs7signedData_RSA_SHA256_custom_contentType.der", 0,
  47224. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  47225. NULL, 0, 0);
  47226. /* RSA with SHA256 and FirmwarePkgData contentType */
  47227. ADD_PKCS7SIGNEDVECTOR(
  47228. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47229. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47230. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47231. "pkcs7signedData_RSA_SHA256_firmwarePkgData.der",
  47232. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47233. /* RSA with SHA256 using server cert and ca cert */
  47234. ADD_PKCS7SIGNEDVECTOR(
  47235. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  47236. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  47237. rsaCaCertBuf, rsaCaCertBufSz,
  47238. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47239. "pkcs7signedData_RSA_SHA256_with_ca_cert.der", 0, NULL, 0, 0, 0, 0,
  47240. NULL, 0, NULL, 0, 0);
  47241. #endif
  47242. #if defined(WOLFSSL_SHA384)
  47243. /* RSA with SHA384 */
  47244. ADD_PKCS7SIGNEDVECTOR(
  47245. data, (word32)sizeof(data), SHA384h, RSAk, rsaClientPrivKeyBuf,
  47246. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47247. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47248. "pkcs7signedData_RSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47249. NULL, 0, 0);
  47250. #endif
  47251. #if defined(WOLFSSL_SHA512)
  47252. /* RSA with SHA512 */
  47253. ADD_PKCS7SIGNEDVECTOR(
  47254. data, (word32)sizeof(data), SHA512h, RSAk, rsaClientPrivKeyBuf,
  47255. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47256. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47257. "pkcs7signedData_RSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47258. NULL, 0, 0);
  47259. #endif
  47260. #endif /* NO_RSA */
  47261. #ifdef HAVE_ECC
  47262. #ifndef NO_SHA
  47263. /* ECDSA with SHA */
  47264. ADD_PKCS7SIGNEDVECTOR(
  47265. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  47266. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47267. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47268. "pkcs7signedData_ECDSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47269. NULL, 0, 0);
  47270. /* ECDSA with SHA, no signed attributes */
  47271. ADD_PKCS7SIGNEDVECTOR(
  47272. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  47273. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz,
  47274. NULL, 0, NULL, 0,
  47275. "pkcs7signedData_ECDSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47276. NULL, 0, 0);
  47277. #endif
  47278. #ifdef WOLFSSL_SHA224
  47279. /* ECDSA with SHA224 */
  47280. ADD_PKCS7SIGNEDVECTOR(
  47281. data, (word32)sizeof(data), SHA224h, ECDSAk, eccClientPrivKeyBuf,
  47282. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47283. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47284. "pkcs7signedData_ECDSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47285. NULL, 0, 0);
  47286. #endif
  47287. #ifndef NO_SHA256
  47288. /* ECDSA with SHA256 */
  47289. ADD_PKCS7SIGNEDVECTOR(
  47290. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47291. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47292. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47293. "pkcs7signedData_ECDSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47294. NULL, 0, 0);
  47295. /* ECDSA with SHA256 and SubjectKeyIdentifier in SigherIdentifier */
  47296. ADD_PKCS7SIGNEDVECTOR(
  47297. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47298. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47299. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47300. "pkcs7signedData_ECDSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47301. NULL, 0, NULL, 0, 0);
  47302. /* ECDSA with SHA256 and custom contentType */
  47303. ADD_PKCS7SIGNEDVECTOR(
  47304. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47305. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47306. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47307. "pkcs7signedData_ECDSA_SHA256_custom_contentType.der", 0,
  47308. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  47309. NULL, 0, 0);
  47310. /* ECDSA with SHA256 and FirmwarePkgData contentType */
  47311. ADD_PKCS7SIGNEDVECTOR(
  47312. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47313. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47314. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47315. "pkcs7signedData_ECDSA_SHA256_firmwarePkgData.der",
  47316. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47317. #endif
  47318. #ifdef WOLFSSL_SHA384
  47319. /* ECDSA with SHA384 */
  47320. ADD_PKCS7SIGNEDVECTOR(
  47321. data, (word32)sizeof(data), SHA384h, ECDSAk, eccClientPrivKeyBuf,
  47322. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47323. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47324. "pkcs7signedData_ECDSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47325. NULL, 0, 0);
  47326. #endif
  47327. #ifdef WOLFSSL_SHA512
  47328. /* ECDSA with SHA512 */
  47329. ADD_PKCS7SIGNEDVECTOR(
  47330. data, (word32)sizeof(data), SHA512h, ECDSAk, eccClientPrivKeyBuf,
  47331. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47332. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47333. "pkcs7signedData_ECDSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47334. NULL, 0, 0);
  47335. #endif
  47336. #endif /* HAVE_ECC */
  47337. };
  47338. #undef MAX_TESTVECTORS_LEN
  47339. #undef ADD_PKCS7SIGNEDVECTOR
  47340. outSz = FOURK_BUF;
  47341. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47342. if (out == NULL)
  47343. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47344. XMEMSET(out, 0, outSz);
  47345. /* test inner pad size error with block size being 0 */
  47346. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
  47347. if (ret > 0)
  47348. ERROR_OUT(-1, out);
  47349. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  47350. if (ret < 0)
  47351. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47352. #ifndef HAVE_FIPS
  47353. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  47354. #else
  47355. ret = wc_InitRng(&rng);
  47356. #endif
  47357. if (ret != 0)
  47358. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47359. for (i = 0; i < testSz; i++) {
  47360. if (pkcs7)
  47361. wc_PKCS7_Free(pkcs7);
  47362. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47363. if (pkcs7 == NULL)
  47364. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47365. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  47366. (word32)testVectors[i].certSz);
  47367. if (ret != 0)
  47368. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47369. /* load CA certificate, if present */
  47370. if (testVectors[i].caCert != NULL) {
  47371. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  47372. (word32)testVectors[i].caCertSz);
  47373. if (ret != 0)
  47374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47375. }
  47376. pkcs7->rng = &rng;
  47377. pkcs7->content = (byte*)testVectors[i].content;
  47378. pkcs7->contentSz = testVectors[i].contentSz;
  47379. pkcs7->contentOID = testVectors[i].contentOID;
  47380. pkcs7->hashOID = testVectors[i].hashOID;
  47381. pkcs7->encryptOID = testVectors[i].signOID;
  47382. pkcs7->privateKey = testVectors[i].privateKey;
  47383. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  47384. pkcs7->signedAttribs = testVectors[i].signedAttribs;
  47385. pkcs7->signedAttribsSz = testVectors[i].signedAttribsSz;
  47386. /* optional custom contentType, default is DATA,
  47387. overrides contentOID if set */
  47388. if (testVectors[i].contentType != NULL) {
  47389. ret = wc_PKCS7_SetContentType(pkcs7,
  47390. (byte *)testVectors[i].contentType,
  47391. testVectors[i].contentTypeSz);
  47392. if (ret != 0)
  47393. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47394. }
  47395. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  47396. default is IssuerAndSerialNumber */
  47397. if (testVectors[i].sidType == CMS_SKID) {
  47398. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47399. if (ret != 0)
  47400. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47401. }
  47402. /* generate senderNonce */
  47403. {
  47404. senderNonce[0] = 0x04;
  47405. senderNonce[1] = PKCS7_NONCE_SZ;
  47406. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  47407. if (ret != 0)
  47408. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47409. }
  47410. /* generate transactionID (used with SCEP) */
  47411. {
  47412. #ifndef NO_SHA
  47413. wc_Sha sha;
  47414. byte digest[WC_SHA_DIGEST_SIZE];
  47415. #else
  47416. wc_Sha256 sha;
  47417. byte digest[WC_SHA256_DIGEST_SIZE];
  47418. #endif
  47419. int j,k;
  47420. transId[0] = 0x13;
  47421. transId[1] = sizeof(digest) * 2;
  47422. #ifndef NO_SHA
  47423. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  47424. if (ret != 0)
  47425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47426. wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  47427. wc_ShaFinal(&sha, digest);
  47428. wc_ShaFree(&sha);
  47429. #else
  47430. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  47431. if (ret != 0)
  47432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47433. wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  47434. wc_Sha256Final(&sha, digest);
  47435. wc_Sha256Free(&sha);
  47436. #endif
  47437. for (j = 0, k = 2; j < (int)sizeof(digest); j++, k += 2) {
  47438. (void)XSNPRINTF((char*)&transId[k], 3, "%02x", digest[j]);
  47439. }
  47440. }
  47441. /* enable detached signature generation, if set */
  47442. if (testVectors[i].detachedSignature == 1) {
  47443. ret = wc_PKCS7_SetDetached(pkcs7, 1);
  47444. if (ret != 0)
  47445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47446. }
  47447. encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz);
  47448. if (encodedSz < 0)
  47449. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47450. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47451. /* write PKCS#7 to output file for more testing */
  47452. file = XFOPEN(testVectors[i].outFileName, "wb");
  47453. if (!file) {
  47454. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47455. }
  47456. ret = (int)XFWRITE(out, 1, encodedSz, file);
  47457. XFCLOSE(file);
  47458. if (ret != (int)encodedSz)
  47459. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47460. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47461. wc_PKCS7_Free(pkcs7);
  47462. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47463. if (pkcs7 == NULL)
  47464. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47465. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47466. if (testVectors[i].detachedSignature == 1) {
  47467. /* set content for verifying detached signatures */
  47468. pkcs7->content = (byte*)testVectors[i].content;
  47469. pkcs7->contentSz = testVectors[i].contentSz;
  47470. }
  47471. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  47472. if (ret < 0)
  47473. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47474. /* verify contentType extracted successfully for custom content types */
  47475. if (testVectors[i].contentTypeSz > 0) {
  47476. if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) {
  47477. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47478. } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType,
  47479. pkcs7->contentTypeSz) != 0) {
  47480. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47481. }
  47482. }
  47483. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  47484. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47485. {
  47486. /* check getting signed attributes */
  47487. #ifndef NO_SHA
  47488. byte buf[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47489. #else
  47490. byte buf[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47491. #endif
  47492. const byte* oidPt = transIdOid + 2; /* skip object id tag and size */
  47493. int oidSz = (int)sizeof(transIdOid) - 2;
  47494. int bufSz = 0;
  47495. if (testVectors[i].signedAttribs != NULL) {
  47496. ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  47497. NULL, (word32*)&bufSz);
  47498. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47500. ret = 0;
  47501. }
  47502. if (bufSz > (int)sizeof(buf))
  47503. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47504. bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  47505. buf, (word32*)&bufSz);
  47506. if ((testVectors[i].signedAttribs != NULL && bufSz < 0) ||
  47507. (testVectors[i].signedAttribs == NULL && bufSz > 0))
  47508. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47509. }
  47510. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47511. file = XFOPEN("./pkcs7cert.der", "wb");
  47512. if (!file)
  47513. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47514. ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file);
  47515. if (ret < 0)
  47516. ret = WC_TEST_RET_ENC_ERRNO;
  47517. else
  47518. ret = 0;
  47519. XFCLOSE(file);
  47520. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47521. }
  47522. out:
  47523. if (pkcs7 != NULL)
  47524. wc_PKCS7_Free(pkcs7);
  47525. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47526. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47527. wc_FreeRng(&rng);
  47528. if (ret > 0)
  47529. return 0;
  47530. (void)rsaClientCertBuf;
  47531. (void)rsaClientCertBufSz;
  47532. (void)rsaClientPrivKeyBuf;
  47533. (void)rsaClientPrivKeyBufSz;
  47534. (void)rsaServerCertBuf;
  47535. (void)rsaServerCertBufSz;
  47536. (void)rsaServerPrivKeyBuf;
  47537. (void)rsaServerPrivKeyBufSz;
  47538. (void)rsaCaCertBuf;
  47539. (void)rsaCaCertBufSz;
  47540. (void)rsaCaPrivKeyBuf;
  47541. (void)rsaCaPrivKeyBufSz;
  47542. (void)eccClientCertBuf;
  47543. (void)eccClientCertBufSz;
  47544. (void)eccClientPrivKeyBuf;
  47545. (void)eccClientPrivKeyBufSz;
  47546. return ret;
  47547. }
  47548. static wc_test_ret_t pkcs7signed_run_SingleShotVectors(
  47549. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47550. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47551. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47552. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47553. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47554. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47555. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47556. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47557. {
  47558. wc_test_ret_t ret;
  47559. int testSz = 0, i;
  47560. int encodedSz;
  47561. byte* out = NULL;
  47562. word32 outSz;
  47563. WC_RNG rng;
  47564. PKCS7* pkcs7 = NULL;
  47565. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47566. XFILE file;
  47567. #endif
  47568. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  47569. !defined(NO_PKCS7_ENCRYPTED_DATA)
  47570. byte* encryptedTmp = NULL;
  47571. int encryptedTmpSz;
  47572. #endif
  47573. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47574. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47575. 0x72,0x6c,0x64
  47576. };
  47577. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  47578. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  47579. static const byte aes256Key[] = {
  47580. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47581. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47582. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47583. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47584. };
  47585. #endif
  47586. static const byte messageTypeOid[] =
  47587. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47588. 0x09, 0x02 };
  47589. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47590. PKCS7Attrib attribs[] =
  47591. {
  47592. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47593. sizeof(messageType) },
  47594. };
  47595. #define MAX_TESTVECTORS_LEN 19
  47596. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47597. pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47598. if (testSz == MAX_TESTVECTORS_LEN) { \
  47599. ret = WC_TEST_RET_ENC_NC; \
  47600. goto out; \
  47601. } \
  47602. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47603. sizeof _this_vector); \
  47604. }
  47605. pkcs7SignedVector *testVectors = NULL;
  47606. XMEMSET(&rng, 0, sizeof(rng));
  47607. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47608. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47609. if (testVectors == NULL) {
  47610. ret = WC_TEST_RET_ENC_ERRNO;
  47611. goto out;
  47612. }
  47613. {
  47614. #ifndef NO_RSA
  47615. #ifndef NO_SHA256
  47616. /* Signed FirmwarePkgData, RSA, SHA256, no attribs */
  47617. ADD_PKCS7SIGNEDVECTOR(
  47618. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47619. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47620. NULL, 0,
  47621. "pkcs7signedFirmwarePkgData_RSA_SHA256_noattr.der", 0, NULL, 0, 0,
  47622. 0, 0, NULL, 0, NULL, 0, 0);
  47623. /* Signed FirmwarePkgData, RSA, SHA256, attrs */
  47624. ADD_PKCS7SIGNEDVECTOR(
  47625. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47626. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47627. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47628. "pkcs7signedFirmwarePkgData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0,
  47629. NULL, 0, NULL, 0, 0);
  47630. /* Signed FirmwarePkgData, RSA, SHA256, SubjectKeyIdentifier, attrs */
  47631. ADD_PKCS7SIGNEDVECTOR(
  47632. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47633. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47634. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47635. "pkcs7signedFirmwarePkgData_RSA_SHA256_SKID.der", 0, NULL,
  47636. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  47637. /* Signed FirmwraePkgData, RSA, SHA256, server cert and ca cert, attr */
  47638. ADD_PKCS7SIGNEDVECTOR(
  47639. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  47640. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  47641. rsaCaCertBuf, rsaCaCertBufSz,
  47642. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47643. "pkcs7signedFirmwarePkgData_RSA_SHA256_with_ca_cert.der", 0, NULL,
  47644. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47645. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  47646. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  47647. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, no attribs */
  47648. ADD_PKCS7SIGNEDVECTOR(
  47649. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47650. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47651. NULL, 0,
  47652. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  47653. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  47654. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, attribs */
  47655. ADD_PKCS7SIGNEDVECTOR(
  47656. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47657. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47658. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47659. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256.der", 0,
  47660. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  47661. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47662. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  47663. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47664. /* Signed Compressed FirmwarePkgData, RSA, SHA256, no attribs */
  47665. ADD_PKCS7SIGNEDVECTOR(
  47666. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47667. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47668. NULL, 0,
  47669. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  47670. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47671. /* Signed Compressed FirmwarePkgData, RSA, SHA256, attribs */
  47672. ADD_PKCS7SIGNEDVECTOR(
  47673. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47674. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47675. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47676. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256.der", 0,
  47677. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47678. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47679. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  47680. no attribs */
  47681. ADD_PKCS7SIGNEDVECTOR(
  47682. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47683. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47684. NULL, 0,
  47685. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der",
  47686. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  47687. 0, 0);
  47688. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  47689. attribs */
  47690. ADD_PKCS7SIGNEDVECTOR(
  47691. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47692. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47693. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47694. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der",
  47695. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  47696. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47697. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  47698. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  47699. #endif /* NO_SHA256 */
  47700. #endif /* NO_RSA */
  47701. #ifdef HAVE_ECC
  47702. #ifndef NO_SHA256
  47703. /* Signed FirmwarePkgData, ECDSA, SHA256, no attribs */
  47704. ADD_PKCS7SIGNEDVECTOR(
  47705. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47706. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47707. NULL, 0,
  47708. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  47709. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47710. /* Signed FirmwarePkgData, ECDSA, SHA256, attribs */
  47711. ADD_PKCS7SIGNEDVECTOR(
  47712. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47713. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47714. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47715. "pkcs7signedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  47716. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47717. /* Signed FirmwarePkgData, ECDSA, SHA256, SubjectKeyIdentifier, attr */
  47718. ADD_PKCS7SIGNEDVECTOR(
  47719. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47720. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47721. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47722. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_SKID.der", 0, NULL,
  47723. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  47724. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  47725. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  47726. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, no attribs */
  47727. ADD_PKCS7SIGNEDVECTOR(
  47728. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47729. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47730. NULL, 0,
  47731. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  47732. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  47733. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, attribs */
  47734. ADD_PKCS7SIGNEDVECTOR(
  47735. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47736. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47737. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47738. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  47739. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  47740. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47741. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  47742. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47743. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, no attribs */
  47744. ADD_PKCS7SIGNEDVECTOR(
  47745. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47746. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47747. NULL, 0,
  47748. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  47749. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47750. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, attrib */
  47751. ADD_PKCS7SIGNEDVECTOR(
  47752. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47753. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47754. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47755. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  47756. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47757. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47758. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  47759. no attribs */
  47760. ADD_PKCS7SIGNEDVECTOR(
  47761. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47762. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47763. NULL, 0,
  47764. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der",
  47765. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  47766. 0, 0);
  47767. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  47768. attribs */
  47769. ADD_PKCS7SIGNEDVECTOR(
  47770. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47771. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47772. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47773. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der",
  47774. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  47775. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47776. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  47777. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  47778. #endif /* NO_SHA256 */
  47779. #endif /* HAVE_ECC */
  47780. };
  47781. #undef MAX_TESTVECTORS_LEN
  47782. #undef ADD_PKCS7SIGNEDVECTOR
  47783. outSz = FOURK_BUF;
  47784. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47785. if (out == NULL)
  47786. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47787. XMEMSET(out, 0, outSz);
  47788. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  47789. if (ret < 0)
  47790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47791. #ifndef HAVE_FIPS
  47792. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  47793. #else
  47794. ret = wc_InitRng(&rng);
  47795. #endif
  47796. if (ret != 0)
  47797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47798. for (i = 0; i < testSz; i++) {
  47799. if (pkcs7)
  47800. wc_PKCS7_Free(pkcs7);
  47801. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47802. if (pkcs7 == NULL)
  47803. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47804. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  47805. (word32)testVectors[i].certSz);
  47806. if (ret != 0)
  47807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47808. /* load CA certificate, if present */
  47809. if (testVectors[i].caCert != NULL) {
  47810. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  47811. (word32)testVectors[i].caCertSz);
  47812. if (ret != 0)
  47813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47814. }
  47815. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  47816. default is IssuerAndSerialNumber */
  47817. if (testVectors[i].sidType == CMS_SKID) {
  47818. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47819. if (ret != 0)
  47820. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47821. }
  47822. if (testVectors[i].encCompFlag == 0) {
  47823. /* encode Signed FirmwarePkgData */
  47824. encodedSz = wc_PKCS7_EncodeSignedFPD(pkcs7,
  47825. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47826. testVectors[i].signOID, testVectors[i].hashOID,
  47827. (byte*)testVectors[i].content, testVectors[i].contentSz,
  47828. testVectors[i].signedAttribs,
  47829. testVectors[i].signedAttribsSz, out, outSz);
  47830. if (encodedSz < 0)
  47831. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47832. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47833. } else if (testVectors[i].encCompFlag == 1) {
  47834. /* encode Signed Encrypted FirmwarePkgData */
  47835. encodedSz = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7,
  47836. (byte *)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  47837. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47838. testVectors[i].encryptOID, testVectors[i].signOID,
  47839. testVectors[i].hashOID, (byte*)testVectors[i].content,
  47840. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  47841. testVectors[i].unprotectedAttribsSz,
  47842. testVectors[i].signedAttribs,
  47843. testVectors[i].signedAttribsSz, out, outSz);
  47844. if (encodedSz <= 0)
  47845. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47846. #endif
  47847. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47848. } else if (testVectors[i].encCompFlag == 2) {
  47849. /* encode Signed Compressed FirmwarePkgData */
  47850. encodedSz = wc_PKCS7_EncodeSignedCompressedFPD(pkcs7,
  47851. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47852. testVectors[i].signOID, testVectors[i].hashOID,
  47853. (byte*)testVectors[i].content, testVectors[i].contentSz,
  47854. testVectors[i].signedAttribs,
  47855. testVectors[i].signedAttribsSz, out, outSz);
  47856. if (encodedSz <= 0)
  47857. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47858. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47859. } else if (testVectors[i].encCompFlag == 3) {
  47860. /* encode Signed Encrypted Compressed FirmwarePkgData */
  47861. encodedSz = wc_PKCS7_EncodeSignedEncryptedCompressedFPD(pkcs7,
  47862. (byte*)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  47863. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47864. testVectors[i].encryptOID, testVectors[i].signOID,
  47865. testVectors[i].hashOID, (byte*)testVectors[i].content,
  47866. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  47867. testVectors[i].unprotectedAttribsSz,
  47868. testVectors[i].signedAttribs,
  47869. testVectors[i].signedAttribsSz, out, outSz);
  47870. if (encodedSz <= 0)
  47871. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47872. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47873. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  47874. } else {
  47875. /* unsupported SignedData single-shot combination */
  47876. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47877. }
  47878. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47879. /* write PKCS#7 to output file for more testing */
  47880. file = XFOPEN(testVectors[i].outFileName, "wb");
  47881. if (!file)
  47882. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47883. ret = (int)XFWRITE(out, 1, encodedSz, file);
  47884. XFCLOSE(file);
  47885. file = NULL;
  47886. if (ret != (int)encodedSz)
  47887. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47888. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47889. wc_PKCS7_Free(pkcs7);
  47890. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47891. if (pkcs7 == NULL)
  47892. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47893. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47894. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  47895. if (ret < 0)
  47896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47897. #ifndef NO_PKCS7_STREAM
  47898. {
  47899. word32 z;
  47900. for (z = 0; z < outSz && ret != 0; z++) {
  47901. ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1);
  47902. if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  47903. printf("unexpected error %d\n", ret);
  47904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47905. }
  47906. }
  47907. }
  47908. #endif
  47909. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  47910. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47911. if (testVectors[i].encCompFlag == 0) {
  47912. /* verify decoded content matches expected */
  47913. if ((pkcs7->contentSz != testVectors[i].contentSz) ||
  47914. XMEMCMP(pkcs7->content, testVectors[i].content,
  47915. pkcs7->contentSz)) {
  47916. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47917. }
  47918. }
  47919. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47920. else if (testVectors[i].encCompFlag == 1) {
  47921. /* decrypt inner encryptedData */
  47922. pkcs7->encryptionKey = (byte *)testVectors[i].encryptKey;
  47923. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  47924. ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47925. pkcs7->contentSz, out, outSz);
  47926. if (ret < 0)
  47927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47928. /* compare decrypted to expected */
  47929. if (((word32)ret != testVectors[i].contentSz) ||
  47930. XMEMCMP(out, testVectors[i].content, ret))
  47931. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47932. }
  47933. #endif
  47934. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47935. else if (testVectors[i].encCompFlag == 2) {
  47936. /* decompress inner compressedData */
  47937. ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content,
  47938. pkcs7->contentSz, out, outSz);
  47939. if (ret < 0)
  47940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47941. /* compare decompressed to expected */
  47942. if (((word32)ret != testVectors[i].contentSz) ||
  47943. XMEMCMP(out, testVectors[i].content, ret))
  47944. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47945. }
  47946. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47947. else if (testVectors[i].encCompFlag == 3) {
  47948. encryptedTmpSz = FOURK_BUF;
  47949. encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT,
  47950. DYNAMIC_TYPE_TMP_BUFFER);
  47951. if (encryptedTmp == NULL)
  47952. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47953. XMEMSET(encryptedTmp, 0, encryptedTmpSz);
  47954. /* decrypt inner encryptedData */
  47955. pkcs7->encryptionKey = (byte*)testVectors[i].encryptKey;
  47956. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  47957. encryptedTmpSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47958. pkcs7->contentSz, encryptedTmp,
  47959. encryptedTmpSz);
  47960. if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA)
  47961. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47962. /* decompress inner compressedData */
  47963. ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp,
  47964. encryptedTmpSz, out, outSz);
  47965. if (ret < 0)
  47966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47967. /* compare decompressed to expected */
  47968. if (((word32)ret != testVectors[i].contentSz) ||
  47969. XMEMCMP(out, testVectors[i].content, ret))
  47970. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47971. }
  47972. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47973. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  47974. }
  47975. out:
  47976. if (pkcs7 != NULL)
  47977. wc_PKCS7_Free(pkcs7);
  47978. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47979. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  47980. !defined(NO_PKCS7_ENCRYPTED_DATA)
  47981. XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47982. #endif
  47983. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47984. wc_FreeRng(&rng);
  47985. if (ret > 0)
  47986. return 0;
  47987. (void)eccClientCertBuf;
  47988. (void)eccClientCertBufSz;
  47989. (void)eccClientPrivKeyBuf;
  47990. (void)eccClientPrivKeyBufSz;
  47991. (void)rsaClientCertBuf;
  47992. (void)rsaClientCertBufSz;
  47993. (void)rsaClientPrivKeyBuf;
  47994. (void)rsaClientPrivKeyBufSz;
  47995. (void)rsaServerCertBuf;
  47996. (void)rsaServerCertBufSz;
  47997. (void)rsaServerPrivKeyBuf;
  47998. (void)rsaServerPrivKeyBufSz;
  47999. (void)rsaCaCertBuf;
  48000. (void)rsaCaCertBufSz;
  48001. (void)rsaCaPrivKeyBuf;
  48002. (void)rsaCaPrivKeyBufSz;
  48003. return ret;
  48004. }
  48005. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void)
  48006. {
  48007. wc_test_ret_t ret = 0;
  48008. byte* rsaClientCertBuf = NULL;
  48009. byte* rsaServerCertBuf = NULL;
  48010. byte* rsaCaCertBuf = NULL;
  48011. byte* eccClientCertBuf = NULL;
  48012. byte* rsaClientPrivKeyBuf = NULL;
  48013. byte* rsaServerPrivKeyBuf = NULL;
  48014. byte* rsaCaPrivKeyBuf = NULL;
  48015. byte* eccClientPrivKeyBuf = NULL;
  48016. word32 rsaClientCertBufSz = 0;
  48017. word32 rsaServerCertBufSz = 0;
  48018. word32 rsaCaCertBufSz = 0;
  48019. word32 eccClientCertBufSz = 0;
  48020. word32 rsaClientPrivKeyBufSz = 0;
  48021. word32 rsaServerPrivKeyBufSz = 0;
  48022. word32 rsaCaPrivKeyBufSz = 0;
  48023. word32 eccClientPrivKeyBufSz = 0;
  48024. WOLFSSL_ENTER("pkcs7signed_test");
  48025. #ifndef NO_RSA
  48026. /* read client RSA cert and key in DER format */
  48027. rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48028. DYNAMIC_TYPE_TMP_BUFFER);
  48029. if (rsaClientCertBuf == NULL)
  48030. ret = WC_TEST_RET_ENC_NC;
  48031. rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48032. DYNAMIC_TYPE_TMP_BUFFER);
  48033. if (ret == 0 && rsaClientPrivKeyBuf == NULL) {
  48034. ret = WC_TEST_RET_ENC_ERRNO;
  48035. }
  48036. rsaClientCertBufSz = FOURK_BUF;
  48037. rsaClientPrivKeyBufSz = FOURK_BUF;
  48038. /* read server RSA cert and key in DER format */
  48039. rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48040. DYNAMIC_TYPE_TMP_BUFFER);
  48041. if (ret == 0 && rsaServerCertBuf == NULL)
  48042. ret = WC_TEST_RET_ENC_NC;
  48043. rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48044. DYNAMIC_TYPE_TMP_BUFFER);
  48045. if (ret == 0 && rsaServerPrivKeyBuf == NULL) {
  48046. ret = WC_TEST_RET_ENC_ERRNO;
  48047. }
  48048. rsaServerCertBufSz = FOURK_BUF;
  48049. rsaServerPrivKeyBufSz = FOURK_BUF;
  48050. /* read CA RSA cert and key in DER format, for use with server cert */
  48051. rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48052. DYNAMIC_TYPE_TMP_BUFFER);
  48053. if (ret == 0 && rsaCaCertBuf == NULL)
  48054. ret = WC_TEST_RET_ENC_NC;
  48055. rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48056. DYNAMIC_TYPE_TMP_BUFFER);
  48057. if (ret == 0 && rsaCaPrivKeyBuf == NULL) {
  48058. ret = WC_TEST_RET_ENC_ERRNO;
  48059. }
  48060. rsaCaCertBufSz = FOURK_BUF;
  48061. rsaCaPrivKeyBufSz = FOURK_BUF;
  48062. #endif /* NO_RSA */
  48063. #ifdef HAVE_ECC
  48064. /* read client ECC cert and key in DER format */
  48065. eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48066. DYNAMIC_TYPE_TMP_BUFFER);
  48067. if (ret == 0 && eccClientCertBuf == NULL) {
  48068. ret = WC_TEST_RET_ENC_ERRNO;
  48069. }
  48070. eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48071. DYNAMIC_TYPE_TMP_BUFFER);
  48072. if (ret == 0 && eccClientPrivKeyBuf == NULL) {
  48073. ret = WC_TEST_RET_ENC_ERRNO;
  48074. }
  48075. eccClientCertBufSz = FOURK_BUF;
  48076. eccClientPrivKeyBufSz = FOURK_BUF;
  48077. #endif /* HAVE_ECC */
  48078. if (ret >= 0)
  48079. ret = pkcs7_load_certs_keys(rsaClientCertBuf, &rsaClientCertBufSz,
  48080. rsaClientPrivKeyBuf, &rsaClientPrivKeyBufSz,
  48081. rsaServerCertBuf, &rsaServerCertBufSz,
  48082. rsaServerPrivKeyBuf, &rsaServerPrivKeyBufSz,
  48083. rsaCaCertBuf, &rsaCaCertBufSz,
  48084. rsaCaPrivKeyBuf, &rsaCaPrivKeyBufSz,
  48085. eccClientCertBuf, &eccClientCertBufSz,
  48086. eccClientPrivKeyBuf, &eccClientPrivKeyBufSz);
  48087. if (ret < 0) {
  48088. ret = WC_TEST_RET_ENC_EC(ret);
  48089. }
  48090. if (ret >= 0)
  48091. ret = pkcs7signed_run_vectors(rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48092. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48093. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48094. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48095. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48096. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48097. eccClientCertBuf, (word32)eccClientCertBufSz,
  48098. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48099. if (ret >= 0)
  48100. ret = pkcs7signed_run_SingleShotVectors(
  48101. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48102. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48103. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48104. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48105. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48106. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48107. eccClientCertBuf, (word32)eccClientCertBufSz,
  48108. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48109. #if !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  48110. if (ret >= 0)
  48111. ret = pkcs7callback_test(
  48112. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48113. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz);
  48114. #endif
  48115. XFREE(rsaClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48116. XFREE(rsaClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48117. XFREE(rsaServerCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48118. XFREE(rsaServerPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48119. XFREE(rsaCaCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48120. XFREE(rsaCaPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48121. XFREE(eccClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48122. XFREE(eccClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48123. return ret;
  48124. }
  48125. #endif /* HAVE_PKCS7 */
  48126. #if defined(WOLFSSL_PUBLIC_MP) && \
  48127. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48128. defined(USE_FAST_MATH))
  48129. /* Maximum number of bytes in a number to test. */
  48130. #define MP_MAX_TEST_BYTE_LEN 32
  48131. static wc_test_ret_t randNum(mp_int* n, int len, WC_RNG* rng, void* heap)
  48132. {
  48133. byte d[MP_MAX_TEST_BYTE_LEN];
  48134. wc_test_ret_t ret;
  48135. (void)heap;
  48136. do {
  48137. ret = wc_RNG_GenerateBlock(rng, d, (word32)len);
  48138. if (ret != 0)
  48139. return ret;
  48140. ret = mp_read_unsigned_bin(n, d, (word32)len);
  48141. if (ret != 0)
  48142. return ret;
  48143. } while (mp_iszero(n));
  48144. return 0;
  48145. }
  48146. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  48147. static wc_test_ret_t mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng)
  48148. {
  48149. int i, j;
  48150. mp_digit rem;
  48151. mp_digit rem2;
  48152. wc_test_ret_t ret;
  48153. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48154. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48155. for (i = 0; i < 10; i++) {
  48156. for (j = 1; j < 10; j++) {
  48157. ret = randNum(a, j, rng, NULL);
  48158. if (ret != 0)
  48159. return WC_TEST_RET_ENC_EC(ret);
  48160. ret = mp_div_3(a, r, &rem);
  48161. if (ret != 0)
  48162. return WC_TEST_RET_ENC_EC(ret);
  48163. ret = mp_mul_d(r, 3, r);
  48164. if (ret != 0)
  48165. return WC_TEST_RET_ENC_EC(ret);
  48166. ret = mp_add_d(r, rem, r);
  48167. if (ret != 0)
  48168. return WC_TEST_RET_ENC_EC(ret);
  48169. ret = mp_cmp(r, a);
  48170. if (ret != MP_EQ)
  48171. return WC_TEST_RET_ENC_NC;
  48172. }
  48173. }
  48174. ret = mp_div_3(a, r, &rem);
  48175. if (ret != 0)
  48176. return WC_TEST_RET_ENC_NC;
  48177. ret = mp_div_3(a, a, NULL);
  48178. if (ret != 0)
  48179. return WC_TEST_RET_ENC_NC;
  48180. ret = mp_cmp(r, a);
  48181. if (ret != MP_EQ)
  48182. return WC_TEST_RET_ENC_NC;
  48183. #endif
  48184. #if defined(WOLFSSL_SP_MATH_ALL)
  48185. ret = mp_div_d(a, 10, r, &rem);
  48186. if (ret != 0)
  48187. return WC_TEST_RET_ENC_EC(ret);
  48188. ret = mp_div_d(a, 10, a, NULL);
  48189. if (ret != 0)
  48190. return WC_TEST_RET_ENC_EC(ret);
  48191. ret = mp_cmp(r, a);
  48192. if (ret != MP_EQ)
  48193. return WC_TEST_RET_ENC_NC;
  48194. ret = mp_div_d(a, 12, r, &rem);
  48195. if (ret != 0)
  48196. return WC_TEST_RET_ENC_EC(ret);
  48197. ret = mp_div_d(a, 12, a, NULL);
  48198. if (ret != 0)
  48199. return WC_TEST_RET_ENC_EC(ret);
  48200. ret = mp_cmp(r, a);
  48201. if (ret != MP_EQ)
  48202. return WC_TEST_RET_ENC_NC;
  48203. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem);
  48204. if (ret != 0)
  48205. return WC_TEST_RET_ENC_EC(ret);
  48206. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2);
  48207. if (ret != 0)
  48208. return WC_TEST_RET_ENC_EC(ret);
  48209. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL);
  48210. if (ret != 0)
  48211. return WC_TEST_RET_ENC_EC(ret);
  48212. ret = mp_cmp(r, a);
  48213. if (ret != MP_EQ)
  48214. return WC_TEST_RET_ENC_NC;
  48215. if (rem != rem2)
  48216. return WC_TEST_RET_ENC_NC;
  48217. #endif
  48218. (void)a;
  48219. (void)r;
  48220. (void)rng;
  48221. (void)i;
  48222. (void)j;
  48223. (void)rem;
  48224. (void)rem2;
  48225. (void)ret;
  48226. return 0;
  48227. }
  48228. #endif /* WOLFSSL_SP_MATH || !USE_FAST_MATH */
  48229. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  48230. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48231. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  48232. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  48233. static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
  48234. {
  48235. wc_test_ret_t ret;
  48236. int i, j;
  48237. int size;
  48238. char str[30];
  48239. WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
  48240. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
  48241. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  48242. WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
  48243. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  48244. for (i = 0; i < 10; i++) {
  48245. for (j = 2; j < 12; j++) {
  48246. ret = randNum(a, j, rng, NULL);
  48247. if (ret != 0)
  48248. return WC_TEST_RET_ENC_EC(ret);
  48249. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  48250. if (ret != MP_OKAY)
  48251. return WC_TEST_RET_ENC_EC(ret);
  48252. ret = mp_toradix(a, str, MP_RADIX_DEC);
  48253. if (ret != MP_OKAY)
  48254. return WC_TEST_RET_ENC_EC(ret);
  48255. if ((int)XSTRLEN(str) != size - 1)
  48256. return WC_TEST_RET_ENC_NC;
  48257. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  48258. if (ret != MP_OKAY)
  48259. return WC_TEST_RET_ENC_EC(ret);
  48260. ret = mp_cmp(a, r);
  48261. if (ret != MP_EQ)
  48262. return WC_TEST_RET_ENC_NC;
  48263. }
  48264. }
  48265. ret = mp_read_radix(r, badStr1, MP_RADIX_DEC);
  48266. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48267. return WC_TEST_RET_ENC_EC(ret);
  48268. ret = mp_read_radix(r, badStr2, MP_RADIX_DEC);
  48269. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48270. return WC_TEST_RET_ENC_EC(ret);
  48271. ret = mp_read_radix(r, empty2, MP_RADIX_DEC);
  48272. if (ret != MP_OKAY)
  48273. return WC_TEST_RET_ENC_EC(ret);
  48274. ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
  48275. if (ret != MP_OKAY)
  48276. return WC_TEST_RET_ENC_EC(ret);
  48277. if (!mp_iszero(r))
  48278. return WC_TEST_RET_ENC_NC;
  48279. mp_set(r, 1);
  48280. ret = mp_read_radix(r, empty, MP_RADIX_DEC);
  48281. if (ret != MP_OKAY)
  48282. return WC_TEST_RET_ENC_EC(ret);
  48283. if (!mp_iszero(r))
  48284. return WC_TEST_RET_ENC_NC;
  48285. mp_zero(a);
  48286. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  48287. if (ret != 0)
  48288. return WC_TEST_RET_ENC_EC(ret);
  48289. if (size != 2)
  48290. return WC_TEST_RET_ENC_NC;
  48291. ret = mp_toradix(a, str, MP_RADIX_DEC);
  48292. if (ret != 0)
  48293. return WC_TEST_RET_ENC_EC(ret);
  48294. if ((int)XSTRLEN(str) != size - 1)
  48295. return WC_TEST_RET_ENC_NC;
  48296. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  48297. if (ret != 0)
  48298. return WC_TEST_RET_ENC_EC(ret);
  48299. if (!mp_iszero(r))
  48300. return WC_TEST_RET_ENC_NC;
  48301. return 0;
  48302. }
  48303. #endif
  48304. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  48305. defined(HAVE_ECC))
  48306. static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
  48307. {
  48308. wc_test_ret_t ret;
  48309. int i, j;
  48310. int size;
  48311. char str[30];
  48312. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  48313. static char longStr[2 * sizeof(a->dp) + 2];
  48314. #endif
  48315. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  48316. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
  48317. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  48318. for (i = 0; i < 10; i++) {
  48319. for (j = 2; j < 12; j++) {
  48320. ret = randNum(a, j, rng, NULL);
  48321. if (ret != 0)
  48322. return WC_TEST_RET_ENC_EC(ret);
  48323. mp_radix_size(a, MP_RADIX_HEX, &size);
  48324. mp_toradix(a, str, MP_RADIX_HEX);
  48325. if ((int)XSTRLEN(str) != size - 1)
  48326. return WC_TEST_RET_ENC_NC;
  48327. mp_read_radix(r, str, MP_RADIX_HEX);
  48328. ret = mp_cmp(a, r);
  48329. if (ret != MP_EQ)
  48330. return WC_TEST_RET_ENC_NC;
  48331. }
  48332. }
  48333. ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
  48334. if (ret != MP_OKAY)
  48335. return WC_TEST_RET_ENC_EC(ret);
  48336. ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
  48337. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48338. return WC_TEST_RET_ENC_EC(ret);
  48339. mp_set(r, 1);
  48340. ret = mp_read_radix(r, empty, MP_RADIX_HEX);
  48341. if (ret != MP_OKAY)
  48342. return WC_TEST_RET_ENC_EC(ret);
  48343. if (!mp_iszero(r))
  48344. return WC_TEST_RET_ENC_NC;
  48345. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  48346. /* Fixed MP data size - string can be too long. */
  48347. longStr[0] = '8';
  48348. XMEMSET(longStr+1, '0', sizeof(longStr) - 2);
  48349. longStr[sizeof(longStr)-1] = '\0';
  48350. ret = mp_read_radix(r, longStr, MP_RADIX_HEX);
  48351. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48352. return WC_TEST_RET_ENC_EC(ret);
  48353. #endif
  48354. mp_zero(a);
  48355. ret = mp_radix_size(a, MP_RADIX_HEX, &size);
  48356. if (ret != 0)
  48357. return WC_TEST_RET_ENC_EC(ret);
  48358. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  48359. if (size != 3)
  48360. #else
  48361. if (size != 2)
  48362. #endif
  48363. return WC_TEST_RET_ENC_NC;
  48364. ret = mp_toradix(a, str, MP_RADIX_HEX);
  48365. if (ret != 0)
  48366. return WC_TEST_RET_ENC_EC(ret);
  48367. if ((int)XSTRLEN(str) != size - 1)
  48368. return WC_TEST_RET_ENC_NC;
  48369. ret = mp_read_radix(r, str, MP_RADIX_HEX);
  48370. if (ret != 0)
  48371. return WC_TEST_RET_ENC_EC(ret);
  48372. if (!mp_iszero(r))
  48373. return WC_TEST_RET_ENC_NC;
  48374. #ifdef WOLFSSL_SP_MATH
  48375. ret = mp_toradix(a, str, 8);
  48376. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48377. return WC_TEST_RET_ENC_EC(ret);
  48378. ret = mp_radix_size(a, 8, &size);
  48379. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48380. return WC_TEST_RET_ENC_EC(ret);
  48381. #endif
  48382. return 0;
  48383. }
  48384. #endif
  48385. static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
  48386. {
  48387. int i;
  48388. wc_test_ret_t ret;
  48389. ret = randNum(a, 4, rng, NULL);
  48390. if (ret != 0)
  48391. return WC_TEST_RET_ENC_EC(ret);
  48392. for (i = 0; i < 4; i++) {
  48393. mp_copy(r1, a);
  48394. ret = mp_lshd(r1, i);
  48395. if (ret != MP_OKAY)
  48396. return WC_TEST_RET_ENC_EC(ret);
  48397. #ifndef WOLFSSL_SP_MATH
  48398. mp_rshd(r1, i);
  48399. #else
  48400. mp_rshb(r1, i * SP_WORD_SIZE);
  48401. #endif
  48402. ret = mp_cmp(a, r1);
  48403. if (ret != MP_EQ)
  48404. return WC_TEST_RET_ENC_NC;
  48405. }
  48406. #ifndef WOLFSSL_SP_MATH
  48407. for (i = 0; i < DIGIT_BIT+1; i++) {
  48408. ret = mp_mul_2d(a, i, r1);
  48409. if (ret != MP_OKAY)
  48410. return WC_TEST_RET_ENC_EC(ret);
  48411. mp_rshb(r1, i);
  48412. ret = mp_cmp(a, r1);
  48413. if (ret != MP_EQ)
  48414. return WC_TEST_RET_ENC_NC;
  48415. }
  48416. #endif
  48417. return 0;
  48418. }
  48419. static wc_test_ret_t mp_test_add_sub_d(mp_int* a, mp_int* r1)
  48420. {
  48421. int i, j;
  48422. wc_test_ret_t ret;
  48423. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  48424. mp_zero(a);
  48425. mp_set_bit(a, i);
  48426. if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT)
  48427. return WC_TEST_RET_ENC_NC;
  48428. for (j = 0; j < i && j < DIGIT_BIT; j++) {
  48429. mp_zero(r1);
  48430. mp_set_bit(r1, i);
  48431. ret = mp_sub_d(r1, (mp_digit)1 << j, r1);
  48432. if (ret != MP_OKAY)
  48433. return WC_TEST_RET_ENC_EC(ret);
  48434. ret = mp_add_d(r1, (mp_digit)1 << j, r1);
  48435. if (ret != MP_OKAY)
  48436. return WC_TEST_RET_ENC_EC(ret);
  48437. ret = mp_cmp(a, r1);
  48438. if (ret != MP_EQ)
  48439. return WC_TEST_RET_ENC_NC;
  48440. }
  48441. }
  48442. mp_zero(r1);
  48443. ret = mp_add_d(r1, 1, r1);
  48444. if (ret != MP_OKAY)
  48445. return WC_TEST_RET_ENC_EC(ret);
  48446. if (r1->used != 1)
  48447. return WC_TEST_RET_ENC_NC;
  48448. ret = mp_sub_d(r1, 1, r1);
  48449. if (ret != MP_OKAY)
  48450. return WC_TEST_RET_ENC_EC(ret);
  48451. if (r1->used != 0)
  48452. return WC_TEST_RET_ENC_NC;
  48453. return 0;
  48454. }
  48455. static wc_test_ret_t mp_test_read_to_bin(mp_int* a)
  48456. {
  48457. WOLFSSL_SMALL_STACK_STATIC const byte in[16] = {
  48458. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7, 0x08,
  48459. 0x93, 0xa4, 0xb4, 0xc5, 0xd6, 0xe7, 0xf8, 0x09
  48460. };
  48461. byte out[24];
  48462. int i, j, k;
  48463. const byte* p;
  48464. wc_test_ret_t ret;
  48465. for (i = 0; i < (int)sizeof(in); i++) {
  48466. p = in + sizeof(in) - i;
  48467. ret = mp_read_unsigned_bin(a, p, (word32)i);
  48468. if (ret != 0)
  48469. return WC_TEST_RET_ENC_EC(ret);
  48470. for (j = i; j < (int)sizeof(out); j++) {
  48471. XMEMSET(out, 0xff, sizeof(out));
  48472. ret = mp_to_unsigned_bin_len(a, out, j);
  48473. if (ret != 0)
  48474. return WC_TEST_RET_ENC_EC(ret);
  48475. for (k = 0; k < j - i; k++) {
  48476. if (out[k] != 0)
  48477. return WC_TEST_RET_ENC_NC;
  48478. }
  48479. for (; k < j; k++) {
  48480. if (out[k] != p[k - (j - i)])
  48481. return WC_TEST_RET_ENC_NC;
  48482. }
  48483. }
  48484. }
  48485. /* Length too small. */
  48486. ret = mp_to_unsigned_bin_len(a, out, 1);
  48487. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48488. return WC_TEST_RET_ENC_EC(ret);
  48489. ret = mp_read_unsigned_bin(a, NULL, 0);
  48490. if (ret != 0)
  48491. return WC_TEST_RET_ENC_EC(ret);
  48492. if (!mp_iszero(a))
  48493. return WC_TEST_RET_ENC_NC;
  48494. return 0;
  48495. }
  48496. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  48497. static wc_test_ret_t mp_test_set_int(mp_int* a)
  48498. {
  48499. #if SP_ULONG_BITS == 64
  48500. unsigned long n = 0xfedcba9876543210UL;
  48501. byte exp[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
  48502. byte out[8] = { 0 };
  48503. #elif SP_ULONG_BITS == 32
  48504. unsigned long n = 0xfedcba98UL;
  48505. byte exp[4] = { 0xfe, 0xdc, 0xba, 0x98 };
  48506. byte out[4] = { 0 };
  48507. #elif SP_ULONG_BITS == 16
  48508. unsigned long n = 0xfedc;
  48509. byte exp[2] = { 0xfe, 0xdc };
  48510. byte out[2] = { 0 };
  48511. #elif SP_ULONG_BITS == 8
  48512. unsigned long n = 0xfe;
  48513. byte exp[1] = { 0xfe };
  48514. byte out[1] = { 0 };
  48515. #endif
  48516. wc_test_ret_t ret;
  48517. ret = mp_set_int(a, n);
  48518. if (ret != 0)
  48519. return WC_TEST_RET_ENC_EC(ret);
  48520. ret = mp_unsigned_bin_size(a);
  48521. if (ret != sizeof(exp))
  48522. return WC_TEST_RET_ENC_NC;
  48523. ret = mp_to_unsigned_bin(a, out);
  48524. if (ret != 0)
  48525. return WC_TEST_RET_ENC_EC(ret);
  48526. if (XMEMCMP(exp, out, sizeof(exp)) != 0)
  48527. return WC_TEST_RET_ENC_NC;
  48528. return 0;
  48529. }
  48530. #endif
  48531. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  48532. static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
  48533. {
  48534. byte buffer[16];
  48535. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  48536. char hexStr[] = "abcdef0123456789";
  48537. #ifndef WOLFSSL_SP_INT_NEGATIVE
  48538. char negStr[] = "-1234";
  48539. #endif
  48540. #endif
  48541. #if !defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
  48542. defined(HAVE_COMP_KEY)
  48543. char decStr[] = "0987654321";
  48544. #endif
  48545. wc_test_ret_t ret;
  48546. #ifdef WOLFSSL_SP_MATH_ALL
  48547. mp_digit rho;
  48548. int size;
  48549. #endif
  48550. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  48551. int result;
  48552. #endif
  48553. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  48554. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  48555. mp_digit rd;
  48556. #endif
  48557. (void)rng;
  48558. (void)r;
  48559. ret = mp_init(NULL);
  48560. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48561. return WC_TEST_RET_ENC_EC(ret);
  48562. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  48563. ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL);
  48564. if (ret != MP_OKAY)
  48565. return WC_TEST_RET_ENC_EC(ret);
  48566. #endif
  48567. mp_free(NULL);
  48568. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  48569. ret = mp_grow(NULL, 1);
  48570. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48571. return WC_TEST_RET_ENC_EC(ret);
  48572. #ifdef WOLFSSL_SP_MATH
  48573. ret = mp_grow(a, SP_INT_DIGITS + 1);
  48574. if (ret != WC_NO_ERR_TRACE(MP_MEM))
  48575. return WC_TEST_RET_ENC_EC(ret);
  48576. #endif
  48577. #endif
  48578. mp_clear(NULL);
  48579. ret = mp_abs(NULL, NULL);
  48580. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48581. return WC_TEST_RET_ENC_EC(ret);
  48582. ret = mp_abs(a, NULL);
  48583. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48584. return WC_TEST_RET_ENC_EC(ret);
  48585. ret = mp_abs(NULL, b);
  48586. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48587. return WC_TEST_RET_ENC_EC(ret);
  48588. ret = mp_unsigned_bin_size(NULL);
  48589. if (ret != 0)
  48590. return WC_TEST_RET_ENC_EC(ret);
  48591. /* clear buffer to avoid provoking uninitvar errors. */
  48592. XMEMSET(buffer, 0, sizeof(buffer));
  48593. ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer));
  48594. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48595. return WC_TEST_RET_ENC_EC(ret);
  48596. ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer));
  48597. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48598. return WC_TEST_RET_ENC_EC(ret);
  48599. ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
  48600. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48601. return WC_TEST_RET_ENC_EC(ret);
  48602. ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
  48603. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48604. return WC_TEST_RET_ENC_EC(ret);
  48605. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  48606. ret = mp_read_radix(NULL, NULL, 16);
  48607. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48608. return WC_TEST_RET_ENC_EC(ret);
  48609. ret = mp_read_radix(a, NULL, 16);
  48610. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48611. return WC_TEST_RET_ENC_EC(ret);
  48612. ret = mp_read_radix(NULL, hexStr, 16);
  48613. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48614. return WC_TEST_RET_ENC_EC(ret);
  48615. #ifndef WOLFSSL_SP_INT_NEGATIVE
  48616. ret = mp_read_radix(a, negStr, 16);
  48617. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48618. return WC_TEST_RET_ENC_EC(ret);
  48619. #ifdef WOLFSSL_SP_MATH_ALL
  48620. ret = mp_read_radix(a, negStr, 10);
  48621. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48622. return WC_TEST_RET_ENC_EC(ret);
  48623. #endif /* WOLFSSL_SP_MATH_ALL */
  48624. #endif /* WOLFSSL_SP_INT_NEGATIVE */
  48625. #endif
  48626. #ifndef WOLFSSL_SP_MATH_ALL
  48627. /* Radix 10 only supported with ALL. */
  48628. ret = mp_read_radix(a, decStr, 10);
  48629. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48630. return WC_TEST_RET_ENC_EC(ret);
  48631. #endif
  48632. /* Radix 8 not supported SP_INT. */
  48633. ret = mp_read_radix(a, "0123", 8);
  48634. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48635. return WC_TEST_RET_ENC_EC(ret);
  48636. ret = mp_count_bits(NULL);
  48637. if (ret != 0)
  48638. return WC_TEST_RET_ENC_EC(ret);
  48639. ret = mp_is_bit_set(NULL, 0);
  48640. if (ret != 0)
  48641. return WC_TEST_RET_ENC_EC(ret);
  48642. ret = mp_leading_bit(NULL);
  48643. if (ret != 0)
  48644. return WC_TEST_RET_ENC_EC(ret);
  48645. mp_zero(a);
  48646. ret = mp_leading_bit(a);
  48647. if (ret != 0)
  48648. return WC_TEST_RET_ENC_EC(ret);
  48649. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  48650. defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \
  48651. !defined(NO_RSA)
  48652. ret = mp_set_bit(NULL, 1);
  48653. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48654. return WC_TEST_RET_ENC_EC(ret);
  48655. #endif
  48656. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  48657. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48658. ret = mp_to_unsigned_bin(NULL, NULL);
  48659. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48660. return WC_TEST_RET_ENC_EC(ret);
  48661. ret = mp_to_unsigned_bin(a, NULL);
  48662. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48663. return WC_TEST_RET_ENC_EC(ret);
  48664. ret = mp_to_unsigned_bin(NULL, buffer);
  48665. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48666. return WC_TEST_RET_ENC_EC(ret);
  48667. #endif
  48668. ret = mp_to_unsigned_bin_len(NULL, NULL, 1);
  48669. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48670. return WC_TEST_RET_ENC_EC(ret);
  48671. ret = mp_to_unsigned_bin_len(a, NULL, 1);
  48672. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48673. return WC_TEST_RET_ENC_EC(ret);
  48674. ret = mp_to_unsigned_bin_len(NULL, buffer, 1);
  48675. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48676. return WC_TEST_RET_ENC_EC(ret);
  48677. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  48678. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48679. ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL);
  48680. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48681. return WC_TEST_RET_ENC_EC(ret);
  48682. ret = mp_to_unsigned_bin_at_pos(0, a, NULL);
  48683. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48684. return WC_TEST_RET_ENC_EC(ret);
  48685. ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer);
  48686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48687. return WC_TEST_RET_ENC_EC(ret);
  48688. ret = mp_to_unsigned_bin_at_pos(0, a, buffer);
  48689. if (ret != MP_OKAY)
  48690. return WC_TEST_RET_ENC_EC(ret);
  48691. #endif
  48692. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  48693. ret = mp_copy(NULL, NULL);
  48694. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48695. return WC_TEST_RET_ENC_EC(ret);
  48696. ret = mp_copy(a, NULL);
  48697. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48698. return WC_TEST_RET_ENC_EC(ret);
  48699. ret = mp_copy(NULL, b);
  48700. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48701. return WC_TEST_RET_ENC_EC(ret);
  48702. #endif
  48703. #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH)
  48704. ret = sp_2expt(NULL, 1);
  48705. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48706. return WC_TEST_RET_ENC_EC(ret);
  48707. #endif
  48708. ret = mp_set(NULL, 0);
  48709. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48710. return WC_TEST_RET_ENC_EC(ret);
  48711. ret = mp_cmp_d(NULL, 0);
  48712. if (ret != MP_LT)
  48713. return WC_TEST_RET_ENC_EC(ret);
  48714. ret = mp_cmp(NULL, NULL);
  48715. if (ret != MP_EQ)
  48716. return WC_TEST_RET_ENC_NC;
  48717. ret = mp_cmp(a, NULL);
  48718. if (ret != MP_GT)
  48719. return WC_TEST_RET_ENC_NC;
  48720. ret = mp_cmp(NULL, b);
  48721. if (ret != MP_LT)
  48722. return WC_TEST_RET_ENC_NC;
  48723. #ifdef WOLFSSL_SP_MATH_ALL
  48724. mp_rshd(NULL, 1);
  48725. #endif
  48726. mp_zero(NULL);
  48727. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  48728. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48729. ret = mp_lshd(NULL, 0);
  48730. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48731. return WC_TEST_RET_ENC_EC(ret);
  48732. ret = mp_lshd(a, SP_INT_DIGITS + 1);
  48733. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48734. return WC_TEST_RET_ENC_EC(ret);
  48735. #endif
  48736. #if defined(WOLFSSL_SP_MATH_ALL)
  48737. ret = mp_div(NULL, NULL, a, b);
  48738. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48739. return WC_TEST_RET_ENC_EC(ret);
  48740. ret = mp_div(a, NULL, a, b);
  48741. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48742. return WC_TEST_RET_ENC_EC(ret);
  48743. ret = mp_div(NULL, b, a, b);
  48744. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48745. return WC_TEST_RET_ENC_EC(ret);
  48746. ret = mp_div(a, b, NULL, NULL);
  48747. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48748. return WC_TEST_RET_ENC_EC(ret);
  48749. #endif
  48750. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  48751. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  48752. ret = mp_mod(NULL, NULL, NULL);
  48753. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48754. return WC_TEST_RET_ENC_EC(ret);
  48755. ret = mp_mod(a, NULL, NULL);
  48756. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48757. return WC_TEST_RET_ENC_EC(ret);
  48758. ret = mp_mod(NULL, b, NULL);
  48759. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48760. return WC_TEST_RET_ENC_EC(ret);
  48761. ret = mp_mod(NULL, NULL, r);
  48762. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48763. return WC_TEST_RET_ENC_EC(ret);
  48764. ret = mp_mod(a, b, NULL);
  48765. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48766. return WC_TEST_RET_ENC_EC(ret);
  48767. ret = mp_mod(a, NULL, r);
  48768. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48769. return WC_TEST_RET_ENC_EC(ret);
  48770. ret = mp_mod(NULL, b, r);
  48771. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48772. return WC_TEST_RET_ENC_EC(ret);
  48773. #endif
  48774. #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL)
  48775. ret = mp_set_int(NULL, 0);
  48776. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48777. return WC_TEST_RET_ENC_EC(ret);
  48778. #endif
  48779. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  48780. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  48781. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  48782. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48783. return WC_TEST_RET_ENC_EC(ret);
  48784. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  48785. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48786. return WC_TEST_RET_ENC_EC(ret);
  48787. ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL);
  48788. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48789. return WC_TEST_RET_ENC_EC(ret);
  48790. ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL);
  48791. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48792. return WC_TEST_RET_ENC_EC(ret);
  48793. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  48794. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48795. return WC_TEST_RET_ENC_EC(ret);
  48796. ret = mp_exptmod_ex(a, a, 1, a, NULL);
  48797. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48798. return WC_TEST_RET_ENC_EC(ret);
  48799. ret = mp_exptmod_ex(a, a, 1, NULL, a);
  48800. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48801. return WC_TEST_RET_ENC_EC(ret);
  48802. ret = mp_exptmod_ex(a, NULL, 1, a, a);
  48803. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48804. return WC_TEST_RET_ENC_EC(ret);
  48805. ret = mp_exptmod_ex(NULL, a, 1, a, a);
  48806. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48807. return WC_TEST_RET_ENC_EC(ret);
  48808. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  48809. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48810. return WC_TEST_RET_ENC_EC(ret);
  48811. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  48812. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48813. return WC_TEST_RET_ENC_EC(ret);
  48814. ret = mp_exptmod_nct(NULL, a, NULL, NULL);
  48815. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48816. return WC_TEST_RET_ENC_EC(ret);
  48817. ret = mp_exptmod_nct(NULL, NULL, a, NULL);
  48818. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48819. return WC_TEST_RET_ENC_EC(ret);
  48820. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  48821. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48822. return WC_TEST_RET_ENC_EC(ret);
  48823. ret = mp_exptmod_nct(a, a, a, NULL);
  48824. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48825. return WC_TEST_RET_ENC_EC(ret);
  48826. ret = mp_exptmod_nct(a, a, NULL, a);
  48827. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48828. return WC_TEST_RET_ENC_EC(ret);
  48829. ret = mp_exptmod_nct(a, NULL, a, a);
  48830. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48831. return WC_TEST_RET_ENC_EC(ret);
  48832. ret = mp_exptmod_nct(NULL, a, a, a);
  48833. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48834. return WC_TEST_RET_ENC_EC(ret);
  48835. #endif
  48836. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  48837. !defined(WC_NO_RNG)
  48838. ret = mp_rand_prime(NULL, 32, NULL, NULL);
  48839. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48840. return WC_TEST_RET_ENC_EC(ret);
  48841. ret = mp_rand_prime(a, 32, NULL, NULL);
  48842. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48843. return WC_TEST_RET_ENC_EC(ret);
  48844. ret = mp_rand_prime(NULL, 32, rng, NULL);
  48845. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48846. return WC_TEST_RET_ENC_EC(ret);
  48847. ret = mp_rand_prime(a, 0, rng, NULL);
  48848. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48849. return WC_TEST_RET_ENC_EC(ret);
  48850. #endif
  48851. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48852. ret = mp_mul(NULL, NULL, NULL);
  48853. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48854. return WC_TEST_RET_ENC_EC(ret);
  48855. ret = mp_mul(a, NULL, NULL);
  48856. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48857. return WC_TEST_RET_ENC_EC(ret);
  48858. ret = mp_mul(NULL, b, NULL);
  48859. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48860. return WC_TEST_RET_ENC_EC(ret);
  48861. ret = mp_mul(NULL, NULL, r);
  48862. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48863. return WC_TEST_RET_ENC_EC(ret);
  48864. ret = mp_mul(a, b, NULL);
  48865. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48866. return WC_TEST_RET_ENC_EC(ret);
  48867. ret = mp_mul(a, NULL, r);
  48868. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48869. return WC_TEST_RET_ENC_EC(ret);
  48870. ret = mp_mul(NULL, b, r);
  48871. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48872. return WC_TEST_RET_ENC_EC(ret);
  48873. #endif
  48874. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  48875. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  48876. ret = mp_sqr(NULL, NULL);
  48877. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48878. return WC_TEST_RET_ENC_EC(ret);
  48879. ret = mp_sqr(a, NULL);
  48880. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48881. return WC_TEST_RET_ENC_EC(ret);
  48882. ret = mp_sqr(NULL, r);
  48883. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48884. return WC_TEST_RET_ENC_EC(ret);
  48885. #endif
  48886. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48887. ret = mp_sqrmod(NULL, NULL, NULL);
  48888. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48889. return WC_TEST_RET_ENC_EC(ret);
  48890. ret = mp_sqrmod(a, NULL, NULL);
  48891. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48892. return WC_TEST_RET_ENC_EC(ret);
  48893. ret = mp_sqrmod(NULL, a, NULL);
  48894. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48895. return WC_TEST_RET_ENC_EC(ret);
  48896. ret = mp_sqrmod(NULL, NULL, a);
  48897. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48898. return WC_TEST_RET_ENC_EC(ret);
  48899. ret = mp_sqrmod(a, b, NULL);
  48900. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48901. return WC_TEST_RET_ENC_EC(ret);
  48902. ret = mp_sqrmod(a, NULL, b);
  48903. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48904. return WC_TEST_RET_ENC_EC(ret);
  48905. ret = mp_sqrmod(NULL, a, b);
  48906. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48907. return WC_TEST_RET_ENC_EC(ret);
  48908. ret = mp_mulmod(NULL, NULL, NULL, NULL);
  48909. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48910. return WC_TEST_RET_ENC_EC(ret);
  48911. ret = mp_mulmod(a, NULL, NULL, NULL);
  48912. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48913. return WC_TEST_RET_ENC_EC(ret);
  48914. ret = mp_mulmod(NULL, a, NULL, NULL);
  48915. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48916. return WC_TEST_RET_ENC_EC(ret);
  48917. ret = mp_mulmod(NULL, NULL, a, NULL);
  48918. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48919. return WC_TEST_RET_ENC_EC(ret);
  48920. ret = mp_mulmod(NULL, NULL, NULL, a);
  48921. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48922. return WC_TEST_RET_ENC_EC(ret);
  48923. ret = mp_mulmod(a, b, b, NULL);
  48924. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48925. return WC_TEST_RET_ENC_EC(ret);
  48926. ret = mp_mulmod(a, b, NULL, a);
  48927. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48928. return WC_TEST_RET_ENC_EC(ret);
  48929. ret = mp_mulmod(a, NULL, b, a);
  48930. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48931. return WC_TEST_RET_ENC_EC(ret);
  48932. ret = mp_mulmod(NULL, b, b, a);
  48933. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48934. return WC_TEST_RET_ENC_EC(ret);
  48935. #endif
  48936. #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
  48937. !defined(NO_RSA) || !defined(NO_DSA)
  48938. ret = mp_add_d(NULL, 1, NULL);
  48939. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48940. return WC_TEST_RET_ENC_EC(ret);
  48941. ret = mp_add_d(a, 1, NULL);
  48942. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48943. return WC_TEST_RET_ENC_EC(ret);
  48944. ret = mp_add_d(NULL, 1, b);
  48945. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48946. return WC_TEST_RET_ENC_EC(ret);
  48947. #endif
  48948. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48949. !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA)
  48950. ret = mp_sub_d(NULL, 1, NULL);
  48951. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48952. return WC_TEST_RET_ENC_EC(ret);
  48953. ret = mp_sub_d(a, 1, NULL);
  48954. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48955. return WC_TEST_RET_ENC_EC(ret);
  48956. ret = mp_sub_d(NULL, 1, b);
  48957. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48958. return WC_TEST_RET_ENC_EC(ret);
  48959. #endif
  48960. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48961. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48962. ret = mp_div_d(NULL, 0, NULL, NULL);
  48963. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48964. return WC_TEST_RET_ENC_EC(ret);
  48965. ret = mp_div_d(a, 0, NULL, NULL);
  48966. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48967. return WC_TEST_RET_ENC_EC(ret);
  48968. ret = mp_div_d(NULL, 1, NULL, NULL);
  48969. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48970. return WC_TEST_RET_ENC_EC(ret);
  48971. #endif
  48972. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  48973. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  48974. ret = mp_mod_d(NULL, 0, NULL);
  48975. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48976. return WC_TEST_RET_ENC_EC(ret);
  48977. ret = mp_mod_d(a, 0, NULL);
  48978. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48979. return WC_TEST_RET_ENC_EC(ret);
  48980. ret = mp_mod_d(NULL, 0, &rd);
  48981. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48982. return WC_TEST_RET_ENC_EC(ret);
  48983. #endif
  48984. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  48985. ret = mp_gcd(NULL, NULL, NULL);
  48986. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48987. return WC_TEST_RET_ENC_EC(ret);
  48988. ret = mp_gcd(a, NULL, NULL);
  48989. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48990. return WC_TEST_RET_ENC_EC(ret);
  48991. ret = mp_gcd(NULL, a, NULL);
  48992. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48993. return WC_TEST_RET_ENC_EC(ret);
  48994. ret = mp_gcd(NULL, NULL, a);
  48995. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48996. return WC_TEST_RET_ENC_EC(ret);
  48997. ret = mp_gcd(a, b, NULL);
  48998. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48999. return WC_TEST_RET_ENC_EC(ret);
  49000. ret = mp_gcd(a, NULL, b);
  49001. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49002. return WC_TEST_RET_ENC_EC(ret);
  49003. ret = mp_gcd(NULL, a, b);
  49004. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49005. return WC_TEST_RET_ENC_EC(ret);
  49006. #endif
  49007. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49008. ret = mp_div_2_mod_ct(NULL, NULL, NULL);
  49009. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49010. return WC_TEST_RET_ENC_EC(ret);
  49011. ret = mp_div_2_mod_ct(a, NULL, NULL);
  49012. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49013. return WC_TEST_RET_ENC_EC(ret);
  49014. ret = mp_div_2_mod_ct(NULL, b, NULL);
  49015. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49016. return WC_TEST_RET_ENC_EC(ret);
  49017. ret = mp_div_2_mod_ct(NULL, NULL, a);
  49018. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49019. return WC_TEST_RET_ENC_EC(ret);
  49020. ret = mp_div_2_mod_ct(a, b, NULL);
  49021. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49022. return WC_TEST_RET_ENC_EC(ret);
  49023. ret = mp_div_2_mod_ct(a, b, NULL);
  49024. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49025. return WC_TEST_RET_ENC_EC(ret);
  49026. ret = mp_div_2_mod_ct(NULL, b, a);
  49027. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49028. return WC_TEST_RET_ENC_EC(ret);
  49029. ret = mp_div_2(NULL, NULL);
  49030. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49031. return WC_TEST_RET_ENC_EC(ret);
  49032. ret = mp_div_2(a, NULL);
  49033. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49034. return WC_TEST_RET_ENC_EC(ret);
  49035. ret = mp_div_2(NULL, a);
  49036. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49037. return WC_TEST_RET_ENC_EC(ret);
  49038. #endif
  49039. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49040. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  49041. ret = mp_invmod(NULL, NULL, NULL);
  49042. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49043. return WC_TEST_RET_ENC_EC(ret);
  49044. ret = mp_invmod(a, NULL, NULL);
  49045. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49046. return WC_TEST_RET_ENC_EC(ret);
  49047. ret = mp_invmod(NULL, b, NULL);
  49048. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49049. return WC_TEST_RET_ENC_EC(ret);
  49050. ret = mp_invmod(NULL, NULL, a);
  49051. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49052. return WC_TEST_RET_ENC_EC(ret);
  49053. ret = mp_invmod(a, b, NULL);
  49054. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49055. return WC_TEST_RET_ENC_EC(ret);
  49056. ret = mp_invmod(a, NULL, a);
  49057. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49058. return WC_TEST_RET_ENC_EC(ret);
  49059. ret = mp_invmod(NULL, b, a);
  49060. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49061. return WC_TEST_RET_ENC_EC(ret);
  49062. #endif
  49063. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49064. ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1);
  49065. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49066. return WC_TEST_RET_ENC_EC(ret);
  49067. ret = mp_invmod_mont_ct(a, NULL, NULL, 1);
  49068. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49069. return WC_TEST_RET_ENC_EC(ret);
  49070. ret = mp_invmod_mont_ct(NULL, b, NULL, 1);
  49071. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49072. return WC_TEST_RET_ENC_EC(ret);
  49073. ret = mp_invmod_mont_ct(NULL, NULL, a, 1);
  49074. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49075. return WC_TEST_RET_ENC_EC(ret);
  49076. ret = mp_invmod_mont_ct(a, b, NULL, 1);
  49077. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49078. return WC_TEST_RET_ENC_EC(ret);
  49079. ret = mp_invmod_mont_ct(a, NULL, a, 1);
  49080. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49081. return WC_TEST_RET_ENC_EC(ret);
  49082. ret = mp_invmod_mont_ct(NULL, b, a, 1);
  49083. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49084. return WC_TEST_RET_ENC_EC(ret);
  49085. #endif
  49086. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49087. ret = mp_lcm(NULL, NULL, NULL);
  49088. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49089. return WC_TEST_RET_ENC_EC(ret);
  49090. ret = mp_lcm(a, NULL, NULL);
  49091. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49092. return WC_TEST_RET_ENC_EC(ret);
  49093. ret = mp_lcm(NULL, b, NULL);
  49094. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49095. return WC_TEST_RET_ENC_EC(ret);
  49096. ret = mp_lcm(NULL, NULL, a);
  49097. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49098. return WC_TEST_RET_ENC_EC(ret);
  49099. ret = mp_lcm(a, b, NULL);
  49100. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49101. return WC_TEST_RET_ENC_EC(ret);
  49102. ret = mp_lcm(a, NULL, a);
  49103. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49104. return WC_TEST_RET_ENC_EC(ret);
  49105. ret = mp_lcm(NULL, b, a);
  49106. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49107. return WC_TEST_RET_ENC_EC(ret);
  49108. #endif
  49109. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49110. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49111. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49112. return WC_TEST_RET_ENC_EC(ret);
  49113. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49114. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49115. return WC_TEST_RET_ENC_EC(ret);
  49116. ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL);
  49117. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49118. return WC_TEST_RET_ENC_EC(ret);
  49119. ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL);
  49120. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49121. return WC_TEST_RET_ENC_EC(ret);
  49122. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49123. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49124. return WC_TEST_RET_ENC_EC(ret);
  49125. ret = mp_exptmod_ex(a, b, 1, b, NULL);
  49126. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49127. return WC_TEST_RET_ENC_EC(ret);
  49128. ret = mp_exptmod_ex(a, b, 1, NULL, a);
  49129. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49130. return WC_TEST_RET_ENC_EC(ret);
  49131. ret = mp_exptmod_ex(a, NULL, 1, b, a);
  49132. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49133. return WC_TEST_RET_ENC_EC(ret);
  49134. ret = mp_exptmod_ex(NULL, b, 1, b, a);
  49135. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49136. return WC_TEST_RET_ENC_EC(ret);
  49137. ret = mp_exptmod(NULL, NULL, NULL, NULL);
  49138. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49139. return WC_TEST_RET_ENC_EC(ret);
  49140. ret = mp_exptmod(a, NULL, NULL, NULL);
  49141. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49142. return WC_TEST_RET_ENC_EC(ret);
  49143. ret = mp_exptmod(NULL, b, NULL, NULL);
  49144. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49145. return WC_TEST_RET_ENC_EC(ret);
  49146. ret = mp_exptmod(NULL, NULL, b, NULL);
  49147. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49148. return WC_TEST_RET_ENC_EC(ret);
  49149. ret = mp_exptmod(NULL, NULL, NULL, a);
  49150. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49151. return WC_TEST_RET_ENC_EC(ret);
  49152. ret = mp_exptmod(a, b, b, NULL);
  49153. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49154. return WC_TEST_RET_ENC_EC(ret);
  49155. ret = mp_exptmod(a, b, NULL, a);
  49156. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49157. return WC_TEST_RET_ENC_EC(ret);
  49158. ret = mp_exptmod(a, NULL, b, a);
  49159. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49160. return WC_TEST_RET_ENC_EC(ret);
  49161. ret = mp_exptmod(NULL, b, b, a);
  49162. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49163. return WC_TEST_RET_ENC_EC(ret);
  49164. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49165. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49166. return WC_TEST_RET_ENC_EC(ret);
  49167. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49168. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49169. return WC_TEST_RET_ENC_EC(ret);
  49170. ret = mp_exptmod_nct(NULL, b, NULL, NULL);
  49171. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49172. return WC_TEST_RET_ENC_EC(ret);
  49173. ret = mp_exptmod_nct(NULL, NULL, b, NULL);
  49174. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49175. return WC_TEST_RET_ENC_EC(ret);
  49176. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49177. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49178. return WC_TEST_RET_ENC_EC(ret);
  49179. ret = mp_exptmod_nct(a, b, b, NULL);
  49180. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49181. return WC_TEST_RET_ENC_EC(ret);
  49182. ret = mp_exptmod_nct(a, b, NULL, a);
  49183. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49184. return WC_TEST_RET_ENC_EC(ret);
  49185. ret = mp_exptmod_nct(a, NULL, b, a);
  49186. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49187. return WC_TEST_RET_ENC_EC(ret);
  49188. ret = mp_exptmod_nct(NULL, b, b, a);
  49189. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49190. return WC_TEST_RET_ENC_EC(ret);
  49191. #endif
  49192. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  49193. ret = mp_cnt_lsb(NULL);
  49194. if (ret != 0)
  49195. return WC_TEST_RET_ENC_EC(ret);
  49196. #endif
  49197. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49198. ret = mp_prime_is_prime(NULL, 1, NULL);
  49199. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49200. return WC_TEST_RET_ENC_EC(ret);
  49201. ret = mp_prime_is_prime(a, 1, NULL);
  49202. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49203. return WC_TEST_RET_ENC_EC(ret);
  49204. ret = mp_prime_is_prime(NULL, 1, &result);
  49205. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49206. return WC_TEST_RET_ENC_EC(ret);
  49207. ret = mp_prime_is_prime(a, 0, &result);
  49208. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49209. return WC_TEST_RET_ENC_EC(ret);
  49210. ret = mp_prime_is_prime(a, 1024, &result);
  49211. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49212. return WC_TEST_RET_ENC_EC(ret);
  49213. ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL);
  49214. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49215. return WC_TEST_RET_ENC_EC(ret);
  49216. ret = mp_prime_is_prime_ex(a, 1, NULL, NULL);
  49217. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49218. return WC_TEST_RET_ENC_EC(ret);
  49219. ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL);
  49220. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49221. return WC_TEST_RET_ENC_EC(ret);
  49222. ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng);
  49223. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49224. return WC_TEST_RET_ENC_EC(ret);
  49225. ret = mp_prime_is_prime_ex(a, 1, &result, NULL);
  49226. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49227. return WC_TEST_RET_ENC_EC(ret);
  49228. ret = mp_prime_is_prime_ex(a, 1, NULL, rng);
  49229. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49230. return WC_TEST_RET_ENC_EC(ret);
  49231. ret = mp_prime_is_prime_ex(NULL, 1, &result, rng);
  49232. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49233. return WC_TEST_RET_ENC_EC(ret);
  49234. #endif
  49235. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
  49236. ret = mp_exch(NULL, NULL);
  49237. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49238. return WC_TEST_RET_ENC_EC(ret);
  49239. ret = mp_exch(a, NULL);
  49240. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49241. return WC_TEST_RET_ENC_EC(ret);
  49242. ret = mp_exch(NULL, b);
  49243. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49244. return WC_TEST_RET_ENC_EC(ret);
  49245. #endif
  49246. #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \
  49247. defined(WOLFSSL_SP_MATH_ALL)
  49248. ret = mp_mul_d(NULL, 1, NULL);
  49249. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49250. return WC_TEST_RET_ENC_EC(ret);
  49251. ret = mp_mul_d(a, 1, NULL);
  49252. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49253. return WC_TEST_RET_ENC_EC(ret);
  49254. ret = mp_mul_d(NULL, 1, b);
  49255. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49256. return WC_TEST_RET_ENC_EC(ret);
  49257. #endif
  49258. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49259. ret = mp_add(NULL, NULL, NULL);
  49260. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49261. return WC_TEST_RET_ENC_EC(ret);
  49262. ret = mp_add(a, NULL, NULL);
  49263. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49264. return WC_TEST_RET_ENC_EC(ret);
  49265. ret = mp_add(NULL, b, NULL);
  49266. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49267. return WC_TEST_RET_ENC_EC(ret);
  49268. ret = mp_add(NULL, NULL, r);
  49269. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49270. return WC_TEST_RET_ENC_EC(ret);
  49271. ret = mp_add(a, b, NULL);
  49272. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49273. return WC_TEST_RET_ENC_EC(ret);
  49274. ret = mp_add(a, NULL, r);
  49275. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49276. return WC_TEST_RET_ENC_EC(ret);
  49277. ret = mp_add(NULL, b, r);
  49278. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49279. return WC_TEST_RET_ENC_EC(ret);
  49280. #endif
  49281. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49282. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49283. ret = mp_sub(NULL, NULL, NULL);
  49284. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49285. return WC_TEST_RET_ENC_EC(ret);
  49286. ret = mp_sub(a, NULL, NULL);
  49287. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49288. return WC_TEST_RET_ENC_EC(ret);
  49289. ret = mp_sub(NULL, b, NULL);
  49290. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49291. return WC_TEST_RET_ENC_EC(ret);
  49292. ret = mp_sub(NULL, NULL, r);
  49293. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49294. return WC_TEST_RET_ENC_EC(ret);
  49295. ret = mp_sub(a, b, NULL);
  49296. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49297. return WC_TEST_RET_ENC_EC(ret);
  49298. ret = mp_sub(a, NULL, r);
  49299. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49300. return WC_TEST_RET_ENC_EC(ret);
  49301. ret = mp_sub(NULL, b, r);
  49302. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49303. return WC_TEST_RET_ENC_EC(ret);
  49304. #endif
  49305. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
  49306. defined(WOLFSSL_CUSTOM_CURVES))
  49307. ret = mp_addmod(NULL, NULL, NULL, NULL);
  49308. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49309. return WC_TEST_RET_ENC_EC(ret);
  49310. ret = mp_addmod(a, NULL, NULL, NULL);
  49311. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49312. return WC_TEST_RET_ENC_EC(ret);
  49313. ret = mp_addmod(NULL, b, NULL, NULL);
  49314. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49315. return WC_TEST_RET_ENC_EC(ret);
  49316. ret = mp_addmod(NULL, NULL, b, NULL);
  49317. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49318. return WC_TEST_RET_ENC_EC(ret);
  49319. ret = mp_addmod(NULL, NULL, NULL, a);
  49320. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49321. return WC_TEST_RET_ENC_EC(ret);
  49322. ret = mp_addmod(a, b, b, NULL);
  49323. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49324. return WC_TEST_RET_ENC_EC(ret);
  49325. ret = mp_addmod(a, b, NULL, a);
  49326. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49327. return WC_TEST_RET_ENC_EC(ret);
  49328. ret = mp_addmod(a, NULL, b, a);
  49329. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49330. return WC_TEST_RET_ENC_EC(ret);
  49331. ret = mp_addmod(NULL, b, b, a);
  49332. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49333. return WC_TEST_RET_ENC_EC(ret);
  49334. #endif
  49335. #ifdef WOLFSSL_SP_MATH_ALL
  49336. ret = mp_submod(NULL, NULL, NULL, NULL);
  49337. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49338. return WC_TEST_RET_ENC_EC(ret);
  49339. ret = mp_submod(a, NULL, NULL, NULL);
  49340. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49341. return WC_TEST_RET_ENC_EC(ret);
  49342. ret = mp_submod(NULL, b, NULL, NULL);
  49343. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49344. return WC_TEST_RET_ENC_EC(ret);
  49345. ret = mp_submod(NULL, NULL, b, NULL);
  49346. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49347. return WC_TEST_RET_ENC_EC(ret);
  49348. ret = mp_submod(NULL, NULL, NULL, a);
  49349. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49350. return WC_TEST_RET_ENC_EC(ret);
  49351. ret = mp_submod(a, b, b, NULL);
  49352. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49353. return WC_TEST_RET_ENC_EC(ret);
  49354. ret = mp_submod(a, b, NULL, a);
  49355. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49356. return WC_TEST_RET_ENC_EC(ret);
  49357. ret = mp_submod(a, NULL, b, a);
  49358. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49359. return WC_TEST_RET_ENC_EC(ret);
  49360. ret = mp_submod(NULL, b, b, a);
  49361. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49362. return WC_TEST_RET_ENC_EC(ret);
  49363. #endif
  49364. #ifdef WOLFSSL_SP_MATH_ALL
  49365. ret = mp_div_2d(NULL, 1, a, b);
  49366. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49367. return WC_TEST_RET_ENC_EC(ret);
  49368. ret = mp_mod_2d(NULL, 1, NULL);
  49369. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49370. return WC_TEST_RET_ENC_EC(ret);
  49371. ret = mp_mod_2d(a, 1, NULL);
  49372. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49373. return WC_TEST_RET_ENC_EC(ret);
  49374. ret = mp_mod_2d(NULL, 1, b);
  49375. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49376. return WC_TEST_RET_ENC_EC(ret);
  49377. ret = mp_mul_2d(NULL, 1, NULL);
  49378. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49379. return WC_TEST_RET_ENC_EC(ret);
  49380. ret = mp_mul_2d(a, 1, NULL);
  49381. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49382. return WC_TEST_RET_ENC_EC(ret);
  49383. ret = mp_mul_2d(NULL, 1, b);
  49384. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49385. return WC_TEST_RET_ENC_EC(ret);
  49386. #endif
  49387. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49388. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49389. ret = mp_montgomery_reduce(NULL, NULL, 1);
  49390. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49391. return WC_TEST_RET_ENC_EC(ret);
  49392. ret = mp_montgomery_reduce(a, NULL, 1);
  49393. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49394. return WC_TEST_RET_ENC_EC(ret);
  49395. ret = mp_montgomery_reduce(NULL, b, 1);
  49396. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49397. return WC_TEST_RET_ENC_EC(ret);
  49398. mp_zero(b);
  49399. ret = mp_montgomery_reduce(a, b, 1);
  49400. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49401. return WC_TEST_RET_ENC_EC(ret);
  49402. #endif
  49403. #ifdef WOLFSSL_SP_MATH_ALL
  49404. ret = mp_montgomery_setup(NULL, NULL);
  49405. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49406. return WC_TEST_RET_ENC_EC(ret);
  49407. ret = mp_montgomery_setup(a, NULL);
  49408. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49409. return WC_TEST_RET_ENC_EC(ret);
  49410. ret = mp_montgomery_setup(NULL, &rho);
  49411. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49412. return WC_TEST_RET_ENC_EC(ret);
  49413. ret = mp_montgomery_calc_normalization(NULL, NULL);
  49414. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49415. return WC_TEST_RET_ENC_EC(ret);
  49416. ret = mp_montgomery_calc_normalization(a, NULL);
  49417. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49418. return WC_TEST_RET_ENC_EC(ret);
  49419. ret = mp_montgomery_calc_normalization(NULL, b);
  49420. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49421. return WC_TEST_RET_ENC_EC(ret);
  49422. #endif
  49423. ret = mp_unsigned_bin_size(NULL);
  49424. if (ret != 0)
  49425. return WC_TEST_RET_ENC_EC(ret);
  49426. #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL)
  49427. ret = mp_tohex(NULL, NULL);
  49428. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49429. return WC_TEST_RET_ENC_EC(ret);
  49430. ret = mp_tohex(a, NULL);
  49431. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49432. return WC_TEST_RET_ENC_EC(ret);
  49433. ret = mp_tohex(NULL, hexStr);
  49434. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49435. return WC_TEST_RET_ENC_EC(ret);
  49436. #endif
  49437. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49438. ret = mp_todecimal(NULL, NULL);
  49439. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49440. return WC_TEST_RET_ENC_EC(ret);
  49441. ret = mp_todecimal(a, NULL);
  49442. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49443. return WC_TEST_RET_ENC_EC(ret);
  49444. ret = mp_todecimal(NULL, decStr);
  49445. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49446. return WC_TEST_RET_ENC_EC(ret);
  49447. #endif
  49448. #ifdef WOLFSSL_SP_MATH_ALL
  49449. ret = mp_toradix(NULL, NULL, MP_RADIX_HEX);
  49450. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49451. return WC_TEST_RET_ENC_EC(ret);
  49452. ret = mp_toradix(a, NULL, MP_RADIX_HEX);
  49453. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49454. return WC_TEST_RET_ENC_EC(ret);
  49455. ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX);
  49456. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49457. return WC_TEST_RET_ENC_EC(ret);
  49458. ret = mp_toradix(a, hexStr, 3);
  49459. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49460. return WC_TEST_RET_ENC_EC(ret);
  49461. ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL);
  49462. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49463. return WC_TEST_RET_ENC_EC(ret);
  49464. ret = mp_radix_size(a, MP_RADIX_HEX, NULL);
  49465. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49466. return WC_TEST_RET_ENC_EC(ret);
  49467. ret = mp_radix_size(NULL, MP_RADIX_HEX, &size);
  49468. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49469. return WC_TEST_RET_ENC_EC(ret);
  49470. ret = mp_radix_size(a, 3, &size);
  49471. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49472. return WC_TEST_RET_ENC_EC(ret);
  49473. #endif
  49474. return 0;
  49475. }
  49476. #endif
  49477. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49478. static wc_test_ret_t mp_test_set_is_bit(mp_int* a)
  49479. {
  49480. int i, j;
  49481. wc_test_ret_t ret;
  49482. mp_zero(a);
  49483. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49484. if (mp_is_bit_set(a, i))
  49485. return WC_TEST_RET_ENC_NC;
  49486. for (j = 0; j < i; j++) {
  49487. if (!mp_is_bit_set(a, j))
  49488. return WC_TEST_RET_ENC_NC;
  49489. }
  49490. if (mp_set_bit(a, i) != 0)
  49491. return WC_TEST_RET_ENC_NC;
  49492. if (!mp_is_bit_set(a, i))
  49493. return WC_TEST_RET_ENC_NC;
  49494. }
  49495. mp_zero(a);
  49496. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49497. if (mp_is_bit_set(a, i))
  49498. return WC_TEST_RET_ENC_NC;
  49499. }
  49500. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49501. mp_zero(a);
  49502. if (mp_set_bit(a, i) != 0)
  49503. return WC_TEST_RET_ENC_NC;
  49504. for (j = 0; j < i; j++) {
  49505. if (mp_is_bit_set(a, j))
  49506. return WC_TEST_RET_ENC_NC;
  49507. }
  49508. if (!mp_is_bit_set(a, i))
  49509. return WC_TEST_RET_ENC_NC;
  49510. }
  49511. #ifdef WOLFSSL_KEY_GEN
  49512. for (i = 0; i < DIGIT_BIT * 2; i++) {
  49513. mp_set(a, 1);
  49514. ret = mp_2expt(a, i);
  49515. if (ret != 0)
  49516. return WC_TEST_RET_ENC_EC(ret);
  49517. for (j = 0; j < i; j++) {
  49518. if (mp_is_bit_set(a, j))
  49519. return WC_TEST_RET_ENC_NC;
  49520. }
  49521. if (!mp_is_bit_set(a, i))
  49522. return WC_TEST_RET_ENC_NC;
  49523. }
  49524. #endif
  49525. #ifdef WOLFSSL_SP_MATH
  49526. mp_zero(a);
  49527. for (j = 1; j <= 3; j++) {
  49528. i = SP_INT_MAX_BITS - j;
  49529. if (mp_is_bit_set(a, i))
  49530. return WC_TEST_RET_ENC_NC;
  49531. if (mp_set_bit(a, i) != 0)
  49532. return WC_TEST_RET_ENC_NC;
  49533. if (!mp_is_bit_set(a, i))
  49534. return WC_TEST_RET_ENC_NC;
  49535. #ifdef WOLFSSL_KEY_GEN
  49536. ret = mp_2expt(a, i);
  49537. if (ret != 0)
  49538. return WC_TEST_RET_ENC_EC(ret);
  49539. if (!mp_is_bit_set(a, i))
  49540. return WC_TEST_RET_ENC_NC;
  49541. #endif
  49542. }
  49543. mp_zero(a);
  49544. for (j = 0; j <= 3; j++) {
  49545. i = SP_INT_MAX_BITS + j;
  49546. if (mp_is_bit_set(a, i))
  49547. return WC_TEST_RET_ENC_NC;
  49548. if (mp_set_bit(a, i) != WC_NO_ERR_TRACE(MP_VAL))
  49549. return WC_TEST_RET_ENC_NC;
  49550. #ifdef WOLFSSL_KEY_GEN
  49551. ret = mp_2expt(a, i);
  49552. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49553. return WC_TEST_RET_ENC_EC(ret);
  49554. #endif
  49555. }
  49556. #endif
  49557. (void)ret;
  49558. return 0;
  49559. }
  49560. #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */
  49561. static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
  49562. {
  49563. wc_test_ret_t ret;
  49564. mp_zero(a);
  49565. mp_zero(b);
  49566. ret = mp_cmp_d(a, 0);
  49567. if (ret != MP_EQ)
  49568. return WC_TEST_RET_ENC_EC(ret);
  49569. ret = mp_cmp_d(a, 1);
  49570. if (ret != MP_LT)
  49571. return WC_TEST_RET_ENC_EC(ret);
  49572. ret = mp_cmp(a, b);
  49573. if (ret != MP_EQ)
  49574. return WC_TEST_RET_ENC_NC;
  49575. mp_set(a, 1);
  49576. ret = mp_cmp_d(a, 0);
  49577. if (ret != MP_GT)
  49578. return WC_TEST_RET_ENC_EC(ret);
  49579. ret = mp_cmp_d(a, 1);
  49580. if (ret != MP_EQ)
  49581. return WC_TEST_RET_ENC_EC(ret);
  49582. ret = mp_cmp_d(a, 2);
  49583. if (ret != MP_LT)
  49584. return WC_TEST_RET_ENC_EC(ret);
  49585. ret = mp_cmp(a, b);
  49586. if (ret != MP_GT)
  49587. return WC_TEST_RET_ENC_NC;
  49588. mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX);
  49589. ret = mp_cmp_d(b, -1);
  49590. if (ret != MP_GT)
  49591. return WC_TEST_RET_ENC_EC(ret);
  49592. ret = mp_cmp(a, b);
  49593. if (ret != MP_LT)
  49594. return WC_TEST_RET_ENC_NC;
  49595. ret = mp_cmp(b, a);
  49596. if (ret != MP_GT)
  49597. return WC_TEST_RET_ENC_NC;
  49598. ret = mp_cmp(b, b);
  49599. if (ret != MP_EQ)
  49600. return WC_TEST_RET_ENC_NC;
  49601. #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
  49602. defined(WOLFSSL_SP_INT_NEGATIVE)
  49603. mp_read_radix(a, "-1", MP_RADIX_HEX);
  49604. mp_read_radix(a, "1", MP_RADIX_HEX);
  49605. ret = mp_cmp(a, b);
  49606. if (ret != MP_LT)
  49607. return WC_TEST_RET_ENC_NC;
  49608. ret = mp_cmp(b, a);
  49609. if (ret != MP_GT)
  49610. return WC_TEST_RET_ENC_NC;
  49611. mp_read_radix(b, "-2", MP_RADIX_HEX);
  49612. ret = mp_cmp(a, b);
  49613. if (ret != MP_GT)
  49614. return WC_TEST_RET_ENC_NC;
  49615. ret = mp_cmp(b, a);
  49616. if (ret != MP_LT)
  49617. return WC_TEST_RET_ENC_NC;
  49618. mp_read_radix(a, "-2", MP_RADIX_HEX);
  49619. ret = mp_cmp(a, b);
  49620. if (ret != MP_EQ)
  49621. return WC_TEST_RET_ENC_NC;
  49622. #endif
  49623. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  49624. defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING)
  49625. mp_zero(a);
  49626. mp_zero(b);
  49627. ret = mp_cmp_ct(a, b, 1);
  49628. if (ret != MP_EQ)
  49629. return WC_TEST_RET_ENC_EC(ret);
  49630. ret = mp_cmp_ct(a, a, a->used);
  49631. if (ret != MP_EQ)
  49632. return WC_TEST_RET_ENC_EC(ret);
  49633. #ifdef WOLFSSL_SP_MATH_ALL
  49634. ret = mp_cmp_ct(a, NULL, a->used);
  49635. if (ret != MP_GT)
  49636. return WC_TEST_RET_ENC_EC(ret);
  49637. ret = mp_cmp_ct(NULL, a, a->used);
  49638. if (ret != MP_LT)
  49639. return WC_TEST_RET_ENC_EC(ret);
  49640. #endif
  49641. mp_read_radix(a, "1", MP_RADIX_HEX);
  49642. ret = mp_cmp_ct(a, b, 1);
  49643. if (ret != MP_GT)
  49644. return WC_TEST_RET_ENC_EC(ret);
  49645. ret = mp_cmp_ct(b, a, 1);
  49646. if (ret != MP_LT)
  49647. return WC_TEST_RET_ENC_EC(ret);
  49648. mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  49649. ret = mp_cmp_ct(a, b, a->used);
  49650. if (ret != MP_GT)
  49651. return WC_TEST_RET_ENC_EC(ret);
  49652. ret = mp_cmp_ct(b, a, a->used);
  49653. if (ret != MP_LT)
  49654. return WC_TEST_RET_ENC_EC(ret);
  49655. mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  49656. ret = mp_cmp_ct(b, a, a->used);
  49657. if (ret != MP_GT)
  49658. return WC_TEST_RET_ENC_EC(ret);
  49659. ret = mp_cmp_ct(a, b, a->used);
  49660. if (ret != MP_LT)
  49661. return WC_TEST_RET_ENC_EC(ret);
  49662. mp_read_radix(b, "0123456789abcdef0123456789abcdf0", MP_RADIX_HEX);
  49663. ret = mp_cmp_ct(b, a, a->used);
  49664. if (ret != MP_GT)
  49665. return WC_TEST_RET_ENC_EC(ret);
  49666. ret = mp_cmp_ct(a, b, a->used);
  49667. if (ret != MP_LT)
  49668. return WC_TEST_RET_ENC_EC(ret);
  49669. mp_read_radix(b, "0123456789abcdf0", MP_RADIX_HEX);
  49670. ret = mp_cmp_ct(a, b, a->used);
  49671. if (ret != MP_GT)
  49672. return WC_TEST_RET_ENC_EC(ret);
  49673. ret = mp_cmp_ct(b, a, a->used);
  49674. if (ret != MP_LT)
  49675. return WC_TEST_RET_ENC_EC(ret);
  49676. #endif
  49677. return 0;
  49678. }
  49679. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49680. static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
  49681. {
  49682. wc_test_ret_t ret;
  49683. int i, j, k;
  49684. #ifndef WOLFSSL_SP_MATH
  49685. for (i = 0; i < 10; i++) {
  49686. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  49687. ret = randNum(a, j, rng, NULL);
  49688. if (ret != MP_OKAY)
  49689. return WC_TEST_RET_ENC_EC(ret);
  49690. mp_copy(a, b);
  49691. for (k = 0; k <= DIGIT_BIT * 2; k++) {
  49692. ret = mp_mul_2d(a, k, a);
  49693. if (ret != MP_OKAY)
  49694. return WC_TEST_RET_ENC_EC(ret);
  49695. mp_rshb(a, k);
  49696. ret = mp_cmp(a, b);
  49697. if (ret != MP_EQ)
  49698. return WC_TEST_RET_ENC_NC;
  49699. }
  49700. }
  49701. }
  49702. #endif
  49703. for (i = 0; i < 10; i++) {
  49704. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  49705. ret = randNum(a, j, rng, NULL);
  49706. if (ret != MP_OKAY)
  49707. return WC_TEST_RET_ENC_EC(ret);
  49708. mp_copy(a, b);
  49709. for (k = 0; k < 10; k++) {
  49710. ret = mp_lshd(a, k);
  49711. if (ret != MP_OKAY)
  49712. return WC_TEST_RET_ENC_EC(ret);
  49713. #ifndef WOLFSSL_SP_MATH
  49714. mp_rshd(a, k);
  49715. #else
  49716. mp_rshb(a, k * SP_WORD_SIZE);
  49717. #endif
  49718. ret = mp_cmp(a, b);
  49719. if (ret != MP_EQ)
  49720. return WC_TEST_RET_ENC_NC;
  49721. }
  49722. }
  49723. }
  49724. #ifndef WOLFSSL_SP_MATH
  49725. mp_zero(a);
  49726. mp_rshd(a, 1);
  49727. if (!mp_iszero(a))
  49728. return WC_TEST_RET_ENC_NC;
  49729. mp_set(a, 1);
  49730. mp_rshd(a, 1);
  49731. if (!mp_iszero(a))
  49732. return WC_TEST_RET_ENC_NC;
  49733. mp_set(a, 1);
  49734. mp_rshd(a, 2);
  49735. if (!mp_iszero(a))
  49736. return WC_TEST_RET_ENC_NC;
  49737. #endif
  49738. return 0;
  49739. }
  49740. #endif
  49741. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49742. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  49743. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  49744. static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
  49745. WC_RNG* rng)
  49746. {
  49747. wc_test_ret_t ret;
  49748. int i, j, k;
  49749. mp_zero(a);
  49750. mp_zero(d);
  49751. ret = mp_div(a, d, r, rem);
  49752. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49753. return WC_TEST_RET_ENC_EC(ret);
  49754. mp_set(d, 1);
  49755. ret = mp_div(a, d, r, rem);
  49756. if (ret != MP_OKAY)
  49757. return WC_TEST_RET_ENC_EC(ret);
  49758. if (!mp_iszero(r))
  49759. return WC_TEST_RET_ENC_EC(ret);
  49760. if (!mp_iszero(rem))
  49761. return WC_TEST_RET_ENC_EC(ret);
  49762. mp_set(a, 1);
  49763. ret = mp_div(a, d, r, rem);
  49764. if (ret != MP_OKAY)
  49765. return WC_TEST_RET_ENC_EC(ret);
  49766. if (!mp_isone(r))
  49767. return WC_TEST_RET_ENC_EC(ret);
  49768. if (!mp_iszero(rem))
  49769. return WC_TEST_RET_ENC_EC(ret);
  49770. for (i = 0; i < 100; i++) {
  49771. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) {
  49772. ret = randNum(d, j, rng, NULL);
  49773. if (ret != MP_OKAY)
  49774. return WC_TEST_RET_ENC_EC(ret);
  49775. for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) {
  49776. ret = randNum(a, k, rng, NULL);
  49777. if (ret != MP_OKAY)
  49778. return WC_TEST_RET_ENC_EC(ret);
  49779. ret = mp_div(a, d, NULL, rem);
  49780. if (ret != MP_OKAY)
  49781. return WC_TEST_RET_ENC_EC(ret);
  49782. ret = mp_div(a, d, r, NULL);
  49783. if (ret != MP_OKAY)
  49784. return WC_TEST_RET_ENC_EC(ret);
  49785. ret = mp_div(a, d, r, rem);
  49786. if (ret != MP_OKAY)
  49787. return WC_TEST_RET_ENC_EC(ret);
  49788. mp_mul(r, d, r);
  49789. mp_add(r, rem, r);
  49790. if (mp_cmp(r, a) != MP_EQ)
  49791. return WC_TEST_RET_ENC_NC;
  49792. }
  49793. }
  49794. }
  49795. ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL);
  49796. if (ret != MP_OKAY)
  49797. return WC_TEST_RET_ENC_EC(ret);
  49798. mp_add(d, d, a);
  49799. mp_set(rem, 1);
  49800. mp_div(a, d, NULL, rem);
  49801. if (ret != MP_OKAY)
  49802. return WC_TEST_RET_ENC_EC(ret);
  49803. if (!mp_iszero(rem))
  49804. return WC_TEST_RET_ENC_EC(ret);
  49805. mp_set(r, 1);
  49806. mp_div(a, d, r, NULL);
  49807. if (ret != MP_OKAY)
  49808. return WC_TEST_RET_ENC_EC(ret);
  49809. if (mp_cmp_d(r, 2) != MP_EQ)
  49810. return WC_TEST_RET_ENC_EC(ret);
  49811. mp_set(r, 1);
  49812. mp_set(rem, 1);
  49813. mp_div(a, d, r, rem);
  49814. if (ret != MP_OKAY)
  49815. return WC_TEST_RET_ENC_EC(ret);
  49816. if (mp_cmp_d(r, 2) != MP_EQ)
  49817. return WC_TEST_RET_ENC_EC(ret);
  49818. if (!mp_iszero(rem))
  49819. return WC_TEST_RET_ENC_EC(ret);
  49820. mp_set(a, 0xfe);
  49821. mp_lshd(a, 3);
  49822. mp_add_d(a, 0xff, a);
  49823. mp_set(d, 0xfe);
  49824. mp_lshd(d, 2);
  49825. ret = mp_div(a, d, r, rem);
  49826. if (ret != MP_OKAY)
  49827. return WC_TEST_RET_ENC_EC(ret);
  49828. mp_mul(r, d, d);
  49829. mp_add(rem, d, d);
  49830. if (mp_cmp(a, d) != MP_EQ)
  49831. return WC_TEST_RET_ENC_NC;
  49832. /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in
  49833. * a digit. So mp_div must detect and handle.
  49834. * For example: 0x800000 / 0x8001, DIGIT_BIT = 8
  49835. */
  49836. mp_zero(a);
  49837. mp_set_bit(a, DIGIT_BIT * 3 - 1);
  49838. mp_zero(d);
  49839. mp_set_bit(d, DIGIT_BIT * 2 - 1);
  49840. mp_add_d(d, 1, d);
  49841. ret = mp_div(a, d, r, rem);
  49842. if (ret != MP_OKAY)
  49843. return WC_TEST_RET_ENC_EC(ret);
  49844. /* Make sure [d | d] / d is handled. */
  49845. mp_zero(a);
  49846. mp_set_bit(a, DIGIT_BIT * 2 - 1);
  49847. mp_set_bit(a, DIGIT_BIT * 1 - 1);
  49848. mp_zero(d);
  49849. mp_set_bit(d, DIGIT_BIT - 1);
  49850. ret = mp_div(a, d, r, rem);
  49851. if (ret != MP_OKAY)
  49852. return WC_TEST_RET_ENC_EC(ret);
  49853. mp_zero(a);
  49854. mp_set_bit(a, DIGIT_BIT);
  49855. mp_set_bit(a, 0);
  49856. mp_zero(d);
  49857. if (mp_cmp(r, a) != MP_EQ)
  49858. return WC_TEST_RET_ENC_NC;
  49859. if (mp_cmp(rem, d) != MP_EQ)
  49860. return WC_TEST_RET_ENC_NC;
  49861. return 0;
  49862. }
  49863. #endif
  49864. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49865. !defined(WC_NO_RNG)
  49866. static wc_test_ret_t mp_test_prime(mp_int* a, WC_RNG* rng)
  49867. {
  49868. wc_test_ret_t ret;
  49869. int res;
  49870. ret = mp_rand_prime(a, 1, rng, NULL);
  49871. #if defined(WOLFSSL_SP_MATH_ALL)
  49872. if (ret != 0)
  49873. return WC_TEST_RET_ENC_EC(ret);
  49874. #else
  49875. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49876. return WC_TEST_RET_ENC_NC;
  49877. #endif
  49878. #ifndef WOLFSSL_SP_MATH
  49879. ret = mp_rand_prime(a, -5, rng, NULL);
  49880. if (ret != 0 || (a->dp[0] & 3) != 3)
  49881. return WC_TEST_RET_ENC_NC;
  49882. #endif
  49883. ret = mp_prime_is_prime(a, 1, &res);
  49884. if (ret != MP_OKAY)
  49885. return WC_TEST_RET_ENC_EC(ret);
  49886. #ifndef WOLFSSL_SP_MATH
  49887. if (res != MP_YES)
  49888. return WC_TEST_RET_ENC_EC(res);
  49889. #else
  49890. if (res != MP_NO)
  49891. return WC_TEST_RET_ENC_EC(res);
  49892. #endif
  49893. ret = mp_prime_is_prime(a, 0, &res);
  49894. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49895. return WC_TEST_RET_ENC_EC(ret);
  49896. ret = mp_prime_is_prime(a, -1, &res);
  49897. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49898. return WC_TEST_RET_ENC_EC(ret);
  49899. ret = mp_prime_is_prime(a, 257, &res);
  49900. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49901. return WC_TEST_RET_ENC_EC(ret);
  49902. mp_set(a, 1);
  49903. ret = mp_prime_is_prime(a, 1, &res);
  49904. if (ret != MP_OKAY)
  49905. return WC_TEST_RET_ENC_EC(ret);
  49906. if (res != MP_NO)
  49907. return WC_TEST_RET_ENC_EC(res);
  49908. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  49909. if (ret != MP_OKAY)
  49910. return WC_TEST_RET_ENC_EC(ret);
  49911. if (res != MP_NO)
  49912. return WC_TEST_RET_ENC_EC(res);
  49913. mp_set(a, 2);
  49914. ret = mp_prime_is_prime(a, 1, &res);
  49915. if (ret != MP_OKAY)
  49916. return WC_TEST_RET_ENC_EC(ret);
  49917. if (res != MP_YES)
  49918. return WC_TEST_RET_ENC_EC(res);
  49919. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  49920. if (ret != MP_OKAY)
  49921. return WC_TEST_RET_ENC_EC(ret);
  49922. if (res != MP_YES)
  49923. return WC_TEST_RET_ENC_EC(res);
  49924. mp_set(a, 0xfb);
  49925. ret = mp_prime_is_prime(a, 1, &res);
  49926. if (ret != MP_OKAY)
  49927. return WC_TEST_RET_ENC_EC(ret);
  49928. if (res != MP_YES)
  49929. return WC_TEST_RET_ENC_EC(res);
  49930. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  49931. if (ret != MP_OKAY)
  49932. return WC_TEST_RET_ENC_EC(ret);
  49933. if (res != MP_YES)
  49934. return WC_TEST_RET_ENC_EC(res);
  49935. mp_set(a, 0x6);
  49936. ret = mp_prime_is_prime(a, 1, &res);
  49937. if (ret != MP_OKAY)
  49938. return WC_TEST_RET_ENC_EC(ret);
  49939. if (res != MP_NO)
  49940. return WC_TEST_RET_ENC_EC(res);
  49941. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  49942. if (ret != MP_OKAY)
  49943. return WC_TEST_RET_ENC_EC(ret);
  49944. if (res != MP_NO)
  49945. return WC_TEST_RET_ENC_EC(res);
  49946. mp_set_int(a, 0x655 * 0x65b);
  49947. ret = mp_prime_is_prime(a, 10, &res);
  49948. if (ret != MP_OKAY)
  49949. return WC_TEST_RET_ENC_EC(ret);
  49950. if (res != MP_NO)
  49951. return WC_TEST_RET_ENC_EC(res);
  49952. ret = mp_prime_is_prime_ex(a, 10, &res, rng);
  49953. if (ret != MP_OKAY)
  49954. return WC_TEST_RET_ENC_EC(ret);
  49955. if (res != MP_NO)
  49956. return WC_TEST_RET_ENC_EC(res);
  49957. return 0;
  49958. }
  49959. #endif
  49960. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49961. static wc_test_ret_t mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp,
  49962. WC_RNG* rng)
  49963. {
  49964. wc_test_ret_t ret;
  49965. int i;
  49966. WOLFSSL_SMALL_STACK_STATIC const int kat[][3] = {
  49967. { 1, 1, 1 }, { 2, 1, 2 }, { 1, 2, 2 }, { 2, 4, 4 }, { 4, 2, 4 },
  49968. { 12, 56, 168 }, { 56, 12, 168 }
  49969. };
  49970. (void)exp;
  49971. mp_set(a, 0);
  49972. mp_set(b, 1);
  49973. ret = mp_lcm(a, a, r);
  49974. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49975. return WC_TEST_RET_ENC_EC(ret);
  49976. ret = mp_lcm(a, b, r);
  49977. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49978. return WC_TEST_RET_ENC_EC(ret);
  49979. ret = mp_lcm(b, a, r);
  49980. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49981. return WC_TEST_RET_ENC_EC(ret);
  49982. for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) {
  49983. mp_set(a, kat[i][0]);
  49984. mp_set(b, kat[i][1]);
  49985. ret = mp_lcm(a, b, r);
  49986. if (ret != MP_OKAY)
  49987. return WC_TEST_RET_ENC_EC(ret);
  49988. mp_set(exp, kat[i][2]);
  49989. ret = mp_cmp(r, exp);
  49990. if (ret != MP_EQ)
  49991. return WC_TEST_RET_ENC_NC;
  49992. }
  49993. (void)rng;
  49994. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49995. !defined(WC_NO_RNG)
  49996. ret = mp_rand_prime(a, 20, rng, NULL);
  49997. if (ret != MP_OKAY)
  49998. return WC_TEST_RET_ENC_EC(ret);
  49999. ret = mp_rand_prime(b, 20, rng, NULL);
  50000. if (ret != MP_OKAY)
  50001. return WC_TEST_RET_ENC_EC(ret);
  50002. ret = mp_mul(a, b, exp);
  50003. if (ret != MP_OKAY)
  50004. return WC_TEST_RET_ENC_EC(ret);
  50005. ret = mp_lcm(a, b, r);
  50006. if (ret != MP_OKAY)
  50007. return WC_TEST_RET_ENC_EC(ret);
  50008. ret = mp_cmp(r, exp);
  50009. if (ret != MP_EQ)
  50010. return WC_TEST_RET_ENC_NC;
  50011. ret = mp_lcm(b, a, r);
  50012. if (ret != MP_OKAY)
  50013. return WC_TEST_RET_ENC_EC(ret);
  50014. ret = mp_cmp(r, exp);
  50015. if (ret != MP_EQ)
  50016. return WC_TEST_RET_ENC_NC;
  50017. #endif
  50018. mp_set(a, 11);
  50019. mp_zero(b);
  50020. ret = mp_gcd(a, b, r);
  50021. if (ret != MP_OKAY)
  50022. return WC_TEST_RET_ENC_EC(ret);
  50023. ret = mp_cmp_d(r, 11);
  50024. if (ret != MP_EQ)
  50025. return WC_TEST_RET_ENC_EC(ret);
  50026. ret = mp_gcd(b, a, r);
  50027. if (ret != MP_OKAY)
  50028. return WC_TEST_RET_ENC_EC(ret);
  50029. ret = mp_cmp_d(r, 11);
  50030. if (ret != MP_EQ)
  50031. return WC_TEST_RET_ENC_EC(ret);
  50032. ret = mp_gcd(b, b, r);
  50033. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50034. return WC_TEST_RET_ENC_EC(ret);
  50035. return 0;
  50036. }
  50037. #endif
  50038. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50039. defined(WOLFSSL_SP_MATH_ALL)
  50040. static wc_test_ret_t mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng)
  50041. {
  50042. wc_test_ret_t ret;
  50043. int i;
  50044. int j;
  50045. mp_set(a, 10);
  50046. ret = mp_mod_2d(a, 0, r);
  50047. if (ret != MP_OKAY)
  50048. return WC_TEST_RET_ENC_EC(ret);
  50049. if (!mp_iszero(r))
  50050. return WC_TEST_RET_ENC_NC;
  50051. ret = mp_mod_2d(a, 1, r);
  50052. if (ret != MP_OKAY)
  50053. return WC_TEST_RET_ENC_EC(ret);
  50054. if (!mp_iszero(r))
  50055. return WC_TEST_RET_ENC_NC;
  50056. ret = mp_mod_2d(a, 2, r);
  50057. if (ret != MP_OKAY)
  50058. return WC_TEST_RET_ENC_EC(ret);
  50059. ret = mp_cmp_d(r, 2);
  50060. if (ret != 0)
  50061. return WC_TEST_RET_ENC_EC(ret);
  50062. for (i = 2; i < 20; i++) {
  50063. ret = randNum(a, i, rng, NULL);
  50064. if (ret != 0)
  50065. return WC_TEST_RET_ENC_EC(ret);
  50066. for (j = 1; j <= mp_count_bits(a); j++) {
  50067. /* Get top part */
  50068. ret = mp_div_2d(a, j, t, NULL);
  50069. if (ret != 0)
  50070. return WC_TEST_RET_ENC_EC(ret);
  50071. ret = mp_mul_2d(t, j, t);
  50072. if (ret != 0)
  50073. return WC_TEST_RET_ENC_EC(ret);
  50074. /* Get bottom part */
  50075. ret = mp_mod_2d(a, j, r);
  50076. if (ret != 0)
  50077. return WC_TEST_RET_ENC_EC(ret);
  50078. /* Reassemble */
  50079. ret = mp_add(t, r, r);
  50080. if (ret != 0)
  50081. return WC_TEST_RET_ENC_EC(ret);
  50082. ret = mp_cmp(a, r);
  50083. if (ret != MP_EQ)
  50084. return WC_TEST_RET_ENC_NC;
  50085. }
  50086. }
  50087. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_SP_INT_NEGATIVE)
  50088. /* Test negative value being moded. */
  50089. for (j = 0; j < 20; j++) {
  50090. ret = randNum(a, 2, rng, NULL);
  50091. if (ret != 0)
  50092. return WC_TEST_RET_ENC_EC(ret);
  50093. a->sign = MP_NEG;
  50094. for (i = 1; i < DIGIT_BIT * 3 + 1; i++) {
  50095. ret = mp_mod_2d(a, i, r);
  50096. if (ret != 0)
  50097. return WC_TEST_RET_ENC_EC(ret);
  50098. mp_zero(t);
  50099. ret = mp_set_bit(t, i);
  50100. if (ret != 0)
  50101. return WC_TEST_RET_ENC_EC(ret);
  50102. ret = mp_mod(a, t, t);
  50103. if (ret != 0)
  50104. return WC_TEST_RET_ENC_EC(ret);
  50105. ret = mp_cmp(r, t);
  50106. if (ret != MP_EQ)
  50107. return WC_TEST_RET_ENC_NC;
  50108. }
  50109. }
  50110. #endif
  50111. return 0;
  50112. }
  50113. #endif
  50114. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50115. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50116. static wc_test_ret_t mp_test_mod_d(mp_int* a, WC_RNG* rng)
  50117. {
  50118. wc_test_ret_t ret;
  50119. mp_digit r;
  50120. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50121. mp_digit rem;
  50122. int i;
  50123. #endif
  50124. (void)rng;
  50125. ret = mp_set(a, 1);
  50126. if (ret != MP_OKAY)
  50127. return WC_TEST_RET_ENC_EC(ret);
  50128. ret = mp_mod_d(a, 0, &r);
  50129. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50130. return WC_TEST_RET_ENC_EC(ret);
  50131. mp_zero(a);
  50132. ret = mp_mod_d(a, 1, &r);
  50133. if (ret != MP_OKAY)
  50134. return WC_TEST_RET_ENC_EC(ret);
  50135. ret = mp_mod_d(a, 3, &r);
  50136. if (ret != MP_OKAY)
  50137. return WC_TEST_RET_ENC_EC(ret);
  50138. ret = mp_mod_d(a, 5, &r);
  50139. if (ret != MP_OKAY)
  50140. return WC_TEST_RET_ENC_EC(ret);
  50141. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50142. for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) {
  50143. ret = randNum(a, i, rng, NULL);
  50144. if (ret != MP_OKAY)
  50145. return WC_TEST_RET_ENC_EC(ret);
  50146. ret = mp_mod_d(a, 3, &r);
  50147. if (ret != MP_OKAY)
  50148. return WC_TEST_RET_ENC_EC(ret);
  50149. ret = mp_div_d(a, 3, a, &rem);
  50150. if (ret != MP_OKAY)
  50151. return WC_TEST_RET_ENC_EC(ret);
  50152. if (r != rem)
  50153. return WC_TEST_RET_ENC_NC;
  50154. }
  50155. #endif
  50156. return 0;
  50157. }
  50158. #endif
  50159. static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2,
  50160. WC_RNG* rng)
  50161. {
  50162. wc_test_ret_t ret;
  50163. int i;
  50164. for (i = 1; i < 16; i++) {
  50165. ret = randNum(a, i, rng, NULL);
  50166. if (ret != 0)
  50167. return WC_TEST_RET_ENC_EC(ret);
  50168. ret = mp_mul(a, a, r1);
  50169. if (ret != 0)
  50170. return WC_TEST_RET_ENC_EC(ret);
  50171. ret = mp_sqr(a, r2);
  50172. if (ret != 0)
  50173. return WC_TEST_RET_ENC_EC(ret);
  50174. ret = mp_cmp(r1, r2);
  50175. if (ret != MP_EQ)
  50176. return WC_TEST_RET_ENC_NC;
  50177. }
  50178. ret = mp_set(b, 0);
  50179. if (ret != MP_OKAY)
  50180. return WC_TEST_RET_ENC_EC(ret);
  50181. ret = mp_mul(a, b, r1);
  50182. if (ret != MP_OKAY)
  50183. return WC_TEST_RET_ENC_EC(ret);
  50184. if (!mp_iszero(r1))
  50185. return WC_TEST_RET_ENC_EC(ret);
  50186. ret = mp_sqr(b, r1);
  50187. if (ret != MP_OKAY)
  50188. return WC_TEST_RET_ENC_EC(ret);
  50189. if (!mp_iszero(r1))
  50190. return WC_TEST_RET_ENC_NC;
  50191. #ifdef WOLFSSL_SP_MATH_ALL
  50192. ret = mp_set(a, 1);
  50193. if (ret != MP_OKAY)
  50194. return WC_TEST_RET_ENC_EC(ret);
  50195. i = (SP_INT_DIGITS / 2) + 1;
  50196. ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a);
  50197. if (ret != MP_OKAY)
  50198. return WC_TEST_RET_ENC_EC(ret);
  50199. ret = mp_set(b, 1);
  50200. if (ret != MP_OKAY)
  50201. return WC_TEST_RET_ENC_EC(ret);
  50202. ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b);
  50203. if (ret != MP_OKAY)
  50204. return WC_TEST_RET_ENC_EC(ret);
  50205. ret = mp_mul(a, b, r1);
  50206. if (ret != MP_OKAY)
  50207. return WC_TEST_RET_ENC_EC(ret);
  50208. ret = mp_mul(a, a, r1);
  50209. if (ret == MP_OKAY)
  50210. return WC_TEST_RET_ENC_NC;
  50211. ret = mp_sqr(a, r1);
  50212. if (ret == MP_OKAY)
  50213. return WC_TEST_RET_ENC_NC;
  50214. ret = mp_sqr(b, r1);
  50215. if (ret != MP_OKAY)
  50216. return WC_TEST_RET_ENC_EC(ret);
  50217. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50218. (defined(HAVE_ECC) && defined(FP_ECC))
  50219. ret = mp_mulmod(a, b, b, r1);
  50220. if (ret != MP_OKAY)
  50221. return WC_TEST_RET_ENC_EC(ret);
  50222. ret = mp_mulmod(a, a, b, r1);
  50223. if (ret == MP_OKAY)
  50224. return WC_TEST_RET_ENC_NC;
  50225. #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC))
  50226. ret = mp_sqrmod(a, b, r1);
  50227. if (ret == MP_OKAY)
  50228. return WC_TEST_RET_ENC_NC;
  50229. ret = mp_sqrmod(b, a, r1);
  50230. if (ret != MP_OKAY)
  50231. return WC_TEST_RET_ENC_EC(ret);
  50232. #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */
  50233. #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
  50234. #endif /* WOLFSSL_SP_MATH_ALL */
  50235. return 0;
  50236. }
  50237. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  50238. defined(OPENSSL_EXTRA)
  50239. static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
  50240. {
  50241. wc_test_ret_t ret;
  50242. mp_set(a, 0);
  50243. mp_set(m, 1);
  50244. ret = mp_invmod(a, m, r);
  50245. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50246. return WC_TEST_RET_ENC_EC(ret);
  50247. ret = mp_invmod(m, a, r);
  50248. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50249. return WC_TEST_RET_ENC_EC(ret);
  50250. mp_set(a, 2);
  50251. mp_set(m, 4);
  50252. ret = mp_invmod(a, m, r);
  50253. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50254. return WC_TEST_RET_ENC_EC(ret);
  50255. mp_set(a, 3);
  50256. mp_set(m, 6);
  50257. ret = mp_invmod(a, m, r);
  50258. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50259. return WC_TEST_RET_ENC_EC(ret);
  50260. mp_set(a, 5*9);
  50261. mp_set(m, 6*9);
  50262. ret = mp_invmod(a, m, r);
  50263. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50264. return WC_TEST_RET_ENC_EC(ret);
  50265. mp_set(a, 1);
  50266. mp_set(m, 4);
  50267. ret = mp_invmod(a, m, r);
  50268. if (ret != MP_OKAY)
  50269. return WC_TEST_RET_ENC_EC(ret);
  50270. if (!mp_isone(r))
  50271. return WC_TEST_RET_ENC_NC;
  50272. mp_set(a, 3);
  50273. mp_set(m, 4);
  50274. ret = mp_invmod(a, m, r);
  50275. if (ret != MP_OKAY)
  50276. return WC_TEST_RET_ENC_EC(ret);
  50277. ret = mp_cmp_d(r, 3);
  50278. if (ret != 0)
  50279. return WC_TEST_RET_ENC_EC(ret);
  50280. mp_set(a, 3);
  50281. mp_set(m, 5);
  50282. ret = mp_invmod(a, m, r);
  50283. if (ret != MP_OKAY)
  50284. return WC_TEST_RET_ENC_EC(ret);
  50285. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50286. /* Maximum 'a' */
  50287. mp_set(a, 0);
  50288. mp_set_bit(a, (r->size / 2)* SP_WORD_SIZE - 1);
  50289. mp_sub_d(a, 1, a);
  50290. /* Modulus too big. */
  50291. mp_set(m, 0);
  50292. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE);
  50293. ret = mp_invmod(a, m, r);
  50294. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50295. return WC_TEST_RET_ENC_EC(ret);
  50296. /* Maximum modulus - even. */
  50297. mp_set(m, 0);
  50298. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1);
  50299. ret = mp_invmod(a, m, r);
  50300. if (ret != MP_OKAY)
  50301. return WC_TEST_RET_ENC_EC(ret);
  50302. #endif
  50303. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE)
  50304. mp_read_radix(a, "-3", 16);
  50305. ret = mp_invmod(a, m, r);
  50306. if (ret != MP_OKAY)
  50307. return WC_TEST_RET_ENC_EC(ret);
  50308. #endif
  50309. #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
  50310. mp_set(a, 0);
  50311. mp_set(m, 3);
  50312. ret = mp_invmod_mont_ct(a, m, r, 1);
  50313. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50314. return WC_TEST_RET_ENC_EC(ret);
  50315. mp_set(a, 1);
  50316. mp_set(m, 0);
  50317. ret = mp_invmod_mont_ct(a, m, r, 1);
  50318. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50319. return WC_TEST_RET_ENC_EC(ret);
  50320. mp_set(a, 1);
  50321. mp_set(m, 1);
  50322. ret = mp_invmod_mont_ct(a, m, r, 1);
  50323. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50324. return WC_TEST_RET_ENC_EC(ret);
  50325. mp_set(a, 1);
  50326. mp_set(m, 2);
  50327. ret = mp_invmod_mont_ct(a, m, r, 1);
  50328. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50329. return WC_TEST_RET_ENC_EC(ret);
  50330. mp_set(a, 1);
  50331. mp_set(m, 3);
  50332. ret = mp_invmod_mont_ct(a, m, r, 1);
  50333. if (ret != MP_OKAY)
  50334. return WC_TEST_RET_ENC_EC(ret);
  50335. #endif
  50336. return 0;
  50337. }
  50338. #endif /* !NO_RSA || HAVE_ECC || !NO_DSA || OPENSSL_EXTRA */
  50339. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  50340. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  50341. static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r)
  50342. {
  50343. wc_test_ret_t ret;
  50344. mp_set(b, 0x2);
  50345. mp_set(e, 0x3);
  50346. mp_set(m, 0x0);
  50347. ret = mp_exptmod_ex(b, e, 1, m, r);
  50348. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50349. return WC_TEST_RET_ENC_EC(ret);
  50350. ret = mp_exptmod_nct(b, e, m, r);
  50351. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50352. return WC_TEST_RET_ENC_EC(ret);
  50353. mp_set(b, 0x2);
  50354. mp_set(e, 0x3);
  50355. mp_set(m, 0x1);
  50356. ret = mp_exptmod_ex(b, e, 1, m, r);
  50357. if (ret != MP_OKAY)
  50358. return WC_TEST_RET_ENC_EC(ret);
  50359. if (!mp_iszero(r))
  50360. return WC_TEST_RET_ENC_NC;
  50361. ret = mp_exptmod_nct(b, e, m, r);
  50362. if (ret != MP_OKAY)
  50363. return WC_TEST_RET_ENC_EC(ret);
  50364. if (!mp_iszero(r))
  50365. return WC_TEST_RET_ENC_NC;
  50366. mp_set(b, 0x2);
  50367. mp_set(e, 0x0);
  50368. mp_set(m, 0x7);
  50369. ret = mp_exptmod_ex(b, e, 1, m, r);
  50370. if (ret != MP_OKAY)
  50371. return WC_TEST_RET_ENC_EC(ret);
  50372. if (!mp_isone(r))
  50373. return WC_TEST_RET_ENC_NC;
  50374. ret = mp_exptmod_nct(b, e, m, r);
  50375. if (ret != MP_OKAY)
  50376. return WC_TEST_RET_ENC_EC(ret);
  50377. if (!mp_isone(r))
  50378. return WC_TEST_RET_ENC_NC;
  50379. mp_set(b, 0x0);
  50380. mp_set(e, 0x3);
  50381. mp_set(m, 0x7);
  50382. ret = mp_exptmod_ex(b, e, 1, m, r);
  50383. if (ret != MP_OKAY)
  50384. return WC_TEST_RET_ENC_EC(ret);
  50385. if (!mp_iszero(r))
  50386. return WC_TEST_RET_ENC_NC;
  50387. ret = mp_exptmod_nct(b, e, m, r);
  50388. if (ret != MP_OKAY)
  50389. return WC_TEST_RET_ENC_EC(ret);
  50390. if (!mp_iszero(r))
  50391. return WC_TEST_RET_ENC_NC;
  50392. mp_set(b, 0x10);
  50393. mp_set(e, 0x3);
  50394. mp_set(m, 0x7);
  50395. ret = mp_exptmod_ex(b, e, 1, m, r);
  50396. if (ret != MP_OKAY)
  50397. return WC_TEST_RET_ENC_EC(ret);
  50398. ret = mp_exptmod_nct(b, e, m, r);
  50399. if (ret != MP_OKAY)
  50400. return WC_TEST_RET_ENC_EC(ret);
  50401. mp_set(b, 0x7);
  50402. mp_set(e, 0x3);
  50403. mp_set(m, 0x7);
  50404. ret = mp_exptmod_ex(b, e, 1, m, r);
  50405. if (ret != MP_OKAY)
  50406. return WC_TEST_RET_ENC_EC(ret);
  50407. if (!mp_iszero(r))
  50408. return WC_TEST_RET_ENC_NC;
  50409. ret = mp_exptmod_nct(b, e, m, r);
  50410. if (ret != MP_OKAY)
  50411. return WC_TEST_RET_ENC_EC(ret);
  50412. if (!mp_iszero(r))
  50413. return WC_TEST_RET_ENC_NC;
  50414. #ifndef WOLFSSL_SP_MATH
  50415. mp_set(b, 0x01);
  50416. mp_mul_2d(b, DIGIT_BIT, b);
  50417. mp_add_d(b, 1, b);
  50418. mp_set(e, 0x3);
  50419. mp_copy(b, m);
  50420. ret = mp_exptmod_ex(b, e, 1, m, r);
  50421. if (ret != MP_OKAY)
  50422. return WC_TEST_RET_ENC_EC(ret);
  50423. if (!mp_iszero(r))
  50424. return WC_TEST_RET_ENC_NC;
  50425. ret = mp_exptmod_nct(b, e, m, r);
  50426. if (ret != MP_OKAY)
  50427. return WC_TEST_RET_ENC_EC(ret);
  50428. if (!mp_iszero(r))
  50429. return WC_TEST_RET_ENC_NC;
  50430. #endif
  50431. mp_set(b, 0x2);
  50432. mp_set(e, 0x3);
  50433. mp_set(m, 0x7);
  50434. ret = mp_exptmod_ex(b, e, 1, m, r);
  50435. if (ret != MP_OKAY)
  50436. return WC_TEST_RET_ENC_EC(ret);
  50437. ret = mp_exptmod_nct(b, e, m, r);
  50438. if (ret != MP_OKAY)
  50439. return WC_TEST_RET_ENC_EC(ret);
  50440. #ifdef WOLFSSL_SP_MATH_ALL
  50441. mp_set(b, 0x2);
  50442. mp_set(e, 0x3);
  50443. mp_set(m, 0x01);
  50444. mp_mul_2d(m, SP_WORD_SIZE * SP_INT_DIGITS / 2, m);
  50445. mp_add_d(m, 0x01, m);
  50446. ret = mp_exptmod_ex(b, e, 1, m, r);
  50447. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50448. return WC_TEST_RET_ENC_EC(ret);
  50449. ret = mp_exptmod_nct(b, e, m, r);
  50450. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50451. return WC_TEST_RET_ENC_EC(ret);
  50452. #endif
  50453. return 0;
  50454. }
  50455. #endif /* !NO_RSA || !NO_DSA || !NO_DH || (HAVE_ECC && HAVE_COMP_KEY) ||
  50456. * OPENSSL_EXTRA */
  50457. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50458. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50459. static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng)
  50460. {
  50461. wc_test_ret_t ret;
  50462. mp_digit mp;
  50463. static int exp[] = { 7, 8, 16, 27, 32, 64,
  50464. 127, 128, 255, 256,
  50465. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  50466. 383, 384, 2033, 2048
  50467. #endif
  50468. };
  50469. static mp_digit sub[] = { 0x01, 0x05, 0x0f, 0x27, 0x05, 0x3b,
  50470. 0x01, 0x9f, 0x13, 0xbd,
  50471. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  50472. 0x1f, 0x13d, 0x45, 0x615
  50473. #endif
  50474. };
  50475. int bits[] = { 256, 384,
  50476. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 4096
  50477. 2048,
  50478. #endif
  50479. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 6144
  50480. 3072
  50481. #endif
  50482. };
  50483. int i;
  50484. int j;
  50485. for (i = 0; i < (int)(sizeof(exp) / sizeof(*exp)); i++) {
  50486. if (exp[i] >= DIGIT_BIT)
  50487. continue;
  50488. mp_zero(m);
  50489. ret = mp_set_bit(m, exp[i]);
  50490. if (ret != MP_OKAY)
  50491. return WC_TEST_RET_ENC_EC(ret);
  50492. ret = mp_sub_d(m, sub[i], m);
  50493. if (ret != MP_OKAY)
  50494. return WC_TEST_RET_ENC_EC(ret);
  50495. ret = mp_montgomery_setup(m, &mp);
  50496. if (ret != MP_OKAY)
  50497. return WC_TEST_RET_ENC_EC(ret);
  50498. ret = mp_montgomery_calc_normalization(n, m);
  50499. if (ret != MP_OKAY)
  50500. return WC_TEST_RET_ENC_EC(ret);
  50501. for (j = 0; j < 10; j++) {
  50502. ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL);
  50503. if (ret != 0)
  50504. return WC_TEST_RET_ENC_EC(ret);
  50505. ret = mp_mod(a, m, a);
  50506. if (ret != 0)
  50507. return WC_TEST_RET_ENC_EC(ret);
  50508. /* r = a * a */
  50509. ret = mp_sqrmod(a, m, r);
  50510. if (ret != MP_OKAY)
  50511. return WC_TEST_RET_ENC_EC(ret);
  50512. /* Convert to Montgomery form = a*n */
  50513. ret = mp_mulmod(a, n, m, a);
  50514. if (ret != MP_OKAY)
  50515. return WC_TEST_RET_ENC_EC(ret);
  50516. /* a*a mod m == ((a*n) * (a*n)) / n / n */
  50517. ret = mp_sqr(a, a);
  50518. if (ret != MP_OKAY)
  50519. return WC_TEST_RET_ENC_EC(ret);
  50520. ret = mp_montgomery_reduce(a, m, mp);
  50521. if (ret != MP_OKAY)
  50522. return WC_TEST_RET_ENC_EC(ret);
  50523. ret = mp_montgomery_reduce(a, m, mp);
  50524. if (ret != MP_OKAY)
  50525. return WC_TEST_RET_ENC_EC(ret);
  50526. if (mp_cmp(a, r) != MP_EQ)
  50527. return WC_TEST_RET_ENC_NC;
  50528. }
  50529. }
  50530. /* Force carries. */
  50531. for (i = 0; i < (int)(sizeof(bits) / sizeof(*bits)); i++) {
  50532. /* a = 2^(bits*2) - 1 */
  50533. mp_zero(a);
  50534. mp_set_bit(a, bits[i] * 2);
  50535. mp_sub_d(a, 1, a);
  50536. /* m = 2^(bits) - 1 */
  50537. mp_zero(m);
  50538. mp_set_bit(m, bits[i]);
  50539. mp_sub_d(m, 1, m);
  50540. mp = 1;
  50541. /* result = r = 2^(bits) - 1 */
  50542. mp_zero(r);
  50543. mp_set_bit(r, bits[i]);
  50544. mp_sub_d(r, 1, r);
  50545. ret = mp_montgomery_reduce(a, m, mp);
  50546. if (ret != MP_OKAY)
  50547. return WC_TEST_RET_ENC_EC(ret);
  50548. /* Result is m or 0 if reduced to range of modulus. */
  50549. if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES)
  50550. return WC_TEST_RET_ENC_NC;
  50551. }
  50552. return 0;
  50553. }
  50554. #endif
  50555. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
  50556. {
  50557. WC_RNG rng;
  50558. int rng_inited = 0;
  50559. wc_test_ret_t ret;
  50560. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  50561. int i, j;
  50562. #ifndef WOLFSSL_SP_MATH
  50563. int k;
  50564. #endif
  50565. mp_digit d = 0;
  50566. #endif
  50567. #ifdef WOLFSSL_SMALL_STACK
  50568. mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50569. DYNAMIC_TYPE_TMP_BUFFER),
  50570. *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50571. DYNAMIC_TYPE_TMP_BUFFER),
  50572. *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50573. DYNAMIC_TYPE_TMP_BUFFER),
  50574. *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50575. DYNAMIC_TYPE_TMP_BUFFER),
  50576. *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50577. DYNAMIC_TYPE_TMP_BUFFER);
  50578. if ((a == NULL) ||
  50579. (b == NULL) ||
  50580. (r1 == NULL) ||
  50581. (r2 == NULL) ||
  50582. (p == NULL))
  50583. {
  50584. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  50585. }
  50586. #else
  50587. mp_int a[1], b[1], r1[1], r2[1], p[1];
  50588. #endif
  50589. WOLFSSL_ENTER("mp_test");
  50590. ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
  50591. if (ret != 0)
  50592. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50593. #ifdef WOLFSSL_SP_MATH_ALL
  50594. mp_init_copy(p, a);
  50595. #else
  50596. ret = mp_init(p);
  50597. if (ret != 0)
  50598. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50599. #endif
  50600. #ifndef HAVE_FIPS
  50601. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  50602. #else
  50603. ret = wc_InitRng(&rng);
  50604. #endif
  50605. if (ret != 0)
  50606. goto done;
  50607. rng_inited = 1;
  50608. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  50609. mp_set_int(a, 0);
  50610. if (a->used != 0 || a->dp[0] != 0)
  50611. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50612. for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) {
  50613. for (i = 0; i < 4 * j; i++) {
  50614. /* New values to use. */
  50615. ret = randNum(p, j, &rng, NULL);
  50616. if (ret != 0)
  50617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50618. ret = randNum(a, j, &rng, NULL);
  50619. if (ret != 0)
  50620. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50621. ret = randNum(b, j, &rng, NULL);
  50622. if (ret != 0)
  50623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50624. ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d));
  50625. if (ret != 0)
  50626. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50627. d &= MP_MASK;
  50628. #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \
  50629. (defined(ECC_SHAMIR) || defined(FP_ECC)))
  50630. /* Ensure sqrmod produce same result as mulmod. */
  50631. ret = mp_sqrmod(a, p, r1);
  50632. if (ret != 0)
  50633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50634. ret = mp_mulmod(a, a, p, r2);
  50635. if (ret != 0)
  50636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50637. if (mp_cmp(r1, r2) != 0) {
  50638. WOLFSSL_MSG("Fail: mp_mulmod result does not match mp_sqrmod!");
  50639. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50640. }
  50641. #endif
  50642. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50643. #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \
  50644. !defined(WOLFSSL_SP_INT_NEGATIVE))
  50645. ret = mp_addmod(a, b, p, r1);
  50646. if (ret != 0)
  50647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50648. ret = mp_submod(r1, b, p, r2);
  50649. if (ret != 0)
  50650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50651. ret = mp_mod(a, p, r1);
  50652. if (ret != 0)
  50653. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50654. if (mp_cmp(r1, r2) != MP_EQ)
  50655. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50656. #else
  50657. /* Ensure add with mod produce same result as sub with mod. */
  50658. ret = mp_addmod(a, b, p, r1);
  50659. if (ret != 0)
  50660. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50661. b->sign ^= 1;
  50662. ret = mp_submod(a, b, p, r2);
  50663. if (ret != 0)
  50664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50665. if (mp_cmp(r1, r2) != 0)
  50666. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50667. #endif
  50668. #endif
  50669. /* Ensure add digit produce same result as sub digit. */
  50670. ret = mp_add_d(a, d, r1);
  50671. if (ret != 0)
  50672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50673. ret = mp_sub_d(r1, d, r2);
  50674. if (ret != 0)
  50675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50676. if (mp_cmp(a, r2) != 0)
  50677. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50678. /* Invert - if p is even it will use the slow impl.
  50679. * - if p and a are even it will fail.
  50680. */
  50681. ret = mp_invmod(a, p, r1);
  50682. if (ret != 0 && ret != WC_NO_ERR_TRACE(MP_VAL))
  50683. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50684. #ifndef WOLFSSL_SP_MATH
  50685. /* Shift up and down number all bits in a digit. */
  50686. for (k = 0; k < DIGIT_BIT; k++) {
  50687. mp_mul_2d(a, k, r1);
  50688. mp_div_2d(r1, k, r2, p);
  50689. if (mp_cmp(a, r2) != 0)
  50690. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50691. if (!mp_iszero(p))
  50692. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50693. mp_rshb(r1, k);
  50694. if (mp_cmp(a, r1) != 0)
  50695. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50696. }
  50697. #endif
  50698. }
  50699. }
  50700. /* Test adding and subtracting zero from zero. */
  50701. mp_zero(a);
  50702. ret = mp_add_d(a, 0, r1);
  50703. if (ret != 0)
  50704. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50705. if (!mp_iszero(r1)) {
  50706. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50707. }
  50708. ret = mp_sub_d(a, 0, r2);
  50709. if (ret != 0)
  50710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50711. if (!mp_iszero(r2)) {
  50712. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50713. }
  50714. #if DIGIT_BIT >= 32
  50715. /* Check that setting a 32-bit digit works. */
  50716. d &= 0xffffffffU;
  50717. mp_set_int(a, d);
  50718. if (a->used != 1 || a->dp[0] != d)
  50719. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50720. #endif
  50721. /* Check setting a bit and testing a bit works. */
  50722. for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) {
  50723. mp_zero(a);
  50724. mp_set_bit(a, i);
  50725. if (!mp_is_bit_set(a, i))
  50726. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50727. }
  50728. #endif
  50729. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  50730. mp_zero(a);
  50731. i = mp_cnt_lsb(a);
  50732. if (i != 0)
  50733. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50734. mp_set(a, 1);
  50735. i = mp_cnt_lsb(a);
  50736. if (i != 0)
  50737. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50738. mp_set(a, 32);
  50739. i = mp_cnt_lsb(a);
  50740. if (i != 5)
  50741. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50742. mp_zero(a);
  50743. mp_set_bit(a, 129);
  50744. i = mp_cnt_lsb(a);
  50745. if (i != 129)
  50746. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50747. #endif
  50748. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50749. if ((ret = mp_test_param(a, b, r1, &rng)) != 0)
  50750. goto done;
  50751. #endif
  50752. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  50753. if ((ret = mp_test_div_3(a, r1, &rng)) != 0)
  50754. goto done;
  50755. #endif
  50756. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  50757. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  50758. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  50759. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  50760. if ((ret = mp_test_radix_10(a, r1, &rng)) != 0)
  50761. goto done;
  50762. #endif
  50763. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  50764. defined(HAVE_ECC))
  50765. if ((ret = mp_test_radix_16(a, r1, &rng)) != 0)
  50766. goto done;
  50767. #endif
  50768. if ((ret = mp_test_shift(a, r1, &rng)) != 0)
  50769. goto done;
  50770. if ((ret = mp_test_add_sub_d(a, r1)) != 0)
  50771. goto done;
  50772. if ((ret = mp_test_read_to_bin(a)) != 0)
  50773. goto done;
  50774. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50775. if ((ret = mp_test_set_int(a)) != 0)
  50776. goto done;
  50777. #endif
  50778. if ((ret = mp_test_cmp(a, r1)) != 0)
  50779. goto done;
  50780. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50781. if ((ret = mp_test_shbd(a, b, &rng)) != 0)
  50782. goto done;
  50783. #endif
  50784. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50785. if ((ret = mp_test_set_is_bit(a)) != 0)
  50786. goto done;
  50787. #endif
  50788. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50789. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  50790. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50791. if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
  50792. goto done;
  50793. #endif
  50794. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50795. !defined(WC_NO_RNG)
  50796. if ((ret = mp_test_prime(a, &rng)) != 0)
  50797. goto done;
  50798. #endif
  50799. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50800. if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0)
  50801. goto done;
  50802. #endif
  50803. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50804. defined(WOLFSSL_SP_MATH_ALL)
  50805. if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0)
  50806. goto done;
  50807. #endif
  50808. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50809. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50810. if ((ret = mp_test_mod_d(a, &rng)) != 0)
  50811. goto done;
  50812. #endif
  50813. if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
  50814. goto done;
  50815. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  50816. defined(OPENSSL_EXTRA)
  50817. if ((ret = mp_test_invmod(a, b, r1)) != 0)
  50818. goto done;
  50819. #endif
  50820. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  50821. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  50822. if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0)
  50823. goto done;
  50824. #endif
  50825. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50826. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50827. if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0)
  50828. goto done;
  50829. #endif
  50830. done:
  50831. #ifdef WOLFSSL_SMALL_STACK
  50832. if (p) {
  50833. mp_clear(p);
  50834. XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50835. }
  50836. if (r2) {
  50837. mp_clear(r2);
  50838. XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50839. }
  50840. if (r1) {
  50841. mp_clear(r1);
  50842. XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50843. }
  50844. if (b) {
  50845. mp_clear(b);
  50846. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50847. }
  50848. if (a) {
  50849. mp_clear(a);
  50850. XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50851. }
  50852. #else
  50853. mp_clear(p);
  50854. mp_clear(r2);
  50855. mp_clear(r1);
  50856. mp_clear(b);
  50857. mp_clear(a);
  50858. #endif
  50859. if (rng_inited)
  50860. wc_FreeRng(&rng);
  50861. return ret;
  50862. }
  50863. #endif /* WOLFSSL_PUBLIC_MP && ((WOLFSSL_SP_MATH_ALL &&
  50864. * !WOLFSSL_RSA_VERIFY_ONLY) || USE_FAST_MATH) */
  50865. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  50866. typedef struct pairs_t {
  50867. const unsigned char* coeff;
  50868. int coeffSz;
  50869. int exp;
  50870. } pairs_t;
  50871. /*
  50872. n =p1p2p3, where pi = ki(p1-1)+1 with (k2,k3) = (173,293)
  50873. p1 = 2^192 * 0x000000000000e24fd4f6d6363200bf2323ec46285cac1d3a
  50874. + 2^0 * 0x0b2488b0c29d96c5e67f8bec15b54b189ae5636efe89b45b
  50875. */
  50876. static const unsigned char c192a[] =
  50877. {
  50878. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x4f,
  50879. 0xd4, 0xf6, 0xd6, 0x36, 0x32, 0x00, 0xbf, 0x23,
  50880. 0x23, 0xec, 0x46, 0x28, 0x5c, 0xac, 0x1d, 0x3a
  50881. };
  50882. static const unsigned char c0a[] =
  50883. {
  50884. 0x0b, 0x24, 0x88, 0xb0, 0xc2, 0x9d, 0x96, 0xc5,
  50885. 0xe6, 0x7f, 0x8b, 0xec, 0x15, 0xb5, 0x4b, 0x18,
  50886. 0x9a, 0xe5, 0x63, 0x6e, 0xfe, 0x89, 0xb4, 0x5b
  50887. };
  50888. static const pairs_t ecPairsA[] =
  50889. {
  50890. {c192a, sizeof(c192a), 192},
  50891. {c0a, sizeof(c0a), 0}
  50892. };
  50893. static const int kA[] = {173, 293};
  50894. static const unsigned char controlPrime[] = {
  50895. 0xe1, 0x76, 0x45, 0x80, 0x59, 0xb6, 0xd3, 0x49,
  50896. 0xdf, 0x0a, 0xef, 0x12, 0xd6, 0x0f, 0xf0, 0xb7,
  50897. 0xcb, 0x2a, 0x37, 0xbf, 0xa7, 0xf8, 0xb5, 0x4d,
  50898. 0xf5, 0x31, 0x35, 0xad, 0xe4, 0xa3, 0x94, 0xa1,
  50899. 0xdb, 0xf1, 0x96, 0xad, 0xb5, 0x05, 0x64, 0x85,
  50900. 0x83, 0xfc, 0x1b, 0x5b, 0x29, 0xaa, 0xbe, 0xf8,
  50901. 0x26, 0x3f, 0x76, 0x7e, 0xad, 0x1c, 0xf0, 0xcb,
  50902. 0xd7, 0x26, 0xb4, 0x1b, 0x05, 0x8e, 0x56, 0x86,
  50903. 0x7e, 0x08, 0x62, 0x21, 0xc1, 0x86, 0xd6, 0x47,
  50904. 0x79, 0x3e, 0xb7, 0x5d, 0xa4, 0xc6, 0x3a, 0xd7,
  50905. 0xb1, 0x74, 0x20, 0xf6, 0x50, 0x97, 0x41, 0x04,
  50906. 0x53, 0xed, 0x3f, 0x26, 0xd6, 0x6f, 0x91, 0xfa,
  50907. 0x68, 0x26, 0xec, 0x2a, 0xdc, 0x9a, 0xf1, 0xe7,
  50908. 0xdc, 0xfb, 0x73, 0xf0, 0x79, 0x43, 0x1b, 0x21,
  50909. 0xa3, 0x59, 0x04, 0x63, 0x52, 0x07, 0xc9, 0xd7,
  50910. 0xe6, 0xd1, 0x1b, 0x5d, 0x5e, 0x96, 0xfa, 0x53
  50911. };
  50912. static const unsigned char testOne[] = { 1 };
  50913. static wc_test_ret_t GenerateNextP(mp_int* p1, mp_int* p2, int k)
  50914. {
  50915. wc_test_ret_t ret;
  50916. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  50917. mp_int *ki = (mp_int *)XMALLOC(sizeof(*ki), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50918. if (ki == NULL)
  50919. return MEMORY_E;
  50920. #else
  50921. mp_int ki[1];
  50922. #endif
  50923. ret = mp_init(ki);
  50924. if (ret != 0)
  50925. ret = WC_TEST_RET_ENC_EC(ret);
  50926. if (ret == 0) {
  50927. ret = mp_set(ki, (mp_digit)k);
  50928. if (ret != 0)
  50929. ret = WC_TEST_RET_ENC_EC(ret);
  50930. }
  50931. if (ret == 0) {
  50932. ret = mp_sub_d(p1, 1, p2);
  50933. if (ret != 0)
  50934. ret = WC_TEST_RET_ENC_EC(ret);
  50935. }
  50936. if (ret == 0) {
  50937. ret = mp_mul(p2, ki, p2);
  50938. if (ret != 0)
  50939. ret = WC_TEST_RET_ENC_EC(ret);
  50940. }
  50941. if (ret == 0) {
  50942. ret = mp_add_d(p2, 1, p2);
  50943. if (ret != 0)
  50944. ret = WC_TEST_RET_ENC_EC(ret);
  50945. }
  50946. mp_clear(ki);
  50947. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  50948. XFREE(ki, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50949. #endif
  50950. return ret;
  50951. }
  50952. static wc_test_ret_t GenerateP(mp_int* p1, mp_int* p2, mp_int* p3,
  50953. const pairs_t* ecPairs, int ecPairsSz,
  50954. const int* k)
  50955. {
  50956. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  50957. mp_int *x = NULL, *y = NULL;
  50958. #else
  50959. mp_int x[1], y[1];
  50960. #endif
  50961. wc_test_ret_t ret;
  50962. int i;
  50963. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  50964. if (((x = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) ||
  50965. ((y = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)) {
  50966. ret = MEMORY_E;
  50967. goto out;
  50968. }
  50969. #endif
  50970. ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL);
  50971. if (ret != 0) {
  50972. ret = WC_TEST_RET_ENC_EC(ret);
  50973. goto out;
  50974. }
  50975. for (i = 0; ret == 0 && i < ecPairsSz; i++) {
  50976. ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, (word32)ecPairs[i].coeffSz);
  50977. if (ret != 0) {
  50978. ret = WC_TEST_RET_ENC_EC(ret);
  50979. break;
  50980. }
  50981. /* p1 = 2^exp */
  50982. ret = mp_2expt(y, ecPairs[i].exp);
  50983. if (ret != 0) {
  50984. ret = WC_TEST_RET_ENC_EC(ret);
  50985. break;
  50986. }
  50987. /* p1 = p1 * m */
  50988. ret = mp_mul(x, y, x);
  50989. if (ret != 0) {
  50990. ret = WC_TEST_RET_ENC_EC(ret);
  50991. break;
  50992. }
  50993. /* p1 += */
  50994. ret = mp_add(p1, x, p1);
  50995. if (ret != 0) {
  50996. ret = WC_TEST_RET_ENC_EC(ret);
  50997. break;
  50998. }
  50999. mp_zero(x);
  51000. mp_zero(y);
  51001. }
  51002. if (ret == 0)
  51003. ret = GenerateNextP(p1, p2, k[0]);
  51004. if (ret == 0)
  51005. ret = GenerateNextP(p1, p3, k[1]);
  51006. out:
  51007. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51008. if (x != NULL) {
  51009. mp_clear(x);
  51010. XFREE(x, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51011. }
  51012. if (y != NULL) {
  51013. mp_clear(y);
  51014. XFREE(y, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51015. }
  51016. #else
  51017. mp_clear(x);
  51018. mp_clear(y);
  51019. #endif
  51020. return ret;
  51021. }
  51022. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void)
  51023. {
  51024. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51025. mp_int *n = (mp_int *)XMALLOC(sizeof *n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51026. *p1 = (mp_int *)XMALLOC(sizeof *p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51027. *p2 = (mp_int *)XMALLOC(sizeof *p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51028. *p3 = (mp_int *)XMALLOC(sizeof *p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51029. #else
  51030. mp_int n[1],
  51031. p1[1],
  51032. p2[1],
  51033. p3[1];
  51034. #endif
  51035. wc_test_ret_t ret;
  51036. int isPrime = 0;
  51037. WC_RNG rng;
  51038. WOLFSSL_ENTER("prime_test");
  51039. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51040. if ((n == NULL) ||
  51041. (p1 == NULL) ||
  51042. (p2 == NULL) ||
  51043. (p3 == NULL))
  51044. ERROR_OUT(MEMORY_E, out);
  51045. #endif
  51046. ret = wc_InitRng(&rng);
  51047. if (ret != 0)
  51048. ret = WC_TEST_RET_ENC_EC(ret);
  51049. if (ret == 0) {
  51050. ret = mp_init_multi(n, p1, p2, p3, NULL, NULL);
  51051. if (ret != 0)
  51052. ret = WC_TEST_RET_ENC_EC(ret);
  51053. }
  51054. if (ret == 0)
  51055. ret = GenerateP(p1, p2, p3,
  51056. ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA);
  51057. if (ret == 0) {
  51058. ret = mp_mul(p1, p2, n);
  51059. if (ret != 0)
  51060. ret = WC_TEST_RET_ENC_EC(ret);
  51061. }
  51062. if (ret == 0) {
  51063. ret = mp_mul(n, p3, n);
  51064. if (ret != 0)
  51065. ret = WC_TEST_RET_ENC_EC(ret);
  51066. }
  51067. if (ret != 0)
  51068. ERROR_OUT(ret, out);
  51069. /* Check the old prime test using the number that false positives.
  51070. * This test result should indicate as not prime. */
  51071. ret = mp_prime_is_prime(n, 40, &isPrime);
  51072. if (ret != 0)
  51073. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51074. if (isPrime)
  51075. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51076. /* This test result should fail. It should indicate the value as prime. */
  51077. ret = mp_prime_is_prime(n, 8, &isPrime);
  51078. if (ret != 0)
  51079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51080. if (!isPrime)
  51081. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51082. /* This test result should indicate the value as not prime. */
  51083. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51084. if (ret != 0)
  51085. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51086. if (isPrime)
  51087. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51088. ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime));
  51089. if (ret != 0)
  51090. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51091. /* This test result should indicate the value as prime. */
  51092. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51093. if (ret != 0)
  51094. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51095. if (!isPrime)
  51096. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51097. /* This test result should indicate the value as prime. */
  51098. isPrime = -1;
  51099. ret = mp_prime_is_prime(n, 8, &isPrime);
  51100. if (ret != 0)
  51101. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51102. if (!isPrime)
  51103. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51104. ret = mp_read_unsigned_bin(n, testOne, sizeof(testOne));
  51105. if (ret != 0)
  51106. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51107. /* This test result should indicate the value as not prime. */
  51108. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51109. if (ret != 0)
  51110. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51111. if (isPrime)
  51112. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51113. ret = mp_prime_is_prime(n, 8, &isPrime);
  51114. if (ret != 0)
  51115. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51116. if (isPrime)
  51117. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51118. ret = 0;
  51119. out:
  51120. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51121. if (n != NULL) {
  51122. mp_clear(n);
  51123. XFREE(n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51124. }
  51125. if (p1 != NULL) {
  51126. mp_clear(p1);
  51127. XFREE(p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51128. }
  51129. if (p2 != NULL) {
  51130. mp_clear(p2);
  51131. XFREE(p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51132. }
  51133. if (p3 != NULL) {
  51134. mp_clear(p3);
  51135. XFREE(p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51136. }
  51137. #else
  51138. mp_clear(p3);
  51139. mp_clear(p2);
  51140. mp_clear(p1);
  51141. mp_clear(n);
  51142. #endif
  51143. wc_FreeRng(&rng);
  51144. return ret;
  51145. }
  51146. #endif /* WOLFSSL_PUBLIC_MP */
  51147. #ifdef ASN_BER_TO_DER
  51148. /* wc_BerToDer is only public facing in the case of test cert or opensslextra */
  51149. typedef struct berDerTestData {
  51150. const byte *in;
  51151. word32 inSz;
  51152. const byte *out;
  51153. word32 outSz;
  51154. } berDerTestData;
  51155. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void)
  51156. {
  51157. wc_test_ret_t ret;
  51158. int i;
  51159. word32 len = 0, l;
  51160. byte out[32];
  51161. WOLFSSL_SMALL_STACK_STATIC const byte good1_in[] = { 0x30, 0x80, 0x00, 0x00 };
  51162. WOLFSSL_SMALL_STACK_STATIC const byte good1_out[] = { 0x30, 0x00 };
  51163. WOLFSSL_SMALL_STACK_STATIC const byte good2_in[] = { 0x30, 0x80, 0x02, 0x01, 0x01, 0x00, 0x00 };
  51164. WOLFSSL_SMALL_STACK_STATIC const byte good2_out[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51165. WOLFSSL_SMALL_STACK_STATIC const byte good3_in[] = {
  51166. 0x24, 0x80, 0x04, 0x01, 0x01, 0x00, 0x00
  51167. };
  51168. WOLFSSL_SMALL_STACK_STATIC const byte good3_out[] = { 0x04, 0x1, 0x01 };
  51169. WOLFSSL_SMALL_STACK_STATIC const byte good4_in[] = {
  51170. 0x30, 0x80,
  51171. 0x02, 0x01, 0x01,
  51172. 0x30, 0x80,
  51173. 0x24, 0x80,
  51174. 0x04, 0x01, 0x01,
  51175. 0x04, 0x02, 0x02, 0x03,
  51176. 0x00, 0x00,
  51177. 0x06, 0x01, 0x01,
  51178. 0x00, 0x00,
  51179. 0x31, 0x80,
  51180. 0x06, 0x01, 0x01,
  51181. 0x00, 0x00,
  51182. 0x00, 0x00,
  51183. };
  51184. WOLFSSL_SMALL_STACK_STATIC const byte good4_out[] = {
  51185. 0x30, 0x12,
  51186. 0x02, 0x01, 0x01,
  51187. 0x30, 0x08,
  51188. 0x04, 0x03, 0x01, 0x02, 0x03,
  51189. 0x06, 0x01, 0x01,
  51190. 0x31, 0x03,
  51191. 0x06, 0x01, 0x01
  51192. };
  51193. WOLFSSL_SMALL_STACK_STATIC const byte good5_in[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51194. berDerTestData testData[] = {
  51195. { good1_in, sizeof(good1_in), good1_out, sizeof(good1_out) },
  51196. { good2_in, sizeof(good2_in), good2_out, sizeof(good2_out) },
  51197. { good3_in, sizeof(good3_in), good3_out, sizeof(good3_out) },
  51198. { good4_in, sizeof(good4_in), good4_out, sizeof(good4_out) },
  51199. { good5_in, sizeof(good5_in), good5_in , sizeof(good5_in ) },
  51200. };
  51201. WOLFSSL_ENTER("berder_test");
  51202. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  51203. ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len);
  51204. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  51205. return WC_TEST_RET_ENC_I(i);
  51206. if (len != testData[i].outSz)
  51207. return WC_TEST_RET_ENC_I(i);
  51208. len = testData[i].outSz;
  51209. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len);
  51210. if (ret != 0)
  51211. return WC_TEST_RET_ENC_I(i);
  51212. if (XMEMCMP(out, testData[i].out, len) != 0)
  51213. return WC_TEST_RET_ENC_I(i);
  51214. for (l = 1; l < testData[i].inSz; l++) {
  51215. ret = wc_BerToDer(testData[i].in, l, NULL, &len);
  51216. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  51217. return WC_TEST_RET_ENC_EC(ret);
  51218. len = testData[i].outSz;
  51219. ret = wc_BerToDer(testData[i].in, l, out, &len);
  51220. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  51221. return WC_TEST_RET_ENC_EC(ret);
  51222. }
  51223. for (l = 0; l < testData[i].outSz-1; l++) {
  51224. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l);
  51225. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  51226. return WC_TEST_RET_ENC_EC(ret);
  51227. }
  51228. }
  51229. ret = wc_BerToDer(NULL, 4, NULL, NULL);
  51230. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51231. return WC_TEST_RET_ENC_EC(ret);
  51232. ret = wc_BerToDer(out, 4, NULL, NULL);
  51233. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51234. return WC_TEST_RET_ENC_EC(ret);
  51235. ret = wc_BerToDer(NULL, 4, NULL, &len);
  51236. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51237. return WC_TEST_RET_ENC_EC(ret);
  51238. ret = wc_BerToDer(NULL, 4, out, NULL);
  51239. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51240. return WC_TEST_RET_ENC_EC(ret);
  51241. ret = wc_BerToDer(out, 4, out, NULL);
  51242. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51243. return WC_TEST_RET_ENC_EC(ret);
  51244. ret = wc_BerToDer(NULL, 4, out, &len);
  51245. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51246. return WC_TEST_RET_ENC_EC(ret);
  51247. for (l = 1; l < sizeof(good4_out); l++) {
  51248. len = l;
  51249. ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len);
  51250. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  51251. return WC_TEST_RET_ENC_EC(ret);
  51252. }
  51253. return 0;
  51254. }
  51255. #endif /* ASN_BER_TO_DER */
  51256. #ifdef DEBUG_WOLFSSL
  51257. static THREAD_LS_T int log_cnt = 0;
  51258. static void my_Logging_cb(const int logLevel, const char *const logMessage)
  51259. {
  51260. (void)logLevel;
  51261. (void)logMessage;
  51262. log_cnt++;
  51263. }
  51264. #endif /* DEBUG_WOLFSSL */
  51265. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void)
  51266. {
  51267. wc_test_ret_t ret;
  51268. #ifdef DEBUG_WOLFSSL
  51269. const char* msg = "Testing, testing. 1, 2, 3, 4 ...";
  51270. byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  51271. byte b[256];
  51272. int i;
  51273. WOLFSSL_ENTER("logging_test (debug)");
  51274. for (i = 0; i < (int)sizeof(b); i++)
  51275. b[i] = i;
  51276. ret = wolfSSL_Debugging_ON();
  51277. if (ret != 0)
  51278. return WC_TEST_RET_ENC_EC(ret);
  51279. ret = wolfSSL_SetLoggingCb(my_Logging_cb);
  51280. if (ret != 0)
  51281. return WC_TEST_RET_ENC_EC(ret);
  51282. WOLFSSL_MSG(msg);
  51283. WOLFSSL_BUFFER(a, sizeof(a));
  51284. WOLFSSL_BUFFER(b, sizeof(b));
  51285. WOLFSSL_BUFFER(NULL, 0);
  51286. WOLFSSL_ERROR(MEMORY_E);
  51287. WOLFSSL_ERROR_MSG(msg);
  51288. /* turn off logs */
  51289. wolfSSL_Debugging_OFF();
  51290. /* capture log count */
  51291. i = log_cnt;
  51292. /* validate no logs are output when disabled */
  51293. WOLFSSL_MSG(msg);
  51294. WOLFSSL_BUFFER(a, sizeof(a));
  51295. WOLFSSL_BUFFER(b, sizeof(b));
  51296. WOLFSSL_BUFFER(NULL, 0);
  51297. WOLFSSL_ERROR(MEMORY_E);
  51298. WOLFSSL_ERROR_MSG(msg);
  51299. /* check the logs were disabled */
  51300. if (i != log_cnt)
  51301. return WC_TEST_RET_ENC_NC;
  51302. /* restore callback and leave logging enabled */
  51303. wolfSSL_SetLoggingCb(NULL);
  51304. wolfSSL_Debugging_ON();
  51305. /* suppress unused args */
  51306. (void)a;
  51307. (void)b;
  51308. #else
  51309. WOLFSSL_ENTER("logging_test");
  51310. ret = wolfSSL_Debugging_ON();
  51311. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  51312. return WC_TEST_RET_ENC_EC(ret);
  51313. wolfSSL_Debugging_OFF();
  51314. ret = wolfSSL_SetLoggingCb(NULL);
  51315. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  51316. return WC_TEST_RET_ENC_EC(ret);
  51317. #endif /* DEBUG_WOLFSSL */
  51318. return 0;
  51319. }
  51320. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  51321. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void)
  51322. #else
  51323. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void)
  51324. #endif
  51325. {
  51326. #ifdef WOLFSSL_PTHREADS
  51327. wolfSSL_Mutex m;
  51328. #endif
  51329. #if defined(WOLFSSL_PTHREADS) || (!defined(WOLFSSL_NO_MALLOC) && \
  51330. !defined(WOLFSSL_USER_MUTEX) && defined(WOLFSSL_STATIC_MEMORY))
  51331. wc_test_ret_t ret;
  51332. #endif
  51333. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX)
  51334. #ifndef WOLFSSL_STATIC_MEMORY
  51335. wolfSSL_Mutex *mm = wc_InitAndAllocMutex();
  51336. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (1)");
  51337. #else
  51338. wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex),
  51339. HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51340. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (2)");
  51341. if (mm != NULL) {
  51342. ret = wc_InitMutex(mm);
  51343. if (ret != 0) {
  51344. WOLFSSL_MSG("Init Mutex failed");
  51345. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51346. return WC_TEST_RET_ENC_EC(ret);
  51347. }
  51348. }
  51349. #endif
  51350. if (mm == NULL)
  51351. return WC_TEST_RET_ENC_ERRNO;
  51352. wc_FreeMutex(mm);
  51353. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51354. #endif
  51355. /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */
  51356. #ifdef WOLFSSL_PTHREADS
  51357. ret = wc_InitMutex(&m);
  51358. if (ret != 0)
  51359. return WC_TEST_RET_ENC_EC(ret);
  51360. ret = wc_LockMutex(&m);
  51361. if (ret != 0)
  51362. return WC_TEST_RET_ENC_EC(ret);
  51363. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  51364. /* trying to free a locked mutex is not portable behavior with pthread */
  51365. /* Attempting to destroy a locked mutex results in undefined behavior */
  51366. ret = wc_FreeMutex(&m);
  51367. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51368. return WC_TEST_RET_ENC_EC(ret);
  51369. #endif
  51370. ret = wc_UnLockMutex(&m);
  51371. if (ret != 0)
  51372. return WC_TEST_RET_ENC_EC(ret);
  51373. ret = wc_FreeMutex(&m);
  51374. if (ret != 0)
  51375. return WC_TEST_RET_ENC_EC(ret);
  51376. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  51377. /* Trying to use a pthread after free'ing is not portable behavior */
  51378. ret = wc_LockMutex(&m);
  51379. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51380. return WC_TEST_RET_ENC_EC(ret);
  51381. ret = wc_UnLockMutex(&m);
  51382. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51383. return WC_TEST_RET_ENC_EC(ret);
  51384. #endif
  51385. #endif
  51386. return 0;
  51387. }
  51388. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  51389. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \
  51390. !defined(WOLFSSL_STATIC_MEMORY)
  51391. static wc_test_ret_t malloc_cnt = 0;
  51392. static wc_test_ret_t realloc_cnt = 0;
  51393. static wc_test_ret_t free_cnt = 0;
  51394. #ifdef WOLFSSL_DEBUG_MEMORY
  51395. static void *my_Malloc_cb(size_t size, const char* func, unsigned int line)
  51396. {
  51397. (void) func;
  51398. (void) line;
  51399. #else
  51400. static void *my_Malloc_cb(size_t size)
  51401. {
  51402. #endif
  51403. malloc_cnt++;
  51404. #ifndef WOLFSSL_NO_MALLOC
  51405. return malloc(size);
  51406. #else
  51407. WOLFSSL_MSG("No malloc available");
  51408. (void)size;
  51409. return NULL;
  51410. #endif
  51411. }
  51412. #ifdef WOLFSSL_DEBUG_MEMORY
  51413. static void my_Free_cb(void *ptr, const char* func, unsigned int line)
  51414. {
  51415. (void) func;
  51416. (void) line;
  51417. #else
  51418. static void my_Free_cb(void *ptr)
  51419. {
  51420. #endif
  51421. free_cnt++;
  51422. #ifndef WOLFSSL_NO_MALLOC
  51423. free(ptr);
  51424. #else
  51425. WOLFSSL_MSG("No free available");
  51426. (void)ptr;
  51427. #endif
  51428. }
  51429. #ifdef WOLFSSL_DEBUG_MEMORY
  51430. static void *my_Realloc_cb(void *ptr, size_t size, const char* func, unsigned int line)
  51431. {
  51432. (void) func;
  51433. (void) line;
  51434. #else
  51435. static void *my_Realloc_cb(void *ptr, size_t size)
  51436. {
  51437. #endif
  51438. realloc_cnt++;
  51439. #ifndef WOLFSSL_NO_MALLOC
  51440. return realloc(ptr, size);
  51441. #else
  51442. WOLFSSL_MSG("No realloc available");
  51443. (void)ptr;
  51444. (void)size;
  51445. return NULL;
  51446. #endif
  51447. }
  51448. #endif /* !WOLFSSL_NO_MALLOC */
  51449. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void)
  51450. {
  51451. wc_test_ret_t ret = 0;
  51452. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51453. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51454. byte* b = NULL;
  51455. #endif
  51456. wolfSSL_Malloc_cb mc;
  51457. wolfSSL_Free_cb fc;
  51458. wolfSSL_Realloc_cb rc;
  51459. WOLFSSL_ENTER("memcb_test");
  51460. /* Save existing memory callbacks */
  51461. ret = wolfSSL_GetAllocators(&mc, &fc, &rc);
  51462. if (ret != 0)
  51463. return WC_TEST_RET_ENC_EC(ret);
  51464. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51465. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51466. /* test realloc */
  51467. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51468. if (b == NULL) {
  51469. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb);
  51470. }
  51471. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51472. b = NULL;
  51473. /* Use API. */
  51474. ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb,
  51475. (wolfSSL_Free_cb)my_Free_cb,
  51476. (wolfSSL_Realloc_cb)my_Realloc_cb);
  51477. if (ret != 0) {
  51478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb);
  51479. }
  51480. b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51481. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51482. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51483. #ifndef WOLFSSL_STATIC_MEMORY
  51484. #ifndef WOLFSSL_CHECK_MEM_ZERO
  51485. if (malloc_cnt != 1 || free_cnt != 1 || realloc_cnt != 1)
  51486. #else
  51487. /* Checking zeroized memory means realloc is a malloc and free. */
  51488. if (malloc_cnt != 2 || free_cnt != 2 || realloc_cnt != 0)
  51489. #endif
  51490. #else
  51491. if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0)
  51492. #endif
  51493. ret = WC_TEST_RET_ENC_NC;
  51494. #endif /* !WOLFSSL_NO_MALLOC */
  51495. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51496. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51497. exit_memcb:
  51498. /* reset malloc/free/realloc counts */
  51499. malloc_cnt = 0;
  51500. free_cnt = 0;
  51501. realloc_cnt = 0;
  51502. #endif
  51503. /* restore memory callbacks */
  51504. wolfSSL_SetAllocators(mc, fc, rc);
  51505. return ret;
  51506. }
  51507. #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */
  51508. #if defined(WOLFSSL_CAAM_BLOB)
  51509. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void)
  51510. {
  51511. wc_test_ret_t ret = 0;
  51512. byte out[112];
  51513. byte blob[112];
  51514. word32 outSz;
  51515. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  51516. {
  51517. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  51518. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  51519. };
  51520. WOLFSSL_SMALL_STACK_STATIC const byte text[] =
  51521. {
  51522. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  51523. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  51524. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  51525. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  51526. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  51527. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  51528. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  51529. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  51530. };
  51531. WOLFSSL_ENTER("blob_test");
  51532. XMEMSET(blob, 0, sizeof(blob));
  51533. XMEMSET(out, 0, sizeof(out));
  51534. outSz = sizeof(blob);
  51535. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  51536. if (ret != 0)
  51537. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51538. blob[outSz - 2] += 1;
  51539. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51540. if (ret == 0) { /* should fail with altered blob */
  51541. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51542. }
  51543. XMEMSET(blob, 0, sizeof(blob));
  51544. outSz = sizeof(blob);
  51545. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  51546. if (ret != 0)
  51547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51548. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51549. if (ret != 0)
  51550. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51551. if (XMEMCMP(out, iv, sizeof(iv))) {
  51552. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51553. }
  51554. XMEMSET(blob, 0, sizeof(blob));
  51555. outSz = sizeof(blob);
  51556. ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz);
  51557. if (ret != 0)
  51558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51559. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51560. if (ret != 0)
  51561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51562. if (XMEMCMP(out, text, sizeof(text))) {
  51563. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51564. }
  51565. exit_blob:
  51566. return ret;
  51567. }
  51568. #endif /* WOLFSSL_CAAM_BLOB */
  51569. #ifdef WOLF_CRYPTO_CB
  51570. /* Example custom context for crypto callback */
  51571. typedef struct {
  51572. int exampleVar; /* flag for testing if only crypt is enabled. */
  51573. } myCryptoDevCtx;
  51574. #ifdef WOLF_CRYPTO_CB_ONLY_RSA
  51575. /* Testing rsa cb when CB_ONLY_RSA is enabled
  51576. * When CB_ONLY_RSA is enabled, software imple. is not available.
  51577. *
  51578. * ctx callback ctx
  51579. * returen 0 on success, otherwise return negative
  51580. */
  51581. static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
  51582. {
  51583. wc_test_ret_t ret = 0;
  51584. #if !defined(NO_RSA)
  51585. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51586. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key,
  51587. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51588. byte* tmp = NULL;
  51589. #else
  51590. RsaKey key[1];
  51591. byte tmp[FOURK_BUF];
  51592. #endif
  51593. size_t bytes;
  51594. const word32 inLen = (word32)TEST_STRING_SZ;
  51595. word32 idx = 0;
  51596. word32 sigSz;
  51597. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  51598. byte out[RSA_TEST_BYTES];
  51599. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  51600. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  51601. !defined(NO_FILESYSTEM)
  51602. XFILE file;
  51603. #endif
  51604. #ifdef WOLFSSL_KEY_GEN
  51605. WC_RNG rng;
  51606. #endif
  51607. #ifdef USE_CERT_BUFFERS_1024
  51608. bytes = (size_t)sizeof_client_key_der_1024;
  51609. if (bytes < (size_t)sizeof_client_cert_der_1024)
  51610. bytes = (size_t)sizeof_client_cert_der_1024;
  51611. #elif defined(USE_CERT_BUFFERS_2048)
  51612. bytes = (size_t)sizeof_client_key_der_2048;
  51613. if (bytes < (size_t)sizeof_client_cert_der_2048)
  51614. bytes = (size_t)sizeof_client_cert_der_2048;
  51615. #elif defined(USE_CERT_BUFFERS_3072)
  51616. bytes = (size_t)sizeof_client_key_der_3072;
  51617. if (bytes < (size_t)sizeof_client_cert_der_3072)
  51618. bytes = (size_t)sizeof_client_cert_der_3072;
  51619. #elif defined(USE_CERT_BUFFERS_4096)
  51620. bytes = (size_t)sizeof_client_key_der_4096;
  51621. if (bytes < (size_t)sizeof_client_cert_der_4096)
  51622. bytes = (size_t)sizeof_client_cert_der_4096;
  51623. #else
  51624. bytes = FOURK_BUF;
  51625. #endif
  51626. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51627. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51628. if (tmp == NULL)
  51629. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  51630. #endif
  51631. #ifdef USE_CERT_BUFFERS_1024
  51632. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  51633. #elif defined(USE_CERT_BUFFERS_2048)
  51634. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  51635. #elif defined(USE_CERT_BUFFERS_3072)
  51636. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  51637. #elif defined(USE_CERT_BUFFERS_4096)
  51638. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  51639. #elif !defined(NO_FILESYSTEM)
  51640. file = XFOPEN(clientKey, "rb");
  51641. if (!file) {
  51642. ret = WC_TEST_RET_ENC_ERRNO;
  51643. err_sys("can't open ./certs/client-key.der, "
  51644. "Please run from wolfSSL home dir", ret);
  51645. ERROR_OUT(ret, exit_onlycb);
  51646. }
  51647. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  51648. XFCLOSE(file);
  51649. if (bytes == 0)
  51650. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  51651. #endif
  51652. #ifdef WOLFSSL_KEY_GEN
  51653. /* wc_CryptoCb_MakeRsaKey cb test, no actual making key
  51654. * wc_MakeRsaKey() -> rsa cb ->
  51655. * myCryptoDevCb -> wc_MakeRsaKey(CBONLY_TEST_DEVID)
  51656. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
  51657. */
  51658. ctx->exampleVar = 99;
  51659. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  51660. if (ret != 0)
  51661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51662. /* wc_MakeRsaKey() -> rsa cb ->
  51663. * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
  51664. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
  51665. */
  51666. ctx->exampleVar = 1;
  51667. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  51668. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51669. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51670. } else
  51671. /* reset return code */
  51672. ret = 0;
  51673. #endif
  51674. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  51675. if (ret != 0)
  51676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51677. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  51678. if (ret != 0)
  51679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51680. sigSz = (word32)wc_RsaEncryptSize(key);
  51681. /* wc_CryptoCb_Rsa cb test, no actual rsa operation */
  51682. if (ret == 0) {
  51683. /* wc_SignatureGenerate() -> rsa cb ->
  51684. * myCryptoDevCb -> wc_RsaFunction(CBONLY_TEST_DEVID)
  51685. * wc_RsaFunction(CBONLY_TEST_DEVID) expects to return 0(success)
  51686. */
  51687. ctx->exampleVar = 99;
  51688. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  51689. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  51690. if (ret != 0)
  51691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51692. }
  51693. if (ret == 0) {
  51694. /* wc_SignatureGenerate() -> rsa cb ->
  51695. * myCryptoDevCb -> wc_RsaFunction(INVALID_DEVID)
  51696. * wc_SignatureGenerate(INVALID_DEVID) expects to
  51697. * return NO_VALID_DEVID(failure)
  51698. */
  51699. ctx->exampleVar = 1;
  51700. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  51701. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  51702. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51704. } else
  51705. /* reset return code */
  51706. ret = 0;
  51707. }
  51708. exit_onlycb:
  51709. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51710. if (key != NULL) {
  51711. wc_FreeRsaKey(key);
  51712. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51713. }
  51714. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51715. #else
  51716. wc_FreeRsaKey(key);
  51717. #endif
  51718. #endif
  51719. return ret;
  51720. }
  51721. #endif
  51722. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  51723. /* Testing rsa cb when CB_ONLY_ECC is enabled
  51724. * When CB_ONLY_ECC is enabled, software imple. is not available.
  51725. *
  51726. * ctx callback ctx
  51727. * returen 0 on success, otherwise return negative
  51728. */
  51729. static wc_test_ret_t ecc_onlycb_test(myCryptoDevCtx *ctx)
  51730. {
  51731. wc_test_ret_t ret = 0;
  51732. #if defined(HAVE_ECC)
  51733. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51734. ecc_key* key = (ecc_key *)XMALLOC(sizeof *key,
  51735. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51736. ecc_key* pub = (ecc_key *)XMALLOC(sizeof *pub,
  51737. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51738. byte* out = (byte*)XMALLOC(sizeof(byte),
  51739. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51740. #ifdef OPENSSL_EXTRA
  51741. byte* check = (byte*)XMALLOC(sizeof(byte)*(256), HEAP_HINT,
  51742. DYNAMIC_TYPE_TMP_BUFFER);
  51743. #endif
  51744. #else
  51745. ecc_key key[1];
  51746. ecc_key pub[1];
  51747. byte out[256];
  51748. #ifdef OPENSSL_EXTRA
  51749. unsigned char check[256];
  51750. #endif
  51751. #endif
  51752. #ifdef OPENSSL_EXTRA
  51753. EVP_PKEY* privKey = NULL;
  51754. EVP_PKEY* pubKey = NULL;
  51755. #ifdef USE_CERT_BUFFERS_256
  51756. ecc_key* pkey;
  51757. const unsigned char* cp;
  51758. #endif
  51759. EVP_MD_CTX mdCtx;
  51760. const char testData[] = "Hi There";
  51761. size_t checkSz = -1;
  51762. const unsigned char* p;
  51763. const unsigned char check_v[256] = {
  51764. 0x30,0x45,0x02,0x20,0x1b,0x5c,0x2a,0xf0,0x18,0x09,
  51765. 0x74,0x65,0xa1,0x04,0x76,0x3a,0xce,0xcc,0xe5,0x34,
  51766. 0x5e,0x89,0xed,0x40,0x1e,0x5a,0xb1,0x53,0xb4,0xff,
  51767. 0xc7,0x18,0xfe,0x0f,0xc7,0xa6,0x02,0x21,0x00,0xe5,
  51768. 0x70,0x21,0xfc,0xf9,0x63,0x36,0xfd,0x16,0x18,0x08,
  51769. 0x9a,0x63,0x61,0x0f,0xe7,0x7c,0xa3,0xc9,0x14,0xa3,
  51770. 0x30,0x87,0xf7,0xf5,0x70,0x19,0xaf,0x56,0x96,0x9b,
  51771. 0xd8,0x64,0xcd,0xd9,0xff,0x7b,0x2a,0x55,0x52,0xca,
  51772. 0x41,0xb2,0xa6,0xa4,0x8a,0x3b,0x02,0x20,0x8c,0xc5,
  51773. 0xf9,0xc1,0x7d,0x2a,0x65,0x6c,0xe6,0x5a,0xe3,0x76,
  51774. 0x9b,0xab,0x0b,0x9f,0xaf,0x62,0x5d,0xb2,0x60,0xd7,
  51775. 0xeb,0xb4,0x1b,0x73,0xdc,0x01,0x7d,0x7b,0xab,0xc1,
  51776. 0x0c,0x74,0x96,0x41,0xe6,0x3f,0xc5,0x86,0xe6,0x7d,
  51777. 0x2b,0x9d,0x54,0x6b,0xcd,0x31,0x35,0x1f,0xdb,0x49,
  51778. 0x1f,0x32,0x34,0xf8,0x57,0x12,0x86,0x5c,0x0e,0x80,
  51779. 0x55,0x8d,0xff,0xd8,0xbd,0xdf,0x32,0x26,0x62,0x42,
  51780. 0x09,0xda,0xf7,0x74,0xf2,0x3f,0xe6,0xf1,0x77,0x82,
  51781. 0xce,0xe4,0xbb,0x61,0xa6,0xc0,0x17,0x0c,0x6c,0x47,
  51782. 0x2a,0x40,0x1c,0x2b,0xe0,0x98,0x3b,0xbf,0xc6,0xf8,
  51783. 0x6d,0xfd,0xd0,0xfa,0xc1,0x02,0xfb,0x5f,0xfb,0xb0,
  51784. 0xcb,0xd9,0xa3,0x59,0x94,0xe9,0x0f,0x74,0xbb,0x3f,
  51785. 0x64,0xa3,0x83,0xc4,0x2b,0xf7,0xd2,0x97,0xbf,0x3b,
  51786. 0xcf,0xbb,0x60,0x81,0x33,0x94,0xfa,0x0d,0x35,0xd2,
  51787. 0x3d,0xb9,0x99,0xe3,0x12,0xf8,0xf4,0xa3,0x74,0xf4,
  51788. 0x94,0x1d,0x7a,0x66,0xf8,0xd1,0x1d,0xcf,0xb0,0x48,
  51789. 0xef,0x8c,0x94,0x6f,0xdd,0x62,
  51790. };
  51791. #endif
  51792. WC_RNG rng;
  51793. EncryptedInfo encInfo;
  51794. int keyFormat = 0;
  51795. word32 keyIdx = 0;
  51796. byte in[] = "Everyone gets Friday off. ecc p";
  51797. word32 inLen = (word32)XSTRLEN((char*)in);
  51798. word32 outLen;
  51799. int verify;
  51800. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51801. if (key == NULL || pub == NULL) {
  51802. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  51803. }
  51804. #endif
  51805. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  51806. if (ret != 0)
  51807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51808. /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */
  51809. ctx->exampleVar = 99;
  51810. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  51811. if (ret != 0)
  51812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51813. ctx->exampleVar = 1;
  51814. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  51815. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51816. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51817. } else
  51818. /* reset return code */
  51819. ret = 0;
  51820. #ifdef USE_CERT_BUFFERS_256
  51821. if (ret == 0) {
  51822. /* load ECC private key and perform private transform */
  51823. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx,
  51824. key, sizeof_ecc_key_der_256);
  51825. }
  51826. if (ret != 0)
  51827. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51828. /* wc_CryptoCb_EccSign cb test, no actual testing */
  51829. ctx->exampleVar = 99;
  51830. if (ret == 0) {
  51831. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  51832. }
  51833. if (ret != 0)
  51834. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51835. ctx->exampleVar = 1;
  51836. if (ret == 0) {
  51837. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  51838. }
  51839. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51840. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51841. }
  51842. else
  51843. ret = 0;
  51844. /* wc_CryptoCb_EccVerify cb test, no actual testing */
  51845. ctx->exampleVar = 99;
  51846. if (ret == 0) {
  51847. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  51848. }
  51849. if (ret != 0)
  51850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51851. ctx->exampleVar = 1;
  51852. if (ret == 0) {
  51853. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  51854. }
  51855. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51856. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51857. }
  51858. else
  51859. ret = 0;
  51860. /* wc_CryptoCb_Ecdh cb test, no actual testing */
  51861. /* make public key for shared secret */
  51862. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  51863. ctx->exampleVar = 99;
  51864. if (ret == 0) {
  51865. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  51866. }
  51867. if (ret != 0)
  51868. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51869. ctx->exampleVar = 1;
  51870. if (ret == 0) {
  51871. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  51872. }
  51873. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51875. }
  51876. else
  51877. ret = 0;
  51878. #ifdef OPENSSL_EXTRA
  51879. (void)pkey;
  51880. cp = ecc_clikey_der_256;
  51881. privKey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  51882. sizeof_ecc_clikey_der_256);
  51883. if (privKey == NULL) {
  51884. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51885. }
  51886. pkey = (ecc_key*)privKey->ecc->internal;
  51887. pkey->devId = devId;
  51888. p = ecc_clikeypub_der_256;
  51889. pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256);
  51890. if (pubKey == NULL) {
  51891. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51892. }
  51893. pkey = (ecc_key*)pubKey->ecc->internal;
  51894. pkey->devId = devId;
  51895. /* sign */
  51896. EVP_MD_CTX_init(&mdCtx);
  51897. ret = EVP_DigestSignInit(&mdCtx, NULL, EVP_sha256(), NULL, privKey);
  51898. if (ret != WOLFSSL_SUCCESS) {
  51899. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51900. }
  51901. ret = EVP_DigestSignUpdate(&mdCtx, testData,
  51902. (unsigned int)XSTRLEN(testData));
  51903. if (ret != WOLFSSL_SUCCESS) {
  51904. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51905. }
  51906. ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz);
  51907. if (ret != WOLFSSL_SUCCESS) {
  51908. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51909. }
  51910. ctx->exampleVar = 99;
  51911. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  51912. /* just called crypt callback as dummy
  51913. * EVP_DigestSignFinal returns 0 internally.
  51914. */
  51915. if (ret != 0)
  51916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51917. ctx->exampleVar = 1;
  51918. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  51919. /* just called crypt callback as dummy
  51920. * EVP_DigestSignFinal returns 0 internally.
  51921. */
  51922. if (ret != 0)
  51923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51924. /* restore checkSz for verify */
  51925. checkSz = 71;
  51926. ret = EVP_MD_CTX_cleanup(&mdCtx);
  51927. if (ret != SSL_SUCCESS) {
  51928. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51929. }
  51930. /* verify */
  51931. EVP_MD_CTX_init(&mdCtx);
  51932. if (ret == SSL_SUCCESS) {
  51933. ret = EVP_DigestVerifyInit(&mdCtx, NULL, EVP_sha256(), NULL, pubKey);
  51934. }
  51935. if (ret != WOLFSSL_SUCCESS) {
  51936. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51937. }
  51938. if (ret == WOLFSSL_SUCCESS) {
  51939. ret = EVP_DigestVerifyUpdate(&mdCtx, testData,
  51940. (unsigned int)XSTRLEN(testData));
  51941. }
  51942. if (ret != WOLFSSL_SUCCESS) {
  51943. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51944. }
  51945. ctx->exampleVar = 99;
  51946. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  51947. /* just called crypt callback as dummy
  51948. * EVP_DigestSignFinal returns 0 internally.
  51949. */
  51950. if (ret != 0)
  51951. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51952. ctx->exampleVar = 1;
  51953. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  51954. /* just called crypt callback as dummy
  51955. * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID.
  51956. */
  51957. if (ret != -1) {
  51958. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51959. }
  51960. ret = EVP_MD_CTX_cleanup(&mdCtx);
  51961. if (ret != SSL_SUCCESS) {
  51962. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51963. } else
  51964. ret = 0;
  51965. #endif
  51966. #else
  51967. (void)verify;
  51968. (void)outLen;
  51969. (void)inLen;
  51970. (void)out;
  51971. (void)pub;
  51972. #ifdef OPENSSL_EXTRA
  51973. (void)privKey;
  51974. (void)pubKey;
  51975. (void)mdCtx;
  51976. (void)check;
  51977. (void)checkSz;
  51978. (void)p;
  51979. #endif
  51980. #endif
  51981. (void)keyFormat;
  51982. (void)encInfo;
  51983. exit_onlycb:
  51984. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51985. if (key != NULL) {
  51986. wc_ecc_free(key);
  51987. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51988. }
  51989. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51990. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51991. #ifdef OPENSSL_EXTRA
  51992. if (check) {
  51993. FREE(check, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51994. }
  51995. #endif
  51996. #else
  51997. wc_ecc_free(key);
  51998. #ifdef OPENSSL_EXTRA
  51999. if (privKey)
  52000. EVP_PKEY_free(privKey);
  52001. if (pubKey)
  52002. EVP_PKEY_free(pubKey);
  52003. #endif
  52004. #endif
  52005. #endif /* HAVE_ECC */
  52006. return ret;
  52007. }
  52008. #endif
  52009. /* Example crypto dev callback function that calls software version */
  52010. static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
  52011. {
  52012. int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); /* return this to bypass HW and
  52013. use SW */
  52014. myCryptoDevCtx* myCtx = (myCryptoDevCtx*)ctx;
  52015. if (info == NULL)
  52016. return BAD_FUNC_ARG;
  52017. #ifdef DEBUG_WOLFSSL
  52018. WOLFSSL_MSG_EX("CryptoDevCb: Algo Type %d\n", info->algo_type);
  52019. #endif
  52020. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  52021. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  52022. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  52023. /* if RNG only supports crypto callback, just use seed */
  52024. ret = wc_GenerateSeed(&info->rng.rng->seed,
  52025. info->rng.out, info->rng.sz);
  52026. #elif !defined(WC_NO_RNG)
  52027. /* set devId to invalid, so software is used */
  52028. info->rng.rng->devId = INVALID_DEVID;
  52029. ret = wc_RNG_GenerateBlock(info->rng.rng,
  52030. info->rng.out, info->rng.sz);
  52031. /* reset devId */
  52032. info->rng.rng->devId = devIdArg;
  52033. #endif
  52034. }
  52035. else if (info->algo_type == WC_ALGO_TYPE_SEED) {
  52036. #ifndef WC_NO_RNG
  52037. ALIGN32 static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 };
  52038. word32* seedWord32 = (word32*)seed;
  52039. word32 len;
  52040. /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */
  52041. while (info->seed.sz > 0) {
  52042. len = (word32)sizeof(seed);
  52043. if (info->seed.sz < len)
  52044. len = info->seed.sz;
  52045. XMEMCPY(info->seed.seed, seed, sizeof(seed));
  52046. info->seed.seed += len;
  52047. info->seed.sz -= len;
  52048. (*seedWord32)++;
  52049. }
  52050. ret = 0;
  52051. #endif
  52052. }
  52053. else if (info->algo_type == WC_ALGO_TYPE_PK) {
  52054. #ifdef DEBUG_WOLFSSL
  52055. WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type);
  52056. #endif
  52057. #ifndef NO_RSA
  52058. if (info->pk.type == WC_PK_TYPE_RSA) {
  52059. /* set devId to invalid, so software is used */
  52060. info->pk.rsa.key->devId = INVALID_DEVID;
  52061. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52062. #ifdef DEBUG_WOLFSSL
  52063. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52064. #endif
  52065. if (myCtx->exampleVar == 99) {
  52066. info->pk.rsa.key->devId = devIdArg;
  52067. return 0;
  52068. }
  52069. #endif
  52070. switch (info->pk.rsa.type) {
  52071. case RSA_PUBLIC_ENCRYPT:
  52072. case RSA_PUBLIC_DECRYPT:
  52073. /* perform software based RSA public op */
  52074. ret = wc_RsaFunction(
  52075. info->pk.rsa.in, info->pk.rsa.inLen,
  52076. info->pk.rsa.out, info->pk.rsa.outLen,
  52077. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52078. break;
  52079. case RSA_PRIVATE_ENCRYPT:
  52080. case RSA_PRIVATE_DECRYPT:
  52081. /* perform software based RSA private op */
  52082. ret = wc_RsaFunction(
  52083. info->pk.rsa.in, info->pk.rsa.inLen,
  52084. info->pk.rsa.out, info->pk.rsa.outLen,
  52085. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52086. break;
  52087. }
  52088. /* reset devId */
  52089. info->pk.rsa.key->devId = devIdArg;
  52090. }
  52091. #ifdef WOLFSSL_KEY_GEN
  52092. else if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
  52093. info->pk.rsakg.key->devId = INVALID_DEVID;
  52094. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52095. #ifdef DEBUG_WOLFSSL
  52096. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52097. #endif
  52098. if (myCtx->exampleVar == 99) {
  52099. info->pk.rsakg.key->devId = devIdArg;
  52100. return 0;
  52101. }
  52102. #endif
  52103. #ifdef HAVE_FIPS
  52104. for (;;) {
  52105. #endif
  52106. ret = wc_MakeRsaKey(info->pk.rsakg.key, info->pk.rsakg.size,
  52107. info->pk.rsakg.e, info->pk.rsakg.rng);
  52108. #ifdef HAVE_FIPS
  52109. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  52110. continue;
  52111. break;
  52112. }
  52113. #endif
  52114. /* reset devId */
  52115. info->pk.rsakg.key->devId = devIdArg;
  52116. }
  52117. #endif
  52118. #endif /* !NO_RSA */
  52119. #ifdef HAVE_ECC
  52120. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  52121. /* set devId to invalid, so software is used */
  52122. info->pk.eckg.key->devId = INVALID_DEVID;
  52123. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52124. #ifdef DEBUG_WOLFSSL
  52125. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52126. #endif
  52127. if (myCtx->exampleVar == 99) {
  52128. info->pk.eckg.key->devId = devIdArg;
  52129. return 0;
  52130. }
  52131. #endif
  52132. ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
  52133. info->pk.eckg.key, info->pk.eckg.curveId);
  52134. /* reset devId */
  52135. info->pk.eckg.key->devId = devIdArg;
  52136. }
  52137. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  52138. /* set devId to invalid, so software is used */
  52139. info->pk.eccsign.key->devId = INVALID_DEVID;
  52140. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52141. #ifdef DEBUG_WOLFSSL
  52142. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52143. #endif
  52144. if (myCtx->exampleVar == 99) {
  52145. info->pk.eccsign.key->devId = devIdArg;
  52146. return 0;
  52147. }
  52148. #endif
  52149. ret = wc_ecc_sign_hash(
  52150. info->pk.eccsign.in, info->pk.eccsign.inlen,
  52151. info->pk.eccsign.out, info->pk.eccsign.outlen,
  52152. info->pk.eccsign.rng, info->pk.eccsign.key);
  52153. /* reset devId */
  52154. info->pk.eccsign.key->devId = devIdArg;
  52155. }
  52156. else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
  52157. /* set devId to invalid, so software is used */
  52158. info->pk.eccverify.key->devId = INVALID_DEVID;
  52159. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52160. #ifdef DEBUG_WOLFSSL
  52161. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52162. #endif
  52163. if (myCtx->exampleVar == 99) {
  52164. info->pk.eccverify.key->devId = devIdArg;
  52165. return 0;
  52166. }
  52167. #endif
  52168. ret = wc_ecc_verify_hash(
  52169. info->pk.eccverify.sig, info->pk.eccverify.siglen,
  52170. info->pk.eccverify.hash, info->pk.eccverify.hashlen,
  52171. info->pk.eccverify.res, info->pk.eccverify.key);
  52172. /* reset devId */
  52173. info->pk.eccverify.key->devId = devIdArg;
  52174. }
  52175. else if (info->pk.type == WC_PK_TYPE_ECDH) {
  52176. /* set devId to invalid, so software is used */
  52177. info->pk.ecdh.private_key->devId = INVALID_DEVID;
  52178. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52179. #ifdef DEBUG_WOLFSSL
  52180. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52181. #endif
  52182. if (myCtx->exampleVar == 99) {
  52183. info->pk.ecdh.private_key->devId = devIdArg;
  52184. return 0;
  52185. }
  52186. #endif
  52187. ret = wc_ecc_shared_secret(
  52188. info->pk.ecdh.private_key, info->pk.ecdh.public_key,
  52189. info->pk.ecdh.out, info->pk.ecdh.outlen);
  52190. /* reset devId */
  52191. info->pk.ecdh.private_key->devId = devIdArg;
  52192. }
  52193. #endif /* HAVE_ECC */
  52194. #ifdef HAVE_CURVE25519
  52195. if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
  52196. /* set devId to invalid, so software is used */
  52197. info->pk.curve25519kg.key->devId = INVALID_DEVID;
  52198. ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
  52199. info->pk.curve25519kg.size, info->pk.curve25519kg.key);
  52200. /* reset devId */
  52201. info->pk.curve25519kg.key->devId = devIdArg;
  52202. }
  52203. else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
  52204. /* set devId to invalid, so software is used */
  52205. info->pk.curve25519.private_key->devId = INVALID_DEVID;
  52206. ret = wc_curve25519_shared_secret_ex(
  52207. info->pk.curve25519.private_key, info->pk.curve25519.public_key,
  52208. info->pk.curve25519.out, info->pk.curve25519.outlen,
  52209. info->pk.curve25519.endian);
  52210. /* reset devId */
  52211. info->pk.curve25519.private_key->devId = devIdArg;
  52212. }
  52213. #endif /* HAVE_CURVE25519 */
  52214. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  52215. if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
  52216. /* set devId to invalid, so software is used */
  52217. info->pk.ed25519kg.key->devId = INVALID_DEVID;
  52218. ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
  52219. info->pk.ed25519kg.size, info->pk.ed25519kg.key);
  52220. /* reset devId */
  52221. info->pk.ed25519kg.key->devId = devIdArg;
  52222. }
  52223. #ifdef HAVE_ED25519_SIGN
  52224. else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  52225. /* set devId to invalid, so software is used */
  52226. info->pk.ed25519sign.key->devId = INVALID_DEVID;
  52227. ret = wc_ed25519_sign_msg_ex(
  52228. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  52229. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  52230. info->pk.ed25519sign.key, info->pk.ed25519sign.type,
  52231. info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
  52232. /* reset devId */
  52233. info->pk.ed25519sign.key->devId = devIdArg;
  52234. }
  52235. #endif
  52236. #ifdef HAVE_ED25519_VERIFY
  52237. else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
  52238. /* set devId to invalid, so software is used */
  52239. info->pk.ed25519verify.key->devId = INVALID_DEVID;
  52240. ret = wc_ed25519_verify_msg_ex(
  52241. info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
  52242. info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
  52243. info->pk.ed25519verify.res, info->pk.ed25519verify.key,
  52244. info->pk.ed25519verify.type, info->pk.ed25519verify.context,
  52245. info->pk.ed25519verify.contextLen);
  52246. /* reset devId */
  52247. info->pk.ed25519verify.key->devId = devIdArg;
  52248. }
  52249. #endif
  52250. #endif /* HAVE_ED25519 */
  52251. }
  52252. else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
  52253. #if !defined(NO_AES) || !defined(NO_DES3)
  52254. #ifdef HAVE_AESGCM
  52255. if (info->cipher.type == WC_CIPHER_AES_GCM) {
  52256. if (info->cipher.enc) {
  52257. /* set devId to invalid, so software is used */
  52258. info->cipher.aesgcm_enc.aes->devId = INVALID_DEVID;
  52259. ret = wc_AesGcmEncrypt(
  52260. info->cipher.aesgcm_enc.aes,
  52261. info->cipher.aesgcm_enc.out,
  52262. info->cipher.aesgcm_enc.in,
  52263. info->cipher.aesgcm_enc.sz,
  52264. info->cipher.aesgcm_enc.iv,
  52265. info->cipher.aesgcm_enc.ivSz,
  52266. info->cipher.aesgcm_enc.authTag,
  52267. info->cipher.aesgcm_enc.authTagSz,
  52268. info->cipher.aesgcm_enc.authIn,
  52269. info->cipher.aesgcm_enc.authInSz);
  52270. /* reset devId */
  52271. info->cipher.aesgcm_enc.aes->devId = devIdArg;
  52272. }
  52273. else {
  52274. /* set devId to invalid, so software is used */
  52275. info->cipher.aesgcm_dec.aes->devId = INVALID_DEVID;
  52276. ret = wc_AesGcmDecrypt(
  52277. info->cipher.aesgcm_dec.aes,
  52278. info->cipher.aesgcm_dec.out,
  52279. info->cipher.aesgcm_dec.in,
  52280. info->cipher.aesgcm_dec.sz,
  52281. info->cipher.aesgcm_dec.iv,
  52282. info->cipher.aesgcm_dec.ivSz,
  52283. info->cipher.aesgcm_dec.authTag,
  52284. info->cipher.aesgcm_dec.authTagSz,
  52285. info->cipher.aesgcm_dec.authIn,
  52286. info->cipher.aesgcm_dec.authInSz);
  52287. /* reset devId */
  52288. info->cipher.aesgcm_dec.aes->devId = devIdArg;
  52289. }
  52290. }
  52291. #endif /* HAVE_AESGCM */
  52292. #ifdef HAVE_AES_CBC
  52293. if (info->cipher.type == WC_CIPHER_AES_CBC) {
  52294. if (info->cipher.enc) {
  52295. /* set devId to invalid, so software is used */
  52296. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  52297. ret = wc_AesCbcEncrypt(
  52298. info->cipher.aescbc.aes,
  52299. info->cipher.aescbc.out,
  52300. info->cipher.aescbc.in,
  52301. info->cipher.aescbc.sz);
  52302. /* reset devId */
  52303. info->cipher.aescbc.aes->devId = devIdArg;
  52304. }
  52305. else {
  52306. /* set devId to invalid, so software is used */
  52307. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  52308. ret = wc_AesCbcDecrypt(
  52309. info->cipher.aescbc.aes,
  52310. info->cipher.aescbc.out,
  52311. info->cipher.aescbc.in,
  52312. info->cipher.aescbc.sz);
  52313. /* reset devId */
  52314. info->cipher.aescbc.aes->devId = devIdArg;
  52315. }
  52316. }
  52317. #endif /* HAVE_AES_CBC */
  52318. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  52319. if (info->cipher.type == WC_CIPHER_AES_ECB) {
  52320. if (info->cipher.enc) {
  52321. /* set devId to invalid, so software is used */
  52322. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  52323. ret = wc_AesEcbEncrypt(
  52324. info->cipher.aesecb.aes,
  52325. info->cipher.aesecb.out,
  52326. info->cipher.aesecb.in,
  52327. info->cipher.aesecb.sz);
  52328. /* reset devId */
  52329. info->cipher.aesecb.aes->devId = devIdArg;
  52330. }
  52331. else {
  52332. /* set devId to invalid, so software is used */
  52333. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  52334. ret = wc_AesEcbDecrypt(
  52335. info->cipher.aesecb.aes,
  52336. info->cipher.aesecb.out,
  52337. info->cipher.aesecb.in,
  52338. info->cipher.aesecb.sz);
  52339. /* reset devId */
  52340. info->cipher.aesecb.aes->devId = devIdArg;
  52341. }
  52342. }
  52343. #endif /* HAVE_AES_ECB */
  52344. #if defined(WOLFSSL_AES_COUNTER) && !defined(HAVE_FIPS) && \
  52345. !defined(HAVE_SELFTEST)
  52346. if (info->cipher.type == WC_CIPHER_AES_CTR) {
  52347. /* set devId to invalid, so software is used */
  52348. info->cipher.aesctr.aes->devId = INVALID_DEVID;
  52349. ret = wc_AesCtrEncrypt(
  52350. info->cipher.aesctr.aes,
  52351. info->cipher.aesctr.out,
  52352. info->cipher.aesctr.in,
  52353. info->cipher.aesctr.sz);
  52354. /* reset devId */
  52355. info->cipher.aesctr.aes->devId = devIdArg;
  52356. }
  52357. #endif /* WOLFSSL_AES_COUNTER */
  52358. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  52359. if (info->cipher.type == WC_CIPHER_AES_CCM) {
  52360. if (info->cipher.enc) {
  52361. /* set devId to invalid, so software is used */
  52362. info->cipher.aesccm_enc.aes->devId = INVALID_DEVID;
  52363. ret = wc_AesCcmEncrypt(
  52364. info->cipher.aesccm_enc.aes,
  52365. info->cipher.aesccm_enc.out,
  52366. info->cipher.aesccm_enc.in,
  52367. info->cipher.aesccm_enc.sz,
  52368. info->cipher.aesccm_enc.nonce,
  52369. info->cipher.aesccm_enc.nonceSz,
  52370. info->cipher.aesccm_enc.authTag,
  52371. info->cipher.aesccm_enc.authTagSz,
  52372. info->cipher.aesccm_enc.authIn,
  52373. info->cipher.aesccm_enc.authInSz);
  52374. /* reset devId */
  52375. info->cipher.aesccm_enc.aes->devId = devIdArg;
  52376. }
  52377. else {
  52378. /* set devId to invalid, so software is used */
  52379. info->cipher.aesccm_dec.aes->devId = INVALID_DEVID;
  52380. ret = wc_AesCcmDecrypt(
  52381. info->cipher.aesccm_dec.aes,
  52382. info->cipher.aesccm_dec.out,
  52383. info->cipher.aesccm_dec.in,
  52384. info->cipher.aesccm_dec.sz,
  52385. info->cipher.aesccm_dec.nonce,
  52386. info->cipher.aesccm_dec.nonceSz,
  52387. info->cipher.aesccm_dec.authTag,
  52388. info->cipher.aesccm_dec.authTagSz,
  52389. info->cipher.aesccm_dec.authIn,
  52390. info->cipher.aesccm_dec.authInSz);
  52391. /* reset devId */
  52392. info->cipher.aesccm_dec.aes->devId = devIdArg;
  52393. }
  52394. }
  52395. #endif
  52396. #ifndef NO_DES3
  52397. if (info->cipher.type == WC_CIPHER_DES3) {
  52398. if (info->cipher.enc) {
  52399. /* set devId to invalid, so software is used */
  52400. info->cipher.des3.des->devId = INVALID_DEVID;
  52401. ret = wc_Des3_CbcEncrypt(
  52402. info->cipher.des3.des,
  52403. info->cipher.des3.out,
  52404. info->cipher.des3.in,
  52405. info->cipher.des3.sz);
  52406. /* reset devId */
  52407. info->cipher.des3.des->devId = devIdArg;
  52408. }
  52409. else {
  52410. /* set devId to invalid, so software is used */
  52411. info->cipher.des3.des->devId = INVALID_DEVID;
  52412. ret = wc_Des3_CbcDecrypt(
  52413. info->cipher.des3.des,
  52414. info->cipher.des3.out,
  52415. info->cipher.des3.in,
  52416. info->cipher.des3.sz);
  52417. /* reset devId */
  52418. info->cipher.des3.des->devId = devIdArg;
  52419. }
  52420. }
  52421. #endif /* !NO_DES3 */
  52422. #endif /* !NO_AES || !NO_DES3 */
  52423. }
  52424. #if !defined(NO_SHA) || !defined(NO_SHA256) || \
  52425. defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
  52426. else if (info->algo_type == WC_ALGO_TYPE_HASH) {
  52427. #if !defined(NO_SHA)
  52428. if (info->hash.type == WC_HASH_TYPE_SHA) {
  52429. if (info->hash.sha1 == NULL)
  52430. return NOT_COMPILED_IN;
  52431. /* set devId to invalid, so software is used */
  52432. info->hash.sha1->devId = INVALID_DEVID;
  52433. if (info->hash.in != NULL) {
  52434. ret = wc_ShaUpdate(
  52435. info->hash.sha1,
  52436. info->hash.in,
  52437. info->hash.inSz);
  52438. }
  52439. if (info->hash.digest != NULL) {
  52440. ret = wc_ShaFinal(
  52441. info->hash.sha1,
  52442. info->hash.digest);
  52443. }
  52444. /* reset devId */
  52445. info->hash.sha1->devId = devIdArg;
  52446. }
  52447. else
  52448. #endif
  52449. #if !defined(NO_SHA256)
  52450. if (info->hash.type == WC_HASH_TYPE_SHA256) {
  52451. if (info->hash.sha256 == NULL)
  52452. return NOT_COMPILED_IN;
  52453. /* set devId to invalid, so software is used */
  52454. info->hash.sha256->devId = INVALID_DEVID;
  52455. if (info->hash.in != NULL) {
  52456. ret = wc_Sha256Update(
  52457. info->hash.sha256,
  52458. info->hash.in,
  52459. info->hash.inSz);
  52460. }
  52461. if (info->hash.digest != NULL) {
  52462. ret = wc_Sha256Final(
  52463. info->hash.sha256,
  52464. info->hash.digest);
  52465. }
  52466. /* reset devId */
  52467. info->hash.sha256->devId = devIdArg;
  52468. }
  52469. else
  52470. #endif
  52471. #ifdef WOLFSSL_SHA384
  52472. if (info->hash.type == WC_HASH_TYPE_SHA384) {
  52473. if (info->hash.sha384 == NULL)
  52474. return NOT_COMPILED_IN;
  52475. #ifndef NO_SHA2_CRYPTO_CB
  52476. /* set devId to invalid, so software is used */
  52477. info->hash.sha384->devId = INVALID_DEVID;
  52478. #endif
  52479. if (info->hash.in != NULL) {
  52480. ret = wc_Sha384Update(
  52481. info->hash.sha384,
  52482. info->hash.in,
  52483. info->hash.inSz);
  52484. }
  52485. if (info->hash.digest != NULL) {
  52486. ret = wc_Sha384Final(
  52487. info->hash.sha384,
  52488. info->hash.digest);
  52489. }
  52490. #ifndef NO_SHA2_CRYPTO_CB
  52491. /* reset devId */
  52492. info->hash.sha384->devId = devIdArg;
  52493. #endif
  52494. }
  52495. else
  52496. #endif
  52497. #ifdef WOLFSSL_SHA512
  52498. if (info->hash.type == WC_HASH_TYPE_SHA512) {
  52499. if (info->hash.sha512 == NULL)
  52500. return NOT_COMPILED_IN;
  52501. #ifndef NO_SHA2_CRYPTO_CB
  52502. /* set devId to invalid, so software is used */
  52503. info->hash.sha512->devId = INVALID_DEVID;
  52504. #endif
  52505. if (info->hash.in != NULL) {
  52506. ret = wc_Sha512Update(
  52507. info->hash.sha512,
  52508. info->hash.in,
  52509. info->hash.inSz);
  52510. }
  52511. if (info->hash.digest != NULL) {
  52512. ret = wc_Sha512Final(
  52513. info->hash.sha512,
  52514. info->hash.digest);
  52515. }
  52516. #ifndef NO_SHA2_CRYPTO_CB
  52517. /* reset devId */
  52518. info->hash.sha512->devId = devIdArg;
  52519. #endif
  52520. }
  52521. else
  52522. #endif
  52523. #if defined(WOLFSSL_SHA3) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0))
  52524. if (info->hash.type == WC_HASH_TYPE_SHA3_224) {
  52525. if (info->hash.sha3 == NULL)
  52526. return NOT_COMPILED_IN;
  52527. /* set devId to invalid, so software is used */
  52528. info->hash.sha3->devId = INVALID_DEVID;
  52529. if (info->hash.in != NULL) {
  52530. ret = wc_Sha3_224_Update(
  52531. info->hash.sha3,
  52532. info->hash.in,
  52533. info->hash.inSz);
  52534. }
  52535. if (info->hash.digest != NULL) {
  52536. ret = wc_Sha3_224_Final(
  52537. info->hash.sha3,
  52538. info->hash.digest);
  52539. }
  52540. /* reset devId */
  52541. info->hash.sha3->devId = devIdArg;
  52542. }
  52543. else if (info->hash.type == WC_HASH_TYPE_SHA3_256) {
  52544. if (info->hash.sha3 == NULL)
  52545. return NOT_COMPILED_IN;
  52546. /* set devId to invalid, so software is used */
  52547. info->hash.sha3->devId = INVALID_DEVID;
  52548. if (info->hash.in != NULL) {
  52549. ret = wc_Sha3_256_Update(
  52550. info->hash.sha3,
  52551. info->hash.in,
  52552. info->hash.inSz);
  52553. }
  52554. if (info->hash.digest != NULL) {
  52555. ret = wc_Sha3_256_Final(
  52556. info->hash.sha3,
  52557. info->hash.digest);
  52558. }
  52559. /* reset devId */
  52560. info->hash.sha3->devId = devIdArg;
  52561. }
  52562. else if (info->hash.type == WC_HASH_TYPE_SHA3_384) {
  52563. if (info->hash.sha3 == NULL)
  52564. return NOT_COMPILED_IN;
  52565. /* set devId to invalid, so software is used */
  52566. info->hash.sha3->devId = INVALID_DEVID;
  52567. if (info->hash.in != NULL) {
  52568. ret = wc_Sha3_384_Update(
  52569. info->hash.sha3,
  52570. info->hash.in,
  52571. info->hash.inSz);
  52572. }
  52573. if (info->hash.digest != NULL) {
  52574. ret = wc_Sha3_384_Final(
  52575. info->hash.sha3,
  52576. info->hash.digest);
  52577. }
  52578. /* reset devId */
  52579. info->hash.sha3->devId = devIdArg;
  52580. }
  52581. else if (info->hash.type == WC_HASH_TYPE_SHA3_512) {
  52582. if (info->hash.sha3 == NULL)
  52583. return NOT_COMPILED_IN;
  52584. /* set devId to invalid, so software is used */
  52585. info->hash.sha3->devId = INVALID_DEVID;
  52586. if (info->hash.in != NULL) {
  52587. ret = wc_Sha3_512_Update(
  52588. info->hash.sha3,
  52589. info->hash.in,
  52590. info->hash.inSz);
  52591. }
  52592. if (info->hash.digest != NULL) {
  52593. ret = wc_Sha3_512_Final(
  52594. info->hash.sha3,
  52595. info->hash.digest);
  52596. }
  52597. /* reset devId */
  52598. info->hash.sha3->devId = devIdArg;
  52599. }
  52600. else
  52601. #endif
  52602. {
  52603. }
  52604. }
  52605. #endif /* !NO_SHA || !NO_SHA256 */
  52606. #ifndef NO_HMAC
  52607. else if (info->algo_type == WC_ALGO_TYPE_HMAC) {
  52608. if (info->hmac.hmac == NULL)
  52609. return NOT_COMPILED_IN;
  52610. /* set devId to invalid, so software is used */
  52611. info->hmac.hmac->devId = INVALID_DEVID;
  52612. if (info->hmac.in != NULL) {
  52613. ret = wc_HmacUpdate(
  52614. info->hmac.hmac,
  52615. info->hmac.in,
  52616. info->hmac.inSz);
  52617. }
  52618. else if (info->hmac.digest != NULL) {
  52619. ret = wc_HmacFinal(
  52620. info->hmac.hmac,
  52621. info->hmac.digest);
  52622. }
  52623. /* reset devId */
  52624. info->hmac.hmac->devId = devIdArg;
  52625. }
  52626. #endif
  52627. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  52628. else if (info->algo_type == WC_ALGO_TYPE_CMAC) {
  52629. if (info->cmac.cmac == NULL) {
  52630. return NOT_COMPILED_IN;
  52631. }
  52632. /* set devId to invalid so software is used */
  52633. info->cmac.cmac->devId = INVALID_DEVID;
  52634. /* Handle one-shot cases */
  52635. if (info->cmac.key != NULL && info->cmac.in != NULL
  52636. && info->cmac.out != NULL) {
  52637. ret = wc_AesCmacGenerate(info->cmac.out,
  52638. info->cmac.outSz,
  52639. info->cmac.in,
  52640. info->cmac.inSz,
  52641. info->cmac.key,
  52642. info->cmac.keySz);
  52643. /* Sequentially handle incremental cases */
  52644. } else {
  52645. if (info->cmac.key != NULL) {
  52646. ret = wc_InitCmac(info->cmac.cmac,
  52647. info->cmac.key,
  52648. info->cmac.keySz,
  52649. info->cmac.type,
  52650. NULL);
  52651. }
  52652. if ((ret == 0) && (info->cmac.in != NULL)) {
  52653. ret = wc_CmacUpdate(info->cmac.cmac,
  52654. info->cmac.in,
  52655. info->cmac.inSz);
  52656. }
  52657. if ((ret ==0) && (info->cmac.out != NULL)) {
  52658. ret = wc_CmacFinal(info->cmac.cmac,
  52659. info->cmac.out,
  52660. info->cmac.outSz);
  52661. }
  52662. }
  52663. /* reset devId */
  52664. info->cmac.cmac->devId = devIdArg;
  52665. }
  52666. #endif /* WOLFSSL_CMAC && !(NO_AES) && WOLFSSL_AES_DIRECT */
  52667. (void)devIdArg;
  52668. (void)myCtx;
  52669. return ret;
  52670. }
  52671. #ifdef WOLF_CRYPTO_CB_FIND
  52672. static int myCryptoCbFind(int currentId, int algoType)
  52673. {
  52674. /* can have algo specific overrides here
  52675. switch (algoType) {
  52676. i.e.
  52677. WC_ALGO_TYPE_CMAC
  52678. WC_ALGO_TYPE_SEED
  52679. WC_ALGO_TYPE_HMAC
  52680. WC_ALGO_TYPE_HASH
  52681. WC_ALGO_TYPE_CIPHER
  52682. WC_ALGO_TYPE_PK
  52683. }
  52684. */
  52685. (void)algoType;
  52686. if (currentId == INVALID_DEVID) {
  52687. /* can override invalid devid found with 1 */
  52688. }
  52689. return currentId;
  52690. }
  52691. #endif /* WOLF_CRYPTO_CB_FIND */
  52692. #if !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  52693. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
  52694. {
  52695. wc_test_ret_t ret = 0;
  52696. int origDevId = devId;
  52697. myCryptoDevCtx myCtx;
  52698. WOLFSSL_ENTER("cryptocb_test");
  52699. /* example data for callback */
  52700. myCtx.exampleVar = 1;
  52701. /* set devId to something other than INVALID_DEVID */
  52702. devId = 1;
  52703. ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
  52704. #ifdef WOLF_CRYPTO_CB_FIND
  52705. wc_CryptoCb_SetDeviceFindCb(myCryptoCbFind);
  52706. #endif /* WOLF_CRYPTO_CB_FIND */
  52707. #ifndef WC_NO_RNG
  52708. if (ret == 0)
  52709. ret = random_test();
  52710. #endif /* WC_NO_RNG */
  52711. #if !defined(NO_RSA)
  52712. PRIVATE_KEY_UNLOCK();
  52713. if (ret == 0)
  52714. ret = rsa_test();
  52715. PRIVATE_KEY_LOCK();
  52716. #endif
  52717. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52718. PRIVATE_KEY_UNLOCK();
  52719. if (ret == 0)
  52720. ret = rsa_onlycb_test(&myCtx);
  52721. PRIVATE_KEY_LOCK();
  52722. #endif
  52723. #if defined(HAVE_ECC)
  52724. PRIVATE_KEY_UNLOCK();
  52725. if (ret == 0)
  52726. ret = ecc_test();
  52727. PRIVATE_KEY_LOCK();
  52728. #endif
  52729. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52730. PRIVATE_KEY_UNLOCK();
  52731. if (ret == 0)
  52732. ret = ecc_onlycb_test(&myCtx);
  52733. PRIVATE_KEY_LOCK();
  52734. #endif
  52735. #ifdef HAVE_ED25519
  52736. PRIVATE_KEY_UNLOCK();
  52737. if (ret == 0)
  52738. ret = ed25519_test();
  52739. PRIVATE_KEY_LOCK();
  52740. #endif
  52741. #ifdef HAVE_CURVE25519
  52742. if (ret == 0)
  52743. ret = curve25519_test();
  52744. #endif
  52745. #ifndef NO_AES
  52746. #ifdef HAVE_AESGCM
  52747. if (ret == 0)
  52748. ret = aesgcm_test();
  52749. #endif
  52750. #ifdef HAVE_AES_CBC
  52751. if (ret == 0)
  52752. ret = aes_test();
  52753. #endif
  52754. #ifdef WOLFSSL_AES_XTS
  52755. if (ret == 0)
  52756. ret = aes_xts_test();
  52757. #endif
  52758. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  52759. if (ret == 0)
  52760. ret = aesccm_test();
  52761. #endif
  52762. #endif /* !NO_AES */
  52763. #ifndef NO_DES3
  52764. if (ret == 0)
  52765. ret = des3_test();
  52766. #endif /* !NO_DES3 */
  52767. #ifndef NO_SHA
  52768. if (ret == 0)
  52769. ret = sha_test();
  52770. #endif
  52771. #ifndef NO_SHA256
  52772. if (ret == 0)
  52773. ret = sha256_test();
  52774. #endif
  52775. #ifdef WOLFSSL_SHA384
  52776. if (ret == 0)
  52777. ret = sha384_test();
  52778. #endif
  52779. #ifdef WOLFSSL_SHA512
  52780. if (ret == 0)
  52781. ret = sha512_test();
  52782. #ifdef WOLFSSL_SHA3
  52783. if (ret == 0)
  52784. ret = sha3_test();
  52785. #endif
  52786. #endif
  52787. #ifndef NO_HMAC
  52788. #ifndef NO_SHA
  52789. if (ret == 0)
  52790. ret = hmac_sha_test();
  52791. #endif
  52792. #ifndef NO_SHA256
  52793. if (ret == 0)
  52794. ret = hmac_sha256_test();
  52795. #endif
  52796. #ifdef WOLFSSL_SHA3
  52797. if (ret == 0)
  52798. ret = hmac_sha3_test();
  52799. #endif
  52800. #endif
  52801. #ifndef NO_PWDBASED
  52802. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  52803. PRIVATE_KEY_UNLOCK();
  52804. if (ret == 0)
  52805. ret = pbkdf2_test();
  52806. PRIVATE_KEY_LOCK();
  52807. #endif
  52808. #endif
  52809. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  52810. if (ret == 0)
  52811. ret = cmac_test();
  52812. #endif
  52813. /* restore devId */
  52814. devId = origDevId;
  52815. return ret;
  52816. }
  52817. #endif /* ! WC_TEST_NO_CRYPTOCB_SW_TEST */
  52818. #endif /* WOLF_CRYPTO_CB */
  52819. #ifdef WOLFSSL_CERT_PIV
  52820. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void)
  52821. {
  52822. wc_test_ret_t ret;
  52823. wc_CertPIV piv;
  52824. /* Template for Identiv PIV cert, nonce and signature */
  52825. WOLFSSL_SMALL_STACK_STATIC const byte pivCertIdentiv[] = {
  52826. 0x0A, 0x0B,
  52827. 0x53, 0x09, /* NIST PIV Cert */
  52828. 0x70, 0x02, /* Certificate */
  52829. 0x30, 0x00,
  52830. 0x71, 0x01, 0x05, /* Cert Info */
  52831. 0xFE, 0x00, /* Error Detection */
  52832. 0x0B, 0x01, 0x00, /* Nonce */
  52833. 0x0C, 0x01, 0x00, /* Signed Nonce */
  52834. };
  52835. /* PIV certificate data including certificate, info and error detection. */
  52836. WOLFSSL_SMALL_STACK_STATIC const byte pivCert[] = {
  52837. 0x53, 0x09, /* NIST PIV Cert */
  52838. 0x70, 0x02, /* Certificate */
  52839. 0x30, 0x00,
  52840. 0x71, 0x01, 0x04, /* Cert Info */
  52841. 0xFE, 0x00, /* Error Detection */
  52842. };
  52843. WOLFSSL_ENTER("certpiv_test");
  52844. XMEMSET(&piv, 0, sizeof(piv));
  52845. /* Test with Identiv 0x0A, 0x0B and 0x0C markers */
  52846. ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv));
  52847. if (ret != 0) {
  52848. return WC_TEST_RET_ENC_EC(ret);
  52849. }
  52850. if (!piv.isIdentiv) {
  52851. return WC_TEST_RET_ENC_NC;
  52852. }
  52853. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  52854. return WC_TEST_RET_ENC_NC;
  52855. }
  52856. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  52857. return WC_TEST_RET_ENC_NC;
  52858. }
  52859. if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) {
  52860. return WC_TEST_RET_ENC_NC;
  52861. }
  52862. if (!piv.isX509) {
  52863. return WC_TEST_RET_ENC_NC;
  52864. }
  52865. if ((piv.nonce == NULL) || (piv.nonceSz != 1)) {
  52866. return WC_TEST_RET_ENC_NC;
  52867. }
  52868. if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) {
  52869. return WC_TEST_RET_ENC_NC;
  52870. }
  52871. XMEMSET(&piv, 0, sizeof(piv));
  52872. /* Test with NIST PIV format */
  52873. ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
  52874. if (ret != 0) {
  52875. return WC_TEST_RET_ENC_EC(ret);
  52876. }
  52877. if (piv.isIdentiv) {
  52878. return WC_TEST_RET_ENC_NC;
  52879. }
  52880. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  52881. return WC_TEST_RET_ENC_NC;
  52882. }
  52883. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  52884. return WC_TEST_RET_ENC_NC;
  52885. }
  52886. if ((piv.compression != 0)) {
  52887. return WC_TEST_RET_ENC_NC;
  52888. }
  52889. if (!piv.isX509) {
  52890. return WC_TEST_RET_ENC_NC;
  52891. }
  52892. return ret;
  52893. }
  52894. #endif /* WOLFSSL_CERT_PIV */
  52895. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  52896. static time_t time_cb(time_t* t)
  52897. {
  52898. if (t != NULL) {
  52899. *t = 99;
  52900. }
  52901. return 99;
  52902. }
  52903. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void)
  52904. {
  52905. time_t t;
  52906. wc_test_ret_t ret;
  52907. WOLFSSL_ENTER("time_test");
  52908. ret = wc_SetTimeCb(time_cb);
  52909. if (ret != 0)
  52910. return WC_TEST_RET_ENC_EC(ret);
  52911. t = wc_Time(NULL);
  52912. if (t != 99)
  52913. return WC_TEST_RET_ENC_NC;
  52914. ret = wc_GetTime(&t, sizeof(time_t));
  52915. if (ret != 0)
  52916. return WC_TEST_RET_ENC_EC(ret);
  52917. if (t != 99)
  52918. return WC_TEST_RET_ENC_NC;
  52919. ret = wc_SetTimeCb(NULL);
  52920. if (ret != 0)
  52921. return WC_TEST_RET_ENC_EC(ret);
  52922. return 0;
  52923. }
  52924. #endif
  52925. #ifdef WOLFSSL_AES_SIV
  52926. typedef struct {
  52927. const byte key[33];
  52928. word32 keySz;
  52929. const byte nonce[49];
  52930. word32 nonceSz;
  52931. byte numAssoc;
  52932. const byte assoc1[81];
  52933. word32 assoc1Sz;
  52934. const byte assoc2[11];
  52935. word32 assoc2Sz;
  52936. const byte plaintext[83];
  52937. word32 plaintextSz;
  52938. const byte siv[AES_BLOCK_SIZE+1];
  52939. const byte ciphertext[82];
  52940. word32 ciphertextSz;
  52941. } AesSivTestVector;
  52942. #define AES_SIV_TEST_VECTORS 9
  52943. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
  52944. {
  52945. WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
  52946. /* These test vectors come from chrony 4.1's SIV unit tests. */
  52947. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  52948. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  52949. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  52950. 1,
  52951. "", 0,
  52952. "", 0,
  52953. "", 0,
  52954. "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
  52955. "", 0
  52956. },
  52957. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  52958. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  52959. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  52960. 1,
  52961. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  52962. "", 0,
  52963. "", 0,
  52964. "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
  52965. "", 0
  52966. },
  52967. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  52968. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  52969. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  52970. 1,
  52971. "", 0,
  52972. "", 0,
  52973. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  52974. "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
  52975. "\x14\xff\xb3\x97\x34\x5c\xcb\xe4\x4a\xa4\xde\xac\xd9\x36\x90\x46", 16
  52976. },
  52977. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  52978. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  52979. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
  52980. 1,
  52981. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
  52982. "", 0,
  52983. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
  52984. "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
  52985. "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
  52986. },
  52987. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  52988. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  52989. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  52990. 1,
  52991. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  52992. "", 0,
  52993. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
  52994. "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
  52995. "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
  52996. },
  52997. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  52998. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  52999. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53000. "\xd5", 17,
  53001. 1,
  53002. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
  53003. "\xa0", 17,
  53004. "", 0,
  53005. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
  53006. "\x08", 17,
  53007. "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
  53008. "\xa5\x11\xcd\xb6\x08\xf3\x76\xa0\xb6\xfa\x15\x82\xf3\x95\xe1\xeb"
  53009. "\xbd", 17
  53010. },
  53011. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53012. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53013. "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
  53014. "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
  53015. "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
  53016. 1,
  53017. "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
  53018. "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
  53019. "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
  53020. "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
  53021. "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
  53022. "", 0,
  53023. "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
  53024. "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
  53025. "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
  53026. "\xae\x81\xa1\xca\x5b\x5f\x45\xa6\x6f\x0c\x8a\xf3\xd4\x67\x40\x81"
  53027. "\x26\xe2\x01\x86\xe8\x5a\xd5\xf8\x58\x80\x9f\x56\xaa\x76\x96\xbf"
  53028. "\x31", 81,
  53029. "\x9a\x06\x33\xe0\xee\x00\x6a\x9b\xc8\x20\xd5\xe2\xc2\xed\xb5\x75",
  53030. "\xfa\x9e\x42\x2a\x31\x6b\xda\xca\xaa\x7d\x31\x8b\x84\x7a\xb8\xd7"
  53031. "\x8a\x81\x25\x64\xed\x41\x9b\xa9\x77\x10\xbd\x05\x0c\x4e\xc5\x31"
  53032. "\x0c\xa2\x86\xec\x8a\x94\xc8\x24\x23\x3c\x13\xee\xa5\x51\xc9\xdf"
  53033. "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
  53034. "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
  53035. "\xa1", 81
  53036. },
  53037. /* Example A.1 from RFC5297 */
  53038. {
  53039. "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
  53040. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
  53041. "", 0,
  53042. 1,
  53043. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53044. "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
  53045. "", 0,
  53046. "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
  53047. "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
  53048. "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
  53049. },
  53050. /* Example A.2 from RFC5297 */
  53051. {
  53052. "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
  53053. "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
  53054. "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
  53055. 2,
  53056. "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
  53057. "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
  53058. "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
  53059. "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
  53060. "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
  53061. "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
  53062. "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
  53063. "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
  53064. "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
  53065. "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
  53066. "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
  53067. }
  53068. };
  53069. int i;
  53070. byte computedCiphertext[82];
  53071. byte computedPlaintext[82];
  53072. byte siv[AES_BLOCK_SIZE];
  53073. wc_test_ret_t ret = 0;
  53074. WOLFSSL_ENTER("aes_siv_test");
  53075. /* First test legacy "exactly one Assoc" interface. */
  53076. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53077. if (testVectors[i].numAssoc != 1)
  53078. continue;
  53079. ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
  53080. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53081. testVectors[i].nonce, testVectors[i].nonceSz,
  53082. testVectors[i].plaintext,
  53083. testVectors[i].plaintextSz, siv,
  53084. computedCiphertext);
  53085. if (ret != 0) {
  53086. return WC_TEST_RET_ENC_EC(ret);
  53087. }
  53088. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53089. if (ret != 0) {
  53090. return WC_TEST_RET_ENC_NC;
  53091. }
  53092. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53093. testVectors[i].ciphertextSz);
  53094. if (ret != 0) {
  53095. return WC_TEST_RET_ENC_NC;
  53096. }
  53097. ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
  53098. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53099. testVectors[i].nonce, testVectors[i].nonceSz,
  53100. computedCiphertext, testVectors[i].plaintextSz,
  53101. siv, computedPlaintext);
  53102. if (ret != 0) {
  53103. return WC_TEST_RET_ENC_EC(ret);
  53104. }
  53105. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53106. testVectors[i].plaintextSz);
  53107. if (ret != 0) {
  53108. return WC_TEST_RET_ENC_NC;
  53109. }
  53110. }
  53111. /* Then test "multiple Assoc" interface. */
  53112. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53113. const struct AesSivAssoc assoc[2] = {
  53114. { testVectors[i].assoc1, testVectors[i].assoc1Sz },
  53115. { testVectors[i].assoc2, testVectors[i].assoc2Sz }
  53116. };
  53117. ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53118. assoc, testVectors[i].numAssoc,
  53119. testVectors[i].nonce, testVectors[i].nonceSz,
  53120. testVectors[i].plaintext,
  53121. testVectors[i].plaintextSz, siv,
  53122. computedCiphertext);
  53123. if (ret != 0) {
  53124. return WC_TEST_RET_ENC_EC(ret);
  53125. }
  53126. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53127. if (ret != 0) {
  53128. return WC_TEST_RET_ENC_NC;
  53129. }
  53130. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53131. testVectors[i].ciphertextSz);
  53132. if (ret != 0) {
  53133. return WC_TEST_RET_ENC_NC;
  53134. }
  53135. ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53136. assoc, testVectors[i].numAssoc,
  53137. testVectors[i].nonce, testVectors[i].nonceSz,
  53138. computedCiphertext,
  53139. testVectors[i].plaintextSz, siv,
  53140. computedPlaintext);
  53141. if (ret != 0) {
  53142. return WC_TEST_RET_ENC_EC(ret);
  53143. }
  53144. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53145. testVectors[i].plaintextSz);
  53146. if (ret != 0) {
  53147. return WC_TEST_RET_ENC_NC;
  53148. }
  53149. }
  53150. return 0;
  53151. }
  53152. #endif
  53153. #undef ERROR_OUT
  53154. static const int fiducial4 = WC_TEST_RET_LN;
  53155. /* print the fiducial line numbers assigned above, allowing confirmation of
  53156. * source code version match when in doubt.
  53157. */
  53158. static void print_fiducials(void) {
  53159. printf(" [fiducial line numbers: %d %d %d %d]\n",
  53160. fiducial1, fiducial2, fiducial3, fiducial4);
  53161. }
  53162. #else
  53163. #ifndef NO_MAIN_DRIVER
  53164. int main(void) { return 0; }
  53165. #endif
  53166. #endif /* NO_CRYPT_TEST */