test.c 2.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869
  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. #ifdef WOLFSSL_NDS
  407. #include <nds/ndstypes.h>
  408. #include <nds/arm9/console.h>
  409. #include <nds/arm9/input.h>
  410. #include <nds/interrupts.h>
  411. #include <fat.h>
  412. #endif
  413. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  414. /* FIPS build has replaced ecc.h. */
  415. #define wc_ecc_key_get_priv(key) (&((key)->k))
  416. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  417. #endif
  418. #ifdef WOLFSSL_STATIC_MEMORY
  419. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  420. #else
  421. #define HEAP_HINT NULL
  422. #endif /* WOLFSSL_STATIC_MEMORY */
  423. /* these cases do not have intermediate hashing support */
  424. #if (defined(WOLFSSL_AFALG_XILINX_SHA3) && !defined(WOLFSSL_AFALG_HASH_KEEP)) \
  425. && !defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  426. #define NO_INTM_HASH_TEST
  427. #endif
  428. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  429. defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY) || \
  430. defined(WOLFSSL_SECO_CAAM)
  431. #define HASH_SIZE_LIMIT
  432. #endif
  433. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  434. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  435. static void initDefaultName(void);
  436. #endif
  437. /* for async devices */
  438. #ifdef WOLFSSL_CAAM_DEVID
  439. static int devId = WOLFSSL_CAAM_DEVID;
  440. #else
  441. #ifdef WC_USE_DEVID
  442. static int devId = WC_USE_DEVID;
  443. #else
  444. static int devId = INVALID_DEVID;
  445. #endif
  446. #endif
  447. #ifdef HAVE_WNR
  448. const char* wnrConfigFile = "wnr-example.conf";
  449. #endif
  450. #define TEST_STRING "Everyone gets Friday off."
  451. #define TEST_STRING_SZ 25
  452. typedef struct testVector {
  453. const char* input;
  454. const char* output;
  455. size_t inLen;
  456. size_t outLen;
  457. } testVector;
  458. #ifdef WOLFCRYPT_TEST_LINT
  459. #define WOLFSSL_TEST_SUBROUTINE static
  460. #else
  461. PRAGMA_GCC("GCC diagnostic ignored \"-Wunused-function\"")
  462. PRAGMA_CLANG("clang diagnostic ignored \"-Wunused-function\"")
  463. #endif
  464. #ifndef WOLFSSL_TEST_SUBROUTINE
  465. #define WOLFSSL_TEST_SUBROUTINE
  466. #endif
  467. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void);
  468. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void);
  469. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void);
  470. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void);
  471. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void);
  472. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void);
  473. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void);
  474. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void);
  475. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void);
  476. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void);
  477. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void);
  478. #if !defined(WOLFSSL_NOSHA512_224) && \
  479. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  480. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void);
  481. #endif
  482. #if !defined(WOLFSSL_NOSHA512_256) && \
  483. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  484. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void);
  485. #endif
  486. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void);
  487. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void);
  488. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void);
  489. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void);
  490. #ifdef WOLFSSL_SM3
  491. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void);
  492. #endif
  493. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void);
  494. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void);
  495. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void);
  496. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void);
  497. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void);
  498. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void);
  499. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void);
  500. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void);
  501. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  502. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  503. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  504. defined(WOLFSSL_AFALG_XILINX_RSA)
  505. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  506. static wc_test_ret_t hkdf_test(void);
  507. #else
  508. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void);
  509. #endif
  510. #endif /* HAVE_HKDF && ! NO_HMAC */
  511. #ifdef WOLFSSL_HAVE_PRF
  512. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  513. #ifdef WOLFSSL_BASE16
  514. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void);
  515. #endif /* WOLFSSL_BASE16 */
  516. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  517. #endif /* WOLFSSL_HAVE_PRF */
  518. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  519. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void);
  520. #endif
  521. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void);
  522. #ifdef WOLFSSL_TLS13
  523. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void);
  524. #endif
  525. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void);
  526. #if defined(HAVE_HPKE) && defined(HAVE_ECC) && defined(HAVE_AESGCM)
  527. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void);
  528. #endif
  529. #ifdef WC_SRTP_KDF
  530. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void);
  531. #endif
  532. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void);
  533. #ifdef WC_RC2
  534. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void);
  535. #endif
  536. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void);
  537. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void);
  538. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void);
  539. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void);
  540. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void);
  541. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void);
  542. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void);
  543. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void);
  544. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void);
  545. #if defined(WOLFSSL_AES_CFB)
  546. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void);
  547. #endif
  548. #ifdef WOLFSSL_AES_XTS
  549. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void);
  550. #endif
  551. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void);
  552. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void);
  553. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void);
  554. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void);
  555. #if defined(WOLFSSL_SIPHASH)
  556. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void);
  557. #endif
  558. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void);
  559. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void);
  560. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void);
  561. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void);
  562. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void);
  563. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void);
  564. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void);
  565. #ifdef WOLFSSL_SM4
  566. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void);
  567. #endif
  568. #ifdef WC_RSA_NO_PADDING
  569. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void);
  570. #endif
  571. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void);
  572. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void);
  573. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void);
  574. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void);
  575. #ifndef WC_NO_RNG
  576. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void);
  577. #endif /* WC_NO_RNG */
  578. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void);
  579. #if defined(USE_CERT_BUFFERS_2048) && \
  580. defined(HAVE_PKCS12) && \
  581. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  582. !defined(NO_CERTS) && !defined(NO_DES3)
  583. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void);
  584. #endif
  585. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void);
  586. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  587. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void); /* test mini api */
  588. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void);
  589. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void);
  590. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void);
  591. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void);
  592. #endif
  593. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void);
  594. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void);
  595. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  596. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void);
  597. #endif
  598. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
  599. #ifdef HAVE_ECC
  600. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void);
  601. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  602. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  603. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void);
  604. #endif
  605. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  606. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  607. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  608. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  609. /* skip for ATECC508/608A, cannot import private key buffers */
  610. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void);
  611. #endif
  612. #endif
  613. #ifdef HAVE_CURVE25519
  614. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void);
  615. #endif
  616. #ifdef HAVE_ED25519
  617. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void);
  618. #endif
  619. #ifdef HAVE_CURVE448
  620. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void);
  621. #endif
  622. #ifdef HAVE_ED448
  623. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void);
  624. #endif
  625. #ifdef WOLFSSL_HAVE_KYBER
  626. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void);
  627. #endif
  628. #ifdef HAVE_DILITHIUM
  629. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void);
  630. #endif
  631. #if defined(WOLFSSL_HAVE_XMSS)
  632. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  633. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void);
  634. #endif
  635. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  636. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void);
  637. #endif
  638. #endif
  639. #if defined(WOLFSSL_HAVE_LMS)
  640. #if !defined(WOLFSSL_SMALL_STACK)
  641. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  642. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  643. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void);
  644. #endif
  645. #endif
  646. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  647. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void);
  648. #endif
  649. #endif
  650. #ifdef WOLFCRYPT_HAVE_ECCSI
  651. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void);
  652. #endif
  653. #ifdef WOLFCRYPT_HAVE_SAKKE
  654. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void);
  655. #endif
  656. #ifdef HAVE_BLAKE2
  657. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void);
  658. #endif
  659. #ifdef HAVE_BLAKE2S
  660. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void);
  661. #endif
  662. #ifdef HAVE_LIBZ
  663. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void);
  664. #endif
  665. #ifdef HAVE_PKCS7
  666. #ifndef NO_PKCS7_ENCRYPTED_DATA
  667. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void);
  668. #endif
  669. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  670. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void);
  671. #endif
  672. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void);
  673. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void);
  674. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  675. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void);
  676. #endif
  677. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  678. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key,
  679. word32 keySz);
  680. #endif
  681. #endif
  682. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  683. !defined(NO_FILESYSTEM)
  684. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void);
  685. #endif
  686. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  687. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  688. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void);
  689. #endif
  690. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  691. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  692. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void);
  693. #endif
  694. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void);
  695. #if defined(WOLFSSL_PUBLIC_MP) && \
  696. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  697. defined(USE_FAST_MATH))
  698. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void);
  699. #endif
  700. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  701. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void);
  702. #endif
  703. #if defined(ASN_BER_TO_DER) && \
  704. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  705. defined(OPENSSL_EXTRA_X509_SMALL))
  706. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void);
  707. #endif
  708. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void);
  709. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  710. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void);
  711. #endif
  712. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  713. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void);
  714. #else
  715. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void);
  716. #endif
  717. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  718. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void);
  719. #endif
  720. #ifdef WOLFSSL_CAAM_BLOB
  721. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void);
  722. #endif
  723. #ifdef HAVE_ARIA
  724. #include "wolfssl/wolfcrypt/port/aria/aria-crypt.h"
  725. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz);
  726. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID);
  727. #endif
  728. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  729. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void);
  730. #endif
  731. #ifdef WOLFSSL_CERT_PIV
  732. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void);
  733. #endif
  734. #ifdef WOLFSSL_AES_SIV
  735. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void);
  736. #endif
  737. #if defined(WOLFSSL_AES_EAX) && \
  738. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  739. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void);
  740. #endif /* WOLFSSL_AES_EAX */
  741. /* General big buffer size for many tests. */
  742. #define FOURK_BUF 4096
  743. /* If not defined in user_settings, the ERROR_OUT pause is 120 seconds. */
  744. #ifndef WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION
  745. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION 120
  746. #endif
  747. #if defined(WOLFSSL_ESPIDF_ERROR_PAUSE)
  748. #if defined(CONFIG_FREERTOS_HZ)
  749. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  750. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * CONFIG_FREERTOS_HZ)
  751. #else
  752. /* If not defined, assume RTOS is 1000 ticks per second. */
  753. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  754. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * 1000)
  755. #endif
  756. /* When defined, pause at error condition rather than exit with error. */
  757. #define ERROR_OUT(err, eLabel) \
  758. do { \
  759. ret = (err); \
  760. ESP_LOGE(ESPIDF_TAG, "Failed: Error = %d during %s, line %d", \
  761. err, __FUNCTION__, __LINE__); \
  762. ESP_LOGI(ESPIDF_TAG, "Extended system info:"); \
  763. esp_ShowExtendedSystemInfo(); \
  764. ESP_LOGW(ESPIDF_TAG, "Paused for %d seconds! " \
  765. "WOLFSSL_ESPIDF_ERROR_PAUSE is enabled.", \
  766. WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION); \
  767. vTaskDelay(WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS); \
  768. goto eLabel; \
  769. } while (0)
  770. #else
  771. #define ERROR_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  772. #endif
  773. /* Not all unexpected conditions are actually errors .*/
  774. #define WARNING_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  775. static void render_error_message(const char* msg, wc_test_ret_t es)
  776. {
  777. (void)msg;
  778. (void)es;
  779. #ifdef WOLFSSL_LINUXKM
  780. #define err_sys_printf lkm_printf
  781. #else
  782. #define err_sys_printf printf
  783. #endif
  784. switch (WC_TEST_RET_DEC_TAG(es)) {
  785. case WC_TEST_RET_TAG_NC:
  786. err_sys_printf("%s error L=%d\n", msg, WC_TEST_RET_DEC_LN(es));
  787. break;
  788. case WC_TEST_RET_TAG_EC:
  789. #ifdef NO_ERROR_STRINGS
  790. err_sys_printf("%s error L=%d code=%d\n", msg,
  791. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es));
  792. #elif defined(WOLFCRYPT_ONLY) || !defined(WOLFSSL_TYPES_DEFINED)
  793. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  794. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  795. wc_GetErrorString(-WC_TEST_RET_DEC_I(es))
  796. );
  797. #else
  798. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  799. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  800. wolfSSL_ERR_reason_error_string(-WC_TEST_RET_DEC_I(es))
  801. );
  802. #endif
  803. break;
  804. case WC_TEST_RET_TAG_ERRNO:
  805. {
  806. /* strerror_r() comes in two mutually incompatible flavors, a native glibc
  807. * flavor that always returns a non-null char pointer that must be used
  808. * directly, and a POSIX flavor that returns an error int, and iff success,
  809. * stores an error string in the supplied buffer. this is all most
  810. * infelicitous...
  811. */
  812. #if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
  813. (defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
  814. ((defined(__GLIBC__) && (__GLIBC__ >= 2) && defined(__USE_GNU)) || \
  815. (defined(__USE_XOPEN2K) && \
  816. defined(_POSIX_C_SOURCE) && \
  817. (_POSIX_C_SOURCE >= 200112L)))
  818. char errno_buf[64], *errno_string;
  819. /* precisely mirror the gate used in glibc string.h */
  820. #if defined __USE_XOPEN2K && !defined __USE_GNU
  821. if (strerror_r(WC_TEST_RET_DEC_I(es),
  822. errno_buf, sizeof(errno_buf)) != 0)
  823. XSTRLCPY(errno_buf, "?", sizeof(errno_buf));
  824. errno_string = errno_buf;
  825. #else
  826. errno_string = strerror_r(WC_TEST_RET_DEC_I(es),
  827. errno_buf, sizeof(errno_buf));
  828. #endif
  829. err_sys_printf("%s error L=%d errno=%d (%s)\n", msg,
  830. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es),
  831. errno_string);
  832. #else /* can't figure out how to strerror_r(), or don't want error strings */
  833. err_sys_printf("%s error L=%d errno=%d\n", msg,
  834. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  835. #endif
  836. break;
  837. }
  838. case WC_TEST_RET_TAG_I:
  839. err_sys_printf("%s error L=%d i=%d\n", msg,
  840. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  841. break;
  842. }
  843. #undef err_sys_printf
  844. }
  845. static void print_fiducials(void);
  846. #ifdef HAVE_STACK_SIZE
  847. static THREAD_RETURN err_sys(const char* msg, int es)
  848. #else
  849. static wc_test_ret_t err_sys(const char* msg, wc_test_ret_t es)
  850. #endif
  851. {
  852. render_error_message(msg, es);
  853. print_fiducials();
  854. #ifdef WOLFSSL_LINUXKM
  855. EXIT_TEST(es);
  856. #else
  857. EXIT_TEST(-1);
  858. #endif
  859. }
  860. #ifndef HAVE_WOLFCRYPT_TEST_OPTIONS
  861. /* func_args from test.h, so don't have to pull in other stuff */
  862. typedef struct func_args {
  863. int argc;
  864. char** argv;
  865. wc_test_ret_t return_code;
  866. } func_args;
  867. #endif /* !HAVE_WOLFCRYPT_TEST_OPTIONS */
  868. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  869. static void myFipsCb(int ok, int err, const char* hash)
  870. {
  871. printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
  872. printf("message = %s\n", wc_GetErrorString(err));
  873. printf("hash = %s\n", hash);
  874. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  875. printf("In core integrity hash check failure, copy above hash\n");
  876. printf("into verifyCore[] in fips_test.c and rebuild\n");
  877. }
  878. }
  879. #endif /* HAVE_FIPS && !WOLFSSL_LINUXKM */
  880. #if defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && !defined(WC_NO_CONSTRUCTORS)
  881. #if !defined(NO_AES)
  882. static WC_MAYBE_UNUSED Aes* wc_AesNew(void* heap, int thisDevId, int *result_code)
  883. {
  884. int ret;
  885. Aes* aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_AES);
  886. if (aes == NULL) {
  887. ret = MEMORY_E;
  888. }
  889. else {
  890. ret = wc_AesInit(aes, heap, thisDevId);
  891. if (ret != 0) {
  892. XFREE(aes, heap, DYNAMIC_TYPE_AES);
  893. aes = NULL;
  894. }
  895. }
  896. if (result_code != NULL)
  897. *result_code = ret;
  898. return aes;
  899. }
  900. static WC_MAYBE_UNUSED int wc_AesDelete(Aes *aes, Aes** aes_p)
  901. {
  902. if (aes == NULL)
  903. return BAD_FUNC_ARG;
  904. wc_AesFree(aes);
  905. XFREE(aes, aes->heap, DYNAMIC_TYPE_AES);
  906. if (aes_p != NULL)
  907. *aes_p = NULL;
  908. return 0;
  909. }
  910. #endif /* !NO_AES */
  911. #if !defined(NO_RSA)
  912. static WC_MAYBE_UNUSED RsaKey* wc_NewRsaKey(void* heap, int thisDevId, int *result_code)
  913. {
  914. int ret;
  915. RsaKey* key = (RsaKey*)XMALLOC(sizeof(RsaKey), heap, DYNAMIC_TYPE_RSA);
  916. if (key == NULL) {
  917. ret = MEMORY_E;
  918. }
  919. else {
  920. ret = wc_InitRsaKey_ex(key, heap, thisDevId);
  921. if (ret != 0) {
  922. XFREE(key, heap, DYNAMIC_TYPE_RSA);
  923. key = NULL;
  924. }
  925. }
  926. if (result_code != NULL)
  927. *result_code = ret;
  928. return key;
  929. }
  930. static WC_MAYBE_UNUSED int wc_DeleteRsaKey(RsaKey* key, RsaKey** key_p)
  931. {
  932. if (key == NULL)
  933. return BAD_FUNC_ARG;
  934. wc_FreeRsaKey(key);
  935. XFREE(key, key->heap, DYNAMIC_TYPE_RSA);
  936. if (key_p != NULL)
  937. *key_p = NULL;
  938. return 0;
  939. }
  940. #endif /* !NO_RSA */
  941. #endif /* FIPS_VERSION3_LT(6,0,0) && !WC_NO_CONSTRUCTORS */
  942. #ifdef WOLFSSL_STATIC_MEMORY
  943. #if defined(WOLFSSL_STATIC_MEMORY_TEST_SZ)
  944. static byte gTestMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  945. #elif defined(BENCH_EMBEDDED)
  946. static byte gTestMemory[14000];
  947. #elif defined(WOLFSSL_CERT_EXT)
  948. static byte gTestMemory[140000];
  949. #elif (defined(WOLFSSL_SP_MATH_ALL) || defined(USE_FAST_MATH)) && \
  950. !defined(ALT_ECC_SIZE)
  951. static byte gTestMemory[160000];
  952. #else
  953. static byte gTestMemory[80000];
  954. #endif
  955. #endif
  956. #ifdef WOLFSSL_PB
  957. static int wolfssl_pb_print(const char* msg, ...)
  958. {
  959. int ret;
  960. va_list args;
  961. char tmpBuf[80];
  962. va_start(args, msg);
  963. ret = vsprint(tmpBuf, msg, args);
  964. va_end(args);
  965. fnDumpStringToSystemLog(tmpBuf);
  966. return ret;
  967. }
  968. #endif /* WOLFSSL_PB */
  969. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  970. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  971. /* Enable support for RNG with crypto callback */
  972. static int rng_crypto_cb(int thisDevId, wc_CryptoInfo* info, void* ctx)
  973. {
  974. int rc = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  975. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  976. rc = wc_GenerateSeed(&info->rng.rng->seed, info->rng.out, info->rng.sz);
  977. }
  978. (void)ctx;
  979. (void)thisDevId;
  980. return rc;
  981. }
  982. #endif
  983. #if defined(WC_KDF_NIST_SP_800_56C)
  984. #define INIT_SP80056C_TEST_VECTOR(_z, _fixedInfo, _derivedKey, _hashType) \
  985. { \
  986. .z = (const byte*)_z, .zSz = sizeof(_z) - 1, \
  987. .fixedInfo = (const byte*)_fixedInfo, \
  988. .fixedInfoSz = sizeof(_fixedInfo) - 1, \
  989. .derivedKey = (const byte*)_derivedKey, \
  990. .derivedKeySz = sizeof(_derivedKey) - 1, .hashType = _hashType, \
  991. }
  992. #define SP800_56C_MAX_OUT 128
  993. static WOLFSSL_TEST_SUBROUTINE wc_test_ret_t nist_sp80056c_kdf_test(void)
  994. {
  995. struct sp800_56c_test_vector {
  996. const byte* z;
  997. word32 zSz;
  998. const byte* fixedInfo;
  999. word32 fixedInfoSz;
  1000. const byte* derivedKey;
  1001. word32 derivedKeySz;
  1002. enum wc_HashType hashType;
  1003. };
  1004. struct sp800_56c_test_vector* v;
  1005. byte output[SP800_56C_MAX_OUT];
  1006. word32 i;
  1007. int ret;
  1008. /* vectors from
  1009. * https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
  1010. *
  1011. * (KeyManagement) */
  1012. struct sp800_56c_test_vector vctors[] = {
  1013. #if !defined(NO_SHA)
  1014. /* SHA-1 */
  1015. INIT_SP80056C_TEST_VECTOR(
  1016. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  1017. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  1018. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  1019. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1020. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1021. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  1022. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  1023. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  1024. WC_HASH_TYPE_SHA),
  1025. INIT_SP80056C_TEST_VECTOR(
  1026. "\xae\x64\xab\x2b\x2b\x75\xa9\x4c\xf8\xef\x24\xda\x24\x56\xbd\x3a"
  1027. "\xa3\x6d\xb6\x14\x29\xea\x55\x21",
  1028. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1029. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1030. "\xcc\x96\x5a\x52\xd0\x5c\x94\x9e\x52\xc0\x35\xfd\x03\x53\x0d\xb7"
  1031. "\xea\xa4\x08\x70\x2c\x9d\x35\x21\x1e\x67\x21\x54\x12\x45\x91\x51"
  1032. "\xba\x22\x62\xbd\x1e\x28\xe5\x6b",
  1033. WC_HASH_TYPE_SHA),
  1034. INIT_SP80056C_TEST_VECTOR(
  1035. "\x71\x5d\xc0\xea\x24\x6b\x46\x56\x63\xa8\x9c\xde\x04\x12\xc1\x92"
  1036. "\xe1\x9e\x58\xd5\xb0\xb6\x36\x6d\xa7\x89\xad\xbf\x44\x9a\x38\xaa"
  1037. "\x46\x69\xfe\x36\x30\xa2\x0f\x7f\xa3\x14\x9c\x9b\x4b\x0a\xb5\xcd"
  1038. "\x3e\x14\x18\x2b\x75\x04\xd5\xd2\x75\x2b\xf6\x58\x7a\xab\xc9\xf4"
  1039. "\xcb\x8f\xe5\x29\x23\x6a\xb8\x15\x36\xad\xd2\xbd\x25\xd6\xbf\x9d"
  1040. "\x5f\x1d\xf5\x76\x16\x5a\xa5\x5c\x24\x99\x61\xd8\xf8\x75\x00\xed"
  1041. "\x8d\xbf\xc5\xd2\x50\x53\x4c\x07\xd9\x9a\xc9\x17\xf9\x84\x60\x46"
  1042. "\xac\x5c\xb8\xa2\x98\x74\x26\x22\xd3\xc9\x86\x18\x06\x92\x46\xe8"
  1043. "\xad\x37\x11\x25\x57\xe0\xe6\x34\xb5\x81\x32\x7a\x4a\xd3\x2c\x7c"
  1044. "\x76\x4b\xe8\xf8\x08\x0d\x37\x2c\x63\x20\x93\xa7\x67\xf1\x55\xbd"
  1045. "\x22\xec\x00\x3c\xa6\x1c\x8b\x43\x32\x0f\x3a\xbe\xb5\xdd\xc4\xa3"
  1046. "\xb1\x89\x82\xfd\xd6\x51\x0f\x88\x3c\x8d\xc1\xe0\xb1\x57\xff\xb9"
  1047. "\xcf\xc0\xa5\x9c\xe2\xd4\x05\x5f\xfc\x73\xe7\x15\x2a\x6a\x95\x43"
  1048. "\xb9\x19\xe7\x94\xe9\x49\x61\x33\xbe\x2a\x23\x18\xd9\x05\x6e\xfd"
  1049. "\x74\x48\x2d\xc6\x3c\x0d\xb5\x8f\xe6\x42\x6b\x0f\xe7\x35\x45\x42"
  1050. "\xc2\x19\x7a\xb6\xbd\x35\xf1\xa9\x2d\xce\x90\xb1\xc4\x6d\x32\xc1",
  1051. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1052. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1053. "\x1b\x5f\xcc\x8d\x81\xa5\xd9\xa9\x36\x94\xe6\x47\x77\x88\xd8\x03"
  1054. "\x15\x84\xc3\xf5\x2e\x9f\x11\x7a\xe8\x18\x4d\xba\x56\x47\x9d\x87"
  1055. "\x66\x76\x92\xf1\x2d\x7b\xd3\x8b",
  1056. WC_HASH_TYPE_SHA),
  1057. INIT_SP80056C_TEST_VECTOR(
  1058. "\x33\xe0\x50\xbd\x20\x9f\x2d\xf2\x77\x19\x78\xfc\xd1\xd4\xc8\x2e"
  1059. "\x49\xd0\x1d\x65\xbb\x62\x03\x20\xd3\x0b\xfe\xa8\x7a\xa8\x69\xe1"
  1060. "\x07\xa5\x17\xa4\xc8\x5b\x69\x28\x45\x21\xca\x54\xb7\x7f\x59\xe9"
  1061. "\x4a\x85\x6d\xaa\x30\xa3\x85\xa5\x25\xd8\xa3\xf7\xe1\x5e\xe5\xe9"
  1062. "\xaa\x12\x8d\x45\xef\x63\xf9\x0c\x10\xe0\x8f\xc5\x26\x36\x13\x77"
  1063. "\x81\x54\x7a\x58\x9f\x97\x87\xf9\xd7\xdd\x61\x43\x41\x9a\x26\x16"
  1064. "\x80\x16\x82\x40\xaa\xb2\x01\x3d\x80\x20\xdb\xe8\x4b\x7e\x2b\xed"
  1065. "\xce\x67\x1b\x94\x03\xbd\x1f\x91\x71\xa2\x57\x90\xce\x66\x7d\xed",
  1066. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1067. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1068. "\x35\x10\x85\x85\xfc\x55\x62\xb5\xf1\x8f\x20\x7b\xa8\x35\x63\xe4"
  1069. "\x49\x28\x45\x6a\x5e\x53\x63\x7e\xae\x6b\xb5\xfc\x33\x88\xae\x02"
  1070. "\x91\x79\x0a\x1d\xc8\x31\x4e\x28",
  1071. WC_HASH_TYPE_SHA),
  1072. INIT_SP80056C_TEST_VECTOR(
  1073. "\x5c\x80\x4f\x45\x4d\x30\xd9\xc4\xdf\x85\x27\x1f\x93\x52\x8c\x91"
  1074. "\xdf\x6b\x48\xab\x5f\x80\xb3\xb5\x9c\xaa\xc1\xb2\x8f\x8a\xcb\xa9"
  1075. "\xcd\x3e\x39\xf3\xcb\x61\x45\x25\xd9\x52\x1d\x2e\x64\x4c\x53\xb8"
  1076. "\x07\xb8\x10\xf3\x40\x06\x2f\x25\x7d\x7d\x6f\xbf\xe8\xd5\xe8\xf0"
  1077. "\x72\xe9\xb6\xe9\xaf\xda\x94\x13\xea\xfb\x2e\x8b\x06\x99\xb1\xfb"
  1078. "\x5a\x0c\xac\xed\xde\xae\xad\x7e\x9c\xfb\xb3\x6a\xe2\xb4\x20\x83"
  1079. "\x5b\xd8\x3a\x19\xfb\x0b\x5e\x96\xbf\x8f\xa4\xd0\x9e\x34\x55\x25"
  1080. "\x16\x7e\xcd\x91\x55\x41\x6f\x46\xf4\x08\xed\x31\xb6\x3c\x6e\x6d",
  1081. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1082. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1083. "\xfa\xa0\x22\xce\x7f\xa9\xba\x95\xeb\xa3\x9f\x3f\x44\xf3\xee\x14"
  1084. "\x96\x0a\x0b\x23\x9d\x01\x4b\x57\x70\xe4\x71\xd7\x5a\x99\xea\x87"
  1085. "\x10\xe3\x8f\x0c\xef\x0f\xfc\x67",
  1086. WC_HASH_TYPE_SHA),
  1087. INIT_SP80056C_TEST_VECTOR(
  1088. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  1089. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  1090. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  1091. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1092. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1093. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  1094. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  1095. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  1096. WC_HASH_TYPE_SHA),
  1097. #endif
  1098. #if defined(WOLFSSL_SHA224)
  1099. /* SHA-224*/
  1100. INIT_SP80056C_TEST_VECTOR(
  1101. "\x8c\x5d\x6e\x5d\x36\x06\x83\xba\x55\xb0\x9d\xb1\x69\x6d\x7c\x64"
  1102. "\x02\xff\x87\x88\x5f\xf5\x07\x70\xf2\x76\x7b\x75\x54\x60\x20\x7e"
  1103. "\xd5\xc7\x43\xfd\x27\xe7\xeb\x1d\x0c\xa5\x91\xf8\x56\x38\x93\x11"
  1104. "\x73\x07\x44\xf2\x04\xd2\xe5\x5b\x8b\xd4\x46\xce\xca\x03\x1f\x7b"
  1105. "\xac\xcf\xf1\xa7\x1b\x68\x34\x59\xcc\x54\xd5\x01\xda\xbf\x4a\x84"
  1106. "\xcd\xb8\x6d\xfa\xda\xff\x31\x0f\xbd\xba\xf7\x4d\xd5\x1b\xa1\xe1"
  1107. "\xe1\x19\x1a\xf1\x4c\x9b\xf8\x94\x43\xbf\x58\x8e\x9c\xe3\x30\x34"
  1108. "\xaf\x5e\x89\xbf\x6f\xfc\x47\xd7\xd9\xca\x4a\x5e\x8f\xf8\xa0\x50"
  1109. "\x20\xbb\x0f\x95\xbc\xde\x01\x56\xd8\x7f\xb8\x60\xbd\x40\x83\xfa"
  1110. "\x5b\x53\x1a\x08\xa4\xfb\x7e\xe0\x20\x1a\xe8\xb3\xcc\xff\xe9\x9f"
  1111. "\x27\x0b\xc3\x53\x4b\xaa\xcf\xc0\x01\xcd\xd8\x0a\xd8\x7c\xce\x71"
  1112. "\xf0\x91\xe7\x66\xca\x5c\xc2\x75\xcb\x49\x14\x5a\x5e\xe6\x16\x2e"
  1113. "\xcc\xf5\x58\xce\xc4\xd3\xee\x53\x1e\x91\xe9\xa5\x29\x69\x63\x4d"
  1114. "\x3a\xf8\xd2\x6f\x8d\x15\xdc\x0d\x6f\x6e\x0a\x97\x4b\xe4\x34\x1b"
  1115. "\x68\xa0\x19\x90\xdb\xb8\x64\x95\x89\x1a\xd3\xaf\xc1\xe4\xce\xdf"
  1116. "\x4c\x6a\xe1\xf1\xcd\x60\x81\xcd\xee\xd8\xe6\xb3\x26\x4e\xc3\xbe"
  1117. "\x24\x58\xd1\xc0\xca\x24\x43\x41\x0c\xf3\xb4\x7c\x0c\x25\x4c\x7d"
  1118. "\xc8\xec\xb4\x3e\x6c\x23\x64\xe1\xc0\x62\x19\xcc\x7e\xfb\xff\xbb"
  1119. "\x63\xd7\xff\xfc\x74\x58\x12\xfd\x24\x0c\x33\xd4\x96\xb9\x99\x2f"
  1120. "\x96\x80\xa6\x3c\x07\x96\x3c\x0c\x49\xf3\xc1\xba\xef\xec\xaf\x32"
  1121. "\xe2\xaa\x8a\x2f\x7c\xd3\x0d\x8f\x05\x1e\xe2\xf5\x0f\xbf\x05\xab"
  1122. "\x13\x96\xa4\xea\x87\x44\x7d\x7b\x98\x1b\x5e\x46\x14\x28\x18\x71"
  1123. "\xa6\xf0\xf6\xbf\x1f\xe0\x02\x2f\x7e\xa1\x32\xbe\x0a\xe9\x19\x26"
  1124. "\xab\x12\xaf\x6d\xc4\x50\x64\xaa\xd5\x6b\x84\xb9\x0c\x70\x08\x37"
  1125. "\x09\xcf\xf7\xe3\x1b\x54\x8f\xb7\xfb\x2c\xf7\x5a\xbf\x96\xe0\x1c"
  1126. "\xcd\x3e\x94\x2e\xed\x91\x48\x0d\x4c\x24\xc6\xb7\xf9\x79\xfb\xbe"
  1127. "\x5d\xa2\x39\xb3\x76\x16\x7d\x68\x57\x35\x24\xff\xcb\x50\x99\x54"
  1128. "\xcc\x80\xa0\xe1\xa7\x1c\x40\xc4\xda\x17\xb8\xd1\x57\x2b\x21\x58"
  1129. "\x7a\x8d\x66\xcc\x62\x1c\x7c\xd1\x0f\x49\xab\xd5\xef\x86\x31\x13"
  1130. "\xe6\x19\x21\x08\x6f\xac\x25\x31\x2b\x74\x1c\x11\xa8\xfb\xc1\xe3"
  1131. "\x3c\x34\xd9\xda\x14\xa8\x22\x47\x7f\xcc\x36\x66\x70\x25\xc4\xf1"
  1132. "\x30\xae\x10\x0e\x36\xf1\x5d\xa0\x03\x74\xce\x87\x41\x67\x9f\x61",
  1133. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1134. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1135. "\x4b\x99\x6a\x60\xc0\x4a\x35\xc5\xe6\xd4\x74\xb1\x0a\x25\x8d\x56"
  1136. "\x2e\xa6\xdc\x52\xf6\xc6\x9b\xf3\x9e\xf8\x8c\x89\xe3\xcc\x8a\x54"
  1137. "\xda\x2f\x3c\x0b\x56\x1b\x53\xfe\x76\x55\x13\x63\xd6\x9c\x3c\xef"
  1138. "\x74\xe3\x4f\xe8\x8e\xb3\xac\x51",
  1139. WC_HASH_TYPE_SHA224),
  1140. INIT_SP80056C_TEST_VECTOR(
  1141. "\x52\x27\x2f\x50\xf4\x6f\x4e\xdc\x91\x51\x56\x90\x92\xf4\x6d\xf2"
  1142. "\xd9\x6e\xcc\x3b\x6d\xc1\x71\x4a\x4e\xa9\x49\xfa\x9f\x18\xff\x54"
  1143. "\xf8\x87\x23\x07\x3f\x64\xa6\x95\x3d\x04\x91\x4f\x45\xa2\x3e\xee"
  1144. "\x7c\xfc\x46\x67\x08\x0a\xa0\xf9",
  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. "\x77\x56\xbc\xfd\xef\x3e\xe6\x9f\x6a\xc2\x3c\xd2\xdc\x60\x7d\x01"
  1148. "\xfa\x8c\xe1\xb2\x4f\x5c\xaa\xaa\x48\xe0\x4b\x81\x63\xe1\x73\x3a"
  1149. "\xed\x7a\x04\x0e\x73\xf2\xb5\x42\x36\x8f\x00\x54\x8b\x16\x3c\x3d"
  1150. "\xc9\x6d\x70\x09\x99\x16\xf1\x6b",
  1151. WC_HASH_TYPE_SHA224),
  1152. #endif
  1153. #if !defined(NO_SHA256)
  1154. /* SHA-256 */
  1155. INIT_SP80056C_TEST_VECTOR(
  1156. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1157. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1158. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1159. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  1160. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1161. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1162. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1163. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1164. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1165. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc\xa6",
  1166. WC_HASH_TYPE_SHA256),
  1167. INIT_SP80056C_TEST_VECTOR(
  1168. "\x44\xf4\x84\x09\xf3\x1b\xf3\x50\x94\x51\xdb\x4d\x30\x4b\xeb\xd8"
  1169. "\x3c\x2a\xd6\x50\x1c\x1b\x85\xe6\x32\xbc\x92\x58\x8e\x2d\x48\xb5"
  1170. "\xd2\xb8\x44\x44\x62\xad\x94\xe8\xa4\x44\x94\x1e\xd4\x97\x5c\x97"
  1171. "\x91\x17\xd7\x5a\x0a\x2b\xa8\x10\xdf\xa8\x80\x4a\x0f\xe9\x42\x6d"
  1172. "\xd7\xeb\x95\xf2\x9c\xa4\x30\xda\x37\xef\xa5\x2c\x42\xda\x1d\xe2"
  1173. "\x23\x76\x3b\xdd\xc9\x5e\x46\x6a\xa3\xb8\xd2\x06\xb8\x21\x8e\xdf"
  1174. "\x23\x97\x3d\x05\xf3\xc7\xc2\x2b\x22\x46\x53\xd4\xf9\x21\x85\x45"
  1175. "\x79\x83\x26\x2f\x27\xbc\x55\xa0\xa7\xae\xe5\x43\x54\x55\xd4\x3c"
  1176. "\x0e\x0c\x6d\x80\x67\xad\xaf\x90\x42\xb6\xb7\x77\x7e\x19\x8d\x67"
  1177. "\x60\x83\x0d\x96\xb2\x9a\x6a\xae\xf5\x74\xd7\x5e\x2d\x65\x43\x55"
  1178. "\x0f\x75\x55\xcf\x89\x82\xc8\x21\xc4\xec\x9b\x82\x66\x2b\x09\x36"
  1179. "\x69\xfd\x24\x6d\x4d\xcc\xbf\xf3\x1d\x98\x4e\xf6\x3c\x4f\x95\xd7"
  1180. "\x39\xc7\x7e\x66\xf6\x9b\x6d\xb0\xd9\xfc\x1a\x97\x3f\x52\x33\xd1"
  1181. "\x1f\xe7\x15\x4b\x8a\x6b\xe1\x50\x46\x7d\x92\xda\xf0\x91\x44\x34"
  1182. "\xf0\xcf\x17\x6e\x96\x1b\x31\x3f\xe3\xe2\x3b\xfe\x37\x8b\x87\xba"
  1183. "\xf2\x73\x93\x7f\xfa\xa6\x85\x65\x8b\x09\x78\x1d\x26\x97\x86\x4b"
  1184. "\x0d\x82\x48\x5c\xf7\xd6\x2f\xfc\xea\x34\x33\x88\xcf\xec\x15\x27"
  1185. "\x3a\x39\x4b\x84\x32\xee\xb6\x32\x1b\xe3\x1d\x4f\xcd\x16\x15\xc8"
  1186. "\x1c\x69\x37\xc0\x8d\x92\x41\x6e\xdb\xdd\x20\x10\xfa\x8b\x6e\x0a"
  1187. "\x8a\x60\x3d\xad\xe0\x10\xbc\x9c\xd7\x6b\x14\xe3\xe2\x19\x0e\x3b"
  1188. "\xa3\x00\xe7\x1a\xdd\xbf\x24\x4c\xf8\x06\x29\x49\x76\xea\xf0\x7d"
  1189. "\x02\x3b\xdb\x57\xfc\x5d\x19\x64\xc7\xd4\x20\x6e\x72\x06\x1b\xfe"
  1190. "\x1e\xe4\xee\xbc\x92\x00\xe1\x3a\x6c\xba\x32\x86\x9d\xbe\x80\x82"
  1191. "\xcd\xf3\x64\x5b\x5a\x72\x7d\xd2\x7c\xa5\x03\xf4\xed\xeb\x73\xe8"
  1192. "\x8a\x3a\x55\x2c\x7e\x00\xd4\xee\x72\x42\x13\x72\x36\xa0\x96\x5c"
  1193. "\x1e\xc3\xeb\xc0\xb4\x8c\x2b\x46\x7e\xb8\x42\x41\x5a\x28\x3f\x55"
  1194. "\xe2\x20\xff\xd1\x88\x19\x25\x6d\xa2\x47\x4d\x28\xfc\x3b\x04\xe0"
  1195. "\xc0\x7e\x4d\x25\xc1\x74\x93\x41\xd2\x22\x97\x01\x5c\xd8\x17\x8c"
  1196. "\x39\x18\xbe\x8c\x5c\xdf\x0f\xbf\xbb\x9a\x5a\xcc\xdd\x82\xaf\x07"
  1197. "\x83\xef\xe4\xdf\x64\xa8\xd8\x92\x82\x8f\x8d\xe5\x8c\x5d\x56\x9b"
  1198. "\x5b\x08\x45\x58\x96\xc4\xd3\xc3\x4f\xd3\xce\x93\xc4\x34\xc3\x8e"
  1199. "\xf5\x6c\xed\x30\x56\x1c\x37\x1a\xf9\xf2\xd8\x64\xfd\xc5\xb6\x2f",
  1200. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1201. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1202. "\x42\x35\xac\x89\xc9\xf3\x3e\x5d\xbb\x11\x60\x1a\x29\x83\xe3\x76"
  1203. "\xe2\x15\x39\x97\x87\xd8\x39\xa0\x38\x55\xfe\x04\x53\x3e\x1a\x67"
  1204. "\x66\x91\x5e\x67\xc2\x5e\xeb\x04\x08\x28\xe9\x6c\xd3\xd6\xef\x0a"
  1205. "\xb7\xd1\x7b\x43\x13\x43\xa7\xf3\xaa\xc6\x8f\x0c\x4a\x7e\x77\x9b",
  1206. WC_HASH_TYPE_SHA256),
  1207. /* slightly modified vector to test generation when derivedKeySz %
  1208. * hashOutSz != 0*/
  1209. INIT_SP80056C_TEST_VECTOR(
  1210. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1211. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1212. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1213. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  1214. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1215. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1216. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1217. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1218. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1219. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc",
  1220. WC_HASH_TYPE_SHA256),
  1221. #endif
  1222. #if defined(WOLFSSL_SHA384)
  1223. /* SHA-384 */
  1224. INIT_SP80056C_TEST_VECTOR(
  1225. "\x5e\xa1\xfc\x4a\xf7\x25\x6d\x20\x55\x98\x1b\x11\x05\x75\xe0\xa8"
  1226. "\xca\xe5\x31\x60\x13\x7d\x90\x4c\x59\xd9\x26\xeb\x1b\x84\x56\xe4"
  1227. "\x27\xaa\x8a\x45\x40\x88\x4c\x37\xde\x15\x9a\x58\x02\x8a\xbc\x0e"
  1228. "\x88\x76\x9c\xb7\x2f\xc5\xac\x45\x7c\xd5\x8e\x89\x08\x9b\x19\x6a"
  1229. "\x70\xbf\x53\x3c\x6d\xc9\x1c\x9c\x7e\x17\x41\xdb\x5e\x7a\xb6\xb0"
  1230. "\x84\x9f\x01\xde\xa6\x5f\xed\xd0\x6c\x77\x18\x7c\xd8\x8e\xd0\x30",
  1231. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1232. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1233. "\x8e\x6e\x26\x5f\x20\x82\xf1\x4d\x34\xda\x23\xe1\x03\x2c\x90\x24"
  1234. "\x83\x4a\xf0\x15\x72\xb6\x64\x77\x82\x41\x1b\xdd\xcb\x84\xa5\xda"
  1235. "\xee\x11\x7b\xa6\xfb\xa6\xd0\xeb\x28\x08\xef\x8a\xb0\x70\x05\xee"
  1236. "\xab\xe5\x2d\x2e\xfd\x31\x12\x1c\x7b\xf9\xd5\xfa\xfc\x40\xe0\x0c"
  1237. "\x6d\x6d\xbf\x39\xef\x43\xfe\x97\x15\xc7\x20\x2c\xdc\x2d\xb7\xe8"
  1238. "\x2b\x88\xd7\x48\xeb\x84\x25\x8b\xf8\x4d\x85\x82\xf2\xbf\xd9\x40",
  1239. WC_HASH_TYPE_SHA384),
  1240. #endif
  1241. #if defined(WOLFSSL_SHA512)
  1242. /* SHA-512 */
  1243. INIT_SP80056C_TEST_VECTOR(
  1244. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1245. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1246. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1247. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1248. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1249. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1250. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1251. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1252. "\xde\x34\x54\xe4",
  1253. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1254. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1255. "\x2d\x4a\x46\xa1\x70\x99\xba\xa8\x33\x0b\xc5\x9d\x4a\x1c\xf5\xae"
  1256. "\x3a\x30\x75\xb4\xc6\x2b\xb2\x6e\x7f\xc9\x89\x24\x72\x6d\x27\x4c"
  1257. "\x09\x64\x6f\x44\x08\xe6\x85\x8c\x43\xb4\x2d\xae\xd0\x15\xef\x26"
  1258. "\x17\x08\xd5\x5e\xf2\x4d\xaa\x7d\x3e\xa3\xd1\xc4\xa0\x8c\xfd\x24"
  1259. "\xdb\x60\x00\xa5\xb8\xa6\x7d\xe7\x46\xf3\xd3\xf4\xff\x34\x85\x15"
  1260. "\x8f\xd3\xb6\x91\x55\x79\x1d\xf4\x67\x47\xd4\xdb\xbe\x17\xc4\xb5"
  1261. "\x58\x46\x2e\x26\xbe\x5e\xd3\x5f\xe6\x80\xe2\x97\x14\x22\xc3\xb0"
  1262. "\x1b\x17\xe1\x67\xfc\x43\x7f\x84\x86\x9d\x85\x49\x53\x7b\x33\x38",
  1263. WC_HASH_TYPE_SHA512),
  1264. #endif
  1265. INIT_SP80056C_TEST_VECTOR(
  1266. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1267. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1268. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1269. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1270. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1271. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1272. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1273. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1274. "\xde\x34\x54\xe4",
  1275. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1276. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1277. "\x2d\x4a",
  1278. WC_HASH_TYPE_SHA512),
  1279. };
  1280. for (i = 0; i < sizeof(vctors) / sizeof(vctors[0]); i++) {
  1281. v = &vctors[i];
  1282. ret = wc_KDA_KDF_onestep(v->z, v->zSz, v->fixedInfo, v->fixedInfoSz,
  1283. v->derivedKeySz, v->hashType, output,
  1284. /* use derivedKeySz to force the function to use a temporary buff
  1285. for the last block */
  1286. v->derivedKeySz);
  1287. if (ret != 0)
  1288. return WC_TEST_RET_ENC_EC(ret);
  1289. if (XMEMCMP(output, v->derivedKey, v->derivedKeySz) != 0)
  1290. return WC_TEST_RET_ENC_NC;
  1291. }
  1292. /* negative tests */
  1293. ret = wc_KDA_KDF_onestep(NULL, 0, (byte*)"fixed_info",
  1294. sizeof("fixed_info"), 16, WC_HASH_TYPE_SHA256, output, 16);
  1295. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1296. return WC_TEST_RET_ENC_NC;
  1297. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 1, 16,
  1298. WC_HASH_TYPE_SHA256, output, 16);
  1299. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1300. return WC_TEST_RET_ENC_NC;
  1301. /* allow empty FixedInfo */
  1302. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 0, 16,
  1303. WC_HASH_TYPE_SHA256, output, 16);
  1304. if (ret != 0)
  1305. return WC_TEST_RET_ENC_EC(ret);
  1306. return 0;
  1307. }
  1308. #endif /* WC_KDF_NIST_SP_800_56C */
  1309. /* optional macro to add sleep between tests */
  1310. #ifndef TEST_SLEEP
  1311. #define TEST_SLEEP() WC_DO_NOTHING
  1312. #else
  1313. #define TEST_PASS test_pass
  1314. #include <stdarg.h> /* for var args */
  1315. static WC_INLINE void test_pass(const char* fmt, ...)
  1316. {
  1317. va_list args;
  1318. va_start(args, fmt);
  1319. STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK(max_relative_stack, vprintf(fmt, args));
  1320. va_end(args);
  1321. PRINT_HEAP_CHECKPOINT();
  1322. TEST_SLEEP();
  1323. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1););
  1324. }
  1325. #endif
  1326. /* set test pass output to printf if not overridden */
  1327. #ifndef TEST_PASS
  1328. /* redirect to printf */
  1329. #define TEST_PASS(...) { \
  1330. if (STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK \
  1331. (max_relative_stack, printf(__VA_ARGS__)) < 0) { \
  1332. return err_sys("post-test check failed", WC_TEST_RET_ENC_NC);\
  1333. } \
  1334. PRINT_HEAP_CHECKPOINT(); \
  1335. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); \
  1336. }
  1337. #endif
  1338. #ifdef TEST_ALWAYS_RUN_TO_END
  1339. #define TEST_FAIL(msg, retval) do { last_failed_test_ret = (retval); render_error_message(msg, retval); } while (0)
  1340. #elif !defined(TEST_FAIL)
  1341. #define TEST_FAIL(msg, retval) return err_sys(msg, retval)
  1342. #endif
  1343. #ifdef HAVE_STACK_SIZE
  1344. THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args)
  1345. #else
  1346. wc_test_ret_t wolfcrypt_test(void* args)
  1347. #endif
  1348. {
  1349. wc_test_ret_t ret;
  1350. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1351. long heap_baselineAllocs, heap_baselineBytes;
  1352. #endif
  1353. #ifdef TEST_ALWAYS_RUN_TO_END
  1354. int last_failed_test_ret = 0;
  1355. #endif
  1356. STACK_SIZE_INIT();
  1357. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1358. (void)wolfCrypt_heap_peakAllocs_checkpoint();
  1359. heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint();
  1360. (void)wolfCrypt_heap_peakBytes_checkpoint();
  1361. heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint();
  1362. #endif
  1363. #ifdef WC_RNG_SEED_CB
  1364. wc_SetSeed_Cb(wc_GenerateSeed);
  1365. #endif
  1366. printf("------------------------------------------------------------------------------\n");
  1367. printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING);
  1368. #ifdef WOLF_CRYPTO_CB
  1369. if (devId != INVALID_DEVID)
  1370. printf(" CryptoCB with DevID:%X\n", devId);
  1371. #endif
  1372. printf("------------------------------------------------------------------------------\n");
  1373. if (args) {
  1374. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1375. int ch;
  1376. #endif
  1377. ((func_args*)args)->return_code = -1; /* error state */
  1378. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1379. while ((ch = mygetopt(((func_args*)args)->argc, ((func_args*)args)->argv, "s:m:a:h")) != -1) {
  1380. switch(ch) {
  1381. case 's':
  1382. #ifdef HAVE_STACK_SIZE_VERBOSE
  1383. max_relative_stack = (ssize_t)atoi(myoptarg);
  1384. break;
  1385. #else
  1386. return err_sys("-s (max relative stack bytes) requires HAVE_STACK_SIZE_VERBOSE (--enable-stacksize=verbose).", WC_TEST_RET_ENC_NC);
  1387. #endif
  1388. case 'm':
  1389. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1390. max_relative_heap_bytes = (ssize_t)atoi(myoptarg);
  1391. break;
  1392. #else
  1393. return err_sys("-m (max relative heap memory bytes) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1394. #endif
  1395. case 'a':
  1396. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1397. max_relative_heap_allocs = (ssize_t)atoi(myoptarg);
  1398. break;
  1399. #else
  1400. return err_sys("-a (max relative heap allocs) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1401. #endif
  1402. case 'h':
  1403. return err_sys("\
  1404. options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
  1405. [-a max_relative_heap_allocs] [-h]\n", 0);
  1406. default:
  1407. return err_sys("unknown test option. try -h.", WC_TEST_RET_ENC_NC);
  1408. }
  1409. }
  1410. #endif
  1411. }
  1412. #ifdef WOLFSSL_STATIC_MEMORY
  1413. if (wc_LoadStaticMemory(&HEAP_HINT, gTestMemory, sizeof(gTestMemory),
  1414. WOLFMEM_GENERAL, 1) != 0) {
  1415. printf("unable to load static memory.\n");
  1416. return(EXIT_FAILURE);
  1417. }
  1418. #ifndef OPENSSL_EXTRA
  1419. wolfSSL_SetGlobalHeapHint(HEAP_HINT);
  1420. #endif
  1421. #endif
  1422. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  1423. wolfSSL_Debugging_ON();
  1424. #endif
  1425. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  1426. wc_SetLoggingHeap(HEAP_HINT);
  1427. #endif
  1428. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  1429. wolfCrypt_SetCb_fips(myFipsCb);
  1430. #if FIPS_VERSION3_GE(6,0,0)
  1431. printf("FIPS module version in use: %s\n",
  1432. wolfCrypt_GetVersion_fips());
  1433. #endif
  1434. #endif
  1435. #if !defined(NO_BIG_INT)
  1436. if (CheckCtcSettings() != 1) {
  1437. printf("Sizeof mismatch (build) %x != (run) %lx\n",
  1438. CTC_SETTINGS, (unsigned long)CheckRunTimeSettings());
  1439. return err_sys("Build vs runtime math mismatch\n", WC_TEST_RET_ENC_NC);
  1440. }
  1441. #if defined(USE_FAST_MATH) && \
  1442. (!defined(NO_RSA) || !defined(NO_DH) || defined(HAVE_ECC))
  1443. if (CheckFastMathSettings() != 1)
  1444. return err_sys("Build vs runtime fastmath FP_MAX_BITS mismatch\n",
  1445. WC_TEST_RET_ENC_NC);
  1446. #endif /* USE_FAST_MATH */
  1447. #endif /* !NO_BIG_INT */
  1448. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  1449. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  1450. initDefaultName();
  1451. #endif
  1452. #ifdef WOLFSSL_ASYNC_CRYPT
  1453. ret = wolfAsync_DevOpen(&devId);
  1454. if (ret < 0) {
  1455. printf("Async device open failed\nRunning without async\n");
  1456. }
  1457. #else
  1458. (void)devId;
  1459. #endif /* WOLFSSL_ASYNC_CRYPT */
  1460. #ifdef WOLF_CRYPTO_CB
  1461. #ifdef HAVE_INTEL_QA_SYNC
  1462. devId = wc_CryptoCb_InitIntelQa();
  1463. if (INVALID_DEVID == devId) {
  1464. printf("Couldn't init the Intel QA\n");
  1465. }
  1466. #endif
  1467. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  1468. devId = wc_CryptoCb_InitOcteon();
  1469. if (INVALID_DEVID == devId) {
  1470. printf("Couldn't init the Cavium Octeon\n");
  1471. }
  1472. #endif
  1473. #ifdef HAVE_RENESAS_SYNC
  1474. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  1475. if (devId == INVALID_DEVID) {
  1476. printf("Couldn't get the Renesas device ID\n");
  1477. }
  1478. #endif
  1479. #endif
  1480. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  1481. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  1482. if (devId == INVALID_DEVID) {
  1483. /* for testing RNG with crypto callback register function */
  1484. devId = 100; /* any value beside -2 (INVALID_DEVID) */
  1485. wc_CryptoCb_RegisterDevice(devId, rng_crypto_cb, NULL);
  1486. }
  1487. #endif
  1488. #ifdef HAVE_SELFTEST
  1489. if ( (ret = wolfCrypt_SelfTest()) != 0)
  1490. TEST_FAIL("CAVP selftest failed!\n", ret);
  1491. else
  1492. TEST_PASS("CAVP selftest passed!\n");
  1493. #endif
  1494. if ( (ret = error_test()) != 0)
  1495. TEST_FAIL("error test failed!\n", ret);
  1496. else
  1497. TEST_PASS("error test passed!\n");
  1498. if ( (ret = memory_test()) != 0)
  1499. TEST_FAIL("MEMORY test failed!\n", ret);
  1500. else
  1501. TEST_PASS("MEMORY test passed!\n");
  1502. #ifndef NO_CODING
  1503. if ( (ret = base64_test()) != 0)
  1504. TEST_FAIL("base64 test failed!\n", ret);
  1505. else
  1506. TEST_PASS("base64 test passed!\n");
  1507. #ifdef WOLFSSL_BASE16
  1508. if ( (ret = base16_test()) != 0)
  1509. TEST_FAIL("base16 test failed!\n", ret);
  1510. else
  1511. TEST_PASS("base16 test passed!\n");
  1512. #endif
  1513. #endif /* !NO_CODING */
  1514. #ifndef NO_ASN
  1515. if ( (ret = asn_test()) != 0)
  1516. TEST_FAIL("asn test failed!\n", ret);
  1517. else
  1518. TEST_PASS("asn test passed!\n");
  1519. #endif
  1520. #ifndef WC_NO_RNG
  1521. if ( (ret = random_test()) != 0)
  1522. TEST_FAIL("RANDOM test failed!\n", ret);
  1523. else
  1524. TEST_PASS("RANDOM test passed!\n");
  1525. #endif /* WC_NO_RNG */
  1526. #ifndef NO_MD5
  1527. if ( (ret = md5_test()) != 0)
  1528. TEST_FAIL("MD5 test failed!\n", ret);
  1529. else
  1530. TEST_PASS("MD5 test passed!\n");
  1531. #endif
  1532. #ifdef WOLFSSL_MD2
  1533. if ( (ret = md2_test()) != 0)
  1534. TEST_FAIL("MD2 test failed!\n", ret);
  1535. else
  1536. TEST_PASS("MD2 test passed!\n");
  1537. #endif
  1538. #ifndef NO_MD4
  1539. if ( (ret = md4_test()) != 0)
  1540. TEST_FAIL("MD4 test failed!\n", ret);
  1541. else
  1542. TEST_PASS("MD4 test passed!\n");
  1543. #endif
  1544. #ifndef NO_SHA
  1545. if ( (ret = sha_test()) != 0)
  1546. TEST_FAIL("SHA test failed!\n", ret);
  1547. else
  1548. TEST_PASS("SHA test passed!\n");
  1549. #endif
  1550. #ifdef WOLFSSL_SHA224
  1551. if ( (ret = sha224_test()) != 0)
  1552. TEST_FAIL("SHA-224 test failed!\n", ret);
  1553. else
  1554. TEST_PASS("SHA-224 test passed!\n");
  1555. #endif
  1556. #ifndef NO_SHA256
  1557. if ( (ret = sha256_test()) != 0)
  1558. TEST_FAIL("SHA-256 test failed!\n", ret);
  1559. else
  1560. TEST_PASS("SHA-256 test passed!\n");
  1561. #endif
  1562. #ifdef WOLFSSL_SHA384
  1563. if ( (ret = sha384_test()) != 0)
  1564. TEST_FAIL("SHA-384 test failed!\n", ret);
  1565. else
  1566. TEST_PASS("SHA-384 test passed!\n");
  1567. #endif
  1568. #ifdef WOLFSSL_SHA512
  1569. if ((ret = sha512_test()) != 0) {
  1570. TEST_FAIL("SHA-512 test failed!\n", ret);
  1571. }
  1572. else {
  1573. TEST_PASS("SHA-512 test passed!\n");
  1574. }
  1575. #if !defined(WOLFSSL_NOSHA512_224) && \
  1576. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1577. if ((ret = sha512_224_test()) != 0) {
  1578. TEST_FAIL("SHA-512/224 test failed!\n", ret);
  1579. }
  1580. else
  1581. TEST_PASS("SHA-512/224 test passed!\n");
  1582. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  1583. #if !defined(WOLFSSL_NOSHA512_256) && \
  1584. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1585. if ((ret = sha512_256_test()) != 0) {
  1586. TEST_FAIL("SHA-512/256 test failed!\n", ret);
  1587. }
  1588. else
  1589. TEST_PASS("SHA-512/256 test passed!\n");
  1590. #endif /* !defined(WOLFSSL_NOSHA512_256) & !FIPS ... */
  1591. #endif /* WOLFSSL_SHA512 */
  1592. #ifdef WOLFSSL_SHA3
  1593. if ( (ret = sha3_test()) != 0)
  1594. TEST_FAIL("SHA-3 test failed!\n", ret);
  1595. else
  1596. TEST_PASS("SHA-3 test passed!\n");
  1597. #endif
  1598. #ifdef WOLFSSL_SHAKE128
  1599. if ( (ret = shake128_test()) != 0)
  1600. TEST_FAIL("SHAKE128 test failed!\n", ret);
  1601. else
  1602. TEST_PASS("SHAKE128 test passed!\n");
  1603. #endif
  1604. #ifdef WOLFSSL_SHAKE256
  1605. if ( (ret = shake256_test()) != 0)
  1606. TEST_FAIL("SHAKE256 test failed!\n", ret);
  1607. else
  1608. TEST_PASS("SHAKE256 test passed!\n");
  1609. #endif
  1610. #ifdef WOLFSSL_SM3
  1611. if ( (ret = sm3_test()) != 0)
  1612. return err_sys("SM-3 test failed!\n", ret);
  1613. else
  1614. TEST_PASS("SM-3 test passed!\n");
  1615. #endif
  1616. #ifndef NO_HASH_WRAPPER
  1617. if ( (ret = hash_test()) != 0)
  1618. TEST_FAIL("Hash test failed!\n", ret);
  1619. else
  1620. TEST_PASS("Hash test passed!\n");
  1621. #endif
  1622. #ifdef WOLFSSL_RIPEMD
  1623. if ( (ret = ripemd_test()) != 0)
  1624. TEST_FAIL("RIPEMD test failed!\n", ret);
  1625. else
  1626. TEST_PASS("RIPEMD test passed!\n");
  1627. #endif
  1628. #ifdef HAVE_BLAKE2
  1629. if ( (ret = blake2b_test()) != 0)
  1630. TEST_FAIL("BLAKE2b test failed!\n", ret);
  1631. else
  1632. TEST_PASS("BLAKE2b test passed!\n");
  1633. #endif
  1634. #ifdef HAVE_BLAKE2S
  1635. if ( (ret = blake2s_test()) != 0)
  1636. TEST_FAIL("BLAKE2s test failed!\n", ret);
  1637. else
  1638. TEST_PASS("BLAKE2s test passed!\n");
  1639. #endif
  1640. #ifndef NO_HMAC
  1641. #if !defined(NO_MD5) && !(defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) \
  1642. && (HAVE_FIPS_VERSION >= 5))
  1643. if ( (ret = hmac_md5_test()) != 0)
  1644. TEST_FAIL("HMAC-MD5 test failed!\n", ret);
  1645. else
  1646. TEST_PASS("HMAC-MD5 test passed!\n");
  1647. #endif
  1648. #ifndef NO_SHA
  1649. if ( (ret = hmac_sha_test()) != 0)
  1650. TEST_FAIL("HMAC-SHA test failed!\n", ret);
  1651. else
  1652. TEST_PASS("HMAC-SHA test passed!\n");
  1653. #endif
  1654. #ifdef WOLFSSL_SHA224
  1655. if ( (ret = hmac_sha224_test()) != 0)
  1656. TEST_FAIL("HMAC-SHA224 test failed!\n", ret);
  1657. else
  1658. TEST_PASS("HMAC-SHA224 test passed!\n");
  1659. #endif
  1660. #ifndef NO_SHA256
  1661. if ( (ret = hmac_sha256_test()) != 0)
  1662. TEST_FAIL("HMAC-SHA256 test failed!\n", ret);
  1663. else
  1664. TEST_PASS("HMAC-SHA256 test passed!\n");
  1665. #endif
  1666. #ifdef WOLFSSL_SHA384
  1667. if ( (ret = hmac_sha384_test()) != 0)
  1668. TEST_FAIL("HMAC-SHA384 test failed!\n", ret);
  1669. else
  1670. TEST_PASS("HMAC-SHA384 test passed!\n");
  1671. #endif
  1672. #ifdef WOLFSSL_SHA512
  1673. if ( (ret = hmac_sha512_test()) != 0)
  1674. TEST_FAIL("HMAC-SHA512 test failed!\n", ret);
  1675. else
  1676. TEST_PASS("HMAC-SHA512 test passed!\n");
  1677. #endif
  1678. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  1679. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  1680. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  1681. if ( (ret = hmac_sha3_test()) != 0)
  1682. TEST_FAIL("HMAC-SHA3 test failed!\n", ret);
  1683. else
  1684. TEST_PASS("HMAC-SHA3 test passed!\n");
  1685. #endif
  1686. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  1687. PRIVATE_KEY_UNLOCK();
  1688. if ( (ret = hkdf_test()) != 0)
  1689. TEST_FAIL("HMAC-KDF test failed!\n", ret);
  1690. else
  1691. TEST_PASS("HMAC-KDF test passed!\n");
  1692. PRIVATE_KEY_LOCK();
  1693. #endif
  1694. #endif /* !NO_HMAC */
  1695. #ifdef WOLFSSL_WOLFSSH
  1696. PRIVATE_KEY_UNLOCK();
  1697. if ( (ret = sshkdf_test()) != 0)
  1698. TEST_FAIL("SSH-KDF test failed!\n", ret);
  1699. else
  1700. TEST_PASS("SSH-KDF test passed!\n");
  1701. PRIVATE_KEY_LOCK();
  1702. #endif /* WOLFSSL_WOLFSSH */
  1703. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  1704. PRIVATE_KEY_UNLOCK();
  1705. if ( (ret = prf_test()) != 0)
  1706. TEST_FAIL("PRF test failed!\n", ret);
  1707. else
  1708. TEST_PASS("PRF test passed!\n");
  1709. PRIVATE_KEY_LOCK();
  1710. #endif
  1711. #ifdef WOLFSSL_HAVE_PRF
  1712. #if defined (HAVE_HKDF) && !defined(NO_HMAC)
  1713. #ifdef WOLFSSL_BASE16
  1714. PRIVATE_KEY_UNLOCK();
  1715. if ( (ret = tls12_kdf_test()) != 0)
  1716. TEST_FAIL("TLSv1.2 KDF test failed!\n", ret);
  1717. else
  1718. TEST_PASS("TLSv1.2 KDF test passed!\n");
  1719. PRIVATE_KEY_LOCK();
  1720. #endif /* WOLFSSL_BASE16 */
  1721. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  1722. #endif /* WOLFSSL_HAVE_PRF */
  1723. #ifdef WOLFSSL_TLS13
  1724. PRIVATE_KEY_UNLOCK();
  1725. if ( (ret = tls13_kdf_test()) != 0)
  1726. TEST_FAIL("TLSv1.3 KDF test failed!\n", ret);
  1727. else
  1728. TEST_PASS("TLSv1.3 KDF test passed!\n");
  1729. PRIVATE_KEY_LOCK();
  1730. #endif /* WOLFSSL_TLS13 */
  1731. #if defined(HAVE_X963_KDF) && defined(HAVE_ECC)
  1732. if ( (ret = x963kdf_test()) != 0)
  1733. TEST_FAIL("X963-KDF test failed!\n", ret);
  1734. else
  1735. TEST_PASS("X963-KDF test passed!\n");
  1736. #endif
  1737. #if defined(HAVE_HPKE) && defined(HAVE_ECC) && defined(HAVE_AESGCM)
  1738. PRIVATE_KEY_UNLOCK();
  1739. if ( (ret = hpke_test()) != 0)
  1740. TEST_FAIL("HPKE test failed!\n", ret);
  1741. else
  1742. TEST_PASS("HPKE test passed!\n");
  1743. PRIVATE_KEY_LOCK();
  1744. #endif
  1745. #if defined(WC_SRTP_KDF)
  1746. PRIVATE_KEY_UNLOCK();
  1747. if ( (ret = srtpkdf_test()) != 0)
  1748. TEST_FAIL("SRTP KDF test failed!\n", ret);
  1749. else
  1750. TEST_PASS("SRTP KDF test passed!\n");
  1751. PRIVATE_KEY_LOCK();
  1752. #endif
  1753. #if defined(WC_KDF_NIST_SP_800_56C)
  1754. if ( (ret = nist_sp80056c_kdf_test()) != 0)
  1755. TEST_FAIL("NIST SP 800-56C KDF test failed!\n", ret);
  1756. else
  1757. TEST_PASS("NIST SP 800-56C KDF test passed!\n");
  1758. #endif
  1759. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
  1760. !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1761. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1762. if ( (ret = gmac_test()) != 0)
  1763. TEST_FAIL("GMAC test failed!\n", ret);
  1764. else
  1765. TEST_PASS("GMAC test passed!\n");
  1766. #endif
  1767. #ifdef WC_RC2
  1768. if ( (ret = rc2_test()) != 0)
  1769. TEST_FAIL("RC2 test failed!\n", ret);
  1770. else
  1771. TEST_PASS("RC2 test passed!\n");
  1772. #endif
  1773. #ifndef NO_RC4
  1774. if ( (ret = arc4_test()) != 0)
  1775. TEST_FAIL("ARC4 test failed!\n", ret);
  1776. else
  1777. TEST_PASS("ARC4 test passed!\n");
  1778. #endif
  1779. #ifdef HAVE_CHACHA
  1780. if ( (ret = chacha_test()) != 0)
  1781. TEST_FAIL("Chacha test failed!\n", ret);
  1782. else
  1783. TEST_PASS("Chacha test passed!\n");
  1784. #endif
  1785. #ifdef HAVE_XCHACHA
  1786. if ( (ret = XChaCha_test()) != 0)
  1787. TEST_FAIL("XChacha test failed!\n", ret);
  1788. else
  1789. TEST_PASS("XChacha test passed!\n");
  1790. #endif
  1791. #ifdef HAVE_POLY1305
  1792. if ( (ret = poly1305_test()) != 0)
  1793. TEST_FAIL("POLY1305 test failed!\n", ret);
  1794. else
  1795. TEST_PASS("POLY1305 test passed!\n");
  1796. #endif
  1797. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  1798. if ( (ret = chacha20_poly1305_aead_test()) != 0)
  1799. TEST_FAIL("ChaCha20-Poly1305 AEAD test failed!\n", ret);
  1800. else
  1801. TEST_PASS("ChaCha20-Poly1305 AEAD test passed!\n");
  1802. #endif
  1803. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  1804. if ( (ret = XChaCha20Poly1305_test()) != 0)
  1805. TEST_FAIL("XChaCha20-Poly1305 AEAD test failed!\n", ret);
  1806. else
  1807. TEST_PASS("XChaCha20-Poly1305 AEAD test passed!\n");
  1808. #endif
  1809. #ifndef NO_DES3
  1810. if ( (ret = des_test()) != 0)
  1811. TEST_FAIL("DES test failed!\n", ret);
  1812. else
  1813. TEST_PASS("DES test passed!\n");
  1814. #endif
  1815. #ifndef NO_DES3
  1816. if ( (ret = des3_test()) != 0)
  1817. TEST_FAIL("DES3 test failed!\n", ret);
  1818. else
  1819. TEST_PASS("DES3 test passed!\n");
  1820. #endif
  1821. #ifndef NO_AES
  1822. /* key sizes, ECB and Direct tests */
  1823. if ( (ret = aes_test()) != 0)
  1824. TEST_FAIL("AES test failed!\n", ret);
  1825. else
  1826. TEST_PASS("AES test passed!\n");
  1827. #if defined(WOLFSSL_AES_192) && \
  1828. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1829. if ( (ret = aes192_test()) != 0)
  1830. TEST_FAIL("AES192 test failed!\n", ret);
  1831. else
  1832. TEST_PASS("AES192 test passed!\n");
  1833. #endif
  1834. #if defined(WOLFSSL_AES_256)
  1835. if ( (ret = aes256_test()) != 0)
  1836. TEST_FAIL("AES256 test failed!\n", ret);
  1837. else
  1838. TEST_PASS("AES256 test passed!\n");
  1839. #endif
  1840. #ifdef HAVE_AES_CBC
  1841. if ( (ret = aes_cbc_test()) != 0)
  1842. TEST_FAIL("AES-CBC test failed!\n", ret);
  1843. else
  1844. TEST_PASS("AES-CBC test passed!\n");
  1845. #endif
  1846. #ifdef WOLFSSL_AES_COUNTER
  1847. if ( (ret = aes_ctr_test()) != 0)
  1848. TEST_FAIL("AES-CTR test failed!\n", ret);
  1849. else
  1850. TEST_PASS("AES-CTR test passed!\n");
  1851. #endif
  1852. #ifdef WOLFSSL_AES_OFB
  1853. if ( (ret = aesofb_test()) != 0)
  1854. TEST_FAIL("AES-OFB test failed!\n", ret);
  1855. else
  1856. TEST_PASS("AES-OFB test passed!\n");
  1857. #endif
  1858. #ifdef HAVE_AESGCM
  1859. #if !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO)
  1860. if ( (ret = aesgcm_test()) != 0)
  1861. TEST_FAIL("AES-GCM test failed!\n", ret);
  1862. #endif
  1863. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1864. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY) && \
  1865. !defined(WOLFSSL_KCAPI_AES) && !(defined(WOLF_CRYPTO_CB) && \
  1866. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  1867. if ((ret = aesgcm_default_test()) != 0) {
  1868. TEST_FAIL("AES-GCM test failed!\n", ret);
  1869. }
  1870. #endif
  1871. if (ret == 0) {
  1872. TEST_PASS("AES-GCM test passed!\n");
  1873. }
  1874. #endif
  1875. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  1876. if ( (ret = aesccm_test()) != 0)
  1877. TEST_FAIL("AES-CCM test failed!\n", ret);
  1878. else
  1879. TEST_PASS("AES-CCM test passed!\n");
  1880. #endif
  1881. #ifdef WOLFSSL_AES_CFB
  1882. if ( (ret = aes_cfb_test()) != 0)
  1883. TEST_FAIL("AES-CFB test failed!\n", ret);
  1884. else
  1885. TEST_PASS("AES-CFB test passed!\n");
  1886. #endif
  1887. #ifdef WOLFSSL_AES_XTS
  1888. if ( (ret = aes_xts_test()) != 0)
  1889. TEST_FAIL("AES-XTS test failed!\n", ret);
  1890. else
  1891. TEST_PASS("AES-XTS test passed!\n");
  1892. #endif
  1893. #ifdef HAVE_AES_KEYWRAP
  1894. if ( (ret = aeskeywrap_test()) != 0)
  1895. TEST_FAIL("AES Key Wrap test failed!\n", ret);
  1896. else
  1897. TEST_PASS("AES Key Wrap test passed!\n");
  1898. #endif
  1899. #ifdef WOLFSSL_AES_SIV
  1900. if ( (ret = aes_siv_test()) != 0)
  1901. TEST_FAIL("AES-SIV test failed!\n", ret);
  1902. else
  1903. TEST_PASS("AES-SIV test passed!\n");
  1904. #endif
  1905. #endif /* !NO_AES */
  1906. #if defined(WOLFSSL_AES_EAX) && \
  1907. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1908. if ( (ret = aes_eax_test()) != 0)
  1909. TEST_FAIL("AES-EAX test failed!\n", ret);
  1910. else
  1911. TEST_PASS("AES-EAX test passed!\n");
  1912. #endif /* WOLFSSL_AES_EAX */
  1913. #ifdef HAVE_ARIA
  1914. if ( (ret = ariagcm_test(MC_ALGID_ARIA_128BITKEY)) != 0)
  1915. TEST_FAIL("ARIA128 test failed!\n", ret);
  1916. else
  1917. TEST_PASS("ARIA128 test passed!\n");
  1918. if ( (ret = ariagcm_test(MC_ALGID_ARIA_192BITKEY)) != 0)
  1919. TEST_FAIL("ARIA192 test failed!\n", ret);
  1920. else
  1921. TEST_PASS("ARIA192 test passed!\n");
  1922. if ( (ret = ariagcm_test(MC_ALGID_ARIA_256BITKEY)) != 0)
  1923. TEST_FAIL("ARIA256 test failed!\n", ret);
  1924. else
  1925. TEST_PASS("ARIA256 test passed!\n");
  1926. #endif
  1927. #ifdef HAVE_CAMELLIA
  1928. if ( (ret = camellia_test()) != 0)
  1929. TEST_FAIL("CAMELLIA test failed!\n", ret);
  1930. else
  1931. TEST_PASS("CAMELLIA test passed!\n");
  1932. #endif
  1933. #ifdef WOLFSSL_SM4
  1934. if ( (ret = sm4_test()) != 0)
  1935. return err_sys("SM-4 test failed!\n", ret);
  1936. else
  1937. TEST_PASS("SM-4 test passed!\n");
  1938. #endif
  1939. #if !defined(NO_RSA) && !defined(HAVE_RENESAS_SYNC)
  1940. #ifdef WC_RSA_NO_PADDING
  1941. if ( (ret = rsa_no_pad_test()) != 0)
  1942. TEST_FAIL("RSA NOPAD test failed!\n", ret);
  1943. else
  1944. TEST_PASS("RSA NOPAD test passed!\n");
  1945. #endif
  1946. if ( (ret = rsa_test()) != 0)
  1947. TEST_FAIL("RSA test failed!\n", ret);
  1948. else
  1949. TEST_PASS("RSA test passed!\n");
  1950. #endif
  1951. #ifndef NO_DH
  1952. PRIVATE_KEY_UNLOCK();
  1953. if ( (ret = dh_test()) != 0)
  1954. TEST_FAIL("DH test failed!\n", ret);
  1955. else
  1956. TEST_PASS("DH test passed!\n");
  1957. PRIVATE_KEY_LOCK();
  1958. #endif
  1959. #ifndef NO_DSA
  1960. if ( (ret = dsa_test()) != 0)
  1961. TEST_FAIL("DSA test failed!\n", ret);
  1962. else
  1963. TEST_PASS("DSA test passed!\n");
  1964. #endif
  1965. #ifdef WOLFCRYPT_HAVE_SRP
  1966. if ( (ret = srp_test()) != 0)
  1967. TEST_FAIL("SRP test failed!\n", ret);
  1968. else
  1969. TEST_PASS("SRP test passed!\n");
  1970. #endif
  1971. #ifndef NO_PWDBASED
  1972. PRIVATE_KEY_UNLOCK();
  1973. if ( (ret = pwdbased_test()) != 0)
  1974. TEST_FAIL("PWDBASED test failed!\n", ret);
  1975. else
  1976. TEST_PASS("PWDBASED test passed!\n");
  1977. PRIVATE_KEY_LOCK();
  1978. #endif
  1979. #if defined(USE_CERT_BUFFERS_2048) && \
  1980. defined(HAVE_PKCS12) && \
  1981. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  1982. !defined(NO_CERTS) && !defined(NO_DES3)
  1983. if ( (ret = pkcs12_test()) != 0)
  1984. TEST_FAIL("PKCS12 test failed!\n", ret);
  1985. else
  1986. TEST_PASS("PKCS12 test passed!\n");
  1987. #endif
  1988. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  1989. if ( (ret = openssl_test()) != 0)
  1990. TEST_FAIL("OPENSSL test failed!\n", ret);
  1991. else
  1992. TEST_PASS("OPENSSL test passed!\n");
  1993. if ( (ret = openSSL_evpMD_test()) != 0)
  1994. TEST_FAIL("OPENSSL (EVP MD) test failed!\n", ret);
  1995. else
  1996. TEST_PASS("OPENSSL (EVP MD) passed!\n");
  1997. if ( (ret = openssl_pkey0_test()) != 0)
  1998. TEST_FAIL("OPENSSL (PKEY0) test failed!\n", ret);
  1999. else
  2000. TEST_PASS("OPENSSL (PKEY0) passed!\n");
  2001. if ( (ret = openssl_pkey1_test()) != 0)
  2002. TEST_FAIL("OPENSSL (PKEY1) test failed!\n", ret);
  2003. else
  2004. TEST_PASS("OPENSSL (PKEY1) passed!\n");
  2005. #if !defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  2006. if ( (ret = openssl_evpSig_test()) != 0)
  2007. TEST_FAIL("OPENSSL (EVP Sign/Verify) test failed!\n", ret);
  2008. else
  2009. TEST_PASS("OPENSSL (EVP Sign/Verify) passed!\n");
  2010. #endif
  2011. #endif
  2012. #if defined(HAVE_ECC)
  2013. PRIVATE_KEY_UNLOCK();
  2014. if ( (ret = ecc_test()) != 0)
  2015. TEST_FAIL("ECC test failed!\n", ret);
  2016. else
  2017. TEST_PASS("ECC test passed!\n");
  2018. PRIVATE_KEY_LOCK();
  2019. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  2020. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  2021. if ( (ret = ecc_encrypt_test()) != 0)
  2022. TEST_FAIL("ECC Enc test failed!\n", ret);
  2023. else
  2024. TEST_PASS("ECC Enc test passed!\n");
  2025. #endif
  2026. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  2027. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  2028. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  2029. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  2030. /* skip for ATECC508/608A, cannot import private key buffers */
  2031. if ( (ret = ecc_test_buffers()) != 0)
  2032. TEST_FAIL("ECC buffer test failed!\n", ret);
  2033. else
  2034. TEST_PASS("ECC buffer test passed!\n");
  2035. #endif
  2036. #endif
  2037. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  2038. !defined(NO_FILESYSTEM)
  2039. if ( (ret = cert_test()) != 0)
  2040. TEST_FAIL("CERT test failed!\n", ret);
  2041. else
  2042. TEST_PASS("CERT test passed!\n");
  2043. #endif
  2044. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  2045. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  2046. if ( (ret = certext_test()) != 0)
  2047. TEST_FAIL("CERT EXT test failed!\n", ret);
  2048. else
  2049. TEST_PASS("CERT EXT test passed!\n");
  2050. #endif
  2051. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  2052. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  2053. if ( (ret = decodedCertCache_test()) != 0)
  2054. TEST_FAIL("DECODED CERT CACHE test failed!\n", ret);
  2055. else
  2056. TEST_PASS("DECODED CERT CACHE test passed!\n");
  2057. #endif
  2058. #ifdef HAVE_CURVE25519
  2059. if ( (ret = curve25519_test()) != 0)
  2060. TEST_FAIL("CURVE25519 test failed!\n", ret);
  2061. else
  2062. TEST_PASS("CURVE25519 test passed!\n");
  2063. #endif
  2064. #ifdef HAVE_ED25519
  2065. PRIVATE_KEY_UNLOCK();
  2066. if ( (ret = ed25519_test()) != 0)
  2067. TEST_FAIL("ED25519 test failed!\n", ret);
  2068. else
  2069. TEST_PASS("ED25519 test passed!\n");
  2070. PRIVATE_KEY_LOCK();
  2071. #endif
  2072. #ifdef HAVE_CURVE448
  2073. if ( (ret = curve448_test()) != 0)
  2074. TEST_FAIL("CURVE448 test failed!\n", ret);
  2075. else
  2076. TEST_PASS("CURVE448 test passed!\n");
  2077. #endif
  2078. #ifdef HAVE_ED448
  2079. PRIVATE_KEY_UNLOCK();
  2080. if ( (ret = ed448_test()) != 0)
  2081. TEST_FAIL("ED448 test failed!\n", ret);
  2082. else
  2083. TEST_PASS("ED448 test passed!\n");
  2084. PRIVATE_KEY_LOCK();
  2085. #endif
  2086. #ifdef WOLFSSL_HAVE_KYBER
  2087. if ( (ret = kyber_test()) != 0)
  2088. TEST_FAIL("KYBER test failed!\n", ret);
  2089. else
  2090. TEST_PASS("KYBER test passed!\n");
  2091. #endif
  2092. #ifdef HAVE_DILITHIUM
  2093. if ( (ret = dilithium_test()) != 0)
  2094. TEST_FAIL("DILITHIUM test failed!\n", ret);
  2095. else
  2096. TEST_PASS("DILITHIUM test passed!\n");
  2097. #endif
  2098. #if defined(WOLFSSL_HAVE_XMSS)
  2099. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  2100. if ( (ret = xmss_test_verify_only()) != 0)
  2101. TEST_FAIL("XMSS Vfy test failed!\n", ret);
  2102. else
  2103. TEST_PASS("XMSS Vfy test passed!\n");
  2104. #endif
  2105. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  2106. if ( (ret = xmss_test()) != 0)
  2107. TEST_FAIL("XMSS test failed!\n", ret);
  2108. else
  2109. TEST_PASS("XMSS test passed!\n");
  2110. #endif
  2111. #endif /* if defined(WOLFSSL_HAVE_XMSS) */
  2112. #if defined(WOLFSSL_HAVE_LMS)
  2113. #if !defined(WOLFSSL_SMALL_STACK)
  2114. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  2115. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  2116. if ( (ret = lms_test_verify_only()) != 0)
  2117. TEST_FAIL("LMS Vfy test failed!\n", ret);
  2118. else
  2119. TEST_PASS("LMS Vfy test passed!\n");
  2120. #endif
  2121. #endif
  2122. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  2123. if ( (ret = lms_test()) != 0)
  2124. TEST_FAIL("LMS test failed!\n", ret);
  2125. else
  2126. TEST_PASS("LMS test passed!\n");
  2127. #endif
  2128. #endif /* if defined(WOLFSSL_HAVE_LMS) */
  2129. #ifdef WOLFCRYPT_HAVE_ECCSI
  2130. if ( (ret = eccsi_test()) != 0)
  2131. TEST_FAIL("ECCSI test failed!\n", ret);
  2132. else
  2133. TEST_PASS("ECCSI test passed!\n");
  2134. #endif
  2135. #ifdef WOLFCRYPT_HAVE_SAKKE
  2136. if ( (ret = sakke_test()) != 0)
  2137. TEST_FAIL("SAKKE test failed!\n", ret);
  2138. else
  2139. TEST_PASS("SAKKE test passed!\n");
  2140. #endif
  2141. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  2142. if ( (ret = cmac_test()) != 0)
  2143. TEST_FAIL("CMAC test failed!\n", ret);
  2144. else
  2145. TEST_PASS("CMAC test passed!\n");
  2146. #endif
  2147. #if defined(WOLFSSL_SIPHASH)
  2148. if ( (ret = siphash_test()) != 0)
  2149. TEST_FAIL("SipHash test failed!\n", ret);
  2150. else
  2151. TEST_PASS("SipHash test passed!\n");
  2152. #endif
  2153. #ifdef HAVE_LIBZ
  2154. if ( (ret = compress_test()) != 0)
  2155. TEST_FAIL("COMPRESS test failed!\n", ret);
  2156. else
  2157. TEST_PASS("COMPRESS test passed!\n");
  2158. #endif
  2159. #ifdef HAVE_PKCS7
  2160. #ifndef NO_PKCS7_ENCRYPTED_DATA
  2161. if ( (ret = pkcs7encrypted_test()) != 0)
  2162. TEST_FAIL("PKCS7encrypted test failed!\n", ret);
  2163. else
  2164. TEST_PASS("PKCS7encrypted test passed!\n");
  2165. #endif
  2166. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  2167. if ( (ret = pkcs7compressed_test()) != 0)
  2168. TEST_FAIL("PKCS7compressed test failed!\n", ret);
  2169. else
  2170. TEST_PASS("PKCS7compressed test passed!\n");
  2171. #endif
  2172. if ( (ret = pkcs7signed_test()) != 0)
  2173. TEST_FAIL("PKCS7signed test failed!\n", ret);
  2174. else
  2175. TEST_PASS("PKCS7signed test passed!\n");
  2176. if ( (ret = pkcs7enveloped_test()) != 0)
  2177. TEST_FAIL("PKCS7enveloped test failed!\n", ret);
  2178. else
  2179. TEST_PASS("PKCS7enveloped test passed!\n");
  2180. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  2181. if ( (ret = pkcs7authenveloped_test()) != 0)
  2182. TEST_FAIL("PKCS7authenveloped test failed!\n", ret);
  2183. else
  2184. TEST_PASS("PKCS7authenveloped test passed!\n");
  2185. #endif
  2186. #endif
  2187. #if defined(WOLFSSL_PUBLIC_MP) && \
  2188. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  2189. defined(USE_FAST_MATH))
  2190. if ( (ret = mp_test()) != 0)
  2191. TEST_FAIL("mp test failed!\n", ret);
  2192. else
  2193. TEST_PASS("mp test passed!\n");
  2194. #endif
  2195. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  2196. if ( (ret = prime_test()) != 0)
  2197. TEST_FAIL("prime test failed!\n", ret);
  2198. else
  2199. TEST_PASS("prime test passed!\n");
  2200. #endif
  2201. #if defined(ASN_BER_TO_DER) && \
  2202. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  2203. defined(OPENSSL_EXTRA_X509_SMALL))
  2204. if ( (ret = berder_test()) != 0)
  2205. TEST_FAIL("ber-der test failed!\n", ret);
  2206. else
  2207. TEST_PASS("ber-der test passed!\n");
  2208. #endif
  2209. if ( (ret = logging_test()) != 0)
  2210. TEST_FAIL("logging test failed!\n", ret);
  2211. else
  2212. TEST_PASS("logging test passed!\n");
  2213. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  2214. if ( (ret = time_test()) != 0)
  2215. TEST_FAIL("time test failed!\n", ret);
  2216. else
  2217. TEST_PASS("time test passed!\n");
  2218. #endif
  2219. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  2220. if ((ret = wolfcrypt_mutex_test()) != 0)
  2221. #else
  2222. if ((ret = mutex_test()) != 0)
  2223. #endif
  2224. TEST_FAIL("mutex test failed!\n", ret);
  2225. else
  2226. TEST_PASS("mutex test passed!\n");
  2227. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  2228. if ( (ret = memcb_test()) != 0)
  2229. TEST_FAIL("memcb test failed!\n", ret);
  2230. else
  2231. TEST_PASS("memcb test passed!\n");
  2232. #endif
  2233. #ifdef WOLFSSL_CAAM_BLOB
  2234. if ( (ret = blob_test()) != 0)
  2235. TEST_FAIL("blob test failed!\n", ret);
  2236. else
  2237. TEST_PASS("blob test passed!\n");
  2238. #endif
  2239. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST) && \
  2240. !(defined(HAVE_INTEL_QAT_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2241. defined(WOLFSSL_QNX_CAAM) || defined(HAVE_RENESAS_SYNC))
  2242. if ( (ret = cryptocb_test()) != 0)
  2243. TEST_FAIL("crypto callback test failed!\n", ret);
  2244. else
  2245. TEST_PASS("crypto callback test passed!\n");
  2246. #endif
  2247. #ifdef WOLFSSL_CERT_PIV
  2248. if ( (ret = certpiv_test()) != 0)
  2249. TEST_FAIL("cert piv test failed!\n", ret);
  2250. else
  2251. TEST_PASS("cert piv test passed!\n");
  2252. #endif
  2253. #ifdef WOLF_CRYPTO_CB
  2254. #ifdef HAVE_INTEL_QA_SYNC
  2255. wc_CryptoCb_CleanupIntelQa(&devId);
  2256. #endif
  2257. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2258. wc_CryptoCb_CleanupOcteon(&devId);
  2259. #endif
  2260. #endif
  2261. #ifdef WOLFSSL_ASYNC_CRYPT
  2262. wolfAsync_DevClose(&devId);
  2263. #endif
  2264. /* cleanup the thread if fixed point cache is enabled and have thread local */
  2265. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  2266. wc_ecc_fp_free();
  2267. #endif
  2268. #ifdef TEST_ALWAYS_RUN_TO_END
  2269. if (last_failed_test_ret != 0)
  2270. ret = last_failed_test_ret;
  2271. #endif
  2272. if (args)
  2273. ((func_args*)args)->return_code = ret;
  2274. /* If hardware acceleration and respective metrics tracked, show results: */
  2275. #ifdef WOLFSSL_HW_METRICS
  2276. #if defined(WOLFSSL_ESP32_CRYPT_RSA_PRI) && defined(WOLFSSL_HW_METRICS)
  2277. esp_hw_show_mp_metrics();
  2278. #endif
  2279. #endif
  2280. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(OPENSSL_EXTRA)
  2281. wolfSSL_SetGlobalHeapHint(NULL);
  2282. #endif
  2283. TEST_PASS("Test complete\n");
  2284. EXIT_TEST(ret);
  2285. } /* end of wolfcrypt_test() */
  2286. #ifndef NO_MAIN_DRIVER
  2287. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  2288. int myoptind = 0;
  2289. char* myoptarg = NULL;
  2290. #endif
  2291. /* so overall tests can pull in test function */
  2292. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  2293. wc_test_ret_t wolf_test_task(void)
  2294. #else
  2295. #ifndef NO_MAIN_FUNCTION
  2296. int main(int argc, char** argv)
  2297. {
  2298. return (int)wolfcrypt_test_main(argc, argv);
  2299. }
  2300. #endif
  2301. wc_test_ret_t wolfcrypt_test_main(int argc, char** argv)
  2302. #endif
  2303. {
  2304. wc_test_ret_t ret;
  2305. func_args args = { 0, 0, 0 };
  2306. #if defined(WOLFSSL_ESPIDF) || defined(WOLFSSL_SE050)
  2307. /* set dummy wallclock time. */
  2308. struct timeval utctime;
  2309. struct timezone tz;
  2310. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2311. utctime.tv_usec = 0;
  2312. tz.tz_minuteswest = 0;
  2313. tz.tz_dsttime = 0;
  2314. settimeofday(&utctime, &tz);
  2315. #endif
  2316. #ifdef WOLFSSL_APACHE_MYNEWT
  2317. #ifdef ARCH_sim
  2318. mcu_sim_parse_args(argc, argv);
  2319. #endif
  2320. sysinit();
  2321. /* set dummy wallclock time. */
  2322. struct os_timeval utctime;
  2323. struct os_timezone tz;
  2324. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2325. utctime.tv_usec = 0;
  2326. tz.tz_minuteswest = 0;
  2327. tz.tz_dsttime = 0;
  2328. os_settimeofday(&utctime, &tz);
  2329. #endif
  2330. #ifdef WOLFSSL_ZEPHYR
  2331. /* set dummy wallclock time. */
  2332. struct timespec utctime;
  2333. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2334. utctime.tv_nsec = 0;
  2335. clock_settime(CLOCK_REALTIME, &utctime);
  2336. #endif
  2337. #ifdef DEVKITPRO
  2338. void *framebuffer;
  2339. GXRModeObj *rmode = NULL;
  2340. VIDEO_Init();
  2341. WPAD_Init();
  2342. rmode = VIDEO_GetPreferredMode(NULL);
  2343. #pragma GCC diagnostic ignored "-Wbad-function-cast"
  2344. framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  2345. #pragma GCC diagnostic pop
  2346. console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  2347. VIDEO_Configure(rmode);
  2348. VIDEO_SetNextFramebuffer(framebuffer);
  2349. VIDEO_SetBlack(FALSE);
  2350. VIDEO_Flush();
  2351. VIDEO_WaitVSync();
  2352. if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  2353. #endif
  2354. #ifdef WOLFSSL_NDS
  2355. /* Init Console output */
  2356. consoleDemoInit();
  2357. /* Init the Filesystem */
  2358. fatInitDefault();
  2359. #endif
  2360. #ifdef HAVE_WNR
  2361. if ((ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000)) != 0) {
  2362. err_sys("Whitewood netRandom global config failed",
  2363. WC_TEST_RET_ENC_EC(ret));
  2364. return WC_TEST_RET_ENC_EC(ret);
  2365. }
  2366. #endif
  2367. #ifndef WOLFSSL_ESPIDF
  2368. args.argc = argc;
  2369. args.argv = argv;
  2370. #endif
  2371. if ((ret = wolfCrypt_Init()) != 0) {
  2372. printf("wolfCrypt_Init failed %d\n", (int)ret);
  2373. err_sys("Error with wolfCrypt_Init!\n", WC_TEST_RET_ENC_EC(ret));
  2374. }
  2375. #ifdef HAVE_WC_INTROSPECTION
  2376. printf("Math: %s\n", wc_GetMathInfo());
  2377. #endif
  2378. #ifdef HAVE_STACK_SIZE
  2379. StackSizeCheck(&args, wolfcrypt_test);
  2380. #else
  2381. wolfcrypt_test(&args);
  2382. #endif
  2383. if ((ret = wolfCrypt_Cleanup()) != 0) {
  2384. printf("wolfCrypt_Cleanup failed %d\n", (int)ret);
  2385. err_sys("Error with wolfCrypt_Cleanup!\n", WC_TEST_RET_ENC_EC(ret));
  2386. }
  2387. #ifdef HAVE_WNR
  2388. if ((ret = wc_FreeNetRandom()) < 0)
  2389. err_sys("Failed to free netRandom context",
  2390. WC_TEST_RET_ENC_EC(ret));
  2391. #endif /* HAVE_WNR */
  2392. #ifdef DOLPHIN_EMULATOR
  2393. /* Returning from main panics the emulator. Just hang
  2394. * and let the user force quit the emulator window. */
  2395. printf("args.return_code: %d\n", args.return_code);
  2396. printf("Testing complete. You may close the window now\n");
  2397. while (1);
  2398. #endif
  2399. #ifdef WOLFSSL_NDS
  2400. /* in Nintendo DS returning from main shuts down the Device without letting you see the Results. */
  2401. printf("args.return_code: %d\n", args.return_code);
  2402. printf("Testing complete. Press Start to exit the Program\n");
  2403. while(1) {
  2404. swiWaitForVBlank();
  2405. scanKeys();
  2406. int keys = keysDown();
  2407. if(keys & KEY_START) break;
  2408. }
  2409. #endif
  2410. #if defined(WOLFSSL_ESPIDF)
  2411. /* ESP_LOGI to print takes up a lot less memory than printf */
  2412. ESP_LOGI(ESPIDF_TAG, "Exiting main with return code: % d\n",
  2413. args.return_code);
  2414. #else
  2415. /* gate this for target platforms wishing to avoid printf reference */
  2416. printf("Exiting main with return code: %ld\n", (long int)args.return_code);
  2417. #endif
  2418. return args.return_code;
  2419. } /* wolfcrypt_test_main or wolf_test_task */
  2420. #endif /* NO_MAIN_DRIVER */
  2421. /* helper to save DER, convert to PEM and save PEM */
  2422. #if !defined(NO_ASN) && (defined(HAVE_ECC) || !defined(NO_DSA) || \
  2423. (!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) \
  2424. && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  2425. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2426. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, fD, fP, pT, WC_TEST_RET_LN)
  2427. #else
  2428. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, NULL, NULL, pT, WC_TEST_RET_LN)
  2429. #endif
  2430. static wc_test_ret_t _SaveDerAndPem(const byte* der, int derSz,
  2431. const char* fileDer, const char* filePem, int pemType, int calling_line)
  2432. {
  2433. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2434. wc_test_ret_t ret;
  2435. XFILE derFile;
  2436. derFile = XFOPEN(fileDer, "wb");
  2437. if (!derFile) {
  2438. return WC_TEST_RET_ENC(calling_line, 0, WC_TEST_RET_TAG_I);
  2439. }
  2440. ret = (int)XFWRITE(der, 1, (size_t)derSz, derFile);
  2441. XFCLOSE(derFile);
  2442. if (ret != derSz) {
  2443. return WC_TEST_RET_ENC(calling_line, 1, WC_TEST_RET_TAG_I);
  2444. }
  2445. #endif
  2446. #ifdef WOLFSSL_DER_TO_PEM
  2447. if (filePem) {
  2448. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2449. XFILE pemFile;
  2450. #endif
  2451. #ifndef WOLFSSL_NO_MALLOC
  2452. byte* pem;
  2453. #else
  2454. byte pem[2048];
  2455. #endif
  2456. int pemSz;
  2457. /* calculate PEM size */
  2458. pemSz = wc_DerToPem(der, (word32)derSz, NULL, 0, pemType);
  2459. if (pemSz < 0) {
  2460. return WC_TEST_RET_ENC(calling_line, 2, WC_TEST_RET_TAG_I);
  2461. }
  2462. #ifndef WOLFSSL_NO_MALLOC
  2463. pem = (byte*)XMALLOC((word32)pemSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2464. if (pem == NULL) {
  2465. return WC_TEST_RET_ENC(calling_line, 3, WC_TEST_RET_TAG_I);
  2466. }
  2467. #else
  2468. if (pemSz > (int)sizeof(pem))
  2469. return WC_TEST_RET_ENC_EC(BAD_FUNC_ARG);
  2470. #endif
  2471. /* Convert to PEM */
  2472. pemSz = wc_DerToPem(der, (word32)derSz, pem, (word32)pemSz, pemType);
  2473. if (pemSz < 0) {
  2474. #ifndef WOLFSSL_NO_MALLOC
  2475. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2476. #endif
  2477. return WC_TEST_RET_ENC(calling_line, 4, WC_TEST_RET_TAG_I);
  2478. }
  2479. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2480. pemFile = XFOPEN(filePem, "wb");
  2481. if (!pemFile) {
  2482. #ifndef WOLFSSL_NO_MALLOC
  2483. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2484. #endif
  2485. return WC_TEST_RET_ENC(calling_line, 5, WC_TEST_RET_TAG_I);
  2486. }
  2487. ret = (int)XFWRITE(pem, 1, (size_t)pemSz, pemFile);
  2488. XFCLOSE(pemFile);
  2489. if (ret != pemSz) {
  2490. #ifndef WOLFSSL_NO_MALLOC
  2491. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2492. #endif
  2493. return WC_TEST_RET_ENC(calling_line, 6, WC_TEST_RET_TAG_I);
  2494. }
  2495. #endif
  2496. #ifndef WOLFSSL_NO_MALLOC
  2497. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2498. #endif
  2499. }
  2500. #endif /* WOLFSSL_DER_TO_PEM */
  2501. /* suppress unused variable warnings */
  2502. (void)der;
  2503. (void)derSz;
  2504. (void)filePem;
  2505. (void)fileDer;
  2506. (void)pemType;
  2507. (void)calling_line;
  2508. return 0;
  2509. }
  2510. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  2511. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void)
  2512. {
  2513. const char* errStr;
  2514. char out[WOLFSSL_MAX_ERROR_SZ];
  2515. const char* unknownStr = wc_GetErrorString(0);
  2516. #ifdef NO_ERROR_STRINGS
  2517. /* Ensure a valid error code's string matches an invalid code's.
  2518. * The string is that error strings are not available.
  2519. */
  2520. WOLFSSL_ENTER("error_test NO_ERROR_STRINGS");
  2521. errStr = wc_GetErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E));
  2522. wc_ErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E), out);
  2523. if (XSTRCMP(errStr, unknownStr) != 0)
  2524. return WC_TEST_RET_ENC_NC;
  2525. if (XSTRCMP(out, unknownStr) != 0)
  2526. return WC_TEST_RET_ENC_NC;
  2527. #else
  2528. int i;
  2529. int j = 0;
  2530. /* Values that are not or no longer error codes. */
  2531. static const struct {
  2532. int first;
  2533. int last;
  2534. } missing[] = {
  2535. { -124, -124 },
  2536. { -166, -169 },
  2537. { WC_SPAN1_LAST_E - 1, WC_SPAN2_FIRST_E + 1 },
  2538. { WC_SPAN2_LAST_E - 1, WC_SPAN2_MIN_CODE_E }
  2539. };
  2540. /* Check that all errors have a string and it's the same through the two
  2541. * APIs. Check that the values that are not errors map to the unknown
  2542. * string.
  2543. */
  2544. for (i = WC_SPAN1_FIRST_E; i >= WC_SPAN2_MIN_CODE_E; i--) {
  2545. int this_missing = 0;
  2546. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  2547. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  2548. this_missing = 1;
  2549. break;
  2550. }
  2551. }
  2552. errStr = wc_GetErrorString(i);
  2553. wc_ErrorString(i, out);
  2554. if (! this_missing) {
  2555. if (XSTRCMP(errStr, unknownStr) == 0) {
  2556. WOLFSSL_MSG("errStr unknown");
  2557. return WC_TEST_RET_ENC_I(-i);
  2558. }
  2559. if (XSTRCMP(out, unknownStr) == 0) {
  2560. WOLFSSL_MSG("out unknown");
  2561. return WC_TEST_RET_ENC_I(-i);
  2562. }
  2563. if (XSTRCMP(errStr, out) != 0) {
  2564. WOLFSSL_MSG("errStr does not match output");
  2565. return WC_TEST_RET_ENC_I(-i);
  2566. }
  2567. if (XSTRLEN(errStr) >= WOLFSSL_MAX_ERROR_SZ) {
  2568. WOLFSSL_MSG("errStr too long");
  2569. return WC_TEST_RET_ENC_I(-i);
  2570. }
  2571. }
  2572. else {
  2573. j++;
  2574. if (XSTRCMP(errStr, unknownStr) != 0)
  2575. return WC_TEST_RET_ENC_I(-i);
  2576. if (XSTRCMP(out, unknownStr) != 0)
  2577. return WC_TEST_RET_ENC_I(-i);
  2578. }
  2579. }
  2580. /* Check if the next possible value has been given a string. */
  2581. errStr = wc_GetErrorString(i);
  2582. wc_ErrorString(i, out);
  2583. if (XSTRCMP(errStr, unknownStr) != 0)
  2584. return WC_TEST_RET_ENC_NC;
  2585. if (XSTRCMP(out, unknownStr) != 0)
  2586. return WC_TEST_RET_ENC_NC;
  2587. #endif
  2588. return 0;
  2589. }
  2590. #ifndef NO_CODING
  2591. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void)
  2592. {
  2593. wc_test_ret_t ret;
  2594. WOLFSSL_SMALL_STACK_STATIC const byte good[] = "A+Gd\0\0\0";
  2595. WOLFSSL_SMALL_STACK_STATIC const byte goodEnd[] = "A+Gd \r\n";
  2596. WOLFSSL_SMALL_STACK_STATIC const byte good_spaces[] = " A + G d \0";
  2597. byte out[128];
  2598. word32 outLen;
  2599. #ifdef WOLFSSL_BASE64_ENCODE
  2600. byte data[3];
  2601. word32 dataLen;
  2602. byte longData[79] = { 0 };
  2603. WOLFSSL_SMALL_STACK_STATIC const byte symbols[] = "+/A=";
  2604. #endif
  2605. WOLFSSL_SMALL_STACK_STATIC const byte badSmall[] = "AAA!Gdj=";
  2606. WOLFSSL_SMALL_STACK_STATIC const byte badLarge[] = "AAA~Gdj=";
  2607. WOLFSSL_SMALL_STACK_STATIC const byte badEOL[] = "A+Gd!AA";
  2608. WOLFSSL_SMALL_STACK_STATIC const byte badPadding[] = "AA=A";
  2609. WOLFSSL_SMALL_STACK_STATIC const byte badChar[] = ",-.:;<=>?@[\\]^_`";
  2610. byte goodChar[] =
  2611. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2612. "abcdefghijklmnopqrstuvwxyz"
  2613. "0123456789+/;";
  2614. byte charTest[] = "A+Gd\0\0\0";
  2615. int i;
  2616. WOLFSSL_ENTER("base64_test");
  2617. /* Good Base64 encodings. */
  2618. outLen = sizeof(out);
  2619. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2620. if (ret != 0)
  2621. return WC_TEST_RET_ENC_EC(ret);
  2622. outLen = sizeof(out);
  2623. ret = Base64_Decode(goodEnd, sizeof(goodEnd), out, &outLen);
  2624. if (ret != 0)
  2625. return WC_TEST_RET_ENC_EC(ret);
  2626. outLen = sizeof(goodChar);
  2627. ret = Base64_Decode(goodChar, sizeof(goodChar), goodChar, &outLen);
  2628. if (ret != 0)
  2629. return WC_TEST_RET_ENC_EC(ret);
  2630. if (outLen != 64 / 4 * 3)
  2631. return WC_TEST_RET_ENC_NC;
  2632. outLen = sizeof(out);
  2633. ret = Base64_Decode(good_spaces, sizeof(good_spaces), out, &outLen);
  2634. if (ret != 0)
  2635. return WC_TEST_RET_ENC_EC(ret);
  2636. /* Bad parameters. */
  2637. outLen = 1;
  2638. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2639. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2640. return WC_TEST_RET_ENC_EC(ret);
  2641. outLen = sizeof(out);
  2642. ret = Base64_Decode(badEOL, sizeof(badEOL), out, &outLen);
  2643. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2644. return WC_TEST_RET_ENC_EC(ret);
  2645. outLen = sizeof(out);
  2646. ret = Base64_Decode(badPadding, sizeof(badPadding), out, &outLen);
  2647. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2648. return WC_TEST_RET_ENC_EC(ret);
  2649. /* Bad character at each offset 0-3. */
  2650. for (i = 0; i < 4; i++) {
  2651. outLen = sizeof(out);
  2652. ret = Base64_Decode(badSmall + i, 4, out, &outLen);
  2653. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2654. return WC_TEST_RET_ENC_I(i);
  2655. ret = Base64_Decode(badLarge + i, 4, out, &outLen);
  2656. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2657. return WC_TEST_RET_ENC_I(i);
  2658. }
  2659. /* Invalid character less than 0x2b */
  2660. for (i = 1; i < 0x2b; i++) {
  2661. outLen = sizeof(out);
  2662. charTest[0] = (byte)i;
  2663. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2664. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2665. return WC_TEST_RET_ENC_I(i);
  2666. }
  2667. /* Bad characters in range 0x2b - 0x7a. */
  2668. for (i = 0; i < (int)sizeof(badChar) - 1; i++) {
  2669. outLen = sizeof(out);
  2670. charTest[0] = badChar[i];
  2671. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2672. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2673. return WC_TEST_RET_ENC_I(i);
  2674. }
  2675. /* Invalid character greater than 0x7a */
  2676. for (i = 0x7b; i < 0x100; i++) {
  2677. outLen = sizeof(out);
  2678. charTest[0] = (byte)i;
  2679. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2680. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2681. return WC_TEST_RET_ENC_I(i);
  2682. }
  2683. #ifdef WOLFSSL_BASE64_ENCODE
  2684. /* Decode and encode all symbols - non-alphanumeric. */
  2685. dataLen = sizeof(data);
  2686. ret = Base64_Decode(symbols, sizeof(symbols), data, &dataLen);
  2687. if (ret != 0)
  2688. return WC_TEST_RET_ENC_EC(ret);
  2689. outLen = sizeof(out);
  2690. ret = Base64_Encode(data, dataLen, NULL, &outLen);
  2691. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2692. return WC_TEST_RET_ENC_EC(ret);
  2693. outLen = sizeof(out);
  2694. ret = Base64_Encode(data, dataLen, out, &outLen);
  2695. if (ret != 0)
  2696. return WC_TEST_RET_ENC_EC(ret);
  2697. outLen = 7;
  2698. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2699. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  2700. return WC_TEST_RET_ENC_EC(ret);
  2701. outLen = sizeof(out);
  2702. ret = Base64_EncodeEsc(data, dataLen, NULL, &outLen);
  2703. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2704. return WC_TEST_RET_ENC_EC(ret);
  2705. outLen = sizeof(out);
  2706. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2707. if (ret != 0)
  2708. return WC_TEST_RET_ENC_EC(ret);
  2709. outLen = sizeof(out);
  2710. ret = Base64_Encode_NoNl(data, dataLen, out, &outLen);
  2711. if (ret != 0)
  2712. return WC_TEST_RET_ENC_EC(ret);
  2713. /* Data that results in an encoding longer than one line. */
  2714. outLen = sizeof(out);
  2715. dataLen = sizeof(longData);
  2716. ret = Base64_Encode(longData, dataLen, out, &outLen);
  2717. if (ret != 0)
  2718. return WC_TEST_RET_ENC_EC(ret);
  2719. outLen = sizeof(out);
  2720. ret = Base64_EncodeEsc(longData, dataLen, out, &outLen);
  2721. if (ret != 0)
  2722. return WC_TEST_RET_ENC_EC(ret);
  2723. outLen = sizeof(out);
  2724. ret = Base64_Encode_NoNl(longData, dataLen, out, &outLen);
  2725. if (ret != 0)
  2726. return WC_TEST_RET_ENC_EC(ret);
  2727. #endif
  2728. return 0;
  2729. }
  2730. #ifdef WOLFSSL_BASE16
  2731. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void)
  2732. {
  2733. wc_test_ret_t ret;
  2734. WOLFSSL_SMALL_STACK_STATIC const byte testData[] = "SomeDataToEncode\n";
  2735. WOLFSSL_SMALL_STACK_STATIC const byte encodedTestData[] = "536F6D6544617461546F456E636F64650A00";
  2736. byte encoded[40];
  2737. word32 encodedLen;
  2738. byte plain[40];
  2739. word32 len;
  2740. WOLFSSL_ENTER("base16_test");
  2741. /* length returned includes null termination */
  2742. encodedLen = sizeof(encoded);
  2743. ret = Base16_Encode(testData, sizeof(testData), encoded, &encodedLen);
  2744. if (ret != 0)
  2745. return WC_TEST_RET_ENC_EC(ret);
  2746. len = (word32)XSTRLEN((char*)encoded);
  2747. if (len != encodedLen - 1)
  2748. return WC_TEST_RET_ENC_NC;
  2749. len = sizeof(plain);
  2750. ret = Base16_Decode(encoded, encodedLen - 1, plain, &len);
  2751. if (ret != 0)
  2752. return WC_TEST_RET_ENC_EC(ret);
  2753. if (len != sizeof(testData) || XMEMCMP(testData, plain, len) != 0)
  2754. return WC_TEST_RET_ENC_NC;
  2755. if (encodedLen != sizeof(encodedTestData) ||
  2756. XMEMCMP(encoded, encodedTestData, encodedLen) != 0) {
  2757. return WC_TEST_RET_ENC_NC;
  2758. }
  2759. return 0;
  2760. }
  2761. #endif /* WOLFSSL_BASE16 */
  2762. #endif /* !NO_CODING */
  2763. #ifndef NO_ASN
  2764. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void)
  2765. {
  2766. wc_test_ret_t ret;
  2767. /* ASN1 encoded date buffer */
  2768. WOLFSSL_SMALL_STACK_STATIC const byte dateBuf[] = {
  2769. 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x31,
  2770. 0x32, 0x30, 0x30, 0x37, 0x33, 0x37, 0x5a
  2771. };
  2772. byte format;
  2773. int length;
  2774. const byte* datePart;
  2775. #ifndef NO_ASN_TIME
  2776. struct tm timearg;
  2777. time_t now;
  2778. #endif
  2779. WOLFSSL_ENTER("asn_test");
  2780. ret = wc_GetDateInfo(dateBuf, (int)sizeof(dateBuf), &datePart, &format,
  2781. &length);
  2782. if (ret != 0)
  2783. return WC_TEST_RET_ENC_EC(ret);
  2784. #ifndef NO_ASN_TIME
  2785. /* Parameter Validation tests. */
  2786. if ((ret = wc_GetTime(NULL, sizeof(now))) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2787. return WC_TEST_RET_ENC_EC(ret);
  2788. if ((ret = wc_GetTime(&now, 0)) != WC_NO_ERR_TRACE(BUFFER_E))
  2789. return WC_TEST_RET_ENC_EC(ret);
  2790. now = 0;
  2791. if ((ret = wc_GetTime(&now, sizeof(now))) != 0) {
  2792. return WC_TEST_RET_ENC_EC(ret);
  2793. }
  2794. if (now == 0) {
  2795. printf("RTC/Time not set!\n");
  2796. return WC_TEST_RET_ENC_NC;
  2797. }
  2798. ret = wc_GetDateAsCalendarTime(datePart, length, format, &timearg);
  2799. if (ret != 0)
  2800. return WC_TEST_RET_ENC_EC(ret);
  2801. #endif /* !NO_ASN_TIME */
  2802. return 0;
  2803. }
  2804. #endif /* !NO_ASN */
  2805. #ifdef WOLFSSL_MD2
  2806. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void)
  2807. {
  2808. wc_test_ret_t ret = 0;
  2809. Md2 md2;
  2810. byte hash[MD2_DIGEST_SIZE];
  2811. testVector a, b, c, d, e, f, g;
  2812. testVector test_md2[7];
  2813. int times = sizeof(test_md2) / sizeof(testVector), i;
  2814. WOLFSSL_ENTER("md2_test");
  2815. a.input = "";
  2816. a.output = "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69"
  2817. "\x27\x73";
  2818. a.inLen = XSTRLEN(a.input);
  2819. a.outLen = MD2_DIGEST_SIZE;
  2820. b.input = "a";
  2821. b.output = "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0"
  2822. "\xb5\xd1";
  2823. b.inLen = XSTRLEN(b.input);
  2824. b.outLen = MD2_DIGEST_SIZE;
  2825. c.input = "abc";
  2826. c.output = "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde"
  2827. "\xd6\xbb";
  2828. c.inLen = XSTRLEN(c.input);
  2829. c.outLen = MD2_DIGEST_SIZE;
  2830. d.input = "message digest";
  2831. d.output = "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe"
  2832. "\x06\xb0";
  2833. d.inLen = XSTRLEN(d.input);
  2834. d.outLen = MD2_DIGEST_SIZE;
  2835. e.input = "abcdefghijklmnopqrstuvwxyz";
  2836. e.output = "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47"
  2837. "\x94\x0b";
  2838. e.inLen = XSTRLEN(e.input);
  2839. e.outLen = MD2_DIGEST_SIZE;
  2840. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2841. "6789";
  2842. f.output = "\xda\x33\xde\xf2\xa4\x2d\xf1\x39\x75\x35\x28\x46\xc3\x03"
  2843. "\x38\xcd";
  2844. f.inLen = XSTRLEN(f.input);
  2845. f.outLen = MD2_DIGEST_SIZE;
  2846. g.input = "1234567890123456789012345678901234567890123456789012345678"
  2847. "9012345678901234567890";
  2848. g.output = "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3"
  2849. "\xef\xd8";
  2850. g.inLen = XSTRLEN(g.input);
  2851. g.outLen = MD2_DIGEST_SIZE;
  2852. test_md2[0] = a;
  2853. test_md2[1] = b;
  2854. test_md2[2] = c;
  2855. test_md2[3] = d;
  2856. test_md2[4] = e;
  2857. test_md2[5] = f;
  2858. test_md2[6] = g;
  2859. wc_InitMd2(&md2);
  2860. for (i = 0; i < times; ++i) {
  2861. wc_Md2Update(&md2, (byte*)test_md2[i].input, (word32)test_md2[i].inLen);
  2862. wc_Md2Final(&md2, hash);
  2863. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0)
  2864. return WC_TEST_RET_ENC_I(i);
  2865. }
  2866. for (i = 0; i < times; ++i) {
  2867. ret = wc_Md2Hash((byte*)test_md2[i].input, (word32)test_md2[i].inLen, hash);
  2868. if (ret != 0) {
  2869. return WC_TEST_RET_ENC_I(i);
  2870. }
  2871. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) {
  2872. return WC_TEST_RET_ENC_I(i);
  2873. }
  2874. }
  2875. return 0;
  2876. }
  2877. #endif
  2878. #ifndef NO_MD5
  2879. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void)
  2880. {
  2881. wc_test_ret_t ret = 0;
  2882. wc_Md5 md5, md5Copy;
  2883. byte hash[WC_MD5_DIGEST_SIZE];
  2884. byte hashcopy[WC_MD5_DIGEST_SIZE];
  2885. testVector a, b, c, d, e, f;
  2886. testVector test_md5[6];
  2887. int times = sizeof(test_md5) / sizeof(testVector), i;
  2888. WOLFSSL_ENTER("md5_test");
  2889. a.input = "";
  2890. a.output = "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42"
  2891. "\x7e";
  2892. a.inLen = XSTRLEN(a.input);
  2893. a.outLen = WC_MD5_DIGEST_SIZE;
  2894. b.input = "abc";
  2895. b.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  2896. "\x72";
  2897. b.inLen = XSTRLEN(b.input);
  2898. b.outLen = WC_MD5_DIGEST_SIZE;
  2899. c.input = "message digest";
  2900. c.output = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
  2901. "\xd0";
  2902. c.inLen = XSTRLEN(c.input);
  2903. c.outLen = WC_MD5_DIGEST_SIZE;
  2904. d.input = "abcdefghijklmnopqrstuvwxyz";
  2905. d.output = "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
  2906. "\x3b";
  2907. d.inLen = XSTRLEN(d.input);
  2908. d.outLen = WC_MD5_DIGEST_SIZE;
  2909. e.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2910. "6789";
  2911. e.output = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
  2912. "\x9f";
  2913. e.inLen = XSTRLEN(e.input);
  2914. e.outLen = WC_MD5_DIGEST_SIZE;
  2915. f.input = "1234567890123456789012345678901234567890123456789012345678"
  2916. "9012345678901234567890";
  2917. f.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  2918. "\x7a";
  2919. f.inLen = XSTRLEN(f.input);
  2920. f.outLen = WC_MD5_DIGEST_SIZE;
  2921. test_md5[0] = a;
  2922. test_md5[1] = b;
  2923. test_md5[2] = c;
  2924. test_md5[3] = d;
  2925. test_md5[4] = e;
  2926. test_md5[5] = f;
  2927. ret = wc_InitMd5_ex(&md5, HEAP_HINT, devId);
  2928. if (ret != 0)
  2929. return WC_TEST_RET_ENC_EC(ret);
  2930. ret = wc_InitMd5_ex(&md5Copy, HEAP_HINT, devId);
  2931. if (ret != 0) {
  2932. wc_Md5Free(&md5);
  2933. return WC_TEST_RET_ENC_EC(ret);
  2934. }
  2935. for (i = 0; i < times; ++i) {
  2936. ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
  2937. (word32)test_md5[i].inLen);
  2938. if (ret != 0)
  2939. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2940. ret = wc_Md5GetHash(&md5, hashcopy);
  2941. if (ret != 0)
  2942. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2943. ret = wc_Md5Copy(&md5, &md5Copy);
  2944. if (ret != 0)
  2945. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2946. ret = wc_Md5Final(&md5, hash);
  2947. if (ret != 0)
  2948. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2949. wc_Md5Free(&md5Copy);
  2950. if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0)
  2951. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2952. if (XMEMCMP(hash, hashcopy, WC_MD5_DIGEST_SIZE) != 0)
  2953. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2954. }
  2955. #ifndef NO_LARGE_HASH_TEST
  2956. /* BEGIN LARGE HASH TEST */ {
  2957. byte large_input[1024];
  2958. const char* large_digest =
  2959. "\x44\xd0\x88\xce\xf1\x36\xd1\x78\xe9\xc8\xba\x84\xc3\xfd\xf6\xca";
  2960. for (i = 0; i < (int)sizeof(large_input); i++) {
  2961. large_input[i] = (byte)(i & 0xFF);
  2962. }
  2963. times = 100;
  2964. #ifdef WOLFSSL_PIC32MZ_HASH
  2965. wc_Md5SizeSet(&md5, times * sizeof(large_input));
  2966. #endif
  2967. for (i = 0; i < times; ++i) {
  2968. ret = wc_Md5Update(&md5, (byte*)large_input,
  2969. (word32)sizeof(large_input));
  2970. if (ret != 0)
  2971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2972. }
  2973. ret = wc_Md5Final(&md5, hash);
  2974. if (ret != 0)
  2975. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2976. if (XMEMCMP(hash, large_digest, WC_MD5_DIGEST_SIZE) != 0)
  2977. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  2978. } /* END LARGE HASH TEST */
  2979. #endif /* NO_LARGE_HASH_TEST */
  2980. exit:
  2981. wc_Md5Free(&md5);
  2982. wc_Md5Free(&md5Copy);
  2983. return ret;
  2984. }
  2985. #endif /* NO_MD5 */
  2986. #ifndef NO_MD4
  2987. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void)
  2988. {
  2989. Md4 md4;
  2990. byte hash[MD4_DIGEST_SIZE];
  2991. testVector a, b, c, d, e, f, g;
  2992. testVector test_md4[7];
  2993. int times = sizeof(test_md4) / sizeof(testVector), i;
  2994. WOLFSSL_ENTER("md4_test");
  2995. a.input = "";
  2996. a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
  2997. "\xc0";
  2998. a.inLen = XSTRLEN(a.input);
  2999. a.outLen = MD4_DIGEST_SIZE;
  3000. b.input = "a";
  3001. b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
  3002. "\x24";
  3003. b.inLen = XSTRLEN(b.input);
  3004. b.outLen = MD4_DIGEST_SIZE;
  3005. c.input = "abc";
  3006. c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
  3007. "\x9d";
  3008. c.inLen = XSTRLEN(c.input);
  3009. c.outLen = MD4_DIGEST_SIZE;
  3010. d.input = "message digest";
  3011. d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
  3012. "\x4b";
  3013. d.inLen = XSTRLEN(d.input);
  3014. d.outLen = MD4_DIGEST_SIZE;
  3015. e.input = "abcdefghijklmnopqrstuvwxyz";
  3016. e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
  3017. "\xa9";
  3018. e.inLen = XSTRLEN(e.input);
  3019. e.outLen = MD4_DIGEST_SIZE;
  3020. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  3021. "6789";
  3022. f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
  3023. "\xe4";
  3024. f.inLen = XSTRLEN(f.input);
  3025. f.outLen = MD4_DIGEST_SIZE;
  3026. g.input = "1234567890123456789012345678901234567890123456789012345678"
  3027. "9012345678901234567890";
  3028. g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
  3029. "\x36";
  3030. g.inLen = XSTRLEN(g.input);
  3031. g.outLen = MD4_DIGEST_SIZE;
  3032. test_md4[0] = a;
  3033. test_md4[1] = b;
  3034. test_md4[2] = c;
  3035. test_md4[3] = d;
  3036. test_md4[4] = e;
  3037. test_md4[5] = f;
  3038. test_md4[6] = g;
  3039. wc_InitMd4(&md4);
  3040. for (i = 0; i < times; ++i) {
  3041. wc_Md4Update(&md4, (byte*)test_md4[i].input, (word32)test_md4[i].inLen);
  3042. wc_Md4Final(&md4, hash);
  3043. if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0)
  3044. return WC_TEST_RET_ENC_I(i);
  3045. }
  3046. return 0;
  3047. }
  3048. #endif /* NO_MD4 */
  3049. #ifndef NO_SHA
  3050. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void)
  3051. {
  3052. wc_test_ret_t ret = 0;
  3053. wc_Sha sha, shaCopy;
  3054. byte hash[WC_SHA_DIGEST_SIZE];
  3055. byte hashcopy[WC_SHA_DIGEST_SIZE];
  3056. testVector a, b, c, d, e;
  3057. testVector test_sha[5];
  3058. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3059. WOLFSSL_ENTER("sha_test");
  3060. a.input = "";
  3061. a.output = "\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18"
  3062. "\x90\xaf\xd8\x07\x09";
  3063. a.inLen = XSTRLEN(a.input);
  3064. a.outLen = WC_SHA_DIGEST_SIZE;
  3065. b.input = "abc";
  3066. b.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  3067. "\x6C\x9C\xD0\xD8\x9D";
  3068. b.inLen = XSTRLEN(b.input);
  3069. b.outLen = WC_SHA_DIGEST_SIZE;
  3070. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3071. c.output = "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
  3072. "\xE5\xE5\x46\x70\xF1";
  3073. c.inLen = XSTRLEN(c.input);
  3074. c.outLen = WC_SHA_DIGEST_SIZE;
  3075. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3076. "aaaaaa";
  3077. d.output = "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
  3078. "\x2A\x25\xEC\x64\x4D";
  3079. d.inLen = XSTRLEN(d.input);
  3080. d.outLen = WC_SHA_DIGEST_SIZE;
  3081. e.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3082. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3083. "aaaaaaaaaa";
  3084. e.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  3085. "\x53\x99\x5E\x26\xA0";
  3086. e.inLen = XSTRLEN(e.input);
  3087. e.outLen = WC_SHA_DIGEST_SIZE;
  3088. test_sha[0] = a;
  3089. test_sha[1] = b;
  3090. test_sha[2] = c;
  3091. test_sha[3] = d;
  3092. test_sha[4] = e;
  3093. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  3094. if (ret != 0)
  3095. return WC_TEST_RET_ENC_EC(ret);
  3096. ret = wc_InitSha_ex(&shaCopy, HEAP_HINT, devId);
  3097. if (ret != 0) {
  3098. wc_ShaFree(&sha);
  3099. return WC_TEST_RET_ENC_EC(ret);
  3100. }
  3101. for (i = 0; i < times; ++i) {
  3102. ret = wc_ShaUpdate(&sha, (byte*)test_sha[i].input,
  3103. (word32)test_sha[i].inLen);
  3104. if (ret != 0)
  3105. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3106. ret = wc_ShaGetHash(&sha, hashcopy);
  3107. if (ret != 0)
  3108. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3109. ret = wc_ShaCopy(&sha, &shaCopy);
  3110. if (ret != 0)
  3111. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3112. ret = wc_ShaFinal(&sha, hash);
  3113. if (ret != 0)
  3114. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3115. wc_ShaFree(&shaCopy);
  3116. if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0)
  3117. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3118. if (XMEMCMP(hash, hashcopy, WC_SHA_DIGEST_SIZE) != 0)
  3119. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3120. }
  3121. #ifndef NO_LARGE_HASH_TEST
  3122. /* BEGIN LARGE HASH TEST */ {
  3123. byte large_input[1024];
  3124. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3125. defined(HASH_SIZE_LIMIT)
  3126. const char* large_digest =
  3127. "\x1d\x6a\x5a\xf6\xe5\x7c\x86\xce\x7f\x7c\xaf\xd5\xdb\x08\xcd\x59"
  3128. "\x15\x8c\x6d\xb6";
  3129. #else
  3130. const char* large_digest =
  3131. "\x8b\x77\x02\x48\x39\xe8\xdb\xd3\x9a\xf4\x05\x24\x66\x12\x2d\x9e"
  3132. "\xc5\xd9\x0a\xac";
  3133. #endif
  3134. for (i = 0; i < (int)sizeof(large_input); i++) {
  3135. large_input[i] = (byte)(i & 0xFF);
  3136. }
  3137. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3138. defined(HASH_SIZE_LIMIT)
  3139. times = 20;
  3140. #else
  3141. times = 100;
  3142. #endif
  3143. #ifdef WOLFSSL_PIC32MZ_HASH
  3144. wc_ShaSizeSet(&sha, times * sizeof(large_input));
  3145. #endif
  3146. for (i = 0; i < times; ++i) {
  3147. ret = wc_ShaUpdate(&sha, (byte*)large_input,
  3148. (word32)sizeof(large_input));
  3149. if (ret != 0)
  3150. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3151. }
  3152. ret = wc_ShaFinal(&sha, hash);
  3153. if (ret != 0)
  3154. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3155. if (XMEMCMP(hash, large_digest, WC_SHA_DIGEST_SIZE) != 0)
  3156. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3157. } /* END LARGE HASH TEST */
  3158. #endif /* NO_LARGE_HASH_TEST */
  3159. exit:
  3160. wc_ShaFree(&sha);
  3161. wc_ShaFree(&shaCopy);
  3162. return ret;
  3163. }
  3164. #endif /* NO_SHA */
  3165. #ifdef WOLFSSL_RIPEMD
  3166. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void)
  3167. {
  3168. RipeMd ripemd;
  3169. wc_test_ret_t ret;
  3170. byte hash[RIPEMD_DIGEST_SIZE];
  3171. testVector a, b, c, d;
  3172. testVector test_ripemd[4];
  3173. int times = sizeof(test_ripemd) / sizeof(struct testVector), i;
  3174. WOLFSSL_ENTER("ripemd_test");
  3175. a.input = "abc";
  3176. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  3177. "\xb0\x87\xf1\x5a\x0b\xfc";
  3178. a.inLen = XSTRLEN(a.input);
  3179. a.outLen = RIPEMD_DIGEST_SIZE;
  3180. b.input = "message digest";
  3181. b.output = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
  3182. "\x5f\xfa\x21\x59\x5f\x36";
  3183. b.inLen = XSTRLEN(b.input);
  3184. b.outLen = RIPEMD_DIGEST_SIZE;
  3185. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3186. c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
  3187. "\xf4\x9a\xda\x62\xeb\x2b";
  3188. c.inLen = XSTRLEN(c.input);
  3189. c.outLen = RIPEMD_DIGEST_SIZE;
  3190. d.input = "12345678901234567890123456789012345678901234567890123456"
  3191. "789012345678901234567890";
  3192. d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
  3193. "\x82\xbf\x63\x32\x6b\xfb";
  3194. d.inLen = XSTRLEN(d.input);
  3195. d.outLen = RIPEMD_DIGEST_SIZE;
  3196. test_ripemd[0] = a;
  3197. test_ripemd[1] = b;
  3198. test_ripemd[2] = c;
  3199. test_ripemd[3] = d;
  3200. ret = wc_InitRipeMd(&ripemd);
  3201. if (ret != 0) {
  3202. return WC_TEST_RET_ENC_EC(ret);
  3203. }
  3204. for (i = 0; i < times; ++i) {
  3205. ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
  3206. (word32)test_ripemd[i].inLen);
  3207. if (ret != 0) {
  3208. return WC_TEST_RET_ENC_I(i);
  3209. }
  3210. ret = wc_RipeMdFinal(&ripemd, hash);
  3211. if (ret != 0) {
  3212. return WC_TEST_RET_ENC_I(i);
  3213. }
  3214. if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
  3215. return WC_TEST_RET_ENC_I(i);
  3216. }
  3217. return 0;
  3218. }
  3219. #endif /* WOLFSSL_RIPEMD */
  3220. #ifdef HAVE_BLAKE2
  3221. #define BLAKE2B_TESTS 3
  3222. static const byte blake2b_vec[BLAKE2B_TESTS][BLAKE2B_OUTBYTES] =
  3223. {
  3224. {
  3225. 0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
  3226. 0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
  3227. 0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61,
  3228. 0x8A, 0x86, 0xE2, 0x17, 0xF7, 0x1F, 0x54, 0x19,
  3229. 0xD2, 0x5E, 0x10, 0x31, 0xAF, 0xEE, 0x58, 0x53,
  3230. 0x13, 0x89, 0x64, 0x44, 0x93, 0x4E, 0xB0, 0x4B,
  3231. 0x90, 0x3A, 0x68, 0x5B, 0x14, 0x48, 0xB7, 0x55,
  3232. 0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
  3233. },
  3234. {
  3235. 0x2F, 0xA3, 0xF6, 0x86, 0xDF, 0x87, 0x69, 0x95,
  3236. 0x16, 0x7E, 0x7C, 0x2E, 0x5D, 0x74, 0xC4, 0xC7,
  3237. 0xB6, 0xE4, 0x8F, 0x80, 0x68, 0xFE, 0x0E, 0x44,
  3238. 0x20, 0x83, 0x44, 0xD4, 0x80, 0xF7, 0x90, 0x4C,
  3239. 0x36, 0x96, 0x3E, 0x44, 0x11, 0x5F, 0xE3, 0xEB,
  3240. 0x2A, 0x3A, 0xC8, 0x69, 0x4C, 0x28, 0xBC, 0xB4,
  3241. 0xF5, 0xA0, 0xF3, 0x27, 0x6F, 0x2E, 0x79, 0x48,
  3242. 0x7D, 0x82, 0x19, 0x05, 0x7A, 0x50, 0x6E, 0x4B
  3243. },
  3244. {
  3245. 0x1C, 0x08, 0x79, 0x8D, 0xC6, 0x41, 0xAB, 0xA9,
  3246. 0xDE, 0xE4, 0x35, 0xE2, 0x25, 0x19, 0xA4, 0x72,
  3247. 0x9A, 0x09, 0xB2, 0xBF, 0xE0, 0xFF, 0x00, 0xEF,
  3248. 0x2D, 0xCD, 0x8E, 0xD6, 0xF8, 0xA0, 0x7D, 0x15,
  3249. 0xEA, 0xF4, 0xAE, 0xE5, 0x2B, 0xBF, 0x18, 0xAB,
  3250. 0x56, 0x08, 0xA6, 0x19, 0x0F, 0x70, 0xB9, 0x04,
  3251. 0x86, 0xC8, 0xA7, 0xD4, 0x87, 0x37, 0x10, 0xB1,
  3252. 0x11, 0x5D, 0x3D, 0xEB, 0xBB, 0x43, 0x27, 0xB5
  3253. }
  3254. };
  3255. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void)
  3256. {
  3257. Blake2b b2b;
  3258. byte digest[64];
  3259. byte input[64];
  3260. int i, ret;
  3261. WOLFSSL_ENTER("blake2b_test");
  3262. for (i = 0; i < (int)sizeof(input); i++)
  3263. input[i] = (byte)i;
  3264. for (i = 0; i < BLAKE2B_TESTS; i++) {
  3265. ret = wc_InitBlake2b(&b2b, 64);
  3266. if (ret != 0)
  3267. return WC_TEST_RET_ENC_I(i);
  3268. ret = wc_Blake2bUpdate(&b2b, input, (word32)i);
  3269. if (ret != 0)
  3270. return WC_TEST_RET_ENC_I(i);
  3271. ret = wc_Blake2bFinal(&b2b, digest, 64);
  3272. if (ret != 0)
  3273. return WC_TEST_RET_ENC_I(i);
  3274. if (XMEMCMP(digest, blake2b_vec[i], 64) != 0) {
  3275. return WC_TEST_RET_ENC_I(i);
  3276. }
  3277. }
  3278. return 0;
  3279. }
  3280. #endif /* HAVE_BLAKE2 */
  3281. #ifdef HAVE_BLAKE2S
  3282. #define BLAKE2S_TESTS 3
  3283. static const byte blake2s_vec[BLAKE2S_TESTS][BLAKE2S_OUTBYTES] =
  3284. {
  3285. {
  3286. 0x69, 0x21, 0x7a, 0x30, 0x79, 0x90, 0x80, 0x94,
  3287. 0xe1, 0x11, 0x21, 0xd0, 0x42, 0x35, 0x4a, 0x7c,
  3288. 0x1f, 0x55, 0xb6, 0x48, 0x2c, 0xa1, 0xa5, 0x1e,
  3289. 0x1b, 0x25, 0x0d, 0xfd, 0x1e, 0xd0, 0xee, 0xf9,
  3290. },
  3291. {
  3292. 0xe3, 0x4d, 0x74, 0xdb, 0xaf, 0x4f, 0xf4, 0xc6,
  3293. 0xab, 0xd8, 0x71, 0xcc, 0x22, 0x04, 0x51, 0xd2,
  3294. 0xea, 0x26, 0x48, 0x84, 0x6c, 0x77, 0x57, 0xfb,
  3295. 0xaa, 0xc8, 0x2f, 0xe5, 0x1a, 0xd6, 0x4b, 0xea,
  3296. },
  3297. {
  3298. 0xdd, 0xad, 0x9a, 0xb1, 0x5d, 0xac, 0x45, 0x49,
  3299. 0xba, 0x42, 0xf4, 0x9d, 0x26, 0x24, 0x96, 0xbe,
  3300. 0xf6, 0xc0, 0xba, 0xe1, 0xdd, 0x34, 0x2a, 0x88,
  3301. 0x08, 0xf8, 0xea, 0x26, 0x7c, 0x6e, 0x21, 0x0c,
  3302. }
  3303. };
  3304. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void)
  3305. {
  3306. Blake2s b2s;
  3307. byte digest[32];
  3308. byte input[64];
  3309. int i, ret;
  3310. WOLFSSL_ENTER("blake2s_test");
  3311. for (i = 0; i < (int)sizeof(input); i++)
  3312. input[i] = (byte)i;
  3313. for (i = 0; i < BLAKE2S_TESTS; i++) {
  3314. ret = wc_InitBlake2s(&b2s, 32);
  3315. if (ret != 0)
  3316. return WC_TEST_RET_ENC_I(i);
  3317. ret = wc_Blake2sUpdate(&b2s, input, (word32)i);
  3318. if (ret != 0)
  3319. return WC_TEST_RET_ENC_I(i);
  3320. ret = wc_Blake2sFinal(&b2s, digest, 32);
  3321. if (ret != 0)
  3322. return WC_TEST_RET_ENC_I(i);
  3323. if (XMEMCMP(digest, blake2s_vec[i], 32) != 0) {
  3324. return WC_TEST_RET_ENC_I(i);
  3325. }
  3326. }
  3327. return 0;
  3328. }
  3329. #endif /* HAVE_BLAKE2S */
  3330. #ifdef WOLFSSL_SHA224
  3331. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void)
  3332. {
  3333. wc_Sha224 sha, shaCopy;
  3334. byte hash[WC_SHA224_DIGEST_SIZE];
  3335. byte hashcopy[WC_SHA224_DIGEST_SIZE];
  3336. wc_test_ret_t ret = 0;
  3337. testVector a, b, c;
  3338. testVector test_sha[3];
  3339. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3340. WOLFSSL_ENTER("sha224_test");
  3341. a.input = "";
  3342. a.output = "\xd1\x4a\x02\x8c\x2a\x3a\x2b\xc9\x47\x61\x02\xbb\x28\x82\x34"
  3343. "\xc4\x15\xa2\xb0\x1f\x82\x8e\xa6\x2a\xc5\xb3\xe4\x2f";
  3344. a.inLen = XSTRLEN(a.input);
  3345. a.outLen = WC_SHA224_DIGEST_SIZE;
  3346. b.input = "abc";
  3347. b.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55"
  3348. "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  3349. b.inLen = XSTRLEN(b.input);
  3350. b.outLen = WC_SHA224_DIGEST_SIZE;
  3351. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3352. c.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  3353. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  3354. c.inLen = XSTRLEN(c.input);
  3355. c.outLen = WC_SHA224_DIGEST_SIZE;
  3356. test_sha[0] = a;
  3357. test_sha[1] = b;
  3358. test_sha[2] = c;
  3359. ret = wc_InitSha224_ex(&sha, HEAP_HINT, devId);
  3360. if (ret != 0)
  3361. return WC_TEST_RET_ENC_EC(ret);
  3362. ret = wc_InitSha224_ex(&shaCopy, HEAP_HINT, devId);
  3363. if (ret != 0) {
  3364. wc_Sha224Free(&sha);
  3365. return WC_TEST_RET_ENC_EC(ret);
  3366. }
  3367. for (i = 0; i < times; ++i) {
  3368. ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,
  3369. (word32)test_sha[i].inLen);
  3370. if (ret != 0)
  3371. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3372. ret = wc_Sha224GetHash(&sha, hashcopy);
  3373. if (ret != 0)
  3374. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3375. ret = wc_Sha224Copy(&sha, &shaCopy);
  3376. if (ret != 0)
  3377. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3378. ret = wc_Sha224Final(&sha, hash);
  3379. if (ret != 0)
  3380. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3381. wc_Sha224Free(&shaCopy);
  3382. if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  3383. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3384. if (XMEMCMP(hash, hashcopy, WC_SHA224_DIGEST_SIZE) != 0)
  3385. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3386. }
  3387. exit:
  3388. wc_Sha224Free(&sha);
  3389. wc_Sha224Free(&shaCopy);
  3390. return ret;
  3391. }
  3392. #endif
  3393. #ifndef NO_SHA256
  3394. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
  3395. {
  3396. wc_Sha256 sha, shaCopy;
  3397. byte hash[WC_SHA256_DIGEST_SIZE];
  3398. byte hashcopy[WC_SHA256_DIGEST_SIZE];
  3399. wc_test_ret_t ret = 0;
  3400. testVector a, b, c, d;
  3401. testVector test_sha[4];
  3402. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3403. byte i_hash[WC_SHA256_DIGEST_SIZE];
  3404. byte i_hashcopy[WC_SHA256_DIGEST_SIZE];
  3405. testVector interleave_test_sha[4];
  3406. wc_Sha256 i_sha, i_shaCopy;
  3407. #endif
  3408. #ifndef NO_LARGE_HASH_TEST
  3409. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3410. #ifdef WOLFSSL_SMALL_STACK
  3411. byte *large_input = NULL;
  3412. #else
  3413. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3414. #endif
  3415. #endif
  3416. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3417. WOLFSSL_ENTER("sha256_test");
  3418. a.input = "";
  3419. a.output = "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9"
  3420. "\x24\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52"
  3421. "\xb8\x55";
  3422. a.inLen = XSTRLEN(a.input);
  3423. a.outLen = WC_SHA256_DIGEST_SIZE;
  3424. b.input = "abc";
  3425. b.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  3426. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  3427. "\x15\xAD";
  3428. b.inLen = XSTRLEN(b.input);
  3429. b.outLen = WC_SHA256_DIGEST_SIZE;
  3430. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3431. c.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  3432. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  3433. "\x06\xC1";
  3434. c.inLen = XSTRLEN(c.input);
  3435. c.outLen = WC_SHA256_DIGEST_SIZE;
  3436. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3437. "aaaaaa"; /* this is BLOCKSIZE length */
  3438. d.output = "\xFF\xE0\x54\xFE\x7A\xE0\xCB\x6D\xC6\x5C\x3A\xF9\xB6\x1D\x52"
  3439. "\x09\xF4\x39\x85\x1D\xB4\x3D\x0B\xA5\x99\x73\x37\xDF\x15\x46"
  3440. "\x68\xEB";
  3441. d.inLen = XSTRLEN(d.input);
  3442. d.outLen = WC_SHA256_DIGEST_SIZE;
  3443. test_sha[0] = a;
  3444. test_sha[1] = b;
  3445. test_sha[2] = c;
  3446. test_sha[3] = d;
  3447. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3448. interleave_test_sha[0] = a;
  3449. interleave_test_sha[1] = b;
  3450. interleave_test_sha[2] = c;
  3451. interleave_test_sha[3] = d;
  3452. #endif
  3453. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  3454. if (ret != 0)
  3455. return WC_TEST_RET_ENC_EC(ret);
  3456. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3457. ret = wc_InitSha256_ex(&i_sha, HEAP_HINT, devId);
  3458. if (ret != 0)
  3459. return WC_TEST_RET_ENC_EC(ret);
  3460. #endif
  3461. ret = wc_InitSha256_ex(&shaCopy, HEAP_HINT, devId);
  3462. if (ret != 0) {
  3463. wc_Sha256Free(&sha);
  3464. return WC_TEST_RET_ENC_EC(ret);
  3465. }
  3466. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3467. ret = wc_InitSha256_ex(&i_shaCopy, HEAP_HINT, devId);
  3468. if (ret != 0) {
  3469. wc_Sha256Free(&sha);
  3470. wc_Sha256Free(&i_sha);
  3471. return WC_TEST_RET_ENC_EC(ret);
  3472. }
  3473. #endif
  3474. for (i = 0; i < times; ++i) {
  3475. ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input,
  3476. (word32)test_sha[i].inLen);
  3477. if (ret != 0) {
  3478. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3479. }
  3480. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3481. ret = wc_Sha256Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3482. (word32)interleave_test_sha[i].inLen);
  3483. if (ret != 0) {
  3484. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3485. }
  3486. #endif
  3487. ret = wc_Sha256GetHash(&sha, hashcopy);
  3488. if (ret != 0)
  3489. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3490. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3491. ret = wc_Sha256GetHash(&i_sha, i_hashcopy);
  3492. if (ret != 0)
  3493. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3494. #endif
  3495. ret = wc_Sha256Copy(&sha, &shaCopy);
  3496. if (ret != 0)
  3497. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3498. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3499. ret = wc_Sha256Copy(&i_sha, &i_shaCopy);
  3500. if (ret != 0)
  3501. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3502. #endif
  3503. ret = wc_Sha256Final(&sha, hash);
  3504. if (ret != 0)
  3505. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3506. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3507. ret = wc_Sha256Final(&i_sha, i_hash);
  3508. if (ret != 0)
  3509. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3510. #endif
  3511. wc_Sha256Free(&shaCopy);
  3512. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3513. wc_Sha256Free(&i_shaCopy);
  3514. #endif
  3515. if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3516. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3517. }
  3518. if (XMEMCMP(hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3519. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3520. }
  3521. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3522. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3523. WC_SHA256_DIGEST_SIZE) != 0) {
  3524. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3525. }
  3526. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3527. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3528. }
  3529. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3530. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3531. }
  3532. if (XMEMCMP(i_hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3533. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3534. }
  3535. #endif
  3536. }
  3537. #ifndef NO_LARGE_HASH_TEST
  3538. /* BEGIN LARGE HASH TEST */ {
  3539. #ifdef HASH_SIZE_LIMIT
  3540. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3541. "\xa4\x75\x9e\x7a\xa2\x03\x38\x32\x88\x66\xa2\xea\x17\xea\xf8\xc7"
  3542. "\xfe\x4e\xc6\xbb\xe3\xbb\x71\xce\xe7\xdf\x7c\x04\x61\xb3\xc2\x2f";
  3543. #else
  3544. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3545. "\x27\x78\x3e\x87\x96\x3a\x4e\xfb\x68\x29\xb5\x31\xc9\xba\x57\xb4"
  3546. "\x4f\x45\x79\x7f\x67\x70\xbd\x63\x7f\xbf\x0d\x80\x7c\xbd\xba\xe0";
  3547. #endif
  3548. #ifdef WOLFSSL_SMALL_STACK
  3549. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3550. DYNAMIC_TYPE_TMP_BUFFER);
  3551. if (large_input == NULL) {
  3552. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3553. }
  3554. #endif
  3555. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3556. large_input[i] = (byte)(i & 0xFF);
  3557. }
  3558. #ifdef HASH_SIZE_LIMIT
  3559. times = 20;
  3560. #else
  3561. times = 100;
  3562. #endif
  3563. #ifdef WOLFSSL_PIC32MZ_HASH
  3564. wc_Sha256SizeSet(&sha, times * LARGE_HASH_TEST_INPUT_SZ);
  3565. #endif
  3566. for (i = 0; i < times; ++i) {
  3567. ret = wc_Sha256Update(&sha, (byte*)large_input,
  3568. LARGE_HASH_TEST_INPUT_SZ);
  3569. if (ret != 0)
  3570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3571. }
  3572. ret = wc_Sha256Final(&sha, hash);
  3573. if (ret != 0)
  3574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3575. if (XMEMCMP(hash, large_digest, WC_SHA256_DIGEST_SIZE) != 0)
  3576. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3577. } /* END LARGE HASH TEST */
  3578. #undef LARGE_HASH_TEST_INPUT_SZ
  3579. #endif /* NO_LARGE_HASH_TEST */
  3580. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_FULL_HASH)
  3581. {
  3582. WOLFSSL_SMALL_STACK_STATIC const unsigned char
  3583. data_hb[WC_SHA256_BLOCK_SIZE] = {
  3584. 0x61, 0x62, 0x63, 0x80, 0x00, 0x00, 0x00, 0x00,
  3585. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3586. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3587. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3588. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3589. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3590. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3591. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18
  3592. };
  3593. ret = wc_Sha256HashBlock(&sha, data_hb, hash);
  3594. if (ret != 0) {
  3595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3596. }
  3597. if (XMEMCMP(hash, b.output, WC_SHA256_DIGEST_SIZE) != 0) {
  3598. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3599. }
  3600. }
  3601. #endif
  3602. exit:
  3603. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3604. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3605. #endif
  3606. wc_Sha256Free(&sha);
  3607. wc_Sha256Free(&shaCopy);
  3608. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3609. wc_Sha256Free(&i_sha);
  3610. wc_Sha256Free(&i_shaCopy);
  3611. #endif
  3612. return ret;
  3613. }
  3614. #endif
  3615. #ifdef WOLFSSL_SHA512
  3616. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
  3617. {
  3618. /*
  3619. ** See https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf
  3620. */
  3621. wc_Sha512 sha, shaCopy;
  3622. byte hash[WC_SHA512_DIGEST_SIZE];
  3623. byte hashcopy[WC_SHA512_DIGEST_SIZE];
  3624. wc_test_ret_t ret = 0;
  3625. testVector a, b, c;
  3626. testVector test_sha[3];
  3627. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3628. wc_Sha512 i_sha, i_shaCopy;
  3629. byte i_hash[WC_SHA512_DIGEST_SIZE];
  3630. byte i_hashcopy[WC_SHA512_DIGEST_SIZE];
  3631. testVector interleave_test_sha[3];
  3632. #endif
  3633. #ifndef NO_LARGE_HASH_TEST
  3634. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3635. #ifdef WOLFSSL_SMALL_STACK
  3636. byte *large_input = NULL;
  3637. #else
  3638. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3639. #endif
  3640. #endif
  3641. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3642. WOLFSSL_ENTER("sha512_test");
  3643. a.input = "";
  3644. a.output = "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80"
  3645. "\x07\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c"
  3646. "\xe9\xce\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87"
  3647. "\x7e\xec\x2f\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a"
  3648. "\xf9\x27\xda\x3e";
  3649. a.inLen = XSTRLEN(a.input);
  3650. a.outLen = WC_SHA512_DIGEST_SIZE;
  3651. b.input = "abc";
  3652. b.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  3653. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  3654. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  3655. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  3656. "\xa5\x4c\xa4\x9f";
  3657. b.inLen = XSTRLEN(b.input);
  3658. b.outLen = WC_SHA512_DIGEST_SIZE;
  3659. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3660. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3661. c.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  3662. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  3663. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  3664. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  3665. "\x87\x4b\xe9\x09";
  3666. c.inLen = XSTRLEN(c.input);
  3667. c.outLen = WC_SHA512_DIGEST_SIZE;
  3668. test_sha[0] = a;
  3669. test_sha[1] = b;
  3670. test_sha[2] = c;
  3671. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3672. interleave_test_sha[0] = a;
  3673. interleave_test_sha[1] = b;
  3674. interleave_test_sha[2] = c;
  3675. #endif
  3676. ret = wc_InitSha512_ex(&sha, HEAP_HINT, devId);
  3677. if (ret != 0)
  3678. return WC_TEST_RET_ENC_EC(ret);
  3679. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3680. ret = wc_InitSha512_ex(&i_sha, HEAP_HINT, devId);
  3681. if (ret != 0)
  3682. return WC_TEST_RET_ENC_EC(ret);
  3683. #endif
  3684. ret = wc_InitSha512_ex(&shaCopy, HEAP_HINT, devId);
  3685. if (ret != 0) {
  3686. wc_Sha512Free(&sha);
  3687. return WC_TEST_RET_ENC_EC(ret);
  3688. }
  3689. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3690. ret = wc_InitSha512_ex(&i_shaCopy, HEAP_HINT, devId);
  3691. if (ret != 0) {
  3692. wc_Sha512Free(&sha);
  3693. wc_Sha512Free(&i_sha);
  3694. return WC_TEST_RET_ENC_EC(ret);
  3695. }
  3696. #endif
  3697. for (i = 0; i < times; ++i) {
  3698. ret = wc_Sha512Update(&sha, (byte*)test_sha[i].input,
  3699. (word32)test_sha[i].inLen);
  3700. if (ret != 0)
  3701. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3702. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3703. ret = wc_Sha512Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3704. (word32)interleave_test_sha[i].inLen);
  3705. if (ret != 0)
  3706. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3707. #endif
  3708. ret = wc_Sha512GetHash(&sha, hashcopy);
  3709. if (ret != 0)
  3710. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3711. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3712. ret = wc_Sha512GetHash(&i_sha, i_hashcopy);
  3713. if (ret != 0)
  3714. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3715. #endif
  3716. ret = wc_Sha512Copy(&sha, &shaCopy);
  3717. if (ret != 0)
  3718. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3719. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3720. ret = wc_Sha512Copy(&i_sha, &i_shaCopy);
  3721. if (ret != 0)
  3722. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3723. #endif
  3724. ret = wc_Sha512Final(&sha, hash);
  3725. if (ret != 0)
  3726. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3727. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3728. ret = wc_Sha512Final(&i_sha, i_hash);
  3729. if (ret != 0)
  3730. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3731. #endif
  3732. wc_Sha512Free(&shaCopy);
  3733. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3734. wc_Sha512Free(&i_shaCopy);
  3735. #endif
  3736. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  3737. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3738. if (XMEMCMP(hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0)
  3739. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3740. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3741. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3742. WC_SHA512_DIGEST_SIZE) != 0) {
  3743. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3744. }
  3745. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3746. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3747. }
  3748. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0) {
  3749. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3750. }
  3751. if (XMEMCMP(i_hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3752. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3753. }
  3754. #endif
  3755. }
  3756. #ifndef NO_LARGE_HASH_TEST
  3757. /* BEGIN LARGE HASH TEST */ {
  3758. #ifdef HASH_SIZE_LIMIT
  3759. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3760. "\x30\x9B\x96\xA6\xE9\x43\x78\x30\xA3\x71\x51\x61\xC1\xEB\xE1\xBE"
  3761. "\xC8\xA5\xF9\x13\x5A\xD6\x6D\x9E\x46\x31\x31\x67\x8D\xE2\xC0\x0B"
  3762. "\x2A\x1A\x03\xE1\xF3\x48\xA7\x33\xBD\x49\xF8\xFF\xF1\xC2\xC2\x95"
  3763. "\xCB\xF0\xAF\x87\x61\x85\x58\x63\x6A\xCA\x70\x9C\x8B\x83\x3F\x5D";
  3764. #else
  3765. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3766. "\x5a\x1f\x73\x90\xbd\x8c\xe4\x63\x54\xce\xa0\x9b\xef\x32\x78\x2d"
  3767. "\x2e\xe7\x0d\x5e\x2f\x9d\x15\x1b\xdd\x2d\xde\x65\x0c\x7b\xfa\x83"
  3768. "\x5e\x80\x02\x13\x84\xb8\x3f\xff\x71\x62\xb5\x09\x89\x63\xe1\xdc"
  3769. "\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
  3770. #endif
  3771. #ifdef WOLFSSL_SMALL_STACK
  3772. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3773. DYNAMIC_TYPE_TMP_BUFFER);
  3774. if (large_input == NULL) {
  3775. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3776. }
  3777. #endif
  3778. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3779. large_input[i] = (byte)(i & 0xFF);
  3780. }
  3781. #ifdef HASH_SIZE_LIMIT
  3782. times = 20;
  3783. #else
  3784. times = 100;
  3785. #endif
  3786. for (i = 0; i < times; ++i) {
  3787. ret = wc_Sha512Update(&sha, (byte*)large_input,
  3788. LARGE_HASH_TEST_INPUT_SZ);
  3789. if (ret != 0)
  3790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3791. }
  3792. ret = wc_Sha512Final(&sha, hash);
  3793. if (ret != 0)
  3794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3795. if (XMEMCMP(hash, large_digest, WC_SHA512_DIGEST_SIZE) != 0)
  3796. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3797. #ifndef NO_UNALIGNED_MEMORY_TEST
  3798. /* Unaligned memory access test */
  3799. for (i = 1; i < 16; i++) {
  3800. ret = wc_Sha512Update(&sha, (byte*)large_input + i,
  3801. LARGE_HASH_TEST_INPUT_SZ - (word32)i);
  3802. if (ret != 0)
  3803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3804. ret = wc_Sha512Final(&sha, hash);
  3805. }
  3806. #endif
  3807. } /* END LARGE HASH TEST */
  3808. #undef LARGE_HASH_TEST_INPUT_SZ
  3809. #endif /* NO_LARGE_HASH_TEST */
  3810. exit:
  3811. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3812. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3813. #endif
  3814. wc_Sha512Free(&sha);
  3815. wc_Sha512Free(&shaCopy);
  3816. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3817. wc_Sha512Free(&i_sha);
  3818. wc_Sha512Free(&i_shaCopy);
  3819. #endif
  3820. return ret;
  3821. }
  3822. #if !defined(WOLFSSL_NOSHA512_224) && \
  3823. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3824. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void)
  3825. {
  3826. /*
  3827. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3828. **
  3829. ** NIST SHA512/224 Document Example:
  3830. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_224.pdf
  3831. */
  3832. wc_Sha512 sha, shaCopy;
  3833. byte hash[WC_SHA512_224_DIGEST_SIZE];
  3834. byte hashcopy[WC_SHA512_224_DIGEST_SIZE];
  3835. wc_test_ret_t ret = 0;
  3836. testVector a, b, c;
  3837. testVector test_sha[3];
  3838. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3839. WOLFSSL_ENTER("sha512_224_test");
  3840. a.input = "";
  3841. a.output = "\x6e\xd0\xdd\x02"
  3842. "\x80\x6f\xa8\x9e" "\x25\xde\x06\x0c"
  3843. "\x19\xd3\xac\x86" "\xca\xbb\x87\xd6"
  3844. "\xa0\xdd\xd0\x5c" "\x33\x3b\x84\xf4";
  3845. a.inLen = XSTRLEN(a.input);
  3846. a.outLen = WC_SHA512_224_DIGEST_SIZE;
  3847. /*
  3848. ** See page 1 in above document for the SHA512/224 "abc" test:
  3849. */
  3850. b.input = "abc";
  3851. /*
  3852. ** See page 1 in above document for the SHA512/224 "abc" test digest:
  3853. */
  3854. b.output = "\x46\x34\x27\x0f"
  3855. "\x70\x7b\x6a\x54" "\xda\xae\x75\x30"
  3856. "\x46\x08\x42\xe2" "\x0e\x37\xed\x26"
  3857. "\x5c\xee\xe9\xa4" "\x3e\x89\x24\xaa";
  3858. b.inLen = XSTRLEN(b.input);
  3859. b.outLen = WC_SHA512_224_DIGEST_SIZE;
  3860. /*
  3861. ** See page 4 in above for the 2-block test:
  3862. */
  3863. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3864. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3865. /*
  3866. ** see page 9 in above document for the 2-block test message digest:
  3867. */
  3868. c.output = "\x23\xfe\xc5\xbb"
  3869. "\x94\xd6\x0b\x23" "\x30\x81\x92\x64"
  3870. "\x0b\x0c\x45\x33" "\x35\xd6\x64\x73"
  3871. "\x4f\xe4\x0e\x72" "\x68\x67\x4a\xf9";
  3872. c.inLen = XSTRLEN(c.input);
  3873. c.outLen = WC_SHA512_224_DIGEST_SIZE;
  3874. test_sha[0] = a;
  3875. test_sha[1] = b;
  3876. test_sha[2] = c;
  3877. ret = wc_InitSha512_224_ex(&sha, HEAP_HINT, devId);
  3878. if (ret != 0)
  3879. return WC_TEST_RET_ENC_EC(ret);
  3880. ret = wc_InitSha512_224_ex(&shaCopy, HEAP_HINT, devId);
  3881. if (ret != 0) {
  3882. wc_Sha512_224Free(&sha);
  3883. return WC_TEST_RET_ENC_EC(ret);
  3884. }
  3885. for (i = 0; i < times; ++i) {
  3886. ret = wc_Sha512_224Update(&sha, (byte*)test_sha[i].input,
  3887. (word32)test_sha[i].inLen);
  3888. if (ret != 0)
  3889. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3890. ret = wc_Sha512_224GetHash(&sha, hashcopy);
  3891. if (ret != 0)
  3892. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3893. ret = wc_Sha512_224Copy(&sha, &shaCopy);
  3894. if (ret != 0)
  3895. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3896. ret = wc_Sha512_224Final(&sha, hash);
  3897. if (ret != 0)
  3898. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3899. wc_Sha512_224Free(&shaCopy);
  3900. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_224_DIGEST_SIZE) != 0)
  3901. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3902. if (XMEMCMP(hash, hashcopy, WC_SHA512_224_DIGEST_SIZE) != 0)
  3903. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3904. }
  3905. #ifndef NO_LARGE_HASH_TEST
  3906. /* BEGIN LARGE HASH TEST */ {
  3907. byte large_input[1024];
  3908. #ifdef HASH_SIZE_LIMIT
  3909. const char* large_digest =
  3910. "\x98\x68\xc3\xd9\xb9\xef\x17\x53"
  3911. "\x43\x66\x0e\x60\xdf\x29\xf8\xef"
  3912. "\x96\xe3\x93\x34\x8c\x6f\xc0\xeb"
  3913. "\x14\x6c\xcf\x6a";
  3914. #else
  3915. const char* large_digest =
  3916. "\x26\x5f\x98\xd1\x76\x49\x71\x4e"
  3917. "\x82\xb7\x9d\x52\x32\x67\x9d\x56"
  3918. "\x91\xf5\x88\xc3\x05\xbb\x3f\x90"
  3919. "\xe2\x4e\x85\x05";
  3920. #endif
  3921. for (i = 0; i < (int)sizeof(large_input); i++) {
  3922. large_input[i] = (byte)(i & 0xFF);
  3923. }
  3924. #ifdef HASH_SIZE_LIMIT
  3925. times = 20;
  3926. #else
  3927. times = 100;
  3928. #endif
  3929. for (i = 0; i < times; ++i) {
  3930. ret = wc_Sha512_224Update(&sha, (byte*)large_input,
  3931. (word32)sizeof(large_input));
  3932. if (ret != 0)
  3933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3934. }
  3935. ret = wc_Sha512_224Final(&sha, hash);
  3936. if (ret != 0)
  3937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3938. if (XMEMCMP(hash, large_digest, WC_SHA512_224_DIGEST_SIZE) != 0)
  3939. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3940. #ifndef NO_UNALIGNED_MEMORY_TEST
  3941. /* Unaligned memory access test */
  3942. for (i = 1; i < 16; i++) {
  3943. ret = wc_Sha512_224Update(&sha, (byte*)large_input + i,
  3944. (word32)sizeof(large_input) - (word32)i);
  3945. if (ret != 0)
  3946. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3947. ret = wc_Sha512_224Final(&sha, hash);
  3948. }
  3949. #endif
  3950. } /* END LARGE HASH TEST */
  3951. #endif /* NO_LARGE_HASH_TEST */
  3952. exit:
  3953. wc_Sha512_224Free(&sha);
  3954. wc_Sha512_224Free(&shaCopy);
  3955. return ret;
  3956. } /* sha512_224_test */
  3957. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  3958. #if !defined(WOLFSSL_NOSHA512_256) && \
  3959. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3960. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void)
  3961. {
  3962. /*
  3963. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3964. ** NIST SHA512/256 Document Example:
  3965. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_256.pdf
  3966. */
  3967. wc_Sha512 sha, shaCopy;
  3968. byte hash[WC_SHA512_256_DIGEST_SIZE];
  3969. byte hashcopy[WC_SHA512_256_DIGEST_SIZE];
  3970. wc_test_ret_t ret = 0;
  3971. testVector a, b, c;
  3972. testVector test_sha[3];
  3973. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3974. WOLFSSL_ENTER("sha512_256_test");
  3975. a.input = "";
  3976. a.output = "\xc6\x72\xb8\xd1" "\xef\x56\xed\x28"
  3977. "\xab\x87\xc3\x62" "\x2c\x51\x14\x06"
  3978. "\x9b\xdd\x3a\xd7" "\xb8\xf9\x73\x74"
  3979. "\x98\xd0\xc0\x1e" "\xce\xf0\x96\x7a";
  3980. a.inLen = XSTRLEN(a.input);
  3981. a.outLen = WC_SHA512_256_DIGEST_SIZE;
  3982. /*
  3983. ** See page 1 of above document for "abc" example:
  3984. */
  3985. b.input = "abc";
  3986. /*
  3987. ** See page 4 of above document for "abc" example digest:
  3988. */
  3989. b.output = "\x53\x04\x8e\x26" "\x81\x94\x1e\xf9"
  3990. "\x9b\x2e\x29\xb7" "\x6b\x4c\x7d\xab"
  3991. "\xe4\xc2\xd0\xc6" "\x34\xfc\x6d\x46"
  3992. "\xe0\xe2\xf1\x31" "\x07\xe7\xaf\x23";
  3993. b.inLen = XSTRLEN(b.input);
  3994. b.outLen = WC_SHA512_256_DIGEST_SIZE;
  3995. /*
  3996. ** See page 4 of above document for Two Block Message Sample:
  3997. */
  3998. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3999. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  4000. /*
  4001. ** See page 10 of above document for Two Block Message Sample digest:
  4002. */
  4003. c.output = "\x39\x28\xe1\x84" "\xfb\x86\x90\xf8"
  4004. "\x40\xda\x39\x88" "\x12\x1d\x31\xbe"
  4005. "\x65\xcb\x9d\x3e" "\xf8\x3e\xe6\x14"
  4006. "\x6f\xea\xc8\x61" "\xe1\x9b\x56\x3a";
  4007. c.inLen = XSTRLEN(c.input);
  4008. c.outLen = WC_SHA512_256_DIGEST_SIZE;
  4009. test_sha[0] = a;
  4010. test_sha[1] = b;
  4011. test_sha[2] = c;
  4012. ret = wc_InitSha512_256_ex(&sha, HEAP_HINT, devId);
  4013. if (ret != 0)
  4014. return WC_TEST_RET_ENC_EC(ret);
  4015. ret = wc_InitSha512_256_ex(&shaCopy, HEAP_HINT, devId);
  4016. if (ret != 0) {
  4017. wc_Sha512_256Free(&sha);
  4018. return WC_TEST_RET_ENC_EC(ret);
  4019. }
  4020. for (i = 0; i < times; ++i) {
  4021. ret = wc_Sha512_256Update(&sha, (byte*)test_sha[i].input,
  4022. (word32)test_sha[i].inLen);
  4023. if (ret != 0)
  4024. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4025. ret = wc_Sha512_256GetHash(&sha, hashcopy);
  4026. if (ret != 0)
  4027. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4028. ret = wc_Sha512_256Copy(&sha, &shaCopy);
  4029. if (ret != 0)
  4030. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4031. ret = wc_Sha512_256Final(&sha, hash);
  4032. if (ret != 0)
  4033. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4034. wc_Sha512_256Free(&shaCopy);
  4035. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_256_DIGEST_SIZE) != 0)
  4036. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4037. if (XMEMCMP(hash, hashcopy, WC_SHA512_256_DIGEST_SIZE) != 0)
  4038. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4039. }
  4040. #ifndef NO_LARGE_HASH_TEST
  4041. /* BEGIN LARGE HASH TEST */ {
  4042. byte large_input[1024];
  4043. #ifdef HASH_SIZE_LIMIT
  4044. const char* large_digest =
  4045. "\x49\xcc\xbc\x7a\x93\x0b\x02\xb8"
  4046. "\xad\x9a\x46\x51\x00\x1f\x13\x80"
  4047. "\x35\x84\x36\xf1\xf2\x3c\xeb\xd8"
  4048. "\x41\xd4\x06\x8b\x1d\x19\xad\x72";
  4049. #else
  4050. const char* large_digest =
  4051. "\x7a\xe3\x84\x05\xcb\x06\x22\x08"
  4052. "\x7e\x2c\x65\x89\x1f\x26\x45\xfd"
  4053. "\xad\xbc\x2e\x29\x83\x12\x84\x4b"
  4054. "\xf2\xa0\xde\xbe\x06\x11\xd7\x44";
  4055. #endif
  4056. for (i = 0; i < (int)sizeof(large_input); i++) {
  4057. large_input[i] = (byte)(i & 0xFF);
  4058. }
  4059. #ifdef HASH_SIZE_LIMIT
  4060. times = 20;
  4061. #else
  4062. times = 100;
  4063. #endif
  4064. for (i = 0; i < times; ++i) {
  4065. ret = wc_Sha512_256Update(&sha, (byte*)large_input,
  4066. (word32)sizeof(large_input));
  4067. if (ret != 0)
  4068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4069. }
  4070. ret = wc_Sha512_256Final(&sha, hash);
  4071. if (ret != 0)
  4072. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4073. if (XMEMCMP(hash, large_digest, WC_SHA512_256_DIGEST_SIZE) != 0)
  4074. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4075. #ifndef NO_UNALIGNED_MEMORY_TEST
  4076. /* Unaligned memory access test */
  4077. for (i = 1; i < 16; i++) {
  4078. ret = wc_Sha512_256Update(&sha, (byte*)large_input + i,
  4079. (word32)sizeof(large_input) - (word32)i);
  4080. if (ret != 0)
  4081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4082. ret = wc_Sha512_256Final(&sha, hash);
  4083. }
  4084. #endif
  4085. } /* END LARGE HASH TEST */
  4086. #endif /* NO_LARGE_HASH_TEST */
  4087. exit:
  4088. wc_Sha512_256Free(&sha);
  4089. wc_Sha512_256Free(&shaCopy);
  4090. return ret;
  4091. } /* sha512_256_test */
  4092. #endif /* !defined(WOLFSSL_NOSHA512_256) && !FIPS ... */
  4093. #endif /* WOLFSSL_SHA512 */
  4094. #ifdef WOLFSSL_SHA384
  4095. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void)
  4096. {
  4097. wc_Sha384 sha, shaCopy;
  4098. byte hash[WC_SHA384_DIGEST_SIZE];
  4099. byte hashcopy[WC_SHA384_DIGEST_SIZE];
  4100. wc_test_ret_t ret = 0;
  4101. testVector a, b, c;
  4102. testVector test_sha[3];
  4103. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4104. WOLFSSL_ENTER("sha384_test");
  4105. a.input = "";
  4106. a.output = "\x38\xb0\x60\xa7\x51\xac\x96\x38\x4c\xd9\x32\x7e\xb1\xb1\xe3"
  4107. "\x6a\x21\xfd\xb7\x11\x14\xbe\x07\x43\x4c\x0c\xc7\xbf\x63\xf6"
  4108. "\xe1\xda\x27\x4e\xde\xbf\xe7\x6f\x65\xfb\xd5\x1a\xd2\xf1\x48"
  4109. "\x98\xb9\x5b";
  4110. a.inLen = XSTRLEN(a.input);
  4111. a.outLen = WC_SHA384_DIGEST_SIZE;
  4112. b.input = "abc";
  4113. b.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  4114. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  4115. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  4116. "\xc8\x25\xa7";
  4117. b.inLen = XSTRLEN(b.input);
  4118. b.outLen = WC_SHA384_DIGEST_SIZE;
  4119. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  4120. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  4121. c.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  4122. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  4123. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  4124. "\x74\x60\x39";
  4125. c.inLen = XSTRLEN(c.input);
  4126. c.outLen = WC_SHA384_DIGEST_SIZE;
  4127. test_sha[0] = a;
  4128. test_sha[1] = b;
  4129. test_sha[2] = c;
  4130. ret = wc_InitSha384_ex(&sha, HEAP_HINT, devId);
  4131. if (ret != 0)
  4132. return WC_TEST_RET_ENC_EC(ret);
  4133. ret = wc_InitSha384_ex(&shaCopy, HEAP_HINT, devId);
  4134. if (ret != 0) {
  4135. wc_Sha384Free(&sha);
  4136. return WC_TEST_RET_ENC_EC(ret);
  4137. }
  4138. for (i = 0; i < times; ++i) {
  4139. ret = wc_Sha384Update(&sha, (byte*)test_sha[i].input,
  4140. (word32)test_sha[i].inLen);
  4141. if (ret != 0)
  4142. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4143. ret = wc_Sha384GetHash(&sha, hashcopy);
  4144. if (ret != 0)
  4145. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4146. ret = wc_Sha384Copy(&sha, &shaCopy);
  4147. if (ret != 0)
  4148. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4149. ret = wc_Sha384Final(&sha, hash);
  4150. if (ret != 0)
  4151. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4152. wc_Sha384Free(&shaCopy);
  4153. if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  4154. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4155. if (XMEMCMP(hash, hashcopy, WC_SHA384_DIGEST_SIZE) != 0)
  4156. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4157. }
  4158. #ifndef NO_LARGE_HASH_TEST
  4159. /* BEGIN LARGE HASH TEST */ {
  4160. byte large_input[1024];
  4161. #ifdef HASH_SIZE_LIMIT
  4162. const char* large_digest =
  4163. "\xB5\xAD\x66\x6F\xD9\x58\x5E\x68\xDD\x5E\x30\xD3\x95\x72\x33\xA4"
  4164. "\xE9\x4B\x99\x3A\xEF\xF8\xE1\xBF\x1F\x05\x32\xAA\x16\x00\x82\xEC"
  4165. "\x15\xDA\xF2\x75\xEE\xE9\x06\xAF\x52\x8A\x5C\xEF\x72\x81\x80\xD6";
  4166. #else
  4167. const char* large_digest =
  4168. "\x37\x01\xdb\xff\x1e\x40\x4f\xe1\xe2\xea\x0b\x40\xbb\x3b\x39\x9a"
  4169. "\xcc\xe8\x44\x8e\x7e\xe5\x64\xb5\x6b\x7f\x56\x64\xa7\x2b\x84\xe3"
  4170. "\xc5\xd7\x79\x03\x25\x90\xf7\xa4\x58\xcb\x97\xa8\x8b\xb1\xa4\x81";
  4171. #endif
  4172. for (i = 0; i < (int)sizeof(large_input); i++) {
  4173. large_input[i] = (byte)(i & 0xFF);
  4174. }
  4175. #ifdef HASH_SIZE_LIMIT
  4176. times = 20;
  4177. #else
  4178. times = 100;
  4179. #endif
  4180. for (i = 0; i < times; ++i) {
  4181. ret = wc_Sha384Update(&sha, (byte*)large_input,
  4182. (word32)sizeof(large_input));
  4183. if (ret != 0)
  4184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4185. }
  4186. ret = wc_Sha384Final(&sha, hash);
  4187. if (ret != 0)
  4188. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4189. if (XMEMCMP(hash, large_digest, WC_SHA384_DIGEST_SIZE) != 0)
  4190. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4191. } /* END LARGE HASH TEST */
  4192. #endif /* NO_LARGE_HASH_TEST */
  4193. exit:
  4194. wc_Sha384Free(&sha);
  4195. wc_Sha384Free(&shaCopy);
  4196. return ret;
  4197. }
  4198. #endif /* WOLFSSL_SHA384 */
  4199. #ifdef WOLFSSL_SHA3
  4200. #ifndef WOLFSSL_NOSHA3_224
  4201. static wc_test_ret_t sha3_224_test(void)
  4202. {
  4203. wc_Sha3 sha;
  4204. byte hash[WC_SHA3_224_DIGEST_SIZE];
  4205. byte hashcopy[WC_SHA3_224_DIGEST_SIZE];
  4206. testVector a, b, c;
  4207. testVector test_sha[3];
  4208. wc_test_ret_t ret = 0;
  4209. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4210. a.input = "";
  4211. a.output = "\x6b\x4e\x03\x42\x36\x67\xdb\xb7\x3b\x6e\x15\x45\x4f\x0e\xb1"
  4212. "\xab\xd4\x59\x7f\x9a\x1b\x07\x8e\x3f\x5b\x5a\x6b\xc7";
  4213. a.inLen = XSTRLEN(a.input);
  4214. a.outLen = WC_SHA3_224_DIGEST_SIZE;
  4215. b.input = "abc";
  4216. b.output = "\xe6\x42\x82\x4c\x3f\x8c\xf2\x4a\xd0\x92\x34\xee\x7d\x3c\x76"
  4217. "\x6f\xc9\xa3\xa5\x16\x8d\x0c\x94\xad\x73\xb4\x6f\xdf";
  4218. b.inLen = XSTRLEN(b.input);
  4219. b.outLen = WC_SHA3_224_DIGEST_SIZE;
  4220. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4221. c.output = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55\x74\x49\x44\x79"
  4222. "\xba\x5c\x7e\x7a\xb7\x6e\xf2\x64\xea\xd0\xfc\xce\x33";
  4223. c.inLen = XSTRLEN(c.input);
  4224. c.outLen = WC_SHA3_224_DIGEST_SIZE;
  4225. test_sha[0] = a;
  4226. test_sha[1] = b;
  4227. test_sha[2] = c;
  4228. ret = wc_InitSha3_224(&sha, HEAP_HINT, devId);
  4229. if (ret != 0)
  4230. return WC_TEST_RET_ENC_EC(ret);
  4231. for (i = 0; i < times; ++i) {
  4232. ret = wc_Sha3_224_Update(&sha, (byte*)test_sha[i].input,
  4233. (word32)test_sha[i].inLen);
  4234. if (ret != 0)
  4235. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4236. ret = wc_Sha3_224_GetHash(&sha, hashcopy);
  4237. if (ret != 0)
  4238. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4239. ret = wc_Sha3_224_Final(&sha, hash);
  4240. if (ret != 0)
  4241. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4242. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_224_DIGEST_SIZE) != 0)
  4243. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4244. if (XMEMCMP(hash, hashcopy, WC_SHA3_224_DIGEST_SIZE) != 0)
  4245. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4246. }
  4247. #ifndef NO_LARGE_HASH_TEST
  4248. /* BEGIN LARGE HASH TEST */ {
  4249. byte large_input[1024];
  4250. const char* large_digest =
  4251. "\x13\xe5\xd3\x98\x7b\x94\xda\x41\x12\xc7\x1e\x92\x3a\x19"
  4252. "\x21\x20\x86\x6f\x24\xbf\x0a\x31\xbc\xfd\xd6\x70\x36\xf3";
  4253. for (i = 0; i < (int)sizeof(large_input); i++) {
  4254. large_input[i] = (byte)(i & 0xFF);
  4255. }
  4256. times = 100;
  4257. for (i = 0; i < times; ++i) {
  4258. ret = wc_Sha3_224_Update(&sha, (byte*)large_input,
  4259. (word32)sizeof(large_input));
  4260. if (ret != 0)
  4261. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4262. }
  4263. ret = wc_Sha3_224_Final(&sha, hash);
  4264. if (ret != 0)
  4265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4266. if (XMEMCMP(hash, large_digest, WC_SHA3_224_DIGEST_SIZE) != 0)
  4267. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4268. } /* END LARGE HASH TEST */
  4269. #endif /* NO_LARGE_HASH_TEST */
  4270. exit:
  4271. wc_Sha3_224_Free(&sha);
  4272. return ret;
  4273. }
  4274. #endif /* WOLFSSL_NOSHA3_224 */
  4275. #ifndef WOLFSSL_NOSHA3_256
  4276. static wc_test_ret_t sha3_256_test(void)
  4277. {
  4278. wc_Sha3 sha;
  4279. byte hash[WC_SHA3_256_DIGEST_SIZE];
  4280. byte hashcopy[WC_SHA3_256_DIGEST_SIZE];
  4281. testVector a, b, c;
  4282. testVector test_sha[3];
  4283. wc_test_ret_t ret = 0;
  4284. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4285. byte large_input[1024];
  4286. const char* large_digest =
  4287. "\xdc\x90\xc0\xb1\x25\xdb\x2c\x34\x81\xa3\xff\xbc\x1e\x2e\x87\xeb"
  4288. "\x6d\x70\x85\x61\xe0\xe9\x63\x61\xff\xe5\x84\x4b\x1f\x68\x05\x15";
  4289. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4290. /* test vector with hash of empty string */
  4291. const char* Keccak256EmptyOut =
  4292. "\xc5\xd2\x46\x01\x86\xf7\x23\x3c\x92\x7e\x7d\xb2\xdc\xc7\x03\xc0"
  4293. "\xe5\x00\xb6\x53\xca\x82\x27\x3b\x7b\xfa\xd8\x04\x5d\x85\xa4\x70";
  4294. #endif
  4295. /*
  4296. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-256_Msg0.pdf
  4297. */
  4298. a.input = "";
  4299. a.output = "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66\x51\xc1\x47\x56\xa0\x61\xd6"
  4300. "\x62\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8"
  4301. "\x43\x4a";
  4302. a.inLen = XSTRLEN(a.input);
  4303. a.outLen = WC_SHA3_256_DIGEST_SIZE;
  4304. b.input = "abc";
  4305. b.output = "\x3a\x98\x5d\xa7\x4f\xe2\x25\xb2\x04\x5c\x17\x2d\x6b\xd3\x90"
  4306. "\xbd\x85\x5f\x08\x6e\x3e\x9d\x52\x5b\x46\xbf\xe2\x45\x11\x43"
  4307. "\x15\x32";
  4308. b.inLen = XSTRLEN(b.input);
  4309. b.outLen = WC_SHA3_256_DIGEST_SIZE;
  4310. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4311. c.output = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8\x23\x5e"
  4312. "\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32\xdd\x97\x49\x6d"
  4313. "\x33\x76";
  4314. c.inLen = XSTRLEN(c.input);
  4315. c.outLen = WC_SHA3_256_DIGEST_SIZE;
  4316. test_sha[0] = a;
  4317. test_sha[1] = b;
  4318. test_sha[2] = c;
  4319. ret = wc_InitSha3_256(&sha, HEAP_HINT, devId);
  4320. if (ret != 0)
  4321. return WC_TEST_RET_ENC_EC(ret);
  4322. for (i = 0; i < times; ++i) {
  4323. ret = wc_Sha3_256_Update(&sha, (byte*)test_sha[i].input,
  4324. (word32)test_sha[i].inLen);
  4325. if (ret != 0)
  4326. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4327. ret = wc_Sha3_256_GetHash(&sha, hashcopy);
  4328. if (ret != 0)
  4329. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4330. ret = wc_Sha3_256_Final(&sha, hash);
  4331. if (ret != 0)
  4332. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4333. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_256_DIGEST_SIZE) != 0)
  4334. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4335. if (XMEMCMP(hash, hashcopy, WC_SHA3_256_DIGEST_SIZE) != 0)
  4336. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4337. }
  4338. #ifndef NO_LARGE_HASH_TEST
  4339. /* BEGIN LARGE HASH TEST */ {
  4340. for (i = 0; i < (int)sizeof(large_input); i++) {
  4341. large_input[i] = (byte)(i & 0xFF);
  4342. }
  4343. times = 100;
  4344. for (i = 0; i < times; ++i) {
  4345. ret = wc_Sha3_256_Update(&sha, (byte*)large_input,
  4346. (word32)sizeof(large_input));
  4347. if (ret != 0)
  4348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4349. }
  4350. ret = wc_Sha3_256_Final(&sha, hash);
  4351. if (ret != 0)
  4352. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4353. if (XMEMCMP(hash, large_digest, WC_SHA3_256_DIGEST_SIZE) != 0)
  4354. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4355. } /* END LARGE HASH TEST */
  4356. #endif /* NO_LARGE_HASH_TEST */
  4357. /* this is a software only variant of SHA3 not supported by external hardware devices */
  4358. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4359. /* Test for Keccak256 */
  4360. ret = wc_Sha3_SetFlags(&sha, WC_HASH_SHA3_KECCAK256);
  4361. if (ret != 0) {
  4362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4363. }
  4364. ret = wc_Sha3_256_Update(&sha, (byte*)"", 0);
  4365. if (ret != 0) {
  4366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4367. }
  4368. ret = wc_Sha3_256_Final(&sha, hash);
  4369. if (ret != 0) {
  4370. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4371. }
  4372. if (XMEMCMP(hash, Keccak256EmptyOut, WC_SHA3_256_DIGEST_SIZE) != 0) {
  4373. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4374. }
  4375. #endif /* WOLFSSL_HASH_FLAGS && !WOLFSSL_ASYNC_CRYPT */
  4376. exit:
  4377. wc_Sha3_256_Free(&sha);
  4378. return ret;
  4379. }
  4380. #endif /* WOLFSSL_NOSHA3_256 */
  4381. #ifndef WOLFSSL_NOSHA3_384
  4382. static wc_test_ret_t sha3_384_test(void)
  4383. {
  4384. wc_Sha3 sha;
  4385. byte hash[WC_SHA3_384_DIGEST_SIZE];
  4386. byte buf[64];
  4387. #ifndef NO_INTM_HASH_TEST
  4388. byte hashcopy[WC_SHA3_384_DIGEST_SIZE];
  4389. #endif
  4390. testVector a, b, c;
  4391. testVector test_sha[3];
  4392. wc_test_ret_t ret;
  4393. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4394. /*
  4395. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-384_Msg0.pdf
  4396. */
  4397. a.input = "";
  4398. a.output = "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d\x01\x10\x7d\x85\x2e\x4c\x24"
  4399. "\x85\xc5\x1a\x50\xaa\xaa\x94\xfc\x61\x99\x5e\x71\xbb\xee\x98"
  4400. "\x3a\x2a\xc3\x71\x38\x31\x26\x4a\xdb\x47\xfb\x6b\xd1\xe0\x58"
  4401. "\xd5\xf0\x04";
  4402. a.inLen = XSTRLEN(a.input);
  4403. a.outLen = WC_SHA3_384_DIGEST_SIZE;
  4404. #if defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4405. /* NIST test vector with a length that is a multiple of 4 */
  4406. b.input = "\x7d\x80\xb1\x60\xc4\xb5\x36\xa3\xbe\xb7\x99\x80\x59\x93\x44"
  4407. "\x04\x7c\x5f\x82\xa1\xdf\xc3\xee\xd4";
  4408. b.output = "\x04\x1c\xc5\x86\x1b\xa3\x34\x56\x3c\x61\xd4\xef\x97\x10\xd4"
  4409. "\x89\x6c\x31\x1c\x92\xed\xbe\x0d\x7c\xd5\x3e\x80\x3b\xf2\xf4"
  4410. "\xeb\x60\x57\x23\x55\x70\x77\x0c\xe8\x7c\x55\x20\xd7\xec\x14"
  4411. "\x19\x87\x22";
  4412. b.inLen = XSTRLEN(b.input);
  4413. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4414. #else
  4415. b.input = "abc";
  4416. b.output = "\xec\x01\x49\x82\x88\x51\x6f\xc9\x26\x45\x9f\x58\xe2\xc6\xad"
  4417. "\x8d\xf9\xb4\x73\xcb\x0f\xc0\x8c\x25\x96\xda\x7c\xf0\xe4\x9b"
  4418. "\xe4\xb2\x98\xd8\x8c\xea\x92\x7a\xc7\xf5\x39\xf1\xed\xf2\x28"
  4419. "\x37\x6d\x25";
  4420. b.inLen = XSTRLEN(b.input);
  4421. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4422. #endif
  4423. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4424. c.output = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7\x8a\x49"
  4425. "\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd\xbc\x32\xb9\xd4"
  4426. "\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe\xa1\x9e\xef\x51\xac\xd0"
  4427. "\x65\x7c\x22";
  4428. c.inLen = XSTRLEN(c.input);
  4429. c.outLen = WC_SHA3_384_DIGEST_SIZE;
  4430. #if defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4431. test_sha[0] = b; /* hardware acc. pre-Versal can not handle "" string */
  4432. #else
  4433. test_sha[0] = a;
  4434. #endif
  4435. test_sha[1] = b;
  4436. test_sha[2] = c;
  4437. ret = wc_InitSha3_384(&sha, HEAP_HINT, devId);
  4438. if (ret != 0)
  4439. return WC_TEST_RET_ENC_EC(ret);
  4440. for (i = 0; i < times; ++i) {
  4441. XMEMCPY(buf, test_sha[i].input, test_sha[i].inLen);
  4442. ret = wc_Sha3_384_Update(&sha, buf,
  4443. (word32)test_sha[i].inLen);
  4444. if (ret != 0)
  4445. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4446. #ifndef NO_INTM_HASH_TEST
  4447. ret = wc_Sha3_384_GetHash(&sha, hashcopy);
  4448. if (ret != 0)
  4449. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4450. #endif
  4451. ret = wc_Sha3_384_Final(&sha, hash);
  4452. if (ret != 0)
  4453. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4454. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_384_DIGEST_SIZE) != 0)
  4455. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4456. #ifndef NO_INTM_HASH_TEST
  4457. if (XMEMCMP(hash, hashcopy, WC_SHA3_384_DIGEST_SIZE) != 0)
  4458. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4459. #endif
  4460. }
  4461. #ifndef NO_LARGE_HASH_TEST
  4462. /* BEGIN LARGE HASH TEST */ {
  4463. byte large_input[1024];
  4464. const char* large_digest =
  4465. "\x30\x44\xec\x17\xef\x47\x9f\x55\x36\x11\xd6\x3f\x8a\x31\x5a\x71"
  4466. "\x8a\x71\xa7\x1d\x8e\x84\xe8\x6c\x24\x02\x2f\x7a\x08\x4e\xea\xd7"
  4467. "\x42\x36\x5d\xa8\xc2\xb7\x42\xad\xec\x19\xfb\xca\xc6\x64\xb3\xa4";
  4468. for (i = 0; i < (int)sizeof(large_input); i++) {
  4469. large_input[i] = (byte)(i & 0xFF);
  4470. }
  4471. times = 100;
  4472. for (i = 0; i < times; ++i) {
  4473. ret = wc_Sha3_384_Update(&sha, (byte*)large_input,
  4474. (word32)sizeof(large_input));
  4475. if (ret != 0)
  4476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4477. }
  4478. ret = wc_Sha3_384_Final(&sha, hash);
  4479. if (ret != 0)
  4480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4481. if (XMEMCMP(hash, large_digest, WC_SHA3_384_DIGEST_SIZE) != 0)
  4482. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4483. } /* END LARGE HASH TEST */
  4484. #endif /* NO_LARGE_HASH_TEST */
  4485. exit:
  4486. wc_Sha3_384_Free(&sha);
  4487. return ret;
  4488. }
  4489. #endif /* WOLFSSL_NOSHA3_384 */
  4490. #ifndef WOLFSSL_NOSHA3_512
  4491. static wc_test_ret_t sha3_512_test(void)
  4492. {
  4493. wc_Sha3 sha;
  4494. byte hash[WC_SHA3_512_DIGEST_SIZE];
  4495. byte hashcopy[WC_SHA3_512_DIGEST_SIZE];
  4496. testVector a, b, c;
  4497. testVector test_sha[3];
  4498. wc_test_ret_t ret;
  4499. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4500. /*
  4501. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-512_Msg0.pdf
  4502. */
  4503. a.input = "";
  4504. a.output = "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5\xc8\xb5\x67\xdc\x18\x5a\x75"
  4505. "\x6e\x97\xc9\x82\x16\x4f\xe2\x58\x59\xe0\xd1\xdc\xc1\x47\x5c"
  4506. "\x80\xa6\x15\xb2\x12\x3a\xf1\xf5\xf9\x4c\x11\xe3\xe9\x40\x2c"
  4507. "\x3a\xc5\x58\xf5\x00\x19\x9d\x95\xb6\xd3\xe3\x01\x75\x85\x86"
  4508. "\x28\x1d\xcd\x26";
  4509. a.inLen = XSTRLEN(a.input);
  4510. a.outLen = WC_SHA3_512_DIGEST_SIZE;
  4511. b.input = "abc";
  4512. b.output = "\xb7\x51\x85\x0b\x1a\x57\x16\x8a\x56\x93\xcd\x92\x4b\x6b\x09"
  4513. "\x6e\x08\xf6\x21\x82\x74\x44\xf7\x0d\x88\x4f\x5d\x02\x40\xd2"
  4514. "\x71\x2e\x10\xe1\x16\xe9\x19\x2a\xf3\xc9\x1a\x7e\xc5\x76\x47"
  4515. "\xe3\x93\x40\x57\x34\x0b\x4c\xf4\x08\xd5\xa5\x65\x92\xf8\x27"
  4516. "\x4e\xec\x53\xf0";
  4517. b.inLen = XSTRLEN(b.input);
  4518. b.outLen = WC_SHA3_512_DIGEST_SIZE;
  4519. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4520. c.output = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10\xfc\xa8"
  4521. "\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7\xec\x2f\x1e\x91"
  4522. "\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53\x02\xba\x1b\x0d\x8d\xc7"
  4523. "\x8c\x08\x63\x46\xb5\x33\xb4\x9c\x03\x0d\x99\xa2\x7d\xaf\x11"
  4524. "\x39\xd6\xe7\x5e";
  4525. c.inLen = XSTRLEN(c.input);
  4526. c.outLen = WC_SHA3_512_DIGEST_SIZE;
  4527. test_sha[0] = a;
  4528. test_sha[1] = b;
  4529. test_sha[2] = c;
  4530. ret = wc_InitSha3_512(&sha, HEAP_HINT, devId);
  4531. if (ret != 0)
  4532. return WC_TEST_RET_ENC_EC(ret);
  4533. for (i = 0; i < times; ++i) {
  4534. ret = wc_Sha3_512_Update(&sha, (byte*)test_sha[i].input,
  4535. (word32)test_sha[i].inLen);
  4536. if (ret != 0)
  4537. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4538. ret = wc_Sha3_512_GetHash(&sha, hashcopy);
  4539. if (ret != 0)
  4540. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4541. ret = wc_Sha3_512_Final(&sha, hash);
  4542. if (ret != 0)
  4543. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4544. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_512_DIGEST_SIZE) != 0)
  4545. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4546. if (XMEMCMP(hash, hashcopy, WC_SHA3_512_DIGEST_SIZE) != 0)
  4547. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4548. }
  4549. #ifndef NO_LARGE_HASH_TEST
  4550. /* BEGIN LARGE HASH TEST */ {
  4551. byte large_input[1024];
  4552. const char* large_digest =
  4553. "\x9c\x13\x26\xb6\x26\xb2\x94\x31\xbc\xf4\x34\xe9\x6f\xf2\xd6\x29"
  4554. "\x9a\xd0\x9b\x32\x63\x2f\x18\xa7\x5f\x23\xc9\x60\xc2\x32\x0c\xbc"
  4555. "\x57\x77\x33\xf1\x83\x81\x8a\xd3\x15\x7c\x93\xdc\x80\x9f\xed\x61"
  4556. "\x41\xa7\x5b\xfd\x32\x0e\x38\x15\xb0\x46\x3b\x7a\x4f\xfd\x44\x88";
  4557. for (i = 0; i < (int)sizeof(large_input); i++) {
  4558. large_input[i] = (byte)(i & 0xFF);
  4559. }
  4560. times = 100;
  4561. for (i = 0; i < times; ++i) {
  4562. ret = wc_Sha3_512_Update(&sha, (byte*)large_input,
  4563. (word32)sizeof(large_input));
  4564. if (ret != 0)
  4565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4566. }
  4567. ret = wc_Sha3_512_Final(&sha, hash);
  4568. if (ret != 0)
  4569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4570. if (XMEMCMP(hash, large_digest, WC_SHA3_512_DIGEST_SIZE) != 0)
  4571. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4572. } /* END LARGE HASH TEST */
  4573. #endif /* NO_LARGE_HASH_TEST */
  4574. exit:
  4575. wc_Sha3_512_Free(&sha);
  4576. return ret;
  4577. }
  4578. #endif /* WOLFSSL_NOSHA3_512 */
  4579. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void)
  4580. {
  4581. wc_test_ret_t ret;
  4582. (void)ret;
  4583. WOLFSSL_ENTER("sha3_test");
  4584. #ifndef WOLFSSL_NOSHA3_224
  4585. if ((ret = sha3_224_test()) != 0)
  4586. return ret;
  4587. #endif
  4588. #ifndef WOLFSSL_NOSHA3_256
  4589. if ((ret = sha3_256_test()) != 0)
  4590. return ret;
  4591. #endif
  4592. #ifndef WOLFSSL_NOSHA3_384
  4593. if ((ret = sha3_384_test()) != 0)
  4594. return ret;
  4595. #endif
  4596. #ifndef WOLFSSL_NOSHA3_512
  4597. if ((ret = sha3_512_test()) != 0)
  4598. return ret;
  4599. #endif
  4600. return 0;
  4601. }
  4602. #endif /* WOLFSSL_SHA3 */
  4603. #ifdef WOLFSSL_SHAKE128
  4604. static wc_test_ret_t shake128_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4605. size_t large_input_buf_size)
  4606. {
  4607. testVector a, b, c, d, e;
  4608. testVector test_sha[5];
  4609. wc_test_ret_t ret = 0;
  4610. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4611. static const char large_digest[] =
  4612. "\x2b\xd1\x69\x9f\xb3\x75\x40\x74\xb8\xb2\xd2\x0b\x92\x47\x9b\xfe"
  4613. "\xc9\x91\x48\xbe\xda\xa4\x09\xd7\x61\x35\x18\x05\x07\x71\xa5\x61"
  4614. "\x4d\xc4\x94\xad\xbe\x04\x7d\xad\x95\x2f\xeb\x2c\xc0\x10\x67\x43"
  4615. "\x40\xf1\x4a\x58\x1c\x54\xfa\x24\x1c\x1a\x4e\x8d\x9b\xbc\xea\xa7"
  4616. "\x32\xf2\x4c\xc7\x86\x05\x36\xdc\xb4\x42\xd8\x35\xd1\xb4\xa2\x79"
  4617. "\xa2\xe6\xee\x67\x4f\xbf\x2a\x93\x41\x88\x25\x56\x29\x90\x1a\x06"
  4618. "\xba\xfe\x9f\xa6\x1a\x74\xe8\x7e\x85\x4a\xc8\x58\x60\xb1\x7b\x18"
  4619. "\xdf\x77\x59\x46\x04\xc1\xff\x4b\x9b\xcb\xad\xfe\x91\x28\xf0\x01"
  4620. "\xc1\x33\xd0\x99\x99\x2e\x0c\x86\x84\x67\x4d\x37\xa4\x42\x45\x10"
  4621. "\xdc\x8f\xdb\x6f\xa6\x9b\xee\x8a\x60\xa5\x1f\x95\x3f\x8f\xf5\x31"
  4622. "\x4b\x1d\x48\x1e\x45\xff\x79\x5c\xbe\x72\xfc\x56\xed\x6d\x1a\x99"
  4623. "\x7f\x23\x7c\xd1\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b"
  4624. "\xa3\x60\x51\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41"
  4625. "\x77\x2c\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59"
  4626. "\x0d\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4627. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d\xa8"
  4628. "\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb\x67\x86"
  4629. "\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b\x3d\xca\x95"
  4630. "\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47\xcf\x56\xba\x71"
  4631. "\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a\xff\xb4\xbe\x72\x26"
  4632. "\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e\xd9\xe9\xe6\xf9\xff\xa5";
  4633. byte hash[sizeof(large_digest) - 1];
  4634. /*
  4635. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4636. */
  4637. a.input = "";
  4638. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4639. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4640. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4641. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4642. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4643. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4644. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4645. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a\x04\x30\x2e\x10\xc8\xbc"
  4646. "\x1c\xbf\x1a\x0b\x3a\x51\x20\xea\x17\xcd\xa7\xcf\xad\x76\x5f"
  4647. "\x56\x23\x47\x4d\x36\x8c\xcc\xa8\xaf\x00\x07\xcd\x9f\x5e\x4c"
  4648. "\x84\x9f\x16\x7a\x58\x0b\x14\xaa\xbd\xef\xae\xe7\xee\xf4\x7c"
  4649. "\xb0\xfc\xa9";
  4650. a.inLen = XSTRLEN(a.input);
  4651. a.outLen = WC_SHA3_128_BLOCK_SIZE;
  4652. b.input = "abc";
  4653. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4654. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4655. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4656. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4657. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4658. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4659. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4660. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3\x77\xcf\xb9\xcd\xe4\xc6"
  4661. "\x35\x99\xb2\x7f\x34\x62\xbb\xa4\xa0\xed\x29\x6c\x80\x1f\x9f"
  4662. "\xf7\xf5\x73\x02\xbb\x30\x76\xee\x14\x5f\x97\xa3\x2a\xe6\x8e"
  4663. "\x76\xab\x66\xc4\x8d\x51\x67\x5b\xd4\x9a\xcc\x29\x08\x2f\x56"
  4664. "\x47\x58\x4e";
  4665. b.inLen = XSTRLEN(b.input);
  4666. b.outLen = WC_SHA3_128_BLOCK_SIZE;
  4667. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4668. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4669. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4670. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4671. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4672. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4673. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4674. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4675. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa\x54\x56\x54\xf7\x0a\xe5"
  4676. "\x86\xff\x10\x13\x14\x20\x77\x14\x83\xec\x92\xed\xab\x40\x8c"
  4677. "\x76\x7b\xf4\xc5\xb4\xff\xfa\xa8\x0c\x8c\xa2\x14\xd8\x4c\x4d"
  4678. "\xc7\x00\xd0\xc5\x06\x30\xb2\xff\xc3\x79\x3e\xa4\xd8\x72\x58"
  4679. "\xb4\xc9\x54";
  4680. c.inLen = XSTRLEN(c.input);
  4681. c.outLen = WC_SHA3_128_BLOCK_SIZE;
  4682. /* Taken from NIST CAVP test vectors - full rate output. */
  4683. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4684. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4685. "\x85\xe0";
  4686. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4687. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4688. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4689. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4690. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4691. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4692. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4693. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4694. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4695. "\xa1\x41\x9b\xaf\x60\x52\xc0\xc1\xb4\x45\xf8\x35\x17\x57\xb0"
  4696. "\xd0\x22\x87\x21\x89\xe2\xc0\x27\x3f\x82\xd9\x69\x69\x66\x3e"
  4697. "\x55\x4d\x09";
  4698. d.inLen = 32;
  4699. d.outLen = WC_SHA3_128_BLOCK_SIZE;
  4700. /* Taken from NIST CAVP test vectors - more than one output block. */
  4701. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4702. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4703. "\x47\xe4";
  4704. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4705. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4706. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4707. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4708. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4709. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4710. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4711. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4712. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4713. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4714. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4715. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4716. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4717. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4718. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4719. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4720. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d"
  4721. "\xa8\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb"
  4722. "\x67\x86\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b"
  4723. "\x3d\xca\x95\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47"
  4724. "\xcf\x56\xba\x71\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a"
  4725. "\xff\xb4\xbe\x72\x26\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e"
  4726. "\xd9\xe9\xe6\xf9\xff\xa5";
  4727. e.inLen = 32;
  4728. e.outLen = 2 * WC_SHA3_128_BLOCK_SIZE;
  4729. test_sha[0] = a;
  4730. test_sha[1] = b;
  4731. test_sha[2] = c;
  4732. test_sha[3] = d;
  4733. test_sha[4] = e;
  4734. for (i = 0; i < times; ++i) {
  4735. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4736. if (ret != 0)
  4737. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4738. ret = wc_Shake128_Absorb(sha, (byte*)test_sha[i].input,
  4739. (word32)test_sha[i].inLen);
  4740. if (ret != 0)
  4741. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4742. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4743. (word32)test_sha[i].outLen / WC_SHA3_128_BLOCK_SIZE);
  4744. if (ret != 0)
  4745. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4746. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  4747. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4748. }
  4749. #ifndef NO_LARGE_HASH_TEST
  4750. /* BEGIN LARGE HASH TEST */ {
  4751. for (i = 0; i < (int)large_input_buf_size; i++) {
  4752. large_input_buf[i] = (byte)(i & 0xFF);
  4753. }
  4754. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4755. if (ret != 0)
  4756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4757. /* Absorb is non-incremental. */
  4758. ret = wc_Shake128_Absorb(sha, (byte*)large_input_buf,
  4759. (word32)large_input_buf_size);
  4760. if (ret != 0)
  4761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4762. /* Able to squeeze out blocks incrementally. */
  4763. ret = wc_Shake128_SqueezeBlocks(sha, hash, 1);
  4764. if (ret != 0)
  4765. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4766. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4767. ((word32)sizeof(hash) / WC_SHA3_128_BLOCK_SIZE) - 1);
  4768. if (ret != 0)
  4769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4770. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  4771. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4772. } /* END LARGE HASH TEST */
  4773. #endif /* NO_LARGE_HASH_TEST */
  4774. exit:
  4775. return ret;
  4776. }
  4777. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void)
  4778. {
  4779. wc_Shake sha;
  4780. byte hash[250];
  4781. testVector a, b, c, d, e;
  4782. testVector test_sha[5];
  4783. wc_test_ret_t ret = 0;
  4784. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4785. #define SHAKE128_LARGE_INPUT_BUFSIZ 1024
  4786. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4787. byte *large_input = NULL;
  4788. #else
  4789. byte large_input[SHAKE128_LARGE_INPUT_BUFSIZ];
  4790. #endif
  4791. static const char large_digest[] =
  4792. "\x88\xd7\x0e\x86\x46\x72\x6b\x3d\x7d\x22\xe1\xa9\x2d\x02\xdb\x35"
  4793. "\x92\x4f\x1b\x03\x90\xee\xa3\xce\xd1\x3a\x08\x3a\xd7\x4e\x10\xdf"
  4794. "\x09\x67\x33\x35\x4f\xdd\x38\x50\x5b\xcb\x75\xc7\xba\x65\xe5\xe8"
  4795. "\xb8\x76\xde\xc5\xee\xd7\xf1\x65\x93\x4e\x5e\xc4\xb1\xd7\x6b\xee"
  4796. "\x4b\x57\x48\xf5\x38\x49\x9e\x45\xa0\xf7\x32\xe9\x05\x26\x6a\x10"
  4797. "\x70\xd4\x7c\x19\x01\x1f\x6d\x37\xba\x7b\x74\xc2\xbc\xb6\xbc\x74"
  4798. "\xa3\x66\x6c\x9b\x11\x84\x9d\x4a\x36\xbc\x8a\x0d\x4c\xe3\x39\xfa"
  4799. "\xfa\x1b";
  4800. WOLFSSL_ENTER("shake128_test");
  4801. /*
  4802. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4803. */
  4804. a.input = "";
  4805. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4806. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4807. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4808. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4809. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4810. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4811. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4812. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a";
  4813. a.inLen = XSTRLEN(a.input);
  4814. a.outLen = 114;
  4815. b.input = "abc";
  4816. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4817. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4818. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4819. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4820. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4821. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4822. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4823. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3";
  4824. b.inLen = XSTRLEN(b.input);
  4825. b.outLen = 114;
  4826. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4827. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4828. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4829. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4830. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4831. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4832. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4833. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4834. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa";
  4835. c.inLen = XSTRLEN(c.input);
  4836. c.outLen = 114;
  4837. /* Taken from NIST CAVP test vectors - full rate output. */
  4838. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4839. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4840. "\x85\xe0";
  4841. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4842. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4843. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4844. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4845. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4846. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4847. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4848. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4849. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4850. "\xa1";
  4851. d.inLen = 32;
  4852. d.outLen = 136;
  4853. /* Taken from NIST CAVP test vectors - more than one output block. */
  4854. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4855. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4856. "\x47\xe4";
  4857. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4858. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4859. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4860. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4861. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4862. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4863. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4864. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4865. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4866. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4867. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4868. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4869. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4870. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4871. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4872. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4873. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4";
  4874. e.inLen = 32;
  4875. e.outLen = 250;
  4876. test_sha[0] = a;
  4877. test_sha[1] = b;
  4878. test_sha[2] = c;
  4879. test_sha[3] = d;
  4880. test_sha[4] = e;
  4881. ret = wc_InitShake128(&sha, HEAP_HINT, devId);
  4882. if (ret != 0)
  4883. return WC_TEST_RET_ENC_EC(ret);
  4884. for (i = 0; i < times; ++i) {
  4885. ret = wc_Shake128_Update(&sha, (byte*)test_sha[i].input,
  4886. (word32)test_sha[i].inLen);
  4887. if (ret != 0)
  4888. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4889. ret = wc_Shake128_Final(&sha, hash, (word32)test_sha[i].outLen);
  4890. if (ret != 0)
  4891. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4892. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  4893. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4894. }
  4895. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4896. large_input = (byte *)XMALLOC(SHAKE128_LARGE_INPUT_BUFSIZ, NULL,
  4897. DYNAMIC_TYPE_TMP_BUFFER);
  4898. if (large_input == NULL)
  4899. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  4900. #endif
  4901. #ifndef NO_LARGE_HASH_TEST
  4902. /* BEGIN LARGE HASH TEST */ {
  4903. for (i = 0; i < SHAKE128_LARGE_INPUT_BUFSIZ; i++) {
  4904. large_input[i] = (byte)(i & 0xFF);
  4905. }
  4906. times = 100;
  4907. for (i = 0; i < times; ++i) {
  4908. ret = wc_Shake128_Update(&sha, (byte*)large_input,
  4909. SHAKE128_LARGE_INPUT_BUFSIZ);
  4910. if (ret != 0)
  4911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4912. }
  4913. ret = wc_Shake128_Final(&sha, hash, (word32)sizeof(hash));
  4914. if (ret != 0)
  4915. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4916. if (XMEMCMP(hash, large_digest, sizeof(large_digest) - 1) != 0)
  4917. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4918. } /* END LARGE HASH TEST */
  4919. #endif /* NO_LARGE_HASH_TEST */
  4920. ret = shake128_absorb_test(&sha, large_input, SHAKE128_LARGE_INPUT_BUFSIZ);
  4921. exit:
  4922. wc_Shake128_Free(&sha);
  4923. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4924. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4925. #endif
  4926. return ret;
  4927. }
  4928. #endif
  4929. #ifdef WOLFSSL_SHAKE256
  4930. static wc_test_ret_t shake256_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4931. size_t large_input_buf_size)
  4932. {
  4933. testVector a, b, c, d, e;
  4934. testVector test_sha[5];
  4935. wc_test_ret_t ret = 0;
  4936. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4937. static const char large_digest[] =
  4938. "\x21\x25\x8e\xae\x6e\x4f\xa7\xe1\xb9\x6d\xa7\xc9\x7d\x46\x03\x69"
  4939. "\x29\x0d\x81\x49\xba\x5d\xaf\x37\xfd\xeb\x25\x52\x1d\xd9\xbd\x65"
  4940. "\xfa\x99\xb9\xd1\x70\x6b\xeb\xd4\xc1\x2c\xea\x24\x20\x27\xa7\xcd"
  4941. "\xfa\xe1\x81\xd9\xd5\xc1\x1c\xc7\xe9\x70\xc3\xc7\x21\x6f\x32\x22"
  4942. "\xe3\x27\xdb\x58\x5e\xea\x18\x2d\x63\x4d\x14\x6c\x94\xcf\x2b\x7e"
  4943. "\x6e\x2a\x74\xf3\xe0\xac\xb3\xb2\xcc\xef\x38\xe9\xe7\x35\xb3\xc5"
  4944. "\x77\x9d\xff\xe3\x08\x8e\xf8\x2c\x89\xbb\x45\x22\x16\x99\x91\xc0"
  4945. "\xe7\x71\x57\x75\xc5\xb1\xc6\xaf\x27\xcb\x64\x8c\xc4\xee\x3d\x5f"
  4946. "\x4c\x35\xfb\x1c\xf3\xf8\x0e\xfd\x5e\xfc\x07\xd8\x4d\x55\x32\x49"
  4947. "\x45\x0d\xab\x4a\x49\xc4\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93"
  4948. "\x7a\xe6\x6b\xb4\x36\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43"
  4949. "\x2f\x3b\xfc\x09\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48"
  4950. "\x3d\x0e\xda\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08"
  4951. "\xd9\xdc\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a"
  4952. "\xb7\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  4953. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4\xe6"
  4954. "\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97\x68\x44";
  4955. byte hash[sizeof(large_digest) - 1];
  4956. /*
  4957. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  4958. */
  4959. a.input = "";
  4960. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  4961. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  4962. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  4963. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  4964. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  4965. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  4966. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  4967. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46\xc1\x85\xc1\x51\x11\xe5"
  4968. "\x95\x52\x2a\x6b\xcd\x16\xcf\x86\xf3\xd1\x22\x10\x9e\x3b\x1f"
  4969. "\xdd";
  4970. a.inLen = XSTRLEN(a.input);
  4971. a.outLen = WC_SHA3_256_BLOCK_SIZE;
  4972. b.input = "abc";
  4973. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  4974. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  4975. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  4976. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  4977. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  4978. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  4979. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  4980. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0\x9a\x3e\x6d\x51\xcb\xfc"
  4981. "\x62\x27\x20\xd7\xa7\x5c\x63\x34\xe8\xa2\xd7\xec\x71\xa7\xcc"
  4982. "\x29";
  4983. b.inLen = XSTRLEN(b.input);
  4984. b.outLen = WC_SHA3_256_BLOCK_SIZE;
  4985. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4986. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  4987. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  4988. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  4989. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  4990. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  4991. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  4992. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  4993. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4\x9d\xd3\xef\x7e\x18\x2b"
  4994. "\x15\x24\xdf\x82\xea\x1c\xef\xe1\xc6\xc3\x96\x61\x75\xf0\x22"
  4995. "\x8d";
  4996. c.inLen = XSTRLEN(c.input);
  4997. c.outLen = WC_SHA3_256_BLOCK_SIZE;
  4998. /* Taken from NIST CAVP test vectors - full rate output. */
  4999. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  5000. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  5001. "\x85\xe0";
  5002. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5003. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5004. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5005. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5006. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5007. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5008. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5009. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5010. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5011. "\xc2";
  5012. d.inLen = 32;
  5013. d.outLen = WC_SHA3_256_BLOCK_SIZE;
  5014. /* Taken from NIST CAVP test vectors - more than one output block. */
  5015. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5016. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5017. "\x47\xe4";
  5018. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5019. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5020. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5021. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5022. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5023. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5024. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5025. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5026. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5027. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5028. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5029. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5030. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5031. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5032. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5033. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5034. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4"
  5035. "\xe6\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97"
  5036. "\x68\x44";
  5037. e.inLen = 32;
  5038. e.outLen = 2 * WC_SHA3_256_BLOCK_SIZE;
  5039. test_sha[0] = a;
  5040. test_sha[1] = b;
  5041. test_sha[2] = c;
  5042. test_sha[3] = d;
  5043. test_sha[4] = e;
  5044. for (i = 0; i < times; ++i) {
  5045. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  5046. if (ret != 0)
  5047. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5048. ret = wc_Shake256_Absorb(sha, (byte*)test_sha[i].input,
  5049. (word32)test_sha[i].inLen);
  5050. if (ret != 0)
  5051. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5052. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  5053. (word32)test_sha[i].outLen / WC_SHA3_256_BLOCK_SIZE);
  5054. if (ret != 0)
  5055. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5056. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  5057. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5058. }
  5059. #ifndef NO_LARGE_HASH_TEST
  5060. /* BEGIN LARGE HASH TEST */ {
  5061. for (i = 0; i < (int)large_input_buf_size; i++) {
  5062. large_input_buf[i] = (byte)(i & 0xFF);
  5063. }
  5064. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  5065. if (ret != 0)
  5066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5067. /* Absorb is non-incremental. */
  5068. ret = wc_Shake256_Absorb(sha, large_input_buf,
  5069. (word32)large_input_buf_size);
  5070. if (ret != 0)
  5071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5072. /* Able to squeeze out blocks incrementally. */
  5073. ret = wc_Shake256_SqueezeBlocks(sha, hash, 1);
  5074. if (ret != 0)
  5075. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5076. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  5077. ((word32)sizeof(hash) / WC_SHA3_256_BLOCK_SIZE) - 1);
  5078. if (ret != 0)
  5079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5080. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  5081. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5082. } /* END LARGE HASH TEST */
  5083. #endif /* NO_LARGE_HASH_TEST */
  5084. exit:
  5085. return ret;
  5086. }
  5087. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void)
  5088. {
  5089. wc_Shake sha;
  5090. byte hash[250];
  5091. testVector a, b, c, d, e;
  5092. testVector test_sha[5];
  5093. wc_test_ret_t ret = 0;
  5094. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  5095. #define SHAKE256_LARGE_INPUT_BUFSIZ 1024
  5096. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5097. byte *large_input = NULL;
  5098. #else
  5099. byte large_input[SHAKE256_LARGE_INPUT_BUFSIZ];
  5100. #endif
  5101. const char* large_digest =
  5102. "\x90\x32\x4a\xcc\xd1\xdf\xb8\x0b\x79\x1f\xb8\xc8\x5b\x54\xc8\xe7"
  5103. "\x45\xf5\x60\x6b\x38\x26\xb2\x0a\xee\x38\x01\xf3\xd9\xfa\x96\x9f"
  5104. "\x6a\xd7\x15\xdf\xb6\xc2\xf4\x20\x33\x44\x55\xe8\x2a\x09\x2b\x68"
  5105. "\x2e\x18\x65\x5e\x65\x93\x28\xbc\xb1\x9e\xe2\xb1\x92\xea\x98\xac"
  5106. "\x21\xef\x4c\xe1\xb4\xb7\xbe\x81\x5c\x1d\xd3\xb7\x17\xe5\xbb\xc5"
  5107. "\x8c\x68\xb7\xfb\xac\x55\x8a\x9b\x4d\x91\xe4\x9f\x72\xbb\x6e\x38"
  5108. "\xaf\x21\x7d\x21\xaa\x98\x4e\x75\xc4\xb4\x1c\x7c\x50\x45\x54\xf9"
  5109. "\xea\x26";
  5110. WOLFSSL_ENTER("shake256_test");
  5111. /*
  5112. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  5113. */
  5114. a.input = "";
  5115. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  5116. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  5117. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  5118. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  5119. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  5120. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  5121. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  5122. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46";
  5123. a.inLen = XSTRLEN(a.input);
  5124. a.outLen = 114;
  5125. b.input = "abc";
  5126. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  5127. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  5128. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  5129. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  5130. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  5131. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  5132. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  5133. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0";
  5134. b.inLen = XSTRLEN(b.input);
  5135. b.outLen = 114;
  5136. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5137. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  5138. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  5139. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  5140. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  5141. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  5142. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  5143. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  5144. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  5145. c.inLen = XSTRLEN(c.input);
  5146. c.outLen = 114;
  5147. /* Taken from NIST CAVP test vectors - full rate output. */
  5148. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  5149. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  5150. "\x85\xe0";
  5151. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5152. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5153. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5154. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5155. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5156. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5157. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5158. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5159. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5160. "\xc2";
  5161. d.inLen = 32;
  5162. d.outLen = 136;
  5163. /* Taken from NIST CAVP test vectors - more than one output block. */
  5164. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5165. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5166. "\x47\xe4";
  5167. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5168. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5169. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5170. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5171. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5172. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5173. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5174. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5175. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5176. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5177. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5178. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5179. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5180. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5181. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5182. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5183. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c";
  5184. e.inLen = 32;
  5185. e.outLen = 250;
  5186. test_sha[0] = a;
  5187. test_sha[1] = b;
  5188. test_sha[2] = c;
  5189. test_sha[3] = d;
  5190. test_sha[4] = e;
  5191. ret = wc_InitShake256(&sha, HEAP_HINT, devId);
  5192. if (ret != 0)
  5193. return WC_TEST_RET_ENC_EC(ret);
  5194. for (i = 0; i < times; ++i) {
  5195. ret = wc_Shake256_Update(&sha, (byte*)test_sha[i].input,
  5196. (word32)test_sha[i].inLen);
  5197. if (ret != 0)
  5198. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5199. ret = wc_Shake256_Final(&sha, hash, (word32)test_sha[i].outLen);
  5200. if (ret != 0)
  5201. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5202. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  5203. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5204. }
  5205. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5206. large_input = (byte *)XMALLOC(SHAKE256_LARGE_INPUT_BUFSIZ, NULL,
  5207. DYNAMIC_TYPE_TMP_BUFFER);
  5208. if (large_input == NULL)
  5209. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  5210. #endif
  5211. #ifndef NO_LARGE_HASH_TEST
  5212. /* BEGIN LARGE HASH TEST */ {
  5213. for (i = 0; i < SHAKE256_LARGE_INPUT_BUFSIZ; i++) {
  5214. large_input[i] = (byte)(i & 0xFF);
  5215. }
  5216. times = 100;
  5217. for (i = 0; i < times; ++i) {
  5218. ret = wc_Shake256_Update(&sha, (byte*)large_input,
  5219. SHAKE256_LARGE_INPUT_BUFSIZ);
  5220. if (ret != 0)
  5221. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5222. }
  5223. ret = wc_Shake256_Final(&sha, hash, (word32)sizeof(hash));
  5224. if (ret != 0)
  5225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5226. if (XMEMCMP(hash, large_digest, 114) != 0)
  5227. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5228. } /* END LARGE HASH TEST */
  5229. #endif /* NO_LARGE_HASH_TEST */
  5230. ret = shake256_absorb_test(&sha, large_input, SHAKE256_LARGE_INPUT_BUFSIZ);
  5231. exit:
  5232. wc_Shake256_Free(&sha);
  5233. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5234. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5235. #endif
  5236. return ret;
  5237. }
  5238. #endif
  5239. #ifdef WOLFSSL_SM3
  5240. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void)
  5241. {
  5242. wc_Sm3 sm3, sm3Copy;
  5243. byte hash[WC_SM3_DIGEST_SIZE];
  5244. byte hashGet[WC_SM3_DIGEST_SIZE];
  5245. byte hashCopy[WC_SM3_DIGEST_SIZE];
  5246. wc_test_ret_t ret = 0;
  5247. WOLFSSL_ENTER("sm3_test");
  5248. testVector a, b, c;
  5249. testVector test_sm3[3];
  5250. int times = sizeof(test_sm3) / sizeof(struct testVector), i;
  5251. a.input = "";
  5252. a.output = "\x1a\xb2\x1d\x83\x55\xcf\xa1\x7f\x8e\x61\x19\x48\x31\xe8\x1a"
  5253. "\x8f\x22\xbe\xc8\xc7\x28\xfe\xfb\x74\x7e\xd0\x35\xeb\x50\x82"
  5254. "\xaa\x2b";
  5255. a.inLen = XSTRLEN(a.input);
  5256. a.outLen = WC_SM3_DIGEST_SIZE;
  5257. b.input = "abc";
  5258. b.output = "\x66\xc7\xf0\xf4\x62\xee\xed\xd9\xd1\xf2\xd4\x6b\xdc\x10\xe4"
  5259. "\xe2\x41\x67\xc4\x87\x5c\xf2\xf7\xa2\x29\x7d\xa0\x2b\x8f\x4b"
  5260. "\xa8\xe0";
  5261. b.inLen = XSTRLEN(b.input);
  5262. b.outLen = WC_SM3_DIGEST_SIZE;
  5263. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5264. c.output = "\x63\x9b\x6c\xc5\xe6\x4d\x9e\x37\xa3\x90\xb1\x92\xdf\x4f\xa1"
  5265. "\xea\x07\x20\xab\x74\x7f\xf6\x92\xb9\xf3\x8c\x4e\x66\xad\x7b"
  5266. "\x8c\x05";
  5267. c.inLen = XSTRLEN(c.input);
  5268. c.outLen = WC_SM3_DIGEST_SIZE;
  5269. test_sm3[0] = a;
  5270. test_sm3[1] = b;
  5271. test_sm3[2] = c;
  5272. ret = wc_InitSm3(&sm3, HEAP_HINT, devId);
  5273. if (ret != 0)
  5274. return WC_TEST_RET_ENC_EC(ret);
  5275. ret = wc_InitSm3(&sm3Copy, HEAP_HINT, devId);
  5276. if (ret != 0) {
  5277. wc_Sm3Free(&sm3);
  5278. return WC_TEST_RET_ENC_EC(ret);
  5279. }
  5280. /* Test all the KATs. */
  5281. for (i = 0; i < times; ++i) {
  5282. ret = wc_Sm3Update(&sm3, (byte*)test_sm3[i].input,
  5283. (word32)test_sm3[i].inLen);
  5284. if (ret != 0) {
  5285. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5286. }
  5287. /* Get the final hash but leave ready for more updates. */
  5288. ret = wc_Sm3GetHash(&sm3, hashGet);
  5289. if (ret != 0)
  5290. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5291. /* Make a copy of the hash. */
  5292. ret = wc_Sm3Copy(&sm3, &sm3Copy);
  5293. if (ret != 0)
  5294. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5295. /* Get the final hash with original. */
  5296. ret = wc_Sm3Final(&sm3, hash);
  5297. if (ret != 0)
  5298. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5299. /* Get the final hash with copy. */
  5300. ret = wc_Sm3Final(&sm3Copy, hashCopy);
  5301. if (ret != 0)
  5302. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5303. /* Dispose of copy. */
  5304. wc_Sm3Free(&sm3Copy);
  5305. /* Check hashes match expected. */
  5306. if (XMEMCMP(hash, test_sm3[i].output, WC_SM3_DIGEST_SIZE) != 0)
  5307. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5308. if (XMEMCMP(hash, hashGet, WC_SM3_DIGEST_SIZE) != 0)
  5309. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5310. if (XMEMCMP(hash, hashCopy, WC_SM3_DIGEST_SIZE) != 0)
  5311. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5312. }
  5313. #ifndef NO_LARGE_HASH_TEST
  5314. {
  5315. word32 sz;
  5316. byte large_input[1024];
  5317. #ifdef HASH_SIZE_LIMIT
  5318. const char* large_digest =
  5319. "\x6c\x42\x57\x64\x8e\x45\xf3\xb6\xc0\x83\xd3\x41\x83\x66\x51\xb4"
  5320. "\x50\xfe\x06\xb5\xb7\x1e\xd5\x0d\x41\xfc\x1e\xe5\xc6\x57\x95\x0f";
  5321. times = 20;
  5322. #else
  5323. const char* large_digest =
  5324. "\x34\x51\x3c\xde\x7c\x30\xb7\xc5\xaa\x97\x3b\xed\xb3\x16\xb9\x76"
  5325. "\x35\x46\x14\x80\x2a\x57\xca\xd9\x48\xf9\x93\xcc\x1f\xdd\xab\x79";
  5326. times = 100;
  5327. #endif
  5328. /* Set large input to something. */
  5329. for (i = 0; i < (int)sizeof(large_input); i++) {
  5330. large_input[i] = (byte)(i & 0xFF);
  5331. }
  5332. /* Hash a large number of times. */
  5333. for (i = 0; i < times; ++i) {
  5334. ret = wc_Sm3Update(&sm3, (byte*)large_input,
  5335. (word32)sizeof(large_input));
  5336. if (ret != 0)
  5337. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5338. }
  5339. /* Calculate hash and compare to expected. */
  5340. ret = wc_Sm3Final(&sm3, hash);
  5341. if (ret != 0)
  5342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5343. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5345. /* Check updating with various sizes works. */
  5346. for (sz = 1; sz <= 64; sz++) {
  5347. /* Hash a large number of times. */
  5348. for (i = 0; i < times; ++i) {
  5349. word32 o;
  5350. /* Update sz bytes at a time from large input buffer. */
  5351. for (o = 0; o + sz <= (word32)sizeof(large_input); o += sz) {
  5352. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o), sz);
  5353. if (ret != 0)
  5354. ERROR_OUT(WC_TEST_RET_ENC_I(o), exit);
  5355. }
  5356. /* Check for left-overs. */
  5357. if (o < (word32)sizeof(large_input)) {
  5358. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o),
  5359. (word32)sizeof(large_input) - o);
  5360. if (ret != 0)
  5361. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5362. }
  5363. }
  5364. /* Calculate hash and compare to expected. */
  5365. ret = wc_Sm3Final(&sm3, hash);
  5366. if (ret != 0)
  5367. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5368. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5369. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5370. }
  5371. }
  5372. #endif /* NO_LARGE_HASH_TEST */
  5373. exit:
  5374. wc_Sm3Free(&sm3);
  5375. wc_Sm3Free(&sm3Copy);
  5376. return ret;
  5377. }
  5378. #endif
  5379. #ifndef NO_HASH_WRAPPER
  5380. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void)
  5381. {
  5382. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5383. wc_HashAlg *hash = NULL;
  5384. #else
  5385. wc_HashAlg hash[1];
  5386. #endif
  5387. int ret, exp_ret;
  5388. int i, j;
  5389. int digestSz;
  5390. byte data[] = "0123456789abcdef0123456789abcdef0123456";
  5391. byte out[WC_MAX_DIGEST_SIZE];
  5392. byte hashOut[WC_MAX_DIGEST_SIZE];
  5393. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5394. enum wc_HashType hashType;
  5395. #endif
  5396. enum wc_HashType typesGood[] = { WC_HASH_TYPE_MD5, WC_HASH_TYPE_SHA,
  5397. WC_HASH_TYPE_SHA224, WC_HASH_TYPE_SHA256,
  5398. WC_HASH_TYPE_SHA384, WC_HASH_TYPE_SHA512,
  5399. WC_HASH_TYPE_SHA3_224,
  5400. WC_HASH_TYPE_SHA3_256,
  5401. WC_HASH_TYPE_SHA3_384,
  5402. WC_HASH_TYPE_SHA3_512 };
  5403. enum wc_HashType typesNoImpl[] = {
  5404. #ifdef NO_MD5
  5405. WC_HASH_TYPE_MD5,
  5406. #endif
  5407. #ifdef NO_SHA
  5408. WC_HASH_TYPE_SHA,
  5409. #endif
  5410. #ifndef WOLFSSL_SHA224
  5411. WC_HASH_TYPE_SHA224,
  5412. #endif
  5413. #ifdef NO_SHA256
  5414. WC_HASH_TYPE_SHA256,
  5415. #endif
  5416. #ifndef WOLFSSL_SHA384
  5417. WC_HASH_TYPE_SHA384,
  5418. #endif
  5419. #ifndef WOLFSSL_SHA512
  5420. WC_HASH_TYPE_SHA512,
  5421. #endif
  5422. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_224)
  5423. WC_HASH_TYPE_SHA3_224,
  5424. #endif
  5425. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_256)
  5426. WC_HASH_TYPE_SHA3_256,
  5427. #endif
  5428. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_384)
  5429. WC_HASH_TYPE_SHA3_384,
  5430. #endif
  5431. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_512)
  5432. WC_HASH_TYPE_SHA3_512,
  5433. #endif
  5434. WC_HASH_TYPE_NONE
  5435. };
  5436. enum wc_HashType typesBad[] = { WC_HASH_TYPE_NONE, WC_HASH_TYPE_MD5_SHA,
  5437. WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4 };
  5438. enum wc_HashType typesHashBad[] = { WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4,
  5439. WC_HASH_TYPE_BLAKE2B,
  5440. WC_HASH_TYPE_NONE };
  5441. WOLFSSL_ENTER("hash_test");
  5442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5443. hash = wc_HashNew(WC_HASH_TYPE_SHA256, HEAP_HINT, devId, &ret);
  5444. if (hash == NULL) {
  5445. return WC_TEST_RET_ENC_EC(ret);
  5446. }
  5447. #else
  5448. XMEMSET(hash, 0, sizeof(wc_HashAlg));
  5449. #endif
  5450. /* Parameter Validation testing. */
  5451. ret = wc_HashInit(NULL, WC_HASH_TYPE_SHA256);
  5452. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5453. return WC_TEST_RET_ENC_EC(ret);
  5454. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5455. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5456. return WC_TEST_RET_ENC_EC(ret);
  5457. ret = wc_HashUpdate(hash, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5458. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5459. return WC_TEST_RET_ENC_EC(ret);
  5460. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, data, sizeof(data));
  5461. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5462. return WC_TEST_RET_ENC_EC(ret);
  5463. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, NULL);
  5464. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5465. return WC_TEST_RET_ENC_EC(ret);
  5466. ret = wc_HashFinal(hash, WC_HASH_TYPE_SHA256, NULL);
  5467. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5468. return WC_TEST_RET_ENC_EC(ret);
  5469. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, out);
  5470. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5471. return WC_TEST_RET_ENC_EC(ret);
  5472. /* Try invalid hash algorithms. */
  5473. for (i = 0; i < (int)(sizeof(typesBad)/sizeof(*typesBad)); i++) {
  5474. ret = wc_HashInit(hash, typesBad[i]);
  5475. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5476. return WC_TEST_RET_ENC_I(i);
  5477. ret = wc_HashUpdate(hash, typesBad[i], data, sizeof(data));
  5478. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5479. return WC_TEST_RET_ENC_I(i);
  5480. ret = wc_HashFinal(hash, typesBad[i], out);
  5481. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5482. return WC_TEST_RET_ENC_I(i);
  5483. wc_HashFree(hash, typesBad[i]);
  5484. }
  5485. /* Try valid hash algorithms. */
  5486. for (i = 0, j = 0; i < (int)(sizeof(typesGood)/sizeof(*typesGood)); i++) {
  5487. exp_ret = 0;
  5488. if (typesGood[i] == typesNoImpl[j]) {
  5489. /* Recognized but no implementation compiled in. */
  5490. exp_ret = HASH_TYPE_E;
  5491. j++;
  5492. }
  5493. ret = wc_HashInit(hash, typesGood[i]);
  5494. if (ret != exp_ret)
  5495. return WC_TEST_RET_ENC_I(i);
  5496. ret = wc_HashUpdate(hash, typesGood[i], data, sizeof(data));
  5497. if (ret != exp_ret)
  5498. return WC_TEST_RET_ENC_I(i);
  5499. ret = wc_HashFinal(hash, typesGood[i], out);
  5500. if (ret != exp_ret)
  5501. return WC_TEST_RET_ENC_I(i);
  5502. wc_HashFree(hash, typesGood[i]);
  5503. digestSz = wc_HashGetDigestSize(typesGood[i]);
  5504. if (exp_ret < 0 && digestSz != exp_ret)
  5505. return WC_TEST_RET_ENC_I(i);
  5506. if (exp_ret == 0 && digestSz < 0)
  5507. return WC_TEST_RET_ENC_I(i);
  5508. if (exp_ret == 0) {
  5509. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut,
  5510. (word32)digestSz - 1);
  5511. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  5512. return WC_TEST_RET_ENC_I(i);
  5513. }
  5514. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, (word32)digestSz);
  5515. if (ret != exp_ret)
  5516. return WC_TEST_RET_ENC_I(i);
  5517. if (exp_ret == 0 && XMEMCMP(out, hashOut, (word32)digestSz) != 0)
  5518. return WC_TEST_RET_ENC_I(i);
  5519. ret = wc_HashGetBlockSize(typesGood[i]);
  5520. if (exp_ret < 0 && ret != exp_ret)
  5521. return WC_TEST_RET_ENC_I(i);
  5522. if (exp_ret == 0 && ret < 0)
  5523. return WC_TEST_RET_ENC_I(i);
  5524. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5525. ret = wc_HashGetOID(typesGood[i]);
  5526. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG) ||
  5527. (exp_ret == 0 && ret == WC_NO_ERR_TRACE(HASH_TYPE_E)) ||
  5528. (exp_ret != 0 && ret != WC_NO_ERR_TRACE(HASH_TYPE_E))) {
  5529. return WC_TEST_RET_ENC_I(i);
  5530. }
  5531. hashType = wc_OidGetHash(ret);
  5532. if (exp_ret == 0 && hashType != typesGood[i])
  5533. return WC_TEST_RET_ENC_I(i);
  5534. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5535. }
  5536. for (i = 0; i < (int)(sizeof(typesHashBad)/sizeof(*typesHashBad)); i++) {
  5537. ret = wc_Hash(typesHashBad[i], data, sizeof(data), out, sizeof(out));
  5538. if ((ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) &&
  5539. (ret != WC_NO_ERR_TRACE(BUFFER_E)) &&
  5540. (ret != WC_NO_ERR_TRACE(HASH_TYPE_E)))
  5541. {
  5542. return WC_TEST_RET_ENC_I(i);
  5543. }
  5544. }
  5545. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5546. ret = wc_HashGetOID(WC_HASH_TYPE_MD2);
  5547. #ifdef WOLFSSL_MD2
  5548. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5549. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5550. {
  5551. return WC_TEST_RET_ENC_EC(ret);
  5552. }
  5553. #else
  5554. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5555. return WC_TEST_RET_ENC_EC(ret);
  5556. #endif
  5557. hashType = wc_OidGetHash(646); /* Md2h */
  5558. #ifdef WOLFSSL_MD2
  5559. if (hashType != WC_HASH_TYPE_MD2)
  5560. return WC_TEST_RET_ENC_NC;
  5561. #else
  5562. if (hashType != WC_HASH_TYPE_NONE)
  5563. return WC_TEST_RET_ENC_NC;
  5564. #endif
  5565. ret = wc_HashGetOID(WC_HASH_TYPE_MD5_SHA);
  5566. #ifndef NO_MD5
  5567. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5568. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5569. {
  5570. return WC_TEST_RET_ENC_EC(ret);
  5571. }
  5572. #else
  5573. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5574. return WC_TEST_RET_ENC_EC(ret);
  5575. #endif
  5576. ret = wc_HashGetOID(WC_HASH_TYPE_MD4);
  5577. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5578. return WC_TEST_RET_ENC_EC(ret);
  5579. ret = wc_HashGetOID(WC_HASH_TYPE_NONE);
  5580. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5581. return WC_TEST_RET_ENC_EC(ret);
  5582. hashType = wc_OidGetHash(0);
  5583. if (hashType != WC_HASH_TYPE_NONE)
  5584. return WC_TEST_RET_ENC_NC;
  5585. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5586. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD2);
  5587. #ifdef WOLFSSL_MD2
  5588. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5589. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5590. {
  5591. return WC_TEST_RET_ENC_EC(ret);
  5592. }
  5593. #else
  5594. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5595. return WC_TEST_RET_ENC_EC(ret);
  5596. #endif
  5597. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD2);
  5598. #ifdef WOLFSSL_MD2
  5599. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5600. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5601. {
  5602. return WC_TEST_RET_ENC_EC(ret);
  5603. }
  5604. #else
  5605. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5606. return WC_TEST_RET_ENC_EC(ret);
  5607. #endif
  5608. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD4);
  5609. #ifndef NO_MD4
  5610. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5611. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5612. {
  5613. return WC_TEST_RET_ENC_EC(ret);
  5614. }
  5615. #else
  5616. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5617. return WC_TEST_RET_ENC_EC(ret);
  5618. #endif
  5619. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD4);
  5620. #ifndef NO_MD4
  5621. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5622. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5623. {
  5624. return WC_TEST_RET_ENC_EC(ret);
  5625. }
  5626. #else
  5627. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5628. return WC_TEST_RET_ENC_EC(ret);
  5629. #endif
  5630. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD5_SHA);
  5631. #if !defined(NO_MD5) && !defined(NO_SHA)
  5632. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5633. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5634. {
  5635. return WC_TEST_RET_ENC_EC(ret);
  5636. }
  5637. #else
  5638. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5639. return WC_TEST_RET_ENC_EC(ret);
  5640. #endif
  5641. ret = wc_HashGetBlockSize(WC_HASH_TYPE_BLAKE2B);
  5642. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5643. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5644. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5645. {
  5646. return WC_TEST_RET_ENC_EC(ret);
  5647. }
  5648. #else
  5649. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5650. return WC_TEST_RET_ENC_EC(ret);
  5651. #endif
  5652. ret = wc_HashGetDigestSize(WC_HASH_TYPE_BLAKE2B);
  5653. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5654. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5655. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5656. {
  5657. return WC_TEST_RET_ENC_EC(ret);
  5658. }
  5659. #else
  5660. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5661. return WC_TEST_RET_ENC_EC(ret);
  5662. #endif
  5663. ret = wc_HashGetBlockSize(WC_HASH_TYPE_NONE);
  5664. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5665. return WC_TEST_RET_ENC_EC(ret);
  5666. ret = wc_HashGetDigestSize(WC_HASH_TYPE_NONE);
  5667. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5668. return WC_TEST_RET_ENC_EC(ret);
  5669. #if !defined(NO_CERTS) && !defined(NO_ASN)
  5670. #if defined(WOLFSSL_MD2) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  5671. ret = wc_GetCTC_HashOID(MD2);
  5672. if (ret == 0)
  5673. return WC_TEST_RET_ENC_EC(ret);
  5674. #endif
  5675. #ifndef NO_MD5
  5676. ret = wc_GetCTC_HashOID(WC_MD5);
  5677. if (ret == 0)
  5678. return WC_TEST_RET_ENC_EC(ret);
  5679. #endif
  5680. #ifndef NO_SHA
  5681. ret = wc_GetCTC_HashOID(WC_SHA);
  5682. if (ret == 0)
  5683. return WC_TEST_RET_ENC_EC(ret);
  5684. #endif
  5685. #ifdef WOLFSSL_SHA224
  5686. ret = wc_GetCTC_HashOID(WC_SHA224);
  5687. if (ret == 0)
  5688. return WC_TEST_RET_ENC_EC(ret);
  5689. #endif
  5690. #ifndef NO_SHA256
  5691. ret = wc_GetCTC_HashOID(WC_SHA256);
  5692. if (ret == 0)
  5693. return WC_TEST_RET_ENC_EC(ret);
  5694. #endif
  5695. #ifdef WOLFSSL_SHA384
  5696. ret = wc_GetCTC_HashOID(WC_SHA384);
  5697. if (ret == 0)
  5698. return WC_TEST_RET_ENC_EC(ret);
  5699. #endif
  5700. #ifdef WOLFSSL_SHA512
  5701. ret = wc_GetCTC_HashOID(WC_SHA512);
  5702. if (ret == 0)
  5703. return WC_TEST_RET_ENC_EC(ret);
  5704. #endif
  5705. ret = wc_GetCTC_HashOID(-1);
  5706. if (ret != 0)
  5707. return WC_TEST_RET_ENC_EC(ret);
  5708. #endif
  5709. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5710. (void)wc_HashDelete(hash, &hash);
  5711. #endif
  5712. return 0;
  5713. }
  5714. #endif /* !NO_HASH_WRAPPER */
  5715. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS) && \
  5716. defined(HAVE_FIPS_VERSION) && \
  5717. (HAVE_FIPS_VERSION >= 5))
  5718. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void)
  5719. {
  5720. Hmac hmac;
  5721. byte hash[WC_MD5_DIGEST_SIZE];
  5722. const char* keys[]=
  5723. {
  5724. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  5725. "Jefe",
  5726. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA",
  5727. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5728. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5729. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5730. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5731. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5732. };
  5733. testVector a, b, c, d;
  5734. testVector test_hmac[4];
  5735. wc_test_ret_t ret;
  5736. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5737. WOLFSSL_ENTER("hmac_md5_test");
  5738. /* Following test vectors are from RFC 2202 section 2 */
  5739. a.input = "Hi There";
  5740. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  5741. "\x9d";
  5742. a.inLen = XSTRLEN(a.input);
  5743. a.outLen = WC_MD5_DIGEST_SIZE;
  5744. b.input = "what do ya want for nothing?";
  5745. b.output = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
  5746. "\x38";
  5747. b.inLen = XSTRLEN(b.input);
  5748. b.outLen = WC_MD5_DIGEST_SIZE;
  5749. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5750. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5751. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5752. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5753. c.output = "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
  5754. "\xf6";
  5755. c.inLen = XSTRLEN(c.input);
  5756. c.outLen = WC_MD5_DIGEST_SIZE;
  5757. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5758. d.output = "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0"
  5759. "\xcd";
  5760. d.inLen = XSTRLEN(d.input);
  5761. d.outLen = WC_MD5_DIGEST_SIZE;
  5762. test_hmac[0] = a;
  5763. test_hmac[1] = b;
  5764. test_hmac[2] = c;
  5765. test_hmac[3] = d;
  5766. for (i = 0; i < times; ++i) {
  5767. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5768. if (i == 1) {
  5769. continue; /* cavium can't handle short keys, fips not allowed */
  5770. }
  5771. #endif
  5772. ret = wc_HmacInit(&hmac, HEAP_HINT, devId);
  5773. if (ret != 0)
  5774. return WC_TEST_RET_ENC_EC(ret);
  5775. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i],
  5776. (word32)XSTRLEN(keys[i]));
  5777. if (ret != 0)
  5778. return WC_TEST_RET_ENC_EC(ret);
  5779. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5780. (word32)test_hmac[i].inLen);
  5781. if (ret != 0)
  5782. return WC_TEST_RET_ENC_EC(ret);
  5783. ret = wc_HmacFinal(&hmac, hash);
  5784. if (ret != 0)
  5785. return WC_TEST_RET_ENC_EC(ret);
  5786. if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0)
  5787. return WC_TEST_RET_ENC_I(i);
  5788. wc_HmacFree(&hmac);
  5789. }
  5790. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5791. if ((ret = wc_HmacSizeByType(WC_MD5)) != WC_MD5_DIGEST_SIZE)
  5792. return WC_TEST_RET_ENC_EC(ret);
  5793. #endif
  5794. return 0;
  5795. }
  5796. #endif /* !NO_HMAC && !NO_MD5 && (!HAVE_FIPS || (HAVE_FIPS_VERSION < 5)) */
  5797. #if !defined(NO_HMAC) && !defined(NO_SHA)
  5798. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void)
  5799. {
  5800. Hmac hmac;
  5801. byte hash[WC_SHA_DIGEST_SIZE];
  5802. const char* keys[]=
  5803. {
  5804. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5805. "\x0b\x0b\x0b",
  5806. "Jefe",
  5807. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5808. "\xAA\xAA\xAA",
  5809. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5810. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5811. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5812. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5813. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5814. };
  5815. testVector a, b, c, d;
  5816. testVector test_hmac[4];
  5817. wc_test_ret_t ret;
  5818. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5819. WOLFSSL_ENTER("hmac_sha_test");
  5820. /* Following test vectors are from RFC 2202 section 3 */
  5821. a.input = "Hi There";
  5822. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  5823. "\x8e\xf1\x46\xbe\x00";
  5824. a.inLen = XSTRLEN(a.input);
  5825. a.outLen = WC_SHA_DIGEST_SIZE;
  5826. b.input = "what do ya want for nothing?";
  5827. b.output = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf"
  5828. "\x9c\x25\x9a\x7c\x79";
  5829. b.inLen = XSTRLEN(b.input);
  5830. b.outLen = WC_SHA_DIGEST_SIZE;
  5831. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5832. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5833. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5834. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5835. c.output = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b"
  5836. "\x4f\x63\xf1\x75\xd3";
  5837. c.inLen = XSTRLEN(c.input);
  5838. c.outLen = WC_SHA_DIGEST_SIZE;
  5839. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5840. d.output = "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b"
  5841. "\x55\xed\x40\x21\x12";
  5842. d.inLen = XSTRLEN(d.input);
  5843. d.outLen = WC_SHA_DIGEST_SIZE;
  5844. test_hmac[0] = a;
  5845. test_hmac[1] = b;
  5846. test_hmac[2] = c;
  5847. test_hmac[3] = d;
  5848. #if FIPS_VERSION3_GE(6,0,0)
  5849. int allowShortKeyWithFips = 1;
  5850. #endif
  5851. for (i = 0; i < times; ++i) {
  5852. #if defined(HAVE_CAVIUM) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0))
  5853. if (i == 1)
  5854. continue; /* cavium can't handle short keys, fips not allowed */
  5855. #endif
  5856. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5857. return WC_TEST_RET_ENC_EC(ret);
  5858. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i],
  5859. (word32)XSTRLEN(keys[i]));
  5860. #if FIPS_VERSION3_GE(6,0,0)
  5861. if (i == 1) {
  5862. if (ret != WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E))
  5863. return WC_TEST_RET_ENC_EC(ret);
  5864. /* Now use the ex and allow short keys with FIPS option */
  5865. ret = wc_HmacSetKey_ex(&hmac, WC_SHA, (byte*) keys[i],
  5866. (word32)XSTRLEN(keys[i]), allowShortKeyWithFips);
  5867. }
  5868. #endif
  5869. if (ret != 0)
  5870. return WC_TEST_RET_ENC_EC(ret);
  5871. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5872. (word32)test_hmac[i].inLen);
  5873. if (ret != 0)
  5874. return WC_TEST_RET_ENC_EC(ret);
  5875. ret = wc_HmacFinal(&hmac, hash);
  5876. if (ret != 0)
  5877. return WC_TEST_RET_ENC_EC(ret);
  5878. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0)
  5879. return WC_TEST_RET_ENC_I(i);
  5880. wc_HmacFree(&hmac);
  5881. }
  5882. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5883. if ((ret = wc_HmacSizeByType(WC_SHA)) != WC_SHA_DIGEST_SIZE)
  5884. return WC_TEST_RET_ENC_EC(ret);
  5885. #endif
  5886. return 0;
  5887. }
  5888. #endif
  5889. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  5890. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void)
  5891. {
  5892. Hmac hmac;
  5893. byte hash[WC_SHA224_DIGEST_SIZE];
  5894. const char* keys[]=
  5895. {
  5896. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5897. "\x0b\x0b\x0b",
  5898. "Jefe",
  5899. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5900. "\xAA\xAA\xAA",
  5901. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5902. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5903. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5904. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5905. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5906. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5907. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5908. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5909. "\xAA\xAA\xAA"
  5910. };
  5911. testVector a, b, c, d;
  5912. testVector test_hmac[4];
  5913. wc_test_ret_t ret;
  5914. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5915. WOLFSSL_ENTER("hmac_sha224_test");
  5916. /* Following test vectors are from RFC 4231 section 4 */
  5917. a.input = "Hi There";
  5918. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  5919. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  5920. a.inLen = XSTRLEN(a.input);
  5921. a.outLen = WC_SHA224_DIGEST_SIZE;
  5922. b.input = "what do ya want for nothing?";
  5923. b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
  5924. "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
  5925. b.inLen = XSTRLEN(b.input);
  5926. b.outLen = WC_SHA224_DIGEST_SIZE;
  5927. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5928. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5929. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5930. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5931. c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
  5932. "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
  5933. c.inLen = XSTRLEN(c.input);
  5934. c.outLen = WC_SHA224_DIGEST_SIZE;
  5935. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5936. 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";
  5937. d.inLen = XSTRLEN(d.input);
  5938. d.outLen = WC_SHA224_DIGEST_SIZE;
  5939. test_hmac[0] = a;
  5940. test_hmac[1] = b;
  5941. test_hmac[2] = c;
  5942. test_hmac[3] = d;
  5943. for (i = 0; i < times; ++i) {
  5944. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5945. if (i == 1)
  5946. continue; /* cavium can't handle short keys, fips not allowed */
  5947. #endif
  5948. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5949. return WC_TEST_RET_ENC_EC(ret);
  5950. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i],
  5951. (word32)XSTRLEN(keys[i]));
  5952. if (ret != 0)
  5953. return WC_TEST_RET_ENC_EC(ret);
  5954. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5955. (word32)test_hmac[i].inLen);
  5956. if (ret != 0)
  5957. return WC_TEST_RET_ENC_EC(ret);
  5958. ret = wc_HmacFinal(&hmac, hash);
  5959. if (ret != 0)
  5960. return WC_TEST_RET_ENC_EC(ret);
  5961. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  5962. return WC_TEST_RET_ENC_I(i);
  5963. wc_HmacFree(&hmac);
  5964. }
  5965. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5966. if ((ret = wc_HmacSizeByType(WC_SHA224)) != WC_SHA224_DIGEST_SIZE)
  5967. return WC_TEST_RET_ENC_EC(ret);
  5968. #endif
  5969. return 0;
  5970. }
  5971. #endif
  5972. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  5973. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void)
  5974. {
  5975. Hmac hmac;
  5976. byte hash[WC_SHA256_DIGEST_SIZE];
  5977. const char* keys[]=
  5978. {
  5979. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5980. "\x0b\x0b\x0b",
  5981. "Jefe",
  5982. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5983. "\xAA\xAA\xAA",
  5984. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5985. "\xAA\xAA\xAA",
  5986. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5987. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5988. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5989. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5990. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5991. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5992. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5993. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5994. "\xAA\xAA\xAA"
  5995. };
  5996. testVector a, b, c, d, e;
  5997. testVector test_hmac[5];
  5998. wc_test_ret_t ret;
  5999. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6000. WOLFSSL_ENTER("hmac_sha256_test");
  6001. /* Following test vectors are from RFC 4231 section 4 */
  6002. a.input = "Hi There";
  6003. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  6004. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  6005. "\xcf\xf7";
  6006. a.inLen = XSTRLEN(a.input);
  6007. a.outLen = WC_SHA256_DIGEST_SIZE;
  6008. b.input = "what do ya want for nothing?";
  6009. b.output = "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75"
  6010. "\xc7\x5a\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec"
  6011. "\x38\x43";
  6012. b.inLen = XSTRLEN(b.input);
  6013. b.outLen = WC_SHA256_DIGEST_SIZE;
  6014. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6015. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6016. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6017. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6018. c.output = "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81"
  6019. "\xa7\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5"
  6020. "\x65\xfe";
  6021. c.inLen = XSTRLEN(c.input);
  6022. c.outLen = WC_SHA256_DIGEST_SIZE;
  6023. d.input = 0;
  6024. d.output = "\x86\xe5\x4f\xd4\x48\x72\x5d\x7e\x5d\xcf\xe2\x23\x53\xc8\x28"
  6025. "\xaf\x48\x78\x1e\xb4\x8c\xae\x81\x06\xa7\xe1\xd4\x98\x94\x9f"
  6026. "\x3e\x46";
  6027. d.inLen = 0;
  6028. d.outLen = WC_SHA256_DIGEST_SIZE;
  6029. e.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6030. e.output = "\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7"
  6031. "\x7f\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3"
  6032. "\x7f\x54";
  6033. e.inLen = XSTRLEN(e.input);;
  6034. e.outLen = WC_SHA256_DIGEST_SIZE;
  6035. test_hmac[0] = a;
  6036. test_hmac[1] = b;
  6037. test_hmac[2] = c;
  6038. test_hmac[3] = d;
  6039. test_hmac[4] = e;
  6040. for (i = 0; i < times; ++i) {
  6041. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  6042. if (i == 1)
  6043. continue; /* cavium can't handle short keys, fips not allowed */
  6044. #endif
  6045. #if defined(HAVE_INTEL_QA) || defined(HAVE_CAVIUM)
  6046. if (i == 3)
  6047. continue; /* QuickAssist can't handle empty HMAC */
  6048. #endif
  6049. if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0)
  6050. return WC_TEST_RET_ENC_I(i);
  6051. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i],
  6052. (word32)XSTRLEN(keys[i]));
  6053. if (ret != 0)
  6054. return WC_TEST_RET_ENC_I(i);
  6055. if (test_hmac[i].input != NULL) {
  6056. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6057. (word32)test_hmac[i].inLen);
  6058. if (ret != 0)
  6059. return WC_TEST_RET_ENC_I(i);
  6060. }
  6061. ret = wc_HmacFinal(&hmac, hash);
  6062. if (ret != 0)
  6063. return WC_TEST_RET_ENC_I(i);
  6064. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0)
  6065. return WC_TEST_RET_ENC_I(i);
  6066. wc_HmacFree(&hmac);
  6067. }
  6068. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6069. if ((ret = wc_HmacSizeByType(WC_SHA256)) != WC_SHA256_DIGEST_SIZE)
  6070. return WC_TEST_RET_ENC_EC(ret);
  6071. #if FIPS_VERSION3_GE(6,0,0)
  6072. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(HMAC_KAT_FIPS_E))
  6073. #else
  6074. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  6075. #endif
  6076. {
  6077. return WC_TEST_RET_ENC_EC(ret);
  6078. }
  6079. #endif
  6080. if ((ret = wolfSSL_GetHmacMaxSize()) != WC_MAX_DIGEST_SIZE)
  6081. return WC_TEST_RET_ENC_EC(ret);
  6082. return 0;
  6083. }
  6084. #endif
  6085. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  6086. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void)
  6087. {
  6088. Hmac hmac;
  6089. byte hash[WC_SHA384_DIGEST_SIZE];
  6090. const char* keys[]=
  6091. {
  6092. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6093. "\x0b\x0b\x0b",
  6094. "Jefe",
  6095. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6096. "\xAA\xAA\xAA",
  6097. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6098. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6099. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6100. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6101. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6102. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6103. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6104. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6105. "\xAA\xAA\xAA"
  6106. };
  6107. testVector a, b, c, d;
  6108. testVector test_hmac[4];
  6109. wc_test_ret_t ret;
  6110. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6111. WOLFSSL_ENTER("hmac_sha384_test");
  6112. /* Following test vectors are from RFC 4231 section 4 */
  6113. a.input = "Hi There";
  6114. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  6115. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  6116. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  6117. "\xfa\x9c\xb6";
  6118. a.inLen = XSTRLEN(a.input);
  6119. a.outLen = WC_SHA384_DIGEST_SIZE;
  6120. b.input = "what do ya want for nothing?";
  6121. b.output = "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b"
  6122. "\x1b\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22"
  6123. "\x44\x5e\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa"
  6124. "\xb2\x16\x49";
  6125. b.inLen = XSTRLEN(b.input);
  6126. b.outLen = WC_SHA384_DIGEST_SIZE;
  6127. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6128. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6129. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6130. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6131. c.output = "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8"
  6132. "\x6f\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66"
  6133. "\x14\x4b\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01"
  6134. "\xa3\x4f\x27";
  6135. c.inLen = XSTRLEN(c.input);
  6136. c.outLen = WC_SHA384_DIGEST_SIZE;
  6137. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6138. d.output = "\x4e\xce\x08\x44\x85\x81\x3e\x90\x88\xd2\xc6\x3a\x04\x1b\xc5"
  6139. "\xb4\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f\x3c\xd1\x1f\x05\x03\x3a"
  6140. "\xc4\xc6\x0c\x2e\xf6\xab\x40\x30\xfe\x82\x96\x24\x8d\xf1\x63"
  6141. "\xf4\x49\x52";
  6142. d.inLen = XSTRLEN(d.input);
  6143. d.outLen = WC_SHA384_DIGEST_SIZE;
  6144. test_hmac[0] = a;
  6145. test_hmac[1] = b;
  6146. test_hmac[2] = c;
  6147. test_hmac[3] = d;
  6148. for (i = 0; i < times; ++i) {
  6149. #if defined(HAVE_FIPS)
  6150. if (i == 1)
  6151. continue; /* fips not allowed */
  6152. #endif
  6153. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6154. return WC_TEST_RET_ENC_EC(ret);
  6155. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i],
  6156. (word32)XSTRLEN(keys[i]));
  6157. if (ret != 0)
  6158. return WC_TEST_RET_ENC_EC(ret);
  6159. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6160. (word32)test_hmac[i].inLen);
  6161. if (ret != 0)
  6162. return WC_TEST_RET_ENC_EC(ret);
  6163. ret = wc_HmacFinal(&hmac, hash);
  6164. if (ret != 0)
  6165. return WC_TEST_RET_ENC_EC(ret);
  6166. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  6167. return WC_TEST_RET_ENC_I(i);
  6168. wc_HmacFree(&hmac);
  6169. }
  6170. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6171. if ((ret = wc_HmacSizeByType(WC_SHA384)) != WC_SHA384_DIGEST_SIZE)
  6172. return WC_TEST_RET_ENC_EC(ret);
  6173. #endif
  6174. return 0;
  6175. }
  6176. #endif
  6177. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA512)
  6178. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void)
  6179. {
  6180. Hmac hmac;
  6181. byte hash[WC_SHA512_DIGEST_SIZE];
  6182. const char* keys[]=
  6183. {
  6184. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6185. "\x0b\x0b\x0b",
  6186. "Jefe",
  6187. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6188. "\xAA\xAA\xAA",
  6189. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6190. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6191. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6192. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6193. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6194. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6195. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6196. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6197. "\xAA\xAA\xAA"
  6198. };
  6199. testVector a, b, c, d;
  6200. testVector test_hmac[4];
  6201. wc_test_ret_t ret;
  6202. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6203. WOLFSSL_ENTER("hmac_sha512_test");
  6204. /* Following test vectors are from RFC 4231 section 4 */
  6205. a.input = "Hi There";
  6206. a.output = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c"
  6207. "\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1"
  6208. "\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae"
  6209. "\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20"
  6210. "\x3a\x12\x68\x54";
  6211. a.inLen = XSTRLEN(a.input);
  6212. a.outLen = WC_SHA512_DIGEST_SIZE;
  6213. b.input = "what do ya want for nothing?";
  6214. b.output = "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2\xe3\x95\xfb\xe7\x3b\x56\xe0"
  6215. "\xa3\x87\xbd\x64\x22\x2e\x83\x1f\xd6\x10\x27\x0c\xd7\xea\x25"
  6216. "\x05\x54\x97\x58\xbf\x75\xc0\x5a\x99\x4a\x6d\x03\x4f\x65\xf8"
  6217. "\xf0\xe6\xfd\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b\x63\x6e\x07\x0a"
  6218. "\x38\xbc\xe7\x37";
  6219. b.inLen = XSTRLEN(b.input);
  6220. b.outLen = WC_SHA512_DIGEST_SIZE;
  6221. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6222. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6223. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6224. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6225. c.output = "\xfa\x73\xb0\x08\x9d\x56\xa2\x84\xef\xb0\xf0\x75\x6c\x89\x0b"
  6226. "\xe9\xb1\xb5\xdb\xdd\x8e\xe8\x1a\x36\x55\xf8\x3e\x33\xb2\x27"
  6227. "\x9d\x39\xbf\x3e\x84\x82\x79\xa7\x22\xc8\x06\xb4\x85\xa4\x7e"
  6228. "\x67\xc8\x07\xb9\x46\xa3\x37\xbe\xe8\x94\x26\x74\x27\x88\x59"
  6229. "\xe1\x32\x92\xfb";
  6230. c.inLen = XSTRLEN(c.input);
  6231. c.outLen = WC_SHA512_DIGEST_SIZE;
  6232. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6233. d.output = "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb\xb7\x14\x93\xc1\xdd\x7b\xe8"
  6234. "\xb4\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1\x12\x1b\x01\x37\x83\xf8"
  6235. "\xf3\x52\x6b\x56\xd0\x37\xe0\x5f\x25\x98\xbd\x0f\xd2\x21\x5d"
  6236. "\x6a\x1e\x52\x95\xe6\x4f\x73\xf6\x3f\x0a\xec\x8b\x91\x5a\x98"
  6237. "\x5d\x78\x65\x98";
  6238. d.inLen = XSTRLEN(d.input);
  6239. d.outLen = WC_SHA512_DIGEST_SIZE;
  6240. test_hmac[0] = a;
  6241. test_hmac[1] = b;
  6242. test_hmac[2] = c;
  6243. test_hmac[3] = d;
  6244. for (i = 0; i < times; ++i) {
  6245. #if defined(HAVE_FIPS)
  6246. if (i == 1)
  6247. continue; /* fips not allowed */
  6248. #endif
  6249. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6250. return WC_TEST_RET_ENC_EC(ret);
  6251. ret = wc_HmacSetKey(&hmac, WC_SHA512, (byte*)keys[i],
  6252. (word32)XSTRLEN(keys[i]));
  6253. if (ret != 0)
  6254. return WC_TEST_RET_ENC_EC(ret);
  6255. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6256. (word32)test_hmac[i].inLen);
  6257. if (ret != 0)
  6258. return WC_TEST_RET_ENC_EC(ret);
  6259. ret = wc_HmacFinal(&hmac, hash);
  6260. if (ret != 0)
  6261. return WC_TEST_RET_ENC_EC(ret);
  6262. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  6263. return WC_TEST_RET_ENC_I(i);
  6264. wc_HmacFree(&hmac);
  6265. }
  6266. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6267. if ((ret = wc_HmacSizeByType(WC_SHA512)) != WC_SHA512_DIGEST_SIZE)
  6268. return WC_TEST_RET_ENC_EC(ret);
  6269. #endif
  6270. return 0;
  6271. }
  6272. #endif
  6273. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  6274. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  6275. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  6276. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void)
  6277. {
  6278. Hmac hmac;
  6279. byte hash[WC_SHA3_512_DIGEST_SIZE];
  6280. const char* key[4] =
  6281. {
  6282. "Jefe",
  6283. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6284. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  6285. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
  6286. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
  6287. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6288. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6289. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6290. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6291. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6292. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6293. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6294. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6295. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6296. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6297. };
  6298. const char* input[4] =
  6299. {
  6300. "what do ya want for nothing?",
  6301. "Hi There",
  6302. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6303. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6304. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6305. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6306. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
  6307. "Big Key Input"
  6308. };
  6309. const int hashType[4] =
  6310. {
  6311. WC_SHA3_224, WC_SHA3_256, WC_SHA3_384, WC_SHA3_512
  6312. };
  6313. const int hashSz[4] =
  6314. {
  6315. WC_SHA3_224_DIGEST_SIZE, WC_SHA3_256_DIGEST_SIZE,
  6316. WC_SHA3_384_DIGEST_SIZE, WC_SHA3_512_DIGEST_SIZE
  6317. };
  6318. const char* output[16] =
  6319. {
  6320. /* key = jefe, input = what do ya want for nothing? */
  6321. /* HMAC-SHA3-224 */
  6322. "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11"
  6323. "\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66",
  6324. /* HMAC-SHA3-256 */
  6325. "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87"
  6326. "\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5",
  6327. /* HMAC-SHA3-384 */
  6328. "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21"
  6329. "\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce"
  6330. "\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a",
  6331. /* HMAC-SHA3-512 */
  6332. "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83"
  6333. "\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b"
  6334. "\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e"
  6335. "\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24",
  6336. /* key = 0b..., input = Hi There */
  6337. /* HMAC-SHA3-224 */
  6338. "\x3b\x16\x54\x6b\xbc\x7b\xe2\x70\x6a\x03\x1d\xca\xfd\x56\x37\x3d"
  6339. "\x98\x84\x36\x76\x41\xd8\xc5\x9a\xf3\xc8\x60\xf7",
  6340. /* HMAC-SHA3-256 */
  6341. "\xba\x85\x19\x23\x10\xdf\xfa\x96\xe2\xa3\xa4\x0e\x69\x77\x43\x51"
  6342. "\x14\x0b\xb7\x18\x5e\x12\x02\xcd\xcc\x91\x75\x89\xf9\x5e\x16\xbb",
  6343. /* HMAC-SHA3-384 */
  6344. "\x68\xd2\xdc\xf7\xfd\x4d\xdd\x0a\x22\x40\xc8\xa4\x37\x30\x5f\x61"
  6345. "\xfb\x73\x34\xcf\xb5\xd0\x22\x6e\x1b\xc2\x7d\xc1\x0a\x2e\x72\x3a"
  6346. "\x20\xd3\x70\xb4\x77\x43\x13\x0e\x26\xac\x7e\x3d\x53\x28\x86\xbd",
  6347. /* HMAC-SHA3-512 */
  6348. "\xeb\x3f\xbd\x4b\x2e\xaa\xb8\xf5\xc5\x04\xbd\x3a\x41\x46\x5a\xac"
  6349. "\xec\x15\x77\x0a\x7c\xab\xac\x53\x1e\x48\x2f\x86\x0b\x5e\xc7\xba"
  6350. "\x47\xcc\xb2\xc6\xf2\xaf\xce\x8f\x88\xd2\x2b\x6d\xc6\x13\x80\xf2"
  6351. "\x3a\x66\x8f\xd3\x88\x8b\xb8\x05\x37\xc0\xa0\xb8\x64\x07\x68\x9e",
  6352. /* key = aa..., output = dd... */
  6353. /* HMAC-SHA3-224 */
  6354. "\x67\x6c\xfc\x7d\x16\x15\x36\x38\x78\x03\x90\x69\x2b\xe1\x42\xd2"
  6355. "\xdf\x7c\xe9\x24\xb9\x09\xc0\xc0\x8d\xbf\xdc\x1a",
  6356. /* HMAC-SHA3-256 */
  6357. "\x84\xec\x79\x12\x4a\x27\x10\x78\x65\xce\xdd\x8b\xd8\x2d\xa9\x96"
  6358. "\x5e\x5e\xd8\xc3\x7b\x0a\xc9\x80\x05\xa7\xf3\x9e\xd5\x8a\x42\x07",
  6359. /* HMAC-SHA3-384 */
  6360. "\x27\x5c\xd0\xe6\x61\xbb\x8b\x15\x1c\x64\xd2\x88\xf1\xf7\x82\xfb"
  6361. "\x91\xa8\xab\xd5\x68\x58\xd7\x2b\xab\xb2\xd4\x76\xf0\x45\x83\x73"
  6362. "\xb4\x1b\x6a\xb5\xbf\x17\x4b\xec\x42\x2e\x53\xfc\x31\x35\xac\x6e",
  6363. /* HMAC-SHA3-512 */
  6364. "\x30\x9e\x99\xf9\xec\x07\x5e\xc6\xc6\xd4\x75\xed\xa1\x18\x06\x87"
  6365. "\xfc\xf1\x53\x11\x95\x80\x2a\x99\xb5\x67\x74\x49\xa8\x62\x51\x82"
  6366. "\x85\x1c\xb3\x32\xaf\xb6\xa8\x9c\x41\x13\x25\xfb\xcb\xcd\x42\xaf"
  6367. "\xcb\x7b\x6e\x5a\xab\x7e\xa4\x2c\x66\x0f\x97\xfd\x85\x84\xbf\x03",
  6368. /* key = big key, input = Big Key Input */
  6369. /* HMAC-SHA3-224 */
  6370. "\x29\xe0\x5e\x46\xc4\xa4\x5e\x46\x74\xbf\xd7\x2d\x1a\xd8\x66\xdb"
  6371. "\x2d\x0d\x10\x4e\x2b\xfa\xad\x53\x7d\x15\x69\x8b",
  6372. /* HMAC-SHA3-256 */
  6373. "\xb5\x5b\x8d\x64\xb6\x9c\x21\xd0\xbf\x20\x5c\xa2\xf7\xb9\xb1\x4e"
  6374. "\x88\x21\x61\x2c\x66\xc3\x91\xae\x6c\x95\x16\x85\x83\xe6\xf4\x9b",
  6375. /* HMAC-SHA3-384 */
  6376. "\xaa\x91\xb3\xa6\x2f\x56\xa1\xbe\x8c\x3e\x74\x38\xdb\x58\xd9\xd3"
  6377. "\x34\xde\xa0\x60\x6d\x8d\x46\xe0\xec\xa9\xf6\x06\x35\x14\xe6\xed"
  6378. "\x83\xe6\x7c\x77\x24\x6c\x11\xb5\x90\x82\xb5\x75\xda\x7b\x83\x2d",
  6379. /* HMAC-SHA3-512 */
  6380. "\x1c\xc3\xa9\x24\x4a\x4a\x3f\xbd\xc7\x20\x00\x16\x9b\x79\x47\x03"
  6381. "\x78\x75\x2c\xb5\xf1\x2e\x62\x7c\xbe\xef\x4e\x8f\x0b\x11\x2b\x32"
  6382. "\xa0\xee\xc9\xd0\x4d\x64\x64\x0b\x37\xf4\xdd\x66\xf7\x8b\xb3\xad"
  6383. "\x52\x52\x6b\x65\x12\xde\x0d\x7c\xc0\x8b\x60\x01\x6c\x37\xd7\xa8"
  6384. };
  6385. int i = 0, iMax = sizeof(input) / sizeof(input[0]),
  6386. j, jMax = sizeof(hashType) / sizeof(hashType[0]);
  6387. int ret;
  6388. WOLFSSL_ENTER("hmac_sha3_test");
  6389. #ifdef HAVE_FIPS
  6390. /* FIPS requires a minimum length for HMAC keys, and "Jefe" is too
  6391. * short. Skip it in FIPS builds. */
  6392. i = 1;
  6393. #endif
  6394. for (; i < iMax; i++) {
  6395. for (j = 0; j < jMax; j++) {
  6396. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6397. return WC_TEST_RET_ENC_EC(ret);
  6398. ret = wc_HmacSetKey(&hmac, hashType[j], (byte*)key[i],
  6399. (word32)XSTRLEN(key[i]));
  6400. if (ret != 0)
  6401. return WC_TEST_RET_ENC_EC(ret);
  6402. ret = wc_HmacUpdate(&hmac, (byte*)input[i],
  6403. (word32)XSTRLEN(input[i]));
  6404. if (ret != 0)
  6405. return WC_TEST_RET_ENC_EC(ret);
  6406. ret = wc_HmacFinal(&hmac, hash);
  6407. if (ret != 0)
  6408. return WC_TEST_RET_ENC_EC(ret);
  6409. if (XMEMCMP(hash, output[(i*jMax) + j], (size_t)hashSz[j]) != 0)
  6410. return WC_TEST_RET_ENC_NC;
  6411. wc_HmacFree(&hmac);
  6412. if (i > 0)
  6413. continue;
  6414. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6415. ret = wc_HmacSizeByType(hashType[j]);
  6416. if (ret != hashSz[j])
  6417. return WC_TEST_RET_ENC_EC(ret);
  6418. #endif
  6419. }
  6420. }
  6421. return 0;
  6422. }
  6423. #endif
  6424. #ifdef WC_RC2
  6425. typedef struct rc2TestVector {
  6426. const char* input;
  6427. const char* output;
  6428. const char* key; /* Key, variable up to 128 bytes */
  6429. const char* iv; /* IV, 8-bytes */
  6430. int inLen;
  6431. int outLen;
  6432. int keyLen;
  6433. int effectiveKeyBits; /* Up to 1024 bits supported */
  6434. } rc2TestVector;
  6435. static wc_test_ret_t rc2_ecb_test(void)
  6436. {
  6437. wc_test_ret_t ret = 0;
  6438. byte cipher[RC2_BLOCK_SIZE];
  6439. byte plain[RC2_BLOCK_SIZE];
  6440. rc2TestVector a, b, c, d, e, f, g, h;
  6441. rc2TestVector test_rc2[8];
  6442. int times = sizeof(test_rc2) / sizeof(rc2TestVector), i;
  6443. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6444. a.output = "\xeb\xb7\x73\xf9\x93\x27\x8e\xff";
  6445. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6446. a.inLen = RC2_BLOCK_SIZE;
  6447. a.outLen = RC2_BLOCK_SIZE;
  6448. a.keyLen = 8;
  6449. a.effectiveKeyBits = 63;
  6450. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6451. b.output = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49";
  6452. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6453. b.inLen = RC2_BLOCK_SIZE;
  6454. b.outLen = RC2_BLOCK_SIZE;
  6455. b.keyLen = 8;
  6456. b.effectiveKeyBits = 64;
  6457. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01";
  6458. c.output = "\x30\x64\x9e\xdf\x9b\xe7\xd2\xc2";
  6459. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6460. c.inLen = RC2_BLOCK_SIZE;
  6461. c.outLen = RC2_BLOCK_SIZE;
  6462. c.keyLen = 8;
  6463. c.effectiveKeyBits = 64;
  6464. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6465. d.output = "\x61\xa8\xa2\x44\xad\xac\xcc\xf0";
  6466. d.key = "\x88";
  6467. d.inLen = RC2_BLOCK_SIZE;
  6468. d.outLen = RC2_BLOCK_SIZE;
  6469. d.keyLen = 1;
  6470. d.effectiveKeyBits = 64;
  6471. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6472. e.output = "\x6c\xcf\x43\x08\x97\x4c\x26\x7f";
  6473. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6474. e.inLen = RC2_BLOCK_SIZE;
  6475. e.outLen = RC2_BLOCK_SIZE;
  6476. e.keyLen = 7;
  6477. e.effectiveKeyBits = 64;
  6478. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6479. f.output = "\x1a\x80\x7d\x27\x2b\xbe\x5d\xb1";
  6480. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6481. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6482. f.inLen = RC2_BLOCK_SIZE;
  6483. f.outLen = RC2_BLOCK_SIZE;
  6484. f.keyLen = 16;
  6485. f.effectiveKeyBits = 64;
  6486. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6487. g.output = "\x22\x69\x55\x2a\xb0\xf8\x5c\xa6";
  6488. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6489. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6490. g.inLen = RC2_BLOCK_SIZE;
  6491. g.outLen = RC2_BLOCK_SIZE;
  6492. g.keyLen = 16;
  6493. g.effectiveKeyBits = 128;
  6494. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6495. h.output = "\x5b\x78\xd3\xa4\x3d\xff\xf1\xf1";
  6496. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6497. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6498. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6499. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6500. "\x1e";
  6501. h.inLen = RC2_BLOCK_SIZE;
  6502. h.outLen = RC2_BLOCK_SIZE;
  6503. h.keyLen = 33;
  6504. h.effectiveKeyBits = 129;
  6505. a.iv = b.iv = c.iv = d.iv = e.iv = f.iv = g.iv = h.iv = NULL;
  6506. test_rc2[0] = a;
  6507. test_rc2[1] = b;
  6508. test_rc2[2] = c;
  6509. test_rc2[3] = d;
  6510. test_rc2[4] = e;
  6511. test_rc2[5] = f;
  6512. test_rc2[6] = g;
  6513. test_rc2[7] = h;
  6514. for (i = 0; i < times; ++i) {
  6515. Rc2 enc;
  6516. XMEMSET(cipher, 0, RC2_BLOCK_SIZE);
  6517. XMEMSET(plain, 0, RC2_BLOCK_SIZE);
  6518. ret = wc_Rc2SetKey(&enc, (byte*)test_rc2[i].key, test_rc2[i].keyLen,
  6519. NULL, test_rc2[i].effectiveKeyBits);
  6520. if (ret != 0) {
  6521. return WC_TEST_RET_ENC_EC(ret);
  6522. }
  6523. /* ECB encrypt */
  6524. ret = wc_Rc2EcbEncrypt(&enc, cipher, (byte*)test_rc2[i].input,
  6525. (word32)test_rc2[i].outLen);
  6526. if (ret != 0) {
  6527. return WC_TEST_RET_ENC_EC(ret);
  6528. }
  6529. if (XMEMCMP(cipher, test_rc2[i].output, test_rc2[i].outLen)) {
  6530. return WC_TEST_RET_ENC_NC;
  6531. }
  6532. /* ECB decrypt */
  6533. ret = wc_Rc2EcbDecrypt(&enc, plain, cipher, RC2_BLOCK_SIZE);
  6534. if (ret != 0) {
  6535. return WC_TEST_RET_ENC_EC(ret);
  6536. }
  6537. if (XMEMCMP(plain, test_rc2[i].input, RC2_BLOCK_SIZE)) {
  6538. return WC_TEST_RET_ENC_NC;
  6539. }
  6540. }
  6541. return 0;
  6542. }
  6543. static wc_test_ret_t rc2_cbc_test(void)
  6544. {
  6545. wc_test_ret_t ret = 0;
  6546. byte cipher[128];
  6547. byte plain[128];
  6548. rc2TestVector a, b, c, d, e, f, g, h, i;
  6549. rc2TestVector test_rc2[9];
  6550. int times = sizeof(test_rc2) / sizeof(rc2TestVector), j;
  6551. /* key length = 7, effective key bits = 63 */
  6552. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6553. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6554. a.output = "\xEB\xB7\x73\xF9\x93\x27\x8E\xFF"
  6555. "\xF0\x51\x77\x8B\x65\xDB\x13\x57";
  6556. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6557. a.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6558. a.inLen = RC2_BLOCK_SIZE*2;
  6559. a.outLen = RC2_BLOCK_SIZE*2;
  6560. a.keyLen = 8;
  6561. a.effectiveKeyBits = 63;
  6562. /* key length = 8, effective key bits = 64, all 0xFF */
  6563. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff"
  6564. "\xff\xff\xff\xff\xff\xff\xff\xff";
  6565. b.output = "\xA3\xA1\x12\x65\x4F\x81\xC5\xCD"
  6566. "\xB6\x94\x3E\xEA\x3E\x8B\x9D\x1F";
  6567. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6568. b.iv = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6569. b.inLen = RC2_BLOCK_SIZE*2;
  6570. b.outLen = RC2_BLOCK_SIZE*2;
  6571. b.keyLen = 8;
  6572. b.effectiveKeyBits = 64;
  6573. /* key length = 8, effective key bits = 64 */
  6574. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01"
  6575. "\x10\x00\x00\x00\x00\x00\x00\x01";
  6576. c.output = "\xB5\x70\x14\xA2\x5F\x40\xE3\x6D"
  6577. "\x81\x99\x8D\xE0\xB5\xD5\x3A\x05";
  6578. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6579. c.iv = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6580. c.inLen = RC2_BLOCK_SIZE*2;
  6581. c.outLen = RC2_BLOCK_SIZE*2;
  6582. c.keyLen = 8;
  6583. c.effectiveKeyBits = 64;
  6584. /* key length = 1, effective key bits = 64 */
  6585. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6586. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6587. d.output = "\x61\xA8\xA2\x44\xAD\xAC\xCC\xF0"
  6588. "\x6D\x19\xE8\xF1\xFC\xE7\x38\x87";
  6589. d.key = "\x88";
  6590. d.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6591. d.inLen = RC2_BLOCK_SIZE*2;
  6592. d.outLen = RC2_BLOCK_SIZE*2;
  6593. d.keyLen = 1;
  6594. d.effectiveKeyBits = 64;
  6595. /* key length = 7, effective key bits = 64 */
  6596. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6597. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6598. e.output = "\x6C\xCF\x43\x08\x97\x4C\x26\x7F"
  6599. "\xCC\x3C\x53\x57\x7C\xA1\xA4\x4B";
  6600. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6601. e.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6602. e.inLen = RC2_BLOCK_SIZE*2;
  6603. e.outLen = RC2_BLOCK_SIZE*2;
  6604. e.keyLen = 7;
  6605. e.effectiveKeyBits = 64;
  6606. /* key length = 16, effective key bits = 64 */
  6607. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6608. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6609. f.output = "\x1A\x80\x7D\x27\x2B\xBE\x5D\xB1"
  6610. "\x64\xEF\xE1\xC3\xB8\xAD\xFB\xBA";
  6611. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6612. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6613. f.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6614. f.inLen = RC2_BLOCK_SIZE*2;
  6615. f.outLen = RC2_BLOCK_SIZE*2;
  6616. f.keyLen = 16;
  6617. f.effectiveKeyBits = 64;
  6618. /* key length = 16, effective bits = 128 */
  6619. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6620. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6621. g.output = "\x22\x69\x55\x2A\xB0\xF8\x5C\xA6"
  6622. "\x53\x6E\xFD\x2D\x89\xE1\x2A\x73";
  6623. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6624. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6625. g.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6626. g.inLen = RC2_BLOCK_SIZE*2;
  6627. g.outLen = RC2_BLOCK_SIZE*2;
  6628. g.keyLen = 16;
  6629. g.effectiveKeyBits = 128;
  6630. /* key length = 33, effective bits = 129 */
  6631. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6632. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6633. h.output = "\x5B\x78\xD3\xA4\x3D\xFF\xF1\xF1"
  6634. "\x45\x30\xA8\xD5\xC7\x7C\x46\x19";
  6635. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6636. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6637. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6638. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6639. "\x1e";
  6640. h.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6641. h.inLen = RC2_BLOCK_SIZE*2;
  6642. h.outLen = RC2_BLOCK_SIZE*2;
  6643. h.keyLen = 33;
  6644. h.effectiveKeyBits = 129;
  6645. /* key length = 10, effective bits = 40 */
  6646. i.input = "\x11\x22\x33\x44\x55\x66\x77\x88"
  6647. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00"
  6648. "\x11\x22\x33\x44\x55\x66\x77\x88"
  6649. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00";
  6650. i.output = "\x71\x2D\x11\x99\xC9\xA0\x78\x4F"
  6651. "\xCD\xF1\x1E\x3D\xFD\x21\x7E\xDB"
  6652. "\xB2\x6E\x0D\xA4\x72\xBC\x31\x51"
  6653. "\x48\xEF\x4E\x68\x3B\xDC\xCD\x7D";
  6654. i.key = "\x26\x1E\x57\x8E\xC9\x62\xBF\xB8"
  6655. "\x3E\x96";
  6656. i.iv = "\x01\x02\x03\x04\x05\x06\x07\x08";
  6657. i.inLen = RC2_BLOCK_SIZE*4;
  6658. i.outLen = RC2_BLOCK_SIZE*4;
  6659. i.keyLen = 10;
  6660. i.effectiveKeyBits = 40;
  6661. test_rc2[0] = a;
  6662. test_rc2[1] = b;
  6663. test_rc2[2] = c;
  6664. test_rc2[3] = d;
  6665. test_rc2[4] = e;
  6666. test_rc2[5] = f;
  6667. test_rc2[6] = g;
  6668. test_rc2[7] = h;
  6669. test_rc2[8] = i;
  6670. for (j = 0; j < times; ++j) {
  6671. Rc2 rc2;
  6672. XMEMSET(cipher, 0, sizeof(cipher));
  6673. XMEMSET(plain, 0, sizeof(plain));
  6674. ret = wc_Rc2SetKey(&rc2, (byte*)test_rc2[j].key, test_rc2[j].keyLen,
  6675. (byte*)test_rc2[j].iv, test_rc2[j].effectiveKeyBits);
  6676. if (ret != 0) {
  6677. return WC_TEST_RET_ENC_EC(ret);
  6678. }
  6679. ret = wc_Rc2CbcEncrypt(&rc2, cipher, (byte*)test_rc2[j].input,
  6680. test_rc2[j].inLen);
  6681. if (ret != 0) {
  6682. return WC_TEST_RET_ENC_EC(ret);
  6683. }
  6684. if (XMEMCMP(cipher, (byte*)test_rc2[j].output, test_rc2[j].outLen)) {
  6685. return WC_TEST_RET_ENC_NC;
  6686. }
  6687. /* reset IV for decrypt, since overridden by encrypt operation */
  6688. ret = wc_Rc2SetIV(&rc2, (byte*)test_rc2[j].iv);
  6689. if (ret != 0) {
  6690. return WC_TEST_RET_ENC_EC(ret);
  6691. }
  6692. ret = wc_Rc2CbcDecrypt(&rc2, plain, cipher, test_rc2[j].outLen);
  6693. if (ret != 0) {
  6694. return WC_TEST_RET_ENC_EC(ret);
  6695. }
  6696. if (XMEMCMP(plain, (byte*)test_rc2[j].input, test_rc2[j].inLen)) {
  6697. return WC_TEST_RET_ENC_NC;
  6698. }
  6699. }
  6700. return 0;
  6701. }
  6702. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void)
  6703. {
  6704. wc_test_ret_t ret = 0;
  6705. WOLFSSL_ENTER("rc2_test");
  6706. ret = rc2_ecb_test();
  6707. if (ret != 0) {
  6708. return ret;
  6709. }
  6710. return rc2_cbc_test();
  6711. }
  6712. #endif
  6713. #ifndef NO_RC4
  6714. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void)
  6715. {
  6716. byte cipher[16];
  6717. byte plain[16];
  6718. wc_test_ret_t ret;
  6719. const char* keys[] =
  6720. {
  6721. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6722. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6723. "\x00\x00\x00\x00\x00\x00\x00\x00",
  6724. "\xef\x01\x23\x45"
  6725. };
  6726. testVector a, b, c, d;
  6727. testVector test_arc4[4];
  6728. int times = sizeof(test_arc4) / sizeof(testVector), i;
  6729. WOLFSSL_ENTER("arc4_test");
  6730. a.input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  6731. a.output = "\x75\xb7\x87\x80\x99\xe0\xc5\x96";
  6732. a.inLen = 8;
  6733. a.outLen = 8;
  6734. b.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6735. b.output = "\x74\x94\xc2\xe7\x10\x4b\x08\x79";
  6736. b.inLen = 8;
  6737. b.outLen = 8;
  6738. c.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6739. c.output = "\xde\x18\x89\x41\xa3\x37\x5d\x3a";
  6740. c.inLen = 8;
  6741. c.outLen = 8;
  6742. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  6743. d.output = "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61";
  6744. d.inLen = 10;
  6745. d.outLen = 10;
  6746. test_arc4[0] = a;
  6747. test_arc4[1] = b;
  6748. test_arc4[2] = c;
  6749. test_arc4[3] = d;
  6750. for (i = 0; i < times; ++i) {
  6751. Arc4 enc;
  6752. Arc4 dec;
  6753. int keylen = 8; /* XSTRLEN with key 0x00 not good */
  6754. if (i == 3)
  6755. keylen = 4;
  6756. ret = wc_Arc4Init(&enc, HEAP_HINT, devId);
  6757. if (ret != 0)
  6758. return WC_TEST_RET_ENC_EC(ret);
  6759. ret = wc_Arc4Init(&dec, HEAP_HINT, devId);
  6760. if (ret != 0)
  6761. return WC_TEST_RET_ENC_EC(ret);
  6762. ret = wc_Arc4SetKey(&enc, (byte*)keys[i], (word32)keylen);
  6763. if (ret != 0)
  6764. return WC_TEST_RET_ENC_EC(ret);
  6765. ret = wc_Arc4SetKey(&dec, (byte*)keys[i], (word32)keylen);
  6766. if (ret != 0)
  6767. return WC_TEST_RET_ENC_EC(ret);
  6768. ret = wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input,
  6769. (word32)test_arc4[i].outLen);
  6770. if (ret != 0)
  6771. return WC_TEST_RET_ENC_EC(ret);
  6772. ret = wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen);
  6773. if (ret != 0)
  6774. return WC_TEST_RET_ENC_EC(ret);
  6775. if (XMEMCMP(plain, test_arc4[i].input, test_arc4[i].outLen))
  6776. return WC_TEST_RET_ENC_I(i);
  6777. if (XMEMCMP(cipher, test_arc4[i].output, test_arc4[i].outLen))
  6778. return WC_TEST_RET_ENC_I(i);
  6779. wc_Arc4Free(&enc);
  6780. wc_Arc4Free(&dec);
  6781. }
  6782. return 0;
  6783. }
  6784. #endif
  6785. #ifdef HAVE_CHACHA
  6786. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void)
  6787. {
  6788. ChaCha enc;
  6789. ChaCha dec;
  6790. byte cipher[128];
  6791. byte plain[128];
  6792. byte sliver[64];
  6793. byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  6794. word32 keySz = 32;
  6795. wc_test_ret_t ret = 0;
  6796. int i;
  6797. int times = 4;
  6798. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  6799. {
  6800. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6801. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6802. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6803. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6804. };
  6805. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  6806. {
  6807. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6808. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6809. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6810. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  6811. };
  6812. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  6813. {
  6814. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6815. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6816. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6817. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6818. };
  6819. /* 128 bit key */
  6820. WOLFSSL_SMALL_STACK_STATIC const byte key4[] =
  6821. {
  6822. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6823. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6824. };
  6825. const byte* keys[] = {key1, key2, key3, key4};
  6826. WOLFSSL_SMALL_STACK_STATIC const byte ivs1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6827. WOLFSSL_SMALL_STACK_STATIC const byte ivs2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6828. WOLFSSL_SMALL_STACK_STATIC const byte ivs3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00};
  6829. WOLFSSL_SMALL_STACK_STATIC const byte ivs4[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6830. const byte* ivs[] = {ivs1, ivs2, ivs3, ivs4};
  6831. #ifndef BENCH_EMBEDDED
  6832. WOLFSSL_SMALL_STACK_STATIC const byte cipher_big_result[] = {
  6833. 0x06, 0xa6, 0x5d, 0x31, 0x21, 0x6c, 0xdb, 0x37, 0x48, 0x7c, 0x01, 0x9d,
  6834. 0x72, 0xdf, 0x0a, 0x5b, 0x64, 0x74, 0x20, 0xba, 0x9e, 0xe0, 0x26, 0x7a,
  6835. 0xbf, 0xdf, 0x83, 0x34, 0x3b, 0x4f, 0x94, 0x3f, 0x37, 0x89, 0xaf, 0x00,
  6836. 0xdf, 0x0f, 0x2e, 0x75, 0x16, 0x41, 0xf6, 0x7a, 0x86, 0x94, 0x9d, 0x32,
  6837. 0x56, 0xf0, 0x79, 0x71, 0x68, 0x6f, 0xa6, 0x6b, 0xc6, 0x59, 0x49, 0xf6,
  6838. 0x10, 0x34, 0x03, 0x03, 0x16, 0x53, 0x9a, 0x98, 0x2a, 0x46, 0xde, 0x17,
  6839. 0x06, 0x65, 0x70, 0xca, 0x0a, 0x1f, 0xab, 0x80, 0x26, 0x96, 0x3f, 0x3e,
  6840. 0x7a, 0x3c, 0xa8, 0x87, 0xbb, 0x65, 0xdd, 0x5e, 0x07, 0x7b, 0x34, 0xe0,
  6841. 0x56, 0xda, 0x32, 0x13, 0x30, 0xc9, 0x0c, 0xd7, 0xba, 0xe4, 0x1f, 0xa6,
  6842. 0x91, 0x4f, 0x72, 0x9f, 0xd9, 0x5c, 0x62, 0x7d, 0xa6, 0xc2, 0xbc, 0x87,
  6843. 0xae, 0x64, 0x11, 0x94, 0x3b, 0xbc, 0x6c, 0x23, 0xbd, 0x7d, 0x00, 0xb4,
  6844. 0x99, 0xf2, 0x68, 0xb5, 0x59, 0x70, 0x93, 0xad, 0x69, 0xd0, 0xb1, 0x28,
  6845. 0x70, 0x92, 0xeb, 0xec, 0x39, 0x80, 0x82, 0xde, 0x44, 0xe2, 0x8a, 0x26,
  6846. 0xb3, 0xe9, 0x45, 0xcf, 0x83, 0x76, 0x9f, 0x6a, 0xa0, 0x46, 0x4a, 0x3d,
  6847. 0x26, 0x56, 0xaf, 0x49, 0x41, 0x26, 0x1b, 0x6a, 0x41, 0x37, 0x65, 0x91,
  6848. 0x72, 0xc4, 0xe7, 0x3c, 0x17, 0x31, 0xae, 0x2e, 0x2b, 0x31, 0x45, 0xe4,
  6849. 0x93, 0xd3, 0x10, 0xaa, 0xc5, 0x62, 0xd5, 0x11, 0x4b, 0x57, 0x1d, 0xad,
  6850. 0x48, 0x06, 0xd0, 0x0d, 0x98, 0xa5, 0xc6, 0x5b, 0xd0, 0x9e, 0x22, 0xc0,
  6851. 0x00, 0x32, 0x5a, 0xf5, 0x1c, 0x89, 0x6d, 0x54, 0x97, 0x55, 0x6b, 0x46,
  6852. 0xc5, 0xc7, 0xc4, 0x48, 0x9c, 0xbf, 0x47, 0xdc, 0x03, 0xc4, 0x1b, 0xcb,
  6853. 0x65, 0xa6, 0x91, 0x9d, 0x6d, 0xf1, 0xb0, 0x7a, 0x4d, 0x3b, 0x03, 0x95,
  6854. 0xf4, 0x8b, 0x0b, 0xae, 0x39, 0xff, 0x3f, 0xf6, 0xc0, 0x14, 0x18, 0x8a,
  6855. 0xe5, 0x19, 0xbd, 0xc1, 0xb4, 0x05, 0x4e, 0x29, 0x2f, 0x0b, 0x33, 0x76,
  6856. 0x28, 0x16, 0xa4, 0xa6, 0x93, 0x04, 0xb5, 0x55, 0x6b, 0x89, 0x3d, 0xa5,
  6857. 0x0f, 0xd3, 0xad, 0xfa, 0xd9, 0xfd, 0x05, 0x5d, 0x48, 0x94, 0x25, 0x5a,
  6858. 0x2c, 0x9a, 0x94, 0x80, 0xb0, 0xe7, 0xcb, 0x4d, 0x77, 0xbf, 0xca, 0xd8,
  6859. 0x55, 0x48, 0xbd, 0x66, 0xb1, 0x85, 0x81, 0xb1, 0x37, 0x79, 0xab, 0x52,
  6860. 0x08, 0x14, 0x12, 0xac, 0xcd, 0x45, 0x4d, 0x53, 0x6b, 0xca, 0x96, 0xc7,
  6861. 0x3b, 0x2f, 0x73, 0xb1, 0x5a, 0x23, 0xbd, 0x65, 0xd5, 0xea, 0x17, 0xb3,
  6862. 0xdc, 0xa1, 0x17, 0x1b, 0x2d, 0xb3, 0x9c, 0xd0, 0xdb, 0x41, 0x77, 0xef,
  6863. 0x93, 0x20, 0x52, 0x3e, 0x9d, 0xf5, 0xbf, 0x33, 0xf7, 0x52, 0xc1, 0x90,
  6864. 0xa0, 0x15, 0x17, 0xce, 0xf7, 0xf7, 0xd0, 0x3a, 0x3b, 0xd1, 0x72, 0x56,
  6865. 0x31, 0x81, 0xae, 0x60, 0xab, 0x40, 0xc1, 0xd1, 0x28, 0x77, 0x53, 0xac,
  6866. 0x9f, 0x11, 0x0a, 0x88, 0x36, 0x4b, 0xda, 0x57, 0xa7, 0x28, 0x5c, 0x85,
  6867. 0xd3, 0x85, 0x9b, 0x79, 0xad, 0x05, 0x1c, 0x37, 0x14, 0x5e, 0x0d, 0xd0,
  6868. 0x23, 0x03, 0x42, 0x1d, 0x48, 0x5d, 0xc5, 0x3c, 0x5a, 0x08, 0xa9, 0x0d,
  6869. 0x6e, 0x82, 0x7c, 0x2e, 0x3c, 0x41, 0xcc, 0x96, 0x8e, 0xad, 0xee, 0x2a,
  6870. 0x61, 0x0b, 0x16, 0x0f, 0xa9, 0x24, 0x40, 0x85, 0xbc, 0x9f, 0x28, 0x8d,
  6871. 0xe6, 0x68, 0x4d, 0x8f, 0x30, 0x48, 0xd9, 0x73, 0x73, 0x6c, 0x9a, 0x7f,
  6872. 0x67, 0xf7, 0xde, 0x4c, 0x0a, 0x8b, 0xe4, 0xb3, 0x08, 0x2a, 0x52, 0xda,
  6873. 0x54, 0xee, 0xcd, 0xb5, 0x62, 0x4a, 0x26, 0x20, 0xfb, 0x40, 0xbb, 0x39,
  6874. 0x3a, 0x0f, 0x09, 0xe8, 0x00, 0xd1, 0x24, 0x97, 0x60, 0xe9, 0x83, 0x83,
  6875. 0xfe, 0x9f, 0x9c, 0x15, 0xcf, 0x69, 0x03, 0x9f, 0x03, 0xe1, 0xe8, 0x6e,
  6876. 0xbd, 0x87, 0x58, 0x68, 0xee, 0xec, 0xd8, 0x29, 0x46, 0x23, 0x49, 0x92,
  6877. 0x72, 0x95, 0x5b, 0x49, 0xca, 0xe0, 0x45, 0x59, 0xb2, 0xca, 0xf4, 0xfc,
  6878. 0xb7, 0x59, 0x37, 0x49, 0x28, 0xbc, 0xf3, 0xd7, 0x61, 0xbc, 0x4b, 0xf3,
  6879. 0xa9, 0x4b, 0x2f, 0x05, 0xa8, 0x01, 0xa5, 0xdc, 0x00, 0x6e, 0x01, 0xb6,
  6880. 0x45, 0x3c, 0xd5, 0x49, 0x7d, 0x5c, 0x25, 0xe8, 0x31, 0x87, 0xb2, 0xb9,
  6881. 0xbf, 0xb3, 0x01, 0x62, 0x0c, 0xd0, 0x48, 0x77, 0xa2, 0x34, 0x0f, 0x16,
  6882. 0x22, 0x28, 0xee, 0x54, 0x08, 0x93, 0x3b, 0xe4, 0xde, 0x7e, 0x63, 0xf7,
  6883. 0x97, 0x16, 0x5d, 0x71, 0x58, 0xc2, 0x2e, 0xf2, 0x36, 0xa6, 0x12, 0x65,
  6884. 0x94, 0x17, 0xac, 0x66, 0x23, 0x7e, 0xc6, 0x72, 0x79, 0x24, 0xce, 0x8f,
  6885. 0x55, 0x19, 0x97, 0x44, 0xfc, 0x55, 0xec, 0x85, 0x26, 0x27, 0xdb, 0x38,
  6886. 0xb1, 0x42, 0x0a, 0xdd, 0x05, 0x99, 0x28, 0xeb, 0x03, 0x6c, 0x9a, 0xe9,
  6887. 0x17, 0xf6, 0x2c, 0xb0, 0xfe, 0xe7, 0xa4, 0xa7, 0x31, 0xda, 0x4d, 0xb0,
  6888. 0x29, 0xdb, 0xdd, 0x8d, 0x12, 0x13, 0x9c, 0xb4, 0xcc, 0x83, 0x97, 0xfb,
  6889. 0x1a, 0xdc, 0x08, 0xd6, 0x30, 0x62, 0xe8, 0xeb, 0x8b, 0x61, 0xcb, 0x1d,
  6890. 0x06, 0xe3, 0xa5, 0x4d, 0x35, 0xdb, 0x59, 0xa8, 0x2d, 0x87, 0x27, 0x44,
  6891. 0x6f, 0xc0, 0x38, 0x97, 0xe4, 0x85, 0x00, 0x02, 0x09, 0xf6, 0x69, 0x3a,
  6892. 0xcf, 0x08, 0x1b, 0x21, 0xbb, 0x79, 0xb1, 0xa1, 0x34, 0x09, 0xe0, 0x80,
  6893. 0xca, 0xb0, 0x78, 0x8a, 0x11, 0x97, 0xd4, 0x07, 0xbe, 0x1b, 0x6a, 0x5d,
  6894. 0xdb, 0xd6, 0x1f, 0x76, 0x6b, 0x16, 0xf0, 0x58, 0x84, 0x5f, 0x59, 0xce,
  6895. 0x62, 0x34, 0xc3, 0xdf, 0x94, 0xb8, 0x2f, 0x84, 0x68, 0xf0, 0xb8, 0x51,
  6896. 0xd9, 0x6d, 0x8e, 0x4a, 0x1d, 0xe6, 0x5c, 0xd8, 0x86, 0x25, 0xe3, 0x24,
  6897. 0xfd, 0x21, 0x61, 0x13, 0x48, 0x3e, 0xf6, 0x7d, 0xa6, 0x71, 0x9b, 0xd2,
  6898. 0x6e, 0xe6, 0xd2, 0x08, 0x94, 0x62, 0x6c, 0x98, 0xfe, 0x2f, 0x9c, 0x88,
  6899. 0x7e, 0x78, 0x15, 0x02, 0x00, 0xf0, 0xba, 0x24, 0x91, 0xf2, 0xdc, 0x47,
  6900. 0x51, 0x4d, 0x15, 0x5e, 0x91, 0x5f, 0x57, 0x5b, 0x1d, 0x35, 0x24, 0x45,
  6901. 0x75, 0x9b, 0x88, 0x75, 0xf1, 0x2f, 0x85, 0xe7, 0x89, 0xd1, 0x01, 0xb4,
  6902. 0xc8, 0x18, 0xb7, 0x97, 0xef, 0x4b, 0x90, 0xf4, 0xbf, 0x10, 0x27, 0x3c,
  6903. 0x60, 0xff, 0xc4, 0x94, 0x20, 0x2f, 0x93, 0x4b, 0x4d, 0xe3, 0x80, 0xf7,
  6904. 0x2c, 0x71, 0xd9, 0xe3, 0x68, 0xb4, 0x77, 0x2b, 0xc7, 0x0d, 0x39, 0x92,
  6905. 0xef, 0x91, 0x0d, 0xb2, 0x11, 0x50, 0x0e, 0xe8, 0xad, 0x3b, 0xf6, 0xb5,
  6906. 0xc6, 0x14, 0x4d, 0x33, 0x53, 0xa7, 0x60, 0x15, 0xc7, 0x27, 0x51, 0xdc,
  6907. 0x54, 0x29, 0xa7, 0x0d, 0x6a, 0x7b, 0x72, 0x13, 0xad, 0x7d, 0x41, 0x19,
  6908. 0x4e, 0x42, 0x49, 0xcc, 0x42, 0xe4, 0xbd, 0x99, 0x13, 0xd9, 0x7f, 0xf3,
  6909. 0x38, 0xa4, 0xb6, 0x33, 0xed, 0x07, 0x48, 0x7e, 0x8e, 0x82, 0xfe, 0x3a,
  6910. 0x9d, 0x75, 0x93, 0xba, 0x25, 0x4e, 0x37, 0x3c, 0x0c, 0xd5, 0x69, 0xa9,
  6911. 0x2d, 0x9e, 0xfd, 0xe8, 0xbb, 0xf5, 0x0c, 0xe2, 0x86, 0xb9, 0x5e, 0x6f,
  6912. 0x28, 0xe4, 0x19, 0xb3, 0x0b, 0xa4, 0x86, 0xd7, 0x24, 0xd0, 0xb8, 0x89,
  6913. 0x7b, 0x76, 0xec, 0x05, 0x10, 0x5b, 0x68, 0xe9, 0x58, 0x66, 0xa3, 0xc5,
  6914. 0xb6, 0x63, 0x20, 0x0e, 0x0e, 0xea, 0x3d, 0x61, 0x5e, 0xda, 0x3d, 0x3c,
  6915. 0xf9, 0xfd, 0xed, 0xa9, 0xdb, 0x52, 0x94, 0x8a, 0x00, 0xca, 0x3c, 0x8d,
  6916. 0x66, 0x8f, 0xb0, 0xf0, 0x5a, 0xca, 0x3f, 0x63, 0x71, 0xbf, 0xca, 0x99,
  6917. 0x37, 0x9b, 0x75, 0x97, 0x89, 0x10, 0x6e, 0xcf, 0xf2, 0xf5, 0xe3, 0xd5,
  6918. 0x45, 0x9b, 0xad, 0x10, 0x71, 0x6c, 0x5f, 0x6f, 0x7f, 0x22, 0x77, 0x18,
  6919. 0x2f, 0xf9, 0x99, 0xc5, 0x69, 0x58, 0x03, 0x12, 0x86, 0x82, 0x3e, 0xbf,
  6920. 0xc2, 0x12, 0x35, 0x43, 0xa3, 0xd9, 0x18, 0x4f, 0x41, 0x11, 0x6b, 0xf3,
  6921. 0x67, 0xaf, 0x3d, 0x78, 0xe4, 0x22, 0x2d, 0xb3, 0x48, 0x43, 0x31, 0x1d,
  6922. 0xef, 0xa8, 0xba, 0x49, 0x8e, 0xa9, 0xa7, 0xb6, 0x18, 0x77, 0x84, 0xca,
  6923. 0xbd, 0xa2, 0x02, 0x1b, 0x6a, 0xf8, 0x5f, 0xda, 0xff, 0xcf, 0x01, 0x6a,
  6924. 0x86, 0x69, 0xa9, 0xe9, 0xcb, 0x60, 0x1e, 0x15, 0xdc, 0x8f, 0x5d, 0x39,
  6925. 0xb5, 0xce, 0x55, 0x5f, 0x47, 0x97, 0xb1, 0x19, 0x6e, 0x21, 0xd6, 0x13,
  6926. 0x39, 0xb2, 0x24, 0xe0, 0x62, 0x82, 0x9f, 0xed, 0x12, 0x81, 0xed, 0xee,
  6927. 0xab, 0xd0, 0x2f, 0x19, 0x89, 0x3f, 0x57, 0x2e, 0xc2, 0xe2, 0x67, 0xe8,
  6928. 0xae, 0x03, 0x56, 0xba, 0xd4, 0xd0, 0xa4, 0x89, 0x03, 0x06, 0x5b, 0xcc,
  6929. 0xf2, 0x22, 0xb8, 0x0e, 0x76, 0x79, 0x4a, 0x42, 0x1d, 0x37, 0x51, 0x5a,
  6930. 0xaa, 0x46, 0x6c, 0x2a, 0xdd, 0x66, 0xfe, 0xc6, 0x68, 0xc3, 0x38, 0xa2,
  6931. 0xae, 0x5b, 0x98, 0x24, 0x5d, 0x43, 0x05, 0x82, 0x38, 0x12, 0xd3, 0xd1,
  6932. 0x75, 0x2d, 0x4f, 0x61, 0xbd, 0xb9, 0x10, 0x87, 0x44, 0x2a, 0x78, 0x07,
  6933. 0xff, 0xf4, 0x0f, 0xa1, 0xf3, 0x68, 0x9f, 0xbe, 0xae, 0xa2, 0x91, 0xf0,
  6934. 0xc7, 0x55, 0x7a, 0x52, 0xd5, 0xa3, 0x8d, 0x6f, 0xe4, 0x90, 0x5c, 0xf3,
  6935. 0x5f, 0xce, 0x3d, 0x23, 0xf9, 0x8e, 0xae, 0x14, 0xfb, 0x82, 0x9a, 0xa3,
  6936. 0x04, 0x5f, 0xbf, 0xad, 0x3e, 0xf2, 0x97, 0x0a, 0x60, 0x40, 0x70, 0x19,
  6937. 0x72, 0xad, 0x66, 0xfb, 0x78, 0x1b, 0x84, 0x6c, 0x98, 0xbc, 0x8c, 0xf8,
  6938. 0x4f, 0xcb, 0xb5, 0xf6, 0xaf, 0x7a, 0xb7, 0x93, 0xef, 0x67, 0x48, 0x02,
  6939. 0x2c, 0xcb, 0xe6, 0x77, 0x0f, 0x7b, 0xc1, 0xee, 0xc5, 0xb6, 0x2d, 0x7e,
  6940. 0x62, 0xa0, 0xc0, 0xa7, 0xa5, 0x80, 0x31, 0x92, 0x50, 0xa1, 0x28, 0x22,
  6941. 0x95, 0x03, 0x17, 0xd1, 0x0f, 0xf6, 0x08, 0xe5, 0xec
  6942. };
  6943. #define CHACHA_BIG_TEST_SIZE 1305
  6944. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  6945. byte cipher_big[CHACHA_BIG_TEST_SIZE] = {0};
  6946. byte plain_big[CHACHA_BIG_TEST_SIZE] = {0};
  6947. byte input_big[CHACHA_BIG_TEST_SIZE] = {0};
  6948. #else
  6949. byte* cipher_big;
  6950. byte* plain_big;
  6951. byte* input_big;
  6952. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6953. int block_size;
  6954. #endif /* BENCH_EMBEDDED */
  6955. byte a[] = {0x76,0xb8,0xe0,0xad,0xa0,0xf1,0x3d,0x90};
  6956. byte b[] = {0x45,0x40,0xf0,0x5a,0x9f,0x1f,0xb2,0x96};
  6957. byte c[] = {0xde,0x9c,0xba,0x7b,0xf3,0xd6,0x9e,0xf5};
  6958. byte d[] = {0x89,0x67,0x09,0x52,0x60,0x83,0x64,0xfd};
  6959. byte* test_chacha[4];
  6960. test_chacha[0] = a;
  6961. test_chacha[1] = b;
  6962. test_chacha[2] = c;
  6963. test_chacha[3] = d;
  6964. WOLFSSL_ENTER("chacha_test");
  6965. #ifndef BENCH_EMBEDDED
  6966. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  6967. cipher_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6968. DYNAMIC_TYPE_TMP_BUFFER);
  6969. if (cipher_big == NULL) {
  6970. return MEMORY_E;
  6971. }
  6972. plain_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6973. DYNAMIC_TYPE_TMP_BUFFER);
  6974. if (plain_big == NULL) {
  6975. return MEMORY_E;
  6976. }
  6977. input_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6978. DYNAMIC_TYPE_TMP_BUFFER);
  6979. if (input_big == NULL) {
  6980. return MEMORY_E;
  6981. }
  6982. XMEMSET(cipher_big, 0, CHACHA_BIG_TEST_SIZE);
  6983. XMEMSET(plain_big, 0, CHACHA_BIG_TEST_SIZE);
  6984. XMEMSET(input_big, 0, CHACHA_BIG_TEST_SIZE);
  6985. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6986. #endif /* BENCH_EMBEDDED */
  6987. for (i = 0; i < times; ++i) {
  6988. if (i < 3) {
  6989. keySz = 32;
  6990. }
  6991. else {
  6992. keySz = 16;
  6993. }
  6994. XMEMCPY(plain, keys[i], keySz);
  6995. XMEMSET(cipher, 0, 32);
  6996. XMEMCPY(cipher + 4, ivs[i], 8);
  6997. ret |= wc_Chacha_SetKey(&enc, keys[i], keySz);
  6998. ret |= wc_Chacha_SetKey(&dec, keys[i], keySz);
  6999. if (ret != 0)
  7000. return ret;
  7001. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  7002. ret |= wc_Chacha_SetIV(&dec, cipher, 0);
  7003. if (ret != 0)
  7004. return ret;
  7005. XMEMCPY(plain, input, 8);
  7006. ret |= wc_Chacha_Process(&enc, cipher, plain, (word32)8);
  7007. ret |= wc_Chacha_Process(&dec, plain, cipher, (word32)8);
  7008. if (ret != 0)
  7009. return ret;
  7010. if (XMEMCMP(test_chacha[i], cipher, 8))
  7011. return WC_TEST_RET_ENC_I(i);
  7012. if (XMEMCMP(plain, input, 8))
  7013. return WC_TEST_RET_ENC_I(i);
  7014. }
  7015. /* test of starting at a different counter
  7016. encrypts all of the information and decrypts starting at 2nd chunk */
  7017. XMEMSET(plain, 0, sizeof(plain));
  7018. XMEMSET(sliver, 1, sizeof(sliver)); /* set as 1's to not match plain */
  7019. XMEMSET(cipher, 0, sizeof(cipher));
  7020. XMEMCPY(cipher + 4, ivs[0], 8);
  7021. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7022. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7023. if (ret != 0)
  7024. return ret;
  7025. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  7026. ret |= wc_Chacha_SetIV(&dec, cipher, 1);
  7027. if (ret != 0)
  7028. return ret;
  7029. ret |= wc_Chacha_Process(&enc, cipher, plain, sizeof(plain));
  7030. ret |= wc_Chacha_Process(&dec, sliver, cipher + 64, sizeof(sliver));
  7031. if (ret != 0)
  7032. return ret;
  7033. if (XMEMCMP(plain + 64, sliver, 64))
  7034. return WC_TEST_RET_ENC_NC;
  7035. #ifndef BENCH_EMBEDDED
  7036. /* test of encrypting more data */
  7037. keySz = 32;
  7038. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7039. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7040. if (ret != 0)
  7041. return ret;
  7042. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  7043. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  7044. if (ret != 0)
  7045. return ret;
  7046. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big, CHACHA_BIG_TEST_SIZE);
  7047. ret |= wc_Chacha_Process(&dec, plain_big, cipher_big,
  7048. CHACHA_BIG_TEST_SIZE);
  7049. if (ret != 0)
  7050. return ret;
  7051. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  7052. return WC_TEST_RET_ENC_NC;
  7053. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  7054. return WC_TEST_RET_ENC_NC;
  7055. for (i = 0; i < 18; ++i) {
  7056. /* this will test all paths
  7057. * block sizes: 1 3 7 15 31 63 127 255 511 (i = 0- 8)
  7058. * 2 4 8 16 32 64 128 256 512 (i = 9-17)
  7059. */
  7060. block_size = (2 << (i%9)) - (i<9?1:0);
  7061. keySz = 32;
  7062. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7063. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7064. if (ret != 0)
  7065. return ret;
  7066. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  7067. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  7068. if (ret != 0)
  7069. return ret;
  7070. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big , (word32)block_size);
  7071. ret |= wc_Chacha_Process(&dec, plain_big , cipher_big, (word32)block_size);
  7072. if (ret != 0)
  7073. return ret;
  7074. if (XMEMCMP(plain_big, input_big, (word32)block_size))
  7075. return WC_TEST_RET_ENC_I(i);
  7076. if (XMEMCMP(cipher_big, cipher_big_result, (word32)block_size))
  7077. return WC_TEST_RET_ENC_I(i);
  7078. }
  7079. /* Streaming test */
  7080. for (i = 1; i <= (int)CHACHA_CHUNK_BYTES + 1; i++) {
  7081. int j, rem;
  7082. ret = wc_Chacha_SetKey(&enc, keys[0], keySz);
  7083. if (ret != 0)
  7084. return WC_TEST_RET_ENC_EC(ret);
  7085. ret = wc_Chacha_SetKey(&dec, keys[0], keySz);
  7086. if (ret != 0)
  7087. return WC_TEST_RET_ENC_EC(ret);
  7088. ret = wc_Chacha_SetIV(&enc, ivs[2], 0);
  7089. if (ret != 0)
  7090. return WC_TEST_RET_ENC_EC(ret);
  7091. ret = wc_Chacha_SetIV(&dec, ivs[2], 0);
  7092. if (ret != 0)
  7093. return WC_TEST_RET_ENC_EC(ret);
  7094. for (j = 0; j < CHACHA_BIG_TEST_SIZE - i; j+= i) {
  7095. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)i);
  7096. if (ret != 0)
  7097. return WC_TEST_RET_ENC_EC(ret);
  7098. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)i);
  7099. if (ret != 0)
  7100. return WC_TEST_RET_ENC_EC(ret);
  7101. }
  7102. rem = CHACHA_BIG_TEST_SIZE - j;
  7103. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)rem);
  7104. if (ret != 0)
  7105. return WC_TEST_RET_ENC_EC(ret);
  7106. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)rem);
  7107. if (ret != 0)
  7108. return WC_TEST_RET_ENC_EC(ret);
  7109. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  7110. return WC_TEST_RET_ENC_I(i);
  7111. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  7112. return WC_TEST_RET_ENC_I(i);
  7113. }
  7114. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  7115. XFREE(cipher_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7116. XFREE(plain_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7117. XFREE(input_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7118. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  7119. #endif /* BENCH_EMBEDDED */
  7120. return 0;
  7121. }
  7122. #endif /* HAVE_CHACHA */
  7123. #ifdef HAVE_POLY1305
  7124. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void)
  7125. {
  7126. byte tag[16];
  7127. Poly1305 enc;
  7128. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {
  7129. 0x43,0x72,0x79,0x70,0x74,0x6f,0x67,0x72,
  7130. 0x61,0x70,0x68,0x69,0x63,0x20,0x46,0x6f,
  7131. 0x72,0x75,0x6d,0x20,0x52,0x65,0x73,0x65,
  7132. 0x61,0x72,0x63,0x68,0x20,0x47,0x72,0x6f,
  7133. 0x75,0x70
  7134. };
  7135. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {
  7136. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,
  7137. 0x6c,0x64,0x21
  7138. };
  7139. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {
  7140. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7141. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7142. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7143. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7144. };
  7145. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  7146. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7147. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7148. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7149. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7150. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7151. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7152. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7153. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7154. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7155. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7156. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7157. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7158. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7159. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7160. 0x61,0x16
  7161. };
  7162. WOLFSSL_SMALL_STACK_STATIC const byte msg5[] = {
  7163. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7164. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7165. };
  7166. WOLFSSL_SMALL_STACK_STATIC const byte msg6[] = {
  7167. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7168. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7169. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7170. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7171. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7172. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7173. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7174. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7175. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7176. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7177. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7178. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7179. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7180. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7181. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7182. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7183. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7184. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7185. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7186. 0x61,0x16
  7187. };
  7188. WOLFSSL_SMALL_STACK_STATIC const byte msg7[] = {
  7189. 0xe8,0x8c,0x85,0x03,0x43,0xaf,0xa7,0x85,
  7190. 0x21,0x6b,0xc3,0x45,0xc4,0x53,0x98,0xf8,
  7191. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7192. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7193. };
  7194. byte additional[] = {
  7195. 0x50,0x51,0x52,0x53,0xc0,0xc1,0xc2,0xc3,
  7196. 0xc4,0xc5,0xc6,0xc7
  7197. };
  7198. WOLFSSL_SMALL_STACK_STATIC const byte correct0[] = {
  7199. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7200. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7201. };
  7202. WOLFSSL_SMALL_STACK_STATIC const byte correct1[] = {
  7203. 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,
  7204. 0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9
  7205. };
  7206. WOLFSSL_SMALL_STACK_STATIC const byte correct2[] = {
  7207. 0xa6,0xf7,0x45,0x00,0x8f,0x81,0xc9,0x16,
  7208. 0xa2,0x0d,0xcc,0x74,0xee,0xf2,0xb2,0xf0
  7209. };
  7210. WOLFSSL_SMALL_STACK_STATIC const byte correct3[] = {
  7211. 0x49,0xec,0x78,0x09,0x0e,0x48,0x1e,0xc6,
  7212. 0xc2,0x6b,0x33,0xb9,0x1c,0xcc,0x03,0x07
  7213. };
  7214. WOLFSSL_SMALL_STACK_STATIC const byte correct4[] = {
  7215. 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,
  7216. 0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91
  7217. };
  7218. WOLFSSL_SMALL_STACK_STATIC const byte correct5[] = {
  7219. 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7220. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7221. };
  7222. WOLFSSL_SMALL_STACK_STATIC const byte correct6[] = {
  7223. 0xea,0x11,0x5c,0x4f,0xd0,0xc0,0x10,0xae,
  7224. 0xf7,0xdf,0xda,0x77,0xa2,0xe9,0xaf,0xca
  7225. };
  7226. WOLFSSL_SMALL_STACK_STATIC const byte correct7[] = {
  7227. 0x14,0x00,0x00,0x88,0x5c,0x00,0x00,0x88,
  7228. 0x5c,0x00,0x00,0x88,0x5c,0x00,0x00,0x88
  7229. };
  7230. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7231. 0x85,0xd6,0xbe,0x78,0x57,0x55,0x6d,0x33,
  7232. 0x7f,0x44,0x52,0xfe,0x42,0xd5,0x06,0xa8,
  7233. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7234. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7235. };
  7236. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7237. 0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,
  7238. 0x33,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,
  7239. 0x6b,0x65,0x79,0x20,0x66,0x6f,0x72,0x20,
  7240. 0x50,0x6f,0x6c,0x79,0x31,0x33,0x30,0x35
  7241. };
  7242. WOLFSSL_SMALL_STACK_STATIC const byte key4[] = {
  7243. 0x7b,0xac,0x2b,0x25,0x2d,0xb4,0x47,0xaf,
  7244. 0x09,0xb6,0x7a,0x55,0xa4,0xe9,0x55,0x84,
  7245. 0x0a,0xe1,0xd6,0x73,0x10,0x75,0xd9,0xeb,
  7246. 0x2a,0x93,0x75,0x78,0x3e,0xd5,0x53,0xff
  7247. };
  7248. WOLFSSL_SMALL_STACK_STATIC const byte key5[] = {
  7249. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7250. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7251. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7252. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7253. };
  7254. WOLFSSL_SMALL_STACK_STATIC const byte key7[] = {
  7255. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7256. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7257. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7258. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  7259. };
  7260. const byte* msgs[] = {NULL, msg1, msg2, msg3, msg5, msg6, msg7};
  7261. word32 szm[] = {0, sizeof(msg1), sizeof(msg2),
  7262. sizeof(msg3), sizeof(msg5), sizeof(msg6),
  7263. sizeof(msg7)};
  7264. const byte* keys[] = {key, key, key2, key2, key5, key, key7};
  7265. const byte* tests[] = {correct0, correct1, correct2, correct3, correct5,
  7266. correct6, correct7};
  7267. int i;
  7268. wc_test_ret_t ret = 0;
  7269. WOLFSSL_ENTER("poly1305_test");
  7270. for (i = 0; i < 7; i++) {
  7271. ret = wc_Poly1305SetKey(&enc, keys[i], 32);
  7272. if (ret != 0)
  7273. return WC_TEST_RET_ENC_I(i);
  7274. ret = wc_Poly1305Update(&enc, msgs[i], szm[i]);
  7275. if (ret != 0)
  7276. return WC_TEST_RET_ENC_I(i);
  7277. ret = wc_Poly1305Final(&enc, tag);
  7278. if (ret != 0)
  7279. return WC_TEST_RET_ENC_I(i);
  7280. if (XMEMCMP(tag, tests[i], sizeof(tag)))
  7281. return WC_TEST_RET_ENC_I(i);
  7282. }
  7283. /* Check TLS MAC function from 2.8.2 https://tools.ietf.org/html/rfc7539 */
  7284. XMEMSET(tag, 0, sizeof(tag));
  7285. ret = wc_Poly1305SetKey(&enc, key4, sizeof(key4));
  7286. if (ret != 0)
  7287. return WC_TEST_RET_ENC_EC(ret);
  7288. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7289. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7290. if (ret != 0)
  7291. return WC_TEST_RET_ENC_EC(ret);
  7292. if (XMEMCMP(tag, correct4, sizeof(tag)))
  7293. return WC_TEST_RET_ENC_NC;
  7294. /* Check fail of TLS MAC function if altering additional data */
  7295. XMEMSET(tag, 0, sizeof(tag));
  7296. additional[0]++;
  7297. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7298. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7299. if (ret != 0)
  7300. return WC_TEST_RET_ENC_EC(ret);
  7301. if (XMEMCMP(tag, correct4, sizeof(tag)) == 0)
  7302. return WC_TEST_RET_ENC_NC;
  7303. return 0;
  7304. }
  7305. #endif /* HAVE_POLY1305 */
  7306. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  7307. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void)
  7308. {
  7309. /* Test #1 from Section 2.8.2 of draft-irtf-cfrg-chacha20-poly1305-10 */
  7310. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7311. WOLFSSL_SMALL_STACK_STATIC const byte key1[] = {
  7312. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  7313. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  7314. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  7315. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  7316. };
  7317. WOLFSSL_SMALL_STACK_STATIC const byte plaintext1[] = {
  7318. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  7319. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  7320. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  7321. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  7322. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  7323. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  7324. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  7325. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  7326. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  7327. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  7328. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  7329. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  7330. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  7331. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  7332. 0x74, 0x2e
  7333. };
  7334. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] = {
  7335. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  7336. 0x44, 0x45, 0x46, 0x47
  7337. };
  7338. WOLFSSL_SMALL_STACK_STATIC const byte aad1[] = { /* additional data */
  7339. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  7340. 0xc4, 0xc5, 0xc6, 0xc7
  7341. };
  7342. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] = { /* expected output from operation */
  7343. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  7344. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  7345. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  7346. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  7347. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  7348. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  7349. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  7350. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  7351. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  7352. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  7353. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  7354. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  7355. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  7356. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  7357. 0x61, 0x16
  7358. };
  7359. WOLFSSL_SMALL_STACK_STATIC const byte authTag1[] = { /* expected output from operation */
  7360. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  7361. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  7362. };
  7363. /* Test #2 from Appendix A.2 in draft-irtf-cfrg-chacha20-poly1305-10 */
  7364. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7365. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7366. 0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
  7367. 0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
  7368. 0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
  7369. 0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0
  7370. };
  7371. WOLFSSL_SMALL_STACK_STATIC const byte plaintext2[] = {
  7372. 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
  7373. 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20,
  7374. 0x61, 0x72, 0x65, 0x20, 0x64, 0x72, 0x61, 0x66,
  7375. 0x74, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7376. 0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x6c, 0x69,
  7377. 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
  7378. 0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20,
  7379. 0x6f, 0x66, 0x20, 0x73, 0x69, 0x78, 0x20, 0x6d,
  7380. 0x6f, 0x6e, 0x74, 0x68, 0x73, 0x20, 0x61, 0x6e,
  7381. 0x64, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65,
  7382. 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
  7383. 0x2c, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63,
  7384. 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f,
  7385. 0x62, 0x73, 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x64,
  7386. 0x20, 0x62, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65,
  7387. 0x72, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7388. 0x6e, 0x74, 0x73, 0x20, 0x61, 0x74, 0x20, 0x61,
  7389. 0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x2e,
  7390. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69,
  7391. 0x6e, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72,
  7392. 0x69, 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20,
  7393. 0x75, 0x73, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65,
  7394. 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61,
  7395. 0x66, 0x74, 0x73, 0x20, 0x61, 0x73, 0x20, 0x72,
  7396. 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
  7397. 0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61,
  7398. 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x20,
  7399. 0x63, 0x69, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65,
  7400. 0x6d, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20,
  7401. 0x74, 0x68, 0x61, 0x6e, 0x20, 0x61, 0x73, 0x20,
  7402. 0x2f, 0xe2, 0x80, 0x9c, 0x77, 0x6f, 0x72, 0x6b,
  7403. 0x20, 0x69, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67,
  7404. 0x72, 0x65, 0x73, 0x73, 0x2e, 0x2f, 0xe2, 0x80,
  7405. 0x9d
  7406. };
  7407. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  7408. 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
  7409. 0x05, 0x06, 0x07, 0x08
  7410. };
  7411. WOLFSSL_SMALL_STACK_STATIC const byte aad2[] = { /* additional data */
  7412. 0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00,
  7413. 0x00, 0x00, 0x4e, 0x91
  7414. };
  7415. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] = { /* expected output from operation */
  7416. 0x64, 0xa0, 0x86, 0x15, 0x75, 0x86, 0x1a, 0xf4,
  7417. 0x60, 0xf0, 0x62, 0xc7, 0x9b, 0xe6, 0x43, 0xbd,
  7418. 0x5e, 0x80, 0x5c, 0xfd, 0x34, 0x5c, 0xf3, 0x89,
  7419. 0xf1, 0x08, 0x67, 0x0a, 0xc7, 0x6c, 0x8c, 0xb2,
  7420. 0x4c, 0x6c, 0xfc, 0x18, 0x75, 0x5d, 0x43, 0xee,
  7421. 0xa0, 0x9e, 0xe9, 0x4e, 0x38, 0x2d, 0x26, 0xb0,
  7422. 0xbd, 0xb7, 0xb7, 0x3c, 0x32, 0x1b, 0x01, 0x00,
  7423. 0xd4, 0xf0, 0x3b, 0x7f, 0x35, 0x58, 0x94, 0xcf,
  7424. 0x33, 0x2f, 0x83, 0x0e, 0x71, 0x0b, 0x97, 0xce,
  7425. 0x98, 0xc8, 0xa8, 0x4a, 0xbd, 0x0b, 0x94, 0x81,
  7426. 0x14, 0xad, 0x17, 0x6e, 0x00, 0x8d, 0x33, 0xbd,
  7427. 0x60, 0xf9, 0x82, 0xb1, 0xff, 0x37, 0xc8, 0x55,
  7428. 0x97, 0x97, 0xa0, 0x6e, 0xf4, 0xf0, 0xef, 0x61,
  7429. 0xc1, 0x86, 0x32, 0x4e, 0x2b, 0x35, 0x06, 0x38,
  7430. 0x36, 0x06, 0x90, 0x7b, 0x6a, 0x7c, 0x02, 0xb0,
  7431. 0xf9, 0xf6, 0x15, 0x7b, 0x53, 0xc8, 0x67, 0xe4,
  7432. 0xb9, 0x16, 0x6c, 0x76, 0x7b, 0x80, 0x4d, 0x46,
  7433. 0xa5, 0x9b, 0x52, 0x16, 0xcd, 0xe7, 0xa4, 0xe9,
  7434. 0x90, 0x40, 0xc5, 0xa4, 0x04, 0x33, 0x22, 0x5e,
  7435. 0xe2, 0x82, 0xa1, 0xb0, 0xa0, 0x6c, 0x52, 0x3e,
  7436. 0xaf, 0x45, 0x34, 0xd7, 0xf8, 0x3f, 0xa1, 0x15,
  7437. 0x5b, 0x00, 0x47, 0x71, 0x8c, 0xbc, 0x54, 0x6a,
  7438. 0x0d, 0x07, 0x2b, 0x04, 0xb3, 0x56, 0x4e, 0xea,
  7439. 0x1b, 0x42, 0x22, 0x73, 0xf5, 0x48, 0x27, 0x1a,
  7440. 0x0b, 0xb2, 0x31, 0x60, 0x53, 0xfa, 0x76, 0x99,
  7441. 0x19, 0x55, 0xeb, 0xd6, 0x31, 0x59, 0x43, 0x4e,
  7442. 0xce, 0xbb, 0x4e, 0x46, 0x6d, 0xae, 0x5a, 0x10,
  7443. 0x73, 0xa6, 0x72, 0x76, 0x27, 0x09, 0x7a, 0x10,
  7444. 0x49, 0xe6, 0x17, 0xd9, 0x1d, 0x36, 0x10, 0x94,
  7445. 0xfa, 0x68, 0xf0, 0xff, 0x77, 0x98, 0x71, 0x30,
  7446. 0x30, 0x5b, 0xea, 0xba, 0x2e, 0xda, 0x04, 0xdf,
  7447. 0x99, 0x7b, 0x71, 0x4d, 0x6c, 0x6f, 0x2c, 0x29,
  7448. 0xa6, 0xad, 0x5c, 0xb4, 0x02, 0x2b, 0x02, 0x70,
  7449. 0x9b
  7450. };
  7451. WOLFSSL_SMALL_STACK_STATIC const byte authTag2[] = { /* expected output from operation */
  7452. 0xee, 0xad, 0x9d, 0x67, 0x89, 0x0c, 0xbb, 0x22,
  7453. 0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38
  7454. };
  7455. byte generatedCiphertext[265]; /* max plaintext2/cipher2 */
  7456. byte generatedPlaintext[265]; /* max plaintext2/cipher2 */
  7457. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  7458. ChaChaPoly_Aead aead;
  7459. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  7460. #define TEST_SMALL_CHACHA_CHUNKS 32
  7461. #else
  7462. #define TEST_SMALL_CHACHA_CHUNKS 64
  7463. #endif
  7464. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7465. word32 testLen;
  7466. #endif
  7467. wc_test_ret_t err;
  7468. WOLFSSL_ENTER("chacha20_poly1305_aead_test");
  7469. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7470. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7471. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7472. /* Parameter Validation testing */
  7473. /* Encrypt */
  7474. err = wc_ChaCha20Poly1305_Encrypt(NULL, iv1, aad1, sizeof(aad1), plaintext1,
  7475. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7476. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7477. return WC_TEST_RET_ENC_EC(err);
  7478. err = wc_ChaCha20Poly1305_Encrypt(key1, NULL, aad1, sizeof(aad1),
  7479. plaintext1, sizeof(plaintext1), generatedCiphertext,
  7480. generatedAuthTag);
  7481. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7482. return WC_TEST_RET_ENC_EC(err);
  7483. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7484. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7485. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7486. return WC_TEST_RET_ENC_EC(err);
  7487. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7488. sizeof(plaintext1), NULL, generatedAuthTag);
  7489. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7490. return WC_TEST_RET_ENC_EC(err);
  7491. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7492. sizeof(plaintext1), generatedCiphertext, NULL);
  7493. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7494. return WC_TEST_RET_ENC_EC(err);
  7495. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7496. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7497. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7498. return WC_TEST_RET_ENC_EC(err);
  7499. /* Decrypt */
  7500. err = wc_ChaCha20Poly1305_Decrypt(NULL, iv2, aad2, sizeof(aad2), cipher2,
  7501. sizeof(cipher2), authTag2, generatedPlaintext);
  7502. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7503. return WC_TEST_RET_ENC_EC(err);
  7504. err = wc_ChaCha20Poly1305_Decrypt(key2, NULL, aad2, sizeof(aad2), cipher2,
  7505. sizeof(cipher2), authTag2, generatedPlaintext);
  7506. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7507. return WC_TEST_RET_ENC_EC(err);
  7508. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7509. sizeof(cipher2), authTag2, generatedPlaintext);
  7510. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7511. return WC_TEST_RET_ENC_EC(err);
  7512. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7513. sizeof(cipher2), NULL, generatedPlaintext);
  7514. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7515. return WC_TEST_RET_ENC_EC(err);
  7516. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7517. sizeof(cipher2), authTag2, NULL);
  7518. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7519. return WC_TEST_RET_ENC_EC(err);
  7520. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7521. sizeof(cipher2), authTag2, generatedPlaintext);
  7522. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7523. return WC_TEST_RET_ENC_EC(err);
  7524. /* Test #1 */
  7525. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1,
  7526. aad1, sizeof(aad1),
  7527. plaintext1, sizeof(plaintext1),
  7528. generatedCiphertext, generatedAuthTag);
  7529. if (err) {
  7530. return WC_TEST_RET_ENC_EC(err);
  7531. }
  7532. /* -- Check the ciphertext and authtag */
  7533. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7534. return WC_TEST_RET_ENC_NC;
  7535. }
  7536. if (XMEMCMP(generatedAuthTag, authTag1, sizeof(authTag1))) {
  7537. return WC_TEST_RET_ENC_NC;
  7538. }
  7539. /* -- Verify decryption works */
  7540. err = wc_ChaCha20Poly1305_Decrypt(key1, iv1,
  7541. aad1, sizeof(aad1),
  7542. cipher1, sizeof(cipher1),
  7543. authTag1, generatedPlaintext);
  7544. if (err) {
  7545. return err;
  7546. }
  7547. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7548. return WC_TEST_RET_ENC_NC;
  7549. }
  7550. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7551. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7552. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7553. /* Test #2 */
  7554. err = wc_ChaCha20Poly1305_Encrypt(key2, iv2,
  7555. aad2, sizeof(aad2),
  7556. plaintext2, sizeof(plaintext2),
  7557. generatedCiphertext, generatedAuthTag);
  7558. if (err) {
  7559. return err;
  7560. }
  7561. /* -- Check the ciphertext and authtag */
  7562. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7563. return WC_TEST_RET_ENC_NC;
  7564. }
  7565. if (XMEMCMP(generatedAuthTag, authTag2, sizeof(authTag2))) {
  7566. return WC_TEST_RET_ENC_NC;
  7567. }
  7568. /* -- Verify decryption works */
  7569. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2,
  7570. aad2, sizeof(aad2),
  7571. cipher2, sizeof(cipher2),
  7572. authTag2, generatedPlaintext);
  7573. if (err) {
  7574. return err;
  7575. }
  7576. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7577. return WC_TEST_RET_ENC_NC;
  7578. }
  7579. /* AEAD init/update/final - bad argument tests */
  7580. err = wc_ChaCha20Poly1305_Init(NULL, key1, iv1,
  7581. CHACHA20_POLY1305_AEAD_DECRYPT);
  7582. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7583. return WC_TEST_RET_ENC_EC(err);
  7584. err = wc_ChaCha20Poly1305_Init(&aead, NULL, iv1,
  7585. CHACHA20_POLY1305_AEAD_DECRYPT);
  7586. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7587. return WC_TEST_RET_ENC_EC(err);
  7588. err = wc_ChaCha20Poly1305_Init(&aead, key1, NULL,
  7589. CHACHA20_POLY1305_AEAD_DECRYPT);
  7590. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7591. return WC_TEST_RET_ENC_EC(err);
  7592. err = wc_ChaCha20Poly1305_UpdateAad(NULL, aad1, sizeof(aad1));
  7593. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7594. return WC_TEST_RET_ENC_EC(err);
  7595. err = wc_ChaCha20Poly1305_UpdateAad(&aead, NULL, sizeof(aad1));
  7596. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7597. return WC_TEST_RET_ENC_EC(err);
  7598. err = wc_ChaCha20Poly1305_UpdateData(NULL, generatedPlaintext,
  7599. generatedPlaintext, sizeof(plaintext1));
  7600. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7601. return WC_TEST_RET_ENC_EC(err);
  7602. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext, NULL,
  7603. sizeof(plaintext1));
  7604. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7605. return WC_TEST_RET_ENC_EC(err);
  7606. err = wc_ChaCha20Poly1305_UpdateData(&aead, NULL, generatedPlaintext,
  7607. sizeof(plaintext1));
  7608. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7609. return WC_TEST_RET_ENC_EC(err);
  7610. err = wc_ChaCha20Poly1305_Final(NULL, generatedAuthTag);
  7611. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7612. return WC_TEST_RET_ENC_EC(err);
  7613. err = wc_ChaCha20Poly1305_Final(&aead, NULL);
  7614. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7615. return WC_TEST_RET_ENC_EC(err);
  7616. /* AEAD init/update/final - bad state tests */
  7617. /* clear struct - make valgrind happy to resolve
  7618. "Conditional jump or move depends on uninitialised value(s)".
  7619. The enum is "int" size and aead.state is "byte" */
  7620. /* The wc_ChaCha20Poly1305_Init function does this normally */
  7621. XMEMSET(&aead, 0, sizeof(aead));
  7622. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7623. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7624. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7625. return WC_TEST_RET_ENC_EC(err);
  7626. aead.state = CHACHA20_POLY1305_STATE_DATA;
  7627. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7628. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7629. return WC_TEST_RET_ENC_EC(err);
  7630. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7631. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext,
  7632. generatedPlaintext, sizeof(plaintext1));
  7633. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7634. return WC_TEST_RET_ENC_EC(err);
  7635. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7636. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7637. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7638. return WC_TEST_RET_ENC_EC(err);
  7639. aead.state = CHACHA20_POLY1305_STATE_READY;
  7640. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7641. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7642. return WC_TEST_RET_ENC_EC(err);
  7643. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7644. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7645. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7646. /* Test 1 - Encrypt */
  7647. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7648. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7649. if (err != 0)
  7650. return WC_TEST_RET_ENC_EC(err);
  7651. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7652. if (err != 0)
  7653. return WC_TEST_RET_ENC_EC(err);
  7654. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7655. /* test doing data in smaller chunks */
  7656. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7657. word32 dataLen = sizeof(plaintext1) - testLen;
  7658. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7659. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7660. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext1[testLen],
  7661. &generatedCiphertext[testLen], dataLen);
  7662. if (err != 0)
  7663. return WC_TEST_RET_ENC_EC(err);
  7664. testLen += dataLen;
  7665. }
  7666. #else
  7667. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext1,
  7668. generatedCiphertext, sizeof(plaintext1));
  7669. #endif
  7670. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7671. if (err != 0)
  7672. return WC_TEST_RET_ENC_EC(err);
  7673. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7674. if (err != 0)
  7675. return WC_TEST_RET_ENC_EC(err);
  7676. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7677. return WC_TEST_RET_ENC_NC;
  7678. }
  7679. /* Test 1 - Decrypt */
  7680. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7681. CHACHA20_POLY1305_AEAD_DECRYPT);
  7682. if (err != 0)
  7683. return WC_TEST_RET_ENC_EC(err);
  7684. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7685. if (err != 0)
  7686. return WC_TEST_RET_ENC_EC(err);
  7687. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7688. /* test doing data in smaller chunks */
  7689. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7690. word32 dataLen = sizeof(plaintext1) - testLen;
  7691. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7692. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7693. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7694. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7695. dataLen);
  7696. if (err != 0)
  7697. return WC_TEST_RET_ENC_EC(err);
  7698. testLen += dataLen;
  7699. }
  7700. #else
  7701. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7702. generatedPlaintext, sizeof(cipher1));
  7703. #endif
  7704. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7705. if (err != 0)
  7706. return WC_TEST_RET_ENC_EC(err);
  7707. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7708. if (err != 0)
  7709. return WC_TEST_RET_ENC_EC(err);
  7710. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7711. return WC_TEST_RET_ENC_NC;
  7712. }
  7713. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7714. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7715. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7716. /* Test 2 - Encrypt */
  7717. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7718. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7719. if (err != 0)
  7720. return WC_TEST_RET_ENC_EC(err);
  7721. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7722. if (err != 0)
  7723. return WC_TEST_RET_ENC_EC(err);
  7724. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7725. /* test doing data in smaller chunks */
  7726. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7727. word32 dataLen = sizeof(plaintext2) - testLen;
  7728. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7729. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7730. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext2[testLen],
  7731. &generatedCiphertext[testLen], dataLen);
  7732. if (err != 0)
  7733. return WC_TEST_RET_ENC_EC(err);
  7734. testLen += dataLen;
  7735. }
  7736. #else
  7737. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext2, generatedCiphertext,
  7738. sizeof(plaintext2));
  7739. #endif
  7740. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7741. if (err != 0)
  7742. return WC_TEST_RET_ENC_EC(err);
  7743. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7744. if (err != 0)
  7745. return WC_TEST_RET_ENC_EC(err);
  7746. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7747. return WC_TEST_RET_ENC_NC;
  7748. }
  7749. /* Test 2 - Decrypt */
  7750. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7751. CHACHA20_POLY1305_AEAD_DECRYPT);
  7752. if (err != 0)
  7753. return WC_TEST_RET_ENC_EC(err);
  7754. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7755. if (err != 0)
  7756. return WC_TEST_RET_ENC_EC(err);
  7757. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7758. /* test doing data in smaller chunks */
  7759. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7760. word32 dataLen = sizeof(plaintext2) - testLen;
  7761. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7762. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7763. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7764. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7765. dataLen);
  7766. if (err != 0)
  7767. return WC_TEST_RET_ENC_EC(err);
  7768. testLen += dataLen;
  7769. }
  7770. #else
  7771. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7772. generatedPlaintext, sizeof(cipher2));
  7773. #endif
  7774. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7775. if (err != 0)
  7776. return WC_TEST_RET_ENC_EC(err);
  7777. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7778. if (err != 0)
  7779. return WC_TEST_RET_ENC_EC(err);
  7780. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7781. return WC_TEST_RET_ENC_NC;
  7782. }
  7783. return err;
  7784. }
  7785. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  7786. #ifndef NO_DES3
  7787. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void)
  7788. {
  7789. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  7790. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7791. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7792. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7793. };
  7794. byte plain[24];
  7795. byte cipher[24];
  7796. Des enc;
  7797. Des dec;
  7798. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  7799. {
  7800. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  7801. };
  7802. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  7803. {
  7804. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  7805. };
  7806. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  7807. {
  7808. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  7809. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  7810. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  7811. };
  7812. #ifdef WOLFSSL_DES_ECB
  7813. /* "Stay strong and move on!"" */
  7814. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7815. {
  7816. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7817. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7818. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7819. };
  7820. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb[] =
  7821. {
  7822. 0x70,0x4F,0x20,0xF6,0x72,0xB4,0xD0,0x2A,
  7823. 0xB5,0xA9,0x94,0x9F,0x11,0xCF,0x87,0xED,
  7824. 0x13,0x33,0x82,0xCB,0x8B,0xF1,0x82,0x56
  7825. };
  7826. /* "Lemmings" */
  7827. WOLFSSL_SMALL_STACK_STATIC const byte key_ecb[] =
  7828. {
  7829. 0x4C,0x65,0x6D,0x6D,0x69,0x6E,0x67,0x73
  7830. };
  7831. #endif /* WOLFSSL_DES_ECB */
  7832. wc_test_ret_t ret;
  7833. WOLFSSL_ENTER("des_test");
  7834. ret = wc_Des_SetKey(&enc, key, iv, DES_ENCRYPTION);
  7835. if (ret != 0)
  7836. return WC_TEST_RET_ENC_EC(ret);
  7837. ret = wc_Des_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7838. if (ret != 0)
  7839. return WC_TEST_RET_ENC_EC(ret);
  7840. ret = wc_Des_SetKey(&dec, key, iv, DES_DECRYPTION);
  7841. if (ret != 0)
  7842. return WC_TEST_RET_ENC_EC(ret);
  7843. ret = wc_Des_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7844. if (ret != 0)
  7845. return WC_TEST_RET_ENC_EC(ret);
  7846. if (XMEMCMP(plain, vector, sizeof(plain)))
  7847. return WC_TEST_RET_ENC_NC;
  7848. if (XMEMCMP(cipher, verify, sizeof(cipher)))
  7849. return WC_TEST_RET_ENC_NC;
  7850. ret = wc_Des_CbcEncryptWithKey(cipher, vector, sizeof(vector), key, iv);
  7851. if (ret != 0)
  7852. return WC_TEST_RET_ENC_EC(ret);
  7853. /* Test basic ECB Process for DES*/
  7854. #ifdef WOLFSSL_DES_ECB
  7855. ret = wc_Des_SetKey(&enc, key_ecb, iv, DES_ENCRYPTION);
  7856. if (ret != 0)
  7857. return WC_TEST_RET_ENC_EC(ret);
  7858. ret = wc_Des_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector));
  7859. if (ret != 0)
  7860. return WC_TEST_RET_ENC_EC(ret);
  7861. ret = wc_Des_SetKey(&dec, key_ecb, iv, DES_DECRYPTION);
  7862. if (ret != 0)
  7863. return WC_TEST_RET_ENC_EC(ret);
  7864. ret = wc_Des_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  7865. if (ret != 0)
  7866. return WC_TEST_RET_ENC_EC(ret);
  7867. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  7868. return WC_TEST_RET_ENC_NC;
  7869. if (XMEMCMP(cipher, verify_ecb, sizeof(cipher)))
  7870. return WC_TEST_RET_ENC_NC;
  7871. #endif /* WOLFSSL_DES_ECB */
  7872. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  7873. {
  7874. EncryptedInfo info;
  7875. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  7876. XMEMCPY(info.iv, iv, sizeof(iv));
  7877. info.ivSz = sizeof(iv);
  7878. info.keySz = sizeof(key);
  7879. info.cipherType = WC_CIPHER_DES;
  7880. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7881. sizeof(key), WC_HASH_TYPE_SHA);
  7882. if (ret != 0)
  7883. return WC_TEST_RET_ENC_EC(ret);
  7884. /* Test invalid info ptr */
  7885. ret = wc_BufferKeyEncrypt(NULL, cipher, sizeof(cipher), key,
  7886. sizeof(key), WC_HASH_TYPE_SHA);
  7887. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7888. return WC_TEST_RET_ENC_EC(ret);
  7889. #ifndef NO_PWDBASED
  7890. /* Test invalid hash type - only applies to wc_PBKDF1 call */
  7891. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7892. sizeof(key), WC_HASH_TYPE_NONE);
  7893. if (ret == 0)
  7894. return WC_TEST_RET_ENC_EC(ret);
  7895. #endif /* !NO_PWDBASED */
  7896. }
  7897. #endif
  7898. return 0;
  7899. }
  7900. #endif /* !NO_DES3 */
  7901. #ifndef NO_DES3
  7902. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void)
  7903. {
  7904. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  7905. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7906. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7907. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7908. };
  7909. byte plain[24];
  7910. byte cipher[24];
  7911. Des3 enc;
  7912. Des3 dec;
  7913. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  7914. {
  7915. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  7916. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  7917. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  7918. };
  7919. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  7920. {
  7921. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  7922. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  7923. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  7924. };
  7925. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] =
  7926. {
  7927. 0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
  7928. 0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
  7929. 0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
  7930. };
  7931. #ifdef WOLFSSL_DES_ECB
  7932. /* Stay strong and move on! */
  7933. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7934. {
  7935. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7936. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7937. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7938. };
  7939. WOLFSSL_SMALL_STACK_STATIC const byte verify3_ecb[] =
  7940. {
  7941. 0x45,0x7E,0xFA,0xA1,0x05,0xDD,0x48,0x86,
  7942. 0x4D,0xB2,0xAB,0xE4,0xF9,0x63,0xD6,0x54,
  7943. 0x7C,0x5A,0xB3,0x67,0x32,0x25,0x67,0x3D
  7944. };
  7945. /* "Life is what you make it" */
  7946. WOLFSSL_SMALL_STACK_STATIC const byte key3_ecb[] =
  7947. {
  7948. 0x4C,0x69,0x66,0x65,0x20,0x69,0x73,0x20,
  7949. 0x77,0x68,0x61,0x74,0x20,0x79,0x6F,0x75,
  7950. 0x20,0x6D,0x61,0x6B,0x65,0x20,0x69,0x74
  7951. };
  7952. #endif /* WOLFSSL_DES_ECB */
  7953. wc_test_ret_t ret;
  7954. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  7955. size_t i;
  7956. #endif
  7957. WOLFSSL_ENTER("des3_test");
  7958. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7959. if (ret != 0)
  7960. return WC_TEST_RET_ENC_EC(ret);
  7961. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7962. if (ret != 0)
  7963. return WC_TEST_RET_ENC_EC(ret);
  7964. ret = wc_Des3_SetKey(&enc, key3, iv3, DES_ENCRYPTION);
  7965. if (ret != 0)
  7966. return WC_TEST_RET_ENC_EC(ret);
  7967. ret = wc_Des3_SetKey(&dec, key3, iv3, DES_DECRYPTION);
  7968. if (ret != 0)
  7969. return WC_TEST_RET_ENC_EC(ret);
  7970. ret = wc_Des3_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7971. #if defined(WOLFSSL_ASYNC_CRYPT)
  7972. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  7973. #endif
  7974. if (ret != 0)
  7975. return WC_TEST_RET_ENC_EC(ret);
  7976. ret = wc_Des3_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7977. #if defined(WOLFSSL_ASYNC_CRYPT)
  7978. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  7979. #endif
  7980. if (ret != 0)
  7981. return WC_TEST_RET_ENC_EC(ret);
  7982. if (XMEMCMP(plain, vector, sizeof(plain)))
  7983. return WC_TEST_RET_ENC_NC;
  7984. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  7985. return WC_TEST_RET_ENC_NC;
  7986. /* Test basic ECB Process for DES3*/
  7987. #ifdef WOLFSSL_DES_ECB
  7988. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7989. if (ret != 0)
  7990. return WC_TEST_RET_ENC_EC(ret);
  7991. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7992. if (ret != 0)
  7993. return WC_TEST_RET_ENC_EC(ret);
  7994. ret = wc_Des3_SetKey(&enc, key3_ecb, NULL, DES_ENCRYPTION);
  7995. if (ret != 0)
  7996. return WC_TEST_RET_ENC_EC(ret);
  7997. ret = wc_Des3_SetKey(&dec, key3_ecb, NULL, DES_DECRYPTION);
  7998. if (ret != 0)
  7999. return WC_TEST_RET_ENC_EC(ret);
  8000. ret = wc_Des3_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector_ecb));
  8001. #if defined(WOLFSSL_ASYNC_CRYPT)
  8002. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  8003. #endif
  8004. if (ret != 0)
  8005. return WC_TEST_RET_ENC_EC(ret);
  8006. ret = wc_Des3_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  8007. #if defined(WOLFSSL_ASYNC_CRYPT)
  8008. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  8009. #endif
  8010. if (ret != 0)
  8011. return WC_TEST_RET_ENC_EC(ret);
  8012. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  8013. return WC_TEST_RET_ENC_NC;
  8014. if (XMEMCMP(cipher, verify3_ecb, sizeof(cipher)))
  8015. return WC_TEST_RET_ENC_NC;
  8016. #endif /* WOLFSSL_DES_ECB */
  8017. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  8018. /* test the same vectors with using compatibility layer */
  8019. for (i = 0; i < sizeof(vector); i += DES_BLOCK_SIZE){
  8020. DES_key_schedule ks1;
  8021. DES_key_schedule ks2;
  8022. DES_key_schedule ks3;
  8023. DES_cblock iv4;
  8024. byte tmp[sizeof(vector)];
  8025. XMEMCPY(ks1, key3, sizeof(DES_key_schedule));
  8026. XMEMCPY(ks2, key3 + 8, sizeof(DES_key_schedule));
  8027. XMEMCPY(ks3, key3 + 16, sizeof(DES_key_schedule));
  8028. XMEMSET(plain, 0, sizeof(plain));
  8029. XMEMSET(cipher, 0, sizeof(cipher));
  8030. /* Test in-place encrypt/decrypt */
  8031. XMEMCPY(tmp, vector, sizeof(vector));
  8032. /* Use i as the splitter */
  8033. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  8034. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8035. &iv4, DES_ENCRYPT);
  8036. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i),
  8037. &ks1, &ks2, &ks3, &iv4, DES_ENCRYPT);
  8038. XMEMCPY(cipher, tmp, sizeof(cipher));
  8039. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  8040. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8041. &iv4, DES_DECRYPT);
  8042. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i),
  8043. &ks1, &ks2, &ks3, &iv4, DES_DECRYPT);
  8044. XMEMCPY(plain, tmp, sizeof(plain));
  8045. if (XMEMCMP(plain, vector, sizeof(plain)))
  8046. return WC_TEST_RET_ENC_NC;
  8047. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  8048. return WC_TEST_RET_ENC_NC;
  8049. }
  8050. #endif /* OPENSSL_EXTRA */
  8051. wc_Des3Free(&enc);
  8052. wc_Des3Free(&dec);
  8053. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  8054. {
  8055. EncryptedInfo info;
  8056. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  8057. XMEMCPY(info.iv, iv3, sizeof(iv3));
  8058. info.ivSz = sizeof(iv3);
  8059. info.keySz = sizeof(key3);
  8060. info.cipherType = WC_CIPHER_DES3;
  8061. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key3,
  8062. sizeof(key3), WC_HASH_TYPE_SHA);
  8063. if (ret != 0)
  8064. return WC_TEST_RET_ENC_EC(ret);
  8065. }
  8066. #endif
  8067. return 0;
  8068. }
  8069. #endif /* NO_DES3 */
  8070. static const int fiducial1 = WC_TEST_RET_LN; /* source code reference point --
  8071. * see print_fiducials() below.
  8072. */
  8073. #ifndef NO_AES
  8074. #if defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_CFB) || \
  8075. defined(WOLFSSL_AES_XTS)
  8076. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8077. && !defined(HAVE_SELFTEST)
  8078. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  8079. /* pass in the function, key, iv, plain text and expected and this function
  8080. * tests that the encryption and decryption is successful */
  8081. static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
  8082. const byte* iv, const byte* plain, int plainSz,
  8083. const byte* expected, int expectedSz)
  8084. {
  8085. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8086. WOLFSSL_EVP_CIPHER_CTX *ctx = NULL;
  8087. #else
  8088. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  8089. #endif
  8090. int ctx_inited = 0;
  8091. int idx, cipherSz;
  8092. wc_test_ret_t ret = 0;
  8093. byte* cipher;
  8094. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8095. if ((ctx = wolfSSL_EVP_CIPHER_CTX_new()) == NULL)
  8096. return MEMORY_E;
  8097. #endif
  8098. cipher = (byte*)XMALLOC(plainSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8099. if (cipher == NULL) {
  8100. ret = WC_TEST_RET_ENC_ERRNO;
  8101. goto EVP_TEST_END;
  8102. }
  8103. /* test encrypt */
  8104. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  8105. ctx_inited = 1;
  8106. if (wolfSSL_EVP_CipherInit(ctx, type, key, iv, 1) == 0) {
  8107. ret = WC_TEST_RET_ENC_NC;
  8108. goto EVP_TEST_END;
  8109. }
  8110. if (wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, plain, expectedSz) == 0) {
  8111. ret = WC_TEST_RET_ENC_NC;
  8112. goto EVP_TEST_END;
  8113. }
  8114. cipherSz = idx;
  8115. if (wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8116. ret = WC_TEST_RET_ENC_NC;
  8117. goto EVP_TEST_END;
  8118. }
  8119. cipherSz += idx;
  8120. if (XMEMCMP(cipher, expected, plainSz)) {
  8121. ret = WC_TEST_RET_ENC_NC;
  8122. goto EVP_TEST_END;
  8123. }
  8124. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8125. ctx_inited = 0;
  8126. if (ret == WOLFSSL_SUCCESS)
  8127. ret = 0;
  8128. else {
  8129. ret = WC_TEST_RET_ENC_NC;
  8130. goto EVP_TEST_END;
  8131. }
  8132. /* test decrypt */
  8133. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  8134. ctx_inited = 1;
  8135. if (wolfSSL_EVP_CipherInit(ctx, type, key, iv, 0) == 0) {
  8136. ret = WC_TEST_RET_ENC_NC;
  8137. goto EVP_TEST_END;
  8138. }
  8139. if (wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, cipher, expectedSz) == 0) {
  8140. ret = WC_TEST_RET_ENC_NC;
  8141. goto EVP_TEST_END;
  8142. }
  8143. cipherSz = idx;
  8144. if (wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8145. ret = WC_TEST_RET_ENC_NC;
  8146. goto EVP_TEST_END;
  8147. }
  8148. cipherSz += idx;
  8149. if ((expectedSz != cipherSz) || XMEMCMP(plain, cipher, plainSz)) {
  8150. ret = WC_TEST_RET_ENC_NC;
  8151. goto EVP_TEST_END;
  8152. }
  8153. EVP_TEST_END:
  8154. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8155. (void)cipherSz;
  8156. if (ctx_inited) {
  8157. int cleanup_ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8158. if (cleanup_ret != WOLFSSL_SUCCESS)
  8159. ret = WC_TEST_RET_ENC_NC;
  8160. }
  8161. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8162. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  8163. #endif
  8164. return ret;
  8165. }
  8166. #endif /* !HAVE_FIPS || FIPS_VERSION3_GE(6,0,0) */
  8167. #endif /* OPENSSL_EXTRA && !WOLFCRYPT_ONLY && !HAVE_SELFTEST */
  8168. #endif /* WOLFSSL_AES_OFB || WOLFSSL_AES_CFB */
  8169. #ifdef WOLFSSL_AES_OFB
  8170. /* test vector from https://csrc.nist.gov/Projects/cryptographic-algorithm-validation-program/Block-Ciphers */
  8171. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void)
  8172. {
  8173. #ifdef WOLFSSL_AES_256
  8174. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8175. {
  8176. 0xc4,0xc7,0xfa,0xd6,0x53,0x5c,0xb8,0x71,
  8177. 0x4a,0x5c,0x40,0x77,0x9a,0x8b,0xa1,0xd2,
  8178. 0x53,0x3e,0x23,0xb4,0xb2,0x58,0x73,0x2a,
  8179. 0x5b,0x78,0x01,0xf4,0xe3,0x71,0xa7,0x94
  8180. };
  8181. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  8182. {
  8183. 0x5e,0xb9,0x33,0x13,0xb8,0x71,0xff,0x16,
  8184. 0xb9,0x8a,0x9b,0xcb,0x43,0x33,0x0d,0x6f
  8185. };
  8186. WOLFSSL_SMALL_STACK_STATIC const byte plain1[] =
  8187. {
  8188. 0x6d,0x0b,0xb0,0x79,0x63,0x84,0x71,0xe9,
  8189. 0x39,0xd4,0x53,0x14,0x86,0xc1,0x4c,0x25,
  8190. 0x9a,0xee,0xc6,0xf3,0xc0,0x0d,0xfd,0xd6,
  8191. 0xc0,0x50,0xa8,0xba,0xa8,0x20,0xdb,0x71,
  8192. 0xcc,0x12,0x2c,0x4e,0x0c,0x17,0x15,0xef,
  8193. 0x55,0xf3,0x99,0x5a,0x6b,0xf0,0x2a,0x4c
  8194. };
  8195. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8196. {
  8197. 0x0f,0x54,0x61,0x71,0x59,0xd0,0x3f,0xfc,
  8198. 0x1b,0xfa,0xfb,0x60,0x29,0x30,0xd7,0x00,
  8199. 0xf4,0xa4,0xa8,0xe6,0xdd,0x93,0x94,0x46,
  8200. 0x64,0xd2,0x19,0xc4,0xc5,0x4d,0xde,0x1b,
  8201. 0x04,0x53,0xe1,0x73,0xf5,0x18,0x74,0xae,
  8202. 0xfd,0x64,0xa2,0xe1,0xe2,0x76,0x13,0xb0
  8203. };
  8204. #endif /* WOLFSSL_AES_256 */
  8205. #ifdef WOLFSSL_AES_128
  8206. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8207. {
  8208. 0x10,0xa5,0x88,0x69,0xd7,0x4b,0xe5,0xa3,
  8209. 0x74,0xcf,0x86,0x7c,0xfb,0x47,0x38,0x59
  8210. };
  8211. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  8212. {
  8213. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8214. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8215. };
  8216. WOLFSSL_SMALL_STACK_STATIC const byte plain2[] =
  8217. {
  8218. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8219. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8220. };
  8221. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8222. {
  8223. 0x6d,0x25,0x1e,0x69,0x44,0xb0,0x51,0xe0,
  8224. 0x4e,0xaa,0x6f,0xb4,0xdb,0xf7,0x84,0x65
  8225. };
  8226. #endif /* WOLFSSL_AES_128 */
  8227. #ifdef WOLFSSL_AES_192
  8228. WOLFSSL_SMALL_STACK_STATIC const byte key3[] = {
  8229. 0xd0,0x77,0xa0,0x3b,0xd8,0xa3,0x89,0x73,
  8230. 0x92,0x8c,0xca,0xfe,0x4a,0x9d,0x2f,0x45,
  8231. 0x51,0x30,0xbd,0x0a,0xf5,0xae,0x46,0xa9
  8232. };
  8233. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  8234. {
  8235. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8236. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8237. };
  8238. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8239. {
  8240. 0xab,0xc7,0x86,0xfb,0x1e,0xdb,0x50,0x45,
  8241. 0x80,0xc4,0xd8,0x82,0xef,0x29,0xa0,0xc7
  8242. };
  8243. WOLFSSL_SMALL_STACK_STATIC const byte plain3[] =
  8244. {
  8245. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8246. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8247. };
  8248. #endif /* WOLFSSL_AES_192 */
  8249. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8250. Aes *enc = NULL;
  8251. #else
  8252. Aes enc[1];
  8253. #endif
  8254. byte cipher[AES_BLOCK_SIZE * 4];
  8255. #ifdef HAVE_AES_DECRYPT
  8256. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8257. Aes *dec = NULL;
  8258. #else
  8259. Aes dec[1];
  8260. #endif
  8261. byte plain [AES_BLOCK_SIZE * 4];
  8262. #endif
  8263. wc_test_ret_t ret = 0;
  8264. WOLFSSL_ENTER("aesofb_test");
  8265. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8266. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8267. if (enc == NULL)
  8268. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8269. #ifdef HAVE_AES_DECRYPT
  8270. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8271. if (dec == NULL)
  8272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8273. #endif
  8274. #else
  8275. XMEMSET(enc, 0, sizeof(Aes));
  8276. #ifdef HAVE_AES_DECRYPT
  8277. XMEMSET(dec, 0, sizeof(Aes));
  8278. #endif
  8279. ret = wc_AesInit(enc, HEAP_HINT, INVALID_DEVID);
  8280. if (ret != 0)
  8281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8282. #ifdef HAVE_AES_DECRYPT
  8283. ret = wc_AesInit(dec, HEAP_HINT, INVALID_DEVID);
  8284. if (ret != 0)
  8285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8286. #endif
  8287. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8288. #ifdef WOLFSSL_AES_128
  8289. /* 128 key size test */
  8290. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8291. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8292. ret = EVP_test(wolfSSL_EVP_aes_128_ofb(), key2, iv2, plain2, sizeof(plain2),
  8293. cipher2, sizeof(cipher2));
  8294. if (ret != 0) {
  8295. goto out;
  8296. }
  8297. #endif
  8298. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8299. if (ret != 0)
  8300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8301. #ifdef HAVE_AES_DECRYPT
  8302. /* decrypt uses AES_ENCRYPTION */
  8303. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8304. if (ret != 0)
  8305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8306. #endif
  8307. XMEMSET(cipher, 0, sizeof(cipher));
  8308. ret = wc_AesOfbEncrypt(enc, cipher, plain2, AES_BLOCK_SIZE);
  8309. if (ret != 0)
  8310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8311. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE))
  8312. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8313. #ifdef HAVE_AES_DECRYPT
  8314. ret = wc_AesOfbDecrypt(dec, plain, cipher2, AES_BLOCK_SIZE);
  8315. if (ret != 0)
  8316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8317. if (XMEMCMP(plain, plain2, AES_BLOCK_SIZE))
  8318. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8319. #endif /* HAVE_AES_DECRYPT */
  8320. #endif /* WOLFSSL_AES_128 */
  8321. #ifdef WOLFSSL_AES_192
  8322. /* 192 key size test */
  8323. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8324. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8325. ret = EVP_test(wolfSSL_EVP_aes_192_ofb(), key3, iv3, plain3, sizeof(plain3),
  8326. cipher3, sizeof(cipher3));
  8327. if (ret != 0) {
  8328. goto out;
  8329. }
  8330. #endif
  8331. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8332. if (ret != 0)
  8333. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8334. #ifdef HAVE_AES_DECRYPT
  8335. /* decrypt uses AES_ENCRYPTION */
  8336. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8337. if (ret != 0)
  8338. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8339. #endif
  8340. XMEMSET(cipher, 0, sizeof(cipher));
  8341. ret = wc_AesOfbEncrypt(enc, cipher, plain3, AES_BLOCK_SIZE);
  8342. if (ret != 0)
  8343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8344. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE))
  8345. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8346. #ifdef HAVE_AES_DECRYPT
  8347. ret = wc_AesOfbDecrypt(dec, plain, cipher3, AES_BLOCK_SIZE);
  8348. if (ret != 0)
  8349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8350. if (XMEMCMP(plain, plain3, AES_BLOCK_SIZE))
  8351. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8352. #endif /* HAVE_AES_DECRYPT */
  8353. #endif /* WOLFSSL_AES_192 */
  8354. #ifdef WOLFSSL_AES_256
  8355. /* 256 key size test */
  8356. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8357. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8358. ret = EVP_test(wolfSSL_EVP_aes_256_ofb(), key1, iv1, plain1, sizeof(plain1),
  8359. cipher1, sizeof(cipher1));
  8360. if (ret != 0) {
  8361. goto out;
  8362. }
  8363. #endif
  8364. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8365. if (ret != 0)
  8366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8367. #ifdef HAVE_AES_DECRYPT
  8368. /* decrypt uses AES_ENCRYPTION */
  8369. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8370. if (ret != 0)
  8371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8372. #endif
  8373. XMEMSET(cipher, 0, sizeof(cipher));
  8374. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE);
  8375. if (ret != 0)
  8376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8377. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE))
  8378. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8379. ret = wc_AesOfbEncrypt(enc, cipher + AES_BLOCK_SIZE,
  8380. plain1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8381. if (ret != 0)
  8382. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8383. if (XMEMCMP(cipher + AES_BLOCK_SIZE, cipher1 + AES_BLOCK_SIZE,
  8384. AES_BLOCK_SIZE))
  8385. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8386. #ifdef HAVE_AES_DECRYPT
  8387. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE);
  8388. if (ret != 0)
  8389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8390. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE))
  8391. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8392. ret = wc_AesOfbDecrypt(dec, plain + AES_BLOCK_SIZE,
  8393. cipher1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8394. if (ret != 0)
  8395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8396. if (XMEMCMP(plain + AES_BLOCK_SIZE, plain1 + AES_BLOCK_SIZE,
  8397. AES_BLOCK_SIZE))
  8398. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8399. #endif /* HAVE_AES_DECRYPT */
  8400. /* multiple blocks at once */
  8401. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8402. if (ret != 0)
  8403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8404. #ifdef HAVE_AES_DECRYPT
  8405. /* decrypt uses AES_ENCRYPTION */
  8406. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8407. if (ret != 0)
  8408. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8409. #endif
  8410. XMEMSET(cipher, 0, sizeof(cipher));
  8411. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE * 3);
  8412. if (ret != 0)
  8413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8414. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 3))
  8415. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8416. #ifdef HAVE_AES_DECRYPT
  8417. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE * 3);
  8418. if (ret != 0)
  8419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8420. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE * 3))
  8421. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8422. #endif /* HAVE_AES_DECRYPT */
  8423. /* inline decrypt/encrypt*/
  8424. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8425. if (ret != 0)
  8426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8427. #ifdef HAVE_AES_DECRYPT
  8428. /* decrypt uses AES_ENCRYPTION */
  8429. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8430. if (ret != 0)
  8431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8432. #endif
  8433. XMEMCPY(cipher, plain1, AES_BLOCK_SIZE * 2);
  8434. ret = wc_AesOfbEncrypt(enc, cipher, cipher, AES_BLOCK_SIZE * 2);
  8435. if (ret != 0)
  8436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8437. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8438. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8439. #ifdef HAVE_AES_DECRYPT
  8440. ret = wc_AesOfbDecrypt(dec, cipher, cipher, AES_BLOCK_SIZE * 2);
  8441. if (ret != 0)
  8442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8443. if (XMEMCMP(cipher, plain1, AES_BLOCK_SIZE * 2))
  8444. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8445. #endif /* HAVE_AES_DECRYPT */
  8446. /* 256 key size test leftover support */
  8447. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8448. if (ret != 0)
  8449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8450. #ifdef HAVE_AES_DECRYPT
  8451. /* decrypt uses AES_ENCRYPTION */
  8452. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8453. if (ret != 0)
  8454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8455. #endif
  8456. XMEMSET(cipher, 0, sizeof(cipher));
  8457. ret = wc_AesOfbEncrypt(enc, cipher, plain1, 3);
  8458. if (ret != 0)
  8459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8460. if (XMEMCMP(cipher, cipher1, 3))
  8461. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8462. ret = wc_AesOfbEncrypt(enc, cipher + 3, plain1 + 3, AES_BLOCK_SIZE);
  8463. if (ret != 0)
  8464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8465. if (XMEMCMP(cipher + 3, cipher1 + 3, AES_BLOCK_SIZE))
  8466. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8467. #ifdef HAVE_AES_DECRYPT
  8468. ret = wc_AesOfbDecrypt(dec, plain, cipher1, 6);
  8469. if (ret != 0)
  8470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8471. if (XMEMCMP(plain, plain1, 6))
  8472. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8473. ret = wc_AesOfbDecrypt(dec, plain + 6, cipher1 + 6, AES_BLOCK_SIZE);
  8474. if (ret != 0)
  8475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8476. if (XMEMCMP(plain + 6, plain1 + 6, AES_BLOCK_SIZE))
  8477. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8478. #endif /* HAVE_AES_DECRYPT */
  8479. out:
  8480. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8481. wc_AesDelete(enc, &enc);
  8482. #else
  8483. wc_AesFree(enc);
  8484. #endif
  8485. #ifdef HAVE_AES_DECRYPT
  8486. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8487. wc_AesDelete(dec, &dec);
  8488. #else
  8489. wc_AesFree(dec);
  8490. #endif
  8491. #endif
  8492. #endif /* WOLFSSL_AES_256 */
  8493. return ret;
  8494. }
  8495. #endif /* WOLFSSL_AES_OFB */
  8496. #if defined(WOLFSSL_AES_CFB)
  8497. /* Test cases from NIST SP 800-38A, Recommendation for Block Cipher Modes of
  8498. * Operation Methods and Techniques
  8499. */
  8500. static wc_test_ret_t aescfb_test_0(void)
  8501. {
  8502. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8503. Aes *enc = NULL;
  8504. #else
  8505. Aes enc[1];
  8506. #endif
  8507. byte cipher[AES_BLOCK_SIZE * 4];
  8508. #ifdef HAVE_AES_DECRYPT
  8509. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8510. Aes *dec = NULL;
  8511. #else
  8512. Aes dec[1];
  8513. #endif
  8514. byte plain [AES_BLOCK_SIZE * 4];
  8515. #endif
  8516. wc_test_ret_t ret = 0;
  8517. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8518. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  8519. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  8520. };
  8521. #ifdef WOLFSSL_AES_128
  8522. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8523. {
  8524. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  8525. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  8526. };
  8527. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8528. {
  8529. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  8530. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  8531. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  8532. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b,
  8533. 0x26,0x75,0x1f,0x67,0xa3,0xcb,0xb1,0x40,
  8534. 0xb1,0x80,0x8c,0xf1,0x87,0xa4,0xf4,0xdf
  8535. };
  8536. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8537. {
  8538. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8539. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8540. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8541. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8542. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8543. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef
  8544. };
  8545. #endif /* WOLFSSL_AES_128 */
  8546. #ifdef WOLFSSL_AES_192
  8547. /* 192 size key test */
  8548. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8549. {
  8550. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  8551. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  8552. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  8553. };
  8554. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8555. {
  8556. 0xcd,0xc8,0x0d,0x6f,0xdd,0xf1,0x8c,0xab,
  8557. 0x34,0xc2,0x59,0x09,0xc9,0x9a,0x41,0x74,
  8558. 0x67,0xce,0x7f,0x7f,0x81,0x17,0x36,0x21,
  8559. 0x96,0x1a,0x2b,0x70,0x17,0x1d,0x3d,0x7a,
  8560. 0x2e,0x1e,0x8a,0x1d,0xd5,0x9b,0x88,0xb1,
  8561. 0xc8,0xe6,0x0f,0xed,0x1e,0xfa,0xc4,0xc9,
  8562. 0xc0,0x5f,0x9f,0x9c,0xa9,0x83,0x4f,0xa0,
  8563. 0x42,0xae,0x8f,0xba,0x58,0x4b,0x09,0xff
  8564. };
  8565. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8566. {
  8567. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8568. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8569. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8570. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8571. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8572. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8573. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8574. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8575. };
  8576. #endif /* WOLFSSL_AES_192 */
  8577. #ifdef WOLFSSL_AES_256
  8578. /* 256 size key simple test */
  8579. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8580. {
  8581. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  8582. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  8583. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  8584. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  8585. };
  8586. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8587. {
  8588. 0xdc,0x7e,0x84,0xbf,0xda,0x79,0x16,0x4b,
  8589. 0x7e,0xcd,0x84,0x86,0x98,0x5d,0x38,0x60,
  8590. 0x39,0xff,0xed,0x14,0x3b,0x28,0xb1,0xc8,
  8591. 0x32,0x11,0x3c,0x63,0x31,0xe5,0x40,0x7b,
  8592. 0xdf,0x10,0x13,0x24,0x15,0xe5,0x4b,0x92,
  8593. 0xa1,0x3e,0xd0,0xa8,0x26,0x7a,0xe2,0xf9,
  8594. 0x75,0xa3,0x85,0x74,0x1a,0xb9,0xce,0xf8,
  8595. 0x20,0x31,0x62,0x3d,0x55,0xb1,0xe4,0x71
  8596. };
  8597. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8598. {
  8599. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8600. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8601. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8602. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8603. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8604. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8605. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8606. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8607. };
  8608. #endif /* WOLFSSL_AES_256 */
  8609. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8610. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8611. if (enc == NULL)
  8612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8613. #ifdef HAVE_AES_DECRYPT
  8614. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8615. if (dec == NULL)
  8616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8617. #endif
  8618. #else
  8619. XMEMSET(enc, 0, sizeof(Aes));
  8620. #ifdef HAVE_AES_DECRYPT
  8621. XMEMSET(dec, 0, sizeof(Aes));
  8622. #endif
  8623. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8624. if (ret != 0)
  8625. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8626. #ifdef HAVE_AES_DECRYPT
  8627. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8628. if (ret != 0)
  8629. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8630. #endif
  8631. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8632. #ifdef WOLFSSL_AES_128
  8633. /* 128 key tests */
  8634. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8635. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8636. ret = EVP_test(wolfSSL_EVP_aes_128_cfb128(), key1, iv, msg1, sizeof(msg1),
  8637. cipher1, sizeof(cipher1));
  8638. if (ret != 0) {
  8639. return ret;
  8640. }
  8641. #endif
  8642. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8643. if (ret != 0)
  8644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8645. #ifdef HAVE_AES_DECRYPT
  8646. /* decrypt uses AES_ENCRYPTION */
  8647. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8648. if (ret != 0)
  8649. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8650. #endif
  8651. XMEMSET(cipher, 0, sizeof(cipher));
  8652. ret = wc_AesCfbEncrypt(enc, cipher, msg1, AES_BLOCK_SIZE * 2);
  8653. if (ret != 0)
  8654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8655. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8656. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8657. /* test restarting encryption process */
  8658. ret = wc_AesCfbEncrypt(enc, cipher + (AES_BLOCK_SIZE * 2),
  8659. msg1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE);
  8660. if (ret != 0)
  8661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8662. if (XMEMCMP(cipher + (AES_BLOCK_SIZE * 2),
  8663. cipher1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE))
  8664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8665. #ifdef HAVE_AES_DECRYPT
  8666. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 3);
  8667. if (ret != 0)
  8668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8669. if (XMEMCMP(plain, msg1, AES_BLOCK_SIZE * 3))
  8670. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8671. #endif /* HAVE_AES_DECRYPT */
  8672. #endif /* WOLFSSL_AES_128 */
  8673. #ifdef WOLFSSL_AES_192
  8674. /* 192 key size test */
  8675. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8676. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8677. ret = EVP_test(wolfSSL_EVP_aes_192_cfb128(), key2, iv, msg2, sizeof(msg2),
  8678. cipher2, sizeof(cipher2));
  8679. if (ret != 0) {
  8680. return ret;
  8681. }
  8682. #endif
  8683. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8684. if (ret != 0)
  8685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8686. #ifdef HAVE_AES_DECRYPT
  8687. /* decrypt uses AES_ENCRYPTION */
  8688. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8689. if (ret != 0)
  8690. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8691. #endif
  8692. XMEMSET(cipher, 0, sizeof(cipher));
  8693. ret = wc_AesCfbEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE * 4);
  8694. if (ret != 0)
  8695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8696. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE * 4))
  8697. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8698. #ifdef HAVE_AES_DECRYPT
  8699. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 4);
  8700. if (ret != 0)
  8701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8702. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE * 4))
  8703. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8704. #endif /* HAVE_AES_DECRYPT */
  8705. #endif /* WOLFSSL_AES_192 */
  8706. #ifdef WOLFSSL_AES_256
  8707. /* 256 key size test */
  8708. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8709. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8710. ret = EVP_test(wolfSSL_EVP_aes_256_cfb128(), key3, iv, msg3, sizeof(msg3),
  8711. cipher3, sizeof(cipher3));
  8712. if (ret != 0) {
  8713. return ret;
  8714. }
  8715. #endif
  8716. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8717. if (ret != 0)
  8718. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8719. #ifdef HAVE_AES_DECRYPT
  8720. /* decrypt uses AES_ENCRYPTION */
  8721. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8722. if (ret != 0)
  8723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8724. #endif
  8725. /* test with data left overs, magic lengths are checking near edges */
  8726. XMEMSET(cipher, 0, sizeof(cipher));
  8727. ret = wc_AesCfbEncrypt(enc, cipher, msg3, 4);
  8728. if (ret != 0)
  8729. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8730. if (XMEMCMP(cipher, cipher3, 4))
  8731. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8732. ret = wc_AesCfbEncrypt(enc, cipher + 4, msg3 + 4, 27);
  8733. if (ret != 0)
  8734. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8735. if (XMEMCMP(cipher + 4, cipher3 + 4, 27))
  8736. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8737. ret = wc_AesCfbEncrypt(enc, cipher + 31, msg3 + 31,
  8738. (AES_BLOCK_SIZE * 4) - 31);
  8739. if (ret != 0)
  8740. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8741. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE * 4))
  8742. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8743. #ifdef HAVE_AES_DECRYPT
  8744. ret = wc_AesCfbDecrypt(dec, plain, cipher, 4);
  8745. if (ret != 0)
  8746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8747. if (XMEMCMP(plain, msg3, 4))
  8748. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8749. ret = wc_AesCfbDecrypt(dec, plain + 4, cipher + 4, 4);
  8750. if (ret != 0)
  8751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8752. ret = wc_AesCfbDecrypt(dec, plain + 8, cipher + 8, 23);
  8753. if (ret != 0)
  8754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8755. if (XMEMCMP(plain + 4, msg3 + 4, 27))
  8756. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8757. ret = wc_AesCfbDecrypt(dec, plain + 31, cipher + 31,
  8758. (AES_BLOCK_SIZE * 4) - 31);
  8759. if (ret != 0)
  8760. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8761. if (XMEMCMP(plain, msg3, AES_BLOCK_SIZE * 4))
  8762. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8763. #endif /* HAVE_AES_DECRYPT */
  8764. #endif /* WOLFSSL_AES_256 */
  8765. out:
  8766. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8767. wc_AesDelete(enc, &enc);
  8768. #else
  8769. wc_AesFree(enc);
  8770. #endif
  8771. #ifdef HAVE_AES_DECRYPT
  8772. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8773. wc_AesDelete(dec, &dec);
  8774. #else
  8775. wc_AesFree(dec);
  8776. #endif
  8777. #endif
  8778. return ret;
  8779. }
  8780. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0))
  8781. static wc_test_ret_t aescfb1_test(void)
  8782. {
  8783. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8784. Aes *enc = NULL;
  8785. #else
  8786. Aes enc[1];
  8787. #endif
  8788. byte cipher[AES_BLOCK_SIZE];
  8789. #ifdef HAVE_AES_DECRYPT
  8790. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8791. Aes *dec = NULL;
  8792. #else
  8793. Aes dec[1];
  8794. #endif
  8795. byte plain [AES_BLOCK_SIZE];
  8796. #endif
  8797. wc_test_ret_t ret = 0;
  8798. #ifdef WOLFSSL_AES_128
  8799. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8800. 0x4d,0xbb,0xdc,0xaa,0x59,0xf3,0x63,0xc9,
  8801. 0x2a,0x3b,0x98,0x43,0xad,0x20,0xe2,0xb7
  8802. };
  8803. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8804. {
  8805. 0xcd,0xef,0x9d,0x06,0x61,0xba,0xe4,0x73,
  8806. 0x8d,0x1a,0x58,0xa2,0xa6,0x22,0x8b,0x66
  8807. };
  8808. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8809. {
  8810. 0x00
  8811. };
  8812. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8813. {
  8814. 0xC0
  8815. };
  8816. WOLFSSL_SMALL_STACK_STATIC const byte cipher1_7bit[] =
  8817. {
  8818. 0x1C
  8819. };
  8820. #endif /* WOLFSSL_AES_128 */
  8821. #ifdef WOLFSSL_AES_192
  8822. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  8823. 0x57,0xc6,0x89,0x7c,0x99,0x52,0x28,0x13,
  8824. 0xbf,0x67,0x9c,0xe1,0x13,0x70,0xaf,0x5e
  8825. };
  8826. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8827. {
  8828. 0xba,0xa1,0x58,0xa1,0x6b,0x50,0x4a,0x10,
  8829. 0x8e,0xd4,0x33,0x2e,0xe7,0xf2,0x9b,0xf6,
  8830. 0xd1,0xac,0x46,0xa8,0xde,0x5a,0xfe,0x7a
  8831. };
  8832. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8833. {
  8834. 0x30
  8835. };
  8836. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8837. {
  8838. 0x80
  8839. };
  8840. #endif /* WOLFSSL_AES_192 */
  8841. #ifdef WOLFSSL_AES_256
  8842. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  8843. 0x63,0x2e,0x9f,0x83,0x1f,0xa3,0x80,0x5e,
  8844. 0x52,0x02,0xbc,0xe0,0x6d,0x04,0xf9,0xa0
  8845. };
  8846. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8847. {
  8848. 0xf6,0xfa,0xe4,0xf1,0x5d,0x91,0xfc,0x50,
  8849. 0x88,0x78,0x4f,0x84,0xa5,0x37,0x12,0x7e,
  8850. 0x32,0x63,0x55,0x9c,0x62,0x73,0x88,0x20,
  8851. 0xc2,0xcf,0x3d,0xe1,0x1c,0x2a,0x30,0x40
  8852. };
  8853. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8854. {
  8855. 0xF7, 0x00
  8856. };
  8857. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8858. {
  8859. 0x41, 0xC0
  8860. };
  8861. #endif /* WOLFSSL_AES_256 */
  8862. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8863. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8864. if (enc == NULL)
  8865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8866. #ifdef HAVE_AES_DECRYPT
  8867. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8868. if (dec == NULL)
  8869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8870. #endif
  8871. #else
  8872. XMEMSET(enc, 0, sizeof(Aes));
  8873. #ifdef HAVE_AES_DECRYPT
  8874. XMEMSET(dec, 0, sizeof(Aes));
  8875. #endif
  8876. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8877. if (ret != 0)
  8878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8879. #ifdef HAVE_AES_DECRYPT
  8880. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8881. if (ret != 0)
  8882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8883. #endif
  8884. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8885. #ifdef WOLFSSL_AES_128
  8886. /* 128 key tests */
  8887. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8888. if (ret != 0)
  8889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8890. #ifdef HAVE_AES_DECRYPT
  8891. /* decrypt uses AES_ENCRYPTION */
  8892. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8893. if (ret != 0)
  8894. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8895. #endif
  8896. XMEMSET(cipher, 0, sizeof(cipher));
  8897. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 2);
  8898. if (ret != 0)
  8899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8900. if (cipher[0] != cipher1[0])
  8901. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8902. #ifdef HAVE_AES_DECRYPT
  8903. ret = wc_AesCfb1Decrypt(dec, plain, cipher, 2);
  8904. if (ret != 0)
  8905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8906. if (plain[0] != msg1[0])
  8907. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8908. #endif /* HAVE_AES_DECRYPT */
  8909. XMEMSET(cipher, 0, sizeof(cipher));
  8910. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 7);
  8911. if (ret != 0)
  8912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8913. if (cipher[0] != cipher1_7bit[0])
  8914. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8915. #ifdef OPENSSL_EXTRA
  8916. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8917. if (ret != 0)
  8918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8919. XMEMSET(cipher, 0, sizeof(cipher));
  8920. ret = wc_AesCfb1Encrypt(enc, cipher, msg1,
  8921. sizeof(msg1) * WOLFSSL_BIT_SIZE);
  8922. if (ret != 0)
  8923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8924. #ifndef WOLFCRYPT_ONLY
  8925. ret = EVP_test(wolfSSL_EVP_aes_128_cfb1(), key1, iv, msg1, sizeof(msg1),
  8926. cipher, sizeof(msg1));
  8927. if (ret != 0) {
  8928. goto out;
  8929. }
  8930. #endif
  8931. #endif
  8932. #endif /* WOLFSSL_AES_128 */
  8933. #ifdef WOLFSSL_AES_192
  8934. /* 192 key tests */
  8935. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8936. if (ret != 0)
  8937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8938. XMEMSET(cipher, 0, sizeof(cipher));
  8939. ret = wc_AesCfb1Encrypt(enc, cipher, msg2, 4);
  8940. if (ret != 0)
  8941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8942. if (XMEMCMP(cipher, cipher2, sizeof(cipher2)) != 0)
  8943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8944. #ifdef OPENSSL_EXTRA
  8945. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8946. if (ret != 0)
  8947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8948. XMEMSET(cipher, 0, sizeof(cipher));
  8949. ret = wc_AesCfb1Encrypt(enc, cipher, msg2,
  8950. sizeof(msg2) * WOLFSSL_BIT_SIZE);
  8951. if (ret != 0)
  8952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8953. #ifndef WOLFCRYPT_ONLY
  8954. ret = EVP_test(wolfSSL_EVP_aes_192_cfb1(), key2, iv2, msg2, sizeof(msg2),
  8955. cipher, sizeof(msg2));
  8956. if (ret != 0) {
  8957. goto out;
  8958. }
  8959. #endif
  8960. #endif
  8961. #endif /* WOLFSSL_AES_192 */
  8962. #ifdef WOLFSSL_AES_256
  8963. /* 256 key tests */
  8964. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8965. if (ret != 0)
  8966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8967. XMEMSET(cipher, 0, sizeof(cipher));
  8968. ret = wc_AesCfb1Encrypt(enc, cipher, msg3, 10);
  8969. if (ret != 0)
  8970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8971. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  8972. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8973. #ifdef OPENSSL_EXTRA
  8974. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8975. if (ret != 0)
  8976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8977. XMEMSET(cipher, 0, sizeof(cipher));
  8978. ret = wc_AesCfb1Encrypt(enc, cipher, msg3,
  8979. sizeof(msg3) * WOLFSSL_BIT_SIZE);
  8980. if (ret != 0)
  8981. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8982. #ifndef WOLFCRYPT_ONLY
  8983. ret = EVP_test(wolfSSL_EVP_aes_256_cfb1(), key3, iv3, msg3, sizeof(msg3),
  8984. cipher, sizeof(msg3));
  8985. if (ret != 0) {
  8986. goto out;
  8987. }
  8988. #endif
  8989. #endif
  8990. #endif /* WOLFSSL_AES_256 */
  8991. out:
  8992. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8993. wc_AesDelete(enc, &enc);
  8994. #else
  8995. wc_AesFree(enc);
  8996. #endif
  8997. #ifdef HAVE_AES_DECRYPT
  8998. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8999. wc_AesDelete(dec, &dec);
  9000. #else
  9001. wc_AesFree(dec);
  9002. #endif
  9003. #endif
  9004. return ret;
  9005. }
  9006. static wc_test_ret_t aescfb8_test(void)
  9007. {
  9008. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9009. Aes *enc = NULL;
  9010. #else
  9011. Aes enc[1];
  9012. #endif
  9013. byte cipher[AES_BLOCK_SIZE];
  9014. #ifdef HAVE_AES_DECRYPT
  9015. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9016. Aes *dec = NULL;
  9017. #else
  9018. Aes dec[1];
  9019. #endif
  9020. byte plain [AES_BLOCK_SIZE];
  9021. #endif
  9022. wc_test_ret_t ret = 0;
  9023. #ifdef WOLFSSL_AES_128
  9024. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  9025. 0xf4,0x75,0xc6,0x49,0x91,0xb2,0x0e,0xae,
  9026. 0xe1,0x83,0xa2,0x26,0x29,0xe2,0x1e,0x22
  9027. };
  9028. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  9029. {
  9030. 0xc8,0xfe,0x9b,0xf7,0x7b,0x93,0x0f,0x46,
  9031. 0xd2,0x07,0x8b,0x8c,0x0e,0x65,0x7c,0xd4
  9032. };
  9033. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  9034. {
  9035. 0xd2,0x76,0x91
  9036. };
  9037. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  9038. {
  9039. 0xc9,0x06,0x35
  9040. };
  9041. #endif /* WOLFSSL_AES_128 */
  9042. #ifdef WOLFSSL_AES_192
  9043. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  9044. 0x0a,0x02,0x84,0x6b,0x62,0xab,0xb6,0x93,
  9045. 0xef,0x31,0xd7,0x54,0x84,0x2e,0xed,0x29
  9046. };
  9047. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  9048. {
  9049. 0xba,0xf0,0x8b,0x76,0x31,0x7a,0x65,0xc5,
  9050. 0xf0,0x7a,0xe6,0xf5,0x7e,0xb0,0xe6,0x54,
  9051. 0x88,0x65,0x93,0x24,0xd2,0x97,0x09,0xe3
  9052. };
  9053. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  9054. {
  9055. 0x72,0x9c,0x0b,0x6d,0xeb,0x75,0xfa,0x6e,
  9056. 0xb5,0xe8
  9057. };
  9058. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  9059. {
  9060. 0x98,0x95,0x93,0x24,0x02,0x39,0x3d,0xc3,
  9061. 0x3a,0x60
  9062. };
  9063. #endif
  9064. #ifdef WOLFSSL_AES_256
  9065. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  9066. 0x33,0x8c,0x55,0x2f,0xf1,0xec,0xa1,0x44,
  9067. 0x08,0xe0,0x5d,0x8c,0xf9,0xf3,0xb3,0x1b
  9068. };
  9069. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  9070. {
  9071. 0x06,0x48,0x74,0x09,0x2f,0x7a,0x13,0xcc,
  9072. 0x44,0x62,0x24,0x7a,0xd4,0x23,0xd0,0xe9,
  9073. 0x6e,0xdf,0x42,0xe8,0xb6,0x7a,0x5a,0x23,
  9074. 0xb7,0xa0,0xa6,0x47,0x7b,0x09,0x8e,0x66
  9075. };
  9076. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  9077. {
  9078. 0x1c,0xff,0x95
  9079. };
  9080. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  9081. {
  9082. 0xb9,0x74,0xfa
  9083. };
  9084. #endif
  9085. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9086. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  9087. if (enc == NULL)
  9088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9089. #ifdef HAVE_AES_DECRYPT
  9090. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  9091. if (dec == NULL)
  9092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9093. #endif
  9094. #else
  9095. XMEMSET(enc, 0, sizeof(Aes));
  9096. #ifdef HAVE_AES_DECRYPT
  9097. XMEMSET(dec, 0, sizeof(Aes));
  9098. #endif
  9099. ret = wc_AesInit(enc, HEAP_HINT, devId);
  9100. if (ret != 0)
  9101. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9102. #ifdef HAVE_AES_DECRYPT
  9103. ret = wc_AesInit(dec, HEAP_HINT, devId);
  9104. if (ret != 0)
  9105. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9106. #endif
  9107. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  9108. #ifdef WOLFSSL_AES_128
  9109. /* 128 key tests */
  9110. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9111. ret = EVP_test(wolfSSL_EVP_aes_128_cfb8(), key1, iv, msg1, sizeof(msg1),
  9112. cipher1, sizeof(cipher1));
  9113. if (ret != 0) {
  9114. return ret;
  9115. }
  9116. #endif
  9117. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9118. if (ret != 0)
  9119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9120. #ifdef HAVE_AES_DECRYPT
  9121. /* decrypt uses AES_ENCRYPTION */
  9122. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9123. if (ret != 0)
  9124. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9125. #endif
  9126. XMEMSET(cipher, 0, sizeof(cipher));
  9127. ret = wc_AesCfb8Encrypt(enc, cipher, msg1, sizeof(msg1));
  9128. if (ret != 0)
  9129. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9130. if (XMEMCMP(cipher, cipher1, sizeof(cipher1)) != 0)
  9131. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9132. #ifdef HAVE_AES_DECRYPT
  9133. ret = wc_AesCfb8Decrypt(dec, plain, cipher, sizeof(msg1));
  9134. if (ret != 0)
  9135. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9136. if (XMEMCMP(plain, msg1, sizeof(msg1)) != 0)
  9137. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9138. #endif /* HAVE_AES_DECRYPT */
  9139. #endif /* WOLFSSL_AES_128 */
  9140. #ifdef WOLFSSL_AES_192
  9141. /* 192 key tests */
  9142. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  9143. if (ret != 0)
  9144. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9145. XMEMSET(cipher, 0, sizeof(cipher));
  9146. ret = wc_AesCfb8Encrypt(enc, cipher, msg2, sizeof(msg2));
  9147. if (ret != 0)
  9148. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9149. if (XMEMCMP(cipher, cipher2, sizeof(msg2)) != 0)
  9150. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9151. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9152. ret = EVP_test(wolfSSL_EVP_aes_192_cfb8(), key2, iv2, msg2, sizeof(msg2),
  9153. cipher2, sizeof(msg2));
  9154. if (ret != 0) {
  9155. return ret;
  9156. }
  9157. #endif
  9158. #endif /* WOLFSSL_AES_192 */
  9159. #ifdef WOLFSSL_AES_256
  9160. /* 256 key tests */
  9161. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  9162. if (ret != 0)
  9163. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9164. XMEMSET(cipher, 0, sizeof(cipher));
  9165. ret = wc_AesCfb8Encrypt(enc, cipher, msg3, sizeof(msg3));
  9166. if (ret != 0)
  9167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9168. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  9169. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9170. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9171. ret = EVP_test(wolfSSL_EVP_aes_256_cfb8(), key3, iv3, msg3, sizeof(msg3),
  9172. cipher3, sizeof(msg3));
  9173. if (ret != 0) {
  9174. goto out;
  9175. }
  9176. #endif
  9177. #endif /* WOLFSSL_AES_256 */
  9178. out:
  9179. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9180. wc_AesDelete(enc, &enc);
  9181. #else
  9182. wc_AesFree(enc);
  9183. #endif
  9184. #ifdef HAVE_AES_DECRYPT
  9185. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9186. wc_AesDelete(dec, &dec);
  9187. #else
  9188. wc_AesFree(dec);
  9189. #endif
  9190. #endif
  9191. return ret;
  9192. }
  9193. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  9194. #endif /* WOLFSSL_AES_CFB */
  9195. #ifndef HAVE_RENESAS_SYNC
  9196. static wc_test_ret_t aes_key_size_test(void)
  9197. {
  9198. wc_test_ret_t ret;
  9199. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9200. Aes *aes = NULL;
  9201. #else
  9202. Aes aes[1];
  9203. #endif
  9204. byte key16[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9205. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9206. #ifndef WOLFSSL_CRYPTOCELL
  9207. byte key24[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9208. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9209. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
  9210. #endif
  9211. byte key32[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9212. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9213. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9214. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9215. byte iv[] = "1234567890abcdef";
  9216. #ifndef HAVE_FIPS
  9217. word32 keySize;
  9218. #endif
  9219. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9220. aes = wc_AesNew(HEAP_HINT, devId, &ret);
  9221. if (aes == NULL)
  9222. return WC_TEST_RET_ENC_EC(ret);
  9223. #else
  9224. ret = wc_AesInit(aes, HEAP_HINT, devId);
  9225. /* 0 check OK for FIPSv1 */
  9226. if (ret != 0)
  9227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9228. #endif
  9229. #if !defined(HAVE_FIPS) || \
  9230. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  9231. /* w/ FIPS v1 (cert 2425) wc_AesInit just returns 0 always as it's not
  9232. * supported with that FIPS version */
  9233. ret = wc_AesInit(NULL, HEAP_HINT, devId);
  9234. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9236. #endif
  9237. #ifndef HAVE_FIPS
  9238. /* Parameter Validation testing. */
  9239. ret = wc_AesGetKeySize(NULL, NULL);
  9240. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9241. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9242. ret = wc_AesGetKeySize(aes, NULL);
  9243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9244. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9245. ret = wc_AesGetKeySize(NULL, &keySize);
  9246. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9247. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9248. /* Crashes in FIPS */
  9249. ret = wc_AesSetKey(NULL, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9250. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9252. #endif
  9253. /* NULL IV indicates to use all zeros IV. */
  9254. ret = wc_AesSetKey(aes, key16, sizeof(key16), NULL, AES_ENCRYPTION);
  9255. #ifdef WOLFSSL_AES_128
  9256. if (ret != 0)
  9257. #else
  9258. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9259. #endif
  9260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9261. ret = wc_AesSetKey(aes, key32, sizeof(key32) - 1, iv, AES_ENCRYPTION);
  9262. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9264. /* CryptoCell handles rounds internally */
  9265. #if !defined(HAVE_FIPS) && !defined(WOLFSSL_CRYPTOCELL)
  9266. /* PSA don't use aes->rounds */
  9267. #if !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_AES)
  9268. /* Force invalid rounds */
  9269. aes->rounds = 16;
  9270. ret = wc_AesGetKeySize(aes, &keySize);
  9271. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9273. #endif
  9274. #endif
  9275. ret = wc_AesSetKey(aes, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9276. #ifdef WOLFSSL_AES_128
  9277. if (ret != 0)
  9278. #else
  9279. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9280. #endif
  9281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9282. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128)
  9283. ret = wc_AesGetKeySize(aes, &keySize);
  9284. if (ret != 0 || keySize != sizeof(key16))
  9285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9286. #endif
  9287. #ifndef WOLFSSL_CRYPTOCELL
  9288. /* Cryptocell only supports AES-128 key size */
  9289. ret = wc_AesSetKey(aes, key24, sizeof(key24), iv, AES_ENCRYPTION);
  9290. #ifdef WOLFSSL_AES_192
  9291. if (ret != 0)
  9292. #else
  9293. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9294. #endif
  9295. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9296. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192)
  9297. ret = wc_AesGetKeySize(aes, &keySize);
  9298. if (ret != 0 || keySize != sizeof(key24))
  9299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9300. #endif
  9301. ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION);
  9302. #ifdef WOLFSSL_AES_256
  9303. if (ret != 0)
  9304. #else
  9305. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9306. #endif
  9307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9308. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256)
  9309. ret = wc_AesGetKeySize(aes, &keySize);
  9310. if (ret != 0 || keySize != sizeof(key32))
  9311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9312. #endif
  9313. #endif /* !WOLFSSL_CRYPTOCELL */
  9314. ret = 0; /* success */
  9315. out:
  9316. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9317. wc_AesDelete(aes, &aes);
  9318. #else
  9319. wc_AesFree(aes);
  9320. #endif
  9321. return ret;
  9322. }
  9323. #endif /* !HAVE_RENESAS_SYNC */
  9324. #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  9325. /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */
  9326. #ifdef WOLFSSL_AES_128
  9327. static wc_test_ret_t aes_xts_128_test(void)
  9328. {
  9329. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9330. XtsAes *aes = NULL;
  9331. #else
  9332. XtsAes aes[1];
  9333. #endif
  9334. int aes_inited = 0;
  9335. wc_test_ret_t ret = 0;
  9336. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9337. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9338. #ifdef WOLFSSL_AESXTS_STREAM
  9339. struct XtsAesStreamData stream;
  9340. #endif
  9341. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9342. !defined(WOLFSSL_AFALG)
  9343. #define LARGE_XTS_SZ 1024
  9344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9345. byte* large_input = NULL;
  9346. #else
  9347. byte large_input[LARGE_XTS_SZ];
  9348. #endif
  9349. #endif
  9350. /* 128 key tests */
  9351. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9352. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  9353. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  9354. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  9355. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  9356. };
  9357. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9358. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9359. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9360. };
  9361. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9362. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9363. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9364. };
  9365. /* plain text test of partial block is not from NIST test vector list */
  9366. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9367. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9368. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9369. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9370. };
  9371. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9372. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a,
  9373. 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63
  9374. };
  9375. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9376. 0x39, 0x25, 0x79, 0x05, 0xdf, 0xcc, 0x77, 0x76,
  9377. 0x6c, 0x87, 0x0a, 0x80, 0x6a, 0x60, 0xe3, 0xc0,
  9378. 0x93, 0xd1, 0x2a, 0xcf, 0xcb, 0x51, 0x42, 0xfa,
  9379. 0x09, 0x69, 0x89, 0x62, 0x5b, 0x60, 0xdb, 0x16
  9380. };
  9381. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9382. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9383. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9384. };
  9385. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9386. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9387. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9388. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9389. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9390. };
  9391. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9392. 0xd6, 0xbe, 0x04, 0x6d, 0x41, 0xf2, 0x3b, 0x5e,
  9393. 0xd7, 0x0b, 0x6b, 0x3d, 0x5c, 0x8e, 0x66, 0x23,
  9394. 0x2b, 0xe6, 0xb8, 0x07, 0xd4, 0xdc, 0xc6, 0x0e,
  9395. 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22
  9396. };
  9397. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9398. 0x2b, 0xf7, 0x2c, 0xf3, 0xeb, 0x85, 0xef, 0x7b,
  9399. 0x0b, 0x76, 0xa0, 0xaa, 0xf3, 0x3f, 0x25, 0x8b,
  9400. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
  9401. };
  9402. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9403. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9404. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9405. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9406. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9407. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9408. };
  9409. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9410. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9411. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9412. };
  9413. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9414. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9415. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9416. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9417. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9418. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9419. };
  9420. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9421. 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23,
  9422. 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12,
  9423. 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36,
  9424. 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF,
  9425. 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD
  9426. };
  9427. #endif /* HAVE_FIPS */
  9428. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9429. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9430. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9431. #endif
  9432. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  9433. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  9434. ret = EVP_test(wolfSSL_EVP_aes_128_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  9435. if (ret != 0) {
  9436. printf("EVP_aes_128_xts failed!\n");
  9437. goto out;
  9438. }
  9439. #endif
  9440. XMEMSET(buf, 0, sizeof(buf));
  9441. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9442. if (ret != 0)
  9443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9444. else
  9445. aes_inited = 1;
  9446. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9447. if (ret != 0)
  9448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9449. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  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. if (XMEMCMP(c2, buf, sizeof(c2)))
  9456. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9457. #ifdef WOLFSSL_AESXTS_STREAM
  9458. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9459. #if defined(WOLFSSL_ASYNC_CRYPT)
  9460. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9461. #endif
  9462. if (ret != 0)
  9463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9464. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  9465. #if defined(WOLFSSL_ASYNC_CRYPT)
  9466. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9467. #endif
  9468. if (ret != 0)
  9469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9470. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  9471. #if defined(WOLFSSL_ASYNC_CRYPT)
  9472. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9473. #endif
  9474. if (ret != 0)
  9475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9476. if (XMEMCMP(c2, buf, sizeof(c2)))
  9477. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9478. #endif /* WOLFSSL_AESXTS_STREAM */
  9479. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9480. defined(WC_C_DYNAMIC_FALLBACK)
  9481. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9482. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9483. #if defined(WOLFSSL_ASYNC_CRYPT)
  9484. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9485. #endif
  9486. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9487. if (ret != 0)
  9488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9489. if (XMEMCMP(c2, buf, sizeof(c2)))
  9490. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9491. #endif
  9492. XMEMSET(buf, 0, sizeof(buf));
  9493. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9494. if (ret != 0)
  9495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9496. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9497. #if defined(WOLFSSL_ASYNC_CRYPT)
  9498. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9499. #endif
  9500. if (ret != 0)
  9501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9502. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9503. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9504. #ifdef WOLFSSL_AESXTS_STREAM
  9505. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i2), &stream);
  9506. #if defined(WOLFSSL_ASYNC_CRYPT)
  9507. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9508. #endif
  9509. if (ret != 0)
  9510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9511. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9512. #if defined(WOLFSSL_ASYNC_CRYPT)
  9513. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9514. #endif
  9515. if (ret != 0)
  9516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9517. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9518. #if defined(WOLFSSL_ASYNC_CRYPT)
  9519. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9520. #endif
  9521. if (ret != 0)
  9522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9523. if (XMEMCMP(c1, buf, sizeof(c1)))
  9524. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9525. #endif /* WOLFSSL_AESXTS_STREAM */
  9526. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9527. defined(WC_C_DYNAMIC_FALLBACK)
  9528. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9529. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9530. #if defined(WOLFSSL_ASYNC_CRYPT)
  9531. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9532. #endif
  9533. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9534. if (ret != 0)
  9535. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9536. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9537. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9538. #endif
  9539. /* partial block encryption test */
  9540. XMEMSET(cipher, 0, sizeof(cipher));
  9541. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9542. #if defined(WOLFSSL_ASYNC_CRYPT)
  9543. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9544. #endif
  9545. if (ret != 0)
  9546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9547. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9548. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9549. #ifdef WOLFSSL_AESXTS_STREAM
  9550. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9551. #if defined(WOLFSSL_ASYNC_CRYPT)
  9552. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9553. #endif
  9554. if (ret != 0)
  9555. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9556. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  9557. #if defined(WOLFSSL_ASYNC_CRYPT)
  9558. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9559. #endif
  9560. if (ret != 0)
  9561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9562. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9563. #if defined(WOLFSSL_ASYNC_CRYPT)
  9564. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9565. #endif
  9566. if (ret != 0)
  9567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9568. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  9569. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9570. #endif /* WOLFSSL_AESXTS_STREAM */
  9571. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9572. defined(WC_C_DYNAMIC_FALLBACK)
  9573. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9574. XMEMSET(cipher, 0, sizeof(cipher));
  9575. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9576. #if defined(WOLFSSL_ASYNC_CRYPT)
  9577. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9578. #endif
  9579. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9580. if (ret != 0)
  9581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9582. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9583. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9584. #endif
  9585. /* partial block decrypt test */
  9586. XMEMSET(buf, 0, sizeof(buf));
  9587. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9588. if (ret != 0)
  9589. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9590. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9591. #if defined(WOLFSSL_ASYNC_CRYPT)
  9592. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9593. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9594. #else
  9595. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9596. #endif
  9597. #endif
  9598. if (ret != 0)
  9599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9600. if (XMEMCMP(pp, buf, sizeof(pp)))
  9601. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9602. #ifdef WOLFSSL_AESXTS_STREAM
  9603. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9604. #if defined(WOLFSSL_ASYNC_CRYPT)
  9605. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9606. #endif
  9607. if (ret != 0)
  9608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9609. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  9610. #if defined(WOLFSSL_ASYNC_CRYPT)
  9611. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9612. #endif
  9613. if (ret != 0)
  9614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9615. if (XMEMCMP(pp, buf, sizeof(pp)))
  9616. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9617. #endif /* WOLFSSL_AESXTS_STREAM */
  9618. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9619. defined(WC_C_DYNAMIC_FALLBACK)
  9620. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9621. XMEMSET(buf, 0, sizeof(buf));
  9622. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9623. #if defined(WOLFSSL_ASYNC_CRYPT)
  9624. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9625. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9626. #else
  9627. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9628. #endif
  9629. #endif
  9630. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9631. if (ret != 0)
  9632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9633. if (XMEMCMP(pp, buf, sizeof(pp)))
  9634. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9635. #endif
  9636. /* NIST decrypt test vector */
  9637. XMEMSET(buf, 0, sizeof(buf));
  9638. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9639. #if defined(WOLFSSL_ASYNC_CRYPT)
  9640. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9641. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9642. #else
  9643. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9644. #endif
  9645. #endif
  9646. if (ret != 0)
  9647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9648. if (XMEMCMP(p1, buf, sizeof(p1)))
  9649. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9650. #ifdef WOLFSSL_AESXTS_STREAM
  9651. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9652. #if defined(WOLFSSL_ASYNC_CRYPT)
  9653. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9654. #endif
  9655. if (ret != 0)
  9656. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9657. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  9658. #if defined(WOLFSSL_ASYNC_CRYPT)
  9659. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9660. #endif
  9661. if (ret != 0)
  9662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9663. if (XMEMCMP(p1, buf, sizeof(p1)))
  9664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9665. #endif /* WOLFSSL_AESXTS_STREAM */
  9666. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9667. defined(WC_C_DYNAMIC_FALLBACK)
  9668. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9669. XMEMSET(buf, 0, sizeof(buf));
  9670. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9671. #if defined(WOLFSSL_ASYNC_CRYPT)
  9672. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9673. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9674. #else
  9675. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9676. #endif
  9677. #endif
  9678. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9679. if (ret != 0)
  9680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9681. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  9682. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9683. #endif
  9684. /* fail case with decrypting using wrong key */
  9685. XMEMSET(buf, 0, sizeof(buf));
  9686. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9687. #if defined(WOLFSSL_ASYNC_CRYPT)
  9688. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9689. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9690. #else
  9691. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9692. #endif
  9693. #endif
  9694. if (ret != 0)
  9695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9696. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  9697. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9698. /* set correct key and retest */
  9699. XMEMSET(buf, 0, sizeof(buf));
  9700. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  9701. if (ret != 0)
  9702. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9703. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9704. #if defined(WOLFSSL_ASYNC_CRYPT)
  9705. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9706. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9707. #else
  9708. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9709. #endif
  9710. #endif
  9711. if (ret != 0)
  9712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9713. if (XMEMCMP(p2, buf, sizeof(p2)))
  9714. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9715. #ifndef HAVE_FIPS
  9716. /* Test ciphertext stealing in-place. */
  9717. XMEMCPY(buf, p3, sizeof(p3));
  9718. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  9719. if (ret != 0)
  9720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9721. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  9722. #if defined(WOLFSSL_ASYNC_CRYPT)
  9723. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9724. #endif
  9725. if (ret != 0)
  9726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9727. if (XMEMCMP(c3, buf, sizeof(c3)))
  9728. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9729. #ifdef WOLFSSL_AESXTS_STREAM
  9730. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  9731. #if defined(WOLFSSL_ASYNC_CRYPT)
  9732. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9733. #endif
  9734. if (ret != 0)
  9735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9736. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  9737. #if defined(WOLFSSL_ASYNC_CRYPT)
  9738. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9739. #endif
  9740. if (ret != 0)
  9741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9742. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  9743. #if defined(WOLFSSL_ASYNC_CRYPT)
  9744. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9745. #endif
  9746. if (ret != 0)
  9747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9748. if (XMEMCMP(c3, buf, sizeof(c3)))
  9749. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9750. #endif /* WOLFSSL_AESXTS_STREAM */
  9751. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  9752. if (ret != 0)
  9753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9754. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  9755. #if defined(WOLFSSL_ASYNC_CRYPT)
  9756. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9757. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9758. #else
  9759. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9760. #endif
  9761. #endif
  9762. if (ret != 0)
  9763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9764. if (XMEMCMP(p3, buf, sizeof(p3)))
  9765. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9766. #ifdef WOLFSSL_AESXTS_STREAM
  9767. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  9768. #if defined(WOLFSSL_ASYNC_CRYPT)
  9769. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9770. #endif
  9771. if (ret != 0)
  9772. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9773. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  9774. #if defined(WOLFSSL_ASYNC_CRYPT)
  9775. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9776. #endif
  9777. if (ret != 0)
  9778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9779. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  9780. #if defined(WOLFSSL_ASYNC_CRYPT)
  9781. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9782. #endif
  9783. if (ret != 0)
  9784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9785. if (XMEMCMP(p3, buf, sizeof(p3)))
  9786. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9787. #endif /* WOLFSSL_AESXTS_STREAM */
  9788. #endif /* !HAVE_FIPS */
  9789. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9790. !defined(WOLFSSL_AFALG)
  9791. {
  9792. int i;
  9793. int j;
  9794. #ifdef WOLFSSL_AESXTS_STREAM
  9795. int k;
  9796. #endif
  9797. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9798. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  9799. DYNAMIC_TYPE_TMP_BUFFER);
  9800. if (large_input == NULL)
  9801. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  9802. #endif
  9803. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9804. large_input[i] = (byte)i;
  9805. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9806. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9807. if (ret != 0)
  9808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9809. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9810. sizeof(i1));
  9811. #if defined(WOLFSSL_ASYNC_CRYPT)
  9812. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9813. #endif
  9814. if (ret != 0)
  9815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9816. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9817. if (ret != 0)
  9818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9819. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9820. sizeof(i1));
  9821. #if defined(WOLFSSL_ASYNC_CRYPT)
  9822. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9823. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9824. WC_ASYNC_FLAG_NONE);
  9825. #else
  9826. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9827. #endif
  9828. #endif
  9829. if (ret != 0)
  9830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9831. for (i = 0; i < j; i++) {
  9832. if (large_input[i] != (byte)i) {
  9833. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9834. }
  9835. }
  9836. }
  9837. #ifdef WOLFSSL_AESXTS_STREAM
  9838. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9839. large_input[i] = (byte)i;
  9840. /* first, encrypt block by block then decrypt with a one-shot call. */
  9841. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9842. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9843. if (ret != 0)
  9844. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9845. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9846. #if defined(WOLFSSL_ASYNC_CRYPT)
  9847. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9848. #endif
  9849. if (ret != 0)
  9850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9851. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9852. if ((j - k) < AES_BLOCK_SIZE*2)
  9853. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9854. else
  9855. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9856. #if defined(WOLFSSL_ASYNC_CRYPT)
  9857. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9858. #endif
  9859. if (ret != 0)
  9860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9861. if ((j - k) < AES_BLOCK_SIZE*2)
  9862. break;
  9863. }
  9864. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9865. if (ret != 0)
  9866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9867. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9868. sizeof(i1));
  9869. #if defined(WOLFSSL_ASYNC_CRYPT)
  9870. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9871. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9872. WC_ASYNC_FLAG_NONE);
  9873. #else
  9874. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9875. #endif
  9876. #endif
  9877. if (ret != 0)
  9878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9879. for (i = 0; i < j; i++) {
  9880. if (large_input[i] != (byte)i) {
  9881. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9882. }
  9883. }
  9884. }
  9885. /* second, encrypt with a one-shot call then decrypt block by block. */
  9886. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9887. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9888. if (ret != 0)
  9889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9890. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9891. sizeof(i1));
  9892. #if defined(WOLFSSL_ASYNC_CRYPT)
  9893. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9894. #endif
  9895. if (ret != 0)
  9896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9897. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9898. if (ret != 0)
  9899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9900. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9901. #if defined(WOLFSSL_ASYNC_CRYPT)
  9902. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9903. #endif
  9904. if (ret != 0)
  9905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9906. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9907. if ((j - k) < AES_BLOCK_SIZE*2)
  9908. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9909. else
  9910. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9911. #if defined(WOLFSSL_ASYNC_CRYPT)
  9912. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9913. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9914. WC_ASYNC_FLAG_NONE);
  9915. #else
  9916. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9917. #endif
  9918. #endif
  9919. if (ret != 0)
  9920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9921. if ((j - k) < AES_BLOCK_SIZE*2)
  9922. break;
  9923. }
  9924. for (i = 0; i < j; i++) {
  9925. if (large_input[i] != (byte)i) {
  9926. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9927. }
  9928. }
  9929. }
  9930. #endif /* WOLFSSL_AESXTS_STREAM */
  9931. }
  9932. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  9933. * !WOLFSSL_AFALG
  9934. */
  9935. out:
  9936. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9937. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  9938. !defined(WOLFSSL_NO_MALLOC)
  9939. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9940. #endif
  9941. if (aes_inited)
  9942. wc_AesXtsFree(aes);
  9943. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9944. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9945. #endif
  9946. return ret;
  9947. }
  9948. #endif /* WOLFSSL_AES_128 */
  9949. #ifdef WOLFSSL_AES_192
  9950. static wc_test_ret_t aes_xts_192_test(void)
  9951. {
  9952. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9953. XtsAes *aes = NULL;
  9954. #else
  9955. XtsAes aes[1];
  9956. #endif
  9957. int aes_inited = 0;
  9958. wc_test_ret_t ret = 0;
  9959. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9960. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9961. #ifdef WOLFSSL_AESXTS_STREAM
  9962. struct XtsAesStreamData stream;
  9963. #endif
  9964. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9965. !defined(WOLFSSL_AFALG)
  9966. #define LARGE_XTS_SZ 1024
  9967. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9968. byte* large_input = NULL;
  9969. #else
  9970. byte large_input[LARGE_XTS_SZ];
  9971. #endif
  9972. #endif
  9973. /* 192 bit key tests */
  9974. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9975. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  9976. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  9977. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  9978. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  9979. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  9980. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3
  9981. };
  9982. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9983. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9984. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9985. };
  9986. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9987. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9988. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9989. };
  9990. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9991. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9992. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9993. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9994. };
  9995. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9996. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4,
  9997. 0xdb, 0x4e, 0xd3, 0x69, 0xdf, 0x8e, 0x3a, 0xe0
  9998. };
  9999. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10000. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10001. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10002. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10003. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10004. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10005. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a
  10006. };
  10007. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10008. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  10009. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  10010. };
  10011. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10012. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  10013. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  10014. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  10015. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  10016. };
  10017. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10018. 0x6c, 0xa6, 0xb5, 0x73, 0x48, 0xf1, 0x89, 0xfa,
  10019. 0xdd, 0x80, 0x72, 0x1f, 0xb8, 0x56, 0x0c, 0xa2,
  10020. 0x35, 0xd4, 0x08, 0xbf, 0x24, 0xcb, 0xec, 0xdb,
  10021. 0x81, 0xe0, 0xe6, 0x4f, 0x3d, 0x1c, 0x5c, 0x46
  10022. };
  10023. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  10024. 0xe9, 0x58, 0xfe, 0xab, 0x66, 0xb4, 0xf1, 0x79,
  10025. 0x91, 0x3f, 0x91, 0xdc, 0x6f, 0xdf, 0xd6, 0xac,
  10026. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4
  10027. };
  10028. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  10029. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  10030. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10031. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10032. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10033. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10034. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10035. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10036. };
  10037. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  10038. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10039. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10040. };
  10041. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  10042. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10043. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10044. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10045. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10046. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10047. };
  10048. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  10049. 0xa4, 0xf2, 0x71, 0x5d, 0x80, 0x60, 0x68, 0xa0,
  10050. 0x80, 0x61, 0xd7, 0xc1, 0x55, 0xc8, 0x3a, 0x2e,
  10051. 0xd7, 0xf4, 0x62, 0xaf, 0xbd, 0x2d, 0xf9, 0x5f,
  10052. 0xe8, 0xc5, 0x99, 0x3d, 0x58, 0x3c, 0xeb, 0xba,
  10053. 0x86, 0xea, 0x2c, 0x7e, 0x1f, 0xba, 0x81, 0xde
  10054. };
  10055. #endif /* HAVE_FIPS */
  10056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10057. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10058. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10059. #endif
  10060. XMEMSET(buf, 0, sizeof(buf));
  10061. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10062. if (ret != 0)
  10063. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10064. else
  10065. aes_inited = 1;
  10066. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10067. if (ret != 0)
  10068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10069. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  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. if (XMEMCMP(c2, buf, sizeof(c2)))
  10076. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10077. #ifdef WOLFSSL_AESXTS_STREAM
  10078. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10079. #if defined(WOLFSSL_ASYNC_CRYPT)
  10080. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10081. #endif
  10082. if (ret != 0)
  10083. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10084. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10085. #if defined(WOLFSSL_ASYNC_CRYPT)
  10086. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10087. #endif
  10088. if (ret != 0)
  10089. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10090. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10091. #if defined(WOLFSSL_ASYNC_CRYPT)
  10092. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10093. #endif
  10094. if (ret != 0)
  10095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10096. if (XMEMCMP(c2, buf, sizeof(c2)))
  10097. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10098. #endif /* WOLFSSL_AESXTS_STREAM */
  10099. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10100. defined(WC_C_DYNAMIC_FALLBACK)
  10101. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10102. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10103. #if defined(WOLFSSL_ASYNC_CRYPT)
  10104. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10105. #endif
  10106. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10107. if (ret != 0)
  10108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10109. if (XMEMCMP(c2, buf, sizeof(c2)))
  10110. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10111. #endif
  10112. XMEMSET(buf, 0, sizeof(buf));
  10113. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10114. if (ret != 0)
  10115. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10116. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10117. #if defined(WOLFSSL_ASYNC_CRYPT)
  10118. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10119. #endif
  10120. if (ret != 0)
  10121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10122. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10123. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10124. #ifdef WOLFSSL_AESXTS_STREAM
  10125. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10126. #if defined(WOLFSSL_ASYNC_CRYPT)
  10127. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10128. #endif
  10129. if (ret != 0)
  10130. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10131. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10132. #if defined(WOLFSSL_ASYNC_CRYPT)
  10133. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10134. #endif
  10135. if (ret != 0)
  10136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10137. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10138. #if defined(WOLFSSL_ASYNC_CRYPT)
  10139. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10140. #endif
  10141. if (ret != 0)
  10142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10143. if (XMEMCMP(c1, buf, sizeof(c1)))
  10144. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10145. #endif /* WOLFSSL_AESXTS_STREAM */
  10146. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10147. defined(WC_C_DYNAMIC_FALLBACK)
  10148. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10149. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10150. #if defined(WOLFSSL_ASYNC_CRYPT)
  10151. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10152. #endif
  10153. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10154. if (ret != 0)
  10155. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10156. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10157. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10158. #endif
  10159. /* partial block encryption test */
  10160. XMEMSET(cipher, 0, sizeof(cipher));
  10161. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10162. #if defined(WOLFSSL_ASYNC_CRYPT)
  10163. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10164. #endif
  10165. if (ret != 0)
  10166. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10167. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10168. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10169. #ifdef WOLFSSL_AESXTS_STREAM
  10170. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10171. #if defined(WOLFSSL_ASYNC_CRYPT)
  10172. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10173. #endif
  10174. if (ret != 0)
  10175. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10176. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  10177. #if defined(WOLFSSL_ASYNC_CRYPT)
  10178. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10179. #endif
  10180. if (ret != 0)
  10181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10182. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10183. #if defined(WOLFSSL_ASYNC_CRYPT)
  10184. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10185. #endif
  10186. if (ret != 0)
  10187. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10188. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  10189. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10190. #endif /* WOLFSSL_AESXTS_STREAM */
  10191. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10192. defined(WC_C_DYNAMIC_FALLBACK)
  10193. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10194. XMEMSET(cipher, 0, sizeof(cipher));
  10195. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10196. #if defined(WOLFSSL_ASYNC_CRYPT)
  10197. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10198. #endif
  10199. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10200. if (ret != 0)
  10201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10202. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10203. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10204. #endif
  10205. /* partial block decrypt test */
  10206. XMEMSET(buf, 0, sizeof(buf));
  10207. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10208. if (ret != 0)
  10209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10210. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10211. #if defined(WOLFSSL_ASYNC_CRYPT)
  10212. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10213. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10214. #else
  10215. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10216. #endif
  10217. #endif
  10218. if (ret != 0)
  10219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10220. if (XMEMCMP(pp, buf, sizeof(pp)))
  10221. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10222. #ifdef WOLFSSL_AESXTS_STREAM
  10223. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10224. #if defined(WOLFSSL_ASYNC_CRYPT)
  10225. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10226. #endif
  10227. if (ret != 0)
  10228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10229. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  10230. #if defined(WOLFSSL_ASYNC_CRYPT)
  10231. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10232. #endif
  10233. if (ret != 0)
  10234. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10235. if (XMEMCMP(pp, buf, sizeof(pp)))
  10236. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10237. #endif /* WOLFSSL_AESXTS_STREAM */
  10238. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10239. defined(WC_C_DYNAMIC_FALLBACK)
  10240. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10241. XMEMSET(buf, 0, sizeof(buf));
  10242. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10243. #if defined(WOLFSSL_ASYNC_CRYPT)
  10244. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10245. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10246. #else
  10247. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10248. #endif
  10249. #endif
  10250. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10251. if (ret != 0)
  10252. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10253. if (XMEMCMP(pp, buf, sizeof(pp)))
  10254. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10255. #endif
  10256. /* NIST decrypt test vector */
  10257. XMEMSET(buf, 0, sizeof(buf));
  10258. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10259. #if defined(WOLFSSL_ASYNC_CRYPT)
  10260. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10261. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10262. #else
  10263. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10264. #endif
  10265. #endif
  10266. if (ret != 0)
  10267. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10268. if (XMEMCMP(p1, buf, sizeof(p1)))
  10269. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10270. #ifdef WOLFSSL_AESXTS_STREAM
  10271. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10272. #if defined(WOLFSSL_ASYNC_CRYPT)
  10273. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10274. #endif
  10275. if (ret != 0)
  10276. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10277. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10278. #if defined(WOLFSSL_ASYNC_CRYPT)
  10279. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10280. #endif
  10281. if (ret != 0)
  10282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10283. if (XMEMCMP(p1, buf, sizeof(p1)))
  10284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10285. #endif /* WOLFSSL_AESXTS_STREAM */
  10286. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10287. defined(WC_C_DYNAMIC_FALLBACK)
  10288. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10289. XMEMSET(buf, 0, sizeof(buf));
  10290. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10291. #if defined(WOLFSSL_ASYNC_CRYPT)
  10292. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10293. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10294. #else
  10295. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10296. #endif
  10297. #endif
  10298. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10299. if (ret != 0)
  10300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10301. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  10302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10303. #endif
  10304. /* fail case with decrypting using wrong key */
  10305. XMEMSET(buf, 0, sizeof(buf));
  10306. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10307. #if defined(WOLFSSL_ASYNC_CRYPT)
  10308. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10309. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10310. #else
  10311. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10312. #endif
  10313. #endif
  10314. if (ret != 0)
  10315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10316. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  10317. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10318. /* set correct key and retest */
  10319. XMEMSET(buf, 0, sizeof(buf));
  10320. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10321. if (ret != 0)
  10322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10323. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10324. #if defined(WOLFSSL_ASYNC_CRYPT)
  10325. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10326. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10327. #else
  10328. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10329. #endif
  10330. #endif
  10331. if (ret != 0)
  10332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10333. if (XMEMCMP(p2, buf, sizeof(p2)))
  10334. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10335. #ifndef HAVE_FIPS
  10336. /* Test ciphertext stealing in-place. */
  10337. XMEMCPY(buf, p3, sizeof(p3));
  10338. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  10339. if (ret != 0)
  10340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10341. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  10342. #if defined(WOLFSSL_ASYNC_CRYPT)
  10343. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10344. #endif
  10345. if (ret != 0)
  10346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10347. if (XMEMCMP(c3, buf, sizeof(c3)))
  10348. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10349. #ifdef WOLFSSL_AESXTS_STREAM
  10350. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  10351. #if defined(WOLFSSL_ASYNC_CRYPT)
  10352. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10353. #endif
  10354. if (ret != 0)
  10355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10356. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  10357. #if defined(WOLFSSL_ASYNC_CRYPT)
  10358. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10359. #endif
  10360. if (ret != 0)
  10361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10362. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  10363. #if defined(WOLFSSL_ASYNC_CRYPT)
  10364. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10365. #endif
  10366. if (ret != 0)
  10367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10368. if (XMEMCMP(c3, buf, sizeof(c3)))
  10369. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10370. #endif /* WOLFSSL_AESXTS_STREAM */
  10371. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  10372. if (ret != 0)
  10373. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10374. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  10375. #if defined(WOLFSSL_ASYNC_CRYPT)
  10376. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10377. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10378. #else
  10379. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10380. #endif
  10381. #endif
  10382. if (ret != 0)
  10383. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10384. if (XMEMCMP(p3, buf, sizeof(p3)))
  10385. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10386. #ifdef WOLFSSL_AESXTS_STREAM
  10387. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  10388. #if defined(WOLFSSL_ASYNC_CRYPT)
  10389. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10390. #endif
  10391. if (ret != 0)
  10392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10393. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  10394. #if defined(WOLFSSL_ASYNC_CRYPT)
  10395. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10396. #endif
  10397. if (ret != 0)
  10398. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10399. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  10400. #if defined(WOLFSSL_ASYNC_CRYPT)
  10401. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10402. #endif
  10403. if (ret != 0)
  10404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10405. if (XMEMCMP(p3, buf, sizeof(p3)))
  10406. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10407. #endif /* WOLFSSL_AESXTS_STREAM */
  10408. #endif /* !HAVE_FIPS */
  10409. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10410. !defined(WOLFSSL_AFALG)
  10411. {
  10412. int i;
  10413. int j;
  10414. #ifdef WOLFSSL_AESXTS_STREAM
  10415. int k;
  10416. #endif
  10417. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10418. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10419. DYNAMIC_TYPE_TMP_BUFFER);
  10420. if (large_input == NULL)
  10421. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10422. #endif
  10423. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10424. large_input[i] = (byte)i;
  10425. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10426. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10427. if (ret != 0)
  10428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10429. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10430. sizeof(i1));
  10431. #if defined(WOLFSSL_ASYNC_CRYPT)
  10432. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10433. #endif
  10434. if (ret != 0)
  10435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10436. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10437. if (ret != 0)
  10438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10439. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10440. sizeof(i1));
  10441. #if defined(WOLFSSL_ASYNC_CRYPT)
  10442. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10443. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10444. WC_ASYNC_FLAG_NONE);
  10445. #else
  10446. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10447. #endif
  10448. #endif
  10449. if (ret != 0)
  10450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10451. for (i = 0; i < j; i++) {
  10452. if (large_input[i] != (byte)i) {
  10453. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10454. }
  10455. }
  10456. }
  10457. #ifdef WOLFSSL_AESXTS_STREAM
  10458. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10459. large_input[i] = (byte)i;
  10460. /* first, encrypt block by block then decrypt with a one-shot call. */
  10461. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10462. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10463. if (ret != 0)
  10464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10465. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10466. #if defined(WOLFSSL_ASYNC_CRYPT)
  10467. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10468. #endif
  10469. if (ret != 0)
  10470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10471. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10472. if ((j - k) < AES_BLOCK_SIZE*2)
  10473. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10474. else
  10475. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10476. #if defined(WOLFSSL_ASYNC_CRYPT)
  10477. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10478. #endif
  10479. if (ret != 0)
  10480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10481. if ((j - k) < AES_BLOCK_SIZE*2)
  10482. break;
  10483. }
  10484. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10485. if (ret != 0)
  10486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10487. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10488. sizeof(i1));
  10489. #if defined(WOLFSSL_ASYNC_CRYPT)
  10490. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10491. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10492. WC_ASYNC_FLAG_NONE);
  10493. #else
  10494. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10495. #endif
  10496. #endif
  10497. if (ret != 0)
  10498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10499. for (i = 0; i < j; i++) {
  10500. if (large_input[i] != (byte)i) {
  10501. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10502. }
  10503. }
  10504. }
  10505. /* second, encrypt with a one-shot call then decrypt block by block. */
  10506. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10507. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10508. if (ret != 0)
  10509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10510. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10511. sizeof(i1));
  10512. #if defined(WOLFSSL_ASYNC_CRYPT)
  10513. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10514. #endif
  10515. if (ret != 0)
  10516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10517. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10518. if (ret != 0)
  10519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10520. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10521. #if defined(WOLFSSL_ASYNC_CRYPT)
  10522. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10523. #endif
  10524. if (ret != 0)
  10525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10526. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10527. if ((j - k) < AES_BLOCK_SIZE*2)
  10528. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10529. else
  10530. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10531. #if defined(WOLFSSL_ASYNC_CRYPT)
  10532. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10533. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10534. WC_ASYNC_FLAG_NONE);
  10535. #else
  10536. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10537. #endif
  10538. #endif
  10539. if (ret != 0)
  10540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10541. if ((j - k) < AES_BLOCK_SIZE*2)
  10542. break;
  10543. }
  10544. for (i = 0; i < j; i++) {
  10545. if (large_input[i] != (byte)i) {
  10546. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10547. }
  10548. }
  10549. }
  10550. #endif /* WOLFSSL_AESXTS_STREAM */
  10551. }
  10552. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10553. * !WOLFSSL_AFALG
  10554. */
  10555. out:
  10556. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10557. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10558. !defined(WOLFSSL_NO_MALLOC)
  10559. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10560. #endif
  10561. if (aes_inited)
  10562. wc_AesXtsFree(aes);
  10563. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10564. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10565. #endif
  10566. return ret;
  10567. }
  10568. #endif /* WOLFSSL_AES_192 */
  10569. #ifdef WOLFSSL_AES_256
  10570. static wc_test_ret_t aes_xts_256_test(void)
  10571. {
  10572. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10573. XtsAes *aes = NULL;
  10574. #else
  10575. XtsAes aes[1];
  10576. #endif
  10577. int aes_inited = 0;
  10578. wc_test_ret_t ret = 0;
  10579. unsigned char buf[AES_BLOCK_SIZE * 3];
  10580. unsigned char cipher[AES_BLOCK_SIZE * 3];
  10581. #ifdef WOLFSSL_AESXTS_STREAM
  10582. struct XtsAesStreamData stream;
  10583. #endif
  10584. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10585. !defined(WOLFSSL_AFALG)
  10586. #define LARGE_XTS_SZ 1024
  10587. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10588. byte* large_input = NULL;
  10589. #else
  10590. byte large_input[LARGE_XTS_SZ];
  10591. #endif
  10592. #endif
  10593. /* 256 key tests */
  10594. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10595. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  10596. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  10597. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  10598. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  10599. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  10600. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3,
  10601. 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58,
  10602. 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08
  10603. };
  10604. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  10605. 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2,
  10606. 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64
  10607. };
  10608. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10609. 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1,
  10610. 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64,
  10611. 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3,
  10612. 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e
  10613. };
  10614. /* plain text test of partial block is not from NIST test vector list */
  10615. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  10616. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  10617. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  10618. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  10619. };
  10620. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10621. 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5,
  10622. 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13,
  10623. 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a,
  10624. 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb
  10625. };
  10626. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10627. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10628. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10629. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10630. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10631. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10632. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a,
  10633. 0xb5, 0xb0, 0xc7, 0xe5, 0x2d, 0xb5, 0x06, 0x12,
  10634. 0xd2, 0xb5, 0x3a, 0xcb, 0x47, 0x8a, 0x53, 0xb4
  10635. };
  10636. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10637. 0xe6, 0x42, 0x19, 0xed, 0xe0, 0xe1, 0xc2, 0xa0,
  10638. 0x0e, 0xf5, 0x58, 0x6a, 0xc4, 0x9b, 0xeb, 0x6f
  10639. };
  10640. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10641. 0x24, 0xcb, 0x76, 0x22, 0x55, 0xb5, 0xa8, 0x00,
  10642. 0xf4, 0x6e, 0x80, 0x60, 0x56, 0x9e, 0x05, 0x53,
  10643. 0xbc, 0xfe, 0x86, 0x55, 0x3b, 0xca, 0xd5, 0x89,
  10644. 0xc7, 0x54, 0x1a, 0x73, 0xac, 0xc3, 0x9a, 0xbd,
  10645. 0x53, 0xc4, 0x07, 0x76, 0xd8, 0xe8, 0x22, 0x61,
  10646. 0x9e, 0xa9, 0xad, 0x77, 0xa0, 0x13, 0x4c, 0xfc
  10647. };
  10648. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10649. 0xa3, 0xc6, 0xf3, 0xf3, 0x82, 0x79, 0x5b, 0x10,
  10650. 0x87, 0xd7, 0x02, 0x50, 0xdb, 0x2c, 0xd3, 0xb1,
  10651. 0xa1, 0x62, 0xa8, 0xb6, 0xdc, 0x12, 0x60, 0x61,
  10652. 0xc1, 0x0a, 0x84, 0xa5, 0x85, 0x3f, 0x3a, 0x89,
  10653. 0xe6, 0x6c, 0xdb, 0xb7, 0x9a, 0xb4, 0x28, 0x9b,
  10654. 0xc3, 0xea, 0xd8, 0x10, 0xe9, 0xc0, 0xaf, 0x92
  10655. };
  10656. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10657. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10658. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10659. #endif
  10660. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  10661. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  10662. ret = EVP_test(wolfSSL_EVP_aes_256_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  10663. if (ret != 0) {
  10664. printf("EVP_aes_256_xts failed\n");
  10665. goto out;
  10666. }
  10667. #endif
  10668. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10669. if (ret != 0)
  10670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10671. else
  10672. aes_inited = 1;
  10673. XMEMSET(buf, 0, sizeof(buf));
  10674. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10675. if (ret != 0)
  10676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10677. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10678. #if defined(WOLFSSL_ASYNC_CRYPT)
  10679. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10680. #endif
  10681. if (ret != 0)
  10682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10683. if (XMEMCMP(c2, buf, sizeof(c2)))
  10684. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10685. #ifdef WOLFSSL_AESXTS_STREAM
  10686. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10687. #if defined(WOLFSSL_ASYNC_CRYPT)
  10688. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10689. #endif
  10690. if (ret != 0)
  10691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10692. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10693. #if defined(WOLFSSL_ASYNC_CRYPT)
  10694. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10695. #endif
  10696. if (ret != 0)
  10697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10698. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10699. #if defined(WOLFSSL_ASYNC_CRYPT)
  10700. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10701. #endif
  10702. if (ret != 0)
  10703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10704. if (XMEMCMP(c2, buf, sizeof(c2)))
  10705. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10706. #endif /* WOLFSSL_AESXTS_STREAM */
  10707. XMEMSET(buf, 0, sizeof(buf));
  10708. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10709. if (ret != 0)
  10710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10711. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10712. #if defined(WOLFSSL_ASYNC_CRYPT)
  10713. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10714. #endif
  10715. if (ret != 0)
  10716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10717. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10718. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10719. #ifdef WOLFSSL_AESXTS_STREAM
  10720. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10721. #if defined(WOLFSSL_ASYNC_CRYPT)
  10722. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10723. #endif
  10724. if (ret != 0)
  10725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10726. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10727. #if defined(WOLFSSL_ASYNC_CRYPT)
  10728. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10729. #endif
  10730. if (ret != 0)
  10731. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10732. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10733. #if defined(WOLFSSL_ASYNC_CRYPT)
  10734. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10735. #endif
  10736. if (ret != 0)
  10737. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10738. if (XMEMCMP(c1, buf, sizeof(c1)))
  10739. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10740. #endif /* WOLFSSL_AESXTS_STREAM */
  10741. /* partial block encryption test */
  10742. XMEMSET(cipher, 0, sizeof(cipher));
  10743. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10744. #if defined(WOLFSSL_ASYNC_CRYPT)
  10745. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10746. #endif
  10747. if (ret != 0)
  10748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10749. /* partial block decrypt test */
  10750. XMEMSET(buf, 0, sizeof(buf));
  10751. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10752. if (ret != 0)
  10753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10754. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10755. #if defined(WOLFSSL_ASYNC_CRYPT)
  10756. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10757. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10758. #else
  10759. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10760. #endif
  10761. #endif
  10762. if (ret != 0)
  10763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10764. if (XMEMCMP(pp, buf, sizeof(pp)))
  10765. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10766. /* NIST decrypt test vector */
  10767. XMEMSET(buf, 0, sizeof(buf));
  10768. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10769. #if defined(WOLFSSL_ASYNC_CRYPT)
  10770. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10771. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10772. #else
  10773. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10774. #endif
  10775. #endif
  10776. if (ret != 0)
  10777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10778. if (XMEMCMP(p1, buf, sizeof(p1)))
  10779. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10780. #ifdef WOLFSSL_AESXTS_STREAM
  10781. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10782. #if defined(WOLFSSL_ASYNC_CRYPT)
  10783. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10784. #endif
  10785. if (ret != 0)
  10786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10787. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10788. #if defined(WOLFSSL_ASYNC_CRYPT)
  10789. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10790. #endif
  10791. if (ret != 0)
  10792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10793. if (XMEMCMP(p1, buf, sizeof(p1)))
  10794. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10795. #endif /* WOLFSSL_AESXTS_STREAM */
  10796. XMEMSET(buf, 0, sizeof(buf));
  10797. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10798. if (ret != 0)
  10799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10800. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10801. #if defined(WOLFSSL_ASYNC_CRYPT)
  10802. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10803. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10804. #else
  10805. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10806. #endif
  10807. #endif
  10808. if (ret != 0)
  10809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10810. if (XMEMCMP(p2, buf, sizeof(p2)))
  10811. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10812. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10813. !defined(WOLFSSL_AFALG)
  10814. {
  10815. int i;
  10816. int j;
  10817. #ifdef WOLFSSL_AESXTS_STREAM
  10818. int k;
  10819. #endif
  10820. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10821. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10822. DYNAMIC_TYPE_TMP_BUFFER);
  10823. if (large_input == NULL)
  10824. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10825. #endif
  10826. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10827. large_input[i] = (byte)i;
  10828. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10829. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10830. if (ret != 0)
  10831. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10832. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10833. sizeof(i1));
  10834. #if defined(WOLFSSL_ASYNC_CRYPT)
  10835. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10836. #endif
  10837. if (ret != 0)
  10838. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10839. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10840. if (ret != 0)
  10841. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10842. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10843. sizeof(i1));
  10844. #if defined(WOLFSSL_ASYNC_CRYPT)
  10845. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10846. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10847. WC_ASYNC_FLAG_NONE);
  10848. #else
  10849. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10850. #endif
  10851. #endif
  10852. if (ret != 0)
  10853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10854. for (i = 0; i < j; i++) {
  10855. if (large_input[i] != (byte)i) {
  10856. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10857. }
  10858. }
  10859. }
  10860. #ifdef WOLFSSL_AESXTS_STREAM
  10861. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10862. large_input[i] = (byte)i;
  10863. /* first, encrypt block by block then decrypt with a one-shot call. */
  10864. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10865. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10866. if (ret != 0)
  10867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10868. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10869. #if defined(WOLFSSL_ASYNC_CRYPT)
  10870. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10871. #endif
  10872. if (ret != 0)
  10873. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10874. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10875. if ((j - k) < AES_BLOCK_SIZE*2)
  10876. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10877. else
  10878. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10879. #if defined(WOLFSSL_ASYNC_CRYPT)
  10880. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10881. #endif
  10882. if (ret != 0)
  10883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10884. if ((j - k) < AES_BLOCK_SIZE*2)
  10885. break;
  10886. }
  10887. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10888. if (ret != 0)
  10889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10890. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10891. sizeof(i1));
  10892. #if defined(WOLFSSL_ASYNC_CRYPT)
  10893. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10894. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10895. WC_ASYNC_FLAG_NONE);
  10896. #else
  10897. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10898. #endif
  10899. #endif
  10900. if (ret != 0)
  10901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10902. for (i = 0; i < j; i++) {
  10903. if (large_input[i] != (byte)i) {
  10904. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10905. }
  10906. }
  10907. }
  10908. /* second, encrypt with a one-shot call then decrypt block by block. */
  10909. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10910. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10911. if (ret != 0)
  10912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10913. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10914. sizeof(i1));
  10915. #if defined(WOLFSSL_ASYNC_CRYPT)
  10916. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10917. #endif
  10918. if (ret != 0)
  10919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10920. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10921. if (ret != 0)
  10922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10923. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10924. #if defined(WOLFSSL_ASYNC_CRYPT)
  10925. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10926. #endif
  10927. if (ret != 0)
  10928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10929. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10930. if ((j - k) < AES_BLOCK_SIZE*2)
  10931. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10932. else
  10933. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10934. #if defined(WOLFSSL_ASYNC_CRYPT)
  10935. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10936. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10937. WC_ASYNC_FLAG_NONE);
  10938. #else
  10939. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10940. #endif
  10941. #endif
  10942. if (ret != 0)
  10943. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10944. if ((j - k) < AES_BLOCK_SIZE*2)
  10945. break;
  10946. }
  10947. for (i = 0; i < j; i++) {
  10948. if (large_input[i] != (byte)i) {
  10949. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10950. }
  10951. }
  10952. }
  10953. #endif /* WOLFSSL_AESXTS_STREAM */
  10954. }
  10955. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10956. * !WOLFSSL_AFALG
  10957. */
  10958. out:
  10959. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10960. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10961. !defined(WOLFSSL_NO_MALLOC)
  10962. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10963. #endif
  10964. if (aes_inited)
  10965. wc_AesXtsFree(aes);
  10966. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10967. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10968. #endif
  10969. return ret;
  10970. }
  10971. #endif /* WOLFSSL_AES_256 */
  10972. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  10973. /* both 128 and 256 bit key test */
  10974. static wc_test_ret_t aes_xts_sector_test(void)
  10975. {
  10976. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10977. XtsAes *aes = NULL;
  10978. #else
  10979. XtsAes aes[1];
  10980. #endif
  10981. int aes_inited = 0;
  10982. wc_test_ret_t ret = 0;
  10983. unsigned char buf[AES_BLOCK_SIZE * 2];
  10984. /* 128 key tests */
  10985. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10986. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  10987. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  10988. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  10989. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  10990. };
  10991. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10992. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  10993. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  10994. };
  10995. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10996. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  10997. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  10998. };
  10999. word64 s1 = 141;
  11000. /* 256 key tests */
  11001. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  11002. 0xef, 0x01, 0x0c, 0xa1, 0xa3, 0x66, 0x3e, 0x32,
  11003. 0x53, 0x43, 0x49, 0xbc, 0x0b, 0xae, 0x62, 0x23,
  11004. 0x2a, 0x15, 0x73, 0x34, 0x85, 0x68, 0xfb, 0x9e,
  11005. 0xf4, 0x17, 0x68, 0xa7, 0x67, 0x4f, 0x50, 0x7a,
  11006. 0x72, 0x7f, 0x98, 0x75, 0x53, 0x97, 0xd0, 0xe0,
  11007. 0xaa, 0x32, 0xf8, 0x30, 0x33, 0x8c, 0xc7, 0xa9,
  11008. 0x26, 0xc7, 0x73, 0xf0, 0x9e, 0x57, 0xb3, 0x57,
  11009. 0xcd, 0x15, 0x6a, 0xfb, 0xca, 0x46, 0xe1, 0xa0
  11010. };
  11011. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  11012. 0xed, 0x98, 0xe0, 0x17, 0x70, 0xa8, 0x53, 0xb4,
  11013. 0x9d, 0xb9, 0xe6, 0xaa, 0xf8, 0x8f, 0x0a, 0x41,
  11014. 0xb9, 0xb5, 0x6e, 0x91, 0xa5, 0xa2, 0xb1, 0x1d,
  11015. 0x40, 0x52, 0x92, 0x54, 0xf5, 0x52, 0x3e, 0x75
  11016. };
  11017. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  11018. 0xca, 0x20, 0xc5, 0x5e, 0x8d, 0xc1, 0x49, 0x68,
  11019. 0x7d, 0x25, 0x41, 0xde, 0x39, 0xc3, 0xdf, 0x63,
  11020. 0x00, 0xbb, 0x5a, 0x16, 0x3c, 0x10, 0xce, 0xd3,
  11021. 0x66, 0x6b, 0x13, 0x57, 0xdb, 0x8b, 0xd3, 0x9d
  11022. };
  11023. word64 s2 = 187;
  11024. #if !defined(BENCH_EMBEDDED) && \
  11025. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11026. /* Sector size for encrypt/decrypt consecutive sectors testcase */
  11027. word32 sectorSz = 512;
  11028. unsigned char data[550];
  11029. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  11030. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11031. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11032. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  11033. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  11034. };
  11035. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  11036. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11037. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11038. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11039. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11040. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11041. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11042. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11043. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11044. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11045. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11046. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11047. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11048. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11049. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11050. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11051. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11052. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11053. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11054. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11055. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11056. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11057. 0xfc, 0xfd, 0xfe, 0xff,
  11058. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11059. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11060. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11061. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11062. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11063. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11064. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11065. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11066. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11067. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11068. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11069. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11070. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11071. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11072. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11073. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11074. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11075. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11076. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11077. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11078. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11079. 0xfc, 0xfd, 0xfe, 0xff,
  11080. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11081. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11082. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  11083. };
  11084. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  11085. 0xb9, 0x6b, 0x2b, 0xfd, 0x61, 0x87, 0x84, 0xd5, 0x26, 0xd2, 0x8c, 0x62,
  11086. 0x63, 0x01, 0xca, 0x46, 0xb1, 0x82, 0xfa, 0xdc, 0xbc, 0x32, 0x18, 0xe9,
  11087. 0xda, 0xe6, 0xda, 0xd1, 0x1a, 0x52, 0x77, 0xca, 0xdb, 0x0e, 0xbe, 0x37,
  11088. 0x88, 0x36, 0x1c, 0x87, 0x16, 0x60, 0xfe, 0xa8, 0x9e, 0xf6, 0x48, 0x64,
  11089. 0x94, 0x34, 0x64, 0xed, 0xf6, 0x9a, 0xc5, 0x28, 0xc9, 0xed, 0x64, 0x80,
  11090. 0x85, 0xd8, 0x93, 0xa7, 0x50, 0xb1, 0x9d, 0x2f, 0x1e, 0x34, 0xcc, 0xb4,
  11091. 0x03, 0xfb, 0x6b, 0x43, 0x21, 0xa8, 0x5b, 0xc6, 0x59, 0x13, 0xd2, 0xb5,
  11092. 0xf5, 0x7b, 0xf6, 0xb2, 0xa4, 0x7a, 0xd2, 0x50, 0x26, 0xcb, 0xa4, 0x83,
  11093. 0xc3, 0x56, 0xb0, 0xb1, 0x14, 0x34, 0x12, 0x1b, 0xea, 0x26, 0x97, 0x24,
  11094. 0x54, 0xcc, 0x32, 0x4c, 0xa4, 0xc2, 0xa3, 0x07, 0xfa, 0x30, 0xa9, 0xf0,
  11095. 0x91, 0x17, 0x60, 0x68, 0x88, 0x7f, 0x34, 0x7e, 0xbd, 0x20, 0x33, 0x95,
  11096. 0x6e, 0xc0, 0xb6, 0x2b, 0xff, 0x7e, 0x61, 0x35, 0x9a, 0x88, 0xff, 0xd9,
  11097. 0x69, 0x21, 0xe7, 0x8f, 0x45, 0x02, 0xf9, 0xd7, 0xeb, 0xa6, 0x53, 0xf1,
  11098. 0x73, 0x04, 0xf1, 0x0b, 0x85, 0xc6, 0x1f, 0x4a, 0x51, 0x2f, 0x95, 0x87,
  11099. 0x5a, 0x67, 0x37, 0xb2, 0x87, 0xf7, 0xbe, 0x2a, 0x17, 0x57, 0xca, 0xfc,
  11100. 0xdd, 0x5f, 0x37, 0x48, 0x78, 0xbd, 0xfa, 0x75, 0xc9, 0xfa, 0x86, 0x7e,
  11101. 0xc4, 0x0f, 0x60, 0x85, 0xce, 0x12, 0x44, 0x7c, 0xd9, 0xb2, 0x50, 0xd9,
  11102. 0x57, 0x85, 0xa5, 0xd7, 0x68, 0x59, 0x03, 0x09, 0x97, 0x2e, 0x8e, 0xa5,
  11103. 0xe3, 0x98, 0xac, 0x16, 0xfb, 0x6d, 0x54, 0xc5, 0x5d, 0x7a, 0x33, 0x44,
  11104. 0x0a, 0x39, 0x91, 0xcc, 0x9f, 0x67, 0xf9, 0x89, 0xbb, 0x62, 0x02, 0xc4,
  11105. 0x22, 0xec, 0xcf, 0x97, 0x69, 0x81, 0x3d, 0x00, 0xfd, 0xeb, 0x55, 0x08,
  11106. 0xa2, 0xff, 0x97, 0xaa, 0x79, 0xde, 0x3c, 0x8a, 0x78, 0x71, 0x73, 0xa2,
  11107. 0x98, 0x2f, 0xd8, 0x5c, 0x62, 0x1c, 0x5c, 0x23, 0x0a, 0xd1, 0xf1, 0x81,
  11108. 0x8a, 0x12, 0xe7, 0x4d, 0xdd, 0x4f, 0xd4, 0xf1, 0xe8, 0x0f, 0x25, 0x79,
  11109. 0x45, 0x4a, 0x49, 0x49, 0x7e, 0x56, 0x91, 0x4e, 0xaa, 0xba, 0x18, 0xe1,
  11110. 0xe4, 0xbe, 0x21, 0xdc, 0x58, 0x60, 0x6f, 0x6a, 0x7f, 0xdc, 0x5e, 0x74,
  11111. 0x47, 0xbf, 0xeb, 0x84, 0xc4, 0x1e, 0x5a, 0x61, 0x64, 0xc8, 0x63, 0x68,
  11112. 0xfa, 0x17, 0x9c, 0xac, 0x60, 0x1c, 0xa5, 0x6e, 0x00, 0x21, 0x93, 0x3c,
  11113. 0xd7, 0xbb, 0x73, 0x45, 0xf7, 0x34, 0x81, 0x6c, 0xfa, 0xf2, 0x33, 0xfd,
  11114. 0xb1, 0x40, 0x30, 0x6b, 0x30, 0xd1, 0x83, 0x5e, 0x2e, 0x7a, 0xce, 0xa6,
  11115. 0x12, 0x2a, 0x15, 0x03, 0x78, 0x29, 0xb9, 0x07, 0xae, 0xe7, 0xc2, 0x78,
  11116. 0x74, 0x72, 0xa5, 0x0e, 0x6b, 0x1f, 0x78, 0xf2, 0x5a, 0x69, 0xb6, 0x2b,
  11117. 0x99, 0x94, 0x1f, 0x89, 0xd1, 0x21, 0x14, 0x4a, 0x54, 0xab, 0x5a, 0x9f,
  11118. 0xaa, 0xa7, 0x96, 0x0a, 0x21, 0xce, 0x30, 0xb6, 0x70, 0x81, 0xe9, 0xd3,
  11119. 0x71, 0xc0, 0xf1, 0x15, 0xe2, 0xf6, 0xd3, 0xcc, 0x41, 0x15, 0x9d, 0xd5,
  11120. 0xa3, 0xa4, 0xe0, 0xf8, 0x62, 0xc4, 0x76, 0x65, 0x63, 0x89, 0xa7, 0xe2,
  11121. 0xfb, 0xf5, 0xc9, 0x80, 0x15, 0x5b, 0xc1, 0x59, 0xb2, 0xd0, 0x01, 0x3a,
  11122. 0xf9, 0xab, 0x5b, 0x79, 0x54, 0xed, 0x6b, 0xf9, 0x1d, 0x9d, 0x87, 0x63,
  11123. 0x80, 0x4f, 0xec, 0x9c, 0x4f, 0xad, 0x97, 0x04, 0xff, 0x62, 0x4a, 0x17,
  11124. 0xc0, 0x09, 0x2a, 0x2c, 0x23, 0x4b, 0xc3, 0xb6, 0x6d, 0xed, 0xdb, 0x1a,
  11125. 0x6f, 0x56, 0x2b, 0x78, 0x92, 0x3a, 0x5c, 0x7f, 0xb2, 0x63, 0xd3, 0xd5,
  11126. 0x1a, 0xbe, 0xc2, 0x34, 0xc8, 0xad, 0x36, 0xb7, 0x12, 0xb8, 0xe1, 0xb7,
  11127. 0x52, 0x7f, 0x16, 0x84, 0x2c, 0x47, 0x7e, 0xf2, 0xa5, 0x36, 0x2e, 0xad,
  11128. 0xe7, 0xbb, 0xc0, 0x6f, 0x27, 0x8e, 0x41, 0x08, 0x75, 0xe5, 0xff, 0xde,
  11129. 0x08, 0x9f, 0x8c, 0x91, 0xba, 0xc9, 0x9d, 0x9f, 0x27, 0x90, 0x50, 0x44,
  11130. 0x24, 0xe7, 0x3d, 0x6f
  11131. };
  11132. word64 s3 = 0x000000ffffffffff;
  11133. #endif
  11134. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11135. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11136. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11137. #endif
  11138. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11139. if (ret != 0)
  11140. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11141. else
  11142. aes_inited = 1;
  11143. XMEMSET(buf, 0, sizeof(buf));
  11144. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11145. if (ret != 0)
  11146. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11147. ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1);
  11148. #if defined(WOLFSSL_ASYNC_CRYPT)
  11149. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11150. #endif
  11151. if (ret != 0)
  11152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11153. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  11154. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11155. /* decrypt test */
  11156. XMEMSET(buf, 0, sizeof(buf));
  11157. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11158. if (ret != 0)
  11159. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11160. ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1);
  11161. #if defined(WOLFSSL_ASYNC_CRYPT)
  11162. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11163. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11164. #else
  11165. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11166. #endif
  11167. #endif
  11168. if (ret != 0)
  11169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11170. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  11171. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11172. /* 256 bit key tests */
  11173. XMEMSET(buf, 0, sizeof(buf));
  11174. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  11175. if (ret != 0)
  11176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11177. ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2);
  11178. #if defined(WOLFSSL_ASYNC_CRYPT)
  11179. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11180. #endif
  11181. if (ret != 0)
  11182. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11183. if (XMEMCMP(c2, buf, sizeof(c2)))
  11184. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11185. /* decrypt test */
  11186. XMEMSET(buf, 0, sizeof(buf));
  11187. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  11188. if (ret != 0)
  11189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11190. ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2);
  11191. #if defined(WOLFSSL_ASYNC_CRYPT)
  11192. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11193. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11194. #else
  11195. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11196. #endif
  11197. #endif
  11198. if (ret != 0)
  11199. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11200. if (XMEMCMP(p2, buf, sizeof(p2)))
  11201. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11202. #if !defined(BENCH_EMBEDDED) && \
  11203. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11204. /* encrypt consecutive sectors test */
  11205. XMEMSET(data, 0, sizeof(buf));
  11206. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  11207. if (ret != 0)
  11208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11209. ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3,
  11210. sizeof(p3), s3, sectorSz);
  11211. #if defined(WOLFSSL_ASYNC_CRYPT)
  11212. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11213. #endif
  11214. if (ret != 0)
  11215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11216. if (XMEMCMP(c3, data, sizeof(c3)))
  11217. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11218. /* decrypt consecutive sectors test */
  11219. XMEMSET(data, 0, sizeof(buf));
  11220. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  11221. if (ret != 0)
  11222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11223. ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3,
  11224. sizeof(c3), s3, sectorSz);
  11225. #if defined(WOLFSSL_ASYNC_CRYPT)
  11226. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11227. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11228. #else
  11229. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11230. #endif
  11231. #endif
  11232. if (ret != 0)
  11233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11234. if (XMEMCMP(p3, data, sizeof(p3)))
  11235. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11236. #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
  11237. out:
  11238. if (aes_inited)
  11239. wc_AesXtsFree(aes);
  11240. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11241. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11242. #endif
  11243. return ret;
  11244. }
  11245. #endif /* WOLFSSL_AES_128 && WOLFSSL_AES_256 */
  11246. #ifdef WOLFSSL_AES_128
  11247. /* testing of bad arguments */
  11248. static wc_test_ret_t aes_xts_args_test(void)
  11249. {
  11250. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11251. XtsAes *aes = NULL;
  11252. #else
  11253. XtsAes aes[1];
  11254. #endif
  11255. int aes_inited = 0;
  11256. wc_test_ret_t ret;
  11257. unsigned char buf[AES_BLOCK_SIZE * 2];
  11258. /* 128 key tests */
  11259. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  11260. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  11261. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  11262. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  11263. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  11264. };
  11265. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  11266. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  11267. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  11268. };
  11269. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  11270. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11271. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11272. };
  11273. word64 s1 = 141;
  11274. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11275. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11276. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11277. #endif
  11278. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11279. if (ret != 0)
  11280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11281. else
  11282. aes_inited = 1;
  11283. if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0)
  11284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11285. if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0)
  11286. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11287. /* encryption operations */
  11288. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11289. if (ret != 0)
  11290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11291. ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
  11292. #if defined(WOLFSSL_ASYNC_CRYPT)
  11293. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11294. #endif
  11295. if (ret == 0)
  11296. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11297. ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1);
  11298. #if defined(WOLFSSL_ASYNC_CRYPT)
  11299. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11300. #endif
  11301. if (ret == 0)
  11302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11303. /* decryption operations */
  11304. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11305. if (ret != 0)
  11306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11307. ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
  11308. #if defined(WOLFSSL_ASYNC_CRYPT)
  11309. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11310. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11311. #else
  11312. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11313. #endif
  11314. #endif
  11315. if (ret == 0)
  11316. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11317. ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1);
  11318. #if defined(WOLFSSL_ASYNC_CRYPT)
  11319. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11320. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11321. #else
  11322. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11323. #endif
  11324. #endif
  11325. if (ret == 0)
  11326. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11327. ret = 0;
  11328. out:
  11329. if (aes_inited)
  11330. wc_AesXtsFree(aes);
  11331. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11332. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11333. #endif
  11334. return ret;
  11335. }
  11336. #endif /* WOLFSSL_AES_128 */
  11337. #endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  11338. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  11339. !defined(HAVE_RENESAS_SYNC)
  11340. static wc_test_ret_t aes_cbc_oneshot_test(void)
  11341. {
  11342. byte cipher[AES_BLOCK_SIZE];
  11343. byte plain[AES_BLOCK_SIZE];
  11344. wc_test_ret_t ret;
  11345. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  11346. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  11347. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  11348. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  11349. };
  11350. byte key[] = "0123456789abcdef "; /* align */
  11351. byte iv[] = "1234567890abcdef "; /* align */
  11352. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11353. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11354. /* Parameter Validation testing. */
  11355. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL);
  11356. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11357. return WC_TEST_RET_ENC_EC(ret);
  11358. #ifdef HAVE_AES_DECRYPT
  11359. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL);
  11360. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11361. return WC_TEST_RET_ENC_EC(ret);
  11362. #endif
  11363. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key,
  11364. AES_BLOCK_SIZE, iv);
  11365. if (ret != 0)
  11366. return WC_TEST_RET_ENC_EC(ret);
  11367. #ifdef HAVE_AES_DECRYPT
  11368. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key,
  11369. AES_BLOCK_SIZE, iv);
  11370. if (ret != 0)
  11371. return WC_TEST_RET_ENC_EC(ret);
  11372. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
  11373. return WC_TEST_RET_ENC_NC;
  11374. #endif /* HAVE_AES_DECRYPT */
  11375. (void)plain;
  11376. return 0;
  11377. }
  11378. #endif
  11379. #if defined(WOLFSSL_AES_COUNTER) && defined(HAVE_AES_DECRYPT)
  11380. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void)
  11381. {
  11382. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11383. Aes *enc = NULL;
  11384. Aes *dec = NULL;
  11385. #else
  11386. Aes enc[1];
  11387. Aes dec[1];
  11388. #endif
  11389. byte cipher[AES_BLOCK_SIZE * 4];
  11390. byte plain [AES_BLOCK_SIZE * 4];
  11391. wc_test_ret_t ret = 0;
  11392. /* test vectors from "Recommendation for Block Cipher Modes of
  11393. * Operation" NIST Special Publication 800-38A */
  11394. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  11395. {
  11396. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  11397. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  11398. };
  11399. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  11400. {
  11401. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11402. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  11403. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  11404. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  11405. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  11406. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  11407. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  11408. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  11409. };
  11410. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11411. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32[] =
  11412. {
  11413. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
  11414. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11415. };
  11416. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32_2[] =
  11417. {
  11418. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11419. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xfe
  11420. };
  11421. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64[] =
  11422. {
  11423. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11424. 0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11425. };
  11426. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64_2[] =
  11427. {
  11428. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
  11429. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11430. };
  11431. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96[] =
  11432. {
  11433. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11434. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff
  11435. };
  11436. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96_2[] =
  11437. {
  11438. 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,
  11439. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11440. };
  11441. #endif
  11442. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
  11443. {
  11444. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11445. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11446. };
  11447. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11448. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128_2[] =
  11449. {
  11450. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11451. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11452. };
  11453. #endif
  11454. #ifdef WOLFSSL_AES_128
  11455. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  11456. {
  11457. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  11458. 0xc2
  11459. };
  11460. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
  11461. {
  11462. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  11463. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  11464. };
  11465. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
  11466. {
  11467. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  11468. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  11469. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  11470. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  11471. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  11472. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  11473. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  11474. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  11475. };
  11476. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11477. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32Cipher[] =
  11478. {
  11479. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11480. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11481. 0x7e,0xad,0xea,0x5c,0xd1
  11482. };
  11483. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32CipherLong[] =
  11484. {
  11485. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11486. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11487. 0x7e,0xad,0xea,0x5c,0xd1,0xb7,0x98,0xf0,
  11488. 0x22,0x20,0xfe,0x67,0xb0,0x02,0x23,0x50
  11489. };
  11490. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32_2CipherLong[] =
  11491. {
  11492. 0x6e,0xa1,0x27,0x4d,0xea,0x20,0x5f,0x39,
  11493. 0x68,0xc8,0xb6,0x78,0xde,0xfc,0x53,0x5c,
  11494. 0x90,0xc8,0xf6,0xc6,0xfa,0xe0,0x7b,0x09,
  11495. 0x7c,0xf8,0x9c,0x6a,0x5a,0xa5,0x17,0x7f,
  11496. 0x03,0x92,0x5f,0x4e,0x85,0xea,0x26,0xc9,
  11497. 0x5a,0xc2,0x74,0xe2,0xbf,0xe4,0x1b,0xd4
  11498. };
  11499. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64Cipher[] =
  11500. {
  11501. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11502. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11503. 0xae,0x74,0x94,0x72,0x8e
  11504. };
  11505. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64CipherLong[] =
  11506. {
  11507. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11508. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11509. 0xae,0x74,0x94,0x72,0x8e,0xd0,0x71,0xc0,
  11510. 0x89,0x8a,0xa1,0xb0,0x29,0xa0,0x10,0x9e
  11511. };
  11512. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64_2CipherLong[] =
  11513. {
  11514. 0x3f,0xe7,0xd5,0xf3,0xfa,0x09,0xfe,0x40,
  11515. 0xa6,0xa1,0x32,0x8b,0x57,0x12,0xb9,0xfa,
  11516. 0xf2,0x2d,0xe4,0x3c,0x66,0x1d,0x0a,0x8e,
  11517. 0x46,0xf8,0x2e,0x33,0xce,0x8d,0x4e,0x3b,
  11518. 0x17,0x67,0x9e,0x9f,0x76,0x9e,0xc2,0x99,
  11519. 0xd5,0xd4,0x71,0xed,0xb4,0x33,0xb2,0xcd
  11520. };
  11521. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96Cipher[] =
  11522. {
  11523. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11524. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11525. 0x9d,0x77,0xc9,0x5f,0x38
  11526. };
  11527. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96CipherLong[] =
  11528. {
  11529. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11530. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11531. 0x9d,0x77,0xc9,0x5f,0x38,0xb5,0x6e,0x44,
  11532. 0x21,0x8e,0xda,0x57,0xe0,0x41,0xc7,0x6a
  11533. };
  11534. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96_2CipherLong[] =
  11535. {
  11536. 0xc8,0x81,0x1a,0xbe,0xc7,0x5b,0x93,0x6f,
  11537. 0xe6,0x52,0xe4,0xb1,0x2d,0x1c,0x39,0xbc,
  11538. 0xeb,0x82,0x27,0x0a,0x7e,0xa5,0x0e,0x2d,
  11539. 0x32,0xda,0xbe,0x10,0x7a,0x10,0xcc,0xd3,
  11540. 0x6f,0xc6,0x83,0x28,0x05,0x57,0x8a,0x24,
  11541. 0x44,0x76,0x17,0x81,0xb9,0x5c,0x94,0x81
  11542. };
  11543. #endif
  11544. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
  11545. {
  11546. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11547. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11548. 0xd3,0xda,0xe1,0x5b,0x04
  11549. };
  11550. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
  11551. {
  11552. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11553. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11554. 0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
  11555. 0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
  11556. };
  11557. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11558. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128_2CipherLong[] =
  11559. {
  11560. 0xba,0x76,0xaa,0x54,0xd5,0xb5,0x60,0x67,
  11561. 0xc1,0xa7,0x90,0x3b,0x3f,0xdd,0xfa,0x89,
  11562. 0x24,0xdf,0x0c,0x56,0x5c,0xf4,0x2a,0x68,
  11563. 0x97,0x87,0x13,0xb6,0x7a,0xd1,0x24,0xfd,
  11564. 0x4d,0x3f,0x77,0x4a,0xb9,0xe4,0x7d,0xa2,
  11565. 0xdb,0xb9,0x31,0x5e,0xa3,0x11,0x06,0x80
  11566. };
  11567. #endif
  11568. #endif /* WOLFSSL_AES_128 */
  11569. #ifdef WOLFSSL_AES_192
  11570. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  11571. {
  11572. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  11573. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  11574. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  11575. };
  11576. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  11577. {
  11578. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  11579. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b,
  11580. 0x09,0x03,0x39,0xec,0x0a,0xa6,0xfa,0xef,
  11581. 0xd5,0xcc,0xc2,0xc6,0xf4,0xce,0x8e,0x94,
  11582. 0x1e,0x36,0xb2,0x6b,0xd1,0xeb,0xc6,0x70,
  11583. 0xd1,0xbd,0x1d,0x66,0x56,0x20,0xab,0xf7,
  11584. 0x4f,0x78,0xa7,0xf6,0xd2,0x98,0x09,0x58,
  11585. 0x5a,0x97,0xda,0xec,0x58,0xc6,0xb0,0x50
  11586. };
  11587. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11588. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32Cipher[] =
  11589. {
  11590. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11591. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11592. 0x0c,0x33,0x97,0x06,0xc0
  11593. };
  11594. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32CipherLong[] =
  11595. {
  11596. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11597. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11598. 0x0c,0x33,0x97,0x06,0xc0,0xbe,0x83,0x87,
  11599. 0xdd,0xd3,0xff,0xd8,0xe4,0x6a,0x5b,0x84
  11600. };
  11601. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32_2CipherLong[] =
  11602. {
  11603. 0xf5,0x00,0xa2,0x91,0x54,0xa3,0x76,0xa2,
  11604. 0xdd,0xad,0x16,0x89,0xe5,0xf0,0x1d,0x40,
  11605. 0x84,0xcd,0x74,0x84,0xcb,0x8b,0x9e,0x29,
  11606. 0xa9,0x8a,0x12,0x65,0xa0,0x79,0x5e,0xce,
  11607. 0xd9,0x50,0x65,0x21,0x86,0xb0,0x85,0x0d,
  11608. 0x98,0x2d,0x9a,0x5a,0x11,0xbe,0xa5,0x7f
  11609. };
  11610. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64Cipher[] =
  11611. {
  11612. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11613. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11614. 0x3d,0xf7,0xb4,0xfd,0x8c
  11615. };
  11616. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64CipherLong[] =
  11617. {
  11618. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11619. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11620. 0x3d,0xf7,0xb4,0xfd,0x8c,0x55,0x47,0x10,
  11621. 0xd5,0x91,0x35,0xbe,0xd8,0x0d,0xa5,0x9e
  11622. };
  11623. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64_2CipherLong[] =
  11624. {
  11625. 0x59,0xf1,0xed,0x70,0x62,0x42,0xa8,0x06,
  11626. 0x07,0x36,0xe1,0xc5,0x04,0x79,0xc3,0x9b,
  11627. 0xd1,0x14,0x5c,0xcc,0x6f,0x81,0x5f,0x2f,
  11628. 0xa0,0xde,0xcf,0x61,0x55,0x18,0x7a,0xac,
  11629. 0xb0,0x59,0x37,0x90,0x53,0xb3,0x00,0x88,
  11630. 0xb4,0x49,0x90,0x7b,0x96,0xcd,0xcc,0xc3
  11631. };
  11632. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96Cipher[] =
  11633. {
  11634. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11635. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11636. 0x47,0xb5,0xf3,0x30,0x3b
  11637. };
  11638. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96CipherLong[] =
  11639. {
  11640. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11641. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11642. 0x47,0xb5,0xf3,0x30,0x3b,0xef,0xcd,0x80,
  11643. 0xe3,0x61,0x34,0xef,0x4e,0x1b,0x79,0xc1
  11644. };
  11645. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96_2CipherLong[] =
  11646. {
  11647. 0x3c,0xb2,0xff,0xc0,0x24,0xe1,0xf5,0xc4,
  11648. 0x0f,0xd1,0x0a,0x1b,0xbe,0x1f,0x23,0xa1,
  11649. 0x8e,0xbf,0x2b,0x96,0xb6,0x37,0xc8,0x25,
  11650. 0x06,0x90,0xe2,0xca,0x71,0x24,0x52,0x95,
  11651. 0xaa,0x8c,0x80,0xdf,0xb7,0xd7,0x30,0xb0,
  11652. 0xcc,0x06,0x4f,0x28,0xa2,0x74,0x27,0xf8
  11653. };
  11654. #endif
  11655. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128Cipher[] =
  11656. {
  11657. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11658. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11659. 0x8c,0x68,0xa7,0xd9,0x57
  11660. };
  11661. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128CipherLong[] =
  11662. {
  11663. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11664. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11665. 0x8c,0x68,0xa7,0xd9,0x57,0xab,0x09,0x0f,
  11666. 0x01,0xc4,0x4e,0x62,0xaf,0xc2,0xdf,0x1a
  11667. };
  11668. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11669. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128_2CipherLong[] =
  11670. {
  11671. 0x88,0x0a,0x26,0x4e,0xa8,0x26,0x21,0xe0,
  11672. 0xfc,0xbc,0x63,0xdc,0xd9,0x60,0x52,0xb2,
  11673. 0x99,0x2f,0xbb,0x1e,0x00,0xf5,0x9f,0x6d,
  11674. 0xab,0x48,0x0f,0xc6,0x37,0x12,0x56,0xe3,
  11675. 0x12,0x8d,0x31,0xc8,0xea,0xf4,0x41,0x82,
  11676. 0x7a,0x88,0xe0,0xd7,0xf0,0x67,0x03,0xa4
  11677. };
  11678. #endif
  11679. #endif
  11680. #ifdef WOLFSSL_AES_256
  11681. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  11682. {
  11683. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11684. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11685. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11686. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11687. };
  11688. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  11689. {
  11690. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  11691. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
  11692. 0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
  11693. 0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
  11694. 0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
  11695. 0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
  11696. 0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
  11697. 0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
  11698. };
  11699. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11700. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32Cipher[] =
  11701. {
  11702. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11703. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11704. 0xa2,0x13,0x47,0x74,0xda
  11705. };
  11706. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32CipherLong[] =
  11707. {
  11708. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11709. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11710. 0xa2,0x13,0x47,0x74,0xda,0x89,0x77,0x40,
  11711. 0x28,0x9c,0xe8,0x19,0x26,0x32,0xd8,0x1f
  11712. };
  11713. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32_2CipherLong[] =
  11714. {
  11715. 0xf6,0xd9,0x22,0xc6,0x80,0x29,0xaf,0x14,
  11716. 0x54,0x6c,0x0a,0xce,0x42,0xea,0x3c,0xa1,
  11717. 0x7c,0xeb,0x36,0x0d,0x8e,0xd7,0x8c,0x59,
  11718. 0xa8,0x09,0x9f,0x9e,0xba,0x5b,0x95,0xfa,
  11719. 0x26,0x8c,0x37,0x59,0xf8,0xae,0x8e,0xaa,
  11720. 0x4d,0xe4,0x1c,0xfe,0x51,0xc7,0xb7,0xcc
  11721. };
  11722. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64Cipher[] =
  11723. {
  11724. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11725. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11726. 0xd4,0x94,0x4c,0xcd,0x4d
  11727. };
  11728. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64CipherLong[] =
  11729. {
  11730. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11731. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11732. 0xd4,0x94,0x4c,0xcd,0x4d,0x47,0x5a,0x92,
  11733. 0x26,0x49,0x81,0x7a,0xda,0x36,0x27,0x01
  11734. };
  11735. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64_2CipherLong[] =
  11736. {
  11737. 0xf7,0x9c,0xbf,0xf6,0xa2,0xaa,0x8a,0x0a,
  11738. 0x63,0x8a,0x20,0x2f,0x12,0xf1,0x8e,0x49,
  11739. 0x30,0xc0,0x8d,0x5c,0x5f,0x8b,0xbc,0x16,
  11740. 0xdd,0x71,0xee,0x13,0x14,0x7b,0xe1,0x25,
  11741. 0xcb,0x87,0x8a,0xc6,0xdc,0x1d,0x54,0x7a,
  11742. 0xe1,0xe4,0x6f,0x0d,0x95,0x1b,0xd1,0x8b
  11743. };
  11744. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96Cipher[] =
  11745. {
  11746. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11747. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11748. 0xb8,0x69,0xa1,0x48,0x45
  11749. };
  11750. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96CipherLong[] =
  11751. {
  11752. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11753. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11754. 0xb8,0x69,0xa1,0x48,0x45,0xf1,0xc6,0x27,
  11755. 0x36,0xa8,0xb2,0x4b,0x0e,0x62,0x6b,0x72
  11756. };
  11757. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96_2CipherLong[] =
  11758. {
  11759. 0xd5,0x56,0x73,0xaa,0xb8,0xe4,0x06,0xf6,
  11760. 0x83,0x45,0x3a,0xb4,0xb9,0x63,0xec,0xad,
  11761. 0x73,0xc5,0xab,0x78,0xb1,0x21,0xab,0xef,
  11762. 0x69,0x15,0xb7,0x0c,0xe9,0xb4,0x3a,0xe7,
  11763. 0xbc,0xc4,0x22,0xbd,0x93,0xba,0x52,0xe0,
  11764. 0x91,0x2f,0x5e,0x8d,0x6d,0x59,0xf7,0xc2
  11765. };
  11766. #endif
  11767. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
  11768. {
  11769. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11770. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11771. 0x4b,0x45,0x7c,0xd6,0x8a
  11772. };
  11773. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
  11774. {
  11775. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11776. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11777. 0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
  11778. 0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
  11779. };
  11780. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11781. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128_2CipherLong[] =
  11782. {
  11783. 0x24,0x5c,0x09,0xa0,0x3b,0x1a,0x5a,0x94,
  11784. 0x2b,0x93,0x56,0x13,0x48,0xa0,0x21,0xce,
  11785. 0x95,0x11,0xa3,0x76,0xd6,0x59,0x88,0x42,
  11786. 0x04,0x71,0x69,0x62,0x28,0xb2,0xee,0x9d,
  11787. 0xd5,0xa0,0xea,0xc7,0x37,0x93,0x92,0xc7,
  11788. 0xf2,0xb6,0x8d,0xd9,0x59,0x1a,0xfa,0xbb
  11789. };
  11790. #endif
  11791. #endif
  11792. int i;
  11793. struct {
  11794. const byte* key;
  11795. int keySz;
  11796. const byte* iv;
  11797. const byte* plain;
  11798. int len;
  11799. const byte* cipher;
  11800. } testVec[] = {
  11801. #ifdef WOLFSSL_AES_128
  11802. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11803. ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
  11804. /* let's try with just 9 bytes, non block size test */
  11805. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11806. ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
  11807. /* and an additional 9 bytes to reuse tmp left buffer */
  11808. { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
  11809. /* Counter wrapping */
  11810. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11811. ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
  11812. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11813. ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
  11814. ctr128Wrap128CipherLong },
  11815. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11816. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128_2,
  11817. ctrPlain, (int)sizeof(ctr128Wrap128_2CipherLong),
  11818. ctr128Wrap128_2CipherLong },
  11819. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11820. ctrPlain, (int)sizeof(ctr128Wrap96Cipher), ctr128Wrap96Cipher },
  11821. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11822. ctrPlain, (int)sizeof(ctr128Wrap96CipherLong),
  11823. ctr128Wrap96CipherLong },
  11824. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96_2,
  11825. ctrPlain, (int)sizeof(ctr128Wrap96_2CipherLong),
  11826. ctr128Wrap96_2CipherLong },
  11827. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11828. ctrPlain, (int)sizeof(ctr128Wrap64Cipher), ctr128Wrap64Cipher },
  11829. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11830. ctrPlain, (int)sizeof(ctr128Wrap64CipherLong),
  11831. ctr128Wrap64CipherLong },
  11832. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64_2,
  11833. ctrPlain, (int)sizeof(ctr128Wrap64_2CipherLong),
  11834. ctr128Wrap64_2CipherLong },
  11835. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11836. ctrPlain, (int)sizeof(ctr128Wrap32Cipher), ctr128Wrap32Cipher },
  11837. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11838. ctrPlain, (int)sizeof(ctr128Wrap32CipherLong),
  11839. ctr128Wrap32CipherLong },
  11840. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32_2,
  11841. ctrPlain, (int)sizeof(ctr128Wrap32_2CipherLong),
  11842. ctr128Wrap32_2CipherLong },
  11843. #endif
  11844. #endif
  11845. #ifdef WOLFSSL_AES_192
  11846. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11847. ctrPlain, (int)sizeof(ctrPlain), ctr192Cipher },
  11848. /* let's try with just 9 bytes, non block size test */
  11849. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11850. ctrPlain, (int)sizeof(oddCipher), ctr192Cipher },
  11851. /* Counter wrapping */
  11852. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11853. ctrPlain, (int)sizeof(ctr192Wrap128Cipher), ctr192Wrap128Cipher },
  11854. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11855. ctrPlain, (int)sizeof(ctr192Wrap128CipherLong),
  11856. ctr192Wrap128CipherLong },
  11857. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11858. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128_2,
  11859. ctrPlain, (int)sizeof(ctr192Wrap128_2CipherLong),
  11860. ctr192Wrap128_2CipherLong },
  11861. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11862. ctrPlain, (int)sizeof(ctr192Wrap96Cipher), ctr192Wrap96Cipher },
  11863. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11864. ctrPlain, (int)sizeof(ctr192Wrap96CipherLong),
  11865. ctr192Wrap96CipherLong },
  11866. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96_2,
  11867. ctrPlain, (int)sizeof(ctr192Wrap96_2CipherLong),
  11868. ctr192Wrap96_2CipherLong },
  11869. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11870. ctrPlain, (int)sizeof(ctr192Wrap64Cipher), ctr192Wrap64Cipher },
  11871. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11872. ctrPlain, (int)sizeof(ctr192Wrap64CipherLong),
  11873. ctr192Wrap64CipherLong },
  11874. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64_2,
  11875. ctrPlain, (int)sizeof(ctr192Wrap64_2CipherLong),
  11876. ctr192Wrap64_2CipherLong },
  11877. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11878. ctrPlain, (int)sizeof(ctr192Wrap32Cipher), ctr192Wrap32Cipher },
  11879. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11880. ctrPlain, (int)sizeof(ctr192Wrap32CipherLong),
  11881. ctr192Wrap32CipherLong },
  11882. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32_2,
  11883. ctrPlain, (int)sizeof(ctr192Wrap32_2CipherLong),
  11884. ctr192Wrap32_2CipherLong },
  11885. #endif
  11886. #endif
  11887. #ifdef WOLFSSL_AES_256
  11888. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11889. ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
  11890. /* let's try with just 9 bytes, non block size test */
  11891. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11892. ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
  11893. /* Counter wrapping */
  11894. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11895. ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
  11896. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11897. ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
  11898. ctr256Wrap128CipherLong },
  11899. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11900. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128_2,
  11901. ctrPlain, (int)sizeof(ctr256Wrap128_2CipherLong),
  11902. ctr256Wrap128_2CipherLong },
  11903. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11904. ctrPlain, (int)sizeof(ctr256Wrap96Cipher), ctr256Wrap96Cipher },
  11905. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11906. ctrPlain, (int)sizeof(ctr256Wrap96CipherLong),
  11907. ctr256Wrap96CipherLong },
  11908. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96_2,
  11909. ctrPlain, (int)sizeof(ctr256Wrap96_2CipherLong),
  11910. ctr256Wrap96_2CipherLong },
  11911. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11912. ctrPlain, (int)sizeof(ctr256Wrap64Cipher), ctr256Wrap64Cipher },
  11913. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11914. ctrPlain, (int)sizeof(ctr256Wrap64CipherLong),
  11915. ctr256Wrap64CipherLong },
  11916. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64_2,
  11917. ctrPlain, (int)sizeof(ctr256Wrap64_2CipherLong),
  11918. ctr256Wrap64_2CipherLong },
  11919. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11920. ctrPlain, (int)sizeof(ctr256Wrap32Cipher), ctr256Wrap32Cipher },
  11921. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11922. ctrPlain, (int)sizeof(ctr256Wrap32CipherLong),
  11923. ctr256Wrap32CipherLong },
  11924. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32_2,
  11925. ctrPlain, (int)sizeof(ctr256Wrap32_2CipherLong),
  11926. ctr256Wrap32_2CipherLong },
  11927. #endif
  11928. #endif
  11929. };
  11930. #define AES_CTR_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  11931. WOLFSSL_ENTER("aes_ctr_test");
  11932. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11933. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  11934. if (enc == NULL)
  11935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11936. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  11937. if (dec == NULL)
  11938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11939. #else
  11940. XMEMSET(enc, 0, sizeof(Aes));
  11941. XMEMSET(dec, 0, sizeof(Aes));
  11942. ret = wc_AesInit(enc, HEAP_HINT, devId);
  11943. if (ret != 0)
  11944. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11945. ret = wc_AesInit(dec, HEAP_HINT, devId);
  11946. if (ret != 0)
  11947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11948. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  11949. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11950. if (testVec[i].key != NULL) {
  11951. ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
  11952. testVec[i].iv, AES_ENCRYPTION);
  11953. if (ret != 0) {
  11954. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11955. }
  11956. /* Ctr only uses encrypt, even on key setup */
  11957. ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)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. }
  11963. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
  11964. if (ret != 0) {
  11965. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11966. }
  11967. ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
  11968. if (ret != 0) {
  11969. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11970. }
  11971. if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
  11972. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11973. }
  11974. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11975. if (XMEMCMP(cipher, testVec[i].cipher, (size_t)testVec[i].len)) {
  11976. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11977. }
  11978. #endif
  11979. }
  11980. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11981. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11982. if (testVec[i].key != NULL) {
  11983. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11984. testVec[i].iv, AES_ENCRYPTION);
  11985. if (ret != 0) {
  11986. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11987. }
  11988. /* Ctr only uses encrypt, even on key setup */
  11989. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  11990. testVec[i].iv, AES_ENCRYPTION);
  11991. if (ret != 0) {
  11992. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11993. }
  11994. }
  11995. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11996. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  11997. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11998. if (ret != 0) {
  11999. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12000. }
  12001. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12002. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12003. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12004. if (ret != 0) {
  12005. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12006. }
  12007. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12008. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12009. }
  12010. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12011. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12012. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12013. }
  12014. #endif
  12015. }
  12016. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  12017. if (testVec[i].key != NULL) {
  12018. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12019. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  12020. testVec[i].iv, AES_ENCRYPTION);
  12021. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12022. if (ret != 0) {
  12023. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12024. }
  12025. /* Ctr only uses encrypt, even on key setup */
  12026. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12027. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  12028. testVec[i].iv, AES_ENCRYPTION);
  12029. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12030. if (ret != 0) {
  12031. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12032. }
  12033. }
  12034. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12035. if (ret != 0) {
  12036. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12037. }
  12038. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12039. if (ret != 0) {
  12040. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12041. }
  12042. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12043. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12044. }
  12045. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12046. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12047. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12048. }
  12049. #endif
  12050. }
  12051. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12052. out:
  12053. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12054. wc_AesDelete(enc, &enc);
  12055. #else
  12056. wc_AesFree(enc);
  12057. #endif
  12058. #ifdef HAVE_AES_DECRYPT
  12059. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12060. wc_AesDelete(dec, &dec);
  12061. #else
  12062. wc_AesFree(dec);
  12063. #endif
  12064. #endif
  12065. return ret;
  12066. }
  12067. #endif /* WOLFSSL_AES_COUNTER */
  12068. #ifdef HAVE_AES_ECB
  12069. static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12070. {
  12071. wc_test_ret_t ret = 0;
  12072. /* keys padded to block size (16 bytes) */
  12073. WOLFSSL_SMALL_STACK_STATIC const byte key_128[] =
  12074. "0123456789abcdef ";
  12075. WOLFSSL_SMALL_STACK_STATIC const byte key_192[] =
  12076. "0123456789abcdef01234567 ";
  12077. WOLFSSL_SMALL_STACK_STATIC const byte key_256[] =
  12078. "0123456789abcdef0123456789abcdef ";
  12079. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12080. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12081. 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  12082. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20
  12083. };
  12084. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[AES_BLOCK_SIZE] = {
  12085. 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
  12086. 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
  12087. };
  12088. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[AES_BLOCK_SIZE] = {
  12089. 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1,
  12090. 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab
  12091. };
  12092. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[AES_BLOCK_SIZE] = {
  12093. 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33,
  12094. 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82
  12095. };
  12096. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] = {
  12097. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12098. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12099. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12100. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12101. };
  12102. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] = {
  12103. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12104. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12105. };
  12106. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] = {
  12107. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12108. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12109. };
  12110. int i;
  12111. struct {
  12112. const byte* key;
  12113. int keySz;
  12114. const byte* iv; /* null uses 0's */
  12115. const byte* plain;
  12116. const byte* verify;
  12117. } testVec[] = {
  12118. { key_128, 16, iv, msg, verify_ecb_128 },
  12119. { key_192, 24, iv, msg, verify_ecb_192 },
  12120. { key_256, 32, iv, msg, verify_ecb_256 },
  12121. { niKey, 32, NULL, niPlain, niCipher }
  12122. };
  12123. #define AES_ECB_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  12124. for (i = 0; i < AES_ECB_TEST_LEN; i++) {
  12125. ret = wc_AesSetKey(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12126. AES_ENCRYPTION);
  12127. if (ret != 0)
  12128. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12129. #ifdef HAVE_AES_DECRYPT
  12130. ret = wc_AesSetKey(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12131. AES_DECRYPTION);
  12132. if (ret != 0)
  12133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12134. #endif
  12135. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12136. ret = wc_AesEcbEncrypt(enc, cipher, testVec[i].plain, AES_BLOCK_SIZE);
  12137. #if defined(WOLFSSL_ASYNC_CRYPT)
  12138. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12139. #endif
  12140. if (ret != 0)
  12141. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12142. if (XMEMCMP(cipher, testVec[i].verify, AES_BLOCK_SIZE)) {
  12143. WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!");
  12144. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12145. }
  12146. #ifdef HAVE_AES_DECRYPT
  12147. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12148. ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12149. #if defined(WOLFSSL_ASYNC_CRYPT)
  12150. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12151. #endif
  12152. if (ret != 0)
  12153. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12154. if (XMEMCMP(plain, testVec[i].plain, AES_BLOCK_SIZE))
  12155. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12156. #endif /* HAVE_AES_DECRYPT */
  12157. (void)dec;
  12158. (void)plain;
  12159. }
  12160. out:
  12161. return ret;
  12162. }
  12163. #endif /* HAVE_AES_ECB */
  12164. #ifdef WOLFSSL_AES_DIRECT
  12165. static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12166. {
  12167. wc_test_ret_t ret = 0;
  12168. WOLFSSL_ENTER("aes_direct_test");
  12169. #if defined(WOLFSSL_AES_256)
  12170. {
  12171. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  12172. {
  12173. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12174. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12175. };
  12176. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  12177. {
  12178. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12179. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12180. };
  12181. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  12182. {
  12183. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12184. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12185. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12186. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12187. };
  12188. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12189. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  12190. if (ret != 0)
  12191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12192. #if !defined(HAVE_SELFTEST) && \
  12193. (defined(WOLFSSL_LINUXKM) || \
  12194. !defined(HAVE_FIPS) || \
  12195. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12196. ret = wc_AesEncryptDirect(enc, cipher, niPlain);
  12197. if (ret != 0)
  12198. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12199. #else
  12200. wc_AesEncryptDirect(enc, cipher, niPlain);
  12201. #endif
  12202. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  12203. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12204. #ifdef HAVE_AES_DECRYPT
  12205. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12206. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  12207. if (ret != 0)
  12208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12209. #if !defined(HAVE_SELFTEST) && \
  12210. (defined(WOLFSSL_LINUXKM) || \
  12211. !defined(HAVE_FIPS) || \
  12212. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12213. ret = wc_AesDecryptDirect(dec, plain, niCipher);
  12214. if (ret != 0)
  12215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12216. #else
  12217. wc_AesDecryptDirect(dec, plain, niCipher);
  12218. #endif
  12219. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  12220. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12221. #endif /* HAVE_AES_DECRYPT */
  12222. }
  12223. (void)dec;
  12224. (void)plain;
  12225. #endif /* WOLFSSL_AES_256 */
  12226. out:
  12227. return ret;
  12228. }
  12229. #endif /* WOLFSSL_AES_DIRECT */
  12230. #ifdef HAVE_AES_CBC
  12231. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void)
  12232. {
  12233. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12234. Aes *enc = NULL;
  12235. #else
  12236. Aes enc[1];
  12237. #endif
  12238. #ifdef HAVE_AES_DECRYPT
  12239. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12240. Aes *dec = NULL;
  12241. #else
  12242. Aes dec[1];
  12243. #endif
  12244. #endif
  12245. byte cipher[AES_BLOCK_SIZE * 4];
  12246. #ifdef HAVE_AES_DECRYPT
  12247. byte plain [AES_BLOCK_SIZE * 4];
  12248. #endif
  12249. wc_test_ret_t ret = 0;
  12250. WOLFSSL_ENTER("aes_cbc_test");
  12251. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12252. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12253. if (enc == NULL)
  12254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12255. #ifdef HAVE_AES_DECRYPT
  12256. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12257. if (dec == NULL)
  12258. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12259. #endif
  12260. #else
  12261. XMEMSET(enc, 0, sizeof(Aes));
  12262. #ifdef HAVE_AES_DECRYPT
  12263. XMEMSET(dec, 0, sizeof(Aes));
  12264. #endif
  12265. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12266. if (ret != 0)
  12267. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12268. #ifdef HAVE_AES_DECRYPT
  12269. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12270. if (ret != 0)
  12271. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12272. #endif
  12273. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12274. #ifdef WOLFSSL_AES_128
  12275. {
  12276. /* "Now is the time for all " w/o trailing 0 */
  12277. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12278. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  12279. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  12280. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  12281. };
  12282. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12283. {
  12284. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  12285. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  12286. };
  12287. #ifdef HAVE_RENESAS_SYNC
  12288. const byte *key = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  12289. #else
  12290. /* padded to 16-byye */
  12291. WOLFSSL_SMALL_STACK_STATIC const byte key[] = "0123456789abcdef ";
  12292. #endif
  12293. /* padded to 16-bytes */
  12294. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12295. ret = wc_AesSetKey(enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  12296. if (ret != 0)
  12297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12298. #ifdef HAVE_AES_DECRYPT
  12299. ret = wc_AesSetKey(dec, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
  12300. if (ret != 0)
  12301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12302. #endif
  12303. XMEMSET(cipher, 0, sizeof(cipher));
  12304. ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
  12305. #if defined(WOLFSSL_ASYNC_CRYPT)
  12306. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12307. #endif
  12308. if (ret != 0)
  12309. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12310. #ifdef HAVE_AES_DECRYPT
  12311. XMEMSET(plain, 0, sizeof(plain));
  12312. ret = wc_AesCbcDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12313. #if defined(WOLFSSL_ASYNC_CRYPT)
  12314. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12315. #endif
  12316. if (ret != 0) {
  12317. WOLFSSL_MSG("failed wc_AesCbcDecrypt");
  12318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12319. }
  12320. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) {
  12321. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare");
  12322. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12323. }
  12324. #endif /* HAVE_AES_DECRYPT */
  12325. /* skipped because wrapped key use in case of renesas sm */
  12326. #ifndef HAVE_RENESAS_SYNC
  12327. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) {
  12328. WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare");
  12329. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12330. }
  12331. #endif
  12332. }
  12333. #endif /* WOLFSSL_AES_128 */
  12334. #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT)
  12335. {
  12336. WOLFSSL_SMALL_STACK_STATIC const byte bigMsg[] = {
  12337. /* "All work and no play makes Jack a dull boy. " */
  12338. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12339. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12340. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12341. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12342. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12343. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12344. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12345. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12346. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12347. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12348. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12349. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12350. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12351. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12352. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12353. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12354. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12355. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12356. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12357. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12358. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12359. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12360. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12361. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12362. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12363. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12364. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12365. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12366. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12367. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12368. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12369. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12370. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12371. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12372. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12373. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12374. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12375. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12376. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12377. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12378. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12379. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12380. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12381. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12382. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12383. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12384. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12385. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20
  12386. };
  12387. WOLFSSL_SMALL_STACK_STATIC const byte bigKey[] =
  12388. "0123456789abcdeffedcba9876543210";
  12389. /* padded to 16-bytes */
  12390. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12391. word32 keySz, msgSz;
  12392. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12393. byte *bigCipher = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12394. DYNAMIC_TYPE_TMP_BUFFER);
  12395. byte *bigPlain = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12396. DYNAMIC_TYPE_TMP_BUFFER);
  12397. if ((bigCipher == NULL) ||
  12398. (bigPlain == NULL)) {
  12399. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12400. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12401. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12402. }
  12403. #else
  12404. byte bigCipher[sizeof(bigMsg)];
  12405. byte bigPlain[sizeof(bigMsg)];
  12406. #endif
  12407. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12408. * message by AES_BLOCK_SIZE for each size of AES key. */
  12409. for (keySz = 16; keySz <= 32; keySz += 8) {
  12410. for (msgSz = AES_BLOCK_SIZE;
  12411. msgSz <= sizeof(bigMsg);
  12412. msgSz += AES_BLOCK_SIZE) {
  12413. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12414. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12415. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12416. if (ret != 0) {
  12417. ret = WC_TEST_RET_ENC_EC(ret);
  12418. break;
  12419. }
  12420. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12421. if (ret != 0) {
  12422. ret = WC_TEST_RET_ENC_EC(ret);
  12423. break;
  12424. }
  12425. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12426. #if defined(WOLFSSL_ASYNC_CRYPT)
  12427. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12428. #endif
  12429. if (ret != 0) {
  12430. ret = WC_TEST_RET_ENC_EC(ret);
  12431. break;
  12432. }
  12433. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12434. #if defined(WOLFSSL_ASYNC_CRYPT)
  12435. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12436. #endif
  12437. if (ret != 0) {
  12438. ret = WC_TEST_RET_ENC_EC(ret);
  12439. break;
  12440. }
  12441. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12442. ret = WC_TEST_RET_ENC_NC;
  12443. break;
  12444. }
  12445. }
  12446. if (ret != 0)
  12447. break;
  12448. }
  12449. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12450. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12451. * message by AES_BLOCK_SIZE for each size of AES key. */
  12452. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12453. for (keySz = 16; keySz <= 32; keySz += 8) {
  12454. for (msgSz = AES_BLOCK_SIZE;
  12455. msgSz <= sizeof(bigMsg);
  12456. msgSz += AES_BLOCK_SIZE) {
  12457. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12458. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12459. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12460. if (ret != 0) {
  12461. ret = WC_TEST_RET_ENC_EC(ret);
  12462. break;
  12463. }
  12464. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12465. if (ret != 0) {
  12466. ret = WC_TEST_RET_ENC_EC(ret);
  12467. break;
  12468. }
  12469. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12470. #if defined(WOLFSSL_ASYNC_CRYPT)
  12471. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12472. #endif
  12473. if (ret != 0) {
  12474. ret = WC_TEST_RET_ENC_EC(ret);
  12475. break;
  12476. }
  12477. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12478. #if defined(WOLFSSL_ASYNC_CRYPT)
  12479. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12480. #endif
  12481. if (ret != 0) {
  12482. ret = WC_TEST_RET_ENC_EC(ret);
  12483. break;
  12484. }
  12485. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12486. ret = WC_TEST_RET_ENC_NC;
  12487. break;
  12488. }
  12489. }
  12490. if (ret != 0)
  12491. break;
  12492. }
  12493. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12494. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12495. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12496. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12497. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12498. #endif
  12499. if (ret != 0)
  12500. goto out;
  12501. }
  12502. #endif /* WOLFSSL_AESNI && HAVE_AES_DECRYPT */
  12503. /* Test of AES IV state with encrypt/decrypt */
  12504. #if defined(WOLFSSL_AES_128) && !defined(HAVE_RENESAS_SYNC)
  12505. {
  12506. /* Test Vector from "NIST Special Publication 800-38A, 2001 Edition"
  12507. * https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf
  12508. */
  12509. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  12510. {
  12511. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  12512. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  12513. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  12514. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
  12515. };
  12516. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] =
  12517. {
  12518. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  12519. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  12520. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  12521. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2
  12522. };
  12523. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  12524. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  12525. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  12526. };
  12527. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  12528. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  12529. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  12530. };
  12531. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  12532. if (ret != 0)
  12533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12534. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 2);
  12535. ret = wc_AesCbcEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE);
  12536. #if defined(WOLFSSL_ASYNC_CRYPT)
  12537. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12538. #endif
  12539. if (ret != 0)
  12540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12541. #ifndef HAVE_RENESAS_SYNC
  12542. if (XMEMCMP(cipher, verify2, AES_BLOCK_SIZE))
  12543. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12544. #endif
  12545. ret = wc_AesCbcEncrypt(enc, cipher + AES_BLOCK_SIZE,
  12546. msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12547. #if defined(WOLFSSL_ASYNC_CRYPT)
  12548. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12549. #endif
  12550. if (ret != 0)
  12551. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12552. if (XMEMCMP(cipher + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE,
  12553. AES_BLOCK_SIZE))
  12554. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12555. #if defined(HAVE_AES_DECRYPT)
  12556. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION);
  12557. if (ret != 0)
  12558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12559. XMEMSET(plain, 0, AES_BLOCK_SIZE * 2);
  12560. ret = wc_AesCbcDecrypt(dec, plain, verify2, AES_BLOCK_SIZE);
  12561. #if defined(WOLFSSL_ASYNC_CRYPT)
  12562. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12563. #endif
  12564. if (ret != 0)
  12565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12566. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE))
  12567. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12568. ret = wc_AesCbcDecrypt(dec, plain + AES_BLOCK_SIZE,
  12569. verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12570. #if defined(WOLFSSL_ASYNC_CRYPT)
  12571. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12572. #endif
  12573. if (ret != 0)
  12574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12575. if (XMEMCMP(plain + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE,
  12576. AES_BLOCK_SIZE)) {
  12577. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare");
  12578. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12579. }
  12580. #endif /* HAVE_AES_DECRYPT */
  12581. aes_cbc_oneshot_test();
  12582. }
  12583. #endif /* WOLFSSL_AES_128 && !HAVE_RENESAS_SYNC */
  12584. out:
  12585. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12586. wc_AesDelete(enc, &enc);
  12587. #else
  12588. wc_AesFree(enc);
  12589. #endif
  12590. #ifdef HAVE_AES_DECRYPT
  12591. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12592. wc_AesDelete(dec, &dec);
  12593. #else
  12594. wc_AesFree(dec);
  12595. #endif
  12596. #endif
  12597. return ret;
  12598. }
  12599. #endif /* HAVE_AES_CBC */
  12600. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12601. static wc_test_ret_t aes_ecb_direct_test(void)
  12602. {
  12603. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12604. Aes *enc = NULL;
  12605. #else
  12606. Aes enc[1];
  12607. #endif
  12608. #if !defined(HAVE_AES_DECRYPT) || \
  12609. (defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC))
  12610. Aes *dec = NULL;
  12611. #else
  12612. Aes dec[1];
  12613. #endif
  12614. byte cipher[AES_BLOCK_SIZE];
  12615. byte plain [AES_BLOCK_SIZE];
  12616. wc_test_ret_t ret = 0;
  12617. WOLFSSL_ENTER("aes_ecb/direct_test");
  12618. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  12619. XMEMSET(enc, 0, sizeof(Aes));
  12620. #ifdef HAVE_AES_DECRYPT
  12621. XMEMSET(dec, 0, sizeof(Aes));
  12622. #endif
  12623. #endif
  12624. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12625. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12626. if (enc == NULL)
  12627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12628. #ifdef HAVE_AES_DECRYPT
  12629. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12630. if (dec == NULL)
  12631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12632. #endif
  12633. #else
  12634. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12635. if (ret != 0)
  12636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12637. #ifdef HAVE_AES_DECRYPT
  12638. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12639. if (ret != 0)
  12640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12641. #endif
  12642. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12643. #ifdef HAVE_AES_ECB
  12644. ret = aes_ecb_test(enc, dec, cipher, plain);
  12645. if (ret != 0)
  12646. return ret;
  12647. #endif
  12648. #ifdef WOLFSSL_AES_DIRECT
  12649. ret = aes_direct_test(enc, dec, cipher, plain);
  12650. if (ret != 0)
  12651. return ret;
  12652. #endif
  12653. out:
  12654. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12655. wc_AesDelete(enc, &enc);
  12656. wc_AesDelete(dec, &dec);
  12657. #else
  12658. wc_AesFree(enc);
  12659. wc_AesFree(dec);
  12660. #endif
  12661. return ret;
  12662. }
  12663. #endif /* HAVE_AES_ECB || WOLFSSL_AES_DIRECT */
  12664. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
  12665. {
  12666. wc_test_ret_t ret = 0;
  12667. WOLFSSL_ENTER("aes_test");
  12668. #ifndef HAVE_RENESAS_SYNC
  12669. ret = aes_key_size_test();
  12670. if (ret != 0)
  12671. goto out;
  12672. #endif
  12673. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12674. ret = aes_ecb_direct_test();
  12675. if (ret != 0)
  12676. return ret;
  12677. #endif
  12678. out:
  12679. return ret;
  12680. }
  12681. #if defined(WOLFSSL_AES_CFB)
  12682. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
  12683. {
  12684. int ret;
  12685. WOLFSSL_ENTER("aes_cfb_test");
  12686. ret = aescfb_test_0();
  12687. if (ret != 0)
  12688. return ret;
  12689. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  12690. ret = aescfb1_test();
  12691. if (ret != 0)
  12692. return ret;
  12693. ret = aescfb8_test();
  12694. if (ret != 0)
  12695. return ret;
  12696. #endif
  12697. return 0;
  12698. }
  12699. #endif
  12700. #if defined(WOLFSSL_AES_XTS)
  12701. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void)
  12702. {
  12703. int ret = 0;
  12704. WOLFSSL_ENTER("aes_xts_test");
  12705. #ifdef WOLFSSL_AES_128
  12706. ret = aes_xts_128_test();
  12707. if (ret != 0)
  12708. return ret;
  12709. #endif
  12710. #ifdef WOLFSSL_AES_192
  12711. ret = aes_xts_192_test();
  12712. if (ret != 0)
  12713. return ret;
  12714. #endif
  12715. #ifdef WOLFSSL_AES_256
  12716. ret = aes_xts_256_test();
  12717. if (ret != 0)
  12718. return ret;
  12719. #endif
  12720. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  12721. ret = aes_xts_sector_test();
  12722. if (ret != 0)
  12723. return ret;
  12724. #endif
  12725. #ifdef WOLFSSL_AES_128
  12726. ret = aes_xts_args_test();
  12727. if (ret != 0)
  12728. return ret;
  12729. #endif
  12730. return 0;
  12731. }
  12732. #endif
  12733. #ifdef WOLFSSL_AES_192
  12734. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
  12735. {
  12736. wc_test_ret_t ret = 0;
  12737. #ifdef HAVE_AES_CBC
  12738. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12739. Aes *enc = NULL;
  12740. #else
  12741. Aes enc[1];
  12742. #endif
  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. byte plain[AES_BLOCK_SIZE];
  12751. #endif
  12752. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  12753. * Appendix F.2.3 */
  12754. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12755. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12756. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12757. };
  12758. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12759. {
  12760. 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  12761. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8
  12762. };
  12763. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12764. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  12765. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  12766. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  12767. };
  12768. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12769. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12770. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12771. };
  12772. WOLFSSL_ENTER("aes192_test");
  12773. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12774. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12775. if (enc == NULL)
  12776. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12777. #ifdef HAVE_AES_DECRYPT
  12778. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12779. if (dec == NULL)
  12780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12781. #endif
  12782. #else
  12783. XMEMSET(enc, 0, sizeof(Aes));
  12784. #ifdef HAVE_AES_DECRYPT
  12785. XMEMSET(dec, 0, sizeof(Aes));
  12786. #endif
  12787. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12788. if (ret != 0)
  12789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12790. #ifdef HAVE_AES_DECRYPT
  12791. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12792. if (ret != 0)
  12793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12794. #endif
  12795. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12796. ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
  12797. if (ret != 0)
  12798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12799. #ifdef HAVE_AES_DECRYPT
  12800. ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
  12801. if (ret != 0)
  12802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12803. #endif
  12804. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12805. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12806. #if defined(WOLFSSL_ASYNC_CRYPT)
  12807. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12808. #endif
  12809. if (ret != 0)
  12810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12811. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12812. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12813. #ifdef HAVE_AES_DECRYPT
  12814. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12815. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12816. #if defined(WOLFSSL_ASYNC_CRYPT)
  12817. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12818. #endif
  12819. if (ret != 0)
  12820. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12821. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12822. WOLFSSL_MSG("failed wc_AesCbcDecrypt plain-msg compare");
  12823. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12824. }
  12825. #endif
  12826. out:
  12827. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12828. wc_AesDelete(enc, &enc);
  12829. #else
  12830. wc_AesFree(enc);
  12831. #endif
  12832. #ifdef HAVE_AES_DECRYPT
  12833. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12834. wc_AesDelete(dec, &dec);
  12835. #else
  12836. wc_AesFree(dec);
  12837. #endif
  12838. #endif
  12839. #endif /* HAVE_AES_CBC */
  12840. return ret;
  12841. }
  12842. #endif /* WOLFSSL_AES_192 */
  12843. #ifdef WOLFSSL_AES_256
  12844. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
  12845. {
  12846. #ifdef HAVE_AES_CBC
  12847. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12848. Aes *enc = NULL;
  12849. #else
  12850. Aes enc[1];
  12851. #endif
  12852. byte cipher[AES_BLOCK_SIZE];
  12853. #ifdef HAVE_AES_DECRYPT
  12854. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12855. Aes *dec = NULL;
  12856. #else
  12857. Aes dec[1];
  12858. #endif
  12859. byte plain[AES_BLOCK_SIZE];
  12860. #endif
  12861. #endif /* HAVE_AES_CBC */
  12862. wc_test_ret_t ret = 0;
  12863. #ifdef HAVE_AES_CBC
  12864. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  12865. * Appendix F.2.5 */
  12866. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12867. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12868. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12869. };
  12870. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12871. {
  12872. 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  12873. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6
  12874. };
  12875. #ifdef HAVE_RENESAS_SYNC
  12876. byte *key =
  12877. (byte*)guser_PKCbInfo.wrapped_key_aes256;
  12878. int keySz = (256/8);
  12879. #else
  12880. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12881. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12882. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12883. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12884. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12885. };
  12886. int keySz = (int)sizeof(key);
  12887. #endif
  12888. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12889. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12890. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12891. };
  12892. WOLFSSL_ENTER("aes256_test");
  12893. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12894. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12895. if (enc == NULL)
  12896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12897. #ifdef HAVE_AES_DECRYPT
  12898. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12899. if (dec == NULL)
  12900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12901. #endif
  12902. #else
  12903. XMEMSET(enc, 0, sizeof(Aes));
  12904. #ifdef HAVE_AES_DECRYPT
  12905. XMEMSET(dec, 0, sizeof(Aes));
  12906. #endif
  12907. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12908. if (ret != 0)
  12909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12910. #ifdef HAVE_AES_DECRYPT
  12911. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12912. if (ret != 0)
  12913. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12914. #endif
  12915. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12916. ret = wc_AesSetKey(enc, key, (word32)keySz, iv, AES_ENCRYPTION);
  12917. if (ret != 0)
  12918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12919. #ifdef HAVE_AES_DECRYPT
  12920. ret = wc_AesSetKey(dec, key, (word32)keySz, iv, AES_DECRYPTION);
  12921. if (ret != 0)
  12922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12923. #endif
  12924. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12925. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12926. #if defined(WOLFSSL_ASYNC_CRYPT)
  12927. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12928. #endif
  12929. if (ret != 0)
  12930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12931. #ifdef HAVE_AES_DECRYPT
  12932. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12933. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12934. #if defined(WOLFSSL_ASYNC_CRYPT)
  12935. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12936. #endif
  12937. if (ret != 0)
  12938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12939. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12940. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12941. }
  12942. #endif
  12943. #ifndef HAVE_RENESAS_SYNC
  12944. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12945. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12946. #endif
  12947. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12948. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12949. if (ret != 0)
  12950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12951. #ifdef HAVE_AES_DECRYPT
  12952. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12953. if (ret != 0)
  12954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12955. #endif
  12956. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12957. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12958. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12959. #if defined(WOLFSSL_ASYNC_CRYPT)
  12960. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12961. #endif
  12962. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12963. if (ret != 0)
  12964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12965. #ifdef HAVE_AES_DECRYPT
  12966. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12967. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12968. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12969. #if defined(WOLFSSL_ASYNC_CRYPT)
  12970. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12971. #endif
  12972. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12973. if (ret != 0)
  12974. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12975. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12976. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12977. }
  12978. #endif
  12979. #ifndef HAVE_RENESAS_SYNC
  12980. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12981. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12982. #endif
  12983. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12984. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12985. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12986. if (ret != 0)
  12987. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12988. #ifdef HAVE_AES_DECRYPT
  12989. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12990. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12991. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12992. if (ret != 0)
  12993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12994. #endif
  12995. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12996. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12997. #if defined(WOLFSSL_ASYNC_CRYPT)
  12998. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12999. #endif
  13000. if (ret != 0)
  13001. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13002. #ifdef HAVE_AES_DECRYPT
  13003. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  13004. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  13005. #if defined(WOLFSSL_ASYNC_CRYPT)
  13006. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13007. #endif
  13008. if (ret != 0)
  13009. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13010. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  13011. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13012. }
  13013. #endif
  13014. #ifndef HAVE_RENESAS_SYNC
  13015. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  13016. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13017. #endif
  13018. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  13019. out:
  13020. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13021. wc_AesDelete(enc, &enc);
  13022. #else
  13023. wc_AesFree(enc);
  13024. #endif
  13025. #ifdef HAVE_AES_DECRYPT
  13026. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13027. wc_AesDelete(dec, &dec);
  13028. #else
  13029. wc_AesFree(dec);
  13030. #endif
  13031. #endif
  13032. #endif /* HAVE_AES_CBC */
  13033. return ret;
  13034. }
  13035. #endif /* WOLFSSL_AES_256 */
  13036. #ifdef HAVE_AESGCM
  13037. #ifdef WOLFSSL_AES_128
  13038. static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
  13039. byte* plain, int plainSz, byte* cipher, int cipherSz,
  13040. byte* aad, int aadSz, byte* tag, int tagSz)
  13041. {
  13042. wc_test_ret_t ret;
  13043. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13044. Aes *enc = NULL;
  13045. Aes *dec = NULL;
  13046. #else
  13047. Aes enc[1];
  13048. Aes dec[1];
  13049. #endif
  13050. byte resultT[AES_BLOCK_SIZE];
  13051. byte resultP[AES_BLOCK_SIZE * 3];
  13052. byte resultC[AES_BLOCK_SIZE * 3];
  13053. XMEMSET(resultT, 0, sizeof(resultT));
  13054. XMEMSET(resultC, 0, sizeof(resultC));
  13055. XMEMSET(resultP, 0, sizeof(resultP));
  13056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13057. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13058. if (enc == NULL)
  13059. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13060. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13061. if (dec == NULL)
  13062. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13063. #else
  13064. XMEMSET(enc, 0, sizeof(Aes));
  13065. XMEMSET(dec, 0, sizeof(Aes));
  13066. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13067. if (ret != 0)
  13068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13069. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13070. if (ret != 0)
  13071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13072. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  13073. ret = wc_AesGcmSetKey(enc, key, (word32)keySz);
  13074. if (ret != 0)
  13075. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13076. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13077. ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, (word32)ivSz,
  13078. resultT, (word32)tagSz, aad, (word32)aadSz);
  13079. #if defined(WOLFSSL_ASYNC_CRYPT)
  13080. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13081. #endif
  13082. if (ret != 0)
  13083. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13084. if (cipher != NULL) {
  13085. if (XMEMCMP(cipher, resultC, (word32)cipherSz))
  13086. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13087. }
  13088. if (XMEMCMP(tag, resultT, (unsigned long)tagSz))
  13089. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13090. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13091. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13092. ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz,
  13093. resultT, tagSz, aad, aadSz);
  13094. #if defined(WOLFSSL_ASYNC_CRYPT)
  13095. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13096. #endif
  13097. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13098. if (ret != 0)
  13099. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13100. if (cipher != NULL) {
  13101. if (XMEMCMP(cipher, resultC, (unsigned long)cipherSz))
  13102. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13103. }
  13104. if (XMEMCMP(tag, resultT, tagSz))
  13105. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13106. #endif
  13107. #ifdef HAVE_AES_DECRYPT
  13108. ret = wc_AesGcmSetKey(dec, key, (word32)keySz);
  13109. if (ret != 0)
  13110. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13111. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz,
  13112. iv, (word32)ivSz, resultT, (word32)tagSz, aad, (word32)aadSz);
  13113. #if defined(WOLFSSL_ASYNC_CRYPT)
  13114. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13115. #endif
  13116. if (ret != 0)
  13117. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13118. if (plain != NULL) {
  13119. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13120. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13121. }
  13122. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13123. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13124. ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz,
  13125. iv, ivSz, resultT, tagSz, aad, aadSz);
  13126. #if defined(WOLFSSL_ASYNC_CRYPT)
  13127. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13128. #endif
  13129. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13130. if (ret != 0)
  13131. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13132. if (plain != NULL) {
  13133. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13134. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13135. }
  13136. #endif
  13137. #endif /* HAVE_AES_DECRYPT */
  13138. ret = 0;
  13139. out:
  13140. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13141. wc_AesDelete(enc, &enc);
  13142. wc_AesDelete(dec, &dec);
  13143. #else
  13144. wc_AesFree(enc);
  13145. wc_AesFree(dec);
  13146. #endif
  13147. return ret;
  13148. }
  13149. #endif
  13150. /* tests that only use 12 byte IV and 16 or less byte AAD
  13151. * test vectors are from NIST SP 800-38D
  13152. * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES*/
  13153. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void)
  13154. {
  13155. #ifdef WOLFSSL_AES_128
  13156. byte key1[] = {
  13157. 0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62,
  13158. 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc
  13159. };
  13160. byte iv1[] = {
  13161. 0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa,
  13162. 0xe4, 0xed, 0x2f, 0x6d
  13163. };
  13164. ALIGN64 byte plain1[] = {
  13165. 0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad,
  13166. 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01,
  13167. 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac,
  13168. 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01
  13169. };
  13170. byte aad1[] = {
  13171. 0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73,
  13172. 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1
  13173. };
  13174. ALIGN64 byte cipher1[] = {
  13175. 0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d,
  13176. 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d,
  13177. 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46,
  13178. 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb
  13179. };
  13180. byte tag1[] = {
  13181. 0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7,
  13182. 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2
  13183. };
  13184. byte key2[] = {
  13185. 0x01, 0x6d, 0xbb, 0x38, 0xda, 0xa7, 0x6d, 0xfe,
  13186. 0x7d, 0xa3, 0x84, 0xeb, 0xf1, 0x24, 0x03, 0x64
  13187. };
  13188. byte iv2[] = {
  13189. 0x07, 0x93, 0xef, 0x3a, 0xda, 0x78, 0x2f, 0x78,
  13190. 0xc9, 0x8a, 0xff, 0xe3
  13191. };
  13192. ALIGN64 byte plain2[] = {
  13193. 0x4b, 0x34, 0xa9, 0xec, 0x57, 0x63, 0x52, 0x4b,
  13194. 0x19, 0x1d, 0x56, 0x16, 0xc5, 0x47, 0xf6, 0xb7
  13195. };
  13196. ALIGN64 byte cipher2[] = {
  13197. 0x60, 0x9a, 0xa3, 0xf4, 0x54, 0x1b, 0xc0, 0xfe,
  13198. 0x99, 0x31, 0xda, 0xad, 0x2e, 0xe1, 0x5d, 0x0c
  13199. };
  13200. byte tag2[] = {
  13201. 0x33, 0xaf, 0xec, 0x59, 0xc4, 0x5b, 0xaf, 0x68,
  13202. 0x9a, 0x5e, 0x1b, 0x13, 0xae, 0x42, 0x36, 0x19
  13203. };
  13204. byte key3[] = {
  13205. 0xb0, 0x1e, 0x45, 0xcc, 0x30, 0x88, 0xaa, 0xba,
  13206. 0x9f, 0xa4, 0x3d, 0x81, 0xd4, 0x81, 0x82, 0x3f
  13207. };
  13208. byte iv3[] = {
  13209. 0x5a, 0x2c, 0x4a, 0x66, 0x46, 0x87, 0x13, 0x45,
  13210. 0x6a, 0x4b, 0xd5, 0xe1
  13211. };
  13212. byte tag3[] = {
  13213. 0x01, 0x42, 0x80, 0xf9, 0x44, 0xf5, 0x3c, 0x68,
  13214. 0x11, 0x64, 0xb2, 0xff
  13215. };
  13216. wc_test_ret_t ret;
  13217. WOLFSSL_ENTER("aesgcm_default_test");
  13218. ret = aesgcm_default_test_helper(key1, sizeof(key1), iv1, sizeof(iv1),
  13219. plain1, sizeof(plain1), cipher1, sizeof(cipher1),
  13220. aad1, sizeof(aad1), tag1, sizeof(tag1));
  13221. if (ret != 0) {
  13222. return ret;
  13223. }
  13224. ret = aesgcm_default_test_helper(key2, sizeof(key2), iv2, sizeof(iv2),
  13225. plain2, sizeof(plain2), cipher2, sizeof(cipher2),
  13226. NULL, 0, tag2, sizeof(tag2));
  13227. if (ret != 0) {
  13228. return ret;
  13229. }
  13230. ret = aesgcm_default_test_helper(key3, sizeof(key3), iv3, sizeof(iv3),
  13231. NULL, 0, NULL, 0,
  13232. NULL, 0, tag3, sizeof(tag3));
  13233. if (ret != 0) {
  13234. return ret;
  13235. }
  13236. #endif
  13237. return 0;
  13238. }
  13239. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
  13240. {
  13241. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13242. Aes *enc = NULL;
  13243. Aes *dec = NULL;
  13244. #else
  13245. Aes enc[1];
  13246. Aes dec[1];
  13247. #endif
  13248. /*
  13249. * This is Test Case 16 from the document Galois/
  13250. * Counter Mode of Operation (GCM) by McGrew and
  13251. * Viega.
  13252. */
  13253. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  13254. {
  13255. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  13256. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  13257. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  13258. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  13259. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  13260. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  13261. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  13262. 0xba, 0x63, 0x7b, 0x39
  13263. };
  13264. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  13265. {
  13266. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13267. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13268. 0xab, 0xad, 0xda, 0xd2
  13269. };
  13270. #ifdef WOLFSSL_AES_256
  13271. #ifdef HAVE_RENESAS_SYNC
  13272. const byte *k1 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  13273. int k1Sz = (int)(256/8);
  13274. #else
  13275. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13276. {
  13277. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13278. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13279. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13280. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  13281. };
  13282. int k1Sz = (int)sizeof(k1);
  13283. #endif
  13284. #endif /* WOLFSSL_AES_256 */
  13285. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13286. {
  13287. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  13288. 0xde, 0xca, 0xf8, 0x88
  13289. };
  13290. #if defined(WOLFSSL_AES_256) || defined(WOLFSSL_AES_192)
  13291. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  13292. {
  13293. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  13294. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  13295. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  13296. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  13297. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  13298. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  13299. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  13300. 0xbc, 0xc9, 0xf6, 0x62
  13301. };
  13302. #endif /* WOLFSSL_AES_256 || WOLFSSL_AES_192 */
  13303. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13304. {
  13305. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  13306. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  13307. };
  13308. /* FIPS, QAT and PIC32MZ HW Crypto only support 12-byte IV */
  13309. #if !defined(HAVE_FIPS) && \
  13310. !defined(WOLFSSL_PIC32MZ_CRYPT) && \
  13311. !defined(FREESCALE_LTC) && !defined(FREESCALE_MMCAU) && \
  13312. !defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13313. !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_AES) && \
  13314. !(defined(WOLF_CRYPTO_CB) && \
  13315. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  13316. #define ENABLE_NON_12BYTE_IV_TEST
  13317. #ifdef WOLFSSL_AES_192
  13318. /* Test Case 12, uses same plaintext and AAD data. */
  13319. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13320. {
  13321. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13322. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13323. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  13324. };
  13325. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13326. {
  13327. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  13328. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  13329. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  13330. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  13331. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  13332. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  13333. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  13334. 0xa6, 0x37, 0xb3, 0x9b
  13335. };
  13336. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  13337. {
  13338. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  13339. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  13340. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  13341. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  13342. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  13343. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  13344. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  13345. 0xe9, 0xb7, 0x37, 0x3b
  13346. };
  13347. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13348. {
  13349. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  13350. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  13351. };
  13352. #endif /* WOLFSSL_AES_192 */
  13353. #ifdef WOLFSSL_AES_128
  13354. /* The following is an interesting test case from the example
  13355. * FIPS test vectors for AES-GCM. IVlen = 1 byte */
  13356. WOLFSSL_SMALL_STACK_STATIC const byte p3[] =
  13357. {
  13358. 0x57, 0xce, 0x45, 0x1f, 0xa5, 0xe2, 0x35, 0xa5,
  13359. 0x8e, 0x1a, 0xa2, 0x3b, 0x77, 0xcb, 0xaf, 0xe2
  13360. };
  13361. #ifdef HAVE_RENESAS_SYNC
  13362. const byte *k3 =
  13363. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  13364. int k3Sz = (int)(128/8);
  13365. #else
  13366. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  13367. {
  13368. 0xbb, 0x01, 0xd7, 0x03, 0x81, 0x1c, 0x10, 0x1a,
  13369. 0x35, 0xe0, 0xff, 0xd2, 0x91, 0xba, 0xf2, 0x4b
  13370. };
  13371. int k3Sz = (int)sizeof(k3);
  13372. #endif
  13373. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  13374. {
  13375. 0xca
  13376. };
  13377. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  13378. {
  13379. 0x6b, 0x5f, 0xb3, 0x9d, 0xc1, 0xc5, 0x7a, 0x4f,
  13380. 0xf3, 0x51, 0x4d, 0xc2, 0xd5, 0xf0, 0xd0, 0x07
  13381. };
  13382. WOLFSSL_SMALL_STACK_STATIC const byte a3[] =
  13383. {
  13384. 0x40, 0xfc, 0xdc, 0xd7, 0x4a, 0xd7, 0x8b, 0xf1,
  13385. 0x3e, 0x7c, 0x60, 0x55, 0x50, 0x51, 0xdd, 0x54
  13386. };
  13387. WOLFSSL_SMALL_STACK_STATIC const byte t3[] =
  13388. {
  13389. 0x06, 0x90, 0xed, 0x01, 0x34, 0xdd, 0xc6, 0x95,
  13390. 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
  13391. };
  13392. #endif /* WOLFSSL_AES_128 */
  13393. #ifdef WOLFSSL_AES_256
  13394. int ivlen;
  13395. #endif
  13396. #endif
  13397. byte resultT[sizeof(t1) + AES_BLOCK_SIZE];
  13398. byte resultP[sizeof(p) + AES_BLOCK_SIZE];
  13399. byte resultC[sizeof(p) + AES_BLOCK_SIZE];
  13400. wc_test_ret_t ret = 0;
  13401. int alen = 0;
  13402. int plen = 0;
  13403. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13404. byte buf[sizeof(p) + AES_BLOCK_SIZE];
  13405. byte bufA[sizeof(a) + 1];
  13406. byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13407. #endif
  13408. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM)
  13409. #if !defined(BENCH_AESGCM_LARGE)
  13410. #define BENCH_AESGCM_LARGE 1024
  13411. #endif
  13412. #ifndef WOLFSSL_NO_MALLOC
  13413. byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13414. byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13415. byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13416. (void)alen;
  13417. (void)plen;
  13418. if ((! large_input) || (! large_output) || (! large_outdec))
  13419. ERROR_OUT(MEMORY_E, out);
  13420. #else
  13421. byte large_input[BENCH_AESGCM_LARGE];
  13422. byte large_output[BENCH_AESGCM_LARGE + AES_BLOCK_SIZE];
  13423. byte large_outdec[BENCH_AESGCM_LARGE];
  13424. #endif
  13425. XMEMSET(large_input, 0, BENCH_AESGCM_LARGE);
  13426. XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + AES_BLOCK_SIZE);
  13427. XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE);
  13428. #endif
  13429. WOLFSSL_ENTER("aesgcm_test");
  13430. XMEMSET(resultT, 0, sizeof(resultT));
  13431. XMEMSET(resultC, 0, sizeof(resultC));
  13432. XMEMSET(resultP, 0, sizeof(resultP));
  13433. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13434. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13435. if (enc == NULL)
  13436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13437. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13438. if (dec == NULL)
  13439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13440. #else
  13441. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13442. if (ret != 0)
  13443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13444. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13445. if (ret != 0)
  13446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13447. #endif
  13448. #ifdef WOLFSSL_AES_256
  13449. ret = wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13450. if (ret != 0)
  13451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13452. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13453. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13454. resultT, sizeof(t1), a, sizeof(a));
  13455. #if defined(WOLFSSL_ASYNC_CRYPT)
  13456. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13457. #endif
  13458. if (ret != 0)
  13459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13460. #ifndef HAVE_RENESAS_SYNC
  13461. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13462. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13463. if (XMEMCMP(t1, resultT, sizeof(t1)))
  13464. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13465. #endif
  13466. #ifdef HAVE_AES_DECRYPT
  13467. ret = wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13468. if (ret != 0)
  13469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13470. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
  13471. iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13472. #if defined(WOLFSSL_ASYNC_CRYPT)
  13473. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13474. #endif
  13475. if (ret != 0)
  13476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13477. if (XMEMCMP(p, resultP, sizeof(p)))
  13478. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13479. #endif /* HAVE_AES_DECRYPT */
  13480. /* Large buffer test */
  13481. #ifdef BENCH_AESGCM_LARGE
  13482. /* setup test buffer */
  13483. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13484. large_input[alen] = (byte)alen;
  13485. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13486. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13487. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13488. resultT, sizeof(t1), a, sizeof(a));
  13489. #if defined(WOLFSSL_ASYNC_CRYPT)
  13490. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13491. #endif
  13492. if (ret != 0)
  13493. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13494. #ifdef HAVE_AES_DECRYPT
  13495. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13496. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13497. sizeof(t1), a, sizeof(a));
  13498. #if defined(WOLFSSL_ASYNC_CRYPT)
  13499. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13500. #endif
  13501. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13502. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13503. if (ret != 0)
  13504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13505. #endif /* HAVE_AES_DECRYPT */
  13506. #endif /* BENCH_AESGCM_LARGE */
  13507. #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256)
  13508. /* Variable IV length test */
  13509. for (ivlen=1; ivlen<k1Sz; ivlen++) {
  13510. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13511. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1,
  13512. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13513. #if defined(WOLFSSL_ASYNC_CRYPT)
  13514. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13515. #endif
  13516. if (ret != 0)
  13517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13518. #ifdef HAVE_AES_DECRYPT
  13519. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1,
  13520. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13521. #if defined(WOLFSSL_ASYNC_CRYPT)
  13522. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13523. #endif
  13524. if (ret != 0)
  13525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13526. #endif /* HAVE_AES_DECRYPT */
  13527. }
  13528. #endif
  13529. #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC))
  13530. /* Variable authenticated data length test */
  13531. for (alen=0; alen<(int)sizeof(p); alen++) {
  13532. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13533. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13534. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13535. #if defined(WOLFSSL_ASYNC_CRYPT)
  13536. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13537. #endif
  13538. if (ret != 0)
  13539. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13540. #ifdef HAVE_AES_DECRYPT
  13541. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13542. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13543. #if defined(WOLFSSL_ASYNC_CRYPT)
  13544. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13545. #endif
  13546. if (ret != 0)
  13547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13548. #endif /* HAVE_AES_DECRYPT */
  13549. }
  13550. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13551. if (! large_aad)
  13552. ERROR_OUT(MEMORY_E, out);
  13553. XMEMSET(large_aad, 0, 1024+16);
  13554. /* Variable authenticated data length test */
  13555. for (alen=0; alen<=1024; alen+=16) {
  13556. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13557. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13558. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13559. if (ret != 0)
  13560. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13561. #ifdef HAVE_AES_DECRYPT
  13562. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13563. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13564. if (ret != 0)
  13565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13566. #endif /* HAVE_AES_DECRYPT */
  13567. }
  13568. /* Test unaligned memory of all potential arguments */
  13569. ret = wc_AesGcmSetKey(enc, k1, k1Sz);
  13570. if (ret != 0)
  13571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13572. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13573. XMEMCPY(&buf[1], p, sizeof(p));
  13574. XMEMCPY(&bufA[1], a, sizeof(a));
  13575. ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1),
  13576. &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13577. if (ret != 0)
  13578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13579. if (XMEMCMP(c1, &resultC[1], sizeof(c1)))
  13580. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13581. if (XMEMCMP(t1, &resultT[1], sizeof(t1)))
  13582. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13583. #ifdef HAVE_AES_DECRYPT
  13584. ret = wc_AesGcmSetKey(dec, k1, k1Sz);
  13585. if (ret != 0)
  13586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13587. ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1),
  13588. iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13589. if (ret != 0)
  13590. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13591. if (XMEMCMP(p, &resultP[1], sizeof(p)))
  13592. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13593. #endif /* HAVE_AES_DECRYPT */
  13594. #endif /* Xilinx Versal */
  13595. #endif
  13596. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13597. #ifdef BENCH_AESGCM_LARGE
  13598. /* Variable plain text length test */
  13599. for (plen=1; plen<BENCH_AESGCM_LARGE; plen++) {
  13600. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13601. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13602. (word32)plen, iv1, sizeof(iv1), resultT,
  13603. sizeof(t1), a, sizeof(a));
  13604. #if defined(WOLFSSL_ASYNC_CRYPT)
  13605. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13606. #endif
  13607. if (ret != 0)
  13608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13609. #ifdef HAVE_AES_DECRYPT
  13610. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13611. (word32)plen, iv1, sizeof(iv1), resultT,
  13612. sizeof(t1), a, sizeof(a));
  13613. #if defined(WOLFSSL_ASYNC_CRYPT)
  13614. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13615. #endif
  13616. if (ret != 0)
  13617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13618. #endif /* HAVE_AES_DECRYPT */
  13619. }
  13620. #else /* BENCH_AESGCM_LARGE */
  13621. /* Variable plain text length test */
  13622. for (plen=1; plen<(int)sizeof(p); plen++) {
  13623. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13624. ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1,
  13625. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13626. #if defined(WOLFSSL_ASYNC_CRYPT)
  13627. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13628. #endif
  13629. if (ret != 0)
  13630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13631. #ifdef HAVE_AES_DECRYPT
  13632. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1,
  13633. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13634. #if defined(WOLFSSL_ASYNC_CRYPT)
  13635. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13636. #endif
  13637. if (ret != 0)
  13638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13639. #endif /* HAVE_AES_DECRYPT */
  13640. }
  13641. #endif /* BENCH_AESGCM_LARGE */
  13642. #endif
  13643. #endif /* WOLFSSL_AES_256 */
  13644. /* test with IV != 12 bytes */
  13645. #ifdef ENABLE_NON_12BYTE_IV_TEST
  13646. XMEMSET(resultT, 0, sizeof(resultT));
  13647. XMEMSET(resultC, 0, sizeof(resultC));
  13648. XMEMSET(resultP, 0, sizeof(resultP));
  13649. #ifdef WOLFSSL_AES_192
  13650. wc_AesGcmSetKey(enc, k2, sizeof(k2));
  13651. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13652. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2),
  13653. resultT, sizeof(t1), a, sizeof(a));
  13654. #if defined(WOLFSSL_ASYNC_CRYPT)
  13655. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13656. #endif
  13657. if (ret != 0)
  13658. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13659. if (XMEMCMP(c2, resultC, sizeof(c2)))
  13660. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13661. if (XMEMCMP(t2, resultT, sizeof(t1)))
  13662. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13663. #ifdef HAVE_AES_DECRYPT
  13664. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1),
  13665. iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a));
  13666. #if defined(WOLFSSL_ASYNC_CRYPT)
  13667. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13668. #endif
  13669. if (ret != 0)
  13670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13671. if (XMEMCMP(p, resultP, sizeof(p)))
  13672. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13673. #endif /* HAVE_AES_DECRYPT */
  13674. /* Large buffer test */
  13675. #ifdef BENCH_AESGCM_LARGE
  13676. wc_AesGcmSetKey(enc, k2, (word32)sizeof(k2));
  13677. wc_AesGcmSetKey(dec, k2, (word32)sizeof(k2));
  13678. /* setup test buffer */
  13679. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13680. large_input[alen] = (byte)alen;
  13681. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13682. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13683. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13684. resultT, sizeof(t1), a, sizeof(a));
  13685. #if defined(WOLFSSL_ASYNC_CRYPT)
  13686. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13687. #endif
  13688. if (ret != 0)
  13689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13690. #ifdef HAVE_AES_DECRYPT
  13691. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13692. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13693. sizeof(t1), a, sizeof(a));
  13694. #if defined(WOLFSSL_ASYNC_CRYPT)
  13695. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13696. #endif
  13697. if (ret != 0)
  13698. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13699. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13700. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13701. #endif /* HAVE_AES_DECRYPT */
  13702. #endif /* BENCH_AESGCM_LARGE */
  13703. XMEMSET(resultT, 0, sizeof(resultT));
  13704. XMEMSET(resultC, 0, sizeof(resultC));
  13705. XMEMSET(resultP, 0, sizeof(resultP));
  13706. #endif /* WOLFSSL_AES_192 */
  13707. #ifdef WOLFSSL_AES_128
  13708. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13709. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13710. ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3),
  13711. resultT, sizeof(t3), a3, sizeof(a3));
  13712. #if defined(WOLFSSL_ASYNC_CRYPT)
  13713. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13714. #endif
  13715. if (ret != 0)
  13716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13717. #ifndef HAVE_RENESAS_SYNC
  13718. if (XMEMCMP(c3, resultC, sizeof(c3)))
  13719. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13720. if (XMEMCMP(t3, resultT, sizeof(t3)))
  13721. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13722. #endif
  13723. #ifdef HAVE_AES_DECRYPT
  13724. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
  13725. iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3));
  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. if (XMEMCMP(p3, resultP, sizeof(p3)))
  13732. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13733. #endif /* HAVE_AES_DECRYPT */
  13734. /* Large buffer test */
  13735. #ifdef BENCH_AESGCM_LARGE
  13736. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13737. wc_AesGcmSetKey(dec, k3, (word32)k3Sz);
  13738. /* setup test buffer */
  13739. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13740. large_input[alen] = (byte)alen;
  13741. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13742. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13743. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13744. resultT, sizeof(t1), a, sizeof(a));
  13745. #if defined(WOLFSSL_ASYNC_CRYPT)
  13746. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13747. #endif
  13748. if (ret != 0)
  13749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13750. #ifdef HAVE_AES_DECRYPT
  13751. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13752. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13753. sizeof(t1), a, sizeof(a));
  13754. #if defined(WOLFSSL_ASYNC_CRYPT)
  13755. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13756. #endif
  13757. if (ret != 0)
  13758. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13759. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13760. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13761. #endif /* HAVE_AES_DECRYPT */
  13762. #endif /* BENCH_AESGCM_LARGE */
  13763. #endif /* WOLFSSL_AES_128 */
  13764. #endif /* ENABLE_NON_12BYTE_IV_TEST */
  13765. #if defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13766. !defined(WOLFSSL_XILINX_CRYPT) && \
  13767. !(defined(WOLF_CRYPTO_CB) && \
  13768. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC))
  13769. XMEMSET(resultT, 0, sizeof(resultT));
  13770. XMEMSET(resultC, 0, sizeof(resultC));
  13771. XMEMSET(resultP, 0, sizeof(resultP));
  13772. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13773. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13774. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13775. resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13776. #if defined(WOLFSSL_ASYNC_CRYPT)
  13777. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13778. #endif
  13779. if (ret != 0)
  13780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13781. #ifndef HAVE_RENESAS_SYNC
  13782. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13783. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13784. if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1))
  13785. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13786. #endif
  13787. #ifdef HAVE_AES_DECRYPT
  13788. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
  13789. iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13790. #if defined(WOLFSSL_ASYNC_CRYPT)
  13791. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13792. #endif
  13793. if (ret != 0)
  13794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13795. if (XMEMCMP(p, resultP, sizeof(p)))
  13796. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13797. #endif /* HAVE_AES_DECRYPT */
  13798. #endif /* WOLFSSL_AES_256 */
  13799. #if !defined(HAVE_FIPS) || \
  13800. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  13801. /* Test encrypt with internally generated IV */
  13802. #if defined(WOLFSSL_AES_256) && !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST)) \
  13803. && !(defined(WOLF_CRYPTO_CB) && defined(HAVE_CAVIUM_OCTEON_SYNC))
  13804. {
  13805. WC_RNG rng;
  13806. byte randIV[12];
  13807. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13808. if (ret != 0)
  13809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13810. XMEMSET(randIV, 0, sizeof(randIV));
  13811. XMEMSET(resultT, 0, sizeof(resultT));
  13812. XMEMSET(resultC, 0, sizeof(resultC));
  13813. XMEMSET(resultP, 0, sizeof(resultP));
  13814. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13815. ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng);
  13816. if (ret != 0)
  13817. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13818. ret = wc_AesGcmEncrypt_ex(enc,
  13819. resultC, p, sizeof(p),
  13820. randIV, sizeof(randIV),
  13821. resultT, sizeof(t1),
  13822. a, sizeof(a));
  13823. #if defined(WOLFSSL_ASYNC_CRYPT)
  13824. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13825. #endif
  13826. if (ret != 0)
  13827. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13828. /* Check the IV has been set. */
  13829. {
  13830. word32 i, ivSum = 0;
  13831. for (i = 0; i < sizeof(randIV); i++)
  13832. ivSum += randIV[i];
  13833. if (ivSum == 0)
  13834. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13835. }
  13836. #ifdef HAVE_AES_DECRYPT
  13837. wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13838. ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng);
  13839. if (ret != 0)
  13840. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13841. ret = wc_AesGcmDecrypt(dec,
  13842. resultP, resultC, sizeof(c1),
  13843. randIV, sizeof(randIV),
  13844. resultT, sizeof(t1),
  13845. a, sizeof(a));
  13846. #if defined(WOLFSSL_ASYNC_CRYPT)
  13847. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13848. #endif
  13849. if (ret != 0)
  13850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13851. if (XMEMCMP(p, resultP, sizeof(p)))
  13852. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13853. #endif /* HAVE_AES_DECRYPT */
  13854. wc_FreeRng(&rng);
  13855. }
  13856. #endif /* WOLFSSL_AES_256 && !(WC_NO_RNG || HAVE_SELFTEST) */
  13857. #endif /* HAVE_FIPS_VERSION >= 2 */
  13858. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13859. #ifdef WOLFSSL_AES_256
  13860. #ifdef WOLFSSL_AESGCM_STREAM
  13861. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13862. if (ret != 0)
  13863. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13864. ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a));
  13865. if (ret != 0)
  13866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13867. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13868. if (ret != 0)
  13869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13870. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13871. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13872. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13873. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13874. #ifdef HAVE_AES_DECRYPT
  13875. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13876. if (ret != 0)
  13877. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13878. ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
  13879. if (ret != 0)
  13880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13881. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13882. if (ret != 0)
  13883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13884. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13885. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13886. #endif
  13887. /* alen is the size to pass in with each update. */
  13888. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13889. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13890. if (ret != 0)
  13891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13892. /* plen is the offset into AAD to update with. */
  13893. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13894. int len = sizeof(a) - plen;
  13895. if (len > alen) len = alen;
  13896. ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13897. if (ret != 0)
  13898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13899. }
  13900. /* plen is the offset into plaintext to update with. */
  13901. for (plen = 0; plen < (int)sizeof(p); plen += alen) {
  13902. int len = sizeof(p) - plen;
  13903. if (len > alen) len = alen;
  13904. ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, (word32)len,
  13905. NULL, 0);
  13906. if (ret != 0)
  13907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13908. }
  13909. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13910. if (ret != 0)
  13911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13912. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13913. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13914. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13915. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13916. }
  13917. #ifdef HAVE_AES_DECRYPT
  13918. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13919. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13920. if (ret != 0)
  13921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13922. /* plen is the offset into AAD to update with. */
  13923. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13924. int len = sizeof(a) - plen;
  13925. if (len > alen) len = alen;
  13926. ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13927. if (ret != 0)
  13928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13929. }
  13930. /* plen is the offset into cipher text to update with. */
  13931. for (plen = 0; plen < (int)sizeof(c1); plen += alen) {
  13932. int len = sizeof(c1) - plen;
  13933. if (len > alen) len = alen;
  13934. ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, (word32)len,
  13935. NULL, 0);
  13936. if (ret != 0)
  13937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13938. }
  13939. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13940. if (ret != 0)
  13941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13942. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13944. }
  13945. #endif /* HAVE_AES_DECRYPT */
  13946. #ifdef BENCH_AESGCM_LARGE
  13947. /* setup test buffer */
  13948. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13949. if (ret != 0)
  13950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13951. ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input,
  13952. BENCH_AESGCM_LARGE, a, sizeof(a));
  13953. if (ret != 0)
  13954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13955. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13956. if (ret != 0)
  13957. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13958. #ifdef HAVE_AES_DECRYPT
  13959. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13960. if (ret != 0)
  13961. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13962. ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output,
  13963. BENCH_AESGCM_LARGE, a, sizeof(a));
  13964. if (ret != 0)
  13965. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13966. ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1));
  13967. if (ret != 0)
  13968. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13969. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13970. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13971. #endif /* HAVE_AES_DECRYPT */
  13972. #endif /* BENCH_AESGCM_LARGE */
  13973. #endif /* WOLFSSL_AESGCM_STREAM */
  13974. #endif /* WOLFSSL_AES_256 */
  13975. #endif /* !WOLFSSL_AFALG_XILINX_AES && !WOLFSSL_XILINX_CRYPT */
  13976. ret = 0;
  13977. out:
  13978. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  13979. !defined(WOLFSSL_NO_MALLOC)
  13980. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13981. XFREE(large_output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13982. XFREE(large_outdec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13983. #endif
  13984. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13985. wc_AesDelete(enc, &enc);
  13986. wc_AesDelete(dec, &dec);
  13987. #else
  13988. wc_AesFree(enc);
  13989. wc_AesFree(dec);
  13990. #endif
  13991. return ret;
  13992. }
  13993. #ifdef WOLFSSL_AES_128
  13994. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void)
  13995. {
  13996. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13997. Gmac *gmac;
  13998. #else
  13999. Gmac gmac[1];
  14000. #endif
  14001. wc_test_ret_t ret;
  14002. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14003. {
  14004. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  14005. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  14006. };
  14007. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  14008. {
  14009. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  14010. 0xe2, 0x8c, 0x8f, 0x16
  14011. };
  14012. WOLFSSL_SMALL_STACK_STATIC const byte a1[] =
  14013. {
  14014. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  14015. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  14016. };
  14017. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  14018. {
  14019. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  14020. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14021. };
  14022. #if (!defined(HAVE_FIPS) || \
  14023. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
  14024. /* FIPS builds only allow 16-byte auth tags. */
  14025. /* This sample uses a 15-byte auth tag. */
  14026. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14027. {
  14028. 0x40, 0xf7, 0xec, 0xb2, 0x52, 0x6d, 0xaa, 0xd4,
  14029. 0x74, 0x25, 0x1d, 0xf4, 0x88, 0x9e, 0xf6, 0x5b
  14030. };
  14031. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  14032. {
  14033. 0xee, 0x9c, 0x6e, 0x06, 0x15, 0x45, 0x45, 0x03,
  14034. 0x1a, 0x60, 0x24, 0xa7
  14035. };
  14036. WOLFSSL_SMALL_STACK_STATIC const byte a2[] =
  14037. {
  14038. 0x94, 0x81, 0x2c, 0x87, 0x07, 0x4e, 0x15, 0x18,
  14039. 0x34, 0xb8, 0x35, 0xaf, 0x1c, 0xa5, 0x7e, 0x56
  14040. };
  14041. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  14042. {
  14043. 0xc6, 0x81, 0x79, 0x8e, 0x3d, 0xda, 0xb0, 0x9f,
  14044. 0x8d, 0x83, 0xb0, 0xbb, 0x14, 0xb6, 0x91
  14045. };
  14046. #endif
  14047. byte tag[16];
  14048. WOLFSSL_ENTER("gmac_test");
  14049. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14050. if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  14051. return WC_TEST_RET_ENC_ERRNO;
  14052. #endif
  14053. XMEMSET(gmac, 0, sizeof *gmac); /* clear context */
  14054. (void)wc_AesInit(&gmac->aes, HEAP_HINT, INVALID_DEVID); /* Make sure devId updated */
  14055. XMEMSET(tag, 0, sizeof(tag));
  14056. wc_GmacSetKey(gmac, k1, sizeof(k1));
  14057. wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1));
  14058. if (XMEMCMP(t1, tag, sizeof(t1)) != 0)
  14059. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14060. #if (!defined(HAVE_FIPS) || \
  14061. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) )
  14062. XMEMSET(tag, 0, sizeof(tag));
  14063. wc_GmacSetKey(gmac, k2, sizeof(k2));
  14064. wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2));
  14065. if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
  14066. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14067. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
  14068. {
  14069. WOLFSSL_SMALL_STACK_STATIC const byte badT[] =
  14070. {
  14071. 0xde, 0xad, 0xbe, 0xef, 0x17, 0x2e, 0xd0, 0x43,
  14072. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14073. };
  14074. WC_RNG rng;
  14075. byte iv[12];
  14076. #ifndef HAVE_FIPS
  14077. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14078. if (ret != 0)
  14079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14080. #else
  14081. ret = wc_InitRng(&rng);
  14082. if (ret != 0)
  14083. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14084. #endif
  14085. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14086. t1, sizeof(t1));
  14087. if (ret != 0)
  14088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14089. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14090. badT, sizeof(badT));
  14091. if (ret != WC_NO_ERR_TRACE(AES_GCM_AUTH_E))
  14092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14093. ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2),
  14094. t2, sizeof(t2));
  14095. if (ret != 0)
  14096. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14097. XMEMSET(tag, 0, sizeof(tag));
  14098. XMEMSET(iv, 0, sizeof(iv));
  14099. ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14100. tag, sizeof(tag), &rng);
  14101. if (ret != 0)
  14102. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14103. ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14104. tag, sizeof(tag));
  14105. if (ret != 0)
  14106. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14107. wc_FreeRng(&rng);
  14108. }
  14109. #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
  14110. #endif /* HAVE_FIPS */
  14111. ret = 0;
  14112. out:
  14113. wc_AesFree(&gmac->aes);
  14114. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14115. XFREE(gmac, HEAP_HINT, DYNAMIC_TYPE_AES);
  14116. #endif
  14117. return ret;
  14118. }
  14119. #endif /* WOLFSSL_AES_128 */
  14120. #endif /* HAVE_AESGCM */
  14121. #if defined(HAVE_AESCCM)
  14122. #if defined(WOLFSSL_AES_256)
  14123. static wc_test_ret_t aesccm_256_test(void)
  14124. {
  14125. wc_test_ret_t ret = 0;
  14126. /* Test vectors from NIST AES CCM 256-bit CAST Example #1 */
  14127. WOLFSSL_SMALL_STACK_STATIC const byte in_key[32] = {
  14128. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14129. 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  14130. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14131. 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  14132. };
  14133. WOLFSSL_SMALL_STACK_STATIC const byte in_nonce[7] = {
  14134. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
  14135. WOLFSSL_SMALL_STACK_STATIC const byte in_auth[8] = {
  14136. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  14137. WOLFSSL_SMALL_STACK_STATIC const byte in_plaintext[4] = {
  14138. 0x20, 0x21, 0x22, 0x23};
  14139. WOLFSSL_SMALL_STACK_STATIC const byte exp_ciphertext[4] = {
  14140. 0x8A, 0xB1, 0xA8, 0x74};
  14141. WOLFSSL_SMALL_STACK_STATIC const byte exp_tag[4] = {
  14142. 0x95, 0xFC, 0x08, 0x20};
  14143. byte output[sizeof(in_plaintext)];
  14144. byte atag[sizeof(exp_tag)];
  14145. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14146. Aes* aes = wc_AesNew(HEAP_HINT, devId, &ret);
  14147. if (aes == NULL) {
  14148. ret = WC_TEST_RET_ENC_EC(ret);
  14149. }
  14150. #else
  14151. Aes aes[1];
  14152. ret = wc_AesInit(aes, HEAP_HINT, devId);
  14153. #endif
  14154. if (ret == 0) {
  14155. ret = wc_AesCcmSetKey(aes, in_key, sizeof(in_key));
  14156. }
  14157. if (ret == 0) {
  14158. ret = wc_AesCcmEncrypt(aes, output, in_plaintext, sizeof(in_plaintext),
  14159. in_nonce, sizeof(in_nonce),
  14160. atag, sizeof(atag),
  14161. in_auth, sizeof(in_auth));
  14162. }
  14163. /* Verify we produce the proper ciphertext and tag */
  14164. if (ret == 0 &&
  14165. (XMEMCMP(output, exp_ciphertext, sizeof(output)) ||
  14166. XMEMCMP(atag, exp_tag, sizeof(atag)))) {
  14167. ret = WC_TEST_RET_ENC_NC;
  14168. }
  14169. #ifdef HAVE_AES_DECRYPT
  14170. if (ret == 0) {
  14171. /* decrypt inline */
  14172. ret = wc_AesCcmDecrypt(aes, output, output, sizeof(output),
  14173. in_nonce, sizeof(in_nonce),
  14174. atag, sizeof(atag),
  14175. in_auth, sizeof(in_auth));
  14176. }
  14177. /* Verify decryption was successful */
  14178. if (ret == 0 &&
  14179. XMEMCMP(output, in_plaintext, sizeof(output))) {
  14180. ret = WC_TEST_RET_ENC_NC;
  14181. }
  14182. #endif
  14183. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14184. wc_AesDelete(aes, &aes);
  14185. #else
  14186. wc_AesFree(aes);
  14187. #endif
  14188. return ret;
  14189. }
  14190. #endif /* WOLFSSL_AES_256 */
  14191. #if defined(WOLFSSL_AES_128)
  14192. static wc_test_ret_t aesccm_128_test(void)
  14193. {
  14194. wc_test_ret_t ret;
  14195. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14196. Aes *enc = NULL;
  14197. #else
  14198. Aes enc[1];
  14199. #endif
  14200. /* key */
  14201. WOLFSSL_SMALL_STACK_STATIC const byte k[] =
  14202. {
  14203. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  14204. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  14205. };
  14206. /* nonce */
  14207. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  14208. {
  14209. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  14210. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  14211. };
  14212. /* plaintext */
  14213. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  14214. {
  14215. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14216. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14217. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  14218. };
  14219. /* plaintext - long */
  14220. WOLFSSL_SMALL_STACK_STATIC const byte pl[] =
  14221. {
  14222. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14223. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14224. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  14225. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14226. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  14227. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  14228. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  14229. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14230. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  14231. 0x50
  14232. };
  14233. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  14234. {
  14235. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14236. };
  14237. /* ciphertext */
  14238. WOLFSSL_SMALL_STACK_STATIC const byte c[] =
  14239. {
  14240. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14241. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14242. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  14243. };
  14244. /* tag - authentication */
  14245. WOLFSSL_SMALL_STACK_STATIC const byte t[] =
  14246. {
  14247. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  14248. };
  14249. /* ciphertext - long */
  14250. WOLFSSL_SMALL_STACK_STATIC const byte cl[] =
  14251. {
  14252. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14253. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14254. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0xe0,
  14255. 0x44, 0x2d, 0xbe, 0x25, 0xfa, 0x48, 0x2b, 0xa8,
  14256. 0x36, 0x0b, 0xbf, 0x01, 0xc0, 0x12, 0x45, 0xa4,
  14257. 0x82, 0x9f, 0x20, 0x6c, 0xc3, 0xd6, 0xae, 0x5b,
  14258. 0x54, 0x8d, 0xd0, 0xb1, 0x69, 0x2c, 0xec, 0x5e,
  14259. 0x95, 0xa5, 0x6b, 0x48, 0xc3, 0xc6, 0xc8, 0x9e,
  14260. 0xc7, 0x92, 0x98, 0x9d, 0x26, 0x7d, 0x2a, 0x10,
  14261. 0x0b
  14262. };
  14263. /* tag - authentication - long */
  14264. WOLFSSL_SMALL_STACK_STATIC const byte tl[] =
  14265. {
  14266. 0x89, 0xd8, 0xd2, 0x02, 0xc5, 0xcf, 0xae, 0xf4
  14267. };
  14268. /* tag - authentication - empty plaintext */
  14269. WOLFSSL_SMALL_STACK_STATIC const byte t_empty[] =
  14270. {
  14271. 0xe4, 0x28, 0x8a, 0xc3, 0x78, 0x00, 0x0f, 0xf5
  14272. };
  14273. byte t2[sizeof(t)];
  14274. byte p2[sizeof(p)];
  14275. byte c2[sizeof(c)];
  14276. byte iv2[sizeof(iv)];
  14277. byte pl2[sizeof(pl)];
  14278. byte cl2[sizeof(cl)];
  14279. byte tl2[sizeof(tl)];
  14280. byte t_empty2[sizeof(t_empty)];
  14281. XMEMSET(t2, 0, sizeof(t2));
  14282. XMEMSET(c2, 0, sizeof(c2));
  14283. XMEMSET(p2, 0, sizeof(p2));
  14284. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14285. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  14286. if (enc == NULL)
  14287. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14288. #else
  14289. XMEMSET(enc, 0, sizeof(Aes));
  14290. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14291. if (ret != 0)
  14292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14293. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  14294. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14295. if (ret != 0)
  14296. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14297. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14298. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14299. t2, sizeof(t2), a, sizeof(a));
  14300. if (ret != 0)
  14301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14302. if (XMEMCMP(c, c2, sizeof(c2)))
  14303. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14304. if (XMEMCMP(t, t2, sizeof(t2)))
  14305. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14306. #ifdef HAVE_AES_DECRYPT
  14307. ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv),
  14308. t2, sizeof(t2), a, sizeof(a));
  14309. if (ret != 0)
  14310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14311. if (XMEMCMP(p, p2, sizeof(p2)))
  14312. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14313. /* Test the authentication failure */
  14314. t2[0]++; /* Corrupt the authentication tag. */
  14315. ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv),
  14316. t2, sizeof(t2), a, sizeof(a));
  14317. if (ret == 0)
  14318. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14319. /* Clear c2 to compare against p2. p2 should be set to zero in case of
  14320. * authentication fail. */
  14321. XMEMSET(c2, 0, sizeof(c2));
  14322. if (XMEMCMP(p2, c2, sizeof(p2)))
  14323. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14324. #endif
  14325. XMEMSET(t2, 0, sizeof(t2));
  14326. XMEMSET(c2, 0, sizeof(c2));
  14327. XMEMSET(p2, 0, sizeof(p2));
  14328. XMEMSET(iv2, 0, sizeof(iv2));
  14329. wc_AesFree(enc);
  14330. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14331. if (ret != 0)
  14332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14333. #ifndef HAVE_SELFTEST
  14334. /* selftest build does not have wc_AesCcmSetNonce() or
  14335. * wc_AesCcmEncrypt_ex() */
  14336. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14337. if (ret != 0)
  14338. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14339. ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv));
  14340. if (ret != 0)
  14341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14342. ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2),
  14343. t2, sizeof(t2), a, sizeof(a));
  14344. if (ret != 0)
  14345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14346. if (XMEMCMP(iv, iv2, sizeof(iv2)))
  14347. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14348. if (XMEMCMP(c, c2, sizeof(c2)))
  14349. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14350. if (XMEMCMP(t, t2, sizeof(t2)))
  14351. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14352. #endif
  14353. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  14354. /* test fail on invalid IV sizes */
  14355. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14356. if (ret != 0)
  14357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14358. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14359. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14360. t2, 1, a, sizeof(a));
  14361. if (ret == 0) {
  14362. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14363. }
  14364. #endif
  14365. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14366. ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv),
  14367. tl2, sizeof(tl2), a, sizeof(a));
  14368. if (ret != 0)
  14369. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14370. if (XMEMCMP(cl, cl2, sizeof(cl2)))
  14371. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14372. if (XMEMCMP(tl, tl2, sizeof(tl2)))
  14373. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14374. #ifdef HAVE_AES_DECRYPT
  14375. ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv),
  14376. tl2, sizeof(tl2), a, sizeof(a));
  14377. if (ret != 0)
  14378. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14379. if (XMEMCMP(pl, pl2, sizeof(pl2)))
  14380. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14381. #endif
  14382. /* test empty message as null input or output with nonzero inSz. */
  14383. ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */,
  14384. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14385. a, sizeof(a));
  14386. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14387. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14388. ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14389. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14390. a, sizeof(a));
  14391. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14393. #ifdef HAVE_AES_DECRYPT
  14394. ret = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */,
  14395. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14396. sizeof(a));
  14397. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14398. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14399. ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14400. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14401. sizeof(a));
  14402. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14404. #endif
  14405. /* test empty message as null input and output with zero inSz --
  14406. * must either succeed, or fail early with BAD_FUNC_ARG.
  14407. */
  14408. ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */,
  14409. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14410. a, sizeof(a));
  14411. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  14412. if (ret != 0)
  14413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14414. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14415. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14416. #ifdef HAVE_AES_DECRYPT
  14417. ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */,
  14418. 0 /* inSz */, iv, sizeof(iv), t_empty2,
  14419. sizeof(t_empty2), a, sizeof(a));
  14420. if (ret != 0)
  14421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14422. #endif
  14423. }
  14424. /* test empty message as zero-length string -- must work. */
  14425. ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv,
  14426. sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14427. sizeof(a));
  14428. if (ret != 0)
  14429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14430. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14431. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14432. #ifdef HAVE_AES_DECRYPT
  14433. ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */,
  14434. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14435. sizeof(a));
  14436. if (ret != 0)
  14437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14438. #endif
  14439. ret = 0;
  14440. out:
  14441. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14442. wc_AesDelete(enc, &enc);
  14443. #else
  14444. wc_AesFree(enc);
  14445. #endif
  14446. return ret;
  14447. }
  14448. #endif /* WOLFSSL_AES_128 */
  14449. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void)
  14450. {
  14451. wc_test_ret_t ret = 0;
  14452. WOLFSSL_ENTER("aesccm_test");
  14453. #ifdef WOLFSSL_AES_128
  14454. if (ret == 0)
  14455. ret = aesccm_128_test();
  14456. #endif
  14457. #ifdef WOLFSSL_AES_256
  14458. if (ret == 0)
  14459. ret = aesccm_256_test();
  14460. #endif
  14461. return ret;
  14462. }
  14463. #endif /* HAVE_AESCCM */
  14464. #if defined(WOLFSSL_AES_EAX) && \
  14465. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14466. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
  14467. {
  14468. typedef struct {
  14469. byte key[AES_256_KEY_SIZE];
  14470. int key_length;
  14471. byte iv[AES_BLOCK_SIZE];
  14472. int iv_length;
  14473. byte aad[AES_BLOCK_SIZE * 2];
  14474. int aad_length;
  14475. byte msg[AES_BLOCK_SIZE * 2];
  14476. int msg_length;
  14477. byte ct[AES_BLOCK_SIZE * 2];
  14478. int ct_length;
  14479. byte tag[AES_BLOCK_SIZE];
  14480. int tag_length;
  14481. int valid;
  14482. } AadVector;
  14483. /* A small selection of Google wycheproof vectors that use vectors
  14484. * from the original paper: eprint.iacr.org/2003/069
  14485. * https://github.com/google/wycheproof/blob/master/testvectors/aes_eax_test.json
  14486. */
  14487. WOLFSSL_SMALL_STACK_STATIC const AadVector vectors[] = {
  14488. /* Vector from paper - empty message with auth data */
  14489. {
  14490. /* key, key length */
  14491. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  14492. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  14493. /* iv, iv length */
  14494. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  14495. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  14496. /* aad, aad length */
  14497. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  14498. /* msg, msg length */
  14499. {0}, 0,
  14500. /* ct, ct length */
  14501. {0}, 0,
  14502. /* tag, tag length */
  14503. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2,
  14504. 0x7b, 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  14505. /* valid */
  14506. 1,
  14507. },
  14508. /* Vector from paper - no auth data, valid auth tag */
  14509. {
  14510. /* key, key length */
  14511. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14512. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14513. /* iv , iv length */
  14514. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  14515. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  14516. /* aad, aad length */
  14517. {0}, 0,
  14518. /* msg, msg length */
  14519. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14520. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14521. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  14522. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  14523. /* ct, ct length */
  14524. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  14525. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  14526. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  14527. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  14528. /* tag, tag length */
  14529. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  14530. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  14531. /* valid */
  14532. 1,
  14533. },
  14534. /* Vector from paper - no auth data with invalid auth tag */
  14535. {
  14536. /* key, key length */
  14537. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14538. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14539. /* iv, iv length */
  14540. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14541. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  14542. /* aad, aad length */
  14543. {0}, 0,
  14544. /* msg, msg length */
  14545. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14546. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  14547. /* ct , ct length */
  14548. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  14549. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  14550. /* tag, tag length */
  14551. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  14552. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  14553. /* valid */
  14554. 0,
  14555. },
  14556. };
  14557. WOLFSSL_SMALL_STACK_STATIC byte ciphertext[sizeof(vectors[0].ct)];
  14558. WOLFSSL_SMALL_STACK_STATIC byte authtag[sizeof(vectors[0].tag)];
  14559. int i;
  14560. int len;
  14561. wc_test_ret_t ret;
  14562. WOLFSSL_ENTER("aes_eax_test");
  14563. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  14564. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14565. len = sizeof(authtag);
  14566. ret = wc_AesEaxEncryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14567. ciphertext,
  14568. vectors[i].msg, (word32)vectors[i].msg_length,
  14569. vectors[i].iv, (word32)vectors[i].iv_length,
  14570. authtag, (word32)len,
  14571. vectors[i].aad, (word32)vectors[i].aad_length);
  14572. if (ret != 0) {
  14573. return WC_TEST_RET_ENC_EC(ret);
  14574. }
  14575. /* check ciphertext matches vector */
  14576. if (XMEMCMP(ciphertext, vectors[i].ct, (size_t)vectors[i].ct_length)) {
  14577. return WC_TEST_RET_ENC_NC;
  14578. }
  14579. /* check that tag matches vector only for vectors marked as valid */
  14580. ret = XMEMCMP(authtag, vectors[i].tag, len);
  14581. if (vectors[i].valid == 1 && ret != 0 ) {
  14582. return WC_TEST_RET_ENC_NC;
  14583. }
  14584. else if (vectors[i].valid == 0 && ret == 0) {
  14585. return WC_TEST_RET_ENC_NC;
  14586. }
  14587. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14588. ret = wc_AesEaxDecryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14589. ciphertext,
  14590. vectors[i].ct, (word32)vectors[i].ct_length,
  14591. vectors[i].iv, (word32)vectors[i].iv_length,
  14592. authtag, (word32)len,
  14593. vectors[i].aad, (word32)vectors[i].aad_length);
  14594. if (ret != 0) {
  14595. return WC_TEST_RET_ENC_EC(ret);
  14596. }
  14597. /* check decrypted ciphertext matches vector plaintext */
  14598. if (XMEMCMP(ciphertext, vectors[i].msg, (size_t)vectors[i].msg_length)) {
  14599. return WC_TEST_RET_ENC_NC;
  14600. }
  14601. }
  14602. return 0;
  14603. }
  14604. #endif /* WOLFSSL_AES_EAX */
  14605. #ifdef HAVE_AES_KEYWRAP
  14606. #define MAX_KEYWRAP_TEST_OUTLEN 40
  14607. #define MAX_KEYWRAP_TEST_PLAINLEN 32
  14608. typedef struct keywrapVector {
  14609. const byte* kek;
  14610. const byte* data;
  14611. const byte* verify;
  14612. word32 kekLen;
  14613. word32 dataLen;
  14614. word32 verifyLen;
  14615. } keywrapVector;
  14616. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void)
  14617. {
  14618. int wrapSz, plainSz, testSz, i;
  14619. /* test vectors from RFC 3394 (kek, data, verify) */
  14620. #ifdef WOLFSSL_AES_128
  14621. /* Wrap 128 bits of Key Data with a 128-bit KEK */
  14622. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14623. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14624. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14625. };
  14626. WOLFSSL_SMALL_STACK_STATIC const byte d1[] = {
  14627. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14628. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14629. };
  14630. WOLFSSL_SMALL_STACK_STATIC const byte v1[] = {
  14631. 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
  14632. 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
  14633. 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
  14634. };
  14635. #endif /* WOLFSSL_AES_128 */
  14636. #ifdef WOLFSSL_AES_192
  14637. /* Wrap 128 bits of Key Data with a 192-bit KEK */
  14638. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  14639. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14640. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14641. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14642. };
  14643. WOLFSSL_SMALL_STACK_STATIC const byte d2[] = {
  14644. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14645. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14646. };
  14647. WOLFSSL_SMALL_STACK_STATIC const byte v2[] = {
  14648. 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
  14649. 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
  14650. 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
  14651. };
  14652. #endif
  14653. #ifdef WOLFSSL_AES_256
  14654. /* Wrap 128 bits of Key Data with a 256-bit KEK */
  14655. WOLFSSL_SMALL_STACK_STATIC const byte k3[] = {
  14656. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14657. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14658. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14659. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14660. };
  14661. WOLFSSL_SMALL_STACK_STATIC const byte d3[] = {
  14662. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14663. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14664. };
  14665. WOLFSSL_SMALL_STACK_STATIC const byte v3[] = {
  14666. 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
  14667. 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
  14668. 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7
  14669. };
  14670. #endif
  14671. #ifdef WOLFSSL_AES_192
  14672. /* Wrap 192 bits of Key Data with a 192-bit KEK */
  14673. WOLFSSL_SMALL_STACK_STATIC const byte k4[] = {
  14674. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14675. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14676. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14677. };
  14678. WOLFSSL_SMALL_STACK_STATIC const byte d4[] = {
  14679. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14680. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14681. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14682. };
  14683. WOLFSSL_SMALL_STACK_STATIC const byte v4[] = {
  14684. 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
  14685. 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
  14686. 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
  14687. 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
  14688. };
  14689. #endif
  14690. #ifdef WOLFSSL_AES_256
  14691. /* Wrap 192 bits of Key Data with a 256-bit KEK */
  14692. WOLFSSL_SMALL_STACK_STATIC const byte k5[] = {
  14693. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14694. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14695. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14696. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14697. };
  14698. WOLFSSL_SMALL_STACK_STATIC const byte d5[] = {
  14699. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14700. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14701. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14702. };
  14703. WOLFSSL_SMALL_STACK_STATIC const byte v5[] = {
  14704. 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
  14705. 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
  14706. 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
  14707. 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1
  14708. };
  14709. /* Wrap 256 bits of Key Data with a 256-bit KEK */
  14710. WOLFSSL_SMALL_STACK_STATIC const byte k6[] = {
  14711. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14712. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14713. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14714. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14715. };
  14716. WOLFSSL_SMALL_STACK_STATIC const byte d6[] = {
  14717. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14718. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14719. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14720. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14721. };
  14722. WOLFSSL_SMALL_STACK_STATIC const byte v6[] = {
  14723. 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
  14724. 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
  14725. 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
  14726. 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
  14727. 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
  14728. };
  14729. #endif /* WOLFSSL_AES_256 */
  14730. byte output[MAX_KEYWRAP_TEST_OUTLEN];
  14731. byte plain [MAX_KEYWRAP_TEST_PLAINLEN];
  14732. const keywrapVector test_wrap[] =
  14733. {
  14734. #ifdef WOLFSSL_AES_128
  14735. {k1, d1, v1, sizeof(k1), sizeof(d1), sizeof(v1)},
  14736. #endif
  14737. #ifdef WOLFSSL_AES_192
  14738. {k2, d2, v2, sizeof(k2), sizeof(d2), sizeof(v2)},
  14739. #endif
  14740. #ifdef WOLFSSL_AES_256
  14741. {k3, d3, v3, sizeof(k3), sizeof(d3), sizeof(v3)},
  14742. #endif
  14743. #ifdef WOLFSSL_AES_192
  14744. {k4, d4, v4, sizeof(k4), sizeof(d4), sizeof(v4)},
  14745. #endif
  14746. #ifdef WOLFSSL_AES_256
  14747. {k5, d5, v5, sizeof(k5), sizeof(d5), sizeof(v5)},
  14748. {k6, d6, v6, sizeof(k6), sizeof(d6), sizeof(v6)}
  14749. #endif
  14750. };
  14751. WOLFSSL_ENTER("aeskeywrap_test");
  14752. testSz = sizeof(test_wrap) / sizeof(keywrapVector);
  14753. XMEMSET(output, 0, sizeof(output));
  14754. XMEMSET(plain, 0, sizeof(plain));
  14755. for (i = 0; i < testSz; i++) {
  14756. wrapSz = wc_AesKeyWrap(test_wrap[i].kek, test_wrap[i].kekLen,
  14757. test_wrap[i].data, test_wrap[i].dataLen,
  14758. output, sizeof(output), NULL);
  14759. if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) )
  14760. return WC_TEST_RET_ENC_NC;
  14761. if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0)
  14762. return WC_TEST_RET_ENC_NC;
  14763. plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen,
  14764. output, (word32)wrapSz,
  14765. plain, sizeof(plain), NULL);
  14766. if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) )
  14767. return WC_TEST_RET_ENC_NC;
  14768. if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0)
  14769. return WC_TEST_RET_ENC_I(i);
  14770. }
  14771. return 0;
  14772. }
  14773. #endif /* HAVE_AES_KEYWRAP */
  14774. #endif /* !NO_AES */
  14775. #ifdef HAVE_ARIA
  14776. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz)
  14777. {
  14778. #ifndef DEBUG_WOLFSSL
  14779. (void)strName;
  14780. (void)data;
  14781. (void)dataSz;
  14782. #else
  14783. WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
  14784. WOLFSSL_BUFFER(data,dataSz);
  14785. #endif
  14786. }
  14787. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo)
  14788. {
  14789. byte data[] = TEST_STRING;
  14790. word32 dataSz = TEST_STRING_SZ;
  14791. /* Arbitrarily random long key that we will truncate to the right size */
  14792. byte key[] = { 0x1E, 0xCC, 0x95, 0xCB, 0xD3, 0x74, 0x58, 0x4F,
  14793. 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6,
  14794. 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF,
  14795. 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B };
  14796. byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[AES_BLOCK_SIZE];
  14797. word32 keySz, adSz = 256, authTagSz = sizeof(authTag);
  14798. wc_Aria aria;
  14799. int ret = 0;
  14800. WOLFSSL_ENTER("ariagcm_test");
  14801. XMEMSET((void *)&aria, 0, sizeof(aria));
  14802. ret = wc_AriaInitCrypt(&aria, algo);
  14803. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14804. ret = wc_AriaSetKey(&aria, key);
  14805. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14806. MC_GetObjectValue(aria.hSession, aria.hKey, key, &keySz);
  14807. printOutput("Key", key, keySz);
  14808. WC_RNG rng;
  14809. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14810. if (ret != 0)
  14811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14812. ret = wc_AriaGcmSetIV(&aria, GCM_NONCE_MID_SZ, NULL, 0, &rng);
  14813. if (ret != 0)
  14814. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14815. wc_FreeRng(&rng);
  14816. printOutput("Plaintext", data, sizeof(data));
  14817. XMEMSET(cipher, 0, sizeof(cipher));
  14818. ret = wc_AriaEncrypt(&aria, cipher, data, dataSz,
  14819. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14820. authTag, authTagSz);
  14821. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14822. printOutput("Ciphertext", cipher, sizeof(cipher));
  14823. printOutput("AuthTag", authTag, sizeof(authTag));
  14824. XMEMSET(plain, 0, sizeof(plain));
  14825. ret = wc_AriaDecrypt(&aria, plain, cipher, dataSz,
  14826. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14827. authTag, authTagSz);
  14828. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14829. printOutput("Plaintext", plain, sizeof(plain));
  14830. if (XMEMCMP(plain, data, dataSz) != 0)
  14831. ERROR_OUT(WC_TEST_RET_ENC_NC,out);
  14832. out:
  14833. if (ret != 0) { wc_AriaFreeCrypt(&aria); }
  14834. else { ret = wc_AriaFreeCrypt(&aria); }
  14835. return ret;
  14836. }
  14837. #endif /* HAVE_ARIA */
  14838. #ifdef HAVE_CAMELLIA
  14839. enum {
  14840. CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
  14841. };
  14842. typedef struct {
  14843. int type;
  14844. const byte* plaintext;
  14845. const byte* iv;
  14846. const byte* ciphertext;
  14847. const byte* key;
  14848. word32 keySz;
  14849. int errorCode;
  14850. } test_vector_t;
  14851. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void)
  14852. {
  14853. /* Camellia ECB Test Plaintext */
  14854. WOLFSSL_SMALL_STACK_STATIC const byte pte[] =
  14855. {
  14856. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14857. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14858. };
  14859. /* Camellia ECB Test Initialization Vector */
  14860. WOLFSSL_SMALL_STACK_STATIC const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  14861. /* Test 1: Camellia ECB 128-bit key */
  14862. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14863. {
  14864. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14865. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14866. };
  14867. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  14868. {
  14869. 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
  14870. 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
  14871. };
  14872. /* Test 2: Camellia ECB 192-bit key */
  14873. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14874. {
  14875. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14876. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14877. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  14878. };
  14879. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  14880. {
  14881. 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
  14882. 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
  14883. };
  14884. /* Test 3: Camellia ECB 256-bit key */
  14885. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  14886. {
  14887. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14888. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14889. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14890. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  14891. };
  14892. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  14893. {
  14894. 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
  14895. 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
  14896. };
  14897. /* Camellia CBC Test Plaintext */
  14898. WOLFSSL_SMALL_STACK_STATIC const byte ptc[] =
  14899. {
  14900. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  14901. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  14902. };
  14903. /* Camellia CBC Test Initialization Vector */
  14904. WOLFSSL_SMALL_STACK_STATIC const byte ivc[] =
  14905. {
  14906. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14907. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14908. };
  14909. /* Test 4: Camellia-CBC 128-bit key */
  14910. WOLFSSL_SMALL_STACK_STATIC const byte k4[] =
  14911. {
  14912. 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
  14913. 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
  14914. };
  14915. WOLFSSL_SMALL_STACK_STATIC const byte c4[] =
  14916. {
  14917. 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
  14918. 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
  14919. };
  14920. /* Test 5: Camellia-CBC 192-bit key */
  14921. WOLFSSL_SMALL_STACK_STATIC const byte k5[] =
  14922. {
  14923. 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
  14924. 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
  14925. 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
  14926. };
  14927. WOLFSSL_SMALL_STACK_STATIC const byte c5[] =
  14928. {
  14929. 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
  14930. 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
  14931. };
  14932. /* Test 6: CBC 256-bit key */
  14933. WOLFSSL_SMALL_STACK_STATIC const byte k6[] =
  14934. {
  14935. 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
  14936. 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
  14937. 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
  14938. 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
  14939. };
  14940. WOLFSSL_SMALL_STACK_STATIC const byte c6[] =
  14941. {
  14942. 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
  14943. 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
  14944. };
  14945. byte out[CAMELLIA_BLOCK_SIZE];
  14946. Camellia cam;
  14947. WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] =
  14948. {
  14949. {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
  14950. {CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
  14951. {CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
  14952. {CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
  14953. {CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
  14954. {CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
  14955. {CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
  14956. {CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
  14957. {CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
  14958. {CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
  14959. {CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
  14960. {CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
  14961. };
  14962. int i, testsSz;
  14963. int ret;
  14964. WOLFSSL_ENTER("camellia_test");
  14965. testsSz = sizeof(testVectors)/sizeof(test_vector_t);
  14966. for (i = 0; i < testsSz; i++) {
  14967. if (wc_CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
  14968. testVectors[i].iv) != 0)
  14969. return testVectors[i].errorCode;
  14970. switch (testVectors[i].type) {
  14971. case CAM_ECB_ENC:
  14972. ret = wc_CamelliaEncryptDirect(&cam, out,
  14973. testVectors[i].plaintext);
  14974. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14975. CAMELLIA_BLOCK_SIZE))
  14976. return testVectors[i].errorCode;
  14977. break;
  14978. case CAM_ECB_DEC:
  14979. ret = wc_CamelliaDecryptDirect(&cam, out,
  14980. testVectors[i].ciphertext);
  14981. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14982. CAMELLIA_BLOCK_SIZE))
  14983. return testVectors[i].errorCode;
  14984. break;
  14985. case CAM_CBC_ENC:
  14986. ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
  14987. CAMELLIA_BLOCK_SIZE);
  14988. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14989. CAMELLIA_BLOCK_SIZE))
  14990. return testVectors[i].errorCode;
  14991. break;
  14992. case CAM_CBC_DEC:
  14993. ret = wc_CamelliaCbcDecrypt(&cam, out,
  14994. testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE);
  14995. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14996. CAMELLIA_BLOCK_SIZE))
  14997. return testVectors[i].errorCode;
  14998. break;
  14999. default:
  15000. break;
  15001. }
  15002. }
  15003. /* Setting the IV and checking it was actually set. */
  15004. ret = wc_CamelliaSetIV(&cam, ivc);
  15005. if (ret != 0)
  15006. return WC_TEST_RET_ENC_EC(ret);
  15007. if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE) != 0)
  15008. return WC_TEST_RET_ENC_NC;
  15009. /* Setting the IV to NULL should be same as all zeros IV */
  15010. ret = wc_CamelliaSetIV(&cam, NULL);
  15011. if (ret != 0)
  15012. return WC_TEST_RET_ENC_EC(ret);
  15013. if (XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE) != 0)
  15014. return WC_TEST_RET_ENC_NC;
  15015. /* First parameter should never be null */
  15016. if (wc_CamelliaSetIV(NULL, NULL) == 0)
  15017. return WC_TEST_RET_ENC_NC;
  15018. /* First parameter should never be null, check it fails */
  15019. if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
  15020. return WC_TEST_RET_ENC_NC;
  15021. /* Key should have a size of 16, 24, or 32 */
  15022. if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0)
  15023. return WC_TEST_RET_ENC_NC;
  15024. return 0;
  15025. }
  15026. #endif /* HAVE_CAMELLIA */
  15027. #ifdef WOLFSSL_SM4
  15028. #ifdef WOLFSSL_SM4_ECB
  15029. static int sm4_ecb_test(void)
  15030. {
  15031. /* draft-ribose-cfrg-sm4-10 A.2.1.1 */
  15032. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15033. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15034. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15035. };
  15036. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15037. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15038. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15039. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15040. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15041. };
  15042. WOLFSSL_SMALL_STACK_STATIC const byte c1_ecb[] = {
  15043. 0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
  15044. 0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
  15045. 0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
  15046. 0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04
  15047. };
  15048. wc_Sm4 sm4;
  15049. byte enc[SM4_BLOCK_SIZE * 4];
  15050. byte dec[SM4_BLOCK_SIZE * 4];
  15051. int ret;
  15052. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15053. if (ret != 0)
  15054. return WC_TEST_RET_ENC_EC(ret);
  15055. /* Encrypt and decrypt with ECB. */
  15056. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15057. if (ret != 0)
  15058. return WC_TEST_RET_ENC_EC(ret);
  15059. ret = wc_Sm4EcbEncrypt(&sm4, enc, p1, sizeof(p1));
  15060. if (ret != 0)
  15061. return WC_TEST_RET_ENC_EC(ret);
  15062. if (XMEMCMP(enc, c1_ecb, sizeof(c1_ecb)) != 0)
  15063. return WC_TEST_RET_ENC_NC;
  15064. ret = wc_Sm4EcbDecrypt(&sm4, dec, enc, sizeof(c1_ecb));
  15065. if (ret != 0)
  15066. return WC_TEST_RET_ENC_EC(ret);
  15067. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15068. return WC_TEST_RET_ENC_NC;
  15069. wc_Sm4Free(&sm4);
  15070. return 0;
  15071. }
  15072. #endif
  15073. #ifdef WOLFSSL_SM4_CBC
  15074. static int sm4_cbc_test(void)
  15075. {
  15076. /* draft-ribose-cfrg-sm4-10 A.2.2.1 */
  15077. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15078. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15079. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15080. };
  15081. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15082. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15083. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15084. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15085. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15086. };
  15087. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15088. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15089. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15090. };
  15091. WOLFSSL_SMALL_STACK_STATIC const byte c1_cbc[] = {
  15092. 0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
  15093. 0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
  15094. 0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
  15095. 0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D
  15096. };
  15097. wc_Sm4 sm4;
  15098. byte enc[SM4_BLOCK_SIZE * 4];
  15099. byte dec[SM4_BLOCK_SIZE * 4];
  15100. int ret;
  15101. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15102. if (ret != 0)
  15103. return WC_TEST_RET_ENC_EC(ret);
  15104. /* Encrypt and decrypt with CBC. */
  15105. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15106. if (ret != 0)
  15107. return WC_TEST_RET_ENC_EC(ret);
  15108. ret = wc_Sm4SetIV(&sm4, i1);
  15109. if (ret != 0)
  15110. return WC_TEST_RET_ENC_EC(ret);
  15111. ret = wc_Sm4CbcEncrypt(&sm4, enc, p1, sizeof(p1));
  15112. if (ret != 0)
  15113. return WC_TEST_RET_ENC_EC(ret);
  15114. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15115. return WC_TEST_RET_ENC_NC;
  15116. ret = wc_Sm4SetIV(&sm4, i1);
  15117. if (ret != 0)
  15118. return WC_TEST_RET_ENC_EC(ret);
  15119. ret = wc_Sm4CbcDecrypt(&sm4, dec, enc, sizeof(c1_cbc));
  15120. if (ret != 0)
  15121. return WC_TEST_RET_ENC_EC(ret);
  15122. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15123. return WC_TEST_RET_ENC_NC;
  15124. /* Encrypt and decrypt in-place with CBC. */
  15125. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15126. if (ret != 0)
  15127. return WC_TEST_RET_ENC_EC(ret);
  15128. ret = wc_Sm4SetIV(&sm4, i1);
  15129. if (ret != 0)
  15130. return WC_TEST_RET_ENC_EC(ret);
  15131. XMEMCPY(enc, p1, sizeof(p1));
  15132. ret = wc_Sm4CbcEncrypt(&sm4, enc, enc, sizeof(p1));
  15133. if (ret != 0)
  15134. return WC_TEST_RET_ENC_EC(ret);
  15135. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15136. return WC_TEST_RET_ENC_NC;
  15137. ret = wc_Sm4SetIV(&sm4, i1);
  15138. if (ret != 0)
  15139. return WC_TEST_RET_ENC_EC(ret);
  15140. ret = wc_Sm4CbcDecrypt(&sm4, enc, enc, sizeof(c1_cbc));
  15141. if (ret != 0)
  15142. return WC_TEST_RET_ENC_EC(ret);
  15143. if (XMEMCMP(enc, p1, sizeof(p1)) != 0)
  15144. return WC_TEST_RET_ENC_NC;
  15145. wc_Sm4Free(&sm4);
  15146. return 0;
  15147. }
  15148. #endif
  15149. #ifdef WOLFSSL_SM4_CTR
  15150. static int sm4_ctr_test(void)
  15151. {
  15152. /* draft-ribose-cfrg-sm4-10 A.2.5.1 */
  15153. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15154. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15155. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15156. };
  15157. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15158. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15159. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15160. };
  15161. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15162. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15163. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15164. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15165. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15166. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15167. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15168. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15169. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB
  15170. };
  15171. WOLFSSL_SMALL_STACK_STATIC const byte c2_ctr[] = {
  15172. 0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
  15173. 0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
  15174. 0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
  15175. 0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
  15176. 0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
  15177. 0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
  15178. 0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
  15179. 0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14
  15180. };
  15181. wc_Sm4 sm4;
  15182. byte enc[SM4_BLOCK_SIZE * 4];
  15183. byte dec[SM4_BLOCK_SIZE * 4];
  15184. int chunk;
  15185. int i;
  15186. int ret;
  15187. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15188. if (ret != 0)
  15189. return WC_TEST_RET_ENC_EC(ret);
  15190. /* Encrypt and decrypt using encrypt with CTR. */
  15191. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15192. if (ret != 0)
  15193. return WC_TEST_RET_ENC_EC(ret);
  15194. ret = wc_Sm4SetIV(&sm4, i1);
  15195. if (ret != 0)
  15196. return WC_TEST_RET_ENC_EC(ret);
  15197. ret = wc_Sm4CtrEncrypt(&sm4, enc, p2, sizeof(p2));
  15198. if (ret != 0)
  15199. return WC_TEST_RET_ENC_EC(ret);
  15200. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15201. return WC_TEST_RET_ENC_NC;
  15202. ret = wc_Sm4SetIV(&sm4, i1);
  15203. if (ret != 0)
  15204. return WC_TEST_RET_ENC_EC(ret);
  15205. ret = wc_Sm4CtrEncrypt(&sm4, dec, enc, sizeof(c2_ctr));
  15206. if (ret != 0)
  15207. return WC_TEST_RET_ENC_EC(ret);
  15208. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15209. return WC_TEST_RET_ENC_NC;
  15210. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15211. ret = wc_Sm4SetIV(&sm4, i1);
  15212. if (ret != 0)
  15213. return WC_TEST_RET_ENC_I(chunk);
  15214. XMEMSET(enc, 0, sizeof(enc));
  15215. for (i = 0; i + chunk <= (int)sizeof(p2); i += chunk) {
  15216. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, chunk);
  15217. if (ret != 0)
  15218. return WC_TEST_RET_ENC_I(i);
  15219. }
  15220. if (i < (int)sizeof(p2)) {
  15221. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, sizeof(p2) - i);
  15222. if (ret != 0)
  15223. return WC_TEST_RET_ENC_I(chunk);
  15224. }
  15225. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15226. return WC_TEST_RET_ENC_I(chunk);
  15227. }
  15228. wc_Sm4Free(&sm4);
  15229. return 0;
  15230. }
  15231. #endif
  15232. #ifdef WOLFSSL_SM4_GCM
  15233. static int sm4_gcm_test(void)
  15234. {
  15235. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15236. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15237. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15238. };
  15239. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15240. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15241. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15242. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15243. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15244. };
  15245. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15246. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15247. 0x08, 0x09, 0x0A, 0x0B
  15248. };
  15249. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15250. 0xFF, 0xEE, 0xDD
  15251. };
  15252. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15253. 0x83, 0xb2, 0x91, 0xcf, 0x22, 0xc9, 0x5f, 0x89,
  15254. 0xde, 0x3d, 0x52, 0x8d, 0xd7, 0x13, 0x50, 0x89
  15255. };
  15256. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15257. 0xff, 0x8b, 0xb2, 0x3b, 0x0a, 0x0a, 0x12, 0xa4,
  15258. 0xa8, 0x4c, 0x4f, 0x67, 0x06, 0x81, 0xbb, 0x88,
  15259. 0x66, 0x17, 0xc7, 0x43, 0xbf, 0xae, 0x41, 0x40,
  15260. 0xec, 0x1e, 0x03, 0x85, 0x2b, 0x56, 0xa8, 0xc0
  15261. };
  15262. /* RFC8998 A.1. */
  15263. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15264. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15265. 0x00, 0x00, 0xAB, 0xCD
  15266. };
  15267. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15268. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15269. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15270. };
  15271. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15272. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15273. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15274. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15275. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15276. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15277. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15278. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15279. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15280. };
  15281. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15282. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15283. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15284. 0xAB, 0xAD, 0xDA, 0xD2
  15285. };
  15286. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15287. 0x17, 0xF3, 0x99, 0xF0, 0x8C, 0x67, 0xD5, 0xEE,
  15288. 0x19, 0xD0, 0xDC, 0x99, 0x69, 0xC4, 0xBB, 0x7D,
  15289. 0x5F, 0xD4, 0x6F, 0xD3, 0x75, 0x64, 0x89, 0x06,
  15290. 0x91, 0x57, 0xB2, 0x82, 0xBB, 0x20, 0x07, 0x35,
  15291. 0xD8, 0x27, 0x10, 0xCA, 0x5C, 0x22, 0xF0, 0xCC,
  15292. 0xFA, 0x7C, 0xBF, 0x93, 0xD4, 0x96, 0xAC, 0x15,
  15293. 0xA5, 0x68, 0x34, 0xCB, 0xCF, 0x98, 0xC3, 0x97,
  15294. 0xB4, 0x02, 0x4A, 0x26, 0x91, 0x23, 0x3B, 0x8D
  15295. };
  15296. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15297. 0x83, 0xDE, 0x35, 0x41, 0xE4, 0xC2, 0xB5, 0x81,
  15298. 0x77, 0xE0, 0x65, 0xA9, 0xBF, 0x7B, 0x62, 0xEC
  15299. };
  15300. wc_Sm4 sm4;
  15301. byte enc[SM4_BLOCK_SIZE * 4];
  15302. byte dec[SM4_BLOCK_SIZE * 4];
  15303. byte tag[SM4_BLOCK_SIZE];
  15304. int ret;
  15305. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15306. if (ret != 0)
  15307. return WC_TEST_RET_ENC_EC(ret);
  15308. /* Encrypt and decrypt using encrypt with GCM. */
  15309. ret = wc_Sm4GcmSetKey(&sm4, k1, sizeof(k1));
  15310. if (ret != 0)
  15311. return WC_TEST_RET_ENC_EC(ret);
  15312. ret = wc_Sm4GcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15313. sizeof(tag), a1, sizeof(a1));
  15314. if (ret != 0)
  15315. return WC_TEST_RET_ENC_EC(ret);
  15316. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15317. return WC_TEST_RET_ENC_NC;
  15318. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15319. return WC_TEST_RET_ENC_NC;
  15320. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15321. sizeof(tag), a1, sizeof(a1));
  15322. if (ret != 0)
  15323. return WC_TEST_RET_ENC_EC(ret);
  15324. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15325. return WC_TEST_RET_ENC_NC;
  15326. /* RFC8998 test vector. */
  15327. ret = wc_Sm4GcmSetKey(&sm4, k2, sizeof(k2));
  15328. if (ret != 0)
  15329. return WC_TEST_RET_ENC_EC(ret);
  15330. ret = wc_Sm4GcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15331. sizeof(tag), a2, sizeof(a2));
  15332. if (ret != 0)
  15333. return WC_TEST_RET_ENC_EC(ret);
  15334. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15335. return WC_TEST_RET_ENC_NC;
  15336. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15337. return WC_TEST_RET_ENC_NC;
  15338. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15339. sizeof(tag), a2, sizeof(a2));
  15340. if (ret != 0)
  15341. return WC_TEST_RET_ENC_EC(ret);
  15342. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15343. return WC_TEST_RET_ENC_NC;
  15344. wc_Sm4Free(&sm4);
  15345. return 0;
  15346. }
  15347. #endif
  15348. #ifdef WOLFSSL_SM4_CCM
  15349. static int sm4_ccm_test(void)
  15350. {
  15351. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15352. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15353. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15354. };
  15355. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15356. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15357. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15358. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15359. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15360. };
  15361. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15362. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15363. 0x08, 0x09, 0x0A, 0x0B
  15364. };
  15365. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15366. 0xFF, 0xEE, 0xDD
  15367. };
  15368. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15369. 0x9a, 0x98, 0x04, 0xb6, 0x0f, 0x19, 0x4a, 0x46,
  15370. 0xba, 0xed, 0xe6, 0x89, 0x69, 0x34, 0xad, 0x61
  15371. };
  15372. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15373. 0xbd, 0xc0, 0x72, 0x60, 0xda, 0x2d, 0x11, 0xdc,
  15374. 0x66, 0x33, 0xcc, 0xec, 0xb2, 0xf4, 0x53, 0x59,
  15375. 0x9e, 0xb1, 0xb3, 0x6b, 0x1f, 0x1c, 0xfb, 0x29,
  15376. 0xf5, 0x37, 0xfc, 0x00, 0xf2, 0x4e, 0x70, 0x6f
  15377. };
  15378. /* RFC8998 A.1. */
  15379. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15380. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15381. 0x00, 0x00, 0xAB, 0xCD
  15382. };
  15383. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15384. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15385. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15386. };
  15387. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15388. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15389. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15390. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15391. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15392. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15393. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15394. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15395. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15396. };
  15397. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15398. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15399. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15400. 0xAB, 0xAD, 0xDA, 0xD2
  15401. };
  15402. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15403. 0x48, 0xAF, 0x93, 0x50, 0x1F, 0xA6, 0x2A, 0xDB,
  15404. 0xCD, 0x41, 0x4C, 0xCE, 0x60, 0x34, 0xD8, 0x95,
  15405. 0xDD, 0xA1, 0xBF, 0x8F, 0x13, 0x2F, 0x04, 0x20,
  15406. 0x98, 0x66, 0x15, 0x72, 0xE7, 0x48, 0x30, 0x94,
  15407. 0xFD, 0x12, 0xE5, 0x18, 0xCE, 0x06, 0x2C, 0x98,
  15408. 0xAC, 0xEE, 0x28, 0xD9, 0x5D, 0xF4, 0x41, 0x6B,
  15409. 0xED, 0x31, 0xA2, 0xF0, 0x44, 0x76, 0xC1, 0x8B,
  15410. 0xB4, 0x0C, 0x84, 0xA7, 0x4B, 0x97, 0xDC, 0x5B
  15411. };
  15412. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15413. 0x16, 0x84, 0x2D, 0x4F, 0xA1, 0x86, 0xF5, 0x6A,
  15414. 0xB3, 0x32, 0x56, 0x97, 0x1F, 0xA1, 0x10, 0xF4
  15415. };
  15416. wc_Sm4 sm4;
  15417. byte enc[SM4_BLOCK_SIZE * 4];
  15418. byte dec[SM4_BLOCK_SIZE * 4];
  15419. byte tag[SM4_BLOCK_SIZE];
  15420. int ret;
  15421. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15422. if (ret != 0)
  15423. return WC_TEST_RET_ENC_EC(ret);
  15424. /* Encrypt and decrypt using encrypt with CCM. */
  15425. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15426. if (ret != 0)
  15427. return WC_TEST_RET_ENC_EC(ret);
  15428. ret = wc_Sm4CcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15429. sizeof(tag), a1, sizeof(a1));
  15430. if (ret != 0)
  15431. return WC_TEST_RET_ENC_EC(ret);
  15432. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15433. return WC_TEST_RET_ENC_NC;
  15434. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15435. return WC_TEST_RET_ENC_NC;
  15436. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15437. sizeof(tag), a1, sizeof(a1));
  15438. if (ret != 0)
  15439. return WC_TEST_RET_ENC_EC(ret);
  15440. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15441. return WC_TEST_RET_ENC_NC;
  15442. /* RFC8998 test vector. */
  15443. ret = wc_Sm4SetKey(&sm4, k2, sizeof(k2));
  15444. if (ret != 0)
  15445. return WC_TEST_RET_ENC_EC(ret);
  15446. ret = wc_Sm4CcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15447. sizeof(tag), a2, sizeof(a2));
  15448. if (ret != 0)
  15449. return WC_TEST_RET_ENC_EC(ret);
  15450. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15451. return WC_TEST_RET_ENC_NC;
  15452. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15453. return WC_TEST_RET_ENC_NC;
  15454. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15455. sizeof(tag), a2, sizeof(a2));
  15456. if (ret != 0)
  15457. return WC_TEST_RET_ENC_EC(ret);
  15458. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15459. return WC_TEST_RET_ENC_NC;
  15460. wc_Sm4Free(&sm4);
  15461. return 0;
  15462. }
  15463. #endif
  15464. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void)
  15465. {
  15466. wc_test_ret_t ret;
  15467. WOLFSSL_ENTER("sm4_test");
  15468. #ifdef WOLFSSL_SM4_ECB
  15469. ret = sm4_ecb_test();
  15470. if (ret != 0)
  15471. return ret;
  15472. #endif
  15473. #ifdef WOLFSSL_SM4_CBC
  15474. ret = sm4_cbc_test();
  15475. if (ret != 0)
  15476. return ret;
  15477. #endif
  15478. #ifdef WOLFSSL_SM4_CTR
  15479. ret = sm4_ctr_test();
  15480. if (ret != 0)
  15481. return ret;
  15482. #endif
  15483. #ifdef WOLFSSL_SM4_GCM
  15484. ret = sm4_gcm_test();
  15485. if (ret != 0)
  15486. return ret;
  15487. #endif
  15488. #ifdef WOLFSSL_SM4_CCM
  15489. ret = sm4_ccm_test();
  15490. if (ret != 0)
  15491. return ret;
  15492. #endif
  15493. return 0;
  15494. }
  15495. #endif
  15496. #ifdef HAVE_XCHACHA
  15497. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void) {
  15498. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15499. 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */
  15500. 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, /* unced "dole") is */
  15501. 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, /* also known as t */
  15502. 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, /* he Asiatic wild */
  15503. 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, /* dog, red dog, an */
  15504. 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, /* d whistling dog. */
  15505. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, /* It is about the */
  15506. 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, /* size of a Germa */
  15507. 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, /* n shepherd but l */
  15508. 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, /* ooks more like a */
  15509. 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, /* long-legged fox */
  15510. 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, /* . This highly el */
  15511. 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, /* usive and skille */
  15512. 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, /* d jumper is clas */
  15513. 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, /* sified with wolv */
  15514. 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, /* es, coyotes, jac */
  15515. 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, /* kals, and foxes */
  15516. 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, /* in the taxonomic */
  15517. 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e /* family Canidae. */
  15518. };
  15519. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15520. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15521. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15522. };
  15523. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15524. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15525. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 }; /* PQRSTUVW */
  15526. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15527. 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f,
  15528. 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9,
  15529. 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa,
  15530. 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d,
  15531. 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a,
  15532. 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda,
  15533. 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31,
  15534. 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44,
  15535. 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b,
  15536. 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40,
  15537. 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e,
  15538. 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c,
  15539. 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41,
  15540. 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae,
  15541. 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa,
  15542. 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c,
  15543. 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20,
  15544. 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63,
  15545. 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5
  15546. };
  15547. wc_test_ret_t ret;
  15548. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15549. struct ChaCha *chacha = (struct ChaCha *)XMALLOC(sizeof *chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15550. byte *buf1 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15551. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15552. WOLFSSL_ENTER("XChaCha_test");
  15553. if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL))
  15554. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15555. #else
  15556. struct ChaCha chacha[1];
  15557. byte buf1[sizeof Plaintext];
  15558. byte buf2[sizeof Plaintext];
  15559. WOLFSSL_ENTER("XChaCha_test");
  15560. #endif
  15561. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15562. if (ret < 0)
  15563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15564. ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext);
  15565. if (ret < 0)
  15566. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15567. if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext))
  15568. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15569. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15570. if (ret < 0)
  15571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15572. ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext);
  15573. if (ret < 0)
  15574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15575. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15576. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15577. out:
  15578. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15579. XFREE(chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15580. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15581. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15582. #endif
  15583. return ret;
  15584. }
  15585. #endif /* HAVE_XCHACHA */
  15586. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  15587. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void) {
  15588. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15589. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, /* Ladies and Gentl */
  15590. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, /* emen of the clas */
  15591. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, /* s of '99: If I c */
  15592. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, /* ould offer you o */
  15593. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, /* nly one tip for */
  15594. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, /* the future, suns */
  15595. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, /* creen would be i */
  15596. 0x74, 0x2e }; /* t. */
  15597. WOLFSSL_SMALL_STACK_STATIC const byte AAD[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; /* PQRS........ */
  15598. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15599. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15600. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15601. };
  15602. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15603. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15604. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }; /* PQRSTUVW */
  15605. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15606. 0xbd, 0x6d, 0x17, 0x9d, 0x3e, 0x83, 0xd4, 0x3b, 0x95, 0x76, 0x57, 0x94, 0x93, 0xc0, 0xe9, 0x39,
  15607. 0x57, 0x2a, 0x17, 0x00, 0x25, 0x2b, 0xfa, 0xcc, 0xbe, 0xd2, 0x90, 0x2c, 0x21, 0x39, 0x6c, 0xbb,
  15608. 0x73, 0x1c, 0x7f, 0x1b, 0x0b, 0x4a, 0xa6, 0x44, 0x0b, 0xf3, 0xa8, 0x2f, 0x4e, 0xda, 0x7e, 0x39,
  15609. 0xae, 0x64, 0xc6, 0x70, 0x8c, 0x54, 0xc2, 0x16, 0xcb, 0x96, 0xb7, 0x2e, 0x12, 0x13, 0xb4, 0x52,
  15610. 0x2f, 0x8c, 0x9b, 0xa4, 0x0d, 0xb5, 0xd9, 0x45, 0xb1, 0x1b, 0x69, 0xb9, 0x82, 0xc1, 0xbb, 0x9e,
  15611. 0x3f, 0x3f, 0xac, 0x2b, 0xc3, 0x69, 0x48, 0x8f, 0x76, 0xb2, 0x38, 0x35, 0x65, 0xd3, 0xff, 0xf9,
  15612. 0x21, 0xf9, 0x66, 0x4c, 0x97, 0x63, 0x7d, 0xa9, 0x76, 0x88, 0x12, 0xf6, 0x15, 0xc6, 0x8b, 0x13,
  15613. 0xb5, 0x2e };
  15614. WOLFSSL_SMALL_STACK_STATIC const byte Tag[] = {
  15615. 0xc0, 0x87, 0x59, 0x24, 0xc1, 0xc7, 0x98, 0x79, 0x47, 0xde, 0xaf, 0xd8, 0x78, 0x0a, 0xcf, 0x49
  15616. };
  15617. wc_test_ret_t ret;
  15618. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15619. byte *buf1 = (byte *)XMALLOC(sizeof Ciphertext + sizeof Tag, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15620. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15621. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15622. if ((buf1 == NULL) || (buf2 == NULL))
  15623. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15624. #else
  15625. byte buf1[sizeof Ciphertext + sizeof Tag];
  15626. byte buf2[sizeof Plaintext];
  15627. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15628. #endif
  15629. ret = wc_XChaCha20Poly1305_Encrypt(buf1, sizeof Ciphertext + sizeof Tag,
  15630. Plaintext, sizeof Plaintext,
  15631. AAD, sizeof AAD,
  15632. IV, sizeof IV,
  15633. Key, sizeof Key);
  15634. if (ret < 0)
  15635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15636. if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext))
  15637. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15638. if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE))
  15639. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15640. ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext,
  15641. buf1, sizeof Ciphertext + sizeof Tag,
  15642. AAD, sizeof AAD,
  15643. IV, sizeof IV,
  15644. Key, sizeof Key);
  15645. if (ret < 0)
  15646. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15647. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15648. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15649. out:
  15650. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15651. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15652. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15653. #endif
  15654. return ret;
  15655. }
  15656. #endif /* defined(HAVE_XCHACHA) && defined(HAVE_POLY1305) */
  15657. #ifndef WC_NO_RNG
  15658. static wc_test_ret_t _rng_test(WC_RNG* rng)
  15659. {
  15660. byte block[32];
  15661. wc_test_ret_t ret;
  15662. int i;
  15663. XMEMSET(block, 0, sizeof(block));
  15664. ret = wc_RNG_GenerateBlock(rng, block, sizeof(block));
  15665. if (ret != 0) {
  15666. return WC_TEST_RET_ENC_EC(ret);
  15667. }
  15668. /* Check for 0's */
  15669. for (i=0; i<(int)sizeof(block); i++) {
  15670. if (block[i] == 0) {
  15671. ret++;
  15672. }
  15673. }
  15674. /* All zeros count check */
  15675. if (ret >= (int)sizeof(block)) {
  15676. return WC_TEST_RET_ENC_NC;
  15677. }
  15678. ret = wc_RNG_GenerateByte(rng, block);
  15679. if (ret != 0) {
  15680. return WC_TEST_RET_ENC_EC(ret);
  15681. }
  15682. /* Parameter validation testing. */
  15683. ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block));
  15684. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15685. return WC_TEST_RET_ENC_EC(ret);
  15686. }
  15687. ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block));
  15688. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15689. return WC_TEST_RET_ENC_EC(ret);
  15690. }
  15691. ret = wc_RNG_GenerateByte(NULL, block);
  15692. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15693. return WC_TEST_RET_ENC_EC(ret);
  15694. }
  15695. ret = wc_RNG_GenerateByte(rng, NULL);
  15696. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15697. return WC_TEST_RET_ENC_EC(ret);
  15698. }
  15699. return 0;
  15700. }
  15701. static wc_test_ret_t random_rng_test(void)
  15702. {
  15703. WC_RNG localRng;
  15704. WC_RNG* rng;
  15705. wc_test_ret_t ret;
  15706. rng = &localRng;
  15707. /* Test stack based RNG. */
  15708. #ifndef HAVE_FIPS
  15709. ret = wc_InitRng_ex(rng, HEAP_HINT, devId);
  15710. #else
  15711. ret = wc_InitRng(rng);
  15712. #endif
  15713. if (ret != 0)
  15714. return WC_TEST_RET_ENC_EC(ret);
  15715. ret = _rng_test(rng);
  15716. /* Make sure and free RNG */
  15717. wc_FreeRng(rng);
  15718. if (ret != 0)
  15719. return ret;
  15720. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
  15721. {
  15722. byte nonce[8] = { 0 };
  15723. /* Test dynamic RNG */
  15724. rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
  15725. if (rng == NULL)
  15726. return WC_TEST_RET_ENC_ERRNO;
  15727. ret = _rng_test(rng);
  15728. wc_rng_free(rng);
  15729. rng = NULL;
  15730. if (ret != 0)
  15731. return ret;
  15732. /* Test dynamic RNG using extended API */
  15733. ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
  15734. HEAP_HINT, devId);
  15735. if (ret != 0)
  15736. return WC_TEST_RET_ENC_EC(ret);
  15737. ret = _rng_test(rng);
  15738. wc_rng_free(rng);
  15739. if (ret != 0)
  15740. return ret;
  15741. }
  15742. #endif
  15743. return ret;
  15744. }
  15745. #if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  15746. #ifdef WC_RNG_SEED_CB
  15747. static int seed_cb(OS_Seed* os, byte* output, word32 sz)
  15748. {
  15749. word32 i;
  15750. (void)os;
  15751. /* Known answer test. Set the seed to the same value every time. */
  15752. for (i = 0; i < sz; i++)
  15753. output[i] = (byte)i;
  15754. return 0;
  15755. }
  15756. static wc_test_ret_t rng_seed_test(void)
  15757. {
  15758. #ifndef HAVE_FIPS
  15759. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15760. {
  15761. 0x83, 0x46, 0x65, 0x2f, 0x5c, 0x44, 0x16, 0x5f,
  15762. 0xb3, 0x89, 0x26, 0xde, 0x0b, 0x6b, 0xa2, 0x06,
  15763. 0x7e, 0xa7, 0x9a, 0x55, 0x22, 0x01, 0xb0, 0x22,
  15764. 0xf4, 0x7e, 0xa2, 0x66, 0xc4, 0x08, 0x6f, 0xba
  15765. };
  15766. #else
  15767. /* FIPS uses a longer seed, so different check value. */
  15768. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15769. {
  15770. 0xaf, 0x31, 0xcc, 0xef, 0xa9, 0x29, 0x4c, 0x24,
  15771. 0xbd, 0xa5, 0xa3, 0x52, 0x69, 0xf3, 0xb9, 0xb2,
  15772. 0x1e, 0xd4, 0x52, 0x3b, 0x9a, 0x96, 0x06, 0x20,
  15773. 0xc0, 0x5f, 0x44, 0x06, 0x1f, 0x80, 0xdf, 0xe0
  15774. };
  15775. #endif
  15776. byte output[WC_SHA256_DIGEST_SIZE];
  15777. WC_RNG rng;
  15778. wc_test_ret_t ret;
  15779. ret = wc_SetSeed_Cb(seed_cb);
  15780. if (ret != 0) {
  15781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15782. }
  15783. ret = wc_InitRng(&rng);
  15784. if (ret != 0) {
  15785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15786. }
  15787. ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output));
  15788. if (ret != 0) {
  15789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15790. }
  15791. ret = XMEMCMP(output, check, sizeof(output));
  15792. if (ret != 0) {
  15793. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15794. }
  15795. ret = wc_FreeRng(&rng);
  15796. if (ret != 0) {
  15797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15798. }
  15799. ret = wc_SetSeed_Cb(wc_GenerateSeed);
  15800. if (ret != 0) {
  15801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15802. }
  15803. out:
  15804. return ret;
  15805. }
  15806. #endif
  15807. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15808. {
  15809. WOLFSSL_SMALL_STACK_STATIC const byte test1Entropy[] =
  15810. {
  15811. 0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e, 0xff, 0xe8, 0x75, 0xc3,
  15812. 0xa2, 0xe7, 0x1f, 0x42, 0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
  15813. 0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb, 0x85, 0x81, 0xf9, 0x31,
  15814. 0x75, 0x17, 0x27, 0x6e, 0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
  15815. };
  15816. WOLFSSL_SMALL_STACK_STATIC const byte test1Output[] =
  15817. {
  15818. 0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40, 0xb2, 0x62, 0x82, 0x64,
  15819. 0xd1, 0x75, 0x10, 0x60, 0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
  15820. 0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d, 0xaa, 0xf6, 0xa6, 0xc3,
  15821. 0x5a, 0x91, 0xbb, 0x45, 0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
  15822. 0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed, 0x52, 0x8f, 0x01, 0x81,
  15823. 0x21, 0xb3, 0xfe, 0xbd, 0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
  15824. 0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1, 0x77, 0xcf, 0xa6, 0xb7,
  15825. 0x1f, 0xe8, 0xab, 0x1d, 0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
  15826. 0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99, 0x0e, 0xea, 0xeb, 0x91,
  15827. 0x12, 0x04, 0x15, 0x52, 0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
  15828. 0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
  15829. };
  15830. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyA[] =
  15831. {
  15832. 0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46, 0x8d, 0xeb, 0x0a, 0xb4,
  15833. 0xa8, 0xed, 0x68, 0x3f, 0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
  15834. 0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69, 0x80, 0x8a, 0xa3, 0x8f,
  15835. 0x2a, 0x72, 0xa6, 0x23, 0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
  15836. };
  15837. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyB[] =
  15838. {
  15839. 0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6, 0x98, 0x05, 0x66, 0xe3,
  15840. 0xbf, 0xe3, 0xc0, 0x49, 0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
  15841. 0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
  15842. };
  15843. WOLFSSL_SMALL_STACK_STATIC const byte test2Output[] =
  15844. {
  15845. 0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c, 0x63, 0x0a, 0x1a, 0xfb,
  15846. 0xe7, 0x24, 0x94, 0x9d, 0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
  15847. 0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62, 0x1c, 0x18, 0xbd, 0xdc,
  15848. 0xdd, 0x8d, 0x99, 0xfc, 0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
  15849. 0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1, 0xdd, 0xd6, 0xc0, 0x71,
  15850. 0x31, 0x8a, 0x60, 0x18, 0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
  15851. 0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10, 0x5d, 0x92, 0x99, 0xb8,
  15852. 0xaf, 0x99, 0xaa, 0x07, 0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
  15853. 0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09, 0x88, 0x96, 0xff, 0x22,
  15854. 0x82, 0xc9, 0x55, 0xa8, 0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
  15855. 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
  15856. };
  15857. byte output[WC_SHA256_DIGEST_SIZE * 4];
  15858. wc_test_ret_t ret;
  15859. WOLFSSL_ENTER("random_test");
  15860. ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
  15861. output, sizeof(output));
  15862. if (ret != 0)
  15863. return WC_TEST_RET_ENC_EC(ret);
  15864. if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
  15865. return WC_TEST_RET_ENC_NC;
  15866. ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
  15867. test2EntropyB, sizeof(test2EntropyB),
  15868. output, sizeof(output));
  15869. if (ret != 0)
  15870. return WC_TEST_RET_ENC_EC(ret);
  15871. if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
  15872. return WC_TEST_RET_ENC_NC;
  15873. /* Basic RNG generate block test */
  15874. if ((ret = random_rng_test()) != 0)
  15875. return ret;
  15876. /* Test the seed check function. */
  15877. #if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
  15878. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  15879. {
  15880. word32 i, outputSz;
  15881. /* Repeat the same byte over and over. Should fail. */
  15882. outputSz = sizeof(output);
  15883. XMEMSET(output, 1, outputSz);
  15884. ret = wc_RNG_TestSeed(output, outputSz);
  15885. if (ret == 0)
  15886. return WC_TEST_RET_ENC_NC;
  15887. /* Every byte of the entropy scratch is different,
  15888. * entropy is a single byte that shouldn't match. */
  15889. outputSz = (sizeof(output) / 2) + 1;
  15890. for (i = 0; i < outputSz; i++)
  15891. output[i] = (byte)i;
  15892. ret = wc_RNG_TestSeed(output, outputSz);
  15893. if (ret != 0)
  15894. return WC_TEST_RET_ENC_EC(ret);
  15895. outputSz = sizeof(output);
  15896. for (i = 0; i < outputSz; i++)
  15897. output[i] = (byte)i;
  15898. ret = wc_RNG_TestSeed(output, outputSz);
  15899. if (ret != 0)
  15900. return WC_TEST_RET_ENC_EC(ret);
  15901. }
  15902. #endif
  15903. /* Test the seed callback. */
  15904. #ifdef WC_RNG_SEED_CB
  15905. if ((ret = rng_seed_test()) != 0)
  15906. return ret;
  15907. #endif
  15908. return 0;
  15909. }
  15910. #else
  15911. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15912. {
  15913. WOLFSSL_ENTER("random_test");
  15914. /* Basic RNG generate block test */
  15915. return random_rng_test();
  15916. }
  15917. #endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
  15918. #endif /* WC_NO_RNG */
  15919. #ifndef MEM_TEST_SZ
  15920. #define MEM_TEST_SZ 1024
  15921. #endif
  15922. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15923. static int simple_mem_test(size_t sz)
  15924. {
  15925. int ret = 0;
  15926. byte* b;
  15927. int i;
  15928. b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15929. if (b == NULL) {
  15930. return WC_TEST_RET_ENC_NC;
  15931. }
  15932. /* utilize memory */
  15933. for (i = 0; i < (int)sz; i++) {
  15934. b[i] = (byte)i;
  15935. }
  15936. /* read back and verify */
  15937. for (i = 0; i < (int)sz; i++) {
  15938. if (b[i] != (byte)i) {
  15939. ret = WC_TEST_RET_ENC_NC;
  15940. break;
  15941. }
  15942. }
  15943. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15944. return ret;
  15945. }
  15946. #endif
  15947. /* If successful, returns the first letter of the byte array `in`.
  15948. **
  15949. ** This is a deceptively simple test of a read-only embedded Linux file system.
  15950. ** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
  15951. ** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
  15952. ** Const is on read-only memory-mapped file system, *not* loaded in app memory.
  15953. **
  15954. ** Edit with caution. See PR #6523. */
  15955. static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
  15956. {
  15957. wc_test_ret_t ret = 0;
  15958. volatile word32 j = (word32)-1; /* must be volatile to properly detect error */
  15959. ret = (wc_test_ret_t)*in; /* accessed *in value. */
  15960. (void)ret;
  15961. j = *outJ; /* Found index to use in const array. */
  15962. if (j == 0) {
  15963. #ifdef WOLFSSL_DEBUG
  15964. printf("Testing const byte ptr reference...\n");
  15965. #endif
  15966. /* although j is zero, in[0] does not detect the Illegal instruction */
  15967. ret = in[j]; /* The big test: can we actually access the `in` data? */
  15968. }
  15969. else {
  15970. ret = WC_TEST_RET_ENC_I(j);
  15971. }
  15972. return ret;
  15973. }
  15974. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
  15975. {
  15976. wc_test_ret_t ret = 0;
  15977. word32 j = 0; /* used in embedded const pointer test */
  15978. WOLFSSL_ENTER("memory_test");
  15979. #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
  15980. int i;
  15981. #endif
  15982. #ifdef WOLFSSL_STATIC_MEMORY
  15983. word32 size[] = { WOLFMEM_BUCKETS };
  15984. word32 dist[] = { WOLFMEM_DIST };
  15985. byte buffer[30000]; /* make large enough to involve many bucket sizes */
  15986. int pad = -(int)((wc_ptr_t)buffer) & (WOLFSSL_STATIC_ALIGN - 1);
  15987. /* pad to account for if head of buffer is not at set memory
  15988. * alignment when tests are ran */
  15989. #endif
  15990. #ifdef WOLFSSL_STATIC_MEMORY
  15991. /* check macro settings */
  15992. if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15993. return WC_TEST_RET_ENC_NC;
  15994. }
  15995. if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15996. return WC_TEST_RET_ENC_NC;
  15997. }
  15998. if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
  15999. return WC_TEST_RET_ENC_NC;
  16000. }
  16001. for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
  16002. if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
  16003. /* each element in array should be divisible by alignment size */
  16004. return WC_TEST_RET_ENC_NC;
  16005. }
  16006. }
  16007. for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
  16008. if (size[i - 1] >= size[i]) {
  16009. return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
  16010. }
  16011. }
  16012. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  16013. /* check that padding size returned is possible */
  16014. if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) {
  16015. return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */
  16016. }
  16017. ret = wolfSSL_MemoryPaddingSz();
  16018. if (ret < 0) {
  16019. return WC_TEST_RET_ENC_EC(ret);
  16020. }
  16021. if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) {
  16022. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16023. }
  16024. /* check function to return optimum buffer size (rounded down) */
  16025. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL);
  16026. if (ret < 0) {
  16027. return WC_TEST_RET_ENC_EC(ret);
  16028. }
  16029. if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) {
  16030. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16031. }
  16032. if ((unsigned int)ret > sizeof(buffer)) {
  16033. return WC_TEST_RET_ENC_NC; /* did not round down as expected */
  16034. }
  16035. if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) {
  16036. return WC_TEST_RET_ENC_NC; /* return value changed when using suggested
  16037. * value
  16038. */
  16039. }
  16040. ret = wolfSSL_MemoryPaddingSz();
  16041. ret += pad; /* add space that is going to be needed if buffer not aligned */
  16042. if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) !=
  16043. (ret + (int)size[0])) {
  16044. return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket
  16045. * value
  16046. */
  16047. }
  16048. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL);
  16049. if ((ret - pad) < 0) {
  16050. return WC_TEST_RET_ENC_NC;
  16051. }
  16052. if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) {
  16053. return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */
  16054. }
  16055. if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) {
  16056. return WC_TEST_RET_ENC_NC; /* memory not aligned */
  16057. }
  16058. /* check for passing bad or unknown arguments to functions */
  16059. if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) {
  16060. return WC_TEST_RET_ENC_NC;
  16061. }
  16062. if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) {
  16063. return WC_TEST_RET_ENC_NC; /* should round to 0
  16064. since struct + bucket will not fit */
  16065. }
  16066. #endif
  16067. (void)pad;
  16068. (void)dist; /* avoid static analysis warning of variable not used */
  16069. #endif
  16070. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  16071. /* simple test */
  16072. ret = simple_mem_test((size_t)MEM_TEST_SZ);
  16073. if (ret != 0)
  16074. return ret;
  16075. #endif
  16076. #ifdef COMPLEX_MEM_TEST
  16077. /* test various size blocks */
  16078. for (i = 1; i < MEM_TEST_SZ; i*=2) {
  16079. ret = simple_mem_test((size_t)i);
  16080. if (ret != 0)
  16081. return ret;
  16082. }
  16083. #endif
  16084. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC)
  16085. /* realloc test */
  16086. {
  16087. byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT,
  16088. DYNAMIC_TYPE_TMP_BUFFER);
  16089. #ifndef WOLFSSL_NO_REALLOC
  16090. byte *c = NULL;
  16091. if (b) {
  16092. c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT,
  16093. DYNAMIC_TYPE_TMP_BUFFER);
  16094. if (c)
  16095. b = c;
  16096. }
  16097. #endif
  16098. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16099. if (b == NULL
  16100. #ifndef WOLFSSL_NO_REALLOC
  16101. || c == NULL
  16102. #endif
  16103. ) {
  16104. return WC_TEST_RET_ENC_ERRNO;
  16105. }
  16106. }
  16107. #endif
  16108. if (ret == 0) {
  16109. /* This test is only interesting on embedded R/O Flash systems */
  16110. if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
  16111. ret = 1;
  16112. }
  16113. }
  16114. return ret;
  16115. }
  16116. #ifndef NO_FILESYSTEM
  16117. /* Cert Paths */
  16118. #ifdef FREESCALE_MQX
  16119. #define CERT_PREFIX "a:\\"
  16120. #define CERT_PATH_SEP "\\"
  16121. #elif defined(WOLFSSL_uTKERNEL2)
  16122. #define CERT_PREFIX "/uda/"
  16123. #define CERT_PATH_SEP "/"
  16124. #elif defined(_WIN32_WCE)
  16125. #define CERT_PREFIX "\\windows\\"
  16126. #define CERT_PATH_SEP "\\"
  16127. #elif defined(WOLFSSL_NDS)
  16128. #undef CERT_PREFIX
  16129. #ifndef WOLFSSL_MELONDS
  16130. #define CERT_PREFIX "fat:/_nds/"
  16131. #else
  16132. #define CERT_PREFIX "_nds/"
  16133. #endif
  16134. #define CERT_PATH_SEP "/"
  16135. #endif
  16136. #ifndef CERT_PREFIX
  16137. #define CERT_PREFIX "./"
  16138. #endif
  16139. #ifndef CERT_PATH_SEP
  16140. #define CERT_PATH_SEP "/"
  16141. #endif
  16142. #ifndef CERT_WRITE_TEMP_DIR
  16143. #define CERT_WRITE_TEMP_DIR CERT_PREFIX
  16144. #endif
  16145. #define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
  16146. /* Generated Test Certs */
  16147. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16148. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16149. #if !defined(NO_RSA) && !defined(NO_ASN)
  16150. static const char* clientKey = CERT_ROOT "client-key.der";
  16151. static const char* clientCert = CERT_ROOT "client-cert.der";
  16152. #ifdef WOLFSSL_CERT_EXT
  16153. static const char* clientKeyPub = CERT_ROOT "client-keyPub.der";
  16154. #endif
  16155. #endif /* !NO_RSA && !NO_ASN */
  16156. #endif
  16157. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16158. #if !defined(NO_RSA) && !defined(NO_ASN)
  16159. #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_PKCS7)
  16160. static const char* rsaCaKeyFile = CERT_ROOT "ca-key.der";
  16161. #ifdef WOLFSSL_CERT_GEN
  16162. static const char* rsaCaCertFile = CERT_ROOT "ca-cert.pem";
  16163. #endif
  16164. #if (defined(WOLFSSL_ALT_NAMES) && !defined(WOLFSSL_NO_MALLOC)) || \
  16165. defined(HAVE_PKCS7)
  16166. static const char* rsaCaCertDerFile = CERT_ROOT "ca-cert.der";
  16167. #endif
  16168. #ifdef HAVE_PKCS7
  16169. static const char* rsaServerCertDerFile =
  16170. CERT_ROOT "server-cert.der";
  16171. static const char* rsaServerKeyDerFile =
  16172. CERT_ROOT "server-key.der";
  16173. #endif
  16174. #endif
  16175. #endif /* !NO_RSA && !NO_ASN */
  16176. #endif /* !USE_CERT_BUFFER_* */
  16177. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16178. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16179. #if !defined(NO_ASN) && !defined(NO_DH)
  16180. static const char* dhParamsFile = CERT_ROOT "dh2048.der";
  16181. #endif
  16182. #endif
  16183. #if !defined(NO_ASN) && !defined(NO_DH)
  16184. #if defined(WOLFSSL_DH_EXTRA) && (!defined(HAVE_FIPS) || \
  16185. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  16186. #if !defined(USE_CERT_BUFFERS_2048)
  16187. static const char* dhKeyFile = CERT_ROOT "statickeys/dh-ffdhe2048.der";
  16188. static const char* dhKeyPubFile = CERT_ROOT "statickeys/dh-ffdhe2048-pub.der";
  16189. #endif
  16190. #endif
  16191. #endif
  16192. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16193. #ifndef NO_DSA
  16194. static const char* dsaKey = CERT_ROOT "dsa2048.der";
  16195. #endif
  16196. #endif /* !USE_CERT_BUFFER_* */
  16197. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ECC256)
  16198. #ifdef HAVE_ECC
  16199. /* cert files to be used in rsa cert gen test, check if RSA enabled */
  16200. #ifdef HAVE_ECC_KEY_IMPORT
  16201. static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der";
  16202. #endif
  16203. #endif
  16204. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN)
  16205. #if defined(HAVE_ECC) && defined(WOLFSSL_CERT_GEN) && \
  16206. !defined(NO_ECC_SECP)
  16207. #ifndef NO_RSA
  16208. static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der";
  16209. #endif
  16210. #if !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  16211. static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der";
  16212. static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem";
  16213. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16214. static const char* eccCaKey384File =
  16215. CERT_ROOT "ca-ecc384-key.der";
  16216. static const char* eccCaCert384File =
  16217. CERT_ROOT "ca-ecc384-cert.pem";
  16218. #endif
  16219. #endif
  16220. #endif
  16221. #if defined(HAVE_PKCS7) && defined(HAVE_ECC)
  16222. static const char* eccClientKey = CERT_ROOT "ecc-client-key.der";
  16223. static const char* eccClientCert = CERT_ROOT "client-ecc-cert.der";
  16224. #endif
  16225. #endif /* HAVE_ECC */
  16226. #ifdef HAVE_ED25519
  16227. #ifdef WOLFSSL_TEST_CERT
  16228. static const char* serverEd25519Cert =
  16229. CERT_ROOT "ed25519/server-ed25519.der";
  16230. static const char* caEd25519Cert =
  16231. CERT_ROOT "ed25519/ca-ed25519.der";
  16232. #endif
  16233. #endif
  16234. #ifdef HAVE_ED448
  16235. #ifdef WOLFSSL_TEST_CERT
  16236. static const char* serverEd448Cert =
  16237. CERT_ROOT "ed448/server-ed448.der";
  16238. static const char* caEd448Cert = CERT_ROOT "ed448/ca-ed448.der";
  16239. #endif
  16240. #endif
  16241. #endif /* !USE_CERT_BUFFER_* */
  16242. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16243. !defined(NO_FILESYSTEM)
  16244. static const char* certExtNc =
  16245. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nc.der";
  16246. static const char* certExtIa =
  16247. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-ia.der";
  16248. static const char* certExtNct =
  16249. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nct.der";
  16250. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16251. static const char* certBadNegInt =
  16252. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-neg-int.der";
  16253. #endif
  16254. static const char* certBadOid =
  16255. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-oid.der";
  16256. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16257. static const char* certBadUtf8 =
  16258. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-utf8.der";
  16259. #endif
  16260. #endif
  16261. #ifndef NO_WRITE_TEMP_FILES
  16262. #ifdef HAVE_ECC
  16263. #ifndef NO_ECC_SECP
  16264. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16265. !defined(WOLFSSL_NO_MALLOC)
  16266. static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem";
  16267. static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
  16268. #endif
  16269. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  16270. static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
  16271. static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
  16272. #endif
  16273. #endif
  16274. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  16275. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT)
  16276. static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem";
  16277. static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
  16278. static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
  16279. #if defined(HAVE_PKCS8) && !defined(WC_NO_RNG) && \
  16280. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  16281. static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
  16282. #endif
  16283. #endif /* HAVE_ECC_KEY_EXPORT */
  16284. #endif /* HAVE_ECC */
  16285. #ifndef NO_RSA
  16286. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16287. !defined(WOLFSSL_NO_MALLOC)
  16288. static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
  16289. static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
  16290. static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
  16291. static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
  16292. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  16293. static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
  16294. static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
  16295. #endif
  16296. #endif
  16297. #endif /* !NO_RSA */
  16298. #if !defined(NO_RSA) || !defined(NO_DSA)
  16299. #ifdef WOLFSSL_KEY_GEN
  16300. static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
  16301. static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
  16302. #endif
  16303. #endif
  16304. #endif /* !NO_WRITE_TEMP_FILES */
  16305. #endif /* !NO_FILESYSTEM */
  16306. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  16307. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  16308. static CertName certDefaultName;
  16309. static void initDefaultName(void)
  16310. {
  16311. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16312. NameAttrib* n;
  16313. #endif
  16314. XMEMCPY(certDefaultName.country, "US", sizeof("US"));
  16315. certDefaultName.countryEnc = CTC_PRINTABLE;
  16316. XMEMCPY(certDefaultName.state, "Oregon", sizeof("Oregon"));
  16317. certDefaultName.stateEnc = CTC_UTF8;
  16318. XMEMCPY(certDefaultName.street, "Main St", sizeof("Main St"));
  16319. certDefaultName.streetEnc = CTC_UTF8;
  16320. XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
  16321. certDefaultName.localityEnc = CTC_UTF8;
  16322. XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
  16323. certDefaultName.surEnc = CTC_UTF8;
  16324. XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
  16325. certDefaultName.orgEnc = CTC_UTF8;
  16326. XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
  16327. certDefaultName.unitEnc = CTC_UTF8;
  16328. XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  16329. certDefaultName.commonNameEnc = CTC_UTF8;
  16330. XMEMCPY(certDefaultName.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  16331. certDefaultName.serialDevEnc = CTC_PRINTABLE;
  16332. XMEMCPY(certDefaultName.postalCode, "12-456", sizeof("12-456"));
  16333. certDefaultName.postalCodeEnc = CTC_PRINTABLE;
  16334. #ifdef WOLFSSL_CERT_EXT
  16335. XMEMCPY(certDefaultName.busCat, "Private Organization", sizeof("Private Organization"));
  16336. certDefaultName.busCatEnc = CTC_UTF8;
  16337. XMEMCPY(certDefaultName.joiSt, "US", sizeof("US"));
  16338. certDefaultName.joiStEnc = CTC_PRINTABLE;
  16339. XMEMCPY(certDefaultName.joiC, "Oregon", sizeof("Oregon"));
  16340. certDefaultName.joiCEnc = CTC_PRINTABLE;
  16341. #endif
  16342. XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
  16343. XMEMCPY(certDefaultName.userId, "TestUserID", sizeof("TestUserID"));
  16344. certDefaultName.userIdEnc = CTC_PRINTABLE;
  16345. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16346. /* test having additional OUs and setting DC */
  16347. n = &certDefaultName.name[0];
  16348. n->id = ASN_ORGUNIT_NAME;
  16349. n->type = CTC_UTF8;
  16350. n->sz = XSTRLEN("Development-2");
  16351. XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
  16352. #if CTC_MAX_ATTRIB > 3
  16353. n = &certDefaultName.name[1];
  16354. n->id = ASN_DOMAIN_COMPONENT;
  16355. n->type = CTC_UTF8;
  16356. n->sz = XSTRLEN("com");
  16357. XMEMCPY(n->value, "com", sizeof("com"));
  16358. n = &certDefaultName.name[2];
  16359. n->id = ASN_DOMAIN_COMPONENT;
  16360. n->type = CTC_UTF8;
  16361. n->sz = XSTRLEN("wolfssl");
  16362. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  16363. #endif
  16364. #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */
  16365. #ifdef WOLFSSL_CUSTOM_OID
  16366. /* TODO: Add test case for custom OID's */
  16367. #endif
  16368. }
  16369. #ifdef WOLFSSL_CERT_EXT
  16370. #if ((defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  16371. defined(WOLFSSL_TEST_CERT)) || defined(HAVE_ECC)
  16372. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] =
  16373. "digitalSignature,nonRepudiation";
  16374. #endif
  16375. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME)
  16376. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] =
  16377. "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement";
  16378. #endif
  16379. #endif /* WOLFSSL_CERT_EXT */
  16380. #endif /* WOLFSSL_CERT_GEN */
  16381. #ifndef NO_RSA
  16382. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16383. !defined(NO_FILESYSTEM)
  16384. static const byte minSerial[] = { 0x02, 0x01, 0x01 };
  16385. static const byte minName[] = { 0x30, 0x00 };
  16386. static const byte nameBad[] = {
  16387. 0x30, 0x08,
  16388. 0x31, 0x06,
  16389. 0x30, 0x04,
  16390. 0x06, 0x02,
  16391. 0x55, 0x04,
  16392. };
  16393. static const byte minDates[] = {
  16394. 0x30, 0x1e,
  16395. 0x17, 0x0d,
  16396. 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35,
  16397. 0x32, 0x33, 0x31, 0x30, 0x5a,
  16398. 0x17, 0x0d,
  16399. 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35,
  16400. 0x32, 0x33, 0x31, 0x30, 0x5a
  16401. };
  16402. static const byte minPubKey[] = {
  16403. 0x30, 0x1c,
  16404. 0x30, 0x0d,
  16405. 0x06, 0x09,
  16406. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16407. 0x01,
  16408. 0x05, 0x00,
  16409. 0x03, 0x0b,
  16410. 0x00, 0x30, 0x08,
  16411. 0x02, 0x01,
  16412. 0x03,
  16413. 0x02, 0x03,
  16414. 0x01, 0x00, 0x01
  16415. };
  16416. static const byte minSigAlg[] = {
  16417. 0x30, 0x0d,
  16418. 0x06, 0x09,
  16419. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16420. 0x0b,
  16421. 0x05, 0x00
  16422. };
  16423. static const byte minSig[] = {
  16424. 0x03, 0x01,
  16425. 0x00
  16426. };
  16427. static int add_seq(byte* certData, int offset, byte* data, byte length)
  16428. {
  16429. XMEMMOVE(certData + offset + 2, data, length);
  16430. certData[offset++] = 0x30;
  16431. certData[offset++] = length;
  16432. return offset + length;
  16433. }
  16434. static int add_data(byte* certData, int offset, const byte* data, byte length)
  16435. {
  16436. XMEMCPY(certData + offset, data, length);
  16437. return offset + length;
  16438. }
  16439. static wc_test_ret_t cert_asn1_test(void)
  16440. {
  16441. wc_test_ret_t ret;
  16442. int len[3];
  16443. DecodedCert cert;
  16444. byte certData[114];
  16445. byte* badCert = NULL;
  16446. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16447. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16448. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16449. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16450. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16451. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16452. len[1] = add_seq(certData, 0, certData, len[2]);
  16453. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16454. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16455. len[0] = add_seq(certData, 0, certData, len[1]);
  16456. /* Minimal good certificate */
  16457. InitDecodedCert(&cert, certData, len[0], 0);
  16458. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16459. FreeDecodedCert(&cert);
  16460. if (ret != 0)
  16461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16462. /* Bad issuer name */
  16463. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16464. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16465. len[2] = add_data(certData, len[2], nameBad, (byte)sizeof(nameBad));
  16466. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16467. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16468. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16469. len[1] = add_seq(certData, 0, certData, len[2]);
  16470. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16471. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16472. len[0] = add_seq(certData, 0, certData, len[1]);
  16473. /* Put data into allocated buffer to allow access error checking. */
  16474. badCert = (byte*)XMALLOC(len[0], HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16475. XMEMCPY(badCert, certData, len[0]);
  16476. InitDecodedCert(&cert, badCert, len[0], 0);
  16477. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16478. FreeDecodedCert(&cert);
  16479. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  16480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16481. }
  16482. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16483. badCert = NULL;
  16484. ret = 0;
  16485. done:
  16486. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16487. return ret;
  16488. }
  16489. static wc_test_ret_t cert_load_bad(const char* fname, byte* tmp, int err)
  16490. {
  16491. wc_test_ret_t ret;
  16492. DecodedCert cert;
  16493. XFILE file;
  16494. size_t bytes;
  16495. if ((fname == NULL) || (tmp == NULL)) {
  16496. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  16497. }
  16498. file = XFOPEN(fname, "rb");
  16499. if (!file) {
  16500. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16501. }
  16502. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16503. XFCLOSE(file);
  16504. if (bytes == 0) {
  16505. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16506. }
  16507. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16508. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16509. FreeDecodedCert(&cert);
  16510. if (ret != err) {
  16511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16512. }
  16513. ret = 0;
  16514. done:
  16515. return ret;
  16516. }
  16517. static wc_test_ret_t cert_bad_asn1_test(void)
  16518. {
  16519. wc_test_ret_t ret = 0;
  16520. byte* tmp;
  16521. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16522. if (tmp == NULL) {
  16523. ret = WC_TEST_RET_ENC_ERRNO;
  16524. }
  16525. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16526. if (ret == 0) {
  16527. /* Serial number: 0xff 0xa8. 0xff and top bit set on next byte invalid.
  16528. */
  16529. ret = cert_load_bad(certBadNegInt, tmp, ASN_EXPECT_0_E);
  16530. }
  16531. #endif
  16532. if (ret == 0) {
  16533. /* Subject name OID: 55 04 f4. Last byte with top bit set invalid. */
  16534. ret = cert_load_bad(certBadOid, tmp, ASN_PARSE_E);
  16535. }
  16536. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16537. if (ret == 0) {
  16538. /* Issuer name UTF8STRING: df 52 4e 44. Top bit of second byte not set.
  16539. */
  16540. ret = cert_load_bad(certBadUtf8, tmp, ASN_PARSE_E);
  16541. }
  16542. #endif
  16543. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16544. return ret;
  16545. }
  16546. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void)
  16547. {
  16548. #if !defined(NO_FILESYSTEM)
  16549. DecodedCert cert;
  16550. byte* tmp;
  16551. size_t bytes;
  16552. XFILE file;
  16553. wc_test_ret_t ret;
  16554. WOLFSSL_ENTER("cert_test");
  16555. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16556. if (tmp == NULL)
  16557. return WC_TEST_RET_ENC_ERRNO;
  16558. /* Certificate with Name Constraints extension. */
  16559. file = XFOPEN(certExtNc, "rb");
  16560. if (!file) {
  16561. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16562. }
  16563. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16564. XFCLOSE(file);
  16565. if (bytes == 0)
  16566. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16567. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16568. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16569. if (ret != 0)
  16570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16571. FreeDecodedCert(&cert);
  16572. /* Certificate with Inhibit Any Policy extension. */
  16573. file = XFOPEN(certExtIa, "rb");
  16574. if (!file) {
  16575. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16576. }
  16577. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16578. XFCLOSE(file);
  16579. if (bytes == 0)
  16580. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16581. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16582. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16583. if (ret != 0)
  16584. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16585. FreeDecodedCert(&cert);
  16586. /* Certificate with Netscape Certificate Type extension. */
  16587. file = XFOPEN(certExtNct, "rb");
  16588. if (!file) {
  16589. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16590. }
  16591. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16592. XFCLOSE(file);
  16593. if (bytes == 0)
  16594. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16595. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16596. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16597. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  16598. if (ret != 0)
  16599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16600. #else
  16601. if (ret != WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
  16602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16603. }
  16604. ret = 0;
  16605. #endif
  16606. done:
  16607. FreeDecodedCert(&cert);
  16608. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16609. #endif /* !NO_FILESYSTEM */
  16610. if (ret == 0)
  16611. ret = cert_asn1_test();
  16612. if (ret == 0)
  16613. ret = cert_bad_asn1_test();
  16614. return ret;
  16615. }
  16616. #endif /* WOLFSSL_TEST_CERT */
  16617. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  16618. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  16619. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void)
  16620. {
  16621. DecodedCert cert;
  16622. byte* tmp;
  16623. size_t bytes;
  16624. XFILE file;
  16625. wc_test_ret_t ret;
  16626. /* created from rsa_test : othercert.der */
  16627. byte skid_rsa[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16628. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16629. /* created from rsa_test : othercert.der */
  16630. byte akid_rsa[] = "\x27\x8E\x67\x11\x74\xC3\x26\x1D\x3F\xED"
  16631. "\x33\x63\xB3\xA4\xD8\x1D\x30\xE5\xE8\xD5";
  16632. #ifdef HAVE_ECC
  16633. /* created from ecc_test_cert_gen : certecc.der */
  16634. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16635. /* Authority key id from ./certs/ca-ecc384-cert.pem */
  16636. byte akid_ecc[] = "\xAB\xE0\xC3\x26\x4C\x18\xD4\x72\xBB\xD2"
  16637. "\x84\x8C\x9C\x0A\x05\x92\x80\x12\x53\x52";
  16638. #else
  16639. /* Authority key id from ./certs/ca-ecc-cert.pem */
  16640. byte akid_ecc[] = "\x56\x8E\x9A\xC3\xF0\x42\xDE\x18\xB9\x45"
  16641. "\x55\x6E\xF9\x93\xCF\xEA\xC3\xF3\xA5\x21";
  16642. #endif
  16643. #endif /* HAVE_ECC */
  16644. /* created from rsa_test : cert.der */
  16645. byte kid_ca[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16646. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16647. WOLFSSL_ENTER("certext_test");
  16648. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16649. if (tmp == NULL)
  16650. return WC_TEST_RET_ENC_ERRNO;
  16651. /* load othercert.der (Cert signed by an authority) */
  16652. file = XFOPEN(otherCertDerFile, "rb");
  16653. if (!file) {
  16654. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16655. return WC_TEST_RET_ENC_ERRNO;
  16656. }
  16657. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16658. XFCLOSE(file);
  16659. if (bytes == 0)
  16660. return WC_TEST_RET_ENC_ERRNO;
  16661. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16662. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16663. if (ret != 0)
  16664. return WC_TEST_RET_ENC_EC(ret);
  16665. /* check the SKID from a RSA certificate */
  16666. if ((sizeof(skid_rsa) - 1 != cert.extSubjKeyIdSz) ||
  16667. (XMEMCMP(skid_rsa, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16668. return WC_TEST_RET_ENC_NC;
  16669. /* check the AKID from an RSA certificate */
  16670. if ((sizeof(akid_rsa) - 1 != cert.extAuthKeyIdSz) ||
  16671. (XMEMCMP(akid_rsa, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16672. return WC_TEST_RET_ENC_NC;
  16673. /* check the Key Usage from an RSA certificate */
  16674. if (!cert.extKeyUsageSet)
  16675. return WC_TEST_RET_ENC_NC;
  16676. if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE))
  16677. return WC_TEST_RET_ENC_NC;
  16678. /* check the CA Basic Constraints from an RSA certificate */
  16679. if (cert.isCA)
  16680. return WC_TEST_RET_ENC_NC;
  16681. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16682. /* check the Certificate Policies Id */
  16683. if (cert.extCertPoliciesNb != 1)
  16684. return WC_TEST_RET_ENC_NC;
  16685. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16686. return WC_TEST_RET_ENC_NC;
  16687. #endif
  16688. FreeDecodedCert(&cert);
  16689. #ifdef HAVE_ECC
  16690. /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */
  16691. file = XFOPEN(certEccDerFile, "rb");
  16692. if (!file) {
  16693. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16694. return WC_TEST_RET_ENC_ERRNO;
  16695. }
  16696. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16697. XFCLOSE(file);
  16698. if (bytes == 0)
  16699. return WC_TEST_RET_ENC_ERRNO;
  16700. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16701. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16702. if (ret != 0)
  16703. return WC_TEST_RET_ENC_EC(ret);
  16704. /* check the SKID from a ECC certificate - generated dynamically */
  16705. /* check the AKID from an ECC certificate */
  16706. if ((sizeof(akid_ecc) - 1 != cert.extAuthKeyIdSz) ||
  16707. (XMEMCMP(akid_ecc, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16708. return WC_TEST_RET_ENC_NC;
  16709. /* check the Key Usage from an ECC certificate */
  16710. if (!cert.extKeyUsageSet)
  16711. return WC_TEST_RET_ENC_NC;
  16712. if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT))
  16713. return WC_TEST_RET_ENC_NC;
  16714. /* check the CA Basic Constraints from an ECC certificate */
  16715. if (cert.isCA)
  16716. return WC_TEST_RET_ENC_NC;
  16717. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16718. /* check the Certificate Policies Id */
  16719. if (cert.extCertPoliciesNb != 2)
  16720. return WC_TEST_RET_ENC_NC;
  16721. if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32))
  16722. return WC_TEST_RET_ENC_NC;
  16723. if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22))
  16724. return WC_TEST_RET_ENC_NC;
  16725. #endif
  16726. FreeDecodedCert(&cert);
  16727. #endif /* HAVE_ECC */
  16728. /* load cert.der (self signed certificate) */
  16729. file = XFOPEN(certDerFile, "rb");
  16730. if (!file) {
  16731. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16732. return WC_TEST_RET_ENC_ERRNO;
  16733. }
  16734. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16735. XFCLOSE(file);
  16736. if (bytes == 0)
  16737. return WC_TEST_RET_ENC_ERRNO;
  16738. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16739. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16740. if (ret != 0)
  16741. return WC_TEST_RET_ENC_EC(ret);
  16742. /* check the SKID from a CA certificate */
  16743. if ((sizeof(kid_ca) - 1 != cert.extSubjKeyIdSz) ||
  16744. (XMEMCMP(kid_ca, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16745. return WC_TEST_RET_ENC_NC;
  16746. /* check the AKID from an CA certificate */
  16747. if ((sizeof(kid_ca) - 1 != cert.extAuthKeyIdSz) ||
  16748. (XMEMCMP(kid_ca, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16749. return WC_TEST_RET_ENC_NC;
  16750. /* check the Key Usage from CA certificate */
  16751. if (!cert.extKeyUsageSet)
  16752. return WC_TEST_RET_ENC_NC;
  16753. if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN))
  16754. return WC_TEST_RET_ENC_NC;
  16755. /* check the CA Basic Constraints CA certificate */
  16756. if (!cert.isCA)
  16757. return WC_TEST_RET_ENC_NC;
  16758. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16759. /* check the Certificate Policies Id */
  16760. if (cert.extCertPoliciesNb != 2)
  16761. return WC_TEST_RET_ENC_NC;
  16762. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16763. return WC_TEST_RET_ENC_NC;
  16764. if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25))
  16765. return WC_TEST_RET_ENC_NC;
  16766. #endif
  16767. FreeDecodedCert(&cert);
  16768. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16769. return 0;
  16770. }
  16771. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_TEST_CERT &&
  16772. !NO_FILESYSTEM && !NO_RSA && WOLFSSL_CERT_GEN */
  16773. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  16774. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  16775. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void)
  16776. {
  16777. wc_test_ret_t ret = 0;
  16778. Cert cert;
  16779. FILE* file;
  16780. byte* der;
  16781. word32 derSz;
  16782. WOLFSSL_ENTER("decodedCertCache_test");
  16783. derSz = FOURK_BUF;
  16784. der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16785. if (der == NULL)
  16786. ret = WC_TEST_RET_ENC_NC;
  16787. if (ret == 0) {
  16788. /* load cert.der */
  16789. file = XFOPEN(certDerFile, "rb");
  16790. if (file != NULL) {
  16791. derSz = (word32)XFREAD(der, 1, FOURK_BUF, file);
  16792. XFCLOSE(file);
  16793. if (derSz == 0)
  16794. ret = WC_TEST_RET_ENC_ERRNO;
  16795. }
  16796. else
  16797. ret = WC_TEST_RET_ENC_ERRNO;
  16798. }
  16799. if (ret == 0) {
  16800. ret = wc_InitCert_ex(&cert, HEAP_HINT, devId);
  16801. if (ret != 0)
  16802. ret = WC_TEST_RET_ENC_EC(ret);
  16803. }
  16804. if (ret == 0) {
  16805. ret = wc_SetSubjectBuffer(&cert, der, derSz);
  16806. if (ret != 0)
  16807. ret = WC_TEST_RET_ENC_EC(ret);
  16808. }
  16809. if (ret == 0) {
  16810. ret = wc_SetSubjectBuffer(NULL, der, derSz);
  16811. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16812. ret = 0;
  16813. else
  16814. ret = WC_TEST_RET_ENC_EC(ret);
  16815. }
  16816. if (ret == 0) {
  16817. ret = wc_SetSubjectRaw(&cert, der, derSz);
  16818. if (ret != 0)
  16819. ret = WC_TEST_RET_ENC_EC(ret);
  16820. }
  16821. if (ret == 0) {
  16822. ret = wc_SetSubjectRaw(NULL, der, derSz);
  16823. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16824. ret = 0;
  16825. else
  16826. ret = WC_TEST_RET_ENC_EC(ret);
  16827. }
  16828. if (ret == 0) {
  16829. ret = wc_SetIssuerBuffer(&cert, der, derSz);
  16830. if (ret != 0)
  16831. ret = WC_TEST_RET_ENC_EC(ret);
  16832. }
  16833. if (ret == 0) {
  16834. ret = wc_SetIssuerBuffer(NULL, der, derSz);
  16835. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16836. ret = 0;
  16837. else
  16838. ret = WC_TEST_RET_ENC_EC(ret);
  16839. }
  16840. if (ret == 0) {
  16841. ret = wc_SetIssuerRaw(&cert, der, derSz);
  16842. if (ret != 0)
  16843. ret = WC_TEST_RET_ENC_EC(ret);
  16844. }
  16845. if (ret == 0) {
  16846. ret = wc_SetIssuerRaw(NULL, der, derSz);
  16847. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16848. ret = 0;
  16849. else
  16850. ret = WC_TEST_RET_ENC_EC(ret);
  16851. }
  16852. #ifdef WOLFSSL_ALT_NAMES
  16853. if (ret == 0) {
  16854. ret = wc_SetAltNamesBuffer(&cert, der, derSz);
  16855. if (ret != 0)
  16856. ret = WC_TEST_RET_ENC_EC(ret);
  16857. }
  16858. if (ret == 0) {
  16859. ret = wc_SetAltNamesBuffer(NULL, der, derSz);
  16860. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16861. ret = 0;
  16862. else
  16863. ret = WC_TEST_RET_ENC_EC(ret);
  16864. }
  16865. if (ret == 0) {
  16866. ret = wc_SetDatesBuffer(&cert, der, derSz);
  16867. if (ret != 0)
  16868. ret = WC_TEST_RET_ENC_EC(ret);
  16869. }
  16870. if (ret == 0) {
  16871. ret = wc_SetDatesBuffer(NULL, der, derSz);
  16872. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16873. ret = 0;
  16874. else
  16875. ret = WC_TEST_RET_ENC_EC(ret);
  16876. }
  16877. #endif
  16878. if (ret == 0) {
  16879. ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz);
  16880. if (ret != 0)
  16881. ret = WC_TEST_RET_ENC_EC(ret);
  16882. }
  16883. if (ret == 0) {
  16884. ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz);
  16885. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16886. ret = 0;
  16887. else
  16888. ret = WC_TEST_RET_ENC_NC;
  16889. }
  16890. wc_SetCert_Free(&cert);
  16891. if (ret == 0) {
  16892. if(cert.decodedCert != NULL)
  16893. ret = WC_TEST_RET_ENC_NC;
  16894. }
  16895. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16896. return ret;
  16897. }
  16898. #endif /* defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) &&
  16899. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) */
  16900. #define RSA_TEST_BYTES 512 /* up to 4096-bit key */
  16901. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  16902. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16903. static wc_test_ret_t rsa_flatten_test(RsaKey* key)
  16904. {
  16905. wc_test_ret_t ret;
  16906. byte e[RSA_TEST_BYTES];
  16907. byte n[RSA_TEST_BYTES];
  16908. word32 eSz = sizeof(e);
  16909. word32 nSz = sizeof(n);
  16910. /* Parameter Validation testing. */
  16911. ret = wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz);
  16912. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16913. return WC_TEST_RET_ENC_EC(ret);
  16914. ret = wc_RsaFlattenPublicKey(key, NULL, &eSz, n, &nSz);
  16915. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16916. return WC_TEST_RET_ENC_EC(ret);
  16917. ret = wc_RsaFlattenPublicKey(key, e, NULL, n, &nSz);
  16918. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16919. return WC_TEST_RET_ENC_EC(ret);
  16920. ret = wc_RsaFlattenPublicKey(key, e, &eSz, NULL, &nSz);
  16921. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16922. return WC_TEST_RET_ENC_EC(ret);
  16923. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, NULL);
  16924. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16925. return WC_TEST_RET_ENC_EC(ret);
  16926. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16927. if (ret != 0)
  16928. return WC_TEST_RET_ENC_EC(ret);
  16929. eSz = 0;
  16930. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16931. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16932. return WC_TEST_RET_ENC_EC(ret);
  16933. eSz = sizeof(e);
  16934. nSz = 0;
  16935. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16936. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16937. return WC_TEST_RET_ENC_EC(ret);
  16938. return 0;
  16939. }
  16940. #endif /* NO_ASN */
  16941. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  16942. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16943. static wc_test_ret_t rsa_export_key_test(RsaKey* key)
  16944. {
  16945. wc_test_ret_t ret;
  16946. byte e[3];
  16947. word32 eSz = sizeof(e);
  16948. byte n[RSA_TEST_BYTES];
  16949. word32 nSz = sizeof(n);
  16950. byte d[RSA_TEST_BYTES];
  16951. word32 dSz = sizeof(d);
  16952. byte p[RSA_TEST_BYTES/2];
  16953. word32 pSz = sizeof(p);
  16954. byte q[RSA_TEST_BYTES/2];
  16955. word32 qSz = sizeof(q);
  16956. word32 zero = 0;
  16957. ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16958. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16959. return WC_TEST_RET_ENC_EC(ret);
  16960. ret = wc_RsaExportKey(key, NULL, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16961. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16962. return WC_TEST_RET_ENC_EC(ret);
  16963. ret = wc_RsaExportKey(key, e, NULL, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16964. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16965. return WC_TEST_RET_ENC_EC(ret);
  16966. ret = wc_RsaExportKey(key, e, &eSz, NULL, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16967. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16968. return WC_TEST_RET_ENC_EC(ret);
  16969. ret = wc_RsaExportKey(key, e, &eSz, n, NULL, d, &dSz, p, &pSz, q, &qSz);
  16970. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16971. return WC_TEST_RET_ENC_EC(ret);
  16972. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, NULL, &dSz, p, &pSz, q, &qSz);
  16973. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16974. return WC_TEST_RET_ENC_EC(ret);
  16975. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, NULL, p, &pSz, q, &qSz);
  16976. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16977. return WC_TEST_RET_ENC_EC(ret);
  16978. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, NULL, &pSz, q, &qSz);
  16979. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16980. return WC_TEST_RET_ENC_EC(ret);
  16981. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, NULL, q, &qSz);
  16982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16983. return WC_TEST_RET_ENC_EC(ret);
  16984. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, NULL, &qSz);
  16985. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16986. return WC_TEST_RET_ENC_EC(ret);
  16987. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, NULL);
  16988. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16989. return WC_TEST_RET_ENC_EC(ret);
  16990. ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16991. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16992. return WC_TEST_RET_ENC_EC(ret);
  16993. ret = wc_RsaExportKey(key, e, &eSz, n, &zero, d, &dSz, p, &pSz, q, &qSz);
  16994. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16995. return WC_TEST_RET_ENC_EC(ret);
  16996. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  16997. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz);
  16998. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16999. return WC_TEST_RET_ENC_EC(ret);
  17000. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, q, &qSz);
  17001. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17002. return WC_TEST_RET_ENC_EC(ret);
  17003. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &zero);
  17004. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17005. return WC_TEST_RET_ENC_EC(ret);
  17006. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  17007. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  17008. if (ret != 0)
  17009. return WC_TEST_RET_ENC_EC(ret);
  17010. return 0;
  17011. }
  17012. #endif /* !HAVE_FIPS && !NO_ASN && !WOLFSSL_RSA_VERIFY_ONLY */
  17013. #ifndef NO_SIG_WRAPPER
  17014. static wc_test_ret_t rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
  17015. {
  17016. wc_test_ret_t ret;
  17017. word32 sigSz;
  17018. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  17019. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  17020. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17021. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17022. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17023. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17024. };
  17025. WOLFSSL_SMALL_STACK_STATIC const byte hashEnc[] = {
  17026. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  17027. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  17028. 0x00, 0x04, 0x20,
  17029. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17030. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17031. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17032. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17033. };
  17034. word32 inLen = (word32)XSTRLEN((char*)in);
  17035. byte out[RSA_TEST_BYTES];
  17036. /* Parameter Validation testing. */
  17037. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen);
  17038. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17039. return WC_TEST_RET_ENC_EC(ret);
  17040. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0);
  17041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17042. return WC_TEST_RET_ENC_EC(ret);
  17043. sigSz = (word32)modLen;
  17044. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17045. inLen, out, &sigSz, key, keyLen, rng);
  17046. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17047. return WC_TEST_RET_ENC_EC(ret);
  17048. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17049. 0, out, &sigSz, key, keyLen, rng);
  17050. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17051. return WC_TEST_RET_ENC_EC(ret);
  17052. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17053. inLen, NULL, &sigSz, key, keyLen, rng);
  17054. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17055. return WC_TEST_RET_ENC_EC(ret);
  17056. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17057. inLen, out, NULL, key, keyLen, rng);
  17058. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17059. return WC_TEST_RET_ENC_EC(ret);
  17060. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17061. inLen, out, &sigSz, NULL, keyLen, rng);
  17062. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17063. return WC_TEST_RET_ENC_EC(ret);
  17064. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17065. inLen, out, &sigSz, key, 0, rng);
  17066. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17067. return WC_TEST_RET_ENC_EC(ret);
  17068. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17069. inLen, out, &sigSz, key, keyLen, NULL);
  17070. #if defined(WOLFSSL_AFALG_XILINX_RSA) || defined(WOLFSSL_XILINX_CRYPT)
  17071. /* blinding / rng handled with hardware acceleration */
  17072. if (ret != 0)
  17073. #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
  17074. /* async may not require RNG */
  17075. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17076. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID))
  17077. #else
  17078. if (ret != 0 && ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17079. #endif
  17080. #elif defined(HAVE_FIPS) || !defined(WC_RSA_BLINDING)
  17081. /* FIPS140 implementation does not do blinding */
  17082. if (ret != 0)
  17083. #elif defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
  17084. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17085. #elif defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050)
  17086. /* RNG is handled by hardware */
  17087. if (ret != 0)
  17088. #else
  17089. if (ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17090. #endif
  17091. return WC_TEST_RET_ENC_EC(ret);
  17092. sigSz = 0;
  17093. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17094. inLen, out, &sigSz, key, keyLen, rng);
  17095. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17096. return WC_TEST_RET_ENC_EC(ret);
  17097. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17098. inLen, out, (word32)modLen, key, keyLen);
  17099. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17100. return WC_TEST_RET_ENC_EC(ret);
  17101. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17102. 0, out, (word32)modLen, key, keyLen);
  17103. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17104. return WC_TEST_RET_ENC_EC(ret);
  17105. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17106. inLen, NULL, (word32)modLen, key, keyLen);
  17107. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17108. return WC_TEST_RET_ENC_EC(ret);
  17109. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17110. inLen, out, 0, key, keyLen);
  17111. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17112. return WC_TEST_RET_ENC_EC(ret);
  17113. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17114. inLen, out, (word32)modLen, NULL, keyLen);
  17115. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17116. return WC_TEST_RET_ENC_EC(ret);
  17117. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17118. inLen, out, (word32)modLen, key, 0);
  17119. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17120. return WC_TEST_RET_ENC_EC(ret);
  17121. #ifndef HAVE_ECC
  17122. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen);
  17123. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17124. return WC_TEST_RET_ENC_EC(ret);
  17125. #endif
  17126. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17127. return 0;
  17128. #endif
  17129. /* Use APIs. */
  17130. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen);
  17131. if (ret != modLen)
  17132. return WC_TEST_RET_ENC_EC(ret);
  17133. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen);
  17134. if (ret != modLen)
  17135. return WC_TEST_RET_ENC_EC(ret);
  17136. sigSz = (word32)ret;
  17137. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  17138. XMEMSET(out, 0, sizeof(out));
  17139. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17140. inLen, out, &sigSz, key, keyLen, rng);
  17141. if (ret != 0)
  17142. return WC_TEST_RET_ENC_EC(ret);
  17143. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17144. inLen, out, (word32)modLen, key, keyLen);
  17145. if (ret != 0)
  17146. return WC_TEST_RET_ENC_EC(ret);
  17147. sigSz = (word32)sizeof(out);
  17148. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17149. in, inLen, out, &sigSz, key, keyLen, rng);
  17150. if (ret != 0)
  17151. return WC_TEST_RET_ENC_EC(ret);
  17152. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17153. in, inLen, out, (word32)modLen, key, keyLen);
  17154. if (ret != 0)
  17155. return WC_TEST_RET_ENC_EC(ret);
  17156. /* Wrong signature type. */
  17157. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17158. inLen, out, (word32)modLen, key, keyLen);
  17159. if (ret == 0)
  17160. return WC_TEST_RET_ENC_EC(ret);
  17161. /* check hash functions */
  17162. sigSz = (word32)sizeof(out);
  17163. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17164. hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng);
  17165. if (ret != 0)
  17166. return WC_TEST_RET_ENC_EC(ret);
  17167. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17168. hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen);
  17169. if (ret != 0)
  17170. return WC_TEST_RET_ENC_EC(ret);
  17171. sigSz = (word32)sizeof(out);
  17172. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17173. hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng);
  17174. if (ret != 0)
  17175. return WC_TEST_RET_ENC_EC(ret);
  17176. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17177. hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen);
  17178. if (ret != 0)
  17179. return WC_TEST_RET_ENC_EC(ret);
  17180. #else
  17181. (void)hash;
  17182. (void)hashEnc;
  17183. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  17184. return 0;
  17185. }
  17186. #endif /* !NO_SIG_WRAPPER */
  17187. #ifdef WC_RSA_NONBLOCK
  17188. static wc_test_ret_t rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out,
  17189. word32 outSz, byte* plain, word32 plainSz, WC_RNG* rng)
  17190. {
  17191. wc_test_ret_t ret = 0;
  17192. int count;
  17193. int signSz = 0;
  17194. RsaNb nb;
  17195. byte* inlinePlain = NULL;
  17196. /* Enable non-blocking RSA mode - provide context */
  17197. ret = wc_RsaSetNonBlock(key, &nb);
  17198. if (ret != 0)
  17199. return ret;
  17200. #ifdef WC_RSA_NONBLOCK_TIME
  17201. /* Enable time based RSA blocking. 8 microseconds max (3.1GHz) */
  17202. ret = wc_RsaSetNonBlockTime(key, 8, 3100);
  17203. if (ret != 0)
  17204. return ret;
  17205. #endif
  17206. count = 0;
  17207. do {
  17208. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, rng);
  17209. count++; /* track number of would blocks */
  17210. if (ret == FP_WOULDBLOCK) {
  17211. /* do "other" work here */
  17212. }
  17213. } while (ret == FP_WOULDBLOCK);
  17214. if (ret < 0) {
  17215. return ret;
  17216. }
  17217. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17218. printf("RSA non-block sign: %d times\n", count);
  17219. #endif
  17220. signSz = ret;
  17221. /* Test non-blocking verify */
  17222. XMEMSET(plain, 0, plainSz);
  17223. count = 0;
  17224. do {
  17225. ret = wc_RsaSSL_Verify(out, (word32)signSz, plain, plainSz, key);
  17226. count++; /* track number of would blocks */
  17227. if (ret == FP_WOULDBLOCK) {
  17228. /* do "other" work here */
  17229. }
  17230. } while (ret == FP_WOULDBLOCK);
  17231. if (ret < 0) {
  17232. return ret;
  17233. }
  17234. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17235. printf("RSA non-block verify: %d times\n", count);
  17236. #endif
  17237. if (signSz == ret && XMEMCMP(plain, in, (size_t)ret)) {
  17238. return SIG_VERIFY_E;
  17239. }
  17240. /* Test inline non-blocking verify */
  17241. count = 0;
  17242. do {
  17243. ret = wc_RsaSSL_VerifyInline(out, (word32)signSz, &inlinePlain, key);
  17244. count++; /* track number of would blocks */
  17245. if (ret == FP_WOULDBLOCK) {
  17246. /* do "other" work here */
  17247. }
  17248. } while (ret == FP_WOULDBLOCK);
  17249. if (ret < 0) {
  17250. return ret;
  17251. }
  17252. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17253. printf("RSA non-block inline verify: %d times\n", count);
  17254. #endif
  17255. if (signSz == ret && XMEMCMP(inlinePlain, in, (size_t)ret)) {
  17256. return SIG_VERIFY_E;
  17257. }
  17258. /* Disabling non-block RSA mode */
  17259. ret = wc_RsaSetNonBlock(key, NULL);
  17260. (void)count;
  17261. return 0;
  17262. }
  17263. #endif
  17264. #if !defined(NO_ASN)
  17265. static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
  17266. {
  17267. wc_test_ret_t ret;
  17268. word32 inSz;
  17269. word32 inOutIdx;
  17270. WOLFSSL_SMALL_STACK_STATIC const byte n[2] = { 0x00, 0x23 };
  17271. WOLFSSL_SMALL_STACK_STATIC const byte e[2] = { 0x00, 0x03 };
  17272. WOLFSSL_SMALL_STACK_STATIC const byte good[] = { 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1,
  17273. 0x03 };
  17274. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgId[] = {
  17275. 0x30, 0x18, 0x30, 0x16,
  17276. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17277. 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17278. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgIdNull[] = {
  17279. 0x30, 0x1a, 0x30, 0x18,
  17280. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17281. 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17282. 0x02, 0x1, 0x03 };
  17283. WOLFSSL_SMALL_STACK_STATIC const byte badAlgIdNull[] = {
  17284. 0x30, 0x1b, 0x30, 0x19,
  17285. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17286. 0x05, 0x01, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17287. 0x02, 0x1, 0x03 };
  17288. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitString[] = {
  17289. 0x30, 0x18, 0x30, 0x16,
  17290. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17291. 0x04, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17292. WOLFSSL_SMALL_STACK_STATIC const byte badBitStringLen[] = {
  17293. 0x30, 0x18, 0x30, 0x16,
  17294. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17295. 0x03, 0x0a, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17296. WOLFSSL_SMALL_STACK_STATIC const byte badNoSeq[] = {
  17297. 0x30, 0x16, 0x30, 0x14,
  17298. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17299. 0x07, 0x00, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17300. WOLFSSL_SMALL_STACK_STATIC const byte badNoObj[] = {
  17301. 0x30, 0x0f, 0x30, 0x0d, 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06,
  17302. 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17303. WOLFSSL_SMALL_STACK_STATIC const byte badIntN[] = {
  17304. 0x30, 0x06, 0x02, 0x05, 0x23, 0x02, 0x1, 0x03 };
  17305. WOLFSSL_SMALL_STACK_STATIC const byte badNotIntE[] = {
  17306. 0x30, 0x06, 0x02, 0x01, 0x23, 0x04, 0x1, 0x03 };
  17307. WOLFSSL_SMALL_STACK_STATIC const byte badLength[] = {
  17308. 0x30, 0x04, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17309. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrNoZero[] = {
  17310. 0x30, 0x17, 0x30, 0x15,
  17311. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17312. 0x03, 0x08, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17313. ret = wc_InitRsaKey(keyPub, NULL);
  17314. if (ret != 0)
  17315. return WC_TEST_RET_ENC_EC(ret);
  17316. /* Parameter Validation testing. */
  17317. ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, sizeof(e), keyPub);
  17318. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17319. ret = WC_TEST_RET_ENC_EC(ret);
  17320. goto done;
  17321. }
  17322. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), NULL, sizeof(e), keyPub);
  17323. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17324. ret = WC_TEST_RET_ENC_EC(ret);
  17325. goto done;
  17326. }
  17327. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), NULL);
  17328. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17329. ret = WC_TEST_RET_ENC_EC(ret);
  17330. goto done;
  17331. }
  17332. ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
  17333. #if defined(USE_INTEGER_HEAP_MATH)
  17334. if (ret != 0)
  17335. #else
  17336. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17337. #endif
  17338. {
  17339. ret = WC_TEST_RET_ENC_EC(ret);
  17340. goto done;
  17341. }
  17342. wc_FreeRsaKey(keyPub);
  17343. ret = wc_InitRsaKey(keyPub, NULL);
  17344. if (ret != 0)
  17345. return WC_TEST_RET_ENC_EC(ret);
  17346. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
  17347. #if defined(USE_INTEGER_HEAP_MATH)
  17348. if (ret != 0)
  17349. #else
  17350. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17351. #endif
  17352. {
  17353. ret = WC_TEST_RET_ENC_EC(ret);
  17354. goto done;
  17355. }
  17356. wc_FreeRsaKey(keyPub);
  17357. ret = wc_InitRsaKey(keyPub, NULL);
  17358. if (ret != 0)
  17359. return WC_TEST_RET_ENC_EC(ret);
  17360. /* Use API. */
  17361. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub);
  17362. if (ret != 0) {
  17363. ret = WC_TEST_RET_ENC_EC(ret);
  17364. goto done;
  17365. }
  17366. wc_FreeRsaKey(keyPub);
  17367. ret = wc_InitRsaKey(keyPub, NULL);
  17368. if (ret != 0)
  17369. return WC_TEST_RET_ENC_EC(ret);
  17370. /* Parameter Validation testing. */
  17371. inSz = sizeof(good);
  17372. ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, keyPub, inSz);
  17373. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17374. ret = WC_TEST_RET_ENC_EC(ret);
  17375. goto done;
  17376. }
  17377. ret = wc_RsaPublicKeyDecode(good, NULL, keyPub, inSz);
  17378. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17379. ret = WC_TEST_RET_ENC_EC(ret);
  17380. goto done;
  17381. }
  17382. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  17383. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17384. ret = WC_TEST_RET_ENC_EC(ret);
  17385. goto done;
  17386. }
  17387. /* Use good data and offset to bad data. */
  17388. inOutIdx = 2;
  17389. inSz = sizeof(good) - inOutIdx;
  17390. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17391. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17392. ret = WC_TEST_RET_ENC_EC(ret);
  17393. goto done;
  17394. }
  17395. inOutIdx = 2;
  17396. inSz = sizeof(goodAlgId) - inOutIdx;
  17397. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17398. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17399. ret = WC_TEST_RET_ENC_EC(ret);
  17400. goto done;
  17401. }
  17402. inOutIdx = 2;
  17403. inSz = sizeof(goodAlgId);
  17404. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17405. #ifndef WOLFSSL_NO_DECODE_EXTRA
  17406. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17407. #else
  17408. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E))
  17409. #endif
  17410. {
  17411. ret = WC_TEST_RET_ENC_EC(ret);
  17412. goto done;
  17413. }
  17414. /* Try different bad data. */
  17415. inSz = sizeof(badAlgIdNull);
  17416. inOutIdx = 0;
  17417. ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz);
  17418. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E)) {
  17419. ret = WC_TEST_RET_ENC_EC(ret);
  17420. goto done;
  17421. }
  17422. inSz = sizeof(badNotBitString);
  17423. inOutIdx = 0;
  17424. ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz);
  17425. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E)) {
  17426. ret = WC_TEST_RET_ENC_EC(ret);
  17427. goto done;
  17428. }
  17429. inSz = sizeof(badBitStringLen);
  17430. inOutIdx = 0;
  17431. ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz);
  17432. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17433. ret = WC_TEST_RET_ENC_EC(ret);
  17434. goto done;
  17435. }
  17436. inSz = sizeof(badNoSeq);
  17437. inOutIdx = 0;
  17438. ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz);
  17439. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17440. ret = WC_TEST_RET_ENC_EC(ret);
  17441. goto done;
  17442. }
  17443. inSz = sizeof(badNoObj);
  17444. inOutIdx = 0;
  17445. ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz);
  17446. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E) &&
  17447. ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E))
  17448. {
  17449. ret = WC_TEST_RET_ENC_EC(ret);
  17450. goto done;
  17451. }
  17452. inSz = sizeof(badIntN);
  17453. inOutIdx = 0;
  17454. ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz);
  17455. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17456. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17457. {
  17458. ret = WC_TEST_RET_ENC_EC(ret);
  17459. goto done;
  17460. }
  17461. inSz = sizeof(badNotIntE);
  17462. inOutIdx = 0;
  17463. ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz);
  17464. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17465. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17466. {
  17467. ret = WC_TEST_RET_ENC_EC(ret);
  17468. goto done;
  17469. }
  17470. /* TODO: Shouldn't pass as the sequence length is too small. */
  17471. inSz = sizeof(badLength);
  17472. inOutIdx = 0;
  17473. ret = wc_RsaPublicKeyDecode(badLength, &inOutIdx, keyPub, inSz);
  17474. #ifndef WOLFSSL_ASN_TEMPLATE
  17475. if (ret != 0)
  17476. #else
  17477. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17478. #endif
  17479. {
  17480. ret = WC_TEST_RET_ENC_EC(ret);
  17481. goto done;
  17482. }
  17483. /* TODO: Shouldn't ignore object id's data. */
  17484. wc_FreeRsaKey(keyPub);
  17485. ret = wc_InitRsaKey(keyPub, NULL);
  17486. if (ret != 0)
  17487. return WC_TEST_RET_ENC_EC(ret);
  17488. inSz = sizeof(badBitStrNoZero);
  17489. inOutIdx = 0;
  17490. ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz);
  17491. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  17492. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17493. {
  17494. ret = WC_TEST_RET_ENC_EC(ret);
  17495. goto done;
  17496. }
  17497. wc_FreeRsaKey(keyPub);
  17498. ret = wc_InitRsaKey(keyPub, NULL);
  17499. if (ret != 0)
  17500. return WC_TEST_RET_ENC_EC(ret);
  17501. /* Valid data cases. */
  17502. inSz = sizeof(good);
  17503. inOutIdx = 0;
  17504. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17505. if (ret != 0) {
  17506. ret = WC_TEST_RET_ENC_EC(ret);
  17507. goto done;
  17508. }
  17509. if (inOutIdx != inSz) {
  17510. ret = WC_TEST_RET_ENC_NC;
  17511. goto done;
  17512. }
  17513. wc_FreeRsaKey(keyPub);
  17514. ret = wc_InitRsaKey(keyPub, NULL);
  17515. if (ret != 0)
  17516. return WC_TEST_RET_ENC_EC(ret);
  17517. inSz = sizeof(goodAlgId);
  17518. inOutIdx = 0;
  17519. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17520. if (ret != 0) {
  17521. ret = WC_TEST_RET_ENC_EC(ret);
  17522. goto done;
  17523. }
  17524. if (inOutIdx != inSz) {
  17525. ret = WC_TEST_RET_ENC_NC;
  17526. goto done;
  17527. }
  17528. wc_FreeRsaKey(keyPub);
  17529. ret = wc_InitRsaKey(keyPub, NULL);
  17530. if (ret != 0)
  17531. return WC_TEST_RET_ENC_EC(ret);
  17532. inSz = sizeof(goodAlgIdNull);
  17533. inOutIdx = 0;
  17534. ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz);
  17535. if (ret != 0) {
  17536. ret = WC_TEST_RET_ENC_EC(ret);
  17537. goto done;
  17538. }
  17539. if (inOutIdx != inSz) {
  17540. ret = WC_TEST_RET_ENC_NC;
  17541. goto done;
  17542. }
  17543. done:
  17544. wc_FreeRsaKey(keyPub);
  17545. return ret;
  17546. }
  17547. #endif
  17548. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  17549. /* Need to create known good signatures to test with this. */
  17550. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  17551. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17552. static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key)
  17553. {
  17554. byte digest[WC_MAX_DIGEST_SIZE];
  17555. wc_test_ret_t ret = 0;
  17556. const char inStr[] = TEST_STRING;
  17557. word32 inLen = (word32)TEST_STRING_SZ;
  17558. word32 outSz;
  17559. word32 plainSz;
  17560. word32 digestSz;
  17561. int i, j;
  17562. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17563. int k, l;
  17564. #endif
  17565. #ifndef WOLFSSL_SE050
  17566. int len;
  17567. #endif
  17568. byte* plain;
  17569. int mgf[] = {
  17570. #ifndef NO_SHA
  17571. WC_MGF1SHA1,
  17572. #endif
  17573. #ifdef WOLFSSL_SHA224
  17574. WC_MGF1SHA224,
  17575. #endif
  17576. WC_MGF1SHA256,
  17577. #ifdef WOLFSSL_SHA384
  17578. WC_MGF1SHA384,
  17579. #endif
  17580. #ifdef WOLFSSL_SHA512
  17581. WC_MGF1SHA512
  17582. #endif
  17583. };
  17584. enum wc_HashType hash[] = {
  17585. #ifndef NO_SHA
  17586. WC_HASH_TYPE_SHA,
  17587. #endif
  17588. #ifdef WOLFSSL_SHA224
  17589. WC_HASH_TYPE_SHA224,
  17590. #endif
  17591. WC_HASH_TYPE_SHA256,
  17592. #ifdef WOLFSSL_SHA384
  17593. WC_HASH_TYPE_SHA384,
  17594. #endif
  17595. #ifdef WOLFSSL_SHA512
  17596. WC_HASH_TYPE_SHA512,
  17597. #endif
  17598. };
  17599. WC_DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17600. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17601. WC_DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17602. WC_ALLOC_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17603. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17604. WC_ALLOC_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17605. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17606. if (in == NULL || out == NULL || sig == NULL)
  17607. ERROR_OUT(MEMORY_E, exit_rsa_pss);
  17608. #endif
  17609. XMEMCPY(in, inStr, inLen);
  17610. /* Test all combinations of hash and MGF. */
  17611. for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) {
  17612. /* Calculate hash of message. */
  17613. ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest));
  17614. if (ret != 0)
  17615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17616. digestSz = (word32)wc_HashGetDigestSize(hash[j]);
  17617. #ifdef WOLFSSL_SE050
  17618. /* SE050 only supports MGF matched to same hash type */
  17619. i = j;
  17620. #else
  17621. for (i = 0; i < (int)(sizeof(mgf)/sizeof(*mgf)); i++) {
  17622. #endif
  17623. outSz = RSA_TEST_BYTES;
  17624. do {
  17625. #if defined(WOLFSSL_ASYNC_CRYPT)
  17626. ret = wc_AsyncWait(ret, &key->asyncDev,
  17627. WC_ASYNC_FLAG_CALL_AGAIN);
  17628. #endif
  17629. if (ret >= 0) {
  17630. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz,
  17631. hash[j], mgf[i], -1, key, rng);
  17632. }
  17633. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17634. if (ret <= 0)
  17635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17636. outSz = (word32)ret;
  17637. XMEMCPY(sig, out, outSz);
  17638. plain = NULL;
  17639. TEST_SLEEP();
  17640. do {
  17641. #if defined(WOLFSSL_ASYNC_CRYPT)
  17642. ret = wc_AsyncWait(ret, &key->asyncDev,
  17643. WC_ASYNC_FLAG_CALL_AGAIN);
  17644. #endif
  17645. if (ret >= 0) {
  17646. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[j],
  17647. mgf[i], -1, key);
  17648. }
  17649. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17650. if (ret <= 0)
  17651. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17652. plainSz = (word32)ret;
  17653. TEST_SLEEP();
  17654. #if defined(HAVE_SELFTEST) && \
  17655. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17656. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17657. hash[j], -1);
  17658. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17659. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17660. hash[j], -1, 0);
  17661. #else
  17662. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz,
  17663. hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT);
  17664. #endif
  17665. if (ret != 0)
  17666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17667. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17668. for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) {
  17669. for (l = 0; l < (int)(sizeof(hash)/sizeof(*hash)); l++) {
  17670. if (i == k && j == l)
  17671. continue;
  17672. XMEMCPY(sig, out, outSz);
  17673. do {
  17674. #if defined(WOLFSSL_ASYNC_CRYPT)
  17675. ret = wc_AsyncWait(ret, &key->asyncDev,
  17676. WC_ASYNC_FLAG_CALL_AGAIN);
  17677. #endif
  17678. if (ret >= 0) {
  17679. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz,
  17680. (byte**)&plain, hash[l], mgf[k], -1, key);
  17681. }
  17682. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17683. if (ret >= 0)
  17684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17685. }
  17686. }
  17687. #endif
  17688. #ifndef WOLFSSL_SE050
  17689. } /* end mgf for loop */
  17690. #endif
  17691. }
  17692. /* SE050 generates salts internally only of hash length */
  17693. #ifndef WOLFSSL_SE050
  17694. /* Test that a salt length of zero works. */
  17695. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17696. outSz = RSA_TEST_BYTES;
  17697. do {
  17698. #if defined(WOLFSSL_ASYNC_CRYPT)
  17699. ret = wc_AsyncWait(ret, &key->asyncDev,
  17700. WC_ASYNC_FLAG_CALL_AGAIN);
  17701. #endif
  17702. if (ret >= 0) {
  17703. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17704. mgf[0], 0, key, rng);
  17705. }
  17706. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17707. if (ret <= 0)
  17708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17709. outSz = (word32)ret;
  17710. TEST_SLEEP();
  17711. do {
  17712. #if defined(WOLFSSL_ASYNC_CRYPT)
  17713. ret = wc_AsyncWait(ret, &key->asyncDev,
  17714. WC_ASYNC_FLAG_CALL_AGAIN);
  17715. #endif
  17716. if (ret >= 0) {
  17717. ret = wc_RsaPSS_Verify_ex(out, outSz, sig, outSz, hash[0], mgf[0],
  17718. 0, key);
  17719. }
  17720. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17721. if (ret <= 0)
  17722. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17723. plainSz = (word32)ret;
  17724. TEST_SLEEP();
  17725. do {
  17726. #if defined(WOLFSSL_ASYNC_CRYPT)
  17727. ret = wc_AsyncWait(ret, &key->asyncDev,
  17728. WC_ASYNC_FLAG_CALL_AGAIN);
  17729. #endif
  17730. if (ret >= 0) {
  17731. #if defined(HAVE_SELFTEST) && \
  17732. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17733. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17734. hash[0], 0);
  17735. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17736. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17737. hash[0], 0, 0);
  17738. #else
  17739. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, sig, plainSz,
  17740. hash[0], 0, 0, HEAP_HINT);
  17741. #endif
  17742. }
  17743. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17744. if (ret != 0)
  17745. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17746. XMEMCPY(sig, out, outSz);
  17747. plain = NULL;
  17748. do {
  17749. #if defined(WOLFSSL_ASYNC_CRYPT)
  17750. ret = wc_AsyncWait(ret, &key->asyncDev,
  17751. WC_ASYNC_FLAG_CALL_AGAIN);
  17752. #endif
  17753. if (ret >= 0) {
  17754. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17755. 0, key);
  17756. }
  17757. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17758. if (ret <= 0)
  17759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17760. plainSz = (word32)ret;
  17761. TEST_SLEEP();
  17762. #if defined(HAVE_SELFTEST) && \
  17763. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17764. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17765. hash[0], 0);
  17766. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17767. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17768. hash[0], 0, 0);
  17769. #else
  17770. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17771. 0, 0, HEAP_HINT);
  17772. #endif
  17773. if (ret != 0)
  17774. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17775. /* Test bad salt lengths in various APIs. */
  17776. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17777. outSz = RSA_TEST_BYTES;
  17778. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17779. len = -2;
  17780. #else
  17781. len = -3;
  17782. #endif
  17783. do {
  17784. #if defined(WOLFSSL_ASYNC_CRYPT)
  17785. ret = wc_AsyncWait(ret, &key->asyncDev,
  17786. WC_ASYNC_FLAG_CALL_AGAIN);
  17787. #endif
  17788. if (ret >= 0) {
  17789. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17790. mgf[0], len, key, rng);
  17791. }
  17792. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17793. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17795. do {
  17796. #if defined(WOLFSSL_ASYNC_CRYPT)
  17797. ret = wc_AsyncWait(ret, &key->asyncDev,
  17798. WC_ASYNC_FLAG_CALL_AGAIN);
  17799. #endif
  17800. if (ret >= 0) {
  17801. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17802. mgf[0], (int)digestSz + 1, key, rng);
  17803. }
  17804. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17805. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17806. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17807. TEST_SLEEP();
  17808. do {
  17809. #if defined(WOLFSSL_ASYNC_CRYPT)
  17810. ret = wc_AsyncWait(ret, &key->asyncDev,
  17811. WC_ASYNC_FLAG_CALL_AGAIN);
  17812. #endif
  17813. if (ret >= 0) {
  17814. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0],
  17815. mgf[0], -2, key);
  17816. }
  17817. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17818. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17819. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17820. TEST_SLEEP();
  17821. do {
  17822. #if defined(WOLFSSL_ASYNC_CRYPT)
  17823. ret = wc_AsyncWait(ret, &key->asyncDev,
  17824. WC_ASYNC_FLAG_CALL_AGAIN);
  17825. #endif
  17826. if (ret >= 0) {
  17827. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17828. (int)digestSz + 1, key);
  17829. }
  17830. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17831. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17833. TEST_SLEEP();
  17834. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17835. len = -2;
  17836. #else
  17837. len = -3;
  17838. #endif
  17839. #if defined(HAVE_SELFTEST) && \
  17840. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17841. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17842. hash[0], len);
  17843. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17844. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17845. hash[0], len, 0);
  17846. #else
  17847. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17848. len, 0, HEAP_HINT);
  17849. #endif
  17850. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17851. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17852. #ifndef WOLFSSL_PSS_LONG_SALT
  17853. len = (int)(digestSz + 1);
  17854. #else
  17855. len = (int)(plainSz - digestSz - 1);
  17856. #endif
  17857. #if defined(HAVE_SELFTEST) && \
  17858. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17859. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17860. hash[0], len);
  17861. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17862. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17863. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17864. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17865. hash[0], len, 0);
  17866. if (ret != WC_NO_ERR_TRACE(BAD_PADDING_E))
  17867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17868. #else
  17869. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17870. len, 0, HEAP_HINT);
  17871. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17872. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17873. #endif
  17874. ret = 0;
  17875. #endif /* WOLFSSL_SE050 */
  17876. exit_rsa_pss:
  17877. WC_FREE_VAR(sig, HEAP_HINT);
  17878. WC_FREE_VAR(in, HEAP_HINT);
  17879. WC_FREE_VAR(out, HEAP_HINT);
  17880. return ret;
  17881. }
  17882. #endif /* !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY */
  17883. #endif
  17884. #ifdef WC_RSA_NO_PADDING
  17885. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
  17886. {
  17887. WC_RNG rng;
  17888. byte* tmp = NULL;
  17889. size_t bytes;
  17890. wc_test_ret_t ret;
  17891. word32 inLen = 0;
  17892. word32 idx = 0;
  17893. word32 outSz = RSA_TEST_BYTES;
  17894. word32 plainSz = RSA_TEST_BYTES;
  17895. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  17896. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  17897. !defined(NO_FILESYSTEM)
  17898. XFILE file;
  17899. #endif
  17900. WC_DECLARE_VAR(key, RsaKey, 1, HEAP_HINT);
  17901. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17902. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17903. WC_ALLOC_VAR(key, RsaKey, 1, HEAP_HINT);
  17904. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17905. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17906. WOLFSSL_ENTER("rsa_no_pad_test");
  17907. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17908. if (key == NULL || out == NULL || plain == NULL)
  17909. ERROR_OUT(MEMORY_E, exit_rsa_nopadding);
  17910. #endif
  17911. /* initialize stack structures */
  17912. XMEMSET(&rng, 0, sizeof(rng));
  17913. XMEMSET(key, 0, sizeof(RsaKey));
  17914. #ifdef USE_CERT_BUFFERS_1024
  17915. bytes = (size_t)sizeof_client_key_der_1024;
  17916. if (bytes < (size_t)sizeof_client_cert_der_1024)
  17917. bytes = (size_t)sizeof_client_cert_der_1024;
  17918. #elif defined(USE_CERT_BUFFERS_2048)
  17919. bytes = (size_t)sizeof_client_key_der_2048;
  17920. if (bytes < (size_t)sizeof_client_cert_der_2048)
  17921. bytes = (size_t)sizeof_client_cert_der_2048;
  17922. #else
  17923. bytes = FOURK_BUF;
  17924. #endif
  17925. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17926. if (tmp == NULL
  17927. #ifdef WOLFSSL_ASYNC_CRYPT
  17928. || out == NULL || plain == NULL
  17929. #endif
  17930. ) {
  17931. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17932. }
  17933. #ifdef USE_CERT_BUFFERS_1024
  17934. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  17935. #elif defined(USE_CERT_BUFFERS_2048)
  17936. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  17937. #elif defined(USE_CERT_BUFFERS_3072)
  17938. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  17939. #elif defined(USE_CERT_BUFFERS_4096)
  17940. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  17941. #elif !defined(NO_FILESYSTEM)
  17942. file = XFOPEN(clientKey, "rb");
  17943. if (!file) {
  17944. err_sys("can't open clientKey, Please run from wolfSSL home dir",
  17945. WC_TEST_RET_ENC_ERRNO);
  17946. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17947. }
  17948. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  17949. XFCLOSE(file);
  17950. if (bytes == 0)
  17951. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17952. #else
  17953. /* No key to use. */
  17954. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17955. #endif /* USE_CERT_BUFFERS */
  17956. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  17957. if (ret != 0) {
  17958. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17959. }
  17960. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  17961. if (ret != 0) {
  17962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17963. }
  17964. /* after loading in key use tmp as the test buffer */
  17965. #ifndef HAVE_FIPS
  17966. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  17967. #else
  17968. ret = wc_InitRng(&rng);
  17969. #endif
  17970. if (ret != 0) {
  17971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17972. }
  17973. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17974. inLen = (word32)wc_RsaEncryptSize(key);
  17975. outSz = inLen;
  17976. plainSz = inLen;
  17977. XMEMSET(tmp, 7, inLen);
  17978. do {
  17979. #if defined(WOLFSSL_ASYNC_CRYPT)
  17980. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17981. #endif
  17982. if (ret >= 0) {
  17983. ret = wc_RsaDirect(tmp, inLen, out, &outSz, key,
  17984. RSA_PRIVATE_ENCRYPT, &rng);
  17985. }
  17986. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17987. if (ret <= 0) {
  17988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17989. }
  17990. /* encrypted result should not be the same as input */
  17991. if (XMEMCMP(out, tmp, inLen) == 0) {
  17992. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17993. }
  17994. TEST_SLEEP();
  17995. /* decrypt with public key and compare result */
  17996. do {
  17997. #if defined(WOLFSSL_ASYNC_CRYPT)
  17998. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17999. #endif
  18000. if (ret >= 0) {
  18001. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key,
  18002. RSA_PUBLIC_DECRYPT, &rng);
  18003. }
  18004. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18005. if (ret <= 0) {
  18006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18007. }
  18008. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18009. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18010. }
  18011. TEST_SLEEP();
  18012. #endif
  18013. #ifdef WC_RSA_BLINDING
  18014. ret = wc_RsaSetRNG(NULL, &rng);
  18015. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18016. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18017. }
  18018. ret = wc_RsaSetRNG(key, &rng);
  18019. if (ret < 0) {
  18020. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18021. }
  18022. #endif
  18023. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18024. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18025. do {
  18026. #if defined(WOLFSSL_ASYNC_CRYPT)
  18027. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18028. #endif
  18029. if (ret >= 0) {
  18030. ret = wc_RsaPublicEncrypt_ex(tmp, inLen, out, outSz, key, &rng,
  18031. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18032. }
  18033. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18034. if (ret < 0) {
  18035. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18036. }
  18037. TEST_SLEEP();
  18038. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18039. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18040. do {
  18041. #if defined(WOLFSSL_ASYNC_CRYPT)
  18042. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18043. #endif
  18044. if (ret >= 0) {
  18045. ret = wc_RsaPrivateDecrypt_ex(out, outSz, plain, plainSz, key,
  18046. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18047. }
  18048. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18049. if (ret < 0) {
  18050. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18051. }
  18052. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18053. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18054. }
  18055. TEST_SLEEP();
  18056. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18057. /* test some bad arguments */
  18058. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1,
  18059. &rng);
  18060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18062. }
  18063. ret = wc_RsaDirect(out, outSz, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT,
  18064. &rng);
  18065. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18067. }
  18068. ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT,
  18069. &rng);
  18070. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || plainSz != inLen) {
  18071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18072. }
  18073. ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key,
  18074. RSA_PUBLIC_DECRYPT, &rng);
  18075. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18076. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18077. }
  18078. /* if making it to this point of code without hitting an ERROR_OUT then
  18079. * all tests have passed */
  18080. ret = 0;
  18081. exit_rsa_nopadding:
  18082. wc_FreeRsaKey(key);
  18083. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18084. WC_FREE_VAR(key, HEAP_HINT);
  18085. WC_FREE_VAR(out, HEAP_HINT);
  18086. WC_FREE_VAR(plain, HEAP_HINT);
  18087. wc_FreeRng(&rng);
  18088. return ret;
  18089. }
  18090. #endif /* WC_RSA_NO_PADDING */
  18091. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  18092. static wc_test_ret_t rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
  18093. {
  18094. byte* tmp = NULL;
  18095. size_t bytes;
  18096. wc_test_ret_t ret;
  18097. word32 inLen = 0;
  18098. #ifndef NO_ASN
  18099. word32 idx = 0;
  18100. #endif
  18101. word32 outSz = RSA_TEST_BYTES;
  18102. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18103. word32 plainSz = RSA_TEST_BYTES;
  18104. #endif
  18105. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_3072) && \
  18106. !defined(USE_CERT_BUFFERS_4096) && !defined(NO_FILESYSTEM)
  18107. XFILE file;
  18108. #endif
  18109. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18110. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18111. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18112. #endif
  18113. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18114. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18115. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18116. #endif
  18117. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18118. if (out == NULL
  18119. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18120. || plain == NULL
  18121. #endif
  18122. ) {
  18123. ERROR_OUT(MEMORY_E, exit_rsa_even_mod);
  18124. }
  18125. #endif
  18126. #if defined(USE_CERT_BUFFERS_2048)
  18127. bytes = (size_t)sizeof_client_key_der_2048;
  18128. if (bytes < (size_t)sizeof_client_cert_der_2048)
  18129. bytes = (size_t)sizeof_client_cert_der_2048;
  18130. #else
  18131. bytes = FOURK_BUF;
  18132. #endif
  18133. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18134. if (tmp == NULL
  18135. #ifdef WOLFSSL_ASYNC_CRYPT
  18136. || out == NULL || plain == NULL
  18137. #endif
  18138. ) {
  18139. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18140. }
  18141. #if defined(USE_CERT_BUFFERS_2048)
  18142. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  18143. #elif defined(USE_CERT_BUFFERS_3072)
  18144. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  18145. #elif defined(USE_CERT_BUFFERS_4096)
  18146. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  18147. #elif !defined(NO_FILESYSTEM)
  18148. file = XFOPEN(clientKey, "rb");
  18149. if (!file) {
  18150. err_sys("can't open ./certs/client-key.der, "
  18151. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  18152. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18153. }
  18154. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  18155. XFCLOSE(file);
  18156. if (bytes == 0)
  18157. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18158. #else
  18159. /* No key to use. */
  18160. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18161. #endif /* USE_CERT_BUFFERS */
  18162. #ifndef NO_ASN
  18163. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  18164. if (ret != 0) {
  18165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18166. }
  18167. #else
  18168. #ifdef USE_CERT_BUFFERS_2048
  18169. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  18170. if (ret != 0) {
  18171. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18172. }
  18173. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  18174. if (ret != 0) {
  18175. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18176. }
  18177. #ifndef NO_SIG_WRAPPER
  18178. modLen = 2048;
  18179. #endif
  18180. #else
  18181. #error Not supported yet!
  18182. #endif
  18183. #endif
  18184. key->n.dp[0] &= (mp_digit)-2;
  18185. if (ret != 0) {
  18186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18187. }
  18188. /* after loading in key use tmp as the test buffer */
  18189. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  18190. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM))) && \
  18191. !defined(WOLFSSL_XILINX_CRYPT)
  18192. /* The ARM64_ASM code that was FIPS validated did not return these expected
  18193. * failure codes. These tests cases were added after the assembly was
  18194. * in-lined in the module and validated, these tests will be available in
  18195. * the 140-3 module */
  18196. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18197. inLen = 32;
  18198. outSz = wc_RsaEncryptSize(key);
  18199. XMEMSET(tmp, 7, plainSz);
  18200. ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
  18201. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18202. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18203. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18204. {
  18205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18206. }
  18207. ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
  18208. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18209. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18210. {
  18211. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18212. }
  18213. #endif
  18214. #ifdef WC_RSA_BLINDING
  18215. ret = wc_RsaSetRNG(key, rng);
  18216. if (ret < 0) {
  18217. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18218. }
  18219. #endif
  18220. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18221. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18222. ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
  18223. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18224. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18225. {
  18226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18227. }
  18228. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18229. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18230. ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
  18231. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18232. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18233. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18234. {
  18235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18236. }
  18237. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18238. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  18239. /* if making it to this point of code without hitting an ERROR_OUT then
  18240. * all tests have passed */
  18241. ret = 0;
  18242. exit_rsa_even_mod:
  18243. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18244. WC_FREE_VAR(out, HEAP_HINT);
  18245. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18246. WC_FREE_VAR(plain, HEAP_HINT);
  18247. #endif
  18248. (void)out;
  18249. (void)outSz;
  18250. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18251. (void)plain;
  18252. (void)plainSz;
  18253. #endif
  18254. (void)inLen;
  18255. (void)rng;
  18256. return ret;
  18257. }
  18258. #endif /* WOLFSSL_HAVE_SP_RSA */
  18259. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  18260. static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp)
  18261. {
  18262. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18263. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18264. #ifdef WOLFSSL_TEST_CERT
  18265. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18266. #endif
  18267. #else
  18268. RsaKey caKey[1];
  18269. #ifdef WOLFSSL_TEST_CERT
  18270. DecodedCert decode[1];
  18271. #endif
  18272. #endif
  18273. byte* der = NULL;
  18274. wc_test_ret_t ret;
  18275. Cert* myCert = NULL;
  18276. int certSz;
  18277. size_t bytes3;
  18278. word32 idx3 = 0;
  18279. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  18280. XFILE file3;
  18281. #endif
  18282. #if defined(WOLFSSL_ALT_NAMES) && !defined(NO_ASN_TIME)
  18283. struct tm beforeTime;
  18284. struct tm afterTime;
  18285. #endif
  18286. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  18287. (void)keypub;
  18288. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18289. if (caKey == NULL)
  18290. ERROR_OUT(MEMORY_E, exit_rsa);
  18291. #ifdef WOLFSSL_TEST_CERT
  18292. if (decode == NULL)
  18293. ERROR_OUT(MEMORY_E, exit_rsa);
  18294. #endif
  18295. #endif
  18296. XMEMSET(caKey, 0, sizeof *caKey);
  18297. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18298. if (der == NULL) {
  18299. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18300. }
  18301. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18302. if (myCert == NULL) {
  18303. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18304. }
  18305. /* self signed */
  18306. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18307. if (ret != 0) {
  18308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18309. }
  18310. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18311. XMEMCPY(myCert->serial, mySerial, sizeof(mySerial));
  18312. myCert->serialSz = (int)sizeof(mySerial);
  18313. myCert->isCA = 1;
  18314. #ifndef NO_SHA256
  18315. myCert->sigType = CTC_SHA256wRSA;
  18316. #else
  18317. myCert->sigType = CTC_SHAwRSA;
  18318. #endif
  18319. #ifdef WOLFSSL_CERT_EXT
  18320. /* add Policies */
  18321. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18322. CTC_MAX_CERTPOL_SZ);
  18323. XSTRNCPY(myCert->certPolicies[1], "1.2.840.113549.1.9.16.6.5",
  18324. CTC_MAX_CERTPOL_SZ);
  18325. myCert->certPoliciesNb = 2;
  18326. /* add SKID from the Public Key */
  18327. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL);
  18328. if (ret != 0) {
  18329. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18330. }
  18331. /* add AKID from the Public Key */
  18332. ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL);
  18333. if (ret != 0) {
  18334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18335. }
  18336. /* add Key Usage */
  18337. ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign");
  18338. if (ret != 0) {
  18339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18340. }
  18341. #ifdef WOLFSSL_EKU_OID
  18342. {
  18343. const char unique[] = "2.16.840.1.111111.100.1.10.1";
  18344. ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0,
  18345. HEAP_HINT);
  18346. if (ret != 0) {
  18347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18348. }
  18349. }
  18350. #endif /* WOLFSSL_EKU_OID */
  18351. #endif /* WOLFSSL_CERT_EXT */
  18352. do {
  18353. #if defined(WOLFSSL_ASYNC_CRYPT)
  18354. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18355. #endif
  18356. if (ret >= 0) {
  18357. ret = wc_MakeSelfCert(myCert, der, FOURK_BUF, key, rng);
  18358. }
  18359. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18360. if (ret < 0) {
  18361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18362. }
  18363. certSz = (int)ret;
  18364. #ifdef WOLFSSL_TEST_CERT
  18365. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18366. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18367. if (ret != 0) {
  18368. FreeDecodedCert(decode);
  18369. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18370. }
  18371. FreeDecodedCert(decode);
  18372. #endif
  18373. ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile,
  18374. CERT_TYPE);
  18375. if (ret != 0) {
  18376. goto exit_rsa;
  18377. }
  18378. /* Setup Certificate */
  18379. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18380. if (ret < 0) {
  18381. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18382. }
  18383. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  18384. /* Get CA Cert for testing */
  18385. #ifdef USE_CERT_BUFFERS_1024
  18386. XMEMCPY(tmp, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  18387. bytes3 = sizeof_ca_cert_der_1024;
  18388. #elif defined(USE_CERT_BUFFERS_2048)
  18389. XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  18390. bytes3 = sizeof_ca_cert_der_2048;
  18391. #else
  18392. file3 = XFOPEN(rsaCaCertDerFile, "rb");
  18393. if (!file3) {
  18394. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18395. }
  18396. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18397. XFCLOSE(file3);
  18398. if (bytes3 == 0)
  18399. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18400. #endif /* USE_CERT_BUFFERS */
  18401. #if defined(WOLFSSL_ALT_NAMES)
  18402. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \
  18403. !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  18404. ret = wc_SetAltNames(myCert, rsaCaCertFile);
  18405. if (ret != 0)
  18406. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18407. #endif
  18408. /* get alt names from der */
  18409. ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3);
  18410. if (ret != 0)
  18411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18412. /* get dates from der */
  18413. ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3);
  18414. if (ret != 0)
  18415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18416. #ifndef NO_ASN_TIME
  18417. ret = wc_GetCertDates(myCert, &beforeTime, &afterTime);
  18418. if (ret < 0)
  18419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18420. #endif
  18421. #endif /* WOLFSSL_ALT_NAMES */
  18422. #endif /* WOLFSSL_ALT_NAMES || HAVE_PKCS7 */
  18423. /* Get CA Key */
  18424. #ifdef USE_CERT_BUFFERS_1024
  18425. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18426. bytes3 = sizeof_ca_key_der_1024;
  18427. #elif defined(USE_CERT_BUFFERS_2048)
  18428. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18429. bytes3 = sizeof_ca_key_der_2048;
  18430. #else
  18431. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18432. if (!file3) {
  18433. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18434. }
  18435. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18436. XFCLOSE(file3);
  18437. if (bytes3 == 0)
  18438. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18439. #endif /* USE_CERT_BUFFERS */
  18440. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18441. if (ret != 0)
  18442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18443. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18444. if (ret != 0)
  18445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18446. #ifndef NO_SHA256
  18447. myCert->sigType = CTC_SHA256wRSA;
  18448. #else
  18449. myCert->sigType = CTC_SHAwRSA;
  18450. #endif
  18451. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18452. #ifdef WOLFSSL_CERT_EXT
  18453. /* add Policies */
  18454. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18455. CTC_MAX_CERTPOL_SZ);
  18456. myCert->certPoliciesNb =1;
  18457. /* add SKID from the Public Key */
  18458. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL);
  18459. if (ret != 0)
  18460. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18461. /* add AKID from the CA certificate */
  18462. #if defined(USE_CERT_BUFFERS_2048)
  18463. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18464. sizeof_ca_cert_der_2048);
  18465. #elif defined(USE_CERT_BUFFERS_1024)
  18466. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18467. sizeof_ca_cert_der_1024);
  18468. #else
  18469. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18470. #endif
  18471. if (ret != 0)
  18472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18473. /* add Key Usage */
  18474. ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement");
  18475. if (ret != 0)
  18476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18477. #endif /* WOLFSSL_CERT_EXT */
  18478. #if defined(USE_CERT_BUFFERS_2048)
  18479. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18480. sizeof_ca_cert_der_2048);
  18481. #elif defined(USE_CERT_BUFFERS_1024)
  18482. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18483. sizeof_ca_cert_der_1024);
  18484. #else
  18485. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18486. #endif
  18487. if (ret < 0)
  18488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18489. certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng);
  18490. if (certSz < 0) {
  18491. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18492. }
  18493. ret = 0;
  18494. do {
  18495. #if defined(WOLFSSL_ASYNC_CRYPT)
  18496. ret = wc_AsyncWait(ret, &caKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18497. #endif
  18498. if (ret >= 0) {
  18499. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der, FOURK_BUF,
  18500. caKey, NULL, rng);
  18501. }
  18502. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18503. if (ret < 0)
  18504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18505. certSz = (int)ret;
  18506. #ifdef WOLFSSL_TEST_CERT
  18507. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18508. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18509. if (ret != 0) {
  18510. FreeDecodedCert(decode);
  18511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18512. }
  18513. FreeDecodedCert(decode);
  18514. #endif
  18515. ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile,
  18516. CERT_TYPE);
  18517. if (ret != 0) {
  18518. goto exit_rsa;
  18519. }
  18520. exit_rsa:
  18521. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18522. if (caKey != NULL) {
  18523. wc_FreeRsaKey(caKey);
  18524. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18525. }
  18526. #ifdef WOLFSSL_TEST_CERT
  18527. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18528. #endif
  18529. #else
  18530. wc_FreeRsaKey(caKey);
  18531. #endif
  18532. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18533. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18534. return ret;
  18535. }
  18536. #endif
  18537. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
  18538. defined(WOLFSSL_CERT_GEN)
  18539. /* Make Cert / Sign example for ECC cert and RSA CA */
  18540. static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
  18541. {
  18542. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18543. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18544. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18545. ecc_key *caEccKeyPub = (ecc_key *)XMALLOC(sizeof *caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18546. #ifdef WOLFSSL_TEST_CERT
  18547. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18548. #endif
  18549. #else
  18550. RsaKey caKey[1];
  18551. ecc_key caEccKey[1];
  18552. ecc_key caEccKeyPub[1];
  18553. #ifdef WOLFSSL_TEST_CERT
  18554. DecodedCert decode[1];
  18555. #endif
  18556. #endif
  18557. byte* der = NULL;
  18558. Cert* myCert = NULL;
  18559. int certSz;
  18560. size_t bytes3;
  18561. word32 idx3 = 0;
  18562. #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
  18563. || !defined(USE_CERT_BUFFERS_256)
  18564. #ifndef NO_FILESYSTEM
  18565. XFILE file3;
  18566. #endif
  18567. #endif
  18568. wc_test_ret_t ret;
  18569. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18570. if ((caKey == NULL) || (caEccKey == NULL) || (caEccKeyPub == NULL)
  18571. #ifdef WOLFSSL_TEST_CERT
  18572. || (decode == NULL)
  18573. #endif
  18574. )
  18575. ERROR_OUT(MEMORY_E, exit_rsa);
  18576. #endif
  18577. XMEMSET(caKey, 0, sizeof *caKey);
  18578. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  18579. XMEMSET(caEccKeyPub, 0, sizeof *caEccKeyPub);
  18580. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18581. if (der == NULL) {
  18582. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18583. }
  18584. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18585. if (myCert == NULL) {
  18586. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18587. }
  18588. /* Get CA Key */
  18589. #ifdef USE_CERT_BUFFERS_1024
  18590. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18591. bytes3 = sizeof_ca_key_der_1024;
  18592. #elif defined(USE_CERT_BUFFERS_2048)
  18593. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18594. bytes3 = sizeof_ca_key_der_2048;
  18595. #else
  18596. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18597. if (!file3) {
  18598. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18599. }
  18600. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18601. XFCLOSE(file3);
  18602. if (bytes3 == 0)
  18603. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18604. #endif /* USE_CERT_BUFFERS */
  18605. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18606. if (ret != 0)
  18607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18608. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18609. if (ret != 0)
  18610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18611. /* Get Cert Key */
  18612. #if defined(USE_CERT_BUFFERS_256)
  18613. {
  18614. XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
  18615. bytes3 = sizeof_ecc_key_pub_der_256;
  18616. }
  18617. #elif !defined(NO_FILESYSTEM)
  18618. {
  18619. file3 = XFOPEN(eccKeyPubFileDer, "rb");
  18620. if (!file3) {
  18621. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18622. }
  18623. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18624. XFCLOSE(file3);
  18625. if (bytes3 == 0)
  18626. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18627. }
  18628. #else
  18629. {
  18630. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
  18631. ERROR_OUT(ASN_PARSE_E, exit_rsa);
  18632. }
  18633. #endif
  18634. ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
  18635. if (ret != 0)
  18636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18637. idx3 = 0;
  18638. ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3);
  18639. if (ret != 0)
  18640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18641. /* Setup Certificate */
  18642. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18643. if (ret != 0)
  18644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18645. #ifndef NO_SHA256
  18646. myCert->sigType = CTC_SHA256wRSA;
  18647. #else
  18648. myCert->sigType = CTC_SHAwRSA;
  18649. #endif
  18650. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18651. #ifdef WOLFSSL_CERT_EXT
  18652. /* add Policies */
  18653. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  18654. CTC_MAX_CERTPOL_SZ);
  18655. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  18656. CTC_MAX_CERTPOL_SZ);
  18657. myCert->certPoliciesNb = 2;
  18658. /* add SKID from the Public Key */
  18659. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub);
  18660. if (ret != 0)
  18661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18662. /* add AKID from the CA certificate */
  18663. #if defined(USE_CERT_BUFFERS_2048)
  18664. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18665. sizeof_ca_cert_der_2048);
  18666. #elif defined(USE_CERT_BUFFERS_1024)
  18667. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18668. sizeof_ca_cert_der_1024);
  18669. #else
  18670. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18671. #endif
  18672. if (ret != 0)
  18673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18674. /* add Key Usage */
  18675. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  18676. if (ret != 0)
  18677. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18678. #endif /* WOLFSSL_CERT_EXT */
  18679. #if defined(USE_CERT_BUFFERS_2048)
  18680. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18681. sizeof_ca_cert_der_2048);
  18682. #elif defined(USE_CERT_BUFFERS_1024)
  18683. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18684. sizeof_ca_cert_der_1024);
  18685. #else
  18686. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18687. #endif
  18688. if (ret < 0)
  18689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18690. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng);
  18691. if (certSz < 0) {
  18692. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18693. }
  18694. ret = 0;
  18695. do {
  18696. #if defined(WOLFSSL_ASYNC_CRYPT)
  18697. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18698. #endif
  18699. if (ret >= 0) {
  18700. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  18701. FOURK_BUF, caKey, NULL, rng);
  18702. }
  18703. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18704. if (ret < 0)
  18705. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18706. certSz = (int)ret;
  18707. #ifdef WOLFSSL_TEST_CERT
  18708. InitDecodedCert(decode, der, certSz, 0);
  18709. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18710. if (ret != 0) {
  18711. FreeDecodedCert(decode);
  18712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18713. }
  18714. FreeDecodedCert(decode);
  18715. #endif
  18716. ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile,
  18717. CERT_TYPE);
  18718. if (ret != 0) {
  18719. goto exit_rsa;
  18720. }
  18721. exit_rsa:
  18722. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18723. if (caKey != NULL) {
  18724. wc_FreeRsaKey(caKey);
  18725. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18726. }
  18727. if (caEccKey != NULL) {
  18728. wc_ecc_free(caEccKey);
  18729. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18730. }
  18731. if (caEccKeyPub != NULL) {
  18732. wc_ecc_free(caEccKeyPub);
  18733. XFREE(caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18734. }
  18735. #ifdef WOLFSSL_TEST_CERT
  18736. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18737. #endif
  18738. #else
  18739. wc_FreeRsaKey(caKey);
  18740. wc_ecc_free(caEccKey);
  18741. wc_ecc_free(caEccKeyPub);
  18742. #endif
  18743. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18744. myCert = NULL;
  18745. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18746. der = NULL;
  18747. if (ret >= 0)
  18748. ret = 0;
  18749. return ret;
  18750. }
  18751. #endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
  18752. #ifdef WOLFSSL_KEY_GEN
  18753. static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
  18754. {
  18755. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18756. RsaKey *genKey = (RsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18757. #else
  18758. RsaKey genKey[1];
  18759. #endif
  18760. wc_test_ret_t ret;
  18761. #ifndef WOLFSSL_NO_MALLOC
  18762. byte* der = NULL;
  18763. #else
  18764. byte der[1280];
  18765. #endif
  18766. #ifndef WOLFSSL_CRYPTOCELL
  18767. word32 idx = 0;
  18768. #endif
  18769. int derSz = 0;
  18770. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FIPS) && \
  18771. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18772. int keySz = 1024;
  18773. #else
  18774. int keySz = 2048;
  18775. #endif
  18776. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18777. if (! genKey)
  18778. ERROR_OUT(MEMORY_E, exit_rsa);
  18779. #endif
  18780. XMEMSET(genKey, 0, sizeof *genKey);
  18781. ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId);
  18782. if (ret != 0)
  18783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18784. #ifdef HAVE_FIPS
  18785. for (;;) {
  18786. #endif
  18787. ret = wc_MakeRsaKey(genKey, keySz, WC_RSA_EXPONENT, rng);
  18788. #if defined(WOLFSSL_ASYNC_CRYPT)
  18789. ret = wc_AsyncWait(ret, &genKey->asyncDev, WC_ASYNC_FLAG_NONE);
  18790. #endif
  18791. #ifdef HAVE_FIPS
  18792. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  18793. continue;
  18794. break;
  18795. }
  18796. #endif
  18797. if (ret != 0)
  18798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18799. TEST_SLEEP();
  18800. #ifdef WOLFSSL_RSA_KEY_CHECK
  18801. ret = wc_CheckRsaKey(genKey);
  18802. if (ret != 0)
  18803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18804. #endif
  18805. #ifndef WOLFSSL_NO_MALLOC
  18806. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18807. if (der == NULL) {
  18808. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18809. }
  18810. derSz = FOURK_BUF;
  18811. #else
  18812. derSz = sizeof(der);
  18813. #endif
  18814. derSz = wc_RsaKeyToDer(genKey, der, derSz);
  18815. if (derSz < 0) {
  18816. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  18817. }
  18818. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  18819. PRIVATEKEY_TYPE);
  18820. if (ret != 0) {
  18821. goto exit_rsa;
  18822. }
  18823. wc_FreeRsaKey(genKey);
  18824. ret = wc_InitRsaKey(genKey, HEAP_HINT);
  18825. if (ret != 0)
  18826. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18827. #ifndef WOLFSSL_CRYPTOCELL
  18828. idx = 0;
  18829. /* The private key part of the key gen pairs from cryptocell can't be exported */
  18830. ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, (word32)derSz);
  18831. if (ret != 0)
  18832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18833. #endif /* WOLFSSL_CRYPTOCELL */
  18834. exit_rsa:
  18835. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18836. if (genKey) {
  18837. wc_FreeRsaKey(genKey);
  18838. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18839. }
  18840. #else
  18841. wc_FreeRsaKey(genKey);
  18842. #endif
  18843. #ifndef WOLFSSL_NO_MALLOC
  18844. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18845. der = NULL;
  18846. #endif
  18847. return ret;
  18848. }
  18849. #endif
  18850. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18851. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) && \
  18852. (!defined(HAVE_FIPS) || \
  18853. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  18854. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  18855. static wc_test_ret_t rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng)
  18856. {
  18857. wc_test_ret_t ret = 0;
  18858. word32 idx = 0;
  18859. const char inStr[] = TEST_STRING;
  18860. const word32 inLen = (word32)TEST_STRING_SZ;
  18861. const word32 outSz = RSA_TEST_BYTES;
  18862. const word32 plainSz = RSA_TEST_BYTES;
  18863. byte* res = NULL;
  18864. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18865. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18866. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18867. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18868. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18869. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18870. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18871. if (in == NULL || out == NULL || plain == NULL)
  18872. ERROR_OUT(MEMORY_E, exit_rsa);
  18873. #endif
  18874. XMEMCPY(in, inStr, inLen);
  18875. #ifndef NO_SHA
  18876. do {
  18877. #if defined(WOLFSSL_ASYNC_CRYPT)
  18878. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18879. #endif
  18880. if (ret >= 0) {
  18881. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18882. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18883. }
  18884. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18885. if (ret < 0)
  18886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18887. TEST_SLEEP();
  18888. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18889. idx = (word32)ret;
  18890. do {
  18891. #if defined(WOLFSSL_ASYNC_CRYPT)
  18892. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18893. #endif
  18894. if (ret >= 0) {
  18895. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18896. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18897. }
  18898. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18899. if (ret < 0)
  18900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18901. if (XMEMCMP(plain, in, inLen)) {
  18902. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18903. }
  18904. TEST_SLEEP();
  18905. #endif /* NO_SHA */
  18906. #endif
  18907. #ifndef NO_SHA256
  18908. XMEMSET(plain, 0, plainSz);
  18909. do {
  18910. #if defined(WOLFSSL_ASYNC_CRYPT)
  18911. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18912. #endif
  18913. if (ret >= 0) {
  18914. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18915. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18916. }
  18917. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18918. if (ret < 0)
  18919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18920. TEST_SLEEP();
  18921. idx = (word32)ret;
  18922. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18923. do {
  18924. #if defined(WOLFSSL_ASYNC_CRYPT)
  18925. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18926. #endif
  18927. if (ret >= 0) {
  18928. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18929. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18930. }
  18931. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18932. if (ret < 0)
  18933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18934. if (XMEMCMP(plain, in, inLen)) {
  18935. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18936. }
  18937. TEST_SLEEP();
  18938. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18939. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18940. do {
  18941. #if defined(WOLFSSL_ASYNC_CRYPT)
  18942. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18943. #endif
  18944. if (ret >= 0) {
  18945. ret = wc_RsaPrivateDecryptInline_ex(out, idx, &res, key,
  18946. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18947. }
  18948. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18949. if (ret < 0)
  18950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18951. if (ret != (int)inLen) {
  18952. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18953. }
  18954. if (XMEMCMP(res, in, inLen)) {
  18955. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18956. }
  18957. TEST_SLEEP();
  18958. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18959. /* check fails if not using the same optional label */
  18960. XMEMSET(plain, 0, plainSz);
  18961. do {
  18962. #if defined(WOLFSSL_ASYNC_CRYPT)
  18963. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18964. #endif
  18965. if (ret >= 0) {
  18966. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18967. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18968. }
  18969. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18970. if (ret < 0)
  18971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18972. TEST_SLEEP();
  18973. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18974. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18975. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18976. /* label is unused in cryptocell and SE050 so it won't detect decrypt error
  18977. * due to label */
  18978. idx = (word32)ret;
  18979. do {
  18980. #if defined(WOLFSSL_ASYNC_CRYPT)
  18981. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18982. #endif
  18983. if (ret >= 0) {
  18984. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18985. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18986. }
  18987. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18988. if (ret > 0) { /* in this case decrypt should fail */
  18989. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18990. }
  18991. ret = 0;
  18992. TEST_SLEEP();
  18993. #endif /* !HAVE_CAVIUM */
  18994. /* check using optional label with encrypt/decrypt */
  18995. XMEMSET(plain, 0, plainSz);
  18996. do {
  18997. #if defined(WOLFSSL_ASYNC_CRYPT)
  18998. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18999. #endif
  19000. if (ret >= 0) {
  19001. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19002. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19003. }
  19004. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19005. if (ret < 0)
  19006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19007. TEST_SLEEP();
  19008. idx = (word32)ret;
  19009. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19010. do {
  19011. #if defined(WOLFSSL_ASYNC_CRYPT)
  19012. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19013. #endif
  19014. if (ret >= 0) {
  19015. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19016. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19017. }
  19018. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19019. if (ret < 0)
  19020. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19021. if (XMEMCMP(plain, in, inLen)) {
  19022. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19023. }
  19024. TEST_SLEEP();
  19025. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19026. #ifndef NO_SHA
  19027. /* check fail using mismatch hash algorithms */
  19028. XMEMSET(plain, 0, plainSz);
  19029. do {
  19030. #if defined(WOLFSSL_ASYNC_CRYPT)
  19031. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19032. #endif
  19033. if (ret >= 0) {
  19034. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19035. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen);
  19036. }
  19037. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19038. if (ret < 0)
  19039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19040. TEST_SLEEP();
  19041. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  19042. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19043. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  19044. idx = (word32)ret;
  19045. do {
  19046. #if defined(WOLFSSL_ASYNC_CRYPT)
  19047. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19048. #endif
  19049. if (ret >= 0) {
  19050. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19051. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256,
  19052. in, inLen);
  19053. }
  19054. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19055. if (ret > 0) { /* should fail */
  19056. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19057. }
  19058. ret = 0;
  19059. TEST_SLEEP();
  19060. #endif /* !HAVE_CAVIUM */
  19061. #endif /* NO_SHA */
  19062. #endif /* NO_SHA256 */
  19063. #ifdef WOLFSSL_SHA512
  19064. /* Check valid RSA key size is used while using hash length of SHA512
  19065. If key size is less than (hash length * 2) + 2 then is invalid use
  19066. and test, since OAEP padding requires this.
  19067. BAD_FUNC_ARG is returned when this case is not met */
  19068. if (wc_RsaEncryptSize(key) > ((int)WC_SHA512_DIGEST_SIZE * 2) + 2) {
  19069. XMEMSET(plain, 0, plainSz);
  19070. do {
  19071. #if defined(WOLFSSL_ASYNC_CRYPT)
  19072. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19073. #endif
  19074. if (ret >= 0) {
  19075. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19076. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19077. }
  19078. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19079. if (ret < 0)
  19080. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19081. TEST_SLEEP();
  19082. idx = (word32)ret;
  19083. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19084. do {
  19085. #if defined(WOLFSSL_ASYNC_CRYPT)
  19086. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19087. #endif
  19088. if (ret >= 0) {
  19089. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19090. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19091. }
  19092. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19093. if (ret < 0)
  19094. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19095. if (XMEMCMP(plain, in, inLen)) {
  19096. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19097. }
  19098. TEST_SLEEP();
  19099. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19100. }
  19101. #endif /* WOLFSSL_SHA512 */
  19102. /* check using pkcsv15 padding with _ex API */
  19103. XMEMSET(plain, 0, plainSz);
  19104. do {
  19105. #if defined(WOLFSSL_ASYNC_CRYPT)
  19106. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19107. #endif
  19108. if (ret >= 0) {
  19109. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19110. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19111. }
  19112. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19113. if (ret < 0)
  19114. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19115. TEST_SLEEP();
  19116. idx = (word32)ret;
  19117. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19118. do {
  19119. #if defined(WOLFSSL_ASYNC_CRYPT)
  19120. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19121. #endif
  19122. if (ret >= 0) {
  19123. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19124. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19125. }
  19126. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19127. if (ret < 0)
  19128. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19129. if (XMEMCMP(plain, in, inLen)) {
  19130. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19131. }
  19132. TEST_SLEEP();
  19133. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19134. exit_rsa:
  19135. WC_FREE_VAR(in, HEAP_HINT);
  19136. WC_FREE_VAR(out, HEAP_HINT);
  19137. WC_FREE_VAR(plain, HEAP_HINT);
  19138. (void)idx;
  19139. (void)inStr;
  19140. (void)res;
  19141. if (ret >= 0)
  19142. ret = 0;
  19143. return ret;
  19144. }
  19145. #endif
  19146. #endif
  19147. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
  19148. {
  19149. wc_test_ret_t ret;
  19150. size_t bytes = 0;
  19151. WC_RNG rng;
  19152. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19153. byte* tmp = NULL;
  19154. byte* der = NULL;
  19155. RsaKey *key = NULL;
  19156. #else
  19157. RsaKey key[1];
  19158. byte tmp[FOURK_BUF];
  19159. #endif
  19160. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19161. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19162. RsaKey *keypub = NULL;
  19163. #else
  19164. RsaKey keypub[1];
  19165. #endif
  19166. #endif
  19167. word32 idx = 0;
  19168. const char inStr[] = TEST_STRING;
  19169. const word32 inLen = (word32)TEST_STRING_SZ;
  19170. const word32 outSz = RSA_TEST_BYTES;
  19171. const word32 plainSz = RSA_TEST_BYTES;
  19172. byte* res = NULL;
  19173. #ifndef NO_SIG_WRAPPER
  19174. int modLen;
  19175. #endif
  19176. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19177. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  19178. !defined(NO_FILESYSTEM)
  19179. XFILE file;
  19180. #ifdef WOLFSSL_TEST_CERT
  19181. XFILE file2;
  19182. #endif
  19183. #endif
  19184. #ifdef WOLFSSL_TEST_CERT
  19185. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19186. DecodedCert *cert = (DecodedCert *)XMALLOC(sizeof *cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19187. #else
  19188. DecodedCert cert[1];
  19189. #endif
  19190. #ifndef NO_ASN_TIME
  19191. struct tm timearg;
  19192. const byte* date;
  19193. byte dateFormat;
  19194. int dateLength;
  19195. #endif
  19196. #endif
  19197. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19198. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19199. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19200. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19201. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19202. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19203. WOLFSSL_ENTER("rsa_test");
  19204. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  19205. if (in == NULL || out == NULL || plain == NULL)
  19206. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19207. #endif
  19208. XMEMCPY(in, inStr, inLen);
  19209. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19210. key = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19211. if (key == NULL)
  19212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19213. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19214. keypub = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19215. if (keypub == NULL)
  19216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19217. #endif
  19218. #ifdef WOLFSSL_TEST_CERT
  19219. if (cert == NULL)
  19220. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19221. #endif
  19222. #else /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19223. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19224. if (ret != 0)
  19225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19226. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19227. ret = wc_InitRsaKey_ex(keypub, HEAP_HINT, devId);
  19228. if (ret != 0)
  19229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19230. #endif
  19231. #endif /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19232. /* initialize stack structures */
  19233. XMEMSET(&rng, 0, sizeof(rng));
  19234. #if !defined(NO_ASN)
  19235. ret = rsa_decode_test(key);
  19236. if (ret != 0)
  19237. ERROR_OUT(ret, exit_rsa);
  19238. #endif
  19239. #ifdef USE_CERT_BUFFERS_1024
  19240. bytes = (size_t)sizeof_client_key_der_1024;
  19241. if (bytes < (size_t)sizeof_client_cert_der_1024)
  19242. bytes = (size_t)sizeof_client_cert_der_1024;
  19243. #elif defined(USE_CERT_BUFFERS_2048)
  19244. bytes = (size_t)sizeof_client_key_der_2048;
  19245. if (bytes < (size_t)sizeof_client_cert_der_2048)
  19246. bytes = (size_t)sizeof_client_cert_der_2048;
  19247. #elif defined(USE_CERT_BUFFERS_3072)
  19248. bytes = (size_t)sizeof_client_key_der_3072;
  19249. if (bytes < (size_t)sizeof_client_cert_der_3072)
  19250. bytes = (size_t)sizeof_client_cert_der_3072;
  19251. #elif defined(USE_CERT_BUFFERS_4096)
  19252. bytes = (size_t)sizeof_client_key_der_4096;
  19253. if (bytes < (size_t)sizeof_client_cert_der_4096)
  19254. bytes = (size_t)sizeof_client_cert_der_4096;
  19255. #else
  19256. bytes = FOURK_BUF;
  19257. #endif
  19258. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19259. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19260. if (tmp == NULL)
  19261. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19262. #endif
  19263. #ifdef USE_CERT_BUFFERS_1024
  19264. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  19265. #elif defined(USE_CERT_BUFFERS_2048)
  19266. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  19267. #elif defined(USE_CERT_BUFFERS_3072)
  19268. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  19269. #elif defined(USE_CERT_BUFFERS_4096)
  19270. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  19271. #elif !defined(NO_FILESYSTEM)
  19272. file = XFOPEN(clientKey, "rb");
  19273. if (!file) {
  19274. err_sys("can't open ./certs/client-key.der, "
  19275. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19276. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19277. }
  19278. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19279. XFCLOSE(file);
  19280. if (bytes == 0)
  19281. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19282. #else
  19283. /* No key to use. */
  19284. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19285. #endif /* USE_CERT_BUFFERS */
  19286. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19287. if (ret != 0)
  19288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19289. #ifndef NO_ASN
  19290. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  19291. if (ret != 0)
  19292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19293. #ifndef NO_SIG_WRAPPER
  19294. modLen = wc_RsaEncryptSize(key);
  19295. #endif
  19296. #else
  19297. #ifdef USE_CERT_BUFFERS_2048
  19298. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  19299. if (ret != 0)
  19300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19301. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  19302. if (ret != 0)
  19303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19304. #ifndef NO_SIG_WRAPPER
  19305. modLen = 2048;
  19306. #endif
  19307. #else
  19308. #error Not supported yet!
  19309. #endif
  19310. #endif
  19311. #ifndef WC_NO_RNG
  19312. #ifndef HAVE_FIPS
  19313. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  19314. #else
  19315. ret = wc_InitRng(&rng);
  19316. #endif
  19317. if (ret != 0)
  19318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19319. #endif
  19320. #ifndef NO_SIG_WRAPPER
  19321. ret = rsa_sig_test(key, sizeof *key, modLen, &rng);
  19322. if (ret != 0)
  19323. goto exit_rsa;
  19324. #endif
  19325. #ifdef WC_RSA_NONBLOCK
  19326. ret = rsa_nb_test(key, in, inLen, out, outSz, plain, plainSz, &rng);
  19327. if (ret != 0)
  19328. goto exit_rsa;
  19329. #endif
  19330. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19331. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19332. do {
  19333. #if defined(WOLFSSL_ASYNC_CRYPT)
  19334. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19335. #endif
  19336. if (ret >= 0) {
  19337. ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng);
  19338. }
  19339. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19340. if (ret < 0)
  19341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19342. TEST_SLEEP();
  19343. #ifdef WC_RSA_BLINDING
  19344. {
  19345. wc_test_ret_t tmpret = ret;
  19346. ret = wc_RsaSetRNG(key, &rng);
  19347. if (ret < 0)
  19348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19349. ret = tmpret;
  19350. }
  19351. #endif
  19352. idx = (word32)ret; /* save off encrypted length */
  19353. do {
  19354. #if defined(WOLFSSL_ASYNC_CRYPT)
  19355. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19356. #endif
  19357. if (ret >= 0) {
  19358. ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key);
  19359. }
  19360. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19361. if (ret < 0)
  19362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19363. if (XMEMCMP(plain, in, inLen)) {
  19364. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19365. }
  19366. TEST_SLEEP();
  19367. do {
  19368. #if defined(WOLFSSL_ASYNC_CRYPT)
  19369. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19370. #endif
  19371. if (ret >= 0) {
  19372. ret = wc_RsaPrivateDecryptInline(out, idx, &res, key);
  19373. }
  19374. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19375. if (ret < 0)
  19376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19377. if (ret != (int)inLen) {
  19378. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19379. }
  19380. if (XMEMCMP(res, in, inLen)) {
  19381. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19382. }
  19383. TEST_SLEEP();
  19384. do {
  19385. #if defined(WOLFSSL_ASYNC_CRYPT)
  19386. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19387. #endif
  19388. if (ret >= 0) {
  19389. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
  19390. }
  19391. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19392. if (ret < 0)
  19393. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19394. TEST_SLEEP();
  19395. #elif defined(WOLFSSL_PUBLIC_MP)
  19396. {
  19397. static const byte signature_2048[] = {
  19398. 0x07, 0x6f, 0xc9, 0x85, 0x73, 0x9e, 0x21, 0x79,
  19399. 0x47, 0xf1, 0xa3, 0xd7, 0xf4, 0x27, 0x29, 0xbe,
  19400. 0x99, 0x5d, 0xac, 0xb2, 0x10, 0x3f, 0x95, 0xda,
  19401. 0x89, 0x23, 0xb8, 0x96, 0x13, 0x57, 0x72, 0x30,
  19402. 0xa1, 0xfe, 0x5a, 0x68, 0x9c, 0x99, 0x9d, 0x1e,
  19403. 0x05, 0xa4, 0x80, 0xb0, 0xbb, 0xd9, 0xd9, 0xa1,
  19404. 0x69, 0x97, 0x74, 0xb3, 0x41, 0x21, 0x3b, 0x47,
  19405. 0xf5, 0x51, 0xb1, 0xfb, 0xc7, 0xaa, 0xcc, 0xdc,
  19406. 0xcd, 0x76, 0xa0, 0x28, 0x4d, 0x27, 0x14, 0xa4,
  19407. 0xb9, 0x41, 0x68, 0x7c, 0xb3, 0x66, 0xe6, 0x6f,
  19408. 0x40, 0x76, 0xe4, 0x12, 0xfd, 0xae, 0x29, 0xb5,
  19409. 0x63, 0x60, 0x87, 0xce, 0x49, 0x6b, 0xf3, 0x05,
  19410. 0x9a, 0x14, 0xb5, 0xcc, 0xcd, 0xf7, 0x30, 0x95,
  19411. 0xd2, 0x72, 0x52, 0x1d, 0x5b, 0x7e, 0xef, 0x4a,
  19412. 0x02, 0x96, 0x21, 0x6c, 0x55, 0xa5, 0x15, 0xb1,
  19413. 0x57, 0x63, 0x2c, 0xa3, 0x8e, 0x9d, 0x3d, 0x45,
  19414. 0xcc, 0xb8, 0xe6, 0xa1, 0xc8, 0x59, 0xcd, 0xf5,
  19415. 0xdc, 0x0a, 0x51, 0xb6, 0x9d, 0xfb, 0xf4, 0x6b,
  19416. 0xfd, 0x32, 0x71, 0x6e, 0xcf, 0xcb, 0xb3, 0xd9,
  19417. 0xe0, 0x4a, 0x77, 0x34, 0xd6, 0x61, 0xf5, 0x7c,
  19418. 0xf9, 0xa9, 0xa4, 0xb0, 0x8e, 0x3b, 0xd6, 0x04,
  19419. 0xe0, 0xde, 0x2b, 0x5b, 0x5a, 0xbf, 0xd9, 0xef,
  19420. 0x8d, 0xa3, 0xf5, 0xb1, 0x67, 0xf3, 0xb9, 0x72,
  19421. 0x0a, 0x37, 0x12, 0x35, 0x6c, 0x8e, 0x10, 0x8b,
  19422. 0x38, 0x06, 0x16, 0x4b, 0x20, 0x20, 0x13, 0x00,
  19423. 0x2e, 0x6d, 0xc2, 0x59, 0x23, 0x67, 0x4a, 0x6d,
  19424. 0xa1, 0x46, 0x8b, 0xee, 0xcf, 0x44, 0xb4, 0x3e,
  19425. 0x56, 0x75, 0x00, 0x68, 0xb5, 0x7d, 0x0f, 0x20,
  19426. 0x79, 0x5d, 0x7f, 0x12, 0x15, 0x32, 0x89, 0x61,
  19427. 0x6b, 0x29, 0xb7, 0x52, 0xf5, 0x25, 0xd8, 0x98,
  19428. 0xe8, 0x6f, 0xf9, 0x22, 0xb4, 0xbb, 0xe5, 0xff,
  19429. 0xd0, 0x92, 0x86, 0x9a, 0x88, 0xa2, 0xaf, 0x6b
  19430. };
  19431. ret = sizeof(signature_2048);
  19432. XMEMCPY(out, signature_2048, ret);
  19433. }
  19434. #endif
  19435. #if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
  19436. ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  19437. defined(WOLFSSL_PUBLIC_MP)) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19438. idx = (word32)ret;
  19439. XMEMSET(plain, 0, plainSz);
  19440. do {
  19441. #if defined(WOLFSSL_ASYNC_CRYPT)
  19442. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19443. #endif
  19444. if (ret >= 0) {
  19445. #ifndef WOLFSSL_RSA_VERIFY_INLINE
  19446. #if defined(WOLFSSL_CRYPTOCELL)
  19447. /*
  19448. Cryptocell requires the input data and signature byte array to verify.
  19449. first argument must be the input data
  19450. second argument must be the length of input data
  19451. third argument must be the signature byte array or the output from
  19452. wc_RsaSSL_Sign()
  19453. fourth argument must be the length of the signature byte array
  19454. */
  19455. ret = wc_RsaSSL_Verify(in, inLen, out, outSz, key);
  19456. #else
  19457. ret = wc_RsaSSL_Verify(out, idx, plain, plainSz, key);
  19458. #endif /* WOLFSSL_CRYPTOCELL */
  19459. #else
  19460. byte* dec = NULL;
  19461. ret = wc_RsaSSL_VerifyInline(out, idx, &dec, key);
  19462. if (ret > 0) {
  19463. XMEMCPY(plain, dec, ret);
  19464. }
  19465. #endif
  19466. }
  19467. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19468. if (ret < 0)
  19469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19470. if (XMEMCMP(plain, in, (size_t)ret)) {
  19471. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19472. }
  19473. TEST_SLEEP();
  19474. #endif
  19475. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  19476. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG)
  19477. #if (!defined(HAVE_FIPS) || \
  19478. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  19479. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19480. ret = rsa_oaep_padding_test(key, &rng);
  19481. if (ret != 0)
  19482. goto exit_rsa;
  19483. #endif /* !HAVE_FIPS */
  19484. #endif /* WC_NO_RSA_OAEP && !WC_NO_RNG */
  19485. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  19486. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  19487. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19488. ret = rsa_export_key_test(key);
  19489. if (ret != 0)
  19490. goto exit_rsa;
  19491. #endif
  19492. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19493. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19494. ret = rsa_flatten_test(key);
  19495. if (ret != 0)
  19496. goto exit_rsa;
  19497. #endif
  19498. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_ASN) && \
  19499. !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19500. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  19501. (void)clientCert;
  19502. #endif
  19503. #ifdef WOLFSSL_TEST_CERT
  19504. #ifdef USE_CERT_BUFFERS_1024
  19505. XMEMCPY(tmp, client_cert_der_1024, (size_t)sizeof_client_cert_der_1024);
  19506. bytes = (size_t)sizeof_client_cert_der_1024;
  19507. #elif defined(USE_CERT_BUFFERS_2048)
  19508. XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048);
  19509. bytes = (size_t)sizeof_client_cert_der_2048;
  19510. #elif defined(USE_CERT_BUFFERS_3072)
  19511. XMEMCPY(tmp, client_cert_der_3072, (size_t)sizeof_client_cert_der_3072);
  19512. bytes = (size_t)sizeof_client_cert_der_3072;
  19513. #elif defined(USE_CERT_BUFFERS_4096)
  19514. XMEMCPY(tmp, client_cert_der_4096, (size_t)sizeof_client_cert_der_4096);
  19515. bytes = (size_t)sizeof_client_cert_der_4096;
  19516. #elif !defined(NO_FILESYSTEM)
  19517. file2 = XFOPEN(clientCert, "rb");
  19518. if (!file2) {
  19519. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19520. }
  19521. bytes = XFREAD(tmp, 1, FOURK_BUF, file2);
  19522. XFCLOSE(file2);
  19523. if (bytes == 0)
  19524. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19525. #else
  19526. /* No certificate to use. */
  19527. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19528. #endif
  19529. InitDecodedCert(cert, tmp, (word32)bytes, NULL);
  19530. ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
  19531. if (ret != 0) {
  19532. FreeDecodedCert(cert);
  19533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19534. }
  19535. #ifndef NO_ASN_TIME
  19536. ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
  19537. &dateFormat, &dateLength);
  19538. if (ret != 0) {
  19539. FreeDecodedCert(cert);
  19540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19541. }
  19542. ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
  19543. if (ret != 0) {
  19544. FreeDecodedCert(cert);
  19545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19546. }
  19547. #endif
  19548. FreeDecodedCert(cert);
  19549. #endif /* WOLFSSL_TEST_CERT */
  19550. #ifdef WOLFSSL_CERT_EXT
  19551. #ifdef USE_CERT_BUFFERS_1024
  19552. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  19553. bytes = sizeof_client_keypub_der_1024;
  19554. #elif defined(USE_CERT_BUFFERS_2048)
  19555. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  19556. bytes = sizeof_client_keypub_der_2048;
  19557. #elif defined(USE_CERT_BUFFERS_3072)
  19558. XMEMCPY(tmp, client_keypub_der_3072, sizeof_client_keypub_der_3072);
  19559. bytes = sizeof_client_keypub_der_3072;
  19560. #elif defined(USE_CERT_BUFFERS_4096)
  19561. XMEMCPY(tmp, client_keypub_der_4096, sizeof_client_keypub_der_4096);
  19562. bytes = sizeof_client_keypub_der_4096;
  19563. #else
  19564. file = XFOPEN(clientKeyPub, "rb");
  19565. if (!file) {
  19566. err_sys("can't open ./certs/client-keyPub.der, "
  19567. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19568. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19569. }
  19570. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19571. XFCLOSE(file);
  19572. if (bytes == 0)
  19573. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19574. #endif /* USE_CERT_BUFFERS */
  19575. ret = wc_InitRsaKey(keypub, HEAP_HINT);
  19576. if (ret != 0)
  19577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19578. idx = 0;
  19579. ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
  19580. if (ret != 0)
  19581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19582. #endif /* WOLFSSL_CERT_EXT */
  19583. #ifdef WOLFSSL_KEY_GEN
  19584. ret = rsa_keygen_test(&rng);
  19585. if (ret != 0)
  19586. goto exit_rsa;
  19587. #endif
  19588. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  19589. !defined(WOLFSSL_NO_MALLOC)
  19590. /* Make Cert / Sign example for RSA cert and RSA CA */
  19591. ret = rsa_certgen_test(key, keypub, &rng, tmp);
  19592. if (ret != 0)
  19593. goto exit_rsa;
  19594. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP)
  19595. ret = rsa_ecc_certgen_test(&rng, tmp);
  19596. if (ret != 0)
  19597. goto exit_rsa;
  19598. #endif
  19599. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  19600. {
  19601. Cert *req;
  19602. int derSz;
  19603. #ifndef WOLFSSL_SMALL_STACK
  19604. byte* der = NULL;
  19605. #endif
  19606. req = (Cert *)XMALLOC(sizeof *req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19607. if (! req)
  19608. ERROR_OUT(MEMORY_E, exit_rsa);
  19609. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER);
  19610. if (der == NULL) {
  19611. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19612. }
  19613. ret = wc_InitCert_ex(req, HEAP_HINT, devId);
  19614. if (ret != 0)
  19615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19616. req->version = 0;
  19617. req->isCA = 1;
  19618. XSTRNCPY(req->challengePw, "wolf123", CTC_NAME_SIZE);
  19619. XMEMCPY(&req->subject, &certDefaultName, sizeof(CertName));
  19620. #ifndef NO_SHA256
  19621. req->sigType = CTC_SHA256wRSA;
  19622. #else
  19623. req->sigType = CTC_SHAwRSA;
  19624. #endif
  19625. #ifdef WOLFSSL_CERT_EXT
  19626. /* add SKID from the Public Key */
  19627. ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL);
  19628. if (ret != 0)
  19629. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19630. /* add Key Usage */
  19631. ret = wc_SetKeyUsage(req, certKeyUsage2);
  19632. if (ret != 0)
  19633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19634. /* add Extended Key Usage */
  19635. ret = wc_SetExtKeyUsage(req,
  19636. "serverAuth,clientAuth,codeSigning,"
  19637. "emailProtection,timeStamping,OCSPSigning");
  19638. if (ret != 0)
  19639. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19640. #ifdef WOLFSSL_EKU_OID
  19641. {
  19642. WOLFSSL_SMALL_STACK_STATIC const char unique[] =
  19643. "2.16.840.1.111111.100.1.10.1";
  19644. ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0,
  19645. HEAP_HINT);
  19646. if (ret != 0)
  19647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19648. }
  19649. #endif /* WOLFSSL_EKU_OID */
  19650. #endif /* WOLFSSL_CERT_EXT */
  19651. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19652. if (derSz < 0) {
  19653. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19654. }
  19655. #ifdef WOLFSSL_CERT_EXT
  19656. /* Try again with "any" flag set, will override all others */
  19657. ret = wc_SetExtKeyUsage(req, "any");
  19658. if (ret != 0)
  19659. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19660. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19661. if (derSz < 0) {
  19662. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19663. }
  19664. #endif /* WOLFSSL_CERT_EXT */
  19665. ret = 0;
  19666. do {
  19667. #if defined(WOLFSSL_ASYNC_CRYPT)
  19668. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19669. #endif
  19670. if (ret >= 0) {
  19671. ret = wc_SignCert(req->bodySz, req->sigType, der, FOURK_BUF,
  19672. key, NULL, &rng);
  19673. }
  19674. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19675. if (ret < 0)
  19676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19677. derSz = (int)ret;
  19678. ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile,
  19679. CERTREQ_TYPE);
  19680. if (ret != 0) {
  19681. goto exit_rsa;
  19682. }
  19683. derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key);
  19684. if (derSz < 0) {
  19685. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19686. }
  19687. /* Test getting the size of the buffer without providing the buffer.
  19688. * derSz is set to the "largest buffer" we are willing to allocate. */
  19689. derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL);
  19690. if (derSz < 0) {
  19691. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19692. }
  19693. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19694. XFREE(req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19695. der = NULL;
  19696. }
  19697. #endif /* WOLFSSL_CERT_REQ */
  19698. #endif /* WOLFSSL_CERT_GEN */
  19699. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  19700. /* Need to create known good signatures to test with this. */
  19701. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19702. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19703. ret = rsa_pss_test(&rng, key);
  19704. if (ret != 0)
  19705. goto exit_rsa;
  19706. #endif
  19707. #endif
  19708. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  19709. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19710. /* New key to be loaded in rsa_even_mod_test(). */
  19711. if (key != NULL)
  19712. #endif
  19713. wc_FreeRsaKey(key);
  19714. /* New key to be loaded in rsa_even_mod_test(). */
  19715. ret = rsa_even_mod_test(&rng, key);
  19716. #endif
  19717. exit_rsa:
  19718. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19719. wc_DeleteRsaKey(key, &key);
  19720. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19721. wc_DeleteRsaKey(keypub, &keypub);
  19722. #endif
  19723. #ifdef WOLFSSL_TEST_CERT
  19724. XFREE(cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19725. #endif
  19726. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19727. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19728. #else
  19729. wc_FreeRsaKey(key);
  19730. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19731. wc_FreeRsaKey(keypub);
  19732. #endif
  19733. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19734. wc_FreeRng(&rng);
  19735. WC_FREE_VAR(in, HEAP_HINT);
  19736. WC_FREE_VAR(out, HEAP_HINT);
  19737. WC_FREE_VAR(plain, HEAP_HINT);
  19738. (void)res;
  19739. (void)bytes;
  19740. (void)idx;
  19741. (void)in;
  19742. (void)out;
  19743. (void)plain;
  19744. (void)idx;
  19745. (void)inStr;
  19746. (void)inLen;
  19747. (void)outSz;
  19748. (void)plainSz;
  19749. /* ret can be greater then 0 with certgen but all negative values should
  19750. * be returned and treated as an error */
  19751. if (ret >= 0) {
  19752. return 0;
  19753. }
  19754. else {
  19755. return ret;
  19756. }
  19757. }
  19758. #endif /* !NO_RSA */
  19759. #ifndef NO_DH
  19760. static wc_test_ret_t dh_fips_generate_test(WC_RNG *rng)
  19761. {
  19762. wc_test_ret_t ret = 0;
  19763. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19764. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19765. #else
  19766. DhKey key[1];
  19767. #endif
  19768. WOLFSSL_SMALL_STACK_STATIC const byte p[] = {
  19769. 0xc5, 0x7c, 0xa2, 0x4f, 0x4b, 0xd6, 0x8c, 0x3c,
  19770. 0xda, 0xc7, 0xba, 0xaa, 0xea, 0x2e, 0x5c, 0x1e,
  19771. 0x18, 0xb2, 0x7b, 0x8c, 0x55, 0x65, 0x9f, 0xea,
  19772. 0xe0, 0xa1, 0x36, 0x53, 0x2b, 0x36, 0xe0, 0x4e,
  19773. 0x3e, 0x64, 0xa9, 0xe4, 0xfc, 0x8f, 0x32, 0x62,
  19774. 0x97, 0xe4, 0xbe, 0xf7, 0xc1, 0xde, 0x07, 0x5a,
  19775. 0x89, 0x28, 0xf3, 0xfe, 0x4f, 0xfe, 0x68, 0xbc,
  19776. 0xfb, 0x0a, 0x7c, 0xa4, 0xb3, 0x14, 0x48, 0x89,
  19777. 0x9f, 0xaf, 0xb8, 0x43, 0xe2, 0xa0, 0x62, 0x5c,
  19778. 0xb4, 0x88, 0x3f, 0x06, 0x50, 0x11, 0xfe, 0x65,
  19779. 0x8d, 0x49, 0xd2, 0xf5, 0x4b, 0x74, 0x79, 0xdb,
  19780. 0x06, 0x62, 0x92, 0x89, 0xed, 0xda, 0xcb, 0x87,
  19781. 0x37, 0x16, 0xd2, 0xa1, 0x7a, 0xe8, 0xde, 0x92,
  19782. 0xee, 0x3e, 0x41, 0x4a, 0x91, 0x5e, 0xed, 0xf3,
  19783. 0x6c, 0x6b, 0x7e, 0xfd, 0x15, 0x92, 0x18, 0xfc,
  19784. 0xa7, 0xac, 0x42, 0x85, 0x57, 0xe9, 0xdc, 0xda,
  19785. 0x55, 0xc9, 0x8b, 0x28, 0x9e, 0xc1, 0xc4, 0x46,
  19786. 0x4d, 0x88, 0xed, 0x62, 0x8e, 0xdb, 0x3f, 0xb9,
  19787. 0xd7, 0xc8, 0xe3, 0xcf, 0xb8, 0x34, 0x2c, 0xd2,
  19788. 0x6f, 0x28, 0x06, 0x41, 0xe3, 0x66, 0x8c, 0xfc,
  19789. 0x72, 0xff, 0x26, 0x3b, 0x6b, 0x6c, 0x6f, 0x73,
  19790. 0xde, 0xf2, 0x90, 0x29, 0xe0, 0x61, 0x32, 0xc4,
  19791. 0x12, 0x74, 0x09, 0x52, 0xec, 0xf3, 0x1b, 0xa6,
  19792. 0x45, 0x98, 0xac, 0xf9, 0x1c, 0x65, 0x8e, 0x3a,
  19793. 0x91, 0x84, 0x4b, 0x23, 0x8a, 0xb2, 0x3c, 0xc9,
  19794. 0xfa, 0xea, 0xf1, 0x38, 0xce, 0xd8, 0x05, 0xe0,
  19795. 0xfa, 0x44, 0x68, 0x1f, 0xeb, 0xd9, 0x57, 0xb8,
  19796. 0x4a, 0x97, 0x5b, 0x88, 0xc5, 0xf1, 0xbb, 0xb0,
  19797. 0x49, 0xc3, 0x91, 0x7c, 0xd3, 0x13, 0xb9, 0x47,
  19798. 0xbb, 0x91, 0x8f, 0xe5, 0x26, 0x07, 0xab, 0xa9,
  19799. 0xc5, 0xd0, 0x3d, 0x95, 0x41, 0x26, 0x92, 0x9d,
  19800. 0x13, 0x67, 0xf2, 0x7e, 0x11, 0x88, 0xdc, 0x2d
  19801. };
  19802. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  19803. 0x4a, 0x1a, 0xf3, 0xa4, 0x92, 0xe9, 0xee, 0x74,
  19804. 0x6e, 0x57, 0xd5, 0x8c, 0x2c, 0x5b, 0x41, 0x41,
  19805. 0x5e, 0xd4, 0x55, 0x19, 0xdc, 0xd9, 0x32, 0x91,
  19806. 0xf7, 0xfd, 0xc2, 0x57, 0xff, 0x03, 0x14, 0xdb,
  19807. 0xf1, 0xb7, 0x60, 0x0c, 0x43, 0x59, 0x3f, 0xff,
  19808. 0xac, 0xf1, 0x80, 0x9a, 0x15, 0x6f, 0xd8, 0x6e,
  19809. 0xb7, 0x85, 0x18, 0xc8, 0xec, 0x4e, 0x59, 0x4a,
  19810. 0xe2, 0x91, 0x43, 0x4c, 0xeb, 0x95, 0xb6, 0x2e,
  19811. 0x9a, 0xea, 0x53, 0x68, 0x80, 0x64, 0x69, 0x40,
  19812. 0xf9, 0xec, 0xbd, 0x85, 0x89, 0x26, 0x97, 0x67,
  19813. 0xaf, 0xb0, 0xad, 0x00, 0x1b, 0xd4, 0xfd, 0x94,
  19814. 0xd3, 0xe9, 0x92, 0xb1, 0xb4, 0xbc, 0x5a, 0xaa,
  19815. 0x92, 0x80, 0x89, 0x3b, 0x39, 0x05, 0x6c, 0x22,
  19816. 0x26, 0xfe, 0x5a, 0x28, 0x6c, 0x37, 0x50, 0x5a,
  19817. 0x38, 0x99, 0xcf, 0xf3, 0xc1, 0x96, 0x45, 0xdc,
  19818. 0x01, 0xcb, 0x20, 0x87, 0xa5, 0x00, 0x8c, 0xf5,
  19819. 0x4d, 0xc2, 0xef, 0xb8, 0x9b, 0xd1, 0x87, 0xbe,
  19820. 0xed, 0xd5, 0x0a, 0x29, 0x15, 0x34, 0x59, 0x4c,
  19821. 0x3a, 0x05, 0x22, 0x05, 0x44, 0x4f, 0x9f, 0xc8,
  19822. 0x47, 0x12, 0x24, 0x8e, 0xa8, 0x79, 0xe4, 0x67,
  19823. 0xba, 0x4d, 0x5b, 0x75, 0x56, 0x95, 0xeb, 0xe8,
  19824. 0x8a, 0xfa, 0x8e, 0x01, 0x8c, 0x1b, 0x74, 0x63,
  19825. 0xd9, 0x2f, 0xf7, 0xd3, 0x44, 0x8f, 0xa8, 0xf5,
  19826. 0xaf, 0x6c, 0x4f, 0xdb, 0xe7, 0xc9, 0x6c, 0x71,
  19827. 0x22, 0xa3, 0x1d, 0xf1, 0x40, 0xb2, 0xe0, 0x9a,
  19828. 0xb6, 0x72, 0xc9, 0xc0, 0x13, 0x16, 0xa2, 0x4a,
  19829. 0xe1, 0x92, 0xc7, 0x54, 0x23, 0xab, 0x9d, 0xa1,
  19830. 0xa1, 0xe5, 0x0b, 0xed, 0xba, 0xe8, 0x84, 0x37,
  19831. 0xb2, 0xe7, 0xfe, 0x32, 0x8d, 0xfa, 0x1c, 0x53,
  19832. 0x77, 0x97, 0xc7, 0xf3, 0x48, 0xc9, 0xdb, 0x2d,
  19833. 0x75, 0x52, 0x9d, 0x42, 0x51, 0x78, 0x62, 0x68,
  19834. 0x05, 0x45, 0x15, 0xf8, 0xa2, 0x4e, 0xf3, 0x0b
  19835. };
  19836. WOLFSSL_SMALL_STACK_STATIC const byte q[] = {
  19837. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19838. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19839. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19840. 0x40, 0x52, 0xed, 0x41
  19841. };
  19842. WOLFSSL_SMALL_STACK_STATIC const byte q0[] = {
  19843. 0x00,
  19844. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19845. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19846. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19847. 0x40, 0x52, 0xed, 0x41
  19848. };
  19849. byte priv[256];
  19850. byte pub[256];
  19851. word32 privSz = sizeof(priv);
  19852. word32 pubSz = sizeof(pub);
  19853. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19854. if (key == NULL)
  19855. ERROR_OUT(MEMORY_E, exit_gen_test);
  19856. #endif
  19857. /* Parameter Validation testing. */
  19858. ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz);
  19859. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19861. ret = wc_DhGenerateKeyPair(key, NULL, priv, &privSz, pub, &pubSz);
  19862. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19863. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19864. ret = wc_DhGenerateKeyPair(key, rng, NULL, &privSz, pub, &pubSz);
  19865. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19867. ret = wc_DhGenerateKeyPair(key, rng, priv, NULL, pub, &pubSz);
  19868. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19870. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, NULL, &pubSz);
  19871. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19872. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19873. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, NULL);
  19874. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19875. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19876. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19877. if (ret != 0)
  19878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19879. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0));
  19880. if (ret != 0)
  19881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19882. wc_FreeDhKey(key);
  19883. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19884. if (ret != 0)
  19885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19886. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q));
  19887. if (ret != 0)
  19888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19889. /* Use API. */
  19890. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19891. #if defined(WOLFSSL_ASYNC_CRYPT)
  19892. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19893. #endif
  19894. if (ret != 0)
  19895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19896. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0));
  19897. if (ret != 0)
  19898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19899. wc_FreeDhKey(key);
  19900. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19901. if (ret != 0)
  19902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19903. ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
  19904. if (ret != 0)
  19905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19906. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q));
  19907. if (ret != 0)
  19908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19909. #ifndef HAVE_SELFTEST
  19910. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19911. if (ret != 0)
  19912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19913. /* Taint the public key so the check fails. */
  19914. pub[0]++;
  19915. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19916. if (ret != WC_NO_ERR_TRACE(MP_CMP_E)) {
  19917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19918. }
  19919. #ifdef WOLFSSL_KEY_GEN
  19920. wc_FreeDhKey(key);
  19921. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19922. if (ret != 0)
  19923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19924. ret = wc_DhGenerateParams(rng, 2048, key);
  19925. if (ret != 0)
  19926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19927. privSz = sizeof(priv);
  19928. pubSz = sizeof(pub);
  19929. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19930. #if defined(WOLFSSL_ASYNC_CRYPT)
  19931. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19932. #endif
  19933. if (ret != 0)
  19934. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19935. #endif /* WOLFSSL_KEY_GEN */
  19936. #endif /* HAVE_SELFTEST */
  19937. ret = 0;
  19938. exit_gen_test:
  19939. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19940. if (key) {
  19941. wc_FreeDhKey(key);
  19942. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19943. }
  19944. #else
  19945. wc_FreeDhKey(key);
  19946. #endif
  19947. return ret;
  19948. }
  19949. static wc_test_ret_t dh_generate_test(WC_RNG *rng)
  19950. {
  19951. wc_test_ret_t ret = 0;
  19952. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19953. DhKey *smallKey = NULL;
  19954. #else
  19955. DhKey smallKey[1];
  19956. #endif
  19957. byte p[2] = { 1, 7 }; /* 263 in decimal */
  19958. byte g[2] = { 0, 2 };
  19959. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19960. #ifdef WOLFSSL_DH_CONST
  19961. /* the table for constant DH lookup will round to the lowest byte size 21 */
  19962. byte priv[21];
  19963. byte pub[21];
  19964. #else
  19965. byte priv[2];
  19966. byte pub[2];
  19967. #endif
  19968. word32 privSz = sizeof(priv);
  19969. word32 pubSz = sizeof(pub);
  19970. #endif
  19971. int smallKey_inited = 0;
  19972. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19973. if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  19974. return WC_TEST_RET_ENC_ERRNO;
  19975. #endif
  19976. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19977. if (ret != 0)
  19978. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19979. smallKey_inited = 1;
  19980. /* Parameter Validation testing. */
  19981. ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId);
  19982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19983. return WC_TEST_RET_ENC_EC(ret);
  19984. wc_FreeDhKey(NULL);
  19985. ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g));
  19986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19987. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19988. }
  19989. ret = wc_DhSetKey(smallKey, NULL, sizeof(p), g, sizeof(g));
  19990. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19991. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19992. }
  19993. ret = wc_DhSetKey(smallKey, p, 0, g, sizeof(g));
  19994. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19996. }
  19997. ret = wc_DhSetKey(smallKey, p, sizeof(p), NULL, sizeof(g));
  19998. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19999. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20000. }
  20001. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, 0);
  20002. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20003. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20004. }
  20005. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, sizeof(g));
  20006. if (ret != 0)
  20007. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20008. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  20009. /* Use API. */
  20010. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20011. #if defined(WOLFSSL_ASYNC_CRYPT)
  20012. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20013. #endif
  20014. if (ret != 0) {
  20015. ret = WC_TEST_RET_ENC_EC(ret);
  20016. }
  20017. #else
  20018. (void)rng;
  20019. #if defined(HAVE_FIPS) || !defined(WOLFSSL_NO_DH186)
  20020. ret = 0;
  20021. #endif
  20022. #endif
  20023. #if !defined(HAVE_FIPS) && defined(WOLFSSL_NO_DH186)
  20024. {
  20025. byte priv[260];
  20026. byte pub[260];
  20027. word32 privSz = sizeof(priv);
  20028. word32 pubSz = sizeof(pub);
  20029. /* test odd ball param generation with DH */
  20030. wc_FreeDhKey(smallKey);
  20031. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  20032. if (ret != 0)
  20033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20034. /* should fail since modSz is 16 and group size is 20 */
  20035. ret = wc_DhGenerateParams(rng, 128, smallKey);
  20036. if (ret == 0)
  20037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20038. ret = wc_DhGenerateParams(rng, 2056, smallKey);
  20039. if (ret != 0)
  20040. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20041. privSz = sizeof(priv);
  20042. pubSz = sizeof(pub);
  20043. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20044. #if defined(WOLFSSL_ASYNC_CRYPT)
  20045. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20046. #endif
  20047. if (ret != 0)
  20048. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20049. }
  20050. #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */
  20051. exit_gen_test:
  20052. if (smallKey_inited)
  20053. wc_FreeDhKey(smallKey);
  20054. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20055. XFREE(smallKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20056. #endif
  20057. return ret;
  20058. }
  20059. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20060. typedef struct dh_pubvalue_test {
  20061. const byte* data;
  20062. word32 len;
  20063. } dh_pubvalue_test;
  20064. static wc_test_ret_t dh_test_check_pubvalue(void)
  20065. {
  20066. wc_test_ret_t ret;
  20067. word32 i;
  20068. WOLFSSL_SMALL_STACK_STATIC const byte prime[] = {0x01, 0x00, 0x01};
  20069. WOLFSSL_SMALL_STACK_STATIC const byte pubValZero[] = { 0x00 };
  20070. WOLFSSL_SMALL_STACK_STATIC const byte pubValZeroLong[] = { 0x00, 0x00, 0x00 };
  20071. WOLFSSL_SMALL_STACK_STATIC const byte pubValOne[] = { 0x01 };
  20072. WOLFSSL_SMALL_STACK_STATIC const byte pubValOneLong[] = { 0x00, 0x00, 0x01 };
  20073. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeMinusOne[] = { 0x01, 0x00, 0x00 };
  20074. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeLong[] = {0x00, 0x01, 0x00, 0x01};
  20075. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimePlusOne[] = { 0x01, 0x00, 0x02 };
  20076. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig0[] = { 0x02, 0x00, 0x01 };
  20077. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig1[] = { 0x01, 0x01, 0x01 };
  20078. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooLong[] = { 0x01, 0x00, 0x00, 0x01 };
  20079. const dh_pubvalue_test dh_pubval_fail[] = {
  20080. { prime, sizeof(prime) },
  20081. { pubValZero, sizeof(pubValZero) },
  20082. { pubValZeroLong, sizeof(pubValZeroLong) },
  20083. { pubValOne, sizeof(pubValOne) },
  20084. { pubValOneLong, sizeof(pubValOneLong) },
  20085. { pubValPrimeMinusOne, sizeof(pubValPrimeMinusOne) },
  20086. { pubValPrimeLong, sizeof(pubValPrimeLong) },
  20087. { pubValPrimePlusOne, sizeof(pubValPrimePlusOne) },
  20088. { pubValTooBig0, sizeof(pubValTooBig0) },
  20089. { pubValTooBig1, sizeof(pubValTooBig1) },
  20090. { pubValTooLong, sizeof(pubValTooLong) },
  20091. };
  20092. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwo[] = { 0x02 };
  20093. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwoLong[] = { 0x00, 0x00, 0x02 };
  20094. WOLFSSL_SMALL_STACK_STATIC const byte pubValGood[] = { 0x12, 0x34 };
  20095. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLen[] = { 0x00, 0x12, 0x34 };
  20096. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLong[] = { 0x00, 0x00, 0x12, 0x34 };
  20097. const dh_pubvalue_test dh_pubval_pass[] = {
  20098. { pubValTwo, sizeof(pubValTwo) },
  20099. { pubValTwoLong, sizeof(pubValTwoLong) },
  20100. { pubValGood, sizeof(pubValGood) },
  20101. { pubValGoodLen, sizeof(pubValGoodLen) },
  20102. { pubValGoodLong, sizeof(pubValGoodLong) },
  20103. };
  20104. for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) {
  20105. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data,
  20106. dh_pubval_fail[i].len);
  20107. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  20108. return WC_TEST_RET_ENC_I(i);
  20109. }
  20110. for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) {
  20111. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data,
  20112. dh_pubval_pass[i].len);
  20113. if (ret != 0)
  20114. return WC_TEST_RET_ENC_I(i);
  20115. }
  20116. return 0;
  20117. }
  20118. #endif
  20119. #if defined(HAVE_FFDHE)
  20120. #if defined(HAVE_FFDHE_4096)
  20121. #define MAX_DH_PRIV_SZ 39
  20122. #define MAX_DH_KEY_SZ 512
  20123. #elif defined(HAVE_FFDHE_3072)
  20124. #define MAX_DH_PRIV_SZ 34
  20125. #define MAX_DH_KEY_SZ 384
  20126. #else
  20127. #define MAX_DH_PRIV_SZ 29
  20128. #define MAX_DH_KEY_SZ 256
  20129. #endif
  20130. #ifndef WC_NO_RNG
  20131. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20132. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20133. #ifdef HAVE_PUBLIC_FFDHE
  20134. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
  20135. #else
  20136. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, int name)
  20137. #endif
  20138. {
  20139. wc_test_ret_t ret;
  20140. word32 privSz, pubSz, privSz2, pubSz2;
  20141. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20142. byte *priv = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20143. byte *pub = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20144. byte *priv2 = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20145. byte *pub2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20146. byte *agree = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20147. byte *agree2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20148. DhKey *key = (DhKey*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20149. DhKey *key2 = (DhKey*)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20150. #else
  20151. byte priv[MAX_DH_PRIV_SZ];
  20152. byte pub[MAX_DH_KEY_SZ];
  20153. byte priv2[MAX_DH_PRIV_SZ];
  20154. byte pub2[MAX_DH_KEY_SZ];
  20155. byte agree[MAX_DH_KEY_SZ];
  20156. byte agree2[MAX_DH_KEY_SZ];
  20157. DhKey key[1];
  20158. DhKey key2[1];
  20159. #endif
  20160. word32 agreeSz = MAX_DH_KEY_SZ;
  20161. word32 agreeSz2 = MAX_DH_KEY_SZ;
  20162. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20163. if ((priv == NULL) ||
  20164. (pub == NULL) ||
  20165. (priv2 == NULL) ||
  20166. (pub2 == NULL) ||
  20167. (agree == NULL) ||
  20168. (agree2 == NULL) ||
  20169. (key == NULL) ||
  20170. (key2 == NULL))
  20171. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20172. #endif
  20173. pubSz = MAX_DH_KEY_SZ;
  20174. pubSz2 = MAX_DH_KEY_SZ;
  20175. #ifdef HAVE_PUBLIC_FFDHE
  20176. privSz = MAX_DH_PRIV_SZ;
  20177. privSz2 = MAX_DH_PRIV_SZ;
  20178. #else
  20179. privSz = wc_DhGetNamedKeyMinSize(name);
  20180. privSz2 = privSz;
  20181. #endif
  20182. XMEMSET(key, 0, sizeof(*key));
  20183. XMEMSET(key2, 0, sizeof(*key2));
  20184. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20185. if (ret != 0)
  20186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20187. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20188. if (ret != 0)
  20189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20190. #ifdef HAVE_PUBLIC_FFDHE
  20191. ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len);
  20192. #else
  20193. ret = wc_DhSetNamedKey(key, name);
  20194. #endif
  20195. if (ret != 0)
  20196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20197. #ifdef HAVE_PUBLIC_FFDHE
  20198. ret = wc_DhSetKey(key2, params->p, params->p_len, params->g,
  20199. params->g_len);
  20200. #else
  20201. ret = wc_DhSetNamedKey(key2, name);
  20202. #endif
  20203. if (ret != 0)
  20204. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20205. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20206. #if defined(WOLFSSL_ASYNC_CRYPT)
  20207. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20208. #endif
  20209. if (ret != 0)
  20210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20211. ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2);
  20212. #if defined(WOLFSSL_ASYNC_CRYPT)
  20213. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20214. #endif
  20215. if (ret != 0)
  20216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20217. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20218. #if defined(WOLFSSL_ASYNC_CRYPT)
  20219. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20220. #endif
  20221. if (ret != 0)
  20222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20223. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20224. #if defined(WOLFSSL_ASYNC_CRYPT)
  20225. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20226. #endif
  20227. if (ret != 0)
  20228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20229. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20230. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20231. }
  20232. #if (defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH)) && \
  20233. !defined(HAVE_INTEL_QA)
  20234. /* Make p even */
  20235. key->p.dp[0] &= (mp_digit)-2;
  20236. if (ret != 0)
  20237. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20238. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20239. #if defined(WOLFSSL_ASYNC_CRYPT)
  20240. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20241. #endif
  20242. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20243. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  20244. {
  20245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20246. }
  20247. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20248. #if defined(WOLFSSL_ASYNC_CRYPT)
  20249. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20250. #endif
  20251. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20252. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20253. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20254. {
  20255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20256. }
  20257. #ifndef HAVE_SELFTEST
  20258. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  20259. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20260. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20261. ret != WC_NO_ERR_TRACE(MP_CMP_E) &&
  20262. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20263. {
  20264. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20265. }
  20266. #endif
  20267. /* Getting here means success - set ret to 0. */
  20268. ret = 0;
  20269. #endif /* (SP DH or Fast Math) and not Intel QuickAssist */
  20270. done:
  20271. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) && \
  20272. !defined(WC_NO_RNG)
  20273. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20274. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20275. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20276. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20277. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20278. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20279. if (key) {
  20280. wc_FreeDhKey(key);
  20281. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20282. }
  20283. if (key2) {
  20284. wc_FreeDhKey(key2);
  20285. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20286. }
  20287. #else
  20288. wc_FreeDhKey(key);
  20289. wc_FreeDhKey(key2);
  20290. #endif
  20291. return ret;
  20292. }
  20293. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  20294. #endif /* !WC_NO_RNG */
  20295. #endif /* HAVE_FFDHE */
  20296. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void)
  20297. {
  20298. wc_test_ret_t ret;
  20299. word32 bytes;
  20300. word32 idx = 0;
  20301. word32 privSz = 0;
  20302. word32 pubSz = 0;
  20303. word32 privSz2 = 0;
  20304. word32 pubSz2 = 0;
  20305. #ifndef WC_NO_RNG
  20306. WC_RNG rng;
  20307. int rngInit = 0;
  20308. #endif
  20309. int keyInit = 0, key2Init = 0;
  20310. #define DH_TEST_TMP_SIZE 1024
  20311. #if !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  20312. #define DH_TEST_BUF_SIZE 256
  20313. #else
  20314. #define DH_TEST_BUF_SIZE 512
  20315. #endif
  20316. #ifndef WC_NO_RNG
  20317. word32 agreeSz = DH_TEST_BUF_SIZE;
  20318. word32 agreeSz2 = DH_TEST_BUF_SIZE;
  20319. #endif
  20320. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20321. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20322. DhKey *key2 = (DhKey *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20323. byte *tmp = (byte *)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20324. #else
  20325. DhKey key[1];
  20326. DhKey key2[1];
  20327. byte tmp[DH_TEST_TMP_SIZE];
  20328. #endif
  20329. #ifndef WC_NO_RNG
  20330. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20331. byte *priv = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20332. byte *pub = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20333. byte *priv2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20334. byte *pub2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20335. byte *agree = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20336. byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20337. if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL ||
  20338. agree == NULL || agree2 == NULL) {
  20339. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20340. }
  20341. #else
  20342. byte priv[DH_TEST_BUF_SIZE];
  20343. byte pub[DH_TEST_BUF_SIZE];
  20344. byte priv2[DH_TEST_BUF_SIZE];
  20345. byte pub2[DH_TEST_BUF_SIZE];
  20346. byte agree[DH_TEST_BUF_SIZE];
  20347. byte agree2[DH_TEST_BUF_SIZE];
  20348. #endif
  20349. #endif /* !WC_NO_RNG */
  20350. WOLFSSL_ENTER("dh_test");
  20351. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20352. if (key == NULL || key2 == NULL || tmp == NULL) {
  20353. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20354. }
  20355. #endif
  20356. #ifdef USE_CERT_BUFFERS_1024
  20357. XMEMCPY(tmp, dh_key_der_1024, (size_t)sizeof_dh_key_der_1024);
  20358. bytes = (size_t)sizeof_dh_key_der_1024;
  20359. #elif defined(USE_CERT_BUFFERS_2048)
  20360. XMEMCPY(tmp, dh_key_der_2048, (size_t)sizeof_dh_key_der_2048);
  20361. bytes = (size_t)sizeof_dh_key_der_2048;
  20362. #elif defined(USE_CERT_BUFFERS_3072)
  20363. XMEMCPY(tmp, dh_key_der_3072, (size_t)sizeof_dh_key_der_3072);
  20364. bytes = (size_t)sizeof_dh_key_der_3072;
  20365. #elif defined(USE_CERT_BUFFERS_4096)
  20366. XMEMCPY(tmp, dh_key_der_4096, (size_t)sizeof_dh_key_der_4096);
  20367. bytes = (size_t)sizeof_dh_key_der_4096;
  20368. #elif defined(NO_ASN)
  20369. /* don't use file, no DER parsing */
  20370. #elif !defined(NO_FILESYSTEM)
  20371. {
  20372. XFILE file = XFOPEN(dhParamsFile, "rb");
  20373. if (! file)
  20374. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20375. bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20376. XFCLOSE(file);
  20377. if (bytes == 0)
  20378. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20379. }
  20380. #else
  20381. /* No DH key to use. */
  20382. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20383. #endif /* USE_CERT_BUFFERS */
  20384. (void)idx;
  20385. (void)tmp;
  20386. (void)bytes;
  20387. pubSz = DH_TEST_BUF_SIZE;
  20388. pubSz2 = DH_TEST_BUF_SIZE;
  20389. privSz = DH_TEST_BUF_SIZE;
  20390. privSz2 = DH_TEST_BUF_SIZE;
  20391. #ifndef WC_NO_RNG
  20392. XMEMSET(&rng, 0, sizeof(rng));
  20393. #endif
  20394. /* Use API for coverage. */
  20395. ret = wc_InitDhKey(key);
  20396. if (ret != 0)
  20397. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20398. wc_FreeDhKey(key);
  20399. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20400. if (ret != 0)
  20401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20402. keyInit = 1;
  20403. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20404. if (ret != 0)
  20405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20406. key2Init = 1;
  20407. #ifdef NO_ASN
  20408. #ifndef WOLFSSL_SP_MATH
  20409. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20410. if (ret != 0)
  20411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20412. ret = wc_DhSetKey(key2, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20413. if (ret != 0)
  20414. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20415. #else
  20416. ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20417. sizeof(dh2048_g));
  20418. if (ret != 0)
  20419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20420. ret = wc_DhSetKey(key2, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20421. sizeof(dh2048_g));
  20422. if (ret != 0)
  20423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20424. #endif
  20425. #else
  20426. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20427. if (ret != 0)
  20428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20429. idx = 0;
  20430. ret = wc_DhKeyDecode(tmp, &idx, key2, bytes);
  20431. if (ret != 0)
  20432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20433. #endif
  20434. #ifndef WC_NO_RNG
  20435. #ifndef HAVE_FIPS
  20436. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20437. #else
  20438. ret = wc_InitRng(&rng);
  20439. #endif
  20440. if (ret != 0)
  20441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20442. rngInit = 1;
  20443. ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz);
  20444. #if defined(WOLFSSL_ASYNC_CRYPT)
  20445. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20446. #endif
  20447. if (ret != 0)
  20448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20449. ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2);
  20450. #if defined(WOLFSSL_ASYNC_CRYPT)
  20451. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20452. #endif
  20453. if (ret != 0)
  20454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20455. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20456. #if defined(WOLFSSL_ASYNC_CRYPT)
  20457. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20458. #endif
  20459. if (ret != 0)
  20460. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20461. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20462. #if defined(WOLFSSL_ASYNC_CRYPT)
  20463. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20464. #endif
  20465. if (ret != 0)
  20466. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20467. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20468. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20469. }
  20470. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) && \
  20471. !defined(HAVE_SELFTEST)
  20472. agreeSz = DH_TEST_BUF_SIZE;
  20473. agreeSz2 = DH_TEST_BUF_SIZE;
  20474. ret = wc_DhAgree_ct(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20475. if (ret != 0)
  20476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20477. ret = wc_DhAgree_ct(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20478. if (ret != 0)
  20479. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20480. #ifdef WOLFSSL_PUBLIC_MP
  20481. if (agreeSz != (word32)mp_unsigned_bin_size(&key->p))
  20482. {
  20483. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20484. }
  20485. #endif
  20486. if (agreeSz != agreeSz2)
  20487. {
  20488. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20489. }
  20490. if (XMEMCMP(agree, agree2, agreeSz) != 0)
  20491. {
  20492. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20493. }
  20494. #endif /* (!HAVE_FIPS || FIPS_VERSION_GE(7,0)) && !HAVE_SELFTEST */
  20495. #endif /* !WC_NO_RNG */
  20496. #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20497. ret = wc_DhCheckPrivKey(NULL, NULL, 0);
  20498. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20500. ret = wc_DhCheckPrivKey(key, priv, privSz);
  20501. if (ret != 0)
  20502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20503. ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  20504. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20506. {
  20507. word32 pSz, qSz, gSz;
  20508. ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz);
  20509. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  20510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20511. }
  20512. #endif
  20513. /* Test DH key import / export */
  20514. #if defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM) && \
  20515. (!defined(HAVE_FIPS) || \
  20516. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  20517. wc_FreeDhKey(key);
  20518. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20519. if (ret != 0)
  20520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20521. #ifndef NO_ASN
  20522. {
  20523. /* DH Private - Key Export / Import */
  20524. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20525. byte *tmp2;
  20526. #else
  20527. byte tmp2[DH_TEST_TMP_SIZE];
  20528. #endif
  20529. #if defined(USE_CERT_BUFFERS_2048)
  20530. XMEMCPY(tmp, dh_ffdhe_statickey_der_2048, sizeof_dh_ffdhe_statickey_der_2048);
  20531. bytes = sizeof_dh_ffdhe_statickey_der_2048;
  20532. #else
  20533. XFILE file = XFOPEN(dhKeyFile, "rb");
  20534. if (!file)
  20535. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20536. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20537. XFCLOSE(file);
  20538. if (bytes == 0)
  20539. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20540. #endif
  20541. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20542. tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20543. if (tmp2 == NULL)
  20544. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20545. #endif
  20546. idx = 0;
  20547. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20548. /* Import DH Private key as DER */
  20549. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20550. if (ret == 0) {
  20551. /* Export as DER */
  20552. idx = DH_TEST_TMP_SIZE;
  20553. ret = wc_DhPrivKeyToDer(key, tmp2, &idx);
  20554. }
  20555. /* Verify export matches original */
  20556. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20557. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20558. }
  20559. /* DH Public Key - Export / Import */
  20560. #if defined(USE_CERT_BUFFERS_2048)
  20561. XMEMCPY(tmp, dh_ffdhe_pub_statickey_der_2048, sizeof_dh_ffdhe_pub_statickey_der_2048);
  20562. bytes = sizeof_dh_ffdhe_pub_statickey_der_2048;
  20563. #else
  20564. file = XFOPEN(dhKeyPubFile, "rb");
  20565. if (!file)
  20566. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20567. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20568. XFCLOSE(file);
  20569. if (bytes == 0)
  20570. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20571. #endif
  20572. /* for HAVE_WOLF_BIGINT prevent leak */
  20573. wc_FreeDhKey(key);
  20574. (void)wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20575. idx = 0;
  20576. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20577. /* Import DH Public key as DER */
  20578. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20579. if (ret == 0) {
  20580. /* Export as DER */
  20581. idx = DH_TEST_TMP_SIZE;
  20582. ret = wc_DhPubKeyToDer(key, tmp2, &idx);
  20583. }
  20584. /* Verify export matches original */
  20585. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20586. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20587. }
  20588. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20589. XFREE(tmp2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20590. #endif
  20591. }
  20592. #else
  20593. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20594. if (ret != 0)
  20595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20596. #endif /* !NO_ASN */
  20597. privSz = DH_TEST_BUF_SIZE;
  20598. pubSz = DH_TEST_BUF_SIZE;
  20599. ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz);
  20600. if (ret != 0)
  20601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20602. ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz);
  20603. if (ret != 0)
  20604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20605. #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */
  20606. #ifndef WC_NO_RNG
  20607. ret = dh_generate_test(&rng);
  20608. if (ret != 0)
  20609. ERROR_OUT(ret, done);
  20610. ret = dh_fips_generate_test(&rng);
  20611. if (ret != 0)
  20612. ERROR_OUT(ret, done);
  20613. #endif /* !WC_NO_RNG */
  20614. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20615. ret = dh_test_check_pubvalue();
  20616. if (ret != 0)
  20617. ERROR_OUT(ret, done);
  20618. #endif
  20619. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20620. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20621. /* RNG with DH and SP_ASM code not supported in the in-lined FIPS ASM code,
  20622. * this will be available for testing in the 140-3 module */
  20623. #ifndef WC_NO_RNG
  20624. /* Specialized code for key gen when using FFDHE-2048, FFDHE-3072 and FFDHE-4096 */
  20625. #ifdef HAVE_FFDHE_2048
  20626. #ifdef HAVE_PUBLIC_FFDHE
  20627. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe2048_Get());
  20628. #else
  20629. ret = dh_ffdhe_test(&rng, WC_FFDHE_2048);
  20630. #endif
  20631. if (ret != 0)
  20632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20633. #endif
  20634. #ifdef HAVE_FFDHE_3072
  20635. #ifdef HAVE_PUBLIC_FFDHE
  20636. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe3072_Get());
  20637. #else
  20638. ret = dh_ffdhe_test(&rng, WC_FFDHE_3072);
  20639. #endif
  20640. if (ret != 0)
  20641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20642. #endif
  20643. #ifdef HAVE_FFDHE_4096
  20644. #ifdef HAVE_PUBLIC_FFDHE
  20645. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe4096_Get());
  20646. #else
  20647. ret = dh_ffdhe_test(&rng, WC_FFDHE_4096);
  20648. #endif
  20649. if (ret != 0)
  20650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20651. #endif
  20652. #endif /* !WC_NO_RNG */
  20653. #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */
  20654. wc_FreeDhKey(key);
  20655. keyInit = 0;
  20656. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  20657. !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(WC_NO_RNG)
  20658. /* Test Check Key */
  20659. ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g),
  20660. NULL, 0, 0, &rng);
  20661. if (ret != 0)
  20662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20663. keyInit = 1; /* DhSetCheckKey also initializes the key, free it */
  20664. #endif
  20665. done:
  20666. #ifndef WC_NO_RNG
  20667. if (rngInit)
  20668. wc_FreeRng(&rng);
  20669. #endif
  20670. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20671. if (key) {
  20672. if (keyInit)
  20673. wc_FreeDhKey(key);
  20674. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20675. }
  20676. if (key2) {
  20677. if (key2Init)
  20678. wc_FreeDhKey(key2);
  20679. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20680. }
  20681. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20682. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20683. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20684. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20685. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20686. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20687. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20688. #else
  20689. if (keyInit)
  20690. wc_FreeDhKey(key);
  20691. if (key2Init)
  20692. wc_FreeDhKey(key2);
  20693. #endif
  20694. (void)privSz;
  20695. (void)pubSz;
  20696. (void)pubSz2;
  20697. (void)privSz2;
  20698. return ret;
  20699. #undef DH_TEST_BUF_SIZE
  20700. #undef DH_TEST_TMP_SIZE
  20701. }
  20702. #endif /* NO_DH */
  20703. #ifndef NO_DSA
  20704. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
  20705. {
  20706. wc_test_ret_t ret = 0;
  20707. int answer;
  20708. word32 bytes;
  20709. word32 idx = 0;
  20710. WC_RNG rng;
  20711. int rng_inited = 0;
  20712. wc_Sha sha;
  20713. byte hash[WC_SHA_DIGEST_SIZE];
  20714. byte signature[40];
  20715. int key_inited = 0;
  20716. #ifdef WOLFSSL_KEY_GEN
  20717. byte* der = 0;
  20718. int derIn_inited = 0;
  20719. int genKey_inited = 0;
  20720. #endif
  20721. #define DSA_TEST_TMP_SIZE 1024
  20722. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20723. byte *tmp = (byte *)XMALLOC(DSA_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20724. DsaKey *key = (DsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20725. #ifdef WOLFSSL_KEY_GEN
  20726. DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20727. DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20728. #endif
  20729. WOLFSSL_ENTER("dsa_test");
  20730. if ((tmp == NULL) ||
  20731. (key == NULL)
  20732. #ifdef WOLFSSL_KEY_GEN
  20733. || (derIn == NULL)
  20734. || (genKey == NULL)
  20735. #endif
  20736. ) {
  20737. ret = WC_TEST_RET_ENC_NC;
  20738. goto out;
  20739. }
  20740. #else
  20741. byte tmp[1024];
  20742. DsaKey key[1];
  20743. #ifdef WOLFSSL_KEY_GEN
  20744. DsaKey derIn[1];
  20745. DsaKey genKey[1];
  20746. #endif
  20747. #endif
  20748. #ifdef USE_CERT_BUFFERS_1024
  20749. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20750. bytes = sizeof_dsa_key_der_1024;
  20751. #elif defined(USE_CERT_BUFFERS_2048)
  20752. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20753. bytes = sizeof_dsa_key_der_2048;
  20754. #else
  20755. {
  20756. XFILE file = XFOPEN(dsaKey, "rb");
  20757. if (!file)
  20758. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20759. bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file);
  20760. XFCLOSE(file);
  20761. if (bytes == 0)
  20762. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20763. }
  20764. #endif /* USE_CERT_BUFFERS */
  20765. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  20766. if (ret != 0)
  20767. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20768. wc_ShaUpdate(&sha, tmp, bytes);
  20769. wc_ShaFinal(&sha, hash);
  20770. wc_ShaFree(&sha);
  20771. ret = wc_InitDsaKey(key);
  20772. if (ret != 0)
  20773. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20774. key_inited = 1;
  20775. ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes);
  20776. if (ret != 0)
  20777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20778. #ifndef HAVE_FIPS
  20779. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20780. #else
  20781. ret = wc_InitRng(&rng);
  20782. #endif
  20783. if (ret != 0)
  20784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20785. rng_inited = 1;
  20786. ret = wc_DsaSign(hash, signature, key, &rng);
  20787. if (ret != 0)
  20788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20789. ret = wc_DsaVerify(hash, signature, key, &answer);
  20790. if (ret != 0)
  20791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20792. if (answer != 1)
  20793. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20794. wc_FreeDsaKey(key);
  20795. key_inited = 0;
  20796. ret = wc_InitDsaKey_h(key, NULL);
  20797. if (ret != 0)
  20798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20799. key_inited = 1;
  20800. #ifdef WOLFSSL_KEY_GEN
  20801. {
  20802. int derSz = 0;
  20803. ret = wc_InitDsaKey(genKey);
  20804. if (ret != 0)
  20805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20806. genKey_inited = 1;
  20807. ret = wc_MakeDsaParameters(&rng, 1024, genKey);
  20808. if (ret != 0)
  20809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20810. ret = wc_MakeDsaKey(&rng, genKey);
  20811. if (ret != 0)
  20812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20813. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20814. if (der == NULL)
  20815. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20816. derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF);
  20817. if (derSz < 0)
  20818. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out);
  20819. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  20820. DSA_PRIVATEKEY_TYPE);
  20821. if (ret != 0)
  20822. goto out;
  20823. ret = wc_InitDsaKey(derIn);
  20824. if (ret != 0)
  20825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20826. derIn_inited = 1;
  20827. idx = 0;
  20828. ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, (word32)derSz);
  20829. if (ret != 0)
  20830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20831. }
  20832. #endif /* WOLFSSL_KEY_GEN */
  20833. out:
  20834. #ifdef WOLFSSL_KEY_GEN
  20835. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20836. #endif
  20837. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20838. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20839. if (key) {
  20840. if (key_inited)
  20841. wc_FreeDsaKey(key);
  20842. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20843. }
  20844. #ifdef WOLFSSL_KEY_GEN
  20845. if (derIn) {
  20846. if (derIn_inited)
  20847. wc_FreeDsaKey(derIn);
  20848. XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20849. }
  20850. if (genKey) {
  20851. if (genKey_inited)
  20852. wc_FreeDsaKey(genKey);
  20853. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20854. }
  20855. #endif
  20856. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  20857. if (key_inited)
  20858. wc_FreeDsaKey(key);
  20859. #ifdef WOLFSSL_KEY_GEN
  20860. if (derIn_inited)
  20861. wc_FreeDsaKey(derIn);
  20862. if (genKey_inited)
  20863. wc_FreeDsaKey(genKey);
  20864. #endif
  20865. #endif
  20866. if (rng_inited)
  20867. wc_FreeRng(&rng);
  20868. return ret;
  20869. }
  20870. #endif /* NO_DSA */
  20871. #ifdef WOLFCRYPT_HAVE_SRP
  20872. static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
  20873. {
  20874. wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
  20875. WC_RNG rng;
  20876. if(NULL == buf || !size)
  20877. return WC_TEST_RET_ENC_NC;
  20878. if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) {
  20879. ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size);
  20880. wc_FreeRng(&rng);
  20881. }
  20882. return ret;
  20883. }
  20884. static wc_test_ret_t srp_test_digest(SrpType dgstType)
  20885. {
  20886. wc_test_ret_t r;
  20887. byte clientPubKey[192]; /* A */
  20888. byte serverPubKey[192]; /* B */
  20889. word32 clientPubKeySz = 192;
  20890. word32 serverPubKeySz = 192;
  20891. byte username[] = "user";
  20892. word32 usernameSz = 4;
  20893. byte password[] = "password";
  20894. word32 passwordSz = 8;
  20895. WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
  20896. 0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
  20897. 0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
  20898. 0x7a, 0xe9, 0x1f, 0x85, 0x36, 0x18, 0xc4, 0x35,
  20899. 0x3f, 0xf8, 0x8a, 0x8f, 0x8c, 0x10, 0x2e, 0x01,
  20900. 0x58, 0x1d, 0x41, 0xcb, 0xc4, 0x47, 0xa8, 0xaf,
  20901. 0x9a, 0x6f, 0x58, 0x14, 0xa4, 0x68, 0xf0, 0x9c,
  20902. 0xa6, 0xe7, 0xbf, 0x0d, 0xe9, 0x62, 0x0b, 0xd7,
  20903. 0x26, 0x46, 0x5b, 0x27, 0xcb, 0x4c, 0xf9, 0x7e,
  20904. 0x1e, 0x8b, 0xe6, 0xdd, 0x29, 0xb7, 0xb7, 0x15,
  20905. 0x2e, 0xcf, 0x23, 0xa6, 0x4b, 0x97, 0x9f, 0x89,
  20906. 0xd4, 0x86, 0xc4, 0x90, 0x63, 0x92, 0xf4, 0x30,
  20907. 0x26, 0x69, 0x48, 0x9d, 0x7a, 0x4f, 0xad, 0xb5,
  20908. 0x6a, 0x51, 0xad, 0xeb, 0xf9, 0x90, 0x31, 0x77,
  20909. 0x53, 0x30, 0x2a, 0x85, 0xf7, 0x11, 0x21, 0x0c,
  20910. 0xb8, 0x4b, 0x56, 0x03, 0x5e, 0xbb, 0x25, 0x33,
  20911. 0x7c, 0xd9, 0x5a, 0xd1, 0x5c, 0xb2, 0xd4, 0x53,
  20912. 0xc5, 0x16, 0x68, 0xf0, 0xdf, 0x48, 0x55, 0x3e,
  20913. 0xd4, 0x59, 0x87, 0x64, 0x59, 0xaa, 0x39, 0x01,
  20914. 0x45, 0x89, 0x9c, 0x72, 0xff, 0xdd, 0x8f, 0x6d,
  20915. 0xa0, 0x42, 0xbc, 0x6f, 0x6e, 0x62, 0x18, 0x2d,
  20916. 0x50, 0xe8, 0x18, 0x97, 0x87, 0xfc, 0xef, 0x1f,
  20917. 0xf5, 0x53, 0x68, 0xe8, 0x49, 0xd1, 0xa2, 0xe8,
  20918. 0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
  20919. 0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
  20920. };
  20921. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  20922. 0x02
  20923. };
  20924. byte salt[10];
  20925. byte verifier[192];
  20926. word32 v_size = sizeof(verifier);
  20927. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  20928. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  20929. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20930. Srp *cli = (Srp *)XMALLOC(sizeof *cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20931. Srp *srv = (Srp *)XMALLOC(sizeof *srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20932. byte *clientProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20933. DYNAMIC_TYPE_TMP_BUFFER); /* M1 */
  20934. byte *serverProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20935. DYNAMIC_TYPE_TMP_BUFFER); /* M2 */
  20936. if ((cli == NULL) ||
  20937. (srv == NULL) ||
  20938. (clientProof == NULL) ||
  20939. (serverProof == NULL)) {
  20940. r = WC_TEST_RET_ENC_NC;
  20941. goto out;
  20942. }
  20943. #else
  20944. Srp cli[1], srv[1];
  20945. byte clientProof[SRP_MAX_DIGEST_SIZE]; /* M1 */
  20946. byte serverProof[SRP_MAX_DIGEST_SIZE]; /* M2 */
  20947. #endif
  20948. /* set as 0's so if second init on srv not called SrpTerm is not on
  20949. * garbage values */
  20950. XMEMSET(srv, 0, sizeof *srv);
  20951. XMEMSET(cli, 0, sizeof *cli);
  20952. /* generating random salt */
  20953. r = generate_random_salt(salt, sizeof(salt));
  20954. /* client knows username and password. */
  20955. /* server knows N, g, salt and verifier. */
  20956. if (!r) r = wc_SrpInit_ex(cli, dgstType, SRP_CLIENT_SIDE, HEAP_HINT, devId);
  20957. if (!r) r = wc_SrpSetUsername(cli, username, usernameSz);
  20958. /* loading N, g and salt in advance to generate the verifier. */
  20959. if (!r) r = wc_SrpSetParams(cli, N, sizeof(N),
  20960. g, sizeof(g),
  20961. salt, sizeof(salt));
  20962. if (!r) r = wc_SrpSetPassword(cli, password, passwordSz);
  20963. if (!r) r = wc_SrpGetVerifier(cli, verifier, &v_size);
  20964. /* client sends username to server */
  20965. if (!r) r = wc_SrpInit_ex(srv, dgstType, SRP_SERVER_SIDE, HEAP_HINT, devId);
  20966. if (!r) r = wc_SrpSetUsername(srv, username, usernameSz);
  20967. if (!r) r = wc_SrpSetParams(srv, N, sizeof(N),
  20968. g, sizeof(g),
  20969. salt, sizeof(salt));
  20970. if (!r) r = wc_SrpSetVerifier(srv, verifier, v_size);
  20971. if (!r) r = wc_SrpGetPublic(srv, serverPubKey, &serverPubKeySz);
  20972. /* server sends N, g, salt and B to client */
  20973. if (!r) r = wc_SrpGetPublic(cli, clientPubKey, &clientPubKeySz);
  20974. if (!r) r = wc_SrpComputeKey(cli, clientPubKey, clientPubKeySz,
  20975. serverPubKey, serverPubKeySz);
  20976. if (!r) r = wc_SrpGetProof(cli, clientProof, &clientProofSz);
  20977. /* client sends A and M1 to server */
  20978. if (!r) r = wc_SrpComputeKey(srv, clientPubKey, clientPubKeySz,
  20979. serverPubKey, serverPubKeySz);
  20980. if (!r) r = wc_SrpVerifyPeersProof(srv, clientProof, clientProofSz);
  20981. if (!r) r = wc_SrpGetProof(srv, serverProof, &serverProofSz);
  20982. /* server sends M2 to client */
  20983. if (!r) r = wc_SrpVerifyPeersProof(cli, serverProof, serverProofSz);
  20984. wc_SrpTerm(cli);
  20985. wc_SrpTerm(srv);
  20986. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20987. out:
  20988. XFREE(cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20989. XFREE(srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20990. XFREE(clientProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20991. XFREE(serverProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20992. #endif
  20993. return r;
  20994. }
  20995. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
  20996. {
  20997. wc_test_ret_t ret;
  20998. WOLFSSL_ENTER("srp_test");
  20999. #ifndef NO_SHA
  21000. ret = srp_test_digest(SRP_TYPE_SHA);
  21001. if (ret != 0)
  21002. return ret;
  21003. #endif
  21004. #ifndef NO_SHA256
  21005. ret = srp_test_digest(SRP_TYPE_SHA256);
  21006. if (ret != 0)
  21007. return ret;
  21008. #endif
  21009. #ifdef WOLFSSL_SHA384
  21010. ret = srp_test_digest(SRP_TYPE_SHA384);
  21011. if (ret != 0)
  21012. return ret;
  21013. #endif
  21014. #ifdef WOLFSSL_SHA512
  21015. ret = srp_test_digest(SRP_TYPE_SHA512);
  21016. if (ret != 0)
  21017. return ret;
  21018. #endif
  21019. return ret;
  21020. }
  21021. #endif /* WOLFCRYPT_HAVE_SRP */
  21022. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  21023. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  21024. static wc_test_ret_t openssl_aes_test(void)
  21025. {
  21026. #ifdef HAVE_AES_CBC
  21027. #ifdef WOLFSSL_AES_128
  21028. {
  21029. /* EVP_CipherUpdate test */
  21030. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21031. {
  21032. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21033. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21034. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21035. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21036. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21037. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21038. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21039. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21040. };
  21041. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21042. "0123456789abcdef "; /* align */
  21043. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21044. "1234567890abcdef "; /* align */
  21045. byte cipher[AES_BLOCK_SIZE * 4];
  21046. byte plain [AES_BLOCK_SIZE * 4];
  21047. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21048. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21049. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21050. #else
  21051. WOLFSSL_EVP_CIPHER_CTX en[1];
  21052. WOLFSSL_EVP_CIPHER_CTX de[1];
  21053. #endif
  21054. int outlen ;
  21055. int total = 0;
  21056. int i;
  21057. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21058. if ((en == NULL) || (de == NULL))
  21059. return MEMORY_E;
  21060. #endif
  21061. wolfSSL_EVP_CIPHER_CTX_init(en);
  21062. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21063. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21064. return WC_TEST_RET_ENC_NC;
  21065. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21066. (byte*)cbcPlain, 9) == 0)
  21067. return WC_TEST_RET_ENC_NC;
  21068. if (outlen != 0)
  21069. return WC_TEST_RET_ENC_NC;
  21070. total += outlen;
  21071. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21072. (byte*)&cbcPlain[9] , 9) == 0)
  21073. return WC_TEST_RET_ENC_NC;
  21074. if (outlen != 16)
  21075. return WC_TEST_RET_ENC_NC;
  21076. total += outlen;
  21077. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21078. return WC_TEST_RET_ENC_NC;
  21079. if (outlen != 16)
  21080. return WC_TEST_RET_ENC_NC;
  21081. total += outlen;
  21082. if (total != 32)
  21083. return 3408;
  21084. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21085. total = 0;
  21086. wolfSSL_EVP_CIPHER_CTX_init(de);
  21087. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21088. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21089. return WC_TEST_RET_ENC_NC;
  21090. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  21091. return WC_TEST_RET_ENC_NC;
  21092. if (outlen != 0)
  21093. return WC_TEST_RET_ENC_NC;
  21094. total += outlen;
  21095. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21096. (byte*)&cipher[6], 12) == 0)
  21097. return WC_TEST_RET_ENC_NC;
  21098. if (outlen != 0)
  21099. total += outlen;
  21100. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21101. (byte*)&cipher[6+12], 14) == 0)
  21102. return WC_TEST_RET_ENC_NC;
  21103. if (outlen != 16)
  21104. return WC_TEST_RET_ENC_NC;
  21105. total += outlen;
  21106. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21107. return WC_TEST_RET_ENC_NC;
  21108. if (outlen != 2)
  21109. return WC_TEST_RET_ENC_NC;
  21110. total += outlen;
  21111. if (total != 18)
  21112. return 3427;
  21113. if (XMEMCMP(plain, cbcPlain, 18))
  21114. return WC_TEST_RET_ENC_NC;
  21115. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21116. /* test with encrypting/decrypting more than 16 bytes at once */
  21117. total = 0;
  21118. wolfSSL_EVP_CIPHER_CTX_init(en);
  21119. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21120. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21121. return WC_TEST_RET_ENC_NC;
  21122. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21123. (byte*)cbcPlain, 17) == 0)
  21124. return WC_TEST_RET_ENC_NC;
  21125. if (outlen != 16)
  21126. return WC_TEST_RET_ENC_NC;
  21127. total += outlen;
  21128. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21129. (byte*)&cbcPlain[17] , 1) == 0)
  21130. return WC_TEST_RET_ENC_NC;
  21131. if (outlen != 0)
  21132. return WC_TEST_RET_ENC_NC;
  21133. total += outlen;
  21134. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21135. return WC_TEST_RET_ENC_NC;
  21136. if (outlen != 16)
  21137. return WC_TEST_RET_ENC_NC;
  21138. total += outlen;
  21139. if (total != 32)
  21140. return WC_TEST_RET_ENC_NC;
  21141. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21142. total = 0;
  21143. wolfSSL_EVP_CIPHER_CTX_init(de);
  21144. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21145. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21146. return WC_TEST_RET_ENC_NC;
  21147. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0)
  21148. return WC_TEST_RET_ENC_NC;
  21149. if (outlen != 16)
  21150. return WC_TEST_RET_ENC_NC;
  21151. total += outlen;
  21152. /* final call on non block size should fail */
  21153. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21154. return WC_TEST_RET_ENC_NC;
  21155. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21156. (byte*)&cipher[17], 1) == 0)
  21157. return WC_TEST_RET_ENC_NC;
  21158. if (outlen != 0)
  21159. total += outlen;
  21160. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21161. (byte*)&cipher[17+1], 14) == 0)
  21162. return WC_TEST_RET_ENC_NC;
  21163. if (outlen != 0)
  21164. return WC_TEST_RET_ENC_NC;
  21165. total += outlen;
  21166. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21167. return WC_TEST_RET_ENC_NC;
  21168. if (outlen != 2)
  21169. return WC_TEST_RET_ENC_NC;
  21170. total += outlen;
  21171. if (total != 18)
  21172. return WC_TEST_RET_ENC_NC;
  21173. if (XMEMCMP(plain, cbcPlain, 18))
  21174. return WC_TEST_RET_ENC_NC;
  21175. /* test byte by byte decrypt */
  21176. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21177. plain[i] = i;
  21178. }
  21179. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21180. total = 0;
  21181. wolfSSL_EVP_CIPHER_CTX_init(en);
  21182. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21183. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21184. return WC_TEST_RET_ENC_NC;
  21185. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21186. (byte*)plain, AES_BLOCK_SIZE * 3) == 0)
  21187. return WC_TEST_RET_ENC_NC;
  21188. if (outlen != AES_BLOCK_SIZE * 3)
  21189. return WC_TEST_RET_ENC_NC;
  21190. total += outlen;
  21191. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21192. return WC_TEST_RET_ENC_NC;
  21193. if (outlen != AES_BLOCK_SIZE)
  21194. return WC_TEST_RET_ENC_NC;
  21195. total += outlen;
  21196. if (total != sizeof(plain))
  21197. return WC_TEST_RET_ENC_NC;
  21198. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21199. total = 0;
  21200. wolfSSL_EVP_CIPHER_CTX_init(de);
  21201. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21202. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21203. return WC_TEST_RET_ENC_NC;
  21204. for (i = 0; i < AES_BLOCK_SIZE * 4; i++) {
  21205. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain + total, &outlen,
  21206. (byte*)cipher + i, 1) == 0)
  21207. return WC_TEST_RET_ENC_NC;
  21208. if (outlen > 0) {
  21209. int j;
  21210. total += outlen;
  21211. for (j = 0; j < total; j++) {
  21212. if (plain[j] != j) {
  21213. return WC_TEST_RET_ENC_NC;
  21214. }
  21215. }
  21216. }
  21217. }
  21218. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21219. return WC_TEST_RET_ENC_NC;
  21220. total += outlen;
  21221. if (total != AES_BLOCK_SIZE * 3) {
  21222. return WC_TEST_RET_ENC_NC;
  21223. }
  21224. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21225. if (plain[i] != i) {
  21226. return WC_TEST_RET_ENC_NC;
  21227. }
  21228. }
  21229. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21230. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21231. wolfSSL_EVP_CIPHER_CTX_free(en);
  21232. wolfSSL_EVP_CIPHER_CTX_free(de);
  21233. #endif
  21234. }
  21235. /* set buffers to be exact size to catch potential over read/write */
  21236. {
  21237. /* EVP_CipherUpdate test */
  21238. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21239. {
  21240. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21241. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21242. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21243. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21244. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21245. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21246. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21247. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21248. };
  21249. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21250. "0123456789abcdef "; /* align */
  21251. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21252. "1234567890abcdef "; /* align */
  21253. #define EVP_TEST_BUF_SZ 18
  21254. #define EVP_TEST_BUF_PAD 32
  21255. byte cipher[EVP_TEST_BUF_SZ];
  21256. byte plain [EVP_TEST_BUF_SZ];
  21257. byte padded[EVP_TEST_BUF_PAD];
  21258. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21259. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21260. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21261. #else
  21262. WOLFSSL_EVP_CIPHER_CTX en[1];
  21263. WOLFSSL_EVP_CIPHER_CTX de[1];
  21264. #endif
  21265. int outlen ;
  21266. int total = 0;
  21267. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21268. if ((en == NULL) || (de == NULL))
  21269. return MEMORY_E;
  21270. #endif
  21271. wolfSSL_EVP_CIPHER_CTX_init(en);
  21272. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21273. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21274. return WC_TEST_RET_ENC_NC;
  21275. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != 1)
  21276. return WC_TEST_RET_ENC_NC;
  21277. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21278. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21279. return WC_TEST_RET_ENC_NC;
  21280. if (outlen != 16)
  21281. return WC_TEST_RET_ENC_NC;
  21282. total += outlen;
  21283. /* should fail here */
  21284. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0)
  21285. return WC_TEST_RET_ENC_NC;
  21286. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21287. /* turn padding back on and do successful encrypt */
  21288. total = 0;
  21289. wolfSSL_EVP_CIPHER_CTX_init(en);
  21290. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21291. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21292. return WC_TEST_RET_ENC_NC;
  21293. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != 1)
  21294. return WC_TEST_RET_ENC_NC;
  21295. if (wolfSSL_EVP_CipherUpdate(en, (byte*)padded, &outlen,
  21296. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21297. return WC_TEST_RET_ENC_NC;
  21298. if (outlen != 16)
  21299. return WC_TEST_RET_ENC_NC;
  21300. total += outlen;
  21301. if (wolfSSL_EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0)
  21302. return WC_TEST_RET_ENC_NC;
  21303. total += outlen;
  21304. if (total != 32)
  21305. return WC_TEST_RET_ENC_NC;
  21306. XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ);
  21307. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21308. /* test out of bounds read on buffers w/o padding during decryption */
  21309. total = 0;
  21310. wolfSSL_EVP_CIPHER_CTX_init(de);
  21311. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21312. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21313. return WC_TEST_RET_ENC_NC;
  21314. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 0) != 1)
  21315. return WC_TEST_RET_ENC_NC;
  21316. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher,
  21317. EVP_TEST_BUF_SZ) == 0)
  21318. return WC_TEST_RET_ENC_NC;
  21319. if (outlen != 16)
  21320. return WC_TEST_RET_ENC_NC;
  21321. total += outlen;
  21322. /* should fail since not using padding */
  21323. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21324. return WC_TEST_RET_ENC_NC;
  21325. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21326. total = 0;
  21327. wolfSSL_EVP_CIPHER_CTX_init(de);
  21328. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21329. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21330. return WC_TEST_RET_ENC_NC;
  21331. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 1) != 1)
  21332. return WC_TEST_RET_ENC_NC;
  21333. if (wolfSSL_EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded,
  21334. EVP_TEST_BUF_PAD) == 0)
  21335. return WC_TEST_RET_ENC_NC;
  21336. if (outlen != 16)
  21337. return WC_TEST_RET_ENC_NC;
  21338. total += outlen;
  21339. if (wolfSSL_EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0)
  21340. return WC_TEST_RET_ENC_NC;
  21341. if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ))
  21342. return WC_TEST_RET_ENC_NC;
  21343. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21345. wolfSSL_EVP_CIPHER_CTX_free(en);
  21346. wolfSSL_EVP_CIPHER_CTX_free(de);
  21347. #endif
  21348. }
  21349. { /* evp_cipher test: EVP_aes_128_cbc */
  21350. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21351. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21352. #else
  21353. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21354. #endif
  21355. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  21356. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  21357. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  21358. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  21359. };
  21360. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21361. {
  21362. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  21363. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  21364. };
  21365. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21366. "0123456789abcdef "; /* align */
  21367. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21368. "1234567890abcdef "; /* align */
  21369. byte cipher[AES_BLOCK_SIZE * 4];
  21370. byte plain [AES_BLOCK_SIZE * 4];
  21371. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21372. if (ctx == NULL)
  21373. return MEMORY_E;
  21374. #endif
  21375. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21376. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1) == 0)
  21377. return WC_TEST_RET_ENC_NC;
  21378. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21379. return WC_TEST_RET_ENC_NC;
  21380. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21381. return WC_TEST_RET_ENC_NC;
  21382. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21383. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21384. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0) == 0)
  21385. return WC_TEST_RET_ENC_NC;
  21386. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21387. return WC_TEST_RET_ENC_NC;
  21388. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21389. return WC_TEST_RET_ENC_NC;
  21390. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21391. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21392. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21393. #endif
  21394. } /* end evp_cipher test: EVP_aes_128_cbc*/
  21395. #endif /* WOLFSSL_AES_128 */
  21396. #endif /* HAVE_AES_CBC */
  21397. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21398. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  21399. { /* evp_cipher test: EVP_aes_256_ecb*/
  21400. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21401. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21402. #else
  21403. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21404. #endif
  21405. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21406. {
  21407. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21408. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21409. };
  21410. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21411. {
  21412. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21413. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21414. };
  21415. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21416. {
  21417. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21418. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21419. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21420. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21421. };
  21422. byte cipher[AES_BLOCK_SIZE * 4];
  21423. byte plain [AES_BLOCK_SIZE * 4];
  21424. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21425. if (ctx == NULL)
  21426. return MEMORY_E;
  21427. #endif
  21428. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21429. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0)
  21430. return WC_TEST_RET_ENC_NC;
  21431. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21432. return WC_TEST_RET_ENC_NC;
  21433. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21434. return WC_TEST_RET_ENC_NC;
  21435. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21436. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0)
  21437. return WC_TEST_RET_ENC_NC;
  21438. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21439. return WC_TEST_RET_ENC_NC;
  21440. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21441. return WC_TEST_RET_ENC_NC;
  21442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21443. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21444. #endif
  21445. } /* end evp_cipher test */
  21446. #endif /* HAVE_AES_ECB && WOLFSSL_AES_256 */
  21447. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  21448. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  21449. {
  21450. /* Test: AES_encrypt/decrypt/set Key */
  21451. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21452. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21453. #ifdef HAVE_AES_DECRYPT
  21454. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21455. #endif
  21456. #else
  21457. AES_KEY enc[1];
  21458. #ifdef HAVE_AES_DECRYPT
  21459. AES_KEY dec[1];
  21460. #endif
  21461. #endif
  21462. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21463. {
  21464. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21465. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21466. };
  21467. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21468. {
  21469. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21470. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21471. };
  21472. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21473. {
  21474. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21475. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21476. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21477. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21478. };
  21479. byte plain[sizeof(msg)];
  21480. byte cipher[sizeof(msg)];
  21481. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21482. if (enc == NULL)
  21483. return MEMORY_E;
  21484. #ifdef HAVE_AES_DECRYPT
  21485. if (dec == NULL)
  21486. return MEMORY_E;
  21487. #endif
  21488. #endif
  21489. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  21490. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  21491. AES_encrypt(msg, cipher, enc);
  21492. #ifdef HAVE_AES_DECRYPT
  21493. AES_decrypt(cipher, plain, dec);
  21494. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21495. return WC_TEST_RET_ENC_NC;
  21496. #endif /* HAVE_AES_DECRYPT */
  21497. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21498. return WC_TEST_RET_ENC_NC;
  21499. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21500. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21501. #ifdef HAVE_AES_DECRYPT
  21502. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21503. #endif
  21504. #endif
  21505. }
  21506. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  21507. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21508. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  21509. #ifdef WOLFSSL_AES_COUNTER
  21510. {
  21511. byte plainBuff [64];
  21512. byte cipherBuff[64];
  21513. #ifdef WOLFSSL_AES_128
  21514. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  21515. {
  21516. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21517. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21518. };
  21519. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  21520. {
  21521. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21522. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21523. };
  21524. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  21525. {
  21526. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21527. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21528. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21529. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21530. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21531. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21532. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21533. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21534. };
  21535. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  21536. {
  21537. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  21538. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  21539. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  21540. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  21541. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  21542. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  21543. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  21544. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  21545. };
  21546. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  21547. {
  21548. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  21549. 0xc2
  21550. };
  21551. #endif
  21552. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21553. * NIST Special Publication 800-38A */
  21554. #ifdef WOLFSSL_AES_192
  21555. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  21556. {
  21557. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  21558. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  21559. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  21560. };
  21561. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  21562. {
  21563. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21564. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21565. };
  21566. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  21567. {
  21568. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21569. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21570. };
  21571. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  21572. {
  21573. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  21574. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  21575. };
  21576. #endif /* WOLFSSL_AES_192 */
  21577. #ifdef WOLFSSL_AES_256
  21578. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21579. * NIST Special Publication 800-38A */
  21580. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  21581. {
  21582. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21583. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21584. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21585. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21586. };
  21587. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  21588. {
  21589. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21590. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21591. };
  21592. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  21593. {
  21594. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21595. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21596. };
  21597. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  21598. {
  21599. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  21600. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  21601. };
  21602. #endif /* WOLFSSL_AES_256 */
  21603. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21604. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21605. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21606. #else
  21607. WOLFSSL_EVP_CIPHER_CTX en[1];
  21608. WOLFSSL_EVP_CIPHER_CTX de[1];
  21609. #endif
  21610. #ifdef WOLFSSL_AES_128
  21611. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21612. WOLFSSL_EVP_CIPHER_CTX *p_en;
  21613. WOLFSSL_EVP_CIPHER_CTX *p_de;
  21614. #endif
  21615. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21616. if ((en == NULL) || (de == NULL))
  21617. return MEMORY_E;
  21618. #endif
  21619. wolfSSL_EVP_CIPHER_CTX_init(en);
  21620. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21621. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21622. return WC_TEST_RET_ENC_NC;
  21623. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  21624. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21625. return WC_TEST_RET_ENC_NC;
  21626. wolfSSL_EVP_CIPHER_CTX_init(de);
  21627. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21628. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21629. return WC_TEST_RET_ENC_NC;
  21630. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21631. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  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 (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21638. return WC_TEST_RET_ENC_NC;
  21639. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21640. return WC_TEST_RET_ENC_NC;
  21641. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21642. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  21643. if (p_en == NULL)
  21644. return WC_TEST_RET_ENC_ERRNO;
  21645. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  21646. if (p_de == NULL)
  21647. return WC_TEST_RET_ENC_ERRNO;
  21648. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  21649. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21650. return WC_TEST_RET_ENC_NC;
  21651. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  21652. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21653. return WC_TEST_RET_ENC_NC;
  21654. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  21655. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21656. return WC_TEST_RET_ENC_NC;
  21657. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  21658. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21659. return WC_TEST_RET_ENC_NC;
  21660. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21661. return WC_TEST_RET_ENC_NC;
  21662. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21663. return WC_TEST_RET_ENC_NC;
  21664. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  21665. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  21666. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  21667. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21668. return WC_TEST_RET_ENC_NC;
  21669. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21670. return WC_TEST_RET_ENC_NC;
  21671. wolfSSL_EVP_CIPHER_CTX_init(en);
  21672. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21673. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21674. return WC_TEST_RET_ENC_NC;
  21675. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21676. return WC_TEST_RET_ENC_NC;
  21677. wolfSSL_EVP_CIPHER_CTX_init(de);
  21678. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21679. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21680. return WC_TEST_RET_ENC_NC;
  21681. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21682. return WC_TEST_RET_ENC_NC;
  21683. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21684. return WC_TEST_RET_ENC_NC;
  21685. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  21686. return WC_TEST_RET_ENC_NC;
  21687. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21688. return WC_TEST_RET_ENC_NC;
  21689. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21690. return WC_TEST_RET_ENC_NC;
  21691. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21692. return WC_TEST_RET_ENC_NC;
  21693. if (XMEMCMP(cipherBuff, oddCipher, 9))
  21694. return WC_TEST_RET_ENC_NC;
  21695. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21696. return WC_TEST_RET_ENC_NC;
  21697. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21698. return WC_TEST_RET_ENC_NC;
  21699. #endif /* WOLFSSL_AES_128 */
  21700. #ifdef WOLFSSL_AES_192
  21701. wolfSSL_EVP_CIPHER_CTX_init(en);
  21702. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  21703. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21704. return WC_TEST_RET_ENC_NC;
  21705. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  21706. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21707. return WC_TEST_RET_ENC_NC;
  21708. wolfSSL_EVP_CIPHER_CTX_init(de);
  21709. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  21710. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21711. return WC_TEST_RET_ENC_NC;
  21712. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21713. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21714. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21715. return WC_TEST_RET_ENC_NC;
  21716. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  21717. return WC_TEST_RET_ENC_NC;
  21718. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  21719. return WC_TEST_RET_ENC_NC;
  21720. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21721. return WC_TEST_RET_ENC_NC;
  21722. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21723. return WC_TEST_RET_ENC_NC;
  21724. #endif /* WOLFSSL_AES_192 */
  21725. #ifdef WOLFSSL_AES_256
  21726. wolfSSL_EVP_CIPHER_CTX_init(en);
  21727. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  21728. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21729. return WC_TEST_RET_ENC_NC;
  21730. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  21731. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21732. return WC_TEST_RET_ENC_NC;
  21733. wolfSSL_EVP_CIPHER_CTX_init(de);
  21734. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  21735. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21736. return WC_TEST_RET_ENC_NC;
  21737. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21738. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21739. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21740. return WC_TEST_RET_ENC_NC;
  21741. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  21742. return WC_TEST_RET_ENC_NC;
  21743. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  21744. return WC_TEST_RET_ENC_NC;
  21745. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21746. return WC_TEST_RET_ENC_NC;
  21747. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21748. return WC_TEST_RET_ENC_NC;
  21749. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21750. wolfSSL_EVP_CIPHER_CTX_free(en);
  21751. wolfSSL_EVP_CIPHER_CTX_free(de);
  21752. #endif
  21753. #endif /* WOLFSSL_AES_256 */
  21754. }
  21755. #endif /* HAVE_AES_COUNTER */
  21756. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21757. #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128)
  21758. {
  21759. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21760. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21761. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21762. #else
  21763. AES_KEY enc[1];
  21764. AES_KEY dec[1];
  21765. #endif
  21766. WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = {
  21767. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  21768. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  21769. };
  21770. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21771. {
  21772. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21773. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21774. };
  21775. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  21776. {
  21777. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  21778. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  21779. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  21780. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b
  21781. };
  21782. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21783. {
  21784. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21785. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21786. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21787. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51
  21788. };
  21789. byte cipher[AES_BLOCK_SIZE * 2];
  21790. byte iv[AES_BLOCK_SIZE]; /* iv buffer is updeated by API */
  21791. int num = 0;
  21792. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21793. if ((enc == NULL) || (dec == NULL))
  21794. return MEMORY_E;
  21795. #endif
  21796. XMEMCPY(iv, setIv, sizeof(setIv));
  21797. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc);
  21798. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec);
  21799. wolfSSL_AES_cfb128_encrypt(msg, cipher, AES_BLOCK_SIZE - 1, enc, iv,
  21800. &num, AES_ENCRYPT);
  21801. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE - 1))
  21802. return WC_TEST_RET_ENC_NC;
  21803. if (num != 15) /* should have used 15 of the 16 bytes */
  21804. return WC_TEST_RET_ENC_NC;
  21805. wolfSSL_AES_cfb128_encrypt(msg + AES_BLOCK_SIZE - 1,
  21806. cipher + AES_BLOCK_SIZE - 1, AES_BLOCK_SIZE + 1, enc, iv,
  21807. &num, AES_ENCRYPT);
  21808. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  21809. return WC_TEST_RET_ENC_NC;
  21810. if (num != 0)
  21811. return WC_TEST_RET_ENC_NC;
  21812. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21813. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21814. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21815. #endif
  21816. }
  21817. #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */
  21818. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21819. return 0;
  21820. }
  21821. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  21822. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void)
  21823. {
  21824. wc_test_ret_t ret;
  21825. #ifdef WOLFSSL_SMALL_STACK
  21826. WOLFSSL_EVP_MD_CTX *md_ctx = (WOLFSSL_EVP_MD_CTX *)XMALLOC(sizeof(WOLFSSL_EVP_MD_CTX), NULL, DYNAMIC_TYPE_OPENSSL);
  21827. #else
  21828. WOLFSSL_EVP_MD_CTX md_ctx[1];
  21829. #endif
  21830. testVector a, b, c, d, e, f;
  21831. byte hash[WC_SHA256_DIGEST_SIZE*2]; /* max size */
  21832. #ifdef WOLFSSL_SMALL_STACK
  21833. if (md_ctx == NULL)
  21834. return WC_TEST_RET_ENC_EC(MEMORY_E);
  21835. #endif
  21836. WOLFSSL_ENTER("openssl_test");
  21837. a.inLen = 0;
  21838. b.inLen = c.inLen = d.inLen = e.inLen = f.inLen = a.inLen;
  21839. (void)a;
  21840. (void)b;
  21841. (void)c;
  21842. (void)d;
  21843. (void)e;
  21844. (void)f;
  21845. /* test malloc / free , 10 is an arbitrary amount of memory chosen */
  21846. {
  21847. byte* p;
  21848. p = (byte*)wolfSSL_CRYPTO_malloc(10, "", 0);
  21849. if (p == NULL) {
  21850. return WC_TEST_RET_ENC_NC;
  21851. }
  21852. XMEMSET(p, 0, 10);
  21853. wolfSSL_CRYPTO_free(p, "", 0);
  21854. }
  21855. #ifndef NO_MD5
  21856. a.input = "1234567890123456789012345678901234567890123456789012345678"
  21857. "9012345678901234567890";
  21858. a.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  21859. "\x7a";
  21860. a.inLen = XSTRLEN(a.input);
  21861. a.outLen = WC_MD5_DIGEST_SIZE;
  21862. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21863. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_md5());
  21864. if (ret == WOLFSSL_SUCCESS) {
  21865. ret = wolfSSL_EVP_DigestUpdate(md_ctx, a.input, (unsigned long)a.inLen);
  21866. }
  21867. if (ret == WOLFSSL_SUCCESS) {
  21868. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21869. }
  21870. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21871. if (ret != WOLFSSL_SUCCESS)
  21872. return WC_TEST_RET_ENC_NC;
  21873. if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0)
  21874. return WC_TEST_RET_ENC_NC;
  21875. #endif /* NO_MD5 */
  21876. #ifndef NO_SHA
  21877. b.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21878. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21879. "aaaaaaaaaa";
  21880. b.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  21881. "\x53\x99\x5E\x26\xA0";
  21882. b.inLen = XSTRLEN(b.input);
  21883. b.outLen = WC_SHA_DIGEST_SIZE;
  21884. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21885. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha1());
  21886. if (ret == WOLFSSL_SUCCESS) {
  21887. ret = wolfSSL_EVP_DigestUpdate(md_ctx, b.input, (unsigned long)b.inLen);
  21888. if (ret == WOLFSSL_SUCCESS)
  21889. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21890. }
  21891. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21892. if (ret != WOLFSSL_SUCCESS)
  21893. return WC_TEST_RET_ENC_NC;
  21894. if (XMEMCMP(hash, b.output, b.outLen) != 0)
  21895. return WC_TEST_RET_ENC_NC;
  21896. #endif /* NO_SHA */
  21897. #ifdef WOLFSSL_SHA224
  21898. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21899. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21900. e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
  21901. "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
  21902. e.inLen = XSTRLEN(e.input);
  21903. e.outLen = WC_SHA224_DIGEST_SIZE;
  21904. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21905. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha224());
  21906. if (ret == WOLFSSL_SUCCESS) {
  21907. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21908. if (ret == WOLFSSL_SUCCESS)
  21909. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21910. }
  21911. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21912. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21913. return WC_TEST_RET_ENC_NC;
  21914. }
  21915. #endif /* WOLFSSL_SHA224 */
  21916. #ifndef NO_SHA256
  21917. d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  21918. d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  21919. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  21920. "\x06\xC1";
  21921. d.inLen = XSTRLEN(d.input);
  21922. d.outLen = WC_SHA256_DIGEST_SIZE;
  21923. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21924. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha256());
  21925. if (ret == WOLFSSL_SUCCESS) {
  21926. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21927. if (ret == WOLFSSL_SUCCESS)
  21928. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21929. }
  21930. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21931. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21932. return WC_TEST_RET_ENC_NC;
  21933. }
  21934. #endif /* !NO_SHA256 */
  21935. #ifdef WOLFSSL_SHA384
  21936. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21937. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21938. e.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  21939. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  21940. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  21941. "\x74\x60\x39";
  21942. e.inLen = XSTRLEN(e.input);
  21943. e.outLen = WC_SHA384_DIGEST_SIZE;
  21944. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21945. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha384());
  21946. if (ret == WOLFSSL_SUCCESS) {
  21947. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21948. if (ret == WOLFSSL_SUCCESS)
  21949. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21950. }
  21951. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21952. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21953. return WC_TEST_RET_ENC_NC;
  21954. }
  21955. #endif /* WOLFSSL_SHA384 */
  21956. #ifdef WOLFSSL_SHA512
  21957. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21958. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21959. f.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  21960. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  21961. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  21962. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  21963. "\x87\x4b\xe9\x09";
  21964. f.inLen = XSTRLEN(f.input);
  21965. f.outLen = WC_SHA512_DIGEST_SIZE;
  21966. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21967. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512());
  21968. if (ret == WOLFSSL_SUCCESS) {
  21969. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21970. if (ret == WOLFSSL_SUCCESS)
  21971. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21972. }
  21973. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21974. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21975. return WC_TEST_RET_ENC_NC;
  21976. }
  21977. #if !defined(WOLFSSL_NOSHA512_224) && \
  21978. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21979. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21980. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21981. f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45"
  21982. "\x33\x35\xd6\x64\x73\x4f\xe4\x0e\x72\x68\x67\x4a\xf9";
  21983. f.inLen = XSTRLEN(f.input);
  21984. f.outLen = WC_SHA512_224_DIGEST_SIZE;
  21985. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21986. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_224());
  21987. if (ret == WOLFSSL_SUCCESS) {
  21988. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21989. if (ret == WOLFSSL_SUCCESS)
  21990. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21991. }
  21992. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21993. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21994. return WC_TEST_RET_ENC_NC;
  21995. }
  21996. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  21997. #if !defined(WOLFSSL_NOSHA512_256) && \
  21998. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21999. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22000. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22001. f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31"
  22002. "\xbe\x65\xcb\x9d\x3e\xf8\x3e\xe6\x14\x6f\xea\xc8\x61\xe1\x9b"
  22003. "\x56\x3a";
  22004. f.inLen = XSTRLEN(f.input);
  22005. f.outLen = WC_SHA512_256_DIGEST_SIZE;
  22006. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22007. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_256());
  22008. if (ret == WOLFSSL_SUCCESS) {
  22009. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22010. if (ret == WOLFSSL_SUCCESS)
  22011. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22012. }
  22013. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22014. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  22015. return WC_TEST_RET_ENC_NC;
  22016. }
  22017. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  22018. #endif /* WOLFSSL_SHA512 */
  22019. #ifdef WOLFSSL_SHA3
  22020. #ifndef WOLFSSL_NOSHA3_224
  22021. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22022. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22023. e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a"
  22024. "\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
  22025. e.inLen = XSTRLEN(e.input);
  22026. e.outLen = WC_SHA3_224_DIGEST_SIZE;
  22027. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22028. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_224());
  22029. if (ret == WOLFSSL_SUCCESS) {
  22030. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22031. if (ret == WOLFSSL_SUCCESS)
  22032. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22033. }
  22034. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22035. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22036. return WC_TEST_RET_ENC_NC;
  22037. }
  22038. #endif /* WOLFSSL_NOSHA3_224 */
  22039. #ifndef WOLFSSL_NOSHA3_256
  22040. d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22041. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22042. d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
  22043. "\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
  22044. "\x1d\x18";
  22045. d.inLen = XSTRLEN(d.input);
  22046. d.outLen = WC_SHA3_256_DIGEST_SIZE;
  22047. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22048. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_256());
  22049. if (ret == WOLFSSL_SUCCESS) {
  22050. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  22051. if (ret == WOLFSSL_SUCCESS)
  22052. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22053. }
  22054. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22055. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  22056. return WC_TEST_RET_ENC_NC;
  22057. }
  22058. #endif /* WOLFSSL_NOSHA3_256 */
  22059. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22060. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22061. e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47"
  22062. "\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6"
  22063. "\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79"
  22064. "\xaa\x7f\xc7";
  22065. e.inLen = XSTRLEN(e.input);
  22066. e.outLen = WC_SHA3_384_DIGEST_SIZE;
  22067. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22068. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_384());
  22069. if (ret == WOLFSSL_SUCCESS) {
  22070. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22071. if (ret == WOLFSSL_SUCCESS)
  22072. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22073. }
  22074. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22075. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22076. return WC_TEST_RET_ENC_NC;
  22077. }
  22078. #ifndef WOLFSSL_NOSHA3_512
  22079. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22080. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22081. f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78"
  22082. "\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18"
  22083. "\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8"
  22084. "\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55"
  22085. "\xf2\x1d\xd1\x85";
  22086. f.inLen = XSTRLEN(f.input);
  22087. f.outLen = WC_SHA3_512_DIGEST_SIZE;
  22088. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22089. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_512());
  22090. if (ret == WOLFSSL_SUCCESS) {
  22091. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22092. if (ret == WOLFSSL_SUCCESS)
  22093. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22094. }
  22095. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22096. if (ret != WOLFSSL_SUCCESS ||
  22097. XMEMCMP(hash, f.output, f.outLen) != 0) {
  22098. return WC_TEST_RET_ENC_NC;
  22099. }
  22100. #endif /* WOLFSSL_NOSHA3_512 */
  22101. #endif /* WOLFSSL_SHA3 */
  22102. #ifdef WOLFSSL_SMALL_STACK
  22103. XFREE(md_ctx, NULL, DYNAMIC_TYPE_OPENSSL);
  22104. md_ctx = NULL;
  22105. #endif
  22106. #ifndef WC_NO_RNG
  22107. if (wolfSSL_RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS)
  22108. return WC_TEST_RET_ENC_NC;
  22109. #endif
  22110. #ifndef NO_MD5
  22111. c.input = "what do ya want for nothing?";
  22112. c.output = "\x55\x78\xe8\x48\x4b\xcc\x93\x80\x93\xec\x53\xaf\x22\xd6\x14"
  22113. "\x76";
  22114. c.inLen = XSTRLEN(c.input);
  22115. c.outLen = WC_MD5_DIGEST_SIZE;
  22116. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)
  22117. /* Expect failure with MD5 + HMAC when using FIPS 140-3. */
  22118. if (HMAC(EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22119. hash, 0) != NULL)
  22120. #else
  22121. if (wolfSSL_HMAC(wolfSSL_EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22122. hash, 0) == NULL ||
  22123. XMEMCMP(hash, c.output, c.outLen) != 0)
  22124. #endif
  22125. {
  22126. return WC_TEST_RET_ENC_NC;
  22127. }
  22128. #endif /* NO_MD5 */
  22129. #ifndef NO_DES3
  22130. { /* des test */
  22131. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  22132. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22133. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22134. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22135. };
  22136. byte plain[24];
  22137. byte cipher[24];
  22138. const_DES_cblock key = {
  22139. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  22140. };
  22141. DES_cblock iv = {
  22142. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  22143. };
  22144. DES_key_schedule sched;
  22145. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22146. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  22147. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  22148. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  22149. };
  22150. DES_key_sched(&key, &sched);
  22151. DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, DES_ENCRYPT);
  22152. DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, DES_DECRYPT);
  22153. if (XMEMCMP(plain, vector, sizeof(vector)) != 0)
  22154. return WC_TEST_RET_ENC_NC;
  22155. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22156. return WC_TEST_RET_ENC_NC;
  22157. /* test changing iv */
  22158. DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, DES_ENCRYPT);
  22159. DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, DES_ENCRYPT);
  22160. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22161. return WC_TEST_RET_ENC_NC;
  22162. } /* end des test */
  22163. #endif /* NO_DES3 */
  22164. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  22165. if ((ret = openssl_aes_test()) != 0) {
  22166. return ret;
  22167. }
  22168. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  22169. { /* evp_cipher test: EVP_aes_128_cbc */
  22170. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22171. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22172. #else
  22173. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22174. #endif
  22175. int idx, cipherSz, plainSz;
  22176. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  22177. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22178. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22179. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22180. };
  22181. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22182. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22183. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22184. 0x3b,0x5d,0x41,0x97,0x94,0x25,0xa4,0xb4,
  22185. 0xae,0x7b,0x34,0xd0,0x3f,0x0c,0xbc,0x06
  22186. };
  22187. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  22188. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22189. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22190. 0x7d,0x37,0x7b,0x0b,0x44,0xaa,0xb5,0xf0,
  22191. 0x5f,0x34,0xb4,0xde,0xb5,0xbd,0x2a,0xbb
  22192. };
  22193. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22194. "0123456789abcdef "; /* align */
  22195. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  22196. "1234567890abcdef "; /* align */
  22197. byte cipher[AES_BLOCK_SIZE * 4];
  22198. byte plain [AES_BLOCK_SIZE * 4];
  22199. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22200. if (ctx == NULL)
  22201. return MEMORY_E;
  22202. #endif
  22203. cipherSz = 0;
  22204. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22205. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22206. if (ret == WOLFSSL_SUCCESS) {
  22207. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, (byte*)msg, sizeof(msg));
  22208. if (ret == WOLFSSL_SUCCESS)
  22209. cipherSz += idx;
  22210. }
  22211. if (ret == WOLFSSL_SUCCESS) {
  22212. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22213. if (ret == WOLFSSL_SUCCESS)
  22214. cipherSz += idx;
  22215. }
  22216. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22217. if (ret != WOLFSSL_SUCCESS)
  22218. return WC_TEST_RET_ENC_NC;
  22219. if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz))
  22220. return WC_TEST_RET_ENC_NC;
  22221. /* check partial decrypt (not enough padding for full block) */
  22222. plainSz = 0;
  22223. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22224. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22225. if (ret == WOLFSSL_SUCCESS) {
  22226. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, 1);
  22227. if (ret == WOLFSSL_SUCCESS)
  22228. plainSz += idx;
  22229. }
  22230. if (ret == WOLFSSL_SUCCESS) {
  22231. /* this test should fail... not enough padding for full block */
  22232. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22233. if (plainSz == 0 && ret != WOLFSSL_SUCCESS)
  22234. ret = WOLFSSL_SUCCESS;
  22235. else
  22236. ret = WC_TEST_RET_ENC_NC;
  22237. }
  22238. else
  22239. ret = WC_TEST_RET_ENC_NC;
  22240. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22241. if (ret != WOLFSSL_SUCCESS)
  22242. return ret;
  22243. plainSz = 0;
  22244. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22245. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22246. if (ret == WOLFSSL_SUCCESS) {
  22247. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, cipherSz);
  22248. if (ret == WOLFSSL_SUCCESS)
  22249. plainSz += idx;
  22250. }
  22251. if (ret == WOLFSSL_SUCCESS) {
  22252. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22253. if (ret == WOLFSSL_SUCCESS)
  22254. plainSz += idx;
  22255. }
  22256. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22257. if (ret != WOLFSSL_SUCCESS)
  22258. return WC_TEST_RET_ENC_NC;
  22259. if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg)))
  22260. return WC_TEST_RET_ENC_NC;
  22261. cipherSz = 0;
  22262. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22263. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22264. if (ret == WOLFSSL_SUCCESS) {
  22265. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, msg, AES_BLOCK_SIZE);
  22266. if (ret == WOLFSSL_SUCCESS)
  22267. cipherSz += idx;
  22268. }
  22269. if (ret == WOLFSSL_SUCCESS) {
  22270. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22271. if (ret == WOLFSSL_SUCCESS)
  22272. cipherSz += idx;
  22273. }
  22274. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22275. if (ret != WOLFSSL_SUCCESS)
  22276. return WC_TEST_RET_ENC_NC;
  22277. if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz))
  22278. return WC_TEST_RET_ENC_NC;
  22279. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22280. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22281. #endif
  22282. } /* end evp_cipher test: EVP_aes_128_cbc*/
  22283. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22284. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  22285. { /* evp_cipher test: EVP_aes_256_ecb*/
  22286. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22287. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22288. #else
  22289. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22290. #endif
  22291. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  22292. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22293. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22294. };
  22295. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22296. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22297. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22298. };
  22299. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  22300. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22301. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22302. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22303. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22304. };
  22305. byte cipher[AES_BLOCK_SIZE * 4];
  22306. byte plain [AES_BLOCK_SIZE * 4];
  22307. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22308. if (ctx == NULL)
  22309. return MEMORY_E;
  22310. #endif
  22311. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22312. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1);
  22313. if (ret == WOLFSSL_SUCCESS)
  22314. ret = wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16);
  22315. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22316. if (ret != 16)
  22317. return WC_TEST_RET_ENC_NC;
  22318. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22319. return WC_TEST_RET_ENC_NC;
  22320. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22321. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0);
  22322. if (ret == WOLFSSL_SUCCESS)
  22323. ret = wolfSSL_EVP_Cipher(ctx, plain, cipher, 16);
  22324. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22325. if (ret != 16)
  22326. return WC_TEST_RET_ENC_NC;
  22327. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22328. return WC_TEST_RET_ENC_NC;
  22329. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22330. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22331. #endif
  22332. } /* end evp_cipher test */
  22333. #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */
  22334. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  22335. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  22336. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  22337. {
  22338. /* Test: AES_encrypt/decrypt/set Key */
  22339. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22340. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22341. #ifdef HAVE_AES_DECRYPT
  22342. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22343. #endif
  22344. #else
  22345. AES_KEY enc[1];
  22346. #ifdef HAVE_AES_DECRYPT
  22347. AES_KEY dec[1];
  22348. #endif
  22349. #endif
  22350. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  22351. {
  22352. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22353. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22354. };
  22355. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  22356. {
  22357. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22358. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22359. };
  22360. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22361. {
  22362. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22363. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22364. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22365. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22366. };
  22367. byte plain[sizeof(msg)];
  22368. byte cipher[sizeof(msg)];
  22369. printf("openSSL extra test\n") ;
  22370. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22371. if (enc == NULL)
  22372. return MEMORY_E;
  22373. #ifdef HAVE_AES_DECRYPT
  22374. if (dec == NULL)
  22375. return MEMORY_E;
  22376. #endif
  22377. #endif
  22378. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  22379. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  22380. AES_encrypt(msg, cipher, enc);
  22381. #ifdef HAVE_AES_DECRYPT
  22382. AES_decrypt(cipher, plain, dec);
  22383. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22384. return WC_TEST_RET_ENC_NC;
  22385. #endif /* HAVE_AES_DECRYPT */
  22386. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22387. return WC_TEST_RET_ENC_NC;
  22388. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22389. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22390. #ifdef HAVE_AES_DECRYPT
  22391. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22392. #endif
  22393. #endif
  22394. }
  22395. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  22396. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  22397. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  22398. #ifdef WOLFSSL_AES_COUNTER
  22399. {
  22400. byte plainBuff [64];
  22401. byte cipherBuff[64];
  22402. #ifdef WOLFSSL_AES_128
  22403. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  22404. {
  22405. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  22406. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  22407. };
  22408. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  22409. {
  22410. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22411. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22412. };
  22413. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  22414. {
  22415. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22416. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22417. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22418. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22419. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22420. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22421. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22422. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22423. };
  22424. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  22425. {
  22426. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  22427. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  22428. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  22429. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  22430. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  22431. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  22432. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  22433. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  22434. };
  22435. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  22436. {
  22437. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  22438. 0xc2
  22439. };
  22440. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22441. WOLFSSL_EVP_CIPHER_CTX *p_en;
  22442. WOLFSSL_EVP_CIPHER_CTX *p_de;
  22443. #endif
  22444. #endif /* WOLFSSL_AES_128 */
  22445. #ifdef WOLFSSL_AES_192
  22446. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22447. * NIST Special Publication 800-38A */
  22448. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  22449. {
  22450. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  22451. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  22452. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  22453. };
  22454. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  22455. {
  22456. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22457. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22458. };
  22459. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  22460. {
  22461. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22462. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22463. };
  22464. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  22465. {
  22466. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  22467. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  22468. };
  22469. #endif /* WOLFSSL_AES_192 */
  22470. #ifdef WOLFSSL_AES_256
  22471. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22472. * NIST Special Publication 800-38A */
  22473. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  22474. {
  22475. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22476. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22477. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22478. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22479. };
  22480. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  22481. {
  22482. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22483. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22484. };
  22485. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  22486. {
  22487. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22488. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22489. };
  22490. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  22491. {
  22492. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  22493. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  22494. };
  22495. #endif /* WOLFSSL_AES_256 */
  22496. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22497. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22498. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22499. if ((en == NULL) || (de == NULL))
  22500. return MEMORY_E;
  22501. #else
  22502. WOLFSSL_EVP_CIPHER_CTX en[1];
  22503. WOLFSSL_EVP_CIPHER_CTX de[1];
  22504. #endif
  22505. #ifdef WOLFSSL_AES_128
  22506. wolfSSL_EVP_CIPHER_CTX_init(en);
  22507. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22508. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22509. return WC_TEST_RET_ENC_NC;
  22510. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  22511. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22512. return WC_TEST_RET_ENC_NC;
  22513. wolfSSL_EVP_CIPHER_CTX_init(de);
  22514. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22515. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22516. return WC_TEST_RET_ENC_NC;
  22517. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22518. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22519. return WC_TEST_RET_ENC_NC;
  22520. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22521. return WC_TEST_RET_ENC_NC;
  22522. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22523. return WC_TEST_RET_ENC_NC;
  22524. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22525. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22526. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22527. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  22528. if (p_en == NULL)
  22529. return WC_TEST_RET_ENC_ERRNO;
  22530. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  22531. if (p_de == NULL)
  22532. return WC_TEST_RET_ENC_ERRNO;
  22533. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  22534. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22535. return WC_TEST_RET_ENC_NC;
  22536. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  22537. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22538. return WC_TEST_RET_ENC_NC;
  22539. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  22540. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22541. return WC_TEST_RET_ENC_NC;
  22542. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  22543. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22544. return WC_TEST_RET_ENC_NC;
  22545. wolfSSL_EVP_CIPHER_CTX_cleanup(p_en);
  22546. wolfSSL_EVP_CIPHER_CTX_cleanup(p_de);
  22547. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  22548. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  22549. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  22550. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22551. return WC_TEST_RET_ENC_NC;
  22552. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22553. return WC_TEST_RET_ENC_NC;
  22554. wolfSSL_EVP_CIPHER_CTX_init(en);
  22555. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22556. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22557. return WC_TEST_RET_ENC_NC;
  22558. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22559. return WC_TEST_RET_ENC_NC;
  22560. wolfSSL_EVP_CIPHER_CTX_init(de);
  22561. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22562. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22563. return WC_TEST_RET_ENC_NC;
  22564. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22565. return WC_TEST_RET_ENC_NC;
  22566. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22567. return WC_TEST_RET_ENC_NC;
  22568. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  22569. return WC_TEST_RET_ENC_NC;
  22570. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22571. return WC_TEST_RET_ENC_NC;
  22572. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22573. return WC_TEST_RET_ENC_NC;
  22574. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22575. return WC_TEST_RET_ENC_NC;
  22576. if (XMEMCMP(cipherBuff, oddCipher, 9))
  22577. return WC_TEST_RET_ENC_NC;
  22578. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22579. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22580. #endif /* WOLFSSL_AES_128 */
  22581. #ifdef WOLFSSL_AES_192
  22582. wolfSSL_EVP_CIPHER_CTX_init(en);
  22583. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  22584. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22585. return WC_TEST_RET_ENC_NC;
  22586. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  22587. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22588. return WC_TEST_RET_ENC_NC;
  22589. wolfSSL_EVP_CIPHER_CTX_init(de);
  22590. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  22591. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22592. return WC_TEST_RET_ENC_NC;
  22593. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22594. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22595. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22596. return WC_TEST_RET_ENC_NC;
  22597. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  22598. return WC_TEST_RET_ENC_NC;
  22599. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  22600. return WC_TEST_RET_ENC_NC;
  22601. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22602. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22603. #endif /* WOLFSSL_AES_192 */
  22604. #ifdef WOLFSSL_AES_256
  22605. wolfSSL_EVP_CIPHER_CTX_init(en);
  22606. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  22607. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22608. return WC_TEST_RET_ENC_NC;
  22609. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  22610. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22611. return WC_TEST_RET_ENC_NC;
  22612. wolfSSL_EVP_CIPHER_CTX_init(de);
  22613. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  22614. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22615. return WC_TEST_RET_ENC_NC;
  22616. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22617. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22618. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22619. return WC_TEST_RET_ENC_NC;
  22620. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  22621. return WC_TEST_RET_ENC_NC;
  22622. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  22623. return WC_TEST_RET_ENC_NC;
  22624. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22625. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22626. #endif /* WOLFSSL_AES_256 */
  22627. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22628. wolfSSL_EVP_CIPHER_CTX_free(en);
  22629. wolfSSL_EVP_CIPHER_CTX_free(de);
  22630. #endif
  22631. }
  22632. #endif /* HAVE_AES_COUNTER */
  22633. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22634. {
  22635. /* EVP_CipherUpdate test */
  22636. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  22637. {
  22638. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22639. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22640. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22641. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22642. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22643. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22644. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22645. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22646. };
  22647. byte key[] = "0123456789abcdef "; /* align */
  22648. byte iv[] = "1234567890abcdef "; /* align */
  22649. byte cipher[AES_BLOCK_SIZE * 4];
  22650. byte plain [AES_BLOCK_SIZE * 4];
  22651. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22652. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22653. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22654. #else
  22655. WOLFSSL_EVP_CIPHER_CTX en[1];
  22656. WOLFSSL_EVP_CIPHER_CTX de[1];
  22657. #endif
  22658. int outlen ;
  22659. int total = 0;
  22660. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22661. if ((en == NULL) || (de == NULL))
  22662. return MEMORY_E;
  22663. #endif
  22664. wolfSSL_EVP_CIPHER_CTX_init(en);
  22665. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22666. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22667. return WC_TEST_RET_ENC_NC;
  22668. /* openSSL compatibility, if(inlen == 0)return 1; */
  22669. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22670. (byte*)cbcPlain, 0) != 1)
  22671. return WC_TEST_RET_ENC_NC;
  22672. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22673. return WC_TEST_RET_ENC_NC;
  22674. wolfSSL_EVP_CIPHER_CTX_init(en);
  22675. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22676. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22677. return WC_TEST_RET_ENC_NC;
  22678. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22679. (byte*)cbcPlain, 9) == 0)
  22680. return WC_TEST_RET_ENC_NC;
  22681. if(outlen != 0)
  22682. return WC_TEST_RET_ENC_NC;
  22683. total += outlen;
  22684. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  22685. (byte*)&cbcPlain[9] , 9) == 0)
  22686. return WC_TEST_RET_ENC_NC;
  22687. if(outlen != 16)
  22688. return WC_TEST_RET_ENC_NC;
  22689. total += outlen;
  22690. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22691. return WC_TEST_RET_ENC_NC;
  22692. if(outlen != 16)
  22693. return WC_TEST_RET_ENC_NC;
  22694. total += outlen;
  22695. if(total != 32)
  22696. return WC_TEST_RET_ENC_NC;
  22697. total = 0;
  22698. wolfSSL_EVP_CIPHER_CTX_init(de);
  22699. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  22700. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22701. return WC_TEST_RET_ENC_NC;
  22702. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22703. return WC_TEST_RET_ENC_NC;
  22704. if(outlen != 0)
  22705. return WC_TEST_RET_ENC_NC;
  22706. total += outlen;
  22707. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22708. (byte*)&cipher[6], 12) == 0)
  22709. return WC_TEST_RET_ENC_NC;
  22710. if(outlen != 0)
  22711. total += outlen;
  22712. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22713. (byte*)&cipher[6+12], 14) == 0)
  22714. return WC_TEST_RET_ENC_NC;
  22715. if(outlen != 16)
  22716. return WC_TEST_RET_ENC_NC;
  22717. total += outlen;
  22718. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  22719. return WC_TEST_RET_ENC_NC;
  22720. if(outlen != 2)
  22721. return WC_TEST_RET_ENC_NC;
  22722. total += outlen;
  22723. if(total != 18)
  22724. return WC_TEST_RET_ENC_NC;
  22725. if (XMEMCMP(plain, cbcPlain, 18))
  22726. return WC_TEST_RET_ENC_NC;
  22727. total = 0;
  22728. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22729. return WC_TEST_RET_ENC_NC;
  22730. wolfSSL_EVP_CIPHER_CTX_init(en);
  22731. if (wolfSSL_EVP_EncryptInit(en, wolfSSL_EVP_aes_128_cbc(),
  22732. (unsigned char*)key, (unsigned char*)iv) == 0)
  22733. return WC_TEST_RET_ENC_NC;
  22734. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0)
  22735. return WC_TEST_RET_ENC_NC;
  22736. if(outlen != 0)
  22737. return WC_TEST_RET_ENC_NC;
  22738. total += outlen;
  22739. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0)
  22740. return WC_TEST_RET_ENC_NC;
  22741. if(outlen != 16)
  22742. return WC_TEST_RET_ENC_NC;
  22743. total += outlen;
  22744. if (wolfSSL_EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22745. return WC_TEST_RET_ENC_NC;
  22746. if(outlen != 16)
  22747. return WC_TEST_RET_ENC_NC;
  22748. total += outlen;
  22749. if(total != 32)
  22750. return 3438;
  22751. total = 0;
  22752. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22753. return WC_TEST_RET_ENC_NC;
  22754. wolfSSL_EVP_CIPHER_CTX_init(de);
  22755. if (wolfSSL_EVP_DecryptInit(de, wolfSSL_EVP_aes_128_cbc(),
  22756. (unsigned char*)key, (unsigned char*)iv) == 0)
  22757. return WC_TEST_RET_ENC_NC;
  22758. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22759. return WC_TEST_RET_ENC_NC;
  22760. if(outlen != 0)
  22761. return WC_TEST_RET_ENC_NC;
  22762. total += outlen;
  22763. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0)
  22764. return WC_TEST_RET_ENC_NC;
  22765. if(outlen != 0)
  22766. total += outlen;
  22767. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0)
  22768. return WC_TEST_RET_ENC_NC;
  22769. if(outlen != 16)
  22770. return WC_TEST_RET_ENC_NC;
  22771. total += outlen;
  22772. if (wolfSSL_EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0)
  22773. return WC_TEST_RET_ENC_NC;
  22774. if(outlen != 2)
  22775. return WC_TEST_RET_ENC_NC;
  22776. total += outlen;
  22777. if(total != 18)
  22778. return 3447;
  22779. if (XMEMCMP(plain, cbcPlain, 18))
  22780. return WC_TEST_RET_ENC_NC;
  22781. if (wolfSSL_EVP_Cipher_key_length(NULL) != 0)
  22782. return WC_TEST_RET_ENC_NC;
  22783. if (wolfSSL_EVP_Cipher_key_length(wolfSSL_EVP_aes_128_cbc()) != 16)
  22784. return WC_TEST_RET_ENC_NC;
  22785. if (wolfSSL_EVP_CIPHER_CTX_mode(NULL) != 0)
  22786. return WC_TEST_RET_ENC_NC;
  22787. if (wolfSSL_EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE))
  22788. return WC_TEST_RET_ENC_NC;
  22789. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22790. return WC_TEST_RET_ENC_NC;
  22791. wolfSSL_EVP_CIPHER_CTX_init(en);
  22792. if (wolfSSL_EVP_CipherInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22793. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22794. return WC_TEST_RET_ENC_NC;
  22795. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22796. return WC_TEST_RET_ENC_NC;
  22797. wolfSSL_EVP_CIPHER_CTX_init(en);
  22798. if (wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22799. (unsigned char*)key, (unsigned char*)iv) == 0)
  22800. return WC_TEST_RET_ENC_NC;
  22801. if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL)
  22802. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22803. {
  22804. return WC_TEST_RET_ENC_NC;
  22805. }
  22806. if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL)
  22807. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22808. {
  22809. return WC_TEST_RET_ENC_NC;
  22810. }
  22811. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22812. return WC_TEST_RET_ENC_NC;
  22813. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22814. return WC_TEST_RET_ENC_NC;
  22815. wolfSSL_EVP_CIPHER_CTX_init(de);
  22816. if (wolfSSL_EVP_DecryptInit_ex(de, wolfSSL_EVP_aes_128_cbc(), NULL,
  22817. (unsigned char*)key, (unsigned char*)iv) == 0)
  22818. return WC_TEST_RET_ENC_NC;
  22819. if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL)
  22820. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22821. {
  22822. return WC_TEST_RET_ENC_NC;
  22823. }
  22824. if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL)
  22825. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22826. {
  22827. return WC_TEST_RET_ENC_NC;
  22828. }
  22829. if (wolfSSL_EVP_CIPHER_CTX_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22830. return WC_TEST_RET_ENC_NC;
  22831. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22832. return WC_TEST_RET_ENC_NC;
  22833. wolfSSL_EVP_CIPHER_CTX_init(en);
  22834. wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22835. (unsigned char*)key, (unsigned char*)iv);
  22836. if (wolfSSL_EVP_CIPHER_CTX_block_size(en) != en->block_size)
  22837. return WC_TEST_RET_ENC_NC;
  22838. if (wolfSSL_EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22839. return WC_TEST_RET_ENC_NC;
  22840. if (wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_128_cbc()) != AES_BLOCK_SIZE)
  22841. return WC_TEST_RET_ENC_NC;
  22842. if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0)
  22843. return WC_TEST_RET_ENC_NC;
  22844. if (wolfSSL_EVP_CIPHER_flags(wolfSSL_EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE)
  22845. return WC_TEST_RET_ENC_NC;
  22846. wolfSSL_EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF);
  22847. wolfSSL_EVP_CIPHER_CTX_set_flags(en, 42);
  22848. if (en->flags != 42)
  22849. return WC_TEST_RET_ENC_NC;
  22850. if (wolfSSL_EVP_CIPHER_CTX_set_padding(NULL, 0) !=
  22851. WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22852. return WC_TEST_RET_ENC_NC;
  22853. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS)
  22854. return WC_TEST_RET_ENC_NC;
  22855. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS)
  22856. return WC_TEST_RET_ENC_NC;
  22857. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22858. return WC_TEST_RET_ENC_NC;
  22859. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22860. return WC_TEST_RET_ENC_NC;
  22861. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22862. wolfSSL_EVP_CIPHER_CTX_free(en);
  22863. wolfSSL_EVP_CIPHER_CTX_free(de);
  22864. #endif
  22865. }
  22866. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22867. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  22868. return 0;
  22869. }
  22870. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void)
  22871. {
  22872. wc_test_ret_t ret = 0;
  22873. #if !defined(NO_SHA256) && !defined(NO_SHA)
  22874. WOLFSSL_EVP_MD_CTX* ctx;
  22875. WOLFSSL_EVP_MD_CTX* ctx2;
  22876. WOLFSSL_ENTER("openSSL_evpMD_test");
  22877. ctx = wolfSSL_EVP_MD_CTX_new();
  22878. ctx2 = wolfSSL_EVP_MD_CTX_new();
  22879. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha256());
  22880. if (ret != WOLFSSL_SUCCESS) {
  22881. ret = WC_TEST_RET_ENC_NC;
  22882. goto openSSL_evpMD_test_done;
  22883. }
  22884. ret = wolfSSL_EVP_MD_CTX_copy(ctx2, ctx);
  22885. if (ret != WOLFSSL_SUCCESS) {
  22886. ret = WC_TEST_RET_ENC_NC;
  22887. goto openSSL_evpMD_test_done;
  22888. }
  22889. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22890. ret = WC_TEST_RET_ENC_NC;
  22891. goto openSSL_evpMD_test_done;
  22892. }
  22893. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha1());
  22894. if (ret != WOLFSSL_SUCCESS) {
  22895. ret = WC_TEST_RET_ENC_NC;
  22896. goto openSSL_evpMD_test_done;
  22897. }
  22898. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22899. ret = WC_TEST_RET_ENC_NC;
  22900. goto openSSL_evpMD_test_done;
  22901. }
  22902. ret = wolfSSL_EVP_MD_CTX_copy_ex(ctx2, ctx);
  22903. if (ret != WOLFSSL_SUCCESS) {
  22904. ret = WC_TEST_RET_ENC_NC;
  22905. goto openSSL_evpMD_test_done;
  22906. }
  22907. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) == wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22908. ret = WC_TEST_RET_ENC_NC;
  22909. goto openSSL_evpMD_test_done;
  22910. }
  22911. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha1()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22912. ret = WC_TEST_RET_ENC_NC;
  22913. goto openSSL_evpMD_test_done;
  22914. }
  22915. if (wolfSSL_EVP_DigestInit_ex(ctx, wolfSSL_EVP_sha1(), NULL) != WOLFSSL_SUCCESS) {
  22916. ret = WC_TEST_RET_ENC_NC;
  22917. goto openSSL_evpMD_test_done;
  22918. }
  22919. if (wolfSSL_EVP_add_digest(NULL) != 0) {
  22920. ret = WC_TEST_RET_ENC_NC;
  22921. goto openSSL_evpMD_test_done;
  22922. }
  22923. if (wolfSSL_EVP_add_cipher(NULL) != 0) {
  22924. ret = WC_TEST_RET_ENC_NC;
  22925. goto openSSL_evpMD_test_done;
  22926. }
  22927. ret = 0; /* got to success state without jumping to end with a fail */
  22928. openSSL_evpMD_test_done:
  22929. wolfSSL_EVP_MD_CTX_free(ctx);
  22930. wolfSSL_EVP_MD_CTX_free(ctx2);
  22931. #endif /* NO_SHA256 */
  22932. return ret;
  22933. }
  22934. #ifdef DEBUG_SIGN
  22935. static void show(const char *title, const char *p, unsigned int s) {
  22936. char* i;
  22937. printf("%s: ", title);
  22938. for (i = p;
  22939. i < p + s;
  22940. printf("%c", *i), i++);
  22941. printf("\n");
  22942. }
  22943. #else
  22944. #define show(a,b,c) WC_DO_NOTHING
  22945. #endif
  22946. #define FOURK_BUFF 4096
  22947. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void)
  22948. {
  22949. wc_test_ret_t ret = 0;
  22950. #if !defined(NO_RSA) && !defined(NO_SHA)
  22951. byte* prvTmp;
  22952. byte* pubTmp;
  22953. int prvBytes;
  22954. int pubBytes;
  22955. WOLFSSL_RSA *prvRsa = NULL;
  22956. WOLFSSL_RSA *pubRsa = NULL;
  22957. WOLFSSL_EVP_PKEY *prvPkey = NULL;
  22958. WOLFSSL_EVP_PKEY *pubPkey = NULL;
  22959. WOLFSSL_EVP_PKEY_CTX *enc = NULL;
  22960. WOLFSSL_EVP_PKEY_CTX *dec = NULL;
  22961. byte in[] = TEST_STRING;
  22962. byte out[256];
  22963. size_t outlen;
  22964. size_t keySz;
  22965. byte plain[256];
  22966. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  22967. XFILE keyFile;
  22968. XFILE keypubFile;
  22969. char cliKey[] = "./certs/client-key.der";
  22970. char cliKeypub[] = "./certs/client-keyPub.der";
  22971. #endif
  22972. WOLFSSL_ENTER("openssl_pkey0_test");
  22973. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22974. if (prvTmp == NULL)
  22975. return WC_TEST_RET_ENC_ERRNO;
  22976. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22977. if (pubTmp == NULL) {
  22978. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22979. return WC_TEST_RET_ENC_NC;
  22980. }
  22981. #ifdef USE_CERT_BUFFERS_1024
  22982. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  22983. prvBytes = sizeof_client_key_der_1024;
  22984. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  22985. pubBytes = sizeof_client_keypub_der_1024;
  22986. #elif defined(USE_CERT_BUFFERS_2048)
  22987. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  22988. prvBytes = sizeof_client_key_der_2048;
  22989. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  22990. pubBytes = sizeof_client_keypub_der_2048;
  22991. #else
  22992. keyFile = XFOPEN(cliKey, "rb");
  22993. if (!keyFile) {
  22994. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22995. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22996. err_sys("can't open ./certs/client-key.der, "
  22997. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  22998. return WC_TEST_RET_ENC_ERRNO;
  22999. }
  23000. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23001. XFCLOSE(keyFile);
  23002. if (prvBytes == 0) {
  23003. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23004. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23005. return WC_TEST_RET_ENC_ERRNO;
  23006. }
  23007. keypubFile = XFOPEN(cliKeypub, "rb");
  23008. if (!keypubFile) {
  23009. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23010. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23011. err_sys("can't open ./certs/client-cert.der, "
  23012. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23013. return WC_TEST_RET_ENC_ERRNO;
  23014. }
  23015. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23016. XFCLOSE(keypubFile);
  23017. if (pubBytes == 0) {
  23018. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23019. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23020. return WC_TEST_RET_ENC_ERRNO;
  23021. }
  23022. #endif /* USE_CERT_BUFFERS */
  23023. prvRsa = wolfSSL_RSA_new();
  23024. pubRsa = wolfSSL_RSA_new();
  23025. if((prvRsa == NULL) || (pubRsa == NULL)){
  23026. printf("error with RSA_new\n");
  23027. ret = WC_TEST_RET_ENC_ERRNO;
  23028. goto openssl_pkey0_test_done;
  23029. }
  23030. ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23031. if(ret != WOLFSSL_SUCCESS){
  23032. printf("error with RSA_LoadDer_ex\n");
  23033. ret = WC_TEST_RET_ENC_EC(ret);
  23034. goto openssl_pkey0_test_done;
  23035. }
  23036. ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23037. if(ret != WOLFSSL_SUCCESS){
  23038. printf("error with RSA_LoadDer_ex\n");
  23039. ret = WC_TEST_RET_ENC_EC(ret);
  23040. goto openssl_pkey0_test_done;
  23041. }
  23042. keySz = (size_t)wolfSSL_RSA_size(pubRsa);
  23043. prvPkey = wolfSSL_EVP_PKEY_new();
  23044. pubPkey = wolfSSL_EVP_PKEY_new();
  23045. if((prvPkey == NULL) || (pubPkey == NULL)){
  23046. printf("error with PKEY_new\n");
  23047. ret = WC_TEST_RET_ENC_NC;
  23048. goto openssl_pkey0_test_done;
  23049. }
  23050. ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23051. ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23052. if(ret != 2){
  23053. printf("error with PKEY_set1_RSA\n");
  23054. ret = WC_TEST_RET_ENC_I(ret);
  23055. goto openssl_pkey0_test_done;
  23056. }
  23057. dec = wolfSSL_EVP_PKEY_CTX_new(prvPkey, NULL);
  23058. enc = wolfSSL_EVP_PKEY_CTX_new(pubPkey, NULL);
  23059. if((dec == NULL)||(enc==NULL)){
  23060. printf("error with EVP_PKEY_CTX_new\n");
  23061. ret = WC_TEST_RET_ENC_NC;
  23062. goto openssl_pkey0_test_done;
  23063. }
  23064. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23065. if (ret != 1) {
  23066. printf("error with decrypt init\n");
  23067. ret = WC_TEST_RET_ENC_NC;
  23068. goto openssl_pkey0_test_done;
  23069. }
  23070. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23071. if (ret != 1) {
  23072. printf("error with encrypt init\n");
  23073. ret = WC_TEST_RET_ENC_NC;
  23074. goto openssl_pkey0_test_done;
  23075. }
  23076. XMEMSET(out, 0, sizeof(out));
  23077. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23078. if (ret != 1) {
  23079. printf("error encrypting msg\n");
  23080. ret = WC_TEST_RET_ENC_NC;
  23081. goto openssl_pkey0_test_done;
  23082. }
  23083. show("encrypted msg", out, outlen);
  23084. XMEMSET(plain, 0, sizeof(plain));
  23085. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23086. if (ret != 1) {
  23087. printf("error decrypting msg\n");
  23088. ret = WC_TEST_RET_ENC_NC;
  23089. goto openssl_pkey0_test_done;
  23090. }
  23091. show("decrypted msg", plain, outlen);
  23092. /* RSA_PKCS1_OAEP_PADDING test */
  23093. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23094. if (ret != 1) {
  23095. printf("error with decrypt init\n");
  23096. ret = WC_TEST_RET_ENC_NC;
  23097. goto openssl_pkey0_test_done;
  23098. }
  23099. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23100. if (ret != 1) {
  23101. printf("error with encrypt init\n");
  23102. ret = WC_TEST_RET_ENC_NC;
  23103. goto openssl_pkey0_test_done;
  23104. }
  23105. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23106. printf("first set rsa padding error\n");
  23107. ret = WC_TEST_RET_ENC_EC(ret);
  23108. goto openssl_pkey0_test_done;
  23109. }
  23110. #ifndef HAVE_FIPS
  23111. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23112. printf("second set rsa padding error\n");
  23113. ret = WC_TEST_RET_ENC_EC(ret);
  23114. goto openssl_pkey0_test_done;
  23115. }
  23116. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23117. printf("third set rsa padding error\n");
  23118. ret = WC_TEST_RET_ENC_EC(ret);
  23119. goto openssl_pkey0_test_done;
  23120. }
  23121. #endif
  23122. XMEMSET(out, 0, sizeof(out));
  23123. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23124. if (ret != 1) {
  23125. printf("error encrypting msg\n");
  23126. ret = WC_TEST_RET_ENC_NC;
  23127. goto openssl_pkey0_test_done;
  23128. }
  23129. show("encrypted msg", out, outlen);
  23130. XMEMSET(plain, 0, sizeof(plain));
  23131. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23132. if (ret != 1) {
  23133. printf("error decrypting msg\n");
  23134. ret = WC_TEST_RET_ENC_NC;
  23135. goto openssl_pkey0_test_done;
  23136. }
  23137. show("decrypted msg", plain, outlen);
  23138. ret = 0; /* made it to this point without error then set success */
  23139. openssl_pkey0_test_done:
  23140. wolfSSL_RSA_free(prvRsa);
  23141. wolfSSL_RSA_free(pubRsa);
  23142. wolfSSL_EVP_PKEY_free(pubPkey);
  23143. wolfSSL_EVP_PKEY_free(prvPkey);
  23144. wolfSSL_EVP_PKEY_CTX_free(dec);
  23145. wolfSSL_EVP_PKEY_CTX_free(enc);
  23146. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23147. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23148. #endif /* NO_RSA */
  23149. return ret;
  23150. }
  23151. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void)
  23152. {
  23153. wc_test_ret_t ret = 0;
  23154. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_SHA)
  23155. WOLFSSL_EVP_PKEY_CTX* dec = NULL;
  23156. WOLFSSL_EVP_PKEY_CTX* enc = NULL;
  23157. WOLFSSL_EVP_PKEY* pubKey = NULL;
  23158. WOLFSSL_EVP_PKEY* prvKey = NULL;
  23159. WOLFSSL_X509* x509 = NULL;
  23160. WOLFSSL_SMALL_STACK_STATIC const unsigned char msg[] = "sugar slapped";
  23161. const unsigned char* clikey;
  23162. long cliKeySz;
  23163. size_t outlen;
  23164. int keyLenBits = 2048;
  23165. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23166. unsigned char *tmp = (unsigned char *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23167. unsigned char *cipher = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23168. unsigned char *plain = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23169. if ((tmp == NULL) ||
  23170. (cipher == NULL) ||
  23171. (plain == NULL)) {
  23172. ret = WC_TEST_RET_ENC_NC;
  23173. goto openssl_pkey1_test_done;
  23174. }
  23175. #else
  23176. unsigned char tmp[FOURK_BUF];
  23177. unsigned char cipher[RSA_TEST_BYTES];
  23178. unsigned char plain[RSA_TEST_BYTES];
  23179. #endif
  23180. WOLFSSL_ENTER("openssl_pkey1_test");
  23181. #if defined(USE_CERT_BUFFERS_1024)
  23182. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  23183. cliKeySz = (long)sizeof_client_key_der_1024;
  23184. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_1024,
  23185. sizeof_client_cert_der_1024, SSL_FILETYPE_ASN1);
  23186. keyLenBits = 1024;
  23187. #elif defined(USE_CERT_BUFFERS_2048)
  23188. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  23189. cliKeySz = (long)sizeof_client_key_der_2048;
  23190. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048,
  23191. sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1);
  23192. #elif defined(USE_CERT_BUFFERS_3072)
  23193. XMEMCPY(tmp, client_key_der_3072, sizeof_client_key_der_3072);
  23194. cliKeySz = (long)sizeof_client_key_der_3072;
  23195. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_3072,
  23196. sizeof_client_cert_der_3072, SSL_FILETYPE_ASN1);
  23197. keyLenBits = 3072;
  23198. #elif defined(USE_CERT_BUFFERS_4096)
  23199. XMEMCPY(tmp, client_key_der_4096, sizeof_client_key_der_4096);
  23200. cliKeySz = (long)sizeof_client_key_der_4096;
  23201. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_4096,
  23202. sizeof_client_cert_der_4096, SSL_FILETYPE_ASN1);
  23203. keyLenBits = 4096;
  23204. #else
  23205. {
  23206. XFILE f;
  23207. f = XFOPEN(clientKey, "rb");
  23208. if (!f) {
  23209. err_sys("can't open ./certs/client-key.der, "
  23210. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23211. ret = WC_TEST_RET_ENC_ERRNO;
  23212. goto openssl_pkey1_test_done;
  23213. }
  23214. cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f);
  23215. XFCLOSE(f);
  23216. if (cliKeySz == 0)
  23217. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done);
  23218. }
  23219. /* using existing wolfSSL api to get public and private key */
  23220. x509 = wolfSSL_X509_load_certificate_file(clientCert, WOLFSSL_FILETYPE_ASN1);
  23221. #endif /* USE_CERT_BUFFERS */
  23222. clikey = tmp;
  23223. if ((prvKey = wolfSSL_EVP_PKEY_new()) == NULL) {
  23224. ret = WC_TEST_RET_ENC_ERRNO;
  23225. goto openssl_pkey1_test_done;
  23226. }
  23227. wolfSSL_EVP_PKEY_free(prvKey);
  23228. prvKey = NULL;
  23229. if (x509 == NULL) {
  23230. ret = WC_TEST_RET_ENC_NC;
  23231. goto openssl_pkey1_test_done;
  23232. }
  23233. pubKey = wolfSSL_X509_get_pubkey(x509);
  23234. if (pubKey == NULL) {
  23235. ret = WC_TEST_RET_ENC_NC;
  23236. goto openssl_pkey1_test_done;
  23237. }
  23238. prvKey = wolfSSL_d2i_PrivateKey(WC_EVP_PKEY_RSA, NULL, &clikey, cliKeySz);
  23239. if (prvKey == NULL) {
  23240. ret = WC_TEST_RET_ENC_NC;
  23241. goto openssl_pkey1_test_done;
  23242. }
  23243. /* phase 2 API to create WOLFSSL_EVP_PKEY_CTX and encrypt/decrypt */
  23244. if (wolfSSL_EVP_PKEY_bits(prvKey) != keyLenBits) {
  23245. ret = WC_TEST_RET_ENC_NC;
  23246. goto openssl_pkey1_test_done;
  23247. }
  23248. if (wolfSSL_EVP_PKEY_size(prvKey) != keyLenBits/8) {
  23249. ret = WC_TEST_RET_ENC_NC;
  23250. goto openssl_pkey1_test_done;
  23251. }
  23252. dec = wolfSSL_EVP_PKEY_CTX_new(prvKey, NULL);
  23253. enc = wolfSSL_EVP_PKEY_CTX_new(pubKey, NULL);
  23254. if (dec == NULL || enc == NULL) {
  23255. ret = WC_TEST_RET_ENC_ERRNO;
  23256. goto openssl_pkey1_test_done;
  23257. }
  23258. if (wolfSSL_EVP_PKEY_decrypt_init(dec) != 1) {
  23259. ret = WC_TEST_RET_ENC_NC;
  23260. goto openssl_pkey1_test_done;
  23261. }
  23262. if (wolfSSL_EVP_PKEY_encrypt_init(enc) != 1) {
  23263. ret = WC_TEST_RET_ENC_NC;
  23264. goto openssl_pkey1_test_done;
  23265. }
  23266. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23267. ret = WC_TEST_RET_ENC_NC;
  23268. goto openssl_pkey1_test_done;
  23269. }
  23270. #ifndef HAVE_FIPS
  23271. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23272. ret = WC_TEST_RET_ENC_EC(ret);
  23273. goto openssl_pkey1_test_done;
  23274. }
  23275. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23276. ret = WC_TEST_RET_ENC_EC(ret);
  23277. goto openssl_pkey1_test_done;
  23278. }
  23279. #endif
  23280. XMEMSET(cipher, 0, RSA_TEST_BYTES);
  23281. outlen = (size_t)(keyLenBits/8);
  23282. if (wolfSSL_EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) {
  23283. ret = WC_TEST_RET_ENC_EC(ret);
  23284. goto openssl_pkey1_test_done;
  23285. }
  23286. XMEMSET(plain, 0, RSA_TEST_BYTES);
  23287. if (wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) {
  23288. ret = WC_TEST_RET_ENC_NC;
  23289. goto openssl_pkey1_test_done;
  23290. }
  23291. openssl_pkey1_test_done:
  23292. if (pubKey != NULL) {
  23293. wolfSSL_EVP_PKEY_free(pubKey);
  23294. }
  23295. if (prvKey != NULL) {
  23296. wolfSSL_EVP_PKEY_free(prvKey);
  23297. }
  23298. if (dec != NULL) {
  23299. wolfSSL_EVP_PKEY_CTX_free(dec);
  23300. }
  23301. if (enc != NULL) {
  23302. wolfSSL_EVP_PKEY_CTX_free(enc);
  23303. }
  23304. if (x509 != NULL) {
  23305. wolfSSL_X509_free(x509);
  23306. }
  23307. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23308. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23309. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23310. XFREE(plain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23311. #endif
  23312. #endif
  23313. return ret;
  23314. }
  23315. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void)
  23316. {
  23317. #if !defined(NO_RSA) && !defined(NO_SHA)
  23318. byte* prvTmp;
  23319. byte* pubTmp;
  23320. int prvBytes;
  23321. int pubBytes;
  23322. WOLFSSL_RSA *prvRsa;
  23323. WOLFSSL_RSA *pubRsa;
  23324. WOLFSSL_EVP_PKEY *prvPkey;
  23325. WOLFSSL_EVP_PKEY *pubPkey;
  23326. WOLFSSL_EVP_MD_CTX* sign;
  23327. WOLFSSL_EVP_MD_CTX* verf;
  23328. char msg[] = "see spot run";
  23329. unsigned char sig[256];
  23330. unsigned int sigSz;
  23331. const void* pt;
  23332. unsigned int count;
  23333. wc_test_ret_t ret, ret1, ret2;
  23334. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  23335. XFILE keyFile;
  23336. XFILE keypubFile;
  23337. char cliKey[] = "./certs/client-key.der";
  23338. char cliKeypub[] = "./certs/client-keyPub.der";
  23339. #endif
  23340. WOLFSSL_ENTER("openssl_evpSig_test");
  23341. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23342. if (prvTmp == NULL)
  23343. return WC_TEST_RET_ENC_ERRNO;
  23344. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23345. if (pubTmp == NULL) {
  23346. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23347. return WC_TEST_RET_ENC_NC;
  23348. }
  23349. #ifdef USE_CERT_BUFFERS_1024
  23350. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  23351. prvBytes = sizeof_client_key_der_1024;
  23352. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  23353. pubBytes = sizeof_client_keypub_der_1024;
  23354. #elif defined(USE_CERT_BUFFERS_2048)
  23355. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  23356. prvBytes = sizeof_client_key_der_2048;
  23357. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  23358. pubBytes = sizeof_client_keypub_der_2048;
  23359. #else
  23360. keyFile = XFOPEN(cliKey, "rb");
  23361. if (!keyFile) {
  23362. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23363. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23364. err_sys("can't open ./certs/client-key.der, "
  23365. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23366. return WC_TEST_RET_ENC_ERRNO;
  23367. }
  23368. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23369. XFCLOSE(keyFile);
  23370. if (prvBytes == 0) {
  23371. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23372. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23373. return WC_TEST_RET_ENC_ERRNO;
  23374. }
  23375. keypubFile = XFOPEN(cliKeypub, "rb");
  23376. if (!keypubFile) {
  23377. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23378. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23379. err_sys("can't open ./certs/client-cert.der, "
  23380. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23381. return WC_TEST_RET_ENC_ERRNO;
  23382. }
  23383. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23384. XFCLOSE(keypubFile);
  23385. if (pubBytes == 0) {
  23386. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23387. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23388. return WC_TEST_RET_ENC_ERRNO;
  23389. }
  23390. #endif /* USE_CERT_BUFFERS */
  23391. prvRsa = wolfSSL_RSA_new();
  23392. pubRsa = wolfSSL_RSA_new();
  23393. if((prvRsa == NULL) || (pubRsa == NULL)){
  23394. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23395. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23396. err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC);
  23397. return WC_TEST_RET_ENC_NC;
  23398. }
  23399. ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23400. ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23401. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23402. printf("error with RSA_LoadDer_ex\n");
  23403. return WC_TEST_RET_ENC_NC;
  23404. }
  23405. prvPkey = wolfSSL_EVP_PKEY_new();
  23406. pubPkey = wolfSSL_EVP_PKEY_new();
  23407. if((prvPkey == NULL) || (pubPkey == NULL)){
  23408. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23409. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23410. printf("error with KEY_new\n");
  23411. return WC_TEST_RET_ENC_NC;
  23412. }
  23413. ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23414. ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23415. if((ret1 != 1) || (ret2 != 1)){
  23416. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23417. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23418. printf("error with WOLFSSL_EVP_PKEY_set1_RSA\n");
  23419. return WC_TEST_RET_ENC_NC;
  23420. }
  23421. /****************** sign and verify *******************/
  23422. sign = wolfSSL_EVP_MD_CTX_new();
  23423. verf = wolfSSL_EVP_MD_CTX_new();
  23424. if((sign == NULL)||(verf == NULL)){
  23425. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23426. wolfSSL_EVP_MD_CTX_free(sign);
  23427. wolfSSL_EVP_MD_CTX_free(verf);
  23428. return WC_TEST_RET_ENC_NC;
  23429. }
  23430. ret = wolfSSL_EVP_SignInit(sign, wolfSSL_EVP_sha1());
  23431. if (ret != WOLFSSL_SUCCESS){
  23432. printf("error with EVP_SignInit\n");
  23433. wolfSSL_EVP_MD_CTX_free(sign);
  23434. wolfSSL_EVP_MD_CTX_free(verf);
  23435. return WC_TEST_RET_ENC_NC;
  23436. }
  23437. count = sizeof(msg);
  23438. show("message = ", (char *)msg, count);
  23439. /* sign */
  23440. XMEMSET(sig, 0, sizeof(sig));
  23441. pt = (const void*)msg;
  23442. ret1 = wolfSSL_EVP_SignUpdate(sign, pt, count);
  23443. ret2 = wolfSSL_EVP_SignFinal(sign, sig, &sigSz, prvPkey);
  23444. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23445. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23446. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23447. wolfSSL_EVP_MD_CTX_free(sign);
  23448. wolfSSL_EVP_MD_CTX_free(verf);
  23449. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23450. return WC_TEST_RET_ENC_NC;
  23451. }
  23452. show("signature = ", (char *)sig, sigSz);
  23453. /* verify */
  23454. pt = (const void*)msg;
  23455. ret1 = wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23456. ret2 = wolfSSL_EVP_VerifyUpdate(verf, pt, count);
  23457. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23458. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23459. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23460. wolfSSL_EVP_MD_CTX_free(sign);
  23461. wolfSSL_EVP_MD_CTX_free(verf);
  23462. printf("error with EVP_Verify\n");
  23463. return WC_TEST_RET_ENC_NC;
  23464. }
  23465. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) {
  23466. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23467. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23468. wolfSSL_EVP_MD_CTX_free(sign);
  23469. wolfSSL_EVP_MD_CTX_free(verf);
  23470. printf("error with EVP_VerifyFinal\n");
  23471. return WC_TEST_RET_ENC_NC;
  23472. }
  23473. /* expect fail without update */
  23474. wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23475. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) {
  23476. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23477. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23478. wolfSSL_EVP_MD_CTX_free(sign);
  23479. wolfSSL_EVP_MD_CTX_free(verf);
  23480. printf("EVP_VerifyInit without update not detected\n");
  23481. return WC_TEST_RET_ENC_NC;
  23482. }
  23483. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23484. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23485. wolfSSL_EVP_MD_CTX_free(sign);
  23486. wolfSSL_EVP_MD_CTX_free(verf);
  23487. wolfSSL_RSA_free(prvRsa);
  23488. wolfSSL_RSA_free(pubRsa);
  23489. wolfSSL_EVP_PKEY_free(pubPkey);
  23490. wolfSSL_EVP_PKEY_free(prvPkey);
  23491. #endif /* NO_RSA */
  23492. return 0;
  23493. }
  23494. #endif /* OPENSSL_EXTRA */
  23495. #ifndef NO_PWDBASED
  23496. #ifdef HAVE_SCRYPT
  23497. /* Test vectors taken from RFC 7914: scrypt PBKDF - Section 12. */
  23498. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
  23499. {
  23500. #ifdef HAVE_FIPS
  23501. /* RFC 7914 test vector keys are too short for FIPS. */
  23502. #else
  23503. wc_test_ret_t ret;
  23504. byte derived[64];
  23505. WOLFSSL_SMALL_STACK_STATIC const byte verify1[] = {
  23506. 0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20,
  23507. 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97,
  23508. 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8,
  23509. 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42,
  23510. 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8,
  23511. 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17,
  23512. 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28,
  23513. 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06
  23514. };
  23515. #if !defined(BENCH_EMBEDDED)
  23516. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23517. 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00,
  23518. 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe,
  23519. 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30,
  23520. 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62,
  23521. 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88,
  23522. 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda,
  23523. 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d,
  23524. 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40
  23525. };
  23526. #endif
  23527. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23528. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  23529. 0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48,
  23530. 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb,
  23531. 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e,
  23532. 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2,
  23533. 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf,
  23534. 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9,
  23535. 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40,
  23536. 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87
  23537. };
  23538. #endif
  23539. #ifdef SCRYPT_TEST_ALL
  23540. /* Test case is very slow.
  23541. * Use for confirmation after code change or new platform.
  23542. */
  23543. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  23544. 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae,
  23545. 0xad, 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81,
  23546. 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d,
  23547. 0xab, 0xe5, 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47,
  23548. 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, 0x9f,
  23549. 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3,
  23550. 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, 0x52, 0xfb,
  23551. 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4
  23552. };
  23553. #endif
  23554. WOLFSSL_ENTER("scrypt_test");
  23555. ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1));
  23556. if (ret != 0)
  23557. return WC_TEST_RET_ENC_EC(ret);
  23558. if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0)
  23559. return WC_TEST_RET_ENC_NC;
  23560. #if !defined(BENCH_EMBEDDED)
  23561. ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16,
  23562. sizeof(verify2));
  23563. if (ret != 0)
  23564. return WC_TEST_RET_ENC_EC(ret);
  23565. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23566. return WC_TEST_RET_ENC_NC;
  23567. #endif
  23568. /* Test case with parallel overflowing */
  23569. ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608,
  23570. sizeof(verify1));
  23571. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  23572. return WC_TEST_RET_ENC_EC(ret);
  23573. /* Don't run these test on embedded, since they use large mallocs */
  23574. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23575. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23576. (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3));
  23577. if (ret != 0)
  23578. return WC_TEST_RET_ENC_EC(ret);
  23579. if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0)
  23580. return WC_TEST_RET_ENC_NC;
  23581. #ifdef SCRYPT_TEST_ALL
  23582. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23583. (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4));
  23584. if (ret != 0)
  23585. return WC_TEST_RET_ENC_EC(ret);
  23586. if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0)
  23587. return WC_TEST_RET_ENC_NC;
  23588. #endif
  23589. #else
  23590. #ifdef SCRYPT_TEST_ALL
  23591. (void)verify4;
  23592. #endif
  23593. #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
  23594. #if !defined(BENCH_EMBEDDED)
  23595. ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10,
  23596. 8, 16, sizeof(verify2));
  23597. if (ret != 0)
  23598. return WC_TEST_RET_ENC_EC(ret);
  23599. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23600. return WC_TEST_RET_ENC_NC;
  23601. #endif
  23602. #endif /* !HAVE_FIPS */
  23603. return 0;
  23604. }
  23605. #endif
  23606. #ifdef HAVE_PKCS12
  23607. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void)
  23608. {
  23609. WOLFSSL_SMALL_STACK_STATIC const byte passwd[] = { 0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
  23610. 0x00, 0x00 };
  23611. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f };
  23612. WOLFSSL_SMALL_STACK_STATIC const byte passwd2[] = { 0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
  23613. 0x00, 0x67, 0x00, 0x00 };
  23614. WOLFSSL_SMALL_STACK_STATIC const byte salt2[] = { 0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5 };
  23615. byte derived[64];
  23616. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23617. 0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
  23618. 0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
  23619. 0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
  23620. };
  23621. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23622. 0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
  23623. 0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
  23624. 0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
  23625. };
  23626. int id = 1;
  23627. int kLen = 24;
  23628. int iterations = 1;
  23629. wc_test_ret_t ret;
  23630. WOLFSSL_ENTER("pkcs12_pbkdf_test");
  23631. ret = wc_PKCS12_PBKDF(derived, passwd, sizeof(passwd), salt, 8,
  23632. iterations, kLen, WC_SHA256, id);
  23633. if (ret < 0)
  23634. return WC_TEST_RET_ENC_EC(ret);
  23635. if (XMEMCMP(derived, verify, (unsigned long)kLen) != 0)
  23636. return WC_TEST_RET_ENC_NC;
  23637. iterations = 1000;
  23638. ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8,
  23639. iterations, kLen, WC_SHA256, id);
  23640. if (ret < 0)
  23641. return WC_TEST_RET_ENC_EC(ret);
  23642. ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8,
  23643. iterations, kLen, WC_SHA256, id, HEAP_HINT);
  23644. if (ret < 0)
  23645. return WC_TEST_RET_ENC_EC(ret);
  23646. if (XMEMCMP(derived, verify2, 24) != 0)
  23647. return WC_TEST_RET_ENC_NC;
  23648. return 0;
  23649. }
  23650. #endif /* HAVE_PKCS12 */
  23651. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23652. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
  23653. {
  23654. char passwd[] = "passwordpassword";
  23655. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a,
  23656. 0x5d, 0x63, 0xcb, 0x06 };
  23657. int iterations = 2048;
  23658. int kLen = 24;
  23659. byte derived[64];
  23660. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23661. 0x43, 0x6d, 0xb5, 0xe8, 0xd0, 0xfb, 0x3f, 0x35, 0x42, 0x48, 0x39, 0xbc,
  23662. 0x2d, 0xd4, 0xf9, 0x37, 0xd4, 0x95, 0x16, 0xa7, 0x2a, 0x9a, 0x21, 0xd1
  23663. };
  23664. wc_test_ret_t ret;
  23665. WOLFSSL_ENTER("pbkdf2_test");
  23666. ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
  23667. salt, (int)sizeof(salt), iterations,
  23668. kLen, WC_SHA256, HEAP_HINT, devId);
  23669. if (ret != 0)
  23670. return WC_TEST_RET_ENC_EC(ret);
  23671. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23672. return WC_TEST_RET_ENC_NC;
  23673. return 0;
  23674. }
  23675. #endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
  23676. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23677. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void)
  23678. {
  23679. char passwd[] = "password";
  23680. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  23681. int iterations = 1000;
  23682. int kLen = 16;
  23683. byte derived[16];
  23684. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23685. 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F,
  23686. 0xAF, 0x10, 0xEB, 0xFB, 0x4A, 0x3D, 0x2A, 0x20
  23687. };
  23688. wc_test_ret_t ret;
  23689. WOLFSSL_ENTER("pbkdf1_test");
  23690. ret = wc_PBKDF1_ex(derived, kLen, NULL, 0, (byte*)passwd,
  23691. (int)XSTRLEN(passwd), salt, (int)sizeof(salt), iterations, WC_SHA,
  23692. HEAP_HINT);
  23693. if (ret != 0)
  23694. return ret;
  23695. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23696. return WC_TEST_RET_ENC_NC;
  23697. return 0;
  23698. }
  23699. #endif /* HAVE_PBKDF2 && !NO_SHA */
  23700. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void)
  23701. {
  23702. wc_test_ret_t ret = 0;
  23703. WOLFSSL_ENTER("pwdbased_test");
  23704. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23705. ret = pbkdf1_test();
  23706. if (ret != 0)
  23707. return ret;
  23708. #endif
  23709. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23710. ret = pbkdf2_test();
  23711. if (ret != 0)
  23712. return ret;
  23713. #endif
  23714. #ifdef HAVE_PKCS12
  23715. ret = pkcs12_pbkdf_test();
  23716. if (ret != 0)
  23717. return ret;
  23718. #endif
  23719. #ifdef HAVE_SCRYPT
  23720. ret = scrypt_test();
  23721. if (ret != 0)
  23722. return ret;
  23723. #endif
  23724. return ret;
  23725. }
  23726. #endif /* NO_PWDBASED */
  23727. #if defined(USE_CERT_BUFFERS_2048) && \
  23728. defined(HAVE_PKCS12) && \
  23729. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  23730. !defined(NO_CERTS) && !defined(NO_DES3)
  23731. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
  23732. {
  23733. wc_test_ret_t ret = 0;
  23734. WC_PKCS12* pkcs12 = NULL;
  23735. /* Gen vars */
  23736. byte* pkcs12der = NULL;
  23737. int pkcs12derSz = 0;
  23738. WC_DerCertList derCaList = {
  23739. (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
  23740. };
  23741. char* pass = (char*)"wolfSSL test";
  23742. /* Parsing vars */
  23743. WC_DerCertList* derCaListOut = NULL;
  23744. byte* keyDer = NULL;
  23745. byte* certDer = NULL;
  23746. word32 keySz;
  23747. word32 certSz;
  23748. WOLFSSL_ENTER("pkcs12_test");
  23749. pkcs12 = wc_PKCS12_create(pass, (word32)XSTRLEN(pass),
  23750. (char*)"friendlyName" /* not used currently */,
  23751. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  23752. (byte*)server_cert_der_2048, sizeof_server_cert_der_2048,
  23753. &derCaList, PBE_SHA1_DES3, PBE_SHA1_DES3, 100, 100,
  23754. 0 /* not used currently */, HEAP_HINT);
  23755. if (pkcs12 == NULL) {
  23756. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23757. goto out;
  23758. }
  23759. ret = wc_i2d_PKCS12(pkcs12, NULL, &pkcs12derSz);
  23760. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  23761. if (ret == 0)
  23762. ret = WC_TEST_RET_ENC_NC;
  23763. else
  23764. ret = WC_TEST_RET_ENC_I(ret);
  23765. goto out;
  23766. }
  23767. pkcs12der = (byte*)XMALLOC(pkcs12derSz, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23768. if (pkcs12der == NULL) {
  23769. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23770. goto out;
  23771. }
  23772. {
  23773. /* Use tmp pointer to avoid advancing pkcs12der */
  23774. byte* tmp = pkcs12der;
  23775. ret = wc_i2d_PKCS12(pkcs12, &tmp, &pkcs12derSz);
  23776. if (ret <= 0) {
  23777. if (ret == 0)
  23778. ret = WC_TEST_RET_ENC_NC;
  23779. else
  23780. ret = WC_TEST_RET_ENC_I(ret);
  23781. goto out;
  23782. }
  23783. }
  23784. wc_PKCS12_free(pkcs12);
  23785. pkcs12 = wc_PKCS12_new_ex(HEAP_HINT);
  23786. if (pkcs12 == NULL) {
  23787. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23788. goto out;
  23789. }
  23790. /* convert the DER file into an internal structure */
  23791. ret = wc_d2i_PKCS12(pkcs12der, pkcs12derSz, pkcs12);
  23792. if (ret != 0) {
  23793. ret = WC_TEST_RET_ENC_EC(ret);
  23794. goto out;
  23795. }
  23796. /* parse the internal structure into its parts */
  23797. ret = wc_PKCS12_parse(pkcs12, "wolfSSL test", &keyDer, &keySz,
  23798. &certDer, &certSz, &derCaListOut);
  23799. if (ret != 0) {
  23800. ret = WC_TEST_RET_ENC_EC(ret);
  23801. goto out;
  23802. }
  23803. if (keyDer == NULL || certDer == NULL || derCaListOut == NULL) {
  23804. ret = WC_TEST_RET_ENC_NC;
  23805. goto out;
  23806. }
  23807. out:
  23808. if (derCaListOut)
  23809. wc_FreeCertList(derCaListOut, HEAP_HINT);
  23810. XFREE(keyDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23811. XFREE(certDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23812. if (pkcs12)
  23813. wc_PKCS12_free(pkcs12);
  23814. XFREE(pkcs12der, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23815. return ret;
  23816. }
  23817. #endif
  23818. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  23819. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  23820. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  23821. defined(WOLFSSL_AFALG_XILINX_RSA)
  23822. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  23823. static wc_test_ret_t hkdf_test(void)
  23824. #else
  23825. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void)
  23826. #endif
  23827. {
  23828. wc_test_ret_t ret = 0;
  23829. #if !defined(NO_SHA) || !defined(NO_SHA256)
  23830. int L;
  23831. byte okm1[42];
  23832. byte ikm1[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23833. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23834. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  23835. #ifndef HAVE_FIPS
  23836. byte salt1[13] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  23837. 0x08, 0x09, 0x0a, 0x0b, 0x0c };
  23838. byte info1[10] ={ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  23839. 0xf8, 0xf9 };
  23840. #endif
  23841. #ifndef NO_SHA
  23842. byte res1[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
  23843. 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
  23844. 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
  23845. 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
  23846. 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
  23847. 0x49, 0x18 };
  23848. #ifndef HAVE_FIPS
  23849. byte res2[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
  23850. 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
  23851. 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
  23852. 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
  23853. 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
  23854. 0xf8, 0x96 };
  23855. #endif
  23856. #endif /* !NO_SHA */
  23857. #ifndef NO_SHA256
  23858. byte res3[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
  23859. 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
  23860. 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
  23861. 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
  23862. 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
  23863. 0x96, 0xc8 };
  23864. #ifndef HAVE_FIPS
  23865. byte res4[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
  23866. 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
  23867. 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
  23868. 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
  23869. 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
  23870. 0x58, 0x65 };
  23871. #endif
  23872. #endif /* !NO_SHA256 */
  23873. WOLFSSL_ENTER("hkdf_test");
  23874. XMEMSET(okm1, 0, sizeof(okm1));
  23875. L = (int)sizeof(okm1);
  23876. #ifndef NO_SHA
  23877. ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23878. okm1, (word32)L);
  23879. if (ret != 0)
  23880. return WC_TEST_RET_ENC_EC(ret);
  23881. if (XMEMCMP(okm1, res1, (unsigned long)L) != 0)
  23882. return WC_TEST_RET_ENC_NC;
  23883. #ifndef HAVE_FIPS
  23884. /* fips can't have key size under 14 bytes, salt is key too */
  23885. L = (int)sizeof(okm1);
  23886. ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1),
  23887. info1, (word32)sizeof(info1), okm1, (word32)L);
  23888. if (ret != 0)
  23889. return WC_TEST_RET_ENC_EC(ret);
  23890. if (XMEMCMP(okm1, res2, (unsigned long)L) != 0)
  23891. return WC_TEST_RET_ENC_NC;
  23892. #endif /* HAVE_FIPS */
  23893. #endif /* !NO_SHA */
  23894. #ifndef NO_SHA256
  23895. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23896. okm1, (word32)L);
  23897. if (ret != 0)
  23898. return WC_TEST_RET_ENC_EC(ret);
  23899. if (XMEMCMP(okm1, res3, (unsigned long)L) != 0)
  23900. return WC_TEST_RET_ENC_NC;
  23901. #ifndef HAVE_FIPS
  23902. /* fips can't have key size under 14 bytes, salt is key too */
  23903. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1),
  23904. salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, (word32)L);
  23905. if (ret != 0)
  23906. return WC_TEST_RET_ENC_EC(ret);
  23907. if (XMEMCMP(okm1, res4, (unsigned long)L) != 0)
  23908. return WC_TEST_RET_ENC_NC;
  23909. #endif /* HAVE_FIPS */
  23910. #endif /* !NO_SHA256 */
  23911. #endif /* !NO_SHA || !NO_SHA256 */
  23912. return ret;
  23913. }
  23914. #endif /* HAVE_HKDF */
  23915. #ifdef WOLFSSL_WOLFSSH
  23916. typedef struct {
  23917. byte hashId;
  23918. byte keyId;
  23919. const byte* k;
  23920. word32 kSz;
  23921. const byte* h;
  23922. word32 hSz;
  23923. const byte* sessionId;
  23924. word32 sessionIdSz;
  23925. const byte* expectedKey;
  23926. word32 expectedKeySz;
  23927. } SshKdfTestVector;
  23928. /** Test Vector Set #3: SHA-256 **/
  23929. static const byte sshKdfTvSet3k[] = {
  23930. 0x6A, 0xC3, 0x82, 0xEA, 0xAC, 0xA0, 0x93, 0xE1,
  23931. 0x25, 0xE2, 0x5C, 0x24, 0xBE, 0xBC, 0x84, 0x64,
  23932. 0x0C, 0x11, 0x98, 0x75, 0x07, 0x34, 0x4B, 0x5C,
  23933. 0x73, 0x9C, 0xEB, 0x84, 0xA9, 0xE0, 0xB2, 0x22,
  23934. 0xB9, 0xA8, 0xB5, 0x1C, 0x83, 0x9E, 0x5E, 0xBE,
  23935. 0x49, 0xCF, 0xAD, 0xBF, 0xB3, 0x95, 0x99, 0x76,
  23936. 0x4E, 0xD5, 0x22, 0x09, 0x9D, 0xC9, 0x12, 0x75,
  23937. 0x19, 0x50, 0xDC, 0x7D, 0xC9, 0x7F, 0xBD, 0xC0,
  23938. 0x63, 0x28, 0xB6, 0x8F, 0x22, 0x78, 0x1F, 0xD3,
  23939. 0x15, 0xAF, 0x56, 0x80, 0x09, 0xA5, 0x50, 0x9E,
  23940. 0x5B, 0x87, 0xA1, 0x1B, 0xF5, 0x27, 0xC0, 0x56,
  23941. 0xDA, 0xFF, 0xD8, 0x2A, 0xB6, 0xCB, 0xC2, 0x5C,
  23942. 0xCA, 0x37, 0x14, 0x34, 0x59, 0xE7, 0xBC, 0x63,
  23943. 0xBC, 0xDE, 0x52, 0x75, 0x7A, 0xDE, 0xB7, 0xDF,
  23944. 0x01, 0xCF, 0x12, 0x17, 0x3F, 0x1F, 0xEF, 0x81,
  23945. 0x02, 0xEC, 0x5A, 0xB1, 0x42, 0xC2, 0x13, 0xDD,
  23946. 0x9D, 0x30, 0x69, 0x62, 0x78, 0xA8, 0xD8, 0xBC,
  23947. 0x32, 0xDD, 0xE9, 0x59, 0x2D, 0x28, 0xC0, 0x78,
  23948. 0xC6, 0xD9, 0x2B, 0x94, 0x7D, 0x82, 0x5A, 0xCA,
  23949. 0xAB, 0x64, 0x94, 0x84, 0x6A, 0x49, 0xDE, 0x24,
  23950. 0xB9, 0x62, 0x3F, 0x48, 0x89, 0xE8, 0xAD, 0xC3,
  23951. 0x8E, 0x8C, 0x66, 0x9E, 0xFF, 0xEF, 0x17, 0x60,
  23952. 0x40, 0xAD, 0x94, 0x5E, 0x90, 0xA7, 0xD3, 0xEE,
  23953. 0xC1, 0x5E, 0xFE, 0xEE, 0x78, 0xAE, 0x71, 0x04,
  23954. 0x3C, 0x96, 0x51, 0x11, 0x03, 0xA1, 0x6B, 0xA7,
  23955. 0xCA, 0xF0, 0xAC, 0xD0, 0x64, 0x2E, 0xFD, 0xBE,
  23956. 0x80, 0x99, 0x34, 0xFA, 0xA1, 0xA5, 0xF1, 0xBD,
  23957. 0x11, 0x04, 0x36, 0x49, 0xB2, 0x5C, 0xCD, 0x1F,
  23958. 0xEE, 0x2E, 0x38, 0x81, 0x5D, 0x4D, 0x5F, 0x5F,
  23959. 0xC6, 0xB4, 0x10, 0x29, 0x69, 0xF2, 0x1C, 0x22,
  23960. 0xAE, 0x1B, 0x0E, 0x7D, 0x36, 0x03, 0xA5, 0x56,
  23961. 0xA1, 0x32, 0x62, 0xFF, 0x62, 0x8D, 0xE2, 0x22
  23962. };
  23963. static const byte sshKdfTvSet3h[] = {
  23964. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23965. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23966. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23967. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23968. };
  23969. static const byte sshKdfTvSet3sid[] = {
  23970. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23971. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23972. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23973. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23974. };
  23975. static const byte sshKdfTvSet3a[] = {
  23976. 0x81, 0xF0, 0x33, 0x0E, 0xF6, 0xF0, 0x53, 0x61,
  23977. 0xB3, 0x82, 0x3B, 0xFD, 0xED, 0x6E, 0x1D, 0xE9
  23978. };
  23979. static const byte sshKdfTvSet3b[] = {
  23980. 0x3F, 0x6F, 0xD2, 0x06, 0x5E, 0xEB, 0x2B, 0x0B,
  23981. 0x1D, 0x93, 0x19, 0x5A, 0x1F, 0xED, 0x48, 0xA5
  23982. };
  23983. static const byte sshKdfTvSet3c[] = {
  23984. 0xC3, 0x54, 0x71, 0x03, 0x4E, 0x6F, 0xD6, 0x54,
  23985. 0x76, 0x13, 0x17, 0x8E, 0x23, 0x43, 0x5F, 0x21
  23986. };
  23987. static const byte sshKdfTvSet3d[] = {
  23988. 0x7E, 0x9D, 0x79, 0x03, 0x20, 0x90, 0xD9, 0x9F,
  23989. 0x98, 0xB0, 0x15, 0x63, 0x4D, 0xD9, 0xF4, 0x62
  23990. };
  23991. static const byte sshKdfTvSet3e[] = {
  23992. 0x24, 0xEE, 0x55, 0x9A, 0xD7, 0xCE, 0x71, 0x2B,
  23993. 0x68, 0x5D, 0x0B, 0x22, 0x71, 0xE4, 0x43, 0xC1,
  23994. 0x7A, 0xB1, 0xD1, 0xDC, 0xEB, 0x5A, 0x36, 0x05,
  23995. 0x69, 0xD2, 0x5D, 0x5D, 0xC2, 0x43, 0x00, 0x2F
  23996. };
  23997. static const byte sshKdfTvSet3f[] = {
  23998. 0xC3, 0x41, 0x9C, 0x2B, 0x96, 0x62, 0x35, 0x86,
  23999. 0x9D, 0x71, 0x4B, 0xA5, 0xAC, 0x48, 0xDD, 0xB7,
  24000. 0xD9, 0xE3, 0x5C, 0x8C, 0x19, 0xAA, 0xC7, 0x34,
  24001. 0x22, 0x33, 0x7A, 0x37, 0x34, 0x53, 0x60, 0x7E
  24002. };
  24003. static const SshKdfTestVector sshKdfTestVectors[] = {
  24004. {WC_HASH_TYPE_SHA256, 'A',
  24005. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24006. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24007. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24008. sshKdfTvSet3a, sizeof(sshKdfTvSet3a)},
  24009. {WC_HASH_TYPE_SHA256, 'B',
  24010. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24011. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24012. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24013. sshKdfTvSet3b, sizeof(sshKdfTvSet3b)},
  24014. {WC_HASH_TYPE_SHA256, 'C',
  24015. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24016. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24017. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24018. sshKdfTvSet3c, sizeof(sshKdfTvSet3c)},
  24019. {WC_HASH_TYPE_SHA256, 'D',
  24020. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24021. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24022. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24023. sshKdfTvSet3d, sizeof(sshKdfTvSet3d)},
  24024. {WC_HASH_TYPE_SHA256, 'E',
  24025. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24026. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24027. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24028. sshKdfTvSet3e, sizeof(sshKdfTvSet3e)},
  24029. {WC_HASH_TYPE_SHA256, 'F',
  24030. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24031. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24032. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24033. sshKdfTvSet3f, sizeof(sshKdfTvSet3f)},
  24034. };
  24035. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
  24036. {
  24037. byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and AES_BLOCK_SIZE */
  24038. word32 i;
  24039. word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector);
  24040. const SshKdfTestVector* tv = NULL;
  24041. wc_test_ret_t result = 0;
  24042. WOLFSSL_ENTER("sshkdf_test");
  24043. /* sId - Session ID, eKey - Expected Key, cKey - Calculated Key */
  24044. for (i = 0, tv = sshKdfTestVectors; i < tc; i++, tv++) {
  24045. result = wc_SSH_KDF(tv->hashId, tv->keyId,
  24046. cKey, tv->expectedKeySz,
  24047. tv->k, tv->kSz, tv->h, tv->hSz,
  24048. tv->sessionId, tv->sessionIdSz);
  24049. if (result != 0) {
  24050. printf("KDF: Could not derive key.\n");
  24051. result = WC_TEST_RET_ENC_EC(result);
  24052. }
  24053. else {
  24054. if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) {
  24055. printf("KDF: Calculated Key does not match Expected Key.\n");
  24056. result = WC_TEST_RET_ENC_EC(result);
  24057. }
  24058. }
  24059. if (result != 0) break;
  24060. }
  24061. return result;
  24062. }
  24063. #endif /* WOLFSSL_WOLFSSH */
  24064. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  24065. #define DIGL 12
  24066. #define SECL 48
  24067. #define LBSL 63
  24068. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
  24069. {
  24070. int ret;
  24071. byte dig[DIGL] = {0};
  24072. byte secret[SECL] = {
  24073. 0x10, 0xbc, 0xb4, 0xa2, 0xe8, 0xdc, 0xf1, 0x9b, 0x4c,
  24074. 0x51, 0x9c, 0xed, 0x31, 0x1b, 0x51, 0x57, 0x02, 0x3f,
  24075. 0xa1, 0x7d, 0xfb, 0x0e, 0xf3, 0x4e, 0x8f, 0x6f, 0x71,
  24076. 0xa3, 0x67, 0x76, 0x6b, 0xfa, 0x5d, 0x46, 0x4a, 0xe8,
  24077. 0x61, 0x18, 0x81, 0xc4, 0x66, 0xcc, 0x6f, 0x09, 0x99,
  24078. 0x9d, 0xfc, 0x47
  24079. };
  24080. byte lablSd[LBSL] = {
  24081. 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69,
  24082. 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x0b, 0x46, 0xba,
  24083. 0x56, 0xbf, 0x1f, 0x5d, 0x99, 0xff, 0xe9, 0xbb, 0x43,
  24084. 0x01, 0xe7, 0xca, 0x2c, 0x00, 0xdf, 0x9a, 0x39, 0x6e,
  24085. 0xcf, 0x6d, 0x15, 0x27, 0x4d, 0xf2, 0x93, 0x96, 0x4a,
  24086. 0x91, 0xde, 0x5c, 0xc0, 0x47, 0x7c, 0xa8, 0xae, 0xcf,
  24087. 0x5d, 0x93, 0x5f, 0x4c, 0x92, 0xcc, 0x98, 0x5b, 0x43
  24088. };
  24089. byte expected[DIGL] = {
  24090. 0xee, 0xcb, 0xb1, 0x30, 0xf2, 0xcd, 0xb3, 0x4a,
  24091. 0xbe, 0xda, 0xc1, 0xf6
  24092. };
  24093. int digL = DIGL;
  24094. int secL = SECL;
  24095. int lblsdL = LBSL;
  24096. int hash_type = sha384_mac;
  24097. ret = wc_PRF(dig, (word32)digL, secret, (word32)secL, lablSd,
  24098. (word32)lblsdL, hash_type,
  24099. HEAP_HINT, INVALID_DEVID);
  24100. if (ret != 0) {
  24101. printf("Failed w/ code: %d\n", ret);
  24102. return WC_TEST_RET_ENC_EC(ret);
  24103. }
  24104. if (XMEMCMP(expected, dig, DIGL) != 0) {
  24105. printf("Got unexpected digest\n");
  24106. return WC_TEST_RET_ENC_NC;
  24107. }
  24108. return 0;
  24109. }
  24110. #endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
  24111. #ifdef WOLFSSL_HAVE_PRF
  24112. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  24113. #ifdef WOLFSSL_BASE16
  24114. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
  24115. {
  24116. const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
  24117. "4E6C2E6C34A165B24540E2970875D641"
  24118. "2AA6515871B389B4C199BB8389C71CED";
  24119. const char* helloRandom = "162B81EDFBEAE4F25240320B87E7651C"
  24120. "865564191DD782DB0B9ECA275FBA1BB9"
  24121. "5A1DA3DF436D68DA86C5E7B4B4A36E46"
  24122. "B977C61767983A31BE270D74517BD0F6";
  24123. const char* masterSecret = "EB38B8D89B98B1C266DE44BB3CA14E83"
  24124. "C32F009F9955B1D994E61D3C51EE8760"
  24125. "90B4EF89CC7AF42F46E72201BFCC7977";
  24126. const char* label = "master secret";
  24127. byte pms[48] = {0};
  24128. byte seed[64] = {0};
  24129. byte ms[48] = {0};
  24130. byte result[48] = {0};
  24131. word32 pmsSz = (word32)sizeof(pms);
  24132. word32 seedSz = (word32)sizeof(seed);
  24133. word32 msSz = (word32)sizeof(ms);
  24134. int ret;
  24135. ret = Base16_Decode((const byte*)preMasterSecret,
  24136. (word32)XSTRLEN(preMasterSecret), pms, &pmsSz);
  24137. if (ret != 0)
  24138. return ret;
  24139. ret = Base16_Decode((const byte*)helloRandom,
  24140. (word32)XSTRLEN(helloRandom), seed, &seedSz);
  24141. if (ret != 0)
  24142. return ret;
  24143. ret = Base16_Decode((const byte*)masterSecret,
  24144. (word32)XSTRLEN(masterSecret), ms, &msSz);
  24145. if (ret != 0)
  24146. return ret;
  24147. ret = wc_PRF_TLS(result, msSz, pms, pmsSz,
  24148. (const byte*)label, (word32)XSTRLEN(label), seed, seedSz,
  24149. 1, sha256_mac, NULL, INVALID_DEVID);
  24150. if (ret != 0) {
  24151. if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
  24152. printf(" wc_PRF_TLSv12: Private key locked.\n");
  24153. }
  24154. return WC_TEST_RET_ENC_NC;
  24155. }
  24156. if (XMEMCMP(result, ms, msSz) != 0)
  24157. return WC_TEST_RET_ENC_NC;
  24158. return 0;
  24159. }
  24160. #endif /* WOLFSSL_BASE16 */
  24161. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  24162. #endif /* WOLFSSL_HAVE_PRF */
  24163. #ifdef WOLFSSL_TLS13
  24164. #define TLSV13_PSK_DHE_SZ 40
  24165. typedef struct {
  24166. enum wc_HashType hashAlg;
  24167. word32 pskSz;
  24168. word32 dheSz;
  24169. byte psk[TLSV13_PSK_DHE_SZ];
  24170. byte dhe[TLSV13_PSK_DHE_SZ];
  24171. byte hashHello1[WC_MAX_DIGEST_SIZE];
  24172. byte hashHello2[WC_MAX_DIGEST_SIZE];
  24173. byte hashFinished1[WC_MAX_DIGEST_SIZE];
  24174. byte hashFinished2[WC_MAX_DIGEST_SIZE];
  24175. /* Expected */
  24176. byte clientEarlyTrafficSecret[WC_MAX_DIGEST_SIZE];
  24177. byte earlyExporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24178. byte clientHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24179. byte serverHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24180. byte clientApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24181. byte serverApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24182. byte exporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24183. byte resumptionMasterSecret[WC_MAX_DIGEST_SIZE];
  24184. } Tls13KdfTestVector;
  24185. /* The following tests come from the CAVP test vectors we used for
  24186. * our FIPS validation. The hash values used are the components from
  24187. * the test hashed together. hashHello1 is the hash of the
  24188. * clientHelloRandom value of the test vector. hashHello2 is the hash
  24189. * of the clientHelloRandom and serverHelloRandom values from the test
  24190. * vector. hashFinished1 is clientHelloRandom, serverHelloRandom, and
  24191. * serverFinishedRandom. hashFinished2 is clientHelloRandom,
  24192. * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom
  24193. * hashed together. */
  24194. static const Tls13KdfTestVector tls13KdfTestVectors[] = {
  24195. { /* 1 */
  24196. WC_HASH_TYPE_SHA256, 35, 35,
  24197. { /* PSK */
  24198. 0x7b, 0xf1, 0x05, 0x31, 0x36, 0xfa, 0x03, 0xdc,
  24199. 0x31, 0x97, 0x88, 0x04, 0x9c, 0xbc, 0xee, 0xf7,
  24200. 0x8d, 0x84, 0x95, 0x26, 0xaf, 0x1d, 0x68, 0xb0,
  24201. 0x60, 0x7a, 0xcc, 0x4f, 0xc1, 0xd3, 0xa1, 0x68,
  24202. 0x7f, 0x6d, 0xbe
  24203. },
  24204. { /* DHE */
  24205. 0x6e, 0xa1, 0x77, 0xab, 0x2f, 0x43, 0xd2, 0x4b,
  24206. 0xe5, 0xa1, 0x09, 0xe0, 0x7a, 0xd0, 0x01, 0x35,
  24207. 0x8d, 0xf8, 0xf2, 0x5c, 0x91, 0x02, 0xb0, 0x6c,
  24208. 0x3f, 0xeb, 0xee, 0xa4, 0x42, 0x19, 0xce, 0xdc,
  24209. 0x81, 0x26, 0x40
  24210. },
  24211. { /* Hello 1 */
  24212. 0xd9, 0x4b, 0xe4, 0x17, 0xef, 0x58, 0x73, 0x7d,
  24213. 0x28, 0x3d, 0xf0, 0xcc, 0x05, 0x03, 0xaf, 0xac,
  24214. 0x3d, 0x92, 0x79, 0x48, 0xe8, 0x8c, 0xdb, 0xce,
  24215. 0x95, 0x82, 0x21, 0x31, 0x7b, 0x61, 0xd7, 0xc6
  24216. },
  24217. { /* Hello 2 */
  24218. 0xb7, 0x7f, 0x29, 0x91, 0xa4, 0x8b, 0x34, 0xdb,
  24219. 0xbd, 0xc7, 0x54, 0x1c, 0x3b, 0x86, 0xa3, 0x69,
  24220. 0xfe, 0x26, 0xe4, 0x7b, 0xac, 0x57, 0x71, 0xb3,
  24221. 0x32, 0x97, 0xed, 0xd2, 0x0e, 0x95, 0xb8, 0x63
  24222. },
  24223. { /* Finished 1 */
  24224. 0x65, 0xdb, 0x6d, 0x71, 0x71, 0xd0, 0xd8, 0x49,
  24225. 0xd0, 0x3c, 0x8e, 0x2b, 0x24, 0xdf, 0xc2, 0xe9,
  24226. 0xd6, 0xfd, 0xea, 0x04, 0x95, 0x7c, 0xf0, 0x7e,
  24227. 0x57, 0x74, 0x7c, 0xdd, 0xa3, 0x0b, 0x2b, 0x36
  24228. },
  24229. { /* Finished 2 */
  24230. 0x28, 0xf2, 0xf2, 0x79, 0xcf, 0x20, 0x52, 0x90,
  24231. 0x1d, 0x91, 0x05, 0xad, 0x44, 0x26, 0x23, 0x96,
  24232. 0x32, 0xce, 0xec, 0x61, 0xd1, 0xbf, 0x00, 0x48,
  24233. 0x4a, 0xa5, 0x60, 0xcc, 0x28, 0xb5, 0x8d, 0x98
  24234. },
  24235. { /* Client Early Traffic Secret */
  24236. 0x07, 0x14, 0x6a, 0x26, 0x5b, 0x6c, 0x7f, 0x4d, 0x6b, 0x47, 0x3f, 0xd5,
  24237. 0x03, 0x1d, 0xd2, 0x23, 0x3d, 0x89, 0x3e, 0xc6, 0x51, 0xd1, 0xac, 0xf8,
  24238. 0x28, 0xae, 0x4b, 0x76, 0xc8, 0x10, 0x7e, 0xdd
  24239. },
  24240. { /* Early Exporter Master Secret */
  24241. 0xb8, 0xd3, 0x25, 0x7e, 0x2d, 0x41, 0x7b, 0xcb, 0x5e, 0x82, 0x49, 0xf5,
  24242. 0x51, 0x3d, 0xb7, 0x59, 0x32, 0xb3, 0xdf, 0x99, 0x4e, 0x04, 0x69, 0xc6,
  24243. 0x96, 0x8e, 0xe6, 0x3d, 0x91, 0xe4, 0x81, 0x11
  24244. },
  24245. { /* Client Handshake Traffic Secret */
  24246. 0xd9, 0x3b, 0x54, 0xe2, 0xb0, 0xd1, 0x85, 0xf0, 0xfd, 0xf3, 0x48, 0x4a,
  24247. 0xf8, 0x0b, 0xa5, 0xdc, 0x4c, 0x37, 0xcb, 0xd4, 0x20, 0xaf, 0x60, 0xc7,
  24248. 0xd5, 0x50, 0x5d, 0x0c, 0x77, 0x3b, 0x6f, 0xd2
  24249. },
  24250. { /* Server Handshake Traffic Secret */
  24251. 0x4d, 0x40, 0x2b, 0xd2, 0x8c, 0x33, 0x90, 0x39, 0x67, 0x67, 0x05, 0xf7,
  24252. 0x5d, 0x37, 0x1e, 0xdc, 0x4a, 0x70, 0x6b, 0x9e, 0xf8, 0x06, 0x61, 0x89,
  24253. 0x70, 0xe1, 0x3d, 0x36, 0xad, 0x88, 0x7e, 0x5b
  24254. },
  24255. { /* Client Application Traffic Secret */
  24256. 0x74, 0x6e, 0xa0, 0x13, 0x18, 0x34, 0x48, 0x4d, 0x23, 0x31, 0xf1, 0xf9,
  24257. 0xee, 0x44, 0x6d, 0xad, 0xc1, 0xad, 0x92, 0x73, 0xca, 0x27, 0x16, 0x91,
  24258. 0xa2, 0x50, 0x9a, 0xfc, 0xec, 0xf0, 0x6b, 0x24
  24259. },
  24260. { /* Server Application Traffic Secret */
  24261. 0x89, 0x18, 0x7e, 0x34, 0x8d, 0xfc, 0x14, 0xb1, 0x4f, 0x21, 0xd8, 0x29,
  24262. 0xdb, 0x9b, 0xfb, 0x55, 0xcf, 0xa1, 0x4f, 0x95, 0xf8, 0xe0, 0xb0, 0x83,
  24263. 0xd5, 0x34, 0x9e, 0x0b, 0x83, 0x37, 0x42, 0x93
  24264. },
  24265. { /* Exporter Master Secret */
  24266. 0x7d, 0xc8, 0x88, 0x46, 0xd5, 0x57, 0x15, 0xb6, 0x24, 0x25, 0x92, 0x61,
  24267. 0xb1, 0x18, 0x86, 0x2a, 0x6d, 0xa5, 0x84, 0xeb, 0x59, 0xdf, 0x13, 0xbd,
  24268. 0x73, 0xaa, 0x5d, 0x65, 0xab, 0xd9, 0xb4, 0x56
  24269. },
  24270. { /* Resumption Master Secret */
  24271. 0x20, 0xb7, 0xd0, 0xe3, 0x82, 0x01, 0xa1, 0x04, 0xb8, 0x13, 0x29, 0xed,
  24272. 0x35, 0xe4, 0x2f, 0xbf, 0x58, 0x23, 0x7f, 0x21, 0xdb, 0x9f, 0xf8, 0xe0,
  24273. 0xe8, 0xe4, 0xab, 0xc4, 0xa1, 0x61, 0xb9, 0xbb
  24274. }
  24275. },
  24276. { /* 6 */
  24277. WC_HASH_TYPE_SHA256, 0, 33,
  24278. { 0 }, /* PSK */
  24279. { /* DHE */
  24280. 0x7a, 0x46, 0x8c, 0x5a, 0xd1, 0x8e, 0x95, 0xba,
  24281. 0x61, 0xe6, 0x6f, 0xe6, 0x76, 0x0c, 0x20, 0x43,
  24282. 0x16, 0x82, 0x15, 0xfe, 0x54, 0xa3, 0xc7, 0xfd,
  24283. 0x3b, 0x2c, 0x88, 0xb4, 0xd3, 0x42, 0x70, 0x12,
  24284. 0x18
  24285. },
  24286. { /* Hello 1 */
  24287. 0x63, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
  24288. 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
  24289. 0x7d, 0x5b, 0x42, 0xdc, 0xa8, 0xaa, 0x06, 0xfb,
  24290. 0x20, 0xa5, 0xbb, 0x85, 0xdb, 0x54, 0xd8, 0x8b
  24291. },
  24292. { /* Hello 2 */
  24293. 0xea, 0xfe, 0x9e, 0x8e, 0xff, 0x1f, 0x6f, 0x43,
  24294. 0xf9, 0x5d, 0xfd, 0xbf, 0xe2, 0x5f, 0x02, 0x2f,
  24295. 0x6d, 0x47, 0x60, 0x9a, 0x48, 0x9a, 0x75, 0xfb,
  24296. 0xb5, 0x4a, 0xbf, 0x9c, 0x4e, 0xff, 0xbf, 0x0b
  24297. },
  24298. { /* Finished 1 */
  24299. 0xca, 0x25, 0xb3, 0x53, 0x8e, 0x6d, 0xc3, 0x36,
  24300. 0x17, 0x30, 0x07, 0xdf, 0x0d, 0xd7, 0x79, 0xb0,
  24301. 0x7f, 0xcb, 0xbe, 0x7a, 0xbc, 0x2d, 0x9f, 0x2d,
  24302. 0x94, 0x44, 0x94, 0xe6, 0xa4, 0xf3, 0xe8, 0x53
  24303. },
  24304. { /* Finished 2 */
  24305. 0x2e, 0xa6, 0x5a, 0xaf, 0xb5, 0xba, 0x9f, 0x2f,
  24306. 0x74, 0x83, 0x5d, 0xbf, 0x86, 0xa4, 0xa6, 0xf6,
  24307. 0xb9, 0x89, 0xdf, 0x17, 0xe1, 0xa8, 0x14, 0xc0,
  24308. 0xe1, 0x50, 0xfa, 0xec, 0xfa, 0xae, 0x8b, 0x7b
  24309. },
  24310. {
  24311. 0x20, 0x18, 0x72, 0x7c, 0xde, 0x3a, 0x85, 0x17, 0x72, 0xdc, 0xd7, 0x72,
  24312. 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
  24313. 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
  24314. },
  24315. {
  24316. 0x68, 0x10, 0x20, 0xd1, 0x5e, 0xfc, 0x0c, 0x53, 0x85, 0xbb, 0xdb, 0x18,
  24317. 0xa8, 0x78, 0xf1, 0x2b, 0x13, 0xba, 0x64, 0x1d, 0xe7, 0x09, 0xbe, 0x13,
  24318. 0x49, 0x26, 0xf9, 0x98, 0x56, 0xf1, 0x43, 0xfb
  24319. },
  24320. {
  24321. 0x24, 0x35, 0x3e, 0x10, 0x6f, 0x39, 0x50, 0xd6, 0xa2, 0x12, 0x99, 0xf2,
  24322. 0xd5, 0xf5, 0x19, 0xf5, 0x84, 0xed, 0xee, 0x78, 0x2a, 0xa6, 0xfa, 0x3d,
  24323. 0x06, 0xa8, 0xa7, 0x5d, 0x97, 0x78, 0xd6, 0x58
  24324. },
  24325. {
  24326. 0xf4, 0x57, 0xac, 0x24, 0x7a, 0xfb, 0x7c, 0x3b, 0xb6, 0x39, 0x17, 0x14,
  24327. 0xd9, 0xd4, 0x58, 0x4d, 0x46, 0xd5, 0x1b, 0xde, 0xf7, 0x9d, 0x06, 0xee,
  24328. 0x8d, 0x1a, 0x2c, 0x25, 0x6d, 0x64, 0xde, 0x89
  24329. },
  24330. {
  24331. 0xb6, 0x00, 0xce, 0x63, 0xed, 0x65, 0x8b, 0x66, 0x66, 0x42, 0xc6, 0xbd,
  24332. 0x89, 0xc4, 0x71, 0x6f, 0xce, 0x28, 0xb2, 0xac, 0x97, 0x07, 0x5b, 0xea,
  24333. 0xb8, 0x1d, 0x4c, 0xeb, 0x9e, 0x71, 0x07, 0x8f
  24334. },
  24335. {
  24336. 0xf8, 0x92, 0xc8, 0xba, 0xe7, 0x83, 0xfe, 0x68, 0xe4, 0xd6, 0x5e, 0xcb,
  24337. 0xb3, 0xef, 0x49, 0xd0, 0xe7, 0xb1, 0xac, 0xcb, 0x39, 0x19, 0xfd, 0xa7,
  24338. 0xf7, 0xca, 0xab, 0x1e, 0x42, 0x14, 0xd8, 0xe7
  24339. },
  24340. {
  24341. 0x32, 0x4a, 0x1a, 0xad, 0xe2, 0xbb, 0x55, 0x8a, 0xdd, 0xe9, 0xa5, 0x2a,
  24342. 0x46, 0x5e, 0x6c, 0x83, 0x66, 0x27, 0x27, 0x94, 0xdd, 0x68, 0x59, 0xa0,
  24343. 0xbb, 0xe8, 0x31, 0x7c, 0x39, 0xd7, 0xfd, 0x6d
  24344. },
  24345. {
  24346. 0x58, 0xbc, 0x6c, 0x5b, 0x24, 0xad, 0x82, 0xb3, 0xcc, 0xc7, 0xd1, 0xa1,
  24347. 0xaa, 0x2b, 0x98, 0x9f, 0x2f, 0x7e, 0xa9, 0x63, 0xc2, 0x8e, 0xb6, 0x06,
  24348. 0xc2, 0x2b, 0x74, 0x4b, 0x79, 0x19, 0x7e, 0x2e
  24349. }
  24350. },
  24351. { /* 11 */
  24352. WC_HASH_TYPE_SHA256, 33, 0,
  24353. { /* PSK */
  24354. 0x3d, 0x39, 0x49, 0x36, 0x98, 0xc5, 0xfd, 0xcd,
  24355. 0xa0, 0x17, 0xbd, 0x65, 0x0a, 0xdb, 0xd4, 0x07,
  24356. 0x56, 0xa2, 0x7b, 0xb8, 0x2a, 0x7e, 0xfb, 0x26,
  24357. 0x74, 0xe1, 0xbc, 0x08, 0x4b, 0xf0, 0x30, 0x14,
  24358. 0x12
  24359. },
  24360. { 0 }, /* DHE */
  24361. { /* Hello 1 */
  24362. 0xb7, 0x44, 0x74, 0x6c, 0x57, 0x1f, 0xf3, 0x84,
  24363. 0x8f, 0x63, 0xfb, 0x8c, 0x94, 0x6c, 0x16, 0x68,
  24364. 0x4b, 0xe1, 0xb5, 0xb5, 0x2a, 0x4e, 0x5f, 0xdf,
  24365. 0x4b, 0x53, 0xb2, 0x35, 0xfc, 0x30, 0xf1, 0x36
  24366. },
  24367. { /* Hello 2 */
  24368. 0xe6, 0x4f, 0x3a, 0x4f, 0xd7, 0xe0, 0x64, 0xd4,
  24369. 0x69, 0x50, 0xe4, 0x8b, 0xba, 0xbc, 0x47, 0x74,
  24370. 0xa7, 0x9b, 0x40, 0x91, 0x8f, 0xa8, 0x72, 0x22,
  24371. 0x97, 0xad, 0x43, 0xa7, 0x11, 0x86, 0xb5, 0x72
  24372. },
  24373. { /* Finished 1 */
  24374. 0x5f, 0xa6, 0x10, 0xe2, 0xa3, 0x99, 0x0b, 0x5e,
  24375. 0x57, 0xee, 0xc3, 0x3a, 0x8e, 0x04, 0xf3, 0x0e,
  24376. 0x58, 0x02, 0x09, 0xb2, 0x7e, 0x2d, 0xc6, 0xd2,
  24377. 0x08, 0xae, 0x68, 0x0a, 0x55, 0xa5, 0xda, 0x51
  24378. },
  24379. { /* Finished 2 */
  24380. 0xfc, 0x5b, 0xc0, 0x7e, 0x1b, 0xaa, 0xc0, 0xb4,
  24381. 0x34, 0x85, 0x49, 0x8e, 0x16, 0x31, 0x98, 0xdf,
  24382. 0x10, 0x54, 0x22, 0xda, 0x1e, 0x6b, 0x51, 0xf6,
  24383. 0x97, 0x57, 0xa0, 0x7a, 0x92, 0xe7, 0x47, 0x52
  24384. },
  24385. {
  24386. 0x80, 0xfa, 0x36, 0x30, 0xb8, 0x65, 0xb3, 0x2a, 0x1d, 0x68, 0x91, 0x06,
  24387. 0x98, 0xa0, 0x17, 0x8f, 0xee, 0xb7, 0x9e, 0x3d, 0xd8, 0x84, 0x99, 0x30,
  24388. 0xb9, 0xd6, 0x09, 0x25, 0x5e, 0xfb, 0x8f, 0xd3 },
  24389. {
  24390. 0xa9, 0x89, 0x29, 0x70, 0xe4, 0x55, 0xec, 0x97, 0xfb, 0x24, 0x5b, 0xf9,
  24391. 0xf1, 0xa3, 0x19, 0x3d, 0xf1, 0x31, 0x14, 0xcd, 0x2a, 0xed, 0x21, 0xc8,
  24392. 0xb1, 0x53, 0xad, 0x11, 0x0b, 0x9e, 0x5a, 0xee },
  24393. {
  24394. 0x72, 0xad, 0x8d, 0x7f, 0xfc, 0xb7, 0x68, 0xda, 0x27, 0x60, 0x37, 0xa3,
  24395. 0x4a, 0x63, 0xe8, 0xa5, 0xc8, 0xcd, 0x36, 0x6a, 0x77, 0x99, 0x0d, 0xa9,
  24396. 0xb1, 0x5b, 0x2f, 0x47, 0x2e, 0x22, 0xa7, 0x5e },
  24397. {
  24398. 0x95, 0x6e, 0x85, 0x09, 0xe5, 0x04, 0x88, 0x14, 0x28, 0x8d, 0xdf, 0xe6,
  24399. 0x0d, 0x0f, 0x0d, 0x6b, 0x4e, 0x66, 0x1c, 0x03, 0xb9, 0xaa, 0x2d, 0x45,
  24400. 0x56, 0x67, 0x5c, 0x55, 0x29, 0xd6, 0x89, 0xd0 },
  24401. {
  24402. 0xe8, 0xf2, 0x14, 0xf9, 0x9b, 0x2b, 0x9f, 0x24, 0x2b, 0x37, 0xbe, 0x86,
  24403. 0xdb, 0x23, 0x4b, 0xbe, 0x39, 0x57, 0xe8, 0xa9, 0xa5, 0xee, 0x08, 0xf2,
  24404. 0x75, 0x58, 0xdb, 0xd9, 0x51, 0xc1, 0x46, 0x02 },
  24405. {
  24406. 0x3d, 0x19, 0xaf, 0xa3, 0x0b, 0x21, 0xf7, 0x3d, 0xe7, 0x37, 0x6e, 0x32,
  24407. 0x13, 0x48, 0x9d, 0xea, 0xe0, 0x90, 0xbf, 0x64, 0x48, 0xf7, 0x1e, 0xcc,
  24408. 0xf0, 0xbc, 0x92, 0xd7, 0x8a, 0x4a, 0xa8, 0xc1 },
  24409. {
  24410. 0x16, 0x35, 0xb1, 0x66, 0x28, 0xa3, 0x3e, 0x19, 0xf5, 0x2d, 0x92, 0x22,
  24411. 0x95, 0x48, 0xe8, 0x34, 0x7b, 0x30, 0x50, 0xa2, 0xa0, 0xd9, 0xc2, 0x59,
  24412. 0x39, 0xf9, 0x8c, 0x69, 0xf2, 0x2a, 0xb9, 0xff },
  24413. {
  24414. 0x32, 0x71, 0xa6, 0x87, 0x0c, 0x97, 0x42, 0x07, 0xdd, 0x5f, 0xc9, 0x44,
  24415. 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b,
  24416. 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 }
  24417. },
  24418. #ifdef WOLFSSL_SHA384
  24419. { /* 26 */
  24420. WC_HASH_TYPE_SHA384, 35, 35,
  24421. { /* PSK */
  24422. 0x62, 0x83, 0x25, 0xc7, 0xcc, 0x08, 0x5e, 0x63,
  24423. 0x64, 0x56, 0xf0, 0xc6, 0x88, 0x27, 0x5a, 0x5b,
  24424. 0x68, 0x59, 0x0b, 0x14, 0x55, 0x13, 0x2e, 0xfd,
  24425. 0x8f, 0x28, 0x5b, 0x3d, 0xe3, 0xad, 0x67, 0xe4,
  24426. 0x68, 0xba, 0xf9
  24427. },
  24428. { /* DHE */
  24429. 0xa8, 0xb1, 0xab, 0xd8, 0xc8, 0x5b, 0x52, 0xdf,
  24430. 0x7f, 0x49, 0x10, 0xf4, 0xa1, 0x31, 0xd1, 0x91,
  24431. 0x36, 0xc1, 0x87, 0x5d, 0x42, 0x2a, 0xe7, 0x1d,
  24432. 0x2c, 0x29, 0x3d, 0x40, 0x64, 0x61, 0x63, 0x76,
  24433. 0xd8, 0x66, 0xac
  24434. },
  24435. { /* Hello 1 */
  24436. 0x6f, 0xc6, 0x4c, 0xe1, 0xc6, 0x68, 0x34, 0x8c,
  24437. 0x0a, 0xe1, 0xf8, 0xb8, 0x3e, 0xd4, 0xf8, 0x0b,
  24438. 0x54, 0x50, 0xe4, 0xc5, 0x4a, 0x33, 0x7d, 0xbd,
  24439. 0x90, 0xd2, 0xa2, 0xb9, 0xb7, 0x92, 0xed, 0xab,
  24440. 0x14, 0xf1, 0xe4, 0x86, 0x22, 0x67, 0xd7, 0x44,
  24441. 0x03, 0x21, 0xdc, 0x51, 0x52, 0x7f, 0x35, 0x80
  24442. },
  24443. { /* Hello 2 */
  24444. 0x3e, 0xcf, 0x2f, 0xc3, 0x87, 0xba, 0xc5, 0xbd,
  24445. 0x7c, 0xe8, 0x35, 0x5b, 0x95, 0x51, 0x30, 0x3b,
  24446. 0x08, 0xcc, 0x2a, 0x7d, 0xb5, 0x74, 0x7c, 0x16,
  24447. 0xb3, 0x0b, 0xe7, 0x61, 0xa3, 0x7c, 0x6c, 0xbd,
  24448. 0x39, 0x74, 0xfd, 0x1e, 0x4c, 0xff, 0xc8, 0xcc,
  24449. 0xa0, 0xef, 0x29, 0x4d, 0x94, 0xaa, 0x55, 0x6f,
  24450. },
  24451. { /* Finished 1 */
  24452. 0x06, 0xc1, 0x47, 0x78, 0x66, 0x53, 0x6f, 0x24,
  24453. 0x94, 0x61, 0x69, 0xec, 0xd8, 0x60, 0x31, 0x2f,
  24454. 0xbf, 0xd6, 0x8a, 0x29, 0x17, 0xff, 0xa3, 0x88,
  24455. 0x13, 0x09, 0x8c, 0x9d, 0x6c, 0x64, 0x84, 0x48,
  24456. 0x44, 0xdd, 0x2d, 0x29, 0x4d, 0xe6, 0x98, 0x2b,
  24457. 0x45, 0x3b, 0x84, 0x33, 0x79, 0xb2, 0x75, 0x68
  24458. },
  24459. { /* Finished 2 */
  24460. 0x28, 0x1e, 0x18, 0xf7, 0x9c, 0x32, 0xa9, 0xbf,
  24461. 0x0c, 0x24, 0x58, 0x21, 0xce, 0xbc, 0xf2, 0x44,
  24462. 0xb1, 0x18, 0xaf, 0x9d, 0xd9, 0x20, 0xf9, 0xf4,
  24463. 0xed, 0xcc, 0x53, 0x82, 0x66, 0x5c, 0x46, 0x94,
  24464. 0x8c, 0x36, 0x5e, 0xca, 0x9f, 0xd8, 0x9a, 0xd3,
  24465. 0xf0, 0xe1, 0x53, 0x71, 0xdd, 0x19, 0x1e, 0x59
  24466. },
  24467. {
  24468. 0xd0, 0xef, 0xa8, 0xcb, 0x5b, 0x14, 0x0f, 0x0a, 0x62, 0xba, 0x5a, 0xb1,
  24469. 0xc5, 0xb5, 0x3f, 0x11, 0xda, 0xa1, 0x0c, 0x9c, 0xb4, 0x32, 0x48, 0x4e,
  24470. 0xfa, 0x84, 0x4f, 0xe4, 0xe7, 0x91, 0x8f, 0x42, 0x3f, 0xc7, 0x4e, 0xd3,
  24471. 0x83, 0x3d, 0x7f, 0x70, 0x12, 0xee, 0x9a, 0x37, 0x01, 0xbb, 0x14, 0xd3
  24472. },
  24473. {
  24474. 0x48, 0x6f, 0x77, 0x1d, 0x39, 0x1b, 0xa5, 0x9a, 0x76, 0xd9, 0x1d, 0x7d,
  24475. 0xb3, 0xd9, 0xb9, 0x78, 0x35, 0x0f, 0xd0, 0xe1, 0x07, 0x1f, 0x8d, 0xe5,
  24476. 0x75, 0x00, 0xda, 0xc0, 0x19, 0x01, 0xfb, 0x08, 0x35, 0xe7, 0x18, 0x8f,
  24477. 0xf0, 0x19, 0xfb, 0x46, 0xf6, 0xa5, 0x77, 0x0e, 0x90, 0x38, 0x8b, 0x15
  24478. },
  24479. {
  24480. 0x80, 0x8c, 0xa7, 0x24, 0x97, 0xf9, 0xd3, 0x52, 0xb0, 0x69, 0x9d, 0x4b,
  24481. 0xa4, 0x19, 0x4a, 0xb1, 0x46, 0x53, 0x3a, 0xc8, 0xe4, 0x02, 0x69, 0xf2,
  24482. 0xe7, 0xb6, 0x1d, 0x33, 0x51, 0xcc, 0x14, 0x40, 0x4a, 0xb0, 0xe7, 0x58,
  24483. 0x84, 0xba, 0xc2, 0x14, 0x58, 0x6b, 0xb9, 0xdc, 0x50, 0x98, 0x67, 0x01
  24484. },
  24485. {
  24486. 0xb1, 0xa8, 0xc0, 0x06, 0xb3, 0x2e, 0xa7, 0x8a, 0x6a, 0x12, 0x88, 0x00,
  24487. 0x65, 0x88, 0x9c, 0x5d, 0x35, 0xee, 0xe5, 0x51, 0x0b, 0x62, 0xf8, 0x67,
  24488. 0xe5, 0xef, 0x15, 0x1f, 0x23, 0x02, 0x74, 0x08, 0x9c, 0xc8, 0xba, 0x27,
  24489. 0x5d, 0x32, 0x19, 0x6f, 0x6d, 0x5d, 0x72, 0x5e, 0x15, 0xde, 0x30, 0xc3
  24490. },
  24491. {
  24492. 0xfd, 0xce, 0xf5, 0x65, 0x45, 0x84, 0xfb, 0x8c, 0x79, 0xa4, 0x6c, 0x1b,
  24493. 0x0e, 0x1b, 0xfd, 0x26, 0xa2, 0x53, 0xf4, 0x4e, 0x00, 0x4d, 0x4b, 0x0b,
  24494. 0x24, 0x6d, 0x35, 0x35, 0xd9, 0x97, 0x70, 0xc5, 0xf4, 0xee, 0xe3, 0xba,
  24495. 0x31, 0x1e, 0x2a, 0x42, 0xcb, 0xdf, 0x40, 0xb1, 0x14, 0xb8, 0x53, 0xce
  24496. },
  24497. {
  24498. 0xbb, 0xb3, 0x26, 0x7c, 0x22, 0x21, 0x9b, 0x72, 0x32, 0xa1, 0x97, 0xfb,
  24499. 0x78, 0x8c, 0xbe, 0x3d, 0x71, 0x45, 0xb8, 0xf5, 0x24, 0x8f, 0x0f, 0xac,
  24500. 0x42, 0x5b, 0x81, 0xe8, 0xd0, 0x71, 0x4a, 0xcb, 0x32, 0x3f, 0x03, 0xfb,
  24501. 0xec, 0x6a, 0x1f, 0x76, 0x80, 0x65, 0x01, 0x7a, 0x3d, 0xce, 0xc4, 0xdf
  24502. },
  24503. {
  24504. 0x3f, 0xcf, 0x2f, 0x63, 0x94, 0x94, 0x99, 0xfd, 0x04, 0x3a, 0x89, 0x83,
  24505. 0xcf, 0x06, 0x05, 0xec, 0x20, 0x3e, 0x5f, 0x51, 0x9d, 0x6e, 0x4a, 0xc6,
  24506. 0xf1, 0x2b, 0x37, 0x17, 0x34, 0x72, 0x6e, 0x1d, 0x2a, 0xfd, 0xc7, 0x73,
  24507. 0xb5, 0x07, 0x22, 0x81, 0x32, 0x2e, 0x21, 0x85, 0xaf, 0x10, 0xb2, 0x73
  24508. },
  24509. {
  24510. 0x52, 0x0c, 0x3d, 0x2e, 0x2d, 0x4a, 0x11, 0xae, 0x96, 0x78, 0xe9, 0x5b,
  24511. 0xd8, 0x0f, 0x6c, 0xf4, 0xbd, 0x96, 0x13, 0x55, 0x88, 0xdd, 0xa3, 0x67,
  24512. 0x36, 0x86, 0x1e, 0x0b, 0x36, 0x41, 0xec, 0xf6, 0x04, 0xb2, 0xc4, 0x16,
  24513. 0xbc, 0x2c, 0xdb, 0x30, 0x02, 0x94, 0xd4, 0x42, 0xbf, 0x38, 0xee, 0x9d
  24514. }
  24515. },
  24516. { /* 36 */
  24517. WC_HASH_TYPE_SHA384, 0, 33,
  24518. { 0 }, /* PSK */
  24519. { /* DHE */
  24520. 0xd3, 0x00, 0x72, 0x9a, 0xa8, 0xc5, 0xf3, 0xc4,
  24521. 0xf1, 0xa0, 0x26, 0x89, 0x65, 0x70, 0xc7, 0x0b,
  24522. 0x77, 0xbb, 0xe1, 0x4b, 0x2b, 0xa8, 0x4f, 0xa6,
  24523. 0x09, 0x4b, 0xba, 0x45, 0x36, 0x15, 0xee, 0x68,
  24524. 0xfd
  24525. },
  24526. { /* Hello 1 */
  24527. 0x10, 0x9d, 0x8b, 0xa2, 0x93, 0xe7, 0xd3, 0xb9,
  24528. 0xb4, 0x0f, 0xeb, 0x6a, 0xb9, 0x69, 0xcb, 0x39,
  24529. 0x16, 0x29, 0xcc, 0xd3, 0xcc, 0x1a, 0x4c, 0x1b,
  24530. 0x53, 0x7c, 0x33, 0x88, 0x06, 0xbc, 0x0a, 0x02,
  24531. 0xa0, 0xbe, 0x62, 0xc0, 0xe6, 0x5e, 0x97, 0x5b,
  24532. 0x6a, 0xa1, 0x98, 0xf3, 0xd2, 0x1e, 0xcd, 0xc5
  24533. },
  24534. { /* Hello 2 */
  24535. 0x74, 0xc0, 0x07, 0x2c, 0xc1, 0x63, 0xcc, 0x11,
  24536. 0xad, 0x1a, 0x55, 0x63, 0xbc, 0x20, 0x77, 0x96,
  24537. 0x30, 0x1c, 0x68, 0x45, 0x1e, 0x9b, 0xa7, 0xb4,
  24538. 0xf3, 0x04, 0x45, 0x16, 0x76, 0x55, 0xf9, 0xdf,
  24539. 0x4b, 0x2f, 0x1a, 0xdf, 0x5a, 0xb0, 0x93, 0xc9,
  24540. 0xab, 0xf5, 0x32, 0x47, 0x79, 0x9c, 0x01, 0xeb
  24541. },
  24542. { /* Finished 1 */
  24543. 0x27, 0x08, 0x8e, 0xa5, 0xf1, 0x30, 0xe1, 0xd6,
  24544. 0x4f, 0xa2, 0x9e, 0x3b, 0x03, 0x2d, 0x2e, 0xa3,
  24545. 0x84, 0x75, 0x51, 0x3a, 0xc3, 0xf6, 0xee, 0x2e,
  24546. 0x37, 0x0c, 0xe3, 0x28, 0x46, 0xa5, 0x2d, 0xc7,
  24547. 0xf0, 0x64, 0x78, 0x53, 0x66, 0x43, 0x02, 0xa4,
  24548. 0x7a, 0x43, 0x66, 0x4b, 0xa7, 0xcb, 0x97, 0x16
  24549. },
  24550. { /* Finished 2 */
  24551. 0x1d, 0x0d, 0xf8, 0xe1, 0x81, 0xa5, 0xbd, 0xa8,
  24552. 0x6f, 0x9d, 0x01, 0xa4, 0x9a, 0x92, 0xe2, 0xef,
  24553. 0x08, 0xab, 0xef, 0x3e, 0x2d, 0xd4, 0x82, 0xac,
  24554. 0x68, 0x9d, 0xe0, 0x54, 0x17, 0xde, 0x1a, 0xed,
  24555. 0x57, 0xcb, 0xd9, 0x2d, 0xc8, 0xbc, 0x93, 0xe6,
  24556. 0xa3, 0xec, 0xde, 0xee, 0xa1, 0x1c, 0x41, 0x85
  24557. },
  24558. {
  24559. 0x7f, 0x1f, 0xe6, 0x7b, 0xd8, 0xf5, 0x2b, 0x37, 0xbe, 0xb7, 0xd0, 0x37,
  24560. 0xce, 0x46, 0xad, 0x04, 0x2f, 0xc7, 0xdb, 0xc9, 0x9a, 0xb6, 0x00, 0x3f,
  24561. 0xc1, 0x97, 0xe9, 0x5c, 0x5e, 0x14, 0xd1, 0x38, 0x4d, 0x55, 0xe1, 0x07,
  24562. 0xb5, 0x85, 0x6d, 0xfa, 0xa7, 0x66, 0xad, 0xfa, 0xb6, 0xad, 0x29, 0x44
  24563. },
  24564. {
  24565. 0x4e, 0x6b, 0x20, 0x99, 0x55, 0x1b, 0x21, 0x89, 0xb6, 0x70, 0xdb, 0xe8,
  24566. 0xa7, 0x16, 0x55, 0xf2, 0x93, 0x13, 0x90, 0x7d, 0xfa, 0x62, 0x65, 0x53,
  24567. 0xa0, 0x97, 0xe9, 0xb4, 0xc0, 0xf1, 0xc9, 0x1a, 0x67, 0xdd, 0xca, 0x57,
  24568. 0xbc, 0xca, 0x39, 0xe6, 0x39, 0x6b, 0x63, 0x47, 0x25, 0x08, 0x3a, 0xd7
  24569. },
  24570. {
  24571. 0x35, 0x0d, 0xac, 0xd8, 0x10, 0x6a, 0x46, 0x50, 0x66, 0xae, 0x02, 0xc9,
  24572. 0xde, 0x13, 0x48, 0xce, 0x53, 0xd4, 0x92, 0x62, 0xc5, 0x65, 0x10, 0x08,
  24573. 0xc2, 0xc2, 0x82, 0xed, 0x9d, 0xc9, 0x6f, 0xa8, 0xc3, 0xc1, 0x0b, 0x7c,
  24574. 0xe1, 0x97, 0x85, 0xd6, 0x46, 0x29, 0x0e, 0x42, 0x51, 0xc1, 0x35, 0xcf
  24575. },
  24576. {
  24577. 0x3d, 0x5d, 0x84, 0xbd, 0x16, 0x46, 0x34, 0xb3, 0xf6, 0x31, 0x49, 0x3e,
  24578. 0x8d, 0xdc, 0xcb, 0x8c, 0x6a, 0x42, 0xf4, 0x88, 0xfc, 0x19, 0xfa, 0xa2,
  24579. 0x25, 0xc7, 0xa0, 0xa4, 0xca, 0xf0, 0xea, 0x2d, 0xe8, 0xc4, 0x02, 0x14,
  24580. 0x63, 0xfb, 0xd3, 0x7b, 0x51, 0x1c, 0xce, 0xca, 0xa3, 0xc3, 0xe4, 0xa5
  24581. },
  24582. {
  24583. 0x7c, 0x3a, 0x55, 0x92, 0x2e, 0xdd, 0x75, 0xdd, 0x76, 0x54, 0x4a, 0x9f,
  24584. 0xd0, 0xa2, 0x88, 0x83, 0xe9, 0x27, 0xda, 0x30, 0xe9, 0x96, 0x58, 0xc5,
  24585. 0xb7, 0x56, 0xfc, 0x4b, 0xb8, 0x5d, 0xee, 0x46, 0x70, 0x4e, 0x1b, 0x06,
  24586. 0x86, 0xaf, 0x48, 0x5c, 0x17, 0x35, 0xfa, 0x69, 0xc2, 0x4d, 0xfb, 0x09
  24587. },
  24588. {
  24589. 0x00, 0x0e, 0x28, 0x51, 0xc1, 0x7f, 0x41, 0x89, 0x6f, 0x9a, 0xca, 0x15,
  24590. 0xee, 0xed, 0x43, 0xca, 0x6d, 0x65, 0x6f, 0x51, 0x18, 0x6c, 0x08, 0x4b,
  24591. 0x77, 0xca, 0x75, 0xc4, 0xc3, 0xde, 0x29, 0x41, 0x8b, 0xaf, 0xa7, 0x1c,
  24592. 0x28, 0x37, 0xa0, 0xa0, 0x74, 0x8e, 0x09, 0x42, 0x7a, 0x1b, 0x68, 0xdb
  24593. },
  24594. {
  24595. 0x14, 0x8f, 0xab, 0x28, 0x64, 0xea, 0x45, 0x88, 0xdb, 0xc1, 0xc6, 0xa0,
  24596. 0x48, 0xdf, 0x15, 0xd0, 0x28, 0x07, 0x2d, 0x6c, 0xb8, 0x42, 0xbb, 0x60,
  24597. 0x02, 0x08, 0x9e, 0x29, 0x9b, 0x8d, 0xd6, 0x1c, 0xaf, 0xf2, 0x1a, 0xdc,
  24598. 0xf0, 0x78, 0x0b, 0x4d, 0x90, 0xa1, 0x0c, 0xb3, 0x13, 0xde, 0xca, 0x5a
  24599. },
  24600. {
  24601. 0x4d, 0x80, 0x7d, 0x0b, 0xb9, 0x00, 0x6f, 0x65, 0x51, 0x65, 0x23, 0xde,
  24602. 0x72, 0xdc, 0x4f, 0x04, 0xa5, 0xa2, 0x90, 0x45, 0x51, 0x9e, 0xd0, 0x3a,
  24603. 0xe4, 0xd7, 0x78, 0xa3, 0x0f, 0x2d, 0x65, 0x12, 0xad, 0xc8, 0x92, 0x30,
  24604. 0x79, 0x9d, 0x9d, 0x08, 0x7a, 0x9c, 0x9f, 0x83, 0xb1, 0xca, 0x59, 0x56
  24605. }
  24606. },
  24607. { /* 41 */
  24608. WC_HASH_TYPE_SHA384, 33, 0,
  24609. { /* PSK */
  24610. 0xa4, 0x8b, 0x1b, 0x5f, 0xd0, 0xea, 0x75, 0x62,
  24611. 0x06, 0x4d, 0x68, 0x40, 0x85, 0x20, 0x45, 0x95,
  24612. 0x4a, 0x00, 0xca, 0x05, 0xeb, 0xd4, 0x1d, 0x48,
  24613. 0x81, 0x89, 0xe8, 0x86, 0x43, 0xfa, 0x28, 0x17,
  24614. 0x12
  24615. },
  24616. { 0 }, /* DHE */
  24617. { /* Hello 1 */
  24618. 0x03, 0x7c, 0x33, 0x75, 0xdc, 0xc5, 0x46, 0x3a,
  24619. 0x0d, 0x56, 0xc6, 0xfb, 0xab, 0x1e, 0x1d, 0xda,
  24620. 0x59, 0xc2, 0xb2, 0xb1, 0x7c, 0x48, 0x9b, 0x06,
  24621. 0x0a, 0x5a, 0xbb, 0xf8, 0x98, 0x53, 0x78, 0x2d,
  24622. 0xd2, 0xcc, 0x87, 0x68, 0x25, 0xdd, 0x88, 0x22,
  24623. 0xcd, 0xb7, 0x74, 0x55, 0x21, 0xf9, 0x34, 0x98
  24624. },
  24625. { /* Hello 2 */
  24626. 0x03, 0xb4, 0xfb, 0xcc, 0x28, 0x2c, 0xc1, 0x70,
  24627. 0x42, 0x73, 0x57, 0xac, 0xdb, 0x47, 0x71, 0xf6,
  24628. 0x2e, 0x11, 0x8a, 0x5b, 0x47, 0x2f, 0x02, 0x54,
  24629. 0x95, 0x34, 0xed, 0x5f, 0x19, 0xc1, 0x75, 0xe0,
  24630. 0x76, 0xad, 0xb0, 0x90, 0x57, 0xcd, 0xfd, 0xd7,
  24631. 0x58, 0x1f, 0x0d, 0x6b, 0x9e, 0x51, 0x3c, 0x08
  24632. },
  24633. { /* Finished 1 */
  24634. 0x2b, 0x50, 0xd9, 0xa7, 0x43, 0x24, 0xda, 0x2c,
  24635. 0x7a, 0xaa, 0x0e, 0x37, 0xd7, 0x6b, 0x2c, 0xab,
  24636. 0x8e, 0xb2, 0xfe, 0x31, 0x1b, 0xa8, 0x12, 0x59,
  24637. 0x5b, 0x7b, 0xdc, 0x3e, 0xa7, 0x86, 0xa5, 0x48,
  24638. 0xe4, 0x46, 0x2b, 0x4c, 0xc1, 0x66, 0x4b, 0xf3,
  24639. 0x2a, 0x99, 0x93, 0x08, 0xbc, 0x3d, 0x08, 0x76
  24640. },
  24641. { /* Finished 2 */
  24642. 0x7c, 0x34, 0xc8, 0x56, 0x17, 0xf1, 0x62, 0x1c,
  24643. 0x9f, 0x0b, 0xeb, 0xfd, 0x69, 0x72, 0x51, 0xc5,
  24644. 0xfa, 0x74, 0x87, 0xc9, 0xbd, 0x50, 0xe9, 0x48,
  24645. 0xa7, 0x3c, 0x94, 0x3e, 0x06, 0x7d, 0xe8, 0x8e,
  24646. 0xc1, 0xd1, 0x08, 0x1f, 0x5d, 0x48, 0x8a, 0x25,
  24647. 0xfc, 0xea, 0xe7, 0xd9, 0xd4, 0xd0, 0xf9, 0xad
  24648. },
  24649. {
  24650. 0x4b, 0x0b, 0xed, 0xb9, 0xc8, 0xb8, 0xa8, 0x1e, 0xb0, 0x81, 0x76, 0xd5,
  24651. 0x33, 0x22, 0x71, 0x33, 0x3a, 0x85, 0x19, 0x67, 0x7e, 0x91, 0x37, 0xf2,
  24652. 0xa6, 0x11, 0x22, 0xdf, 0x41, 0x04, 0x3d, 0xa9, 0x13, 0xb9, 0xb2, 0xb1,
  24653. 0xbb, 0xd8, 0xef, 0x23, 0x7c, 0xc2, 0xab, 0x70, 0x1b, 0x51, 0x9f, 0xc9
  24654. },
  24655. {
  24656. 0xeb, 0x96, 0x10, 0x8c, 0x7d, 0x92, 0xea, 0x80, 0x86, 0xb2, 0xf8, 0x27,
  24657. 0xf2, 0x9a, 0x09, 0xc1, 0x7c, 0x09, 0x43, 0xbc, 0xfe, 0xc8, 0x75, 0xe0,
  24658. 0x97, 0xe7, 0x6d, 0xd5, 0xb2, 0x3c, 0xed, 0x12, 0xb7, 0x74, 0x0e, 0xe3,
  24659. 0xb6, 0xe0, 0xba, 0xe1, 0x8d, 0x89, 0xcf, 0x4f, 0x57, 0xf6, 0x6d, 0x90
  24660. },
  24661. {
  24662. 0x22, 0xb0, 0x39, 0x34, 0xb6, 0x6c, 0x2d, 0x7a, 0x97, 0x1c, 0x5d, 0xcc,
  24663. 0x78, 0x84, 0x71, 0xbb, 0xc6, 0x7b, 0xb6, 0xbc, 0xcc, 0x0b, 0xf8, 0xac,
  24664. 0x8e, 0xd7, 0x20, 0xbd, 0xbe, 0x32, 0xf0, 0xd6, 0xe9, 0x69, 0x13, 0xf2,
  24665. 0x9a, 0xce, 0xfe, 0x86, 0xd3, 0xee, 0xba, 0x69, 0x51, 0xb6, 0x77, 0x56
  24666. },
  24667. {
  24668. 0x16, 0xfd, 0xda, 0xf3, 0x5e, 0xb9, 0xa6, 0x17, 0x24, 0xb2, 0x16, 0x9f,
  24669. 0xb6, 0x59, 0x13, 0x0f, 0x25, 0x5a, 0xf1, 0x5b, 0x5f, 0xe4, 0x54, 0x2a,
  24670. 0xa7, 0xbf, 0x29, 0xaf, 0x5a, 0x77, 0xf4, 0x4f, 0x25, 0xba, 0x94, 0xad,
  24671. 0x6b, 0x91, 0x3b, 0xe7, 0xd5, 0x73, 0x0d, 0xff, 0xaa, 0xe3, 0x72, 0x2c
  24672. },
  24673. {
  24674. 0x22, 0xb4, 0x94, 0xc0, 0x53, 0xd7, 0x82, 0x06, 0x38, 0x9d, 0x4a, 0xa0,
  24675. 0x3f, 0xf1, 0x5f, 0x6e, 0x23, 0x8d, 0x09, 0x62, 0xbf, 0x6f, 0x7c, 0x84,
  24676. 0xc6, 0x3e, 0x15, 0xad, 0x18, 0x37, 0x76, 0x29, 0xc7, 0xd6, 0x68, 0x0c,
  24677. 0x1e, 0xc6, 0x93, 0x31, 0xef, 0x85, 0x69, 0x30, 0x68, 0xf0, 0x1e, 0x37
  24678. },
  24679. {
  24680. 0x6d, 0x4d, 0x20, 0xaf, 0x47, 0xe8, 0x1b, 0xfa, 0xd0, 0xb6, 0xc8, 0x97,
  24681. 0xd1, 0x03, 0xfc, 0x9d, 0x59, 0xa0, 0x68, 0x9d, 0xe9, 0x17, 0x8b, 0xce,
  24682. 0x48, 0x2c, 0x77, 0x8a, 0x22, 0x4b, 0x5c, 0x54, 0x22, 0xa1, 0x15, 0x12,
  24683. 0xe1, 0x07, 0x8e, 0x15, 0xd8, 0x7b, 0x16, 0x65, 0x99, 0x6b, 0xcb, 0x71
  24684. },
  24685. {
  24686. 0x79, 0x64, 0x79, 0xdd, 0x75, 0x5c, 0x6f, 0x98, 0xac, 0x03, 0xe0, 0xcd,
  24687. 0x92, 0xba, 0x0e, 0x2d, 0xb4, 0xd1, 0x8b, 0x97, 0xd0, 0x85, 0xbb, 0x2e,
  24688. 0x4f, 0x26, 0x93, 0xf5, 0x1d, 0xf3, 0xd2, 0x43, 0x4f, 0xd2, 0x47, 0xaa,
  24689. 0x91, 0x1e, 0xf3, 0x67, 0x10, 0x18, 0x2c, 0xb9, 0x01, 0xba, 0x10, 0x9f
  24690. },
  24691. {
  24692. 0x79, 0xb6, 0x9c, 0xbe, 0xf1, 0x6a, 0xb0, 0x92, 0xa0, 0x29, 0x52, 0x61,
  24693. 0xf1, 0xcd, 0x3a, 0x67, 0xe1, 0x6b, 0xb8, 0x9d, 0x0d, 0x95, 0xb6, 0x03,
  24694. 0x80, 0x1f, 0xd5, 0x75, 0xb6, 0x1d, 0x79, 0x02, 0x93, 0x43, 0x77, 0xa7,
  24695. 0x9d, 0x2f, 0xc3, 0x84, 0xc6, 0x83, 0x76, 0x16, 0x06, 0x98, 0x7b, 0x79
  24696. }
  24697. },
  24698. #endif /* WOLFSSL_SHA384 */
  24699. };
  24700. static const char protocolLabel[] = "tls13 ";
  24701. static const char ceTrafficLabel[] = "c e traffic";
  24702. static const char eExpMasterLabel[] = "e exp master";
  24703. static const char cHsTrafficLabel[] = "c hs traffic";
  24704. static const char sHsTrafficLabel[] = "s hs traffic";
  24705. static const char cAppTrafficLabel[] = "c ap traffic";
  24706. static const char sAppTrafficLabel[] = "s ap traffic";
  24707. static const char expMasterLabel[] = "exp master";
  24708. static const char resMasterLabel[] = "res master";
  24709. static const char derivedLabel[] = "derived";
  24710. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void)
  24711. {
  24712. wc_test_ret_t ret = 0;
  24713. word32 i;
  24714. word32 tc = sizeof(tls13KdfTestVectors)/sizeof(Tls13KdfTestVector);
  24715. const Tls13KdfTestVector* tv = NULL;
  24716. WOLFSSL_ENTER("tls13_kdf_test");
  24717. for (i = 0, tv = tls13KdfTestVectors; i < tc; i++, tv++) {
  24718. byte output[WC_MAX_DIGEST_SIZE];
  24719. byte secret[WC_MAX_DIGEST_SIZE];
  24720. byte salt[WC_MAX_DIGEST_SIZE];
  24721. byte zeroes[WC_MAX_DIGEST_SIZE];
  24722. byte hashZero[WC_MAX_DIGEST_SIZE];
  24723. int hashAlgSz;
  24724. XMEMSET(zeroes, 0, sizeof zeroes);
  24725. hashAlgSz = wc_HashGetDigestSize(tv->hashAlg);
  24726. if (hashAlgSz == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) break;
  24727. ret = wc_Hash(tv->hashAlg, NULL, 0, hashZero, (word32)hashAlgSz);
  24728. if (ret != 0) break;
  24729. ret = wc_Tls13_HKDF_Extract(secret, NULL, 0,
  24730. (tv->pskSz == 0) ? zeroes : (byte*)tv->psk,
  24731. tv->pskSz, (int)tv->hashAlg);
  24732. if (ret != 0) break;
  24733. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24734. secret, (word32)hashAlgSz,
  24735. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24736. (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel),
  24737. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24738. if (ret != 0) break;
  24739. ret = XMEMCMP(tv->clientEarlyTrafficSecret, output,
  24740. (unsigned long)hashAlgSz);
  24741. if (ret != 0) break;
  24742. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24743. secret, (word32)hashAlgSz,
  24744. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24745. (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel),
  24746. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24747. if (ret != 0) break;
  24748. ret = XMEMCMP(tv->earlyExporterMasterSecret, output,
  24749. (unsigned long)hashAlgSz);
  24750. if (ret != 0) break;
  24751. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24752. secret, (word32)hashAlgSz,
  24753. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24754. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24755. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24756. if (ret != 0) break;
  24757. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24758. (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe,
  24759. tv->dheSz, (int)tv->hashAlg);
  24760. if (ret != 0) break;
  24761. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24762. secret, (word32)hashAlgSz,
  24763. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24764. (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel),
  24765. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24766. if (ret != 0) break;
  24767. ret = XMEMCMP(tv->clientHandshakeTrafficSecret,
  24768. output, (unsigned long)hashAlgSz);
  24769. if (ret != 0) break;
  24770. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24771. secret, (word32)hashAlgSz,
  24772. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24773. (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel),
  24774. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24775. if (ret != 0) break;
  24776. ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output,
  24777. (unsigned long)hashAlgSz);
  24778. if (ret != 0) break;
  24779. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24780. secret, (word32)hashAlgSz,
  24781. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24782. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24783. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24784. if (ret != 0) break;
  24785. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24786. zeroes, (word32)(word32)hashAlgSz, (int)tv->hashAlg);
  24787. if (ret != 0) break;
  24788. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24789. secret, (word32)hashAlgSz,
  24790. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24791. (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel),
  24792. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24793. if (ret != 0) break;
  24794. ret = XMEMCMP(tv->clientApplicationTrafficSecret, output,
  24795. (unsigned long)hashAlgSz);
  24796. if (ret != 0) break;
  24797. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24798. secret, (word32)hashAlgSz,
  24799. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24800. (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel),
  24801. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24802. if (ret != 0) break;
  24803. ret = XMEMCMP(tv->serverApplicationTrafficSecret, output,
  24804. (unsigned long)hashAlgSz);
  24805. if (ret != 0) break;
  24806. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24807. secret, (word32)hashAlgSz,
  24808. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24809. (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel),
  24810. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24811. if (ret != 0) break;
  24812. ret = XMEMCMP(tv->exporterMasterSecret, output, (unsigned long)hashAlgSz);
  24813. if (ret != 0) break;
  24814. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24815. secret, (word32)hashAlgSz,
  24816. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24817. (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel),
  24818. tv->hashFinished2, (word32)hashAlgSz, (int)tv->hashAlg);
  24819. if (ret != 0) break;
  24820. ret = XMEMCMP(tv->resumptionMasterSecret, output,
  24821. (unsigned long)hashAlgSz);
  24822. if (ret != 0) break;
  24823. }
  24824. return ret;
  24825. }
  24826. #endif /* WOLFSSL_TLS13 */
  24827. static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point --
  24828. * see print_fiducials() below.
  24829. */
  24830. #if defined(HAVE_ECC) && defined(HAVE_X963_KDF)
  24831. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void)
  24832. {
  24833. wc_test_ret_t ret;
  24834. byte kek[128];
  24835. #ifndef NO_SHA
  24836. /* SHA-1, COUNT = 0
  24837. * shared secret length: 192
  24838. * SharedInfo length: 0
  24839. * key data length: 128
  24840. */
  24841. WOLFSSL_SMALL_STACK_STATIC const byte Z[] = {
  24842. 0x1c, 0x7d, 0x7b, 0x5f, 0x05, 0x97, 0xb0, 0x3d,
  24843. 0x06, 0xa0, 0x18, 0x46, 0x6e, 0xd1, 0xa9, 0x3e,
  24844. 0x30, 0xed, 0x4b, 0x04, 0xdc, 0x64, 0xcc, 0xdd
  24845. };
  24846. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  24847. 0xbf, 0x71, 0xdf, 0xfd, 0x8f, 0x4d, 0x99, 0x22,
  24848. 0x39, 0x36, 0xbe, 0xb4, 0x6f, 0xee, 0x8c, 0xcc
  24849. };
  24850. #endif
  24851. #ifndef NO_SHA256
  24852. /* SHA-256, COUNT = 3
  24853. * shared secret length: 192
  24854. * SharedInfo length: 0
  24855. * key data length: 128
  24856. */
  24857. WOLFSSL_SMALL_STACK_STATIC const byte Z2[] = {
  24858. 0xd3, 0x8b, 0xdb, 0xe5, 0xc4, 0xfc, 0x16, 0x4c,
  24859. 0xdd, 0x96, 0x7f, 0x63, 0xc0, 0x4f, 0xe0, 0x7b,
  24860. 0x60, 0xcd, 0xe8, 0x81, 0xc2, 0x46, 0x43, 0x8c
  24861. };
  24862. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  24863. 0x5e, 0x67, 0x4d, 0xb9, 0x71, 0xba, 0xc2, 0x0a,
  24864. 0x80, 0xba, 0xd0, 0xd4, 0x51, 0x4d, 0xc4, 0x84
  24865. };
  24866. #endif
  24867. #ifdef WOLFSSL_SHA512
  24868. /* SHA-512, COUNT = 0
  24869. * shared secret length: 192
  24870. * SharedInfo length: 0
  24871. * key data length: 128
  24872. */
  24873. WOLFSSL_SMALL_STACK_STATIC const byte Z3[] = {
  24874. 0x87, 0xfc, 0x0d, 0x8c, 0x44, 0x77, 0x48, 0x5b,
  24875. 0xb5, 0x74, 0xf5, 0xfc, 0xea, 0x26, 0x4b, 0x30,
  24876. 0x88, 0x5d, 0xc8, 0xd9, 0x0a, 0xd8, 0x27, 0x82
  24877. };
  24878. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  24879. 0x94, 0x76, 0x65, 0xfb, 0xb9, 0x15, 0x21, 0x53,
  24880. 0xef, 0x46, 0x02, 0x38, 0x50, 0x6a, 0x02, 0x45
  24881. };
  24882. /* SHA-512, COUNT = 0
  24883. * shared secret length: 521
  24884. * SharedInfo length: 128
  24885. * key data length: 1024
  24886. */
  24887. WOLFSSL_SMALL_STACK_STATIC const byte Z4[] = {
  24888. 0x00, 0xaa, 0x5b, 0xb7, 0x9b, 0x33, 0xe3, 0x89,
  24889. 0xfa, 0x58, 0xce, 0xad, 0xc0, 0x47, 0x19, 0x7f,
  24890. 0x14, 0xe7, 0x37, 0x12, 0xf4, 0x52, 0xca, 0xa9,
  24891. 0xfc, 0x4c, 0x9a, 0xdb, 0x36, 0x93, 0x48, 0xb8,
  24892. 0x15, 0x07, 0x39, 0x2f, 0x1a, 0x86, 0xdd, 0xfd,
  24893. 0xb7, 0xc4, 0xff, 0x82, 0x31, 0xc4, 0xbd, 0x0f,
  24894. 0x44, 0xe4, 0x4a, 0x1b, 0x55, 0xb1, 0x40, 0x47,
  24895. 0x47, 0xa9, 0xe2, 0xe7, 0x53, 0xf5, 0x5e, 0xf0,
  24896. 0x5a, 0x2d
  24897. };
  24898. WOLFSSL_SMALL_STACK_STATIC const byte info4[] = {
  24899. 0xe3, 0xb5, 0xb4, 0xc1, 0xb0, 0xd5, 0xcf, 0x1d,
  24900. 0x2b, 0x3a, 0x2f, 0x99, 0x37, 0x89, 0x5d, 0x31
  24901. };
  24902. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  24903. 0x44, 0x63, 0xf8, 0x69, 0xf3, 0xcc, 0x18, 0x76,
  24904. 0x9b, 0x52, 0x26, 0x4b, 0x01, 0x12, 0xb5, 0x85,
  24905. 0x8f, 0x7a, 0xd3, 0x2a, 0x5a, 0x2d, 0x96, 0xd8,
  24906. 0xcf, 0xfa, 0xbf, 0x7f, 0xa7, 0x33, 0x63, 0x3d,
  24907. 0x6e, 0x4d, 0xd2, 0xa5, 0x99, 0xac, 0xce, 0xb3,
  24908. 0xea, 0x54, 0xa6, 0x21, 0x7c, 0xe0, 0xb5, 0x0e,
  24909. 0xef, 0x4f, 0x6b, 0x40, 0xa5, 0xc3, 0x02, 0x50,
  24910. 0xa5, 0xa8, 0xee, 0xee, 0x20, 0x80, 0x02, 0x26,
  24911. 0x70, 0x89, 0xdb, 0xf3, 0x51, 0xf3, 0xf5, 0x02,
  24912. 0x2a, 0xa9, 0x63, 0x8b, 0xf1, 0xee, 0x41, 0x9d,
  24913. 0xea, 0x9c, 0x4f, 0xf7, 0x45, 0xa2, 0x5a, 0xc2,
  24914. 0x7b, 0xda, 0x33, 0xca, 0x08, 0xbd, 0x56, 0xdd,
  24915. 0x1a, 0x59, 0xb4, 0x10, 0x6c, 0xf2, 0xdb, 0xbc,
  24916. 0x0a, 0xb2, 0xaa, 0x8e, 0x2e, 0xfa, 0x7b, 0x17,
  24917. 0x90, 0x2d, 0x34, 0x27, 0x69, 0x51, 0xce, 0xcc,
  24918. 0xab, 0x87, 0xf9, 0x66, 0x1c, 0x3e, 0x88, 0x16
  24919. };
  24920. #endif
  24921. WOLFSSL_ENTER("x963kdf_test");
  24922. #ifndef NO_SHA
  24923. ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0,
  24924. kek, sizeof(verify));
  24925. if (ret != 0)
  24926. return WC_TEST_RET_ENC_EC(ret);
  24927. if (XMEMCMP(verify, kek, sizeof(verify)) != 0)
  24928. return WC_TEST_RET_ENC_NC;
  24929. #endif
  24930. #ifndef NO_SHA256
  24931. ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0,
  24932. kek, sizeof(verify2));
  24933. if (ret != 0)
  24934. return WC_TEST_RET_ENC_EC(ret);
  24935. if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0)
  24936. return WC_TEST_RET_ENC_NC;
  24937. #endif
  24938. #ifdef WOLFSSL_SHA512
  24939. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0,
  24940. kek, sizeof(verify3));
  24941. if (ret != 0)
  24942. return WC_TEST_RET_ENC_EC(ret);
  24943. if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0)
  24944. return WC_TEST_RET_ENC_NC;
  24945. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4,
  24946. sizeof(info4), kek, sizeof(verify4));
  24947. if (ret != 0)
  24948. return WC_TEST_RET_ENC_EC(ret);
  24949. if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0)
  24950. return WC_TEST_RET_ENC_NC;
  24951. #endif
  24952. return 0;
  24953. }
  24954. #endif /* HAVE_X963_KDF */
  24955. #if defined(HAVE_HPKE) && \
  24956. (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) && \
  24957. defined(HAVE_AESGCM)
  24958. static wc_test_ret_t hpke_test_single(Hpke* hpke)
  24959. {
  24960. wc_test_ret_t ret = 0;
  24961. int rngRet = 0;
  24962. WC_RNG rng[1];
  24963. const char* start_text = "this is a test";
  24964. const char* info_text = "info";
  24965. const char* aad_text = "aad";
  24966. byte ciphertext[MAX_HPKE_LABEL_SZ];
  24967. byte plaintext[MAX_HPKE_LABEL_SZ];
  24968. void* receiverKey = NULL;
  24969. void* ephemeralKey = NULL;
  24970. #ifdef WOLFSSL_SMALL_STACK
  24971. byte *pubKey = NULL; /* public key */
  24972. word16 pubKeySz = (word16)HPKE_Npk_MAX;
  24973. #else
  24974. byte pubKey[HPKE_Npk_MAX]; /* public key */
  24975. word16 pubKeySz = (word16)sizeof(pubKey);
  24976. #endif
  24977. rngRet = ret = wc_InitRng(rng);
  24978. if (ret != 0)
  24979. return WC_TEST_RET_ENC_EC(ret);
  24980. #ifdef WOLFSSL_SMALL_STACK
  24981. if (ret == 0) {
  24982. pubKey = (byte *)XMALLOC(pubKeySz, HEAP_HINT,
  24983. DYNAMIC_TYPE_TMP_BUFFER);
  24984. if (pubKey == NULL)
  24985. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  24986. }
  24987. #endif
  24988. /* generate the keys */
  24989. if (ret == 0) {
  24990. ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng);
  24991. if (ret != 0)
  24992. ret = WC_TEST_RET_ENC_EC(ret);
  24993. }
  24994. if (ret == 0) {
  24995. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng);
  24996. if (ret != 0)
  24997. ret = WC_TEST_RET_ENC_EC(ret);
  24998. }
  24999. /* seal */
  25000. if (ret == 0) {
  25001. ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey,
  25002. (byte*)info_text, (word32)XSTRLEN(info_text),
  25003. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25004. (byte*)start_text, (word32)XSTRLEN(start_text),
  25005. ciphertext);
  25006. if (ret != 0)
  25007. ret = WC_TEST_RET_ENC_EC(ret);
  25008. }
  25009. /* export ephemeral key */
  25010. if (ret == 0) {
  25011. ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz);
  25012. if (ret != 0)
  25013. ret = WC_TEST_RET_ENC_EC(ret);
  25014. }
  25015. /* open with exported ephemeral key */
  25016. if (ret == 0) {
  25017. ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz,
  25018. (byte*)info_text, (word32)XSTRLEN(info_text),
  25019. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25020. ciphertext, (word32)XSTRLEN(start_text),
  25021. plaintext);
  25022. if (ret != 0)
  25023. ret = WC_TEST_RET_ENC_EC(ret);
  25024. }
  25025. if (ret == 0) {
  25026. ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text));
  25027. if (ret != 0)
  25028. ret = WC_TEST_RET_ENC_NC;
  25029. }
  25030. /* Negative test case with NULL argument */
  25031. if (ret == 0) {
  25032. ret = wc_HpkeGenerateKeyPair(NULL, &receiverKey, rng);
  25033. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25034. ret = WC_TEST_RET_ENC_EC(ret);
  25035. else
  25036. ret = 0;
  25037. }
  25038. if (ret == 0) {
  25039. ret = wc_HpkeGenerateKeyPair(hpke, NULL, rng);
  25040. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25041. ret = WC_TEST_RET_ENC_EC(ret);
  25042. else
  25043. ret = 0;
  25044. }
  25045. if (ret == 0) {
  25046. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, NULL);
  25047. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25048. ret = WC_TEST_RET_ENC_EC(ret);
  25049. else
  25050. ret = 0;
  25051. }
  25052. if (ephemeralKey != NULL)
  25053. wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
  25054. if (receiverKey != NULL)
  25055. wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
  25056. #ifdef WOLFSSL_SMALL_STACK
  25057. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25058. #endif
  25059. if (rngRet == 0)
  25060. wc_FreeRng(rng);
  25061. return ret;
  25062. }
  25063. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void)
  25064. {
  25065. wc_test_ret_t ret = 0;
  25066. Hpke hpke[1];
  25067. WOLFSSL_ENTER("hpke_test");
  25068. #if defined(HAVE_ECC)
  25069. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
  25070. /* p256 */
  25071. ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256,
  25072. HPKE_AES_128_GCM, NULL);
  25073. if (ret != 0)
  25074. return WC_TEST_RET_ENC_EC(ret);
  25075. ret = hpke_test_single(hpke);
  25076. if (ret != 0)
  25077. return ret;
  25078. #endif
  25079. #if defined(WOLFSSL_SHA384) && \
  25080. (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  25081. /* p384 */
  25082. ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384,
  25083. HPKE_AES_128_GCM, NULL);
  25084. if (ret != 0)
  25085. return WC_TEST_RET_ENC_EC(ret);
  25086. ret = hpke_test_single(hpke);
  25087. if (ret != 0)
  25088. return ret;
  25089. #endif
  25090. #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \
  25091. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25092. /* p521 */
  25093. ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512,
  25094. HPKE_AES_128_GCM, NULL);
  25095. if (ret != 0)
  25096. return WC_TEST_RET_ENC_EC(ret);
  25097. ret = hpke_test_single(hpke);
  25098. if (ret != 0)
  25099. return ret;
  25100. #endif
  25101. #endif
  25102. #if defined(HAVE_CURVE25519)
  25103. /* test with curve25519 and aes256 */
  25104. ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256,
  25105. HPKE_AES_256_GCM, NULL);
  25106. if (ret != 0)
  25107. return WC_TEST_RET_ENC_EC(ret);
  25108. ret = hpke_test_single(hpke);
  25109. if (ret != 0)
  25110. return ret;
  25111. #endif
  25112. #if defined(HAVE_CURVE448) && \
  25113. (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512))
  25114. /* test with curve448 and aes256 */
  25115. ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512,
  25116. HPKE_AES_256_GCM, NULL);
  25117. /* HPKE does not support X448 yet, so expect failure */
  25118. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25119. return WC_TEST_RET_ENC_EC(ret);
  25120. ret = hpke_test_single(hpke);
  25121. /* HPKE does not support X448 yet, so expect failure */
  25122. if (WC_TEST_RET_DEC_EC(ret) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25123. return ret;
  25124. ret = 0; /* reset error code */
  25125. #endif
  25126. /* TODO: HPKE chacha20 is not implemented */
  25127. return ret;
  25128. }
  25129. #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */
  25130. #if defined(WC_SRTP_KDF)
  25131. typedef struct Srtp_Kdf_Tv {
  25132. const unsigned char* key;
  25133. word32 keySz;
  25134. const unsigned char* salt;
  25135. word32 saltSz;
  25136. int kdfIdx;
  25137. const unsigned char* index;
  25138. const unsigned char* ke;
  25139. const unsigned char* ka;
  25140. const unsigned char* ks;
  25141. const unsigned char* index_c;
  25142. const unsigned char* ke_c;
  25143. const unsigned char* ka_c;
  25144. const unsigned char* ks_c;
  25145. word32 keSz;
  25146. word32 kaSz;
  25147. word32 ksSz;
  25148. } Srtp_Kdf_Tv;
  25149. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
  25150. {
  25151. wc_test_ret_t ret = 0;
  25152. /* 128-bit key, kdrIdx = -1 */
  25153. WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = {
  25154. 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72,
  25155. 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90
  25156. };
  25157. WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = {
  25158. 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56,
  25159. 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6
  25160. };
  25161. WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = {
  25162. 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca
  25163. };
  25164. WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = {
  25165. 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a,
  25166. 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f
  25167. };
  25168. WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = {
  25169. 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee,
  25170. 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3,
  25171. 0xbd, 0x32, 0x6e, 0xe4
  25172. };
  25173. WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = {
  25174. 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6,
  25175. 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c
  25176. };
  25177. WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = {
  25178. 0x56, 0xf3, 0xf1, 0x97
  25179. };
  25180. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = {
  25181. 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf,
  25182. 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38
  25183. };
  25184. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = {
  25185. 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba,
  25186. 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7,
  25187. 0xc3, 0xd8, 0x77, 0x0e
  25188. };
  25189. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = {
  25190. 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96,
  25191. 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8
  25192. };
  25193. /* 192-bit key, kdrIdx = 0 */
  25194. WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = {
  25195. 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c,
  25196. 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70,
  25197. 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2
  25198. };
  25199. WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = {
  25200. 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6,
  25201. 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52
  25202. };
  25203. WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = {
  25204. 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76
  25205. };
  25206. WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = {
  25207. 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3,
  25208. 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93,
  25209. 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60
  25210. };
  25211. WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = {
  25212. 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d,
  25213. 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78,
  25214. 0xd1, 0xd1, 0x47, 0x08
  25215. };
  25216. WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = {
  25217. 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe,
  25218. 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea
  25219. };
  25220. WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = {
  25221. 0x40, 0xbf, 0xd4, 0xa9
  25222. };
  25223. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = {
  25224. 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65,
  25225. 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11,
  25226. 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84
  25227. };
  25228. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = {
  25229. 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef,
  25230. 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2,
  25231. 0xf3, 0x3b, 0x8e, 0x29
  25232. };
  25233. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = {
  25234. 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4,
  25235. 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0
  25236. };
  25237. /* 256-bit key, kdrIdx = 1 */
  25238. WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = {
  25239. 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee,
  25240. 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02,
  25241. 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50,
  25242. 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb
  25243. };
  25244. WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = {
  25245. 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74,
  25246. 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a
  25247. };
  25248. WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = {
  25249. 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42
  25250. };
  25251. WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = {
  25252. 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98,
  25253. 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f,
  25254. 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb,
  25255. 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb
  25256. };
  25257. WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = {
  25258. 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84,
  25259. 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57,
  25260. 0x65, 0xc7, 0x50, 0xc1
  25261. };
  25262. WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = {
  25263. 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c,
  25264. 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a
  25265. };
  25266. WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = {
  25267. 0x31, 0x2d, 0x58, 0x15
  25268. };
  25269. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = {
  25270. 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1,
  25271. 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4,
  25272. 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa,
  25273. 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd
  25274. };
  25275. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = {
  25276. 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13,
  25277. 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6,
  25278. 0x35, 0x78, 0xdf, 0xa4
  25279. };
  25280. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = {
  25281. 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f,
  25282. 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff
  25283. };
  25284. /* 128-bit key, kdrIdx = 8 */
  25285. WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = {
  25286. 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76,
  25287. 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04
  25288. };
  25289. WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = {
  25290. 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3,
  25291. 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76
  25292. };
  25293. WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = {
  25294. 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60
  25295. };
  25296. WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = {
  25297. 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2,
  25298. 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74
  25299. };
  25300. WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = {
  25301. 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6,
  25302. 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66,
  25303. 0xea, 0x31, 0x24, 0xe6
  25304. };
  25305. WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = {
  25306. 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a,
  25307. 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f
  25308. };
  25309. WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = {
  25310. 0x4a, 0x7d, 0xaa, 0x85
  25311. };
  25312. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = {
  25313. 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c,
  25314. 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88
  25315. };
  25316. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = {
  25317. 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13,
  25318. 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17,
  25319. 0x05, 0x18, 0xe3, 0xed
  25320. };
  25321. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = {
  25322. 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46,
  25323. 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6
  25324. };
  25325. /* SRTCP w/ 48-bit idx - KDR 0 (-1) */
  25326. WOLFSSL_SMALL_STACK_STATIC const byte mk48_1[] = {
  25327. 0xFF, 0xB6, 0xCB, 0x09, 0x71, 0x3F, 0x63, 0x4D,
  25328. 0x7F, 0x42, 0xED, 0xA8, 0x12, 0x81, 0x50, 0xE6
  25329. };
  25330. WOLFSSL_SMALL_STACK_STATIC const byte ms48_1[] = {
  25331. 0x1F, 0x04, 0x76, 0xC8, 0x7F, 0x58, 0x23, 0xEF,
  25332. 0xD3, 0x57, 0xB2, 0xBD, 0xF1, 0x32
  25333. };
  25334. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_1[] = {
  25335. 0x00, 0x00, 0x08, 0x56, 0xBC, 0x39
  25336. };
  25337. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_1[] = {
  25338. 0xD2, 0xC3, 0xF3, 0x49, 0x00, 0x1A, 0x18, 0x0F,
  25339. 0xB6, 0x05, 0x5A, 0x5A, 0x67, 0x8E, 0xE5, 0xB2
  25340. };
  25341. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_1[] = {
  25342. 0x8D, 0x54, 0xBE, 0xB5, 0x7B, 0x7F, 0x7A, 0xAB,
  25343. 0xF5, 0x46, 0xCE, 0x5B, 0x45, 0x69, 0x4A, 0x75,
  25344. 0x81, 0x2A, 0xE2, 0xCB
  25345. };
  25346. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_1[] = {
  25347. 0x76, 0x3C, 0x97, 0x6A, 0x45, 0x31, 0xA7, 0x79,
  25348. 0x3C, 0x28, 0x4A, 0xA6, 0x82, 0x03
  25349. };
  25350. /* SRTCP w/ 48-bit idx - KDR 19 */
  25351. WOLFSSL_SMALL_STACK_STATIC const byte mk48_2[] = {
  25352. 0xBD, 0x1D, 0x71, 0x6B, 0xDA, 0x28, 0xE3, 0xFC,
  25353. 0xA5, 0xA0, 0x66, 0x3F, 0x2E, 0x34, 0xA8, 0x58
  25354. };
  25355. WOLFSSL_SMALL_STACK_STATIC const byte ms48_2[] = {
  25356. 0x79, 0x06, 0xE5, 0xAB, 0x5C, 0x2B, 0x1B, 0x69,
  25357. 0xFA, 0xEE, 0xD2, 0x29, 0x57, 0x3C
  25358. };
  25359. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_2[] = {
  25360. 0x00, 0x00, 0x59, 0xD0, 0xC2, 0xE8
  25361. };
  25362. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_2[] = {
  25363. 0xB9, 0xD7, 0xAD, 0xD8, 0x90, 0x94, 0xC2, 0x92,
  25364. 0xA5, 0x04, 0x87, 0xC4, 0x8C, 0xEF, 0xE2, 0xA3
  25365. };
  25366. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_2[] = {
  25367. 0x07, 0xD5, 0xC4, 0xD2, 0x06, 0xFB, 0x63, 0x15,
  25368. 0xC2, 0x9C, 0x7F, 0x55, 0xD1, 0x16, 0x5C, 0xB5,
  25369. 0xB7, 0x44, 0x54, 0xBD
  25370. };
  25371. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_2[] = {
  25372. 0x0C, 0x5E, 0x53, 0xC1, 0xD0, 0x75, 0xAD, 0x65,
  25373. 0xBF, 0x51, 0x74, 0x50, 0x89, 0xD7
  25374. };
  25375. int kdr_48_1 = -1;
  25376. int kdr_48_2 = 19;
  25377. #define SRTP_TV_CNT 4
  25378. Srtp_Kdf_Tv tv[SRTP_TV_CNT] = {
  25379. { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1,
  25380. index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0,
  25381. 16, 20, 14 },
  25382. { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0,
  25383. index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1,
  25384. 24, 20, 14 },
  25385. { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1,
  25386. index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2,
  25387. 32, 20, 14 },
  25388. { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8,
  25389. index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3,
  25390. 16, 20, 14 },
  25391. };
  25392. int i;
  25393. int idx;
  25394. unsigned char keyE[32];
  25395. unsigned char keyA[20];
  25396. unsigned char keyS[14];
  25397. WOLFSSL_ENTER("srtpkdf_test");
  25398. for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) {
  25399. #ifndef WOLFSSL_AES_128
  25400. if (tv[i].keySz == AES_128_KEY_SIZE) {
  25401. continue;
  25402. }
  25403. #endif
  25404. #ifndef WOLFSSL_AES_192
  25405. if (tv[i].keySz == AES_192_KEY_SIZE) {
  25406. continue;
  25407. }
  25408. #endif
  25409. #ifndef WOLFSSL_AES_256
  25410. if (tv[i].keySz == AES_256_KEY_SIZE) {
  25411. continue;
  25412. }
  25413. #endif
  25414. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25415. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25416. keyS, tv[i].ksSz);
  25417. if (ret != 0)
  25418. return WC_TEST_RET_ENC_EC(ret);
  25419. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25420. return WC_TEST_RET_ENC_NC;
  25421. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25422. return WC_TEST_RET_ENC_NC;
  25423. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25424. return WC_TEST_RET_ENC_NC;
  25425. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25426. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION,
  25427. keyE, tv[i].keSz);
  25428. if (ret != 0)
  25429. return WC_TEST_RET_ENC_EC(ret);
  25430. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25431. return WC_TEST_RET_ENC_NC;
  25432. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25433. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH,
  25434. keyA, tv[i].kaSz);
  25435. if (ret != 0)
  25436. return WC_TEST_RET_ENC_EC(ret);
  25437. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25438. return WC_TEST_RET_ENC_NC;
  25439. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25440. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS,
  25441. tv[i].ksSz);
  25442. if (ret != 0)
  25443. return WC_TEST_RET_ENC_EC(ret);
  25444. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25445. return WC_TEST_RET_ENC_NC;
  25446. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25447. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25448. keyS, tv[i].ksSz);
  25449. if (ret != 0)
  25450. return WC_TEST_RET_ENC_EC(ret);
  25451. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25452. return WC_TEST_RET_ENC_NC;
  25453. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25454. return WC_TEST_RET_ENC_NC;
  25455. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25456. return WC_TEST_RET_ENC_NC;
  25457. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25458. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c,
  25459. WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz);
  25460. if (ret != 0)
  25461. return WC_TEST_RET_ENC_EC(ret);
  25462. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25463. return WC_TEST_RET_ENC_NC;
  25464. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25465. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH,
  25466. keyA, tv[i].kaSz);
  25467. if (ret != 0)
  25468. return WC_TEST_RET_ENC_EC(ret);
  25469. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25470. return WC_TEST_RET_ENC_NC;
  25471. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25472. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
  25473. keyS, tv[i].ksSz);
  25474. if (ret != 0)
  25475. return WC_TEST_RET_ENC_EC(ret);
  25476. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25477. return WC_TEST_RET_ENC_NC;
  25478. }
  25479. #ifdef WOLFSSL_AES_128
  25480. i = 0;
  25481. #elif defined(WOLFSSL_AES_192)
  25482. i = 1;
  25483. #else
  25484. i = 2;
  25485. #endif
  25486. ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25487. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25488. keyS, tv[i].ksSz);
  25489. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25490. return WC_TEST_RET_ENC_EC(ret);
  25491. ret = wc_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25492. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25493. keyS, tv[i].ksSz);
  25494. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25495. return WC_TEST_RET_ENC_EC(ret);
  25496. ret = wc_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25497. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25498. keyS, tv[i].ksSz);
  25499. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25500. return WC_TEST_RET_ENC_EC(ret);
  25501. ret = wc_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25502. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25503. keyS, tv[i].ksSz);
  25504. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25505. return WC_TEST_RET_ENC_EC(ret);
  25506. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25507. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25508. keyS, tv[i].ksSz);
  25509. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25510. return WC_TEST_RET_ENC_EC(ret);
  25511. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25512. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25513. keyS, tv[i].ksSz);
  25514. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25515. return WC_TEST_RET_ENC_EC(ret);
  25516. ret = wc_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25517. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25518. keyS, tv[i].ksSz);
  25519. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25520. return WC_TEST_RET_ENC_EC(ret);
  25521. ret = wc_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25522. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25523. keyS, tv[i].ksSz);
  25524. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25525. return WC_TEST_RET_ENC_EC(ret);
  25526. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25527. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25528. keyS, tv[i].ksSz);
  25529. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25530. return WC_TEST_RET_ENC_EC(ret);
  25531. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25532. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25533. keyS, tv[i].ksSz);
  25534. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25535. return WC_TEST_RET_ENC_EC(ret);
  25536. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25537. 25, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25538. keyS, tv[i].ksSz);
  25539. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25540. return WC_TEST_RET_ENC_EC(ret);
  25541. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25542. 25, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25543. keyS, tv[i].ksSz);
  25544. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25545. return WC_TEST_RET_ENC_EC(ret);
  25546. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25547. -2, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25548. keyS, tv[i].ksSz);
  25549. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25550. return WC_TEST_RET_ENC_EC(ret);
  25551. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25552. -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25553. keyS, tv[i].ksSz);
  25554. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25555. return WC_TEST_RET_ENC_EC(ret);
  25556. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25557. tv[i].kdfIdx, tv[i].index, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25558. keyS, tv[i].ksSz);
  25559. if (ret != 0)
  25560. return WC_TEST_RET_ENC_EC(ret);
  25561. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25562. tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25563. keyS, tv[i].ksSz);
  25564. if (ret != 0)
  25565. return WC_TEST_RET_ENC_EC(ret);
  25566. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25567. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25568. keyS, tv[i].ksSz);
  25569. if (ret != 0)
  25570. return WC_TEST_RET_ENC_EC(ret);
  25571. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25572. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25573. keyS, tv[i].ksSz);
  25574. if (ret != 0)
  25575. return WC_TEST_RET_ENC_EC(ret);
  25576. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25577. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25578. NULL, tv[i].ksSz);
  25579. if (ret != 0)
  25580. return WC_TEST_RET_ENC_EC(ret);
  25581. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25582. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25583. NULL, tv[i].ksSz);
  25584. if (ret != 0)
  25585. return WC_TEST_RET_ENC_EC(ret);
  25586. idx = wc_SRTP_KDF_kdr_to_idx(0);
  25587. if (idx != -1)
  25588. return WC_TEST_RET_ENC_NC;
  25589. for (i = 0; i < 32; i++) {
  25590. word32 kdr = 1U << i;
  25591. /* SRTCP w/ 48-bit IDX, 128-bit key test */
  25592. if (i == 0) {
  25593. ret = wc_SRTCP_KDF_ex(mk48_1, (word32)sizeof(mk48_1),
  25594. ms48_1, (word32)sizeof(ms48_1),
  25595. kdr_48_1, srtcp48idx_1, keyE, tv[i].keSz,
  25596. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25597. WC_SRTCP_48BIT_IDX);
  25598. if (ret != 0)
  25599. return WC_TEST_RET_ENC_EC(ret);
  25600. if (XMEMCMP(keyE, srtcpKe_48_1, tv[i].keSz) != 0)
  25601. return WC_TEST_RET_ENC_NC;
  25602. if (XMEMCMP(keyA, srtcpKa_48_1, tv[i].kaSz) != 0)
  25603. return WC_TEST_RET_ENC_NC;
  25604. if (XMEMCMP(keyS, srtcpKs_48_1, tv[i].ksSz) != 0)
  25605. return WC_TEST_RET_ENC_NC;
  25606. ret = wc_SRTCP_KDF_ex(mk48_2, (word32)sizeof(mk48_2),
  25607. ms48_2, (word32)sizeof(ms48_2),
  25608. kdr_48_2, srtcp48idx_2, keyE, tv[i].keSz,
  25609. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25610. WC_SRTCP_48BIT_IDX);
  25611. if (ret != 0)
  25612. return WC_TEST_RET_ENC_EC(ret);
  25613. if (XMEMCMP(keyE, srtcpKe_48_2, tv[i].keSz) != 0)
  25614. return WC_TEST_RET_ENC_NC;
  25615. if (XMEMCMP(keyA, srtcpKa_48_2, tv[i].kaSz) != 0)
  25616. return WC_TEST_RET_ENC_NC;
  25617. if (XMEMCMP(keyS, srtcpKs_48_2, tv[i].ksSz) != 0)
  25618. return WC_TEST_RET_ENC_NC;
  25619. }
  25620. idx = wc_SRTP_KDF_kdr_to_idx(kdr);
  25621. if (idx != i)
  25622. return WC_TEST_RET_ENC_NC;
  25623. }
  25624. return 0;
  25625. }
  25626. #endif
  25627. #ifdef HAVE_ECC
  25628. /* size to use for ECC key gen tests */
  25629. #ifndef ECC_KEYGEN_SIZE
  25630. #if !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  25631. #define ECC_KEYGEN_SIZE 32
  25632. #elif defined(HAVE_ECC384)
  25633. #define ECC_KEYGEN_SIZE 48
  25634. #elif defined(HAVE_ECC224)
  25635. #define ECC_KEYGEN_SIZE 28
  25636. #elif defined(HAVE_ECC521)
  25637. #define ECC_KEYGEN_SIZE 66
  25638. #else
  25639. #error No ECC keygen size defined for test
  25640. #endif
  25641. #endif
  25642. #ifdef BENCH_EMBEDDED
  25643. #define ECC_SHARED_SIZE 128
  25644. #else
  25645. #define ECC_SHARED_SIZE MAX_ECC_BYTES
  25646. #endif
  25647. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  25648. #define HAVE_ECC_DETERMINISTIC_K
  25649. #define ECC_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  25650. #else
  25651. #define ECC_DIGEST_SIZE MAX_ECC_BYTES
  25652. #endif
  25653. #define ECC_SIG_SIZE ECC_MAX_SIG_SIZE
  25654. #ifdef NO_ECC_SECP
  25655. #define NO_ECC_VECTOR_TEST
  25656. #endif
  25657. #ifndef NO_ECC_VECTOR_TEST
  25658. #if (defined(HAVE_ECC192) || defined(HAVE_ECC224) ||\
  25659. !defined(NO_ECC256) || defined(HAVE_ECC384) ||\
  25660. defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25661. #define HAVE_ECC_VECTOR_TEST
  25662. #endif
  25663. #endif
  25664. #ifdef HAVE_ECC_VECTOR_TEST
  25665. typedef struct eccVector {
  25666. const char* msg; /* SHA-1 Encoded Message */
  25667. const char* Qx;
  25668. const char* Qy;
  25669. const char* d; /* Private Key */
  25670. const char* R;
  25671. const char* S;
  25672. const char* curveName;
  25673. word32 msgLen;
  25674. word32 keySize;
  25675. const byte* r;
  25676. word32 rSz;
  25677. const byte* s;
  25678. word32 sSz;
  25679. } eccVector;
  25680. #if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  25681. static wc_test_ret_t ecc_test_vector_item(const eccVector* vector)
  25682. {
  25683. wc_test_ret_t ret = 0;
  25684. int verify = 0;
  25685. word32 sigSz;
  25686. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25687. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25688. #else
  25689. ecc_key userA[1];
  25690. #endif
  25691. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25692. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25693. word32 sigRawSz, rSz = MAX_ECC_BYTES, sSz = MAX_ECC_BYTES;
  25694. WC_DECLARE_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25695. WC_DECLARE_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25696. WC_DECLARE_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25697. #endif
  25698. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25699. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25700. WC_ALLOC_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25701. WC_ALLOC_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25702. WC_ALLOC_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25703. #endif
  25704. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  25705. if (sig == NULL)
  25706. ERROR_OUT(MEMORY_E, done);
  25707. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25708. if (sigRaw == NULL || r == NULL || s == NULL)
  25709. ERROR_OUT(MEMORY_E, done);
  25710. #endif
  25711. #endif
  25712. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25713. if (userA == NULL)
  25714. ERROR_OUT(MEMORY_E, done);
  25715. #endif
  25716. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  25717. if (ret != 0)
  25718. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25719. ret = wc_ecc_import_raw(userA, vector->Qx, vector->Qy,
  25720. vector->d, vector->curveName);
  25721. if (ret != 0)
  25722. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25723. #if !defined(NO_ASN)
  25724. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25725. sigSz = ECC_SIG_SIZE;
  25726. ret = wc_ecc_rs_to_sig(vector->R, vector->S, sig, &sigSz);
  25727. if (ret != 0)
  25728. goto done;
  25729. #if !defined(HAVE_SELFTEST)
  25730. XMEMSET(sigRaw, 0, ECC_SIG_SIZE);
  25731. sigRawSz = ECC_SIG_SIZE;
  25732. ret = wc_ecc_rs_raw_to_sig(vector->r, vector->rSz, vector->s, vector->sSz,
  25733. sigRaw, &sigRawSz);
  25734. if (ret != 0)
  25735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25736. if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) {
  25737. ret = WC_TEST_RET_ENC_NC;
  25738. goto done;
  25739. }
  25740. ret = wc_ecc_sig_to_rs(sig, sigSz, r, &rSz, s, &sSz);
  25741. if (ret != 0)
  25742. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25743. if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 ||
  25744. sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) {
  25745. ret = WC_TEST_RET_ENC_NC;
  25746. goto done;
  25747. }
  25748. #endif /* !HAVE_SELFTEST */
  25749. #else
  25750. /* Signature will be R+S directly */
  25751. /* Make sure and zero pad if r or s is less than key size */
  25752. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25753. sigSz = vector->keySize * 2;
  25754. XMEMCPY(sig + (vector->keySize - vector->rSz),
  25755. vector->r, vector->rSz);
  25756. XMEMCPY(sig + vector->keySize + (vector->keySize - vector->sSz),
  25757. vector->s, vector->sSz);
  25758. #endif /* !NO_ASN */
  25759. #ifdef HAVE_ECC_VERIFY
  25760. do {
  25761. #if defined(WOLFSSL_ASYNC_CRYPT)
  25762. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25763. #endif
  25764. if (ret == 0)
  25765. ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg,
  25766. vector->msgLen, &verify, userA);
  25767. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25768. if (ret != 0)
  25769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25770. TEST_SLEEP();
  25771. if (verify != 1)
  25772. ret = WC_TEST_RET_ENC_NC;
  25773. #endif
  25774. done:
  25775. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25776. if (userA != NULL) {
  25777. wc_ecc_free(userA);
  25778. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25779. }
  25780. #else
  25781. wc_ecc_free(userA);
  25782. #endif
  25783. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25784. WC_FREE_VAR(sigRaw, HEAP_HINT);
  25785. WC_FREE_VAR(r, HEAP_HINT);
  25786. WC_FREE_VAR(s, HEAP_HINT);
  25787. #endif
  25788. WC_FREE_VAR(sig, HEAP_HINT);
  25789. return ret;
  25790. }
  25791. static wc_test_ret_t ecc_test_vector(int keySize)
  25792. {
  25793. wc_test_ret_t ret;
  25794. eccVector vec;
  25795. XMEMSET(&vec, 0, sizeof(vec));
  25796. vec.keySize = (word32)keySize;
  25797. switch(keySize) {
  25798. #if defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)
  25799. case 14:
  25800. return 0;
  25801. #endif /* HAVE_ECC112 */
  25802. #if defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)
  25803. case 16:
  25804. return 0;
  25805. #endif /* HAVE_ECC128 */
  25806. #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)
  25807. case 20:
  25808. return 0;
  25809. #endif /* HAVE_ECC160 */
  25810. #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
  25811. case 24:
  25812. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  25813. #if 1
  25814. vec.msg = "\x60\x80\x79\x42\x3f\x12\x42\x1d\xe6\x16\xb7\x49\x3e\xbe\x55\x1c\xf4\xd6\x5b\x92";
  25815. vec.msgLen = 20;
  25816. #else
  25817. /* This is the raw message prior to SHA-1 */
  25818. vec.msg =
  25819. "\xeb\xf7\x48\xd7\x48\xeb\xbc\xa7\xd2\x9f\xb4\x73\x69\x8a\x6e\x6b"
  25820. "\x4f\xb1\x0c\x86\x5d\x4a\xf0\x24\xcc\x39\xae\x3d\xf3\x46\x4b\xa4"
  25821. "\xf1\xd6\xd4\x0f\x32\xbf\x96\x18\xa9\x1b\xb5\x98\x6f\xa1\xa2\xaf"
  25822. "\x04\x8a\x0e\x14\xdc\x51\xe5\x26\x7e\xb0\x5e\x12\x7d\x68\x9d\x0a"
  25823. "\xc6\xf1\xa7\xf1\x56\xce\x06\x63\x16\xb9\x71\xcc\x7a\x11\xd0\xfd"
  25824. "\x7a\x20\x93\xe2\x7c\xf2\xd0\x87\x27\xa4\xe6\x74\x8c\xc3\x2f\xd5"
  25825. "\x9c\x78\x10\xc5\xb9\x01\x9d\xf2\x1c\xdc\xc0\xbc\xa4\x32\xc0\xa3"
  25826. "\xee\xd0\x78\x53\x87\x50\x88\x77\x11\x43\x59\xce\xe4\xa0\x71\xcf";
  25827. vec.msgLen = 128;
  25828. #endif
  25829. vec.Qx = "07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6";
  25830. vec.Qy = "76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477";
  25831. vec.d = "e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3";
  25832. vec.R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  25833. vec.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  25834. vec.curveName = "SECP192R1";
  25835. vec.r = (byte*)"\x69\x94\xd9\x62\xbd\xd0\xd7\x93\xff\xdd\xf8\x55"
  25836. "\xec\x5b\xf2\xf9\x1a\x96\x98\xb4\x62\x58\xa6\x3e";
  25837. vec.rSz = 24;
  25838. vec.s = (byte*)"\x02\xba\x64\x65\xa2\x34\x90\x37\x44\xab\x02\xbc"
  25839. "\x85\x21\x40\x5b\x73\xcf\x5f\xc0\x0e\x1a\x9f\x41";
  25840. vec.sSz = 24;
  25841. break;
  25842. #endif /* HAVE_ECC192 */
  25843. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  25844. case 28:
  25845. /* first [P-224,SHA-1] vector from FIPS 186-3 NIST vectors */
  25846. #if 1
  25847. vec.msg = "\xb9\xa3\xb8\x6d\xb0\xba\x99\xfd\xc6\xd2\x94\x6b\xfe\xbe\x9c\xe8\x3f\x10\x74\xfc";
  25848. vec.msgLen = 20;
  25849. #else
  25850. /* This is the raw message prior to SHA-1 */
  25851. vec.msg =
  25852. "\x36\xc8\xb2\x29\x86\x48\x7f\x67\x7c\x18\xd0\x97\x2a\x9e\x20\x47"
  25853. "\xb3\xaf\xa5\x9e\xc1\x62\x76\x4e\xc3\x0b\x5b\x69\xe0\x63\x0f\x99"
  25854. "\x0d\x4e\x05\xc2\x73\xb0\xe5\xa9\xd4\x28\x27\xb6\x95\xfc\x2d\x64"
  25855. "\xd9\x13\x8b\x1c\xf4\xc1\x21\x55\x89\x4c\x42\x13\x21\xa7\xbb\x97"
  25856. "\x0b\xdc\xe0\xfb\xf0\xd2\xae\x85\x61\xaa\xd8\x71\x7f\x2e\x46\xdf"
  25857. "\xe3\xff\x8d\xea\xb4\xd7\x93\x23\x56\x03\x2c\x15\x13\x0d\x59\x9e"
  25858. "\x26\xc1\x0f\x2f\xec\x96\x30\x31\xac\x69\x38\xa1\x8d\x66\x45\x38"
  25859. "\xb9\x4d\xac\x55\x34\xef\x7b\x59\x94\x24\xd6\x9b\xe1\xf7\x1c\x20";
  25860. vec.msgLen = 128;
  25861. #endif
  25862. vec.Qx = "8a4dca35136c4b70e588e23554637ae251077d1365a6ba5db9585de7";
  25863. vec.Qy = "ad3dee06de0be8279d4af435d7245f14f3b4f82eb578e519ee0057b1";
  25864. vec.d = "97c4b796e1639dd1035b708fc00dc7ba1682cec44a1002a1a820619f";
  25865. vec.R = "147b33758321e722a0360a4719738af848449e2c1d08defebc1671a7";
  25866. vec.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b";
  25867. vec.curveName = "SECP224R1";
  25868. vec.r = (byte*)"\x14\x7b\x33\x75\x83\x21\xe7\x22\xa0\x36\x0a\x47"
  25869. "\x19\x73\x8a\xf8\x48\x44\x9e\x2c\x1d\x08\xde\xfe"
  25870. "\xbc\x16\x71\xa7";
  25871. vec.rSz = 28;
  25872. vec.s = (byte*)"\x24\xfc\x7e\xd7\xf1\x35\x2c\xa3\x87\x2a\xa0\x91"
  25873. "\x61\x91\x28\x9e\x2e\x04\xd4\x54\x93\x5d\x50\xfe"
  25874. "\x6a\xf3\xad\x5b";
  25875. vec.sSz = 28;
  25876. break;
  25877. #endif /* HAVE_ECC224 */
  25878. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  25879. case 30:
  25880. return 0;
  25881. #endif /* HAVE_ECC239 */
  25882. #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
  25883. case 32:
  25884. /* first [P-256,SHA-1] vector from FIPS 186-3 NIST vectors */
  25885. #if 1
  25886. vec.msg = "\xa3\xf9\x1a\xe2\x1b\xa6\xb3\x03\x98\x64\x47\x2f\x18\x41\x44\xc6\xaf\x62\xcd\x0e";
  25887. vec.msgLen = 20;
  25888. #else
  25889. /* This is the raw message prior to SHA-1 */
  25890. vec.msg =
  25891. "\xa2\x4b\x21\x76\x2e\x6e\xdb\x15\x3c\xc1\x14\x38\xdb\x0e\x92\xcd"
  25892. "\xf5\x2b\x86\xb0\x6c\xa9\x70\x16\x06\x27\x59\xc7\x0d\x36\xd1\x56"
  25893. "\x2c\xc9\x63\x0d\x7f\xc7\xc7\x74\xb2\x8b\x54\xe3\x1e\xf5\x58\x72"
  25894. "\xb2\xa6\x5d\xf1\xd7\xec\x26\xde\xbb\x33\xe7\xd9\x27\xef\xcc\xf4"
  25895. "\x6b\x63\xde\x52\xa4\xf4\x31\xea\xca\x59\xb0\x5d\x2e\xde\xc4\x84"
  25896. "\x5f\xff\xc0\xee\x15\x03\x94\xd6\x1f\x3d\xfe\xcb\xcd\xbf\x6f\x5a"
  25897. "\x73\x38\xd0\xbe\x3f\x2a\x77\x34\x51\x98\x3e\xba\xeb\x48\xf6\x73"
  25898. "\x8f\xc8\x95\xdf\x35\x7e\x1a\x48\xa6\x53\xbb\x35\x5a\x31\xa1\xb4"
  25899. vec.msgLen = 128;
  25900. #endif
  25901. vec.Qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  25902. vec.Qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  25903. vec.d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  25904. vec.R = "2b826f5d44e2d0b6de531ad96b51e8f0c56fdfead3c236892e4d84eacfc3b75c";
  25905. vec.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248";
  25906. vec.r = (byte*)"\x2b\x82\x6f\x5d\x44\xe2\xd0\xb6\xde\x53\x1a\xd9"
  25907. "\x6b\x51\xe8\xf0\xc5\x6f\xdf\xea\xd3\xc2\x36\x89"
  25908. "\x2e\x4d\x84\xea\xcf\xc3\xb7\x5c";
  25909. vec.rSz = 32;
  25910. vec.s = (byte*)"\xa2\x24\x8b\x62\xc0\x3d\xb3\x5a\x7c\xd6\x3e\x8a"
  25911. "\x12\x0a\x35\x21\xa8\x9d\x3d\x2f\x61\xff\x99\x03"
  25912. "\x5a\x21\x48\xae\x32\xe3\xa2\x48";
  25913. vec.sSz = 32;
  25914. vec.curveName = "SECP256R1";
  25915. break;
  25916. #endif /* !NO_ECC256 */
  25917. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  25918. case 40:
  25919. return 0;
  25920. #endif /* HAVE_ECC320 */
  25921. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  25922. case 48:
  25923. /* first [P-384,SHA-1] vector from FIPS 186-3 NIST vectors */
  25924. #if 1
  25925. vec.msg = "\x9b\x9f\x8c\x95\x35\xa5\xca\x26\x60\x5d\xb7\xf2\xfa\x57\x3b\xdf\xc3\x2e\xab\x8b";
  25926. vec.msgLen = 20;
  25927. #else
  25928. /* This is the raw message prior to SHA-1 */
  25929. vec.msg =
  25930. "\xab\xe1\x0a\xce\x13\xe7\xe1\xd9\x18\x6c\x48\xf7\x88\x9d\x51\x47"
  25931. "\x3d\x3a\x09\x61\x98\x4b\xc8\x72\xdf\x70\x8e\xcc\x3e\xd3\xb8\x16"
  25932. "\x9d\x01\xe3\xd9\x6f\xc4\xf1\xd5\xea\x00\xa0\x36\x92\xbc\xc5\xcf"
  25933. "\xfd\x53\x78\x7c\x88\xb9\x34\xaf\x40\x4c\x03\x9d\x32\x89\xb5\xba"
  25934. "\xc5\xae\x7d\xb1\x49\x68\x75\xb5\xdc\x73\xc3\x09\xf9\x25\xc1\x3d"
  25935. "\x1c\x01\xab\xda\xaf\xeb\xcd\xac\x2c\xee\x43\x39\x39\xce\x8d\x4a"
  25936. "\x0a\x5d\x57\xbb\x70\x5f\x3b\xf6\xec\x08\x47\x95\x11\xd4\xb4\xa3"
  25937. "\x21\x1f\x61\x64\x9a\xd6\x27\x43\x14\xbf\x0d\x43\x8a\x81\xe0\x60"
  25938. vec.msgLen = 128;
  25939. #endif
  25940. vec.Qx = "e55fee6c49d8d523f5ce7bf9c0425ce4ff650708b7de5cfb095901523979a7f042602db30854735369813b5c3f5ef868";
  25941. vec.Qy = "28f59cc5dc509892a988d38a8e2519de3d0c4fd0fbdb0993e38f18506c17606c5e24249246f1ce94983a5361c5be983e";
  25942. vec.d = "a492ce8fa90084c227e1a32f7974d39e9ff67a7e8705ec3419b35fb607582bebd461e0b1520ac76ec2dd4e9b63ebae71";
  25943. vec.R = "6820b8585204648aed63bdff47f6d9acebdea62944774a7d14f0e14aa0b9a5b99545b2daee6b3c74ebf606667a3f39b7";
  25944. vec.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907";
  25945. vec.curveName = "SECP384R1";
  25946. vec.r = (byte*)"\x68\x20\xb8\x58\x52\x04\x64\x8a\xed\x63\xbd\xff"
  25947. "\x47\xf6\xd9\xac\xeb\xde\xa6\x29\x44\x77\x4a\x7d"
  25948. "\x14\xf0\xe1\x4a\xa0\xb9\xa5\xb9\x95\x45\xb2\xda"
  25949. "\xee\x6b\x3c\x74\xeb\xf6\x06\x66\x7a\x3f\x39\xb7";
  25950. vec.rSz = 48;
  25951. vec.s = (byte*)"\x49\x1a\xf1\xd0\xcc\xcd\x56\xdd\xd5\x20\xb2\x33"
  25952. "\x77\x5d\x0b\xc6\xb4\x0a\x62\x55\xcc\x55\x20\x7d"
  25953. "\x8e\x93\x56\x74\x1f\x23\xc9\x6c\x14\x71\x42\x21"
  25954. "\x07\x8d\xbd\x5c\x17\xf4\xfd\xd8\x9b\x32\xa9\x07";
  25955. vec.sSz = 48;
  25956. break;
  25957. #endif /* HAVE_ECC384 */
  25958. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  25959. case 64:
  25960. return 0;
  25961. #endif /* HAVE_ECC512 */
  25962. #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  25963. case 66:
  25964. /* first [P-521,SHA-1] vector from FIPS 186-3 NIST vectors */
  25965. #if 1
  25966. vec.msg = "\x1b\xf7\x03\x9c\xca\x23\x94\x27\x3f\x11\xa1\xd4\x8d\xcc\xb4\x46\x6f\x31\x61\xdf";
  25967. vec.msgLen = 20;
  25968. #else
  25969. /* This is the raw message prior to SHA-1 */
  25970. vec.msg =
  25971. "\x50\x3f\x79\x39\x34\x0a\xc7\x23\xcd\x4a\x2f\x4e\x6c\xcc\x27\x33"
  25972. "\x38\x3a\xca\x2f\xba\x90\x02\x19\x9d\x9e\x1f\x94\x8b\xe0\x41\x21"
  25973. "\x07\xa3\xfd\xd5\x14\xd9\x0c\xd4\xf3\x7c\xc3\xac\x62\xef\x00\x3a"
  25974. "\x2d\xb1\xd9\x65\x7a\xb7\x7f\xe7\x55\xbf\x71\xfa\x59\xe4\xd9\x6e"
  25975. "\xa7\x2a\xe7\xbf\x9d\xe8\x7d\x79\x34\x3b\xc1\xa4\xbb\x14\x4d\x16"
  25976. "\x28\xd1\xe9\xe9\xc8\xed\x80\x8b\x96\x2c\x54\xe5\xf9\x6d\x53\xda"
  25977. "\x14\x7a\x96\x38\xf9\x4a\x91\x75\xd8\xed\x61\x05\x5f\x0b\xa5\x73"
  25978. "\xa8\x2b\xb7\xe0\x18\xee\xda\xc4\xea\x7b\x36\x2e\xc8\x9c\x38\x2b"
  25979. vec.msgLen = 128;
  25980. #endif
  25981. vec.Qx = "12fbcaeffa6a51f3ee4d3d2b51c5dec6d7c726ca353fc014ea2bf7cfbb9b910d32cbfa6a00fe39b6cdb8946f22775398b2e233c0cf144d78c8a7742b5c7a3bb5d23";
  25982. vec.Qy = "09cdef823dd7bf9a79e8cceacd2e4527c231d0ae5967af0958e931d7ddccf2805a3e618dc3039fec9febbd33052fe4c0fee98f033106064982d88f4e03549d4a64d";
  25983. vec.d = "1bd56bd106118eda246155bd43b42b8e13f0a6e25dd3bb376026fab4dc92b6157bc6dfec2d15dd3d0cf2a39aa68494042af48ba9601118da82c6f2108a3a203ad74";
  25984. vec.R = "0bd117b4807710898f9dd7778056485777668f0e78e6ddf5b000356121eb7a220e9493c7f9a57c077947f89ac45d5acb6661bbcd17abb3faea149ba0aa3bb1521be";
  25985. vec.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c";
  25986. vec.curveName = "SECP521R1";
  25987. vec.r = (byte*)"\xbd\x11\x7b\x48\x07\x71\x08\x98\xf9\xdd\x77\x78"
  25988. "\x05\x64\x85\x77\x76\x68\xf0\xe7\x8e\x6d\xdf\x5b"
  25989. "\x00\x03\x56\x12\x1e\xb7\xa2\x20\xe9\x49\x3c\x7f"
  25990. "\x9a\x57\xc0\x77\x94\x7f\x89\xac\x45\xd5\xac\xb6"
  25991. "\x66\x1b\xbc\xd1\x7a\xbb\x3f\xae\xa1\x49\xba\x0a"
  25992. "\xa3\xbb\x15\x21\xbe";
  25993. vec.rSz = 65;
  25994. vec.s = (byte*)"\x19\xcd\x2c\x5c\x3f\x98\x70\xec\xde\xb9\xb3\x23"
  25995. "\xab\xdf\x3a\x98\xcd\x5e\x23\x1d\x85\xc6\xdd\xc5"
  25996. "\xb7\x1a\xb1\x90\x73\x9f\x7f\x22\x6e\x6b\x13\x4b"
  25997. "\xa1\xd5\x88\x9d\xde\xb2\x75\x1d\xab\xd9\x79\x11"
  25998. "\xdf\xf9\x0c\x34\x68\x4c\xdb\xe7\xbb\x66\x9b\x6c"
  25999. "\x3d\x22\xf2\x48\x0c";
  26000. vec.sSz = 65;
  26001. break;
  26002. #endif /* HAVE_ECC521 */
  26003. default:
  26004. return WC_TEST_RET_ENC_EC(NOT_COMPILED_IN); /* Invalid key size /
  26005. * Not supported
  26006. */
  26007. }; /* Switch */
  26008. ret = ecc_test_vector_item(&vec);
  26009. if (ret < 0) {
  26010. return ret;
  26011. }
  26012. return 0;
  26013. }
  26014. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26015. #if defined(HAVE_ECC_SIGN) && \
  26016. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  26017. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  26018. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  26019. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  26020. static wc_test_ret_t ecdsa_test_deterministic_k_sig(ecc_key *key,
  26021. enum wc_HashType hashType, const char* msg, WC_RNG* rng, const byte* expSig,
  26022. size_t expSigSz)
  26023. {
  26024. wc_test_ret_t ret;
  26025. int verify;
  26026. byte sig[ECC_MAX_SIG_SIZE];
  26027. word32 sigSz;
  26028. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26029. ret = wc_Hash(hashType,
  26030. (byte*)msg, (word32)XSTRLEN(msg),
  26031. hash, sizeof(hash));
  26032. if (ret != 0)
  26033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26034. /* Sign test */
  26035. sigSz = sizeof(sig);
  26036. do {
  26037. #if defined(WOLFSSL_ASYNC_CRYPT)
  26038. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26039. #endif
  26040. if (ret == 0)
  26041. ret = wc_ecc_sign_hash(hash, wc_HashGetDigestSize(hashType),
  26042. sig, &sigSz, rng, key);
  26043. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26044. if (ret != 0)
  26045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26046. TEST_SLEEP();
  26047. /* Compare test vector */
  26048. if (sigSz != expSigSz) {
  26049. ret = WC_TEST_RET_ENC_NC;
  26050. goto done;
  26051. }
  26052. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26053. ret = WC_TEST_RET_ENC_NC;
  26054. goto done;
  26055. }
  26056. /* Verification */
  26057. verify = 0;
  26058. do {
  26059. #if defined(WOLFSSL_ASYNC_CRYPT)
  26060. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26061. #endif
  26062. if (ret == 0)
  26063. ret = wc_ecc_verify_hash(sig, sigSz,
  26064. hash, wc_HashGetDigestSize(hashType), &verify, key);
  26065. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26066. if (ret != 0)
  26067. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26068. if (verify != 1) {
  26069. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26070. }
  26071. done:
  26072. return ret;
  26073. }
  26074. static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
  26075. {
  26076. wc_test_ret_t ret;
  26077. #ifdef WOLFSSL_SMALL_STACK
  26078. ecc_key *key = NULL;
  26079. #else
  26080. ecc_key key[1];
  26081. #endif
  26082. int key_inited = 0;
  26083. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26084. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26085. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721";
  26086. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26087. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6";
  26088. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26089. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299";
  26090. #ifndef NO_SHA256
  26091. WOLFSSL_SMALL_STACK_STATIC const byte expSig256[] = {
  26092. 0x30, 0x46, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26093. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26094. 0x00, 0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8,
  26095. 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81,
  26096. 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9,
  26097. 0x91, 0xC3, 0x4D, 0x0E, 0xA8, 0x4E, 0xAF, 0x37,
  26098. 0x16,
  26099. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26100. 0x00, 0xF7, 0xCB, 0x1C, 0x94, 0x2D, 0x65, 0x7C,
  26101. 0x41, 0xD4, 0x36, 0xC7, 0xA1, 0xB6, 0xE2, 0x9F,
  26102. 0x65, 0xF3, 0xE9, 0x00, 0xDB, 0xB9, 0xAF, 0xF4,
  26103. 0x06, 0x4D, 0xC4, 0xAB, 0x2F, 0x84, 0x3A, 0xCD,
  26104. 0xA8
  26105. };
  26106. #endif
  26107. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26108. WOLFSSL_SMALL_STACK_STATIC const byte expSig384[] = {
  26109. 0x30, 0x44, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26110. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26111. 0x0e, 0xaf, 0xea, 0x03, 0x9b, 0x20, 0xe9, 0xb4,
  26112. 0x23, 0x09, 0xfb, 0x1d, 0x89, 0xe2, 0x13, 0x05,
  26113. 0x7c, 0xbf, 0x97, 0x3d, 0xc0, 0xcf, 0xc8, 0xf1,
  26114. 0x29, 0xed, 0xdd, 0xc8, 0x00, 0xef, 0x77, 0x19,
  26115. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26116. 0x48, 0x61, 0xf0, 0x49, 0x1e, 0x69, 0x98, 0xb9,
  26117. 0x45, 0x51, 0x93, 0xe3, 0x4e, 0x7b, 0x0d, 0x28,
  26118. 0x4d, 0xdd, 0x71, 0x49, 0xa7, 0x4b, 0x95, 0xb9,
  26119. 0x26, 0x1f, 0x13, 0xab, 0xde, 0x94, 0x09, 0x54
  26120. };
  26121. #endif
  26122. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26123. WOLFSSL_SMALL_STACK_STATIC const byte expSig512[] = {
  26124. 0x30, 0x45, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26125. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26126. 0x00, 0x84, 0x96, 0xa6, 0x0b, 0x5e, 0x9b, 0x47,
  26127. 0xc8, 0x25, 0x48, 0x88, 0x27, 0xe0, 0x49, 0x5b,
  26128. 0x0e, 0x3f, 0xa1, 0x09, 0xec, 0x45, 0x68, 0xfd,
  26129. 0x3f, 0x8d, 0x10, 0x97, 0x67, 0x8e, 0xb9, 0x7f,
  26130. 0x00,
  26131. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26132. 0x23, 0x62, 0xab, 0x1a, 0xdb, 0xe2, 0xb8, 0xad,
  26133. 0xf9, 0xcb, 0x9e, 0xda, 0xb7, 0x40, 0xea, 0x60,
  26134. 0x49, 0xc0, 0x28, 0x11, 0x4f, 0x24, 0x60, 0xf9,
  26135. 0x65, 0x54, 0xf6, 0x1f, 0xae, 0x33, 0x02, 0xfe
  26136. };
  26137. #endif
  26138. #ifdef WOLFSSL_SMALL_STACK
  26139. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26140. if (key == NULL)
  26141. return MEMORY_E;
  26142. #endif
  26143. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26144. if (ret != 0)
  26145. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26146. key_inited = 1;
  26147. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26148. if (ret != 0)
  26149. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26150. ret = wc_ecc_set_deterministic(key, 1);
  26151. if (ret != 0)
  26152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26153. #ifndef NO_SHA256
  26154. /* Test for SHA2-256 */
  26155. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA256, msg, rng,
  26156. expSig256, sizeof(expSig256));
  26157. if (ret != 0)
  26158. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26159. #endif /* !NO_SHA256 */
  26160. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26161. /* Test for SHA2-384 */
  26162. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA384, msg, rng,
  26163. expSig384, sizeof(expSig384));
  26164. if (ret != 0)
  26165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26166. #endif /* WOLFSSL_SHA384 */
  26167. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26168. /* Test for SHA2-512 */
  26169. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA512, msg, rng,
  26170. expSig512, sizeof(expSig512));
  26171. if (ret != 0)
  26172. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26173. #endif /* WOLFSSL_SHA512 */
  26174. done:
  26175. if (key_inited)
  26176. wc_ecc_free(key);
  26177. #ifdef WOLFSSL_SMALL_STACK
  26178. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26179. #endif
  26180. return ret;
  26181. }
  26182. #endif /* NO_ECC256 || HAVE_ALL_CURVES */
  26183. #ifdef WOLFSSL_PUBLIC_MP
  26184. static wc_test_ret_t ecdsa_test_deterministic_k_rs(ecc_key *key,
  26185. enum wc_HashType hashType, const char* msg, WC_RNG* rng,
  26186. mp_int* r, mp_int* s,
  26187. mp_int* expR, mp_int* expS)
  26188. {
  26189. wc_test_ret_t ret;
  26190. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26191. int verify;
  26192. ret = wc_Hash(hashType,
  26193. (byte*)msg, (word32)XSTRLEN(msg),
  26194. hash, sizeof(hash));
  26195. if (ret != 0)
  26196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26197. ret = wc_ecc_sign_hash_ex(hash, wc_HashGetDigestSize(hashType), rng, key,
  26198. r, s);
  26199. #if defined(WOLFSSL_ASYNC_CRYPT)
  26200. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26201. #endif
  26202. if (ret != 0)
  26203. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26204. TEST_SLEEP();
  26205. if (mp_cmp(r, expR) != MP_EQ && mp_cmp(s, expS) != MP_EQ) {
  26206. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26207. }
  26208. /* Verification */
  26209. verify = 0;
  26210. ret = wc_ecc_verify_hash_ex(r, s, hash, wc_HashGetDigestSize(hashType),
  26211. &verify, key);
  26212. #if defined(WOLFSSL_ASYNC_CRYPT)
  26213. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26214. #endif
  26215. if (ret != 0)
  26216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26217. if (verify != 1) {
  26218. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26219. }
  26220. done:
  26221. return ret;
  26222. }
  26223. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  26224. /* KAT from RFC6979 */
  26225. static wc_test_ret_t ecc384_test_deterministic_k(WC_RNG* rng)
  26226. {
  26227. wc_test_ret_t ret;
  26228. #ifdef WOLFSSL_SMALL_STACK
  26229. ecc_key *key;
  26230. mp_int *r, *s, *expR, *expS;
  26231. #else
  26232. ecc_key key[1];
  26233. mp_int r[1], s[1], expR[1], expS[1];
  26234. #endif
  26235. int key_inited = 0,
  26236. tmp_mp_ints_inited = 0;
  26237. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26238. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26239. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8"
  26240. "96D5724E4C70A825F872C9EA60D2EDF5";
  26241. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26242. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64"
  26243. "DEF8F0EA9055866064A254515480BC13";
  26244. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26245. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1"
  26246. "288B231C3AE0D4FE7344FD2533264720";
  26247. #ifndef NO_SHA256
  26248. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26249. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33"
  26250. "BDE1E888E63355D92FA2B3C36D8FB2CD";
  26251. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26252. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB"
  26253. "EFDC63ECCD1AC42EC0CB8668A4FA0AB0";
  26254. #endif
  26255. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26256. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26257. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C"
  26258. "81A648152E44ACF96E36DD1E80FABE46";
  26259. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26260. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F"
  26261. "A329C145786E679E7B82C71A38628AC8";
  26262. #endif
  26263. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26264. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26265. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C"
  26266. "FE30F35CC900056D7C99CD7882433709";
  26267. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26268. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112"
  26269. "DC7CC3EF3446DEFCEB01A45C2667FDD5";
  26270. #endif
  26271. #ifdef WOLFSSL_SMALL_STACK
  26272. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26273. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26274. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26275. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26276. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26277. if ((key == NULL) ||
  26278. (r == NULL) ||
  26279. (s == NULL) ||
  26280. (expR == NULL) ||
  26281. (expS == NULL))
  26282. {
  26283. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26284. }
  26285. #endif
  26286. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26287. if (ret != MP_OKAY)
  26288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26289. tmp_mp_ints_inited = 1;
  26290. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26291. if (ret != 0)
  26292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26293. key_inited = 1;
  26294. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP384R1");
  26295. if (ret != 0)
  26296. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26297. ret = wc_ecc_set_deterministic(key, 1);
  26298. if (ret != 0)
  26299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26300. #ifndef NO_SHA256
  26301. /* Test for SHA2-256 */
  26302. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26303. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26304. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26305. r, s, expR, expS);
  26306. if (ret != 0)
  26307. ERROR_OUT(ret, done);
  26308. #endif /* NO_SHA256 */
  26309. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26310. /* Test for SHA2-384 */
  26311. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26312. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26313. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26314. r, s, expR, expS);
  26315. if (ret != 0)
  26316. ERROR_OUT(ret, done);
  26317. #endif /* WOLFSSL_SHA384 */
  26318. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26319. /* Test for SHA2-512 */
  26320. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26321. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26322. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26323. r, s, expR, expS);
  26324. if (ret != 0)
  26325. ERROR_OUT(ret, done);
  26326. #endif /* WOLFSSL_SHA512 */
  26327. done:
  26328. if (key_inited)
  26329. wc_ecc_free(key);
  26330. if (tmp_mp_ints_inited) {
  26331. mp_free(r);
  26332. mp_free(s);
  26333. mp_free(expR);
  26334. mp_free(expS);
  26335. }
  26336. #ifdef WOLFSSL_SMALL_STACK
  26337. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26338. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26339. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26340. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26341. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26342. #endif
  26343. return ret;
  26344. }
  26345. #endif /* HAVE_ECC384 */
  26346. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  26347. /* KAT from RFC6979 */
  26348. static wc_test_ret_t ecc521_test_deterministic_k(WC_RNG* rng)
  26349. {
  26350. wc_test_ret_t ret;
  26351. #ifdef WOLFSSL_SMALL_STACK
  26352. ecc_key *key;
  26353. mp_int *r, *s, *expR, *expS;
  26354. #else
  26355. ecc_key key[1];
  26356. mp_int r[1], s[1], expR[1], expS[1];
  26357. #endif
  26358. int key_inited = 0,
  26359. tmp_mp_ints_inited = 0;
  26360. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26361. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26362. "0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C"
  26363. "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83"
  26364. "538";
  26365. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26366. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD3"
  26367. "71123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F502"
  26368. "3A4";
  26369. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26370. "0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A2"
  26371. "8A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDF"
  26372. "CF5";
  26373. #ifndef NO_SHA256
  26374. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26375. "1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659"
  26376. "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E"
  26377. "1A7";
  26378. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26379. "04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916"
  26380. "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E"
  26381. "CFC";
  26382. #endif
  26383. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26384. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26385. "1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4"
  26386. "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67"
  26387. "451";
  26388. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26389. "1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5"
  26390. "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65"
  26391. "D61";
  26392. #endif
  26393. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26394. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26395. "0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1"
  26396. "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37"
  26397. "7FA";
  26398. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26399. "0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2"
  26400. "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A"
  26401. "67A";
  26402. #endif
  26403. #ifdef WOLFSSL_SMALL_STACK
  26404. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26405. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26406. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26407. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26408. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26409. if ((key == NULL) ||
  26410. (r == NULL) ||
  26411. (s == NULL) ||
  26412. (expR == NULL) ||
  26413. (expS == NULL))
  26414. {
  26415. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26416. goto done;
  26417. }
  26418. #endif
  26419. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26420. if (ret != MP_OKAY)
  26421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26422. tmp_mp_ints_inited = 1;
  26423. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26424. if (ret != 0)
  26425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26426. key_inited = 1;
  26427. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP521R1");
  26428. if (ret != 0)
  26429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26430. ret = wc_ecc_set_deterministic(key, 1);
  26431. if (ret != 0)
  26432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26433. #ifndef NO_SHA256
  26434. /* Test for SHA2-256 */
  26435. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26436. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26437. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26438. r, s, expR, expS);
  26439. if (ret != 0)
  26440. ERROR_OUT(ret, done);
  26441. #endif /* NO_SHA256 */
  26442. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26443. /* Test for SHA2-384 */
  26444. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26445. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26446. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26447. r, s, expR, expS);
  26448. if (ret != 0)
  26449. ERROR_OUT(ret, done);
  26450. #endif /* WOLFSSL_SHA384 */
  26451. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26452. /* Test for SHA2-512 */
  26453. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26454. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26455. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26456. r, s, expR, expS);
  26457. if (ret != 0)
  26458. ERROR_OUT(ret, done);
  26459. #endif /* WOLFSSL_SHA512 */
  26460. done:
  26461. if (key_inited)
  26462. wc_ecc_free(key);
  26463. if (tmp_mp_ints_inited) {
  26464. mp_free(r);
  26465. mp_free(s);
  26466. mp_free(expR);
  26467. mp_free(expS);
  26468. }
  26469. #ifdef WOLFSSL_SMALL_STACK
  26470. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26471. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26472. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26473. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26474. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26475. #endif
  26476. return ret;
  26477. }
  26478. #endif /* HAVE_ECC521 */
  26479. #endif /* WOLFSSL_PUBLIC_MP */
  26480. #endif /* HAVE_ECC_SIGN && (WOLFSSL_ECDSA_DETERMINISTIC_K ||
  26481. WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  26482. && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  26483. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  26484. !defined(WOLFSSL_KCAPI_ECC)
  26485. static wc_test_ret_t ecc_test_sign_vectors(WC_RNG* rng)
  26486. {
  26487. wc_test_ret_t ret;
  26488. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26489. ecc_key *key = NULL;
  26490. #else
  26491. ecc_key key[1];
  26492. #endif
  26493. int key_inited = 0;
  26494. byte sig[72];
  26495. word32 sigSz;
  26496. WOLFSSL_SMALL_STACK_STATIC const unsigned char hash[32] = "test wolfSSL deterministic sign";
  26497. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26498. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26499. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26500. WOLFSSL_SMALL_STACK_STATIC const byte k[1] = { 0x02 };
  26501. WOLFSSL_SMALL_STACK_STATIC const byte expSig[71] = {
  26502. 0x30, 0x45, 0x02, 0x20, 0x7c, 0xf2, 0x7b, 0x18,
  26503. 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03,
  26504. 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2,
  26505. 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc,
  26506. 0x47, 0x66, 0x99, 0x78, 0x02, 0x21, 0x00, 0xa8,
  26507. 0x43, 0xa0, 0xce, 0x6c, 0x5e, 0x17, 0x8a, 0x53,
  26508. 0x4d, 0xaf, 0xd2, 0x95, 0x78, 0x9f, 0x84, 0x4f,
  26509. 0x94, 0xb8, 0x75, 0xa3, 0x19, 0xa5, 0xd4, 0xdf,
  26510. 0xe1, 0xd4, 0x5e, 0x9d, 0x97, 0xfe, 0x81
  26511. };
  26512. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26513. if ((key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  26514. return MEMORY_E;
  26515. #endif
  26516. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26517. if (ret != 0)
  26518. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26519. key_inited = 1;
  26520. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26521. if (ret != 0)
  26522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26523. #if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \
  26524. && (HAVE_FIPS_VERSION > 2)))
  26525. wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN);
  26526. #endif
  26527. ret = wc_ecc_sign_set_k(k, sizeof(k), key);
  26528. if (ret != 0)
  26529. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26530. sigSz = sizeof(sig);
  26531. do {
  26532. #if defined(WOLFSSL_ASYNC_CRYPT)
  26533. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26534. #endif
  26535. if (ret == 0)
  26536. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26537. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26538. if (ret != 0)
  26539. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26540. TEST_SLEEP();
  26541. if (sigSz != sizeof(expSig)) {
  26542. ret = WC_TEST_RET_ENC_NC;
  26543. goto done;
  26544. }
  26545. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26546. ret = WC_TEST_RET_ENC_NC;
  26547. goto done;
  26548. }
  26549. sigSz = sizeof(sig);
  26550. do {
  26551. #if defined(WOLFSSL_ASYNC_CRYPT)
  26552. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26553. #endif
  26554. if (ret == 0)
  26555. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26556. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26557. if (ret != 0)
  26558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26559. TEST_SLEEP();
  26560. done:
  26561. if (key_inited)
  26562. wc_ecc_free(key);
  26563. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26564. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26565. #endif
  26566. return ret;
  26567. }
  26568. #endif
  26569. #if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE)
  26570. static wc_test_ret_t ecc_test_cdh_vectors(WC_RNG* rng)
  26571. {
  26572. wc_test_ret_t ret;
  26573. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26574. ecc_key *pub_key = (ecc_key *)XMALLOC(sizeof *pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26575. ecc_key *priv_key = (ecc_key *)XMALLOC(sizeof *priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26576. #else
  26577. ecc_key pub_key[1], priv_key[1];
  26578. #endif
  26579. byte sharedA[32] = {0}, sharedB[32] = {0};
  26580. word32 x, z;
  26581. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
  26582. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
  26583. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26584. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26585. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26586. WOLFSSL_SMALL_STACK_STATIC const char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b";
  26587. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26588. if ((pub_key == NULL) ||
  26589. (priv_key == NULL)) {
  26590. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26591. goto done;
  26592. }
  26593. #endif
  26594. XMEMSET(pub_key, 0, sizeof *pub_key);
  26595. XMEMSET(priv_key, 0, sizeof *priv_key);
  26596. /* setup private and public keys */
  26597. ret = wc_ecc_init_ex(pub_key, HEAP_HINT, devId);
  26598. if (ret != 0)
  26599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26600. ret = wc_ecc_init_ex(priv_key, HEAP_HINT, devId);
  26601. if (ret != 0)
  26602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26603. wc_ecc_set_flags(pub_key, WC_ECC_FLAG_COFACTOR);
  26604. wc_ecc_set_flags(priv_key, WC_ECC_FLAG_COFACTOR);
  26605. ret = wc_ecc_import_raw(pub_key, QCAVSx, QCAVSy, NULL, "SECP256R1");
  26606. if (ret != 0)
  26607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26608. ret = wc_ecc_import_raw(priv_key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26609. if (ret != 0)
  26610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26611. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26612. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26613. !defined(HAVE_SELFTEST)
  26614. ret = wc_ecc_set_rng(priv_key, rng);
  26615. if (ret != 0)
  26616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26617. #else
  26618. (void)rng;
  26619. #endif
  26620. /* compute ECC Cofactor shared secret */
  26621. x = sizeof(sharedA);
  26622. do {
  26623. #if defined(WOLFSSL_ASYNC_CRYPT)
  26624. ret = wc_AsyncWait(ret, &priv_key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26625. #endif
  26626. if (ret == 0)
  26627. ret = wc_ecc_shared_secret(priv_key, pub_key, sharedA, &x);
  26628. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26629. if (ret != 0)
  26630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26631. TEST_SLEEP();
  26632. /* read in expected Z */
  26633. z = sizeof(sharedB);
  26634. ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
  26635. if (ret != 0)
  26636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26637. /* compare results */
  26638. if (x != z || XMEMCMP(sharedA, sharedB, x)) {
  26639. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26640. }
  26641. done:
  26642. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26643. if (priv_key) {
  26644. wc_ecc_free(priv_key);
  26645. XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26646. }
  26647. if (pub_key) {
  26648. wc_ecc_free(pub_key);
  26649. XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26650. }
  26651. #else
  26652. wc_ecc_free(priv_key);
  26653. wc_ecc_free(pub_key);
  26654. #endif
  26655. return ret;
  26656. }
  26657. #endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */
  26658. #endif /* HAVE_ECC_VECTOR_TEST */
  26659. #ifdef HAVE_ECC_KEY_IMPORT
  26660. /* returns 0 on success */
  26661. static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
  26662. {
  26663. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26664. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26665. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26666. ecc_key *pub = (ecc_key *)XMALLOC(sizeof *pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26667. #endif
  26668. byte *exportBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26669. byte *tmp = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26670. #else
  26671. ecc_key key[1];
  26672. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  26673. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26674. ecc_key pub[1];
  26675. #endif
  26676. byte exportBuf[ECC_BUFSIZE];
  26677. byte tmp[ECC_BUFSIZE];
  26678. #endif
  26679. const byte* msg = (const byte*)"test wolfSSL ECC public gen";
  26680. word32 x;
  26681. word32 tmpSz;
  26682. wc_test_ret_t ret = 0;
  26683. ecc_point* pubPoint = NULL;
  26684. #ifdef HAVE_ECC_VERIFY
  26685. int verify = 0;
  26686. #endif
  26687. #ifdef NO_ASN
  26688. /* private d for eccKeyDerFile / ecc_key_der_256 */
  26689. const byte keyPriv[] = {
  26690. 0x45, 0xB6, 0x69, 0x02, 0x73, 0x9C, 0x6C, 0x85,
  26691. 0xA1, 0x38, 0x5B, 0x72, 0xE8, 0xE8, 0xC7, 0xAC,
  26692. 0xC4, 0x03, 0x8D, 0x53, 0x35, 0x04, 0xFA, 0x6C,
  26693. 0x28, 0xDC, 0x34, 0x8D, 0xE1, 0xA8, 0x09, 0x8C
  26694. };
  26695. #endif
  26696. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26697. if ((key == NULL) ||
  26698. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26699. (pub == NULL) ||
  26700. #endif
  26701. (exportBuf == NULL) ||
  26702. (tmp == NULL))
  26703. ERROR_OUT(MEMORY_E, done);
  26704. #endif
  26705. (void)msg;
  26706. (void)verify;
  26707. (void)exportBuf;
  26708. (void)rng;
  26709. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26710. #ifndef NO_ECC256
  26711. #if defined(USE_CERT_BUFFERS_256)
  26712. {
  26713. XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
  26714. tmpSz = (size_t)sizeof_ecc_key_der_256;
  26715. }
  26716. #elif !defined(NO_FILESYSTEM)
  26717. {
  26718. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  26719. if (!file) {
  26720. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26721. }
  26722. tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file);
  26723. XFCLOSE(file);
  26724. if (tmpSz == 0)
  26725. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26726. }
  26727. #else
  26728. {
  26729. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
  26730. ERROR_OUT(ASN_PARSE_E, done);
  26731. }
  26732. #endif /* USE_CERT_BUFFERS_256 */
  26733. /* import private only then test with */
  26734. ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL);
  26735. if (ret == 0) {
  26736. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26737. }
  26738. ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key);
  26739. if (ret == 0) {
  26740. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26741. }
  26742. #ifndef NO_ASN
  26743. x = 0;
  26744. ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz);
  26745. if (ret != 0)
  26746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26747. #ifdef HAVE_ECC_KEY_EXPORT
  26748. x = ECC_BUFSIZE;
  26749. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26750. if (ret != 0)
  26751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26752. /* make private only key */
  26753. wc_ecc_free(key);
  26754. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26755. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26756. if (ret != 0)
  26757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26758. x = ECC_BUFSIZE;
  26759. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26760. if (ret == 0) {
  26761. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26762. }
  26763. #endif /* HAVE_ECC_KEY_EXPORT */
  26764. #else
  26765. /* Load raw private d directly */
  26766. ret = wc_ecc_import_private_key(keyPriv, sizeof(keyPriv), NULL, 0, key);
  26767. #endif /* !NO_ASN */
  26768. ret = wc_ecc_make_pub(NULL, NULL);
  26769. if (ret == 0) {
  26770. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26771. }
  26772. TEST_SLEEP();
  26773. #ifndef WOLFSSL_NO_MALLOC
  26774. pubPoint = wc_ecc_new_point_h(HEAP_HINT);
  26775. if (pubPoint == NULL) {
  26776. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26777. }
  26778. #if !defined(WOLFSSL_CRYPTOCELL)
  26779. ret = wc_ecc_make_pub(key, pubPoint);
  26780. #if defined(WOLFSSL_ASYNC_CRYPT)
  26781. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26782. #endif
  26783. if (ret != 0)
  26784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26785. #endif /* !WOLFSSL_CRYPTOCELL */
  26786. TEST_SLEEP();
  26787. #ifdef HAVE_ECC_KEY_EXPORT
  26788. /* export should still fail, is private only key */
  26789. x = ECC_BUFSIZE;
  26790. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26791. if (ret == 0) {
  26792. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26793. }
  26794. #endif /* HAVE_ECC_KEY_EXPORT */
  26795. #endif /* !WOLFSSL_NO_MALLOC */
  26796. #endif /* !NO_ECC256 */
  26797. /* create a new key since above test for loading key is not supported */
  26798. #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \
  26799. defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \
  26800. defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM)
  26801. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  26802. if (ret != 0)
  26803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26804. #endif
  26805. #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \
  26806. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG))) && \
  26807. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(HAVE_ECC_DETERMINISTIC_K)
  26808. tmpSz = ECC_BUFSIZE;
  26809. ret = 0;
  26810. do {
  26811. #if defined(WOLFSSL_ASYNC_CRYPT)
  26812. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26813. #endif
  26814. if (ret == 0) {
  26815. ret = wc_ecc_sign_hash(msg, (word32)XSTRLEN((const char* )msg), tmp,
  26816. &tmpSz, rng, key);
  26817. }
  26818. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26819. if (ret != 0)
  26820. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26821. TEST_SLEEP();
  26822. #ifdef HAVE_ECC_VERIFY
  26823. /* try verify with private only key */
  26824. ret = 0;
  26825. do {
  26826. #if defined(WOLFSSL_ASYNC_CRYPT)
  26827. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26828. #endif
  26829. if (ret == 0) {
  26830. ret = wc_ecc_verify_hash(tmp, tmpSz, msg,
  26831. (word32)XSTRLEN((const char*)msg), &verify, key);
  26832. }
  26833. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26834. if (ret != 0)
  26835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26836. if (verify != 1) {
  26837. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26838. }
  26839. TEST_SLEEP();
  26840. #ifdef HAVE_ECC_KEY_EXPORT
  26841. /* exporting the public part should now work */
  26842. x = ECC_BUFSIZE;
  26843. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26844. if (ret != 0)
  26845. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26846. #endif /* HAVE_ECC_KEY_EXPORT */
  26847. #endif /* HAVE_ECC_VERIFY */
  26848. #endif /* HAVE_ECC_SIGN */
  26849. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  26850. /* now test private only key with creating a shared secret */
  26851. x = ECC_BUFSIZE;
  26852. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26853. if (ret != 0)
  26854. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26855. #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050)
  26856. /* make private only key */
  26857. wc_ecc_free(key);
  26858. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26859. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26860. if (ret != 0)
  26861. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26862. /* check that public export fails with private only key */
  26863. x = ECC_BUFSIZE;
  26864. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26865. if (ret == 0) {
  26866. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26867. }
  26868. #endif /* WOLFSSL_QNX_CAAM */
  26869. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  26870. /* make public key for shared secret */
  26871. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  26872. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, pub);
  26873. #ifdef HAVE_ECC_CDH
  26874. wc_ecc_set_flags(key, WC_ECC_FLAG_COFACTOR);
  26875. #endif
  26876. #if defined(WOLFSSL_ASYNC_CRYPT)
  26877. ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE);
  26878. #endif
  26879. if (ret != 0)
  26880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26881. TEST_SLEEP();
  26882. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26883. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26884. !defined(HAVE_SELFTEST)
  26885. ret = wc_ecc_set_rng(key, rng);
  26886. if (ret != 0)
  26887. goto done;
  26888. #endif
  26889. x = ECC_BUFSIZE;
  26890. do {
  26891. #if defined(WOLFSSL_ASYNC_CRYPT)
  26892. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26893. #endif
  26894. if (ret == 0) {
  26895. ret = wc_ecc_shared_secret(key, pub, exportBuf, &x);
  26896. }
  26897. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26898. wc_ecc_free(pub);
  26899. if (ret != 0)
  26900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26901. TEST_SLEEP();
  26902. #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */
  26903. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26904. ret = 0;
  26905. done:
  26906. wc_ecc_del_point_h(pubPoint, HEAP_HINT);
  26907. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26908. if (key != NULL) {
  26909. wc_ecc_free(key);
  26910. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26911. }
  26912. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26913. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26914. #endif
  26915. XFREE(exportBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26916. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26917. #else
  26918. wc_ecc_free(key);
  26919. #endif
  26920. return ret;
  26921. }
  26922. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26923. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26924. static wc_test_ret_t ecc_test_key_decode(WC_RNG* rng, int keySize)
  26925. {
  26926. wc_test_ret_t ret;
  26927. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26928. ecc_key *eccKey = (ecc_key *)XMALLOC(sizeof *eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26929. byte *tmpBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26930. #else
  26931. ecc_key eccKey[1];
  26932. byte tmpBuf[ECC_BUFSIZE];
  26933. #endif
  26934. word32 tmpSz;
  26935. word32 idx;
  26936. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26937. if ((eccKey == NULL) || (tmpBuf == NULL))
  26938. ERROR_OUT(MEMORY_E, done);
  26939. #endif
  26940. ret = wc_ecc_init(eccKey);
  26941. if (ret != 0) {
  26942. goto done;
  26943. }
  26944. ret = wc_ecc_make_key(rng, keySize, eccKey);
  26945. #if defined(WOLFSSL_ASYNC_CRYPT)
  26946. ret = wc_AsyncWait(ret, &eccKey->asyncDev, WC_ASYNC_FLAG_NONE);
  26947. #endif
  26948. if (ret != 0) {
  26949. goto done;
  26950. }
  26951. tmpSz = ECC_BUFSIZE;
  26952. ret = wc_EccKeyToDer(eccKey, tmpBuf, tmpSz);
  26953. wc_ecc_free(eccKey);
  26954. if (ret < 0) {
  26955. goto done;
  26956. }
  26957. tmpSz = (word32)ret;
  26958. ret = wc_ecc_init(eccKey);
  26959. if (ret != 0) {
  26960. goto done;
  26961. }
  26962. idx = 0;
  26963. ret = wc_EccPrivateKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26964. if (ret != 0) {
  26965. goto done;
  26966. }
  26967. wc_ecc_free(eccKey);
  26968. ret = wc_ecc_init(eccKey);
  26969. if (ret != 0) {
  26970. goto done;
  26971. }
  26972. idx = 0;
  26973. ret = wc_EccPublicKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26974. if (ret != 0) {
  26975. goto done;
  26976. }
  26977. ret = 0;
  26978. done:
  26979. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26980. if (eccKey != NULL) {
  26981. wc_ecc_free(eccKey);
  26982. XFREE(eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26983. }
  26984. XFREE(tmpBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26985. #else
  26986. wc_ecc_free(eccKey);
  26987. #endif
  26988. return ret;
  26989. }
  26990. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26991. #endif /* HAVE_ECC_KEY_IMPORT */
  26992. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26993. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26994. static wc_test_ret_t ecc_test_key_gen(WC_RNG* rng, int keySize)
  26995. {
  26996. wc_test_ret_t ret = 0;
  26997. int derSz;
  26998. #ifdef HAVE_PKCS8
  26999. word32 pkcs8Sz;
  27000. #endif
  27001. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27002. byte *der = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27003. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27004. #else
  27005. byte der[ECC_BUFSIZE];
  27006. ecc_key userA[1];
  27007. #endif
  27008. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27009. if ((der == NULL) || (userA == NULL))
  27010. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  27011. #endif
  27012. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27013. if (ret != 0)
  27014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27015. ret = wc_ecc_make_key(rng, keySize, userA);
  27016. #if defined(WOLFSSL_ASYNC_CRYPT)
  27017. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27018. #endif
  27019. if (ret != 0)
  27020. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27021. TEST_SLEEP();
  27022. ret = wc_ecc_check_key(userA);
  27023. if (ret != 0)
  27024. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27025. TEST_SLEEP();
  27026. derSz = wc_EccKeyToDer(userA, der, ECC_BUFSIZE);
  27027. if (derSz < 0) {
  27028. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27029. }
  27030. ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile,
  27031. ECC_PRIVATEKEY_TYPE);
  27032. if (ret != 0)
  27033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27034. /* test export of public key */
  27035. derSz = wc_EccPublicKeyToDer(userA, der, ECC_BUFSIZE, 1);
  27036. if (derSz < 0) {
  27037. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27038. }
  27039. if (derSz == 0) {
  27040. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27041. }
  27042. #ifdef HAVE_COMP_KEY
  27043. /* test export of compressed public key */
  27044. derSz = wc_EccPublicKeyToDer_ex(userA, der, ECC_BUFSIZE, 1, 1);
  27045. if (derSz < 0) {
  27046. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27047. }
  27048. if (derSz == 0) {
  27049. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27050. }
  27051. #endif
  27052. ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0);
  27053. if (ret != 0)
  27054. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27055. #ifdef HAVE_PKCS8
  27056. /* test export of PKCS#8 unencrypted private key */
  27057. pkcs8Sz = FOURK_BUF;
  27058. derSz = wc_EccPrivateKeyToPKCS8(userA, der, &pkcs8Sz);
  27059. if (derSz < 0) {
  27060. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27061. }
  27062. if (derSz == 0) {
  27063. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27064. }
  27065. ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0);
  27066. if (ret != 0) {
  27067. goto done;
  27068. }
  27069. #endif /* HAVE_PKCS8 */
  27070. done:
  27071. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27072. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27073. if (userA != NULL) {
  27074. wc_ecc_free(userA);
  27075. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27076. }
  27077. #else
  27078. wc_ecc_free(userA);
  27079. #endif
  27080. return ret;
  27081. }
  27082. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  27083. static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
  27084. int curve_id, const ecc_set_type* dp)
  27085. {
  27086. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27087. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27088. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27089. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27090. word32 y;
  27091. #endif
  27092. #ifdef HAVE_ECC_KEY_EXPORT
  27093. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  27094. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27095. #endif
  27096. word32 x = 0;
  27097. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27098. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27099. defined(HAVE_ECC_SIGN)
  27100. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27101. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27102. int i;
  27103. #ifdef HAVE_ECC_VERIFY
  27104. int verify;
  27105. #endif /* HAVE_ECC_VERIFY */
  27106. #endif /* HAVE_ECC_SIGN */
  27107. wc_test_ret_t ret;
  27108. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27109. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27110. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27111. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27112. #else
  27113. ecc_key userA[1];
  27114. ecc_key userB[1];
  27115. ecc_key pubKey[1];
  27116. #endif
  27117. #ifndef WC_NO_RNG
  27118. int curveSize;
  27119. #endif
  27120. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27121. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27122. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27123. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27124. #endif
  27125. #ifdef HAVE_ECC_KEY_EXPORT
  27126. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27127. #endif
  27128. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27129. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27130. defined(HAVE_ECC_SIGN)
  27131. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27132. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27133. #endif
  27134. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  27135. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \
  27136. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27137. if (sharedA == NULL || sharedB == NULL)
  27138. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27139. #endif
  27140. #ifdef HAVE_ECC_KEY_EXPORT
  27141. if (exportBuf == NULL)
  27142. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27143. #endif
  27144. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27145. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27146. defined(HAVE_ECC_SIGN)
  27147. if (sig == NULL || digest == NULL)
  27148. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27149. #endif
  27150. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  27151. (void)testVerifyCount;
  27152. (void)dp;
  27153. (void)x;
  27154. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27155. if ((userA == NULL) ||
  27156. (userB == NULL) ||
  27157. (pubKey == NULL))
  27158. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27159. #endif
  27160. XMEMSET(userA, 0, sizeof *userA);
  27161. XMEMSET(userB, 0, sizeof *userB);
  27162. XMEMSET(pubKey, 0, sizeof *pubKey);
  27163. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27164. if (ret != 0)
  27165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27166. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  27167. if (ret != 0)
  27168. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27169. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27170. if (ret != 0)
  27171. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27172. #ifdef WOLFSSL_CUSTOM_CURVES
  27173. if (dp != NULL) {
  27174. ret = wc_ecc_set_custom_curve(userA, dp);
  27175. if (ret != 0)
  27176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27177. ret = wc_ecc_set_custom_curve(userB, dp);
  27178. if (ret != 0)
  27179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27180. }
  27181. #endif
  27182. #ifndef WC_NO_RNG
  27183. ret = wc_ecc_make_key_ex(rng, keySize, userA, curve_id);
  27184. #if defined(WOLFSSL_ASYNC_CRYPT)
  27185. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27186. #endif
  27187. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  27188. if (ret == WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  27189. ret = 0;
  27190. goto done; /* no software case */
  27191. }
  27192. #endif
  27193. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  27194. goto done; /* catch case, where curve is not supported */
  27195. if (ret != 0)
  27196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27197. TEST_SLEEP();
  27198. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  27199. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  27200. if (curveSize != userA->dp->size)
  27201. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27202. }
  27203. ret = wc_ecc_check_key(userA);
  27204. if (ret != 0)
  27205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27206. TEST_SLEEP();
  27207. /* ATECC508/608 configuration may not support more than one ECDH key */
  27208. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27209. ret = wc_ecc_make_key_ex(rng, keySize, userB, curve_id);
  27210. #if defined(WOLFSSL_ASYNC_CRYPT)
  27211. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  27212. #endif
  27213. if (ret != 0)
  27214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27215. TEST_SLEEP();
  27216. /* only perform the below tests if the key size matches */
  27217. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  27218. /* Not an error, just not a key size match */
  27219. WARNING_OUT(ECC_CURVE_OID_E, done);
  27220. #ifdef HAVE_ECC_DHE
  27221. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27222. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27223. !defined(HAVE_SELFTEST)
  27224. ret = wc_ecc_set_rng(userA, rng);
  27225. if (ret != 0)
  27226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27227. ret = wc_ecc_set_rng(userB, rng);
  27228. if (ret != 0)
  27229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27230. #endif
  27231. x = ECC_SHARED_SIZE;
  27232. do {
  27233. #if defined(WOLFSSL_ASYNC_CRYPT)
  27234. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27235. #endif
  27236. if (ret == 0)
  27237. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27238. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27239. if (ret != 0)
  27240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27241. TEST_SLEEP();
  27242. y = ECC_SHARED_SIZE;
  27243. do {
  27244. #if defined(WOLFSSL_ASYNC_CRYPT)
  27245. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27246. #endif
  27247. if (ret == 0)
  27248. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27249. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27250. if (ret != 0)
  27251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27252. if (y != x)
  27253. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27254. if (XMEMCMP(sharedA, sharedB, x))
  27255. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27256. TEST_SLEEP();
  27257. #ifdef HAVE_ECC_CDH
  27258. /* add cofactor flag */
  27259. wc_ecc_set_flags(userA, WC_ECC_FLAG_COFACTOR);
  27260. wc_ecc_set_flags(userB, WC_ECC_FLAG_COFACTOR);
  27261. x = ECC_SHARED_SIZE;
  27262. do {
  27263. #if defined(WOLFSSL_ASYNC_CRYPT)
  27264. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27265. #endif
  27266. if (ret == 0)
  27267. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27268. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27269. if (ret != 0)
  27270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27271. TEST_SLEEP();
  27272. y = ECC_SHARED_SIZE;
  27273. do {
  27274. #if defined(WOLFSSL_ASYNC_CRYPT)
  27275. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27276. #endif
  27277. if (ret == 0)
  27278. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27279. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27280. if (ret != 0)
  27281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27282. if (y != x)
  27283. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27284. if (XMEMCMP(sharedA, sharedB, x))
  27285. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27286. TEST_SLEEP();
  27287. /* remove cofactor flag */
  27288. wc_ecc_set_flags(userA, 0);
  27289. wc_ecc_set_flags(userB, 0);
  27290. #endif /* HAVE_ECC_CDH */
  27291. #endif /* HAVE_ECC_DHE */
  27292. #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
  27293. #ifdef HAVE_ECC_KEY_EXPORT
  27294. x = ECC_KEY_EXPORT_BUF_SIZE;
  27295. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  27296. if (ret != 0)
  27297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27298. #ifdef HAVE_ECC_KEY_IMPORT
  27299. #ifdef WOLFSSL_CUSTOM_CURVES
  27300. if (dp != NULL) {
  27301. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27302. if (ret != 0)
  27303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27304. }
  27305. #endif
  27306. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27307. if (ret != 0)
  27308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27309. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27310. #ifdef HAVE_ECC_DHE
  27311. y = ECC_SHARED_SIZE;
  27312. do {
  27313. #if defined(WOLFSSL_ASYNC_CRYPT)
  27314. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27315. #endif
  27316. if (ret == 0)
  27317. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27318. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27319. if (ret != 0)
  27320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27321. if (XMEMCMP(sharedA, sharedB, y))
  27322. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27323. TEST_SLEEP();
  27324. #endif /* HAVE_ECC_DHE */
  27325. #ifdef HAVE_COMP_KEY
  27326. /* try compressed export / import too */
  27327. x = ECC_KEY_EXPORT_BUF_SIZE;
  27328. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  27329. if (ret != 0)
  27330. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27331. wc_ecc_free(pubKey);
  27332. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27333. if (ret != 0)
  27334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27335. #ifdef WOLFSSL_CUSTOM_CURVES
  27336. if (dp != NULL) {
  27337. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27338. if (ret != 0)
  27339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27340. }
  27341. #endif
  27342. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27343. if (ret != 0)
  27344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27345. #ifdef HAVE_ECC_DHE
  27346. y = ECC_SHARED_SIZE;
  27347. do {
  27348. #if defined(WOLFSSL_ASYNC_CRYPT)
  27349. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27350. #endif
  27351. if (ret == 0)
  27352. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27353. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27354. if (ret != 0)
  27355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27356. if (XMEMCMP(sharedA, sharedB, y))
  27357. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27358. TEST_SLEEP();
  27359. #endif /* HAVE_ECC_DHE */
  27360. #endif /* HAVE_COMP_KEY */
  27361. #endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A */
  27362. #endif /* !WC_NO_RNG */
  27363. #endif /* HAVE_ECC_KEY_IMPORT */
  27364. #endif /* HAVE_ECC_KEY_EXPORT */
  27365. /* For KCAPI cannot sign using generated ECDH key */
  27366. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27367. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
  27368. #ifdef HAVE_ECC_SIGN
  27369. /* some hardware doesn't support sign/verify of all zero digest */
  27370. #if !defined(WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST)
  27371. /* test DSA sign hash with zeros */
  27372. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27373. digest[i] = 0;
  27374. }
  27375. x = ECC_SIG_SIZE;
  27376. do {
  27377. #if defined(WOLFSSL_ASYNC_CRYPT)
  27378. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27379. #endif
  27380. if (ret == 0)
  27381. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
  27382. userA);
  27383. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27384. if (ret != 0)
  27385. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27386. TEST_SLEEP();
  27387. #ifdef HAVE_ECC_VERIFY
  27388. for (i=0; i<testVerifyCount; i++) {
  27389. verify = 0;
  27390. do {
  27391. #if defined(WOLFSSL_ASYNC_CRYPT)
  27392. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27393. #endif
  27394. if (ret == 0)
  27395. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
  27396. &verify, userA);
  27397. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27398. if (ret != 0)
  27399. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27400. if (verify != 1)
  27401. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27402. TEST_SLEEP();
  27403. }
  27404. #endif /* HAVE_ECC_VERIFY */
  27405. #endif /* !WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST */
  27406. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  27407. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27408. digest[i] = (byte)i;
  27409. }
  27410. x = ECC_SIG_SIZE;
  27411. do {
  27412. #if defined(WOLFSSL_ASYNC_CRYPT)
  27413. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27414. #endif
  27415. if (ret == 0)
  27416. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  27417. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27418. if (ret != 0)
  27419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27420. TEST_SLEEP();
  27421. #ifdef HAVE_ECC_VERIFY
  27422. for (i=0; i<testVerifyCount; i++) {
  27423. verify = 0;
  27424. do {
  27425. #if defined(WOLFSSL_ASYNC_CRYPT)
  27426. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27427. #endif
  27428. if (ret == 0)
  27429. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA);
  27430. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27431. if (ret != 0)
  27432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27433. if (verify != 1)
  27434. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27435. TEST_SLEEP();
  27436. }
  27437. #endif /* HAVE_ECC_VERIFY */
  27438. #endif /* HAVE_ECC_SIGN */
  27439. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT &&
  27440. * !WC_NO_RNG && !WOLFSSL_KCAPI_ECC) */
  27441. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  27442. !defined(WOLFSSL_ATECC508) && !defined(WOLFSSL_ATECC608A) && \
  27443. !defined(WOLFSSL_KCAPI_ECC)
  27444. x = ECC_KEY_EXPORT_BUF_SIZE;
  27445. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  27446. if (ret != 0)
  27447. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27448. #elif defined(HAVE_ECC_KEY_EXPORT)
  27449. (void)exportBuf;
  27450. #endif /* HAVE_ECC_KEY_EXPORT */
  27451. done:
  27452. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27453. if (userA != NULL) {
  27454. wc_ecc_free(userA);
  27455. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27456. }
  27457. if (userB != NULL) {
  27458. wc_ecc_free(userB);
  27459. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27460. }
  27461. if (pubKey != NULL) {
  27462. wc_ecc_free(pubKey);
  27463. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27464. }
  27465. #else
  27466. wc_ecc_free(pubKey);
  27467. wc_ecc_free(userB);
  27468. wc_ecc_free(userA);
  27469. #endif
  27470. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  27471. WC_FREE_VAR(sharedA, HEAP_HINT);
  27472. WC_FREE_VAR(sharedB, HEAP_HINT);
  27473. #endif
  27474. #ifdef HAVE_ECC_KEY_EXPORT
  27475. WC_FREE_VAR(exportBuf, HEAP_HINT);
  27476. #endif
  27477. #ifdef HAVE_ECC_SIGN
  27478. WC_FREE_VAR(sig, HEAP_HINT);
  27479. WC_FREE_VAR(digest, HEAP_HINT);
  27480. #endif
  27481. (void)keySize;
  27482. (void)curve_id;
  27483. (void)rng;
  27484. return ret;
  27485. }
  27486. #undef ECC_TEST_VERIFY_COUNT
  27487. #define ECC_TEST_VERIFY_COUNT 2
  27488. static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
  27489. {
  27490. wc_test_ret_t ret;
  27491. WOLFSSL_MSG_EX("ecc_test_curve keySize = %d", keySize);
  27492. #if FIPS_VERSION3_GE(6,0,0)
  27493. #ifdef DEBUG_WOLFSSL
  27494. printf("keySize is %d\n", keySize);
  27495. #endif
  27496. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27497. goto skip_A;
  27498. }
  27499. #endif
  27500. ret = ecc_test_curve_size(rng, keySize, ECC_TEST_VERIFY_COUNT, curve_id,
  27501. NULL);
  27502. if (ret < 0) {
  27503. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27504. /* ignore error for curves not found */
  27505. /* some curve sizes are only available with:
  27506. HAVE_ECC_SECPR2, HAVE_ECC_SECPR3, HAVE_ECC_BRAINPOOL
  27507. and HAVE_ECC_KOBLITZ */
  27508. }
  27509. else {
  27510. printf("ecc_test_curve_size %d failed!\n", keySize);
  27511. return ret;
  27512. }
  27513. }
  27514. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27515. #if FIPS_VERSION3_GE(6,0,0)
  27516. skip_A:
  27517. #endif
  27518. #ifdef HAVE_ECC_VECTOR_TEST
  27519. ret = ecc_test_vector(keySize);
  27520. if (ret < 0) {
  27521. printf("ecc_test_vector %d failed!\n", keySize);
  27522. return ret;
  27523. }
  27524. #endif
  27525. #if FIPS_VERSION3_GE(6,0,0)
  27526. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27527. goto skip_B;
  27528. }
  27529. #endif
  27530. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27531. !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27532. ret = ecc_test_key_decode(rng, keySize);
  27533. if (ret < 0) {
  27534. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27535. /* ignore error for curves not found */
  27536. }
  27537. else {
  27538. printf("ecc_test_key_decode %d failed!\n", keySize);
  27539. return ret;
  27540. }
  27541. }
  27542. #endif
  27543. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27544. ret = ecc_test_key_gen(rng, keySize);
  27545. if (ret < 0) {
  27546. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27547. /* ignore error for curves not found */
  27548. }
  27549. else {
  27550. printf("ecc_test_key_gen %d failed!\n", keySize);
  27551. return ret;
  27552. }
  27553. }
  27554. #endif
  27555. #if FIPS_VERSION3_GE(6,0,0)
  27556. skip_B:
  27557. #endif
  27558. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  27559. return 0;
  27560. }
  27561. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  27562. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  27563. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27564. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27565. static wc_test_ret_t ecc_point_test(void)
  27566. {
  27567. wc_test_ret_t ret;
  27568. ecc_point* point;
  27569. ecc_point* point2;
  27570. #ifdef HAVE_COMP_KEY
  27571. ecc_point* point3;
  27572. ecc_point* point4;
  27573. #endif
  27574. word32 outLen;
  27575. byte out[65];
  27576. byte der[] = { 0x04, /* = Uncompressed */
  27577. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27578. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27579. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27580. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27581. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27582. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27583. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27584. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27585. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27586. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27587. byte derComp0[] = { 0x02, /* = Compressed, y even */
  27588. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27589. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27590. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27591. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27592. byte derComp1[] = { 0x03, /* = Compressed, y odd */
  27593. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27594. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27595. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27596. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27597. #endif
  27598. byte altDer[] = { 0x04, /* = Uncompressed */
  27599. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27600. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27601. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27602. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27603. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27604. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27605. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27606. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  27607. int curve_idx = wc_ecc_get_curve_idx(ECC_SECP256R1);
  27608. /* if curve P256 is not enabled then test should not fail */
  27609. if (curve_idx == ECC_CURVE_INVALID)
  27610. return 0;
  27611. outLen = sizeof(out);
  27612. point = wc_ecc_new_point();
  27613. if (point == NULL)
  27614. return WC_TEST_RET_ENC_ERRNO;
  27615. point2 = wc_ecc_new_point();
  27616. if (point2 == NULL) {
  27617. wc_ecc_del_point(point);
  27618. return WC_TEST_RET_ENC_NC;
  27619. }
  27620. #ifdef HAVE_COMP_KEY
  27621. point3 = wc_ecc_new_point();
  27622. if (point3 == NULL) {
  27623. wc_ecc_del_point(point2);
  27624. wc_ecc_del_point(point);
  27625. return WC_TEST_RET_ENC_NC;
  27626. }
  27627. point4 = wc_ecc_new_point();
  27628. if (point4 == NULL) {
  27629. wc_ecc_del_point(point3);
  27630. wc_ecc_del_point(point2);
  27631. wc_ecc_del_point(point);
  27632. return WC_TEST_RET_ENC_NC;
  27633. }
  27634. #endif
  27635. /* Parameter Validation testing. */
  27636. wc_ecc_del_point(NULL);
  27637. ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, point);
  27638. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27639. ret = WC_TEST_RET_ENC_EC(ret);
  27640. goto done;
  27641. }
  27642. ret = wc_ecc_import_point_der(der, sizeof(der), ECC_CURVE_INVALID, point);
  27643. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27644. ret = WC_TEST_RET_ENC_EC(ret);
  27645. goto done;
  27646. }
  27647. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, NULL);
  27648. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27649. ret = WC_TEST_RET_ENC_EC(ret);
  27650. goto done;
  27651. }
  27652. ret = wc_ecc_export_point_der(-1, point, out, &outLen);
  27653. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27654. ret = WC_TEST_RET_ENC_EC(ret);
  27655. goto done;
  27656. }
  27657. ret = wc_ecc_export_point_der(curve_idx, NULL, out, &outLen);
  27658. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27659. ret = WC_TEST_RET_ENC_EC(ret);
  27660. goto done;
  27661. }
  27662. ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen);
  27663. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || outLen != sizeof(out)) {
  27664. ret = WC_TEST_RET_ENC_EC(ret);
  27665. goto done;
  27666. }
  27667. ret = wc_ecc_export_point_der(curve_idx, point, out, NULL);
  27668. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27669. ret = WC_TEST_RET_ENC_EC(ret);
  27670. goto done;
  27671. }
  27672. outLen = 0;
  27673. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27674. if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
  27675. ret = WC_TEST_RET_ENC_EC(ret);
  27676. goto done;
  27677. }
  27678. ret = wc_ecc_copy_point(NULL, NULL);
  27679. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27680. ret = WC_TEST_RET_ENC_EC(ret);
  27681. goto done;
  27682. }
  27683. ret = wc_ecc_copy_point(NULL, point2);
  27684. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27685. ret = WC_TEST_RET_ENC_EC(ret);
  27686. goto done;
  27687. }
  27688. ret = wc_ecc_copy_point(point, NULL);
  27689. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27690. ret = WC_TEST_RET_ENC_EC(ret);
  27691. goto done;
  27692. }
  27693. ret = wc_ecc_cmp_point(NULL, NULL);
  27694. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27695. ret = WC_TEST_RET_ENC_EC(ret);
  27696. goto done;
  27697. }
  27698. ret = wc_ecc_cmp_point(NULL, point2);
  27699. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27700. ret = WC_TEST_RET_ENC_EC(ret);
  27701. goto done;
  27702. }
  27703. ret = wc_ecc_cmp_point(point, NULL);
  27704. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27705. ret = WC_TEST_RET_ENC_EC(ret);
  27706. goto done;
  27707. }
  27708. /* Use API. */
  27709. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point);
  27710. if (ret != 0)
  27711. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27712. outLen = sizeof(out);
  27713. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27714. if (ret != 0)
  27715. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27716. if (outLen != sizeof(der)) {
  27717. ret = WC_TEST_RET_ENC_NC;
  27718. goto done;
  27719. }
  27720. if (XMEMCMP(out, der, outLen) != 0) {
  27721. ret = WC_TEST_RET_ENC_NC;
  27722. goto done;
  27723. }
  27724. ret = wc_ecc_copy_point(point2, point);
  27725. if (ret != MP_OKAY) {
  27726. ret = WC_TEST_RET_ENC_EC(ret);
  27727. goto done;
  27728. }
  27729. ret = wc_ecc_cmp_point(point2, point);
  27730. if (ret != MP_EQ) {
  27731. ret = WC_TEST_RET_ENC_EC(ret);
  27732. goto done;
  27733. }
  27734. ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2);
  27735. if (ret != 0)
  27736. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27737. ret = wc_ecc_cmp_point(point2, point);
  27738. if (ret != MP_GT) {
  27739. ret = WC_TEST_RET_ENC_EC(ret);
  27740. goto done;
  27741. }
  27742. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27743. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27744. ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3);
  27745. if (ret != 0)
  27746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27747. ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0);
  27748. if (ret != 0)
  27749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27750. ret = wc_ecc_cmp_point(point3, point4);
  27751. if (ret != MP_EQ) {
  27752. ret = WC_TEST_RET_ENC_EC(ret);
  27753. goto done;
  27754. }
  27755. ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3);
  27756. if (ret != 0)
  27757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27758. ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0);
  27759. if (ret != 0)
  27760. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27761. ret = wc_ecc_cmp_point(point3, point4);
  27762. if (ret != MP_EQ) {
  27763. ret = WC_TEST_RET_ENC_EC(ret);
  27764. goto done;
  27765. }
  27766. #endif
  27767. done:
  27768. #ifdef HAVE_COMP_KEY
  27769. wc_ecc_del_point(point4);
  27770. wc_ecc_del_point(point3);
  27771. #endif
  27772. wc_ecc_del_point(point2);
  27773. wc_ecc_del_point(point);
  27774. return ret;
  27775. }
  27776. #endif /* !WOLFSSL_ATECC508A && HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27777. #if !defined(NO_SIG_WRAPPER) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27778. static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key)
  27779. {
  27780. wc_test_ret_t ret;
  27781. word32 sigSz;
  27782. int size;
  27783. byte out[ECC_MAX_SIG_SIZE];
  27784. byte in[] = TEST_STRING;
  27785. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  27786. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  27787. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  27788. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  27789. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  27790. };
  27791. word32 inLen = (word32)XSTRLEN((char*)in);
  27792. size = wc_ecc_sig_size(key);
  27793. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key));
  27794. if (ret != size)
  27795. return WC_TEST_RET_ENC_NC;
  27796. sigSz = (word32)ret;
  27797. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27798. inLen, out, &sigSz, key, sizeof(*key), rng);
  27799. if (ret != 0)
  27800. return WC_TEST_RET_ENC_EC(ret);
  27801. TEST_SLEEP();
  27802. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27803. inLen, out, sigSz, key, sizeof(*key));
  27804. if (ret != 0)
  27805. return WC_TEST_RET_ENC_EC(ret);
  27806. TEST_SLEEP();
  27807. sigSz = (word32)sizeof(out);
  27808. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27809. hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng);
  27810. if (ret != 0)
  27811. return WC_TEST_RET_ENC_EC(ret);
  27812. TEST_SLEEP();
  27813. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27814. hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key));
  27815. if (ret != 0)
  27816. return WC_TEST_RET_ENC_EC(ret);
  27817. TEST_SLEEP();
  27818. return 0;
  27819. }
  27820. #endif
  27821. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27822. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27823. static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
  27824. {
  27825. wc_test_ret_t ret;
  27826. int curve_id;
  27827. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27828. ecc_key *keyImp = (ecc_key *)XMALLOC(sizeof *keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27829. #else
  27830. ecc_key keyImp[1];
  27831. #endif
  27832. byte priv[32];
  27833. word32 privLen;
  27834. byte pub[65*2];
  27835. word32 pubLen, pubLenX, pubLenY;
  27836. const char qx[] = "7a4e287890a1a47ad3457e52f2f76a83"
  27837. "ce46cbc947616d0cbaa82323818a793d";
  27838. const char qy[] = "eec4084f5b29ebf29c44cce3b3059610"
  27839. "922f8b30ea6e8811742ac7238fe87308";
  27840. const char d[] = "8c14b793cb19137e323a6d2e2a870bca"
  27841. "2e7a493ec1153b3a95feb8a4873f8d08";
  27842. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27843. if (keyImp == NULL)
  27844. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27845. #endif
  27846. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27847. privLen = sizeof(priv);
  27848. ret = wc_ecc_export_private_only(key, priv, &privLen);
  27849. if (ret != 0)
  27850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27851. pubLen = sizeof(pub);
  27852. ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen);
  27853. if (ret != 0)
  27854. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27855. ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp);
  27856. if (ret != 0)
  27857. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27858. wc_ecc_free(keyImp);
  27859. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27860. ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1);
  27861. if (ret != 0)
  27862. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27863. wc_ecc_free(keyImp);
  27864. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27865. curve_id = wc_ecc_get_curve_id(key->idx);
  27866. if (curve_id < 0) {
  27867. ret = WC_TEST_RET_ENC_EC(curve_id);
  27868. goto done;
  27869. }
  27870. /* test import private only */
  27871. ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp,
  27872. curve_id);
  27873. if (ret != 0)
  27874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27875. wc_ecc_free(keyImp);
  27876. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27877. /* test export public raw */
  27878. pubLenX = pubLenY = 32;
  27879. ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY);
  27880. if (ret != 0)
  27881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27882. #ifndef HAVE_SELFTEST
  27883. /* test import of public */
  27884. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1);
  27885. if (ret != 0)
  27886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27887. #endif
  27888. wc_ecc_free(keyImp);
  27889. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27890. /* test export private and public raw */
  27891. pubLenX = pubLenY = privLen = 32;
  27892. ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY,
  27893. priv, &privLen);
  27894. if (ret != 0)
  27895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27896. #ifndef HAVE_SELFTEST
  27897. /* test import of private and public */
  27898. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1);
  27899. if (ret != 0)
  27900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27901. #endif
  27902. done:
  27903. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27904. if (keyImp != NULL) {
  27905. wc_ecc_free(keyImp);
  27906. XFREE(keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27907. }
  27908. #else
  27909. wc_ecc_free(keyImp);
  27910. #endif
  27911. return ret;
  27912. }
  27913. #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27914. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  27915. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27916. static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
  27917. {
  27918. wc_test_ret_t ret;
  27919. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27920. ecc_key *key2 = (ecc_key *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27921. ecc_key *key3 = (ecc_key *)XMALLOC(sizeof *key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27922. #else
  27923. ecc_key key2[1];
  27924. ecc_key key3[1];
  27925. #endif
  27926. #ifdef WOLFSSL_PUBLIC_MP
  27927. mp_int* priv;
  27928. #endif
  27929. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27930. if ((key2 == NULL) || (key3 == NULL))
  27931. ERROR_OUT(MEMORY_E, done);
  27932. #endif
  27933. wc_ecc_init_ex(key2, HEAP_HINT, devId);
  27934. wc_ecc_init_ex(key3, HEAP_HINT, devId);
  27935. /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */
  27936. /* Need base point (Gx,Gy) and parameter A - load them as the public and
  27937. * private key in key2.
  27938. */
  27939. ret = wc_ecc_import_raw_ex(key2, key1->dp->Gx, key1->dp->Gy, key1->dp->Af,
  27940. ECC_SECP256R1);
  27941. if (ret != 0)
  27942. goto done;
  27943. /* Need a point (Gx,Gy) and prime - load them as the public and private key
  27944. * in key3.
  27945. */
  27946. ret = wc_ecc_import_raw_ex(key3, key1->dp->Gx, key1->dp->Gy,
  27947. key1->dp->prime, ECC_SECP256R1);
  27948. if (ret != 0)
  27949. goto done;
  27950. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27951. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27952. 1);
  27953. if (ret != 0)
  27954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27955. #ifdef WOLFSSL_PUBLIC_MP
  27956. priv = wc_ecc_key_get_priv(key1);
  27957. mp_zero(priv);
  27958. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27959. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27960. 1);
  27961. if (ret != 0)
  27962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27963. if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
  27964. ret = WC_TEST_RET_ENC_EC(ret);
  27965. goto done;
  27966. }
  27967. if (mp_cmp_d(key3->pubkey.z, 1) != MP_EQ) {
  27968. ret = WC_TEST_RET_ENC_EC(ret);
  27969. goto done;
  27970. }
  27971. #endif
  27972. done:
  27973. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27974. if (key2 != NULL) {
  27975. wc_ecc_free(key2);
  27976. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27977. }
  27978. if (key3 != NULL) {
  27979. wc_ecc_free(key3);
  27980. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27981. }
  27982. #else
  27983. wc_ecc_free(key3);
  27984. wc_ecc_free(key2);
  27985. #endif
  27986. return ret;
  27987. }
  27988. #endif
  27989. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27990. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
  27991. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  27992. !defined(WOLFSSL_CRYPTOCELL)
  27993. static wc_test_ret_t ecc_ssh_test(ecc_key* key, WC_RNG* rng)
  27994. {
  27995. wc_test_ret_t ret;
  27996. byte out[128];
  27997. word32 outLen = sizeof(out);
  27998. /* Parameter Validation testing. */
  27999. ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen);
  28000. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28001. return WC_TEST_RET_ENC_EC(ret);
  28002. ret = wc_ecc_shared_secret_ssh(key, NULL, out, &outLen);
  28003. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28004. return WC_TEST_RET_ENC_EC(ret);
  28005. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, NULL, &outLen);
  28006. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28007. return WC_TEST_RET_ENC_EC(ret);
  28008. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, NULL);
  28009. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28010. return WC_TEST_RET_ENC_EC(ret);
  28011. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  28012. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  28013. !defined(HAVE_SELFTEST)
  28014. ret = wc_ecc_set_rng(key, rng);
  28015. if (ret != 0)
  28016. return WC_TEST_RET_ENC_EC(ret);
  28017. #else
  28018. (void)rng;
  28019. #endif
  28020. /* Use API. */
  28021. ret = 0;
  28022. do {
  28023. #if defined(WOLFSSL_ASYNC_CRYPT)
  28024. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  28025. #endif
  28026. if (ret == 0)
  28027. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen);
  28028. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  28029. if (ret != 0)
  28030. return WC_TEST_RET_ENC_EC(ret);
  28031. TEST_SLEEP();
  28032. return 0;
  28033. }
  28034. #endif /* HAVE_ECC_DHE && !WC_NO_RNG */
  28035. static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
  28036. {
  28037. wc_test_ret_t ret;
  28038. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28039. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28040. #else
  28041. ecc_key key[1];
  28042. #endif
  28043. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28044. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28045. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28046. word32 idx = 0;
  28047. #endif
  28048. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28049. if (key == NULL)
  28050. ERROR_OUT(MEMORY_E, done);
  28051. #endif
  28052. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28053. /* Use API */
  28054. ret = wc_ecc_set_flags(NULL, 0);
  28055. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28056. ret = WC_TEST_RET_ENC_EC(ret);
  28057. goto done;
  28058. }
  28059. ret = wc_ecc_set_flags(key, 0);
  28060. if (ret != 0)
  28061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28062. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  28063. #ifndef WC_NO_RNG
  28064. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  28065. #if defined(WOLFSSL_ASYNC_CRYPT)
  28066. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  28067. #endif
  28068. if (ret != 0) {
  28069. goto done;
  28070. }
  28071. #ifndef NO_SIG_WRAPPER
  28072. ret = ecc_sig_test(rng, key);
  28073. if (ret < 0)
  28074. goto done;
  28075. #endif
  28076. TEST_SLEEP();
  28077. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
  28078. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  28079. ret = ecc_ssh_test(key, rng);
  28080. if (ret < 0)
  28081. goto done;
  28082. #endif
  28083. wc_ecc_free(key);
  28084. #else
  28085. (void)rng;
  28086. #endif /* !WC_NO_RNG */
  28087. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28088. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28089. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28090. /* Use test ECC key - ensure real private "d" exists */
  28091. #if defined(USE_CERT_BUFFERS_256)
  28092. {
  28093. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  28094. sizeof_ecc_key_der_256);
  28095. }
  28096. #elif !defined(NO_FILESYSTEM)
  28097. {
  28098. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  28099. byte der[128];
  28100. word32 derSz;
  28101. if (!file) {
  28102. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28103. }
  28104. derSz = (word32)XFREAD(der, 1, sizeof(der), file);
  28105. XFCLOSE(file);
  28106. if (derSz == 0)
  28107. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28108. ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
  28109. }
  28110. #else
  28111. {
  28112. (void)idx;
  28113. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
  28114. ERROR_OUT(ASN_PARSE_E, done);
  28115. }
  28116. #endif
  28117. if (ret != 0) {
  28118. goto done;
  28119. }
  28120. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
  28121. ret = ecc_exp_imp_test(key);
  28122. if (ret < 0)
  28123. goto done;
  28124. #endif
  28125. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  28126. !defined(WOLFSSL_CRYPTOCELL)
  28127. ret = ecc_mulmod_test(key);
  28128. if (ret < 0)
  28129. goto done;
  28130. #endif
  28131. #endif
  28132. #else
  28133. (void)rng;
  28134. (void)idx;
  28135. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  28136. done:
  28137. wc_ecc_free(key);
  28138. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28139. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28140. #endif
  28141. return ret;
  28142. }
  28143. #endif /* !NO_ECC256 || HAVE_ALL_CURVES */
  28144. #if defined(WOLFSSL_CERT_EXT) && \
  28145. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  28146. static wc_test_ret_t ecc_decode_test(void)
  28147. {
  28148. wc_test_ret_t ret;
  28149. word32 inSz;
  28150. word32 inOutIdx;
  28151. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28152. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28153. #else
  28154. ecc_key key[1];
  28155. #endif
  28156. /* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
  28157. /* This is ecc_clikeypub_der_256. */
  28158. WOLFSSL_SMALL_STACK_STATIC const byte good[] = {
  28159. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  28160. 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  28161. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xbf, 0xf4,
  28162. 0x0f, 0x44, 0x50, 0x9a, 0x3d, 0xce, 0x9b, 0xb7, 0xf0, 0xc5,
  28163. 0x4d, 0xf5, 0x70, 0x7b, 0xd4, 0xec, 0x24, 0x8e, 0x19, 0x80,
  28164. 0xec, 0x5a, 0x4c, 0xa2, 0x24, 0x03, 0x62, 0x2c, 0x9b, 0xda,
  28165. 0xef, 0xa2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xc6, 0x56,
  28166. 0x95, 0x06, 0xcc, 0x01, 0xa9, 0xbd, 0xf6, 0x75, 0x1a, 0x42,
  28167. 0xf7, 0xbd, 0xa9, 0xb2, 0x36, 0x22, 0x5f, 0xc7, 0x5d, 0x7f,
  28168. 0xb4 };
  28169. WOLFSSL_SMALL_STACK_STATIC const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
  28170. 0x00, 0x04, 0x01, 0x01 };
  28171. WOLFSSL_SMALL_STACK_STATIC const byte badOneObjId[] = { 0x30, 0x0a, 0x30, 0x08, 0x06, 0x00,
  28172. 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28173. WOLFSSL_SMALL_STACK_STATIC const byte badObjId1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x09,
  28174. 0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28175. WOLFSSL_SMALL_STACK_STATIC const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
  28176. 0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28177. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28178. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28179. 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28180. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28181. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28182. 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
  28183. WOLFSSL_SMALL_STACK_STATIC const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
  28184. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28185. 0x03, 0x03, 0x04, 0x01, 0x01 };
  28186. WOLFSSL_SMALL_STACK_STATIC const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
  28187. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28188. 0x03, 0x03, 0x00, 0x04, 0x01 };
  28189. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28190. if (key == NULL)
  28191. ERROR_OUT(MEMORY_E, done);
  28192. #endif
  28193. XMEMSET(key, 0, sizeof *key);
  28194. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28195. inSz = sizeof(good);
  28196. ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, key, inSz);
  28197. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28198. ret = WC_TEST_RET_ENC_EC(ret);
  28199. goto done;
  28200. }
  28201. ret = wc_EccPublicKeyDecode(good, NULL, key, inSz);
  28202. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28203. ret = WC_TEST_RET_ENC_EC(ret);
  28204. goto done;
  28205. }
  28206. ret = wc_EccPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  28207. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28208. ret = WC_TEST_RET_ENC_EC(ret);
  28209. goto done;
  28210. }
  28211. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0);
  28212. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28213. ret = WC_TEST_RET_ENC_EC(ret);
  28214. goto done;
  28215. }
  28216. /* Change offset to produce bad input data. */
  28217. inOutIdx = 2;
  28218. inSz = sizeof(good) - inOutIdx;
  28219. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28220. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28221. ret = WC_TEST_RET_ENC_EC(ret);
  28222. goto done;
  28223. }
  28224. inOutIdx = 4;
  28225. inSz = sizeof(good) - inOutIdx;
  28226. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28227. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28228. ret = WC_TEST_RET_ENC_EC(ret);
  28229. goto done;
  28230. }
  28231. /* Bad data. */
  28232. inSz = sizeof(badNoObjId);
  28233. inOutIdx = 0;
  28234. ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz);
  28235. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28236. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28237. {
  28238. ret = WC_TEST_RET_ENC_EC(ret);
  28239. goto done;
  28240. }
  28241. inSz = sizeof(badOneObjId);
  28242. inOutIdx = 0;
  28243. ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz);
  28244. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28245. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28246. {
  28247. ret = WC_TEST_RET_ENC_EC(ret);
  28248. goto done;
  28249. }
  28250. inSz = sizeof(badObjId1Len);
  28251. inOutIdx = 0;
  28252. ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz);
  28253. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28254. ret = WC_TEST_RET_ENC_EC(ret);
  28255. goto done;
  28256. }
  28257. inSz = sizeof(badObj2d1Len);
  28258. inOutIdx = 0;
  28259. ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz);
  28260. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28261. ret = WC_TEST_RET_ENC_EC(ret);
  28262. goto done;
  28263. }
  28264. inSz = sizeof(badNotBitStr);
  28265. inOutIdx = 0;
  28266. ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz);
  28267. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E) &&
  28268. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28269. {
  28270. ret = WC_TEST_RET_ENC_EC(ret);
  28271. goto done;
  28272. }
  28273. inSz = sizeof(badBitStrLen);
  28274. inOutIdx = 0;
  28275. ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz);
  28276. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28277. ret = WC_TEST_RET_ENC_EC(ret);
  28278. goto done;
  28279. }
  28280. inSz = sizeof(badNoBitStrZero);
  28281. inOutIdx = 0;
  28282. ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz);
  28283. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  28284. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28285. {
  28286. ret = WC_TEST_RET_ENC_EC(ret);
  28287. goto done;
  28288. }
  28289. inSz = sizeof(badPoint);
  28290. inOutIdx = 0;
  28291. ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz);
  28292. if (ret != WC_NO_ERR_TRACE(ASN_ECC_KEY_E) &&
  28293. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28294. {
  28295. ret = WC_TEST_RET_ENC_EC(ret);
  28296. goto done;
  28297. }
  28298. inSz = sizeof(good);
  28299. inOutIdx = 0;
  28300. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28301. if (ret != 0)
  28302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28303. done:
  28304. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28305. if (key != NULL) {
  28306. wc_ecc_free(key);
  28307. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28308. }
  28309. #else
  28310. wc_ecc_free(key);
  28311. #endif
  28312. return ret;
  28313. }
  28314. #endif /* WOLFSSL_CERT_EXT */
  28315. #ifdef WOLFSSL_CUSTOM_CURVES
  28316. static const byte eccKeyExplicitCurve[] = {
  28317. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  28318. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  28319. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  28320. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  28321. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  28322. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28323. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28324. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  28325. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  28326. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  28327. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  28328. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  28329. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  28330. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  28331. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  28332. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  28333. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  28334. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  28335. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28336. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28337. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  28338. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  28339. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  28340. 0x3c, 0x4c, 0xc9, 0x5e, 0x2e, 0xa2, 0x3d, 0x49,
  28341. 0xcc, 0x5b, 0xff, 0x4f, 0xc9, 0x2e, 0x1d, 0x4a,
  28342. 0xc6, 0x21, 0xf6, 0xf3, 0xe6, 0x0b, 0x4f, 0xa9,
  28343. 0x9d, 0x74, 0x99, 0xdd, 0x97, 0xc7, 0x6e, 0xbe,
  28344. 0x14, 0x2b, 0x39, 0x9d, 0x63, 0xc7, 0x97, 0x0d,
  28345. 0x45, 0x25, 0x40, 0x30, 0x77, 0x05, 0x76, 0x88,
  28346. 0x38, 0x96, 0x29, 0x7d, 0x9c, 0xe1, 0x50, 0xbe,
  28347. 0xac, 0xf0, 0x1d, 0x86, 0xf4, 0x2f, 0x65, 0x0b
  28348. };
  28349. static wc_test_ret_t ecc_test_custom_curves(WC_RNG* rng)
  28350. {
  28351. wc_test_ret_t ret;
  28352. word32 inOutIdx;
  28353. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28354. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28355. #else
  28356. ecc_key key[1];
  28357. #endif
  28358. /* test use of custom curve - using BRAINPOOLP256R1 for test */
  28359. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28360. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28361. WOLFSSL_SMALL_STACK_STATIC const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
  28362. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
  28363. };
  28364. #define ecc_oid_brainpoolp256r1_sz \
  28365. (sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t))
  28366. #else
  28367. #define ecc_oid_brainpoolp256r1 { \
  28368. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 \
  28369. }
  28370. #define ecc_oid_brainpoolp256r1_sz 9
  28371. #endif
  28372. #define ecc_oid_brainpoolp256r1_sum 104
  28373. WOLFSSL_SMALL_STACK_STATIC const ecc_set_type ecc_dp_brainpool256r1 = {
  28374. 32, /* size/bytes */
  28375. ECC_CURVE_CUSTOM, /* ID */
  28376. "BRAINPOOLP256R1", /* curve name */
  28377. "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
  28378. "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
  28379. "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", /* B */
  28380. "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", /* order */
  28381. "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", /* Gx */
  28382. "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
  28383. ecc_oid_brainpoolp256r1, /* oid/oidSz */
  28384. ecc_oid_brainpoolp256r1_sz,
  28385. ecc_oid_brainpoolp256r1_sum, /* oid sum */
  28386. 1, /* cofactor */
  28387. };
  28388. #endif /* HAVE_ECC_BRAINPOOL */
  28389. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28390. if (! key) {
  28391. ret = MEMORY_E;
  28392. goto done;
  28393. }
  28394. #endif
  28395. XMEMSET(key, 0, sizeof *key);
  28396. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28397. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, ECC_CURVE_DEF,
  28398. &ecc_dp_brainpool256r1);
  28399. if (ret != 0) {
  28400. printf("ECC test for custom curve failed!\n");
  28401. goto done;
  28402. }
  28403. #endif
  28404. #if defined(HAVE_ECC_BRAINPOOL) || defined(HAVE_ECC_KOBLITZ)
  28405. {
  28406. int curve_id;
  28407. #ifdef HAVE_ECC_BRAINPOOL
  28408. curve_id = ECC_BRAINPOOLP256R1;
  28409. #else
  28410. curve_id = ECC_SECP256K1;
  28411. #endif
  28412. /* Test and demonstrate use of non-SECP curve */
  28413. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, curve_id, NULL);
  28414. if (ret < 0) {
  28415. printf("ECC test for curve_id %d failed!\n", curve_id);
  28416. goto done;
  28417. }
  28418. }
  28419. #endif
  28420. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  28421. if (ret != 0)
  28422. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28423. inOutIdx = 0;
  28424. ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key,
  28425. sizeof(eccKeyExplicitCurve));
  28426. if (ret != 0)
  28427. ret = WC_TEST_RET_ENC_EC(ret);
  28428. done:
  28429. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28430. if (key) {
  28431. wc_ecc_free(key);
  28432. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28433. }
  28434. #else
  28435. wc_ecc_free(key);
  28436. #endif
  28437. (void)rng;
  28438. return ret;
  28439. }
  28440. #endif /* WOLFSSL_CUSTOM_CURVES */
  28441. #ifdef WOLFSSL_SM2
  28442. #ifdef HAVE_ECC_VERIFY
  28443. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28444. #ifdef HAVE_OID_ENCODING
  28445. #define CODED_SM2P256V1 {1,2,156,10197,1,301}
  28446. #define CODED_SM2P256V1_SZ 6
  28447. #else
  28448. #define CODED_SM2P256V1 {0x06,0x08,0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D}
  28449. #define CODED_SM2P256V1_SZ 10
  28450. #endif
  28451. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28452. static const ecc_oid_t ecc_oid_sm2p256v1[] = CODED_SM2P256V1;
  28453. #else
  28454. #define ecc_oid_sm2p256v1 CODED_SM2P256V1
  28455. #endif
  28456. #define ecc_oid_sm2p256v1_sz CODED_SM2P256V1_SZ
  28457. #define ECC_SM2P256V1_TEST 102
  28458. static int test_sm2_verify_caseA2(void)
  28459. {
  28460. ecc_key key;
  28461. int ret, res;
  28462. mp_int r,s;
  28463. /* test key values */
  28464. const char qx[] = "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A";
  28465. const char qy[] = "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857";
  28466. const char d[] = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
  28467. const ecc_set_type ecc_sm2_A2 = {
  28468. 32, /* size/bytes */
  28469. ECC_SM2P256V1_TEST, /* ID */
  28470. "SM2P256V1_TEST", /* curve name */
  28471. /* from test case A.2 in draft-shen-sm2-ecdsa-02 */
  28472. "8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", /* prime */
  28473. "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", /* A */
  28474. "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", /* B */
  28475. "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", /* order n */
  28476. "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", /* Gx */
  28477. "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", /* Gy */
  28478. ecc_oid_sm2p256v1, /* oid/oidSz */
  28479. ecc_oid_sm2p256v1_sz,
  28480. ECC_SM2P256V1_OID, /* oid sum */
  28481. 1, /* cofactor */
  28482. };
  28483. /* use canned hash value hash = H(ZA||M) */
  28484. const byte hash[] = {
  28485. 0xB5,0x24,0xF5,0x52,0xCD,0x82,0xB8,0xB0,
  28486. 0x28,0x47,0x6E,0x00,0x5C,0x37,0x7F,0xB1,
  28487. 0x9A,0x87,0xE6,0xFC,0x68,0x2D,0x48,0xBB,
  28488. 0x5D,0x42,0xE3,0xD9,0xB9,0xEF,0xFE,0x76
  28489. };
  28490. /* canned r and s */
  28491. const byte rCan[] = {
  28492. 0x40,0xF1,0xEC,0x59,0xF7,0x93,0xD9,0xF4,
  28493. 0x9E,0x09,0xDC,0xEF,0x49,0x13,0x0D,0x41,
  28494. 0x94,0xF7,0x9F,0xB1,0xEE,0xD2,0xCA,0xA5,
  28495. 0x5B,0xAC,0xDB,0x49,0xC4,0xE7,0x55,0xD1
  28496. };
  28497. const byte sCan[] = {
  28498. 0x6F,0xC6,0xDA,0xC3,0x2C,0x5D,0x5C,0xF1,
  28499. 0x0C,0x77,0xDF,0xB2,0x0F,0x7C,0x2E,0xB6,
  28500. 0x67,0xA4,0x57,0x87,0x2F,0xB0,0x9E,0xC5,
  28501. 0x63,0x27,0xA6,0x7E,0xC7,0xDE,0xEB,0xE7
  28502. };
  28503. mp_init(&r);
  28504. mp_init(&s);
  28505. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28506. if (ret != 0)
  28507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28508. ret = wc_ecc_set_custom_curve(&key, &ecc_sm2_A2);
  28509. if (ret != 0)
  28510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28511. ret = wc_ecc_import_raw_ex(&key, qx, qy, d, ECC_SM2P256V1_TEST);
  28512. if (ret != 0)
  28513. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28514. mp_read_unsigned_bin(&r, rCan, sizeof(rCan));
  28515. mp_read_unsigned_bin(&s, sCan, sizeof(sCan));
  28516. ret = wc_ecc_sm2_verify_hash_ex(&r, &s, hash, sizeof(hash), &res, &key);
  28517. if (ret != 0)
  28518. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28519. if (res != 1)
  28520. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28521. done:
  28522. mp_free(&r);
  28523. mp_free(&s);
  28524. wc_ecc_free(&key);
  28525. return ret;
  28526. }
  28527. #endif /* WOLFSSL_PUBLIC_MP && WOLFSSL_CUSTOM_CURVES */
  28528. static int test_sm2_verify_case(void)
  28529. {
  28530. ecc_key key;
  28531. int ret, res;
  28532. /* test key values */
  28533. const char qx[] = "637F1B135036C933DC3F7A8EBB1B7B2FD1DFBD268D4F894B5AD47DBDBECD558F";
  28534. const char qy[] = "E88101D08048E36CCBF61CA38DDF7ABA542B4486E99E49F3A7470A857A096433";
  28535. /* use canned hash value hash = H(ZA||M) */
  28536. const byte hash[] = {
  28537. 0x3B,0xFA,0x5F,0xFB,0xC4,0x27,0x8C,0x9D,
  28538. 0x02,0x3A,0x19,0xCB,0x1E,0xAA,0xD2,0xF1,
  28539. 0x50,0x69,0x5B,0x20
  28540. };
  28541. const byte sig[] = {
  28542. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28543. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28544. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28545. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28546. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28547. 0xB5,0xB5,0xD9,0xD8,0xF1,0x20,0xDD,0x97,
  28548. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28549. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28550. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28551. };
  28552. const byte badSig[] = {
  28553. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28554. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28555. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28556. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28557. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28558. 0xB5,0xB5,0xE9,0xD8,0xF1,0x20,0xDD,0x97,
  28559. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28560. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28561. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28562. };
  28563. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28564. if (ret != 0)
  28565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28566. ret = wc_ecc_import_raw(&key, qx, qy, NULL, "SM2P256V1");
  28567. if (ret != 0)
  28568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28569. ret = wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash), &res,
  28570. &key);
  28571. if (ret != 0)
  28572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28573. if (res != 1)
  28574. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28575. /* now test a case that should fail */
  28576. ret = wc_ecc_sm2_verify_hash(badSig, sizeof(badSig), hash, sizeof(hash),
  28577. &res, &key);
  28578. if (ret != 0)
  28579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28580. if (res == 1)
  28581. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28582. done:
  28583. wc_ecc_free(&key);
  28584. return ret;
  28585. }
  28586. static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
  28587. {
  28588. const ecc_set_type* dp = wc_ecc_get_curve_params(
  28589. wc_ecc_get_curve_idx(ECC_SM2P256V1));
  28590. int keySize = 32;
  28591. int curve_id = ECC_SM2P256V1;
  28592. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28593. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28594. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28595. #endif
  28596. #ifdef HAVE_ECC_KEY_EXPORT
  28597. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  28598. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28599. #endif
  28600. word32 x = 0;
  28601. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28602. word32 y;
  28603. #endif
  28604. #ifdef HAVE_ECC_SIGN
  28605. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28606. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28607. int i;
  28608. int verify;
  28609. #endif /* HAVE_ECC_SIGN */
  28610. int ret;
  28611. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28612. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28613. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28614. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28615. #else
  28616. ecc_key userA[1];
  28617. ecc_key userB[1];
  28618. ecc_key pubKey[1];
  28619. #endif
  28620. #ifndef WC_NO_RNG
  28621. int curveSize;
  28622. #endif
  28623. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28624. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28625. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28626. #endif
  28627. #ifdef HAVE_ECC_KEY_EXPORT
  28628. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28629. #endif
  28630. #ifdef HAVE_ECC_SIGN
  28631. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28632. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28633. #endif
  28634. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  28635. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28636. if (sharedA == NULL || sharedB == NULL)
  28637. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28638. #endif
  28639. #ifdef HAVE_ECC_KEY_EXPORT
  28640. if (exportBuf == NULL)
  28641. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28642. #endif
  28643. #ifdef HAVE_ECC_SIGN
  28644. if (sig == NULL || digest == NULL)
  28645. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28646. #endif
  28647. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  28648. (void)testVerifyCount;
  28649. (void)dp;
  28650. (void)x;
  28651. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28652. if ((userA == NULL) ||
  28653. (userB == NULL) ||
  28654. (pubKey == NULL))
  28655. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28656. #endif
  28657. XMEMSET(userA, 0, sizeof *userA);
  28658. XMEMSET(userB, 0, sizeof *userB);
  28659. XMEMSET(pubKey, 0, sizeof *pubKey);
  28660. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  28661. if (ret != 0)
  28662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28663. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  28664. if (ret != 0)
  28665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28666. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28667. if (ret != 0)
  28668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28669. #ifndef WC_NO_RNG
  28670. ret = wc_ecc_sm2_make_key(rng, userA, WC_ECC_FLAG_NONE);
  28671. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  28672. goto done; /* catch case, where curve is not supported */
  28673. if (ret != 0)
  28674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28675. TEST_SLEEP();
  28676. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  28677. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  28678. if (curveSize != userA->dp->size) {
  28679. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28680. }
  28681. }
  28682. ret = wc_ecc_check_key(userA);
  28683. if (ret != 0)
  28684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28685. TEST_SLEEP();
  28686. ret = wc_ecc_sm2_make_key(rng, userB, WC_ECC_FLAG_NONE);
  28687. if (ret != 0)
  28688. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28689. /* only perform the below tests if the key size matches */
  28690. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  28691. if (ret != 0) {
  28692. ret = ECC_CURVE_OID_E;
  28693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28694. }
  28695. #ifdef HAVE_ECC_DHE
  28696. #if defined(ECC_TIMING_RESISTANT)
  28697. ret = wc_ecc_set_rng(userA, rng);
  28698. if (ret != 0)
  28699. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28700. ret = wc_ecc_set_rng(userB, rng);
  28701. if (ret != 0)
  28702. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28703. #endif
  28704. x = ECC_SHARED_SIZE;
  28705. ret = wc_ecc_sm2_shared_secret(userA, userB, sharedA, &x);
  28706. if (ret != 0)
  28707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28708. y = ECC_SHARED_SIZE;
  28709. ret = wc_ecc_sm2_shared_secret(userB, userA, sharedB, &y);
  28710. if (ret != 0)
  28711. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28712. if (y != x)
  28713. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28714. if (XMEMCMP(sharedA, sharedB, x))
  28715. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28716. #endif /* HAVE_ECC_DHE */
  28717. #ifdef HAVE_ECC_KEY_EXPORT
  28718. x = ECC_KEY_EXPORT_BUF_SIZE;
  28719. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  28720. if (ret != 0)
  28721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28722. #ifdef HAVE_ECC_KEY_IMPORT
  28723. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28724. if (ret != 0)
  28725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28726. #ifdef HAVE_ECC_DHE
  28727. y = ECC_SHARED_SIZE;
  28728. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28729. if (ret != 0)
  28730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28731. if (XMEMCMP(sharedA, sharedB, y))
  28732. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28733. #endif /* HAVE_ECC_DHE */
  28734. #ifdef HAVE_COMP_KEY
  28735. /* try compressed export / import too */
  28736. x = ECC_KEY_EXPORT_BUF_SIZE;
  28737. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  28738. if (ret != 0)
  28739. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28740. wc_ecc_free(pubKey);
  28741. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28742. if (ret != 0)
  28743. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28744. #endif
  28745. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28746. if (ret != 0)
  28747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28748. #ifdef HAVE_ECC_DHE
  28749. y = ECC_SHARED_SIZE;
  28750. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28751. if (ret != 0)
  28752. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28753. if (XMEMCMP(sharedA, sharedB, y))
  28754. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28755. #endif /* HAVE_ECC_DHE */
  28756. #endif /* HAVE_ECC_KEY_IMPORT */
  28757. #endif /* HAVE_ECC_KEY_EXPORT */
  28758. #endif /* !WC_NO_RNG */
  28759. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  28760. !defined(WC_NO_RNG))
  28761. #ifdef HAVE_ECC_SIGN
  28762. /* ECC w/out Shamir has issue with all 0 digest */
  28763. /* WC_BIGINT doesn't have 0 len well on hardware */
  28764. /* Cryptocell has issues with all 0 digest */
  28765. #if defined(ECC_SHAMIR)
  28766. /* test DSA sign hash with zeros */
  28767. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28768. digest[i] = 0;
  28769. }
  28770. x = ECC_SIG_SIZE;
  28771. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28772. if (ret != 0)
  28773. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28774. for (i = 0; i < testVerifyCount; i++) {
  28775. verify = 0;
  28776. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28777. userA);
  28778. if (ret != 0)
  28779. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28780. if (verify != 1)
  28781. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28782. }
  28783. #endif /* ECC_SHAMIR */
  28784. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  28785. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28786. digest[i] = (byte)i;
  28787. }
  28788. x = ECC_SIG_SIZE;
  28789. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28790. if (ret != 0)
  28791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28792. for (i = 0; i < testVerifyCount; i++) {
  28793. verify = 0;
  28794. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28795. userA);
  28796. if (ret != 0)
  28797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28798. if (verify != 1)
  28799. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28800. }
  28801. #endif /* HAVE_ECC_SIGN */
  28802. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT && !WC_NO_RNG) */
  28803. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  28804. x = ECC_KEY_EXPORT_BUF_SIZE;
  28805. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  28806. if (ret != 0)
  28807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28808. #elif defined(HAVE_ECC_KEY_EXPORT)
  28809. (void)exportBuf;
  28810. #endif /* HAVE_ECC_KEY_EXPORT */
  28811. done:
  28812. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28813. if (userA != NULL) {
  28814. wc_ecc_free(userA);
  28815. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28816. }
  28817. if (userB != NULL) {
  28818. wc_ecc_free(userB);
  28819. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28820. }
  28821. if (pubKey != NULL) {
  28822. wc_ecc_free(pubKey);
  28823. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28824. }
  28825. #else
  28826. wc_ecc_free(pubKey);
  28827. wc_ecc_free(userB);
  28828. wc_ecc_free(userA);
  28829. #endif
  28830. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  28831. WC_FREE_VAR(sharedA, HEAP_HINT);
  28832. WC_FREE_VAR(sharedB, HEAP_HINT);
  28833. #endif
  28834. #ifdef HAVE_ECC_KEY_EXPORT
  28835. WC_FREE_VAR(exportBuf, HEAP_HINT);
  28836. #endif
  28837. #ifdef HAVE_ECC_SIGN
  28838. WC_FREE_VAR(sig, HEAP_HINT);
  28839. WC_FREE_VAR(digest, HEAP_HINT);
  28840. #endif
  28841. (void)keySize;
  28842. (void)curve_id;
  28843. (void)rng;
  28844. return ret;
  28845. }
  28846. #endif /* HAVE_ECC_VERIFY */
  28847. static int test_sm2_create_digest(void)
  28848. {
  28849. #ifndef WOLFSSL_SM3
  28850. const byte msg[] = "message to sign";
  28851. const byte id[] = "0123456789";
  28852. const byte badId[] = "0123556789";
  28853. byte expected[] = {
  28854. 0xdd, 0x4d, 0x65, 0x49, 0xa3, 0x64, 0x76, 0xc0,
  28855. 0x73, 0x05, 0xdc, 0x05, 0x16, 0xb5, 0xee, 0x9f,
  28856. 0x82, 0xf9, 0xe9, 0x7d, 0x01, 0x1a, 0xdc, 0x88,
  28857. 0x5a, 0x59, 0x9c, 0x44, 0xcc, 0x47, 0xa4, 0x78
  28858. };
  28859. ecc_key key;
  28860. int ret;
  28861. /* test key values */
  28862. const char qx[] =
  28863. "af178b7b8740cc9d5b493fbd22049c12621bc27dcc5802e75ff4d045a4158baf";
  28864. const char qy[] =
  28865. "89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
  28866. const char d[] =
  28867. "b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
  28868. int hash_type = WC_HASH_TYPE_SHA256;
  28869. byte digest[WC_SHA256_DIGEST_SIZE];
  28870. #else
  28871. ecc_key key;
  28872. int ret;
  28873. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
  28874. 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
  28875. const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28876. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28877. 0x00 };
  28878. const byte badId[] = "0123556789";
  28879. const char qx[] =
  28880. "09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
  28881. const char qy[] =
  28882. "CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
  28883. const char d[] =
  28884. "3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
  28885. byte expected[] = {
  28886. 0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
  28887. 0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
  28888. 0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
  28889. 0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
  28890. };
  28891. int hash_type = WC_HASH_TYPE_SM3;
  28892. byte digest[WC_SM3_DIGEST_SIZE];
  28893. #endif
  28894. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28895. if (ret != 0)
  28896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28897. ret = wc_ecc_import_raw(&key, qx, qy, d, "SM2P256V1");
  28898. if (ret != 0)
  28899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28900. ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
  28901. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28902. &key);
  28903. if (ret != 0)
  28904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28905. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
  28906. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28907. ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
  28908. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28909. &key);
  28910. if (ret != 0)
  28911. goto done;
  28912. /* should be different than the previous ID used */
  28913. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) == 0)
  28914. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28915. done:
  28916. wc_ecc_free(&key);
  28917. return ret;
  28918. }
  28919. static int test_sm2_verify(void)
  28920. {
  28921. int ret = 0;
  28922. #ifdef HAVE_ECC_VERIFY
  28923. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28924. ret = test_sm2_verify_caseA2();
  28925. if (ret != 0)
  28926. return ret;
  28927. #endif
  28928. ret = test_sm2_verify_case();
  28929. if (ret != 0)
  28930. return ret;
  28931. #endif /* HAVE_ECC_VERIFY */
  28932. ret = test_sm2_create_digest();
  28933. return ret;
  28934. }
  28935. #endif /* WOLFSSL_SM2 */
  28936. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  28937. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  28938. /* Make Cert / Sign example for ECC cert and ECC CA */
  28939. static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
  28940. {
  28941. wc_test_ret_t ret;
  28942. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28943. Cert *myCert = (Cert *)XMALLOC(sizeof *myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28944. #ifdef WOLFSSL_TEST_CERT
  28945. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28946. #endif
  28947. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28948. ecc_key *certPubKey = (ecc_key *)XMALLOC(sizeof *certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28949. #else
  28950. Cert myCert[1];
  28951. #ifdef WOLFSSL_TEST_CERT
  28952. DecodedCert decode[1];
  28953. #endif
  28954. ecc_key caEccKey[1];
  28955. ecc_key certPubKey[1];
  28956. #endif
  28957. int certSz;
  28958. size_t bytes = 0;
  28959. word32 idx = 0;
  28960. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
  28961. XFILE file;
  28962. #endif
  28963. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28964. byte* der = NULL;
  28965. #else
  28966. byte der[FOURK_BUF];
  28967. #endif
  28968. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28969. if ((myCert == NULL)
  28970. #ifdef WOLFSSL_TEST_CERT
  28971. || (decode == NULL)
  28972. #endif
  28973. || (caEccKey == NULL) || (certPubKey == NULL))
  28974. ERROR_OUT(MEMORY_E, exit);
  28975. #endif
  28976. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  28977. XMEMSET(certPubKey, 0, sizeof *certPubKey);
  28978. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28979. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28980. if (der == NULL) {
  28981. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28982. }
  28983. #endif
  28984. /* Get cert private key */
  28985. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28986. /* Get Cert Key 384 */
  28987. #ifdef USE_CERT_BUFFERS_256
  28988. XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
  28989. bytes = sizeof_ca_ecc_key_der_384;
  28990. #elif !defined(NO_FILESYSTEM)
  28991. file = XFOPEN(eccCaKey384File, "rb");
  28992. if (!file) {
  28993. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28994. }
  28995. bytes = XFREAD(der, 1, FOURK_BUF, file);
  28996. XFCLOSE(file);
  28997. if (bytes == 0)
  28998. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28999. (void)eccCaKeyFile;
  29000. #else
  29001. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
  29002. ERROR_OUT(ASN_PARSE_E, exit);
  29003. #endif /* USE_CERT_BUFFERS_256 */
  29004. /* end if ENABLE_ECC384_CERT_GEN_TEST */
  29005. #else
  29006. /* !ENABLE_ECC384_CERT_GEN_TEST */
  29007. #ifdef USE_CERT_BUFFERS_256
  29008. XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
  29009. bytes = sizeof_ca_ecc_key_der_256;
  29010. #else
  29011. file = XFOPEN(eccCaKeyFile, "rb");
  29012. if (!file) {
  29013. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29014. }
  29015. bytes = XFREAD(der, 1, FOURK_BUF, file);
  29016. XFCLOSE(file);
  29017. if (bytes == 0)
  29018. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29019. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29020. (void)eccCaKey384File;
  29021. #endif
  29022. #endif /* USE_CERT_BUFFERS_256 */
  29023. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29024. /* Get CA Key */
  29025. ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId);
  29026. if (ret != 0)
  29027. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29028. ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes);
  29029. if (ret != 0)
  29030. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29031. /* Make a public key */
  29032. ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId);
  29033. if (ret != 0)
  29034. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29035. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey);
  29036. #if defined(WOLFSSL_ASYNC_CRYPT)
  29037. ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE);
  29038. #endif
  29039. if (ret != 0)
  29040. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29041. TEST_SLEEP();
  29042. /* Setup Certificate */
  29043. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  29044. if (ret != 0)
  29045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29046. #ifndef NO_SHA256
  29047. myCert->sigType = CTC_SHA256wECDSA;
  29048. #else
  29049. myCert->sigType = CTC_SHAwECDSA;
  29050. #endif
  29051. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  29052. #ifdef WOLFSSL_CERT_EXT
  29053. /* add Policies */
  29054. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  29055. CTC_MAX_CERTPOL_SZ);
  29056. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  29057. CTC_MAX_CERTPOL_SZ);
  29058. myCert->certPoliciesNb = 2;
  29059. /* add SKID from the Public Key */
  29060. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey);
  29061. if (ret != 0)
  29062. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29063. /* add AKID from the Public Key */
  29064. ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey);
  29065. if (ret != 0)
  29066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29067. /* add Key Usage */
  29068. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  29069. if (ret != 0)
  29070. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29071. #endif /* WOLFSSL_CERT_EXT */
  29072. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29073. #if defined(USE_CERT_BUFFERS_256)
  29074. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
  29075. sizeof_ca_ecc_cert_der_384);
  29076. #elif !defined(NO_FILESYSTEM)
  29077. ret = wc_SetIssuer(myCert, eccCaCert384File);
  29078. (void)eccCaCertFile;
  29079. #else
  29080. /* not testing with embedded, no file system target */
  29081. ERROR_OUT(ASN_PARSE_E, exit);
  29082. #endif /* USE_CERT_BUFFERS_256 */
  29083. #else
  29084. /* not ENABLE_ECC384_CERT_GEN_TEST */
  29085. #if defined(USE_CERT_BUFFERS_256)
  29086. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
  29087. sizeof_ca_ecc_cert_der_256);
  29088. #else
  29089. ret = wc_SetIssuer(myCert, eccCaCertFile);
  29090. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29091. (void)eccCaCert384File;
  29092. #endif
  29093. #endif
  29094. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29095. if (ret < 0)
  29096. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29097. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng);
  29098. if (certSz < 0) {
  29099. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit);
  29100. }
  29101. ret = 0;
  29102. do {
  29103. #if defined(WOLFSSL_ASYNC_CRYPT)
  29104. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  29105. #endif
  29106. if (ret >= 0) {
  29107. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  29108. FOURK_BUF, NULL, caEccKey, rng);
  29109. }
  29110. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  29111. if (ret < 0)
  29112. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29113. certSz = (int)ret;
  29114. TEST_SLEEP();
  29115. #ifdef WOLFSSL_TEST_CERT
  29116. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  29117. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  29118. if (ret != 0) {
  29119. FreeDecodedCert(decode);
  29120. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29121. }
  29122. FreeDecodedCert(decode);
  29123. #endif
  29124. ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile,
  29125. CERT_TYPE);
  29126. if (ret != 0) {
  29127. goto exit;
  29128. }
  29129. exit:
  29130. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29131. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29132. #endif
  29133. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29134. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29135. #ifdef WOLFSSL_TEST_CERT
  29136. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29137. #endif
  29138. if (caEccKey != NULL) {
  29139. wc_ecc_free(caEccKey);
  29140. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29141. }
  29142. if (certPubKey != NULL) {
  29143. wc_ecc_free(certPubKey);
  29144. XFREE(certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29145. }
  29146. #else
  29147. wc_ecc_free(certPubKey);
  29148. wc_ecc_free(caEccKey);
  29149. #endif
  29150. return ret;
  29151. }
  29152. #endif /* WOLFSSL_CERT_GEN */
  29153. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  29154. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
  29155. (!defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES))
  29156. /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */
  29157. static wc_test_ret_t ecc_test_allocator(WC_RNG* rng)
  29158. {
  29159. wc_test_ret_t ret = 0;
  29160. ecc_key* key;
  29161. #ifdef WC_NO_RNG
  29162. word32 idx = 0;
  29163. #endif
  29164. key = wc_ecc_key_new(HEAP_HINT);
  29165. if (key == NULL) {
  29166. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29167. }
  29168. #ifndef WC_NO_RNG
  29169. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  29170. #if defined(WOLFSSL_ASYNC_CRYPT)
  29171. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  29172. #endif
  29173. if (ret != 0)
  29174. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29175. #else
  29176. /* use test ECC key */
  29177. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  29178. (word32)sizeof_ecc_key_der_256);
  29179. (void)rng;
  29180. #endif
  29181. exit:
  29182. wc_ecc_key_free(key);
  29183. return ret;
  29184. }
  29185. #endif
  29186. /* ECC Non-blocking tests for Sign and Verify */
  29187. /* Requires SP math and supports P384 or P256 */
  29188. /* ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" */
  29189. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_HAVE_SP_ECC) && \
  29190. defined(WOLFSSL_PUBLIC_MP)
  29191. /* ECC Private Key "d" */
  29192. static const byte p256PrivKey[] = {
  29193. /* SECP256R1 */
  29194. /* d */
  29195. 0x1e, 0xe7, 0x70, 0x07, 0xd3, 0x30, 0x94, 0x39,
  29196. 0x28, 0x90, 0xdf, 0x23, 0x88, 0x2c, 0x4a, 0x34,
  29197. 0x15, 0xdb, 0x4c, 0x43, 0xcd, 0xfa, 0xe5, 0x1f,
  29198. 0x3d, 0x4c, 0x37, 0xfe, 0x59, 0x3b, 0x96, 0xd8
  29199. };
  29200. #ifdef HAVE_ECC384
  29201. static const byte p384PrivKey[] = {
  29202. /* SECP384R1 */
  29203. /* d */
  29204. 0xa4, 0xe5, 0x06, 0xe8, 0x06, 0x16, 0x3e, 0xab,
  29205. 0x89, 0xf8, 0x60, 0x43, 0xc0, 0x60, 0x25, 0xdb,
  29206. 0xba, 0x7b, 0xfe, 0x19, 0x35, 0x08, 0x55, 0x65,
  29207. 0x76, 0xe2, 0xdc, 0xe0, 0x01, 0x8b, 0x6b, 0x68,
  29208. 0xdf, 0xcf, 0x6f, 0x80, 0x12, 0xce, 0x79, 0x37,
  29209. 0xeb, 0x2b, 0x9c, 0x7b, 0xc4, 0x68, 0x1c, 0x74
  29210. };
  29211. #endif /* HAVE_ECC384 */
  29212. #ifdef HAVE_ECC521
  29213. static const byte p521PrivKey[] = {
  29214. /* SECP521R1 */
  29215. /* d */
  29216. 0x01, 0x68, 0x91, 0x33, 0x53, 0xe2, 0x90, 0x68,
  29217. 0x11, 0x8f, 0xaa, 0xa8, 0x76, 0x0c, 0xf7, 0x2a,
  29218. 0x07, 0x1b, 0x92, 0x2a, 0xa7, 0x82, 0x3d, 0xfa,
  29219. 0x83, 0xce, 0x70, 0xc8, 0xc2, 0x60, 0x82, 0xfe,
  29220. 0x18, 0x88, 0x68, 0xda, 0x6a, 0x83, 0x46, 0x78,
  29221. 0xe4, 0xe9, 0xe9, 0xcc, 0x51, 0x7f, 0xed, 0x81,
  29222. 0x02, 0x32, 0xee, 0x26, 0x87, 0xcc, 0xed, 0x63,
  29223. 0x3f, 0x39, 0x27, 0xf0, 0xd7, 0x17, 0x77, 0xa1,
  29224. 0xa4, 0x36
  29225. };
  29226. #endif /* HAVE_ECC521 */
  29227. /* ECC public key Qx/Qy */
  29228. static const byte p256PubKey[] = {
  29229. /* SECP256R1 */
  29230. /* Qx */
  29231. 0x96, 0x93, 0x1c, 0x53, 0x0b, 0x43, 0x6c, 0x42,
  29232. 0x0c, 0x52, 0x90, 0xe4, 0xa7, 0xec, 0x98, 0xb1,
  29233. 0xaf, 0xd4, 0x14, 0x49, 0xd8, 0xc1, 0x42, 0x82,
  29234. 0x04, 0x78, 0xd1, 0x90, 0xae, 0xa0, 0x6c, 0x07,
  29235. /* Qy */
  29236. 0xf2, 0x3a, 0xb5, 0x10, 0x32, 0x8d, 0xce, 0x9e,
  29237. 0x76, 0xa0, 0xd2, 0x8c, 0xf3, 0xfc, 0xa9, 0x94,
  29238. 0x43, 0x24, 0xe6, 0x82, 0x00, 0x40, 0xc6, 0xdb,
  29239. 0x1c, 0x2f, 0xcd, 0x38, 0x4b, 0x60, 0xdd, 0x61
  29240. };
  29241. #ifdef HAVE_ECC384
  29242. static const byte p384PubKey[] = {
  29243. /* SECP384R1 */
  29244. /* Qx */
  29245. 0xea, 0xcf, 0x93, 0x4f, 0x2c, 0x09, 0xbb, 0x39,
  29246. 0x14, 0x0f, 0x56, 0x64, 0xc3, 0x40, 0xb4, 0xdf,
  29247. 0x0e, 0x63, 0xae, 0xe5, 0x71, 0x4b, 0x00, 0xcc,
  29248. 0x04, 0x97, 0xff, 0xe1, 0xe9, 0x38, 0x96, 0xbb,
  29249. 0x5f, 0x91, 0xb2, 0x6a, 0xcc, 0xb5, 0x39, 0x5f,
  29250. 0x8f, 0x70, 0x59, 0xf1, 0x01, 0xf6, 0x5a, 0x2b,
  29251. /* Qy */
  29252. 0x01, 0x6c, 0x68, 0x0b, 0xcf, 0x55, 0x25, 0xaf,
  29253. 0x6d, 0x98, 0x48, 0x0a, 0xa8, 0x74, 0xc9, 0xa9,
  29254. 0x17, 0xa0, 0x0c, 0xc3, 0xfb, 0xd3, 0x23, 0x68,
  29255. 0xfe, 0x04, 0x3c, 0x63, 0x50, 0x88, 0x3b, 0xb9,
  29256. 0x4f, 0x7c, 0x67, 0x34, 0xf7, 0x3b, 0xa9, 0x73,
  29257. 0xe7, 0x1b, 0xc3, 0x51, 0x5e, 0x22, 0x18, 0xec
  29258. };
  29259. #endif
  29260. #ifdef HAVE_ECC521
  29261. static const byte p521PubKey[] = {
  29262. /* SECP521R1 */
  29263. /* Qx */
  29264. 0x01, 0x62, 0x6e, 0xf1, 0x00, 0xec, 0xd8, 0x99,
  29265. 0x58, 0x9b, 0x80, 0x6b, 0xfe, 0x2c, 0xf1, 0xb2,
  29266. 0xf0, 0xc8, 0x48, 0xdf, 0xac, 0xd2, 0x3b, 0x71,
  29267. 0x29, 0xab, 0xf0, 0x66, 0x63, 0xd8, 0x8e, 0xb5,
  29268. 0xc8, 0xc2, 0xfc, 0x99, 0x44, 0xe2, 0x45, 0xb1,
  29269. 0x5a, 0x7b, 0xb9, 0x73, 0x01, 0xda, 0x79, 0xec,
  29270. 0x9c, 0x26, 0x27, 0x34, 0x45, 0x26, 0xd5, 0x89,
  29271. 0x4b, 0x44, 0xfe, 0x69, 0x4e, 0x72, 0x14, 0xe3,
  29272. 0x8b, 0xbc,
  29273. /* Qy */
  29274. 0x00, 0x0f, 0x09, 0xa2, 0x03, 0xc3, 0x5a, 0xdc,
  29275. 0x95, 0x82, 0xf6, 0xf9, 0xf6, 0x9c, 0xff, 0xb5,
  29276. 0x6b, 0x75, 0x95, 0x4b, 0xa4, 0x28, 0x5d, 0x9e,
  29277. 0x90, 0x04, 0xd1, 0xc0, 0x1e, 0xd5, 0xfd, 0x43,
  29278. 0x9e, 0x1e, 0x83, 0xc0, 0x11, 0x2b, 0x2b, 0x07,
  29279. 0x6d, 0xa9, 0x7a, 0x10, 0xd7, 0x67, 0xe7, 0x51,
  29280. 0x37, 0x24, 0xd8, 0xbf, 0x03, 0x0d, 0x8b, 0xb5,
  29281. 0x40, 0x5c, 0x4f, 0xd6, 0x13, 0x73, 0x42, 0xbc,
  29282. 0x91, 0xd9
  29283. };
  29284. /* perform verify of signature and hash using public key */
  29285. /* key is public Qx + public Qy */
  29286. /* sig is r + s */
  29287. static wc_test_ret_t crypto_ecc_verify(const byte *key, uint32_t keySz,
  29288. const byte *hash, uint32_t hashSz, const byte *sig, uint32_t sigSz,
  29289. uint32_t curveSz, int curveId)
  29290. {
  29291. wc_test_ret_t ret;
  29292. int verify_res = 0, count = 0;
  29293. mp_int r, s;
  29294. ecc_key ecc;
  29295. ecc_nb_ctx_t nb_ctx;
  29296. /* validate arguments */
  29297. if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 ||
  29298. hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2))
  29299. {
  29300. return WC_TEST_RET_ENC_NC;
  29301. }
  29302. /* Setup the ECC key */
  29303. ret = wc_ecc_init(&ecc);
  29304. if (ret < 0) {
  29305. return WC_TEST_RET_ENC_EC(ret);
  29306. }
  29307. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29308. if (ret != MP_OKAY) {
  29309. wc_ecc_free(&ecc);
  29310. return WC_TEST_RET_ENC_EC(ret);
  29311. }
  29312. /* Setup the signature r/s variables */
  29313. ret = mp_init(&r);
  29314. if (ret != MP_OKAY) {
  29315. wc_ecc_free(&ecc);
  29316. return WC_TEST_RET_ENC_EC(ret);
  29317. }
  29318. ret = mp_init(&s);
  29319. if (ret != MP_OKAY) {
  29320. mp_clear(&r);
  29321. wc_ecc_free(&ecc);
  29322. return WC_TEST_RET_ENC_EC(ret);
  29323. }
  29324. /* Import public key x/y */
  29325. ret = wc_ecc_import_unsigned(
  29326. &ecc,
  29327. (byte*)key, /* Public "x" Coordinate */
  29328. (byte*)(key + curveSz), /* Public "y" Coordinate */
  29329. NULL, /* Private "d" (optional) */
  29330. curveId /* ECC Curve Id */
  29331. );
  29332. /* Make sure it was a public key imported */
  29333. if (ret == 0 && ecc.type != ECC_PUBLICKEY) {
  29334. ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */
  29335. }
  29336. /* Import signature r/s */
  29337. if (ret == 0) {
  29338. ret = mp_read_unsigned_bin(&r, sig, curveSz);
  29339. if (ret < 0)
  29340. ret = WC_TEST_RET_ENC_EC(ret);
  29341. }
  29342. if (ret == 0) {
  29343. ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz);
  29344. if (ret < 0)
  29345. ret = WC_TEST_RET_ENC_EC(ret);
  29346. }
  29347. /* Verify ECC Signature */
  29348. if (ret == 0) {
  29349. do {
  29350. ret = wc_ecc_verify_hash_ex(
  29351. &r, &s, /* r/s as mp_int */
  29352. hash, hashSz, /* computed hash digest */
  29353. &verify_res, /* verification result 1=success */
  29354. &ecc
  29355. );
  29356. count++;
  29357. /* This is where real-time work could be called */
  29358. } while (ret == FP_WOULDBLOCK);
  29359. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29360. printf("ECC non-block verify: %d times\n", count);
  29361. #endif
  29362. if (ret < 0)
  29363. ret = WC_TEST_RET_ENC_EC(ret);
  29364. }
  29365. /* check verify result */
  29366. if (ret == 0 && verify_res == 0) {
  29367. ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */;
  29368. }
  29369. mp_clear(&r);
  29370. mp_clear(&s);
  29371. wc_ecc_free(&ecc);
  29372. (void)count;
  29373. return ret;
  29374. }
  29375. /* perform signature operation against hash using private key */
  29376. static wc_test_ret_t crypto_ecc_sign(const byte *key, uint32_t keySz,
  29377. const byte *hash, uint32_t hashSz, byte *sig, uint32_t* sigSz,
  29378. uint32_t curveSz, int curveId, WC_RNG* rng)
  29379. {
  29380. wc_test_ret_t ret;
  29381. int count = 0;
  29382. mp_int r, s;
  29383. ecc_key ecc;
  29384. ecc_nb_ctx_t nb_ctx;
  29385. /* validate arguments */
  29386. if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL ||
  29387. curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2))
  29388. {
  29389. return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */;
  29390. }
  29391. /* Initialize signature result */
  29392. memset(sig, 0, curveSz*2);
  29393. /* Setup the ECC key */
  29394. ret = wc_ecc_init(&ecc);
  29395. if (ret < 0) {
  29396. return WC_TEST_RET_ENC_EC(ret);
  29397. }
  29398. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29399. if (ret != MP_OKAY) {
  29400. wc_ecc_free(&ecc);
  29401. return WC_TEST_RET_ENC_EC(ret);
  29402. }
  29403. /* Setup the signature r/s variables */
  29404. ret = mp_init(&r);
  29405. if (ret != MP_OKAY) {
  29406. wc_ecc_free(&ecc);
  29407. return WC_TEST_RET_ENC_EC(ret);
  29408. }
  29409. ret = mp_init(&s);
  29410. if (ret != MP_OKAY) {
  29411. mp_clear(&r);
  29412. wc_ecc_free(&ecc);
  29413. return WC_TEST_RET_ENC_EC(ret);
  29414. }
  29415. /* Import private key "k" */
  29416. ret = wc_ecc_import_private_key_ex(
  29417. key, keySz, /* private key "d" */
  29418. NULL, 0, /* public (optional) */
  29419. &ecc,
  29420. curveId /* ECC Curve Id */
  29421. );
  29422. if (ret < 0)
  29423. ret = WC_TEST_RET_ENC_EC(ret);
  29424. if (ret == 0) {
  29425. do {
  29426. /* Verify ECC Signature */
  29427. ret = wc_ecc_sign_hash_ex(
  29428. hash, hashSz, /* computed hash digest */
  29429. rng, &ecc, /* random and key context */
  29430. &r, &s /* r/s as mp_int */
  29431. );
  29432. count++;
  29433. /* This is where real-time work could be called */
  29434. } while (ret == FP_WOULDBLOCK);
  29435. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29436. printf("ECC non-block sign: %d times\n", count);
  29437. #endif
  29438. if (ret < 0)
  29439. ret = WC_TEST_RET_ENC_EC(ret);
  29440. }
  29441. if (ret == 0) {
  29442. /* export r/s */
  29443. mp_to_unsigned_bin_len(&r, sig, curveSz);
  29444. mp_to_unsigned_bin_len(&s, sig + curveSz, curveSz);
  29445. }
  29446. mp_clear(&r);
  29447. mp_clear(&s);
  29448. wc_ecc_free(&ecc);
  29449. (void)count;
  29450. return ret;
  29451. }
  29452. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29453. /*
  29454. * This test doesn't work with WOLFSSL_VALIDATE_ECC_KEYGEN defined because we
  29455. * don't have non-blocking versions of the key checking functions, yet.
  29456. */
  29457. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29458. static wc_test_ret_t ecc_test_nonblock_dhe(int curveId, word32 curveSz,
  29459. const byte* privKey, const byte* pubKey, WC_RNG* rng)
  29460. {
  29461. wc_test_ret_t ret;
  29462. ecc_key keyA;
  29463. ecc_key keyB;
  29464. ecc_nb_ctx_t nbCtxA;
  29465. ecc_nb_ctx_t nbCtxB;
  29466. byte secretA[ECC_SHARED_SIZE];
  29467. byte secretB[ECC_SHARED_SIZE];
  29468. word32 secretSzA = ECC_SHARED_SIZE;
  29469. word32 secretSzB = ECC_SHARED_SIZE;
  29470. int count = 0;
  29471. ret = wc_ecc_init(&keyA);
  29472. if (ret == 0) {
  29473. ret = wc_ecc_init(&keyB);
  29474. if (ret < 0)
  29475. ret = WC_TEST_RET_ENC_EC(ret);
  29476. }
  29477. if (ret == 0) {
  29478. ret = wc_ecc_set_nonblock(&keyA, &nbCtxA);
  29479. if (ret < 0)
  29480. ret = WC_TEST_RET_ENC_EC(ret);
  29481. }
  29482. if (ret == 0) {
  29483. ret = wc_ecc_set_nonblock(&keyB, &nbCtxB);
  29484. if (ret < 0)
  29485. ret = WC_TEST_RET_ENC_EC(ret);
  29486. }
  29487. if (ret == 0) {
  29488. do {
  29489. ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId);
  29490. count++;
  29491. } while (ret == FP_WOULDBLOCK);
  29492. if (ret < 0)
  29493. ret = WC_TEST_RET_ENC_EC(ret);
  29494. }
  29495. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29496. fprintf(stderr, "ECC non-block key gen: %d times\n", count);
  29497. #endif
  29498. if (ret == 0) {
  29499. ret = wc_ecc_check_key(&keyA);
  29500. if (ret < 0)
  29501. ret = WC_TEST_RET_ENC_EC(ret);
  29502. }
  29503. if (ret == 0) {
  29504. ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz,
  29505. privKey, curveId);
  29506. if (ret < 0)
  29507. ret = WC_TEST_RET_ENC_EC(ret);
  29508. }
  29509. count = 0;
  29510. if (ret == 0) {
  29511. do {
  29512. ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA);
  29513. count++;
  29514. } while (ret == FP_WOULDBLOCK);
  29515. if (ret < 0)
  29516. ret = WC_TEST_RET_ENC_EC(ret);
  29517. }
  29518. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29519. fprintf(stderr, "ECC non-block shared secret: %d times\n", count);
  29520. #endif
  29521. if (ret == 0) {
  29522. do {
  29523. ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB);
  29524. } while (ret == FP_WOULDBLOCK);
  29525. if (ret < 0)
  29526. ret = WC_TEST_RET_ENC_EC(ret);
  29527. }
  29528. if (ret == 0) {
  29529. if (secretSzA != secretSzB ||
  29530. XMEMCMP(secretA, secretB, secretSzA) != 0) {
  29531. ret = WC_TEST_RET_ENC_NC;
  29532. }
  29533. }
  29534. wc_ecc_free(&keyA);
  29535. wc_ecc_free(&keyB);
  29536. return ret;
  29537. }
  29538. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29539. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29540. static wc_test_ret_t ecc_test_nonblock_ecdsa(int curveId, word32 curveSz,
  29541. const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz,
  29542. WC_RNG* rng)
  29543. {
  29544. wc_test_ret_t ret = 0;
  29545. byte* sig = NULL;
  29546. word32 sigSz = curveSz * 2;
  29547. static const byte hash[] = {
  29548. 0x8d, 0x28, 0xa3, 0x8b, 0x0b, 0xa9, 0xfe, 0xd4, 0x0e, 0x54, 0xc4, 0x17,
  29549. 0x3d, 0x54, 0x66, 0x34, 0xbf, 0x5d, 0x6f, 0x46, 0xc2, 0x20, 0xcb, 0xc3,
  29550. 0x22, 0xe9, 0xb0, 0xdf, 0xe7, 0x64, 0x3f, 0xd9
  29551. };
  29552. sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29553. if (sig == NULL) {
  29554. ret = WC_TEST_RET_ENC_ERRNO;
  29555. }
  29556. if (ret == 0) {
  29557. /* Sign hash using private key */
  29558. /* Note: result of an ECC sign varies for each call even with same
  29559. private key and hash. This is because a new random public key is
  29560. used for each operation. */
  29561. ret = crypto_ecc_sign(privKey, privKeySz, hash, sizeof(hash), sig,
  29562. &sigSz, curveSz, curveId, rng);
  29563. }
  29564. if (ret == 0) {
  29565. /* Verify generated signature is valid */
  29566. ret = crypto_ecc_verify(pubKey, pubKeySz, hash, sizeof(hash), sig,
  29567. sigSz, curveSz, curveId);
  29568. }
  29569. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29570. return ret;
  29571. }
  29572. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29573. static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng)
  29574. {
  29575. wc_test_ret_t ret = 0;
  29576. word32 i;
  29577. int curveIds[3] = {0, 0, 0};
  29578. word32 curveSzs[3] = {0, 0, 0};
  29579. const byte* privKeys[3] = {NULL, NULL, NULL};
  29580. word32 privKeySzs[3] = {0, 0, 0};
  29581. const byte* pubKeys[3] = {NULL, NULL, NULL};
  29582. word32 pubKeySzs[3] = {0, 0, 0};
  29583. curveIds[0] = ECC_SECP256R1;
  29584. curveSzs[0] = 32;
  29585. privKeys[0] = p256PrivKey;
  29586. privKeySzs[0] = sizeof(p256PrivKey);
  29587. pubKeys[0] = p256PubKey;
  29588. pubKeySzs[0] = sizeof(p256PubKey);
  29589. #ifdef HAVE_ECC384
  29590. curveIds[1] = ECC_SECP384R1;
  29591. curveSzs[1] = 48;
  29592. privKeys[1] = p384PrivKey;
  29593. privKeySzs[1] = sizeof(p384PrivKey);
  29594. pubKeys[1] = p384PubKey;
  29595. pubKeySzs[1] = sizeof(p384PubKey);
  29596. #endif
  29597. #ifdef HAVE_ECC521
  29598. curveIds[2] = ECC_SECP521R1;
  29599. curveSzs[2] = 66;
  29600. privKeys[2] = p521PrivKey;
  29601. privKeySzs[2] = sizeof(p521PrivKey);
  29602. pubKeys[2] = p521PubKey;
  29603. pubKeySzs[2] = sizeof(p521PubKey);
  29604. #endif
  29605. for (i = 0; ret == 0 && i < sizeof(curveIds) / sizeof(curveIds[0]); ++i) {
  29606. if (curveIds[i] == 0) {
  29607. continue;
  29608. }
  29609. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29610. ret = ecc_test_nonblock_ecdsa(curveIds[i], curveSzs[i], privKeys[i],
  29611. privKeySzs[i], pubKeys[i], pubKeySzs[i], rng);
  29612. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29613. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29614. if (ret == 0) {
  29615. ret = ecc_test_nonblock_dhe(curveIds[i], curveSzs[i], privKeys[i],
  29616. pubKeys[i], rng);
  29617. }
  29618. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29619. }
  29620. return ret;
  29621. }
  29622. #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */
  29623. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29624. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29625. (HAVE_FIPS_VERSION > 2)))
  29626. static int ecc_test_raw_enc_dec(void)
  29627. {
  29628. int ret;
  29629. unsigned char r[1];
  29630. word32 rSz;
  29631. unsigned char s[1];
  29632. word32 sSz;
  29633. unsigned char rZero[] = { 0, 0, 0, 0 };
  29634. unsigned char sOne[] = { 0, 0, 1 };
  29635. unsigned char sigRaw[32];
  29636. word32 sigRawSz;
  29637. unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 };
  29638. sigRawSz = sizeof(sigRaw);
  29639. ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne),
  29640. sigRaw, &sigRawSz);
  29641. if (ret != 0) {
  29642. return WC_TEST_RET_ENC_EC(ret);
  29643. }
  29644. if (sigRawSz != sizeof(expSig)) {
  29645. return WC_TEST_RET_ENC_EC((int)sigRawSz);
  29646. }
  29647. if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) {
  29648. return WC_TEST_RET_ENC_NC;
  29649. }
  29650. rSz = sizeof(r);
  29651. sSz = sizeof(s);
  29652. ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz);
  29653. if (ret != 0) {
  29654. return WC_TEST_RET_ENC_EC(ret);
  29655. }
  29656. if (rSz != 1) {
  29657. return WC_TEST_RET_ENC_EC((int)rSz);
  29658. }
  29659. if (sSz != 1) {
  29660. return WC_TEST_RET_ENC_EC((int)sSz);
  29661. }
  29662. if (r[0] != 0) {
  29663. return WC_TEST_RET_ENC_EC(r[0]);
  29664. }
  29665. if (s[0] != 1) {
  29666. return WC_TEST_RET_ENC_EC(s[0]);
  29667. }
  29668. return ret;
  29669. }
  29670. #endif
  29671. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void)
  29672. {
  29673. wc_test_ret_t ret;
  29674. WC_RNG rng;
  29675. WOLFSSL_ENTER("ecc_test");
  29676. #if defined(ECC_MIN_KEY_SZ)
  29677. WOLFSSL_MSG_EX("ecc_test ECC_MIN_KEY_SZ = %d\n", ECC_MIN_KEY_SZ);
  29678. #else
  29679. WOLFSSL_MSG("ecc_test ECC_MIN_KEY_SZ not defined.");
  29680. #endif
  29681. #if defined(WOLFSSL_CERT_EXT) && \
  29682. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29683. ret = ecc_decode_test();
  29684. if (ret < 0)
  29685. return ret;
  29686. #endif
  29687. #ifndef HAVE_FIPS
  29688. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  29689. #else
  29690. ret = wc_InitRng(&rng);
  29691. #endif
  29692. #ifndef WC_NO_RNG
  29693. if (ret != 0)
  29694. return WC_TEST_RET_ENC_EC(ret);
  29695. #else
  29696. (void)ret;
  29697. #endif
  29698. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  29699. ret = ecc_test_curve(&rng, 14, ECC_CURVE_DEF);
  29700. if (ret < 0) {
  29701. printf("keySize=14, Default\n");
  29702. goto done;
  29703. }
  29704. #endif /* HAVE_ECC112 */
  29705. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  29706. ret = ecc_test_curve(&rng, 16, ECC_CURVE_DEF);
  29707. if (ret < 0) {
  29708. printf("keySize=16, Default\n");
  29709. goto done;
  29710. }
  29711. #endif /* HAVE_ECC128 */
  29712. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  29713. ret = ecc_test_curve(&rng, 20, ECC_CURVE_DEF);
  29714. if (ret < 0) {
  29715. printf("keySize=20, Default\n");
  29716. goto done;
  29717. }
  29718. #endif /* HAVE_ECC160 */
  29719. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  29720. #if !FIPS_VERSION3_GE(6,0,0)
  29721. ret = ecc_test_curve(&rng, 24, ECC_CURVE_DEF);
  29722. if (ret < 0) {
  29723. printf("keySize=24, Default\n");
  29724. goto done;
  29725. }
  29726. #endif
  29727. #endif /* HAVE_ECC192 */
  29728. #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224
  29729. ret = ecc_test_curve(&rng, 28, ECC_CURVE_DEF);
  29730. if (ret < 0) {
  29731. printf("keySize=28, Default\n");
  29732. goto done;
  29733. }
  29734. #endif /* HAVE_ECC224 */
  29735. #if (defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 239
  29736. ret = ecc_test_curve(&rng, 30, ECC_CURVE_DEF);
  29737. if (ret < 0) {
  29738. printf("keySize=30, Default\n");
  29739. goto done;
  29740. }
  29741. #endif /* HAVE_ECC239 */
  29742. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29743. ret = ecc_test_curve(&rng, 32, ECC_CURVE_DEF);
  29744. if (ret < 0) {
  29745. printf("keySize=32, Default\n");
  29746. goto done;
  29747. }
  29748. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29749. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  29750. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  29751. ret = ecc_point_test();
  29752. if (ret < 0) {
  29753. goto done;
  29754. }
  29755. #endif
  29756. #if !defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES)
  29757. ret = ecc_def_curve_test(&rng);
  29758. if (ret < 0) {
  29759. printf("Default\n");
  29760. goto done;
  29761. }
  29762. #endif
  29763. #endif /* !NO_ECC256 */
  29764. #if (defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 320
  29765. ret = ecc_test_curve(&rng, 40, ECC_CURVE_DEF);
  29766. if (ret < 0) {
  29767. printf("keySize=40, Default\n");
  29768. goto done;
  29769. }
  29770. #endif /* HAVE_ECC320 */
  29771. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  29772. ret = ecc_test_curve(&rng, 48, ECC_CURVE_DEF);
  29773. if (ret < 0) {
  29774. printf("keySize=48, Default\n");
  29775. goto done;
  29776. }
  29777. #endif /* HAVE_ECC384 */
  29778. #if (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 512
  29779. ret = ecc_test_curve(&rng, 64, ECC_CURVE_DEF);
  29780. if (ret < 0) {
  29781. printf("keySize=64, Default\n");
  29782. goto done;
  29783. }
  29784. #endif /* HAVE_ECC512 */
  29785. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  29786. ret = ecc_test_curve(&rng, 66, ECC_CURVE_DEF);
  29787. if (ret < 0) {
  29788. printf("keySize=66, Default\n");
  29789. goto done;
  29790. }
  29791. #endif /* HAVE_ECC521 */
  29792. #ifdef WOLFSSL_SM2
  29793. ret = ecc_test_curve(&rng, 32, ECC_SM2P256V1);
  29794. if (ret < 0) {
  29795. printf("SM2\n");
  29796. goto done;
  29797. }
  29798. #endif
  29799. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29800. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29801. (HAVE_FIPS_VERSION > 2)))
  29802. ret = ecc_test_raw_enc_dec();
  29803. if (ret != 0) {
  29804. printf("raw sig encode/decode\n");
  29805. goto done;
  29806. }
  29807. #endif
  29808. #if defined(WOLFSSL_CUSTOM_CURVES)
  29809. ret = ecc_test_custom_curves(&rng);
  29810. if (ret != 0) {
  29811. printf("Custom\n");
  29812. goto done;
  29813. }
  29814. #endif
  29815. #if defined(WOLFSSL_SM2)
  29816. ret = test_sm2_verify();
  29817. if (ret != 0) {
  29818. printf("SM2 Verify\n");
  29819. goto done;
  29820. }
  29821. ret = ecc_sm2_test_curve(&rng, ECC_TEST_VERIFY_COUNT);
  29822. if (ret != 0) {
  29823. printf("SM2 test\n");
  29824. goto done;
  29825. }
  29826. #endif
  29827. #if defined(HAVE_ECC_SIGN) && \
  29828. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  29829. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  29830. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  29831. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29832. ret = ecc_test_deterministic_k(&rng);
  29833. if (ret != 0) {
  29834. printf("ecc_test_deterministic_k failed!\n");
  29835. goto done;
  29836. }
  29837. #endif
  29838. #ifdef WOLFSSL_PUBLIC_MP
  29839. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  29840. ECC_MIN_KEY_SZ <= 384
  29841. ret = ecc384_test_deterministic_k(&rng);
  29842. if (ret != 0) {
  29843. printf("ecc384_test_deterministic_k failed!\n");
  29844. goto done;
  29845. }
  29846. #endif
  29847. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && \
  29848. ECC_MIN_KEY_SZ <= 521
  29849. ret = ecc521_test_deterministic_k(&rng);
  29850. if (ret != 0) {
  29851. printf("ecc512_test_deterministic_k failed!\n");
  29852. goto done;
  29853. }
  29854. #endif
  29855. #endif
  29856. #endif
  29857. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  29858. !defined(WOLFSSL_KCAPI_ECC)
  29859. ret = ecc_test_sign_vectors(&rng);
  29860. if (ret != 0) {
  29861. printf("ecc_test_sign_vectors failed!\n");
  29862. goto done;
  29863. }
  29864. #endif
  29865. #if defined(HAVE_ECC_VECTOR_TEST) && defined(HAVE_ECC_CDH) && \
  29866. defined(HAVE_ECC_DHE)
  29867. ret = ecc_test_cdh_vectors(&rng);
  29868. if (ret != 0) {
  29869. printf("ecc_test_cdh_vectors failed!\n");
  29870. goto done;
  29871. }
  29872. #endif
  29873. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29874. !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
  29875. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  29876. ret = ecc_test_make_pub(&rng);
  29877. if (ret != 0) {
  29878. printf("ecc_test_make_pub failed!\n");
  29879. goto done;
  29880. }
  29881. #elif defined(HAVE_ECC_KEY_IMPORT)
  29882. (void)ecc_test_make_pub; /* for compiler warning */
  29883. #endif
  29884. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  29885. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  29886. ret = ecc_test_cert_gen(&rng);
  29887. if (ret != 0) {
  29888. printf("ecc_test_cert_gen failed!\n");
  29889. goto done;
  29890. }
  29891. #endif
  29892. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) && \
  29893. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && (!defined(NO_ECC_SECP) || \
  29894. defined(WOLFSSL_CUSTOM_CURVES))
  29895. ret = ecc_test_allocator(&rng);
  29896. if (ret != 0) {
  29897. printf("ecc_test_allocator failed!\n");
  29898. goto done;
  29899. }
  29900. #endif
  29901. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  29902. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29903. ret = ecc_test_nonblock(&rng);
  29904. if (ret != 0) {
  29905. printf("ecc_test_nonblock failed!\n");
  29906. goto done;
  29907. }
  29908. #endif
  29909. done:
  29910. wc_FreeRng(&rng);
  29911. return ret;
  29912. }
  29913. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  29914. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  29915. #if !defined(WOLFSSL_NO_MALLOC)
  29916. #if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3))
  29917. /* maximum encrypted message:
  29918. * msgSz (14) + pad (2) + pubKeySz(1+66*2) + ivSz(16) + digestSz(32) = 197 */
  29919. #define MAX_ECIES_TEST_SZ 200
  29920. static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
  29921. {
  29922. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29923. byte* plaintext;
  29924. byte* encrypted;
  29925. byte* decrypted;
  29926. #else
  29927. byte plaintext[MAX_ECIES_TEST_SZ];
  29928. byte encrypted[MAX_ECIES_TEST_SZ];
  29929. byte decrypted[MAX_ECIES_TEST_SZ];
  29930. #endif
  29931. ecEncCtx* aCtx = NULL;
  29932. ecEncCtx* bCtx = NULL;
  29933. static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  29934. 14, 15};
  29935. wc_test_ret_t ret = 0;
  29936. static const char message[] = "Hello wolfSSL!";
  29937. word32 plaintextLen;
  29938. word32 encryptLen = MAX_ECIES_TEST_SZ;
  29939. word32 decryptLen = MAX_ECIES_TEST_SZ;
  29940. int aInit = 0;
  29941. int bInit = 0;
  29942. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29943. plaintext = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29944. encrypted = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29945. decrypted = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29946. #endif
  29947. wc_ecc_free(a);
  29948. wc_ecc_free(b);
  29949. ret = wc_ecc_init(a);
  29950. if (ret != 0) {
  29951. ret = WC_TEST_RET_ENC_EC(ret);
  29952. }
  29953. else {
  29954. aInit = 1;
  29955. }
  29956. if (ret == 0) {
  29957. ret = wc_ecc_init(b);
  29958. if (ret != 0) {
  29959. ret = WC_TEST_RET_ENC_EC(ret);
  29960. }
  29961. else {
  29962. bInit = 1;
  29963. }
  29964. }
  29965. if (ret == 0)
  29966. ret = wc_ecc_make_key(rng, 32, a);
  29967. if (ret == 0)
  29968. ret = wc_ecc_make_key(rng, 32, b);
  29969. /* create context */
  29970. if (ret == 0) {
  29971. aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  29972. if (aCtx == NULL)
  29973. ret = WC_TEST_RET_ENC_NC;
  29974. }
  29975. if (ret == 0) {
  29976. bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  29977. if (bCtx == NULL)
  29978. ret = WC_TEST_RET_ENC_NC;
  29979. }
  29980. /* set salt */
  29981. if (ret == 0) {
  29982. ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt));
  29983. if (ret != 0)
  29984. ret = 10472;
  29985. }
  29986. if (ret == 0) {
  29987. ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt));
  29988. if (ret != 0)
  29989. ret = 10473;
  29990. }
  29991. XMEMSET(plaintext, 0, MAX_ECIES_TEST_SZ);
  29992. XSTRLCPY((char *)plaintext, message, sizeof plaintext);
  29993. plaintextLen = (((word32)XSTRLEN(message) + AES_BLOCK_SIZE - 1) /
  29994. AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
  29995. /* encrypt */
  29996. if (ret == 0) {
  29997. ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted,
  29998. &encryptLen, aCtx);
  29999. if (ret != 0)
  30000. ret = WC_TEST_RET_ENC_EC(ret);
  30001. }
  30002. /* decrypt */
  30003. if (ret == 0) {
  30004. ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted,
  30005. &decryptLen, bCtx);
  30006. if (ret != 0)
  30007. ret = WC_TEST_RET_ENC_EC(ret);
  30008. }
  30009. /* compare */
  30010. if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
  30011. ret = WC_TEST_RET_ENC_NC;
  30012. if (aInit) {
  30013. wc_ecc_free(a);
  30014. }
  30015. if (bInit) {
  30016. wc_ecc_free(b);
  30017. }
  30018. wc_ecc_ctx_free(aCtx);
  30019. wc_ecc_ctx_free(bCtx);
  30020. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30021. XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30022. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30023. XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30024. #endif
  30025. return ret;
  30026. }
  30027. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30028. #endif /* !WOLFSSL_NO_MALLOC */
  30029. /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in
  30030. * wolfFIPS 5.3.
  30031. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test().
  30032. */
  30033. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30034. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30035. ECC_MIN_KEY_SZ <= 256 && defined(WOLFSSL_AES_128)
  30036. static wc_test_ret_t ecc_encrypt_kat(WC_RNG *rng)
  30037. {
  30038. wc_test_ret_t ret = 0;
  30039. #ifdef WOLFSSL_ECIES_OLD
  30040. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30041. ecc_key* userA = NULL;
  30042. #else
  30043. ecc_key userA[1];
  30044. #endif
  30045. int userAInit = 0;
  30046. #endif
  30047. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30048. ecc_key* userB = NULL;
  30049. #else
  30050. ecc_key userB[1];
  30051. #endif
  30052. int userBInit = 0;
  30053. ecc_key* tmpKey;
  30054. byte plain[48];
  30055. word32 plainSz = sizeof(plain);
  30056. WOLFSSL_SMALL_STACK_STATIC const byte privKey[] = {
  30057. 0x04, 0x80, 0xef, 0x1d, 0xbe, 0x02, 0x0c, 0x20,
  30058. 0x5b, 0xab, 0x80, 0x35, 0x5b, 0x2a, 0x0f, 0x6d,
  30059. 0xd3, 0xb0, 0x7f, 0x7e, 0x7f, 0x86, 0x8a, 0x49,
  30060. 0xee, 0xb4, 0xaa, 0x09, 0x2d, 0x1e, 0x1d, 0x02
  30061. };
  30062. #if defined(WOLFSSL_ECIES_OLD) || defined(WOLFSSL_QNX_CAAM)
  30063. WOLFSSL_SMALL_STACK_STATIC const byte pubKey[] = {
  30064. 0x04,
  30065. /* X */
  30066. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30067. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30068. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30069. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30070. /* X */
  30071. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30072. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30073. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30074. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28
  30075. };
  30076. #endif
  30077. WOLFSSL_SMALL_STACK_STATIC const byte enc_msg[] = {
  30078. #ifdef WOLFSSL_ECIES_OLD
  30079. 0x42, 0x70, 0xbf, 0xf9, 0xf4, 0x7e, 0x4b, 0x9b,
  30080. 0xb5, 0x4c, 0xcc, 0xc5, 0x94, 0xa7, 0xef, 0xaa,
  30081. 0xc3, 0x7c, 0x85, 0xa6, 0x51, 0x6e, 0xd3, 0xfa,
  30082. 0x56, 0xc9, 0x10, 0x4d, 0x14, 0x32, 0x61, 0xb8,
  30083. 0xbb, 0x66, 0x7a, 0xb5, 0xbc, 0x95, 0xf8, 0xca,
  30084. 0xd1, 0x2a, 0x19, 0x51, 0x44, 0xd8, 0x0e, 0x57,
  30085. 0x34, 0xed, 0x45, 0x89, 0x2e, 0x57, 0xbe, 0xd5,
  30086. 0x06, 0x22, 0xd7, 0x13, 0x0a, 0x0e, 0x40, 0x36,
  30087. 0x0d, 0x05, 0x0d, 0xb6, 0xae, 0x61, 0x37, 0x18,
  30088. 0x83, 0x90, 0x0a, 0x27, 0x95, 0x41, 0x8c, 0x45
  30089. #elif defined(WOLFSSL_ECIES_ISO18033)
  30090. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30091. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30092. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30093. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30094. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30095. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30096. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30097. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30098. 0x28, 0xbb, 0x9f, 0xa8, 0x2d, 0xe1, 0xf1, 0x67,
  30099. 0x45, 0x02, 0x19, 0xdc, 0xc8, 0x24, 0x8b, 0x20,
  30100. 0x02, 0xa0, 0x8f, 0x95, 0x12, 0x55, 0x51, 0xf8,
  30101. 0x03, 0xc4, 0x54, 0x13, 0x98, 0x2d, 0xf0, 0x31,
  30102. 0x51, 0x80, 0x45, 0x24, 0xcb, 0x8b, 0x48, 0xa6,
  30103. 0x8b, 0x8e, 0x97, 0x9c, 0x56, 0x4d, 0x70, 0x00,
  30104. 0x53, 0xd3, 0x47, 0x00, 0x5a, 0x23, 0x8c, 0xf9,
  30105. 0xfd, 0xd2, 0x33, 0x2c, 0x43, 0x6e, 0x9e, 0xb2,
  30106. 0xf4, 0x95, 0xd4, 0xcf, 0x30, 0xd6, 0xa2, 0xc5,
  30107. 0x35, 0x96, 0x6a, 0xd4, 0x36, 0x15, 0xa9, 0xbd,
  30108. 0x7f
  30109. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30110. /* EC P-256 point */
  30111. 0x04,
  30112. /* X */
  30113. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30114. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30115. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30116. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30117. /* Y */
  30118. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30119. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30120. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30121. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28,
  30122. /* IV */
  30123. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30124. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30125. /* Encrypted Msg */
  30126. 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d, 0x50,
  30127. 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c, 0x1f,
  30128. 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc, 0x44,
  30129. 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca, 0x65,
  30130. 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61, 0xbd,
  30131. 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1, 0xde,
  30132. /* HMAC */
  30133. 0x5a, 0x22, 0xc1, 0x5d, 0x99, 0x66, 0x3f, 0x24,
  30134. 0x35, 0x96, 0xac, 0xf7, 0xf6, 0x28, 0x45, 0x16,
  30135. 0x52, 0x19, 0x0d, 0xe4, 0xb2, 0xca, 0x5b, 0x28,
  30136. 0x4e, 0xbb, 0xf3, 0x98, 0x57, 0xd7, 0x3b, 0xe2
  30137. #else
  30138. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30139. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30140. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30141. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30142. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30143. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30144. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30145. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30146. 0x28, 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d,
  30147. 0x50, 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c,
  30148. 0x1f, 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc,
  30149. 0x44, 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca,
  30150. 0x65, 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61,
  30151. 0xbd, 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1,
  30152. 0xde, 0xc7, 0x3f, 0x6f, 0xce, 0xbe, 0x49, 0x61,
  30153. 0x48, 0x01, 0x77, 0x41, 0xd0, 0xd8, 0x5b, 0x48,
  30154. 0xca, 0x4e, 0x47, 0x3e, 0x47, 0xbf, 0x1d, 0x28,
  30155. 0x4c, 0x18, 0x1a, 0xfb, 0x96, 0x95, 0xda, 0xde,
  30156. 0x55
  30157. #endif
  30158. };
  30159. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  30160. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  30161. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  30162. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  30163. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  30164. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  30165. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  30166. };
  30167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30168. userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT,
  30169. DYNAMIC_TYPE_TMP_BUFFER);
  30170. if (userB == NULL) {
  30171. ret = WC_TEST_RET_ENC_ERRNO;
  30172. }
  30173. #ifdef WOLFSSL_ECIES_OLD
  30174. if (ret == 0) {
  30175. userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT,
  30176. DYNAMIC_TYPE_TMP_BUFFER);
  30177. if (userA == NULL) {
  30178. ret = WC_TEST_RET_ENC_ERRNO;
  30179. }
  30180. }
  30181. #endif
  30182. #endif
  30183. if (ret == 0) {
  30184. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30185. if (ret != 0)
  30186. ret = WC_TEST_RET_ENC_EC(ret);
  30187. }
  30188. if (ret == 0) {
  30189. userBInit = 1;
  30190. #ifdef WOLFSSL_ECIES_OLD
  30191. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30192. if (ret != 0)
  30193. ret = WC_TEST_RET_ENC_EC(ret);
  30194. }
  30195. if (ret == 0) {
  30196. userAInit = 1;
  30197. tmpKey = userA;
  30198. #else
  30199. tmpKey = NULL;
  30200. #endif
  30201. }
  30202. if (ret == 0) {
  30203. #ifdef WOLFSSL_QNX_CAAM
  30204. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), pubKey,
  30205. sizeof(pubKey), userB, ECC_SECP256R1);
  30206. #else
  30207. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), NULL, 0,
  30208. userB, ECC_SECP256R1);
  30209. #endif
  30210. if (ret != 0)
  30211. ret = WC_TEST_RET_ENC_EC(ret);
  30212. }
  30213. #ifdef WOLFSSL_ECIES_OLD
  30214. if (ret == 0) {
  30215. ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA,
  30216. ECC_SECP256R1);
  30217. if (ret != 0)
  30218. ret = WC_TEST_RET_ENC_EC(ret);
  30219. }
  30220. #endif
  30221. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30222. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30223. !defined(HAVE_SELFTEST)
  30224. if (ret == 0) {
  30225. ret = wc_ecc_set_rng(userB, rng);
  30226. if (ret != 0) {
  30227. ret = WC_TEST_RET_ENC_EC(ret);
  30228. }
  30229. }
  30230. #else
  30231. (void)rng;
  30232. #endif
  30233. if (ret == 0) {
  30234. ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain,
  30235. &plainSz, NULL);
  30236. if (ret != 0)
  30237. ret = WC_TEST_RET_ENC_EC(ret);
  30238. }
  30239. if (ret == 0) {
  30240. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30241. ret = WC_TEST_RET_ENC_NC;
  30242. }
  30243. }
  30244. if (userBInit)
  30245. wc_ecc_free(userB);
  30246. #ifdef WOLFSSL_ECIES_OLD
  30247. if (userAInit)
  30248. wc_ecc_free(userA);
  30249. #endif
  30250. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30251. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30252. #ifdef WOLFSSL_ECIES_OLD
  30253. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30254. #endif
  30255. #endif
  30256. return ret;
  30257. }
  30258. #endif
  30259. #ifndef WOLFSSL_NO_MALLOC
  30260. static wc_test_ret_t ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB,
  30261. byte encAlgo, byte kdfAlgo, byte macAlgo)
  30262. {
  30263. wc_test_ret_t ret = 0;
  30264. byte msg[48];
  30265. byte plain[48];
  30266. #ifdef WOLFSSL_ECIES_OLD
  30267. byte out[80];
  30268. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30269. byte out[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30270. #else
  30271. byte out[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30272. #endif
  30273. word32 outSz = sizeof(out);
  30274. word32 plainSz = sizeof(plain);
  30275. int i;
  30276. ecEncCtx* cliCtx = NULL;
  30277. ecEncCtx* srvCtx = NULL;
  30278. byte cliSalt[EXCHANGE_SALT_SZ];
  30279. byte srvSalt[EXCHANGE_SALT_SZ];
  30280. const byte* tmpSalt;
  30281. byte msg2[48];
  30282. byte plain2[48];
  30283. #ifdef WOLFSSL_ECIES_OLD
  30284. byte out2[80];
  30285. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30286. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30287. #else
  30288. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30289. #endif
  30290. word32 outSz2 = sizeof(out2);
  30291. word32 plainSz2 = sizeof(plain2);
  30292. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30293. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof(ecc_key), HEAP_HINT,
  30294. DYNAMIC_TYPE_TMP_BUFFER);
  30295. #else
  30296. ecc_key tmpKey[1];
  30297. #endif
  30298. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30299. if (tmpKey == NULL) {
  30300. ERROR_OUT(MEMORY_E, done);
  30301. }
  30302. #endif
  30303. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30304. if (ret != 0)
  30305. goto done;
  30306. /* set message to incrementing 0,1,2,etc... */
  30307. for (i = 0; i < (int)sizeof(msg); i++)
  30308. msg[i] = i;
  30309. /* encrypt msg to B */
  30310. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL);
  30311. if (ret != 0) {
  30312. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30313. }
  30314. #ifdef WOLFSSL_ECIES_OLD
  30315. tmpKey->dp = userA->dp;
  30316. ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey);
  30317. if (ret != 0) {
  30318. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30319. }
  30320. #endif
  30321. /* decrypt msg from A */
  30322. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL);
  30323. if (ret != 0) {
  30324. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30325. }
  30326. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30327. ret = WC_TEST_RET_ENC_NC; goto done;
  30328. }
  30329. #ifndef WOLFSSL_ECIES_OLD
  30330. /* A decrypts msg (response) from B */
  30331. ret = wc_ecc_decrypt(userB, NULL, out, outSz, plain2, &plainSz2, NULL);
  30332. if (ret != 0)
  30333. goto done;
  30334. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30335. ret = WC_TEST_RET_ENC_NC; goto done;
  30336. }
  30337. #endif
  30338. /* let's verify message exchange works, A is client, B is server */
  30339. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30340. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30341. if (cliCtx == NULL || srvCtx == NULL) {
  30342. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30343. }
  30344. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30345. if (ret != 0)
  30346. goto done;
  30347. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30348. if (ret != 0)
  30349. goto done;
  30350. /* get salt to send to peer */
  30351. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30352. if (tmpSalt == NULL) {
  30353. ret = WC_TEST_RET_ENC_NC; goto done;
  30354. }
  30355. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30356. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30357. if (tmpSalt == NULL) {
  30358. ret = WC_TEST_RET_ENC_NC; goto done;
  30359. }
  30360. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30361. /* in actual use, we'd get the peer's salt over the transport */
  30362. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30363. if (ret != 0)
  30364. goto done;
  30365. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30366. if (ret != 0)
  30367. goto done;
  30368. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 11);
  30369. if (ret != 0)
  30370. goto done;
  30371. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 11);
  30372. if (ret != 0)
  30373. goto done;
  30374. /* get encrypted msg (request) to send to B */
  30375. outSz = sizeof(out);
  30376. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz,cliCtx);
  30377. if (ret != 0)
  30378. goto done;
  30379. #ifndef WOLFSSL_ECIES_OLD
  30380. wc_ecc_free(tmpKey);
  30381. #endif
  30382. /* B decrypts msg (request) from A */
  30383. plainSz = sizeof(plain);
  30384. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30385. if (ret != 0)
  30386. goto done;
  30387. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30388. ret = WC_TEST_RET_ENC_NC; goto done;
  30389. }
  30390. /* msg2 (response) from B to A */
  30391. for (i = 0; i < (int)sizeof(msg2); i++)
  30392. msg2[i] = i + sizeof(msg2);
  30393. /* get encrypted msg (response) to send to B */
  30394. ret = wc_ecc_encrypt(userB, userA, msg2, sizeof(msg2), out2,
  30395. &outSz2, srvCtx);
  30396. if (ret != 0)
  30397. goto done;
  30398. #ifdef WOLFSSL_ECIES_OLD
  30399. tmpKey->dp = userB->dp;
  30400. ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey);
  30401. if (ret != 0) {
  30402. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30403. }
  30404. #else
  30405. wc_ecc_free(tmpKey);
  30406. #endif
  30407. /* A decrypts msg (response) from B */
  30408. ret = wc_ecc_decrypt(userA, tmpKey, out2, outSz2, plain2, &plainSz2,
  30409. cliCtx);
  30410. if (ret != 0)
  30411. goto done;
  30412. if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) {
  30413. ret = WC_TEST_RET_ENC_NC; goto done;
  30414. }
  30415. #if defined(HAVE_COMP_KEY) && \
  30416. (! defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  30417. /* Create new client and server contexts. */
  30418. wc_ecc_ctx_free(srvCtx);
  30419. wc_ecc_ctx_free(cliCtx);
  30420. /* let's verify message exchange works, A is client, B is server */
  30421. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30422. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30423. if (cliCtx == NULL || srvCtx == NULL) {
  30424. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30425. }
  30426. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30427. if (ret != 0)
  30428. goto done;
  30429. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30430. if (ret != 0)
  30431. goto done;
  30432. /* get salt to send to peer */
  30433. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30434. if (tmpSalt == NULL) {
  30435. ret = WC_TEST_RET_ENC_NC; goto done;
  30436. }
  30437. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30438. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30439. if (tmpSalt == NULL) {
  30440. ret = WC_TEST_RET_ENC_NC; goto done;
  30441. }
  30442. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30443. /* in actual use, we'd get the peer's salt over the transport */
  30444. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30445. if (ret != 0)
  30446. goto done;
  30447. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30448. if (ret != 0)
  30449. goto done;
  30450. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 12);
  30451. if (ret != 0)
  30452. goto done;
  30453. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 12);
  30454. if (ret != 0)
  30455. goto done;
  30456. /* get encrypted msg (request) to send to B - compressed public key */
  30457. outSz = sizeof(out);
  30458. ret = wc_ecc_encrypt_ex(userA, userB, msg, sizeof(msg), out, &outSz, cliCtx,
  30459. 1);
  30460. if (ret != 0)
  30461. goto done;
  30462. #ifndef WOLFSSL_ECIES_OLD
  30463. wc_ecc_free(tmpKey);
  30464. #endif
  30465. /* B decrypts msg (request) from A - out has a compressed public key */
  30466. plainSz = sizeof(plain);
  30467. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30468. if (ret != 0)
  30469. goto done;
  30470. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30471. ret = WC_TEST_RET_ENC_NC; goto done;
  30472. }
  30473. #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */
  30474. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30475. (ECC_MIN_KEY_SZ <= 256) && defined(WOLFSSL_AES_128)
  30476. ret = ecc_encrypt_kat(rng);
  30477. #endif
  30478. done:
  30479. /* cleanup */
  30480. wc_ecc_ctx_free(srvCtx);
  30481. wc_ecc_ctx_free(cliCtx);
  30482. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30483. if (tmpKey != NULL) {
  30484. wc_ecc_free(tmpKey);
  30485. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30486. }
  30487. #else
  30488. wc_ecc_free(tmpKey);
  30489. #endif
  30490. return ret;
  30491. }
  30492. #endif
  30493. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30494. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void)
  30495. {
  30496. WC_RNG rng;
  30497. wc_test_ret_t ret;
  30498. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30499. ecc_key *userA;
  30500. ecc_key *userB;
  30501. #else
  30502. ecc_key userA[1];
  30503. ecc_key userB[1];
  30504. #endif
  30505. WOLFSSL_ENTER("ecc_encrypt_test");
  30506. #ifndef HAVE_FIPS
  30507. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30508. #else
  30509. ret = wc_InitRng(&rng);
  30510. #endif
  30511. if (ret != 0)
  30512. return WC_TEST_RET_ENC_EC(ret);
  30513. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30514. userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT,
  30515. DYNAMIC_TYPE_TMP_BUFFER);
  30516. userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT,
  30517. DYNAMIC_TYPE_TMP_BUFFER);
  30518. if ((userA == NULL) || (userB == NULL)) {
  30519. ERROR_OUT(MEMORY_E, done);
  30520. }
  30521. #endif
  30522. XMEMSET(userA, 0, sizeof *userA);
  30523. XMEMSET(userB, 0, sizeof *userB);
  30524. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30525. if (ret != 0)
  30526. goto done;
  30527. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30528. if (ret != 0)
  30529. goto done;
  30530. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userA);
  30531. #if defined(WOLFSSL_ASYNC_CRYPT)
  30532. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  30533. #endif
  30534. if (ret != 0){
  30535. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30536. }
  30537. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB);
  30538. #if defined(WOLFSSL_ASYNC_CRYPT)
  30539. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  30540. #endif
  30541. if (ret != 0){
  30542. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30543. }
  30544. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30545. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30546. !defined(HAVE_SELFTEST)
  30547. ret = wc_ecc_set_rng(userA, &rng);
  30548. if (ret != 0) {
  30549. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30550. }
  30551. ret = wc_ecc_set_rng(userB, &rng);
  30552. if (ret != 0) {
  30553. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30554. }
  30555. #endif
  30556. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30557. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30558. #ifdef WOLFSSL_AES_128
  30559. if (ret == 0) {
  30560. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30561. ecHKDF_SHA256, ecHMAC_SHA256);
  30562. if (ret != 0) {
  30563. printf("ECIES: AES_128_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30564. }
  30565. }
  30566. #ifdef HAVE_X963_KDF
  30567. if (ret == 0) {
  30568. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30569. ecKDF_X963_SHA256, ecHMAC_SHA256);
  30570. if (ret != 0) {
  30571. printf("ECIES: AES_128_CBC, KDF_X963_SHA256, HMAC_SHA256\n");
  30572. }
  30573. }
  30574. if (ret == 0) {
  30575. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30576. ecKDF_SHA256, ecHMAC_SHA256);
  30577. if (ret != 0) {
  30578. printf("ECIES: AES_128_CBC, KDF_SHA256, HMAC_SHA256\n");
  30579. }
  30580. }
  30581. #endif
  30582. #endif
  30583. #ifdef WOLFSSL_AES_256
  30584. if (ret == 0) {
  30585. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CBC,
  30586. ecHKDF_SHA256, ecHMAC_SHA256);
  30587. if (ret != 0) {
  30588. printf("ECIES: AES_256_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30589. }
  30590. }
  30591. #endif
  30592. #endif
  30593. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && !defined(WOLFSSL_NO_MALLOC)
  30594. #ifdef WOLFSSL_AES_128
  30595. if (ret == 0) {
  30596. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CTR,
  30597. ecHKDF_SHA256, ecHMAC_SHA256);
  30598. if (ret != 0) {
  30599. printf("ECIES: AES_128_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30600. }
  30601. }
  30602. #endif
  30603. #ifdef WOLFSSL_AES_256
  30604. if (ret == 0) {
  30605. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CTR,
  30606. ecHKDF_SHA256, ecHMAC_SHA256);
  30607. if (ret != 0) {
  30608. printf("ECIES: AES_256_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30609. }
  30610. }
  30611. #endif
  30612. #endif /* !NO_AES && WOLFSSL_AES_COUNTER */
  30613. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30614. if (ret == 0) {
  30615. ret = ecc_ctx_kdf_salt_test(&rng, userA, userB);
  30616. }
  30617. #endif
  30618. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30619. done:
  30620. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30621. if (userA != NULL) {
  30622. wc_ecc_free(userA);
  30623. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30624. }
  30625. if (userB != NULL) {
  30626. wc_ecc_free(userB);
  30627. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30628. }
  30629. #else
  30630. wc_ecc_free(userB);
  30631. wc_ecc_free(userA);
  30632. #endif
  30633. wc_FreeRng(&rng);
  30634. return ret;
  30635. }
  30636. #endif /* HAVE_ECC_ENCRYPT && HAVE_AES_CBC && WOLFSSL_AES_128 */
  30637. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  30638. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  30639. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  30640. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  30641. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void)
  30642. {
  30643. size_t bytes;
  30644. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30645. ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30646. ecc_key *servKey = (ecc_key *)XMALLOC(sizeof *servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30647. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof *tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30648. #else
  30649. ecc_key cliKey[1];
  30650. ecc_key servKey[1];
  30651. ecc_key tmpKey[1];
  30652. #endif
  30653. WC_RNG rng;
  30654. word32 idx = 0;
  30655. wc_test_ret_t ret;
  30656. /* pad our test message to 32 bytes so evenly divisible by AES_BLOCK_SZ */
  30657. byte in[] = "Everyone gets Friday off. ecc p";
  30658. word32 inLen = (word32)XSTRLEN((char*)in);
  30659. byte out[256];
  30660. byte plain[256];
  30661. int verify = 0;
  30662. word32 x;
  30663. WOLFSSL_ENTER("ecc_test_buffers");
  30664. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30665. if ((cliKey == NULL) || (servKey == NULL) || (tmpKey == NULL))
  30666. ERROR_OUT(MEMORY_E, done);
  30667. #endif
  30668. ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId);
  30669. if (ret != 0)
  30670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30671. ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId);
  30672. if (ret != 0)
  30673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30674. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30675. if (ret != 0)
  30676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30677. bytes = (size_t)sizeof_ecc_clikey_der_256;
  30678. /* place client key into ecc_key struct cliKey */
  30679. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey,
  30680. (word32)bytes);
  30681. if (ret != 0)
  30682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30683. idx = 0;
  30684. bytes = (size_t)sizeof_ecc_key_der_256;
  30685. /* place server key into ecc_key struct servKey */
  30686. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey,
  30687. (word32)bytes);
  30688. if (ret != 0)
  30689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30690. #ifndef WC_NO_RNG
  30691. #ifndef HAVE_FIPS
  30692. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30693. #else
  30694. ret = wc_InitRng(&rng);
  30695. #endif
  30696. if (ret != 0)
  30697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30698. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30699. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30700. !defined(HAVE_SELFTEST)
  30701. ret = wc_ecc_set_rng(cliKey, &rng);
  30702. if (ret != 0)
  30703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30704. ret = wc_ecc_set_rng(servKey, &rng);
  30705. if (ret != 0)
  30706. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30707. #endif
  30708. #endif /* !WC_NO_RNG */
  30709. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_HKDF) && \
  30710. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  30711. {
  30712. word32 y;
  30713. /* test encrypt and decrypt if they're available */
  30714. x = sizeof(out);
  30715. ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL);
  30716. if (ret < 0)
  30717. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30718. #ifdef WOLFSSL_ECIES_OLD
  30719. tmpKey->dp = cliKey->dp;
  30720. ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey);
  30721. if (ret != 0) {
  30722. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30723. }
  30724. #endif
  30725. y = sizeof(plain);
  30726. ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL);
  30727. if (ret < 0)
  30728. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30729. if (XMEMCMP(plain, in, inLen))
  30730. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30731. }
  30732. #endif
  30733. x = sizeof(out);
  30734. do {
  30735. #if defined(WOLFSSL_ASYNC_CRYPT)
  30736. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30737. #endif
  30738. if (ret == 0)
  30739. ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey);
  30740. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30741. if (ret < 0)
  30742. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30743. TEST_SLEEP();
  30744. XMEMSET(plain, 0, sizeof(plain));
  30745. do {
  30746. #if defined(WOLFSSL_ASYNC_CRYPT)
  30747. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30748. #endif
  30749. if (ret == 0)
  30750. ret = wc_ecc_verify_hash(out, x, in, inLen, &verify,
  30751. cliKey);
  30752. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30753. if (ret < 0)
  30754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30755. if (verify != 1)
  30756. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30757. TEST_SLEEP();
  30758. #ifdef WOLFSSL_CERT_EXT
  30759. idx = 0;
  30760. bytes = sizeof_ecc_clikeypub_der_256;
  30761. ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey,
  30762. (word32) bytes);
  30763. if (ret != 0)
  30764. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30765. #endif
  30766. ret = 0;
  30767. done:
  30768. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30769. if (cliKey != NULL) {
  30770. wc_ecc_free(cliKey);
  30771. XFREE(cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30772. }
  30773. if (servKey != NULL) {
  30774. wc_ecc_free(servKey);
  30775. XFREE(servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30776. }
  30777. if (tmpKey != NULL) {
  30778. wc_ecc_free(tmpKey);
  30779. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30780. }
  30781. #else
  30782. wc_ecc_free(cliKey);
  30783. wc_ecc_free(servKey);
  30784. wc_ecc_free(tmpKey);
  30785. #endif
  30786. wc_FreeRng(&rng);
  30787. return ret;
  30788. }
  30789. #endif /* USE_CERT_BUFFERS_256 && !WOLFSSL_ATECCX08A && !NO_ECC256 */
  30790. #endif /* HAVE_ECC */
  30791. #ifdef HAVE_CURVE25519
  30792. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30793. defined(HAVE_CURVE25519_KEY_IMPORT)
  30794. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30795. #define X25519_TEST_CNT 5
  30796. #else
  30797. #define X25519_TEST_CNT 1
  30798. #endif
  30799. static wc_test_ret_t curve25519_overflow_test(void)
  30800. {
  30801. /* secret key for party a */
  30802. byte sa[X25519_TEST_CNT][32] = {
  30803. {
  30804. 0x8d,0xaf,0x6e,0x7a,0xc1,0xeb,0x8d,0x30,
  30805. 0x99,0x86,0xd3,0x90,0x47,0x96,0x21,0x3c,
  30806. 0x3a,0x75,0xc0,0x7b,0x75,0x01,0x75,0xa3,
  30807. 0x81,0x4b,0xff,0x5a,0xbc,0x96,0x87,0x28
  30808. },
  30809. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30810. {
  30811. 0x9d,0x63,0x5f,0xce,0xe2,0xe8,0xd7,0xfb,
  30812. 0x68,0x77,0x0e,0x44,0xd1,0xad,0x87,0x2b,
  30813. 0xf4,0x65,0x06,0xb7,0xbb,0xdb,0xbe,0x6e,
  30814. 0x02,0x43,0x24,0xc7,0x3d,0x7b,0x88,0x60
  30815. },
  30816. {
  30817. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30818. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30819. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30820. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30821. },
  30822. {
  30823. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30824. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30825. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30826. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30827. },
  30828. {
  30829. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30830. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30831. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30832. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30833. }
  30834. #endif
  30835. };
  30836. /* public key for party b */
  30837. byte pb[X25519_TEST_CNT][32] = {
  30838. {
  30839. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30840. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30841. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30842. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30843. },
  30844. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30845. {
  30846. /* 0xff first byte in original - invalid! */
  30847. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30848. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30849. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30850. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30851. },
  30852. {
  30853. 0x36,0x1a,0x74,0x87,0x28,0x59,0xe0,0xb6,
  30854. 0xe4,0x2b,0x17,0x9b,0x16,0xb0,0x3b,0xf8,
  30855. 0xb8,0x9f,0x2a,0x8f,0xc5,0x33,0x68,0x4f,
  30856. 0xde,0x4d,0xd8,0x80,0x63,0xe7,0xb4,0x0a
  30857. },
  30858. {
  30859. 0x00,0x80,0x38,0x59,0x19,0x3a,0x66,0x12,
  30860. 0xfd,0xa1,0xec,0x1c,0x40,0x84,0x40,0xbd,
  30861. 0x64,0x10,0x8b,0x53,0x81,0x21,0x03,0x2d,
  30862. 0x7d,0x33,0xb4,0x01,0x57,0x0d,0xe1,0x89
  30863. },
  30864. {
  30865. 0x1d,0xf8,0xf8,0x33,0x89,0x6c,0xb7,0xba,
  30866. 0x94,0x73,0xfa,0xc2,0x36,0xac,0xbe,0x49,
  30867. 0xaf,0x85,0x3e,0x93,0x5f,0xae,0xb2,0xc0,
  30868. 0xc8,0x80,0x8f,0x4a,0xaa,0xd3,0x55,0x2b
  30869. }
  30870. #endif
  30871. };
  30872. /* expected shared key */
  30873. byte ss[X25519_TEST_CNT][32] = {
  30874. {
  30875. 0x5c,0x4c,0x85,0x5f,0xfb,0x20,0x38,0xcc,
  30876. 0x55,0x16,0x5b,0x8a,0xa7,0xed,0x57,0x6e,
  30877. 0x35,0xaa,0x71,0x67,0x85,0x1f,0xb6,0x28,
  30878. 0x17,0x07,0x7b,0xda,0x76,0xdd,0xe0,0xb4
  30879. },
  30880. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30881. {
  30882. 0x33,0xf6,0xc1,0x34,0x62,0x92,0x06,0x02,
  30883. 0x95,0xdb,0x91,0x4c,0x5d,0x52,0x54,0xc7,
  30884. 0xd2,0x5b,0x24,0xb5,0x4f,0x33,0x59,0x79,
  30885. 0x9f,0x6d,0x7e,0x4a,0x4c,0x30,0xd6,0x38
  30886. },
  30887. {
  30888. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30889. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30890. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30891. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02
  30892. },
  30893. {
  30894. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30895. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30896. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30897. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
  30898. },
  30899. {
  30900. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30901. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30902. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30903. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10
  30904. }
  30905. #endif
  30906. };
  30907. wc_test_ret_t ret = 0;
  30908. int i;
  30909. word32 y;
  30910. byte shared[32];
  30911. curve25519_key userA;
  30912. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  30913. for (i = 0; i < X25519_TEST_CNT; i++) {
  30914. if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i],
  30915. sizeof(pb[i]), &userA) != 0) {
  30916. ret = WC_TEST_RET_ENC_I(i); break;
  30917. }
  30918. /* test against known test vector */
  30919. XMEMSET(shared, 0, sizeof(shared));
  30920. y = sizeof(shared);
  30921. if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
  30922. ret = WC_TEST_RET_ENC_I(i); break;
  30923. }
  30924. if (XMEMCMP(ss[i], shared, y)) {
  30925. ret = WC_TEST_RET_ENC_I(i); break;
  30926. }
  30927. }
  30928. wc_curve25519_free(&userA);
  30929. return ret;
  30930. }
  30931. /* Test the wc_curve25519_check_public API.
  30932. *
  30933. * returns 0 on success and -ve on failure.
  30934. */
  30935. static wc_test_ret_t curve25519_check_public_test(void)
  30936. {
  30937. wc_test_ret_t ret;
  30938. /* Little-endian values that will fail */
  30939. byte fail_le[][CURVE25519_KEYSIZE] = {
  30940. {
  30941. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30942. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30943. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30944. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30945. },
  30946. {
  30947. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30948. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30949. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30950. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30951. },
  30952. {
  30953. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30954. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30955. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30956. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81
  30957. },
  30958. };
  30959. /* Big-endian values that will fail */
  30960. byte fail_be[][CURVE25519_KEYSIZE] = {
  30961. {
  30962. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30963. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30964. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30965. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30966. },
  30967. {
  30968. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30969. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30970. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30971. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30972. },
  30973. {
  30974. 0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30975. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30976. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30977. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30978. },
  30979. };
  30980. /* Good or valid public value */
  30981. byte good[CURVE25519_KEYSIZE] = {
  30982. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30983. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30984. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30985. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30986. };
  30987. int i;
  30988. /* Parameter checks */
  30989. /* NULL pointer */
  30990. ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN);
  30991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30992. return WC_TEST_RET_ENC_EC(ret);
  30993. }
  30994. ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN);
  30995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30996. return WC_TEST_RET_ENC_EC(ret);
  30997. }
  30998. /* Length of 0 treated differently to other invalid lengths for TLS */
  30999. ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN);
  31000. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31001. return WC_TEST_RET_ENC_EC(ret);
  31002. ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN);
  31003. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31004. return WC_TEST_RET_ENC_EC(ret);
  31005. /* Length not CURVE25519_KEYSIZE */
  31006. for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) {
  31007. if (i == CURVE25519_KEYSIZE)
  31008. continue;
  31009. if (wc_curve25519_check_public(good, (word32)i, EC25519_LITTLE_ENDIAN) !=
  31010. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31011. return WC_TEST_RET_ENC_I(i);
  31012. }
  31013. if (wc_curve25519_check_public(good, (word32)i, EC25519_BIG_ENDIAN) !=
  31014. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31015. return WC_TEST_RET_ENC_I(i);
  31016. }
  31017. }
  31018. /* Little-endian fail cases */
  31019. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  31020. if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE,
  31021. EC25519_LITTLE_ENDIAN) == 0) {
  31022. return WC_TEST_RET_ENC_I(i);
  31023. }
  31024. }
  31025. /* Big-endian fail cases */
  31026. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  31027. if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE,
  31028. EC25519_BIG_ENDIAN) == 0) {
  31029. return WC_TEST_RET_ENC_I(i);
  31030. }
  31031. }
  31032. /* Check a valid public value works! */
  31033. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31034. EC25519_LITTLE_ENDIAN);
  31035. if (ret != 0) {
  31036. return WC_TEST_RET_ENC_EC(ret);
  31037. }
  31038. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31039. EC25519_BIG_ENDIAN);
  31040. if (ret != 0) {
  31041. return WC_TEST_RET_ENC_EC(ret);
  31042. }
  31043. return 0;
  31044. }
  31045. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31046. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31047. defined(HAVE_CURVE25519_KEY_IMPORT)
  31048. static wc_test_ret_t curve255519_der_test(void)
  31049. {
  31050. wc_test_ret_t ret = 0;
  31051. /* certs/statickeys/x25519.der */
  31052. const byte kCurve25519PrivDer[] = {
  31053. 0x30, 0x2E, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E,
  31054. 0x04, 0x22, 0x04, 0x20, 0x78, 0x8E, 0x31, 0x5C, 0x33, 0xA9, 0x19, 0xC0,
  31055. 0x5E, 0x36, 0x70, 0x1B, 0xA4, 0xE8, 0xEF, 0xC1, 0x89, 0x8C, 0xB3, 0x15,
  31056. 0xC6, 0x79, 0xD3, 0xAC, 0x22, 0x00, 0xAE, 0xFA, 0xB3, 0xB7, 0x0F, 0x78
  31057. };
  31058. /* certs/statickeys/x25519-pub.der */
  31059. const byte kCurve25519PubDer[] = {
  31060. 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00,
  31061. 0x09, 0xBC, 0x8C, 0xC7, 0x45, 0x0D, 0xC1, 0xC2, 0x02, 0x57, 0x9A, 0x68,
  31062. 0x3A, 0xFD, 0x7A, 0xA8, 0xA5, 0x2F, 0xF0, 0x99, 0x39, 0x98, 0xEA, 0x26,
  31063. 0xA2, 0x5B, 0x38, 0xFD, 0x96, 0xDB, 0x2A, 0x26
  31064. };
  31065. curve25519_key key;
  31066. byte output[128];
  31067. word32 outputSz = 128;
  31068. word32 idx;
  31069. ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId);
  31070. if (ret != 0)
  31071. return WC_TEST_RET_ENC_EC(ret);
  31072. /* Test decode / encode of Curve25519 private key only */
  31073. if (ret == 0) {
  31074. idx = 0;
  31075. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key,
  31076. (word32)sizeof(kCurve25519PrivDer));
  31077. if (ret < 0)
  31078. ret = WC_TEST_RET_ENC_EC(ret);
  31079. }
  31080. if (ret == 0) {
  31081. outputSz = (word32)sizeof(output);
  31082. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31083. if (ret >= 0) {
  31084. outputSz = (word32)ret;
  31085. ret = 0;
  31086. }
  31087. else {
  31088. ret = WC_TEST_RET_ENC_EC(ret);
  31089. }
  31090. }
  31091. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31092. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31093. ret = WC_TEST_RET_ENC_NC;
  31094. }
  31095. /* Test decode / encode of Curve25519 public key only */
  31096. if (ret == 0) {
  31097. idx = 0;
  31098. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key,
  31099. (word32)sizeof(kCurve25519PubDer));
  31100. if (ret < 0)
  31101. ret = WC_TEST_RET_ENC_EC(ret);
  31102. }
  31103. if (ret == 0) {
  31104. outputSz = (word32)sizeof(output);
  31105. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31106. if (ret >= 0) {
  31107. outputSz = (word32)ret;
  31108. ret = 0;
  31109. }
  31110. else {
  31111. ret = WC_TEST_RET_ENC_EC(ret);
  31112. }
  31113. }
  31114. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31115. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31116. ret = WC_TEST_RET_ENC_NC;
  31117. }
  31118. /* Test decode/encode of Curve25519 private key (only) using generic API */
  31119. if (ret == 0) {
  31120. /* clear key, since generic API will try to decode all fields */
  31121. XMEMSET(&key, 0, sizeof(key));
  31122. idx = 0;
  31123. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31124. (word32)sizeof(kCurve25519PrivDer));
  31125. if (ret < 0) {
  31126. ret = WC_TEST_RET_ENC_EC(ret);
  31127. }
  31128. }
  31129. if (ret == 0) {
  31130. outputSz = (word32)sizeof(output);
  31131. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31132. if (ret >= 0) {
  31133. outputSz = (word32)ret;
  31134. ret = 0;
  31135. }
  31136. else {
  31137. ret = WC_TEST_RET_ENC_EC(ret);
  31138. }
  31139. }
  31140. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31141. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31142. ret = WC_TEST_RET_ENC_NC;
  31143. }
  31144. /* Test decode/encode of Curve25519 public key (only) using generic API */
  31145. if (ret == 0) {
  31146. /* clear key, since generic API will try to decode all fields */
  31147. XMEMSET(&key, 0, sizeof(key));
  31148. idx = 0;
  31149. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31150. (word32)sizeof(kCurve25519PubDer));
  31151. if (ret < 0) {
  31152. ret = WC_TEST_RET_ENC_EC(ret);
  31153. }
  31154. }
  31155. if (ret == 0) {
  31156. outputSz = (word32)sizeof(output);
  31157. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31158. if (ret >= 0) {
  31159. outputSz = (word32)ret;
  31160. ret = 0;
  31161. }
  31162. else {
  31163. ret = WC_TEST_RET_ENC_EC(ret);
  31164. }
  31165. }
  31166. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31167. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31168. ret = WC_TEST_RET_ENC_NC;
  31169. }
  31170. /* Test decode/encode key data containing both public and private fields */
  31171. if (ret == 0) {
  31172. XMEMSET(&key, 0 , sizeof(key));
  31173. /* Decode public key */
  31174. idx = 0;
  31175. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31176. (word32)sizeof(kCurve25519PubDer));
  31177. if (ret < 0) {
  31178. ret = WC_TEST_RET_ENC_EC(ret);
  31179. }
  31180. if (ret == 0) {
  31181. /* Decode private key */
  31182. idx = 0;
  31183. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31184. (word32)sizeof(kCurve25519PrivDer));
  31185. if (ret < 0) {
  31186. ret = WC_TEST_RET_ENC_EC(ret);
  31187. }
  31188. }
  31189. /* Both public and private flags should be set */
  31190. if ((ret == 0) && (!key.pubSet && !key.privSet)) {
  31191. ret = WC_TEST_RET_ENC_NC;
  31192. }
  31193. if (ret == 0) {
  31194. /* Export key to temporary DER */
  31195. outputSz = (word32)sizeof(output);
  31196. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31197. if (ret >= 0) {
  31198. outputSz = (word32)ret;
  31199. ret = 0;
  31200. }
  31201. else {
  31202. ret = WC_TEST_RET_ENC_EC(ret);
  31203. }
  31204. /* Re-import temporary DER */
  31205. if (ret == 0) {
  31206. idx = 0;
  31207. ret = wc_Curve25519KeyDecode(output, &idx, &key, sizeof(output));
  31208. if (ret < 0) {
  31209. ret = WC_TEST_RET_ENC_EC(ret);
  31210. }
  31211. }
  31212. /* Ensure public and private keys survived combined keypair
  31213. * export/import by re-exporting DER for private and public keys,
  31214. * individually, and re-checking output against known good vectors.
  31215. * This is slightly circuitous but does test the functionality
  31216. * without requiring the addition of new test keys */
  31217. if (ret == 0) {
  31218. idx = 0;
  31219. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx,
  31220. &key, (word32)sizeof(kCurve25519PrivDer));
  31221. if (ret < 0)
  31222. ret = WC_TEST_RET_ENC_EC(ret);
  31223. }
  31224. if (ret == 0) {
  31225. outputSz = (word32)sizeof(output);
  31226. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31227. if (ret >= 0) {
  31228. outputSz = (word32)ret;
  31229. ret = 0;
  31230. }
  31231. else {
  31232. ret = WC_TEST_RET_ENC_EC(ret);
  31233. }
  31234. }
  31235. if ((ret == 0) &&
  31236. (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31237. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31238. ret = WC_TEST_RET_ENC_NC;
  31239. }
  31240. if (ret == 0) {
  31241. idx = 0;
  31242. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx,
  31243. &key, (word32)sizeof(kCurve25519PubDer));
  31244. if (ret < 0)
  31245. ret = WC_TEST_RET_ENC_EC(ret);
  31246. }
  31247. if (ret == 0) {
  31248. outputSz = (word32)sizeof(output);
  31249. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31250. if (ret >= 0) {
  31251. outputSz = (word32)ret;
  31252. ret = 0;
  31253. }
  31254. else {
  31255. ret = WC_TEST_RET_ENC_EC(ret);
  31256. }
  31257. }
  31258. if ((ret == 0) &&
  31259. (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31260. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31261. ret = WC_TEST_RET_ENC_NC;
  31262. }
  31263. }
  31264. }
  31265. wc_curve25519_free(&key);
  31266. return ret;
  31267. }
  31268. #endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
  31269. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
  31270. {
  31271. WC_RNG rng;
  31272. wc_test_ret_t ret;
  31273. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31274. byte sharedA[32];
  31275. byte sharedB[32];
  31276. word32 y;
  31277. #endif
  31278. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31279. byte exportBuf[32];
  31280. #endif
  31281. word32 x = 0;
  31282. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31283. curve25519_key *userA = NULL, *userB = NULL, *pubKey = NULL;
  31284. #else
  31285. curve25519_key userA[1], userB[1], pubKey[1];
  31286. #endif
  31287. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31288. defined(HAVE_CURVE25519_KEY_IMPORT)
  31289. /* test vectors from
  31290. https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
  31291. */
  31292. /* secret key for party a */
  31293. byte sa[] = {
  31294. 0x5A,0xC9,0x9F,0x33,0x63,0x2E,0x5A,0x76,
  31295. 0x8D,0xE7,0xE8,0x1B,0xF8,0x54,0xC2,0x7C,
  31296. 0x46,0xE3,0xFB,0xF2,0xAB,0xBA,0xCD,0x29,
  31297. 0xEC,0x4A,0xFF,0x51,0x73,0x69,0xC6,0x60
  31298. };
  31299. /* public key for party a */
  31300. byte pa[] = {
  31301. 0x05,0x7E,0x23,0xEA,0x9F,0x1C,0xBE,0x8A,
  31302. 0x27,0x16,0x8F,0x6E,0x69,0x6A,0x79,0x1D,
  31303. 0xE6,0x1D,0xD3,0xAF,0x7A,0xCD,0x4E,0xEA,
  31304. 0xCC,0x6E,0x7B,0xA5,0x14,0xFD,0xA8,0x63
  31305. };
  31306. /* secret key for party b */
  31307. byte sb[] = {
  31308. 0x47,0xDC,0x3D,0x21,0x41,0x74,0x82,0x0E,
  31309. 0x11,0x54,0xB4,0x9B,0xC6,0xCD,0xB2,0xAB,
  31310. 0xD4,0x5E,0xE9,0x58,0x17,0x05,0x5D,0x25,
  31311. 0x5A,0xA3,0x58,0x31,0xB7,0x0D,0x32,0x60
  31312. };
  31313. /* public key for party b */
  31314. byte pb[] = {
  31315. 0x6E,0xB8,0x9D,0xA9,0x19,0x89,0xAE,0x37,
  31316. 0xC7,0xEA,0xC7,0x61,0x8D,0x9E,0x5C,0x49,
  31317. 0x51,0xDB,0xA1,0xD7,0x3C,0x28,0x5A,0xE1,
  31318. 0xCD,0x26,0xA8,0x55,0x02,0x0E,0xEF,0x04
  31319. };
  31320. /* expected shared key */
  31321. byte ss[] = {
  31322. 0x61,0x45,0x0C,0xD9,0x8E,0x36,0x01,0x6B,
  31323. 0x58,0x77,0x6A,0x89,0x7A,0x9F,0x0A,0xEF,
  31324. 0x73,0x8B,0x99,0xF0,0x94,0x68,0xB8,0xD6,
  31325. 0xB8,0x51,0x11,0x84,0xD5,0x34,0x94,0xAB
  31326. };
  31327. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  31328. (void)x;
  31329. WOLFSSL_ENTER("curve25519_test");
  31330. /* wc_FreeRng is always called on exit. Therefore wc_InitRng should be
  31331. * called before any exit goto's */
  31332. #ifndef HAVE_FIPS
  31333. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31334. #else
  31335. ret = wc_InitRng(&rng);
  31336. #endif
  31337. if (ret != 0)
  31338. return WC_TEST_RET_ENC_EC(ret);
  31339. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31340. userA = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31341. if (ret != 0)
  31342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31343. userB = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31344. if (ret != 0)
  31345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31346. pubKey = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31347. if (ret != 0)
  31348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31349. #else
  31350. wc_curve25519_init_ex(userA, HEAP_HINT, devId);
  31351. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31352. wc_curve25519_init_ex(pubKey, HEAP_HINT, devId);
  31353. #endif
  31354. /* make curve25519 keys */
  31355. ret = wc_curve25519_make_key(&rng, 32, userA);
  31356. if (ret != 0)
  31357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31358. ret = wc_curve25519_make_key(&rng, 32, userB);
  31359. if (ret != 0)
  31360. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31361. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31362. /* find shared secret key */
  31363. x = sizeof(sharedA);
  31364. if ((ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x)) != 0) {
  31365. printf("wc_curve25519_shared_secret 1 failed\n");
  31366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31367. }
  31368. y = sizeof(sharedB);
  31369. if ((ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y)) != 0) {
  31370. printf("wc_curve25519_shared_secret 2 failed\n");
  31371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31372. }
  31373. /* compare shared secret keys to test they are the same */
  31374. if (y != x)
  31375. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31376. if (XMEMCMP(sharedA, sharedB, x))
  31377. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31378. #endif
  31379. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31380. /* export a public key and import it for another user */
  31381. x = sizeof(exportBuf);
  31382. ret = wc_curve25519_export_public(userA, exportBuf, &x);
  31383. if (ret != 0)
  31384. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31385. #ifdef HAVE_CURVE25519_KEY_IMPORT
  31386. ret = wc_curve25519_import_public(exportBuf, x, pubKey);
  31387. if (ret != 0)
  31388. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31389. #endif
  31390. #endif
  31391. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31392. defined(HAVE_CURVE25519_KEY_IMPORT)
  31393. /* test shared key after importing a public key */
  31394. XMEMSET(sharedB, 0, sizeof(sharedB));
  31395. y = sizeof(sharedB);
  31396. if (wc_curve25519_shared_secret(userB, pubKey, sharedB, &y) != 0) {
  31397. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31398. }
  31399. if (XMEMCMP(sharedA, sharedB, y))
  31400. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31401. /* import RFC test vectors and compare shared key */
  31402. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31403. userA);
  31404. if (ret != 0)
  31405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31406. ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb),
  31407. userB);
  31408. if (ret != 0)
  31409. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31410. /* test against known test vector */
  31411. XMEMSET(sharedB, 0, sizeof(sharedB));
  31412. y = sizeof(sharedB);
  31413. ret = wc_curve25519_shared_secret(userA, userB, sharedB, &y);
  31414. if (ret != 0)
  31415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31416. if (XMEMCMP(ss, sharedB, y))
  31417. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31418. /* test swapping roles of keys and generating same shared key */
  31419. XMEMSET(sharedB, 0, sizeof(sharedB));
  31420. y = sizeof(sharedB);
  31421. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31422. if (ret != 0)
  31423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31424. if (XMEMCMP(ss, sharedB, y))
  31425. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31426. /* test with 1 generated key and 1 from known test vector */
  31427. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31428. userA);
  31429. if (ret != 0)
  31430. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31431. wc_curve25519_free(userB);
  31432. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31433. ret = wc_curve25519_make_key(&rng, 32, userB);
  31434. if (ret != 0)
  31435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31436. x = sizeof(sharedA);
  31437. ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x);
  31438. if (ret != 0)
  31439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31440. y = sizeof(sharedB);
  31441. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31442. if (ret != 0)
  31443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31444. /* compare shared secret keys to test they are the same */
  31445. if (y != x)
  31446. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31447. if (XMEMCMP(sharedA, sharedB, x))
  31448. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31449. ret = curve25519_overflow_test();
  31450. if (ret != 0)
  31451. goto cleanup;
  31452. ret = curve25519_check_public_test();
  31453. if (ret != 0)
  31454. goto cleanup;
  31455. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31456. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31457. defined(HAVE_CURVE25519_KEY_IMPORT)
  31458. ret = curve255519_der_test();
  31459. if (ret != 0)
  31460. goto cleanup;
  31461. #endif
  31462. cleanup:
  31463. /* clean up keys when done */
  31464. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31465. wc_curve25519_delete(pubKey, &pubKey);
  31466. wc_curve25519_delete(userB, &userB);
  31467. wc_curve25519_delete(userA, &userA);
  31468. #else
  31469. wc_curve25519_free(pubKey);
  31470. wc_curve25519_free(userB);
  31471. wc_curve25519_free(userA);
  31472. #endif
  31473. wc_FreeRng(&rng);
  31474. return ret;
  31475. }
  31476. #endif /* HAVE_CURVE25519 */
  31477. #ifdef HAVE_ED25519
  31478. #ifdef WOLFSSL_TEST_CERT
  31479. static wc_test_ret_t ed25519_test_cert(void)
  31480. {
  31481. DecodedCert cert[2];
  31482. DecodedCert* serverCert = NULL;
  31483. DecodedCert* caCert = NULL;
  31484. #ifdef HAVE_ED25519_VERIFY
  31485. ed25519_key key;
  31486. ed25519_key* pubKey = NULL;
  31487. int verify;
  31488. #endif /* HAVE_ED25519_VERIFY */
  31489. wc_test_ret_t ret;
  31490. byte* tmp;
  31491. size_t bytes;
  31492. XFILE file;
  31493. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31494. if (tmp == NULL) {
  31495. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31496. }
  31497. #ifdef USE_CERT_BUFFERS_256
  31498. XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert);
  31499. bytes = sizeof_ca_ed25519_cert;
  31500. #elif !defined(NO_FILESYSTEM)
  31501. file = XFOPEN(caEd25519Cert, "rb");
  31502. if (file == NULL) {
  31503. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31504. }
  31505. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31506. XFCLOSE(file);
  31507. if (bytes == 0)
  31508. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31509. #else
  31510. /* No certificate to use. */
  31511. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31512. #endif
  31513. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  31514. caCert = &cert[0];
  31515. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  31516. if (ret != 0)
  31517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31518. #ifdef USE_CERT_BUFFERS_256
  31519. XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert);
  31520. bytes = sizeof_server_ed25519_cert;
  31521. #elif !defined(NO_FILESYSTEM)
  31522. file = XFOPEN(serverEd25519Cert, "rb");
  31523. if (file == NULL) {
  31524. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31525. }
  31526. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31527. XFCLOSE(file);
  31528. if (bytes == 0)
  31529. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31530. #else
  31531. /* No certificate to use. */
  31532. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31533. #endif
  31534. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  31535. serverCert = &cert[1];
  31536. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  31537. if (ret != 0)
  31538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31539. #ifdef HAVE_ED25519_VERIFY
  31540. ret = wc_ed25519_init(&key);
  31541. if (ret < 0)
  31542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31543. pubKey = &key;
  31544. ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize,
  31545. pubKey);
  31546. if (ret < 0)
  31547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31548. ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength,
  31549. serverCert->source + serverCert->certBegin,
  31550. serverCert->sigIndex - serverCert->certBegin,
  31551. &verify, pubKey);
  31552. if (ret < 0 || verify != 1)
  31553. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31554. #endif /* HAVE_ED25519_VERIFY */
  31555. done:
  31556. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31557. #ifdef HAVE_ED25519_VERIFY
  31558. wc_ed25519_free(pubKey);
  31559. #endif /* HAVE_ED25519_VERIFY */
  31560. if (caCert != NULL)
  31561. FreeDecodedCert(caCert);
  31562. if (serverCert != NULL)
  31563. FreeDecodedCert(serverCert);
  31564. return ret;
  31565. }
  31566. static wc_test_ret_t ed25519_test_make_cert(void)
  31567. {
  31568. WC_RNG rng;
  31569. Cert cert;
  31570. DecodedCert decode;
  31571. ed25519_key key;
  31572. ed25519_key* privKey = NULL;
  31573. wc_test_ret_t ret = 0;
  31574. byte* tmp = NULL;
  31575. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  31576. #ifndef HAVE_FIPS
  31577. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31578. #else
  31579. ret = wc_InitRng(&rng);
  31580. #endif
  31581. if (ret != 0)
  31582. return WC_TEST_RET_ENC_EC(ret);
  31583. wc_ed25519_init(&key);
  31584. privKey = &key;
  31585. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, privKey);
  31586. cert.daysValid = 365 * 2;
  31587. cert.selfSigned = 1;
  31588. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  31589. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  31590. cert.isCA = 0;
  31591. #ifdef WOLFSSL_CERT_EXT
  31592. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  31593. if (ret < 0)
  31594. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31595. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31596. if (ret < 0)
  31597. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31598. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31599. if (ret < 0)
  31600. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31601. #endif
  31602. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31603. if (tmp == NULL) {
  31604. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31605. }
  31606. cert.sigType = CTC_ED25519;
  31607. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng);
  31608. if (ret < 0)
  31609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31610. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF,
  31611. ED25519_TYPE, privKey, &rng);
  31612. if (ret < 0)
  31613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31614. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  31615. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  31616. FreeDecodedCert(&decode);
  31617. if (ret != 0)
  31618. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31619. done:
  31620. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31621. wc_ed25519_free(privKey);
  31622. wc_FreeRng(&rng);
  31623. return ret;
  31624. }
  31625. #endif /* WOLFSSL_TEST_CERT */
  31626. #if defined(HAVE_ED25519_KEY_IMPORT)
  31627. static wc_test_ret_t ed25519_test_check_key(void)
  31628. {
  31629. /* Fails to find x-ordinate from this y-ordinate. */
  31630. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  31631. 0x40,
  31632. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31633. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31634. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31635. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31636. };
  31637. /* Y-ordinate value larger than prime. */
  31638. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  31639. 0x40,
  31640. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31641. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31642. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31643. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31644. };
  31645. /* Y-ordinate value equal to prime. */
  31646. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  31647. 0x40,
  31648. 0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31649. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31650. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31651. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31652. };
  31653. /* Y-ordinate value equal to prime - 1. */
  31654. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  31655. 0x40,
  31656. 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31657. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31658. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31659. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31660. };
  31661. ed25519_key key;
  31662. int ret;
  31663. int res = 0;
  31664. /* Initialize key for use. */
  31665. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31666. if (ret != 0) {
  31667. return WC_TEST_RET_ENC_NC;
  31668. }
  31669. /* Load bad public key only and perform checks. */
  31670. ret = wc_ed25519_import_public(key_bad_y, ED25519_PUB_KEY_SIZE + 1, &key);
  31671. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31672. res = WC_TEST_RET_ENC_NC;
  31673. }
  31674. if (res == 0) {
  31675. /* Load bad public key only and perform checks. */
  31676. ret = wc_ed25519_import_public(key_bad_y_max, ED25519_PUB_KEY_SIZE + 1,
  31677. &key);
  31678. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31679. res = WC_TEST_RET_ENC_NC;
  31680. }
  31681. }
  31682. if (res == 0) {
  31683. /* Load bad public key only and perform checks. */
  31684. ret = wc_ed25519_import_public(key_bad_y_is_p, ED25519_PUB_KEY_SIZE + 1,
  31685. &key);
  31686. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31687. res = WC_TEST_RET_ENC_NC;
  31688. }
  31689. }
  31690. if (res == 0) {
  31691. /* Load good public key only and perform checks. */
  31692. ret = wc_ed25519_import_public(key_y_is_p_minus_1,
  31693. ED25519_PUB_KEY_SIZE + 1, &key);
  31694. if (ret != 0) {
  31695. res = WC_TEST_RET_ENC_NC;
  31696. }
  31697. }
  31698. /* Dispose of key. */
  31699. wc_ed25519_free(&key);
  31700. return res;
  31701. }
  31702. #endif
  31703. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31704. defined(HAVE_ED25519_KEY_IMPORT)
  31705. static wc_test_ret_t ed25519ctx_test(void)
  31706. {
  31707. wc_test_ret_t ret;
  31708. byte out[ED25519_SIG_SIZE];
  31709. word32 outlen;
  31710. #ifdef HAVE_ED25519_VERIFY
  31711. int verify = 0;
  31712. #endif /* HAVE_ED25519_VERIFY */
  31713. ed25519_key key;
  31714. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  31715. 0x03,0x05,0x33,0x4e,0x38,0x1a,0xf7,0x8f,
  31716. 0x14,0x1c,0xb6,0x66,0xf6,0x19,0x9f,0x57,
  31717. 0xbc,0x34,0x95,0x33,0x5a,0x25,0x6a,0x95,
  31718. 0xbd,0x2a,0x55,0xbf,0x54,0x66,0x63,0xf6
  31719. };
  31720. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  31721. 0xdf,0xc9,0x42,0x5e,0x4f,0x96,0x8f,0x7f,
  31722. 0x0c,0x29,0xf0,0x25,0x9c,0xf5,0xf9,0xae,
  31723. 0xd6,0x85,0x1c,0x2b,0xb4,0xad,0x8b,0xfb,
  31724. 0x86,0x0c,0xfe,0xe0,0xab,0x24,0x82,0x92
  31725. };
  31726. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx1[] = {
  31727. 0x55,0xa4,0xcc,0x2f,0x70,0xa5,0x4e,0x04,
  31728. 0x28,0x8c,0x5f,0x4c,0xd1,0xe4,0x5a,0x7b,
  31729. 0xb5,0x20,0xb3,0x62,0x92,0x91,0x18,0x76,
  31730. 0xca,0xda,0x73,0x23,0x19,0x8d,0xd8,0x7a,
  31731. 0x8b,0x36,0x95,0x0b,0x95,0x13,0x00,0x22,
  31732. 0x90,0x7a,0x7f,0xb7,0xc4,0xe9,0xb2,0xd5,
  31733. 0xf6,0xcc,0xa6,0x85,0xa5,0x87,0xb4,0xb2,
  31734. 0x1f,0x4b,0x88,0x8e,0x4e,0x7e,0xdb,0x0d
  31735. };
  31736. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx2[] = {
  31737. 0xcc,0x5e,0x63,0xa2,0x7e,0x94,0xaf,0xd3,
  31738. 0x41,0x83,0x38,0xd2,0x48,0x6f,0xa9,0x2a,
  31739. 0xf9,0x91,0x7c,0x2d,0x98,0x9e,0x06,0xe5,
  31740. 0x02,0x77,0x72,0x1c,0x34,0x38,0x18,0xb4,
  31741. 0x21,0x96,0xbc,0x29,0x2e,0x68,0xf3,0x4d,
  31742. 0x85,0x9b,0xbe,0xad,0x17,0x9f,0x54,0x54,
  31743. 0x2d,0x4b,0x04,0xdc,0xfb,0xfa,0x4a,0x68,
  31744. 0x4e,0x39,0x50,0xfb,0x1c,0xcd,0x8d,0x0d
  31745. };
  31746. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  31747. 0xf7,0x26,0x93,0x6d,0x19,0xc8,0x00,0x49,
  31748. 0x4e,0x3f,0xda,0xff,0x20,0xb2,0x76,0xa8
  31749. };
  31750. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  31751. 0x66,0x6f,0x6f
  31752. };
  31753. outlen = sizeof(out);
  31754. XMEMSET(out, 0, sizeof(out));
  31755. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31756. if (ret != 0)
  31757. return 10800;
  31758. ret = wc_ed25519_import_private_key(sKeyCtx, ED25519_KEY_SIZE, pKeyCtx,
  31759. sizeof(pKeyCtx), &key);
  31760. if (ret == 0)
  31761. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31762. contextCtx, sizeof(contextCtx));
  31763. if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0)
  31764. ret = WC_TEST_RET_ENC_NC;
  31765. #if defined(HAVE_ED25519_VERIFY)
  31766. /* test verify on good msg */
  31767. if (ret == 0)
  31768. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31769. &verify, &key, contextCtx, sizeof(contextCtx));
  31770. if (ret == 0 && verify != 1)
  31771. ret = WC_TEST_RET_ENC_NC;
  31772. #endif
  31773. if (ret == 0)
  31774. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31775. NULL, 0);
  31776. if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0)
  31777. ret = WC_TEST_RET_ENC_NC;
  31778. #if defined(HAVE_ED25519_VERIFY)
  31779. /* test verify on good msg */
  31780. if (ret == 0)
  31781. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31782. &verify, &key, NULL, 0);
  31783. if (ret == 0 && verify != 1)
  31784. ret = WC_TEST_RET_ENC_NC;
  31785. #endif
  31786. wc_ed25519_free(&key);
  31787. return ret;
  31788. }
  31789. static wc_test_ret_t ed25519ph_test(void)
  31790. {
  31791. wc_test_ret_t ret = 0;
  31792. byte out[ED25519_SIG_SIZE];
  31793. word32 outlen;
  31794. #ifdef HAVE_ED25519_VERIFY
  31795. int verify = 0;
  31796. #endif /* HAVE_ED25519_VERIFY */
  31797. ed25519_key key;
  31798. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  31799. 0x83,0x3f,0xe6,0x24,0x09,0x23,0x7b,0x9d,
  31800. 0x62,0xec,0x77,0x58,0x75,0x20,0x91,0x1e,
  31801. 0x9a,0x75,0x9c,0xec,0x1d,0x19,0x75,0x5b,
  31802. 0x7d,0xa9,0x01,0xb9,0x6d,0xca,0x3d,0x42
  31803. };
  31804. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  31805. 0xec,0x17,0x2b,0x93,0xad,0x5e,0x56,0x3b,
  31806. 0xf4,0x93,0x2c,0x70,0xe1,0x24,0x50,0x34,
  31807. 0xc3,0x54,0x67,0xef,0x2e,0xfd,0x4d,0x64,
  31808. 0xeb,0xf8,0x19,0x68,0x34,0x67,0xe2,0xbf
  31809. };
  31810. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  31811. 0x98,0xa7,0x02,0x22,0xf0,0xb8,0x12,0x1a,
  31812. 0xa9,0xd3,0x0f,0x81,0x3d,0x68,0x3f,0x80,
  31813. 0x9e,0x46,0x2b,0x46,0x9c,0x7f,0xf8,0x76,
  31814. 0x39,0x49,0x9b,0xb9,0x4e,0x6d,0xae,0x41,
  31815. 0x31,0xf8,0x50,0x42,0x46,0x3c,0x2a,0x35,
  31816. 0x5a,0x20,0x03,0xd0,0x62,0xad,0xf5,0xaa,
  31817. 0xa1,0x0b,0x8c,0x61,0xe6,0x36,0x06,0x2a,
  31818. 0xaa,0xd1,0x1c,0x2a,0x26,0x08,0x34,0x06
  31819. };
  31820. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  31821. 0xe0,0x39,0x70,0x2b,0x4c,0x25,0x95,0xa6,
  31822. 0xa5,0x41,0xac,0x85,0x09,0x23,0x6e,0x29,
  31823. 0x90,0x47,0x47,0x95,0x33,0x0c,0x9b,0x34,
  31824. 0xa7,0x5f,0x58,0xa6,0x60,0x12,0x9e,0x08,
  31825. 0xfd,0x73,0x69,0x43,0xfb,0x19,0x43,0xa5,
  31826. 0x57,0x20,0xb9,0xe0,0x95,0x7b,0x1e,0xd6,
  31827. 0x73,0x48,0x16,0x61,0x9f,0x13,0x88,0xf4,
  31828. 0x3f,0x73,0xe6,0xe3,0xba,0xa8,0x1c,0x0e
  31829. };
  31830. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  31831. 0x61,0x62,0x63
  31832. };
  31833. /* SHA-512 hash of msgPh */
  31834. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  31835. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  31836. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  31837. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  31838. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  31839. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  31840. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  31841. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  31842. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f
  31843. };
  31844. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  31845. 0x66,0x6f,0x6f
  31846. };
  31847. outlen = sizeof(out);
  31848. XMEMSET(out, 0, sizeof(out));
  31849. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31850. if (ret != 0)
  31851. return WC_TEST_RET_ENC_EC(ret);
  31852. ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh,
  31853. sizeof(pKeyPh), &key);
  31854. if (ret == 0)
  31855. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31856. NULL, 0);
  31857. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31858. ret = WC_TEST_RET_ENC_NC;
  31859. #if defined(HAVE_ED25519_VERIFY)
  31860. /* test verify on good msg */
  31861. if (ret == 0)
  31862. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh),
  31863. &verify, &key, NULL, 0);
  31864. if (ret == 0 && verify != 1)
  31865. ret = WC_TEST_RET_ENC_NC;
  31866. #endif
  31867. if (ret == 0)
  31868. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31869. contextPh2, sizeof(contextPh2));
  31870. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31871. ret = WC_TEST_RET_ENC_NC;
  31872. #if defined(HAVE_ED25519_VERIFY)
  31873. /* test verify on good msg */
  31874. if (ret == 0)
  31875. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify,
  31876. &key, contextPh2, sizeof(contextPh2));
  31877. if (ret == 0 && verify != 1)
  31878. ret = WC_TEST_RET_ENC_NC;
  31879. #endif
  31880. if (ret == 0)
  31881. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31882. NULL, 0);
  31883. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31884. ret = WC_TEST_RET_ENC_NC;
  31885. #if defined(HAVE_ED25519_VERIFY)
  31886. if (ret == 0)
  31887. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh),
  31888. &verify, &key, NULL, 0);
  31889. if (ret == 0 && verify != 1)
  31890. ret = WC_TEST_RET_ENC_NC;
  31891. #endif
  31892. if (ret == 0)
  31893. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31894. contextPh2, sizeof(contextPh2));
  31895. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31896. ret = WC_TEST_RET_ENC_NC;
  31897. #if defined(HAVE_ED25519_VERIFY)
  31898. if (ret == 0)
  31899. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  31900. &key, contextPh2, sizeof(contextPh2));
  31901. if (ret == 0 && verify != 1)
  31902. ret = WC_TEST_RET_ENC_NC;
  31903. #endif
  31904. wc_ed25519_free(&key);
  31905. return ret;
  31906. }
  31907. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31908. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
  31909. {
  31910. wc_test_ret_t ret;
  31911. WC_RNG rng;
  31912. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31913. defined(HAVE_ED25519_KEY_IMPORT)
  31914. byte out[ED25519_SIG_SIZE];
  31915. byte exportPKey[ED25519_KEY_SIZE];
  31916. byte exportSKey[ED25519_KEY_SIZE];
  31917. word32 exportPSz;
  31918. word32 exportSSz;
  31919. int i;
  31920. word32 outlen;
  31921. #ifdef HAVE_ED25519_VERIFY
  31922. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  31923. int j;
  31924. #endif
  31925. int verify;
  31926. #endif /* HAVE_ED25519_VERIFY */
  31927. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31928. word32 keySz, sigSz;
  31929. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31930. ed25519_key* key = NULL;
  31931. ed25519_key* key2 = NULL;
  31932. #else
  31933. ed25519_key key[1];
  31934. ed25519_key key2[1];
  31935. #endif
  31936. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31937. defined(HAVE_ED25519_KEY_IMPORT)
  31938. /* test vectors from
  31939. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02
  31940. */
  31941. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  31942. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31943. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31944. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31945. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31946. };
  31947. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  31948. 0x4c,0xcd,0x08,0x9b,0x28,0xff,0x96,0xda,
  31949. 0x9d,0xb6,0xc3,0x46,0xec,0x11,0x4e,0x0f,
  31950. 0x5b,0x8a,0x31,0x9f,0x35,0xab,0xa6,0x24,
  31951. 0xda,0x8c,0xf6,0xed,0x4f,0xb8,0xa6,0xfb
  31952. };
  31953. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  31954. 0xc5,0xaa,0x8d,0xf4,0x3f,0x9f,0x83,0x7b,
  31955. 0xed,0xb7,0x44,0x2f,0x31,0xdc,0xb7,0xb1,
  31956. 0x66,0xd3,0x85,0x35,0x07,0x6f,0x09,0x4b,
  31957. 0x85,0xce,0x3a,0x2e,0x0b,0x44,0x58,0xf7
  31958. };
  31959. /* uncompressed test */
  31960. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  31961. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31962. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31963. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31964. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31965. };
  31966. /* compressed prefix test */
  31967. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  31968. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31969. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31970. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31971. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31972. };
  31973. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  31974. 0xf5,0xe5,0x76,0x7c,0xf1,0x53,0x31,0x95,
  31975. 0x17,0x63,0x0f,0x22,0x68,0x76,0xb8,0x6c,
  31976. 0x81,0x60,0xcc,0x58,0x3b,0xc0,0x13,0x74,
  31977. 0x4c,0x6b,0xf2,0x55,0xf5,0xcc,0x0e,0xe5
  31978. };
  31979. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  31980. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  31981. 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31982. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31983. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31984. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31985. };
  31986. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  31987. 0x3d,0x40,0x17,0xc3,0xe8,0x43,0x89,0x5a,
  31988. 0x92,0xb7,0x0a,0xa7,0x4d,0x1b,0x7e,0xbc,
  31989. 0x9c,0x98,0x2c,0xcf,0x2e,0xc4,0x96,0x8c,
  31990. 0xc0,0xcd,0x55,0xf1,0x2a,0xf4,0x66,0x0c
  31991. };
  31992. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  31993. 0xfc,0x51,0xcd,0x8e,0x62,0x18,0xa1,0xa3,
  31994. 0x8d,0xa4,0x7e,0xd0,0x02,0x30,0xf0,0x58,
  31995. 0x08,0x16,0xed,0x13,0xba,0x33,0x03,0xac,
  31996. 0x5d,0xeb,0x91,0x15,0x48,0x90,0x80,0x25
  31997. };
  31998. /* uncompressed test */
  31999. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  32000. 0x04,0x55,0xd0,0xe0,0x9a,0x2b,0x9d,0x34,
  32001. 0x29,0x22,0x97,0xe0,0x8d,0x60,0xd0,0xf6,
  32002. 0x20,0xc5,0x13,0xd4,0x72,0x53,0x18,0x7c,
  32003. 0x24,0xb1,0x27,0x86,0xbd,0x77,0x76,0x45,
  32004. 0xce,0x1a,0x51,0x07,0xf7,0x68,0x1a,0x02,
  32005. 0xaf,0x25,0x23,0xa6,0xda,0xf3,0x72,0xe1,
  32006. 0x0e,0x3a,0x07,0x64,0xc9,0xd3,0xfe,0x4b,
  32007. 0xd5,0xb7,0x0a,0xb1,0x82,0x01,0x98,0x5a,
  32008. 0xd7
  32009. };
  32010. /* compressed prefix */
  32011. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  32012. 0x40,0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  32013. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  32014. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  32015. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  32016. };
  32017. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  32018. 0x27,0x81,0x17,0xfc,0x14,0x4c,0x72,0x34,
  32019. 0x0f,0x67,0xd0,0xf2,0x31,0x6e,0x83,0x86,
  32020. 0xce,0xff,0xbf,0x2b,0x24,0x28,0xc9,0xc5,
  32021. 0x1f,0xef,0x7c,0x59,0x7f,0x1d,0x42,0x6e
  32022. };
  32023. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  32024. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  32025. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  32026. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  32027. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32028. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32029. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32030. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32031. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32032. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32033. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32034. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32035. };
  32036. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  32037. 0x92,0xa0,0x09,0xa9,0xf0,0xd4,0xca,0xb8,
  32038. 0x72,0x0e,0x82,0x0b,0x5f,0x64,0x25,0x40,
  32039. 0xa2,0xb2,0x7b,0x54,0x16,0x50,0x3f,0x8f,
  32040. 0xb3,0x76,0x22,0x23,0xeb,0xdb,0x69,0xda,
  32041. 0x08,0x5a,0xc1,0xe4,0x3e,0x15,0x99,0x6e,
  32042. 0x45,0x8f,0x36,0x13,0xd0,0xf1,0x1d,0x8c,
  32043. 0x38,0x7b,0x2e,0xae,0xb4,0x30,0x2a,0xee,
  32044. 0xb0,0x0d,0x29,0x16,0x12,0xbb,0x0c,0x00
  32045. };
  32046. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  32047. 0x62,0x91,0xd6,0x57,0xde,0xec,0x24,0x02,
  32048. 0x48,0x27,0xe6,0x9c,0x3a,0xbe,0x01,0xa3,
  32049. 0x0c,0xe5,0x48,0xa2,0x84,0x74,0x3a,0x44,
  32050. 0x5e,0x36,0x80,0xd7,0xdb,0x5a,0xc3,0xac,
  32051. 0x18,0xff,0x9b,0x53,0x8d,0x16,0xf2,0x90,
  32052. 0xae,0x67,0xf7,0x60,0x98,0x4d,0xc6,0x59,
  32053. 0x4a,0x7c,0x15,0xe9,0x71,0x6e,0xd2,0x8d,
  32054. 0xc0,0x27,0xbe,0xce,0xea,0x1e,0xc4,0x0a
  32055. };
  32056. /* uncompressed test */
  32057. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  32058. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32059. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32060. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32061. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32062. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32063. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32064. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32065. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32066. };
  32067. /* compressed prefix */
  32068. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  32069. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32070. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32071. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32072. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32073. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32074. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32075. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32076. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32077. };
  32078. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  32079. 0x0a,0xab,0x4c,0x90,0x05,0x01,0xb3,0xe2,
  32080. 0x4d,0x7c,0xdf,0x46,0x63,0x32,0x6a,0x3a,
  32081. 0x87,0xdf,0x5e,0x48,0x43,0xb2,0xcb,0xdb,
  32082. 0x67,0xcb,0xf6,0xe4,0x60,0xfe,0xc3,0x50,
  32083. 0xaa,0x53,0x71,0xb1,0x50,0x8f,0x9f,0x45,
  32084. 0x28,0xec,0xea,0x23,0xc4,0x36,0xd9,0x4b,
  32085. 0x5e,0x8f,0xcd,0x4f,0x68,0x1e,0x30,0xa6,
  32086. 0xac,0x00,0xa9,0x70,0x4a,0x18,0x8a,0x03
  32087. };
  32088. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  32089. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {0x0 };
  32090. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {0x72};
  32091. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {0xAF,0x82};
  32092. /* test of a 1024 byte long message */
  32093. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  32094. 0x08,0xb8,0xb2,0xb7,0x33,0x42,0x42,0x43,
  32095. 0x76,0x0f,0xe4,0x26,0xa4,0xb5,0x49,0x08,
  32096. 0x63,0x21,0x10,0xa6,0x6c,0x2f,0x65,0x91,
  32097. 0xea,0xbd,0x33,0x45,0xe3,0xe4,0xeb,0x98,
  32098. 0xfa,0x6e,0x26,0x4b,0xf0,0x9e,0xfe,0x12,
  32099. 0xee,0x50,0xf8,0xf5,0x4e,0x9f,0x77,0xb1,
  32100. 0xe3,0x55,0xf6,0xc5,0x05,0x44,0xe2,0x3f,
  32101. 0xb1,0x43,0x3d,0xdf,0x73,0xbe,0x84,0xd8,
  32102. 0x79,0xde,0x7c,0x00,0x46,0xdc,0x49,0x96,
  32103. 0xd9,0xe7,0x73,0xf4,0xbc,0x9e,0xfe,0x57,
  32104. 0x38,0x82,0x9a,0xdb,0x26,0xc8,0x1b,0x37,
  32105. 0xc9,0x3a,0x1b,0x27,0x0b,0x20,0x32,0x9d,
  32106. 0x65,0x86,0x75,0xfc,0x6e,0xa5,0x34,0xe0,
  32107. 0x81,0x0a,0x44,0x32,0x82,0x6b,0xf5,0x8c,
  32108. 0x94,0x1e,0xfb,0x65,0xd5,0x7a,0x33,0x8b,
  32109. 0xbd,0x2e,0x26,0x64,0x0f,0x89,0xff,0xbc,
  32110. 0x1a,0x85,0x8e,0xfc,0xb8,0x55,0x0e,0xe3,
  32111. 0xa5,0xe1,0x99,0x8b,0xd1,0x77,0xe9,0x3a,
  32112. 0x73,0x63,0xc3,0x44,0xfe,0x6b,0x19,0x9e,
  32113. 0xe5,0xd0,0x2e,0x82,0xd5,0x22,0xc4,0xfe,
  32114. 0xba,0x15,0x45,0x2f,0x80,0x28,0x8a,0x82,
  32115. 0x1a,0x57,0x91,0x16,0xec,0x6d,0xad,0x2b,
  32116. 0x3b,0x31,0x0d,0xa9,0x03,0x40,0x1a,0xa6,
  32117. 0x21,0x00,0xab,0x5d,0x1a,0x36,0x55,0x3e,
  32118. 0x06,0x20,0x3b,0x33,0x89,0x0c,0xc9,0xb8,
  32119. 0x32,0xf7,0x9e,0xf8,0x05,0x60,0xcc,0xb9,
  32120. 0xa3,0x9c,0xe7,0x67,0x96,0x7e,0xd6,0x28,
  32121. 0xc6,0xad,0x57,0x3c,0xb1,0x16,0xdb,0xef,
  32122. 0xef,0xd7,0x54,0x99,0xda,0x96,0xbd,0x68,
  32123. 0xa8,0xa9,0x7b,0x92,0x8a,0x8b,0xbc,0x10,
  32124. 0x3b,0x66,0x21,0xfc,0xde,0x2b,0xec,0xa1,
  32125. 0x23,0x1d,0x20,0x6b,0xe6,0xcd,0x9e,0xc7,
  32126. 0xaf,0xf6,0xf6,0xc9,0x4f,0xcd,0x72,0x04,
  32127. 0xed,0x34,0x55,0xc6,0x8c,0x83,0xf4,0xa4,
  32128. 0x1d,0xa4,0xaf,0x2b,0x74,0xef,0x5c,0x53,
  32129. 0xf1,0xd8,0xac,0x70,0xbd,0xcb,0x7e,0xd1,
  32130. 0x85,0xce,0x81,0xbd,0x84,0x35,0x9d,0x44,
  32131. 0x25,0x4d,0x95,0x62,0x9e,0x98,0x55,0xa9,
  32132. 0x4a,0x7c,0x19,0x58,0xd1,0xf8,0xad,0xa5,
  32133. 0xd0,0x53,0x2e,0xd8,0xa5,0xaa,0x3f,0xb2,
  32134. 0xd1,0x7b,0xa7,0x0e,0xb6,0x24,0x8e,0x59,
  32135. 0x4e,0x1a,0x22,0x97,0xac,0xbb,0xb3,0x9d,
  32136. 0x50,0x2f,0x1a,0x8c,0x6e,0xb6,0xf1,0xce,
  32137. 0x22,0xb3,0xde,0x1a,0x1f,0x40,0xcc,0x24,
  32138. 0x55,0x41,0x19,0xa8,0x31,0xa9,0xaa,0xd6,
  32139. 0x07,0x9c,0xad,0x88,0x42,0x5d,0xe6,0xbd,
  32140. 0xe1,0xa9,0x18,0x7e,0xbb,0x60,0x92,0xcf,
  32141. 0x67,0xbf,0x2b,0x13,0xfd,0x65,0xf2,0x70,
  32142. 0x88,0xd7,0x8b,0x7e,0x88,0x3c,0x87,0x59,
  32143. 0xd2,0xc4,0xf5,0xc6,0x5a,0xdb,0x75,0x53,
  32144. 0x87,0x8a,0xd5,0x75,0xf9,0xfa,0xd8,0x78,
  32145. 0xe8,0x0a,0x0c,0x9b,0xa6,0x3b,0xcb,0xcc,
  32146. 0x27,0x32,0xe6,0x94,0x85,0xbb,0xc9,0xc9,
  32147. 0x0b,0xfb,0xd6,0x24,0x81,0xd9,0x08,0x9b,
  32148. 0xec,0xcf,0x80,0xcf,0xe2,0xdf,0x16,0xa2,
  32149. 0xcf,0x65,0xbd,0x92,0xdd,0x59,0x7b,0x07,
  32150. 0x07,0xe0,0x91,0x7a,0xf4,0x8b,0xbb,0x75,
  32151. 0xfe,0xd4,0x13,0xd2,0x38,0xf5,0x55,0x5a,
  32152. 0x7a,0x56,0x9d,0x80,0xc3,0x41,0x4a,0x8d,
  32153. 0x08,0x59,0xdc,0x65,0xa4,0x61,0x28,0xba,
  32154. 0xb2,0x7a,0xf8,0x7a,0x71,0x31,0x4f,0x31,
  32155. 0x8c,0x78,0x2b,0x23,0xeb,0xfe,0x80,0x8b,
  32156. 0x82,0xb0,0xce,0x26,0x40,0x1d,0x2e,0x22,
  32157. 0xf0,0x4d,0x83,0xd1,0x25,0x5d,0xc5,0x1a,
  32158. 0xdd,0xd3,0xb7,0x5a,0x2b,0x1a,0xe0,0x78,
  32159. 0x45,0x04,0xdf,0x54,0x3a,0xf8,0x96,0x9b,
  32160. 0xe3,0xea,0x70,0x82,0xff,0x7f,0xc9,0x88,
  32161. 0x8c,0x14,0x4d,0xa2,0xaf,0x58,0x42,0x9e,
  32162. 0xc9,0x60,0x31,0xdb,0xca,0xd3,0xda,0xd9,
  32163. 0xaf,0x0d,0xcb,0xaa,0xaf,0x26,0x8c,0xb8,
  32164. 0xfc,0xff,0xea,0xd9,0x4f,0x3c,0x7c,0xa4,
  32165. 0x95,0xe0,0x56,0xa9,0xb4,0x7a,0xcd,0xb7,
  32166. 0x51,0xfb,0x73,0xe6,0x66,0xc6,0xc6,0x55,
  32167. 0xad,0xe8,0x29,0x72,0x97,0xd0,0x7a,0xd1,
  32168. 0xba,0x5e,0x43,0xf1,0xbc,0xa3,0x23,0x01,
  32169. 0x65,0x13,0x39,0xe2,0x29,0x04,0xcc,0x8c,
  32170. 0x42,0xf5,0x8c,0x30,0xc0,0x4a,0xaf,0xdb,
  32171. 0x03,0x8d,0xda,0x08,0x47,0xdd,0x98,0x8d,
  32172. 0xcd,0xa6,0xf3,0xbf,0xd1,0x5c,0x4b,0x4c,
  32173. 0x45,0x25,0x00,0x4a,0xa0,0x6e,0xef,0xf8,
  32174. 0xca,0x61,0x78,0x3a,0xac,0xec,0x57,0xfb,
  32175. 0x3d,0x1f,0x92,0xb0,0xfe,0x2f,0xd1,0xa8,
  32176. 0x5f,0x67,0x24,0x51,0x7b,0x65,0xe6,0x14,
  32177. 0xad,0x68,0x08,0xd6,0xf6,0xee,0x34,0xdf,
  32178. 0xf7,0x31,0x0f,0xdc,0x82,0xae,0xbf,0xd9,
  32179. 0x04,0xb0,0x1e,0x1d,0xc5,0x4b,0x29,0x27,
  32180. 0x09,0x4b,0x2d,0xb6,0x8d,0x6f,0x90,0x3b,
  32181. 0x68,0x40,0x1a,0xde,0xbf,0x5a,0x7e,0x08,
  32182. 0xd7,0x8f,0xf4,0xef,0x5d,0x63,0x65,0x3a,
  32183. 0x65,0x04,0x0c,0xf9,0xbf,0xd4,0xac,0xa7,
  32184. 0x98,0x4a,0x74,0xd3,0x71,0x45,0x98,0x67,
  32185. 0x80,0xfc,0x0b,0x16,0xac,0x45,0x16,0x49,
  32186. 0xde,0x61,0x88,0xa7,0xdb,0xdf,0x19,0x1f,
  32187. 0x64,0xb5,0xfc,0x5e,0x2a,0xb4,0x7b,0x57,
  32188. 0xf7,0xf7,0x27,0x6c,0xd4,0x19,0xc1,0x7a,
  32189. 0x3c,0xa8,0xe1,0xb9,0x39,0xae,0x49,0xe4,
  32190. 0x88,0xac,0xba,0x6b,0x96,0x56,0x10,0xb5,
  32191. 0x48,0x01,0x09,0xc8,0xb1,0x7b,0x80,0xe1,
  32192. 0xb7,0xb7,0x50,0xdf,0xc7,0x59,0x8d,0x5d,
  32193. 0x50,0x11,0xfd,0x2d,0xcc,0x56,0x00,0xa3,
  32194. 0x2e,0xf5,0xb5,0x2a,0x1e,0xcc,0x82,0x0e,
  32195. 0x30,0x8a,0xa3,0x42,0x72,0x1a,0xac,0x09,
  32196. 0x43,0xbf,0x66,0x86,0xb6,0x4b,0x25,0x79,
  32197. 0x37,0x65,0x04,0xcc,0xc4,0x93,0xd9,0x7e,
  32198. 0x6a,0xed,0x3f,0xb0,0xf9,0xcd,0x71,0xa4,
  32199. 0x3d,0xd4,0x97,0xf0,0x1f,0x17,0xc0,0xe2,
  32200. 0xcb,0x37,0x97,0xaa,0x2a,0x2f,0x25,0x66,
  32201. 0x56,0x16,0x8e,0x6c,0x49,0x6a,0xfc,0x5f,
  32202. 0xb9,0x32,0x46,0xf6,0xb1,0x11,0x63,0x98,
  32203. 0xa3,0x46,0xf1,0xa6,0x41,0xf3,0xb0,0x41,
  32204. 0xe9,0x89,0xf7,0x91,0x4f,0x90,0xcc,0x2c,
  32205. 0x7f,0xff,0x35,0x78,0x76,0xe5,0x06,0xb5,
  32206. 0x0d,0x33,0x4b,0xa7,0x7c,0x22,0x5b,0xc3,
  32207. 0x07,0xba,0x53,0x71,0x52,0xf3,0xf1,0x61,
  32208. 0x0e,0x4e,0xaf,0xe5,0x95,0xf6,0xd9,0xd9,
  32209. 0x0d,0x11,0xfa,0xa9,0x33,0xa1,0x5e,0xf1,
  32210. 0x36,0x95,0x46,0x86,0x8a,0x7f,0x3a,0x45,
  32211. 0xa9,0x67,0x68,0xd4,0x0f,0xd9,0xd0,0x34,
  32212. 0x12,0xc0,0x91,0xc6,0x31,0x5c,0xf4,0xfd,
  32213. 0xe7,0xcb,0x68,0x60,0x69,0x37,0x38,0x0d,
  32214. 0xb2,0xea,0xaa,0x70,0x7b,0x4c,0x41,0x85,
  32215. 0xc3,0x2e,0xdd,0xcd,0xd3,0x06,0x70,0x5e,
  32216. 0x4d,0xc1,0xff,0xc8,0x72,0xee,0xee,0x47,
  32217. 0x5a,0x64,0xdf,0xac,0x86,0xab,0xa4,0x1c,
  32218. 0x06,0x18,0x98,0x3f,0x87,0x41,0xc5,0xef,
  32219. 0x68,0xd3,0xa1,0x01,0xe8,0xa3,0xb8,0xca,
  32220. 0xc6,0x0c,0x90,0x5c,0x15,0xfc,0x91,0x08,
  32221. 0x40,0xb9,0x4c,0x00,0xa0,0xb9,0xd0
  32222. };
  32223. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  32224. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  32225. sizeof(msg2),
  32226. sizeof(msg3),
  32227. 0 /*sizeof(msg1)*/,
  32228. 0 /*sizeof(msg1)*/,
  32229. sizeof(msg4)
  32230. };
  32231. #ifndef NO_ASN
  32232. static const byte privateEd25519[] = {
  32233. 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
  32234. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32235. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32236. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32237. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32238. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  32239. };
  32240. static const byte badPrivateEd25519[] = {
  32241. 0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
  32242. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32243. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32244. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32245. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32246. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32247. 0xa1,0x22,0x04,0x21,0xd7,0x5a,0x98,0x01, /* octet len 0x20 -> 0x21 */
  32248. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32249. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32250. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32251. 0xf7,0x07,0x51,0x1a,
  32252. 0x00 /* add additional bytes to make the pubkey bigger */
  32253. };
  32254. static const byte publicEd25519[] = {
  32255. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32256. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32257. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32258. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32259. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32260. 0xf7,0x07,0x51,0x1a
  32261. };
  32262. /* size has been altered to catch if sanity check is done */
  32263. static const byte badPublicEd25519[] = {
  32264. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32265. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32266. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32267. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32268. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32269. 0xf7,0x07,0x51,0x1a,
  32270. 0x00 /* add an additional byte to make the pubkey appear bigger */
  32271. };
  32272. static const byte privPubEd25519[] = {
  32273. 0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
  32274. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32275. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32276. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32277. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32278. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32279. 0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
  32280. 0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
  32281. 0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
  32282. 0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
  32283. 0x51,0x1a
  32284. };
  32285. word32 idx;
  32286. #endif /* NO_ASN */
  32287. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32288. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32289. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32290. ed25519_key* key3 = NULL;
  32291. #else
  32292. ed25519_key key3[1];
  32293. #endif
  32294. #endif
  32295. WOLFSSL_ENTER("ed25519_test");
  32296. /* create ed25519 keys */
  32297. #ifndef HAVE_FIPS
  32298. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32299. #else
  32300. ret = wc_InitRng(&rng);
  32301. #endif
  32302. if (ret != 0)
  32303. return WC_TEST_RET_ENC_EC(ret);
  32304. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32305. key = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32306. if (ret != 0)
  32307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32308. key2 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32309. if (ret != 0)
  32310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32311. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32312. key3 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32313. if (ret != 0)
  32314. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32315. #endif
  32316. #else
  32317. wc_ed25519_init_ex(key, HEAP_HINT, devId);
  32318. wc_ed25519_init_ex(key2, HEAP_HINT, devId);
  32319. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32320. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32321. #endif
  32322. #endif
  32323. #ifdef HAVE_ED25519_MAKE_KEY
  32324. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
  32325. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key2);
  32326. #endif
  32327. /* helper functions for signature and key size */
  32328. keySz = (word32)wc_ed25519_size(key);
  32329. sigSz = (word32)wc_ed25519_sig_size(key);
  32330. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  32331. defined(HAVE_ED25519_KEY_IMPORT)
  32332. for (i = 0; i < 6; i++) {
  32333. outlen = sizeof(out);
  32334. XMEMSET(out, 0, sizeof(out));
  32335. if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i],
  32336. pKeySz[i], key) != 0)
  32337. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32338. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key) != 0)
  32339. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32340. if (XMEMCMP(out, sigs[i], 64))
  32341. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32342. #if defined(HAVE_ED25519_VERIFY)
  32343. /* test verify on good msg */
  32344. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32345. key) != 0 || verify != 1)
  32346. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32347. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  32348. /* test verify on good msg using streaming interface directly */
  32349. if (wc_ed25519_verify_msg_init(out, outlen,
  32350. key, (byte)Ed25519, NULL, 0) != 0)
  32351. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32352. for (j = 0; j < msgSz[i]; j += i) {
  32353. if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  32354. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32355. }
  32356. if (wc_ed25519_verify_msg_final(out, outlen, &verify,
  32357. key) != 0 || verify != 1)
  32358. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32359. #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */
  32360. /* test verify on bad msg */
  32361. out[outlen-1] = out[outlen-1] + 1;
  32362. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32363. key) == 0 || verify == 1)
  32364. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32365. #endif /* HAVE_ED25519_VERIFY */
  32366. /* test api for import/exporting keys */
  32367. exportPSz = sizeof(exportPKey);
  32368. exportSSz = sizeof(exportSKey);
  32369. if (wc_ed25519_export_public(key, exportPKey, &exportPSz) != 0)
  32370. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32371. if (wc_ed25519_import_public_ex(exportPKey, exportPSz, key2, 1) != 0)
  32372. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32373. if (wc_ed25519_export_private_only(key, exportSKey, &exportSSz) != 0)
  32374. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32375. if (wc_ed25519_import_private_key(exportSKey, exportSSz,
  32376. exportPKey, exportPSz, key2) != 0)
  32377. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32378. /* clear "out" buffer and test sign with imported keys */
  32379. outlen = sizeof(out);
  32380. XMEMSET(out, 0, sizeof(out));
  32381. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key2) != 0)
  32382. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32383. #if defined(HAVE_ED25519_VERIFY)
  32384. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32385. key2) != 0 || verify != 1)
  32386. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32387. if (XMEMCMP(out, sigs[i], 64))
  32388. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32389. #endif /* HAVE_ED25519_VERIFY */
  32390. }
  32391. {
  32392. /* Run tests for some rare code paths */
  32393. /* sig is exactly equal to the order */
  32394. static const byte rareEd1[] = {
  32395. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32396. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32397. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32398. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32399. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32400. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32401. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32402. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32403. };
  32404. /* sig is larger than the order before we get to the low part */
  32405. static const byte rareEd2[] = {
  32406. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32407. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32408. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32409. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32410. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32411. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32412. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32413. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10
  32414. };
  32415. /* sig is larger than the order in the low part */
  32416. static const byte rareEd3[] = {
  32417. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32418. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32419. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32420. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32421. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32422. 0xd6, 0x9c, 0xf9, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32423. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32425. };
  32426. /* sig is smaller than the order */
  32427. static const byte rareEd4[] = {
  32428. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32429. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32430. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32431. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32432. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32433. 0xd6, 0x9c, 0xf1, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32434. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32435. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32436. };
  32437. ret = wc_ed25519_import_private_key(sKeys[0], ED25519_KEY_SIZE,
  32438. pKeys[0], pKeySz[0], key);
  32439. if (ret != 0)
  32440. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32441. ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
  32442. &verify, key);
  32443. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32445. ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), msgs[0], msgSz[0],
  32446. &verify, key);
  32447. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32449. ret = wc_ed25519_verify_msg(rareEd3, sizeof(rareEd3), msgs[0], msgSz[0],
  32450. &verify, key);
  32451. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32453. ret = wc_ed25519_verify_msg(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
  32454. &verify, key);
  32455. if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
  32456. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32457. }
  32458. ret = ed25519ctx_test();
  32459. if (ret != 0)
  32460. goto cleanup;
  32461. ret = ed25519ph_test();
  32462. if (ret != 0)
  32463. goto cleanup;
  32464. #ifndef NO_ASN
  32465. /* Try ASN.1 encoded private-only key and public key. */
  32466. idx = 0;
  32467. ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, key3,
  32468. sizeof(privateEd25519));
  32469. if (ret != 0)
  32470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32471. idx = 0;
  32472. if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, key3,
  32473. sizeof(badPrivateEd25519)) == 0)
  32474. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32475. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32476. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32477. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32478. /* try with a buffer size that is too large */
  32479. idx = 0;
  32480. if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, key3,
  32481. sizeof(badPublicEd25519)) == 0)
  32482. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32483. idx = 0;
  32484. ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, key3,
  32485. sizeof(publicEd25519));
  32486. if (ret != 0)
  32487. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32488. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32489. if (ret != 0)
  32490. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32491. if (XMEMCMP(out, sigs[0], 64))
  32492. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32493. #if defined(HAVE_ED25519_VERIFY)
  32494. /* test verify on good msg */
  32495. ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3);
  32496. if (ret != 0 || verify != 1)
  32497. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32498. #endif /* HAVE_ED25519_VERIFY */
  32499. wc_ed25519_free(key3);
  32500. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32501. idx = 0;
  32502. ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, key3,
  32503. sizeof(privPubEd25519));
  32504. if (ret != 0)
  32505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32506. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32507. if (ret != 0)
  32508. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32509. if (XMEMCMP(out, sigs[0], 64))
  32510. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32511. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32512. wc_ed25519_delete(key3, &key3);
  32513. #else
  32514. wc_ed25519_free(key3);
  32515. #endif
  32516. #endif /* NO_ASN */
  32517. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32518. ret = ed25519_test_check_key();
  32519. if (ret < 0)
  32520. goto cleanup;
  32521. #ifdef WOLFSSL_TEST_CERT
  32522. ret = ed25519_test_cert();
  32523. if (ret < 0)
  32524. goto cleanup;
  32525. #if defined(WOLFSSL_CERT_GEN) && defined(HAVE_ED25519_MAKE_KEY)
  32526. ret = ed25519_test_make_cert();
  32527. if (ret < 0)
  32528. goto cleanup;
  32529. #endif /* WOLFSSL_CERT_GEN */
  32530. #endif /* WOLFSSL_TEST_CERT */
  32531. cleanup:
  32532. /* clean up keys when done */
  32533. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32534. wc_ed25519_delete(key, &key);
  32535. wc_ed25519_delete(key2, &key2);
  32536. #else
  32537. wc_ed25519_free(key);
  32538. wc_ed25519_free(key2);
  32539. #endif
  32540. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  32541. wc_FreeRng(&rng);
  32542. #endif
  32543. /* hush warnings of unused keySz and sigSz */
  32544. (void)keySz;
  32545. (void)sigSz;
  32546. return ret;
  32547. }
  32548. #endif /* HAVE_ED25519 */
  32549. #ifdef HAVE_CURVE448
  32550. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32551. defined(HAVE_CURVE448_KEY_IMPORT)
  32552. /* Test the wc_curve448_check_public API.
  32553. *
  32554. * returns 0 on success and -ve on failure.
  32555. */
  32556. static wc_test_ret_t curve448_check_public_test(void)
  32557. {
  32558. /* Little-endian values that will fail */
  32559. byte fail_le[][CURVE448_KEY_SIZE] = {
  32560. {
  32561. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32562. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32563. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32564. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32565. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32566. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32567. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32568. },
  32569. {
  32570. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32571. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32572. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32573. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32574. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32575. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32577. },
  32578. };
  32579. /* Big-endian values that will fail */
  32580. byte fail_be[][CURVE448_KEY_SIZE] = {
  32581. {
  32582. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32583. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32584. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32585. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32586. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32587. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32588. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32589. },
  32590. {
  32591. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32592. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32593. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32594. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32595. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32596. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32597. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32598. },
  32599. };
  32600. /* Good or valid public value */
  32601. byte good[CURVE448_KEY_SIZE] = {
  32602. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32603. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32604. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32605. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32606. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32607. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32608. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32609. };
  32610. int i;
  32611. wc_test_ret_t ret;
  32612. /* Parameter checks */
  32613. /* NULL pointer */
  32614. ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN);
  32615. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32616. return WC_TEST_RET_ENC_EC(ret);
  32617. ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN);
  32618. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32619. return WC_TEST_RET_ENC_EC(ret);
  32620. /* Length of 0 treated differently to other invalid lengths for TLS */
  32621. ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN);
  32622. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32623. return WC_TEST_RET_ENC_EC(ret);
  32624. ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN);
  32625. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32626. return WC_TEST_RET_ENC_EC(ret);
  32627. /* Length not CURVE448_KEY_SIZE */
  32628. for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) {
  32629. if (i == CURVE448_KEY_SIZE)
  32630. continue;
  32631. if (wc_curve448_check_public(good, (word32)i, EC448_LITTLE_ENDIAN) !=
  32632. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32633. return WC_TEST_RET_ENC_I(i);
  32634. }
  32635. if (wc_curve448_check_public(good, (word32)i, EC448_BIG_ENDIAN) !=
  32636. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32637. return WC_TEST_RET_ENC_I(i);
  32638. }
  32639. }
  32640. /* Little-endian fail cases */
  32641. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  32642. if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE,
  32643. EC448_LITTLE_ENDIAN) == 0) {
  32644. return WC_TEST_RET_ENC_I(i);
  32645. }
  32646. }
  32647. /* Big-endian fail cases */
  32648. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  32649. if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE,
  32650. EC448_BIG_ENDIAN) == 0) {
  32651. return WC_TEST_RET_ENC_I(i);
  32652. }
  32653. }
  32654. /* Check a valid public value works! */
  32655. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE,
  32656. EC448_LITTLE_ENDIAN);
  32657. if (ret != 0)
  32658. return WC_TEST_RET_ENC_EC(ret);
  32659. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN);
  32660. if (ret != 0)
  32661. return WC_TEST_RET_ENC_EC(ret);
  32662. return 0;
  32663. }
  32664. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32665. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
  32666. {
  32667. WC_RNG rng;
  32668. wc_test_ret_t ret;
  32669. #ifdef HAVE_CURVE448_SHARED_SECRET
  32670. byte sharedA[CURVE448_KEY_SIZE];
  32671. byte sharedB[CURVE448_KEY_SIZE];
  32672. word32 y;
  32673. #endif
  32674. #ifdef HAVE_CURVE448_KEY_EXPORT
  32675. byte exportBuf[CURVE448_KEY_SIZE];
  32676. #endif
  32677. word32 x = 0;
  32678. curve448_key userA, userB, pubKey;
  32679. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32680. defined(HAVE_CURVE448_KEY_IMPORT)
  32681. /* test vectors from
  32682. https://www.rfc-editor.org/rfc/rfc7748.html
  32683. */
  32684. /* secret key for party a */
  32685. byte sa[] = {
  32686. 0x6b, 0x72, 0x98, 0xa5, 0xc0, 0xd8, 0xc2, 0x9a,
  32687. 0x1d, 0xab, 0x27, 0xf1, 0xa6, 0x82, 0x63, 0x00,
  32688. 0x91, 0x73, 0x89, 0x44, 0x97, 0x41, 0xa9, 0x74,
  32689. 0xf5, 0xba, 0xc9, 0xd9, 0x8d, 0xc2, 0x98, 0xd4,
  32690. 0x65, 0x55, 0xbc, 0xe8, 0xba, 0xe8, 0x9e, 0xee,
  32691. 0xd4, 0x00, 0x58, 0x4b, 0xb0, 0x46, 0xcf, 0x75,
  32692. 0x57, 0x9f, 0x51, 0xd1, 0x25, 0x49, 0x8f, 0x9a,
  32693. };
  32694. /* public key for party a */
  32695. byte pa[] = {
  32696. 0xa0, 0x1f, 0xc4, 0x32, 0xe5, 0x80, 0x7f, 0x17,
  32697. 0x53, 0x0d, 0x12, 0x88, 0xda, 0x12, 0x5b, 0x0c,
  32698. 0xd4, 0x53, 0xd9, 0x41, 0x72, 0x64, 0x36, 0xc8,
  32699. 0xbb, 0xd9, 0xc5, 0x22, 0x2c, 0x3d, 0xa7, 0xfa,
  32700. 0x63, 0x9c, 0xe0, 0x3d, 0xb8, 0xd2, 0x3b, 0x27,
  32701. 0x4a, 0x07, 0x21, 0xa1, 0xae, 0xd5, 0x22, 0x7d,
  32702. 0xe6, 0xe3, 0xb7, 0x31, 0xcc, 0xf7, 0x08, 0x9b,
  32703. };
  32704. /* secret key for party b */
  32705. byte sb[] = {
  32706. 0x2d, 0x99, 0x73, 0x51, 0xb6, 0x10, 0x6f, 0x36,
  32707. 0xb0, 0xd1, 0x09, 0x1b, 0x92, 0x9c, 0x4c, 0x37,
  32708. 0x21, 0x3e, 0x0d, 0x2b, 0x97, 0xe8, 0x5e, 0xbb,
  32709. 0x20, 0xc1, 0x27, 0x69, 0x1d, 0x0d, 0xad, 0x8f,
  32710. 0x1d, 0x81, 0x75, 0xb0, 0x72, 0x37, 0x45, 0xe6,
  32711. 0x39, 0xa3, 0xcb, 0x70, 0x44, 0x29, 0x0b, 0x99,
  32712. 0xe0, 0xe2, 0xa0, 0xc2, 0x7a, 0x6a, 0x30, 0x1c,
  32713. };
  32714. /* public key for party b */
  32715. byte pb[] = {
  32716. 0x09, 0x36, 0xf3, 0x7b, 0xc6, 0xc1, 0xbd, 0x07,
  32717. 0xae, 0x3d, 0xec, 0x7a, 0xb5, 0xdc, 0x06, 0xa7,
  32718. 0x3c, 0xa1, 0x32, 0x42, 0xfb, 0x34, 0x3e, 0xfc,
  32719. 0x72, 0xb9, 0xd8, 0x27, 0x30, 0xb4, 0x45, 0xf3,
  32720. 0xd4, 0xb0, 0xbd, 0x07, 0x71, 0x62, 0xa4, 0x6d,
  32721. 0xcf, 0xec, 0x6f, 0x9b, 0x59, 0x0b, 0xfc, 0xbc,
  32722. 0xf5, 0x20, 0xcd, 0xb0, 0x29, 0xa8, 0xb7, 0x3e,
  32723. };
  32724. /* expected shared key */
  32725. byte ss[] = {
  32726. 0x9d, 0x87, 0x4a, 0x51, 0x37, 0x50, 0x9a, 0x44,
  32727. 0x9a, 0xd5, 0x85, 0x30, 0x40, 0x24, 0x1c, 0x52,
  32728. 0x36, 0x39, 0x54, 0x35, 0xc3, 0x64, 0x24, 0xfd,
  32729. 0x56, 0x0b, 0x0c, 0xb6, 0x2b, 0x28, 0x1d, 0x28,
  32730. 0x52, 0x75, 0xa7, 0x40, 0xce, 0x32, 0xa2, 0x2d,
  32731. 0xd1, 0x74, 0x0f, 0x4a, 0xa9, 0x16, 0x1c, 0xec,
  32732. 0x95, 0xcc, 0xc6, 0x1a, 0x18, 0xf4, 0xff, 0x07,
  32733. };
  32734. #endif /* HAVE_CURVE448_SHARED_SECRET */
  32735. (void)x;
  32736. WOLFSSL_ENTER("curve448_test");
  32737. #ifndef HAVE_FIPS
  32738. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32739. #else
  32740. ret = wc_InitRng(&rng);
  32741. #endif
  32742. if (ret != 0)
  32743. return WC_TEST_RET_ENC_EC(ret);
  32744. wc_curve448_init(&userA);
  32745. wc_curve448_init(&userB);
  32746. wc_curve448_init(&pubKey);
  32747. /* make curve448 keys */
  32748. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA);
  32749. if (ret != 0)
  32750. return WC_TEST_RET_ENC_EC(ret);
  32751. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB);
  32752. if (ret != 0)
  32753. return WC_TEST_RET_ENC_EC(ret);
  32754. #ifdef HAVE_CURVE448_SHARED_SECRET
  32755. /* find shared secret key */
  32756. x = sizeof(sharedA);
  32757. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32758. if (ret != 0)
  32759. return WC_TEST_RET_ENC_EC(ret);
  32760. y = sizeof(sharedB);
  32761. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32762. if (ret != 0)
  32763. return WC_TEST_RET_ENC_EC(ret);
  32764. /* compare shared secret keys to test they are the same */
  32765. if (y != x)
  32766. return WC_TEST_RET_ENC_NC;
  32767. if (XMEMCMP(sharedA, sharedB, x))
  32768. return WC_TEST_RET_ENC_NC;
  32769. #endif
  32770. #ifdef HAVE_CURVE448_KEY_EXPORT
  32771. /* export a public key and import it for another user */
  32772. x = sizeof(exportBuf);
  32773. ret = wc_curve448_export_public(&userA, exportBuf, &x);
  32774. if (ret != 0)
  32775. return WC_TEST_RET_ENC_EC(ret);
  32776. #ifdef HAVE_CURVE448_KEY_IMPORT
  32777. ret = wc_curve448_import_public(exportBuf, x, &pubKey);
  32778. if (ret != 0)
  32779. return WC_TEST_RET_ENC_EC(ret);
  32780. #endif
  32781. #endif
  32782. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32783. defined(HAVE_CURVE448_KEY_IMPORT)
  32784. /* test shared key after importing a public key */
  32785. XMEMSET(sharedB, 0, sizeof(sharedB));
  32786. y = sizeof(sharedB);
  32787. ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y);
  32788. if (ret != 0)
  32789. return WC_TEST_RET_ENC_EC(ret);
  32790. if (XMEMCMP(sharedA, sharedB, y))
  32791. return WC_TEST_RET_ENC_NC;
  32792. /* import RFC test vectors and compare shared key */
  32793. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32794. if (ret != 0)
  32795. return WC_TEST_RET_ENC_EC(ret);
  32796. ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB);
  32797. if (ret != 0)
  32798. return WC_TEST_RET_ENC_EC(ret);
  32799. /* test against known test vector */
  32800. XMEMSET(sharedB, 0, sizeof(sharedB));
  32801. y = sizeof(sharedB);
  32802. ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y);
  32803. if (ret != 0)
  32804. return WC_TEST_RET_ENC_EC(ret);
  32805. if (XMEMCMP(ss, sharedB, y))
  32806. return WC_TEST_RET_ENC_NC;
  32807. /* test swapping roles of keys and generating same shared key */
  32808. XMEMSET(sharedB, 0, sizeof(sharedB));
  32809. y = sizeof(sharedB);
  32810. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32811. if (ret != 0)
  32812. return WC_TEST_RET_ENC_EC(ret);
  32813. if (XMEMCMP(ss, sharedB, y))
  32814. return WC_TEST_RET_ENC_NC;
  32815. /* test with 1 generated key and 1 from known test vector */
  32816. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32817. if (ret != 0)
  32818. return WC_TEST_RET_ENC_EC(ret);
  32819. ret = wc_curve448_make_key(&rng, 56, &userB);
  32820. if (ret != 0)
  32821. return WC_TEST_RET_ENC_EC(ret);
  32822. x = sizeof(sharedA);
  32823. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32824. if (ret != 0)
  32825. return WC_TEST_RET_ENC_EC(ret);
  32826. y = sizeof(sharedB);
  32827. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32828. if (ret != 0)
  32829. return WC_TEST_RET_ENC_EC(ret);
  32830. /* compare shared secret keys to test they are the same */
  32831. if (y != x)
  32832. return WC_TEST_RET_ENC_NC;
  32833. if (XMEMCMP(sharedA, sharedB, x))
  32834. return WC_TEST_RET_ENC_NC;
  32835. ret = curve448_check_public_test();
  32836. if (ret != 0)
  32837. return ret;
  32838. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32839. /* clean up keys when done */
  32840. wc_curve448_free(&pubKey);
  32841. wc_curve448_free(&userB);
  32842. wc_curve448_free(&userA);
  32843. wc_FreeRng(&rng);
  32844. return 0;
  32845. }
  32846. #endif /* HAVE_CURVE448 */
  32847. #ifdef HAVE_ED448
  32848. #ifdef WOLFSSL_TEST_CERT
  32849. static wc_test_ret_t ed448_test_cert(void)
  32850. {
  32851. DecodedCert cert[2];
  32852. DecodedCert* serverCert = NULL;
  32853. DecodedCert* caCert = NULL;
  32854. #ifdef HAVE_ED448_VERIFY
  32855. ed448_key key;
  32856. ed448_key* pubKey = NULL;
  32857. int verify;
  32858. #endif /* HAVE_ED448_VERIFY */
  32859. wc_test_ret_t ret;
  32860. byte* tmp;
  32861. size_t bytes;
  32862. XFILE file;
  32863. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32864. if (tmp == NULL) {
  32865. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32866. }
  32867. #ifdef USE_CERT_BUFFERS_256
  32868. XMEMCPY(tmp, ca_ed448_cert, sizeof_ca_ed448_cert);
  32869. bytes = sizeof_ca_ed448_cert;
  32870. #elif !defined(NO_FILESYSTEM)
  32871. file = XFOPEN(caEd448Cert, "rb");
  32872. if (file == NULL) {
  32873. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32874. }
  32875. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32876. XFCLOSE(file);
  32877. if (bytes == 0)
  32878. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32879. #else
  32880. /* No certificate to use. */
  32881. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32882. #endif
  32883. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  32884. caCert = &cert[0];
  32885. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  32886. if (ret != 0)
  32887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32888. #ifdef USE_CERT_BUFFERS_256
  32889. XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert);
  32890. bytes = sizeof_server_ed448_cert;
  32891. #elif !defined(NO_FILESYSTEM)
  32892. file = XFOPEN(serverEd448Cert, "rb");
  32893. if (file == NULL) {
  32894. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32895. }
  32896. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32897. XFCLOSE(file);
  32898. if (bytes == 0)
  32899. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32900. #else
  32901. /* No certificate to use. */
  32902. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32903. #endif
  32904. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  32905. serverCert = &cert[1];
  32906. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  32907. if (ret != 0)
  32908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32909. #ifdef HAVE_ED448_VERIFY
  32910. ret = wc_ed448_init(&key);
  32911. if (ret < 0)
  32912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32913. pubKey = &key;
  32914. ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey);
  32915. if (ret < 0)
  32916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32917. ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength,
  32918. serverCert->source + serverCert->certBegin,
  32919. serverCert->sigIndex - serverCert->certBegin,
  32920. &verify, pubKey, NULL, 0);
  32921. if (ret < 0 || verify != 1) {
  32922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32923. }
  32924. #endif /* HAVE_ED448_VERIFY */
  32925. done:
  32926. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32927. #ifdef HAVE_ED448_VERIFY
  32928. wc_ed448_free(pubKey);
  32929. #endif /* HAVE_ED448_VERIFY */
  32930. if (caCert != NULL)
  32931. FreeDecodedCert(caCert);
  32932. if (serverCert != NULL)
  32933. FreeDecodedCert(serverCert);
  32934. return ret;
  32935. }
  32936. static wc_test_ret_t ed448_test_make_cert(void)
  32937. {
  32938. WC_RNG rng;
  32939. Cert cert;
  32940. DecodedCert decode;
  32941. ed448_key key;
  32942. ed448_key* privKey = NULL;
  32943. wc_test_ret_t ret = 0;
  32944. byte* tmp = NULL;
  32945. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  32946. #ifndef HAVE_FIPS
  32947. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32948. #else
  32949. ret = wc_InitRng(&rng);
  32950. #endif
  32951. if (ret != 0)
  32952. return WC_TEST_RET_ENC_EC(ret);
  32953. wc_ed448_init(&key);
  32954. privKey = &key;
  32955. wc_ed448_make_key(&rng, ED448_KEY_SIZE, privKey);
  32956. cert.daysValid = 365 * 2;
  32957. cert.selfSigned = 1;
  32958. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  32959. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  32960. cert.isCA = 0;
  32961. #ifdef WOLFSSL_CERT_EXT
  32962. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  32963. if (ret < 0)
  32964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32965. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32966. if (ret < 0)
  32967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32968. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32969. if (ret < 0)
  32970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32971. #endif
  32972. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32973. if (tmp == NULL) {
  32974. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32975. }
  32976. cert.sigType = CTC_ED448;
  32977. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng);
  32978. if (ret < 0)
  32979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32980. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE,
  32981. privKey, &rng);
  32982. if (ret < 0)
  32983. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32984. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  32985. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  32986. FreeDecodedCert(&decode);
  32987. if (ret != 0)
  32988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32989. done:
  32990. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32991. wc_ed448_free(privKey);
  32992. wc_FreeRng(&rng);
  32993. return ret;
  32994. }
  32995. #endif /* WOLFSSL_TEST_CERT */
  32996. #if defined(HAVE_ED448_KEY_IMPORT)
  32997. static wc_test_ret_t ed448_test_check_key(void)
  32998. {
  32999. /* Fails to find x-ordinate from this y-ordinate. */
  33000. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  33001. 0x40,
  33002. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33003. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33004. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33005. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33006. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33007. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33008. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33009. 0x00
  33010. };
  33011. /* Y-ordinate value larger than prime. */
  33012. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  33013. 0x40,
  33014. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33015. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33016. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33017. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33018. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33019. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33020. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33021. 0xff
  33022. };
  33023. /* Y-ordinate value equal to prime. */
  33024. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  33025. 0x40,
  33026. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33027. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33028. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33029. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  33030. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33031. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33032. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33033. 0xff
  33034. };
  33035. /* Y-ordinate value equal to prime - 1. */
  33036. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  33037. 0x40,
  33038. 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33039. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33040. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33041. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  33042. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33043. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33044. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33045. 0xff
  33046. };
  33047. ed448_key key;
  33048. int ret;
  33049. int res = 0;
  33050. /* Initialize key for use. */
  33051. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33052. if (ret != 0) {
  33053. return WC_TEST_RET_ENC_NC;
  33054. }
  33055. /* Load bad public key only and perform checks. */
  33056. ret = wc_ed448_import_public(key_bad_y, ED448_PUB_KEY_SIZE + 1, &key);
  33057. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33058. res = WC_TEST_RET_ENC_NC;
  33059. }
  33060. if (ret == 0) {
  33061. /* Load bad public key only and perform checks. */
  33062. ret = wc_ed448_import_public(key_bad_y_max, ED448_PUB_KEY_SIZE + 1,
  33063. &key);
  33064. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33065. res = WC_TEST_RET_ENC_NC;
  33066. }
  33067. }
  33068. if (res == 0) {
  33069. /* Load bad public key only and perform checks. */
  33070. ret = wc_ed448_import_public(key_bad_y_is_p, ED448_PUB_KEY_SIZE + 1,
  33071. &key);
  33072. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33073. res = WC_TEST_RET_ENC_NC;
  33074. }
  33075. }
  33076. if (res == 0) {
  33077. /* Load good public key only and perform checks. */
  33078. ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1,
  33079. &key);
  33080. if (ret != 0) {
  33081. res = WC_TEST_RET_ENC_NC;
  33082. }
  33083. }
  33084. /* Dispose of key. */
  33085. wc_ed448_free(&key);
  33086. return res;
  33087. }
  33088. #endif
  33089. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33090. defined(HAVE_ED448_KEY_IMPORT)
  33091. static wc_test_ret_t ed448_ctx_test(void)
  33092. {
  33093. wc_test_ret_t ret;
  33094. byte out[ED448_SIG_SIZE];
  33095. word32 outlen;
  33096. #ifdef HAVE_ED448_VERIFY
  33097. int verify;
  33098. #endif /* HAVE_ED448_VERIFY */
  33099. ed448_key key;
  33100. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  33101. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33102. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33103. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33104. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33105. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33106. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33107. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33108. 0x4e
  33109. };
  33110. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  33111. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33112. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33113. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33114. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33115. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33116. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33117. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33118. 0x80
  33119. };
  33120. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx[] = {
  33121. 0xd4, 0xf8, 0xf6, 0x13, 0x17, 0x70, 0xdd, 0x46,
  33122. 0xf4, 0x08, 0x67, 0xd6, 0xfd, 0x5d, 0x50, 0x55,
  33123. 0xde, 0x43, 0x54, 0x1f, 0x8c, 0x5e, 0x35, 0xab,
  33124. 0xbc, 0xd0, 0x01, 0xb3, 0x2a, 0x89, 0xf7, 0xd2,
  33125. 0x15, 0x1f, 0x76, 0x47, 0xf1, 0x1d, 0x8c, 0xa2,
  33126. 0xae, 0x27, 0x9f, 0xb8, 0x42, 0xd6, 0x07, 0x21,
  33127. 0x7f, 0xce, 0x6e, 0x04, 0x2f, 0x68, 0x15, 0xea,
  33128. 0x00, 0x0c, 0x85, 0x74, 0x1d, 0xe5, 0xc8, 0xda,
  33129. 0x11, 0x44, 0xa6, 0xa1, 0xab, 0xa7, 0xf9, 0x6d,
  33130. 0xe4, 0x25, 0x05, 0xd7, 0xa7, 0x29, 0x85, 0x24,
  33131. 0xfd, 0xa5, 0x38, 0xfc, 0xcb, 0xbb, 0x75, 0x4f,
  33132. 0x57, 0x8c, 0x1c, 0xad, 0x10, 0xd5, 0x4d, 0x0d,
  33133. 0x54, 0x28, 0x40, 0x7e, 0x85, 0xdc, 0xbc, 0x98,
  33134. 0xa4, 0x91, 0x55, 0xc1, 0x37, 0x64, 0xe6, 0x6c,
  33135. 0x3c, 0x00
  33136. };
  33137. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  33138. 0x03
  33139. };
  33140. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  33141. 0x66,0x6f,0x6f
  33142. };
  33143. outlen = sizeof(out);
  33144. XMEMSET(out, 0, sizeof(out));
  33145. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33146. if (ret != 0)
  33147. return WC_TEST_RET_ENC_EC(ret);
  33148. ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx,
  33149. sizeof(pKeyCtx), &key);
  33150. if (ret != 0)
  33151. return WC_TEST_RET_ENC_EC(ret);
  33152. ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  33153. contextCtx, sizeof(contextCtx));
  33154. if (ret != 0)
  33155. return WC_TEST_RET_ENC_EC(ret);
  33156. if (XMEMCMP(out, sigCtx, sizeof(sigCtx)))
  33157. return WC_TEST_RET_ENC_NC;
  33158. #if defined(HAVE_ED448_VERIFY)
  33159. /* test verify on good msg */
  33160. ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key,
  33161. contextCtx, sizeof(contextCtx));
  33162. if (ret != 0 || verify != 1)
  33163. return WC_TEST_RET_ENC_EC(ret);
  33164. #endif
  33165. wc_ed448_free(&key);
  33166. return 0;
  33167. }
  33168. static wc_test_ret_t ed448ph_test(void)
  33169. {
  33170. wc_test_ret_t ret;
  33171. byte out[ED448_SIG_SIZE];
  33172. word32 outlen;
  33173. #ifdef HAVE_ED448_VERIFY
  33174. int verify;
  33175. #endif /* HAVE_ED448_VERIFY */
  33176. ed448_key key;
  33177. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  33178. 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
  33179. 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
  33180. 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
  33181. 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42,
  33182. 0xef, 0x78, 0x22, 0xe0, 0xd5, 0x10, 0x41, 0x27,
  33183. 0xdc, 0x05, 0xd6, 0xdb, 0xef, 0xde, 0x69, 0xe3,
  33184. 0xab, 0x2c, 0xec, 0x7c, 0x86, 0x7c, 0x6e, 0x2c,
  33185. 0x49
  33186. };
  33187. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  33188. 0x25, 0x9b, 0x71, 0xc1, 0x9f, 0x83, 0xef, 0x77,
  33189. 0xa7, 0xab, 0xd2, 0x65, 0x24, 0xcb, 0xdb, 0x31,
  33190. 0x61, 0xb5, 0x90, 0xa4, 0x8f, 0x7d, 0x17, 0xde,
  33191. 0x3e, 0xe0, 0xba, 0x9c, 0x52, 0xbe, 0xb7, 0x43,
  33192. 0xc0, 0x94, 0x28, 0xa1, 0x31, 0xd6, 0xb1, 0xb5,
  33193. 0x73, 0x03, 0xd9, 0x0d, 0x81, 0x32, 0xc2, 0x76,
  33194. 0xd5, 0xed, 0x3d, 0x5d, 0x01, 0xc0, 0xf5, 0x38,
  33195. 0x80
  33196. };
  33197. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  33198. 0x82, 0x2f, 0x69, 0x01, 0xf7, 0x48, 0x0f, 0x3d,
  33199. 0x5f, 0x56, 0x2c, 0x59, 0x29, 0x94, 0xd9, 0x69,
  33200. 0x36, 0x02, 0x87, 0x56, 0x14, 0x48, 0x32, 0x56,
  33201. 0x50, 0x56, 0x00, 0xbb, 0xc2, 0x81, 0xae, 0x38,
  33202. 0x1f, 0x54, 0xd6, 0xbc, 0xe2, 0xea, 0x91, 0x15,
  33203. 0x74, 0x93, 0x2f, 0x52, 0xa4, 0xe6, 0xca, 0xdd,
  33204. 0x78, 0x76, 0x93, 0x75, 0xec, 0x3f, 0xfd, 0x1b,
  33205. 0x80, 0x1a, 0x0d, 0x9b, 0x3f, 0x40, 0x30, 0xcd,
  33206. 0x43, 0x39, 0x64, 0xb6, 0x45, 0x7e, 0xa3, 0x94,
  33207. 0x76, 0x51, 0x12, 0x14, 0xf9, 0x74, 0x69, 0xb5,
  33208. 0x7d, 0xd3, 0x2d, 0xbc, 0x56, 0x0a, 0x9a, 0x94,
  33209. 0xd0, 0x0b, 0xff, 0x07, 0x62, 0x04, 0x64, 0xa3,
  33210. 0xad, 0x20, 0x3d, 0xf7, 0xdc, 0x7c, 0xe3, 0x60,
  33211. 0xc3, 0xcd, 0x36, 0x96, 0xd9, 0xd9, 0xfa, 0xb9,
  33212. 0x0f, 0x00
  33213. };
  33214. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  33215. 0xc3, 0x22, 0x99, 0xd4, 0x6e, 0xc8, 0xff, 0x02,
  33216. 0xb5, 0x45, 0x40, 0x98, 0x28, 0x14, 0xdc, 0xe9,
  33217. 0xa0, 0x58, 0x12, 0xf8, 0x19, 0x62, 0xb6, 0x49,
  33218. 0xd5, 0x28, 0x09, 0x59, 0x16, 0xa2, 0xaa, 0x48,
  33219. 0x10, 0x65, 0xb1, 0x58, 0x04, 0x23, 0xef, 0x92,
  33220. 0x7e, 0xcf, 0x0a, 0xf5, 0x88, 0x8f, 0x90, 0xda,
  33221. 0x0f, 0x6a, 0x9a, 0x85, 0xad, 0x5d, 0xc3, 0xf2,
  33222. 0x80, 0xd9, 0x12, 0x24, 0xba, 0x99, 0x11, 0xa3,
  33223. 0x65, 0x3d, 0x00, 0xe4, 0x84, 0xe2, 0xce, 0x23,
  33224. 0x25, 0x21, 0x48, 0x1c, 0x86, 0x58, 0xdf, 0x30,
  33225. 0x4b, 0xb7, 0x74, 0x5a, 0x73, 0x51, 0x4c, 0xdb,
  33226. 0x9b, 0xf3, 0xe1, 0x57, 0x84, 0xab, 0x71, 0x28,
  33227. 0x4f, 0x8d, 0x07, 0x04, 0xa6, 0x08, 0xc5, 0x4a,
  33228. 0x6b, 0x62, 0xd9, 0x7b, 0xeb, 0x51, 0x1d, 0x13,
  33229. 0x21, 0x00
  33230. };
  33231. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  33232. 0x61,0x62,0x63
  33233. };
  33234. /* SHA-512 hash of msgPh */
  33235. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  33236. 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
  33237. 0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
  33238. 0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
  33239. 0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39,
  33240. 0xd5, 0xa1, 0x5b, 0xef, 0x18, 0x6a, 0x53, 0x86,
  33241. 0xc7, 0x57, 0x44, 0xc0, 0x52, 0x7e, 0x1f, 0xaa,
  33242. 0x9f, 0x87, 0x26, 0xe4, 0x62, 0xa1, 0x2a, 0x4f,
  33243. 0xeb, 0x06, 0xbd, 0x88, 0x01, 0xe7, 0x51, 0xe4
  33244. };
  33245. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  33246. 0x66,0x6f,0x6f
  33247. };
  33248. outlen = sizeof(out);
  33249. XMEMSET(out, 0, sizeof(out));
  33250. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33251. if (ret != 0)
  33252. return WC_TEST_RET_ENC_EC(ret);
  33253. ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh,
  33254. sizeof(pKeyPh), &key);
  33255. if (ret != 0)
  33256. return WC_TEST_RET_ENC_EC(ret);
  33257. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL,
  33258. 0);
  33259. if (ret != 0)
  33260. return WC_TEST_RET_ENC_EC(ret);
  33261. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33262. return WC_TEST_RET_ENC_NC;
  33263. #if defined(HAVE_ED448_VERIFY)
  33264. /* test verify on good msg */
  33265. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33266. NULL, 0);
  33267. if (ret != 0 || verify != 1) {
  33268. return WC_TEST_RET_ENC_EC(ret);
  33269. }
  33270. #endif
  33271. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  33272. contextPh2, sizeof(contextPh2));
  33273. if (ret != 0)
  33274. return WC_TEST_RET_ENC_EC(ret);
  33275. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33276. return WC_TEST_RET_ENC_NC;
  33277. #if defined(HAVE_ED448_VERIFY)
  33278. /* test verify on good msg */
  33279. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33280. contextPh2, sizeof(contextPh2));
  33281. if (ret != 0 || verify != 1) {
  33282. return WC_TEST_RET_ENC_EC(ret);
  33283. }
  33284. #endif
  33285. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL,
  33286. 0);
  33287. if (ret != 0)
  33288. return WC_TEST_RET_ENC_EC(ret);
  33289. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33290. return WC_TEST_RET_ENC_NC;
  33291. #if defined(HAVE_ED448_VERIFY)
  33292. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33293. &key, NULL, 0);
  33294. if (ret != 0 || verify != 1) {
  33295. return WC_TEST_RET_ENC_EC(ret);
  33296. }
  33297. #endif
  33298. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  33299. contextPh2, sizeof(contextPh2));
  33300. if (ret != 0)
  33301. return WC_TEST_RET_ENC_EC(ret);
  33302. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33303. return WC_TEST_RET_ENC_NC;
  33304. #if defined(HAVE_ED448_VERIFY)
  33305. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33306. &key, contextPh2, sizeof(contextPh2));
  33307. if (ret != 0 || verify != 1) {
  33308. return WC_TEST_RET_ENC_EC(ret);
  33309. }
  33310. #endif
  33311. wc_ed448_free(&key);
  33312. return 0;
  33313. }
  33314. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33315. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
  33316. {
  33317. wc_test_ret_t ret;
  33318. WC_RNG rng;
  33319. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33320. defined(HAVE_ED448_KEY_IMPORT)
  33321. byte out[ED448_SIG_SIZE];
  33322. int i;
  33323. word32 outlen;
  33324. #ifdef HAVE_ED448_VERIFY
  33325. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33326. int j;
  33327. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33328. int verify;
  33329. #endif /* HAVE_ED448_VERIFY */
  33330. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33331. word32 keySz, sigSz;
  33332. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33333. ed448_key *key = NULL;
  33334. ed448_key *key2 = NULL;
  33335. #else
  33336. ed448_key key[1];
  33337. ed448_key key2[1];
  33338. #endif
  33339. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33340. defined(HAVE_ED448_KEY_IMPORT)
  33341. /* test vectors from
  33342. https://tools.ietf.org/html/rfc8032
  33343. */
  33344. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  33345. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33346. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33347. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33348. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33349. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33350. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33351. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33352. 0x5b
  33353. };
  33354. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  33355. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33356. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33357. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33358. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33359. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33360. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33361. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33362. 0x4e
  33363. };
  33364. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  33365. 0x25, 0x8c, 0xdd, 0x4a, 0xda, 0x32, 0xed, 0x9c,
  33366. 0x9f, 0xf5, 0x4e, 0x63, 0x75, 0x6a, 0xe5, 0x82,
  33367. 0xfb, 0x8f, 0xab, 0x2a, 0xc7, 0x21, 0xf2, 0xc8,
  33368. 0xe6, 0x76, 0xa7, 0x27, 0x68, 0x51, 0x3d, 0x93,
  33369. 0x9f, 0x63, 0xdd, 0xdb, 0x55, 0x60, 0x91, 0x33,
  33370. 0xf2, 0x9a, 0xdf, 0x86, 0xec, 0x99, 0x29, 0xdc,
  33371. 0xcb, 0x52, 0xc1, 0xc5, 0xfd, 0x2f, 0xf7, 0xe2,
  33372. 0x1b
  33373. };
  33374. /* uncompressed test */
  33375. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  33376. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33377. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33378. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33379. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33380. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33381. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33382. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33383. 0x5b
  33384. };
  33385. /* compressed prefix test */
  33386. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  33387. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33388. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33389. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33390. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33391. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33392. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33393. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33394. 0x5b
  33395. };
  33396. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  33397. 0x87, 0x2d, 0x09, 0x37, 0x80, 0xf5, 0xd3, 0x73,
  33398. 0x0d, 0xf7, 0xc2, 0x12, 0x66, 0x4b, 0x37, 0xb8,
  33399. 0xa0, 0xf2, 0x4f, 0x56, 0x81, 0x0d, 0xaa, 0x83,
  33400. 0x82, 0xcd, 0x4f, 0xa3, 0xf7, 0x76, 0x34, 0xec,
  33401. 0x44, 0xdc, 0x54, 0xf1, 0xc2, 0xed, 0x9b, 0xea,
  33402. 0x86, 0xfa, 0xfb, 0x76, 0x32, 0xd8, 0xbe, 0x19,
  33403. 0x9e, 0xa1, 0x65, 0xf5, 0xad, 0x55, 0xdd, 0x9c,
  33404. 0xe8
  33405. };
  33406. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  33407. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  33408. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33409. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33410. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33411. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33412. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33413. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33414. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33415. 0x80
  33416. };
  33417. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  33418. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33419. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33420. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33421. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33422. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33423. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33424. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33425. 0x80
  33426. };
  33427. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  33428. 0x3b, 0xa1, 0x6d, 0xa0, 0xc6, 0xf2, 0xcc, 0x1f,
  33429. 0x30, 0x18, 0x77, 0x40, 0x75, 0x6f, 0x5e, 0x79,
  33430. 0x8d, 0x6b, 0xc5, 0xfc, 0x01, 0x5d, 0x7c, 0x63,
  33431. 0xcc, 0x95, 0x10, 0xee, 0x3f, 0xd4, 0x4a, 0xdc,
  33432. 0x24, 0xd8, 0xe9, 0x68, 0xb6, 0xe4, 0x6e, 0x6f,
  33433. 0x94, 0xd1, 0x9b, 0x94, 0x53, 0x61, 0x72, 0x6b,
  33434. 0xd7, 0x5e, 0x14, 0x9e, 0xf0, 0x98, 0x17, 0xf5,
  33435. 0x80
  33436. };
  33437. /* uncompressed test */
  33438. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  33439. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33440. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33441. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33442. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33443. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33444. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33445. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33446. 0x80
  33447. };
  33448. /* compressed prefix */
  33449. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  33450. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33451. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33452. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33453. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33454. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33455. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33456. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33457. 0x80
  33458. };
  33459. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  33460. 0xa8, 0x1b, 0x2e, 0x8a, 0x70, 0xa5, 0xac, 0x94,
  33461. 0xff, 0xdb, 0xcc, 0x9b, 0xad, 0xfc, 0x3f, 0xeb,
  33462. 0x08, 0x01, 0xf2, 0x58, 0x57, 0x8b, 0xb1, 0x14,
  33463. 0xad, 0x44, 0xec, 0xe1, 0xec, 0x0e, 0x79, 0x9d,
  33464. 0xa0, 0x8e, 0xff, 0xb8, 0x1c, 0x5d, 0x68, 0x5c,
  33465. 0x0c, 0x56, 0xf6, 0x4e, 0xec, 0xae, 0xf8, 0xcd,
  33466. 0xf1, 0x1c, 0xc3, 0x87, 0x37, 0x83, 0x8c, 0xf4,
  33467. 0x00
  33468. };
  33469. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  33470. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  33471. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  33472. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  33473. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33474. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33475. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33476. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33477. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33478. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33479. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33480. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33481. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33482. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33483. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33484. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33485. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33486. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33487. 0x26, 0x00
  33488. };
  33489. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  33490. 0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89,
  33491. 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3, 0x77,
  33492. 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35,
  33493. 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10, 0xf4, 0x35,
  33494. 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7,
  33495. 0xe1, 0x8f, 0x62, 0xde, 0x8c, 0xcd, 0xf6, 0x33,
  33496. 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79,
  33497. 0x80, 0x5e, 0x0d, 0xbc, 0xc0, 0xaa, 0xe1, 0xcb,
  33498. 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36,
  33499. 0xbc, 0x04, 0xdc, 0xec, 0xbf, 0x15, 0x43, 0x36,
  33500. 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29,
  33501. 0x05, 0xe7, 0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f,
  33502. 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf,
  33503. 0xd1, 0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0,
  33504. 0x3a, 0x00
  33505. };
  33506. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  33507. 0x7e, 0xee, 0xab, 0x7c, 0x4e, 0x50, 0xfb, 0x79,
  33508. 0x9b, 0x41, 0x8e, 0xe5, 0xe3, 0x19, 0x7f, 0xf6,
  33509. 0xbf, 0x15, 0xd4, 0x3a, 0x14, 0xc3, 0x43, 0x89,
  33510. 0xb5, 0x9d, 0xd1, 0xa7, 0xb1, 0xb8, 0x5b, 0x4a,
  33511. 0xe9, 0x04, 0x38, 0xac, 0xa6, 0x34, 0xbe, 0xa4,
  33512. 0x5e, 0x3a, 0x26, 0x95, 0xf1, 0x27, 0x0f, 0x07,
  33513. 0xfd, 0xcd, 0xf7, 0xc6, 0x2b, 0x8e, 0xfe, 0xaf,
  33514. 0x00, 0xb4, 0x5c, 0x2c, 0x96, 0xba, 0x45, 0x7e,
  33515. 0xb1, 0xa8, 0xbf, 0x07, 0x5a, 0x3d, 0xb2, 0x8e,
  33516. 0x5c, 0x24, 0xf6, 0xb9, 0x23, 0xed, 0x4a, 0xd7,
  33517. 0x47, 0xc3, 0xc9, 0xe0, 0x3c, 0x70, 0x79, 0xef,
  33518. 0xb8, 0x7c, 0xb1, 0x10, 0xd3, 0xa9, 0x98, 0x61,
  33519. 0xe7, 0x20, 0x03, 0xcb, 0xae, 0x6d, 0x6b, 0x8b,
  33520. 0x82, 0x7e, 0x4e, 0x6c, 0x14, 0x30, 0x64, 0xff,
  33521. 0x3c, 0x00
  33522. };
  33523. /* uncompressed test */
  33524. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  33525. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33526. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33527. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33528. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33529. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33530. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33531. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33532. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33533. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33534. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33535. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33536. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33537. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33538. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33539. 0x26, 0x00
  33540. };
  33541. /* compressed prefix */
  33542. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  33543. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33544. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33545. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33546. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33547. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33548. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33549. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33550. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33551. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33552. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33553. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33554. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33555. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33556. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33557. 0x26, 0x00
  33558. };
  33559. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  33560. 0xe3, 0x01, 0x34, 0x5a, 0x41, 0xa3, 0x9a, 0x4d,
  33561. 0x72, 0xff, 0xf8, 0xdf, 0x69, 0xc9, 0x80, 0x75,
  33562. 0xa0, 0xcc, 0x08, 0x2b, 0x80, 0x2f, 0xc9, 0xb2,
  33563. 0xb6, 0xbc, 0x50, 0x3f, 0x92, 0x6b, 0x65, 0xbd,
  33564. 0xdf, 0x7f, 0x4c, 0x8f, 0x1c, 0xb4, 0x9f, 0x63,
  33565. 0x96, 0xaf, 0xc8, 0xa7, 0x0a, 0xbe, 0x6d, 0x8a,
  33566. 0xef, 0x0d, 0xb4, 0x78, 0xd4, 0xc6, 0xb2, 0x97,
  33567. 0x00, 0x76, 0xc6, 0xa0, 0x48, 0x4f, 0xe7, 0x6d,
  33568. 0x76, 0xb3, 0xa9, 0x76, 0x25, 0xd7, 0x9f, 0x1c,
  33569. 0xe2, 0x40, 0xe7, 0xc5, 0x76, 0x75, 0x0d, 0x29,
  33570. 0x55, 0x28, 0x28, 0x6f, 0x71, 0x9b, 0x41, 0x3d,
  33571. 0xe9, 0xad, 0xa3, 0xe8, 0xeb, 0x78, 0xed, 0x57,
  33572. 0x36, 0x03, 0xce, 0x30, 0xd8, 0xbb, 0x76, 0x17,
  33573. 0x85, 0xdc, 0x30, 0xdb, 0xc3, 0x20, 0x86, 0x9e,
  33574. 0x1a, 0x00
  33575. };
  33576. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  33577. #define SIGSZ sizeof(sig1)
  33578. PEDANTIC_EXTENSION WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = { 0 };
  33579. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = { 0x03 };
  33580. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = { 0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd,
  33581. 0x66, 0x81, 0x1e, 0x29, 0x15 };
  33582. /* test of a 1023 byte long message */
  33583. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  33584. 0x6d, 0xdf, 0x80, 0x2e, 0x1a, 0xae, 0x49, 0x86,
  33585. 0x93, 0x5f, 0x7f, 0x98, 0x1b, 0xa3, 0xf0, 0x35,
  33586. 0x1d, 0x62, 0x73, 0xc0, 0xa0, 0xc2, 0x2c, 0x9c,
  33587. 0x0e, 0x83, 0x39, 0x16, 0x8e, 0x67, 0x54, 0x12,
  33588. 0xa3, 0xde, 0xbf, 0xaf, 0x43, 0x5e, 0xd6, 0x51,
  33589. 0x55, 0x80, 0x07, 0xdb, 0x43, 0x84, 0xb6, 0x50,
  33590. 0xfc, 0xc0, 0x7e, 0x3b, 0x58, 0x6a, 0x27, 0xa4,
  33591. 0xf7, 0xa0, 0x0a, 0xc8, 0xa6, 0xfe, 0xc2, 0xcd,
  33592. 0x86, 0xae, 0x4b, 0xf1, 0x57, 0x0c, 0x41, 0xe6,
  33593. 0xa4, 0x0c, 0x93, 0x1d, 0xb2, 0x7b, 0x2f, 0xaa,
  33594. 0x15, 0xa8, 0xce, 0xdd, 0x52, 0xcf, 0xf7, 0x36,
  33595. 0x2c, 0x4e, 0x6e, 0x23, 0xda, 0xec, 0x0f, 0xbc,
  33596. 0x3a, 0x79, 0xb6, 0x80, 0x6e, 0x31, 0x6e, 0xfc,
  33597. 0xc7, 0xb6, 0x81, 0x19, 0xbf, 0x46, 0xbc, 0x76,
  33598. 0xa2, 0x60, 0x67, 0xa5, 0x3f, 0x29, 0x6d, 0xaf,
  33599. 0xdb, 0xdc, 0x11, 0xc7, 0x7f, 0x77, 0x77, 0xe9,
  33600. 0x72, 0x66, 0x0c, 0xf4, 0xb6, 0xa9, 0xb3, 0x69,
  33601. 0xa6, 0x66, 0x5f, 0x02, 0xe0, 0xcc, 0x9b, 0x6e,
  33602. 0xdf, 0xad, 0x13, 0x6b, 0x4f, 0xab, 0xe7, 0x23,
  33603. 0xd2, 0x81, 0x3d, 0xb3, 0x13, 0x6c, 0xfd, 0xe9,
  33604. 0xb6, 0xd0, 0x44, 0x32, 0x2f, 0xee, 0x29, 0x47,
  33605. 0x95, 0x2e, 0x03, 0x1b, 0x73, 0xab, 0x5c, 0x60,
  33606. 0x33, 0x49, 0xb3, 0x07, 0xbd, 0xc2, 0x7b, 0xc6,
  33607. 0xcb, 0x8b, 0x8b, 0xbd, 0x7b, 0xd3, 0x23, 0x21,
  33608. 0x9b, 0x80, 0x33, 0xa5, 0x81, 0xb5, 0x9e, 0xad,
  33609. 0xeb, 0xb0, 0x9b, 0x3c, 0x4f, 0x3d, 0x22, 0x77,
  33610. 0xd4, 0xf0, 0x34, 0x36, 0x24, 0xac, 0xc8, 0x17,
  33611. 0x80, 0x47, 0x28, 0xb2, 0x5a, 0xb7, 0x97, 0x17,
  33612. 0x2b, 0x4c, 0x5c, 0x21, 0xa2, 0x2f, 0x9c, 0x78,
  33613. 0x39, 0xd6, 0x43, 0x00, 0x23, 0x2e, 0xb6, 0x6e,
  33614. 0x53, 0xf3, 0x1c, 0x72, 0x3f, 0xa3, 0x7f, 0xe3,
  33615. 0x87, 0xc7, 0xd3, 0xe5, 0x0b, 0xdf, 0x98, 0x13,
  33616. 0xa3, 0x0e, 0x5b, 0xb1, 0x2c, 0xf4, 0xcd, 0x93,
  33617. 0x0c, 0x40, 0xcf, 0xb4, 0xe1, 0xfc, 0x62, 0x25,
  33618. 0x92, 0xa4, 0x95, 0x88, 0x79, 0x44, 0x94, 0xd5,
  33619. 0x6d, 0x24, 0xea, 0x4b, 0x40, 0xc8, 0x9f, 0xc0,
  33620. 0x59, 0x6c, 0xc9, 0xeb, 0xb9, 0x61, 0xc8, 0xcb,
  33621. 0x10, 0xad, 0xde, 0x97, 0x6a, 0x5d, 0x60, 0x2b,
  33622. 0x1c, 0x3f, 0x85, 0xb9, 0xb9, 0xa0, 0x01, 0xed,
  33623. 0x3c, 0x6a, 0x4d, 0x3b, 0x14, 0x37, 0xf5, 0x20,
  33624. 0x96, 0xcd, 0x19, 0x56, 0xd0, 0x42, 0xa5, 0x97,
  33625. 0xd5, 0x61, 0xa5, 0x96, 0xec, 0xd3, 0xd1, 0x73,
  33626. 0x5a, 0x8d, 0x57, 0x0e, 0xa0, 0xec, 0x27, 0x22,
  33627. 0x5a, 0x2c, 0x4a, 0xaf, 0xf2, 0x63, 0x06, 0xd1,
  33628. 0x52, 0x6c, 0x1a, 0xf3, 0xca, 0x6d, 0x9c, 0xf5,
  33629. 0xa2, 0xc9, 0x8f, 0x47, 0xe1, 0xc4, 0x6d, 0xb9,
  33630. 0xa3, 0x32, 0x34, 0xcf, 0xd4, 0xd8, 0x1f, 0x2c,
  33631. 0x98, 0x53, 0x8a, 0x09, 0xeb, 0xe7, 0x69, 0x98,
  33632. 0xd0, 0xd8, 0xfd, 0x25, 0x99, 0x7c, 0x7d, 0x25,
  33633. 0x5c, 0x6d, 0x66, 0xec, 0xe6, 0xfa, 0x56, 0xf1,
  33634. 0x11, 0x44, 0x95, 0x0f, 0x02, 0x77, 0x95, 0xe6,
  33635. 0x53, 0x00, 0x8f, 0x4b, 0xd7, 0xca, 0x2d, 0xee,
  33636. 0x85, 0xd8, 0xe9, 0x0f, 0x3d, 0xc3, 0x15, 0x13,
  33637. 0x0c, 0xe2, 0xa0, 0x03, 0x75, 0xa3, 0x18, 0xc7,
  33638. 0xc3, 0xd9, 0x7b, 0xe2, 0xc8, 0xce, 0x5b, 0x6d,
  33639. 0xb4, 0x1a, 0x62, 0x54, 0xff, 0x26, 0x4f, 0xa6,
  33640. 0x15, 0x5b, 0xae, 0xe3, 0xb0, 0x77, 0x3c, 0x0f,
  33641. 0x49, 0x7c, 0x57, 0x3f, 0x19, 0xbb, 0x4f, 0x42,
  33642. 0x40, 0x28, 0x1f, 0x0b, 0x1f, 0x4f, 0x7b, 0xe8,
  33643. 0x57, 0xa4, 0xe5, 0x9d, 0x41, 0x6c, 0x06, 0xb4,
  33644. 0xc5, 0x0f, 0xa0, 0x9e, 0x18, 0x10, 0xdd, 0xc6,
  33645. 0xb1, 0x46, 0x7b, 0xae, 0xac, 0x5a, 0x36, 0x68,
  33646. 0xd1, 0x1b, 0x6e, 0xca, 0xa9, 0x01, 0x44, 0x00,
  33647. 0x16, 0xf3, 0x89, 0xf8, 0x0a, 0xcc, 0x4d, 0xb9,
  33648. 0x77, 0x02, 0x5e, 0x7f, 0x59, 0x24, 0x38, 0x8c,
  33649. 0x7e, 0x34, 0x0a, 0x73, 0x2e, 0x55, 0x44, 0x40,
  33650. 0xe7, 0x65, 0x70, 0xf8, 0xdd, 0x71, 0xb7, 0xd6,
  33651. 0x40, 0xb3, 0x45, 0x0d, 0x1f, 0xd5, 0xf0, 0x41,
  33652. 0x0a, 0x18, 0xf9, 0xa3, 0x49, 0x4f, 0x70, 0x7c,
  33653. 0x71, 0x7b, 0x79, 0xb4, 0xbf, 0x75, 0xc9, 0x84,
  33654. 0x00, 0xb0, 0x96, 0xb2, 0x16, 0x53, 0xb5, 0xd2,
  33655. 0x17, 0xcf, 0x35, 0x65, 0xc9, 0x59, 0x74, 0x56,
  33656. 0xf7, 0x07, 0x03, 0x49, 0x7a, 0x07, 0x87, 0x63,
  33657. 0x82, 0x9b, 0xc0, 0x1b, 0xb1, 0xcb, 0xc8, 0xfa,
  33658. 0x04, 0xea, 0xdc, 0x9a, 0x6e, 0x3f, 0x66, 0x99,
  33659. 0x58, 0x7a, 0x9e, 0x75, 0xc9, 0x4e, 0x5b, 0xab,
  33660. 0x00, 0x36, 0xe0, 0xb2, 0xe7, 0x11, 0x39, 0x2c,
  33661. 0xff, 0x00, 0x47, 0xd0, 0xd6, 0xb0, 0x5b, 0xd2,
  33662. 0xa5, 0x88, 0xbc, 0x10, 0x97, 0x18, 0x95, 0x42,
  33663. 0x59, 0xf1, 0xd8, 0x66, 0x78, 0xa5, 0x79, 0xa3,
  33664. 0x12, 0x0f, 0x19, 0xcf, 0xb2, 0x96, 0x3f, 0x17,
  33665. 0x7a, 0xeb, 0x70, 0xf2, 0xd4, 0x84, 0x48, 0x26,
  33666. 0x26, 0x2e, 0x51, 0xb8, 0x02, 0x71, 0x27, 0x20,
  33667. 0x68, 0xef, 0x5b, 0x38, 0x56, 0xfa, 0x85, 0x35,
  33668. 0xaa, 0x2a, 0x88, 0xb2, 0xd4, 0x1f, 0x2a, 0x0e,
  33669. 0x2f, 0xda, 0x76, 0x24, 0xc2, 0x85, 0x02, 0x72,
  33670. 0xac, 0x4a, 0x2f, 0x56, 0x1f, 0x8f, 0x2f, 0x7a,
  33671. 0x31, 0x8b, 0xfd, 0x5c, 0xaf, 0x96, 0x96, 0x14,
  33672. 0x9e, 0x4a, 0xc8, 0x24, 0xad, 0x34, 0x60, 0x53,
  33673. 0x8f, 0xdc, 0x25, 0x42, 0x1b, 0xee, 0xc2, 0xcc,
  33674. 0x68, 0x18, 0x16, 0x2d, 0x06, 0xbb, 0xed, 0x0c,
  33675. 0x40, 0xa3, 0x87, 0x19, 0x23, 0x49, 0xdb, 0x67,
  33676. 0xa1, 0x18, 0xba, 0xda, 0x6c, 0xd5, 0xab, 0x01,
  33677. 0x40, 0xee, 0x27, 0x32, 0x04, 0xf6, 0x28, 0xaa,
  33678. 0xd1, 0xc1, 0x35, 0xf7, 0x70, 0x27, 0x9a, 0x65,
  33679. 0x1e, 0x24, 0xd8, 0xc1, 0x4d, 0x75, 0xa6, 0x05,
  33680. 0x9d, 0x76, 0xb9, 0x6a, 0x6f, 0xd8, 0x57, 0xde,
  33681. 0xf5, 0xe0, 0xb3, 0x54, 0xb2, 0x7a, 0xb9, 0x37,
  33682. 0xa5, 0x81, 0x5d, 0x16, 0xb5, 0xfa, 0xe4, 0x07,
  33683. 0xff, 0x18, 0x22, 0x2c, 0x6d, 0x1e, 0xd2, 0x63,
  33684. 0xbe, 0x68, 0xc9, 0x5f, 0x32, 0xd9, 0x08, 0xbd,
  33685. 0x89, 0x5c, 0xd7, 0x62, 0x07, 0xae, 0x72, 0x64,
  33686. 0x87, 0x56, 0x7f, 0x9a, 0x67, 0xda, 0xd7, 0x9a,
  33687. 0xbe, 0xc3, 0x16, 0xf6, 0x83, 0xb1, 0x7f, 0x2d,
  33688. 0x02, 0xbf, 0x07, 0xe0, 0xac, 0x8b, 0x5b, 0xc6,
  33689. 0x16, 0x2c, 0xf9, 0x46, 0x97, 0xb3, 0xc2, 0x7c,
  33690. 0xd1, 0xfe, 0xa4, 0x9b, 0x27, 0xf2, 0x3b, 0xa2,
  33691. 0x90, 0x18, 0x71, 0x96, 0x25, 0x06, 0x52, 0x0c,
  33692. 0x39, 0x2d, 0xa8, 0xb6, 0xad, 0x0d, 0x99, 0xf7,
  33693. 0x01, 0x3f, 0xbc, 0x06, 0xc2, 0xc1, 0x7a, 0x56,
  33694. 0x95, 0x00, 0xc8, 0xa7, 0x69, 0x64, 0x81, 0xc1,
  33695. 0xcd, 0x33, 0xe9, 0xb1, 0x4e, 0x40, 0xb8, 0x2e,
  33696. 0x79, 0xa5, 0xf5, 0xdb, 0x82, 0x57, 0x1b, 0xa9,
  33697. 0x7b, 0xae, 0x3a, 0xd3, 0xe0, 0x47, 0x95, 0x15,
  33698. 0xbb, 0x0e, 0x2b, 0x0f, 0x3b, 0xfc, 0xd1, 0xfd,
  33699. 0x33, 0x03, 0x4e, 0xfc, 0x62, 0x45, 0xed, 0xdd,
  33700. 0x7e, 0xe2, 0x08, 0x6d, 0xda, 0xe2, 0x60, 0x0d,
  33701. 0x8c, 0xa7, 0x3e, 0x21, 0x4e, 0x8c, 0x2b, 0x0b,
  33702. 0xdb, 0x2b, 0x04, 0x7c, 0x6a, 0x46, 0x4a, 0x56,
  33703. 0x2e, 0xd7, 0x7b, 0x73, 0xd2, 0xd8, 0x41, 0xc4,
  33704. 0xb3, 0x49, 0x73, 0x55, 0x12, 0x57, 0x71, 0x3b,
  33705. 0x75, 0x36, 0x32, 0xef, 0xba, 0x34, 0x81, 0x69,
  33706. 0xab, 0xc9, 0x0a, 0x68, 0xf4, 0x26, 0x11, 0xa4,
  33707. 0x01, 0x26, 0xd7, 0xcb, 0x21, 0xb5, 0x86, 0x95,
  33708. 0x56, 0x81, 0x86, 0xf7, 0xe5, 0x69, 0xd2, 0xff,
  33709. 0x0f, 0x9e, 0x74, 0x5d, 0x04, 0x87, 0xdd, 0x2e,
  33710. 0xb9, 0x97, 0xca, 0xfc, 0x5a, 0xbf, 0x9d, 0xd1,
  33711. 0x02, 0xe6, 0x2f, 0xf6, 0x6c, 0xba, 0x87
  33712. };
  33713. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  33714. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  33715. sizeof(msg2),
  33716. sizeof(msg3),
  33717. 0 /*sizeof(msg1)*/,
  33718. 0 /*sizeof(msg1)*/,
  33719. sizeof(msg4)
  33720. };
  33721. #ifndef NO_ASN
  33722. static const byte privateEd448[] = {
  33723. 0x30, 0x47, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
  33724. 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04, 0x39,
  33725. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33726. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33727. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33728. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33729. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33730. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33731. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33732. 0x5b
  33733. };
  33734. static const byte publicEd448[] = {
  33735. 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
  33736. 0x71, 0x03, 0x3a, 0x00, 0x5f, 0xd7, 0x44, 0x9b,
  33737. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33738. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33739. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33740. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33741. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33742. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33743. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33744. };
  33745. static const byte privPubEd448[] = {
  33746. 0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
  33747. 0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
  33748. 0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
  33749. 0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
  33750. 0xbf, 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c,
  33751. 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48,
  33752. 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
  33753. 0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
  33754. 0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
  33755. 0xf9, 0x5b, 0x81, 0x39, 0x5f, 0xd7, 0x44, 0x9b,
  33756. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33757. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33758. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33759. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33760. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33761. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33762. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33763. };
  33764. word32 idx;
  33765. #endif /* NO_ASN */
  33766. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33767. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33768. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33769. ed448_key *key3 = NULL;
  33770. #else
  33771. ed448_key key3[1];
  33772. #endif
  33773. #endif
  33774. WOLFSSL_ENTER("ed448_test");
  33775. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33776. key = (ed448_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33777. key2 = (ed448_key *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33778. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33779. key3 = (ed448_key *)XMALLOC(sizeof(*key3), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33780. #endif
  33781. #endif
  33782. /* create ed448 keys */
  33783. #ifndef HAVE_FIPS
  33784. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  33785. #else
  33786. ret = wc_InitRng(&rng);
  33787. #endif
  33788. if (ret != 0) {
  33789. XMEMSET(&rng, 0, sizeof(rng));
  33790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33791. }
  33792. ret = wc_ed448_init(key);
  33793. if (ret < 0)
  33794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33795. ret = wc_ed448_init(key2);
  33796. if (ret < 0)
  33797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33798. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33799. ret = wc_ed448_init(key3);
  33800. if (ret < 0)
  33801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33802. #endif
  33803. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key);
  33804. if (ret < 0)
  33805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33806. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2);
  33807. if (ret < 0)
  33808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33809. /* helper functions for signature and key size */
  33810. keySz = (word32)wc_ed448_size(key);
  33811. sigSz = (word32)wc_ed448_sig_size(key);
  33812. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33813. defined(HAVE_ED448_KEY_IMPORT)
  33814. for (i = 0; i < 6; i++) {
  33815. outlen = sizeof(out);
  33816. XMEMSET(out, 0, sizeof(out));
  33817. if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i],
  33818. pKeySz[i], key) != 0)
  33819. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33820. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL,
  33821. 0) != 0)
  33822. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33823. if (XMEMCMP(out, sigs[i], 114))
  33824. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33825. #if defined(HAVE_ED448_VERIFY)
  33826. /* test verify on good msg */
  33827. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33828. NULL, 0) != 0 || verify != 1)
  33829. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33830. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33831. /* test verify on good msg using streaming interface directly */
  33832. if (wc_ed448_verify_msg_init(out, outlen,
  33833. key, (byte)Ed448, NULL, 0) != 0)
  33834. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33835. for (j = 0; j < msgSz[i]; j += i) {
  33836. if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  33837. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33838. }
  33839. if (wc_ed448_verify_msg_final(out, outlen, &verify,
  33840. key) != 0 || verify != 1)
  33841. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33842. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33843. /* test verify on bad msg */
  33844. out[outlen-2] = out[outlen-2] + 1;
  33845. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33846. NULL, 0) == 0 || verify == 1)
  33847. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33848. #endif /* HAVE_ED448_VERIFY */
  33849. /* test api for import/exporting keys */
  33850. {
  33851. word32 exportPSz = ED448_KEY_SIZE;
  33852. word32 exportSSz = ED448_KEY_SIZE;
  33853. #ifdef WOLFSSL_NO_MALLOC
  33854. byte exportPKey[exportPSz];
  33855. byte exportSKey[exportSSz];
  33856. #else
  33857. byte *exportPKey = NULL;
  33858. byte *exportSKey = NULL;
  33859. exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33860. exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33861. if ((exportPKey == NULL) || (exportSKey == NULL))
  33862. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33863. #endif
  33864. ret = 0;
  33865. do {
  33866. if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) {
  33867. ret = WC_TEST_RET_ENC_I(i);
  33868. break;
  33869. }
  33870. if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) {
  33871. ret = WC_TEST_RET_ENC_I(i);
  33872. break;
  33873. }
  33874. if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) {
  33875. ret = WC_TEST_RET_ENC_I(i);
  33876. break;
  33877. }
  33878. if (wc_ed448_import_private_key(exportSKey, exportSSz,
  33879. exportPKey, exportPSz, key2) != 0) {
  33880. ret = WC_TEST_RET_ENC_I(i);
  33881. break;
  33882. }
  33883. /* clear "out" buffer and test sign with imported keys */
  33884. outlen = sizeof(out);
  33885. XMEMSET(out, 0, sizeof(out));
  33886. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL,
  33887. 0) != 0) {
  33888. ret = WC_TEST_RET_ENC_I(i);
  33889. break;
  33890. }
  33891. } while(0);
  33892. #ifndef WOLFSSL_NO_MALLOC
  33893. XFREE(exportPKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33894. XFREE(exportSKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33895. #endif
  33896. if (ret != 0)
  33897. goto out;
  33898. }
  33899. #if defined(HAVE_ED448_VERIFY)
  33900. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2,
  33901. NULL, 0) != 0 || verify != 1)
  33902. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33903. if (XMEMCMP(out, sigs[i], SIGSZ))
  33904. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33905. #endif /* HAVE_ED448_VERIFY */
  33906. }
  33907. ret = ed448_ctx_test();
  33908. if (ret != 0)
  33909. goto out;
  33910. ret = ed448ph_test();
  33911. if (ret != 0)
  33912. goto out;
  33913. #ifndef NO_ASN
  33914. /* Try ASN.1 encoded private-only key and public key. */
  33915. idx = 0;
  33916. ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3,
  33917. sizeof(privateEd448));
  33918. if (ret != 0)
  33919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33920. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33921. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  33922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33923. idx = 0;
  33924. ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448));
  33925. if (ret != 0)
  33926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33927. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33928. if (ret != 0)
  33929. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33930. if (XMEMCMP(out, sigs[0], SIGSZ))
  33931. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33932. #if defined(HAVE_ED448_VERIFY)
  33933. /* test verify on good msg */
  33934. ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3,
  33935. NULL, 0);
  33936. if (ret != 0 || verify != 1)
  33937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33938. #endif /* HAVE_ED448_VERIFY */
  33939. wc_ed448_free(key3);
  33940. ret = wc_ed448_init(key3);
  33941. if (ret < 0)
  33942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33943. idx = 0;
  33944. ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3,
  33945. sizeof(privPubEd448));
  33946. if (ret != 0)
  33947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33948. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33949. if (ret != 0)
  33950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33951. if (XMEMCMP(out, sigs[0], SIGSZ))
  33952. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33953. #endif /* NO_ASN */
  33954. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33955. ret = 0;
  33956. out:
  33957. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33958. if (key) {
  33959. wc_ed448_free(key);
  33960. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33961. }
  33962. if (key2) {
  33963. wc_ed448_free(key2);
  33964. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33965. }
  33966. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33967. if (key3) {
  33968. wc_ed448_free(key3);
  33969. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33970. }
  33971. #endif
  33972. #else
  33973. wc_ed448_free(key);
  33974. wc_ed448_free(key2);
  33975. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33976. wc_ed448_free(key3);
  33977. #endif
  33978. #endif
  33979. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  33980. wc_FreeRng(&rng);
  33981. #endif
  33982. if (ret < 0)
  33983. return ret;
  33984. /* hush warnings of unused keySz and sigSz */
  33985. (void)keySz;
  33986. (void)sigSz;
  33987. ret = ed448_test_check_key();
  33988. if (ret < 0)
  33989. return ret;
  33990. #ifdef WOLFSSL_TEST_CERT
  33991. ret = ed448_test_cert();
  33992. if (ret < 0)
  33993. return ret;
  33994. #ifdef WOLFSSL_CERT_GEN
  33995. ret = ed448_test_make_cert();
  33996. if (ret < 0)
  33997. return ret;
  33998. #endif /* WOLFSSL_CERT_GEN */
  33999. #endif /* WOLFSSL_TEST_CERT */
  34000. return 0;
  34001. }
  34002. #endif /* HAVE_ED448 */
  34003. #ifdef WOLFSSL_HAVE_KYBER
  34004. #ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
  34005. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  34006. static wc_test_ret_t kyber512_kat(void)
  34007. {
  34008. wc_test_ret_t ret;
  34009. #ifdef WOLFSSL_SMALL_STACK
  34010. KyberKey *key = NULL;
  34011. byte *priv = NULL;
  34012. byte *pub = NULL;
  34013. byte *ct = NULL;
  34014. byte *ss = NULL;
  34015. byte *ss_dec = NULL;
  34016. #else
  34017. KyberKey key[1];
  34018. byte priv[KYBER512_PRIVATE_KEY_SIZE];
  34019. byte pub[KYBER512_PUBLIC_KEY_SIZE];
  34020. byte ct[KYBER512_CIPHER_TEXT_SIZE];
  34021. byte ss[KYBER_SS_SZ];
  34022. byte ss_dec[KYBER_SS_SZ];
  34023. #endif
  34024. int key_inited = 0;
  34025. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_rand[] = {
  34026. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34027. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34028. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34029. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34030. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34031. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34032. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34033. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34034. };
  34035. WOLFSSL_SMALL_STACK_STATIC const byte kyber512enc_rand[] = {
  34036. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34037. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34038. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34039. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34040. };
  34041. #ifdef WOLFSSL_KYBER_ORIGINAL
  34042. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_pk[] = {
  34043. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34044. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34045. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34046. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34047. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34048. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34049. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34050. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34051. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34052. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34053. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34054. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34055. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34056. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34057. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34058. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34059. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34060. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34061. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34062. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34063. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34064. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34065. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34066. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34067. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34068. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34069. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34070. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34071. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34072. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34073. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34074. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34075. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34076. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34077. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34078. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34079. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34080. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34081. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34082. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34083. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34084. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34085. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34086. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34087. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34088. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34089. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34090. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34091. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34092. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34093. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34094. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34095. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34096. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34097. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34098. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34099. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34100. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34101. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34102. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34103. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34104. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34105. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34106. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34107. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34108. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34109. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34110. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34111. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34112. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34113. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34114. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34115. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34116. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34117. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34118. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34119. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34120. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34121. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34122. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34123. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34124. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34125. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34126. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34127. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34128. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34129. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34130. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34131. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34132. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34133. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34134. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34135. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34136. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34137. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34138. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34139. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34140. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34141. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34142. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  34143. };
  34144. #endif
  34145. #ifndef WOLFSSL_NO_ML_KEM
  34146. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_pk[] = {
  34147. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34148. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34149. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34150. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34151. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34152. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34153. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34154. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34155. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34156. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34157. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34158. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34159. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34160. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34161. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34162. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34163. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34164. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34165. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34166. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34167. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34168. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34169. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34170. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34171. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34172. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34173. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34174. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34175. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34176. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34177. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34178. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34179. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34180. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34181. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34182. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34183. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34184. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34185. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34186. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34187. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34188. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34189. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34190. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34191. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34192. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34193. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34194. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34195. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34196. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34197. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34198. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34199. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34200. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34201. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34202. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34203. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34204. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34205. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34206. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34207. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34208. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34209. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34210. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34211. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34212. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34213. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34214. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34215. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34216. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34217. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34218. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34219. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34220. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34221. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34222. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34223. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34224. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34225. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34226. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34227. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34228. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34229. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34230. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34231. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34232. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34233. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34234. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34235. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34236. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34237. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34238. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34239. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34240. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34241. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34242. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34243. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34244. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34245. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34246. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39
  34247. };
  34248. #endif
  34249. #ifdef WOLFSSL_KYBER_ORIGINAL
  34250. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_sk[] = {
  34251. 0x6C, 0x89, 0x2B, 0x02, 0x97, 0xA9, 0xC7, 0x64,
  34252. 0x14, 0x93, 0xF8, 0x7D, 0xAF, 0x35, 0x33, 0xEE,
  34253. 0xD6, 0x1F, 0x07, 0xF4, 0x65, 0x20, 0x66, 0x33,
  34254. 0x7E, 0xD7, 0x40, 0x46, 0xDC, 0xC7, 0x1B, 0xA0,
  34255. 0x3F, 0x30, 0x96, 0x01, 0x03, 0x16, 0x1F, 0x7D,
  34256. 0xEB, 0x53, 0xA7, 0x1B, 0x11, 0x61, 0x72, 0x63,
  34257. 0xFE, 0x2A, 0x80, 0x97, 0x69, 0xCE, 0x6D, 0x70,
  34258. 0xA8, 0x5F, 0xE6, 0x00, 0xEC, 0xE2, 0x9D, 0x7F,
  34259. 0x36, 0xA1, 0x6D, 0x33, 0x1B, 0x8B, 0x2A, 0x9E,
  34260. 0x1D, 0xB8, 0xC0, 0x90, 0x74, 0x2D, 0xF0, 0x73,
  34261. 0x9F, 0xF0, 0x60, 0xCE, 0xB4, 0xEC, 0xC5, 0xAB,
  34262. 0x1C, 0x5E, 0x55, 0xAC, 0x97, 0xBB, 0x66, 0xA7,
  34263. 0xF8, 0x95, 0x10, 0x5D, 0x57, 0x78, 0x2B, 0x22,
  34264. 0x95, 0x38, 0xE3, 0x42, 0x15, 0x44, 0xA3, 0x42,
  34265. 0x14, 0x08, 0xDB, 0xF4, 0x49, 0x10, 0x93, 0x4C,
  34266. 0xC4, 0x23, 0x77, 0x4F, 0x16, 0x76, 0xFF, 0x1C,
  34267. 0x30, 0x6F, 0x97, 0x55, 0x5F, 0x57, 0xB4, 0xAE,
  34268. 0xD7, 0xA6, 0xBA, 0xB9, 0x50, 0xA8, 0x16, 0x3C,
  34269. 0x8D, 0x31, 0x8D, 0xEA, 0x62, 0x75, 0x1B, 0xD6,
  34270. 0xAB, 0xC5, 0x06, 0x9C, 0x06, 0xC8, 0x8F, 0x33,
  34271. 0x00, 0x26, 0xA1, 0x98, 0x06, 0xA0, 0x3B, 0x97,
  34272. 0xA7, 0x69, 0x6B, 0x56, 0xDA, 0x21, 0x82, 0x7B,
  34273. 0xB4, 0xE8, 0xDC, 0x03, 0x11, 0x52, 0xB4, 0x1B,
  34274. 0x89, 0x2A, 0x9E, 0x99, 0xAD, 0xF6, 0xE1, 0x96,
  34275. 0x3E, 0x96, 0x57, 0x88, 0x28, 0x15, 0x4F, 0x46,
  34276. 0x70, 0x33, 0x84, 0x69, 0x20, 0xFB, 0xB4, 0xB8,
  34277. 0x05, 0x44, 0xE7, 0xE8, 0xA8, 0x1A, 0xE9, 0x63,
  34278. 0xCF, 0x36, 0x8C, 0x9B, 0xA0, 0x37, 0xA8, 0xC2,
  34279. 0xAD, 0x62, 0xE3, 0x2B, 0x6E, 0x61, 0xC9, 0x1D,
  34280. 0x75, 0xCE, 0x00, 0x5A, 0xB3, 0x0F, 0x80, 0x99,
  34281. 0xA1, 0xF2, 0x9D, 0x7B, 0x63, 0x05, 0xB4, 0xDC,
  34282. 0x06, 0xE2, 0x56, 0x80, 0xBB, 0x00, 0x99, 0x2F,
  34283. 0x71, 0x7F, 0xE6, 0xC1, 0x15, 0xA8, 0x08, 0x42,
  34284. 0x31, 0xCC, 0x79, 0xDD, 0x70, 0x0E, 0xA6, 0x91,
  34285. 0x2A, 0xC7, 0xFA, 0x0D, 0x93, 0x7B, 0xB6, 0xA7,
  34286. 0x56, 0x66, 0x22, 0x30, 0x47, 0x0C, 0x18, 0x9B,
  34287. 0x5A, 0xA1, 0x65, 0x3D, 0xEB, 0x93, 0x7D, 0x5A,
  34288. 0x9C, 0x25, 0xA2, 0x1D, 0x93, 0xB1, 0x90, 0x74,
  34289. 0xFC, 0x23, 0x9D, 0x81, 0x53, 0x53, 0x97, 0x97,
  34290. 0xC7, 0xD4, 0xAB, 0x62, 0x64, 0x9D, 0x76, 0xAA,
  34291. 0x55, 0x37, 0x36, 0xA9, 0x49, 0x02, 0x2C, 0x22,
  34292. 0xC5, 0x2B, 0xAE, 0xEC, 0x60, 0x5B, 0x32, 0xCE,
  34293. 0x9E, 0x5B, 0x93, 0x84, 0x90, 0x35, 0x58, 0xCA,
  34294. 0x9D, 0x6A, 0x3A, 0xBA, 0x90, 0x42, 0x3E, 0xED,
  34295. 0xA0, 0x1C, 0x94, 0x19, 0x8B, 0x19, 0x2A, 0x8B,
  34296. 0xA9, 0x06, 0x34, 0x97, 0xA0, 0xC5, 0x01, 0x33,
  34297. 0x07, 0xDD, 0xD8, 0x63, 0x52, 0x64, 0x71, 0xA4,
  34298. 0xD9, 0x95, 0x23, 0xEB, 0x41, 0x7F, 0x29, 0x1A,
  34299. 0xAC, 0x0C, 0x3A, 0x58, 0x1B, 0x6D, 0xA0, 0x07,
  34300. 0x32, 0xE5, 0xE8, 0x1B, 0x1F, 0x7C, 0x87, 0x9B,
  34301. 0x16, 0x93, 0xC1, 0x3B, 0x6F, 0x9F, 0x79, 0x31,
  34302. 0x62, 0x24, 0x29, 0xE5, 0x42, 0xAF, 0x40, 0x69,
  34303. 0x22, 0x2F, 0x04, 0x55, 0x44, 0xE0, 0xCC, 0x4F,
  34304. 0xB2, 0x4D, 0x44, 0x48, 0xCF, 0x2C, 0x65, 0x96,
  34305. 0xF5, 0xCB, 0x08, 0x62, 0x4B, 0x11, 0x85, 0x01,
  34306. 0x3B, 0x6B, 0x02, 0x08, 0x92, 0xF9, 0x6B, 0xDF,
  34307. 0xD4, 0xAD, 0xA9, 0x17, 0x9D, 0xE7, 0x27, 0xB8,
  34308. 0xD9, 0x42, 0x6E, 0x09, 0x96, 0xB5, 0xD3, 0x49,
  34309. 0x48, 0xCE, 0x02, 0xD0, 0xC3, 0x69, 0xB3, 0x7C,
  34310. 0xBB, 0x54, 0xD3, 0x47, 0x9E, 0xD8, 0xB5, 0x82,
  34311. 0xE9, 0xE7, 0x28, 0x92, 0x9B, 0x4C, 0x71, 0xC9,
  34312. 0xBE, 0x11, 0xD4, 0x5B, 0x20, 0xC4, 0xBD, 0xC3,
  34313. 0xC7, 0x43, 0x13, 0x22, 0x3F, 0x58, 0x27, 0x4E,
  34314. 0x8B, 0xA5, 0x24, 0x44, 0x47, 0xC4, 0x95, 0x95,
  34315. 0x0B, 0x84, 0xCB, 0x0C, 0x3C, 0x27, 0x36, 0x40,
  34316. 0x10, 0x8A, 0x33, 0x97, 0x94, 0x45, 0x73, 0x27,
  34317. 0x93, 0x28, 0x99, 0x6C, 0xDC, 0x0C, 0x91, 0x3C,
  34318. 0x95, 0x8A, 0xD6, 0x20, 0xBA, 0x8B, 0x5E, 0x5E,
  34319. 0xCB, 0xBB, 0x7E, 0x13, 0xCB, 0x9C, 0x70, 0xBD,
  34320. 0x5A, 0xB3, 0x0E, 0xB7, 0x48, 0x8C, 0x97, 0x00,
  34321. 0x1C, 0x20, 0x49, 0x8F, 0x1D, 0x7C, 0xC0, 0x6D,
  34322. 0xA7, 0x6B, 0xF5, 0x20, 0xC6, 0x58, 0xCC, 0xAD,
  34323. 0xFA, 0x29, 0x56, 0x42, 0x45, 0x57, 0xAB, 0xEA,
  34324. 0x8A, 0xB8, 0x92, 0x39, 0xC1, 0x78, 0x33, 0xDC,
  34325. 0x3A, 0x49, 0xB3, 0x6A, 0x9A, 0xE9, 0xA4, 0x86,
  34326. 0x94, 0x05, 0x40, 0xEB, 0x44, 0x4F, 0x97, 0x15,
  34327. 0x23, 0x57, 0xE0, 0x20, 0x35, 0x93, 0x9D, 0x75,
  34328. 0xA3, 0xC0, 0x25, 0xF4, 0x1A, 0x40, 0x08, 0x23,
  34329. 0x82, 0xA0, 0x73, 0x3C, 0x39, 0xB0, 0x62, 0x2B,
  34330. 0x74, 0x0E, 0x40, 0x75, 0x92, 0xC6, 0x2E, 0xCA,
  34331. 0xEB, 0x14, 0x32, 0xC4, 0x45, 0xB3, 0x70, 0x3A,
  34332. 0x86, 0xF6, 0x98, 0x1A, 0x27, 0x81, 0x57, 0xEA,
  34333. 0x95, 0xA6, 0xE9, 0x2D, 0x55, 0xE4, 0xB9, 0x72,
  34334. 0xF9, 0x36, 0xC2, 0xF0, 0xA6, 0x58, 0x28, 0x0E,
  34335. 0xA2, 0xB0, 0x7A, 0x48, 0x99, 0x2D, 0xF8, 0x93,
  34336. 0x7E, 0x0A, 0x2A, 0xC1, 0xDC, 0xC9, 0x74, 0xFE,
  34337. 0x00, 0xAA, 0xE1, 0xF5, 0x61, 0xFA, 0x25, 0x8E,
  34338. 0x2D, 0x25, 0x9C, 0x3E, 0x86, 0x1D, 0xCE, 0x23,
  34339. 0x60, 0x39, 0x12, 0x76, 0x06, 0xFC, 0x1C, 0xE0,
  34340. 0x09, 0x00, 0x3A, 0x7B, 0xAC, 0x94, 0x21, 0x01,
  34341. 0xDC, 0xB8, 0x22, 0xB1, 0xF3, 0xC1, 0x2B, 0xF7,
  34342. 0x32, 0x38, 0xF5, 0x46, 0xE0, 0x1C, 0x36, 0xB5,
  34343. 0xA6, 0x93, 0x61, 0x92, 0x99, 0x5C, 0xC6, 0x9C,
  34344. 0x63, 0x23, 0x74, 0x09, 0xCB, 0x53, 0xC2, 0xE3,
  34345. 0x5D, 0x74, 0x89, 0x0D, 0x18, 0x88, 0x53, 0x76,
  34346. 0xFA, 0x55, 0x03, 0xB1, 0x07, 0xA2, 0xA3, 0x92,
  34347. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34348. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34349. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34350. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34351. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34352. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34353. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34354. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34355. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34356. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34357. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34358. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34359. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34360. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34361. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34362. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34363. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34364. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34365. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34366. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34367. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34368. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34369. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34370. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34371. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34372. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34373. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34374. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34375. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34376. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34377. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34378. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34379. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34380. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34381. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34382. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34383. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34384. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34385. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34386. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34387. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34388. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34389. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34390. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34391. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34392. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34393. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34394. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34395. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34396. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34397. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34398. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34399. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34400. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34401. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34402. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34403. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34404. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34405. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34406. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34407. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34408. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34409. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34410. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34411. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34412. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34413. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34414. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34415. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34416. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34417. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34418. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34419. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34420. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34421. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34422. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34423. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34424. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34425. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34426. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34427. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34428. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34429. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34430. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34431. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34432. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34433. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34434. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34435. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34436. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34437. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34438. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34439. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34440. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34441. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34442. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34443. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34444. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34445. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34446. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  34447. 0x7F, 0xFA, 0xD1, 0xBC, 0x8A, 0xF7, 0x3B, 0x7E,
  34448. 0x87, 0x49, 0x56, 0xB8, 0x1C, 0x2A, 0x2E, 0xF0,
  34449. 0xBF, 0xAB, 0xE8, 0xDC, 0x93, 0xD7, 0x7B, 0x2F,
  34450. 0xBC, 0x9E, 0x0C, 0x64, 0xEF, 0xA0, 0x1E, 0x84,
  34451. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34452. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34453. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34454. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34455. };
  34456. #endif
  34457. #ifndef WOLFSSL_NO_ML_KEM
  34458. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_sk[] = {
  34459. 0x9c, 0xda, 0x16, 0x86, 0xa3, 0x39, 0x6a, 0x7c,
  34460. 0x10, 0x9b, 0x41, 0x52, 0x89, 0xf5, 0x6a, 0x9e,
  34461. 0xc4, 0x4c, 0xd5, 0xb9, 0xb6, 0x74, 0xc3, 0x8a,
  34462. 0x3b, 0xba, 0xb3, 0x0a, 0x2c, 0x90, 0xf0, 0x04,
  34463. 0x37, 0xa2, 0x64, 0xb0, 0xbe, 0x9a, 0x1e, 0x8b,
  34464. 0xa8, 0x87, 0xd3, 0xc3, 0xb1, 0x00, 0x89, 0x80,
  34465. 0x54, 0x27, 0x2f, 0x94, 0x1c, 0x88, 0xa1, 0xf2,
  34466. 0x08, 0xf1, 0xc9, 0x14, 0xf9, 0x64, 0xc1, 0xaa,
  34467. 0xd6, 0x13, 0xa6, 0xa8, 0x4f, 0x88, 0xe4, 0x2d,
  34468. 0x35, 0x56, 0x83, 0x5f, 0xb1, 0x61, 0xfd, 0xc5,
  34469. 0xcd, 0x15, 0xa3, 0xbc, 0x7e, 0x74, 0xb6, 0xf2,
  34470. 0x61, 0x2f, 0xa8, 0x27, 0x1c, 0x7e, 0xa1, 0x12,
  34471. 0xb0, 0x5c, 0x2a, 0x36, 0xcc, 0x70, 0x7c, 0xe3,
  34472. 0x8d, 0x5d, 0x1a, 0xcc, 0x51, 0x15, 0x46, 0x2a,
  34473. 0x8c, 0x1a, 0xab, 0xf0, 0x72, 0x76, 0xc7, 0x23,
  34474. 0x18, 0x33, 0x7f, 0x74, 0xb5, 0xcb, 0xef, 0xea,
  34475. 0x7a, 0x80, 0x37, 0x90, 0xbc, 0x03, 0x93, 0xf3,
  34476. 0xa5, 0x4c, 0x72, 0x4a, 0x57, 0x65, 0xa4, 0x8f,
  34477. 0x29, 0x6b, 0x03, 0xf4, 0x84, 0x37, 0x60, 0x23,
  34478. 0x62, 0x69, 0x30, 0x22, 0x27, 0x04, 0xc0, 0x8f,
  34479. 0xd3, 0xbc, 0x72, 0x93, 0x15, 0xd1, 0xfc, 0x70,
  34480. 0xeb, 0x79, 0x75, 0xa9, 0x7b, 0x9d, 0xee, 0xd1,
  34481. 0x62, 0xf4, 0x86, 0xbb, 0xc6, 0x4a, 0x09, 0x71,
  34482. 0x11, 0x95, 0x2d, 0x89, 0xb5, 0x7d, 0x76, 0x5e,
  34483. 0x8a, 0x99, 0x1a, 0x2e, 0x56, 0x42, 0x06, 0xea,
  34484. 0x7b, 0xf5, 0xe4, 0x00, 0x7a, 0x66, 0x35, 0x88,
  34485. 0x31, 0xca, 0x0e, 0x34, 0xb2, 0xf6, 0xa8, 0x4d,
  34486. 0x10, 0xf7, 0x9c, 0x47, 0x7c, 0xb6, 0x6a, 0x8a,
  34487. 0x95, 0x25, 0x69, 0x36, 0x73, 0x88, 0x13, 0x0d,
  34488. 0x7b, 0x97, 0x4a, 0x63, 0xaa, 0x51, 0x99, 0x6c,
  34489. 0x97, 0x70, 0x9b, 0xb8, 0xea, 0xbc, 0x94, 0xe6,
  34490. 0xa5, 0x35, 0xd7, 0x92, 0xd2, 0x90, 0x54, 0x74,
  34491. 0x95, 0x2d, 0x6b, 0x8c, 0x22, 0x22, 0xb2, 0xae,
  34492. 0x56, 0xdc, 0x66, 0xfb, 0x04, 0x61, 0x19, 0x20,
  34493. 0x66, 0xcd, 0xdb, 0x43, 0xec, 0x05, 0x98, 0x4f,
  34494. 0xb4, 0x98, 0x26, 0x49, 0x77, 0x13, 0x97, 0xc6,
  34495. 0xa8, 0x37, 0x9f, 0x3b, 0x56, 0x43, 0x06, 0x98,
  34496. 0x48, 0x87, 0x59, 0x19, 0xe8, 0x9c, 0xc4, 0x39,
  34497. 0xa3, 0xbe, 0x2f, 0x08, 0x14, 0x90, 0xf3, 0x41,
  34498. 0xbd, 0x12, 0x40, 0xad, 0xd8, 0x0d, 0xdb, 0x8c,
  34499. 0x99, 0x63, 0xb4, 0x7a, 0x2a, 0x09, 0x92, 0x29,
  34500. 0x03, 0x38, 0xda, 0x9c, 0x3b, 0x72, 0x5c, 0x6d,
  34501. 0xa4, 0x47, 0x18, 0xc0, 0x10, 0x46, 0x81, 0x25,
  34502. 0x62, 0xaf, 0xb0, 0x84, 0x83, 0x7a, 0xcb, 0x3c,
  34503. 0x57, 0x5e, 0x4f, 0x93, 0x93, 0x6c, 0x35, 0x2a,
  34504. 0xc0, 0xe7, 0x0a, 0xa3, 0x84, 0x5e, 0xe4, 0x85,
  34505. 0x29, 0x6e, 0x6b, 0x02, 0xde, 0x0b, 0x47, 0xb5,
  34506. 0xc4, 0xc9, 0x6b, 0x0b, 0x7c, 0xf9, 0x4c, 0x4a,
  34507. 0xbe, 0x95, 0x48, 0x61, 0x53, 0x11, 0x8e, 0x43,
  34508. 0xc2, 0xb9, 0xc8, 0x4d, 0x9d, 0xa9, 0x1c, 0x6c,
  34509. 0x5a, 0xcd, 0x5a, 0x57, 0x00, 0x2d, 0x05, 0x84,
  34510. 0x97, 0x99, 0x27, 0x99, 0xe5, 0xba, 0x1c, 0xe6,
  34511. 0xc2, 0x5e, 0xb2, 0x98, 0x44, 0xd8, 0x58, 0xba,
  34512. 0x1c, 0x37, 0x85, 0x0c, 0x0c, 0x2f, 0x57, 0xc6,
  34513. 0x0d, 0xe3, 0x7f, 0x77, 0xc0, 0x82, 0xec, 0x14,
  34514. 0x49, 0x4e, 0xba, 0x28, 0x8a, 0x65, 0x91, 0x51,
  34515. 0x16, 0xc2, 0x0a, 0x32, 0x5d, 0xe3, 0x1a, 0xaa,
  34516. 0xdd, 0x68, 0x0d, 0xb1, 0x9c, 0x0c, 0xfc, 0xc3,
  34517. 0x46, 0x0f, 0x0a, 0xa0, 0x1a, 0x87, 0xa6, 0xa5,
  34518. 0x80, 0xc6, 0xca, 0x29, 0x1f, 0xae, 0xf0, 0xcc,
  34519. 0xc4, 0x9b, 0x76, 0xa8, 0xda, 0xc4, 0xf9, 0xd4,
  34520. 0x16, 0x40, 0x50, 0x9d, 0xbd, 0x0b, 0x40, 0x45,
  34521. 0xc1, 0x53, 0x0e, 0xd3, 0x47, 0x55, 0xd4, 0x74,
  34522. 0x62, 0x70, 0x0f, 0x2a, 0x8c, 0xaf, 0x96, 0x80,
  34523. 0xa6, 0xd7, 0xe3, 0x8a, 0x7e, 0x2a, 0x63, 0xe9,
  34524. 0x37, 0x65, 0x0a, 0x23, 0x30, 0x6d, 0x85, 0x5d,
  34525. 0xa2, 0xa2, 0xb7, 0xef, 0x50, 0x5c, 0xa5, 0x96,
  34526. 0xab, 0x04, 0x85, 0x01, 0x3e, 0xa9, 0x27, 0xc7,
  34527. 0x34, 0x23, 0x43, 0x61, 0x36, 0x43, 0xba, 0x40,
  34528. 0x07, 0xd6, 0xc8, 0x74, 0xb9, 0x80, 0xc7, 0x9c,
  34529. 0x3a, 0xa1, 0xc7, 0x4f, 0x85, 0x81, 0xc3, 0x48,
  34530. 0x49, 0xb3, 0x6e, 0xa7, 0x98, 0x15, 0xfb, 0xb4,
  34531. 0xcc, 0xf9, 0x61, 0x05, 0x83, 0x08, 0x1d, 0x7c,
  34532. 0x5b, 0x44, 0x09, 0xb8, 0xd0, 0x53, 0x1c, 0x04,
  34533. 0xbc, 0xaf, 0x7c, 0xc7, 0x51, 0x10, 0x3a, 0x5f,
  34534. 0xd1, 0xba, 0x44, 0x70, 0x83, 0x3e, 0x89, 0x77,
  34535. 0x5a, 0xde, 0xd9, 0x70, 0xb5, 0x47, 0x18, 0x59,
  34536. 0x25, 0x0f, 0xe7, 0x26, 0x71, 0x05, 0x83, 0x5f,
  34537. 0x39, 0x00, 0x30, 0xc5, 0xe7, 0xcd, 0x3f, 0x96,
  34538. 0x10, 0x19, 0xea, 0xae, 0xa2, 0x37, 0x77, 0xd3,
  34539. 0x47, 0xbb, 0x2a, 0xdc, 0xb6, 0x73, 0xc0, 0x20,
  34540. 0x34, 0xf3, 0x94, 0x34, 0x22, 0x71, 0xbc, 0xea,
  34541. 0x64, 0x14, 0xe5, 0x46, 0xc3, 0xb2, 0x0b, 0xd5,
  34542. 0x74, 0x81, 0xc7, 0xea, 0x14, 0xc7, 0x7c, 0x38,
  34543. 0x8c, 0xc8, 0x62, 0x51, 0xc1, 0x25, 0x58, 0xb1,
  34544. 0x00, 0xf8, 0xc5, 0xb3, 0xd0, 0x3c, 0xa2, 0xc7,
  34545. 0x07, 0x13, 0x90, 0x96, 0x59, 0xc8, 0xba, 0x26,
  34546. 0xd0, 0xd1, 0x76, 0x5e, 0x0b, 0xc8, 0x23, 0xd6,
  34547. 0x8c, 0xa5, 0x57, 0x0d, 0xe6, 0x00, 0xcd, 0x09,
  34548. 0x41, 0x72, 0x5d, 0x38, 0x6e, 0x14, 0xc1, 0x01,
  34549. 0x2d, 0xf5, 0x95, 0x1b, 0xeb, 0x8d, 0x82, 0x81,
  34550. 0xa4, 0xf6, 0x81, 0x5d, 0x37, 0x60, 0xb7, 0x64,
  34551. 0x29, 0x5a, 0xd0, 0x40, 0x6c, 0x2b, 0xf7, 0x92,
  34552. 0x8a, 0xd6, 0x50, 0x32, 0xb6, 0x5f, 0x14, 0xb7,
  34553. 0x7c, 0xcb, 0x89, 0x17, 0xc9, 0x3a, 0x29, 0xd6,
  34554. 0x28, 0x7d, 0x8a, 0x60, 0x62, 0x39, 0x9c, 0xb6,
  34555. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34556. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34557. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34558. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34559. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34560. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34561. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34562. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34563. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34564. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34565. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34566. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34567. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34568. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34569. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34570. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34571. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34572. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34573. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34574. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34575. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34576. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34577. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34578. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34579. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34580. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34581. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34582. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34583. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34584. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34585. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34586. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34587. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34588. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34589. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34590. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34591. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34592. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34593. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34594. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34595. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34596. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34597. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34598. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34599. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34600. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34601. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34602. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34603. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34604. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34605. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34606. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34607. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34608. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34609. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34610. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34611. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34612. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34613. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34614. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34615. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34616. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34617. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34618. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34619. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34620. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34621. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34622. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34623. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34624. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34625. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34626. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34627. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34628. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34629. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34630. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34631. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34632. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34633. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34634. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34635. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34636. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34637. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34638. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34639. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34640. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34641. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34642. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34643. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34644. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34645. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34646. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34647. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34648. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34649. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34650. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34651. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34652. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34653. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34654. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39,
  34655. 0x50, 0xc8, 0xdd, 0x15, 0x2a, 0x45, 0x31, 0xaa,
  34656. 0xb5, 0x60, 0xd2, 0xfc, 0x7c, 0xa9, 0xa4, 0x0a,
  34657. 0xd8, 0xaf, 0x25, 0xad, 0x1d, 0xd0, 0x8c, 0x6d,
  34658. 0x79, 0xaf, 0xe4, 0xdd, 0x4d, 0x1e, 0xee, 0x5a,
  34659. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  34660. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  34661. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  34662. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  34663. };
  34664. #endif
  34665. #ifdef WOLFSSL_KYBER_ORIGINAL
  34666. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ct[] = {
  34667. 0xED, 0xF2, 0x41, 0x45, 0xE4, 0x3B, 0x4F, 0x6D,
  34668. 0xC6, 0xBF, 0x83, 0x32, 0xF5, 0x4E, 0x02, 0xCA,
  34669. 0xB0, 0x2D, 0xBF, 0x3B, 0x56, 0x05, 0xDD, 0xC9,
  34670. 0x0A, 0x15, 0xC8, 0x86, 0xAD, 0x3E, 0xD4, 0x89,
  34671. 0x46, 0x26, 0x99, 0xE4, 0xAB, 0xED, 0x44, 0x35,
  34672. 0x0B, 0xC3, 0x75, 0x7E, 0x26, 0x96, 0xFB, 0xFB,
  34673. 0x25, 0x34, 0x41, 0x2E, 0x8D, 0xD2, 0x01, 0xF1,
  34674. 0xE4, 0x54, 0x0A, 0x39, 0x70, 0xB0, 0x55, 0xFE,
  34675. 0x3B, 0x0B, 0xEC, 0x3A, 0x71, 0xF9, 0xE1, 0x15,
  34676. 0xB3, 0xF9, 0xF3, 0x91, 0x02, 0x06, 0x5B, 0x1C,
  34677. 0xCA, 0x83, 0x14, 0xDC, 0xC7, 0x95, 0xE3, 0xC0,
  34678. 0xE8, 0xFA, 0x98, 0xEE, 0x83, 0xCA, 0x66, 0x28,
  34679. 0x45, 0x70, 0x28, 0xA4, 0xD0, 0x9E, 0x83, 0x9E,
  34680. 0x55, 0x48, 0x62, 0xCF, 0x0B, 0x7B, 0xF5, 0x6C,
  34681. 0x5C, 0x0A, 0x82, 0x9E, 0x86, 0x57, 0x94, 0x79,
  34682. 0x45, 0xFE, 0x9C, 0x22, 0x56, 0x4F, 0xBA, 0xEB,
  34683. 0xC1, 0xB3, 0xAF, 0x35, 0x0D, 0x79, 0x55, 0x50,
  34684. 0x8A, 0x26, 0xD8, 0xA8, 0xEB, 0x54, 0x7B, 0x8B,
  34685. 0x1A, 0x2C, 0xF0, 0x3C, 0xCA, 0x1A, 0xAB, 0xCE,
  34686. 0x6C, 0x34, 0x97, 0x78, 0x3B, 0x64, 0x65, 0xBA,
  34687. 0x0B, 0x6E, 0x7A, 0xCB, 0xA8, 0x21, 0x19, 0x51,
  34688. 0x24, 0xAE, 0xF0, 0x9E, 0x62, 0x83, 0x82, 0xA1,
  34689. 0xF9, 0x14, 0x04, 0x3B, 0xE7, 0x09, 0x6E, 0x95,
  34690. 0x2C, 0xBC, 0x4F, 0xB4, 0xAF, 0xED, 0x13, 0x60,
  34691. 0x90, 0x46, 0x11, 0x7C, 0x01, 0x1F, 0xD7, 0x41,
  34692. 0xEE, 0x28, 0x6C, 0x83, 0x77, 0x16, 0x90, 0xF0,
  34693. 0xAE, 0xB5, 0x0D, 0xA0, 0xD7, 0x12, 0x85, 0xA1,
  34694. 0x79, 0xB2, 0x15, 0xC6, 0x03, 0x6D, 0xEB, 0x78,
  34695. 0x0F, 0x4D, 0x16, 0x76, 0x9F, 0x72, 0xDE, 0x16,
  34696. 0xFD, 0xAD, 0xAC, 0x73, 0xBE, 0xFA, 0x5B, 0xEF,
  34697. 0x89, 0x43, 0x19, 0x7F, 0x44, 0xC5, 0x95, 0x89,
  34698. 0xDC, 0x9F, 0x49, 0x73, 0xDE, 0x14, 0x50, 0xBA,
  34699. 0x1D, 0x0C, 0x32, 0x90, 0xD6, 0xB1, 0xD6, 0x83,
  34700. 0xF2, 0x94, 0xE7, 0x59, 0xC9, 0x54, 0xAB, 0xE8,
  34701. 0xA7, 0xDA, 0x5B, 0x10, 0x54, 0xFD, 0x6D, 0x21,
  34702. 0x32, 0x9B, 0x8E, 0x73, 0xD3, 0x75, 0x6A, 0xFD,
  34703. 0xA0, 0xDC, 0xB1, 0xFC, 0x8B, 0x15, 0x82, 0xD1,
  34704. 0xF9, 0x0C, 0xF2, 0x75, 0xA1, 0x02, 0xAB, 0xC6,
  34705. 0xAC, 0x69, 0x9D, 0xF0, 0xC5, 0x87, 0x0E, 0x50,
  34706. 0xA1, 0xF9, 0x89, 0xE4, 0xE6, 0x24, 0x1B, 0x60,
  34707. 0xAA, 0xA2, 0xEC, 0xF9, 0xE8, 0xE3, 0x3E, 0x0F,
  34708. 0xFC, 0xF4, 0x0F, 0xE8, 0x31, 0xE8, 0xFD, 0xC2,
  34709. 0xE8, 0x3B, 0x52, 0xCA, 0x7A, 0xB6, 0xD9, 0x3F,
  34710. 0x14, 0x6D, 0x29, 0xDC, 0xA5, 0x3C, 0x7D, 0xA1,
  34711. 0xDB, 0x4A, 0xC4, 0xF2, 0xDB, 0x39, 0xEA, 0x12,
  34712. 0x0D, 0x90, 0xFA, 0x60, 0xF4, 0xD4, 0x37, 0xC6,
  34713. 0xD0, 0x0E, 0xF4, 0x83, 0xBC, 0x94, 0xA3, 0x17,
  34714. 0x5C, 0xDA, 0x16, 0x3F, 0xC1, 0xC2, 0x82, 0x8B,
  34715. 0xE4, 0xDB, 0xD6, 0x43, 0x05, 0x07, 0xB5, 0x84,
  34716. 0xBB, 0x51, 0x77, 0xE1, 0x71, 0xB8, 0xDD, 0xA9,
  34717. 0xA4, 0x29, 0x3C, 0x32, 0x00, 0x29, 0x5C, 0x80,
  34718. 0x3A, 0x86, 0x5D, 0x6D, 0x21, 0x66, 0xF6, 0x6B,
  34719. 0xA5, 0x40, 0x1F, 0xB7, 0xA0, 0xE8, 0x53, 0x16,
  34720. 0x86, 0x00, 0xA2, 0x94, 0x84, 0x37, 0xE0, 0x36,
  34721. 0xE3, 0xBF, 0x19, 0xE1, 0x2F, 0xD3, 0xF2, 0xA2,
  34722. 0xB8, 0xB3, 0x43, 0xF7, 0x84, 0x24, 0x8E, 0x8D,
  34723. 0x68, 0x5E, 0xB0, 0xAF, 0xDE, 0x63, 0x15, 0x33,
  34724. 0x87, 0x30, 0xE7, 0xA1, 0x00, 0x1C, 0x27, 0xD8,
  34725. 0xD2, 0xA7, 0x6F, 0xA6, 0x9D, 0x15, 0x7B, 0xA1,
  34726. 0xAC, 0x7A, 0xD5, 0x6D, 0xA5, 0xA8, 0xC7, 0x0F,
  34727. 0xE4, 0xB5, 0xB8, 0xD7, 0x86, 0xDC, 0x6F, 0xC0,
  34728. 0x56, 0x6B, 0xA8, 0xE1, 0xB8, 0x81, 0x63, 0x34,
  34729. 0xD3, 0x2A, 0x3F, 0xB1, 0xCE, 0x7D, 0x4D, 0x5E,
  34730. 0x4C, 0x33, 0x2A, 0xF7, 0xB0, 0x03, 0xD0, 0x91,
  34731. 0x74, 0x1A, 0x3D, 0x5C, 0x96, 0x52, 0x92, 0x25,
  34732. 0x5D, 0xFF, 0x8E, 0xD2, 0xBB, 0xF1, 0xF9, 0x11,
  34733. 0x6B, 0xE5, 0x0C, 0x17, 0xB8, 0xE5, 0x48, 0x74,
  34734. 0x8A, 0xD4, 0xB2, 0xE9, 0x57, 0xBB, 0xD1, 0x95,
  34735. 0x34, 0x82, 0xA2, 0xE1, 0x71, 0x8C, 0xEC, 0x66,
  34736. 0xCD, 0x2C, 0x81, 0xF5, 0x72, 0xD5, 0x52, 0xB7,
  34737. 0x18, 0x78, 0x85, 0xE6, 0xB8, 0x94, 0x3D, 0x64,
  34738. 0x31, 0x41, 0x3C, 0x59, 0xEB, 0xB7, 0xE0, 0x36,
  34739. 0x04, 0x84, 0x90, 0xBE, 0x52, 0x89, 0xE9, 0x5B,
  34740. 0x20, 0xA8, 0x9E, 0x8B, 0x15, 0x9F, 0x61, 0xA9,
  34741. 0xA9, 0x88, 0x6E, 0x14, 0x75, 0x68, 0xF4, 0xC9,
  34742. 0x02, 0x1F, 0x36, 0x2F, 0x02, 0x68, 0x8A, 0x1C,
  34743. 0x8C, 0x3B, 0xB0, 0xD2, 0x40, 0x86, 0x88, 0x0E,
  34744. 0x55, 0xB6, 0xED, 0xB4, 0x3F, 0x37, 0x45, 0xD2,
  34745. 0xC1, 0x66, 0xDC, 0x1C, 0xB7, 0x43, 0xC7, 0x6F,
  34746. 0xE6, 0xBE, 0x52, 0x3A, 0x89, 0x3C, 0xC7, 0x64,
  34747. 0xD1, 0x64, 0x35, 0xC3, 0x78, 0x51, 0x25, 0x2A,
  34748. 0x81, 0xE2, 0xFF, 0xBA, 0x0F, 0x18, 0x97, 0x1A,
  34749. 0x3D, 0xEE, 0x37, 0xD4, 0x87, 0x7C, 0xB9, 0x28,
  34750. 0xE3, 0x6E, 0x52, 0x35, 0x03, 0x7A, 0x6B, 0x20,
  34751. 0x57, 0x89, 0x7D, 0x51, 0x8A, 0x5F, 0x0E, 0x34,
  34752. 0x8E, 0x3A, 0xB6, 0xD5, 0xB5, 0x2D, 0xFC, 0x60,
  34753. 0x75, 0x7F, 0x3B, 0x41, 0xA4, 0xFE, 0xC7, 0x82,
  34754. 0x8F, 0x1D, 0xEE, 0xAF, 0x45, 0x87, 0xCC, 0xC8,
  34755. 0xEA, 0xDF, 0x64, 0x7F, 0x4D, 0x20, 0x3B, 0x2F,
  34756. 0xAA, 0x05, 0xA6, 0x49, 0xB5, 0x82, 0x34, 0x0C,
  34757. 0xB4, 0xCA, 0xCE, 0x57, 0xA3, 0x07, 0x11, 0xBE,
  34758. 0x75, 0x2F, 0xAC, 0xF0, 0x22, 0x7D, 0x0A, 0x80,
  34759. 0xC4, 0x12, 0x84, 0x42, 0xDD, 0xC5, 0x44, 0xBE,
  34760. 0x80, 0x5B, 0x9C, 0xFE, 0x8F, 0xE9, 0xB1, 0x23,
  34761. 0x7C, 0x80, 0xF9, 0x67, 0x87, 0xCD, 0x92, 0x81,
  34762. 0xCC, 0xF2, 0x70, 0xC1, 0xAF, 0xC0, 0x67, 0x0D
  34763. };
  34764. #endif
  34765. #ifndef WOLFSSL_NO_ML_KEM
  34766. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ct[] = {
  34767. 0x11, 0x3d, 0xb2, 0xdd, 0x06, 0x87, 0x12, 0x35,
  34768. 0xe7, 0xbc, 0x36, 0xc9, 0xdc, 0xaa, 0x52, 0x8f,
  34769. 0xc2, 0x6c, 0xe5, 0xdb, 0x9e, 0xcc, 0x1d, 0xc3,
  34770. 0x2e, 0x95, 0x7d, 0x7f, 0xfb, 0x3c, 0x74, 0x29,
  34771. 0xd5, 0x0c, 0x3c, 0x35, 0x77, 0xa5, 0x15, 0xd3,
  34772. 0x18, 0x3a, 0x1b, 0x9d, 0x26, 0x7b, 0x93, 0x6b,
  34773. 0x7e, 0xb8, 0xf5, 0x43, 0xa3, 0xaf, 0xb7, 0x77,
  34774. 0x65, 0xca, 0x79, 0x38, 0xf7, 0x8a, 0xa6, 0x43,
  34775. 0x8c, 0xe8, 0x0a, 0x06, 0xa6, 0x96, 0x6d, 0x0d,
  34776. 0x06, 0xaf, 0x75, 0xba, 0x3e, 0x0d, 0x4f, 0x37,
  34777. 0xba, 0xc7, 0x33, 0x69, 0xf5, 0xa7, 0x29, 0xf7,
  34778. 0x3e, 0x85, 0x72, 0x9e, 0xdd, 0x97, 0xc8, 0xc2,
  34779. 0xa8, 0xcc, 0x26, 0x19, 0xe4, 0xcf, 0x7b, 0x60,
  34780. 0x91, 0x86, 0x9e, 0x90, 0x9f, 0xd4, 0x7d, 0x97,
  34781. 0x09, 0x14, 0x92, 0x04, 0xb0, 0x83, 0x7d, 0x8d,
  34782. 0x6f, 0x25, 0xd2, 0x67, 0x97, 0x2b, 0xe6, 0x3b,
  34783. 0xad, 0x34, 0xb5, 0x44, 0x52, 0x3c, 0x01, 0xc0,
  34784. 0x9d, 0xe3, 0xb1, 0xfa, 0x1d, 0x6b, 0x7b, 0x05,
  34785. 0x9e, 0xee, 0x9e, 0x65, 0x20, 0x62, 0xfe, 0x87,
  34786. 0x0f, 0x68, 0xc6, 0x80, 0x05, 0x33, 0x9e, 0xa1,
  34787. 0x81, 0xe1, 0xd0, 0x76, 0x7c, 0x15, 0x2a, 0xeb,
  34788. 0x38, 0xfa, 0xf0, 0xf9, 0x24, 0x5a, 0xe5, 0x9d,
  34789. 0x5c, 0xb0, 0xd2, 0xb7, 0xf2, 0x01, 0x22, 0x9e,
  34790. 0xd9, 0x70, 0x20, 0xd0, 0x62, 0x3a, 0x46, 0x10,
  34791. 0x0d, 0x09, 0x7b, 0x0c, 0xe1, 0x15, 0x4e, 0x02,
  34792. 0x8a, 0xe6, 0x19, 0x4d, 0xe0, 0x5d, 0xe9, 0x7d,
  34793. 0xd9, 0xae, 0x2e, 0x85, 0xff, 0xd2, 0x5d, 0x95,
  34794. 0xeb, 0x22, 0xef, 0xfe, 0x5b, 0xa1, 0x9c, 0xd8,
  34795. 0x07, 0xc5, 0x30, 0xeb, 0xaa, 0x9f, 0xe9, 0xf6,
  34796. 0x42, 0xcc, 0xac, 0xff, 0x47, 0xed, 0x15, 0xc2,
  34797. 0x2b, 0xfe, 0x30, 0x36, 0xeb, 0xf8, 0xad, 0x9c,
  34798. 0x8e, 0xd2, 0x32, 0x40, 0xae, 0xeb, 0xaa, 0x24,
  34799. 0xd1, 0x35, 0x75, 0x51, 0x00, 0xb8, 0x5e, 0xce,
  34800. 0xe3, 0x17, 0x49, 0x06, 0xe4, 0x63, 0x12, 0x06,
  34801. 0x2c, 0xee, 0xca, 0xc7, 0x5d, 0xe5, 0x27, 0x52,
  34802. 0x56, 0xc2, 0xc1, 0xa6, 0x53, 0xfd, 0x69, 0x15,
  34803. 0xb1, 0xb3, 0x0c, 0x8e, 0xcb, 0xb6, 0xfd, 0x42,
  34804. 0x80, 0x43, 0x74, 0x53, 0x17, 0x3a, 0x96, 0x23,
  34805. 0x8b, 0xc7, 0xd1, 0x08, 0x89, 0x23, 0x43, 0xe0,
  34806. 0x33, 0xbc, 0xd9, 0x8e, 0x43, 0x7e, 0x78, 0x9f,
  34807. 0xc5, 0xbe, 0xba, 0xa1, 0x2b, 0x26, 0x34, 0xb5,
  34808. 0x1e, 0xd0, 0xd5, 0x89, 0xf1, 0x11, 0x43, 0xa0,
  34809. 0x21, 0xd8, 0xec, 0xce, 0x59, 0x4f, 0xdd, 0x48,
  34810. 0xda, 0xe8, 0x4c, 0x80, 0x63, 0xef, 0x35, 0x81,
  34811. 0xbc, 0x37, 0x8a, 0x48, 0xda, 0x4e, 0x51, 0xbb,
  34812. 0x17, 0x5b, 0x0d, 0xb4, 0x7f, 0x9d, 0xcf, 0x99,
  34813. 0x31, 0x8c, 0x30, 0x22, 0x5c, 0xa7, 0xfa, 0x79,
  34814. 0xc8, 0x79, 0xbf, 0x1c, 0x93, 0x97, 0xb5, 0xcc,
  34815. 0xc5, 0xef, 0xad, 0x94, 0xc5, 0x00, 0xed, 0x7f,
  34816. 0x9f, 0x38, 0x5d, 0x08, 0x8e, 0x34, 0x93, 0x22,
  34817. 0x21, 0xfc, 0x0f, 0xc9, 0xaf, 0xe5, 0x1f, 0x68,
  34818. 0x75, 0x54, 0x81, 0x31, 0x69, 0x76, 0x95, 0x47,
  34819. 0x8a, 0xbd, 0xc8, 0x73, 0x6f, 0x10, 0x09, 0x5a,
  34820. 0x6b, 0x92, 0xec, 0x67, 0x9f, 0xe0, 0xe2, 0xae,
  34821. 0x5d, 0x8b, 0x33, 0x53, 0x55, 0xd5, 0x8d, 0xae,
  34822. 0x4d, 0x4f, 0x0b, 0x17, 0xaa, 0x5d, 0x1e, 0x52,
  34823. 0xf1, 0xd4, 0x55, 0x84, 0xa8, 0x92, 0xc3, 0x4c,
  34824. 0xe4, 0xb0, 0x4f, 0xcd, 0x00, 0x98, 0x1d, 0x51,
  34825. 0xca, 0xa1, 0x60, 0x64, 0xba, 0xd9, 0x2d, 0x01,
  34826. 0x9d, 0xc3, 0xad, 0xed, 0x91, 0x96, 0x84, 0x11,
  34827. 0x2b, 0x29, 0xda, 0xa2, 0x8b, 0x9d, 0xae, 0x09,
  34828. 0xb8, 0x6b, 0x21, 0xa9, 0x33, 0x10, 0xd5, 0xfb,
  34829. 0xc6, 0x52, 0x7b, 0x22, 0x4b, 0x9c, 0xe8, 0x7d,
  34830. 0x27, 0x82, 0xbb, 0x29, 0x46, 0x73, 0xf0, 0xec,
  34831. 0x06, 0xf2, 0x6b, 0x08, 0x76, 0x52, 0xa1, 0x8d,
  34832. 0x6a, 0xd7, 0xb1, 0xc9, 0x33, 0x03, 0xef, 0x05,
  34833. 0x61, 0xc0, 0xfc, 0x9c, 0xd4, 0xf6, 0x78, 0xf6,
  34834. 0x06, 0xf1, 0x92, 0xcf, 0x5d, 0xf9, 0x2b, 0x15,
  34835. 0x48, 0xf5, 0xdd, 0x26, 0x87, 0xed, 0xbe, 0xcc,
  34836. 0xfc, 0x6d, 0x4e, 0x9d, 0xe4, 0xbd, 0x50, 0xd3,
  34837. 0xc7, 0x4f, 0xb2, 0x75, 0xab, 0xd9, 0xb3, 0xe9,
  34838. 0x02, 0x77, 0xdb, 0x4a, 0x00, 0x69, 0xc0, 0xa2,
  34839. 0xa7, 0x13, 0x6f, 0x50, 0xce, 0xad, 0x4b, 0x2f,
  34840. 0x19, 0x95, 0xfa, 0xaf, 0x16, 0x80, 0x40, 0xe9,
  34841. 0xe4, 0xbe, 0xb7, 0xc5, 0x72, 0x20, 0x49, 0xd6,
  34842. 0xda, 0x64, 0x02, 0x99, 0x2f, 0xce, 0xa4, 0x50,
  34843. 0x97, 0xdf, 0x7c, 0x1c, 0x20, 0xfb, 0x06, 0x82,
  34844. 0x22, 0x00, 0x05, 0x76, 0x93, 0x5a, 0x08, 0x06,
  34845. 0x77, 0x34, 0x51, 0x92, 0x1f, 0x54, 0xc5, 0x5f,
  34846. 0xbf, 0x59, 0x3a, 0x4f, 0x14, 0x7c, 0x1f, 0xef,
  34847. 0x3a, 0xca, 0xf0, 0xcf, 0xa9, 0x07, 0xae, 0x48,
  34848. 0xc8, 0xc0, 0x63, 0x12, 0xcf, 0xdf, 0x51, 0x86,
  34849. 0x90, 0x4b, 0xec, 0x7f, 0xed, 0x4e, 0xd9, 0x33,
  34850. 0xc9, 0x25, 0x6a, 0xb0, 0x4c, 0xbf, 0xa0, 0x3a,
  34851. 0x96, 0x7c, 0x1f, 0x7e, 0xad, 0x4a, 0xb4, 0x0d,
  34852. 0xf1, 0x16, 0xbe, 0x66, 0x0e, 0x27, 0xca, 0x2b,
  34853. 0x54, 0x35, 0x26, 0xd4, 0xb9, 0x68, 0x4c, 0x31,
  34854. 0xe1, 0xe4, 0x23, 0x83, 0xb9, 0x69, 0xf8, 0x96,
  34855. 0x29, 0x9d, 0x71, 0x39, 0x0c, 0xc8, 0x5b, 0x70,
  34856. 0x32, 0x02, 0xac, 0xad, 0xec, 0xfa, 0x8c, 0x40,
  34857. 0x96, 0x5c, 0x08, 0xc5, 0x3b, 0x56, 0x71, 0xe0,
  34858. 0xd5, 0x94, 0x55, 0xbc, 0x5a, 0x85, 0x86, 0xc6,
  34859. 0x55, 0xdb, 0x8c, 0x2a, 0xde, 0x4b, 0xa8, 0x87,
  34860. 0x7f, 0x19, 0xb6, 0x00, 0x0e, 0x18, 0xf8, 0xfe,
  34861. 0xad, 0xda, 0x7e, 0xde, 0x8f, 0xe8, 0x0a, 0xa6,
  34862. 0x62, 0xd6, 0x94, 0xc6, 0xd8, 0xc3, 0x3b, 0x52
  34863. };
  34864. #endif
  34865. #ifdef WOLFSSL_KYBER_ORIGINAL
  34866. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ss[] = {
  34867. 0x0A, 0x69, 0x25, 0x67, 0x6F, 0x24, 0xB2, 0x2C,
  34868. 0x28, 0x6F, 0x4C, 0x81, 0xA4, 0x22, 0x4C, 0xEC,
  34869. 0x50, 0x6C, 0x9B, 0x25, 0x7D, 0x48, 0x0E, 0x02,
  34870. 0xE3, 0xB4, 0x9F, 0x44, 0xCA, 0xA3, 0x23, 0x7F
  34871. };
  34872. #endif
  34873. #ifndef WOLFSSL_NO_ML_KEM
  34874. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ss[] = {
  34875. 0x31, 0x98, 0x39, 0xe8, 0x2a, 0xb6, 0xb2, 0x22,
  34876. 0xde, 0x7b, 0x61, 0x9e, 0x80, 0xda, 0x83, 0x91,
  34877. 0x52, 0x2b, 0xbb, 0x37, 0x67, 0x70, 0x18, 0x49,
  34878. 0x4a, 0x47, 0x42, 0xc5, 0x3f, 0x9a, 0xbf, 0xdf
  34879. };
  34880. #endif
  34881. #ifdef WOLFSSL_SMALL_STACK
  34882. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  34883. DYNAMIC_TYPE_TMP_BUFFER);
  34884. priv = (byte *)XMALLOC(KYBER512_PRIVATE_KEY_SIZE, HEAP_HINT,
  34885. DYNAMIC_TYPE_TMP_BUFFER);
  34886. pub = (byte *)XMALLOC(KYBER512_PUBLIC_KEY_SIZE, HEAP_HINT,
  34887. DYNAMIC_TYPE_TMP_BUFFER);
  34888. ct = (byte *)XMALLOC(KYBER512_CIPHER_TEXT_SIZE, HEAP_HINT,
  34889. DYNAMIC_TYPE_TMP_BUFFER);
  34890. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34891. DYNAMIC_TYPE_TMP_BUFFER);
  34892. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34893. DYNAMIC_TYPE_TMP_BUFFER);
  34894. if (! (key && priv && pub && ct && ss && ss_dec))
  34895. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  34896. #endif
  34897. #ifdef WOLFSSL_KYBER_ORIGINAL
  34898. ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
  34899. if (ret != 0)
  34900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34901. else
  34902. key_inited = 1;
  34903. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34904. sizeof(kyber512_rand));
  34905. if (ret != 0)
  34906. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34907. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
  34908. if (ret != 0)
  34909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34910. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
  34911. if (ret != 0)
  34912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34913. if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0)
  34914. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34915. if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
  34916. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34917. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34918. sizeof(kyber512enc_rand));
  34919. if (ret != 0)
  34920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34921. if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0)
  34922. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34923. if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34924. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34925. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
  34926. if (ret != 0)
  34927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34928. if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34929. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34930. #endif
  34931. #ifndef WOLFSSL_NO_ML_KEM
  34932. ret = wc_KyberKey_Init(WC_ML_KEM_512, key, HEAP_HINT, INVALID_DEVID);
  34933. if (ret != 0)
  34934. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34935. else
  34936. key_inited = 1;
  34937. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34938. sizeof(kyber512_rand));
  34939. if (ret != 0)
  34940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34941. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_512_PUBLIC_KEY_SIZE);
  34942. if (ret != 0)
  34943. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34944. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  34945. WC_ML_KEM_512_PRIVATE_KEY_SIZE);
  34946. if (ret != 0)
  34947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34948. if (XMEMCMP(pub, ml_kem_512_pk, sizeof(ml_kem_512_pk)) != 0)
  34949. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34950. if (XMEMCMP(priv, ml_kem_512_sk, sizeof(ml_kem_512_sk)) != 0)
  34951. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34952. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34953. sizeof(kyber512enc_rand));
  34954. if (ret != 0)
  34955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34956. if (XMEMCMP(ct, ml_kem_512_ct, sizeof(ml_kem_512_ct)) != 0)
  34957. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34958. if (XMEMCMP(ss, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34959. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34960. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_512_ct));
  34961. if (ret != 0)
  34962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34963. if (XMEMCMP(ss_dec, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34964. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34965. #endif
  34966. out:
  34967. if (key_inited)
  34968. wc_KyberKey_Free(key);
  34969. #ifdef WOLFSSL_SMALL_STACK
  34970. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34971. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34972. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34973. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34974. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34975. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34976. #endif
  34977. return ret;
  34978. }
  34979. #endif /* WOLFSSL_KYBER512 */
  34980. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  34981. static wc_test_ret_t kyber768_kat(void)
  34982. {
  34983. wc_test_ret_t ret;
  34984. #ifdef WOLFSSL_SMALL_STACK
  34985. KyberKey *key = NULL;
  34986. byte *priv = NULL;
  34987. byte *pub = NULL;
  34988. byte *ct = NULL;
  34989. byte *ss = NULL;
  34990. byte *ss_dec = NULL;
  34991. #else
  34992. KyberKey key[1];
  34993. byte priv[KYBER768_PRIVATE_KEY_SIZE];
  34994. byte pub[KYBER768_PUBLIC_KEY_SIZE];
  34995. byte ct[KYBER768_CIPHER_TEXT_SIZE];
  34996. byte ss[KYBER_SS_SZ];
  34997. byte ss_dec[KYBER_SS_SZ];
  34998. #endif
  34999. int key_inited = 0;
  35000. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_rand[] = {
  35001. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  35002. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  35003. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  35004. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  35005. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35006. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35007. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35008. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35009. };
  35010. WOLFSSL_SMALL_STACK_STATIC const byte kyber768enc_rand[] = {
  35011. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  35012. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  35013. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  35014. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  35015. };
  35016. #ifdef WOLFSSL_KYBER_ORIGINAL
  35017. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_pk[] = {
  35018. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35019. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35020. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35021. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35022. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35023. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35024. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35025. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35026. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35027. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35028. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35029. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35030. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35031. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35032. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35033. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35034. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35035. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35036. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35037. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35038. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35039. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35040. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35041. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35042. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35043. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35044. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35045. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35046. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35047. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35048. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35049. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35050. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35051. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35052. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35053. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35054. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35055. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35056. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35057. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35058. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35059. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35060. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35061. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35062. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35063. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35064. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35065. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35066. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35067. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35068. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35069. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35070. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35071. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35072. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35073. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35074. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35075. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35076. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35077. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35078. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35079. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35080. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35081. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35082. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35083. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35084. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35085. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35086. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35087. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35088. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35089. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35090. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35091. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35092. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35093. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35094. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35095. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35096. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35097. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35098. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35099. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35100. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35101. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35102. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35103. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35104. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35105. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35106. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35107. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35108. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35109. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35110. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35111. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35112. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35113. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35114. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35115. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35116. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35117. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35118. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35119. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35120. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35121. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35122. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35123. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35124. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35125. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35126. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35127. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35128. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35129. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35130. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35131. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35132. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35133. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35134. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35135. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35136. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35137. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35138. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35139. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35140. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35141. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35142. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35143. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35144. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35145. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35146. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35147. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35148. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35149. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35150. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35151. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35152. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35153. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35154. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35155. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35156. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35157. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35158. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35159. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35160. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35161. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35162. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35163. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35164. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35165. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  35166. };
  35167. #endif
  35168. #ifndef WOLFSSL_NO_ML_KEM
  35169. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_pk[] = {
  35170. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35171. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35172. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35173. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35174. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35175. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35176. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35177. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35178. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35179. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35180. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35181. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35182. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35183. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35184. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35185. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35186. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35187. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35188. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35189. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35190. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35191. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35192. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35193. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35194. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35195. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35196. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35197. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35198. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35199. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35200. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35201. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35202. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35203. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35204. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35205. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35206. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35207. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35208. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35209. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35210. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35211. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35212. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35213. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35214. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35215. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35216. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35217. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35218. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35219. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35220. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35221. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35222. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35223. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35224. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35225. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35226. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35227. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35228. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35229. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35230. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35231. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35232. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35233. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35234. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35235. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35236. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35237. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35238. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35239. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35240. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35241. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35242. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35243. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35244. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35245. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35246. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35247. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35248. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35249. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35250. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35251. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35252. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35253. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35254. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35255. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35256. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35257. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35258. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35259. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35260. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35261. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35262. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35263. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35264. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35265. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35266. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35267. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35268. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35269. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35270. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35271. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35272. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35273. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35274. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35275. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35276. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35277. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35278. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35279. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35280. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35281. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35282. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35283. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35284. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35285. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35286. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35287. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35288. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35289. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35290. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35291. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35292. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35293. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35294. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35295. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35296. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35297. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35298. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35299. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35300. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35301. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35302. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35303. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35304. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35305. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35306. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35307. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35308. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35309. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35310. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35311. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35312. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35313. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35314. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35315. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35316. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35317. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28
  35318. };
  35319. #endif
  35320. #ifdef WOLFSSL_KYBER_ORIGINAL
  35321. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_sk[] = {
  35322. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  35323. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  35324. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  35325. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  35326. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  35327. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  35328. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  35329. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  35330. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  35331. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  35332. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  35333. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  35334. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  35335. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  35336. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  35337. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  35338. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  35339. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  35340. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  35341. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  35342. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  35343. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  35344. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  35345. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  35346. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  35347. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  35348. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  35349. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  35350. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  35351. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  35352. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  35353. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  35354. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  35355. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  35356. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  35357. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  35358. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  35359. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  35360. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  35361. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  35362. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  35363. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  35364. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  35365. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  35366. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  35367. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  35368. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  35369. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  35370. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  35371. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  35372. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  35373. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  35374. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  35375. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  35376. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  35377. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  35378. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  35379. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  35380. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  35381. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  35382. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  35383. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  35384. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  35385. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  35386. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  35387. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  35388. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  35389. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  35390. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  35391. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  35392. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  35393. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  35394. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  35395. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  35396. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  35397. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  35398. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  35399. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  35400. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  35401. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  35402. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  35403. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  35404. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  35405. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  35406. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  35407. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  35408. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  35409. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  35410. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  35411. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  35412. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  35413. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  35414. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  35415. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  35416. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  35417. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  35418. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  35419. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  35420. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  35421. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  35422. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  35423. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  35424. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  35425. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  35426. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  35427. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  35428. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  35429. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  35430. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  35431. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  35432. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  35433. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  35434. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  35435. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  35436. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  35437. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  35438. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  35439. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  35440. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  35441. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  35442. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  35443. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  35444. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  35445. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  35446. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  35447. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  35448. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  35449. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  35450. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  35451. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  35452. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  35453. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  35454. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  35455. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  35456. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  35457. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  35458. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  35459. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  35460. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  35461. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  35462. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  35463. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  35464. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  35465. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  35466. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35467. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35468. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35469. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35470. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35471. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35472. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35473. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35474. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35475. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35476. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35477. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35478. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35479. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35480. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35481. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35482. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35483. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35484. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35485. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35486. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35487. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35488. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35489. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35490. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35491. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35492. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35493. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35494. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35495. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35496. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35497. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35498. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35499. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35500. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35501. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35502. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35503. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35504. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35505. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35506. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35507. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35508. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35509. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35510. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35511. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35512. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35513. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35514. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35515. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35516. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35517. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35518. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35519. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35520. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35521. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35522. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35523. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35524. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35525. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35526. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35527. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35528. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35529. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35530. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35531. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35532. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35533. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35534. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35535. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35536. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35537. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35538. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35539. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35540. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35541. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35542. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35543. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35544. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35545. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35546. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35547. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35548. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35549. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35550. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35551. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35552. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35553. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35554. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35555. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35556. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35557. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35558. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35559. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35560. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35561. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35562. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35563. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35564. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35565. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35566. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35567. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35568. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35569. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35570. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35571. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35572. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35573. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35574. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35575. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35576. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35577. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35578. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35579. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35580. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35581. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35582. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35583. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35584. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35585. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35586. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35587. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35588. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35589. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35590. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35591. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35592. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35593. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35594. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35595. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35596. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35597. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35598. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35599. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35600. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35601. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35602. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35603. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35604. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35605. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35606. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35607. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35608. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35609. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35610. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35611. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35612. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35613. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  35614. 0xD4, 0xEC, 0x14, 0x3B, 0x50, 0xF0, 0x14, 0x23,
  35615. 0xB1, 0x77, 0x89, 0x5E, 0xDE, 0xE2, 0x2B, 0xB7,
  35616. 0x39, 0xF6, 0x47, 0xEC, 0xF8, 0x5F, 0x50, 0xBC,
  35617. 0x25, 0xEF, 0x7B, 0x5A, 0x72, 0x5D, 0xEE, 0x86,
  35618. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35619. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35620. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35621. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35622. };
  35623. #endif
  35624. #ifndef WOLFSSL_NO_ML_KEM
  35625. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_sk[] = {
  35626. 0xda, 0x0a, 0xc7, 0xb6, 0x60, 0x40, 0x4e, 0x61,
  35627. 0x3a, 0xa1, 0xf9, 0x80, 0x38, 0x0c, 0xb3, 0x6d,
  35628. 0xba, 0x18, 0xd2, 0x32, 0x56, 0xc7, 0x26, 0x7a,
  35629. 0x00, 0xa6, 0x7b, 0xa6, 0xc2, 0xa2, 0xb1, 0x4c,
  35630. 0x41, 0x42, 0x39, 0x66, 0x2f, 0x68, 0xbd, 0x44,
  35631. 0x6c, 0x8e, 0xfd, 0xf3, 0x66, 0x56, 0xa0, 0x89,
  35632. 0x1a, 0x3c, 0xc6, 0x23, 0xfc, 0x68, 0xb6, 0x57,
  35633. 0x2f, 0x7b, 0x29, 0xa6, 0xde, 0x12, 0x80, 0x14,
  35634. 0x41, 0x1e, 0xe4, 0x19, 0x06, 0xd0, 0x80, 0x71,
  35635. 0xf9, 0x48, 0x56, 0xe3, 0x6a, 0x83, 0x2b, 0x40,
  35636. 0x33, 0x8d, 0x74, 0x35, 0x16, 0x65, 0x9b, 0xd2,
  35637. 0x58, 0x79, 0xc0, 0x07, 0xa5, 0x2b, 0xc9, 0x58,
  35638. 0x6f, 0x79, 0x87, 0x6a, 0xfa, 0xc6, 0xc9, 0xa3,
  35639. 0x0d, 0x8f, 0xac, 0x24, 0x3b, 0xd2, 0x24, 0x25,
  35640. 0xd6, 0xad, 0xce, 0x42, 0xab, 0x7e, 0xd3, 0x90,
  35641. 0x14, 0x75, 0x7a, 0x95, 0x8b, 0xc8, 0xa7, 0x45,
  35642. 0x65, 0xf0, 0x19, 0x23, 0x4f, 0xf0, 0x4b, 0x34,
  35643. 0x89, 0x3e, 0xd6, 0xd0, 0x55, 0x01, 0xc3, 0x72,
  35644. 0x55, 0x23, 0x9a, 0xae, 0x2a, 0xc1, 0x9f, 0x8c,
  35645. 0x75, 0xac, 0x59, 0x00, 0xda, 0xe8, 0x30, 0x0d,
  35646. 0xbb, 0xa7, 0x10, 0xdc, 0x2c, 0xaa, 0xe1, 0xbc,
  35647. 0xa3, 0xa3, 0x8c, 0x58, 0x34, 0x2b, 0x28, 0x6b,
  35648. 0x85, 0x18, 0xf1, 0x36, 0xad, 0x15, 0xb9, 0xf7,
  35649. 0xbc, 0xbb, 0x06, 0xa5, 0x60, 0x7d, 0xb3, 0x75,
  35650. 0xdb, 0xe9, 0x76, 0x45, 0x7c, 0x26, 0xc6, 0x59,
  35651. 0x82, 0x57, 0x53, 0x1b, 0x2c, 0xfb, 0x6e, 0xe7,
  35652. 0xf5, 0x15, 0x91, 0x84, 0x08, 0x04, 0xc3, 0x83,
  35653. 0x88, 0x37, 0x6c, 0x27, 0x14, 0x84, 0x13, 0xda,
  35654. 0x9e, 0x92, 0x92, 0x0b, 0xfd, 0x9a, 0x06, 0x9e,
  35655. 0x01, 0x8b, 0xd2, 0x72, 0x05, 0x3d, 0xa8, 0x77,
  35656. 0x5c, 0x0b, 0x73, 0x9f, 0x76, 0x1d, 0xb2, 0x10,
  35657. 0x7c, 0xf3, 0x5a, 0x43, 0x4d, 0x69, 0xb0, 0x7e,
  35658. 0x5b, 0xcd, 0xb8, 0x74, 0x34, 0x13, 0x8b, 0x0c,
  35659. 0xb5, 0x56, 0x76, 0x1b, 0xa5, 0x22, 0xa5, 0x74,
  35660. 0x7b, 0x28, 0x74, 0x7d, 0x80, 0xeb, 0x9d, 0x6c,
  35661. 0xc6, 0x73, 0xbe, 0xe5, 0x76, 0x93, 0x77, 0xb9,
  35662. 0x96, 0xd3, 0x6c, 0xeb, 0x0c, 0x0c, 0x7e, 0xd9,
  35663. 0xa6, 0x58, 0x53, 0x33, 0x24, 0x86, 0x9c, 0x18,
  35664. 0xa1, 0xa3, 0x6f, 0x31, 0x47, 0x0f, 0x14, 0xc5,
  35665. 0xae, 0x49, 0xab, 0x07, 0x05, 0x07, 0xf8, 0x24,
  35666. 0x9c, 0xe4, 0x04, 0xb4, 0x9c, 0x0a, 0x8c, 0x3e,
  35667. 0xe4, 0x2f, 0xea, 0x96, 0x31, 0xfa, 0x1a, 0x0d,
  35668. 0x10, 0xd8, 0x6b, 0x93, 0xf9, 0x86, 0xe0, 0xe3,
  35669. 0xa8, 0x2e, 0x70, 0x3b, 0x74, 0xe5, 0xae, 0x61,
  35670. 0x01, 0x24, 0x24, 0x21, 0xa8, 0x9a, 0xa0, 0x7f,
  35671. 0xe6, 0x85, 0x88, 0x46, 0x0b, 0xaa, 0x36, 0x87,
  35672. 0x86, 0x48, 0x6a, 0x72, 0xe4, 0xf2, 0x4d, 0x2d,
  35673. 0xd7, 0x6c, 0xfc, 0x03, 0xb6, 0x94, 0xa5, 0xba,
  35674. 0x91, 0xa7, 0x55, 0xa0, 0xb9, 0x8f, 0x3b, 0xf9,
  35675. 0x33, 0x07, 0xc0, 0xab, 0x64, 0x63, 0x9a, 0xea,
  35676. 0x7a, 0x64, 0x98, 0xa3, 0xc3, 0xdd, 0xc5, 0x71,
  35677. 0x14, 0x1a, 0xbc, 0xa4, 0x67, 0x8c, 0xd2, 0xe2,
  35678. 0xb8, 0x57, 0xfb, 0x88, 0xf6, 0x00, 0xca, 0xa5,
  35679. 0x96, 0xb4, 0x4b, 0xc4, 0x22, 0x25, 0x0b, 0x28,
  35680. 0x19, 0xe0, 0x51, 0x5f, 0x04, 0x72, 0x39, 0x18,
  35681. 0x53, 0x70, 0x0b, 0x01, 0xef, 0xf9, 0x45, 0x3f,
  35682. 0xd1, 0x18, 0x76, 0xb7, 0xc7, 0x59, 0xa0, 0x7d,
  35683. 0xd8, 0x45, 0xca, 0xba, 0x45, 0x55, 0x26, 0x4a,
  35684. 0x82, 0x76, 0x51, 0x93, 0xfd, 0xf8, 0x1b, 0x62,
  35685. 0x0a, 0x1e, 0x1f, 0x92, 0x3f, 0xb2, 0x44, 0x42,
  35686. 0xcd, 0x1c, 0xbe, 0x94, 0x17, 0x50, 0x03, 0xec,
  35687. 0x06, 0xce, 0x77, 0xa3, 0xc6, 0x44, 0x93, 0xc1,
  35688. 0x99, 0x98, 0x7a, 0x30, 0x0c, 0x95, 0xc5, 0x3c,
  35689. 0x00, 0x89, 0xb5, 0xd6, 0x5c, 0x92, 0xea, 0x97,
  35690. 0x1b, 0x2f, 0xfa, 0x93, 0xb5, 0x2a, 0x46, 0x1e,
  35691. 0xa2, 0xac, 0x8c, 0x19, 0x9c, 0x2f, 0x4c, 0x2b,
  35692. 0x70, 0x42, 0x97, 0xce, 0x3c, 0x39, 0x49, 0xe0,
  35693. 0x73, 0x5e, 0xa8, 0xa1, 0x4a, 0xa5, 0x9e, 0x8d,
  35694. 0xec, 0x0c, 0x87, 0x83, 0x99, 0xff, 0x70, 0x74,
  35695. 0x7a, 0xb2, 0x44, 0xce, 0x46, 0xb5, 0xf2, 0x23,
  35696. 0x04, 0x73, 0x32, 0x3d, 0x25, 0xc6, 0x6f, 0xe6,
  35697. 0xb4, 0x19, 0xb1, 0xf4, 0xa1, 0x12, 0xe5, 0x21,
  35698. 0x40, 0x35, 0x25, 0x6b, 0xc4, 0x3f, 0xfd, 0x2b,
  35699. 0x6b, 0x7b, 0x37, 0x87, 0x69, 0xa6, 0xb4, 0x70,
  35700. 0x00, 0xbf, 0xb6, 0x35, 0x7d, 0x45, 0x81, 0x4b,
  35701. 0xae, 0xf3, 0x85, 0x7d, 0x37, 0x9e, 0x2f, 0xb8,
  35702. 0xb5, 0xe5, 0x20, 0x1a, 0xb2, 0x62, 0x74, 0xbb,
  35703. 0x1b, 0x70, 0xad, 0x32, 0x2c, 0xd0, 0x43, 0x9b,
  35704. 0x2d, 0xb1, 0x09, 0xcf, 0xf0, 0xa2, 0xf8, 0xe6,
  35705. 0x00, 0x99, 0x55, 0x71, 0xff, 0xc3, 0x8c, 0x59,
  35706. 0x0b, 0xc4, 0xc7, 0x61, 0x5c, 0x69, 0xd0, 0xc9,
  35707. 0x8e, 0xf4, 0x30, 0xf3, 0x08, 0x61, 0xa7, 0x72,
  35708. 0x38, 0xff, 0xc0, 0x70, 0x61, 0xe4, 0x75, 0xd6,
  35709. 0xa3, 0x0a, 0xd1, 0xb4, 0x7f, 0xd0, 0x39, 0xc3,
  35710. 0xa4, 0x47, 0x76, 0x2d, 0xb2, 0x21, 0x1d, 0xc3,
  35711. 0x1d, 0x0a, 0xca, 0xcf, 0xd5, 0x58, 0x90, 0xa5,
  35712. 0x82, 0x47, 0x98, 0xf9, 0xae, 0xad, 0x74, 0x13,
  35713. 0xdf, 0xe0, 0x28, 0xb1, 0x01, 0x2b, 0xe8, 0xb6,
  35714. 0xca, 0x10, 0x26, 0x66, 0x6a, 0xc6, 0xbc, 0x94,
  35715. 0x40, 0xa4, 0x49, 0xb5, 0x1a, 0xd8, 0xbb, 0xa7,
  35716. 0xb0, 0x92, 0x1d, 0xd4, 0xd8, 0xb4, 0xa5, 0x78,
  35717. 0x13, 0x6d, 0x1a, 0x05, 0xdb, 0x38, 0xcc, 0x85,
  35718. 0x84, 0x37, 0xb2, 0x51, 0x61, 0xd1, 0xc3, 0xc2,
  35719. 0x8e, 0xe0, 0x7b, 0xbc, 0xf2, 0xb2, 0x49, 0x11,
  35720. 0x0d, 0x22, 0x78, 0x1d, 0xc3, 0x05, 0x0d, 0x8c,
  35721. 0xc0, 0x09, 0x00, 0x96, 0xb3, 0x8a, 0x85, 0x06,
  35722. 0x96, 0xf8, 0x6e, 0x9e, 0x6b, 0xab, 0x32, 0x52,
  35723. 0x71, 0xb2, 0x24, 0x86, 0x75, 0x01, 0x19, 0x68,
  35724. 0x50, 0x28, 0x81, 0x09, 0x04, 0x97, 0xfa, 0xc0,
  35725. 0xaf, 0x84, 0x3c, 0x1a, 0xea, 0x76, 0xdd, 0x81,
  35726. 0xcf, 0x29, 0xc0, 0x12, 0xc6, 0x62, 0x27, 0xb7,
  35727. 0xf0, 0x6d, 0x99, 0x61, 0x30, 0x9b, 0x02, 0x62,
  35728. 0xf7, 0x32, 0xc9, 0xa4, 0xd0, 0xbb, 0xd0, 0x67,
  35729. 0x27, 0xab, 0xb8, 0x37, 0x1f, 0xf2, 0xc1, 0x18,
  35730. 0x99, 0xa0, 0x98, 0x37, 0x5c, 0x46, 0x05, 0x16,
  35731. 0xb2, 0xcc, 0x88, 0xbc, 0xf6, 0x28, 0xed, 0xe3,
  35732. 0x7d, 0x8f, 0x3b, 0x33, 0x42, 0xe4, 0x49, 0x0a,
  35733. 0x85, 0x60, 0x6e, 0xc0, 0x3d, 0xa2, 0x9b, 0x02,
  35734. 0x56, 0x27, 0x53, 0x82, 0xa3, 0x31, 0x3d, 0xc0,
  35735. 0x41, 0x11, 0x48, 0x01, 0x03, 0x2c, 0x51, 0x9f,
  35736. 0x35, 0x0c, 0x3e, 0x6a, 0xba, 0xc3, 0xe3, 0x3b,
  35737. 0x93, 0xb4, 0xa1, 0x9f, 0x7c, 0x54, 0x66, 0xe5,
  35738. 0x8c, 0xb1, 0xdc, 0x14, 0xb4, 0xa9, 0x6c, 0x47,
  35739. 0x57, 0x29, 0xf9, 0x71, 0xbd, 0xf1, 0x73, 0xcd,
  35740. 0xf3, 0x54, 0x82, 0x4d, 0x01, 0x94, 0x27, 0xf9,
  35741. 0x5b, 0x3b, 0x4a, 0x4a, 0x4a, 0x95, 0x8e, 0x47,
  35742. 0x6a, 0x6e, 0x69, 0x91, 0xce, 0x6f, 0x06, 0xcb,
  35743. 0x5d, 0xfc, 0xa7, 0xd4, 0x38, 0x0c, 0x3d, 0x92,
  35744. 0x0b, 0x57, 0x11, 0xac, 0x1f, 0xcb, 0xaf, 0x4b,
  35745. 0x9a, 0xc8, 0x00, 0xb9, 0x76, 0xd1, 0xec, 0x76,
  35746. 0x6a, 0x62, 0x6c, 0xc1, 0x90, 0x0b, 0x66, 0xb3,
  35747. 0xa9, 0xdc, 0x62, 0xc5, 0xc1, 0x44, 0x52, 0x7a,
  35748. 0x29, 0x6b, 0xaf, 0x70, 0x43, 0x3b, 0xf6, 0x57,
  35749. 0xc0, 0x43, 0x7f, 0x87, 0x59, 0x7b, 0xd7, 0xc8,
  35750. 0xbb, 0xbe, 0x9a, 0xbc, 0x37, 0x05, 0x09, 0x31,
  35751. 0xa4, 0xa8, 0x69, 0x82, 0xa2, 0x02, 0x8a, 0x74,
  35752. 0x45, 0x4c, 0x9b, 0x81, 0x0c, 0x88, 0xd1, 0x70,
  35753. 0x1c, 0x8c, 0xc9, 0x8a, 0x1d, 0x4c, 0xa1, 0x07,
  35754. 0xa6, 0xb2, 0x5e, 0x96, 0x2f, 0xe4, 0xb6, 0xb0,
  35755. 0x3c, 0x95, 0x45, 0x32, 0x60, 0xb8, 0x07, 0x22,
  35756. 0x86, 0x37, 0xcc, 0x9e, 0xb1, 0x2a, 0xcc, 0x09,
  35757. 0x54, 0x95, 0x9a, 0x52, 0xae, 0x54, 0xd1, 0x97,
  35758. 0x73, 0x00, 0xab, 0xa0, 0xba, 0x2c, 0x14, 0x60,
  35759. 0x9b, 0xb2, 0x8c, 0x11, 0xd5, 0xfa, 0xc5, 0xca,
  35760. 0xc8, 0x82, 0x97, 0x60, 0x32, 0x83, 0xe8, 0x67,
  35761. 0xa3, 0x64, 0x83, 0x66, 0xc7, 0x24, 0xd9, 0x35,
  35762. 0x4c, 0xd7, 0xa1, 0x96, 0xdb, 0xd9, 0x80, 0x2f,
  35763. 0x7b, 0x88, 0xd3, 0xfa, 0x00, 0x1f, 0x9c, 0x97,
  35764. 0x73, 0x22, 0x54, 0x62, 0x23, 0x5e, 0x91, 0x35,
  35765. 0x2a, 0x20, 0x79, 0x1f, 0xd8, 0xb8, 0x7f, 0xe3,
  35766. 0x37, 0x7e, 0xc6, 0xa3, 0x94, 0x0b, 0x11, 0x30,
  35767. 0xa0, 0xbb, 0x04, 0xe7, 0x41, 0x0a, 0x34, 0xe2,
  35768. 0x58, 0x0d, 0x07, 0x1d, 0x6c, 0x56, 0x20, 0x20,
  35769. 0x86, 0x78, 0x7a, 0x65, 0x90, 0xf8, 0x43, 0x93,
  35770. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35771. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35772. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35773. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35774. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35775. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35776. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35777. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35778. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35779. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35780. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35781. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35782. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35783. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35784. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35785. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35786. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35787. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35788. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35789. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35790. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35791. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35792. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35793. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35794. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35795. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35796. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35797. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35798. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35799. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35800. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35801. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35802. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35803. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35804. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35805. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35806. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35807. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35808. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35809. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35810. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35811. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35812. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35813. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35814. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35815. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35816. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35817. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35818. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35819. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35820. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35821. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35822. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35823. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35824. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35825. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35826. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35827. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35828. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35829. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35830. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35831. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35832. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35833. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35834. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35835. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35836. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35837. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35838. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35839. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35840. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35841. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35842. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35843. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35844. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35845. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35846. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35847. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35848. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35849. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35850. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35851. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35852. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35853. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35854. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35855. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35856. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35857. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35858. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35859. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35860. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35861. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35862. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35863. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35864. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35865. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35866. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35867. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35868. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35869. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35870. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35871. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35872. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35873. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35874. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35875. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35876. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35877. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35878. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35879. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35880. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35881. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35882. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35883. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35884. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35885. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35886. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35887. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35888. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35889. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35890. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35891. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35892. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35893. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35894. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35895. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35896. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35897. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35898. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35899. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35900. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35901. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35902. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35903. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35904. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35905. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35906. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35907. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35908. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35909. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35910. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35911. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35912. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35913. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35914. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35915. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35916. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35917. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28,
  35918. 0xf5, 0x72, 0x62, 0x66, 0x13, 0x58, 0xcd, 0xe8,
  35919. 0xd3, 0xeb, 0xf9, 0x90, 0xe5, 0xfd, 0x1d, 0x5b,
  35920. 0x89, 0x6c, 0x99, 0x2c, 0xcf, 0xaa, 0xdb, 0x52,
  35921. 0x56, 0xb6, 0x8b, 0xbf, 0x59, 0x43, 0xb1, 0x32,
  35922. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  35923. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  35924. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  35925. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  35926. };
  35927. #endif
  35928. #ifdef WOLFSSL_KYBER_ORIGINAL
  35929. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ct[] = {
  35930. 0xB5, 0x2C, 0x56, 0xB9, 0x2A, 0x4B, 0x7C, 0xE9,
  35931. 0xE4, 0xCB, 0x7C, 0x5B, 0x1B, 0x16, 0x31, 0x67,
  35932. 0xA8, 0xA1, 0x67, 0x5B, 0x2F, 0xDE, 0xF8, 0x4A,
  35933. 0x5B, 0x67, 0xCA, 0x15, 0xDB, 0x69, 0x4C, 0x9F,
  35934. 0x11, 0xBD, 0x02, 0x7C, 0x30, 0xAE, 0x22, 0xEC,
  35935. 0x92, 0x1A, 0x1D, 0x91, 0x15, 0x99, 0xAF, 0x05,
  35936. 0x85, 0xE4, 0x8D, 0x20, 0xDA, 0x70, 0xDF, 0x9F,
  35937. 0x39, 0xE3, 0x2E, 0xF9, 0x5D, 0x4C, 0x8F, 0x44,
  35938. 0xBF, 0xEF, 0xDA, 0xA5, 0xDA, 0x64, 0xF1, 0x05,
  35939. 0x46, 0x31, 0xD0, 0x4D, 0x6D, 0x3C, 0xFD, 0x0A,
  35940. 0x54, 0x0D, 0xD7, 0xBA, 0x38, 0x86, 0xE4, 0xB5,
  35941. 0xF1, 0x3E, 0x87, 0x87, 0x88, 0x60, 0x4C, 0x95,
  35942. 0xC0, 0x96, 0xEA, 0xB3, 0x91, 0x9F, 0x42, 0x75,
  35943. 0x21, 0x41, 0x9A, 0x94, 0x6C, 0x26, 0xCC, 0x04,
  35944. 0x14, 0x75, 0xD7, 0x12, 0x4C, 0xDC, 0x01, 0xD0,
  35945. 0x37, 0x3E, 0x5B, 0x09, 0xC7, 0xA7, 0x06, 0x03,
  35946. 0xCF, 0xDB, 0x4F, 0xB3, 0x40, 0x50, 0x23, 0xF2,
  35947. 0x26, 0x4D, 0xC3, 0xF9, 0x83, 0xC4, 0xFC, 0x02,
  35948. 0xA2, 0xD1, 0xB2, 0x68, 0xF2, 0x20, 0x8A, 0x1F,
  35949. 0x6E, 0x2A, 0x62, 0x09, 0xBF, 0xF1, 0x2F, 0x6F,
  35950. 0x46, 0x5F, 0x0B, 0x06, 0x9C, 0x3A, 0x7F, 0x84,
  35951. 0xF6, 0x06, 0xD8, 0xA9, 0x40, 0x64, 0x00, 0x3D,
  35952. 0x6E, 0xC1, 0x14, 0xC8, 0xE8, 0x08, 0xD3, 0x05,
  35953. 0x38, 0x84, 0xC1, 0xD5, 0xA1, 0x42, 0xFB, 0xF2,
  35954. 0x01, 0x12, 0xEB, 0x36, 0x0F, 0xDA, 0x3F, 0x0F,
  35955. 0x28, 0xB1, 0x72, 0xAE, 0x50, 0xF5, 0xE7, 0xD8,
  35956. 0x38, 0x01, 0xFB, 0x3F, 0x00, 0x64, 0xB6, 0x87,
  35957. 0x18, 0x70, 0x74, 0xBD, 0x7F, 0xE3, 0x0E, 0xDD,
  35958. 0xAA, 0x33, 0x4C, 0xF8, 0xFC, 0x04, 0xFA, 0x8C,
  35959. 0xED, 0x89, 0x9C, 0xEA, 0xDE, 0x4B, 0x4F, 0x28,
  35960. 0xB6, 0x83, 0x72, 0xBA, 0xF9, 0x8F, 0xF4, 0x82,
  35961. 0xA4, 0x15, 0xB7, 0x31, 0x15, 0x5B, 0x75, 0xCE,
  35962. 0xB9, 0x76, 0xBE, 0x0E, 0xA0, 0x28, 0x5B, 0xA0,
  35963. 0x1A, 0x27, 0xF1, 0x85, 0x7A, 0x8F, 0xB3, 0x77,
  35964. 0xA3, 0xAE, 0x0C, 0x23, 0xB2, 0xAA, 0x9A, 0x07,
  35965. 0x9B, 0xFA, 0xBF, 0xF0, 0xD5, 0xB2, 0xF1, 0xCD,
  35966. 0x9B, 0x71, 0x8B, 0xEA, 0x03, 0xC4, 0x2F, 0x34,
  35967. 0x3A, 0x39, 0xB4, 0xF1, 0x42, 0xD0, 0x1A, 0xD8,
  35968. 0xAC, 0xBB, 0x50, 0xE3, 0x88, 0x53, 0xCF, 0x9A,
  35969. 0x50, 0xC8, 0xB4, 0x4C, 0x3C, 0xF6, 0x71, 0xA4,
  35970. 0xA9, 0x04, 0x3B, 0x26, 0xDD, 0xBB, 0x24, 0x95,
  35971. 0x9A, 0xD6, 0x71, 0x5C, 0x08, 0x52, 0x18, 0x55,
  35972. 0xC7, 0x9A, 0x23, 0xB9, 0xC3, 0xD6, 0x47, 0x17,
  35973. 0x49, 0xC4, 0x07, 0x25, 0xBD, 0xD5, 0xC2, 0x77,
  35974. 0x6D, 0x43, 0xAE, 0xD2, 0x02, 0x04, 0xBA, 0xA1,
  35975. 0x41, 0xEF, 0xB3, 0x30, 0x49, 0x17, 0x47, 0x4B,
  35976. 0x7F, 0x9F, 0x7A, 0x4B, 0x08, 0xB1, 0xA9, 0x3D,
  35977. 0xAE, 0xD9, 0x8C, 0x67, 0x49, 0x53, 0x59, 0xD3,
  35978. 0x7D, 0x67, 0xF7, 0x43, 0x8B, 0xEE, 0x5E, 0x43,
  35979. 0x58, 0x56, 0x34, 0xB2, 0x6C, 0x6B, 0x38, 0x10,
  35980. 0xD7, 0xCD, 0xCB, 0xC0, 0xF6, 0xEB, 0x87, 0x7A,
  35981. 0x60, 0x87, 0xE6, 0x8A, 0xCB, 0x84, 0x80, 0xD3,
  35982. 0xA8, 0xCF, 0x69, 0x00, 0x44, 0x7E, 0x49, 0xB4,
  35983. 0x17, 0xF1, 0x5A, 0x53, 0xB6, 0x07, 0xA0, 0xE2,
  35984. 0x16, 0xB8, 0x55, 0x97, 0x0D, 0x37, 0x40, 0x68,
  35985. 0x70, 0xB4, 0x56, 0x87, 0x22, 0xDA, 0x77, 0xA4,
  35986. 0x08, 0x47, 0x03, 0x81, 0x67, 0x84, 0xE2, 0xF1,
  35987. 0x6B, 0xED, 0x18, 0x99, 0x65, 0x32, 0xC5, 0xD8,
  35988. 0xB7, 0xF5, 0xD2, 0x14, 0x46, 0x4E, 0x5F, 0x3F,
  35989. 0x6E, 0x90, 0x58, 0x67, 0xB0, 0xCE, 0x11, 0x9E,
  35990. 0x25, 0x2A, 0x66, 0x71, 0x32, 0x53, 0x54, 0x46,
  35991. 0x85, 0xD2, 0x08, 0xE1, 0x72, 0x39, 0x08, 0xA0,
  35992. 0xCE, 0x97, 0x83, 0x46, 0x52, 0xE0, 0x8A, 0xE7,
  35993. 0xBD, 0xC8, 0x81, 0xA1, 0x31, 0xB7, 0x3C, 0x71,
  35994. 0xE8, 0x4D, 0x20, 0xD6, 0x8F, 0xDE, 0xFF, 0x4F,
  35995. 0x5D, 0x70, 0xCD, 0x1A, 0xF5, 0x7B, 0x78, 0xE3,
  35996. 0x49, 0x1A, 0x98, 0x65, 0x94, 0x23, 0x21, 0x80,
  35997. 0x0A, 0x20, 0x3C, 0x05, 0xED, 0x1F, 0xEE, 0xB5,
  35998. 0xA2, 0x8E, 0x58, 0x4E, 0x19, 0xF6, 0x53, 0x5E,
  35999. 0x7F, 0x84, 0xE4, 0xA2, 0x4F, 0x84, 0xA7, 0x2D,
  36000. 0xCA, 0xF5, 0x64, 0x8B, 0x4A, 0x42, 0x35, 0xDD,
  36001. 0x66, 0x44, 0x64, 0x48, 0x2F, 0x03, 0x17, 0x6E,
  36002. 0x88, 0x8C, 0x28, 0xBF, 0xC6, 0xC1, 0xCB, 0x23,
  36003. 0x8C, 0xFF, 0xA3, 0x5A, 0x32, 0x1E, 0x71, 0x79,
  36004. 0x1D, 0x9E, 0xA8, 0xED, 0x08, 0x78, 0xC6, 0x11,
  36005. 0x21, 0xBF, 0x8D, 0x2A, 0x4A, 0xB2, 0xC1, 0xA5,
  36006. 0xE1, 0x20, 0xBC, 0x40, 0xAB, 0xB1, 0x89, 0x2D,
  36007. 0x17, 0x15, 0x09, 0x0A, 0x0E, 0xE4, 0x82, 0x52,
  36008. 0xCA, 0x29, 0x7A, 0x99, 0xAA, 0x0E, 0x51, 0x0C,
  36009. 0xF2, 0x6B, 0x1A, 0xDD, 0x06, 0xCA, 0x54, 0x3E,
  36010. 0x1C, 0x5D, 0x6B, 0xDC, 0xD3, 0xB9, 0xC5, 0x85,
  36011. 0xC8, 0x53, 0x80, 0x45, 0xDB, 0x5C, 0x25, 0x2E,
  36012. 0xC3, 0xC8, 0xC3, 0xC9, 0x54, 0xD9, 0xBE, 0x59,
  36013. 0x07, 0x09, 0x4A, 0x89, 0x4E, 0x60, 0xEA, 0xB4,
  36014. 0x35, 0x38, 0xCF, 0xEE, 0x82, 0xE8, 0xFF, 0xC0,
  36015. 0x79, 0x1B, 0x0D, 0x0F, 0x43, 0xAC, 0x16, 0x27,
  36016. 0x83, 0x0A, 0x61, 0xD5, 0x6D, 0xAD, 0x96, 0xC6,
  36017. 0x29, 0x58, 0xB0, 0xDE, 0x78, 0x0B, 0x78, 0xBD,
  36018. 0x47, 0xA6, 0x04, 0x55, 0x0D, 0xAB, 0x83, 0xFF,
  36019. 0xF2, 0x27, 0xC3, 0x24, 0x04, 0x94, 0x71, 0xF3,
  36020. 0x52, 0x48, 0xCF, 0xB8, 0x49, 0xB2, 0x57, 0x24,
  36021. 0xFF, 0x70, 0x4D, 0x52, 0x77, 0xAA, 0x35, 0x2D,
  36022. 0x55, 0x09, 0x58, 0xBE, 0x3B, 0x23, 0x7D, 0xFF,
  36023. 0x47, 0x3E, 0xC2, 0xAD, 0xBA, 0xEA, 0x48, 0xCA,
  36024. 0x26, 0x58, 0xAE, 0xFC, 0xC7, 0x7B, 0xBD, 0x42,
  36025. 0x64, 0xAB, 0x37, 0x4D, 0x70, 0xEA, 0xE5, 0xB9,
  36026. 0x64, 0x41, 0x6C, 0xE8, 0x22, 0x6A, 0x7E, 0x32,
  36027. 0x55, 0xA0, 0xF8, 0xD7, 0xE2, 0xAD, 0xCA, 0x06,
  36028. 0x2B, 0xCD, 0x6D, 0x78, 0xD6, 0x0D, 0x1B, 0x32,
  36029. 0xE1, 0x14, 0x05, 0xBE, 0x54, 0xB6, 0x6E, 0xF0,
  36030. 0xFD, 0xDD, 0x56, 0x77, 0x02, 0xA3, 0xBC, 0xCF,
  36031. 0xED, 0xE3, 0xC5, 0x84, 0x70, 0x12, 0x69, 0xED,
  36032. 0x14, 0x80, 0x9F, 0x06, 0xF8, 0x96, 0x83, 0x56,
  36033. 0xBB, 0x92, 0x67, 0xFE, 0x86, 0xE5, 0x14, 0x25,
  36034. 0x2E, 0x88, 0xBB, 0x5C, 0x30, 0xA7, 0xEC, 0xB3,
  36035. 0xD0, 0xE6, 0x21, 0x02, 0x1E, 0xE0, 0xFB, 0xF7,
  36036. 0x87, 0x1B, 0x09, 0x34, 0x2B, 0xF8, 0x4F, 0x55,
  36037. 0xC9, 0x7E, 0xAF, 0x86, 0xC4, 0x81, 0x89, 0xC7,
  36038. 0xFF, 0x4D, 0xF3, 0x89, 0xF0, 0x77, 0xE2, 0x80,
  36039. 0x6E, 0x5F, 0xA7, 0x3B, 0x3E, 0x94, 0x58, 0xA1,
  36040. 0x6C, 0x7E, 0x27, 0x5F, 0x4F, 0x60, 0x22, 0x75,
  36041. 0x58, 0x0E, 0xB7, 0xB7, 0x13, 0x5F, 0xB5, 0x37,
  36042. 0xFA, 0x0C, 0xD9, 0x5D, 0x6E, 0xA5, 0x8C, 0x10,
  36043. 0x8C, 0xD8, 0x94, 0x3D, 0x70, 0xC1, 0x64, 0x31,
  36044. 0x11, 0xF4, 0xF0, 0x1C, 0xA8, 0xA8, 0x27, 0x6A,
  36045. 0x90, 0x26, 0x66, 0xED, 0x81, 0xB7, 0x8D, 0x16,
  36046. 0x8B, 0x00, 0x6F, 0x16, 0xAA, 0xA3, 0xD8, 0xE4,
  36047. 0xCE, 0x4F, 0x4D, 0x0F, 0xB0, 0x99, 0x7E, 0x41,
  36048. 0xAE, 0xFF, 0xB5, 0xB3, 0xDA, 0xA8, 0x38, 0x73,
  36049. 0x2F, 0x35, 0x73, 0x49, 0x44, 0x7F, 0x38, 0x77,
  36050. 0x76, 0xC7, 0x93, 0xC0, 0x47, 0x9D, 0xE9, 0xE9,
  36051. 0x94, 0x98, 0xCC, 0x35, 0x6F, 0xDB, 0x00, 0x75,
  36052. 0xA7, 0x03, 0xF2, 0x3C, 0x55, 0xD4, 0x7B, 0x55,
  36053. 0x0E, 0xC8, 0x9B, 0x02, 0xAD, 0xE8, 0x93, 0x29,
  36054. 0x08, 0x6A, 0x50, 0x84, 0x34, 0x56, 0xFE, 0xDC,
  36055. 0x37, 0x88, 0xAC, 0x8D, 0x97, 0x23, 0x3C, 0x54,
  36056. 0x56, 0x04, 0x67, 0xEE, 0x1D, 0x0F, 0x02, 0x4B,
  36057. 0x18, 0x42, 0x8F, 0x0D, 0x73, 0xB3, 0x0E, 0x19,
  36058. 0xF5, 0xC6, 0x3B, 0x9A, 0xBF, 0x11, 0x41, 0x5B,
  36059. 0xEA, 0x4D, 0x01, 0x70, 0x13, 0x0B, 0xAA, 0xBD,
  36060. 0x33, 0xC0, 0x5E, 0x65, 0x24, 0xE5, 0xFB, 0x55,
  36061. 0x81, 0xB2, 0x2B, 0x04, 0x33, 0x34, 0x22, 0x48,
  36062. 0x26, 0x6D, 0x0F, 0x10, 0x53, 0xB2, 0x45, 0xCC,
  36063. 0x24, 0x62, 0xDC, 0x44, 0xD3, 0x49, 0x65, 0x10,
  36064. 0x24, 0x82, 0xA8, 0xED, 0x9E, 0x4E, 0x96, 0x4D,
  36065. 0x56, 0x83, 0xE5, 0xD4, 0x5D, 0x0C, 0x82, 0x69
  36066. };
  36067. #endif
  36068. #ifndef WOLFSSL_NO_ML_KEM
  36069. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ct[] = {
  36070. 0xc8, 0x39, 0x10, 0x85, 0xb8, 0xd3, 0xea, 0x97,
  36071. 0x94, 0x21, 0x25, 0x41, 0xb2, 0x91, 0x4f, 0x08,
  36072. 0x96, 0x4d, 0x33, 0x52, 0x1d, 0x3f, 0x67, 0xad,
  36073. 0x66, 0x09, 0x6e, 0xbf, 0xb1, 0xf7, 0x06, 0x42,
  36074. 0x4b, 0x49, 0x55, 0x8f, 0x75, 0x5b, 0x56, 0x25,
  36075. 0xba, 0xe2, 0x36, 0xf2, 0xe0, 0x07, 0x96, 0x01,
  36076. 0xc7, 0x66, 0xf7, 0xd9, 0x60, 0x80, 0x8f, 0x7e,
  36077. 0x2b, 0xb0, 0xc7, 0xa5, 0xe0, 0x66, 0xed, 0x34,
  36078. 0x6d, 0xe6, 0x28, 0xf8, 0xc5, 0x7e, 0xeb, 0xab,
  36079. 0xbb, 0x0c, 0x22, 0xd9, 0x11, 0x54, 0x84, 0x63,
  36080. 0x69, 0x3e, 0xf3, 0xce, 0x52, 0xa5, 0x3f, 0x7f,
  36081. 0xf4, 0x15, 0xf0, 0x0e, 0x65, 0x7a, 0xe1, 0xc5,
  36082. 0xa4, 0x8f, 0xa5, 0xec, 0x6e, 0x4b, 0xe5, 0xcf,
  36083. 0x46, 0x2d, 0xaf, 0xfc, 0x84, 0xd2, 0xf6, 0xd5,
  36084. 0xff, 0x55, 0xdc, 0x9b, 0xbe, 0x8b, 0xb0, 0xd7,
  36085. 0x25, 0xec, 0x64, 0xfd, 0x4c, 0xd4, 0xbd, 0x8d,
  36086. 0xba, 0x0a, 0x84, 0x4e, 0x8b, 0x5c, 0xe4, 0xb6,
  36087. 0xa2, 0x89, 0x34, 0xd7, 0xf7, 0xa0, 0x50, 0x99,
  36088. 0x1f, 0xe1, 0x85, 0xb5, 0x06, 0xb4, 0x51, 0xda,
  36089. 0xbf, 0xad, 0x52, 0xd5, 0x2c, 0xb2, 0x11, 0x4c,
  36090. 0xa7, 0xd9, 0xa5, 0xcf, 0x98, 0x6c, 0x8f, 0xdc,
  36091. 0x1b, 0xc1, 0x0e, 0xc0, 0xc1, 0x86, 0x9e, 0x50,
  36092. 0xc0, 0x3c, 0x55, 0xa7, 0x61, 0x92, 0xa1, 0x04,
  36093. 0x9a, 0xca, 0x63, 0x6b, 0xa9, 0x02, 0x0b, 0xda,
  36094. 0xa8, 0xd0, 0xf5, 0x8c, 0x76, 0x3b, 0x0b, 0x89,
  36095. 0x84, 0x5c, 0xa0, 0x6d, 0x4c, 0x4d, 0xdc, 0x21,
  36096. 0x43, 0x3e, 0x16, 0xb9, 0xc6, 0x2e, 0x44, 0x87,
  36097. 0x1f, 0xdb, 0xc0, 0x5b, 0xa2, 0x18, 0xaf, 0x87,
  36098. 0x1f, 0xdd, 0x7d, 0xcf, 0xa4, 0x64, 0xe6, 0x0f,
  36099. 0xaa, 0x52, 0x65, 0x26, 0x4c, 0xe1, 0x39, 0x1b,
  36100. 0xd9, 0xa8, 0xc5, 0xfa, 0xa7, 0x62, 0x6d, 0x5f,
  36101. 0x15, 0x9b, 0x98, 0x05, 0xb9, 0x75, 0x71, 0x0a,
  36102. 0x35, 0x03, 0xa0, 0xb8, 0x58, 0xa1, 0x1c, 0x6a,
  36103. 0x64, 0x7c, 0xc0, 0xe1, 0x9a, 0xc8, 0x8b, 0x1b,
  36104. 0xe9, 0x05, 0x6c, 0x95, 0xb4, 0xd2, 0x08, 0x7d,
  36105. 0x09, 0x51, 0xd1, 0xd2, 0xf4, 0x99, 0x24, 0x91,
  36106. 0x11, 0x7e, 0x63, 0x47, 0x79, 0x4b, 0xa5, 0x45,
  36107. 0x71, 0xec, 0x49, 0xbb, 0xa7, 0x1a, 0xf3, 0x41,
  36108. 0x3d, 0x38, 0xa3, 0x0b, 0xf5, 0x87, 0x22, 0x48,
  36109. 0xd1, 0xf6, 0xd0, 0x7c, 0x86, 0xba, 0xf7, 0x82,
  36110. 0xe7, 0x3d, 0x26, 0x37, 0xf0, 0x43, 0xd3, 0x41,
  36111. 0xa0, 0x09, 0x21, 0x85, 0x7d, 0x8b, 0x21, 0xdd,
  36112. 0xf3, 0xe1, 0xd6, 0x31, 0x00, 0x36, 0xed, 0x27,
  36113. 0xaf, 0x49, 0xe5, 0xde, 0x1b, 0x90, 0x0f, 0xe4,
  36114. 0xde, 0x79, 0x80, 0x8f, 0xf2, 0x9f, 0x95, 0x70,
  36115. 0x85, 0x96, 0x12, 0xb1, 0x5a, 0xdc, 0x01, 0xfb,
  36116. 0xb2, 0x65, 0xb3, 0x05, 0xb1, 0xe3, 0xa1, 0x2a,
  36117. 0xe4, 0x19, 0xda, 0x5b, 0x74, 0x26, 0x1f, 0xa2,
  36118. 0x84, 0xc1, 0x01, 0xda, 0x3d, 0x8d, 0xca, 0x8b,
  36119. 0x2e, 0x45, 0x21, 0xac, 0xa5, 0x71, 0xef, 0x44,
  36120. 0xa0, 0x58, 0xe8, 0x44, 0xff, 0x32, 0xb1, 0x6d,
  36121. 0x5a, 0xae, 0xa0, 0x5f, 0x7f, 0x3a, 0xf8, 0xe2,
  36122. 0xab, 0x16, 0x22, 0x2e, 0x34, 0x76, 0x62, 0xed,
  36123. 0xdf, 0xb8, 0x91, 0xd0, 0xec, 0xc2, 0xa5, 0x5c,
  36124. 0x56, 0x38, 0xf9, 0xdd, 0xe9, 0x2d, 0x9a, 0x3d,
  36125. 0x54, 0x4a, 0x5f, 0x90, 0x1a, 0xc5, 0x01, 0xac,
  36126. 0xd1, 0xea, 0x6a, 0x01, 0x02, 0x01, 0xfc, 0xb1,
  36127. 0x0a, 0xd7, 0x02, 0xc4, 0x25, 0xa9, 0x4b, 0xdf,
  36128. 0x58, 0x90, 0xd5, 0x00, 0xa2, 0xa1, 0x47, 0xee,
  36129. 0xe1, 0xd1, 0xfc, 0xba, 0x8c, 0x3a, 0xbe, 0x7c,
  36130. 0x2d, 0xfe, 0x70, 0xf3, 0x46, 0xf0, 0x33, 0xd8,
  36131. 0x16, 0xa0, 0xb2, 0x79, 0x1b, 0x4f, 0x0b, 0x2d,
  36132. 0x95, 0x6d, 0x9e, 0xe5, 0x97, 0x17, 0x15, 0x39,
  36133. 0x9a, 0x56, 0x88, 0x30, 0x24, 0x95, 0xe2, 0xe0,
  36134. 0x7c, 0x1c, 0x8c, 0x01, 0x52, 0x71, 0x84, 0xbc,
  36135. 0xd0, 0xc2, 0x08, 0xbc, 0x15, 0x9f, 0x2e, 0x13,
  36136. 0x31, 0x8c, 0x0b, 0xb3, 0xdd, 0x24, 0xa6, 0xa7,
  36137. 0xfc, 0x84, 0x9f, 0x83, 0x38, 0x5e, 0xd4, 0xdb,
  36138. 0xa0, 0x7f, 0xe1, 0xd7, 0xbd, 0x56, 0x40, 0xcc,
  36139. 0x9e, 0xd5, 0xcc, 0xfd, 0xd6, 0x87, 0x63, 0xcb,
  36140. 0x0d, 0x0e, 0xdf, 0x61, 0xb2, 0x92, 0x17, 0x7f,
  36141. 0xc1, 0xd2, 0xd3, 0xc1, 0x1d, 0xd0, 0x49, 0x50,
  36142. 0x56, 0xbc, 0xb1, 0x25, 0x58, 0xae, 0xbc, 0xfd,
  36143. 0xde, 0xf9, 0xfe, 0xb4, 0xae, 0xbc, 0x57, 0xaf,
  36144. 0xd9, 0x02, 0x3c, 0x65, 0xcf, 0xe6, 0x5a, 0x24,
  36145. 0xe3, 0x3f, 0x1b, 0x00, 0x11, 0x1e, 0x92, 0xe6,
  36146. 0x3e, 0x01, 0x1e, 0xaf, 0x0b, 0x21, 0x2c, 0xf9,
  36147. 0x57, 0x43, 0xcd, 0x07, 0xf5, 0x18, 0x9e, 0xce,
  36148. 0x1f, 0x20, 0x5b, 0x7f, 0x6f, 0xcb, 0x2e, 0x6b,
  36149. 0x19, 0x61, 0xb5, 0x40, 0x4c, 0xeb, 0xe4, 0x7c,
  36150. 0x8c, 0xd1, 0x3b, 0x85, 0x99, 0xd5, 0xb4, 0x9e,
  36151. 0x6d, 0x87, 0xee, 0xda, 0x36, 0xe9, 0xb8, 0xfc,
  36152. 0x4c, 0x00, 0x63, 0x58, 0x96, 0xaa, 0x2b, 0x75,
  36153. 0x89, 0x6e, 0x33, 0x6d, 0x1b, 0x61, 0x2e, 0xe1,
  36154. 0x3d, 0xb8, 0x11, 0xe1, 0xf0, 0x7e, 0x61, 0x74,
  36155. 0x8d, 0x92, 0x0f, 0x48, 0x65, 0xf3, 0xf1, 0x17,
  36156. 0x41, 0x39, 0x9d, 0xc6, 0x16, 0x2c, 0x91, 0xca,
  36157. 0x16, 0x8a, 0x02, 0x32, 0x9d, 0xff, 0x82, 0x1d,
  36158. 0x58, 0x19, 0x87, 0x12, 0xdd, 0x55, 0x8a, 0xbb,
  36159. 0x09, 0x9b, 0x3a, 0x0b, 0xaf, 0x9d, 0xa1, 0xb7,
  36160. 0x30, 0xb2, 0xaa, 0x73, 0xbc, 0xf5, 0x8d, 0x74,
  36161. 0xf3, 0x57, 0xb0, 0x6f, 0x72, 0x11, 0xc8, 0x04,
  36162. 0xb6, 0xc8, 0xaf, 0x16, 0xff, 0x35, 0x09, 0xfa,
  36163. 0xd1, 0xd3, 0x5b, 0x14, 0xbf, 0xdc, 0xed, 0x7d,
  36164. 0xb8, 0xa6, 0xa2, 0x5c, 0x48, 0xe5, 0x95, 0x64,
  36165. 0x80, 0x72, 0x4d, 0xaa, 0x05, 0x7c, 0xd6, 0x60,
  36166. 0xb6, 0x7e, 0xe3, 0xe4, 0x72, 0x57, 0x41, 0x82,
  36167. 0x67, 0x9d, 0x48, 0x58, 0x38, 0xa6, 0x47, 0x6e,
  36168. 0xac, 0x02, 0x14, 0x10, 0x75, 0xc8, 0x12, 0xaf,
  36169. 0x79, 0x67, 0xba, 0x7c, 0x91, 0x85, 0xcc, 0x2a,
  36170. 0xbd, 0x2a, 0x45, 0x45, 0xb8, 0x0f, 0x3d, 0x31,
  36171. 0x04, 0xd5, 0x8d, 0x65, 0x4a, 0x57, 0x79, 0x2d,
  36172. 0xcf, 0xab, 0xbe, 0x9c, 0x07, 0x15, 0xe8, 0xde,
  36173. 0x2e, 0xf8, 0x1e, 0xf4, 0x04, 0xc8, 0x16, 0x8f,
  36174. 0xd7, 0xa4, 0x3e, 0xfa, 0xb3, 0xd4, 0x48, 0xe6,
  36175. 0x86, 0xa0, 0x88, 0xef, 0xd2, 0x6a, 0x26, 0x15,
  36176. 0x99, 0x48, 0x92, 0x67, 0x23, 0xd7, 0xec, 0xcc,
  36177. 0x39, 0xe3, 0xc1, 0xb7, 0x19, 0xcf, 0x8b, 0xec,
  36178. 0xb7, 0xbe, 0x7e, 0x96, 0x4f, 0x22, 0xcd, 0x8c,
  36179. 0xb1, 0xb7, 0xe2, 0x5e, 0x80, 0x0e, 0xa9, 0x7d,
  36180. 0x60, 0xa6, 0x4c, 0xc0, 0xbb, 0xd9, 0xcb, 0x40,
  36181. 0x7a, 0x3a, 0xb9, 0xf8, 0x8f, 0x5e, 0x29, 0x16,
  36182. 0x9e, 0xea, 0xfd, 0x4e, 0x03, 0x22, 0xfd, 0xe6,
  36183. 0x59, 0x0a, 0xe0, 0x93, 0xce, 0x8f, 0xee, 0xae,
  36184. 0x98, 0xb6, 0x22, 0xca, 0xa7, 0x55, 0x6f, 0xf4,
  36185. 0x26, 0xc9, 0xe7, 0xa4, 0x04, 0xce, 0x69, 0x35,
  36186. 0x58, 0x30, 0xa7, 0xa6, 0x77, 0x67, 0xa7, 0x6c,
  36187. 0x7d, 0x9a, 0x97, 0xb8, 0x4b, 0xfc, 0xf5, 0x0a,
  36188. 0x02, 0xf7, 0x5c, 0x23, 0x5d, 0x2f, 0x9c, 0x67,
  36189. 0x11, 0x38, 0x04, 0x9f, 0xfc, 0x7c, 0x80, 0x55,
  36190. 0x92, 0x6c, 0x03, 0xeb, 0x3f, 0xb8, 0x7f, 0x96,
  36191. 0x95, 0x18, 0x5a, 0x42, 0xec, 0xa9, 0xa4, 0x16,
  36192. 0x55, 0x87, 0x3d, 0x30, 0xa6, 0xb3, 0xbf, 0x42,
  36193. 0x8b, 0x24, 0x62, 0x23, 0x48, 0x4a, 0x8f, 0xf6,
  36194. 0x1e, 0xe3, 0xee, 0xaf, 0xff, 0x10, 0xe9, 0x9c,
  36195. 0x2c, 0x13, 0xa7, 0x62, 0x84, 0xd0, 0x63, 0xe5,
  36196. 0x6a, 0xb7, 0x11, 0xa3, 0x5a, 0x85, 0xb5, 0x38,
  36197. 0x3d, 0xf8, 0x1d, 0xa2, 0x34, 0x90, 0xf6, 0x6e,
  36198. 0x8e, 0xa3, 0xfc, 0xba, 0x06, 0x7f, 0x55, 0x30,
  36199. 0xc6, 0x54, 0x1c, 0x2b, 0x8f, 0x74, 0x71, 0x7c,
  36200. 0x35, 0x02, 0x3e, 0x7b, 0x9b, 0x39, 0x56, 0xc3,
  36201. 0xee, 0x2f, 0xf8, 0x4b, 0xa0, 0x3c, 0xcf, 0x4b,
  36202. 0x4b, 0x53, 0x21, 0xb9, 0x24, 0x08, 0x95, 0x48,
  36203. 0x1b, 0xc6, 0xd6, 0x3c, 0x16, 0x93, 0xc1, 0x84,
  36204. 0x78, 0x52, 0xf8, 0xe9, 0x7f, 0x50, 0xa1, 0x33,
  36205. 0x53, 0x2a, 0xc3, 0xee, 0x1e, 0x52, 0xd4, 0x64
  36206. };
  36207. #endif
  36208. #ifdef WOLFSSL_KYBER_ORIGINAL
  36209. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ss[] = {
  36210. 0x91, 0x4C, 0xB6, 0x7F, 0xE5, 0xC3, 0x8E, 0x73,
  36211. 0xBF, 0x74, 0x18, 0x1C, 0x0A, 0xC5, 0x04, 0x28,
  36212. 0xDE, 0xDF, 0x77, 0x50, 0xA9, 0x80, 0x58, 0xF7,
  36213. 0xD5, 0x36, 0x70, 0x87, 0x74, 0x53, 0x5B, 0x29
  36214. };
  36215. #endif
  36216. #ifndef WOLFSSL_NO_ML_KEM
  36217. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ss[] = {
  36218. 0xe7, 0x18, 0x4a, 0x09, 0x75, 0xee, 0x34, 0x70,
  36219. 0x87, 0x8d, 0x2d, 0x15, 0x9e, 0xc8, 0x31, 0x29,
  36220. 0xc8, 0xae, 0xc2, 0x53, 0xd4, 0xee, 0x17, 0xb4,
  36221. 0x81, 0x03, 0x11, 0xd1, 0x98, 0xcd, 0x03, 0x68
  36222. };
  36223. #endif
  36224. #ifdef WOLFSSL_SMALL_STACK
  36225. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  36226. DYNAMIC_TYPE_TMP_BUFFER);
  36227. priv = (byte *)XMALLOC(KYBER768_PRIVATE_KEY_SIZE, HEAP_HINT,
  36228. DYNAMIC_TYPE_TMP_BUFFER);
  36229. pub = (byte *)XMALLOC(KYBER768_PUBLIC_KEY_SIZE, HEAP_HINT,
  36230. DYNAMIC_TYPE_TMP_BUFFER);
  36231. ct = (byte *)XMALLOC(KYBER768_CIPHER_TEXT_SIZE, HEAP_HINT,
  36232. DYNAMIC_TYPE_TMP_BUFFER);
  36233. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36234. DYNAMIC_TYPE_TMP_BUFFER);
  36235. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36236. DYNAMIC_TYPE_TMP_BUFFER);
  36237. if (! (key && priv && pub && ct && ss && ss_dec))
  36238. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  36239. #endif
  36240. #ifdef WOLFSSL_KYBER_ORIGINAL
  36241. ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
  36242. if (ret != 0)
  36243. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36244. else
  36245. key_inited = 1;
  36246. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36247. sizeof(kyber768_rand));
  36248. if (ret != 0)
  36249. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36250. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
  36251. if (ret != 0)
  36252. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36253. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
  36254. if (ret != 0)
  36255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36256. if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0)
  36257. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36258. if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
  36259. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36260. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36261. sizeof(kyber768enc_rand));
  36262. if (ret != 0)
  36263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36264. if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0)
  36265. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36266. if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36267. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36268. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
  36269. if (ret != 0)
  36270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36271. if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36272. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36273. #endif
  36274. #ifndef WOLFSSL_NO_ML_KEM
  36275. ret = wc_KyberKey_Init(WC_ML_KEM_768, key, HEAP_HINT, INVALID_DEVID);
  36276. if (ret != 0)
  36277. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36278. else
  36279. key_inited = 1;
  36280. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36281. sizeof(kyber768_rand));
  36282. if (ret != 0)
  36283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36284. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_768_PUBLIC_KEY_SIZE);
  36285. if (ret != 0)
  36286. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36287. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  36288. WC_ML_KEM_768_PRIVATE_KEY_SIZE);
  36289. if (ret != 0)
  36290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36291. if (XMEMCMP(pub, ml_kem_768_pk, sizeof(ml_kem_768_pk)) != 0)
  36292. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36293. if (XMEMCMP(priv, ml_kem_768_sk, sizeof(ml_kem_768_sk)) != 0)
  36294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36295. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36296. sizeof(kyber768enc_rand));
  36297. if (ret != 0)
  36298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36299. if (XMEMCMP(ct, ml_kem_768_ct, sizeof(ml_kem_768_ct)) != 0)
  36300. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36301. if (XMEMCMP(ss, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36303. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_768_ct));
  36304. if (ret != 0)
  36305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36306. if (XMEMCMP(ss_dec, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36307. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36308. #endif
  36309. out:
  36310. if (key_inited)
  36311. wc_KyberKey_Free(key);
  36312. #ifdef WOLFSSL_SMALL_STACK
  36313. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36314. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36315. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36316. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36317. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36318. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36319. #endif
  36320. return ret;
  36321. }
  36322. #endif /* WOLFSSL_KYBER768 */
  36323. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  36324. static wc_test_ret_t kyber1024_kat(void)
  36325. {
  36326. wc_test_ret_t ret;
  36327. #ifdef WOLFSSL_SMALL_STACK
  36328. KyberKey *key = NULL;
  36329. byte *priv = NULL;
  36330. byte *pub = NULL;
  36331. byte *ct = NULL;
  36332. byte *ss = NULL;
  36333. byte *ss_dec = NULL;
  36334. #else
  36335. KyberKey key[1];
  36336. byte priv[KYBER1024_PRIVATE_KEY_SIZE];
  36337. byte pub[KYBER1024_PUBLIC_KEY_SIZE];
  36338. byte ct[KYBER1024_CIPHER_TEXT_SIZE];
  36339. byte ss[KYBER_SS_SZ];
  36340. byte ss_dec[KYBER_SS_SZ];
  36341. #endif
  36342. int key_inited = 0;
  36343. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_rand[] = {
  36344. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  36345. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  36346. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  36347. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  36348. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  36349. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  36350. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  36351. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  36352. };
  36353. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024enc_rand[] = {
  36354. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  36355. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  36356. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  36357. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  36358. };
  36359. #ifdef WOLFSSL_KYBER_ORIGINAL
  36360. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_pk[] = {
  36361. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36362. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36363. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36364. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36365. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36366. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36367. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36368. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36369. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36370. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36371. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36372. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36373. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36374. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36375. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36376. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36377. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36378. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36379. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36380. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36381. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36382. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36383. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36384. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36385. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36386. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36387. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36388. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36389. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36390. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36391. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36392. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36393. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36394. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36395. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36396. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36397. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36398. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36399. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36400. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36401. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36402. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36403. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36404. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36405. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36406. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36407. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36408. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36409. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36410. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36411. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36412. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36413. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36414. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36415. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36416. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36417. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36418. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36419. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36420. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36421. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36422. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36423. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36424. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36425. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36426. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36427. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36428. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36429. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36430. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36431. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36432. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36433. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36434. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36435. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36436. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36437. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36438. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36439. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36440. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36441. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36442. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36443. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36444. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36445. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36446. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36447. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36448. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36449. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36450. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36451. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36452. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36453. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36454. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36455. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36456. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36457. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36458. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36459. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36460. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36461. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36462. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36463. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36464. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36465. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36466. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36467. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36468. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36469. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36470. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36471. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36472. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36473. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36474. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36475. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36476. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36477. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36478. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36479. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36480. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36481. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36482. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36483. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36484. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36485. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36486. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36487. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36488. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36489. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36490. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36491. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36492. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36493. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36494. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36495. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36496. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36497. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36498. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36499. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36500. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36501. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36502. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36503. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36504. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36505. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36506. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36507. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36508. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36509. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36510. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36511. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36512. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36513. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36514. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36515. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36516. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36517. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36518. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36519. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36520. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36521. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36522. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36523. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36524. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36525. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36526. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36527. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36528. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36529. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36530. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36531. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36532. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36533. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36534. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36535. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36536. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36537. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36538. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36539. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36540. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36541. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36542. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36543. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36544. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36545. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36546. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36547. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36548. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36549. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36550. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36551. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36552. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36553. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36554. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36555. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36556. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  36557. };
  36558. #endif
  36559. #ifndef WOLFSSL_NO_ML_KEM
  36560. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_pk[] = {
  36561. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36562. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36563. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36564. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36565. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36566. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36567. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36568. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36569. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36570. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36571. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36572. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36573. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36574. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36575. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36576. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36577. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36578. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36579. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36580. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36581. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36582. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36583. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36584. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36585. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36586. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36587. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36588. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36589. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36590. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36591. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36592. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36593. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36594. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36595. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36596. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36597. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36598. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36599. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36600. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36601. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36602. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36603. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36604. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36605. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36606. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36607. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36608. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36609. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36610. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36611. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36612. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36613. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36614. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36615. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36616. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36617. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36618. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36619. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36620. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36621. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36622. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36623. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36624. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36625. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36626. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36627. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36628. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36629. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36630. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36631. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36632. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36633. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36634. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36635. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36636. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36637. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36638. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36639. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36640. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36641. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36642. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36643. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36644. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36645. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36646. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36647. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36648. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36649. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36650. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36651. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36652. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36653. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36654. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36655. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36656. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36657. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36658. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36659. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36660. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36661. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36662. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  36663. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  36664. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  36665. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  36666. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  36667. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  36668. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  36669. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  36670. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  36671. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  36672. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  36673. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  36674. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  36675. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  36676. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  36677. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  36678. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  36679. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  36680. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  36681. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  36682. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  36683. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  36684. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  36685. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  36686. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  36687. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  36688. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  36689. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  36690. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  36691. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  36692. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  36693. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  36694. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  36695. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  36696. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  36697. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  36698. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  36699. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  36700. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  36701. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  36702. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  36703. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  36704. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  36705. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  36706. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  36707. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  36708. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  36709. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  36710. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  36711. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  36712. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  36713. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  36714. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  36715. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  36716. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  36717. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  36718. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  36719. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  36720. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  36721. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  36722. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  36723. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  36724. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  36725. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  36726. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  36727. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  36728. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  36729. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  36730. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  36731. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  36732. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  36733. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  36734. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  36735. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  36736. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  36737. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  36738. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  36739. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  36740. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  36741. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  36742. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  36743. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  36744. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  36745. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  36746. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  36747. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  36748. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  36749. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  36750. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  36751. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  36752. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  36753. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  36754. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  36755. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  36756. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb
  36757. };
  36758. #endif
  36759. #ifdef WOLFSSL_KYBER_ORIGINAL
  36760. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_sk[] = {
  36761. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  36762. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  36763. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  36764. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  36765. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  36766. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  36767. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  36768. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  36769. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  36770. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  36771. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  36772. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  36773. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  36774. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  36775. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  36776. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  36777. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  36778. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  36779. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  36780. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  36781. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  36782. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  36783. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  36784. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  36785. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  36786. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  36787. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  36788. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  36789. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  36790. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  36791. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  36792. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  36793. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  36794. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  36795. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  36796. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  36797. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  36798. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  36799. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  36800. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  36801. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  36802. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  36803. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  36804. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  36805. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  36806. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  36807. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  36808. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  36809. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  36810. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  36811. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  36812. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  36813. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  36814. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  36815. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  36816. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  36817. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  36818. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  36819. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  36820. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  36821. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  36822. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  36823. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  36824. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  36825. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  36826. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  36827. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  36828. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  36829. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  36830. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  36831. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  36832. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  36833. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  36834. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  36835. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  36836. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  36837. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  36838. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  36839. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  36840. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  36841. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  36842. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  36843. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  36844. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  36845. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  36846. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  36847. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  36848. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  36849. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  36850. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  36851. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  36852. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  36853. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  36854. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  36855. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  36856. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  36857. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  36858. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  36859. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  36860. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  36861. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  36862. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  36863. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  36864. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  36865. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  36866. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  36867. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  36868. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  36869. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  36870. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  36871. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  36872. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  36873. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  36874. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  36875. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  36876. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  36877. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  36878. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  36879. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  36880. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  36881. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  36882. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  36883. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  36884. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  36885. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  36886. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  36887. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  36888. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  36889. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  36890. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  36891. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  36892. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  36893. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  36894. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  36895. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  36896. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  36897. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  36898. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  36899. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  36900. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  36901. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  36902. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  36903. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  36904. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  36905. 0x85, 0xA4, 0xC1, 0xA1, 0xAB, 0x9B, 0x6A, 0xEB,
  36906. 0x49, 0xCC, 0xE1, 0xC2, 0xF8, 0xA9, 0x7C, 0x35,
  36907. 0x16, 0xC7, 0x2A, 0x00, 0xA4, 0x62, 0x63, 0xBA,
  36908. 0xA6, 0x96, 0xBF, 0x25, 0x72, 0x77, 0x19, 0xC3,
  36909. 0x21, 0x64, 0x23, 0x61, 0x8F, 0xF3, 0x33, 0x80,
  36910. 0x93, 0x4A, 0x6C, 0x10, 0x54, 0x5C, 0x4C, 0x5C,
  36911. 0x51, 0x55, 0xB1, 0x24, 0x86, 0x18, 0x1F, 0xC7,
  36912. 0xA2, 0x31, 0x98, 0x73, 0x97, 0x8B, 0x6A, 0x2A,
  36913. 0x67, 0x49, 0x0F, 0x82, 0x56, 0xBD, 0x21, 0x96,
  36914. 0xFE, 0x17, 0x92, 0xA4, 0xC0, 0x00, 0x77, 0xB8,
  36915. 0x12, 0xEA, 0xE8, 0xBE, 0xD3, 0x57, 0x24, 0x99,
  36916. 0x68, 0x4A, 0xB3, 0x37, 0x18, 0x76, 0x76, 0x1E,
  36917. 0x45, 0x0C, 0x9F, 0x9D, 0x27, 0x68, 0xA3, 0x68,
  36918. 0x06, 0xD7, 0xAB, 0x20, 0x46, 0xC9, 0x1F, 0x17,
  36919. 0x59, 0x9E, 0x9A, 0xC5, 0x92, 0x99, 0x08, 0x08,
  36920. 0xDC, 0xD7, 0xB4, 0xD0, 0x91, 0x90, 0x72, 0xF1,
  36921. 0x4E, 0xC3, 0x61, 0x77, 0x3B, 0x72, 0x52, 0x44,
  36922. 0x4C, 0x32, 0x3C, 0x30, 0x83, 0x26, 0xF4, 0xA3,
  36923. 0x0F, 0x86, 0x80, 0xD2, 0xF7, 0x48, 0xF5, 0x6A,
  36924. 0x13, 0x2B, 0x82, 0x67, 0x4E, 0xD0, 0x18, 0x46,
  36925. 0x20, 0xB8, 0x2A, 0xD2, 0xCB, 0x18, 0x2C, 0x97,
  36926. 0xB4, 0x81, 0x62, 0x66, 0x47, 0x49, 0x12, 0x90,
  36927. 0xA0, 0x11, 0xCC, 0x73, 0x82, 0x86, 0x85, 0xA8,
  36928. 0xC3, 0x67, 0xA5, 0xB9, 0xCF, 0x8D, 0x62, 0x1B,
  36929. 0x0D, 0x5C, 0x1E, 0xFF, 0x03, 0x17, 0x27, 0x58,
  36930. 0xBD, 0x00, 0x49, 0x78, 0xC2, 0x51, 0xCD, 0x51,
  36931. 0x34, 0x22, 0x28, 0x98, 0x9C, 0xAE, 0x63, 0x32,
  36932. 0xAC, 0x48, 0x64, 0x37, 0xCB, 0x5C, 0x57, 0xD4,
  36933. 0x30, 0x74, 0x62, 0x86, 0x52, 0x53, 0xBE, 0x21,
  36934. 0x7B, 0x35, 0x15, 0xC7, 0x3D, 0xF4, 0x05, 0xB7,
  36935. 0xF2, 0x82, 0x17, 0xAD, 0x0B, 0x8C, 0xF6, 0x0C,
  36936. 0x2F, 0xFF, 0xAA, 0x0A, 0x00, 0x48, 0xB1, 0xFB,
  36937. 0x4A, 0xCD, 0xCD, 0xC3, 0x8B, 0x52, 0x50, 0xCF,
  36938. 0xEC, 0x35, 0x6A, 0x6D, 0xE2, 0x6C, 0xFA, 0x7A,
  36939. 0x58, 0x8F, 0xDC, 0x86, 0xF9, 0x8C, 0x85, 0x4A,
  36940. 0xC6, 0x4C, 0x7B, 0xFA, 0xA9, 0x6F, 0x5A, 0x32,
  36941. 0xCC, 0x06, 0x10, 0x93, 0x4B, 0xAA, 0x6A, 0x58,
  36942. 0x6B, 0x9A, 0x20, 0x54, 0xF1, 0x3B, 0xA2, 0x74,
  36943. 0x17, 0x4A, 0xA0, 0xD2, 0xB3, 0xA8, 0x1B, 0x96,
  36944. 0xA9, 0x40, 0x66, 0x6F, 0x78, 0x9B, 0x5A, 0x6B,
  36945. 0xCD, 0xC0, 0xA6, 0xA0, 0x17, 0x8A, 0x0C, 0x9A,
  36946. 0x02, 0x57, 0x8A, 0x49, 0x3F, 0x6E, 0xEA, 0x0D,
  36947. 0x2E, 0x6C, 0x13, 0x95, 0x1C, 0x9F, 0x24, 0x9A,
  36948. 0x5E, 0x8D, 0xD7, 0x1D, 0xD4, 0x9A, 0x74, 0x2D,
  36949. 0x45, 0x1F, 0x1A, 0xBB, 0xA1, 0x9A, 0xF8, 0xC5,
  36950. 0x47, 0x85, 0x5E, 0x0A, 0xFC, 0x72, 0x8E, 0x90,
  36951. 0xAB, 0xB4, 0x99, 0xC9, 0xBE, 0xEB, 0x76, 0x6F,
  36952. 0x47, 0x29, 0xCD, 0xA2, 0x22, 0x63, 0xE3, 0x24,
  36953. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36954. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36955. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36956. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36957. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36958. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36959. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36960. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36961. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36962. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36963. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36964. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36965. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36966. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36967. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36968. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36969. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36970. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36971. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36972. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36973. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36974. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36975. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36976. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36977. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36978. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36979. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36980. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36981. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36982. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36983. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36984. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36985. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36986. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36987. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36988. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36989. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36990. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36991. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36992. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36993. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36994. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36995. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36996. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36997. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36998. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36999. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  37000. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  37001. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  37002. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  37003. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  37004. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  37005. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  37006. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  37007. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  37008. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  37009. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  37010. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  37011. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  37012. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  37013. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  37014. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  37015. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  37016. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  37017. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  37018. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  37019. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  37020. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  37021. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  37022. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  37023. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  37024. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  37025. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  37026. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  37027. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  37028. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  37029. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  37030. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  37031. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  37032. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  37033. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  37034. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  37035. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  37036. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  37037. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  37038. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  37039. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  37040. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  37041. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  37042. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  37043. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  37044. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  37045. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  37046. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  37047. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  37048. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  37049. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  37050. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  37051. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  37052. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  37053. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  37054. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  37055. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  37056. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  37057. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  37058. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  37059. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  37060. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  37061. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  37062. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  37063. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  37064. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  37065. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  37066. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  37067. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  37068. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  37069. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  37070. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  37071. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  37072. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  37073. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  37074. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  37075. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  37076. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  37077. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  37078. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  37079. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  37080. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  37081. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  37082. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  37083. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  37084. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  37085. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  37086. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  37087. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  37088. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  37089. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  37090. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  37091. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  37092. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  37093. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  37094. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  37095. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  37096. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  37097. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  37098. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  37099. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  37100. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  37101. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  37102. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  37103. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  37104. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  37105. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  37106. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  37107. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  37108. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  37109. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  37110. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  37111. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  37112. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  37113. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  37114. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  37115. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  37116. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  37117. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  37118. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  37119. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  37120. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  37121. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  37122. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  37123. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  37124. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  37125. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  37126. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  37127. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  37128. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  37129. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  37130. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  37131. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  37132. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  37133. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  37134. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  37135. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  37136. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  37137. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  37138. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  37139. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  37140. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  37141. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  37142. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  37143. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  37144. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  37145. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  37146. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  37147. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  37148. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  37149. 0x8A, 0x39, 0xE8, 0x7D, 0x53, 0x1F, 0x35, 0x27,
  37150. 0xC2, 0x07, 0xED, 0xCC, 0x1D, 0xB7, 0xFA, 0xDD,
  37151. 0xCF, 0x96, 0x28, 0x39, 0x18, 0x79, 0xB3, 0x35,
  37152. 0xC7, 0x07, 0x83, 0x9A, 0x0D, 0xB0, 0x51, 0xA8,
  37153. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  37154. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  37155. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  37156. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  37157. };
  37158. #endif
  37159. #ifndef WOLFSSL_NO_ML_KEM
  37160. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_sk[] = {
  37161. 0x43, 0x3a, 0x70, 0xee, 0x69, 0x50, 0xf9, 0x88,
  37162. 0x2a, 0xcd, 0xd5, 0xa4, 0x78, 0x20, 0xa6, 0xa8,
  37163. 0x16, 0x37, 0x08, 0xf0, 0x4d, 0x45, 0x7c, 0x77,
  37164. 0x99, 0x79, 0xb8, 0x3f, 0xe1, 0x17, 0x22, 0x47,
  37165. 0x01, 0x49, 0x08, 0x30, 0x38, 0x66, 0x37, 0xda,
  37166. 0x33, 0x2e, 0x74, 0xb1, 0xae, 0xda, 0x0b, 0x2f,
  37167. 0x81, 0xca, 0x4f, 0x9b, 0xb2, 0xc2, 0xb0, 0x2b,
  37168. 0x0c, 0xfd, 0x68, 0x0c, 0x11, 0x48, 0x2f, 0x33,
  37169. 0x5a, 0xcf, 0x7b, 0x91, 0x39, 0xb5, 0xb8, 0x8a,
  37170. 0x34, 0xe3, 0x54, 0x2c, 0x68, 0x61, 0x37, 0x75,
  37171. 0x45, 0x98, 0x33, 0x43, 0xcd, 0x82, 0x94, 0x14,
  37172. 0xe4, 0x78, 0x64, 0x21, 0x2e, 0x78, 0xf8, 0x55,
  37173. 0xf5, 0x23, 0x90, 0x37, 0x9a, 0xcc, 0x3a, 0x62,
  37174. 0x95, 0x31, 0x31, 0xb6, 0x3e, 0xe8, 0x32, 0xad,
  37175. 0xb3, 0xbf, 0x4b, 0xf5, 0x8e, 0x24, 0x73, 0x49,
  37176. 0xb5, 0xe0, 0x97, 0xe5, 0x5a, 0xbe, 0x49, 0x7b,
  37177. 0x15, 0x98, 0x23, 0x73, 0xae, 0x73, 0x2e, 0x04,
  37178. 0x39, 0xac, 0x67, 0xd0, 0x5c, 0x7f, 0x03, 0x7c,
  37179. 0x8a, 0x73, 0x9b, 0x18, 0x14, 0x0e, 0x14, 0x4c,
  37180. 0x85, 0x1d, 0xc9, 0x61, 0x1f, 0x4b, 0xcf, 0x04,
  37181. 0xf3, 0xa2, 0x09, 0x3c, 0x19, 0x7b, 0xd6, 0x3b,
  37182. 0xb5, 0xe6, 0x19, 0x01, 0x00, 0x54, 0x5f, 0xf8,
  37183. 0x1d, 0xb7, 0xfc, 0xcd, 0xdd, 0x9a, 0x32, 0x4b,
  37184. 0x0b, 0xac, 0x3c, 0x2c, 0x23, 0x82, 0x28, 0x40,
  37185. 0x58, 0xf0, 0x8b, 0x96, 0x19, 0x52, 0xc0, 0x94,
  37186. 0x01, 0x9c, 0x10, 0xbe, 0x37, 0xa5, 0x3d, 0x5a,
  37187. 0xc7, 0x94, 0xc0, 0x10, 0xa9, 0xd0, 0x82, 0x1f,
  37188. 0x15, 0x02, 0x7a, 0x1c, 0x41, 0x9c, 0x3c, 0x71,
  37189. 0xc9, 0xa1, 0xd2, 0x8a, 0xed, 0x02, 0x59, 0x7a,
  37190. 0xb7, 0x9b, 0x87, 0x53, 0x94, 0x62, 0x6b, 0xa3,
  37191. 0x9a, 0xdc, 0x09, 0x0c, 0x3a, 0x90, 0xcf, 0x75,
  37192. 0x87, 0x1a, 0x65, 0x27, 0x5e, 0xb1, 0xc5, 0xb0,
  37193. 0x33, 0x72, 0xe1, 0x3a, 0x1a, 0x23, 0xd0, 0xcf,
  37194. 0x93, 0x74, 0x11, 0x1f, 0x80, 0xcc, 0x83, 0xa9,
  37195. 0x05, 0x62, 0x2b, 0x83, 0xfc, 0x51, 0x39, 0x71,
  37196. 0xec, 0x84, 0x19, 0xf0, 0x88, 0x0c, 0x30, 0x67,
  37197. 0x63, 0x36, 0x71, 0xb0, 0x9b, 0x54, 0x56, 0xab,
  37198. 0x60, 0x57, 0x93, 0x6d, 0x19, 0xa4, 0xa2, 0xa2,
  37199. 0x67, 0x91, 0x1b, 0x00, 0x0a, 0x13, 0x95, 0x6f,
  37200. 0xbd, 0x49, 0x38, 0x21, 0xda, 0x07, 0x2c, 0x04,
  37201. 0x64, 0x2b, 0x0c, 0x20, 0xda, 0x6c, 0xc0, 0xd9,
  37202. 0xd8, 0x64, 0xa3, 0x93, 0x65, 0xdf, 0xd6, 0x4f,
  37203. 0x10, 0x18, 0x78, 0x25, 0xfa, 0x33, 0x25, 0x07,
  37204. 0x49, 0xcb, 0xc0, 0xc9, 0x05, 0xd7, 0xb1, 0xff,
  37205. 0x3c, 0xae, 0x24, 0x12, 0xbf, 0x86, 0xb8, 0x1a,
  37206. 0x81, 0x7b, 0x86, 0xba, 0xa3, 0x0e, 0xdf, 0x78,
  37207. 0x62, 0xe5, 0xf6, 0xba, 0xc9, 0x87, 0x26, 0xe5,
  37208. 0x6b, 0x3c, 0xec, 0x60, 0x66, 0x4c, 0xaa, 0x2a,
  37209. 0x7d, 0xf6, 0x70, 0xc5, 0xe2, 0x07, 0xdf, 0xac,
  37210. 0x03, 0x82, 0x4c, 0x89, 0x89, 0x7c, 0xb4, 0x90,
  37211. 0xea, 0xa7, 0x65, 0x21, 0x22, 0x2c, 0x86, 0x20,
  37212. 0x51, 0x69, 0xc9, 0x1c, 0x32, 0x9c, 0x4a, 0x18,
  37213. 0x4d, 0x78, 0x72, 0x1a, 0xf8, 0x36, 0xad, 0x4d,
  37214. 0xb0, 0xca, 0x78, 0x46, 0x4d, 0x41, 0x71, 0x47,
  37215. 0x30, 0x12, 0xb7, 0xd1, 0x83, 0xba, 0xfa, 0x62,
  37216. 0x75, 0x85, 0xc6, 0x4b, 0xe3, 0x80, 0x9d, 0x7e,
  37217. 0x60, 0x04, 0xcb, 0xdc, 0x79, 0xa5, 0x46, 0x0f,
  37218. 0x0a, 0xd6, 0x77, 0xcb, 0x71, 0x65, 0x12, 0x40,
  37219. 0x7d, 0x3a, 0x61, 0x9a, 0xd0, 0x95, 0x43, 0xb7,
  37220. 0x39, 0x54, 0x74, 0x72, 0xa7, 0x06, 0xb3, 0x17,
  37221. 0xa5, 0x09, 0xbe, 0x5d, 0x86, 0x1f, 0xd6, 0x6c,
  37222. 0x7d, 0x0e, 0xd9, 0x4c, 0xd5, 0x00, 0x47, 0x95,
  37223. 0xc1, 0x81, 0x59, 0xe3, 0xa3, 0x3d, 0x79, 0x87,
  37224. 0x11, 0x52, 0x5f, 0x16, 0x35, 0xa6, 0x84, 0x28,
  37225. 0x17, 0x29, 0x23, 0x24, 0x96, 0x35, 0xaa, 0xd0,
  37226. 0x32, 0xb9, 0xe5, 0x66, 0x64, 0xbd, 0xd4, 0x8e,
  37227. 0xd2, 0x4a, 0xc7, 0x5c, 0x64, 0x68, 0xd1, 0x90,
  37228. 0x3e, 0x47, 0x10, 0x86, 0xc5, 0xf1, 0x56, 0x7e,
  37229. 0x83, 0x1a, 0x05, 0x08, 0xc5, 0x39, 0x63, 0x25,
  37230. 0x91, 0xab, 0x57, 0x7d, 0x32, 0x4a, 0x82, 0x42,
  37231. 0x97, 0x25, 0x80, 0x99, 0x50, 0x76, 0x1d, 0x84,
  37232. 0x34, 0x28, 0x8c, 0x14, 0x03, 0x4f, 0x1c, 0x06,
  37233. 0xc1, 0xd0, 0xaa, 0xe0, 0x9a, 0x71, 0xc7, 0x40,
  37234. 0xa5, 0x57, 0x01, 0xc2, 0x8f, 0xf8, 0x44, 0x99,
  37235. 0xf2, 0xbb, 0x18, 0xb6, 0x62, 0x8c, 0xaa, 0xa3,
  37236. 0xfe, 0x75, 0xac, 0x4d, 0xe0, 0x4c, 0x6f, 0x91,
  37237. 0x39, 0x00, 0xd8, 0x6c, 0x88, 0x12, 0x62, 0x52,
  37238. 0xa1, 0x7c, 0x4d, 0x30, 0x39, 0x91, 0xdb, 0x02,
  37239. 0x87, 0x12, 0x08, 0x81, 0xbb, 0x88, 0x47, 0x8a,
  37240. 0xaa, 0x9a, 0xf9, 0xbc, 0x53, 0xd3, 0x72, 0x98,
  37241. 0x43, 0x85, 0x8f, 0xdb, 0x46, 0x48, 0x05, 0x9c,
  37242. 0xac, 0x82, 0xc1, 0xa1, 0x08, 0x78, 0xba, 0x39,
  37243. 0x82, 0x3b, 0x04, 0x1b, 0xd0, 0xe2, 0x58, 0x48,
  37244. 0x7b, 0x56, 0xcc, 0x8a, 0x32, 0x20, 0xc1, 0xa5,
  37245. 0x8b, 0xf6, 0x6a, 0x17, 0x2b, 0x5b, 0x9a, 0x0c,
  37246. 0x63, 0x2d, 0x67, 0x4e, 0xae, 0x88, 0x5a, 0x01,
  37247. 0x5c, 0x4e, 0x37, 0xba, 0x07, 0x36, 0x80, 0xbe,
  37248. 0xde, 0x75, 0x34, 0xf3, 0xe3, 0x4b, 0x60, 0x50,
  37249. 0xc8, 0x6b, 0x21, 0xc3, 0xc0, 0x90, 0x94, 0x1f,
  37250. 0x23, 0xb7, 0xf6, 0x73, 0x1e, 0x2b, 0xda, 0x0e,
  37251. 0x6e, 0xa4, 0x64, 0x67, 0x71, 0xce, 0xc5, 0x72,
  37252. 0xb9, 0x8c, 0xa0, 0xa1, 0x58, 0x91, 0x9a, 0xdb,
  37253. 0xeb, 0x84, 0xce, 0x58, 0x5f, 0xf9, 0xf2, 0x5e,
  37254. 0xbd, 0xda, 0x6c, 0xb6, 0xf0, 0x7a, 0x8f, 0x81,
  37255. 0x12, 0x32, 0x60, 0x7e, 0x72, 0x17, 0xbb, 0x03,
  37256. 0x9b, 0xab, 0xd0, 0xd9, 0x19, 0x34, 0xa8, 0x59,
  37257. 0x40, 0x59, 0xc9, 0x68, 0x77, 0x23, 0xc0, 0x43,
  37258. 0x81, 0xbf, 0xd6, 0x27, 0xa1, 0x05, 0x17, 0xf5,
  37259. 0xf4, 0xbf, 0xc7, 0x77, 0x77, 0xaa, 0x26, 0x71,
  37260. 0xae, 0x12, 0x4f, 0x2b, 0x7a, 0x5f, 0x4d, 0x56,
  37261. 0x14, 0x02, 0x91, 0x97, 0xe6, 0x58, 0x6f, 0xa8,
  37262. 0xc1, 0x7e, 0x0a, 0xd9, 0x07, 0x81, 0xbc, 0x7b,
  37263. 0xb1, 0x9a, 0x77, 0x2d, 0x5a, 0x4e, 0xfe, 0x32,
  37264. 0xca, 0xc8, 0x9b, 0x76, 0xc4, 0x2a, 0x5e, 0xde,
  37265. 0x9b, 0xcc, 0x20, 0xc1, 0x89, 0x8c, 0x08, 0xa5,
  37266. 0xb0, 0xc0, 0x7e, 0x47, 0x8b, 0x1b, 0xbc, 0x22,
  37267. 0x6e, 0xfa, 0xd1, 0x5f, 0x2a, 0xc7, 0x37, 0x51,
  37268. 0x4b, 0x8c, 0x61, 0x49, 0x81, 0x07, 0x79, 0x22,
  37269. 0x24, 0x16, 0x53, 0x7e, 0xd0, 0x0d, 0xae, 0xab,
  37270. 0x17, 0x7e, 0x90, 0x3e, 0xad, 0x6b, 0x4a, 0xc4,
  37271. 0x23, 0x70, 0xaf, 0x1b, 0x1f, 0x50, 0xeb, 0xaf,
  37272. 0xaa, 0x1c, 0x6e, 0x64, 0x7b, 0xba, 0xcc, 0xe7,
  37273. 0x2c, 0x7d, 0x0b, 0x88, 0xae, 0xb0, 0xb0, 0x6f,
  37274. 0xc1, 0xa4, 0x54, 0x57, 0xa9, 0xc1, 0x87, 0x57,
  37275. 0x9b, 0xf1, 0x84, 0x57, 0x9c, 0xc3, 0x51, 0xc4,
  37276. 0x3d, 0xff, 0x94, 0x26, 0x05, 0xaa, 0x56, 0x04,
  37277. 0xfc, 0x85, 0xfc, 0x55, 0x83, 0xf6, 0xf1, 0x49,
  37278. 0x6f, 0xe6, 0x1d, 0x70, 0xd6, 0xcd, 0xe2, 0x32,
  37279. 0x7f, 0xee, 0x71, 0x3d, 0x86, 0xf2, 0x9b, 0x3a,
  37280. 0xfc, 0xbb, 0x54, 0xe9, 0xa9, 0x2a, 0x33, 0xa6,
  37281. 0xc1, 0xea, 0x6f, 0xfa, 0x30, 0x95, 0x66, 0xb0,
  37282. 0x68, 0x62, 0x33, 0xc0, 0xf3, 0xb1, 0xc3, 0x14,
  37283. 0x48, 0x90, 0xe4, 0xf0, 0x82, 0x9a, 0x60, 0x99,
  37284. 0xc5, 0x74, 0x9c, 0xde, 0xc8, 0x43, 0x28, 0xec,
  37285. 0x2c, 0xb6, 0x4a, 0x73, 0x85, 0xa7, 0x61, 0xd6,
  37286. 0x4b, 0x3a, 0x23, 0xc4, 0x89, 0x34, 0x33, 0x43,
  37287. 0xb9, 0x77, 0x23, 0xae, 0x78, 0xc7, 0xd8, 0x05,
  37288. 0x45, 0x8e, 0x16, 0x20, 0xf0, 0x29, 0x28, 0x97,
  37289. 0x69, 0x17, 0x04, 0xcb, 0x76, 0xe3, 0xb0, 0xb2,
  37290. 0x81, 0xa8, 0x3c, 0xf6, 0x44, 0x90, 0x49, 0x8c,
  37291. 0xbc, 0xaf, 0x04, 0x80, 0x24, 0x16, 0xb3, 0x3c,
  37292. 0x56, 0x51, 0x71, 0xd7, 0x72, 0xd3, 0xb9, 0x35,
  37293. 0x40, 0x37, 0x58, 0x76, 0x29, 0xae, 0x14, 0xa5,
  37294. 0xc5, 0x03, 0x1a, 0xc3, 0x66, 0x71, 0xa0, 0xd0,
  37295. 0xc9, 0x1c, 0xc0, 0xb4, 0xcd, 0x69, 0xd8, 0x40,
  37296. 0x2e, 0x33, 0xb9, 0xbc, 0xc2, 0xbb, 0xaf, 0x6b,
  37297. 0x97, 0x1e, 0x30, 0x3f, 0xa1, 0x37, 0xbe, 0x23,
  37298. 0x25, 0x98, 0xa4, 0x99, 0x9b, 0xc0, 0x12, 0x57,
  37299. 0x4c, 0x81, 0x65, 0x1b, 0x38, 0xb3, 0x83, 0x96,
  37300. 0xc1, 0xc3, 0x65, 0x30, 0x3a, 0xd2, 0x5d, 0x49,
  37301. 0xfc, 0x6b, 0x68, 0x99, 0x51, 0xa1, 0xcc, 0x4c,
  37302. 0x60, 0x07, 0x61, 0x30, 0x65, 0x49, 0x5f, 0x97,
  37303. 0x91, 0x0f, 0x97, 0x35, 0xd4, 0xea, 0x4e, 0x44,
  37304. 0x2a, 0xcb, 0x2f, 0xab, 0xae, 0xcf, 0xe1, 0xad,
  37305. 0xef, 0x06, 0x67, 0xba, 0x42, 0x2c, 0x95, 0x4a,
  37306. 0x05, 0xd1, 0xb6, 0x16, 0x7a, 0x26, 0x3e, 0x12,
  37307. 0x75, 0xc6, 0xad, 0xa8, 0x38, 0x59, 0x65, 0x30,
  37308. 0x4b, 0x30, 0x32, 0x40, 0x40, 0x54, 0x2c, 0xf5,
  37309. 0xa4, 0x51, 0xbc, 0xaf, 0xc7, 0x47, 0x88, 0xbe,
  37310. 0x3b, 0x9b, 0x9f, 0xcc, 0x45, 0xd4, 0x79, 0x0e,
  37311. 0x2d, 0x73, 0x35, 0xc6, 0x0a, 0x14, 0xf0, 0xa4,
  37312. 0x9d, 0x13, 0x05, 0x3f, 0x26, 0x26, 0xa6, 0x27,
  37313. 0xca, 0x19, 0x55, 0x3c, 0xb3, 0x36, 0xa2, 0xcb,
  37314. 0x4a, 0x45, 0x5d, 0x8e, 0xf3, 0x98, 0x94, 0x91,
  37315. 0x47, 0x2b, 0xa0, 0x05, 0x1e, 0xf7, 0x41, 0x6e,
  37316. 0x0b, 0xbf, 0x1a, 0x61, 0x08, 0xfa, 0x07, 0xc1,
  37317. 0x61, 0x54, 0x8e, 0x7c, 0x62, 0x33, 0x1a, 0xe5,
  37318. 0xa2, 0xb4, 0xe4, 0xa1, 0x08, 0xa5, 0x10, 0x93,
  37319. 0xd3, 0x15, 0x08, 0x21, 0xa2, 0xfb, 0x54, 0x71,
  37320. 0x70, 0xa1, 0xb7, 0x3c, 0x43, 0xc5, 0x50, 0xc6,
  37321. 0x55, 0x7a, 0x40, 0x48, 0xa5, 0x8a, 0x2c, 0xd7,
  37322. 0x7a, 0x24, 0x42, 0x34, 0xb2, 0x23, 0x51, 0x75,
  37323. 0xa0, 0x89, 0x7d, 0x50, 0x61, 0xb4, 0x61, 0x34,
  37324. 0x82, 0xdc, 0x13, 0x64, 0x14, 0x04, 0x8c, 0x11,
  37325. 0xdb, 0x37, 0xea, 0xe0, 0xa5, 0xdf, 0x87, 0xc1,
  37326. 0x93, 0x14, 0xb0, 0xe8, 0x23, 0x97, 0xa0, 0xd3,
  37327. 0x38, 0xdc, 0x21, 0x53, 0x8a, 0xf3, 0x61, 0x49,
  37328. 0xd9, 0x3f, 0x8b, 0x1a, 0x11, 0xc5, 0x3b, 0xb5,
  37329. 0xde, 0xf8, 0xb7, 0xa2, 0xcc, 0xa3, 0x36, 0x2b,
  37330. 0x7f, 0xe3, 0xa1, 0x40, 0x8a, 0x25, 0x47, 0xe2,
  37331. 0x09, 0x05, 0x8c, 0x67, 0x3a, 0x75, 0x66, 0xc2,
  37332. 0x61, 0x23, 0xa6, 0xd8, 0xb6, 0x92, 0xa5, 0xf3,
  37333. 0x3e, 0xbd, 0xcb, 0x26, 0x24, 0xb7, 0x9d, 0x87,
  37334. 0x7b, 0xce, 0x5f, 0xa1, 0x4e, 0x42, 0xe8, 0x3f,
  37335. 0xaa, 0xd8, 0x2e, 0x99, 0x00, 0x55, 0x3a, 0x3c,
  37336. 0x60, 0x45, 0xca, 0x32, 0x9f, 0xea, 0x4a, 0x50,
  37337. 0x65, 0x58, 0xc4, 0x91, 0xb6, 0xa6, 0x16, 0xc6,
  37338. 0xfd, 0x40, 0x0b, 0x42, 0x13, 0x6f, 0x44, 0xcb,
  37339. 0x0d, 0x02, 0x57, 0x65, 0x08, 0x19, 0x01, 0x8d,
  37340. 0x3c, 0x56, 0x8e, 0xf6, 0xc6, 0x0c, 0x6c, 0x40,
  37341. 0x9e, 0x70, 0xa8, 0x29, 0x28, 0x71, 0x08, 0xc1,
  37342. 0xb6, 0xa4, 0xd3, 0x2f, 0x76, 0xe5, 0xcc, 0x4d,
  37343. 0x10, 0x4b, 0x02, 0x43, 0x8e, 0xf7, 0xa4, 0x67,
  37344. 0x91, 0x23, 0x98, 0xea, 0x9c, 0x7c, 0xbd, 0x99,
  37345. 0x81, 0x58, 0x9a, 0x34, 0x18, 0x97, 0x68, 0x7b,
  37346. 0x51, 0x6a, 0x13, 0x30, 0x7d, 0x66, 0xc0, 0x68,
  37347. 0xc4, 0x44, 0xb4, 0xb9, 0x49, 0xa1, 0x74, 0x12,
  37348. 0x41, 0x33, 0x15, 0xcc, 0xf4, 0x9b, 0x99, 0x98,
  37349. 0x00, 0x34, 0xb5, 0xb8, 0xcf, 0xde, 0xc4, 0xa6,
  37350. 0x0b, 0x9c, 0x1e, 0x74, 0x55, 0xaa, 0xfb, 0xf3,
  37351. 0xa7, 0x57, 0x34, 0x69, 0x90, 0xcc, 0x32, 0xb0,
  37352. 0x59, 0x9b, 0xa2, 0x17, 0xa6, 0xc5, 0xfc, 0x39,
  37353. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  37354. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  37355. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  37356. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  37357. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  37358. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  37359. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  37360. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  37361. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  37362. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  37363. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  37364. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  37365. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  37366. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  37367. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  37368. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  37369. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  37370. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  37371. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  37372. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  37373. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  37374. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  37375. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  37376. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  37377. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  37378. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  37379. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  37380. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  37381. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  37382. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  37383. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  37384. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  37385. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  37386. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  37387. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  37388. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  37389. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  37390. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  37391. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  37392. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  37393. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  37394. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  37395. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  37396. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  37397. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  37398. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  37399. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  37400. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  37401. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  37402. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  37403. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  37404. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  37405. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  37406. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  37407. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  37408. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  37409. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  37410. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  37411. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  37412. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  37413. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  37414. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  37415. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  37416. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  37417. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  37418. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  37419. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  37420. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  37421. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  37422. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  37423. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  37424. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  37425. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  37426. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  37427. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  37428. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  37429. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  37430. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  37431. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  37432. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  37433. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  37434. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  37435. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  37436. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  37437. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  37438. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  37439. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  37440. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  37441. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  37442. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  37443. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  37444. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  37445. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  37446. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  37447. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  37448. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  37449. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  37450. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  37451. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  37452. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  37453. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  37454. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  37455. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  37456. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  37457. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  37458. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  37459. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  37460. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  37461. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  37462. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  37463. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  37464. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  37465. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  37466. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  37467. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  37468. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  37469. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  37470. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  37471. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  37472. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  37473. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  37474. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  37475. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  37476. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  37477. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  37478. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  37479. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  37480. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  37481. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  37482. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  37483. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  37484. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  37485. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  37486. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  37487. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  37488. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  37489. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  37490. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  37491. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  37492. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  37493. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  37494. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  37495. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  37496. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  37497. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  37498. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  37499. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  37500. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  37501. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  37502. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  37503. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  37504. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  37505. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  37506. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  37507. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  37508. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  37509. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  37510. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  37511. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  37512. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  37513. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  37514. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  37515. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  37516. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  37517. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  37518. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  37519. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  37520. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  37521. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  37522. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  37523. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  37524. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  37525. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  37526. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  37527. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  37528. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  37529. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  37530. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  37531. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  37532. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  37533. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  37534. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  37535. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  37536. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  37537. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  37538. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  37539. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  37540. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  37541. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  37542. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  37543. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  37544. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  37545. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  37546. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  37547. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  37548. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb,
  37549. 0xeb, 0xbe, 0x41, 0xcd, 0x4d, 0xea, 0x48, 0x9d,
  37550. 0xed, 0xd0, 0x0e, 0x76, 0xae, 0x0b, 0xcf, 0x54,
  37551. 0xaa, 0x85, 0x50, 0x20, 0x29, 0x20, 0xeb, 0x64,
  37552. 0xd5, 0x89, 0x2a, 0xd0, 0x2b, 0x13, 0xf2, 0xe5,
  37553. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  37554. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  37555. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  37556. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  37557. };
  37558. #endif
  37559. #ifdef WOLFSSL_KYBER_ORIGINAL
  37560. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ct[] = {
  37561. 0xA6, 0xAF, 0x29, 0xD5, 0xF5, 0xB8, 0x0B, 0xD1,
  37562. 0x30, 0xF5, 0x18, 0xBA, 0xDD, 0xD6, 0xC8, 0xF1,
  37563. 0x75, 0x45, 0x41, 0x3D, 0x86, 0x0F, 0xB3, 0xDE,
  37564. 0x45, 0x19, 0x79, 0xEB, 0xFA, 0x5E, 0x4E, 0x31,
  37565. 0x12, 0xC7, 0xC0, 0xAD, 0xF9, 0x98, 0x24, 0xBB,
  37566. 0x52, 0x6F, 0x2C, 0x35, 0x50, 0x74, 0x8E, 0xD0,
  37567. 0xE1, 0x34, 0xF0, 0x45, 0x7A, 0x7C, 0x61, 0xF9,
  37568. 0xF5, 0x26, 0xF0, 0x02, 0xBA, 0xAD, 0xC0, 0x3F,
  37569. 0xC1, 0x3E, 0x38, 0x13, 0x12, 0x19, 0x51, 0x3C,
  37570. 0x3E, 0xDE, 0x06, 0x16, 0x61, 0xE7, 0x4F, 0x60,
  37571. 0x3C, 0x4F, 0xCF, 0x79, 0x51, 0xC8, 0xE5, 0x2C,
  37572. 0x9C, 0x21, 0x3B, 0x0D, 0x22, 0xD9, 0x29, 0x36,
  37573. 0x63, 0xD6, 0x69, 0xA6, 0xB5, 0x8E, 0xD8, 0xFC,
  37574. 0xEF, 0xCF, 0x82, 0x49, 0xD7, 0xBB, 0x52, 0x98,
  37575. 0xF5, 0x57, 0x61, 0x44, 0x5B, 0x2B, 0x83, 0xCE,
  37576. 0x7F, 0x00, 0x5C, 0xB0, 0x42, 0x48, 0xAE, 0xC8,
  37577. 0xBD, 0xA2, 0x2F, 0xD2, 0xD4, 0x2A, 0xA7, 0x66,
  37578. 0x32, 0x20, 0x14, 0xEA, 0x03, 0x8C, 0xC3, 0x2C,
  37579. 0x55, 0xC8, 0xE4, 0xB9, 0xE2, 0x8E, 0xC9, 0x11,
  37580. 0x9F, 0x52, 0x73, 0x41, 0xE4, 0xF6, 0x6A, 0x03,
  37581. 0x51, 0x21, 0x07, 0x3B, 0x85, 0xDE, 0x67, 0x06,
  37582. 0xDA, 0x19, 0xE0, 0x83, 0x8A, 0x9F, 0x33, 0xB7,
  37583. 0x19, 0xA6, 0x8F, 0x03, 0x9B, 0x66, 0x4D, 0xC0,
  37584. 0x02, 0x65, 0x9E, 0xAB, 0xFC, 0x39, 0x86, 0x79,
  37585. 0xAA, 0x70, 0x09, 0xCE, 0x0C, 0xD0, 0x1C, 0xDA,
  37586. 0xFB, 0x6C, 0xD2, 0xA2, 0x6F, 0xE4, 0x10, 0x16,
  37587. 0x72, 0xC9, 0x8F, 0xF5, 0x8F, 0x7C, 0x47, 0xD5,
  37588. 0xBD, 0xA2, 0x90, 0x66, 0x53, 0xB3, 0xA6, 0xF9,
  37589. 0x65, 0x1F, 0x7A, 0x12, 0x1E, 0xA7, 0x7E, 0xA7,
  37590. 0x47, 0x23, 0xFA, 0xE5, 0xB8, 0x73, 0xF9, 0xBB,
  37591. 0x7B, 0x66, 0x4F, 0x0C, 0x8A, 0x93, 0x83, 0x1E,
  37592. 0xF9, 0xD5, 0x1C, 0x7C, 0xC1, 0xEF, 0x44, 0xAC,
  37593. 0x0E, 0x55, 0xA5, 0x5C, 0xA7, 0x6D, 0x13, 0x7F,
  37594. 0xE9, 0xB7, 0x5F, 0x40, 0x50, 0x9C, 0xEF, 0x15,
  37595. 0x6E, 0x5A, 0xD1, 0x8F, 0x9F, 0xB9, 0x99, 0x68,
  37596. 0x00, 0x08, 0xE5, 0x47, 0xD5, 0x5E, 0xEC, 0xD5,
  37597. 0xB4, 0xD1, 0xCB, 0x1D, 0x9F, 0x07, 0x6C, 0xEC,
  37598. 0x21, 0x50, 0x1C, 0x74, 0x02, 0x50, 0x9E, 0xCB,
  37599. 0x77, 0xAF, 0xB2, 0xCB, 0x9A, 0x61, 0x34, 0x0A,
  37600. 0x8B, 0xD1, 0x51, 0x4C, 0x6E, 0x71, 0xB4, 0xAA,
  37601. 0x45, 0xE4, 0x7E, 0xC3, 0x75, 0x12, 0x27, 0x1B,
  37602. 0x91, 0x1F, 0x8F, 0xB4, 0x6C, 0x90, 0x82, 0xC9,
  37603. 0xDF, 0x07, 0x20, 0x4A, 0xBB, 0x5A, 0x50, 0xE6,
  37604. 0xE3, 0x64, 0x7A, 0x8A, 0xD4, 0xD8, 0xD5, 0xD7,
  37605. 0xBF, 0xF1, 0x9C, 0x8A, 0x50, 0x93, 0x08, 0xBC,
  37606. 0xFB, 0x89, 0x55, 0x36, 0xD0, 0x45, 0xCA, 0x2B,
  37607. 0x97, 0xCB, 0x16, 0xA2, 0x9B, 0xB7, 0x18, 0x1C,
  37608. 0xAD, 0x05, 0x09, 0xDD, 0xB9, 0x17, 0x35, 0x02,
  37609. 0x8E, 0xBA, 0x8C, 0x31, 0xD7, 0x4B, 0xD2, 0x75,
  37610. 0xEA, 0xA6, 0x5B, 0x53, 0x40, 0xB3, 0xA4, 0x3F,
  37611. 0xBF, 0xE0, 0xB3, 0x06, 0x1D, 0x6B, 0xAE, 0x7E,
  37612. 0x75, 0xB7, 0x09, 0x8C, 0xDA, 0xBE, 0x91, 0xD4,
  37613. 0xB3, 0x1E, 0x36, 0xC9, 0xAA, 0x7A, 0x82, 0x98,
  37614. 0x86, 0x2A, 0xD6, 0x3C, 0x8F, 0xD2, 0x82, 0xE0,
  37615. 0x3B, 0x46, 0x0B, 0x3A, 0xB4, 0x64, 0xCE, 0x0F,
  37616. 0x27, 0xB1, 0xC3, 0xD1, 0x11, 0x55, 0xAC, 0xAA,
  37617. 0x01, 0x1E, 0xB9, 0xE2, 0xAE, 0x3E, 0x6D, 0xDA,
  37618. 0x07, 0xD6, 0xF4, 0x91, 0x73, 0x7C, 0xBC, 0xE9,
  37619. 0xB0, 0x5F, 0x9B, 0xC5, 0x6B, 0xE2, 0x0E, 0x8D,
  37620. 0x32, 0x6B, 0xA1, 0x32, 0xC5, 0x7F, 0xB2, 0x35,
  37621. 0x16, 0x11, 0x44, 0x51, 0x9C, 0xDF, 0x40, 0x56,
  37622. 0x0F, 0xBE, 0x27, 0x9B, 0xDE, 0x41, 0x1E, 0x11,
  37623. 0x25, 0x31, 0xF8, 0x26, 0xD6, 0xAB, 0x10, 0xD4,
  37624. 0x54, 0x73, 0x50, 0xAD, 0xD2, 0xA9, 0xDE, 0x8D,
  37625. 0x62, 0xC2, 0xAC, 0x82, 0xCA, 0xBE, 0x68, 0x15,
  37626. 0x64, 0x6F, 0x4D, 0xC9, 0x74, 0x2B, 0xB0, 0xC2,
  37627. 0xA3, 0xF7, 0x7E, 0xC7, 0xB4, 0x6C, 0x6B, 0x53,
  37628. 0x76, 0x05, 0xFA, 0x31, 0x79, 0x8C, 0xD8, 0x92,
  37629. 0x81, 0x22, 0x1A, 0x33, 0xDF, 0xB9, 0x79, 0x6E,
  37630. 0x64, 0x43, 0x05, 0x63, 0x03, 0x32, 0xC2, 0xCB,
  37631. 0x93, 0x14, 0x08, 0xAB, 0x48, 0x1A, 0x16, 0xD9,
  37632. 0x53, 0xF6, 0xBE, 0xAE, 0x38, 0x91, 0xD6, 0xD9,
  37633. 0xAC, 0x1F, 0xAB, 0x38, 0x22, 0x2D, 0x92, 0x71,
  37634. 0x87, 0x2D, 0x9D, 0x0C, 0xAD, 0xB9, 0x1A, 0xBE,
  37635. 0x9B, 0x4E, 0x26, 0x5F, 0x75, 0xC6, 0xE5, 0xE8,
  37636. 0x29, 0xE1, 0x46, 0xC3, 0xD8, 0xCE, 0x1E, 0x9D,
  37637. 0x12, 0xE0, 0xD1, 0x29, 0x80, 0x19, 0x57, 0xF4,
  37638. 0x6B, 0x0D, 0x2D, 0xBE, 0x1F, 0x74, 0x9B, 0x1D,
  37639. 0x08, 0xE2, 0x34, 0x5F, 0x62, 0x39, 0xA7, 0x31,
  37640. 0x34, 0x2E, 0xB7, 0x5B, 0x0C, 0xF1, 0xBF, 0x41,
  37641. 0x17, 0x49, 0xBC, 0x2C, 0xAF, 0x28, 0x10, 0xB7,
  37642. 0x88, 0xC6, 0xB7, 0x23, 0x8B, 0x4D, 0x3D, 0xA2,
  37643. 0xD6, 0x31, 0x5C, 0xE9, 0x54, 0x2E, 0x24, 0x40,
  37644. 0x4F, 0x14, 0x57, 0x55, 0xA3, 0x0A, 0xB8, 0x51,
  37645. 0xE4, 0x44, 0x58, 0x41, 0xBD, 0x33, 0xF7, 0x16,
  37646. 0xA5, 0x86, 0x88, 0x48, 0x88, 0xEC, 0xC6, 0xBC,
  37647. 0x64, 0x98, 0xAA, 0x32, 0x91, 0x9A, 0xE8, 0x1D,
  37648. 0x20, 0xC2, 0x69, 0x73, 0xC2, 0xBD, 0x54, 0x58,
  37649. 0x2A, 0x0F, 0x6A, 0xD9, 0x8A, 0xBF, 0xD2, 0x62,
  37650. 0x7E, 0x15, 0x69, 0x0A, 0x72, 0x7E, 0x69, 0xF5,
  37651. 0x81, 0xDD, 0x2A, 0x71, 0x27, 0x98, 0x2A, 0x90,
  37652. 0xE3, 0x3E, 0x2D, 0x4A, 0x03, 0xFE, 0x33, 0x91,
  37653. 0x42, 0xC7, 0xE4, 0x4C, 0x32, 0x6A, 0xC4, 0x6E,
  37654. 0xD3, 0x95, 0xA2, 0x25, 0xD3, 0x03, 0x33, 0x89,
  37655. 0x91, 0x73, 0x28, 0xB4, 0x53, 0x16, 0xB1, 0x58,
  37656. 0x5A, 0x01, 0xB2, 0xC3, 0x04, 0xB2, 0x94, 0x4E,
  37657. 0x90, 0x3A, 0xBB, 0xB3, 0xEC, 0x56, 0x19, 0x44,
  37658. 0x1C, 0xFC, 0x89, 0x65, 0xA4, 0x46, 0xDF, 0x75,
  37659. 0xDE, 0xFA, 0x80, 0xC6, 0xE1, 0x5A, 0xDB, 0xD5,
  37660. 0x06, 0xB7, 0xAB, 0x2D, 0xE1, 0x2D, 0xDA, 0x9B,
  37661. 0xC8, 0x14, 0x41, 0xCF, 0xC8, 0x90, 0x52, 0xE2,
  37662. 0xE5, 0x80, 0x8F, 0x71, 0x26, 0xC6, 0xFD, 0x3A,
  37663. 0xC6, 0xAC, 0x80, 0x81, 0x25, 0x8A, 0x84, 0xA0,
  37664. 0x9A, 0xE5, 0x0F, 0x6C, 0xD7, 0xCC, 0x0F, 0x4A,
  37665. 0xF3, 0x36, 0xFD, 0x1D, 0x64, 0x3E, 0x99, 0x07,
  37666. 0x99, 0x96, 0x26, 0x8C, 0x2D, 0x32, 0xD9, 0x09,
  37667. 0xF2, 0x2E, 0x35, 0x04, 0xF0, 0x7F, 0xBB, 0x56,
  37668. 0x31, 0x96, 0xD4, 0x31, 0x2F, 0xDD, 0xB9, 0x33,
  37669. 0x5D, 0x5C, 0x1D, 0x36, 0xE8, 0xC5, 0xEE, 0xA2,
  37670. 0x27, 0x8D, 0xBA, 0x23, 0xB9, 0x4D, 0x19, 0x3C,
  37671. 0x94, 0x7C, 0xC4, 0x1C, 0xA9, 0x93, 0xDC, 0x7D,
  37672. 0xB1, 0x39, 0x63, 0x40, 0xAD, 0x9C, 0x4F, 0xE6,
  37673. 0x87, 0xDD, 0x7B, 0x8D, 0x0C, 0x7A, 0x51, 0x20,
  37674. 0xAE, 0x02, 0x04, 0xF2, 0xC6, 0x65, 0xBD, 0x5F,
  37675. 0x47, 0x3D, 0x64, 0x4C, 0x7F, 0xF2, 0x6B, 0xFF,
  37676. 0xBA, 0x7A, 0x36, 0x98, 0x08, 0x30, 0x70, 0x21,
  37677. 0x28, 0xA7, 0xE6, 0x61, 0xD6, 0x77, 0xA0, 0x92,
  37678. 0xA3, 0x6E, 0x74, 0x28, 0xA4, 0x13, 0x9F, 0xB2,
  37679. 0x9B, 0x00, 0x95, 0xCC, 0x11, 0x08, 0x6F, 0x44,
  37680. 0x7D, 0x2A, 0x9E, 0xF6, 0xC9, 0xB1, 0x61, 0xF1,
  37681. 0x89, 0xC6, 0x29, 0x9E, 0x08, 0x4C, 0xB7, 0xAA,
  37682. 0x00, 0xFA, 0xF7, 0x87, 0x79, 0x7B, 0xFB, 0x06,
  37683. 0x9F, 0xBC, 0x08, 0x7F, 0xDE, 0x26, 0x25, 0x2A,
  37684. 0x16, 0x64, 0xF1, 0x9C, 0x5A, 0x8A, 0x22, 0xEC,
  37685. 0x5E, 0xE1, 0xAE, 0xB0, 0x76, 0x35, 0x7B, 0x7D,
  37686. 0xC3, 0x7E, 0x6B, 0x0F, 0x15, 0x20, 0xF9, 0x58,
  37687. 0xF7, 0x85, 0x1B, 0xAC, 0xB9, 0x2C, 0x89, 0xFD,
  37688. 0x11, 0x4A, 0x72, 0xFE, 0xAC, 0x54, 0x65, 0x2D,
  37689. 0x45, 0xB0, 0x9E, 0x1A, 0xE7, 0x65, 0x1A, 0xBD,
  37690. 0x16, 0x4B, 0xCD, 0x53, 0x7D, 0x58, 0xFA, 0x39,
  37691. 0xD3, 0xEC, 0x8A, 0xCD, 0xCD, 0xF9, 0x84, 0x25,
  37692. 0x00, 0x58, 0x62, 0xFA, 0x59, 0x69, 0x2D, 0xE1,
  37693. 0x62, 0xB7, 0x7E, 0x62, 0x97, 0xC6, 0x62, 0x33,
  37694. 0x34, 0x84, 0x08, 0xA8, 0xAB, 0x69, 0x5C, 0xE2,
  37695. 0xF2, 0x72, 0x8D, 0xB9, 0xFB, 0xE2, 0x7E, 0x95,
  37696. 0x89, 0x67, 0xEC, 0x59, 0x74, 0x76, 0x7C, 0x5A,
  37697. 0x66, 0x02, 0x30, 0x74, 0xB4, 0xA7, 0x1A, 0xFD,
  37698. 0x26, 0x4A, 0xD2, 0x89, 0x0E, 0x97, 0x0A, 0x1F,
  37699. 0x31, 0xD6, 0xE3, 0x31, 0x1B, 0x73, 0x6F, 0x9F,
  37700. 0x94, 0x88, 0x79, 0x3D, 0xDC, 0x88, 0xF2, 0x34,
  37701. 0x58, 0x06, 0x42, 0x54, 0xC8, 0x2A, 0x1D, 0x9E,
  37702. 0x59, 0xEA, 0xD2, 0xFC, 0xEC, 0x40, 0xB4, 0x30,
  37703. 0x68, 0x7C, 0x4B, 0x7E, 0x28, 0x96, 0x09, 0x26,
  37704. 0xAF, 0xCA, 0xCC, 0x9B, 0xD7, 0x56, 0xA7, 0x10,
  37705. 0x88, 0xC7, 0x84, 0x50, 0xE2, 0x0A, 0x2E, 0x98,
  37706. 0x0A, 0xED, 0xE9, 0xEB, 0xED, 0xFE, 0x7F, 0xAB,
  37707. 0xD6, 0xAB, 0xFE, 0x96, 0xF9, 0x34, 0xC4, 0xB0,
  37708. 0x2C, 0x01, 0xCA, 0x19, 0x4D, 0x01, 0xB7, 0x3C,
  37709. 0x25, 0xD5, 0x99, 0x70, 0x39, 0xD3, 0xFC, 0xD0,
  37710. 0xF0, 0x99, 0x52, 0x1F, 0x70, 0xCA, 0xEE, 0x69,
  37711. 0x11, 0x0A, 0xC1, 0xFC, 0x5A, 0x99, 0x91, 0x7A,
  37712. 0xD7, 0x52, 0xFC, 0x96, 0xAD, 0xFA, 0xD7, 0x18,
  37713. 0x6D, 0x0A, 0x7C, 0x9C, 0xFE, 0x56, 0x01, 0xC0,
  37714. 0x75, 0x14, 0xEA, 0x64, 0x48, 0xD6, 0x61, 0xC5,
  37715. 0x7A, 0xA2, 0x02, 0x42, 0x10, 0x3C, 0x42, 0x76,
  37716. 0xA0, 0x70, 0xA4, 0x89, 0xA4, 0xCB, 0x6B, 0xCA,
  37717. 0x0F, 0x9E, 0xCC, 0x43, 0x79, 0xFB, 0x22, 0x02,
  37718. 0x15, 0xFD, 0x91, 0xF8, 0x10, 0x19, 0xD5, 0xB0,
  37719. 0xAE, 0x61, 0x93, 0x58, 0xB5, 0x24, 0x68, 0xF2,
  37720. 0x72, 0xC1, 0x78, 0xE3, 0xA7, 0x4C, 0xF6, 0x77,
  37721. 0x5A, 0xA9, 0x24, 0xFE, 0x32, 0x9C, 0x31, 0x75,
  37722. 0xD9, 0xE4, 0xC3, 0xE2, 0x1A, 0xB9, 0xEC, 0x83,
  37723. 0x6E, 0xDC, 0x3A, 0xCA, 0xB2, 0xE3, 0x89, 0x1E,
  37724. 0xE8, 0xDE, 0xDA, 0x51, 0x5D, 0x39, 0xAF, 0x9B,
  37725. 0x8D, 0xDD, 0x0E, 0xE7, 0xB0, 0x16, 0x4F, 0x80,
  37726. 0x5C, 0x38, 0x35, 0xF6, 0xD2, 0xBA, 0xBD, 0xB3,
  37727. 0x0E, 0xAB, 0x47, 0x56, 0xE7, 0xEC, 0x7F, 0x82,
  37728. 0x9E, 0xCE, 0x01, 0xE8, 0xEA, 0xDF, 0xBB, 0xED,
  37729. 0x12, 0xFC, 0x28, 0x3B, 0x3D, 0x4C, 0x69, 0xF5,
  37730. 0x75, 0xE7, 0xF8, 0x04, 0x17, 0x68, 0x9F, 0xDF,
  37731. 0xCF, 0xC7, 0xBE, 0x27, 0xEE, 0x3B, 0x8C, 0xDF,
  37732. 0x57, 0xAA, 0xEB, 0xEC, 0x4A, 0x95, 0xB7, 0xE5,
  37733. 0xBB, 0x58, 0x5B, 0x85, 0x22, 0x7F, 0x7C, 0x32,
  37734. 0xBE, 0x30, 0xDB, 0x3E, 0x65, 0xE4, 0x2E, 0x30,
  37735. 0xDC, 0xF5, 0xA5, 0xFA, 0x07, 0x3D, 0xBA, 0x39,
  37736. 0x9D, 0x94, 0x2F, 0x22, 0x22, 0xAD, 0xB9, 0xB9,
  37737. 0x89, 0x81, 0x02, 0xAF, 0xE5, 0x43, 0x2E, 0xDC,
  37738. 0x7F, 0x04, 0xAE, 0x34, 0xA8, 0xFE, 0xC2, 0xD8,
  37739. 0x1C, 0xB4, 0x9A, 0x9A, 0x9B, 0x43, 0x81, 0x4C,
  37740. 0xE7, 0x1D, 0x97, 0xF7, 0x26, 0xE2, 0xB1, 0xE8,
  37741. 0xF6, 0x4B, 0x50, 0xE6, 0x5D, 0xFB, 0x48, 0x16,
  37742. 0xE1, 0x2E, 0x82, 0xA3, 0x19, 0x74, 0x84, 0xA4,
  37743. 0xE9, 0xBB, 0xA4, 0xD2, 0xD6, 0x9E, 0x3F, 0x19,
  37744. 0xD0, 0xB7, 0x5C, 0x21, 0xE2, 0xBF, 0xFE, 0x9F,
  37745. 0xC0, 0xC9, 0x8C, 0xF4, 0x8A, 0x3A, 0xAF, 0x08,
  37746. 0xD4, 0x67, 0xF7, 0x26, 0x87, 0xDF, 0x01, 0x78,
  37747. 0x17, 0x4B, 0x78, 0x97, 0xF7, 0x34, 0x34, 0x9B,
  37748. 0x18, 0x1E, 0xCA, 0x86, 0xA5, 0x98, 0xA0, 0xC5,
  37749. 0xE8, 0xC2, 0x59, 0x46, 0xF2, 0x4D, 0xC5, 0x57,
  37750. 0x2B, 0xD3, 0x24, 0xA4, 0x04, 0x58, 0xA7, 0x88,
  37751. 0xE5, 0x13, 0x7F, 0x3C, 0x7A, 0x7C, 0x97, 0xFC,
  37752. 0x9F, 0x12, 0xA3, 0xC4, 0x63, 0xA8, 0xFE, 0x94,
  37753. 0x49, 0x10, 0x1C, 0xCE, 0x96, 0x6D, 0x7C, 0x00,
  37754. 0x93, 0x23, 0x93, 0x29, 0x98, 0xD5, 0x6E, 0xF4,
  37755. 0x30, 0xC7, 0x3B, 0xC2, 0x4F, 0x5D, 0x95, 0xF7,
  37756. 0x37, 0x85, 0x8D, 0xDC, 0x4F, 0x32, 0xC0, 0x13
  37757. };
  37758. #endif
  37759. #ifndef WOLFSSL_NO_ML_KEM
  37760. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ct[] = {
  37761. 0xc9, 0xbe, 0xad, 0x6b, 0x0c, 0x11, 0x14, 0x38,
  37762. 0x9b, 0xd4, 0x76, 0x1c, 0x73, 0xab, 0x90, 0x95,
  37763. 0xb5, 0x80, 0x9d, 0xaa, 0xc9, 0xf6, 0x59, 0xbb,
  37764. 0x56, 0x4a, 0xf2, 0x26, 0x17, 0x30, 0x52, 0xa4,
  37765. 0xa3, 0xe7, 0xf2, 0xe5, 0xfd, 0x47, 0xd2, 0xb0,
  37766. 0x2a, 0xae, 0xb5, 0x18, 0x9e, 0x06, 0xb9, 0xf4,
  37767. 0xae, 0x98, 0xb6, 0x19, 0xcb, 0x63, 0xef, 0xbd,
  37768. 0xf3, 0x98, 0x9a, 0x94, 0xb3, 0x6e, 0x8e, 0xa0,
  37769. 0xd7, 0x00, 0x63, 0x3b, 0x95, 0x0a, 0x0a, 0xe2,
  37770. 0xa7, 0x8e, 0xd9, 0x2e, 0x85, 0xc8, 0x5c, 0x70,
  37771. 0xe1, 0x3e, 0x62, 0x6f, 0xb2, 0x63, 0xfa, 0xc9,
  37772. 0x68, 0x15, 0x21, 0xc3, 0xab, 0x22, 0xfd, 0xab,
  37773. 0x29, 0x17, 0x3c, 0x96, 0x16, 0xa2, 0xb0, 0x37,
  37774. 0x08, 0x3f, 0xf7, 0xb2, 0xe0, 0x19, 0xb5, 0xbc,
  37775. 0xde, 0x06, 0x8f, 0xac, 0x25, 0x7e, 0xf8, 0xf1,
  37776. 0x27, 0x98, 0x41, 0x16, 0x93, 0xc1, 0xbd, 0xcc,
  37777. 0x65, 0x42, 0x09, 0x97, 0xa5, 0x13, 0xa8, 0xa6,
  37778. 0x95, 0x02, 0x62, 0x0b, 0xe8, 0xe4, 0xce, 0x73,
  37779. 0x62, 0xe4, 0x12, 0xa7, 0x6c, 0xf5, 0x1c, 0x1f,
  37780. 0x24, 0x33, 0xf1, 0xab, 0x64, 0xce, 0x0e, 0x5d,
  37781. 0x2f, 0x56, 0xd7, 0xc9, 0xad, 0xe9, 0x94, 0xd0,
  37782. 0xe3, 0x5d, 0x0a, 0xee, 0xf3, 0xac, 0x51, 0x5b,
  37783. 0x48, 0x24, 0x37, 0x66, 0x4d, 0x8c, 0x1d, 0x25,
  37784. 0xe5, 0xa5, 0x50, 0x7c, 0xf8, 0x0f, 0x97, 0x0d,
  37785. 0x3e, 0xa7, 0x22, 0x6a, 0xac, 0xdc, 0x45, 0x7c,
  37786. 0xbf, 0x88, 0xa0, 0x56, 0x0a, 0xa3, 0x5b, 0xb2,
  37787. 0xc5, 0xc4, 0x55, 0x86, 0x7e, 0x21, 0x59, 0x91,
  37788. 0x0a, 0x35, 0x81, 0x0b, 0xef, 0xe3, 0xaa, 0x10,
  37789. 0xeb, 0x04, 0xd8, 0xd5, 0x71, 0x47, 0xcb, 0x8f,
  37790. 0x66, 0xd2, 0xb0, 0x70, 0xba, 0xc4, 0x3d, 0x1f,
  37791. 0x1f, 0xfd, 0xd5, 0x7a, 0x93, 0x99, 0x95, 0x1f,
  37792. 0x64, 0x96, 0x57, 0x27, 0xbc, 0xb9, 0xf6, 0x6a,
  37793. 0xd4, 0x23, 0x09, 0xda, 0xfc, 0x79, 0x9c, 0x1c,
  37794. 0x54, 0x0a, 0xf1, 0xaf, 0x93, 0xef, 0xf6, 0x8a,
  37795. 0x86, 0xd6, 0x1f, 0x51, 0x15, 0xdb, 0x66, 0x2d,
  37796. 0xee, 0x7a, 0xc9, 0xa3, 0x62, 0x67, 0x77, 0x62,
  37797. 0xb6, 0xa1, 0x64, 0xa0, 0xfa, 0x0a, 0x4d, 0x85,
  37798. 0x9e, 0x4b, 0x8c, 0x8d, 0xbd, 0xb4, 0xe1, 0x83,
  37799. 0xf5, 0xe6, 0x80, 0x8f, 0xc5, 0x22, 0x29, 0x65,
  37800. 0x0c, 0xaf, 0x7c, 0xf3, 0xe1, 0x6d, 0xe3, 0xd8,
  37801. 0x95, 0xd1, 0x48, 0xc3, 0x54, 0x48, 0xab, 0x8c,
  37802. 0x27, 0x53, 0xc9, 0x83, 0x1b, 0x24, 0xbd, 0x49,
  37803. 0x21, 0x49, 0x7e, 0xaa, 0x19, 0x25, 0x65, 0xca,
  37804. 0xbf, 0xd8, 0x3c, 0x0c, 0x68, 0xdf, 0xe7, 0xd3,
  37805. 0x92, 0xab, 0xf5, 0xe5, 0xe6, 0xf8, 0x4b, 0xb9,
  37806. 0xf5, 0xaf, 0x4b, 0x71, 0x18, 0xc0, 0xb5, 0x58,
  37807. 0x10, 0x5f, 0x9c, 0x10, 0xc9, 0xb6, 0xd7, 0x06,
  37808. 0x82, 0xe1, 0xde, 0x6e, 0x06, 0x89, 0xd7, 0x10,
  37809. 0x6a, 0x63, 0x74, 0xbd, 0x34, 0xae, 0xd7, 0x22,
  37810. 0x9e, 0x6c, 0xb3, 0x56, 0xf2, 0xea, 0x65, 0xe6,
  37811. 0x80, 0xce, 0x7b, 0x1e, 0x2c, 0x37, 0x04, 0xe1,
  37812. 0x16, 0xa3, 0x85, 0x42, 0x82, 0x6e, 0x8a, 0x00,
  37813. 0x11, 0x41, 0xba, 0xf2, 0xe3, 0x4d, 0xe3, 0x7a,
  37814. 0x03, 0x04, 0x09, 0x86, 0xd4, 0xc0, 0xcd, 0x5d,
  37815. 0x57, 0xf0, 0x70, 0x1c, 0xe9, 0x30, 0x98, 0x6f,
  37816. 0xd9, 0x52, 0x5b, 0x58, 0xe2, 0xe5, 0x9f, 0x45,
  37817. 0xb8, 0xdd, 0x04, 0xc0, 0xf3, 0x5b, 0x0f, 0x47,
  37818. 0x97, 0x0c, 0xc6, 0x70, 0x79, 0x61, 0x8e, 0xb9,
  37819. 0xe6, 0xd9, 0x1e, 0x9b, 0x0f, 0x8c, 0x6d, 0x2e,
  37820. 0x16, 0x5c, 0xf4, 0x48, 0xa2, 0xc1, 0xeb, 0xf7,
  37821. 0x1b, 0x65, 0x37, 0xe0, 0xf3, 0x75, 0x18, 0x5d,
  37822. 0xfa, 0xfe, 0xf6, 0x98, 0xb6, 0x23, 0x9b, 0xb3,
  37823. 0x55, 0x80, 0xb3, 0x15, 0xbc, 0xb5, 0xed, 0x40,
  37824. 0x8c, 0x35, 0x7f, 0x19, 0x2d, 0xef, 0x89, 0xbc,
  37825. 0x1b, 0x75, 0xcd, 0xd6, 0xaa, 0xe8, 0xb5, 0xfa,
  37826. 0xf0, 0xc3, 0xe1, 0x38, 0x03, 0xf6, 0xbd, 0xfa,
  37827. 0x76, 0xfb, 0x40, 0x7f, 0xcb, 0xda, 0x79, 0x0c,
  37828. 0x32, 0x9b, 0x3e, 0xe4, 0x2f, 0xd3, 0xd3, 0xb0,
  37829. 0x3b, 0xd5, 0x00, 0x3f, 0x0b, 0xc4, 0x32, 0xf7,
  37830. 0xba, 0x39, 0x63, 0x11, 0x12, 0x45, 0x2d, 0xfd,
  37831. 0x12, 0x14, 0x04, 0x33, 0xff, 0x89, 0x80, 0xeb,
  37832. 0x6a, 0x52, 0x6b, 0xa8, 0x5e, 0xf9, 0x94, 0x77,
  37833. 0x37, 0x8b, 0x4d, 0xc7, 0x66, 0x35, 0xa5, 0xcd,
  37834. 0x50, 0x40, 0xe4, 0x3b, 0x8c, 0x1f, 0xe4, 0xee,
  37835. 0x5e, 0x15, 0x8e, 0x42, 0x3b, 0xfc, 0x0c, 0x89,
  37836. 0x3c, 0x1d, 0x56, 0x13, 0xbe, 0xd0, 0x8d, 0xa7,
  37837. 0x19, 0xc9, 0x07, 0x31, 0x84, 0xee, 0xb3, 0x6f,
  37838. 0xd3, 0x57, 0x38, 0x0f, 0xb1, 0x87, 0x3d, 0x8c,
  37839. 0xbd, 0x36, 0xe2, 0x25, 0x5e, 0x98, 0x5b, 0x1b,
  37840. 0x76, 0x81, 0x97, 0x43, 0xa6, 0x58, 0x4a, 0x9b,
  37841. 0x3a, 0x58, 0x09, 0x96, 0xc9, 0xc2, 0xee, 0xd9,
  37842. 0xbb, 0xbf, 0xff, 0x78, 0xa6, 0x20, 0x4b, 0x5e,
  37843. 0x5e, 0xea, 0xe5, 0xf4, 0xef, 0xd2, 0x66, 0x00,
  37844. 0x78, 0xb3, 0x7f, 0x07, 0x54, 0xab, 0x5d, 0xa8,
  37845. 0x62, 0xe6, 0x66, 0xb1, 0x45, 0xb5, 0xf2, 0x3f,
  37846. 0x3d, 0x09, 0x77, 0x79, 0x99, 0x29, 0xdf, 0xa2,
  37847. 0xae, 0xdd, 0xa5, 0x3d, 0x15, 0x2e, 0xda, 0x1d,
  37848. 0x0d, 0x0e, 0x4e, 0xa4, 0x3f, 0x6e, 0xd8, 0x89,
  37849. 0xbb, 0x96, 0x5e, 0xef, 0xe0, 0xa7, 0xc6, 0x85,
  37850. 0xbb, 0x36, 0x77, 0x0e, 0xaa, 0x87, 0x42, 0x42,
  37851. 0xc0, 0xe2, 0x29, 0xcf, 0x6c, 0xe5, 0x6d, 0xef,
  37852. 0xa5, 0xae, 0xae, 0x64, 0xd0, 0xc4, 0x0d, 0xda,
  37853. 0x8a, 0xa2, 0x6e, 0xae, 0xb3, 0x14, 0x58, 0xf0,
  37854. 0x70, 0xa3, 0xbc, 0x72, 0xe1, 0x61, 0x9e, 0xe9,
  37855. 0xb5, 0xf6, 0x42, 0x29, 0x1c, 0x56, 0xdf, 0x5b,
  37856. 0x7e, 0x43, 0xdb, 0x6c, 0x80, 0x2f, 0xc7, 0x4f,
  37857. 0x4f, 0x3f, 0x9b, 0x5c, 0x0d, 0x35, 0x5c, 0x3a,
  37858. 0xae, 0x52, 0x0a, 0xa3, 0x12, 0x29, 0xd1, 0x2f,
  37859. 0x3e, 0x7c, 0xc5, 0xd4, 0x8e, 0x69, 0x11, 0x91,
  37860. 0xa3, 0x6b, 0x28, 0x37, 0x65, 0xf4, 0x13, 0x3f,
  37861. 0x0f, 0xf1, 0xfe, 0x2f, 0x01, 0xc6, 0x64, 0x8b,
  37862. 0x27, 0x98, 0xa7, 0x4e, 0xb5, 0xd8, 0x42, 0xa2,
  37863. 0x48, 0xf5, 0x24, 0xa7, 0xe7, 0xf8, 0x97, 0x42,
  37864. 0x11, 0x29, 0x7b, 0x44, 0xf0, 0xdd, 0x19, 0xf3,
  37865. 0x86, 0xe8, 0x6b, 0xe6, 0xba, 0x78, 0x2d, 0xe7,
  37866. 0x7f, 0xde, 0x88, 0x72, 0x26, 0xf3, 0x7a, 0x1c,
  37867. 0x77, 0xbc, 0x5e, 0xdd, 0xee, 0xe5, 0xbf, 0x46,
  37868. 0xb6, 0x7f, 0xb7, 0x47, 0x8d, 0x55, 0x98, 0x65,
  37869. 0xf2, 0x62, 0xca, 0xa8, 0x4d, 0x64, 0xa8, 0xce,
  37870. 0x59, 0xe4, 0xdf, 0x08, 0x18, 0xe1, 0x48, 0x61,
  37871. 0x52, 0x6a, 0xcd, 0x34, 0x83, 0x60, 0x0f, 0x3d,
  37872. 0xae, 0x79, 0x59, 0xd3, 0x5d, 0x81, 0x81, 0xca,
  37873. 0x6a, 0x81, 0xce, 0x79, 0x1b, 0xe0, 0x07, 0x52,
  37874. 0xda, 0x77, 0x59, 0x44, 0x6a, 0x2c, 0xfb, 0xe0,
  37875. 0x0b, 0x82, 0x48, 0xb9, 0x34, 0x91, 0xde, 0xbd,
  37876. 0x52, 0x02, 0x20, 0xb7, 0x55, 0x41, 0x6d, 0x2f,
  37877. 0xc6, 0xb7, 0xc8, 0xaf, 0x2f, 0xf7, 0x5e, 0x5b,
  37878. 0xcb, 0xb8, 0xe7, 0x53, 0x73, 0x80, 0xa5, 0x72,
  37879. 0x1c, 0x77, 0x48, 0x49, 0x57, 0xa6, 0x92, 0x71,
  37880. 0xd8, 0xba, 0xfc, 0xe0, 0xf1, 0x66, 0x73, 0x5f,
  37881. 0xf8, 0x69, 0x23, 0x2d, 0xe5, 0xd3, 0x81, 0xaf,
  37882. 0xbf, 0x0e, 0x44, 0xd6, 0x91, 0x72, 0xb7, 0x9a,
  37883. 0x35, 0x19, 0x19, 0x49, 0xde, 0x09, 0x70, 0x3b,
  37884. 0x94, 0x22, 0x2b, 0x13, 0xc3, 0x85, 0xc6, 0x08,
  37885. 0x1e, 0x6d, 0x2e, 0xde, 0x1e, 0x57, 0xfe, 0x18,
  37886. 0x4e, 0xf8, 0xf6, 0x01, 0x96, 0xb9, 0xa3, 0xa7,
  37887. 0xb7, 0xef, 0xf7, 0x49, 0x71, 0x91, 0xca, 0x87,
  37888. 0x41, 0xb5, 0xa0, 0x1e, 0x79, 0xcb, 0x69, 0xa6,
  37889. 0x11, 0x42, 0xe6, 0xf5, 0xd0, 0x80, 0xfb, 0xb3,
  37890. 0xe5, 0x66, 0xf7, 0x9e, 0x14, 0x6f, 0x75, 0xc8,
  37891. 0xa1, 0x09, 0x78, 0x60, 0x84, 0x1b, 0x47, 0x47,
  37892. 0xdf, 0x60, 0x4d, 0xba, 0x95, 0x4e, 0x4a, 0x8d,
  37893. 0x9e, 0x0d, 0xcc, 0xc1, 0xf6, 0x09, 0xd0, 0x5c,
  37894. 0xf8, 0xd3, 0x12, 0x19, 0xec, 0xd6, 0x0c, 0x31,
  37895. 0x2d, 0xe6, 0x84, 0x55, 0x2f, 0x09, 0x22, 0x7c,
  37896. 0xb8, 0x29, 0x29, 0x1c, 0x64, 0x57, 0x32, 0xc5,
  37897. 0xf5, 0xd4, 0xd7, 0x11, 0x63, 0x9f, 0x42, 0xa2,
  37898. 0x30, 0x80, 0xaa, 0x34, 0xfe, 0x14, 0x20, 0xf2,
  37899. 0x19, 0xbd, 0x6b, 0xcf, 0x4e, 0x3b, 0x29, 0xb9,
  37900. 0xd0, 0x22, 0x93, 0xb2, 0xda, 0x81, 0x38, 0x3e,
  37901. 0x0a, 0x51, 0xd2, 0xbb, 0x18, 0x6c, 0x7b, 0x0a,
  37902. 0x21, 0x1a, 0x0c, 0xd6, 0x3a, 0xcb, 0xfc, 0x02,
  37903. 0x10, 0x40, 0x1e, 0x98, 0x5d, 0x43, 0x6b, 0x38,
  37904. 0x03, 0xd5, 0x60, 0x1c, 0x24, 0x13, 0x6a, 0xfd,
  37905. 0x15, 0x62, 0x52, 0x2e, 0x45, 0xb4, 0x57, 0xcb,
  37906. 0x43, 0x91, 0x78, 0xbe, 0x4a, 0x87, 0xcc, 0xe4,
  37907. 0x03, 0x46, 0xd3, 0x4a, 0xe0, 0xf3, 0xc3, 0x91,
  37908. 0x03, 0xc8, 0xa3, 0xeb, 0xc9, 0xc8, 0x6c, 0x8d,
  37909. 0xb8, 0xfc, 0x55, 0x61, 0xeb, 0x0f, 0x3a, 0x14,
  37910. 0x3d, 0x4e, 0x9f, 0xe9, 0x3a, 0x5c, 0xba, 0x6f,
  37911. 0x6f, 0xca, 0xe5, 0x65, 0x0d, 0x3f, 0x43, 0xd2,
  37912. 0x66, 0x8a, 0x59, 0x56, 0xc9, 0x22, 0x89, 0x3b,
  37913. 0x81, 0x66, 0x47, 0xde, 0xd0, 0xaf, 0xc0, 0x52,
  37914. 0xa6, 0xc3, 0xd9, 0xd0, 0x1a, 0x3d, 0x3a, 0xf0,
  37915. 0xf1, 0xba, 0x80, 0x7f, 0xf1, 0x04, 0x91, 0xe1,
  37916. 0x31, 0xdc, 0x15, 0xe1, 0x65, 0xcf, 0xd0, 0x65,
  37917. 0x0a, 0x1f, 0x2c, 0x31, 0x3d, 0x79, 0x56, 0x14,
  37918. 0x1e, 0xdc, 0xc6, 0x1c, 0xb9, 0x0e, 0x9e, 0x7a,
  37919. 0xbf, 0x2f, 0xe3, 0x5f, 0xc9, 0xdc, 0x1b, 0xde,
  37920. 0x88, 0x93, 0x9f, 0xa1, 0x1f, 0x7b, 0xbe, 0x3e,
  37921. 0xb4, 0xd8, 0xff, 0xa6, 0x43, 0xb0, 0x74, 0xd7,
  37922. 0x4f, 0x45, 0x11, 0x35, 0x86, 0xe9, 0xbb, 0x12,
  37923. 0x06, 0x00, 0x03, 0xd7, 0x19, 0x41, 0xf2, 0xda,
  37924. 0x09, 0x8d, 0xc0, 0xe9, 0x6c, 0xad, 0x32, 0x55,
  37925. 0xcf, 0x32, 0x8e, 0xa2, 0xd3, 0x30, 0x8c, 0x1f,
  37926. 0x45, 0x85, 0xe8, 0x9c, 0x61, 0x3c, 0x42, 0x6b,
  37927. 0x7e, 0x79, 0x8e, 0x1e, 0xc4, 0xe9, 0x8f, 0xe6,
  37928. 0xc7, 0x1e, 0x74, 0x91, 0xf5, 0xec, 0xa0, 0xcd,
  37929. 0x05, 0x11, 0x58, 0x61, 0xbd, 0x16, 0x0e, 0x3f,
  37930. 0xe7, 0x3a, 0x58, 0xa0, 0x26, 0xba, 0x53, 0x8e,
  37931. 0x0e, 0x25, 0x6b, 0x92, 0xf1, 0xd7, 0xa2, 0x49,
  37932. 0x75, 0x70, 0x59, 0x48, 0x56, 0x86, 0x0f, 0xfd,
  37933. 0x06, 0xb6, 0x01, 0xac, 0x57, 0x55, 0x92, 0xf4,
  37934. 0xac, 0x61, 0x2b, 0x5d, 0xe7, 0x86, 0x60, 0x42,
  37935. 0x12, 0x3e, 0xbc, 0x60, 0xc5, 0x57, 0x68, 0xe3,
  37936. 0xa7, 0x60, 0x0a, 0x32, 0x60, 0x55, 0x1f, 0x2b,
  37937. 0xea, 0x22, 0xbb, 0xf6, 0xb6, 0xc8, 0x24, 0x6e,
  37938. 0x80, 0xf9, 0x12, 0x5c, 0x4b, 0xb9, 0xdb, 0x35,
  37939. 0x4d, 0xd6, 0x4a, 0xe6, 0x95, 0xc1, 0x5f, 0x50,
  37940. 0x71, 0xf4, 0xab, 0xb9, 0x63, 0x92, 0x07, 0xca,
  37941. 0xc7, 0x33, 0x1b, 0x31, 0x0f, 0x69, 0xa0, 0x5f,
  37942. 0x54, 0xb9, 0x95, 0xde, 0x52, 0x9a, 0x02, 0x3f,
  37943. 0x03, 0x3b, 0x05, 0x5d, 0xb9, 0x52, 0x87, 0xa1,
  37944. 0x4b, 0xa3, 0x0a, 0x7c, 0xc5, 0x26, 0xbb, 0x72,
  37945. 0x4c, 0x41, 0x7f, 0xba, 0x29, 0x06, 0x36, 0xa9,
  37946. 0x96, 0xf2, 0x86, 0xe3, 0xe9, 0xe9, 0x39, 0xe4,
  37947. 0xfe, 0x1c, 0x39, 0x8b, 0x5c, 0x65, 0x99, 0x95,
  37948. 0x9d, 0x0b, 0x44, 0x45, 0xa3, 0x27, 0xec, 0x46,
  37949. 0x9a, 0x16, 0x53, 0xcf, 0xae, 0xa7, 0x55, 0x2c,
  37950. 0xec, 0xec, 0x08, 0x5c, 0xca, 0xa6, 0x89, 0x38,
  37951. 0xae, 0x4a, 0xc3, 0xc4, 0x24, 0xf7, 0xe4, 0x80,
  37952. 0x43, 0x9e, 0xbd, 0x2c, 0x99, 0x2b, 0x5f, 0x6f,
  37953. 0x95, 0xec, 0x24, 0x4b, 0x65, 0x7d, 0xbd, 0xea,
  37954. 0xa9, 0xae, 0x11, 0x0a, 0xaf, 0x4d, 0x68, 0xbf,
  37955. 0x4e, 0x27, 0x41, 0x0d, 0x43, 0xce, 0xef, 0x3e,
  37956. 0x88, 0xe9, 0xc7, 0x17, 0xdd, 0x44, 0xc9, 0xee
  37957. };
  37958. #endif
  37959. #ifdef WOLFSSL_KYBER_ORIGINAL
  37960. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ss[] = {
  37961. 0xB1, 0x0F, 0x73, 0x94, 0x92, 0x6A, 0xD3, 0xB4,
  37962. 0x9C, 0x5D, 0x62, 0xD5, 0xAE, 0xB5, 0x31, 0xD5,
  37963. 0x75, 0x75, 0x38, 0xBC, 0xC0, 0xDA, 0x9E, 0x55,
  37964. 0x0D, 0x43, 0x8F, 0x1B, 0x61, 0xBD, 0x74, 0x19
  37965. };
  37966. #endif
  37967. #ifndef WOLFSSL_NO_ML_KEM
  37968. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ss[] = {
  37969. 0x48, 0x9d, 0xd1, 0xe9, 0xc2, 0xbe, 0x4a, 0xf3,
  37970. 0x48, 0x2b, 0xdb, 0x35, 0xbb, 0x26, 0xce, 0x76,
  37971. 0x0e, 0x6e, 0x41, 0x4d, 0xa6, 0xec, 0xbe, 0x48,
  37972. 0x99, 0x85, 0x74, 0x8a, 0x82, 0x5f, 0x1c, 0xd6
  37973. };
  37974. #endif
  37975. #ifdef WOLFSSL_SMALL_STACK
  37976. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37977. DYNAMIC_TYPE_TMP_BUFFER);
  37978. priv = (byte *)XMALLOC(KYBER1024_PRIVATE_KEY_SIZE, HEAP_HINT,
  37979. DYNAMIC_TYPE_TMP_BUFFER);
  37980. pub = (byte *)XMALLOC(KYBER1024_PUBLIC_KEY_SIZE, HEAP_HINT,
  37981. DYNAMIC_TYPE_TMP_BUFFER);
  37982. ct = (byte *)XMALLOC(KYBER1024_CIPHER_TEXT_SIZE, HEAP_HINT,
  37983. DYNAMIC_TYPE_TMP_BUFFER);
  37984. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37985. DYNAMIC_TYPE_TMP_BUFFER);
  37986. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37987. DYNAMIC_TYPE_TMP_BUFFER);
  37988. if (! (key && priv && pub && ct && ss && ss_dec))
  37989. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37990. #endif
  37991. #ifdef WOLFSSL_KYBER_ORIGINAL
  37992. ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
  37993. if (ret != 0)
  37994. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37995. else
  37996. key_inited = 1;
  37997. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  37998. sizeof(kyber1024_rand));
  37999. if (ret != 0)
  38000. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38001. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
  38002. if (ret != 0)
  38003. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38004. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
  38005. if (ret != 0)
  38006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38007. if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0)
  38008. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38009. if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
  38010. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38011. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38012. sizeof(kyber1024enc_rand));
  38013. if (ret != 0)
  38014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38015. if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0)
  38016. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38017. if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38018. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38019. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
  38020. if (ret != 0)
  38021. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38022. if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38023. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38024. #endif
  38025. #ifndef WOLFSSL_NO_ML_KEM
  38026. ret = wc_KyberKey_Init(WC_ML_KEM_1024, key, HEAP_HINT, INVALID_DEVID);
  38027. if (ret != 0)
  38028. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38029. else
  38030. key_inited = 1;
  38031. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  38032. sizeof(kyber1024_rand));
  38033. if (ret != 0)
  38034. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38035. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE);
  38036. if (ret != 0)
  38037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38038. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  38039. WC_ML_KEM_MAX_PRIVATE_KEY_SIZE);
  38040. if (ret != 0)
  38041. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38042. if (XMEMCMP(pub, ml_kem_1024_pk, sizeof(ml_kem_1024_pk)) != 0)
  38043. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38044. if (XMEMCMP(priv, ml_kem_1024_sk, sizeof(ml_kem_1024_sk)) != 0)
  38045. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38046. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38047. sizeof(kyber1024enc_rand));
  38048. if (ret != 0)
  38049. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38050. if (XMEMCMP(ct, ml_kem_1024_ct, sizeof(ml_kem_1024_ct)) != 0)
  38051. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38052. if (XMEMCMP(ss, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38053. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38054. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_1024_ct));
  38055. if (ret != 0)
  38056. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38057. if (XMEMCMP(ss_dec, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38058. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38059. #endif
  38060. out:
  38061. if (key_inited)
  38062. wc_KyberKey_Free(key);
  38063. #ifdef WOLFSSL_SMALL_STACK
  38064. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38065. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38066. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38067. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38068. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38069. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38070. #endif
  38071. return ret;
  38072. }
  38073. #endif /* WOLFSSL_KYBER1024 */
  38074. #endif /* WOLFSSL_WC_KYBER */
  38075. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
  38076. {
  38077. wc_test_ret_t ret;
  38078. WC_RNG rng;
  38079. int i;
  38080. #ifdef WOLFSSL_SMALL_STACK
  38081. KyberKey *key = NULL;
  38082. byte *priv = NULL;
  38083. byte *pub = NULL;
  38084. byte *priv2 = NULL;
  38085. byte *pub2 = NULL;
  38086. byte *ct = NULL;
  38087. byte *ss = NULL;
  38088. byte *ss_dec = NULL;
  38089. #else
  38090. KyberKey key[1];
  38091. byte priv[KYBER_MAX_PRIVATE_KEY_SIZE];
  38092. byte pub[KYBER_MAX_PUBLIC_KEY_SIZE];
  38093. byte priv2[KYBER_MAX_PRIVATE_KEY_SIZE];
  38094. byte pub2[KYBER_MAX_PUBLIC_KEY_SIZE];
  38095. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  38096. byte ss[KYBER_SS_SZ];
  38097. byte ss_dec[KYBER_SS_SZ];
  38098. #endif
  38099. int key_inited = 0;
  38100. static const int testData[][4] = {
  38101. #ifndef WOLFSSL_NO_ML_KEM
  38102. #ifdef WOLFSSL_WC_ML_KEM_512
  38103. { WC_ML_KEM_512, WC_ML_KEM_512_PRIVATE_KEY_SIZE,
  38104. WC_ML_KEM_512_PUBLIC_KEY_SIZE, WC_ML_KEM_512_CIPHER_TEXT_SIZE },
  38105. #endif
  38106. #ifdef WOLFSSL_WC_ML_KEM_768
  38107. { WC_ML_KEM_768, WC_ML_KEM_768_PRIVATE_KEY_SIZE,
  38108. WC_ML_KEM_768_PUBLIC_KEY_SIZE, WC_ML_KEM_768_CIPHER_TEXT_SIZE },
  38109. #endif
  38110. #ifdef WOLFSSL_WC_ML_KEM_1024
  38111. { WC_ML_KEM_1024, WC_ML_KEM_1024_PRIVATE_KEY_SIZE,
  38112. WC_ML_KEM_1024_PUBLIC_KEY_SIZE, WC_ML_KEM_1024_CIPHER_TEXT_SIZE },
  38113. #endif
  38114. #endif
  38115. #ifdef WOLFSSL_KYBER_ORIGINAL
  38116. #ifdef WOLFSSL_KYBER512
  38117. { KYBER512, KYBER512_PRIVATE_KEY_SIZE, KYBER512_PUBLIC_KEY_SIZE,
  38118. KYBER512_CIPHER_TEXT_SIZE },
  38119. #endif
  38120. #ifdef WOLFSSL_KYBER768
  38121. { KYBER768, KYBER768_PRIVATE_KEY_SIZE, KYBER768_PUBLIC_KEY_SIZE,
  38122. KYBER768_CIPHER_TEXT_SIZE },
  38123. #endif
  38124. #ifdef WOLFSSL_KYBER1024
  38125. { KYBER1024, KYBER1024_PRIVATE_KEY_SIZE, KYBER1024_PUBLIC_KEY_SIZE,
  38126. KYBER1024_CIPHER_TEXT_SIZE },
  38127. #endif
  38128. #endif
  38129. };
  38130. WOLFSSL_ENTER("kyber_test");
  38131. #ifdef WOLFSSL_SMALL_STACK
  38132. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  38133. DYNAMIC_TYPE_TMP_BUFFER);
  38134. priv = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38135. DYNAMIC_TYPE_TMP_BUFFER);
  38136. pub = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38137. DYNAMIC_TYPE_TMP_BUFFER);
  38138. priv2 = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38139. DYNAMIC_TYPE_TMP_BUFFER);
  38140. pub2 = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38141. DYNAMIC_TYPE_TMP_BUFFER);
  38142. ct = (byte *)XMALLOC(KYBER_MAX_CIPHER_TEXT_SIZE, HEAP_HINT,
  38143. DYNAMIC_TYPE_TMP_BUFFER);
  38144. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38145. DYNAMIC_TYPE_TMP_BUFFER);
  38146. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38147. DYNAMIC_TYPE_TMP_BUFFER);
  38148. if (! (key && priv && pub && priv2 && pub2 && ct && ss && ss_dec))
  38149. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38150. #endif
  38151. #ifndef HAVE_FIPS
  38152. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  38153. #else
  38154. ret = wc_InitRng(&rng);
  38155. #endif
  38156. if (ret != 0)
  38157. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38158. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  38159. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38160. if (ret != 0)
  38161. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38162. else
  38163. key_inited = 1;
  38164. ret = wc_KyberKey_MakeKey(key, &rng);
  38165. if (ret != 0)
  38166. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38167. ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
  38168. if (ret != 0)
  38169. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38170. ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
  38171. if (ret != 0)
  38172. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38173. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38174. if (ret != 0)
  38175. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38176. ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
  38177. if (ret != 0)
  38178. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38179. ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
  38180. if (ret != 0)
  38181. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38182. ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
  38183. if (ret != 0)
  38184. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38185. if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
  38186. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38187. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38188. if (ret != 0)
  38189. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38190. ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
  38191. if (ret != 0)
  38192. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38193. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
  38194. if (ret != 0)
  38195. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38196. if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
  38197. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38198. ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
  38199. if (ret != 0)
  38200. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38201. if (XMEMCMP(priv, priv2, testData[i][2]) != 0)
  38202. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38203. }
  38204. wc_FreeRng(&rng);
  38205. #ifdef WOLFSSL_WC_KYBER
  38206. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  38207. ret = kyber512_kat();
  38208. if (ret != 0)
  38209. goto out;
  38210. #endif
  38211. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  38212. ret = kyber768_kat();
  38213. if (ret != 0)
  38214. goto out;
  38215. #endif
  38216. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  38217. ret = kyber1024_kat();
  38218. if (ret != 0)
  38219. goto out;
  38220. #endif
  38221. #endif /* WOLFSSL_WC_KYBER */
  38222. out:
  38223. if (key_inited)
  38224. wc_KyberKey_Free(key);
  38225. #ifdef WOLFSSL_SMALL_STACK
  38226. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38227. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38228. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38229. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38230. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38231. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38232. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38233. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38234. #endif
  38235. return ret;
  38236. }
  38237. #endif /* WOLFSSL_HAVE_KYBER */
  38238. #ifdef HAVE_DILITHIUM
  38239. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  38240. static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
  38241. word32 pubKeyLen, const byte* sig, word32 sigLen)
  38242. {
  38243. byte msg[512];
  38244. dilithium_key* key;
  38245. byte * pubExported = NULL;
  38246. wc_test_ret_t ret;
  38247. int i;
  38248. int res = 0;
  38249. word32 lenExported = pubKeyLen;
  38250. int n_diff = 0;
  38251. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  38252. DYNAMIC_TYPE_TMP_BUFFER);
  38253. if (key == NULL) {
  38254. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38255. }
  38256. pubExported = (byte*)XMALLOC(pubKeyLen, HEAP_HINT,
  38257. DYNAMIC_TYPE_TMP_BUFFER);
  38258. if (pubExported == NULL) {
  38259. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38260. }
  38261. /* make dummy msg */
  38262. for (i = 0; i < (int)sizeof(msg); i++) {
  38263. msg[i] = (byte)i;
  38264. }
  38265. ret = wc_dilithium_init(key);
  38266. if (ret != 0) {
  38267. ret = WC_TEST_RET_ENC_EC(ret);
  38268. return ret;
  38269. }
  38270. ret = wc_dilithium_set_level(key, param);
  38271. if (ret != 0)
  38272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38273. ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
  38274. if (ret != 0)
  38275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38276. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38277. if (param >= WC_ML_DSA_DRAFT) {
  38278. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg),
  38279. &res, key);
  38280. }
  38281. else
  38282. #endif
  38283. {
  38284. ret = wc_dilithium_verify_ctx_msg(sig, sigLen, NULL, 0, msg,
  38285. (word32)sizeof(msg), &res, key);
  38286. }
  38287. if (ret != 0)
  38288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38289. if (res != 1)
  38290. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  38291. /* Now test the export pub raw API, verify we recover the original pub. */
  38292. ret = wc_dilithium_export_public(key, pubExported, &lenExported);
  38293. if (ret != 0) {
  38294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38295. }
  38296. if (lenExported <= 0 || lenExported != pubKeyLen) {
  38297. ERROR_OUT(WC_TEST_RET_ENC_EC(lenExported), out);
  38298. }
  38299. n_diff = XMEMCMP(pubExported, pubKey, pubKeyLen);
  38300. if (n_diff) {
  38301. ERROR_OUT(WC_TEST_RET_ENC_EC(n_diff), out);
  38302. }
  38303. out:
  38304. wc_dilithium_free(key);
  38305. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38306. XFREE(pubExported, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38307. return ret;
  38308. }
  38309. #ifndef WOLFSSL_NO_ML_DSA_44
  38310. static wc_test_ret_t dilithium_param_44_vfy_test(void)
  38311. {
  38312. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_pub_key[] = {
  38313. 0xd8, 0xac, 0xaf, 0xd8, 0x2e, 0x14, 0x23, 0x78, 0xf7, 0x0d, 0x9a, 0x04,
  38314. 0x2b, 0x92, 0x48, 0x67, 0x60, 0x55, 0x34, 0xd9, 0xac, 0x0b, 0xc4, 0x1f,
  38315. 0x46, 0xe8, 0x85, 0xb9, 0x2e, 0x1b, 0x10, 0x3a, 0x75, 0x7a, 0xc2, 0xbc,
  38316. 0x76, 0xf0, 0x6d, 0x05, 0xa4, 0x78, 0x48, 0x84, 0x26, 0x69, 0xbd, 0x26,
  38317. 0x1d, 0x73, 0x60, 0xaa, 0x57, 0x9d, 0x8c, 0x66, 0xb1, 0x19, 0xea, 0x11,
  38318. 0xff, 0xbb, 0xf6, 0xeb, 0x26, 0x26, 0xac, 0x78, 0x74, 0x46, 0x6d, 0x51,
  38319. 0x6e, 0x92, 0xdf, 0x6a, 0x98, 0x41, 0xe9, 0x10, 0xf2, 0xcc, 0xa8, 0x7a,
  38320. 0x50, 0xdb, 0x1f, 0x4c, 0x42, 0x19, 0xd5, 0xbc, 0x76, 0x20, 0x6f, 0x2f,
  38321. 0xbf, 0xc2, 0xc9, 0x1b, 0x02, 0xb5, 0xb1, 0x09, 0x46, 0x06, 0x87, 0x02,
  38322. 0xac, 0x3d, 0xcf, 0xc3, 0xa5, 0x1b, 0xf0, 0xce, 0xd4, 0x9e, 0x84, 0x34,
  38323. 0x3c, 0x24, 0x7d, 0x89, 0xf3, 0xbf, 0x9c, 0x18, 0x9d, 0x1b, 0x1d, 0xd4,
  38324. 0xf6, 0xda, 0xc9, 0xa4, 0x14, 0xc4, 0x6b, 0xd7, 0x05, 0x6d, 0xed, 0x54,
  38325. 0x42, 0x6b, 0x5f, 0x6d, 0x1e, 0xda, 0x6b, 0x47, 0x70, 0xe5, 0x4e, 0xe7,
  38326. 0x25, 0x06, 0xf8, 0x28, 0x24, 0x34, 0xd6, 0xe5, 0xbe, 0xc5, 0x4f, 0x9e,
  38327. 0x5d, 0x33, 0xfc, 0xef, 0xe4, 0xe9, 0x55, 0x67, 0x93, 0x1f, 0x2e, 0x11,
  38328. 0x3a, 0x2e, 0xf2, 0xbb, 0x82, 0x09, 0x8d, 0xb2, 0x09, 0xf3, 0x2f, 0xef,
  38329. 0x6f, 0x38, 0xc6, 0x56, 0xf2, 0x23, 0x08, 0x63, 0x99, 0x7f, 0x4e, 0xc0,
  38330. 0x9d, 0x08, 0x9d, 0xa1, 0x59, 0x6e, 0xe1, 0x00, 0x2c, 0x99, 0xec, 0x83,
  38331. 0x2f, 0x12, 0x97, 0x2f, 0x75, 0x04, 0x67, 0x44, 0xb5, 0x95, 0xce, 0xc6,
  38332. 0x3e, 0x7a, 0x10, 0x77, 0x5e, 0xbe, 0x9c, 0x0f, 0xb3, 0xc7, 0x38, 0xbf,
  38333. 0x9e, 0x35, 0x8f, 0xe4, 0x8d, 0x19, 0xc3, 0x41, 0xb1, 0x0b, 0x8c, 0x10,
  38334. 0x9a, 0x58, 0xec, 0x4f, 0xb3, 0xe9, 0x5b, 0x72, 0x4b, 0xb8, 0x99, 0x34,
  38335. 0x9a, 0xcd, 0xb0, 0x69, 0xd0, 0x67, 0xef, 0x96, 0xb9, 0xe5, 0x54, 0x92,
  38336. 0xb7, 0x1a, 0x52, 0xf6, 0x0a, 0xc2, 0x23, 0x8d, 0x4f, 0xad, 0x00, 0xae,
  38337. 0x0f, 0x97, 0xfa, 0xce, 0x96, 0xba, 0xe7, 0x74, 0x55, 0xd4, 0xaf, 0xbf,
  38338. 0xa1, 0x32, 0x91, 0x2d, 0x03, 0x9f, 0xe3, 0x10, 0x8c, 0x77, 0x5d, 0x26,
  38339. 0x76, 0xf1, 0x87, 0x90, 0xf0, 0x20, 0xd1, 0xea, 0xf7, 0xa4, 0xe8, 0x2c,
  38340. 0x32, 0x1c, 0x55, 0xc0, 0x5d, 0xc9, 0xcd, 0x4e, 0x8f, 0x0d, 0xef, 0x0a,
  38341. 0x27, 0xb6, 0x4f, 0xa4, 0xd3, 0xa4, 0xed, 0x33, 0x22, 0xa1, 0xd3, 0x15,
  38342. 0xac, 0x1a, 0x20, 0x4e, 0x28, 0x8c, 0x8c, 0xd0, 0x71, 0xd1, 0xf2, 0xdb,
  38343. 0x33, 0x63, 0xb6, 0xa4, 0xf2, 0x17, 0x3c, 0x12, 0xb0, 0xad, 0xef, 0x31,
  38344. 0x91, 0xfe, 0xe5, 0x53, 0x99, 0xb6, 0x85, 0x63, 0xfa, 0xe6, 0xcd, 0xf6,
  38345. 0xb9, 0xce, 0x4a, 0x7d, 0x4a, 0x49, 0x29, 0xd2, 0xd9, 0xc9, 0x47, 0x4a,
  38346. 0x8a, 0x5c, 0x14, 0x5e, 0x0f, 0x7c, 0xc3, 0x91, 0xb0, 0xab, 0x37, 0xf5,
  38347. 0x26, 0x8d, 0x46, 0x74, 0x49, 0xad, 0x51, 0xc3, 0x11, 0xfa, 0x85, 0x15,
  38348. 0xa5, 0x84, 0xc1, 0xe0, 0x3c, 0x13, 0x6d, 0x13, 0xa3, 0xe6, 0xa8, 0x3c,
  38349. 0x22, 0xac, 0x17, 0x48, 0x57, 0x7c, 0x81, 0xe2, 0x4e, 0xd8, 0x33, 0x5d,
  38350. 0x4d, 0x65, 0xf7, 0xe1, 0xb8, 0x00, 0x78, 0x09, 0x16, 0xb0, 0x0b, 0xca,
  38351. 0x15, 0x0d, 0xcd, 0x9a, 0xd8, 0x47, 0x4c, 0x9b, 0x69, 0xb2, 0xa0, 0x9d,
  38352. 0x96, 0x96, 0x52, 0x6d, 0x89, 0xad, 0xff, 0x55, 0xde, 0x7b, 0xd6, 0x3d,
  38353. 0x1d, 0x5e, 0x8d, 0xf1, 0xfc, 0x48, 0x1c, 0x50, 0x59, 0x55, 0xb9, 0x07,
  38354. 0xfd, 0x6b, 0xcb, 0x95, 0xa6, 0x14, 0x73, 0xdb, 0x40, 0x40, 0x1c, 0x44,
  38355. 0xe6, 0x79, 0x30, 0x88, 0xbd, 0xa0, 0xde, 0x9b, 0xb8, 0x76, 0xf8, 0x98,
  38356. 0x56, 0x4b, 0xb9, 0x7a, 0xf6, 0xd4, 0x73, 0x89, 0x6b, 0xf7, 0x7d, 0x05,
  38357. 0x33, 0xbe, 0xb6, 0x1c, 0x4d, 0xa7, 0x12, 0x3b, 0x3f, 0xed, 0x4a, 0x0f,
  38358. 0xae, 0xa7, 0x6a, 0x26, 0x0d, 0x01, 0x84, 0x84, 0xa8, 0x0e, 0xc1, 0xc1,
  38359. 0xfd, 0xe4, 0xa9, 0xe2, 0x3f, 0xab, 0xce, 0x20, 0x90, 0x86, 0x79, 0xa2,
  38360. 0x40, 0xd0, 0xef, 0x79, 0x34, 0x2b, 0xe8, 0xc9, 0x54, 0xa7, 0x19, 0x62,
  38361. 0xcc, 0x20, 0x79, 0x3f, 0x5b, 0x9c, 0x61, 0xc2, 0xc1, 0xd2, 0x36, 0x7c,
  38362. 0x8e, 0xe3, 0x01, 0xbe, 0xc4, 0xb2, 0xb8, 0x07, 0x51, 0x23, 0x5b, 0x5d,
  38363. 0x00, 0xe6, 0x7f, 0xd6, 0xbb, 0x32, 0xa9, 0x7e, 0xb4, 0x30, 0xeb, 0x5e,
  38364. 0x6d, 0xed, 0xb2, 0xc3, 0x88, 0x81, 0xa3, 0x3b, 0x1f, 0x1e, 0xf9, 0x48,
  38365. 0x10, 0xd6, 0x01, 0x65, 0x5f, 0x6d, 0xc5, 0xeb, 0x76, 0x5f, 0x10, 0x79,
  38366. 0xaa, 0xc0, 0x86, 0xe7, 0x44, 0x95, 0x44, 0x4b, 0x54, 0x0c, 0x46, 0x2a,
  38367. 0x98, 0x01, 0x6e, 0xc0, 0xb9, 0x59, 0x2a, 0xff, 0x8f, 0xb3, 0x80, 0x15,
  38368. 0xec, 0xcd, 0x39, 0x36, 0xd7, 0x2f, 0x20, 0x9e, 0x3a, 0xc1, 0x90, 0xe5,
  38369. 0x99, 0x27, 0x16, 0xd7, 0x6c, 0x30, 0x10, 0x12, 0x03, 0x3e, 0xdc, 0xb9,
  38370. 0x03, 0x25, 0xb0, 0x8a, 0x27, 0x4d, 0x1a, 0x32, 0x36, 0x54, 0xc0, 0xba,
  38371. 0x22, 0xb2, 0xe2, 0xf6, 0x39, 0x23, 0x03, 0xc4, 0xc9, 0xe4, 0x0d, 0x99,
  38372. 0xfb, 0x98, 0xa5, 0x9b, 0x12, 0x9b, 0x58, 0x44, 0x74, 0x9f, 0x65, 0x61,
  38373. 0x51, 0xba, 0x31, 0x60, 0x9c, 0xec, 0xf8, 0x4d, 0x36, 0x61, 0xd1, 0x33,
  38374. 0x6d, 0xa6, 0x28, 0x75, 0xba, 0x7c, 0x82, 0xcb, 0x7e, 0xbe, 0x8f, 0x2d,
  38375. 0x21, 0x84, 0xb9, 0xf2, 0x4e, 0x7b, 0x95, 0x99, 0x11, 0xf3, 0xe1, 0xc0,
  38376. 0x6a, 0x44, 0xae, 0x11, 0xcb, 0x04, 0xa0, 0xf2, 0x3e, 0x17, 0xdf, 0xb2,
  38377. 0x6a, 0xdf, 0x5c, 0xf3, 0x8a, 0xf8, 0x90, 0x86, 0x64, 0xea, 0x0a, 0x32,
  38378. 0x7f, 0x9f, 0x90, 0xa8, 0x9d, 0x33, 0x12, 0xa6, 0xa4, 0xe7, 0x74, 0xa0,
  38379. 0x75, 0xa9, 0x65, 0xf8, 0x39, 0xae, 0x14, 0x32, 0x79, 0xcc, 0xaa, 0x34,
  38380. 0x86, 0x55, 0xcc, 0x99, 0xb7, 0x00, 0x05, 0x8b, 0xe3, 0x76, 0x28, 0x12,
  38381. 0xb6, 0x2a, 0x3e, 0x44, 0x8d, 0xf4, 0xba, 0xef, 0xf6, 0xdc, 0x29, 0x08,
  38382. 0x29, 0x7d, 0xd1, 0x1d, 0x17, 0x15, 0xb6, 0xb6, 0x58, 0x67, 0xd5, 0xd3,
  38383. 0x12, 0x05, 0x4e, 0xb0, 0xc3, 0x83, 0xe0, 0x35, 0x30, 0x60, 0x59, 0xa0,
  38384. 0xc5, 0x97, 0x5b, 0x81, 0xd3, 0x68, 0x6c, 0x8c, 0x17, 0x28, 0xa9, 0x24,
  38385. 0x4f, 0x80, 0x20, 0xa5, 0x21, 0x9f, 0x8f, 0x15, 0x89, 0x2d, 0x87, 0xae,
  38386. 0x2e, 0xcc, 0x73, 0x3e, 0x06, 0x43, 0xbc, 0xb3, 0x1b, 0xa6, 0x72, 0xaa,
  38387. 0xa3, 0xaa, 0xbb, 0x6f, 0x2d, 0x68, 0x60, 0xcf, 0x05, 0x94, 0x25, 0x3e,
  38388. 0x59, 0xf3, 0x64, 0x61, 0x5e, 0x78, 0x9a, 0x7e, 0x0d, 0x50, 0x45, 0x78,
  38389. 0x51, 0xab, 0x11, 0xb1, 0xc6, 0x95, 0xfc, 0x29, 0x28, 0x10, 0x9c, 0x1a,
  38390. 0x8c, 0x37, 0xb5, 0x4f, 0x0e, 0xed, 0x4a, 0x28, 0x6c, 0xaa, 0xb7, 0x0d,
  38391. 0x12, 0xfa, 0x87, 0x5d, 0xd4, 0x9a, 0xb7, 0x2b, 0x46, 0x90, 0x58, 0x4e,
  38392. 0xd7, 0x8b, 0x41, 0x1b, 0xf8, 0xc4, 0xc2, 0xde, 0xda, 0xec, 0x61, 0xe7,
  38393. 0xbf, 0x11, 0xdd, 0x6e, 0x4e, 0x6a, 0xd4, 0x87, 0x01, 0xe4, 0xac, 0xe8,
  38394. 0xaf, 0x2b, 0x01, 0xe1, 0x09, 0x20, 0xe0, 0xbd, 0x7d, 0x03, 0x73, 0x23,
  38395. 0xdf, 0x77, 0x71, 0xa4, 0x25, 0x8b, 0x0a, 0x93, 0x49, 0x32, 0x45, 0x1a,
  38396. 0xa4, 0x94, 0x31, 0x61, 0x2e, 0x17, 0x39, 0x8a, 0x66, 0xc9, 0xf9, 0x20,
  38397. 0x2d, 0x6a, 0x97, 0x2f, 0xe7, 0x26, 0xd8, 0x01, 0x42, 0x65, 0xcf, 0xce,
  38398. 0xd4, 0x24, 0x41, 0xfb, 0x9b, 0x6f, 0xf1, 0xc2, 0x9e, 0xd5, 0x08, 0x0c,
  38399. 0xdc, 0x4d, 0x8e, 0xae, 0xcb, 0x5f, 0xd4, 0xcd, 0x7c, 0xf6, 0x82, 0xc6,
  38400. 0xee, 0xf9, 0x88, 0x3a, 0x34, 0x07, 0x04, 0xb4, 0x84, 0x69, 0xb3, 0xa4,
  38401. 0x67, 0xab, 0x09, 0xc0, 0x83, 0xfe, 0x59, 0xaf, 0x18, 0x2c, 0xc8, 0x09,
  38402. 0xc1, 0xbb, 0x13, 0x7c, 0xce, 0x01, 0x5d, 0x85, 0xaa, 0x10, 0x28, 0xa2,
  38403. 0x96, 0x98, 0x69, 0x23, 0xa3, 0xe7, 0x67, 0xbc, 0x7c, 0x7e, 0xde, 0x4b,
  38404. 0x36, 0xab, 0x94, 0xd2, 0xb8, 0xf9, 0xdf, 0xee, 0xa1, 0x69, 0xa1, 0xc8,
  38405. 0xe9, 0x83, 0x21, 0xac, 0x1b, 0x39, 0xf7, 0x6d, 0xbf, 0x8c, 0xdb, 0xd6,
  38406. 0x2f, 0xc9, 0x3c, 0x3d, 0x50, 0xcf, 0x7f, 0xbe, 0x4a, 0x8d, 0xd8, 0x14,
  38407. 0xad, 0x69, 0xb0, 0x3e, 0x8a, 0xaf, 0xeb, 0xd9, 0x1a, 0x15, 0x4a, 0xe4,
  38408. 0xdd, 0xd9, 0xb2, 0xf8, 0x6b, 0xe2, 0x42, 0x9e, 0x29, 0x16, 0xfc, 0x85,
  38409. 0x9c, 0x47, 0x4b, 0x1f, 0x3d, 0x7b, 0x8c, 0xe1, 0x6d, 0xa3, 0xb8, 0x0a,
  38410. 0xe6, 0xfa, 0x27, 0xfe, 0x52, 0x72, 0xab, 0x3a, 0xa6, 0x58, 0xd7, 0x53,
  38411. 0xaf, 0x9f, 0xee, 0x03, 0x85, 0xfc, 0xa4, 0x7a, 0x72, 0x29, 0x7e, 0x62,
  38412. 0x28, 0x08, 0x79, 0xa8, 0xb8, 0xc7, 0x51, 0x8d, 0xaa, 0x40, 0x2d, 0x4a,
  38413. 0xd9, 0x47, 0xb4, 0xa8, 0xa2, 0x0a, 0x43, 0xd0, 0xe0, 0x4a, 0x39, 0xa3,
  38414. 0x06, 0x08, 0x9a, 0xe2, 0xf3, 0xf2, 0xf8, 0xb9, 0x9f, 0x63, 0x32, 0xa0,
  38415. 0x65, 0x0b, 0xb0, 0x50, 0x96, 0xa6, 0xa8, 0x7a, 0x18, 0xdd, 0x6c, 0xd1,
  38416. 0x9b, 0xd9, 0x4e, 0x76, 0x8f, 0xfb, 0x22, 0xa6, 0x1d, 0x29, 0xfc, 0xb8,
  38417. 0x47, 0x29, 0xb6, 0xd1, 0xb1, 0x63, 0x4a, 0x36, 0x1b, 0x10, 0xe6, 0x4c,
  38418. 0x65, 0x68, 0x1f, 0xad, 0x4f, 0x7d, 0x6b, 0x01, 0x41, 0x18, 0x5f, 0xba,
  38419. 0x3d, 0xa6, 0x54, 0x28, 0x58, 0xd5, 0x81, 0x60, 0xdf, 0x84, 0x76, 0x00,
  38420. 0x21, 0x53, 0xeb, 0xd3, 0xa6, 0xec, 0x7d, 0x3c, 0xb8, 0xcd, 0x91, 0x4c,
  38421. 0x2f, 0x4b, 0x2e, 0x23, 0x4c, 0x0f, 0x0f, 0xe0, 0x14, 0xa5, 0xe7, 0xe5,
  38422. 0x70, 0x8d, 0x8b, 0x9c
  38423. };
  38424. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38425. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_pub_key[] = {
  38426. 0xea, 0x05, 0x24, 0x0d, 0x80, 0x72, 0x25, 0x55, 0xf4, 0x5b,
  38427. 0xc2, 0x13, 0x8b, 0x87, 0x5d, 0x31, 0x99, 0x2f, 0x1d, 0xa9,
  38428. 0x41, 0x09, 0x05, 0x76, 0xa7, 0xb7, 0x5e, 0x8c, 0x44, 0xe2,
  38429. 0x64, 0x79, 0xa0, 0xec, 0x1f, 0x24, 0xb6, 0xc8, 0x05, 0x5b,
  38430. 0xc1, 0x18, 0xb0, 0xb7, 0xcf, 0x8c, 0x60, 0x67, 0x6b, 0x81,
  38431. 0x44, 0x27, 0xb6, 0x0e, 0xfd, 0x9b, 0xc3, 0xcb, 0x52, 0x31,
  38432. 0xfa, 0xc9, 0x34, 0x8d, 0x22, 0x1e, 0x07, 0x9d, 0x96, 0x6a,
  38433. 0x63, 0x83, 0x5c, 0xd7, 0x83, 0x2d, 0x7f, 0x48, 0x64, 0x79,
  38434. 0xca, 0xb4, 0x9f, 0xa2, 0x02, 0xb7, 0x86, 0x1d, 0x0e, 0xc7,
  38435. 0xf9, 0x6c, 0x07, 0xc0, 0x35, 0x6a, 0x34, 0x79, 0x7c, 0xb8,
  38436. 0x0f, 0xed, 0x98, 0x50, 0xfb, 0x51, 0xe0, 0x36, 0x44, 0x4c,
  38437. 0xc6, 0x35, 0xa2, 0xbb, 0x55, 0xb0, 0x5c, 0x39, 0x08, 0x02,
  38438. 0x20, 0x35, 0x5c, 0x56, 0x6d, 0x2e, 0xb9, 0xef, 0x21, 0x26,
  38439. 0x87, 0x87, 0x85, 0x8a, 0x32, 0xb5, 0xa7, 0x68, 0x70, 0x3a,
  38440. 0xfd, 0x0d, 0x21, 0x48, 0x91, 0xa3, 0x29, 0xc1, 0x2a, 0x38,
  38441. 0xe5, 0x26, 0x31, 0x1f, 0x42, 0xde, 0x0b, 0x25, 0xff, 0x1d,
  38442. 0x6b, 0xb4, 0xe0, 0x5d, 0x2d, 0xcf, 0x44, 0xd5, 0x7d, 0xc4,
  38443. 0xf6, 0x95, 0xf2, 0x06, 0x4f, 0x83, 0x88, 0x9d, 0x1e, 0xeb,
  38444. 0x1c, 0x09, 0x45, 0x62, 0x67, 0x3d, 0xff, 0x51, 0x47, 0xe8,
  38445. 0xbc, 0x9b, 0x03, 0x1f, 0xc7, 0x72, 0x65, 0xce, 0xa8, 0x8c,
  38446. 0xc2, 0xa0, 0xc2, 0xbd, 0x5b, 0x7c, 0x17, 0x16, 0x8b, 0x72,
  38447. 0xfa, 0xb1, 0xbd, 0xdf, 0x49, 0xd6, 0xa1, 0x00, 0x65, 0xbe,
  38448. 0x82, 0xe7, 0x68, 0xc7, 0xe7, 0xbc, 0xc2, 0xa4, 0xdb, 0xaa,
  38449. 0xcc, 0xea, 0x41, 0x52, 0x7f, 0x56, 0xb4, 0x68, 0x1f, 0x92,
  38450. 0x96, 0x0f, 0xce, 0xd4, 0xd0, 0x87, 0x4c, 0x4a, 0x73, 0xb5,
  38451. 0x6c, 0xd4, 0x69, 0x55, 0x15, 0x47, 0xdc, 0x94, 0x7f, 0xd2,
  38452. 0x54, 0x5e, 0xb2, 0x90, 0xc2, 0x47, 0xe4, 0xf5, 0xde, 0x8b,
  38453. 0x9b, 0xc6, 0x5d, 0x50, 0x95, 0x60, 0xe0, 0xf0, 0xa7, 0x4e,
  38454. 0xe0, 0xcd, 0x41, 0x09, 0xef, 0xb3, 0x3d, 0x90, 0x5c, 0x77,
  38455. 0x54, 0xec, 0x9e, 0x5d, 0x8a, 0xe7, 0x09, 0x5c, 0xc9, 0x58,
  38456. 0x0c, 0xd0, 0x42, 0x35, 0xd2, 0x14, 0x59, 0x38, 0x69, 0xad,
  38457. 0xf9, 0xb5, 0xbf, 0x8a, 0x8e, 0x33, 0xd8, 0x5e, 0x7a, 0x55,
  38458. 0xd0, 0x53, 0x15, 0x40, 0x4e, 0xc5, 0x86, 0xd7, 0x8f, 0x5f,
  38459. 0x2f, 0x55, 0x82, 0xc2, 0x4f, 0x16, 0xe5, 0xea, 0x1c, 0xbc,
  38460. 0xff, 0x5e, 0x1f, 0x39, 0x46, 0x70, 0x54, 0x7a, 0x3a, 0x27,
  38461. 0x16, 0x1a, 0x2b, 0x6c, 0xd2, 0xb7, 0x80, 0xd3, 0xd1, 0x9d,
  38462. 0x25, 0x59, 0xed, 0xe6, 0x51, 0xb1, 0xf2, 0xad, 0x7e, 0x51,
  38463. 0x78, 0x14, 0x2b, 0x19, 0xae, 0x64, 0x72, 0x0f, 0xd8, 0x18,
  38464. 0x79, 0x8e, 0x66, 0x88, 0xd3, 0xa4, 0xa3, 0xc3, 0x76, 0x21,
  38465. 0xcb, 0xe4, 0x79, 0x5e, 0x95, 0x74, 0xe3, 0x31, 0x18, 0x79,
  38466. 0xed, 0xc7, 0xe7, 0xfb, 0x86, 0x48, 0x1b, 0x7b, 0x75, 0x5b,
  38467. 0x7f, 0x7c, 0x82, 0xc5, 0xab, 0x11, 0xb4, 0x5d, 0x59, 0x6f,
  38468. 0x78, 0xb2, 0xa5, 0x39, 0xc6, 0x63, 0x38, 0x6c, 0xeb, 0x50,
  38469. 0x06, 0x14, 0x76, 0xf0, 0xe8, 0xfb, 0x11, 0x95, 0x1f, 0x9d,
  38470. 0x9c, 0xa6, 0xe1, 0xe2, 0x0d, 0xa3, 0x66, 0xfc, 0x20, 0x83,
  38471. 0x50, 0x0e, 0x53, 0x75, 0xb5, 0x12, 0xf4, 0xdf, 0x31, 0x46,
  38472. 0x83, 0xac, 0x5b, 0xf3, 0x99, 0xa6, 0xd1, 0x7b, 0x2b, 0xc5,
  38473. 0xdc, 0x71, 0x07, 0x27, 0x33, 0x35, 0x34, 0xf5, 0x30, 0x19,
  38474. 0xc1, 0x3b, 0xba, 0x8a, 0xaf, 0x7e, 0x49, 0x93, 0x48, 0x5b,
  38475. 0x38, 0xc0, 0xbc, 0x2e, 0xc7, 0x59, 0x1b, 0xd9, 0xf5, 0xcc,
  38476. 0x86, 0xf5, 0x7b, 0x4d, 0xd7, 0x39, 0xa7, 0xa2, 0x56, 0x20,
  38477. 0x48, 0x98, 0x7d, 0x4f, 0x75, 0x56, 0x9b, 0xb8, 0x95, 0x45,
  38478. 0x17, 0xf3, 0x86, 0x3d, 0x97, 0x0a, 0x49, 0x1b, 0xca, 0xff,
  38479. 0x20, 0xc0, 0x24, 0x2c, 0x51, 0xc2, 0x0a, 0x3c, 0xbf, 0x07,
  38480. 0x60, 0x1c, 0x88, 0x85, 0x9b, 0x85, 0x2d, 0x4a, 0xfe, 0x5a,
  38481. 0x1c, 0x90, 0xf5, 0x90, 0x12, 0xd3, 0x03, 0x3c, 0x8c, 0x2e,
  38482. 0x95, 0x4a, 0x47, 0x76, 0x0f, 0x1f, 0x5d, 0x9e, 0xed, 0xc5,
  38483. 0x64, 0xc4, 0x9b, 0xbf, 0x86, 0xc5, 0x63, 0x84, 0x33, 0x00,
  38484. 0xf1, 0x26, 0x18, 0x21, 0xf3, 0x88, 0x1a, 0x08, 0x18, 0x6d,
  38485. 0x2f, 0xef, 0xd5, 0xeb, 0x2f, 0x69, 0xc8, 0x6e, 0x92, 0x34,
  38486. 0xfc, 0x72, 0x3d, 0x9a, 0xa7, 0x9e, 0x51, 0xfb, 0x56, 0xe3,
  38487. 0xdc, 0xf4, 0x8f, 0x9b, 0x6d, 0x0d, 0x2a, 0xec, 0x66, 0x12,
  38488. 0x26, 0x35, 0xbd, 0x61, 0xc2, 0x67, 0x19, 0xf5, 0x7e, 0xa1,
  38489. 0x67, 0xa2, 0x9c, 0x3b, 0x67, 0xb0, 0xc2, 0x51, 0x6a, 0x37,
  38490. 0x7c, 0x48, 0xe9, 0x4b, 0xb9, 0xa3, 0x38, 0x2f, 0xfc, 0xde,
  38491. 0xb4, 0x7c, 0xda, 0x52, 0x84, 0x0b, 0xb0, 0xd9, 0x08, 0xe9,
  38492. 0x7a, 0x4a, 0x6f, 0x79, 0x29, 0x3d, 0xc4, 0x5c, 0x78, 0xee,
  38493. 0x63, 0xb6, 0x96, 0x68, 0xd9, 0x82, 0x4e, 0xc1, 0x1b, 0x6f,
  38494. 0x52, 0xf5, 0xb3, 0xfb, 0xe8, 0xc4, 0x2a, 0x07, 0xc6, 0x3b,
  38495. 0x85, 0x0d, 0xf4, 0xbf, 0xb0, 0x6b, 0xfb, 0xce, 0x1d, 0xb4,
  38496. 0xbf, 0x63, 0x0b, 0x91, 0x67, 0xc4, 0xa3, 0x06, 0xa4, 0xaf,
  38497. 0x6c, 0xd3, 0xe5, 0x8b, 0x87, 0x4e, 0x64, 0x9c, 0xb1, 0xf3,
  38498. 0x70, 0x7c, 0x68, 0x43, 0x46, 0x13, 0x46, 0xee, 0x27, 0x75,
  38499. 0x12, 0x45, 0x42, 0xde, 0xa5, 0x8d, 0xcf, 0xf7, 0x09, 0x87,
  38500. 0xa8, 0x80, 0x3d, 0xb6, 0x45, 0xee, 0x41, 0x2d, 0x7c, 0x45,
  38501. 0x01, 0x9d, 0xaa, 0x78, 0xa8, 0x10, 0xa4, 0xfd, 0xb5, 0x5f,
  38502. 0xee, 0x0f, 0x77, 0xba, 0x73, 0xff, 0x49, 0xdc, 0xfa, 0x39,
  38503. 0xd6, 0xa3, 0x6f, 0x25, 0xb9, 0x63, 0x2c, 0x92, 0xc5, 0xdf,
  38504. 0xfb, 0xba, 0x89, 0xf9, 0xfa, 0x94, 0x5b, 0x6f, 0x5a, 0x4d,
  38505. 0x1c, 0xe4, 0xc9, 0x10, 0xf9, 0xa0, 0xe8, 0xc4, 0xcb, 0x55,
  38506. 0x1a, 0xdb, 0x56, 0x5f, 0x8e, 0x91, 0x03, 0x23, 0xca, 0xb0,
  38507. 0x1f, 0xef, 0xb8, 0x6c, 0x13, 0x5a, 0x99, 0x25, 0xf0, 0x49,
  38508. 0xa9, 0x5a, 0x45, 0xf7, 0xfd, 0x1a, 0xc2, 0x71, 0x06, 0xe3,
  38509. 0x2d, 0x25, 0x64, 0xb0, 0x52, 0x12, 0x03, 0x62, 0xc7, 0xb6,
  38510. 0xf9, 0xdc, 0x1f, 0x78, 0xff, 0x8b, 0xfa, 0xde, 0x7f, 0x71,
  38511. 0xa6, 0x35, 0x3e, 0xac, 0x20, 0x54, 0x94, 0xa7, 0x2e, 0x9d,
  38512. 0x47, 0x17, 0x4b, 0xad, 0x92, 0xb3, 0x14, 0x26, 0x8c, 0x5a,
  38513. 0xd0, 0x16, 0x4b, 0x22, 0xe9, 0x0c, 0x79, 0x6b, 0x8e, 0xac,
  38514. 0x0d, 0x12, 0xf5, 0x66, 0x8e, 0x82, 0x1a, 0x44, 0xf3, 0xe9,
  38515. 0x56, 0x5a, 0xcd, 0x1c, 0x1b, 0x81, 0x7b, 0x63, 0x59, 0xfe,
  38516. 0xc8, 0xc0, 0xe3, 0xda, 0x16, 0x6b, 0x6f, 0x0d, 0xba, 0x0e,
  38517. 0x47, 0x12, 0x86, 0x9e, 0xf0, 0x3b, 0x4d, 0x87, 0x3b, 0xf2,
  38518. 0x75, 0x73, 0x2d, 0xdf, 0xca, 0x76, 0x0b, 0xbd, 0xe7, 0xb7,
  38519. 0x74, 0x24, 0xf3, 0xc6, 0xe6, 0x75, 0x3f, 0x8b, 0x6a, 0xd9,
  38520. 0xad, 0xed, 0xc0, 0x70, 0x04, 0x1e, 0x0b, 0x8e, 0x8b, 0x7f,
  38521. 0xea, 0xbc, 0x39, 0x6b, 0x8a, 0x44, 0xa6, 0x9a, 0x2d, 0x0d,
  38522. 0x8c, 0x21, 0x60, 0x09, 0xd2, 0x4a, 0xe0, 0x62, 0xcf, 0xfa,
  38523. 0xe8, 0x9b, 0x35, 0x6f, 0x23, 0x2f, 0xb5, 0x65, 0x08, 0x60,
  38524. 0x92, 0x15, 0xd0, 0x5b, 0x63, 0xcc, 0x65, 0x05, 0xd1, 0xef,
  38525. 0x0f, 0x7e, 0x1b, 0xb3, 0x8e, 0xc6, 0x12, 0x85, 0xc9, 0x82,
  38526. 0x53, 0x79, 0x2e, 0x80, 0x5f, 0x0c, 0x7b, 0xc7, 0x1c, 0x83,
  38527. 0x41, 0x06, 0xd8, 0x41, 0xc9, 0xe7, 0xb9, 0x4b, 0xa1, 0x61,
  38528. 0xc6, 0x86, 0x67, 0xf5, 0x10, 0xf7, 0x34, 0x0d, 0x39, 0x9e,
  38529. 0x2b, 0x5f, 0x19, 0x06, 0x02, 0xa5, 0x02, 0x23, 0x71, 0xc2,
  38530. 0x12, 0x65, 0xcc, 0x81, 0x06, 0xfd, 0x8d, 0x09, 0x68, 0x37,
  38531. 0x06, 0x3b, 0xff, 0xc4, 0x24, 0xb3, 0x1f, 0xd6, 0xe6, 0x8f,
  38532. 0x9c, 0x74, 0x2c, 0x5e, 0xc5, 0xf4, 0xe9, 0xeb, 0xca, 0xd3,
  38533. 0x04, 0x5b, 0x92, 0x9e, 0x5c, 0x1a, 0x1d, 0xa1, 0xa7, 0x34,
  38534. 0xd2, 0x05, 0xae, 0xdb, 0x3d, 0x71, 0x10, 0x6e, 0x30, 0xd9,
  38535. 0xa3, 0x44, 0xa0, 0xbd, 0x9e, 0x7b, 0xb5, 0x12, 0x8a, 0x12,
  38536. 0x07, 0x60, 0xd7, 0x1f, 0x92, 0xe6, 0xfe, 0x04, 0xa9, 0x3e,
  38537. 0x62, 0x64, 0x00, 0x5f, 0x7c, 0x7b, 0x34, 0x09, 0xeb, 0x4a,
  38538. 0x18, 0x9e, 0x77, 0x72, 0x3a, 0x31, 0x1a, 0x62, 0x2a, 0xb5,
  38539. 0xcb, 0x4e, 0x53, 0xce, 0xad, 0x8b, 0x5a, 0x20, 0x4f, 0xd7,
  38540. 0x3e, 0x16, 0xf8, 0x10, 0xe2, 0xae, 0xbd, 0x3f, 0x02, 0xa9,
  38541. 0x18, 0xa0, 0x01, 0x18, 0x84, 0x95, 0x22, 0x2e, 0x93, 0x76,
  38542. 0x44, 0x4e, 0x11, 0x7b, 0x03, 0x51, 0x50, 0x19, 0x79, 0xe7,
  38543. 0xbb, 0x5c, 0x7b, 0xca, 0x74, 0xb4, 0x25, 0x26, 0xdb, 0x66,
  38544. 0xaa, 0x0b, 0x21, 0x07, 0xfb, 0x7a, 0x96, 0x10, 0x7d, 0x99,
  38545. 0xa9, 0x16, 0xcb, 0x0e, 0xba, 0x63, 0xab, 0x95, 0xfc, 0x5a,
  38546. 0xbe, 0xa6, 0x7f, 0xd8, 0xb4, 0xcd, 0x7c, 0xc5, 0xd0, 0xb1,
  38547. 0x1b, 0x48, 0x40, 0xfb, 0xe6, 0x2f, 0x2b, 0x94, 0xfe, 0x68,
  38548. 0xa2, 0xc4, 0x36, 0xd9, 0xcd, 0xc1, 0x93, 0x6d, 0xef, 0x39,
  38549. 0x5e, 0x43, 0x30, 0x5a, 0x2e, 0x66, 0xb6, 0xf2, 0xed, 0x9a,
  38550. 0x8d, 0x12, 0xdf, 0x5c, 0xae, 0xad, 0x16, 0x12, 0x7e, 0x81,
  38551. 0x82, 0x91, 0x7d, 0x2b, 0x12, 0xe9, 0x96, 0xb8, 0xb7, 0x42,
  38552. 0xcb, 0x1f, 0xf8, 0xd1, 0xfd, 0x83, 0x7a, 0xe4, 0x36, 0x1d,
  38553. 0x04, 0x27, 0x4c, 0xe5, 0xbd, 0x75, 0x24, 0xf7, 0xbd, 0xb6,
  38554. 0x6a, 0x68, 0x4e, 0x2c, 0x1b, 0x56, 0x3e, 0x60, 0xa4, 0x42,
  38555. 0xca, 0x7a, 0x54, 0xe5, 0x06, 0xe3, 0xda, 0x05, 0xf7, 0x77,
  38556. 0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
  38557. 0xfe, 0x4b
  38558. };
  38559. #endif
  38560. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_sig[] = {
  38561. 0x27, 0x3b, 0x58, 0xa0, 0xcf, 0x00, 0x29, 0x5e, 0x1a, 0x63, 0xbf, 0xb4,
  38562. 0x97, 0x16, 0xa1, 0x9c, 0x78, 0xd1, 0x33, 0xdc, 0x72, 0xde, 0xa3, 0xfc,
  38563. 0xf4, 0x09, 0xb1, 0x09, 0x16, 0x3f, 0x80, 0x72, 0x22, 0x68, 0x65, 0x68,
  38564. 0xb9, 0x80, 0x5a, 0x4a, 0x0d, 0x73, 0x49, 0xe1, 0xc6, 0xde, 0xca, 0x08,
  38565. 0x4f, 0xca, 0xf8, 0xb2, 0xf8, 0x45, 0x3b, 0x6b, 0x8c, 0x6c, 0xfd, 0x3a,
  38566. 0xf4, 0xde, 0xde, 0x82, 0xd8, 0x04, 0xbe, 0x4f, 0x4a, 0xdb, 0x92, 0x47,
  38567. 0x83, 0x2d, 0xc4, 0x55, 0xed, 0x20, 0x4f, 0x71, 0xb1, 0x58, 0xd9, 0x70,
  38568. 0x73, 0xbd, 0xb0, 0x3a, 0xb4, 0x8f, 0xd6, 0x9e, 0x32, 0x98, 0x2b, 0x9e,
  38569. 0xff, 0x2a, 0x7c, 0xcb, 0x05, 0x1b, 0x8e, 0xe6, 0x3a, 0x45, 0xc6, 0x7a,
  38570. 0xc8, 0xaf, 0x62, 0xd3, 0x04, 0xfa, 0x69, 0x4f, 0xda, 0x1b, 0x74, 0x16,
  38571. 0x0d, 0xb3, 0x1a, 0xee, 0x71, 0xd7, 0xb0, 0xef, 0x69, 0xf5, 0xe2, 0xe9,
  38572. 0xc2, 0xcc, 0x15, 0x66, 0x28, 0x0a, 0xac, 0xe2, 0x63, 0x06, 0xb7, 0x21,
  38573. 0x0d, 0xd8, 0x5c, 0x94, 0x63, 0xfd, 0x51, 0x18, 0x9f, 0x07, 0x19, 0x3d,
  38574. 0xa2, 0x50, 0x40, 0xd3, 0xe9, 0x05, 0xd4, 0x11, 0x13, 0x15, 0xaa, 0x46,
  38575. 0xda, 0x3e, 0x5f, 0xcd, 0x3c, 0xfa, 0x42, 0xba, 0x79, 0x4a, 0xb7, 0x43,
  38576. 0x91, 0xa5, 0xcb, 0xbc, 0xeb, 0x37, 0x94, 0xf1, 0x9c, 0xb9, 0xdb, 0x41,
  38577. 0x06, 0xd8, 0x7b, 0x5e, 0x90, 0xe3, 0x3c, 0x8a, 0x10, 0x62, 0x9a, 0x15,
  38578. 0x27, 0x78, 0xed, 0x69, 0x11, 0x2c, 0xb5, 0xb4, 0xdb, 0xc8, 0x70, 0x50,
  38579. 0x62, 0x47, 0x96, 0xcb, 0xd9, 0xb2, 0x3e, 0x59, 0x2f, 0x1c, 0xac, 0xcb,
  38580. 0xcf, 0x22, 0xc2, 0x9b, 0xc7, 0x92, 0xe9, 0x4d, 0x8d, 0x5d, 0xcf, 0x06,
  38581. 0x53, 0x7e, 0xf4, 0x4e, 0xfe, 0x9e, 0x41, 0x5d, 0x00, 0x8c, 0x08, 0xf4,
  38582. 0x02, 0x79, 0x33, 0x1c, 0x27, 0x1d, 0xe3, 0x94, 0xac, 0xe6, 0x87, 0xa0,
  38583. 0x08, 0xb4, 0x60, 0x0c, 0xff, 0x47, 0xdc, 0x16, 0x3a, 0x1d, 0x89, 0xc0,
  38584. 0x6a, 0xa4, 0x3d, 0x71, 0x33, 0xdd, 0x1e, 0x70, 0xfe, 0xd4, 0x8b, 0xed,
  38585. 0x7c, 0x91, 0xe4, 0xe2, 0x15, 0x06, 0xc1, 0x83, 0x24, 0x55, 0xa7, 0x2a,
  38586. 0x9f, 0x4e, 0xd9, 0x56, 0x7a, 0x95, 0xa8, 0xdd, 0xc4, 0xf0, 0x71, 0x3a,
  38587. 0x99, 0x65, 0x31, 0x4b, 0xb7, 0x96, 0x2c, 0x53, 0x54, 0x83, 0xec, 0xc9,
  38588. 0x97, 0x2f, 0x0c, 0xa4, 0x8f, 0xbb, 0x93, 0x9d, 0xea, 0xae, 0xf9, 0xcb,
  38589. 0xb2, 0xb9, 0xa3, 0x61, 0x5f, 0x77, 0x8c, 0xb6, 0x5a, 0x56, 0xbe, 0x5f,
  38590. 0x85, 0xd1, 0xb5, 0x0a, 0x53, 0xe2, 0xc7, 0xbf, 0x76, 0x8b, 0x97, 0x6f,
  38591. 0x10, 0xdd, 0x1f, 0x44, 0x69, 0x66, 0x03, 0xc4, 0x6b, 0x59, 0xf7, 0xb4,
  38592. 0xc1, 0x12, 0xcc, 0x00, 0x70, 0xe8, 0xbd, 0x44, 0x28, 0xf5, 0xfa, 0x96,
  38593. 0xf3, 0x59, 0xed, 0x81, 0x67, 0xe0, 0xbe, 0x47, 0x75, 0xb3, 0xa8, 0x9f,
  38594. 0x21, 0x70, 0x2e, 0x6f, 0xef, 0x54, 0x11, 0x3f, 0x34, 0xaf, 0x0d, 0x73,
  38595. 0x5b, 0x9e, 0x6d, 0x86, 0x58, 0xb7, 0x34, 0xc2, 0xc2, 0xb3, 0x64, 0xd5,
  38596. 0x9b, 0x6e, 0xb9, 0x99, 0x6a, 0xe4, 0xfd, 0xc3, 0x17, 0xf3, 0x10, 0xfc,
  38597. 0x6e, 0xf5, 0x65, 0xe1, 0x9c, 0x59, 0x15, 0x11, 0x00, 0xea, 0x96, 0x81,
  38598. 0x69, 0x9b, 0x05, 0x4d, 0xf3, 0xce, 0xf3, 0xf0, 0xa9, 0x01, 0x3f, 0x13,
  38599. 0xbb, 0xb0, 0xac, 0xc3, 0x92, 0x1c, 0x2b, 0x61, 0xe3, 0x01, 0x22, 0x45,
  38600. 0x4a, 0x23, 0x19, 0x80, 0xca, 0xb9, 0xef, 0x4e, 0x76, 0x52, 0xc5, 0x9d,
  38601. 0x91, 0x33, 0x17, 0xc4, 0x28, 0x83, 0x55, 0x61, 0x49, 0x72, 0x04, 0xaa,
  38602. 0xf8, 0xe3, 0x4b, 0x20, 0xf7, 0x6a, 0x74, 0x56, 0x64, 0xf9, 0xb3, 0xc9,
  38603. 0x67, 0x5b, 0x55, 0x29, 0x9a, 0x89, 0xa5, 0x14, 0x67, 0xea, 0x6d, 0x6a,
  38604. 0xde, 0x98, 0x58, 0x73, 0x25, 0xa3, 0xdb, 0xed, 0x3d, 0x62, 0xaa, 0xe0,
  38605. 0x79, 0x7f, 0xa3, 0xd9, 0xb5, 0x4c, 0xe9, 0xa8, 0xdf, 0xfd, 0x59, 0x31,
  38606. 0x42, 0x81, 0x9e, 0xb7, 0x81, 0x3f, 0x0e, 0xfb, 0xef, 0x80, 0x71, 0x9d,
  38607. 0xb7, 0xa5, 0xfc, 0xb1, 0x80, 0xc9, 0x7e, 0x31, 0xd9, 0x47, 0xe2, 0xca,
  38608. 0x10, 0x7b, 0xd1, 0xa1, 0x1c, 0x28, 0xc7, 0x7f, 0x51, 0x26, 0xb1, 0x4e,
  38609. 0x57, 0xdd, 0x7d, 0x76, 0x5c, 0x5a, 0x85, 0xa7, 0x7b, 0x8c, 0xc5, 0x6e,
  38610. 0xac, 0x20, 0xf8, 0x49, 0x16, 0xd6, 0x64, 0xf5, 0xf4, 0x2c, 0x32, 0xa1,
  38611. 0x5d, 0xfb, 0x87, 0xb6, 0x14, 0xfe, 0x68, 0x7c, 0x4d, 0xce, 0xd7, 0x94,
  38612. 0xf9, 0x8b, 0xf0, 0x61, 0xfd, 0xe0, 0x83, 0x7f, 0x13, 0xec, 0x7a, 0xb7,
  38613. 0x41, 0x04, 0x51, 0x6e, 0x30, 0xa2, 0x01, 0xf7, 0x30, 0x12, 0xec, 0xd2,
  38614. 0x8f, 0x73, 0xe7, 0x8e, 0x12, 0xb4, 0xe5, 0xc1, 0xff, 0xdf, 0x67, 0x14,
  38615. 0xb1, 0xe9, 0xba, 0x36, 0x19, 0x18, 0xf4, 0xaa, 0xe0, 0xe4, 0x9d, 0xcd,
  38616. 0xe8, 0xe7, 0x2b, 0x33, 0xb3, 0xdc, 0xb9, 0x19, 0xd7, 0xad, 0xa4, 0x68,
  38617. 0xcd, 0x83, 0x77, 0x98, 0x36, 0x49, 0xd9, 0x32, 0x20, 0xfd, 0xfc, 0x34,
  38618. 0xe7, 0x54, 0xd9, 0xb5, 0x05, 0xab, 0x0e, 0x08, 0x0e, 0x16, 0x8a, 0x7d,
  38619. 0x91, 0x4c, 0xaa, 0x19, 0x04, 0x37, 0x35, 0xa5, 0xab, 0x6c, 0xee, 0xc4,
  38620. 0x90, 0xf0, 0x5f, 0xc7, 0xae, 0x82, 0xfd, 0x59, 0x53, 0xe5, 0x36, 0x5a,
  38621. 0x56, 0x37, 0x61, 0x69, 0xda, 0xe5, 0x8f, 0xfd, 0x2e, 0xd4, 0x9c, 0x7f,
  38622. 0xb6, 0x39, 0xa4, 0x8d, 0x0a, 0xab, 0x82, 0x0f, 0xfe, 0x84, 0x69, 0x44,
  38623. 0x8a, 0xa6, 0xd0, 0x39, 0xf9, 0x72, 0x68, 0xe7, 0x97, 0xd8, 0x6c, 0x7b,
  38624. 0xec, 0x85, 0x8c, 0x52, 0xc9, 0x97, 0xbb, 0xc4, 0x7a, 0x67, 0x22, 0x60,
  38625. 0x46, 0x9f, 0x16, 0xf1, 0x67, 0x0e, 0x1b, 0x50, 0x7c, 0xc4, 0x29, 0x15,
  38626. 0xbc, 0x55, 0x6a, 0x67, 0xf6, 0xa8, 0x85, 0x66, 0x89, 0x9f, 0xff, 0x38,
  38627. 0x28, 0xaa, 0x87, 0x91, 0xce, 0xde, 0x8d, 0x45, 0x5c, 0xa1, 0x25, 0x95,
  38628. 0xe2, 0x86, 0xdd, 0xa1, 0x87, 0x6a, 0x0a, 0xa8, 0x3e, 0x63, 0x0e, 0x21,
  38629. 0xa5, 0x6e, 0x08, 0x4d, 0x07, 0xb6, 0x26, 0xa8, 0x92, 0xdb, 0xed, 0x13,
  38630. 0x01, 0xc3, 0xba, 0xcf, 0xad, 0x01, 0xbc, 0xe5, 0xc0, 0xba, 0xbe, 0x7c,
  38631. 0x75, 0xf1, 0xb9, 0xfe, 0xd3, 0xf0, 0xa5, 0x2c, 0x8e, 0x10, 0xff, 0x99,
  38632. 0xcb, 0xe2, 0x2d, 0xdc, 0x2f, 0x76, 0x00, 0xf8, 0x51, 0x7c, 0xcc, 0x52,
  38633. 0x16, 0x0f, 0x18, 0x98, 0xea, 0x34, 0x06, 0x7f, 0xb7, 0x2e, 0xe9, 0x40,
  38634. 0xf0, 0x2d, 0x30, 0x3d, 0xc0, 0x67, 0x4c, 0xe6, 0x63, 0x40, 0x41, 0x42,
  38635. 0x96, 0xbb, 0x0b, 0xd6, 0xc9, 0x1c, 0x22, 0x7a, 0xa9, 0x4d, 0xcc, 0x5b,
  38636. 0xaa, 0x03, 0xc6, 0x3b, 0x1e, 0x2f, 0x11, 0xae, 0x34, 0x6f, 0x0c, 0xe9,
  38637. 0x16, 0x9c, 0x82, 0x3b, 0x90, 0x4c, 0x0e, 0xf0, 0xf9, 0x7f, 0x02, 0xca,
  38638. 0xb9, 0xa9, 0x49, 0x6d, 0x27, 0x73, 0xd0, 0xbf, 0x15, 0x61, 0x52, 0xbc,
  38639. 0xd6, 0x31, 0x59, 0x2b, 0x52, 0x5b, 0xaf, 0x3c, 0xc0, 0x8f, 0xdc, 0xd5,
  38640. 0x2c, 0x1d, 0xe4, 0xe9, 0x41, 0xe8, 0xd3, 0x35, 0xd6, 0xb1, 0xf3, 0x32,
  38641. 0xe0, 0x52, 0x08, 0x73, 0x99, 0xb6, 0x6b, 0xbc, 0x26, 0xfb, 0x2e, 0xa7,
  38642. 0xb7, 0xcd, 0x14, 0xf0, 0xf9, 0xe5, 0x3a, 0xd0, 0x05, 0x5b, 0x2b, 0x38,
  38643. 0xbd, 0x7c, 0xda, 0xd4, 0x15, 0x45, 0xfa, 0x3b, 0x6f, 0x94, 0x8e, 0x22,
  38644. 0xce, 0xfa, 0x53, 0xe0, 0x5f, 0xa6, 0x9d, 0x1c, 0x26, 0x91, 0x8a, 0xab,
  38645. 0x72, 0x5b, 0x18, 0x78, 0x69, 0x98, 0x3f, 0x8d, 0x33, 0x7c, 0x21, 0x93,
  38646. 0x9e, 0xf0, 0xaf, 0xb7, 0x30, 0xc8, 0xac, 0xbc, 0xdb, 0x9c, 0x29, 0x17,
  38647. 0x6b, 0x9d, 0x0f, 0x16, 0xd6, 0xc0, 0xcc, 0x3b, 0xce, 0x11, 0xe9, 0x64,
  38648. 0xc8, 0xd4, 0x4c, 0x98, 0x7c, 0x8f, 0xf1, 0x5e, 0x84, 0xe4, 0x72, 0xf9,
  38649. 0x69, 0xf5, 0x9d, 0xad, 0x95, 0x3b, 0xfb, 0x6d, 0x30, 0x7e, 0x0a, 0x47,
  38650. 0x5b, 0x26, 0xb2, 0x4e, 0xeb, 0x1a, 0xc3, 0x37, 0x16, 0x28, 0x79, 0x62,
  38651. 0xb4, 0x36, 0x85, 0x4a, 0x15, 0x5a, 0xc3, 0x6e, 0xbe, 0x7e, 0x00, 0xe9,
  38652. 0x4a, 0xa5, 0xd7, 0x90, 0xcf, 0x59, 0x63, 0x2d, 0x2b, 0xc2, 0xc6, 0x47,
  38653. 0xe6, 0x77, 0xb7, 0x6e, 0x9b, 0xc8, 0x0d, 0x18, 0x2b, 0x45, 0x2b, 0xc9,
  38654. 0x5a, 0x6e, 0xb4, 0x50, 0xa5, 0x23, 0x7d, 0x17, 0xcc, 0x49, 0xe2, 0xb3,
  38655. 0xf4, 0x6d, 0xb4, 0xb7, 0xbb, 0x9e, 0xdd, 0x20, 0x99, 0x19, 0xf5, 0x53,
  38656. 0x1f, 0xd0, 0xff, 0x67, 0xf3, 0x8e, 0x6a, 0xcd, 0x2a, 0x6e, 0x2b, 0x0a,
  38657. 0x90, 0xd7, 0xdb, 0xe1, 0xff, 0x1c, 0x40, 0xa1, 0xb0, 0x5d, 0x94, 0x4d,
  38658. 0x20, 0x14, 0x01, 0xa1, 0xa8, 0xd1, 0x15, 0xd2, 0xd9, 0x1b, 0xbf, 0xc2,
  38659. 0x8a, 0xd0, 0x02, 0xf6, 0x16, 0xa1, 0xb7, 0x40, 0xe0, 0x36, 0x88, 0xc8,
  38660. 0x17, 0x0a, 0xf0, 0xb6, 0x0d, 0x3c, 0x53, 0xb9, 0x51, 0xed, 0xef, 0x20,
  38661. 0x6f, 0xf3, 0x0c, 0xb5, 0xce, 0x0e, 0x9e, 0xfd, 0x0f, 0x5e, 0x3f, 0x8f,
  38662. 0x3c, 0xb7, 0x2a, 0xdb, 0xc6, 0xa7, 0xf2, 0x11, 0x6e, 0xdc, 0x05, 0x33,
  38663. 0xd4, 0xd8, 0xb0, 0x2d, 0x8a, 0xe5, 0x39, 0x82, 0x00, 0x49, 0x7d, 0xfd,
  38664. 0x32, 0x29, 0xbb, 0x79, 0x5d, 0xcb, 0x21, 0x7b, 0x2d, 0x36, 0x58, 0x73,
  38665. 0x52, 0x57, 0x52, 0x96, 0x4d, 0x89, 0x61, 0xf4, 0xad, 0x1f, 0x48, 0xd5,
  38666. 0x7a, 0x4a, 0xaa, 0x1c, 0xa1, 0xf4, 0xb4, 0x9c, 0x43, 0x3b, 0x95, 0x72,
  38667. 0xd0, 0x0e, 0x35, 0x82, 0x26, 0xd4, 0x2e, 0xe3, 0x83, 0x96, 0x97, 0x5a,
  38668. 0x7b, 0xfc, 0x48, 0x17, 0x3c, 0xba, 0x9e, 0x5f, 0x46, 0x1a, 0x53, 0xe3,
  38669. 0x2e, 0x78, 0x79, 0x80, 0xf6, 0x2d, 0x24, 0xcf, 0x62, 0xb6, 0x86, 0xeb,
  38670. 0xee, 0xec, 0xf2, 0x1d, 0x00, 0xc8, 0x28, 0x9d, 0x93, 0x16, 0xa7, 0xd9,
  38671. 0x11, 0x47, 0xe3, 0xc4, 0xb6, 0xc4, 0xa0, 0x99, 0x83, 0xc1, 0x17, 0xd8,
  38672. 0x8e, 0xde, 0x69, 0x1d, 0xcb, 0xdd, 0xe7, 0x86, 0x6f, 0xf2, 0x36, 0x07,
  38673. 0x23, 0x86, 0x0d, 0xe9, 0xad, 0x87, 0xae, 0x76, 0x98, 0x95, 0x51, 0xf2,
  38674. 0xb3, 0x11, 0xc5, 0x34, 0xf0, 0x0c, 0xf8, 0x29, 0x9c, 0x84, 0x4f, 0x81,
  38675. 0x49, 0x85, 0x63, 0x25, 0x16, 0xb0, 0xc3, 0xaa, 0xd7, 0x8a, 0x2e, 0x4b,
  38676. 0x97, 0x60, 0x74, 0xf8, 0xa7, 0x39, 0xec, 0x6c, 0x2c, 0x9b, 0x33, 0x3a,
  38677. 0x11, 0xbd, 0xa6, 0x90, 0x48, 0x65, 0xb1, 0xe7, 0x38, 0x53, 0x47, 0x1b,
  38678. 0x62, 0xd5, 0xb7, 0xa8, 0xd4, 0xae, 0xf5, 0x12, 0x06, 0x12, 0x54, 0xa2,
  38679. 0xce, 0xf1, 0x6b, 0x3a, 0xda, 0x63, 0x2e, 0x37, 0x2a, 0x25, 0x89, 0x30,
  38680. 0x98, 0x77, 0x1d, 0x4b, 0x5a, 0x1e, 0xb7, 0x3d, 0xed, 0x19, 0xec, 0x9f,
  38681. 0x64, 0x46, 0xa8, 0x2a, 0x79, 0xf3, 0x70, 0x39, 0x9f, 0x8c, 0xc3, 0x28,
  38682. 0xcc, 0x2a, 0xc0, 0xd0, 0xe6, 0x80, 0xf5, 0x01, 0x78, 0x72, 0x7f, 0xe7,
  38683. 0x2e, 0x7b, 0x5f, 0x05, 0xc3, 0x41, 0x33, 0x07, 0xdb, 0x9c, 0xa8, 0x96,
  38684. 0xa7, 0x21, 0x20, 0x23, 0xd0, 0x59, 0x39, 0x06, 0x19, 0xa4, 0x29, 0xe5,
  38685. 0x72, 0x39, 0x69, 0x23, 0xe3, 0xfa, 0x28, 0x63, 0xf5, 0x42, 0x3b, 0xca,
  38686. 0x88, 0x5d, 0x7e, 0x47, 0x93, 0xa8, 0x8c, 0x75, 0xf2, 0x19, 0x44, 0x43,
  38687. 0x15, 0x39, 0x03, 0x42, 0xd8, 0x1d, 0x81, 0x30, 0x8e, 0x84, 0x31, 0x24,
  38688. 0x75, 0x67, 0x4e, 0xbe, 0xfe, 0x0a, 0xd8, 0xc3, 0xe7, 0x5b, 0xe1, 0xd5,
  38689. 0x12, 0x6a, 0x69, 0x99, 0xcd, 0x35, 0xca, 0x22, 0x02, 0x65, 0xb3, 0x0f,
  38690. 0x50, 0xb6, 0xaa, 0xc6, 0x91, 0x5c, 0x4d, 0xd4, 0x07, 0x93, 0x46, 0xf0,
  38691. 0xcc, 0xe1, 0x92, 0x14, 0x91, 0x21, 0x43, 0xc4, 0xba, 0x45, 0x1c, 0x47,
  38692. 0x29, 0xdf, 0xff, 0x89, 0x60, 0xee, 0x89, 0x1e, 0xc3, 0xb4, 0xb9, 0x0b,
  38693. 0xc9, 0x7e, 0xd9, 0x15, 0xb0, 0x80, 0x91, 0xbe, 0xb9, 0x43, 0x48, 0x12,
  38694. 0x86, 0x8e, 0x79, 0x38, 0x4d, 0xce, 0x36, 0x7f, 0xc3, 0xe8, 0xb7, 0xb9,
  38695. 0x92, 0xbf, 0x27, 0x20, 0x54, 0xc8, 0x05, 0x63, 0x3b, 0xf5, 0x48, 0x1a,
  38696. 0xa9, 0x04, 0x6c, 0xb6, 0x0e, 0x11, 0xea, 0xf3, 0x59, 0xb9, 0xa6, 0xf6,
  38697. 0xf8, 0x0b, 0x15, 0xed, 0x30, 0xf9, 0xe4, 0xe5, 0x26, 0x2d, 0xbb, 0xc6,
  38698. 0x5b, 0x36, 0xbb, 0x73, 0xa6, 0x4f, 0xf5, 0x43, 0x9f, 0xd7, 0xb9, 0x0f,
  38699. 0xbc, 0x4f, 0x8d, 0xb8, 0xec, 0x1d, 0x42, 0x19, 0x56, 0x37, 0xc4, 0xcb,
  38700. 0xd0, 0x16, 0x85, 0xff, 0xd3, 0x9b, 0xef, 0xc8, 0x75, 0x37, 0xd1, 0x92,
  38701. 0xad, 0x21, 0x94, 0x1e, 0x9a, 0xf6, 0x2f, 0x6d, 0x30, 0xba, 0x37, 0xc3,
  38702. 0xdc, 0x11, 0xe0, 0x79, 0xa4, 0x92, 0x1f, 0xe4, 0xaa, 0x7a, 0x6b, 0x2a,
  38703. 0xe4, 0x04, 0xb7, 0xf9, 0x86, 0x95, 0xdb, 0xa8, 0xfc, 0x8a, 0x53, 0x21,
  38704. 0x31, 0x14, 0xf7, 0x40, 0x01, 0x78, 0x4e, 0x73, 0x18, 0xb3, 0x54, 0xd7,
  38705. 0xa6, 0x93, 0xf0, 0x70, 0x04, 0x1c, 0xe0, 0x2b, 0xef, 0xee, 0xd4, 0x64,
  38706. 0xa7, 0xd9, 0x9f, 0x81, 0x4f, 0xe5, 0x1e, 0xbe, 0x6e, 0xd2, 0xf6, 0x3a,
  38707. 0xba, 0xcf, 0x8c, 0x96, 0x2a, 0x3d, 0xf7, 0xe5, 0x5c, 0x59, 0x40, 0x9c,
  38708. 0xe3, 0xf9, 0x2b, 0x6d, 0x3d, 0xf2, 0x6f, 0x81, 0xd6, 0xab, 0x9c, 0xab,
  38709. 0xc6, 0xf7, 0x8f, 0xaa, 0xe5, 0x71, 0xe3, 0xc9, 0x8c, 0x1a, 0xeb, 0xc5,
  38710. 0x87, 0xe7, 0xb0, 0xde, 0x18, 0xba, 0xaa, 0x1e, 0xda, 0x12, 0x32, 0x16,
  38711. 0x94, 0x3a, 0x6e, 0x4f, 0x84, 0x06, 0x8e, 0x33, 0xf7, 0xfa, 0x35, 0xb8,
  38712. 0x45, 0xe4, 0x5e, 0x9e, 0x46, 0x05, 0x7a, 0xf7, 0xf4, 0x99, 0xad, 0xb9,
  38713. 0xdd, 0x55, 0xd9, 0x52, 0x3b, 0x93, 0xe3, 0x9b, 0x54, 0x1b, 0xe6, 0xa9,
  38714. 0x70, 0xd3, 0x48, 0xf9, 0x3d, 0xdb, 0x88, 0x63, 0x66, 0xa0, 0xab, 0x72,
  38715. 0x83, 0x6e, 0x8f, 0x78, 0x9d, 0x55, 0x46, 0x21, 0xca, 0x7c, 0xb7, 0x5d,
  38716. 0x16, 0xe8, 0x66, 0x3b, 0x7b, 0xaa, 0xfe, 0x9c, 0x9c, 0x33, 0xc9, 0xc2,
  38717. 0xa4, 0x3c, 0x78, 0x97, 0xf3, 0x5b, 0xc2, 0x29, 0x36, 0x98, 0x68, 0x28,
  38718. 0xfe, 0x0a, 0xae, 0x6f, 0xe5, 0xf7, 0xfb, 0x9d, 0xf8, 0x8c, 0xd9, 0xd0,
  38719. 0x4d, 0xfe, 0xc7, 0xd0, 0xb0, 0xe3, 0x9c, 0xdb, 0xac, 0x9e, 0x1b, 0x55,
  38720. 0x7e, 0x24, 0xfe, 0xc4, 0x12, 0xcb, 0xc2, 0xdd, 0x0a, 0xda, 0x31, 0x40,
  38721. 0x41, 0xb7, 0xfc, 0x3f, 0x6d, 0xe2, 0xd3, 0x8a, 0x0f, 0x21, 0x33, 0x3a,
  38722. 0xbc, 0xa7, 0x62, 0x18, 0xb3, 0xaf, 0x48, 0xc6, 0xe2, 0xa3, 0xdd, 0x1d,
  38723. 0x20, 0x62, 0xe4, 0x4b, 0x81, 0x6b, 0x3a, 0xc5, 0xb1, 0x07, 0xe1, 0xf1,
  38724. 0xe1, 0xba, 0xf6, 0x01, 0xc6, 0xf2, 0xea, 0xc0, 0x97, 0x73, 0x79, 0x19,
  38725. 0x06, 0xaa, 0x62, 0x42, 0xcb, 0x21, 0x5f, 0x08, 0x97, 0x7d, 0x72, 0xb5,
  38726. 0x39, 0x4d, 0x99, 0xe3, 0xa2, 0x3f, 0xb9, 0xb4, 0xed, 0xf4, 0x61, 0x35,
  38727. 0xe1, 0x50, 0xfb, 0x56, 0x7c, 0x35, 0xfd, 0x44, 0x8a, 0x57, 0x22, 0xed,
  38728. 0x30, 0x33, 0xc3, 0x0b, 0xf1, 0x88, 0xe4, 0x44, 0x46, 0xf5, 0x73, 0x6d,
  38729. 0x9b, 0x98, 0x88, 0x92, 0xf5, 0x34, 0x85, 0x18, 0x66, 0xef, 0x70, 0xbe,
  38730. 0x7b, 0xc1, 0x0f, 0x1c, 0x78, 0x2d, 0x42, 0x13, 0x2d, 0x2f, 0x4d, 0x40,
  38731. 0x8e, 0xe2, 0x6f, 0xe0, 0x04, 0xdb, 0x58, 0xbc, 0x65, 0x80, 0xba, 0xfc,
  38732. 0x89, 0xee, 0xf3, 0x78, 0xb2, 0xd9, 0x78, 0x93, 0x6d, 0xbf, 0xd4, 0x74,
  38733. 0x24, 0xf4, 0x5c, 0x37, 0x89, 0x0c, 0x14, 0xd5, 0xbd, 0xc5, 0xfc, 0x37,
  38734. 0xe8, 0x8b, 0xe0, 0xc5, 0x89, 0xc9, 0x70, 0xb3, 0x76, 0x46, 0xce, 0x0d,
  38735. 0x7c, 0x3d, 0xa4, 0x5d, 0x02, 0x95, 0x03, 0xba, 0x24, 0xaa, 0xf7, 0xd0,
  38736. 0x75, 0x35, 0x78, 0x27, 0x9c, 0x6d, 0x2a, 0xef, 0xaa, 0xac, 0x85, 0xef,
  38737. 0x8d, 0xfc, 0xc0, 0xfc, 0x72, 0x02, 0xf4, 0xa3, 0xd3, 0x87, 0xfc, 0x4d,
  38738. 0xce, 0x3d, 0xcb, 0xc2, 0x74, 0x5b, 0xb0, 0x83, 0xc5, 0x72, 0x72, 0xd6,
  38739. 0xa1, 0x67, 0x4d, 0xa1, 0xd6, 0xaa, 0xe7, 0x9b, 0xe7, 0xc0, 0xfd, 0x86,
  38740. 0x91, 0x08, 0xfa, 0x48, 0x2f, 0x50, 0xce, 0x17, 0xea, 0x1c, 0xe3, 0x90,
  38741. 0x35, 0xe6, 0x6c, 0xc9, 0x66, 0x7d, 0x51, 0x32, 0x20, 0x0c, 0x2d, 0x4b,
  38742. 0xa1, 0xbf, 0x78, 0x87, 0xe1, 0x5a, 0x28, 0x0e, 0x9a, 0x85, 0xf6, 0x7e,
  38743. 0x39, 0x60, 0xbc, 0x64, 0x42, 0x5d, 0xf0, 0x0a, 0xd7, 0x3e, 0xbb, 0xa0,
  38744. 0x6d, 0x7c, 0xfa, 0x75, 0xee, 0x34, 0x39, 0x23, 0x0e, 0xbd, 0x50, 0x19,
  38745. 0x7a, 0x2a, 0xb7, 0x17, 0x3a, 0x8b, 0xb7, 0xb6, 0xf4, 0xd8, 0x47, 0x71,
  38746. 0x6b, 0x21, 0x1b, 0x56, 0xcc, 0xfb, 0x7b, 0x81, 0x99, 0x46, 0x88, 0x23,
  38747. 0x40, 0x49, 0x66, 0x8b, 0xac, 0x84, 0x16, 0x8a, 0x86, 0xae, 0x38, 0xc4,
  38748. 0x5b, 0x1f, 0x2b, 0xfa, 0xf2, 0x8b, 0x81, 0xc1, 0x22, 0x61, 0x61, 0x6c,
  38749. 0x43, 0x16, 0x8c, 0x1d, 0x37, 0xb2, 0xaf, 0x3c, 0x3a, 0x90, 0x33, 0xed,
  38750. 0xf5, 0x08, 0x78, 0xfd, 0x5a, 0xde, 0xd3, 0x38, 0x6d, 0xd7, 0x1c, 0x23,
  38751. 0xeb, 0xb4, 0x9b, 0x8e, 0xc2, 0x48, 0x47, 0x8e, 0x84, 0xbb, 0xc4, 0xd0,
  38752. 0xcc, 0xf9, 0x55, 0x5a, 0x57, 0xb9, 0x99, 0x52, 0x82, 0x21, 0x3b, 0x83,
  38753. 0xda, 0x8f, 0xa3, 0x88, 0x9c, 0x57, 0xe0, 0x4b, 0xc1, 0xce, 0xbe, 0xd3,
  38754. 0xea, 0xdd, 0xf2, 0x07, 0xc1, 0x73, 0x6f, 0xc0, 0x5e, 0x8e, 0x85, 0x72,
  38755. 0xab, 0x2f, 0xa9, 0xac, 0x39, 0xee, 0x05, 0x34, 0x13, 0x16, 0x1b, 0x1c,
  38756. 0x21, 0x24, 0x41, 0x49, 0x78, 0x87, 0x8b, 0x97, 0x9c, 0x9f, 0xa3, 0xa8,
  38757. 0xb9, 0xbc, 0xc6, 0xcc, 0xf2, 0xfd, 0x18, 0x2a, 0x46, 0x58, 0x5a, 0x88,
  38758. 0xa2, 0xb5, 0xcc, 0xd2, 0xda, 0xe1, 0xe3, 0x0d, 0x20, 0x23, 0x2b, 0x2f,
  38759. 0x47, 0x57, 0x5e, 0x64, 0x87, 0x97, 0x9c, 0xa7, 0xaa, 0xbc, 0xc1, 0xe4,
  38760. 0xe5, 0xea, 0x0b, 0x16, 0x3b, 0x3c, 0x3e, 0x45, 0x58, 0x63, 0x6a, 0x6f,
  38761. 0x7c, 0x8c, 0x8d, 0x92, 0x99, 0x9c, 0xad, 0xb5, 0xb7, 0xce, 0x00, 0x00,
  38762. 0x00, 0x00, 0x00, 0x00, 0x16, 0x23, 0x36, 0x4a
  38763. };
  38764. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38765. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_sig[] = {
  38766. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  38767. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  38768. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  38769. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  38770. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  38771. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  38772. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  38773. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  38774. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  38775. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  38776. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  38777. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  38778. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  38779. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  38780. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  38781. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  38782. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  38783. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  38784. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  38785. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  38786. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  38787. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  38788. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  38789. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  38790. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  38791. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  38792. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  38793. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  38794. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  38795. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  38796. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  38797. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  38798. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  38799. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  38800. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  38801. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  38802. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  38803. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  38804. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  38805. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  38806. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  38807. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  38808. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  38809. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  38810. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  38811. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  38812. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  38813. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  38814. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  38815. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  38816. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  38817. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  38818. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  38819. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  38820. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  38821. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  38822. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  38823. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  38824. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  38825. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  38826. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  38827. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  38828. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  38829. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  38830. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  38831. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  38832. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  38833. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  38834. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  38835. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  38836. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  38837. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  38838. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  38839. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  38840. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  38841. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  38842. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  38843. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  38844. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  38845. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  38846. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  38847. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  38848. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  38849. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  38850. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  38851. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  38852. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  38853. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  38854. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  38855. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  38856. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  38857. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  38858. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  38859. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  38860. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  38861. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  38862. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  38863. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  38864. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  38865. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  38866. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  38867. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  38868. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  38869. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  38870. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  38871. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  38872. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  38873. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  38874. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  38875. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  38876. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  38877. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  38878. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  38879. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  38880. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  38881. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  38882. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  38883. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  38884. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  38885. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  38886. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  38887. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  38888. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  38889. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  38890. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  38891. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  38892. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  38893. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  38894. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  38895. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  38896. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  38897. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  38898. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  38899. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  38900. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  38901. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  38902. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  38903. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  38904. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  38905. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  38906. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  38907. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  38908. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  38909. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  38910. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  38911. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  38912. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  38913. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  38914. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  38915. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  38916. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  38917. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  38918. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  38919. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  38920. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  38921. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  38922. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  38923. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  38924. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  38925. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  38926. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  38927. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  38928. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  38929. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  38930. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  38931. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  38932. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  38933. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  38934. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  38935. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  38936. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  38937. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  38938. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  38939. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  38940. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  38941. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  38942. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  38943. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  38944. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  38945. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  38946. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  38947. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  38948. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  38949. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  38950. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  38951. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  38952. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  38953. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  38954. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  38955. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  38956. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  38957. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  38958. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  38959. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  38960. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  38961. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  38962. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  38963. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  38964. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  38965. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  38966. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  38967. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  38968. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  38969. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  38970. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  38971. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  38972. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  38973. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  38974. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  38975. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  38976. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  38977. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  38978. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  38979. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  38980. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  38981. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  38982. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  38983. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  38984. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  38985. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  38986. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  38987. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  38988. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  38989. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  38990. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  38991. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  38992. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  38993. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  38994. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  38995. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  38996. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  38997. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  38998. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  38999. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  39000. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  39001. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  39002. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  39003. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  39004. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  39005. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  39006. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  39007. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46
  39008. };
  39009. #endif
  39010. wc_test_ret_t ret;
  39011. ret = dilithium_param_vfy_test(WC_ML_DSA_44, ml_dsa_44_pub_key,
  39012. (word32)sizeof(ml_dsa_44_pub_key), ml_dsa_44_sig,
  39013. (word32)sizeof(ml_dsa_44_sig));
  39014. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39015. if (ret == 0) {
  39016. ret = dilithium_param_vfy_test(WC_ML_DSA_44_DRAFT,
  39017. ml_dsa_44_draft_pub_key, (word32)sizeof(ml_dsa_44_draft_pub_key),
  39018. ml_dsa_44_draft_sig, (word32)sizeof(ml_dsa_44_draft_sig));
  39019. }
  39020. #endif
  39021. return ret;
  39022. }
  39023. #endif
  39024. #ifndef WOLFSSL_NO_ML_DSA_65
  39025. static wc_test_ret_t dilithium_param_65_vfy_test(void)
  39026. {
  39027. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_pub_key[] = {
  39028. 0x2c, 0x32, 0xfa, 0x59, 0x71, 0x16, 0x4a, 0x0e, 0x45, 0x0f, 0x21, 0xfd,
  39029. 0x65, 0xee, 0x50, 0xb0, 0xbf, 0xea, 0x8e, 0x4e, 0xa2, 0x55, 0x71, 0xa6,
  39030. 0x65, 0x48, 0x56, 0x20, 0x8a, 0x48, 0x9d, 0xd7, 0xc9, 0x2c, 0x80, 0x62,
  39031. 0x88, 0x68, 0x4d, 0x5f, 0xbe, 0x5f, 0xe5, 0xf5, 0xa4, 0x75, 0xb6, 0x88,
  39032. 0x26, 0xae, 0x7d, 0x11, 0x43, 0x89, 0xcd, 0xe9, 0x67, 0x0c, 0x91, 0x0b,
  39033. 0xd1, 0xd8, 0x8b, 0x7b, 0x73, 0x75, 0x94, 0xc1, 0xc9, 0x61, 0xc7, 0x35,
  39034. 0x21, 0x99, 0x2e, 0xab, 0xe0, 0xdf, 0x4d, 0xac, 0x0d, 0xd0, 0xa2, 0x61,
  39035. 0x5f, 0x04, 0x08, 0x83, 0x66, 0x5c, 0x67, 0x47, 0x0c, 0xab, 0x2c, 0xb7,
  39036. 0x6d, 0x0e, 0x32, 0x4c, 0x8c, 0x25, 0x80, 0xf5, 0xe5, 0x7e, 0x3b, 0xa1,
  39037. 0xc6, 0xc5, 0x87, 0xd8, 0x68, 0xb2, 0xd5, 0x67, 0xf9, 0x5a, 0x8b, 0x88,
  39038. 0xf8, 0xcd, 0x0c, 0xda, 0x4f, 0xfc, 0xd2, 0xaf, 0xb2, 0xa2, 0x38, 0x21,
  39039. 0xf9, 0xd8, 0xf1, 0x1c, 0x8d, 0xb4, 0xe8, 0xfb, 0x76, 0x36, 0x87, 0xf4,
  39040. 0x7d, 0x03, 0xc4, 0x06, 0xab, 0x87, 0xac, 0x52, 0xe8, 0xd5, 0xf7, 0x63,
  39041. 0xf0, 0xa8, 0x0b, 0x95, 0xbd, 0x07, 0xf1, 0x1d, 0x33, 0x7b, 0x8a, 0x2c,
  39042. 0xef, 0x85, 0xbe, 0xf8, 0xc1, 0x4b, 0xa2, 0xb0, 0xe0, 0x7a, 0x85, 0xfa,
  39043. 0x52, 0x36, 0x05, 0xa7, 0x65, 0x4a, 0x0c, 0x21, 0x5c, 0xc0, 0x4f, 0x18,
  39044. 0xb8, 0x66, 0x02, 0xe6, 0xd0, 0x45, 0x60, 0x56, 0xfc, 0x40, 0x94, 0xb5,
  39045. 0xa5, 0x2b, 0xc7, 0x57, 0xc3, 0xc5, 0x30, 0x72, 0x1c, 0x4c, 0x2a, 0xd5,
  39046. 0x75, 0xae, 0x43, 0x9f, 0x01, 0x71, 0xac, 0x5c, 0xdf, 0x9c, 0x0a, 0x3c,
  39047. 0xb5, 0x89, 0x07, 0x9b, 0x28, 0x25, 0x31, 0x31, 0xc5, 0xb7, 0x24, 0x53,
  39048. 0x2c, 0x3c, 0x2a, 0x96, 0xe5, 0x0d, 0xa2, 0x97, 0xa7, 0x08, 0x9d, 0x31,
  39049. 0xc0, 0xcd, 0x53, 0xd5, 0xa8, 0x58, 0xa6, 0xac, 0x43, 0x2d, 0xac, 0x39,
  39050. 0x01, 0x2c, 0x60, 0xf6, 0x82, 0x86, 0xd0, 0xaf, 0xad, 0x61, 0x3f, 0x82,
  39051. 0x80, 0xa1, 0xe1, 0x12, 0x83, 0x6e, 0x1d, 0x5e, 0xfe, 0xc6, 0x1e, 0x2a,
  39052. 0x7a, 0x44, 0xcd, 0xc2, 0x0a, 0xf5, 0xc8, 0x72, 0x3e, 0x29, 0xc7, 0x0a,
  39053. 0xd1, 0x4c, 0x17, 0xdd, 0x1f, 0xb6, 0x95, 0x34, 0xc2, 0x6c, 0xdc, 0x63,
  39054. 0xd1, 0x7e, 0xb0, 0x52, 0x06, 0x18, 0x6c, 0xb1, 0x99, 0x6a, 0xbe, 0x42,
  39055. 0xa9, 0xc0, 0x22, 0xcc, 0x09, 0x11, 0x84, 0x1f, 0x16, 0x9a, 0x0e, 0xdd,
  39056. 0x18, 0x7a, 0x39, 0x34, 0xb0, 0x49, 0x44, 0xcb, 0x88, 0x1f, 0x91, 0x93,
  39057. 0x49, 0x3f, 0xcc, 0x62, 0x56, 0x33, 0x15, 0xcb, 0x02, 0x9b, 0x33, 0xe8,
  39058. 0xd7, 0xab, 0x51, 0xc0, 0x91, 0xe0, 0x9c, 0xd2, 0xf9, 0x52, 0x05, 0x0c,
  39059. 0xbf, 0xf1, 0x97, 0x42, 0xfe, 0xd0, 0x32, 0x27, 0x34, 0xf8, 0x82, 0x2d,
  39060. 0x65, 0x3a, 0x36, 0xce, 0xd1, 0x07, 0x82, 0x3a, 0x6a, 0xaa, 0x56, 0xf1,
  39061. 0x9b, 0x98, 0xca, 0x8e, 0x55, 0xff, 0xa0, 0x74, 0xd6, 0x6a, 0x42, 0xaa,
  39062. 0x0a, 0xd4, 0x59, 0x74, 0xfb, 0xd4, 0xdb, 0x14, 0x10, 0xee, 0xca, 0x78,
  39063. 0x83, 0x83, 0x95, 0x9b, 0x77, 0xf1, 0x9a, 0x48, 0xe0, 0x8f, 0xa4, 0x5a,
  39064. 0x4d, 0xa9, 0x3f, 0x32, 0x78, 0x4a, 0x25, 0x96, 0x9c, 0x20, 0x0a, 0xcc,
  39065. 0x5b, 0xd8, 0xca, 0x19, 0x47, 0x77, 0xb8, 0x7c, 0x51, 0x3e, 0xd6, 0x30,
  39066. 0xdb, 0x45, 0xb0, 0xe6, 0x9d, 0x6f, 0xc5, 0x0a, 0x5d, 0x5f, 0x55, 0xcd,
  39067. 0x0f, 0x20, 0x22, 0x7e, 0x09, 0x99, 0xac, 0xb8, 0x9c, 0x9d, 0xf7, 0x3e,
  39068. 0x7e, 0x07, 0xd7, 0xbc, 0x21, 0x76, 0x8c, 0x27, 0x81, 0x94, 0xab, 0x57,
  39069. 0x4a, 0xe2, 0x91, 0x1c, 0xa4, 0x77, 0x4a, 0xd2, 0x96, 0x52, 0x9d, 0x33,
  39070. 0xb5, 0x58, 0x70, 0xd7, 0xff, 0x22, 0xe8, 0x14, 0xea, 0xd0, 0x8c, 0xd4,
  39071. 0x06, 0x08, 0xd8, 0x73, 0x66, 0x4b, 0x93, 0x41, 0xc9, 0x73, 0x5b, 0x07,
  39072. 0x5f, 0x31, 0xc5, 0x25, 0x98, 0x7b, 0x7b, 0xa5, 0x26, 0x83, 0x94, 0x22,
  39073. 0x42, 0x1c, 0x51, 0xe6, 0x80, 0x48, 0xca, 0xd4, 0x53, 0x40, 0x3a, 0xee,
  39074. 0x2c, 0x29, 0x07, 0xed, 0xdf, 0x97, 0x44, 0x19, 0xe5, 0xe5, 0x35, 0x66,
  39075. 0x1f, 0xbd, 0x29, 0x77, 0x0c, 0x15, 0x6c, 0x95, 0x08, 0x81, 0xe0, 0x76,
  39076. 0x86, 0x5e, 0x6d, 0x77, 0x78, 0x76, 0x07, 0xdd, 0x21, 0x97, 0x59, 0xdb,
  39077. 0xd4, 0xbd, 0xb6, 0x4c, 0x3f, 0x07, 0x93, 0xb6, 0x4a, 0xce, 0xf7, 0x08,
  39078. 0x86, 0xfd, 0x9c, 0x03, 0x08, 0x94, 0x00, 0xea, 0x4b, 0xd6, 0x1e, 0x17,
  39079. 0xfb, 0xb5, 0xba, 0xde, 0x25, 0x95, 0xe7, 0xf8, 0x97, 0x9e, 0x99, 0xae,
  39080. 0x5d, 0xdd, 0xf6, 0x32, 0x1a, 0xf2, 0x4f, 0xcf, 0x0c, 0x17, 0x55, 0xb8,
  39081. 0xfb, 0xae, 0xc8, 0x46, 0xb0, 0x3e, 0x86, 0x2b, 0x5e, 0xef, 0x36, 0xca,
  39082. 0x24, 0xed, 0x32, 0x5b, 0xc8, 0xfb, 0x88, 0x35, 0x6a, 0x26, 0xfe, 0x06,
  39083. 0x54, 0x0c, 0x3e, 0x2c, 0x71, 0xdf, 0x98, 0xf0, 0xbb, 0xb2, 0xe0, 0x9d,
  39084. 0xf7, 0xeb, 0xce, 0x07, 0xfa, 0xc4, 0xab, 0x88, 0xc3, 0x14, 0x33, 0x60,
  39085. 0x48, 0xcf, 0x39, 0x26, 0x90, 0xac, 0xfa, 0x39, 0x6f, 0x2d, 0x9d, 0x6d,
  39086. 0x15, 0x7f, 0x84, 0x6b, 0x0a, 0x1c, 0xf4, 0x6c, 0x78, 0x62, 0x52, 0x93,
  39087. 0x2c, 0x7e, 0x9f, 0x4a, 0x51, 0x7a, 0x2e, 0xad, 0xea, 0xe4, 0xe5, 0x9c,
  39088. 0x15, 0x15, 0x28, 0x4d, 0x3e, 0x5e, 0xb4, 0x3b, 0xff, 0x81, 0xe0, 0x56,
  39089. 0x44, 0x33, 0x33, 0xd9, 0x4b, 0xb2, 0x23, 0x60, 0xed, 0x0d, 0xa5, 0x4e,
  39090. 0x9f, 0x7d, 0xbc, 0x6e, 0x3a, 0xf9, 0x7e, 0x16, 0x47, 0x66, 0xb1, 0x6c,
  39091. 0xc7, 0x26, 0x62, 0x9b, 0x3c, 0x53, 0xb3, 0xa1, 0x16, 0x62, 0x31, 0x64,
  39092. 0xd2, 0xbb, 0x28, 0x5c, 0xe8, 0x21, 0xc3, 0xfc, 0xc3, 0x6d, 0xa7, 0x35,
  39093. 0x4d, 0x57, 0xe0, 0xbd, 0x54, 0x1a, 0x84, 0xf7, 0x9c, 0x8a, 0x54, 0x3d,
  39094. 0x59, 0xb3, 0xa2, 0x46, 0x3b, 0x16, 0x48, 0x3b, 0x3a, 0x3c, 0x5e, 0x88,
  39095. 0xc3, 0x60, 0x63, 0x7e, 0xca, 0x68, 0xb7, 0x2f, 0x2b, 0xb5, 0x62, 0x2e,
  39096. 0x51, 0x89, 0xbe, 0x78, 0xf7, 0xfa, 0x19, 0xcc, 0xca, 0x87, 0x9a, 0xf5,
  39097. 0xef, 0x0d, 0x21, 0x08, 0x3b, 0xd6, 0x9a, 0x94, 0xc5, 0xd1, 0x1b, 0xa9,
  39098. 0x7c, 0xc8, 0x9f, 0x9a, 0xb0, 0xb8, 0xf7, 0x02, 0x12, 0x31, 0x70, 0x52,
  39099. 0x52, 0xda, 0xb5, 0x9a, 0x08, 0x20, 0xc3, 0xc4, 0x0c, 0x6a, 0x34, 0x58,
  39100. 0x75, 0x9b, 0xdc, 0x1a, 0x6a, 0x37, 0x42, 0x9f, 0x16, 0x70, 0xbb, 0x39,
  39101. 0x86, 0xbd, 0x09, 0x9c, 0x04, 0x44, 0xbe, 0x1a, 0xe5, 0xe9, 0x50, 0x9b,
  39102. 0x14, 0x50, 0x4f, 0x00, 0xba, 0xb0, 0xf6, 0x36, 0x4d, 0x69, 0x16, 0x11,
  39103. 0x40, 0x5a, 0x4e, 0x8b, 0x39, 0xb4, 0xf1, 0xb2, 0x11, 0x36, 0x2f, 0x02,
  39104. 0x15, 0xca, 0x78, 0xde, 0x75, 0x07, 0x64, 0x72, 0xfd, 0xd4, 0x48, 0xdd,
  39105. 0xfb, 0xf5, 0x8a, 0x3d, 0xa8, 0x8e, 0x14, 0xd1, 0x69, 0xe3, 0x21, 0x50,
  39106. 0x39, 0xfd, 0xd0, 0x3b, 0xa0, 0x22, 0x61, 0x5c, 0x7e, 0x88, 0x91, 0xe1,
  39107. 0xf0, 0xf6, 0x16, 0x23, 0xdb, 0xdb, 0x50, 0x0e, 0x39, 0xcc, 0x86, 0xf1,
  39108. 0xab, 0x89, 0x60, 0xb0, 0xac, 0x28, 0xc6, 0x57, 0xe4, 0xee, 0xa9, 0x1b,
  39109. 0xae, 0x78, 0xc5, 0x67, 0x1a, 0xeb, 0xb3, 0x43, 0xbc, 0xea, 0x11, 0x0c,
  39110. 0x64, 0xf6, 0xd2, 0x52, 0xa0, 0x7e, 0xcd, 0x6d, 0x84, 0x8c, 0xf8, 0x80,
  39111. 0xb7, 0xdb, 0x26, 0x91, 0x4a, 0xa0, 0x61, 0x69, 0x2f, 0x6f, 0x1c, 0x9d,
  39112. 0x2a, 0x20, 0x44, 0xdc, 0x58, 0xaf, 0x7d, 0xfe, 0x4d, 0xa2, 0x10, 0x21,
  39113. 0x88, 0xef, 0x42, 0x2e, 0x8e, 0xfb, 0x63, 0xbc, 0xc8, 0x26, 0xe7, 0x80,
  39114. 0xa5, 0xbf, 0xe0, 0x7a, 0xcb, 0xf3, 0x31, 0x1c, 0xd9, 0xa3, 0x12, 0x00,
  39115. 0x2f, 0x20, 0xc6, 0xc1, 0x15, 0xfd, 0x5b, 0x0d, 0x8a, 0x4d, 0xfb, 0x84,
  39116. 0x4d, 0xb4, 0x64, 0xeb, 0x12, 0xf3, 0x78, 0x6b, 0x4d, 0xc6, 0x98, 0x46,
  39117. 0x4c, 0xb3, 0xb4, 0x59, 0xdc, 0xb7, 0xdc, 0xbb, 0x56, 0x0f, 0x09, 0x14,
  39118. 0x28, 0x43, 0x9f, 0xb8, 0x75, 0xed, 0xcb, 0x97, 0x25, 0xaf, 0xa5, 0xeb,
  39119. 0x46, 0x14, 0xa6, 0x38, 0x68, 0x06, 0xe0, 0x6e, 0x55, 0x68, 0x6b, 0xf3,
  39120. 0xd8, 0x6d, 0x59, 0x65, 0x65, 0xff, 0x48, 0xfd, 0xdb, 0x3d, 0xe2, 0x21,
  39121. 0xb4, 0x7b, 0x78, 0x6a, 0x2e, 0x28, 0xb8, 0x21, 0xc4, 0x72, 0xf4, 0xef,
  39122. 0xfb, 0x74, 0x43, 0x29, 0xf2, 0x30, 0xc9, 0xca, 0x78, 0x93, 0x72, 0xfd,
  39123. 0x84, 0xa4, 0x95, 0xe0, 0xcd, 0xb1, 0x48, 0x29, 0xe7, 0xd1, 0x27, 0xf7,
  39124. 0xdc, 0x31, 0x6e, 0x00, 0x04, 0xd7, 0x7c, 0xfd, 0x2d, 0x25, 0xe9, 0xdb,
  39125. 0xc2, 0xb8, 0x14, 0x26, 0xed, 0x63, 0xb1, 0x50, 0x0a, 0x3c, 0xb2, 0x79,
  39126. 0x98, 0x79, 0x81, 0x2d, 0xdb, 0x60, 0x97, 0x99, 0xc0, 0x0a, 0x89, 0x9f,
  39127. 0x90, 0x19, 0x0b, 0xb3, 0x97, 0xd2, 0xf7, 0x50, 0xa5, 0x1d, 0x7d, 0x71,
  39128. 0x75, 0xe6, 0x58, 0x62, 0x53, 0x95, 0x40, 0x9e, 0xc7, 0xd3, 0x72, 0xa1,
  39129. 0xae, 0x07, 0xb3, 0x8a, 0x56, 0x61, 0x99, 0x81, 0x3e, 0xe4, 0x5e, 0x78,
  39130. 0x57, 0xd1, 0x8a, 0xc4, 0x04, 0x38, 0x13, 0xa0, 0x5d, 0x68, 0x6d, 0x22,
  39131. 0xae, 0xda, 0xfc, 0x67, 0xbb, 0xfb, 0x8e, 0x1a, 0xdc, 0x24, 0xf7, 0xc8,
  39132. 0xf9, 0x92, 0x6f, 0x4e, 0xb5, 0xe7, 0x6d, 0x13, 0x88, 0x05, 0x5c, 0xbb,
  39133. 0xe0, 0x24, 0x2a, 0x96, 0xc6, 0x70, 0x52, 0x14, 0xd0, 0xd9, 0xd8, 0xb2,
  39134. 0x5b, 0xdc, 0x85, 0xcf, 0x62, 0xb4, 0xcf, 0x77, 0xf1, 0xe5, 0x51, 0xeb,
  39135. 0xef, 0xe9, 0x3e, 0xf0, 0x16, 0xd2, 0xcc, 0x38, 0x0a, 0x47, 0x91, 0xc0,
  39136. 0xe0, 0x14, 0x1a, 0xf9, 0x74, 0xd1, 0x32, 0x8b, 0x02, 0x36, 0x05, 0x55,
  39137. 0x62, 0xa7, 0xae, 0x77, 0xb0, 0x01, 0x3d, 0x2c, 0x91, 0xbe, 0xfa, 0xdd,
  39138. 0x9c, 0x17, 0x42, 0xc1, 0x01, 0x4d, 0xd8, 0x27, 0x3c, 0x10, 0x82, 0x66,
  39139. 0x11, 0x91, 0x8b, 0xc8, 0x52, 0xd5, 0xc1, 0x1d, 0xee, 0xb2, 0x90, 0x17,
  39140. 0xed, 0xf3, 0xad, 0xa5, 0xd5, 0xeb, 0xf2, 0x9b, 0x78, 0xbf, 0x2d, 0x5a,
  39141. 0xad, 0xe5, 0x53, 0xe6, 0xc1, 0x3b, 0xd8, 0xf3, 0x6b, 0xc5, 0x4c, 0x87,
  39142. 0x0a, 0xe3, 0xc8, 0xc7, 0xe5, 0x42, 0x2c, 0xe2, 0x13, 0x1a, 0xe7, 0x27,
  39143. 0x20, 0x3e, 0x95, 0x13, 0x1e, 0xbb, 0x03, 0xae, 0xc0, 0x84, 0x14, 0x6d,
  39144. 0x7b, 0xf7, 0x98, 0x08, 0x18, 0x12, 0xb4, 0x4f, 0x99, 0x4a, 0xcf, 0xd0,
  39145. 0x4a, 0x5d, 0x21, 0x16, 0xf6, 0xdf, 0x10, 0xc7, 0xbe, 0xe6, 0x79, 0x3b,
  39146. 0x35, 0x2a, 0xa6, 0xd6, 0x19, 0x9c, 0xde, 0xbd, 0xaf, 0x72, 0xd2, 0x25,
  39147. 0xe0, 0xa4, 0xde, 0x99, 0x44, 0x18, 0x66, 0x41, 0xc7, 0x56, 0xf7, 0xdc,
  39148. 0x32, 0x56, 0x57, 0x39, 0x18, 0x31, 0xc8, 0x75, 0x01, 0xc3, 0xf3, 0x46,
  39149. 0xcf, 0xbf, 0xc6, 0x10, 0xb5, 0x1c, 0x38, 0xf9, 0xa4, 0xa5, 0x44, 0xa1,
  39150. 0x0b, 0x25, 0x48, 0x9c, 0xd3, 0x1c, 0x55, 0x54, 0x15, 0x9f, 0xe3, 0x74,
  39151. 0x5b, 0xb1, 0x92, 0xb6, 0x52, 0x61, 0xba, 0x2f, 0x53, 0x91, 0x17, 0x44,
  39152. 0x94, 0x00, 0xe4, 0x43, 0xa0, 0xe7, 0x0d, 0xaa, 0x8a, 0x5b, 0x81, 0x43,
  39153. 0xad, 0xfb, 0x50, 0xfe, 0xcf, 0x85, 0x2d, 0xfa, 0xc8, 0x1d, 0xad, 0xc8,
  39154. 0x7a, 0x7c, 0x5e, 0xf3, 0x90, 0x35, 0x5e, 0x67, 0xce, 0x57, 0x4d, 0xa0,
  39155. 0x22, 0x9e, 0x07, 0x4a, 0xf5, 0x9e, 0x5f, 0x91, 0x45, 0xd8, 0x62, 0xe0,
  39156. 0xf3, 0x87, 0x3b, 0xb7, 0x89, 0x2f, 0xdf, 0x8b, 0x82, 0xb1, 0x86, 0xc3,
  39157. 0xa4, 0xa3, 0x68, 0xc7, 0x73, 0x9e, 0x68, 0x8d, 0x24, 0x6a, 0x29, 0x94,
  39158. 0x58, 0x57, 0x4b, 0x81, 0x00, 0xe2, 0x2b, 0x94, 0x0a, 0xf5, 0x96, 0xa3,
  39159. 0x23, 0x9a, 0x7b, 0xd0, 0x2d, 0xcb, 0x6a, 0x8e, 0xae, 0x1b, 0x1c, 0x34,
  39160. 0xed, 0x30, 0x4e, 0xca, 0x29, 0x21, 0xfc, 0x3d, 0x70, 0x11, 0xc1, 0x5f,
  39161. 0x3e, 0xc2, 0x9e, 0x88, 0x71, 0x29, 0xa3, 0x8f, 0x92, 0xf5, 0x46, 0x77,
  39162. 0xd5, 0x47, 0x2d, 0x2b, 0x66, 0x1c, 0x07, 0xf0, 0xfc, 0x7b, 0xa0, 0x13,
  39163. 0x00, 0xae, 0xa5, 0x61, 0x92, 0x36, 0xeb, 0x7e, 0x43, 0x91, 0x20, 0x72,
  39164. 0xe5, 0xba, 0x7f, 0x79, 0x23, 0x12, 0x3e, 0xb2, 0x4b, 0x13, 0xa1, 0x8c,
  39165. 0x84, 0x72, 0x3b, 0x45, 0x62, 0xcf, 0x2e, 0x78, 0xc4, 0x9c, 0x22, 0x09,
  39166. 0xfa, 0x59, 0x9d, 0xdf, 0x13, 0x54, 0x66, 0xe2, 0x6f, 0xfa, 0xb5, 0x2a,
  39167. 0x27, 0x3e, 0x17, 0x82, 0xf3, 0x2a, 0x4d, 0x36, 0xd3, 0xf0, 0x8d, 0x43,
  39168. 0x40, 0x2c, 0x84, 0x68, 0xbe, 0x40, 0x50, 0x7d, 0xa3, 0x27, 0x5e, 0xde,
  39169. 0x4d, 0x04, 0x6f, 0xe8, 0x96, 0x9c, 0x7a, 0x1d, 0xb8, 0x2b, 0x8a, 0xb1,
  39170. 0x6e, 0xe2, 0x36, 0x07, 0x22, 0x50, 0xd9, 0x71, 0x93, 0x48, 0xb5, 0x51,
  39171. 0xce, 0x2a, 0x64, 0x6b, 0x11, 0xa6, 0xb9, 0x40, 0x2d, 0x6c, 0xd2, 0x76,
  39172. 0x52, 0xc6, 0xe3, 0xa6, 0x6b, 0xd2, 0x3f, 0x39, 0xd2, 0x13, 0x28, 0xa4,
  39173. 0xa9, 0x58, 0x99, 0xe8, 0x3d, 0x08, 0xfa, 0x3c, 0x34, 0x39, 0x4d, 0x7d,
  39174. 0x5e, 0x10, 0x72, 0x51, 0x96, 0x1d, 0x4b, 0xd9, 0x3e, 0xc9, 0x22, 0x4c,
  39175. 0x72, 0x63, 0xf8, 0x87, 0x4b, 0xe7, 0x41, 0xac, 0xcd, 0xd6, 0x34, 0xa2,
  39176. 0xe1, 0xe8, 0x66, 0x81, 0x04, 0x7d, 0x70, 0x95, 0xba, 0x37, 0x86, 0x9e,
  39177. 0x1f, 0x9a, 0x1b, 0xe4, 0x35, 0xac, 0xe6, 0xcf, 0x48, 0x55, 0x6e, 0xbb,
  39178. 0x9d, 0x40, 0x79, 0x96, 0xdd, 0xac, 0xf8, 0xf5, 0x99, 0xad, 0x43, 0x0d,
  39179. 0xad, 0xa9, 0x62, 0xc0, 0x70, 0x8b, 0x50, 0x9b, 0xca, 0x0d, 0x3e, 0x54,
  39180. 0x9c, 0x27, 0xd5, 0x9e, 0x20, 0xe2, 0xe0, 0xb0, 0xb0, 0xbe, 0x8e, 0x56,
  39181. 0x43, 0x95, 0x9b, 0x34, 0xd1, 0x05, 0x28, 0xa0, 0xee, 0xd9, 0xab, 0x6a,
  39182. 0xa7, 0xbb, 0xb7, 0x1b, 0x3a, 0x5d, 0x33, 0x97, 0x25, 0x54, 0xe4, 0x0e,
  39183. 0x64, 0x79, 0xed, 0x16, 0x62, 0x89, 0x70, 0x4a, 0xa6, 0x47, 0x40, 0xd7,
  39184. 0xa3, 0xd2, 0x6f, 0x28, 0xdd, 0xc5, 0x04, 0xab, 0x7e, 0x7e, 0x1e, 0xb0,
  39185. 0x19, 0x02, 0x48, 0xb5, 0x88, 0x82, 0x75, 0xaf, 0x66, 0x74, 0xca, 0xf6,
  39186. 0xd7, 0xe8, 0x6d, 0xfa, 0x5e, 0xfa, 0xaf, 0xa8, 0x04, 0xaa, 0x2c, 0x09,
  39187. 0xf1, 0x4c, 0x36, 0x75, 0xb5, 0xdc, 0xe8, 0x04, 0x80, 0xd3, 0x14, 0x78,
  39188. 0x09, 0x5b, 0xfd, 0x52, 0x6f, 0xd9, 0x3c, 0x1c, 0x02, 0x3b, 0x77, 0xb8,
  39189. 0xa1, 0xe9, 0xa4, 0xb7, 0x42, 0x62, 0xee, 0xea, 0x43, 0xf3, 0xd8, 0xd0,
  39190. 0x7a, 0x53, 0x91, 0x34, 0x7f, 0xe7, 0x9a, 0xc6
  39191. };
  39192. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39193. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_pub_key[] = {
  39194. 0x15, 0xc9, 0xe5, 0x53, 0x2f, 0xd8, 0x1f, 0xb4, 0xa3, 0x9f,
  39195. 0xae, 0xad, 0xb3, 0x10, 0xd0, 0x72, 0x69, 0xd3, 0x02, 0xf3,
  39196. 0xdf, 0x67, 0x5a, 0x31, 0x52, 0x19, 0xca, 0x39, 0x27, 0x77,
  39197. 0x61, 0x6d, 0x0f, 0xc1, 0x33, 0x26, 0x09, 0xf0, 0xf9, 0x4d,
  39198. 0x12, 0x7a, 0xef, 0xf7, 0x21, 0x26, 0x2c, 0xe0, 0xe2, 0x92,
  39199. 0x1f, 0x9d, 0xd1, 0xaa, 0xaf, 0x08, 0x14, 0xf2, 0xaa, 0x24,
  39200. 0x99, 0x0f, 0x20, 0x57, 0x35, 0x04, 0x32, 0x96, 0x8e, 0x6e,
  39201. 0x10, 0x64, 0xe3, 0xe3, 0x57, 0x26, 0x33, 0x32, 0x7b, 0xe4,
  39202. 0x18, 0x41, 0x77, 0xd3, 0x24, 0x63, 0x3d, 0x11, 0xea, 0xdc,
  39203. 0xbe, 0x59, 0xff, 0x8d, 0xc2, 0xe4, 0xc7, 0x04, 0xf3, 0xd4,
  39204. 0xe0, 0x1d, 0x5e, 0x09, 0x46, 0xbf, 0x02, 0x05, 0xc7, 0xa6,
  39205. 0xb7, 0x82, 0x40, 0x1f, 0x55, 0xe9, 0x77, 0x82, 0xc0, 0xcc,
  39206. 0x86, 0x99, 0x19, 0x99, 0xa2, 0xc9, 0x1b, 0x4f, 0xdd, 0x49,
  39207. 0x4c, 0x78, 0x0a, 0x58, 0xb8, 0xf0, 0x23, 0xac, 0x1a, 0x71,
  39208. 0x57, 0x6d, 0xd6, 0x3a, 0x3a, 0x6f, 0x93, 0xb3, 0x2b, 0x09,
  39209. 0xbe, 0xec, 0x7b, 0x5b, 0xf7, 0x3a, 0xed, 0xf9, 0xd0, 0xb1,
  39210. 0xfe, 0x9f, 0x9b, 0xec, 0x11, 0xb6, 0x6b, 0xd1, 0xb6, 0x00,
  39211. 0x72, 0x7f, 0x68, 0x9a, 0x61, 0xa5, 0xf5, 0x6e, 0xe9, 0x46,
  39212. 0xa4, 0x82, 0x08, 0x9f, 0x50, 0x4c, 0x75, 0xc3, 0x48, 0x85,
  39213. 0x76, 0x39, 0xea, 0x0c, 0xf2, 0xe8, 0x7e, 0x48, 0x69, 0xd9,
  39214. 0x6f, 0x9a, 0x89, 0x7d, 0x98, 0xc1, 0x16, 0xdc, 0x2f, 0xc7,
  39215. 0x0a, 0x11, 0xa8, 0xbb, 0xe7, 0x91, 0xb1, 0x0f, 0x0e, 0xf0,
  39216. 0xb4, 0xc8, 0x41, 0x7e, 0x62, 0x9e, 0x3c, 0x30, 0x4c, 0xbc,
  39217. 0x4c, 0xeb, 0x37, 0xaf, 0x48, 0x72, 0x59, 0x64, 0x8e, 0xfb,
  39218. 0x77, 0x11, 0x28, 0xdd, 0x30, 0x52, 0x8e, 0x69, 0x8c, 0x9f,
  39219. 0x3d, 0xec, 0xdf, 0xa7, 0x5f, 0x42, 0x18, 0xda, 0xba, 0x1a,
  39220. 0x96, 0x91, 0x7d, 0x62, 0xd5, 0x52, 0xff, 0x44, 0xc9, 0x1d,
  39221. 0x29, 0xa6, 0xb9, 0x03, 0x9a, 0x26, 0x26, 0xcf, 0x57, 0x40,
  39222. 0x70, 0x7e, 0x2b, 0xbd, 0xf0, 0x81, 0x71, 0x0f, 0x0b, 0x2e,
  39223. 0x9b, 0x03, 0xba, 0x31, 0x41, 0x68, 0x37, 0xc8, 0xff, 0xea,
  39224. 0xc4, 0x73, 0xa5, 0xf9, 0xc2, 0x92, 0x78, 0x0c, 0xe7, 0xfd,
  39225. 0x5d, 0xb2, 0x01, 0xb5, 0x8d, 0xeb, 0x64, 0xd4, 0x14, 0xea,
  39226. 0x7a, 0xd1, 0x42, 0xc8, 0x99, 0xe4, 0x7d, 0x5b, 0x7e, 0x3b,
  39227. 0x8f, 0xab, 0x82, 0x12, 0xdf, 0xbb, 0xa1, 0x45, 0x30, 0xc9,
  39228. 0x0f, 0xb9, 0xe5, 0xba, 0xe6, 0x8a, 0xf3, 0x78, 0x61, 0xcc,
  39229. 0x9f, 0xe1, 0x46, 0x2a, 0x9a, 0x18, 0x0e, 0x2a, 0x57, 0xf3,
  39230. 0xe5, 0x56, 0xd1, 0x42, 0x48, 0xe1, 0x5a, 0x8e, 0x33, 0xce,
  39231. 0x19, 0xe5, 0x3e, 0x7f, 0x00, 0x70, 0x9c, 0x4c, 0xd3, 0xe1,
  39232. 0x0c, 0xa1, 0x7e, 0xd4, 0xa9, 0x9e, 0x8b, 0xe2, 0xf0, 0xac,
  39233. 0xdb, 0xa6, 0x72, 0x75, 0x67, 0xa6, 0x57, 0xed, 0x79, 0x2e,
  39234. 0xca, 0x8d, 0xeb, 0x9b, 0x9e, 0xb7, 0xbf, 0x30, 0x02, 0x2b,
  39235. 0xb3, 0x43, 0x89, 0x9b, 0xa8, 0x88, 0xa5, 0xbb, 0x33, 0xd9,
  39236. 0x99, 0x30, 0x7c, 0xc7, 0xd4, 0x28, 0x5e, 0x5e, 0x3f, 0x9d,
  39237. 0x6d, 0x35, 0x75, 0x33, 0x8e, 0xff, 0x84, 0x2e, 0x2d, 0xda,
  39238. 0xf0, 0xff, 0x70, 0xe5, 0xb5, 0x62, 0x96, 0x33, 0x3a, 0xd9,
  39239. 0xb5, 0x82, 0x25, 0x81, 0x81, 0x40, 0x5d, 0x4f, 0x11, 0x86,
  39240. 0x63, 0x1a, 0x06, 0xc1, 0x67, 0xc7, 0x49, 0x03, 0xc7, 0xe4,
  39241. 0x6f, 0xb4, 0x13, 0x3e, 0x57, 0x62, 0xfd, 0x8a, 0xc6, 0x2b,
  39242. 0x65, 0x5b, 0xa4, 0x29, 0x57, 0x8d, 0xde, 0xa5, 0xee, 0x32,
  39243. 0xc2, 0x76, 0x03, 0xca, 0xce, 0xc1, 0x48, 0xec, 0x45, 0xcf,
  39244. 0x30, 0x21, 0x28, 0x7f, 0x10, 0x47, 0xd2, 0xdb, 0xee, 0xca,
  39245. 0x5b, 0x0f, 0xd5, 0x39, 0x3a, 0xc3, 0xa6, 0x78, 0xb2, 0x15,
  39246. 0xaf, 0x82, 0x3c, 0x2f, 0xc4, 0x51, 0x5c, 0x52, 0xad, 0xf2,
  39247. 0x89, 0x92, 0x8e, 0xf3, 0x50, 0x38, 0xed, 0xf8, 0xc9, 0x14,
  39248. 0x4c, 0xe4, 0xa3, 0x9a, 0xaf, 0xc4, 0x5c, 0xf3, 0x9f, 0xc3,
  39249. 0xa3, 0xc0, 0xbe, 0x45, 0x1b, 0x21, 0x63, 0xfa, 0xe0, 0xe0,
  39250. 0x91, 0x2b, 0x42, 0xca, 0x91, 0xfb, 0x5e, 0x97, 0x9a, 0x0a,
  39251. 0xd4, 0x88, 0xba, 0xb8, 0x22, 0xc6, 0xbf, 0x56, 0x58, 0x1e,
  39252. 0x92, 0xa9, 0x9d, 0xa7, 0xed, 0xc9, 0xab, 0x54, 0x4f, 0x75,
  39253. 0x8d, 0x42, 0xc1, 0xe1, 0x61, 0xd0, 0x91, 0x9a, 0x3a, 0x40,
  39254. 0x9a, 0xa3, 0xfb, 0x7b, 0x4e, 0xf0, 0x85, 0xf0, 0xdc, 0x40,
  39255. 0x72, 0x9f, 0x05, 0xa8, 0xbe, 0x95, 0x5a, 0x7f, 0xba, 0x75,
  39256. 0x00, 0x6e, 0x95, 0x76, 0xbd, 0xb2, 0x40, 0xf5, 0xb0, 0x64,
  39257. 0x0a, 0x2f, 0x06, 0x3d, 0x9f, 0xac, 0x6a, 0xa5, 0x46, 0x5a,
  39258. 0x85, 0xa4, 0x6f, 0xee, 0x27, 0xa0, 0xeb, 0x5f, 0x1f, 0x91,
  39259. 0xbd, 0x2b, 0x02, 0x16, 0xdf, 0x74, 0x97, 0x2c, 0xd0, 0xa8,
  39260. 0x9f, 0x3a, 0x7b, 0xdf, 0x3e, 0x98, 0x4a, 0x91, 0xdc, 0x19,
  39261. 0x96, 0x88, 0x75, 0x21, 0x1a, 0x6a, 0xa8, 0x4b, 0x1f, 0x35,
  39262. 0xd1, 0x92, 0xf5, 0x76, 0xf4, 0x72, 0x55, 0x13, 0xdb, 0x5d,
  39263. 0x07, 0x8d, 0xd9, 0x72, 0xe4, 0x75, 0xde, 0x80, 0xbc, 0xe9,
  39264. 0x9c, 0xf0, 0x5c, 0x6a, 0x8a, 0x0e, 0x34, 0xf6, 0x3f, 0x5c,
  39265. 0xef, 0x0e, 0xcc, 0x52, 0x38, 0x2d, 0x7b, 0xc2, 0x1b, 0x69,
  39266. 0x9f, 0xe5, 0xed, 0x14, 0xb0, 0x91, 0x0b, 0xe9, 0x4d, 0x34,
  39267. 0xd5, 0xaa, 0xd4, 0xd2, 0x46, 0x39, 0x45, 0x7e, 0x85, 0x2f,
  39268. 0xdb, 0x89, 0xf4, 0xff, 0x05, 0x74, 0x51, 0xba, 0xdd, 0xee,
  39269. 0xf6, 0xc2, 0xc1, 0x0a, 0x8f, 0xd9, 0xeb, 0xc7, 0x61, 0x30,
  39270. 0x8f, 0x86, 0x8b, 0x1f, 0x82, 0xc1, 0x22, 0xfd, 0x83, 0xf4,
  39271. 0x5d, 0xc5, 0x94, 0xf5, 0xd7, 0x17, 0xc7, 0x7b, 0x71, 0xf5,
  39272. 0x5e, 0x15, 0x49, 0x70, 0xb2, 0x57, 0xa0, 0xc0, 0x57, 0x63,
  39273. 0x53, 0x35, 0xb6, 0x52, 0x20, 0x7b, 0x83, 0xd4, 0x57, 0x63,
  39274. 0x25, 0x8e, 0x83, 0xb3, 0x8e, 0x26, 0x1f, 0x09, 0xde, 0x14,
  39275. 0xd6, 0xa6, 0xfc, 0xe5, 0x93, 0x3c, 0x88, 0x8e, 0xf5, 0x10,
  39276. 0x57, 0xb9, 0xc9, 0x9b, 0xff, 0x72, 0x9d, 0x3d, 0x3f, 0x97,
  39277. 0xd9, 0x3c, 0x20, 0xe2, 0x57, 0xfd, 0x2a, 0x5c, 0x17, 0x12,
  39278. 0xe6, 0x08, 0xaf, 0xe4, 0x26, 0x96, 0xb9, 0x6d, 0xc3, 0xac,
  39279. 0x22, 0xf3, 0x8b, 0x89, 0xde, 0xc7, 0x8a, 0x93, 0x06, 0xf7,
  39280. 0x1d, 0x08, 0x21, 0x36, 0x16, 0x74, 0x2b, 0x97, 0x23, 0xe4,
  39281. 0x79, 0x31, 0x08, 0x23, 0x62, 0x30, 0x67, 0xe2, 0xed, 0x30,
  39282. 0x9b, 0x0c, 0xf9, 0x08, 0x7a, 0x29, 0x73, 0xc6, 0x77, 0x8a,
  39283. 0xbb, 0x2a, 0x1c, 0x66, 0xd0, 0xdd, 0x9e, 0xa3, 0xe9, 0x62,
  39284. 0xcc, 0xb7, 0x88, 0x25, 0x4a, 0x5f, 0xbc, 0xaa, 0xe3, 0xe4,
  39285. 0x4f, 0xec, 0xa6, 0x8e, 0xa6, 0xa4, 0x1b, 0x22, 0x2b, 0x2c,
  39286. 0x8f, 0x57, 0x7f, 0xb7, 0x33, 0xfe, 0x16, 0x43, 0x85, 0xc5,
  39287. 0xd2, 0x95, 0xe6, 0xb9, 0x21, 0x68, 0x88, 0x98, 0x33, 0x8c,
  39288. 0x1d, 0x15, 0x9c, 0x4d, 0x62, 0x1f, 0x6b, 0xe8, 0x7a, 0x2d,
  39289. 0x6b, 0x0e, 0xc3, 0xde, 0x1a, 0xa8, 0xed, 0x67, 0xb3, 0xb3,
  39290. 0x36, 0x5b, 0x4b, 0xcb, 0xe8, 0xa8, 0x5c, 0x0b, 0x2f, 0xca,
  39291. 0xd7, 0x71, 0xe8, 0x85, 0xe7, 0x4d, 0xe5, 0x7b, 0x45, 0xed,
  39292. 0xb2, 0x4c, 0x69, 0x04, 0x7e, 0x4f, 0xc0, 0xef, 0x1a, 0xca,
  39293. 0x0d, 0xa6, 0xc4, 0x79, 0x15, 0x78, 0x9c, 0xd2, 0x91, 0x3c,
  39294. 0x32, 0x55, 0x40, 0xe7, 0xcb, 0x7e, 0xde, 0x07, 0xa6, 0x97,
  39295. 0x00, 0x2d, 0x70, 0xf6, 0x3d, 0x15, 0xdf, 0x29, 0x8e, 0xa3,
  39296. 0x96, 0x6d, 0xf2, 0xbb, 0xa5, 0x1b, 0x7b, 0x58, 0x30, 0xf6,
  39297. 0x17, 0xbd, 0xda, 0x13, 0xf7, 0x33, 0xc2, 0x62, 0x32, 0xd4,
  39298. 0x1c, 0x2e, 0x31, 0x74, 0x92, 0xad, 0x99, 0x8c, 0x0e, 0x7c,
  39299. 0x50, 0x21, 0xcd, 0xff, 0x41, 0xeb, 0xd1, 0xca, 0x14, 0xb7,
  39300. 0xb2, 0x31, 0x2f, 0xbe, 0x16, 0xce, 0x4f, 0x26, 0x16, 0x04,
  39301. 0xc2, 0xaf, 0xbe, 0x0d, 0x24, 0xab, 0x9a, 0x21, 0x37, 0x06,
  39302. 0xac, 0x50, 0x23, 0xf1, 0xbe, 0x5c, 0xbb, 0x64, 0xf3, 0xd3,
  39303. 0x66, 0xa3, 0xb8, 0xbe, 0x8b, 0x49, 0x8d, 0xf6, 0xc7, 0xb9,
  39304. 0x8f, 0x4e, 0x31, 0x06, 0x51, 0xe5, 0xf3, 0x0e, 0x56, 0xc4,
  39305. 0x24, 0x30, 0xf5, 0xe9, 0x36, 0x71, 0xbc, 0xc9, 0x70, 0x2c,
  39306. 0x6c, 0x4c, 0x15, 0x43, 0x44, 0xa4, 0xfc, 0xf1, 0xd2, 0x71,
  39307. 0x6c, 0x4c, 0xce, 0x30, 0x6c, 0x05, 0x7d, 0x2e, 0xb7, 0xbc,
  39308. 0xe4, 0x65, 0x76, 0x24, 0x75, 0x36, 0xdf, 0x28, 0xfc, 0xcd,
  39309. 0x9a, 0xba, 0xc2, 0xcd, 0xb0, 0x30, 0xdb, 0xe7, 0x2e, 0x3c,
  39310. 0x92, 0x63, 0x1d, 0x30, 0x23, 0x74, 0xb1, 0xb8, 0xcc, 0xd7,
  39311. 0xb6, 0x90, 0x65, 0x73, 0xa2, 0x2a, 0x6e, 0x49, 0x95, 0x0d,
  39312. 0xab, 0x24, 0xdf, 0x2d, 0xbf, 0x76, 0x46, 0x01, 0x44, 0xe4,
  39313. 0x18, 0x8e, 0xd5, 0x9a, 0x76, 0xc9, 0xc6, 0xbc, 0xdb, 0x7f,
  39314. 0x80, 0x52, 0xc6, 0x40, 0x41, 0x12, 0x36, 0x7c, 0x80, 0x69,
  39315. 0xce, 0x7b, 0xe1, 0xa0, 0x53, 0xa2, 0xd6, 0x8f, 0x3f, 0xf7,
  39316. 0xd7, 0x61, 0x09, 0x70, 0xa2, 0xa0, 0xc6, 0xaf, 0xa0, 0xd0,
  39317. 0xfa, 0x13, 0xbf, 0xc0, 0x69, 0x15, 0xce, 0x15, 0xec, 0x24,
  39318. 0x4b, 0x6b, 0xdc, 0x93, 0x51, 0xc6, 0x82, 0x19, 0x92, 0x84,
  39319. 0x5d, 0x99, 0xb0, 0x90, 0x2c, 0xcc, 0x2a, 0x81, 0x6b, 0x22,
  39320. 0x64, 0x0a, 0xcb, 0x51, 0x25, 0x82, 0x50, 0x02, 0x2d, 0x3e,
  39321. 0xd4, 0x72, 0xb3, 0x0c, 0x15, 0x77, 0xd2, 0xca, 0x98, 0x2f,
  39322. 0x41, 0x93, 0x14, 0xb2, 0x7f, 0xa1, 0x97, 0xa3, 0xb8, 0x8a,
  39323. 0x56, 0x24, 0x38, 0xa7, 0x36, 0xc5, 0x01, 0xc0, 0x9f, 0x3f,
  39324. 0x3e, 0x9a, 0xf6, 0xe9, 0x16, 0x82, 0x01, 0x58, 0x70, 0x0e,
  39325. 0x0d, 0xbc, 0xfa, 0x03, 0x57, 0x65, 0xa8, 0x5a, 0x3d, 0x57,
  39326. 0x81, 0x23, 0xbe, 0x6e, 0xa9, 0xe8, 0x22, 0xdf, 0x2f, 0x70,
  39327. 0xeb, 0x0a, 0x03, 0x96, 0x6b, 0xef, 0x20, 0x9f, 0xf2, 0x62,
  39328. 0xe7, 0xb2, 0x6e, 0x3a, 0x1e, 0x40, 0x1f, 0xd2, 0x97, 0x48,
  39329. 0xd1, 0x18, 0xf0, 0xeb, 0x52, 0x58, 0x02, 0x26, 0xce, 0x75,
  39330. 0xb1, 0x3a, 0x9d, 0x5b, 0x52, 0x94, 0xb2, 0x6e, 0x0e, 0x3f,
  39331. 0x39, 0xb6, 0xd9, 0x8a, 0x9d, 0xe8, 0x7c, 0x83, 0x32, 0xcc,
  39332. 0x43, 0x35, 0x9b, 0x7a, 0xed, 0xb2, 0x1e, 0x51, 0x37, 0x6c,
  39333. 0x14, 0xd8, 0xb8, 0x55, 0xb3, 0x91, 0xef, 0x0c, 0x3a, 0xe5,
  39334. 0x77, 0xd0, 0xbd, 0xb0, 0x7d, 0x38, 0x84, 0x2a, 0x47, 0xb2,
  39335. 0xb6, 0xda, 0xd7, 0x75, 0xd6, 0x2e, 0x60, 0xc7, 0x10, 0x52,
  39336. 0xf7, 0xdd, 0x09, 0x15, 0x6f, 0x04, 0x31, 0xc3, 0x5a, 0x6b,
  39337. 0x0c, 0x60, 0x10, 0xa8, 0x6e, 0x20, 0xa9, 0xdd, 0xb7, 0x72,
  39338. 0xc3, 0x9e, 0x85, 0xd2, 0x8f, 0x16, 0x7e, 0x3d, 0xe0, 0x63,
  39339. 0x81, 0x32, 0xfd, 0xca, 0xbc, 0x0f, 0xef, 0x3e, 0x74, 0x6a,
  39340. 0xb1, 0x60, 0xc1, 0x10, 0x50, 0x7c, 0x67, 0xa4, 0x19, 0xa7,
  39341. 0xb8, 0xed, 0xe6, 0xf5, 0x4e, 0x41, 0x53, 0xa6, 0x72, 0x1b,
  39342. 0x2c, 0x33, 0x6a, 0x37, 0xf1, 0xb5, 0x1c, 0x01, 0x7d, 0xa2,
  39343. 0x1f, 0x2c, 0x4e, 0x0a, 0xbf, 0xd4, 0x2c, 0x24, 0x91, 0x58,
  39344. 0x62, 0xfb, 0xf8, 0x63, 0xd9, 0xf8, 0x78, 0xf5, 0xc7, 0x78,
  39345. 0x32, 0xda, 0x99, 0xeb, 0x58, 0x20, 0x25, 0x19, 0xb1, 0x06,
  39346. 0x7f, 0x6a, 0x29, 0x20, 0xdb, 0xc8, 0x22, 0x48, 0xa9, 0x7f,
  39347. 0x24, 0x54, 0x8d, 0x7d, 0x8d, 0xb1, 0x69, 0xb2, 0xa3, 0x98,
  39348. 0x14, 0x0f, 0xba, 0xfa, 0xb6, 0x15, 0xe8, 0x28, 0x99, 0x3f,
  39349. 0x30, 0x04, 0x50, 0xab, 0x5a, 0x3c, 0xf1, 0x97, 0xe1, 0xc8,
  39350. 0x0f, 0x0e, 0xb4, 0x11, 0x63, 0x5a, 0x79, 0x08, 0x48, 0x75,
  39351. 0xaf, 0x9b, 0xca, 0xd9, 0x13, 0x18, 0xcc, 0xb1, 0xb3, 0xee,
  39352. 0xdd, 0x63, 0xdd, 0xf4, 0x21, 0x98, 0x76, 0xe2, 0x3e, 0xd5,
  39353. 0x86, 0x23, 0x33, 0x7e, 0xc7, 0xb4, 0x35, 0x4b, 0xc2, 0x2d,
  39354. 0xe1, 0xe2, 0xb0, 0x6c, 0x8b, 0x9b, 0x20, 0x3d, 0x48, 0x24,
  39355. 0x7c, 0xea, 0xa1, 0x75, 0x27, 0xe5, 0xf4, 0x70, 0xeb, 0x3b,
  39356. 0xc7, 0x26, 0x37, 0x04, 0xff, 0x8a, 0x7a, 0xd0, 0xc2, 0xb7,
  39357. 0x84, 0xb7, 0x29, 0xfb, 0x0e, 0xa3, 0xa8, 0x71, 0xcd, 0x58,
  39358. 0x06, 0x36, 0xe2, 0xf2, 0x77, 0xcc, 0x0f, 0x78, 0x08, 0x2b,
  39359. 0xbb, 0xe3, 0x53, 0x05, 0x71, 0xdc, 0x6c, 0x37, 0x32, 0x91,
  39360. 0x46, 0x42, 0x4f, 0x21, 0xe0, 0x34, 0xad, 0x3f, 0x30, 0x5a,
  39361. 0xc7, 0x0d, 0x17, 0x19, 0x39, 0x31, 0x58, 0x69, 0x3c, 0x8c,
  39362. 0xbe, 0xe7, 0xa6, 0x3b, 0xad, 0xfb, 0x46, 0x89, 0x06, 0xc1,
  39363. 0x8c, 0x16, 0x9a, 0x06, 0x3a, 0xd0, 0x7e, 0xd6, 0xb0, 0x7b,
  39364. 0x7d, 0xf8, 0x91, 0x7c, 0xfa, 0xd9, 0x66, 0x39, 0xfa, 0xbc,
  39365. 0x57, 0xa7, 0x78, 0x8b, 0x36, 0x78, 0xc0, 0x1c, 0x0e, 0x23,
  39366. 0x05, 0x0e, 0x04, 0x61, 0x16, 0x34, 0xf9, 0xc6, 0x63, 0x58,
  39367. 0xdf, 0xf4, 0x52, 0xce, 0xd0, 0x0f, 0x0c, 0xec, 0xb1, 0x82,
  39368. 0xf4, 0x72, 0x73, 0x72, 0x3f, 0x02, 0xbe, 0xe3, 0x9c, 0x63,
  39369. 0x73, 0xc8, 0x21, 0x65, 0xba, 0x57, 0x52, 0xa9, 0x19, 0xac,
  39370. 0x68, 0x50, 0xbd, 0x2d, 0x72, 0x5b, 0x93, 0x0f, 0x1c, 0x81,
  39371. 0x77, 0xd7, 0x2e, 0xc3, 0x93, 0x52, 0x6e, 0xdc, 0x79, 0x52,
  39372. 0x9f, 0xe3, 0xde, 0xe1, 0xba, 0x58, 0x55, 0xab, 0x8a, 0xf2,
  39373. 0x35, 0x6a, 0xcf, 0x94, 0x1f, 0x17, 0xa4, 0x23, 0x2e, 0x8e,
  39374. 0x18, 0x21, 0xbe, 0x14, 0xfa, 0xe7, 0x59, 0xc5, 0x44, 0x34,
  39375. 0xce, 0x03, 0xf4, 0xb7, 0x75, 0xd3, 0x51, 0x55, 0xdf, 0xff,
  39376. 0xcf, 0x4f, 0x44, 0xee, 0x13, 0x9b, 0xcb, 0x12, 0xae, 0xe5,
  39377. 0x5b, 0x44, 0x65, 0x28, 0xcb, 0x6a, 0x9c, 0x24, 0x1d, 0xea,
  39378. 0x2d, 0x5e, 0xa5, 0xc3, 0x78, 0xad, 0xed, 0x0c, 0x05, 0xa6,
  39379. 0xaf, 0x95, 0x04, 0xd2, 0xb5, 0x91, 0x0e, 0xa0, 0x06, 0x77,
  39380. 0xc5, 0x82, 0xf6, 0xdd, 0x72, 0x83, 0x04, 0xcc, 0xb0, 0xab,
  39381. 0x7a, 0xf0, 0xb4, 0x4d, 0x36, 0x71, 0x72, 0x1a, 0x9a, 0x0d,
  39382. 0xcd, 0xa3, 0x11, 0xa8, 0x0d, 0x7d, 0x49, 0xce, 0x9c, 0x09,
  39383. 0x1d, 0x08, 0xa4, 0x39, 0x2e, 0x03, 0xdf, 0x3a, 0xc8, 0xfe,
  39384. 0x6a, 0x2b, 0x0b, 0x07, 0x80, 0x55, 0x8a, 0xa8, 0xe6, 0x0e,
  39385. 0xc9, 0x7e, 0x83, 0xce, 0x3a, 0x98, 0x98, 0x4e, 0x3e, 0x08,
  39386. 0x20, 0x8f, 0x10, 0xfc, 0xc1, 0xc4, 0xcf, 0x37, 0x8d, 0x69,
  39387. 0xd8, 0x57, 0x9d, 0x48, 0x80, 0x6a, 0xef, 0x0c, 0xdd, 0x27,
  39388. 0x99, 0xf9, 0xe7, 0xd0, 0xd2, 0x36, 0xd8, 0xed, 0x41, 0x14,
  39389. 0x1b, 0x10
  39390. };
  39391. #endif
  39392. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_sig[] = {
  39393. 0xb1, 0xd1, 0x8e, 0x83, 0x0b, 0x0d, 0xd2, 0x71, 0xb2, 0xaa, 0x31, 0x38,
  39394. 0x16, 0xf0, 0xb4, 0xbc, 0x64, 0x2b, 0x97, 0xa1, 0x08, 0x19, 0x4f, 0x52,
  39395. 0xfe, 0x99, 0x1a, 0xa9, 0xd4, 0x08, 0x93, 0x99, 0x88, 0xfd, 0x6a, 0xd6,
  39396. 0xd8, 0xdb, 0xf0, 0x71, 0x2a, 0xc9, 0x04, 0x83, 0xc9, 0x45, 0x59, 0x5d,
  39397. 0xe0, 0x36, 0x59, 0x53, 0x1b, 0xb8, 0x5a, 0xa6, 0x1f, 0xb4, 0x1b, 0x0a,
  39398. 0xfb, 0x3a, 0xba, 0xe3, 0xb7, 0x5e, 0x04, 0x14, 0x59, 0x09, 0x9a, 0x8e,
  39399. 0xc2, 0x77, 0x5a, 0x3d, 0xf1, 0x43, 0x67, 0x74, 0x78, 0xfc, 0xcd, 0x34,
  39400. 0xed, 0x35, 0x16, 0x38, 0x04, 0xe6, 0xe7, 0xd6, 0xd2, 0x90, 0x1b, 0x28,
  39401. 0xb6, 0x66, 0x1b, 0x57, 0x85, 0x5e, 0xa7, 0x9f, 0x86, 0x1a, 0x0d, 0xc3,
  39402. 0x7e, 0xed, 0xbd, 0x32, 0x8a, 0x35, 0xe1, 0xb3, 0x01, 0xdc, 0x9b, 0x44,
  39403. 0x88, 0xa1, 0x0b, 0x87, 0x6e, 0x55, 0x31, 0xb1, 0x27, 0xcb, 0x85, 0xa4,
  39404. 0x27, 0x56, 0x33, 0xb0, 0x39, 0x0d, 0xd3, 0x4b, 0xd1, 0xa2, 0x47, 0x07,
  39405. 0xc6, 0xf4, 0xe6, 0x1f, 0x88, 0x70, 0x70, 0x13, 0x7e, 0x2e, 0x17, 0x32,
  39406. 0x0a, 0x6b, 0x38, 0x34, 0xcf, 0x2f, 0x00, 0x36, 0x58, 0x8d, 0xe1, 0xdd,
  39407. 0xa7, 0x94, 0x2a, 0x8f, 0x87, 0x99, 0x67, 0x02, 0x4d, 0x5b, 0x56, 0xaf,
  39408. 0xef, 0xc4, 0x3c, 0xff, 0x72, 0x53, 0x95, 0x27, 0x03, 0x49, 0x94, 0x4f,
  39409. 0x94, 0x87, 0x1f, 0x52, 0x33, 0xed, 0xb9, 0x14, 0x7b, 0xe5, 0x6c, 0xef,
  39410. 0x7a, 0x17, 0x5a, 0xa4, 0x89, 0x2a, 0xfe, 0x68, 0xda, 0xdd, 0x48, 0xc2,
  39411. 0xf0, 0x92, 0xf4, 0xe4, 0xd6, 0xa6, 0x48, 0x08, 0x2c, 0xe8, 0xcd, 0x72,
  39412. 0xf6, 0x94, 0x3e, 0xc1, 0x82, 0xb8, 0x01, 0x58, 0xb2, 0xef, 0xef, 0xf4,
  39413. 0xcb, 0x93, 0x63, 0x2e, 0x33, 0x5b, 0xc9, 0xd6, 0x6a, 0xde, 0xad, 0xe8,
  39414. 0x1e, 0x3f, 0xa3, 0xf2, 0x35, 0x87, 0xc1, 0xc9, 0x48, 0x2f, 0x1b, 0x00,
  39415. 0xea, 0x3d, 0x04, 0x29, 0xd5, 0xc0, 0xe9, 0x1a, 0xc5, 0xce, 0x5e, 0xdb,
  39416. 0xd1, 0xee, 0x16, 0x9c, 0x05, 0x40, 0xf9, 0x21, 0x13, 0x72, 0x08, 0x39,
  39417. 0x6b, 0x63, 0x19, 0xcd, 0x6f, 0x64, 0xa0, 0xc3, 0x77, 0xb7, 0x50, 0xed,
  39418. 0xe9, 0x2d, 0xd5, 0x72, 0xea, 0xa6, 0xc1, 0x97, 0xb9, 0x6b, 0xe5, 0x81,
  39419. 0x91, 0x8e, 0xd1, 0x36, 0x11, 0xee, 0xfb, 0x2b, 0x66, 0xba, 0xe4, 0x3e,
  39420. 0xd0, 0xdd, 0x17, 0xc5, 0x24, 0x3b, 0xc3, 0x5b, 0x75, 0xfc, 0xd5, 0xb6,
  39421. 0x8c, 0xba, 0x8c, 0x66, 0xb2, 0xee, 0x40, 0x45, 0x8c, 0x23, 0xbb, 0xe0,
  39422. 0xc8, 0xd6, 0x05, 0xfd, 0x71, 0x5b, 0x24, 0xbb, 0x37, 0x65, 0x5f, 0x57,
  39423. 0x92, 0x22, 0x13, 0xb2, 0x9a, 0x70, 0x22, 0x4b, 0xbe, 0x03, 0xd1, 0x54,
  39424. 0xb0, 0x3a, 0x30, 0x50, 0x71, 0x24, 0xf7, 0x81, 0x8c, 0x20, 0x67, 0x74,
  39425. 0x5a, 0xef, 0xa1, 0x6a, 0xe3, 0xd0, 0x04, 0xd6, 0xa5, 0x6e, 0xad, 0xa7,
  39426. 0x15, 0x41, 0xf3, 0x21, 0xe8, 0xd9, 0xe6, 0xe5, 0x97, 0xbd, 0xc2, 0x1b,
  39427. 0xbb, 0xd1, 0x4e, 0x7e, 0x5a, 0xd6, 0xe4, 0x19, 0xa5, 0xe4, 0x76, 0xf4,
  39428. 0xce, 0x00, 0x94, 0x76, 0xef, 0x1b, 0xb3, 0x47, 0xb9, 0xa3, 0x32, 0xf7,
  39429. 0x45, 0x6d, 0x32, 0x73, 0x06, 0xc0, 0xb9, 0xaf, 0x9c, 0x46, 0x99, 0xbe,
  39430. 0x14, 0x06, 0xcd, 0x35, 0x7c, 0x90, 0x7c, 0xe7, 0x97, 0x0a, 0x9f, 0xb4,
  39431. 0x21, 0xff, 0xf0, 0xea, 0x83, 0xc0, 0x86, 0x68, 0x9f, 0x36, 0xb0, 0xad,
  39432. 0xe1, 0x8d, 0xc5, 0x76, 0x55, 0xb5, 0xb6, 0x7e, 0x1f, 0xa7, 0x5b, 0x26,
  39433. 0x6c, 0xb5, 0xf9, 0x54, 0x1f, 0x76, 0xc1, 0x9c, 0xfc, 0x57, 0xc8, 0x86,
  39434. 0xc1, 0x7d, 0x59, 0x55, 0x92, 0xa5, 0xb8, 0x03, 0xfa, 0xa5, 0x72, 0xd1,
  39435. 0x5c, 0x8d, 0x9b, 0x2e, 0x84, 0x07, 0x18, 0xee, 0x49, 0xc5, 0x99, 0x8e,
  39436. 0x15, 0x7c, 0xbf, 0xad, 0x8b, 0x13, 0xcd, 0x97, 0xf9, 0x3c, 0xa2, 0x89,
  39437. 0x9c, 0x9c, 0x89, 0xc9, 0x7a, 0x46, 0xb3, 0x42, 0x7b, 0xd4, 0x28, 0x0d,
  39438. 0x55, 0x63, 0x28, 0xd6, 0xc1, 0x65, 0xf5, 0x34, 0x6e, 0x38, 0x2a, 0xb4,
  39439. 0x35, 0x40, 0xed, 0x7e, 0x80, 0x61, 0x9d, 0x8f, 0x68, 0x4f, 0x74, 0x0c,
  39440. 0x30, 0x35, 0x0e, 0xb3, 0x07, 0xf4, 0x92, 0xed, 0x9c, 0x7f, 0xf5, 0xed,
  39441. 0x3e, 0x17, 0x5b, 0x6e, 0x91, 0x46, 0xa1, 0x25, 0x1d, 0x83, 0x50, 0x93,
  39442. 0x35, 0x06, 0x6c, 0x2f, 0x99, 0x8b, 0x21, 0x4c, 0x5c, 0x34, 0xb1, 0xa7,
  39443. 0x82, 0xbc, 0x70, 0x28, 0x56, 0x61, 0x29, 0x35, 0x89, 0x0b, 0x41, 0x21,
  39444. 0xf0, 0xf7, 0xff, 0x69, 0x3d, 0xa4, 0x28, 0x1e, 0x0d, 0x5d, 0xa7, 0x0e,
  39445. 0xaa, 0xd3, 0x4a, 0x95, 0x49, 0xfe, 0x35, 0x5f, 0xa9, 0xc0, 0xe4, 0xe1,
  39446. 0x9a, 0x03, 0xd4, 0xac, 0x96, 0xe3, 0xea, 0x7e, 0xa6, 0x85, 0x7e, 0xb0,
  39447. 0xb8, 0xc2, 0xe8, 0x07, 0xd6, 0xd3, 0x1a, 0x84, 0x90, 0x24, 0x04, 0xef,
  39448. 0x7c, 0x93, 0x15, 0x83, 0xea, 0xe2, 0x42, 0xc6, 0xe7, 0x13, 0x45, 0xbf,
  39449. 0x35, 0xae, 0x5d, 0x50, 0x79, 0x16, 0xbb, 0x11, 0x17, 0x1b, 0xf4, 0x08,
  39450. 0x88, 0x9d, 0x66, 0x14, 0x6a, 0xa0, 0x71, 0x76, 0x80, 0x51, 0x73, 0x7c,
  39451. 0x1d, 0xb0, 0xc1, 0xad, 0x58, 0xfb, 0xbe, 0xcf, 0x73, 0xe0, 0xd9, 0xf8,
  39452. 0xd5, 0xac, 0xd7, 0x49, 0xd9, 0xc9, 0x59, 0xbf, 0xfa, 0xf5, 0xb1, 0xd2,
  39453. 0x5a, 0x01, 0xcd, 0x8b, 0x07, 0x8b, 0x59, 0x37, 0xc0, 0x8c, 0x7d, 0xa9,
  39454. 0x71, 0x83, 0xf9, 0x7c, 0x58, 0xa9, 0x77, 0x01, 0x3d, 0x39, 0x56, 0x5c,
  39455. 0x93, 0xfe, 0x40, 0x87, 0x5a, 0x31, 0x81, 0x53, 0x8e, 0x0d, 0x99, 0x7e,
  39456. 0xdf, 0x37, 0xd9, 0xe3, 0x91, 0xb8, 0x60, 0x3a, 0x5b, 0xca, 0xe8, 0x91,
  39457. 0x56, 0x89, 0x59, 0x61, 0xc6, 0x31, 0xe2, 0x6c, 0x81, 0xda, 0xc7, 0x5c,
  39458. 0x04, 0x9d, 0xe4, 0x23, 0x12, 0x73, 0xfc, 0x48, 0xfb, 0xa5, 0xce, 0x87,
  39459. 0x37, 0x47, 0x71, 0x5c, 0xd1, 0x2a, 0x63, 0x89, 0xdc, 0x07, 0xe7, 0x7f,
  39460. 0x5d, 0x48, 0xe6, 0xd2, 0x96, 0xc6, 0x6f, 0xed, 0xee, 0x8c, 0xed, 0x5e,
  39461. 0x41, 0x38, 0xbd, 0xdf, 0x21, 0xaa, 0x9e, 0x51, 0x16, 0x22, 0x4a, 0xdc,
  39462. 0xd8, 0x12, 0xdf, 0x5a, 0x83, 0xd6, 0xd0, 0x07, 0xa4, 0x42, 0x41, 0x13,
  39463. 0xe1, 0x08, 0xc9, 0x00, 0x0f, 0x37, 0xc0, 0x7d, 0xda, 0xb2, 0x25, 0xfc,
  39464. 0xc9, 0xbc, 0xa8, 0x86, 0xcc, 0x38, 0x0e, 0x06, 0x51, 0x1b, 0x37, 0xc1,
  39465. 0x0e, 0x2a, 0x58, 0x49, 0xbc, 0x7c, 0xa7, 0xf0, 0xda, 0xd7, 0x74, 0x34,
  39466. 0xf5, 0xd8, 0x99, 0x8c, 0x94, 0x86, 0xe3, 0x1e, 0x6b, 0xf5, 0x68, 0xfa,
  39467. 0xa6, 0x69, 0x63, 0x22, 0x5a, 0x3c, 0x6f, 0x29, 0xc9, 0x40, 0xc0, 0xbe,
  39468. 0x8d, 0xb5, 0xcc, 0x82, 0x6e, 0x9d, 0xd1, 0x1f, 0x13, 0x63, 0xd8, 0x24,
  39469. 0x63, 0x38, 0x59, 0xf0, 0x4a, 0x8c, 0x0f, 0x28, 0x8a, 0x77, 0x81, 0xa2,
  39470. 0xa0, 0x23, 0x11, 0x59, 0xa9, 0x5a, 0x2d, 0x71, 0x8f, 0x82, 0xa7, 0xbd,
  39471. 0x85, 0x26, 0x4d, 0xc2, 0x2f, 0x11, 0xe8, 0xff, 0x96, 0xa1, 0x2d, 0xf2,
  39472. 0xd5, 0xf3, 0x1d, 0x54, 0xd0, 0x5f, 0x71, 0x07, 0xaf, 0x22, 0xa0, 0xcd,
  39473. 0x78, 0xb3, 0x47, 0xb1, 0x40, 0x3d, 0x6b, 0xfd, 0x10, 0x1b, 0xc6, 0x60,
  39474. 0xef, 0x5c, 0x24, 0xa3, 0x1f, 0xee, 0xc0, 0x0b, 0xed, 0x1d, 0x38, 0xc8,
  39475. 0xf2, 0x8c, 0xec, 0x5e, 0xd9, 0x70, 0x1a, 0x2b, 0x25, 0xe6, 0xed, 0xa9,
  39476. 0x0c, 0xb3, 0x78, 0xe1, 0x91, 0x01, 0x41, 0x2e, 0xfe, 0x7d, 0xbd, 0xfe,
  39477. 0xcf, 0x48, 0x6d, 0x2e, 0x05, 0x31, 0x89, 0x24, 0xc4, 0xd7, 0xc4, 0x26,
  39478. 0x2f, 0x64, 0x43, 0xa3, 0xdd, 0x56, 0x11, 0x5c, 0x65, 0x76, 0x96, 0xcc,
  39479. 0x3c, 0x12, 0x42, 0xf2, 0x6b, 0x20, 0xc2, 0xe6, 0xc3, 0x5c, 0xfa, 0x91,
  39480. 0xb1, 0xbd, 0x3b, 0xd3, 0x99, 0xde, 0x59, 0x7a, 0x34, 0x40, 0x56, 0xb0,
  39481. 0x88, 0x02, 0x19, 0xc8, 0xf9, 0xf9, 0x8f, 0xe7, 0x60, 0xfb, 0x42, 0x87,
  39482. 0x57, 0xb4, 0x42, 0xb4, 0x65, 0x94, 0x0a, 0x5f, 0xdb, 0xf5, 0x32, 0xe9,
  39483. 0x49, 0x28, 0xbe, 0xa6, 0x64, 0x0d, 0x6d, 0x08, 0x43, 0x91, 0x16, 0x7a,
  39484. 0x6c, 0xa9, 0x02, 0xe4, 0x84, 0x03, 0x39, 0x48, 0x08, 0xcc, 0xcb, 0x56,
  39485. 0xad, 0x52, 0x95, 0x9e, 0x9a, 0x2b, 0xf1, 0x6d, 0x3f, 0x4b, 0x02, 0xc6,
  39486. 0x52, 0xc7, 0x09, 0x6b, 0x3f, 0xa9, 0x60, 0xe2, 0x19, 0x5d, 0x0a, 0x61,
  39487. 0xcd, 0xc8, 0x36, 0xdb, 0x8e, 0x57, 0xd2, 0x11, 0x49, 0x1c, 0x26, 0x58,
  39488. 0x04, 0x07, 0x32, 0x2a, 0x34, 0xf0, 0x6a, 0x88, 0xcf, 0x63, 0xb7, 0xef,
  39489. 0x7e, 0x93, 0xcc, 0x64, 0x07, 0x14, 0xfa, 0x63, 0x38, 0xdd, 0xc0, 0xf0,
  39490. 0xaa, 0x56, 0xa1, 0xed, 0x16, 0xaa, 0x53, 0x8c, 0x99, 0xc0, 0xd4, 0xda,
  39491. 0x94, 0x58, 0x13, 0xd9, 0x5f, 0x98, 0x9a, 0xa1, 0x57, 0xbd, 0x89, 0xca,
  39492. 0x9d, 0x3e, 0xdf, 0x75, 0x26, 0x29, 0x0f, 0xb2, 0x33, 0x4b, 0x83, 0xb3,
  39493. 0x99, 0x1f, 0x06, 0x5d, 0x10, 0xf5, 0x1c, 0x75, 0x97, 0xec, 0x5b, 0x87,
  39494. 0xc7, 0xf1, 0xd8, 0xbd, 0x0e, 0x4c, 0x1a, 0xb0, 0x59, 0x3b, 0x27, 0x73,
  39495. 0xdc, 0xde, 0xca, 0x0c, 0x2e, 0x1f, 0x42, 0x7f, 0xd8, 0x0f, 0x9b, 0x3f,
  39496. 0x49, 0x3f, 0x63, 0x7d, 0x71, 0xe3, 0x77, 0x79, 0xcc, 0x9c, 0xbf, 0xff,
  39497. 0x23, 0xa9, 0x74, 0xa2, 0xda, 0xb7, 0xca, 0x86, 0x7f, 0x12, 0xc1, 0x1b,
  39498. 0x41, 0x35, 0xb5, 0xc7, 0x10, 0x09, 0xc0, 0xa2, 0x1b, 0x41, 0x31, 0x5e,
  39499. 0x6c, 0x35, 0xb5, 0x63, 0x13, 0x19, 0x61, 0x8e, 0xbd, 0x89, 0xf6, 0x0a,
  39500. 0xbd, 0x16, 0x15, 0xd8, 0xfa, 0xcc, 0x9f, 0x97, 0x02, 0x8f, 0x1b, 0x34,
  39501. 0x40, 0xbc, 0x4a, 0xb1, 0x39, 0x12, 0xf8, 0x66, 0xda, 0x34, 0x03, 0xf2,
  39502. 0x5c, 0x33, 0x9c, 0x63, 0x0b, 0xb6, 0x8f, 0xca, 0x81, 0xa2, 0x4a, 0x43,
  39503. 0xe7, 0xe7, 0x66, 0x41, 0x45, 0x6b, 0x7c, 0xd1, 0x1d, 0xbc, 0x4f, 0x91,
  39504. 0xab, 0x24, 0x0b, 0x9f, 0x60, 0x47, 0x36, 0x04, 0x8b, 0x72, 0xb6, 0x65,
  39505. 0x35, 0xfc, 0xbf, 0xc9, 0x26, 0xaf, 0x84, 0x04, 0x30, 0x32, 0x02, 0xc0,
  39506. 0x94, 0x98, 0xbc, 0x17, 0x33, 0x99, 0xac, 0xb1, 0x4e, 0xdd, 0xf0, 0x46,
  39507. 0x68, 0x6a, 0xac, 0x6d, 0xdb, 0x85, 0xfd, 0xc6, 0x3b, 0xc8, 0x93, 0x89,
  39508. 0xbf, 0xd7, 0xd9, 0x94, 0xe4, 0xa4, 0x37, 0xb9, 0x67, 0x52, 0x84, 0xcf,
  39509. 0x88, 0xba, 0x01, 0x8b, 0xe4, 0xd4, 0x3e, 0xde, 0x94, 0xa1, 0xa9, 0xd8,
  39510. 0x15, 0xb5, 0x6e, 0xa0, 0x62, 0x92, 0x5c, 0xb1, 0x1b, 0xbf, 0x4f, 0xaf,
  39511. 0xf5, 0x99, 0x35, 0xce, 0x7d, 0xa9, 0x4b, 0xa8, 0x60, 0x31, 0xf5, 0x0a,
  39512. 0x83, 0x58, 0xf5, 0x83, 0xde, 0xb2, 0xfe, 0xf3, 0x12, 0x08, 0x3d, 0xe3,
  39513. 0x14, 0x89, 0x17, 0x93, 0x5c, 0x87, 0xe4, 0x89, 0xcb, 0xb7, 0x67, 0x3e,
  39514. 0xea, 0x0e, 0x08, 0x57, 0xf1, 0xca, 0xe0, 0x18, 0xd7, 0xae, 0x5f, 0x9e,
  39515. 0x62, 0x5c, 0xd7, 0x6a, 0x2f, 0xd6, 0x30, 0x67, 0xfb, 0x5e, 0xed, 0xcf,
  39516. 0xa9, 0x88, 0x04, 0x0a, 0xf2, 0x62, 0x50, 0xc5, 0x39, 0xc6, 0xa1, 0x3c,
  39517. 0xe4, 0x9a, 0x81, 0x55, 0x96, 0xca, 0x60, 0xb2, 0x53, 0x62, 0xee, 0xa1,
  39518. 0x1d, 0xfc, 0xd9, 0x5c, 0x51, 0xbf, 0x55, 0x65, 0x1d, 0x13, 0x2a, 0x13,
  39519. 0x58, 0xa3, 0x18, 0x52, 0x6b, 0xb4, 0xae, 0x60, 0x1c, 0x26, 0x3e, 0xb1,
  39520. 0x4c, 0xb1, 0x72, 0x1b, 0x8a, 0x4c, 0xaa, 0xb5, 0x5b, 0x8a, 0x3b, 0x2f,
  39521. 0x1f, 0xc3, 0x29, 0x41, 0xe6, 0x6d, 0xd7, 0x96, 0x26, 0xdd, 0x37, 0x67,
  39522. 0x4f, 0x9d, 0x31, 0xc6, 0x54, 0x51, 0xaa, 0xba, 0x73, 0xae, 0xd2, 0x00,
  39523. 0x0b, 0x05, 0x98, 0x73, 0xd6, 0x9c, 0xb4, 0x2e, 0x23, 0xd0, 0xc3, 0xac,
  39524. 0x46, 0x6f, 0x3e, 0x05, 0x43, 0xf8, 0x96, 0xa0, 0xe0, 0xfe, 0x17, 0x3f,
  39525. 0xfa, 0xc2, 0xc3, 0xf6, 0x1a, 0x46, 0xd0, 0x05, 0x53, 0x0e, 0xea, 0xd8,
  39526. 0xba, 0xa3, 0xab, 0xb6, 0x58, 0xd1, 0x40, 0x1c, 0x97, 0x38, 0xd4, 0x77,
  39527. 0x58, 0x03, 0xf5, 0x8a, 0xc7, 0x48, 0x19, 0x71, 0x71, 0xb5, 0x4b, 0x08,
  39528. 0x85, 0x35, 0x1c, 0xdf, 0xbd, 0xa9, 0xc9, 0xd1, 0x40, 0x62, 0xa3, 0xd6,
  39529. 0x3b, 0xa1, 0xf7, 0x4e, 0xc6, 0xfe, 0xc4, 0x07, 0x2f, 0xf5, 0xc9, 0x0c,
  39530. 0xb6, 0xa0, 0xb3, 0x25, 0x3e, 0x2a, 0x07, 0xe3, 0x63, 0xe3, 0x9e, 0x8d,
  39531. 0x0d, 0x7a, 0x70, 0x1e, 0x65, 0x95, 0x47, 0x37, 0xa8, 0xd2, 0x35, 0x09,
  39532. 0x09, 0x70, 0xf5, 0xc9, 0xc9, 0x30, 0x95, 0xd9, 0xf2, 0x5d, 0x10, 0x3c,
  39533. 0xc3, 0x66, 0x66, 0xb6, 0xdc, 0x14, 0xf6, 0x91, 0xc2, 0x7b, 0x4b, 0x71,
  39534. 0x42, 0xf9, 0x35, 0xe7, 0x08, 0x1e, 0xb6, 0x9a, 0x5c, 0x0e, 0x8b, 0x41,
  39535. 0x44, 0x7f, 0xad, 0xca, 0x8a, 0x4b, 0x6a, 0x02, 0x81, 0x96, 0xe7, 0xe1,
  39536. 0xb0, 0x5b, 0xaf, 0xf2, 0x17, 0x44, 0x7f, 0xd1, 0x49, 0x77, 0xfd, 0x07,
  39537. 0x59, 0x53, 0x8e, 0x51, 0xac, 0x0f, 0x0c, 0xb4, 0xa3, 0xf6, 0x24, 0x16,
  39538. 0x47, 0xf3, 0xa4, 0x36, 0x17, 0x3e, 0x01, 0x1e, 0xf1, 0xec, 0x78, 0x4a,
  39539. 0xcb, 0xbd, 0x2a, 0xfd, 0x01, 0xdd, 0xa5, 0xad, 0x7b, 0xef, 0x5e, 0x56,
  39540. 0xb2, 0x60, 0xb4, 0xf2, 0x27, 0xc8, 0x9b, 0x5b, 0x31, 0x49, 0x54, 0xbc,
  39541. 0x69, 0x9b, 0xc6, 0x1a, 0x79, 0xe7, 0xd4, 0x46, 0xc8, 0x50, 0xc3, 0xaa,
  39542. 0xfc, 0xb5, 0x28, 0x87, 0x1e, 0xa0, 0x0c, 0xc6, 0x1a, 0xa7, 0x34, 0xd6,
  39543. 0xbb, 0x9d, 0x9c, 0x0d, 0x90, 0x6f, 0x1a, 0x3c, 0xdc, 0x3b, 0x95, 0xc4,
  39544. 0x38, 0x25, 0x7a, 0xc6, 0x46, 0x82, 0x9f, 0x68, 0xca, 0x6a, 0x63, 0xa7,
  39545. 0x99, 0xfe, 0x64, 0xe6, 0x6f, 0x11, 0xcd, 0x2c, 0x76, 0x1e, 0xe6, 0x08,
  39546. 0xb8, 0x33, 0x64, 0x43, 0x51, 0xbd, 0x52, 0xf7, 0x05, 0x06, 0xd5, 0xcc,
  39547. 0x6a, 0xde, 0x1a, 0xa2, 0xbe, 0xf8, 0x8c, 0x44, 0x5e, 0x2d, 0xc2, 0x28,
  39548. 0xcd, 0x9a, 0x53, 0x04, 0x96, 0xcc, 0x1e, 0xbb, 0x96, 0x07, 0xc9, 0x17,
  39549. 0x04, 0xf8, 0xd8, 0xd9, 0xdd, 0x35, 0x35, 0x3d, 0x53, 0x30, 0x60, 0xb3,
  39550. 0x87, 0x5d, 0xf3, 0xe5, 0xa7, 0x20, 0x30, 0x9d, 0xb0, 0x5b, 0xc4, 0x36,
  39551. 0xf7, 0xd7, 0xb6, 0x3e, 0x44, 0x98, 0x99, 0xe7, 0xc3, 0x29, 0xcb, 0x70,
  39552. 0xc4, 0x91, 0x8b, 0xfc, 0x63, 0x60, 0x29, 0x95, 0xeb, 0x61, 0x7f, 0xdf,
  39553. 0xf7, 0x3a, 0x69, 0x3a, 0xeb, 0xa1, 0x73, 0x1d, 0x13, 0x18, 0x29, 0x2c,
  39554. 0x89, 0x82, 0x56, 0x42, 0xe7, 0xa3, 0xba, 0xe9, 0x59, 0x2e, 0xfd, 0xff,
  39555. 0xb6, 0xf7, 0xbd, 0x2a, 0xc9, 0xff, 0x4c, 0x63, 0xef, 0x54, 0x63, 0x82,
  39556. 0x7c, 0xa5, 0x11, 0x44, 0xc7, 0x68, 0xf5, 0x7b, 0x44, 0x2c, 0xee, 0xab,
  39557. 0xa3, 0x84, 0x5a, 0x99, 0x28, 0x98, 0x97, 0x2e, 0x8b, 0x07, 0x09, 0x6c,
  39558. 0xea, 0xc1, 0x81, 0x0b, 0xe0, 0xc4, 0xb7, 0xc2, 0x73, 0xbe, 0x8b, 0x72,
  39559. 0xf8, 0xc9, 0x8d, 0x50, 0x28, 0xf2, 0x95, 0x54, 0x8a, 0x3b, 0x23, 0x86,
  39560. 0xc4, 0xe8, 0xe8, 0xe5, 0x45, 0x0d, 0xdf, 0xa3, 0xe6, 0x00, 0x71, 0xe8,
  39561. 0x20, 0xd2, 0x6d, 0x22, 0x23, 0xaf, 0x37, 0x04, 0x55, 0x05, 0x8d, 0xc9,
  39562. 0x38, 0x38, 0x12, 0x4c, 0x9f, 0x28, 0x56, 0x14, 0x76, 0xe5, 0x10, 0x54,
  39563. 0xd9, 0x68, 0xca, 0xc3, 0x97, 0x9f, 0xd2, 0x25, 0x2c, 0x0d, 0xa0, 0xff,
  39564. 0xea, 0xab, 0x61, 0xd2, 0xb2, 0x06, 0xc2, 0x93, 0xfd, 0x5a, 0xfe, 0xe3,
  39565. 0x98, 0xbf, 0x37, 0x2e, 0xa5, 0x74, 0x56, 0xd0, 0x7a, 0x5a, 0x23, 0x3b,
  39566. 0xd2, 0xa0, 0x1f, 0x4b, 0xeb, 0x7f, 0x5a, 0xc5, 0x51, 0x79, 0xf6, 0x95,
  39567. 0x19, 0x50, 0xb1, 0x6a, 0x80, 0xcb, 0xcf, 0x19, 0xa4, 0x67, 0xf4, 0x08,
  39568. 0x0f, 0x6a, 0xd9, 0x3f, 0x15, 0x96, 0x2c, 0x6d, 0xd5, 0x69, 0x7a, 0x56,
  39569. 0x4d, 0x17, 0xc8, 0xcb, 0xba, 0x9b, 0x6e, 0x65, 0xa2, 0x3d, 0x66, 0xed,
  39570. 0xea, 0xe2, 0x54, 0x88, 0x6c, 0xc1, 0x1a, 0x11, 0xde, 0x4e, 0x0c, 0x8a,
  39571. 0x42, 0x04, 0xe1, 0x77, 0xc3, 0x0c, 0xff, 0x10, 0x7d, 0x4a, 0x45, 0x3f,
  39572. 0xb8, 0x40, 0xf9, 0x75, 0x76, 0x9f, 0x65, 0x42, 0x2f, 0x78, 0x5b, 0x0b,
  39573. 0x32, 0xbc, 0x45, 0xfc, 0xd4, 0x29, 0x49, 0x34, 0x76, 0xda, 0x5f, 0xe8,
  39574. 0x39, 0x35, 0x9e, 0xba, 0x7f, 0x19, 0x7e, 0x14, 0xe6, 0x71, 0x9c, 0x72,
  39575. 0x6a, 0xce, 0xcc, 0xa6, 0x72, 0x73, 0x3f, 0x4e, 0x9b, 0x9e, 0x94, 0x0c,
  39576. 0xce, 0x00, 0x15, 0xb4, 0x50, 0xff, 0xcf, 0xcd, 0x78, 0xd3, 0x08, 0x0e,
  39577. 0x95, 0x48, 0x24, 0x13, 0x16, 0x54, 0xb4, 0xe0, 0xa9, 0x29, 0xa3, 0x05,
  39578. 0x77, 0x2f, 0x5d, 0x47, 0x6a, 0xa5, 0xb0, 0x4e, 0xf3, 0xa9, 0x4a, 0x82,
  39579. 0xb9, 0x2c, 0x26, 0x07, 0x9c, 0x33, 0xc6, 0x68, 0xc2, 0xe0, 0xc0, 0x7d,
  39580. 0x70, 0x48, 0x74, 0xb9, 0xf5, 0x1e, 0x6c, 0x15, 0x7f, 0xba, 0xe5, 0xa1,
  39581. 0xb4, 0x36, 0x41, 0x20, 0xf4, 0x2d, 0x97, 0x27, 0x0b, 0x10, 0x30, 0x57,
  39582. 0x7f, 0x38, 0x66, 0xe1, 0xc4, 0xf6, 0xa4, 0xc9, 0x8d, 0xbc, 0x2b, 0x4f,
  39583. 0x14, 0xb3, 0xf0, 0x1e, 0x80, 0x70, 0xc0, 0x0f, 0x69, 0x06, 0xe7, 0x95,
  39584. 0xd1, 0x53, 0x65, 0x49, 0x1c, 0xa8, 0xfa, 0x9e, 0x2b, 0xcc, 0x33, 0x71,
  39585. 0x76, 0xa4, 0x0b, 0x4a, 0xc7, 0xea, 0xa0, 0xfa, 0x1b, 0x2b, 0xfb, 0xa5,
  39586. 0x59, 0x06, 0x2a, 0xef, 0x4b, 0xbf, 0x05, 0x4b, 0x87, 0x70, 0x3c, 0xde,
  39587. 0xc7, 0xb2, 0x4f, 0xf2, 0x5b, 0x1a, 0xbe, 0xda, 0x04, 0x31, 0x57, 0xff,
  39588. 0xf2, 0xa5, 0x43, 0x12, 0xff, 0x8d, 0xf4, 0x99, 0x05, 0xe1, 0x34, 0xa9,
  39589. 0xb9, 0x0a, 0xb3, 0x1f, 0x3d, 0x6d, 0x0d, 0xb7, 0xd3, 0x35, 0x0b, 0x04,
  39590. 0x44, 0x77, 0x60, 0xc0, 0x96, 0x99, 0x7b, 0xa8, 0x8e, 0x79, 0x4a, 0x96,
  39591. 0x24, 0xef, 0xb1, 0xf4, 0x8a, 0x2f, 0x3e, 0x08, 0xf3, 0x3d, 0xf2, 0xfe,
  39592. 0x5f, 0x0a, 0xf7, 0x0a, 0xf5, 0xd8, 0xf2, 0xa0, 0x1b, 0xe7, 0x9e, 0xc9,
  39593. 0x0b, 0xcf, 0x58, 0x97, 0x92, 0x90, 0xad, 0x3d, 0xfc, 0x42, 0xc1, 0x7f,
  39594. 0x39, 0xe8, 0xd1, 0x35, 0x14, 0x8a, 0xb3, 0x77, 0xb1, 0xa9, 0xdb, 0xb4,
  39595. 0x3a, 0x3d, 0xeb, 0x59, 0x0b, 0x5b, 0x3a, 0x63, 0x54, 0x70, 0xda, 0xf0,
  39596. 0xf0, 0xb9, 0xe6, 0x07, 0x69, 0x27, 0x9d, 0xc6, 0xb6, 0x00, 0x2d, 0xd6,
  39597. 0xc7, 0xd7, 0x2e, 0xf8, 0x9c, 0xfe, 0x4c, 0xfb, 0xc0, 0x7b, 0xbf, 0xa2,
  39598. 0x25, 0xb8, 0x2a, 0x5c, 0x06, 0xca, 0x12, 0x2c, 0x96, 0xa4, 0x27, 0xa6,
  39599. 0x73, 0x0b, 0xb8, 0x42, 0x93, 0x51, 0x87, 0xfe, 0xe6, 0x8f, 0xca, 0x00,
  39600. 0x53, 0xdc, 0xc0, 0x38, 0x03, 0x9e, 0x66, 0x13, 0x84, 0x68, 0xe7, 0x04,
  39601. 0x93, 0x79, 0x0c, 0x3e, 0x4c, 0x90, 0xe2, 0xf7, 0x81, 0x15, 0x49, 0x05,
  39602. 0xe1, 0x8f, 0xe6, 0xfc, 0xc8, 0x40, 0xae, 0x3d, 0x7a, 0x16, 0xec, 0xc6,
  39603. 0x39, 0xa5, 0x04, 0x95, 0x35, 0xac, 0xdd, 0x0d, 0x19, 0xd6, 0xa9, 0xd9,
  39604. 0xd2, 0x53, 0x71, 0x31, 0x38, 0xa2, 0xf1, 0x9c, 0x13, 0x2c, 0x8c, 0x21,
  39605. 0x9c, 0x3a, 0x1b, 0xf2, 0xd8, 0x4c, 0xeb, 0xe9, 0x8b, 0x27, 0x52, 0xd3,
  39606. 0x6c, 0x01, 0xc0, 0x60, 0x32, 0x8c, 0x6e, 0xfb, 0xd6, 0xd6, 0x1b, 0xc6,
  39607. 0x93, 0xff, 0xdc, 0xdb, 0x38, 0xf5, 0x0e, 0xd5, 0x15, 0xcd, 0x65, 0x76,
  39608. 0x78, 0x42, 0x13, 0x37, 0x6b, 0x2e, 0xe8, 0xe2, 0x54, 0x4d, 0x45, 0x34,
  39609. 0x73, 0x1b, 0x61, 0x35, 0x2c, 0xf7, 0x20, 0x3e, 0xe9, 0x7c, 0xf0, 0xf3,
  39610. 0xba, 0x41, 0xfc, 0x49, 0xe4, 0x5d, 0xd4, 0xb8, 0x07, 0x15, 0x7b, 0x16,
  39611. 0xc7, 0x7f, 0x78, 0xef, 0xd6, 0x53, 0x3f, 0xe4, 0xa6, 0x33, 0xcf, 0xcc,
  39612. 0x78, 0x53, 0x0c, 0x59, 0xf7, 0x28, 0xa5, 0x83, 0x2b, 0x5a, 0xd3, 0xd6,
  39613. 0xb7, 0xb2, 0xd1, 0x73, 0x63, 0xa9, 0xad, 0x16, 0xf2, 0xed, 0x48, 0x6e,
  39614. 0x88, 0x22, 0xbd, 0x16, 0x9d, 0x6a, 0xc2, 0x48, 0x83, 0xdf, 0x40, 0xb7,
  39615. 0x0a, 0x50, 0x23, 0x3d, 0x58, 0x50, 0x00, 0x02, 0x04, 0xd2, 0x31, 0x72,
  39616. 0x28, 0x7b, 0x10, 0x96, 0xe0, 0xe7, 0x3f, 0xe0, 0xd0, 0x61, 0x70, 0x5c,
  39617. 0x0a, 0xdb, 0xc0, 0x7b, 0xea, 0xef, 0xba, 0xc0, 0x90, 0xe0, 0xf9, 0x0e,
  39618. 0x83, 0x8c, 0x3b, 0x05, 0x2b, 0xb6, 0xcb, 0xbb, 0x37, 0xa1, 0xd3, 0x28,
  39619. 0x02, 0x40, 0xe3, 0x76, 0xbf, 0x27, 0x0b, 0x4f, 0x82, 0xb9, 0x22, 0xee,
  39620. 0x0b, 0x3a, 0xcb, 0xcc, 0x56, 0x13, 0x51, 0xb8, 0xb6, 0x2d, 0xd3, 0x6c,
  39621. 0x96, 0x10, 0xd9, 0x51, 0x24, 0x7b, 0x2b, 0xb8, 0x7b, 0xbd, 0x8d, 0xd9,
  39622. 0xf2, 0x50, 0x61, 0xbb, 0x0c, 0xb7, 0x71, 0x65, 0x3a, 0x25, 0x18, 0x09,
  39623. 0x1a, 0x9d, 0x41, 0xf4, 0xdb, 0x5a, 0x1c, 0x61, 0x0a, 0xbb, 0x43, 0x27,
  39624. 0x8a, 0xa8, 0x83, 0x60, 0x8c, 0x5d, 0x4c, 0x9b, 0xa9, 0xe5, 0xa7, 0x67,
  39625. 0x99, 0x98, 0xdc, 0x7a, 0x3a, 0x55, 0x0d, 0x25, 0x69, 0x47, 0x21, 0xb1,
  39626. 0xd7, 0x0c, 0x0c, 0x43, 0x58, 0xc9, 0xbf, 0x74, 0x91, 0x1b, 0x2b, 0xf3,
  39627. 0x29, 0x8d, 0x10, 0x41, 0xaf, 0xdd, 0x42, 0x0a, 0x71, 0xe3, 0xb8, 0x4d,
  39628. 0x3a, 0xf3, 0x9c, 0x5a, 0x46, 0x4e, 0x70, 0xbe, 0xdb, 0x0d, 0x03, 0xee,
  39629. 0xcb, 0xfb, 0x61, 0x45, 0xbd, 0x25, 0xb4, 0x72, 0xd1, 0x51, 0x03, 0x19,
  39630. 0x82, 0x53, 0x83, 0x18, 0xab, 0xa3, 0x6c, 0x9e, 0xa2, 0xe9, 0x15, 0xb1,
  39631. 0x74, 0x61, 0xa1, 0xaf, 0x09, 0x4b, 0x4a, 0x34, 0x9b, 0xd0, 0xd2, 0x80,
  39632. 0x43, 0xd9, 0x90, 0x53, 0x71, 0x38, 0xb9, 0x80, 0x58, 0x1b, 0x9f, 0x9e,
  39633. 0xfe, 0x07, 0x1b, 0x33, 0x24, 0xb2, 0x58, 0x7f, 0x01, 0xbe, 0xe8, 0x25,
  39634. 0x53, 0x08, 0x06, 0x77, 0x7d, 0x5a, 0x16, 0x83, 0x67, 0x91, 0x0b, 0xa2,
  39635. 0xd2, 0x1e, 0x5f, 0x9c, 0x39, 0xda, 0x57, 0xbc, 0x67, 0xc5, 0x39, 0xbe,
  39636. 0xb9, 0x73, 0x03, 0x19, 0x97, 0x34, 0x4f, 0x1e, 0x6b, 0x4d, 0x87, 0xef,
  39637. 0x79, 0x4f, 0xd1, 0xdd, 0x80, 0x13, 0xbe, 0x3b, 0x0f, 0xea, 0x77, 0x9a,
  39638. 0x1a, 0x46, 0x63, 0xc5, 0x2f, 0x93, 0xfe, 0x18, 0x71, 0xfb, 0x70, 0xbf,
  39639. 0x85, 0x3b, 0x3e, 0x54, 0xe6, 0xf8, 0xe0, 0xb9, 0xd0, 0x9d, 0xf5, 0x2b,
  39640. 0x12, 0x22, 0x39, 0x6a, 0x8d, 0x13, 0xa1, 0x3a, 0x95, 0xd0, 0xe7, 0x07,
  39641. 0xa4, 0x2c, 0x33, 0xba, 0x43, 0x1d, 0xd8, 0xb5, 0xd0, 0x8e, 0x6c, 0x85,
  39642. 0x6f, 0xf8, 0x8f, 0xd3, 0x72, 0x65, 0xc1, 0xff, 0x8f, 0xf6, 0xb5, 0x19,
  39643. 0x59, 0x34, 0xf9, 0xe8, 0xdb, 0xf3, 0x10, 0x68, 0xbd, 0xd5, 0x59, 0xf7,
  39644. 0xe5, 0xf2, 0x84, 0x98, 0x8d, 0xd6, 0x6f, 0xcc, 0xde, 0xc5, 0xee, 0xf7,
  39645. 0x16, 0xca, 0xec, 0xc4, 0x00, 0x89, 0x2e, 0x0d, 0x0d, 0xb6, 0xa8, 0xe0,
  39646. 0x9a, 0xb0, 0xe5, 0x8e, 0xb6, 0x64, 0x47, 0x7d, 0x01, 0x59, 0x8a, 0x90,
  39647. 0xa6, 0x9b, 0x2b, 0x63, 0xad, 0x70, 0xc8, 0x07, 0x36, 0x3e, 0xa9, 0x8f,
  39648. 0xd9, 0xc2, 0xf7, 0x4b, 0xec, 0x95, 0x53, 0xec, 0x6b, 0x2d, 0x1f, 0xb5,
  39649. 0x91, 0xbf, 0x9f, 0xc5, 0x85, 0x61, 0x3a, 0xc7, 0x5c, 0x15, 0x2a, 0x0b,
  39650. 0x4b, 0x3c, 0x38, 0x6d, 0xc9, 0x2c, 0x91, 0x11, 0xc6, 0x6b, 0x44, 0x71,
  39651. 0x9f, 0x89, 0xd5, 0xde, 0x27, 0x99, 0x81, 0xa2, 0x59, 0x8b, 0x57, 0x97,
  39652. 0x83, 0x46, 0x33, 0xe1, 0x8c, 0xdf, 0xcf, 0x5b, 0x6b, 0xb3, 0x0e, 0x17,
  39653. 0x1a, 0xb8, 0x7d, 0x6e, 0x71, 0xe5, 0xc8, 0x4c, 0xa9, 0xe2, 0x52, 0x81,
  39654. 0xf6, 0x2f, 0x3a, 0xef, 0x5a, 0x1b, 0x6b, 0x7b, 0x61, 0x51, 0xcb, 0xd5,
  39655. 0x7b, 0x5f, 0xf0, 0x1c, 0xb8, 0xeb, 0x9a, 0xe4, 0x0a, 0x6e, 0x53, 0x59,
  39656. 0x2e, 0x2d, 0x78, 0x27, 0xb7, 0x47, 0x35, 0x1a, 0x01, 0x25, 0x0a, 0xcc,
  39657. 0x67, 0xae, 0xda, 0xaf, 0xfe, 0x22, 0x63, 0xe8, 0xa2, 0x1c, 0x34, 0xe6,
  39658. 0x6b, 0x73, 0xcf, 0x6f, 0x3e, 0x0a, 0x4a, 0x36, 0xbc, 0xda, 0x43, 0xbc,
  39659. 0x5e, 0x9c, 0x91, 0xe4, 0x8b, 0x34, 0x2e, 0x09, 0x87, 0x69, 0x96, 0x93,
  39660. 0xb4, 0xff, 0x97, 0xbc, 0x4e, 0xd6, 0xa2, 0xb4, 0x16, 0x78, 0x7c, 0x62,
  39661. 0xd0, 0x78, 0x3f, 0x37, 0xdb, 0xf2, 0x92, 0xad, 0x9b, 0x51, 0x77, 0x08,
  39662. 0x19, 0xd2, 0x09, 0x12, 0xf7, 0x52, 0xe8, 0xc8, 0xb2, 0xfb, 0x6f, 0xcd,
  39663. 0x05, 0x5b, 0xd2, 0x8e, 0x0d, 0x6e, 0x0c, 0x16, 0x5b, 0x8a, 0xc2, 0x09,
  39664. 0x13, 0x3b, 0x69, 0x85, 0xbd, 0xc0, 0xcc, 0x2b, 0x48, 0x65, 0xa7, 0xc1,
  39665. 0xc3, 0xe0, 0xea, 0x14, 0x67, 0x6f, 0xa4, 0xb8, 0xc6, 0xf0, 0x12, 0x3e,
  39666. 0x96, 0x0d, 0x23, 0x2b, 0x37, 0x87, 0x8d, 0xc8, 0xf7, 0x00, 0x00, 0x00,
  39667. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39668. 0x00, 0x00, 0x00, 0x03, 0x0b, 0x13, 0x1a, 0x1d, 0x25
  39669. };
  39670. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39671. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_sig[] = {
  39672. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  39673. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  39674. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  39675. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  39676. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  39677. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  39678. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  39679. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  39680. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  39681. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  39682. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  39683. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  39684. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  39685. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  39686. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  39687. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  39688. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  39689. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  39690. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  39691. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  39692. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  39693. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  39694. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  39695. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  39696. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  39697. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  39698. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  39699. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  39700. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  39701. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  39702. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  39703. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  39704. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  39705. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  39706. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  39707. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  39708. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  39709. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  39710. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  39711. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  39712. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  39713. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  39714. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  39715. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  39716. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  39717. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  39718. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  39719. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  39720. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  39721. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  39722. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  39723. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  39724. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  39725. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  39726. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  39727. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  39728. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  39729. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  39730. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  39731. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  39732. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  39733. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  39734. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  39735. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  39736. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  39737. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  39738. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  39739. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  39740. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  39741. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  39742. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  39743. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  39744. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  39745. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  39746. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  39747. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  39748. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  39749. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  39750. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  39751. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  39752. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  39753. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  39754. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  39755. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  39756. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  39757. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  39758. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  39759. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  39760. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  39761. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  39762. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  39763. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  39764. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  39765. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  39766. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  39767. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  39768. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  39769. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  39770. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  39771. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  39772. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  39773. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  39774. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  39775. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  39776. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  39777. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  39778. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  39779. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  39780. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  39781. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  39782. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  39783. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  39784. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  39785. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  39786. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  39787. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  39788. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  39789. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  39790. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  39791. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  39792. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  39793. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  39794. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  39795. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  39796. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  39797. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  39798. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  39799. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  39800. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  39801. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  39802. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  39803. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  39804. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  39805. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  39806. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  39807. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  39808. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  39809. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  39810. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  39811. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  39812. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  39813. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  39814. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  39815. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  39816. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  39817. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  39818. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  39819. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  39820. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  39821. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  39822. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  39823. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  39824. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  39825. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  39826. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  39827. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  39828. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  39829. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  39830. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  39831. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  39832. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  39833. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  39834. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  39835. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  39836. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  39837. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  39838. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  39839. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  39840. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  39841. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  39842. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  39843. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  39844. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  39845. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  39846. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  39847. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  39848. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  39849. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  39850. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  39851. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  39852. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  39853. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  39854. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  39855. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  39856. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  39857. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  39858. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  39859. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  39860. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  39861. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  39862. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  39863. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  39864. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  39865. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  39866. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  39867. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  39868. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  39869. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  39870. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  39871. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  39872. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  39873. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  39874. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  39875. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  39876. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  39877. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  39878. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  39879. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  39880. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  39881. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  39882. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  39883. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  39884. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  39885. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  39886. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  39887. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  39888. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  39889. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  39890. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  39891. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  39892. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  39893. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  39894. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  39895. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  39896. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  39897. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  39898. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  39899. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  39900. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  39901. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  39902. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  39903. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  39904. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  39905. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  39906. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  39907. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  39908. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  39909. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  39910. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  39911. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  39912. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  39913. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  39914. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  39915. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  39916. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  39917. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  39918. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  39919. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  39920. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  39921. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  39922. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  39923. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  39924. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  39925. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  39926. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  39927. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  39928. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  39929. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  39930. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  39931. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  39932. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  39933. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  39934. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  39935. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  39936. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  39937. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  39938. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  39939. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  39940. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  39941. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  39942. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  39943. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  39944. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  39945. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  39946. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  39947. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  39948. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  39949. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  39950. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  39951. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  39952. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  39953. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  39954. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  39955. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  39956. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  39957. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  39958. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  39959. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  39960. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  39961. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  39962. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  39963. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  39964. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  39965. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  39966. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  39967. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  39968. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  39969. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  39970. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  39971. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  39972. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  39973. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  39974. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  39975. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  39976. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  39977. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  39978. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  39979. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  39980. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  39981. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  39982. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  39983. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  39984. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  39985. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  39986. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  39987. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  39988. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  39989. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  39990. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  39991. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  39992. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  39993. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  39994. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  39995. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  39996. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  39997. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  39998. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  39999. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  40000. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  40001. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40002. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28
  40003. };
  40004. #endif
  40005. wc_test_ret_t ret;
  40006. ret = dilithium_param_vfy_test(WC_ML_DSA_65, ml_dsa_65_pub_key,
  40007. (word32)sizeof(ml_dsa_65_pub_key), ml_dsa_65_sig,
  40008. (word32)sizeof(ml_dsa_65_sig));
  40009. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40010. if (ret == 0) {
  40011. ret = dilithium_param_vfy_test(WC_ML_DSA_65_DRAFT,
  40012. ml_dsa_65_draft_pub_key, (word32)sizeof(ml_dsa_65_draft_pub_key),
  40013. ml_dsa_65_draft_sig, (word32)sizeof(ml_dsa_65_draft_sig));
  40014. }
  40015. #endif
  40016. return ret;
  40017. }
  40018. #endif
  40019. #ifndef WOLFSSL_NO_ML_DSA_87
  40020. static wc_test_ret_t dilithium_param_87_vfy_test(void)
  40021. {
  40022. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_pub_key[] = {
  40023. 0x8a, 0x66, 0xe3, 0x6e, 0x3c, 0x11, 0x70, 0x9f, 0x82, 0xdd, 0xeb, 0x9e,
  40024. 0xc0, 0xd7, 0x25, 0x87, 0x0c, 0x65, 0x07, 0x9d, 0x47, 0x39, 0x5d, 0x04,
  40025. 0x42, 0x5c, 0xd6, 0x0a, 0xdc, 0x39, 0x44, 0x04, 0xd9, 0x79, 0x43, 0x87,
  40026. 0x98, 0x64, 0x88, 0x82, 0x3a, 0x31, 0xbd, 0xec, 0x66, 0xcb, 0x01, 0x90,
  40027. 0xf9, 0x85, 0xcc, 0xde, 0x54, 0x69, 0x7d, 0x84, 0xb3, 0x84, 0x3c, 0x42,
  40028. 0x0d, 0x09, 0x63, 0xdb, 0xe6, 0x5d, 0xc2, 0x8a, 0xcf, 0xe1, 0xf4, 0x86,
  40029. 0x13, 0x05, 0x09, 0x9a, 0x4d, 0x05, 0xd4, 0x31, 0xe7, 0x27, 0x39, 0xfd,
  40030. 0x3a, 0xdb, 0x63, 0x9f, 0x1c, 0x67, 0x0b, 0x01, 0xec, 0xf9, 0xff, 0xf3,
  40031. 0xda, 0xa9, 0xf4, 0x9a, 0x59, 0x52, 0x76, 0xc2, 0xd2, 0xd5, 0xdd, 0x8d,
  40032. 0xb1, 0xa2, 0xef, 0xb3, 0x73, 0x99, 0xe3, 0xcd, 0x1c, 0xf5, 0xca, 0x6e,
  40033. 0x39, 0xfa, 0x26, 0x83, 0x45, 0xe7, 0xd0, 0x9c, 0x1b, 0xf7, 0xb2, 0x64,
  40034. 0xf1, 0x70, 0x00, 0x10, 0xc0, 0x7c, 0x7f, 0xb2, 0x32, 0xce, 0x6d, 0x71,
  40035. 0xa5, 0x43, 0x7c, 0x40, 0x71, 0x09, 0x54, 0x74, 0xac, 0xb5, 0xeb, 0xe0,
  40036. 0x04, 0x02, 0xe5, 0x82, 0x4d, 0x5a, 0x85, 0x1e, 0x19, 0x86, 0x39, 0x33,
  40037. 0x92, 0x2f, 0xa9, 0xa8, 0x10, 0xd2, 0x31, 0x60, 0x16, 0x08, 0x99, 0xe3,
  40038. 0x2c, 0x93, 0x13, 0xc4, 0x4b, 0x10, 0xe0, 0x42, 0xca, 0x3f, 0x32, 0xa7,
  40039. 0xa4, 0xd2, 0xfc, 0x9c, 0x93, 0xb6, 0x5f, 0xe2, 0x5b, 0x6e, 0x40, 0x0c,
  40040. 0x63, 0xf8, 0xf8, 0xe1, 0x2d, 0xcd, 0x86, 0x07, 0x79, 0xdb, 0x61, 0xad,
  40041. 0x24, 0xfd, 0x1e, 0x66, 0x3e, 0x8d, 0x76, 0xba, 0x98, 0x8e, 0x94, 0xc7,
  40042. 0x57, 0xb1, 0x65, 0xce, 0x4f, 0x97, 0xfa, 0x34, 0x7c, 0x97, 0x6b, 0xcd,
  40043. 0x3c, 0x42, 0x81, 0xa4, 0xd1, 0x75, 0xeb, 0x6d, 0x0c, 0x31, 0x0e, 0x6f,
  40044. 0xd5, 0x75, 0xe7, 0xff, 0x83, 0xdd, 0x7a, 0x4d, 0x83, 0x67, 0xa7, 0x4b,
  40045. 0xc1, 0x74, 0xad, 0x37, 0x38, 0x99, 0xe0, 0xf5, 0x5a, 0x44, 0x36, 0xa2,
  40046. 0x20, 0x2b, 0xfc, 0xc9, 0xfa, 0x68, 0xcb, 0xf0, 0x6f, 0x0a, 0x46, 0x1d,
  40047. 0xb5, 0xca, 0x5b, 0x96, 0x1b, 0x3a, 0xaf, 0x7d, 0x01, 0x7a, 0xd2, 0x09,
  40048. 0xcc, 0xd4, 0xe4, 0xb1, 0x49, 0x34, 0x56, 0x68, 0x9c, 0x0f, 0x23, 0xe9,
  40049. 0xb3, 0x4b, 0xed, 0x3d, 0xe7, 0x8d, 0x19, 0x6e, 0xe6, 0xfa, 0x06, 0x55,
  40050. 0xb8, 0x06, 0x4d, 0xa8, 0x45, 0x20, 0x91, 0xf7, 0xfa, 0x0b, 0x6b, 0xce,
  40051. 0x55, 0xa7, 0x14, 0x1b, 0xf9, 0xea, 0xc5, 0x79, 0x78, 0xf7, 0x3a, 0xd9,
  40052. 0xfc, 0x07, 0x43, 0x06, 0x90, 0x94, 0x5e, 0xc9, 0x48, 0x51, 0xe5, 0x96,
  40053. 0x68, 0x78, 0xc8, 0xcb, 0xd1, 0xf3, 0x65, 0xef, 0x14, 0x91, 0xa3, 0xca,
  40054. 0x8b, 0x77, 0x40, 0x84, 0xf4, 0x2e, 0xe7, 0x56, 0xe3, 0xab, 0xa0, 0xa8,
  40055. 0x61, 0x93, 0x17, 0x95, 0x9e, 0xff, 0x3a, 0xd4, 0x12, 0xea, 0x13, 0xe6,
  40056. 0x82, 0x16, 0xed, 0x14, 0x70, 0x91, 0xcc, 0x72, 0x58, 0x99, 0xa1, 0x7f,
  40057. 0xf3, 0x84, 0x10, 0xf4, 0x01, 0x0d, 0x05, 0x45, 0x4d, 0xca, 0x05, 0x03,
  40058. 0x75, 0x7e, 0xbb, 0x44, 0x2e, 0xf5, 0xee, 0xed, 0x64, 0x9b, 0xd3, 0xde,
  40059. 0x3e, 0xfc, 0x31, 0x8c, 0xca, 0x23, 0x66, 0x25, 0xac, 0x5f, 0x0f, 0x33,
  40060. 0x0f, 0xd2, 0xe9, 0xc9, 0x96, 0x2a, 0xe2, 0xb8, 0xed, 0x93, 0xd3, 0x78,
  40061. 0xd8, 0x81, 0xe4, 0x52, 0x9a, 0xc6, 0x64, 0x1d, 0x2d, 0x5f, 0x93, 0x9a,
  40062. 0x2e, 0x73, 0xc4, 0x17, 0xae, 0xc6, 0x08, 0x0d, 0x2d, 0xe9, 0x4b, 0x10,
  40063. 0x29, 0xa8, 0x4e, 0x8c, 0x08, 0x59, 0x87, 0x10, 0x0d, 0x5d, 0xfa, 0xec,
  40064. 0xd6, 0x42, 0xf6, 0x5c, 0xa4, 0x0d, 0xaa, 0x64, 0x8e, 0x20, 0xa5, 0x50,
  40065. 0x9f, 0x0b, 0x85, 0x37, 0x57, 0x15, 0x7c, 0xb1, 0xe4, 0xdd, 0xd5, 0x19,
  40066. 0x3b, 0x10, 0x7d, 0x22, 0xdb, 0x53, 0x8b, 0x7b, 0x32, 0xf7, 0xf2, 0x24,
  40067. 0x92, 0xb2, 0x05, 0xd1, 0xfd, 0xfc, 0x11, 0xd6, 0xfd, 0x3c, 0x8d, 0xd7,
  40068. 0xb0, 0x58, 0x50, 0x06, 0x84, 0x61, 0xa6, 0x78, 0x04, 0x1d, 0x7f, 0x92,
  40069. 0x0e, 0x8b, 0xb3, 0x63, 0x43, 0xc5, 0x30, 0x4c, 0xce, 0x2b, 0x44, 0x70,
  40070. 0x53, 0x7c, 0xb5, 0xbd, 0x30, 0xcb, 0x41, 0x19, 0x27, 0x69, 0xfe, 0x41,
  40071. 0x92, 0xae, 0xf0, 0x37, 0x33, 0xf0, 0x95, 0xe4, 0xe8, 0x4f, 0x75, 0x41,
  40072. 0x64, 0x87, 0xc5, 0x68, 0xd3, 0xce, 0xfa, 0xaa, 0xe8, 0x59, 0x88, 0xfe,
  40073. 0x24, 0x46, 0x27, 0x60, 0x71, 0x36, 0x78, 0x66, 0x3c, 0x36, 0x8e, 0xdb,
  40074. 0x90, 0x67, 0xa5, 0x6a, 0xfe, 0xd3, 0x23, 0x28, 0x91, 0x34, 0x24, 0x67,
  40075. 0x4b, 0x01, 0x6a, 0x0e, 0x02, 0xb7, 0xf0, 0xa8, 0xd4, 0x76, 0xd5, 0xa8,
  40076. 0x1c, 0xd3, 0xb3, 0x7d, 0x74, 0xc6, 0x17, 0x96, 0xa7, 0xf9, 0xad, 0x24,
  40077. 0x36, 0xd2, 0xeb, 0x34, 0x5a, 0xcc, 0x9c, 0x01, 0x99, 0xbe, 0x21, 0x4f,
  40078. 0x27, 0x9d, 0x6b, 0xca, 0x27, 0x1b, 0x60, 0x51, 0x41, 0x23, 0xe1, 0xcb,
  40079. 0xfc, 0x17, 0x2e, 0x1a, 0x4d, 0x3d, 0x51, 0xb3, 0x91, 0x8c, 0x53, 0x4d,
  40080. 0xd7, 0xbc, 0xa4, 0x07, 0xd7, 0x17, 0x19, 0x18, 0x61, 0x38, 0x4e, 0x05,
  40081. 0x81, 0x3f, 0x43, 0x8a, 0x00, 0x60, 0xdc, 0x30, 0xf4, 0x38, 0x3f, 0x93,
  40082. 0x82, 0x10, 0x29, 0x73, 0xa9, 0xbd, 0x63, 0x15, 0x7d, 0xac, 0x2e, 0xc9,
  40083. 0x05, 0xc1, 0x01, 0x41, 0x18, 0x5a, 0xc0, 0xc8, 0xc7, 0x81, 0x69, 0xe7,
  40084. 0x24, 0x21, 0x57, 0xaf, 0x88, 0x73, 0x7c, 0x53, 0x29, 0xae, 0x5a, 0xdf,
  40085. 0x76, 0x37, 0x56, 0x4f, 0x1f, 0x6b, 0xfd, 0x71, 0xbb, 0x80, 0x4a, 0xd7,
  40086. 0x53, 0x50, 0x10, 0x2d, 0xfc, 0x1a, 0xaf, 0x7c, 0x1f, 0xe8, 0xd0, 0x6c,
  40087. 0xa6, 0x45, 0x3d, 0xb5, 0x3d, 0xb2, 0xfc, 0x97, 0xa9, 0xbf, 0x7c, 0x0f,
  40088. 0x32, 0x7a, 0xcc, 0xa9, 0x2f, 0xd0, 0xc6, 0xe6, 0xcd, 0x04, 0x1d, 0x71,
  40089. 0x91, 0xb9, 0x59, 0x4b, 0xad, 0xa0, 0xde, 0x9e, 0xdc, 0x9c, 0x10, 0xeb,
  40090. 0x8d, 0xd6, 0x65, 0x57, 0xbc, 0x96, 0xfd, 0x0f, 0xcc, 0x73, 0xbe, 0x39,
  40091. 0x27, 0x99, 0x94, 0xf5, 0xe1, 0xbb, 0x32, 0xcd, 0x27, 0x7e, 0x08, 0xa0,
  40092. 0xd2, 0x92, 0x39, 0xeb, 0x71, 0xc8, 0xe8, 0x34, 0x57, 0x34, 0x4b, 0x20,
  40093. 0x3f, 0xe2, 0x68, 0xec, 0xc0, 0x8a, 0x71, 0xa3, 0x16, 0xa2, 0x91, 0x77,
  40094. 0xde, 0x41, 0x12, 0xa5, 0xf5, 0x2a, 0x63, 0x60, 0x55, 0xd0, 0x33, 0xa4,
  40095. 0xa7, 0x2e, 0xcb, 0x80, 0x08, 0xe5, 0x76, 0x16, 0x75, 0x04, 0x57, 0xe3,
  40096. 0x14, 0x71, 0x4e, 0x57, 0x29, 0x23, 0x0e, 0xc0, 0xcc, 0xad, 0xba, 0xdc,
  40097. 0x96, 0x5d, 0x23, 0x49, 0x42, 0xd8, 0x91, 0x08, 0x0d, 0x52, 0xf4, 0x5f,
  40098. 0xcd, 0xb7, 0x03, 0xaa, 0x73, 0x26, 0xa8, 0xd5, 0x5b, 0x0c, 0x85, 0xc8,
  40099. 0x84, 0x50, 0x9e, 0x70, 0x18, 0x45, 0x27, 0x82, 0x20, 0x75, 0xad, 0x52,
  40100. 0x5c, 0x80, 0x4b, 0xb1, 0x0b, 0x3b, 0x30, 0x39, 0x02, 0x54, 0x18, 0x5d,
  40101. 0x02, 0x9e, 0x85, 0x31, 0x4a, 0x07, 0x9c, 0x59, 0x5d, 0xab, 0x13, 0x4f,
  40102. 0x8f, 0x6e, 0x39, 0x20, 0xb2, 0xc5, 0x31, 0x93, 0xc6, 0xcc, 0xfb, 0xdc,
  40103. 0x15, 0xba, 0x3d, 0xcc, 0xbb, 0xd2, 0x6f, 0x04, 0x21, 0xdf, 0x0b, 0x27,
  40104. 0x5c, 0xd2, 0x6e, 0xfa, 0xda, 0x86, 0x5d, 0xe4, 0xca, 0xa4, 0x90, 0x22,
  40105. 0xa2, 0x80, 0xb5, 0x33, 0x17, 0xdb, 0x9b, 0x7b, 0x0a, 0xcc, 0x0f, 0x9b,
  40106. 0x38, 0x06, 0xdf, 0x10, 0x11, 0xa1, 0xd7, 0x2c, 0x24, 0xf0, 0xa8, 0x34,
  40107. 0x24, 0xfb, 0x99, 0xba, 0x0a, 0xb5, 0xa1, 0x94, 0x6c, 0x2d, 0xf8, 0xda,
  40108. 0x74, 0xaf, 0x19, 0x59, 0x84, 0xb2, 0x68, 0x1c, 0xef, 0xa1, 0xf5, 0x18,
  40109. 0x8f, 0x10, 0xf6, 0xb3, 0x6d, 0x33, 0x87, 0xe0, 0x25, 0xc8, 0x65, 0x5c,
  40110. 0x2f, 0x51, 0x07, 0x83, 0x69, 0x1b, 0xce, 0xa8, 0xe6, 0xe4, 0x27, 0x62,
  40111. 0x5d, 0x9b, 0x7f, 0xa7, 0x07, 0xc8, 0x54, 0x86, 0x90, 0xa5, 0x06, 0x6a,
  40112. 0x94, 0x80, 0x84, 0x97, 0xaa, 0x2a, 0xb9, 0x79, 0xe5, 0x19, 0x7a, 0x91,
  40113. 0xef, 0x8b, 0x58, 0xdc, 0xf9, 0x90, 0x94, 0xa2, 0x25, 0x4c, 0x69, 0xd8,
  40114. 0x6e, 0x9e, 0xad, 0xf8, 0x82, 0x17, 0x37, 0xc9, 0x20, 0x15, 0x24, 0x40,
  40115. 0xe5, 0xc6, 0xc1, 0xc7, 0xbd, 0xd4, 0x62, 0xff, 0x16, 0x6d, 0xa5, 0xec,
  40116. 0xe9, 0x67, 0x41, 0x9d, 0x3e, 0xfb, 0x22, 0x81, 0x80, 0x61, 0x37, 0x45,
  40117. 0xa5, 0x9f, 0x70, 0xff, 0xd4, 0x99, 0x3d, 0x79, 0x45, 0xd0, 0x27, 0xc2,
  40118. 0x32, 0xbe, 0xd4, 0xe2, 0x53, 0xa8, 0x8c, 0x94, 0x8b, 0xbe, 0x8a, 0x43,
  40119. 0xf7, 0x2a, 0x28, 0x49, 0xf4, 0xce, 0x2e, 0x0b, 0x98, 0xc7, 0xaf, 0x7d,
  40120. 0x51, 0x2e, 0xda, 0xd0, 0x7a, 0xfa, 0x91, 0x3a, 0xe6, 0xe7, 0x64, 0xd6,
  40121. 0x09, 0xd8, 0x5d, 0x6a, 0x97, 0xcf, 0x89, 0x96, 0x72, 0x21, 0x97, 0x61,
  40122. 0xc5, 0x1b, 0xd8, 0xa1, 0xf0, 0xcd, 0x9d, 0xe4, 0xe9, 0x13, 0xd0, 0x16,
  40123. 0x41, 0x20, 0xa4, 0x2c, 0x33, 0xf5, 0x3d, 0xfe, 0x80, 0xe8, 0xb2, 0x52,
  40124. 0x0e, 0x18, 0x31, 0x19, 0x50, 0xeb, 0xc6, 0x99, 0x43, 0xab, 0x9a, 0x59,
  40125. 0x5d, 0x6c, 0x84, 0x00, 0x88, 0x45, 0x7c, 0x73, 0xdf, 0x56, 0x61, 0x3a,
  40126. 0xe1, 0x55, 0xb8, 0x59, 0x13, 0xcc, 0x0e, 0x53, 0xe9, 0xf4, 0x74, 0xa0,
  40127. 0xf2, 0x15, 0xd2, 0xa8, 0xf9, 0xd4, 0x0d, 0x3d, 0xe7, 0x3d, 0x7d, 0x5b,
  40128. 0x19, 0x89, 0x8b, 0x2c, 0x4d, 0x8a, 0xeb, 0xc3, 0x43, 0x31, 0x9a, 0x45,
  40129. 0x72, 0x5b, 0x25, 0xb6, 0xa2, 0xc1, 0x98, 0xe3, 0x8a, 0xd4, 0x90, 0xd0,
  40130. 0x3e, 0x13, 0xf0, 0xd7, 0x90, 0x34, 0x94, 0xcc, 0xf1, 0x0a, 0xa9, 0x30,
  40131. 0xd1, 0x95, 0x43, 0x07, 0xcd, 0xd2, 0xca, 0xb0, 0xe5, 0xd4, 0xf1, 0xa1,
  40132. 0xc5, 0x9b, 0xf4, 0x98, 0x28, 0xba, 0xde, 0x40, 0xd6, 0x98, 0x98, 0x20,
  40133. 0x9c, 0x84, 0x9e, 0xc6, 0x57, 0xd8, 0x84, 0xc4, 0xa2, 0x9b, 0x53, 0x50,
  40134. 0xa5, 0xa6, 0x0b, 0x47, 0xe8, 0x08, 0x7d, 0xd7, 0x09, 0xa4, 0x0c, 0x2b,
  40135. 0x27, 0xde, 0xf9, 0x78, 0xbc, 0xa4, 0xb6, 0xc6, 0x1b, 0xda, 0xce, 0x6a,
  40136. 0xf8, 0x1a, 0xf5, 0xfe, 0x7b, 0xab, 0x58, 0x7c, 0xdc, 0x72, 0x02, 0x94,
  40137. 0x99, 0xf0, 0x3c, 0x37, 0x87, 0x5b, 0xd2, 0x4b, 0x5a, 0x80, 0x83, 0xd7,
  40138. 0xfc, 0x9d, 0xa7, 0x51, 0x81, 0xb8, 0x62, 0xff, 0x4b, 0xb3, 0x9f, 0x07,
  40139. 0xc3, 0x54, 0xfb, 0x41, 0x85, 0x42, 0x9d, 0xac, 0x27, 0x81, 0x2e, 0xaf,
  40140. 0x98, 0x67, 0x8c, 0x23, 0xad, 0x45, 0xfe, 0x6a, 0x57, 0x9f, 0x18, 0xc5,
  40141. 0x71, 0x8c, 0xad, 0x3f, 0x30, 0x3c, 0xaa, 0x47, 0x8d, 0xba, 0xc8, 0x7f,
  40142. 0x03, 0x1c, 0x86, 0xee, 0xba, 0x3f, 0x59, 0x45, 0xd4, 0xd0, 0xf5, 0x54,
  40143. 0x9e, 0xcb, 0x08, 0xcf, 0xca, 0x40, 0x0a, 0x06, 0xc0, 0x1e, 0x60, 0x1f,
  40144. 0x33, 0xbf, 0x2c, 0xa8, 0x5f, 0xce, 0x23, 0xa0, 0xe2, 0x1c, 0x2d, 0x56,
  40145. 0x2a, 0x44, 0x61, 0x58, 0xf1, 0x84, 0x63, 0x4f, 0x0d, 0x5e, 0xfb, 0x83,
  40146. 0x0f, 0x36, 0x1b, 0xf4, 0x8f, 0x17, 0x82, 0x2e, 0x04, 0x2c, 0x77, 0x9d,
  40147. 0x32, 0x58, 0xb8, 0xb0, 0xf9, 0x44, 0xd2, 0xf6, 0x84, 0xa4, 0x8b, 0x28,
  40148. 0x53, 0xd6, 0x99, 0x81, 0x84, 0x43, 0xf0, 0xc1, 0x15, 0xc6, 0x74, 0x4f,
  40149. 0xab, 0x05, 0xcc, 0x80, 0xdf, 0xef, 0xcf, 0xaf, 0x14, 0x82, 0xdf, 0x51,
  40150. 0x7c, 0x28, 0x5e, 0x5b, 0x27, 0x5e, 0x91, 0x8b, 0x54, 0x3d, 0x54, 0x26,
  40151. 0xb0, 0x3f, 0xd7, 0xc5, 0xce, 0xf3, 0x6d, 0x2c, 0x12, 0xc6, 0xb4, 0x48,
  40152. 0x60, 0x11, 0x9c, 0xef, 0x29, 0x98, 0x9c, 0x76, 0x4e, 0x73, 0x2b, 0xd2,
  40153. 0x23, 0x53, 0x7d, 0x03, 0xc2, 0x2f, 0x8a, 0xa1, 0xe2, 0x84, 0x54, 0x2d,
  40154. 0xd8, 0xc6, 0x55, 0x77, 0x9d, 0x07, 0x67, 0x1f, 0x1a, 0xd3, 0x57, 0x4c,
  40155. 0x25, 0x79, 0x8f, 0xd8, 0x82, 0xc2, 0x4d, 0x87, 0x84, 0x33, 0xdc, 0x47,
  40156. 0xed, 0x9e, 0xfb, 0xd2, 0x62, 0xc8, 0x50, 0x76, 0xda, 0x3c, 0x3c, 0x05,
  40157. 0x0e, 0x2d, 0x30, 0x56, 0xca, 0x4d, 0x6a, 0xe2, 0x17, 0x24, 0x26, 0x9c,
  40158. 0xff, 0x09, 0xec, 0xb3, 0x94, 0xec, 0xab, 0x69, 0xb2, 0xf0, 0xa5, 0x66,
  40159. 0x18, 0x92, 0x49, 0x6b, 0x90, 0xf5, 0x77, 0x5a, 0x18, 0xe5, 0x51, 0x36,
  40160. 0x4a, 0x35, 0x54, 0x98, 0x48, 0x04, 0xa9, 0x0f, 0xcb, 0x55, 0xf1, 0x71,
  40161. 0xad, 0x1a, 0x4a, 0x2c, 0x0e, 0x5d, 0x5e, 0x77, 0x47, 0xf5, 0x46, 0x17,
  40162. 0x6b, 0x94, 0x2a, 0xbc, 0x40, 0xe5, 0xa7, 0xa6, 0x88, 0x41, 0x76, 0x22,
  40163. 0x47, 0xd1, 0xe8, 0x2b, 0x18, 0x48, 0x21, 0xc0, 0xe8, 0x4f, 0xe2, 0xb2,
  40164. 0x7e, 0x03, 0xbb, 0x25, 0x9c, 0xc8, 0x68, 0x66, 0x48, 0x25, 0x6a, 0xf2,
  40165. 0x64, 0x29, 0xec, 0x79, 0xba, 0xdb, 0x34, 0xe1, 0xd4, 0xf9, 0x52, 0x0e,
  40166. 0xfd, 0x8d, 0x86, 0x94, 0x71, 0xd8, 0xe0, 0x86, 0x02, 0x9b, 0xd4, 0x65,
  40167. 0x69, 0x5e, 0x01, 0x32, 0x87, 0x59, 0xd8, 0x6c, 0xbc, 0x8a, 0x9f, 0x58,
  40168. 0x28, 0x8c, 0x97, 0xef, 0x33, 0xb2, 0xda, 0x45, 0xa0, 0xec, 0xe5, 0x5b,
  40169. 0xac, 0xc6, 0x65, 0xc1, 0xb6, 0xcb, 0xf7, 0x85, 0x0e, 0xfa, 0x78, 0x36,
  40170. 0x30, 0x84, 0x90, 0xa8, 0xf8, 0x42, 0x25, 0xa5, 0xdd, 0xdc, 0xdc, 0x89,
  40171. 0xd3, 0xf0, 0x73, 0x9a, 0xd8, 0x95, 0x8f, 0x04, 0xbf, 0xc1, 0xfd, 0x94,
  40172. 0xff, 0xe6, 0xf8, 0x4e, 0xc6, 0x43, 0xc9, 0x60, 0x30, 0xe9, 0x68, 0xa8,
  40173. 0x76, 0xfb, 0xfa, 0xdf, 0xc0, 0x9b, 0xbc, 0xbc, 0x34, 0xe4, 0x38, 0xfd,
  40174. 0x93, 0xb0, 0x47, 0xb2, 0x3e, 0x83, 0x6c, 0xef, 0xe1, 0xaf, 0x35, 0xb4,
  40175. 0x90, 0x2a, 0x32, 0xaf, 0x25, 0x3f, 0x3e, 0x72, 0x61, 0xc0, 0x0f, 0x29,
  40176. 0xbb, 0x46, 0x6e, 0x2e, 0x94, 0x7d, 0xdd, 0xb7, 0x67, 0x1f, 0x7b, 0x64,
  40177. 0xcb, 0xa5, 0x9a, 0x58, 0x63, 0x20, 0xa7, 0xc0, 0x94, 0xa9, 0xad, 0x90,
  40178. 0x7d, 0xf3, 0x2b, 0x61, 0x2b, 0x64, 0x3d, 0x8a, 0xc3, 0xd1, 0xcb, 0xad,
  40179. 0x36, 0x44, 0xe6, 0x29, 0x8b, 0x3d, 0x95, 0x7c, 0xa7, 0xa2, 0xfa, 0x1b,
  40180. 0x16, 0x8d, 0x9e, 0xc4, 0xf8, 0x4c, 0x76, 0x20, 0x00, 0x68, 0x07, 0x99,
  40181. 0x9c, 0x60, 0xe6, 0x16, 0x6a, 0x6f, 0x8a, 0xbe, 0x71, 0x95, 0xa1, 0xcb,
  40182. 0xfe, 0x7c, 0x41, 0x59, 0x61, 0x20, 0xf9, 0x54, 0x3c, 0xb1, 0x19, 0x5c,
  40183. 0x42, 0x67, 0x3f, 0xff, 0xf3, 0x32, 0x21, 0x9c, 0x9e, 0x88, 0xf9, 0x97,
  40184. 0x00, 0x43, 0x73, 0x4a, 0xfc, 0x54, 0xeb, 0x27, 0x79, 0x14, 0x85, 0xd3,
  40185. 0xdc, 0x47, 0xb3, 0x6d, 0x24, 0xd3, 0xf7, 0x7a, 0xfb, 0x90, 0x7c, 0x6e,
  40186. 0xcd, 0x4e, 0xbf, 0x26, 0x76, 0xd2, 0xe8, 0xcc, 0x67, 0xd1, 0x23, 0x3c,
  40187. 0x94, 0x16, 0x1e, 0x07, 0x36, 0x7c, 0x96, 0xf6, 0xe8, 0x50, 0x72, 0x26,
  40188. 0x56, 0x67, 0x89, 0xa9, 0x11, 0xfb, 0x1d, 0xb8, 0xb9, 0x2a, 0x55, 0xb7,
  40189. 0x85, 0xf7, 0x40, 0xa2, 0xfc, 0x9f, 0x30, 0xec, 0x8f, 0x9a, 0x1c, 0xc8,
  40190. 0xe4, 0xc5, 0x1f, 0xcb, 0x0a, 0x60, 0x80, 0x41, 0xec, 0x88, 0x8a, 0xda,
  40191. 0x7c, 0x7a, 0xa1, 0x96, 0x51, 0x62, 0x16, 0x63, 0x75, 0x36, 0x28, 0x7c,
  40192. 0xc9, 0xd0, 0x27, 0x0c, 0x9e, 0x18, 0x4a, 0x82, 0xf7, 0x02, 0xb9, 0x40,
  40193. 0x8f, 0xd5, 0x97, 0x7a, 0x35, 0xa9, 0x3a, 0xb3, 0x8b, 0x6b, 0xf1, 0x9a,
  40194. 0xd1, 0xe7, 0x14, 0x38, 0x5e, 0xba, 0x8c, 0xbf, 0x32, 0xaa, 0x34, 0x30,
  40195. 0x7c, 0x1e, 0x11, 0xcd, 0x1f, 0x9f, 0xcf, 0x4d, 0x14, 0xce, 0x67, 0xf9,
  40196. 0x9c, 0x89, 0x07, 0x92, 0x44, 0x6e, 0x9a, 0x16, 0xe4, 0xfb, 0x67, 0x01,
  40197. 0x3f, 0x4c, 0x14, 0x89, 0x33, 0x87, 0x46, 0xc6, 0xe4, 0x66, 0x94, 0xd4,
  40198. 0x87, 0x4f, 0x2c, 0x92, 0x1b, 0xae, 0x82, 0xe7, 0x99, 0xaa, 0xb4, 0x99,
  40199. 0x81, 0x26, 0xa6, 0x6f, 0x1d, 0xc1, 0x95, 0x80, 0xe9, 0xea, 0xe3, 0x44,
  40200. 0x6a, 0x2b, 0xd2, 0xe0, 0x0d, 0x69, 0x42, 0xf7, 0x27, 0x6b, 0x4f, 0x02,
  40201. 0x7a, 0x33, 0x7b, 0x43, 0x3d, 0xef, 0x10, 0xaa, 0xab, 0xc5, 0xa2, 0xf0,
  40202. 0xbb, 0x07, 0x4b, 0x26, 0x0c, 0x58, 0xcd, 0x3b, 0xd2, 0x6d, 0xa5, 0x32,
  40203. 0x37, 0x88, 0x4e, 0x8b, 0xe3, 0x75, 0xb0, 0xbb, 0x87, 0xea, 0xa4, 0x53,
  40204. 0xf3, 0xff, 0x39, 0x92, 0x44, 0xab, 0x7b, 0x71, 0x62, 0x31, 0x6b, 0x31,
  40205. 0xca, 0x97, 0xba, 0xd7, 0x41, 0xe0, 0x47, 0x47, 0x4f, 0x77, 0xa2, 0x35,
  40206. 0x62, 0x7a, 0xc1, 0xb6, 0x69, 0x10, 0x09, 0xce, 0xfc, 0x92, 0xcc, 0xc5,
  40207. 0x7a, 0x11, 0xf1, 0xc1, 0xa0, 0x80, 0xe5, 0x42, 0x17, 0xb6, 0x3f, 0xab,
  40208. 0xc1, 0xa2, 0x41, 0xfb, 0xe3, 0x98, 0x2d, 0x7a, 0xe4, 0x1b, 0x1f, 0x7e,
  40209. 0x71, 0x3c, 0x3e, 0x90, 0x8c, 0x60, 0x30, 0xb7, 0x73, 0x06, 0x1f, 0x8a,
  40210. 0xce, 0x50, 0x20, 0x7c, 0xfa, 0x8c, 0xf2, 0x14, 0xd9, 0x00, 0xa2, 0x21,
  40211. 0xea, 0x10, 0x36, 0x21, 0x6f, 0x7f, 0x13, 0xe3, 0x6c, 0xb2, 0xd6, 0xa5,
  40212. 0xa6, 0x6e, 0xa9, 0xe7, 0x1d, 0xdf, 0xc9, 0x97, 0x60, 0x75, 0xa3, 0x55,
  40213. 0xa1, 0x2c, 0x94, 0xd7, 0x85, 0x4b, 0x44, 0xc6, 0x9c, 0x17, 0xc2, 0xad,
  40214. 0xe6, 0x56, 0x72, 0x1d, 0xb9, 0x13, 0x54, 0xfe, 0x8c, 0xec, 0xf4, 0xa3,
  40215. 0x54, 0x6b, 0x31, 0xbc, 0x55, 0x9e, 0x01, 0xd4, 0x9b, 0x24, 0x9e, 0x51,
  40216. 0xaf, 0x67, 0x76, 0x02, 0xf7, 0x34, 0x6a, 0xaa, 0xb0, 0x3c, 0x70, 0x2e,
  40217. 0xc8, 0x86, 0xfa, 0x40, 0x89, 0x12, 0xb7, 0x49, 0x38, 0x0b, 0xf7, 0x66,
  40218. 0xd2, 0x2e, 0x58, 0xf1, 0x22, 0x3b, 0xb3, 0x40, 0x6b, 0x7a, 0x68, 0x4d,
  40219. 0x42, 0xfd, 0xbf, 0xa0, 0xf7, 0x2f, 0x63, 0x4a, 0x87, 0xe7, 0x99, 0x52,
  40220. 0x6e, 0xe7, 0xdd, 0xca, 0x19, 0x71, 0xee, 0x92, 0xe2, 0x68, 0x0e, 0xe1,
  40221. 0xb7, 0x90, 0x1f, 0xc4, 0xef, 0xf8, 0xf6, 0x85, 0x53, 0x18, 0x33, 0x86,
  40222. 0x15, 0xc8, 0x29, 0x58, 0x6f, 0xf0, 0x1c, 0x14, 0x73, 0xa9, 0x8e, 0x88,
  40223. 0x74, 0xd4, 0x21, 0xf5, 0xc6, 0x7c, 0xd8, 0x96, 0x0f, 0xb0, 0xa6, 0x7b,
  40224. 0xf7, 0x72, 0x15, 0xd7, 0x30, 0x6b, 0x15, 0x1d, 0x3f, 0xb7, 0x4e, 0xaa,
  40225. 0xc0, 0x52, 0x1d, 0x84, 0xbf, 0x98, 0xbd, 0x33, 0x02, 0xab, 0x8b, 0xd0,
  40226. 0x9c, 0x85, 0x2f, 0xa3, 0xfb, 0x46, 0x8d, 0x4d, 0x97, 0x1a, 0x8a, 0x3c,
  40227. 0x73, 0x5b, 0x3b, 0x58, 0x26, 0xba, 0x6b, 0x45, 0x2e, 0x24, 0x66, 0x79,
  40228. 0x7d, 0xc4, 0xf8, 0x8c, 0x05, 0x7d, 0x5c, 0x23, 0xb9, 0xe8, 0x5d, 0xfe,
  40229. 0xc9, 0x84, 0xe5, 0x58, 0x40, 0xa4, 0xb7, 0x55, 0x74, 0x69, 0x92, 0x9c,
  40230. 0x3e, 0x19, 0xb1, 0xb6, 0x51, 0xe9, 0x71, 0xcc, 0x96, 0x2b, 0x01, 0x71,
  40231. 0xf5, 0xb9, 0xde, 0x77, 0xfe, 0x2e, 0x74, 0x9c, 0x6a, 0x52, 0x17, 0x1e,
  40232. 0xea, 0xd9, 0xc8, 0x14, 0xbe, 0x61, 0xdf, 0xe9, 0x96, 0x24, 0x5a, 0x9a,
  40233. 0xd8, 0xd7, 0xad, 0x71, 0xe0, 0xf4, 0xbb, 0x9e, 0xae, 0x95, 0xcd, 0x58,
  40234. 0x94, 0x81, 0xee, 0x46, 0x84, 0x65, 0x39, 0xb1, 0x1b, 0x1e, 0xf5, 0x50,
  40235. 0xad, 0x56, 0x58, 0xb7, 0x53, 0x9b, 0x2a, 0x2f, 0x09, 0x61, 0x57, 0xda,
  40236. 0xf5, 0xdc, 0x9f, 0x3c, 0x6c, 0x69, 0x0d, 0x61, 0x49, 0xb2, 0xe0, 0xb2,
  40237. 0xe5, 0xef, 0x19, 0xbe, 0x04, 0xf6, 0x6b, 0xad, 0x41, 0x4c, 0x5a, 0x50,
  40238. 0xf6, 0xac, 0x1b, 0x25, 0x8a, 0xdd, 0xe3, 0x57, 0xab, 0x7c, 0x92, 0xe4
  40239. };
  40240. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40241. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_pub_key[] = {
  40242. 0xef, 0x49, 0x79, 0x47, 0x15, 0xc4, 0x8a, 0xa9, 0x74, 0x2a,
  40243. 0xf0, 0x36, 0x94, 0x5c, 0x91, 0x1c, 0x5d, 0xff, 0x2c, 0x83,
  40244. 0xf2, 0x8b, 0x04, 0xfc, 0x5d, 0x64, 0xbd, 0x49, 0x73, 0xcd,
  40245. 0xcc, 0x99, 0x50, 0x5f, 0x2b, 0x16, 0x3a, 0xbb, 0x98, 0xc0,
  40246. 0xa7, 0x69, 0x0e, 0x95, 0x99, 0x0b, 0xa2, 0x6c, 0xfe, 0x6c,
  40247. 0xdb, 0xc8, 0xa7, 0x09, 0x46, 0x6c, 0x90, 0x50, 0xa4, 0x75,
  40248. 0x30, 0xf7, 0x90, 0xac, 0x31, 0xb6, 0xdd, 0x21, 0xaf, 0xc6,
  40249. 0xf9, 0xfe, 0xee, 0xc6, 0x5b, 0xa8, 0x8f, 0x0a, 0x2e, 0xd0,
  40250. 0x42, 0xab, 0xa8, 0x3c, 0x8d, 0xbf, 0xf7, 0x44, 0xbd, 0x0d,
  40251. 0xcf, 0xf4, 0x68, 0xfc, 0x16, 0x67, 0xf7, 0x39, 0x48, 0x5f,
  40252. 0x56, 0xd1, 0xe7, 0x1f, 0x49, 0x80, 0x50, 0xbe, 0x54, 0xd1,
  40253. 0xb7, 0xc9, 0xd2, 0x32, 0xc7, 0x08, 0x8c, 0xde, 0x2c, 0x31,
  40254. 0xf6, 0x1d, 0xc7, 0xac, 0xb3, 0x79, 0xd7, 0x4b, 0x1b, 0x23,
  40255. 0x89, 0x0a, 0xdc, 0x8e, 0x44, 0x41, 0x14, 0x28, 0x99, 0x13,
  40256. 0xb3, 0x26, 0xa6, 0x0e, 0x83, 0x60, 0xaa, 0x8d, 0x7c, 0x23,
  40257. 0x13, 0xba, 0x6c, 0x28, 0x90, 0x56, 0x84, 0xa1, 0x23, 0x8b,
  40258. 0x81, 0x20, 0x97, 0x7c, 0x66, 0x3f, 0xed, 0x5d, 0xd0, 0xe4,
  40259. 0x5d, 0xee, 0x46, 0xbc, 0x4b, 0x3c, 0x03, 0xb5, 0xbc, 0x4d,
  40260. 0x8d, 0x37, 0xa3, 0x56, 0x4b, 0x33, 0xad, 0xef, 0xd4, 0xb6,
  40261. 0xec, 0xdb, 0x04, 0x9a, 0x19, 0x58, 0x57, 0xd8, 0x00, 0x3a,
  40262. 0x92, 0x61, 0x0c, 0x0b, 0xc8, 0x52, 0xe5, 0x04, 0x02, 0x9a,
  40263. 0x00, 0x7e, 0xec, 0x7e, 0x94, 0xaa, 0xef, 0x2d, 0x7f, 0xb6,
  40264. 0x2e, 0x7c, 0xb0, 0x73, 0xa2, 0x20, 0xc0, 0x07, 0x30, 0x41,
  40265. 0x50, 0x20, 0x14, 0x18, 0x21, 0x5e, 0x2a, 0x6f, 0x70, 0x21,
  40266. 0xd6, 0x97, 0x13, 0xb9, 0xc1, 0x9e, 0x90, 0x67, 0xcc, 0x55,
  40267. 0x8a, 0xec, 0xec, 0x0a, 0x1e, 0x90, 0xdc, 0x3f, 0xb0, 0x4d,
  40268. 0xd1, 0x18, 0xea, 0x4f, 0xcb, 0x5d, 0x15, 0x4c, 0xb8, 0x35,
  40269. 0x9b, 0x34, 0x24, 0x30, 0x06, 0x53, 0x17, 0xf0, 0xbe, 0x27,
  40270. 0x36, 0xb3, 0x04, 0x6a, 0xbd, 0xbf, 0xa7, 0x39, 0xee, 0xa9,
  40271. 0x8f, 0x0e, 0x98, 0xc5, 0xf5, 0x9f, 0x46, 0x25, 0x93, 0xc9,
  40272. 0xf2, 0xf6, 0x2b, 0x8e, 0x92, 0x06, 0x01, 0x3d, 0x81, 0x18,
  40273. 0xf2, 0xec, 0xf1, 0x05, 0x4c, 0xad, 0x4b, 0xcb, 0x98, 0xa4,
  40274. 0xb5, 0x61, 0x20, 0xda, 0x81, 0xa1, 0xfb, 0x92, 0x4c, 0xaf,
  40275. 0x87, 0x6f, 0x6e, 0xd2, 0x57, 0xec, 0xcd, 0x94, 0xb3, 0x79,
  40276. 0xbf, 0x59, 0x88, 0x17, 0x81, 0xce, 0x8a, 0x57, 0xce, 0x57,
  40277. 0xae, 0x3e, 0x82, 0x81, 0x2f, 0x83, 0x61, 0xd8, 0xf9, 0x68,
  40278. 0x21, 0xe7, 0x72, 0x5b, 0xd6, 0x80, 0x55, 0x68, 0x5d, 0x67,
  40279. 0x15, 0x0c, 0x8b, 0xdc, 0x4f, 0xc3, 0x89, 0x36, 0x3c, 0xac,
  40280. 0xaf, 0x16, 0x5e, 0x1c, 0xfa, 0x68, 0x74, 0x6a, 0xab, 0x68,
  40281. 0xd8, 0x59, 0x96, 0x2d, 0x33, 0x62, 0xe4, 0xbd, 0xb3, 0xb7,
  40282. 0x4d, 0x88, 0x35, 0xb8, 0xed, 0xb2, 0x16, 0x85, 0x97, 0x08,
  40283. 0x71, 0x71, 0x39, 0x7e, 0x0c, 0x53, 0x16, 0xda, 0x38, 0xe5,
  40284. 0x28, 0x09, 0x9c, 0xd9, 0x46, 0xec, 0x68, 0xda, 0x8d, 0xd0,
  40285. 0xad, 0xb2, 0x79, 0x28, 0x3b, 0x1e, 0x12, 0xc9, 0xdf, 0xa9,
  40286. 0x6d, 0x3d, 0x29, 0x99, 0x2f, 0x53, 0xc2, 0xd0, 0xf9, 0x88,
  40287. 0x26, 0x94, 0x47, 0xaf, 0xf6, 0x96, 0xf3, 0xe1, 0x11, 0xa6,
  40288. 0x82, 0x3d, 0x43, 0x3f, 0x1f, 0xbc, 0xf6, 0x98, 0xbe, 0xff,
  40289. 0x06, 0x86, 0x61, 0x27, 0xdc, 0x91, 0x54, 0xd4, 0xfc, 0x68,
  40290. 0x83, 0xe8, 0x35, 0x3e, 0xee, 0x94, 0x59, 0x28, 0x2f, 0xde,
  40291. 0xdd, 0x03, 0x60, 0x66, 0xc1, 0x49, 0x57, 0xdd, 0xbc, 0xd5,
  40292. 0x0a, 0x67, 0x34, 0xf1, 0xa6, 0x0a, 0x57, 0x94, 0x65, 0x02,
  40293. 0x2c, 0x52, 0x43, 0x70, 0x3b, 0xc1, 0x9a, 0xff, 0xda, 0x6f,
  40294. 0xb9, 0x54, 0x47, 0x01, 0xda, 0x27, 0xe4, 0x48, 0x4a, 0x90,
  40295. 0x9f, 0xb5, 0xc3, 0xee, 0x0e, 0x09, 0x57, 0xfe, 0x48, 0x51,
  40296. 0x08, 0x34, 0x5e, 0x8f, 0x16, 0xc9, 0x0b, 0x74, 0xd9, 0x7d,
  40297. 0x22, 0x3f, 0xd6, 0xb7, 0x5d, 0xd6, 0x76, 0x00, 0x8d, 0x4e,
  40298. 0x78, 0x73, 0x86, 0xd6, 0xdb, 0x2a, 0x65, 0xab, 0xdf, 0xb0,
  40299. 0xea, 0x11, 0xad, 0xdf, 0xba, 0x43, 0xdb, 0xa8, 0x0a, 0xfb,
  40300. 0x04, 0x38, 0x81, 0x2b, 0xa3, 0x29, 0xfc, 0x95, 0x73, 0x9a,
  40301. 0x0c, 0x6c, 0x9e, 0xcd, 0xdc, 0xcf, 0x0a, 0x0c, 0x18, 0x41,
  40302. 0x6f, 0x1d, 0xa3, 0xf6, 0x12, 0x4c, 0x13, 0xf2, 0x02, 0xc6,
  40303. 0x50, 0x99, 0x86, 0x73, 0xa7, 0xf9, 0x7e, 0x84, 0x7f, 0x4c,
  40304. 0x00, 0xce, 0x2e, 0x21, 0x76, 0x8e, 0x17, 0x7a, 0x87, 0x6f,
  40305. 0x81, 0xe6, 0xc0, 0x52, 0xa5, 0xa0, 0x3c, 0x54, 0x3c, 0xec,
  40306. 0xb0, 0x9d, 0x1c, 0x3b, 0xec, 0xe5, 0x4e, 0x4a, 0x37, 0xe7,
  40307. 0xd5, 0xa9, 0x07, 0x87, 0x23, 0x28, 0x5d, 0x3d, 0x22, 0x02,
  40308. 0x79, 0x40, 0x3f, 0x2d, 0x40, 0xc9, 0xe5, 0xa6, 0x9b, 0xa8,
  40309. 0xb8, 0x76, 0xf6, 0x77, 0x5b, 0x8d, 0x72, 0x96, 0x3e, 0x13,
  40310. 0xbf, 0x76, 0xfa, 0x7b, 0xb7, 0x82, 0x5f, 0xe7, 0x9d, 0x54,
  40311. 0x0e, 0x05, 0x1a, 0x9f, 0xa4, 0x42, 0xa5, 0xb4, 0x93, 0x23,
  40312. 0x06, 0x59, 0x43, 0xa8, 0xe8, 0x5c, 0xfc, 0x18, 0x97, 0xdb,
  40313. 0xad, 0x9a, 0x80, 0x0a, 0xf2, 0x20, 0x50, 0xac, 0xc1, 0x13,
  40314. 0x3e, 0x98, 0x09, 0xde, 0xf2, 0x70, 0x9e, 0x14, 0xc2, 0x5c,
  40315. 0xec, 0x65, 0x07, 0x0b, 0xfa, 0x02, 0x5c, 0xf8, 0x71, 0xaa,
  40316. 0x9b, 0x45, 0x62, 0xe2, 0x27, 0xaf, 0x77, 0xf8, 0xe3, 0xeb,
  40317. 0x7b, 0x24, 0x7b, 0x3c, 0x67, 0xc2, 0x6d, 0x6e, 0x17, 0xae,
  40318. 0x6e, 0x86, 0x6f, 0x98, 0xc9, 0xac, 0x13, 0x9f, 0x87, 0x64,
  40319. 0x3d, 0x4d, 0x6f, 0xa0, 0xb3, 0x39, 0xc6, 0x68, 0x1b, 0xa7,
  40320. 0xeb, 0x3e, 0x0f, 0x6b, 0xc7, 0xa4, 0xe2, 0x20, 0x27, 0x75,
  40321. 0x3f, 0x09, 0x16, 0xff, 0x1a, 0xcc, 0xa7, 0xc4, 0x6d, 0xc2,
  40322. 0xfc, 0xc3, 0x0b, 0x37, 0x63, 0xff, 0x9b, 0x10, 0xe6, 0x00,
  40323. 0xf7, 0x18, 0x43, 0x9f, 0x07, 0x50, 0x31, 0x51, 0xd4, 0xfd,
  40324. 0xad, 0xa2, 0x0f, 0x77, 0xda, 0x41, 0xc1, 0x0a, 0x6f, 0x86,
  40325. 0xd7, 0xdc, 0x8a, 0x52, 0xd6, 0xa1, 0x27, 0xdb, 0x14, 0x67,
  40326. 0x26, 0x91, 0xb3, 0xcd, 0x01, 0x5f, 0x60, 0xa1, 0x7f, 0x43,
  40327. 0x15, 0x1a, 0x82, 0x0f, 0xd3, 0x66, 0x5f, 0x60, 0x57, 0x2f,
  40328. 0xb2, 0x8c, 0x27, 0x2a, 0x9d, 0x1b, 0xf9, 0xf2, 0x59, 0x20,
  40329. 0x39, 0xd9, 0xc5, 0xaf, 0xf2, 0x36, 0x8c, 0x58, 0x00, 0x1b,
  40330. 0xd0, 0xc5, 0x8e, 0x1a, 0x49, 0xa8, 0x60, 0xbe, 0xd1, 0xd7,
  40331. 0x2a, 0xb0, 0xc2, 0xab, 0x58, 0x8a, 0x7a, 0xa9, 0x41, 0x68,
  40332. 0x70, 0xbd, 0xea, 0x73, 0xa5, 0x03, 0x11, 0xb2, 0x27, 0xd9,
  40333. 0xcd, 0xf5, 0x09, 0xe8, 0x1c, 0xe2, 0x4f, 0x50, 0x6a, 0x84,
  40334. 0x34, 0x62, 0x2e, 0x36, 0xaa, 0x4c, 0xc1, 0x83, 0x78, 0x98,
  40335. 0x35, 0x7a, 0x27, 0x7e, 0xfe, 0xf1, 0x6f, 0x59, 0x27, 0x35,
  40336. 0x73, 0xce, 0x74, 0xaa, 0xb4, 0x72, 0x82, 0xa8, 0xe2, 0x81,
  40337. 0x7a, 0x6b, 0xca, 0x33, 0xa5, 0xda, 0xa2, 0x63, 0xca, 0x2e,
  40338. 0x90, 0x03, 0x32, 0xec, 0x63, 0xdb, 0x52, 0x7b, 0x16, 0xfc,
  40339. 0x01, 0x2d, 0x30, 0x12, 0x1e, 0xf9, 0xa3, 0x72, 0x21, 0x3c,
  40340. 0x75, 0x0c, 0x61, 0x9c, 0x7e, 0x73, 0x04, 0x71, 0x41, 0x45,
  40341. 0x5d, 0x7f, 0x49, 0x1c, 0x09, 0x08, 0xa4, 0xec, 0x2f, 0xfd,
  40342. 0xc4, 0xfb, 0x59, 0x6a, 0x27, 0x7a, 0xd4, 0xfc, 0x5f, 0x20,
  40343. 0x04, 0x34, 0x7d, 0x08, 0xed, 0x82, 0x5a, 0x90, 0xe1, 0xab,
  40344. 0xfd, 0x35, 0x3a, 0x8d, 0xbb, 0x0a, 0x9d, 0x73, 0xff, 0x69,
  40345. 0xe5, 0xe9, 0x09, 0x55, 0x14, 0xd9, 0x7b, 0x6f, 0x0d, 0x99,
  40346. 0xd2, 0x7e, 0x71, 0xf8, 0x4f, 0x72, 0x2f, 0xbb, 0xc6, 0xc4,
  40347. 0x36, 0xc9, 0x01, 0xd3, 0x9b, 0x94, 0xab, 0x41, 0x0f, 0x4a,
  40348. 0x61, 0x5c, 0x68, 0xe5, 0xd7, 0x0d, 0x94, 0xaa, 0xee, 0xba,
  40349. 0x95, 0xcb, 0x8c, 0x0e, 0x85, 0x3a, 0x02, 0x6b, 0x95, 0x50,
  40350. 0xfd, 0x02, 0xfd, 0xa4, 0x58, 0x29, 0x78, 0x4f, 0xd0, 0xae,
  40351. 0x66, 0xd6, 0x5c, 0xe7, 0x45, 0xfe, 0x98, 0xb0, 0xa3, 0xe2,
  40352. 0x87, 0xc0, 0xd2, 0x81, 0x08, 0xf1, 0xf1, 0xe7, 0xda, 0x62,
  40353. 0x9e, 0xa0, 0x34, 0x86, 0xeb, 0xa1, 0x6e, 0x4a, 0x26, 0x8e,
  40354. 0x39, 0x0c, 0x51, 0x10, 0x33, 0x11, 0x87, 0xf8, 0x79, 0x3c,
  40355. 0x49, 0x7a, 0x8b, 0xce, 0xc1, 0x0a, 0x0e, 0xe1, 0xd5, 0x2a,
  40356. 0xac, 0xf0, 0x3a, 0x1d, 0x6a, 0x6a, 0xe5, 0xe1, 0x81, 0x70,
  40357. 0xad, 0xaf, 0x15, 0x4c, 0x2a, 0x70, 0x2a, 0x6b, 0x22, 0x0d,
  40358. 0x30, 0xe7, 0x56, 0xed, 0x2d, 0x4b, 0x85, 0x17, 0x49, 0x72,
  40359. 0x3a, 0x1b, 0x6f, 0x57, 0x1c, 0xf7, 0x72, 0x9e, 0x20, 0xdb,
  40360. 0x57, 0x1c, 0xfb, 0x36, 0x50, 0x52, 0xec, 0x5b, 0xd6, 0x6a,
  40361. 0x1b, 0xf8, 0x74, 0xad, 0xe6, 0x00, 0x74, 0x04, 0xc5, 0x99,
  40362. 0x83, 0xe4, 0x5a, 0x0c, 0xc3, 0xe8, 0x6d, 0x3a, 0xd7, 0x3c,
  40363. 0x3c, 0xc0, 0x1a, 0x28, 0xb3, 0x29, 0x7a, 0x10, 0x9e, 0x39,
  40364. 0x66, 0x5b, 0xc1, 0x38, 0xac, 0x21, 0x4e, 0xcd, 0x01, 0xf2,
  40365. 0xf6, 0x30, 0x2c, 0x2b, 0xb6, 0xbf, 0xf5, 0xea, 0x61, 0xaf,
  40366. 0x0c, 0xa6, 0x01, 0x11, 0x15, 0x19, 0x09, 0x8c, 0x7e, 0x69,
  40367. 0xdf, 0x3b, 0xea, 0xd3, 0x0a, 0x3a, 0xd7, 0xbd, 0xe1, 0x17,
  40368. 0xaf, 0x92, 0x3c, 0xf5, 0xfe, 0x35, 0xd6, 0xcf, 0x07, 0xa6,
  40369. 0xf7, 0xe9, 0xc1, 0x99, 0xed, 0x80, 0xe3, 0x12, 0xd5, 0x4b,
  40370. 0xb9, 0xdf, 0xaf, 0x4e, 0x52, 0xad, 0x8e, 0x66, 0x87, 0xe5,
  40371. 0x2c, 0xd0, 0x45, 0x70, 0xd9, 0x78, 0x8f, 0x4b, 0xf4, 0xe1,
  40372. 0xf1, 0x22, 0xf2, 0xe3, 0xed, 0x1f, 0xeb, 0xe9, 0x70, 0x31,
  40373. 0x4c, 0x65, 0x5f, 0x55, 0xee, 0x5d, 0xaa, 0x83, 0x87, 0x76,
  40374. 0xbe, 0x11, 0xae, 0xd7, 0xf2, 0xfb, 0x43, 0xe7, 0x17, 0x81,
  40375. 0x33, 0x15, 0x47, 0xa0, 0xf3, 0x8e, 0x84, 0x57, 0xff, 0x35,
  40376. 0x9e, 0x4a, 0x8a, 0xab, 0x50, 0x3a, 0x45, 0xe0, 0xc3, 0x73,
  40377. 0xca, 0x77, 0x61, 0x68, 0x38, 0xd0, 0xa3, 0x5f, 0x03, 0x8d,
  40378. 0x41, 0xc2, 0xd3, 0x4a, 0x17, 0xe0, 0xa8, 0xaa, 0x00, 0xf3,
  40379. 0xf2, 0x5b, 0xa8, 0xe1, 0x06, 0xa6, 0x2b, 0xdb, 0xe1, 0x74,
  40380. 0xbd, 0xc4, 0xd2, 0x2b, 0x55, 0x9a, 0xb0, 0xf8, 0x35, 0xd8,
  40381. 0x6b, 0xec, 0xdb, 0xc5, 0xf4, 0x6c, 0x40, 0x90, 0x6a, 0x68,
  40382. 0xc9, 0xb5, 0xcb, 0xbb, 0xd0, 0xb0, 0xbc, 0x9f, 0xb9, 0xaa,
  40383. 0x50, 0x14, 0x93, 0x3b, 0x9f, 0x25, 0xcb, 0x40, 0xb8, 0x08,
  40384. 0xcc, 0x13, 0xe5, 0xdc, 0x3f, 0x84, 0x96, 0xe0, 0x73, 0x7b,
  40385. 0x7d, 0x9e, 0x41, 0x92, 0x5d, 0xcc, 0xa4, 0xea, 0x4f, 0x93,
  40386. 0x0c, 0x40, 0x2e, 0x42, 0x8a, 0xe9, 0xb9, 0x12, 0x74, 0xbb,
  40387. 0x79, 0x7c, 0xb0, 0x37, 0x20, 0xb6, 0xaf, 0x43, 0x3a, 0x88,
  40388. 0x59, 0x7c, 0x68, 0x28, 0x5f, 0x98, 0xc2, 0xf0, 0x2a, 0xbc,
  40389. 0xa1, 0x61, 0x88, 0x1f, 0x43, 0xbc, 0x42, 0x8f, 0x43, 0xf3,
  40390. 0x7e, 0x16, 0x96, 0xfa, 0x92, 0x70, 0xaf, 0x3c, 0x9f, 0x4b,
  40391. 0xd9, 0x60, 0xe9, 0xf6, 0x2e, 0x84, 0xda, 0x88, 0x31, 0x34,
  40392. 0xa6, 0x85, 0x10, 0x05, 0xef, 0x40, 0xa8, 0xa5, 0x4f, 0x92,
  40393. 0x59, 0xf7, 0xe0, 0xc4, 0x2b, 0x12, 0x17, 0x71, 0xbe, 0x8c,
  40394. 0x4a, 0x02, 0xfe, 0x12, 0xb6, 0x3b, 0x85, 0x75, 0x37, 0xf3,
  40395. 0x73, 0x2d, 0x9c, 0x00, 0x5d, 0x80, 0xad, 0x20, 0x2f, 0x5a,
  40396. 0x0b, 0x17, 0x7e, 0x67, 0x72, 0x24, 0x5a, 0xb9, 0xf3, 0xb1,
  40397. 0x33, 0xa4, 0x57, 0x1d, 0x49, 0x72, 0x2c, 0x7f, 0x47, 0x15,
  40398. 0x07, 0xe0, 0x45, 0x14, 0xdd, 0x77, 0x86, 0x6d, 0x03, 0xbe,
  40399. 0x57, 0xd0, 0xaa, 0x18, 0xa6, 0xdd, 0x94, 0x18, 0x3f, 0x8a,
  40400. 0xf3, 0xb5, 0xd7, 0x5a, 0xec, 0xc8, 0x79, 0x7f, 0x51, 0x61,
  40401. 0x3c, 0x9b, 0xb2, 0x9b, 0xf3, 0xb4, 0x35, 0xd1, 0x38, 0xbf,
  40402. 0x37, 0xce, 0x54, 0xd1, 0xf8, 0xb6, 0x45, 0xeb, 0x52, 0x0d,
  40403. 0x9a, 0x09, 0x58, 0x0d, 0x2c, 0x0b, 0xb1, 0xf2, 0x30, 0x3a,
  40404. 0x95, 0xc1, 0x13, 0x91, 0xd2, 0x9f, 0x8d, 0x8d, 0xd0, 0x38,
  40405. 0x3e, 0x4c, 0xae, 0x4a, 0x55, 0xa7, 0x42, 0x11, 0x83, 0xc4,
  40406. 0x70, 0xf0, 0x2b, 0x68, 0x9e, 0x07, 0xad, 0xb7, 0x83, 0xc6,
  40407. 0x53, 0x3c, 0xfb, 0x0a, 0x5d, 0x24, 0xdc, 0xe1, 0x55, 0x72,
  40408. 0xcf, 0xce, 0x3e, 0xc8, 0xd0, 0x57, 0x8a, 0x82, 0x5e, 0x78,
  40409. 0x2b, 0x80, 0xc5, 0xb9, 0x09, 0x46, 0xf8, 0x90, 0x39, 0x52,
  40410. 0xa9, 0xce, 0x3f, 0x3d, 0x41, 0x3b, 0x28, 0x45, 0xa3, 0xb3,
  40411. 0x21, 0xc2, 0xcd, 0x14, 0x49, 0x41, 0x6c, 0x38, 0xda, 0x1b,
  40412. 0x5f, 0x16, 0x49, 0xf9, 0x65, 0x00, 0x4e, 0xb4, 0x20, 0x55,
  40413. 0x70, 0xe8, 0x58, 0x1a, 0x18, 0xbf, 0x41, 0xef, 0x31, 0xb1,
  40414. 0xe7, 0x8d, 0x89, 0xc1, 0x48, 0xe8, 0xf5, 0x57, 0x35, 0xfa,
  40415. 0xc1, 0x79, 0xee, 0x2c, 0xe8, 0x7d, 0xb6, 0x03, 0xcc, 0x66,
  40416. 0x09, 0x6f, 0x52, 0x84, 0x0a, 0x34, 0x18, 0x2c, 0x01, 0x45,
  40417. 0x81, 0x00, 0xe5, 0x5e, 0x8d, 0xae, 0x1c, 0x96, 0x8b, 0x45,
  40418. 0x73, 0x00, 0x0a, 0xb5, 0xcf, 0x8d, 0x0e, 0x35, 0x5d, 0x1a,
  40419. 0x0e, 0xbf, 0x64, 0x9a, 0x52, 0x20, 0x48, 0xc6, 0xb9, 0x40,
  40420. 0xd3, 0x2c, 0x52, 0xca, 0x93, 0xcf, 0xbb, 0x94, 0x06, 0xf3,
  40421. 0x97, 0xee, 0xcc, 0x5d, 0xa3, 0xea, 0xf8, 0x5a, 0x39, 0x77,
  40422. 0x34, 0xd7, 0xf6, 0x4e, 0xbe, 0x8a, 0x07, 0x5f, 0x51, 0x53,
  40423. 0xc5, 0x1b, 0x8c, 0x47, 0x8f, 0x34, 0x0e, 0x60, 0x0a, 0x90,
  40424. 0xe2, 0xda, 0x7b, 0xef, 0xd6, 0xf5, 0x5d, 0xe5, 0x32, 0x37,
  40425. 0x75, 0x99, 0x81, 0x4a, 0x2a, 0x78, 0x71, 0xdc, 0xf4, 0xe5,
  40426. 0xca, 0xd8, 0x6b, 0x3b, 0x90, 0x68, 0x2e, 0x93, 0xc5, 0x10,
  40427. 0x42, 0x5d, 0x38, 0x90, 0x32, 0x46, 0xea, 0x87, 0xe0, 0xbc,
  40428. 0xb8, 0x9a, 0x18, 0x20, 0x68, 0x85, 0x6d, 0x9b, 0xc9, 0x8f,
  40429. 0x9b, 0xd2, 0xbe, 0x15, 0x12, 0x68, 0xd0, 0xb0, 0x16, 0x5f,
  40430. 0xe2, 0x69, 0x1d, 0x04, 0x00, 0xfc, 0x63, 0x33, 0xcd, 0x1f,
  40431. 0x89, 0xcd, 0x52, 0xff, 0xec, 0x19, 0x69, 0x74, 0xa3, 0xce,
  40432. 0x4d, 0xab, 0x93, 0xe4, 0xc6, 0x13, 0x56, 0x27, 0xc9, 0x25,
  40433. 0x5a, 0x01, 0xb2, 0x36, 0x8b, 0x61, 0xe5, 0x8b, 0x98, 0xac,
  40434. 0xe4, 0x2a, 0xb6, 0x40, 0x9f, 0x42, 0xe4, 0x1b, 0x52, 0xf7,
  40435. 0xfd, 0xd8, 0x30, 0x07, 0x33, 0xf9, 0x47, 0xcb, 0x3c, 0xad,
  40436. 0x12, 0xc1, 0xcc, 0x29, 0x62, 0x49, 0x04, 0x0c, 0x23, 0x97,
  40437. 0x5a, 0xa4, 0x84, 0x67, 0xde, 0x5a, 0xe5, 0x36, 0xd2, 0x88,
  40438. 0xf1, 0xd4, 0xeb, 0x13, 0x81, 0x54, 0x51, 0x11, 0xe3, 0xba,
  40439. 0xbc, 0xee, 0xdd, 0x6c, 0xcd, 0xe6, 0xb4, 0xa1, 0x8b, 0x0b,
  40440. 0x66, 0xfb, 0x8e, 0x50, 0xa0, 0xda, 0x69, 0x8d, 0xcc, 0x2d,
  40441. 0xe4, 0x2c, 0xc4, 0x37, 0xdf, 0x61, 0xc0, 0x03, 0xbd, 0x8b,
  40442. 0x28, 0xca, 0xd2, 0x8c, 0x1c, 0xf1, 0xa4, 0x26, 0x69, 0xe5,
  40443. 0xcf, 0x45, 0xdb, 0x5a, 0x47, 0x79, 0xed, 0x9f, 0xf7, 0xd2,
  40444. 0xdb, 0xba, 0x46, 0x53, 0x4f, 0xce, 0xa8, 0xbe, 0x8f, 0x4a,
  40445. 0xd6, 0xdf, 0x2e, 0x06, 0xe6, 0x4c, 0x9a, 0xc1, 0xb6, 0x49,
  40446. 0xed, 0xc4, 0xeb, 0xaa, 0xa4, 0x29, 0x6d, 0xd4, 0xcc, 0x8c,
  40447. 0xb6, 0x40, 0x11, 0x39, 0x69, 0xf7, 0x75, 0xcd, 0xb1, 0x99,
  40448. 0x46, 0x4e, 0xde, 0xcb, 0xf6, 0x9d, 0x32, 0xf3, 0xc9, 0x47,
  40449. 0x47, 0x7a, 0xcb, 0xfb, 0xa3, 0x0c, 0x3b, 0xdf, 0xb7, 0xde,
  40450. 0xec, 0x99, 0xde, 0xb0, 0x26, 0x04, 0x34, 0xae, 0x6b, 0xfc,
  40451. 0x99, 0xbc, 0xde, 0xd5, 0xbe, 0xe7, 0xeb, 0xf9, 0xe7, 0xa6,
  40452. 0x01, 0x9a, 0x0c, 0x5e, 0x66, 0xe6, 0x53, 0xe4, 0xd1, 0x58,
  40453. 0xac, 0xda, 0x69, 0x77, 0x7b, 0x68, 0xd6, 0x30, 0x2a, 0x9c,
  40454. 0x6b, 0xbe, 0x9f, 0x3d, 0x71, 0xd6, 0x54, 0xcd, 0x59, 0x4e,
  40455. 0x1f, 0xe3, 0x83, 0x4e, 0xd1, 0x8e, 0xaf, 0x97, 0xa8, 0xe5,
  40456. 0xb6, 0x59, 0x77, 0xa8, 0x02, 0x20, 0xe4, 0xeb, 0x44, 0x71,
  40457. 0xbc, 0x07, 0x14, 0x79, 0x4f, 0x0c, 0x27, 0x06, 0x39, 0xcf,
  40458. 0x7c, 0xef, 0x2b, 0x9b, 0x5e, 0xc4, 0x6d, 0x79, 0x13, 0x00,
  40459. 0x43, 0x6f, 0x51, 0x77, 0xb5, 0xc3, 0x72, 0xad, 0x13, 0xa9,
  40460. 0xe5, 0x9a, 0x5b, 0x1a, 0x99, 0x74, 0xc0, 0x7a, 0xf9, 0xc5,
  40461. 0xb0, 0x58, 0x35, 0x1c, 0xa5, 0x51, 0xdb, 0xa1, 0x14, 0xcd,
  40462. 0x26, 0x71, 0xb1, 0xe7, 0xaa, 0x14, 0xa7, 0x46, 0x93, 0xd3,
  40463. 0x5c, 0x8c, 0x1a, 0x91, 0x77, 0x46, 0x2e, 0x15, 0xaa, 0x9e,
  40464. 0xf7, 0x2b, 0x79, 0x41, 0x76, 0xf7, 0x22, 0x53, 0x7d, 0x51,
  40465. 0xdb, 0x98, 0x3d, 0x5b, 0x78, 0x5f, 0xc3, 0xc9, 0x29, 0xa3,
  40466. 0xff, 0x75, 0x82, 0x06, 0x9a, 0x16, 0x5e, 0xa4, 0x79, 0x0d,
  40467. 0xd1, 0x6d, 0x08, 0xff, 0x43, 0xef, 0x9c, 0xf3, 0x1b, 0x7a,
  40468. 0x3f, 0x34, 0xbe, 0x19, 0x15, 0x06, 0x33, 0xdb, 0xa5, 0x71,
  40469. 0xcb, 0x5f, 0x6b, 0x8d, 0xbd, 0x5b, 0x32, 0x91, 0xb2, 0x37,
  40470. 0x3d, 0xb4, 0x40, 0x9e, 0x02, 0x9b, 0xb7, 0x68, 0x20, 0x58,
  40471. 0x5c, 0xab, 0xcb, 0xc8, 0x23, 0x2d, 0x77, 0xcc, 0x0b, 0xf6,
  40472. 0x78, 0x6b, 0x80, 0x06, 0x91, 0xa9, 0xfd, 0x7e, 0xfa, 0x25,
  40473. 0x98, 0x9f, 0xcc, 0x79, 0x0a, 0x1a, 0x54, 0x83, 0xac, 0x64,
  40474. 0x16, 0x90, 0xe5, 0xd9, 0xa7, 0xd7, 0x1b, 0x86, 0x0d, 0xe6,
  40475. 0xe6, 0x22, 0x2b, 0x1f, 0x44, 0x49, 0x98, 0x9c, 0x51, 0x6f,
  40476. 0xcf, 0x58, 0x4a, 0xfa, 0xfa, 0x84, 0x12, 0xa5, 0x10, 0xf4,
  40477. 0xca, 0xf0, 0x98, 0x2b, 0xc9, 0x03, 0x71, 0x37, 0xe7, 0xdc,
  40478. 0xc2, 0xb1, 0x4e, 0x64, 0xde, 0x4f, 0x46, 0x0d, 0x6b, 0x25,
  40479. 0x88, 0x5d, 0xd6, 0xff, 0x23, 0x46, 0x57, 0x36, 0x14, 0x18,
  40480. 0xa7, 0xcb, 0xb8, 0xbd, 0xf0, 0xc5, 0x37, 0x36, 0xee, 0xe1,
  40481. 0xed, 0x9f, 0x4d, 0xd4, 0x39, 0xe5, 0x92, 0xcf, 0x95, 0x4d,
  40482. 0x66, 0x36, 0x5d, 0xd0, 0xcc, 0x07, 0xcf, 0x15, 0x5a, 0xce,
  40483. 0x14, 0xb8, 0xda, 0x0d, 0x3d, 0x1b, 0x45, 0xc5, 0x2e, 0x34,
  40484. 0x43, 0x25, 0x02, 0x3a, 0xcd, 0x14, 0x45, 0xfb, 0x3e, 0xf9,
  40485. 0x88, 0x5d, 0x0d, 0x29, 0x31, 0xb9, 0xa1, 0xe6, 0x31, 0x18,
  40486. 0x52, 0x46, 0x3f, 0x22, 0x4f, 0x9f, 0x7a, 0x65, 0x36, 0x88,
  40487. 0xa3, 0x1c, 0x3e, 0x6f, 0x50, 0x7a, 0x36, 0xbe, 0x56, 0x7e,
  40488. 0x50, 0xcb, 0x7a, 0x10, 0xa0, 0xec, 0xf6, 0x82, 0xd6, 0x30,
  40489. 0x1c, 0xe8, 0x4c, 0x50, 0xf9, 0x3e, 0xdb, 0xac, 0xbe, 0x4f,
  40490. 0x90, 0xb1, 0xd5, 0x1b, 0x12, 0x95, 0xfb, 0xe8, 0x08, 0x64,
  40491. 0x56, 0x7c, 0x96, 0xcc, 0x90, 0xb1, 0xbc, 0xa0, 0xf5, 0x32,
  40492. 0x69, 0xb3, 0x5f, 0x27, 0x0f, 0xbe, 0xc9, 0xbd, 0xeb, 0xfa,
  40493. 0x4b, 0x5c, 0xc5, 0x99, 0x9e, 0x5a, 0x04, 0xcc, 0xd0, 0x4d,
  40494. 0x29, 0xe8, 0x84, 0x55, 0x8c, 0xd7, 0xc4, 0x06, 0x13, 0x4d,
  40495. 0x92, 0xe5, 0x98, 0x9c, 0x4c, 0xc1, 0xf7, 0xaf, 0x7b, 0xd5,
  40496. 0x2b, 0x92, 0x68, 0x68, 0x19, 0x70, 0x4c, 0x9e, 0x46, 0xb8,
  40497. 0x34, 0xeb, 0x01, 0x47, 0xbe, 0x59, 0xab, 0x0b, 0x22, 0x25,
  40498. 0xe7, 0x56, 0xa8, 0xb4, 0x93, 0x3c, 0xd5, 0x98, 0x9f, 0x61,
  40499. 0x2e, 0xfa, 0xcb, 0x5f, 0x5b, 0xd8, 0x09, 0x83, 0xe9, 0x40,
  40500. 0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
  40501. 0x0a, 0x93
  40502. };
  40503. #endif
  40504. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_sig[] = {
  40505. 0x20, 0xff, 0x12, 0xe1, 0x87, 0xf6, 0x11, 0x38, 0xff, 0x41, 0xd0, 0x8f,
  40506. 0xcd, 0x7e, 0xd1, 0xf6, 0x21, 0x17, 0xd0, 0x46, 0xe9, 0x86, 0x83, 0x1b,
  40507. 0xaf, 0xe5, 0x2b, 0x59, 0x21, 0xd1, 0x6b, 0xc9, 0xdb, 0x34, 0xdc, 0xba,
  40508. 0xfd, 0xd3, 0xf8, 0x71, 0x49, 0xd8, 0x31, 0xbc, 0x48, 0x83, 0x22, 0x7b,
  40509. 0xfd, 0x6a, 0x93, 0xa6, 0x39, 0x4c, 0xda, 0xdb, 0x15, 0xe7, 0x41, 0x14,
  40510. 0xb4, 0xb8, 0xfe, 0xb0, 0x1f, 0xf9, 0x0a, 0x2c, 0x0b, 0xc0, 0xac, 0x09,
  40511. 0x84, 0x69, 0x5e, 0x64, 0x8c, 0xa8, 0xee, 0xa1, 0x52, 0x22, 0xde, 0x0d,
  40512. 0xc7, 0x25, 0xef, 0xa8, 0xfd, 0x8c, 0xb9, 0x45, 0x4f, 0xa4, 0x9c, 0xbc,
  40513. 0x70, 0xf2, 0x88, 0xea, 0x79, 0x13, 0xb0, 0xfc, 0xe6, 0x41, 0x48, 0x1c,
  40514. 0x33, 0x48, 0xa2, 0x77, 0x75, 0x37, 0x9f, 0xc1, 0x86, 0x94, 0xcd, 0x69,
  40515. 0x98, 0x87, 0x47, 0x49, 0x75, 0x93, 0xf1, 0xa4, 0x2d, 0x8e, 0xa8, 0x7e,
  40516. 0x0f, 0x95, 0xf5, 0x3e, 0x5d, 0x31, 0x2d, 0xc9, 0x58, 0x1c, 0x42, 0xfd,
  40517. 0x79, 0x6a, 0x49, 0xa3, 0x84, 0xc5, 0x2e, 0x8d, 0x96, 0x9c, 0xc8, 0x05,
  40518. 0x93, 0xdb, 0x6d, 0xbf, 0x83, 0x34, 0xc2, 0x81, 0x47, 0x90, 0xc9, 0xa9,
  40519. 0x82, 0xbd, 0xe1, 0xc8, 0x89, 0xa2, 0x36, 0x47, 0xed, 0xfb, 0x47, 0x57,
  40520. 0x01, 0x1a, 0x75, 0x8c, 0x6b, 0x83, 0xcf, 0x56, 0xae, 0x52, 0x66, 0x8b,
  40521. 0xab, 0x7f, 0x0c, 0xec, 0xde, 0x5c, 0x13, 0xbe, 0xbd, 0x5b, 0x74, 0x28,
  40522. 0xb5, 0xd7, 0x68, 0xd5, 0xd2, 0xe9, 0x96, 0x3b, 0x55, 0xda, 0x3a, 0x93,
  40523. 0x3c, 0xd9, 0x9f, 0x53, 0x2a, 0x31, 0x84, 0x45, 0x3f, 0xee, 0x2b, 0xfc,
  40524. 0x92, 0xb0, 0x9c, 0xc6, 0x16, 0x16, 0x4f, 0x33, 0x41, 0x17, 0x58, 0xbe,
  40525. 0x5d, 0x57, 0x4b, 0x04, 0x82, 0xe3, 0xb3, 0x68, 0xdf, 0x7c, 0x93, 0xce,
  40526. 0x9d, 0xf6, 0x7e, 0x21, 0x3d, 0x28, 0x1c, 0xf0, 0x37, 0x46, 0xf2, 0xc2,
  40527. 0x73, 0x7c, 0xbe, 0x98, 0x0e, 0x09, 0x75, 0xa7, 0x21, 0x11, 0xa9, 0xd6,
  40528. 0xd1, 0x47, 0xac, 0xd0, 0x19, 0x48, 0x3b, 0x74, 0xc1, 0x3c, 0x37, 0x43,
  40529. 0x49, 0x12, 0x62, 0xee, 0xaf, 0x5c, 0x38, 0xf7, 0x8a, 0xce, 0xb3, 0x7a,
  40530. 0x05, 0x16, 0xd4, 0x71, 0x8b, 0xbe, 0x1a, 0xe0, 0x1e, 0xbc, 0x4b, 0x54,
  40531. 0x0f, 0xb5, 0x73, 0x2b, 0xb8, 0x3a, 0x75, 0xf0, 0x26, 0xcd, 0xf9, 0xca,
  40532. 0x32, 0xf9, 0x7e, 0x15, 0x38, 0x75, 0x9c, 0x4d, 0xbc, 0x11, 0xf8, 0xea,
  40533. 0x8e, 0xe8, 0x38, 0x17, 0xc5, 0x62, 0xf4, 0x34, 0xfb, 0xd6, 0xf5, 0x76,
  40534. 0xfc, 0xa3, 0xf3, 0x44, 0xf9, 0xab, 0x2e, 0x9a, 0x68, 0xcd, 0xa1, 0x29,
  40535. 0xff, 0xda, 0xe8, 0xb5, 0xb0, 0x20, 0x5d, 0x02, 0x01, 0x62, 0x26, 0x44,
  40536. 0x32, 0xc8, 0x94, 0xf8, 0xf1, 0xaa, 0xf9, 0xc2, 0x86, 0xcb, 0x55, 0x7f,
  40537. 0x8d, 0xb3, 0xf6, 0x63, 0xb1, 0xa4, 0x95, 0x57, 0xb8, 0x1d, 0xc3, 0x42,
  40538. 0xd2, 0x4b, 0x69, 0xcd, 0x7a, 0x10, 0x5b, 0x6a, 0x13, 0xd1, 0x02, 0x98,
  40539. 0x38, 0x87, 0x9b, 0x9a, 0x5a, 0x66, 0x73, 0xcb, 0x75, 0xd0, 0x7a, 0x4b,
  40540. 0xad, 0x23, 0x06, 0x1c, 0xc8, 0x6b, 0x0c, 0xa8, 0xfe, 0x7b, 0x8f, 0x65,
  40541. 0x50, 0xd7, 0xf7, 0x76, 0x88, 0x42, 0xe0, 0x5e, 0x18, 0x91, 0x8b, 0x99,
  40542. 0x37, 0x56, 0x08, 0x91, 0xe7, 0x01, 0xe7, 0x05, 0xd5, 0xed, 0x43, 0x25,
  40543. 0x71, 0x7e, 0x3e, 0xfc, 0xc4, 0xfd, 0xed, 0x8b, 0x85, 0x16, 0x8c, 0xe3,
  40544. 0x05, 0xee, 0x51, 0x02, 0xa4, 0x4b, 0xd8, 0x3c, 0xcf, 0x4d, 0x2f, 0x2d,
  40545. 0x68, 0x6e, 0xc1, 0xd5, 0xfa, 0x91, 0xfd, 0x6a, 0xe0, 0x64, 0x85, 0x35,
  40546. 0x9c, 0x75, 0xe6, 0x0d, 0xb8, 0xec, 0x97, 0x88, 0x62, 0x98, 0x78, 0x75,
  40547. 0xc7, 0x1e, 0x68, 0xa7, 0xb9, 0x7b, 0xab, 0x75, 0x7a, 0x72, 0x3c, 0x7b,
  40548. 0xab, 0x60, 0x03, 0xb7, 0x38, 0x13, 0xe4, 0x96, 0x6e, 0xcb, 0x95, 0xcc,
  40549. 0xdc, 0x6a, 0x47, 0x67, 0x77, 0xd7, 0x95, 0xc4, 0x87, 0x66, 0xc2, 0x7e,
  40550. 0x42, 0x90, 0x59, 0x4f, 0xd6, 0xf3, 0xf4, 0xa7, 0xd0, 0x29, 0xf9, 0x5d,
  40551. 0x4b, 0x06, 0x06, 0xf7, 0x6e, 0xb2, 0xab, 0xb0, 0x8e, 0x21, 0xa6, 0xff,
  40552. 0x5e, 0x7b, 0x47, 0xb6, 0x3a, 0xa6, 0x9e, 0x19, 0xf6, 0xdf, 0x9b, 0x3b,
  40553. 0x3d, 0x07, 0x37, 0xd1, 0x0b, 0xa8, 0xf3, 0x9c, 0x43, 0x89, 0xee, 0xba,
  40554. 0x03, 0xee, 0x38, 0x74, 0x13, 0x09, 0x8e, 0x47, 0x4e, 0xa9, 0x14, 0xf5,
  40555. 0xb0, 0x55, 0xe0, 0x03, 0xe5, 0xb9, 0x53, 0xef, 0x03, 0x15, 0x60, 0xb3,
  40556. 0x4a, 0x71, 0x31, 0x4b, 0xf1, 0xc8, 0xe4, 0x63, 0x9b, 0x8b, 0x78, 0x3c,
  40557. 0x1f, 0xac, 0x27, 0x20, 0xa8, 0x53, 0x7d, 0xdd, 0x72, 0xd3, 0x90, 0x8f,
  40558. 0x71, 0xa6, 0xa7, 0xeb, 0xb0, 0xeb, 0x42, 0x96, 0xa4, 0xc3, 0xba, 0xc6,
  40559. 0x3c, 0xe7, 0x7b, 0x15, 0x1e, 0xfa, 0x15, 0x23, 0x37, 0xf3, 0xc8, 0xb2,
  40560. 0xf9, 0x46, 0x04, 0xd1, 0x5e, 0x44, 0xd7, 0x8f, 0x70, 0xb1, 0x0a, 0xde,
  40561. 0x6a, 0xe3, 0xaf, 0x9e, 0x49, 0x55, 0x78, 0x79, 0x11, 0x22, 0x87, 0xa9,
  40562. 0x54, 0x7c, 0xb4, 0x83, 0xe1, 0x25, 0xcd, 0x89, 0xa6, 0x91, 0x21, 0x7b,
  40563. 0xbe, 0x3d, 0x2f, 0x46, 0xb5, 0x5b, 0x50, 0x1a, 0xc8, 0x8d, 0x32, 0xf3,
  40564. 0x62, 0x1f, 0x24, 0x64, 0xe8, 0xb6, 0x02, 0x4f, 0x1f, 0x52, 0x3c, 0x40,
  40565. 0xfc, 0x72, 0x38, 0xd4, 0xba, 0x40, 0x8e, 0xb7, 0xc0, 0x97, 0x06, 0x16,
  40566. 0xd5, 0xe3, 0x39, 0x45, 0xd7, 0x7c, 0x0e, 0xed, 0x6b, 0x19, 0x19, 0x0a,
  40567. 0x8e, 0xcb, 0x2b, 0xee, 0x4d, 0xa1, 0x5e, 0x84, 0x22, 0x66, 0xcd, 0x4f,
  40568. 0xb9, 0x1a, 0x25, 0x85, 0x02, 0xc0, 0x67, 0xc4, 0xd5, 0x1a, 0xcb, 0xbb,
  40569. 0xde, 0x4d, 0x3c, 0x3c, 0x62, 0x9f, 0x76, 0x8f, 0x15, 0x29, 0xa5, 0xbb,
  40570. 0x5a, 0x48, 0x38, 0x66, 0xfa, 0x56, 0x0a, 0x09, 0xbd, 0xdf, 0xdf, 0x4a,
  40571. 0xe7, 0x0e, 0xa6, 0xb1, 0xb5, 0x7c, 0xe1, 0xed, 0x8d, 0x63, 0x07, 0x42,
  40572. 0xf3, 0xf8, 0x15, 0x28, 0x7c, 0x09, 0xf5, 0x02, 0x69, 0x1b, 0x88, 0x1e,
  40573. 0x3d, 0xad, 0x5f, 0x46, 0xed, 0xab, 0x2b, 0x11, 0x96, 0x73, 0xa8, 0xe8,
  40574. 0xe6, 0x64, 0x7d, 0xae, 0x13, 0xa1, 0x7d, 0x54, 0xae, 0xc0, 0x82, 0xeb,
  40575. 0x2a, 0xd1, 0x76, 0xb7, 0x9f, 0xbd, 0x33, 0x8f, 0xe7, 0xe6, 0x79, 0x92,
  40576. 0xa6, 0xaf, 0x61, 0x91, 0x49, 0xbc, 0xd2, 0x3c, 0x6f, 0x8b, 0xbe, 0x8f,
  40577. 0x5f, 0x1f, 0x00, 0x2c, 0x2e, 0x2c, 0xa0, 0x14, 0xcf, 0x34, 0x42, 0x44,
  40578. 0x41, 0x11, 0xd7, 0x37, 0xd3, 0x99, 0x44, 0x36, 0x43, 0x03, 0xb9, 0x50,
  40579. 0x4f, 0xab, 0xfe, 0x48, 0xe2, 0x4b, 0xed, 0x51, 0x8b, 0xe0, 0x04, 0x3c,
  40580. 0x93, 0x28, 0x55, 0xc8, 0x5a, 0xb3, 0x52, 0x2c, 0x56, 0xbd, 0x43, 0xb9,
  40581. 0x4a, 0x6c, 0x4c, 0xcc, 0xda, 0xba, 0x9c, 0xe6, 0x3e, 0x50, 0x8b, 0x1a,
  40582. 0xe5, 0x83, 0xc1, 0x60, 0x55, 0xb2, 0x02, 0x16, 0x54, 0x33, 0x62, 0x69,
  40583. 0x7c, 0x7d, 0x94, 0xf2, 0xb0, 0x3a, 0x22, 0xf0, 0x21, 0x46, 0xd7, 0x94,
  40584. 0x53, 0xec, 0x63, 0x4c, 0x3e, 0xc3, 0x71, 0xd1, 0xb9, 0x2e, 0x16, 0xe8,
  40585. 0x17, 0x63, 0x7e, 0x0c, 0x83, 0x05, 0x72, 0xe6, 0x20, 0x60, 0x34, 0xae,
  40586. 0x0e, 0x54, 0xa0, 0x57, 0x75, 0x93, 0x2e, 0xb8, 0x6c, 0xec, 0xda, 0x44,
  40587. 0x1b, 0xac, 0xd6, 0x75, 0xc5, 0x79, 0x3c, 0xc2, 0xa6, 0xa2, 0x7f, 0x3a,
  40588. 0xb0, 0xec, 0xeb, 0xc1, 0xe6, 0xd6, 0xae, 0xac, 0x2e, 0x55, 0x30, 0x1c,
  40589. 0x81, 0xa4, 0x4c, 0x35, 0x0e, 0xd8, 0xa6, 0x4e, 0xea, 0x0e, 0xbf, 0x79,
  40590. 0xf7, 0xdf, 0x55, 0xfc, 0xf9, 0x24, 0xb0, 0xa6, 0xba, 0xc3, 0x72, 0x42,
  40591. 0x60, 0x06, 0x44, 0x03, 0xe3, 0x40, 0x3c, 0x2a, 0x13, 0xf7, 0xdf, 0x3d,
  40592. 0xb7, 0x0d, 0x86, 0x6c, 0xb0, 0x0f, 0x2e, 0x72, 0x91, 0x16, 0x4f, 0x5f,
  40593. 0xd0, 0x3e, 0x8c, 0x36, 0xed, 0xa8, 0x6f, 0xbc, 0x65, 0xb0, 0x65, 0x99,
  40594. 0x47, 0x50, 0xa5, 0x9c, 0xea, 0xee, 0x8a, 0x44, 0x70, 0xf5, 0x31, 0x1a,
  40595. 0xe9, 0x11, 0xc1, 0xce, 0xe0, 0x21, 0x52, 0x70, 0x89, 0xf7, 0xc3, 0x35,
  40596. 0xfa, 0x55, 0x5a, 0xc5, 0x10, 0x02, 0xc4, 0xc7, 0xf7, 0xe1, 0xaf, 0x49,
  40597. 0x48, 0x61, 0xe7, 0x0d, 0xa1, 0x2d, 0x7d, 0x03, 0x00, 0x38, 0xa7, 0xd5,
  40598. 0xd3, 0xbf, 0x95, 0x29, 0xed, 0xcc, 0x70, 0x3e, 0xbe, 0x95, 0x8a, 0xdf,
  40599. 0xaf, 0xbf, 0xec, 0xf8, 0x6a, 0x4f, 0x9e, 0x69, 0xee, 0x4e, 0x3d, 0x8b,
  40600. 0x58, 0xa0, 0x2e, 0xb5, 0x83, 0x6a, 0x0e, 0x04, 0xa4, 0xa9, 0x74, 0xcb,
  40601. 0x4f, 0xb0, 0x39, 0x37, 0x8f, 0xcf, 0xbf, 0x77, 0xe4, 0x1a, 0x74, 0xcf,
  40602. 0x0e, 0x0d, 0x2d, 0x6e, 0x1d, 0xba, 0xc1, 0xf5, 0x7c, 0x54, 0x6e, 0x92,
  40603. 0xec, 0x4b, 0x03, 0xc3, 0xa4, 0x44, 0xad, 0x3e, 0x4f, 0xa4, 0xd9, 0xe9,
  40604. 0x71, 0x3c, 0xe6, 0xb6, 0xbe, 0xe7, 0xfc, 0x72, 0x76, 0x86, 0x9a, 0x73,
  40605. 0xb1, 0xb3, 0xf3, 0x84, 0xb6, 0x2a, 0x40, 0x0b, 0x8c, 0xae, 0xb3, 0xc4,
  40606. 0xdc, 0xb5, 0x21, 0x85, 0x87, 0xdc, 0x19, 0x18, 0xd5, 0xba, 0xa4, 0x5e,
  40607. 0x88, 0x89, 0xa4, 0xf4, 0x88, 0x75, 0xc2, 0x7a, 0xb4, 0xee, 0x9d, 0x54,
  40608. 0x66, 0x97, 0x70, 0x08, 0x8f, 0x99, 0x84, 0x5d, 0x5e, 0xa7, 0x6f, 0x92,
  40609. 0xe8, 0xa3, 0x65, 0xfa, 0x0e, 0x87, 0xfb, 0x3c, 0xe9, 0x17, 0x2d, 0xc7,
  40610. 0x2d, 0x30, 0x8f, 0x41, 0x82, 0x68, 0x2b, 0xf1, 0x67, 0x8e, 0xf7, 0x05,
  40611. 0x78, 0xfa, 0xc3, 0x61, 0xba, 0x35, 0xe7, 0x2f, 0x19, 0xef, 0x71, 0x36,
  40612. 0xac, 0x5b, 0xf0, 0x45, 0x30, 0x70, 0xdc, 0xc7, 0xab, 0x7b, 0x62, 0x17,
  40613. 0x9d, 0xc4, 0x43, 0x6f, 0xfc, 0x02, 0x56, 0x5f, 0x65, 0xaa, 0x68, 0x3b,
  40614. 0x5c, 0xfa, 0x71, 0x28, 0x89, 0xe9, 0x28, 0x2f, 0x95, 0x4b, 0xfc, 0xe6,
  40615. 0xe7, 0xc8, 0x44, 0x28, 0x5c, 0x3c, 0x08, 0x5f, 0x9c, 0xbc, 0x41, 0x68,
  40616. 0x91, 0x98, 0x7a, 0x00, 0x63, 0xc9, 0x5c, 0x75, 0x8f, 0xcc, 0x33, 0x77,
  40617. 0x7b, 0xd0, 0x2d, 0xe8, 0xa2, 0x98, 0xa4, 0x1b, 0xfa, 0x09, 0x67, 0x7b,
  40618. 0x25, 0x96, 0x19, 0xf4, 0x77, 0x33, 0x20, 0x4f, 0x19, 0xf6, 0x9c, 0x6c,
  40619. 0x2e, 0xd9, 0x68, 0x95, 0xb0, 0xe2, 0x18, 0x06, 0xe5, 0x84, 0x8e, 0xf7,
  40620. 0xbf, 0x6c, 0x96, 0xa8, 0x9d, 0x37, 0xc7, 0x28, 0xa1, 0x3d, 0x90, 0x8c,
  40621. 0x40, 0x3d, 0xe2, 0x51, 0xfd, 0x55, 0x09, 0xf8, 0x83, 0x43, 0x44, 0x4d,
  40622. 0x1c, 0x8a, 0x8d, 0x36, 0x84, 0x64, 0xc4, 0xfa, 0x1d, 0x72, 0x04, 0x0b,
  40623. 0x1d, 0x49, 0x13, 0x88, 0x78, 0x5f, 0x07, 0x9b, 0xc8, 0x01, 0x9c, 0x3c,
  40624. 0xfc, 0xff, 0x0f, 0xd5, 0x13, 0xcd, 0x15, 0x98, 0xcc, 0xe6, 0x59, 0x1e,
  40625. 0x83, 0x38, 0x8f, 0x6c, 0x75, 0xbe, 0xdf, 0xe9, 0x1b, 0xc5, 0xb9, 0x6b,
  40626. 0xa4, 0x5a, 0x0c, 0xae, 0x98, 0x8d, 0x93, 0xfa, 0x76, 0x7f, 0x0d, 0x0b,
  40627. 0xe8, 0xa0, 0x3b, 0x9e, 0x5e, 0xc8, 0xa8, 0xcc, 0x02, 0xc9, 0x86, 0x9c,
  40628. 0x78, 0xaf, 0x6e, 0x6a, 0xf4, 0xfe, 0x49, 0xad, 0xc5, 0x93, 0xae, 0x62,
  40629. 0xbd, 0xe3, 0x3a, 0xa8, 0xf2, 0x60, 0xb5, 0x29, 0xde, 0x5f, 0x12, 0x02,
  40630. 0x2d, 0x43, 0x90, 0xf5, 0x9d, 0x9d, 0x97, 0x29, 0xfa, 0xdd, 0x60, 0x41,
  40631. 0x64, 0xb7, 0xa5, 0x03, 0x72, 0x10, 0x2b, 0xdd, 0x5b, 0x60, 0xe6, 0xf0,
  40632. 0xe1, 0xd7, 0xa5, 0x97, 0xec, 0xb4, 0x9a, 0x4c, 0x3e, 0x16, 0xa2, 0x82,
  40633. 0xb3, 0xc3, 0x3f, 0x3e, 0x5d, 0x32, 0xac, 0x5a, 0x40, 0xb4, 0x00, 0xfa,
  40634. 0xd9, 0x47, 0xe8, 0x77, 0xa8, 0x96, 0x5c, 0x60, 0x04, 0x9c, 0x5c, 0xdf,
  40635. 0x24, 0x3b, 0xa7, 0x4a, 0x58, 0x25, 0x12, 0x9a, 0xa8, 0x7b, 0x3e, 0x14,
  40636. 0xc8, 0x06, 0x79, 0x23, 0xea, 0x91, 0x7f, 0xe1, 0x78, 0x41, 0x6c, 0xdb,
  40637. 0x8c, 0xeb, 0x66, 0x35, 0x87, 0x87, 0x81, 0x65, 0x2c, 0xef, 0x3a, 0x6e,
  40638. 0xae, 0xb3, 0x6c, 0xe9, 0x86, 0x50, 0x6d, 0x89, 0xd6, 0x27, 0x0a, 0xdb,
  40639. 0xf8, 0xd4, 0xb8, 0x85, 0x8e, 0x37, 0xa6, 0x56, 0xf7, 0x58, 0x18, 0x4c,
  40640. 0x44, 0xcf, 0xeb, 0xc4, 0x79, 0x19, 0xfc, 0x2e, 0x53, 0x18, 0x0e, 0x7b,
  40641. 0x51, 0x86, 0xf3, 0x59, 0x13, 0xb2, 0xaf, 0xd3, 0xee, 0xf4, 0xd5, 0xbf,
  40642. 0x2c, 0xb8, 0x6d, 0x71, 0x74, 0x7c, 0x67, 0x54, 0xa7, 0x4b, 0x03, 0xa9,
  40643. 0x1b, 0x62, 0x95, 0x9f, 0xc3, 0xf0, 0x71, 0x39, 0x2d, 0x26, 0xaf, 0xaf,
  40644. 0xa7, 0xa5, 0x58, 0xf8, 0xf8, 0x8a, 0xe0, 0x62, 0x90, 0x3f, 0x72, 0x9d,
  40645. 0x21, 0x82, 0x76, 0x3e, 0x4c, 0x5d, 0xe0, 0xb5, 0x67, 0x23, 0xe3, 0x13,
  40646. 0x1a, 0x29, 0xa3, 0xda, 0xa4, 0xb4, 0x5c, 0x1d, 0x47, 0xdf, 0xdf, 0xc9,
  40647. 0x93, 0x6c, 0xb2, 0xb5, 0x22, 0xb3, 0x47, 0x2b, 0xcf, 0xf0, 0x36, 0x87,
  40648. 0x51, 0x3c, 0x79, 0x41, 0x70, 0xbd, 0xea, 0x70, 0xa2, 0x29, 0x90, 0x55,
  40649. 0x30, 0x6f, 0x3e, 0x50, 0xc8, 0x38, 0xd6, 0xfa, 0x6f, 0xe3, 0x39, 0x67,
  40650. 0x88, 0x52, 0x1f, 0xd3, 0x52, 0xbf, 0x3e, 0x7b, 0x2a, 0xe5, 0x1e, 0xcd,
  40651. 0xf9, 0xf1, 0x91, 0x1d, 0x04, 0x61, 0x25, 0xbb, 0xe1, 0x33, 0xe3, 0x66,
  40652. 0x46, 0xed, 0x06, 0x8d, 0xc3, 0x4f, 0x20, 0xc6, 0x24, 0xa7, 0xb5, 0x49,
  40653. 0x3b, 0xc7, 0xe6, 0xa0, 0x77, 0x58, 0xd9, 0x70, 0xb1, 0xf5, 0xec, 0x94,
  40654. 0x19, 0xf3, 0x5b, 0x0f, 0x9a, 0xe4, 0xad, 0x37, 0x81, 0xaf, 0x68, 0x7b,
  40655. 0xe5, 0x67, 0xb5, 0xae, 0x7f, 0x2d, 0x64, 0x78, 0x68, 0x5a, 0xd1, 0x8f,
  40656. 0x1c, 0xc0, 0xc3, 0x5b, 0x21, 0x77, 0xe4, 0xa8, 0x5d, 0x05, 0x50, 0xc1,
  40657. 0x92, 0xee, 0x36, 0x2d, 0xd2, 0xff, 0xee, 0xc2, 0x11, 0x99, 0xee, 0xd7,
  40658. 0x48, 0xfb, 0x6a, 0xa3, 0xc9, 0xb7, 0x0c, 0xc1, 0xe5, 0x12, 0xbf, 0x6f,
  40659. 0x58, 0x66, 0x35, 0x34, 0x26, 0xaa, 0xbe, 0xc3, 0x33, 0x86, 0xfd, 0xc0,
  40660. 0x1c, 0xa5, 0xe4, 0x1e, 0x91, 0xc4, 0x55, 0x4e, 0xf1, 0xcb, 0xd2, 0x0b,
  40661. 0xe8, 0x0d, 0x89, 0x6a, 0x00, 0xbd, 0x7b, 0xf5, 0x3d, 0x1a, 0x4a, 0x48,
  40662. 0xfc, 0xf0, 0x5b, 0xcd, 0xdb, 0xb2, 0xa0, 0x27, 0x4b, 0x8f, 0xf7, 0x87,
  40663. 0x78, 0x13, 0xdb, 0x3f, 0xfb, 0x0b, 0xda, 0x22, 0xb3, 0x2b, 0x3a, 0x38,
  40664. 0xd2, 0x29, 0x73, 0x77, 0xb8, 0xd6, 0xec, 0xab, 0xb4, 0xfe, 0xbe, 0xbb,
  40665. 0x6e, 0xe2, 0xc8, 0x45, 0x7b, 0x0d, 0x36, 0x28, 0x0f, 0x45, 0x72, 0xea,
  40666. 0x6d, 0x38, 0x02, 0x5e, 0x48, 0x89, 0x12, 0x24, 0x1b, 0x33, 0x0f, 0xe9,
  40667. 0xf4, 0xce, 0xf8, 0x27, 0x16, 0x37, 0x29, 0xae, 0xe8, 0x22, 0x03, 0x31,
  40668. 0xa9, 0xa0, 0x73, 0x0c, 0x40, 0xe4, 0xfc, 0x6b, 0xe2, 0x1c, 0x8d, 0x7c,
  40669. 0x40, 0x82, 0x72, 0x28, 0xd0, 0x7d, 0xe5, 0xef, 0x05, 0x14, 0x80, 0x28,
  40670. 0x11, 0x32, 0x0d, 0x63, 0x8a, 0xc3, 0x7c, 0xfe, 0xf5, 0x06, 0x0e, 0xb0,
  40671. 0x78, 0x5c, 0x3a, 0xb6, 0x54, 0x37, 0x46, 0xa7, 0x43, 0x4f, 0x05, 0xec,
  40672. 0xe4, 0x9f, 0xd8, 0x55, 0x1f, 0x70, 0xb3, 0xe6, 0xbc, 0x46, 0x34, 0x9e,
  40673. 0xfc, 0xa4, 0x57, 0x8f, 0x0f, 0x25, 0x6f, 0x9f, 0xb3, 0x80, 0x21, 0x0b,
  40674. 0xa1, 0xca, 0x59, 0xcd, 0x37, 0xf7, 0xc9, 0xcb, 0xbe, 0x91, 0xad, 0x07,
  40675. 0x4f, 0xc7, 0x4e, 0x04, 0xbd, 0x38, 0x8b, 0x63, 0xb5, 0x51, 0xac, 0xc8,
  40676. 0x83, 0x3a, 0xa7, 0xe1, 0x77, 0xbc, 0xa4, 0x0c, 0x6c, 0x50, 0xeb, 0x46,
  40677. 0xe1, 0x45, 0x9a, 0x7b, 0x01, 0xca, 0x54, 0xf0, 0x0f, 0xa0, 0x1f, 0x43,
  40678. 0x9a, 0x19, 0x70, 0x2e, 0x70, 0x5a, 0xcf, 0x3b, 0x1b, 0x41, 0xfd, 0xd3,
  40679. 0x9a, 0xa2, 0x36, 0x14, 0xf0, 0xdd, 0xb0, 0x12, 0x6d, 0xcf, 0x55, 0x3f,
  40680. 0xef, 0x0a, 0xc1, 0x80, 0xa9, 0x68, 0xc3, 0x98, 0x03, 0x46, 0x34, 0xce,
  40681. 0x91, 0xb2, 0x7a, 0x94, 0xd2, 0xe7, 0xb9, 0x9c, 0x56, 0xb8, 0xf8, 0xd6,
  40682. 0xff, 0xbf, 0x8b, 0x39, 0x45, 0x04, 0x45, 0xc9, 0xa2, 0xe2, 0xbb, 0x50,
  40683. 0x68, 0x13, 0x32, 0x1e, 0x09, 0x51, 0xb7, 0xb9, 0xcf, 0x5f, 0xcc, 0x54,
  40684. 0xd2, 0xf3, 0xc1, 0x9d, 0xa0, 0x8d, 0x22, 0xc8, 0x7e, 0x1b, 0xc6, 0x14,
  40685. 0xde, 0x5f, 0x52, 0xb4, 0x69, 0x71, 0xca, 0x58, 0x1d, 0x1e, 0x89, 0xcb,
  40686. 0x56, 0x78, 0x7a, 0x85, 0xee, 0xfd, 0xf6, 0x7e, 0xbe, 0x49, 0x9b, 0xb1,
  40687. 0x05, 0x95, 0x12, 0xe9, 0x63, 0xbd, 0x61, 0x9a, 0x26, 0xf9, 0x0b, 0x9f,
  40688. 0x23, 0x0a, 0x59, 0x55, 0x93, 0xd3, 0x2d, 0xca, 0x66, 0x45, 0x03, 0xb7,
  40689. 0xf0, 0x88, 0x9e, 0xc1, 0x11, 0xbb, 0x62, 0x2c, 0x6f, 0xac, 0x3e, 0x87,
  40690. 0xd7, 0xe6, 0x4a, 0x44, 0x83, 0x04, 0x5d, 0x5d, 0xbc, 0x3c, 0xce, 0x83,
  40691. 0x2b, 0x11, 0x42, 0x02, 0x73, 0x1c, 0x24, 0x90, 0xd9, 0x1a, 0x7d, 0x96,
  40692. 0x82, 0x33, 0x75, 0x1e, 0x59, 0xea, 0xa7, 0x99, 0xe1, 0x5b, 0xdc, 0xe4,
  40693. 0x07, 0xc5, 0x48, 0x07, 0xb4, 0xbc, 0x80, 0x0e, 0xbd, 0x63, 0x6e, 0x66,
  40694. 0xf1, 0x12, 0xb6, 0x67, 0xe0, 0x14, 0x74, 0x9f, 0xbb, 0xb3, 0xb8, 0x16,
  40695. 0xd0, 0x25, 0xe9, 0x21, 0x80, 0x1a, 0x32, 0xb0, 0x58, 0x9a, 0x62, 0x17,
  40696. 0x18, 0x9d, 0x64, 0x2d, 0x47, 0x89, 0x82, 0x3b, 0x8c, 0x5d, 0x60, 0xc4,
  40697. 0x54, 0x69, 0xaa, 0xb4, 0x6a, 0x1d, 0x16, 0xb0, 0xe2, 0x5d, 0x7d, 0xeb,
  40698. 0xb9, 0x80, 0x37, 0xcd, 0x5b, 0xf0, 0xa1, 0xa8, 0x39, 0xb2, 0xd6, 0x3a,
  40699. 0xc8, 0xcd, 0xca, 0xaf, 0xcb, 0x3b, 0x54, 0xc2, 0x67, 0x49, 0xf3, 0xf1,
  40700. 0x11, 0x4d, 0x53, 0x7c, 0x46, 0x8d, 0x22, 0xf6, 0x9a, 0x0d, 0x9e, 0xda,
  40701. 0x37, 0xc6, 0x06, 0x00, 0xca, 0xb6, 0xb6, 0x99, 0xc5, 0xb6, 0x81, 0x7e,
  40702. 0x87, 0x62, 0xcf, 0x07, 0x76, 0xc1, 0x5f, 0xfe, 0x86, 0xfc, 0x5b, 0xa0,
  40703. 0xac, 0xca, 0xcb, 0x7d, 0xf5, 0x5a, 0xc2, 0x5e, 0x41, 0x48, 0x35, 0xc4,
  40704. 0x71, 0x9d, 0xc4, 0x0a, 0x79, 0x6f, 0xe3, 0x6d, 0x47, 0xd4, 0xaa, 0xfd,
  40705. 0x97, 0xe7, 0xb0, 0x7e, 0x61, 0xf1, 0x7d, 0x7e, 0xf8, 0x78, 0x4c, 0x2e,
  40706. 0x65, 0x51, 0xeb, 0x99, 0xd0, 0x3e, 0x24, 0x4c, 0xe0, 0x40, 0x7e, 0x2d,
  40707. 0xf7, 0x00, 0x9d, 0x50, 0x87, 0xce, 0x1f, 0x9a, 0xd2, 0x76, 0x00, 0x09,
  40708. 0xeb, 0x10, 0x1b, 0x4c, 0xf1, 0x43, 0x0e, 0x35, 0xbb, 0x23, 0x2e, 0x26,
  40709. 0x3d, 0x66, 0xa3, 0x0f, 0xf6, 0x10, 0x8b, 0x67, 0xce, 0x66, 0xfd, 0xb5,
  40710. 0x07, 0xdc, 0x04, 0x69, 0xad, 0xe0, 0x4d, 0xdf, 0xdb, 0x2f, 0x87, 0xf7,
  40711. 0xde, 0xc3, 0x77, 0x89, 0x71, 0xfd, 0x70, 0x38, 0xed, 0xe6, 0x27, 0xb1,
  40712. 0xbd, 0x94, 0x5f, 0x39, 0x20, 0x72, 0x59, 0xc4, 0x39, 0xd0, 0x20, 0x5d,
  40713. 0xe2, 0xe7, 0xe0, 0x00, 0x61, 0xc7, 0x65, 0xbd, 0xef, 0x05, 0xb3, 0xc7,
  40714. 0x7e, 0xae, 0xc5, 0x83, 0x7f, 0xc1, 0x32, 0x4e, 0x2a, 0x17, 0x64, 0x4e,
  40715. 0x2a, 0x9a, 0x2d, 0x26, 0x99, 0xa2, 0xd7, 0x37, 0x3a, 0x10, 0x6a, 0x89,
  40716. 0x72, 0x43, 0x0e, 0x3a, 0x03, 0x4c, 0xf9, 0xfe, 0xe8, 0xfc, 0x87, 0x71,
  40717. 0x37, 0x71, 0x5a, 0x05, 0xbc, 0x4e, 0x20, 0x4c, 0xd7, 0xf9, 0x8d, 0x4e,
  40718. 0xb8, 0xb8, 0x56, 0x07, 0xc8, 0x6e, 0x34, 0x6d, 0x45, 0x83, 0x34, 0xf0,
  40719. 0x77, 0xfb, 0x18, 0xec, 0x72, 0xf6, 0x4c, 0xfb, 0xba, 0x84, 0xe9, 0x89,
  40720. 0x3d, 0xfd, 0xb7, 0x0d, 0x70, 0xae, 0xa4, 0x48, 0x6b, 0x39, 0xf8, 0x62,
  40721. 0xc0, 0x7f, 0x0c, 0xf2, 0xa3, 0xfa, 0x7a, 0x64, 0x83, 0x57, 0x7d, 0x4c,
  40722. 0x04, 0x96, 0xd7, 0x9d, 0x10, 0x8b, 0x34, 0x48, 0x17, 0xff, 0x74, 0x5c,
  40723. 0x9c, 0xbe, 0xeb, 0xe5, 0x52, 0x94, 0x6a, 0x34, 0x6f, 0xf7, 0x95, 0x32,
  40724. 0x38, 0x5a, 0x9b, 0x08, 0xf6, 0xda, 0x8c, 0x0f, 0x9c, 0x5d, 0x04, 0x45,
  40725. 0xd4, 0xe9, 0xa4, 0x7a, 0xc4, 0xfd, 0x70, 0xfe, 0xa1, 0x3d, 0x21, 0xa0,
  40726. 0x01, 0xe5, 0x21, 0xca, 0xa7, 0xd9, 0xf1, 0x9f, 0x45, 0xe1, 0xe8, 0x2d,
  40727. 0x27, 0xe6, 0x87, 0xc8, 0x0d, 0xad, 0x13, 0xdb, 0xfe, 0x2f, 0xaa, 0x2b,
  40728. 0xdc, 0xa6, 0x1a, 0xc9, 0x19, 0x78, 0x1a, 0x1f, 0x10, 0xcf, 0x31, 0xe1,
  40729. 0x06, 0x28, 0x66, 0xb3, 0xa7, 0xa2, 0xa6, 0xf1, 0x3b, 0x2d, 0xd3, 0x81,
  40730. 0xaf, 0x6f, 0xc9, 0x88, 0x76, 0xe9, 0x83, 0x6c, 0x52, 0xb9, 0x70, 0x51,
  40731. 0x87, 0x6b, 0x8b, 0xbd, 0x5b, 0x9c, 0xa9, 0xf3, 0xcb, 0x55, 0xd1, 0x76,
  40732. 0x40, 0xe1, 0x90, 0xb9, 0x4c, 0xbd, 0xab, 0x1d, 0xa0, 0x5b, 0x5b, 0x34,
  40733. 0x14, 0x2f, 0x87, 0x8f, 0x63, 0xa0, 0x2d, 0x29, 0x4e, 0x50, 0x4b, 0x18,
  40734. 0x5f, 0x86, 0xac, 0x1b, 0x93, 0xe9, 0x59, 0x38, 0xa1, 0x2a, 0x36, 0x21,
  40735. 0xb2, 0xa4, 0xc0, 0x79, 0xc1, 0x60, 0xfc, 0x0f, 0xbf, 0x99, 0x04, 0x9d,
  40736. 0x4b, 0x17, 0x60, 0x5b, 0xcd, 0x78, 0x03, 0xd7, 0x7c, 0x4b, 0x9b, 0x17,
  40737. 0x58, 0x24, 0x60, 0xb8, 0x08, 0x92, 0x48, 0x4f, 0x66, 0x42, 0x9a, 0x98,
  40738. 0x2a, 0x99, 0x9a, 0x8f, 0xdd, 0xd7, 0x09, 0xf3, 0x22, 0x66, 0x62, 0xef,
  40739. 0xe5, 0x64, 0xd3, 0xdf, 0x31, 0xaa, 0x84, 0x4c, 0xa5, 0x3f, 0x4e, 0x27,
  40740. 0x48, 0x37, 0x96, 0x63, 0xbf, 0x8d, 0xe1, 0xf0, 0xd1, 0xef, 0x95, 0x1a,
  40741. 0xe6, 0xf4, 0x02, 0x61, 0xbf, 0xe3, 0xbc, 0x8b, 0x3d, 0x0b, 0x77, 0x91,
  40742. 0xc0, 0x5d, 0xfb, 0xe6, 0x7e, 0xab, 0x5e, 0xc5, 0x1c, 0x5b, 0x16, 0xfd,
  40743. 0x88, 0xa4, 0x78, 0x4c, 0x06, 0x77, 0xc3, 0x6e, 0x84, 0x0c, 0xda, 0xbf,
  40744. 0xf3, 0x8e, 0xd3, 0x61, 0x65, 0xac, 0xf2, 0x18, 0x70, 0x68, 0x84, 0x6f,
  40745. 0x9f, 0x3a, 0x94, 0x81, 0xa6, 0xc7, 0xc3, 0x92, 0xee, 0x4b, 0x20, 0x15,
  40746. 0x4e, 0x03, 0x76, 0x51, 0x5b, 0x4e, 0xe1, 0x5c, 0x51, 0x5e, 0x1b, 0x9c,
  40747. 0x30, 0x25, 0x79, 0xdd, 0x70, 0x12, 0xec, 0xdc, 0x45, 0x95, 0x45, 0x43,
  40748. 0xcd, 0xbb, 0xae, 0xa0, 0x0d, 0x43, 0xb4, 0xc9, 0x8c, 0x62, 0xfd, 0x7b,
  40749. 0xed, 0x50, 0x78, 0xb7, 0xa6, 0x94, 0xcb, 0x98, 0xb0, 0xbe, 0x09, 0xd9,
  40750. 0x0c, 0xb2, 0xc4, 0x8b, 0x96, 0x93, 0xd9, 0x26, 0xc6, 0x6d, 0x26, 0x93,
  40751. 0x32, 0x4e, 0x86, 0x72, 0x74, 0x92, 0x00, 0x72, 0x0b, 0x20, 0xa3, 0x2b,
  40752. 0x94, 0xe6, 0x10, 0x56, 0x5a, 0x41, 0x71, 0x92, 0x08, 0xce, 0x6c, 0xc4,
  40753. 0x1d, 0x9e, 0x71, 0x82, 0x64, 0x23, 0xe5, 0x15, 0xef, 0x4a, 0x7c, 0x4d,
  40754. 0xe3, 0x92, 0xbc, 0xa3, 0xa2, 0x29, 0xb7, 0x46, 0xfa, 0x8f, 0x9f, 0xc2,
  40755. 0x5d, 0xe4, 0xc0, 0x9c, 0x3f, 0x40, 0x17, 0xae, 0x44, 0xf3, 0x28, 0x10,
  40756. 0x29, 0x24, 0xa9, 0x1c, 0x9e, 0xd2, 0x55, 0x4c, 0xee, 0x45, 0xfe, 0x4a,
  40757. 0x45, 0x12, 0xf5, 0xde, 0xc7, 0x64, 0x15, 0xc3, 0x4a, 0x77, 0x63, 0x05,
  40758. 0x8d, 0xa6, 0x31, 0xa0, 0xad, 0x64, 0xaf, 0x3c, 0x69, 0x2c, 0x25, 0x78,
  40759. 0xae, 0xa0, 0x88, 0x96, 0x8a, 0xc2, 0x9b, 0x8d, 0xee, 0x6f, 0x2e, 0x79,
  40760. 0x1f, 0xec, 0x32, 0x35, 0x75, 0x83, 0x19, 0x8b, 0xda, 0xca, 0xd0, 0xaf,
  40761. 0x6a, 0x6c, 0x42, 0xe8, 0x81, 0xb5, 0x69, 0x31, 0x0b, 0x7d, 0xbc, 0xd8,
  40762. 0xd2, 0xb7, 0x7a, 0x8f, 0xfa, 0xcf, 0x91, 0x07, 0x1f, 0xda, 0xa9, 0x1f,
  40763. 0xb7, 0x2d, 0xff, 0x50, 0x15, 0x2a, 0xef, 0x8c, 0xa1, 0xe3, 0x7f, 0x08,
  40764. 0x95, 0xf2, 0x99, 0x83, 0x1f, 0x97, 0x71, 0x3e, 0x35, 0x3c, 0x8c, 0xe7,
  40765. 0x08, 0xd8, 0xa6, 0x1f, 0x0c, 0xa6, 0x52, 0xdc, 0x73, 0xa0, 0xfc, 0xd2,
  40766. 0x73, 0xe9, 0x27, 0x9d, 0xfd, 0x7a, 0x4a, 0x29, 0xd3, 0x12, 0x26, 0x13,
  40767. 0x0f, 0xce, 0xea, 0x56, 0x99, 0x61, 0x78, 0x47, 0x2c, 0xa0, 0x16, 0xa0,
  40768. 0xe2, 0x64, 0x97, 0x57, 0x31, 0xf0, 0x32, 0x5b, 0x44, 0x93, 0x76, 0x8b,
  40769. 0x59, 0x63, 0x5c, 0x5b, 0x0f, 0xe1, 0xe7, 0x74, 0x98, 0x11, 0x2d, 0x90,
  40770. 0xe4, 0xde, 0xd4, 0x3a, 0xc2, 0xfd, 0x24, 0xe3, 0x1f, 0x7a, 0xf4, 0x40,
  40771. 0xbb, 0x51, 0x92, 0x8f, 0x68, 0x9c, 0x51, 0xab, 0xdc, 0xf6, 0x1e, 0x96,
  40772. 0xca, 0x56, 0x5c, 0x92, 0xca, 0xb2, 0x1b, 0x2e, 0x6d, 0x20, 0x28, 0xb3,
  40773. 0x0a, 0x8e, 0xfd, 0xa9, 0xa2, 0x38, 0x74, 0x60, 0x37, 0xa6, 0x96, 0x02,
  40774. 0x20, 0x8a, 0x9a, 0x2b, 0x8c, 0xb9, 0x6d, 0xec, 0xff, 0xbf, 0x88, 0xbd,
  40775. 0x6c, 0xb4, 0x10, 0xbd, 0xfa, 0x5a, 0xeb, 0xb2, 0x6b, 0x74, 0x13, 0x2d,
  40776. 0xa5, 0xdb, 0x60, 0x93, 0xc6, 0xed, 0x39, 0x4f, 0xc5, 0x63, 0xe1, 0x9e,
  40777. 0x57, 0x1f, 0xe7, 0x47, 0xa4, 0xfb, 0x7f, 0xfa, 0x3a, 0x46, 0x50, 0x3a,
  40778. 0xd8, 0xd3, 0x83, 0xf5, 0xe6, 0x5e, 0xf8, 0x09, 0x0d, 0xfa, 0x33, 0xe1,
  40779. 0x50, 0xe4, 0x36, 0x3e, 0x0a, 0x5d, 0xe6, 0xf8, 0x2e, 0x17, 0x87, 0x8f,
  40780. 0xe1, 0x8c, 0x82, 0x73, 0xbd, 0xdd, 0x3b, 0x77, 0x47, 0x9f, 0x42, 0xd7,
  40781. 0xf4, 0x2d, 0x6c, 0xef, 0xcc, 0x22, 0x15, 0x3c, 0xe9, 0x26, 0xea, 0xbc,
  40782. 0xee, 0x09, 0xd3, 0xea, 0x84, 0x0f, 0x46, 0xa8, 0xe0, 0xda, 0xc5, 0x57,
  40783. 0x02, 0x54, 0xb6, 0x88, 0x2b, 0x37, 0xe5, 0x96, 0xc5, 0x33, 0xb7, 0x45,
  40784. 0x5d, 0xb7, 0xc7, 0xfd, 0xa0, 0xfa, 0x85, 0x1b, 0x2f, 0xe1, 0xec, 0x89,
  40785. 0xc6, 0xb2, 0x51, 0x71, 0xcb, 0x08, 0x82, 0x3e, 0xc9, 0xed, 0x80, 0x9d,
  40786. 0x37, 0x31, 0x9d, 0x15, 0xde, 0x24, 0x6f, 0xbd, 0x0e, 0x73, 0xa2, 0xb8,
  40787. 0x7e, 0x29, 0x7e, 0x96, 0xe4, 0xbb, 0xd6, 0x23, 0x17, 0xff, 0x33, 0x97,
  40788. 0x9c, 0x87, 0xe0, 0xe5, 0x0f, 0xb9, 0xb6, 0x31, 0x33, 0xad, 0xf8, 0xd8,
  40789. 0xdb, 0xa0, 0x71, 0x13, 0xe4, 0x1c, 0xce, 0xd0, 0x7e, 0x65, 0x7b, 0xa0,
  40790. 0x38, 0x17, 0x53, 0x4f, 0x71, 0x75, 0x6d, 0x02, 0x61, 0xc4, 0x52, 0xf8,
  40791. 0xe4, 0x2e, 0xbc, 0x52, 0xc1, 0xb1, 0x7e, 0x83, 0x0a, 0xa1, 0xd1, 0xcd,
  40792. 0x2f, 0xa0, 0x30, 0xfd, 0x41, 0x86, 0x7f, 0x26, 0xd1, 0xe7, 0xfc, 0xd7,
  40793. 0xc7, 0x37, 0xe5, 0x11, 0xa6, 0xc0, 0x9a, 0x75, 0x18, 0x04, 0x36, 0xca,
  40794. 0x8e, 0x26, 0x7d, 0xcf, 0xa2, 0x6a, 0x94, 0x9b, 0xc4, 0xf7, 0xc7, 0xeb,
  40795. 0x51, 0x13, 0xa3, 0x6f, 0x8c, 0x80, 0x5f, 0xae, 0xf0, 0x18, 0xa0, 0x88,
  40796. 0xe0, 0x8d, 0xb7, 0x80, 0x4e, 0x8c, 0xec, 0xc8, 0x7b, 0xeb, 0xac, 0x29,
  40797. 0xb7, 0x4a, 0x0f, 0x33, 0xdd, 0x9d, 0x89, 0x0a, 0x10, 0xb0, 0xce, 0x74,
  40798. 0x59, 0xa2, 0x62, 0x91, 0xc9, 0xac, 0x56, 0xcd, 0x69, 0xd3, 0x01, 0x6d,
  40799. 0x51, 0xe7, 0x04, 0xc3, 0xfb, 0xe9, 0x79, 0x1b, 0x72, 0x72, 0x1a, 0x90,
  40800. 0x0a, 0x20, 0x55, 0x85, 0xc1, 0x8b, 0xeb, 0x1e, 0x9f, 0x9f, 0x4a, 0x81,
  40801. 0x47, 0x97, 0x96, 0xbc, 0xc2, 0xe4, 0xc2, 0xfe, 0xa0, 0x20, 0xda, 0x70,
  40802. 0x0c, 0x2b, 0xe2, 0xd4, 0xc8, 0xcb, 0x46, 0x00, 0xb6, 0x7c, 0xfb, 0xbd,
  40803. 0x56, 0x94, 0x3d, 0x7f, 0x64, 0xf7, 0x88, 0xb5, 0xa7, 0xfe, 0xbe, 0x64,
  40804. 0x8a, 0xe4, 0x00, 0x08, 0x82, 0x5b, 0x8f, 0x98, 0x77, 0x87, 0xda, 0xaf,
  40805. 0x16, 0x25, 0x4a, 0x9a, 0xed, 0xfb, 0x50, 0x18, 0x45, 0x46, 0x2b, 0x73,
  40806. 0xff, 0xb9, 0xb9, 0xab, 0xa2, 0x8f, 0x3a, 0xaf, 0xc5, 0x0a, 0x14, 0x91,
  40807. 0xb2, 0x3f, 0xa6, 0x93, 0xf4, 0x81, 0x20, 0x77, 0xfa, 0x51, 0x79, 0x62,
  40808. 0xe8, 0xe6, 0x89, 0x52, 0x39, 0xd5, 0x01, 0xa2, 0x87, 0xa3, 0x53, 0x74,
  40809. 0x3c, 0x36, 0x8a, 0xc3, 0xb4, 0x44, 0x3b, 0x15, 0x21, 0xf6, 0xdc, 0x18,
  40810. 0x02, 0xd2, 0x57, 0xe5, 0x10, 0xf0, 0x3d, 0x61, 0xa7, 0x16, 0x85, 0x6f,
  40811. 0x71, 0x07, 0x75, 0x50, 0x4b, 0x21, 0x53, 0x47, 0x38, 0x35, 0x9e, 0xa7,
  40812. 0xd8, 0xfd, 0x74, 0x59, 0x15, 0x32, 0x7b, 0x89, 0xd0, 0x2c, 0xd9, 0xf6,
  40813. 0x40, 0x49, 0x79, 0xdc, 0xfb, 0x0a, 0x64, 0x59, 0x9b, 0x17, 0x47, 0x36,
  40814. 0xcb, 0xf0, 0xc3, 0xcc, 0x14, 0x8e, 0x1f, 0xa8, 0x12, 0xaa, 0xb7, 0x6a,
  40815. 0xba, 0x45, 0xf9, 0xc4, 0x44, 0xe7, 0xb5, 0x7c, 0xdd, 0xbe, 0x16, 0x76,
  40816. 0x52, 0x92, 0x3d, 0x78, 0xb7, 0xec, 0x81, 0x96, 0xd8, 0x7f, 0x34, 0x2a,
  40817. 0xa2, 0x64, 0x5f, 0xfd, 0xb1, 0x42, 0x4c, 0x79, 0x98, 0xc9, 0x17, 0x48,
  40818. 0x74, 0x12, 0x72, 0x2c, 0xde, 0x91, 0x7e, 0xa9, 0x49, 0x2a, 0xcc, 0x5c,
  40819. 0x60, 0x05, 0x25, 0x09, 0x72, 0x20, 0x80, 0x42, 0x7b, 0x18, 0xc2, 0xfc,
  40820. 0x2a, 0x5e, 0x3e, 0x2d, 0x61, 0xa6, 0xf6, 0x82, 0x42, 0x83, 0x81, 0x66,
  40821. 0x4d, 0xa6, 0xe1, 0xf9, 0xf6, 0x48, 0xd4, 0xc8, 0x69, 0xed, 0xee, 0xb5,
  40822. 0x7a, 0xcb, 0xf6, 0x0a, 0x76, 0x0e, 0x61, 0x8b, 0xf2, 0x1a, 0x8a, 0xa7,
  40823. 0x88, 0xb0, 0x90, 0xd5, 0x23, 0xaa, 0xe0, 0x2b, 0xd6, 0xd0, 0xef, 0x49,
  40824. 0x13, 0x88, 0xc7, 0x50, 0xf0, 0x9e, 0xd5, 0x28, 0xe1, 0xaa, 0x1d, 0xaf,
  40825. 0xd9, 0x73, 0xb3, 0x9e, 0xa7, 0xd8, 0xfc, 0xb9, 0x22, 0x97, 0x0e, 0x21,
  40826. 0xa0, 0xb9, 0xf9, 0xea, 0x1e, 0x95, 0x88, 0xda, 0x85, 0x7c, 0x32, 0x7c,
  40827. 0xbd, 0xef, 0xf8, 0x44, 0x25, 0x5f, 0x23, 0xfd, 0x14, 0x78, 0xc6, 0xdb,
  40828. 0x86, 0xee, 0xf8, 0xda, 0xc0, 0xae, 0x92, 0x6a, 0x03, 0xa9, 0x0a, 0xee,
  40829. 0x4a, 0x22, 0x5a, 0x6c, 0x39, 0xd3, 0x91, 0x7d, 0x91, 0x43, 0xac, 0x79,
  40830. 0xad, 0xab, 0xb7, 0x91, 0xb1, 0x20, 0x84, 0x7f, 0x0a, 0xd7, 0xa8, 0x62,
  40831. 0x95, 0xab, 0x04, 0xb6, 0xb2, 0xf1, 0xd4, 0xb0, 0xac, 0x52, 0x89, 0xb0,
  40832. 0x93, 0xdf, 0xdf, 0x80, 0x26, 0x0c, 0x32, 0x31, 0xb3, 0xba, 0xa1, 0xba,
  40833. 0x6f, 0xa3, 0x14, 0x5c, 0xfa, 0x37, 0x3b, 0x6a, 0xf2, 0xc4, 0x34, 0x27,
  40834. 0x08, 0x1a, 0xe4, 0xfc, 0x89, 0x58, 0x79, 0x34, 0x36, 0xe4, 0xad, 0x4b,
  40835. 0x3f, 0x57, 0x7b, 0xc1, 0x59, 0x2d, 0xb6, 0x54, 0x44, 0xbe, 0x4e, 0x5d,
  40836. 0x0d, 0x6a, 0xf3, 0xcd, 0xbf, 0xcd, 0x4d, 0x9f, 0x9a, 0x50, 0x09, 0xa4,
  40837. 0x6b, 0x8b, 0xb3, 0x01, 0x69, 0x6c, 0x69, 0x5d, 0x28, 0x73, 0x9e, 0xb5,
  40838. 0xc2, 0xc7, 0x6e, 0xff, 0x4c, 0x5c, 0x6b, 0x93, 0x22, 0xc1, 0x9f, 0xa6,
  40839. 0x71, 0xbf, 0x4d, 0x2d, 0x4e, 0x4e, 0x98, 0xa3, 0x6d, 0xab, 0x05, 0xa0,
  40840. 0xde, 0x34, 0x41, 0x28, 0xa4, 0x38, 0x75, 0x4e, 0xdf, 0x7f, 0xc9, 0xdd,
  40841. 0xbf, 0x5a, 0xd4, 0xcd, 0x38, 0x0c, 0x89, 0xe7, 0x0e, 0xfc, 0x0f, 0x27,
  40842. 0x39, 0x21, 0xa4, 0xa6, 0x07, 0x7b, 0x2a, 0x13, 0x56, 0xe7, 0x4e, 0x55,
  40843. 0x57, 0x71, 0x98, 0xb9, 0x3d, 0x59, 0xb5, 0xa8, 0x24, 0x18, 0x08, 0xa2,
  40844. 0x6e, 0x9a, 0xe5, 0x97, 0xa7, 0x38, 0xd9, 0x43, 0x9b, 0x19, 0x17, 0x34,
  40845. 0x03, 0xd6, 0xba, 0xe9, 0x71, 0x38, 0x26, 0x90, 0x78, 0x9e, 0x1c, 0x41,
  40846. 0x8d, 0x60, 0xdd, 0x0e, 0x12, 0x46, 0x37, 0xb4, 0x79, 0x87, 0x33, 0x12,
  40847. 0x24, 0xc4, 0x5a, 0x6c, 0x70, 0xa2, 0xb2, 0x58, 0xbb, 0xe7, 0xd6, 0x88,
  40848. 0x42, 0x2d, 0x49, 0xc8, 0x67, 0x1e, 0xc5, 0xed, 0x16, 0xa8, 0x1f, 0x36,
  40849. 0x2b, 0xfb, 0x0d, 0x51, 0x96, 0xc8, 0x78, 0xf2, 0xab, 0x82, 0xa1, 0xe2,
  40850. 0xaf, 0x8c, 0xa4, 0x13, 0x54, 0x90, 0xf1, 0xe7, 0xbb, 0xd1, 0x09, 0x23,
  40851. 0x76, 0x0e, 0x50, 0x32, 0xc5, 0x54, 0xbb, 0x1e, 0x12, 0x5d, 0x59, 0xf3,
  40852. 0xe9, 0xc9, 0xa4, 0xaa, 0xbc, 0x13, 0x1d, 0xf0, 0x79, 0x54, 0xae, 0x70,
  40853. 0xc0, 0xea, 0xcb, 0x21, 0x32, 0xe6, 0xe6, 0x8e, 0xaa, 0x51, 0x46, 0x25,
  40854. 0x1e, 0xf1, 0x3f, 0x9f, 0xf6, 0xff, 0x19, 0x53, 0x97, 0xbc, 0xa2, 0xb6,
  40855. 0x91, 0x59, 0x27, 0x1e, 0x39, 0x76, 0x76, 0x02, 0x0b, 0x03, 0x25, 0x6b,
  40856. 0x00, 0x02, 0xfa, 0x7d, 0x69, 0x5e, 0xde, 0x64, 0x33, 0xbf, 0xab, 0x3e,
  40857. 0x3f, 0x24, 0x32, 0x68, 0xbf, 0x90, 0x8f, 0x0f, 0xc5, 0x36, 0x58, 0x9e,
  40858. 0x9b, 0x11, 0xd1, 0x2a, 0x8a, 0x0d, 0xac, 0x3a, 0x23, 0xe2, 0x8e, 0xd6,
  40859. 0x0d, 0x4a, 0x8b, 0x45, 0x04, 0x47, 0xd9, 0x5a, 0x46, 0x6c, 0x70, 0x82,
  40860. 0xc7, 0x81, 0x67, 0xdc, 0xa6, 0xfa, 0x6a, 0x86, 0xfd, 0x01, 0xed, 0x90,
  40861. 0xf6, 0xe6, 0x26, 0x6d, 0xac, 0x52, 0x03, 0x4a, 0x91, 0x08, 0x7b, 0xa5,
  40862. 0x9c, 0xca, 0xd3, 0x2d, 0x79, 0xf1, 0xed, 0xcb, 0xaa, 0x8f, 0x77, 0xc8,
  40863. 0x17, 0xa8, 0xfb, 0x6c, 0x15, 0x62, 0xab, 0x34, 0xd1, 0xdd, 0x94, 0x3e,
  40864. 0xd4, 0x0c, 0x47, 0xed, 0x04, 0x91, 0xd2, 0xd7, 0x98, 0xb4, 0x43, 0x57,
  40865. 0xd1, 0x54, 0xef, 0x63, 0xba, 0xe3, 0x8a, 0x72, 0xc5, 0xb9, 0xf4, 0x30,
  40866. 0xfa, 0x16, 0x3c, 0xe1, 0xbb, 0xbe, 0x57, 0x90, 0xb9, 0xa1, 0xa0, 0x23,
  40867. 0xfa, 0xdd, 0xbe, 0x2f, 0xb3, 0xec, 0x41, 0x8b, 0x64, 0xeb, 0xc5, 0x41,
  40868. 0xea, 0xa8, 0x16, 0x76, 0x6f, 0x28, 0xda, 0x2b, 0x5f, 0x03, 0x0b, 0xe8,
  40869. 0x1c, 0x29, 0x71, 0xd8, 0x4e, 0x41, 0xdf, 0x39, 0x8e, 0x6a, 0x95, 0x79,
  40870. 0x85, 0x9c, 0xa9, 0x79, 0xd9, 0x8f, 0x33, 0xaf, 0x15, 0x3b, 0x5a, 0x82,
  40871. 0x56, 0x32, 0x98, 0x0c, 0xf6, 0xf6, 0x64, 0x42, 0xd4, 0x6a, 0x15, 0x0f,
  40872. 0xb9, 0x75, 0x22, 0xbd, 0x9a, 0x58, 0xa6, 0x01, 0x3a, 0x63, 0xf0, 0x80,
  40873. 0x78, 0x22, 0x80, 0xa0, 0x14, 0xe1, 0x37, 0x6b, 0xd4, 0x99, 0x3f, 0xc2,
  40874. 0xba, 0x2b, 0x8f, 0xf3, 0x56, 0xc8, 0x1b, 0xe4, 0x7a, 0x5e, 0x96, 0x60,
  40875. 0xee, 0x74, 0x54, 0xb6, 0x6d, 0x5c, 0x3d, 0x3e, 0x05, 0xf0, 0x9a, 0xf6,
  40876. 0xcd, 0xdd, 0x06, 0xdb, 0x8c, 0x21, 0xb9, 0xf5, 0x28, 0x57, 0x9c, 0x4f,
  40877. 0xb4, 0x08, 0xcf, 0xac, 0x6c, 0xfe, 0x30, 0xaf, 0xa2, 0xef, 0xcf, 0x93,
  40878. 0x15, 0xdd, 0x12, 0x16, 0x19, 0x7d, 0xbc, 0x57, 0xd9, 0xce, 0xbe, 0x0e,
  40879. 0xfc, 0xe1, 0xf0, 0x4a, 0x7c, 0xaa, 0xbf, 0x20, 0x64, 0x00, 0x34, 0x59,
  40880. 0xed, 0xea, 0x12, 0x58, 0x46, 0x4c, 0xc6, 0x2f, 0x77, 0x62, 0x1d, 0x82,
  40881. 0x5c, 0xe8, 0x98, 0x0d, 0xef, 0x5c, 0x0e, 0xec, 0x5d, 0x2e, 0x5f, 0xd2,
  40882. 0x22, 0x43, 0x2d, 0xe1, 0x02, 0xd5, 0x4a, 0x0a, 0x79, 0x6f, 0xa5, 0xec,
  40883. 0x48, 0xaa, 0xee, 0xf8, 0xe3, 0x5f, 0xdd, 0xe7, 0x26, 0x87, 0xb5, 0xc4,
  40884. 0xcf, 0xd9, 0x7f, 0xa8, 0xaa, 0xb6, 0xbe, 0xe9, 0x02, 0x49, 0x5d, 0x5f,
  40885. 0x81, 0x8b, 0xb9, 0xbd, 0xc0, 0xc9, 0xd5, 0xfe, 0x36, 0x3e, 0x49, 0x56,
  40886. 0x63, 0x8b, 0xce, 0xef, 0x48, 0x6e, 0xc0, 0xd4, 0x04, 0x0c, 0x33, 0x45,
  40887. 0x6e, 0x97, 0x9e, 0xa3, 0xae, 0xbc, 0xc2, 0xce, 0xdc, 0xe3, 0xff, 0x48,
  40888. 0x51, 0x68, 0x89, 0xad, 0xae, 0xc7, 0xd1, 0xde, 0xe2, 0xf9, 0xfe, 0x00,
  40889. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40890. 0x0c, 0x18, 0x20, 0x24, 0x2f, 0x33, 0x3f
  40891. };
  40892. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40893. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_sig[] = {
  40894. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  40895. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  40896. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  40897. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  40898. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  40899. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  40900. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  40901. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  40902. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  40903. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  40904. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  40905. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  40906. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  40907. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  40908. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  40909. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  40910. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  40911. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  40912. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  40913. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  40914. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  40915. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  40916. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  40917. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  40918. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  40919. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  40920. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  40921. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  40922. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  40923. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  40924. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  40925. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  40926. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  40927. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  40928. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  40929. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  40930. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  40931. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  40932. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  40933. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  40934. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  40935. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  40936. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  40937. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  40938. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  40939. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  40940. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  40941. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  40942. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  40943. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  40944. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  40945. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  40946. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  40947. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  40948. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  40949. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  40950. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  40951. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  40952. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  40953. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  40954. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  40955. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  40956. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  40957. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  40958. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  40959. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  40960. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  40961. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  40962. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  40963. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  40964. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  40965. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  40966. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  40967. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  40968. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  40969. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  40970. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  40971. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  40972. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  40973. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  40974. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  40975. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  40976. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  40977. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  40978. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  40979. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  40980. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  40981. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  40982. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  40983. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  40984. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  40985. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  40986. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  40987. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  40988. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  40989. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  40990. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  40991. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  40992. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  40993. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  40994. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  40995. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  40996. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  40997. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  40998. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  40999. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  41000. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  41001. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  41002. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  41003. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  41004. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  41005. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  41006. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  41007. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  41008. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  41009. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  41010. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  41011. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  41012. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  41013. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  41014. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  41015. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  41016. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  41017. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  41018. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  41019. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  41020. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  41021. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  41022. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  41023. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  41024. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  41025. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  41026. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  41027. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  41028. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  41029. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  41030. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  41031. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  41032. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  41033. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  41034. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  41035. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  41036. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  41037. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  41038. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  41039. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  41040. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  41041. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  41042. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  41043. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  41044. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  41045. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  41046. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  41047. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  41048. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  41049. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  41050. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  41051. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  41052. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  41053. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  41054. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  41055. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  41056. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  41057. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  41058. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  41059. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  41060. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  41061. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  41062. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  41063. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  41064. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  41065. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  41066. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  41067. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  41068. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  41069. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  41070. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  41071. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  41072. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  41073. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  41074. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  41075. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  41076. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  41077. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  41078. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  41079. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  41080. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  41081. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  41082. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  41083. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  41084. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  41085. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  41086. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  41087. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  41088. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  41089. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  41090. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  41091. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  41092. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  41093. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  41094. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  41095. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  41096. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  41097. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  41098. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  41099. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  41100. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  41101. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  41102. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  41103. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  41104. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  41105. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  41106. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  41107. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  41108. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  41109. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  41110. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  41111. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  41112. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  41113. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  41114. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  41115. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  41116. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  41117. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  41118. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  41119. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  41120. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  41121. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  41122. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  41123. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  41124. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  41125. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  41126. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  41127. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  41128. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  41129. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  41130. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  41131. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  41132. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  41133. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  41134. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  41135. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  41136. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  41137. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  41138. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  41139. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  41140. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  41141. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  41142. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  41143. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  41144. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  41145. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  41146. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  41147. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  41148. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  41149. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  41150. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  41151. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  41152. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  41153. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  41154. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  41155. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  41156. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  41157. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  41158. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  41159. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  41160. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  41161. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  41162. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  41163. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  41164. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  41165. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  41166. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  41167. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  41168. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  41169. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  41170. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  41171. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  41172. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  41173. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  41174. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  41175. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  41176. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  41177. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  41178. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  41179. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  41180. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  41181. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  41182. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  41183. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  41184. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  41185. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  41186. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  41187. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  41188. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  41189. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  41190. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  41191. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  41192. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  41193. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  41194. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  41195. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  41196. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  41197. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  41198. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  41199. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  41200. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  41201. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  41202. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  41203. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  41204. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  41205. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  41206. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  41207. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  41208. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  41209. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  41210. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  41211. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  41212. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  41213. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  41214. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  41215. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  41216. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  41217. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  41218. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  41219. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  41220. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  41221. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  41222. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  41223. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  41224. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  41225. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  41226. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  41227. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  41228. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  41229. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  41230. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  41231. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  41232. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  41233. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  41234. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  41235. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  41236. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  41237. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  41238. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  41239. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  41240. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  41241. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  41242. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  41243. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  41244. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  41245. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  41246. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  41247. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  41248. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  41249. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  41250. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  41251. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  41252. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  41253. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  41254. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  41255. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  41256. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  41257. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  41258. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  41259. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  41260. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  41261. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  41262. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  41263. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  41264. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  41265. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  41266. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  41267. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  41268. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  41269. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  41270. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  41271. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  41272. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  41273. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  41274. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  41275. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  41276. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  41277. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  41278. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  41279. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  41280. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  41281. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  41282. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  41283. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  41284. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  41285. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  41286. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  41287. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  41288. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  41289. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  41290. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  41291. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  41292. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  41293. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  41294. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  41295. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  41296. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  41297. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  41298. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  41299. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  41300. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  41301. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  41302. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  41303. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  41304. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  41305. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  41306. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  41307. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  41308. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  41309. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  41310. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  41311. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  41312. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  41313. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  41314. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  41315. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  41316. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  41317. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  41318. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  41319. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  41320. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  41321. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  41322. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  41323. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  41324. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  41325. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  41326. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  41327. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  41328. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  41329. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  41330. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  41331. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  41332. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  41333. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  41334. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  41335. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  41336. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  41337. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  41338. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  41339. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  41340. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  41341. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  41342. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  41343. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  41344. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  41345. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  41346. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  41347. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  41348. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  41349. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  41350. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  41351. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  41352. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  41353. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  41354. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  41355. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  41356. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f
  41357. };
  41358. #endif
  41359. wc_test_ret_t ret;
  41360. ret = dilithium_param_vfy_test(WC_ML_DSA_87, ml_dsa_87_pub_key,
  41361. (word32)sizeof(ml_dsa_87_pub_key), ml_dsa_87_sig,
  41362. (word32)sizeof(ml_dsa_87_sig));
  41363. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41364. if (ret == 0) {
  41365. ret = dilithium_param_vfy_test(WC_ML_DSA_87_DRAFT,
  41366. ml_dsa_87_draft_pub_key, (word32)sizeof(ml_dsa_87_draft_pub_key),
  41367. ml_dsa_87_draft_sig, (word32)sizeof(ml_dsa_87_draft_sig));
  41368. }
  41369. #endif
  41370. return ret;
  41371. }
  41372. #endif
  41373. #endif
  41374. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41375. static wc_test_ret_t dilithium_param_test(int param, WC_RNG* rng)
  41376. {
  41377. wc_test_ret_t ret;
  41378. dilithium_key* key;
  41379. byte* sig = NULL;
  41380. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41381. word32 sigLen;
  41382. byte msg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  41383. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41384. int res = 0;
  41385. #endif
  41386. #endif
  41387. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  41388. DYNAMIC_TYPE_TMP_BUFFER);
  41389. if (key == NULL) {
  41390. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41391. }
  41392. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
  41393. DYNAMIC_TYPE_TMP_BUFFER);
  41394. if (sig == NULL) {
  41395. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41396. }
  41397. ret = wc_dilithium_init(key);
  41398. if (ret != 0) {
  41399. ret = WC_TEST_RET_ENC_EC(ret);
  41400. return ret;
  41401. }
  41402. ret = wc_dilithium_set_level(key, param);
  41403. if (ret != 0)
  41404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41405. ret = wc_dilithium_make_key(key, rng);
  41406. if (ret != 0)
  41407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41408. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41409. sigLen = wc_dilithium_sig_size(key);
  41410. if (sigLen <= 0)
  41411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41412. ret = wc_dilithium_sign_msg(msg, (word32)sizeof(msg), sig, &sigLen, key,
  41413. rng);
  41414. if (ret != 0)
  41415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41416. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41417. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  41418. key);
  41419. if (ret != 0)
  41420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41421. if (res != 1)
  41422. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  41423. #endif
  41424. #endif
  41425. out:
  41426. wc_dilithium_free(key);
  41427. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41428. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41429. return ret;
  41430. }
  41431. #endif
  41432. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41433. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41434. /* Tests decoding a key from DER without the security level specified */
  41435. static wc_test_ret_t test_dilithium_decode_level(const byte* rawKey,
  41436. word32 rawKeySz,
  41437. int expectedLevel,
  41438. int isPublicOnlyKey)
  41439. {
  41440. int ret;
  41441. dilithium_key key;
  41442. word32 idx;
  41443. byte* der;
  41444. word32 derSz;
  41445. /* Size the buffer to accommodate the largest encoded key size */
  41446. const word32 maxDerSz = DILITHIUM_MAX_PRV_KEY_DER_SIZE;
  41447. /* Allocate DER buffer */
  41448. der = (byte*)XMALLOC(maxDerSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41449. if (der == NULL) {
  41450. return MEMORY_E;
  41451. }
  41452. /* Initialize key */
  41453. ret = wc_dilithium_init(&key);
  41454. /* Import raw key, setting the security level */
  41455. if (ret == 0) {
  41456. ret = wc_dilithium_set_level(&key, expectedLevel);
  41457. }
  41458. if (ret == 0) {
  41459. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41460. if (isPublicOnlyKey) {
  41461. ret = wc_dilithium_import_public(rawKey, rawKeySz, &key);
  41462. }
  41463. #endif
  41464. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41465. if (!isPublicOnlyKey) {
  41466. ret = wc_dilithium_import_private(rawKey, rawKeySz, &key);
  41467. }
  41468. #endif
  41469. }
  41470. /* Export raw key as DER */
  41471. if (ret == 0) {
  41472. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41473. if (isPublicOnlyKey) {
  41474. ret = wc_Dilithium_PublicKeyToDer(&key, der, maxDerSz, 1);
  41475. }
  41476. #endif
  41477. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41478. if (!isPublicOnlyKey) {
  41479. ret = wc_Dilithium_PrivateKeyToDer(&key, der, maxDerSz);
  41480. }
  41481. #endif
  41482. if (ret >= 0) {
  41483. derSz = ret;
  41484. ret = 0;
  41485. }
  41486. }
  41487. /* Free and reinit key to test fresh decode */
  41488. if (ret == 0) {
  41489. wc_dilithium_free(&key);
  41490. ret = wc_dilithium_init(&key);
  41491. }
  41492. /* First test decoding when security level is set externally */
  41493. if (ret == 0) {
  41494. ret = wc_dilithium_set_level(&key, expectedLevel);
  41495. }
  41496. if (ret == 0) {
  41497. idx = 0;
  41498. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41499. if (isPublicOnlyKey) {
  41500. ret = wc_Dilithium_PublicKeyDecode(der, &idx, &key, derSz);
  41501. }
  41502. #endif
  41503. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41504. if (!isPublicOnlyKey) {
  41505. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, &key, derSz);
  41506. }
  41507. #endif
  41508. }
  41509. /* Free and reinit key to test fresh decode */
  41510. if (ret == 0) {
  41511. wc_dilithium_free(&key);
  41512. ret = wc_dilithium_init(&key);
  41513. }
  41514. /* Test decoding without setting security level - should auto-detect */
  41515. if (ret == 0) {
  41516. idx = 0;
  41517. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41518. if (isPublicOnlyKey) {
  41519. ret = wc_Dilithium_PublicKeyDecode(der, &idx, &key, derSz);
  41520. }
  41521. #endif
  41522. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41523. if (!isPublicOnlyKey) {
  41524. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, &key, derSz);
  41525. }
  41526. #endif
  41527. }
  41528. /* Verify auto-detected security level */
  41529. if (ret == 0 && key.level != expectedLevel) {
  41530. printf("Dilithium key decode failed to detect level.\n"
  41531. "\tExpected level=%d\n\tGot level=%d\n",
  41532. expectedLevel, key.level);
  41533. ret = WC_TEST_RET_ENC_NC;
  41534. }
  41535. /* Cleanup */
  41536. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41537. wc_dilithium_free(&key);
  41538. return ret;
  41539. }
  41540. /* Test Dilithium key decoding and security level detection */
  41541. static wc_test_ret_t dilithium_decode_test(void)
  41542. {
  41543. wc_test_ret_t ret;
  41544. const byte* key;
  41545. word32 keySz;
  41546. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41547. const int isPrvKey = 0;
  41548. #endif
  41549. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41550. const int isPubKey = 1;
  41551. #endif
  41552. #ifndef WOLFSSL_NO_ML_DSA_44
  41553. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41554. /* Test ML-DSA-44 */
  41555. key = bench_dilithium_level2_key;
  41556. keySz = sizeof_bench_dilithium_level2_key;
  41557. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPrvKey);
  41558. if (ret != 0) {
  41559. return ret;
  41560. }
  41561. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41562. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41563. key = bench_dilithium_level2_pubkey;
  41564. keySz = sizeof_bench_dilithium_level2_pubkey;
  41565. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPubKey);
  41566. if (ret != 0) {
  41567. return ret;
  41568. }
  41569. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41570. #endif /* WOLFSSL_NO_ML_DSA_44 */
  41571. #ifndef WOLFSSL_NO_ML_DSA_65
  41572. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41573. /* Test ML-DSA-65 */
  41574. key = bench_dilithium_level3_key;
  41575. keySz = sizeof_bench_dilithium_level3_key;
  41576. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPrvKey);
  41577. if (ret != 0) {
  41578. return ret;
  41579. }
  41580. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41581. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41582. key = bench_dilithium_level3_pubkey;
  41583. keySz = sizeof_bench_dilithium_level3_pubkey;
  41584. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPubKey);
  41585. if (ret != 0) {
  41586. return ret;
  41587. }
  41588. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41589. #endif /* WOLFSSL_NO_ML_DSA_65 */
  41590. #ifndef WOLFSSL_NO_ML_DSA_87
  41591. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41592. /* Test ML-DSA-87 */
  41593. key = bench_dilithium_level5_key;
  41594. keySz = sizeof_bench_dilithium_level5_key;
  41595. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPrvKey);
  41596. if (ret != 0) {
  41597. return ret;
  41598. }
  41599. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41600. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41601. key = bench_dilithium_level5_pubkey;
  41602. keySz = sizeof_bench_dilithium_level5_pubkey;
  41603. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPubKey);
  41604. if (ret != 0) {
  41605. return ret;
  41606. }
  41607. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41608. #endif /* WOLFSSL_NO_ML_DSA_87 */
  41609. return ret;
  41610. }
  41611. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY || WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41612. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
  41613. {
  41614. wc_test_ret_t ret;
  41615. WC_RNG rng;
  41616. #ifndef HAVE_FIPS
  41617. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41618. #else
  41619. ret = wc_InitRng(&rng);
  41620. #endif
  41621. if (ret != 0) {
  41622. ret = WC_TEST_RET_ENC_EC(ret);
  41623. return ret;
  41624. }
  41625. #ifndef WOLFSSL_NO_ML_DSA_44
  41626. #ifdef WOLFSSL_WC_DILITHIUM
  41627. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41628. ret = dilithium_param_44_vfy_test();
  41629. if (ret != 0)
  41630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41631. #endif
  41632. #endif
  41633. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41634. ret = dilithium_param_test(WC_ML_DSA_44, &rng);
  41635. if (ret != 0)
  41636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41637. #endif
  41638. #endif
  41639. #ifndef WOLFSSL_NO_ML_DSA_65
  41640. #ifdef WOLFSSL_WC_DILITHIUM
  41641. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41642. ret = dilithium_param_65_vfy_test();
  41643. if (ret != 0)
  41644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41645. #endif
  41646. #endif
  41647. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41648. ret = dilithium_param_test(WC_ML_DSA_65, &rng);
  41649. if (ret != 0)
  41650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41651. #endif
  41652. #endif
  41653. #ifndef WOLFSSL_NO_ML_DSA_87
  41654. #ifdef WOLFSSL_WC_DILITHIUM
  41655. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41656. ret = dilithium_param_87_vfy_test();
  41657. if (ret != 0)
  41658. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41659. #endif
  41660. #endif
  41661. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41662. ret = dilithium_param_test(WC_ML_DSA_87, &rng);
  41663. if (ret != 0)
  41664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41665. #endif
  41666. #endif
  41667. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41668. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41669. ret = dilithium_decode_test();
  41670. if (ret != 0) {
  41671. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41672. }
  41673. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY || WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41674. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  41675. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) || \
  41676. defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41677. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41678. out:
  41679. #endif
  41680. wc_FreeRng(&rng);
  41681. return ret;
  41682. }
  41683. #endif /* HAVE_DILITHIUM */
  41684. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  41685. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  41686. void *context)
  41687. {
  41688. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41689. * BE USED FOR TESTING PURPOSES! Production applications should
  41690. * write only to non-volatile storage. */
  41691. XMEMCPY(context, priv, privSz);
  41692. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  41693. }
  41694. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  41695. void *context)
  41696. {
  41697. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41698. * BE USED FOR TESTING PURPOSES! */
  41699. XMEMCPY(priv, context, privSz);
  41700. return WC_XMSS_RC_READ_TO_MEMORY;
  41701. }
  41702. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
  41703. {
  41704. int i = 0;
  41705. int j = 0;
  41706. XmssKey signingKey;
  41707. XmssKey verifyKey;
  41708. WC_RNG rng;
  41709. word32 pkSz = 0;
  41710. word32 skSz = 0;
  41711. word32 sigSz = 0;
  41712. word32 bufSz = 0;
  41713. unsigned char * sk = NULL;
  41714. unsigned char * old_sk = NULL;
  41715. const char * msg = "XMSS post quantum signature test";
  41716. word32 msgSz = (word32) XSTRLEN(msg);
  41717. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41718. const char * param = "XMSS-SHA2_10_256";
  41719. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 20
  41720. const char * param = "XMSSMT-SHA2_20/4_256";
  41721. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 40
  41722. const char * param = "XMSSMT-SHA2_40/8_256";
  41723. #else
  41724. const char * param = "XMSSMT-SHA2_60/12_256";
  41725. #endif
  41726. byte * sig = NULL;
  41727. int ret2 = -1;
  41728. int ret = WC_TEST_RET_ENC_NC;
  41729. WOLFSSL_ENTER("xmss_test");
  41730. #ifndef HAVE_FIPS
  41731. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41732. #else
  41733. ret = wc_InitRng(&rng);
  41734. #endif
  41735. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41736. ret = wc_XmssKey_Init(&signingKey, NULL, INVALID_DEVID);
  41737. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41738. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41739. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41740. /* Set the parameter string to the signing key, and
  41741. * get sizes for secret key, pub key, and signature. */
  41742. ret = wc_XmssKey_SetParamStr(&signingKey, param);
  41743. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41744. ret = wc_XmssKey_GetPubLen(&signingKey, &pkSz);
  41745. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41746. if (pkSz != XMSS_SHA256_PUBLEN) {
  41747. return WC_TEST_RET_ENC_EC(pkSz);
  41748. }
  41749. ret = wc_XmssKey_GetPrivLen(&signingKey, &skSz);
  41750. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41751. ret = wc_XmssKey_GetSigLen(&signingKey, &sigSz);
  41752. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41753. /* Allocate signature array. */
  41754. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41755. if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41756. bufSz = sigSz;
  41757. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41758. fprintf(stderr, "param: %s\n", param);
  41759. fprintf(stderr, "pkSz: %d\n", pkSz);
  41760. fprintf(stderr, "skSz: %d\n", skSz);
  41761. fprintf(stderr, "sigSz: %d\n", sigSz);
  41762. #endif
  41763. /* Allocate current and old secret keys.*/
  41764. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41765. if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41766. old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41767. if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41768. XMEMSET(sk, 0, skSz);
  41769. XMEMSET(old_sk, 0, skSz);
  41770. XMEMSET(sig, 0, sigSz);
  41771. ret = wc_XmssKey_SetWriteCb(&signingKey, xmss_write_key_mem);
  41772. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41773. ret = wc_XmssKey_SetReadCb(&signingKey, xmss_read_key_mem);
  41774. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41775. ret = wc_XmssKey_SetContext(&signingKey, (void *) sk);
  41776. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41777. ret = wc_XmssKey_MakeKey(&signingKey, &rng);
  41778. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41779. /* Export the pub to a verify key. */
  41780. ret = wc_XmssKey_ExportPub(&verifyKey, &signingKey);
  41781. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41782. /* Repeat a few times to check that:
  41783. * 1. The secret key is mutated on each sign.
  41784. * 2. We can verify each new signature.
  41785. * Only do a few times, because the full signature space
  41786. * for this parameter set is huge. */
  41787. for (i = 0; i < 10; ++i) {
  41788. XMEMCPY(old_sk, sk, skSz);
  41789. ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41790. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41791. if (sigSz != bufSz) { return WC_TEST_RET_ENC_I(i); }
  41792. /* Old secret key and current secret key should not match. */
  41793. ret = XMEMCMP(old_sk, sk, skSz);
  41794. if (ret == 0) { return WC_TEST_RET_ENC_I(i); }
  41795. ret = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41796. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41797. /* Flip bits in a few places throughout the signature, stepping in multiple
  41798. * of hash size. These should all fail with -1. */
  41799. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41800. sig[j] ^= 1;
  41801. ret2 = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41802. msgSz);
  41803. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41804. /* Verify passed when it should have failed. */
  41805. return WC_TEST_RET_ENC_I(j);
  41806. }
  41807. /* Flip this spot back. */
  41808. sig[j] ^= 1;
  41809. }
  41810. }
  41811. /* Cleanup everything. */
  41812. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41813. sig = NULL;
  41814. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41815. sk = NULL;
  41816. XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41817. old_sk = NULL;
  41818. wc_XmssKey_Free(&signingKey);
  41819. wc_FreeRng(&rng);
  41820. return ret;
  41821. }
  41822. #endif /*if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)*/
  41823. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_SMALL_STACK) && \
  41824. WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41825. /* A simple xmss verify only test using:
  41826. * XMSS-SHA2_10_256
  41827. * pub len: 68
  41828. * msg len: 32
  41829. * sig len: 2500
  41830. *
  41831. * These were generated with the test xmss_fast, from the unpatched
  41832. * xmss-reference repository:
  41833. * https://github.com/XMSS/xmss-reference
  41834. * */
  41835. static const byte xmss_pub[XMSS_SHA256_PUBLEN] =
  41836. {
  41837. 0x00,0x00,0x00,0x01,0xA5,0x41,0x31,0x96,
  41838. 0x0A,0xF9,0xF3,0xB2,0x4B,0x2E,0x5B,0x3E,
  41839. 0xCA,0x74,0xAD,0x6C,0xA5,0x89,0xAD,0x2C,
  41840. 0x0E,0x96,0xB3,0x54,0xFB,0x5B,0x63,0x50,
  41841. 0x96,0x81,0xE2,0x59,0x72,0x10,0x09,0x54,
  41842. 0xBB,0x39,0xAC,0xEE,0x78,0xEF,0x95,0xEC,
  41843. 0x01,0x1D,0xF0,0x36,0x68,0xE2,0xC4,0xA5,
  41844. 0x2F,0x60,0x42,0x7E,0xD3,0x8E,0xAA,0x27,
  41845. 0xC9,0xB7,0x39,0x4E
  41846. };
  41847. static /* not const */ byte xmss_msg[32] =
  41848. {
  41849. 0x07,0x9F,0x80,0x86,0xDB,0x76,0x27,0xDF,
  41850. 0xED,0x5B,0x2A,0x81,0x60,0x60,0x7D,0xB4,
  41851. 0xE8,0x7A,0x69,0x45,0x20,0x6B,0xA2,0x96,
  41852. 0xC0,0x21,0xA5,0x46,0x29,0x63,0x9B,0x37
  41853. };
  41854. /* This was actually the 5th signature produced from
  41855. * xmss_fast test in xmss-reference. */
  41856. static /* not const */ byte xmss_sig[2500] =
  41857. {
  41858. 0x00,0x00,0x00,0x05,0xF0,0x15,0x34,0xBA,
  41859. 0x92,0x03,0x6A,0xB9,0xA5,0x23,0x86,0x11,
  41860. 0xAE,0x65,0x0A,0x5C,0x78,0x2C,0xC9,0xBE,
  41861. 0x7E,0xA6,0xDC,0xA2,0x8B,0xA9,0x9C,0x50,
  41862. 0xF6,0x61,0x8D,0x9D,0xD7,0xE9,0xC0,0xF8,
  41863. 0x67,0xCD,0x8A,0xC4,0x9B,0x74,0x96,0x07,
  41864. 0x5D,0xF2,0xC9,0xCC,0x28,0x05,0xB1,0xBE,
  41865. 0x5E,0xA4,0xBA,0xBE,0xAB,0xD8,0x21,0x6B,
  41866. 0x21,0x5F,0xAB,0xB7,0x6C,0xEC,0x2F,0xC8,
  41867. 0xC6,0x74,0x3E,0x97,0x1B,0xC3,0x45,0x57,
  41868. 0xAF,0xAA,0x1E,0xA8,0xF2,0x86,0xA8,0xAA,
  41869. 0x43,0x6D,0x66,0xE9,0x81,0x14,0xDE,0x09,
  41870. 0x39,0xD2,0xAF,0xD1,0x4C,0xE7,0x75,0x18,
  41871. 0x0D,0xAA,0x29,0xA1,0x92,0x53,0xCC,0xE9,
  41872. 0xF3,0x0B,0x1E,0x3B,0xE2,0xAE,0x80,0x0C,
  41873. 0xE7,0x7A,0x7C,0x13,0x8A,0x28,0xC6,0x5F,
  41874. 0x0A,0xA4,0xA3,0x73,0x0A,0x3A,0xC2,0xA6,
  41875. 0x3B,0xB4,0x30,0x67,0xC0,0x36,0x18,0xA1,
  41876. 0x58,0xCD,0xAD,0x54,0x36,0x64,0xCE,0xFD,
  41877. 0x52,0xFF,0x70,0x7E,0x09,0xFB,0x13,0xA2,
  41878. 0xEA,0xDF,0x67,0x8D,0x6C,0x42,0xB2,0x78,
  41879. 0xF5,0x7D,0x5C,0x4B,0xF7,0x8E,0xCF,0x3E,
  41880. 0xB7,0xC6,0xC1,0x23,0xFA,0x65,0xDE,0xD2,
  41881. 0xFA,0x40,0x51,0x97,0x0D,0x52,0x32,0x76,
  41882. 0x7E,0x82,0x8D,0xD0,0xB9,0x1E,0x62,0xD9,
  41883. 0x1E,0xC1,0xDB,0x40,0x43,0x37,0x4A,0x23,
  41884. 0x8A,0x1D,0x35,0xFA,0xF4,0x53,0x11,0x5A,
  41885. 0xB5,0x6D,0x1E,0x8B,0x22,0xC8,0x7D,0x2A,
  41886. 0xE4,0x94,0xAA,0x25,0x20,0x40,0x96,0xDB,
  41887. 0x82,0x62,0xBA,0x8F,0x8B,0x45,0xCB,0x4F,
  41888. 0x35,0x88,0x33,0xEB,0xEF,0xB3,0xBA,0xA7,
  41889. 0x09,0x72,0xB3,0x4C,0xEC,0xF2,0xC3,0xC7,
  41890. 0x5E,0x02,0x6C,0x41,0x93,0xCB,0x3C,0x89,
  41891. 0x12,0x09,0x68,0x54,0x8E,0xEC,0x6A,0x7E,
  41892. 0x20,0xE1,0x70,0x3D,0x8C,0xEB,0xB4,0x36,
  41893. 0xBE,0x91,0xBE,0x97,0xB5,0xA6,0x34,0x16,
  41894. 0x95,0x0F,0x10,0x26,0xA9,0x13,0x80,0x88,
  41895. 0x9C,0xAA,0x68,0xEC,0x34,0x70,0x4A,0x15,
  41896. 0x9B,0x5E,0x57,0x05,0x87,0x1C,0xF8,0x35,
  41897. 0x45,0x29,0xE9,0x6E,0xF2,0x70,0x13,0x42,
  41898. 0x89,0x4E,0x77,0xC0,0x18,0xC7,0x55,0x6D,
  41899. 0xE7,0xFA,0x0D,0x63,0x83,0x16,0x19,0x01,
  41900. 0x2D,0xFD,0x31,0x14,0x94,0xCA,0x3E,0x0E,
  41901. 0xD6,0x11,0x34,0x81,0x57,0x58,0xEC,0x24,
  41902. 0xA4,0x17,0x63,0xD3,0x25,0x00,0xBF,0x7D,
  41903. 0x78,0x5D,0xC5,0xD8,0xC6,0xC1,0xBD,0x8C,
  41904. 0xD0,0x94,0x0A,0xB1,0x33,0xA5,0x4B,0x31,
  41905. 0x25,0xF5,0xAF,0xE7,0x84,0x26,0xAA,0x05,
  41906. 0xBB,0xF3,0x9A,0xAF,0x58,0x36,0x40,0xEF,
  41907. 0x3D,0xA2,0xBD,0xCA,0xA1,0x8D,0x2F,0x6D,
  41908. 0x54,0xD2,0x62,0x33,0x09,0xAE,0xE6,0x73,
  41909. 0xD6,0x44,0xE8,0x7C,0x5C,0x39,0x2B,0x78,
  41910. 0x94,0x14,0xC7,0xC9,0xAF,0xEC,0x77,0x36,
  41911. 0xA1,0x61,0x61,0xF1,0xD0,0x09,0xA2,0xEE,
  41912. 0xE7,0x55,0xD7,0x35,0x89,0x89,0x9B,0xCF,
  41913. 0xFA,0xA6,0x09,0x1E,0x3B,0xBD,0x5D,0xD9,
  41914. 0x25,0xE7,0xED,0xDD,0x7C,0xF0,0x1C,0x57,
  41915. 0xE0,0x06,0xBB,0x08,0x39,0x59,0xDF,0xD7,
  41916. 0xAF,0x4B,0x88,0x0D,0x87,0x8F,0x4A,0xF3,
  41917. 0x1C,0xD4,0x4B,0xB3,0xE2,0xF3,0x1B,0x86,
  41918. 0x4F,0xCD,0x35,0x75,0xE2,0x03,0xF9,0x1D,
  41919. 0xBF,0x3E,0xD1,0x7B,0xC7,0x23,0x11,0x75,
  41920. 0x5F,0x92,0x0D,0x98,0xEE,0x14,0xE1,0xDA,
  41921. 0x7A,0x02,0x17,0x47,0x6B,0x41,0xEA,0x47,
  41922. 0xA1,0xAF,0x06,0x79,0x1A,0x52,0x6F,0x19,
  41923. 0x31,0x70,0x71,0xBD,0xC2,0x61,0x8D,0xB7,
  41924. 0xEE,0x6B,0x69,0x2A,0xE8,0x21,0x7A,0x95,
  41925. 0xBE,0x86,0x2A,0xA1,0xF4,0xE2,0x2F,0x17,
  41926. 0x02,0xFD,0xAD,0x17,0x9F,0x0A,0x0A,0x78,
  41927. 0xA9,0x92,0x30,0x21,0x72,0x2B,0x28,0xF8,
  41928. 0xF2,0x3E,0x05,0xD5,0xAC,0xC0,0x82,0xF8,
  41929. 0xD2,0xDA,0xD0,0xA3,0xBC,0x93,0xDB,0xA5,
  41930. 0x46,0xDE,0x14,0x1E,0xD4,0x3A,0x5D,0x79,
  41931. 0x3D,0x31,0x4B,0x06,0xCE,0x22,0x29,0x3C,
  41932. 0x98,0xB6,0x18,0x8A,0xAE,0xF7,0xBA,0x22,
  41933. 0x88,0xA1,0xEE,0xC0,0x14,0x4C,0x4A,0xA0,
  41934. 0x57,0x0A,0xD3,0x18,0xA2,0x3D,0xDD,0xC7,
  41935. 0x83,0x73,0xFC,0x38,0x9B,0x31,0xA3,0xE1,
  41936. 0x17,0x76,0xA1,0xA2,0x69,0xFC,0xAB,0x08,
  41937. 0x80,0x72,0x8D,0xF5,0xE4,0x14,0xB7,0x6B,
  41938. 0x03,0xFF,0xE8,0x11,0x4B,0x06,0x55,0x7E,
  41939. 0x36,0x21,0x2F,0xD7,0x54,0x82,0xC9,0x31,
  41940. 0xB4,0x85,0x68,0x41,0xEF,0x75,0xB0,0x3A,
  41941. 0xEA,0x4F,0xE0,0xEC,0x72,0xCC,0x33,0x96,
  41942. 0xCE,0x7D,0xAD,0xDD,0x0D,0x27,0x05,0x6E,
  41943. 0xA2,0xD4,0x11,0x07,0xD8,0x7D,0x27,0xD4,
  41944. 0x80,0x8F,0x00,0x22,0xE4,0xFC,0x2C,0x9D,
  41945. 0xD5,0xD8,0x18,0x7F,0x4E,0xF4,0xB9,0x7F,
  41946. 0xEF,0xD6,0x00,0x08,0x5C,0x05,0x04,0x1E,
  41947. 0x9A,0xC6,0x8D,0xCC,0x19,0xD9,0x0B,0x06,
  41948. 0xCC,0x6A,0x17,0xE2,0x03,0x23,0xDB,0x1C,
  41949. 0xBC,0xA2,0xB9,0xA2,0x95,0x3C,0x73,0xD8,
  41950. 0xFF,0xE6,0x0E,0xAE,0x04,0xB2,0xFC,0x91,
  41951. 0x4F,0xEF,0x8A,0x58,0xB7,0x31,0x68,0x4C,
  41952. 0x1E,0xD0,0x5B,0x85,0xCC,0x03,0xDC,0xF4,
  41953. 0xAC,0xDB,0x03,0x9B,0x35,0x33,0x08,0x71,
  41954. 0xD0,0x50,0x8D,0xDC,0xE3,0x3A,0x98,0x40,
  41955. 0x41,0x80,0xDD,0x35,0xE1,0xA2,0xAF,0x14,
  41956. 0x9A,0xDB,0xD3,0x68,0x14,0xE2,0x50,0x7A,
  41957. 0x76,0x3F,0xE4,0xA4,0x1B,0xAA,0xC1,0x06,
  41958. 0x87,0x9A,0x92,0xF9,0xBE,0x9E,0x86,0x8C,
  41959. 0x92,0x1D,0x74,0xB1,0x7F,0x27,0x43,0xC0,
  41960. 0xEE,0x2E,0xC2,0x6C,0x6D,0xAA,0x0C,0x0E,
  41961. 0x71,0xC9,0x56,0xD6,0x3A,0x56,0xCB,0x90,
  41962. 0xD1,0x7E,0x6E,0x1C,0x6A,0x00,0x2D,0x02,
  41963. 0x2C,0x96,0xF0,0x2A,0x37,0x37,0x18,0x07,
  41964. 0x0B,0xF4,0xB4,0x8C,0x30,0xF2,0xA4,0xAB,
  41965. 0x66,0xFB,0x8B,0x22,0xC0,0x00,0x7E,0x05,
  41966. 0xB6,0xF9,0x95,0x49,0x33,0xA1,0xDC,0x97,
  41967. 0x0C,0x5C,0x61,0x46,0xE2,0xD7,0x87,0x4B,
  41968. 0xC4,0xC7,0x5F,0x26,0x06,0x84,0xD7,0x47,
  41969. 0x05,0xF1,0x33,0xFF,0x85,0x85,0xB2,0xBD,
  41970. 0x1F,0x44,0xC6,0xC2,0x7D,0x51,0xBE,0x0E,
  41971. 0xB5,0xC4,0x44,0x2F,0xFE,0x73,0x5F,0xF4,
  41972. 0xA4,0xEF,0xE2,0xF1,0x73,0x0B,0xEF,0x3E,
  41973. 0x2B,0xD7,0xCC,0x9F,0xDA,0x1A,0x7E,0x92,
  41974. 0x39,0xA1,0x55,0xBF,0x60,0x0A,0xDB,0x23,
  41975. 0x74,0xFE,0xE7,0x05,0x63,0xA9,0x85,0x52,
  41976. 0x9F,0xCC,0xC3,0xFF,0xF6,0x6C,0x1B,0x4E,
  41977. 0x4F,0x01,0xBD,0xC3,0xEB,0x37,0xEC,0x29,
  41978. 0x21,0x3B,0x2C,0xC9,0x2E,0x93,0x20,0x3E,
  41979. 0x19,0xC0,0x8B,0xE8,0x33,0xCD,0xC6,0x6A,
  41980. 0x6E,0x72,0x13,0x15,0xA1,0x90,0x20,0x0C,
  41981. 0x14,0x66,0xED,0xCC,0xA4,0xDD,0x7F,0x58,
  41982. 0x53,0xBC,0x4A,0x68,0xFC,0x86,0x3E,0xAA,
  41983. 0xF1,0x17,0x0F,0x3E,0x20,0x54,0x93,0xF4,
  41984. 0x98,0xBF,0xB4,0x07,0x05,0xBD,0x70,0xE7,
  41985. 0xD7,0x34,0xFD,0xE3,0x69,0xDF,0xCD,0xF5,
  41986. 0x1A,0x73,0x6E,0xC9,0x2B,0x21,0xFB,0xB8,
  41987. 0x7E,0x44,0x10,0x83,0x56,0xCE,0xD5,0x15,
  41988. 0x9A,0x75,0xFC,0x91,0x8E,0x6B,0x9E,0x1A,
  41989. 0x3A,0x33,0x39,0x35,0xB4,0x0D,0x74,0xF4,
  41990. 0xFB,0x4C,0x0E,0x37,0xFE,0x82,0x95,0x46,
  41991. 0x6B,0xD2,0x6E,0xEE,0xCD,0x4D,0x38,0xAF,
  41992. 0x0A,0xAA,0xF1,0xD5,0xA4,0x7C,0x04,0xD8,
  41993. 0xB9,0xDB,0x11,0x68,0x88,0x35,0x41,0xDE,
  41994. 0x31,0x33,0x0C,0xDC,0x2D,0x4C,0xA8,0x20,
  41995. 0xCC,0x2C,0x4C,0x63,0xAB,0xBA,0xDF,0x48,
  41996. 0x84,0xD5,0x25,0xBC,0x70,0xE3,0x49,0xAA,
  41997. 0x43,0xCA,0x8B,0xE7,0x9F,0xDD,0x20,0x76,
  41998. 0x9B,0x38,0xF4,0xBA,0x4D,0x4E,0x34,0x4A,
  41999. 0xAF,0x81,0xE7,0x0B,0xEC,0xE9,0x59,0xC1,
  42000. 0x35,0x22,0x7F,0x69,0x46,0x62,0xD2,0x18,
  42001. 0x6E,0x1F,0x79,0xD1,0xAD,0xC3,0x84,0x95,
  42002. 0x96,0xB2,0x18,0x58,0x5E,0x7E,0x0C,0x25,
  42003. 0x0A,0x0F,0x69,0xA3,0x1D,0xEC,0x29,0xCB,
  42004. 0xDA,0xA2,0xD1,0x1A,0x10,0xA5,0x52,0xC3,
  42005. 0x62,0x1E,0xC5,0x83,0xFF,0xA3,0x56,0xC2,
  42006. 0xFD,0x87,0x3B,0x57,0x52,0x98,0x36,0x95,
  42007. 0x77,0x6B,0xE5,0x49,0x10,0x8E,0x39,0xDD,
  42008. 0xCA,0x4B,0xB3,0x9F,0x4C,0x0C,0x11,0x62,
  42009. 0xF3,0x22,0x78,0xDB,0x48,0xEB,0x68,0xFE,
  42010. 0xE4,0x2A,0xE9,0xAA,0x8F,0x7A,0x2F,0x69,
  42011. 0xA5,0xC5,0x03,0x2D,0xEF,0x62,0xA8,0x71,
  42012. 0x65,0x06,0x40,0x84,0x10,0x0F,0xF2,0xED,
  42013. 0xBC,0x70,0x71,0x69,0x24,0xA2,0xBF,0x83,
  42014. 0x39,0xDD,0xFA,0xA2,0x7B,0xE5,0xEC,0x3D,
  42015. 0xFE,0x3B,0x52,0x6E,0x3D,0x82,0xA6,0x2A,
  42016. 0x86,0x01,0x61,0x51,0x63,0xBF,0xF9,0x0A,
  42017. 0x06,0x72,0xF1,0xD5,0x39,0x0C,0xBA,0xC9,
  42018. 0x78,0xC6,0x77,0x22,0xE4,0x96,0x6E,0xB1,
  42019. 0x48,0x62,0x84,0x62,0x2D,0xEA,0x49,0x56,
  42020. 0x50,0x86,0x3F,0x90,0xC3,0x01,0x42,0x45,
  42021. 0xED,0xE6,0x9A,0x65,0x19,0x93,0x7F,0x48,
  42022. 0x16,0xF2,0x50,0xA7,0x70,0xB3,0xF5,0xDB,
  42023. 0x0E,0x5E,0x22,0x9E,0x64,0x04,0x26,0x69,
  42024. 0xC1,0x16,0xEE,0x65,0x08,0x82,0x27,0x65,
  42025. 0xEC,0x3D,0xDF,0x51,0x5E,0x2D,0xE8,0x76,
  42026. 0xF2,0xE3,0xE4,0x24,0x04,0x88,0x06,0x0F,
  42027. 0xB2,0x7B,0x9B,0x72,0x3D,0x4C,0x7D,0x6A,
  42028. 0x1F,0xB2,0xA2,0xD2,0x35,0xD6,0x40,0x25,
  42029. 0xC2,0x0B,0x25,0xF9,0xDF,0x26,0xE4,0xDC,
  42030. 0xFB,0xB1,0x84,0x84,0x77,0x1B,0x45,0x51,
  42031. 0x60,0xD5,0xF0,0xB6,0x09,0xE6,0xBC,0xE3,
  42032. 0x1C,0x70,0x96,0x2C,0xD3,0x9D,0x7D,0x7F,
  42033. 0xB1,0x70,0xDA,0x79,0xB8,0x74,0x99,0xBF,
  42034. 0x84,0x95,0xCC,0x93,0xD7,0x51,0xDD,0x66,
  42035. 0xD3,0x70,0x0C,0x75,0x86,0x09,0x06,0xFD,
  42036. 0x66,0x14,0x80,0xCD,0xF3,0x59,0xB4,0x92,
  42037. 0x5F,0xE4,0xEE,0x00,0xA8,0xB0,0x8B,0x5C,
  42038. 0x3E,0xDB,0x8A,0x9C,0x0B,0xB5,0x99,0xC2,
  42039. 0x0D,0x81,0x09,0x06,0x6C,0x28,0xC0,0x7E,
  42040. 0xA5,0x07,0x70,0x64,0xD7,0x41,0xF4,0xC3,
  42041. 0x66,0x61,0x1C,0xA8,0x51,0xF6,0x3C,0xBA,
  42042. 0xE0,0x94,0xA3,0x11,0x8C,0x2E,0xBA,0x13,
  42043. 0xB2,0x47,0x48,0x93,0xB4,0x1A,0x2C,0x9A,
  42044. 0x6E,0x8E,0x30,0x66,0x7B,0xD3,0xBB,0x3B,
  42045. 0x5D,0x97,0x0D,0xE4,0xEA,0x24,0x28,0x9E,
  42046. 0xB4,0x88,0xCE,0x1D,0x7D,0x6F,0x39,0xB3,
  42047. 0x87,0x21,0xE5,0x08,0x93,0xF0,0xD4,0x9D,
  42048. 0x2D,0x91,0xC9,0xFD,0x0C,0x74,0x34,0xB4,
  42049. 0x1F,0xFE,0xDA,0xDC,0x10,0x5B,0x8D,0x2B,
  42050. 0x87,0xD3,0x42,0xB4,0xAE,0x32,0x9C,0xAE,
  42051. 0x4C,0x99,0xD8,0xED,0x44,0x41,0x07,0xE0,
  42052. 0x8F,0xBD,0xA5,0x7C,0x5A,0xDF,0x91,0x29,
  42053. 0x00,0xB5,0x4B,0xC3,0x3A,0x40,0x6C,0x48,
  42054. 0xAB,0x2A,0xF3,0x02,0xCB,0xB3,0x69,0xDA,
  42055. 0x06,0x0C,0x4D,0x5C,0x45,0xC3,0x28,0xAC,
  42056. 0x7A,0x01,0xD4,0xF8,0xCB,0x07,0x63,0x89,
  42057. 0x09,0x34,0x78,0xA7,0x14,0x39,0xCF,0x2D,
  42058. 0x94,0x8D,0x7A,0x4E,0x4E,0xBD,0xC4,0x32,
  42059. 0xAB,0x21,0xC9,0xDA,0x3F,0x5F,0x04,0x6B,
  42060. 0x14,0x40,0x18,0x18,0x2F,0xF9,0x46,0x17,
  42061. 0x57,0x54,0x9B,0x28,0x7B,0xBD,0xF9,0xA2,
  42062. 0x13,0xAC,0x69,0x24,0xB1,0x31,0x39,0xBF,
  42063. 0x8D,0x75,0xC3,0xFD,0x03,0x54,0x5A,0xFD,
  42064. 0xD4,0x7A,0xB7,0x56,0x4F,0x66,0x43,0x57,
  42065. 0x1B,0xFB,0xF9,0x92,0x7A,0x83,0xE6,0xFF,
  42066. 0xB4,0xBA,0x83,0xD2,0x61,0x8E,0x4A,0x82,
  42067. 0x82,0xA8,0xF5,0x0C,0xD2,0x43,0x53,0xA8,
  42068. 0x85,0x0A,0xD4,0x69,0x7B,0x04,0x71,0x3B,
  42069. 0x80,0x49,0x27,0x47,0x12,0xB6,0xB0,0xEA,
  42070. 0x90,0x0A,0xFA,0xA8,0xC8,0x78,0x61,0xDE,
  42071. 0x30,0x12,0xBB,0xDC,0xA6,0x57,0x56,0x30,
  42072. 0x6E,0xF1,0xA8,0x3B,0xF6,0x09,0x07,0xEA,
  42073. 0x31,0xE2,0x08,0x23,0x31,0x0F,0xD4,0x34,
  42074. 0xE3,0x60,0xC2,0x2B,0xDB,0x5A,0x99,0xCF,
  42075. 0xD4,0x6B,0x4E,0x75,0x65,0x35,0xE8,0x8B,
  42076. 0x93,0x7D,0xCA,0x11,0x47,0xF0,0x3E,0x11,
  42077. 0x5C,0xD1,0xEE,0x4B,0x11,0xB4,0x65,0x2B,
  42078. 0x6B,0x79,0xC0,0x86,0x60,0xA4,0x4B,0x24,
  42079. 0xA0,0x5C,0x70,0x34,0xC3,0x7C,0xE7,0x4F,
  42080. 0x97,0x89,0x4D,0xFE,0x22,0x89,0x3A,0xE9,
  42081. 0x07,0xB9,0x1A,0x86,0xB8,0x7A,0x12,0x38,
  42082. 0xE1,0x24,0x46,0xBC,0x9B,0x21,0xCD,0xAC,
  42083. 0x30,0xAB,0x98,0x21,0x31,0xC5,0x17,0x3F,
  42084. 0x1E,0x56,0xC3,0x18,0xCE,0xF0,0xA1,0xCC,
  42085. 0xFF,0x9D,0xA8,0x53,0xAF,0x74,0x77,0x54,
  42086. 0x02,0x9A,0x8F,0xA4,0xD4,0xBD,0xB2,0x1A,
  42087. 0xBA,0x52,0x2E,0x19,0xBE,0x49,0x11,0x45,
  42088. 0x02,0x01,0x7A,0xBF,0x28,0xD6,0x18,0xED,
  42089. 0xBD,0xCE,0xE4,0xDE,0xB5,0xF1,0x53,0x5D,
  42090. 0x65,0xF9,0x5F,0x83,0x8F,0x2D,0xF2,0x82,
  42091. 0xA0,0x2D,0x28,0xD3,0x0A,0x9E,0x0F,0x7F,
  42092. 0xC7,0xC4,0x43,0x7F,0xC3,0x0E,0x06,0xEB,
  42093. 0x4E,0xB4,0x2D,0xFA,0xDD,0x48,0xAB,0xF4,
  42094. 0x7D,0x41,0x48,0x33,0x5A,0xE6,0x70,0x02,
  42095. 0xE7,0x71,0x8D,0xD9,0x6B,0x0C,0x5A,0x8F,
  42096. 0xA4,0xC1,0xB7,0x4E,0x96,0x83,0xD6,0xA7,
  42097. 0x1D,0xF1,0x88,0xB3,0x6E,0xF4,0x12,0xA9,
  42098. 0xF6,0x31,0x69,0x66,0xFE,0xFE,0x02,0xF2,
  42099. 0x86,0x6D,0xBB,0x57,0x51,0x8C,0x4C,0xE9,
  42100. 0x7C,0x92,0x3E,0x3A,0xD3,0x2D,0xA8,0x82,
  42101. 0x53,0x84,0x26,0x89,0xBB,0xCC,0x13,0x12,
  42102. 0x3D,0x94,0xBB,0xDF,0x3D,0x4C,0xDF,0x27,
  42103. 0x9B,0x1F,0xB8,0xB6,0xE4,0xEA,0xA2,0x07,
  42104. 0xF8,0x4D,0x42,0x8F,0x29,0x90,0xFE,0x21,
  42105. 0x20,0xE9,0x55,0x02,0xAD,0x90,0xA7,0x77,
  42106. 0x4E,0x29,0xB6,0xD9,0x14,0x94,0xB2,0x25,
  42107. 0xA4,0xB2,0x0E,0x96,0x31,0xAB,0x9E,0x93,
  42108. 0x49,0xAC,0xA9,0xCB,0x68,0x22,0xBA,0xB8,
  42109. 0x57,0x5C,0x9D,0x65,0xC1,0xF1,0xFC,0x99,
  42110. 0x7C,0x3C,0xE9,0xEA,0x4B,0x29,0x22,0x2F,
  42111. 0xDB,0x17,0x21,0x8D,0xB0,0x13,0xBF,0xEE,
  42112. 0x7D,0xE4,0x8B,0x6D,0x17,0xE0,0x53,0x92,
  42113. 0x0B,0x32,0x6B,0xB1,0x65,0x2E,0xA7,0x83,
  42114. 0xFD,0x62,0x62,0xE3,0xAA,0x81,0xE8,0xD6,
  42115. 0xF7,0xB1,0x30,0x65,0x80,0x9F,0x77,0x1E,
  42116. 0x4A,0xEA,0xE8,0x45,0x32,0x12,0x3A,0xFB,
  42117. 0x22,0xE9,0xA9,0xF6,0xCB,0xAB,0xA8,0x0C,
  42118. 0x20,0xA8,0x7C,0xF9,0xF7,0x53,0xC1,0xB4,
  42119. 0xC0,0x5D,0x06,0x45,0xDD,0x7E,0xA7,0x34,
  42120. 0xA1,0x21,0xC2,0x62,0xAB,0x22,0x45,0x3D,
  42121. 0x73,0x4C,0x26,0xD1,0x1A,0xB2,0xF0,0xB2,
  42122. 0x6D,0x11,0x70,0x58,0xAA,0xF5,0xA4,0xF5,
  42123. 0xF8,0x0B,0x3D,0xC1,0xF6,0x17,0x70,0x15,
  42124. 0xCD,0x72,0x02,0x7E,0x4E,0x94,0x96,0x0A,
  42125. 0x56,0xCC,0xA5,0xA3,0xB3,0x7E,0xDD,0x5A,
  42126. 0x72,0xD2,0xFB,0xAC,0x3D,0x0E,0x66,0x65,
  42127. 0xE9,0x08,0x6C,0xB0,0x1C,0xE2,0x1A,0x82,
  42128. 0xF6,0xF3,0x34,0x89,0x73,0x02,0x5B,0x42,
  42129. 0x6D,0x40,0x61,0xB6,0xE0,0xE6,0x53,0x32,
  42130. 0xA5,0x72,0x17,0x4F,0x3B,0x51,0x4F,0xBC,
  42131. 0x00,0xE0,0x69,0x26,0xA9,0xAE,0x83,0xE3,
  42132. 0x73,0x7F,0x71,0x97,0xE0,0xDC,0x7C,0x63,
  42133. 0x9C,0x85,0x5F,0xDF,0x7D,0xE4,0x6C,0xD8,
  42134. 0xA9,0x3A,0x6F,0x5E,0x4A,0x2E,0xB0,0xE7,
  42135. 0x8B,0x45,0xE2,0x90,0x05,0x37,0xE8,0xAB,
  42136. 0x49,0x48,0x4C,0xC0,0x59,0x1D,0x8C,0x46,
  42137. 0x5B,0x84,0xE0,0x83,0xCE,0xEA,0x4B,0xF9,
  42138. 0xD4,0xDC,0x63,0xDF,0x79,0xB7,0x5C,0x11,
  42139. 0x25,0x7F,0x90,0x2E,0x0A,0x38,0x03,0xEA,
  42140. 0xEA,0xA1,0x26,0x52,0x20,0x19,0xA3,0xBE,
  42141. 0xFC,0x9D,0xB7,0x6E,0xA6,0x58,0x8E,0x6D,
  42142. 0xC5,0x58,0xE9,0xED,0x2F,0x55,0x43,0x8B,
  42143. 0x03,0x8B,0xE6,0xA4,0xC2,0x25,0x4B,0x36,
  42144. 0xBA,0xD3,0x27,0x48,0x40,0x2E,0x87,0xA2,
  42145. 0xD4,0x12,0xC6,0x05,0x36,0x03,0x11,0x51,
  42146. 0xD1,0xF2,0xAC,0x71,0x2C,0xB6,0xC3,0xA5,
  42147. 0x57,0x0F,0xAF,0x4B,0xBD,0xCD,0x47,0x4C,
  42148. 0x3A,0x52,0x6F,0x47,0xE7,0x0B,0xB7,0xD5,
  42149. 0xF7,0xA6,0x39,0x63,0x82,0x08,0x4C,0x41,
  42150. 0x0E,0x2A,0x52,0x42,0x5A,0xEA,0x59,0xC7,
  42151. 0x94,0xFB,0xD0,0x88,0x47,0x27,0xF6,0x97,
  42152. 0x03,0x9E,0x29,0xB8,0x3A,0x67,0xE6,0xF3,
  42153. 0x95,0xA7,0x42,0xC1,0x96,0xD1,0x9A,0xA6,
  42154. 0xF0,0x09,0x0C,0xEA,0xE0,0xAB,0x0F,0x15,
  42155. 0xE9,0xC3,0xEB,0xA5,0x89,0x86,0x98,0x32,
  42156. 0x83,0xAB,0x30,0x33,0xAE,0x90,0x8D,0x2E,
  42157. 0xB3,0xAA,0x91,0xA6,0xD9,0xA4,0x4A,0x54,
  42158. 0xE0,0xD3,0x08,0xCC,0x79,0xCE,0xE4,0x15,
  42159. 0x31,0xA6,0xCE,0x61,0xCF,0x03,0x06,0xEE,
  42160. 0x8E,0xE2,0x64,0x29,0xD1,0x54,0x9B,0xD0,
  42161. 0x5F,0x09,0x2B,0x8B,0xD5,0xF8,0xD4,0x7D,
  42162. 0xF1,0x97,0x32,0xD9,0xEA,0x5A,0x0E,0x10,
  42163. 0x8C,0x4D,0xFB,0x55,0xE6,0x27,0x0C,0xBA,
  42164. 0xC1,0x73,0xC1,0x73,0xE3,0x1C,0x09,0xB3,
  42165. 0x6F,0xB4,0x12,0xFA,0xF3,0x29,0xDC,0x23,
  42166. 0x32,0xED,0x80,0x87,0x83,0xC2,0xF6,0x07,
  42167. 0xB5,0xA9,0x22,0xDE,0x66,0x1A,0xA7,0x4A,
  42168. 0x86,0xF1,0x39,0x9B,0xF4,0xE7,0x50,0x15,
  42169. 0x4A,0x55,0x3C,0x93,0xB9,0xF9,0xFD,0xDC,
  42170. 0xB3,0x5D,0x73,0x52
  42171. };
  42172. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void)
  42173. {
  42174. XmssKey verifyKey;
  42175. unsigned char pub_raw[XMSS_SHA256_PUBLEN];
  42176. word32 pub_len = sizeof(pub_raw);
  42177. word32 pkSz = 0;
  42178. word32 sigSz = 0;
  42179. const char * param = "XMSS-SHA2_10_256";
  42180. int j = 0;
  42181. int ret2 = WC_TEST_RET_ENC_NC;
  42182. int ret = WC_TEST_RET_ENC_NC;
  42183. int n_diff = 0;
  42184. WOLFSSL_ENTER("xmss_test_verify_only");
  42185. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42186. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42187. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42188. ret = wc_XmssKey_SetParamStr(&verifyKey, param);
  42189. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42190. ret = wc_XmssKey_GetPubLen(&verifyKey, &pkSz);
  42191. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42192. if (pkSz != XMSS_SHA256_PUBLEN) {
  42193. return WC_TEST_RET_ENC_EC(pkSz);
  42194. }
  42195. ret = wc_XmssKey_GetSigLen(&verifyKey, &sigSz);
  42196. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42197. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  42198. fprintf(stderr, "param: %s\n", param);
  42199. fprintf(stderr, "pkSz: %d\n", pkSz);
  42200. fprintf(stderr, "sigSz: %d\n", sigSz);
  42201. #endif
  42202. if (sigSz != sizeof(xmss_sig)) {
  42203. return WC_TEST_RET_ENC_EC(sigSz);
  42204. }
  42205. ret = wc_XmssKey_ImportPubRaw(&verifyKey, xmss_pub, XMSS_SHA256_PUBLEN);
  42206. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42207. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42208. (byte *) xmss_msg, sizeof(xmss_msg));
  42209. if (ret != 0) {
  42210. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42211. return WC_TEST_RET_ENC_EC(ret);
  42212. }
  42213. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42214. ret = wc_XmssKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42215. if (ret != 0) {
  42216. printf("error: wc_XmssKey_ExportPubRaw returned %d, expected 0\n", ret);
  42217. return WC_TEST_RET_ENC_EC(ret);
  42218. }
  42219. if (pub_len != XMSS_SHA256_PUBLEN) {
  42220. printf("error: xmss pub len %u, expected %d\n", pub_len,
  42221. XMSS_SHA256_PUBLEN);
  42222. return WC_TEST_RET_ENC_EC(pub_len);
  42223. }
  42224. n_diff = XMEMCMP(pub_raw, xmss_pub, sizeof(xmss_pub));
  42225. if (n_diff != 0) {
  42226. printf("error: exported and imported pub raw do not match: %d\n",
  42227. n_diff);
  42228. return WC_TEST_RET_ENC_EC(n_diff);
  42229. }
  42230. /* Flip bits in message. This should fail. */
  42231. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42232. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42233. (byte *) xmss_msg, sizeof(xmss_msg));
  42234. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42235. printf("error: wc_XmssKey_Verify returned %d, expected -1\n", ret2);
  42236. return WC_TEST_RET_ENC_EC(ret2);
  42237. }
  42238. /* Flip it back. This should pass again. */
  42239. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42240. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42241. (byte *) xmss_msg, sizeof(xmss_msg));
  42242. if (ret != 0) {
  42243. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42244. return WC_TEST_RET_ENC_EC(ret);
  42245. }
  42246. /* Flip bits in a few places throughout the signature, stepping in multiple
  42247. * of hash size. These should all fail with -1. */
  42248. for (j = 0; j < (int) sizeof(xmss_sig); j+= 4 * 32) {
  42249. xmss_sig[j] ^= 1;
  42250. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42251. (byte *) xmss_msg, sizeof(xmss_msg));
  42252. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42253. /* Verify passed when it should have failed. */
  42254. return WC_TEST_RET_ENC_I(j);
  42255. }
  42256. /* Flip this spot back. */
  42257. xmss_sig[j] ^= 1;
  42258. }
  42259. /* Cleanup everything. */
  42260. wc_XmssKey_Free(&verifyKey);
  42261. return ret;
  42262. }
  42263. #endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_SMALL_STACK &&
  42264. * WOLFSSL_XMSS_MIN_HEIGHT <= 10 */
  42265. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  42266. static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
  42267. {
  42268. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  42269. * BE USED FOR TESTING PURPOSES! Production applications should
  42270. * write only to non-volatile storage. */
  42271. XMEMCPY(context, priv, privSz);
  42272. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  42273. }
  42274. static int lms_read_key_mem(byte * priv, word32 privSz, void *context)
  42275. {
  42276. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  42277. * BE USED FOR TESTING PURPOSES! */
  42278. XMEMCPY(priv, context, privSz);
  42279. return WC_LMS_RC_READ_TO_MEMORY;
  42280. }
  42281. /* LMS signature sizes are a function of their parameters. This
  42282. * test has a signature of 8688 bytes. */
  42283. #ifndef WOLFSSL_NO_LMS_SHA256_256
  42284. #define WC_TEST_LMS_SIG_LEN (8688)
  42285. #else
  42286. #define WC_TEST_LMS_SIG_LEN (4984)
  42287. #endif
  42288. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
  42289. {
  42290. int i = 0;
  42291. int j = 0;
  42292. int ret = WC_TEST_RET_ENC_NC;
  42293. int ret2 = WC_TEST_RET_ENC_NC;
  42294. int sigsLeft = 0;
  42295. LmsKey signingKey;
  42296. LmsKey verifyKey;
  42297. WC_RNG rng;
  42298. word32 sigSz = 0;
  42299. const char * msg = "LMS HSS post quantum signature test";
  42300. word32 msgSz = (word32) XSTRLEN(msg);
  42301. unsigned char priv[HSS_MAX_PRIVATE_KEY_LEN];
  42302. unsigned char old_priv[HSS_MAX_PRIVATE_KEY_LEN];
  42303. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42304. byte * sig = XMALLOC(WC_TEST_LMS_SIG_LEN, HEAP_HINT,
  42305. DYNAMIC_TYPE_TMP_BUFFER);
  42306. if (sig == NULL) {
  42307. return WC_TEST_RET_ENC_ERRNO;
  42308. }
  42309. #else
  42310. byte sig[WC_TEST_LMS_SIG_LEN];
  42311. #endif
  42312. WOLFSSL_ENTER("lms_test");
  42313. XMEMSET(priv, 0, sizeof(priv));
  42314. XMEMSET(old_priv, 0, sizeof(old_priv));
  42315. XMEMSET(sig, 0, WC_TEST_LMS_SIG_LEN);
  42316. #ifndef HAVE_FIPS
  42317. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  42318. #else
  42319. ret = wc_InitRng(&rng);
  42320. #endif
  42321. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42322. /* This test:
  42323. * levels: 1
  42324. * height: 5
  42325. * winternitz: 1
  42326. *
  42327. * max sigs: 2 ** (1 * 5) = 32
  42328. * signature length: 8688
  42329. */
  42330. ret = wc_LmsKey_Init(&signingKey, NULL, INVALID_DEVID);
  42331. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42332. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42333. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42334. ret = wc_LmsKey_SetParameters(&signingKey, 1, 5, 1);
  42335. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42336. ret = wc_LmsKey_SetWriteCb(&signingKey, lms_write_key_mem);
  42337. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42338. ret = wc_LmsKey_SetReadCb(&signingKey, lms_read_key_mem);
  42339. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42340. ret = wc_LmsKey_SetContext(&signingKey, (void *) priv);
  42341. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42342. ret = wc_LmsKey_MakeKey(&signingKey, &rng);
  42343. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42344. XMEMCPY(old_priv, priv, sizeof(priv));
  42345. ret = wc_LmsKey_ExportPub(&verifyKey, &signingKey);
  42346. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42347. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42348. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42349. if (sigSz != WC_TEST_LMS_SIG_LEN) {
  42350. printf("error: got %u, expected %d\n", sigSz, WC_TEST_LMS_SIG_LEN);
  42351. return WC_TEST_RET_ENC_EC(sigSz);
  42352. }
  42353. /* 2 ** 5 should be the max number of signatures */
  42354. for (i = 0; i < 32; ++i) {
  42355. /* We should have remaining signstures. */
  42356. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42357. if (sigsLeft == 0) {
  42358. return WC_TEST_RET_ENC_EC(sigsLeft);
  42359. }
  42360. /* Sign with key. The private key will be updated on every signature. */
  42361. ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  42362. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42363. /* The updated private key should not match the old one. */
  42364. if (XMEMCMP(old_priv, priv, sizeof(priv)) == 0) {
  42365. printf("error: current priv key should not match old: %d\n", i);
  42366. return WC_TEST_RET_ENC_I(i);
  42367. }
  42368. XMEMCPY(old_priv, priv, sizeof(priv));
  42369. ret = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  42370. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42371. /* Flip bits in a few places throughout the signature, stepping in multiple
  42372. * of hash size. These should all fail with -1. */
  42373. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42374. sig[j] ^= 1;
  42375. ret2 = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  42376. msgSz);
  42377. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42378. /* Verify passed when it should have failed. */
  42379. return WC_TEST_RET_ENC_I(j);
  42380. }
  42381. /* Flip this spot back. */
  42382. sig[j] ^= 1;
  42383. }
  42384. }
  42385. /* This should be the last signature. */
  42386. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42387. if (sigsLeft != 0) {
  42388. return WC_TEST_RET_ENC_EC(sigsLeft);
  42389. }
  42390. wc_LmsKey_Free(&signingKey);
  42391. wc_LmsKey_Free(&verifyKey);
  42392. wc_FreeRng(&rng);
  42393. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42394. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42395. #endif
  42396. return ret;
  42397. }
  42398. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  42399. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
  42400. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  42401. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  42402. /* A simple LMS verify only test.
  42403. *
  42404. * Note: LMS signature sizes are a function of their parameters. This
  42405. * test has a signature of 1456 bytes:
  42406. * levels: 1
  42407. * height: 10
  42408. * winternitz: 8
  42409. * max sigs: 2 ** (1 * 10) = 1024
  42410. * signature length: 1456
  42411. * */
  42412. /* "wolfSSL LMS example message!" without null terminator. */
  42413. static byte lms_msg[28] =
  42414. {
  42415. 0x77,0x6F,0x6C,0x66,0x53,0x53,0x4C,0x20,
  42416. 0x4C,0x4D,0x53,0x20,0x65,0x78,0x61,0x6D,
  42417. 0x70,0x6C,0x65,0x20,0x6D,0x65,0x73,0x73,
  42418. 0x61,0x67,0x65,0x21
  42419. };
  42420. static const byte lms_L1H10W8_pub[HSS_MAX_PUBLIC_KEY_LEN] =
  42421. {
  42422. 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,
  42423. 0x00,0x00,0x00,0x04,0xA1,0x26,0x76,0xF8,
  42424. 0xBB,0x0B,0xC0,0x82,0x21,0x71,0x0B,0x2E,
  42425. 0x8C,0xA6,0xEF,0x12,0xED,0x41,0x0E,0x8C,
  42426. 0xAF,0x11,0x93,0x34,0x7B,0x49,0x79,0xB7,
  42427. 0xDE,0x63,0x1C,0xFE,0x1F,0xD1,0x17,0x49,
  42428. 0xCD,0x5C,0xD4,0x26,0xA0,0x53,0x26,0x1A,
  42429. 0xC5,0xB4,0x8F,0x23
  42430. };
  42431. #define LMS_L1H10W8_SIGLEN (1456)
  42432. static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
  42433. {
  42434. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  42435. 0x00,0x00,0x00,0x04,0x18,0x70,0x09,0x2E,
  42436. 0x21,0xC9,0x6A,0xC9,0x5C,0xB6,0xB0,0xAA,
  42437. 0xC3,0xED,0x6E,0x66,0x2F,0xCC,0x45,0x81,
  42438. 0xBC,0xBA,0x44,0x96,0x1C,0xBF,0x4E,0xFB,
  42439. 0x7A,0x46,0xFB,0xBE,0x9A,0x0C,0xE4,0x50,
  42440. 0x90,0xC7,0x92,0xAC,0x53,0xAE,0x53,0x76,
  42441. 0x29,0xA6,0x65,0xF1,0x09,0xED,0x1A,0x8E,
  42442. 0x03,0x2E,0x5A,0x06,0x51,0xE3,0x1E,0xE6,
  42443. 0xF6,0xFE,0x3A,0x6E,0xD1,0x92,0x31,0x1D,
  42444. 0xA1,0x6A,0x5C,0x30,0x3A,0xC7,0xFD,0x5B,
  42445. 0xFE,0x71,0x2C,0x5C,0x2F,0x5B,0x5B,0xCF,
  42446. 0xBC,0x7F,0xBF,0x6C,0xAF,0x44,0x8A,0xAE,
  42447. 0x14,0x60,0xAB,0x88,0xED,0x0E,0x4F,0xF8,
  42448. 0xC7,0x1B,0x74,0x28,0x72,0xB3,0x96,0xA6,
  42449. 0xE6,0x46,0x22,0x82,0xCF,0x1F,0x4D,0xA6,
  42450. 0xEA,0x22,0x06,0x07,0x52,0xF5,0x26,0x16,
  42451. 0x0B,0x90,0xE3,0xFF,0x64,0xA9,0xE4,0x61,
  42452. 0x1E,0x9C,0x12,0x9C,0xF6,0xD4,0x63,0x29,
  42453. 0xEA,0x02,0xF7,0x18,0x52,0x79,0x6C,0x43,
  42454. 0xDC,0xCF,0x43,0x23,0xB9,0xCC,0x4A,0x25,
  42455. 0x9D,0x10,0xAF,0xA3,0xE6,0x47,0x5A,0x1C,
  42456. 0xFE,0x68,0x89,0xAF,0x1B,0x2D,0x88,0x3E,
  42457. 0xCA,0xDC,0x70,0xEA,0xAC,0x11,0x00,0x8A,
  42458. 0x6E,0xE0,0xC7,0xD0,0xD2,0x1A,0x36,0x18,
  42459. 0x97,0xB3,0x5F,0x0E,0x75,0x48,0x28,0xF8,
  42460. 0xA8,0xF5,0x90,0xD1,0xA1,0x84,0xFB,0xA4,
  42461. 0xAD,0x50,0xBE,0xE9,0x39,0x8C,0xC5,0xA1,
  42462. 0x67,0x51,0xA1,0x8C,0xD6,0x6B,0x97,0x1F,
  42463. 0x47,0x99,0xEE,0xE0,0x70,0x01,0xC7,0x07,
  42464. 0x50,0xF3,0x5E,0x3F,0xE7,0x06,0xD6,0x8D,
  42465. 0x26,0xD6,0x5A,0x59,0x18,0x72,0x6B,0x12,
  42466. 0xD2,0xAF,0x9B,0xB4,0x2B,0xD0,0xB2,0xF2,
  42467. 0x96,0x2F,0x40,0xEA,0xBE,0xE6,0xAC,0x1F,
  42468. 0xB8,0x33,0xC2,0x76,0xDC,0x8C,0xAC,0xC1,
  42469. 0x46,0x5E,0x04,0x84,0x1B,0xC8,0xB9,0x65,
  42470. 0x8D,0xAD,0x96,0xB5,0xB1,0xF6,0x17,0x4A,
  42471. 0x19,0x87,0xE7,0xBF,0x29,0xC7,0x9B,0xB9,
  42472. 0xD6,0x11,0x2C,0x92,0x2F,0xB7,0x24,0xD5,
  42473. 0x01,0x1D,0x80,0x37,0x54,0xED,0x33,0x32,
  42474. 0xAB,0x7A,0x12,0xD4,0x02,0x1D,0x27,0x52,
  42475. 0x89,0xDB,0x32,0xBF,0x61,0xD4,0xBB,0xB4,
  42476. 0x46,0x78,0x1B,0x64,0x17,0x84,0x4B,0x8A,
  42477. 0xBA,0xC6,0xC1,0xCF,0xC7,0x5D,0x8F,0x93,
  42478. 0xC5,0x9A,0x27,0x90,0xAC,0x17,0x98,0xFF,
  42479. 0xC8,0x22,0x59,0x55,0x90,0xB2,0x29,0x39,
  42480. 0xA0,0xBE,0x00,0x23,0x55,0x6B,0xDA,0x83,
  42481. 0xD8,0x5B,0x57,0x7C,0x67,0x1B,0xC3,0x6B,
  42482. 0x6D,0xC7,0x9B,0x2B,0x9E,0xB7,0x95,0xB3,
  42483. 0xF0,0x1B,0x89,0x5A,0xD7,0x4B,0x67,0xAF,
  42484. 0xDC,0x9E,0xCF,0x7E,0x1A,0xBA,0x1B,0xB9,
  42485. 0x3B,0x7A,0xDD,0x3F,0x0D,0xEE,0x4C,0x0B,
  42486. 0xD1,0x4F,0x34,0xF2,0x93,0xF7,0x21,0x64,
  42487. 0x2C,0x07,0x00,0x15,0x4F,0xE3,0x6A,0x9F,
  42488. 0x08,0x52,0xC2,0x65,0x47,0x1F,0x34,0x64,
  42489. 0x66,0x07,0xBC,0xEA,0xAF,0x9B,0xAA,0x39,
  42490. 0x15,0x8B,0x08,0x8C,0x24,0x41,0x9B,0x46,
  42491. 0x1B,0x5B,0x91,0x11,0xC4,0xFD,0xA9,0x88,
  42492. 0x35,0x0E,0x7D,0xAF,0xFD,0xB7,0x90,0x7E,
  42493. 0xD7,0x29,0x02,0x0A,0xDC,0xC8,0x3F,0xC0,
  42494. 0xFD,0x97,0xAF,0x50,0x49,0xA6,0x5E,0x12,
  42495. 0xC1,0xCD,0xEC,0x52,0xC5,0x51,0xF2,0x80,
  42496. 0x17,0x61,0xC7,0x7E,0xBE,0xD1,0x1B,0x65,
  42497. 0xA4,0xAB,0x92,0x8D,0x89,0xB2,0xC5,0x8F,
  42498. 0xFF,0xA5,0x6F,0xFA,0x62,0x75,0xE4,0xA1,
  42499. 0xD4,0x22,0xA8,0x9E,0x40,0x04,0x27,0x1F,
  42500. 0xCC,0x81,0xBA,0x28,0x67,0xA0,0x1C,0x80,
  42501. 0xEB,0xCA,0xB0,0x61,0xA5,0x48,0xD0,0x8A,
  42502. 0x25,0xEB,0x9E,0x67,0x8C,0x8E,0x9B,0xD1,
  42503. 0xAD,0xBB,0xC3,0xEA,0xD3,0xD4,0xC5,0x12,
  42504. 0x7B,0xDD,0x00,0x57,0x7F,0xF6,0xF7,0xF6,
  42505. 0x3C,0x05,0xCF,0xFC,0x12,0xE1,0x93,0x05,
  42506. 0xE5,0x9B,0x79,0x87,0x69,0xD8,0x82,0xD9,
  42507. 0xD7,0x1D,0x41,0x73,0xE4,0x52,0x1D,0x3E,
  42508. 0xE5,0x8C,0x8D,0x34,0xE1,0x75,0xA9,0xF1,
  42509. 0x9D,0x09,0xA2,0x5B,0xEF,0xDA,0x96,0x6E,
  42510. 0x76,0x3D,0xEA,0x50,0xD9,0xCF,0x4F,0xAC,
  42511. 0xAD,0x1D,0x35,0x72,0x1B,0x88,0x8B,0xCD,
  42512. 0x8C,0x8A,0x8A,0xE0,0x96,0x04,0xD8,0xBB,
  42513. 0x28,0x43,0x16,0x77,0x60,0x98,0x63,0xF9,
  42514. 0xB9,0x71,0x46,0xB7,0xE1,0xA7,0xA9,0x84,
  42515. 0xC3,0x65,0x82,0xE1,0x1B,0x67,0x04,0x2D,
  42516. 0x55,0x6B,0xF9,0xC0,0x79,0x09,0x09,0xE7,
  42517. 0xFD,0x06,0x4D,0x09,0x9B,0x1A,0xCE,0x35,
  42518. 0xFA,0x27,0x6F,0x2F,0x01,0x65,0x0D,0xA0,
  42519. 0x97,0x59,0x11,0xF0,0x48,0xD2,0xE7,0x46,
  42520. 0xBE,0xB4,0x0A,0xA3,0xE2,0x75,0x0E,0x09,
  42521. 0x94,0xD9,0x69,0x28,0xD4,0xDA,0x64,0xBA,
  42522. 0xFE,0xA4,0xB9,0xF0,0xBA,0xEB,0xBA,0xAC,
  42523. 0xA8,0xF9,0xD3,0x82,0x4C,0x36,0x80,0xFA,
  42524. 0xE5,0xF6,0x76,0xC3,0x80,0xFA,0x90,0x29,
  42525. 0xF4,0x85,0xA4,0xC6,0x25,0x22,0x79,0x7E,
  42526. 0x39,0x1E,0x30,0xB8,0x65,0x72,0xCF,0xE1,
  42527. 0x99,0xF0,0x75,0xE8,0x09,0xB4,0x92,0x96,
  42528. 0x1B,0x68,0x50,0x88,0xF1,0x2C,0x97,0xE3,
  42529. 0x2D,0x26,0x8F,0xC5,0x30,0xCF,0x24,0xCB,
  42530. 0xB2,0x60,0x77,0xDC,0x02,0x72,0x0D,0xD9,
  42531. 0x2E,0xF2,0x52,0xEA,0x00,0xF6,0x32,0x65,
  42532. 0xA5,0xC6,0x43,0x29,0x29,0x69,0xAB,0x27,
  42533. 0x0C,0x39,0xDF,0x76,0x3E,0x93,0x95,0xB1,
  42534. 0x2C,0xA2,0x0D,0x18,0xCE,0xA0,0x97,0x10,
  42535. 0x3C,0x90,0xC0,0xEF,0x0E,0x04,0xA6,0xC8,
  42536. 0xA0,0x21,0x3C,0x0B,0x22,0x77,0x7A,0x66,
  42537. 0xA5,0x90,0x25,0xA4,0x09,0x3E,0xD5,0x27,
  42538. 0x1F,0x6C,0x99,0x85,0x5C,0xA2,0x99,0x7A,
  42539. 0x25,0xEE,0x8D,0x32,0x3D,0xD3,0xDC,0xF5,
  42540. 0x00,0x5A,0x34,0x61,0xB6,0xCD,0x4E,0xBC,
  42541. 0x26,0x36,0xFB,0x44,0x97,0x35,0xBD,0x06,
  42542. 0x7D,0x2E,0x4A,0xA2,0xDC,0x24,0xFE,0x70,
  42543. 0x0A,0xF9,0x57,0xE3,0xEE,0xAB,0xD1,0x17,
  42544. 0xF3,0x7C,0xD6,0x37,0x26,0xFA,0x83,0x9F,
  42545. 0xDD,0xB2,0xE1,0xD7,0xF9,0xC7,0x0E,0x15,
  42546. 0x01,0xA6,0x58,0x32,0x98,0x04,0x32,0xD4,
  42547. 0xDE,0xB9,0xEF,0x09,0xFA,0xE4,0x5A,0xD7,
  42548. 0xDD,0x09,0x1C,0xC9,0xAC,0xB8,0x6A,0xF5,
  42549. 0x00,0x5D,0x6B,0x95,0x12,0x8C,0x2F,0xCC,
  42550. 0xD8,0xB9,0x50,0x3A,0xEB,0x74,0x86,0xD2,
  42551. 0x3F,0xA1,0x05,0x8F,0x6E,0xEF,0xF5,0xA4,
  42552. 0xD6,0x6E,0x53,0xFA,0x9E,0xFA,0xCE,0xDB,
  42553. 0x99,0x46,0xE7,0xC5,0xDA,0x92,0x51,0x4F,
  42554. 0x22,0x07,0xF3,0xA5,0x38,0x26,0xD3,0xEC,
  42555. 0xD6,0x01,0xDD,0x31,0x3A,0x48,0x93,0xF6,
  42556. 0x69,0x4F,0xD8,0xF6,0xC2,0x91,0xA5,0x7C,
  42557. 0xDF,0x51,0x64,0xF1,0x3B,0x79,0xBC,0x0A,
  42558. 0x2C,0xDC,0x33,0x5A,0x29,0xF6,0xB2,0x09,
  42559. 0x66,0xCA,0x24,0x9F,0x1A,0x18,0xF3,0x76,
  42560. 0x4C,0x5E,0x0B,0x81,0x7F,0x29,0x84,0xD8,
  42561. 0x7A,0xA8,0xD6,0x11,0xAC,0xEC,0xD9,0x07,
  42562. 0x91,0xEC,0xB6,0x6D,0xEC,0xDB,0xBE,0x6F,
  42563. 0x9F,0xC5,0x19,0x5E,0x56,0x87,0x20,0x80,
  42564. 0x75,0xD5,0x64,0xE9,0x80,0xBF,0x2D,0xD5,
  42565. 0x94,0x9F,0x8C,0xA4,0x54,0x41,0xAB,0xB1,
  42566. 0x8E,0xAD,0x51,0xE4,0x3C,0x24,0xF7,0x1D,
  42567. 0xFE,0x02,0x48,0x7C,0x6D,0xED,0xF1,0xAC,
  42568. 0xD9,0x79,0x42,0xE5,0x3A,0xCF,0x6A,0x4C,
  42569. 0x6D,0xE2,0x13,0xD2,0x2B,0x9D,0xAB,0x1F,
  42570. 0x70,0xD3,0xC0,0x6F,0x81,0xE9,0x9A,0x86,
  42571. 0x33,0x39,0x60,0xE7,0x6A,0x00,0x1F,0x97,
  42572. 0xEB,0xE5,0x1D,0x0D,0x66,0x15,0xC9,0xA2,
  42573. 0xB1,0xC0,0xF0,0x2E,0xF4,0x07,0xA2,0x2E,
  42574. 0x49,0x92,0x95,0x13,0xA3,0x18,0x46,0x25,
  42575. 0xB9,0x3C,0xA1,0x4B,0x00,0x00,0x00,0x06,
  42576. 0xAB,0xAA,0xF9,0x3F,0x7E,0x21,0xF4,0x0E,
  42577. 0xCE,0xFD,0xE0,0x44,0xAC,0xC7,0x1A,0x30,
  42578. 0x22,0x9D,0x0A,0xD7,0x96,0x2D,0x8F,0x9A,
  42579. 0x99,0x1F,0x40,0x75,0x7F,0x62,0xF9,0xC1,
  42580. 0x81,0x7B,0x4A,0x1B,0xFA,0xD6,0x87,0xB9,
  42581. 0xEF,0x58,0x48,0xE4,0x5C,0x79,0xE5,0xB1,
  42582. 0x2C,0x59,0xA4,0x42,0xDB,0xA6,0x53,0x70,
  42583. 0x80,0x61,0x17,0xD4,0xD3,0x77,0xBD,0x53,
  42584. 0x26,0x7C,0x0E,0x0E,0xFF,0x30,0x4B,0xD0,
  42585. 0x86,0xFC,0x02,0x20,0x24,0x46,0x5B,0xF5,
  42586. 0xE3,0x99,0x73,0x85,0x60,0x00,0x36,0x47,
  42587. 0x17,0xEE,0x0C,0xD2,0x80,0x71,0x46,0x0E,
  42588. 0x2B,0xB0,0xEF,0x7F,0xFE,0x3B,0xE5,0xE1,
  42589. 0x87,0xC2,0xAF,0x1A,0x6F,0x63,0xF4,0x5A,
  42590. 0xC4,0x16,0xF7,0xAD,0x07,0x70,0x71,0x85,
  42591. 0x7D,0x3D,0x67,0x08,0xB8,0xD8,0xE2,0xF0,
  42592. 0xA1,0xAC,0xD2,0x94,0x7D,0x93,0x03,0xDD,
  42593. 0x54,0xF9,0x64,0x19,0xB3,0xED,0x24,0x22,
  42594. 0x01,0xD7,0x12,0x5E,0xC1,0x2B,0x39,0x10,
  42595. 0x13,0xE2,0x56,0x1C,0xEE,0xF4,0x2A,0x49,
  42596. 0x7B,0xFB,0x36,0x8D,0xF8,0xAF,0x60,0xDF,
  42597. 0x10,0xF0,0x72,0xA2,0xED,0xB6,0x53,0x88,
  42598. 0xA9,0x0C,0xED,0x9C,0x18,0x33,0x7D,0x65,
  42599. 0x9B,0xB2,0x9C,0x3E,0xE9,0x1E,0x43,0x51,
  42600. 0x7E,0xBE,0x01,0x95,0xF6,0x60,0x65,0xBE,
  42601. 0xD1,0xF4,0xE2,0x83,0x6B,0xCA,0x7A,0x70,
  42602. 0x41,0x83,0x72,0xC0,0x23,0x51,0x13,0x11,
  42603. 0x2D,0xF9,0xC0,0x0D,0x7D,0x73,0x76,0xA5,
  42604. 0x30,0x83,0x68,0x10,0x35,0xA2,0x18,0x22,
  42605. 0x4E,0x21,0x93,0x27,0x6A,0x19,0x28,0x83,
  42606. 0x7F,0xDD,0xDD,0xFF,0xC3,0x8A,0x64,0x00,
  42607. 0x5F,0x1C,0x0D,0xF8,0xBB,0xD7,0x15,0xB9,
  42608. 0xEF,0xE0,0x07,0x62,0x05,0x9E,0xCF,0xFC,
  42609. 0x08,0x52,0x1E,0x65,0x41,0x56,0x6A,0xEB,
  42610. 0x81,0x53,0x30,0x7B,0xF2,0xFD,0x65,0xFF,
  42611. 0xA2,0x14,0xF5,0x62,0x1E,0x24,0x48,0x47,
  42612. 0xA5,0x41,0x80,0xB4,0xC5,0xDC,0xB2,0xB4,
  42613. 0x2D,0x17,0xE7,0xBE,0x49,0x53,0x7A,0x25,
  42614. 0xC5,0x0D,0x19,0x59,0xF4,0x88,0x59,0xED,
  42615. 0x92,0x13,0xEE,0x7A,0x4F,0x12,0x98,0x4C
  42616. };
  42617. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
  42618. {
  42619. LmsKey verifyKey;
  42620. unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
  42621. word32 pub_len = sizeof(pub_raw);
  42622. word32 sigSz = 0;
  42623. word32 msgSz = sizeof(lms_msg);
  42624. word32 pubSz = 0;
  42625. int levels = 0;
  42626. int height = 0;
  42627. int winternitz = 0;
  42628. int ret = WC_TEST_RET_ENC_NC;
  42629. int ret2 = WC_TEST_RET_ENC_NC;
  42630. int j = 0;
  42631. int n_diff = 0;
  42632. WOLFSSL_ENTER("lms_test_verify_only");
  42633. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42634. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42635. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42636. ret = wc_LmsKey_SetParameters(&verifyKey, 1, 10, 8);
  42637. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42638. ret = wc_LmsKey_ImportPubRaw(&verifyKey, lms_L1H10W8_pub,
  42639. HSS_MAX_PUBLIC_KEY_LEN);
  42640. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42641. /* Verify parameters, pub length, and sig length are correct. */
  42642. ret = wc_LmsKey_GetParameters(&verifyKey, &levels, &height, &winternitz);
  42643. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42644. if (levels != 1 || height != 10 || winternitz != 8) {
  42645. printf("error: invalid LMS parameters: L%d-H%d-W%d\n", levels, height,
  42646. winternitz);
  42647. return WC_TEST_RET_ENC_NC;
  42648. }
  42649. ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
  42650. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42651. if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
  42652. printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
  42653. return WC_TEST_RET_ENC_EC(pubSz);
  42654. }
  42655. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42656. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42657. if (sigSz != LMS_L1H10W8_SIGLEN) {
  42658. printf("error: got %u, expected %d\n", sigSz, LMS_L1H10W8_SIGLEN);
  42659. return WC_TEST_RET_ENC_EC(sigSz);
  42660. }
  42661. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42662. (byte *) lms_msg, msgSz);
  42663. if (ret != 0) {
  42664. printf("error: wc_LmsKey_Verify returned %d\n", ret);
  42665. return WC_TEST_RET_ENC_EC(ret);
  42666. }
  42667. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42668. ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42669. if (ret != 0) {
  42670. printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
  42671. return WC_TEST_RET_ENC_EC(ret);
  42672. }
  42673. if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
  42674. printf("error: LMS pub len %u, expected %d\n", pub_len,
  42675. HSS_MAX_PUBLIC_KEY_LEN);
  42676. return WC_TEST_RET_ENC_EC(pub_len);
  42677. }
  42678. n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
  42679. if (n_diff != 0) {
  42680. printf("error: exported and imported pub raw do not match: %d\n",
  42681. n_diff);
  42682. return WC_TEST_RET_ENC_EC(n_diff);
  42683. }
  42684. /* Flip bits in message. This should fail. */
  42685. lms_msg[msgSz / 2] ^= 1;
  42686. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42687. (byte *) lms_msg, msgSz);
  42688. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42689. printf("error: wc_LmsKey_Verify returned %d, expected -1\n", ret2);
  42690. return WC_TEST_RET_ENC_EC(ret);
  42691. }
  42692. /* Flip it back. This should pass again. */
  42693. lms_msg[msgSz / 2] ^= 1;
  42694. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42695. (byte *) lms_msg, msgSz);
  42696. if (ret != 0) {
  42697. printf("error: wc_LmsKey_Verify returned %d, expected 0\n", ret);
  42698. return WC_TEST_RET_ENC_EC(ret);
  42699. }
  42700. /* Flip bits in a few places throughout the signature, stepping in multiple
  42701. * of hash size. These should all fail with -1. */
  42702. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42703. lms_L1H10W8_sig[j] ^= 1;
  42704. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig,
  42705. LMS_L1H10W8_SIGLEN,
  42706. (byte *) lms_msg, msgSz);
  42707. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42708. /* Verify passed when it should have failed. */
  42709. return WC_TEST_RET_ENC_I(j);
  42710. }
  42711. /* Flip this spot back. */
  42712. lms_L1H10W8_sig[j] ^= 1;
  42713. }
  42714. wc_LmsKey_Free(&verifyKey);
  42715. return ret;
  42716. }
  42717. #endif
  42718. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK) */
  42719. static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --
  42720. * see print_fiducials() below.
  42721. */
  42722. #ifdef WOLFCRYPT_HAVE_ECCSI
  42723. static wc_test_ret_t eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk,
  42724. ecc_point* pvt)
  42725. {
  42726. wc_test_ret_t ret;
  42727. byte id[1] = { 0x00 };
  42728. int valid;
  42729. word32 sz;
  42730. byte data[256];
  42731. byte hash[WC_MAX_DIGEST_SIZE];
  42732. byte hashSz;
  42733. byte sig[257];
  42734. word32 sigSz;
  42735. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42736. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42737. return WC_TEST_RET_ENC_EC(ret);
  42738. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42739. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42740. return WC_TEST_RET_ENC_EC(ret);
  42741. ret = wc_InitEccsiKey(NULL, NULL, INVALID_DEVID);
  42742. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42743. return WC_TEST_RET_ENC_EC(ret);
  42744. ret = wc_InitEccsiKey(NULL, HEAP_HINT, INVALID_DEVID);
  42745. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42746. return WC_TEST_RET_ENC_EC(ret);
  42747. wc_FreeEccsiKey(NULL);
  42748. /* Create a valid key. */
  42749. ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID);
  42750. if (ret != 0)
  42751. return WC_TEST_RET_ENC_EC(ret);
  42752. ret = wc_MakeEccsiKey(NULL, NULL);
  42753. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42754. return WC_TEST_RET_ENC_EC(ret);
  42755. ret = wc_MakeEccsiKey(key, NULL);
  42756. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42757. return WC_TEST_RET_ENC_EC(ret);
  42758. ret = wc_MakeEccsiKey(NULL, rng);
  42759. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42760. return WC_TEST_RET_ENC_EC(ret);
  42761. ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL,
  42762. NULL);
  42763. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42764. return WC_TEST_RET_ENC_EC(ret);
  42765. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL);
  42766. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42767. return WC_TEST_RET_ENC_EC(ret);
  42768. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt);
  42769. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42770. return WC_TEST_RET_ENC_EC(ret);
  42771. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt);
  42772. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42773. return WC_TEST_RET_ENC_EC(ret);
  42774. ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42775. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42776. return WC_TEST_RET_ENC_EC(ret);
  42777. ret = wc_MakeEccsiPair(NULL, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42778. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42779. return WC_TEST_RET_ENC_EC(ret);
  42780. /* No key set */
  42781. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42782. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42783. return WC_TEST_RET_ENC_EC(ret);
  42784. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL,
  42785. NULL);
  42786. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42787. return WC_TEST_RET_ENC_EC(ret);
  42788. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42789. NULL);
  42790. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42791. return WC_TEST_RET_ENC_EC(ret);
  42792. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL,
  42793. &valid);
  42794. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42795. return WC_TEST_RET_ENC_EC(ret);
  42796. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt,
  42797. &valid);
  42798. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42799. return WC_TEST_RET_ENC_EC(ret);
  42800. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt,
  42801. &valid);
  42802. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42803. return WC_TEST_RET_ENC_EC(ret);
  42804. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42805. &valid);
  42806. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42807. return WC_TEST_RET_ENC_EC(ret);
  42808. /* No key set */
  42809. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42810. &valid);
  42811. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42812. return WC_TEST_RET_ENC_EC(ret);
  42813. ret = wc_ValidateEccsiPvt(NULL, NULL, NULL);
  42814. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42815. return WC_TEST_RET_ENC_EC(ret);
  42816. ret = wc_ValidateEccsiPvt(key, NULL, NULL);
  42817. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42818. return WC_TEST_RET_ENC_EC(ret);
  42819. ret = wc_ValidateEccsiPvt(NULL, pvt, NULL);
  42820. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42821. return WC_TEST_RET_ENC_EC(ret);
  42822. ret = wc_ValidateEccsiPvt(NULL, NULL, &valid);
  42823. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42824. return WC_TEST_RET_ENC_EC(ret);
  42825. ret = wc_ValidateEccsiPvt(key, pvt, NULL);
  42826. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42827. return WC_TEST_RET_ENC_EC(ret);
  42828. ret = wc_ValidateEccsiPvt(key, NULL, &valid);
  42829. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42830. return WC_TEST_RET_ENC_EC(ret);
  42831. ret = wc_ValidateEccsiPvt(NULL, pvt, &valid);
  42832. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42833. return WC_TEST_RET_ENC_EC(ret);
  42834. ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL);
  42835. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42836. return WC_TEST_RET_ENC_EC(ret);
  42837. ret = wc_EncodeEccsiPair(key, ssk, pvt, data, NULL);
  42838. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42839. return WC_TEST_RET_ENC_EC(ret);
  42840. ret = wc_EncodeEccsiPair(key, ssk, NULL, data, &sz);
  42841. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42842. return WC_TEST_RET_ENC_EC(ret);
  42843. ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz);
  42844. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42845. return WC_TEST_RET_ENC_EC(ret);
  42846. ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz);
  42847. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42848. return WC_TEST_RET_ENC_EC(ret);
  42849. /* No key created so no curve information. */
  42850. ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz);
  42851. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42852. return WC_TEST_RET_ENC_EC(ret);
  42853. ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL);
  42854. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42855. return WC_TEST_RET_ENC_EC(ret);
  42856. ret = wc_EncodeEccsiSsk(key, ssk, data, NULL);
  42857. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42858. return WC_TEST_RET_ENC_EC(ret);
  42859. ret = wc_EncodeEccsiSsk(key, NULL, data, &sz);
  42860. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42861. return WC_TEST_RET_ENC_EC(ret);
  42862. ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz);
  42863. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42864. return WC_TEST_RET_ENC_EC(ret);
  42865. ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1);
  42866. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42867. return WC_TEST_RET_ENC_EC(ret);
  42868. ret = wc_EncodeEccsiPvt(key, pvt, data, NULL, 1);
  42869. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42870. return WC_TEST_RET_ENC_EC(ret);
  42871. ret = wc_EncodeEccsiPvt(key, NULL, data, &sz, 1);
  42872. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42873. return WC_TEST_RET_ENC_EC(ret);
  42874. ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1);
  42875. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42876. return WC_TEST_RET_ENC_EC(ret);
  42877. ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL);
  42878. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42879. return WC_TEST_RET_ENC_EC(ret);
  42880. ret = wc_DecodeEccsiPair(key, data, 0, ssk, NULL);
  42881. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42882. return WC_TEST_RET_ENC_EC(ret);
  42883. ret = wc_DecodeEccsiPair(key, data, 0, NULL, pvt);
  42884. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42885. return WC_TEST_RET_ENC_EC(ret);
  42886. ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt);
  42887. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42888. return WC_TEST_RET_ENC_EC(ret);
  42889. ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt);
  42890. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42891. return WC_TEST_RET_ENC_EC(ret);
  42892. ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL);
  42893. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42894. return WC_TEST_RET_ENC_EC(ret);
  42895. ret = wc_DecodeEccsiSsk(key, data, 0, NULL);
  42896. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42897. return WC_TEST_RET_ENC_EC(ret);
  42898. ret = wc_DecodeEccsiSsk(key, NULL, 0, ssk);
  42899. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42900. return WC_TEST_RET_ENC_EC(ret);
  42901. ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk);
  42902. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42903. return WC_TEST_RET_ENC_EC(ret);
  42904. ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL);
  42905. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42906. return WC_TEST_RET_ENC_EC(ret);
  42907. ret = wc_DecodeEccsiPvt(key, data, 0, NULL);
  42908. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42909. return WC_TEST_RET_ENC_EC(ret);
  42910. ret = wc_DecodeEccsiPvt(key, NULL, 0, pvt);
  42911. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42912. return WC_TEST_RET_ENC_EC(ret);
  42913. ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt);
  42914. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42915. return WC_TEST_RET_ENC_EC(ret);
  42916. ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL);
  42917. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42918. return WC_TEST_RET_ENC_EC(ret);
  42919. ret = wc_DecodeEccsiPvtFromSig(key, data, 0, NULL);
  42920. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42921. return WC_TEST_RET_ENC_EC(ret);
  42922. ret = wc_DecodeEccsiPvtFromSig(key, NULL, 0, pvt);
  42923. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42924. return WC_TEST_RET_ENC_EC(ret);
  42925. ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt);
  42926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42927. return WC_TEST_RET_ENC_EC(ret);
  42928. ret = wc_ExportEccsiKey(NULL, data, NULL);
  42929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42930. return WC_TEST_RET_ENC_EC(ret);
  42931. ret = wc_ExportEccsiKey(key, data, NULL);
  42932. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42933. return WC_TEST_RET_ENC_EC(ret);
  42934. ret = wc_ExportEccsiKey(NULL, data, &sz);
  42935. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42936. return WC_TEST_RET_ENC_EC(ret);
  42937. /* No key to export */
  42938. ret = wc_ExportEccsiKey(key, NULL, &sz);
  42939. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42940. return WC_TEST_RET_ENC_EC(ret);
  42941. ret = wc_ImportEccsiKey(NULL, NULL, 0);
  42942. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42943. return WC_TEST_RET_ENC_EC(ret);
  42944. ret = wc_ImportEccsiKey(key, NULL, 0);
  42945. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42946. return WC_TEST_RET_ENC_EC(ret);
  42947. ret = wc_ImportEccsiKey(NULL, data, 0);
  42948. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42949. return WC_TEST_RET_ENC_EC(ret);
  42950. ret = wc_ExportEccsiPrivateKey(NULL, data, NULL);
  42951. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42952. return WC_TEST_RET_ENC_EC(ret);
  42953. ret = wc_ExportEccsiPrivateKey(key, data, NULL);
  42954. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42955. return WC_TEST_RET_ENC_EC(ret);
  42956. ret = wc_ExportEccsiPrivateKey(NULL, data, &sz);
  42957. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42958. return WC_TEST_RET_ENC_EC(ret);
  42959. /* No key to export */
  42960. ret = wc_ExportEccsiPrivateKey(key, NULL, &sz);
  42961. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42962. return WC_TEST_RET_ENC_EC(ret);
  42963. ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0);
  42964. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42965. return WC_TEST_RET_ENC_EC(ret);
  42966. ret = wc_ImportEccsiPrivateKey(key, NULL, 0);
  42967. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42968. return WC_TEST_RET_ENC_EC(ret);
  42969. ret = wc_ImportEccsiPrivateKey(NULL, data, 0);
  42970. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42971. return WC_TEST_RET_ENC_EC(ret);
  42972. ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1);
  42973. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42974. return WC_TEST_RET_ENC_EC(ret);
  42975. ret = wc_ExportEccsiPublicKey(key, data, NULL, 1);
  42976. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42977. return WC_TEST_RET_ENC_EC(ret);
  42978. ret = wc_ExportEccsiPublicKey(NULL, data, &sz, 1);
  42979. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42980. return WC_TEST_RET_ENC_EC(ret);
  42981. /* No key to export */
  42982. ret = wc_ExportEccsiPublicKey(key, data, &sz, 1);
  42983. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42984. return WC_TEST_RET_ENC_EC(ret);
  42985. ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1);
  42986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42987. return WC_TEST_RET_ENC_EC(ret);
  42988. ret = wc_ImportEccsiPublicKey(key, NULL, 0, 1);
  42989. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42990. return WC_TEST_RET_ENC_EC(ret);
  42991. ret = wc_ImportEccsiPublicKey(NULL, data, 0, 1);
  42992. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42993. return WC_TEST_RET_ENC_EC(ret);
  42994. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL);
  42995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42996. return WC_TEST_RET_ENC_EC(ret);
  42997. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, NULL);
  42998. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42999. return WC_TEST_RET_ENC_EC(ret);
  43000. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, NULL, &hashSz);
  43001. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43002. return WC_TEST_RET_ENC_EC(ret);
  43003. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, NULL, hash, &hashSz);
  43004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43005. return WC_TEST_RET_ENC_EC(ret);
  43006. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, NULL, 1, pvt, hash,
  43007. &hashSz);
  43008. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43009. return WC_TEST_RET_ENC_EC(ret);
  43010. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43011. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43012. return WC_TEST_RET_ENC_EC(ret);
  43013. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43014. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43015. return WC_TEST_RET_ENC_EC(ret);
  43016. ret = wc_SetEccsiHash(NULL, NULL, 1);
  43017. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43018. return WC_TEST_RET_ENC_EC(ret);
  43019. ret = wc_SetEccsiHash(key, NULL, 1);
  43020. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43021. return WC_TEST_RET_ENC_EC(ret);
  43022. ret = wc_SetEccsiHash(NULL, hash, 1);
  43023. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43024. return WC_TEST_RET_ENC_EC(ret);
  43025. ret = wc_SetEccsiPair(NULL, NULL, NULL);
  43026. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43027. return WC_TEST_RET_ENC_EC(ret);
  43028. ret = wc_SetEccsiPair(key, NULL, NULL);
  43029. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43030. return WC_TEST_RET_ENC_EC(ret);
  43031. ret = wc_SetEccsiPair(NULL, ssk, NULL);
  43032. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43033. return WC_TEST_RET_ENC_EC(ret);
  43034. ret = wc_SetEccsiPair(NULL, NULL, pvt);
  43035. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43036. return WC_TEST_RET_ENC_EC(ret);
  43037. ret = wc_SetEccsiPair(key, ssk, NULL);
  43038. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43039. return WC_TEST_RET_ENC_EC(ret);
  43040. ret = wc_SetEccsiPair(key, NULL, pvt);
  43041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43042. return WC_TEST_RET_ENC_EC(ret);
  43043. ret = wc_SetEccsiPair(NULL, ssk, pvt);
  43044. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43045. return WC_TEST_RET_ENC_EC(ret);
  43046. ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL);
  43047. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43048. return WC_TEST_RET_ENC_EC(ret);
  43049. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, sig, NULL);
  43050. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43051. return WC_TEST_RET_ENC_EC(ret);
  43052. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, NULL, 0, sig,
  43053. &sigSz);
  43054. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43055. return WC_TEST_RET_ENC_EC(ret);
  43056. ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig,
  43057. &sigSz);
  43058. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43059. return WC_TEST_RET_ENC_EC(ret);
  43060. ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig,
  43061. &sigSz);
  43062. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43063. return WC_TEST_RET_ENC_EC(ret);
  43064. /* Key not set. */
  43065. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43066. &sigSz);
  43067. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43068. return WC_TEST_RET_ENC_EC(ret);
  43069. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  43070. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43071. return WC_TEST_RET_ENC_EC(ret);
  43072. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  43073. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43074. return WC_TEST_RET_ENC_EC(ret);
  43075. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, NULL, 0, NULL);
  43076. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43077. return WC_TEST_RET_ENC_EC(ret);
  43078. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, NULL);
  43079. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43080. return WC_TEST_RET_ENC_EC(ret);
  43081. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0,
  43082. &valid);
  43083. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43084. return WC_TEST_RET_ENC_EC(ret);
  43085. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL);
  43086. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43087. return WC_TEST_RET_ENC_EC(ret);
  43088. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, NULL, 0,
  43089. &valid);
  43090. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43091. return WC_TEST_RET_ENC_EC(ret);
  43092. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0,
  43093. &valid);
  43094. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43095. return WC_TEST_RET_ENC_EC(ret);
  43096. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43097. &valid);
  43098. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43099. return WC_TEST_RET_ENC_EC(ret);
  43100. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43101. &valid);
  43102. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43103. return WC_TEST_RET_ENC_EC(ret);
  43104. ret = wc_SetEccsiPair(key, ssk, pvt);
  43105. if (ret != 0)
  43106. return WC_TEST_RET_ENC_EC(ret);
  43107. /* Identity hash not set. */
  43108. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43109. &sigSz);
  43110. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43111. return WC_TEST_RET_ENC_EC(ret);
  43112. wc_FreeEccsiKey(key);
  43113. return 0;
  43114. }
  43115. /* RFC 6507: Appendix A */
  43116. static wc_test_ret_t eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt)
  43117. {
  43118. wc_test_ret_t ret;
  43119. int verified;
  43120. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00 };
  43121. word32 msgSz = sizeof(msg);
  43122. byte hash[WC_SHA256_DIGEST_SIZE];
  43123. byte hashSz = WC_SHA256_DIGEST_SIZE;
  43124. static const byte id[] = {
  43125. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43126. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43127. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43128. 0x33, 0x00
  43129. };
  43130. word32 idSz = sizeof(id);
  43131. static const byte sig[] = {
  43132. 0x26, 0x9D, 0x4C, 0x8F, 0xDE, 0xB6, 0x6A, 0x74,
  43133. 0xE4, 0xEF, 0x8C, 0x0D, 0x5D, 0xCC, 0x59, 0x7D,
  43134. 0xDF, 0xE6, 0x02, 0x9C, 0x2A, 0xFF, 0xC4, 0x93,
  43135. 0x60, 0x08, 0xCD, 0x2C, 0xC1, 0x04, 0x5D, 0x81,
  43136. 0xE0, 0x9B, 0x52, 0x8D, 0x0E, 0xF8, 0xD6, 0xDF,
  43137. 0x1A, 0xA3, 0xEC, 0xBF, 0x80, 0x11, 0x0C, 0xFC,
  43138. 0xEC, 0x9F, 0xC6, 0x82, 0x52, 0xCE, 0xBB, 0x67,
  43139. 0x9F, 0x41, 0x34, 0x84, 0x69, 0x40, 0xCC, 0xFD,
  43140. 0x04,
  43141. 0x75, 0x8A, 0x14, 0x27, 0x79, 0xBE, 0x89, 0xE8,
  43142. 0x29, 0xE7, 0x19, 0x84, 0xCB, 0x40, 0xEF, 0x75,
  43143. 0x8C, 0xC4, 0xAD, 0x77, 0x5F, 0xC5, 0xB9, 0xA3,
  43144. 0xE1, 0xC8, 0xED, 0x52, 0xF6, 0xFA, 0x36, 0xD9,
  43145. 0xA7, 0x9D, 0x24, 0x76, 0x92, 0xF4, 0xED, 0xA3,
  43146. 0xA6, 0xBD, 0xAB, 0x77, 0xD6, 0xAA, 0x64, 0x74,
  43147. 0xA4, 0x64, 0xAE, 0x49, 0x34, 0x66, 0x3C, 0x52,
  43148. 0x65, 0xBA, 0x70, 0x18, 0xBA, 0x09, 0x1F, 0x79
  43149. };
  43150. word32 sigSz = sizeof(sig);
  43151. static const byte pubData[] = {
  43152. 0x50, 0xD4, 0x67, 0x0B, 0xDE, 0x75, 0x24, 0x4F,
  43153. 0x28, 0xD2, 0x83, 0x8A, 0x0D, 0x25, 0x55, 0x8A,
  43154. 0x7A, 0x72, 0x68, 0x6D, 0x45, 0x22, 0xD4, 0xC8,
  43155. 0x27, 0x3F, 0xB6, 0x44, 0x2A, 0xEB, 0xFA, 0x93,
  43156. 0xDB, 0xDD, 0x37, 0x55, 0x1A, 0xFD, 0x26, 0x3B,
  43157. 0x5D, 0xFD, 0x61, 0x7F, 0x39, 0x60, 0xC6, 0x5A,
  43158. 0x8C, 0x29, 0x88, 0x50, 0xFF, 0x99, 0xF2, 0x03,
  43159. 0x66, 0xDC, 0xE7, 0xD4, 0x36, 0x72, 0x17, 0xF4
  43160. };
  43161. static const byte expHash[] = {
  43162. 0x49, 0x0f, 0x3f, 0xeb, 0xbc, 0x1c, 0x90, 0x2f,
  43163. 0x62, 0x89, 0x72, 0x3d, 0x7f, 0x8c, 0xbf, 0x79,
  43164. 0xdb, 0x88, 0x93, 0x08, 0x49, 0xd1, 0x9f, 0x38,
  43165. 0xf0, 0x29, 0x5b, 0x5c, 0x27, 0x6c, 0x14, 0xd1
  43166. };
  43167. ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0);
  43168. if (ret != 0)
  43169. return WC_TEST_RET_ENC_EC(ret);
  43170. ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt);
  43171. if (ret != 0)
  43172. return WC_TEST_RET_ENC_EC(ret);
  43173. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash,
  43174. &hashSz);
  43175. if (ret != 0)
  43176. return WC_TEST_RET_ENC_EC(ret);
  43177. if (hashSz != sizeof(expHash))
  43178. return WC_TEST_RET_ENC_NC;
  43179. if (XMEMCMP(hash, expHash, hashSz) != 0)
  43180. return WC_TEST_RET_ENC_NC;
  43181. ret = wc_SetEccsiHash(key, hash, hashSz);
  43182. if (ret != 0)
  43183. return WC_TEST_RET_ENC_EC(ret);
  43184. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43185. &verified);
  43186. if (ret != 0)
  43187. return WC_TEST_RET_ENC_EC(ret);
  43188. if (!verified)
  43189. return WC_TEST_RET_ENC_NC;
  43190. return 0;
  43191. }
  43192. static wc_test_ret_t eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt)
  43193. {
  43194. wc_test_ret_t ret;
  43195. byte data[32 * 3];
  43196. word32 sz;
  43197. ecc_point* decPvt = NULL;
  43198. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43199. mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT,
  43200. DYNAMIC_TYPE_TMP_BUFFER);
  43201. if (decSsk == NULL)
  43202. return WC_TEST_RET_ENC_ERRNO;
  43203. #else
  43204. mp_int decSsk[1];
  43205. #endif
  43206. ret = mp_init(decSsk);
  43207. if (ret != 0)
  43208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43209. decPvt = wc_ecc_new_point();
  43210. if (decPvt == NULL)
  43211. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  43212. ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz);
  43213. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43215. if (sz != 32 * 3)
  43216. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43217. ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz);
  43218. if (ret != 0)
  43219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43220. if (sz != 32* 3)
  43221. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43222. ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt);
  43223. if (ret != 0)
  43224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43225. ret = mp_cmp(ssk, decSsk);
  43226. if (ret != MP_EQ)
  43227. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43228. ret = wc_ecc_cmp_point(pvt, decPvt);
  43229. if (ret != MP_EQ)
  43230. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43231. ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz);
  43232. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43234. if (sz != 32)
  43235. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43236. ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz);
  43237. if (ret != 0)
  43238. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43239. if (sz != 32)
  43240. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43241. ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk);
  43242. if (ret != 0)
  43243. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43244. ret = mp_cmp(ssk, decSsk);
  43245. if (ret != MP_EQ)
  43246. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43247. ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1);
  43248. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43249. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43250. if (sz != 32 * 2)
  43251. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43252. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1);
  43253. if (ret != 0)
  43254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43255. if (sz != 32 * 2)
  43256. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43257. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43258. if (ret != 0)
  43259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43260. ret = wc_ecc_cmp_point(pvt, decPvt);
  43261. if (ret != MP_EQ)
  43262. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43263. sz = sizeof(data);
  43264. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0);
  43265. if (ret != 0)
  43266. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43267. if (sz != 32 * 2 + 1)
  43268. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43269. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43270. if (ret != 0)
  43271. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43272. ret = wc_ecc_cmp_point(pvt, decPvt);
  43273. if (ret != MP_EQ)
  43274. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43275. wc_ecc_del_point(decPvt);
  43276. out:
  43277. mp_free(decSsk);
  43278. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43279. XFREE(decSsk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43280. #endif
  43281. return ret;
  43282. }
  43283. static wc_test_ret_t eccsi_imp_exp_key_test(EccsiKey* priv)
  43284. {
  43285. wc_test_ret_t ret;
  43286. byte data[32 * 3];
  43287. byte out[32 * 3];
  43288. word32 sz;
  43289. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43290. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43291. return WC_TEST_RET_ENC_EC(ret);
  43292. if (sz != 32 * 3)
  43293. return WC_TEST_RET_ENC_NC;
  43294. ret = wc_ExportEccsiKey(priv, data, &sz);
  43295. if (ret != 0)
  43296. return WC_TEST_RET_ENC_EC(ret);
  43297. ret = wc_ImportEccsiKey(priv, data, sz);
  43298. if (ret != 0)
  43299. return WC_TEST_RET_ENC_EC(ret);
  43300. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43301. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43302. return WC_TEST_RET_ENC_EC(ret);
  43303. if (sz != 32 * 3)
  43304. return WC_TEST_RET_ENC_NC;
  43305. ret = wc_ExportEccsiKey(priv, out, &sz);
  43306. if (ret != 0)
  43307. return WC_TEST_RET_ENC_EC(ret);
  43308. if (sz != 32 * 3)
  43309. return WC_TEST_RET_ENC_NC;
  43310. if (XMEMCMP(data, out, sz) != 0)
  43311. return WC_TEST_RET_ENC_NC;
  43312. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43313. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43314. return WC_TEST_RET_ENC_EC(ret);
  43315. if (sz != 32)
  43316. return WC_TEST_RET_ENC_NC;
  43317. ret = wc_ExportEccsiPrivateKey(priv, data, &sz);
  43318. if (ret != 0)
  43319. return WC_TEST_RET_ENC_EC(ret);
  43320. ret = wc_ImportEccsiPrivateKey(priv, data, sz);
  43321. if (ret != 0)
  43322. return WC_TEST_RET_ENC_EC(ret);
  43323. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43324. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43325. return WC_TEST_RET_ENC_EC(ret);
  43326. if (sz != 32)
  43327. return WC_TEST_RET_ENC_NC;
  43328. ret = wc_ExportEccsiPrivateKey(priv, out, &sz);
  43329. if (ret != 0)
  43330. return WC_TEST_RET_ENC_EC(ret);
  43331. if (sz != 32)
  43332. return WC_TEST_RET_ENC_NC;
  43333. if (XMEMCMP(data, out, sz) != 0)
  43334. return WC_TEST_RET_ENC_NC;
  43335. return 0;
  43336. }
  43337. static wc_test_ret_t eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2)
  43338. {
  43339. wc_test_ret_t ret;
  43340. byte data[32 * 2 + 1];
  43341. byte pubData[32 * 2 + 1];
  43342. word32 sz;
  43343. ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1);
  43344. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43345. return WC_TEST_RET_ENC_EC(ret);
  43346. if (sz != 32 * 2)
  43347. return WC_TEST_RET_ENC_NC;
  43348. ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1);
  43349. if (ret != 0)
  43350. return WC_TEST_RET_ENC_EC(ret);
  43351. ret = wc_ImportEccsiPublicKey(key2, data, sz, 1);
  43352. if (ret != 0)
  43353. return WC_TEST_RET_ENC_EC(ret);
  43354. sz = sizeof(pubData);
  43355. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1);
  43356. if (ret != 0)
  43357. return WC_TEST_RET_ENC_EC(ret);
  43358. if (sz != 32 * 2)
  43359. return WC_TEST_RET_ENC_NC;
  43360. if (XMEMCMP(data, pubData, sz) != 0)
  43361. return WC_TEST_RET_ENC_NC;
  43362. sz = sizeof(pubData);
  43363. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0);
  43364. if (ret != 0)
  43365. return WC_TEST_RET_ENC_EC(ret);
  43366. if (sz != 32 * 2 + 1)
  43367. return WC_TEST_RET_ENC_NC;
  43368. if (pubData[0] != 0x04)
  43369. return WC_TEST_RET_ENC_NC;
  43370. if (XMEMCMP(pubData + 1, data, sz - 1) != 0)
  43371. return WC_TEST_RET_ENC_NC;
  43372. ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0);
  43373. if (ret != 0)
  43374. return WC_TEST_RET_ENC_EC(ret);
  43375. return 0;
  43376. }
  43377. static wc_test_ret_t eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43378. mp_int* ssk, ecc_point* pvt)
  43379. {
  43380. wc_test_ret_t ret;
  43381. char mail[] = "test@wolfssl.com";
  43382. byte* id = (byte*)mail;
  43383. word32 idSz = (word32) XSTRLEN(mail);
  43384. int valid;
  43385. ret = wc_MakeEccsiKey(priv, rng);
  43386. if (ret != 0)
  43387. return WC_TEST_RET_ENC_EC(ret);
  43388. ret = eccsi_imp_exp_key_test(priv);
  43389. if (ret < 0)
  43390. return ret;
  43391. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43392. if (ret < 0)
  43393. return ret;
  43394. ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt);
  43395. if (ret != 0)
  43396. return WC_TEST_RET_ENC_EC(ret);
  43397. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43398. &valid);
  43399. if (ret != 0)
  43400. return WC_TEST_RET_ENC_EC(ret);
  43401. if (!valid)
  43402. return WC_TEST_RET_ENC_NC;
  43403. ret = eccsi_enc_dec_pair_test(priv, ssk, pvt);
  43404. if (ret != 0)
  43405. return ret;
  43406. return 0;
  43407. }
  43408. static wc_test_ret_t eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43409. mp_int* ssk, ecc_point* pvt)
  43410. {
  43411. wc_test_ret_t ret;
  43412. byte hashPriv[WC_MAX_DIGEST_SIZE];
  43413. byte hashPub[WC_MAX_DIGEST_SIZE];
  43414. byte hashSz;
  43415. byte sig[144];
  43416. word32 sigSz;
  43417. int verified, valid;
  43418. char mail[] = "test@wolfssl.com";
  43419. byte* id = (byte*)mail;
  43420. word32 idSz = (word32) XSTRLEN(mail);
  43421. byte msg[] = { 0x00 };
  43422. word32 msgSz = sizeof(msg);
  43423. #ifdef WOLFSSL_SHA384
  43424. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv,
  43425. &hashSz);
  43426. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43427. return WC_TEST_RET_ENC_EC(ret);
  43428. #endif
  43429. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv,
  43430. &hashSz);
  43431. if (ret != 0)
  43432. return WC_TEST_RET_ENC_EC(ret);
  43433. if (hashSz != 32)
  43434. return WC_TEST_RET_ENC_NC;
  43435. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub,
  43436. &hashSz);
  43437. if (ret != 0)
  43438. return WC_TEST_RET_ENC_EC(ret);
  43439. if (hashSz != 32)
  43440. return WC_TEST_RET_ENC_NC;
  43441. if (XMEMCMP(hashPriv, hashPub, hashSz) != 0)
  43442. return WC_TEST_RET_ENC_NC;
  43443. ret = wc_SetEccsiHash(priv, hashPriv, hashSz);
  43444. if (ret != 0)
  43445. return WC_TEST_RET_ENC_EC(ret);
  43446. ret = wc_SetEccsiPair(priv, ssk, pvt);
  43447. if (ret != 0)
  43448. return WC_TEST_RET_ENC_EC(ret);
  43449. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL,
  43450. &sigSz);
  43451. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43452. return WC_TEST_RET_ENC_EC(ret);
  43453. if (sigSz != 129)
  43454. return WC_TEST_RET_ENC_NC;
  43455. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig,
  43456. &sigSz);
  43457. if (ret != 0)
  43458. return WC_TEST_RET_ENC_EC(ret);
  43459. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43460. if (ret != 0)
  43461. return WC_TEST_RET_ENC_EC(ret);
  43462. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43463. &verified);
  43464. if (ret != 0)
  43465. return WC_TEST_RET_ENC_EC(ret);
  43466. if (!verified)
  43467. return WC_TEST_RET_ENC_NC;
  43468. /* Check that changing HS results in verification failure. */
  43469. hashPub[0] ^= 0x80;
  43470. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43471. if (ret != 0)
  43472. return WC_TEST_RET_ENC_EC(ret);
  43473. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43474. &verified);
  43475. if (ret != 0)
  43476. return WC_TEST_RET_ENC_EC(ret);
  43477. if (verified)
  43478. return WC_TEST_RET_ENC_NC;
  43479. hashPub[0] ^= 0x80;
  43480. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43481. if (ret != 0)
  43482. return WC_TEST_RET_ENC_EC(ret);
  43483. /* Check that changing msg results in verification failure. */
  43484. msg[0] ^= 0x80;
  43485. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43486. &verified);
  43487. if (ret != 0)
  43488. return WC_TEST_RET_ENC_EC(ret);
  43489. if (verified)
  43490. return WC_TEST_RET_ENC_NC;
  43491. msg[0] ^= 0x80;
  43492. /* Check that changing signature results in verification failure. */
  43493. sig[0] ^= 0x80;
  43494. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43495. &verified);
  43496. if (ret != 0)
  43497. return WC_TEST_RET_ENC_EC(ret);
  43498. if (verified)
  43499. return WC_TEST_RET_ENC_NC;
  43500. sig[0] ^= 0x80;
  43501. /* Check that key state hasn't been invalidated. */
  43502. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43503. &verified);
  43504. if (ret != 0)
  43505. return WC_TEST_RET_ENC_EC(ret);
  43506. if (!verified)
  43507. return WC_TEST_RET_ENC_NC;
  43508. /* Check that verifying with the private key works. */
  43509. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43510. &verified);
  43511. if (ret != 0)
  43512. return WC_TEST_RET_ENC_EC(ret);
  43513. if (!verified)
  43514. return WC_TEST_RET_ENC_NC;
  43515. /* Check that the KPAK is converted from montgomery form. */
  43516. ret = eccsi_imp_exp_key_test(priv);
  43517. if (ret != 0)
  43518. return ret;
  43519. /* Check that KPAK can converted to Montgomery form again. */
  43520. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43521. &verified);
  43522. if (ret != 0)
  43523. return WC_TEST_RET_ENC_EC(ret);
  43524. if (!verified)
  43525. return WC_TEST_RET_ENC_NC;
  43526. /* Check that the KPAK is converted from montgomery form. */
  43527. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43528. &valid);
  43529. if (ret != 0)
  43530. return WC_TEST_RET_ENC_EC(ret);
  43531. if (!valid)
  43532. return WC_TEST_RET_ENC_NC;
  43533. /* Check that KPAK can converted to Montgomery form again. */
  43534. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43535. &verified);
  43536. if (ret != 0)
  43537. return WC_TEST_RET_ENC_EC(ret);
  43538. if (!verified)
  43539. return WC_TEST_RET_ENC_NC;
  43540. /* Check that the KPAK is converted from montgomery form. */
  43541. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43542. if (ret != 0)
  43543. return ret;
  43544. return 0;
  43545. }
  43546. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void)
  43547. {
  43548. wc_test_ret_t ret = 0;
  43549. WC_RNG rng;
  43550. int rng_inited = 0;
  43551. EccsiKey* priv = NULL;
  43552. EccsiKey* pub = NULL;
  43553. mp_int* ssk = NULL;
  43554. ecc_point* pvt = NULL;
  43555. WOLFSSL_ENTER("eccsi_test");
  43556. priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43557. DYNAMIC_TYPE_TMP_BUFFER);
  43558. if (priv == NULL)
  43559. ret = WC_TEST_RET_ENC_NC;
  43560. else
  43561. XMEMSET(priv, 0, sizeof(*priv));
  43562. if (ret == 0) {
  43563. pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43564. DYNAMIC_TYPE_TMP_BUFFER);
  43565. if (pub == NULL)
  43566. ret = WC_TEST_RET_ENC_NC;
  43567. else
  43568. XMEMSET(pub, 0, sizeof(*pub));
  43569. }
  43570. if (ret == 0) {
  43571. ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT,
  43572. DYNAMIC_TYPE_TMP_BUFFER);
  43573. if (ssk == NULL)
  43574. ret = WC_TEST_RET_ENC_NC;
  43575. else
  43576. XMEMSET(ssk, 0, sizeof(*ssk));
  43577. }
  43578. if (ret == 0) {
  43579. #ifndef HAVE_FIPS
  43580. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  43581. #else
  43582. ret = wc_InitRng(&rng);
  43583. #endif
  43584. if (ret != 0)
  43585. ret = WC_TEST_RET_ENC_EC(ret);
  43586. else
  43587. rng_inited = 1;
  43588. }
  43589. if (ret == 0) {
  43590. pvt = wc_ecc_new_point();
  43591. if (pvt == NULL)
  43592. ret = WC_TEST_RET_ENC_NC;
  43593. }
  43594. if (ret == 0) {
  43595. ret = mp_init(ssk);
  43596. if (ret != 0)
  43597. ret = WC_TEST_RET_ENC_EC(ret);
  43598. }
  43599. if (ret == 0) {
  43600. ret = eccsi_api_test(&rng, priv, ssk, pvt);
  43601. }
  43602. if (ret == 0) {
  43603. ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID);
  43604. if (ret != 0)
  43605. ret = WC_TEST_RET_ENC_EC(ret);
  43606. }
  43607. if (ret == 0) {
  43608. ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID);
  43609. if (ret != 0)
  43610. ret = WC_TEST_RET_ENC_EC(ret);
  43611. }
  43612. if (ret == 0) {
  43613. ret = eccsi_kat_verify_test(pub, pvt);
  43614. }
  43615. if (ret == 0) {
  43616. ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt);
  43617. }
  43618. if (ret == 0) {
  43619. ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt);
  43620. }
  43621. if (pvt != NULL)
  43622. wc_ecc_del_point(pvt);
  43623. if (rng_inited)
  43624. wc_FreeRng(&rng);
  43625. if (ssk != NULL) {
  43626. mp_free(ssk);
  43627. XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43628. }
  43629. if (pub != NULL) {
  43630. wc_FreeEccsiKey(pub);
  43631. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43632. }
  43633. if (priv != NULL) {
  43634. wc_FreeEccsiKey(priv);
  43635. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43636. }
  43637. return ret;
  43638. }
  43639. #endif /* WOLFCRYPT_HAVE_ECCSI */
  43640. #ifdef WOLFCRYPT_HAVE_SAKKE
  43641. static wc_test_ret_t sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk)
  43642. {
  43643. wc_test_ret_t ret;
  43644. byte id[1] = { 0x00 };
  43645. int valid;
  43646. byte data[256];
  43647. word32 sz;
  43648. byte auth[257];
  43649. word16 authSz;
  43650. byte ssv[256];
  43651. word16 ssvSz;
  43652. word32 len;
  43653. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43654. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43655. return WC_TEST_RET_ENC_EC(ret);
  43656. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43657. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43658. return WC_TEST_RET_ENC_EC(ret);
  43659. wc_FreeSakkeKey(NULL);
  43660. XMEMSET(key, 0, sizeof(*key));
  43661. wc_FreeSakkeKey(key);
  43662. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43663. if (ret != 0)
  43664. return WC_TEST_RET_ENC_EC(ret);
  43665. ret = wc_MakeSakkeKey(NULL, NULL);
  43666. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43667. return WC_TEST_RET_ENC_EC(ret);
  43668. ret = wc_MakeSakkeKey(key, NULL);
  43669. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43670. return WC_TEST_RET_ENC_EC(ret);
  43671. ret = wc_MakeSakkeKey(NULL, rng);
  43672. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43673. return WC_TEST_RET_ENC_EC(ret);
  43674. ret = wc_MakeSakkePublicKey(NULL, NULL);
  43675. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43676. return WC_TEST_RET_ENC_EC(ret);
  43677. ret = wc_MakeSakkePublicKey(key, NULL);
  43678. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43679. return WC_TEST_RET_ENC_EC(ret);
  43680. ret = wc_MakeSakkePublicKey(NULL, rsk);
  43681. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43682. return WC_TEST_RET_ENC_EC(ret);
  43683. ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL);
  43684. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43685. return WC_TEST_RET_ENC_EC(ret);
  43686. ret = wc_MakeSakkeRsk(key, id, 1, NULL);
  43687. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43688. return WC_TEST_RET_ENC_EC(ret);
  43689. ret = wc_MakeSakkeRsk(key, NULL, 1, rsk);
  43690. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43691. return WC_TEST_RET_ENC_EC(ret);
  43692. ret = wc_MakeSakkeRsk(NULL, id, 1, rsk);
  43693. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43694. return WC_TEST_RET_ENC_EC(ret);
  43695. ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL);
  43696. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43697. return WC_TEST_RET_ENC_EC(ret);
  43698. ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL);
  43699. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43700. return WC_TEST_RET_ENC_EC(ret);
  43701. ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid);
  43702. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43703. return WC_TEST_RET_ENC_EC(ret);
  43704. ret = wc_ExportSakkeKey(NULL, NULL, NULL);
  43705. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43706. return WC_TEST_RET_ENC_EC(ret);
  43707. ret = wc_ExportSakkeKey(key, data, NULL);
  43708. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43709. return WC_TEST_RET_ENC_EC(ret);
  43710. ret = wc_ExportSakkeKey(NULL, data, &sz);
  43711. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43712. return WC_TEST_RET_ENC_EC(ret);
  43713. ret = wc_ImportSakkeKey(NULL, NULL, 1);
  43714. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43715. return WC_TEST_RET_ENC_EC(ret);
  43716. ret = wc_ImportSakkeKey(key, NULL, 1);
  43717. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43718. return WC_TEST_RET_ENC_EC(ret);
  43719. ret = wc_ImportSakkeKey(NULL, data, 1);
  43720. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43721. return WC_TEST_RET_ENC_EC(ret);
  43722. ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL);
  43723. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43724. return WC_TEST_RET_ENC_EC(ret);
  43725. ret = wc_ExportSakkePrivateKey(key, data, NULL);
  43726. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43727. return WC_TEST_RET_ENC_EC(ret);
  43728. ret = wc_ExportSakkePrivateKey(NULL, data, &sz);
  43729. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43730. return WC_TEST_RET_ENC_EC(ret);
  43731. ret = wc_ImportSakkePrivateKey(NULL, NULL, 1);
  43732. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43733. return WC_TEST_RET_ENC_EC(ret);
  43734. ret = wc_ImportSakkePrivateKey(key, NULL, 1);
  43735. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43736. return WC_TEST_RET_ENC_EC(ret);
  43737. ret = wc_ImportSakkePrivateKey(NULL, data, 1);
  43738. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43739. return WC_TEST_RET_ENC_EC(ret);
  43740. sz = sizeof(data);
  43741. ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1);
  43742. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43743. return WC_TEST_RET_ENC_EC(ret);
  43744. ret = wc_EncodeSakkeRsk(key, rsk, data, NULL, 1);
  43745. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43746. return WC_TEST_RET_ENC_EC(ret);
  43747. ret = wc_EncodeSakkeRsk(key, NULL, data, &sz, 1);
  43748. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43749. return WC_TEST_RET_ENC_EC(ret);
  43750. ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1);
  43751. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43752. return WC_TEST_RET_ENC_EC(ret);
  43753. ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL);
  43754. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43755. return WC_TEST_RET_ENC_EC(ret);
  43756. ret = wc_DecodeSakkeRsk(key, data, sz, NULL);
  43757. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43758. return WC_TEST_RET_ENC_EC(ret);
  43759. ret = wc_DecodeSakkeRsk(key, NULL, sz, rsk);
  43760. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43761. return WC_TEST_RET_ENC_EC(ret);
  43762. ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk);
  43763. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43764. return WC_TEST_RET_ENC_EC(ret);
  43765. ret = wc_ImportSakkeRsk(NULL, NULL, sz);
  43766. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43767. return WC_TEST_RET_ENC_EC(ret);
  43768. ret = wc_ImportSakkeRsk(key, NULL, sz);
  43769. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43770. return WC_TEST_RET_ENC_EC(ret);
  43771. ret = wc_ImportSakkeRsk(NULL, data, sz);
  43772. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43773. return WC_TEST_RET_ENC_EC(ret);
  43774. ret = wc_ImportSakkeRsk(key, data, 1);
  43775. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43776. return WC_TEST_RET_ENC_EC(ret);
  43777. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL);
  43778. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43779. return WC_TEST_RET_ENC_EC(ret);
  43780. ret = wc_GenerateSakkeRskTable(key, NULL, data, NULL);
  43781. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43782. return WC_TEST_RET_ENC_EC(ret);
  43783. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, NULL);
  43784. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43785. return WC_TEST_RET_ENC_EC(ret);
  43786. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, &len);
  43787. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43788. return WC_TEST_RET_ENC_EC(ret);
  43789. ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL);
  43790. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43791. return WC_TEST_RET_ENC_EC(ret);
  43792. ret = wc_GenerateSakkeRskTable(key, NULL, data, &len);
  43793. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43794. return WC_TEST_RET_ENC_EC(ret);
  43795. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len);
  43796. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43797. return WC_TEST_RET_ENC_EC(ret);
  43798. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43799. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43800. return WC_TEST_RET_ENC_EC(ret);
  43801. len--;
  43802. ret = wc_GenerateSakkeRskTable(key, rsk, data, &len);
  43803. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43804. return WC_TEST_RET_ENC_EC(ret);
  43805. ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1);
  43806. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43807. return WC_TEST_RET_ENC_EC(ret);
  43808. ret = wc_ExportSakkePublicKey(key, data, NULL, 1);
  43809. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43810. return WC_TEST_RET_ENC_EC(ret);
  43811. ret = wc_ExportSakkePublicKey(NULL, data, &sz, 1);
  43812. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43813. return WC_TEST_RET_ENC_EC(ret);
  43814. ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1);
  43815. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43816. return WC_TEST_RET_ENC_EC(ret);
  43817. ret = wc_ImportSakkePublicKey(key, NULL, sz, 1);
  43818. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43819. return WC_TEST_RET_ENC_EC(ret);
  43820. ret = wc_ImportSakkePublicKey(NULL, data, sz, 1);
  43821. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43822. return WC_TEST_RET_ENC_EC(ret);
  43823. ret = wc_GetSakkeAuthSize(NULL, NULL);
  43824. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43825. return WC_TEST_RET_ENC_EC(ret);
  43826. ret = wc_GetSakkeAuthSize(key, NULL);
  43827. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43828. return WC_TEST_RET_ENC_EC(ret);
  43829. ret = wc_GetSakkeAuthSize(NULL, &authSz);
  43830. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43831. return WC_TEST_RET_ENC_EC(ret);
  43832. ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1);
  43833. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43834. return WC_TEST_RET_ENC_EC(ret);
  43835. ret = wc_MakeSakkePointI(key, NULL, SAKKE_ID_MAX_SIZE + 1);
  43836. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43837. return WC_TEST_RET_ENC_EC(ret);
  43838. ret = wc_MakeSakkePointI(NULL, id, 1);
  43839. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43840. return WC_TEST_RET_ENC_EC(ret);
  43841. ret = wc_MakeSakkePointI(NULL, NULL, 1);
  43842. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43843. return WC_TEST_RET_ENC_EC(ret);
  43844. ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1);
  43845. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43846. return WC_TEST_RET_ENC_EC(ret);
  43847. ret = wc_MakeSakkePointI(key, NULL, 1);
  43848. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43849. return WC_TEST_RET_ENC_EC(ret);
  43850. ret = wc_MakeSakkePointI(NULL, id, 1);
  43851. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43852. return WC_TEST_RET_ENC_EC(ret);
  43853. ret = wc_GenerateSakkePointITable(NULL, data, NULL);
  43854. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43855. return WC_TEST_RET_ENC_EC(ret);
  43856. ret = wc_GenerateSakkePointITable(key, data, NULL);
  43857. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43858. return WC_TEST_RET_ENC_EC(ret);
  43859. ret = wc_GenerateSakkePointITable(NULL, data, &len);
  43860. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43861. return WC_TEST_RET_ENC_EC(ret);
  43862. ret = wc_GenerateSakkePointITable(key, NULL, &len);
  43863. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43864. return WC_TEST_RET_ENC_EC(ret);
  43865. len--;
  43866. ret = wc_GenerateSakkePointITable(key, data, &len);
  43867. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43868. return WC_TEST_RET_ENC_EC(ret);
  43869. ret = wc_SetSakkePointITable(NULL, NULL, 1);
  43870. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43871. return WC_TEST_RET_ENC_EC(ret);
  43872. ret = wc_SetSakkePointITable(key, NULL, 1);
  43873. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43874. return WC_TEST_RET_ENC_EC(ret);
  43875. ret = wc_SetSakkePointITable(NULL, data, 1);
  43876. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43877. return WC_TEST_RET_ENC_EC(ret);
  43878. ret = wc_SetSakkePointITable(key, data, 1);
  43879. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43880. return WC_TEST_RET_ENC_EC(ret);
  43881. ret = wc_ClearSakkePointITable(NULL);
  43882. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43883. return WC_TEST_RET_ENC_EC(ret);
  43884. ret = wc_GetSakkePointI(NULL, data, NULL);
  43885. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43886. return WC_TEST_RET_ENC_EC(ret);
  43887. ret = wc_GetSakkePointI(key, data, NULL);
  43888. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43889. return WC_TEST_RET_ENC_EC(ret);
  43890. ret = wc_GetSakkePointI(NULL, data, &sz);
  43891. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43892. return WC_TEST_RET_ENC_EC(ret);
  43893. sz = 1;
  43894. ret = wc_GetSakkePointI(key, data, &sz);
  43895. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43896. return WC_TEST_RET_ENC_EC(ret);
  43897. sz = 256;
  43898. ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz);
  43899. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43900. return WC_TEST_RET_ENC_EC(ret);
  43901. ret = wc_SetSakkePointI(key, NULL, 1, NULL, sz);
  43902. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43903. return WC_TEST_RET_ENC_EC(ret);
  43904. ret = wc_SetSakkePointI(NULL, id, 1, NULL, sz);
  43905. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43906. return WC_TEST_RET_ENC_EC(ret);
  43907. ret = wc_SetSakkePointI(NULL, NULL, 1, data, sz);
  43908. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43909. return WC_TEST_RET_ENC_EC(ret);
  43910. ret = wc_SetSakkePointI(key, id, 1, NULL, sz);
  43911. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43912. return WC_TEST_RET_ENC_EC(ret);
  43913. ret = wc_SetSakkePointI(key, NULL, 1, data, sz);
  43914. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43915. return WC_TEST_RET_ENC_EC(ret);
  43916. ret = wc_SetSakkePointI(NULL, id, 1, data, sz);
  43917. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43918. return WC_TEST_RET_ENC_EC(ret);
  43919. ret = wc_SetSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz);
  43920. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43921. return WC_TEST_RET_ENC_EC(ret);
  43922. ret = wc_SetSakkePointI(key, id, 1, data, sz - 1);
  43923. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43924. return WC_TEST_RET_ENC_EC(ret);
  43925. ret = wc_SetSakkeIdentity(NULL, NULL, 1);
  43926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43927. return WC_TEST_RET_ENC_EC(ret);
  43928. ret = wc_SetSakkeIdentity(key, NULL, 1);
  43929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43930. return WC_TEST_RET_ENC_EC(ret);
  43931. ret = wc_SetSakkeIdentity(NULL, id, 1);
  43932. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43933. return WC_TEST_RET_ENC_EC(ret);
  43934. ssvSz = sizeof(ssv);
  43935. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43936. auth, NULL);
  43937. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43938. return WC_TEST_RET_ENC_EC(ret);
  43939. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43940. auth, NULL);
  43941. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43942. return WC_TEST_RET_ENC_EC(ret);
  43943. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43944. auth, NULL);
  43945. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43946. return WC_TEST_RET_ENC_EC(ret);
  43947. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43948. auth, &authSz);
  43949. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43950. return WC_TEST_RET_ENC_EC(ret);
  43951. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43952. auth, NULL);
  43953. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43954. return WC_TEST_RET_ENC_EC(ret);
  43955. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43956. auth, &authSz);
  43957. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43958. return WC_TEST_RET_ENC_EC(ret);
  43959. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43960. auth, &authSz);
  43961. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43962. return WC_TEST_RET_ENC_EC(ret);
  43963. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43964. auth, &authSz);
  43965. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43966. return WC_TEST_RET_ENC_EC(ret);
  43967. ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL);
  43968. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43969. return WC_TEST_RET_ENC_EC(ret);
  43970. ret = wc_GenerateSakkeSSV(key, rng, data, NULL);
  43971. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43972. return WC_TEST_RET_ENC_EC(ret);
  43973. ret = wc_GenerateSakkeSSV(key, NULL, data, &ssvSz);
  43974. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43975. return WC_TEST_RET_ENC_EC(ret);
  43976. ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz);
  43977. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43978. return WC_TEST_RET_ENC_EC(ret);
  43979. ret = wc_SetSakkeRsk(NULL, NULL, data, 1);
  43980. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43981. return WC_TEST_RET_ENC_EC(ret);
  43982. ret = wc_SetSakkeRsk(key, NULL, data, 1);
  43983. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43984. return WC_TEST_RET_ENC_EC(ret);
  43985. ret = wc_SetSakkeRsk(NULL, rsk, data, 1);
  43986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43987. return WC_TEST_RET_ENC_EC(ret);
  43988. ssvSz = sizeof(ssv);
  43989. authSz = sizeof(auth);
  43990. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43991. authSz);
  43992. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43993. return WC_TEST_RET_ENC_EC(ret);
  43994. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43995. authSz);
  43996. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43997. return WC_TEST_RET_ENC_EC(ret);
  43998. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  43999. authSz);
  44000. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44001. return WC_TEST_RET_ENC_EC(ret);
  44002. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44003. authSz);
  44004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44005. return WC_TEST_RET_ENC_EC(ret);
  44006. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  44007. authSz);
  44008. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44009. return WC_TEST_RET_ENC_EC(ret);
  44010. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44011. authSz);
  44012. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44013. return WC_TEST_RET_ENC_EC(ret);
  44014. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44015. authSz);
  44016. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44017. return WC_TEST_RET_ENC_EC(ret);
  44018. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44019. authSz);
  44020. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44021. return WC_TEST_RET_ENC_EC(ret);
  44022. ret = wc_SetSakkeIdentity(key, id, 1);
  44023. if (ret != 0)
  44024. return WC_TEST_RET_ENC_EC(ret);
  44025. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44026. authSz);
  44027. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44028. return WC_TEST_RET_ENC_EC(ret);
  44029. ret = wc_SetSakkeIdentity(key, id, 0);
  44030. if (ret != 0)
  44031. return WC_TEST_RET_ENC_EC(ret);
  44032. ret = wc_SetSakkeRsk(key, rsk, data, 1);
  44033. if (ret != 0)
  44034. return WC_TEST_RET_ENC_EC(ret);
  44035. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44036. authSz);
  44037. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44038. return WC_TEST_RET_ENC_EC(ret);
  44039. wc_FreeSakkeKey(key);
  44040. return 0;
  44041. }
  44042. static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
  44043. {
  44044. WOLFSSL_SMALL_STACK_STATIC const byte pubData[] = {
  44045. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44046. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44047. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44048. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44049. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44050. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44051. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44052. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44053. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44054. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44055. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44056. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44057. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44058. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44059. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44060. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44061. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44062. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44063. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44064. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44065. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44066. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44067. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44068. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44069. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44070. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44071. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44072. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44073. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44074. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44075. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44076. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44077. };
  44078. WOLFSSL_SMALL_STACK_STATIC const byte rskData[] = {
  44079. 0x93, 0xAF, 0x67, 0xE5, 0x00, 0x7B, 0xA6, 0xE6,
  44080. 0xA8, 0x0D, 0xA7, 0x93, 0xDA, 0x30, 0x0F, 0xA4,
  44081. 0xB5, 0x2D, 0x0A, 0x74, 0xE2, 0x5E, 0x6E, 0x7B,
  44082. 0x2B, 0x3D, 0x6E, 0xE9, 0xD1, 0x8A, 0x9B, 0x5C,
  44083. 0x50, 0x23, 0x59, 0x7B, 0xD8, 0x2D, 0x80, 0x62,
  44084. 0xD3, 0x40, 0x19, 0x56, 0x3B, 0xA1, 0xD2, 0x5C,
  44085. 0x0D, 0xC5, 0x6B, 0x7B, 0x97, 0x9D, 0x74, 0xAA,
  44086. 0x50, 0xF2, 0x9F, 0xBF, 0x11, 0xCC, 0x2C, 0x93,
  44087. 0xF5, 0xDF, 0xCA, 0x61, 0x5E, 0x60, 0x92, 0x79,
  44088. 0xF6, 0x17, 0x5C, 0xEA, 0xDB, 0x00, 0xB5, 0x8C,
  44089. 0x6B, 0xEE, 0x1E, 0x7A, 0x2A, 0x47, 0xC4, 0xF0,
  44090. 0xC4, 0x56, 0xF0, 0x52, 0x59, 0xA6, 0xFA, 0x94,
  44091. 0xA6, 0x34, 0xA4, 0x0D, 0xAE, 0x1D, 0xF5, 0x93,
  44092. 0xD4, 0xFE, 0xCF, 0x68, 0x8D, 0x5F, 0xC6, 0x78,
  44093. 0xBE, 0x7E, 0xFC, 0x6D, 0xF3, 0xD6, 0x83, 0x53,
  44094. 0x25, 0xB8, 0x3B, 0x2C, 0x6E, 0x69, 0x03, 0x6B,
  44095. 0x15, 0x5F, 0x0A, 0x27, 0x24, 0x10, 0x94, 0xB0,
  44096. 0x4B, 0xFB, 0x0B, 0xDF, 0xAC, 0x6C, 0x67, 0x0A,
  44097. 0x65, 0xC3, 0x25, 0xD3, 0x9A, 0x06, 0x9F, 0x03,
  44098. 0x65, 0x9D, 0x44, 0xCA, 0x27, 0xD3, 0xBE, 0x8D,
  44099. 0xF3, 0x11, 0x17, 0x2B, 0x55, 0x41, 0x60, 0x18,
  44100. 0x1C, 0xBE, 0x94, 0xA2, 0xA7, 0x83, 0x32, 0x0C,
  44101. 0xED, 0x59, 0x0B, 0xC4, 0x26, 0x44, 0x70, 0x2C,
  44102. 0xF3, 0x71, 0x27, 0x1E, 0x49, 0x6B, 0xF2, 0x0F,
  44103. 0x58, 0x8B, 0x78, 0xA1, 0xBC, 0x01, 0xEC, 0xBB,
  44104. 0x65, 0x59, 0x93, 0x4B, 0xDD, 0x2F, 0xB6, 0x5D,
  44105. 0x28, 0x84, 0x31, 0x8A, 0x33, 0xD1, 0xA4, 0x2A,
  44106. 0xDF, 0x5E, 0x33, 0xCC, 0x58, 0x00, 0x28, 0x0B,
  44107. 0x28, 0x35, 0x64, 0x97, 0xF8, 0x71, 0x35, 0xBA,
  44108. 0xB9, 0x61, 0x2A, 0x17, 0x26, 0x04, 0x24, 0x40,
  44109. 0x9A, 0xC1, 0x5F, 0xEE, 0x99, 0x6B, 0x74, 0x4C,
  44110. 0x33, 0x21, 0x51, 0x23, 0x5D, 0xEC, 0xB0, 0xF5
  44111. };
  44112. WOLFSSL_SMALL_STACK_STATIC const byte id[] = {
  44113. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44114. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44115. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44116. 0x33, 0x00
  44117. };
  44118. WOLFSSL_SMALL_STACK_STATIC const byte ssv[] = {
  44119. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44120. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44121. };
  44122. WOLFSSL_SMALL_STACK_STATIC const byte auth[] = {
  44123. 0x04,
  44124. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44125. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44126. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44127. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44128. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44129. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44130. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44131. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44132. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44133. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44134. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44135. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44136. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44137. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44138. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44139. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44140. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44141. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44142. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44143. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44144. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44145. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44146. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44147. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44148. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44149. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44150. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44151. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44152. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44153. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44154. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44155. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44156. };
  44157. WOLFSSL_SMALL_STACK_STATIC const byte encSsv[] = {
  44158. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44159. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44160. };
  44161. wc_test_ret_t ret;
  44162. int valid;
  44163. byte pubKey[sizeof(pubData) + 1];
  44164. word32 sz = sizeof(pubKey);
  44165. byte tmpSsv[sizeof(encSsv)];
  44166. byte* iTable = NULL;
  44167. word32 iTableLen;
  44168. byte* table = NULL;
  44169. word32 len;
  44170. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44171. if (ret != 0)
  44172. return WC_TEST_RET_ENC_EC(ret);
  44173. ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk);
  44174. if (ret != 0)
  44175. return WC_TEST_RET_ENC_EC(ret);
  44176. ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid);
  44177. if (ret != 0)
  44178. return WC_TEST_RET_ENC_EC(ret);
  44179. if (valid != 1)
  44180. return WC_TEST_RET_ENC_NC;
  44181. ret = wc_SetSakkeRsk(key, rsk, NULL, 0);
  44182. if (ret != 0)
  44183. return WC_TEST_RET_ENC_EC(ret);
  44184. ret = wc_SetSakkeIdentity(key, id, sizeof(id));
  44185. if (ret != 0)
  44186. return WC_TEST_RET_ENC_EC(ret);
  44187. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44188. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44189. auth, sizeof(auth));
  44190. if (ret != 0)
  44191. return WC_TEST_RET_ENC_EC(ret);
  44192. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44193. return WC_TEST_RET_ENC_NC;
  44194. ret = wc_MakeSakkePointI(key, id, sizeof(id));
  44195. if (ret != 0)
  44196. return WC_TEST_RET_ENC_EC(ret);
  44197. iTableLen = 0;
  44198. ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen);
  44199. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44200. return WC_TEST_RET_ENC_EC(ret);
  44201. if (iTableLen != 0) {
  44202. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44203. if (iTable == NULL)
  44204. return WC_TEST_RET_ENC_ERRNO;
  44205. ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
  44206. if (ret != 0)
  44207. return WC_TEST_RET_ENC_EC(ret);
  44208. }
  44209. len = 0;
  44210. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  44211. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44212. return WC_TEST_RET_ENC_EC(ret);
  44213. if (len > 0) {
  44214. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44215. if (table == NULL)
  44216. return WC_TEST_RET_ENC_ERRNO;
  44217. ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
  44218. if (ret != 0)
  44219. return WC_TEST_RET_ENC_EC(ret);
  44220. }
  44221. ret = wc_SetSakkeRsk(key, rsk, table, len);
  44222. if (ret != 0)
  44223. return WC_TEST_RET_ENC_EC(ret);
  44224. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44225. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44226. auth, sizeof(auth));
  44227. if (ret != 0)
  44228. return WC_TEST_RET_ENC_EC(ret);
  44229. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44230. return WC_TEST_RET_ENC_NC;
  44231. /* Don't reference table that is about to be freed. */
  44232. ret = wc_ClearSakkePointITable(key);
  44233. if (ret != 0)
  44234. return WC_TEST_RET_ENC_EC(ret);
  44235. /* Dispose of tables */
  44236. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44237. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44238. /* Make sure the key public key is exportable - convert to Montgomery form
  44239. * in Validation.
  44240. */
  44241. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1);
  44242. if (ret != 0)
  44243. return WC_TEST_RET_ENC_EC(ret);
  44244. if (sz != sizeof(pubData))
  44245. return WC_TEST_RET_ENC_NC;
  44246. if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0)
  44247. return WC_TEST_RET_ENC_NC;
  44248. sz = sizeof(pubData) + 1;
  44249. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0);
  44250. if (ret != 0)
  44251. return WC_TEST_RET_ENC_EC(ret);
  44252. if (sz != sizeof(pubData) + 1)
  44253. return WC_TEST_RET_ENC_NC;
  44254. if (pubKey[0] != 0x04)
  44255. return WC_TEST_RET_ENC_NC;
  44256. if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0)
  44257. return WC_TEST_RET_ENC_NC;
  44258. return 0;
  44259. }
  44260. static wc_test_ret_t sakke_kat_encapsulate_test(SakkeKey* key)
  44261. {
  44262. static const byte pubData[] = {
  44263. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44264. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44265. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44266. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44267. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44268. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44269. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44270. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44271. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44272. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44273. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44274. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44275. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44276. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44277. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44278. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44279. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44280. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44281. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44282. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44283. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44284. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44285. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44286. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44287. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44288. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44289. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44290. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44291. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44292. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44293. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44294. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44295. };
  44296. static const byte id[] = {
  44297. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44298. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44299. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44300. 0x33, 0x00
  44301. };
  44302. static const word32 idSz = sizeof(id);
  44303. byte ssv[] = {
  44304. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44305. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44306. };
  44307. static const word16 ssvSz = sizeof(ssv);
  44308. static const byte expAuth[] = {
  44309. 0x04,
  44310. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44311. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44312. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44313. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44314. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44315. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44316. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44317. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44318. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44319. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44320. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44321. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44322. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44323. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44324. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44325. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44326. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44327. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44328. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44329. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44330. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44331. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44332. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44333. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44334. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44335. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44336. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44337. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44338. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44339. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44340. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44341. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44342. };
  44343. static const byte encSsv[] = {
  44344. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44345. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44346. };
  44347. wc_test_ret_t ret;
  44348. byte auth[257];
  44349. word16 authSz = sizeof(auth);
  44350. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44351. if (ret != 0)
  44352. return WC_TEST_RET_ENC_EC(ret);
  44353. ret = wc_SetSakkeIdentity(key, id, idSz);
  44354. if (ret != 0)
  44355. return WC_TEST_RET_ENC_EC(ret);
  44356. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44357. auth, &authSz);
  44358. if (ret != 0)
  44359. return WC_TEST_RET_ENC_EC(ret);
  44360. if (authSz != 257)
  44361. return WC_TEST_RET_ENC_NC;
  44362. if (XMEMCMP(ssv, encSsv, ssvSz) != 0)
  44363. return WC_TEST_RET_ENC_NC;
  44364. if (XMEMCMP(auth, expAuth, authSz) != 0)
  44365. return WC_TEST_RET_ENC_NC;
  44366. return 0;
  44367. }
  44368. static wc_test_ret_t sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key,
  44369. WC_RNG* rng, ecc_point* rsk)
  44370. {
  44371. wc_test_ret_t ret;
  44372. byte data[440];
  44373. byte pubData[257];
  44374. word32 sz;
  44375. char mail[] = "test@wolfssl.com";
  44376. byte* id = (byte*)mail;
  44377. word32 idSz = (word32)XSTRLEN(mail);
  44378. int valid;
  44379. ecc_point* pubKey = rsk;
  44380. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44381. if (ret != 0)
  44382. return WC_TEST_RET_ENC_EC(ret);
  44383. ret = wc_MakeSakkeKey(priv, rng);
  44384. if (ret != 0)
  44385. return WC_TEST_RET_ENC_EC(ret);
  44386. ret = wc_ExportSakkeKey(priv, NULL, &sz);
  44387. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44388. return WC_TEST_RET_ENC_EC(ret);
  44389. if (sz != 384)
  44390. return WC_TEST_RET_ENC_NC;
  44391. sz--;
  44392. ret = wc_ExportSakkeKey(priv, data, &sz);
  44393. if (ret == 0)
  44394. return WC_TEST_RET_ENC_NC;
  44395. sz++;
  44396. ret = wc_ExportSakkeKey(priv, data, &sz);
  44397. if (ret != 0)
  44398. return WC_TEST_RET_ENC_EC(ret);
  44399. if (sz != 384)
  44400. return WC_TEST_RET_ENC_NC;
  44401. ret = wc_ImportSakkeKey(key, data, sz - 1);
  44402. if (ret == 0)
  44403. return WC_TEST_RET_ENC_NC;
  44404. ret = wc_ImportSakkeKey(key, data, sz);
  44405. if (ret != 0)
  44406. return WC_TEST_RET_ENC_EC(ret);
  44407. wc_FreeSakkeKey(key);
  44408. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44409. if (ret != 0)
  44410. return WC_TEST_RET_ENC_EC(ret);
  44411. ret = wc_ExportSakkePrivateKey(priv, NULL, &sz);
  44412. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44413. return WC_TEST_RET_ENC_EC(ret);
  44414. if (sz != 128)
  44415. return WC_TEST_RET_ENC_NC;
  44416. sz--;
  44417. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44418. if (ret == 0)
  44419. return WC_TEST_RET_ENC_NC;
  44420. sz++;
  44421. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44422. if (ret != 0)
  44423. return WC_TEST_RET_ENC_EC(ret);
  44424. if (sz != 128)
  44425. return WC_TEST_RET_ENC_NC;
  44426. ret = wc_ImportSakkePrivateKey(key, data, sz - 1);
  44427. if (ret == 0)
  44428. return WC_TEST_RET_ENC_NC;
  44429. ret = wc_ImportSakkePrivateKey(key, data, sz);
  44430. if (ret != 0)
  44431. return WC_TEST_RET_ENC_EC(ret);
  44432. ret = wc_MakeSakkePublicKey(key, pubKey);
  44433. if (ret != 0)
  44434. return WC_TEST_RET_ENC_EC(ret);
  44435. ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1);
  44436. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44437. return WC_TEST_RET_ENC_EC(ret);
  44438. if (sz != 256)
  44439. return WC_TEST_RET_ENC_NC;
  44440. sz--;
  44441. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44442. if (ret == 0)
  44443. return WC_TEST_RET_ENC_NC;
  44444. sz++;
  44445. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44446. if (ret != 0)
  44447. return WC_TEST_RET_ENC_EC(ret);
  44448. if (sz != 256)
  44449. return WC_TEST_RET_ENC_NC;
  44450. ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1);
  44451. if (ret == 0)
  44452. return WC_TEST_RET_ENC_NC;
  44453. ret = wc_ImportSakkePublicKey(pub, data, sz, 1);
  44454. if (ret != 0)
  44455. return WC_TEST_RET_ENC_EC(ret);
  44456. ret = wc_ExportSakkePublicKey(pub, pubData, &sz, 1);
  44457. if (ret != 0)
  44458. return WC_TEST_RET_ENC_EC(ret);
  44459. if (sz != 256)
  44460. return WC_TEST_RET_ENC_NC;
  44461. if (XMEMCMP(data, pubData, sz) != 0)
  44462. return WC_TEST_RET_ENC_NC;
  44463. ret = wc_MakeSakkeRsk(priv, id, idSz, rsk);
  44464. if (ret != 0)
  44465. return WC_TEST_RET_ENC_EC(ret);
  44466. ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid);
  44467. if (ret != 0)
  44468. return WC_TEST_RET_ENC_EC(ret);
  44469. if (valid != 1)
  44470. return WC_TEST_RET_ENC_NC;
  44471. ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid);
  44472. if (ret != 0)
  44473. return WC_TEST_RET_ENC_EC(ret);
  44474. if (valid != 1)
  44475. return WC_TEST_RET_ENC_NC;
  44476. sz = sizeof(data);
  44477. ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1);
  44478. if (ret != 0)
  44479. return WC_TEST_RET_ENC_EC(ret);
  44480. if (sz != 256)
  44481. return WC_TEST_RET_ENC_NC;
  44482. ret = wc_DecodeSakkeRsk(priv, data, sz, rsk);
  44483. if (ret != 0)
  44484. return WC_TEST_RET_ENC_EC(ret);
  44485. sz = sizeof(pubData);
  44486. ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0);
  44487. if (ret != 0)
  44488. return WC_TEST_RET_ENC_EC(ret);
  44489. if (sz != sizeof(pubData))
  44490. return WC_TEST_RET_ENC_NC;
  44491. ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk);
  44492. if (ret != 0)
  44493. return WC_TEST_RET_ENC_EC(ret);
  44494. wc_FreeSakkeKey(key);
  44495. return 0;
  44496. }
  44497. static wc_test_ret_t sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng,
  44498. ecc_point* rsk)
  44499. {
  44500. wc_test_ret_t ret;
  44501. byte ssv[16];
  44502. word16 ssvSz;
  44503. byte auth[257];
  44504. word16 authSz;
  44505. char mail[] = "test@wolfssl.com";
  44506. byte* id = (byte*)mail;
  44507. word32 idSz = (word32)XSTRLEN(mail);
  44508. byte pointI[256];
  44509. word32 sz;
  44510. ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz);
  44511. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44512. return WC_TEST_RET_ENC_EC(ret);
  44513. if (ssvSz != 16)
  44514. return WC_TEST_RET_ENC_NC;
  44515. ssvSz += 128;
  44516. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44517. if (ret == 0)
  44518. return WC_TEST_RET_ENC_NC;
  44519. ssvSz -= 128;
  44520. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44521. if (ret != 0)
  44522. return WC_TEST_RET_ENC_EC(ret);
  44523. if (ssvSz != 16)
  44524. return WC_TEST_RET_ENC_NC;
  44525. ret = wc_GetSakkeAuthSize(pub, &authSz);
  44526. if (ret != 0)
  44527. return WC_TEST_RET_ENC_EC(ret);
  44528. ret = wc_SetSakkeIdentity(pub, id, idSz);
  44529. if (ret != 0)
  44530. return WC_TEST_RET_ENC_EC(ret);
  44531. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44532. NULL, &authSz);
  44533. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44534. return WC_TEST_RET_ENC_EC(ret);
  44535. if (authSz != 257)
  44536. return WC_TEST_RET_ENC_NC;
  44537. authSz--;
  44538. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44539. auth, &authSz);
  44540. if (ret == 0)
  44541. return WC_TEST_RET_ENC_NC;
  44542. authSz++;
  44543. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44544. auth, &authSz);
  44545. if (ret != 0)
  44546. return WC_TEST_RET_ENC_EC(ret);
  44547. if (authSz != 257)
  44548. return WC_TEST_RET_ENC_NC;
  44549. ret = wc_GetSakkePointI(pub, NULL, &sz);
  44550. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44551. return WC_TEST_RET_ENC_EC(ret);
  44552. if (sz != 256)
  44553. return WC_TEST_RET_ENC_NC;
  44554. ret = wc_GetSakkePointI(pub, pointI, &sz);
  44555. if (ret != 0)
  44556. return WC_TEST_RET_ENC_EC(ret);
  44557. if (sz != 256)
  44558. return WC_TEST_RET_ENC_NC;
  44559. /* Bogus identity - make it check and regenerate I. */
  44560. ret = wc_MakeSakkePointI(pub, ssv, ssvSz);
  44561. if (ret != 0)
  44562. return WC_TEST_RET_ENC_EC(ret);
  44563. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44564. auth, &authSz);
  44565. if (ret != 0)
  44566. return WC_TEST_RET_ENC_EC(ret);
  44567. if (authSz != 257)
  44568. return WC_TEST_RET_ENC_NC;
  44569. ret = wc_SetSakkeRsk(priv, rsk, NULL, 0);
  44570. if (ret != 0)
  44571. return WC_TEST_RET_ENC_EC(ret);
  44572. ret = wc_SetSakkeIdentity(priv, id, idSz);
  44573. if (ret != 0)
  44574. return WC_TEST_RET_ENC_EC(ret);
  44575. authSz--;
  44576. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44577. authSz);
  44578. if (ret == 0)
  44579. return WC_TEST_RET_ENC_NC;
  44580. authSz++;
  44581. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44582. authSz);
  44583. if (ret != 0)
  44584. return WC_TEST_RET_ENC_EC(ret);
  44585. ssv[0] ^= 0x80;
  44586. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44587. authSz);
  44588. if (ret != WC_NO_ERR_TRACE(SAKKE_VERIFY_FAIL_E))
  44589. return WC_TEST_RET_ENC_EC(ret);
  44590. ssv[0] ^= 0x80;
  44591. /* Bogus identity - make it check and regenerate I. */
  44592. ret = wc_MakeSakkePointI(pub, ssv, idSz);
  44593. if (ret != 0)
  44594. return WC_TEST_RET_ENC_EC(ret);
  44595. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44596. authSz);
  44597. if (ret != 0)
  44598. return WC_TEST_RET_ENC_EC(ret);
  44599. return 0;
  44600. }
  44601. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void)
  44602. {
  44603. wc_test_ret_t ret = 0;
  44604. WC_RNG rng;
  44605. int rng_inited = 0;
  44606. SakkeKey* priv = NULL;
  44607. SakkeKey* pub = NULL;
  44608. SakkeKey* key = NULL;
  44609. ecc_point* rsk = NULL;
  44610. WOLFSSL_ENTER("sakke_test");
  44611. priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44612. DYNAMIC_TYPE_TMP_BUFFER);
  44613. if (priv == NULL)
  44614. ret = WC_TEST_RET_ENC_NC;
  44615. else
  44616. XMEMSET(priv, 0, sizeof(*priv));
  44617. if (ret == 0) {
  44618. pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44619. DYNAMIC_TYPE_TMP_BUFFER);
  44620. if (pub == NULL)
  44621. ret = WC_TEST_RET_ENC_NC;
  44622. else
  44623. XMEMSET(pub, 0, sizeof(*pub));
  44624. }
  44625. if (ret == 0) {
  44626. key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44627. DYNAMIC_TYPE_TMP_BUFFER);
  44628. if (key == NULL)
  44629. ret = WC_TEST_RET_ENC_NC;
  44630. else
  44631. XMEMSET(key, 0, sizeof(*key));
  44632. }
  44633. if (ret == 0) {
  44634. #ifndef HAVE_FIPS
  44635. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  44636. #else
  44637. ret = wc_InitRng(&rng);
  44638. #endif
  44639. if (ret == 0)
  44640. rng_inited = 1;
  44641. else
  44642. ret = WC_TEST_RET_ENC_EC(ret);
  44643. }
  44644. if (ret == 0) {
  44645. rsk = wc_ecc_new_point();
  44646. if (rsk == NULL)
  44647. ret = WC_TEST_RET_ENC_NC;
  44648. }
  44649. if (ret == 0) {
  44650. ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID);
  44651. if (ret != 0)
  44652. ret = WC_TEST_RET_ENC_EC(ret);
  44653. }
  44654. if (ret == 0) {
  44655. ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID);
  44656. if (ret != 0)
  44657. ret = WC_TEST_RET_ENC_EC(ret);
  44658. }
  44659. if (ret == 0) {
  44660. ret = sakke_api_test(&rng, key, rsk);
  44661. }
  44662. if (ret == 0) {
  44663. ret = sakke_kat_derive_test(pub, rsk);
  44664. }
  44665. if (ret == 0) {
  44666. ret = sakke_kat_encapsulate_test(pub);
  44667. }
  44668. if (ret == 0) {
  44669. ret = sakke_make_key_test(priv, pub, key, &rng, rsk);
  44670. }
  44671. if (ret == 0) {
  44672. ret = sakke_op_test(priv, pub, &rng, rsk);
  44673. }
  44674. if (rsk != NULL) {
  44675. wc_ecc_forcezero_point(rsk);
  44676. wc_ecc_del_point(rsk);
  44677. }
  44678. if (rng_inited)
  44679. wc_FreeRng(&rng);
  44680. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44681. if (pub != NULL) {
  44682. wc_FreeSakkeKey(pub);
  44683. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44684. }
  44685. if (priv != NULL) {
  44686. wc_FreeSakkeKey(priv);
  44687. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44688. }
  44689. return ret;
  44690. }
  44691. #endif /* WOLFCRYPT_HAVE_SAKKE */
  44692. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  44693. typedef struct CMAC_Test_Case {
  44694. int type;
  44695. int partial;
  44696. const byte* m;
  44697. word32 mSz;
  44698. const byte* k;
  44699. word32 kSz;
  44700. const byte* t;
  44701. word32 tSz;
  44702. } CMAC_Test_Case;
  44703. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void)
  44704. {
  44705. #ifdef WOLFSSL_AES_128
  44706. WOLFSSL_SMALL_STACK_STATIC const byte k128[] =
  44707. {
  44708. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  44709. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  44710. };
  44711. #define KLEN_128 (sizeof(k128))
  44712. #endif
  44713. #ifdef WOLFSSL_AES_192
  44714. WOLFSSL_SMALL_STACK_STATIC const byte k192[] =
  44715. {
  44716. 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
  44717. 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
  44718. 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
  44719. };
  44720. #define KLEN_192 (sizeof(k192))
  44721. #endif
  44722. #ifdef WOLFSSL_AES_256
  44723. WOLFSSL_SMALL_STACK_STATIC const byte k256[] =
  44724. {
  44725. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  44726. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  44727. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  44728. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  44729. };
  44730. #define KLEN_256 (sizeof(k256))
  44731. #endif
  44732. WOLFSSL_SMALL_STACK_STATIC const byte m[] =
  44733. {
  44734. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  44735. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  44736. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  44737. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  44738. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  44739. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  44740. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  44741. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  44742. };
  44743. #define MLEN_0 (0)
  44744. #define MLEN_128 (128/8)
  44745. #define MLEN_320 (320/8)
  44746. #define MLEN_319 (MLEN_320 - 1)
  44747. #define MLEN_512 (512/8)
  44748. #ifdef WOLFSSL_AES_128
  44749. WOLFSSL_SMALL_STACK_STATIC const byte t128_0[] =
  44750. {
  44751. 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
  44752. 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
  44753. };
  44754. WOLFSSL_SMALL_STACK_STATIC const byte t128_128[] =
  44755. {
  44756. 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
  44757. 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
  44758. };
  44759. WOLFSSL_SMALL_STACK_STATIC const byte t128_319[] =
  44760. {
  44761. 0x2c, 0x17, 0x84, 0x4c, 0x93, 0x1c, 0x07, 0x95,
  44762. 0x15, 0x92, 0x73, 0x0a, 0x34, 0xd0, 0xd9, 0xd2
  44763. };
  44764. WOLFSSL_SMALL_STACK_STATIC const byte t128_320[] =
  44765. {
  44766. 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
  44767. 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
  44768. };
  44769. WOLFSSL_SMALL_STACK_STATIC const byte t128_512[] =
  44770. {
  44771. 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
  44772. 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
  44773. };
  44774. #endif
  44775. #ifdef WOLFSSL_AES_192
  44776. WOLFSSL_SMALL_STACK_STATIC const byte t192_0[] =
  44777. {
  44778. 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
  44779. 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
  44780. };
  44781. WOLFSSL_SMALL_STACK_STATIC const byte t192_128[] =
  44782. {
  44783. 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
  44784. 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
  44785. };
  44786. WOLFSSL_SMALL_STACK_STATIC const byte t192_320[] =
  44787. {
  44788. 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
  44789. 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
  44790. };
  44791. WOLFSSL_SMALL_STACK_STATIC const byte t192_512[] =
  44792. {
  44793. 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
  44794. 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
  44795. };
  44796. #endif
  44797. #ifdef WOLFSSL_AES_256
  44798. WOLFSSL_SMALL_STACK_STATIC const byte t256_0[] =
  44799. {
  44800. 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
  44801. 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
  44802. };
  44803. WOLFSSL_SMALL_STACK_STATIC const byte t256_128[] =
  44804. {
  44805. 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
  44806. 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
  44807. };
  44808. WOLFSSL_SMALL_STACK_STATIC const byte t256_320[] =
  44809. {
  44810. 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
  44811. 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
  44812. };
  44813. WOLFSSL_SMALL_STACK_STATIC const byte t256_512[] =
  44814. {
  44815. 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
  44816. 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
  44817. };
  44818. #endif
  44819. const CMAC_Test_Case testCases[] =
  44820. {
  44821. #ifdef WOLFSSL_AES_128
  44822. {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, AES_BLOCK_SIZE},
  44823. {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, AES_BLOCK_SIZE},
  44824. {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, AES_BLOCK_SIZE},
  44825. {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44826. {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44827. #endif
  44828. #ifdef WOLFSSL_AES_192
  44829. {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, AES_BLOCK_SIZE},
  44830. {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, AES_BLOCK_SIZE},
  44831. {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, AES_BLOCK_SIZE},
  44832. {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, AES_BLOCK_SIZE},
  44833. #endif
  44834. #ifdef WOLFSSL_AES_256
  44835. {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, AES_BLOCK_SIZE},
  44836. {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, AES_BLOCK_SIZE},
  44837. {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, AES_BLOCK_SIZE},
  44838. {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, AES_BLOCK_SIZE},
  44839. #endif
  44840. #ifdef WOLFSSL_AES_128
  44841. {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, AES_BLOCK_SIZE}
  44842. #endif
  44843. };
  44844. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44845. Cmac *cmac;
  44846. #else
  44847. Cmac cmac[1];
  44848. #endif
  44849. byte tag[AES_BLOCK_SIZE];
  44850. const CMAC_Test_Case* tc;
  44851. word32 i, tagSz;
  44852. wc_test_ret_t ret;
  44853. WOLFSSL_ENTER("cmac_test");
  44854. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44855. if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL)
  44856. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  44857. #endif
  44858. for (i = 0, tc = testCases;
  44859. i < sizeof(testCases)/sizeof(CMAC_Test_Case);
  44860. i++, tc++) {
  44861. XMEMSET(tag, 0, sizeof(tag));
  44862. tagSz = AES_BLOCK_SIZE;
  44863. #if !defined(HAVE_FIPS) || \
  44864. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)
  44865. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44866. #else
  44867. ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL);
  44868. #endif
  44869. if (ret != 0)
  44870. {
  44871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44872. }
  44873. if (tc->partial) {
  44874. ret = wc_CmacUpdate(cmac, tc->m,
  44875. tc->mSz/2 - tc->partial);
  44876. if (ret != 0)
  44877. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44878. ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial,
  44879. tc->mSz/2 + tc->partial);
  44880. if (ret != 0)
  44881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44882. }
  44883. else {
  44884. ret = wc_CmacUpdate(cmac, tc->m, tc->mSz);
  44885. if (ret != 0)
  44886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44887. }
  44888. ret = wc_CmacFinal(cmac, tag, &tagSz);
  44889. if (ret != 0)
  44890. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44891. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44892. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44893. XMEMSET(tag, 0, sizeof(tag));
  44894. tagSz = sizeof(tag);
  44895. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44896. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44897. tc->k, tc->kSz, NULL, devId);
  44898. #else
  44899. ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz,
  44900. tc->k, tc->kSz);
  44901. #endif
  44902. if (ret != 0)
  44903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44904. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44905. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44906. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44907. ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz,
  44908. tc->k, tc->kSz, HEAP_HINT, devId);
  44909. #else
  44910. ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz,
  44911. tc->k, tc->kSz);
  44912. #endif
  44913. if (ret != 0)
  44914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44915. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44916. /* Test that keyless generate with init is the same */
  44917. XMEMSET(tag, 0, sizeof(tag));
  44918. tagSz = sizeof(tag);
  44919. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44920. if (ret != 0) {
  44921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44922. }
  44923. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44924. NULL, 0, HEAP_HINT, devId);
  44925. if (ret != 0) {
  44926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44927. }
  44928. #endif
  44929. }
  44930. ret = 0;
  44931. out:
  44932. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44933. XFREE(cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC);
  44934. #endif
  44935. return ret;
  44936. }
  44937. #endif /* !NO_AES && WOLFSSL_CMAC */
  44938. #if defined(WOLFSSL_SIPHASH)
  44939. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44940. /* Test vectors from:
  44941. * https://github.com/veorq/SipHash/blob/master/vectors.h
  44942. */
  44943. static const unsigned char siphash_key[SIPHASH_KEY_SIZE] = {
  44944. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44945. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  44946. };
  44947. static const unsigned char siphash_msg[64] = {
  44948. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44949. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44950. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  44951. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  44952. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  44953. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  44954. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  44955. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  44956. };
  44957. static const unsigned char siphash_r8[64][SIPHASH_MAC_SIZE_8] = {
  44958. { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
  44959. { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
  44960. { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, },
  44961. { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, },
  44962. { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, },
  44963. { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, },
  44964. { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, },
  44965. { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, },
  44966. { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, },
  44967. { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, },
  44968. { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, },
  44969. { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, },
  44970. { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, },
  44971. { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, },
  44972. { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, },
  44973. { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, },
  44974. { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, },
  44975. { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, },
  44976. { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, },
  44977. { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, },
  44978. { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, },
  44979. { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, },
  44980. { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, },
  44981. { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, },
  44982. { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, },
  44983. { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, },
  44984. { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, },
  44985. { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, },
  44986. { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, },
  44987. { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, },
  44988. { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, },
  44989. { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, },
  44990. { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, },
  44991. { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, },
  44992. { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, },
  44993. { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, },
  44994. { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, },
  44995. { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, },
  44996. { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, },
  44997. { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, },
  44998. { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, },
  44999. { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, },
  45000. { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, },
  45001. { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, },
  45002. { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, },
  45003. { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
  45004. { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
  45005. { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
  45006. { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
  45007. { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
  45008. { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
  45009. { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
  45010. { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
  45011. { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
  45012. { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
  45013. { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
  45014. { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
  45015. { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
  45016. { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
  45017. { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
  45018. { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
  45019. { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
  45020. { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
  45021. { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, },
  45022. };
  45023. static const unsigned char siphash_r16[64][SIPHASH_MAC_SIZE_16] = {
  45024. { 0xa3, 0x81, 0x7f, 0x04, 0xba, 0x25, 0xa8, 0xe6,
  45025. 0x6d, 0xf6, 0x72, 0x14, 0xc7, 0x55, 0x02, 0x93, },
  45026. { 0xda, 0x87, 0xc1, 0xd8, 0x6b, 0x99, 0xaf, 0x44,
  45027. 0x34, 0x76, 0x59, 0x11, 0x9b, 0x22, 0xfc, 0x45, },
  45028. { 0x81, 0x77, 0x22, 0x8d, 0xa4, 0xa4, 0x5d, 0xc7,
  45029. 0xfc, 0xa3, 0x8b, 0xde, 0xf6, 0x0a, 0xff, 0xe4, },
  45030. { 0x9c, 0x70, 0xb6, 0x0c, 0x52, 0x67, 0xa9, 0x4e,
  45031. 0x5f, 0x33, 0xb6, 0xb0, 0x29, 0x85, 0xed, 0x51, },
  45032. { 0xf8, 0x81, 0x64, 0xc1, 0x2d, 0x9c, 0x8f, 0xaf,
  45033. 0x7d, 0x0f, 0x6e, 0x7c, 0x7b, 0xcd, 0x55, 0x79, },
  45034. { 0x13, 0x68, 0x87, 0x59, 0x80, 0x77, 0x6f, 0x88,
  45035. 0x54, 0x52, 0x7a, 0x07, 0x69, 0x0e, 0x96, 0x27, },
  45036. { 0x14, 0xee, 0xca, 0x33, 0x8b, 0x20, 0x86, 0x13,
  45037. 0x48, 0x5e, 0xa0, 0x30, 0x8f, 0xd7, 0xa1, 0x5e, },
  45038. { 0xa1, 0xf1, 0xeb, 0xbe, 0xd8, 0xdb, 0xc1, 0x53,
  45039. 0xc0, 0xb8, 0x4a, 0xa6, 0x1f, 0xf0, 0x82, 0x39, },
  45040. { 0x3b, 0x62, 0xa9, 0xba, 0x62, 0x58, 0xf5, 0x61,
  45041. 0x0f, 0x83, 0xe2, 0x64, 0xf3, 0x14, 0x97, 0xb4, },
  45042. { 0x26, 0x44, 0x99, 0x06, 0x0a, 0xd9, 0xba, 0xab,
  45043. 0xc4, 0x7f, 0x8b, 0x02, 0xbb, 0x6d, 0x71, 0xed, },
  45044. { 0x00, 0x11, 0x0d, 0xc3, 0x78, 0x14, 0x69, 0x56,
  45045. 0xc9, 0x54, 0x47, 0xd3, 0xf3, 0xd0, 0xfb, 0xba, },
  45046. { 0x01, 0x51, 0xc5, 0x68, 0x38, 0x6b, 0x66, 0x77,
  45047. 0xa2, 0xb4, 0xdc, 0x6f, 0x81, 0xe5, 0xdc, 0x18, },
  45048. { 0xd6, 0x26, 0xb2, 0x66, 0x90, 0x5e, 0xf3, 0x58,
  45049. 0x82, 0x63, 0x4d, 0xf6, 0x85, 0x32, 0xc1, 0x25, },
  45050. { 0x98, 0x69, 0xe2, 0x47, 0xe9, 0xc0, 0x8b, 0x10,
  45051. 0xd0, 0x29, 0x93, 0x4f, 0xc4, 0xb9, 0x52, 0xf7, },
  45052. { 0x31, 0xfc, 0xef, 0xac, 0x66, 0xd7, 0xde, 0x9c,
  45053. 0x7e, 0xc7, 0x48, 0x5f, 0xe4, 0x49, 0x49, 0x02, },
  45054. { 0x54, 0x93, 0xe9, 0x99, 0x33, 0xb0, 0xa8, 0x11,
  45055. 0x7e, 0x08, 0xec, 0x0f, 0x97, 0xcf, 0xc3, 0xd9, },
  45056. { 0x6e, 0xe2, 0xa4, 0xca, 0x67, 0xb0, 0x54, 0xbb,
  45057. 0xfd, 0x33, 0x15, 0xbf, 0x85, 0x23, 0x05, 0x77, },
  45058. { 0x47, 0x3d, 0x06, 0xe8, 0x73, 0x8d, 0xb8, 0x98,
  45059. 0x54, 0xc0, 0x66, 0xc4, 0x7a, 0xe4, 0x77, 0x40, },
  45060. { 0xa4, 0x26, 0xe5, 0xe4, 0x23, 0xbf, 0x48, 0x85,
  45061. 0x29, 0x4d, 0xa4, 0x81, 0xfe, 0xae, 0xf7, 0x23, },
  45062. { 0x78, 0x01, 0x77, 0x31, 0xcf, 0x65, 0xfa, 0xb0,
  45063. 0x74, 0xd5, 0x20, 0x89, 0x52, 0x51, 0x2e, 0xb1, },
  45064. { 0x9e, 0x25, 0xfc, 0x83, 0x3f, 0x22, 0x90, 0x73,
  45065. 0x3e, 0x93, 0x44, 0xa5, 0xe8, 0x38, 0x39, 0xeb, },
  45066. { 0x56, 0x8e, 0x49, 0x5a, 0xbe, 0x52, 0x5a, 0x21,
  45067. 0x8a, 0x22, 0x14, 0xcd, 0x3e, 0x07, 0x1d, 0x12, },
  45068. { 0x4a, 0x29, 0xb5, 0x45, 0x52, 0xd1, 0x6b, 0x9a,
  45069. 0x46, 0x9c, 0x10, 0x52, 0x8e, 0xff, 0x0a, 0xae, },
  45070. { 0xc9, 0xd1, 0x84, 0xdd, 0xd5, 0xa9, 0xf5, 0xe0,
  45071. 0xcf, 0x8c, 0xe2, 0x9a, 0x9a, 0xbf, 0x69, 0x1c, },
  45072. { 0x2d, 0xb4, 0x79, 0xae, 0x78, 0xbd, 0x50, 0xd8,
  45073. 0x88, 0x2a, 0x8a, 0x17, 0x8a, 0x61, 0x32, 0xad, },
  45074. { 0x8e, 0xce, 0x5f, 0x04, 0x2d, 0x5e, 0x44, 0x7b,
  45075. 0x50, 0x51, 0xb9, 0xea, 0xcb, 0x8d, 0x8f, 0x6f, },
  45076. { 0x9c, 0x0b, 0x53, 0xb4, 0xb3, 0xc3, 0x07, 0xe8,
  45077. 0x7e, 0xae, 0xe0, 0x86, 0x78, 0x14, 0x1f, 0x66, },
  45078. { 0xab, 0xf2, 0x48, 0xaf, 0x69, 0xa6, 0xea, 0xe4,
  45079. 0xbf, 0xd3, 0xeb, 0x2f, 0x12, 0x9e, 0xeb, 0x94, },
  45080. { 0x06, 0x64, 0xda, 0x16, 0x68, 0x57, 0x4b, 0x88,
  45081. 0xb9, 0x35, 0xf3, 0x02, 0x73, 0x58, 0xae, 0xf4, },
  45082. { 0xaa, 0x4b, 0x9d, 0xc4, 0xbf, 0x33, 0x7d, 0xe9,
  45083. 0x0c, 0xd4, 0xfd, 0x3c, 0x46, 0x7c, 0x6a, 0xb7, },
  45084. { 0xea, 0x5c, 0x7f, 0x47, 0x1f, 0xaf, 0x6b, 0xde,
  45085. 0x2b, 0x1a, 0xd7, 0xd4, 0x68, 0x6d, 0x22, 0x87, },
  45086. { 0x29, 0x39, 0xb0, 0x18, 0x32, 0x23, 0xfa, 0xfc,
  45087. 0x17, 0x23, 0xde, 0x4f, 0x52, 0xc4, 0x3d, 0x35, },
  45088. { 0x7c, 0x39, 0x56, 0xca, 0x5e, 0xea, 0xfc, 0x3e,
  45089. 0x36, 0x3e, 0x9d, 0x55, 0x65, 0x46, 0xeb, 0x68, },
  45090. { 0x77, 0xc6, 0x07, 0x71, 0x46, 0xf0, 0x1c, 0x32,
  45091. 0xb6, 0xb6, 0x9d, 0x5f, 0x4e, 0xa9, 0xff, 0xcf, },
  45092. { 0x37, 0xa6, 0x98, 0x6c, 0xb8, 0x84, 0x7e, 0xdf,
  45093. 0x09, 0x25, 0xf0, 0xf1, 0x30, 0x9b, 0x54, 0xde, },
  45094. { 0xa7, 0x05, 0xf0, 0xe6, 0x9d, 0xa9, 0xa8, 0xf9,
  45095. 0x07, 0x24, 0x1a, 0x2e, 0x92, 0x3c, 0x8c, 0xc8, },
  45096. { 0x3d, 0xc4, 0x7d, 0x1f, 0x29, 0xc4, 0x48, 0x46,
  45097. 0x1e, 0x9e, 0x76, 0xed, 0x90, 0x4f, 0x67, 0x11, },
  45098. { 0x0d, 0x62, 0xbf, 0x01, 0xe6, 0xfc, 0x0e, 0x1a,
  45099. 0x0d, 0x3c, 0x47, 0x51, 0xc5, 0xd3, 0x69, 0x2b, },
  45100. { 0x8c, 0x03, 0x46, 0x8b, 0xca, 0x7c, 0x66, 0x9e,
  45101. 0xe4, 0xfd, 0x5e, 0x08, 0x4b, 0xbe, 0xe7, 0xb5, },
  45102. { 0x52, 0x8a, 0x5b, 0xb9, 0x3b, 0xaf, 0x2c, 0x9c,
  45103. 0x44, 0x73, 0xcc, 0xe5, 0xd0, 0xd2, 0x2b, 0xd9, },
  45104. { 0xdf, 0x6a, 0x30, 0x1e, 0x95, 0xc9, 0x5d, 0xad,
  45105. 0x97, 0xae, 0x0c, 0xc8, 0xc6, 0x91, 0x3b, 0xd8, },
  45106. { 0x80, 0x11, 0x89, 0x90, 0x2c, 0x85, 0x7f, 0x39,
  45107. 0xe7, 0x35, 0x91, 0x28, 0x5e, 0x70, 0xb6, 0xdb, },
  45108. { 0xe6, 0x17, 0x34, 0x6a, 0xc9, 0xc2, 0x31, 0xbb,
  45109. 0x36, 0x50, 0xae, 0x34, 0xcc, 0xca, 0x0c, 0x5b, },
  45110. { 0x27, 0xd9, 0x34, 0x37, 0xef, 0xb7, 0x21, 0xaa,
  45111. 0x40, 0x18, 0x21, 0xdc, 0xec, 0x5a, 0xdf, 0x89, },
  45112. { 0x89, 0x23, 0x7d, 0x9d, 0xed, 0x9c, 0x5e, 0x78,
  45113. 0xd8, 0xb1, 0xc9, 0xb1, 0x66, 0xcc, 0x73, 0x42, },
  45114. { 0x4a, 0x6d, 0x80, 0x91, 0xbf, 0x5e, 0x7d, 0x65,
  45115. 0x11, 0x89, 0xfa, 0x94, 0xa2, 0x50, 0xb1, 0x4c, },
  45116. { 0x0e, 0x33, 0xf9, 0x60, 0x55, 0xe7, 0xae, 0x89,
  45117. 0x3f, 0xfc, 0x0e, 0x3d, 0xcf, 0x49, 0x29, 0x02, },
  45118. { 0xe6, 0x1c, 0x43, 0x2b, 0x72, 0x0b, 0x19, 0xd1,
  45119. 0x8e, 0xc8, 0xd8, 0x4b, 0xdc, 0x63, 0x15, 0x1b, },
  45120. { 0xf7, 0xe5, 0xae, 0xf5, 0x49, 0xf7, 0x82, 0xcf,
  45121. 0x37, 0x90, 0x55, 0xa6, 0x08, 0x26, 0x9b, 0x16, },
  45122. { 0x43, 0x8d, 0x03, 0x0f, 0xd0, 0xb7, 0xa5, 0x4f,
  45123. 0xa8, 0x37, 0xf2, 0xad, 0x20, 0x1a, 0x64, 0x03, },
  45124. { 0xa5, 0x90, 0xd3, 0xee, 0x4f, 0xbf, 0x04, 0xe3,
  45125. 0x24, 0x7e, 0x0d, 0x27, 0xf2, 0x86, 0x42, 0x3f, },
  45126. { 0x5f, 0xe2, 0xc1, 0xa1, 0x72, 0xfe, 0x93, 0xc4,
  45127. 0xb1, 0x5c, 0xd3, 0x7c, 0xae, 0xf9, 0xf5, 0x38, },
  45128. { 0x2c, 0x97, 0x32, 0x5c, 0xbd, 0x06, 0xb3, 0x6e,
  45129. 0xb2, 0x13, 0x3d, 0xd0, 0x8b, 0x3a, 0x01, 0x7c, },
  45130. { 0x92, 0xc8, 0x14, 0x22, 0x7a, 0x6b, 0xca, 0x94,
  45131. 0x9f, 0xf0, 0x65, 0x9f, 0x00, 0x2a, 0xd3, 0x9e, },
  45132. { 0xdc, 0xe8, 0x50, 0x11, 0x0b, 0xd8, 0x32, 0x8c,
  45133. 0xfb, 0xd5, 0x08, 0x41, 0xd6, 0x91, 0x1d, 0x87, },
  45134. { 0x67, 0xf1, 0x49, 0x84, 0xc7, 0xda, 0x79, 0x12,
  45135. 0x48, 0xe3, 0x2b, 0xb5, 0x92, 0x25, 0x83, 0xda, },
  45136. { 0x19, 0x38, 0xf2, 0xcf, 0x72, 0xd5, 0x4e, 0xe9,
  45137. 0x7e, 0x94, 0x16, 0x6f, 0xa9, 0x1d, 0x2a, 0x36, },
  45138. { 0x74, 0x48, 0x1e, 0x96, 0x46, 0xed, 0x49, 0xfe,
  45139. 0x0f, 0x62, 0x24, 0x30, 0x16, 0x04, 0x69, 0x8e, },
  45140. { 0x57, 0xfc, 0xa5, 0xde, 0x98, 0xa9, 0xd6, 0xd8,
  45141. 0x00, 0x64, 0x38, 0xd0, 0x58, 0x3d, 0x8a, 0x1d, },
  45142. { 0x9f, 0xec, 0xde, 0x1c, 0xef, 0xdc, 0x1c, 0xbe,
  45143. 0xd4, 0x76, 0x36, 0x74, 0xd9, 0x57, 0x53, 0x59, },
  45144. { 0xe3, 0x04, 0x0c, 0x00, 0xeb, 0x28, 0xf1, 0x53,
  45145. 0x66, 0xca, 0x73, 0xcb, 0xd8, 0x72, 0xe7, 0x40, },
  45146. { 0x76, 0x97, 0x00, 0x9a, 0x6a, 0x83, 0x1d, 0xfe,
  45147. 0xcc, 0xa9, 0x1c, 0x59, 0x93, 0x67, 0x0f, 0x7a, },
  45148. { 0x58, 0x53, 0x54, 0x23, 0x21, 0xf5, 0x67, 0xa0,
  45149. 0x05, 0xd5, 0x47, 0xa4, 0xf0, 0x47, 0x59, 0xbd, },
  45150. { 0x51, 0x50, 0xd1, 0x77, 0x2f, 0x50, 0x83, 0x4a,
  45151. 0x50, 0x3e, 0x06, 0x9a, 0x97, 0x3f, 0xbd, 0x7c, },
  45152. };
  45153. #endif
  45154. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void)
  45155. {
  45156. wc_test_ret_t ret = 0;
  45157. int i;
  45158. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  45159. unsigned char res[SIPHASH_MAC_SIZE_16];
  45160. unsigned char tmp[SIPHASH_MAC_SIZE_8];
  45161. SipHash siphash;
  45162. WOLFSSL_ENTER("siphash_test (1)");
  45163. for (i = 0; i < 64; i++) {
  45164. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45165. if (ret != 0)
  45166. return WC_TEST_RET_ENC_I(i);
  45167. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45168. if (ret != 0)
  45169. return WC_TEST_RET_ENC_I(i);
  45170. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45171. if (ret != 0)
  45172. return WC_TEST_RET_ENC_I(i);
  45173. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45174. return WC_TEST_RET_ENC_I(i);
  45175. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_8);
  45176. if (ret != 0)
  45177. return WC_TEST_RET_ENC_I(i);
  45178. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45179. return WC_TEST_RET_ENC_I(i);
  45180. }
  45181. for (i = 0; i < 64; i++) {
  45182. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16);
  45183. if (ret != 0)
  45184. return WC_TEST_RET_ENC_I(i);
  45185. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45186. if (ret != 0)
  45187. return WC_TEST_RET_ENC_I(i);
  45188. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  45189. if (ret != 0)
  45190. return WC_TEST_RET_ENC_I(i);
  45191. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45192. return WC_TEST_RET_ENC_I(i);
  45193. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_16);
  45194. if (ret != 0)
  45195. return WC_TEST_RET_ENC_I(i);
  45196. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45197. return WC_TEST_RET_ENC_I(i);
  45198. }
  45199. #else
  45200. WOLFSSL_ENTER("siphash_test (1)");
  45201. #endif
  45202. /* Testing bad parameters. */
  45203. ret = wc_InitSipHash(NULL, NULL, SIPHASH_MAC_SIZE_8);
  45204. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45205. return WC_TEST_RET_ENC_EC(ret);
  45206. ret = wc_InitSipHash(NULL, siphash_key, SIPHASH_MAC_SIZE_8);
  45207. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45208. return WC_TEST_RET_ENC_EC(ret);
  45209. ret = wc_InitSipHash(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  45210. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45211. return WC_TEST_RET_ENC_EC(ret);
  45212. ret = wc_InitSipHash(&siphash, siphash_key, 7);
  45213. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45214. return WC_TEST_RET_ENC_EC(ret);
  45215. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45216. if (ret != 0)
  45217. return WC_TEST_RET_ENC_EC(ret);
  45218. ret = wc_SipHashUpdate(NULL, NULL, 0);
  45219. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45220. return WC_TEST_RET_ENC_EC(ret);
  45221. ret = wc_SipHashUpdate(&siphash, NULL, 1);
  45222. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45223. return WC_TEST_RET_ENC_EC(ret);
  45224. ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8);
  45225. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45226. return WC_TEST_RET_ENC_EC(ret);
  45227. ret = wc_SipHashFinal(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  45228. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45229. return WC_TEST_RET_ENC_EC(ret);
  45230. ret = wc_SipHashFinal(NULL, res, SIPHASH_MAC_SIZE_8);
  45231. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45232. return WC_TEST_RET_ENC_EC(ret);
  45233. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  45234. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45235. return WC_TEST_RET_ENC_EC(ret);
  45236. ret = wc_SipHash(NULL, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  45237. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45238. return WC_TEST_RET_ENC_EC(ret);
  45239. ret = wc_SipHash(siphash_key, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  45240. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45241. return WC_TEST_RET_ENC_EC(ret);
  45242. ret = wc_SipHash(NULL, NULL, 0, res, SIPHASH_MAC_SIZE_16);
  45243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45244. return WC_TEST_RET_ENC_EC(ret);
  45245. ret = wc_SipHash(siphash_key, NULL, 0, res, 15);
  45246. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45247. return WC_TEST_RET_ENC_EC(ret);
  45248. ret = wc_SipHash(siphash_key, NULL, 1, res, SIPHASH_MAC_SIZE_16);
  45249. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45250. return WC_TEST_RET_ENC_EC(ret);
  45251. /* Test cache with multiple non blocksize bytes */
  45252. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45253. if (ret != 0)
  45254. return WC_TEST_RET_ENC_EC(ret);
  45255. ret = wc_SipHashUpdate(&siphash, siphash_msg, 5);
  45256. if (ret != 0)
  45257. return WC_TEST_RET_ENC_EC(ret);
  45258. ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4);
  45259. if (ret != 0)
  45260. return WC_TEST_RET_ENC_EC(ret);
  45261. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45262. if (ret != 0)
  45263. return WC_TEST_RET_ENC_EC(ret);
  45264. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45265. if (ret != 0)
  45266. return WC_TEST_RET_ENC_EC(ret);
  45267. ret = wc_SipHashUpdate(&siphash, siphash_msg, 9);
  45268. if (ret != 0)
  45269. return WC_TEST_RET_ENC_EC(ret);
  45270. ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8);
  45271. if (ret != 0)
  45272. return WC_TEST_RET_ENC_EC(ret);
  45273. if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0)
  45274. return WC_TEST_RET_ENC_NC;
  45275. return 0;
  45276. }
  45277. #endif /* WOLFSSL_SIPHASH */
  45278. #ifdef HAVE_LIBZ
  45279. static const byte sample_text[] =
  45280. "Biodiesel cupidatat marfa, cliche aute put a bird on it incididunt elit\n"
  45281. "polaroid. Sunt tattooed bespoke reprehenderit. Sint twee organic id\n"
  45282. "marfa. Commodo veniam ad esse gastropub. 3 wolf moon sartorial vero,\n"
  45283. "plaid delectus biodiesel squid +1 vice. Post-ironic keffiyeh leggings\n"
  45284. "selfies cray fap hoodie, forage anim. Carles cupidatat shoreditch, VHS\n"
  45285. "small batch meggings kogi dolore food truck bespoke gastropub.\n"
  45286. "\n"
  45287. "Terry richardson adipisicing actually typewriter tumblr, twee whatever\n"
  45288. "four loko you probably haven't heard of them high life. Messenger bag\n"
  45289. "whatever tattooed deep v mlkshk. Brooklyn pinterest assumenda chillwave\n"
  45290. "et, banksy ullamco messenger bag umami pariatur direct trade forage.\n"
  45291. "Typewriter culpa try-hard, pariatur sint brooklyn meggings. Gentrify\n"
  45292. "food truck next level, tousled irony non semiotics PBR ethical anim cred\n"
  45293. "readymade. Mumblecore brunch lomo odd future, portland organic terry\n"
  45294. "richardson elit leggings adipisicing ennui raw denim banjo hella. Godard\n"
  45295. "mixtape polaroid, pork belly readymade organic cray typewriter helvetica\n"
  45296. "four loko whatever street art yr farm-to-table.\n"
  45297. "\n"
  45298. "Vinyl keytar vice tofu. Locavore you probably haven't heard of them pug\n"
  45299. "pickled, hella tonx labore truffaut DIY mlkshk elit cosby sweater sint\n"
  45300. "et mumblecore. Elit swag semiotics, reprehenderit DIY sartorial nisi ugh\n"
  45301. "nesciunt pug pork belly wayfarers selfies delectus. Ethical hoodie\n"
  45302. "seitan fingerstache kale chips. Terry richardson artisan williamsburg,\n"
  45303. "eiusmod fanny pack irony tonx ennui lo-fi incididunt tofu YOLO\n"
  45304. "readymade. 8-bit sed ethnic beard officia. Pour-over iphone DIY butcher,\n"
  45305. "ethnic art party qui letterpress nisi proident jean shorts mlkshk\n"
  45306. "locavore.\n"
  45307. "\n"
  45308. "Narwhal flexitarian letterpress, do gluten-free voluptate next level\n"
  45309. "banh mi tonx incididunt carles DIY. Odd future nulla 8-bit beard ut\n"
  45310. "cillum pickled velit, YOLO officia you probably haven't heard of them\n"
  45311. "trust fund gastropub. Nisi adipisicing tattooed, Austin mlkshk 90's\n"
  45312. "small batch american apparel. Put a bird on it cosby sweater before they\n"
  45313. "sold out pork belly kogi hella. Street art mollit sustainable polaroid,\n"
  45314. "DIY ethnic ea pug beard dreamcatcher cosby sweater magna scenester nisi.\n"
  45315. "Sed pork belly skateboard mollit, labore proident eiusmod. Sriracha\n"
  45316. "excepteur cosby sweater, anim deserunt laborum eu aliquip ethical et\n"
  45317. "neutra PBR selvage.\n"
  45318. "\n"
  45319. "Raw denim pork belly truffaut, irony plaid sustainable put a bird on it\n"
  45320. "next level jean shorts exercitation. Hashtag keytar whatever, nihil\n"
  45321. "authentic aliquip disrupt laborum. Tattooed selfies deserunt trust fund\n"
  45322. "wayfarers. 3 wolf moon synth church-key sartorial, gastropub leggings\n"
  45323. "tattooed. Labore high life commodo, meggings raw denim fingerstache pug\n"
  45324. "trust fund leggings seitan forage. Nostrud ullamco duis, reprehenderit\n"
  45325. "incididunt flannel sustainable helvetica pork belly pug banksy you\n"
  45326. "probably haven't heard of them nesciunt farm-to-table. Disrupt nostrud\n"
  45327. "mollit magna, sriracha sartorial helvetica.\n"
  45328. "\n"
  45329. "Nulla kogi reprehenderit, skateboard sustainable duis adipisicing viral\n"
  45330. "ad fanny pack salvia. Fanny pack trust fund you probably haven't heard\n"
  45331. "of them YOLO vice nihil. Keffiyeh cray lo-fi pinterest cardigan aliqua,\n"
  45332. "reprehenderit aute. Culpa tousled williamsburg, marfa lomo actually anim\n"
  45333. "skateboard. Iphone aliqua ugh, semiotics pariatur vero readymade\n"
  45334. "organic. Marfa squid nulla, in laborum disrupt laboris irure gastropub.\n"
  45335. "Veniam sunt food truck leggings, sint vinyl fap.\n"
  45336. "\n"
  45337. "Hella dolore pork belly, truffaut carles you probably haven't heard of\n"
  45338. "them PBR helvetica in sapiente. Fashion axe ugh bushwick american\n"
  45339. "apparel. Fingerstache sed iphone, jean shorts blue bottle nisi bushwick\n"
  45340. "flexitarian officia veniam plaid bespoke fap YOLO lo-fi. Blog\n"
  45341. "letterpress mumblecore, food truck id cray brooklyn cillum ad sed.\n"
  45342. "Assumenda chambray wayfarers vinyl mixtape sustainable. VHS vinyl\n"
  45343. "delectus, culpa williamsburg polaroid cliche swag church-key synth kogi\n"
  45344. "magna pop-up literally. Swag thundercats ennui shoreditch vegan\n"
  45345. "pitchfork neutra truffaut etsy, sed single-origin coffee craft beer.\n"
  45346. "\n"
  45347. "Odio letterpress brooklyn elit. Nulla single-origin coffee in occaecat\n"
  45348. "meggings. Irony meggings 8-bit, chillwave lo-fi adipisicing cred\n"
  45349. "dreamcatcher veniam. Put a bird on it irony umami, trust fund bushwick\n"
  45350. "locavore kale chips. Sriracha swag thundercats, chillwave disrupt\n"
  45351. "tousled beard mollit mustache leggings portland next level. Nihil esse\n"
  45352. "est, skateboard art party etsy thundercats sed dreamcatcher ut iphone\n"
  45353. "swag consectetur et. Irure skateboard banjo, nulla deserunt messenger\n"
  45354. "bag dolor terry richardson sapiente.\n";
  45355. static const byte sample_text_gz[] = {
  45356. 0x1F, 0x8B, 0x08, 0x08, 0xC5, 0x49, 0xB5, 0x5B, 0x00, 0x03, 0x63, 0x69, 0x70,
  45357. 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x8D,
  45358. 0x58, 0xCB, 0x92, 0xE4, 0xB6, 0x11, 0xBC, 0xE3, 0x2B, 0xEA, 0xA6, 0x83, 0xD9,
  45359. 0x1D, 0x72, 0xF8, 0x22, 0x1F, 0xB5, 0x96, 0xA5, 0xDD, 0x90, 0xBC, 0xAB, 0xD0,
  45360. 0x28, 0x36, 0x42, 0x47, 0x90, 0x2C, 0x36, 0xA1, 0x06, 0x09, 0x0A, 0x8F, 0xEE,
  45361. 0xE1, 0xDF, 0x3B, 0x0B, 0xE0, 0x73, 0x2C, 0x4B, 0xBA, 0xCD, 0xCE, 0x80, 0x78,
  45362. 0x64, 0x65, 0x65, 0x66, 0xED, 0x3B, 0xE3, 0x5A, 0xC3, 0x81, 0x2D, 0x35, 0x69,
  45363. 0x32, 0xAD, 0x8E, 0x3A, 0xD2, 0xA0, 0x7D, 0xA7, 0x2B, 0x6A, 0xAC, 0x69, 0x7A,
  45364. 0x26, 0x9D, 0x22, 0xD3, 0x94, 0x22, 0x69, 0xAA, 0x8D, 0x6F, 0xC9, 0x8D, 0x64,
  45365. 0x22, 0x99, 0xB1, 0x31, 0xAD, 0x69, 0xD3, 0x18, 0x89, 0xAD, 0x89, 0x6A, 0x72,
  45366. 0x56, 0x7B, 0x67, 0xDA, 0x2B, 0xBD, 0xC8, 0xEF, 0xB0, 0x4D, 0x74, 0x8E, 0x5B,
  45367. 0xAA, 0x39, 0x4C, 0xEE, 0xCE, 0xE4, 0x79, 0xF2, 0xDC, 0xF3, 0xD8, 0xB2, 0x37,
  45368. 0x11, 0x8B, 0x8C, 0x2C, 0x7A, 0x32, 0x93, 0xF3, 0x37, 0x3D, 0x9A, 0x86, 0x4C,
  45369. 0xAB, 0xF2, 0xB9, 0x57, 0xFA, 0x97, 0x1B, 0x06, 0xD7, 0x3A, 0x7A, 0xF0, 0x68,
  45370. 0xF4, 0x40, 0xBA, 0x25, 0x0E, 0x81, 0xE9, 0xA6, 0x43, 0xF4, 0x6E, 0x4A, 0xF5,
  45371. 0x95, 0xFE, 0x41, 0x4F, 0x67, 0x3B, 0x1A, 0x1C, 0xEE, 0x12, 0xB4, 0x8F, 0xCE,
  45372. 0x1B, 0x6D, 0xB1, 0xDE, 0xBB, 0x4A, 0x4D, 0x56, 0x9B, 0x96, 0x5A, 0xB6, 0xDC,
  45373. 0xC4, 0x14, 0x70, 0xE5, 0xF5, 0x7D, 0xE1, 0xB7, 0x84, 0x3F, 0xFC, 0xED, 0xEF,
  45374. 0xF4, 0x30, 0x0D, 0x5F, 0xE9, 0x47, 0x17, 0xE2, 0xC5, 0x78, 0x27, 0x67, 0xDF,
  45375. 0xB9, 0xEB, 0xCC, 0xCC, 0x3D, 0x59, 0xBE, 0xDD, 0xCC, 0x78, 0x0B, 0x0A, 0x1F,
  45376. 0x74, 0xF8, 0x8C, 0x1A, 0xAF, 0x67, 0xEA, 0xF4, 0x44, 0xBD, 0x93, 0x7D, 0x2A,
  45377. 0xEA, 0x9C, 0xD7, 0x37, 0x80, 0x32, 0x9A, 0x01, 0x37, 0xD5, 0xDE, 0xCA, 0xA2,
  45378. 0x0D, 0xB9, 0xD0, 0x3B, 0xCF, 0xAD, 0x89, 0x4D, 0x5F, 0xD1, 0xE7, 0xF7, 0x2F,
  45379. 0x2A, 0x0C, 0xDA, 0x5A, 0xAA, 0x35, 0x7E, 0x41, 0xC3, 0xB2, 0x37, 0xDD, 0xDD,
  45380. 0xCD, 0x50, 0xEB, 0x2C, 0x96, 0x62, 0x3B, 0xD7, 0x52, 0xF4, 0xA9, 0xB9, 0x6F,
  45381. 0x48, 0xED, 0xEF, 0x54, 0xEA, 0x67, 0xF6, 0x7E, 0x26, 0x8F, 0x3A, 0x68, 0xDF,
  45382. 0x06, 0xBC, 0x56, 0xB7, 0x66, 0x32, 0xC1, 0x34, 0xD8, 0x88, 0x34, 0x1E, 0x88,
  45383. 0xED, 0x67, 0x8A, 0xF3, 0xC4, 0x4F, 0xC0, 0xCA, 0x9E, 0x62, 0x1A, 0x6A, 0xEB,
  45384. 0xAB, 0x02, 0xED, 0xB3, 0xD7, 0x91, 0x81, 0x8A, 0xEA, 0x5C, 0xF2, 0x64, 0xDD,
  45385. 0xDD, 0xD1, 0xEC, 0x12, 0x4D, 0xDE, 0xD5, 0xBA, 0xC6, 0x77, 0xBD, 0x06, 0xC4,
  45386. 0x5F, 0x44, 0xEA, 0x59, 0x4B, 0x5D, 0x3B, 0x8A, 0x3D, 0x0F, 0xD4, 0x9B, 0x1B,
  45387. 0x80, 0x30, 0x1D, 0x30, 0xFA, 0x8F, 0x00, 0x3F, 0xDE, 0xB0, 0x6F, 0xAD, 0x6F,
  45388. 0x6A, 0xDD, 0x6E, 0x2F, 0x6E, 0xCB, 0x3C, 0xD1, 0x83, 0x06, 0x7B, 0x0F, 0xFD,
  45389. 0xFD, 0x4A, 0xEF, 0xBC, 0x73, 0x77, 0x3B, 0x8F, 0x34, 0xA1, 0xBA, 0xEC, 0x39,
  45390. 0x80, 0x33, 0x21, 0xA4, 0x01, 0x55, 0xD7, 0xD4, 0xF4, 0xC6, 0xDA, 0x27, 0x4E,
  45391. 0x54, 0x1C, 0x2B, 0xEC, 0x37, 0xDE, 0xC3, 0x4C, 0xC9, 0x5A, 0x3D, 0x34, 0x0E,
  45392. 0xD8, 0x1C, 0x0E, 0xA2, 0x34, 0xE8, 0xC1, 0xD0, 0xA4, 0x51, 0xD5, 0x88, 0x8B,
  45393. 0xB7, 0xC6, 0xA3, 0x96, 0x40, 0x49, 0xB7, 0xBC, 0xE0, 0x7F, 0x55, 0x3F, 0xEF,
  45394. 0x6F, 0x6E, 0x92, 0x9D, 0x34, 0xFE, 0x3C, 0x5F, 0x04, 0xA5, 0x6A, 0xFF, 0x30,
  45395. 0x08, 0xC9, 0xEA, 0xF5, 0x52, 0x2B, 0xFE, 0x57, 0xFA, 0x8E, 0xC7, 0xE8, 0x4D,
  45396. 0x37, 0xAB, 0x03, 0xFA, 0x23, 0xBF, 0x46, 0x94, 0xFF, 0xC1, 0x16, 0xE0, 0xB9,
  45397. 0x14, 0x2C, 0x9E, 0x27, 0xEC, 0x98, 0x69, 0x14, 0x92, 0xF1, 0x60, 0x5C, 0x34,
  45398. 0x4D, 0xA0, 0x1F, 0xDF, 0xFD, 0x44, 0x1C, 0x7B, 0xD3, 0x80, 0x70, 0x42, 0x02,
  45399. 0x30, 0x84, 0x5B, 0xE5, 0x59, 0xB7, 0xF3, 0x80, 0xFB, 0x01, 0x33, 0xA9, 0x00,
  45400. 0x37, 0x52, 0xDC, 0xDA, 0xA7, 0x11, 0x85, 0xB7, 0x6E, 0x70, 0xE4, 0xDA, 0x96,
  45401. 0xBA, 0x84, 0x5B, 0x81, 0x43, 0x93, 0xF3, 0xD1, 0xEA, 0xB1, 0xDD, 0xB8, 0x1F,
  45402. 0xA5, 0xCC, 0xEA, 0x50, 0x66, 0x69, 0xA9, 0x8D, 0x8C, 0xA7, 0xA2, 0xF3, 0x38,
  45403. 0x26, 0x43, 0x5E, 0x3F, 0x01, 0xBE, 0x1C, 0x0F, 0x20, 0x7F, 0x75, 0xA8, 0x20,
  45404. 0x80, 0xC4, 0xC3, 0x5C, 0x8B, 0x0D, 0xD4, 0x60, 0x5E, 0xA3, 0x9E, 0xD0, 0xB4,
  45405. 0x4B, 0x4F, 0xE6, 0x13, 0x85, 0x60, 0x42, 0x96, 0xED, 0xAA, 0xDB, 0xE9, 0x99,
  45406. 0xE3, 0x07, 0x0E, 0x61, 0xB3, 0x07, 0xE3, 0xB1, 0xFA, 0xC0, 0x9B, 0xAD, 0xF6,
  45407. 0xE0, 0x26, 0x33, 0xEA, 0xEA, 0x23, 0xCD, 0x1E, 0x9D, 0xE1, 0x87, 0x4B, 0x74,
  45408. 0x97, 0x08, 0x3E, 0xA1, 0x28, 0xEA, 0xB3, 0x19, 0x67, 0x8B, 0x76, 0x9A, 0xA3,
  45409. 0xF6, 0xB9, 0xCF, 0x80, 0x65, 0x97, 0xAE, 0xF4, 0x83, 0x6B, 0xF4, 0x43, 0x20,
  45410. 0xF9, 0x0B, 0xFC, 0x9B, 0xD2, 0x4D, 0x4D, 0xA6, 0xB9, 0xA3, 0x02, 0x55, 0x79,
  45411. 0x18, 0x36, 0x19, 0x5F, 0xC9, 0xEA, 0x5A, 0x76, 0x40, 0xB9, 0xBA, 0x0E, 0x9A,
  45412. 0x44, 0xDF, 0x7C, 0xF8, 0x65, 0x61, 0x5E, 0x81, 0xAB, 0x71, 0xA1, 0x9E, 0x29,
  45413. 0x3C, 0x59, 0xCB, 0x23, 0xA4, 0xF6, 0x60, 0x1A, 0x0D, 0x5B, 0x39, 0xAE, 0xF4,
  45414. 0x6F, 0x59, 0x16, 0x9E, 0x60, 0xD8, 0x56, 0xCF, 0xEA, 0x2C, 0x4C, 0x79, 0xD3,
  45415. 0x5D, 0x51, 0x46, 0xA0, 0x4E, 0xE9, 0xD6, 0xAB, 0x91, 0x43, 0x63, 0x44, 0xD7,
  45416. 0x70, 0xB9, 0x23, 0x98, 0x4F, 0x3D, 0x03, 0x02, 0xF6, 0x81, 0x56, 0xC1, 0x58,
  45417. 0x85, 0x07, 0xA7, 0x2D, 0x2C, 0x29, 0xCA, 0x01, 0x45, 0x31, 0x51, 0x8F, 0xD4,
  45418. 0x19, 0xA1, 0x79, 0x88, 0x5A, 0xA4, 0xF5, 0xAE, 0x2D, 0x4B, 0x63, 0x4C, 0x58,
  45419. 0xFE, 0xBF, 0xAD, 0xEE, 0xA3, 0x09, 0xF8, 0xE2, 0x89, 0xBE, 0x81, 0x0E, 0x86,
  45420. 0x3A, 0xF9, 0x5B, 0xA5, 0xD8, 0xA4, 0x00, 0x75, 0x04, 0xF2, 0x23, 0xB8, 0x39,
  45421. 0x69, 0x50, 0xB7, 0xD0, 0x34, 0x63, 0x54, 0xD8, 0x61, 0xDD, 0xA5, 0x33, 0x47,
  45422. 0x85, 0x96, 0x22, 0xD0, 0x2F, 0x9F, 0x7E, 0xF8, 0x74, 0x24, 0xEA, 0x57, 0x97,
  45423. 0x5A, 0xE0, 0x00, 0xCF, 0xC1, 0x67, 0xE1, 0x41, 0xBD, 0x94, 0xA1, 0x03, 0xD3,
  45424. 0xB4, 0x08, 0x64, 0xF2, 0x17, 0x27, 0x35, 0x37, 0x53, 0xEF, 0x46, 0xCE, 0xD8,
  45425. 0xD4, 0x09, 0x52, 0xC6, 0x1E, 0xF7, 0x28, 0xDF, 0x08, 0x0F, 0xD0, 0x6F, 0x71,
  45426. 0xA6, 0xDF, 0xE4, 0x60, 0x8E, 0xC0, 0x1E, 0x78, 0x86, 0x50, 0xB0, 0x9B, 0x84,
  45427. 0x7E, 0xE8, 0x36, 0xFA, 0x95, 0xF1, 0x12, 0x51, 0xC7, 0x18, 0x96, 0xA2, 0x29,
  45428. 0xBB, 0x70, 0x02, 0xB4, 0xF9, 0xA8, 0x3D, 0x08, 0x66, 0xA9, 0xB3, 0xFC, 0x0A,
  45429. 0x94, 0x80, 0xFD, 0x78, 0xDC, 0xAB, 0x82, 0x5A, 0xD2, 0xCD, 0xC2, 0x87, 0xC6,
  45430. 0x4B, 0x07, 0xFA, 0xD1, 0xC3, 0xD9, 0x34, 0x41, 0x85, 0xF8, 0xD0, 0xB6, 0x0A,
  45431. 0x9D, 0x00, 0x91, 0x35, 0x05, 0x88, 0xC3, 0xE3, 0x9B, 0x22, 0xD2, 0xB8, 0xFD,
  45432. 0x95, 0x3E, 0x6D, 0x5D, 0x48, 0xA3, 0x68, 0xCF, 0x02, 0x42, 0x79, 0x79, 0x8A,
  45433. 0xAA, 0x01, 0xD6, 0x09, 0x14, 0x2C, 0xF4, 0x83, 0xA3, 0x80, 0x31, 0x55, 0x46,
  45434. 0x6E, 0xC5, 0xE5, 0x2F, 0x30, 0x58, 0x81, 0xA2, 0x90, 0xBE, 0x2E, 0xA1, 0xC3,
  45435. 0x0F, 0xA6, 0xF5, 0x51, 0x00, 0x39, 0xB6, 0xF2, 0x2A, 0xA3, 0x15, 0x7D, 0x8D,
  45436. 0xF5, 0x66, 0x5C, 0xD9, 0xFC, 0xCF, 0x2F, 0xBF, 0x08, 0x27, 0xE7, 0xD0, 0x03,
  45437. 0xB8, 0xD9, 0x00, 0x13, 0x3D, 0x01, 0x6B, 0xB6, 0xA8, 0xCD, 0x5B, 0x3B, 0x3E,
  45438. 0x93, 0xBF, 0xE6, 0x2E, 0xB7, 0x4A, 0xCF, 0xB3, 0x0A, 0xCE, 0x62, 0x11, 0xD6,
  45439. 0x1F, 0x68, 0x9B, 0x1D, 0x68, 0xD1, 0x8C, 0x97, 0xBD, 0xA1, 0x07, 0x67, 0x73,
  45440. 0x87, 0xE0, 0x36, 0xDA, 0x8C, 0xD2, 0xD2, 0xBB, 0x84, 0x28, 0xA9, 0xFE, 0x52,
  45441. 0x74, 0xD6, 0xB9, 0x0F, 0x0A, 0x6A, 0x2D, 0x28, 0x35, 0x34, 0x3A, 0xD3, 0xE2,
  45442. 0xCD, 0x35, 0x06, 0x7D, 0x1B, 0x35, 0x85, 0x86, 0xD1, 0x3E, 0xF2, 0x6F, 0xA1,
  45443. 0xC4, 0x55, 0xBD, 0x00, 0xD8, 0xC3, 0x5D, 0xC2, 0x1D, 0x6B, 0x6B, 0x27, 0x5B,
  45444. 0x95, 0xF3, 0xAB, 0xB5, 0xD3, 0x37, 0xF2, 0x2C, 0x9C, 0xC7, 0x5D, 0xBD, 0xF1,
  45445. 0x68, 0x1C, 0xAD, 0xF8, 0xB5, 0xE1, 0x29, 0x72, 0x7A, 0x73, 0x62, 0x55, 0x24,
  45446. 0xB9, 0x85, 0xDF, 0x7B, 0x29, 0x7D, 0xDE, 0x08, 0xF5, 0xE4, 0x44, 0xDA, 0x1A,
  45447. 0x30, 0x74, 0xDA, 0xB4, 0x9B, 0x23, 0x9A, 0x3A, 0xC1, 0x53, 0xB2, 0xA2, 0xA3,
  45448. 0x7B, 0x1F, 0xD9, 0x56, 0xD4, 0x4F, 0x9B, 0xB2, 0x1E, 0xEE, 0xB8, 0x6A, 0x4E,
  45449. 0xB5, 0xF4, 0x5A, 0xC9, 0x18, 0x27, 0x9C, 0xDE, 0x14, 0x44, 0xED, 0xC4, 0x3C,
  45450. 0x71, 0x9F, 0x5F, 0xD9, 0x37, 0xA0, 0x78, 0x34, 0x6E, 0xBC, 0xD2, 0x7B, 0x1D,
  45451. 0xFA, 0x08, 0x39, 0x5A, 0x04, 0x73, 0x15, 0xD9, 0x0A, 0x48, 0xC1, 0x2D, 0x15,
  45452. 0x4E, 0x84, 0x30, 0x45, 0x69, 0xB3, 0xE5, 0xF6, 0xAD, 0x09, 0x1E, 0xCC, 0x5F,
  45453. 0x1F, 0x06, 0xD5, 0x58, 0xAD, 0x78, 0xD7, 0x9F, 0xE5, 0xED, 0x3B, 0x09, 0xD5,
  45454. 0xA6, 0x52, 0x6F, 0x92, 0xD3, 0x3C, 0xC6, 0x1E, 0xF2, 0x93, 0x7C, 0xD3, 0x5F,
  45455. 0x70, 0x85, 0x5D, 0xF8, 0xAA, 0x9D, 0xB7, 0x7B, 0x24, 0x5A, 0xE9, 0x0A, 0x35,
  45456. 0x2F, 0xF5, 0xD9, 0x82, 0x02, 0x8A, 0x90, 0x13, 0x5B, 0xB5, 0x67, 0x9C, 0xDD,
  45457. 0xA0, 0x4E, 0x82, 0x27, 0xDA, 0x7E, 0xE8, 0x8E, 0xCD, 0xE1, 0x56, 0x71, 0x2C,
  45458. 0xE6, 0x4E, 0x1F, 0x91, 0xCD, 0x7C, 0x6A, 0xB7, 0x78, 0xD0, 0x26, 0xF3, 0x56,
  45459. 0xA9, 0xD5, 0xA1, 0xC3, 0x3B, 0x98, 0xE9, 0x28, 0x09, 0xEF, 0x50, 0x90, 0xCD,
  45460. 0xC4, 0x8E, 0x75, 0xCC, 0xAC, 0x2D, 0xC9, 0x03, 0x6D, 0xAC, 0xFE, 0xC4, 0x88,
  45461. 0x36, 0xD1, 0x3F, 0xBB, 0x1C, 0x7D, 0xB3, 0x14, 0x61, 0x2C, 0xB7, 0x54, 0x4B,
  45462. 0xDB, 0x64, 0xB6, 0x57, 0x14, 0x16, 0x8E, 0x1E, 0x6C, 0x64, 0xBB, 0x8B, 0x48,
  45463. 0x5D, 0x96, 0x9D, 0xDC, 0x80, 0xA7, 0xF7, 0x54, 0xC7, 0x46, 0x38, 0x3E, 0x44,
  45464. 0xDE, 0x7E, 0x92, 0x8D, 0x07, 0xF6, 0x07, 0x37, 0x4E, 0x16, 0x10, 0xB4, 0x7D,
  45465. 0x88, 0x66, 0x7F, 0xBB, 0xFF, 0xEA, 0x00, 0xF3, 0xFF, 0x97, 0x2C, 0xB5, 0xBE,
  45466. 0x35, 0x4B, 0x5C, 0x36, 0xEC, 0x4C, 0xBD, 0x2B, 0x7D, 0xBF, 0x46, 0xE2, 0x9C,
  45467. 0x0E, 0x8A, 0xA3, 0xEC, 0xB1, 0x0E, 0x9A, 0xDA, 0x9A, 0x9B, 0x28, 0x92, 0x10,
  45468. 0x53, 0x57, 0xEA, 0xEC, 0xA2, 0x32, 0x32, 0x20, 0x1D, 0x97, 0x5C, 0xB6, 0x84,
  45469. 0xA9, 0x93, 0x8D, 0x95, 0x11, 0xA3, 0x24, 0xA3, 0x2D, 0xC6, 0x4A, 0xEF, 0xAA,
  45470. 0x1D, 0x85, 0x2B, 0x7D, 0x28, 0xBE, 0x53, 0xCE, 0x10, 0x1F, 0xAE, 0x0E, 0x41,
  45471. 0x6C, 0x4B, 0x79, 0x12, 0xFB, 0xF7, 0x54, 0xA3, 0x96, 0x54, 0x83, 0x20, 0x96,
  45472. 0x8F, 0x28, 0xA9, 0x3F, 0x8B, 0x3D, 0xBA, 0x77, 0xDC, 0x24, 0xE1, 0xD4, 0x49,
  45473. 0x40, 0xD8, 0x78, 0x31, 0x85, 0x43, 0xF6, 0xFE, 0x5C, 0xA6, 0x8F, 0x90, 0x09,
  45474. 0xB0, 0xE7, 0xC4, 0x95, 0xB2, 0x55, 0x49, 0x97, 0x8F, 0x1C, 0x78, 0x30, 0x20,
  45475. 0xA0, 0xB4, 0xEF, 0x73, 0x56, 0x59, 0x82, 0xFD, 0xCE, 0xBA, 0x6A, 0x8F, 0x2C,
  45476. 0x8B, 0x15, 0xFD, 0xA1, 0x85, 0xA8, 0x5C, 0x0F, 0x11, 0xA5, 0x9D, 0xC2, 0x46,
  45477. 0xC6, 0x9C, 0xC9, 0x40, 0x0B, 0x58, 0x6A, 0x1C, 0x7A, 0x23, 0xF9, 0xE0, 0x95,
  45478. 0x05, 0x13, 0x58, 0x72, 0xE8, 0x9F, 0x30, 0xAC, 0xCD, 0x26, 0xD4, 0x66, 0x13,
  45479. 0xDF, 0x1E, 0x7B, 0x4F, 0x9C, 0xBE, 0x38, 0x79, 0x75, 0x92, 0xA4, 0xDA, 0x26,
  45480. 0x44, 0x55, 0x17, 0xA3, 0xE5, 0x62, 0xDA, 0xEB, 0x86, 0xEA, 0x68, 0xC7, 0xAB,
  45481. 0xFD, 0x2D, 0x43, 0x59, 0x51, 0xC0, 0x75, 0x64, 0x91, 0x01, 0x29, 0x33, 0x28,
  45482. 0xF3, 0x04, 0x83, 0x80, 0x75, 0x37, 0x75, 0x0C, 0x03, 0x7B, 0x0A, 0xAB, 0x8E,
  45483. 0x60, 0x62, 0x8B, 0x4C, 0xAF, 0x2D, 0xA3, 0x2F, 0xFE, 0xAB, 0x45, 0xCF, 0xDA,
  45484. 0xAB, 0xFA, 0xFA, 0x30, 0x3D, 0xE8, 0xA1, 0x96, 0xA5, 0x7B, 0xE2, 0x2A, 0xD0,
  45485. 0xAF, 0x59, 0xF7, 0xD0, 0x32, 0x57, 0x19, 0xBD, 0xCA, 0x9F, 0xD5, 0x1A, 0xC7,
  45486. 0xAA, 0x65, 0x4A, 0x38, 0xB2, 0x70, 0x33, 0xB7, 0x75, 0xD2, 0xCD, 0xD1, 0xF0,
  45487. 0xA8, 0x87, 0x59, 0x20, 0xA5, 0x57, 0x55, 0xB1, 0xB2, 0xC9, 0x4D, 0x97, 0x34,
  45488. 0x41, 0xF3, 0xF0, 0x30, 0xA1, 0x2C, 0x1C, 0x49, 0x3E, 0x89, 0x7D, 0x12, 0xE2,
  45489. 0xC3, 0x04, 0xC3, 0x92, 0xC0, 0xF6, 0x39, 0x10, 0x80, 0x81, 0x8F, 0x08, 0xB4,
  45490. 0xF8, 0xB9, 0x13, 0x4E, 0x2C, 0xAE, 0xB3, 0x71, 0x82, 0x63, 0x98, 0xAB, 0x5C,
  45491. 0x1C, 0x10, 0xEA, 0x66, 0xF9, 0x02, 0x3A, 0x82, 0x61, 0xD0, 0xD4, 0xAE, 0x43,
  45492. 0xD4, 0x01, 0x3E, 0x9D, 0x04, 0x14, 0xF6, 0x60, 0xD8, 0xA7, 0xD6, 0xB8, 0x53,
  45493. 0xC8, 0xDA, 0x80, 0x93, 0xA0, 0x02, 0xDD, 0xCC, 0xE2, 0xF2, 0xBB, 0xFB, 0xE0,
  45494. 0x27, 0xD7, 0x34, 0x9A, 0x71, 0x49, 0xB5, 0x4F, 0x42, 0x1F, 0xB2, 0x9D, 0x6D,
  45495. 0xAA, 0x9D, 0xD3, 0x50, 0xB5, 0x8F, 0x6A, 0x4B, 0xDF, 0x1F, 0xD5, 0x27, 0x8F,
  45496. 0x3B, 0x27, 0xCF, 0x2F, 0x8C, 0xF8, 0x9D, 0x4C, 0x52, 0xBC, 0x32, 0x0F, 0x73,
  45497. 0xD5, 0x51, 0x8E, 0x36, 0x7E, 0xAD, 0x09, 0xF0, 0x94, 0x83, 0x5F, 0x36, 0xFD,
  45498. 0x7C, 0x03, 0xED, 0xF1, 0x5E, 0x4B, 0xF7, 0xAA, 0x55, 0x5C, 0x4A, 0x14, 0x59,
  45499. 0x85, 0x38, 0x2D, 0x8C, 0xDF, 0xEC, 0x65, 0x1B, 0xB8, 0x76, 0x57, 0x96, 0x3C,
  45500. 0x86, 0xED, 0xF2, 0x7F, 0x2D, 0x28, 0x48, 0xDA, 0x49, 0x7F, 0xF7, 0x54, 0x2B,
  45501. 0xD5, 0x39, 0xD5, 0x57, 0x0A, 0x75, 0x7A, 0x3E, 0x5E, 0x5D, 0xBA, 0x4A, 0x15,
  45502. 0xFA, 0xB8, 0x31, 0x80, 0x71, 0x2C, 0xCA, 0xC4, 0x51, 0x10, 0x16, 0x5D, 0x39,
  45503. 0xEC, 0x9D, 0x07, 0xB6, 0x6A, 0x89, 0x9F, 0x9B, 0x5B, 0x6F, 0x03, 0xB0, 0x92,
  45504. 0x01, 0x38, 0x6B, 0x48, 0x99, 0x0A, 0x8F, 0x13, 0xC1, 0xA6, 0x01, 0xEA, 0xBF,
  45505. 0x6F, 0x86, 0x43, 0x51, 0xB6, 0x11, 0x00, 0x00
  45506. };
  45507. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void)
  45508. {
  45509. wc_test_ret_t ret = 0;
  45510. word32 dSz = sizeof(sample_text);
  45511. word32 cSz = (dSz + (word32)(dSz * 0.001) + 12);
  45512. byte *c;
  45513. byte *d;
  45514. WOLFSSL_ENTER("compress_test");
  45515. c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45516. d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45517. if (c == NULL || d == NULL) {
  45518. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  45519. }
  45520. /* follow calloc and initialize to 0 */
  45521. XMEMSET(c, 0, cSz);
  45522. XMEMSET(d, 0, dSz);
  45523. if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) {
  45524. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45525. }
  45526. cSz = (word32)ret;
  45527. if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) {
  45528. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45529. }
  45530. dSz = (word32)ret;
  45531. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45532. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45533. }
  45534. /* GZIP tests */
  45535. cSz = (dSz + (word32)(dSz * 0.001) + 12); /* reset cSz */
  45536. XMEMSET(c, 0, cSz);
  45537. XMEMSET(d, 0, dSz);
  45538. ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP);
  45539. if (ret < 0)
  45540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45541. cSz = (word32)ret;
  45542. ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP);
  45543. if (ret < 0)
  45544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45545. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45546. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45547. }
  45548. /* Try with gzip generated output */
  45549. XMEMSET(d, 0, dSz);
  45550. ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz),
  45551. LIBZ_WINBITS_GZIP);
  45552. if (ret < 0)
  45553. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45554. dSz = (word32)ret;
  45555. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45556. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45557. }
  45558. ret = 0; /* success */
  45559. exit:
  45560. XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45561. XFREE(d, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45562. return ret;
  45563. }
  45564. #endif /* HAVE_LIBZ */
  45565. #ifdef HAVE_PKCS7
  45566. /* External Debugging/Testing Note:
  45567. *
  45568. * PKCS#7 test functions can output generated PKCS#7/CMS bundles for
  45569. * additional testing. To dump bundles to files DER encoded files, please
  45570. * define:
  45571. *
  45572. * #define PKCS7_OUTPUT_TEST_BUNDLES
  45573. */
  45574. /* Loads certs and keys for use with PKCS7 tests, from either files
  45575. * or buffers.
  45576. *
  45577. * rsaClientCertBuf - output buffer for RSA client cert
  45578. * rsaClientCertBufSz - IN/OUT size of output buffer, size of RSA client cert
  45579. * rsaClientPrivKeyBuf - output buffer for RSA client private key
  45580. * rsaClientPrivKeyBufSz - IN/OUT size of output buffer, size of RSA client key
  45581. *
  45582. * rsaServerCertBuf - output buffer for RSA server cert
  45583. * rsaServerCertBufSz - IN/OUT size of output buffer, size of RSA server cert
  45584. * rsaServerPrivKeyBuf - output buffer for RSA server private key
  45585. * rsaServerPrivKeyBufSz - IN/OUT size of output buffer, size of RSA server key
  45586. *
  45587. * rsaCaCertBuf - output buffer for RSA CA cert
  45588. * rsaCaCertBufSz - IN/OUT size of output buffer, size of RSA ca cert
  45589. * rsaCaPrivKeyBuf - output buffer for RSA CA private key
  45590. * rsaCaPrivKeyBufSz - IN/OUT size of output buffer, size of RSA CA key
  45591. *
  45592. * eccClientCertBuf - output buffer for ECC cert
  45593. * eccClientCertBufSz - IN/OUT size of output buffer, size of ECC cert
  45594. * eccClientPrivKeyBuf - output buffer for ECC private key
  45595. * eccClientPrivKeyBufSz - IN/OUT size of output buffer, size of ECC private key
  45596. *
  45597. * Returns 0 on success, negative on error
  45598. */
  45599. static wc_test_ret_t pkcs7_load_certs_keys(
  45600. byte* rsaClientCertBuf, word32* rsaClientCertBufSz,
  45601. byte* rsaClientPrivKeyBuf, word32* rsaClientPrivKeyBufSz,
  45602. byte* rsaServerCertBuf, word32* rsaServerCertBufSz,
  45603. byte* rsaServerPrivKeyBuf, word32* rsaServerPrivKeyBufSz,
  45604. byte* rsaCaCertBuf, word32* rsaCaCertBufSz,
  45605. byte* rsaCaPrivKeyBuf, word32* rsaCaPrivKeyBufSz,
  45606. byte* eccClientCertBuf, word32* eccClientCertBufSz,
  45607. byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz)
  45608. {
  45609. #ifndef NO_FILESYSTEM
  45610. XFILE certFile;
  45611. XFILE keyFile;
  45612. (void)certFile;
  45613. (void)keyFile;
  45614. #endif
  45615. #ifndef NO_RSA
  45616. if (rsaClientCertBuf == NULL || rsaClientCertBufSz == NULL ||
  45617. rsaClientPrivKeyBuf == NULL || rsaClientPrivKeyBufSz == NULL)
  45618. return BAD_FUNC_ARG;
  45619. #endif
  45620. #ifdef HAVE_ECC
  45621. if (eccClientCertBuf == NULL || eccClientCertBufSz == NULL ||
  45622. eccClientPrivKeyBuf == NULL || eccClientPrivKeyBufSz == NULL)
  45623. return BAD_FUNC_ARG;
  45624. #endif
  45625. /* RSA */
  45626. #ifndef NO_RSA
  45627. #ifdef USE_CERT_BUFFERS_1024
  45628. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024)
  45629. return WC_TEST_RET_ENC_NC;
  45630. XMEMCPY(rsaClientCertBuf, client_cert_der_1024,
  45631. sizeof_client_cert_der_1024);
  45632. *rsaClientCertBufSz = sizeof_client_cert_der_1024;
  45633. if (rsaServerCertBuf != NULL) {
  45634. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024)
  45635. return WC_TEST_RET_ENC_NC;
  45636. XMEMCPY(rsaServerCertBuf, server_cert_der_1024,
  45637. sizeof_server_cert_der_1024);
  45638. *rsaServerCertBufSz = sizeof_server_cert_der_1024;
  45639. }
  45640. if (rsaCaCertBuf != NULL) {
  45641. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024)
  45642. return WC_TEST_RET_ENC_NC;
  45643. XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  45644. *rsaCaCertBufSz = sizeof_ca_cert_der_1024;
  45645. }
  45646. #elif defined(USE_CERT_BUFFERS_2048)
  45647. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048)
  45648. return WC_TEST_RET_ENC_NC;
  45649. XMEMCPY(rsaClientCertBuf, client_cert_der_2048,
  45650. sizeof_client_cert_der_2048);
  45651. *rsaClientCertBufSz = sizeof_client_cert_der_2048;
  45652. if (rsaServerCertBuf != NULL) {
  45653. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048)
  45654. return WC_TEST_RET_ENC_NC;
  45655. XMEMCPY(rsaServerCertBuf, server_cert_der_2048,
  45656. sizeof_server_cert_der_2048);
  45657. *rsaServerCertBufSz = sizeof_server_cert_der_2048;
  45658. }
  45659. if (rsaCaCertBuf != NULL) {
  45660. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048)
  45661. return WC_TEST_RET_ENC_NC;
  45662. XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  45663. *rsaCaCertBufSz = sizeof_ca_cert_der_2048;
  45664. }
  45665. #else
  45666. certFile = XFOPEN(clientCert, "rb");
  45667. if (!certFile)
  45668. return WC_TEST_RET_ENC_ERRNO;
  45669. *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1,
  45670. *rsaClientCertBufSz, certFile);
  45671. XFCLOSE(certFile);
  45672. if (*rsaClientCertBufSz == 0)
  45673. return WC_TEST_RET_ENC_ERRNO;
  45674. if (rsaServerCertBuf != NULL) {
  45675. certFile = XFOPEN(rsaServerCertDerFile, "rb");
  45676. if (!certFile)
  45677. return WC_TEST_RET_ENC_ERRNO;
  45678. *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1,
  45679. *rsaServerCertBufSz, certFile);
  45680. XFCLOSE(certFile);
  45681. if (*rsaServerCertBufSz == 0)
  45682. return WC_TEST_RET_ENC_ERRNO;
  45683. }
  45684. if (rsaCaCertBuf != NULL) {
  45685. certFile = XFOPEN(rsaCaCertDerFile, "rb");
  45686. if (!certFile)
  45687. return WC_TEST_RET_ENC_ERRNO;
  45688. *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz,
  45689. certFile);
  45690. XFCLOSE(certFile);
  45691. if (*rsaCaCertBufSz == 0)
  45692. return WC_TEST_RET_ENC_ERRNO;
  45693. }
  45694. #endif
  45695. #ifdef USE_CERT_BUFFERS_1024
  45696. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024)
  45697. return WC_TEST_RET_ENC_NC;
  45698. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024,
  45699. sizeof_client_key_der_1024);
  45700. *rsaClientPrivKeyBufSz = sizeof_client_key_der_1024;
  45701. if (rsaServerPrivKeyBuf != NULL) {
  45702. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024)
  45703. return WC_TEST_RET_ENC_NC;
  45704. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024,
  45705. sizeof_server_key_der_1024);
  45706. *rsaServerPrivKeyBufSz = sizeof_server_key_der_1024;
  45707. }
  45708. if (rsaCaPrivKeyBuf != NULL) {
  45709. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024)
  45710. return WC_TEST_RET_ENC_NC;
  45711. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024);
  45712. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024;
  45713. }
  45714. #elif defined(USE_CERT_BUFFERS_2048)
  45715. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048)
  45716. return WC_TEST_RET_ENC_NC;
  45717. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048,
  45718. sizeof_client_key_der_2048);
  45719. *rsaClientPrivKeyBufSz = sizeof_client_key_der_2048;
  45720. if (rsaServerPrivKeyBuf != NULL) {
  45721. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048)
  45722. return WC_TEST_RET_ENC_NC;
  45723. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048,
  45724. sizeof_server_key_der_2048);
  45725. *rsaServerPrivKeyBufSz = sizeof_server_key_der_2048;
  45726. }
  45727. if (rsaCaPrivKeyBuf != NULL) {
  45728. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048)
  45729. return WC_TEST_RET_ENC_NC;
  45730. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048);
  45731. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048;
  45732. }
  45733. #else
  45734. keyFile = XFOPEN(clientKey, "rb");
  45735. if (!keyFile)
  45736. return WC_TEST_RET_ENC_ERRNO;
  45737. *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1,
  45738. *rsaClientPrivKeyBufSz, keyFile);
  45739. XFCLOSE(keyFile);
  45740. if (*rsaClientPrivKeyBufSz == 0)
  45741. return WC_TEST_RET_ENC_ERRNO;
  45742. if (rsaServerPrivKeyBuf != NULL) {
  45743. keyFile = XFOPEN(rsaServerKeyDerFile, "rb");
  45744. if (!keyFile)
  45745. return WC_TEST_RET_ENC_ERRNO;
  45746. *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1,
  45747. *rsaServerPrivKeyBufSz, keyFile);
  45748. XFCLOSE(keyFile);
  45749. if (*rsaServerPrivKeyBufSz == 0)
  45750. return WC_TEST_RET_ENC_ERRNO;
  45751. }
  45752. if (rsaCaPrivKeyBuf != NULL) {
  45753. keyFile = XFOPEN(rsaCaKeyFile, "rb");
  45754. if (!keyFile)
  45755. return WC_TEST_RET_ENC_ERRNO;
  45756. *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1,
  45757. *rsaCaPrivKeyBufSz, keyFile);
  45758. XFCLOSE(keyFile);
  45759. if (*rsaCaPrivKeyBufSz == 0)
  45760. return WC_TEST_RET_ENC_ERRNO;
  45761. }
  45762. #endif /* USE_CERT_BUFFERS */
  45763. #endif /* NO_RSA */
  45764. /* ECC */
  45765. #ifdef HAVE_ECC
  45766. #ifdef USE_CERT_BUFFERS_256
  45767. if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256)
  45768. return WC_TEST_RET_ENC_NC;
  45769. XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45770. *eccClientCertBufSz = sizeof_cliecc_cert_der_256;
  45771. #else
  45772. certFile = XFOPEN(eccClientCert, "rb");
  45773. if (!certFile)
  45774. return WC_TEST_RET_ENC_ERRNO;
  45775. *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1,
  45776. *eccClientCertBufSz, certFile);
  45777. XFCLOSE(certFile);
  45778. if (*eccClientCertBufSz == 0)
  45779. return WC_TEST_RET_ENC_ERRNO;
  45780. #endif /* USE_CERT_BUFFERS_256 */
  45781. #ifdef USE_CERT_BUFFERS_256
  45782. if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256)
  45783. return WC_TEST_RET_ENC_NC;
  45784. XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45785. *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256;
  45786. #else
  45787. keyFile = XFOPEN(eccClientKey, "rb");
  45788. if (!keyFile)
  45789. return WC_TEST_RET_ENC_ERRNO;
  45790. *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1,
  45791. *eccClientPrivKeyBufSz, keyFile);
  45792. XFCLOSE(keyFile);
  45793. if (*eccClientPrivKeyBufSz == 0)
  45794. return WC_TEST_RET_ENC_ERRNO;
  45795. #endif /* USE_CERT_BUFFERS_256 */
  45796. #endif /* HAVE_ECC */
  45797. #ifdef NO_RSA
  45798. (void)rsaClientCertBuf;
  45799. (void)rsaClientCertBufSz;
  45800. (void)rsaClientPrivKeyBuf;
  45801. (void)rsaClientPrivKeyBufSz;
  45802. (void)rsaServerCertBuf;
  45803. (void)rsaServerCertBufSz;
  45804. (void)rsaServerPrivKeyBuf;
  45805. (void)rsaServerPrivKeyBufSz;
  45806. (void)rsaCaCertBuf;
  45807. (void)rsaCaCertBufSz;
  45808. (void)rsaCaPrivKeyBuf;
  45809. (void)rsaCaPrivKeyBufSz;
  45810. #endif
  45811. #ifndef HAVE_ECC
  45812. (void)eccClientCertBuf;
  45813. (void)eccClientCertBufSz;
  45814. (void)eccClientPrivKeyBuf;
  45815. (void)eccClientPrivKeyBufSz;
  45816. #endif
  45817. #ifndef NO_FILESYSTEM
  45818. (void)certFile;
  45819. (void)keyFile;
  45820. #endif
  45821. return 0;
  45822. }
  45823. typedef struct {
  45824. const byte* content;
  45825. word32 contentSz;
  45826. int contentOID;
  45827. int encryptOID;
  45828. int keyWrapOID;
  45829. int keyAgreeOID;
  45830. byte* cert;
  45831. size_t certSz;
  45832. byte* privateKey;
  45833. word32 privateKeySz;
  45834. byte* optionalUkm;
  45835. word32 optionalUkmSz;
  45836. int ktriOptions; /* KTRI options flags */
  45837. int kariOptions; /* KARI options flags */
  45838. /* KEKRI specific */
  45839. const byte* secretKey; /* key, only for kekri RecipientInfo types */
  45840. word32 secretKeySz; /* size of secretKey, bytes */
  45841. const byte* secretKeyId; /* key identifier */
  45842. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45843. void* timePtr; /* time_t pointer */
  45844. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45845. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45846. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45847. word32 otherAttrSz; /* size of otherAttr, bytes */
  45848. int kekriOptions; /* KEKRI options flags */
  45849. /* PWRI specific */
  45850. const char* password;
  45851. word32 passwordSz;
  45852. const byte* salt;
  45853. word32 saltSz;
  45854. int kdfOID;
  45855. int hashOID;
  45856. int kdfIterations;
  45857. int pwriOptions; /* PWRI options flags */
  45858. /* ORI specific */
  45859. int isOri;
  45860. int oriOptions; /* ORI options flags */
  45861. const char* outFileName;
  45862. } pkcs7EnvelopedVector;
  45863. static const byte asnDataOid[] = {
  45864. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
  45865. };
  45866. /* ORI encrypt callback, responsible for encrypting content-encryption key (CEK)
  45867. * and giving wolfCrypt the value for oriOID and oriValue to place in
  45868. * OtherRecipientInfo.
  45869. *
  45870. * Returns 0 on success, negative upon error. */
  45871. static int myOriEncryptCb(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType,
  45872. word32* oriTypeSz, byte* oriValue, word32* oriValueSz,
  45873. void* ctx)
  45874. {
  45875. int i;
  45876. /* make sure buffers are large enough */
  45877. if (*oriValueSz < (2 + cekSz))
  45878. return WC_TEST_RET_ENC_NC;
  45879. if (*oriTypeSz < sizeof(asnDataOid))
  45880. return WC_TEST_RET_ENC_NC;
  45881. /* our simple encryption algorithm will be take the bitwise complement */
  45882. oriValue[0] = 0x04; /*ASN OCTET STRING */
  45883. oriValue[1] = (byte)cekSz; /* length */
  45884. for (i = 0; i < (int)cekSz; i++) {
  45885. oriValue[2 + i] = ~cek[i];
  45886. }
  45887. *oriValueSz = 2 + cekSz;
  45888. /* set oriType to ASN.1 encoded data OID */
  45889. XMEMCPY(oriType, asnDataOid, sizeof(asnDataOid));
  45890. *oriTypeSz = sizeof(asnDataOid);
  45891. (void)pkcs7;
  45892. (void)ctx;
  45893. return 0;
  45894. }
  45895. /* ORI decrypt callback, responsible for providing a decrypted content
  45896. * encryption key (CEK) placed into decryptedKey and size placed into
  45897. * decryptedKeySz. oriOID and oriValue are given to the callback to help
  45898. * in decrypting the encrypted CEK.
  45899. *
  45900. * Returns 0 on success, negative upon error. */
  45901. static int myOriDecryptCb(wc_PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  45902. byte* oriValue, word32 oriValueSz, byte* decryptedKey,
  45903. word32* decryptedKeySz, void* ctx)
  45904. {
  45905. int i;
  45906. /* make sure oriType matches what we expect */
  45907. if (oriTypeSz != sizeof(asnDataOid))
  45908. return WC_TEST_RET_ENC_NC;
  45909. if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0)
  45910. return WC_TEST_RET_ENC_NC;
  45911. /* make sure decrypted buffer is large enough */
  45912. if (*decryptedKeySz < oriValueSz)
  45913. return WC_TEST_RET_ENC_NC;
  45914. /* decrypt encrypted CEK using simple bitwise complement,
  45915. only for example */
  45916. for (i = 0; i < (int)oriValueSz - 2; i++) {
  45917. decryptedKey[i] = ~oriValue[2 + i];
  45918. }
  45919. *decryptedKeySz = oriValueSz - 2;
  45920. (void)pkcs7;
  45921. (void)ctx;
  45922. return 0;
  45923. }
  45924. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45925. /* returns 0 on success */
  45926. static int myDecryptionFunc(wc_PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45927. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45928. byte* in, int inSz, byte* out, void* usrCtx)
  45929. {
  45930. wc_test_ret_t ret;
  45931. int keyId = -1, keySz;
  45932. word32 keyIdSz = 8;
  45933. const byte* key;
  45934. byte keyIdRaw[8];
  45935. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45936. Aes *aes;
  45937. #else
  45938. Aes aes[1];
  45939. #endif
  45940. /* looking for KEY ID
  45941. * fwDecryptKeyID OID "1.2.840.113549.1.9.16.2.37
  45942. */
  45943. WOLFSSL_SMALL_STACK_STATIC const unsigned char OID[] = {
  45944. /* 0x06, 0x0B do not pass in tag and length */
  45945. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  45946. 0x01, 0x09, 0x10, 0x02, 0x25
  45947. };
  45948. WOLFSSL_SMALL_STACK_STATIC const byte defKey[] = {
  45949. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45950. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45951. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45952. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45953. };
  45954. WOLFSSL_SMALL_STACK_STATIC const byte altKey[] = {
  45955. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45956. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45957. };
  45958. /* test user context passed in */
  45959. if (usrCtx == NULL || *(int*)usrCtx != 1) {
  45960. return WC_TEST_RET_ENC_NC;
  45961. }
  45962. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45963. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  45964. return WC_TEST_RET_ENC_ERRNO;
  45965. #endif
  45966. /* if needing to find keyIdSz can call with NULL */
  45967. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), NULL,
  45968. &keyIdSz);
  45969. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  45970. printf("Unexpected error %d when getting keyIdSz\n", ret);
  45971. printf("Possibly no KEY ID attribute set\n");
  45972. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45973. }
  45974. else {
  45975. XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw));
  45976. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw,
  45977. &keyIdSz);
  45978. if (ret < 0) {
  45979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45980. }
  45981. if (keyIdSz < 3) {
  45982. printf("keyIdSz is smaller than expected\n");
  45983. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45984. }
  45985. if (keyIdSz > 2 + sizeof(int)) {
  45986. printf("example case was only expecting a keyId of int size\n");
  45987. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45988. }
  45989. /* keyIdRaw[0] OCTET TAG */
  45990. /* keyIdRaw[1] Length */
  45991. #ifdef BIG_ENDIAN_ORDER
  45992. if (keyIdRaw[1] == 0x01) {
  45993. keyId = 1;
  45994. }
  45995. #else
  45996. XMEMCPY(&keyId, keyIdRaw + 2, sizeof(keyId));
  45997. #endif
  45998. }
  45999. /* Use keyID here if found to select key and decrypt in HSM or in this
  46000. * example just select key and do software decryption */
  46001. if (keyId == 1) {
  46002. key = altKey;
  46003. keySz = sizeof(altKey);
  46004. }
  46005. else {
  46006. key = defKey;
  46007. keySz = sizeof(defKey);
  46008. }
  46009. switch (encryptOID) {
  46010. #ifdef WOLFSSL_AES_256
  46011. case AES256CBCb:
  46012. if ((keySz != 32 ) || (ivSz != AES_BLOCK_SIZE))
  46013. WARNING_OUT(BAD_FUNC_ARG, out);
  46014. break;
  46015. #endif
  46016. #ifdef WOLFSSL_AES_128
  46017. case AES128CBCb:
  46018. if ((keySz != 16 ) || (ivSz != AES_BLOCK_SIZE))
  46019. ERROR_OUT(BAD_FUNC_ARG, out);
  46020. break;
  46021. #endif
  46022. default:
  46023. printf("Unsupported content cipher type for example");
  46024. ERROR_OUT(ALGO_ID_E, out);
  46025. };
  46026. ret = wc_AesInit(aes, HEAP_HINT, INVALID_DEVID);
  46027. if (ret == 0) {
  46028. ret = wc_AesSetKey(aes, key, (word32)keySz, iv, AES_DECRYPTION);
  46029. if (ret == 0)
  46030. ret = wc_AesCbcDecrypt(aes, out, in, (word32)inSz);
  46031. wc_AesFree(aes);
  46032. }
  46033. out:
  46034. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  46035. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46036. #endif
  46037. (void)aad;
  46038. (void)aadSz;
  46039. (void)authTag;
  46040. (void)authTagSz;
  46041. return (int)ret;
  46042. }
  46043. #endif /* !NO_AES && HAVE_AES_CBC */
  46044. #define PKCS7_BUF_SIZE 2048
  46045. static wc_test_ret_t pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46046. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46047. byte* eccCert, word32 eccCertSz,
  46048. byte* eccPrivKey, word32 eccPrivKeySz)
  46049. {
  46050. wc_test_ret_t ret = 0;
  46051. int testSz = 0, i;
  46052. int envelopedSz, decodedSz;
  46053. byte *enveloped = NULL;
  46054. byte *decoded = NULL;
  46055. wc_PKCS7* pkcs7 = NULL;
  46056. #ifdef ECC_TIMING_RESISTANT
  46057. WC_RNG rng;
  46058. #endif
  46059. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46060. XFILE pkcs7File;
  46061. #endif
  46062. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46063. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46064. 0x72,0x6c,0x64
  46065. };
  46066. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256) && \
  46067. defined(HAVE_ECC) && defined(WOLFSSL_SHA512)
  46068. byte optionalUkm[] = {
  46069. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46070. };
  46071. #endif /* !NO_AES */
  46072. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  46073. !defined(NO_SHA)
  46074. /* encryption key for kekri recipient types */
  46075. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46076. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46077. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46078. };
  46079. /* encryption key identifier */
  46080. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46081. 0x02,0x02,0x03,0x04
  46082. };
  46083. #endif
  46084. #if !defined(NO_PWDBASED) && !defined(NO_SHA) && \
  46085. !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46086. #ifndef HAVE_FIPS
  46087. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password"; /* NOTE: Password is too short for FIPS */
  46088. #else
  46089. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46090. #endif
  46091. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46092. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46093. };
  46094. #endif
  46095. #define MAX_TESTVECTORS_LEN 13
  46096. #define ADD_PKCS7ENVELOPEDVECTOR(...) { \
  46097. pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46098. if (testSz == MAX_TESTVECTORS_LEN) { \
  46099. ret = WC_TEST_RET_ENC_NC; \
  46100. goto out; \
  46101. } \
  46102. XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\
  46103. }
  46104. pkcs7EnvelopedVector *testVectors = NULL;
  46105. #ifdef ECC_TIMING_RESISTANT
  46106. XMEMSET(&rng, 0, sizeof(rng));
  46107. #endif
  46108. testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46109. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46110. if (testVectors == NULL) {
  46111. ret = WC_TEST_RET_ENC_ERRNO;
  46112. goto out;
  46113. }
  46114. {
  46115. /* key transport key encryption technique */
  46116. #ifndef NO_RSA
  46117. #ifndef NO_DES3
  46118. ADD_PKCS7ENVELOPEDVECTOR(
  46119. data, (word32)sizeof(data), DATA, DES3b, 0, 0, rsaCert, rsaCertSz,
  46120. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46121. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46122. "pkcs7envelopedDataDES3.der");
  46123. #endif
  46124. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46125. #ifdef WOLFSSL_AES_128
  46126. ADD_PKCS7ENVELOPEDVECTOR(
  46127. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, rsaCert, rsaCertSz,
  46128. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46129. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46130. "pkcs7envelopedDataAES128CBC.der");
  46131. #endif
  46132. #ifdef WOLFSSL_AES_192
  46133. ADD_PKCS7ENVELOPEDVECTOR(
  46134. data, (word32)sizeof(data), DATA, AES192CBCb, 0, 0, rsaCert, rsaCertSz,
  46135. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46136. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46137. "pkcs7envelopedDataAES192CBC.der");
  46138. #endif
  46139. #ifdef WOLFSSL_AES_256
  46140. ADD_PKCS7ENVELOPEDVECTOR(
  46141. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46142. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46143. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46144. "pkcs7envelopedDataAES256CBC.der");
  46145. /* explicitly using SKID for SubjectKeyIdentifier */
  46146. ADD_PKCS7ENVELOPEDVECTOR(
  46147. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46148. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_SKID, 0, NULL, 0, NULL, 0, NULL,
  46149. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46150. "pkcs7envelopedDataAES256CBC_SKID.der");
  46151. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46152. ADD_PKCS7ENVELOPEDVECTOR(
  46153. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46154. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_ISSUER_AND_SERIAL_NUMBER, 0,
  46155. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46156. 0, 0, 0, 0, "pkcs7envelopedDataAES256CBC_IANDS.der");
  46157. #endif
  46158. #endif /* !NO_AES && HAVE_AES_CBC */
  46159. #endif
  46160. /* key agreement key encryption technique*/
  46161. #ifdef HAVE_ECC
  46162. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46163. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46164. ADD_PKCS7ENVELOPEDVECTOR(
  46165. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP,
  46166. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46167. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46168. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46169. "pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der");
  46170. #endif
  46171. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46172. ADD_PKCS7ENVELOPEDVECTOR(
  46173. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46174. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46175. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46176. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46177. "pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der");
  46178. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46179. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46180. ADD_PKCS7ENVELOPEDVECTOR(
  46181. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46182. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46183. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46184. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46185. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der");
  46186. /* with optional user keying material (ukm) */
  46187. ADD_PKCS7ENVELOPEDVECTOR(
  46188. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46189. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46190. eccPrivKeySz, optionalUkm, sizeof(optionalUkm), 0, 0, NULL, 0,
  46191. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46192. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF_ukm.der");
  46193. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46194. #endif /* !NO_AES && HAVE_AES_CBC */
  46195. #endif
  46196. /* kekri (KEKRecipientInfo) recipient types */
  46197. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46198. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46199. ADD_PKCS7ENVELOPEDVECTOR(
  46200. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP, 0,
  46201. NULL, 0, NULL, 0, NULL, 0, 0, 0, secretKey, sizeof(secretKey),
  46202. secretKeyId, sizeof(secretKeyId), NULL, NULL, 0, NULL, 0,
  46203. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46204. "pkcs7envelopedDataAES128CBC_KEKRI.der");
  46205. #endif
  46206. #endif /* !NO_AES && HAVE_AES_CBC */
  46207. /* pwri (PasswordRecipientInfo) recipient types */
  46208. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  46209. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46210. ADD_PKCS7ENVELOPEDVECTOR(
  46211. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0,
  46212. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46213. NULL, 0, NULL, NULL, 0, NULL, 0, 0, password,
  46214. (word32)XSTRLEN(password), salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46215. 0, 0, 0, "pkcs7envelopedDataAES128CBC_PWRI.der");
  46216. #endif
  46217. #endif
  46218. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_128)
  46219. /* ori (OtherRecipientInfo) recipient types */
  46220. ADD_PKCS7ENVELOPEDVECTOR(
  46221. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, NULL, 0, NULL, 0,
  46222. NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0,
  46223. NULL, 0, 0, 0, 0, 0, 1, 0, "pkcs7envelopedDataAES128CBC_ORI.der");
  46224. #endif
  46225. };
  46226. #undef MAX_TESTVECTORS_LEN
  46227. #undef ADD_PKCS7ENVELOPEDVECTOR
  46228. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46229. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46230. if ((! enveloped) || (! decoded)) {
  46231. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46232. }
  46233. #ifdef ECC_TIMING_RESISTANT
  46234. #ifndef HAVE_FIPS
  46235. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46236. #else
  46237. ret = wc_InitRng(&rng);
  46238. #endif
  46239. if (ret != 0)
  46240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46241. #endif
  46242. for (i = 0; i < testSz; i++) {
  46243. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46244. #ifdef WOLFSSL_ASYNC_CRYPT
  46245. INVALID_DEVID /* async PKCS7 is not supported */
  46246. #else
  46247. devId
  46248. #endif
  46249. );
  46250. if (pkcs7 == NULL) {
  46251. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46252. }
  46253. if (testVectors[i].secretKey != NULL) {
  46254. /* KEKRI recipient type */
  46255. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46256. if (ret != 0)
  46257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46258. pkcs7->content = (byte*)testVectors[i].content;
  46259. pkcs7->contentSz = testVectors[i].contentSz;
  46260. pkcs7->contentOID = testVectors[i].contentOID;
  46261. pkcs7->encryptOID = testVectors[i].encryptOID;
  46262. pkcs7->ukm = testVectors[i].optionalUkm;
  46263. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46264. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46265. (byte *)testVectors[i].secretKey, testVectors[i].secretKeySz,
  46266. (byte *)testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46267. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46268. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46269. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46270. if (ret < 0) {
  46271. wc_PKCS7_Free(pkcs7);
  46272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46273. }
  46274. /* set key, for decryption */
  46275. ret = wc_PKCS7_SetKey(pkcs7, (byte *)testVectors[i].secretKey,
  46276. testVectors[i].secretKeySz);
  46277. if (ret != 0) {
  46278. wc_PKCS7_Free(pkcs7);
  46279. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46280. }
  46281. } else if (testVectors[i].password != NULL) {
  46282. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46283. /* PWRI recipient type */
  46284. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46285. if (ret != 0)
  46286. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46287. pkcs7->content = (byte*)testVectors[i].content;
  46288. pkcs7->contentSz = testVectors[i].contentSz;
  46289. pkcs7->contentOID = testVectors[i].contentOID;
  46290. pkcs7->encryptOID = testVectors[i].encryptOID;
  46291. pkcs7->ukm = testVectors[i].optionalUkm;
  46292. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46293. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46294. (byte *)testVectors[i].password, testVectors[i].passwordSz,
  46295. (byte *)testVectors[i].salt, testVectors[i].saltSz,
  46296. testVectors[i].kdfOID,
  46297. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46298. testVectors[i].encryptOID, testVectors[i].pwriOptions);
  46299. if (ret < 0) {
  46300. wc_PKCS7_Free(pkcs7);
  46301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46302. }
  46303. /* set password, for decryption */
  46304. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46305. testVectors[i].passwordSz);
  46306. if (ret < 0) {
  46307. wc_PKCS7_Free(pkcs7);
  46308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46309. }
  46310. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46311. } else if (testVectors[i].isOri == 1) {
  46312. /* ORI recipient type */
  46313. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46314. if (ret != 0)
  46315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46316. pkcs7->content = (byte*)testVectors[i].content;
  46317. pkcs7->contentSz = testVectors[i].contentSz;
  46318. pkcs7->contentOID = testVectors[i].contentOID;
  46319. pkcs7->encryptOID = testVectors[i].encryptOID;
  46320. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46321. testVectors[i].oriOptions);
  46322. if (ret < 0) {
  46323. wc_PKCS7_Free(pkcs7);
  46324. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46325. }
  46326. /* set decrypt callback for decryption */
  46327. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46328. if (ret < 0) {
  46329. wc_PKCS7_Free(pkcs7);
  46330. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46331. }
  46332. } else {
  46333. /* KTRI or KARI recipient types */
  46334. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46335. if (ret != 0)
  46336. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46337. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46338. (word32)testVectors[i].certSz);
  46339. if (ret != 0) {
  46340. wc_PKCS7_Free(pkcs7);
  46341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46342. }
  46343. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46344. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46345. pkcs7->privateKey = testVectors[i].privateKey;
  46346. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46347. pkcs7->content = (byte*)testVectors[i].content;
  46348. pkcs7->contentSz = testVectors[i].contentSz;
  46349. pkcs7->contentOID = testVectors[i].contentOID;
  46350. pkcs7->encryptOID = testVectors[i].encryptOID;
  46351. pkcs7->ukm = testVectors[i].optionalUkm;
  46352. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46353. /* set SubjectIdentifier type for KTRI types */
  46354. if (testVectors[i].ktriOptions & CMS_SKID) {
  46355. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46356. if (ret != 0) {
  46357. wc_PKCS7_Free(pkcs7);
  46358. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46359. }
  46360. } else if (testVectors[i].ktriOptions &
  46361. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46362. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46363. CMS_ISSUER_AND_SERIAL_NUMBER);
  46364. if (ret != 0) {
  46365. wc_PKCS7_Free(pkcs7);
  46366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46367. }
  46368. }
  46369. }
  46370. #ifdef ECC_TIMING_RESISTANT
  46371. pkcs7->rng = &rng;
  46372. #endif
  46373. /* encode envelopedData */
  46374. envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, enveloped,
  46375. PKCS7_BUF_SIZE);
  46376. if (envelopedSz <= 0) {
  46377. wc_PKCS7_Free(pkcs7);
  46378. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46379. }
  46380. /* decode envelopedData */
  46381. pkcs7->contentOID = 0;
  46382. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, (word32)envelopedSz,
  46383. decoded, PKCS7_BUF_SIZE);
  46384. if (pkcs7->contentOID != testVectors[i].contentOID ||
  46385. decodedSz <= 0) {
  46386. wc_PKCS7_Free(pkcs7);
  46387. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46388. }
  46389. /* test decode result */
  46390. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46391. wc_PKCS7_Free(pkcs7);
  46392. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46393. }
  46394. #ifndef NO_PKCS7_STREAM
  46395. { /* test reading byte by byte */
  46396. int z;
  46397. for (z = 0; z < envelopedSz; z++) {
  46398. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped + z, 1,
  46399. decoded, PKCS7_BUF_SIZE);
  46400. if (decodedSz <= 0 &&
  46401. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46402. {
  46403. printf("unexpected error %d\n", decodedSz);
  46404. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46405. }
  46406. }
  46407. /* test decode result */
  46408. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46409. printf("stream read compare failed\n");
  46410. wc_PKCS7_Free(pkcs7);
  46411. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46412. }
  46413. }
  46414. #endif
  46415. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46416. /* output pkcs7 envelopedData for external testing */
  46417. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46418. if (!pkcs7File) {
  46419. wc_PKCS7_Free(pkcs7);
  46420. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46421. }
  46422. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46423. XFCLOSE(pkcs7File);
  46424. if (ret != envelopedSz) {
  46425. wc_PKCS7_Free(pkcs7);
  46426. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46427. } else {
  46428. /* reset ret to 0 for success */
  46429. ret = 0;
  46430. }
  46431. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46432. wc_PKCS7_Free(pkcs7);
  46433. pkcs7 = NULL;
  46434. }
  46435. #ifdef ECC_TIMING_RESISTANT
  46436. wc_FreeRng(&rng);
  46437. #endif
  46438. (void)eccCert;
  46439. (void)eccCertSz;
  46440. (void)eccPrivKey;
  46441. (void)eccPrivKeySz;
  46442. (void)rsaCert;
  46443. (void)rsaCertSz;
  46444. (void)rsaPrivKey;
  46445. (void)rsaPrivKeySz;
  46446. out:
  46447. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46448. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46449. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46450. return ret;
  46451. }
  46452. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void)
  46453. {
  46454. wc_test_ret_t ret = 0;
  46455. byte* rsaCert = NULL;
  46456. byte* rsaPrivKey = NULL;
  46457. word32 rsaCertSz = 0;
  46458. word32 rsaPrivKeySz = 0;
  46459. byte* eccCert = NULL;
  46460. byte* eccPrivKey = NULL;
  46461. word32 eccCertSz = 0;
  46462. word32 eccPrivKeySz = 0;
  46463. WOLFSSL_ENTER("pkcs7enveloped_test");
  46464. #ifndef NO_RSA
  46465. /* read client RSA cert and key in DER format */
  46466. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46467. if (rsaCert == NULL)
  46468. return WC_TEST_RET_ENC_ERRNO;
  46469. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46470. if (rsaPrivKey == NULL) {
  46471. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46472. return WC_TEST_RET_ENC_NC;
  46473. }
  46474. rsaCertSz = FOURK_BUF;
  46475. rsaPrivKeySz = FOURK_BUF;
  46476. #endif /* NO_RSA */
  46477. #ifdef HAVE_ECC
  46478. /* read client ECC cert and key in DER format */
  46479. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46480. if (eccCert == NULL) {
  46481. #ifndef NO_RSA
  46482. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46483. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46484. #endif
  46485. return WC_TEST_RET_ENC_NC;
  46486. }
  46487. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46488. if (eccPrivKey == NULL) {
  46489. #ifndef NO_RSA
  46490. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46491. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46492. #endif
  46493. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46494. return WC_TEST_RET_ENC_NC;
  46495. }
  46496. eccCertSz = FOURK_BUF;
  46497. eccPrivKeySz = FOURK_BUF;
  46498. #endif /* HAVE_ECC */
  46499. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46500. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46501. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46502. eccPrivKey, &eccPrivKeySz);
  46503. if (ret < 0) {
  46504. #ifndef NO_RSA
  46505. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46506. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46507. #endif
  46508. #ifdef HAVE_ECC
  46509. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46510. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46511. #endif
  46512. return WC_TEST_RET_ENC_EC(ret);
  46513. }
  46514. ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46515. rsaPrivKey, (word32)rsaPrivKeySz,
  46516. eccCert, (word32)eccCertSz,
  46517. eccPrivKey, (word32)eccPrivKeySz);
  46518. #ifndef NO_RSA
  46519. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46520. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46521. #endif
  46522. #ifdef HAVE_ECC
  46523. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46524. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46525. #endif
  46526. return ret;
  46527. }
  46528. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  46529. typedef struct {
  46530. const byte* content;
  46531. word32 contentSz;
  46532. int contentOID;
  46533. int encryptOID;
  46534. int keyWrapOID;
  46535. int keyAgreeOID;
  46536. byte* cert;
  46537. size_t certSz;
  46538. byte* privateKey;
  46539. word32 privateKeySz;
  46540. PKCS7Attrib* authAttribs;
  46541. word32 authAttribsSz;
  46542. PKCS7Attrib* unauthAttribs;
  46543. word32 unauthAttribsSz;
  46544. /* KARI / KTRI specific */
  46545. byte* optionalUkm;
  46546. word32 optionalUkmSz;
  46547. int ktriOptions; /* KTRI options flags */
  46548. int kariOptions; /* KARI options flags */
  46549. /* KEKRI specific */
  46550. byte* secretKey; /* key, only for kekri RecipientInfo types */
  46551. word32 secretKeySz; /* size of secretKey, bytes */
  46552. byte* secretKeyId; /* key identifier */
  46553. word32 secretKeyIdSz; /* size of key identifier, bytes */
  46554. void* timePtr; /* time_t pointer */
  46555. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  46556. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  46557. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  46558. word32 otherAttrSz; /* size of otherAttr, bytes */
  46559. int kekriOptions; /* KEKRI options flags */
  46560. /* PWRI specific */
  46561. char* password; /* password */
  46562. word32 passwordSz; /* password size, bytes */
  46563. byte* salt; /* KDF salt */
  46564. word32 saltSz; /* KDF salt size, bytes */
  46565. int kdfOID; /* KDF OID */
  46566. int hashOID; /* KDF hash algorithm OID */
  46567. int kdfIterations; /* KDF iterations */
  46568. int kekEncryptOID; /* KEK encryption algorithm OID */
  46569. int pwriOptions; /* PWRI options flags */
  46570. /* ORI specific */
  46571. int isOri;
  46572. int oriOptions; /* ORI options flags */
  46573. const char* outFileName;
  46574. } pkcs7AuthEnvelopedVector;
  46575. static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46576. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46577. byte* eccCert, word32 eccCertSz,
  46578. byte* eccPrivKey, word32 eccPrivKeySz)
  46579. {
  46580. wc_test_ret_t ret = 0;
  46581. int testSz = 0, i;
  46582. int envelopedSz, decodedSz;
  46583. byte *enveloped = NULL;
  46584. byte *decoded = NULL;
  46585. WC_RNG rng;
  46586. wc_PKCS7* pkcs7;
  46587. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46588. XFILE pkcs7File;
  46589. #endif
  46590. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46591. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46592. 0x72,0x6c,0x64
  46593. };
  46594. byte senderNonce[PKCS7_NONCE_SZ + 2];
  46595. #ifdef HAVE_ECC
  46596. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46597. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46598. WOLFSSL_SMALL_STACK_STATIC const byte senderNonceOid[] =
  46599. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  46600. 0x09, 0x05 };
  46601. PKCS7Attrib attribs[] =
  46602. {
  46603. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  46604. sizeof(senderNonce) }
  46605. };
  46606. #endif
  46607. #endif
  46608. #endif
  46609. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \
  46610. defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM)
  46611. WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = {
  46612. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46613. };
  46614. #endif /* !NO_AES */
  46615. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46616. /* encryption key for kekri recipient types */
  46617. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46618. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46619. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46620. };
  46621. /* encryption key identifier */
  46622. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46623. 0x02,0x02,0x03,0x04
  46624. };
  46625. #endif
  46626. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  46627. !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46628. #ifndef HAVE_FIPS
  46629. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password";
  46630. #else
  46631. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46632. #endif
  46633. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46634. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46635. };
  46636. #endif
  46637. #define MAX_TESTVECTORS_LEN 20
  46638. #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \
  46639. pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46640. if (testSz == MAX_TESTVECTORS_LEN) { \
  46641. ret = WC_TEST_RET_ENC_NC; \
  46642. goto out; \
  46643. } \
  46644. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  46645. sizeof _this_vector); \
  46646. }
  46647. pkcs7AuthEnvelopedVector *testVectors = NULL;
  46648. XMEMSET(&rng, 0, sizeof(rng));
  46649. testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46650. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46651. if (testVectors == NULL) {
  46652. ret = WC_TEST_RET_ENC_ERRNO;
  46653. goto out;
  46654. }
  46655. {
  46656. /* key transport key encryption technique */
  46657. #ifndef NO_RSA
  46658. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46659. #ifdef WOLFSSL_AES_128
  46660. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46661. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, rsaCert, rsaCertSz,
  46662. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46663. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46664. 0, 0, "pkcs7authEnvelopedDataAES128GCM.der");
  46665. #endif
  46666. #ifdef WOLFSSL_AES_192
  46667. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46668. data, (word32)sizeof(data), DATA, AES192GCMb, 0, 0, rsaCert, rsaCertSz,
  46669. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46670. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46671. 0, 0, "pkcs7authEnvelopedDataAES192GCM.der");
  46672. #endif
  46673. #ifdef WOLFSSL_AES_256
  46674. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46675. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46676. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46677. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46678. 0, 0, "pkcs7authEnvelopedDataAES256GCM.der");
  46679. /* test with contentType set to FirmwarePkgData */
  46680. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46681. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, 0, 0,
  46682. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL,
  46683. 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL,
  46684. 0, 0, 0, 0, 0, 0, 0, 0,
  46685. "pkcs7authEnvelopedDataAES256GCM_firmwarePkgData.der");
  46686. /* explicitly using SKID for SubjectKeyIdentifier */
  46687. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46688. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46689. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, CMS_SKID, 0,
  46690. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46691. 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_SKID.der");
  46692. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46693. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46694. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46695. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0,
  46696. CMS_ISSUER_AND_SERIAL_NUMBER, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46697. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46698. "pkcs7authEnvelopedDataAES256GCM_IANDS.der");
  46699. #endif
  46700. #else
  46701. (void)rsaCert;
  46702. (void)rsaCertSz;
  46703. (void)rsaPrivKey;
  46704. (void)rsaPrivKeySz;
  46705. #endif /* !NO_AES && !HAVE_AESGCM */
  46706. #endif
  46707. /* key agreement key encryption technique*/
  46708. #ifdef HAVE_ECC
  46709. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46710. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46711. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46712. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP,
  46713. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46714. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46715. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46716. "pkcs7authEnvelopedDataAES128GCM_ECDH_SHA1KDF.der");
  46717. #endif
  46718. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46719. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46720. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46721. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46722. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46723. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46724. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF.der");
  46725. /* with authenticated attributes */
  46726. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46727. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46728. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46729. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46730. NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46731. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46732. 0, 0, 0,
  46733. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_authAttribs.der");
  46734. /* with unauthenticated attributes */
  46735. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46736. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46737. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46738. eccPrivKeySz, NULL, 0, attribs,
  46739. (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0, NULL, 0,
  46740. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46741. 0, 0, 0,
  46742. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_unauthAttribs.der");
  46743. /* with authenticated AND unauthenticated attributes */
  46744. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46745. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46746. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46747. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46748. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46749. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46750. 0, 0, 0, 0, 0, 0,
  46751. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_bothAttribs.der");
  46752. /* with authenticated AND unauthenticated attributes AND
  46753. * contentType of FirmwarePkgData */
  46754. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46755. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, AES256_WRAP,
  46756. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46757. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46758. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46759. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46760. 0, 0, 0, 0, 0, 0,
  46761. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_fw_bothAttribs.der");
  46762. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46763. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46764. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46765. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46766. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46767. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL,
  46768. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46769. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF.der");
  46770. /* with optional user keying material (ukm) */
  46771. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46772. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46773. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46774. eccPrivKeySz, NULL, 0, NULL, 0, (byte *)optionalUkm, sizeof(optionalUkm), 0,
  46775. 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46776. 0, 0, 0, 0, 0, 0,
  46777. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF_ukm.der");
  46778. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46779. #endif /* !NO_AES && HAVE_AESGCM */
  46780. #endif
  46781. /* kekri (KEKRecipientInfo) recipient types */
  46782. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46783. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46784. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46785. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP, 0,
  46786. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0,
  46787. (byte *)secretKey, sizeof(secretKey), (byte *)secretKeyId, sizeof(secretKeyId),
  46788. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46789. "pkcs7authEnvelopedDataAES128GCM_KEKRI.der");
  46790. #endif
  46791. #endif
  46792. /* pwri (PasswordRecipientInfo) recipient types */
  46793. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM)
  46794. #if !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46795. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46796. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0,
  46797. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46798. NULL, 0, NULL, NULL, 0, NULL, 0, 0, (char *)password,
  46799. (word32)XSTRLEN(password), (byte *)salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46800. AES128CBCb, 0, 0, 0, "pkcs7authEnvelopedDataAES128GCM_PWRI.der");
  46801. #endif
  46802. #endif
  46803. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46804. #ifdef WOLFSSL_AES_128
  46805. /* ori (OtherRecipientInfo) recipient types */
  46806. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46807. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, NULL, 0, NULL, 0,
  46808. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46809. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0,
  46810. "pkcs7authEnvelopedDataAES128GCM_ORI.der");
  46811. #endif
  46812. #endif
  46813. }
  46814. #undef MAX_TESTVECTORS_LEN
  46815. #undef ADD_PKCS7AUTHENVELOPEDVECTOR
  46816. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46817. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46818. if ((! enveloped) || (! decoded)) {
  46819. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46820. }
  46821. /* generate senderNonce */
  46822. {
  46823. #ifndef HAVE_FIPS
  46824. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46825. #else
  46826. ret = wc_InitRng(&rng);
  46827. #endif
  46828. if (ret != 0)
  46829. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46830. senderNonce[0] = 0x04;
  46831. senderNonce[1] = PKCS7_NONCE_SZ;
  46832. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  46833. if (ret != 0) {
  46834. wc_FreeRng(&rng);
  46835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46836. }
  46837. }
  46838. for (i = 0; i < testSz; i++) {
  46839. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46840. #ifdef WOLFSSL_ASYNC_CRYPT
  46841. INVALID_DEVID /* async PKCS7 is not supported */
  46842. #else
  46843. devId
  46844. #endif
  46845. );
  46846. if (pkcs7 == NULL) {
  46847. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46848. }
  46849. if (testVectors[i].secretKey != NULL) {
  46850. /* KEKRI recipient type */
  46851. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46852. if (ret != 0)
  46853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46854. pkcs7->content = (byte*)testVectors[i].content;
  46855. pkcs7->contentSz = testVectors[i].contentSz;
  46856. pkcs7->contentOID = testVectors[i].contentOID;
  46857. pkcs7->encryptOID = testVectors[i].encryptOID;
  46858. pkcs7->ukm = testVectors[i].optionalUkm;
  46859. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46860. pkcs7->authAttribs = testVectors[i].authAttribs;
  46861. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46862. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46863. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46864. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46865. testVectors[i].secretKey, testVectors[i].secretKeySz,
  46866. testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46867. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46868. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46869. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46870. if (ret < 0) {
  46871. wc_PKCS7_Free(pkcs7);
  46872. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46873. }
  46874. /* set key, for decryption */
  46875. ret = wc_PKCS7_SetKey(pkcs7, testVectors[i].secretKey,
  46876. testVectors[i].secretKeySz);
  46877. if (ret != 0) {
  46878. wc_PKCS7_Free(pkcs7);
  46879. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46880. }
  46881. } else if (testVectors[i].password != NULL) {
  46882. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46883. /* PWRI recipient type */
  46884. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46885. if (ret != 0)
  46886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46887. pkcs7->content = (byte*)testVectors[i].content;
  46888. pkcs7->contentSz = testVectors[i].contentSz;
  46889. pkcs7->contentOID = testVectors[i].contentOID;
  46890. pkcs7->encryptOID = testVectors[i].encryptOID;
  46891. pkcs7->ukm = testVectors[i].optionalUkm;
  46892. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46893. pkcs7->authAttribs = testVectors[i].authAttribs;
  46894. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46895. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46896. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46897. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46898. (byte*)testVectors[i].password,
  46899. testVectors[i].passwordSz, testVectors[i].salt,
  46900. testVectors[i].saltSz, testVectors[i].kdfOID,
  46901. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46902. testVectors[i].kekEncryptOID, testVectors[i].pwriOptions);
  46903. if (ret < 0) {
  46904. wc_PKCS7_Free(pkcs7);
  46905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46906. }
  46907. /* set password, for decryption */
  46908. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46909. testVectors[i].passwordSz);
  46910. if (ret < 0) {
  46911. wc_PKCS7_Free(pkcs7);
  46912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46913. }
  46914. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46915. } else if (testVectors[i].isOri == 1) {
  46916. /* ORI recipient type */
  46917. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46918. if (ret != 0)
  46919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46920. pkcs7->content = (byte*)testVectors[i].content;
  46921. pkcs7->contentSz = testVectors[i].contentSz;
  46922. pkcs7->contentOID = testVectors[i].contentOID;
  46923. pkcs7->encryptOID = testVectors[i].encryptOID;
  46924. pkcs7->authAttribs = testVectors[i].authAttribs;
  46925. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46926. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46927. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46928. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46929. testVectors[i].oriOptions);
  46930. if (ret < 0) {
  46931. wc_PKCS7_Free(pkcs7);
  46932. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46933. }
  46934. /* set decrypt callback for decryption */
  46935. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46936. if (ret < 0) {
  46937. wc_PKCS7_Free(pkcs7);
  46938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46939. }
  46940. } else {
  46941. /* KTRI or KARI recipient types */
  46942. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46943. (word32)testVectors[i].certSz);
  46944. if (ret != 0) {
  46945. wc_PKCS7_Free(pkcs7);
  46946. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46947. }
  46948. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46949. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46950. pkcs7->privateKey = testVectors[i].privateKey;
  46951. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46952. pkcs7->content = (byte*)testVectors[i].content;
  46953. pkcs7->contentSz = testVectors[i].contentSz;
  46954. pkcs7->contentOID = testVectors[i].contentOID;
  46955. pkcs7->encryptOID = testVectors[i].encryptOID;
  46956. pkcs7->ukm = testVectors[i].optionalUkm;
  46957. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46958. pkcs7->authAttribs = testVectors[i].authAttribs;
  46959. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46960. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46961. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46962. /* set SubjectIdentifier type for KTRI types */
  46963. if (testVectors[i].ktriOptions & CMS_SKID) {
  46964. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46965. if (ret != 0) {
  46966. wc_PKCS7_Free(pkcs7);
  46967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46968. }
  46969. } else if (testVectors[i].ktriOptions &
  46970. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46971. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46972. CMS_ISSUER_AND_SERIAL_NUMBER);
  46973. if (ret != 0) {
  46974. wc_PKCS7_Free(pkcs7);
  46975. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46976. }
  46977. }
  46978. }
  46979. #ifdef ECC_TIMING_RESISTANT
  46980. pkcs7->rng = &rng;
  46981. #endif
  46982. /* encode envelopedData */
  46983. envelopedSz = wc_PKCS7_EncodeAuthEnvelopedData(pkcs7, enveloped,
  46984. PKCS7_BUF_SIZE);
  46985. if (envelopedSz <= 0) {
  46986. wc_PKCS7_Free(pkcs7);
  46987. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46988. }
  46989. #ifndef NO_PKCS7_STREAM
  46990. { /* test reading byte by byte */
  46991. int z;
  46992. for (z = 0; z < envelopedSz; z++) {
  46993. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7,
  46994. enveloped + z, 1, decoded, PKCS7_BUF_SIZE);
  46995. if (decodedSz <= 0 &&
  46996. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46997. {
  46998. printf("unexpected error %d\n", decodedSz);
  46999. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47000. }
  47001. }
  47002. /* test decode result */
  47003. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47004. printf("stream read compare failed\n");
  47005. wc_PKCS7_Free(pkcs7);
  47006. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47007. }
  47008. }
  47009. #endif
  47010. /* decode envelopedData */
  47011. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, enveloped,
  47012. (word32)envelopedSz, decoded,
  47013. PKCS7_BUF_SIZE);
  47014. if (decodedSz <= 0) {
  47015. wc_PKCS7_Free(pkcs7);
  47016. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47017. }
  47018. /* test decode result */
  47019. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  47020. wc_PKCS7_Free(pkcs7);
  47021. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47022. }
  47023. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47024. /* output pkcs7 envelopedData for external testing */
  47025. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47026. if (!pkcs7File) {
  47027. wc_PKCS7_Free(pkcs7);
  47028. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47029. }
  47030. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  47031. XFCLOSE(pkcs7File);
  47032. if (ret != envelopedSz) {
  47033. wc_PKCS7_Free(pkcs7);
  47034. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47035. } else {
  47036. /* reset ret to 0 for success */
  47037. ret = 0;
  47038. }
  47039. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47040. wc_PKCS7_Free(pkcs7);
  47041. pkcs7 = NULL;
  47042. }
  47043. wc_FreeRng(&rng);
  47044. (void)eccCert;
  47045. (void)eccCertSz;
  47046. (void)eccPrivKey;
  47047. (void)eccPrivKeySz;
  47048. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  47049. (void)secretKey;
  47050. (void)secretKeyId;
  47051. #endif
  47052. #ifdef NO_RSA
  47053. (void)rsaCert;
  47054. (void)rsaCertSz;
  47055. (void)rsaPrivKey;
  47056. (void)rsaPrivKeySz;
  47057. #endif
  47058. out:
  47059. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47060. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47061. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47062. return ret;
  47063. }
  47064. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void)
  47065. {
  47066. wc_test_ret_t ret = 0;
  47067. byte* rsaCert = NULL;
  47068. byte* rsaPrivKey = NULL;
  47069. word32 rsaCertSz = 0;
  47070. word32 rsaPrivKeySz = 0;
  47071. byte* eccCert = NULL;
  47072. byte* eccPrivKey = NULL;
  47073. word32 eccCertSz = 0;
  47074. word32 eccPrivKeySz = 0;
  47075. WOLFSSL_ENTER("pkcs7authenveloped_test");
  47076. #ifndef NO_RSA
  47077. /* read client RSA cert and key in DER format */
  47078. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47079. if (rsaCert == NULL)
  47080. return WC_TEST_RET_ENC_ERRNO;
  47081. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47082. if (rsaPrivKey == NULL) {
  47083. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47084. return WC_TEST_RET_ENC_NC;
  47085. }
  47086. rsaCertSz = FOURK_BUF;
  47087. rsaPrivKeySz = FOURK_BUF;
  47088. #endif /* NO_RSA */
  47089. #ifdef HAVE_ECC
  47090. /* read client ECC cert and key in DER format */
  47091. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47092. if (eccCert == NULL) {
  47093. #ifndef NO_RSA
  47094. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47095. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47096. #endif
  47097. return WC_TEST_RET_ENC_NC;
  47098. }
  47099. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47100. if (eccPrivKey == NULL) {
  47101. #ifndef NO_RSA
  47102. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47103. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47104. #endif
  47105. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47106. return WC_TEST_RET_ENC_NC;
  47107. }
  47108. eccCertSz = FOURK_BUF;
  47109. eccPrivKeySz = FOURK_BUF;
  47110. #endif /* HAVE_ECC */
  47111. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  47112. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  47113. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  47114. eccPrivKey, &eccPrivKeySz);
  47115. if (ret < 0) {
  47116. #ifndef NO_RSA
  47117. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47118. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47119. #endif
  47120. #ifdef HAVE_ECC
  47121. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47122. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47123. #endif
  47124. return WC_TEST_RET_ENC_EC(ret);
  47125. }
  47126. ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  47127. rsaPrivKey, (word32)rsaPrivKeySz,
  47128. eccCert, (word32)eccCertSz,
  47129. eccPrivKey, (word32)eccPrivKeySz);
  47130. #ifndef NO_RSA
  47131. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47132. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47133. #endif
  47134. #ifdef HAVE_ECC
  47135. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47136. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47137. #endif
  47138. return ret;
  47139. }
  47140. #endif /* HAVE_AESGCM || HAVE_AESCCM */
  47141. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47142. static const byte p7DefKey[] = {
  47143. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47144. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47145. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47146. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47147. };
  47148. static const byte p7AltKey[] = {
  47149. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47150. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47151. };
  47152. static int myCEKwrapFunc(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  47153. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  47154. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  47155. {
  47156. wc_test_ret_t ret;
  47157. if (cek == NULL || out == NULL)
  47158. return BAD_FUNC_ARG;
  47159. /* test case sanity checks */
  47160. if (keyIdSz != 1) {
  47161. return WC_TEST_RET_ENC_NC;
  47162. }
  47163. if (keyId[0] != 0x00) {
  47164. return WC_TEST_RET_ENC_NC;
  47165. }
  47166. if (type != (int)PKCS7_KEKRI) {
  47167. return WC_TEST_RET_ENC_NC;
  47168. }
  47169. switch (keyWrapAlgo) {
  47170. case AES256_WRAP:
  47171. ret = wc_AesKeyUnWrap(p7DefKey, sizeof(p7DefKey), cek, cekSz,
  47172. out, outSz, NULL);
  47173. if (ret <= 0)
  47174. return (int)ret;
  47175. break;
  47176. default:
  47177. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  47178. return BAD_KEYWRAP_ALG_E;
  47179. };
  47180. (void)pkcs7;
  47181. (void)direction;
  47182. (void)orginKey; /* used with KAKRI */
  47183. (void)orginKeySz;
  47184. return (int)ret;
  47185. }
  47186. /* returns key size on success */
  47187. static wc_test_ret_t getFirmwareKey(wc_PKCS7* pkcs7, byte* key, word32 keySz)
  47188. {
  47189. wc_test_ret_t ret;
  47190. word32 atrSz;
  47191. byte atr[256];
  47192. /* Additionally can look for fwWrappedFirmwareKey
  47193. * 1.2.840.113529.1.9.16.1.16 */
  47194. const unsigned char fwWrappedFirmwareKey[] = {
  47195. /* 0x06, 0x0B */
  47196. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47197. 0x01, 0x09, 0x10, 0x02, 0x27
  47198. };
  47199. /* find keyID in fwWrappedFirmwareKey */
  47200. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47201. sizeof(fwWrappedFirmwareKey), NULL, &atrSz);
  47202. if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  47203. XMEMSET(atr, 0, sizeof(atr));
  47204. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47205. sizeof(fwWrappedFirmwareKey), atr, &atrSz);
  47206. /* keyIdRaw[0] OCTET TAG */
  47207. /* keyIdRaw[1] Length */
  47208. if (ret > 0) {
  47209. wc_PKCS7* envPkcs7;
  47210. envPkcs7 = wc_PKCS7_New(NULL, 0);
  47211. if (envPkcs7 == NULL) {
  47212. return MEMORY_E;
  47213. }
  47214. wc_PKCS7_Init(envPkcs7, NULL, 0);
  47215. ret = wc_PKCS7_SetWrapCEKCb(envPkcs7, myCEKwrapFunc);
  47216. if (ret == 0) {
  47217. /* expecting FIRMWARE_PKG_DATA content */
  47218. envPkcs7->contentOID = FIRMWARE_PKG_DATA;
  47219. ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
  47220. key, keySz);
  47221. if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
  47222. /* the contentOID should have been set to the inner
  47223. * FIRMWARE_PKG_DATA content */
  47224. ret = BAD_STATE_E;
  47225. }
  47226. }
  47227. wc_PKCS7_Free(envPkcs7);
  47228. }
  47229. }
  47230. return ret;
  47231. }
  47232. /* create a KEKRI enveloped data
  47233. * return size on success */
  47234. static wc_test_ret_t envelopedData_encrypt(byte* in, word32 inSz, byte* out,
  47235. word32 outSz)
  47236. {
  47237. wc_test_ret_t ret;
  47238. wc_PKCS7* pkcs7;
  47239. WOLFSSL_SMALL_STACK_STATIC const byte keyId[] = { 0x00 };
  47240. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47241. if (pkcs7 == NULL)
  47242. return WC_TEST_RET_ENC_ERRNO;
  47243. pkcs7->content = in;
  47244. pkcs7->contentSz = inSz;
  47245. pkcs7->contentOID = FIRMWARE_PKG_DATA;
  47246. pkcs7->encryptOID = AES256CBCb;
  47247. pkcs7->ukm = NULL;
  47248. pkcs7->ukmSz = 0;
  47249. /* add recipient (KEKRI type) */
  47250. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP, (byte*)p7DefKey,
  47251. sizeof(p7DefKey), (byte*)keyId,
  47252. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0);
  47253. if (ret < 0) {
  47254. printf("wc_PKCS7_AddRecipient_KEKRI() failed\n");
  47255. wc_PKCS7_Free(pkcs7);
  47256. return WC_TEST_RET_ENC_EC(ret);
  47257. }
  47258. /* encode envelopedData, returns size */
  47259. ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
  47260. if (ret <= 0) {
  47261. printf("wc_PKCS7_EncodeEnvelopedData() failed\n");
  47262. wc_PKCS7_Free(pkcs7);
  47263. return WC_TEST_RET_ENC_EC(ret);
  47264. }
  47265. wc_PKCS7_Free(pkcs7);
  47266. return ret;
  47267. }
  47268. /*
  47269. * keyHint is the KeyID to be set in the fwDecryptKeyID attribute
  47270. * returns size of buffer output on success
  47271. */
  47272. static wc_test_ret_t generateBundle(byte* out, word32 *outSz, const byte* encryptKey,
  47273. word32 encryptKeySz, byte keyHint, byte* cert, word32 certSz,
  47274. byte* key, word32 keySz)
  47275. {
  47276. wc_test_ret_t ret;
  47277. int attribNum = 1;
  47278. wc_PKCS7* pkcs7;
  47279. /* KEY ID
  47280. * fwDecryptKeyID OID 1.2.840.113549.1.9.16.2.37
  47281. */
  47282. const unsigned char fwDecryptKeyID[] = {
  47283. 0x06, 0x0B,
  47284. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47285. 0x01, 0x09, 0x10, 0x02, 0x25
  47286. };
  47287. /* fwWrappedFirmwareKey 1.2.840.113529.1.9.16.1.16 */
  47288. const unsigned char fwWrappedFirmwareKey[] = {
  47289. 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47290. 0x01, 0x09, 0x10, 0x02, 0x27
  47291. };
  47292. byte keyID[] = { 0x04, 0x01, 0x00 };
  47293. byte env[256];
  47294. char data[] = "Test of wolfSSL PKCS7 decrypt callback";
  47295. PKCS7Attrib attribs[] =
  47296. {
  47297. { fwDecryptKeyID, sizeof(fwDecryptKeyID), keyID, sizeof(keyID) },
  47298. { fwWrappedFirmwareKey, sizeof(fwWrappedFirmwareKey), env, 0 }
  47299. };
  47300. keyID[2] = keyHint;
  47301. /* If using keyHint 0 then create a bundle with fwWrappedFirmwareKey */
  47302. if (keyHint == 0) {
  47303. ret = envelopedData_encrypt((byte*)p7DefKey, sizeof(p7DefKey), env,
  47304. sizeof(env));
  47305. if (ret <= 0) {
  47306. return ret;
  47307. }
  47308. attribs[1].valueSz = (word32)ret;
  47309. attribNum++;
  47310. }
  47311. /* init PKCS7 */
  47312. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47313. if (pkcs7 == NULL)
  47314. return WC_TEST_RET_ENC_ERRNO;
  47315. ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
  47316. if (ret != 0) {
  47317. printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret);
  47318. wc_PKCS7_Free(pkcs7);
  47319. return WC_TEST_RET_ENC_EC(ret);
  47320. }
  47321. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47322. if (ret != 0) {
  47323. wc_PKCS7_Free(pkcs7);
  47324. return WC_TEST_RET_ENC_EC(ret);
  47325. }
  47326. /* encode Signed Encrypted FirmwarePkgData */
  47327. if (encryptKeySz == 16) {
  47328. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47329. encryptKeySz, key, keySz, AES128CBCb, RSAk, SHA256h,
  47330. (byte*)data, sizeof(data), NULL, 0,
  47331. attribs, (word32)attribNum, out, *outSz);
  47332. }
  47333. else {
  47334. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47335. encryptKeySz, key, keySz, AES256CBCb, RSAk, SHA256h,
  47336. (byte*)data, sizeof(data), NULL, 0,
  47337. attribs, (word32)attribNum, out, *outSz);
  47338. }
  47339. if (ret <= 0) {
  47340. printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, "
  47341. "ret = %d\n", ret);
  47342. wc_PKCS7_Free(pkcs7);
  47343. return WC_TEST_RET_ENC_EC(ret);
  47344. } else {
  47345. *outSz = (word32)ret;
  47346. }
  47347. wc_PKCS7_Free(pkcs7);
  47348. return ret;
  47349. }
  47350. /* test verification and decryption of PKCS7 bundle
  47351. * return 0 on success
  47352. */
  47353. static wc_test_ret_t verifyBundle(byte* derBuf, word32 derSz, int keyHint)
  47354. {
  47355. wc_test_ret_t ret = 0;
  47356. int usrCtx = 1; /* test value to pass as user context to callback */
  47357. wc_PKCS7* pkcs7 = NULL;
  47358. byte* sid = NULL;
  47359. word32 sidSz;
  47360. byte key[256];
  47361. word32 keySz = sizeof(key);
  47362. byte *decoded = NULL;
  47363. int decodedSz = FOURK_BUF/2;
  47364. WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = {
  47365. #ifdef NO_SHA
  47366. #ifdef USE_CERT_BUFFERS_1024
  47367. 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9,
  47368. 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2,
  47369. 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06,
  47370. 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9
  47371. #else
  47372. 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36,
  47373. 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e,
  47374. 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4,
  47375. 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71
  47376. #endif
  47377. #else /* !NO_SHA */
  47378. #ifdef USE_CERT_BUFFERS_1024
  47379. 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34,
  47380. 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75,
  47381. 0x10, 0x69, 0x59, 0xec,
  47382. #else
  47383. 0x33, 0xD8, 0x45, 0x66, 0xD7, 0x68, 0x87, 0x18,
  47384. 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26,
  47385. 0xD7, 0x85, 0x65, 0xC0
  47386. #endif
  47387. #endif /* !NO_SHA */
  47388. };
  47389. decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47390. if (decoded == NULL) {
  47391. ret = MEMORY_E;
  47392. goto out;
  47393. }
  47394. pkcs7 = wc_PKCS7_New(HEAP_HINT, INVALID_DEVID);
  47395. if (pkcs7 == NULL) {
  47396. ret = MEMORY_E;
  47397. goto out;
  47398. }
  47399. /* Test verify */
  47400. ret = wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID);
  47401. if (ret != 0)
  47402. goto out;
  47403. ret = wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47404. if (ret != 0)
  47405. goto out;
  47406. ret = wc_PKCS7_VerifySignedData(pkcs7, derBuf, derSz);
  47407. if (ret != 0)
  47408. goto out;
  47409. /* Get size of SID and print it out */
  47410. ret = wc_PKCS7_GetSignerSID(pkcs7, NULL, &sidSz);
  47411. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47412. goto out;
  47413. sid = (byte*)XMALLOC(sidSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47414. if (sid == NULL) {
  47415. ret = MEMORY_E;
  47416. goto out;
  47417. }
  47418. ret = wc_PKCS7_GetSignerSID(pkcs7, sid, &sidSz);
  47419. if (ret != 0)
  47420. goto out;
  47421. ret = XMEMCMP(sid, expectedSid, sidSz);
  47422. if (ret != 0) {
  47423. ret = PKCS7_NO_SIGNER_E; /* close enough */
  47424. goto out;
  47425. }
  47426. /* get expected fwWrappedFirmwareKey */
  47427. if (keyHint == 0) {
  47428. ret = getFirmwareKey(pkcs7, key, keySz);
  47429. if (ret < 0)
  47430. goto out;
  47431. pkcs7->encryptionKey = key;
  47432. pkcs7->encryptionKeySz = (word32)ret;
  47433. }
  47434. else {
  47435. decodedSz = PKCS7_BUF_SIZE;
  47436. ret = wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc);
  47437. if (ret != 0)
  47438. goto out;
  47439. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)&usrCtx);
  47440. if (ret != 0)
  47441. goto out;
  47442. }
  47443. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47444. pkcs7->contentSz, decoded, (word32)decodedSz);
  47445. if (decodedSz < 0) {
  47446. ret = decodedSz;
  47447. goto out;
  47448. }
  47449. ret = 0;
  47450. out:
  47451. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47452. if (pkcs7)
  47453. wc_PKCS7_Free(pkcs7);
  47454. XFREE(sid, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47455. return ret;
  47456. }
  47457. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key, word32 keySz)
  47458. {
  47459. wc_test_ret_t ret = 0;
  47460. word32 derSz;
  47461. byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47462. WOLFSSL_ENTER("pkcs7callback_test");
  47463. if (! derBuf)
  47464. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47465. /* Doing default generation and verify */
  47466. derSz = FOURK_BUF;
  47467. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert,
  47468. certSz, key, keySz);
  47469. if (ret <= 0) {
  47470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47471. }
  47472. ret = verifyBundle(derBuf, derSz, 0);
  47473. if (ret != 0)
  47474. ERROR_OUT(ret, out);
  47475. /* test choosing other key with keyID */
  47476. derSz = FOURK_BUF;
  47477. ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1,
  47478. cert, certSz, key, keySz);
  47479. if (ret <= 0) {
  47480. ERROR_OUT(ret, out);
  47481. }
  47482. ret = verifyBundle(derBuf, derSz, 1);
  47483. if (ret != 0)
  47484. ERROR_OUT(ret, out);
  47485. /* test fail case with wrong keyID */
  47486. derSz = FOURK_BUF;
  47487. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1,
  47488. cert, certSz, key, keySz);
  47489. if (ret <= 0) {
  47490. ERROR_OUT(ret, out);
  47491. }
  47492. ret = verifyBundle(derBuf, derSz, 1);
  47493. if (ret == 0) {
  47494. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47495. }
  47496. ret = 0;
  47497. out:
  47498. XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47499. return ret;
  47500. }
  47501. #endif /* !NO_AES && HAVE_AES_CBC */
  47502. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47503. typedef struct {
  47504. const byte* content;
  47505. word32 contentSz;
  47506. int contentOID;
  47507. int encryptOID;
  47508. byte* encryptionKey;
  47509. word32 encryptionKeySz;
  47510. PKCS7Attrib* attribs;
  47511. word32 attribsSz;
  47512. const char* outFileName;
  47513. } pkcs7EncryptedVector;
  47514. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void)
  47515. {
  47516. wc_test_ret_t ret = 0;
  47517. int i, testSz;
  47518. int encryptedSz, decodedSz, attribIdx;
  47519. wc_PKCS7* pkcs7;
  47520. byte *encrypted;
  47521. byte *decoded;
  47522. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47523. XFILE pkcs7File;
  47524. #endif
  47525. PKCS7Attrib* expectedAttrib;
  47526. PKCS7DecodedAttrib* decodedAttrib;
  47527. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47528. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47529. 0x72,0x6c,0x64
  47530. };
  47531. #ifndef NO_DES3
  47532. byte desKey[] = {
  47533. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  47534. };
  47535. byte des3Key[] = {
  47536. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  47537. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  47538. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  47539. };
  47540. #endif
  47541. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47542. #ifdef WOLFSSL_AES_128
  47543. byte aes128Key[] = {
  47544. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47545. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47546. };
  47547. #endif
  47548. #ifdef WOLFSSL_AES_192
  47549. byte aes192Key[] = {
  47550. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47551. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47552. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47553. };
  47554. #endif
  47555. #ifdef WOLFSSL_AES_256
  47556. byte aes256Key[] = {
  47557. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47558. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47559. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47560. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47561. };
  47562. #endif
  47563. #ifdef WOLFSSL_AES_256
  47564. /* Attribute example from RFC 4134, Section 7.2
  47565. * OID = 1.2.5555
  47566. * OCTET STRING = 'This is a test General ASN Attribute, number 1.' */
  47567. static const byte genAttrOid[] = { 0x06, 0x03, 0x2a, 0xab, 0x33 };
  47568. static const byte genAttr[] = { 0x04, 47,
  47569. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47570. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47571. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47572. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47573. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47574. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x31, 0x2e };
  47575. static const byte genAttrOid2[] = { 0x06, 0x03, 0x2a, 0xab, 0x34 };
  47576. static const byte genAttr2[] = { 0x04, 47,
  47577. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47578. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47579. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47580. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47581. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47582. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x32, 0x2e };
  47583. PKCS7Attrib attribs[] =
  47584. {
  47585. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }
  47586. };
  47587. PKCS7Attrib multiAttribs[] =
  47588. {
  47589. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) },
  47590. { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) }
  47591. };
  47592. #endif
  47593. #endif /* NO_AES */
  47594. const pkcs7EncryptedVector testVectors[] =
  47595. {
  47596. #ifndef NO_DES3
  47597. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key),
  47598. NULL, 0, "pkcs7encryptedDataDES3.der"},
  47599. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey),
  47600. NULL, 0, "pkcs7encryptedDataDES.der"},
  47601. #endif /* NO_DES3 */
  47602. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47603. #ifdef WOLFSSL_AES_128
  47604. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  47605. sizeof(aes128Key), NULL, 0, "pkcs7encryptedDataAES128CBC.der"},
  47606. #endif
  47607. #ifdef WOLFSSL_AES_192
  47608. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  47609. sizeof(aes192Key), NULL, 0, "pkcs7encryptedDataAES192CBC.der"},
  47610. #endif
  47611. #ifdef WOLFSSL_AES_256
  47612. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47613. sizeof(aes256Key), NULL, 0, "pkcs7encryptedDataAES256CBC.der"},
  47614. /* test with optional unprotected attributes */
  47615. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47616. sizeof(aes256Key), attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47617. "pkcs7encryptedDataAES256CBC_attribs.der"},
  47618. /* test with multiple optional unprotected attributes */
  47619. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47620. sizeof(aes256Key), multiAttribs,
  47621. (sizeof(multiAttribs)/sizeof(PKCS7Attrib)),
  47622. "pkcs7encryptedDataAES256CBC_multi_attribs.der"},
  47623. /* test with contentType set to FirmwarePkgData */
  47624. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256CBCb, aes256Key,
  47625. sizeof(aes256Key), NULL, 0,
  47626. "pkcs7encryptedDataAES256CBC_firmwarePkgData.der"},
  47627. #endif
  47628. #endif /* !NO_AES && HAVE_AES_CBC */
  47629. };
  47630. WOLFSSL_ENTER("pkcs7encrypted_test");
  47631. encrypted = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47632. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47633. if ((! encrypted) || (! decoded)) {
  47634. ERROR_OUT(MEMORY_E, out);
  47635. }
  47636. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  47637. for (i = 0; i < testSz; i++) {
  47638. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47639. if (pkcs7 == NULL) {
  47640. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47641. }
  47642. pkcs7->content = (byte*)testVectors[i].content;
  47643. pkcs7->contentSz = testVectors[i].contentSz;
  47644. pkcs7->contentOID = testVectors[i].contentOID;
  47645. pkcs7->encryptOID = testVectors[i].encryptOID;
  47646. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  47647. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  47648. pkcs7->unprotectedAttribs = testVectors[i].attribs;
  47649. pkcs7->unprotectedAttribsSz = testVectors[i].attribsSz;
  47650. /* encode encryptedData */
  47651. encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47652. PKCS7_BUF_SIZE);
  47653. if (encryptedSz <= 0) {
  47654. wc_PKCS7_Free(pkcs7);
  47655. ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out);
  47656. }
  47657. /* decode encryptedData */
  47658. #ifndef NO_PKCS7_STREAM
  47659. { /* test reading byte by byte */
  47660. int z;
  47661. for (z = 0; z < encryptedSz; z++) {
  47662. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted + z, 1,
  47663. decoded, PKCS7_BUF_SIZE);
  47664. if (decodedSz <= 0 &&
  47665. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47666. {
  47667. printf("unexpected error %d\n", decodedSz);
  47668. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47669. }
  47670. }
  47671. /* test decode result */
  47672. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47673. printf("stream read failed\n");
  47674. wc_PKCS7_Free(pkcs7);
  47675. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47676. }
  47677. }
  47678. #endif
  47679. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47680. decoded, PKCS7_BUF_SIZE);
  47681. if (decodedSz <= 0){
  47682. wc_PKCS7_Free(pkcs7);
  47683. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47684. }
  47685. /* test decode result */
  47686. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47687. wc_PKCS7_Free(pkcs7);
  47688. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47689. }
  47690. /* verify decoded unprotected attributes */
  47691. if (pkcs7->decodedAttrib != NULL) {
  47692. decodedAttrib = pkcs7->decodedAttrib;
  47693. attribIdx = 1;
  47694. while (decodedAttrib != NULL) {
  47695. /* expected attribute, stored list is reversed */
  47696. expectedAttrib = &(pkcs7->unprotectedAttribs
  47697. [pkcs7->unprotectedAttribsSz - attribIdx]);
  47698. /* verify oid */
  47699. if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid,
  47700. decodedAttrib->oidSz) != 0) {
  47701. wc_PKCS7_Free(pkcs7);
  47702. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47703. }
  47704. /* verify value */
  47705. if (XMEMCMP(decodedAttrib->value, expectedAttrib->value,
  47706. decodedAttrib->valueSz) != 0) {
  47707. wc_PKCS7_Free(pkcs7);
  47708. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47709. }
  47710. decodedAttrib = decodedAttrib->next;
  47711. attribIdx++;
  47712. }
  47713. }
  47714. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47715. /* output pkcs7 envelopedData for external testing */
  47716. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47717. if (!pkcs7File) {
  47718. wc_PKCS7_Free(pkcs7);
  47719. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47720. }
  47721. ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File);
  47722. if (ret < 0)
  47723. ret = WC_TEST_RET_ENC_ERRNO;
  47724. else
  47725. ret = 0;
  47726. XFCLOSE(pkcs7File);
  47727. #endif
  47728. wc_PKCS7_Free(pkcs7);
  47729. }
  47730. out:
  47731. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47732. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47733. return ret;
  47734. }
  47735. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47736. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47737. typedef struct {
  47738. const byte* content;
  47739. word32 contentSz;
  47740. int contentOID;
  47741. const char* outFileName;
  47742. } pkcs7CompressedVector;
  47743. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void)
  47744. {
  47745. wc_test_ret_t ret = 0;
  47746. int i, testSz;
  47747. int compressedSz, decodedSz;
  47748. wc_PKCS7* pkcs7;
  47749. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47750. byte *compressed;
  47751. byte *decoded;
  47752. #else
  47753. byte compressed[PKCS7_BUF_SIZE];
  47754. byte decoded[PKCS7_BUF_SIZE];
  47755. #endif
  47756. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47757. XFILE pkcs7File;
  47758. #endif
  47759. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47760. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47761. 0x72,0x6c,0x64
  47762. };
  47763. const pkcs7CompressedVector testVectors[] =
  47764. {
  47765. {data, (word32)sizeof(data), DATA,
  47766. "pkcs7compressedData_data_zlib.der"},
  47767. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA,
  47768. "pkcs7compressedData_firmwarePkgData_zlib.der"},
  47769. };
  47770. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47771. compressed = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47772. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47773. if ((! compressed) || (! decoded)) {
  47774. ERROR_OUT(MEMORY_E, out);
  47775. }
  47776. #endif
  47777. WOLFSSL_ENTER("pkcs7compressed_test");
  47778. testSz = sizeof(testVectors) / sizeof(pkcs7CompressedVector);
  47779. for (i = 0; i < testSz; i++) {
  47780. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47781. if (pkcs7 == NULL) {
  47782. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47783. }
  47784. pkcs7->content = (byte*)testVectors[i].content;
  47785. pkcs7->contentSz = testVectors[i].contentSz;
  47786. pkcs7->contentOID = testVectors[i].contentOID;
  47787. /* encode compressedData */
  47788. compressedSz = wc_PKCS7_EncodeCompressedData(pkcs7, compressed,
  47789. PKCS7_BUF_SIZE);
  47790. if (compressedSz <= 0) {
  47791. wc_PKCS7_Free(pkcs7);
  47792. ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out);
  47793. }
  47794. /* decode compressedData */
  47795. decodedSz = wc_PKCS7_DecodeCompressedData(pkcs7, compressed,
  47796. compressedSz, decoded,
  47797. PKCS7_BUF_SIZE);
  47798. if (decodedSz <= 0){
  47799. wc_PKCS7_Free(pkcs7);
  47800. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47801. }
  47802. /* test decode result */
  47803. if (XMEMCMP(decoded, testVectors[i].content,
  47804. testVectors[i].contentSz) != 0) {
  47805. wc_PKCS7_Free(pkcs7);
  47806. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47807. }
  47808. /* make sure content type is the same */
  47809. if (testVectors[i].contentOID != pkcs7->contentOID) {
  47810. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47811. }
  47812. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47813. /* output pkcs7 compressedData for external testing */
  47814. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47815. if (!pkcs7File) {
  47816. wc_PKCS7_Free(pkcs7);
  47817. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47818. }
  47819. ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File);
  47820. if (ret < 0)
  47821. ret = WC_TEST_RET_ENC_ERRNO;
  47822. else
  47823. ret = 0;
  47824. XFCLOSE(pkcs7File);
  47825. #endif
  47826. wc_PKCS7_Free(pkcs7);
  47827. }
  47828. out:
  47829. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47830. XFREE(compressed, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47831. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47832. #endif
  47833. return ret;
  47834. } /* pkcs7compressed_test() */
  47835. #undef PKCS7_BUF_SIZE
  47836. #endif /* HAVE_LIBZ */
  47837. typedef struct {
  47838. const byte* content;
  47839. word32 contentSz;
  47840. int hashOID;
  47841. int signOID;
  47842. byte* privateKey;
  47843. word32 privateKeySz;
  47844. byte* cert;
  47845. size_t certSz;
  47846. byte* caCert;
  47847. size_t caCertSz;
  47848. PKCS7Attrib* signedAttribs;
  47849. word32 signedAttribsSz;
  47850. const char* outFileName;
  47851. int contentOID;
  47852. const byte* contentType;
  47853. word32 contentTypeSz;
  47854. int sidType;
  47855. int encryptOID; /* for single-shot encrypt alg OID */
  47856. int encCompFlag; /* for single-shot. 1 = enc, 2 = comp, 3 = both*/
  47857. const byte* encryptKey; /* for single-shot, encryptedData */
  47858. word32 encryptKeySz; /* for single-shot, encryptedData */
  47859. PKCS7Attrib* unprotectedAttribs; /* for single-shot, encryptedData */
  47860. word32 unprotectedAttribsSz; /* for single-shot, encryptedData */
  47861. word16 detachedSignature; /* generate detached signature (0:1) */
  47862. } pkcs7SignedVector;
  47863. static wc_test_ret_t pkcs7signed_run_vectors(
  47864. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47865. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47866. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47867. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47868. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47869. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47870. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47871. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47872. {
  47873. wc_test_ret_t ret;
  47874. int testSz = 0, i;
  47875. int encodedSz;
  47876. byte* out = NULL;
  47877. word32 outSz;
  47878. WC_RNG rng;
  47879. wc_PKCS7* pkcs7 = NULL;
  47880. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47881. XFILE file;
  47882. #endif
  47883. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47884. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47885. 0x72,0x6c,0x64
  47886. };
  47887. static const byte transIdOid[] =
  47888. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47889. 0x09, 0x07 };
  47890. static const byte messageTypeOid[] =
  47891. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47892. 0x09, 0x02 };
  47893. static const byte senderNonceOid[] =
  47894. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47895. 0x09, 0x05 };
  47896. #ifndef NO_SHA
  47897. byte transId[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47898. #else
  47899. byte transId[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47900. #endif
  47901. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47902. byte senderNonce[PKCS7_NONCE_SZ + 2];
  47903. PKCS7Attrib attribs[] =
  47904. {
  47905. { transIdOid, sizeof(transIdOid), transId,
  47906. sizeof(transId) - 1 }, /* take off the null */
  47907. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47908. sizeof(messageType) },
  47909. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  47910. sizeof(senderNonce) }
  47911. };
  47912. /* for testing custom contentType, FirmwarePkgData */
  47913. static const byte customContentType[] = { 0x06, 0x0B, 0x2A, 0x86,
  47914. 0x48, 0x86, 0xF7, 0x0D,
  47915. 0x01, 0x09, 0x10, 0x01, 0x10 };
  47916. #define MAX_TESTVECTORS_LEN 20
  47917. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47918. const pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47919. if (testSz == MAX_TESTVECTORS_LEN) { \
  47920. ret = WC_TEST_RET_ENC_NC; \
  47921. goto out; \
  47922. } \
  47923. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47924. sizeof _this_vector); \
  47925. }
  47926. pkcs7SignedVector *testVectors = NULL;
  47927. XMEMSET(&rng, 0, sizeof(rng));
  47928. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47929. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47930. if (testVectors == NULL) {
  47931. ret = WC_TEST_RET_ENC_ERRNO;
  47932. goto out;
  47933. }
  47934. {
  47935. #ifndef NO_RSA
  47936. #ifndef NO_SHA
  47937. /* RSA with SHA */
  47938. ADD_PKCS7SIGNEDVECTOR(
  47939. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47940. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47941. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47942. "pkcs7signedData_RSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0, NULL,
  47943. 0, 0);
  47944. /* RSA with SHA, no signed attributes */
  47945. ADD_PKCS7SIGNEDVECTOR(
  47946. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47947. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz,
  47948. NULL, 0, NULL, 0,
  47949. "pkcs7signedData_RSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47950. NULL, 0, 0);
  47951. #endif
  47952. #ifdef WOLFSSL_SHA224
  47953. /* RSA with SHA224 */
  47954. ADD_PKCS7SIGNEDVECTOR(
  47955. data, (word32)sizeof(data), SHA224h, RSAk, rsaClientPrivKeyBuf,
  47956. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47957. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47958. "pkcs7signedData_RSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47959. NULL, 0, 0);
  47960. #endif
  47961. #ifndef NO_SHA256
  47962. /* RSA with SHA256 */
  47963. ADD_PKCS7SIGNEDVECTOR(
  47964. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47965. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47966. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47967. "pkcs7signedData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47968. NULL, 0, 0);
  47969. /* RSA with SHA256, detached signature */
  47970. ADD_PKCS7SIGNEDVECTOR(
  47971. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47972. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47973. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47974. "pkcs7signedData_RSA_SHA256_detachedSig.der", 0, NULL, 0, 0, 0, 0,
  47975. NULL, 0, NULL, 0, 1);
  47976. /* RSA with SHA256 and SubjectKeyIdentifier in SignerIdentifier */
  47977. ADD_PKCS7SIGNEDVECTOR(
  47978. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47979. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47980. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47981. "pkcs7signedData_RSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47982. NULL, 0, NULL, 0, 0);
  47983. /* RSA with SHA256 and custom contentType */
  47984. ADD_PKCS7SIGNEDVECTOR(
  47985. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47986. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47987. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47988. "pkcs7signedData_RSA_SHA256_custom_contentType.der", 0,
  47989. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  47990. NULL, 0, 0);
  47991. /* RSA with SHA256 and FirmwarePkgData contentType */
  47992. ADD_PKCS7SIGNEDVECTOR(
  47993. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47994. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47995. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47996. "pkcs7signedData_RSA_SHA256_firmwarePkgData.der",
  47997. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47998. /* RSA with SHA256 using server cert and ca cert */
  47999. ADD_PKCS7SIGNEDVECTOR(
  48000. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48001. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48002. rsaCaCertBuf, rsaCaCertBufSz,
  48003. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48004. "pkcs7signedData_RSA_SHA256_with_ca_cert.der", 0, NULL, 0, 0, 0, 0,
  48005. NULL, 0, NULL, 0, 0);
  48006. #endif
  48007. #if defined(WOLFSSL_SHA384)
  48008. /* RSA with SHA384 */
  48009. ADD_PKCS7SIGNEDVECTOR(
  48010. data, (word32)sizeof(data), SHA384h, RSAk, rsaClientPrivKeyBuf,
  48011. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48012. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48013. "pkcs7signedData_RSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48014. NULL, 0, 0);
  48015. #endif
  48016. #if defined(WOLFSSL_SHA512)
  48017. /* RSA with SHA512 */
  48018. ADD_PKCS7SIGNEDVECTOR(
  48019. data, (word32)sizeof(data), SHA512h, RSAk, rsaClientPrivKeyBuf,
  48020. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48021. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48022. "pkcs7signedData_RSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48023. NULL, 0, 0);
  48024. #endif
  48025. #endif /* NO_RSA */
  48026. #ifdef HAVE_ECC
  48027. #ifndef NO_SHA
  48028. /* ECDSA with SHA */
  48029. ADD_PKCS7SIGNEDVECTOR(
  48030. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48031. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48032. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48033. "pkcs7signedData_ECDSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48034. NULL, 0, 0);
  48035. /* ECDSA with SHA, no signed attributes */
  48036. ADD_PKCS7SIGNEDVECTOR(
  48037. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48038. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz,
  48039. NULL, 0, NULL, 0,
  48040. "pkcs7signedData_ECDSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48041. NULL, 0, 0);
  48042. #endif
  48043. #ifdef WOLFSSL_SHA224
  48044. /* ECDSA with SHA224 */
  48045. ADD_PKCS7SIGNEDVECTOR(
  48046. data, (word32)sizeof(data), SHA224h, ECDSAk, eccClientPrivKeyBuf,
  48047. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48048. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48049. "pkcs7signedData_ECDSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48050. NULL, 0, 0);
  48051. #endif
  48052. #ifndef NO_SHA256
  48053. /* ECDSA with SHA256 */
  48054. ADD_PKCS7SIGNEDVECTOR(
  48055. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48056. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48057. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48058. "pkcs7signedData_ECDSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48059. NULL, 0, 0);
  48060. /* ECDSA with SHA256 and SubjectKeyIdentifier in SigherIdentifier */
  48061. ADD_PKCS7SIGNEDVECTOR(
  48062. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48063. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48064. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48065. "pkcs7signedData_ECDSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  48066. NULL, 0, NULL, 0, 0);
  48067. /* ECDSA with SHA256 and custom contentType */
  48068. ADD_PKCS7SIGNEDVECTOR(
  48069. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48070. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48071. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48072. "pkcs7signedData_ECDSA_SHA256_custom_contentType.der", 0,
  48073. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  48074. NULL, 0, 0);
  48075. /* ECDSA with SHA256 and FirmwarePkgData contentType */
  48076. ADD_PKCS7SIGNEDVECTOR(
  48077. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48078. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48079. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48080. "pkcs7signedData_ECDSA_SHA256_firmwarePkgData.der",
  48081. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48082. #endif
  48083. #ifdef WOLFSSL_SHA384
  48084. /* ECDSA with SHA384 */
  48085. ADD_PKCS7SIGNEDVECTOR(
  48086. data, (word32)sizeof(data), SHA384h, ECDSAk, eccClientPrivKeyBuf,
  48087. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48088. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48089. "pkcs7signedData_ECDSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48090. NULL, 0, 0);
  48091. #endif
  48092. #ifdef WOLFSSL_SHA512
  48093. /* ECDSA with SHA512 */
  48094. ADD_PKCS7SIGNEDVECTOR(
  48095. data, (word32)sizeof(data), SHA512h, ECDSAk, eccClientPrivKeyBuf,
  48096. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48097. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48098. "pkcs7signedData_ECDSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48099. NULL, 0, 0);
  48100. #endif
  48101. #endif /* HAVE_ECC */
  48102. };
  48103. #undef MAX_TESTVECTORS_LEN
  48104. #undef ADD_PKCS7SIGNEDVECTOR
  48105. outSz = FOURK_BUF;
  48106. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48107. if (out == NULL)
  48108. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48109. XMEMSET(out, 0, outSz);
  48110. /* test inner pad size error with block size being 0 */
  48111. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
  48112. if (ret > 0)
  48113. ERROR_OUT(-1, out);
  48114. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48115. if (ret < 0)
  48116. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48117. #ifndef HAVE_FIPS
  48118. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48119. #else
  48120. ret = wc_InitRng(&rng);
  48121. #endif
  48122. if (ret != 0)
  48123. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48124. for (i = 0; i < testSz; i++) {
  48125. if (pkcs7)
  48126. wc_PKCS7_Free(pkcs7);
  48127. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48128. if (pkcs7 == NULL)
  48129. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48130. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48131. (word32)testVectors[i].certSz);
  48132. if (ret != 0)
  48133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48134. /* load CA certificate, if present */
  48135. if (testVectors[i].caCert != NULL) {
  48136. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48137. (word32)testVectors[i].caCertSz);
  48138. if (ret != 0)
  48139. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48140. }
  48141. pkcs7->rng = &rng;
  48142. pkcs7->content = (byte*)testVectors[i].content;
  48143. pkcs7->contentSz = testVectors[i].contentSz;
  48144. pkcs7->contentOID = testVectors[i].contentOID;
  48145. pkcs7->hashOID = testVectors[i].hashOID;
  48146. pkcs7->encryptOID = testVectors[i].signOID;
  48147. pkcs7->privateKey = testVectors[i].privateKey;
  48148. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  48149. pkcs7->signedAttribs = testVectors[i].signedAttribs;
  48150. pkcs7->signedAttribsSz = testVectors[i].signedAttribsSz;
  48151. /* optional custom contentType, default is DATA,
  48152. overrides contentOID if set */
  48153. if (testVectors[i].contentType != NULL) {
  48154. ret = wc_PKCS7_SetContentType(pkcs7,
  48155. (byte *)testVectors[i].contentType,
  48156. testVectors[i].contentTypeSz);
  48157. if (ret != 0)
  48158. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48159. }
  48160. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48161. default is IssuerAndSerialNumber */
  48162. if (testVectors[i].sidType == CMS_SKID) {
  48163. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48164. if (ret != 0)
  48165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48166. }
  48167. /* generate senderNonce */
  48168. {
  48169. senderNonce[0] = 0x04;
  48170. senderNonce[1] = PKCS7_NONCE_SZ;
  48171. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  48172. if (ret != 0)
  48173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48174. }
  48175. /* generate transactionID (used with SCEP) */
  48176. {
  48177. #ifndef NO_SHA
  48178. wc_Sha sha;
  48179. byte digest[WC_SHA_DIGEST_SIZE];
  48180. #else
  48181. wc_Sha256 sha;
  48182. byte digest[WC_SHA256_DIGEST_SIZE];
  48183. #endif
  48184. int j,k;
  48185. transId[0] = 0x13;
  48186. transId[1] = sizeof(digest) * 2;
  48187. #ifndef NO_SHA
  48188. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  48189. if (ret != 0)
  48190. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48191. wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48192. wc_ShaFinal(&sha, digest);
  48193. wc_ShaFree(&sha);
  48194. #else
  48195. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  48196. if (ret != 0)
  48197. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48198. wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48199. wc_Sha256Final(&sha, digest);
  48200. wc_Sha256Free(&sha);
  48201. #endif
  48202. for (j = 0, k = 2; j < (int)sizeof(digest); j++, k += 2) {
  48203. (void)XSNPRINTF((char*)&transId[k], 3, "%02x", digest[j]);
  48204. }
  48205. }
  48206. /* enable detached signature generation, if set */
  48207. if (testVectors[i].detachedSignature == 1) {
  48208. ret = wc_PKCS7_SetDetached(pkcs7, 1);
  48209. if (ret != 0)
  48210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48211. }
  48212. encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz);
  48213. if (encodedSz < 0)
  48214. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48215. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48216. /* write PKCS#7 to output file for more testing */
  48217. file = XFOPEN(testVectors[i].outFileName, "wb");
  48218. if (!file) {
  48219. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48220. }
  48221. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48222. XFCLOSE(file);
  48223. if (ret != (int)encodedSz)
  48224. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48225. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48226. wc_PKCS7_Free(pkcs7);
  48227. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48228. if (pkcs7 == NULL)
  48229. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48230. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48231. if (testVectors[i].detachedSignature == 1) {
  48232. /* set content for verifying detached signatures */
  48233. pkcs7->content = (byte*)testVectors[i].content;
  48234. pkcs7->contentSz = testVectors[i].contentSz;
  48235. }
  48236. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48237. if (ret < 0)
  48238. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48239. /* verify contentType extracted successfully for custom content types */
  48240. if (testVectors[i].contentTypeSz > 0) {
  48241. if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) {
  48242. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48243. } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType,
  48244. pkcs7->contentTypeSz) != 0) {
  48245. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48246. }
  48247. }
  48248. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48249. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48250. {
  48251. /* check getting signed attributes */
  48252. #ifndef NO_SHA
  48253. byte buf[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  48254. #else
  48255. byte buf[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  48256. #endif
  48257. const byte* oidPt = transIdOid + 2; /* skip object id tag and size */
  48258. int oidSz = (int)sizeof(transIdOid) - 2;
  48259. int bufSz = 0;
  48260. if (testVectors[i].signedAttribs != NULL) {
  48261. ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48262. NULL, (word32*)&bufSz);
  48263. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  48264. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48265. ret = 0;
  48266. }
  48267. if (bufSz > (int)sizeof(buf))
  48268. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48269. bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48270. buf, (word32*)&bufSz);
  48271. if ((testVectors[i].signedAttribs != NULL && bufSz < 0) ||
  48272. (testVectors[i].signedAttribs == NULL && bufSz > 0))
  48273. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48274. }
  48275. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48276. file = XFOPEN("./pkcs7cert.der", "wb");
  48277. if (!file)
  48278. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48279. ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file);
  48280. if (ret < 0)
  48281. ret = WC_TEST_RET_ENC_ERRNO;
  48282. else
  48283. ret = 0;
  48284. XFCLOSE(file);
  48285. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48286. }
  48287. out:
  48288. if (pkcs7 != NULL)
  48289. wc_PKCS7_Free(pkcs7);
  48290. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48291. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48292. wc_FreeRng(&rng);
  48293. if (ret > 0)
  48294. return 0;
  48295. (void)rsaClientCertBuf;
  48296. (void)rsaClientCertBufSz;
  48297. (void)rsaClientPrivKeyBuf;
  48298. (void)rsaClientPrivKeyBufSz;
  48299. (void)rsaServerCertBuf;
  48300. (void)rsaServerCertBufSz;
  48301. (void)rsaServerPrivKeyBuf;
  48302. (void)rsaServerPrivKeyBufSz;
  48303. (void)rsaCaCertBuf;
  48304. (void)rsaCaCertBufSz;
  48305. (void)rsaCaPrivKeyBuf;
  48306. (void)rsaCaPrivKeyBufSz;
  48307. (void)eccClientCertBuf;
  48308. (void)eccClientCertBufSz;
  48309. (void)eccClientPrivKeyBuf;
  48310. (void)eccClientPrivKeyBufSz;
  48311. return ret;
  48312. }
  48313. static wc_test_ret_t pkcs7signed_run_SingleShotVectors(
  48314. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  48315. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  48316. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  48317. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  48318. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  48319. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  48320. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  48321. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  48322. {
  48323. wc_test_ret_t ret;
  48324. int testSz = 0, i;
  48325. int encodedSz;
  48326. byte* out = NULL;
  48327. word32 outSz;
  48328. WC_RNG rng;
  48329. wc_PKCS7* pkcs7 = NULL;
  48330. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48331. XFILE file;
  48332. #endif
  48333. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48334. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48335. byte* encryptedTmp = NULL;
  48336. int encryptedTmpSz;
  48337. #endif
  48338. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  48339. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  48340. 0x72,0x6c,0x64
  48341. };
  48342. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48343. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48344. static const byte aes256Key[] = {
  48345. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48346. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48347. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48348. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  48349. };
  48350. #endif
  48351. static const byte messageTypeOid[] =
  48352. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  48353. 0x09, 0x02 };
  48354. static const byte messageType[] = { 0x13, 2, '1', '9' };
  48355. PKCS7Attrib attribs[] =
  48356. {
  48357. { messageTypeOid, sizeof(messageTypeOid), messageType,
  48358. sizeof(messageType) },
  48359. };
  48360. #define MAX_TESTVECTORS_LEN 19
  48361. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  48362. pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  48363. if (testSz == MAX_TESTVECTORS_LEN) { \
  48364. ret = WC_TEST_RET_ENC_NC; \
  48365. goto out; \
  48366. } \
  48367. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  48368. sizeof _this_vector); \
  48369. }
  48370. pkcs7SignedVector *testVectors = NULL;
  48371. XMEMSET(&rng, 0, sizeof(rng));
  48372. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  48373. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48374. if (testVectors == NULL) {
  48375. ret = WC_TEST_RET_ENC_ERRNO;
  48376. goto out;
  48377. }
  48378. {
  48379. #ifndef NO_RSA
  48380. #ifndef NO_SHA256
  48381. /* Signed FirmwarePkgData, RSA, SHA256, no attribs */
  48382. ADD_PKCS7SIGNEDVECTOR(
  48383. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48384. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48385. NULL, 0,
  48386. "pkcs7signedFirmwarePkgData_RSA_SHA256_noattr.der", 0, NULL, 0, 0,
  48387. 0, 0, NULL, 0, NULL, 0, 0);
  48388. /* Signed FirmwarePkgData, RSA, SHA256, attrs */
  48389. ADD_PKCS7SIGNEDVECTOR(
  48390. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48391. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48392. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48393. "pkcs7signedFirmwarePkgData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0,
  48394. NULL, 0, NULL, 0, 0);
  48395. /* Signed FirmwarePkgData, RSA, SHA256, SubjectKeyIdentifier, attrs */
  48396. ADD_PKCS7SIGNEDVECTOR(
  48397. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48398. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48399. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48400. "pkcs7signedFirmwarePkgData_RSA_SHA256_SKID.der", 0, NULL,
  48401. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48402. /* Signed FirmwraePkgData, RSA, SHA256, server cert and ca cert, attr */
  48403. ADD_PKCS7SIGNEDVECTOR(
  48404. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48405. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48406. rsaCaCertBuf, rsaCaCertBufSz,
  48407. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48408. "pkcs7signedFirmwarePkgData_RSA_SHA256_with_ca_cert.der", 0, NULL,
  48409. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48410. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48411. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48412. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, no attribs */
  48413. ADD_PKCS7SIGNEDVECTOR(
  48414. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48415. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48416. NULL, 0,
  48417. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48418. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48419. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, attribs */
  48420. ADD_PKCS7SIGNEDVECTOR(
  48421. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48422. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48423. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48424. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256.der", 0,
  48425. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48426. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48427. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48428. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48429. /* Signed Compressed FirmwarePkgData, RSA, SHA256, no attribs */
  48430. ADD_PKCS7SIGNEDVECTOR(
  48431. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48432. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48433. NULL, 0,
  48434. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48435. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48436. /* Signed Compressed FirmwarePkgData, RSA, SHA256, attribs */
  48437. ADD_PKCS7SIGNEDVECTOR(
  48438. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48439. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48440. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48441. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256.der", 0,
  48442. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48443. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48444. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48445. no attribs */
  48446. ADD_PKCS7SIGNEDVECTOR(
  48447. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48448. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48449. NULL, 0,
  48450. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der",
  48451. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48452. 0, 0);
  48453. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48454. attribs */
  48455. ADD_PKCS7SIGNEDVECTOR(
  48456. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48457. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48458. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48459. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der",
  48460. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48461. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48462. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48463. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48464. #endif /* NO_SHA256 */
  48465. #endif /* NO_RSA */
  48466. #ifdef HAVE_ECC
  48467. #ifndef NO_SHA256
  48468. /* Signed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48469. ADD_PKCS7SIGNEDVECTOR(
  48470. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48471. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48472. NULL, 0,
  48473. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48474. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48475. /* Signed FirmwarePkgData, ECDSA, SHA256, attribs */
  48476. ADD_PKCS7SIGNEDVECTOR(
  48477. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48478. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48479. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48480. "pkcs7signedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48481. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48482. /* Signed FirmwarePkgData, ECDSA, SHA256, SubjectKeyIdentifier, attr */
  48483. ADD_PKCS7SIGNEDVECTOR(
  48484. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48485. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48486. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48487. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_SKID.der", 0, NULL,
  48488. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48489. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48490. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48491. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, no attribs */
  48492. ADD_PKCS7SIGNEDVECTOR(
  48493. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48494. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48495. NULL, 0,
  48496. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48497. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48498. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, attribs */
  48499. ADD_PKCS7SIGNEDVECTOR(
  48500. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48501. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48502. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48503. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48504. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48505. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48506. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48507. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48508. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48509. ADD_PKCS7SIGNEDVECTOR(
  48510. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48511. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48512. NULL, 0,
  48513. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48514. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48515. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, attrib */
  48516. ADD_PKCS7SIGNEDVECTOR(
  48517. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48518. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48519. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48520. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48521. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48522. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48523. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48524. no attribs */
  48525. ADD_PKCS7SIGNEDVECTOR(
  48526. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48527. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48528. NULL, 0,
  48529. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der",
  48530. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48531. 0, 0);
  48532. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48533. attribs */
  48534. ADD_PKCS7SIGNEDVECTOR(
  48535. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48536. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48537. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48538. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der",
  48539. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48540. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48541. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48542. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48543. #endif /* NO_SHA256 */
  48544. #endif /* HAVE_ECC */
  48545. };
  48546. #undef MAX_TESTVECTORS_LEN
  48547. #undef ADD_PKCS7SIGNEDVECTOR
  48548. outSz = FOURK_BUF;
  48549. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48550. if (out == NULL)
  48551. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48552. XMEMSET(out, 0, outSz);
  48553. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48554. if (ret < 0)
  48555. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48556. #ifndef HAVE_FIPS
  48557. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48558. #else
  48559. ret = wc_InitRng(&rng);
  48560. #endif
  48561. if (ret != 0)
  48562. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48563. for (i = 0; i < testSz; i++) {
  48564. if (pkcs7)
  48565. wc_PKCS7_Free(pkcs7);
  48566. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48567. if (pkcs7 == NULL)
  48568. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48569. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48570. (word32)testVectors[i].certSz);
  48571. if (ret != 0)
  48572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48573. /* load CA certificate, if present */
  48574. if (testVectors[i].caCert != NULL) {
  48575. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48576. (word32)testVectors[i].caCertSz);
  48577. if (ret != 0)
  48578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48579. }
  48580. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48581. default is IssuerAndSerialNumber */
  48582. if (testVectors[i].sidType == CMS_SKID) {
  48583. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48584. if (ret != 0)
  48585. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48586. }
  48587. if (testVectors[i].encCompFlag == 0) {
  48588. /* encode Signed FirmwarePkgData */
  48589. encodedSz = wc_PKCS7_EncodeSignedFPD(pkcs7,
  48590. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48591. testVectors[i].signOID, testVectors[i].hashOID,
  48592. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48593. testVectors[i].signedAttribs,
  48594. testVectors[i].signedAttribsSz, out, outSz);
  48595. if (encodedSz < 0)
  48596. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48597. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48598. } else if (testVectors[i].encCompFlag == 1) {
  48599. /* encode Signed Encrypted FirmwarePkgData */
  48600. encodedSz = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7,
  48601. (byte *)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48602. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48603. testVectors[i].encryptOID, testVectors[i].signOID,
  48604. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48605. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48606. testVectors[i].unprotectedAttribsSz,
  48607. testVectors[i].signedAttribs,
  48608. testVectors[i].signedAttribsSz, out, outSz);
  48609. if (encodedSz <= 0)
  48610. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48611. #endif
  48612. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48613. } else if (testVectors[i].encCompFlag == 2) {
  48614. /* encode Signed Compressed FirmwarePkgData */
  48615. encodedSz = wc_PKCS7_EncodeSignedCompressedFPD(pkcs7,
  48616. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48617. testVectors[i].signOID, testVectors[i].hashOID,
  48618. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48619. testVectors[i].signedAttribs,
  48620. testVectors[i].signedAttribsSz, out, outSz);
  48621. if (encodedSz <= 0)
  48622. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48623. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48624. } else if (testVectors[i].encCompFlag == 3) {
  48625. /* encode Signed Encrypted Compressed FirmwarePkgData */
  48626. encodedSz = wc_PKCS7_EncodeSignedEncryptedCompressedFPD(pkcs7,
  48627. (byte*)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48628. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48629. testVectors[i].encryptOID, testVectors[i].signOID,
  48630. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48631. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48632. testVectors[i].unprotectedAttribsSz,
  48633. testVectors[i].signedAttribs,
  48634. testVectors[i].signedAttribsSz, out, outSz);
  48635. if (encodedSz <= 0)
  48636. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48637. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48638. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48639. } else {
  48640. /* unsupported SignedData single-shot combination */
  48641. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48642. }
  48643. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48644. /* write PKCS#7 to output file for more testing */
  48645. file = XFOPEN(testVectors[i].outFileName, "wb");
  48646. if (!file)
  48647. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48648. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48649. XFCLOSE(file);
  48650. file = NULL;
  48651. if (ret != (int)encodedSz)
  48652. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48653. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48654. wc_PKCS7_Free(pkcs7);
  48655. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48656. if (pkcs7 == NULL)
  48657. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48658. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48659. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48660. if (ret < 0)
  48661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48662. #ifndef NO_PKCS7_STREAM
  48663. {
  48664. word32 z;
  48665. for (z = 0; z < outSz && ret != 0; z++) {
  48666. ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1);
  48667. if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  48668. printf("unexpected error %d\n", ret);
  48669. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48670. }
  48671. }
  48672. }
  48673. #endif
  48674. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48675. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48676. if (testVectors[i].encCompFlag == 0) {
  48677. /* verify decoded content matches expected */
  48678. if ((pkcs7->contentSz != testVectors[i].contentSz) ||
  48679. XMEMCMP(pkcs7->content, testVectors[i].content,
  48680. pkcs7->contentSz)) {
  48681. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48682. }
  48683. }
  48684. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48685. else if (testVectors[i].encCompFlag == 1) {
  48686. /* decrypt inner encryptedData */
  48687. pkcs7->encryptionKey = (byte *)testVectors[i].encryptKey;
  48688. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48689. ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48690. pkcs7->contentSz, out, outSz);
  48691. if (ret < 0)
  48692. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48693. /* compare decrypted to expected */
  48694. if (((word32)ret != testVectors[i].contentSz) ||
  48695. XMEMCMP(out, testVectors[i].content, ret))
  48696. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48697. }
  48698. #endif
  48699. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48700. else if (testVectors[i].encCompFlag == 2) {
  48701. /* decompress inner compressedData */
  48702. ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content,
  48703. pkcs7->contentSz, out, outSz);
  48704. if (ret < 0)
  48705. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48706. /* compare decompressed to expected */
  48707. if (((word32)ret != testVectors[i].contentSz) ||
  48708. XMEMCMP(out, testVectors[i].content, ret))
  48709. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48710. }
  48711. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48712. else if (testVectors[i].encCompFlag == 3) {
  48713. encryptedTmpSz = FOURK_BUF;
  48714. encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT,
  48715. DYNAMIC_TYPE_TMP_BUFFER);
  48716. if (encryptedTmp == NULL)
  48717. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48718. XMEMSET(encryptedTmp, 0, encryptedTmpSz);
  48719. /* decrypt inner encryptedData */
  48720. pkcs7->encryptionKey = (byte*)testVectors[i].encryptKey;
  48721. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48722. encryptedTmpSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48723. pkcs7->contentSz, encryptedTmp,
  48724. encryptedTmpSz);
  48725. if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA)
  48726. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48727. /* decompress inner compressedData */
  48728. ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp,
  48729. encryptedTmpSz, out, outSz);
  48730. if (ret < 0)
  48731. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48732. /* compare decompressed to expected */
  48733. if (((word32)ret != testVectors[i].contentSz) ||
  48734. XMEMCMP(out, testVectors[i].content, ret))
  48735. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48736. }
  48737. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48738. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48739. }
  48740. out:
  48741. if (pkcs7 != NULL)
  48742. wc_PKCS7_Free(pkcs7);
  48743. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48744. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48745. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48746. XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48747. #endif
  48748. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48749. wc_FreeRng(&rng);
  48750. if (ret > 0)
  48751. return 0;
  48752. (void)eccClientCertBuf;
  48753. (void)eccClientCertBufSz;
  48754. (void)eccClientPrivKeyBuf;
  48755. (void)eccClientPrivKeyBufSz;
  48756. (void)rsaClientCertBuf;
  48757. (void)rsaClientCertBufSz;
  48758. (void)rsaClientPrivKeyBuf;
  48759. (void)rsaClientPrivKeyBufSz;
  48760. (void)rsaServerCertBuf;
  48761. (void)rsaServerCertBufSz;
  48762. (void)rsaServerPrivKeyBuf;
  48763. (void)rsaServerPrivKeyBufSz;
  48764. (void)rsaCaCertBuf;
  48765. (void)rsaCaCertBufSz;
  48766. (void)rsaCaPrivKeyBuf;
  48767. (void)rsaCaPrivKeyBufSz;
  48768. return ret;
  48769. }
  48770. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void)
  48771. {
  48772. wc_test_ret_t ret = 0;
  48773. byte* rsaClientCertBuf = NULL;
  48774. byte* rsaServerCertBuf = NULL;
  48775. byte* rsaCaCertBuf = NULL;
  48776. byte* eccClientCertBuf = NULL;
  48777. byte* rsaClientPrivKeyBuf = NULL;
  48778. byte* rsaServerPrivKeyBuf = NULL;
  48779. byte* rsaCaPrivKeyBuf = NULL;
  48780. byte* eccClientPrivKeyBuf = NULL;
  48781. word32 rsaClientCertBufSz = 0;
  48782. word32 rsaServerCertBufSz = 0;
  48783. word32 rsaCaCertBufSz = 0;
  48784. word32 eccClientCertBufSz = 0;
  48785. word32 rsaClientPrivKeyBufSz = 0;
  48786. word32 rsaServerPrivKeyBufSz = 0;
  48787. word32 rsaCaPrivKeyBufSz = 0;
  48788. word32 eccClientPrivKeyBufSz = 0;
  48789. WOLFSSL_ENTER("pkcs7signed_test");
  48790. #ifndef NO_RSA
  48791. /* read client RSA cert and key in DER format */
  48792. rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48793. DYNAMIC_TYPE_TMP_BUFFER);
  48794. if (rsaClientCertBuf == NULL)
  48795. ret = WC_TEST_RET_ENC_NC;
  48796. rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48797. DYNAMIC_TYPE_TMP_BUFFER);
  48798. if (ret == 0 && rsaClientPrivKeyBuf == NULL) {
  48799. ret = WC_TEST_RET_ENC_ERRNO;
  48800. }
  48801. rsaClientCertBufSz = FOURK_BUF;
  48802. rsaClientPrivKeyBufSz = FOURK_BUF;
  48803. /* read server RSA cert and key in DER format */
  48804. rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48805. DYNAMIC_TYPE_TMP_BUFFER);
  48806. if (ret == 0 && rsaServerCertBuf == NULL)
  48807. ret = WC_TEST_RET_ENC_NC;
  48808. rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48809. DYNAMIC_TYPE_TMP_BUFFER);
  48810. if (ret == 0 && rsaServerPrivKeyBuf == NULL) {
  48811. ret = WC_TEST_RET_ENC_ERRNO;
  48812. }
  48813. rsaServerCertBufSz = FOURK_BUF;
  48814. rsaServerPrivKeyBufSz = FOURK_BUF;
  48815. /* read CA RSA cert and key in DER format, for use with server cert */
  48816. rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48817. DYNAMIC_TYPE_TMP_BUFFER);
  48818. if (ret == 0 && rsaCaCertBuf == NULL)
  48819. ret = WC_TEST_RET_ENC_NC;
  48820. rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48821. DYNAMIC_TYPE_TMP_BUFFER);
  48822. if (ret == 0 && rsaCaPrivKeyBuf == NULL) {
  48823. ret = WC_TEST_RET_ENC_ERRNO;
  48824. }
  48825. rsaCaCertBufSz = FOURK_BUF;
  48826. rsaCaPrivKeyBufSz = FOURK_BUF;
  48827. #endif /* NO_RSA */
  48828. #ifdef HAVE_ECC
  48829. /* read client ECC cert and key in DER format */
  48830. eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48831. DYNAMIC_TYPE_TMP_BUFFER);
  48832. if (ret == 0 && eccClientCertBuf == NULL) {
  48833. ret = WC_TEST_RET_ENC_ERRNO;
  48834. }
  48835. eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48836. DYNAMIC_TYPE_TMP_BUFFER);
  48837. if (ret == 0 && eccClientPrivKeyBuf == NULL) {
  48838. ret = WC_TEST_RET_ENC_ERRNO;
  48839. }
  48840. eccClientCertBufSz = FOURK_BUF;
  48841. eccClientPrivKeyBufSz = FOURK_BUF;
  48842. #endif /* HAVE_ECC */
  48843. if (ret >= 0)
  48844. ret = pkcs7_load_certs_keys(rsaClientCertBuf, &rsaClientCertBufSz,
  48845. rsaClientPrivKeyBuf, &rsaClientPrivKeyBufSz,
  48846. rsaServerCertBuf, &rsaServerCertBufSz,
  48847. rsaServerPrivKeyBuf, &rsaServerPrivKeyBufSz,
  48848. rsaCaCertBuf, &rsaCaCertBufSz,
  48849. rsaCaPrivKeyBuf, &rsaCaPrivKeyBufSz,
  48850. eccClientCertBuf, &eccClientCertBufSz,
  48851. eccClientPrivKeyBuf, &eccClientPrivKeyBufSz);
  48852. if (ret < 0) {
  48853. ret = WC_TEST_RET_ENC_EC(ret);
  48854. }
  48855. if (ret >= 0)
  48856. ret = pkcs7signed_run_vectors(rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48857. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48858. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48859. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48860. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48861. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48862. eccClientCertBuf, (word32)eccClientCertBufSz,
  48863. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48864. if (ret >= 0)
  48865. ret = pkcs7signed_run_SingleShotVectors(
  48866. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48867. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48868. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48869. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48870. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48871. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48872. eccClientCertBuf, (word32)eccClientCertBufSz,
  48873. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48874. #if !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  48875. if (ret >= 0)
  48876. ret = pkcs7callback_test(
  48877. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48878. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz);
  48879. #endif
  48880. XFREE(rsaClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48881. XFREE(rsaClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48882. XFREE(rsaServerCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48883. XFREE(rsaServerPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48884. XFREE(rsaCaCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48885. XFREE(rsaCaPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48886. XFREE(eccClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48887. XFREE(eccClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48888. return ret;
  48889. }
  48890. #endif /* HAVE_PKCS7 */
  48891. #if defined(WOLFSSL_PUBLIC_MP) && \
  48892. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48893. defined(USE_FAST_MATH))
  48894. /* Maximum number of bytes in a number to test. */
  48895. #define MP_MAX_TEST_BYTE_LEN 32
  48896. static wc_test_ret_t randNum(mp_int* n, int len, WC_RNG* rng, void* heap)
  48897. {
  48898. byte d[MP_MAX_TEST_BYTE_LEN];
  48899. wc_test_ret_t ret;
  48900. (void)heap;
  48901. do {
  48902. ret = wc_RNG_GenerateBlock(rng, d, (word32)len);
  48903. if (ret != 0)
  48904. return ret;
  48905. ret = mp_read_unsigned_bin(n, d, (word32)len);
  48906. if (ret != 0)
  48907. return ret;
  48908. } while (mp_iszero(n));
  48909. return 0;
  48910. }
  48911. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  48912. static wc_test_ret_t mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng)
  48913. {
  48914. int i, j;
  48915. mp_digit rem;
  48916. mp_digit rem2;
  48917. wc_test_ret_t ret;
  48918. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48919. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48920. for (i = 0; i < 10; i++) {
  48921. for (j = 1; j < 10; j++) {
  48922. ret = randNum(a, j, rng, NULL);
  48923. if (ret != 0)
  48924. return WC_TEST_RET_ENC_EC(ret);
  48925. ret = mp_div_3(a, r, &rem);
  48926. if (ret != 0)
  48927. return WC_TEST_RET_ENC_EC(ret);
  48928. ret = mp_mul_d(r, 3, r);
  48929. if (ret != 0)
  48930. return WC_TEST_RET_ENC_EC(ret);
  48931. ret = mp_add_d(r, rem, r);
  48932. if (ret != 0)
  48933. return WC_TEST_RET_ENC_EC(ret);
  48934. ret = mp_cmp(r, a);
  48935. if (ret != MP_EQ)
  48936. return WC_TEST_RET_ENC_NC;
  48937. }
  48938. }
  48939. ret = mp_div_3(a, r, &rem);
  48940. if (ret != 0)
  48941. return WC_TEST_RET_ENC_NC;
  48942. ret = mp_div_3(a, a, NULL);
  48943. if (ret != 0)
  48944. return WC_TEST_RET_ENC_NC;
  48945. ret = mp_cmp(r, a);
  48946. if (ret != MP_EQ)
  48947. return WC_TEST_RET_ENC_NC;
  48948. #endif
  48949. #if defined(WOLFSSL_SP_MATH_ALL)
  48950. ret = mp_div_d(a, 10, r, &rem);
  48951. if (ret != 0)
  48952. return WC_TEST_RET_ENC_EC(ret);
  48953. ret = mp_div_d(a, 10, a, NULL);
  48954. if (ret != 0)
  48955. return WC_TEST_RET_ENC_EC(ret);
  48956. ret = mp_cmp(r, a);
  48957. if (ret != MP_EQ)
  48958. return WC_TEST_RET_ENC_NC;
  48959. ret = mp_div_d(a, 12, r, &rem);
  48960. if (ret != 0)
  48961. return WC_TEST_RET_ENC_EC(ret);
  48962. ret = mp_div_d(a, 12, a, NULL);
  48963. if (ret != 0)
  48964. return WC_TEST_RET_ENC_EC(ret);
  48965. ret = mp_cmp(r, a);
  48966. if (ret != MP_EQ)
  48967. return WC_TEST_RET_ENC_NC;
  48968. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem);
  48969. if (ret != 0)
  48970. return WC_TEST_RET_ENC_EC(ret);
  48971. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2);
  48972. if (ret != 0)
  48973. return WC_TEST_RET_ENC_EC(ret);
  48974. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL);
  48975. if (ret != 0)
  48976. return WC_TEST_RET_ENC_EC(ret);
  48977. ret = mp_cmp(r, a);
  48978. if (ret != MP_EQ)
  48979. return WC_TEST_RET_ENC_NC;
  48980. if (rem != rem2)
  48981. return WC_TEST_RET_ENC_NC;
  48982. #endif
  48983. (void)a;
  48984. (void)r;
  48985. (void)rng;
  48986. (void)i;
  48987. (void)j;
  48988. (void)rem;
  48989. (void)rem2;
  48990. (void)ret;
  48991. return 0;
  48992. }
  48993. #endif /* WOLFSSL_SP_MATH || !USE_FAST_MATH */
  48994. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  48995. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48996. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  48997. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  48998. static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
  48999. {
  49000. wc_test_ret_t ret;
  49001. int i, j;
  49002. int size;
  49003. char str[30];
  49004. WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
  49005. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
  49006. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49007. WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
  49008. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49009. for (i = 0; i < 10; i++) {
  49010. for (j = 2; j < 12; j++) {
  49011. ret = randNum(a, j, rng, NULL);
  49012. if (ret != 0)
  49013. return WC_TEST_RET_ENC_EC(ret);
  49014. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49015. if (ret != MP_OKAY)
  49016. return WC_TEST_RET_ENC_EC(ret);
  49017. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49018. if (ret != MP_OKAY)
  49019. return WC_TEST_RET_ENC_EC(ret);
  49020. if ((int)XSTRLEN(str) != size - 1)
  49021. return WC_TEST_RET_ENC_NC;
  49022. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49023. if (ret != MP_OKAY)
  49024. return WC_TEST_RET_ENC_EC(ret);
  49025. ret = mp_cmp(a, r);
  49026. if (ret != MP_EQ)
  49027. return WC_TEST_RET_ENC_NC;
  49028. }
  49029. }
  49030. ret = mp_read_radix(r, badStr1, MP_RADIX_DEC);
  49031. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49032. return WC_TEST_RET_ENC_EC(ret);
  49033. ret = mp_read_radix(r, badStr2, MP_RADIX_DEC);
  49034. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49035. return WC_TEST_RET_ENC_EC(ret);
  49036. ret = mp_read_radix(r, empty2, MP_RADIX_DEC);
  49037. if (ret != MP_OKAY)
  49038. return WC_TEST_RET_ENC_EC(ret);
  49039. ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
  49040. if (ret != MP_OKAY)
  49041. return WC_TEST_RET_ENC_EC(ret);
  49042. if (!mp_iszero(r))
  49043. return WC_TEST_RET_ENC_NC;
  49044. mp_set(r, 1);
  49045. ret = mp_read_radix(r, empty, MP_RADIX_DEC);
  49046. if (ret != MP_OKAY)
  49047. return WC_TEST_RET_ENC_EC(ret);
  49048. if (!mp_iszero(r))
  49049. return WC_TEST_RET_ENC_NC;
  49050. mp_zero(a);
  49051. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49052. if (ret != 0)
  49053. return WC_TEST_RET_ENC_EC(ret);
  49054. if (size != 2)
  49055. return WC_TEST_RET_ENC_NC;
  49056. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49057. if (ret != 0)
  49058. return WC_TEST_RET_ENC_EC(ret);
  49059. if ((int)XSTRLEN(str) != size - 1)
  49060. return WC_TEST_RET_ENC_NC;
  49061. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49062. if (ret != 0)
  49063. return WC_TEST_RET_ENC_EC(ret);
  49064. if (!mp_iszero(r))
  49065. return WC_TEST_RET_ENC_NC;
  49066. return 0;
  49067. }
  49068. #endif
  49069. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  49070. defined(HAVE_ECC))
  49071. static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
  49072. {
  49073. wc_test_ret_t ret;
  49074. int i, j;
  49075. int size;
  49076. char str[30];
  49077. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49078. static char longStr[2 * sizeof(a->dp) + 2];
  49079. #endif
  49080. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49081. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
  49082. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49083. for (i = 0; i < 10; i++) {
  49084. for (j = 2; j < 12; j++) {
  49085. ret = randNum(a, j, rng, NULL);
  49086. if (ret != 0)
  49087. return WC_TEST_RET_ENC_EC(ret);
  49088. mp_radix_size(a, MP_RADIX_HEX, &size);
  49089. mp_toradix(a, str, MP_RADIX_HEX);
  49090. if ((int)XSTRLEN(str) != size - 1)
  49091. return WC_TEST_RET_ENC_NC;
  49092. mp_read_radix(r, str, MP_RADIX_HEX);
  49093. ret = mp_cmp(a, r);
  49094. if (ret != MP_EQ)
  49095. return WC_TEST_RET_ENC_NC;
  49096. }
  49097. }
  49098. ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
  49099. if (ret != MP_OKAY)
  49100. return WC_TEST_RET_ENC_EC(ret);
  49101. ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
  49102. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49103. return WC_TEST_RET_ENC_EC(ret);
  49104. mp_set(r, 1);
  49105. ret = mp_read_radix(r, empty, MP_RADIX_HEX);
  49106. if (ret != MP_OKAY)
  49107. return WC_TEST_RET_ENC_EC(ret);
  49108. if (!mp_iszero(r))
  49109. return WC_TEST_RET_ENC_NC;
  49110. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49111. /* Fixed MP data size - string can be too long. */
  49112. longStr[0] = '8';
  49113. XMEMSET(longStr+1, '0', sizeof(longStr) - 2);
  49114. longStr[sizeof(longStr)-1] = '\0';
  49115. ret = mp_read_radix(r, longStr, MP_RADIX_HEX);
  49116. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49117. return WC_TEST_RET_ENC_EC(ret);
  49118. #endif
  49119. mp_zero(a);
  49120. ret = mp_radix_size(a, MP_RADIX_HEX, &size);
  49121. if (ret != 0)
  49122. return WC_TEST_RET_ENC_EC(ret);
  49123. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  49124. if (size != 3)
  49125. #else
  49126. if (size != 2)
  49127. #endif
  49128. return WC_TEST_RET_ENC_NC;
  49129. ret = mp_toradix(a, str, MP_RADIX_HEX);
  49130. if (ret != 0)
  49131. return WC_TEST_RET_ENC_EC(ret);
  49132. if ((int)XSTRLEN(str) != size - 1)
  49133. return WC_TEST_RET_ENC_NC;
  49134. ret = mp_read_radix(r, str, MP_RADIX_HEX);
  49135. if (ret != 0)
  49136. return WC_TEST_RET_ENC_EC(ret);
  49137. if (!mp_iszero(r))
  49138. return WC_TEST_RET_ENC_NC;
  49139. #ifdef WOLFSSL_SP_MATH
  49140. ret = mp_toradix(a, str, 8);
  49141. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49142. return WC_TEST_RET_ENC_EC(ret);
  49143. ret = mp_radix_size(a, 8, &size);
  49144. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49145. return WC_TEST_RET_ENC_EC(ret);
  49146. #endif
  49147. return 0;
  49148. }
  49149. #endif
  49150. static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
  49151. {
  49152. int i;
  49153. wc_test_ret_t ret;
  49154. ret = randNum(a, 4, rng, NULL);
  49155. if (ret != 0)
  49156. return WC_TEST_RET_ENC_EC(ret);
  49157. for (i = 0; i < 4; i++) {
  49158. mp_copy(r1, a);
  49159. ret = mp_lshd(r1, i);
  49160. if (ret != MP_OKAY)
  49161. return WC_TEST_RET_ENC_EC(ret);
  49162. #ifndef WOLFSSL_SP_MATH
  49163. mp_rshd(r1, i);
  49164. #else
  49165. mp_rshb(r1, i * SP_WORD_SIZE);
  49166. #endif
  49167. ret = mp_cmp(a, r1);
  49168. if (ret != MP_EQ)
  49169. return WC_TEST_RET_ENC_NC;
  49170. }
  49171. #ifndef WOLFSSL_SP_MATH
  49172. for (i = 0; i < DIGIT_BIT+1; i++) {
  49173. ret = mp_mul_2d(a, i, r1);
  49174. if (ret != MP_OKAY)
  49175. return WC_TEST_RET_ENC_EC(ret);
  49176. mp_rshb(r1, i);
  49177. ret = mp_cmp(a, r1);
  49178. if (ret != MP_EQ)
  49179. return WC_TEST_RET_ENC_NC;
  49180. }
  49181. #endif
  49182. return 0;
  49183. }
  49184. static wc_test_ret_t mp_test_add_sub_d(mp_int* a, mp_int* r1)
  49185. {
  49186. int i, j;
  49187. wc_test_ret_t ret;
  49188. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49189. mp_zero(a);
  49190. mp_set_bit(a, i);
  49191. if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT)
  49192. return WC_TEST_RET_ENC_NC;
  49193. for (j = 0; j < i && j < DIGIT_BIT; j++) {
  49194. mp_zero(r1);
  49195. mp_set_bit(r1, i);
  49196. ret = mp_sub_d(r1, (mp_digit)1 << j, r1);
  49197. if (ret != MP_OKAY)
  49198. return WC_TEST_RET_ENC_EC(ret);
  49199. ret = mp_add_d(r1, (mp_digit)1 << j, r1);
  49200. if (ret != MP_OKAY)
  49201. return WC_TEST_RET_ENC_EC(ret);
  49202. ret = mp_cmp(a, r1);
  49203. if (ret != MP_EQ)
  49204. return WC_TEST_RET_ENC_NC;
  49205. }
  49206. }
  49207. mp_zero(r1);
  49208. ret = mp_add_d(r1, 1, r1);
  49209. if (ret != MP_OKAY)
  49210. return WC_TEST_RET_ENC_EC(ret);
  49211. if (r1->used != 1)
  49212. return WC_TEST_RET_ENC_NC;
  49213. ret = mp_sub_d(r1, 1, r1);
  49214. if (ret != MP_OKAY)
  49215. return WC_TEST_RET_ENC_EC(ret);
  49216. if (r1->used != 0)
  49217. return WC_TEST_RET_ENC_NC;
  49218. return 0;
  49219. }
  49220. static wc_test_ret_t mp_test_read_to_bin(mp_int* a)
  49221. {
  49222. WOLFSSL_SMALL_STACK_STATIC const byte in[16] = {
  49223. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7, 0x08,
  49224. 0x93, 0xa4, 0xb4, 0xc5, 0xd6, 0xe7, 0xf8, 0x09
  49225. };
  49226. byte out[24];
  49227. int i, j, k;
  49228. const byte* p;
  49229. wc_test_ret_t ret;
  49230. for (i = 0; i < (int)sizeof(in); i++) {
  49231. p = in + sizeof(in) - i;
  49232. ret = mp_read_unsigned_bin(a, p, (word32)i);
  49233. if (ret != 0)
  49234. return WC_TEST_RET_ENC_EC(ret);
  49235. for (j = i; j < (int)sizeof(out); j++) {
  49236. XMEMSET(out, 0xff, sizeof(out));
  49237. ret = mp_to_unsigned_bin_len(a, out, j);
  49238. if (ret != 0)
  49239. return WC_TEST_RET_ENC_EC(ret);
  49240. for (k = 0; k < j - i; k++) {
  49241. if (out[k] != 0)
  49242. return WC_TEST_RET_ENC_NC;
  49243. }
  49244. for (; k < j; k++) {
  49245. if (out[k] != p[k - (j - i)])
  49246. return WC_TEST_RET_ENC_NC;
  49247. }
  49248. }
  49249. }
  49250. /* Length too small. */
  49251. ret = mp_to_unsigned_bin_len(a, out, 1);
  49252. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49253. return WC_TEST_RET_ENC_EC(ret);
  49254. ret = mp_read_unsigned_bin(a, NULL, 0);
  49255. if (ret != 0)
  49256. return WC_TEST_RET_ENC_EC(ret);
  49257. if (!mp_iszero(a))
  49258. return WC_TEST_RET_ENC_NC;
  49259. return 0;
  49260. }
  49261. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49262. static wc_test_ret_t mp_test_set_int(mp_int* a)
  49263. {
  49264. #if SP_ULONG_BITS == 64
  49265. unsigned long n = 0xfedcba9876543210UL;
  49266. byte exp[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
  49267. byte out[8] = { 0 };
  49268. #elif SP_ULONG_BITS == 32
  49269. unsigned long n = 0xfedcba98UL;
  49270. byte exp[4] = { 0xfe, 0xdc, 0xba, 0x98 };
  49271. byte out[4] = { 0 };
  49272. #elif SP_ULONG_BITS == 16
  49273. unsigned long n = 0xfedc;
  49274. byte exp[2] = { 0xfe, 0xdc };
  49275. byte out[2] = { 0 };
  49276. #elif SP_ULONG_BITS == 8
  49277. unsigned long n = 0xfe;
  49278. byte exp[1] = { 0xfe };
  49279. byte out[1] = { 0 };
  49280. #endif
  49281. wc_test_ret_t ret;
  49282. ret = mp_set_int(a, n);
  49283. if (ret != 0)
  49284. return WC_TEST_RET_ENC_EC(ret);
  49285. ret = mp_unsigned_bin_size(a);
  49286. if (ret != sizeof(exp))
  49287. return WC_TEST_RET_ENC_NC;
  49288. ret = mp_to_unsigned_bin(a, out);
  49289. if (ret != 0)
  49290. return WC_TEST_RET_ENC_EC(ret);
  49291. if (XMEMCMP(exp, out, sizeof(exp)) != 0)
  49292. return WC_TEST_RET_ENC_NC;
  49293. return 0;
  49294. }
  49295. #endif
  49296. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49297. static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
  49298. {
  49299. byte buffer[16];
  49300. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49301. char hexStr[] = "abcdef0123456789";
  49302. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49303. char negStr[] = "-1234";
  49304. #endif
  49305. #endif
  49306. #if !defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
  49307. defined(HAVE_COMP_KEY)
  49308. char decStr[] = "0987654321";
  49309. #endif
  49310. wc_test_ret_t ret;
  49311. #ifdef WOLFSSL_SP_MATH_ALL
  49312. mp_digit rho;
  49313. int size;
  49314. #endif
  49315. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49316. int result;
  49317. #endif
  49318. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49319. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49320. mp_digit rd;
  49321. #endif
  49322. (void)rng;
  49323. (void)r;
  49324. ret = mp_init(NULL);
  49325. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49326. return WC_TEST_RET_ENC_EC(ret);
  49327. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49328. ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL);
  49329. if (ret != MP_OKAY)
  49330. return WC_TEST_RET_ENC_EC(ret);
  49331. #endif
  49332. mp_free(NULL);
  49333. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  49334. ret = mp_grow(NULL, 1);
  49335. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49336. return WC_TEST_RET_ENC_EC(ret);
  49337. #ifdef WOLFSSL_SP_MATH
  49338. ret = mp_grow(a, SP_INT_DIGITS + 1);
  49339. if (ret != WC_NO_ERR_TRACE(MP_MEM))
  49340. return WC_TEST_RET_ENC_EC(ret);
  49341. #endif
  49342. #endif
  49343. mp_clear(NULL);
  49344. ret = mp_abs(NULL, NULL);
  49345. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49346. return WC_TEST_RET_ENC_EC(ret);
  49347. ret = mp_abs(a, NULL);
  49348. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49349. return WC_TEST_RET_ENC_EC(ret);
  49350. ret = mp_abs(NULL, b);
  49351. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49352. return WC_TEST_RET_ENC_EC(ret);
  49353. ret = mp_unsigned_bin_size(NULL);
  49354. if (ret != 0)
  49355. return WC_TEST_RET_ENC_EC(ret);
  49356. /* clear buffer to avoid provoking uninitvar errors. */
  49357. XMEMSET(buffer, 0, sizeof(buffer));
  49358. ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer));
  49359. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49360. return WC_TEST_RET_ENC_EC(ret);
  49361. ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer));
  49362. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49363. return WC_TEST_RET_ENC_EC(ret);
  49364. ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
  49365. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49366. return WC_TEST_RET_ENC_EC(ret);
  49367. ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
  49368. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49369. return WC_TEST_RET_ENC_EC(ret);
  49370. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49371. ret = mp_read_radix(NULL, NULL, 16);
  49372. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49373. return WC_TEST_RET_ENC_EC(ret);
  49374. ret = mp_read_radix(a, NULL, 16);
  49375. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49376. return WC_TEST_RET_ENC_EC(ret);
  49377. ret = mp_read_radix(NULL, hexStr, 16);
  49378. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49379. return WC_TEST_RET_ENC_EC(ret);
  49380. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49381. ret = mp_read_radix(a, negStr, 16);
  49382. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49383. return WC_TEST_RET_ENC_EC(ret);
  49384. #ifdef WOLFSSL_SP_MATH_ALL
  49385. ret = mp_read_radix(a, negStr, 10);
  49386. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49387. return WC_TEST_RET_ENC_EC(ret);
  49388. #endif /* WOLFSSL_SP_MATH_ALL */
  49389. #endif /* WOLFSSL_SP_INT_NEGATIVE */
  49390. #endif
  49391. #ifndef WOLFSSL_SP_MATH_ALL
  49392. /* Radix 10 only supported with ALL. */
  49393. ret = mp_read_radix(a, decStr, 10);
  49394. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49395. return WC_TEST_RET_ENC_EC(ret);
  49396. #endif
  49397. /* Radix 8 not supported SP_INT. */
  49398. ret = mp_read_radix(a, "0123", 8);
  49399. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49400. return WC_TEST_RET_ENC_EC(ret);
  49401. ret = mp_count_bits(NULL);
  49402. if (ret != 0)
  49403. return WC_TEST_RET_ENC_EC(ret);
  49404. ret = mp_is_bit_set(NULL, 0);
  49405. if (ret != 0)
  49406. return WC_TEST_RET_ENC_EC(ret);
  49407. ret = mp_leading_bit(NULL);
  49408. if (ret != 0)
  49409. return WC_TEST_RET_ENC_EC(ret);
  49410. mp_zero(a);
  49411. ret = mp_leading_bit(a);
  49412. if (ret != 0)
  49413. return WC_TEST_RET_ENC_EC(ret);
  49414. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49415. defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \
  49416. !defined(NO_RSA)
  49417. ret = mp_set_bit(NULL, 1);
  49418. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49419. return WC_TEST_RET_ENC_EC(ret);
  49420. #endif
  49421. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49422. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49423. ret = mp_to_unsigned_bin(NULL, NULL);
  49424. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49425. return WC_TEST_RET_ENC_EC(ret);
  49426. ret = mp_to_unsigned_bin(a, NULL);
  49427. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49428. return WC_TEST_RET_ENC_EC(ret);
  49429. ret = mp_to_unsigned_bin(NULL, buffer);
  49430. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49431. return WC_TEST_RET_ENC_EC(ret);
  49432. #endif
  49433. ret = mp_to_unsigned_bin_len(NULL, NULL, 1);
  49434. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49435. return WC_TEST_RET_ENC_EC(ret);
  49436. ret = mp_to_unsigned_bin_len(a, NULL, 1);
  49437. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49438. return WC_TEST_RET_ENC_EC(ret);
  49439. ret = mp_to_unsigned_bin_len(NULL, buffer, 1);
  49440. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49441. return WC_TEST_RET_ENC_EC(ret);
  49442. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49443. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49444. ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL);
  49445. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49446. return WC_TEST_RET_ENC_EC(ret);
  49447. ret = mp_to_unsigned_bin_at_pos(0, a, NULL);
  49448. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49449. return WC_TEST_RET_ENC_EC(ret);
  49450. ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer);
  49451. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49452. return WC_TEST_RET_ENC_EC(ret);
  49453. ret = mp_to_unsigned_bin_at_pos(0, a, buffer);
  49454. if (ret != MP_OKAY)
  49455. return WC_TEST_RET_ENC_EC(ret);
  49456. #endif
  49457. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49458. ret = mp_copy(NULL, NULL);
  49459. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49460. return WC_TEST_RET_ENC_EC(ret);
  49461. ret = mp_copy(a, NULL);
  49462. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49463. return WC_TEST_RET_ENC_EC(ret);
  49464. ret = mp_copy(NULL, b);
  49465. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49466. return WC_TEST_RET_ENC_EC(ret);
  49467. #endif
  49468. #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH)
  49469. ret = sp_2expt(NULL, 1);
  49470. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49471. return WC_TEST_RET_ENC_EC(ret);
  49472. #endif
  49473. ret = mp_set(NULL, 0);
  49474. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49475. return WC_TEST_RET_ENC_EC(ret);
  49476. ret = mp_cmp_d(NULL, 0);
  49477. if (ret != MP_LT)
  49478. return WC_TEST_RET_ENC_EC(ret);
  49479. ret = mp_cmp(NULL, NULL);
  49480. if (ret != MP_EQ)
  49481. return WC_TEST_RET_ENC_NC;
  49482. ret = mp_cmp(a, NULL);
  49483. if (ret != MP_GT)
  49484. return WC_TEST_RET_ENC_NC;
  49485. ret = mp_cmp(NULL, b);
  49486. if (ret != MP_LT)
  49487. return WC_TEST_RET_ENC_NC;
  49488. #ifdef WOLFSSL_SP_MATH_ALL
  49489. mp_rshd(NULL, 1);
  49490. #endif
  49491. mp_zero(NULL);
  49492. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49493. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49494. ret = mp_lshd(NULL, 0);
  49495. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49496. return WC_TEST_RET_ENC_EC(ret);
  49497. ret = mp_lshd(a, SP_INT_DIGITS + 1);
  49498. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49499. return WC_TEST_RET_ENC_EC(ret);
  49500. #endif
  49501. #if defined(WOLFSSL_SP_MATH_ALL)
  49502. ret = mp_div(NULL, NULL, a, b);
  49503. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49504. return WC_TEST_RET_ENC_EC(ret);
  49505. ret = mp_div(a, NULL, a, b);
  49506. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49507. return WC_TEST_RET_ENC_EC(ret);
  49508. ret = mp_div(NULL, b, a, b);
  49509. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49510. return WC_TEST_RET_ENC_EC(ret);
  49511. ret = mp_div(a, b, NULL, NULL);
  49512. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49513. return WC_TEST_RET_ENC_EC(ret);
  49514. #endif
  49515. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49516. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49517. ret = mp_mod(NULL, NULL, NULL);
  49518. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49519. return WC_TEST_RET_ENC_EC(ret);
  49520. ret = mp_mod(a, NULL, NULL);
  49521. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49522. return WC_TEST_RET_ENC_EC(ret);
  49523. ret = mp_mod(NULL, b, NULL);
  49524. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49525. return WC_TEST_RET_ENC_EC(ret);
  49526. ret = mp_mod(NULL, NULL, r);
  49527. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49528. return WC_TEST_RET_ENC_EC(ret);
  49529. ret = mp_mod(a, b, NULL);
  49530. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49531. return WC_TEST_RET_ENC_EC(ret);
  49532. ret = mp_mod(a, NULL, r);
  49533. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49534. return WC_TEST_RET_ENC_EC(ret);
  49535. ret = mp_mod(NULL, b, r);
  49536. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49537. return WC_TEST_RET_ENC_EC(ret);
  49538. #endif
  49539. #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL)
  49540. ret = mp_set_int(NULL, 0);
  49541. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49542. return WC_TEST_RET_ENC_EC(ret);
  49543. #endif
  49544. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  49545. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  49546. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49547. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49548. return WC_TEST_RET_ENC_EC(ret);
  49549. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49550. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49551. return WC_TEST_RET_ENC_EC(ret);
  49552. ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL);
  49553. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49554. return WC_TEST_RET_ENC_EC(ret);
  49555. ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL);
  49556. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49557. return WC_TEST_RET_ENC_EC(ret);
  49558. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49559. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49560. return WC_TEST_RET_ENC_EC(ret);
  49561. ret = mp_exptmod_ex(a, a, 1, a, NULL);
  49562. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49563. return WC_TEST_RET_ENC_EC(ret);
  49564. ret = mp_exptmod_ex(a, a, 1, NULL, a);
  49565. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49566. return WC_TEST_RET_ENC_EC(ret);
  49567. ret = mp_exptmod_ex(a, NULL, 1, a, a);
  49568. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49569. return WC_TEST_RET_ENC_EC(ret);
  49570. ret = mp_exptmod_ex(NULL, a, 1, a, a);
  49571. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49572. return WC_TEST_RET_ENC_EC(ret);
  49573. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49574. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49575. return WC_TEST_RET_ENC_EC(ret);
  49576. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49577. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49578. return WC_TEST_RET_ENC_EC(ret);
  49579. ret = mp_exptmod_nct(NULL, a, NULL, NULL);
  49580. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49581. return WC_TEST_RET_ENC_EC(ret);
  49582. ret = mp_exptmod_nct(NULL, NULL, a, NULL);
  49583. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49584. return WC_TEST_RET_ENC_EC(ret);
  49585. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49586. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49587. return WC_TEST_RET_ENC_EC(ret);
  49588. ret = mp_exptmod_nct(a, a, a, NULL);
  49589. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49590. return WC_TEST_RET_ENC_EC(ret);
  49591. ret = mp_exptmod_nct(a, a, NULL, a);
  49592. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49593. return WC_TEST_RET_ENC_EC(ret);
  49594. ret = mp_exptmod_nct(a, NULL, a, a);
  49595. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49596. return WC_TEST_RET_ENC_EC(ret);
  49597. ret = mp_exptmod_nct(NULL, a, a, a);
  49598. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49599. return WC_TEST_RET_ENC_EC(ret);
  49600. #endif
  49601. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49602. !defined(WC_NO_RNG)
  49603. ret = mp_rand_prime(NULL, 32, NULL, NULL);
  49604. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49605. return WC_TEST_RET_ENC_EC(ret);
  49606. ret = mp_rand_prime(a, 32, NULL, NULL);
  49607. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49608. return WC_TEST_RET_ENC_EC(ret);
  49609. ret = mp_rand_prime(NULL, 32, rng, NULL);
  49610. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49611. return WC_TEST_RET_ENC_EC(ret);
  49612. ret = mp_rand_prime(a, 0, rng, NULL);
  49613. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49614. return WC_TEST_RET_ENC_EC(ret);
  49615. #endif
  49616. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49617. ret = mp_mul(NULL, NULL, NULL);
  49618. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49619. return WC_TEST_RET_ENC_EC(ret);
  49620. ret = mp_mul(a, NULL, NULL);
  49621. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49622. return WC_TEST_RET_ENC_EC(ret);
  49623. ret = mp_mul(NULL, b, NULL);
  49624. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49625. return WC_TEST_RET_ENC_EC(ret);
  49626. ret = mp_mul(NULL, NULL, r);
  49627. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49628. return WC_TEST_RET_ENC_EC(ret);
  49629. ret = mp_mul(a, b, NULL);
  49630. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49631. return WC_TEST_RET_ENC_EC(ret);
  49632. ret = mp_mul(a, NULL, r);
  49633. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49634. return WC_TEST_RET_ENC_EC(ret);
  49635. ret = mp_mul(NULL, b, r);
  49636. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49637. return WC_TEST_RET_ENC_EC(ret);
  49638. #endif
  49639. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49640. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49641. ret = mp_sqr(NULL, NULL);
  49642. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49643. return WC_TEST_RET_ENC_EC(ret);
  49644. ret = mp_sqr(a, NULL);
  49645. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49646. return WC_TEST_RET_ENC_EC(ret);
  49647. ret = mp_sqr(NULL, r);
  49648. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49649. return WC_TEST_RET_ENC_EC(ret);
  49650. #endif
  49651. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49652. ret = mp_sqrmod(NULL, NULL, NULL);
  49653. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49654. return WC_TEST_RET_ENC_EC(ret);
  49655. ret = mp_sqrmod(a, NULL, NULL);
  49656. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49657. return WC_TEST_RET_ENC_EC(ret);
  49658. ret = mp_sqrmod(NULL, a, NULL);
  49659. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49660. return WC_TEST_RET_ENC_EC(ret);
  49661. ret = mp_sqrmod(NULL, NULL, a);
  49662. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49663. return WC_TEST_RET_ENC_EC(ret);
  49664. ret = mp_sqrmod(a, b, NULL);
  49665. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49666. return WC_TEST_RET_ENC_EC(ret);
  49667. ret = mp_sqrmod(a, NULL, b);
  49668. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49669. return WC_TEST_RET_ENC_EC(ret);
  49670. ret = mp_sqrmod(NULL, a, b);
  49671. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49672. return WC_TEST_RET_ENC_EC(ret);
  49673. ret = mp_mulmod(NULL, NULL, NULL, NULL);
  49674. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49675. return WC_TEST_RET_ENC_EC(ret);
  49676. ret = mp_mulmod(a, NULL, NULL, NULL);
  49677. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49678. return WC_TEST_RET_ENC_EC(ret);
  49679. ret = mp_mulmod(NULL, a, NULL, NULL);
  49680. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49681. return WC_TEST_RET_ENC_EC(ret);
  49682. ret = mp_mulmod(NULL, NULL, a, NULL);
  49683. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49684. return WC_TEST_RET_ENC_EC(ret);
  49685. ret = mp_mulmod(NULL, NULL, NULL, a);
  49686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49687. return WC_TEST_RET_ENC_EC(ret);
  49688. ret = mp_mulmod(a, b, b, NULL);
  49689. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49690. return WC_TEST_RET_ENC_EC(ret);
  49691. ret = mp_mulmod(a, b, NULL, a);
  49692. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49693. return WC_TEST_RET_ENC_EC(ret);
  49694. ret = mp_mulmod(a, NULL, b, a);
  49695. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49696. return WC_TEST_RET_ENC_EC(ret);
  49697. ret = mp_mulmod(NULL, b, b, a);
  49698. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49699. return WC_TEST_RET_ENC_EC(ret);
  49700. #endif
  49701. #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
  49702. !defined(NO_RSA) || !defined(NO_DSA)
  49703. ret = mp_add_d(NULL, 1, NULL);
  49704. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49705. return WC_TEST_RET_ENC_EC(ret);
  49706. ret = mp_add_d(a, 1, NULL);
  49707. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49708. return WC_TEST_RET_ENC_EC(ret);
  49709. ret = mp_add_d(NULL, 1, b);
  49710. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49711. return WC_TEST_RET_ENC_EC(ret);
  49712. #endif
  49713. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49714. !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA)
  49715. ret = mp_sub_d(NULL, 1, NULL);
  49716. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49717. return WC_TEST_RET_ENC_EC(ret);
  49718. ret = mp_sub_d(a, 1, NULL);
  49719. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49720. return WC_TEST_RET_ENC_EC(ret);
  49721. ret = mp_sub_d(NULL, 1, b);
  49722. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49723. return WC_TEST_RET_ENC_EC(ret);
  49724. #endif
  49725. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49726. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49727. ret = mp_div_d(NULL, 0, NULL, NULL);
  49728. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49729. return WC_TEST_RET_ENC_EC(ret);
  49730. ret = mp_div_d(a, 0, NULL, NULL);
  49731. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49732. return WC_TEST_RET_ENC_EC(ret);
  49733. ret = mp_div_d(NULL, 1, NULL, NULL);
  49734. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49735. return WC_TEST_RET_ENC_EC(ret);
  49736. #endif
  49737. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49738. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49739. ret = mp_mod_d(NULL, 0, NULL);
  49740. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49741. return WC_TEST_RET_ENC_EC(ret);
  49742. ret = mp_mod_d(a, 0, NULL);
  49743. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49744. return WC_TEST_RET_ENC_EC(ret);
  49745. ret = mp_mod_d(NULL, 0, &rd);
  49746. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49747. return WC_TEST_RET_ENC_EC(ret);
  49748. #endif
  49749. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  49750. ret = mp_gcd(NULL, NULL, NULL);
  49751. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49752. return WC_TEST_RET_ENC_EC(ret);
  49753. ret = mp_gcd(a, NULL, NULL);
  49754. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49755. return WC_TEST_RET_ENC_EC(ret);
  49756. ret = mp_gcd(NULL, a, NULL);
  49757. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49758. return WC_TEST_RET_ENC_EC(ret);
  49759. ret = mp_gcd(NULL, NULL, a);
  49760. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49761. return WC_TEST_RET_ENC_EC(ret);
  49762. ret = mp_gcd(a, b, NULL);
  49763. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49764. return WC_TEST_RET_ENC_EC(ret);
  49765. ret = mp_gcd(a, NULL, b);
  49766. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49767. return WC_TEST_RET_ENC_EC(ret);
  49768. ret = mp_gcd(NULL, a, b);
  49769. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49770. return WC_TEST_RET_ENC_EC(ret);
  49771. #endif
  49772. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49773. ret = mp_div_2_mod_ct(NULL, NULL, NULL);
  49774. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49775. return WC_TEST_RET_ENC_EC(ret);
  49776. ret = mp_div_2_mod_ct(a, NULL, NULL);
  49777. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49778. return WC_TEST_RET_ENC_EC(ret);
  49779. ret = mp_div_2_mod_ct(NULL, b, NULL);
  49780. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49781. return WC_TEST_RET_ENC_EC(ret);
  49782. ret = mp_div_2_mod_ct(NULL, NULL, a);
  49783. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49784. return WC_TEST_RET_ENC_EC(ret);
  49785. ret = mp_div_2_mod_ct(a, b, NULL);
  49786. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49787. return WC_TEST_RET_ENC_EC(ret);
  49788. ret = mp_div_2_mod_ct(a, b, NULL);
  49789. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49790. return WC_TEST_RET_ENC_EC(ret);
  49791. ret = mp_div_2_mod_ct(NULL, b, a);
  49792. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49793. return WC_TEST_RET_ENC_EC(ret);
  49794. ret = mp_div_2(NULL, NULL);
  49795. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49796. return WC_TEST_RET_ENC_EC(ret);
  49797. ret = mp_div_2(a, NULL);
  49798. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49799. return WC_TEST_RET_ENC_EC(ret);
  49800. ret = mp_div_2(NULL, a);
  49801. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49802. return WC_TEST_RET_ENC_EC(ret);
  49803. #endif
  49804. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49805. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  49806. ret = mp_invmod(NULL, NULL, NULL);
  49807. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49808. return WC_TEST_RET_ENC_EC(ret);
  49809. ret = mp_invmod(a, NULL, NULL);
  49810. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49811. return WC_TEST_RET_ENC_EC(ret);
  49812. ret = mp_invmod(NULL, b, NULL);
  49813. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49814. return WC_TEST_RET_ENC_EC(ret);
  49815. ret = mp_invmod(NULL, NULL, a);
  49816. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49817. return WC_TEST_RET_ENC_EC(ret);
  49818. ret = mp_invmod(a, b, NULL);
  49819. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49820. return WC_TEST_RET_ENC_EC(ret);
  49821. ret = mp_invmod(a, NULL, a);
  49822. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49823. return WC_TEST_RET_ENC_EC(ret);
  49824. ret = mp_invmod(NULL, b, a);
  49825. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49826. return WC_TEST_RET_ENC_EC(ret);
  49827. #endif
  49828. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49829. ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1);
  49830. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49831. return WC_TEST_RET_ENC_EC(ret);
  49832. ret = mp_invmod_mont_ct(a, NULL, NULL, 1);
  49833. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49834. return WC_TEST_RET_ENC_EC(ret);
  49835. ret = mp_invmod_mont_ct(NULL, b, NULL, 1);
  49836. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49837. return WC_TEST_RET_ENC_EC(ret);
  49838. ret = mp_invmod_mont_ct(NULL, NULL, a, 1);
  49839. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49840. return WC_TEST_RET_ENC_EC(ret);
  49841. ret = mp_invmod_mont_ct(a, b, NULL, 1);
  49842. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49843. return WC_TEST_RET_ENC_EC(ret);
  49844. ret = mp_invmod_mont_ct(a, NULL, a, 1);
  49845. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49846. return WC_TEST_RET_ENC_EC(ret);
  49847. ret = mp_invmod_mont_ct(NULL, b, a, 1);
  49848. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49849. return WC_TEST_RET_ENC_EC(ret);
  49850. #endif
  49851. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49852. ret = mp_lcm(NULL, NULL, NULL);
  49853. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49854. return WC_TEST_RET_ENC_EC(ret);
  49855. ret = mp_lcm(a, NULL, NULL);
  49856. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49857. return WC_TEST_RET_ENC_EC(ret);
  49858. ret = mp_lcm(NULL, b, NULL);
  49859. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49860. return WC_TEST_RET_ENC_EC(ret);
  49861. ret = mp_lcm(NULL, NULL, a);
  49862. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49863. return WC_TEST_RET_ENC_EC(ret);
  49864. ret = mp_lcm(a, b, NULL);
  49865. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49866. return WC_TEST_RET_ENC_EC(ret);
  49867. ret = mp_lcm(a, NULL, a);
  49868. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49869. return WC_TEST_RET_ENC_EC(ret);
  49870. ret = mp_lcm(NULL, b, a);
  49871. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49872. return WC_TEST_RET_ENC_EC(ret);
  49873. #endif
  49874. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49875. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49876. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49877. return WC_TEST_RET_ENC_EC(ret);
  49878. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49879. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49880. return WC_TEST_RET_ENC_EC(ret);
  49881. ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL);
  49882. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49883. return WC_TEST_RET_ENC_EC(ret);
  49884. ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL);
  49885. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49886. return WC_TEST_RET_ENC_EC(ret);
  49887. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49888. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49889. return WC_TEST_RET_ENC_EC(ret);
  49890. ret = mp_exptmod_ex(a, b, 1, b, NULL);
  49891. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49892. return WC_TEST_RET_ENC_EC(ret);
  49893. ret = mp_exptmod_ex(a, b, 1, NULL, a);
  49894. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49895. return WC_TEST_RET_ENC_EC(ret);
  49896. ret = mp_exptmod_ex(a, NULL, 1, b, a);
  49897. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49898. return WC_TEST_RET_ENC_EC(ret);
  49899. ret = mp_exptmod_ex(NULL, b, 1, b, a);
  49900. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49901. return WC_TEST_RET_ENC_EC(ret);
  49902. ret = mp_exptmod(NULL, NULL, NULL, NULL);
  49903. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49904. return WC_TEST_RET_ENC_EC(ret);
  49905. ret = mp_exptmod(a, NULL, NULL, NULL);
  49906. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49907. return WC_TEST_RET_ENC_EC(ret);
  49908. ret = mp_exptmod(NULL, b, NULL, NULL);
  49909. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49910. return WC_TEST_RET_ENC_EC(ret);
  49911. ret = mp_exptmod(NULL, NULL, b, NULL);
  49912. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49913. return WC_TEST_RET_ENC_EC(ret);
  49914. ret = mp_exptmod(NULL, NULL, NULL, a);
  49915. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49916. return WC_TEST_RET_ENC_EC(ret);
  49917. ret = mp_exptmod(a, b, b, NULL);
  49918. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49919. return WC_TEST_RET_ENC_EC(ret);
  49920. ret = mp_exptmod(a, b, NULL, a);
  49921. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49922. return WC_TEST_RET_ENC_EC(ret);
  49923. ret = mp_exptmod(a, NULL, b, a);
  49924. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49925. return WC_TEST_RET_ENC_EC(ret);
  49926. ret = mp_exptmod(NULL, b, b, a);
  49927. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49928. return WC_TEST_RET_ENC_EC(ret);
  49929. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49930. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49931. return WC_TEST_RET_ENC_EC(ret);
  49932. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49933. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49934. return WC_TEST_RET_ENC_EC(ret);
  49935. ret = mp_exptmod_nct(NULL, b, NULL, NULL);
  49936. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49937. return WC_TEST_RET_ENC_EC(ret);
  49938. ret = mp_exptmod_nct(NULL, NULL, b, NULL);
  49939. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49940. return WC_TEST_RET_ENC_EC(ret);
  49941. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49942. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49943. return WC_TEST_RET_ENC_EC(ret);
  49944. ret = mp_exptmod_nct(a, b, b, NULL);
  49945. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49946. return WC_TEST_RET_ENC_EC(ret);
  49947. ret = mp_exptmod_nct(a, b, NULL, a);
  49948. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49949. return WC_TEST_RET_ENC_EC(ret);
  49950. ret = mp_exptmod_nct(a, NULL, b, a);
  49951. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49952. return WC_TEST_RET_ENC_EC(ret);
  49953. ret = mp_exptmod_nct(NULL, b, b, a);
  49954. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49955. return WC_TEST_RET_ENC_EC(ret);
  49956. #endif
  49957. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  49958. ret = mp_cnt_lsb(NULL);
  49959. if (ret != 0)
  49960. return WC_TEST_RET_ENC_EC(ret);
  49961. #endif
  49962. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49963. ret = mp_prime_is_prime(NULL, 1, NULL);
  49964. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49965. return WC_TEST_RET_ENC_EC(ret);
  49966. ret = mp_prime_is_prime(a, 1, NULL);
  49967. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49968. return WC_TEST_RET_ENC_EC(ret);
  49969. ret = mp_prime_is_prime(NULL, 1, &result);
  49970. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49971. return WC_TEST_RET_ENC_EC(ret);
  49972. ret = mp_prime_is_prime(a, 0, &result);
  49973. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49974. return WC_TEST_RET_ENC_EC(ret);
  49975. ret = mp_prime_is_prime(a, 1024, &result);
  49976. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49977. return WC_TEST_RET_ENC_EC(ret);
  49978. ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL);
  49979. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49980. return WC_TEST_RET_ENC_EC(ret);
  49981. ret = mp_prime_is_prime_ex(a, 1, NULL, NULL);
  49982. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49983. return WC_TEST_RET_ENC_EC(ret);
  49984. ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL);
  49985. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49986. return WC_TEST_RET_ENC_EC(ret);
  49987. ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng);
  49988. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49989. return WC_TEST_RET_ENC_EC(ret);
  49990. ret = mp_prime_is_prime_ex(a, 1, &result, NULL);
  49991. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49992. return WC_TEST_RET_ENC_EC(ret);
  49993. ret = mp_prime_is_prime_ex(a, 1, NULL, rng);
  49994. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49995. return WC_TEST_RET_ENC_EC(ret);
  49996. ret = mp_prime_is_prime_ex(NULL, 1, &result, rng);
  49997. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49998. return WC_TEST_RET_ENC_EC(ret);
  49999. #endif
  50000. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
  50001. ret = mp_exch(NULL, NULL);
  50002. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50003. return WC_TEST_RET_ENC_EC(ret);
  50004. ret = mp_exch(a, NULL);
  50005. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50006. return WC_TEST_RET_ENC_EC(ret);
  50007. ret = mp_exch(NULL, b);
  50008. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50009. return WC_TEST_RET_ENC_EC(ret);
  50010. #endif
  50011. #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \
  50012. defined(WOLFSSL_SP_MATH_ALL)
  50013. ret = mp_mul_d(NULL, 1, NULL);
  50014. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50015. return WC_TEST_RET_ENC_EC(ret);
  50016. ret = mp_mul_d(a, 1, NULL);
  50017. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50018. return WC_TEST_RET_ENC_EC(ret);
  50019. ret = mp_mul_d(NULL, 1, b);
  50020. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50021. return WC_TEST_RET_ENC_EC(ret);
  50022. #endif
  50023. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50024. ret = mp_add(NULL, NULL, NULL);
  50025. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50026. return WC_TEST_RET_ENC_EC(ret);
  50027. ret = mp_add(a, NULL, NULL);
  50028. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50029. return WC_TEST_RET_ENC_EC(ret);
  50030. ret = mp_add(NULL, b, NULL);
  50031. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50032. return WC_TEST_RET_ENC_EC(ret);
  50033. ret = mp_add(NULL, NULL, r);
  50034. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50035. return WC_TEST_RET_ENC_EC(ret);
  50036. ret = mp_add(a, b, NULL);
  50037. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50038. return WC_TEST_RET_ENC_EC(ret);
  50039. ret = mp_add(a, NULL, r);
  50040. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50041. return WC_TEST_RET_ENC_EC(ret);
  50042. ret = mp_add(NULL, b, r);
  50043. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50044. return WC_TEST_RET_ENC_EC(ret);
  50045. #endif
  50046. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50047. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50048. ret = mp_sub(NULL, NULL, NULL);
  50049. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50050. return WC_TEST_RET_ENC_EC(ret);
  50051. ret = mp_sub(a, NULL, NULL);
  50052. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50053. return WC_TEST_RET_ENC_EC(ret);
  50054. ret = mp_sub(NULL, b, NULL);
  50055. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50056. return WC_TEST_RET_ENC_EC(ret);
  50057. ret = mp_sub(NULL, NULL, r);
  50058. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50059. return WC_TEST_RET_ENC_EC(ret);
  50060. ret = mp_sub(a, b, NULL);
  50061. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50062. return WC_TEST_RET_ENC_EC(ret);
  50063. ret = mp_sub(a, NULL, r);
  50064. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50065. return WC_TEST_RET_ENC_EC(ret);
  50066. ret = mp_sub(NULL, b, r);
  50067. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50068. return WC_TEST_RET_ENC_EC(ret);
  50069. #endif
  50070. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
  50071. defined(WOLFSSL_CUSTOM_CURVES))
  50072. ret = mp_addmod(NULL, NULL, NULL, NULL);
  50073. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50074. return WC_TEST_RET_ENC_EC(ret);
  50075. ret = mp_addmod(a, NULL, NULL, NULL);
  50076. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50077. return WC_TEST_RET_ENC_EC(ret);
  50078. ret = mp_addmod(NULL, b, NULL, NULL);
  50079. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50080. return WC_TEST_RET_ENC_EC(ret);
  50081. ret = mp_addmod(NULL, NULL, b, NULL);
  50082. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50083. return WC_TEST_RET_ENC_EC(ret);
  50084. ret = mp_addmod(NULL, NULL, NULL, a);
  50085. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50086. return WC_TEST_RET_ENC_EC(ret);
  50087. ret = mp_addmod(a, b, b, NULL);
  50088. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50089. return WC_TEST_RET_ENC_EC(ret);
  50090. ret = mp_addmod(a, b, NULL, a);
  50091. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50092. return WC_TEST_RET_ENC_EC(ret);
  50093. ret = mp_addmod(a, NULL, b, a);
  50094. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50095. return WC_TEST_RET_ENC_EC(ret);
  50096. ret = mp_addmod(NULL, b, b, a);
  50097. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50098. return WC_TEST_RET_ENC_EC(ret);
  50099. #endif
  50100. #ifdef WOLFSSL_SP_MATH_ALL
  50101. ret = mp_submod(NULL, NULL, NULL, NULL);
  50102. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50103. return WC_TEST_RET_ENC_EC(ret);
  50104. ret = mp_submod(a, NULL, NULL, NULL);
  50105. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50106. return WC_TEST_RET_ENC_EC(ret);
  50107. ret = mp_submod(NULL, b, NULL, NULL);
  50108. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50109. return WC_TEST_RET_ENC_EC(ret);
  50110. ret = mp_submod(NULL, NULL, b, NULL);
  50111. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50112. return WC_TEST_RET_ENC_EC(ret);
  50113. ret = mp_submod(NULL, NULL, NULL, a);
  50114. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50115. return WC_TEST_RET_ENC_EC(ret);
  50116. ret = mp_submod(a, b, b, NULL);
  50117. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50118. return WC_TEST_RET_ENC_EC(ret);
  50119. ret = mp_submod(a, b, NULL, a);
  50120. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50121. return WC_TEST_RET_ENC_EC(ret);
  50122. ret = mp_submod(a, NULL, b, a);
  50123. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50124. return WC_TEST_RET_ENC_EC(ret);
  50125. ret = mp_submod(NULL, b, b, a);
  50126. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50127. return WC_TEST_RET_ENC_EC(ret);
  50128. #endif
  50129. #ifdef WOLFSSL_SP_MATH_ALL
  50130. ret = mp_div_2d(NULL, 1, a, b);
  50131. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50132. return WC_TEST_RET_ENC_EC(ret);
  50133. ret = mp_mod_2d(NULL, 1, NULL);
  50134. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50135. return WC_TEST_RET_ENC_EC(ret);
  50136. ret = mp_mod_2d(a, 1, NULL);
  50137. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50138. return WC_TEST_RET_ENC_EC(ret);
  50139. ret = mp_mod_2d(NULL, 1, b);
  50140. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50141. return WC_TEST_RET_ENC_EC(ret);
  50142. ret = mp_mul_2d(NULL, 1, NULL);
  50143. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50144. return WC_TEST_RET_ENC_EC(ret);
  50145. ret = mp_mul_2d(a, 1, NULL);
  50146. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50147. return WC_TEST_RET_ENC_EC(ret);
  50148. ret = mp_mul_2d(NULL, 1, b);
  50149. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50150. return WC_TEST_RET_ENC_EC(ret);
  50151. #endif
  50152. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50153. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50154. ret = mp_montgomery_reduce(NULL, NULL, 1);
  50155. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50156. return WC_TEST_RET_ENC_EC(ret);
  50157. ret = mp_montgomery_reduce(a, NULL, 1);
  50158. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50159. return WC_TEST_RET_ENC_EC(ret);
  50160. ret = mp_montgomery_reduce(NULL, b, 1);
  50161. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50162. return WC_TEST_RET_ENC_EC(ret);
  50163. mp_zero(b);
  50164. ret = mp_montgomery_reduce(a, b, 1);
  50165. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50166. return WC_TEST_RET_ENC_EC(ret);
  50167. #endif
  50168. #ifdef WOLFSSL_SP_MATH_ALL
  50169. ret = mp_montgomery_setup(NULL, NULL);
  50170. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50171. return WC_TEST_RET_ENC_EC(ret);
  50172. ret = mp_montgomery_setup(a, NULL);
  50173. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50174. return WC_TEST_RET_ENC_EC(ret);
  50175. ret = mp_montgomery_setup(NULL, &rho);
  50176. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50177. return WC_TEST_RET_ENC_EC(ret);
  50178. ret = mp_montgomery_calc_normalization(NULL, NULL);
  50179. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50180. return WC_TEST_RET_ENC_EC(ret);
  50181. ret = mp_montgomery_calc_normalization(a, NULL);
  50182. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50183. return WC_TEST_RET_ENC_EC(ret);
  50184. ret = mp_montgomery_calc_normalization(NULL, b);
  50185. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50186. return WC_TEST_RET_ENC_EC(ret);
  50187. #endif
  50188. ret = mp_unsigned_bin_size(NULL);
  50189. if (ret != 0)
  50190. return WC_TEST_RET_ENC_EC(ret);
  50191. #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL)
  50192. ret = mp_tohex(NULL, NULL);
  50193. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50194. return WC_TEST_RET_ENC_EC(ret);
  50195. ret = mp_tohex(a, NULL);
  50196. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50197. return WC_TEST_RET_ENC_EC(ret);
  50198. ret = mp_tohex(NULL, hexStr);
  50199. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50200. return WC_TEST_RET_ENC_EC(ret);
  50201. #endif
  50202. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  50203. ret = mp_todecimal(NULL, NULL);
  50204. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50205. return WC_TEST_RET_ENC_EC(ret);
  50206. ret = mp_todecimal(a, NULL);
  50207. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50208. return WC_TEST_RET_ENC_EC(ret);
  50209. ret = mp_todecimal(NULL, decStr);
  50210. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50211. return WC_TEST_RET_ENC_EC(ret);
  50212. #endif
  50213. #ifdef WOLFSSL_SP_MATH_ALL
  50214. ret = mp_toradix(NULL, NULL, MP_RADIX_HEX);
  50215. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50216. return WC_TEST_RET_ENC_EC(ret);
  50217. ret = mp_toradix(a, NULL, MP_RADIX_HEX);
  50218. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50219. return WC_TEST_RET_ENC_EC(ret);
  50220. ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX);
  50221. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50222. return WC_TEST_RET_ENC_EC(ret);
  50223. ret = mp_toradix(a, hexStr, 3);
  50224. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50225. return WC_TEST_RET_ENC_EC(ret);
  50226. ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL);
  50227. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50228. return WC_TEST_RET_ENC_EC(ret);
  50229. ret = mp_radix_size(a, MP_RADIX_HEX, NULL);
  50230. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50231. return WC_TEST_RET_ENC_EC(ret);
  50232. ret = mp_radix_size(NULL, MP_RADIX_HEX, &size);
  50233. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50234. return WC_TEST_RET_ENC_EC(ret);
  50235. ret = mp_radix_size(a, 3, &size);
  50236. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50237. return WC_TEST_RET_ENC_EC(ret);
  50238. #endif
  50239. return 0;
  50240. }
  50241. #endif
  50242. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50243. static wc_test_ret_t mp_test_set_is_bit(mp_int* a)
  50244. {
  50245. int i, j;
  50246. wc_test_ret_t ret;
  50247. mp_zero(a);
  50248. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50249. if (mp_is_bit_set(a, i))
  50250. return WC_TEST_RET_ENC_NC;
  50251. for (j = 0; j < i; j++) {
  50252. if (!mp_is_bit_set(a, j))
  50253. return WC_TEST_RET_ENC_NC;
  50254. }
  50255. if (mp_set_bit(a, i) != 0)
  50256. return WC_TEST_RET_ENC_NC;
  50257. if (!mp_is_bit_set(a, i))
  50258. return WC_TEST_RET_ENC_NC;
  50259. }
  50260. mp_zero(a);
  50261. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50262. if (mp_is_bit_set(a, i))
  50263. return WC_TEST_RET_ENC_NC;
  50264. }
  50265. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50266. mp_zero(a);
  50267. if (mp_set_bit(a, i) != 0)
  50268. return WC_TEST_RET_ENC_NC;
  50269. for (j = 0; j < i; j++) {
  50270. if (mp_is_bit_set(a, j))
  50271. return WC_TEST_RET_ENC_NC;
  50272. }
  50273. if (!mp_is_bit_set(a, i))
  50274. return WC_TEST_RET_ENC_NC;
  50275. }
  50276. #ifdef WOLFSSL_KEY_GEN
  50277. for (i = 0; i < DIGIT_BIT * 2; i++) {
  50278. mp_set(a, 1);
  50279. ret = mp_2expt(a, i);
  50280. if (ret != 0)
  50281. return WC_TEST_RET_ENC_EC(ret);
  50282. for (j = 0; j < i; j++) {
  50283. if (mp_is_bit_set(a, j))
  50284. return WC_TEST_RET_ENC_NC;
  50285. }
  50286. if (!mp_is_bit_set(a, i))
  50287. return WC_TEST_RET_ENC_NC;
  50288. }
  50289. #endif
  50290. #ifdef WOLFSSL_SP_MATH
  50291. mp_zero(a);
  50292. for (j = 1; j <= 3; j++) {
  50293. i = SP_INT_MAX_BITS - j;
  50294. if (mp_is_bit_set(a, i))
  50295. return WC_TEST_RET_ENC_NC;
  50296. if (mp_set_bit(a, i) != 0)
  50297. return WC_TEST_RET_ENC_NC;
  50298. if (!mp_is_bit_set(a, i))
  50299. return WC_TEST_RET_ENC_NC;
  50300. #ifdef WOLFSSL_KEY_GEN
  50301. ret = mp_2expt(a, i);
  50302. if (ret != 0)
  50303. return WC_TEST_RET_ENC_EC(ret);
  50304. if (!mp_is_bit_set(a, i))
  50305. return WC_TEST_RET_ENC_NC;
  50306. #endif
  50307. }
  50308. mp_zero(a);
  50309. for (j = 0; j <= 3; j++) {
  50310. i = SP_INT_MAX_BITS + j;
  50311. if (mp_is_bit_set(a, i))
  50312. return WC_TEST_RET_ENC_NC;
  50313. if (mp_set_bit(a, i) != WC_NO_ERR_TRACE(MP_VAL))
  50314. return WC_TEST_RET_ENC_NC;
  50315. #ifdef WOLFSSL_KEY_GEN
  50316. ret = mp_2expt(a, i);
  50317. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50318. return WC_TEST_RET_ENC_EC(ret);
  50319. #endif
  50320. }
  50321. #endif
  50322. (void)ret;
  50323. return 0;
  50324. }
  50325. #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */
  50326. static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
  50327. {
  50328. wc_test_ret_t ret;
  50329. mp_zero(a);
  50330. mp_zero(b);
  50331. ret = mp_cmp_d(a, 0);
  50332. if (ret != MP_EQ)
  50333. return WC_TEST_RET_ENC_EC(ret);
  50334. ret = mp_cmp_d(a, 1);
  50335. if (ret != MP_LT)
  50336. return WC_TEST_RET_ENC_EC(ret);
  50337. ret = mp_cmp(a, b);
  50338. if (ret != MP_EQ)
  50339. return WC_TEST_RET_ENC_NC;
  50340. mp_set(a, 1);
  50341. ret = mp_cmp_d(a, 0);
  50342. if (ret != MP_GT)
  50343. return WC_TEST_RET_ENC_EC(ret);
  50344. ret = mp_cmp_d(a, 1);
  50345. if (ret != MP_EQ)
  50346. return WC_TEST_RET_ENC_EC(ret);
  50347. ret = mp_cmp_d(a, 2);
  50348. if (ret != MP_LT)
  50349. return WC_TEST_RET_ENC_EC(ret);
  50350. ret = mp_cmp(a, b);
  50351. if (ret != MP_GT)
  50352. return WC_TEST_RET_ENC_NC;
  50353. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50354. mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX);
  50355. ret = mp_cmp_d(b, -1);
  50356. if (ret != MP_GT)
  50357. return WC_TEST_RET_ENC_EC(ret);
  50358. ret = mp_cmp(a, b);
  50359. if (ret != MP_LT)
  50360. return WC_TEST_RET_ENC_NC;
  50361. ret = mp_cmp(b, a);
  50362. if (ret != MP_GT)
  50363. return WC_TEST_RET_ENC_NC;
  50364. ret = mp_cmp(b, b);
  50365. if (ret != MP_EQ)
  50366. return WC_TEST_RET_ENC_NC;
  50367. #endif
  50368. #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
  50369. defined(WOLFSSL_SP_INT_NEGATIVE)
  50370. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50371. mp_read_radix(a, "-1", MP_RADIX_HEX);
  50372. mp_read_radix(a, "1", MP_RADIX_HEX);
  50373. ret = mp_cmp(a, b);
  50374. if (ret != MP_LT)
  50375. return WC_TEST_RET_ENC_NC;
  50376. ret = mp_cmp(b, a);
  50377. if (ret != MP_GT)
  50378. return WC_TEST_RET_ENC_NC;
  50379. mp_read_radix(b, "-2", MP_RADIX_HEX);
  50380. ret = mp_cmp(a, b);
  50381. if (ret != MP_GT)
  50382. return WC_TEST_RET_ENC_NC;
  50383. ret = mp_cmp(b, a);
  50384. if (ret != MP_LT)
  50385. return WC_TEST_RET_ENC_NC;
  50386. #endif
  50387. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50388. mp_read_radix(a, "-2", MP_RADIX_HEX);
  50389. ret = mp_cmp(a, b);
  50390. if (ret != MP_EQ)
  50391. return WC_TEST_RET_ENC_NC;
  50392. #endif
  50393. #endif
  50394. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  50395. defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING)
  50396. mp_zero(a);
  50397. mp_zero(b);
  50398. ret = mp_cmp_ct(a, b, 1);
  50399. if (ret != MP_EQ)
  50400. return WC_TEST_RET_ENC_EC(ret);
  50401. ret = mp_cmp_ct(a, a, a->used);
  50402. if (ret != MP_EQ)
  50403. return WC_TEST_RET_ENC_EC(ret);
  50404. #ifdef WOLFSSL_SP_MATH_ALL
  50405. ret = mp_cmp_ct(a, NULL, a->used);
  50406. if (ret != MP_GT)
  50407. return WC_TEST_RET_ENC_EC(ret);
  50408. ret = mp_cmp_ct(NULL, a, a->used);
  50409. if (ret != MP_LT)
  50410. return WC_TEST_RET_ENC_EC(ret);
  50411. #endif
  50412. mp_read_radix(a, "1", MP_RADIX_HEX);
  50413. ret = mp_cmp_ct(a, b, 1);
  50414. if (ret != MP_GT)
  50415. return WC_TEST_RET_ENC_EC(ret);
  50416. ret = mp_cmp_ct(b, a, 1);
  50417. if (ret != MP_LT)
  50418. return WC_TEST_RET_ENC_EC(ret);
  50419. mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50420. ret = mp_cmp_ct(a, b, a->used);
  50421. if (ret != MP_GT)
  50422. return WC_TEST_RET_ENC_EC(ret);
  50423. ret = mp_cmp_ct(b, a, a->used);
  50424. if (ret != MP_LT)
  50425. return WC_TEST_RET_ENC_EC(ret);
  50426. mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50427. ret = mp_cmp_ct(b, a, a->used);
  50428. if (ret != MP_GT)
  50429. return WC_TEST_RET_ENC_EC(ret);
  50430. ret = mp_cmp_ct(a, b, a->used);
  50431. if (ret != MP_LT)
  50432. return WC_TEST_RET_ENC_EC(ret);
  50433. mp_read_radix(b, "0123456789abcdef0123456789abcdf0", MP_RADIX_HEX);
  50434. ret = mp_cmp_ct(b, a, a->used);
  50435. if (ret != MP_GT)
  50436. return WC_TEST_RET_ENC_EC(ret);
  50437. ret = mp_cmp_ct(a, b, a->used);
  50438. if (ret != MP_LT)
  50439. return WC_TEST_RET_ENC_EC(ret);
  50440. mp_read_radix(b, "0123456789abcdf0", MP_RADIX_HEX);
  50441. ret = mp_cmp_ct(a, b, a->used);
  50442. if (ret != MP_GT)
  50443. return WC_TEST_RET_ENC_EC(ret);
  50444. ret = mp_cmp_ct(b, a, a->used);
  50445. if (ret != MP_LT)
  50446. return WC_TEST_RET_ENC_EC(ret);
  50447. #endif
  50448. return 0;
  50449. }
  50450. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50451. static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
  50452. {
  50453. wc_test_ret_t ret;
  50454. int i, j, k;
  50455. #ifndef WOLFSSL_SP_MATH
  50456. for (i = 0; i < 10; i++) {
  50457. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50458. ret = randNum(a, j, rng, NULL);
  50459. if (ret != MP_OKAY)
  50460. return WC_TEST_RET_ENC_EC(ret);
  50461. mp_copy(a, b);
  50462. for (k = 0; k <= DIGIT_BIT * 2; k++) {
  50463. ret = mp_mul_2d(a, k, a);
  50464. if (ret != MP_OKAY)
  50465. return WC_TEST_RET_ENC_EC(ret);
  50466. mp_rshb(a, k);
  50467. ret = mp_cmp(a, b);
  50468. if (ret != MP_EQ)
  50469. return WC_TEST_RET_ENC_NC;
  50470. }
  50471. }
  50472. }
  50473. #endif
  50474. for (i = 0; i < 10; i++) {
  50475. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50476. ret = randNum(a, j, rng, NULL);
  50477. if (ret != MP_OKAY)
  50478. return WC_TEST_RET_ENC_EC(ret);
  50479. mp_copy(a, b);
  50480. for (k = 0; k < 10; k++) {
  50481. ret = mp_lshd(a, k);
  50482. if (ret != MP_OKAY)
  50483. return WC_TEST_RET_ENC_EC(ret);
  50484. #ifndef WOLFSSL_SP_MATH
  50485. mp_rshd(a, k);
  50486. #else
  50487. mp_rshb(a, k * SP_WORD_SIZE);
  50488. #endif
  50489. ret = mp_cmp(a, b);
  50490. if (ret != MP_EQ)
  50491. return WC_TEST_RET_ENC_NC;
  50492. }
  50493. }
  50494. }
  50495. #ifndef WOLFSSL_SP_MATH
  50496. mp_zero(a);
  50497. mp_rshd(a, 1);
  50498. if (!mp_iszero(a))
  50499. return WC_TEST_RET_ENC_NC;
  50500. mp_set(a, 1);
  50501. mp_rshd(a, 1);
  50502. if (!mp_iszero(a))
  50503. return WC_TEST_RET_ENC_NC;
  50504. mp_set(a, 1);
  50505. mp_rshd(a, 2);
  50506. if (!mp_iszero(a))
  50507. return WC_TEST_RET_ENC_NC;
  50508. #endif
  50509. return 0;
  50510. }
  50511. #endif
  50512. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50513. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  50514. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50515. static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
  50516. WC_RNG* rng)
  50517. {
  50518. wc_test_ret_t ret;
  50519. int i, j, k;
  50520. mp_zero(a);
  50521. mp_zero(d);
  50522. ret = mp_div(a, d, r, rem);
  50523. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50524. return WC_TEST_RET_ENC_EC(ret);
  50525. mp_set(d, 1);
  50526. ret = mp_div(a, d, r, rem);
  50527. if (ret != MP_OKAY)
  50528. return WC_TEST_RET_ENC_EC(ret);
  50529. if (!mp_iszero(r))
  50530. return WC_TEST_RET_ENC_EC(ret);
  50531. if (!mp_iszero(rem))
  50532. return WC_TEST_RET_ENC_EC(ret);
  50533. mp_set(a, 1);
  50534. ret = mp_div(a, d, r, rem);
  50535. if (ret != MP_OKAY)
  50536. return WC_TEST_RET_ENC_EC(ret);
  50537. if (!mp_isone(r))
  50538. return WC_TEST_RET_ENC_EC(ret);
  50539. if (!mp_iszero(rem))
  50540. return WC_TEST_RET_ENC_EC(ret);
  50541. for (i = 0; i < 100; i++) {
  50542. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) {
  50543. ret = randNum(d, j, rng, NULL);
  50544. if (ret != MP_OKAY)
  50545. return WC_TEST_RET_ENC_EC(ret);
  50546. for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) {
  50547. ret = randNum(a, k, rng, NULL);
  50548. if (ret != MP_OKAY)
  50549. return WC_TEST_RET_ENC_EC(ret);
  50550. ret = mp_div(a, d, NULL, rem);
  50551. if (ret != MP_OKAY)
  50552. return WC_TEST_RET_ENC_EC(ret);
  50553. ret = mp_div(a, d, r, NULL);
  50554. if (ret != MP_OKAY)
  50555. return WC_TEST_RET_ENC_EC(ret);
  50556. ret = mp_div(a, d, r, rem);
  50557. if (ret != MP_OKAY)
  50558. return WC_TEST_RET_ENC_EC(ret);
  50559. mp_mul(r, d, r);
  50560. mp_add(r, rem, r);
  50561. if (mp_cmp(r, a) != MP_EQ)
  50562. return WC_TEST_RET_ENC_NC;
  50563. }
  50564. }
  50565. }
  50566. ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL);
  50567. if (ret != MP_OKAY)
  50568. return WC_TEST_RET_ENC_EC(ret);
  50569. mp_add(d, d, a);
  50570. mp_set(rem, 1);
  50571. mp_div(a, d, NULL, rem);
  50572. if (ret != MP_OKAY)
  50573. return WC_TEST_RET_ENC_EC(ret);
  50574. if (!mp_iszero(rem))
  50575. return WC_TEST_RET_ENC_EC(ret);
  50576. mp_set(r, 1);
  50577. mp_div(a, d, r, NULL);
  50578. if (ret != MP_OKAY)
  50579. return WC_TEST_RET_ENC_EC(ret);
  50580. if (mp_cmp_d(r, 2) != MP_EQ)
  50581. return WC_TEST_RET_ENC_EC(ret);
  50582. mp_set(r, 1);
  50583. mp_set(rem, 1);
  50584. mp_div(a, d, r, rem);
  50585. if (ret != MP_OKAY)
  50586. return WC_TEST_RET_ENC_EC(ret);
  50587. if (mp_cmp_d(r, 2) != MP_EQ)
  50588. return WC_TEST_RET_ENC_EC(ret);
  50589. if (!mp_iszero(rem))
  50590. return WC_TEST_RET_ENC_EC(ret);
  50591. mp_set(a, 0xfe);
  50592. mp_lshd(a, 3);
  50593. mp_add_d(a, 0xff, a);
  50594. mp_set(d, 0xfe);
  50595. mp_lshd(d, 2);
  50596. ret = mp_div(a, d, r, rem);
  50597. if (ret != MP_OKAY)
  50598. return WC_TEST_RET_ENC_EC(ret);
  50599. mp_mul(r, d, d);
  50600. mp_add(rem, d, d);
  50601. if (mp_cmp(a, d) != MP_EQ)
  50602. return WC_TEST_RET_ENC_NC;
  50603. /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in
  50604. * a digit. So mp_div must detect and handle.
  50605. * For example: 0x800000 / 0x8001, DIGIT_BIT = 8
  50606. */
  50607. mp_zero(a);
  50608. mp_set_bit(a, DIGIT_BIT * 3 - 1);
  50609. mp_zero(d);
  50610. mp_set_bit(d, DIGIT_BIT * 2 - 1);
  50611. mp_add_d(d, 1, d);
  50612. ret = mp_div(a, d, r, rem);
  50613. if (ret != MP_OKAY)
  50614. return WC_TEST_RET_ENC_EC(ret);
  50615. /* Make sure [d | d] / d is handled. */
  50616. mp_zero(a);
  50617. mp_set_bit(a, DIGIT_BIT * 2 - 1);
  50618. mp_set_bit(a, DIGIT_BIT * 1 - 1);
  50619. mp_zero(d);
  50620. mp_set_bit(d, DIGIT_BIT - 1);
  50621. ret = mp_div(a, d, r, rem);
  50622. if (ret != MP_OKAY)
  50623. return WC_TEST_RET_ENC_EC(ret);
  50624. mp_zero(a);
  50625. mp_set_bit(a, DIGIT_BIT);
  50626. mp_set_bit(a, 0);
  50627. mp_zero(d);
  50628. if (mp_cmp(r, a) != MP_EQ)
  50629. return WC_TEST_RET_ENC_NC;
  50630. if (mp_cmp(rem, d) != MP_EQ)
  50631. return WC_TEST_RET_ENC_NC;
  50632. return 0;
  50633. }
  50634. #endif
  50635. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50636. !defined(WC_NO_RNG)
  50637. static wc_test_ret_t mp_test_prime(mp_int* a, WC_RNG* rng)
  50638. {
  50639. wc_test_ret_t ret;
  50640. int res;
  50641. ret = mp_rand_prime(a, 1, rng, NULL);
  50642. #if defined(WOLFSSL_SP_MATH_ALL)
  50643. if (ret != 0)
  50644. return WC_TEST_RET_ENC_EC(ret);
  50645. #else
  50646. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50647. return WC_TEST_RET_ENC_NC;
  50648. #endif
  50649. #ifndef WOLFSSL_SP_MATH
  50650. ret = mp_rand_prime(a, -5, rng, NULL);
  50651. if (ret != 0 || (a->dp[0] & 3) != 3)
  50652. return WC_TEST_RET_ENC_NC;
  50653. #endif
  50654. ret = mp_prime_is_prime(a, 1, &res);
  50655. if (ret != MP_OKAY)
  50656. return WC_TEST_RET_ENC_EC(ret);
  50657. #ifndef WOLFSSL_SP_MATH
  50658. if (res != MP_YES)
  50659. return WC_TEST_RET_ENC_EC(res);
  50660. #else
  50661. if (res != MP_NO)
  50662. return WC_TEST_RET_ENC_EC(res);
  50663. #endif
  50664. ret = mp_prime_is_prime(a, 0, &res);
  50665. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50666. return WC_TEST_RET_ENC_EC(ret);
  50667. ret = mp_prime_is_prime(a, -1, &res);
  50668. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50669. return WC_TEST_RET_ENC_EC(ret);
  50670. ret = mp_prime_is_prime(a, 257, &res);
  50671. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50672. return WC_TEST_RET_ENC_EC(ret);
  50673. mp_set(a, 1);
  50674. ret = mp_prime_is_prime(a, 1, &res);
  50675. if (ret != MP_OKAY)
  50676. return WC_TEST_RET_ENC_EC(ret);
  50677. if (res != MP_NO)
  50678. return WC_TEST_RET_ENC_EC(res);
  50679. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50680. if (ret != MP_OKAY)
  50681. return WC_TEST_RET_ENC_EC(ret);
  50682. if (res != MP_NO)
  50683. return WC_TEST_RET_ENC_EC(res);
  50684. mp_set(a, 2);
  50685. ret = mp_prime_is_prime(a, 1, &res);
  50686. if (ret != MP_OKAY)
  50687. return WC_TEST_RET_ENC_EC(ret);
  50688. if (res != MP_YES)
  50689. return WC_TEST_RET_ENC_EC(res);
  50690. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50691. if (ret != MP_OKAY)
  50692. return WC_TEST_RET_ENC_EC(ret);
  50693. if (res != MP_YES)
  50694. return WC_TEST_RET_ENC_EC(res);
  50695. mp_set(a, 0xfb);
  50696. ret = mp_prime_is_prime(a, 1, &res);
  50697. if (ret != MP_OKAY)
  50698. return WC_TEST_RET_ENC_EC(ret);
  50699. if (res != MP_YES)
  50700. return WC_TEST_RET_ENC_EC(res);
  50701. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50702. if (ret != MP_OKAY)
  50703. return WC_TEST_RET_ENC_EC(ret);
  50704. if (res != MP_YES)
  50705. return WC_TEST_RET_ENC_EC(res);
  50706. mp_set(a, 0x6);
  50707. ret = mp_prime_is_prime(a, 1, &res);
  50708. if (ret != MP_OKAY)
  50709. return WC_TEST_RET_ENC_EC(ret);
  50710. if (res != MP_NO)
  50711. return WC_TEST_RET_ENC_EC(res);
  50712. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50713. if (ret != MP_OKAY)
  50714. return WC_TEST_RET_ENC_EC(ret);
  50715. if (res != MP_NO)
  50716. return WC_TEST_RET_ENC_EC(res);
  50717. mp_set_int(a, 0x655 * 0x65b);
  50718. ret = mp_prime_is_prime(a, 10, &res);
  50719. if (ret != MP_OKAY)
  50720. return WC_TEST_RET_ENC_EC(ret);
  50721. if (res != MP_NO)
  50722. return WC_TEST_RET_ENC_EC(res);
  50723. ret = mp_prime_is_prime_ex(a, 10, &res, rng);
  50724. if (ret != MP_OKAY)
  50725. return WC_TEST_RET_ENC_EC(ret);
  50726. if (res != MP_NO)
  50727. return WC_TEST_RET_ENC_EC(res);
  50728. return 0;
  50729. }
  50730. #endif
  50731. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50732. static wc_test_ret_t mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp,
  50733. WC_RNG* rng)
  50734. {
  50735. wc_test_ret_t ret;
  50736. int i;
  50737. WOLFSSL_SMALL_STACK_STATIC const int kat[][3] = {
  50738. { 1, 1, 1 }, { 2, 1, 2 }, { 1, 2, 2 }, { 2, 4, 4 }, { 4, 2, 4 },
  50739. { 12, 56, 168 }, { 56, 12, 168 }
  50740. };
  50741. (void)exp;
  50742. mp_set(a, 0);
  50743. mp_set(b, 1);
  50744. ret = mp_lcm(a, a, r);
  50745. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50746. return WC_TEST_RET_ENC_EC(ret);
  50747. ret = mp_lcm(a, b, r);
  50748. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50749. return WC_TEST_RET_ENC_EC(ret);
  50750. ret = mp_lcm(b, a, r);
  50751. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50752. return WC_TEST_RET_ENC_EC(ret);
  50753. for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) {
  50754. mp_set(a, kat[i][0]);
  50755. mp_set(b, kat[i][1]);
  50756. ret = mp_lcm(a, b, r);
  50757. if (ret != MP_OKAY)
  50758. return WC_TEST_RET_ENC_EC(ret);
  50759. mp_set(exp, kat[i][2]);
  50760. ret = mp_cmp(r, exp);
  50761. if (ret != MP_EQ)
  50762. return WC_TEST_RET_ENC_NC;
  50763. }
  50764. (void)rng;
  50765. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50766. !defined(WC_NO_RNG)
  50767. ret = mp_rand_prime(a, 20, rng, NULL);
  50768. if (ret != MP_OKAY)
  50769. return WC_TEST_RET_ENC_EC(ret);
  50770. ret = mp_rand_prime(b, 20, rng, NULL);
  50771. if (ret != MP_OKAY)
  50772. return WC_TEST_RET_ENC_EC(ret);
  50773. ret = mp_mul(a, b, exp);
  50774. if (ret != MP_OKAY)
  50775. return WC_TEST_RET_ENC_EC(ret);
  50776. ret = mp_lcm(a, b, r);
  50777. if (ret != MP_OKAY)
  50778. return WC_TEST_RET_ENC_EC(ret);
  50779. ret = mp_cmp(r, exp);
  50780. if (ret != MP_EQ)
  50781. return WC_TEST_RET_ENC_NC;
  50782. ret = mp_lcm(b, a, r);
  50783. if (ret != MP_OKAY)
  50784. return WC_TEST_RET_ENC_EC(ret);
  50785. ret = mp_cmp(r, exp);
  50786. if (ret != MP_EQ)
  50787. return WC_TEST_RET_ENC_NC;
  50788. #endif
  50789. mp_set(a, 11);
  50790. mp_zero(b);
  50791. ret = mp_gcd(a, b, r);
  50792. if (ret != MP_OKAY)
  50793. return WC_TEST_RET_ENC_EC(ret);
  50794. ret = mp_cmp_d(r, 11);
  50795. if (ret != MP_EQ)
  50796. return WC_TEST_RET_ENC_EC(ret);
  50797. ret = mp_gcd(b, a, r);
  50798. if (ret != MP_OKAY)
  50799. return WC_TEST_RET_ENC_EC(ret);
  50800. ret = mp_cmp_d(r, 11);
  50801. if (ret != MP_EQ)
  50802. return WC_TEST_RET_ENC_EC(ret);
  50803. ret = mp_gcd(b, b, r);
  50804. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50805. return WC_TEST_RET_ENC_EC(ret);
  50806. return 0;
  50807. }
  50808. #endif
  50809. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50810. defined(WOLFSSL_SP_MATH_ALL)
  50811. static wc_test_ret_t mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng)
  50812. {
  50813. wc_test_ret_t ret;
  50814. int i;
  50815. int j;
  50816. mp_set(a, 10);
  50817. ret = mp_mod_2d(a, 0, r);
  50818. if (ret != MP_OKAY)
  50819. return WC_TEST_RET_ENC_EC(ret);
  50820. if (!mp_iszero(r))
  50821. return WC_TEST_RET_ENC_NC;
  50822. ret = mp_mod_2d(a, 1, r);
  50823. if (ret != MP_OKAY)
  50824. return WC_TEST_RET_ENC_EC(ret);
  50825. if (!mp_iszero(r))
  50826. return WC_TEST_RET_ENC_NC;
  50827. ret = mp_mod_2d(a, 2, r);
  50828. if (ret != MP_OKAY)
  50829. return WC_TEST_RET_ENC_EC(ret);
  50830. ret = mp_cmp_d(r, 2);
  50831. if (ret != 0)
  50832. return WC_TEST_RET_ENC_EC(ret);
  50833. for (i = 2; i < 20; i++) {
  50834. ret = randNum(a, i, rng, NULL);
  50835. if (ret != 0)
  50836. return WC_TEST_RET_ENC_EC(ret);
  50837. for (j = 1; j <= mp_count_bits(a); j++) {
  50838. /* Get top part */
  50839. ret = mp_div_2d(a, j, t, NULL);
  50840. if (ret != 0)
  50841. return WC_TEST_RET_ENC_EC(ret);
  50842. ret = mp_mul_2d(t, j, t);
  50843. if (ret != 0)
  50844. return WC_TEST_RET_ENC_EC(ret);
  50845. /* Get bottom part */
  50846. ret = mp_mod_2d(a, j, r);
  50847. if (ret != 0)
  50848. return WC_TEST_RET_ENC_EC(ret);
  50849. /* Reassemble */
  50850. ret = mp_add(t, r, r);
  50851. if (ret != 0)
  50852. return WC_TEST_RET_ENC_EC(ret);
  50853. ret = mp_cmp(a, r);
  50854. if (ret != MP_EQ)
  50855. return WC_TEST_RET_ENC_NC;
  50856. }
  50857. }
  50858. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_SP_INT_NEGATIVE)
  50859. /* Test negative value being moded. */
  50860. for (j = 0; j < 20; j++) {
  50861. ret = randNum(a, 2, rng, NULL);
  50862. if (ret != 0)
  50863. return WC_TEST_RET_ENC_EC(ret);
  50864. a->sign = MP_NEG;
  50865. for (i = 1; i < DIGIT_BIT * 3 + 1; i++) {
  50866. ret = mp_mod_2d(a, i, r);
  50867. if (ret != 0)
  50868. return WC_TEST_RET_ENC_EC(ret);
  50869. mp_zero(t);
  50870. ret = mp_set_bit(t, i);
  50871. if (ret != 0)
  50872. return WC_TEST_RET_ENC_EC(ret);
  50873. ret = mp_mod(a, t, t);
  50874. if (ret != 0)
  50875. return WC_TEST_RET_ENC_EC(ret);
  50876. ret = mp_cmp(r, t);
  50877. if (ret != MP_EQ)
  50878. return WC_TEST_RET_ENC_NC;
  50879. }
  50880. }
  50881. #endif
  50882. return 0;
  50883. }
  50884. #endif
  50885. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50886. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50887. static wc_test_ret_t mp_test_mod_d(mp_int* a, WC_RNG* rng)
  50888. {
  50889. wc_test_ret_t ret;
  50890. mp_digit r;
  50891. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50892. mp_digit rem;
  50893. int i;
  50894. #endif
  50895. (void)rng;
  50896. ret = mp_set(a, 1);
  50897. if (ret != MP_OKAY)
  50898. return WC_TEST_RET_ENC_EC(ret);
  50899. ret = mp_mod_d(a, 0, &r);
  50900. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50901. return WC_TEST_RET_ENC_EC(ret);
  50902. mp_zero(a);
  50903. ret = mp_mod_d(a, 1, &r);
  50904. if (ret != MP_OKAY)
  50905. return WC_TEST_RET_ENC_EC(ret);
  50906. ret = mp_mod_d(a, 3, &r);
  50907. if (ret != MP_OKAY)
  50908. return WC_TEST_RET_ENC_EC(ret);
  50909. ret = mp_mod_d(a, 5, &r);
  50910. if (ret != MP_OKAY)
  50911. return WC_TEST_RET_ENC_EC(ret);
  50912. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50913. for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) {
  50914. ret = randNum(a, i, rng, NULL);
  50915. if (ret != MP_OKAY)
  50916. return WC_TEST_RET_ENC_EC(ret);
  50917. ret = mp_mod_d(a, 3, &r);
  50918. if (ret != MP_OKAY)
  50919. return WC_TEST_RET_ENC_EC(ret);
  50920. ret = mp_div_d(a, 3, a, &rem);
  50921. if (ret != MP_OKAY)
  50922. return WC_TEST_RET_ENC_EC(ret);
  50923. if (r != rem)
  50924. return WC_TEST_RET_ENC_NC;
  50925. }
  50926. #endif
  50927. return 0;
  50928. }
  50929. #endif
  50930. static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2,
  50931. WC_RNG* rng)
  50932. {
  50933. wc_test_ret_t ret;
  50934. int i;
  50935. for (i = 1; i < 16; i++) {
  50936. ret = randNum(a, i, rng, NULL);
  50937. if (ret != 0)
  50938. return WC_TEST_RET_ENC_EC(ret);
  50939. ret = mp_mul(a, a, r1);
  50940. if (ret != 0)
  50941. return WC_TEST_RET_ENC_EC(ret);
  50942. ret = mp_sqr(a, r2);
  50943. if (ret != 0)
  50944. return WC_TEST_RET_ENC_EC(ret);
  50945. ret = mp_cmp(r1, r2);
  50946. if (ret != MP_EQ)
  50947. return WC_TEST_RET_ENC_NC;
  50948. }
  50949. ret = mp_set(b, 0);
  50950. if (ret != MP_OKAY)
  50951. return WC_TEST_RET_ENC_EC(ret);
  50952. ret = mp_mul(a, b, r1);
  50953. if (ret != MP_OKAY)
  50954. return WC_TEST_RET_ENC_EC(ret);
  50955. if (!mp_iszero(r1))
  50956. return WC_TEST_RET_ENC_EC(ret);
  50957. ret = mp_sqr(b, r1);
  50958. if (ret != MP_OKAY)
  50959. return WC_TEST_RET_ENC_EC(ret);
  50960. if (!mp_iszero(r1))
  50961. return WC_TEST_RET_ENC_NC;
  50962. #ifdef WOLFSSL_SP_MATH_ALL
  50963. ret = mp_set(a, 1);
  50964. if (ret != MP_OKAY)
  50965. return WC_TEST_RET_ENC_EC(ret);
  50966. i = (SP_INT_DIGITS / 2) + 1;
  50967. ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a);
  50968. if (ret != MP_OKAY)
  50969. return WC_TEST_RET_ENC_EC(ret);
  50970. ret = mp_set(b, 1);
  50971. if (ret != MP_OKAY)
  50972. return WC_TEST_RET_ENC_EC(ret);
  50973. ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b);
  50974. if (ret != MP_OKAY)
  50975. return WC_TEST_RET_ENC_EC(ret);
  50976. ret = mp_mul(a, b, r1);
  50977. if (ret != MP_OKAY)
  50978. return WC_TEST_RET_ENC_EC(ret);
  50979. ret = mp_mul(a, a, r1);
  50980. if (ret == MP_OKAY)
  50981. return WC_TEST_RET_ENC_NC;
  50982. ret = mp_sqr(a, r1);
  50983. if (ret == MP_OKAY)
  50984. return WC_TEST_RET_ENC_NC;
  50985. ret = mp_sqr(b, r1);
  50986. if (ret != MP_OKAY)
  50987. return WC_TEST_RET_ENC_EC(ret);
  50988. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50989. (defined(HAVE_ECC) && defined(FP_ECC))
  50990. ret = mp_mulmod(a, b, b, r1);
  50991. if (ret != MP_OKAY)
  50992. return WC_TEST_RET_ENC_EC(ret);
  50993. ret = mp_mulmod(a, a, b, r1);
  50994. if (ret == MP_OKAY)
  50995. return WC_TEST_RET_ENC_NC;
  50996. #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC))
  50997. ret = mp_sqrmod(a, b, r1);
  50998. if (ret == MP_OKAY)
  50999. return WC_TEST_RET_ENC_NC;
  51000. ret = mp_sqrmod(b, a, r1);
  51001. if (ret != MP_OKAY)
  51002. return WC_TEST_RET_ENC_EC(ret);
  51003. #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */
  51004. #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
  51005. #endif /* WOLFSSL_SP_MATH_ALL */
  51006. return 0;
  51007. }
  51008. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  51009. defined(OPENSSL_EXTRA)
  51010. static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
  51011. {
  51012. wc_test_ret_t ret;
  51013. mp_set(a, 0);
  51014. mp_set(m, 1);
  51015. ret = mp_invmod(a, m, r);
  51016. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51017. return WC_TEST_RET_ENC_EC(ret);
  51018. ret = mp_invmod(m, a, r);
  51019. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51020. return WC_TEST_RET_ENC_EC(ret);
  51021. mp_set(a, 2);
  51022. mp_set(m, 4);
  51023. ret = mp_invmod(a, m, r);
  51024. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51025. return WC_TEST_RET_ENC_EC(ret);
  51026. mp_set(a, 3);
  51027. mp_set(m, 6);
  51028. ret = mp_invmod(a, m, r);
  51029. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51030. return WC_TEST_RET_ENC_EC(ret);
  51031. mp_set(a, 5*9);
  51032. mp_set(m, 6*9);
  51033. ret = mp_invmod(a, m, r);
  51034. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51035. return WC_TEST_RET_ENC_EC(ret);
  51036. mp_set(a, 1);
  51037. mp_set(m, 4);
  51038. ret = mp_invmod(a, m, r);
  51039. if (ret != MP_OKAY)
  51040. return WC_TEST_RET_ENC_EC(ret);
  51041. if (!mp_isone(r))
  51042. return WC_TEST_RET_ENC_NC;
  51043. mp_set(a, 3);
  51044. mp_set(m, 4);
  51045. ret = mp_invmod(a, m, r);
  51046. if (ret != MP_OKAY)
  51047. return WC_TEST_RET_ENC_EC(ret);
  51048. ret = mp_cmp_d(r, 3);
  51049. if (ret != 0)
  51050. return WC_TEST_RET_ENC_EC(ret);
  51051. mp_set(a, 3);
  51052. mp_set(m, 5);
  51053. ret = mp_invmod(a, m, r);
  51054. if (ret != MP_OKAY)
  51055. return WC_TEST_RET_ENC_EC(ret);
  51056. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51057. /* Maximum 'a' */
  51058. mp_set(a, 0);
  51059. mp_set_bit(a, (r->size / 2)* SP_WORD_SIZE - 1);
  51060. mp_sub_d(a, 1, a);
  51061. /* Modulus too big. */
  51062. mp_set(m, 0);
  51063. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE);
  51064. ret = mp_invmod(a, m, r);
  51065. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51066. return WC_TEST_RET_ENC_EC(ret);
  51067. /* Maximum modulus - even. */
  51068. mp_set(m, 0);
  51069. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1);
  51070. ret = mp_invmod(a, m, r);
  51071. if (ret != MP_OKAY)
  51072. return WC_TEST_RET_ENC_EC(ret);
  51073. #endif
  51074. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE)
  51075. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  51076. mp_read_radix(a, "-3", 16);
  51077. ret = mp_invmod(a, m, r);
  51078. if (ret != MP_OKAY)
  51079. return WC_TEST_RET_ENC_EC(ret);
  51080. #endif
  51081. #endif
  51082. #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
  51083. mp_set(a, 0);
  51084. mp_set(m, 3);
  51085. ret = mp_invmod_mont_ct(a, m, r, 1);
  51086. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51087. return WC_TEST_RET_ENC_EC(ret);
  51088. mp_set(a, 1);
  51089. mp_set(m, 0);
  51090. ret = mp_invmod_mont_ct(a, m, r, 1);
  51091. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51092. return WC_TEST_RET_ENC_EC(ret);
  51093. mp_set(a, 1);
  51094. mp_set(m, 1);
  51095. ret = mp_invmod_mont_ct(a, m, r, 1);
  51096. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51097. return WC_TEST_RET_ENC_EC(ret);
  51098. mp_set(a, 1);
  51099. mp_set(m, 2);
  51100. ret = mp_invmod_mont_ct(a, m, r, 1);
  51101. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51102. return WC_TEST_RET_ENC_EC(ret);
  51103. mp_set(a, 1);
  51104. mp_set(m, 3);
  51105. ret = mp_invmod_mont_ct(a, m, r, 1);
  51106. if (ret != MP_OKAY)
  51107. return WC_TEST_RET_ENC_EC(ret);
  51108. #endif
  51109. return 0;
  51110. }
  51111. #endif /* !NO_RSA || HAVE_ECC || !NO_DSA || OPENSSL_EXTRA */
  51112. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51113. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51114. static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r)
  51115. {
  51116. wc_test_ret_t ret;
  51117. mp_set(b, 0x2);
  51118. mp_set(e, 0x3);
  51119. mp_set(m, 0x0);
  51120. ret = mp_exptmod_ex(b, e, 1, m, r);
  51121. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51122. return WC_TEST_RET_ENC_EC(ret);
  51123. ret = mp_exptmod_nct(b, e, m, r);
  51124. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51125. return WC_TEST_RET_ENC_EC(ret);
  51126. mp_set(b, 0x2);
  51127. mp_set(e, 0x3);
  51128. mp_set(m, 0x1);
  51129. ret = mp_exptmod_ex(b, e, 1, m, r);
  51130. if (ret != MP_OKAY)
  51131. return WC_TEST_RET_ENC_EC(ret);
  51132. if (!mp_iszero(r))
  51133. return WC_TEST_RET_ENC_NC;
  51134. ret = mp_exptmod_nct(b, e, m, r);
  51135. if (ret != MP_OKAY)
  51136. return WC_TEST_RET_ENC_EC(ret);
  51137. if (!mp_iszero(r))
  51138. return WC_TEST_RET_ENC_NC;
  51139. mp_set(b, 0x2);
  51140. mp_set(e, 0x0);
  51141. mp_set(m, 0x7);
  51142. ret = mp_exptmod_ex(b, e, 1, m, r);
  51143. if (ret != MP_OKAY)
  51144. return WC_TEST_RET_ENC_EC(ret);
  51145. if (!mp_isone(r))
  51146. return WC_TEST_RET_ENC_NC;
  51147. ret = mp_exptmod_nct(b, e, m, r);
  51148. if (ret != MP_OKAY)
  51149. return WC_TEST_RET_ENC_EC(ret);
  51150. if (!mp_isone(r))
  51151. return WC_TEST_RET_ENC_NC;
  51152. mp_set(b, 0x0);
  51153. mp_set(e, 0x3);
  51154. mp_set(m, 0x7);
  51155. ret = mp_exptmod_ex(b, e, 1, m, r);
  51156. if (ret != MP_OKAY)
  51157. return WC_TEST_RET_ENC_EC(ret);
  51158. if (!mp_iszero(r))
  51159. return WC_TEST_RET_ENC_NC;
  51160. ret = mp_exptmod_nct(b, e, m, r);
  51161. if (ret != MP_OKAY)
  51162. return WC_TEST_RET_ENC_EC(ret);
  51163. if (!mp_iszero(r))
  51164. return WC_TEST_RET_ENC_NC;
  51165. mp_set(b, 0x10);
  51166. mp_set(e, 0x3);
  51167. mp_set(m, 0x7);
  51168. ret = mp_exptmod_ex(b, e, 1, m, r);
  51169. if (ret != MP_OKAY)
  51170. return WC_TEST_RET_ENC_EC(ret);
  51171. ret = mp_exptmod_nct(b, e, m, r);
  51172. if (ret != MP_OKAY)
  51173. return WC_TEST_RET_ENC_EC(ret);
  51174. mp_set(b, 0x7);
  51175. mp_set(e, 0x3);
  51176. mp_set(m, 0x7);
  51177. ret = mp_exptmod_ex(b, e, 1, m, r);
  51178. if (ret != MP_OKAY)
  51179. return WC_TEST_RET_ENC_EC(ret);
  51180. if (!mp_iszero(r))
  51181. return WC_TEST_RET_ENC_NC;
  51182. ret = mp_exptmod_nct(b, e, m, r);
  51183. if (ret != MP_OKAY)
  51184. return WC_TEST_RET_ENC_EC(ret);
  51185. if (!mp_iszero(r))
  51186. return WC_TEST_RET_ENC_NC;
  51187. #ifndef WOLFSSL_SP_MATH
  51188. mp_set(b, 0x01);
  51189. mp_mul_2d(b, DIGIT_BIT, b);
  51190. mp_add_d(b, 1, b);
  51191. mp_set(e, 0x3);
  51192. mp_copy(b, m);
  51193. ret = mp_exptmod_ex(b, e, 1, m, r);
  51194. if (ret != MP_OKAY)
  51195. return WC_TEST_RET_ENC_EC(ret);
  51196. if (!mp_iszero(r))
  51197. return WC_TEST_RET_ENC_NC;
  51198. ret = mp_exptmod_nct(b, e, m, r);
  51199. if (ret != MP_OKAY)
  51200. return WC_TEST_RET_ENC_EC(ret);
  51201. if (!mp_iszero(r))
  51202. return WC_TEST_RET_ENC_NC;
  51203. #endif
  51204. mp_set(b, 0x2);
  51205. mp_set(e, 0x3);
  51206. mp_set(m, 0x7);
  51207. ret = mp_exptmod_ex(b, e, 1, m, r);
  51208. if (ret != MP_OKAY)
  51209. return WC_TEST_RET_ENC_EC(ret);
  51210. ret = mp_exptmod_nct(b, e, m, r);
  51211. if (ret != MP_OKAY)
  51212. return WC_TEST_RET_ENC_EC(ret);
  51213. #ifdef WOLFSSL_SP_MATH_ALL
  51214. mp_set(b, 0x2);
  51215. mp_set(e, 0x3);
  51216. mp_set(m, 0x01);
  51217. mp_mul_2d(m, SP_WORD_SIZE * SP_INT_DIGITS / 2, m);
  51218. mp_add_d(m, 0x01, m);
  51219. ret = mp_exptmod_ex(b, e, 1, m, r);
  51220. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51221. return WC_TEST_RET_ENC_EC(ret);
  51222. ret = mp_exptmod_nct(b, e, m, r);
  51223. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51224. return WC_TEST_RET_ENC_EC(ret);
  51225. #endif
  51226. return 0;
  51227. }
  51228. #endif /* !NO_RSA || !NO_DSA || !NO_DH || (HAVE_ECC && HAVE_COMP_KEY) ||
  51229. * OPENSSL_EXTRA */
  51230. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51231. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51232. static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng)
  51233. {
  51234. wc_test_ret_t ret;
  51235. mp_digit mp;
  51236. static int exp[] = { 7, 8, 16, 27, 32, 64,
  51237. 127, 128, 255, 256,
  51238. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51239. 383, 384, 2033, 2048
  51240. #endif
  51241. };
  51242. static mp_digit sub[] = { 0x01, 0x05, 0x0f, 0x27, 0x05, 0x3b,
  51243. 0x01, 0x9f, 0x13, 0xbd,
  51244. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51245. 0x1f, 0x13d, 0x45, 0x615
  51246. #endif
  51247. };
  51248. int bits[] = { 256, 384,
  51249. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 4096
  51250. 2048,
  51251. #endif
  51252. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 6144
  51253. 3072
  51254. #endif
  51255. };
  51256. int i;
  51257. int j;
  51258. for (i = 0; i < (int)(sizeof(exp) / sizeof(*exp)); i++) {
  51259. if (exp[i] >= DIGIT_BIT)
  51260. continue;
  51261. mp_zero(m);
  51262. ret = mp_set_bit(m, exp[i]);
  51263. if (ret != MP_OKAY)
  51264. return WC_TEST_RET_ENC_EC(ret);
  51265. ret = mp_sub_d(m, sub[i], m);
  51266. if (ret != MP_OKAY)
  51267. return WC_TEST_RET_ENC_EC(ret);
  51268. ret = mp_montgomery_setup(m, &mp);
  51269. if (ret != MP_OKAY)
  51270. return WC_TEST_RET_ENC_EC(ret);
  51271. ret = mp_montgomery_calc_normalization(n, m);
  51272. if (ret != MP_OKAY)
  51273. return WC_TEST_RET_ENC_EC(ret);
  51274. for (j = 0; j < 10; j++) {
  51275. ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL);
  51276. if (ret != 0)
  51277. return WC_TEST_RET_ENC_EC(ret);
  51278. ret = mp_mod(a, m, a);
  51279. if (ret != 0)
  51280. return WC_TEST_RET_ENC_EC(ret);
  51281. /* r = a * a */
  51282. ret = mp_sqrmod(a, m, r);
  51283. if (ret != MP_OKAY)
  51284. return WC_TEST_RET_ENC_EC(ret);
  51285. /* Convert to Montgomery form = a*n */
  51286. ret = mp_mulmod(a, n, m, a);
  51287. if (ret != MP_OKAY)
  51288. return WC_TEST_RET_ENC_EC(ret);
  51289. /* a*a mod m == ((a*n) * (a*n)) / n / n */
  51290. ret = mp_sqr(a, a);
  51291. if (ret != MP_OKAY)
  51292. return WC_TEST_RET_ENC_EC(ret);
  51293. ret = mp_montgomery_reduce(a, m, mp);
  51294. if (ret != MP_OKAY)
  51295. return WC_TEST_RET_ENC_EC(ret);
  51296. ret = mp_montgomery_reduce(a, m, mp);
  51297. if (ret != MP_OKAY)
  51298. return WC_TEST_RET_ENC_EC(ret);
  51299. if (mp_cmp(a, r) != MP_EQ)
  51300. return WC_TEST_RET_ENC_NC;
  51301. }
  51302. }
  51303. /* Force carries. */
  51304. for (i = 0; i < (int)(sizeof(bits) / sizeof(*bits)); i++) {
  51305. /* a = 2^(bits*2) - 1 */
  51306. mp_zero(a);
  51307. mp_set_bit(a, bits[i] * 2);
  51308. ret = mp_sub_d(a, 1, a);
  51309. if (ret != MP_OKAY)
  51310. return WC_TEST_RET_ENC_EC(ret);
  51311. /* m = 2^(bits) - 1 */
  51312. mp_zero(m);
  51313. mp_set_bit(m, bits[i]);
  51314. ret = mp_sub_d(m, 1, m);
  51315. if (ret != MP_OKAY)
  51316. return WC_TEST_RET_ENC_EC(ret);
  51317. mp = 1;
  51318. /* result = r = 2^(bits) - 1 */
  51319. mp_zero(r);
  51320. mp_set_bit(r, bits[i]);
  51321. ret = mp_sub_d(r, 1, r);
  51322. if (ret != MP_OKAY)
  51323. return WC_TEST_RET_ENC_EC(ret);
  51324. ret = mp_montgomery_reduce(a, m, mp);
  51325. if (ret != MP_OKAY)
  51326. return WC_TEST_RET_ENC_EC(ret);
  51327. /* Result is m or 0 if reduced to range of modulus. */
  51328. if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES)
  51329. return WC_TEST_RET_ENC_NC;
  51330. }
  51331. return 0;
  51332. }
  51333. #endif
  51334. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
  51335. {
  51336. WC_RNG rng;
  51337. int rng_inited = 0;
  51338. wc_test_ret_t ret;
  51339. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51340. int i, j;
  51341. #ifndef WOLFSSL_SP_MATH
  51342. int k;
  51343. #endif
  51344. mp_digit d = 0;
  51345. #endif
  51346. #ifdef WOLFSSL_SMALL_STACK
  51347. mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51348. DYNAMIC_TYPE_TMP_BUFFER),
  51349. *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51350. DYNAMIC_TYPE_TMP_BUFFER),
  51351. *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51352. DYNAMIC_TYPE_TMP_BUFFER),
  51353. *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51354. DYNAMIC_TYPE_TMP_BUFFER),
  51355. *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51356. DYNAMIC_TYPE_TMP_BUFFER);
  51357. if ((a == NULL) ||
  51358. (b == NULL) ||
  51359. (r1 == NULL) ||
  51360. (r2 == NULL) ||
  51361. (p == NULL))
  51362. {
  51363. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  51364. }
  51365. #else
  51366. mp_int a[1], b[1], r1[1], r2[1], p[1];
  51367. #endif
  51368. WOLFSSL_ENTER("mp_test");
  51369. ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
  51370. if (ret != 0)
  51371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51372. #ifdef WOLFSSL_SP_MATH_ALL
  51373. mp_init_copy(p, a);
  51374. #else
  51375. ret = mp_init(p);
  51376. if (ret != 0)
  51377. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51378. #endif
  51379. #ifndef HAVE_FIPS
  51380. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  51381. #else
  51382. ret = wc_InitRng(&rng);
  51383. #endif
  51384. if (ret != 0)
  51385. goto done;
  51386. rng_inited = 1;
  51387. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51388. mp_set_int(a, 0);
  51389. if (a->used != 0 || a->dp[0] != 0)
  51390. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51391. for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) {
  51392. for (i = 0; i < 4 * j; i++) {
  51393. /* New values to use. */
  51394. ret = randNum(p, j, &rng, NULL);
  51395. if (ret != 0)
  51396. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51397. ret = randNum(a, j, &rng, NULL);
  51398. if (ret != 0)
  51399. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51400. ret = randNum(b, j, &rng, NULL);
  51401. if (ret != 0)
  51402. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51403. ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d));
  51404. if (ret != 0)
  51405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51406. d &= MP_MASK;
  51407. #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \
  51408. (defined(ECC_SHAMIR) || defined(FP_ECC)))
  51409. /* Ensure sqrmod produce same result as mulmod. */
  51410. ret = mp_sqrmod(a, p, r1);
  51411. if (ret != 0)
  51412. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51413. ret = mp_mulmod(a, a, p, r2);
  51414. if (ret != 0)
  51415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51416. if (mp_cmp(r1, r2) != 0) {
  51417. WOLFSSL_MSG("Fail: mp_mulmod result does not match mp_sqrmod!");
  51418. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51419. }
  51420. #endif
  51421. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51422. #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \
  51423. !defined(WOLFSSL_SP_INT_NEGATIVE))
  51424. ret = mp_addmod(a, b, p, r1);
  51425. if (ret != 0)
  51426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51427. ret = mp_submod(r1, b, p, r2);
  51428. if (ret != 0)
  51429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51430. ret = mp_mod(a, p, r1);
  51431. if (ret != 0)
  51432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51433. if (mp_cmp(r1, r2) != MP_EQ)
  51434. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51435. #else
  51436. /* Ensure add with mod produce same result as sub with mod. */
  51437. ret = mp_addmod(a, b, p, r1);
  51438. if (ret != 0)
  51439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51440. b->sign ^= 1;
  51441. ret = mp_submod(a, b, p, r2);
  51442. if (ret != 0)
  51443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51444. if (mp_cmp(r1, r2) != 0)
  51445. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51446. #endif
  51447. #endif
  51448. /* Ensure add digit produce same result as sub digit. */
  51449. ret = mp_add_d(a, d, r1);
  51450. if (ret != 0)
  51451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51452. ret = mp_sub_d(r1, d, r2);
  51453. if (ret != 0)
  51454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51455. if (mp_cmp(a, r2) != 0)
  51456. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51457. /* Invert - if p is even it will use the slow impl.
  51458. * - if p and a are even it will fail.
  51459. */
  51460. ret = mp_invmod(a, p, r1);
  51461. if (ret != 0 && ret != WC_NO_ERR_TRACE(MP_VAL))
  51462. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51463. #ifndef WOLFSSL_SP_MATH
  51464. /* Shift up and down number all bits in a digit. */
  51465. for (k = 0; k < DIGIT_BIT; k++) {
  51466. mp_mul_2d(a, k, r1);
  51467. mp_div_2d(r1, k, r2, p);
  51468. if (mp_cmp(a, r2) != 0)
  51469. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51470. if (!mp_iszero(p))
  51471. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51472. mp_rshb(r1, k);
  51473. if (mp_cmp(a, r1) != 0)
  51474. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51475. }
  51476. #endif
  51477. }
  51478. }
  51479. /* Test adding and subtracting zero from zero. */
  51480. mp_zero(a);
  51481. ret = mp_add_d(a, 0, r1);
  51482. if (ret != 0)
  51483. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51484. if (!mp_iszero(r1)) {
  51485. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51486. }
  51487. ret = mp_sub_d(a, 0, r2);
  51488. if (ret != 0)
  51489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51490. if (!mp_iszero(r2)) {
  51491. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51492. }
  51493. #if DIGIT_BIT >= 32
  51494. /* Check that setting a 32-bit digit works. */
  51495. d &= 0xffffffffU;
  51496. mp_set_int(a, d);
  51497. if (a->used != 1 || a->dp[0] != d)
  51498. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51499. #endif
  51500. /* Check setting a bit and testing a bit works. */
  51501. for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) {
  51502. mp_zero(a);
  51503. mp_set_bit(a, i);
  51504. if (!mp_is_bit_set(a, i))
  51505. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51506. }
  51507. #endif
  51508. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  51509. mp_zero(a);
  51510. i = mp_cnt_lsb(a);
  51511. if (i != 0)
  51512. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51513. mp_set(a, 1);
  51514. i = mp_cnt_lsb(a);
  51515. if (i != 0)
  51516. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51517. mp_set(a, 32);
  51518. i = mp_cnt_lsb(a);
  51519. if (i != 5)
  51520. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51521. mp_zero(a);
  51522. mp_set_bit(a, 129);
  51523. i = mp_cnt_lsb(a);
  51524. if (i != 129)
  51525. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51526. #endif
  51527. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51528. if ((ret = mp_test_param(a, b, r1, &rng)) != 0)
  51529. goto done;
  51530. #endif
  51531. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  51532. if ((ret = mp_test_div_3(a, r1, &rng)) != 0)
  51533. goto done;
  51534. #endif
  51535. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  51536. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  51537. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  51538. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  51539. if ((ret = mp_test_radix_10(a, r1, &rng)) != 0)
  51540. goto done;
  51541. #endif
  51542. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  51543. defined(HAVE_ECC))
  51544. if ((ret = mp_test_radix_16(a, r1, &rng)) != 0)
  51545. goto done;
  51546. #endif
  51547. if ((ret = mp_test_shift(a, r1, &rng)) != 0)
  51548. goto done;
  51549. if ((ret = mp_test_add_sub_d(a, r1)) != 0)
  51550. goto done;
  51551. if ((ret = mp_test_read_to_bin(a)) != 0)
  51552. goto done;
  51553. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51554. if ((ret = mp_test_set_int(a)) != 0)
  51555. goto done;
  51556. #endif
  51557. if ((ret = mp_test_cmp(a, r1)) != 0)
  51558. goto done;
  51559. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51560. if ((ret = mp_test_shbd(a, b, &rng)) != 0)
  51561. goto done;
  51562. #endif
  51563. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51564. if ((ret = mp_test_set_is_bit(a)) != 0)
  51565. goto done;
  51566. #endif
  51567. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  51568. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  51569. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  51570. if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
  51571. goto done;
  51572. #endif
  51573. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  51574. !defined(WC_NO_RNG)
  51575. if ((ret = mp_test_prime(a, &rng)) != 0)
  51576. goto done;
  51577. #endif
  51578. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  51579. if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0)
  51580. goto done;
  51581. #endif
  51582. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  51583. defined(WOLFSSL_SP_MATH_ALL)
  51584. if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0)
  51585. goto done;
  51586. #endif
  51587. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  51588. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  51589. if ((ret = mp_test_mod_d(a, &rng)) != 0)
  51590. goto done;
  51591. #endif
  51592. if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
  51593. goto done;
  51594. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  51595. defined(OPENSSL_EXTRA)
  51596. if ((ret = mp_test_invmod(a, b, r1)) != 0)
  51597. goto done;
  51598. #endif
  51599. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51600. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51601. if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0)
  51602. goto done;
  51603. #endif
  51604. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51605. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51606. if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0)
  51607. goto done;
  51608. #endif
  51609. done:
  51610. #ifdef WOLFSSL_SMALL_STACK
  51611. if (p) {
  51612. mp_clear(p);
  51613. XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51614. }
  51615. if (r2) {
  51616. mp_clear(r2);
  51617. XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51618. }
  51619. if (r1) {
  51620. mp_clear(r1);
  51621. XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51622. }
  51623. if (b) {
  51624. mp_clear(b);
  51625. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51626. }
  51627. if (a) {
  51628. mp_clear(a);
  51629. XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51630. }
  51631. #else
  51632. mp_clear(p);
  51633. mp_clear(r2);
  51634. mp_clear(r1);
  51635. mp_clear(b);
  51636. mp_clear(a);
  51637. #endif
  51638. if (rng_inited)
  51639. wc_FreeRng(&rng);
  51640. return ret;
  51641. }
  51642. #endif /* WOLFSSL_PUBLIC_MP && ((WOLFSSL_SP_MATH_ALL &&
  51643. * !WOLFSSL_RSA_VERIFY_ONLY) || USE_FAST_MATH) */
  51644. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  51645. typedef struct pairs_t {
  51646. const unsigned char* coeff;
  51647. int coeffSz;
  51648. int exp;
  51649. } pairs_t;
  51650. /*
  51651. n =p1p2p3, where pi = ki(p1-1)+1 with (k2,k3) = (173,293)
  51652. p1 = 2^192 * 0x000000000000e24fd4f6d6363200bf2323ec46285cac1d3a
  51653. + 2^0 * 0x0b2488b0c29d96c5e67f8bec15b54b189ae5636efe89b45b
  51654. */
  51655. static const unsigned char c192a[] =
  51656. {
  51657. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x4f,
  51658. 0xd4, 0xf6, 0xd6, 0x36, 0x32, 0x00, 0xbf, 0x23,
  51659. 0x23, 0xec, 0x46, 0x28, 0x5c, 0xac, 0x1d, 0x3a
  51660. };
  51661. static const unsigned char c0a[] =
  51662. {
  51663. 0x0b, 0x24, 0x88, 0xb0, 0xc2, 0x9d, 0x96, 0xc5,
  51664. 0xe6, 0x7f, 0x8b, 0xec, 0x15, 0xb5, 0x4b, 0x18,
  51665. 0x9a, 0xe5, 0x63, 0x6e, 0xfe, 0x89, 0xb4, 0x5b
  51666. };
  51667. static const pairs_t ecPairsA[] =
  51668. {
  51669. {c192a, sizeof(c192a), 192},
  51670. {c0a, sizeof(c0a), 0}
  51671. };
  51672. static const int kA[] = {173, 293};
  51673. static const unsigned char controlPrime[] = {
  51674. 0xe1, 0x76, 0x45, 0x80, 0x59, 0xb6, 0xd3, 0x49,
  51675. 0xdf, 0x0a, 0xef, 0x12, 0xd6, 0x0f, 0xf0, 0xb7,
  51676. 0xcb, 0x2a, 0x37, 0xbf, 0xa7, 0xf8, 0xb5, 0x4d,
  51677. 0xf5, 0x31, 0x35, 0xad, 0xe4, 0xa3, 0x94, 0xa1,
  51678. 0xdb, 0xf1, 0x96, 0xad, 0xb5, 0x05, 0x64, 0x85,
  51679. 0x83, 0xfc, 0x1b, 0x5b, 0x29, 0xaa, 0xbe, 0xf8,
  51680. 0x26, 0x3f, 0x76, 0x7e, 0xad, 0x1c, 0xf0, 0xcb,
  51681. 0xd7, 0x26, 0xb4, 0x1b, 0x05, 0x8e, 0x56, 0x86,
  51682. 0x7e, 0x08, 0x62, 0x21, 0xc1, 0x86, 0xd6, 0x47,
  51683. 0x79, 0x3e, 0xb7, 0x5d, 0xa4, 0xc6, 0x3a, 0xd7,
  51684. 0xb1, 0x74, 0x20, 0xf6, 0x50, 0x97, 0x41, 0x04,
  51685. 0x53, 0xed, 0x3f, 0x26, 0xd6, 0x6f, 0x91, 0xfa,
  51686. 0x68, 0x26, 0xec, 0x2a, 0xdc, 0x9a, 0xf1, 0xe7,
  51687. 0xdc, 0xfb, 0x73, 0xf0, 0x79, 0x43, 0x1b, 0x21,
  51688. 0xa3, 0x59, 0x04, 0x63, 0x52, 0x07, 0xc9, 0xd7,
  51689. 0xe6, 0xd1, 0x1b, 0x5d, 0x5e, 0x96, 0xfa, 0x53
  51690. };
  51691. static const unsigned char testOne[] = { 1 };
  51692. static wc_test_ret_t GenerateNextP(mp_int* p1, mp_int* p2, int k)
  51693. {
  51694. wc_test_ret_t ret;
  51695. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51696. mp_int *ki = (mp_int *)XMALLOC(sizeof(*ki), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51697. if (ki == NULL)
  51698. return MEMORY_E;
  51699. #else
  51700. mp_int ki[1];
  51701. #endif
  51702. ret = mp_init(ki);
  51703. if (ret != 0)
  51704. ret = WC_TEST_RET_ENC_EC(ret);
  51705. if (ret == 0) {
  51706. ret = mp_set(ki, (mp_digit)k);
  51707. if (ret != 0)
  51708. ret = WC_TEST_RET_ENC_EC(ret);
  51709. }
  51710. if (ret == 0) {
  51711. ret = mp_sub_d(p1, 1, p2);
  51712. if (ret != 0)
  51713. ret = WC_TEST_RET_ENC_EC(ret);
  51714. }
  51715. if (ret == 0) {
  51716. ret = mp_mul(p2, ki, p2);
  51717. if (ret != 0)
  51718. ret = WC_TEST_RET_ENC_EC(ret);
  51719. }
  51720. if (ret == 0) {
  51721. ret = mp_add_d(p2, 1, p2);
  51722. if (ret != 0)
  51723. ret = WC_TEST_RET_ENC_EC(ret);
  51724. }
  51725. mp_clear(ki);
  51726. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51727. XFREE(ki, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51728. #endif
  51729. return ret;
  51730. }
  51731. static wc_test_ret_t GenerateP(mp_int* p1, mp_int* p2, mp_int* p3,
  51732. const pairs_t* ecPairs, int ecPairsSz,
  51733. const int* k)
  51734. {
  51735. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51736. mp_int *x = NULL, *y = NULL;
  51737. #else
  51738. mp_int x[1], y[1];
  51739. #endif
  51740. wc_test_ret_t ret;
  51741. int i;
  51742. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51743. if (((x = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) ||
  51744. ((y = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)) {
  51745. ret = MEMORY_E;
  51746. goto out;
  51747. }
  51748. #endif
  51749. ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL);
  51750. if (ret != 0) {
  51751. ret = WC_TEST_RET_ENC_EC(ret);
  51752. goto out;
  51753. }
  51754. for (i = 0; ret == 0 && i < ecPairsSz; i++) {
  51755. ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, (word32)ecPairs[i].coeffSz);
  51756. if (ret != 0) {
  51757. ret = WC_TEST_RET_ENC_EC(ret);
  51758. break;
  51759. }
  51760. /* p1 = 2^exp */
  51761. ret = mp_2expt(y, ecPairs[i].exp);
  51762. if (ret != 0) {
  51763. ret = WC_TEST_RET_ENC_EC(ret);
  51764. break;
  51765. }
  51766. /* p1 = p1 * m */
  51767. ret = mp_mul(x, y, x);
  51768. if (ret != 0) {
  51769. ret = WC_TEST_RET_ENC_EC(ret);
  51770. break;
  51771. }
  51772. /* p1 += */
  51773. ret = mp_add(p1, x, p1);
  51774. if (ret != 0) {
  51775. ret = WC_TEST_RET_ENC_EC(ret);
  51776. break;
  51777. }
  51778. mp_zero(x);
  51779. mp_zero(y);
  51780. }
  51781. if (ret == 0)
  51782. ret = GenerateNextP(p1, p2, k[0]);
  51783. if (ret == 0)
  51784. ret = GenerateNextP(p1, p3, k[1]);
  51785. out:
  51786. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51787. if (x != NULL) {
  51788. mp_clear(x);
  51789. XFREE(x, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51790. }
  51791. if (y != NULL) {
  51792. mp_clear(y);
  51793. XFREE(y, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51794. }
  51795. #else
  51796. mp_clear(x);
  51797. mp_clear(y);
  51798. #endif
  51799. return ret;
  51800. }
  51801. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void)
  51802. {
  51803. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51804. mp_int *n = (mp_int *)XMALLOC(sizeof *n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51805. *p1 = (mp_int *)XMALLOC(sizeof *p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51806. *p2 = (mp_int *)XMALLOC(sizeof *p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51807. *p3 = (mp_int *)XMALLOC(sizeof *p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51808. #else
  51809. mp_int n[1],
  51810. p1[1],
  51811. p2[1],
  51812. p3[1];
  51813. #endif
  51814. wc_test_ret_t ret;
  51815. int isPrime = 0;
  51816. WC_RNG rng;
  51817. WOLFSSL_ENTER("prime_test");
  51818. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51819. if ((n == NULL) ||
  51820. (p1 == NULL) ||
  51821. (p2 == NULL) ||
  51822. (p3 == NULL))
  51823. ERROR_OUT(MEMORY_E, out);
  51824. #endif
  51825. ret = wc_InitRng(&rng);
  51826. if (ret != 0)
  51827. ret = WC_TEST_RET_ENC_EC(ret);
  51828. if (ret == 0) {
  51829. ret = mp_init_multi(n, p1, p2, p3, NULL, NULL);
  51830. if (ret != 0)
  51831. ret = WC_TEST_RET_ENC_EC(ret);
  51832. }
  51833. if (ret == 0)
  51834. ret = GenerateP(p1, p2, p3,
  51835. ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA);
  51836. if (ret == 0) {
  51837. ret = mp_mul(p1, p2, n);
  51838. if (ret != 0)
  51839. ret = WC_TEST_RET_ENC_EC(ret);
  51840. }
  51841. if (ret == 0) {
  51842. ret = mp_mul(n, p3, n);
  51843. if (ret != 0)
  51844. ret = WC_TEST_RET_ENC_EC(ret);
  51845. }
  51846. if (ret != 0)
  51847. ERROR_OUT(ret, out);
  51848. /* Check the old prime test using the number that false positives.
  51849. * This test result should indicate as not prime. */
  51850. ret = mp_prime_is_prime(n, 40, &isPrime);
  51851. if (ret != 0)
  51852. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51853. if (isPrime)
  51854. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51855. /* This test result should fail. It should indicate the value as prime. */
  51856. ret = mp_prime_is_prime(n, 8, &isPrime);
  51857. if (ret != 0)
  51858. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51859. if (!isPrime)
  51860. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51861. /* This test result should indicate the value as not prime. */
  51862. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51863. if (ret != 0)
  51864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51865. if (isPrime)
  51866. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51867. ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime));
  51868. if (ret != 0)
  51869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51870. /* This test result should indicate the value as prime. */
  51871. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51872. if (ret != 0)
  51873. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51874. if (!isPrime)
  51875. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51876. /* This test result should indicate the value as prime. */
  51877. isPrime = -1;
  51878. ret = mp_prime_is_prime(n, 8, &isPrime);
  51879. if (ret != 0)
  51880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51881. if (!isPrime)
  51882. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51883. ret = mp_read_unsigned_bin(n, testOne, sizeof(testOne));
  51884. if (ret != 0)
  51885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51886. /* This test result should indicate the value as not prime. */
  51887. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51888. if (ret != 0)
  51889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51890. if (isPrime)
  51891. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51892. ret = mp_prime_is_prime(n, 8, &isPrime);
  51893. if (ret != 0)
  51894. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51895. if (isPrime)
  51896. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51897. ret = 0;
  51898. out:
  51899. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51900. if (n != NULL) {
  51901. mp_clear(n);
  51902. XFREE(n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51903. }
  51904. if (p1 != NULL) {
  51905. mp_clear(p1);
  51906. XFREE(p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51907. }
  51908. if (p2 != NULL) {
  51909. mp_clear(p2);
  51910. XFREE(p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51911. }
  51912. if (p3 != NULL) {
  51913. mp_clear(p3);
  51914. XFREE(p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51915. }
  51916. #else
  51917. mp_clear(p3);
  51918. mp_clear(p2);
  51919. mp_clear(p1);
  51920. mp_clear(n);
  51921. #endif
  51922. wc_FreeRng(&rng);
  51923. return ret;
  51924. }
  51925. #endif /* WOLFSSL_PUBLIC_MP */
  51926. #if defined(ASN_BER_TO_DER) && \
  51927. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  51928. defined(OPENSSL_EXTRA_X509_SMALL))
  51929. /* wc_BerToDer is only public facing in the case of test cert or opensslextra */
  51930. typedef struct berDerTestData {
  51931. const byte *in;
  51932. word32 inSz;
  51933. const byte *out;
  51934. word32 outSz;
  51935. } berDerTestData;
  51936. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void)
  51937. {
  51938. wc_test_ret_t ret;
  51939. int i;
  51940. word32 len = 0, l;
  51941. byte out[32];
  51942. WOLFSSL_SMALL_STACK_STATIC const byte good1_in[] = { 0x30, 0x80, 0x00, 0x00 };
  51943. WOLFSSL_SMALL_STACK_STATIC const byte good1_out[] = { 0x30, 0x00 };
  51944. WOLFSSL_SMALL_STACK_STATIC const byte good2_in[] = { 0x30, 0x80, 0x02, 0x01, 0x01, 0x00, 0x00 };
  51945. WOLFSSL_SMALL_STACK_STATIC const byte good2_out[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51946. WOLFSSL_SMALL_STACK_STATIC const byte good3_in[] = {
  51947. 0x24, 0x80, 0x04, 0x01, 0x01, 0x00, 0x00
  51948. };
  51949. WOLFSSL_SMALL_STACK_STATIC const byte good3_out[] = { 0x04, 0x1, 0x01 };
  51950. WOLFSSL_SMALL_STACK_STATIC const byte good4_in[] = {
  51951. 0x30, 0x80,
  51952. 0x02, 0x01, 0x01,
  51953. 0x30, 0x80,
  51954. 0x24, 0x80,
  51955. 0x04, 0x01, 0x01,
  51956. 0x04, 0x02, 0x02, 0x03,
  51957. 0x00, 0x00,
  51958. 0x06, 0x01, 0x01,
  51959. 0x00, 0x00,
  51960. 0x31, 0x80,
  51961. 0x06, 0x01, 0x01,
  51962. 0x00, 0x00,
  51963. 0x00, 0x00,
  51964. };
  51965. WOLFSSL_SMALL_STACK_STATIC const byte good4_out[] = {
  51966. 0x30, 0x12,
  51967. 0x02, 0x01, 0x01,
  51968. 0x30, 0x08,
  51969. 0x04, 0x03, 0x01, 0x02, 0x03,
  51970. 0x06, 0x01, 0x01,
  51971. 0x31, 0x03,
  51972. 0x06, 0x01, 0x01
  51973. };
  51974. WOLFSSL_SMALL_STACK_STATIC const byte good5_in[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51975. berDerTestData testData[] = {
  51976. { good1_in, sizeof(good1_in), good1_out, sizeof(good1_out) },
  51977. { good2_in, sizeof(good2_in), good2_out, sizeof(good2_out) },
  51978. { good3_in, sizeof(good3_in), good3_out, sizeof(good3_out) },
  51979. { good4_in, sizeof(good4_in), good4_out, sizeof(good4_out) },
  51980. { good5_in, sizeof(good5_in), good5_in , sizeof(good5_in ) },
  51981. };
  51982. WOLFSSL_ENTER("berder_test");
  51983. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  51984. ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len);
  51985. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  51986. return WC_TEST_RET_ENC_I(i);
  51987. if (len != testData[i].outSz)
  51988. return WC_TEST_RET_ENC_I(i);
  51989. len = testData[i].outSz;
  51990. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len);
  51991. if (ret != 0)
  51992. return WC_TEST_RET_ENC_I(i);
  51993. if (XMEMCMP(out, testData[i].out, len) != 0)
  51994. return WC_TEST_RET_ENC_I(i);
  51995. for (l = 1; l < testData[i].inSz; l++) {
  51996. ret = wc_BerToDer(testData[i].in, l, NULL, &len);
  51997. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  51998. return WC_TEST_RET_ENC_EC(ret);
  51999. len = testData[i].outSz;
  52000. ret = wc_BerToDer(testData[i].in, l, out, &len);
  52001. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  52002. return WC_TEST_RET_ENC_EC(ret);
  52003. }
  52004. for (l = 0; l < testData[i].outSz-1; l++) {
  52005. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l);
  52006. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52007. return WC_TEST_RET_ENC_EC(ret);
  52008. }
  52009. }
  52010. ret = wc_BerToDer(NULL, 4, NULL, NULL);
  52011. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52012. return WC_TEST_RET_ENC_EC(ret);
  52013. ret = wc_BerToDer(out, 4, NULL, NULL);
  52014. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52015. return WC_TEST_RET_ENC_EC(ret);
  52016. ret = wc_BerToDer(NULL, 4, NULL, &len);
  52017. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52018. return WC_TEST_RET_ENC_EC(ret);
  52019. ret = wc_BerToDer(NULL, 4, out, NULL);
  52020. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52021. return WC_TEST_RET_ENC_EC(ret);
  52022. ret = wc_BerToDer(out, 4, out, NULL);
  52023. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52024. return WC_TEST_RET_ENC_EC(ret);
  52025. ret = wc_BerToDer(NULL, 4, out, &len);
  52026. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52027. return WC_TEST_RET_ENC_EC(ret);
  52028. for (l = 1; l < sizeof(good4_out); l++) {
  52029. len = l;
  52030. ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len);
  52031. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52032. return WC_TEST_RET_ENC_EC(ret);
  52033. }
  52034. return 0;
  52035. }
  52036. #endif /* ASN_BER_TO_DER && (WOLFSSL_TEST_CERT || OPENSSL_EXTRA ||
  52037. OPENSSL_EXTRA_X509_SMALL */
  52038. #ifdef DEBUG_WOLFSSL
  52039. static THREAD_LS_T int log_cnt = 0;
  52040. static void my_Logging_cb(const int logLevel, const char *const logMessage)
  52041. {
  52042. (void)logLevel;
  52043. (void)logMessage;
  52044. log_cnt++;
  52045. }
  52046. #endif /* DEBUG_WOLFSSL */
  52047. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void)
  52048. {
  52049. wc_test_ret_t ret;
  52050. #ifdef DEBUG_WOLFSSL
  52051. const char* msg = "Testing, testing. 1, 2, 3, 4 ...";
  52052. byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  52053. byte b[256];
  52054. int i;
  52055. WOLFSSL_ENTER("logging_test (debug)");
  52056. for (i = 0; i < (int)sizeof(b); i++)
  52057. b[i] = i;
  52058. ret = wolfSSL_Debugging_ON();
  52059. if (ret != 0)
  52060. return WC_TEST_RET_ENC_EC(ret);
  52061. ret = wolfSSL_SetLoggingCb(my_Logging_cb);
  52062. if (ret != 0)
  52063. return WC_TEST_RET_ENC_EC(ret);
  52064. WOLFSSL_MSG(msg);
  52065. WOLFSSL_BUFFER(a, sizeof(a));
  52066. WOLFSSL_BUFFER(b, sizeof(b));
  52067. WOLFSSL_BUFFER(NULL, 0);
  52068. WOLFSSL_ERROR(MEMORY_E);
  52069. WOLFSSL_ERROR_MSG(msg);
  52070. /* turn off logs */
  52071. wolfSSL_Debugging_OFF();
  52072. /* capture log count */
  52073. i = log_cnt;
  52074. /* validate no logs are output when disabled */
  52075. WOLFSSL_MSG(msg);
  52076. WOLFSSL_BUFFER(a, sizeof(a));
  52077. WOLFSSL_BUFFER(b, sizeof(b));
  52078. WOLFSSL_BUFFER(NULL, 0);
  52079. WOLFSSL_ERROR(MEMORY_E);
  52080. WOLFSSL_ERROR_MSG(msg);
  52081. /* check the logs were disabled */
  52082. if (i != log_cnt)
  52083. return WC_TEST_RET_ENC_NC;
  52084. /* restore callback and leave logging enabled */
  52085. wolfSSL_SetLoggingCb(NULL);
  52086. wolfSSL_Debugging_ON();
  52087. /* suppress unused args */
  52088. (void)a;
  52089. (void)b;
  52090. #else
  52091. WOLFSSL_ENTER("logging_test");
  52092. ret = wolfSSL_Debugging_ON();
  52093. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52094. return WC_TEST_RET_ENC_EC(ret);
  52095. wolfSSL_Debugging_OFF();
  52096. ret = wolfSSL_SetLoggingCb(NULL);
  52097. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52098. return WC_TEST_RET_ENC_EC(ret);
  52099. #endif /* DEBUG_WOLFSSL */
  52100. return 0;
  52101. }
  52102. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  52103. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void)
  52104. #else
  52105. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void)
  52106. #endif
  52107. {
  52108. #ifdef WOLFSSL_PTHREADS
  52109. wolfSSL_Mutex m;
  52110. #endif
  52111. #if defined(WOLFSSL_PTHREADS) || (!defined(WOLFSSL_NO_MALLOC) && \
  52112. !defined(WOLFSSL_USER_MUTEX) && defined(WOLFSSL_STATIC_MEMORY))
  52113. wc_test_ret_t ret;
  52114. #endif
  52115. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX)
  52116. #ifndef WOLFSSL_STATIC_MEMORY
  52117. wolfSSL_Mutex *mm = wc_InitAndAllocMutex();
  52118. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (1)");
  52119. #else
  52120. wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex),
  52121. HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52122. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (2)");
  52123. if (mm != NULL) {
  52124. ret = wc_InitMutex(mm);
  52125. if (ret != 0) {
  52126. WOLFSSL_MSG("Init Mutex failed");
  52127. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52128. return WC_TEST_RET_ENC_EC(ret);
  52129. }
  52130. }
  52131. #endif
  52132. if (mm == NULL)
  52133. return WC_TEST_RET_ENC_ERRNO;
  52134. wc_FreeMutex(mm);
  52135. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52136. #endif
  52137. /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */
  52138. #ifdef WOLFSSL_PTHREADS
  52139. ret = wc_InitMutex(&m);
  52140. if (ret != 0)
  52141. return WC_TEST_RET_ENC_EC(ret);
  52142. ret = wc_LockMutex(&m);
  52143. if (ret != 0)
  52144. return WC_TEST_RET_ENC_EC(ret);
  52145. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52146. /* trying to free a locked mutex is not portable behavior with pthread */
  52147. /* Attempting to destroy a locked mutex results in undefined behavior */
  52148. ret = wc_FreeMutex(&m);
  52149. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52150. return WC_TEST_RET_ENC_EC(ret);
  52151. #endif
  52152. ret = wc_UnLockMutex(&m);
  52153. if (ret != 0)
  52154. return WC_TEST_RET_ENC_EC(ret);
  52155. ret = wc_FreeMutex(&m);
  52156. if (ret != 0)
  52157. return WC_TEST_RET_ENC_EC(ret);
  52158. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52159. /* Trying to use a pthread after free'ing is not portable behavior */
  52160. ret = wc_LockMutex(&m);
  52161. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52162. return WC_TEST_RET_ENC_EC(ret);
  52163. ret = wc_UnLockMutex(&m);
  52164. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52165. return WC_TEST_RET_ENC_EC(ret);
  52166. #endif
  52167. #endif
  52168. return 0;
  52169. }
  52170. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  52171. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \
  52172. !defined(WOLFSSL_STATIC_MEMORY)
  52173. static wc_test_ret_t malloc_cnt = 0;
  52174. static wc_test_ret_t realloc_cnt = 0;
  52175. static wc_test_ret_t free_cnt = 0;
  52176. #ifdef WOLFSSL_DEBUG_MEMORY
  52177. static void *my_Malloc_cb(size_t size, const char* func, unsigned int line)
  52178. {
  52179. (void) func;
  52180. (void) line;
  52181. #else
  52182. static void *my_Malloc_cb(size_t size)
  52183. {
  52184. #endif
  52185. malloc_cnt++;
  52186. #ifndef WOLFSSL_NO_MALLOC
  52187. return malloc(size); /* native heap */
  52188. #else
  52189. WOLFSSL_MSG("No malloc available");
  52190. (void)size;
  52191. return NULL;
  52192. #endif
  52193. }
  52194. #ifdef WOLFSSL_DEBUG_MEMORY
  52195. static void my_Free_cb(void *ptr, const char* func, unsigned int line)
  52196. {
  52197. (void) func;
  52198. (void) line;
  52199. #else
  52200. static void my_Free_cb(void *ptr)
  52201. {
  52202. #endif
  52203. free_cnt++;
  52204. #ifndef WOLFSSL_NO_MALLOC
  52205. free(ptr); /* native heap */
  52206. #else
  52207. WOLFSSL_MSG("No free available");
  52208. (void)ptr;
  52209. #endif
  52210. }
  52211. #ifdef WOLFSSL_DEBUG_MEMORY
  52212. static void *my_Realloc_cb(void *ptr, size_t size, const char* func, unsigned int line)
  52213. {
  52214. (void) func;
  52215. (void) line;
  52216. #else
  52217. static void *my_Realloc_cb(void *ptr, size_t size)
  52218. {
  52219. #endif
  52220. realloc_cnt++;
  52221. #ifndef WOLFSSL_NO_MALLOC
  52222. return realloc(ptr, size); /* native heap */
  52223. #else
  52224. WOLFSSL_MSG("No realloc available");
  52225. (void)ptr;
  52226. (void)size;
  52227. return NULL;
  52228. #endif
  52229. }
  52230. #endif /* !WOLFSSL_NO_MALLOC */
  52231. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void)
  52232. {
  52233. wc_test_ret_t ret = 0;
  52234. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52235. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52236. byte* b = NULL;
  52237. #endif
  52238. wolfSSL_Malloc_cb mc;
  52239. wolfSSL_Free_cb fc;
  52240. wolfSSL_Realloc_cb rc;
  52241. WOLFSSL_ENTER("memcb_test");
  52242. /* Save existing memory callbacks */
  52243. ret = wolfSSL_GetAllocators(&mc, &fc, &rc);
  52244. if (ret != 0)
  52245. return WC_TEST_RET_ENC_EC(ret);
  52246. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52247. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52248. /* test realloc */
  52249. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52250. if (b == NULL) {
  52251. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb);
  52252. }
  52253. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52254. b = NULL;
  52255. /* Use API. */
  52256. ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb,
  52257. (wolfSSL_Free_cb)my_Free_cb,
  52258. (wolfSSL_Realloc_cb)my_Realloc_cb);
  52259. if (ret != 0) {
  52260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb);
  52261. }
  52262. b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52263. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52264. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52265. #ifndef WOLFSSL_STATIC_MEMORY
  52266. #ifndef WOLFSSL_CHECK_MEM_ZERO
  52267. if (malloc_cnt != 1 || free_cnt != 1 || realloc_cnt != 1)
  52268. #else
  52269. /* Checking zeroized memory means realloc is a malloc and free. */
  52270. if (malloc_cnt != 2 || free_cnt != 2 || realloc_cnt != 0)
  52271. #endif
  52272. #else
  52273. if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0)
  52274. #endif
  52275. ret = WC_TEST_RET_ENC_NC;
  52276. #endif /* !WOLFSSL_NO_MALLOC */
  52277. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52278. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52279. exit_memcb:
  52280. /* reset malloc/free/realloc counts */
  52281. malloc_cnt = 0;
  52282. free_cnt = 0;
  52283. realloc_cnt = 0;
  52284. #endif
  52285. /* restore memory callbacks */
  52286. wolfSSL_SetAllocators(mc, fc, rc);
  52287. return ret;
  52288. }
  52289. #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */
  52290. #if defined(WOLFSSL_CAAM_BLOB)
  52291. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void)
  52292. {
  52293. wc_test_ret_t ret = 0;
  52294. byte out[112];
  52295. byte blob[112];
  52296. word32 outSz;
  52297. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  52298. {
  52299. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  52300. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  52301. };
  52302. WOLFSSL_SMALL_STACK_STATIC const byte text[] =
  52303. {
  52304. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  52305. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  52306. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  52307. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  52308. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  52309. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  52310. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  52311. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  52312. };
  52313. WOLFSSL_ENTER("blob_test");
  52314. XMEMSET(blob, 0, sizeof(blob));
  52315. XMEMSET(out, 0, sizeof(out));
  52316. outSz = sizeof(blob);
  52317. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52318. if (ret != 0)
  52319. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52320. blob[outSz - 2] += 1;
  52321. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52322. if (ret == 0) { /* should fail with altered blob */
  52323. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52324. }
  52325. XMEMSET(blob, 0, sizeof(blob));
  52326. outSz = sizeof(blob);
  52327. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52328. if (ret != 0)
  52329. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52330. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52331. if (ret != 0)
  52332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52333. if (XMEMCMP(out, iv, sizeof(iv))) {
  52334. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52335. }
  52336. XMEMSET(blob, 0, sizeof(blob));
  52337. outSz = sizeof(blob);
  52338. ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz);
  52339. if (ret != 0)
  52340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52341. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52342. if (ret != 0)
  52343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52344. if (XMEMCMP(out, text, sizeof(text))) {
  52345. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52346. }
  52347. exit_blob:
  52348. return ret;
  52349. }
  52350. #endif /* WOLFSSL_CAAM_BLOB */
  52351. #ifdef WOLF_CRYPTO_CB
  52352. /* Example custom context for crypto callback */
  52353. typedef struct {
  52354. int exampleVar; /* flag for testing if only crypt is enabled. */
  52355. } myCryptoDevCtx;
  52356. #ifdef WOLF_CRYPTO_CB_ONLY_RSA
  52357. /* Testing rsa cb when CB_ONLY_RSA is enabled
  52358. * When CB_ONLY_RSA is enabled, software imple. is not available.
  52359. *
  52360. * ctx callback ctx
  52361. * returen 0 on success, otherwise return negative
  52362. */
  52363. static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
  52364. {
  52365. wc_test_ret_t ret = 0;
  52366. #if !defined(NO_RSA)
  52367. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52368. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key,
  52369. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52370. byte* tmp = NULL;
  52371. #else
  52372. RsaKey key[1];
  52373. byte tmp[FOURK_BUF];
  52374. #endif
  52375. size_t bytes;
  52376. const word32 inLen = (word32)TEST_STRING_SZ;
  52377. word32 idx = 0;
  52378. word32 sigSz;
  52379. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  52380. byte out[RSA_TEST_BYTES];
  52381. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  52382. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  52383. !defined(NO_FILESYSTEM)
  52384. XFILE file;
  52385. #endif
  52386. #ifdef WOLFSSL_KEY_GEN
  52387. WC_RNG rng;
  52388. #endif
  52389. #ifdef USE_CERT_BUFFERS_1024
  52390. bytes = (size_t)sizeof_client_key_der_1024;
  52391. if (bytes < (size_t)sizeof_client_cert_der_1024)
  52392. bytes = (size_t)sizeof_client_cert_der_1024;
  52393. #elif defined(USE_CERT_BUFFERS_2048)
  52394. bytes = (size_t)sizeof_client_key_der_2048;
  52395. if (bytes < (size_t)sizeof_client_cert_der_2048)
  52396. bytes = (size_t)sizeof_client_cert_der_2048;
  52397. #elif defined(USE_CERT_BUFFERS_3072)
  52398. bytes = (size_t)sizeof_client_key_der_3072;
  52399. if (bytes < (size_t)sizeof_client_cert_der_3072)
  52400. bytes = (size_t)sizeof_client_cert_der_3072;
  52401. #elif defined(USE_CERT_BUFFERS_4096)
  52402. bytes = (size_t)sizeof_client_key_der_4096;
  52403. if (bytes < (size_t)sizeof_client_cert_der_4096)
  52404. bytes = (size_t)sizeof_client_cert_der_4096;
  52405. #else
  52406. bytes = FOURK_BUF;
  52407. #endif
  52408. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52409. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52410. if (tmp == NULL)
  52411. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52412. #endif
  52413. #ifdef USE_CERT_BUFFERS_1024
  52414. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  52415. #elif defined(USE_CERT_BUFFERS_2048)
  52416. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  52417. #elif defined(USE_CERT_BUFFERS_3072)
  52418. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  52419. #elif defined(USE_CERT_BUFFERS_4096)
  52420. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  52421. #elif !defined(NO_FILESYSTEM)
  52422. file = XFOPEN(clientKey, "rb");
  52423. if (!file) {
  52424. ret = WC_TEST_RET_ENC_ERRNO;
  52425. err_sys("can't open ./certs/client-key.der, "
  52426. "Please run from wolfSSL home dir", ret);
  52427. ERROR_OUT(ret, exit_onlycb);
  52428. }
  52429. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  52430. XFCLOSE(file);
  52431. if (bytes == 0)
  52432. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52433. #endif
  52434. #ifdef WOLFSSL_KEY_GEN
  52435. /* wc_CryptoCb_MakeRsaKey cb test, no actual making key
  52436. * wc_MakeRsaKey() -> rsa cb ->
  52437. * myCryptoDevCb -> wc_MakeRsaKey(CBONLY_TEST_DEVID)
  52438. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
  52439. */
  52440. ctx->exampleVar = 99;
  52441. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52442. if (ret != 0)
  52443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52444. /* wc_MakeRsaKey() -> rsa cb ->
  52445. * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
  52446. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
  52447. */
  52448. ctx->exampleVar = 1;
  52449. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52450. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52452. } else
  52453. /* reset return code */
  52454. ret = 0;
  52455. #endif
  52456. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  52457. if (ret != 0)
  52458. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52459. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  52460. if (ret != 0)
  52461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52462. sigSz = (word32)wc_RsaEncryptSize(key);
  52463. /* wc_CryptoCb_Rsa cb test, no actual rsa operation */
  52464. if (ret == 0) {
  52465. /* wc_SignatureGenerate() -> rsa cb ->
  52466. * myCryptoDevCb -> wc_RsaFunction(CBONLY_TEST_DEVID)
  52467. * wc_RsaFunction(CBONLY_TEST_DEVID) expects to return 0(success)
  52468. */
  52469. ctx->exampleVar = 99;
  52470. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52471. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52472. if (ret != 0)
  52473. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52474. }
  52475. if (ret == 0) {
  52476. /* wc_SignatureGenerate() -> rsa cb ->
  52477. * myCryptoDevCb -> wc_RsaFunction(INVALID_DEVID)
  52478. * wc_SignatureGenerate(INVALID_DEVID) expects to
  52479. * return NO_VALID_DEVID(failure)
  52480. */
  52481. ctx->exampleVar = 1;
  52482. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52483. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52484. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52485. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52486. } else
  52487. /* reset return code */
  52488. ret = 0;
  52489. }
  52490. exit_onlycb:
  52491. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52492. if (key != NULL) {
  52493. wc_FreeRsaKey(key);
  52494. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52495. }
  52496. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52497. #else
  52498. wc_FreeRsaKey(key);
  52499. #endif
  52500. #endif
  52501. return ret;
  52502. }
  52503. #endif
  52504. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  52505. /* Testing rsa cb when CB_ONLY_ECC is enabled
  52506. * When CB_ONLY_ECC is enabled, software imple. is not available.
  52507. *
  52508. * ctx callback ctx
  52509. * returen 0 on success, otherwise return negative
  52510. */
  52511. static wc_test_ret_t ecc_onlycb_test(myCryptoDevCtx *ctx)
  52512. {
  52513. wc_test_ret_t ret = 0;
  52514. #if defined(HAVE_ECC)
  52515. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52516. ecc_key* key = (ecc_key *)XMALLOC(sizeof *key,
  52517. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52518. ecc_key* pub = (ecc_key *)XMALLOC(sizeof *pub,
  52519. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52520. byte* out = (byte*)XMALLOC(sizeof(byte),
  52521. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52522. #ifdef OPENSSL_EXTRA
  52523. byte* check = (byte*)XMALLOC(sizeof(byte)*(256), HEAP_HINT,
  52524. DYNAMIC_TYPE_TMP_BUFFER);
  52525. #endif
  52526. #else
  52527. ecc_key key[1];
  52528. ecc_key pub[1];
  52529. byte out[256];
  52530. #ifdef OPENSSL_EXTRA
  52531. unsigned char check[256];
  52532. #endif
  52533. #endif
  52534. #ifdef OPENSSL_EXTRA
  52535. WOLFSSL_EVP_PKEY* privKey = NULL;
  52536. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52537. #ifdef USE_CERT_BUFFERS_256
  52538. ecc_key* pkey;
  52539. const unsigned char* cp;
  52540. #endif
  52541. WOLFSSL_EVP_MD_CTX mdCtx;
  52542. const char testData[] = "Hi There";
  52543. size_t checkSz = -1;
  52544. const unsigned char* p;
  52545. const unsigned char check_v[256] = {
  52546. 0x30,0x45,0x02,0x20,0x1b,0x5c,0x2a,0xf0,0x18,0x09,
  52547. 0x74,0x65,0xa1,0x04,0x76,0x3a,0xce,0xcc,0xe5,0x34,
  52548. 0x5e,0x89,0xed,0x40,0x1e,0x5a,0xb1,0x53,0xb4,0xff,
  52549. 0xc7,0x18,0xfe,0x0f,0xc7,0xa6,0x02,0x21,0x00,0xe5,
  52550. 0x70,0x21,0xfc,0xf9,0x63,0x36,0xfd,0x16,0x18,0x08,
  52551. 0x9a,0x63,0x61,0x0f,0xe7,0x7c,0xa3,0xc9,0x14,0xa3,
  52552. 0x30,0x87,0xf7,0xf5,0x70,0x19,0xaf,0x56,0x96,0x9b,
  52553. 0xd8,0x64,0xcd,0xd9,0xff,0x7b,0x2a,0x55,0x52,0xca,
  52554. 0x41,0xb2,0xa6,0xa4,0x8a,0x3b,0x02,0x20,0x8c,0xc5,
  52555. 0xf9,0xc1,0x7d,0x2a,0x65,0x6c,0xe6,0x5a,0xe3,0x76,
  52556. 0x9b,0xab,0x0b,0x9f,0xaf,0x62,0x5d,0xb2,0x60,0xd7,
  52557. 0xeb,0xb4,0x1b,0x73,0xdc,0x01,0x7d,0x7b,0xab,0xc1,
  52558. 0x0c,0x74,0x96,0x41,0xe6,0x3f,0xc5,0x86,0xe6,0x7d,
  52559. 0x2b,0x9d,0x54,0x6b,0xcd,0x31,0x35,0x1f,0xdb,0x49,
  52560. 0x1f,0x32,0x34,0xf8,0x57,0x12,0x86,0x5c,0x0e,0x80,
  52561. 0x55,0x8d,0xff,0xd8,0xbd,0xdf,0x32,0x26,0x62,0x42,
  52562. 0x09,0xda,0xf7,0x74,0xf2,0x3f,0xe6,0xf1,0x77,0x82,
  52563. 0xce,0xe4,0xbb,0x61,0xa6,0xc0,0x17,0x0c,0x6c,0x47,
  52564. 0x2a,0x40,0x1c,0x2b,0xe0,0x98,0x3b,0xbf,0xc6,0xf8,
  52565. 0x6d,0xfd,0xd0,0xfa,0xc1,0x02,0xfb,0x5f,0xfb,0xb0,
  52566. 0xcb,0xd9,0xa3,0x59,0x94,0xe9,0x0f,0x74,0xbb,0x3f,
  52567. 0x64,0xa3,0x83,0xc4,0x2b,0xf7,0xd2,0x97,0xbf,0x3b,
  52568. 0xcf,0xbb,0x60,0x81,0x33,0x94,0xfa,0x0d,0x35,0xd2,
  52569. 0x3d,0xb9,0x99,0xe3,0x12,0xf8,0xf4,0xa3,0x74,0xf4,
  52570. 0x94,0x1d,0x7a,0x66,0xf8,0xd1,0x1d,0xcf,0xb0,0x48,
  52571. 0xef,0x8c,0x94,0x6f,0xdd,0x62,
  52572. };
  52573. #endif
  52574. WC_RNG rng;
  52575. EncryptedInfo encInfo;
  52576. int keyFormat = 0;
  52577. word32 keyIdx = 0;
  52578. byte in[] = "Everyone gets Friday off. ecc p";
  52579. word32 inLen = (word32)XSTRLEN((char*)in);
  52580. word32 outLen;
  52581. int verify;
  52582. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52583. if (key == NULL || pub == NULL) {
  52584. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52585. }
  52586. #endif
  52587. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  52588. if (ret != 0)
  52589. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52590. /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */
  52591. ctx->exampleVar = 99;
  52592. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52593. if (ret != 0)
  52594. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52595. ctx->exampleVar = 1;
  52596. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52597. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52598. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52599. } else
  52600. /* reset return code */
  52601. ret = 0;
  52602. #ifdef USE_CERT_BUFFERS_256
  52603. if (ret == 0) {
  52604. /* load ECC private key and perform private transform */
  52605. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx,
  52606. key, sizeof_ecc_key_der_256);
  52607. }
  52608. if (ret != 0)
  52609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52610. /* wc_CryptoCb_EccSign cb test, no actual testing */
  52611. ctx->exampleVar = 99;
  52612. if (ret == 0) {
  52613. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52614. }
  52615. if (ret != 0)
  52616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52617. ctx->exampleVar = 1;
  52618. if (ret == 0) {
  52619. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52620. }
  52621. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52622. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52623. }
  52624. else
  52625. ret = 0;
  52626. /* wc_CryptoCb_EccVerify cb test, no actual testing */
  52627. ctx->exampleVar = 99;
  52628. if (ret == 0) {
  52629. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52630. }
  52631. if (ret != 0)
  52632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52633. ctx->exampleVar = 1;
  52634. if (ret == 0) {
  52635. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52636. }
  52637. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52639. }
  52640. else
  52641. ret = 0;
  52642. /* wc_CryptoCb_Ecdh cb test, no actual testing */
  52643. /* make public key for shared secret */
  52644. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  52645. ctx->exampleVar = 99;
  52646. if (ret == 0) {
  52647. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52648. }
  52649. if (ret != 0)
  52650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52651. ctx->exampleVar = 1;
  52652. if (ret == 0) {
  52653. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52654. }
  52655. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52656. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52657. }
  52658. else
  52659. ret = 0;
  52660. #ifdef OPENSSL_EXTRA
  52661. (void)pkey;
  52662. cp = ecc_clikey_der_256;
  52663. privKey = d2i_PrivateKey(WC_EVP_PKEY_EC, NULL, &cp,
  52664. sizeof_ecc_clikey_der_256);
  52665. if (privKey == NULL) {
  52666. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52667. }
  52668. pkey = (ecc_key*)privKey->ecc->internal;
  52669. pkey->devId = devId;
  52670. p = ecc_clikeypub_der_256;
  52671. pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256);
  52672. if (pubKey == NULL) {
  52673. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52674. }
  52675. pkey = (ecc_key*)pubKey->ecc->internal;
  52676. pkey->devId = devId;
  52677. /* sign */
  52678. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52679. ret = EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, privKey);
  52680. if (ret != WOLFSSL_SUCCESS) {
  52681. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52682. }
  52683. ret = EVP_DigestSignUpdate(&mdCtx, testData,
  52684. (unsigned int)XSTRLEN(testData));
  52685. if (ret != WOLFSSL_SUCCESS) {
  52686. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52687. }
  52688. ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz);
  52689. if (ret != WOLFSSL_SUCCESS) {
  52690. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52691. }
  52692. ctx->exampleVar = 99;
  52693. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52694. /* just called crypt callback as dummy
  52695. * EVP_DigestSignFinal returns 0 internally.
  52696. */
  52697. if (ret != 0)
  52698. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52699. ctx->exampleVar = 1;
  52700. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52701. /* just called crypt callback as dummy
  52702. * EVP_DigestSignFinal returns 0 internally.
  52703. */
  52704. if (ret != 0)
  52705. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52706. /* restore checkSz for verify */
  52707. checkSz = 71;
  52708. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52709. if (ret != WOLFSSL_SUCCESS) {
  52710. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52711. }
  52712. /* verify */
  52713. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52714. if (ret == WOLFSSL_SUCCESS) {
  52715. ret = EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, pubKey);
  52716. }
  52717. if (ret != WOLFSSL_SUCCESS) {
  52718. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52719. }
  52720. if (ret == WOLFSSL_SUCCESS) {
  52721. ret = EVP_DigestVerifyUpdate(&mdCtx, testData,
  52722. (unsigned int)XSTRLEN(testData));
  52723. }
  52724. if (ret != WOLFSSL_SUCCESS) {
  52725. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52726. }
  52727. ctx->exampleVar = 99;
  52728. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52729. /* just called crypt callback as dummy
  52730. * EVP_DigestSignFinal returns 0 internally.
  52731. */
  52732. if (ret != 0)
  52733. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52734. ctx->exampleVar = 1;
  52735. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52736. /* just called crypt callback as dummy
  52737. * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID.
  52738. */
  52739. if (ret != -1) {
  52740. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52741. }
  52742. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52743. if (ret != WOLFSSL_SUCCESS) {
  52744. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52745. } else
  52746. ret = 0;
  52747. #endif
  52748. #else
  52749. (void)verify;
  52750. (void)outLen;
  52751. (void)inLen;
  52752. (void)out;
  52753. (void)pub;
  52754. #ifdef OPENSSL_EXTRA
  52755. (void)privKey;
  52756. (void)pubKey;
  52757. (void)mdCtx;
  52758. (void)check;
  52759. (void)checkSz;
  52760. (void)p;
  52761. #endif
  52762. #endif
  52763. (void)keyFormat;
  52764. (void)encInfo;
  52765. exit_onlycb:
  52766. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52767. if (key != NULL) {
  52768. wc_ecc_free(key);
  52769. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52770. }
  52771. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52772. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52773. #ifdef OPENSSL_EXTRA
  52774. if (check) {
  52775. FREE(check, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52776. }
  52777. #endif
  52778. #else
  52779. wc_ecc_free(key);
  52780. #ifdef OPENSSL_EXTRA
  52781. if (privKey)
  52782. wolfSSL_EVP_PKEY_free(privKey);
  52783. if (pubKey)
  52784. wolfSSL_EVP_PKEY_free(pubKey);
  52785. #endif
  52786. #endif
  52787. #endif /* HAVE_ECC */
  52788. return ret;
  52789. }
  52790. #endif
  52791. /* Example crypto dev callback function that calls software version */
  52792. static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
  52793. {
  52794. int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); /* return this to bypass HW and
  52795. use SW */
  52796. myCryptoDevCtx* myCtx = (myCryptoDevCtx*)ctx;
  52797. if (info == NULL)
  52798. return BAD_FUNC_ARG;
  52799. #ifdef DEBUG_WOLFSSL
  52800. WOLFSSL_MSG_EX("CryptoDevCb: Algo Type %d\n", info->algo_type);
  52801. #endif
  52802. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  52803. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  52804. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  52805. /* if RNG only supports crypto callback, just use seed */
  52806. ret = wc_GenerateSeed(&info->rng.rng->seed,
  52807. info->rng.out, info->rng.sz);
  52808. #elif !defined(WC_NO_RNG)
  52809. /* set devId to invalid, so software is used */
  52810. info->rng.rng->devId = INVALID_DEVID;
  52811. ret = wc_RNG_GenerateBlock(info->rng.rng,
  52812. info->rng.out, info->rng.sz);
  52813. /* reset devId */
  52814. info->rng.rng->devId = devIdArg;
  52815. #endif
  52816. }
  52817. else if (info->algo_type == WC_ALGO_TYPE_SEED) {
  52818. #ifndef WC_NO_RNG
  52819. ALIGN32 static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 };
  52820. word32* seedWord32 = (word32*)seed;
  52821. word32 len;
  52822. /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */
  52823. while (info->seed.sz > 0) {
  52824. len = (word32)sizeof(seed);
  52825. if (info->seed.sz < len)
  52826. len = info->seed.sz;
  52827. XMEMCPY(info->seed.seed, seed, sizeof(seed));
  52828. info->seed.seed += len;
  52829. info->seed.sz -= len;
  52830. (*seedWord32)++;
  52831. }
  52832. ret = 0;
  52833. #endif
  52834. }
  52835. else if (info->algo_type == WC_ALGO_TYPE_PK) {
  52836. #ifdef DEBUG_WOLFSSL
  52837. WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type);
  52838. #endif
  52839. #ifndef NO_RSA
  52840. if (info->pk.type == WC_PK_TYPE_RSA) {
  52841. /* set devId to invalid, so software is used */
  52842. info->pk.rsa.key->devId = INVALID_DEVID;
  52843. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52844. #ifdef DEBUG_WOLFSSL
  52845. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52846. #endif
  52847. if (myCtx->exampleVar == 99) {
  52848. info->pk.rsa.key->devId = devIdArg;
  52849. return 0;
  52850. }
  52851. #endif
  52852. switch (info->pk.rsa.type) {
  52853. case RSA_PUBLIC_ENCRYPT:
  52854. case RSA_PUBLIC_DECRYPT:
  52855. /* perform software based RSA public op */
  52856. ret = wc_RsaFunction(
  52857. info->pk.rsa.in, info->pk.rsa.inLen,
  52858. info->pk.rsa.out, info->pk.rsa.outLen,
  52859. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52860. break;
  52861. case RSA_PRIVATE_ENCRYPT:
  52862. case RSA_PRIVATE_DECRYPT:
  52863. /* perform software based RSA private op */
  52864. ret = wc_RsaFunction(
  52865. info->pk.rsa.in, info->pk.rsa.inLen,
  52866. info->pk.rsa.out, info->pk.rsa.outLen,
  52867. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52868. break;
  52869. }
  52870. /* reset devId */
  52871. info->pk.rsa.key->devId = devIdArg;
  52872. }
  52873. #ifdef WOLFSSL_KEY_GEN
  52874. else if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
  52875. info->pk.rsakg.key->devId = INVALID_DEVID;
  52876. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52877. #ifdef DEBUG_WOLFSSL
  52878. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52879. #endif
  52880. if (myCtx->exampleVar == 99) {
  52881. info->pk.rsakg.key->devId = devIdArg;
  52882. return 0;
  52883. }
  52884. #endif
  52885. #ifdef HAVE_FIPS
  52886. for (;;) {
  52887. #endif
  52888. ret = wc_MakeRsaKey(info->pk.rsakg.key, info->pk.rsakg.size,
  52889. info->pk.rsakg.e, info->pk.rsakg.rng);
  52890. #ifdef HAVE_FIPS
  52891. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  52892. continue;
  52893. break;
  52894. }
  52895. #endif
  52896. /* reset devId */
  52897. info->pk.rsakg.key->devId = devIdArg;
  52898. }
  52899. #endif
  52900. #endif /* !NO_RSA */
  52901. #ifdef HAVE_ECC
  52902. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  52903. /* set devId to invalid, so software is used */
  52904. info->pk.eckg.key->devId = INVALID_DEVID;
  52905. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52906. #ifdef DEBUG_WOLFSSL
  52907. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52908. #endif
  52909. if (myCtx->exampleVar == 99) {
  52910. info->pk.eckg.key->devId = devIdArg;
  52911. return 0;
  52912. }
  52913. #endif
  52914. ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
  52915. info->pk.eckg.key, info->pk.eckg.curveId);
  52916. /* reset devId */
  52917. info->pk.eckg.key->devId = devIdArg;
  52918. }
  52919. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  52920. /* set devId to invalid, so software is used */
  52921. info->pk.eccsign.key->devId = INVALID_DEVID;
  52922. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52923. #ifdef DEBUG_WOLFSSL
  52924. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52925. #endif
  52926. if (myCtx->exampleVar == 99) {
  52927. info->pk.eccsign.key->devId = devIdArg;
  52928. return 0;
  52929. }
  52930. #endif
  52931. ret = wc_ecc_sign_hash(
  52932. info->pk.eccsign.in, info->pk.eccsign.inlen,
  52933. info->pk.eccsign.out, info->pk.eccsign.outlen,
  52934. info->pk.eccsign.rng, info->pk.eccsign.key);
  52935. /* reset devId */
  52936. info->pk.eccsign.key->devId = devIdArg;
  52937. }
  52938. else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
  52939. /* set devId to invalid, so software is used */
  52940. info->pk.eccverify.key->devId = INVALID_DEVID;
  52941. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52942. #ifdef DEBUG_WOLFSSL
  52943. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52944. #endif
  52945. if (myCtx->exampleVar == 99) {
  52946. info->pk.eccverify.key->devId = devIdArg;
  52947. return 0;
  52948. }
  52949. #endif
  52950. ret = wc_ecc_verify_hash(
  52951. info->pk.eccverify.sig, info->pk.eccverify.siglen,
  52952. info->pk.eccverify.hash, info->pk.eccverify.hashlen,
  52953. info->pk.eccverify.res, info->pk.eccverify.key);
  52954. /* reset devId */
  52955. info->pk.eccverify.key->devId = devIdArg;
  52956. }
  52957. else if (info->pk.type == WC_PK_TYPE_ECDH) {
  52958. /* set devId to invalid, so software is used */
  52959. info->pk.ecdh.private_key->devId = INVALID_DEVID;
  52960. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52961. #ifdef DEBUG_WOLFSSL
  52962. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52963. #endif
  52964. if (myCtx->exampleVar == 99) {
  52965. info->pk.ecdh.private_key->devId = devIdArg;
  52966. return 0;
  52967. }
  52968. #endif
  52969. ret = wc_ecc_shared_secret(
  52970. info->pk.ecdh.private_key, info->pk.ecdh.public_key,
  52971. info->pk.ecdh.out, info->pk.ecdh.outlen);
  52972. /* reset devId */
  52973. info->pk.ecdh.private_key->devId = devIdArg;
  52974. }
  52975. #endif /* HAVE_ECC */
  52976. #ifdef HAVE_CURVE25519
  52977. if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
  52978. /* set devId to invalid, so software is used */
  52979. info->pk.curve25519kg.key->devId = INVALID_DEVID;
  52980. ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
  52981. info->pk.curve25519kg.size, info->pk.curve25519kg.key);
  52982. /* reset devId */
  52983. info->pk.curve25519kg.key->devId = devIdArg;
  52984. }
  52985. else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
  52986. /* set devId to invalid, so software is used */
  52987. info->pk.curve25519.private_key->devId = INVALID_DEVID;
  52988. ret = wc_curve25519_shared_secret_ex(
  52989. info->pk.curve25519.private_key, info->pk.curve25519.public_key,
  52990. info->pk.curve25519.out, info->pk.curve25519.outlen,
  52991. info->pk.curve25519.endian);
  52992. /* reset devId */
  52993. info->pk.curve25519.private_key->devId = devIdArg;
  52994. }
  52995. #endif /* HAVE_CURVE25519 */
  52996. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  52997. if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
  52998. /* set devId to invalid, so software is used */
  52999. info->pk.ed25519kg.key->devId = INVALID_DEVID;
  53000. ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
  53001. info->pk.ed25519kg.size, info->pk.ed25519kg.key);
  53002. /* reset devId */
  53003. info->pk.ed25519kg.key->devId = devIdArg;
  53004. }
  53005. #ifdef HAVE_ED25519_SIGN
  53006. else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  53007. /* set devId to invalid, so software is used */
  53008. info->pk.ed25519sign.key->devId = INVALID_DEVID;
  53009. ret = wc_ed25519_sign_msg_ex(
  53010. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  53011. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  53012. info->pk.ed25519sign.key, info->pk.ed25519sign.type,
  53013. info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
  53014. /* reset devId */
  53015. info->pk.ed25519sign.key->devId = devIdArg;
  53016. }
  53017. #endif
  53018. #ifdef HAVE_ED25519_VERIFY
  53019. else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
  53020. /* set devId to invalid, so software is used */
  53021. info->pk.ed25519verify.key->devId = INVALID_DEVID;
  53022. ret = wc_ed25519_verify_msg_ex(
  53023. info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
  53024. info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
  53025. info->pk.ed25519verify.res, info->pk.ed25519verify.key,
  53026. info->pk.ed25519verify.type, info->pk.ed25519verify.context,
  53027. info->pk.ed25519verify.contextLen);
  53028. /* reset devId */
  53029. info->pk.ed25519verify.key->devId = devIdArg;
  53030. }
  53031. #endif
  53032. #endif /* HAVE_ED25519 */
  53033. }
  53034. else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
  53035. #if !defined(NO_AES) || !defined(NO_DES3)
  53036. #ifdef HAVE_AESGCM
  53037. if (info->cipher.type == WC_CIPHER_AES_GCM) {
  53038. if (info->cipher.enc) {
  53039. /* set devId to invalid, so software is used */
  53040. info->cipher.aesgcm_enc.aes->devId = INVALID_DEVID;
  53041. ret = wc_AesGcmEncrypt(
  53042. info->cipher.aesgcm_enc.aes,
  53043. info->cipher.aesgcm_enc.out,
  53044. info->cipher.aesgcm_enc.in,
  53045. info->cipher.aesgcm_enc.sz,
  53046. info->cipher.aesgcm_enc.iv,
  53047. info->cipher.aesgcm_enc.ivSz,
  53048. info->cipher.aesgcm_enc.authTag,
  53049. info->cipher.aesgcm_enc.authTagSz,
  53050. info->cipher.aesgcm_enc.authIn,
  53051. info->cipher.aesgcm_enc.authInSz);
  53052. /* reset devId */
  53053. info->cipher.aesgcm_enc.aes->devId = devIdArg;
  53054. }
  53055. else {
  53056. /* set devId to invalid, so software is used */
  53057. info->cipher.aesgcm_dec.aes->devId = INVALID_DEVID;
  53058. ret = wc_AesGcmDecrypt(
  53059. info->cipher.aesgcm_dec.aes,
  53060. info->cipher.aesgcm_dec.out,
  53061. info->cipher.aesgcm_dec.in,
  53062. info->cipher.aesgcm_dec.sz,
  53063. info->cipher.aesgcm_dec.iv,
  53064. info->cipher.aesgcm_dec.ivSz,
  53065. info->cipher.aesgcm_dec.authTag,
  53066. info->cipher.aesgcm_dec.authTagSz,
  53067. info->cipher.aesgcm_dec.authIn,
  53068. info->cipher.aesgcm_dec.authInSz);
  53069. /* reset devId */
  53070. info->cipher.aesgcm_dec.aes->devId = devIdArg;
  53071. }
  53072. }
  53073. #endif /* HAVE_AESGCM */
  53074. #ifdef HAVE_AES_CBC
  53075. if (info->cipher.type == WC_CIPHER_AES_CBC) {
  53076. if (info->cipher.enc) {
  53077. /* set devId to invalid, so software is used */
  53078. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53079. ret = wc_AesCbcEncrypt(
  53080. info->cipher.aescbc.aes,
  53081. info->cipher.aescbc.out,
  53082. info->cipher.aescbc.in,
  53083. info->cipher.aescbc.sz);
  53084. /* reset devId */
  53085. info->cipher.aescbc.aes->devId = devIdArg;
  53086. }
  53087. else {
  53088. /* set devId to invalid, so software is used */
  53089. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53090. ret = wc_AesCbcDecrypt(
  53091. info->cipher.aescbc.aes,
  53092. info->cipher.aescbc.out,
  53093. info->cipher.aescbc.in,
  53094. info->cipher.aescbc.sz);
  53095. /* reset devId */
  53096. info->cipher.aescbc.aes->devId = devIdArg;
  53097. }
  53098. }
  53099. #endif /* HAVE_AES_CBC */
  53100. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  53101. if (info->cipher.type == WC_CIPHER_AES_ECB) {
  53102. if (info->cipher.enc) {
  53103. /* set devId to invalid, so software is used */
  53104. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53105. ret = wc_AesEcbEncrypt(
  53106. info->cipher.aesecb.aes,
  53107. info->cipher.aesecb.out,
  53108. info->cipher.aesecb.in,
  53109. info->cipher.aesecb.sz);
  53110. /* reset devId */
  53111. info->cipher.aesecb.aes->devId = devIdArg;
  53112. }
  53113. else {
  53114. /* set devId to invalid, so software is used */
  53115. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53116. ret = wc_AesEcbDecrypt(
  53117. info->cipher.aesecb.aes,
  53118. info->cipher.aesecb.out,
  53119. info->cipher.aesecb.in,
  53120. info->cipher.aesecb.sz);
  53121. /* reset devId */
  53122. info->cipher.aesecb.aes->devId = devIdArg;
  53123. }
  53124. }
  53125. #endif /* HAVE_AES_ECB */
  53126. #if defined(WOLFSSL_AES_COUNTER) && !defined(HAVE_FIPS) && \
  53127. !defined(HAVE_SELFTEST)
  53128. if (info->cipher.type == WC_CIPHER_AES_CTR) {
  53129. /* set devId to invalid, so software is used */
  53130. info->cipher.aesctr.aes->devId = INVALID_DEVID;
  53131. ret = wc_AesCtrEncrypt(
  53132. info->cipher.aesctr.aes,
  53133. info->cipher.aesctr.out,
  53134. info->cipher.aesctr.in,
  53135. info->cipher.aesctr.sz);
  53136. /* reset devId */
  53137. info->cipher.aesctr.aes->devId = devIdArg;
  53138. }
  53139. #endif /* WOLFSSL_AES_COUNTER */
  53140. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53141. if (info->cipher.type == WC_CIPHER_AES_CCM) {
  53142. if (info->cipher.enc) {
  53143. /* set devId to invalid, so software is used */
  53144. info->cipher.aesccm_enc.aes->devId = INVALID_DEVID;
  53145. ret = wc_AesCcmEncrypt(
  53146. info->cipher.aesccm_enc.aes,
  53147. info->cipher.aesccm_enc.out,
  53148. info->cipher.aesccm_enc.in,
  53149. info->cipher.aesccm_enc.sz,
  53150. info->cipher.aesccm_enc.nonce,
  53151. info->cipher.aesccm_enc.nonceSz,
  53152. info->cipher.aesccm_enc.authTag,
  53153. info->cipher.aesccm_enc.authTagSz,
  53154. info->cipher.aesccm_enc.authIn,
  53155. info->cipher.aesccm_enc.authInSz);
  53156. /* reset devId */
  53157. info->cipher.aesccm_enc.aes->devId = devIdArg;
  53158. }
  53159. else {
  53160. /* set devId to invalid, so software is used */
  53161. info->cipher.aesccm_dec.aes->devId = INVALID_DEVID;
  53162. ret = wc_AesCcmDecrypt(
  53163. info->cipher.aesccm_dec.aes,
  53164. info->cipher.aesccm_dec.out,
  53165. info->cipher.aesccm_dec.in,
  53166. info->cipher.aesccm_dec.sz,
  53167. info->cipher.aesccm_dec.nonce,
  53168. info->cipher.aesccm_dec.nonceSz,
  53169. info->cipher.aesccm_dec.authTag,
  53170. info->cipher.aesccm_dec.authTagSz,
  53171. info->cipher.aesccm_dec.authIn,
  53172. info->cipher.aesccm_dec.authInSz);
  53173. /* reset devId */
  53174. info->cipher.aesccm_dec.aes->devId = devIdArg;
  53175. }
  53176. }
  53177. #endif
  53178. #ifndef NO_DES3
  53179. if (info->cipher.type == WC_CIPHER_DES3) {
  53180. if (info->cipher.enc) {
  53181. /* set devId to invalid, so software is used */
  53182. info->cipher.des3.des->devId = INVALID_DEVID;
  53183. ret = wc_Des3_CbcEncrypt(
  53184. info->cipher.des3.des,
  53185. info->cipher.des3.out,
  53186. info->cipher.des3.in,
  53187. info->cipher.des3.sz);
  53188. /* reset devId */
  53189. info->cipher.des3.des->devId = devIdArg;
  53190. }
  53191. else {
  53192. /* set devId to invalid, so software is used */
  53193. info->cipher.des3.des->devId = INVALID_DEVID;
  53194. ret = wc_Des3_CbcDecrypt(
  53195. info->cipher.des3.des,
  53196. info->cipher.des3.out,
  53197. info->cipher.des3.in,
  53198. info->cipher.des3.sz);
  53199. /* reset devId */
  53200. info->cipher.des3.des->devId = devIdArg;
  53201. }
  53202. }
  53203. #endif /* !NO_DES3 */
  53204. #endif /* !NO_AES || !NO_DES3 */
  53205. }
  53206. #if !defined(NO_SHA) || !defined(NO_SHA256) || \
  53207. defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
  53208. else if (info->algo_type == WC_ALGO_TYPE_HASH) {
  53209. #if !defined(NO_SHA)
  53210. if (info->hash.type == WC_HASH_TYPE_SHA) {
  53211. if (info->hash.sha1 == NULL)
  53212. return NOT_COMPILED_IN;
  53213. /* set devId to invalid, so software is used */
  53214. info->hash.sha1->devId = INVALID_DEVID;
  53215. if (info->hash.in != NULL) {
  53216. ret = wc_ShaUpdate(
  53217. info->hash.sha1,
  53218. info->hash.in,
  53219. info->hash.inSz);
  53220. }
  53221. if (info->hash.digest != NULL) {
  53222. ret = wc_ShaFinal(
  53223. info->hash.sha1,
  53224. info->hash.digest);
  53225. }
  53226. /* reset devId */
  53227. info->hash.sha1->devId = devIdArg;
  53228. }
  53229. else
  53230. #endif
  53231. #if !defined(NO_SHA256)
  53232. if (info->hash.type == WC_HASH_TYPE_SHA256) {
  53233. if (info->hash.sha256 == NULL)
  53234. return NOT_COMPILED_IN;
  53235. /* set devId to invalid, so software is used */
  53236. info->hash.sha256->devId = INVALID_DEVID;
  53237. if (info->hash.in != NULL) {
  53238. ret = wc_Sha256Update(
  53239. info->hash.sha256,
  53240. info->hash.in,
  53241. info->hash.inSz);
  53242. }
  53243. if (info->hash.digest != NULL) {
  53244. ret = wc_Sha256Final(
  53245. info->hash.sha256,
  53246. info->hash.digest);
  53247. }
  53248. /* reset devId */
  53249. info->hash.sha256->devId = devIdArg;
  53250. }
  53251. else
  53252. #endif
  53253. #ifdef WOLFSSL_SHA384
  53254. if (info->hash.type == WC_HASH_TYPE_SHA384) {
  53255. if (info->hash.sha384 == NULL)
  53256. return NOT_COMPILED_IN;
  53257. #ifndef NO_SHA2_CRYPTO_CB
  53258. /* set devId to invalid, so software is used */
  53259. info->hash.sha384->devId = INVALID_DEVID;
  53260. #endif
  53261. if (info->hash.in != NULL) {
  53262. ret = wc_Sha384Update(
  53263. info->hash.sha384,
  53264. info->hash.in,
  53265. info->hash.inSz);
  53266. }
  53267. if (info->hash.digest != NULL) {
  53268. ret = wc_Sha384Final(
  53269. info->hash.sha384,
  53270. info->hash.digest);
  53271. }
  53272. #ifndef NO_SHA2_CRYPTO_CB
  53273. /* reset devId */
  53274. info->hash.sha384->devId = devIdArg;
  53275. #endif
  53276. }
  53277. else
  53278. #endif
  53279. #ifdef WOLFSSL_SHA512
  53280. if (info->hash.type == WC_HASH_TYPE_SHA512) {
  53281. if (info->hash.sha512 == NULL)
  53282. return NOT_COMPILED_IN;
  53283. #ifndef NO_SHA2_CRYPTO_CB
  53284. /* set devId to invalid, so software is used */
  53285. info->hash.sha512->devId = INVALID_DEVID;
  53286. #endif
  53287. if (info->hash.in != NULL) {
  53288. ret = wc_Sha512Update(
  53289. info->hash.sha512,
  53290. info->hash.in,
  53291. info->hash.inSz);
  53292. }
  53293. if (info->hash.digest != NULL) {
  53294. ret = wc_Sha512Final(
  53295. info->hash.sha512,
  53296. info->hash.digest);
  53297. }
  53298. #ifndef NO_SHA2_CRYPTO_CB
  53299. /* reset devId */
  53300. info->hash.sha512->devId = devIdArg;
  53301. #endif
  53302. }
  53303. else
  53304. #endif
  53305. #if defined(WOLFSSL_SHA3) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0))
  53306. if (info->hash.type == WC_HASH_TYPE_SHA3_224) {
  53307. if (info->hash.sha3 == NULL)
  53308. return NOT_COMPILED_IN;
  53309. /* set devId to invalid, so software is used */
  53310. info->hash.sha3->devId = INVALID_DEVID;
  53311. if (info->hash.in != NULL) {
  53312. ret = wc_Sha3_224_Update(
  53313. info->hash.sha3,
  53314. info->hash.in,
  53315. info->hash.inSz);
  53316. }
  53317. if (info->hash.digest != NULL) {
  53318. ret = wc_Sha3_224_Final(
  53319. info->hash.sha3,
  53320. info->hash.digest);
  53321. }
  53322. /* reset devId */
  53323. info->hash.sha3->devId = devIdArg;
  53324. }
  53325. else if (info->hash.type == WC_HASH_TYPE_SHA3_256) {
  53326. if (info->hash.sha3 == NULL)
  53327. return NOT_COMPILED_IN;
  53328. /* set devId to invalid, so software is used */
  53329. info->hash.sha3->devId = INVALID_DEVID;
  53330. if (info->hash.in != NULL) {
  53331. ret = wc_Sha3_256_Update(
  53332. info->hash.sha3,
  53333. info->hash.in,
  53334. info->hash.inSz);
  53335. }
  53336. if (info->hash.digest != NULL) {
  53337. ret = wc_Sha3_256_Final(
  53338. info->hash.sha3,
  53339. info->hash.digest);
  53340. }
  53341. /* reset devId */
  53342. info->hash.sha3->devId = devIdArg;
  53343. }
  53344. else if (info->hash.type == WC_HASH_TYPE_SHA3_384) {
  53345. if (info->hash.sha3 == NULL)
  53346. return NOT_COMPILED_IN;
  53347. /* set devId to invalid, so software is used */
  53348. info->hash.sha3->devId = INVALID_DEVID;
  53349. if (info->hash.in != NULL) {
  53350. ret = wc_Sha3_384_Update(
  53351. info->hash.sha3,
  53352. info->hash.in,
  53353. info->hash.inSz);
  53354. }
  53355. if (info->hash.digest != NULL) {
  53356. ret = wc_Sha3_384_Final(
  53357. info->hash.sha3,
  53358. info->hash.digest);
  53359. }
  53360. /* reset devId */
  53361. info->hash.sha3->devId = devIdArg;
  53362. }
  53363. else if (info->hash.type == WC_HASH_TYPE_SHA3_512) {
  53364. if (info->hash.sha3 == NULL)
  53365. return NOT_COMPILED_IN;
  53366. /* set devId to invalid, so software is used */
  53367. info->hash.sha3->devId = INVALID_DEVID;
  53368. if (info->hash.in != NULL) {
  53369. ret = wc_Sha3_512_Update(
  53370. info->hash.sha3,
  53371. info->hash.in,
  53372. info->hash.inSz);
  53373. }
  53374. if (info->hash.digest != NULL) {
  53375. ret = wc_Sha3_512_Final(
  53376. info->hash.sha3,
  53377. info->hash.digest);
  53378. }
  53379. /* reset devId */
  53380. info->hash.sha3->devId = devIdArg;
  53381. }
  53382. else
  53383. #endif
  53384. {
  53385. }
  53386. }
  53387. #endif /* !NO_SHA || !NO_SHA256 */
  53388. #ifndef NO_HMAC
  53389. else if (info->algo_type == WC_ALGO_TYPE_HMAC) {
  53390. if (info->hmac.hmac == NULL)
  53391. return NOT_COMPILED_IN;
  53392. /* set devId to invalid, so software is used */
  53393. info->hmac.hmac->devId = INVALID_DEVID;
  53394. if (info->hmac.in != NULL) {
  53395. ret = wc_HmacUpdate(
  53396. info->hmac.hmac,
  53397. info->hmac.in,
  53398. info->hmac.inSz);
  53399. }
  53400. else if (info->hmac.digest != NULL) {
  53401. ret = wc_HmacFinal(
  53402. info->hmac.hmac,
  53403. info->hmac.digest);
  53404. }
  53405. /* reset devId */
  53406. info->hmac.hmac->devId = devIdArg;
  53407. }
  53408. #endif
  53409. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53410. else if (info->algo_type == WC_ALGO_TYPE_CMAC) {
  53411. if (info->cmac.cmac == NULL) {
  53412. return NOT_COMPILED_IN;
  53413. }
  53414. /* set devId to invalid so software is used */
  53415. info->cmac.cmac->devId = INVALID_DEVID;
  53416. /* Handle one-shot cases */
  53417. if (info->cmac.key != NULL && info->cmac.in != NULL
  53418. && info->cmac.out != NULL) {
  53419. ret = wc_AesCmacGenerate(info->cmac.out,
  53420. info->cmac.outSz,
  53421. info->cmac.in,
  53422. info->cmac.inSz,
  53423. info->cmac.key,
  53424. info->cmac.keySz);
  53425. /* Sequentially handle incremental cases */
  53426. } else {
  53427. if (info->cmac.key != NULL) {
  53428. ret = wc_InitCmac(info->cmac.cmac,
  53429. info->cmac.key,
  53430. info->cmac.keySz,
  53431. info->cmac.type,
  53432. NULL);
  53433. }
  53434. if ((ret == 0) && (info->cmac.in != NULL)) {
  53435. ret = wc_CmacUpdate(info->cmac.cmac,
  53436. info->cmac.in,
  53437. info->cmac.inSz);
  53438. }
  53439. if ((ret ==0) && (info->cmac.out != NULL)) {
  53440. ret = wc_CmacFinal(info->cmac.cmac,
  53441. info->cmac.out,
  53442. info->cmac.outSz);
  53443. }
  53444. }
  53445. /* reset devId */
  53446. info->cmac.cmac->devId = devIdArg;
  53447. }
  53448. #endif /* WOLFSSL_CMAC && !(NO_AES) && WOLFSSL_AES_DIRECT */
  53449. (void)devIdArg;
  53450. (void)myCtx;
  53451. return ret;
  53452. }
  53453. #ifdef WOLF_CRYPTO_CB_FIND
  53454. static int myCryptoCbFind(int currentId, int algoType)
  53455. {
  53456. /* can have algo specific overrides here
  53457. switch (algoType) {
  53458. i.e.
  53459. WC_ALGO_TYPE_CMAC
  53460. WC_ALGO_TYPE_SEED
  53461. WC_ALGO_TYPE_HMAC
  53462. WC_ALGO_TYPE_HASH
  53463. WC_ALGO_TYPE_CIPHER
  53464. WC_ALGO_TYPE_PK
  53465. }
  53466. */
  53467. (void)algoType;
  53468. if (currentId == INVALID_DEVID) {
  53469. /* can override invalid devid found with 1 */
  53470. }
  53471. return currentId;
  53472. }
  53473. #endif /* WOLF_CRYPTO_CB_FIND */
  53474. #if !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  53475. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
  53476. {
  53477. wc_test_ret_t ret = 0;
  53478. int origDevId = devId;
  53479. myCryptoDevCtx myCtx;
  53480. WOLFSSL_ENTER("cryptocb_test");
  53481. /* example data for callback */
  53482. myCtx.exampleVar = 1;
  53483. /* set devId to something other than INVALID_DEVID */
  53484. devId = 1;
  53485. ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
  53486. #ifdef WOLF_CRYPTO_CB_FIND
  53487. wc_CryptoCb_SetDeviceFindCb(myCryptoCbFind);
  53488. #endif /* WOLF_CRYPTO_CB_FIND */
  53489. #ifndef WC_NO_RNG
  53490. if (ret == 0)
  53491. ret = random_test();
  53492. #endif /* WC_NO_RNG */
  53493. #if !defined(NO_RSA)
  53494. PRIVATE_KEY_UNLOCK();
  53495. if (ret == 0)
  53496. ret = rsa_test();
  53497. PRIVATE_KEY_LOCK();
  53498. #endif
  53499. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  53500. PRIVATE_KEY_UNLOCK();
  53501. if (ret == 0)
  53502. ret = rsa_onlycb_test(&myCtx);
  53503. PRIVATE_KEY_LOCK();
  53504. #endif
  53505. #if defined(HAVE_ECC)
  53506. PRIVATE_KEY_UNLOCK();
  53507. if (ret == 0)
  53508. ret = ecc_test();
  53509. PRIVATE_KEY_LOCK();
  53510. #endif
  53511. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  53512. PRIVATE_KEY_UNLOCK();
  53513. if (ret == 0)
  53514. ret = ecc_onlycb_test(&myCtx);
  53515. PRIVATE_KEY_LOCK();
  53516. #endif
  53517. #ifdef HAVE_ED25519
  53518. PRIVATE_KEY_UNLOCK();
  53519. if (ret == 0)
  53520. ret = ed25519_test();
  53521. PRIVATE_KEY_LOCK();
  53522. #endif
  53523. #ifdef HAVE_CURVE25519
  53524. if (ret == 0)
  53525. ret = curve25519_test();
  53526. #endif
  53527. #ifndef NO_AES
  53528. #ifdef HAVE_AESGCM
  53529. if (ret == 0)
  53530. ret = aesgcm_test();
  53531. #endif
  53532. #ifdef HAVE_AES_CBC
  53533. if (ret == 0)
  53534. ret = aes_test();
  53535. #endif
  53536. #ifdef WOLFSSL_AES_XTS
  53537. if (ret == 0)
  53538. ret = aes_xts_test();
  53539. #endif
  53540. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53541. if (ret == 0)
  53542. ret = aesccm_test();
  53543. #endif
  53544. #endif /* !NO_AES */
  53545. #ifndef NO_DES3
  53546. if (ret == 0)
  53547. ret = des3_test();
  53548. #endif /* !NO_DES3 */
  53549. #ifndef NO_SHA
  53550. if (ret == 0)
  53551. ret = sha_test();
  53552. #endif
  53553. #ifndef NO_SHA256
  53554. if (ret == 0)
  53555. ret = sha256_test();
  53556. #endif
  53557. #ifdef WOLFSSL_SHA384
  53558. if (ret == 0)
  53559. ret = sha384_test();
  53560. #endif
  53561. #ifdef WOLFSSL_SHA512
  53562. if (ret == 0)
  53563. ret = sha512_test();
  53564. #ifdef WOLFSSL_SHA3
  53565. if (ret == 0)
  53566. ret = sha3_test();
  53567. #endif
  53568. #endif
  53569. #ifndef NO_HMAC
  53570. #ifndef NO_SHA
  53571. if (ret == 0)
  53572. ret = hmac_sha_test();
  53573. #endif
  53574. #ifndef NO_SHA256
  53575. if (ret == 0)
  53576. ret = hmac_sha256_test();
  53577. #endif
  53578. #ifdef WOLFSSL_SHA3
  53579. if (ret == 0)
  53580. ret = hmac_sha3_test();
  53581. #endif
  53582. #endif
  53583. #ifndef NO_PWDBASED
  53584. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  53585. PRIVATE_KEY_UNLOCK();
  53586. if (ret == 0)
  53587. ret = pbkdf2_test();
  53588. PRIVATE_KEY_LOCK();
  53589. #endif
  53590. #endif
  53591. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53592. if (ret == 0)
  53593. ret = cmac_test();
  53594. #endif
  53595. /* restore devId */
  53596. devId = origDevId;
  53597. return ret;
  53598. }
  53599. #endif /* ! WC_TEST_NO_CRYPTOCB_SW_TEST */
  53600. #endif /* WOLF_CRYPTO_CB */
  53601. #ifdef WOLFSSL_CERT_PIV
  53602. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void)
  53603. {
  53604. wc_test_ret_t ret;
  53605. wc_CertPIV piv;
  53606. /* Template for Identiv PIV cert, nonce and signature */
  53607. WOLFSSL_SMALL_STACK_STATIC const byte pivCertIdentiv[] = {
  53608. 0x0A, 0x0B,
  53609. 0x53, 0x09, /* NIST PIV Cert */
  53610. 0x70, 0x02, /* Certificate */
  53611. 0x30, 0x00,
  53612. 0x71, 0x01, 0x05, /* Cert Info */
  53613. 0xFE, 0x00, /* Error Detection */
  53614. 0x0B, 0x01, 0x00, /* Nonce */
  53615. 0x0C, 0x01, 0x00, /* Signed Nonce */
  53616. };
  53617. /* PIV certificate data including certificate, info and error detection. */
  53618. WOLFSSL_SMALL_STACK_STATIC const byte pivCert[] = {
  53619. 0x53, 0x09, /* NIST PIV Cert */
  53620. 0x70, 0x02, /* Certificate */
  53621. 0x30, 0x00,
  53622. 0x71, 0x01, 0x04, /* Cert Info */
  53623. 0xFE, 0x00, /* Error Detection */
  53624. };
  53625. WOLFSSL_ENTER("certpiv_test");
  53626. XMEMSET(&piv, 0, sizeof(piv));
  53627. /* Test with Identiv 0x0A, 0x0B and 0x0C markers */
  53628. ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv));
  53629. if (ret != 0) {
  53630. return WC_TEST_RET_ENC_EC(ret);
  53631. }
  53632. if (!piv.isIdentiv) {
  53633. return WC_TEST_RET_ENC_NC;
  53634. }
  53635. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53636. return WC_TEST_RET_ENC_NC;
  53637. }
  53638. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53639. return WC_TEST_RET_ENC_NC;
  53640. }
  53641. if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) {
  53642. return WC_TEST_RET_ENC_NC;
  53643. }
  53644. if (!piv.isX509) {
  53645. return WC_TEST_RET_ENC_NC;
  53646. }
  53647. if ((piv.nonce == NULL) || (piv.nonceSz != 1)) {
  53648. return WC_TEST_RET_ENC_NC;
  53649. }
  53650. if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) {
  53651. return WC_TEST_RET_ENC_NC;
  53652. }
  53653. XMEMSET(&piv, 0, sizeof(piv));
  53654. /* Test with NIST PIV format */
  53655. ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
  53656. if (ret != 0) {
  53657. return WC_TEST_RET_ENC_EC(ret);
  53658. }
  53659. if (piv.isIdentiv) {
  53660. return WC_TEST_RET_ENC_NC;
  53661. }
  53662. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53663. return WC_TEST_RET_ENC_NC;
  53664. }
  53665. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53666. return WC_TEST_RET_ENC_NC;
  53667. }
  53668. if ((piv.compression != 0)) {
  53669. return WC_TEST_RET_ENC_NC;
  53670. }
  53671. if (!piv.isX509) {
  53672. return WC_TEST_RET_ENC_NC;
  53673. }
  53674. return ret;
  53675. }
  53676. #endif /* WOLFSSL_CERT_PIV */
  53677. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  53678. static time_t time_cb(time_t* t)
  53679. {
  53680. if (t != NULL) {
  53681. *t = 99;
  53682. }
  53683. return 99;
  53684. }
  53685. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void)
  53686. {
  53687. time_t t;
  53688. wc_test_ret_t ret;
  53689. WOLFSSL_ENTER("time_test");
  53690. ret = wc_SetTimeCb(time_cb);
  53691. if (ret != 0)
  53692. return WC_TEST_RET_ENC_EC(ret);
  53693. t = wc_Time(NULL);
  53694. if (t != 99)
  53695. return WC_TEST_RET_ENC_NC;
  53696. ret = wc_GetTime(&t, sizeof(time_t));
  53697. if (ret != 0)
  53698. return WC_TEST_RET_ENC_EC(ret);
  53699. if (t != 99)
  53700. return WC_TEST_RET_ENC_NC;
  53701. ret = wc_SetTimeCb(NULL);
  53702. if (ret != 0)
  53703. return WC_TEST_RET_ENC_EC(ret);
  53704. return 0;
  53705. }
  53706. #endif
  53707. #ifdef WOLFSSL_AES_SIV
  53708. typedef struct {
  53709. const byte key[33];
  53710. word32 keySz;
  53711. const byte nonce[49];
  53712. word32 nonceSz;
  53713. byte numAssoc;
  53714. const byte assoc1[81];
  53715. word32 assoc1Sz;
  53716. const byte assoc2[11];
  53717. word32 assoc2Sz;
  53718. const byte plaintext[83];
  53719. word32 plaintextSz;
  53720. const byte siv[AES_BLOCK_SIZE+1];
  53721. const byte ciphertext[82];
  53722. word32 ciphertextSz;
  53723. } AesSivTestVector;
  53724. #define AES_SIV_TEST_VECTORS 9
  53725. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
  53726. {
  53727. WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
  53728. /* These test vectors come from chrony 4.1's SIV unit tests. */
  53729. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53730. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53731. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53732. 1,
  53733. "", 0,
  53734. "", 0,
  53735. "", 0,
  53736. "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
  53737. "", 0
  53738. },
  53739. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53740. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53741. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53742. 1,
  53743. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53744. "", 0,
  53745. "", 0,
  53746. "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
  53747. "", 0
  53748. },
  53749. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53750. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53751. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53752. 1,
  53753. "", 0,
  53754. "", 0,
  53755. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53756. "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
  53757. "\x14\xff\xb3\x97\x34\x5c\xcb\xe4\x4a\xa4\xde\xac\xd9\x36\x90\x46", 16
  53758. },
  53759. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53760. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53761. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
  53762. 1,
  53763. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
  53764. "", 0,
  53765. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
  53766. "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
  53767. "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
  53768. },
  53769. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53770. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53771. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53772. 1,
  53773. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53774. "", 0,
  53775. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
  53776. "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
  53777. "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
  53778. },
  53779. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53780. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53781. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53782. "\xd5", 17,
  53783. 1,
  53784. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
  53785. "\xa0", 17,
  53786. "", 0,
  53787. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
  53788. "\x08", 17,
  53789. "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
  53790. "\xa5\x11\xcd\xb6\x08\xf3\x76\xa0\xb6\xfa\x15\x82\xf3\x95\xe1\xeb"
  53791. "\xbd", 17
  53792. },
  53793. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53794. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53795. "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
  53796. "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
  53797. "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
  53798. 1,
  53799. "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
  53800. "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
  53801. "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
  53802. "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
  53803. "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
  53804. "", 0,
  53805. "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
  53806. "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
  53807. "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
  53808. "\xae\x81\xa1\xca\x5b\x5f\x45\xa6\x6f\x0c\x8a\xf3\xd4\x67\x40\x81"
  53809. "\x26\xe2\x01\x86\xe8\x5a\xd5\xf8\x58\x80\x9f\x56\xaa\x76\x96\xbf"
  53810. "\x31", 81,
  53811. "\x9a\x06\x33\xe0\xee\x00\x6a\x9b\xc8\x20\xd5\xe2\xc2\xed\xb5\x75",
  53812. "\xfa\x9e\x42\x2a\x31\x6b\xda\xca\xaa\x7d\x31\x8b\x84\x7a\xb8\xd7"
  53813. "\x8a\x81\x25\x64\xed\x41\x9b\xa9\x77\x10\xbd\x05\x0c\x4e\xc5\x31"
  53814. "\x0c\xa2\x86\xec\x8a\x94\xc8\x24\x23\x3c\x13\xee\xa5\x51\xc9\xdf"
  53815. "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
  53816. "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
  53817. "\xa1", 81
  53818. },
  53819. /* Example A.1 from RFC5297 */
  53820. {
  53821. "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
  53822. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
  53823. "", 0,
  53824. 1,
  53825. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53826. "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
  53827. "", 0,
  53828. "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
  53829. "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
  53830. "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
  53831. },
  53832. /* Example A.2 from RFC5297 */
  53833. {
  53834. "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
  53835. "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
  53836. "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
  53837. 2,
  53838. "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
  53839. "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
  53840. "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
  53841. "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
  53842. "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
  53843. "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
  53844. "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
  53845. "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
  53846. "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
  53847. "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
  53848. "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
  53849. }
  53850. };
  53851. int i;
  53852. byte computedCiphertext[82];
  53853. byte computedPlaintext[82];
  53854. byte siv[AES_BLOCK_SIZE];
  53855. wc_test_ret_t ret = 0;
  53856. WOLFSSL_ENTER("aes_siv_test");
  53857. /* First test legacy "exactly one Assoc" interface. */
  53858. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53859. if (testVectors[i].numAssoc != 1)
  53860. continue;
  53861. ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
  53862. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53863. testVectors[i].nonce, testVectors[i].nonceSz,
  53864. testVectors[i].plaintext,
  53865. testVectors[i].plaintextSz, siv,
  53866. computedCiphertext);
  53867. if (ret != 0) {
  53868. return WC_TEST_RET_ENC_EC(ret);
  53869. }
  53870. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53871. if (ret != 0) {
  53872. return WC_TEST_RET_ENC_NC;
  53873. }
  53874. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53875. testVectors[i].ciphertextSz);
  53876. if (ret != 0) {
  53877. return WC_TEST_RET_ENC_NC;
  53878. }
  53879. ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
  53880. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53881. testVectors[i].nonce, testVectors[i].nonceSz,
  53882. computedCiphertext, testVectors[i].plaintextSz,
  53883. siv, computedPlaintext);
  53884. if (ret != 0) {
  53885. return WC_TEST_RET_ENC_EC(ret);
  53886. }
  53887. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53888. testVectors[i].plaintextSz);
  53889. if (ret != 0) {
  53890. return WC_TEST_RET_ENC_NC;
  53891. }
  53892. }
  53893. /* Then test "multiple Assoc" interface. */
  53894. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53895. const struct AesSivAssoc assoc[2] = {
  53896. { testVectors[i].assoc1, testVectors[i].assoc1Sz },
  53897. { testVectors[i].assoc2, testVectors[i].assoc2Sz }
  53898. };
  53899. ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53900. assoc, testVectors[i].numAssoc,
  53901. testVectors[i].nonce, testVectors[i].nonceSz,
  53902. testVectors[i].plaintext,
  53903. testVectors[i].plaintextSz, siv,
  53904. computedCiphertext);
  53905. if (ret != 0) {
  53906. return WC_TEST_RET_ENC_EC(ret);
  53907. }
  53908. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53909. if (ret != 0) {
  53910. return WC_TEST_RET_ENC_NC;
  53911. }
  53912. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53913. testVectors[i].ciphertextSz);
  53914. if (ret != 0) {
  53915. return WC_TEST_RET_ENC_NC;
  53916. }
  53917. ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53918. assoc, testVectors[i].numAssoc,
  53919. testVectors[i].nonce, testVectors[i].nonceSz,
  53920. computedCiphertext,
  53921. testVectors[i].plaintextSz, siv,
  53922. computedPlaintext);
  53923. if (ret != 0) {
  53924. return WC_TEST_RET_ENC_EC(ret);
  53925. }
  53926. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53927. testVectors[i].plaintextSz);
  53928. if (ret != 0) {
  53929. return WC_TEST_RET_ENC_NC;
  53930. }
  53931. }
  53932. return 0;
  53933. }
  53934. #endif
  53935. #undef ERROR_OUT
  53936. static const int fiducial4 = WC_TEST_RET_LN;
  53937. /* print the fiducial line numbers assigned above, allowing confirmation of
  53938. * source code version match when in doubt.
  53939. */
  53940. static void print_fiducials(void) {
  53941. printf(" [fiducial line numbers: %d %d %d %d]\n",
  53942. fiducial1, fiducial2, fiducial3, fiducial4);
  53943. }
  53944. #else
  53945. #ifndef NO_MAIN_DRIVER
  53946. int main(void) { return 0; }
  53947. #endif
  53948. #endif /* NO_CRYPT_TEST */